opencode-dux 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/agents/descriptions.d.ts +6 -0
- package/dist/agents/designer.d.ts +2 -0
- package/dist/agents/explorer.d.ts +2 -0
- package/dist/agents/fixer.d.ts +2 -0
- package/dist/agents/index.d.ts +22 -0
- package/dist/agents/interpreter.d.ts +2 -0
- package/dist/agents/librarian.d.ts +2 -0
- package/dist/agents/oracle.d.ts +2 -0
- package/dist/agents/orchestrator.d.ts +27 -0
- package/dist/agents/overrides.d.ts +18 -0
- package/dist/agents/prompt-blocks.d.ts +97 -0
- package/dist/agents/steward.d.ts +3 -0
- package/dist/cli/config-io.d.ts +24 -0
- package/dist/cli/config-manager.d.ts +4 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +1006 -0
- package/dist/cli/install.d.ts +2 -0
- package/dist/cli/mcps.d.ts +13 -0
- package/dist/cli/model-key-normalization.d.ts +1 -0
- package/dist/cli/paths.d.ts +35 -0
- package/dist/cli/providers.d.ts +137 -0
- package/dist/cli/skills.d.ts +22 -0
- package/dist/cli/system.d.ts +5 -0
- package/dist/cli/types.d.ts +38 -0
- package/dist/config/constants.d.ts +12 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/loader.d.ts +40 -0
- package/dist/config/runtime-preset.d.ts +12 -0
- package/dist/config/schema.d.ts +281 -0
- package/dist/config/utils.d.ts +10 -0
- package/dist/discovery/local/types.d.ts +79 -0
- package/dist/discovery/local.d.ts +73 -0
- package/dist/discovery/mcp-servers.d.ts +88 -0
- package/dist/discovery/skills.d.ts +94 -0
- package/dist/hooks/apply-patch/codec.d.ts +7 -0
- package/dist/hooks/apply-patch/errors.d.ts +25 -0
- package/dist/hooks/apply-patch/execution-context.d.ts +27 -0
- package/dist/hooks/apply-patch/index.d.ts +15 -0
- package/dist/hooks/apply-patch/matching.d.ts +26 -0
- package/dist/hooks/apply-patch/operations.d.ts +3 -0
- package/dist/hooks/apply-patch/patch.d.ts +2 -0
- package/dist/hooks/apply-patch/prepared-changes.d.ts +17 -0
- package/dist/hooks/apply-patch/resolution.d.ts +19 -0
- package/dist/hooks/apply-patch/rewrite.d.ts +7 -0
- package/dist/hooks/apply-patch/test-helpers.d.ts +6 -0
- package/dist/hooks/apply-patch/types.d.ts +80 -0
- package/dist/hooks/auto-update-checker/cache.d.ts +11 -0
- package/dist/hooks/auto-update-checker/checker.d.ts +32 -0
- package/dist/hooks/auto-update-checker/constants.d.ts +11 -0
- package/dist/hooks/auto-update-checker/index.d.ts +18 -0
- package/dist/hooks/auto-update-checker/types.d.ts +22 -0
- package/dist/hooks/chat-headers.d.ts +16 -0
- package/dist/hooks/context-pressure-reminder/index.d.ts +33 -0
- package/dist/hooks/delegate-task-retry/guidance.d.ts +2 -0
- package/dist/hooks/delegate-task-retry/hook.d.ts +8 -0
- package/dist/hooks/delegate-task-retry/index.d.ts +4 -0
- package/dist/hooks/delegate-task-retry/patterns.d.ts +11 -0
- package/dist/hooks/filter-available-skills/index.d.ts +32 -0
- package/dist/hooks/foreground-fallback/index.d.ts +72 -0
- package/dist/hooks/image-hook.d.ts +5 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/json-error-recovery/hook.d.ts +18 -0
- package/dist/hooks/json-error-recovery/index.d.ts +1 -0
- package/dist/hooks/phase-reminder/index.d.ts +26 -0
- package/dist/hooks/post-file-tool-nudge/index.d.ts +19 -0
- package/dist/hooks/task-session-manager/index.d.ts +52 -0
- package/dist/hooks/todo-continuation/index.d.ts +53 -0
- package/dist/hooks/todo-continuation/todo-hygiene.d.ts +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +31782 -0
- package/dist/mcp/context7.d.ts +6 -0
- package/dist/mcp/grep-app.d.ts +6 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/websearch.d.ts +9 -0
- package/dist/skills/registry.d.ts +29 -0
- package/dist/subscriptions/accounts-store.d.ts +57 -0
- package/dist/subscriptions/index.d.ts +13 -0
- package/dist/subscriptions/neuralwatt-scraper.d.ts +14 -0
- package/dist/subscriptions/opencode-go-scraper.d.ts +27 -0
- package/dist/subscriptions/types.d.ts +115 -0
- package/dist/subscriptions/usage-service.d.ts +74 -0
- package/dist/tools/ast-grep/cli.d.ts +15 -0
- package/dist/tools/ast-grep/constants.d.ts +25 -0
- package/dist/tools/ast-grep/downloader.d.ts +5 -0
- package/dist/tools/ast-grep/index.d.ts +10 -0
- package/dist/tools/ast-grep/tools.d.ts +3 -0
- package/dist/tools/ast-grep/types.d.ts +30 -0
- package/dist/tools/ast-grep/utils.d.ts +4 -0
- package/dist/tools/delegate.d.ts +14 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/preset-manager.d.ts +27 -0
- package/dist/tools/smartfetch/binary.d.ts +3 -0
- package/dist/tools/smartfetch/cache.d.ts +6 -0
- package/dist/tools/smartfetch/constants.d.ts +12 -0
- package/dist/tools/smartfetch/index.d.ts +3 -0
- package/dist/tools/smartfetch/network.d.ts +38 -0
- package/dist/tools/smartfetch/secondary-model.d.ts +28 -0
- package/dist/tools/smartfetch/tool.d.ts +3 -0
- package/dist/tools/smartfetch/types.d.ts +122 -0
- package/dist/tools/smartfetch/utils.d.ts +18 -0
- package/dist/tui-state.d.ts +168 -0
- package/dist/tui.d.ts +37 -0
- package/dist/tui.js +1896 -0
- package/dist/utils/agent-variant.d.ts +63 -0
- package/dist/utils/compat.d.ts +30 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/internal-initiator.d.ts +6 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/polling.d.ts +21 -0
- package/dist/utils/session-manager.d.ts +55 -0
- package/dist/utils/session.d.ts +90 -0
- package/dist/utils/subagent-depth.d.ts +35 -0
- package/dist/utils/system-collapse.d.ts +6 -0
- package/dist/utils/task.d.ts +4 -0
- package/dist/utils/zip-extractor.d.ts +1 -0
- package/index.ts +1 -0
- package/opencode-dux.schema.json +634 -0
- package/package.json +103 -0
- package/src/agents/descriptions.ts +55 -0
- package/src/agents/designer.test.ts +86 -0
- package/src/agents/designer.ts +154 -0
- package/src/agents/display-name.test.ts +186 -0
- package/src/agents/explorer.test.ts +79 -0
- package/src/agents/explorer.ts +144 -0
- package/src/agents/fixer.test.ts +79 -0
- package/src/agents/fixer.ts +145 -0
- package/src/agents/index.test.ts +472 -0
- package/src/agents/index.ts +248 -0
- package/src/agents/interpreter.ts +136 -0
- package/src/agents/librarian.test.ts +80 -0
- package/src/agents/librarian.ts +145 -0
- package/src/agents/oracle.test.ts +89 -0
- package/src/agents/oracle.ts +184 -0
- package/src/agents/orchestrator.test.ts +116 -0
- package/src/agents/orchestrator.ts +574 -0
- package/src/agents/overrides.ts +95 -0
- package/src/agents/prompt-blocks.test.ts +114 -0
- package/src/agents/prompt-blocks.ts +640 -0
- package/src/agents/steward.ts +146 -0
- package/src/cli/config-io.test.ts +536 -0
- package/src/cli/config-io.ts +473 -0
- package/src/cli/config-manager.test.ts +141 -0
- package/src/cli/config-manager.ts +4 -0
- package/src/cli/index.ts +88 -0
- package/src/cli/install.ts +282 -0
- package/src/cli/mcps.test.ts +62 -0
- package/src/cli/mcps.ts +39 -0
- package/src/cli/model-key-normalization.test.ts +21 -0
- package/src/cli/model-key-normalization.ts +60 -0
- package/src/cli/paths.test.ts +167 -0
- package/src/cli/paths.ts +144 -0
- package/src/cli/providers.test.ts +118 -0
- package/src/cli/providers.ts +141 -0
- package/src/cli/skills.test.ts +111 -0
- package/src/cli/skills.ts +103 -0
- package/src/cli/system.test.ts +91 -0
- package/src/cli/system.ts +180 -0
- package/src/cli/types.ts +43 -0
- package/src/config/constants.ts +58 -0
- package/src/config/index.ts +4 -0
- package/src/config/loader.test.ts +1194 -0
- package/src/config/loader.ts +269 -0
- package/src/config/model-resolution.test.ts +176 -0
- package/src/config/runtime-preset.test.ts +61 -0
- package/src/config/runtime-preset.ts +37 -0
- package/src/config/schema.ts +248 -0
- package/src/config/utils.test.ts +41 -0
- package/src/config/utils.ts +23 -0
- package/src/discovery/local/types.ts +85 -0
- package/src/discovery/local.ts +322 -0
- package/src/discovery/mcp-servers.ts +804 -0
- package/src/discovery/skills.ts +959 -0
- package/src/hooks/apply-patch/codec.test.ts +184 -0
- package/src/hooks/apply-patch/codec.ts +352 -0
- package/src/hooks/apply-patch/errors.ts +117 -0
- package/src/hooks/apply-patch/execution-context.ts +432 -0
- package/src/hooks/apply-patch/hook.test.ts +768 -0
- package/src/hooks/apply-patch/index.ts +126 -0
- package/src/hooks/apply-patch/matching.test.ts +215 -0
- package/src/hooks/apply-patch/matching.ts +586 -0
- package/src/hooks/apply-patch/operations.test.ts +1535 -0
- package/src/hooks/apply-patch/operations.ts +3 -0
- package/src/hooks/apply-patch/patch.ts +9 -0
- package/src/hooks/apply-patch/prepared-changes.ts +400 -0
- package/src/hooks/apply-patch/resolution.test.ts +420 -0
- package/src/hooks/apply-patch/resolution.ts +437 -0
- package/src/hooks/apply-patch/rewrite.ts +496 -0
- package/src/hooks/apply-patch/test-helpers.ts +52 -0
- package/src/hooks/apply-patch/types.ts +111 -0
- package/src/hooks/auto-update-checker/cache.test.ts +179 -0
- package/src/hooks/auto-update-checker/cache.ts +188 -0
- package/src/hooks/auto-update-checker/checker.test.ts +159 -0
- package/src/hooks/auto-update-checker/checker.ts +308 -0
- package/src/hooks/auto-update-checker/constants.ts +33 -0
- package/src/hooks/auto-update-checker/index.test.ts +282 -0
- package/src/hooks/auto-update-checker/index.ts +225 -0
- package/src/hooks/auto-update-checker/types.ts +26 -0
- package/src/hooks/chat-headers.test.ts +236 -0
- package/src/hooks/chat-headers.ts +97 -0
- package/src/hooks/context-pressure-reminder/index.test.ts +179 -0
- package/src/hooks/context-pressure-reminder/index.ts +137 -0
- package/src/hooks/delegate-task-retry/guidance.ts +41 -0
- package/src/hooks/delegate-task-retry/hook.ts +23 -0
- package/src/hooks/delegate-task-retry/index.test.ts +38 -0
- package/src/hooks/delegate-task-retry/index.ts +7 -0
- package/src/hooks/delegate-task-retry/patterns.ts +79 -0
- package/src/hooks/filter-available-skills/index.test.ts +297 -0
- package/src/hooks/filter-available-skills/index.ts +160 -0
- package/src/hooks/foreground-fallback/index.test.ts +624 -0
- package/src/hooks/foreground-fallback/index.ts +374 -0
- package/src/hooks/image-hook.ts +6 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/json-error-recovery/hook.ts +73 -0
- package/src/hooks/json-error-recovery/index.test.ts +111 -0
- package/src/hooks/json-error-recovery/index.ts +6 -0
- package/src/hooks/phase-reminder/index.test.ts +74 -0
- package/src/hooks/phase-reminder/index.ts +85 -0
- package/src/hooks/post-file-tool-nudge/index.test.ts +94 -0
- package/src/hooks/post-file-tool-nudge/index.ts +63 -0
- package/src/hooks/task-session-manager/index.test.ts +833 -0
- package/src/hooks/task-session-manager/index.ts +434 -0
- package/src/hooks/todo-continuation/index.test.ts +3026 -0
- package/src/hooks/todo-continuation/index.ts +878 -0
- package/src/hooks/todo-continuation/todo-hygiene.test.ts +204 -0
- package/src/hooks/todo-continuation/todo-hygiene.ts +207 -0
- package/src/index.ts +1672 -0
- package/src/mcp/context7.ts +14 -0
- package/src/mcp/grep-app.ts +11 -0
- package/src/mcp/index.test.ts +96 -0
- package/src/mcp/index.ts +66 -0
- package/src/mcp/types.ts +16 -0
- package/src/mcp/websearch.ts +47 -0
- package/src/skills/codemap/README.md +60 -0
- package/src/skills/codemap/SKILL.md +174 -0
- package/src/skills/codemap/scripts/codemap.mjs +483 -0
- package/src/skills/codemap/scripts/codemap.test.ts +129 -0
- package/src/skills/registry.ts +218 -0
- package/src/skills/simplify/README.md +19 -0
- package/src/skills/simplify/SKILL.md +138 -0
- package/src/subscriptions/accounts-store.test.ts +236 -0
- package/src/subscriptions/accounts-store.ts +184 -0
- package/src/subscriptions/index.ts +30 -0
- package/src/subscriptions/neuralwatt-scraper.ts +108 -0
- package/src/subscriptions/opencode-go-scraper.ts +301 -0
- package/src/subscriptions/types.ts +145 -0
- package/src/subscriptions/usage-service.test.ts +202 -0
- package/src/subscriptions/usage-service.ts +651 -0
- package/src/tools/ast-grep/cli.ts +257 -0
- package/src/tools/ast-grep/constants.ts +214 -0
- package/src/tools/ast-grep/downloader.ts +131 -0
- package/src/tools/ast-grep/index.ts +24 -0
- package/src/tools/ast-grep/tools.ts +117 -0
- package/src/tools/ast-grep/types.ts +51 -0
- package/src/tools/ast-grep/utils.ts +126 -0
- package/src/tools/delegate-handoff.test.ts +18 -0
- package/src/tools/delegate.ts +508 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/preset-manager.test.ts +795 -0
- package/src/tools/preset-manager.ts +332 -0
- package/src/tools/smartfetch/binary.ts +58 -0
- package/src/tools/smartfetch/cache.test.ts +34 -0
- package/src/tools/smartfetch/cache.ts +112 -0
- package/src/tools/smartfetch/constants.ts +29 -0
- package/src/tools/smartfetch/index.ts +8 -0
- package/src/tools/smartfetch/network.test.ts +178 -0
- package/src/tools/smartfetch/network.ts +614 -0
- package/src/tools/smartfetch/secondary-model.test.ts +85 -0
- package/src/tools/smartfetch/secondary-model.ts +276 -0
- package/src/tools/smartfetch/tool.test.ts +60 -0
- package/src/tools/smartfetch/tool.ts +832 -0
- package/src/tools/smartfetch/types.ts +135 -0
- package/src/tools/smartfetch/utils.test.ts +24 -0
- package/src/tools/smartfetch/utils.ts +456 -0
- package/src/tui-state.test.ts +867 -0
- package/src/tui-state.ts +1255 -0
- package/src/tui.test.ts +336 -0
- package/src/tui.ts +1539 -0
- package/src/utils/agent-variant.test.ts +244 -0
- package/src/utils/agent-variant.ts +187 -0
- package/src/utils/compat.ts +91 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/internal-initiator.ts +28 -0
- package/src/utils/logger.test.ts +220 -0
- package/src/utils/logger.ts +136 -0
- package/src/utils/polling.test.ts +191 -0
- package/src/utils/polling.ts +67 -0
- package/src/utils/session-manager.test.ts +173 -0
- package/src/utils/session-manager.ts +356 -0
- package/src/utils/session.test.ts +110 -0
- package/src/utils/session.ts +389 -0
- package/src/utils/subagent-depth.test.ts +170 -0
- package/src/utils/subagent-depth.ts +75 -0
- package/src/utils/system-collapse.test.ts +86 -0
- package/src/utils/system-collapse.ts +24 -0
- package/src/utils/task.test.ts +24 -0
- package/src/utils/task.ts +20 -0
- package/src/utils/zip-extractor.ts +102 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared prompt fragments for the orchestrator and specialist agents.
|
|
3
|
+
* Single source of truth for duplicated routing and variant policy copy.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Subagents use `<needs_user>`; orchestrator runs host `question` once and re-delegates.
|
|
8
|
+
* Shape matches OpenCode SDK `QuestionRequest.questions` / `QuestionInfo` (see
|
|
9
|
+
* `@opencode-ai/sdk` v2 types: `QuestionInfo`, `QuestionOption`).
|
|
10
|
+
*/
|
|
11
|
+
const QUESTION_INFO_SCHEMA = `
|
|
12
|
+
QuestionInfo JSON format (use double-quoted JSON, NO markdown code fences):
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
"question": "Complete question text",
|
|
16
|
+
"header": "Short label (max 30 chars)",
|
|
17
|
+
"options": [
|
|
18
|
+
{"label": "Option text (1-5 words)", "description": "What this choice means"},
|
|
19
|
+
{"label": "Option 2 (1-5 words)", "description": "What this choice means"}
|
|
20
|
+
],
|
|
21
|
+
"multiple": false,
|
|
22
|
+
"custom": true
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
Required fields: question, header, options (array of {label, description})
|
|
26
|
+
Optional: multiple (default false), custom (default true)
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Specialist-safe version: just the QuestionInfo JSON schema so subagents
|
|
31
|
+
* can format their <needs_user> questions correctly.
|
|
32
|
+
*/
|
|
33
|
+
export const SUBAGENT_NEEDS_USER_FORMAT = QUESTION_INFO_SCHEMA;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Full 9-invariant protocol for the orchestrator only.
|
|
37
|
+
* Describes how to handle the question/q&a workflow when subagents
|
|
38
|
+
* return <needs_user>.
|
|
39
|
+
*/
|
|
40
|
+
export const ORCHESTRATOR_CLARIFICATION_HANDOFF = `<orchestrator_clarification>
|
|
41
|
+
Nine invariants for question/q&a workflow:
|
|
42
|
+
|
|
43
|
+
1) Subagent <needs_user> → extract the JSON array from their
|
|
44
|
+
\`<questions>\` block, then call the \`question\` tool with that
|
|
45
|
+
array as the \`questions\` parameter. Pass the JSON as-is
|
|
46
|
+
(no markdown wrapping, no re-serialization).
|
|
47
|
+
Never paste options as chat text - that bypasses the picker UI.
|
|
48
|
+
|
|
49
|
+
Extraction: the \`<questions>...</questions>\` content inside the
|
|
50
|
+
subagent's \`<needs_user>\` block is a JSON array. Parse it and
|
|
51
|
+
pass it directly to the \`question\` tool's \`questions\` parameter.
|
|
52
|
+
If the subagent returned prose or XML instead of JSON, re-delegate
|
|
53
|
+
with \`continue_session_id\` and the note: "Reformat <needs_user>
|
|
54
|
+
questions as JSON per the QuestionInfo schema."
|
|
55
|
+
|
|
56
|
+
2) After user answers: delegate_subagent with \`continue_session_id\`
|
|
57
|
+
from the prior result tag. Copy "User answered:" verbatim into
|
|
58
|
+
prompt. Same agent, model, variant as prior delegation.
|
|
59
|
+
|
|
60
|
+
3) Never substitute your own analysis after \`question\` - resume the
|
|
61
|
+
specialist, don't replace them.
|
|
62
|
+
|
|
63
|
+
4) Multiple subagents return <needs_user> in one round: merge all
|
|
64
|
+
questions into one \`question\` call (prefix each with agent name).
|
|
65
|
+
Resume each with its own \`continue_session_id\`.
|
|
66
|
+
|
|
67
|
+
5) User follow-up questions (? in prose, hybrid ideas, new patterns):
|
|
68
|
+
stay unresolved. Pass through verbatim; only the specialist may
|
|
69
|
+
expand choices via another <needs_user> round.
|
|
70
|
+
|
|
71
|
+
6) Subagent-to-user relay: if the specialist answered a user question
|
|
72
|
+
(definitions, teaching) before <needs_user>, relay that substance
|
|
73
|
+
before calling \`question\` so the picker is not orphaned.
|
|
74
|
+
|
|
75
|
+
6b) If multiple subagents return <needs_user> and any has malformed
|
|
76
|
+
questions, ask only the well-formed ones first. Re-delegate the
|
|
77
|
+
malformed one with format correction note.
|
|
78
|
+
|
|
79
|
+
7) Token discipline: reuse prior @steward/@explorer output; don't
|
|
80
|
+
re-delegate before resume unless scope widens.
|
|
81
|
+
|
|
82
|
+
8) When a subagent returns <blocked> (not <needs_user>), use the
|
|
83
|
+
<subagent_recovery> protocol instead. Both <blocked> and
|
|
84
|
+
<needs_user> share the same continue_session_id resume pattern:
|
|
85
|
+
retrieve missing info first, then re-delegate to the same session.
|
|
86
|
+
</orchestrator_clarification>
|
|
87
|
+
|
|
88
|
+
${QUESTION_INFO_SCHEMA}`;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Shared `<needs_user>` output format for all specialist agents.
|
|
92
|
+
* Contains the scaffolding XML block without agent-specific examples.
|
|
93
|
+
*/
|
|
94
|
+
export const NEEDS_USER_OUTPUT_FORMAT_BLOCK = `<needs_user>
|
|
95
|
+
When the user must decide before you can proceed, output:
|
|
96
|
+
- \`reason\` (1 sentence why the user must decide)
|
|
97
|
+
- \`questions\` as a JSON array of QuestionInfo objects (see schema above).
|
|
98
|
+
|
|
99
|
+
CRITICAL: Output \`<needs_user>\` as raw XML. NEVER wrap it in markdown code fences (\`\`\`).
|
|
100
|
+
</needs_user>`;
|
|
101
|
+
|
|
102
|
+
// New: Standardized repo rules precedence block for all subagents
|
|
103
|
+
export const REPO_RULES_PRECEDENCE_BLOCK = `<repo_rules_precedence>
|
|
104
|
+
When the orchestrator provides steward citations (repo rules from AGENTS.md,
|
|
105
|
+
AGENT.md, .cursor/rules, etc.), those rules ALWAYS override any conflicting
|
|
106
|
+
instructions in this prompt. Repo rules are authoritative.
|
|
107
|
+
|
|
108
|
+
Only ignore a repo rule if following it would cause a security vulnerability
|
|
109
|
+
or data loss - in that case, report the conflict in your output (use <blocked> if the conflict prevents safe continuation) and do NOT proceed.
|
|
110
|
+
</repo_rules_precedence>`;
|
|
111
|
+
|
|
112
|
+
// New: Standardized self-review metacognition block
|
|
113
|
+
export const SELF_REVIEW_BLOCK = `<self_review>
|
|
114
|
+
Before producing your final output, verify against these criteria:
|
|
115
|
+
1) Have I followed my <critical_invariants> without exception?
|
|
116
|
+
2) Does my output match the exact format in <output_format>?
|
|
117
|
+
3) Have I included all required sections and omitted optional ones correctly?
|
|
118
|
+
4) If my task was delegated by the orchestrator, did I answer the EXACT
|
|
119
|
+
question asked (not an adjacent reformulation)?
|
|
120
|
+
5) Is my confidence calibrated - do I distinguish confirmed facts from
|
|
121
|
+
inferences and explicitly label each?
|
|
122
|
+
If any answer is "no," adjust your output before submitting.
|
|
123
|
+
</self_review>`;
|
|
124
|
+
|
|
125
|
+
// New: Standardized user choice policy block
|
|
126
|
+
export const USER_CHOICE_POLICY_BLOCK = `<user_choice_policy>
|
|
127
|
+
When facing a fork where no single option is clearly correct from the
|
|
128
|
+
provided context:
|
|
129
|
+
- Tradeoffs balanced → <needs_user> with options describing what each
|
|
130
|
+
choice optimizes for and gives up.
|
|
131
|
+
- Product scope unclear (who is this for, failure tolerance) → <needs_user>.
|
|
132
|
+
- One clear winner from evidence → state it without asking.
|
|
133
|
+
- Preference among equals → <needs_user>, not a silent "best practice" pick.
|
|
134
|
+
</user_choice_policy>`;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Shared `<blocked>` output format block for all specialist agents.
|
|
138
|
+
* Takes a context string describing when to include the blocked section.
|
|
139
|
+
*/
|
|
140
|
+
export function formatBlockedOutputBlock(context: string): string {
|
|
141
|
+
return `<blocked>
|
|
142
|
+
Only include when ${context}.
|
|
143
|
+
Structure for recovery:
|
|
144
|
+
- <blocked_reason>: 1-2 sentences explaining what is missing or failed.
|
|
145
|
+
- <retrieval_hint>: Concrete instructions for what the orchestrator or another agent should retrieve to unblock this task.
|
|
146
|
+
- <suggested_agent>: Which agent should retrieve this (explorer, librarian, oracle, designer, steward).
|
|
147
|
+
- <suggested_fallback>: Optional alternative approach if the primary tool/source is unavailable.
|
|
148
|
+
- If the blocker is a missing tool that has NO fallback, state that explicitly.
|
|
149
|
+
- If the blocker requires user input rather than retrieval, use <needs_user> instead of <blocked>.
|
|
150
|
+
</blocked>`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// --- Orchestrator invariants ---
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Absolute rules the orchestrator must never violate.
|
|
157
|
+
* Violating any = failure mode.
|
|
158
|
+
*/
|
|
159
|
+
export const CRITICAL_INVARIANTS = `<critical_invariants>
|
|
160
|
+
These are HARD FAILURES. Violating any = broken delegation.
|
|
161
|
+
1) NEVER edit, write, read, or search files yourself. @explorer / @fixer only.
|
|
162
|
+
2) ALWAYS delegate analysis to @oracle (blocking). Never reason through
|
|
163
|
+
debugging, architecture, tradeoffs, or risk in orchestrator prose.
|
|
164
|
+
3) ALWAYS pass explicit \`model\` for @oracle delegation.
|
|
165
|
+
</critical_invariants>
|
|
166
|
+
|
|
167
|
+
<production_safety_gate>
|
|
168
|
+
Before implementing any optimization, refactoring, or "improvement" to agent
|
|
169
|
+
prompts or system behavior, verify ALL of the following:
|
|
170
|
+
|
|
171
|
+
1. **Security**: No security implications (auth, data integrity, privilege
|
|
172
|
+
escalation, input validation, secret handling)
|
|
173
|
+
2. **Correctness**: Current behavior is demonstrably broken or produces wrong
|
|
174
|
+
outputs (not just "could be cleaner")
|
|
175
|
+
3. **User Impact**: Change affects internal implementation only - no breaking
|
|
176
|
+
changes to user-facing behavior without explicit approval
|
|
177
|
+
4. **Test Coverage**: Existing tests cover the affected area AND will catch
|
|
178
|
+
regressions
|
|
179
|
+
5. **Rollback Plan**: Change can be reverted in a single commit if issues arise
|
|
180
|
+
|
|
181
|
+
**If ANY check fails**: Do NOT implement. Flag for human review instead.
|
|
182
|
+
|
|
183
|
+
**Philosophy**: "If it's good enough for production, leave it alone." Only fix
|
|
184
|
+
what's actually broken, not what could theoretically be cleaner.
|
|
185
|
+
</production_safety_gate>
|
|
186
|
+
|
|
187
|
+
<procedural_invariants>
|
|
188
|
+
These ensure quality. Violating = incomplete work.
|
|
189
|
+
4) Run <first_gate> item 1 (steward/explorer briefs) before code work.
|
|
190
|
+
5) Run <planning_gate> for non-trivial changes - plan, present, adjust,
|
|
191
|
+
implement. Never skip user confirmation.
|
|
192
|
+
6) Report verification before declaring success.
|
|
193
|
+
</procedural_invariants>`;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Planning gate workflow for non-trivial changes.
|
|
197
|
+
* Introduces plan → present → adjust → implement cycle.
|
|
198
|
+
*/
|
|
199
|
+
export const PLANNING_GATE_BLOCK = `<planning_gate>
|
|
200
|
+
When the user requests non-trivial changes (anything beyond pure meta or
|
|
201
|
+
mechanical edits), follow this cycle:
|
|
202
|
+
|
|
203
|
+
1) ANALYSIS: After steward brief (per <first_gate> item 1 and
|
|
204
|
+
<procedural_invariants> item 4), blocking @oracle analyzes the
|
|
205
|
+
technical approach (no implementation).
|
|
206
|
+
Oracle output must include a concrete plan section the user can review.
|
|
207
|
+
2) PRESENT: Always present the @oracle plan to the user for confirmation.
|
|
208
|
+
This step is MANDATORY — never skip it for any non-trivial change.
|
|
209
|
+
- If @oracle used <needs_user> with questions: extract JSON, call \`question\` tool, relay answers back via continue_session_id, then present the final plan.
|
|
210
|
+
- Otherwise: relay the plan's key decisions, file paths, and risks as text.
|
|
211
|
+
- Ask the user to confirm or request adjustments before proceeding.
|
|
212
|
+
Wait for explicit user approval before step 4.
|
|
213
|
+
3) ADJUST (if needed): User requests changes → re-delegate @oracle with
|
|
214
|
+
\`continue_session_id\` (same session, incremental). Repeat until approval.
|
|
215
|
+
4) IMPLEMENT: Only after explicit user approval → delegate to @fixer with
|
|
216
|
+
the approved plan as context.
|
|
217
|
+
|
|
218
|
+
Skip this gate ONLY when:
|
|
219
|
+
- Pure meta questions ("what agents exist?")
|
|
220
|
+
- Mechanical edits (typo, single-line fix, known path)
|
|
221
|
+
- Tasks where the user's message already specifies the exact implementation
|
|
222
|
+
(e.g., "rename getCwd to getCurrentWorkingDir in src/utils/fs.ts")
|
|
223
|
+
</planning_gate>`;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Plan handoff block for oracle's pre-implementation planning mode.
|
|
227
|
+
* Instructs oracle to structure plans for end-user readability and avoid
|
|
228
|
+
* using <needs_user> just to deliver a plan.
|
|
229
|
+
*/
|
|
230
|
+
export const ORACLE_PLAN_HANDOFF_BLOCK = `<plan_handoff>
|
|
231
|
+
When creating a plan for pre-implementation planning (the orchestrator
|
|
232
|
+
delegates with "for pre-implementation planning"):
|
|
233
|
+
- Return the plan as normal structured output with <plan>...</plan> section.
|
|
234
|
+
The orchestrator will present this plan to the user for confirmation.
|
|
235
|
+
- Do NOT use <needs_user> just to deliver the plan — plan presentation is
|
|
236
|
+
the orchestrator's job, not the oracle's.
|
|
237
|
+
- Use <needs_user> only for genuine architectural forks where your analysis
|
|
238
|
+
cannot select a single best approach (per <user_choice_policy>).
|
|
239
|
+
- Structure the <plan> section for END-USER readability, not implementer
|
|
240
|
+
notes: clear file paths, concrete change descriptions, tradeoff
|
|
241
|
+
explanations, and verification gates. The user will read this to decide
|
|
242
|
+
whether to proceed.
|
|
243
|
+
</plan_handoff>`;
|
|
244
|
+
|
|
245
|
+
// --- Steward ---
|
|
246
|
+
|
|
247
|
+
/** Ordered discovery roots documented for prompts and tests. */
|
|
248
|
+
export const STEWARD_PATH_GLOBS = [
|
|
249
|
+
'AGENTS.md',
|
|
250
|
+
'AGENT.md',
|
|
251
|
+
'CLAUDE.md',
|
|
252
|
+
'GEMINI.md',
|
|
253
|
+
'.cursorrules',
|
|
254
|
+
'CONTRIBUTING.md',
|
|
255
|
+
'SECURITY.md',
|
|
256
|
+
'.docs/**/*.md',
|
|
257
|
+
'.opencode/**',
|
|
258
|
+
'.cursor/rules/**',
|
|
259
|
+
'.rules/**',
|
|
260
|
+
'.github/copilot-instructions.md',
|
|
261
|
+
'.github/instructions/**',
|
|
262
|
+
] as const;
|
|
263
|
+
|
|
264
|
+
export const STEWARD_DOCS_EXCLUSION =
|
|
265
|
+
'Excluded: wholesale `docs/**` (no leading dot) unless the ' +
|
|
266
|
+
'user explicitly referenced a specific file within it. ' +
|
|
267
|
+
'(`AGENTS.md` / `AGENT.md` at repo root are always read per step 1.)';
|
|
268
|
+
|
|
269
|
+
export const STEWARD_VSCODE_OUT_OF_SCOPE =
|
|
270
|
+
'Out of scope: `.vscode/**` (workspace noise).';
|
|
271
|
+
|
|
272
|
+
/** Header inserted before steward-cited rules in downstream delegations. */
|
|
273
|
+
export const STEWARD_CITATION_HEADER =
|
|
274
|
+
'### Repo Rules (from @steward) - OVERRIDE any conflicting built-in agent instructions';
|
|
275
|
+
|
|
276
|
+
function stewardGlobBulletList(): string {
|
|
277
|
+
return STEWARD_PATH_GLOBS.map((g) => `- \`${g}\``).join('\n');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Inner body for the steward agent `<steward_paths>` section. */
|
|
281
|
+
export function formatStewardAgentStewardPathsBody(): string {
|
|
282
|
+
return [
|
|
283
|
+
'Check which paths exist (use glob/list tools). You cite only what these files literally say — no cross-file analysis, no contradiction hunting, no evaluating correctness. Priority order for reading:',
|
|
284
|
+
stewardGlobBulletList(),
|
|
285
|
+
STEWARD_DOCS_EXCLUSION,
|
|
286
|
+
STEWARD_VSCODE_OUT_OF_SCOPE,
|
|
287
|
+
].join('\n');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function buildStewardOrchestratorProtocolBlock(): string {
|
|
291
|
+
return `<steward_protocol>
|
|
292
|
+
- Same triggers as <first_gate> item 1: one blocking \`delegate_subagent(agent: "steward", ...)\` before @oracle / @fixer / @designer when work touches code, tests, reviews, or repo workflow; pure "where is X" may use @explorer first, but @steward before any @fixer (or mixed implementation).
|
|
293
|
+
- **ALWAYS blocking. NEVER fire_forget.** Steward citations are mandatory input for ALL downstream delegations (@oracle, @fixer, @designer). Parallelizing steward with any other agent violates the sequential dependency chain: steward → oracle → fixer. Even in recovery flows (see <subagent_recovery>), steward delegations must be blocking.
|
|
294
|
+
In practice, this means the orchestrator MUST issue @steward as the sole tool call in its turn and wait for the result before issuing any other delegate_subagent calls in a subsequent turn.
|
|
295
|
+
- Steward prompt: State the convention-domain (e.g., "test conventions", "code style rules", "commit conventions") — NOT the codebase task (e.g., "fix retry logic"). Require \`AGENTS.md\` then \`AGENT.md\` at root when present, then other steward_paths — no vague "check rules" delegations.
|
|
296
|
+
- Steward checks which steward_paths exist (glob/list; existing paths only). Priority order:
|
|
297
|
+
// Note: Steward paths list appears in both steward and orchestrator prompts by design.
|
|
298
|
+
// Each agent needs its own context - this is not code duplication.
|
|
299
|
+
${stewardGlobBulletList()}
|
|
300
|
+
${STEWARD_DOCS_EXCLUSION}
|
|
301
|
+
${STEWARD_VSCODE_OUT_OF_SCOPE}
|
|
302
|
+
- Convention-domain keywords + hints in prompt; cited bullets only. Copy steward citations verbatim into every downstream delegation (@oracle, @fixer, @designer) with the header \`${STEWARD_CITATION_HEADER}\`.
|
|
303
|
+
- PRECEDENCE: Repo rules cited by @steward (AGENTS.md, AGENT.md, .cursor/rules, etc.) ALWAYS override built-in agent prompt rules when they conflict. If a repo rule says "skip tests for docs" and a built-in rule says "always run tests," the repo rule wins. If they don't conflict, follow both.
|
|
304
|
+
- Handoff only: cites steward_paths — not traces, product reads, @explorer search, or @oracle analysis. @steward cites verbatim text from steward_paths files with path attribution. @steward NEVER analyzes rules for correctness, consistency, contradictions, gaps, or applicability to specific code changes. Those tasks are @oracle's responsibility.
|
|
305
|
+
- Attribution: Rules need \`path\` + quote; do not claim steward *proved* code root cause unless the doc says so verbatim-@explorer / @oracle own diagnosis otherwise.
|
|
306
|
+
</steward_protocol>
|
|
307
|
+
|
|
308
|
+
`;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// --- Interpreter ---
|
|
312
|
+
|
|
313
|
+
export function buildInterpreterOrchestratorProtocolBlock(): string {
|
|
314
|
+
return `<interpreter_protocol>
|
|
315
|
+
- When the user message includes images (including pasted screenshots / clipboard) and the task is not explicitly UI redesign/polish, delegate first to \`delegate_subagent(agent: "interpreter", ...)\` (blocking) so vision runs in the specialist session.
|
|
316
|
+
- For explicit UI redesign, accessibility polish, or design-system work, route to @designer instead (may still use @interpreter earlier only if the screenshot context is ambiguous).
|
|
317
|
+
- The UI may show inline placeholders like \`[Image 1]\` or "img clipboard" while the host attaches binary parts separately-you often cannot see pixels yourself on a text-only orchestrator model; still delegate to @interpreter instead of asking the user to "attach again." If delegation errors about missing parts, treat it as an attachment/host pipeline issue-not users forgetting the image.
|
|
318
|
+
- Forward image attachments are handled by delegation plumbing when targeting @interpreter-do not describe pixels yourself in place of @interpreter.
|
|
319
|
+
</interpreter_protocol>
|
|
320
|
+
|
|
321
|
+
`;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// --- Librarian ---
|
|
325
|
+
|
|
326
|
+
export const LIBRARIAN_VARIANT_SCOPE_LINES = [
|
|
327
|
+
'low: answer one focused question with minimal but direct citations',
|
|
328
|
+
'medium: synthesize multiple sources and explain one key caveat',
|
|
329
|
+
'high: provide deep multi-source comparison with explicit version ' +
|
|
330
|
+
'matrix and conflict resolution',
|
|
331
|
+
'max: exhaustive cross-source research with full version matrix, ' +
|
|
332
|
+
'competing implementations, and ecosystem-wide context',
|
|
333
|
+
] as const;
|
|
334
|
+
|
|
335
|
+
// --- Interpreter ---
|
|
336
|
+
|
|
337
|
+
export const INTERPRETER_VARIANT_SCOPE_LINES = [
|
|
338
|
+
'low: single image - identify key elements and suggest one routing agent',
|
|
339
|
+
'medium: multi-image or complex diagram - cross-reference visible artifacts ' +
|
|
340
|
+
'and produce a structured routing recommendation',
|
|
341
|
+
'high: detailed technical breakdown of multiple screenshots or diagrams with ' +
|
|
342
|
+
'annotated findings and ordered routing chain',
|
|
343
|
+
] as const;
|
|
344
|
+
|
|
345
|
+
// --- Steward ---
|
|
346
|
+
|
|
347
|
+
export const STEWARD_VARIANT_SCOPE_LINES = [
|
|
348
|
+
'low: read and cite AGENTS.md / AGENT.md only; stop after root anchor files',
|
|
349
|
+
'medium: root anchor files plus remaining steward_paths in priority order ' +
|
|
350
|
+
'(up to ~6 whole-file reads)',
|
|
351
|
+
'high: read and cite all steward_paths including .cursor/rules, ' +
|
|
352
|
+
'.opencode, .docs, and any secondary convention shards — cite verbatim only, do not analyze',
|
|
353
|
+
] as const;
|
|
354
|
+
|
|
355
|
+
export const STEWARD_VARIANT_MAX_NOTE =
|
|
356
|
+
'not supported — steward is citation-only; deep analysis belongs to @oracle';
|
|
357
|
+
|
|
358
|
+
// --- Designer ---
|
|
359
|
+
|
|
360
|
+
export const DESIGNER_VARIANT_SCOPE_LINES = [
|
|
361
|
+
'low: focused tweaks and small style corrections',
|
|
362
|
+
'medium: full-page redesign or new section layout',
|
|
363
|
+
'high: multi-page system-level UI patterns',
|
|
364
|
+
'max: design-system-wide audit, cross-page consistency, and ' +
|
|
365
|
+
'comprehensive accessibility validation',
|
|
366
|
+
] as const;
|
|
367
|
+
|
|
368
|
+
// --- Explorer ---
|
|
369
|
+
|
|
370
|
+
export const EXPLORER_VARIANT_SCOPE_LINES = [
|
|
371
|
+
'low: locate one file/pattern in a known directory; single-concept search',
|
|
372
|
+
'medium: multi-directory cross-reference; find all callers/usages of a symbol',
|
|
373
|
+
'high: exhaustive codebase-wide usage analysis across all directories; ' +
|
|
374
|
+
'comprehensive dependency mapping (round cap does not apply; state coverage upfront)',
|
|
375
|
+
'max: not supported - explorer is a search and location agent; ' +
|
|
376
|
+
'use @oracle for deep analysis of discovered results',
|
|
377
|
+
] as const;
|
|
378
|
+
|
|
379
|
+
// --- Fixer ---
|
|
380
|
+
|
|
381
|
+
/** Orchestrator `<constraints>` line for @fixer variant caps. */
|
|
382
|
+
export const FIXER_ORCHESTRATOR_DELEGATION_VARIANT_RULE =
|
|
383
|
+
'- ONLY use low or medium variant when delegating to @fixer. For high/max ' +
|
|
384
|
+
'scope, split into multiple low/medium @fixer sessions.';
|
|
385
|
+
|
|
386
|
+
/** Specialist variant_policy cap line (orchestrator must not send high/max). */
|
|
387
|
+
export const FIXER_VARIANT_POLICY_CAP_LINE =
|
|
388
|
+
'- high/max: NOT supported - the orchestrator constrains fixer to low/medium. ' +
|
|
389
|
+
'If high/max scope is needed, split into multiple low/medium fixer sessions.';
|
|
390
|
+
|
|
391
|
+
export const FIXER_VARIANT_SCOPE_LINES = [
|
|
392
|
+
'low: single-file, single-function edit; bounded scope change',
|
|
393
|
+
'medium: multi-file change within one module; small refactor across 2-3 files',
|
|
394
|
+
] as const;
|
|
395
|
+
|
|
396
|
+
// --- Oracle ---
|
|
397
|
+
|
|
398
|
+
export const ORACLE_VARIANT_OMITTED_DEFAULT_RULE =
|
|
399
|
+
'- If variant is omitted by the caller, default to medium.';
|
|
400
|
+
|
|
401
|
+
/** Depth labels: shared between orchestrator routing and oracle specialist. */
|
|
402
|
+
export const ORACLE_VARIANT_DEPTH_LINES = [
|
|
403
|
+
'low: minimal rationale - smart model only (narrow follow-up once ' +
|
|
404
|
+
'smart is warranted)',
|
|
405
|
+
'medium: bounded analysis; 1-3 files; clear problem statement (minimum ' +
|
|
406
|
+
'depth for default/flash)',
|
|
407
|
+
'high: multi-file, moderate ambiguity, or flash+medium was incomplete',
|
|
408
|
+
'max: security-critical, data-integrity, systemic risk, or last resort ' +
|
|
409
|
+
'before giving up',
|
|
410
|
+
] as const;
|
|
411
|
+
|
|
412
|
+
export const ORACLE_SELF_AWARENESS_NOTE =
|
|
413
|
+
'- If you receive `variant: low` and your session model is a standard/flash ' +
|
|
414
|
+
'tier (not the smart/pro tier configured by the orchestrator), the depth may ' +
|
|
415
|
+
'be insufficient. Proceed at minimal depth and note the limitation in ' +
|
|
416
|
+
'`<confidence>` rather than refusing or stalling. If you infer you are the ' +
|
|
417
|
+
'smart tier but your capabilities feel limited for the task, surface that ' +
|
|
418
|
+
'discrepancy in `<confidence>` as well.';
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Model-tier context block injected into oracle\'s own prompt.
|
|
422
|
+
* Explains when each tier is used so oracle can calibrate confidence and depth.
|
|
423
|
+
*/
|
|
424
|
+
export const ORACLE_MODEL_TIER_BLOCK = `<model_tier>
|
|
425
|
+
The orchestrator operates two oracle tiers and selects one before delegating:
|
|
426
|
+
- default (flash): standard debugging, scoped reviews, bounded analysis, no security impact - expects variant medium-max.
|
|
427
|
+
- smart (pro): novel architecture, unclear root cause, cross-framework subtlety, security/concurrency risk, or escalation after a flash attempt was wrong or low-confidence - supports variant low-max.
|
|
428
|
+
|
|
429
|
+
Deciding factors the orchestrator uses to pick the tier:
|
|
430
|
+
1. Security or data-integrity risk → always smart.
|
|
431
|
+
2. Novel/unclear root cause, concurrency, cross-framework subtlety → smart.
|
|
432
|
+
3. Prior flash result was wrong or explicitly low-confidence → escalate to smart.
|
|
433
|
+
4. Standard scoped debugging or review with no ambiguity → default.
|
|
434
|
+
|
|
435
|
+
You cannot observe your own model name. Infer your likely tier from the variant received:
|
|
436
|
+
- variant low → you are almost certainly the smart tier (flash + low is a misconfiguration).
|
|
437
|
+
- variant max → high-stakes task; calibrate for security/systemic risk regardless of tier.
|
|
438
|
+
- variant medium/high on a focused task → likely default tier; proceed at appropriate depth.
|
|
439
|
+
</model_tier>`;
|
|
440
|
+
|
|
441
|
+
export function formatOracleAgentVariantPolicyXml(): string {
|
|
442
|
+
const depth = ORACLE_VARIANT_DEPTH_LINES.map((l) => `- ${l}`).join('\n');
|
|
443
|
+
return `<variant_policy>
|
|
444
|
+
${ORACLE_VARIANT_OMITTED_DEFAULT_RULE}
|
|
445
|
+
${depth}
|
|
446
|
+
${ORACLE_SELF_AWARENESS_NOTE}
|
|
447
|
+
|
|
448
|
+
Variant output:
|
|
449
|
+
- low: keep <tradeoffs>, <risks>, and <confidence> concise.
|
|
450
|
+
- medium: keep all sections but limit alternatives to one; omit placeholder bullets-skip a subsection entirely if it would add no real content.
|
|
451
|
+
- high/max: all sections must be detailed and risk-oriented, with clear severity labels for risks.
|
|
452
|
+
</variant_policy>`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export function formatOrchestratorOracleVariantDepthSection(): string {
|
|
456
|
+
const lines = ORACLE_VARIANT_DEPTH_LINES.map((l) => `- ${l}`).join('\n');
|
|
457
|
+
return `VARIANT (depth):\n${lines}`;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function buildVariantGlossaryBlock(): string {
|
|
461
|
+
return `<variant_glossary>
|
|
462
|
+
**Oracle variants:**
|
|
463
|
+
- low: minimal rationale (smart model only)
|
|
464
|
+
- medium: bounded analysis (1-3 files)
|
|
465
|
+
- high: multi-file or moderate ambiguity
|
|
466
|
+
- max: security-critical or systemic risk
|
|
467
|
+
|
|
468
|
+
**Fixer variants:**
|
|
469
|
+
- low: single-file, single-function edit
|
|
470
|
+
- medium: multi-file change within one module
|
|
471
|
+
|
|
472
|
+
**Note:** For @fixer work exceeding medium scope, split into multiple low/medium sessions.
|
|
473
|
+
</variant_glossary>`;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Consolidated variant guide table for the orchestrator prompt.
|
|
478
|
+
* Replaces 6 separate variant guide sections with a single table.
|
|
479
|
+
* Includes shorter labels with detailed glossary below.
|
|
480
|
+
*/
|
|
481
|
+
export function buildConsolidatedVariantGuide(): string {
|
|
482
|
+
return `<variant_guide>
|
|
483
|
+
| Agent | low | medium | high | max |
|
|
484
|
+
|-------|-----|--------|------|-----|
|
|
485
|
+
| @explorer | low: locate | medium: cross-ref | high: exhaustive | not supported |
|
|
486
|
+
| @librarian | low: focused | medium: synthesize | high: deep comparison | max: exhaustive |
|
|
487
|
+
| @oracle | low: minimal rationale | medium: bounded | high: comprehensive | max: critical risk |
|
|
488
|
+
| @designer | low: tweaks | medium: redesign | high: multi-page | max: audit |
|
|
489
|
+
| @fixer | low: single-file | medium: multi-file | not supported | not supported |
|
|
490
|
+
| @steward | low: anchor files | medium: steward paths | high: all paths | ${STEWARD_VARIANT_MAX_NOTE} |
|
|
491
|
+
| @interpreter | low: single image | medium: multi-image | high: breakdown | not supported |
|
|
492
|
+
</variant_guide>
|
|
493
|
+
|
|
494
|
+
For @fixer work exceeding medium scope, split into multiple low/medium sessions.
|
|
495
|
+
|
|
496
|
+
${buildVariantGlossaryBlock()}`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Build XML block with guidance on when and how to use the
|
|
501
|
+
* `discover_mcp_servers` and `discover_skills_online` tools.
|
|
502
|
+
*
|
|
503
|
+
* MCP servers are capability/tool resources that provide new functions.
|
|
504
|
+
* Skills are knowledge/prompt resources that provide specialized workflows.
|
|
505
|
+
* Never conflate the two.
|
|
506
|
+
*
|
|
507
|
+
* The orchestrator calls these tools when a subagent outputs `<blocked>` due to
|
|
508
|
+
* missing capabilities, or when the user explicitly asks for tool/skill
|
|
509
|
+
* recommendations. Returns recommendations that the orchestrator presents to
|
|
510
|
+
* the user.
|
|
511
|
+
*/
|
|
512
|
+
export function buildDiscoveryGuidanceBlock(): string {
|
|
513
|
+
return `<discovery_guidance>
|
|
514
|
+
When a subagent returns <blocked> because it lacks the capabilities to complete
|
|
515
|
+
a task, you have two recovery options:
|
|
516
|
+
1. Work around the missing capability (use a different tool or approach)
|
|
517
|
+
2. Discover and recommend installable MCP servers or skills that provide the
|
|
518
|
+
needed capability via the discovery tools
|
|
519
|
+
|
|
520
|
+
IMPORTANT SCOPE: Discovery tools are ONLY for AGENT capabilities and
|
|
521
|
+
knowledge — NOT for project dependencies.
|
|
522
|
+
- MCP servers = agent capabilities (tools the AI can call to do things)
|
|
523
|
+
- Skills = agent knowledge (prompt instructions that teach workflows)
|
|
524
|
+
- Project dependencies = what your code imports or references at
|
|
525
|
+
runtime (language libraries, framework packages, runtime deps) — NOT
|
|
526
|
+
for discovery tools
|
|
527
|
+
|
|
528
|
+
<tool_selection>
|
|
529
|
+
- Use \`discover_mcp_servers\` when you need tool/capability resources
|
|
530
|
+
(external service automation, data source access, API integrations,
|
|
531
|
+
file system operations, etc.)
|
|
532
|
+
- Use \`discover_skills_online\` when you need knowledge/prompt resources
|
|
533
|
+
(specialized workflows, domain expertise, task-specific guidance, etc.)
|
|
534
|
+
</tool_selection>
|
|
535
|
+
|
|
536
|
+
Call \`discover_mcp_servers\` when:
|
|
537
|
+
- A subagent reports missing capabilities via <blocked> (e.g. "browser
|
|
538
|
+
automation unavailable", "database MCP not configured")
|
|
539
|
+
- The user explicitly asks for an MCP server or tool recommendation
|
|
540
|
+
- You need to find external tool resources for a specific domain
|
|
541
|
+
|
|
542
|
+
Call \`discover_skills_online\` when:
|
|
543
|
+
- The user explicitly asks for a skill recommendation
|
|
544
|
+
- You need task-specific knowledge, prompts, or workflows
|
|
545
|
+
- A subagent needs specialized guidance for a particular domain
|
|
546
|
+
|
|
547
|
+
<correct_vs_incorrect>
|
|
548
|
+
✅ DO call discovery tools for:
|
|
549
|
+
- External service automation MCP (API integrations, app automation)
|
|
550
|
+
- Data source connector MCP (databases, storage, data platforms)
|
|
551
|
+
- Platform API MCP (GitHub, GitLab, cloud services)
|
|
552
|
+
- Design tool MCP (design asset access, visual workflows)
|
|
553
|
+
- Web search / documentation MCP
|
|
554
|
+
- Domain knowledge skill (best practices, specialized workflows)
|
|
555
|
+
|
|
556
|
+
❌ DON'T call discovery tools for:
|
|
557
|
+
- Language libraries (charting, UI frameworks, utilities — project
|
|
558
|
+
dependencies)
|
|
559
|
+
- Framework packages (runtimes, SDKs, build tools — project
|
|
560
|
+
dependencies)
|
|
561
|
+
- Runtime dependencies (database drivers, HTTP clients, package
|
|
562
|
+
managers — project dependencies)
|
|
563
|
+
- Any package used in \`import\` or \`require\` statements
|
|
564
|
+
|
|
565
|
+
Project dependencies are installed by @fixer during implementation
|
|
566
|
+
using the project's package manager (npm, pip, nuget, cargo, etc.).
|
|
567
|
+
Discovery tools find AGENT capabilities, not PROJECT dependencies.
|
|
568
|
+
</correct_vs_incorrect>
|
|
569
|
+
|
|
570
|
+
Both tools return a JSON array of recommendations with relevance scores,
|
|
571
|
+
install commands, and suggested agents. Present the top 1-3 recommendations
|
|
572
|
+
to the user and ask if they would like to install any.
|
|
573
|
+
|
|
574
|
+
<auto_filtering>
|
|
575
|
+
Both tools automatically filter out already-installed MCPs/skills
|
|
576
|
+
from recommendations. If the user already has a matching MCP or skill
|
|
577
|
+
installed, it will only appear in the output when its relevance_score
|
|
578
|
+
is > 0.8 (significantly better for the current task), and it will be
|
|
579
|
+
marked with 'already_installed: true' so you know the user already has it.
|
|
580
|
+
Otherwise, already-installed items are silently excluded to avoid
|
|
581
|
+
recommending something the user already has.
|
|
582
|
+
|
|
583
|
+
When calling either tool, pass the 'existing_mcp_names' or
|
|
584
|
+
'existing_skill_names' parameter with the list of installed names
|
|
585
|
+
obtained via getLocalDiscovery() to enable this filtering.
|
|
586
|
+
</auto_filtering>
|
|
587
|
+
|
|
588
|
+
<scope_clarification>
|
|
589
|
+
- MCP servers/Skills = AGENT tooling (what AI can do/know)
|
|
590
|
+
- Project dependencies = what your code imports (language libraries,
|
|
591
|
+
framework packages, runtime dependencies)
|
|
592
|
+
|
|
593
|
+
@fixer installs project dependencies during implementation verification.
|
|
594
|
+
Discovery tools find AGENT capabilities, not PROJECT dependencies.
|
|
595
|
+
|
|
596
|
+
Project dependencies (e.g., language libraries, framework packages,
|
|
597
|
+
runtime deps) are installed by @fixer during implementation using the
|
|
598
|
+
project's package manager. Discovery tools are for finding MCP servers
|
|
599
|
+
(agent capabilities) and Skills (agent knowledge) — NOT project
|
|
600
|
+
dependencies.
|
|
601
|
+
</scope_clarification>
|
|
602
|
+
|
|
603
|
+
<heuristics_table>
|
|
604
|
+
| Task signal detected in <blocked> | Tool to use | Likely recommendation(s) |
|
|
605
|
+
|--------------------------------------------------|----------------------|---------------------------------------------------|
|
|
606
|
+
| External service automation, API integration | discover_mcp_servers | Automation/connector MCPs |
|
|
607
|
+
| Data source access, storage queries | discover_mcp_servers | Data source connector MCPs |
|
|
608
|
+
| Repository operations, PR/issue management | discover_mcp_servers | Platform API MCPs |
|
|
609
|
+
| File system operations, file read/write | discover_mcp_servers | Filesystem MCP |
|
|
610
|
+
| Web search, internet research, API docs | discover_mcp_servers | Web search / documentation MCPs |
|
|
611
|
+
| Code search, grep-like operations | discover_mcp_servers | Code search MCPs |
|
|
612
|
+
| Communication (messaging platforms) | discover_mcp_servers | Messaging platform MCPs |
|
|
613
|
+
| Project management (issue tracking, boards) | discover_mcp_servers | Project management MCPs |
|
|
614
|
+
| Design tools, visual asset management | discover_mcp_servers | Design tool MCPs |
|
|
615
|
+
| Error monitoring, crash reporting | discover_mcp_servers | Observability MCPs |
|
|
616
|
+
| Payments, billing, subscriptions | discover_mcp_servers | Payment platform MCPs |
|
|
617
|
+
| Documentation, knowledge base, wiki | discover_mcp_servers | Knowledge base MCPs |
|
|
618
|
+
| Domain-specific knowledge, best practices | discover_skills_online | Specialized workflow/domain knowledge skills |
|
|
619
|
+
| Specialized workflows for a particular task | discover_skills_online | Task-specific workflow skills |
|
|
620
|
+
| Package/import resolution, dependency install | ⚠️ NOT for discovery | @fixer via project package manager |
|
|
621
|
+
</heuristics_table>
|
|
622
|
+
|
|
623
|
+
<example>
|
|
624
|
+
Subagent returns: \`<blocked>\`External API access needed - I need to
|
|
625
|
+
interact with a third-party service but no connector is available.
|
|
626
|
+
<suggested_agent>explorer</suggested_agent>
|
|
627
|
+
\`</blocked>\`
|
|
628
|
+
|
|
629
|
+
Orchestrator action:
|
|
630
|
+
1. Call \`discover_mcp_servers(task_description: "External API integration
|
|
631
|
+
for third-party service access", task_keywords: ["api", "integration",
|
|
632
|
+
"connector", "service"], agent_name: "explorer")\`
|
|
633
|
+
2. Get recommendations including a service connector MCP
|
|
634
|
+
3. Present to user: "To enable external API access, you can install a
|
|
635
|
+
service connector MCP server. Would you like me to search for
|
|
636
|
+
available options?"
|
|
637
|
+
</example>
|
|
638
|
+
|
|
639
|
+
`;
|
|
640
|
+
}
|