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,117 @@
|
|
|
1
|
+
import { type ToolDefinition, tool } from '@opencode-ai/plugin/tool';
|
|
2
|
+
import { runSg } from './cli';
|
|
3
|
+
import type { CliLanguage } from './types';
|
|
4
|
+
import { CLI_LANGUAGES } from './types';
|
|
5
|
+
import {
|
|
6
|
+
formatReplaceResult,
|
|
7
|
+
formatSearchResult,
|
|
8
|
+
getEmptyResultHint,
|
|
9
|
+
} from './utils';
|
|
10
|
+
|
|
11
|
+
function showOutputToUser(context: unknown, output: string): void {
|
|
12
|
+
const ctx = context as {
|
|
13
|
+
metadata?: (input: { metadata: { output: string } }) => void;
|
|
14
|
+
};
|
|
15
|
+
ctx.metadata?.({ metadata: { output } });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ast_grep_search: ToolDefinition = tool({
|
|
19
|
+
description:
|
|
20
|
+
'Search code patterns across filesystem using AST-aware matching. Supports 25 languages. ' +
|
|
21
|
+
'Use meta-variables: $VAR (single node), $$$ (multiple nodes). ' +
|
|
22
|
+
'IMPORTANT: Patterns must be complete AST nodes (valid code). ' +
|
|
23
|
+
"For functions, include params and body: 'export async function $NAME($$$) { $$$ }' not 'export async function $NAME'. " +
|
|
24
|
+
"Examples: 'console.log($MSG)', 'def $FUNC($$$):', 'async function $NAME($$$)'",
|
|
25
|
+
args: {
|
|
26
|
+
pattern: tool.schema
|
|
27
|
+
.string()
|
|
28
|
+
.describe(
|
|
29
|
+
'AST pattern with meta-variables ($VAR, $$$). Must be complete AST node.',
|
|
30
|
+
),
|
|
31
|
+
lang: tool.schema.enum(CLI_LANGUAGES).describe('Target language'),
|
|
32
|
+
paths: tool.schema
|
|
33
|
+
.array(tool.schema.string())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Paths to search (default: ['.'])"),
|
|
36
|
+
globs: tool.schema
|
|
37
|
+
.array(tool.schema.string())
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Include/exclude globs (prefix ! to exclude)'),
|
|
40
|
+
context: tool.schema
|
|
41
|
+
.number()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Context lines around match'),
|
|
44
|
+
},
|
|
45
|
+
execute: async (args, context) => {
|
|
46
|
+
try {
|
|
47
|
+
const result = await runSg({
|
|
48
|
+
pattern: args.pattern,
|
|
49
|
+
lang: args.lang as CliLanguage,
|
|
50
|
+
paths: args.paths,
|
|
51
|
+
globs: args.globs,
|
|
52
|
+
context: args.context,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
let output = formatSearchResult(result);
|
|
56
|
+
|
|
57
|
+
if (result.matches.length === 0 && !result.error) {
|
|
58
|
+
const hint = getEmptyResultHint(args.pattern, args.lang as CliLanguage);
|
|
59
|
+
if (hint) {
|
|
60
|
+
output += `\n\n${hint}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
showOutputToUser(context, output);
|
|
65
|
+
return output;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const output = `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
68
|
+
showOutputToUser(context, output);
|
|
69
|
+
return output;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const ast_grep_replace: ToolDefinition = tool({
|
|
75
|
+
description:
|
|
76
|
+
'Replace code patterns across filesystem with AST-aware rewriting. ' +
|
|
77
|
+
'Dry-run by default. Use meta-variables in rewrite to preserve matched content. ' +
|
|
78
|
+
"Example: pattern='console.log($MSG)' rewrite='logger.info($MSG)'",
|
|
79
|
+
args: {
|
|
80
|
+
pattern: tool.schema.string().describe('AST pattern to match'),
|
|
81
|
+
rewrite: tool.schema
|
|
82
|
+
.string()
|
|
83
|
+
.describe('Replacement pattern (can use $VAR from pattern)'),
|
|
84
|
+
lang: tool.schema.enum(CLI_LANGUAGES).describe('Target language'),
|
|
85
|
+
paths: tool.schema
|
|
86
|
+
.array(tool.schema.string())
|
|
87
|
+
.optional()
|
|
88
|
+
.describe('Paths to search'),
|
|
89
|
+
globs: tool.schema
|
|
90
|
+
.array(tool.schema.string())
|
|
91
|
+
.optional()
|
|
92
|
+
.describe('Include/exclude globs'),
|
|
93
|
+
dryRun: tool.schema
|
|
94
|
+
.boolean()
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('Preview changes without applying (default: true)'),
|
|
97
|
+
},
|
|
98
|
+
execute: async (args, context) => {
|
|
99
|
+
try {
|
|
100
|
+
const result = await runSg({
|
|
101
|
+
pattern: args.pattern,
|
|
102
|
+
rewrite: args.rewrite,
|
|
103
|
+
lang: args.lang as CliLanguage,
|
|
104
|
+
paths: args.paths,
|
|
105
|
+
globs: args.globs,
|
|
106
|
+
updateAll: args.dryRun === false,
|
|
107
|
+
});
|
|
108
|
+
const output = formatReplaceResult(result, args.dryRun !== false);
|
|
109
|
+
showOutputToUser(context, output);
|
|
110
|
+
return output;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
const output = `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
113
|
+
showOutputToUser(context, output);
|
|
114
|
+
return output;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// CLI supported languages (25 total)
|
|
2
|
+
export const CLI_LANGUAGES = [
|
|
3
|
+
'bash',
|
|
4
|
+
'c',
|
|
5
|
+
'cpp',
|
|
6
|
+
'csharp',
|
|
7
|
+
'css',
|
|
8
|
+
'elixir',
|
|
9
|
+
'go',
|
|
10
|
+
'haskell',
|
|
11
|
+
'html',
|
|
12
|
+
'java',
|
|
13
|
+
'javascript',
|
|
14
|
+
'json',
|
|
15
|
+
'kotlin',
|
|
16
|
+
'lua',
|
|
17
|
+
'nix',
|
|
18
|
+
'php',
|
|
19
|
+
'python',
|
|
20
|
+
'ruby',
|
|
21
|
+
'rust',
|
|
22
|
+
'scala',
|
|
23
|
+
'solidity',
|
|
24
|
+
'swift',
|
|
25
|
+
'typescript',
|
|
26
|
+
'tsx',
|
|
27
|
+
'yaml',
|
|
28
|
+
] as const;
|
|
29
|
+
|
|
30
|
+
export type CliLanguage = (typeof CLI_LANGUAGES)[number];
|
|
31
|
+
|
|
32
|
+
export interface CliMatch {
|
|
33
|
+
file: string;
|
|
34
|
+
range: {
|
|
35
|
+
byteOffset: { start: number; end: number };
|
|
36
|
+
start: { line: number; column: number };
|
|
37
|
+
end: { line: number; column: number };
|
|
38
|
+
};
|
|
39
|
+
lines: string;
|
|
40
|
+
text: string;
|
|
41
|
+
replacement?: string;
|
|
42
|
+
language: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SgResult {
|
|
46
|
+
matches: CliMatch[];
|
|
47
|
+
totalMatches: number;
|
|
48
|
+
truncated: boolean;
|
|
49
|
+
truncatedReason?: 'timeout' | 'max_output_bytes' | 'max_matches';
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { CliLanguage, SgResult } from './types';
|
|
2
|
+
|
|
3
|
+
export function formatSearchResult(result: SgResult): string {
|
|
4
|
+
if (result.error) {
|
|
5
|
+
return `Error: ${result.error}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (result.matches.length === 0) {
|
|
9
|
+
return 'No matches found.';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const lines: string[] = [];
|
|
13
|
+
|
|
14
|
+
// Group matches by file
|
|
15
|
+
const byFile = new Map<string, typeof result.matches>();
|
|
16
|
+
for (const match of result.matches) {
|
|
17
|
+
const existing = byFile.get(match.file) || [];
|
|
18
|
+
existing.push(match);
|
|
19
|
+
byFile.set(match.file, existing);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (const [file, matches] of byFile) {
|
|
23
|
+
lines.push(`\n${file}:`);
|
|
24
|
+
for (const match of matches) {
|
|
25
|
+
const startLine = match.range.start.line + 1;
|
|
26
|
+
const text =
|
|
27
|
+
match.text.length > 100
|
|
28
|
+
? `${match.text.substring(0, 100)}...`
|
|
29
|
+
: match.text;
|
|
30
|
+
lines.push(` ${startLine}: ${text.replace(/\n/g, '\\n')}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fileCount = byFile.size;
|
|
35
|
+
const summary = `Found ${result.totalMatches} matches in ${fileCount} files`;
|
|
36
|
+
if (result.truncated) {
|
|
37
|
+
lines.push(`\n${summary} (output truncated: ${result.truncatedReason})`);
|
|
38
|
+
} else {
|
|
39
|
+
lines.push(`\n${summary}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return lines.join('\n');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function formatReplaceResult(
|
|
46
|
+
result: SgResult,
|
|
47
|
+
isDryRun: boolean,
|
|
48
|
+
): string {
|
|
49
|
+
if (result.error) {
|
|
50
|
+
return `Error: ${result.error}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (result.matches.length === 0) {
|
|
54
|
+
return 'No matches found for replacement.';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const lines: string[] = [];
|
|
58
|
+
const mode = isDryRun ? '[DRY RUN]' : '[APPLIED]';
|
|
59
|
+
|
|
60
|
+
// Group by file
|
|
61
|
+
const byFile = new Map<string, typeof result.matches>();
|
|
62
|
+
for (const match of result.matches) {
|
|
63
|
+
const existing = byFile.get(match.file) || [];
|
|
64
|
+
existing.push(match);
|
|
65
|
+
byFile.set(match.file, existing);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const [file, matches] of byFile) {
|
|
69
|
+
lines.push(`\n${file}:`);
|
|
70
|
+
for (const match of matches) {
|
|
71
|
+
const startLine = match.range.start.line + 1;
|
|
72
|
+
const original =
|
|
73
|
+
match.text.length > 60
|
|
74
|
+
? `${match.text.substring(0, 60)}...`
|
|
75
|
+
: match.text;
|
|
76
|
+
const replacement = match.replacement
|
|
77
|
+
? match.replacement.length > 60
|
|
78
|
+
? `${match.replacement.substring(0, 60)}...`
|
|
79
|
+
: match.replacement
|
|
80
|
+
: '[no replacement]';
|
|
81
|
+
lines.push(
|
|
82
|
+
` ${startLine}: "${original.replace(/\n/g, '\\n')}" → "${replacement.replace(/\n/g, '\\n')}"`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const fileCount = byFile.size;
|
|
88
|
+
lines.push(
|
|
89
|
+
`\n${mode} ${result.totalMatches} replacements in ${fileCount} files`,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (isDryRun) {
|
|
93
|
+
lines.push('\nTo apply changes, run with dryRun=false');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return lines.join('\n');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getEmptyResultHint(
|
|
100
|
+
pattern: string,
|
|
101
|
+
lang: CliLanguage,
|
|
102
|
+
): string | null {
|
|
103
|
+
const src = pattern.trim();
|
|
104
|
+
|
|
105
|
+
if (lang === 'python') {
|
|
106
|
+
if (src.startsWith('class ') && src.endsWith(':')) {
|
|
107
|
+
const withoutColon = src.slice(0, -1);
|
|
108
|
+
return `Hint: Remove trailing colon. Try: "${withoutColon}"`;
|
|
109
|
+
}
|
|
110
|
+
if (
|
|
111
|
+
(src.startsWith('def ') || src.startsWith('async def ')) &&
|
|
112
|
+
src.endsWith(':')
|
|
113
|
+
) {
|
|
114
|
+
const withoutColon = src.slice(0, -1);
|
|
115
|
+
return `Hint: Remove trailing colon. Try: "${withoutColon}"`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (['javascript', 'typescript', 'tsx'].includes(lang)) {
|
|
120
|
+
if (/^(export\s+)?(async\s+)?function\s+\$[A-Z_]+\s*$/i.test(src)) {
|
|
121
|
+
return `Hint: Function patterns need params and body. Try "function $NAME($$$) { $$$ }"`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { subagentOutputRequestsUserHandoff } from './delegate';
|
|
3
|
+
|
|
4
|
+
describe('subagentOutputRequestsUserHandoff', () => {
|
|
5
|
+
test('true when <needs_user> is present', () => {
|
|
6
|
+
expect(
|
|
7
|
+
subagentOutputRequestsUserHandoff(
|
|
8
|
+
'<diagnosis>x</diagnosis><needs_user>clarify</needs_user>',
|
|
9
|
+
),
|
|
10
|
+
).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('false when only blocked', () => {
|
|
14
|
+
expect(subagentOutputRequestsUserHandoff('<blocked>x</blocked>')).toBe(
|
|
15
|
+
false,
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|