@doingdev/opencode-claude-manager-plugin 0.1.29 → 0.1.30
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.
|
@@ -11,7 +11,7 @@ export declare const AGENT_CTO = "cto";
|
|
|
11
11
|
export declare const AGENT_ENGINEER_PLAN = "engineer_plan";
|
|
12
12
|
export declare const AGENT_ENGINEER_BUILD = "engineer_build";
|
|
13
13
|
/** All restricted tool IDs (union of all domain groups) */
|
|
14
|
-
export declare const ALL_RESTRICTED_TOOL_IDS: readonly ["engineer_send", "engineer_compact", "engineer_clear", "engineer_status", "engineer_metadata", "engineer_sessions", "engineer_runs", "git_diff", "git_commit", "git_reset", "approval_policy", "approval_decisions", "approval_update"];
|
|
14
|
+
export declare const ALL_RESTRICTED_TOOL_IDS: readonly ["engineer_send", "engineer_send_plan", "engineer_send_build", "engineer_compact", "engineer_clear", "engineer_status", "engineer_metadata", "engineer_sessions", "engineer_runs", "git_diff", "git_commit", "git_reset", "approval_policy", "approval_decisions", "approval_update"];
|
|
15
15
|
type ToolPermission = 'allow' | 'ask' | 'deny';
|
|
16
16
|
type AgentPermission = {
|
|
17
17
|
'*'?: ToolPermission;
|
|
@@ -15,9 +15,8 @@ export const AGENT_ENGINEER_BUILD = 'engineer_build';
|
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
// Tool IDs — grouped by domain
|
|
17
17
|
// ---------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
const
|
|
20
|
-
'engineer_send',
|
|
18
|
+
/** Shared engineer session tools (compact, clear, status, diagnostics) */
|
|
19
|
+
const ENGINEER_SHARED_TOOL_IDS = [
|
|
21
20
|
'engineer_compact',
|
|
22
21
|
'engineer_clear',
|
|
23
22
|
'engineer_status',
|
|
@@ -25,6 +24,23 @@ const ENGINEER_TOOL_IDS = [
|
|
|
25
24
|
'engineer_sessions',
|
|
26
25
|
'engineer_runs',
|
|
27
26
|
];
|
|
27
|
+
/** All engineer tools — generic send + mode-locked sends + shared session tools */
|
|
28
|
+
const ENGINEER_TOOL_IDS = [
|
|
29
|
+
'engineer_send',
|
|
30
|
+
'engineer_send_plan',
|
|
31
|
+
'engineer_send_build',
|
|
32
|
+
...ENGINEER_SHARED_TOOL_IDS,
|
|
33
|
+
];
|
|
34
|
+
/** Tools for the engineer_plan wrapper (plan-mode send + shared) */
|
|
35
|
+
const ENGINEER_PLAN_TOOL_IDS = [
|
|
36
|
+
'engineer_send_plan',
|
|
37
|
+
...ENGINEER_SHARED_TOOL_IDS,
|
|
38
|
+
];
|
|
39
|
+
/** Tools for the engineer_build wrapper (build-mode send + shared) */
|
|
40
|
+
const ENGINEER_BUILD_TOOL_IDS = [
|
|
41
|
+
'engineer_send_build',
|
|
42
|
+
...ENGINEER_SHARED_TOOL_IDS,
|
|
43
|
+
];
|
|
28
44
|
/** Git tools — owned by CTO */
|
|
29
45
|
const GIT_TOOL_IDS = ['git_diff', 'git_commit', 'git_reset'];
|
|
30
46
|
/** Approval tools — owned by CTO */
|
|
@@ -82,14 +98,30 @@ function buildCtoPermissions() {
|
|
|
82
98
|
},
|
|
83
99
|
};
|
|
84
100
|
}
|
|
85
|
-
/** Engineer wrapper:
|
|
86
|
-
function
|
|
101
|
+
/** Engineer plan wrapper: engineer_send_plan + shared session tools. */
|
|
102
|
+
function buildEngineerPlanPermissions() {
|
|
103
|
+
const denied = {};
|
|
104
|
+
for (const toolId of ALL_RESTRICTED_TOOL_IDS) {
|
|
105
|
+
denied[toolId] = 'deny';
|
|
106
|
+
}
|
|
107
|
+
const allowed = {};
|
|
108
|
+
for (const toolId of ENGINEER_PLAN_TOOL_IDS) {
|
|
109
|
+
allowed[toolId] = 'allow';
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
'*': 'deny',
|
|
113
|
+
...denied,
|
|
114
|
+
...allowed,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Engineer build wrapper: engineer_send_build + shared session tools. */
|
|
118
|
+
function buildEngineerBuildPermissions() {
|
|
87
119
|
const denied = {};
|
|
88
120
|
for (const toolId of ALL_RESTRICTED_TOOL_IDS) {
|
|
89
121
|
denied[toolId] = 'deny';
|
|
90
122
|
}
|
|
91
123
|
const allowed = {};
|
|
92
|
-
for (const toolId of
|
|
124
|
+
for (const toolId of ENGINEER_BUILD_TOOL_IDS) {
|
|
93
125
|
allowed[toolId] = 'allow';
|
|
94
126
|
}
|
|
95
127
|
return {
|
|
@@ -115,7 +147,7 @@ export function buildEngineerPlanAgentConfig(prompts) {
|
|
|
115
147
|
description: 'Engineer that manages a Claude Code session in plan mode for read-only investigation and analysis.',
|
|
116
148
|
mode: 'subagent',
|
|
117
149
|
color: '#D97757',
|
|
118
|
-
permission:
|
|
150
|
+
permission: buildEngineerPlanPermissions(),
|
|
119
151
|
prompt: prompts.engineerPlanPrompt,
|
|
120
152
|
};
|
|
121
153
|
}
|
|
@@ -124,7 +156,7 @@ export function buildEngineerBuildAgentConfig(prompts) {
|
|
|
124
156
|
description: 'Engineer that manages a Claude Code session in free mode for implementation and execution.',
|
|
125
157
|
mode: 'subagent',
|
|
126
158
|
color: '#D97757',
|
|
127
|
-
permission:
|
|
159
|
+
permission: buildEngineerBuildPermissions(),
|
|
128
160
|
prompt: prompts.engineerBuildPrompt,
|
|
129
161
|
};
|
|
130
162
|
}
|
|
@@ -4,6 +4,194 @@ import { AGENT_CTO, AGENT_ENGINEER_BUILD, AGENT_ENGINEER_PLAN, buildCtoAgentConf
|
|
|
4
4
|
import { getOrCreatePluginServices } from './service-factory.js';
|
|
5
5
|
export const ClaudeManagerPlugin = async ({ worktree }) => {
|
|
6
6
|
const services = getOrCreatePluginServices(worktree);
|
|
7
|
+
async function executeEngineerSend(args, context) {
|
|
8
|
+
const cwd = args.cwd ?? context.worktree;
|
|
9
|
+
if (args.freshSession) {
|
|
10
|
+
await services.manager.clearSession(cwd);
|
|
11
|
+
}
|
|
12
|
+
const hasActiveSession = services.manager.getStatus().sessionId !== null;
|
|
13
|
+
const promptPreview = args.message.length > 100
|
|
14
|
+
? args.message.slice(0, 100) + '...'
|
|
15
|
+
: args.message;
|
|
16
|
+
context.metadata({
|
|
17
|
+
title: hasActiveSession
|
|
18
|
+
? 'Claude Code: Resuming session...'
|
|
19
|
+
: 'Claude Code: Initializing...',
|
|
20
|
+
metadata: {
|
|
21
|
+
sessionId: services.manager.getStatus().sessionId,
|
|
22
|
+
prompt: promptPreview,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
let turnsSoFar = 0;
|
|
26
|
+
let costSoFar = 0;
|
|
27
|
+
const result = await services.manager.sendMessage(cwd, args.message, {
|
|
28
|
+
model: args.model,
|
|
29
|
+
effort: args.effort,
|
|
30
|
+
mode: args.mode,
|
|
31
|
+
abortSignal: context.abort,
|
|
32
|
+
}, (event) => {
|
|
33
|
+
if (event.turns !== undefined) {
|
|
34
|
+
turnsSoFar = event.turns;
|
|
35
|
+
}
|
|
36
|
+
if (event.totalCostUsd !== undefined) {
|
|
37
|
+
costSoFar = event.totalCostUsd;
|
|
38
|
+
}
|
|
39
|
+
const costLabel = `$${costSoFar.toFixed(4)}`;
|
|
40
|
+
if (event.type === 'tool_call') {
|
|
41
|
+
let toolName = 'tool';
|
|
42
|
+
let inputPreview = '';
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(event.text);
|
|
45
|
+
toolName = parsed.name ?? 'tool';
|
|
46
|
+
if (parsed.input) {
|
|
47
|
+
const inputStr = typeof parsed.input === 'string'
|
|
48
|
+
? parsed.input
|
|
49
|
+
: JSON.stringify(parsed.input);
|
|
50
|
+
inputPreview =
|
|
51
|
+
inputStr.length > 150
|
|
52
|
+
? inputStr.slice(0, 150) + '...'
|
|
53
|
+
: inputStr;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore parse errors
|
|
58
|
+
}
|
|
59
|
+
context.metadata({
|
|
60
|
+
title: `Claude Code: Running ${toolName}... (${turnsSoFar} turns, ${costLabel})`,
|
|
61
|
+
metadata: {
|
|
62
|
+
sessionId: event.sessionId,
|
|
63
|
+
type: event.type,
|
|
64
|
+
tool: toolName,
|
|
65
|
+
input: inputPreview,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else if (event.type === 'assistant') {
|
|
70
|
+
const thinkingPreview = event.text.length > 150
|
|
71
|
+
? event.text.slice(0, 150) + '...'
|
|
72
|
+
: event.text;
|
|
73
|
+
context.metadata({
|
|
74
|
+
title: `Claude Code: Thinking... (${turnsSoFar} turns, ${costLabel})`,
|
|
75
|
+
metadata: {
|
|
76
|
+
sessionId: event.sessionId,
|
|
77
|
+
type: event.type,
|
|
78
|
+
thinking: thinkingPreview,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (event.type === 'init') {
|
|
83
|
+
context.metadata({
|
|
84
|
+
title: `Claude Code: Session started`,
|
|
85
|
+
metadata: {
|
|
86
|
+
sessionId: event.sessionId,
|
|
87
|
+
prompt: promptPreview,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else if (event.type === 'user') {
|
|
92
|
+
const preview = event.text.length > 200
|
|
93
|
+
? event.text.slice(0, 200) + '...'
|
|
94
|
+
: event.text;
|
|
95
|
+
context.metadata({
|
|
96
|
+
title: `Claude Code: Tool result (${turnsSoFar} turns, ${costLabel})`,
|
|
97
|
+
metadata: {
|
|
98
|
+
sessionId: event.sessionId,
|
|
99
|
+
type: event.type,
|
|
100
|
+
output: preview,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else if (event.type === 'tool_progress') {
|
|
105
|
+
let toolName = 'tool';
|
|
106
|
+
let elapsed = 0;
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(event.text);
|
|
109
|
+
toolName = parsed.name ?? 'tool';
|
|
110
|
+
elapsed = parsed.elapsed ?? 0;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// ignore
|
|
114
|
+
}
|
|
115
|
+
context.metadata({
|
|
116
|
+
title: `Claude Code: ${toolName} running ${elapsed > 0 ? `(${elapsed.toFixed(0)}s)` : ''}... (${turnsSoFar} turns, ${costLabel})`,
|
|
117
|
+
metadata: {
|
|
118
|
+
sessionId: event.sessionId,
|
|
119
|
+
type: event.type,
|
|
120
|
+
tool: toolName,
|
|
121
|
+
elapsed,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else if (event.type === 'tool_summary') {
|
|
126
|
+
const summary = event.text.length > 200
|
|
127
|
+
? event.text.slice(0, 200) + '...'
|
|
128
|
+
: event.text;
|
|
129
|
+
context.metadata({
|
|
130
|
+
title: `Claude Code: Tool done (${turnsSoFar} turns, ${costLabel})`,
|
|
131
|
+
metadata: {
|
|
132
|
+
sessionId: event.sessionId,
|
|
133
|
+
type: event.type,
|
|
134
|
+
summary,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (event.type === 'partial') {
|
|
139
|
+
const delta = event.text.length > 200
|
|
140
|
+
? event.text.slice(0, 200) + '...'
|
|
141
|
+
: event.text;
|
|
142
|
+
context.metadata({
|
|
143
|
+
title: `Claude Code: Writing... (${turnsSoFar} turns, ${costLabel})`,
|
|
144
|
+
metadata: {
|
|
145
|
+
sessionId: event.sessionId,
|
|
146
|
+
type: event.type,
|
|
147
|
+
delta,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else if (event.type === 'error') {
|
|
152
|
+
context.metadata({
|
|
153
|
+
title: `Claude Code: Error`,
|
|
154
|
+
metadata: {
|
|
155
|
+
sessionId: event.sessionId,
|
|
156
|
+
error: event.text.slice(0, 200),
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const costLabel = `$${(result.totalCostUsd ?? 0).toFixed(4)}`;
|
|
162
|
+
const turns = result.turns ?? 0;
|
|
163
|
+
const contextWarning = formatContextWarning(result.context);
|
|
164
|
+
if (contextWarning) {
|
|
165
|
+
context.metadata({
|
|
166
|
+
title: `Claude Code: Context at ${result.context.estimatedContextPercent}% (${turns} turns)`,
|
|
167
|
+
metadata: { sessionId: result.sessionId, contextWarning },
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
context.metadata({
|
|
172
|
+
title: `Claude Code: Complete (${turns} turns, ${costLabel})`,
|
|
173
|
+
metadata: { sessionId: result.sessionId },
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
let toolOutputs = [];
|
|
177
|
+
if (result.sessionId) {
|
|
178
|
+
try {
|
|
179
|
+
toolOutputs = await services.liveTailer.getToolOutputPreview(result.sessionId, cwd, 3);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Non-critical — the JSONL file may not exist yet.
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return JSON.stringify({
|
|
186
|
+
sessionId: result.sessionId,
|
|
187
|
+
finalText: result.finalText,
|
|
188
|
+
turns: result.turns,
|
|
189
|
+
totalCostUsd: result.totalCostUsd,
|
|
190
|
+
context: result.context,
|
|
191
|
+
contextWarning,
|
|
192
|
+
toolOutputs: toolOutputs.length > 0 ? toolOutputs : undefined,
|
|
193
|
+
}, null, 2);
|
|
194
|
+
}
|
|
7
195
|
return {
|
|
8
196
|
config: async (config) => {
|
|
9
197
|
config.agent ??= {};
|
|
@@ -15,12 +203,49 @@ export const ClaudeManagerPlugin = async ({ worktree }) => {
|
|
|
15
203
|
},
|
|
16
204
|
tool: {
|
|
17
205
|
engineer_send: tool({
|
|
18
|
-
description: 'Send a message to the persistent Claude Code session. ' +
|
|
206
|
+
description: 'Send a message to the persistent Claude Code session with explicit mode control. ' +
|
|
207
|
+
'Most agents should use engineer_send_plan or engineer_send_build instead.',
|
|
208
|
+
args: {
|
|
209
|
+
message: tool.schema.string().min(1),
|
|
210
|
+
model: tool.schema
|
|
211
|
+
.enum(['claude-opus-4-6', 'claude-sonnet-4-6', 'claude-sonnet-4-5'])
|
|
212
|
+
.optional(),
|
|
213
|
+
effort: tool.schema
|
|
214
|
+
.enum(['low', 'medium', 'high', 'max'])
|
|
215
|
+
.default('high'),
|
|
216
|
+
mode: tool.schema.enum(['plan', 'free']).default('free'),
|
|
217
|
+
freshSession: tool.schema.boolean().default(false),
|
|
218
|
+
cwd: tool.schema.string().optional(),
|
|
219
|
+
},
|
|
220
|
+
async execute(args, context) {
|
|
221
|
+
return executeEngineerSend(args, context);
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
engineer_send_plan: tool({
|
|
225
|
+
description: 'Send a read-only investigation message to the Claude Code session in plan mode. ' +
|
|
226
|
+
'The engineer will analyze code without making edits. ' +
|
|
227
|
+
'Auto-creates a session on first call. Resumes the existing session on subsequent calls. ' +
|
|
228
|
+
'Returns the assistant response and current context health snapshot.',
|
|
229
|
+
args: {
|
|
230
|
+
message: tool.schema.string().min(1),
|
|
231
|
+
model: tool.schema
|
|
232
|
+
.enum(['claude-opus-4-6', 'claude-sonnet-4-6', 'claude-sonnet-4-5'])
|
|
233
|
+
.optional(),
|
|
234
|
+
effort: tool.schema
|
|
235
|
+
.enum(['low', 'medium', 'high', 'max'])
|
|
236
|
+
.default('high'),
|
|
237
|
+
freshSession: tool.schema.boolean().default(false),
|
|
238
|
+
cwd: tool.schema.string().optional(),
|
|
239
|
+
},
|
|
240
|
+
async execute(args, context) {
|
|
241
|
+
return executeEngineerSend({ ...args, mode: 'plan' }, context);
|
|
242
|
+
},
|
|
243
|
+
}),
|
|
244
|
+
engineer_send_build: tool({
|
|
245
|
+
description: 'Send an implementation message to the Claude Code session in free mode. ' +
|
|
246
|
+
'The engineer can read, edit, and create files. ' +
|
|
19
247
|
'Auto-creates a session on first call. Resumes the existing session on subsequent calls. ' +
|
|
20
248
|
'Returns the assistant response and current context health snapshot. ' +
|
|
21
|
-
'Use mode "plan" for read-only investigation and planning (no edits), ' +
|
|
22
|
-
'or "free" (default) for normal execution with edit permissions. ' +
|
|
23
|
-
'Set freshSession to clear the active session before sending (use for unrelated tasks). ' +
|
|
24
249
|
'Prefer claude-opus-4-6 (default) for most coding work; use a Sonnet model for faster/lighter tasks. ' +
|
|
25
250
|
'Prefer effort "high" (default) for most work; use "medium" for lighter tasks and "max" for especially hard problems.',
|
|
26
251
|
args: {
|
|
@@ -31,198 +256,11 @@ export const ClaudeManagerPlugin = async ({ worktree }) => {
|
|
|
31
256
|
effort: tool.schema
|
|
32
257
|
.enum(['low', 'medium', 'high', 'max'])
|
|
33
258
|
.default('high'),
|
|
34
|
-
mode: tool.schema.enum(['plan', 'free']).default('free'),
|
|
35
259
|
freshSession: tool.schema.boolean().default(false),
|
|
36
260
|
cwd: tool.schema.string().optional(),
|
|
37
261
|
},
|
|
38
262
|
async execute(args, context) {
|
|
39
|
-
|
|
40
|
-
if (args.freshSession) {
|
|
41
|
-
await services.manager.clearSession(cwd);
|
|
42
|
-
}
|
|
43
|
-
const hasActiveSession = services.manager.getStatus().sessionId !== null;
|
|
44
|
-
const promptPreview = args.message.length > 100
|
|
45
|
-
? args.message.slice(0, 100) + '...'
|
|
46
|
-
: args.message;
|
|
47
|
-
context.metadata({
|
|
48
|
-
title: hasActiveSession
|
|
49
|
-
? 'Claude Code: Resuming session...'
|
|
50
|
-
: 'Claude Code: Initializing...',
|
|
51
|
-
metadata: {
|
|
52
|
-
sessionId: services.manager.getStatus().sessionId,
|
|
53
|
-
prompt: promptPreview,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
let turnsSoFar = 0;
|
|
57
|
-
let costSoFar = 0;
|
|
58
|
-
const result = await services.manager.sendMessage(cwd, args.message, {
|
|
59
|
-
model: args.model,
|
|
60
|
-
effort: args.effort,
|
|
61
|
-
mode: args.mode,
|
|
62
|
-
abortSignal: context.abort,
|
|
63
|
-
}, (event) => {
|
|
64
|
-
if (event.turns !== undefined) {
|
|
65
|
-
turnsSoFar = event.turns;
|
|
66
|
-
}
|
|
67
|
-
if (event.totalCostUsd !== undefined) {
|
|
68
|
-
costSoFar = event.totalCostUsd;
|
|
69
|
-
}
|
|
70
|
-
const costLabel = `$${costSoFar.toFixed(4)}`;
|
|
71
|
-
if (event.type === 'tool_call') {
|
|
72
|
-
let toolName = 'tool';
|
|
73
|
-
let inputPreview = '';
|
|
74
|
-
try {
|
|
75
|
-
const parsed = JSON.parse(event.text);
|
|
76
|
-
toolName = parsed.name ?? 'tool';
|
|
77
|
-
if (parsed.input) {
|
|
78
|
-
const inputStr = typeof parsed.input === 'string'
|
|
79
|
-
? parsed.input
|
|
80
|
-
: JSON.stringify(parsed.input);
|
|
81
|
-
inputPreview =
|
|
82
|
-
inputStr.length > 150
|
|
83
|
-
? inputStr.slice(0, 150) + '...'
|
|
84
|
-
: inputStr;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
// ignore parse errors
|
|
89
|
-
}
|
|
90
|
-
context.metadata({
|
|
91
|
-
title: `Claude Code: Running ${toolName}... (${turnsSoFar} turns, ${costLabel})`,
|
|
92
|
-
metadata: {
|
|
93
|
-
sessionId: event.sessionId,
|
|
94
|
-
type: event.type,
|
|
95
|
-
tool: toolName,
|
|
96
|
-
input: inputPreview,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else if (event.type === 'assistant') {
|
|
101
|
-
const thinkingPreview = event.text.length > 150
|
|
102
|
-
? event.text.slice(0, 150) + '...'
|
|
103
|
-
: event.text;
|
|
104
|
-
context.metadata({
|
|
105
|
-
title: `Claude Code: Thinking... (${turnsSoFar} turns, ${costLabel})`,
|
|
106
|
-
metadata: {
|
|
107
|
-
sessionId: event.sessionId,
|
|
108
|
-
type: event.type,
|
|
109
|
-
thinking: thinkingPreview,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if (event.type === 'init') {
|
|
114
|
-
context.metadata({
|
|
115
|
-
title: `Claude Code: Session started`,
|
|
116
|
-
metadata: {
|
|
117
|
-
sessionId: event.sessionId,
|
|
118
|
-
prompt: promptPreview,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else if (event.type === 'user') {
|
|
123
|
-
const preview = event.text.length > 200
|
|
124
|
-
? event.text.slice(0, 200) + '...'
|
|
125
|
-
: event.text;
|
|
126
|
-
context.metadata({
|
|
127
|
-
title: `Claude Code: Tool result (${turnsSoFar} turns, ${costLabel})`,
|
|
128
|
-
metadata: {
|
|
129
|
-
sessionId: event.sessionId,
|
|
130
|
-
type: event.type,
|
|
131
|
-
output: preview,
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
else if (event.type === 'tool_progress') {
|
|
136
|
-
let toolName = 'tool';
|
|
137
|
-
let elapsed = 0;
|
|
138
|
-
try {
|
|
139
|
-
const parsed = JSON.parse(event.text);
|
|
140
|
-
toolName = parsed.name ?? 'tool';
|
|
141
|
-
elapsed = parsed.elapsed ?? 0;
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
// ignore
|
|
145
|
-
}
|
|
146
|
-
context.metadata({
|
|
147
|
-
title: `Claude Code: ${toolName} running ${elapsed > 0 ? `(${elapsed.toFixed(0)}s)` : ''}... (${turnsSoFar} turns, ${costLabel})`,
|
|
148
|
-
metadata: {
|
|
149
|
-
sessionId: event.sessionId,
|
|
150
|
-
type: event.type,
|
|
151
|
-
tool: toolName,
|
|
152
|
-
elapsed,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
else if (event.type === 'tool_summary') {
|
|
157
|
-
const summary = event.text.length > 200
|
|
158
|
-
? event.text.slice(0, 200) + '...'
|
|
159
|
-
: event.text;
|
|
160
|
-
context.metadata({
|
|
161
|
-
title: `Claude Code: Tool done (${turnsSoFar} turns, ${costLabel})`,
|
|
162
|
-
metadata: {
|
|
163
|
-
sessionId: event.sessionId,
|
|
164
|
-
type: event.type,
|
|
165
|
-
summary,
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
else if (event.type === 'partial') {
|
|
170
|
-
const delta = event.text.length > 200
|
|
171
|
-
? event.text.slice(0, 200) + '...'
|
|
172
|
-
: event.text;
|
|
173
|
-
context.metadata({
|
|
174
|
-
title: `Claude Code: Writing... (${turnsSoFar} turns, ${costLabel})`,
|
|
175
|
-
metadata: {
|
|
176
|
-
sessionId: event.sessionId,
|
|
177
|
-
type: event.type,
|
|
178
|
-
delta,
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
else if (event.type === 'error') {
|
|
183
|
-
context.metadata({
|
|
184
|
-
title: `Claude Code: Error`,
|
|
185
|
-
metadata: {
|
|
186
|
-
sessionId: event.sessionId,
|
|
187
|
-
error: event.text.slice(0, 200),
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
const costLabel = `$${(result.totalCostUsd ?? 0).toFixed(4)}`;
|
|
193
|
-
const turns = result.turns ?? 0;
|
|
194
|
-
const contextWarning = formatContextWarning(result.context);
|
|
195
|
-
if (contextWarning) {
|
|
196
|
-
context.metadata({
|
|
197
|
-
title: `Claude Code: Context at ${result.context.estimatedContextPercent}% (${turns} turns)`,
|
|
198
|
-
metadata: { sessionId: result.sessionId, contextWarning },
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
context.metadata({
|
|
203
|
-
title: `Claude Code: Complete (${turns} turns, ${costLabel})`,
|
|
204
|
-
metadata: { sessionId: result.sessionId },
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// Fetch recent tool output from the JSONL file for richer feedback.
|
|
208
|
-
let toolOutputs = [];
|
|
209
|
-
if (result.sessionId) {
|
|
210
|
-
try {
|
|
211
|
-
toolOutputs = await services.liveTailer.getToolOutputPreview(result.sessionId, cwd, 3);
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
// Non-critical — the JSONL file may not exist yet.
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return JSON.stringify({
|
|
218
|
-
sessionId: result.sessionId,
|
|
219
|
-
finalText: result.finalText,
|
|
220
|
-
turns: result.turns,
|
|
221
|
-
totalCostUsd: result.totalCostUsd,
|
|
222
|
-
context: result.context,
|
|
223
|
-
contextWarning,
|
|
224
|
-
toolOutputs: toolOutputs.length > 0 ? toolOutputs : undefined,
|
|
225
|
-
}, null, 2);
|
|
263
|
+
return executeEngineerSend({ ...args, mode: 'free' }, context);
|
|
226
264
|
},
|
|
227
265
|
}),
|
|
228
266
|
engineer_compact: tool({
|
package/dist/prompts/registry.js
CHANGED
|
@@ -1,84 +1,76 @@
|
|
|
1
1
|
export const managerPromptRegistry = {
|
|
2
2
|
ctoSystemPrompt: [
|
|
3
|
-
'You are
|
|
4
|
-
'You
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
'',
|
|
8
|
-
'
|
|
9
|
-
'',
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'-
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'',
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'1.
|
|
24
|
-
'2.
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'',
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'',
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'',
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'3. If correct: spawn `engineer_build` to run tests/lint/typecheck.',
|
|
54
|
-
'4. If tests pass: git_commit to checkpoint. Update the todo list.',
|
|
55
|
-
'5. If wrong: spawn `engineer_build` with a specific correction.',
|
|
56
|
-
' On second failure for the same issue: git_reset, then rewrite the prompt',
|
|
57
|
-
' incorporating lessons from both failures.',
|
|
3
|
+
'You are a cracked AI-native engineer who uses Claude Code better than anyone.',
|
|
4
|
+
'You build the right thing, with the right quality, on the first try.',
|
|
5
|
+
'',
|
|
6
|
+
'## Core principle: verification-first',
|
|
7
|
+
'Every delegation MUST include how to verify success.',
|
|
8
|
+
'Tests, expected outputs, lint/typecheck commands, or before/after behavior.',
|
|
9
|
+
'This is the single highest-leverage thing you do.',
|
|
10
|
+
'Never delegate without telling the engineer how to prove it worked.',
|
|
11
|
+
'',
|
|
12
|
+
'## Right-size your approach',
|
|
13
|
+
'Not every task needs a plan. Assess complexity, then act:',
|
|
14
|
+
'',
|
|
15
|
+
'**Simple tasks** (typo, rename, add a log line, one-file fix):',
|
|
16
|
+
' Skip investigation. Delegate directly with specific context.',
|
|
17
|
+
'',
|
|
18
|
+
'**Medium tasks** (bug fix, small feature, refactor one module):',
|
|
19
|
+
' Read the relevant code yourself. Understand the current state.',
|
|
20
|
+
' Then delegate with file paths, line numbers, patterns, and verification.',
|
|
21
|
+
'',
|
|
22
|
+
'**Complex tasks** (multi-file feature, architecture change, large refactor):',
|
|
23
|
+
' 1. Investigate: read code, grep for patterns, spawn `engineer_plan` to explore.',
|
|
24
|
+
' 2. If requirements are unclear, ask the user ONE specific question.',
|
|
25
|
+
' Prefer the question tool when discrete options exist.',
|
|
26
|
+
' 3. Write a plan to the todo list (todowrite). Share it with the user.',
|
|
27
|
+
' 4. Execute steps sequentially, committing after each.',
|
|
28
|
+
'',
|
|
29
|
+
'## How to delegate effectively',
|
|
30
|
+
'The engineer does not have your context. Every instruction must be self-contained.',
|
|
31
|
+
'Include:',
|
|
32
|
+
'- Exact files, functions, and line numbers to change.',
|
|
33
|
+
'- Current behavior and desired behavior.',
|
|
34
|
+
'- Code snippets showing the pattern or convention to follow.',
|
|
35
|
+
'- How to verify: "Run `npm test`, expect all green." or',
|
|
36
|
+
' "The function should return null instead of throwing."',
|
|
37
|
+
'',
|
|
38
|
+
'Bad: "Fix the auth bug"',
|
|
39
|
+
'Good: "In src/auth/session.ts, `validateToken` (line 42) throws on expired',
|
|
40
|
+
' tokens instead of returning null. Change it to return null.',
|
|
41
|
+
' Update the caller in src/routes/login.ts:87.',
|
|
42
|
+
' Follow the pattern in src/auth/refresh.ts:23.',
|
|
43
|
+
' Run `npm test -- --grep auth` to verify. All tests should pass."',
|
|
44
|
+
'',
|
|
45
|
+
'## Review every change',
|
|
46
|
+
'After each delegation:',
|
|
47
|
+
'1. git_diff — read the FULL diff. Check for unintended changes, missing tests,',
|
|
48
|
+
' style violations.',
|
|
49
|
+
'2. If correct: spawn `engineer_build` to run tests/lint/typecheck.',
|
|
50
|
+
'3. If tests pass: git_commit to checkpoint.',
|
|
51
|
+
'4. If wrong: spawn `engineer_build` with a specific correction.',
|
|
52
|
+
' On second failure: git_reset and rewrite the prompt from scratch.',
|
|
58
53
|
' Never send three corrections for the same problem.',
|
|
59
54
|
'',
|
|
60
|
-
'Then return to Phase 3 for the next plan step.',
|
|
61
|
-
'',
|
|
62
55
|
'## Engineers (via the Task tool)',
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
'-
|
|
67
|
-
' Use for: all code changes, test runs, validation, and fixes.',
|
|
56
|
+
'- `engineer_plan` — read-only investigation. Use for: exploring unfamiliar code,',
|
|
57
|
+
' mapping dependencies, analyzing impact, asking "how does X work?"',
|
|
58
|
+
'- `engineer_build` — implementation. Use for: all code changes, test runs, fixes.',
|
|
59
|
+
'- If steps are independent, spawn multiple engineers in parallel.',
|
|
68
60
|
'',
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
61
|
+
'## Context efficiency',
|
|
62
|
+
'- Use `engineer_plan` for broad exploration so your own context stays clean.',
|
|
63
|
+
'- When spawning engineers for unrelated tasks, tell them to use freshSession:true.',
|
|
64
|
+
'- Keep delegations focused — one concern per engineer invocation.',
|
|
73
65
|
'',
|
|
74
66
|
'## What you must NOT do',
|
|
75
|
-
'- Do NOT call any engineer_* tools directly. Use the Task tool
|
|
67
|
+
'- Do NOT call any engineer_* tools directly. Use the Task tool.',
|
|
76
68
|
'- Do NOT edit files or run bash commands yourself.',
|
|
77
|
-
'- Do NOT
|
|
78
|
-
'- Do NOT
|
|
69
|
+
'- Do NOT skip review — always git_diff after delegation.',
|
|
70
|
+
'- Do NOT delegate without verification criteria.',
|
|
79
71
|
'',
|
|
80
72
|
'## Tools reference',
|
|
81
|
-
'todowrite / todoread — track
|
|
73
|
+
'todowrite / todoread — track multi-step work',
|
|
82
74
|
'question — ask the user structured questions with options',
|
|
83
75
|
'git_diff — review all uncommitted changes',
|
|
84
76
|
'git_commit — stage all + commit',
|
|
@@ -95,113 +87,82 @@ export const managerPromptRegistry = {
|
|
|
95
87
|
'State the blocker, what you need, and a concrete suggestion to unblock.',
|
|
96
88
|
].join('\n'),
|
|
97
89
|
engineerPlanPrompt: [
|
|
98
|
-
'You manage a Claude Code engineer for read-only investigation
|
|
99
|
-
'You receive objectives from the CTO and operate the engineer session to fulfill them.',
|
|
90
|
+
'You manage a Claude Code engineer for read-only investigation.',
|
|
100
91
|
'',
|
|
101
92
|
'## Behavior',
|
|
102
|
-
'-
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
'- Send the objective to the engineer using engineer_send_plan.',
|
|
94
|
+
"- Return the engineer's response verbatim. Do not summarize.",
|
|
95
|
+
'- Use freshSession:true on engineer_send_plan when the task is unrelated to prior work.',
|
|
105
96
|
'',
|
|
106
97
|
'## Context management',
|
|
107
|
-
'
|
|
108
|
-
'-
|
|
109
|
-
'
|
|
110
|
-
'
|
|
111
|
-
'-
|
|
112
|
-
'-
|
|
113
|
-
'-
|
|
114
|
-
'',
|
|
115
|
-
'## Model and effort selection',
|
|
116
|
-
'Choose model and effort deliberately:',
|
|
117
|
-
'- claude-opus-4-6 + high effort: default for complex analysis.',
|
|
118
|
-
'- claude-sonnet-4-6 or claude-sonnet-4-5: lighter analysis tasks.',
|
|
119
|
-
'- effort "medium": acceptable for simple lookups or straightforward analysis.',
|
|
120
|
-
"- Do not use Haiku for this plugin's coding-agent role.",
|
|
121
|
-
'',
|
|
122
|
-
'## Diagnostics',
|
|
123
|
-
'- Use engineer_metadata to inspect repo Claude config when needed.',
|
|
124
|
-
'- Use engineer_sessions to review prior session transcripts.',
|
|
125
|
-
'- Use engineer_runs to review prior run records.',
|
|
98
|
+
'- Check engineer_status before sending.',
|
|
99
|
+
'- Under 50%: proceed. Over 70%: engineer_compact. Over 85%: engineer_clear.',
|
|
100
|
+
'',
|
|
101
|
+
'## Model selection',
|
|
102
|
+
'- claude-opus-4-6 + high: complex analysis (default).',
|
|
103
|
+
'- claude-sonnet-4-6: lighter analysis.',
|
|
104
|
+
'- effort "medium": simple lookups.',
|
|
126
105
|
'',
|
|
127
106
|
'## What you must NOT do',
|
|
128
107
|
'- Do NOT investigate on your own — no read, grep, glob, or web tools.',
|
|
129
108
|
'- Do NOT call git_*, approval_*, or any non-engineer tools.',
|
|
130
|
-
'- Do NOT add
|
|
109
|
+
'- Do NOT add commentary to the engineer response.',
|
|
131
110
|
].join('\n'),
|
|
132
111
|
engineerBuildPrompt: [
|
|
133
|
-
'You manage a Claude Code engineer for implementation
|
|
134
|
-
'You receive objectives from the CTO and operate the engineer session to fulfill them.',
|
|
112
|
+
'You manage a Claude Code engineer for implementation.',
|
|
135
113
|
'',
|
|
136
114
|
'## Behavior',
|
|
137
|
-
'-
|
|
138
|
-
|
|
139
|
-
|
|
115
|
+
'- Send the objective to the engineer using engineer_send_build.',
|
|
116
|
+
"- Return the engineer's response verbatim. Do not summarize.",
|
|
117
|
+
'- Use freshSession:true on engineer_send_build when the task is unrelated to prior work.',
|
|
140
118
|
'',
|
|
141
119
|
'## Context management',
|
|
142
|
-
'
|
|
143
|
-
'-
|
|
144
|
-
'
|
|
145
|
-
'
|
|
146
|
-
'-
|
|
147
|
-
'-
|
|
148
|
-
'-
|
|
149
|
-
'',
|
|
150
|
-
'## Model and effort selection',
|
|
151
|
-
'Choose model and effort deliberately:',
|
|
152
|
-
'- claude-opus-4-6 + high effort: default for most coding tasks.',
|
|
153
|
-
'- claude-sonnet-4-6 or claude-sonnet-4-5: faster/lighter work (simple renames,',
|
|
154
|
-
' formatting, test scaffolding).',
|
|
155
|
-
'- effort "medium": acceptable for lighter tasks that do not require deep reasoning.',
|
|
156
|
-
'- effort "max": reserve for unusually hard problems (complex refactors,',
|
|
157
|
-
' subtle concurrency bugs, large cross-cutting changes).',
|
|
158
|
-
"- Do not use Haiku for this plugin's coding-agent role.",
|
|
159
|
-
'',
|
|
160
|
-
'## Diagnostics',
|
|
161
|
-
'- Use engineer_metadata to inspect repo Claude config when needed.',
|
|
162
|
-
'- Use engineer_sessions to review prior session transcripts.',
|
|
163
|
-
'- Use engineer_runs to review prior run records.',
|
|
120
|
+
'- Check engineer_status before sending.',
|
|
121
|
+
'- Under 50%: proceed. Over 70%: engineer_compact. Over 85%: engineer_clear.',
|
|
122
|
+
'',
|
|
123
|
+
'## Model selection',
|
|
124
|
+
'- claude-opus-4-6 + high: most coding tasks (default).',
|
|
125
|
+
'- claude-sonnet-4-6: simple renames, formatting, scaffolding.',
|
|
126
|
+
'- effort "max": complex refactors, subtle bugs, cross-cutting changes.',
|
|
164
127
|
'',
|
|
165
128
|
'## What you must NOT do',
|
|
166
129
|
'- Do NOT investigate on your own — no read, grep, glob, or web tools.',
|
|
167
130
|
'- Do NOT call git_*, approval_*, or any non-engineer tools.',
|
|
168
|
-
'- Do NOT add
|
|
131
|
+
'- Do NOT add commentary to the engineer response.',
|
|
169
132
|
].join('\n'),
|
|
170
133
|
engineerSessionPrompt: [
|
|
171
|
-
'You are
|
|
172
|
-
'Treat each message as a precise instruction from the CTO.',
|
|
134
|
+
'You are an expert engineer. Execute instructions precisely.',
|
|
173
135
|
'',
|
|
174
|
-
'##
|
|
175
|
-
'- Execute
|
|
176
|
-
'- Be concise — no preamble, no restating the task.',
|
|
136
|
+
'## Rules',
|
|
137
|
+
'- Execute directly. No preamble, no restating the task.',
|
|
177
138
|
'- Prefer targeted file reads over reading entire files.',
|
|
178
|
-
'- Use
|
|
179
|
-
'',
|
|
180
|
-
'## Quality expectations',
|
|
139
|
+
'- Use subagents for independent parallel work.',
|
|
181
140
|
'- Follow existing repo conventions (naming, style, patterns).',
|
|
182
|
-
'- When creating or modifying code, consider edge cases and error handling.',
|
|
183
|
-
'- When modifying existing code, preserve surrounding style and structure.',
|
|
184
|
-
'- If asked to implement a feature, include relevant tests unless told otherwise.',
|
|
185
|
-
'- Run tests/lint/typecheck when instructed; report exact output on failure.',
|
|
186
141
|
'',
|
|
187
|
-
'##
|
|
142
|
+
'## Verification',
|
|
143
|
+
'- Always verify your own work before reporting done.',
|
|
144
|
+
'- Run tests, lint, or typecheck when the instruction says to.',
|
|
145
|
+
'- If no verification was specified, still run relevant tests if they exist.',
|
|
146
|
+
'- Report exact output on failure.',
|
|
147
|
+
'',
|
|
148
|
+
'## Git boundary — do NOT run:',
|
|
188
149
|
'git commit, git push, git reset, git checkout, git stash.',
|
|
189
|
-
'
|
|
150
|
+
'Git operations are handled externally.',
|
|
190
151
|
'',
|
|
191
152
|
'## Reporting',
|
|
192
|
-
'- End with
|
|
193
|
-
'- Report blockers immediately with specifics: file, line, error
|
|
194
|
-
'- If
|
|
153
|
+
'- End with: what was done, what was verified, what passed/failed.',
|
|
154
|
+
'- Report blockers immediately with specifics: file, line, error.',
|
|
155
|
+
'- If partially complete, state exactly what remains.',
|
|
195
156
|
].join('\n'),
|
|
196
157
|
modePrefixes: {
|
|
197
158
|
plan: [
|
|
198
|
-
'[PLAN MODE]
|
|
199
|
-
'Do NOT use ExitPlanMode or write
|
|
159
|
+
'[PLAN MODE] Read-only. Do NOT create or edit any files.',
|
|
160
|
+
'Do NOT use ExitPlanMode or write artifacts to disk.',
|
|
200
161
|
'Use read, grep, glob, and search tools only.',
|
|
201
162
|
'Analyze the codebase and produce a detailed implementation plan:',
|
|
202
163
|
'files to change, functions to modify, new files to create, test strategy,',
|
|
203
|
-
'and
|
|
204
|
-
'Return the entire plan inline in your response
|
|
164
|
+
'and risks. End with a numbered step-by-step plan.',
|
|
165
|
+
'Return the entire plan inline in your response.',
|
|
205
166
|
].join(' '),
|
|
206
167
|
free: '',
|
|
207
168
|
},
|