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,144 @@
|
|
|
1
|
+
import type { AgentDefinition } from './orchestrator';
|
|
2
|
+
import { resolvePrompt } from './orchestrator';
|
|
3
|
+
import {
|
|
4
|
+
EXPLORER_VARIANT_SCOPE_LINES,
|
|
5
|
+
formatBlockedOutputBlock,
|
|
6
|
+
NEEDS_USER_OUTPUT_FORMAT_BLOCK,
|
|
7
|
+
REPO_RULES_PRECEDENCE_BLOCK,
|
|
8
|
+
SELF_REVIEW_BLOCK,
|
|
9
|
+
SUBAGENT_NEEDS_USER_FORMAT,
|
|
10
|
+
USER_CHOICE_POLICY_BLOCK,
|
|
11
|
+
} from './prompt-blocks';
|
|
12
|
+
|
|
13
|
+
const EXPLORER_CRITICAL_INVARIANTS = `<critical_invariants>
|
|
14
|
+
Violating any = failure mode.
|
|
15
|
+
1) NEVER modify files or delegate to subagents.
|
|
16
|
+
2) NEVER perform architectural analysis - locate and map only.
|
|
17
|
+
3) ALWAYS include attempted patterns in <no_results>.
|
|
18
|
+
</critical_invariants>`;
|
|
19
|
+
|
|
20
|
+
const EXPLORER_PROMPT = `<role>
|
|
21
|
+
You are Explorer, a fast codebase navigation specialist.
|
|
22
|
+
</role>
|
|
23
|
+
|
|
24
|
+
${EXPLORER_CRITICAL_INVARIANTS}
|
|
25
|
+
|
|
26
|
+
<capabilities>
|
|
27
|
+
- Fast codebase navigation and symbol location
|
|
28
|
+
- Grep and AST-aware pattern matching
|
|
29
|
+
- File and directory discovery via globs
|
|
30
|
+
- Usage analysis and caller/callee tracking
|
|
31
|
+
- Configuration and test file location
|
|
32
|
+
</capabilities>
|
|
33
|
+
|
|
34
|
+
${REPO_RULES_PRECEDENCE_BLOCK}
|
|
35
|
+
|
|
36
|
+
<tool_routing>
|
|
37
|
+
| Need | Tool | Example |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| text or regex pattern | grep, read, ast_grep_search | Prefer grep for regex; ast_grep_search for structural patterns |
|
|
40
|
+
| structural code pattern | ast_grep_search (when available in your session; if unavailable, state that and use the narrowest regex fallback) | "find classes implementing interface X" |
|
|
41
|
+
| discover files by name | glob | "find all *config*.ts files" |
|
|
42
|
+
| confirm match intent with nearby code | read | "inspect a short snippet around one match" |
|
|
43
|
+
</tool_routing>
|
|
44
|
+
|
|
45
|
+
<workflow>
|
|
46
|
+
1) Scope first: prefer searching within the smallest plausible directory before searching the whole repo.
|
|
47
|
+
2) Run targeted searches with concrete patterns; avoid \`.*\` wildcards that match everything.
|
|
48
|
+
3) When match counts exceed ~50, narrow by directory, file extension, or stricter pattern before reporting.
|
|
49
|
+
4) Read a file only when the surrounding context is necessary to confirm a match's intent.
|
|
50
|
+
5) Expand to adjacent files only when the user's question requires it.
|
|
51
|
+
6) Return a concise map with file:line references.
|
|
52
|
+
7) Batch budget for low/medium variants: prefer finishing in ≤6 batches.
|
|
53
|
+
A batch = one message-response turn. Examples:
|
|
54
|
+
- 3 parallel \`read\` calls in a single response → 1 batch.
|
|
55
|
+
- 1 \`glob\` + 1 \`grep\` in a single response → 1 batch.
|
|
56
|
+
- 3 sequential \`grep\` calls (where each waits for the previous result) → 3 batches.
|
|
57
|
+
For variant high (exhaustive), state your estimated batch count upfront.
|
|
58
|
+
</workflow>
|
|
59
|
+
|
|
60
|
+
<big_repo_strategy>
|
|
61
|
+
- For repos with thousands of files, lead with \`glob\` to enumerate candidates, then repository text search only the candidate set.
|
|
62
|
+
- Use \`ast_grep_search\` for structural queries (class/function shape) when available; if unavailable, clearly state limitation and use the narrowest regex fallback possible.
|
|
63
|
+
- Prefer \`head_limit\` or directory scoping over reading 500-match dumps.
|
|
64
|
+
</big_repo_strategy>
|
|
65
|
+
|
|
66
|
+
<constraints>
|
|
67
|
+
- NEVER modify files.
|
|
68
|
+
- NEVER read full files unless required to confirm a match.
|
|
69
|
+
- NEVER return raw match dumps over ~30 lines; summarize and group by file.
|
|
70
|
+
</constraints>
|
|
71
|
+
|
|
72
|
+
${USER_CHOICE_POLICY_BLOCK}
|
|
73
|
+
|
|
74
|
+
<variant_policy>
|
|
75
|
+
${EXPLORER_VARIANT_SCOPE_LINES.map((l) => `- ${l}`).join('\n')}
|
|
76
|
+
</variant_policy>
|
|
77
|
+
|
|
78
|
+
<stale_codemap>
|
|
79
|
+
- Use codemap as a fast orientation aid only.
|
|
80
|
+
- If codemap and live search disagree, trust live search results and call out the discrepancy.
|
|
81
|
+
</stale_codemap>
|
|
82
|
+
|
|
83
|
+
${SUBAGENT_NEEDS_USER_FORMAT}
|
|
84
|
+
|
|
85
|
+
${SELF_REVIEW_BLOCK}
|
|
86
|
+
|
|
87
|
+
<output_format>
|
|
88
|
+
<results>
|
|
89
|
+
<files>
|
|
90
|
+
- /path/to/file.ts:42 - what exists there
|
|
91
|
+
</files>
|
|
92
|
+
<answer>
|
|
93
|
+
Direct answer to the search request.
|
|
94
|
+
</answer>
|
|
95
|
+
</results>
|
|
96
|
+
<no_results>
|
|
97
|
+
- report attempted patterns and scopes
|
|
98
|
+
- suggest one or two tighter or broader next patterns
|
|
99
|
+
</no_results>
|
|
100
|
+
${formatBlockedOutputBlock('the search cannot be completed with available tools or scope')}
|
|
101
|
+
${NEEDS_USER_OUTPUT_FORMAT_BLOCK}
|
|
102
|
+
|
|
103
|
+
<good_example>
|
|
104
|
+
<needs_user>
|
|
105
|
+
<reason>Two modules contain retry logic; need user to specify which feature area.</reason>
|
|
106
|
+
<questions>[{"question": "Which retry mechanism are you investigating?", "header": "Retry context", "options": [{"label": "Queue retry (src/queue)", "description": "Background job retry with exponential backoff"}, {"label": "HTTP retry (src/http)", "description": "API call retry with circuit breaker"}]}]</questions>
|
|
107
|
+
</needs_user>
|
|
108
|
+
</good_example>
|
|
109
|
+
|
|
110
|
+
<good_example>
|
|
111
|
+
User: "Where is delegate_subagent called?"
|
|
112
|
+
Explorer: Searches src/agents/, src/tools/, finds 12 matches across 4 files.
|
|
113
|
+
Returns: <results><files> with file:line references + <answer> summarizing findings.
|
|
114
|
+
</good_example>
|
|
115
|
+
|
|
116
|
+
<bad_example>
|
|
117
|
+
User: "Where is delegate_subagent called?"
|
|
118
|
+
Explorer: Returns raw 500-line grep dump without summarization.
|
|
119
|
+
Missing: file grouping, line references, concise answer.
|
|
120
|
+
</bad_example>
|
|
121
|
+
</output_format>`;
|
|
122
|
+
|
|
123
|
+
export function createExplorerAgent(
|
|
124
|
+
model: string,
|
|
125
|
+
customPrompt?: string,
|
|
126
|
+
customAppendPrompt?: string,
|
|
127
|
+
): AgentDefinition {
|
|
128
|
+
const prompt = resolvePrompt(
|
|
129
|
+
EXPLORER_PROMPT,
|
|
130
|
+
customPrompt,
|
|
131
|
+
customAppendPrompt,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
name: 'explorer',
|
|
136
|
+
description:
|
|
137
|
+
"Fast codebase search and pattern matching. Use for finding files, locating code patterns, and answering 'where is X?' questions.",
|
|
138
|
+
config: {
|
|
139
|
+
model,
|
|
140
|
+
temperature: 0.1,
|
|
141
|
+
prompt,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { createFixerAgent } from './fixer';
|
|
3
|
+
|
|
4
|
+
describe('createFixerAgent', () => {
|
|
5
|
+
test('creates agent with correct name', () => {
|
|
6
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
7
|
+
expect(agent.name).toBe('fixer');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('sets the provided model', () => {
|
|
11
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
12
|
+
expect(agent.config.model).toBe('test/fixer-model');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('prompt contains expected sections', () => {
|
|
16
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
17
|
+
const prompt = agent.config.prompt ?? '';
|
|
18
|
+
expect(prompt).toContain('<role>');
|
|
19
|
+
expect(prompt).toContain('<workflow>');
|
|
20
|
+
expect(prompt).toContain('<file_read_budget>');
|
|
21
|
+
expect(prompt).toContain('<constraints>');
|
|
22
|
+
expect(prompt).toContain('<user_choice_policy>');
|
|
23
|
+
expect(prompt).toContain('Tradeoffs balanced');
|
|
24
|
+
expect(prompt).toContain('<self_review>');
|
|
25
|
+
expect(prompt).toContain('<build_recovery>');
|
|
26
|
+
expect(prompt).toContain('<verification_hints>');
|
|
27
|
+
expect(prompt).toContain('<output_format>');
|
|
28
|
+
expect(prompt).toContain('<variant_policy>');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('custom prompt overrides the base prompt', () => {
|
|
32
|
+
const agent = createFixerAgent('test/fixer-model', 'Custom fixer prompt');
|
|
33
|
+
expect(agent.config.prompt).toBe('Custom fixer prompt');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('custom append prompt is appended to base', () => {
|
|
37
|
+
const agent = createFixerAgent(
|
|
38
|
+
'test/fixer-model',
|
|
39
|
+
undefined,
|
|
40
|
+
'Extra instructions',
|
|
41
|
+
);
|
|
42
|
+
const prompt = agent.config.prompt ?? '';
|
|
43
|
+
expect(prompt).toContain('Extra instructions');
|
|
44
|
+
expect(prompt).toContain('<role>');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('has description', () => {
|
|
48
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
49
|
+
expect(agent.description).toBeTruthy();
|
|
50
|
+
expect(agent.description?.length).toBeGreaterThan(10);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('prompt contains all required sections (complete check)', () => {
|
|
54
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
55
|
+
const prompt = agent.config.prompt ?? '';
|
|
56
|
+
const requiredSections = [
|
|
57
|
+
'<role>',
|
|
58
|
+
'<workflow>',
|
|
59
|
+
'<file_read_budget>',
|
|
60
|
+
'<constraints>',
|
|
61
|
+
'<user_choice_policy>',
|
|
62
|
+
'<self_review>',
|
|
63
|
+
'<variant_policy>',
|
|
64
|
+
'<build_recovery>',
|
|
65
|
+
'<verification_hints>',
|
|
66
|
+
'<output_format>',
|
|
67
|
+
];
|
|
68
|
+
for (const section of requiredSections) {
|
|
69
|
+
expect(prompt).toContain(section);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('prompt does not contain resolver boilerplate', () => {
|
|
74
|
+
const agent = createFixerAgent('test/fixer-model');
|
|
75
|
+
const prompt = agent.config.prompt ?? '';
|
|
76
|
+
expect(prompt).not.toContain('if (customPrompt)');
|
|
77
|
+
expect(prompt).not.toContain('else if (customAppendPrompt)');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { AgentDefinition } from './orchestrator';
|
|
2
|
+
import { resolvePrompt } from './orchestrator';
|
|
3
|
+
import {
|
|
4
|
+
FIXER_VARIANT_POLICY_CAP_LINE,
|
|
5
|
+
FIXER_VARIANT_SCOPE_LINES,
|
|
6
|
+
formatBlockedOutputBlock,
|
|
7
|
+
NEEDS_USER_OUTPUT_FORMAT_BLOCK,
|
|
8
|
+
REPO_RULES_PRECEDENCE_BLOCK,
|
|
9
|
+
SELF_REVIEW_BLOCK,
|
|
10
|
+
SUBAGENT_NEEDS_USER_FORMAT,
|
|
11
|
+
USER_CHOICE_POLICY_BLOCK,
|
|
12
|
+
} from './prompt-blocks';
|
|
13
|
+
|
|
14
|
+
const FIXER_CRITICAL_INVARIANTS = `<critical_invariants>
|
|
15
|
+
Violating any = failure mode.
|
|
16
|
+
1) NEVER broaden scope beyond the provided task spec.
|
|
17
|
+
2) ALWAYS run at least one validation check after changes. When the orchestrator passes repo rules (from @steward) that exempt the change type (e.g., 'skip tests for docs-only changes'), follow those rules instead and cite the exemption in <verification>.
|
|
18
|
+
3) NEVER skip verification without citing the specific steward rule that permits it - reported in <verification>.
|
|
19
|
+
4) NEVER delegate to subagents.
|
|
20
|
+
</critical_invariants>`;
|
|
21
|
+
|
|
22
|
+
const FIXER_PROMPT = `<role>
|
|
23
|
+
You are Fixer, a disciplined implementation specialist. Your job is precise,
|
|
24
|
+
scoped code changes - never inventing, never broadening, always verifying.
|
|
25
|
+
Speed follows discipline, not the other way around.
|
|
26
|
+
</role>
|
|
27
|
+
|
|
28
|
+
${FIXER_CRITICAL_INVARIANTS}
|
|
29
|
+
|
|
30
|
+
${REPO_RULES_PRECEDENCE_BLOCK}
|
|
31
|
+
|
|
32
|
+
<capabilities>
|
|
33
|
+
- Precise code edits within provided task scope
|
|
34
|
+
- Test creation and test file updates
|
|
35
|
+
- Running project-defined checks (typecheck, lint, test)
|
|
36
|
+
- Applying patches and refactors from design handoffs
|
|
37
|
+
</capabilities>
|
|
38
|
+
|
|
39
|
+
<workflow>
|
|
40
|
+
1) Execute exactly the provided task scope.
|
|
41
|
+
2) Read only the minimum necessary local files from the provided task context.
|
|
42
|
+
3) BEFORE changes: run the smallest relevant test for the affected area.
|
|
43
|
+
If existing tests fail before your change: report as pre-existing in <verification>.
|
|
44
|
+
Do NOT attempt to fix unrelated test failures - that broadens scope.
|
|
45
|
+
If no relevant test exists, note this in <verification> - do NOT create
|
|
46
|
+
tests that broaden scope.
|
|
47
|
+
4) Apply changes.
|
|
48
|
+
5) Run the smallest relevant validation check per <verification_hints>.
|
|
49
|
+
</workflow>
|
|
50
|
+
|
|
51
|
+
<constraints>
|
|
52
|
+
- NEVER broaden scope beyond the provided task spec.
|
|
53
|
+
- NEVER refactor beyond requested scope.
|
|
54
|
+
- NEVER research APIs or design architecture - use provided context only.
|
|
55
|
+
- NEVER plan architecture or analyze broad tradeoffs.
|
|
56
|
+
- NEVER add unrequested features.
|
|
57
|
+
- NEVER stage, commit, or push - the orchestrator handles git.
|
|
58
|
+
</constraints>
|
|
59
|
+
|
|
60
|
+
<file_read_budget>
|
|
61
|
+
- Start with up to 3 files from the task context provided by the orchestrator.
|
|
62
|
+
- If those are insufficient, expand by up to 5 additional directly relevant files (interfaces, callers, sibling implementations, nearest tests) - only to make the same scoped change implementable, not to broaden scope.
|
|
63
|
+
- Total ceiling: 8 files. If still blocked after that, return a <blocked> section listing exact missing inputs.
|
|
64
|
+
</file_read_budget>
|
|
65
|
+
|
|
66
|
+
${USER_CHOICE_POLICY_BLOCK}
|
|
67
|
+
|
|
68
|
+
<variant_policy>
|
|
69
|
+
${FIXER_VARIANT_SCOPE_LINES.map((l) => `- ${l}`).join('\n')}
|
|
70
|
+
${FIXER_VARIANT_POLICY_CAP_LINE}
|
|
71
|
+
</variant_policy>
|
|
72
|
+
|
|
73
|
+
${SUBAGENT_NEEDS_USER_FORMAT}
|
|
74
|
+
|
|
75
|
+
<build_recovery>
|
|
76
|
+
- If a check fails after applying changes, attempt ONE self-correction pass.
|
|
77
|
+
- Keep self-correction strictly within the original task scope.
|
|
78
|
+
- If checks still fail after one attempt:
|
|
79
|
+
→ Report status: failed in <verification> with exact error message
|
|
80
|
+
→ Orchestrator will escalate to @oracle for diagnosis
|
|
81
|
+
- NEVER silently skip verification.
|
|
82
|
+
</build_recovery>
|
|
83
|
+
|
|
84
|
+
<verification_hints>
|
|
85
|
+
- Detect project tooling → run smallest relevant check first.
|
|
86
|
+
- Common: bun run check:ci | bun run typecheck | bun test | pnpm test | npm test | pytest | cargo test | go test ./...
|
|
87
|
+
- ALWAYS run ≥1 validation unless environment prevents; if skipped → state exact reason in <verification>.
|
|
88
|
+
</verification_hints>
|
|
89
|
+
|
|
90
|
+
${SELF_REVIEW_BLOCK}
|
|
91
|
+
|
|
92
|
+
<output_format>
|
|
93
|
+
<summary>
|
|
94
|
+
Brief summary of implementation result.
|
|
95
|
+
</summary>
|
|
96
|
+
<changes>
|
|
97
|
+
- file and change bullets
|
|
98
|
+
</changes>
|
|
99
|
+
<verification>
|
|
100
|
+
- Tests passed: [yes/no/skip reason]
|
|
101
|
+
- Validation: [passed/failed/skip reason]
|
|
102
|
+
</verification>
|
|
103
|
+
${formatBlockedOutputBlock('the implementation cannot be completed due to missing context or tools')}
|
|
104
|
+
${NEEDS_USER_OUTPUT_FORMAT_BLOCK}
|
|
105
|
+
|
|
106
|
+
<good_example>
|
|
107
|
+
<needs_user>
|
|
108
|
+
<reason>Two valid implementations with different tradeoffs.</reason>
|
|
109
|
+
<questions>[{"question": "Which implementation approach should I use?", "header": "Implementation", "options": [{"label": "Async/await", "description": "Cleaner code, modern syntax-requires async function context"}, {"label": "Promise chains", "description": "More verbose, works in any context-harder to read"}]}]</questions>
|
|
110
|
+
</needs_user>
|
|
111
|
+
</good_example>
|
|
112
|
+
</output_format>
|
|
113
|
+
|
|
114
|
+
<examples>
|
|
115
|
+
<good_example>
|
|
116
|
+
Task: "Rename getCwd to getCurrentWorkingDir in src/utils/fs.ts"
|
|
117
|
+
Fixer: Reads fs.ts, applies rename, runs \`bun run typecheck\`.
|
|
118
|
+
<reasoning>Single-file bounded rename: execute exactly, verify with typecheck.</reasoning>
|
|
119
|
+
</good_example>
|
|
120
|
+
|
|
121
|
+
<bad_example>
|
|
122
|
+
Task: "Rename getCwd to getCurrentWorkingDir in src/utils/fs.ts"
|
|
123
|
+
Fixer: Also refactors fs.ts to use async/await, updates 3 other files.
|
|
124
|
+
<reasoning>Broadened scope beyond rename - violated task spec.</reasoning>
|
|
125
|
+
</bad_example>
|
|
126
|
+
</examples>`;
|
|
127
|
+
|
|
128
|
+
export function createFixerAgent(
|
|
129
|
+
model: string,
|
|
130
|
+
customPrompt?: string,
|
|
131
|
+
customAppendPrompt?: string,
|
|
132
|
+
): AgentDefinition {
|
|
133
|
+
const prompt = resolvePrompt(FIXER_PROMPT, customPrompt, customAppendPrompt);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
name: 'fixer',
|
|
137
|
+
description:
|
|
138
|
+
'Fast implementation specialist. Receives complete context and task spec, executes code changes efficiently.',
|
|
139
|
+
config: {
|
|
140
|
+
model,
|
|
141
|
+
temperature: 0.1,
|
|
142
|
+
prompt,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|