@kolisachint/hoocode-agent 0.5.52 → 0.5.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/cli/args.d.ts +2 -2
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +9 -8
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/core/agent-frontmatter.d.ts +8 -2
  7. package/dist/core/agent-frontmatter.d.ts.map +1 -1
  8. package/dist/core/agent-frontmatter.js +13 -7
  9. package/dist/core/agent-frontmatter.js.map +1 -1
  10. package/dist/core/agent-session-services.d.ts +1 -1
  11. package/dist/core/agent-session-services.d.ts.map +1 -1
  12. package/dist/core/agent-session-services.js +1 -1
  13. package/dist/core/agent-session-services.js.map +1 -1
  14. package/dist/core/agent-session.d.ts.map +1 -1
  15. package/dist/core/agent-session.js +2 -2
  16. package/dist/core/agent-session.js.map +1 -1
  17. package/dist/core/embsearch/embsearch-service.d.ts +1 -1
  18. package/dist/core/embsearch/embsearch-service.d.ts.map +1 -1
  19. package/dist/core/embsearch/embsearch-service.js +1 -1
  20. package/dist/core/embsearch/embsearch-service.js.map +1 -1
  21. package/dist/core/extensions/plugins/authoring.d.ts.map +1 -1
  22. package/dist/core/extensions/plugins/authoring.js +1 -1
  23. package/dist/core/extensions/plugins/authoring.js.map +1 -1
  24. package/dist/core/extensions/plugins/formats/shared.d.ts +1 -1
  25. package/dist/core/extensions/plugins/formats/shared.d.ts.map +1 -1
  26. package/dist/core/extensions/plugins/formats/shared.js +1 -1
  27. package/dist/core/extensions/plugins/formats/shared.js.map +1 -1
  28. package/dist/core/extensions/plugins/formats/types.d.ts +1 -1
  29. package/dist/core/extensions/plugins/formats/types.d.ts.map +1 -1
  30. package/dist/core/extensions/plugins/formats/types.js.map +1 -1
  31. package/dist/core/external-tools.d.ts +1 -1
  32. package/dist/core/external-tools.d.ts.map +1 -1
  33. package/dist/core/external-tools.js +2 -2
  34. package/dist/core/external-tools.js.map +1 -1
  35. package/dist/core/sdk.d.ts +2 -2
  36. package/dist/core/sdk.d.ts.map +1 -1
  37. package/dist/core/sdk.js +3 -3
  38. package/dist/core/sdk.js.map +1 -1
  39. package/dist/core/self-docs.d.ts +1 -1
  40. package/dist/core/self-docs.d.ts.map +1 -1
  41. package/dist/core/self-docs.js +1 -1
  42. package/dist/core/self-docs.js.map +1 -1
  43. package/dist/core/settings-defaults.d.ts +1 -1
  44. package/dist/core/settings-defaults.d.ts.map +1 -1
  45. package/dist/core/settings-defaults.js +1 -1
  46. package/dist/core/settings-defaults.js.map +1 -1
  47. package/dist/core/settings-manager.d.ts +2 -2
  48. package/dist/core/settings-manager.d.ts.map +1 -1
  49. package/dist/core/settings-manager.js +13 -5
  50. package/dist/core/settings-manager.js.map +1 -1
  51. package/dist/core/settings-types.d.ts +1 -1
  52. package/dist/core/settings-types.d.ts.map +1 -1
  53. package/dist/core/settings-types.js.map +1 -1
  54. package/dist/core/system-prompt.d.ts.map +1 -1
  55. package/dist/core/system-prompt.js +14 -15
  56. package/dist/core/system-prompt.js.map +1 -1
  57. package/dist/core/tools/index.d.ts +2 -2
  58. package/dist/core/tools/index.d.ts.map +1 -1
  59. package/dist/core/tools/index.js +3 -3
  60. package/dist/core/tools/index.js.map +1 -1
  61. package/dist/core/tools/plugins.d.ts.map +1 -1
  62. package/dist/core/tools/plugins.js +2 -2
  63. package/dist/core/tools/plugins.js.map +1 -1
  64. package/dist/core/tools/propose-plugin.d.ts.map +1 -1
  65. package/dist/core/tools/propose-plugin.js +1 -1
  66. package/dist/core/tools/propose-plugin.js.map +1 -1
  67. package/dist/core/tools/search.d.ts +1 -1
  68. package/dist/core/tools/search.d.ts.map +1 -1
  69. package/dist/core/tools/search.js +5 -5
  70. package/dist/core/tools/search.js.map +1 -1
  71. package/dist/core/tools/todo.d.ts.map +1 -1
  72. package/dist/core/tools/todo.js +9 -7
  73. package/dist/core/tools/todo.js.map +1 -1
  74. package/dist/extensions/core/ask-options.d.ts.map +1 -1
  75. package/dist/extensions/core/ask-options.js +1 -0
  76. package/dist/extensions/core/ask-options.js.map +1 -1
  77. package/dist/extensions/core/modes.d.ts.map +1 -1
  78. package/dist/extensions/core/modes.js +9 -0
  79. package/dist/extensions/core/modes.js.map +1 -1
  80. package/dist/extensions/core/permission-gate.d.ts.map +1 -1
  81. package/dist/extensions/core/permission-gate.js +40 -10
  82. package/dist/extensions/core/permission-gate.js.map +1 -1
  83. package/dist/init-templates.generated.d.ts.map +1 -1
  84. package/dist/init-templates.generated.js +14 -14
  85. package/dist/init-templates.generated.js.map +1 -1
  86. package/dist/main.d.ts.map +1 -1
  87. package/dist/main.js +7 -7
  88. package/dist/main.js.map +1 -1
  89. package/dist/modes/interactive/components/tool-chain-summary.d.ts.map +1 -1
  90. package/dist/modes/interactive/components/tool-chain-summary.js +1 -1
  91. package/dist/modes/interactive/components/tool-chain-summary.js.map +1 -1
  92. package/dist/modes/interactive/components/tool-signal.d.ts.map +1 -1
  93. package/dist/modes/interactive/components/tool-signal.js +7 -7
  94. package/dist/modes/interactive/components/tool-signal.js.map +1 -1
  95. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  96. package/dist/modes/interactive/components/tree-selector.js +2 -2
  97. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  98. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  99. package/dist/modes/interactive/interactive-mode.js +2 -2
  100. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  101. package/docs/extensions.md +1 -1
  102. package/docs/modes.md +33 -7
  103. package/docs/quickstart.md +1 -1
  104. package/docs/sdk.md +2 -2
  105. package/docs/settings.md +3 -3
  106. package/docs/usage.md +4 -4
  107. package/examples/agents/fork-reviewer.md +1 -1
  108. package/examples/agents/orchestrator.md +1 -1
  109. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  110. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  111. package/examples/extensions/plan-mode/index.ts +1 -1
  112. package/examples/extensions/preset.ts +1 -1
  113. package/examples/extensions/sandbox/package.json +1 -1
  114. package/examples/extensions/truncated-tool.ts +1 -1
  115. package/examples/extensions/with-deps/package.json +1 -1
  116. package/examples/sdk/05-tools.ts +3 -3
  117. package/package.json +4 -4
  118. package/templates/agents/code-review.md +1 -1
  119. package/templates/agents/explore.md +2 -2
  120. package/templates/agents/general-purpose.md +2 -2
  121. package/templates/agents/plan.md +2 -2
  122. package/templates/agents/security-review.md +1 -1
  123. package/templates/default-config.json +6 -3
  124. package/templates/modes/ask/system.md +4 -7
  125. package/templates/modes/build/system.md +6 -8
  126. package/templates/modes/debug/system.md +7 -8
  127. package/templates/modes/plan/system.md +7 -13
  128. package/templates/prompts/task-main.md +5 -12
  129. package/templates/skills/artifact-design/SKILL.md +1 -1
  130. package/templates/skills/canvas-design/SKILL.md +1 -1
  131. package/templates/skills/plugin-authoring/SKILL.md +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"modes.js","sourceRoot":"","sources":["../../../src/extensions/core/modes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAShD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,oBAAoB,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,eAAe,EAA6B,MAAM,WAAW,CAAC;AAEhH,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E,CAAC,MAAM,CAAC,kBAAkB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;gBAC1F,OAAO;YACR,CAAC;YACD,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAErG,qCAAqC;YACrC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;YAC5B,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC;YAC7B,WAAW,CAAC,MAAM,CAAC,CAAC;YAEpB,IAAI,cAAc,EAAE,CAAC;gBACpB,mEAAmE;gBACnE,+DAA+D;gBAC/D,MAAM,GAAG,CAAC,UAAU,CAAC;oBACpB,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC;wBACnC,MAAM,WAAW,CAAC,eAAe,CAAC,cAAe,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;oBAAA,CAC9E;iBACD,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,eAAe,CAAC;gBACtE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,8BAA8B,OAAO,oCAAkC,EAAE,MAAM,CAAC,CAAC;gBAC/F,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YACpB,CAAC;QAAA,CACD;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Mode system — resolves the active mode (ask/plan/build/debug), loads the\n * mode's system prompt, filters active tools, and exposes the /mode, /plan,\n * /grill, /goal, and /approve commands.\n *\n * Mode prompt search order (first hit wins):\n * - `./.hoocode/modes/{mode}/system.md`\n * - `~/.hoocode/modes/{mode}/system.md`\n * - each configured/contributed external dir in declared order\n * - built-in MODE_DEFAULTS for the four known modes\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport { getHooCodeDir } from \"../../config.js\";\nimport type {\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tSessionStartEvent,\n} from \"../../core/extensions/types.js\";\nimport { isLightModeEnv } from \"../../core/light.js\";\nimport { DEFAULT_MODE, DEFAULT_MODE_PROMPTS as MODE_DEFAULTS } from \"../../core/mode-prompts.js\";\nimport { EMBEDDED_PROMPTS } from \"../../init-templates.generated.js\";\nimport { mergeSearchPaths, readConfig, readMergedConfig, writeConfig } from \"./config.js\";\nimport { AUTO_LOOP_DONE_TOKEN, LOOP_AUTO_CHANGED, LOOP_AUTO_START, type LoopAutoStartPayload } from \"./loop.js\";\n\nconst HOOCODE_DIR = getHooCodeDir();\n\n/**\n * Per-session plan file path. Keying on sessionId lets concurrent or resumed\n * plan sessions keep distinct plans instead of clobbering each other.\n */\nfunction getPlanPath(cwd: string, sessionId: string): string {\n\treturn join(cwd, \".hoocode\", \"plans\", `${sessionId}.md`);\n}\n\n/** Legacy single-file plan location, retained as a read-only fallback for /approve. */\nfunction getLegacyPlanPath(cwd: string): string {\n\treturn join(cwd, \".hoocode\", \"plan.md\");\n}\n\nfunction tryReadFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst text = readFileSync(path, \"utf8\").trim();\n\t\treturn text || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Outcome of reading the first usable plan file out of a candidate list. */\ntype PlanLoadResult =\n\t| { status: \"loaded\"; sections: PlanSections }\n\t| { status: \"missing\" }\n\t| { status: \"error\"; path: string };\n\n/**\n * Reads the first candidate plan file that exists and is non-empty, parsed into\n * sections. Missing and blank files fall through to the next candidate; an\n * unreadable one stops the walk so the caller can report the specific path.\n */\nfunction loadPlanSections(candidatePaths: string[]): PlanLoadResult {\n\tfor (const planPath of candidatePaths) {\n\t\tif (!existsSync(planPath)) continue;\n\t\ttry {\n\t\t\tconst raw = readFileSync(planPath, \"utf8\").trim();\n\t\t\tif (raw) return { status: \"loaded\", sections: parsePlanSections(raw) };\n\t\t} catch {\n\t\t\treturn { status: \"error\", path: planPath };\n\t\t}\n\t}\n\treturn { status: \"missing\" };\n}\n\n/**\n * Walks search dirs in precedence order and returns the first existing\n * `modes/{name}/system.md` content. Order: project → user → externalDirs.\n */\nfunction resolveModeFile(name: string, cwd: string, externalDirs: string[]): string | undefined {\n\tconst candidates: string[] = [\n\t\tjoin(cwd, \".hoocode\", \"modes\", name, \"system.md\"),\n\t\tjoin(HOOCODE_DIR, \"modes\", name, \"system.md\"),\n\t\t...externalDirs.map((dir) => join(dir, name, \"system.md\")),\n\t];\n\tfor (const candidate of candidates) {\n\t\tconst content = tryReadFile(candidate);\n\t\tif (content !== undefined) return content;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the system prompt for the active mode.\n *\n * Search order (first hit wins):\n * - `./.hoocode/modes/{mode}/system.md`\n * - `~/.hoocode/modes/{mode}/system.md`\n * - each of `externalDirs` in declared order (config + CLI + extension contributions)\n * - built-in MODE_DEFAULTS for the four known modes\n */\nexport function buildSystemPrompt(mode: string, cwd: string, options?: { modePaths?: string[] }): string | undefined {\n\tconst modePaths = options?.modePaths ?? [];\n\treturn resolveModeFile(mode, cwd, modePaths) ?? MODE_DEFAULTS[mode];\n}\n\n// ============================================================================\n// Plan file: section parsing and step-by-step execution message\n// ============================================================================\n\nexport interface PlanSections {\n\tgoal?: string;\n\tfilesToModify?: string;\n\tnewFiles?: string;\n\ttests?: string;\n\tverification?: string;\n\t/** Original full text, used as fallback if no sections parsed */\n\traw: string;\n}\n\n/**\n * Parses `.hoocode/plan.md` into named sections.\n *\n * Recognises both ATX headings (`## Goal`) and bold labels (`**Goal**`).\n * Section names matched (case-insensitive): Goal, Files to modify, New files,\n * Tests, Verification.\n */\nexport function parsePlanSections(planContent: string): PlanSections {\n\tconst result: PlanSections = { raw: planContent };\n\n\t// Match `## Heading text` or `**Heading text**` followed by content until\n\t// the next heading of the same style.\n\tconst sectionPattern =\n\t\t/^(?:#{1,3}\\s+(.+?)|(?:\\*\\*(.+?)\\*\\*))\\s*\\n([\\s\\S]*?)(?=(?:^#{1,3}\\s+|\\*\\*[^*\\n]+\\*\\*\\s*\\n)|$)/gm;\n\n\tfor (const match of planContent.matchAll(sectionPattern)) {\n\t\tconst heading = (match[1] ?? match[2] ?? \"\").toLowerCase().trim();\n\t\tconst content = match[3].trim();\n\t\tif (!content) continue;\n\n\t\tif (/^goal/.test(heading)) {\n\t\t\tresult.goal = content;\n\t\t} else if (/files?\\s+to\\s+modif|^modif/.test(heading)) {\n\t\t\tresult.filesToModify = content;\n\t\t} else if (/new\\s+files?/.test(heading)) {\n\t\t\tresult.newFiles = content;\n\t\t} else if (/^tests?/.test(heading)) {\n\t\t\tresult.tests = content;\n\t\t} else if (/^verif/.test(heading)) {\n\t\t\tresult.verification = content;\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Builds the user message sent to the agent when `/approve` is run.\n *\n * If the plan has recognisable sections, each is presented as a numbered step\n * so the agent works through them sequentially. Otherwise the raw plan is used.\n *\n * Execution order:\n * 1. Modify existing files\n * 2. Create new files\n * 3. Update / add tests\n * 4. Run verification commands\n */\nexport function buildApproveMessage(sections: PlanSections): string {\n\tconst steps: string[] = [];\n\n\tif (sections.goal) {\n\t\tsteps.push(`**Goal:** ${sections.goal}`);\n\t}\n\tif (sections.filesToModify) {\n\t\tsteps.push(`**Step 1 — Modify existing files:**\\n${sections.filesToModify}`);\n\t}\n\tif (sections.newFiles) {\n\t\tsteps.push(`**Step 2 — Create new files:**\\n${sections.newFiles}`);\n\t}\n\tif (sections.tests) {\n\t\tsteps.push(`**Step 3 — Update tests:**\\n${sections.tests}`);\n\t}\n\tif (sections.verification) {\n\t\tsteps.push(`**Step 4 — Verify:**\\n${sections.verification}`);\n\t}\n\n\tif (steps.length === 0) {\n\t\treturn `Execute the following plan:\\n\\n${sections.raw}`;\n\t}\n\n\treturn `Execute this plan step by step. Complete each step fully before moving to the next.\\n\\n${steps.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Grill: plan interrogation\n// ============================================================================\n\n/** Which half (or both) of the grill flow to run. */\nexport type GrillTarget = \"both\" | \"me\" | \"plan\";\n\n/**\n * Parses the `/grill` argument into a target.\n *\n * Bare `/grill` runs both phases, `/grill me` only questions the user, and\n * `/grill plan` only critiques the plan. Anything else returns undefined so the\n * caller shows usage rather than guessing at intent.\n */\nexport function parseGrillTarget(args: string): GrillTarget | undefined {\n\tconst arg = args.trim().toLowerCase();\n\tif (!arg) return \"both\";\n\tif (arg === \"me\" || arg === \"plan\") return arg;\n\treturn undefined;\n}\n\n/**\n * Renders the parsed plan back into the message so the agent reviews a concrete\n * artifact rather than whatever it remembers writing. Falls back to the raw plan\n * text when no sections were recognised.\n */\nfunction renderPlanForReview(sections: PlanSections): string {\n\tconst parts: string[] = [];\n\tif (sections.goal) parts.push(`**Goal**\\n${sections.goal}`);\n\tif (sections.filesToModify) parts.push(`**Files to modify**\\n${sections.filesToModify}`);\n\tif (sections.newFiles) parts.push(`**New files**\\n${sections.newFiles}`);\n\tif (sections.tests) parts.push(`**Tests**\\n${sections.tests}`);\n\tif (sections.verification) parts.push(`**Verification**\\n${sections.verification}`);\n\treturn parts.length > 0 ? parts.join(\"\\n\\n\") : sections.raw;\n}\n\n/**\n * The `/grill` phases, read from the shipped prompt templates.\n *\n * These were two ~200-word string constants in this file. They are prose the\n * runtime injects verbatim - no interpolation, no branching, nothing a compiler\n * checks - so a `.md` under `templates/prompts/` is their right home, and the\n * existing build-time embed carries them in. Editing a prompt is now editing\n * prose rather than editing TypeScript that happens to contain prose.\n *\n * Each is trimmed: the files end with a newline and the phases are joined with\n * explicit separators below.\n */\nfunction grillPrompt(name: \"grill-me\" | \"grill-plan\" | \"grill-bridge\"): string {\n\treturn (EMBEDDED_PROMPTS[name] ?? \"\").trim();\n}\n\n/**\n * Builds the follow-up message injected by `/grill`.\n *\n * The two phases are ordered rather than alternative: underspecification sits\n * upstream of plan weakness, so critiquing a plan built on a misread request\n * produces a well-reviewed plan for the wrong job. Bare `/grill` therefore asks\n * first and folds the answers into the critique.\n */\nexport function buildGrillMessage(sections: PlanSections, target: GrillTarget): string {\n\tconst plan = renderPlanForReview(sections);\n\tconst me = grillPrompt(\"grill-me\");\n\tconst critique = grillPrompt(\"grill-plan\");\n\tif (target === \"me\") return `${me}\\n\\n---\\n\\n${plan}`;\n\tif (target === \"plan\") return `${critique}\\n\\n---\\n\\n${plan}`;\n\treturn `${me}\\n\\n${grillPrompt(\"grill-bridge\")}\\n\\n${critique}\\n\\n---\\n\\n${plan}`;\n}\n\n// ============================================================================\n// Goal: autonomous execution toward a completion condition\n// ============================================================================\n\n/** A parsed `/goal` invocation. */\nexport interface GoalInvocation {\n\t/** Explicit objective; falls back to the plan's Goal section when absent. */\n\tobjective?: string;\n\t/** Turn budget passed through to the autonomous loop. */\n\tmaxTurns?: number;\n}\n\n/**\n * Parses `/goal [--max-turns N] [objective]`.\n *\n * Returns undefined when `--max-turns` is present but not followed by a\n * non-negative integer, so the caller shows usage instead of silently running\n * with the default budget.\n */\nexport function parseGoalArgs(args: string): GoalInvocation | undefined {\n\tlet rest = args.trim();\n\tlet maxTurns: number | undefined;\n\n\tconst flag = /^--max-turns(?:\\s+(\\S+))?([\\s\\S]*)$/.exec(rest);\n\tif (flag) {\n\t\tconst raw = flag[1];\n\t\tif (!raw || !/^\\d+$/.test(raw)) return undefined;\n\t\tmaxTurns = Number(raw);\n\t\trest = flag[2].trim();\n\t}\n\n\treturn { objective: rest || undefined, maxTurns };\n}\n\n/** The two messages `/goal` hands to the autonomous loop. */\nexport interface GoalMessages {\n\t/** Delivered once, to start the run. */\n\ttask: string;\n\t/** Re-sent on each continuation to keep the target in view. */\n\tcontinuePrompt: string;\n}\n\n/**\n * Builds the messages for a `/goal` run.\n *\n * When the plan carries a Verification section it becomes the completion\n * condition, which is the difference between a loop that stops when it feels\n * finished and one that stops when something it can run says so. Both messages\n * restate the objective, because the loop's continuation prompt is all that\n * holds the target in place as the transcript grows.\n */\nexport function buildGoalMessages(objective: string, verification?: string): GoalMessages {\n\tconst condition = verification\n\t\t? `\\n\\nThe goal counts as complete only once this verification passes. Run it, and if it fails, fix what it reports and run it again:\\n\\n${verification}`\n\t\t: \"\";\n\n\treturn {\n\t\ttask: `Work autonomously toward this goal:\\n\\n${objective}${condition}`,\n\t\tcontinuePrompt:\n\t\t\t`Keep working toward the goal:\\n\\n${objective}${condition}\\n\\n` +\n\t\t\t`Reply with ${AUTO_LOOP_DONE_TOKEN} only when it is genuinely complete — not when it is merely close.`,\n\t};\n}\n\n// ============================================================================\n// setupMode\n// ============================================================================\n\nexport function setupMode(pi: ExtensionAPI): void {\n\tlet cachedMode = DEFAULT_MODE;\n\tlet cachedSystemPrompt: string | undefined;\n\tlet cachedPlanPath: string | undefined;\n\n\t// `/grill me` asks the user a question via ask_options, which an unattended\n\t// `/loop auto` run has nobody to answer. Track the loop's broadcast state so\n\t// the command can drop its interrogation phase instead of stalling the run.\n\tlet autoLoopActive = false;\n\tpi.events.on(LOOP_AUTO_CHANGED, (data) => {\n\t\tautoLoopActive = (data as { active?: boolean } | undefined)?.active === true;\n\t});\n\n\t// ── session_start ─────────────────────────────────────────────────────────\n\t// Config resolution order:\n\t// 1. Read global config (~/.hoocode/hoo-config.json)\n\t// 2. Read project config (./.hoocode/hoo-config.json) if present\n\t// 3. Merge — project scalars win; arrays are unioned\n\t// 4. Re-resolve active_mode from the merged result\n\n\tpi.on(\"session_start\", (_event: SessionStartEvent, ctx: ExtensionContext) => {\n\t\t// Light mode strips every fixed prompt appendix. Leaving\n\t\t// cachedSystemPrompt unset makes before_agent_start a no-op, so no\n\t\t// `<!-- hoo-core: mode= -->` block is appended.\n\t\tif (isLightModeEnv()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Steps 1–3: merge global + project configs\n\t\tconst config = readMergedConfig(ctx.cwd);\n\n\t\t// Step 4: resolve mode from the merged config\n\t\tcachedMode = config.active_mode ?? DEFAULT_MODE;\n\t\t// External search dirs come from two channels:\n\t\t// - HooConfig.mode_paths (config-declared)\n\t\t// - pi.addModeSearchPath (CLI flags + extension contributions)\n\t\tconst modePaths = mergeSearchPaths(config.mode_paths, pi.getModeSearchPaths());\n\t\tconst rawSystemPrompt = buildSystemPrompt(cachedMode, ctx.cwd, { modePaths });\n\n\t\t// Per-session plan path so concurrent sessions don't overwrite each other.\n\t\t// The `{{PLAN_PATH}}` token in plan-mode templates is substituted here.\n\t\tcachedPlanPath = getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\tconst relPlanPath = relative(ctx.cwd, cachedPlanPath) || cachedPlanPath;\n\t\tcachedSystemPrompt = rawSystemPrompt?.replace(/\\{\\{PLAN_PATH\\}\\}/g, relPlanPath);\n\n\t\t// Update footer with active mode\n\t\tif (ctx.hasUI) {\n\t\t\tctx.ui.setMode(cachedMode);\n\t\t}\n\n\t\t// Apply tool filter from mode enabled_tools\n\t\tconst modeCfg = config.modes?.[cachedMode];\n\t\tif (modeCfg?.enabled_tools && modeCfg.enabled_tools.length > 0) {\n\t\t\tpi.setActiveTools(modeCfg.enabled_tools);\n\t\t}\n\t});\n\n\t// ── before_agent_start ────────────────────────────────────────────────────\n\n\tpi.on(\"before_agent_start\", (event: BeforeAgentStartEvent): BeforeAgentStartEventResult | undefined => {\n\t\tif (!cachedSystemPrompt) return;\n\t\treturn {\n\t\t\tsystemPrompt: `${event.systemPrompt}\\n\\n<!-- hoo-core: mode=${cachedMode} -->\\n${cachedSystemPrompt}`,\n\t\t};\n\t});\n\n\t// ── /mode command ─────────────────────────────────────────────────────────\n\n\tconst KNOWN_MODES = [\"ask\", \"plan\", \"build\", \"debug\"];\n\n\tpi.registerCommand(\"mode\", {\n\t\tdescription: \"Switch active mode. Usage: /mode <ask|plan|build|debug>\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\tKNOWN_MODES.filter((m) => m.startsWith(prefix)).map((m) => ({ value: m, label: m })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst name = args.trim();\n\t\t\tif (!name) {\n\t\t\t\tctx.ui.notify(`Active mode: ${cachedMode}`, \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = name === DEFAULT_MODE ? undefined : name;\n\t\t\twriteConfig(config);\n\t\t\tctx.ui.notify(`Mode set to \"${name}\" — reloading…`, \"info\");\n\t\t\tawait ctx.reload();\n\t\t},\n\t});\n\n\t// ── /plan command (shorthand for /mode plan) ──────────────────────────────\n\n\tpi.registerCommand(\"plan\", {\n\t\tdescription: \"Switch to plan mode. Shorthand for /mode plan.\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (_args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = \"plan\";\n\t\t\twriteConfig(config);\n\t\t\tctx.ui.notify(`Mode set to \"plan\" — reloading…`, \"info\");\n\t\t\tawait ctx.reload();\n\t\t},\n\t});\n\n\t// ── /grill command ────────────────────────────────────────────────────────\n\t// Stress-tests the current plan in two phases: `me` surfaces the request's\n\t// unconfirmed assumptions as ask_options questions, `plan` critiques the plan\n\t// file itself. Unlike /approve this only injects a follow-up message — no\n\t// session switch, no mode change, no config write.\n\n\tpi.registerCommand(\"grill\", {\n\t\tdescription: \"Stress-test the current plan. Usage: /grill [me|plan]\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\t[\"me\", \"plan\"].filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst requested = parseGrillTarget(args);\n\t\t\tif (!requested) {\n\t\t\t\tctx.ui.notify(\"Usage: /grill [me|plan]\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Same lookup as /approve: per-session plan first, legacy file second.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (loaded.status === \"missing\") {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(`No plan to grill — ${relPlan} not found. Run /plan first.`, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Nobody is present to answer during an autonomous loop, so keep the\n\t\t\t// half of the flow that still works rather than blocking on a question.\n\t\t\tlet target = requested;\n\t\t\tif (autoLoopActive && target !== \"plan\") {\n\t\t\t\ttarget = \"plan\";\n\t\t\t\tctx.ui.notify(\"Autonomous loop active — grilling the plan only, skipping questions.\", \"info\");\n\t\t\t}\n\n\t\t\tpi.sendUserMessage(buildGrillMessage(loaded.sections, target), { deliverAs: \"followUp\" });\n\t\t},\n\t});\n\n\t// ── /goal command ─────────────────────────────────────────────────────────\n\t// Works autonomously toward a completion condition by driving the loop in\n\t// loop.ts over the LOOP_AUTO_START channel. Linear by design: a single thread\n\t// of execution that iterates until it reports done or exhausts its budget —\n\t// there is no task graph here, and no subtask fan-out.\n\t//\n\t// The run inherits whatever the active mode already permits (enabled_tools,\n\t// allowed_bash_commands, allowed_write_paths, auto_allow), so how much rope\n\t// an unattended goal gets is a mode-config decision, not one made here.\n\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Work autonomously toward a goal. Usage: /goal [--max-turns N] [objective]\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst parsed = parseGoalArgs(args);\n\t\t\tif (!parsed) {\n\t\t\t\tctx.ui.notify(\"Usage: /goal [--max-turns N] [objective]\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The plan supplies the objective when none was typed, and its\n\t\t\t// verification section becomes the completion condition either way.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst sections = loaded.status === \"loaded\" ? loaded.sections : undefined;\n\n\t\t\tconst objective = parsed.objective ?? sections?.goal;\n\t\t\tif (!objective) {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`No objective — pass one as /goal <objective>, or write a Goal section in ${relPlan}.`,\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { task, continuePrompt } = buildGoalMessages(objective, sections?.verification);\n\t\t\t// The loop announces itself on start, so nothing to notify here.\n\t\t\tpi.events.emit(LOOP_AUTO_START, {\n\t\t\t\ttask,\n\t\t\t\tmaxTurns: parsed.maxTurns,\n\t\t\t\tcontinuePrompt,\n\t\t\t} satisfies LoopAutoStartPayload);\n\t\t},\n\t});\n\n\t// ── /approve command ──────────────────────────────────────────────────────\n\t// Reads .hoocode/plan.md, parses it into named sections (Goal, Files to\n\t// modify, New files, Tests, Verification), switches to build mode, then\n\t// injects a step-by-step execution message into the new session.\n\n\tpi.registerCommand(\"approve\", {\n\t\tdescription: \"Approve the current plan and switch to build mode to execute it.\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (_args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tif (cachedMode !== \"plan\") {\n\t\t\t\tctx.ui.notify(`/approve is only available in plan mode (current mode: \"${cachedMode}\")`, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Prefer the per-session plan file, fall back to the legacy single file.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst approveMessage = loaded.status === \"loaded\" ? buildApproveMessage(loaded.sections) : undefined;\n\n\t\t\t// Switch global config to build mode\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = \"build\";\n\t\t\twriteConfig(config);\n\n\t\t\tif (approveMessage) {\n\t\t\t\t// Open a new build-mode session and deliver the parsed plan as the\n\t\t\t\t// first user message so the agent starts executing immediately\n\t\t\t\tawait ctx.newSession({\n\t\t\t\t\twithSession: async (replacedCtx) => {\n\t\t\t\t\t\tawait replacedCtx.sendUserMessage(approveMessage!, { deliverAs: \"followUp\" });\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(`Switched to build mode. No ${relPlan} found — describe what to build.`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
1
+ {"version":3,"file":"modes.js","sourceRoot":"","sources":["../../../src/extensions/core/modes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,I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E,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC;wBACnC,MAAM,WAAW,CAAC,eAAe,CAAC,cAAe,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;oBAAA,CAC9E;iBACD,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,eAAe,CAAC;gBACtE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,8BAA8B,OAAO,oCAAkC,EAAE,MAAM,CAAC,CAAC;gBAC/F,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YACpB,CAAC;QAAA,CACD;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Mode system — resolves the active mode (ask/plan/build/debug), loads the\n * mode's system prompt, filters active tools, and exposes the /mode, /plan,\n * /grill, /goal, and /approve commands.\n *\n * Mode prompt search order (first hit wins):\n * - `./.hoocode/modes/{mode}/system.md`\n * - `~/.hoocode/modes/{mode}/system.md`\n * - each configured/contributed external dir in declared order\n * - built-in MODE_DEFAULTS for the four known modes\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport { getHooCodeDir } from \"../../config.js\";\nimport type {\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tSessionStartEvent,\n} from \"../../core/extensions/types.js\";\nimport { isLightModeEnv } from \"../../core/light.js\";\nimport { DEFAULT_MODE, DEFAULT_MODE_PROMPTS as MODE_DEFAULTS } from \"../../core/mode-prompts.js\";\nimport { SUBAGENT_DEPTH_ENV } from \"../../core/subagent-depth.js\";\nimport { EMBEDDED_PROMPTS } from \"../../init-templates.generated.js\";\nimport { mergeSearchPaths, readConfig, readMergedConfig, writeConfig } from \"./config.js\";\nimport { AUTO_LOOP_DONE_TOKEN, LOOP_AUTO_CHANGED, LOOP_AUTO_START, type LoopAutoStartPayload } from \"./loop.js\";\n\nconst HOOCODE_DIR = getHooCodeDir();\n\n/**\n * Per-session plan file path. Keying on sessionId lets concurrent or resumed\n * plan sessions keep distinct plans instead of clobbering each other.\n */\nfunction getPlanPath(cwd: string, sessionId: string): string {\n\treturn join(cwd, \".hoocode\", \"plans\", `${sessionId}.md`);\n}\n\n/** Legacy single-file plan location, retained as a read-only fallback for /approve. */\nfunction getLegacyPlanPath(cwd: string): string {\n\treturn join(cwd, \".hoocode\", \"plan.md\");\n}\n\nfunction tryReadFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst text = readFileSync(path, \"utf8\").trim();\n\t\treturn text || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Outcome of reading the first usable plan file out of a candidate list. */\ntype PlanLoadResult =\n\t| { status: \"loaded\"; sections: PlanSections }\n\t| { status: \"missing\" }\n\t| { status: \"error\"; path: string };\n\n/**\n * Reads the first candidate plan file that exists and is non-empty, parsed into\n * sections. Missing and blank files fall through to the next candidate; an\n * unreadable one stops the walk so the caller can report the specific path.\n */\nfunction loadPlanSections(candidatePaths: string[]): PlanLoadResult {\n\tfor (const planPath of candidatePaths) {\n\t\tif (!existsSync(planPath)) continue;\n\t\ttry {\n\t\t\tconst raw = readFileSync(planPath, \"utf8\").trim();\n\t\t\tif (raw) return { status: \"loaded\", sections: parsePlanSections(raw) };\n\t\t} catch {\n\t\t\treturn { status: \"error\", path: planPath };\n\t\t}\n\t}\n\treturn { status: \"missing\" };\n}\n\n/**\n * Walks search dirs in precedence order and returns the first existing\n * `modes/{name}/system.md` content. Order: project → user → externalDirs.\n */\nfunction resolveModeFile(name: string, cwd: string, externalDirs: string[]): string | undefined {\n\tconst candidates: string[] = [\n\t\tjoin(cwd, \".hoocode\", \"modes\", name, \"system.md\"),\n\t\tjoin(HOOCODE_DIR, \"modes\", name, \"system.md\"),\n\t\t...externalDirs.map((dir) => join(dir, name, \"system.md\")),\n\t];\n\tfor (const candidate of candidates) {\n\t\tconst content = tryReadFile(candidate);\n\t\tif (content !== undefined) return content;\n\t}\n\treturn undefined;\n}\n\n/**\n * Returns the system prompt for the active mode.\n *\n * Search order (first hit wins):\n * - `./.hoocode/modes/{mode}/system.md`\n * - `~/.hoocode/modes/{mode}/system.md`\n * - each of `externalDirs` in declared order (config + CLI + extension contributions)\n * - built-in MODE_DEFAULTS for the four known modes\n */\nexport function buildSystemPrompt(mode: string, cwd: string, options?: { modePaths?: string[] }): string | undefined {\n\tconst modePaths = options?.modePaths ?? [];\n\treturn resolveModeFile(mode, cwd, modePaths) ?? MODE_DEFAULTS[mode];\n}\n\n// ============================================================================\n// Plan file: section parsing and step-by-step execution message\n// ============================================================================\n\nexport interface PlanSections {\n\tgoal?: string;\n\tfilesToModify?: string;\n\tnewFiles?: string;\n\ttests?: string;\n\tverification?: string;\n\t/** Original full text, used as fallback if no sections parsed */\n\traw: string;\n}\n\n/**\n * Parses `.hoocode/plan.md` into named sections.\n *\n * Recognises both ATX headings (`## Goal`) and bold labels (`**Goal**`).\n * Section names matched (case-insensitive): Goal, Files to modify, New files,\n * Tests, Verification.\n */\nexport function parsePlanSections(planContent: string): PlanSections {\n\tconst result: PlanSections = { raw: planContent };\n\n\t// Match `## Heading text` or `**Heading text**` followed by content until\n\t// the next heading of the same style.\n\tconst sectionPattern =\n\t\t/^(?:#{1,3}\\s+(.+?)|(?:\\*\\*(.+?)\\*\\*))\\s*\\n([\\s\\S]*?)(?=(?:^#{1,3}\\s+|\\*\\*[^*\\n]+\\*\\*\\s*\\n)|$)/gm;\n\n\tfor (const match of planContent.matchAll(sectionPattern)) {\n\t\tconst heading = (match[1] ?? match[2] ?? \"\").toLowerCase().trim();\n\t\tconst content = match[3].trim();\n\t\tif (!content) continue;\n\n\t\tif (/^goal/.test(heading)) {\n\t\t\tresult.goal = content;\n\t\t} else if (/files?\\s+to\\s+modif|^modif/.test(heading)) {\n\t\t\tresult.filesToModify = content;\n\t\t} else if (/new\\s+files?/.test(heading)) {\n\t\t\tresult.newFiles = content;\n\t\t} else if (/^tests?/.test(heading)) {\n\t\t\tresult.tests = content;\n\t\t} else if (/^verif/.test(heading)) {\n\t\t\tresult.verification = content;\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Builds the user message sent to the agent when `/approve` is run.\n *\n * If the plan has recognisable sections, each is presented as a numbered step\n * so the agent works through them sequentially. Otherwise the raw plan is used.\n *\n * Execution order:\n * 1. Modify existing files\n * 2. Create new files\n * 3. Update / add tests\n * 4. Run verification commands\n */\nexport function buildApproveMessage(sections: PlanSections): string {\n\tconst steps: string[] = [];\n\n\tif (sections.goal) {\n\t\tsteps.push(`**Goal:** ${sections.goal}`);\n\t}\n\tif (sections.filesToModify) {\n\t\tsteps.push(`**Step 1 — Modify existing files:**\\n${sections.filesToModify}`);\n\t}\n\tif (sections.newFiles) {\n\t\tsteps.push(`**Step 2 — Create new files:**\\n${sections.newFiles}`);\n\t}\n\tif (sections.tests) {\n\t\tsteps.push(`**Step 3 — Update tests:**\\n${sections.tests}`);\n\t}\n\tif (sections.verification) {\n\t\tsteps.push(`**Step 4 — Verify:**\\n${sections.verification}`);\n\t}\n\n\tif (steps.length === 0) {\n\t\treturn `Execute the following plan:\\n\\n${sections.raw}`;\n\t}\n\n\treturn `Execute this plan step by step. Complete each step fully before moving to the next.\\n\\n${steps.join(\"\\n\\n\")}`;\n}\n\n// ============================================================================\n// Grill: plan interrogation\n// ============================================================================\n\n/** Which half (or both) of the grill flow to run. */\nexport type GrillTarget = \"both\" | \"me\" | \"plan\";\n\n/**\n * Parses the `/grill` argument into a target.\n *\n * Bare `/grill` runs both phases, `/grill me` only questions the user, and\n * `/grill plan` only critiques the plan. Anything else returns undefined so the\n * caller shows usage rather than guessing at intent.\n */\nexport function parseGrillTarget(args: string): GrillTarget | undefined {\n\tconst arg = args.trim().toLowerCase();\n\tif (!arg) return \"both\";\n\tif (arg === \"me\" || arg === \"plan\") return arg;\n\treturn undefined;\n}\n\n/**\n * Renders the parsed plan back into the message so the agent reviews a concrete\n * artifact rather than whatever it remembers writing. Falls back to the raw plan\n * text when no sections were recognised.\n */\nfunction renderPlanForReview(sections: PlanSections): string {\n\tconst parts: string[] = [];\n\tif (sections.goal) parts.push(`**Goal**\\n${sections.goal}`);\n\tif (sections.filesToModify) parts.push(`**Files to modify**\\n${sections.filesToModify}`);\n\tif (sections.newFiles) parts.push(`**New files**\\n${sections.newFiles}`);\n\tif (sections.tests) parts.push(`**Tests**\\n${sections.tests}`);\n\tif (sections.verification) parts.push(`**Verification**\\n${sections.verification}`);\n\treturn parts.length > 0 ? parts.join(\"\\n\\n\") : sections.raw;\n}\n\n/**\n * The `/grill` phases, read from the shipped prompt templates.\n *\n * These were two ~200-word string constants in this file. They are prose the\n * runtime injects verbatim - no interpolation, no branching, nothing a compiler\n * checks - so a `.md` under `templates/prompts/` is their right home, and the\n * existing build-time embed carries them in. Editing a prompt is now editing\n * prose rather than editing TypeScript that happens to contain prose.\n *\n * Each is trimmed: the files end with a newline and the phases are joined with\n * explicit separators below.\n */\nfunction grillPrompt(name: \"grill-me\" | \"grill-plan\" | \"grill-bridge\"): string {\n\treturn (EMBEDDED_PROMPTS[name] ?? \"\").trim();\n}\n\n/**\n * Builds the follow-up message injected by `/grill`.\n *\n * The two phases are ordered rather than alternative: underspecification sits\n * upstream of plan weakness, so critiquing a plan built on a misread request\n * produces a well-reviewed plan for the wrong job. Bare `/grill` therefore asks\n * first and folds the answers into the critique.\n */\nexport function buildGrillMessage(sections: PlanSections, target: GrillTarget): string {\n\tconst plan = renderPlanForReview(sections);\n\tconst me = grillPrompt(\"grill-me\");\n\tconst critique = grillPrompt(\"grill-plan\");\n\tif (target === \"me\") return `${me}\\n\\n---\\n\\n${plan}`;\n\tif (target === \"plan\") return `${critique}\\n\\n---\\n\\n${plan}`;\n\treturn `${me}\\n\\n${grillPrompt(\"grill-bridge\")}\\n\\n${critique}\\n\\n---\\n\\n${plan}`;\n}\n\n// ============================================================================\n// Goal: autonomous execution toward a completion condition\n// ============================================================================\n\n/** A parsed `/goal` invocation. */\nexport interface GoalInvocation {\n\t/** Explicit objective; falls back to the plan's Goal section when absent. */\n\tobjective?: string;\n\t/** Turn budget passed through to the autonomous loop. */\n\tmaxTurns?: number;\n}\n\n/**\n * Parses `/goal [--max-turns N] [objective]`.\n *\n * Returns undefined when `--max-turns` is present but not followed by a\n * non-negative integer, so the caller shows usage instead of silently running\n * with the default budget.\n */\nexport function parseGoalArgs(args: string): GoalInvocation | undefined {\n\tlet rest = args.trim();\n\tlet maxTurns: number | undefined;\n\n\tconst flag = /^--max-turns(?:\\s+(\\S+))?([\\s\\S]*)$/.exec(rest);\n\tif (flag) {\n\t\tconst raw = flag[1];\n\t\tif (!raw || !/^\\d+$/.test(raw)) return undefined;\n\t\tmaxTurns = Number(raw);\n\t\trest = flag[2].trim();\n\t}\n\n\treturn { objective: rest || undefined, maxTurns };\n}\n\n/** The two messages `/goal` hands to the autonomous loop. */\nexport interface GoalMessages {\n\t/** Delivered once, to start the run. */\n\ttask: string;\n\t/** Re-sent on each continuation to keep the target in view. */\n\tcontinuePrompt: string;\n}\n\n/**\n * Builds the messages for a `/goal` run.\n *\n * When the plan carries a Verification section it becomes the completion\n * condition, which is the difference between a loop that stops when it feels\n * finished and one that stops when something it can run says so. Both messages\n * restate the objective, because the loop's continuation prompt is all that\n * holds the target in place as the transcript grows.\n */\nexport function buildGoalMessages(objective: string, verification?: string): GoalMessages {\n\tconst condition = verification\n\t\t? `\\n\\nThe goal counts as complete only once this verification passes. Run it, and if it fails, fix what it reports and run it again:\\n\\n${verification}`\n\t\t: \"\";\n\n\treturn {\n\t\ttask: `Work autonomously toward this goal:\\n\\n${objective}${condition}`,\n\t\tcontinuePrompt:\n\t\t\t`Keep working toward the goal:\\n\\n${objective}${condition}\\n\\n` +\n\t\t\t`Reply with ${AUTO_LOOP_DONE_TOKEN} only when it is genuinely complete — not when it is merely close.`,\n\t};\n}\n\n// ============================================================================\n// setupMode\n// ============================================================================\n\nexport function setupMode(pi: ExtensionAPI): void {\n\tlet cachedMode = DEFAULT_MODE;\n\tlet cachedSystemPrompt: string | undefined;\n\tlet cachedPlanPath: string | undefined;\n\n\t// `/grill me` asks the user a question via ask_options, which an unattended\n\t// `/loop auto` run has nobody to answer. Track the loop's broadcast state so\n\t// the command can drop its interrogation phase instead of stalling the run.\n\tlet autoLoopActive = false;\n\tpi.events.on(LOOP_AUTO_CHANGED, (data) => {\n\t\tautoLoopActive = (data as { active?: boolean } | undefined)?.active === true;\n\t});\n\n\t// ── session_start ─────────────────────────────────────────────────────────\n\t// Config resolution order:\n\t// 1. Read global config (~/.hoocode/hoo-config.json)\n\t// 2. Read project config (./.hoocode/hoo-config.json) if present\n\t// 3. Merge — project scalars win; arrays are unioned\n\t// 4. Re-resolve active_mode from the merged result\n\n\tpi.on(\"session_start\", (_event: SessionStartEvent, ctx: ExtensionContext) => {\n\t\t// Light mode strips every fixed prompt appendix. Leaving\n\t\t// cachedSystemPrompt unset makes before_agent_start a no-op, so no\n\t\t// `<!-- hoo-core: mode= -->` block is appended.\n\t\tif (isLightModeEnv()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// A spawned subagent already carries its own system prompt (from its agent\n\t\t// definition) and its own tool allowlist. Appending the parent's mode prompt\n\t\t// on top contradicts it — a read-only `explore` child would be told to \"read\n\t\t// before editing\" and \"run tests after every change\" — and spends tokens on\n\t\t// rules for tools the child does not have. The pool sets this on every child.\n\t\tif (process.env[SUBAGENT_DEPTH_ENV]) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Steps 1–3: merge global + project configs\n\t\tconst config = readMergedConfig(ctx.cwd);\n\n\t\t// Step 4: resolve mode from the merged config\n\t\tcachedMode = config.active_mode ?? DEFAULT_MODE;\n\t\t// External search dirs come from two channels:\n\t\t// - HooConfig.mode_paths (config-declared)\n\t\t// - pi.addModeSearchPath (CLI flags + extension contributions)\n\t\tconst modePaths = mergeSearchPaths(config.mode_paths, pi.getModeSearchPaths());\n\t\tconst rawSystemPrompt = buildSystemPrompt(cachedMode, ctx.cwd, { modePaths });\n\n\t\t// Per-session plan path so concurrent sessions don't overwrite each other.\n\t\t// The `{{PLAN_PATH}}` token in plan-mode templates is substituted here.\n\t\tcachedPlanPath = getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\tconst relPlanPath = relative(ctx.cwd, cachedPlanPath) || cachedPlanPath;\n\t\tcachedSystemPrompt = rawSystemPrompt?.replace(/\\{\\{PLAN_PATH\\}\\}/g, relPlanPath);\n\n\t\t// Update footer with active mode\n\t\tif (ctx.hasUI) {\n\t\t\tctx.ui.setMode(cachedMode);\n\t\t}\n\n\t\t// Apply tool filter from mode enabled_tools\n\t\tconst modeCfg = config.modes?.[cachedMode];\n\t\tif (modeCfg?.enabled_tools && modeCfg.enabled_tools.length > 0) {\n\t\t\tpi.setActiveTools(modeCfg.enabled_tools);\n\t\t}\n\t});\n\n\t// ── before_agent_start ────────────────────────────────────────────────────\n\n\tpi.on(\"before_agent_start\", (event: BeforeAgentStartEvent): BeforeAgentStartEventResult | undefined => {\n\t\tif (!cachedSystemPrompt) return;\n\t\treturn {\n\t\t\tsystemPrompt: `${event.systemPrompt}\\n\\n<!-- hoo-core: mode=${cachedMode} -->\\n${cachedSystemPrompt}`,\n\t\t};\n\t});\n\n\t// ── /mode command ─────────────────────────────────────────────────────────\n\n\tconst KNOWN_MODES = [\"ask\", \"plan\", \"build\", \"debug\"];\n\n\tpi.registerCommand(\"mode\", {\n\t\tdescription: \"Switch active mode. Usage: /mode <ask|plan|build|debug>\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\tKNOWN_MODES.filter((m) => m.startsWith(prefix)).map((m) => ({ value: m, label: m })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst name = args.trim();\n\t\t\tif (!name) {\n\t\t\t\tctx.ui.notify(`Active mode: ${cachedMode}`, \"info\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = name === DEFAULT_MODE ? undefined : name;\n\t\t\twriteConfig(config);\n\t\t\tctx.ui.notify(`Mode set to \"${name}\" — reloading…`, \"info\");\n\t\t\tawait ctx.reload();\n\t\t},\n\t});\n\n\t// ── /plan command (shorthand for /mode plan) ──────────────────────────────\n\n\tpi.registerCommand(\"plan\", {\n\t\tdescription: \"Switch to plan mode. Shorthand for /mode plan.\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (_args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = \"plan\";\n\t\t\twriteConfig(config);\n\t\t\tctx.ui.notify(`Mode set to \"plan\" — reloading…`, \"info\");\n\t\t\tawait ctx.reload();\n\t\t},\n\t});\n\n\t// ── /grill command ────────────────────────────────────────────────────────\n\t// Stress-tests the current plan in two phases: `me` surfaces the request's\n\t// unconfirmed assumptions as ask_options questions, `plan` critiques the plan\n\t// file itself. Unlike /approve this only injects a follow-up message — no\n\t// session switch, no mode change, no config write.\n\n\tpi.registerCommand(\"grill\", {\n\t\tdescription: \"Stress-test the current plan. Usage: /grill [me|plan]\",\n\t\tgetArgumentCompletions: (prefix: string) =>\n\t\t\t[\"me\", \"plan\"].filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s })),\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst requested = parseGrillTarget(args);\n\t\t\tif (!requested) {\n\t\t\t\tctx.ui.notify(\"Usage: /grill [me|plan]\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Same lookup as /approve: per-session plan first, legacy file second.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (loaded.status === \"missing\") {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(`No plan to grill — ${relPlan} not found. Run /plan first.`, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Nobody is present to answer during an autonomous loop, so keep the\n\t\t\t// half of the flow that still works rather than blocking on a question.\n\t\t\tlet target = requested;\n\t\t\tif (autoLoopActive && target !== \"plan\") {\n\t\t\t\ttarget = \"plan\";\n\t\t\t\tctx.ui.notify(\"Autonomous loop active — grilling the plan only, skipping questions.\", \"info\");\n\t\t\t}\n\n\t\t\tpi.sendUserMessage(buildGrillMessage(loaded.sections, target), { deliverAs: \"followUp\" });\n\t\t},\n\t});\n\n\t// ── /goal command ─────────────────────────────────────────────────────────\n\t// Works autonomously toward a completion condition by driving the loop in\n\t// loop.ts over the LOOP_AUTO_START channel. Linear by design: a single thread\n\t// of execution that iterates until it reports done or exhausts its budget —\n\t// there is no task graph here, and no subtask fan-out.\n\t//\n\t// The run inherits whatever the active mode already permits (enabled_tools,\n\t// allowed_bash_commands, allowed_write_paths, auto_allow), so how much rope\n\t// an unattended goal gets is a mode-config decision, not one made here.\n\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Work autonomously toward a goal. Usage: /goal [--max-turns N] [objective]\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tconst parsed = parseGoalArgs(args);\n\t\t\tif (!parsed) {\n\t\t\t\tctx.ui.notify(\"Usage: /goal [--max-turns N] [objective]\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The plan supplies the objective when none was typed, and its\n\t\t\t// verification section becomes the completion condition either way.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst sections = loaded.status === \"loaded\" ? loaded.sections : undefined;\n\n\t\t\tconst objective = parsed.objective ?? sections?.goal;\n\t\t\tif (!objective) {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`No objective — pass one as /goal <objective>, or write a Goal section in ${relPlan}.`,\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { task, continuePrompt } = buildGoalMessages(objective, sections?.verification);\n\t\t\t// The loop announces itself on start, so nothing to notify here.\n\t\t\tpi.events.emit(LOOP_AUTO_START, {\n\t\t\t\ttask,\n\t\t\t\tmaxTurns: parsed.maxTurns,\n\t\t\t\tcontinuePrompt,\n\t\t\t} satisfies LoopAutoStartPayload);\n\t\t},\n\t});\n\n\t// ── /approve command ──────────────────────────────────────────────────────\n\t// Reads .hoocode/plan.md, parses it into named sections (Goal, Files to\n\t// modify, New files, Tests, Verification), switches to build mode, then\n\t// injects a step-by-step execution message into the new session.\n\n\tpi.registerCommand(\"approve\", {\n\t\tdescription: \"Approve the current plan and switch to build mode to execute it.\",\n\t\tgetArgumentCompletions: () => [],\n\t\thandler: async (_args: string, ctx: ExtensionCommandContext): Promise<void> => {\n\t\t\tif (cachedMode !== \"plan\") {\n\t\t\t\tctx.ui.notify(`/approve is only available in plan mode (current mode: \"${cachedMode}\")`, \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Prefer the per-session plan file, fall back to the legacy single file.\n\t\t\tconst sessionPlanPath = cachedPlanPath ?? getPlanPath(ctx.cwd, ctx.sessionManager.getSessionId());\n\t\t\tconst loaded = loadPlanSections([sessionPlanPath, getLegacyPlanPath(ctx.cwd)]);\n\t\t\tif (loaded.status === \"error\") {\n\t\t\t\tctx.ui.notify(`Could not read ${relative(ctx.cwd, loaded.path) || loaded.path}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst approveMessage = loaded.status === \"loaded\" ? buildApproveMessage(loaded.sections) : undefined;\n\n\t\t\t// Switch global config to build mode\n\t\t\tconst config = readConfig();\n\t\t\tconfig.active_mode = \"build\";\n\t\t\twriteConfig(config);\n\n\t\t\tif (approveMessage) {\n\t\t\t\t// Open a new build-mode session and deliver the parsed plan as the\n\t\t\t\t// first user message so the agent starts executing immediately\n\t\t\t\tawait ctx.newSession({\n\t\t\t\t\twithSession: async (replacedCtx) => {\n\t\t\t\t\t\tawait replacedCtx.sendUserMessage(approveMessage!, { deliverAs: \"followUp\" });\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst relPlan = relative(ctx.cwd, sessionPlanPath) || sessionPlanPath;\n\t\t\t\tctx.ui.notify(`Switched to build mode. No ${relPlan} found — describe what to build.`, \"info\");\n\t\t\t\tawait ctx.reload();\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"permission-gate.d.ts","sourceRoot":"","sources":["../../../src/extensions/core/permission-gate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACX,YAAY,EAIZ,MAAM,gCAAgC,CAAC;AA2ExC,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA0H1D","sourcesContent":["/**\n * Permission gate — prompts before bash/write/edit/webfetch/websearch; checks\n * modes.{mode}.auto_allow from the merged (global + project) config; persists\n * \"always\" choices back to the global config. Hard enforcement (denied tools,\n * enabled_tools allowlists, bash command patterns, .webtoolsignore hosts)\n * applies even without a UI.\n */\n\nimport type {\n\tExtensionAPI,\n\tExtensionContext,\n\tToolCallEvent,\n\tToolCallEventResult,\n} from \"../../core/extensions/types.js\";\nimport { isToolCallEventType } from \"../../core/extensions/types.js\";\nimport { blockedHostForUrl } from \"../../core/tools/webtools-shared.js\";\nimport { readConfig, readMergedConfig, writeConfig } from \"./config.js\";\n\nconst GATED_TOOLS = new Set([\"bash\", \"write\", \"edit\", \"webfetch\", \"websearch\"]);\n\n/**\n * Checks if a file path matches any of the allowed patterns.\n * Supports glob patterns with * and exact paths.\n */\nfunction matchesAllowedPath(filePath: string, allowedPatterns: string[]): boolean {\n\tif (allowedPatterns.length === 0) return true;\n\tfor (const pattern of allowedPatterns) {\n\t\t// Exact match\n\t\tif (pattern === filePath) return true;\n\t\t// Glob pattern matching for *\n\t\tif (pattern.includes(\"*\")) {\n\t\t\tconst regex = new RegExp(`^${pattern.replace(/\\*/g, \".*\")}$`);\n\t\t\tif (regex.test(filePath)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Tests a bash command string against a regex pattern string.\n * Returns false (no match) if the pattern is an invalid regex.\n */\nfunction matchesBashPattern(pattern: string, command: string): boolean {\n\ttry {\n\t\treturn new RegExp(pattern).test(command);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * The path an edit/write call targets.\n *\n * Both tools declare the argument as `path`; `file_path` is accepted only\n * because some models emit that name and the renderers have long taken either.\n * Reading `file_path` alone matched neither tool's schema, so the confirmation\n * prompt read \"edit (unknown)\" and `allowed_write_paths` compared against an\n * empty string - which matches no pattern, blocking every write in any mode\n * that configured one.\n */\nfunction mutationPath(input: unknown): string | undefined {\n\tconst args = input as { path?: unknown; file_path?: unknown } | undefined;\n\tif (typeof args?.path === \"string\" && args.path.length > 0) return args.path;\n\tif (typeof args?.file_path === \"string\" && args.file_path.length > 0) return args.file_path;\n\treturn undefined;\n}\n\nfunction describeTool(event: ToolCallEvent): string {\n\tif (isToolCallEventType(\"bash\", event)) {\n\t\treturn `$ ${event.input.command.replace(/\\s+/g, \" \").slice(0, 100)}`;\n\t}\n\tif (isToolCallEventType(\"edit\", event)) {\n\t\treturn `edit ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (isToolCallEventType(\"write\", event)) {\n\t\treturn `write ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (event.toolName === \"webfetch\") {\n\t\tconst url = (event.input as { url?: string }).url ?? \"(unknown)\";\n\t\treturn `webfetch ${url}`;\n\t}\n\tif (event.toolName === \"websearch\") {\n\t\tconst query = (event.input as { query?: string }).query ?? \"(unknown)\";\n\t\treturn `websearch \"${query}\"`;\n\t}\n\treturn event.toolName;\n}\n\nexport function setupPermissionGate(pi: ExtensionAPI): void {\n\tpi.on(\"tool_call\", async (event: ToolCallEvent, ctx: ExtensionContext): Promise<ToolCallEventResult | undefined> => {\n\t\t// Use the merged config so project-local entries are respected\n\t\tconst config = readMergedConfig(ctx.cwd);\n\t\tconst mode = config.active_mode ?? \"build\";\n\t\tconst modeCfg = config.modes?.[mode];\n\n\t\t// ── Hard enforcement (always applies, regardless of UI) ───────────────────\n\n\t\t// Explicitly denied tools are blocked unconditionally\n\t\tif (modeCfg?.denied_tools?.includes(event.toolName)) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Tool \"${event.toolName}\" is denied in mode \"${mode}\".`,\n\t\t\t};\n\t\t}\n\n\t\t// enabled_tools acts as a strict allowlist: only listed tools may execute\n\t\tif (\n\t\t\tmodeCfg?.enabled_tools &&\n\t\t\tmodeCfg.enabled_tools.length > 0 &&\n\t\t\t!modeCfg.enabled_tools.includes(event.toolName)\n\t\t) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t`Tool \"${event.toolName}\" is not enabled in mode \"${mode}\" ` +\n\t\t\t\t\t`(enabled: ${modeCfg.enabled_tools.join(\", \")}).`,\n\t\t\t};\n\t\t}\n\n\t\t// Bash command-level filtering\n\t\tif (isToolCallEventType(\"bash\", event)) {\n\t\t\tconst command = (event.input as { command?: string }).command ?? \"\";\n\n\t\t\t// denied_bash_commands: block if any pattern matches\n\t\t\tif (modeCfg?.denied_bash_commands?.length) {\n\t\t\t\tfor (const pattern of modeCfg.denied_bash_commands) {\n\t\t\t\t\tif (matchesBashPattern(pattern, command)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\t\treason: `Bash command matches a denied pattern in mode \"${mode}\": ${pattern}`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// allowed_bash_commands: block unless at least one pattern matches\n\t\t\tif (modeCfg?.allowed_bash_commands?.length) {\n\t\t\t\tconst permitted = modeCfg.allowed_bash_commands.some((p) => matchesBashPattern(p, command));\n\t\t\t\tif (!permitted) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t`Bash command is not permitted in mode \"${mode}\". ` +\n\t\t\t\t\t\t\t`Allowed patterns: ${modeCfg.allowed_bash_commands.join(\", \")}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// webfetch host policy (.webtoolsignore). Hard enforcement, always applies:\n\t\t// a blocked host is denied even in headless runs. SSRF/private-address\n\t\t// blocking lives in the webtools binary; this is host allow/deny policy only.\n\t\tif (event.toolName === \"webfetch\") {\n\t\t\tconst url = (event.input as { url?: string }).url ?? \"\";\n\t\t\tconst blockedHost = url ? blockedHostForUrl(ctx.cwd, url) : undefined;\n\t\t\tif (blockedHost) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason: `Host \"${blockedHost}\" is blocked by .webtoolsignore policy.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// ── UI-based permission prompting (interactive sessions only) ─────────────\n\n\t\tif (!GATED_TOOLS.has(event.toolName) || !ctx.hasUI) return;\n\n\t\tconst autoAllow = modeCfg?.auto_allow ?? [];\n\n\t\t// Check allowed_write_paths for write/edit operations\n\t\tif ((event.toolName === \"write\" || event.toolName === \"edit\") && modeCfg?.allowed_write_paths) {\n\t\t\t// Absent path stays blocked: an unidentifiable write cannot be checked\n\t\t\t// against an allowlist, and refusing is the safe direction.\n\t\t\tconst filePath = mutationPath(event.input) ?? \"\";\n\t\t\tif (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths)) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason:\n\t\t\t\t\t\t`Mode \"${mode}\" only allows writes to: ${modeCfg.allowed_write_paths.join(\", \")}. ` +\n\t\t\t\t\t\t`Attempted to ${event.toolName}: ${filePath}. ` +\n\t\t\t\t\t\t`Switch to \"/mode build\" to modify source files.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (autoAllow.includes(event.toolName)) return;\n\n\t\tconst choice = await ctx.ui.select(`Allow: ${describeTool(event)}`, [\n\t\t\t\"Yes (once)\",\n\t\t\t\"No (block)\",\n\t\t\t\"Always (add to auto-allow for this mode)\",\n\t\t]);\n\n\t\tif (!choice || choice.startsWith(\"No\")) {\n\t\t\treturn { block: true, reason: \"Denied by permission gate\" };\n\t\t}\n\n\t\tif (choice.startsWith(\"Always\")) {\n\t\t\t// Write \"always\" choices to the global config only\n\t\t\tconst latest = readConfig();\n\t\t\tconst currentMode = latest.active_mode ?? \"build\";\n\t\t\tlatest.modes ??= {};\n\t\t\tlatest.modes[currentMode] ??= {};\n\t\t\tlatest.modes[currentMode].auto_allow = Array.from(\n\t\t\t\tnew Set([...(latest.modes[currentMode].auto_allow ?? []), event.toolName]),\n\t\t\t);\n\t\t\twriteConfig(latest);\n\t\t\tctx.ui.notify(`\"${event.toolName}\" added to auto-allow for mode \"${currentMode}\"`, \"info\");\n\t\t}\n\t});\n}\n"]}
1
+ {"version":3,"file":"permission-gate.d.ts","sourceRoot":"","sources":["../../../src/extensions/core/permission-gate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACX,YAAY,EAIZ,MAAM,gCAAgC,CAAC;AAuGxC,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA0H1D","sourcesContent":["/**\n * Permission gate — prompts before bash/write/edit/webfetch/websearch; checks\n * modes.{mode}.auto_allow from the merged (global + project) config; persists\n * \"always\" choices back to the global config. Hard enforcement (denied tools,\n * enabled_tools allowlists, bash command patterns, .webtoolsignore hosts)\n * applies even without a UI.\n */\n\nimport { isAbsolute, relative } from \"node:path\";\nimport type {\n\tExtensionAPI,\n\tExtensionContext,\n\tToolCallEvent,\n\tToolCallEventResult,\n} from \"../../core/extensions/types.js\";\nimport { isToolCallEventType } from \"../../core/extensions/types.js\";\nimport { blockedHostForUrl } from \"../../core/tools/webtools-shared.js\";\nimport { readConfig, readMergedConfig, writeConfig } from \"./config.js\";\n\nconst GATED_TOOLS = new Set([\"bash\", \"write\", \"edit\", \"webfetch\", \"websearch\"]);\n\n/**\n * Checks if a file path matches any of the mode's `allowed_write_paths`.\n * Supports glob patterns with `*` and exact paths.\n *\n * Both sides are normalized to forward slashes first. Patterns are written with\n * `/`, but the paths a model is handed come from `relative()`, which yields\n * backslashes on Windows — and because this check runs *before* `auto_allow`, a\n * non-match is a hard block rather than a prompt. Without normalizing, a mode\n * that sets `allowed_write_paths` could not write anything at all on Windows.\n *\n * An absolute path is also tried in its cwd-relative form, so a model that\n * resolves the relative path it was given still matches. A target outside cwd\n * relativizes to `../…` and correctly fails to match.\n */\nfunction matchesAllowedPath(filePath: string, allowedPatterns: string[], cwd: string): boolean {\n\tif (allowedPatterns.length === 0) return true;\n\tif (!filePath) return false;\n\n\tconst toPosix = (value: string): string => value.replace(/\\\\/g, \"/\");\n\n\tconst candidates = new Set<string>([toPosix(filePath)]);\n\tif (isAbsolute(filePath)) {\n\t\tconst rel = toPosix(relative(cwd, filePath));\n\t\tif (rel) candidates.add(rel);\n\t}\n\n\tfor (const pattern of allowedPatterns) {\n\t\tconst normalizedPattern = toPosix(pattern);\n\t\tif (candidates.has(normalizedPattern)) return true;\n\t\tif (!normalizedPattern.includes(\"*\")) continue;\n\t\t// Escape regex metacharacters before letting `*` mean \"any run of chars\",\n\t\t// so a pattern like `.hoocode/plans/*` cannot also match `Xhoocode/...`.\n\t\tconst source = `^${normalizedPattern.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\").replace(/\\*/g, \".*\")}$`;\n\t\tlet regex: RegExp;\n\t\ttry {\n\t\t\tregex = new RegExp(source);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const candidate of candidates) {\n\t\t\tif (regex.test(candidate)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Tests a bash command string against a regex pattern string.\n * Returns false (no match) if the pattern is an invalid regex.\n */\nfunction matchesBashPattern(pattern: string, command: string): boolean {\n\ttry {\n\t\treturn new RegExp(pattern).test(command);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * The path an edit/write call targets.\n *\n * Both tools declare the argument as `path`; `file_path` is accepted only\n * because some models emit that name and the renderers have long taken either.\n * Reading `file_path` alone matched neither tool's schema, so the confirmation\n * prompt read \"edit (unknown)\" and `allowed_write_paths` compared against an\n * empty string - which matches no pattern, blocking every write in any mode\n * that configured one.\n */\nfunction mutationPath(input: unknown): string | undefined {\n\tconst args = input as { path?: unknown; file_path?: unknown } | undefined;\n\tif (typeof args?.path === \"string\" && args.path.length > 0) return args.path;\n\tif (typeof args?.file_path === \"string\" && args.file_path.length > 0) return args.file_path;\n\treturn undefined;\n}\n\nfunction describeTool(event: ToolCallEvent): string {\n\tif (isToolCallEventType(\"bash\", event)) {\n\t\treturn `$ ${event.input.command.replace(/\\s+/g, \" \").slice(0, 100)}`;\n\t}\n\tif (isToolCallEventType(\"edit\", event)) {\n\t\treturn `edit ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (isToolCallEventType(\"write\", event)) {\n\t\treturn `write ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (event.toolName === \"webfetch\") {\n\t\tconst url = (event.input as { url?: string }).url ?? \"(unknown)\";\n\t\treturn `webfetch ${url}`;\n\t}\n\tif (event.toolName === \"websearch\") {\n\t\tconst query = (event.input as { query?: string }).query ?? \"(unknown)\";\n\t\treturn `websearch \"${query}\"`;\n\t}\n\treturn event.toolName;\n}\n\nexport function setupPermissionGate(pi: ExtensionAPI): void {\n\tpi.on(\"tool_call\", async (event: ToolCallEvent, ctx: ExtensionContext): Promise<ToolCallEventResult | undefined> => {\n\t\t// Use the merged config so project-local entries are respected\n\t\tconst config = readMergedConfig(ctx.cwd);\n\t\tconst mode = config.active_mode ?? \"build\";\n\t\tconst modeCfg = config.modes?.[mode];\n\n\t\t// ── Hard enforcement (always applies, regardless of UI) ───────────────────\n\n\t\t// Explicitly denied tools are blocked unconditionally\n\t\tif (modeCfg?.denied_tools?.includes(event.toolName)) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Tool \"${event.toolName}\" is denied in mode \"${mode}\".`,\n\t\t\t};\n\t\t}\n\n\t\t// enabled_tools acts as a strict allowlist: only listed tools may execute\n\t\tif (\n\t\t\tmodeCfg?.enabled_tools &&\n\t\t\tmodeCfg.enabled_tools.length > 0 &&\n\t\t\t!modeCfg.enabled_tools.includes(event.toolName)\n\t\t) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t`Tool \"${event.toolName}\" is not enabled in mode \"${mode}\" ` +\n\t\t\t\t\t`(enabled: ${modeCfg.enabled_tools.join(\", \")}).`,\n\t\t\t};\n\t\t}\n\n\t\t// Bash command-level filtering\n\t\tif (isToolCallEventType(\"bash\", event)) {\n\t\t\tconst command = (event.input as { command?: string }).command ?? \"\";\n\n\t\t\t// denied_bash_commands: block if any pattern matches\n\t\t\tif (modeCfg?.denied_bash_commands?.length) {\n\t\t\t\tfor (const pattern of modeCfg.denied_bash_commands) {\n\t\t\t\t\tif (matchesBashPattern(pattern, command)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\t\treason: `Bash command matches a denied pattern in mode \"${mode}\": ${pattern}`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// allowed_bash_commands: block unless at least one pattern matches\n\t\t\tif (modeCfg?.allowed_bash_commands?.length) {\n\t\t\t\tconst permitted = modeCfg.allowed_bash_commands.some((p) => matchesBashPattern(p, command));\n\t\t\t\tif (!permitted) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t`Bash command is not permitted in mode \"${mode}\". ` +\n\t\t\t\t\t\t\t`Allowed patterns: ${modeCfg.allowed_bash_commands.join(\", \")}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// webfetch host policy (.webtoolsignore). Hard enforcement, always applies:\n\t\t// a blocked host is denied even in headless runs. SSRF/private-address\n\t\t// blocking lives in the webtools binary; this is host allow/deny policy only.\n\t\tif (event.toolName === \"webfetch\") {\n\t\t\tconst url = (event.input as { url?: string }).url ?? \"\";\n\t\t\tconst blockedHost = url ? blockedHostForUrl(ctx.cwd, url) : undefined;\n\t\t\tif (blockedHost) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason: `Host \"${blockedHost}\" is blocked by .webtoolsignore policy.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// ── UI-based permission prompting (interactive sessions only) ─────────────\n\n\t\tif (!GATED_TOOLS.has(event.toolName) || !ctx.hasUI) return;\n\n\t\tconst autoAllow = modeCfg?.auto_allow ?? [];\n\n\t\t// Check allowed_write_paths for write/edit operations\n\t\tif ((event.toolName === \"write\" || event.toolName === \"edit\") && modeCfg?.allowed_write_paths) {\n\t\t\t// Absent path stays blocked: an unidentifiable write cannot be checked\n\t\t\t// against an allowlist, and refusing is the safe direction.\n\t\t\tconst filePath = mutationPath(event.input) ?? \"\";\n\t\t\tif (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths, ctx.cwd)) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason:\n\t\t\t\t\t\t`Mode \"${mode}\" only allows writes to: ${modeCfg.allowed_write_paths.join(\", \")}. ` +\n\t\t\t\t\t\t`Attempted to ${event.toolName}: ${filePath}. ` +\n\t\t\t\t\t\t`Switch to \"/mode build\" to modify source files.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (autoAllow.includes(event.toolName)) return;\n\n\t\tconst choice = await ctx.ui.select(`Allow: ${describeTool(event)}`, [\n\t\t\t\"Yes (once)\",\n\t\t\t\"No (block)\",\n\t\t\t\"Always (add to auto-allow for this mode)\",\n\t\t]);\n\n\t\tif (!choice || choice.startsWith(\"No\")) {\n\t\t\treturn { block: true, reason: \"Denied by permission gate\" };\n\t\t}\n\n\t\tif (choice.startsWith(\"Always\")) {\n\t\t\t// Write \"always\" choices to the global config only\n\t\t\tconst latest = readConfig();\n\t\t\tconst currentMode = latest.active_mode ?? \"build\";\n\t\t\tlatest.modes ??= {};\n\t\t\tlatest.modes[currentMode] ??= {};\n\t\t\tlatest.modes[currentMode].auto_allow = Array.from(\n\t\t\t\tnew Set([...(latest.modes[currentMode].auto_allow ?? []), event.toolName]),\n\t\t\t);\n\t\t\twriteConfig(latest);\n\t\t\tctx.ui.notify(`\"${event.toolName}\" added to auto-allow for mode \"${currentMode}\"`, \"info\");\n\t\t}\n\t});\n}\n"]}
@@ -5,25 +5,55 @@
5
5
  * enabled_tools allowlists, bash command patterns, .webtoolsignore hosts)
6
6
  * applies even without a UI.
7
7
  */
8
+ import { isAbsolute, relative } from "node:path";
8
9
  import { isToolCallEventType } from "../../core/extensions/types.js";
9
10
  import { blockedHostForUrl } from "../../core/tools/webtools-shared.js";
10
11
  import { readConfig, readMergedConfig, writeConfig } from "./config.js";
11
12
  const GATED_TOOLS = new Set(["bash", "write", "edit", "webfetch", "websearch"]);
12
13
  /**
13
- * Checks if a file path matches any of the allowed patterns.
14
- * Supports glob patterns with * and exact paths.
14
+ * Checks if a file path matches any of the mode's `allowed_write_paths`.
15
+ * Supports glob patterns with `*` and exact paths.
16
+ *
17
+ * Both sides are normalized to forward slashes first. Patterns are written with
18
+ * `/`, but the paths a model is handed come from `relative()`, which yields
19
+ * backslashes on Windows — and because this check runs *before* `auto_allow`, a
20
+ * non-match is a hard block rather than a prompt. Without normalizing, a mode
21
+ * that sets `allowed_write_paths` could not write anything at all on Windows.
22
+ *
23
+ * An absolute path is also tried in its cwd-relative form, so a model that
24
+ * resolves the relative path it was given still matches. A target outside cwd
25
+ * relativizes to `../…` and correctly fails to match.
15
26
  */
16
- function matchesAllowedPath(filePath, allowedPatterns) {
27
+ function matchesAllowedPath(filePath, allowedPatterns, cwd) {
17
28
  if (allowedPatterns.length === 0)
18
29
  return true;
30
+ if (!filePath)
31
+ return false;
32
+ const toPosix = (value) => value.replace(/\\/g, "/");
33
+ const candidates = new Set([toPosix(filePath)]);
34
+ if (isAbsolute(filePath)) {
35
+ const rel = toPosix(relative(cwd, filePath));
36
+ if (rel)
37
+ candidates.add(rel);
38
+ }
19
39
  for (const pattern of allowedPatterns) {
20
- // Exact match
21
- if (pattern === filePath)
40
+ const normalizedPattern = toPosix(pattern);
41
+ if (candidates.has(normalizedPattern))
22
42
  return true;
23
- // Glob pattern matching for *
24
- if (pattern.includes("*")) {
25
- const regex = new RegExp(`^${pattern.replace(/\*/g, ".*")}$`);
26
- if (regex.test(filePath))
43
+ if (!normalizedPattern.includes("*"))
44
+ continue;
45
+ // Escape regex metacharacters before letting `*` mean "any run of chars",
46
+ // so a pattern like `.hoocode/plans/*` cannot also match `Xhoocode/...`.
47
+ const source = `^${normalizedPattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`;
48
+ let regex;
49
+ try {
50
+ regex = new RegExp(source);
51
+ }
52
+ catch {
53
+ continue;
54
+ }
55
+ for (const candidate of candidates) {
56
+ if (regex.test(candidate))
27
57
  return true;
28
58
  }
29
59
  }
@@ -151,7 +181,7 @@ export function setupPermissionGate(pi) {
151
181
  // Absent path stays blocked: an unidentifiable write cannot be checked
152
182
  // against an allowlist, and refusing is the safe direction.
153
183
  const filePath = mutationPath(event.input) ?? "";
154
- if (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths)) {
184
+ if (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths, ctx.cwd)) {
155
185
  return {
156
186
  block: true,
157
187
  reason: `Mode "${mode}" only allows writes to: ${modeCfg.allowed_write_paths.join(", ")}. ` +
@@ -1 +1 @@
1
- {"version":3,"file":"permission-gate.js","sourceRoot":"","sources":["../../../src/extensions/core/permission-gate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AAEhF;;;GAGG;AACH,SAAS,kBAAkB,CAAC,QAAgB,EAAE,eAAyB,EAAW;IACjF,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACvC,cAAc;QACd,IAAI,OAAO,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACtC,8BAA8B;QAC9B,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,C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K,CAAC,QAAQ,CAAC;YAAE,OAAO;QAE/C,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,YAAY,CAAC,KAAK,CAAC,EAAE,EAAE;YACnE,YAAY;YACZ,YAAY;YACZ,0CAA0C;SAC1C,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,2BAA2B,EAAE,CAAC;QAC7D,CAAC;QAED,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,mDAAmD;YACnD,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;YAC5B,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,OAAO,CAAC;YAClD,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACjC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAChD,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAC1E,CAAC;YACF,WAAW,CAAC,MAAM,CAAC,CAAC;YACpB,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,mCAAmC,WAAW,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5F,CAAC;IAAA,CACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Permission gate — prompts before bash/write/edit/webfetch/websearch; checks\n * modes.{mode}.auto_allow from the merged (global + project) config; persists\n * \"always\" choices back to the global config. Hard enforcement (denied tools,\n * enabled_tools allowlists, bash command patterns, .webtoolsignore hosts)\n * applies even without a UI.\n */\n\nimport type {\n\tExtensionAPI,\n\tExtensionContext,\n\tToolCallEvent,\n\tToolCallEventResult,\n} from \"../../core/extensions/types.js\";\nimport { isToolCallEventType } from \"../../core/extensions/types.js\";\nimport { blockedHostForUrl } from \"../../core/tools/webtools-shared.js\";\nimport { readConfig, readMergedConfig, writeConfig } from \"./config.js\";\n\nconst GATED_TOOLS = new Set([\"bash\", \"write\", \"edit\", \"webfetch\", \"websearch\"]);\n\n/**\n * Checks if a file path matches any of the allowed patterns.\n * Supports glob patterns with * and exact paths.\n */\nfunction matchesAllowedPath(filePath: string, allowedPatterns: string[]): boolean {\n\tif (allowedPatterns.length === 0) return true;\n\tfor (const pattern of allowedPatterns) {\n\t\t// Exact match\n\t\tif (pattern === filePath) return true;\n\t\t// Glob pattern matching for *\n\t\tif (pattern.includes(\"*\")) {\n\t\t\tconst regex = new RegExp(`^${pattern.replace(/\\*/g, \".*\")}$`);\n\t\t\tif (regex.test(filePath)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Tests a bash command string against a regex pattern string.\n * Returns false (no match) if the pattern is an invalid regex.\n */\nfunction matchesBashPattern(pattern: string, command: string): boolean {\n\ttry {\n\t\treturn new RegExp(pattern).test(command);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * The path an edit/write call targets.\n *\n * Both tools declare the argument as `path`; `file_path` is accepted only\n * because some models emit that name and the renderers have long taken either.\n * Reading `file_path` alone matched neither tool's schema, so the confirmation\n * prompt read \"edit (unknown)\" and `allowed_write_paths` compared against an\n * empty string - which matches no pattern, blocking every write in any mode\n * that configured one.\n */\nfunction mutationPath(input: unknown): string | undefined {\n\tconst args = input as { path?: unknown; file_path?: unknown } | undefined;\n\tif (typeof args?.path === \"string\" && args.path.length > 0) return args.path;\n\tif (typeof args?.file_path === \"string\" && args.file_path.length > 0) return args.file_path;\n\treturn undefined;\n}\n\nfunction describeTool(event: ToolCallEvent): string {\n\tif (isToolCallEventType(\"bash\", event)) {\n\t\treturn `$ ${event.input.command.replace(/\\s+/g, \" \").slice(0, 100)}`;\n\t}\n\tif (isToolCallEventType(\"edit\", event)) {\n\t\treturn `edit ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (isToolCallEventType(\"write\", event)) {\n\t\treturn `write ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (event.toolName === \"webfetch\") {\n\t\tconst url = (event.input as { url?: string }).url ?? \"(unknown)\";\n\t\treturn `webfetch ${url}`;\n\t}\n\tif (event.toolName === \"websearch\") {\n\t\tconst query = (event.input as { query?: string }).query ?? \"(unknown)\";\n\t\treturn `websearch \"${query}\"`;\n\t}\n\treturn event.toolName;\n}\n\nexport function setupPermissionGate(pi: ExtensionAPI): void {\n\tpi.on(\"tool_call\", async (event: ToolCallEvent, ctx: ExtensionContext): Promise<ToolCallEventResult | undefined> => {\n\t\t// Use the merged config so project-local entries are respected\n\t\tconst config = readMergedConfig(ctx.cwd);\n\t\tconst mode = config.active_mode ?? \"build\";\n\t\tconst modeCfg = config.modes?.[mode];\n\n\t\t// ── Hard enforcement (always applies, regardless of UI) ───────────────────\n\n\t\t// Explicitly denied tools are blocked unconditionally\n\t\tif (modeCfg?.denied_tools?.includes(event.toolName)) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Tool \"${event.toolName}\" is denied in mode \"${mode}\".`,\n\t\t\t};\n\t\t}\n\n\t\t// enabled_tools acts as a strict allowlist: only listed tools may execute\n\t\tif (\n\t\t\tmodeCfg?.enabled_tools &&\n\t\t\tmodeCfg.enabled_tools.length > 0 &&\n\t\t\t!modeCfg.enabled_tools.includes(event.toolName)\n\t\t) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t`Tool \"${event.toolName}\" is not enabled in mode \"${mode}\" ` +\n\t\t\t\t\t`(enabled: ${modeCfg.enabled_tools.join(\", \")}).`,\n\t\t\t};\n\t\t}\n\n\t\t// Bash command-level filtering\n\t\tif (isToolCallEventType(\"bash\", event)) {\n\t\t\tconst command = (event.input as { command?: string }).command ?? \"\";\n\n\t\t\t// denied_bash_commands: block if any pattern matches\n\t\t\tif (modeCfg?.denied_bash_commands?.length) {\n\t\t\t\tfor (const pattern of modeCfg.denied_bash_commands) {\n\t\t\t\t\tif (matchesBashPattern(pattern, command)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\t\treason: `Bash command matches a denied pattern in mode \"${mode}\": ${pattern}`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// allowed_bash_commands: block unless at least one pattern matches\n\t\t\tif (modeCfg?.allowed_bash_commands?.length) {\n\t\t\t\tconst permitted = modeCfg.allowed_bash_commands.some((p) => matchesBashPattern(p, command));\n\t\t\t\tif (!permitted) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t`Bash command is not permitted in mode \"${mode}\". ` +\n\t\t\t\t\t\t\t`Allowed patterns: ${modeCfg.allowed_bash_commands.join(\", \")}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// webfetch host policy (.webtoolsignore). Hard enforcement, always applies:\n\t\t// a blocked host is denied even in headless runs. SSRF/private-address\n\t\t// blocking lives in the webtools binary; this is host allow/deny policy only.\n\t\tif (event.toolName === \"webfetch\") {\n\t\t\tconst url = (event.input as { url?: string }).url ?? \"\";\n\t\t\tconst blockedHost = url ? blockedHostForUrl(ctx.cwd, url) : undefined;\n\t\t\tif (blockedHost) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason: `Host \"${blockedHost}\" is blocked by .webtoolsignore policy.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// ── UI-based permission prompting (interactive sessions only) ─────────────\n\n\t\tif (!GATED_TOOLS.has(event.toolName) || !ctx.hasUI) return;\n\n\t\tconst autoAllow = modeCfg?.auto_allow ?? [];\n\n\t\t// Check allowed_write_paths for write/edit operations\n\t\tif ((event.toolName === \"write\" || event.toolName === \"edit\") && modeCfg?.allowed_write_paths) {\n\t\t\t// Absent path stays blocked: an unidentifiable write cannot be checked\n\t\t\t// against an allowlist, and refusing is the safe direction.\n\t\t\tconst filePath = mutationPath(event.input) ?? \"\";\n\t\t\tif (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths)) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason:\n\t\t\t\t\t\t`Mode \"${mode}\" only allows writes to: ${modeCfg.allowed_write_paths.join(\", \")}. ` +\n\t\t\t\t\t\t`Attempted to ${event.toolName}: ${filePath}. ` +\n\t\t\t\t\t\t`Switch to \"/mode build\" to modify source files.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (autoAllow.includes(event.toolName)) return;\n\n\t\tconst choice = await ctx.ui.select(`Allow: ${describeTool(event)}`, [\n\t\t\t\"Yes (once)\",\n\t\t\t\"No (block)\",\n\t\t\t\"Always (add to auto-allow for this mode)\",\n\t\t]);\n\n\t\tif (!choice || choice.startsWith(\"No\")) {\n\t\t\treturn { block: true, reason: \"Denied by permission gate\" };\n\t\t}\n\n\t\tif (choice.startsWith(\"Always\")) {\n\t\t\t// Write \"always\" choices to the global config only\n\t\t\tconst latest = readConfig();\n\t\t\tconst currentMode = latest.active_mode ?? \"build\";\n\t\t\tlatest.modes ??= {};\n\t\t\tlatest.modes[currentMode] ??= {};\n\t\t\tlatest.modes[currentMode].auto_allow = Array.from(\n\t\t\t\tnew Set([...(latest.modes[currentMode].auto_allow ?? []), event.toolName]),\n\t\t\t);\n\t\t\twriteConfig(latest);\n\t\t\tctx.ui.notify(`\"${event.toolName}\" added to auto-allow for mode \"${currentMode}\"`, \"info\");\n\t\t}\n\t});\n}\n"]}
1
+ {"version":3,"file":"permission-gate.js","sourceRoot":"","sources":["../../../src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,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAC1E,CAAC;YACF,WAAW,CAAC,MAAM,CAAC,CAAC;YACpB,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,mCAAmC,WAAW,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5F,CAAC;IAAA,CACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Permission gate — prompts before bash/write/edit/webfetch/websearch; checks\n * modes.{mode}.auto_allow from the merged (global + project) config; persists\n * \"always\" choices back to the global config. Hard enforcement (denied tools,\n * enabled_tools allowlists, bash command patterns, .webtoolsignore hosts)\n * applies even without a UI.\n */\n\nimport { isAbsolute, relative } from \"node:path\";\nimport type {\n\tExtensionAPI,\n\tExtensionContext,\n\tToolCallEvent,\n\tToolCallEventResult,\n} from \"../../core/extensions/types.js\";\nimport { isToolCallEventType } from \"../../core/extensions/types.js\";\nimport { blockedHostForUrl } from \"../../core/tools/webtools-shared.js\";\nimport { readConfig, readMergedConfig, writeConfig } from \"./config.js\";\n\nconst GATED_TOOLS = new Set([\"bash\", \"write\", \"edit\", \"webfetch\", \"websearch\"]);\n\n/**\n * Checks if a file path matches any of the mode's `allowed_write_paths`.\n * Supports glob patterns with `*` and exact paths.\n *\n * Both sides are normalized to forward slashes first. Patterns are written with\n * `/`, but the paths a model is handed come from `relative()`, which yields\n * backslashes on Windows — and because this check runs *before* `auto_allow`, a\n * non-match is a hard block rather than a prompt. Without normalizing, a mode\n * that sets `allowed_write_paths` could not write anything at all on Windows.\n *\n * An absolute path is also tried in its cwd-relative form, so a model that\n * resolves the relative path it was given still matches. A target outside cwd\n * relativizes to `../…` and correctly fails to match.\n */\nfunction matchesAllowedPath(filePath: string, allowedPatterns: string[], cwd: string): boolean {\n\tif (allowedPatterns.length === 0) return true;\n\tif (!filePath) return false;\n\n\tconst toPosix = (value: string): string => value.replace(/\\\\/g, \"/\");\n\n\tconst candidates = new Set<string>([toPosix(filePath)]);\n\tif (isAbsolute(filePath)) {\n\t\tconst rel = toPosix(relative(cwd, filePath));\n\t\tif (rel) candidates.add(rel);\n\t}\n\n\tfor (const pattern of allowedPatterns) {\n\t\tconst normalizedPattern = toPosix(pattern);\n\t\tif (candidates.has(normalizedPattern)) return true;\n\t\tif (!normalizedPattern.includes(\"*\")) continue;\n\t\t// Escape regex metacharacters before letting `*` mean \"any run of chars\",\n\t\t// so a pattern like `.hoocode/plans/*` cannot also match `Xhoocode/...`.\n\t\tconst source = `^${normalizedPattern.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\").replace(/\\*/g, \".*\")}$`;\n\t\tlet regex: RegExp;\n\t\ttry {\n\t\t\tregex = new RegExp(source);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const candidate of candidates) {\n\t\t\tif (regex.test(candidate)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Tests a bash command string against a regex pattern string.\n * Returns false (no match) if the pattern is an invalid regex.\n */\nfunction matchesBashPattern(pattern: string, command: string): boolean {\n\ttry {\n\t\treturn new RegExp(pattern).test(command);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * The path an edit/write call targets.\n *\n * Both tools declare the argument as `path`; `file_path` is accepted only\n * because some models emit that name and the renderers have long taken either.\n * Reading `file_path` alone matched neither tool's schema, so the confirmation\n * prompt read \"edit (unknown)\" and `allowed_write_paths` compared against an\n * empty string - which matches no pattern, blocking every write in any mode\n * that configured one.\n */\nfunction mutationPath(input: unknown): string | undefined {\n\tconst args = input as { path?: unknown; file_path?: unknown } | undefined;\n\tif (typeof args?.path === \"string\" && args.path.length > 0) return args.path;\n\tif (typeof args?.file_path === \"string\" && args.file_path.length > 0) return args.file_path;\n\treturn undefined;\n}\n\nfunction describeTool(event: ToolCallEvent): string {\n\tif (isToolCallEventType(\"bash\", event)) {\n\t\treturn `$ ${event.input.command.replace(/\\s+/g, \" \").slice(0, 100)}`;\n\t}\n\tif (isToolCallEventType(\"edit\", event)) {\n\t\treturn `edit ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (isToolCallEventType(\"write\", event)) {\n\t\treturn `write ${mutationPath(event.input) ?? \"(unknown)\"}`;\n\t}\n\tif (event.toolName === \"webfetch\") {\n\t\tconst url = (event.input as { url?: string }).url ?? \"(unknown)\";\n\t\treturn `webfetch ${url}`;\n\t}\n\tif (event.toolName === \"websearch\") {\n\t\tconst query = (event.input as { query?: string }).query ?? \"(unknown)\";\n\t\treturn `websearch \"${query}\"`;\n\t}\n\treturn event.toolName;\n}\n\nexport function setupPermissionGate(pi: ExtensionAPI): void {\n\tpi.on(\"tool_call\", async (event: ToolCallEvent, ctx: ExtensionContext): Promise<ToolCallEventResult | undefined> => {\n\t\t// Use the merged config so project-local entries are respected\n\t\tconst config = readMergedConfig(ctx.cwd);\n\t\tconst mode = config.active_mode ?? \"build\";\n\t\tconst modeCfg = config.modes?.[mode];\n\n\t\t// ── Hard enforcement (always applies, regardless of UI) ───────────────────\n\n\t\t// Explicitly denied tools are blocked unconditionally\n\t\tif (modeCfg?.denied_tools?.includes(event.toolName)) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Tool \"${event.toolName}\" is denied in mode \"${mode}\".`,\n\t\t\t};\n\t\t}\n\n\t\t// enabled_tools acts as a strict allowlist: only listed tools may execute\n\t\tif (\n\t\t\tmodeCfg?.enabled_tools &&\n\t\t\tmodeCfg.enabled_tools.length > 0 &&\n\t\t\t!modeCfg.enabled_tools.includes(event.toolName)\n\t\t) {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason:\n\t\t\t\t\t`Tool \"${event.toolName}\" is not enabled in mode \"${mode}\" ` +\n\t\t\t\t\t`(enabled: ${modeCfg.enabled_tools.join(\", \")}).`,\n\t\t\t};\n\t\t}\n\n\t\t// Bash command-level filtering\n\t\tif (isToolCallEventType(\"bash\", event)) {\n\t\t\tconst command = (event.input as { command?: string }).command ?? \"\";\n\n\t\t\t// denied_bash_commands: block if any pattern matches\n\t\t\tif (modeCfg?.denied_bash_commands?.length) {\n\t\t\t\tfor (const pattern of modeCfg.denied_bash_commands) {\n\t\t\t\t\tif (matchesBashPattern(pattern, command)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\t\treason: `Bash command matches a denied pattern in mode \"${mode}\": ${pattern}`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// allowed_bash_commands: block unless at least one pattern matches\n\t\t\tif (modeCfg?.allowed_bash_commands?.length) {\n\t\t\t\tconst permitted = modeCfg.allowed_bash_commands.some((p) => matchesBashPattern(p, command));\n\t\t\t\tif (!permitted) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tblock: true,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t`Bash command is not permitted in mode \"${mode}\". ` +\n\t\t\t\t\t\t\t`Allowed patterns: ${modeCfg.allowed_bash_commands.join(\", \")}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// webfetch host policy (.webtoolsignore). Hard enforcement, always applies:\n\t\t// a blocked host is denied even in headless runs. SSRF/private-address\n\t\t// blocking lives in the webtools binary; this is host allow/deny policy only.\n\t\tif (event.toolName === \"webfetch\") {\n\t\t\tconst url = (event.input as { url?: string }).url ?? \"\";\n\t\t\tconst blockedHost = url ? blockedHostForUrl(ctx.cwd, url) : undefined;\n\t\t\tif (blockedHost) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason: `Host \"${blockedHost}\" is blocked by .webtoolsignore policy.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// ── UI-based permission prompting (interactive sessions only) ─────────────\n\n\t\tif (!GATED_TOOLS.has(event.toolName) || !ctx.hasUI) return;\n\n\t\tconst autoAllow = modeCfg?.auto_allow ?? [];\n\n\t\t// Check allowed_write_paths for write/edit operations\n\t\tif ((event.toolName === \"write\" || event.toolName === \"edit\") && modeCfg?.allowed_write_paths) {\n\t\t\t// Absent path stays blocked: an unidentifiable write cannot be checked\n\t\t\t// against an allowlist, and refusing is the safe direction.\n\t\t\tconst filePath = mutationPath(event.input) ?? \"\";\n\t\t\tif (!matchesAllowedPath(filePath, modeCfg.allowed_write_paths, ctx.cwd)) {\n\t\t\t\treturn {\n\t\t\t\t\tblock: true,\n\t\t\t\t\treason:\n\t\t\t\t\t\t`Mode \"${mode}\" only allows writes to: ${modeCfg.allowed_write_paths.join(\", \")}. ` +\n\t\t\t\t\t\t`Attempted to ${event.toolName}: ${filePath}. ` +\n\t\t\t\t\t\t`Switch to \"/mode build\" to modify source files.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (autoAllow.includes(event.toolName)) return;\n\n\t\tconst choice = await ctx.ui.select(`Allow: ${describeTool(event)}`, [\n\t\t\t\"Yes (once)\",\n\t\t\t\"No (block)\",\n\t\t\t\"Always (add to auto-allow for this mode)\",\n\t\t]);\n\n\t\tif (!choice || choice.startsWith(\"No\")) {\n\t\t\treturn { block: true, reason: \"Denied by permission gate\" };\n\t\t}\n\n\t\tif (choice.startsWith(\"Always\")) {\n\t\t\t// Write \"always\" choices to the global config only\n\t\t\tconst latest = readConfig();\n\t\t\tconst currentMode = latest.active_mode ?? \"build\";\n\t\t\tlatest.modes ??= {};\n\t\t\tlatest.modes[currentMode] ??= {};\n\t\t\tlatest.modes[currentMode].auto_allow = Array.from(\n\t\t\t\tnew Set([...(latest.modes[currentMode].auto_allow ?? []), event.toolName]),\n\t\t\t);\n\t\t\twriteConfig(latest);\n\t\t\tctx.ui.notify(`\"${event.toolName}\" added to auto-allow for mode \"${currentMode}\"`, \"info\");\n\t\t}\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"init-templates.generated.d.ts","sourceRoot":"","sources":["../src/init-templates.generated.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,EAAE,MAC+Z,CAAC;AAEtc,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKjD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAE5D,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAUzD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAanD,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOlD,CAAC","sourcesContent":["// AUTO-GENERATED by scripts/embed-templates.mjs — do not edit.\n// Source of truth: packages/coding-agent/templates/**\n// Regenerated on every `npm run build`.\n\nexport const EMBEDDED_DEFAULT_CONFIG: string =\n\t'{\\n \"version\": \"1.0\",\\n \"active_mode\": \"build\",\\n \"llm\": {\\n \"default_provider\": \"anthropic\",\\n \"providers\": {\\n \"anthropic\": { \"api_key_env\": \"ANTHROPIC_API_KEY\" },\\n \"openai\": { \"api_key_env\": \"OPENAI_API_KEY\" }\\n }\\n },\\n \"modes\": {\\n \"ask\": { \"auto_allow\": [\"read\"] },\\n \"plan\": { \"auto_allow\": [\"read\", \"write\"] },\\n \"build\": { \"auto_allow\": [\"read\"] },\\n \"debug\": { \"auto_allow\": [\"read\", \"bash\"] }\\n }\\n}\\n';\n\nexport const EMBEDDED_MODES: Record<string, string> = {\n\task: \"You are in **ask mode** — read-only Q&A.\\n\\nPermitted: read files, search the codebase, explain code, trace logic, compare approaches, debug conceptually.\\nForbidden: edit files, write files, run commands that modify state.\\n\\nWhen answering:\\n- Cite file paths and line numbers.\\n- Prefer precise over verbose.\\n- If a question requires a code change to answer properly, describe the change; do not apply it.\\n- If the user asks you to edit something, decline and suggest switching to build mode with `/mode build`.\\n\",\n\tbuild: \"You are in **build mode** — implement carefully, one step at a time.\\n\\nRules:\\n- **One tool per turn.** Plan the action, call the tool, wait for the result before proceeding.\\n- **Read before editing.** Never write to a file you have not read in this session.\\n- **Show diffs** before applying non-trivial edits; wait for implicit acceptance.\\n- **Dangerous ops** (delete, force-push, drop table, rm -rf): state what you are about to do and wait for explicit confirmation.\\n- **Match existing style** — indentation, naming, import order.\\n- **Run tests** after every logical unit of change. Fix failures before continuing.\\n\",\n\tdebug: \"You are in **debug mode** — root-cause analysis only, no file modifications.\\n\\nProcess:\\n1. **Gather evidence** — read logs, error traces, and relevant source. Run safe diagnostic commands (search, read, non-mutating shell commands).\\n2. **Reproduce** — identify the minimal condition that triggers the bug.\\n3. **Trace** — follow the full call path from entry point to failure site, citing file and line at each step.\\n4. **State the root cause** in one clear sentence.\\n5. **Describe the fix** — files, lines, and what to change — but do not apply it.\\n\\nForbidden: edit or write any file. To apply a fix, switch to build mode with `/mode build`.\\n\",\n\tplan: 'You are in **plan mode** — explore and design, no source edits.\\n\\nYour job: produce a complete, actionable implementation plan.\\n\\nSteps:\\n1. Read relevant files and ask clarifying questions before drafting.\\n2. Write the finished plan to `{{PLAN_PATH}}` with these sections:\\n - **Goal** — one sentence.\\n - **Files to modify** — path, line range, what changes.\\n - **New files** — path, purpose.\\n - **Tests** — what to add or update.\\n - **Verification** — commands to confirm correctness.\\n3. After writing the plan, tell the user: \"Plan written to `{{PLAN_PATH}}`. Run\\n `/grill` to stress-test it, then `/approve` to execute it step by step or\\n `/goal` to work toward it autonomously.\" Recommend `/grill` first whenever the\\n plan carries real risk — it surfaces weak assumptions before any code changes.\\n\\nForbidden: edit any source file. Only `{{PLAN_PATH}}` may be written.\\n',\n};\n\nexport const EMBEDDED_PROFILES: Record<string, string> = {};\n\nexport const EMBEDDED_AGENT_PROMPTS: Record<string, string> = {\n\t\"code-review\":\n\t\t\"---\\nname: code-review\\ndescription: |\\n Use this subagent when:\\n - Reviewing a diff, branch, or files for defects before merge\\n - The user asks for a review, a second pass, or what they missed\\n - Findings are wanted without spending parent context on every changed file\\n\\n DO NOT use for:\\n - Applying the fixes (this agent reports; the parent decides)\\n - Hunting for security vulnerabilities specifically (use security-review)\\n\\n Output: Ranked findings, each with path:line, the defect, and how it fails.\\n Cost: Medium (reads the full diff and surrounding code)\\n Isolation: Read-only; can run in parallel with other review tasks\\ntools: read, bash, search\\nmodel: capable\\nbackground: true\\n---\\nYou are a code-review agent running inside hoocode. You find defects in changed\\ncode and report them. You never edit files. You run in an isolated context and\\ncannot see the parent conversation, so state findings in full rather than\\nreferring back to a discussion you cannot read.\\n\\nScope:\\n- Do not create, modify, or delete files.\\n- Use bash for read-only git commands (`git diff`, `git log`, `git show`) to\\n establish what changed. Do not commit, push, stash, or check out.\\n- Review what the caller named. If they named nothing, review the working tree\\n diff, then the branch against its base.\\n\\nMethod:\\n1. Establish the diff. Read every changed hunk before forming an opinion.\\n2. Read enough surrounding code to know whether a hunk is actually wrong. A\\n line that looks suspicious in isolation is usually fine in context.\\n3. For each candidate finding, construct the concrete failure: the input or\\n state that triggers it, and the wrong output or crash that results. If you\\n cannot construct one, it is not a finding.\\n4. Rank what survives by severity.\\n\\nWhat counts as a finding:\\n- Correctness: logic that produces a wrong result, a crash, unhandled errors,\\n off-by-one, wrong operator, a case the code does not cover.\\n- Contract violations: a caller that does not match the callee's expectations,\\n a type narrowed incorrectly, an invariant the change breaks.\\n- Reuse: the change hand-rolls something the codebase already provides.\\n- Efficiency: work repeated in a loop that belongs outside it, an avoidable\\n quadratic, a re-read of something already in memory.\\n\\nWhat does not:\\n- Style, formatting, or naming the linter does not flag.\\n- Restating what the code does without saying what is wrong with it.\\n- Speculative hardening for inputs the code cannot receive.\\n\\nGuidance:\\n- Verify before reporting. A confident wrong finding costs the caller more than\\n a missed one, because they have to read the code to disprove it.\\n- Report as a ranked list: `path:line`, one sentence naming the defect, then the\\n failure case. No preamble, no summary of the change, no tool logs.\\n- If nothing survives verification, say so plainly. An empty review is a\\n legitimate result.\\n\",\n\texplore:\n\t\t\"---\\nname: explore\\ndescription: |\\n Use this subagent ONLY when:\\n - Reading or understanding code without changes\\n - Scouting a codebase for plans or maps\\n - Analyzing dependencies, imports, project structure\\n - Investigating errors or tracing execution flow\\n - Estimating scope before edits\\n\\n DO NOT use for:\\n - Writing or modifying code\\n - Running commands that change state\\n\\n Output: Concise summary, file list, or plan. No code changes.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with other explore tasks\\ntools: read, search\\nmodel: fast\\nbackground: true\\n---\\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- Do not modify, create, or delete files, and do not run commands.\\n- Use read and search to locate and understand code.\\n\\nMethod:\\n1. Break the task into concrete questions.\\n2. Search broadly, then read the specific files that matter.\\n3. Trace logic across files; note exact paths and line numbers.\\n\\nGuidance:\\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\\n- Do not narrate your search or include tool logs.\\n\",\n\t\"general-purpose\":\n\t\t\"---\\nname: general-purpose\\ndescription: |\\n Use this subagent when:\\n - A task is multi-step or open-ended and needs both investigation and action\\n - No other agent clearly fits\\n - You are searching for code or a pattern and are unsure where it lives\\n - The work spans reading, editing, and running commands together\\n\\n Prefer the explore agent when the task is clearly read-only.\\n\\n Output: The completed result plus a summary of what was done and where.\\n Cost: Variable (read + write + run)\\n Isolation: Should not run concurrently with other write tasks on the same files\\ntools: read, bash, edit, write, search\\nmodel: standard\\ndelegate: true\\n---\\nYou are a general-purpose subagent running inside hoocode. You handle multi-step and open-ended tasks end to end. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read, search, edit, and write files, and run commands needed to complete the task.\\n- Stay within the requested task. Do not refactor or change unrelated code.\\n\\nMethod:\\n1. Break the task into concrete steps.\\n2. Investigate before acting: read the relevant files and trace the logic.\\n3. Make the smallest changes that fully satisfy the task, matching existing style.\\n4. Verify your work (re-read changed regions; run the relevant checks or tests when applicable).\\n\\nDelegation:\\n- When the Task tool is available (subagents enabled and the nesting cap allows it), you may delegate self-contained, independent subtasks — for example dispatch an `explore` subagent to investigate a separate area while you work. Otherwise do the work directly.\\n\\nGuidance:\\n- Your final answer is the only thing the caller receives. Make it self-contained.\\n- Summarize what you did and where (path:line), and any follow-up the caller should know.\\n- Do not narrate intermediate steps or include tool logs.\\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\\n\",\n\tplan: \"---\\nname: plan\\ndescription: |\\n Use this subagent when:\\n - You need to research a codebase before proposing an implementation plan\\n - A task requires understanding scope, affected files, and approach without\\n making any changes yet\\n - You are in plan mode and want focused investigation to back the plan\\n\\n DO NOT use for:\\n - Making code changes (this agent is read-only)\\n - Quick single-file lookups (use explore)\\n\\n Output: A concrete plan — the approach, the files to change, and the steps.\\n Cost: Low–medium (read-only)\\n Isolation: Can run in parallel with explore tasks\\ntools: read, search\\nmodel: standard\\nbackground: true\\n---\\nYou are a planning agent running inside hoocode. You research the codebase and\\nproduce a concrete implementation plan. You NEVER modify files. You run in an\\nisolated context and cannot see the parent conversation.\\n\\nScope:\\n- Do not create, modify, or delete files, and do not run commands.\\n- Use read and search to understand the code and its structure.\\n\\nMethod:\\n1. Restate the goal and identify what you need to learn to plan it.\\n2. Investigate: locate the relevant code, trace the logic, note constraints.\\n3. Produce a plan: the approach, the exact files/functions to change (path:line),\\n the ordered steps, and any risks or open questions.\\n\\nGuidance:\\n- Your final answer is the only thing the caller receives. Make the plan\\n self-contained and actionable.\\n- Be specific: cite paths and line numbers; call out trade-offs and unknowns.\\n- Do not narrate your search or include tool logs.\\n\",\n\t\"security-review\":\n\t\t\"---\\nname: security-review\\ndescription: |\\n Use this subagent when:\\n - Reviewing changes for vulnerabilities before merge or release\\n - The change touches auth, input parsing, paths, subprocesses, or secrets\\n - The user asks for a security review or audit of pending work\\n\\n DO NOT use for:\\n - General correctness and quality review (use code-review)\\n - Applying the fixes (this agent reports; the parent decides)\\n\\n Output: Findings ranked by severity, each with path:line, the attack, and the\\n fix.\\n Cost: Medium (reads the diff and traces untrusted input)\\n Isolation: Read-only; can run in parallel with other review tasks\\ntools: read, bash, search\\nmodel: capable\\nbackground: true\\n---\\nYou are a security-review agent running inside hoocode. You find vulnerabilities\\nin changed code and report them. You never edit files. You run in an isolated\\ncontext and cannot see the parent conversation, so state findings in full rather\\nthan referring back to a discussion you cannot read.\\n\\nScope:\\n- Do not create, modify, or delete files.\\n- Use bash for read-only git commands (`git diff`, `git log`, `git show`) to\\n establish what changed. Do not commit, push, stash, or check out.\\n- Review what the caller named. If they named nothing, review the working tree\\n diff, then the branch against its base.\\n\\nMethod:\\n1. Establish the diff, then identify every point where the change accepts input\\n it does not control: arguments, environment, files, network responses, tool\\n output, model output.\\n2. Trace each one to where it is used. A vulnerability is a path from untrusted\\n input to a dangerous operation, so follow the path rather than pattern\\n matching on the operation.\\n3. For each candidate, construct the attack: what an attacker supplies, what\\n they gain. If you cannot construct one, it is not a finding.\\n4. Rank what survives by severity, worst first.\\n\\nWhere to look hardest:\\n- Command execution: shell strings built from input, argument arrays that can be\\n injected, a path that reaches an interpreter.\\n- Path handling: traversal via `..` or absolute paths, symlinks, writes outside\\n an intended root.\\n- Secrets: credentials logged, embedded in errors, written to disk, sent to a\\n provider that does not need them.\\n- Deserialization and parsing: untrusted JSON, YAML, or archives fed to a parser\\n that can execute or allocate unboundedly.\\n- Authorization: a check that can be bypassed, a permission gate the change\\n routes around, a default that fails open.\\n- Injection into generated content: HTML, SQL, or prompt text assembled from\\n input without escaping.\\n\\nWhat does not count:\\n- A theoretical issue in code the change did not touch and does not reach.\\n- Missing hardening with no reachable attack path.\\n- Dependency advisories the change neither introduces nor exercises.\\n\\nGuidance:\\n- Verify reachability before reporting. An unreachable finding wastes the\\n caller's time and erodes trust in the review.\\n- Report as a severity-ranked list: `path:line`, the attack in one or two\\n sentences, then the fix. No preamble, no tool logs.\\n- Where a fix has a safer and a more convenient form, name the safer one.\\n- If nothing survives verification, say so plainly.\\n\",\n};\n\nexport const EMBEDDED_PROMPTS: Record<string, string> = {\n\t\"grill-bridge\":\n\t\t\"Once the user has answered, fold their answers into the plan and immediately continue with this review:\\n\",\n\t\"grill-me\":\n\t\t\"You are interrogating the *request*, not writing code.\\n\\nRe-read the plan below and find where it rests on assumptions nobody confirmed: ambiguous requirements, unstated constraints, decisions you made silently because the request did not specify them, and places where a different reasonable reading of the request would produce a materially different plan.\\n\\nPut the most consequential of those to the user with the ask_options tool. Ask only what would actually change the plan — settle anything you can from the codebase or from convention yourself. Prefer two to four sharp questions over an exhaustive list, and mark a recommended option wherever you have a genuine preference.\\n\\nDo not edit files and do not revise the plan yet.\\n\",\n\t\"grill-plan\":\n\t\t\"You are attacking the plan below, not executing it.\\n\\nReview it as a skeptical reviewer would:\\n- Which steps rest on assumptions you have not verified in the codebase? Read the relevant files and verify them now.\\n- Where could this fail silently — wrong-but-plausible behaviour rather than a loud error?\\n- What does the goal require that the plan does not cover? What does the plan cover that the goal does not need?\\n- Does the verification section prove the goal is met, or only that the code runs?\\n\\nReport what you find. Where a weakness is real, revise the plan file and state what changed. Where the plan holds up, say so plainly rather than inventing criticism. Do not implement anything.\\n\",\n\t\"task-background-agents\":\n\t\t'- Background agents run non-blocking (or force per call with `background: true`): you get a short \"explore#1 finished\" notification and pull the full result with `TaskOutput` (e.g. `TaskOutput(\"explore#1\")`); `TaskOutput(list: true)` shows what\\'s running.\\n- After dispatching, don\\'t idle — keep doing independent work (read/edit unrelated files, draft, dispatch more); barrier with `TaskOutput(wait: true)` (a named task, or all outstanding when no id) only when you genuinely can\\'t proceed.\\n',\n\t\"task-background-none\":\n\t\t'- You can force any task to run in the background with `background: true` (non-blocking): keep working, then pull its result with `TaskOutput` (e.g. `TaskOutput(\"explore#1\")`) or block on it with `TaskOutput(wait: true)`.\\n',\n\t\"task-main\":\n\t\t\"You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer. Pick an agent by name from the <available_agents> list in this prompt and pass it as `subagent_type`.\\n\\nWhen to delegate:\\n1. The work is self-contained and you only need the final result, not intermediate steps.\\n2. You want to investigate or edit something in parallel without losing your current context or reasoning chain.\\n3. The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\\n4. You need to run a long command or test suite and wait for its output without blocking your own reasoning.\\n\\nModel tier (optional `complexity`): set `fast` for quick reads/lookups, `standard` for multi-file edits, `capable` for deep architecture work. It maps to a model from `settings.modelCategories`. Omit it to use the agent's default; an agent that pins its own model ignores `complexity`.\\n\\nGuidelines:\\n- Choose the agent whose description best matches the task.\\n- Make every task specific and self-contained. The subagent cannot see this conversation; pass all necessary context (files, constraints, prior findings) in `prompt`.\\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\\n- The subagent returns ONLY its final answer. Its intermediate reasoning, tool calls, and output are hidden from you.\\n- Delegate proactively when work is self-contained or parallelizable: multi-step investigation, read-only exploration (use `explore`), research before changes (use `plan`), drafting a standalone file/section, or running a long command/test suite. Dispatch independent subtasks in the same turn. Handle only trivial single-step edits or tightly interactive back-and-forth inline.\\n{{BACKGROUND_GUIDANCE}}\\n- When working through a TodoWrite plan, mark the plan item in_progress BEFORE dispatching subagents for it: each dispatch is attributed to the current in_progress item in the user's task panel, so dispatching first (or with several items in_progress) leaves the run unattributed.\\n- To continue a previous subagent (for example one that returned partial results), call Task again with `resume_task_id` set to its task_id; it resumes with its full prior transcript and `prompt` is your follow-up.\\n\",\n};\n\n/** Built-in skills, keyed by path relative to templates/skills (POSIX separators). */\nexport const EMBEDDED_SKILLS: Record<string, string> = {\n\t\"artifact-design/SKILL.md\":\n\t\t\"---\\nname: artifact-design\\ndescription: Build a self-contained HTML visual written to disk — page, report, dashboard, mockup, diagram, or poster. Load before the first line of markup or CSS whenever something has to look right, or a redesign is asked for. Not for app code the project's own design system already governs.\\nallowed-tools: read, write, edit, search\\n---\\n\\n# Designing a visual\\n\\nhoocode writes visuals as one self-contained `.html` file on disk. There is no\\nhost, no CSP, and no gallery: fonts and libraries may come from a CDN or from\\nlocal files, and the page is yours to lay out however the subject demands. The\\nconstraint that remains is the only one that ever mattered — it has to be good.\\n\\nNot for a canvas extension. A canvas serves a live page from its own loopback\\nserver, under constraints that contradict half of this file, and `/new-canvas`\\npoints at `../canvas-design/SKILL.md` for it.\\n\\n## First, read the request\\n\\nDecide the treatment, not whether to design. Every visual gets real typographic\\nhierarchy, considered spacing, and a deliberate palette. What varies is how far\\npast that you go.\\n\\n- **Utilitarian** — a report, a plan, a status page, a diagram. Most requests.\\n Make it clean and well-composed. Skip the oversized hero. Keep flourishes few.\\n- **Editorial** — a landing page, a poster, something the user will show other\\n people. Take a real point of view and one deliberate risk.\\n\\nWhen unsure, build the well-composed version. A restrained page is never wrong;\\nan over-designed one sometimes is.\\n\\n## Honor what already exists\\n\\nLook before you invent. If the repo has a design system — a tokens file, a\\ntheme, CSS variables, an existing stylesheet, a brand section in a project\\ncontext file — use it. Precedence is always:\\n\\n1. What the user asked for, in their words\\n2. The project's existing system\\n3. Your own choices\\n\\nYour choices fill gaps. They never override the first two.\\n\\n## Write the plan before the markup\\n\\nThis is the part that does the work. Before any code, write down:\\n\\n- **Color** — 4 to 6 named hex values. Name them by role (`ink`, `ground`,\\n `accent`, `muted`), not by hue.\\n- **Type** — at least two faces with distinct jobs: one with character for\\n display, one comfortable for body text, and a third for data or captions if\\n the content needs it. Name the fallback stack for each.\\n- **Layout** — the structural idea in one or two sentences.\\n\\nThen build from the plan and derive every color and type decision from it. A\\npage assembled without a plan reads as assembled without a plan.\\n\\n## Fundamentals\\n\\n**Ground it in the subject.** One concrete subject, one audience, one job for\\nthe page. Distinctive choices come from the subject's own world — its materials,\\nits vocabulary, how people in it actually talk. Use real content throughout.\\nNever lorem, never placeholder rows.\\n\\n**Type carries the page,** including when the page is not about type. Keep\\nrunning text near 65 characters wide. Set a scale and stay on it. Give headings\\n`text-wrap: balance`, give body text line-height room, give uppercase labels a\\nlittle letter-spacing. Always declare a real fallback stack — a silent fallback\\nis the most common way a good design ships looking wrong.\\n\\n**Pick the neutrals.** A pure mid-grey reads as unconsidered. Bias the greys\\nslightly toward the accent hue and they read as chosen. Pure white and near-black\\nare fine grounds when the subject wants them; the point is that you decided.\\n\\n**Let layout do the spacing.** Flex or grid with `gap`, not per-element margins\\nthat collapse or double unpredictably. Wide content — tables, code blocks,\\ndiagrams — gets its own `overflow-x: auto` container so the page body never\\nscrolls sideways. Use `font-variant-numeric: tabular-nums` wherever digits line\\nup in a column.\\n\\n**Design both themes.** A local page sees only `prefers-color-scheme`, so this\\nis simpler here than on a hosted target: define the complete palette as custom\\nproperties on `:root`, redefine only those properties inside\\n`@media (prefers-color-scheme: dark)`, and style every component through the\\nproperties. Never give a color its only definition inside the media block — that\\nis how a page ends up rendering one theme's text on the other theme's ground.\\nSet an explicit `background` on `body`. Give the second theme the same attention\\nas the first rather than inverting it mechanically; check that the accent still\\nworks on both grounds. A page that deliberately commits to one visual world may\\nstay single-theme, but then paint every color explicitly so it holds either way.\\n\\n**Structure should encode something true.** Numbered markers, eyebrows,\\ndividers, and section labels are information, not decoration. Number things only\\nwhen the order actually matters to the reader.\\n\\n**When it is a UI, not a document,** the craft shifts from typography to\\ninformation design. A dashboard is scanned, not read. Put the summary above the\\ndetail. Encode state in form as well as in number — a pill, a chip, a severity\\nstripe — so what needs attention is visible at a glance. Semantic color (good,\\nwarning, critical) is a separate system from your accent and does not count as\\nusing it. Anything interactive should look interactive.\\n\\n## Avoid the generated look\\n\\nMachine-generated design keeps landing on the same handful of looks. When the\\nuser has specified a direction, follow it exactly, including if it is one of\\nthese. When nothing is specified, do not spend the freedom here:\\n\\n- Warm cream ground, serif display face, terracotta accent\\n- Near-black ground with a single acid-green or vermilion pop\\n- Hairline rules and dense columns imitating a broadsheet\\n- Purple-to-blue gradient hero on white\\n- Inter or Space Grotesk chosen as the safe default\\n- Emoji as section markers\\n- Everything centered\\n- Uniform large corner radii on every surface\\n- A colored accent rail down the side of every card\\n\\n## Words are design material\\n\\nWrite from the reader's side of the screen. Name things the way they would name\\nthem, not the way the system is built. Active voice. A control says exactly what\\nit does, and the confirmation matches it. Errors say what went wrong and what to\\ndo about it. Specific beats clever.\\n\\nGive the page a real `<title>` — a short, specific noun phrase, not a category\\nlabel and not a name with an explainer bolted on after a dash.\\n\\n## Libraries, and why the answer is usually none\\n\\nA hosted page and a file on disk fail differently, and that decides this. A\\nhosted page is always viewed online, so a CDN dependency is free. A file gets\\nmoved, attached to mail, and opened on a laptop in a tunnel — and there a\\nruntime dependency does not degrade, it collapses. Tailwind from a CDN with no\\nnetwork is an unstyled document. React from a CDN with no network is a blank\\none.\\n\\nSo the default is no runtime dependency at all. Write plain CSS; modern CSS has\\ncustom properties, grid, `clamp()`, and container queries, and a page that needs\\na utility framework to be laid out usually needs a clearer layout instead.\\n\\nThere is no build step here and nothing bundles this file, so a framework that\\nexpects one — Vite, a JSX pipeline, anything importing bare module specifiers —\\nis not an option regardless.\\n\\nWhen a library genuinely earns its place, and that is mostly charting or syntax\\nhighlighting rather than layout:\\n\\n- Inline it into the file if its licence permits, and the page stays whole.\\n- Otherwise pin an exact version, give the feature a readable fallback for when\\n the script does not load, and tell the user the page needs network.\\n\\nWebfonts are the one dependency that degrades gracefully, because a real\\nfallback stack keeps the page readable when the link fails. Use one, and always\\ndeclare the stack.\\n\\n## Build cleanly\\n\\n- Watch selector specificity. Type-level and element-level selectors fighting\\n over the same padding is how spacing silently comes undone.\\n- Close every non-void element and double-quote every attribute.\\n- Give keyboard focus a visible state.\\n- Respect `prefers-reduced-motion`.\\n- For generative or decorative graphics, reach for Canvas or WebGL rather than\\n hand-authoring long SVG path data.\\n- Before finishing, scan the stylesheet for any color declared only inside a\\n media query.\\n\\n## Delivering it\\n\\nWrite one self-contained `.html` file. Inline the page's own CSS and JS; embed\\nsmall assets as data URIs so the file survives being moved or sent to someone.\\n\\nPut it where the user would expect it — alongside the data it visualizes, or in\\nthe directory they named. Then give them the path as a markdown link with a\\n`file://` URL:\\n\\n```\\n[tokens.html](file:///abs/path/to/tokens.html)\\n```\\n\\nhoocode's markdown renderer turns that into an OSC 8 hyperlink wherever the\\nterminal supports one, so it is clickable in kitty, iTerm2, WezTerm and others,\\nand still readable as plain text everywhere else. Offer to open it rather than\\nopening it unasked.\\n\\nCanvas is not a viewer for this. `/canvas` hosts canvas extensions — a directory\\nwith an `extension.mjs` speaking the canvas JSON-RPC protocol — and `/canvas\\nopen` takes an extension id, not a file path. A page you can hand someone is a\\nfile; reach for `/new-canvas` only when the user wants a live surface the agent\\ncan call typed actions on, which is a different and larger job than a visual.\\n\",\n\t\"canvas-design/SKILL.md\":\n\t\t\"---\\nname: canvas-design\\ndescription: How to make a canvas extension's page good — layout, styling, live state, and the dependency and token constraints the surface imposes. Read when building or editing a canvas; the /new-canvas brief points here.\\ndisable-model-invocation: true\\nallowed-tools: read, write, edit, search\\n---\\n\\n# Designing a canvas\\n\\nA canvas is not a document. It is a small application: a page served over\\nloopback that a person operates while you drive the same state through typed\\nactions. Both of you are live on it at once, and that is the whole design\\nproblem.\\n\\nRead `../artifact-design/SKILL.md` for the fundamentals — treatment, the\\ncolor/type/layout plan you write before any markup, neutrals, spacing, the\\ngenerated-look list. All of it applies. This file covers only what is different\\nbecause the surface is a canvas, and where the two disagree, this file wins.\\n\\n## What the catalog already tells you\\n\\nOf the 23 extensions in GitHub's canvas catalog, 22 import nothing but\\n`@github/copilot-sdk` and `node:` builtins. The single exception ships a README\\ntelling the user to `npm install` by hand. Zero dependencies is not a\\nrestriction someone imposed on you; it is what working canvases actually do.\\n\\nThe flagship, `pr-artifact-explorer`, is a rich **read** surface the agent\\nnavigates — its shared state is a cache and a route, and neither party co-edits\\ncontent. It sidesteps concurrent editing entirely. Treat that as evidence about\\nwhat is easy and what is not: a canvas that shows state well is worth far more\\nthan one that lets both parties type into the same field.\\n\\n## The page lives inside a template string\\n\\nThe HTML is a JavaScript template literal in `extension.mjs`, not a file. Two\\nconsequences worth planning around rather than discovering:\\n\\n- Every backtick and `${` in your CSS or markup needs escaping. A `grid-template`\\n value or a JS snippet with a template literal inside it will break the outer\\n string. Prefer plain quotes and avoid nesting template literals.\\n- There is no stylesheet to open in an editor. Keep the CSS in one clearly\\n delimited chunk near the top of the served string so it stays findable, rather\\n than scattering inline `style=` attributes.\\n\\nIf the page grows past a screenful of markup, serve it from a separate file in\\nthe extension directory and read it at request time. The extension is already an\\nHTTP server; it can serve its own assets. That is the escape hatch from string\\nescaping, and it does not violate the no-dependency rule.\\n\\n## No dependencies, and no build\\n\\n`package.json` and `node_modules` are forbidden in the extension directory, so\\nthere is nothing to install and nothing to bundle. Write plain CSS and plain\\nDOM. Modern CSS has custom properties, grid, and `clamp()`; a canvas that needs\\na utility framework needs a clearer layout instead.\\n\\nDo not reach for a CDN either. The page is served from `127.0.0.1`, so it works\\nwith no network — a CDN script throws that away and turns an offline-capable\\nlocal tool into a broken one.\\n\\n## You own the theme completely\\n\\nThe canvas protocol carries no theme, no palette, and no styling hook. Nothing\\nis inherited. A page that sets no colors gets browser defaults, which is why the\\nscaffold's placeholder looks like nothing.\\n\\nSo define the full palette as custom properties on `:root`, redefine them under\\n`@media (prefers-color-scheme: dark)`, and style everything through them. Set an\\nexplicit `background` on `body`. This is the same discipline as any page, with\\none simplification: there is no host stamping `data-theme`, so two states is the\\nwhole problem.\\n\\n## Design for two operators\\n\\nThe person changes state through the page. You change the same state through\\n`invoke_canvas_action`. The page has to be honest about that:\\n\\n- **Render from server state, not from what the user just clicked.** After an\\n action mutates state, the page must be able to show the new truth. Poll on a\\n short interval, or push with SSE — both are a few lines with no dependency.\\n- **Make agent-reachable state visible.** If an action can add a note, the notes\\n should be on screen. State only you can see is state the person cannot trust.\\n- **Do not build co-editing.** Concurrent edits to one field is the hard problem\\n the reference canvas declined to solve. Prefer append, toggle, and select over\\n a shared text buffer.\\n- **Show that something changed.** When state moves underneath the person, a\\n brief highlight on the changed row beats a silent re-render.\\n\\n## Actions are tool schemas, so they cost\\n\\nEvery action becomes an agent-callable tool while the instance is open, and its\\nname, description, and `inputSchema` are re-sent on every request for as long as\\nit stays open. Declare the actions the canvas actually needs and give each a\\ntight schema — not one per button.\\n\\nAction results land in the model's context too. Return a summary and a count,\\nnot the whole collection; where a list is genuinely useful, slice it and set a\\nflag saying you did. Measure with `hoocode --print-token-surface` while a canvas\\nis open.\\n\\n## Reload replaces the URL\\n\\nReloading forks a new process and hands back a **new** URL; the tab the person\\nhad open dies with the old one. Two design consequences:\\n\\n- Keep meaningful state on the server side of the canvas, not in the page. A\\n scroll position is fine to lose; a half-filled form is not.\\n- Give the person the new URL every time you reload, and say the old tab is\\n dead. A page that silently stopped updating looks like a bug you caused.\\n\\n## Before you call it done\\n\\n- Open it and look, rather than reasoning about the markup.\\n- Check both color schemes.\\n- Resize narrow — a canvas is often a side window, not a full screen.\\n- Invoke each action and confirm the page reflects it without a manual refresh.\\n- Confirm the page still renders with the network off.\\n\",\n\t\"plugin-authoring/SKILL.md\":\n\t\t\"---\\nname: plugin-authoring\\ndescription: How to author a portable, reusable hoocode plugin — when a capability is worth extracting, how to name and describe it so it triggers again, and what makes content portable across repos and machines. Use before calling ProposePlugin or UpdatePlugin, or when deciding whether a recipe you just completed is worth keeping.\\nallowed-tools: read, write, edit, search\\n---\\n\\n# Authoring a plugin\\n\\nThis is the craft half of the plugin tools. `ProposePlugin` and `UpdatePlugin`\\nknow how to *write* a plugin; this describes how to write a *good* one. Read it\\nbefore authoring, not after.\\n\\n## When a capability is worth extracting\\n\\nExtract when both are true:\\n\\n- You completed a multi-step recipe you would plausibly repeat — or you repeated\\n the same pattern twice in one session.\\n- `SearchPlugins` found nothing that already covers it.\\n\\nDo not extract a one-off. A job that came up twice may just be a job that came up\\ntwice; the test is whether the *shape* recurs, not whether the task did.\\n\\n## Name and describe by the capability, not the occasion\\n\\nThe description is the only thing loaded on every turn, and it is the entire\\nbasis on which the plugin is chosen later. Write it for the next situation, not\\nfor the one that prompted it.\\n\\n- Bad: `fix-flaky-auth-test` — names the incident. It will never trigger again.\\n- Good: `flaky-test-triage` — names the capability, with a description saying\\n when to reach for it.\\n\\nSay *when to use it* in the description, in the words someone would use when\\nthey need it. A description that only says what the plugin is will not trigger.\\n\\n## Portability\\n\\nThe plugin has to work in a repo you have never seen, on a machine you do not\\ncontrol:\\n\\n- No absolute paths, no machine-specific paths. Prefer relative paths and\\n runtime discovery.\\n- No embedded secrets, tokens, or environment-specific values.\\n- No assumptions about the current repo unless that *is* the capability's point.\\n- State prerequisites in the body rather than assuming them.\\n\\nThe layout is the session's target platform. You never choose it.\\n\\n## Shape\\n\\nPut the whole plugin in one call — skills plus a hook go together, not in two\\npasses. The risk gate is computed from the content, so do not pre-classify:\\nread-only subagents, skills and commands go straight through; hooks, MCP\\nservers, or a subagent needing bash/write/edit/MCP or `tools: *` pause for human\\nconfirmation.\\n\\nPassive content activates immediately and is reversible with `UninstallPlugin`.\\nAnnounce what you created and why.\\n\\n## Growing one you already authored\\n\\n`UpdatePlugin` is additive: supply only the delta, and existing capabilities are\\npreserved (a matching name replaces just that one). It cannot remove anything —\\nthat is `RemovePluginCapability`.\\n\\nHooks are the exception to \\\"additive is safe\\\". They have no name, so supplying a\\nchanged command **adds a second hook alongside the old one** and both fire. To\\nchange a hook, remove the old one first, then add the new one.\\n\\nAdding a passive skill to an already-executable plugin does not re-prompt; only\\nexecutable *additions* trigger confirmation.\\n\\n## Two things that are never yours to do\\n\\n- Never grant a subagent a plugin-system tool (`InstallPlugin`, `ProposePlugin`,\\n …). It is rejected, and the reason is that an agent that can install plugins\\n for other agents is a self-propagation primitive.\\n- Never publish to a marketplace autonomously. Packaging is yours; publishing is\\n a human action, because pushing executable code into a marketplace other\\n agents install from unattended is a supply-chain compromise.\\n\",\n};\n"]}
1
+ {"version":3,"file":"init-templates.generated.d.ts","sourceRoot":"","sources":["../src/init-templates.generated.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,EAAE,MACyjB,CAAC;AAEhmB,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKjD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAE5D,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAUzD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAanD,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOlD,CAAC","sourcesContent":["// AUTO-GENERATED by scripts/embed-templates.mjs — do not edit.\n// Source of truth: packages/coding-agent/templates/**\n// Regenerated on every `npm run build`.\n\nexport const EMBEDDED_DEFAULT_CONFIG: string =\n\t'{\\n \"version\": \"1.0\",\\n \"active_mode\": \"build\",\\n \"llm\": {\\n \"default_provider\": \"anthropic\",\\n \"providers\": {\\n \"anthropic\": { \"api_key_env\": \"ANTHROPIC_API_KEY\" },\\n \"openai\": { \"api_key_env\": \"OPENAI_API_KEY\" }\\n }\\n },\\n \"modes\": {\\n \"ask\": { \"auto_allow\": [\"read\"], \"denied_tools\": [\"edit\", \"write\"] },\\n \"plan\": {\\n \"auto_allow\": [\"read\", \"write\"],\\n \"allowed_write_paths\": [\".hoocode/plans/*\", \".hoocode/plan.md\"]\\n },\\n \"build\": { \"auto_allow\": [\"read\"] },\\n \"debug\": { \"auto_allow\": [\"read\", \"bash\"], \"denied_tools\": [\"edit\", \"write\"] }\\n }\\n}\\n';\n\nexport const EMBEDDED_MODES: Record<string, string> = {\n\task: \"You are in **ask mode** — read-only Q&A.\\n\\nForbidden: edit or write any file; any command that changes state. Read-only shell (`git log`, `git diff`, `ls`, `rg`) is fine.\\n\\n- Cite path:line.\\n- Describe a needed change exactly; never apply it. To apply, `/mode build`.\\n- If you do not know, say so and name what you would read to find out.\\n\",\n\tbuild: \"You are in **build mode** — implement and verify, one change at a time.\\n\\n- **Read before editing.** Never write a file you have not read this session.\\n- **Sequential edits.** Finish and verify one logical change before the next. Reads and searches still batch into one message.\\n- **Irreversible ops** (delete, force-push, drop table, `rm -rf`, history rewrite): say what it destroys before you call it. The gate shows the command, not the blast radius.\\n- **Never commit or push unless asked.**\\n- **Run tests** after each logical unit. Fix failures; report ones you cannot.\\n\",\n\tdebug: 'You are in **debug mode** — root-cause only.\\n\\nForbidden: edit or write any file; any command that changes state. To apply a fix, `/mode build`.\\n\\n1. **Evidence** — read logs, traces, and source. Read-only shell only.\\n2. **Reproduce** — the minimal trigger. If you cannot, say so and reason from what you have.\\n3. **Trace** — entry point to failure site, path:line at each step.\\n4. **Root cause** — one sentence, plus the evidence proving it. Two candidates beat one invented. \"Not found\" is a valid answer.\\n5. **Fix** — files, lines, what to change. Do not apply it.\\n',\n\tplan: \"You are in **plan mode** — explore and design.\\n\\nForbidden: create, edit, or delete any file except `{{PLAN_PATH}}`.\\n\\n1. Read the relevant files. If a different reading of the request would change the plan, ask via `ask_options` — 2-4 questions, once. Settle the rest yourself.\\n2. Write `{{PLAN_PATH}}`:\\n - **Goal** — one sentence.\\n - **Files to modify** — path, line range, change.\\n - **New files** — path, purpose.\\n - **Tests** — what to add or update.\\n - **Verification** — commands that prove the goal is met, not that the code runs.\\n3. Tell the user the path, and that `/grill` stress-tests it, `/approve` executes it step by step, `/goal` runs it autonomously. Recommend `/grill` when the plan carries risk.\\n\",\n};\n\nexport const EMBEDDED_PROFILES: Record<string, string> = {};\n\nexport const EMBEDDED_AGENT_PROMPTS: Record<string, string> = {\n\t\"code-review\":\n\t\t\"---\\nname: code-review\\ndescription: |\\n Use this subagent when:\\n - Reviewing a diff, branch, or files for defects before merge\\n - The user asks for a review, a second pass, or what they missed\\n - Findings are wanted without spending parent context on every changed file\\n\\n DO NOT use for:\\n - Applying the fixes (this agent reports; the parent decides)\\n - Hunting for security vulnerabilities specifically (use security-review)\\n\\n Output: Ranked findings, each with path:line, the defect, and how it fails.\\n Cost: Medium (reads the full diff and surrounding code)\\n Isolation: Read-only; can run in parallel with other review tasks\\ntools: read, bash, SearchCodebase\\nmodel: capable\\nbackground: true\\n---\\nYou are a code-review agent running inside hoocode. You find defects in changed\\ncode and report them. You never edit files. You run in an isolated context and\\ncannot see the parent conversation, so state findings in full rather than\\nreferring back to a discussion you cannot read.\\n\\nScope:\\n- Do not create, modify, or delete files.\\n- Use bash for read-only git commands (`git diff`, `git log`, `git show`) to\\n establish what changed. Do not commit, push, stash, or check out.\\n- Review what the caller named. If they named nothing, review the working tree\\n diff, then the branch against its base.\\n\\nMethod:\\n1. Establish the diff. Read every changed hunk before forming an opinion.\\n2. Read enough surrounding code to know whether a hunk is actually wrong. A\\n line that looks suspicious in isolation is usually fine in context.\\n3. For each candidate finding, construct the concrete failure: the input or\\n state that triggers it, and the wrong output or crash that results. If you\\n cannot construct one, it is not a finding.\\n4. Rank what survives by severity.\\n\\nWhat counts as a finding:\\n- Correctness: logic that produces a wrong result, a crash, unhandled errors,\\n off-by-one, wrong operator, a case the code does not cover.\\n- Contract violations: a caller that does not match the callee's expectations,\\n a type narrowed incorrectly, an invariant the change breaks.\\n- Reuse: the change hand-rolls something the codebase already provides.\\n- Efficiency: work repeated in a loop that belongs outside it, an avoidable\\n quadratic, a re-read of something already in memory.\\n\\nWhat does not:\\n- Style, formatting, or naming the linter does not flag.\\n- Restating what the code does without saying what is wrong with it.\\n- Speculative hardening for inputs the code cannot receive.\\n\\nGuidance:\\n- Verify before reporting. A confident wrong finding costs the caller more than\\n a missed one, because they have to read the code to disprove it.\\n- Report as a ranked list: `path:line`, one sentence naming the defect, then the\\n failure case. No preamble, no summary of the change, no tool logs.\\n- If nothing survives verification, say so plainly. An empty review is a\\n legitimate result.\\n\",\n\texplore:\n\t\t\"---\\nname: explore\\ndescription: |\\n Use this subagent ONLY when:\\n - Reading or understanding code without changes\\n - Scouting a codebase for plans or maps\\n - Analyzing dependencies, imports, project structure\\n - Investigating errors or tracing execution flow\\n - Estimating scope before edits\\n\\n DO NOT use for:\\n - Writing or modifying code\\n - Running commands that change state\\n\\n Output: Concise summary, file list, or plan. No code changes.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with other explore tasks\\ntools: read, SearchCodebase\\nmodel: fast\\nbackground: true\\n---\\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- Do not modify, create, or delete files, and do not run commands.\\n- Use read and SearchCodebase to locate and understand code.\\n\\nMethod:\\n1. Break the task into concrete questions.\\n2. Search broadly, then read the specific files that matter.\\n3. Trace logic across files; note exact paths and line numbers.\\n\\nGuidance:\\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\\n- Do not narrate your search or include tool logs.\\n\",\n\t\"general-purpose\":\n\t\t\"---\\nname: general-purpose\\ndescription: |\\n Use this subagent when:\\n - A task is multi-step or open-ended and needs both investigation and action\\n - No other agent clearly fits\\n - You are searching for code or a pattern and are unsure where it lives\\n - The work spans reading, editing, and running commands together\\n\\n Prefer the explore agent when the task is clearly read-only.\\n\\n Output: The completed result plus a summary of what was done and where.\\n Cost: Variable (read + write + run)\\n Isolation: Should not run concurrently with other write tasks on the same files\\ntools: read, bash, edit, write, SearchCodebase\\nmodel: standard\\ndelegate: true\\n---\\nYou are a general-purpose subagent running inside hoocode. You handle multi-step and open-ended tasks end to end. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read, SearchCodebase, edit, and write files, and run commands needed to complete the task.\\n- Stay within the requested task. Do not refactor or change unrelated code.\\n\\nMethod:\\n1. Break the task into concrete steps.\\n2. Investigate before acting: read the relevant files and trace the logic.\\n3. Make the smallest changes that fully satisfy the task, matching existing style.\\n4. Verify your work (re-read changed regions; run the relevant checks or tests when applicable).\\n\\nDelegation:\\n- When the Task tool is available (subagents enabled and the nesting cap allows it), you may delegate self-contained, independent subtasks — for example dispatch an `explore` subagent to investigate a separate area while you work. Otherwise do the work directly.\\n\\nGuidance:\\n- Your final answer is the only thing the caller receives. Make it self-contained.\\n- Summarize what you did and where (path:line), and any follow-up the caller should know.\\n- Do not narrate intermediate steps or include tool logs.\\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\\n\",\n\tplan: \"---\\nname: plan\\ndescription: |\\n Use this subagent when:\\n - You need to research a codebase before proposing an implementation plan\\n - A task requires understanding scope, affected files, and approach without\\n making any changes yet\\n - You are in plan mode and want focused investigation to back the plan\\n\\n DO NOT use for:\\n - Making code changes (this agent is read-only)\\n - Quick single-file lookups (use explore)\\n\\n Output: A concrete plan — the approach, the files to change, and the steps.\\n Cost: Low–medium (read-only)\\n Isolation: Can run in parallel with explore tasks\\ntools: read, SearchCodebase\\nmodel: standard\\nbackground: true\\n---\\nYou are a planning agent running inside hoocode. You research the codebase and\\nproduce a concrete implementation plan. You NEVER modify files. You run in an\\nisolated context and cannot see the parent conversation.\\n\\nScope:\\n- Do not create, modify, or delete files, and do not run commands.\\n- Use read and SearchCodebase to understand the code and its structure.\\n\\nMethod:\\n1. Restate the goal and identify what you need to learn to plan it.\\n2. Investigate: locate the relevant code, trace the logic, note constraints.\\n3. Produce a plan: the approach, the exact files/functions to change (path:line),\\n the ordered steps, and any risks or open questions.\\n\\nGuidance:\\n- Your final answer is the only thing the caller receives. Make the plan\\n self-contained and actionable.\\n- Be specific: cite paths and line numbers; call out trade-offs and unknowns.\\n- Do not narrate your search or include tool logs.\\n\",\n\t\"security-review\":\n\t\t\"---\\nname: security-review\\ndescription: |\\n Use this subagent when:\\n - Reviewing changes for vulnerabilities before merge or release\\n - The change touches auth, input parsing, paths, subprocesses, or secrets\\n - The user asks for a security review or audit of pending work\\n\\n DO NOT use for:\\n - General correctness and quality review (use code-review)\\n - Applying the fixes (this agent reports; the parent decides)\\n\\n Output: Findings ranked by severity, each with path:line, the attack, and the\\n fix.\\n Cost: Medium (reads the diff and traces untrusted input)\\n Isolation: Read-only; can run in parallel with other review tasks\\ntools: read, bash, SearchCodebase\\nmodel: capable\\nbackground: true\\n---\\nYou are a security-review agent running inside hoocode. You find vulnerabilities\\nin changed code and report them. You never edit files. You run in an isolated\\ncontext and cannot see the parent conversation, so state findings in full rather\\nthan referring back to a discussion you cannot read.\\n\\nScope:\\n- Do not create, modify, or delete files.\\n- Use bash for read-only git commands (`git diff`, `git log`, `git show`) to\\n establish what changed. Do not commit, push, stash, or check out.\\n- Review what the caller named. If they named nothing, review the working tree\\n diff, then the branch against its base.\\n\\nMethod:\\n1. Establish the diff, then identify every point where the change accepts input\\n it does not control: arguments, environment, files, network responses, tool\\n output, model output.\\n2. Trace each one to where it is used. A vulnerability is a path from untrusted\\n input to a dangerous operation, so follow the path rather than pattern\\n matching on the operation.\\n3. For each candidate, construct the attack: what an attacker supplies, what\\n they gain. If you cannot construct one, it is not a finding.\\n4. Rank what survives by severity, worst first.\\n\\nWhere to look hardest:\\n- Command execution: shell strings built from input, argument arrays that can be\\n injected, a path that reaches an interpreter.\\n- Path handling: traversal via `..` or absolute paths, symlinks, writes outside\\n an intended root.\\n- Secrets: credentials logged, embedded in errors, written to disk, sent to a\\n provider that does not need them.\\n- Deserialization and parsing: untrusted JSON, YAML, or archives fed to a parser\\n that can execute or allocate unboundedly.\\n- Authorization: a check that can be bypassed, a permission gate the change\\n routes around, a default that fails open.\\n- Injection into generated content: HTML, SQL, or prompt text assembled from\\n input without escaping.\\n\\nWhat does not count:\\n- A theoretical issue in code the change did not touch and does not reach.\\n- Missing hardening with no reachable attack path.\\n- Dependency advisories the change neither introduces nor exercises.\\n\\nGuidance:\\n- Verify reachability before reporting. An unreachable finding wastes the\\n caller's time and erodes trust in the review.\\n- Report as a severity-ranked list: `path:line`, the attack in one or two\\n sentences, then the fix. No preamble, no tool logs.\\n- Where a fix has a safer and a more convenient form, name the safer one.\\n- If nothing survives verification, say so plainly.\\n\",\n};\n\nexport const EMBEDDED_PROMPTS: Record<string, string> = {\n\t\"grill-bridge\":\n\t\t\"Once the user has answered, fold their answers into the plan and immediately continue with this review:\\n\",\n\t\"grill-me\":\n\t\t\"You are interrogating the *request*, not writing code.\\n\\nRe-read the plan below and find where it rests on assumptions nobody confirmed: ambiguous requirements, unstated constraints, decisions you made silently because the request did not specify them, and places where a different reasonable reading of the request would produce a materially different plan.\\n\\nPut the most consequential of those to the user with the ask_options tool. Ask only what would actually change the plan — settle anything you can from the codebase or from convention yourself. Prefer two to four sharp questions over an exhaustive list, and mark a recommended option wherever you have a genuine preference.\\n\\nDo not edit files and do not revise the plan yet.\\n\",\n\t\"grill-plan\":\n\t\t\"You are attacking the plan below, not executing it.\\n\\nReview it as a skeptical reviewer would:\\n- Which steps rest on assumptions you have not verified in the codebase? Read the relevant files and verify them now.\\n- Where could this fail silently — wrong-but-plausible behaviour rather than a loud error?\\n- What does the goal require that the plan does not cover? What does the plan cover that the goal does not need?\\n- Does the verification section prove the goal is met, or only that the code runs?\\n\\nReport what you find. Where a weakness is real, revise the plan file and state what changed. Where the plan holds up, say so plainly rather than inventing criticism. Do not implement anything.\\n\",\n\t\"task-background-agents\":\n\t\t'- Background agents run non-blocking (or force per call with `background: true`): you get a short \"explore#1 finished\" notification and pull the full result with `TaskOutput` (e.g. `TaskOutput(\"explore#1\")`); `TaskOutput(list: true)` shows what\\'s running.\\n- After dispatching, don\\'t idle — keep doing independent work (read/edit unrelated files, draft, dispatch more); barrier with `TaskOutput(wait: true)` (a named task, or all outstanding when no id) only when you genuinely can\\'t proceed.\\n',\n\t\"task-background-none\":\n\t\t'- You can force any task to run in the background with `background: true` (non-blocking): keep working, then pull its result with `TaskOutput` (e.g. `TaskOutput(\"explore#1\")`) or block on it with `TaskOutput(wait: true)`.\\n',\n\t\"task-main\":\n\t\t\"You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer. Pick an agent by name from the <available_agents> list in this prompt and pass it as `subagent_type`.\\n\\nDelegate when you need only the final result: a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug), an investigation you want running in parallel without spending your own context, or a long command or test suite you would block on. Use `explore` for read-only scouting, `plan` for research before changes. Dispatch independent subtasks in the same turn. Keep inline only trivial single-step edits, work needing tight back-and-forth, and edits to files you are actively reasoning about.\\n\\nModel tier (optional `complexity`): `fast` for quick reads/lookups, `standard` for multi-file edits, `capable` for deep architecture. Omit to use the agent's default; an agent pinning its own model ignores it.\\n\\nGuidelines:\\n- Choose the agent whose description best matches the task.\\n- The subagent cannot see this conversation and returns ONLY its final answer — pass all context (files, constraints, prior findings) in `prompt`.\\n{{BACKGROUND_GUIDANCE}}\\n- When working a TodoWrite plan, mark the item in_progress BEFORE dispatching: each dispatch is attributed to the current in_progress item in the task panel.\\n- To continue a previous subagent, call Task with `resume_task_id` set to its task_id; it resumes with its full transcript and `prompt` is your follow-up.\\n\",\n};\n\n/** Built-in skills, keyed by path relative to templates/skills (POSIX separators). */\nexport const EMBEDDED_SKILLS: Record<string, string> = {\n\t\"artifact-design/SKILL.md\":\n\t\t\"---\\nname: artifact-design\\ndescription: Build a self-contained HTML visual written to disk — page, report, dashboard, mockup, diagram, or poster. Load before the first line of markup or CSS whenever something has to look right, or a redesign is asked for. Not for app code the project's own design system already governs.\\nallowed-tools: read, write, edit, SearchCodebase\\n---\\n\\n# Designing a visual\\n\\nhoocode writes visuals as one self-contained `.html` file on disk. There is no\\nhost, no CSP, and no gallery: fonts and libraries may come from a CDN or from\\nlocal files, and the page is yours to lay out however the subject demands. The\\nconstraint that remains is the only one that ever mattered — it has to be good.\\n\\nNot for a canvas extension. A canvas serves a live page from its own loopback\\nserver, under constraints that contradict half of this file, and `/new-canvas`\\npoints at `../canvas-design/SKILL.md` for it.\\n\\n## First, read the request\\n\\nDecide the treatment, not whether to design. Every visual gets real typographic\\nhierarchy, considered spacing, and a deliberate palette. What varies is how far\\npast that you go.\\n\\n- **Utilitarian** — a report, a plan, a status page, a diagram. Most requests.\\n Make it clean and well-composed. Skip the oversized hero. Keep flourishes few.\\n- **Editorial** — a landing page, a poster, something the user will show other\\n people. Take a real point of view and one deliberate risk.\\n\\nWhen unsure, build the well-composed version. A restrained page is never wrong;\\nan over-designed one sometimes is.\\n\\n## Honor what already exists\\n\\nLook before you invent. If the repo has a design system — a tokens file, a\\ntheme, CSS variables, an existing stylesheet, a brand section in a project\\ncontext file — use it. Precedence is always:\\n\\n1. What the user asked for, in their words\\n2. The project's existing system\\n3. Your own choices\\n\\nYour choices fill gaps. They never override the first two.\\n\\n## Write the plan before the markup\\n\\nThis is the part that does the work. Before any code, write down:\\n\\n- **Color** — 4 to 6 named hex values. Name them by role (`ink`, `ground`,\\n `accent`, `muted`), not by hue.\\n- **Type** — at least two faces with distinct jobs: one with character for\\n display, one comfortable for body text, and a third for data or captions if\\n the content needs it. Name the fallback stack for each.\\n- **Layout** — the structural idea in one or two sentences.\\n\\nThen build from the plan and derive every color and type decision from it. A\\npage assembled without a plan reads as assembled without a plan.\\n\\n## Fundamentals\\n\\n**Ground it in the subject.** One concrete subject, one audience, one job for\\nthe page. Distinctive choices come from the subject's own world — its materials,\\nits vocabulary, how people in it actually talk. Use real content throughout.\\nNever lorem, never placeholder rows.\\n\\n**Type carries the page,** including when the page is not about type. Keep\\nrunning text near 65 characters wide. Set a scale and stay on it. Give headings\\n`text-wrap: balance`, give body text line-height room, give uppercase labels a\\nlittle letter-spacing. Always declare a real fallback stack — a silent fallback\\nis the most common way a good design ships looking wrong.\\n\\n**Pick the neutrals.** A pure mid-grey reads as unconsidered. Bias the greys\\nslightly toward the accent hue and they read as chosen. Pure white and near-black\\nare fine grounds when the subject wants them; the point is that you decided.\\n\\n**Let layout do the spacing.** Flex or grid with `gap`, not per-element margins\\nthat collapse or double unpredictably. Wide content — tables, code blocks,\\ndiagrams — gets its own `overflow-x: auto` container so the page body never\\nscrolls sideways. Use `font-variant-numeric: tabular-nums` wherever digits line\\nup in a column.\\n\\n**Design both themes.** A local page sees only `prefers-color-scheme`, so this\\nis simpler here than on a hosted target: define the complete palette as custom\\nproperties on `:root`, redefine only those properties inside\\n`@media (prefers-color-scheme: dark)`, and style every component through the\\nproperties. Never give a color its only definition inside the media block — that\\nis how a page ends up rendering one theme's text on the other theme's ground.\\nSet an explicit `background` on `body`. Give the second theme the same attention\\nas the first rather than inverting it mechanically; check that the accent still\\nworks on both grounds. A page that deliberately commits to one visual world may\\nstay single-theme, but then paint every color explicitly so it holds either way.\\n\\n**Structure should encode something true.** Numbered markers, eyebrows,\\ndividers, and section labels are information, not decoration. Number things only\\nwhen the order actually matters to the reader.\\n\\n**When it is a UI, not a document,** the craft shifts from typography to\\ninformation design. A dashboard is scanned, not read. Put the summary above the\\ndetail. Encode state in form as well as in number — a pill, a chip, a severity\\nstripe — so what needs attention is visible at a glance. Semantic color (good,\\nwarning, critical) is a separate system from your accent and does not count as\\nusing it. Anything interactive should look interactive.\\n\\n## Avoid the generated look\\n\\nMachine-generated design keeps landing on the same handful of looks. When the\\nuser has specified a direction, follow it exactly, including if it is one of\\nthese. When nothing is specified, do not spend the freedom here:\\n\\n- Warm cream ground, serif display face, terracotta accent\\n- Near-black ground with a single acid-green or vermilion pop\\n- Hairline rules and dense columns imitating a broadsheet\\n- Purple-to-blue gradient hero on white\\n- Inter or Space Grotesk chosen as the safe default\\n- Emoji as section markers\\n- Everything centered\\n- Uniform large corner radii on every surface\\n- A colored accent rail down the side of every card\\n\\n## Words are design material\\n\\nWrite from the reader's side of the screen. Name things the way they would name\\nthem, not the way the system is built. Active voice. A control says exactly what\\nit does, and the confirmation matches it. Errors say what went wrong and what to\\ndo about it. Specific beats clever.\\n\\nGive the page a real `<title>` — a short, specific noun phrase, not a category\\nlabel and not a name with an explainer bolted on after a dash.\\n\\n## Libraries, and why the answer is usually none\\n\\nA hosted page and a file on disk fail differently, and that decides this. A\\nhosted page is always viewed online, so a CDN dependency is free. A file gets\\nmoved, attached to mail, and opened on a laptop in a tunnel — and there a\\nruntime dependency does not degrade, it collapses. Tailwind from a CDN with no\\nnetwork is an unstyled document. React from a CDN with no network is a blank\\none.\\n\\nSo the default is no runtime dependency at all. Write plain CSS; modern CSS has\\ncustom properties, grid, `clamp()`, and container queries, and a page that needs\\na utility framework to be laid out usually needs a clearer layout instead.\\n\\nThere is no build step here and nothing bundles this file, so a framework that\\nexpects one — Vite, a JSX pipeline, anything importing bare module specifiers —\\nis not an option regardless.\\n\\nWhen a library genuinely earns its place, and that is mostly charting or syntax\\nhighlighting rather than layout:\\n\\n- Inline it into the file if its licence permits, and the page stays whole.\\n- Otherwise pin an exact version, give the feature a readable fallback for when\\n the script does not load, and tell the user the page needs network.\\n\\nWebfonts are the one dependency that degrades gracefully, because a real\\nfallback stack keeps the page readable when the link fails. Use one, and always\\ndeclare the stack.\\n\\n## Build cleanly\\n\\n- Watch selector specificity. Type-level and element-level selectors fighting\\n over the same padding is how spacing silently comes undone.\\n- Close every non-void element and double-quote every attribute.\\n- Give keyboard focus a visible state.\\n- Respect `prefers-reduced-motion`.\\n- For generative or decorative graphics, reach for Canvas or WebGL rather than\\n hand-authoring long SVG path data.\\n- Before finishing, scan the stylesheet for any color declared only inside a\\n media query.\\n\\n## Delivering it\\n\\nWrite one self-contained `.html` file. Inline the page's own CSS and JS; embed\\nsmall assets as data URIs so the file survives being moved or sent to someone.\\n\\nPut it where the user would expect it — alongside the data it visualizes, or in\\nthe directory they named. Then give them the path as a markdown link with a\\n`file://` URL:\\n\\n```\\n[tokens.html](file:///abs/path/to/tokens.html)\\n```\\n\\nhoocode's markdown renderer turns that into an OSC 8 hyperlink wherever the\\nterminal supports one, so it is clickable in kitty, iTerm2, WezTerm and others,\\nand still readable as plain text everywhere else. Offer to open it rather than\\nopening it unasked.\\n\\nCanvas is not a viewer for this. `/canvas` hosts canvas extensions — a directory\\nwith an `extension.mjs` speaking the canvas JSON-RPC protocol — and `/canvas\\nopen` takes an extension id, not a file path. A page you can hand someone is a\\nfile; reach for `/new-canvas` only when the user wants a live surface the agent\\ncan call typed actions on, which is a different and larger job than a visual.\\n\",\n\t\"canvas-design/SKILL.md\":\n\t\t\"---\\nname: canvas-design\\ndescription: How to make a canvas extension's page good — layout, styling, live state, and the dependency and token constraints the surface imposes. Read when building or editing a canvas; the /new-canvas brief points here.\\ndisable-model-invocation: true\\nallowed-tools: read, write, edit, SearchCodebase\\n---\\n\\n# Designing a canvas\\n\\nA canvas is not a document. It is a small application: a page served over\\nloopback that a person operates while you drive the same state through typed\\nactions. Both of you are live on it at once, and that is the whole design\\nproblem.\\n\\nRead `../artifact-design/SKILL.md` for the fundamentals — treatment, the\\ncolor/type/layout plan you write before any markup, neutrals, spacing, the\\ngenerated-look list. All of it applies. This file covers only what is different\\nbecause the surface is a canvas, and where the two disagree, this file wins.\\n\\n## What the catalog already tells you\\n\\nOf the 23 extensions in GitHub's canvas catalog, 22 import nothing but\\n`@github/copilot-sdk` and `node:` builtins. The single exception ships a README\\ntelling the user to `npm install` by hand. Zero dependencies is not a\\nrestriction someone imposed on you; it is what working canvases actually do.\\n\\nThe flagship, `pr-artifact-explorer`, is a rich **read** surface the agent\\nnavigates — its shared state is a cache and a route, and neither party co-edits\\ncontent. It sidesteps concurrent editing entirely. Treat that as evidence about\\nwhat is easy and what is not: a canvas that shows state well is worth far more\\nthan one that lets both parties type into the same field.\\n\\n## The page lives inside a template string\\n\\nThe HTML is a JavaScript template literal in `extension.mjs`, not a file. Two\\nconsequences worth planning around rather than discovering:\\n\\n- Every backtick and `${` in your CSS or markup needs escaping. A `grid-template`\\n value or a JS snippet with a template literal inside it will break the outer\\n string. Prefer plain quotes and avoid nesting template literals.\\n- There is no stylesheet to open in an editor. Keep the CSS in one clearly\\n delimited chunk near the top of the served string so it stays findable, rather\\n than scattering inline `style=` attributes.\\n\\nIf the page grows past a screenful of markup, serve it from a separate file in\\nthe extension directory and read it at request time. The extension is already an\\nHTTP server; it can serve its own assets. That is the escape hatch from string\\nescaping, and it does not violate the no-dependency rule.\\n\\n## No dependencies, and no build\\n\\n`package.json` and `node_modules` are forbidden in the extension directory, so\\nthere is nothing to install and nothing to bundle. Write plain CSS and plain\\nDOM. Modern CSS has custom properties, grid, and `clamp()`; a canvas that needs\\na utility framework needs a clearer layout instead.\\n\\nDo not reach for a CDN either. The page is served from `127.0.0.1`, so it works\\nwith no network — a CDN script throws that away and turns an offline-capable\\nlocal tool into a broken one.\\n\\n## You own the theme completely\\n\\nThe canvas protocol carries no theme, no palette, and no styling hook. Nothing\\nis inherited. A page that sets no colors gets browser defaults, which is why the\\nscaffold's placeholder looks like nothing.\\n\\nSo define the full palette as custom properties on `:root`, redefine them under\\n`@media (prefers-color-scheme: dark)`, and style everything through them. Set an\\nexplicit `background` on `body`. This is the same discipline as any page, with\\none simplification: there is no host stamping `data-theme`, so two states is the\\nwhole problem.\\n\\n## Design for two operators\\n\\nThe person changes state through the page. You change the same state through\\n`invoke_canvas_action`. The page has to be honest about that:\\n\\n- **Render from server state, not from what the user just clicked.** After an\\n action mutates state, the page must be able to show the new truth. Poll on a\\n short interval, or push with SSE — both are a few lines with no dependency.\\n- **Make agent-reachable state visible.** If an action can add a note, the notes\\n should be on screen. State only you can see is state the person cannot trust.\\n- **Do not build co-editing.** Concurrent edits to one field is the hard problem\\n the reference canvas declined to solve. Prefer append, toggle, and select over\\n a shared text buffer.\\n- **Show that something changed.** When state moves underneath the person, a\\n brief highlight on the changed row beats a silent re-render.\\n\\n## Actions are tool schemas, so they cost\\n\\nEvery action becomes an agent-callable tool while the instance is open, and its\\nname, description, and `inputSchema` are re-sent on every request for as long as\\nit stays open. Declare the actions the canvas actually needs and give each a\\ntight schema — not one per button.\\n\\nAction results land in the model's context too. Return a summary and a count,\\nnot the whole collection; where a list is genuinely useful, slice it and set a\\nflag saying you did. Measure with `hoocode --print-token-surface` while a canvas\\nis open.\\n\\n## Reload replaces the URL\\n\\nReloading forks a new process and hands back a **new** URL; the tab the person\\nhad open dies with the old one. Two design consequences:\\n\\n- Keep meaningful state on the server side of the canvas, not in the page. A\\n scroll position is fine to lose; a half-filled form is not.\\n- Give the person the new URL every time you reload, and say the old tab is\\n dead. A page that silently stopped updating looks like a bug you caused.\\n\\n## Before you call it done\\n\\n- Open it and look, rather than reasoning about the markup.\\n- Check both color schemes.\\n- Resize narrow — a canvas is often a side window, not a full screen.\\n- Invoke each action and confirm the page reflects it without a manual refresh.\\n- Confirm the page still renders with the network off.\\n\",\n\t\"plugin-authoring/SKILL.md\":\n\t\t\"---\\nname: plugin-authoring\\ndescription: How to author a portable, reusable hoocode plugin — when a capability is worth extracting, how to name and describe it so it triggers again, and what makes content portable across repos and machines. Use before calling ProposePlugin or UpdatePlugin, or when deciding whether a recipe you just completed is worth keeping.\\nallowed-tools: read, write, edit, SearchCodebase\\n---\\n\\n# Authoring a plugin\\n\\nThis is the craft half of the plugin tools. `ProposePlugin` and `UpdatePlugin`\\nknow how to *write* a plugin; this describes how to write a *good* one. Read it\\nbefore authoring, not after.\\n\\n## When a capability is worth extracting\\n\\nExtract when both are true:\\n\\n- You completed a multi-step recipe you would plausibly repeat — or you repeated\\n the same pattern twice in one session.\\n- `SearchPlugins` found nothing that already covers it.\\n\\nDo not extract a one-off. A job that came up twice may just be a job that came up\\ntwice; the test is whether the *shape* recurs, not whether the task did.\\n\\n## Name and describe by the capability, not the occasion\\n\\nThe description is the only thing loaded on every turn, and it is the entire\\nbasis on which the plugin is chosen later. Write it for the next situation, not\\nfor the one that prompted it.\\n\\n- Bad: `fix-flaky-auth-test` — names the incident. It will never trigger again.\\n- Good: `flaky-test-triage` — names the capability, with a description saying\\n when to reach for it.\\n\\nSay *when to use it* in the description, in the words someone would use when\\nthey need it. A description that only says what the plugin is will not trigger.\\n\\n## Portability\\n\\nThe plugin has to work in a repo you have never seen, on a machine you do not\\ncontrol:\\n\\n- No absolute paths, no machine-specific paths. Prefer relative paths and\\n runtime discovery.\\n- No embedded secrets, tokens, or environment-specific values.\\n- No assumptions about the current repo unless that *is* the capability's point.\\n- State prerequisites in the body rather than assuming them.\\n\\nThe layout is the session's target platform. You never choose it.\\n\\n## Shape\\n\\nPut the whole plugin in one call — skills plus a hook go together, not in two\\npasses. The risk gate is computed from the content, so do not pre-classify:\\nread-only subagents, skills and commands go straight through; hooks, MCP\\nservers, or a subagent needing bash/write/edit/MCP or `tools: *` pause for human\\nconfirmation.\\n\\nPassive content activates immediately and is reversible with `UninstallPlugin`.\\nAnnounce what you created and why.\\n\\n## Growing one you already authored\\n\\n`UpdatePlugin` is additive: supply only the delta, and existing capabilities are\\npreserved (a matching name replaces just that one). It cannot remove anything —\\nthat is `RemovePluginCapability`.\\n\\nHooks are the exception to \\\"additive is safe\\\". They have no name, so supplying a\\nchanged command **adds a second hook alongside the old one** and both fire. To\\nchange a hook, remove the old one first, then add the new one.\\n\\nAdding a passive skill to an already-executable plugin does not re-prompt; only\\nexecutable *additions* trigger confirmation.\\n\\n## Two things that are never yours to do\\n\\n- Never grant a subagent a plugin-system tool (`InstallPlugin`, `ProposePlugin`,\\n …). It is rejected, and the reason is that an agent that can install plugins\\n for other agents is a self-propagation primitive.\\n- Never publish to a marketplace autonomously. Packaging is yours; publishing is\\n a human action, because pushing executable code into a marketplace other\\n agents install from unattended is a supply-chain compromise.\\n\",\n};\n"]}