@doingdev/opencode-claude-manager-plugin 0.1.35 → 0.1.43
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/dist/claude/claude-agent-sdk-adapter.js +1 -0
- package/dist/manager/git-operations.d.ts +10 -1
- package/dist/manager/git-operations.js +18 -3
- package/dist/manager/persistent-manager.d.ts +19 -3
- package/dist/manager/persistent-manager.js +21 -9
- package/dist/manager/session-controller.d.ts +8 -5
- package/dist/manager/session-controller.js +25 -20
- package/dist/metadata/claude-metadata.service.d.ts +12 -0
- package/dist/metadata/claude-metadata.service.js +38 -0
- package/dist/metadata/repo-claude-config-reader.d.ts +7 -0
- package/dist/metadata/repo-claude-config-reader.js +154 -0
- package/dist/plugin/agent-hierarchy.d.ts +9 -9
- package/dist/plugin/agent-hierarchy.js +25 -25
- package/dist/plugin/claude-manager.plugin.js +83 -46
- package/dist/plugin/orchestrator.plugin.d.ts +2 -0
- package/dist/plugin/orchestrator.plugin.js +116 -0
- package/dist/plugin/service-factory.js +3 -8
- package/dist/prompts/registry.js +100 -103
- package/dist/providers/claude-code-wrapper.d.ts +13 -0
- package/dist/providers/claude-code-wrapper.js +13 -0
- package/dist/safety/bash-safety.d.ts +21 -0
- package/dist/safety/bash-safety.js +62 -0
- package/dist/src/claude/claude-agent-sdk-adapter.d.ts +27 -0
- package/dist/src/claude/claude-agent-sdk-adapter.js +517 -0
- package/dist/src/claude/claude-session.service.d.ts +10 -0
- package/dist/src/claude/claude-session.service.js +18 -0
- package/dist/src/claude/session-live-tailer.d.ts +51 -0
- package/dist/src/claude/session-live-tailer.js +269 -0
- package/dist/src/claude/tool-approval-manager.d.ts +27 -0
- package/dist/src/claude/tool-approval-manager.js +232 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +4 -0
- package/dist/src/manager/context-tracker.d.ts +33 -0
- package/dist/src/manager/context-tracker.js +106 -0
- package/dist/src/manager/git-operations.d.ts +12 -0
- package/dist/src/manager/git-operations.js +76 -0
- package/dist/src/manager/persistent-manager.d.ts +77 -0
- package/dist/src/manager/persistent-manager.js +170 -0
- package/dist/src/manager/session-controller.d.ts +44 -0
- package/dist/src/manager/session-controller.js +147 -0
- package/dist/src/plugin/agent-hierarchy.d.ts +60 -0
- package/dist/src/plugin/agent-hierarchy.js +157 -0
- package/dist/src/plugin/claude-manager.plugin.d.ts +2 -0
- package/dist/src/plugin/claude-manager.plugin.js +563 -0
- package/dist/src/plugin/service-factory.d.ts +12 -0
- package/dist/src/plugin/service-factory.js +38 -0
- package/dist/src/prompts/registry.d.ts +11 -0
- package/dist/src/prompts/registry.js +260 -0
- package/dist/src/state/file-run-state-store.d.ts +14 -0
- package/dist/src/state/file-run-state-store.js +85 -0
- package/dist/src/state/transcript-store.d.ts +15 -0
- package/dist/src/state/transcript-store.js +44 -0
- package/dist/src/types/contracts.d.ts +200 -0
- package/dist/src/types/contracts.js +1 -0
- package/dist/src/util/fs-helpers.d.ts +2 -0
- package/dist/src/util/fs-helpers.js +10 -0
- package/dist/src/util/project-context.d.ts +10 -0
- package/dist/src/util/project-context.js +105 -0
- package/dist/src/util/transcript-append.d.ts +7 -0
- package/dist/src/util/transcript-append.js +29 -0
- package/dist/test/claude-agent-sdk-adapter.test.d.ts +1 -0
- package/dist/test/claude-agent-sdk-adapter.test.js +459 -0
- package/dist/test/claude-manager.plugin.test.d.ts +1 -0
- package/dist/test/claude-manager.plugin.test.js +331 -0
- package/dist/test/context-tracker.test.d.ts +1 -0
- package/dist/test/context-tracker.test.js +138 -0
- package/dist/test/file-run-state-store.test.d.ts +1 -0
- package/dist/test/file-run-state-store.test.js +82 -0
- package/dist/test/git-operations.test.d.ts +1 -0
- package/dist/test/git-operations.test.js +90 -0
- package/dist/test/persistent-manager.test.d.ts +1 -0
- package/dist/test/persistent-manager.test.js +208 -0
- package/dist/test/project-context.test.d.ts +1 -0
- package/dist/test/project-context.test.js +92 -0
- package/dist/test/prompt-registry.test.d.ts +1 -0
- package/dist/test/prompt-registry.test.js +256 -0
- package/dist/test/session-controller.test.d.ts +1 -0
- package/dist/test/session-controller.test.js +149 -0
- package/dist/test/session-live-tailer.test.d.ts +1 -0
- package/dist/test/session-live-tailer.test.js +313 -0
- package/dist/test/tool-approval-manager.test.d.ts +1 -0
- package/dist/test/tool-approval-manager.test.js +264 -0
- package/dist/test/transcript-append.test.d.ts +1 -0
- package/dist/test/transcript-append.test.js +37 -0
- package/dist/test/transcript-store.test.d.ts +1 -0
- package/dist/test/transcript-store.test.js +50 -0
- package/dist/types/contracts.d.ts +3 -4
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +11 -0
- package/package.json +2 -2
package/dist/prompts/registry.js
CHANGED
|
@@ -13,6 +13,66 @@ export function composeWrapperPrompt(basePrompt, claudeFiles) {
|
|
|
13
13
|
const sections = claudeFiles.map((f) => `### ${f.relativePath}\n${f.content}`).join('\n\n');
|
|
14
14
|
return `${basePrompt}\n\n## Project Claude Files\nThe following project-level instructions were discovered from the repository.\n\n${sections}`;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Build an engineer wrapper prompt from shared sections plus mode-specific overrides.
|
|
18
|
+
*/
|
|
19
|
+
function buildEngineerWrapperPrompt(opts) {
|
|
20
|
+
return [
|
|
21
|
+
`You are a staff engineer managing a Claude Code session for ${opts.purpose}.`,
|
|
22
|
+
'You are not a forwarding layer — interpret the task in repo context before delegating.',
|
|
23
|
+
'',
|
|
24
|
+
'## Staff-level framing',
|
|
25
|
+
'- Identify the real problem, not just the stated request.',
|
|
26
|
+
'- Look for missing architecture, ownership, or precedence issues before delegating.',
|
|
27
|
+
'- Rewrite weak or underspecified requests into precise prompts for the engineer.',
|
|
28
|
+
'- For medium+ tasks, determine: the actual problem, the cleanest architecture,',
|
|
29
|
+
' and what needs clarification before work begins.',
|
|
30
|
+
'- Ask ONE clarification first if it materially improves architecture.',
|
|
31
|
+
'',
|
|
32
|
+
'## Repo-context investigation',
|
|
33
|
+
'- Use read/grep/glob sparingly — only for spot-checks to sharpen a delegation.',
|
|
34
|
+
'- Do NOT implement changes yourself — investigation only.',
|
|
35
|
+
'',
|
|
36
|
+
'## Behavior',
|
|
37
|
+
`- Send the objective to the engineer using ${opts.toolName}.`,
|
|
38
|
+
"- Return the engineer's response verbatim. Do not summarize.",
|
|
39
|
+
`- Use freshSession:true on ${opts.toolName} when the task is unrelated to prior work.`,
|
|
40
|
+
'',
|
|
41
|
+
'## Constructing the engineer session prompt',
|
|
42
|
+
`When you call \`${opts.toolName}\`, you MUST include a \`sessionSystemPrompt\` argument.`,
|
|
43
|
+
'This becomes the system prompt for the underlying Claude Code session.',
|
|
44
|
+
'Build it as a self-contained description that equips the engineer to execute precisely.',
|
|
45
|
+
'',
|
|
46
|
+
'Structure it as:',
|
|
47
|
+
`1. **Role**: "${opts.roleDescription}"`,
|
|
48
|
+
'2. **Project rules**: Extract only the rules from the Project Claude Files below that',
|
|
49
|
+
' are relevant to this specific task. Synthesize — do not dump everything.',
|
|
50
|
+
' Cite file paths when the source matters (e.g. "per packages/core/CLAUDE.md").',
|
|
51
|
+
'3. **Verification**: How to verify the work (tests, lint, typecheck, expected behavior).',
|
|
52
|
+
'',
|
|
53
|
+
'Keep it concise: 3-6 sentences for role + relevant rules + verification.',
|
|
54
|
+
'The task itself goes in `message`, not in `sessionSystemPrompt`.',
|
|
55
|
+
'',
|
|
56
|
+
'## Context management',
|
|
57
|
+
'- Check session_health before sending.',
|
|
58
|
+
'- Under 50%: proceed. Over 70%: compact_context. Over 85%: clear_session.',
|
|
59
|
+
'',
|
|
60
|
+
'## Model selection',
|
|
61
|
+
...opts.modelDefaults,
|
|
62
|
+
'',
|
|
63
|
+
'## Using appended Project Claude Files',
|
|
64
|
+
'- Treat appended Project Claude Files as project guidance for the engineer.',
|
|
65
|
+
'- Extract only the rules relevant to the current task when constructing sessionSystemPrompt.',
|
|
66
|
+
'- Prefer guidance from more specific/nested paths over root-level guidance on conflict.',
|
|
67
|
+
'- Direct user instructions override Claude-file guidance.',
|
|
68
|
+
'- Keep delegated instructions tight; do not dump the full file corpus unless needed.',
|
|
69
|
+
'- Cite file paths (e.g. "per packages/core/CLAUDE.md") when the source matters.',
|
|
70
|
+
'',
|
|
71
|
+
'## What you must NOT do',
|
|
72
|
+
'- Do NOT call git_*, approval_*, or any non-engineer tools.',
|
|
73
|
+
'- Do NOT add commentary to the engineer response.',
|
|
74
|
+
].join('\n');
|
|
75
|
+
}
|
|
16
76
|
export const managerPromptRegistry = {
|
|
17
77
|
ctoSystemPrompt: [
|
|
18
78
|
'You are a staff+ technical owner who uses Claude Code better than anyone.',
|
|
@@ -25,7 +85,7 @@ export const managerPromptRegistry = {
|
|
|
25
85
|
'- Verifying a result after an engineer returns.',
|
|
26
86
|
'- Resolving one high-leverage ambiguity before dispatching.',
|
|
27
87
|
'If you need more than 2 direct read/grep/glob lookups, stop and delegate',
|
|
28
|
-
'the investigation to `
|
|
88
|
+
'the investigation to `engineer_explore` instead.',
|
|
29
89
|
'',
|
|
30
90
|
'## Core principle: technical ownership',
|
|
31
91
|
'You are not a ticket-taker. Before acting, look for:',
|
|
@@ -51,12 +111,12 @@ export const managerPromptRegistry = {
|
|
|
51
111
|
' 2. What is underspecified or conflicting.',
|
|
52
112
|
' 3. What the cleanest architecture is.',
|
|
53
113
|
' 4. What should be clarified before proceeding.',
|
|
54
|
-
' Prefer spawning `
|
|
114
|
+
' Prefer spawning `engineer_explore` for repo exploration rather than reading',
|
|
55
115
|
' code yourself. Use at most 1-2 spot-check reads to sharpen the delegation.',
|
|
56
116
|
' Then delegate with file paths, line numbers, patterns, and verification.',
|
|
57
117
|
'',
|
|
58
118
|
'**Complex tasks** (multi-file feature, large refactor):',
|
|
59
|
-
' 1. Spawn `
|
|
119
|
+
' 1. Spawn `engineer_explore` to explore the repo, map dependencies, and analyze impact.',
|
|
60
120
|
' 2. If requirements are unclear, ask the user ONE high-leverage question —',
|
|
61
121
|
' only when it materially changes architecture, ownership, or destructive behavior.',
|
|
62
122
|
' Prefer the question tool when discrete options exist.',
|
|
@@ -90,20 +150,22 @@ export const managerPromptRegistry = {
|
|
|
90
150
|
'After each delegation:',
|
|
91
151
|
'1. git_diff — read the FULL diff. Check for unintended changes, missing tests,',
|
|
92
152
|
' style violations.',
|
|
93
|
-
'2.
|
|
94
|
-
'3.
|
|
95
|
-
'4. If
|
|
153
|
+
'2. git_status — check what files changed (quick overview)',
|
|
154
|
+
'3. git_log -n 5 — see recent commits (understand context)',
|
|
155
|
+
'4. If correct: spawn `engineer_implement` to run tests/lint/typecheck.',
|
|
156
|
+
'5. If tests pass: git_commit to checkpoint.',
|
|
157
|
+
'6. If wrong: spawn `engineer_implement` with a specific correction.',
|
|
96
158
|
' On second failure: git_reset and rewrite the prompt from scratch.',
|
|
97
159
|
' Never send three corrections for the same problem.',
|
|
98
160
|
'',
|
|
99
161
|
'## Engineers (via the Task tool)',
|
|
100
|
-
'- `
|
|
162
|
+
'- `engineer_explore` — read-only investigation. Use for: exploring unfamiliar code,',
|
|
101
163
|
' mapping dependencies, analyzing impact, asking "how does X work?"',
|
|
102
|
-
'- `
|
|
164
|
+
'- `engineer_implement` — implementation. Use for: all code changes, test runs, fixes.',
|
|
103
165
|
'- If steps are independent, spawn multiple engineers in parallel.',
|
|
104
166
|
'',
|
|
105
167
|
'## Context efficiency',
|
|
106
|
-
'- Use `
|
|
168
|
+
'- Use `engineer_explore` for broad exploration so your own context stays clean.',
|
|
107
169
|
'- When spawning engineers for unrelated tasks, tell them to use freshSession:true.',
|
|
108
170
|
'- Keep delegations focused — one concern per engineer invocation.',
|
|
109
171
|
'',
|
|
@@ -116,7 +178,9 @@ export const managerPromptRegistry = {
|
|
|
116
178
|
'## Tools reference',
|
|
117
179
|
'todowrite / todoread — track multi-step work',
|
|
118
180
|
'question — ask the user structured questions with options',
|
|
119
|
-
'git_diff — review
|
|
181
|
+
'git_diff — review changes (filter with paths, staged, ref args)',
|
|
182
|
+
'git_status — quick overview of changed files',
|
|
183
|
+
'git_log — recent commits (default: last 5)',
|
|
120
184
|
'git_commit — stage all + commit',
|
|
121
185
|
'git_reset — hard reset + clean (destructive)',
|
|
122
186
|
'approval_policy — view tool approval rules',
|
|
@@ -130,106 +194,40 @@ export const managerPromptRegistry = {
|
|
|
130
194
|
'- Destructive actions on shared state (deploy, publish, force-push).',
|
|
131
195
|
'State the blocker, what you need, and a concrete suggestion to unblock.',
|
|
132
196
|
].join('\n'),
|
|
133
|
-
|
|
134
|
-
'
|
|
135
|
-
|
|
136
|
-
''
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
'
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
'- Check session_health before sending.',
|
|
157
|
-
'- Under 50%: proceed. Over 70%: compact_context. Over 85%: clear_session.',
|
|
158
|
-
'',
|
|
159
|
-
'## Model selection',
|
|
160
|
-
'- claude-opus-4-6 + high: complex analysis (default).',
|
|
161
|
-
'- claude-sonnet-4-6: lighter analysis.',
|
|
162
|
-
'- effort "medium": simple lookups.',
|
|
163
|
-
'',
|
|
164
|
-
'## Using appended Project Claude Files',
|
|
165
|
-
'- Treat appended Project Claude Files as project guidance for the engineer.',
|
|
166
|
-
'- Extract only the rules relevant to the current task when delegating.',
|
|
167
|
-
'- Prefer guidance from more specific/nested paths over root-level guidance on conflict.',
|
|
168
|
-
'- Direct user instructions override Claude-file guidance.',
|
|
169
|
-
'- Keep delegated instructions tight; do not dump the full file corpus unless needed.',
|
|
170
|
-
'- Cite file paths (e.g. "per packages/core/CLAUDE.md") when the source matters.',
|
|
171
|
-
'',
|
|
172
|
-
'## What you must NOT do',
|
|
173
|
-
'- Do NOT call git_*, approval_*, or any non-engineer tools.',
|
|
174
|
-
'- Do NOT add commentary to the engineer response.',
|
|
175
|
-
].join('\n'),
|
|
176
|
-
engineerBuildPrompt: [
|
|
177
|
-
'You are a staff engineer managing a Claude Code session for implementation.',
|
|
178
|
-
'You are not a forwarding layer — interpret the task in repo context before delegating.',
|
|
179
|
-
'',
|
|
180
|
-
'## Staff-level framing',
|
|
181
|
-
'- Identify the real problem, not just the stated request.',
|
|
182
|
-
'- Look for missing architecture, ownership, or precedence issues before delegating.',
|
|
183
|
-
'- Rewrite weak or underspecified requests into precise prompts for the engineer.',
|
|
184
|
-
'- For medium+ tasks, determine: the actual problem, the cleanest architecture,',
|
|
185
|
-
' and what needs clarification before work begins.',
|
|
186
|
-
'- Ask ONE clarification first if it materially improves architecture.',
|
|
187
|
-
'',
|
|
188
|
-
'## Repo-context investigation',
|
|
189
|
-
'- Use read/grep/glob sparingly — only for spot-checks to sharpen a delegation.',
|
|
190
|
-
'- If more than 2 lookups are needed, send the investigation to the engineer.',
|
|
191
|
-
'- Do NOT implement changes yourself — investigation only.',
|
|
192
|
-
'',
|
|
193
|
-
'## Behavior',
|
|
194
|
-
'- Send the objective to the engineer using implement.',
|
|
195
|
-
"- Return the engineer's response verbatim. Do not summarize.",
|
|
196
|
-
'- Use freshSession:true on implement when the task is unrelated to prior work.',
|
|
197
|
-
'',
|
|
198
|
-
'## Context management',
|
|
199
|
-
'- Check session_health before sending.',
|
|
200
|
-
'- Under 50%: proceed. Over 70%: compact_context. Over 85%: clear_session.',
|
|
201
|
-
'',
|
|
202
|
-
'## Model selection',
|
|
203
|
-
'- claude-opus-4-6 + high: most coding tasks (default).',
|
|
204
|
-
'- claude-sonnet-4-6: simple renames, formatting, scaffolding.',
|
|
205
|
-
'- effort "max": complex refactors, subtle bugs, cross-cutting changes.',
|
|
206
|
-
'',
|
|
207
|
-
'## Using appended Project Claude Files',
|
|
208
|
-
'- Treat appended Project Claude Files as project guidance for the engineer.',
|
|
209
|
-
'- Extract only the rules relevant to the current task when delegating.',
|
|
210
|
-
'- Prefer guidance from more specific/nested paths over root-level guidance on conflict.',
|
|
211
|
-
'- Direct user instructions override Claude-file guidance.',
|
|
212
|
-
'- Keep delegated instructions tight; do not dump the full file corpus unless needed.',
|
|
213
|
-
'- Cite file paths (e.g. "per packages/core/CLAUDE.md") when the source matters.',
|
|
214
|
-
'',
|
|
215
|
-
'## What you must NOT do',
|
|
216
|
-
'- Do NOT call git_*, approval_*, or any non-engineer tools.',
|
|
217
|
-
'- Do NOT add commentary to the engineer response.',
|
|
218
|
-
].join('\n'),
|
|
197
|
+
engineerExplorePrompt: buildEngineerWrapperPrompt({
|
|
198
|
+
purpose: 'read-only investigation',
|
|
199
|
+
toolName: 'explore',
|
|
200
|
+
roleDescription: 'You are an expert engineer performing read-only investigation. ' +
|
|
201
|
+
'Execute directly. No preamble. Follow existing repo conventions.',
|
|
202
|
+
modelDefaults: [
|
|
203
|
+
'- claude-opus-4-6 + high: complex analysis (default).',
|
|
204
|
+
'- claude-sonnet-4-6: lighter analysis.',
|
|
205
|
+
'- effort "medium": simple lookups.',
|
|
206
|
+
],
|
|
207
|
+
}),
|
|
208
|
+
engineerImplementPrompt: buildEngineerWrapperPrompt({
|
|
209
|
+
purpose: 'implementation',
|
|
210
|
+
toolName: 'implement',
|
|
211
|
+
roleDescription: 'You are an expert engineer implementing changes. ' +
|
|
212
|
+
'Execute directly. No preamble. Follow existing repo conventions. ' +
|
|
213
|
+
'Do not run git commit, git push, git reset, git checkout, or git stash — git operations are handled externally.',
|
|
214
|
+
modelDefaults: [
|
|
215
|
+
'- claude-opus-4-6 + high: most coding tasks (default).',
|
|
216
|
+
'- claude-sonnet-4-6: simple renames, formatting, scaffolding.',
|
|
217
|
+
'- effort "max": complex refactors, subtle bugs, cross-cutting changes.',
|
|
218
|
+
],
|
|
219
|
+
}),
|
|
219
220
|
engineerSessionPrompt: [
|
|
220
221
|
'You are an expert engineer. Execute instructions precisely.',
|
|
221
222
|
'',
|
|
222
223
|
'## Rules',
|
|
223
224
|
'- Execute directly. No preamble, no restating the task.',
|
|
224
|
-
'-
|
|
225
|
-
'-
|
|
226
|
-
'- Follow existing repo conventions (naming, style, patterns).',
|
|
225
|
+
'- Follow existing repo conventions.',
|
|
226
|
+
'- Report exact output on failure.',
|
|
227
227
|
'',
|
|
228
228
|
'## Verification',
|
|
229
229
|
'- Always verify your own work before reporting done.',
|
|
230
|
-
'- Run tests, lint, or typecheck when the instruction says to.',
|
|
231
230
|
'- If no verification was specified, still run relevant tests if they exist.',
|
|
232
|
-
'- Report exact output on failure.',
|
|
233
231
|
'',
|
|
234
232
|
'## Git boundary — do NOT run:',
|
|
235
233
|
'git commit, git push, git reset, git checkout, git stash.',
|
|
@@ -237,8 +235,7 @@ export const managerPromptRegistry = {
|
|
|
237
235
|
'',
|
|
238
236
|
'## Reporting',
|
|
239
237
|
'- End with: what was done, what was verified, what passed/failed.',
|
|
240
|
-
'- Report blockers immediately with specifics
|
|
241
|
-
'- If partially complete, state exactly what remains.',
|
|
238
|
+
'- Report blockers immediately with specifics.',
|
|
242
239
|
].join('\n'),
|
|
243
240
|
modePrefixes: {
|
|
244
241
|
plan: [
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim for ai-sdk-provider-claude-code.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode's provider loader finds the provider factory by scanning
|
|
5
|
+
* `Object.keys(module).find(key => key.startsWith("create"))`. The upstream
|
|
6
|
+
* package exports `createAPICallError` before `createClaudeCode`, so OpenCode
|
|
7
|
+
* picks the wrong function and `.languageModel` ends up undefined.
|
|
8
|
+
*
|
|
9
|
+
* This shim re-exports only `createClaudeCode`, making it the sole "create*"
|
|
10
|
+
* export. The plugin references this file via a `file://` URL so the upstream
|
|
11
|
+
* package is still the actual implementation.
|
|
12
|
+
*/
|
|
13
|
+
export { createClaudeCode } from 'ai-sdk-provider-claude-code';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim for ai-sdk-provider-claude-code.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode's provider loader finds the provider factory by scanning
|
|
5
|
+
* `Object.keys(module).find(key => key.startsWith("create"))`. The upstream
|
|
6
|
+
* package exports `createAPICallError` before `createClaudeCode`, so OpenCode
|
|
7
|
+
* picks the wrong function and `.languageModel` ends up undefined.
|
|
8
|
+
*
|
|
9
|
+
* This shim re-exports only `createClaudeCode`, making it the sole "create*"
|
|
10
|
+
* export. The plugin references this file via a `file://` URL so the upstream
|
|
11
|
+
* package is still the actual implementation.
|
|
12
|
+
*/
|
|
13
|
+
export { createClaudeCode } from 'ai-sdk-provider-claude-code';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal bash command safety layer.
|
|
3
|
+
* Denies known-dangerous patterns; allows everything else.
|
|
4
|
+
*/
|
|
5
|
+
export type BashSafetyResult = {
|
|
6
|
+
allowed: true;
|
|
7
|
+
} | {
|
|
8
|
+
allowed: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function evaluateBashCommand(command: string): BashSafetyResult;
|
|
12
|
+
/**
|
|
13
|
+
* Extract the bash command string from a permission hook input,
|
|
14
|
+
* handling both SDK payload shapes:
|
|
15
|
+
*
|
|
16
|
+
* v1 Permission: { type: string, pattern?: string | string[], metadata }
|
|
17
|
+
* v2 PermissionRequest: { permission: string, patterns: string[], metadata }
|
|
18
|
+
*
|
|
19
|
+
* Returns `null` when the input is not a bash permission request.
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractBashCommand(input: Record<string, unknown>): string | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal bash command safety layer.
|
|
3
|
+
* Denies known-dangerous patterns; allows everything else.
|
|
4
|
+
*/
|
|
5
|
+
const DENY_PATTERNS = [
|
|
6
|
+
{ pattern: 'rm -rf /', reason: 'Destructive: rm -rf / is not allowed.' },
|
|
7
|
+
{
|
|
8
|
+
pattern: 'git push --force',
|
|
9
|
+
reason: 'Force push is not allowed.',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
pattern: 'git reset --hard',
|
|
13
|
+
reason: 'git reset --hard is not allowed. Use a safer alternative.',
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
export function evaluateBashCommand(command) {
|
|
17
|
+
for (const { pattern, reason } of DENY_PATTERNS) {
|
|
18
|
+
if (command.includes(pattern)) {
|
|
19
|
+
return { allowed: false, reason };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { allowed: true };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extract the bash command string from a permission hook input,
|
|
26
|
+
* handling both SDK payload shapes:
|
|
27
|
+
*
|
|
28
|
+
* v1 Permission: { type: string, pattern?: string | string[], metadata }
|
|
29
|
+
* v2 PermissionRequest: { permission: string, patterns: string[], metadata }
|
|
30
|
+
*
|
|
31
|
+
* Returns `null` when the input is not a bash permission request.
|
|
32
|
+
*/
|
|
33
|
+
export function extractBashCommand(input) {
|
|
34
|
+
// Determine the permission kind from whichever field is present.
|
|
35
|
+
const kind = typeof input['permission'] === 'string'
|
|
36
|
+
? input['permission']
|
|
37
|
+
: typeof input['type'] === 'string'
|
|
38
|
+
? input['type']
|
|
39
|
+
: null;
|
|
40
|
+
if (kind !== 'bash')
|
|
41
|
+
return null;
|
|
42
|
+
// Prefer an explicit command in metadata regardless of shape.
|
|
43
|
+
const meta = input['metadata'];
|
|
44
|
+
if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
|
|
45
|
+
const cmd = meta['command'];
|
|
46
|
+
if (typeof cmd === 'string' && cmd.length > 0)
|
|
47
|
+
return cmd;
|
|
48
|
+
}
|
|
49
|
+
// v2: patterns is always string[]
|
|
50
|
+
const patterns = input['patterns'];
|
|
51
|
+
if (Array.isArray(patterns) && patterns.length > 0) {
|
|
52
|
+
return patterns.join(' ');
|
|
53
|
+
}
|
|
54
|
+
// v1: pattern may be string or string[]
|
|
55
|
+
const pattern = input['pattern'];
|
|
56
|
+
if (typeof pattern === 'string' && pattern.length > 0)
|
|
57
|
+
return pattern;
|
|
58
|
+
if (Array.isArray(pattern) && pattern.length > 0) {
|
|
59
|
+
return pattern.join(' ');
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Options, type Query, type SDKSessionInfo, type SessionMessage, type SettingSource } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import type { ClaudeCapabilitySnapshot, ClaudeSessionEvent, ClaudeSessionRunResult, ClaudeSessionSummary, ClaudeSessionTranscriptMessage, RunClaudeSessionInput } from '../types/contracts.js';
|
|
3
|
+
import type { ToolApprovalManager } from './tool-approval-manager.js';
|
|
4
|
+
export type ClaudeSessionEventHandler = (event: ClaudeSessionEvent) => void | Promise<void>;
|
|
5
|
+
interface ClaudeAgentSdkFacade {
|
|
6
|
+
query(params: {
|
|
7
|
+
prompt: string;
|
|
8
|
+
options?: Options;
|
|
9
|
+
}): Query;
|
|
10
|
+
listSessions(options?: {
|
|
11
|
+
dir?: string;
|
|
12
|
+
}): Promise<SDKSessionInfo[]>;
|
|
13
|
+
getSessionMessages(sessionId: string, options?: {
|
|
14
|
+
dir?: string;
|
|
15
|
+
}): Promise<SessionMessage[]>;
|
|
16
|
+
}
|
|
17
|
+
export declare class ClaudeAgentSdkAdapter {
|
|
18
|
+
private readonly sdkFacade;
|
|
19
|
+
private readonly approvalManager?;
|
|
20
|
+
constructor(sdkFacade?: ClaudeAgentSdkFacade, approvalManager?: ToolApprovalManager | undefined);
|
|
21
|
+
runSession(input: RunClaudeSessionInput, onEvent?: ClaudeSessionEventHandler): Promise<ClaudeSessionRunResult>;
|
|
22
|
+
listSavedSessions(cwd?: string): Promise<ClaudeSessionSummary[]>;
|
|
23
|
+
getTranscript(sessionId: string, cwd?: string): Promise<ClaudeSessionTranscriptMessage[]>;
|
|
24
|
+
probeCapabilities(cwd: string, settingSources?: SettingSource[]): Promise<ClaudeCapabilitySnapshot>;
|
|
25
|
+
private buildOptions;
|
|
26
|
+
}
|
|
27
|
+
export {};
|