claude-code-session-manager 0.132.0 → 0.133.1
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-BTIBmZkM.js} +2 -2
- package/dist/assets/{AppSettings-DvDKsCnD.js → AppSettings-DwnfV9-4.js} +2 -2
- package/dist/assets/{Button-BzG_KdBC.js → Button-CObXxw7b.js} +1 -1
- package/dist/assets/DocumentEditorPane-CgB5IuOY.js +1 -0
- package/dist/assets/{Extensions-DgxKT_OZ.js → Extensions-Fuhshcl6.js} +2 -2
- package/dist/assets/{History-Nd3bKjBq.js → History-DbUV4jxK.js} +2 -2
- package/dist/assets/{Library-R71t6VAB.js → Library-COr79GyT.js} +1 -1
- package/dist/assets/{ListDetail-CG50Ul7c.js → ListDetail-DY53nXya.js} +1 -1
- package/dist/assets/{Panel-C7EFG4eU.js → Panel-D7NX5iP8.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-J92iNEGC.js → ProjectClaudeConfig-DuWzM8qA.js} +1 -1
- package/dist/assets/{ProvenanceBadge-C3KB3ILO.js → ProvenanceBadge-AnwE1p5X.js} +1 -1
- package/dist/assets/{Scheduler-DeYBA7uc.js → Scheduler-BHfx0rXd.js} +9 -9
- package/dist/assets/Settings-tt0VZCyz.js +2 -0
- package/dist/assets/{SkillReferenceGraph-D7bt3fyB.js → SkillReferenceGraph-D_rxqWgq.js} +1 -1
- package/dist/assets/{Skills-GpxtUrFP.js → Skills-BVQPJZaF.js} +1 -1
- package/dist/assets/{SourceChip-uyVMCZc7.js → SourceChip-DC5XD8KC.js} +1 -1
- package/dist/assets/{SystemPrompt-Cv25uFSM.js → SystemPrompt-XnvP0_cS.js} +1 -1
- package/dist/assets/{TiptapBody-uP8fJkbM.js → TiptapBody-B_TNEADm.js} +1 -1
- package/dist/assets/{Toggle-DRs80cX-.js → Toggle-CxQO8pGN.js} +1 -1
- package/dist/assets/{ViewTabs-BDkvvzJ8.js → ViewTabs-CEjnWPD9.js} +1 -1
- package/dist/assets/{VoiceButton-Cmtz2sQt.js → VoiceButton-B-6gdmKe.js} +1 -1
- package/dist/assets/{historyTotals-DHwAXunq.js → historyTotals-dT8vcKzX.js} +1 -1
- package/dist/assets/{index-oXqzajWV.css → index-5QIl5Kcd.css} +1 -1
- package/dist/assets/index-BLORXCcT.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 +4 -2
- package/scripts/README.md +1 -0
- 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/DocumentEditorPane-fm6zsnLM.js +0 -1
- package/dist/assets/Settings-B6r7N4v-.js +0 -2
- package/dist/assets/index-CBCdyHbZ.js +0 -3097
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* agentCliIpc.cjs — the `agentCli:*` IPC handlers the renderer needs for
|
|
5
|
+
* non-Claude agent-CLI sessions:
|
|
6
|
+
* agentCli:detect — which CLIs are installed (New Session picker)
|
|
7
|
+
* agentCli:terminal-command — the exact shell line the Epic Terminal pane
|
|
8
|
+
* types to launch / resume a non-Claude session
|
|
9
|
+
*
|
|
10
|
+
* Main owns both because the registry and adapters are CommonJS + fs-bound.
|
|
11
|
+
* Desktop-only: these channels are NOT in the web-remote command allowlist.
|
|
12
|
+
* Every dependency is injectable (`deps`) so tests spawn and read nothing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { z } = require('zod');
|
|
16
|
+
const { validated } = require('../../ipcSchemas.cjs');
|
|
17
|
+
const registry = require('./agentCliRegistry.cjs');
|
|
18
|
+
const { readNativeSession } = require('./agentCliSessionStore.cjs');
|
|
19
|
+
const { findEpicByClaudeSessionId } = require('../claude/agentModelResolve.cjs');
|
|
20
|
+
|
|
21
|
+
const detectSchema = z.object({ refresh: z.boolean().optional() }).strict();
|
|
22
|
+
const terminalCommandSchema = z.object({
|
|
23
|
+
cwd: z.string().min(1).max(4096),
|
|
24
|
+
claudeSessionId: z.string().min(1).max(200),
|
|
25
|
+
}).strict();
|
|
26
|
+
|
|
27
|
+
/** Single-quote a value for safe shell interpolation — same rule as renderer/lib/presets.ts shellQuote. */
|
|
28
|
+
function shellQuote(s) {
|
|
29
|
+
return "'" + String(s).replace(/'/g, "'\\''") + "'";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function withDefaults(deps) {
|
|
33
|
+
const d = deps || {};
|
|
34
|
+
return {
|
|
35
|
+
readActiveIndex: d.readActiveIndex, // undefined → findEpicByClaudeSessionId's own default
|
|
36
|
+
resolveAgentCliBin: d.resolveAgentCliBin || registry.resolveAgentCliBin,
|
|
37
|
+
readNativeSession: d.readNativeSession || readNativeSession,
|
|
38
|
+
adapterFor: d.adapterFor || registry.adapterFor,
|
|
39
|
+
detectAgentClis: d.detectAgentClis || registry.detectAgentClis,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builds the Terminal launch/resume line for a non-Claude Epic.
|
|
45
|
+
* @returns {Promise<{ok:true, command:string} | {ok:false, message:string}>} never rejects
|
|
46
|
+
*/
|
|
47
|
+
async function buildTerminalCommand({ cwd, claudeSessionId }, deps) {
|
|
48
|
+
const d = withDefaults(deps);
|
|
49
|
+
let epic = null;
|
|
50
|
+
try {
|
|
51
|
+
epic = findEpicByClaudeSessionId(cwd, claudeSessionId, d.readActiveIndex ? { readActiveIndex: d.readActiveIndex } : {});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return { ok: false, message: `Could not read this project's sessions: ${e && e.message ? e.message : String(e)}` };
|
|
54
|
+
}
|
|
55
|
+
if (!epic) return { ok: false, message: 'No session with that id in this project.' };
|
|
56
|
+
|
|
57
|
+
const cli = epic.agentCli;
|
|
58
|
+
const entry = typeof cli === 'string' && Object.prototype.hasOwnProperty.call(registry.AGENT_CLI_CATALOG, cli)
|
|
59
|
+
? registry.AGENT_CLI_CATALOG[cli]
|
|
60
|
+
: null;
|
|
61
|
+
if (!entry) return { ok: false, message: 'This session is not a non-Claude agent-CLI session.' };
|
|
62
|
+
|
|
63
|
+
let adapter = null;
|
|
64
|
+
try { adapter = d.adapterFor(cli); } catch { adapter = null; }
|
|
65
|
+
if (!adapter || typeof adapter.interactiveArgs !== 'function') {
|
|
66
|
+
return { ok: false, message: `${entry.label} is not supported yet.` };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let binPath = null;
|
|
70
|
+
try { binPath = d.resolveAgentCliBin(cli); } catch { binPath = null; }
|
|
71
|
+
if (!binPath) {
|
|
72
|
+
const hint = entry.install ? `Install it with: ${entry.install}` : `See ${entry.docs}`;
|
|
73
|
+
return { ok: false, message: `${entry.label} is not installed. ${hint}` };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let nativeSessionId = null;
|
|
77
|
+
try {
|
|
78
|
+
const rec = d.readNativeSession(claudeSessionId);
|
|
79
|
+
if (rec && typeof rec.nativeSessionId === 'string' && rec.nativeSessionId
|
|
80
|
+
&& (rec.cli === undefined || rec.cli === cli)) {
|
|
81
|
+
nativeSessionId = rec.nativeSessionId;
|
|
82
|
+
}
|
|
83
|
+
} catch { nativeSessionId = null; } // invalid id / unreadable sidecar → fresh launch
|
|
84
|
+
|
|
85
|
+
const model = typeof epic.agentCliModel === 'string' && epic.agentCliModel.trim() ? epic.agentCliModel.trim() : undefined;
|
|
86
|
+
let args;
|
|
87
|
+
try {
|
|
88
|
+
args = adapter.interactiveArgs({ nativeSessionId, claudeSessionId, model });
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return { ok: false, message: `Could not build the ${entry.label} command: ${e && e.message ? e.message : String(e)}` };
|
|
91
|
+
}
|
|
92
|
+
const command = [binPath, ...(Array.isArray(args) ? args : [])].map(shellQuote).join(' ');
|
|
93
|
+
return { ok: true, command };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {{ ipcMain?: any, deps?: object }} [opts]
|
|
98
|
+
*/
|
|
99
|
+
function registerAgentCliHandlers(opts = {}) {
|
|
100
|
+
const ipcMain = opts.ipcMain || require('electron').ipcMain;
|
|
101
|
+
const deps = opts.deps;
|
|
102
|
+
const d = withDefaults(deps);
|
|
103
|
+
ipcMain.handle('agentCli:detect', validated(detectSchema, (payload) =>
|
|
104
|
+
d.detectAgentClis({ refresh: !!payload.refresh })));
|
|
105
|
+
ipcMain.handle('agentCli:terminal-command', validated(terminalCommandSchema, (payload) =>
|
|
106
|
+
buildTerminalCommand(payload, deps)));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { registerAgentCliHandlers, buildTerminalCommand, shellQuote };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentCliRegistry.cjs — static catalog of the non-Claude agent CLIs a session
|
|
3
|
+
* can run (Codex, Gemini CLI, Antigravity, Cursor Agent, OpenCode), a binary
|
|
4
|
+
* resolver with a per-CLI test override, a bounded detection probe for the New
|
|
5
|
+
* Session picker, and a lazy adapter lookup.
|
|
6
|
+
*
|
|
7
|
+
* Detection only — never installs anything. These CLIs are optional and are
|
|
8
|
+
* deliberately NOT part of prereqs.cjs (the boot Setup checklist).
|
|
9
|
+
*
|
|
10
|
+
* Every probe is injectable via `deps` ({ findCommand, execFile, realpathSync,
|
|
11
|
+
* now }) so tests spawn nothing.
|
|
12
|
+
*/
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const childProcess = require('node:child_process');
|
|
17
|
+
|
|
18
|
+
const PROBE_TIMEOUT_MS = 5000;
|
|
19
|
+
const CACHE_TTL_MS = 60_000;
|
|
20
|
+
const VERSION_MAX = 120;
|
|
21
|
+
|
|
22
|
+
const AGENT_CLI_CATALOG = Object.freeze({
|
|
23
|
+
codex: Object.freeze({
|
|
24
|
+
label: 'Codex',
|
|
25
|
+
bins: Object.freeze(['codex']),
|
|
26
|
+
install: 'npm install -g @openai/codex',
|
|
27
|
+
login: 'codex login',
|
|
28
|
+
authEnv: Object.freeze(['OPENAI_API_KEY', 'CODEX_API_KEY']),
|
|
29
|
+
docs: 'https://developers.openai.com/codex/cli',
|
|
30
|
+
}),
|
|
31
|
+
gemini: Object.freeze({
|
|
32
|
+
label: 'Gemini CLI',
|
|
33
|
+
bins: Object.freeze(['gemini']),
|
|
34
|
+
install: 'npm install -g @google/gemini-cli',
|
|
35
|
+
login: null,
|
|
36
|
+
authEnv: Object.freeze(['GEMINI_API_KEY', 'GOOGLE_API_KEY']),
|
|
37
|
+
docs: 'https://github.com/google-gemini/gemini-cli',
|
|
38
|
+
}),
|
|
39
|
+
antigravity: Object.freeze({
|
|
40
|
+
label: 'Antigravity CLI',
|
|
41
|
+
bins: Object.freeze(['agy']),
|
|
42
|
+
install: null,
|
|
43
|
+
login: null,
|
|
44
|
+
authEnv: Object.freeze([]),
|
|
45
|
+
docs: 'https://antigravity.google/docs/cli/',
|
|
46
|
+
}),
|
|
47
|
+
cursor: Object.freeze({
|
|
48
|
+
label: 'Cursor Agent',
|
|
49
|
+
bins: Object.freeze(['cursor-agent', 'agent']),
|
|
50
|
+
install: 'curl https://cursor.com/install -fsS | bash',
|
|
51
|
+
login: 'cursor-agent login',
|
|
52
|
+
authEnv: Object.freeze(['CURSOR_API_KEY']),
|
|
53
|
+
docs: 'https://cursor.com/docs/cli/overview',
|
|
54
|
+
}),
|
|
55
|
+
opencode: Object.freeze({
|
|
56
|
+
label: 'OpenCode',
|
|
57
|
+
bins: Object.freeze(['opencode']),
|
|
58
|
+
install: 'npm install -g opencode-ai',
|
|
59
|
+
login: 'opencode auth login',
|
|
60
|
+
authEnv: Object.freeze([
|
|
61
|
+
'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'OPENROUTER_API_KEY', 'GEMINI_API_KEY',
|
|
62
|
+
'GOOGLE_GENERATIVE_AI_API_KEY', 'GROQ_API_KEY', 'XAI_API_KEY', 'DEEPSEEK_API_KEY', 'MISTRAL_API_KEY',
|
|
63
|
+
]),
|
|
64
|
+
docs: 'https://opencode.ai/docs/',
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const CATALOG_IDS = Object.freeze(Object.keys(AGENT_CLI_CATALOG));
|
|
69
|
+
|
|
70
|
+
function isCatalogId(id) {
|
|
71
|
+
return typeof id === 'string' && Object.prototype.hasOwnProperty.call(AGENT_CLI_CATALOG, id);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Lazy: openExternalApp.cjs pulls in electron + cleanEnv at load time.
|
|
75
|
+
function defaultFindCommand(name) {
|
|
76
|
+
return require('../openExternalApp.cjs').findCommand(name);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function defaultExecFile(cmd, args, opts) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
childProcess.execFile(cmd, args, opts, (err, stdout, stderr) => {
|
|
82
|
+
if (err) reject(err);
|
|
83
|
+
else resolve({ stdout, stderr });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function withDefaults(deps) {
|
|
89
|
+
const d = deps || {};
|
|
90
|
+
return {
|
|
91
|
+
findCommand: d.findCommand || defaultFindCommand,
|
|
92
|
+
execFile: d.execFile || defaultExecFile,
|
|
93
|
+
realpathSync: d.realpathSync || fs.realpathSync,
|
|
94
|
+
now: d.now || Date.now,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolve the executable for a non-Claude agent CLI.
|
|
100
|
+
* SM_AGENT_CLI_BIN_<ID> wins (never cached); otherwise the first catalog bin
|
|
101
|
+
* on PATH. Cursor's bare `agent` name is generic, so it only counts when its
|
|
102
|
+
* realpath points into a Cursor install.
|
|
103
|
+
* @returns {string|null}
|
|
104
|
+
*/
|
|
105
|
+
function resolveAgentCliBin(id, deps) {
|
|
106
|
+
if (!isCatalogId(id)) return null;
|
|
107
|
+
const override = process.env['SM_AGENT_CLI_BIN_' + id.toUpperCase()];
|
|
108
|
+
if (override) return override;
|
|
109
|
+
const d = withDefaults(deps);
|
|
110
|
+
for (const bin of AGENT_CLI_CATALOG[id].bins) {
|
|
111
|
+
let found = null;
|
|
112
|
+
try { found = d.findCommand(bin); } catch { found = null; }
|
|
113
|
+
if (!found) continue;
|
|
114
|
+
if (id === 'cursor' && bin === 'agent') {
|
|
115
|
+
let real = '';
|
|
116
|
+
try { real = String(d.realpathSync(found)); } catch { real = ''; }
|
|
117
|
+
if (!real.toLowerCase().includes('cursor')) continue;
|
|
118
|
+
}
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function probeEnv() {
|
|
125
|
+
const { pathWithUserBins } = require('../process/cleanEnv.cjs');
|
|
126
|
+
return { ...process.env, PATH: pathWithUserBins() };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function probeVersion(execFile, binPath) {
|
|
130
|
+
try {
|
|
131
|
+
const r = await execFile(binPath, ['--version'], {
|
|
132
|
+
env: probeEnv(),
|
|
133
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
134
|
+
windowsHide: true,
|
|
135
|
+
shell: false,
|
|
136
|
+
});
|
|
137
|
+
const out = typeof r === 'string' ? r : (r && (r.stdout || r.stderr)) || '';
|
|
138
|
+
const first = String(out).trim().split(/\r?\n/)[0].trim();
|
|
139
|
+
return first ? first.slice(0, VERSION_MAX) : null;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let cache = null; // { at: number, rows: object[] }
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* One row per non-Claude CLI: {id,label,installed,path,version,install,docs,login}.
|
|
149
|
+
* Cached 60 s unless opts.refresh. Never rejects.
|
|
150
|
+
*/
|
|
151
|
+
async function detectAgentClis(opts, deps) {
|
|
152
|
+
const d = withDefaults(deps);
|
|
153
|
+
const refresh = !!(opts && opts.refresh);
|
|
154
|
+
let t = 0;
|
|
155
|
+
try { t = Number(d.now()) || 0; } catch { t = 0; }
|
|
156
|
+
if (!refresh && cache && t - cache.at < CACHE_TTL_MS && t >= cache.at) {
|
|
157
|
+
return cache.rows.map((r) => ({ ...r }));
|
|
158
|
+
}
|
|
159
|
+
const rows = await Promise.all(CATALOG_IDS.map(async (id) => {
|
|
160
|
+
const entry = AGENT_CLI_CATALOG[id];
|
|
161
|
+
let binPath = null;
|
|
162
|
+
try { binPath = resolveAgentCliBin(id, d); } catch { binPath = null; }
|
|
163
|
+
const version = binPath ? await probeVersion(d.execFile, binPath) : null;
|
|
164
|
+
return {
|
|
165
|
+
id,
|
|
166
|
+
label: entry.label,
|
|
167
|
+
installed: !!binPath,
|
|
168
|
+
path: binPath,
|
|
169
|
+
version,
|
|
170
|
+
install: entry.install,
|
|
171
|
+
docs: entry.docs,
|
|
172
|
+
login: entry.login,
|
|
173
|
+
};
|
|
174
|
+
}));
|
|
175
|
+
cache = { at: t, rows };
|
|
176
|
+
return rows.map((r) => ({ ...r }));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Test hook: drop the detection cache. */
|
|
180
|
+
function _resetCache() { cache = null; }
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Lazily load the adapter module for a non-Claude CLI. Each require uses a
|
|
184
|
+
* literal path — no path is ever built from the caller's string. Returns null
|
|
185
|
+
* for unknown ids, 'claude', or an adapter that has not been written yet.
|
|
186
|
+
*/
|
|
187
|
+
function adapterFor(id) {
|
|
188
|
+
if (!isCatalogId(id)) return null;
|
|
189
|
+
try {
|
|
190
|
+
switch (id) {
|
|
191
|
+
case 'codex': return require('./adapters/codex.cjs');
|
|
192
|
+
case 'gemini': return require('./adapters/gemini.cjs');
|
|
193
|
+
case 'antigravity': return require('./adapters/antigravity.cjs');
|
|
194
|
+
case 'cursor': return require('./adapters/cursor.cjs');
|
|
195
|
+
case 'opencode': return require('./adapters/opencode.cjs');
|
|
196
|
+
default: return null;
|
|
197
|
+
}
|
|
198
|
+
} catch (e) {
|
|
199
|
+
// Only an absent adapter file is tolerated; a broken adapter still throws.
|
|
200
|
+
if (e && e.code === 'MODULE_NOT_FOUND' && String(e.message).includes(`adapters/${id}.cjs`)) return null;
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = {
|
|
206
|
+
AGENT_CLI_CATALOG,
|
|
207
|
+
resolveAgentCliBin,
|
|
208
|
+
detectAgentClis,
|
|
209
|
+
adapterFor,
|
|
210
|
+
_resetCache,
|
|
211
|
+
PROBE_TIMEOUT_MS,
|
|
212
|
+
CACHE_TTL_MS,
|
|
213
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Machine-level runtime state for non-Claude agent-CLI Epics (not an ops-root
|
|
3
|
+
// namespace, so opsOwnership.cjs is not involved). Two artifacts per Epic,
|
|
4
|
+
// keyed by the app-level claudeSessionId UUID:
|
|
5
|
+
// <root>/sessions/<id>.json — sidecar mapping to the CLI's native session id
|
|
6
|
+
// <root>/transcripts/<id>.jsonl — Claude-transcript-compatible JSONL so the
|
|
7
|
+
// existing tail / Chat feed / usage readers work
|
|
8
|
+
// <root> = $SM_AGENT_CLI_STATE_DIR or schedulerPaths.agentCliStateRoot()
|
|
9
|
+
// (<SM_SCHEDULER_HOME or ~/.claude/session-manager>/agent-cli),
|
|
10
|
+
// resolved per call so tests (and env changes) take effect without re-require.
|
|
11
|
+
|
|
12
|
+
const fs = require('node:fs');
|
|
13
|
+
const path = require('node:path');
|
|
14
|
+
const crypto = require('node:crypto');
|
|
15
|
+
const { writeJsonAtomicSync, readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
16
|
+
const schedulerPaths = require('../scheduler/schedulerPaths.cjs');
|
|
17
|
+
|
|
18
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19
|
+
const DIR_MODE = 0o700;
|
|
20
|
+
|
|
21
|
+
function rootDir() {
|
|
22
|
+
const env = process.env.SM_AGENT_CLI_STATE_DIR;
|
|
23
|
+
if (typeof env === 'string' && env.trim()) return env;
|
|
24
|
+
return schedulerPaths.agentCliStateRoot();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertId(claudeSessionId) {
|
|
28
|
+
if (typeof claudeSessionId !== 'string' || !UUID_RE.test(claudeSessionId)) {
|
|
29
|
+
throw new Error(`agentCliSessionStore: invalid claudeSessionId ${JSON.stringify(String(claudeSessionId))}`);
|
|
30
|
+
}
|
|
31
|
+
return claudeSessionId;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ensureDir(dir) {
|
|
35
|
+
fs.mkdirSync(dir, { recursive: true, mode: DIR_MODE });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function sessionPathFor(claudeSessionId) {
|
|
39
|
+
return path.join(rootDir(), 'sessions', `${assertId(claudeSessionId)}.json`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function transcriptPathFor(claudeSessionId) {
|
|
43
|
+
return path.join(rootDir(), 'transcripts', `${assertId(claudeSessionId)}.jsonl`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readNativeSession(claudeSessionId) {
|
|
47
|
+
const v = readJsonOrSync(sessionPathFor(claudeSessionId), null);
|
|
48
|
+
if (!v || typeof v !== 'object' || typeof v.nativeSessionId !== 'string') return null;
|
|
49
|
+
return { cli: v.cli, nativeSessionId: v.nativeSessionId, updatedAt: v.updatedAt };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function writeNativeSession(claudeSessionId, { cli, nativeSessionId } = {}) {
|
|
53
|
+
const file = sessionPathFor(claudeSessionId);
|
|
54
|
+
if (typeof nativeSessionId !== 'string' || !nativeSessionId) {
|
|
55
|
+
throw new Error('agentCliSessionStore: nativeSessionId must be a non-empty string');
|
|
56
|
+
}
|
|
57
|
+
ensureDir(path.dirname(file));
|
|
58
|
+
const rec = { cli, nativeSessionId, updatedAt: new Date().toISOString() };
|
|
59
|
+
writeJsonAtomicSync(file, rec);
|
|
60
|
+
return rec;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Appends Claude-transcript-shaped JSONL lines for one CLI run. Consecutive
|
|
65
|
+
* assistant text events coalesce into one line, flushed at the next
|
|
66
|
+
* tool_use / tool_result / result event or close(). Never throws on I/O.
|
|
67
|
+
*/
|
|
68
|
+
function createTranscriptWriter({ claudeSessionId, cwd, cli } = {}) {
|
|
69
|
+
const file = transcriptPathFor(claudeSessionId);
|
|
70
|
+
let pendingText = null;
|
|
71
|
+
let logged = false;
|
|
72
|
+
let dirReady = false;
|
|
73
|
+
|
|
74
|
+
function append(type, message) {
|
|
75
|
+
const line = {
|
|
76
|
+
type,
|
|
77
|
+
message,
|
|
78
|
+
uuid: crypto.randomUUID(),
|
|
79
|
+
timestamp: new Date().toISOString(),
|
|
80
|
+
sessionId: claudeSessionId,
|
|
81
|
+
cwd,
|
|
82
|
+
agentCli: cli,
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
if (!dirReady) { ensureDir(path.dirname(file)); dirReady = true; }
|
|
86
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n', 'utf8');
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (!logged) {
|
|
89
|
+
logged = true;
|
|
90
|
+
console.warn(`[agentCliSessionStore] transcript write failed for ${claudeSessionId}: ${e && e.message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function flushText() {
|
|
96
|
+
if (pendingText === null) return;
|
|
97
|
+
const text = pendingText;
|
|
98
|
+
pendingText = null;
|
|
99
|
+
append('assistant', { role: 'assistant', content: [{ type: 'text', text }] });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function userPrompt(text) {
|
|
103
|
+
flushText();
|
|
104
|
+
append('user', { role: 'user', content: typeof text === 'string' ? text : String(text ?? '') });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function event(ev) {
|
|
108
|
+
try {
|
|
109
|
+
if (!ev || typeof ev !== 'object') return;
|
|
110
|
+
if (ev.type === 'system') return;
|
|
111
|
+
if (ev.type === 'result') {
|
|
112
|
+
flushText();
|
|
113
|
+
if (ev.usage && typeof ev.usage === 'object') {
|
|
114
|
+
append('assistant', { role: 'assistant', content: [], usage: ev.usage });
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (ev.type !== 'assistant' && ev.type !== 'user') return;
|
|
119
|
+
const content = ev.message && Array.isArray(ev.message.content) ? ev.message.content : [];
|
|
120
|
+
for (const block of content) {
|
|
121
|
+
if (!block || typeof block !== 'object') continue;
|
|
122
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
123
|
+
if (ev.type === 'assistant') pendingText = (pendingText ?? '') + block.text;
|
|
124
|
+
} else if (block.type === 'tool_use') {
|
|
125
|
+
flushText();
|
|
126
|
+
append('assistant', { role: 'assistant', content: [block] });
|
|
127
|
+
} else if (block.type === 'tool_result') {
|
|
128
|
+
flushText();
|
|
129
|
+
append('user', { role: 'user', content: [block] });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
if (!logged) {
|
|
134
|
+
logged = true;
|
|
135
|
+
console.warn(`[agentCliSessionStore] transcript event failed for ${claudeSessionId}: ${e && e.message}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function close() {
|
|
141
|
+
flushText();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return { userPrompt, event, close };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
module.exports = {
|
|
148
|
+
readNativeSession,
|
|
149
|
+
writeNativeSession,
|
|
150
|
+
transcriptPathFor,
|
|
151
|
+
createTranscriptWriter,
|
|
152
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// agentCliTurn.cjs — plans ONE Chat turn of a non-Claude agent-CLI Epic
|
|
3
|
+
// (codex, gemini, antigravity, cursor, opencode) for chatRunner.cjs's
|
|
4
|
+
// executeRun: which binary to spawn, its argv + stdin (from the adapter's
|
|
5
|
+
// headlessSpawn), the auth env it may inherit, a fresh stream parser and the
|
|
6
|
+
// Claude-compatible transcript writer. Spawns nothing; every collaborator is
|
|
7
|
+
// injectable via `deps` so tests touch no PATH and no disk.
|
|
8
|
+
//
|
|
9
|
+
// The model is epic.agentCliModel or nothing — persona --model resolution is
|
|
10
|
+
// Claude-only and is never forwarded to another CLI.
|
|
11
|
+
|
|
12
|
+
const registry = require('./agentCliRegistry.cjs');
|
|
13
|
+
const sessionStore = require('./agentCliSessionStore.cjs');
|
|
14
|
+
|
|
15
|
+
const NOOP_TRANSCRIPT = Object.freeze({ userPrompt() {}, event() {}, close() {} });
|
|
16
|
+
|
|
17
|
+
function withDefaults(deps) {
|
|
18
|
+
const d = deps || {};
|
|
19
|
+
return {
|
|
20
|
+
adapterFor: d.adapterFor || registry.adapterFor,
|
|
21
|
+
resolveAgentCliBin: d.resolveAgentCliBin || registry.resolveAgentCliBin,
|
|
22
|
+
catalog: d.catalog || registry.AGENT_CLI_CATALOG,
|
|
23
|
+
readNativeSession: d.readNativeSession || sessionStore.readNativeSession,
|
|
24
|
+
createTranscriptWriter: d.createTranscriptWriter || sessionStore.createTranscriptWriter,
|
|
25
|
+
env: d.env || process.env,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Catalog authEnv keys that are set (non-empty) in env — nothing else. */
|
|
30
|
+
function pickAuthEnv(entry, env) {
|
|
31
|
+
const out = {};
|
|
32
|
+
const keys = entry && Array.isArray(entry.authEnv) ? entry.authEnv : [];
|
|
33
|
+
for (const k of keys) {
|
|
34
|
+
const v = env[k];
|
|
35
|
+
if (typeof v === 'string' && v !== '') out[k] = v;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {{ epic: object, claudeSessionId: string, cwd: string, prompt: string, deps?: object }} opts
|
|
42
|
+
* @returns {{ ok: true, command: string, args: string[], stdin: string, envExtra: Record<string,string>,
|
|
43
|
+
* parser: { push(line: string): object[], end(o: { exitCode: number|null }): object[] },
|
|
44
|
+
* transcript: { userPrompt(t: string): void, event(e: object): void, close(): void }, cli: string }
|
|
45
|
+
* | { ok: false, code: string, message: string }}
|
|
46
|
+
*/
|
|
47
|
+
function planAgentCliTurn({ epic, claudeSessionId, cwd, prompt, deps } = {}) {
|
|
48
|
+
const d = withDefaults(deps);
|
|
49
|
+
const cli = epic && typeof epic.agentCli === 'string' ? epic.agentCli : '';
|
|
50
|
+
const adapter = cli ? d.adapterFor(cli) : null;
|
|
51
|
+
const entry = cli && Object.prototype.hasOwnProperty.call(d.catalog, cli) ? d.catalog[cli] : null;
|
|
52
|
+
if (!adapter || !entry) {
|
|
53
|
+
return { ok: false, code: 'agent_cli_unknown', message: `Unknown agent CLI: ${JSON.stringify(cli || null)}` };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let command = null;
|
|
57
|
+
try { command = d.resolveAgentCliBin(cli); } catch { command = null; }
|
|
58
|
+
if (!command) {
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
code: 'agent_cli_missing',
|
|
62
|
+
message: `${entry.label} CLI not found on PATH. Install: ${entry.install || entry.docs}`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let nativeSessionId;
|
|
67
|
+
try {
|
|
68
|
+
const rec = d.readNativeSession(claudeSessionId);
|
|
69
|
+
if (rec && typeof rec.nativeSessionId === 'string' && rec.nativeSessionId && (!rec.cli || rec.cli === cli)) {
|
|
70
|
+
nativeSessionId = rec.nativeSessionId;
|
|
71
|
+
}
|
|
72
|
+
} catch { nativeSessionId = undefined; }
|
|
73
|
+
|
|
74
|
+
const model = typeof epic.agentCliModel === 'string' && epic.agentCliModel.trim()
|
|
75
|
+
? epic.agentCliModel.trim()
|
|
76
|
+
: undefined;
|
|
77
|
+
const spawnPlan = adapter.headlessSpawn({ prompt, nativeSessionId, model }) || {};
|
|
78
|
+
if (spawnPlan.error) {
|
|
79
|
+
return { ok: false, code: 'agent_cli_prompt', message: String(spawnPlan.error) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let transcript = NOOP_TRANSCRIPT;
|
|
83
|
+
try {
|
|
84
|
+
transcript = d.createTranscriptWriter({ claudeSessionId, cwd, cli }) || NOOP_TRANSCRIPT;
|
|
85
|
+
} catch { transcript = NOOP_TRANSCRIPT; } // non-UUID session id: no transcript, turn still runs
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
ok: true,
|
|
89
|
+
command,
|
|
90
|
+
args: Array.isArray(spawnPlan.args) ? spawnPlan.args : [],
|
|
91
|
+
stdin: typeof spawnPlan.stdin === 'string' ? spawnPlan.stdin : '',
|
|
92
|
+
envExtra: pickAuthEnv(entry, d.env),
|
|
93
|
+
parser: adapter.createParser(),
|
|
94
|
+
transcript,
|
|
95
|
+
cli,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = { planAgentCliTurn };
|