@alpacakit/agents 0.1.0-beta.19 → 0.1.0-beta.21
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 +60 -0
- package/dist/agents/claude.d.ts.map +1 -1
- package/dist/agents/claude.js +3 -0
- package/dist/agents/codex.d.ts.map +1 -1
- package/dist/agents/codex.js +4 -0
- package/dist/agents/openai-compatible/config.d.ts.map +1 -1
- package/dist/agents/openai-compatible/config.js +5 -0
- package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -1
- package/dist/agents/openai-compatible/fetch-engine.js +6 -0
- package/dist/agents/openai-compatible/pi/module.d.ts.map +1 -1
- package/dist/agents/openai-compatible/pi/module.js +1 -0
- package/dist/agents/openai-compatible/pi/sandbox.js +2 -0
- package/dist/agents/openai-compatible/response.js +1 -0
- package/dist/auth/profile-store.d.ts.map +1 -1
- package/dist/auth/profile-store.js +1 -0
- package/dist/auth/secrets.d.ts.map +1 -1
- package/dist/auth/secrets.js +2 -0
- package/dist/codex/app-server.js +6 -0
- package/dist/core/controlled-process.d.ts +98 -0
- package/dist/core/controlled-process.d.ts.map +1 -0
- package/dist/core/controlled-process.js +29 -0
- package/dist/core/error.d.ts +25 -0
- package/dist/core/error.d.ts.map +1 -1
- package/dist/core/error.js +32 -0
- package/dist/core/node-controlled-exec.d.ts +3 -0
- package/dist/core/node-controlled-exec.d.ts.map +1 -0
- package/dist/core/node-controlled-exec.js +32 -0
- package/dist/core/node-ports.d.ts +1 -0
- package/dist/core/node-ports.d.ts.map +1 -1
- package/dist/core/node-ports.js +9 -1
- package/dist/core/ports.d.ts +5 -0
- package/dist/core/ports.d.ts.map +1 -1
- package/dist/fleet/fleet.d.ts.map +1 -1
- package/dist/fleet/fleet.js +5 -2
- package/dist/fleet/store.d.ts.map +1 -1
- package/dist/fleet/store.js +3 -0
- package/dist/host/github-dir.d.ts.map +1 -1
- package/dist/host/github-dir.js +5 -0
- package/dist/host/mcp-list.d.ts.map +1 -1
- package/dist/host/mcp-list.js +1 -0
- package/dist/host/run-command.d.ts.map +1 -1
- package/dist/host/run-command.js +2 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/internal/controlled-process/authentication.d.ts +13 -0
- package/dist/internal/controlled-process/authentication.d.ts.map +1 -0
- package/dist/internal/controlled-process/authentication.js +112 -0
- package/dist/internal/controlled-process/child-fd.d.ts +5 -0
- package/dist/internal/controlled-process/child-fd.d.ts.map +1 -0
- package/dist/internal/controlled-process/child-fd.js +47 -0
- package/dist/internal/controlled-process/framed-transport.d.ts +6 -0
- package/dist/internal/controlled-process/framed-transport.d.ts.map +1 -0
- package/dist/internal/controlled-process/framed-transport.js +117 -0
- package/dist/internal/controlled-process/host-controller.d.ts +23 -0
- package/dist/internal/controlled-process/host-controller.d.ts.map +1 -0
- package/dist/internal/controlled-process/host-controller.js +908 -0
- package/dist/internal/controlled-process/lifecycle.d.ts +5 -0
- package/dist/internal/controlled-process/lifecycle.d.ts.map +1 -0
- package/dist/internal/controlled-process/lifecycle.js +22 -0
- package/dist/internal/controlled-process/model.d.ts +99 -0
- package/dist/internal/controlled-process/model.d.ts.map +1 -0
- package/dist/internal/controlled-process/model.js +1 -0
- package/dist/internal/controlled-process/record-store.d.ts +17 -0
- package/dist/internal/controlled-process/record-store.d.ts.map +1 -0
- package/dist/internal/controlled-process/record-store.js +170 -0
- package/dist/internal/controlled-process/record.d.ts +12 -0
- package/dist/internal/controlled-process/record.d.ts.map +1 -0
- package/dist/internal/controlled-process/record.js +87 -0
- package/dist/internal/controlled-process/schema.d.ts +133 -0
- package/dist/internal/controlled-process/schema.d.ts.map +1 -0
- package/dist/internal/controlled-process/schema.js +99 -0
- package/dist/internal/controlled-process/shim-entry.d.ts +2 -0
- package/dist/internal/controlled-process/shim-entry.d.ts.map +1 -0
- package/dist/internal/controlled-process/shim-entry.js +2 -0
- package/dist/internal/controlled-process/shim-runtime.d.ts +2 -0
- package/dist/internal/controlled-process/shim-runtime.d.ts.map +1 -0
- package/dist/internal/controlled-process/shim-runtime.js +57 -0
- package/dist/internal/controlled-process/supervisor-coordinator.d.ts +67 -0
- package/dist/internal/controlled-process/supervisor-coordinator.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-coordinator.js +325 -0
- package/dist/internal/controlled-process/supervisor-entry.d.ts +2 -0
- package/dist/internal/controlled-process/supervisor-entry.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-entry.js +2 -0
- package/dist/internal/controlled-process/supervisor-model.d.ts +92 -0
- package/dist/internal/controlled-process/supervisor-model.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-model.js +1 -0
- package/dist/internal/controlled-process/supervisor-platform.d.ts +16 -0
- package/dist/internal/controlled-process/supervisor-platform.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-platform.js +104 -0
- package/dist/internal/controlled-process/supervisor-runtime.d.ts +11 -0
- package/dist/internal/controlled-process/supervisor-runtime.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-runtime.js +773 -0
- package/dist/internal/controlled-process/supervisor-schema.d.ts +100 -0
- package/dist/internal/controlled-process/supervisor-schema.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-schema.js +73 -0
- package/dist/internal/controlled-process/supervisor-transport.d.ts +46 -0
- package/dist/internal/controlled-process/supervisor-transport.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-transport.js +368 -0
- package/dist/internal/controlled-process/supervisor-values.d.ts +39 -0
- package/dist/internal/controlled-process/supervisor-values.d.ts.map +1 -0
- package/dist/internal/controlled-process/supervisor-values.js +38 -0
- package/dist/internal/controlled-process/token.d.ts +4 -0
- package/dist/internal/controlled-process/token.d.ts.map +1 -0
- package/dist/internal/controlled-process/token.js +38 -0
- package/dist/internal/controlled-process/values.d.ts +39 -0
- package/dist/internal/controlled-process/values.d.ts.map +1 -0
- package/dist/internal/controlled-process/values.js +38 -0
- package/dist/kernel/cli-agent.d.ts.map +1 -1
- package/dist/kernel/cli-agent.js +330 -34
- package/dist/kernel/cli-login.d.ts.map +1 -1
- package/dist/kernel/cli-login.js +5 -0
- package/dist/kernel/env-template.js +1 -0
- package/dist/kernel/facets.d.ts.map +1 -1
- package/dist/kernel/facets.js +1 -0
- package/dist/kernel/keyed.d.ts.map +1 -1
- package/dist/kernel/keyed.js +1 -0
- package/dist/kernel/login.js +2 -0
- package/dist/kernel/options.d.ts +14 -0
- package/dist/kernel/options.d.ts.map +1 -1
- package/dist/kernel/options.js +3 -0
- package/dist/kernel/process-lifecycle-failure.d.ts +5 -0
- package/dist/kernel/process-lifecycle-failure.d.ts.map +1 -0
- package/dist/kernel/process-lifecycle-failure.js +5 -0
- package/dist/kernel/run.d.ts.map +1 -1
- package/dist/kernel/run.js +11 -0
- package/dist/kernel/runtime.d.ts.map +1 -1
- package/dist/kernel/runtime.js +2 -0
- package/dist/keyring/resolver.d.ts.map +1 -1
- package/dist/keyring/resolver.js +2 -0
- package/dist/structured/run-structured.js +1 -0
- package/dist/testing/fake-controlled-exec.d.ts +21 -0
- package/dist/testing/fake-controlled-exec.d.ts.map +1 -0
- package/dist/testing/fake-controlled-exec.js +172 -0
- package/dist/testing/fake-exec.d.ts.map +1 -1
- package/dist/testing/fake-exec.js +64 -54
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { strictReadonlyObject, stringValueMapSchema } from "@alpacakit/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { CHILD_PROCESS_ABSENCE_PROOF, CHILD_PROCESS_TERMINATION_KIND, CHILD_PROCESS_TERMINATION_PHASE, CHILD_PROCESS_UNKILLABLE_REASON, } from "../../core/controlled-process.js";
|
|
4
|
+
import { CONTROLLED_PROCESS_PLATFORM, CONTROLLED_PROCESS_PROTOCOL_VERSION, CONTROLLED_PROCESS_STATE, SUPERVISOR_AUTHENTICATION_FRAME_KIND, } from "./values.js";
|
|
5
|
+
const LOWER_HEX_16_BYTE_PATTERN = /^[0-9a-f]{32}$/u;
|
|
6
|
+
const LOWER_HEX_32_BYTE_PATTERN = /^[0-9a-f]{64}$/u;
|
|
7
|
+
const PROCESS_START_TOKEN_PATTERN = /^alpacakit-supervisor-v1:(?:darwin|linux):[0-9a-f]{32}:[0-9a-f]{32}:[0-9a-f]{32}:[0-9a-f]{32}:[0-9a-f]{64}$/u;
|
|
8
|
+
const lowerHex16ByteSchema = z.string().regex(LOWER_HEX_16_BYTE_PATTERN);
|
|
9
|
+
export const lowerHex32ByteSchema = z.string().regex(LOWER_HEX_32_BYTE_PATTERN);
|
|
10
|
+
export const controlledProcessPlatformSchema = stringValueMapSchema(CONTROLLED_PROCESS_PLATFORM);
|
|
11
|
+
export const controlledProcessStateSchema = stringValueMapSchema(CONTROLLED_PROCESS_STATE);
|
|
12
|
+
export const supervisorBootIdSchema = lowerHex16ByteSchema.transform((value) => value);
|
|
13
|
+
export const supervisorInstanceIdSchema = lowerHex16ByteSchema.transform((value) => value);
|
|
14
|
+
export const controlledProcessRecordIdSchema = lowerHex16ByteSchema.transform((value) => value);
|
|
15
|
+
export const supervisorSocketLocatorSchema = lowerHex16ByteSchema.transform((value) => value);
|
|
16
|
+
export const supervisorCapabilitySchema = lowerHex32ByteSchema.transform((value) => value);
|
|
17
|
+
export const controlledProcessRecordMacSchema = lowerHex32ByteSchema.transform((value) => value);
|
|
18
|
+
export const supervisorAuthenticationMacSchema = lowerHex32ByteSchema.transform((value) => value);
|
|
19
|
+
export const supervisorClientNonceSchema = lowerHex32ByteSchema.transform((value) => value);
|
|
20
|
+
export const supervisorServerNonceSchema = lowerHex32ByteSchema.transform((value) => value);
|
|
21
|
+
export const shimProcessIdSchema = z
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.positive()
|
|
25
|
+
.max(Number.MAX_SAFE_INTEGER)
|
|
26
|
+
.transform((value) => value);
|
|
27
|
+
export const processStartTokenSchema = z
|
|
28
|
+
.string()
|
|
29
|
+
.regex(PROCESS_START_TOKEN_PATTERN)
|
|
30
|
+
.transform((value) => value);
|
|
31
|
+
export const controlledProcessIdentitySchema = strictReadonlyObject({
|
|
32
|
+
pid: shimProcessIdSchema,
|
|
33
|
+
processStartToken: processStartTokenSchema,
|
|
34
|
+
});
|
|
35
|
+
const controlledProcessRecordShape = strictReadonlyObject({
|
|
36
|
+
protocolVersion: z.literal(CONTROLLED_PROCESS_PROTOCOL_VERSION),
|
|
37
|
+
platform: controlledProcessPlatformSchema,
|
|
38
|
+
bootId: supervisorBootIdSchema,
|
|
39
|
+
supervisorInstanceId: supervisorInstanceIdSchema,
|
|
40
|
+
recordId: controlledProcessRecordIdSchema,
|
|
41
|
+
socketLocator: supervisorSocketLocatorSchema,
|
|
42
|
+
pid: shimProcessIdSchema,
|
|
43
|
+
state: controlledProcessStateSchema,
|
|
44
|
+
absenceProof: z
|
|
45
|
+
.enum([
|
|
46
|
+
CHILD_PROCESS_ABSENCE_PROOF.supervisorProbe,
|
|
47
|
+
CHILD_PROCESS_ABSENCE_PROOF.bootChanged,
|
|
48
|
+
])
|
|
49
|
+
.nullable(),
|
|
50
|
+
});
|
|
51
|
+
export const controlledProcessRecordSchema = controlledProcessRecordShape.superRefine((record, context) => {
|
|
52
|
+
const terminal = record.state === CONTROLLED_PROCESS_STATE.absent ||
|
|
53
|
+
record.state === CONTROLLED_PROCESS_STATE.released;
|
|
54
|
+
if (terminal === (record.absenceProof === null)) {
|
|
55
|
+
context.addIssue({
|
|
56
|
+
code: "custom",
|
|
57
|
+
message: "Controlled process absence proof does not match state.",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export const signedControlledProcessRecordSchema = strictReadonlyObject({
|
|
62
|
+
record: controlledProcessRecordSchema,
|
|
63
|
+
recordMac: controlledProcessRecordMacSchema,
|
|
64
|
+
});
|
|
65
|
+
export const supervisorClientChallengeSchema = strictReadonlyObject({
|
|
66
|
+
kind: z.literal(SUPERVISOR_AUTHENTICATION_FRAME_KIND.clientChallenge),
|
|
67
|
+
recordId: controlledProcessRecordIdSchema,
|
|
68
|
+
clientNonce: supervisorClientNonceSchema,
|
|
69
|
+
});
|
|
70
|
+
export const supervisorChallengeSchema = strictReadonlyObject({
|
|
71
|
+
kind: z.literal(SUPERVISOR_AUTHENTICATION_FRAME_KIND.supervisorChallenge),
|
|
72
|
+
recordId: controlledProcessRecordIdSchema,
|
|
73
|
+
clientNonce: supervisorClientNonceSchema,
|
|
74
|
+
serverNonce: supervisorServerNonceSchema,
|
|
75
|
+
supervisorMac: supervisorAuthenticationMacSchema,
|
|
76
|
+
});
|
|
77
|
+
export const supervisorClientProofSchema = strictReadonlyObject({
|
|
78
|
+
kind: z.literal(SUPERVISOR_AUTHENTICATION_FRAME_KIND.clientProof),
|
|
79
|
+
recordId: controlledProcessRecordIdSchema,
|
|
80
|
+
clientNonce: supervisorClientNonceSchema,
|
|
81
|
+
serverNonce: supervisorServerNonceSchema,
|
|
82
|
+
supervisorMac: supervisorAuthenticationMacSchema,
|
|
83
|
+
clientMac: supervisorAuthenticationMacSchema,
|
|
84
|
+
});
|
|
85
|
+
export const childProcessTerminationResultSchema = z.discriminatedUnion("kind", [
|
|
86
|
+
strictReadonlyObject({
|
|
87
|
+
kind: z.literal(CHILD_PROCESS_TERMINATION_KIND.absent),
|
|
88
|
+
proof: stringValueMapSchema(CHILD_PROCESS_ABSENCE_PROOF),
|
|
89
|
+
}),
|
|
90
|
+
strictReadonlyObject({
|
|
91
|
+
kind: z.literal(CHILD_PROCESS_TERMINATION_KIND.pending),
|
|
92
|
+
phase: stringValueMapSchema(CHILD_PROCESS_TERMINATION_PHASE),
|
|
93
|
+
retryAfterMs: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
94
|
+
}),
|
|
95
|
+
strictReadonlyObject({
|
|
96
|
+
kind: z.literal(CHILD_PROCESS_TERMINATION_KIND.unkillable),
|
|
97
|
+
reason: stringValueMapSchema(CHILD_PROCESS_UNKILLABLE_REASON),
|
|
98
|
+
}),
|
|
99
|
+
]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shim-entry.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/shim-entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shim-runtime.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/shim-runtime.ts"],"names":[],"mappings":"AAeA,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAgC9D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { readFramedRecords, readRequiredFrame, writeFramedRecord, } from "./framed-transport.js";
|
|
3
|
+
import { readableFd, writableFd } from "./child-fd.js";
|
|
4
|
+
import { shimAckSchema, shimBootstrapSchema } from "./supervisor-schema.js";
|
|
5
|
+
import { SHIM_FRAME_KIND } from "./supervisor-values.js";
|
|
6
|
+
const SHIM_CONTROL_FD = 3;
|
|
7
|
+
const SHIM_STATUS_FD = 4;
|
|
8
|
+
const SPAWN_FAILURE_EXIT_CODE = 127;
|
|
9
|
+
const KEEPALIVE_INTERVAL_MS = 60_000;
|
|
10
|
+
export async function runControlledProcessShim() {
|
|
11
|
+
const control = readableFd(SHIM_CONTROL_FD);
|
|
12
|
+
const status = writableFd(SHIM_STATUS_FD);
|
|
13
|
+
const frames = readFramedRecords(control)[Symbol.asyncIterator]();
|
|
14
|
+
const bootstrap = shimBootstrapSchema.parse(await readRequiredFrame(frames));
|
|
15
|
+
try {
|
|
16
|
+
shimAckSchema.parse(await readRequiredFrame(frames));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
process.on("SIGTERM", () => { });
|
|
22
|
+
const worker = spawn(bootstrap.worker.command, [...bootstrap.worker.args], {
|
|
23
|
+
cwd: bootstrap.worker.cwd,
|
|
24
|
+
env: bootstrap.worker.env,
|
|
25
|
+
detached: false,
|
|
26
|
+
shell: false,
|
|
27
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
28
|
+
});
|
|
29
|
+
const workerExit = waitForWorkerExit(worker);
|
|
30
|
+
worker.stdin.on("error", () => { });
|
|
31
|
+
if (bootstrap.worker.stdin !== null) {
|
|
32
|
+
worker.stdin.write(bootstrap.worker.stdin);
|
|
33
|
+
}
|
|
34
|
+
worker.stdin.end();
|
|
35
|
+
await writeFramedRecord(status, { kind: SHIM_FRAME_KIND.running });
|
|
36
|
+
const exit = await workerExit;
|
|
37
|
+
await writeFramedRecord(status, {
|
|
38
|
+
kind: SHIM_FRAME_KIND.workerExit,
|
|
39
|
+
code: exit.code,
|
|
40
|
+
signal: exit.signal,
|
|
41
|
+
});
|
|
42
|
+
setInterval(() => { }, KEEPALIVE_INTERVAL_MS);
|
|
43
|
+
}
|
|
44
|
+
function waitForWorkerExit(worker) {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
let spawnFailed = false;
|
|
47
|
+
worker.once("error", () => {
|
|
48
|
+
spawnFailed = true;
|
|
49
|
+
});
|
|
50
|
+
worker.once("close", (code, signal) => {
|
|
51
|
+
resolve({
|
|
52
|
+
code: spawnFailed ? SPAWN_FAILURE_EXIT_CODE : code,
|
|
53
|
+
signal,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ChildProcessTerminationResult } from "../../core/controlled-process.js";
|
|
2
|
+
import type { ExecExit } from "../../core/ports.js";
|
|
3
|
+
import type { ControlledProcessRecord, SignedControlledProcessRecord, SupervisorCapability } from "./model.js";
|
|
4
|
+
import type { SupervisorPlatformAdapter } from "./supervisor-platform.js";
|
|
5
|
+
import type { SupervisorTimingOptions } from "./supervisor-model.js";
|
|
6
|
+
export interface SupervisorRecordWriter {
|
|
7
|
+
write(record: SignedControlledProcessRecord): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class SupervisorCoordinator {
|
|
10
|
+
private record;
|
|
11
|
+
private readonly capability;
|
|
12
|
+
private readonly store;
|
|
13
|
+
private readonly platform;
|
|
14
|
+
private readonly timing;
|
|
15
|
+
private serial;
|
|
16
|
+
private outputClosed;
|
|
17
|
+
private shimExited;
|
|
18
|
+
private shimClosed;
|
|
19
|
+
private preAckAborted;
|
|
20
|
+
private groupAbsentObserved;
|
|
21
|
+
private absencePersistenceFailed;
|
|
22
|
+
private terminationRequested;
|
|
23
|
+
private sigkillSentHere;
|
|
24
|
+
private termDeadline;
|
|
25
|
+
private killDeadline;
|
|
26
|
+
private unkillableReason;
|
|
27
|
+
private workerExit;
|
|
28
|
+
private duplicateWorkerExit;
|
|
29
|
+
constructor(input: {
|
|
30
|
+
readonly record: ControlledProcessRecord;
|
|
31
|
+
readonly capability: SupervisorCapability;
|
|
32
|
+
readonly store: SupervisorRecordWriter;
|
|
33
|
+
readonly platform: SupervisorPlatformAdapter;
|
|
34
|
+
readonly timing: SupervisorTimingOptions;
|
|
35
|
+
readonly now: () => number;
|
|
36
|
+
readonly onAbsent: () => void;
|
|
37
|
+
readonly onReleased: () => void;
|
|
38
|
+
});
|
|
39
|
+
private readonly onAbsent;
|
|
40
|
+
private readonly onReleased;
|
|
41
|
+
private readonly now;
|
|
42
|
+
persistInitial(): Promise<void>;
|
|
43
|
+
acknowledge(): Promise<void>;
|
|
44
|
+
running(): Promise<void>;
|
|
45
|
+
recordWorkerExit(workerExit: ExecExit): Promise<void>;
|
|
46
|
+
recordShimExit(): Promise<void>;
|
|
47
|
+
recordShimClosed(): Promise<void>;
|
|
48
|
+
recordOutputClosed(): Promise<void>;
|
|
49
|
+
abortBeforeAck(): Promise<void>;
|
|
50
|
+
recordProtocolFailure(): Promise<void>;
|
|
51
|
+
tick(): Promise<void>;
|
|
52
|
+
terminate(): Promise<ChildProcessTerminationResult>;
|
|
53
|
+
probe(): Promise<ChildProcessTerminationResult>;
|
|
54
|
+
workerExitEvidence(): ExecExit | null;
|
|
55
|
+
release(): Promise<boolean>;
|
|
56
|
+
private beginTermination;
|
|
57
|
+
private converge;
|
|
58
|
+
private sendSigkillOnce;
|
|
59
|
+
private finishAbsenceWhenOutputCloses;
|
|
60
|
+
private observeGroupAbsence;
|
|
61
|
+
private result;
|
|
62
|
+
private transition;
|
|
63
|
+
private persist;
|
|
64
|
+
private enqueue;
|
|
65
|
+
private enqueueResult;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=supervisor-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-coordinator.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-coordinator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { CHILD_PROCESS_ABSENCE_PROOF, CHILD_PROCESS_TERMINATION_KIND, CHILD_PROCESS_TERMINATION_PHASE, CHILD_PROCESS_UNKILLABLE_REASON, } from "../../core/controlled-process.js";
|
|
2
|
+
import { signControlledProcessRecord } from "./record.js";
|
|
3
|
+
import { PROCESS_PROBE_KIND, PROCESS_SIGNAL_RESULT_KIND, } from "./supervisor-values.js";
|
|
4
|
+
import { transitionControlledProcess } from "./lifecycle.js";
|
|
5
|
+
import { CONTROLLED_PROCESS_PLATFORM, CONTROLLED_PROCESS_STATE, } from "./values.js";
|
|
6
|
+
export class SupervisorCoordinator {
|
|
7
|
+
record;
|
|
8
|
+
capability;
|
|
9
|
+
store;
|
|
10
|
+
platform;
|
|
11
|
+
timing;
|
|
12
|
+
serial = Promise.resolve();
|
|
13
|
+
outputClosed = false;
|
|
14
|
+
shimExited = false;
|
|
15
|
+
shimClosed = false;
|
|
16
|
+
preAckAborted = false;
|
|
17
|
+
groupAbsentObserved = false;
|
|
18
|
+
absencePersistenceFailed = false;
|
|
19
|
+
terminationRequested = false;
|
|
20
|
+
sigkillSentHere = false;
|
|
21
|
+
termDeadline = 0;
|
|
22
|
+
killDeadline = 0;
|
|
23
|
+
unkillableReason = null;
|
|
24
|
+
workerExit = null;
|
|
25
|
+
duplicateWorkerExit = false;
|
|
26
|
+
constructor(input) {
|
|
27
|
+
this.record = input.record;
|
|
28
|
+
this.capability = input.capability;
|
|
29
|
+
this.store = input.store;
|
|
30
|
+
this.platform = input.platform;
|
|
31
|
+
this.timing = input.timing;
|
|
32
|
+
this.now = input.now;
|
|
33
|
+
this.onAbsent = input.onAbsent;
|
|
34
|
+
this.onReleased = input.onReleased;
|
|
35
|
+
}
|
|
36
|
+
onAbsent;
|
|
37
|
+
onReleased;
|
|
38
|
+
now;
|
|
39
|
+
persistInitial() {
|
|
40
|
+
return this.enqueue(async () => this.persist());
|
|
41
|
+
}
|
|
42
|
+
acknowledge() {
|
|
43
|
+
return this.enqueue(async () => {
|
|
44
|
+
await this.transition(CONTROLLED_PROCESS_STATE.acked);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
running() {
|
|
48
|
+
return this.enqueue(async () => {
|
|
49
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.acked) {
|
|
50
|
+
await this.transition(CONTROLLED_PROCESS_STATE.running);
|
|
51
|
+
if (this.terminationRequested &&
|
|
52
|
+
!this.groupAbsentObserved &&
|
|
53
|
+
this.unkillableReason === null) {
|
|
54
|
+
await this.beginTermination();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
recordWorkerExit(workerExit) {
|
|
60
|
+
return this.enqueue(async () => {
|
|
61
|
+
if (this.workerExit !== null) {
|
|
62
|
+
this.duplicateWorkerExit = true;
|
|
63
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.workerExit = workerExit;
|
|
67
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.running &&
|
|
68
|
+
!this.groupAbsentObserved &&
|
|
69
|
+
this.unkillableReason === null) {
|
|
70
|
+
await this.beginTermination();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
recordShimExit() {
|
|
75
|
+
return this.enqueue(async () => {
|
|
76
|
+
this.shimExited = true;
|
|
77
|
+
await this.converge();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
recordShimClosed() {
|
|
81
|
+
return this.enqueue(async () => {
|
|
82
|
+
this.shimClosed = true;
|
|
83
|
+
await this.converge();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
recordOutputClosed() {
|
|
87
|
+
return this.enqueue(async () => {
|
|
88
|
+
this.outputClosed = true;
|
|
89
|
+
await this.converge();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
abortBeforeAck() {
|
|
93
|
+
return this.enqueue(async () => {
|
|
94
|
+
this.preAckAborted = true;
|
|
95
|
+
await this.converge();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
recordProtocolFailure() {
|
|
99
|
+
return this.enqueue(async () => {
|
|
100
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
tick() {
|
|
104
|
+
return this.enqueue(async () => this.converge());
|
|
105
|
+
}
|
|
106
|
+
terminate() {
|
|
107
|
+
return this.enqueueResult(async () => {
|
|
108
|
+
this.terminationRequested = true;
|
|
109
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.running &&
|
|
110
|
+
!this.groupAbsentObserved &&
|
|
111
|
+
this.unkillableReason === null) {
|
|
112
|
+
await this.beginTermination();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
await this.converge();
|
|
116
|
+
}
|
|
117
|
+
return this.result();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
probe() {
|
|
121
|
+
return this.enqueueResult(async () => {
|
|
122
|
+
await this.converge();
|
|
123
|
+
return this.result();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
workerExitEvidence() {
|
|
127
|
+
return this.workerExit;
|
|
128
|
+
}
|
|
129
|
+
release() {
|
|
130
|
+
return this.enqueueResult(async () => {
|
|
131
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.released) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
if (this.record.state !== CONTROLLED_PROCESS_STATE.absent) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
await this.transition(CONTROLLED_PROCESS_STATE.released);
|
|
138
|
+
this.onReleased();
|
|
139
|
+
return true;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async beginTermination() {
|
|
143
|
+
await this.transition(CONTROLLED_PROCESS_STATE.term);
|
|
144
|
+
this.termDeadline = this.now() + this.timing.termGraceMs;
|
|
145
|
+
const signal = this.platform.signalGroup(this.record.pid, "SIGTERM");
|
|
146
|
+
if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.absent) {
|
|
147
|
+
await this.observeGroupAbsence();
|
|
148
|
+
}
|
|
149
|
+
else if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.denied) {
|
|
150
|
+
this.unkillableReason =
|
|
151
|
+
CHILD_PROCESS_UNKILLABLE_REASON.probePermissionDenied;
|
|
152
|
+
}
|
|
153
|
+
else if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.failed) {
|
|
154
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async converge() {
|
|
158
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.absent ||
|
|
159
|
+
this.record.state === CONTROLLED_PROCESS_STATE.released) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (this.groupAbsentObserved) {
|
|
163
|
+
await this.finishAbsenceWhenOutputCloses();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const probe = this.platform.probeGroup(this.record.pid);
|
|
167
|
+
if (probe.kind === PROCESS_PROBE_KIND.denied) {
|
|
168
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.killSent &&
|
|
169
|
+
this.record.platform === CONTROLLED_PROCESS_PLATFORM.darwin &&
|
|
170
|
+
this.sigkillSentHere &&
|
|
171
|
+
this.now() < this.killDeadline) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (this.preAckAborted && !this.shimClosed) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.unkillableReason =
|
|
178
|
+
CHILD_PROCESS_UNKILLABLE_REASON.probePermissionDenied;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (probe.kind === PROCESS_PROBE_KIND.failed) {
|
|
182
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (probe.kind === PROCESS_PROBE_KIND.absent) {
|
|
186
|
+
await this.observeGroupAbsence();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (this.unkillableReason !== null) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (this.shimExited &&
|
|
193
|
+
this.record.state !== CONTROLLED_PROCESS_STATE.killSent &&
|
|
194
|
+
!(this.preAckAborted && !this.shimClosed)) {
|
|
195
|
+
this.unkillableReason =
|
|
196
|
+
CHILD_PROCESS_UNKILLABLE_REASON.shimLostWithLiveGroup;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this.preAckAborted &&
|
|
200
|
+
(this.record.state === CONTROLLED_PROCESS_STATE.reserved ||
|
|
201
|
+
this.record.state === CONTROLLED_PROCESS_STATE.acked)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.term &&
|
|
205
|
+
this.now() >= this.termDeadline) {
|
|
206
|
+
await this.sendSigkillOnce();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.killSent &&
|
|
210
|
+
this.now() >= this.killDeadline) {
|
|
211
|
+
this.unkillableReason =
|
|
212
|
+
CHILD_PROCESS_UNKILLABLE_REASON.groupSurvivedSigkill;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async sendSigkillOnce() {
|
|
216
|
+
await this.transition(CONTROLLED_PROCESS_STATE.killSent);
|
|
217
|
+
this.killDeadline = this.now() + this.timing.killProbeTimeoutMs;
|
|
218
|
+
const signal = this.platform.signalGroup(this.record.pid, "SIGKILL");
|
|
219
|
+
if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.sent) {
|
|
220
|
+
this.sigkillSentHere = true;
|
|
221
|
+
}
|
|
222
|
+
else if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.absent) {
|
|
223
|
+
await this.observeGroupAbsence();
|
|
224
|
+
}
|
|
225
|
+
else if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.denied) {
|
|
226
|
+
this.unkillableReason =
|
|
227
|
+
CHILD_PROCESS_UNKILLABLE_REASON.probePermissionDenied;
|
|
228
|
+
}
|
|
229
|
+
else if (signal.kind === PROCESS_SIGNAL_RESULT_KIND.failed) {
|
|
230
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async finishAbsenceWhenOutputCloses() {
|
|
234
|
+
if (!this.outputClosed || this.absencePersistenceFailed) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
await this.transition(CONTROLLED_PROCESS_STATE.absent);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
this.absencePersistenceFailed = true;
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
if (!this.duplicateWorkerExit) {
|
|
245
|
+
this.unkillableReason = null;
|
|
246
|
+
}
|
|
247
|
+
this.onAbsent();
|
|
248
|
+
}
|
|
249
|
+
async observeGroupAbsence() {
|
|
250
|
+
this.groupAbsentObserved = true;
|
|
251
|
+
await this.finishAbsenceWhenOutputCloses();
|
|
252
|
+
}
|
|
253
|
+
result() {
|
|
254
|
+
if (this.unkillableReason !== null) {
|
|
255
|
+
return {
|
|
256
|
+
kind: CHILD_PROCESS_TERMINATION_KIND.unkillable,
|
|
257
|
+
reason: this.unkillableReason,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.released) {
|
|
261
|
+
return {
|
|
262
|
+
kind: CHILD_PROCESS_TERMINATION_KIND.absent,
|
|
263
|
+
proof: CHILD_PROCESS_ABSENCE_PROOF.releasedReceipt,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (this.record.state === CONTROLLED_PROCESS_STATE.absent) {
|
|
267
|
+
if (this.record.absenceProof === null) {
|
|
268
|
+
return {
|
|
269
|
+
kind: CHILD_PROCESS_TERMINATION_KIND.unkillable,
|
|
270
|
+
reason: CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
kind: CHILD_PROCESS_TERMINATION_KIND.absent,
|
|
275
|
+
proof: this.record.absenceProof,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const killPhase = this.record.state === CONTROLLED_PROCESS_STATE.killSent;
|
|
279
|
+
const termPhase = this.record.state === CONTROLLED_PROCESS_STATE.term;
|
|
280
|
+
const deadline = killPhase
|
|
281
|
+
? this.killDeadline
|
|
282
|
+
: termPhase
|
|
283
|
+
? this.termDeadline
|
|
284
|
+
: this.now() + this.timing.probeIntervalMs;
|
|
285
|
+
return {
|
|
286
|
+
kind: CHILD_PROCESS_TERMINATION_KIND.pending,
|
|
287
|
+
phase: killPhase
|
|
288
|
+
? CHILD_PROCESS_TERMINATION_PHASE.killProbe
|
|
289
|
+
: CHILD_PROCESS_TERMINATION_PHASE.termGrace,
|
|
290
|
+
retryAfterMs: Math.max(1, deadline - this.now()),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async transition(next) {
|
|
294
|
+
const transitioned = {
|
|
295
|
+
...this.record,
|
|
296
|
+
state: transitionControlledProcess(this.record.state, next),
|
|
297
|
+
absenceProof: next === CONTROLLED_PROCESS_STATE.absent
|
|
298
|
+
? CHILD_PROCESS_ABSENCE_PROOF.supervisorProbe
|
|
299
|
+
: next === CONTROLLED_PROCESS_STATE.released
|
|
300
|
+
? this.record.absenceProof
|
|
301
|
+
: null,
|
|
302
|
+
};
|
|
303
|
+
try {
|
|
304
|
+
await this.store.write(signControlledProcessRecord(transitioned, this.capability));
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
this.unkillableReason = CHILD_PROCESS_UNKILLABLE_REASON.protocolFailure;
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
this.record = transitioned;
|
|
311
|
+
}
|
|
312
|
+
persist() {
|
|
313
|
+
return this.store.write(signControlledProcessRecord(this.record, this.capability));
|
|
314
|
+
}
|
|
315
|
+
enqueue(operation) {
|
|
316
|
+
const result = this.serial.then(operation, operation);
|
|
317
|
+
this.serial = result.catch(() => undefined);
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
enqueueResult(operation) {
|
|
321
|
+
const result = this.serial.then(operation, operation);
|
|
322
|
+
this.serial = result.then(() => undefined, () => undefined);
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-entry.d.ts","sourceRoot":"","sources":["../../../src/internal/controlled-process/supervisor-entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ValueOf } from "@alpacakit/core";
|
|
2
|
+
import type { ChildProcessIdentity, ChildProcessTerminationResult } from "../../core/controlled-process.js";
|
|
3
|
+
import type { ExecExit } from "../../core/ports.js";
|
|
4
|
+
import type { OUTPUT_CHANNEL_KIND, PROCESS_PROBE_KIND, PROCESS_SIGNAL_RESULT_KIND, SHIM_FRAME_KIND, SUPERVISOR_BOOTSTRAP_FRAME_KIND, SUPERVISOR_REQUEST_KIND, SUPERVISOR_RESPONSE_KIND } from "./supervisor-values.js";
|
|
5
|
+
export type SupervisorWorkerOptions = {
|
|
6
|
+
readonly command: string;
|
|
7
|
+
readonly args: readonly string[];
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly env: {
|
|
10
|
+
readonly [key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
readonly stdin: string | null;
|
|
13
|
+
};
|
|
14
|
+
export type SupervisorTimingOptions = {
|
|
15
|
+
readonly termGraceMs: number;
|
|
16
|
+
readonly killProbeTimeoutMs: number;
|
|
17
|
+
readonly probeIntervalMs: number;
|
|
18
|
+
};
|
|
19
|
+
export type SupervisorBootstrap = {
|
|
20
|
+
readonly kind: typeof SUPERVISOR_BOOTSTRAP_FRAME_KIND.bootstrap;
|
|
21
|
+
readonly runtimeDirectory: string;
|
|
22
|
+
readonly shimEntryPath: string;
|
|
23
|
+
readonly worker: SupervisorWorkerOptions;
|
|
24
|
+
readonly timing: SupervisorTimingOptions;
|
|
25
|
+
};
|
|
26
|
+
export type SupervisorHostAck = {
|
|
27
|
+
readonly kind: typeof SUPERVISOR_BOOTSTRAP_FRAME_KIND.hostAck;
|
|
28
|
+
};
|
|
29
|
+
export type SupervisorIdentityFrame = {
|
|
30
|
+
readonly kind: typeof SUPERVISOR_BOOTSTRAP_FRAME_KIND.identity;
|
|
31
|
+
readonly identity: ChildProcessIdentity;
|
|
32
|
+
};
|
|
33
|
+
export type SupervisorLaunchFailedFrame = {
|
|
34
|
+
readonly kind: typeof SUPERVISOR_BOOTSTRAP_FRAME_KIND.launchFailed;
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
};
|
|
37
|
+
export type ShimBootstrap = {
|
|
38
|
+
readonly kind: typeof SHIM_FRAME_KIND.bootstrap;
|
|
39
|
+
readonly worker: SupervisorWorkerOptions;
|
|
40
|
+
};
|
|
41
|
+
export type ShimAck = {
|
|
42
|
+
readonly kind: typeof SHIM_FRAME_KIND.ack;
|
|
43
|
+
};
|
|
44
|
+
export type ShimRunning = {
|
|
45
|
+
readonly kind: typeof SHIM_FRAME_KIND.running;
|
|
46
|
+
};
|
|
47
|
+
export type WorkerExit = {
|
|
48
|
+
readonly kind: typeof SHIM_FRAME_KIND.workerExit;
|
|
49
|
+
readonly code: number | null;
|
|
50
|
+
readonly signal: string | null;
|
|
51
|
+
};
|
|
52
|
+
export type SupervisorRequest = {
|
|
53
|
+
readonly kind: typeof SUPERVISOR_REQUEST_KIND.probe;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: typeof SUPERVISOR_REQUEST_KIND.terminate;
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: typeof SUPERVISOR_REQUEST_KIND.release;
|
|
58
|
+
};
|
|
59
|
+
export type SupervisorResponse = {
|
|
60
|
+
readonly kind: typeof SUPERVISOR_RESPONSE_KIND.termination;
|
|
61
|
+
readonly result: ChildProcessTerminationResult;
|
|
62
|
+
readonly workerExit: ExecExit | null;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: typeof SUPERVISOR_RESPONSE_KIND.released;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: typeof SUPERVISOR_RESPONSE_KIND.releaseBeforeAbsent;
|
|
67
|
+
};
|
|
68
|
+
export type ProcessProbe = {
|
|
69
|
+
readonly kind: typeof PROCESS_PROBE_KIND.alive;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: typeof PROCESS_PROBE_KIND.absent;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: typeof PROCESS_PROBE_KIND.denied;
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: typeof PROCESS_PROBE_KIND.failed;
|
|
76
|
+
readonly code: string;
|
|
77
|
+
};
|
|
78
|
+
export type ProcessSignalResult = {
|
|
79
|
+
readonly kind: typeof PROCESS_SIGNAL_RESULT_KIND.sent;
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: typeof PROCESS_SIGNAL_RESULT_KIND.absent;
|
|
82
|
+
} | {
|
|
83
|
+
readonly kind: typeof PROCESS_SIGNAL_RESULT_KIND.denied;
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: typeof PROCESS_SIGNAL_RESULT_KIND.failed;
|
|
86
|
+
readonly code: string;
|
|
87
|
+
};
|
|
88
|
+
export type ControlledProcessOutput = {
|
|
89
|
+
readonly channel: ValueOf<typeof OUTPUT_CHANNEL_KIND>;
|
|
90
|
+
readonly text: string;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=supervisor-model.d.ts.map
|