@cogitator-ai/bridge 0.2.0 → 0.4.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 +242 -8
- package/dist/adapter.d.ts +130 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +2 -0
- package/dist/adapter.js.map +1 -0
- package/dist/adapters/claude.d.ts +145 -0
- package/dist/adapters/claude.d.ts.map +1 -0
- package/dist/adapters/claude.js +537 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +71 -0
- package/dist/adapters/codex.d.ts.map +1 -0
- package/dist/adapters/codex.js +379 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/exec.d.ts +70 -0
- package/dist/adapters/exec.d.ts.map +1 -0
- package/dist/adapters/exec.js +161 -0
- package/dist/adapters/exec.js.map +1 -0
- package/dist/adapters/hosted.d.ts +168 -0
- package/dist/adapters/hosted.d.ts.map +1 -0
- package/dist/adapters/hosted.js +361 -0
- package/dist/adapters/hosted.js.map +1 -0
- package/dist/adapters/tools-server.d.ts +21 -0
- package/dist/adapters/tools-server.d.ts.map +1 -0
- package/dist/adapters/tools-server.js +19 -0
- package/dist/adapters/tools-server.js.map +1 -0
- package/dist/client.d.ts +9 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -3
- package/dist/client.js.map +1 -1
- package/dist/dispatcher.d.ts +69 -17
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +243 -17
- package/dist/dispatcher.js.map +1 -1
- package/dist/host.d.ts +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +40 -1
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +25 -2
- package/dist/inputs.js.map +1 -1
- package/dist/paths.d.ts +6 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +19 -0
- package/dist/paths.js.map +1 -1
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +5 -0
- package/dist/protocol.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/setup/claude.d.ts +53 -0
- package/dist/setup/claude.d.ts.map +1 -0
- package/dist/setup/claude.js +261 -0
- package/dist/setup/claude.js.map +1 -0
- package/dist/setup/codex.d.ts +22 -0
- package/dist/setup/codex.d.ts.map +1 -0
- package/dist/setup/codex.js +95 -0
- package/dist/setup/codex.js.map +1 -0
- package/dist/setup/files.d.ts +22 -0
- package/dist/setup/files.d.ts.map +1 -0
- package/dist/setup/files.js +86 -0
- package/dist/setup/files.js.map +1 -0
- package/dist/setup/index.d.ts +6 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +3 -0
- package/dist/setup/index.js.map +1 -0
- package/dist/setup/setup.d.ts +52 -0
- package/dist/setup/setup.d.ts.map +1 -0
- package/dist/setup/setup.js +2 -0
- package/dist/setup/setup.js.map +1 -0
- package/dist/testing/conformance.d.ts +65 -0
- package/dist/testing/conformance.d.ts.map +1 -0
- package/dist/testing/conformance.js +217 -0
- package/dist/testing/conformance.js.map +1 -0
- package/dist/testing/fake-harnesses.d.ts +121 -0
- package/dist/testing/fake-harnesses.d.ts.map +1 -0
- package/dist/testing/fake-harnesses.js +303 -0
- package/dist/testing/fake-harnesses.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tools/caller.d.ts +39 -0
- package/dist/tools/caller.d.ts.map +1 -0
- package/dist/tools/caller.js +92 -0
- package/dist/tools/caller.js.map +1 -0
- package/dist/tools/guidance.d.ts +33 -0
- package/dist/tools/guidance.d.ts.map +1 -0
- package/dist/tools/guidance.js +92 -0
- package/dist/tools/guidance.js.map +1 -0
- package/dist/tools/index.d.ts +27 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +24 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/tools.d.ts +38 -0
- package/dist/tools/tools.d.ts.map +1 -0
- package/dist/tools/tools.js +354 -0
- package/dist/tools/tools.js.map +1 -0
- package/dist/types.d.ts +3 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/waiter.d.ts +36 -0
- package/dist/waiter.d.ts.map +1 -0
- package/dist/waiter.js +92 -0
- package/dist/waiter.js.map +1 -0
- package/fakes/claude.mjs +715 -0
- package/fakes/codex.mjs +571 -0
- package/fakes/lib.mjs +585 -0
- package/fakes/mcp.mjs +151 -0
- package/fakes/sandbox.mjs +84 -0
- package/package.json +19 -1
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { canonicalPath, findProjectRoot } from '../paths.js';
|
|
6
|
+
import { TOOL_CALL_HINT_KEY } from '../tools/caller.js';
|
|
7
|
+
import { HARNESSES } from '../types.js';
|
|
8
|
+
import { CommandMissingError, failureOf, fitsArgument, pause, runCommand, sessionEnv, shellQuote, tooLongNotice, } from './exec.js';
|
|
9
|
+
import { BRIDGE_TOOLS_SERVER, toolsServerEnv } from './tools-server.js';
|
|
10
|
+
/** How letters reach a Claude Code session: a hook of the session waits for them. */
|
|
11
|
+
export const CLAUDE_DELIVERY = 'hook';
|
|
12
|
+
/** How long a waiter of a Claude Code session waits before Claude Code ends it, 12 hours. */
|
|
13
|
+
export const DEFAULT_HOOK_TIMEOUT_S = 12 * 3600;
|
|
14
|
+
/** The waiter leaves this long before its hook's timeout, so it ends by itself and not mid-answer. */
|
|
15
|
+
const HOOK_MARGIN_S = 60;
|
|
16
|
+
/** The command a hook of a Claude Code session runs to wait for the session's mail. */
|
|
17
|
+
export function claudeWaitCommand(options = {}) {
|
|
18
|
+
const timeoutS = options.timeoutS ?? DEFAULT_HOOK_TIMEOUT_S;
|
|
19
|
+
const waitS = Math.max(1, Math.floor(timeoutS - HOOK_MARGIN_S));
|
|
20
|
+
return [
|
|
21
|
+
options.bridgeCommand ?? 'cogitator bridge',
|
|
22
|
+
'wait',
|
|
23
|
+
`--hook ${HARNESSES.claudeCode}`,
|
|
24
|
+
`--timeout ${waitS}`,
|
|
25
|
+
...(options.agentName ? [`--agent ${shellQuote(options.agentName)}`] : []),
|
|
26
|
+
...(options.bridgeHome ? [`--home ${shellQuote(options.bridgeHome)}`] : []),
|
|
27
|
+
...(options.tools ? ['--tools'] : []),
|
|
28
|
+
].join(' ');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The settings that make a Claude Code session wake for its mail: a `Stop` hook that runs in the
|
|
32
|
+
* background after every turn (`async`), waits at the bridge, and wakes the session with what it
|
|
33
|
+
* got (`asyncRewake`: the hook exits with code 2 and its stderr becomes the session's next
|
|
34
|
+
* input). The session is free while the hook waits. Merge them into the project's
|
|
35
|
+
* `.claude/settings.local.json`, or pass them to one session with `claude --settings`.
|
|
36
|
+
*/
|
|
37
|
+
export function claudeWaitHook(options = {}) {
|
|
38
|
+
return {
|
|
39
|
+
hooks: {
|
|
40
|
+
Stop: [
|
|
41
|
+
{
|
|
42
|
+
hooks: [
|
|
43
|
+
{
|
|
44
|
+
type: 'command',
|
|
45
|
+
command: claudeWaitCommand(options),
|
|
46
|
+
timeout: Math.ceil(options.timeoutS ?? DEFAULT_HOOK_TIMEOUT_S),
|
|
47
|
+
async: true,
|
|
48
|
+
asyncRewake: true,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Whether Claude Code settings hold a hook that waits at the bridge. */
|
|
57
|
+
export function hasClaudeWaitHook(settings) {
|
|
58
|
+
const parsed = SettingsSchema.safeParse(settings);
|
|
59
|
+
if (!parsed.success)
|
|
60
|
+
return false;
|
|
61
|
+
return (parsed.data.hooks?.Stop ?? []).some((group) => (group.hooks ?? []).some((hook) => hook.asyncRewake === true && /\bbridge\s+wait\b/.test(hook.command ?? '')));
|
|
62
|
+
}
|
|
63
|
+
const HookGroupsSchema = z
|
|
64
|
+
.array(z.object({
|
|
65
|
+
hooks: z
|
|
66
|
+
.array(z.object({ command: z.string().optional(), asyncRewake: z.boolean().optional() }))
|
|
67
|
+
.optional(),
|
|
68
|
+
}))
|
|
69
|
+
.optional();
|
|
70
|
+
const SettingsSchema = z.object({
|
|
71
|
+
hooks: z.object({ Stop: HookGroupsSchema, PreToolUse: HookGroupsSchema }).optional(),
|
|
72
|
+
});
|
|
73
|
+
/** How a Claude Code session names the tools of the bridge's server, and what rules match them by. */
|
|
74
|
+
export const CLAUDE_TOOLS_PREFIX = `mcp__${BRIDGE_TOOLS_SERVER}`;
|
|
75
|
+
/** The permission rule that lets a session call the bridge's tools without a prompt. */
|
|
76
|
+
export const CLAUDE_TOOLS_PERMISSION = CLAUDE_TOOLS_PREFIX;
|
|
77
|
+
/** Seconds the hook that names the session of a tool call may take. */
|
|
78
|
+
const CALLER_HOOK_TIMEOUT_S = 15;
|
|
79
|
+
/** The command a hook of a Claude Code session runs before a call of a bridge tool. */
|
|
80
|
+
export function claudeCallerCommand(options = {}) {
|
|
81
|
+
return `${options.bridgeCommand ?? 'cogitator bridge'} caller --hook ${HARNESSES.claudeCode}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The settings that tell the bridge's tools which Claude Code session calls them: a `PreToolUse`
|
|
85
|
+
* hook on the tools of the bridge's server that adds the session to the arguments of the call.
|
|
86
|
+
* Claude Code starts the server once and keeps it across `/clear`, so the session the server was
|
|
87
|
+
* started for is not always the one that calls. Without the hook the tools go by that first
|
|
88
|
+
* session.
|
|
89
|
+
*/
|
|
90
|
+
export function claudeToolsHook(options = {}) {
|
|
91
|
+
return {
|
|
92
|
+
hooks: {
|
|
93
|
+
PreToolUse: [
|
|
94
|
+
{
|
|
95
|
+
matcher: `${CLAUDE_TOOLS_PREFIX}__.*`,
|
|
96
|
+
hooks: [
|
|
97
|
+
{
|
|
98
|
+
type: 'command',
|
|
99
|
+
command: claudeCallerCommand(options),
|
|
100
|
+
timeout: CALLER_HOOK_TIMEOUT_S,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Whether Claude Code settings hold the hook that names the session of a bridge tool call. */
|
|
109
|
+
export function hasClaudeToolsHook(settings) {
|
|
110
|
+
const parsed = SettingsSchema.safeParse(settings);
|
|
111
|
+
if (!parsed.success)
|
|
112
|
+
return false;
|
|
113
|
+
return (parsed.data.hooks?.PreToolUse ?? []).some((group) => (group.hooks ?? []).some((hook) => /\bbridge\s+caller\b/.test(hook.command ?? '')));
|
|
114
|
+
}
|
|
115
|
+
const ToolHookInputSchema = z.object({
|
|
116
|
+
session_id: z.string().min(1),
|
|
117
|
+
cwd: z.string().min(1).optional(),
|
|
118
|
+
tool_input: z.record(z.string(), z.unknown()),
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* What the hook of `claudeToolsHook` answers Claude Code with: the arguments of the call with
|
|
122
|
+
* the session that makes it added (`hookSpecificOutput.updatedInput`). Undefined when the input
|
|
123
|
+
* is not that of a `PreToolUse` hook, and the call goes on as the model wrote it.
|
|
124
|
+
*
|
|
125
|
+
* @param hookInput what Claude Code wrote to the hook's stdin
|
|
126
|
+
*/
|
|
127
|
+
export function claudeToolCallHook(hookInput) {
|
|
128
|
+
let input;
|
|
129
|
+
try {
|
|
130
|
+
input = JSON.parse(hookInput);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
const parsed = ToolHookInputSchema.safeParse(input);
|
|
136
|
+
if (!parsed.success)
|
|
137
|
+
return undefined;
|
|
138
|
+
const { session_id: session, cwd, tool_input: args } = parsed.data;
|
|
139
|
+
const hint = {
|
|
140
|
+
harness: HARNESSES.claudeCode,
|
|
141
|
+
session,
|
|
142
|
+
...(cwd && { cwd: resolve(cwd) }),
|
|
143
|
+
};
|
|
144
|
+
return JSON.stringify({
|
|
145
|
+
hookSpecificOutput: {
|
|
146
|
+
hookEventName: 'PreToolUse',
|
|
147
|
+
updatedInput: { ...args, [TOOL_CALL_HINT_KEY]: hint },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const HookInputSchema = z.object({
|
|
152
|
+
session_id: z.string().min(1),
|
|
153
|
+
cwd: z.string().min(1).optional(),
|
|
154
|
+
});
|
|
155
|
+
const ListedSessionSchema = z.object({
|
|
156
|
+
id: z.string().optional(),
|
|
157
|
+
sessionId: z.string().optional(),
|
|
158
|
+
cwd: z.string().optional(),
|
|
159
|
+
name: z.string().optional(),
|
|
160
|
+
pid: z.number().optional(),
|
|
161
|
+
status: z.string().optional(),
|
|
162
|
+
state: z.string().optional(),
|
|
163
|
+
});
|
|
164
|
+
const ServersSchema = z.record(z.string(), z.unknown()).optional();
|
|
165
|
+
const TrustConfigSchema = z.object({
|
|
166
|
+
projects: z
|
|
167
|
+
.record(z.string(), z.object({ hasTrustDialogAccepted: z.boolean().optional(), mcpServers: ServersSchema }))
|
|
168
|
+
.optional(),
|
|
169
|
+
mcpServers: ServersSchema,
|
|
170
|
+
});
|
|
171
|
+
const ProjectServersSchema = z.object({ mcpServers: ServersSchema });
|
|
172
|
+
/**
|
|
173
|
+
* Where Claude Code has the bridge's server of tools for the sessions of a folder: `local`
|
|
174
|
+
* (this person, this project), `project` (the project's `.mcp.json`) or `user` (this person,
|
|
175
|
+
* every project). Undefined when it has it nowhere.
|
|
176
|
+
*/
|
|
177
|
+
export function claudeToolsScope(folder, configPath = join(homedir(), '.claude.json')) {
|
|
178
|
+
const config = TrustConfigSchema.safeParse(readJson(configPath));
|
|
179
|
+
const projects = config.success ? (config.data.projects ?? {}) : {};
|
|
180
|
+
const folders = spellingsOf(folder).flatMap((start) => {
|
|
181
|
+
const up = [];
|
|
182
|
+
for (let current = start;; current = dirname(current)) {
|
|
183
|
+
up.push(current);
|
|
184
|
+
if (dirname(current) === current)
|
|
185
|
+
return up;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (folders.some((dir) => projects[dir]?.mcpServers?.[BRIDGE_TOOLS_SERVER] !== undefined)) {
|
|
189
|
+
return 'local';
|
|
190
|
+
}
|
|
191
|
+
const shared = folders.some((dir) => {
|
|
192
|
+
const file = ProjectServersSchema.safeParse(readJson(join(dir, '.mcp.json')));
|
|
193
|
+
return file.success && file.data.mcpServers?.[BRIDGE_TOOLS_SERVER] !== undefined;
|
|
194
|
+
});
|
|
195
|
+
if (shared)
|
|
196
|
+
return 'project';
|
|
197
|
+
return config.success && config.data.mcpServers?.[BRIDGE_TOOLS_SERVER] !== undefined
|
|
198
|
+
? 'user'
|
|
199
|
+
: undefined;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The ways a folder may be written in what Claude Code keeps: by its real path, which is how
|
|
203
|
+
* Claude Code names a project, and as it was given.
|
|
204
|
+
*/
|
|
205
|
+
function spellingsOf(folder) {
|
|
206
|
+
return [...new Set([canonicalPath(folder), resolve(folder)])];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Whether Claude Code trusts a folder, read from where it records that a person accepted its
|
|
210
|
+
* trust prompt (`projects[<folder>].hasTrustDialogAccepted` in `~/.claude.json`). Trust of a
|
|
211
|
+
* folder covers the folders inside it. `unknown` when the record cannot be read.
|
|
212
|
+
*/
|
|
213
|
+
export function claudeTrust(folder, configPath = join(homedir(), '.claude.json')) {
|
|
214
|
+
let config;
|
|
215
|
+
try {
|
|
216
|
+
const parsed = TrustConfigSchema.safeParse(JSON.parse(readFileSync(configPath, 'utf8')));
|
|
217
|
+
if (!parsed.success)
|
|
218
|
+
return 'unknown';
|
|
219
|
+
config = parsed.data;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return 'unknown';
|
|
223
|
+
}
|
|
224
|
+
const projects = config.projects ?? {};
|
|
225
|
+
for (let current = resolve(folder);; current = dirname(current)) {
|
|
226
|
+
if (projects[current]?.hasTrustDialogAccepted)
|
|
227
|
+
return 'trusted';
|
|
228
|
+
if (dirname(current) === current)
|
|
229
|
+
return 'untrusted';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** What sets a project up for the sessions a person opens in it. */
|
|
233
|
+
const INSTALL = 'cogitator bridge install claude';
|
|
234
|
+
const DEFAULT_SESSION_LISTED_MS = 30_000;
|
|
235
|
+
const LISTING_INTERVAL_MS = 300;
|
|
236
|
+
/** How `claude agents --json` marks a background session that died before it began */
|
|
237
|
+
const FAILED_STATE = 'failed';
|
|
238
|
+
const SHORT_ID = /backgrounded\s*[·:-]?\s*([0-9a-f]{6,})\b/i;
|
|
239
|
+
function untrusted(folder) {
|
|
240
|
+
return new Error(`Claude Code does not trust ${folder} yet. Open the folder in Claude Code once and accept its trust prompt, then hand the job over again`);
|
|
241
|
+
}
|
|
242
|
+
function readJson(path) {
|
|
243
|
+
try {
|
|
244
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Reaches Claude Code sessions in their own windows. A session started for a job runs in the
|
|
252
|
+
* background of Claude Code (`claude --bg`): `claude attach` opens it, `claude agents` lists it.
|
|
253
|
+
* Letters reach a session through a hook of its own: after every turn the hook waits at the
|
|
254
|
+
* bridge (`cogitator bridge wait`) and wakes the session with the mail, so nothing is pushed
|
|
255
|
+
* into a window from outside and the session stays free to talk to. A session the bridge starts
|
|
256
|
+
* carries the hook itself. One opened by a person needs it in the project's settings, see
|
|
257
|
+
* `claudeWaitHook`.
|
|
258
|
+
*/
|
|
259
|
+
export function claudeCodeAdapter(options = {}) {
|
|
260
|
+
const command = options.command ?? 'claude';
|
|
261
|
+
const env = options.env ?? process.env;
|
|
262
|
+
const configDir = env.CLAUDE_CONFIG_DIR?.trim();
|
|
263
|
+
const configPath = options.configPath ?? join(configDir || homedir(), '.claude.json');
|
|
264
|
+
const userSettingsPath = options.userSettingsPath ?? join(configDir || join(homedir(), '.claude'), 'settings.json');
|
|
265
|
+
const bridgeHome = options.bridgeHome ?? (env.COGITATOR_BRIDGE_HOME?.trim() || undefined);
|
|
266
|
+
const hook = {
|
|
267
|
+
...(bridgeHome !== undefined && { bridgeHome }),
|
|
268
|
+
...(options.bridgeCommand !== undefined && { bridgeCommand: options.bridgeCommand }),
|
|
269
|
+
...(options.hookTimeoutS !== undefined && { timeoutS: options.hookTimeoutS }),
|
|
270
|
+
};
|
|
271
|
+
async function listed() {
|
|
272
|
+
const result = await runCommand(command, ['agents', '--json', '--all'], { env });
|
|
273
|
+
if (result.code !== 0)
|
|
274
|
+
throw new Error(`claude agents --json failed: ${failureOf(result)}`);
|
|
275
|
+
const parsed = z.array(ListedSessionSchema).safeParse(JSON.parse(result.stdout || '[]'));
|
|
276
|
+
if (!parsed.success)
|
|
277
|
+
throw new Error('claude agents --json printed something the bridge cannot read');
|
|
278
|
+
return parsed.data;
|
|
279
|
+
}
|
|
280
|
+
async function sessionOf(shortId) {
|
|
281
|
+
const deadline = Date.now() + (options.sessionListedMs ?? DEFAULT_SESSION_LISTED_MS);
|
|
282
|
+
for (;;) {
|
|
283
|
+
const session = (await listed()).find((candidate) => candidate.id === shortId);
|
|
284
|
+
if (session?.state === FAILED_STATE) {
|
|
285
|
+
throw new Error(`Claude Code started the background session ${shortId}, and it failed before its first turn`);
|
|
286
|
+
}
|
|
287
|
+
if (session?.sessionId) {
|
|
288
|
+
return { sessionId: session.sessionId };
|
|
289
|
+
}
|
|
290
|
+
if (Date.now() >= deadline) {
|
|
291
|
+
throw new Error(`Claude Code started the background session ${shortId}, but it never showed up in claude agents --json`);
|
|
292
|
+
}
|
|
293
|
+
await pause(LISTING_INTERVAL_MS);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* `--mcp-config` takes every argument up to the next option, so it stands before `--settings`
|
|
298
|
+
* and never right before the first letter, which it would read as one more file of servers.
|
|
299
|
+
*/
|
|
300
|
+
async function createSession(request) {
|
|
301
|
+
if (claudeTrust(request.cwd, configPath) === 'untrusted')
|
|
302
|
+
throw untrusted(request.cwd);
|
|
303
|
+
const whole = fitsArgument(request.firstLetter.text);
|
|
304
|
+
const tools = options.toolsServer;
|
|
305
|
+
const waits = claudeWaitHook({ ...hook, agentName: request.agentName, tools: !!tools });
|
|
306
|
+
const settings = tools
|
|
307
|
+
? {
|
|
308
|
+
hooks: { ...waits.hooks, ...claudeToolsHook(hook).hooks },
|
|
309
|
+
permissions: { allow: [CLAUDE_TOOLS_PERMISSION] },
|
|
310
|
+
}
|
|
311
|
+
: waits;
|
|
312
|
+
const servers = tools && {
|
|
313
|
+
mcpServers: {
|
|
314
|
+
[BRIDGE_TOOLS_SERVER]: {
|
|
315
|
+
command: tools.command,
|
|
316
|
+
args: [...tools.args],
|
|
317
|
+
env: toolsServerEnv({
|
|
318
|
+
harness: HARNESSES.claudeCode,
|
|
319
|
+
agentName: request.agentName,
|
|
320
|
+
...(request.sessionName && { sessionName: request.sessionName }),
|
|
321
|
+
}),
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
const result = await runCommand(command, [
|
|
326
|
+
'--bg',
|
|
327
|
+
...(servers ? ['--mcp-config', JSON.stringify(servers)] : []),
|
|
328
|
+
'--settings',
|
|
329
|
+
JSON.stringify(settings),
|
|
330
|
+
...(request.sessionName ? ['--name', request.sessionName] : []),
|
|
331
|
+
...(options.permissionMode ? ['--permission-mode', options.permissionMode] : []),
|
|
332
|
+
...(options.sessionArgs ?? []),
|
|
333
|
+
whole
|
|
334
|
+
? request.firstLetter.text
|
|
335
|
+
: tooLongNotice(request.firstLetter, {
|
|
336
|
+
...(options.bridgeCommand !== undefined && { bridgeCommand: options.bridgeCommand }),
|
|
337
|
+
...(bridgeHome !== undefined && { bridgeHome }),
|
|
338
|
+
tools: !!tools,
|
|
339
|
+
}),
|
|
340
|
+
], {
|
|
341
|
+
cwd: request.cwd,
|
|
342
|
+
env: sessionEnv(env, {
|
|
343
|
+
harness: HARNESSES.claudeCode,
|
|
344
|
+
agentName: request.agentName,
|
|
345
|
+
...(request.sessionName && { sessionName: request.sessionName }),
|
|
346
|
+
}),
|
|
347
|
+
});
|
|
348
|
+
if (result.code !== 0) {
|
|
349
|
+
if (/not trusted/i.test(result.stderr))
|
|
350
|
+
throw untrusted(request.cwd);
|
|
351
|
+
throw new Error(`claude --bg failed: ${failureOf(result)}`);
|
|
352
|
+
}
|
|
353
|
+
const shortId = SHORT_ID.exec(result.stdout)?.[1];
|
|
354
|
+
if (!shortId) {
|
|
355
|
+
throw new Error(`claude --bg did not say which session it started: ${failureOf({ ...result, stderr: '' })}`);
|
|
356
|
+
}
|
|
357
|
+
let session;
|
|
358
|
+
try {
|
|
359
|
+
session = await sessionOf(shortId);
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
await runCommand(command, ['stop', shortId], { env }).catch(() => undefined);
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
sessionId: session.sessionId,
|
|
367
|
+
...(request.sessionName && { sessionName: request.sessionName }),
|
|
368
|
+
deliveredFirstLetter: whole,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The sessions whose process is alive. Background sessions that finished are asked for too
|
|
373
|
+
* (`--all`) and told apart by their process, so a session is never missed for being between
|
|
374
|
+
* two turns
|
|
375
|
+
*/
|
|
376
|
+
async function liveSessions() {
|
|
377
|
+
let sessions;
|
|
378
|
+
try {
|
|
379
|
+
sessions = await listed();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
if (error instanceof CommandMissingError)
|
|
383
|
+
return [];
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
return sessions.flatMap((session) => session.sessionId && (session.pid !== undefined || session.status !== undefined)
|
|
387
|
+
? [
|
|
388
|
+
{
|
|
389
|
+
sessionId: session.sessionId,
|
|
390
|
+
...(session.cwd && { cwd: session.cwd }),
|
|
391
|
+
...(session.name && { name: session.name }),
|
|
392
|
+
...(session.status && { busy: session.status === 'busy' }),
|
|
393
|
+
},
|
|
394
|
+
]
|
|
395
|
+
: []);
|
|
396
|
+
}
|
|
397
|
+
function identify(context) {
|
|
398
|
+
let sessionId = context.env.CLAUDE_CODE_SESSION_ID?.trim();
|
|
399
|
+
let cwd = context.cwd;
|
|
400
|
+
if (context.hookInput !== undefined) {
|
|
401
|
+
let input;
|
|
402
|
+
try {
|
|
403
|
+
input = JSON.parse(context.hookInput);
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
input = undefined;
|
|
407
|
+
}
|
|
408
|
+
const parsed = HookInputSchema.safeParse(input);
|
|
409
|
+
if (parsed.success) {
|
|
410
|
+
sessionId = parsed.data.session_id;
|
|
411
|
+
cwd = parsed.data.cwd ?? cwd;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (!sessionId)
|
|
415
|
+
return undefined;
|
|
416
|
+
const folder = resolve(cwd);
|
|
417
|
+
return {
|
|
418
|
+
harness: HARNESSES.claudeCode,
|
|
419
|
+
sessionId,
|
|
420
|
+
cwd: folder,
|
|
421
|
+
project: findProjectRoot(folder),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
async function health(context) {
|
|
425
|
+
const checks = [];
|
|
426
|
+
let help;
|
|
427
|
+
try {
|
|
428
|
+
const version = await runCommand(command, ['--version'], { env });
|
|
429
|
+
if (version.code !== 0)
|
|
430
|
+
throw new Error(failureOf(version));
|
|
431
|
+
checks.push({
|
|
432
|
+
id: 'version',
|
|
433
|
+
title: 'Claude Code',
|
|
434
|
+
status: 'ok',
|
|
435
|
+
detail: version.stdout.trim(),
|
|
436
|
+
});
|
|
437
|
+
help = (await runCommand(command, ['--help'], { env })).stdout;
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
checks.push({
|
|
441
|
+
id: 'version',
|
|
442
|
+
title: 'Claude Code',
|
|
443
|
+
status: 'fail',
|
|
444
|
+
detail: error instanceof CommandMissingError ? error.message : String(error),
|
|
445
|
+
fix: 'Install Claude Code: https://claude.com/claude-code',
|
|
446
|
+
});
|
|
447
|
+
return checks;
|
|
448
|
+
}
|
|
449
|
+
const background = /--bg\b/.test(help) && /--settings\b/.test(help);
|
|
450
|
+
checks.push({
|
|
451
|
+
id: 'background',
|
|
452
|
+
title: 'Background sessions',
|
|
453
|
+
status: background ? 'ok' : 'fail',
|
|
454
|
+
detail: background
|
|
455
|
+
? 'claude --bg and --settings are there'
|
|
456
|
+
: 'this version has no claude --bg or no --settings: the bridge cannot start sessions',
|
|
457
|
+
...(!background && { fix: 'Update Claude Code: claude update' }),
|
|
458
|
+
});
|
|
459
|
+
const agentsHelp = (await runCommand(command, ['agents', '--help'], { env })).stdout;
|
|
460
|
+
const listing = /--json\b/.test(agentsHelp);
|
|
461
|
+
checks.push({
|
|
462
|
+
id: 'sessions',
|
|
463
|
+
title: 'Session list',
|
|
464
|
+
status: listing ? 'ok' : 'fail',
|
|
465
|
+
detail: listing
|
|
466
|
+
? 'claude agents --json is there'
|
|
467
|
+
: 'this version has no claude agents --json: the bridge cannot find the sessions it starts',
|
|
468
|
+
...(!listing && { fix: 'Update Claude Code: claude update' }),
|
|
469
|
+
});
|
|
470
|
+
const trust = claudeTrust(context.cwd, configPath);
|
|
471
|
+
checks.push({
|
|
472
|
+
id: 'trust',
|
|
473
|
+
title: 'Folder trust',
|
|
474
|
+
status: trust === 'trusted' ? 'ok' : 'warn',
|
|
475
|
+
detail: trust === 'trusted'
|
|
476
|
+
? `Claude Code trusts ${context.cwd}`
|
|
477
|
+
: trust === 'untrusted'
|
|
478
|
+
? `Claude Code does not trust ${context.cwd}: the bridge cannot start sessions in it`
|
|
479
|
+
: `could not read whether Claude Code trusts ${context.cwd}`,
|
|
480
|
+
...(trust !== 'trusted' && {
|
|
481
|
+
fix: 'Open the folder in Claude Code once and accept its trust prompt',
|
|
482
|
+
}),
|
|
483
|
+
});
|
|
484
|
+
const places = [
|
|
485
|
+
join(context.cwd, '.claude', 'settings.local.json'),
|
|
486
|
+
join(context.cwd, '.claude', 'settings.json'),
|
|
487
|
+
userSettingsPath,
|
|
488
|
+
];
|
|
489
|
+
const armed = places.find((place) => hasClaudeWaitHook(readJson(place)));
|
|
490
|
+
checks.push({
|
|
491
|
+
id: 'hook',
|
|
492
|
+
title: 'Wake hook',
|
|
493
|
+
status: armed ? 'ok' : 'warn',
|
|
494
|
+
detail: armed
|
|
495
|
+
? `sessions opened in this folder wait for their mail (${armed})`
|
|
496
|
+
: 'sessions a person opens in this folder do not wake for mail, they read it when asked. Sessions the bridge starts carry the hook themselves',
|
|
497
|
+
...(!armed && { fix: INSTALL }),
|
|
498
|
+
});
|
|
499
|
+
const scope = claudeToolsScope(context.cwd, configPath);
|
|
500
|
+
checks.push({
|
|
501
|
+
id: 'tools',
|
|
502
|
+
title: 'Bridge tools',
|
|
503
|
+
status: scope ? 'ok' : 'warn',
|
|
504
|
+
detail: scope
|
|
505
|
+
? `sessions opened in this folder have the bridge's tools (${scope} config)`
|
|
506
|
+
: 'sessions a person opens in this folder have no bridge tools, they use its command line. Sessions the bridge starts get the tools themselves',
|
|
507
|
+
...(!scope && { fix: INSTALL }),
|
|
508
|
+
});
|
|
509
|
+
if (scope) {
|
|
510
|
+
const named = places.find((place) => hasClaudeToolsHook(readJson(place)));
|
|
511
|
+
checks.push({
|
|
512
|
+
id: 'caller',
|
|
513
|
+
title: 'Session of a tool call',
|
|
514
|
+
status: named ? 'ok' : 'warn',
|
|
515
|
+
detail: named
|
|
516
|
+
? `a hook tells the tools which session calls them (${named})`
|
|
517
|
+
: 'the tools go by the session their server was started for: after /clear they act as the session before it',
|
|
518
|
+
...(!named && { fix: INSTALL }),
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
return checks;
|
|
522
|
+
}
|
|
523
|
+
function toolCallHook(context) {
|
|
524
|
+
return context.hookInput === undefined ? undefined : claudeToolCallHook(context.hookInput);
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
harness: HARNESSES.claudeCode,
|
|
528
|
+
delivery: CLAUDE_DELIVERY,
|
|
529
|
+
capabilities: { createSession: true, push: true, steer: false, nativeWindow: true },
|
|
530
|
+
createSession,
|
|
531
|
+
liveSessions,
|
|
532
|
+
identify,
|
|
533
|
+
toolCallHook,
|
|
534
|
+
health,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
//# sourceMappingURL=claude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/adapters/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAqB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,KAAK,EACL,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,GACd,MAAM,WAAW,C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,YAAY,EAAE,IAAI,EAAE;QACnF,aAAa;QACb,YAAY;QACZ,QAAQ;QACR,YAAY;QACZ,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { BridgeAdapter } from '../adapter.js';
|
|
2
|
+
import { type ToolsServerCommand } from './tools-server.js';
|
|
3
|
+
/** How letters reach a Codex thread: the thread's own message queue. */
|
|
4
|
+
export declare const CODEX_DELIVERY = "queue";
|
|
5
|
+
export type CodexSandbox = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
6
|
+
export interface CodexAdapterOptions {
|
|
7
|
+
/** The Codex executable, `codex` on `PATH` by default */
|
|
8
|
+
command?: string;
|
|
9
|
+
/** The environment of the commands and of the sessions it starts, `process.env` by default */
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
/** How a session runs the bridge's command line, `cogitator bridge` by default */
|
|
12
|
+
bridgeCommand?: string;
|
|
13
|
+
/** The sandbox of the sessions it starts, `workspace-write` by default */
|
|
14
|
+
sandbox?: CodexSandbox;
|
|
15
|
+
/** More arguments for `codex exec`, such as `['--model', 'gpt-5']` */
|
|
16
|
+
sessionArgs?: readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* Where the output of the sessions it starts goes, one file a session, `sessions` in the
|
|
19
|
+
* bridge's folder by default. A session writes there and not to the dispatcher, so it works on
|
|
20
|
+
* when the dispatcher stops
|
|
21
|
+
*/
|
|
22
|
+
logDir?: string;
|
|
23
|
+
/** How long a started session may take to say its thread id, 60 s by default */
|
|
24
|
+
threadStartedMs?: number;
|
|
25
|
+
/** Hears what went wrong outside a call of the bridge: a report that could not be sent */
|
|
26
|
+
onError?: (error: Error) => void;
|
|
27
|
+
/**
|
|
28
|
+
* How a thread starts the bridge's server of tools. With it the threads the adapter starts
|
|
29
|
+
* get the tools, whatever the configuration of Codex has. Codex runs such a server outside
|
|
30
|
+
* the sandbox of the thread, so the tools reach the bridge where the command line cannot
|
|
31
|
+
*/
|
|
32
|
+
toolsServer?: ToolsServerCommand;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What the journal says of a letter Codex queued with no local daemon to resume the thread.
|
|
36
|
+
* `codex queue --resume` warns the same whether the Codex app has the thread open or nobody
|
|
37
|
+
* does, so the note names both cases.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CODEX_NOT_RESUMED_NOTE: string;
|
|
40
|
+
/** The id of the thread `codex exec --json` says it started, when its output has it already. */
|
|
41
|
+
export declare function codexThreadId(output: string): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* What a thread the bridge starts reads under its first letter. A thread without the bridge's
|
|
44
|
+
* tools often cannot reach the bridge from its sandbox, so the bridge reports for it. One with
|
|
45
|
+
* the tools reports itself, and the bridge still does when its turn ends without a report.
|
|
46
|
+
*/
|
|
47
|
+
export declare function codexReportNotice(job: number, tools?: boolean): string;
|
|
48
|
+
/**
|
|
49
|
+
* The arguments that give one `codex exec` the bridge's server of tools, over whatever the
|
|
50
|
+
* configuration of Codex says of a server of that name.
|
|
51
|
+
*/
|
|
52
|
+
export declare function codexToolsServerArgs(server: ToolsServerCommand, env?: Readonly<Record<string, string>>): string[];
|
|
53
|
+
/**
|
|
54
|
+
* What a `codex exec` that ended leaves to report: the last message of the thread, or why the
|
|
55
|
+
* turn failed. `output` is what it wrote with `--json`, `code` its exit code, null after a signal.
|
|
56
|
+
*/
|
|
57
|
+
export declare function codexTurnReport(output: string, code: number | null): {
|
|
58
|
+
body: string;
|
|
59
|
+
failed: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Reaches Codex threads in their own windows. A letter goes into the thread's message queue
|
|
63
|
+
* (`codex queue --resume`): a thread open in the Codex app takes it by itself within seconds,
|
|
64
|
+
* one that is open nowhere needs the local daemon (`codex app-server daemon start`), which the
|
|
65
|
+
* bridge never starts on its own. A session for a job is a thread of `codex exec`, started with
|
|
66
|
+
* the job's first letter and left to finish its turn by itself. Such a thread works in a sandbox
|
|
67
|
+
* that usually keeps it from the bridge, so when its turn ends and it wrote nothing on the job
|
|
68
|
+
* itself, the adapter sends its final answer as the report, or what failed when the turn failed.
|
|
69
|
+
*/
|
|
70
|
+
export declare function codexAdapter(options?: CodexAdapterOptions): BridgeAdapter;
|
|
71
|
+
//# sourceMappingURL=codex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/adapters/codex.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EAQd,MAAM,eAAe,CAAC;AAavB,OAAO,EAAuC,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEjG,wEAAwE;AACxE,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAElF,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,kFAAkF;IAClF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,sEAAsE;IACtE,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAOD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAGrB,CAAC;AAiCf,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SA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