@alpacakit/agents 0.1.0-beta.31 → 0.1.0-beta.36
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 +40 -10
- package/dist/agents/claude.d.ts +9 -2
- package/dist/agents/claude.d.ts.map +1 -1
- package/dist/agents/claude.js +35 -5
- package/dist/agents/codex.d.ts +1 -1
- package/dist/agents/codex.d.ts.map +1 -1
- package/dist/agents/codex.js +19 -1
- package/dist/core/error.d.ts +25 -0
- package/dist/core/error.d.ts.map +1 -1
- package/dist/core/error.js +15 -0
- package/dist/core/node-controlled-exec.d.ts.map +1 -1
- package/dist/core/node-controlled-exec.js +31 -8
- package/dist/core/node-ports.d.ts.map +1 -1
- package/dist/core/node-ports.js +20 -0
- package/dist/core/ports.d.ts +5 -0
- package/dist/core/ports.d.ts.map +1 -1
- package/dist/fleet/policy.d.ts.map +1 -1
- package/dist/fleet/policy.js +3 -0
- package/dist/host/availability.d.ts +56 -0
- package/dist/host/availability.d.ts.map +1 -0
- package/dist/host/availability.js +177 -0
- package/dist/host/command-doctor.d.ts +4 -0
- package/dist/host/command-doctor.d.ts.map +1 -0
- package/dist/host/command-doctor.js +21 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/internal/controlled-process/host-controller.d.ts +3 -2
- package/dist/internal/controlled-process/host-controller.d.ts.map +1 -1
- package/dist/internal/controlled-process/host-controller.js +63 -23
- package/dist/internal/controlled-process/input-transport.d.ts +17 -0
- package/dist/internal/controlled-process/input-transport.d.ts.map +1 -0
- package/dist/internal/controlled-process/input-transport.js +188 -0
- package/dist/internal/controlled-process/lifecycle.d.ts +1 -1
- package/dist/internal/controlled-process/lifecycle.d.ts.map +1 -1
- package/dist/internal/controlled-process/lifecycle.js +1 -0
- package/dist/internal/controlled-process/schema.d.ts +2 -2
- package/dist/internal/controlled-process/schema.js +1 -1
- package/dist/internal/controlled-process/shim-runtime.d.ts.map +1 -1
- package/dist/internal/controlled-process/shim-runtime.js +43 -4
- package/dist/internal/controlled-process/supervisor-coordinator.d.ts.map +1 -1
- package/dist/internal/controlled-process/supervisor-coordinator.js +4 -2
- package/dist/internal/controlled-process/supervisor-model.d.ts +24 -2
- package/dist/internal/controlled-process/supervisor-model.d.ts.map +1 -1
- package/dist/internal/controlled-process/supervisor-runtime.d.ts.map +1 -1
- package/dist/internal/controlled-process/supervisor-runtime.js +116 -15
- package/dist/internal/controlled-process/supervisor-schema.d.ts +66 -3
- package/dist/internal/controlled-process/supervisor-schema.d.ts.map +1 -1
- package/dist/internal/controlled-process/supervisor-schema.js +31 -3
- package/dist/internal/controlled-process/supervisor-values.d.ts +5 -0
- package/dist/internal/controlled-process/supervisor-values.d.ts.map +1 -1
- package/dist/internal/controlled-process/supervisor-values.js +5 -0
- package/dist/internal/controlled-process/values.d.ts +4 -4
- package/dist/internal/controlled-process/values.js +4 -4
- package/dist/kernel/cli-agent.d.ts +3 -0
- package/dist/kernel/cli-agent.d.ts.map +1 -1
- package/dist/kernel/cli-agent.js +8 -19
- package/dist/kernel/definition.d.ts +2 -0
- package/dist/kernel/definition.d.ts.map +1 -1
- package/dist/kernel/facets.d.ts +5 -0
- package/dist/kernel/facets.d.ts.map +1 -1
- package/dist/kernel/facets.js +5 -0
- package/dist/kernel/runtime.d.ts +2 -1
- package/dist/kernel/runtime.d.ts.map +1 -1
- package/dist/kernel/runtime.js +4 -1
- package/dist/structured/run-structured.d.ts.map +1 -1
- package/dist/structured/run-structured.js +2 -5
- package/package.json +2 -2
|
@@ -2,22 +2,26 @@
|
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { CHILD_PROCESS_TERMINATION_KIND } from "../../core/controlled-process.js";
|
|
5
|
+
import { CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE } from "../../core/error.js";
|
|
5
6
|
import { readString } from "../../core/json.js";
|
|
6
7
|
import { closeWritableFd, readableFd, writableFd } from "./child-fd.js";
|
|
7
8
|
import { readFramedRecords, readRequiredFrame, writeFramedRecord, } from "./framed-transport.js";
|
|
9
|
+
import { ControlledProcessLaunchError, launchFailure, transferWorkerInput, } from "./input-transport.js";
|
|
8
10
|
import { assertSecureRuntimeDirectory, resolveSupervisorSocketNamespace, SignedRecordStore, supervisorSocketPath, } from "./record-store.js";
|
|
9
11
|
import { controlledProcessRecordIdSchema, shimProcessIdSchema, supervisorCapabilitySchema, supervisorInstanceIdSchema, supervisorSocketLocatorSchema, } from "./schema.js";
|
|
10
12
|
import { SupervisorCoordinator } from "./supervisor-coordinator.js";
|
|
11
13
|
import { createSupervisorPlatformAdapter } from "./supervisor-platform.js";
|
|
12
|
-
import { shimRunningSchema, supervisorBootstrapSchema, supervisorHostAckSchema, workerExitSchema, } from "./supervisor-schema.js";
|
|
14
|
+
import { shimLaunchFailedSchema, shimRunningSchema, supervisorBootstrapSchema, supervisorHostAckSchema, workerExitSchema, } from "./supervisor-schema.js";
|
|
13
15
|
import { SupervisorSocketServer } from "./supervisor-transport.js";
|
|
14
16
|
import { PROCESS_PROBE_KIND, SHIM_FRAME_KIND, SUPERVISOR_BOOTSTRAP_FRAME_KIND, SUPERVISOR_CONVERGENCE_REASON, SUPERVISOR_REQUEST_KIND, SUPERVISOR_RESPONSE_KIND, } from "./supervisor-values.js";
|
|
15
17
|
import { encodeProcessStartToken } from "./token.js";
|
|
16
18
|
import { CONTROLLED_PROCESS_PROTOCOL_VERSION, CONTROLLED_PROCESS_STATE, } from "./values.js";
|
|
17
19
|
const HOST_BOOTSTRAP_FD = 3;
|
|
18
20
|
const HOST_IDENTITY_FD = 4;
|
|
21
|
+
const HOST_INPUT_FD = 5;
|
|
19
22
|
const SHIM_CONTROL_FD = 3;
|
|
20
23
|
const SHIM_STATUS_FD = 4;
|
|
24
|
+
const SHIM_INPUT_FD = 5;
|
|
21
25
|
const RANDOM_ID_BYTES = 16;
|
|
22
26
|
const CAPABILITY_BYTES = 32;
|
|
23
27
|
const ATTACHED_STDOUT = process.stdout;
|
|
@@ -30,6 +34,7 @@ const SUPERVISOR_RUNTIME_DEPENDENCIES = {
|
|
|
30
34
|
};
|
|
31
35
|
export async function runControlledProcessSupervisor(dependencies = SUPERVISOR_RUNTIME_DEPENDENCIES) {
|
|
32
36
|
const hostInput = readableFd(HOST_BOOTSTRAP_FD);
|
|
37
|
+
const hostData = readableFd(HOST_INPUT_FD);
|
|
33
38
|
const hostOutput = {
|
|
34
39
|
stream: writableFd(HOST_IDENTITY_FD),
|
|
35
40
|
closePromise: null,
|
|
@@ -41,6 +46,7 @@ export async function runControlledProcessSupervisor(dependencies = SUPERVISOR_R
|
|
|
41
46
|
bootstrap,
|
|
42
47
|
frames,
|
|
43
48
|
hostInput,
|
|
49
|
+
hostData,
|
|
44
50
|
hostOutput,
|
|
45
51
|
dependencies,
|
|
46
52
|
});
|
|
@@ -49,7 +55,7 @@ export async function runControlledProcessSupervisor(dependencies = SUPERVISOR_R
|
|
|
49
55
|
if (hostOutput.closePromise === null) {
|
|
50
56
|
await writeFramedRecord(hostOutput.stream, {
|
|
51
57
|
kind: SUPERVISOR_BOOTSTRAP_FRAME_KIND.launchFailed,
|
|
52
|
-
|
|
58
|
+
failure: launchFailureFromUnknown(error),
|
|
53
59
|
}).catch(() => undefined);
|
|
54
60
|
await closeHostOutput(hostOutput).catch(() => undefined);
|
|
55
61
|
}
|
|
@@ -57,6 +63,7 @@ export async function runControlledProcessSupervisor(dependencies = SUPERVISOR_R
|
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
// biome-ignore lint/complexity/noExcessiveLinesPerFunction: The lifecycle sequence is kept contiguous because section 5.103 forbids a new runtime owner.
|
|
66
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: The lifecycle sequence keeps failure custody and cleanup flags in one owner.
|
|
60
67
|
async function runSupervisorSession(input) {
|
|
61
68
|
const platform = createSupervisorPlatformAdapter();
|
|
62
69
|
const runtimeDirectory = await assertSecureRuntimeDirectory(input.bootstrap.runtimeDirectory, platform.uid);
|
|
@@ -72,6 +79,7 @@ async function runSupervisorSession(input) {
|
|
|
72
79
|
let shimPid = null;
|
|
73
80
|
let shimControl = null;
|
|
74
81
|
let shimStatus = null;
|
|
82
|
+
let shimInput = null;
|
|
75
83
|
let shimClosed = null;
|
|
76
84
|
let lifecycleMonitor = null;
|
|
77
85
|
let lifecycleMonitorInFlight = null;
|
|
@@ -80,7 +88,8 @@ async function runSupervisorSession(input) {
|
|
|
80
88
|
let initialPersistCommitted = false;
|
|
81
89
|
let initialPersistReceipt = null;
|
|
82
90
|
let identityDelivered = false;
|
|
83
|
-
let
|
|
91
|
+
let workerReady = false;
|
|
92
|
+
let hostCustodyStarted = false;
|
|
84
93
|
let rollbackAttempted = false;
|
|
85
94
|
let ownershipLossObserved = false;
|
|
86
95
|
let ownershipLossPromise = null;
|
|
@@ -133,7 +142,7 @@ async function runSupervisorSession(input) {
|
|
|
133
142
|
stopLifecycleMonitor();
|
|
134
143
|
input.hostInput.destroy();
|
|
135
144
|
await beforeOwnershipLossDeadline(Promise.all([
|
|
136
|
-
settleOwnershipLossHostOutput(input.hostOutput, convergenceDescription(reason, identityDelivered)),
|
|
145
|
+
settleOwnershipLossHostOutput(input.hostOutput, reason, convergenceDescription(reason, identityDelivered)),
|
|
137
146
|
server.settleAcceptedSessions(),
|
|
138
147
|
]).then(() => undefined), deadline, "Supervisor ownership-loss host output or session drain timed out.");
|
|
139
148
|
const persistReceipt = initialPersistReceipt;
|
|
@@ -196,7 +205,7 @@ async function runSupervisorSession(input) {
|
|
|
196
205
|
void startOwnershipLossConvergence(SUPERVISOR_CONVERGENCE_REASON.socketOwnershipLost);
|
|
197
206
|
return;
|
|
198
207
|
}
|
|
199
|
-
if (
|
|
208
|
+
if (hostCustodyStarted &&
|
|
200
209
|
hostIdleDeadline !== null &&
|
|
201
210
|
Date.now() >= hostIdleDeadline) {
|
|
202
211
|
void startOwnershipLossConvergence(SUPERVISOR_CONVERGENCE_REASON.hostIdleTimeout);
|
|
@@ -228,6 +237,8 @@ async function runSupervisorSession(input) {
|
|
|
228
237
|
shimClosed = waitForShimClose(shim);
|
|
229
238
|
shimControl = shim.stdio[SHIM_CONTROL_FD];
|
|
230
239
|
shimStatus = shim.stdio[SHIM_STATUS_FD];
|
|
240
|
+
shimInput = shim.stdio.at(SHIM_INPUT_FD);
|
|
241
|
+
shimInput.on("error", () => { });
|
|
231
242
|
const pid = requireShimPid(shim);
|
|
232
243
|
shimPid = pid;
|
|
233
244
|
const record = {
|
|
@@ -281,7 +292,19 @@ async function runSupervisorSession(input) {
|
|
|
281
292
|
return response;
|
|
282
293
|
};
|
|
283
294
|
trackLocalCoordinatorOperation(attachOutput(shim, runLocalCoordinatorOperation));
|
|
284
|
-
|
|
295
|
+
let resolveShimReady = () => { };
|
|
296
|
+
let rejectShimReady = (_error) => { };
|
|
297
|
+
const shimReady = new Promise((resolve, reject) => {
|
|
298
|
+
resolveShimReady = resolve;
|
|
299
|
+
rejectShimReady = reject;
|
|
300
|
+
});
|
|
301
|
+
void shimReady.catch(() => undefined);
|
|
302
|
+
trackLocalCoordinatorOperation(pumpShimStatus(shimStatus, runLocalCoordinatorOperation, resolveShimReady).catch(async (error) => {
|
|
303
|
+
rejectShimReady(error);
|
|
304
|
+
if (!(error instanceof ControlledProcessLaunchError)) {
|
|
305
|
+
await runLocalCoordinatorOperation(async (current) => current.recordProtocolFailure());
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
285
308
|
shim.once("exit", () => {
|
|
286
309
|
trackLocalCoordinatorOperation(runLocalCoordinatorOperation(async (current) => current.recordShimExit()));
|
|
287
310
|
});
|
|
@@ -291,7 +314,17 @@ async function runSupervisorSession(input) {
|
|
|
291
314
|
await writeFramedRecord(shimControl, {
|
|
292
315
|
kind: SHIM_FRAME_KIND.bootstrap,
|
|
293
316
|
worker: input.bootstrap.worker,
|
|
317
|
+
input: input.bootstrap.input,
|
|
318
|
+
inputTimeoutMs: input.bootstrap.timing.hostIdleTimeoutMs,
|
|
319
|
+
});
|
|
320
|
+
const inputRelay = transferWorkerInput({
|
|
321
|
+
readable: input.hostData,
|
|
322
|
+
writable: shimInput,
|
|
323
|
+
manifest: input.bootstrap.input,
|
|
324
|
+
stage: "supervisor_to_shim",
|
|
325
|
+
timeoutMs: input.bootstrap.timing.hostIdleTimeoutMs,
|
|
294
326
|
});
|
|
327
|
+
void inputRelay.catch(() => undefined);
|
|
295
328
|
await observeOwnership(true);
|
|
296
329
|
const persistOperation = (input.dependencies.persistInitialRecord ??
|
|
297
330
|
SUPERVISOR_RUNTIME_DEPENDENCIES.persistInitialRecord)(activeCoordinator);
|
|
@@ -336,10 +369,18 @@ async function runSupervisorSession(input) {
|
|
|
336
369
|
await runCoordinatorOperation(async (current) => current.acknowledge());
|
|
337
370
|
coordinatorAckMayHaveCommitted = true;
|
|
338
371
|
await input.dependencies.writeShimAck(shimControl);
|
|
372
|
+
const [inputRelaySettlement, shimReadySettlement] = await Promise.allSettled([inputRelay, shimReady]);
|
|
373
|
+
if (shimReadySettlement.status === "rejected") {
|
|
374
|
+
throw shimReadySettlement.reason;
|
|
375
|
+
}
|
|
376
|
+
if (inputRelaySettlement.status === "rejected") {
|
|
377
|
+
throw inputRelaySettlement.reason;
|
|
378
|
+
}
|
|
339
379
|
await observeOwnership(false);
|
|
340
380
|
coordinatorTickEnabled = true;
|
|
341
|
-
|
|
342
|
-
|
|
381
|
+
workerReady = true;
|
|
382
|
+
hostCustodyStarted = true;
|
|
383
|
+
recordHostActivity({ kind: "custody_started" });
|
|
343
384
|
await closeHostOutput(input.hostOutput);
|
|
344
385
|
input.hostInput.destroy();
|
|
345
386
|
await released;
|
|
@@ -354,17 +395,50 @@ async function runSupervisorSession(input) {
|
|
|
354
395
|
}
|
|
355
396
|
shimControl.destroy();
|
|
356
397
|
shimStatus.destroy();
|
|
398
|
+
shimInput.destroy();
|
|
357
399
|
}
|
|
358
400
|
catch (primaryFailure) {
|
|
359
401
|
await observeOwnership(false).catch(() => undefined);
|
|
360
402
|
if (ownershipLossPromise !== null) {
|
|
361
403
|
await ownershipLossPromise;
|
|
362
404
|
}
|
|
363
|
-
if (
|
|
405
|
+
if (workerReady || rollbackAttempted) {
|
|
364
406
|
stopLifecycleMonitor();
|
|
365
407
|
await settleLifecycleMonitor().catch(() => undefined);
|
|
366
408
|
throw primaryFailure;
|
|
367
409
|
}
|
|
410
|
+
if (primaryFailure instanceof ControlledProcessLaunchError &&
|
|
411
|
+
identityDelivered &&
|
|
412
|
+
coordinator !== null &&
|
|
413
|
+
shimControl !== null &&
|
|
414
|
+
shimStatus !== null &&
|
|
415
|
+
shimClosed !== null &&
|
|
416
|
+
input.hostOutput.closePromise === null) {
|
|
417
|
+
input.hostData.destroy();
|
|
418
|
+
hostCustodyStarted = true;
|
|
419
|
+
recordHostActivity({ kind: "custody_started" });
|
|
420
|
+
const failureReported = await writeStructuredLaunchFailure(input.hostOutput, launchFailureFromUnknown(primaryFailure)).then(() => true, () => false);
|
|
421
|
+
if (!failureReported && ownershipLossPromise !== null) {
|
|
422
|
+
await ownershipLossPromise;
|
|
423
|
+
}
|
|
424
|
+
if (failureReported) {
|
|
425
|
+
await released;
|
|
426
|
+
await shimClosed;
|
|
427
|
+
await settleLocalCoordinatorOperations();
|
|
428
|
+
stopLifecycleMonitor();
|
|
429
|
+
await settleLifecycleMonitor();
|
|
430
|
+
const finalization = await (input.dependencies.finalizeSupervisorSocket ??
|
|
431
|
+
SUPERVISOR_RUNTIME_DEPENDENCIES.finalizeSupervisorSocket)(server);
|
|
432
|
+
if (finalization.kind === "ownership_lost") {
|
|
433
|
+
await startOwnershipLossConvergence(SUPERVISOR_CONVERGENCE_REASON.socketOwnershipLost);
|
|
434
|
+
}
|
|
435
|
+
shimControl.destroy();
|
|
436
|
+
shimStatus.destroy();
|
|
437
|
+
shimInput?.destroy();
|
|
438
|
+
input.hostInput.destroy();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
368
442
|
try {
|
|
369
443
|
rollbackAttempted = true;
|
|
370
444
|
if (coordinator !== null &&
|
|
@@ -410,6 +484,7 @@ async function runSupervisorSession(input) {
|
|
|
410
484
|
}
|
|
411
485
|
finally {
|
|
412
486
|
input.hostInput.destroy();
|
|
487
|
+
input.hostData.destroy();
|
|
413
488
|
}
|
|
414
489
|
throw primaryFailure;
|
|
415
490
|
}
|
|
@@ -518,16 +593,20 @@ async function convergeAfterOwnershipLoss(input) {
|
|
|
518
593
|
await beforeOwnershipLossDeadline(input.settleLifecycleMonitor(), input.deadline, "Supervisor ownership-loss lifecycle monitor did not settle.");
|
|
519
594
|
return selfSigkill();
|
|
520
595
|
}
|
|
521
|
-
function settleOwnershipLossHostOutput(hostOutput, reason) {
|
|
596
|
+
function settleOwnershipLossHostOutput(hostOutput, reason, description) {
|
|
597
|
+
if (reason === SUPERVISOR_CONVERGENCE_REASON.hostIdleTimeout) {
|
|
598
|
+
hostOutput.stream.destroy();
|
|
599
|
+
return waitForWritableFinish(hostOutput.stream);
|
|
600
|
+
}
|
|
522
601
|
return hostOutput.closePromise === null
|
|
523
|
-
? writeLaunchFailure(hostOutput,
|
|
602
|
+
? writeLaunchFailure(hostOutput, description)
|
|
524
603
|
: hostOutput.closePromise;
|
|
525
604
|
}
|
|
526
605
|
function isHostActivityEvidence(input) {
|
|
527
606
|
if (input.convergenceStarted) {
|
|
528
607
|
return false;
|
|
529
608
|
}
|
|
530
|
-
if (input.activity.kind === "
|
|
609
|
+
if (input.activity.kind === "custody_started") {
|
|
531
610
|
return true;
|
|
532
611
|
}
|
|
533
612
|
const beforeDeadline = input.hostIdleDeadline === null || input.now < input.hostIdleDeadline;
|
|
@@ -620,7 +699,7 @@ function spawnShim(bootstrap) {
|
|
|
620
699
|
const shim = spawn(process.execPath, [bootstrap.shimEntryPath], {
|
|
621
700
|
detached: true,
|
|
622
701
|
env: {},
|
|
623
|
-
stdio: ["ignore", "pipe", "pipe", "pipe", "pipe"],
|
|
702
|
+
stdio: ["ignore", "pipe", "pipe", "pipe", "pipe", "pipe"],
|
|
624
703
|
});
|
|
625
704
|
shim.once("error", () => { });
|
|
626
705
|
return shim;
|
|
@@ -653,12 +732,19 @@ function attachOutput(shim, runCoordinatorOperation) {
|
|
|
653
732
|
pumpOutput(stderr, ATTACHED_STDERR),
|
|
654
733
|
]).then(async () => runCoordinatorOperation(async (coordinator) => coordinator.recordOutputClosed()), async () => runCoordinatorOperation(async (coordinator) => coordinator.recordProtocolFailure()));
|
|
655
734
|
}
|
|
656
|
-
async function pumpShimStatus(status, runCoordinatorOperation) {
|
|
735
|
+
async function pumpShimStatus(status, runCoordinatorOperation, onRunning) {
|
|
736
|
+
let running = false;
|
|
657
737
|
for await (const frame of readFramedRecords(status)) {
|
|
658
738
|
const kind = readString(frame, "kind");
|
|
659
739
|
if (kind === SHIM_FRAME_KIND.running) {
|
|
660
740
|
shimRunningSchema.parse(frame);
|
|
661
741
|
await runCoordinatorOperation(async (coordinator) => coordinator.running());
|
|
742
|
+
running = true;
|
|
743
|
+
onRunning();
|
|
744
|
+
}
|
|
745
|
+
else if (kind === SHIM_FRAME_KIND.launchFailed) {
|
|
746
|
+
const failure = shimLaunchFailedSchema.parse(frame);
|
|
747
|
+
throw new ControlledProcessLaunchError(failure.failure);
|
|
662
748
|
}
|
|
663
749
|
else if (kind === SHIM_FRAME_KIND.workerExit) {
|
|
664
750
|
const workerExit = workerExitSchema.parse(frame);
|
|
@@ -671,6 +757,9 @@ async function pumpShimStatus(status, runCoordinatorOperation) {
|
|
|
671
757
|
throw new Error("Shim status frame is invalid.");
|
|
672
758
|
}
|
|
673
759
|
}
|
|
760
|
+
if (!running) {
|
|
761
|
+
throw launchFailure(CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE.protocolViolation, "control_protocol", null, null, "Shim status closed before reporting running.");
|
|
762
|
+
}
|
|
674
763
|
}
|
|
675
764
|
async function handleRequest(coordinator, kind) {
|
|
676
765
|
if (kind === SUPERVISOR_REQUEST_KIND.probe) {
|
|
@@ -815,10 +904,22 @@ function requireCapturedCoordinator(coordinator) {
|
|
|
815
904
|
async function writeLaunchFailure(hostOutput, reason) {
|
|
816
905
|
await writeFramedRecord(hostOutput.stream, {
|
|
817
906
|
kind: SUPERVISOR_BOOTSTRAP_FRAME_KIND.launchFailed,
|
|
818
|
-
reason,
|
|
907
|
+
failure: launchFailure(CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE.protocolViolation, "control_protocol", null, null, reason).failure,
|
|
819
908
|
});
|
|
820
909
|
await closeHostOutput(hostOutput);
|
|
821
910
|
}
|
|
911
|
+
async function writeStructuredLaunchFailure(hostOutput, failure) {
|
|
912
|
+
await writeFramedRecord(hostOutput.stream, {
|
|
913
|
+
kind: SUPERVISOR_BOOTSTRAP_FRAME_KIND.launchFailed,
|
|
914
|
+
failure,
|
|
915
|
+
});
|
|
916
|
+
await closeHostOutput(hostOutput);
|
|
917
|
+
}
|
|
918
|
+
function launchFailureFromUnknown(error) {
|
|
919
|
+
return error instanceof ControlledProcessLaunchError
|
|
920
|
+
? error.failure
|
|
921
|
+
: launchFailure(CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE.protocolViolation, "control_protocol", null, null, error instanceof Error ? error.message : "Supervisor launch failed.", error).failure;
|
|
922
|
+
}
|
|
822
923
|
function closeHostOutput(hostOutput) {
|
|
823
924
|
hostOutput.closePromise ??= closeWritableFd(hostOutput.stream, HOST_IDENTITY_FD);
|
|
824
925
|
return hostOutput.closePromise;
|
|
@@ -8,8 +8,14 @@ export declare const supervisorBootstrapSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
8
8
|
args: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
9
9
|
cwd: z.ZodString;
|
|
10
10
|
env: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
11
|
-
stdin: z.ZodNullable<z.ZodString>;
|
|
12
11
|
}, z.core.$strip>>;
|
|
12
|
+
input: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
13
|
+
kind: z.ZodLiteral<"none">;
|
|
14
|
+
}, z.core.$strip>>, z.ZodReadonly<z.ZodObject<{
|
|
15
|
+
kind: z.ZodLiteral<"stream">;
|
|
16
|
+
byteLength: z.ZodNumber;
|
|
17
|
+
sha256: z.ZodString;
|
|
18
|
+
}, z.core.$strip>>], "kind">;
|
|
13
19
|
timing: z.ZodReadonly<z.ZodObject<{
|
|
14
20
|
termGraceMs: z.ZodNumber;
|
|
15
21
|
killProbeTimeoutMs: z.ZodNumber;
|
|
@@ -29,7 +35,30 @@ export declare const supervisorIdentityFrameSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
29
35
|
}, z.core.$strip>>;
|
|
30
36
|
export declare const supervisorLaunchFailedFrameSchema: z.ZodReadonly<z.ZodObject<{
|
|
31
37
|
kind: z.ZodLiteral<"launch_failed">;
|
|
32
|
-
|
|
38
|
+
failure: z.ZodReadonly<z.ZodObject<{
|
|
39
|
+
code: z.ZodEnum<{
|
|
40
|
+
readonly inputEarlyEof: "input_early_eof";
|
|
41
|
+
readonly inputOverrun: "input_overrun";
|
|
42
|
+
readonly inputDigestMismatch: "input_digest_mismatch";
|
|
43
|
+
readonly inputWriteFailed: "input_write_failed";
|
|
44
|
+
readonly inputTransferTimeout: "input_transfer_timeout";
|
|
45
|
+
readonly workerExited: "worker_exited_during_launch";
|
|
46
|
+
readonly protocolViolation: "protocol_violation";
|
|
47
|
+
}>;
|
|
48
|
+
retryability: z.ZodEnum<{
|
|
49
|
+
readonly permanent: "permanent";
|
|
50
|
+
readonly transient: "transient";
|
|
51
|
+
}>;
|
|
52
|
+
stage: z.ZodEnum<{
|
|
53
|
+
host_to_supervisor: "host_to_supervisor";
|
|
54
|
+
supervisor_to_shim: "supervisor_to_shim";
|
|
55
|
+
shim_to_worker: "shim_to_worker";
|
|
56
|
+
control_protocol: "control_protocol";
|
|
57
|
+
}>;
|
|
58
|
+
expectedBytes: z.ZodNullable<z.ZodNumber>;
|
|
59
|
+
actualBytes: z.ZodNullable<z.ZodNumber>;
|
|
60
|
+
message: z.ZodString;
|
|
61
|
+
}, z.core.$strip>>;
|
|
33
62
|
}, z.core.$strip>>;
|
|
34
63
|
export declare const shimBootstrapSchema: z.ZodReadonly<z.ZodObject<{
|
|
35
64
|
kind: z.ZodLiteral<"shim_bootstrap">;
|
|
@@ -38,8 +67,15 @@ export declare const shimBootstrapSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
38
67
|
args: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
39
68
|
cwd: z.ZodString;
|
|
40
69
|
env: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
41
|
-
stdin: z.ZodNullable<z.ZodString>;
|
|
42
70
|
}, z.core.$strip>>;
|
|
71
|
+
input: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
72
|
+
kind: z.ZodLiteral<"none">;
|
|
73
|
+
}, z.core.$strip>>, z.ZodReadonly<z.ZodObject<{
|
|
74
|
+
kind: z.ZodLiteral<"stream">;
|
|
75
|
+
byteLength: z.ZodNumber;
|
|
76
|
+
sha256: z.ZodString;
|
|
77
|
+
}, z.core.$strip>>], "kind">;
|
|
78
|
+
inputTimeoutMs: z.ZodNumber;
|
|
43
79
|
}, z.core.$strip>>;
|
|
44
80
|
export declare const shimAckSchema: z.ZodReadonly<z.ZodObject<{
|
|
45
81
|
kind: z.ZodLiteral<"shim_ack">;
|
|
@@ -47,6 +83,33 @@ export declare const shimAckSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
47
83
|
export declare const shimRunningSchema: z.ZodReadonly<z.ZodObject<{
|
|
48
84
|
kind: z.ZodLiteral<"shim_running">;
|
|
49
85
|
}, z.core.$strip>>;
|
|
86
|
+
export declare const shimLaunchFailedSchema: z.ZodReadonly<z.ZodObject<{
|
|
87
|
+
kind: z.ZodLiteral<"shim_launch_failed">;
|
|
88
|
+
failure: z.ZodReadonly<z.ZodObject<{
|
|
89
|
+
code: z.ZodEnum<{
|
|
90
|
+
readonly inputEarlyEof: "input_early_eof";
|
|
91
|
+
readonly inputOverrun: "input_overrun";
|
|
92
|
+
readonly inputDigestMismatch: "input_digest_mismatch";
|
|
93
|
+
readonly inputWriteFailed: "input_write_failed";
|
|
94
|
+
readonly inputTransferTimeout: "input_transfer_timeout";
|
|
95
|
+
readonly workerExited: "worker_exited_during_launch";
|
|
96
|
+
readonly protocolViolation: "protocol_violation";
|
|
97
|
+
}>;
|
|
98
|
+
retryability: z.ZodEnum<{
|
|
99
|
+
readonly permanent: "permanent";
|
|
100
|
+
readonly transient: "transient";
|
|
101
|
+
}>;
|
|
102
|
+
stage: z.ZodEnum<{
|
|
103
|
+
host_to_supervisor: "host_to_supervisor";
|
|
104
|
+
supervisor_to_shim: "supervisor_to_shim";
|
|
105
|
+
shim_to_worker: "shim_to_worker";
|
|
106
|
+
control_protocol: "control_protocol";
|
|
107
|
+
}>;
|
|
108
|
+
expectedBytes: z.ZodNullable<z.ZodNumber>;
|
|
109
|
+
actualBytes: z.ZodNullable<z.ZodNumber>;
|
|
110
|
+
message: z.ZodString;
|
|
111
|
+
}, z.core.$strip>>;
|
|
112
|
+
}, z.core.$strip>>;
|
|
50
113
|
export declare const workerExitSchema: z.ZodReadonly<z.ZodObject<{
|
|
51
114
|
kind: z.ZodLiteral<"worker_exit">;
|
|
52
115
|
code: z.ZodNullable<z.ZodNumber>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor-schema.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"supervisor-schema.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8ExB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;kBAOK,CAAC;AAE5C,eAAO,MAAM,uBAAuB;;kBAEK,CAAC;AAE1C,eAAO,MAAM,6BAA6B;;;;;;kBAGK,CAAC;AAEhD,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;kBAGK,CAAC;AAEpD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;kBAKK,CAAC;AAEtC,eAAO,MAAM,aAAa;;kBAEK,CAAC;AAEhC,eAAO,MAAM,iBAAiB;;kBAEK,CAAC;AAEpC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;kBAGK,CAAC;AAEzC,eAAO,MAAM,gBAAgB;;;;kBAIK,CAAC;AAEnC,eAAO,MAAM,uBAAuB;;;;;;4BAIK,CAAC;AAE1C,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAaK,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { strictReadonlyObject } from "@alpacakit/core";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE, CONTROLLED_PROCESS_LAUNCH_FAILURE_RETRYABILITY, } from "../../core/error.js";
|
|
3
4
|
import { childProcessTerminationResultSchema, controlledProcessIdentitySchema, } from "./schema.js";
|
|
4
|
-
import { SHIM_FRAME_KIND, SUPERVISOR_BOOTSTRAP_FRAME_KIND, SUPERVISOR_REQUEST_KIND, SUPERVISOR_RESPONSE_KIND, } from "./supervisor-values.js";
|
|
5
|
+
import { SHIM_FRAME_KIND, SUPERVISOR_BOOTSTRAP_FRAME_KIND, SUPERVISOR_REQUEST_KIND, SUPERVISOR_RESPONSE_KIND, WORKER_INPUT_KIND, } from "./supervisor-values.js";
|
|
5
6
|
const nonBlankStringSchema = z
|
|
6
7
|
.string()
|
|
7
8
|
.min(1)
|
|
@@ -12,7 +13,27 @@ const workerOptionsSchema = strictReadonlyObject({
|
|
|
12
13
|
args: z.array(z.string()).readonly(),
|
|
13
14
|
cwd: nonBlankStringSchema,
|
|
14
15
|
env: z.record(z.string(), z.string()).readonly(),
|
|
15
|
-
|
|
16
|
+
});
|
|
17
|
+
const workerInputManifestSchema = z.discriminatedUnion("kind", [
|
|
18
|
+
strictReadonlyObject({ kind: z.literal(WORKER_INPUT_KIND.none) }),
|
|
19
|
+
strictReadonlyObject({
|
|
20
|
+
kind: z.literal(WORKER_INPUT_KIND.stream),
|
|
21
|
+
byteLength: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
22
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
|
23
|
+
}),
|
|
24
|
+
]);
|
|
25
|
+
const launchFailureSchema = strictReadonlyObject({
|
|
26
|
+
code: z.enum(CONTROLLED_PROCESS_LAUNCH_FAILURE_CODE),
|
|
27
|
+
retryability: z.enum(CONTROLLED_PROCESS_LAUNCH_FAILURE_RETRYABILITY),
|
|
28
|
+
stage: z.enum([
|
|
29
|
+
"host_to_supervisor",
|
|
30
|
+
"supervisor_to_shim",
|
|
31
|
+
"shim_to_worker",
|
|
32
|
+
"control_protocol",
|
|
33
|
+
]),
|
|
34
|
+
expectedBytes: z.number().int().nonnegative().nullable(),
|
|
35
|
+
actualBytes: z.number().int().nonnegative().nullable(),
|
|
36
|
+
message: nonBlankStringSchema,
|
|
16
37
|
});
|
|
17
38
|
// A worker that is still running is re-probed every `probeIntervalMs`, and an
|
|
18
39
|
// accepted request is the only thing that resets the idle deadline. An idle
|
|
@@ -33,6 +54,7 @@ export const supervisorBootstrapSchema = strictReadonlyObject({
|
|
|
33
54
|
runtimeDirectory: nonBlankStringSchema,
|
|
34
55
|
shimEntryPath: nonBlankStringSchema,
|
|
35
56
|
worker: workerOptionsSchema,
|
|
57
|
+
input: workerInputManifestSchema,
|
|
36
58
|
timing: timingOptionsSchema,
|
|
37
59
|
});
|
|
38
60
|
export const supervisorHostAckSchema = strictReadonlyObject({
|
|
@@ -44,11 +66,13 @@ export const supervisorIdentityFrameSchema = strictReadonlyObject({
|
|
|
44
66
|
});
|
|
45
67
|
export const supervisorLaunchFailedFrameSchema = strictReadonlyObject({
|
|
46
68
|
kind: z.literal(SUPERVISOR_BOOTSTRAP_FRAME_KIND.launchFailed),
|
|
47
|
-
|
|
69
|
+
failure: launchFailureSchema,
|
|
48
70
|
});
|
|
49
71
|
export const shimBootstrapSchema = strictReadonlyObject({
|
|
50
72
|
kind: z.literal(SHIM_FRAME_KIND.bootstrap),
|
|
51
73
|
worker: workerOptionsSchema,
|
|
74
|
+
input: workerInputManifestSchema,
|
|
75
|
+
inputTimeoutMs: durationSchema,
|
|
52
76
|
});
|
|
53
77
|
export const shimAckSchema = strictReadonlyObject({
|
|
54
78
|
kind: z.literal(SHIM_FRAME_KIND.ack),
|
|
@@ -56,6 +80,10 @@ export const shimAckSchema = strictReadonlyObject({
|
|
|
56
80
|
export const shimRunningSchema = strictReadonlyObject({
|
|
57
81
|
kind: z.literal(SHIM_FRAME_KIND.running),
|
|
58
82
|
});
|
|
83
|
+
export const shimLaunchFailedSchema = strictReadonlyObject({
|
|
84
|
+
kind: z.literal(SHIM_FRAME_KIND.launchFailed),
|
|
85
|
+
failure: launchFailureSchema,
|
|
86
|
+
});
|
|
59
87
|
export const workerExitSchema = strictReadonlyObject({
|
|
60
88
|
kind: z.literal(SHIM_FRAME_KIND.workerExit),
|
|
61
89
|
code: z.number().int().nullable(),
|
|
@@ -8,8 +8,13 @@ export declare const SHIM_FRAME_KIND: {
|
|
|
8
8
|
readonly bootstrap: "shim_bootstrap";
|
|
9
9
|
readonly ack: "shim_ack";
|
|
10
10
|
readonly running: "shim_running";
|
|
11
|
+
readonly launchFailed: "shim_launch_failed";
|
|
11
12
|
readonly workerExit: "worker_exit";
|
|
12
13
|
};
|
|
14
|
+
export declare const WORKER_INPUT_KIND: {
|
|
15
|
+
readonly none: "none";
|
|
16
|
+
readonly stream: "stream";
|
|
17
|
+
};
|
|
13
18
|
export declare const SUPERVISOR_REQUEST_KIND: {
|
|
14
19
|
readonly probe: "probe";
|
|
15
20
|
readonly terminate: "terminate";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor-values.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-values.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B;;;;;CAKlC,CAAC;AAEX,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"supervisor-values.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-values.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B;;;;;CAKlC,CAAC;AAEX,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAEX,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,eAAO,MAAM,uBAAuB;;;;CAI1B,CAAC;AAEX,eAAO,MAAM,wBAAwB;;;;CAI3B,CAAC;AAEX,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAC;AAEX,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;;CAGhC,CAAC;AAEX,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC"}
|
|
@@ -8,8 +8,13 @@ export const SHIM_FRAME_KIND = {
|
|
|
8
8
|
bootstrap: "shim_bootstrap",
|
|
9
9
|
ack: "shim_ack",
|
|
10
10
|
running: "shim_running",
|
|
11
|
+
launchFailed: "shim_launch_failed",
|
|
11
12
|
workerExit: "worker_exit",
|
|
12
13
|
};
|
|
14
|
+
export const WORKER_INPUT_KIND = {
|
|
15
|
+
none: "none",
|
|
16
|
+
stream: "stream",
|
|
17
|
+
};
|
|
13
18
|
export const SUPERVISOR_REQUEST_KIND = {
|
|
14
19
|
probe: "probe",
|
|
15
20
|
terminate: "terminate",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const CONTROLLED_PROCESS_PROTOCOL_VERSION: "alpacakit-supervisor-
|
|
1
|
+
export declare const CONTROLLED_PROCESS_PROTOCOL_VERSION: "alpacakit-supervisor-v2";
|
|
2
2
|
export declare const CONTROLLED_PROCESS_PLATFORM: {
|
|
3
3
|
readonly darwin: "darwin";
|
|
4
4
|
readonly linux: "linux";
|
|
@@ -32,8 +32,8 @@ export declare const SUPERVISOR_AUTHENTICATION_REJECTION_REASON: {
|
|
|
32
32
|
readonly replay: "replay";
|
|
33
33
|
};
|
|
34
34
|
export declare const SUPERVISOR_MAC_DOMAIN: {
|
|
35
|
-
readonly record: "alpacakit-supervisor-
|
|
36
|
-
readonly supervisorChallenge: "alpacakit-supervisor-
|
|
37
|
-
readonly clientProof: "alpacakit-supervisor-
|
|
35
|
+
readonly record: "alpacakit-supervisor-v2/record/v1";
|
|
36
|
+
readonly supervisorChallenge: "alpacakit-supervisor-v2/auth/supervisor/v1";
|
|
37
|
+
readonly clientProof: "alpacakit-supervisor-v2/auth/client/v1";
|
|
38
38
|
};
|
|
39
39
|
//# sourceMappingURL=values.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const CONTROLLED_PROCESS_PROTOCOL_VERSION = "alpacakit-supervisor-
|
|
1
|
+
export const CONTROLLED_PROCESS_PROTOCOL_VERSION = "alpacakit-supervisor-v2";
|
|
2
2
|
export const CONTROLLED_PROCESS_PLATFORM = {
|
|
3
3
|
darwin: "darwin",
|
|
4
4
|
linux: "linux",
|
|
@@ -32,7 +32,7 @@ export const SUPERVISOR_AUTHENTICATION_REJECTION_REASON = {
|
|
|
32
32
|
replay: "replay",
|
|
33
33
|
};
|
|
34
34
|
export const SUPERVISOR_MAC_DOMAIN = {
|
|
35
|
-
record: "alpacakit-supervisor-
|
|
36
|
-
supervisorChallenge: "alpacakit-supervisor-
|
|
37
|
-
clientProof: "alpacakit-supervisor-
|
|
35
|
+
record: "alpacakit-supervisor-v2/record/v1",
|
|
36
|
+
supervisorChallenge: "alpacakit-supervisor-v2/auth/supervisor/v1",
|
|
37
|
+
clientProof: "alpacakit-supervisor-v2/auth/client/v1",
|
|
38
38
|
};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { LoginCapability } from "../auth/login.js";
|
|
10
10
|
import type { MaterialHandlers } from "../auth/material.js";
|
|
11
11
|
import type { AgentEvent, RunUsage } from "../core/run.js";
|
|
12
|
+
import { type AgentAvailabilityCapability, type AgentRemediation } from "../host/availability.js";
|
|
12
13
|
import type { DoctorCapability, McpCapability, SkillsCapability } from "../host/capabilities.js";
|
|
13
14
|
import { type FailureMatcher } from "./classify.js";
|
|
14
15
|
import type { AgentDefinition } from "./definition.js";
|
|
@@ -52,6 +53,8 @@ export type CliAgentBlueprint<Id extends string = string> = {
|
|
|
52
53
|
* output would misclassify runs that merely talk about limits.
|
|
53
54
|
*/
|
|
54
55
|
readonly classifyOnSuccess?: readonly FailureMatcher[];
|
|
56
|
+
readonly availability?: AgentAvailabilityCapability;
|
|
57
|
+
readonly commandMissingRemediation?: AgentRemediation | null;
|
|
55
58
|
readonly auth?: MaterialHandlers;
|
|
56
59
|
readonly login?: LoginCapability;
|
|
57
60
|
readonly doctor?: DoctorCapability;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-agent.d.ts","sourceRoot":"","sources":["../../src/kernel/cli-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAoB5D,OAAO,KAAK,EACV,UAAU,EAGV,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAIL,KAAK,cAAc,EAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,iBAAiB,CAAC;AAE7E,O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from "../core/run.js";
|
|
13
13
|
import { OUTPUT_CHANNEL, PROCESS_SIGNAL, } from "../core/values.js";
|
|
14
|
-
import {
|
|
14
|
+
import { cliAvailability, } from "../host/availability.js";
|
|
15
|
+
import { cliCommandDoctor } from "../host/command-doctor.js";
|
|
15
16
|
import { classifyFailure, sharedFailureMatchers, } from "./classify.js";
|
|
16
17
|
import { requireKeyedHandler } from "./keyed.js";
|
|
17
18
|
const SIGKILL_ESCALATION_MS = 5_000;
|
|
@@ -538,27 +539,15 @@ export function defineCliAgent(blueprint) {
|
|
|
538
539
|
detectCompletion: blueprint.detectCompletion?.bind(blueprint) ?? (() => false),
|
|
539
540
|
};
|
|
540
541
|
const matchers = [...(blueprint.classify ?? []), ...sharedFailureMatchers];
|
|
541
|
-
const doctor = blueprint.doctor ??
|
|
542
|
-
{
|
|
543
|
-
probe: async (ctx) => {
|
|
544
|
-
const command = await ctx.exec.which(blueprint.command, ctx.env);
|
|
545
|
-
return {
|
|
546
|
-
available: command !== null,
|
|
547
|
-
checks: [
|
|
548
|
-
{
|
|
549
|
-
id: "command-on-path",
|
|
550
|
-
status: command === null
|
|
551
|
-
? DOCTOR_CHECK_STATUS.fail
|
|
552
|
-
: DOCTOR_CHECK_STATUS.pass,
|
|
553
|
-
detail: command,
|
|
554
|
-
},
|
|
555
|
-
],
|
|
556
|
-
};
|
|
557
|
-
},
|
|
558
|
-
};
|
|
542
|
+
const doctor = blueprint.doctor ?? cliCommandDoctor(blueprint.command);
|
|
559
543
|
const definition = {
|
|
560
544
|
id: blueprint.id,
|
|
561
545
|
run: buildRun(blueprint, hooks, matchers, blueprint.classifyOnSuccess ?? []),
|
|
546
|
+
availability: blueprint.availability ??
|
|
547
|
+
cliAvailability({
|
|
548
|
+
command: blueprint.command,
|
|
549
|
+
commandMissingRemediation: blueprint.commandMissingRemediation ?? null,
|
|
550
|
+
}),
|
|
562
551
|
doctor,
|
|
563
552
|
};
|
|
564
553
|
if (blueprint.auth !== undefined) {
|
|
@@ -8,6 +8,7 @@ import type { LoginCapability } from "../auth/login.js";
|
|
|
8
8
|
import type { AuthCapability } from "../auth/material.js";
|
|
9
9
|
import type { Clock, Exec, HttpClient, Logger } from "../core/ports.js";
|
|
10
10
|
import type { AgentEvent, AgentRunOutcome } from "../core/run.js";
|
|
11
|
+
import type { AgentAvailabilityCapability } from "../host/availability.js";
|
|
11
12
|
import type { DoctorCapability, McpCapability, SkillsCapability } from "../host/capabilities.js";
|
|
12
13
|
import type { ResolvedRunOptions } from "./options.js";
|
|
13
14
|
/** Resolved (rule 2): the adapter's whole world. */
|
|
@@ -27,6 +28,7 @@ export type AgentRun = AsyncGenerator<AgentEvent, AgentRunOutcome, void>;
|
|
|
27
28
|
export interface AgentDefinition<Id extends string = string> {
|
|
28
29
|
id: Id;
|
|
29
30
|
run(options: ResolvedRunOptions, ctx: RunContext): AgentRun;
|
|
31
|
+
availability?: AgentAvailabilityCapability;
|
|
30
32
|
auth?: AuthCapability;
|
|
31
33
|
login?: LoginCapability;
|
|
32
34
|
doctor?: DoctorCapability;
|