builtin-workflow-command.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { expandCustomCommandPrompt, type CustomCommandContent } from "@zcode/contracts";
  2. import { BUILTIN_ZCODE_SLASH_COMMAND_HELP_ENTRIES } from "@zcode/shared";
  3. import { DYNAMIC_WORKFLOW_SKILL_NAME } from "./app/bundled-skills.js";
  4. /**
  5. * 内置 `/workflow` 命令(docs/dynamic-workflow/authoring.md「The `/workflow` command and the skill」)。
  6. *
  7. * 它曾是 zcode-guide 内置插件的 `commands/workflow.md`:插件一被卸载/停用,命令与加号菜单入口一起消失,
  8. * 而十个工作流工具仍在(2026-09-19 事故)。现在命令正文随 CLI 编译,与 `/init` 同为代码定义的
  9. * prompt 型内置命令;名字进入保留字表,用户或插件同名命令不再被展开。
  10. *
  11. * 正文刻意复用 contracts 的 custom command 展开($ARGUMENTS 替换 + `skills:` 前言),
  12. * 让模型看到的提示词与插件时代逐字同形,不重新调教。
  13. */
  14. export const BUILTIN_WORKFLOW_COMMAND_NAME = "workflow";
  15. const helpEntry = BUILTIN_ZCODE_SLASH_COMMAND_HELP_ENTRIES.find(
  16. (entry) => entry.name === BUILTIN_WORKFLOW_COMMAND_NAME,
  17. );
  18. if (!helpEntry) {
  19. // 共享 help 表是保留字、TUI 候选与 App 目录的唯一来源;条目缺席时命令根本不可寻址。
  20. throw new Error(`Missing builtin slash command help entry: ${BUILTIN_WORKFLOW_COMMAND_NAME}`);
  21. }
  22. const USAGE_PREFIX = `/${BUILTIN_WORKFLOW_COMMAND_NAME} `;
  23. export const BUILTIN_WORKFLOW_COMMAND_DESCRIPTION = helpEntry.summary;
  24. export const BUILTIN_WORKFLOW_COMMAND_ARGUMENT_HINT = helpEntry.usage.startsWith(USAGE_PREFIX)
  25. ? helpEntry.usage.slice(USAGE_PREFIX.length)
  26. : "";
  27. /** `$ARGUMENTS` 必须在场:否则展开会把参数追加成位置不受控的 "User arguments:" 尾块。 */
  28. const BUILTIN_WORKFLOW_COMMAND_BODY = [
  29. `Use the \`${DYNAMIC_WORKFLOW_SKILL_NAME}\` skill to design and launch a dynamic workflow for this request:`,
  30. "",
  31. "$ARGUMENTS",
  32. "",
  33. "Decide the subagent topology before writing any code: how many subagents, which of them",
  34. "share a context, what result each one returns. Then write the script and call the",
  35. "`CreateWorkflow` tool. (`CreateWorkflow` is the dynamic-workflow tool. Do not use the",
  36. "legacy `Workflow` tool, and do not substitute the `Agent` tool.)",
  37. "",
  38. ].join("\n");
  39. export const BUILTIN_WORKFLOW_COMMAND: CustomCommandContent = {
  40. bytesRead: Buffer.byteLength(BUILTIN_WORKFLOW_COMMAND_BODY),
  41. content: BUILTIN_WORKFLOW_COMMAND_BODY,
  42. metadata: {
  43. allowedTools: [],
  44. argumentHint: BUILTIN_WORKFLOW_COMMAND_ARGUMENT_HINT,
  45. description: BUILTIN_WORKFLOW_COMMAND_DESCRIPTION,
  46. disableNonInteractive: false,
  47. frontmatterKeys: ["description", "argument-hint", "skills"],
  48. name: BUILTIN_WORKFLOW_COMMAND_NAME,
  49. path: `builtin:${BUILTIN_WORKFLOW_COMMAND_NAME}`,
  50. rootPath: "builtin:",
  51. scope: "system",
  52. skills: [DYNAMIC_WORKFLOW_SKILL_NAME],
  53. source: "zcode",
  54. },
  55. sizeBytes: Buffer.byteLength(BUILTIN_WORKFLOW_COMMAND_BODY),
  56. truncated: false,
  57. };
  58. export function expandBuiltinWorkflowCommandPrompt(args: string): string {
  59. return expandCustomCommandPrompt({ args, command: BUILTIN_WORKFLOW_COMMAND }).prompt;
  60. }