claude-code-session-manager 0.132.0 → 0.133.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/README.md +3 -3
- package/dist/assets/{AgentLibrary-C09MlPFx.js → AgentLibrary-DOAG-mcG.js} +1 -1
- package/dist/assets/{AppSettings-DvDKsCnD.js → AppSettings-BHKM_AKh.js} +2 -2
- package/dist/assets/{Button-BzG_KdBC.js → Button-CmO1wmPw.js} +1 -1
- package/dist/assets/{DocumentEditorPane-fm6zsnLM.js → DocumentEditorPane-8QMNrNRt.js} +1 -1
- package/dist/assets/{Extensions-DgxKT_OZ.js → Extensions-Boo21B3b.js} +2 -2
- package/dist/assets/{History-Nd3bKjBq.js → History-C4epd1hp.js} +1 -1
- package/dist/assets/{Library-R71t6VAB.js → Library-CrgzRQzL.js} +1 -1
- package/dist/assets/{ListDetail-CG50Ul7c.js → ListDetail-DA7y1DQ-.js} +1 -1
- package/dist/assets/{Panel-C7EFG4eU.js → Panel-D-WMBhKH.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-J92iNEGC.js → ProjectClaudeConfig-CuUADpIu.js} +1 -1
- package/dist/assets/{ProvenanceBadge-C3KB3ILO.js → ProvenanceBadge-B7AsoRk6.js} +1 -1
- package/dist/assets/{Scheduler-DeYBA7uc.js → Scheduler-C86gRh51.js} +1 -1
- package/dist/assets/{Settings-B6r7N4v-.js → Settings-B4Q9DwVS.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-D7bt3fyB.js → SkillReferenceGraph-DX4ZgvlY.js} +1 -1
- package/dist/assets/{Skills-GpxtUrFP.js → Skills-DqKI37yi.js} +1 -1
- package/dist/assets/{SourceChip-uyVMCZc7.js → SourceChip-C974LROr.js} +1 -1
- package/dist/assets/{SystemPrompt-Cv25uFSM.js → SystemPrompt-C502jIwO.js} +1 -1
- package/dist/assets/{TiptapBody-uP8fJkbM.js → TiptapBody-DwNXN6Ki.js} +1 -1
- package/dist/assets/{Toggle-DRs80cX-.js → Toggle-C2OsxnPK.js} +1 -1
- package/dist/assets/{ViewTabs-BDkvvzJ8.js → ViewTabs-DBxKGbAK.js} +1 -1
- package/dist/assets/{VoiceButton-Cmtz2sQt.js → VoiceButton-C680wpmX.js} +1 -1
- package/dist/assets/{historyTotals-DHwAXunq.js → historyTotals-Cz-VYPEc.js} +1 -1
- package/dist/assets/{index-oXqzajWV.css → index-CMwAikUb.css} +1 -1
- package/dist/assets/index-Dh5geJe3.js +3111 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +427 -413
- package/package.json +1 -1
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +77 -14
- package/src/main/index.cjs +13 -0
- package/src/main/ipcSchemas.cjs +54 -0
- package/src/main/lib/CLAUDE.md +2 -0
- package/src/main/lib/agent-cli/adapters/antigravity.cjs +147 -0
- package/src/main/lib/agent-cli/adapters/codex.cjs +170 -0
- package/src/main/lib/agent-cli/adapters/cursor.cjs +138 -0
- package/src/main/lib/agent-cli/adapters/gemini.cjs +119 -0
- package/src/main/lib/agent-cli/adapters/opencode.cjs +117 -0
- package/src/main/lib/agent-cli/agentCliEvents.cjs +94 -0
- package/src/main/lib/agent-cli/agentCliIpc.cjs +109 -0
- package/src/main/lib/agent-cli/agentCliRegistry.cjs +213 -0
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +152 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +99 -0
- package/src/main/lib/app-preview/appPreviewIpc.cjs +125 -0
- package/src/main/lib/app-preview/appPreviewManager.cjs +317 -0
- package/src/main/lib/app-preview/appPreviewScripts.cjs +106 -0
- package/src/main/lib/app-preview/appPreviewSweep.cjs +92 -0
- package/src/main/lib/chatBootRecovery.cjs +41 -1
- package/src/main/lib/claude/agentEffortResolve.cjs +11 -3
- package/src/main/lib/epic/activeIndexMerge.cjs +25 -2
- package/src/main/lib/epic/archivedTranscript.cjs +39 -6
- package/src/main/lib/epic/epicChanges.cjs +466 -0
- package/src/main/lib/epic/epicMint.cjs +45 -1
- package/src/main/lib/epic/epicReopen.cjs +8 -2
- package/src/main/lib/epic/epicSpawnPlan.cjs +12 -0
- package/src/main/lib/epic/epicWorktreeMerge.cjs +39 -4
- package/src/main/lib/epic/promptSessionsCreateEpic.cjs +9 -4
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
- package/src/main/lib/git/gitExec.cjs +9 -1
- package/src/main/lib/git/gitWorktree.cjs +94 -0
- package/src/main/lib/git/unifiedDiff.cjs +207 -0
- package/src/main/lib/mdDocCensus.cjs +364 -0
- package/src/main/lib/mdDocRefs.cjs +249 -0
- package/src/main/lib/mdNetworkScan.cjs +158 -15
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +4 -1
- package/src/main/lib/persona-macro/macroJobIpc.cjs +1 -1
- package/src/main/lib/prd/prdCreate.cjs +7 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +10 -3
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/remoteTranscriptTail.cjs +23 -4
- package/src/main/lib/scheduler/landedSinceRun.cjs +2 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +3 -0
- package/src/main/projectPages.cjs +14 -3
- package/src/main/scheduler/gitTreeGuard.cjs +2 -1
- package/src/main/scheduler/prdParser.cjs +2 -1
- package/src/main/scheduler.cjs +7 -2
- package/src/main/transcripts.cjs +18 -4
- package/src/main/webRemote.cjs +10 -5
- package/src/preload/api.d.ts +147 -2
- package/src/preload/apiSurface.json +56 -0
- package/src/preload/index.cjs +22 -0
- package/dist/assets/index-CBCdyHbZ.js +0 -3097
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// OpenAI Codex CLI (0.168) adapter: builds headless/interactive argv and
|
|
3
|
+
// translates `codex exec --json` JSONL into the Claude stream-json events
|
|
4
|
+
// from ../agentCliEvents.cjs. Pure module — spawning is the caller's job.
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
initEvent, textEvent, toolUseEvent, toolResultEvent, resultEvent, safeJsonLine,
|
|
8
|
+
} = require('../agentCliEvents.cjs');
|
|
9
|
+
|
|
10
|
+
const BYPASS = '--dangerously-bypass-approvals-and-sandbox';
|
|
11
|
+
|
|
12
|
+
function modelArgs(model) {
|
|
13
|
+
return typeof model === 'string' && model ? ['-m', model] : [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function hasId(id) {
|
|
17
|
+
return typeof id === 'string' && id.length > 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function headlessSpawn({ prompt, nativeSessionId, model } = {}) {
|
|
21
|
+
const head = hasId(nativeSessionId) ? ['exec', 'resume', nativeSessionId] : ['exec'];
|
|
22
|
+
return {
|
|
23
|
+
args: [...head, '--json', BYPASS, '--skip-git-repo-check', ...modelArgs(model), '-'],
|
|
24
|
+
stdin: prompt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function interactiveArgs({ nativeSessionId, model } = {}) {
|
|
29
|
+
const head = hasId(nativeSessionId) ? ['resume', nativeSessionId] : [];
|
|
30
|
+
return [...head, BYPASS, ...modelArgs(model)];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
34
|
+
|
|
35
|
+
// Per item type: the Claude tool name + input, and the tool_result on completion.
|
|
36
|
+
const TOOL_ITEMS = {
|
|
37
|
+
command_execution: {
|
|
38
|
+
use: (it) => ({ name: 'Bash', input: { command: str(it.command) ?? '' } }),
|
|
39
|
+
result: (it) => ({
|
|
40
|
+
content: str(it.aggregated_output) ?? '',
|
|
41
|
+
isError: (typeof it.exit_code === 'number' && it.exit_code !== 0) || it.status === 'failed',
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
file_change: {
|
|
45
|
+
use: (it) => ({ name: 'Edit', input: { changes: Array.isArray(it.changes) ? it.changes : [] } }),
|
|
46
|
+
result: () => ({ content: 'ok', isError: false }),
|
|
47
|
+
},
|
|
48
|
+
mcp_tool_call: {
|
|
49
|
+
use: (it) => ({
|
|
50
|
+
name: `mcp__${str(it.server) ?? 'unknown'}__${str(it.tool) ?? 'unknown'}`,
|
|
51
|
+
input: it.arguments && typeof it.arguments === 'object' ? it.arguments : {},
|
|
52
|
+
}),
|
|
53
|
+
result: (it) => {
|
|
54
|
+
const errMsg = str(it.error?.message) ?? str(it.error);
|
|
55
|
+
if (errMsg || it.status === 'failed') return { content: errMsg ?? 'failed', isError: true };
|
|
56
|
+
return { content: it.result ?? 'ok', isError: false };
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
web_search: {
|
|
60
|
+
use: (it) => ({ name: 'WebSearch', input: { query: str(it.query) ?? '' } }),
|
|
61
|
+
result: () => ({ content: 'ok', isError: false }),
|
|
62
|
+
},
|
|
63
|
+
todo_list: {
|
|
64
|
+
use: (it) => ({ name: 'TodoWrite', input: { todos: Array.isArray(it.items) ? it.items : [] } }),
|
|
65
|
+
result: () => ({ content: 'ok', isError: false }),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function createParser() {
|
|
70
|
+
let sessionId = null;
|
|
71
|
+
let resultEmitted = false;
|
|
72
|
+
let lastError = null;
|
|
73
|
+
const texts = [];
|
|
74
|
+
const startedIds = new Set();
|
|
75
|
+
|
|
76
|
+
function emitUse(it, spec, out) {
|
|
77
|
+
const { name, input } = spec.use(it);
|
|
78
|
+
out.push(toolUseEvent({ id: it.id, name, input }));
|
|
79
|
+
if (hasId(it.id)) startedIds.add(it.id);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function onItem(phase, it, out) {
|
|
83
|
+
if (!it || typeof it !== 'object') return;
|
|
84
|
+
if (it.type === 'agent_message') {
|
|
85
|
+
if (phase === 'completed' && typeof it.text === 'string') {
|
|
86
|
+
texts.push(it.text);
|
|
87
|
+
out.push(textEvent(it.text));
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const spec = TOOL_ITEMS[it.type];
|
|
92
|
+
if (!spec) return; // reasoning, error items, unknown types
|
|
93
|
+
if (phase === 'started') {
|
|
94
|
+
if (!(hasId(it.id) && startedIds.has(it.id))) emitUse(it, spec, out);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!(hasId(it.id) && startedIds.has(it.id))) emitUse(it, spec, out);
|
|
98
|
+
const { content, isError } = spec.result(it);
|
|
99
|
+
out.push(toolResultEvent({ toolUseId: it.id, content, isError }));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function handle(evt, out) {
|
|
103
|
+
switch (evt.type) {
|
|
104
|
+
case 'thread.started':
|
|
105
|
+
if (hasId(evt.thread_id)) {
|
|
106
|
+
sessionId = evt.thread_id;
|
|
107
|
+
out.push(initEvent(sessionId, 'codex'));
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
case 'item.started':
|
|
111
|
+
onItem('started', evt.item, out);
|
|
112
|
+
return;
|
|
113
|
+
case 'item.completed':
|
|
114
|
+
onItem('completed', evt.item, out);
|
|
115
|
+
return;
|
|
116
|
+
case 'turn.completed': {
|
|
117
|
+
if (resultEmitted) return;
|
|
118
|
+
resultEmitted = true;
|
|
119
|
+
const u = evt.usage && typeof evt.usage === 'object' ? evt.usage : {};
|
|
120
|
+
out.push(resultEvent({
|
|
121
|
+
ok: true,
|
|
122
|
+
text: texts.join('\n\n'),
|
|
123
|
+
usage: {
|
|
124
|
+
input_tokens: u.input_tokens,
|
|
125
|
+
output_tokens: u.output_tokens,
|
|
126
|
+
cache_read_input_tokens: u.cached_input_tokens,
|
|
127
|
+
},
|
|
128
|
+
nativeSessionId: sessionId ?? undefined,
|
|
129
|
+
}));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
case 'turn.failed':
|
|
133
|
+
if (resultEmitted) return;
|
|
134
|
+
resultEmitted = true;
|
|
135
|
+
out.push(resultEvent({
|
|
136
|
+
ok: false,
|
|
137
|
+
text: str(evt.error?.message) ?? 'codex turn failed',
|
|
138
|
+
nativeSessionId: sessionId ?? undefined,
|
|
139
|
+
}));
|
|
140
|
+
return;
|
|
141
|
+
case 'error':
|
|
142
|
+
lastError = str(evt.message) ?? 'codex error';
|
|
143
|
+
return;
|
|
144
|
+
default:
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
push(line) {
|
|
150
|
+
const out = [];
|
|
151
|
+
try {
|
|
152
|
+
const evt = safeJsonLine(line);
|
|
153
|
+
if (evt) handle(evt, out);
|
|
154
|
+
} catch {
|
|
155
|
+
// never throw from push; drop the line
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
},
|
|
159
|
+
end() {
|
|
160
|
+
if (resultEmitted || lastError === null) return [];
|
|
161
|
+
resultEmitted = true;
|
|
162
|
+
return [resultEvent({ ok: false, text: lastError, nativeSessionId: sessionId ?? undefined })];
|
|
163
|
+
},
|
|
164
|
+
nativeSessionId() {
|
|
165
|
+
return sessionId;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = { id: 'codex', headlessSpawn, createParser, interactiveArgs };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Cursor Agent CLI (`cursor-agent` / `agent`) adapter: builds print-mode argv
|
|
3
|
+
// and translates `--output-format stream-json` JSONL into the Claude
|
|
4
|
+
// stream-json events from ../agentCliEvents.cjs. The CLI documents no stdin
|
|
5
|
+
// prompt, so the prompt is the positional argument — guarded below Linux's
|
|
6
|
+
// MAX_ARG_STRLEN (131072 bytes). A failed stream may end without a terminal
|
|
7
|
+
// `result`; end() emits nothing and the runner's no-result fallback reports
|
|
8
|
+
// stderr. Pure module.
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
initEvent, textEvent, toolUseEvent, toolResultEvent, resultEvent, safeJsonLine,
|
|
12
|
+
} = require('../agentCliEvents.cjs');
|
|
13
|
+
|
|
14
|
+
const MAX_ARGV_PROMPT_BYTES = 120000;
|
|
15
|
+
const HEADLESS_FLAGS = ['--print', '--output-format', 'stream-json', '--force', '--trust'];
|
|
16
|
+
const TOOL_NAMES = Object.freeze({
|
|
17
|
+
readToolCall: 'Read',
|
|
18
|
+
writeToolCall: 'Write',
|
|
19
|
+
shellToolCall: 'Bash',
|
|
20
|
+
editToolCall: 'Edit',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const hasId = (id) => typeof id === 'string' && id.length > 0;
|
|
24
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
25
|
+
const resumeArgs = (id) => (hasId(id) ? ['--resume', id] : []);
|
|
26
|
+
const modelArgs = (model) => (typeof model === 'string' && model ? ['--model', model] : []);
|
|
27
|
+
|
|
28
|
+
function headlessSpawn({ prompt, nativeSessionId, model } = {}) {
|
|
29
|
+
const p = typeof prompt === 'string' ? prompt : '';
|
|
30
|
+
const bytes = Buffer.byteLength(p, 'utf8');
|
|
31
|
+
if (bytes > MAX_ARGV_PROMPT_BYTES) {
|
|
32
|
+
return {
|
|
33
|
+
error: `cursor prompt is ${bytes} bytes, over the ${MAX_ARGV_PROMPT_BYTES}-byte argv limit `
|
|
34
|
+
+ '(cursor-agent takes the prompt only as a command-line argument)',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
args: [...HEADLESS_FLAGS, ...resumeArgs(nativeSessionId), ...modelArgs(model), p],
|
|
39
|
+
stdin: '',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function interactiveArgs({ nativeSessionId, model } = {}) {
|
|
44
|
+
return ['--force', ...resumeArgs(nativeSessionId), ...modelArgs(model)];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function assistantText(message) {
|
|
48
|
+
if (!isObj(message) || !Array.isArray(message.content)) return '';
|
|
49
|
+
return message.content
|
|
50
|
+
.filter((b) => isObj(b) && b.type === 'text' && typeof b.text === 'string')
|
|
51
|
+
.map((b) => b.text)
|
|
52
|
+
.join('');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// tool_call is { <kindKey>: { args, result? } } or { function: { name, arguments } }.
|
|
56
|
+
function toolEntry(toolCall) {
|
|
57
|
+
if (!isObj(toolCall)) return null;
|
|
58
|
+
const key = Object.keys(toolCall)[0];
|
|
59
|
+
if (!key || !isObj(toolCall[key])) return null;
|
|
60
|
+
const body = toolCall[key];
|
|
61
|
+
if (key === 'function') {
|
|
62
|
+
return { name: typeof body.name === 'string' && body.name ? body.name : 'function', input: body.arguments, body };
|
|
63
|
+
}
|
|
64
|
+
return { name: TOOL_NAMES[key] ?? key, input: body.args, body };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createParser() {
|
|
68
|
+
let sessionId = null;
|
|
69
|
+
let resultEmitted = false;
|
|
70
|
+
const texts = [];
|
|
71
|
+
|
|
72
|
+
function handle(evt, out) {
|
|
73
|
+
switch (evt.type) {
|
|
74
|
+
case 'system':
|
|
75
|
+
if (evt.subtype === 'init' && hasId(evt.session_id)) {
|
|
76
|
+
sessionId = evt.session_id;
|
|
77
|
+
out.push(initEvent(sessionId, 'cursor'));
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
case 'assistant': {
|
|
81
|
+
const text = assistantText(evt.message);
|
|
82
|
+
if (text) {
|
|
83
|
+
texts.push(text);
|
|
84
|
+
out.push(textEvent(text));
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
case 'tool_call': {
|
|
89
|
+
const entry = toolEntry(evt.tool_call);
|
|
90
|
+
if (!entry) return;
|
|
91
|
+
if (evt.subtype === 'started') {
|
|
92
|
+
out.push(toolUseEvent({ id: evt.call_id, name: entry.name, input: entry.input }));
|
|
93
|
+
} else if (evt.subtype === 'completed') {
|
|
94
|
+
const r = isObj(entry.body.result) ? entry.body.result : {};
|
|
95
|
+
const isError = !!r.error;
|
|
96
|
+
const payload = isError ? r.error : r.success;
|
|
97
|
+
out.push(toolResultEvent({
|
|
98
|
+
toolUseId: evt.call_id,
|
|
99
|
+
content: JSON.stringify(payload ?? null),
|
|
100
|
+
isError,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case 'result': {
|
|
106
|
+
if (resultEmitted) return;
|
|
107
|
+
resultEmitted = true;
|
|
108
|
+
const ok = evt.subtype === 'success' && evt.is_error !== true;
|
|
109
|
+
const joined = texts.join('');
|
|
110
|
+
const text = joined || (typeof evt.result === 'string' ? evt.result : '');
|
|
111
|
+
out.push(resultEvent({ ok, text, nativeSessionId: sessionId ?? undefined }));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
default: // 'user' echoes the prompt; unknown types: dropped
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
push(line) {
|
|
120
|
+
const out = [];
|
|
121
|
+
try {
|
|
122
|
+
const evt = safeJsonLine(line);
|
|
123
|
+
if (evt) handle(evt, out);
|
|
124
|
+
} catch {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
},
|
|
129
|
+
end() {
|
|
130
|
+
return [];
|
|
131
|
+
},
|
|
132
|
+
nativeSessionId() {
|
|
133
|
+
return sessionId;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = { id: 'cursor', headlessSpawn, createParser, interactiveArgs, MAX_ARGV_PROMPT_BYTES };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Google Gemini CLI (0.68) adapter: builds headless/interactive argv and
|
|
3
|
+
// translates `--output-format stream-json` JSONL into the Claude stream-json
|
|
4
|
+
// events from ../agentCliEvents.cjs. Headless mode reads the prompt from a
|
|
5
|
+
// non-TTY stdin. Gemini accepts a caller-chosen session UUID, so the first
|
|
6
|
+
// turn passes the Epic's claudeSessionId as --session-id. Pure module.
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
initEvent, textEvent, toolUseEvent, toolResultEvent, resultEvent, safeJsonLine,
|
|
10
|
+
} = require('../agentCliEvents.cjs');
|
|
11
|
+
|
|
12
|
+
const YOLO = ['--approval-mode', 'yolo'];
|
|
13
|
+
const HEADLESS_FLAGS = ['--output-format', 'stream-json', ...YOLO, '--skip-trust'];
|
|
14
|
+
|
|
15
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
16
|
+
const hasId = (id) => typeof id === 'string' && id.length > 0;
|
|
17
|
+
const modelArgs = (model) => (typeof model === 'string' && model ? ['-m', model] : []);
|
|
18
|
+
|
|
19
|
+
function sessionArgs(nativeSessionId, claudeSessionId) {
|
|
20
|
+
if (hasId(nativeSessionId)) return ['--resume', nativeSessionId];
|
|
21
|
+
return hasId(claudeSessionId) ? ['--session-id', claudeSessionId] : [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function headlessSpawn({ prompt, nativeSessionId, claudeSessionId, model } = {}) {
|
|
25
|
+
return {
|
|
26
|
+
args: [...HEADLESS_FLAGS, ...sessionArgs(nativeSessionId, claudeSessionId), ...modelArgs(model)],
|
|
27
|
+
stdin: prompt,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function interactiveArgs({ nativeSessionId, claudeSessionId, model } = {}) {
|
|
32
|
+
return [...YOLO, ...sessionArgs(nativeSessionId, claudeSessionId), ...modelArgs(model)];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createParser() {
|
|
36
|
+
let sessionId = null;
|
|
37
|
+
let resultEmitted = false;
|
|
38
|
+
let lastError = null;
|
|
39
|
+
const texts = [];
|
|
40
|
+
|
|
41
|
+
function handle(evt, out) {
|
|
42
|
+
switch (evt.type) {
|
|
43
|
+
case 'init':
|
|
44
|
+
if (hasId(evt.session_id)) {
|
|
45
|
+
sessionId = evt.session_id;
|
|
46
|
+
out.push(initEvent(sessionId, 'gemini'));
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
case 'message':
|
|
50
|
+
if (evt.role === 'assistant' && typeof evt.content === 'string') {
|
|
51
|
+
texts.push(evt.content);
|
|
52
|
+
out.push(textEvent(evt.content));
|
|
53
|
+
}
|
|
54
|
+
return; // role 'user' echoes the prompt: dropped
|
|
55
|
+
case 'tool_use':
|
|
56
|
+
out.push(toolUseEvent({
|
|
57
|
+
id: evt.tool_id,
|
|
58
|
+
name: str(evt.tool_name) ?? 'unknown',
|
|
59
|
+
input: evt.parameters && typeof evt.parameters === 'object' ? evt.parameters : {},
|
|
60
|
+
}));
|
|
61
|
+
return;
|
|
62
|
+
case 'tool_result': {
|
|
63
|
+
const isError = evt.status === 'error';
|
|
64
|
+
const content = isError
|
|
65
|
+
? (str(evt.error?.message) ?? str(evt.output) ?? 'error')
|
|
66
|
+
: (evt.output ?? '');
|
|
67
|
+
out.push(toolResultEvent({ toolUseId: evt.tool_id, content, isError }));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case 'error':
|
|
71
|
+
lastError = str(evt.message) ?? 'gemini error';
|
|
72
|
+
return;
|
|
73
|
+
case 'result': {
|
|
74
|
+
if (resultEmitted) return;
|
|
75
|
+
resultEmitted = true;
|
|
76
|
+
const ok = evt.status === 'success';
|
|
77
|
+
const s = evt.stats && typeof evt.stats === 'object' ? evt.stats : {};
|
|
78
|
+
const text = ok
|
|
79
|
+
? texts.join('')
|
|
80
|
+
: (str(evt.error?.message) ?? lastError ?? 'gemini turn failed');
|
|
81
|
+
out.push(resultEvent({
|
|
82
|
+
ok,
|
|
83
|
+
text,
|
|
84
|
+
usage: {
|
|
85
|
+
input_tokens: s.input_tokens,
|
|
86
|
+
output_tokens: s.output_tokens,
|
|
87
|
+
cache_read_input_tokens: s.cached,
|
|
88
|
+
},
|
|
89
|
+
nativeSessionId: sessionId ?? undefined,
|
|
90
|
+
}));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
push(line) {
|
|
99
|
+
const out = [];
|
|
100
|
+
try {
|
|
101
|
+
const evt = safeJsonLine(line);
|
|
102
|
+
if (evt) handle(evt, out);
|
|
103
|
+
} catch {
|
|
104
|
+
// never throw from push; drop the line
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
},
|
|
108
|
+
end() {
|
|
109
|
+
if (resultEmitted || lastError === null) return [];
|
|
110
|
+
resultEmitted = true;
|
|
111
|
+
return [resultEvent({ ok: false, text: lastError, nativeSessionId: sessionId ?? undefined })];
|
|
112
|
+
},
|
|
113
|
+
nativeSessionId() {
|
|
114
|
+
return sessionId;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = { id: 'gemini', headlessSpawn, createParser, interactiveArgs };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// OpenCode (`opencode run`) adapter: builds argv for opencode 1.19 and
|
|
3
|
+
// translates `opencode run --format json` JSONL into the Claude stream-json
|
|
4
|
+
// events from ../agentCliEvents.cjs. The prompt goes over stdin (verified live
|
|
5
|
+
// on 1.19.5), so it never hits argv limits. OpenCode emits no terminal result
|
|
6
|
+
// event; end() synthesizes one from the last step_finish reason, the exit
|
|
7
|
+
// code, and any error event seen. Pure module.
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
initEvent, textEvent, toolUseEvent, toolResultEvent, resultEvent, safeJsonLine,
|
|
11
|
+
} = require('../agentCliEvents.cjs');
|
|
12
|
+
|
|
13
|
+
const HEADLESS_FLAGS = ['run', '--format', 'json', '--auto'];
|
|
14
|
+
|
|
15
|
+
const hasId = (id) => typeof id === 'string' && id.length > 0;
|
|
16
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
17
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : 0);
|
|
18
|
+
const sessionArgs = (id) => (hasId(id) ? ['--session', id] : []);
|
|
19
|
+
const modelArgs = (model) => (typeof model === 'string' && model ? ['--model', model] : []);
|
|
20
|
+
|
|
21
|
+
function headlessSpawn({ prompt, nativeSessionId, model } = {}) {
|
|
22
|
+
return {
|
|
23
|
+
args: [...HEADLESS_FLAGS, ...sessionArgs(nativeSessionId), ...modelArgs(model)],
|
|
24
|
+
stdin: typeof prompt === 'string' ? prompt : '',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function interactiveArgs({ nativeSessionId, model } = {}) {
|
|
29
|
+
return ['--auto', ...sessionArgs(nativeSessionId), ...modelArgs(model)];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function errorMessage(evt) {
|
|
33
|
+
if (typeof evt.message === 'string' && evt.message) return evt.message;
|
|
34
|
+
const err = isObj(evt.error) ? evt.error : {};
|
|
35
|
+
if (isObj(err.data) && typeof err.data.message === 'string' && err.data.message) return err.data.message;
|
|
36
|
+
if (typeof err.name === 'string' && err.name) return err.name;
|
|
37
|
+
return 'opencode error';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createParser() {
|
|
41
|
+
let sessionId = null;
|
|
42
|
+
let lastReason = null;
|
|
43
|
+
let errorSeen = null;
|
|
44
|
+
let ended = false;
|
|
45
|
+
const texts = [];
|
|
46
|
+
const usage = { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0 };
|
|
47
|
+
|
|
48
|
+
function handle(evt, out) {
|
|
49
|
+
if (sessionId === null && hasId(evt.sessionID)) {
|
|
50
|
+
sessionId = evt.sessionID;
|
|
51
|
+
out.push(initEvent(sessionId, 'opencode'));
|
|
52
|
+
}
|
|
53
|
+
const part = isObj(evt.part) ? evt.part : null;
|
|
54
|
+
switch (evt.type) {
|
|
55
|
+
case 'text':
|
|
56
|
+
if (part && typeof part.text === 'string' && part.text) {
|
|
57
|
+
texts.push(part.text);
|
|
58
|
+
out.push(textEvent(part.text));
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
case 'tool_use': {
|
|
62
|
+
if (!part || !hasId(part.callID)) return;
|
|
63
|
+
const state = isObj(part.state) ? part.state : {};
|
|
64
|
+
out.push(toolUseEvent({ id: part.callID, name: part.tool, input: state.input }));
|
|
65
|
+
out.push(toolResultEvent({
|
|
66
|
+
toolUseId: part.callID,
|
|
67
|
+
content: state.output ?? '',
|
|
68
|
+
isError: state.status === 'error',
|
|
69
|
+
}));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
case 'step_finish': {
|
|
73
|
+
if (!part) return;
|
|
74
|
+
const t = isObj(part.tokens) ? part.tokens : {};
|
|
75
|
+
usage.input_tokens += num(t.input);
|
|
76
|
+
usage.output_tokens += num(t.output);
|
|
77
|
+
usage.cache_read_input_tokens += num(isObj(t.cache) ? t.cache.read : 0);
|
|
78
|
+
if (typeof part.reason === 'string') lastReason = part.reason;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
case 'error':
|
|
82
|
+
errorSeen = errorMessage(evt);
|
|
83
|
+
return;
|
|
84
|
+
default: // step_start and unknown types: no event
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
push(line) {
|
|
90
|
+
const out = [];
|
|
91
|
+
try {
|
|
92
|
+
const evt = safeJsonLine(line);
|
|
93
|
+
if (evt) handle(evt, out);
|
|
94
|
+
} catch {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
},
|
|
99
|
+
end({ exitCode } = {}) {
|
|
100
|
+
if (ended) return [];
|
|
101
|
+
ended = true;
|
|
102
|
+
const nativeSessionId = sessionId ?? undefined;
|
|
103
|
+
if (errorSeen !== null) {
|
|
104
|
+
return [resultEvent({ ok: false, text: errorSeen, usage: { ...usage }, nativeSessionId })];
|
|
105
|
+
}
|
|
106
|
+
if (lastReason === 'stop' && exitCode === 0) {
|
|
107
|
+
return [resultEvent({ ok: true, text: texts.join(''), usage: { ...usage }, nativeSessionId })];
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
},
|
|
111
|
+
nativeSessionId() {
|
|
112
|
+
return sessionId;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = { id: 'opencode', headlessSpawn, createParser, interactiveArgs };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Shared contract for non-Claude agent-CLI adapters: each adapter translates
|
|
3
|
+
// its CLI's native JSON output into these Claude stream-json event shapes,
|
|
4
|
+
// which src/main/chatRunner.cjs processLine already consumes. Pure module.
|
|
5
|
+
|
|
6
|
+
const AGENT_CLI_IDS = Object.freeze(['claude', 'codex', 'gemini', 'antigravity', 'cursor', 'opencode']);
|
|
7
|
+
const MAX_LINE_CHARS = 8 * 1024 * 1024;
|
|
8
|
+
const MAX_TOOL_RESULT_CHARS = 4000;
|
|
9
|
+
const USAGE_KEYS = ['input_tokens', 'output_tokens', 'cache_read_input_tokens'];
|
|
10
|
+
|
|
11
|
+
function isAgentCliId(x) {
|
|
12
|
+
return typeof x === 'string' && AGENT_CLI_IDS.includes(x);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isNonClaudeAgentCli(x) {
|
|
16
|
+
return isAgentCliId(x) && x !== 'claude';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function initEvent(nativeSessionId, cli) {
|
|
20
|
+
return { type: 'system', subtype: 'init', session_id: nativeSessionId, agent_cli: cli };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function textEvent(text) {
|
|
24
|
+
return { type: 'assistant', message: { role: 'assistant', content: [{ type: 'text', text }] } };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function toolUseEvent({ id, name, input } = {}) {
|
|
28
|
+
return { type: 'assistant', message: { role: 'assistant', content: [{ type: 'tool_use', id, name, input }] } };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toolResultContent(content) {
|
|
32
|
+
let s;
|
|
33
|
+
if (typeof content === 'string') s = content;
|
|
34
|
+
else {
|
|
35
|
+
try { s = JSON.stringify(content); } catch { s = String(content); }
|
|
36
|
+
if (typeof s !== 'string') s = String(content);
|
|
37
|
+
}
|
|
38
|
+
return s.length > MAX_TOOL_RESULT_CHARS ? s.slice(0, MAX_TOOL_RESULT_CHARS) : s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toolResultEvent({ toolUseId, content, isError } = {}) {
|
|
42
|
+
return {
|
|
43
|
+
type: 'user',
|
|
44
|
+
message: {
|
|
45
|
+
role: 'user',
|
|
46
|
+
content: [{ type: 'tool_result', tool_use_id: toolUseId, content: toolResultContent(content), is_error: !!isError }],
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function cleanUsage(usage) {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const k of USAGE_KEYS) {
|
|
54
|
+
const v = usage[k];
|
|
55
|
+
if (typeof v === 'number' && Number.isFinite(v) && v >= 0) out[k] = v;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resultEvent({ ok, text, usage, nativeSessionId } = {}) {
|
|
61
|
+
const ev = {
|
|
62
|
+
type: 'result',
|
|
63
|
+
subtype: ok ? 'success' : 'error',
|
|
64
|
+
is_error: !ok,
|
|
65
|
+
result: text,
|
|
66
|
+
session_id: nativeSessionId,
|
|
67
|
+
};
|
|
68
|
+
if (usage && typeof usage === 'object') ev.usage = cleanUsage(usage);
|
|
69
|
+
return ev;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function safeJsonLine(line) {
|
|
73
|
+
if (typeof line !== 'string' || line.length > MAX_LINE_CHARS) return null;
|
|
74
|
+
const trimmed = line.trim();
|
|
75
|
+
if (!trimmed || trimmed[0] !== '{') return null;
|
|
76
|
+
try {
|
|
77
|
+
const v = JSON.parse(trimmed);
|
|
78
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = {
|
|
85
|
+
AGENT_CLI_IDS,
|
|
86
|
+
isAgentCliId,
|
|
87
|
+
isNonClaudeAgentCli,
|
|
88
|
+
initEvent,
|
|
89
|
+
textEvent,
|
|
90
|
+
toolUseEvent,
|
|
91
|
+
toolResultEvent,
|
|
92
|
+
resultEvent,
|
|
93
|
+
safeJsonLine,
|
|
94
|
+
};
|