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,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase reminder to append after each latest user message.
|
|
3
|
+
*
|
|
4
|
+
* Keeping this at the tail preserves immediate workflow guidance without
|
|
5
|
+
* mutating the cached system prompt or prepending request-local content ahead
|
|
6
|
+
* of the user's actual turn.
|
|
7
|
+
*/
|
|
8
|
+
import { PHASE_REMINDER_TEXT } from '../../config/constants';
|
|
9
|
+
import { SLIM_INTERNAL_INITIATOR_MARKER } from '../../utils';
|
|
10
|
+
|
|
11
|
+
export const PHASE_REMINDER = `<internal_reminder>${PHASE_REMINDER_TEXT}</internal_reminder>`;
|
|
12
|
+
|
|
13
|
+
interface MessageInfo {
|
|
14
|
+
role: string;
|
|
15
|
+
agent?: string;
|
|
16
|
+
sessionID?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface MessagePart {
|
|
20
|
+
type: string;
|
|
21
|
+
text?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface MessageWithParts {
|
|
26
|
+
info: MessageInfo;
|
|
27
|
+
parts: MessagePart[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates the experimental.chat.messages.transform hook for phase reminder injection.
|
|
32
|
+
* This hook runs right before sending to API, so it doesn't affect UI display.
|
|
33
|
+
* Only injects for the orchestrator agent.
|
|
34
|
+
*/
|
|
35
|
+
export function createPhaseReminderHook() {
|
|
36
|
+
return {
|
|
37
|
+
'experimental.chat.messages.transform': async (
|
|
38
|
+
_input: Record<string, never>,
|
|
39
|
+
output: { messages: MessageWithParts[] },
|
|
40
|
+
): Promise<void> => {
|
|
41
|
+
const { messages } = output;
|
|
42
|
+
|
|
43
|
+
if (messages.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let lastUserMessageIndex = -1;
|
|
48
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
49
|
+
if (messages[i].info.role === 'user') {
|
|
50
|
+
lastUserMessageIndex = i;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (lastUserMessageIndex === -1) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const lastUserMessage = messages[lastUserMessageIndex];
|
|
60
|
+
const agent = lastUserMessage.info.agent;
|
|
61
|
+
if (agent && agent !== 'orchestrator') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const textPartIndex = lastUserMessage.parts.findIndex(
|
|
66
|
+
(p) => p.type === 'text' && p.text !== undefined,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (textPartIndex === -1) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const originalText = lastUserMessage.parts[textPartIndex].text ?? '';
|
|
74
|
+
if (originalText.includes(SLIM_INTERNAL_INITIATOR_MARKER)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (originalText.includes(PHASE_REMINDER)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
lastUserMessage.parts[textPartIndex].text =
|
|
82
|
+
`${originalText}\n\n---\n\n${PHASE_REMINDER}`;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { PHASE_REMINDER_TEXT } from '../../config/constants';
|
|
4
|
+
import { createPostFileToolNudgeHook } from './index';
|
|
5
|
+
|
|
6
|
+
function createOutput(output = 'real content') {
|
|
7
|
+
return {
|
|
8
|
+
title: 'Read',
|
|
9
|
+
output,
|
|
10
|
+
metadata: {},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function countReminderInOutput(output: string | unknown): number {
|
|
15
|
+
if (typeof output !== 'string') return 0;
|
|
16
|
+
return output.split(PHASE_REMINDER_TEXT).length - 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('post-file-tool-nudge hook', () => {
|
|
20
|
+
test('appends delegation reminder to tool output', async () => {
|
|
21
|
+
const hook = createPostFileToolNudgeHook();
|
|
22
|
+
const output = createOutput();
|
|
23
|
+
|
|
24
|
+
await hook['tool.execute.after']({ tool: 'Read', sessionID: 's1' }, output);
|
|
25
|
+
|
|
26
|
+
expect(output.output).toContain(PHASE_REMINDER_TEXT);
|
|
27
|
+
expect(output.output).toContain('<internal_reminder>');
|
|
28
|
+
expect(output.output).toContain('</internal_reminder>');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('does not duplicate reminder in same tool output', async () => {
|
|
32
|
+
const hook = createPostFileToolNudgeHook();
|
|
33
|
+
const output = createOutput();
|
|
34
|
+
|
|
35
|
+
await hook['tool.execute.after']({ tool: 'read', sessionID: 's1' }, output);
|
|
36
|
+
await hook['tool.execute.after']({ tool: 'read', sessionID: 's1' }, output);
|
|
37
|
+
|
|
38
|
+
expect(countReminderInOutput(output.output)).toBe(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('deduplicates multiple Read/Write calls in same session', async () => {
|
|
42
|
+
const hook = createPostFileToolNudgeHook();
|
|
43
|
+
const output1 = createOutput('content 1');
|
|
44
|
+
const output2 = createOutput('content 2');
|
|
45
|
+
const output3 = createOutput('content 3');
|
|
46
|
+
|
|
47
|
+
await hook['tool.execute.after'](
|
|
48
|
+
{ tool: 'read', sessionID: 's1' },
|
|
49
|
+
output1,
|
|
50
|
+
);
|
|
51
|
+
await hook['tool.execute.after'](
|
|
52
|
+
{ tool: 'write', sessionID: 's1' },
|
|
53
|
+
output2,
|
|
54
|
+
);
|
|
55
|
+
await hook['tool.execute.after'](
|
|
56
|
+
{ tool: 'Read', sessionID: 's1' },
|
|
57
|
+
output3,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(output1.output).toContain(PHASE_REMINDER_TEXT);
|
|
61
|
+
expect(output2.output).toContain(PHASE_REMINDER_TEXT);
|
|
62
|
+
expect(output3.output).toContain(PHASE_REMINDER_TEXT);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('ignores non-file tools', async () => {
|
|
66
|
+
const hook = createPostFileToolNudgeHook();
|
|
67
|
+
const output = createOutput('ok');
|
|
68
|
+
|
|
69
|
+
await hook['tool.execute.after']({ tool: 'bash', sessionID: 's1' }, output);
|
|
70
|
+
|
|
71
|
+
expect(output.output).toBe('ok');
|
|
72
|
+
expect(output.output).not.toContain(PHASE_REMINDER_TEXT);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('skips injection when shouldInject returns false', async () => {
|
|
76
|
+
const hook = createPostFileToolNudgeHook({ shouldInject: () => false });
|
|
77
|
+
const output = createOutput();
|
|
78
|
+
|
|
79
|
+
await hook['tool.execute.after']({ tool: 'read', sessionID: 's1' }, output);
|
|
80
|
+
|
|
81
|
+
expect(output.output).toBe('real content');
|
|
82
|
+
expect(output.output).not.toContain(PHASE_REMINDER_TEXT);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('ignores Read/Write without sessionID', async () => {
|
|
86
|
+
const hook = createPostFileToolNudgeHook();
|
|
87
|
+
const output = createOutput();
|
|
88
|
+
|
|
89
|
+
await hook['tool.execute.after']({ tool: 'read' }, output);
|
|
90
|
+
|
|
91
|
+
expect(output.output).toBe('real content');
|
|
92
|
+
expect(output.output).not.toContain(PHASE_REMINDER_TEXT);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-tool nudge - queues a delegation reminder after file reads/writes.
|
|
3
|
+
* Catches the "inspect/edit files → implement myself" anti-pattern.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { PHASE_REMINDER_TEXT } from '../../config/constants';
|
|
7
|
+
|
|
8
|
+
const POST_FILE_TOOL_NUDGE = PHASE_REMINDER_TEXT;
|
|
9
|
+
|
|
10
|
+
interface ToolExecuteAfterInput {
|
|
11
|
+
tool: string;
|
|
12
|
+
sessionID?: string;
|
|
13
|
+
callID?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ToolExecuteAfterOutput {
|
|
17
|
+
output?: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PostFileToolNudgeOptions {
|
|
21
|
+
shouldInject?: (sessionID: string) => boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const FILE_TOOLS = new Set(['Read', 'read', 'Write', 'write']);
|
|
25
|
+
|
|
26
|
+
export function createPostFileToolNudgeHook(
|
|
27
|
+
options: PostFileToolNudgeOptions = {},
|
|
28
|
+
) {
|
|
29
|
+
function appendReminder(output: ToolExecuteAfterOutput): void {
|
|
30
|
+
if (typeof output.output !== 'string') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (output.output.includes(POST_FILE_TOOL_NUDGE)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
output.output = [
|
|
39
|
+
output.output,
|
|
40
|
+
'',
|
|
41
|
+
'<internal_reminder>',
|
|
42
|
+
POST_FILE_TOOL_NUDGE,
|
|
43
|
+
'</internal_reminder>',
|
|
44
|
+
].join('\n');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
'tool.execute.after': async (
|
|
49
|
+
input: ToolExecuteAfterInput,
|
|
50
|
+
output: ToolExecuteAfterOutput,
|
|
51
|
+
): Promise<void> => {
|
|
52
|
+
if (!FILE_TOOLS.has(input.tool) || !input.sessionID) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (options.shouldInject && !options.shouldInject(input.sessionID)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
appendReminder(output);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|