MCPcopy Create free account
hub / github.com/ConardLi/easy-agent / tryExpandUserCommand

Method tryExpandUserCommand

src/core/queryEngine.ts:433–467  ·  view source on GitHub ↗

* Stage 23: expand `/command-name [args]` into the same two-message * pattern as skills. The visible marker renders a "❯ /command args" * bubble; the hidden body (prefixed `[command_invocation: ]`) carries * the substituted prompt template to the model. * * Returns null when:

(
    input: string,
  )

Source from the content-addressed store, hash-verified

431 // the model still receives it as a regular user prompt.
432 //
433 // We don't have an `isMeta` field on `MessageParam`, so we use a
434 // string-prefix sentinel ("[skill_invocation:<name>]\n") for the body
435 // and the `<command-*>` XML tags for the marker — both matched in
436 // ConversationView.
437 const skillExpansion = this.tryExpandSkillCommand(trimmed);
438 if (skillExpansion) {
439 if (skillExpansion.skill.frontmatter.hasForkContext) {
440 const { executeForkSkill } = await import("../services/skills/fork.js");
441 const forkAbort = this.beginAbortable();
442 try {
443 const result = await executeForkSkill(skillExpansion.skill, skillExpansion.bodyText, {
444 ...this.toolContext,
445 abortSignal: forkAbort.signal,
446 defaultModel: this.getActiveModel(),
447 availableTools: getToolsForMode(this.currentPermissionMode),
448 getPermissionMode: () => this.currentPermissionMode,
449 permissionSettings: this.permissionSettings,
450 sessionPermissionRules: this.sessionPermissionRules,
451 onPermissionRequest: this.onPermissionRequest,
452 });
453 const message: MessageParam = {
454 role: "assistant",
455 content: typeof result.content === "string" ? result.content : JSON.stringify(result.content),
456 };
457 this.messages.push(
458 markMessageSource({ role: "user", content: skillExpansion.markerContent }, "command"),
459 message,
460 );
461 yield { type: "assistant_message", message };
462 yield { type: "messages_updated", messages: [...this.messages] };
463 return { handled: true, reason: result.isError ? "model_error" : "completed" };
464 } finally {
465 this.abortController = null;
466 }
467 }
468 const markerMessage: MessageParam = markMessageSource(
469 { role: "user", content: skillExpansion.markerContent },
470 "command",

Callers 1

submitMessageMethod · 0.95

Calls 4

addSessionAllowRulesMethod · 0.95
findUserCommandFunction · 0.90
substituteArgumentsFunction · 0.90
isBuiltinCommandNameFunction · 0.85

Tested by

no test coverage detected