agl 43.1.0 → 43.3.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/changelog.md +32 -0
- package/dist_serve/bundle.js +5950 -5530
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +31 -31
- package/dist_serve/bundle.js.third-party-notices.txt +31 -31
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +521 -17
- package/dist_ts/aglapi/interfaces.d.ts +3 -0
- package/dist_ts/aglapi/interfaces.js +2 -1
- package/dist_ts/classes.accountsactions.d.ts +3 -1
- package/dist_ts/classes.accountsactions.js +21 -3
- package/dist_ts/classes.authmodels.js +17 -4
- package/dist_ts/classes.authstore.js +16 -2
- package/dist_ts/classes.claudeharness.d.ts +16 -0
- package/dist_ts/classes.claudeharness.js +24 -2
- package/dist_ts/classes.cli.d.ts +4 -2
- package/dist_ts/classes.cli.js +6 -3
- package/dist_ts/classes.codexclientadapter.d.ts +11 -0
- package/dist_ts/classes.codexclientadapter.js +14 -2
- package/dist_ts/classes.controller.d.ts +175 -11
- package/dist_ts/classes.controller.js +1213 -173
- package/dist_ts/classes.controllerdevices.d.ts +2 -0
- package/dist_ts/classes.controllerdevices.js +6 -1
- package/dist_ts/classes.controllermanagement.d.ts +14 -4
- package/dist_ts/classes.controllermanagement.js +20 -2
- package/dist_ts/classes.gatewayclient.d.ts +115 -0
- package/dist_ts/classes.gatewayclient.js +336 -0
- package/dist_ts/classes.gatewayclientstore.d.ts +97 -0
- package/dist_ts/classes.gatewayclientstore.js +261 -0
- package/dist_ts/classes.inbox.d.ts +72 -0
- package/dist_ts/classes.inbox.js +231 -0
- package/dist_ts/classes.inferencerouter.d.ts +19 -0
- package/dist_ts/classes.inferencerouter.js +15 -3
- package/dist_ts/classes.inferenceservice.d.ts +9 -0
- package/dist_ts/classes.inferenceservice.js +28 -2
- package/dist_ts/classes.mcpclient.d.ts +4 -1
- package/dist_ts/classes.mcpclient.js +42 -6
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -1
- package/dist_ts/classes.mcpcontrollerhost.js +11 -1
- package/dist_ts/classes.mcptools.d.ts +3 -3
- package/dist_ts/classes.mcptools.js +38 -8
- package/dist_ts/classes.mcpvalidation.d.ts +5 -0
- package/dist_ts/classes.mcpvalidation.js +38 -2
- package/dist_ts/classes.nativesessions.d.ts +17 -4
- package/dist_ts/classes.nativesessions.js +41 -9
- package/dist_ts/classes.opencodeclient.d.ts +23 -2
- package/dist_ts/classes.opencodeclient.js +47 -3
- package/dist_ts/classes.proxycontrol.d.ts +11 -0
- package/dist_ts/classes.proxycontrol.js +7 -1
- package/dist_ts/classes.proxycontrolclient.d.ts +17 -0
- package/dist_ts/classes.proxycontrolclient.js +35 -1
- package/dist_ts/classes.proxydaemon.js +8 -1
- package/dist_ts/classes.proxymonitor.d.ts +7 -0
- package/dist_ts/classes.proxymonitor.js +13 -1
- package/dist_ts/classes.publishedset.d.ts +38 -0
- package/dist_ts/classes.publishedset.js +50 -0
- package/dist_ts/classes.sessionfeed.d.ts +3 -3
- package/dist_ts/classes.sessionfeed.js +18 -26
- package/dist_ts/classes.systemmetricssampler.d.ts +6 -0
- package/dist_ts/classes.systemmetricssampler.js +15 -3
- package/dist_ts/classes.ticketstore.d.ts +50 -3
- package/dist_ts/classes.ticketstore.js +45 -8
- package/dist_ts/classes.trustedproxysecrets.d.ts +2 -0
- package/dist_ts/classes.trustedproxysecrets.js +5 -1
- package/dist_ts/driver/classes.directreports.d.ts +14 -4
- package/dist_ts/driver/classes.directreports.js +25 -6
- package/dist_ts/driver/classes.driverservice.d.ts +44 -3
- package/dist_ts/driver/classes.driverservice.js +50 -16
- package/dist_ts/fleet/classes.claudeworkers.d.ts +21 -5
- package/dist_ts/fleet/classes.claudeworkers.js +142 -46
- package/dist_ts/fleet/classes.codexworkers.d.ts +16 -4
- package/dist_ts/fleet/classes.codexworkers.js +22 -5
- package/dist_ts/fleet/classes.workercommand.d.ts +6 -1
- package/dist_ts/fleet/classes.workercommand.js +15 -4
- package/dist_ts/fleet/classes.workers.d.ts +5 -1
- package/dist_ts/fleet/classes.workers.js +8 -2
- package/dist_ts/fleet/functions.unbounddrivers.js +2 -2
- package/dist_ts/fleet/functions.workervalidation.js +2 -2
- package/dist_ts/fleet/interfaces.workers.d.ts +21 -3
- package/dist_ts/fleet/interfaces.workers.js +1 -1
- package/dist_ts/functions.agentmessage.d.ts +3 -0
- package/dist_ts/functions.agentmessage.js +4 -1
- package/dist_ts/functions.controllermanagementsurface.d.ts +4 -0
- package/dist_ts/functions.controllermanagementsurface.js +15 -1
- package/dist_ts/functions.deviceapi.d.ts +151 -4
- package/dist_ts/functions.deviceapi.js +893 -38
- package/dist_ts/functions.fleetworkercli.d.ts +1 -1
- package/dist_ts/functions.fleetworkercli.js +11 -8
- package/dist_ts/functions.gatewaycli.d.ts +24 -0
- package/dist_ts/functions.gatewaycli.js +395 -0
- package/dist_ts/functions.gatewayroute.d.ts +135 -0
- package/dist_ts/functions.gatewayroute.js +366 -0
- package/dist_ts/functions.inferencecli.js +32 -1
- package/dist_ts/functions.inferencecliarguments.d.ts +8 -2
- package/dist_ts/functions.inferencecliarguments.js +31 -3
- package/dist_ts/functions.mcpfleetworkertools.js +2 -2
- package/dist_ts/functions.proxycapacity.d.ts +50 -0
- package/dist_ts/functions.proxycapacity.js +142 -0
- package/dist_ts/functions.proxycapacitycli.d.ts +30 -0
- package/dist_ts/functions.proxycapacitycli.js +65 -0
- package/dist_ts/functions.remotecli.d.ts +30 -3
- package/dist_ts/functions.remotecli.js +44 -18
- package/dist_ts/functions.ticketvalidation.js +11 -2
- package/dist_ts/interfaces.auth.d.ts +25 -4
- package/dist_ts/interfaces.auth.js +15 -1
- package/dist_ts/plugins.d.ts +5 -1
- package/dist_ts/plugins.js +10 -2
- package/dist_ts_authswitch/authority-contract.d.ts +25 -0
- package/dist_ts_authswitch/authority-contract.js +1 -1
- package/dist_ts_authswitch/authority-overview.d.ts +8 -0
- package/dist_ts_authswitch/authority-overview.js +17 -6
- package/dist_ts_authswitch/authority-placement.d.ts +20 -16
- package/dist_ts_authswitch/authority-placement.js +19 -26
- package/dist_ts_authswitch/authority-renewal.d.ts +34 -0
- package/dist_ts_authswitch/authority-renewal.js +56 -0
- package/dist_ts_authswitch/authority-usagelimit.d.ts +29 -0
- package/dist_ts_authswitch/authority-usagelimit.js +66 -2
- package/dist_ts_authswitch/authority-usagewindows.d.ts +6 -0
- package/dist_ts_authswitch/authority-usagewindows.js +15 -1
- package/dist_ts_authswitch/classes.authoritybroker.d.ts +8 -0
- package/dist_ts_authswitch/classes.authoritybroker.js +35 -2
- package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
- package/dist_ts_authswitch/classes.authoritycli.js +44 -3
- package/dist_ts_authswitch/classes.authorityclient.d.ts +6 -1
- package/dist_ts_authswitch/classes.authorityclient.js +12 -4
- package/dist_ts_authswitch/classes.authoritydaemon.js +8 -1
- package/dist_ts_authswitch/classes.authoritydatabase.js +6 -2
- package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
- package/dist_ts_authswitch/classes.authoritymodels.js +21 -5
- package/dist_ts_interfaces/devices.d.ts +1012 -5
- package/dist_ts_interfaces/devices.js +68 -2
- package/dist_ts_interfaces/fleetworkers.d.ts +5 -3
- package/dist_ts_interfaces/gateway.d.ts +151 -0
- package/dist_ts_interfaces/gateway.js +66 -0
- package/dist_ts_interfaces/inbox.d.ts +234 -0
- package/dist_ts_interfaces/inbox.js +101 -0
- package/dist_ts_interfaces/index.d.ts +3 -0
- package/dist_ts_interfaces/index.js +4 -1
- package/dist_ts_interfaces/interfaces.d.ts +10 -3
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/management.d.ts +4 -4
- package/dist_ts_interfaces/management.js +3 -2
- package/dist_ts_interfaces/mcprequests.d.ts +48 -6
- package/dist_ts_interfaces/mcprequests.js +12 -1
- package/dist_ts_interfaces/mcpworkspacerequests.d.ts +4 -1
- package/dist_ts_interfaces/mcpworkspacerequests.js +1 -1
- package/dist_ts_interfaces/nativesessions.d.ts +16 -3
- package/dist_ts_interfaces/plugins.d.ts +2 -1
- package/dist_ts_interfaces/plugins.js +4 -2
- package/dist_ts_interfaces/proxycapacity.d.ts +99 -0
- package/dist_ts_interfaces/proxycapacity.js +74 -0
- package/dist_ts_interfaces/requests.accounts.d.ts +21 -0
- package/dist_ts_interfaces/requests.accounts.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/docs/authswitch.md +20 -1
- package/package.json +6 -5
- package/readme.md +191 -31
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +520 -16
- package/ts/aglapi/interfaces.ts +1 -0
- package/ts/classes.accountsactions.ts +30 -3
- package/ts/classes.authmodels.ts +22 -3
- package/ts/classes.authstore.ts +15 -1
- package/ts/classes.claudeharness.ts +27 -1
- package/ts/classes.cli.ts +7 -3
- package/ts/classes.codexclientadapter.ts +14 -1
- package/ts/classes.controller.ts +1428 -249
- package/ts/classes.controllerdevices.ts +6 -0
- package/ts/classes.controllermanagement.ts +40 -7
- package/ts/classes.gatewayclient.ts +401 -0
- package/ts/classes.gatewayclientstore.ts +272 -0
- package/ts/classes.inbox.ts +239 -0
- package/ts/classes.inferencerouter.ts +27 -2
- package/ts/classes.inferenceservice.ts +28 -1
- package/ts/classes.mcpclient.ts +42 -3
- package/ts/classes.mcpcontrollerhost.ts +15 -0
- package/ts/classes.mcptools.ts +42 -9
- package/ts/classes.mcpvalidation.ts +32 -1
- package/ts/classes.nativesessions.ts +50 -12
- package/ts/classes.opencodeclient.ts +55 -4
- package/ts/classes.proxycontrol.ts +16 -0
- package/ts/classes.proxycontrolclient.ts +30 -0
- package/ts/classes.proxydaemon.ts +8 -0
- package/ts/classes.proxymonitor.ts +12 -0
- package/ts/classes.publishedset.ts +56 -0
- package/ts/classes.sessionfeed.ts +17 -20
- package/ts/classes.systemmetricssampler.ts +13 -2
- package/ts/classes.ticketstore.ts +73 -12
- package/ts/classes.trustedproxysecrets.ts +5 -0
- package/ts/driver/classes.directreports.ts +25 -6
- package/ts/driver/classes.driverservice.ts +75 -14
- package/ts/fleet/classes.claudeworkers.ts +112 -39
- package/ts/fleet/classes.codexworkers.ts +21 -6
- package/ts/fleet/classes.workercommand.ts +14 -4
- package/ts/fleet/classes.workers.ts +9 -2
- package/ts/fleet/functions.unbounddrivers.ts +1 -1
- package/ts/fleet/functions.workervalidation.ts +1 -1
- package/ts/fleet/interfaces.workers.ts +20 -5
- package/ts/functions.agentmessage.ts +3 -0
- package/ts/functions.controllermanagementsurface.ts +15 -0
- package/ts/functions.deviceapi.ts +1071 -34
- package/ts/functions.fleetworkercli.ts +10 -7
- package/ts/functions.gatewaycli.ts +436 -0
- package/ts/functions.gatewayroute.ts +429 -0
- package/ts/functions.inferencecli.ts +26 -0
- package/ts/functions.inferencecliarguments.ts +30 -4
- package/ts/functions.mcpfleetworkertools.ts +1 -1
- package/ts/functions.proxycapacity.ts +191 -0
- package/ts/functions.proxycapacitycli.ts +104 -0
- package/ts/functions.remotecli.ts +56 -20
- package/ts/functions.ticketvalidation.ts +11 -1
- package/ts/interfaces.auth.ts +36 -4
- package/ts/plugins.ts +12 -0
- package/ts_authswitch/authority-contract.ts +20 -0
- package/ts_authswitch/authority-overview.ts +28 -6
- package/ts_authswitch/authority-placement.ts +27 -32
- package/ts_authswitch/authority-renewal.ts +64 -0
- package/ts_authswitch/authority-usagelimit.ts +84 -1
- package/ts_authswitch/authority-usagewindows.ts +13 -0
- package/ts_authswitch/classes.authoritybroker.ts +34 -1
- package/ts_authswitch/classes.authoritycli.ts +49 -2
- package/ts_authswitch/classes.authorityclient.ts +14 -4
- package/ts_authswitch/classes.authoritydaemon.ts +9 -1
- package/ts_authswitch/classes.authoritydatabase.ts +5 -1
- package/ts_authswitch/classes.authoritymodels.ts +23 -3
- package/ts_authswitch/native-contracts.md +21 -0
- package/ts_authswitch/readme.md +1 -1
- package/ts_interfaces/devices.schema.json +3573 -603
- package/ts_interfaces/devices.ts +1093 -4
- package/ts_interfaces/fleetworkers.ts +5 -3
- package/ts_interfaces/gateway.ts +242 -0
- package/ts_interfaces/inbox.ts +287 -0
- package/ts_interfaces/index.ts +3 -0
- package/ts_interfaces/interfaces.ts +9 -2
- package/ts_interfaces/management.ts +6 -4
- package/ts_interfaces/mcprequests.ts +61 -4
- package/ts_interfaces/mcpworkspacerequests.ts +4 -2
- package/ts_interfaces/nativesessions.ts +17 -3
- package/ts_interfaces/plugins.ts +3 -1
- package/ts_interfaces/proxycapacity.ts +162 -0
- package/ts_interfaces/requests.accounts.ts +20 -0
- package/ts_interfaces/requests.ts +4 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/accounts.plugins.ts +4 -2
- package/ts_web/classes.accountsreadmodel.ts +33 -0
- package/ts_web/classes.browserpresentation.ts +19 -6
- package/ts_web/classes.inboxfeed.ts +329 -0
- package/ts_web/classes.nativesessionstate.ts +9 -23
- package/ts_web/elements.accounts.ts +121 -113
- package/ts_web/elements.configurationpane.ts +24 -37
- package/ts_web/elements.deployments.ts +66 -2
- package/ts_web/elements.devices.ts +4 -17
- package/ts_web/elements.flexlimitstrip.ts +21 -70
- package/ts_web/elements.harnesscontrollerapp.ts +198 -222
- package/ts_web/elements.inbox.ts +808 -0
- package/ts_web/functions.inbox.ts +95 -0
- package/ts_web/functions.sessioncards.ts +40 -0
- package/ts_web/plugins.ts +2 -0
|
@@ -5,7 +5,7 @@ import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorke
|
|
|
5
5
|
import { controllerSessionFeedExcerpt, type IControllerMessageBundle, type IControllerNativeWait } from '../../ts_interfaces/index.js';
|
|
6
6
|
import { claudePage, claudeTranscript } from '../classes.claudeprojection.js';
|
|
7
7
|
import { FleetDispatchError, FleetNativeTurnError, boundedFleetReport, fleetClaudeNativeWait, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeEvent, type IFleetNativeAgent, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
|
|
8
|
-
import { runFleetWorkerCommand, type IFleetWorkerCommand, type TFleetWorkerRunner } from './classes.workercommand.js';
|
|
8
|
+
import { runFleetWorkerCommand, type IFleetWorkerCommand, type TFleetWorkerOutputWatch, type TFleetWorkerRunner } from './classes.workercommand.js';
|
|
9
9
|
import { sanitizeFailureText } from '../functions.failuredescription.js';
|
|
10
10
|
import type { FleetWorkerLaunches } from './classes.workerlaunches.js';
|
|
11
11
|
import { claudeCodeFleetFloor, claudeCodeVersionOutput, compareClaudeCodeReleases, isNewerClaudeCodeRelease, parseClaudeCodeRelease } from '../functions.claudecoderelease.js';
|
|
@@ -107,7 +107,7 @@ const claudeObservedTurn = (nativeId: string, agent: TClaudeAgent | undefined, r
|
|
|
107
107
|
const modes = new Set(['acceptEdits', 'auto', 'bypassPermissions', 'default', 'dontAsk', 'manual', 'plan']);
|
|
108
108
|
/** SendMessage resolves a recipient by its session name, never by the short agent id; a name another live session shares is ambiguous. */
|
|
109
109
|
const address = (inventory: TClaudeAgent[], agent: TClaudeAgent): string => {
|
|
110
|
-
if (!agent.name) throw new Error('Claude
|
|
110
|
+
if (!agent.name) throw new Error('Claude session has no session name; SendMessage cannot address it.');
|
|
111
111
|
if (inventory.filter((entry) => entry.name === agent.name && entry.pid !== undefined).length !== 1) {
|
|
112
112
|
throw new Error(`Claude session name ${JSON.stringify(agent.name)} is shared by another live session; SendMessage cannot address it unambiguously.`);
|
|
113
113
|
}
|
|
@@ -204,6 +204,45 @@ export const assertFleetClaudeDelivery = (output: string, expected: Array<{ to:
|
|
|
204
204
|
if (result?.is_error === true || item?.success !== true || typeof item.msg_id !== 'string' || !item.msg_id) throw new FleetDispatchError('Claude recipient did not acknowledge queued delivery.', true);
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
|
+
/**
|
|
208
|
+
* The only tools a relay runs with. `--tools` limits Claude Code's own tools to them and `--strict-mcp-config` drops every
|
|
209
|
+
* configured MCP server, so a relayed message cannot drive any other tool in the permission mode the relay takes on from
|
|
210
|
+
* its recipient, bypassPermissions included; `--allowedTools` only pre-approves them. `--tools` takes several values, so
|
|
211
|
+
* it is passed as one `=` argument, or it would take the prompt as a tool (Claude Code 2.1.306).
|
|
212
|
+
*/
|
|
213
|
+
const relayTools = ['SendMessage', 'Read', 'ToolSearch'] as const;
|
|
214
|
+
export const fleetClaudeRelayToolArguments: readonly string[] = [`--tools=${relayTools.join(',')}`, '--strict-mcp-config', `--allowedTools=${relayTools.join(',')}`];
|
|
215
|
+
const relayToolName = (value: unknown): string => typeof value === 'string' && /^[\w.:-]{1,128}$/u.test(value) ? value : '(unreadable)';
|
|
216
|
+
/**
|
|
217
|
+
* Judges a relay's stream-json output by its `system`/`init` record, which Claude Code 2.1.306 prints before it calls the
|
|
218
|
+
* model: `true` when the record lists exactly the relay tools, the refusal when it lists any other, lacks one, or a record
|
|
219
|
+
* other than a `system` one comes first, and `undefined` while the complete lines decide nothing yet. A refusal is
|
|
220
|
+
* dispatched once anything but `system` records was printed: the model answered, and anything may have run.
|
|
221
|
+
*/
|
|
222
|
+
const relayToolsVerdict = (stdout: string, ended: boolean): true | FleetDispatchError | undefined => {
|
|
223
|
+
const lines = stdout.split('\n'), complete = ended ? lines : lines.slice(0, -1);
|
|
224
|
+
const records = complete.filter((line) => line.trim()).map((line) => { try { return record.safeParse(JSON.parse(line)).data; } catch { return undefined; } });
|
|
225
|
+
const answered = records.some((entry) => entry?.type !== 'system');
|
|
226
|
+
const refuse = (reason: string) => new FleetDispatchError(`Claude relay ${reason}; a relay runs only with ${relayTools.join(', ')}.${answered ? ' Inspect before retrying.' : ''}`, answered);
|
|
227
|
+
for (const entry of records) {
|
|
228
|
+
if (entry?.type !== 'system') return refuse('printed no system/init record before its first answer');
|
|
229
|
+
if (entry.subtype !== 'init') continue;
|
|
230
|
+
if (!Array.isArray(entry.tools)) return refuse('init record lists no tools');
|
|
231
|
+
const listed = entry.tools.map(relayToolName), wanted = new Set<string>(relayTools);
|
|
232
|
+
const extra = [...new Set(listed.filter((tool) => !wanted.has(tool)))], missing = relayTools.filter((tool) => !listed.includes(tool));
|
|
233
|
+
if (!extra.length && !missing.length && listed.length === relayTools.length) return true;
|
|
234
|
+
const named = (tools: string[]) => `${tools.slice(0, 16).join(', ')}${tools.length > 16 ? ` and ${tools.length - 16} more` : ''}`;
|
|
235
|
+
return refuse(`ran with ${extra.length ? `other tools (${named(extra)})` : ''}${extra.length && missing.length ? ' and ' : ''}${missing.length ? `without ${named(missing)}` : ''}${!extra.length && !missing.length ? 'a tool listed twice' : ''}`);
|
|
236
|
+
}
|
|
237
|
+
return ended ? refuse('printed no system/init record') : undefined;
|
|
238
|
+
};
|
|
239
|
+
/** The relay's watch while it runs: it is stopped as soon as its init record lists other tools. */
|
|
240
|
+
export const fleetClaudeRelayToolsWatch: TFleetWorkerOutputWatch = (stdout) => relayToolsVerdict(stdout, false);
|
|
241
|
+
/** Refuses a relay's complete output unless its init record lists exactly the relay tools. */
|
|
242
|
+
export const assertFleetClaudeRelayTools = (stdout: string): void => {
|
|
243
|
+
const verdict = relayToolsVerdict(stdout, true);
|
|
244
|
+
if (verdict !== true) throw verdict ?? new FleetDispatchError('Claude relay printed no system/init record.', true);
|
|
245
|
+
};
|
|
207
246
|
const textOf = (content: unknown): string => typeof content === 'string' ? content : !Array.isArray(content) ? ''
|
|
208
247
|
: content.map((part) => record.safeParse(part)).map((block) => block.success && block.data.type === 'text' && typeof block.data.text === 'string' ? block.data.text : '').filter(Boolean).join(' ');
|
|
209
248
|
/**
|
|
@@ -278,9 +317,9 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
278
317
|
}
|
|
279
318
|
return executable;
|
|
280
319
|
}
|
|
281
|
-
private async run(profile: Pick<IFleetWorkerProfile, 'home'>, cwd: string, args: string[]): Promise<IFleetWorkerCommand> {
|
|
320
|
+
private async run(profile: Pick<IFleetWorkerProfile, 'home'>, cwd: string, args: string[], watch?: TFleetWorkerOutputWatch): Promise<IFleetWorkerCommand> {
|
|
282
321
|
const env = this.env(profile), executable = await this.supportedExecutable(profile, cwd);
|
|
283
|
-
return await this.runner(executable, args, cwd, env, this.signal);
|
|
322
|
+
return await this.runner(executable, args, cwd, env, this.signal, ...(watch ? [watch] : []));
|
|
284
323
|
}
|
|
285
324
|
private async command(profile: Pick<IFleetWorkerProfile, 'home'>, cwd: string, args: string[], mutation = false): Promise<string> {
|
|
286
325
|
const result = await this.run(profile, cwd, args);
|
|
@@ -755,37 +794,53 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
755
794
|
}
|
|
756
795
|
}
|
|
757
796
|
/**
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
* its
|
|
797
|
+
* Sends to a background job that runs outside the fleet through Claude Code itself, so the job stays the session's
|
|
798
|
+
* owner and AGL never becomes a second writer: a settled (reaped or stopped) job is woken with the message, a running
|
|
799
|
+
* one takes it in its inbox through the relay's SendMessage, addressed by its session name, which no other running
|
|
800
|
+
* session of its inventory or of the `peerHomes` inventories, read fresh here, may share. Only a job its fresh inventory lists once, with a readable conversation, in the
|
|
801
|
+
* state the sender prepared its message for (`jobDelivery`), takes it; anything else, and a wake message Claude Code
|
|
802
|
+
* would read as one of its options, is refused before dispatch. Claude Code does not report when the turn that reads
|
|
803
|
+
* the message ends, so `settled` never runs.
|
|
762
804
|
*/
|
|
763
805
|
public async nativeSend(session: IFleetNativeSession, text: string, _settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt> {
|
|
764
806
|
if (turn?.expectedTurnId !== undefined || turn?.agentMessage) {
|
|
765
807
|
throw new FleetNativeTurnError("delivery_unsupported", "Claude Code background jobs do not support guarded native turn delivery.");
|
|
766
808
|
}
|
|
767
809
|
const profile = { home: session.home };
|
|
768
|
-
let original: TClaudeAgent;
|
|
810
|
+
let original: TClaudeAgent, inbox: { to: string; mode: string; offset: number } | undefined;
|
|
769
811
|
try {
|
|
770
812
|
if (Buffer.byteLength(text) > 96 * 1024) throw new Error('A message to a Claude background job is limited to 96 KiB.');
|
|
771
|
-
|
|
772
|
-
if (text.startsWith('-')) throw new Error('Claude Code reads a message that starts with "-" as an option. Start the message with other text.');
|
|
773
|
-
const listed = (await this.agents(session, profile)).filter((entry) => entry.sessionId === session.nativeId);
|
|
813
|
+
const inventory = await this.agents(session, profile), listed = inventory.filter((entry) => entry.sessionId === session.nativeId);
|
|
774
814
|
if (listed.length !== 1) throw new Error(`Claude inventory does not hold session ${session.nativeId} exactly once.`);
|
|
775
815
|
original = listed[0]!;
|
|
776
816
|
if (original.kind !== 'background' || !original.id) throw new Error('This Claude Code session is no background job; Claude Code cannot wake it.');
|
|
777
|
-
if (!resumable(original)) {
|
|
778
|
-
throw new Error(`Claude background job ${original.id} is ${live(original) ? 'running' : original.state ?? 'in an unknown state'}; only a settled job is woken.`);
|
|
779
|
-
}
|
|
780
817
|
const transcript = await this.transcript(session, profile);
|
|
781
818
|
if (!transcript.path || !transcript.records.length) throw new Error('Claude background job has no readable saved conversation.');
|
|
819
|
+
if (live(original) && original.state !== 'failed' && original.state !== 'stopped') {
|
|
820
|
+
// SendMessage reaches the running sessions of every home by name: the name is checked fresh against them all.
|
|
821
|
+
const peers: TClaudeAgent[] = [];
|
|
822
|
+
for (const home of session.peerHomes ?? []) peers.push(...await this.agents(session, { home }));
|
|
823
|
+
inbox = { to: address([...inventory, ...peers], original), mode: fleetClaudePermissionMode(transcript.records), offset: transcript.end };
|
|
824
|
+
} else if (!resumable(original)) {
|
|
825
|
+
throw new Error(`Claude background job ${original.id} is ${original.state ?? 'in an unknown state'}${live(original) ? '' : ' without a process'}; only a settled or running job takes a message.`);
|
|
826
|
+
} else if (text.startsWith('-')) {
|
|
827
|
+
// Claude Code reads a leading dash as an option, and an option makes it start a copy instead of waking the job.
|
|
828
|
+
throw new Error('Claude Code reads a message that starts with "-" as an option. Start the message with other text.');
|
|
829
|
+
}
|
|
830
|
+
if (session.jobDelivery !== undefined && session.jobDelivery !== (inbox ? 'inbox' : 'wake')) {
|
|
831
|
+
throw new Error(`Claude background job ${original.id} ${inbox ? 'started running' : 'settled'} since it was read; read it again and send again.`);
|
|
832
|
+
}
|
|
782
833
|
} catch (error) { throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude background job preflight failed.', false, { cause: error }); }
|
|
834
|
+
if (inbox) {
|
|
835
|
+
await this.relay(profile, session.cwd, inbox.mode, [{ session, to: inbox.to, text, offset: inbox.offset }]);
|
|
836
|
+
return { steered: false, job: 'inbox' };
|
|
837
|
+
}
|
|
783
838
|
await this.wake(profile, session.cwd, session.nativeId, original, text);
|
|
784
839
|
try { await this.awake(async () => (await this.agents(session, profile)).find((entry) => entry.sessionId === session.nativeId), original); }
|
|
785
840
|
catch (error) {
|
|
786
841
|
throw new FleetDispatchError(`Claude Code acknowledged the wake of background job ${original.id}, but its state is not confirmed: ${error instanceof Error ? error.message : 'unknown failure.'} Inspect it before sending again.`, true, { cause: error });
|
|
787
842
|
}
|
|
788
|
-
return { steered: false };
|
|
843
|
+
return { steered: false, job: 'wake' };
|
|
789
844
|
}
|
|
790
845
|
public async send(messages: Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string }>): Promise<void> {
|
|
791
846
|
const groups = new Map<string, Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string; to: string; mode: string; offset: number }>>();
|
|
@@ -818,32 +873,50 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
818
873
|
dispatched = true; await this.revive(message.worker, message.profile, message.text, current, message.baseline);
|
|
819
874
|
}
|
|
820
875
|
for (const group of groups.values()) {
|
|
821
|
-
const
|
|
822
|
-
try {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const result = await this.run(group[0]!.profile, group[0]!.worker.cwd, ['-p', '--output-format', 'stream-json', '--verbose', '--permission-mode', group[0]!.mode, '--allowedTools=SendMessage,Read,ToolSearch', prompt]);
|
|
829
|
-
try {
|
|
830
|
-
if (result.code !== 0) throw fleetClaudeRelayFailure(result);
|
|
831
|
-
assertFleetClaudeDelivery(result.stdout, expected);
|
|
832
|
-
} catch (error) {
|
|
833
|
-
// The relay ended before it sent anything, or Claude refused every send: none of it reached a recipient.
|
|
834
|
-
if (error instanceof FleetDispatchError && !error.dispatched) dispatched = earlier;
|
|
835
|
-
throw error;
|
|
836
|
-
}
|
|
837
|
-
for (const message of group) {
|
|
838
|
-
const after = await this.transcript(message.worker, message.profile, message.offset);
|
|
839
|
-
if (held(after.records)) throw new FleetDispatchError('Claude target held the peer message.', true);
|
|
840
|
-
const current = await this.transcript(message.worker, message.profile);
|
|
841
|
-
if (fleetClaudePermissionMode(current.records) !== message.mode) throw new FleetDispatchError('Claude recipient permission mode changed during delivery; inspect the receipt.', true);
|
|
842
|
-
}
|
|
843
|
-
} finally { await plugins.fs.promises.rm(directory, { recursive: true }); }
|
|
876
|
+
const earlier = dispatched; dispatched = true;
|
|
877
|
+
try { await this.relay(group[0]!.profile, group[0]!.worker.cwd, group[0]!.mode, group.map((item) => ({ session: item.worker, to: item.to, text: item.text, offset: item.offset }))); }
|
|
878
|
+
catch (error) {
|
|
879
|
+
// None of it reached a recipient.
|
|
880
|
+
if (error instanceof FleetDispatchError && !error.dispatched) dispatched = earlier;
|
|
881
|
+
throw error;
|
|
882
|
+
}
|
|
844
883
|
}
|
|
845
884
|
} catch (error) { throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude relay failed.', dispatched || error instanceof FleetDispatchError && error.dispatched, { cause: error }); }
|
|
846
885
|
}
|
|
886
|
+
/**
|
|
887
|
+
* The one relay, for a fleet steer and a native send alike: one `claude -p` run in `cwd`, in the recipients' permission
|
|
888
|
+
* mode `mode`, with exactly the relay tools, calls Claude Code's own SendMessage once per recipient, addressed by its
|
|
889
|
+
* session name (`to`); each receipt must prove queued delivery, and each recipient's transcript after `offset` must hold
|
|
890
|
+
* no held message and still the same permission mode. Throws `FleetDispatchError`, not dispatched only when none of it
|
|
891
|
+
* can have reached a recipient: the relay ended or was stopped before it sent anything, or Claude refused every send.
|
|
892
|
+
*/
|
|
893
|
+
private async relay(profile: Pick<IFleetWorkerProfile, 'home'>, cwd: string, mode: string,
|
|
894
|
+
recipients: ReadonlyArray<{ session: Pick<IFleetWorker, 'nativeId' | 'cwd'>; to: string; text: string; offset: number }>): Promise<void> {
|
|
895
|
+
const unprepared = (error: unknown) => new FleetDispatchError('The relay\'s message file could not be prepared.', false, { cause: error });
|
|
896
|
+
let directory: string;
|
|
897
|
+
try { directory = await plugins.fs.promises.mkdtemp(plugins.path.join(plugins.os.tmpdir(), 'agl-fleet-relay-')); }
|
|
898
|
+
catch (error) { throw unprepared(error); }
|
|
899
|
+
try {
|
|
900
|
+
const file = plugins.path.join(directory, 'messages.json');
|
|
901
|
+
const expected = recipients.map((item) => ({ to: item.to, message: item.text }));
|
|
902
|
+
try { await plugins.fs.promises.writeFile(file, JSON.stringify(expected), { mode: 0o600 }); } catch (error) { throw unprepared(error); }
|
|
903
|
+
const prompt = `Read ${JSON.stringify(file)}. For each object call SendMessage with its to and message values unchanged. Deliver the file's contents, unchanged. Do not send anything else. Report every tool receipt.`;
|
|
904
|
+
const result = await this.run(profile, cwd, ['-p', '--output-format', 'stream-json', '--verbose', '--permission-mode', mode,
|
|
905
|
+
...fleetClaudeRelayToolArguments, prompt], fleetClaudeRelayToolsWatch);
|
|
906
|
+
assertFleetClaudeRelayTools(result.stdout);
|
|
907
|
+
if (result.code !== 0) throw fleetClaudeRelayFailure(result);
|
|
908
|
+
assertFleetClaudeDelivery(result.stdout, expected);
|
|
909
|
+
for (const recipient of recipients) {
|
|
910
|
+
const after = await this.transcript(recipient.session, profile, recipient.offset);
|
|
911
|
+
if (held(after.records)) throw new FleetDispatchError('Claude target held the peer message.', true);
|
|
912
|
+
const current = await this.transcript(recipient.session, profile);
|
|
913
|
+
if (fleetClaudePermissionMode(current.records) !== mode) throw new FleetDispatchError('Claude recipient permission mode changed during delivery; inspect the receipt.', true);
|
|
914
|
+
}
|
|
915
|
+
} catch (error) {
|
|
916
|
+
if (error instanceof FleetDispatchError) throw error;
|
|
917
|
+
throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude relay failed.', true, { cause: error });
|
|
918
|
+
} finally { await plugins.fs.promises.rm(directory, { recursive: true }); }
|
|
919
|
+
}
|
|
847
920
|
public async stop(worker: IFleetWorker, profile: IFleetWorkerProfile): Promise<void> {
|
|
848
921
|
const agent = await this.agent(worker, profile);
|
|
849
922
|
if (!live(agent)) {
|
|
@@ -5,10 +5,10 @@ import { codexRecord, codexArray, codexString, codexSession, codexTimestamp, cod
|
|
|
5
5
|
import { isCodexThreadId } from '../functions.codexidentity.js';
|
|
6
6
|
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerTurnOutcome } from '../../ts_interfaces/fleetworkers.js';
|
|
7
7
|
import { controllerSessionFeedExcerpt } from '../../ts_interfaces/sessionfeed.js';
|
|
8
|
-
import type { IControllerAttention, IControllerMessageBundle } from '../../ts_interfaces/index.js';
|
|
8
|
+
import type { IControllerAttention, IControllerEvent, IControllerMessageBundle } from '../../ts_interfaces/index.js';
|
|
9
9
|
import { controllerAttentionPending } from '../../ts_interfaces/index.js';
|
|
10
10
|
import type { FleetWorkerLaunches, IFleetCodexCallerRuntime } from './classes.workerlaunches.js';
|
|
11
|
-
import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt, type TFleetNativeReply } from './interfaces.workers.js';
|
|
11
|
+
import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePendingAttention, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt, type TFleetNativeReply } from './interfaces.workers.js';
|
|
12
12
|
|
|
13
13
|
/** `turns` and `items` are the poll baseline; `turn` stays when the baseline is forgotten, so a failure stays observed. */
|
|
14
14
|
interface ICodexObservation { turns?: Set<string>; items?: Map<string, string>; status?: IFleetWorkerReport['status']; excerpt?: string; turn?: IFleetWorkerObservedTurn }
|
|
@@ -25,13 +25,21 @@ const codexObservedTurn = (turn: Record<string, unknown>): IFleetWorkerObservedT
|
|
|
25
25
|
...(terminalTurnStates.has(turn.status) ? { outcome: { turnId, state: turn.status as IFleetWorkerTurnOutcome['state'], ...(limit ? { limit } : {}) } } : {}) };
|
|
26
26
|
};
|
|
27
27
|
export interface IFleetCodexConnection { supervisor: CodexSupervisor; adapter: CodexClientAdapter }
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/** `onAttention` hears of every thread whose requests AGL holds on the connection came or went. */
|
|
29
|
+
export type TFleetCodexConnectionFactory = (cwd: string, onAttention: (threadIdArg: string) => void) => IFleetCodexConnection;
|
|
30
|
+
/**
|
|
31
|
+
* The events of the fleet's Codex connection, which serves no browser: of them only a request (a permission, a
|
|
32
|
+
* question or an MCP form) coming or going is told on, as the thread it belongs to.
|
|
33
|
+
*/
|
|
34
|
+
export const fleetCodexAttentionEvents = (onAttentionArg: (threadIdArg: string) => void) => (eventArg: IControllerEvent): void => {
|
|
35
|
+
if (eventArg.type === 'permissions.changed' && eventArg.sessionId) onAttentionArg(eventArg.sessionId.nativeId);
|
|
36
|
+
};
|
|
37
|
+
const connection: TFleetCodexConnectionFactory = (directory, onAttention) => {
|
|
30
38
|
let adapter: CodexClientAdapter;
|
|
31
39
|
const supervisor = new CodexSupervisor({ directory, sharedOnly: true,
|
|
32
40
|
onNotification: (event) => { adapter.onNotification(event); },
|
|
33
41
|
onServerRequest: (request) => { adapter.onServerRequest(request); }, onUnavailable: () => {} });
|
|
34
|
-
adapter = new CodexClientAdapter(supervisor, ()
|
|
42
|
+
adapter = new CodexClientAdapter(supervisor, fleetCodexAttentionEvents(onAttention));
|
|
35
43
|
return { supervisor, adapter };
|
|
36
44
|
};
|
|
37
45
|
/** A shared-daemon observer. Shutdown closes this connection, never the daemon or its turns. */
|
|
@@ -45,6 +53,8 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
|
|
|
45
53
|
private readonly factory: TFleetCodexConnectionFactory = connection,
|
|
46
54
|
/** Proves each worker thread's caller identity; without it workers call AGL as whoever their MCP bridge enrolls as. */
|
|
47
55
|
private readonly callers?: FleetWorkerLaunches,
|
|
56
|
+
/** Told of every native thread whose requests this connection holds for AGL came or went. */
|
|
57
|
+
private readonly onNativeAttention?: (nativeIdArg: string) => void,
|
|
48
58
|
) {}
|
|
49
59
|
/** The connection the fleet uses now, as the controller proves a worker thread's origin on it. */
|
|
50
60
|
private callerRuntime(): IFleetCodexCallerRuntime {
|
|
@@ -71,7 +81,7 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
|
|
|
71
81
|
const previous = this.runtime; await previous.supervisor.stop();
|
|
72
82
|
if (this.runtime === previous) { this.runtime = undefined; this.starting = undefined; }
|
|
73
83
|
}
|
|
74
|
-
this.runtime ??= this.factory(worker.cwd);
|
|
84
|
+
this.runtime ??= this.factory(worker.cwd, (threadIdArg) => this.onNativeAttention?.(threadIdArg));
|
|
75
85
|
this.starting ??= this.runtime.supervisor.start(); await this.starting;
|
|
76
86
|
return this.runtime.adapter;
|
|
77
87
|
}
|
|
@@ -253,6 +263,11 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
|
|
|
253
263
|
const latest = codexArray(result.data, 1).map(codexRecord)[0];
|
|
254
264
|
return latest?.status === 'inProgress' ? codexString(latest.id) : undefined;
|
|
255
265
|
}
|
|
266
|
+
/** Every native thread with requests this connection holds for AGL, without reading anything. */
|
|
267
|
+
public nativePendingAttention(): IFleetNativePendingAttention[] {
|
|
268
|
+
return (this.runtime?.adapter.pendingAttention() ?? []).flatMap((entry) => entry.projectId === 'fleet'
|
|
269
|
+
? [{ nativeId: entry.threadId, cwd: entry.directory, title: entry.session.title, attention: entry.attention }] : []);
|
|
270
|
+
}
|
|
256
271
|
/** The requests of turns this connection runs in the thread that wait for an answer. */
|
|
257
272
|
public async nativeAttention(session: IFleetNativeSession): Promise<IControllerAttention> {
|
|
258
273
|
return (await this.scoped(session)).attention(session.nativeId);
|
|
@@ -2,9 +2,14 @@ import * as plugins from '../plugins.js';
|
|
|
2
2
|
import { FleetDispatchError } from './interfaces.workers.js';
|
|
3
3
|
|
|
4
4
|
export interface IFleetWorkerCommand { stdout: string; stderr: string; code: number }
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Judges a child's stdout while it runs, from everything it printed so far: `undefined` while that decides nothing yet,
|
|
7
|
+
* `true` once the output is accepted (the watch then ends), or the error the child is stopped and the run fails with.
|
|
8
|
+
*/
|
|
9
|
+
export type TFleetWorkerOutputWatch = (stdout: string) => true | Error | undefined;
|
|
10
|
+
export type TFleetWorkerRunner = (command: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, signal: AbortSignal, watch?: TFleetWorkerOutputWatch) => Promise<IFleetWorkerCommand>;
|
|
6
11
|
/** Only owns the short-lived management/relay child, never a native background worker. */
|
|
7
|
-
export const runFleetWorkerCommand: TFleetWorkerRunner = (command, args, cwd, env, signal) => {
|
|
12
|
+
export const runFleetWorkerCommand: TFleetWorkerRunner = (command, args, cwd, env, signal, watch) => {
|
|
8
13
|
signal.throwIfAborted();
|
|
9
14
|
return new Promise((resolve, reject) => {
|
|
10
15
|
const child = plugins.childProcess.spawn(command, args, { cwd, env, detached: process.platform !== 'win32', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -15,10 +20,15 @@ export const runFleetWorkerCommand: TFleetWorkerRunner = (command, args, cwd, en
|
|
|
15
20
|
const abort = () => { failure = new FleetDispatchError('Native worker command cancelled; its dispatch outcome may be unknown.', Boolean(child.pid)); stop(); };
|
|
16
21
|
const timer = setTimeout(() => { failure = new FleetDispatchError('Native worker command timed out; inspect before retrying.', Boolean(child.pid)); stop(); }, 90_000);
|
|
17
22
|
signal.addEventListener('abort', abort, { once: true });
|
|
23
|
+
let watching = watch;
|
|
18
24
|
const collect = (kind: 'stdout' | 'stderr', chunk: Buffer) => {
|
|
19
25
|
bytes += chunk.length;
|
|
20
|
-
if (bytes > 8 * 1024 * 1024) { failure = new FleetDispatchError('Native worker output limit exceeded.', Boolean(child.pid)); stop(); }
|
|
21
|
-
|
|
26
|
+
if (bytes > 8 * 1024 * 1024) { failure = new FleetDispatchError('Native worker output limit exceeded.', Boolean(child.pid)); stop(); return; }
|
|
27
|
+
(kind === 'stdout' ? out : err).push(chunk);
|
|
28
|
+
if (kind !== 'stdout' || !watching || failure) return;
|
|
29
|
+
const verdict = watching(Buffer.concat(out).toString('utf8'));
|
|
30
|
+
if (verdict === true) watching = undefined;
|
|
31
|
+
else if (verdict) { failure = verdict; watching = undefined; stop(); }
|
|
22
32
|
};
|
|
23
33
|
child.stdout.on('data', (chunk: Buffer) => collect('stdout', chunk)); child.stderr.on('data', (chunk: Buffer) => collect('stderr', chunk));
|
|
24
34
|
child.on('error', (error) => { failure = new FleetDispatchError('Native worker executable failed.', false, { cause: error }); });
|
|
@@ -10,7 +10,7 @@ import { FleetEvents } from './classes.events.js';
|
|
|
10
10
|
import { FleetClaudeWorkers } from './classes.claudeworkers.js';
|
|
11
11
|
import { FleetCodexWorkers } from './classes.codexworkers.js';
|
|
12
12
|
import type { FleetWorkerLaunches } from './classes.workerlaunches.js';
|
|
13
|
-
import { FleetDispatchError, FleetWorkerError, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeAgent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt, type TFleetNativeReply } from './interfaces.workers.js';
|
|
13
|
+
import { FleetDispatchError, FleetWorkerError, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeAgent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePendingAttention, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt, type TFleetNativeReply } from './interfaces.workers.js';
|
|
14
14
|
import { assertFleetWorkerRequest, validateFleetWorkerProfiles } from './functions.workervalidation.js';
|
|
15
15
|
import { readControllerProcessIdentity, controllerProcessIdentityIsLive } from '../classes.processinspection.js';
|
|
16
16
|
import { ticketActorSchema } from '../functions.ticketvalidation.js';
|
|
@@ -49,6 +49,8 @@ export interface IFleetWorkersOptions {
|
|
|
49
49
|
nativeMessages?: IFleetNativeMessages;
|
|
50
50
|
/** Told each Claude Code release newer than the verified one that the default Claude backend runs on. */
|
|
51
51
|
claudeReleases?: (releaseArg: string) => void;
|
|
52
|
+
/** Told of each native Codex thread whose requests the default Codex backend holds for AGL came or went. */
|
|
53
|
+
onNativeCodexAttention?: (nativeIdArg: string) => void;
|
|
52
54
|
}
|
|
53
55
|
/** The fleet events that change what the Driver view shows of the fleet's workers. */
|
|
54
56
|
export const fleetWorkerViewEventKinds: ReadonlySet<TFleetEventKind> = new Set<TFleetEventKind>(['worker.changed', 'worker.turn.ended', 'worker.report.mid_turn', 'worker.reaped', 'worker.credential.failed']);
|
|
@@ -108,7 +110,7 @@ export class FleetWorkers {
|
|
|
108
110
|
constructor(private readonly options: IFleetWorkersOptions = {}) {
|
|
109
111
|
this.store = options.store ?? new FleetWorkerStore(); this.events = options.events ?? new FleetEvents();
|
|
110
112
|
this.backends = options.backends ?? { claude: new FleetClaudeWorkers(this.abort.signal, undefined, undefined, options.callers, options.claudeReleases),
|
|
111
|
-
codex: new FleetCodexWorkers(this.abort.signal, undefined, options.callers) };
|
|
113
|
+
codex: new FleetCodexWorkers(this.abort.signal, undefined, options.callers, options.onNativeCodexAttention) };
|
|
112
114
|
}
|
|
113
115
|
public start(): void {
|
|
114
116
|
if (this.pollTimer || this.abort.signal.aborted) return;
|
|
@@ -330,6 +332,11 @@ export class FleetWorkers {
|
|
|
330
332
|
if (!backend.relaunchBlocker) throw new Error('Only a Claude Code session is relaunched.');
|
|
331
333
|
return await backend.relaunchBlocker(cwd, profile, nativeId);
|
|
332
334
|
}
|
|
335
|
+
/** Every native session of `harness` with requests its backend holds for AGL, without reading anything. */
|
|
336
|
+
public nativePendingAttention(harness: IFleetWorker['harness']): IFleetNativePendingAttention[] {
|
|
337
|
+
if (this.abort.signal.aborted) return [];
|
|
338
|
+
return this.backends[harness].nativePendingAttention?.() ?? [];
|
|
339
|
+
}
|
|
333
340
|
public async nativeAttention(harness: IFleetWorker['harness'], session: IFleetNativeSession): Promise<IControllerAttention> {
|
|
334
341
|
return await this.nativeBackend(harness, 'nativeAttention')(session);
|
|
335
342
|
}
|
|
@@ -126,7 +126,7 @@ export const listUnboundDrivers = async (
|
|
|
126
126
|
export const unboundDriverLines = (resultArg: { drivers: IFleetUnboundDriver[]; errors: string[] }): string => {
|
|
127
127
|
const lines = resultArg.drivers.map((driver) => `- ${driver.name ? JSON.stringify(driver.name) : 'unnamed job'} ${driver.nativeId}`
|
|
128
128
|
+ ` (${driver.state}, ${driver.cwd}; looks like a driver by ${driver.driverLike.join(' and ')}): `
|
|
129
|
-
+ (driver.nativeMessage ? `message it
|
|
129
|
+
+ (driver.nativeMessage ? `message it with ${driver.nativeMessage} (a running job by its unique session name), or adopt it once it settles: ${driver.adopt}`
|
|
130
130
|
: driver.adopt ? `adopt it: ${driver.adopt}`
|
|
131
131
|
: `the archived worker ${JSON.stringify(driver.archivedWorker)} still binds it, so it cannot be adopted`));
|
|
132
132
|
return [lines.length ? lines.join('\n') : '- none found', ...resultArg.errors.map((error) => `- not read: ${error}`)].join('\n');
|
|
@@ -119,7 +119,7 @@ const nativeWait = plugins.z.object({ reason: plugins.z.enum(controllerNativeWai
|
|
|
119
119
|
const report = plugins.z.object({ worker: fleetWorkerSchema, status: reportStatus,
|
|
120
120
|
turnId: text.optional(), turnStatus: text.optional(), outcome: outcome.optional(), reportId: text.optional(), text: plugins.z.string().max(64 * 1024),
|
|
121
121
|
truncated: plugins.z.boolean(), error: plugins.z.string().max(4096).optional() }).strict();
|
|
122
|
-
const nativeMessage = plugins.z.object({ delivery: plugins.z.
|
|
122
|
+
const nativeMessage = plugins.z.object({ delivery: plugins.z.enum(['native-wake', 'native-inbox']), nativeId: plugins.z.string().uuid(), jobId: text, cwd,
|
|
123
123
|
profileId: name.optional(), note: plugins.z.string().min(1).max(4096), adopt: plugins.z.string().min(1).max(8192) }).strict();
|
|
124
124
|
const job = plugins.z.object({ id: text, action: plugins.z.enum(['start', 'adopt', 'resolve-lost', 'reconfirm', 'steer', 'report', 'stop', 'archive', 'refresh', 'move', 'native-message']),
|
|
125
125
|
ticketKey: ticketKey.optional(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
2
|
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerTurnOutcome, IFleetRelaunchBlocker, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof, TFleetWorkerErrorCode } from '../../ts_interfaces/fleetworkers.js';
|
|
3
|
-
import type { IControllerAttention, IControllerMessageBundle, IControllerNativeWait, TControllerElicitationReply, TControllerPermissionReply } from '../../ts_interfaces/index.js';
|
|
3
|
+
import type { IControllerAttention, IControllerMessageBundle, IControllerNativeWait, TControllerElicitationReply, TControllerNativeJobDelivery, TControllerPermissionReply } from '../../ts_interfaces/index.js';
|
|
4
4
|
|
|
5
5
|
/** The owner's answer to a request of a native session: a permission, a question (`null` rejects it) or an MCP elicitation. */
|
|
6
6
|
export type TFleetNativeReply = { permission: TControllerPermissionReply } | { answers: string[][] | null } | { elicitation: TControllerElicitationReply };
|
|
@@ -25,8 +25,11 @@ export class FleetNativeTurnError extends Error {
|
|
|
25
25
|
* `agentMessage` steers a turn another client runs only when `expectedTurnId` names it, as an agent message must.
|
|
26
26
|
*/
|
|
27
27
|
export interface IFleetNativeSendTurn { expectedTurnId?: string; agentMessage?: boolean }
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Whether a native send steered the running turn or started the next one, and that turn's id when known; for a Claude
|
|
30
|
+
* Code background job, whether it was woken or took the message in its inbox (`job`).
|
|
31
|
+
*/
|
|
32
|
+
export interface IFleetNativeSendReceipt { steered: boolean; turnId?: string; job?: TControllerNativeJobDelivery }
|
|
30
33
|
export interface IFleetNativeEvent {
|
|
31
34
|
nativeId: string; kind: 'worker.turn.ended' | 'worker.report.mid_turn' | 'worker.reaped' | 'worker.credential.failed'; turnId?: string; status?: string;
|
|
32
35
|
text?: string; reportId?: string; truncated?: boolean; error?: string;
|
|
@@ -56,11 +59,21 @@ export interface IFleetNativeThread {
|
|
|
56
59
|
/** Why the thread waits for a person in the harness's own client: set exactly when `status` is `waiting`. */
|
|
57
60
|
nativeWait?: IControllerNativeWait;
|
|
58
61
|
}
|
|
62
|
+
/** A native session with requests a backend holds for AGL: where it runs, its title and the requests. */
|
|
63
|
+
export interface IFleetNativePendingAttention {
|
|
64
|
+
nativeId: string;
|
|
65
|
+
cwd: string;
|
|
66
|
+
title: string;
|
|
67
|
+
attention: IControllerAttention;
|
|
68
|
+
}
|
|
59
69
|
/**
|
|
60
70
|
* A native session the fleet lists but does not bind: `cwd` is the directory its own source lists, `home` the profile
|
|
61
|
-
* home whose Claude Code holds it (the host's own when absent).
|
|
71
|
+
* home whose Claude Code holds it (the host's own when absent). `jobDelivery` is how the sender prepared its message for a
|
|
72
|
+
* Claude Code background job; a job found in the other state is refused before anything is sent. `peerHomes` are the
|
|
73
|
+
* other Claude Code homes whose running sessions SendMessage reaches by name, so a running job's name must be unique
|
|
74
|
+
* across them too when its inbox is addressed.
|
|
62
75
|
*/
|
|
63
|
-
export interface IFleetNativeSession { nativeId: string; cwd: string; home?: string }
|
|
76
|
+
export interface IFleetNativeSession { nativeId: string; cwd: string; home?: string; jobDelivery?: TControllerNativeJobDelivery; peerHomes?: string[] }
|
|
64
77
|
/** A transcript page read-only: `nextCursor` pages to older bundles, and `earlier` says older bundles exist at all. */
|
|
65
78
|
export interface IFleetNativePage { bundles: IControllerMessageBundle[]; earlier: boolean; nextCursor?: string }
|
|
66
79
|
export interface IFleetWorkerBackend {
|
|
@@ -109,6 +122,8 @@ export interface IFleetWorkerBackend {
|
|
|
109
122
|
nativeTurn?(session: IFleetNativeSession): Promise<string | undefined>;
|
|
110
123
|
/** The requests of turns the backend runs in a native session that wait for an answer. */
|
|
111
124
|
nativeAttention?(session: IFleetNativeSession): Promise<IControllerAttention>;
|
|
125
|
+
/** Every native session with requests the backend holds for AGL, from what it holds alone (no read). */
|
|
126
|
+
nativePendingAttention?(): IFleetNativePendingAttention[];
|
|
112
127
|
nativeReply?(session: IFleetNativeSession, requestId: string, reply: TFleetNativeReply): Promise<void>;
|
|
113
128
|
/** Drops the worker's poll baseline: the next poll observes it afresh and reports nothing it observed before. */
|
|
114
129
|
forget?(worker: IFleetWorker): void;
|
|
@@ -42,6 +42,9 @@ export const agentMessageSubjects = {
|
|
|
42
42
|
anonymous: 'unidentified local caller (self-declared sender)',
|
|
43
43
|
fleet: 'AGL controller fleet events',
|
|
44
44
|
owner: 'the owner, in the AGL Driver view',
|
|
45
|
+
/** The owner's own message into a running Claude Code job's inbox, from AGL's native session view or a paired device. */
|
|
46
|
+
ownerNativeView: 'the owner, in AGL\'s native session view',
|
|
47
|
+
ownerDevice: 'the owner, on a paired AGL device',
|
|
45
48
|
driver: 'the AGL Driver session',
|
|
46
49
|
/** A fleet owner capability the local AGL CLI holds, issued to the OS user it names. */
|
|
47
50
|
localCli: (osUserArg: string): string => `the local AGL CLI of OS user ${quoteAgentMessageHeaderText(osUserArg)}, with the owner capability`,
|
|
@@ -33,6 +33,8 @@ export interface IControllerManagementPeer {
|
|
|
33
33
|
headers: Headers;
|
|
34
34
|
state: Record<string, unknown>;
|
|
35
35
|
};
|
|
36
|
+
/** The request's loopback connection, from which a local CLI caller's process is proved (`agl remote gateway sync`). */
|
|
37
|
+
connection?: plugins.smartserve.IConnectionInfo;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export const isLoopbackPeerAddress = (addressArg: string | undefined): boolean => (
|
|
@@ -113,11 +115,24 @@ export const admitControllerManagementTypedRequest = (
|
|
|
113
115
|
peer: {
|
|
114
116
|
id: `management:${plugins.crypto.randomUUID()}`,
|
|
115
117
|
context: { headers: contextArg.headers, state: {} },
|
|
118
|
+
...(contextArg.connectionInfo === undefined ? {} : { connection: { ...contextArg.connectionInfo } }),
|
|
116
119
|
},
|
|
117
120
|
},
|
|
118
121
|
};
|
|
119
122
|
};
|
|
120
123
|
|
|
124
|
+
/** The loopback connection a management request's peer carries, or `undefined` when it carries none. */
|
|
125
|
+
export const readManagementPeerConnection = (localDataArg: unknown): plugins.smartserve.IConnectionInfo | undefined => {
|
|
126
|
+
const peer = typeof localDataArg === 'object' && localDataArg !== null
|
|
127
|
+
? (localDataArg as { peer?: unknown }).peer : undefined;
|
|
128
|
+
const connection = typeof peer === 'object' && peer !== null ? (peer as { connection?: unknown }).connection : undefined;
|
|
129
|
+
if (typeof connection !== 'object' || connection === null) return undefined;
|
|
130
|
+
const { remoteAddr, remotePort, localAddr, localPort, encrypted } = connection as Record<string, unknown>;
|
|
131
|
+
if (typeof remoteAddr !== 'string' || typeof localAddr !== 'string' || typeof encrypted !== 'boolean'
|
|
132
|
+
|| !Number.isSafeInteger(remotePort) || !Number.isSafeInteger(localPort)) return undefined;
|
|
133
|
+
return { remoteAddr, remotePort: remotePort as number, localAddr, localPort: localPort as number, encrypted };
|
|
134
|
+
};
|
|
135
|
+
|
|
121
136
|
/**
|
|
122
137
|
* The management endpoint as a surface of the controller's listener: it matches only the exact host and path, so
|
|
123
138
|
* every other request on the port keeps reaching the browser surface.
|