@aisac/cli 0.4.0-beta.21 → 0.4.0-beta.22
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 +32 -1
- package/dist/assets/codex-context-compaction.mjs +603 -9
- package/dist/assets/jev-paid-pilot-terminal.mjs +6 -1
- package/dist/claude-observation.mjs +1 -1
- package/dist/cli.mjs +61 -4
- package/dist/engineering-pack.mjs +21 -4
- package/dist/extensions-catalog.mjs +18 -1
- package/dist/guardrails/guards.mjs +1144 -36
- package/dist/launch.mjs +132 -20
- package/dist/manager/bus.mjs +1921 -0
- package/dist/manager/delegation.mjs +354 -0
- package/dist/manager/hooks.mjs +918 -0
- package/dist/manager/launch-role.mjs +476 -0
- package/dist/manager/mcp-stdio.mjs +463 -0
- package/dist/manager/messages.mjs +791 -0
- package/dist/manager/reserve.mjs +2166 -0
- package/dist/manager/room.mjs +106 -0
- package/dist/manager/server.mjs +1792 -0
- package/dist/manager/status.mjs +118 -0
- package/dist/manager/watch.mjs +87 -0
- package/dist/manager/worker.mjs +2793 -0
- package/dist/manager/workers-cli.mjs +1403 -0
- package/dist/package.json +1 -1
- package/dist/release-manifest.json +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
// The launcher's part of the manager feature (spec aisac-engineering-manager
|
|
2
|
+
// D2, D11, D14, FR1, FR2, FR6, FR8): the `--manager`, `--worker` and `--room`
|
|
3
|
+
// flags, the registration of the session, and what the launch hands to the
|
|
4
|
+
// role process. A role lasts one launch, never blocks one, and reaches its
|
|
5
|
+
// process only through the environment the launcher writes.
|
|
6
|
+
|
|
7
|
+
import { readdir } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import {
|
|
10
|
+
BusError,
|
|
11
|
+
MANAGER_NAME,
|
|
12
|
+
MANAGER_ROLE_ENV,
|
|
13
|
+
NAME_PATTERN,
|
|
14
|
+
WORKER_MODULE_ENV,
|
|
15
|
+
WORKER_ROLE_ENV,
|
|
16
|
+
audit,
|
|
17
|
+
ensureRoom,
|
|
18
|
+
listRooms,
|
|
19
|
+
listSessions,
|
|
20
|
+
newSessionId,
|
|
21
|
+
registerSession,
|
|
22
|
+
removeSession,
|
|
23
|
+
roleEnvironmentValue,
|
|
24
|
+
sweepBus,
|
|
25
|
+
} from './bus.mjs';
|
|
26
|
+
import { MESSAGE_FILE_PATTERN } from './messages.mjs';
|
|
27
|
+
import { resolveRoom } from './room.mjs';
|
|
28
|
+
|
|
29
|
+
export const MANAGER_FLAG = '--manager';
|
|
30
|
+
export const WORKER_FLAG = '--worker';
|
|
31
|
+
export const ROOM_FLAG = '--room';
|
|
32
|
+
/** The name of the manager's stdio MCP server in the session's `mcp.json` (FR6). */
|
|
33
|
+
export const MANAGER_SERVER_NAME = 'aisac_manager';
|
|
34
|
+
/**
|
|
35
|
+
* The tools the launcher pre-allows (FR8): the three that only read, and
|
|
36
|
+
* `manager_decide`, whose authorization is the user's delegation (Q12).
|
|
37
|
+
* `manager_send` and `manager_cancel` are left to the host's permission flow.
|
|
38
|
+
*/
|
|
39
|
+
export const MANAGER_ALLOWED_TOOLS = Object.freeze([
|
|
40
|
+
'manager_workers',
|
|
41
|
+
'manager_wait',
|
|
42
|
+
'manager_read',
|
|
43
|
+
'manager_decide',
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* The Codex versions the worker role was measured with (D14). Another version
|
|
47
|
+
* starts Codex without the role; the release qualification adds to this list.
|
|
48
|
+
*/
|
|
49
|
+
export const MEASURED_WORKER_CODEX_VERSIONS = Object.freeze(['0.166.0']);
|
|
50
|
+
|
|
51
|
+
const USAGE_EXIT_CODE = 2;
|
|
52
|
+
/** Registration failures that stop the launch before any host starts (FR1). */
|
|
53
|
+
const REFUSED_REGISTRATIONS = ['worker_name_taken', 'manager_already_active', 'room_full'];
|
|
54
|
+
/** The Codex subcommands a worker runs under: none (the terminal), `resume` and `fork`. */
|
|
55
|
+
const WORKER_CODEX_SUBCOMMANDS = new Set(['resume', 'fork']);
|
|
56
|
+
/**
|
|
57
|
+
* The other subcommands of Codex 0.166.0, the only version measured with the role
|
|
58
|
+
* (D14). None opens the terminal bridge's socket, so no adapter would run the role.
|
|
59
|
+
* A first word not listed here is the prompt.
|
|
60
|
+
*/
|
|
61
|
+
const CODEX_SUBCOMMANDS = new Set([
|
|
62
|
+
'a',
|
|
63
|
+
'agents',
|
|
64
|
+
'app',
|
|
65
|
+
'app-server',
|
|
66
|
+
'apply',
|
|
67
|
+
'archive',
|
|
68
|
+
'cloud',
|
|
69
|
+
'cloud-tasks',
|
|
70
|
+
'completion',
|
|
71
|
+
'debug',
|
|
72
|
+
'delete',
|
|
73
|
+
'doctor',
|
|
74
|
+
'e',
|
|
75
|
+
'exec',
|
|
76
|
+
'exec-server',
|
|
77
|
+
'execpolicy',
|
|
78
|
+
'features',
|
|
79
|
+
'help',
|
|
80
|
+
'history',
|
|
81
|
+
'login',
|
|
82
|
+
'logout',
|
|
83
|
+
'mcp',
|
|
84
|
+
'mcp-server',
|
|
85
|
+
'migrate-nfs-db',
|
|
86
|
+
'plugin',
|
|
87
|
+
'queue',
|
|
88
|
+
'remote-control',
|
|
89
|
+
'responses-api-proxy',
|
|
90
|
+
'review',
|
|
91
|
+
'sandbox',
|
|
92
|
+
'stdio-to-uds',
|
|
93
|
+
'tcp-tunnel',
|
|
94
|
+
'unarchive',
|
|
95
|
+
'update',
|
|
96
|
+
]);
|
|
97
|
+
/** The options of the Codex command line that take the next argument as their value. */
|
|
98
|
+
const CODEX_VALUE_OPTIONS = new Set([
|
|
99
|
+
'-c',
|
|
100
|
+
'--config',
|
|
101
|
+
'--enable',
|
|
102
|
+
'--disable',
|
|
103
|
+
'-i',
|
|
104
|
+
'--image',
|
|
105
|
+
'-m',
|
|
106
|
+
'--model',
|
|
107
|
+
'--local-provider',
|
|
108
|
+
'-p',
|
|
109
|
+
'--profile',
|
|
110
|
+
'-s',
|
|
111
|
+
'--sandbox',
|
|
112
|
+
'-a',
|
|
113
|
+
'--ask-for-approval',
|
|
114
|
+
'-C',
|
|
115
|
+
'--cd',
|
|
116
|
+
'--add-dir',
|
|
117
|
+
'--remote',
|
|
118
|
+
'--remote-auth-token-env',
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
/** @typedef {import('./bus.mjs').BusLocale} BusLocale */
|
|
122
|
+
/** @typedef {import('./bus.mjs').RoomPaths} RoomPaths */
|
|
123
|
+
/** @typedef {import('./bus.mjs').SessionRecord} SessionRecord */
|
|
124
|
+
/** @typedef {{ kind: 'manager' } | { kind: 'worker', name: string }} RoleFlag */
|
|
125
|
+
/**
|
|
126
|
+
* @typedef {object} RoleRequest
|
|
127
|
+
* @property {RoleFlag} role
|
|
128
|
+
* @property {string | null} roomName
|
|
129
|
+
*/
|
|
130
|
+
/**
|
|
131
|
+
* @typedef {object} ActiveRole
|
|
132
|
+
* @property {true} active
|
|
133
|
+
* @property {'manager' | 'worker'} kind
|
|
134
|
+
* @property {string} name
|
|
135
|
+
* @property {string} roomLabel
|
|
136
|
+
* @property {RoomPaths} paths
|
|
137
|
+
* @property {string} sessionId
|
|
138
|
+
* @property {string} environmentValue the JSON the role process parses
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* @typedef {object} InactiveRole
|
|
142
|
+
* @property {false} active
|
|
143
|
+
* @property {'manager' | 'worker'} kind
|
|
144
|
+
* @property {'license_inactive' | 'host_unqualified' | 'bus_unavailable'} reason
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/** @param {string} code @returns {never} */
|
|
148
|
+
function usageError(code) {
|
|
149
|
+
throw Object.assign(new Error(code), { exitCode: USAGE_EXIT_CODE });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The value of a flag given as `--flag value` or `--flag=value`.
|
|
154
|
+
* @param {string[]} args @param {number} index @param {string} flag
|
|
155
|
+
* @returns {{ value: string, next: number }}
|
|
156
|
+
*/
|
|
157
|
+
function flagValue(args, index, flag) {
|
|
158
|
+
const argument = /** @type {string} */ (args[index]);
|
|
159
|
+
const value = argument === flag ? args[index + 1] : argument.slice(flag.length + 1);
|
|
160
|
+
if (value === undefined || value === '') usageError(`option_value_required:${flag}`);
|
|
161
|
+
return { value: /** @type {string} */ (value), next: argument === flag ? index + 1 : index };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Take `--manager`, `--worker <name>` and `--room <name>` out of a launch's
|
|
166
|
+
* arguments (D2): launcher flags, consumed before the native arguments the way
|
|
167
|
+
* `--host` is. Everything after `--` belongs to the host.
|
|
168
|
+
* @param {string[]} args
|
|
169
|
+
* @param {'claude' | 'codex'} host
|
|
170
|
+
* @returns {{ request: RoleRequest | null, args: string[] }}
|
|
171
|
+
*/
|
|
172
|
+
export function takeRoleFlags(args, host) {
|
|
173
|
+
/** @type {string[]} */
|
|
174
|
+
const rest = [];
|
|
175
|
+
/** @type {RoleFlag | null} */
|
|
176
|
+
let role = null;
|
|
177
|
+
/** @type {string | null} */
|
|
178
|
+
let roomName = null;
|
|
179
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
180
|
+
const argument = /** @type {string} */ (args[index]);
|
|
181
|
+
if (argument === '--') {
|
|
182
|
+
rest.push(...args.slice(index));
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (argument === MANAGER_FLAG) {
|
|
186
|
+
if (role !== null) usageError('role_flag_duplicate');
|
|
187
|
+
role = { kind: 'manager' };
|
|
188
|
+
} else if (argument === WORKER_FLAG || argument.startsWith(`${WORKER_FLAG}=`)) {
|
|
189
|
+
if (role !== null) usageError('role_flag_duplicate');
|
|
190
|
+
const taken = flagValue(args, index, WORKER_FLAG);
|
|
191
|
+
index = taken.next;
|
|
192
|
+
if (!NAME_PATTERN.test(taken.value) || taken.value === MANAGER_NAME)
|
|
193
|
+
usageError('worker_name_invalid');
|
|
194
|
+
role = { kind: 'worker', name: taken.value };
|
|
195
|
+
} else if (argument === ROOM_FLAG || argument.startsWith(`${ROOM_FLAG}=`)) {
|
|
196
|
+
if (roomName !== null) usageError('room_flag_duplicate');
|
|
197
|
+
const taken = flagValue(args, index, ROOM_FLAG);
|
|
198
|
+
index = taken.next;
|
|
199
|
+
if (!NAME_PATTERN.test(taken.value)) usageError('room_name_invalid');
|
|
200
|
+
roomName = taken.value;
|
|
201
|
+
} else rest.push(argument);
|
|
202
|
+
}
|
|
203
|
+
if (role === null) {
|
|
204
|
+
if (roomName !== null) usageError('room_flag_requires_role');
|
|
205
|
+
return { request: null, args: rest };
|
|
206
|
+
}
|
|
207
|
+
// v1: the manager is a Claude Code session and a worker is a Codex session (FR1).
|
|
208
|
+
if ((role.kind === 'manager') !== (host === 'claude')) usageError('role_unsupported_for_host');
|
|
209
|
+
// A worker is the interactive terminal; checked before anything is registered.
|
|
210
|
+
if (role.kind === 'worker') {
|
|
211
|
+
const subcommand = codexSubcommand(rest);
|
|
212
|
+
if (subcommand !== null && !WORKER_CODEX_SUBCOMMANDS.has(subcommand))
|
|
213
|
+
usageError('role_unsupported_for_command');
|
|
214
|
+
}
|
|
215
|
+
return { request: { role, roomName }, args: rest };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The Codex subcommand the native arguments name, or null for the interactive
|
|
220
|
+
* terminal (no subcommand, or a first word that is the prompt). A leading `--`
|
|
221
|
+
* is the launcher's separator; a later one is Codex's own, after which the
|
|
222
|
+
* words are the prompt.
|
|
223
|
+
* @param {string[]} args the native arguments, as `takeRoleFlags` leaves them
|
|
224
|
+
* @returns {string | null}
|
|
225
|
+
*/
|
|
226
|
+
function codexSubcommand(args) {
|
|
227
|
+
const native = args[0] === '--' ? args.slice(1) : args;
|
|
228
|
+
for (let index = 0; index < native.length; index += 1) {
|
|
229
|
+
const argument = /** @type {string} */ (native[index]);
|
|
230
|
+
if (argument === '--') return null;
|
|
231
|
+
if (argument.startsWith('-')) {
|
|
232
|
+
if (!argument.includes('=') && CODEX_VALUE_OPTIONS.has(argument)) index += 1;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
return CODEX_SUBCOMMANDS.has(argument) || WORKER_CODEX_SUBCOMMANDS.has(argument)
|
|
236
|
+
? argument
|
|
237
|
+
: null;
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether this Codex version was measured with the worker role (D14).
|
|
244
|
+
* @param {string | null | undefined} version
|
|
245
|
+
*/
|
|
246
|
+
export function supportsWorkerRole(version) {
|
|
247
|
+
return typeof version === 'string' && MEASURED_WORKER_CODEX_VERSIONS.includes(version);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Register this launch's session in its room, when the launch may have the
|
|
252
|
+
* role. A role that cannot be given never blocks the launch: the result says
|
|
253
|
+
* why and the host starts without it. Only a taken name, a second manager or
|
|
254
|
+
* a full room stop the launch, with exit 2, before any host starts (FR1).
|
|
255
|
+
* @param {object} input
|
|
256
|
+
* @param {string} input.root the client's state root
|
|
257
|
+
* @param {RoleRequest} input.request
|
|
258
|
+
* @param {{ name: 'claude' | 'codex', version: string | null }} input.host
|
|
259
|
+
* @param {string} input.cwd
|
|
260
|
+
* @param {BusLocale} input.locale
|
|
261
|
+
* @param {boolean} input.licensed the launch's license check passed (D11)
|
|
262
|
+
* @param {boolean} input.qualified the host version was measured with the role (D14)
|
|
263
|
+
* @param {import('./bus.mjs').BusClock} [input.clock]
|
|
264
|
+
* @param {import('./room.mjs').GitRunner} [input.git]
|
|
265
|
+
* @returns {Promise<ActiveRole | InactiveRole>}
|
|
266
|
+
*/
|
|
267
|
+
export async function prepareRole({
|
|
268
|
+
root,
|
|
269
|
+
request,
|
|
270
|
+
host,
|
|
271
|
+
cwd,
|
|
272
|
+
locale,
|
|
273
|
+
licensed,
|
|
274
|
+
qualified,
|
|
275
|
+
clock,
|
|
276
|
+
git,
|
|
277
|
+
}) {
|
|
278
|
+
const kind = request.role.kind;
|
|
279
|
+
if (!licensed) return { active: false, kind, reason: 'license_inactive' };
|
|
280
|
+
if (!qualified) return { active: false, kind, reason: 'host_unqualified' };
|
|
281
|
+
const now = (clock?.now ?? Date.now)();
|
|
282
|
+
const name = request.role.kind === 'worker' ? request.role.name : MANAGER_NAME;
|
|
283
|
+
try {
|
|
284
|
+
await sweepBus(root, clock);
|
|
285
|
+
const room = await resolveRoom({
|
|
286
|
+
cwd,
|
|
287
|
+
roomName: request.roomName,
|
|
288
|
+
...(git === undefined ? {} : { git }),
|
|
289
|
+
});
|
|
290
|
+
const paths = await ensureRoom(root, room, clock);
|
|
291
|
+
/** @type {SessionRecord} */
|
|
292
|
+
const record = {
|
|
293
|
+
schemaVersion: 1,
|
|
294
|
+
sessionId: newSessionId(),
|
|
295
|
+
name,
|
|
296
|
+
role: kind,
|
|
297
|
+
host: host.name,
|
|
298
|
+
hostVersion: host.version,
|
|
299
|
+
launcherPid: process.pid,
|
|
300
|
+
childPid: null,
|
|
301
|
+
startedAt: now,
|
|
302
|
+
cwd,
|
|
303
|
+
locale,
|
|
304
|
+
state: kind === 'manager' ? 'idle' : 'starting',
|
|
305
|
+
stateSince: now,
|
|
306
|
+
turnOrigin: null,
|
|
307
|
+
queued: 0,
|
|
308
|
+
sandbox: 'unknown',
|
|
309
|
+
approvalPolicy: 'unknown',
|
|
310
|
+
approval: null,
|
|
311
|
+
heldApprovals: [],
|
|
312
|
+
};
|
|
313
|
+
await registerSession(paths, record, clock);
|
|
314
|
+
await audit(paths, { event: 'registered', sessionId: record.sessionId, kind }, clock);
|
|
315
|
+
return {
|
|
316
|
+
active: true,
|
|
317
|
+
kind,
|
|
318
|
+
name,
|
|
319
|
+
roomLabel: room.label,
|
|
320
|
+
paths,
|
|
321
|
+
sessionId: record.sessionId,
|
|
322
|
+
environmentValue: roleEnvironmentValue({
|
|
323
|
+
role: kind,
|
|
324
|
+
stateRoot: root,
|
|
325
|
+
roomId: room.id,
|
|
326
|
+
sessionId: record.sessionId,
|
|
327
|
+
name,
|
|
328
|
+
locale,
|
|
329
|
+
}),
|
|
330
|
+
};
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error instanceof BusError && REFUSED_REGISTRATIONS.includes(error.code))
|
|
333
|
+
throw Object.assign(new Error(error.code), { exitCode: USAGE_EXIT_CODE });
|
|
334
|
+
return { active: false, kind, reason: 'bus_unavailable' };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Remove the session when its launch ends. The role process does this itself
|
|
340
|
+
* when it exits cleanly; this covers the one that did not. Never throws.
|
|
341
|
+
* @param {ActiveRole | InactiveRole | null} prepared
|
|
342
|
+
* @param {import('./bus.mjs').BusClock} [clock]
|
|
343
|
+
*/
|
|
344
|
+
export async function closeRole(prepared, clock) {
|
|
345
|
+
if (prepared === null || !prepared.active) return;
|
|
346
|
+
await removeSession(prepared.paths, prepared.sessionId, prepared.kind).catch(() => undefined);
|
|
347
|
+
await audit(prepared.paths, { event: 'closed', sessionId: prepared.sessionId }, clock);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The one line a launch prints about its role (FR1), in the stored locale.
|
|
352
|
+
* @param {ActiveRole | InactiveRole} prepared
|
|
353
|
+
* @param {BusLocale} locale
|
|
354
|
+
*/
|
|
355
|
+
export function roleLaunchLine(prepared, locale) {
|
|
356
|
+
const portuguese = locale === 'pt-BR';
|
|
357
|
+
if (!prepared.active) {
|
|
358
|
+
const role = prepared.kind === 'manager' ? (portuguese ? 'gerente' : 'manager') : 'worker';
|
|
359
|
+
return portuguese
|
|
360
|
+
? `aisac: a sessão inicia sem o papel de ${role} (${prepared.reason}).`
|
|
361
|
+
: `aisac: the session starts without the ${role} role (${prepared.reason}).`;
|
|
362
|
+
}
|
|
363
|
+
if (prepared.kind === 'worker')
|
|
364
|
+
return portuguese
|
|
365
|
+
? `aisac: worker "${prepared.name}" na sala "${prepared.roomLabel}": as mensagens da sessão gerente rodam nesta sessão, com o sandbox e a política de aprovação dela. O texto das mensagens e das respostas passa pelos provedores das duas sessões.`
|
|
366
|
+
: `aisac: worker "${prepared.name}" in room "${prepared.roomLabel}": messages from the manager session run in this session, under its own sandbox and approval policy. The text of messages and replies crosses the providers of both sessions.`;
|
|
367
|
+
return portuguese
|
|
368
|
+
? `aisac: gerente da sala "${prepared.roomLabel}": as ferramentas manager_* alcançam os workers Codex desta sala; enviar uma mensagem pede a sua permissão. O texto das mensagens e das respostas passa pelos provedores das duas sessões.`
|
|
369
|
+
: `aisac: manager of room "${prepared.roomLabel}": the manager_* tools reach the Codex workers of this room; sending a message asks for your permission. The text of messages and replies crosses the providers of both sessions.`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* What the Codex chain needs for an active worker role: the role itself and
|
|
374
|
+
* the module the adapter loads.
|
|
375
|
+
* @param {ActiveRole} prepared
|
|
376
|
+
* @param {string} packageRoot
|
|
377
|
+
* @returns {Record<string, string>}
|
|
378
|
+
*/
|
|
379
|
+
export function workerEnvironment(prepared, packageRoot) {
|
|
380
|
+
return {
|
|
381
|
+
[WORKER_ROLE_ENV]: prepared.environmentValue,
|
|
382
|
+
[WORKER_MODULE_ENV]: join(packageRoot, 'manager', 'worker.mjs'),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The manager's entry of the session's `mcp.json` (FR6): a stdio server of the
|
|
388
|
+
* client, with the manager's identity in its environment and nowhere else.
|
|
389
|
+
* @param {ActiveRole} prepared
|
|
390
|
+
* @param {string} packageRoot
|
|
391
|
+
* @param {string} node
|
|
392
|
+
*/
|
|
393
|
+
export function managerMcpEntry(prepared, packageRoot, node) {
|
|
394
|
+
return {
|
|
395
|
+
type: 'stdio',
|
|
396
|
+
command: node,
|
|
397
|
+
args: [join(packageRoot, 'manager', 'server.mjs')],
|
|
398
|
+
env: { [MANAGER_ROLE_ENV]: prepared.environmentValue },
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** The allow rules of the manager's pre-allowed tools, in Claude Code's form (FR8). */
|
|
403
|
+
export function managerAllowRules() {
|
|
404
|
+
return MANAGER_ALLOWED_TOOLS.map((tool) => `mcp__${MANAGER_SERVER_NAME}__${tool}`);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** The variables a launch must never inherit from an outer session. */
|
|
408
|
+
export const ROLE_ENVIRONMENT_VARIABLES = Object.freeze([
|
|
409
|
+
WORKER_ROLE_ENV,
|
|
410
|
+
WORKER_MODULE_ENV,
|
|
411
|
+
MANAGER_ROLE_ENV,
|
|
412
|
+
]);
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @typedef {object} ManagerDoctorSection
|
|
416
|
+
* @property {'supported' | 'claude_not_found'} manager_role
|
|
417
|
+
* @property {'supported' | 'host_unqualified' | 'codex_not_found'} worker_role
|
|
418
|
+
* @property {string[]} measured_codex the Codex versions the worker role was measured with
|
|
419
|
+
* @property {{ label: string, kind: string, manager: boolean, workers: number, pending: number }[]} rooms
|
|
420
|
+
*/
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The `manager` section of `aisac doctor` (FR11): the roles the installed
|
|
424
|
+
* hosts can take and the live rooms with their counts. It reads and never
|
|
425
|
+
* writes, and reports a room by its label, never by a path.
|
|
426
|
+
* @param {object} input
|
|
427
|
+
* @param {string} input.root the client's state root
|
|
428
|
+
* @param {boolean} input.claude Claude Code is installed
|
|
429
|
+
* @param {string | null | undefined} input.codexVersion the installed Codex, when there is one
|
|
430
|
+
* @param {import('./bus.mjs').BusClock} [input.clock]
|
|
431
|
+
* @returns {Promise<ManagerDoctorSection>}
|
|
432
|
+
*/
|
|
433
|
+
export async function managerDoctorSection({ root, claude, codexVersion, clock }) {
|
|
434
|
+
/** @type {ManagerDoctorSection['rooms']} */
|
|
435
|
+
const rooms = [];
|
|
436
|
+
for (const { descriptor, paths } of await listRooms(root)) {
|
|
437
|
+
const sessions = await listSessions(paths, { ...clock, sweep: false });
|
|
438
|
+
if (sessions.length === 0) continue;
|
|
439
|
+
const pending = await readdir(paths.pending).catch(() => []);
|
|
440
|
+
rooms.push({
|
|
441
|
+
label: descriptor.label,
|
|
442
|
+
kind: descriptor.kind,
|
|
443
|
+
manager: sessions.some((entry) => entry.role === 'manager'),
|
|
444
|
+
workers: sessions.filter((entry) => entry.role === 'worker').length,
|
|
445
|
+
pending: pending.filter((name) => MESSAGE_FILE_PATTERN.test(name)).length,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
/** @type {ManagerDoctorSection['worker_role']} */
|
|
449
|
+
let workerRole = 'codex_not_found';
|
|
450
|
+
if (typeof codexVersion === 'string')
|
|
451
|
+
workerRole = supportsWorkerRole(codexVersion) ? 'supported' : 'host_unqualified';
|
|
452
|
+
return {
|
|
453
|
+
manager_role: claude ? 'supported' : 'claude_not_found',
|
|
454
|
+
worker_role: workerRole,
|
|
455
|
+
measured_codex: [...MEASURED_WORKER_CODEX_VERSIONS],
|
|
456
|
+
rooms,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The text doctor's one line for the section.
|
|
462
|
+
* @param {ManagerDoctorSection | null} section
|
|
463
|
+
*/
|
|
464
|
+
export function managerDoctorLine(section) {
|
|
465
|
+
if (section === null) return 'manager: unavailable';
|
|
466
|
+
const rooms =
|
|
467
|
+
section.rooms.length === 0
|
|
468
|
+
? 'no live room'
|
|
469
|
+
: section.rooms
|
|
470
|
+
.map(
|
|
471
|
+
(room) =>
|
|
472
|
+
`${room.label} (${room.manager ? 'manager, ' : ''}${room.workers} worker${room.workers === 1 ? '' : 's'}, ${room.pending} pending)`,
|
|
473
|
+
)
|
|
474
|
+
.join('; ');
|
|
475
|
+
return `manager: manager role ${section.manager_role}; worker role ${section.worker_role} (measured with Codex ${section.measured_codex.join(', ')}); ${rooms}`;
|
|
476
|
+
}
|