@codetreker/daynight 0.25.4 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -4
- package/config.example.yml +3 -0
- package/dist/api/client.js +2 -2
- package/dist/api/client.js.map +1 -1
- package/dist/api/parse.js +14 -2
- package/dist/api/parse.js.map +1 -1
- package/dist/api/types.d.ts +4 -1
- package/dist/api/worker-mode.d.ts +6 -0
- package/dist/api/worker-mode.js +14 -0
- package/dist/api/worker-mode.js.map +1 -0
- package/dist/cli/commands.js +2 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/commands/controller/command-controls.d.ts +4 -0
- package/dist/commands/controller/command-controls.js +33 -0
- package/dist/commands/controller/command-controls.js.map +1 -0
- package/dist/commands/controller/definition.d.ts +3 -0
- package/dist/commands/controller/definition.js +22 -0
- package/dist/commands/controller/definition.js.map +1 -0
- package/dist/commands/controller/independent.d.ts +3 -0
- package/dist/commands/controller/independent.js +344 -0
- package/dist/commands/controller/independent.js.map +1 -0
- package/dist/commands/controller/index.d.ts +12 -0
- package/dist/commands/controller/index.js +73 -0
- package/dist/commands/controller/index.js.map +1 -0
- package/dist/commands/controller/launch-ticket.d.ts +49 -0
- package/dist/commands/controller/launch-ticket.js +99 -0
- package/dist/commands/controller/launch-ticket.js.map +1 -0
- package/dist/commands/controller/lifecycle-store.d.ts +84 -0
- package/dist/commands/controller/lifecycle-store.js +278 -0
- package/dist/commands/controller/lifecycle-store.js.map +1 -0
- package/dist/commands/controller/local-client.d.ts +44 -0
- package/dist/commands/controller/local-client.js +75 -0
- package/dist/commands/controller/local-client.js.map +1 -0
- package/dist/commands/controller/local-content.d.ts +23 -0
- package/dist/commands/controller/local-content.js +103 -0
- package/dist/commands/controller/local-content.js.map +1 -0
- package/dist/commands/controller/process-proof.d.ts +13 -0
- package/dist/commands/controller/process-proof.js +121 -0
- package/dist/commands/controller/process-proof.js.map +1 -0
- package/dist/commands/controller/providers/claude.d.ts +2 -0
- package/dist/commands/controller/providers/claude.js +470 -0
- package/dist/commands/controller/providers/claude.js.map +1 -0
- package/dist/commands/controller/providers/codex.d.ts +2 -0
- package/dist/commands/controller/providers/codex.js +254 -0
- package/dist/commands/controller/providers/codex.js.map +1 -0
- package/dist/commands/controller/providers/controls-claude.d.ts +26 -0
- package/dist/commands/controller/providers/controls-claude.js +138 -0
- package/dist/commands/controller/providers/controls-claude.js.map +1 -0
- package/dist/commands/controller/providers/controls-codex.d.ts +38 -0
- package/dist/commands/controller/providers/controls-codex.js +199 -0
- package/dist/commands/controller/providers/controls-codex.js.map +1 -0
- package/dist/commands/controller/providers/controls-copilot.d.ts +20 -0
- package/dist/commands/controller/providers/controls-copilot.js +143 -0
- package/dist/commands/controller/providers/controls-copilot.js.map +1 -0
- package/dist/commands/controller/providers/controls.d.ts +21 -0
- package/dist/commands/controller/providers/controls.js +53 -0
- package/dist/commands/controller/providers/controls.js.map +1 -0
- package/dist/commands/controller/providers/copilot-interactions.d.ts +47 -0
- package/dist/commands/controller/providers/copilot-interactions.js +295 -0
- package/dist/commands/controller/providers/copilot-interactions.js.map +1 -0
- package/dist/commands/controller/providers/copilot-projection.d.ts +11 -0
- package/dist/commands/controller/providers/copilot-projection.js +93 -0
- package/dist/commands/controller/providers/copilot-projection.js.map +1 -0
- package/dist/commands/controller/providers/copilot-runtime.d.ts +9 -0
- package/dist/commands/controller/providers/copilot-runtime.js +127 -0
- package/dist/commands/controller/providers/copilot-runtime.js.map +1 -0
- package/dist/commands/controller/providers/copilot.d.ts +2 -0
- package/dist/commands/controller/providers/copilot.js +309 -0
- package/dist/commands/controller/providers/copilot.js.map +1 -0
- package/dist/commands/controller/providers/interactions.d.ts +3 -0
- package/dist/commands/controller/providers/interactions.js +79 -0
- package/dist/commands/controller/providers/interactions.js.map +1 -0
- package/dist/commands/controller/providers/native-rpc.d.ts +28 -0
- package/dist/commands/controller/providers/native-rpc.js +85 -0
- package/dist/commands/controller/providers/native-rpc.js.map +1 -0
- package/dist/commands/controller/providers/projection.d.ts +23 -0
- package/dist/commands/controller/providers/projection.js +99 -0
- package/dist/commands/controller/providers/projection.js.map +1 -0
- package/dist/commands/controller/providers/turns.d.ts +7 -0
- package/dist/commands/controller/providers/turns.js +21 -0
- package/dist/commands/controller/providers/turns.js.map +1 -0
- package/dist/commands/controller/providers/types.d.ts +44 -0
- package/dist/commands/controller/providers/types.js +2 -0
- package/dist/commands/controller/providers/types.js.map +1 -0
- package/dist/commands/controller/recovery.d.ts +6 -0
- package/dist/commands/controller/recovery.js +22 -0
- package/dist/commands/controller/recovery.js.map +1 -0
- package/dist/commands/controller/relay.d.ts +18 -0
- package/dist/commands/controller/relay.js +299 -0
- package/dist/commands/controller/relay.js.map +1 -0
- package/dist/commands/controller/resume.d.ts +18 -0
- package/dist/commands/controller/resume.js +193 -0
- package/dist/commands/controller/resume.js.map +1 -0
- package/dist/commands/controller/runtime.d.ts +5 -0
- package/dist/commands/controller/runtime.js +455 -0
- package/dist/commands/controller/runtime.js.map +1 -0
- package/dist/commands/controller/windows-job.d.ts +3 -0
- package/dist/commands/controller/windows-job.js +59 -0
- package/dist/commands/controller/windows-job.js.map +1 -0
- package/dist/commands/controller/wire-display.d.ts +5 -0
- package/dist/commands/controller/wire-display.js +11 -0
- package/dist/commands/controller/wire-display.js.map +1 -0
- package/dist/commands/worker/backend.d.ts +7 -0
- package/dist/commands/worker/backend.js +7 -0
- package/dist/commands/worker/backend.js.map +1 -0
- package/dist/commands/worker/backends/grant-renewal.d.ts +13 -0
- package/dist/commands/worker/backends/grant-renewal.js +42 -0
- package/dist/commands/worker/backends/grant-renewal.js.map +1 -0
- package/dist/commands/worker/backends/session-api.d.ts +66 -0
- package/dist/commands/worker/backends/session-api.js +84 -0
- package/dist/commands/worker/backends/session-api.js.map +1 -0
- package/dist/commands/worker/backends/web-process.d.ts +79 -0
- package/dist/commands/worker/backends/web-process.js +156 -0
- package/dist/commands/worker/backends/web-process.js.map +1 -0
- package/dist/commands/worker/backends/web-store.d.ts +49 -0
- package/dist/commands/worker/backends/web-store.js +323 -0
- package/dist/commands/worker/backends/web-store.js.map +1 -0
- package/dist/commands/worker/backends/web-types.d.ts +83 -0
- package/dist/commands/worker/backends/web-types.js +3 -0
- package/dist/commands/worker/backends/web-types.js.map +1 -0
- package/dist/commands/worker/backends/web.d.ts +26 -0
- package/dist/commands/worker/backends/web.js +178 -0
- package/dist/commands/worker/backends/web.js.map +1 -0
- package/dist/commands/worker/config.js +12 -5
- package/dist/commands/worker/config.js.map +1 -1
- package/dist/commands/worker/control.d.ts +2 -0
- package/dist/commands/worker/control.js +11 -4
- package/dist/commands/worker/control.js.map +1 -1
- package/dist/commands/worker/coordinator.d.ts +7 -0
- package/dist/commands/worker/coordinator.js +138 -19
- package/dist/commands/worker/coordinator.js.map +1 -1
- package/dist/commands/worker/herdr/agents.js +5 -4
- package/dist/commands/worker/herdr/agents.js.map +1 -1
- package/dist/commands/worker/herdr/arguments.js +9 -4
- package/dist/commands/worker/herdr/arguments.js.map +1 -1
- package/dist/commands/worker/herdr/claude-input.d.ts +2 -0
- package/dist/commands/worker/herdr/claude-input.js +20 -0
- package/dist/commands/worker/herdr/claude-input.js.map +1 -0
- package/dist/commands/worker/herdr/instance.js +1 -1
- package/dist/commands/worker/herdr/instance.js.map +1 -1
- package/dist/commands/worker/herdr/preflight.d.ts +1 -1
- package/dist/commands/worker/herdr/preflight.js +31 -10
- package/dist/commands/worker/herdr/preflight.js.map +1 -1
- package/dist/commands/worker/herdr.js +5 -1
- package/dist/commands/worker/herdr.js.map +1 -1
- package/dist/commands/worker/prompts.js +5 -1
- package/dist/commands/worker/prompts.js.map +1 -1
- package/dist/commands/worker/repositories.js +2 -2
- package/dist/commands/worker/repositories.js.map +1 -1
- package/dist/commands/worker/runtime.js +62 -10
- package/dist/commands/worker/runtime.js.map +1 -1
- package/dist/commands/worker/setup-environment.d.ts +2 -1
- package/dist/commands/worker/setup-environment.js +10 -4
- package/dist/commands/worker/setup-environment.js.map +1 -1
- package/dist/commands/worker/setup.js +5 -5
- package/dist/commands/worker/setup.js.map +1 -1
- package/dist/commands/worker/store.d.ts +2 -1
- package/dist/commands/worker/store.js +19 -9
- package/dist/commands/worker/store.js.map +1 -1
- package/dist/commands/worker/types.d.ts +4 -1
- package/dist/session/controller-protocol.d.ts +245 -0
- package/dist/session/controller-protocol.js +218 -0
- package/dist/session/controller-protocol.js.map +1 -0
- package/dist/session/controls.d.ts +28 -0
- package/dist/session/controls.js +37 -0
- package/dist/session/controls.js.map +1 -0
- package/dist/session/protocol.d.ts +290 -0
- package/dist/session/protocol.js +307 -0
- package/dist/session/protocol.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
import { readLaunchTicket } from "../../controller/launch-ticket.js";
|
|
3
|
+
/** Keep native channels authorized independently of claim-discovery polling. */
|
|
4
|
+
export const maintainWorkerControllerGrants = async (options) => {
|
|
5
|
+
const readTicket = options.readTicket ?? readLaunchTicket;
|
|
6
|
+
const failures = new Map();
|
|
7
|
+
while (!options.signal.aborted) {
|
|
8
|
+
const renewals = await Promise.allSettled(options.store.listUnfinishedTasks().map(async (task) => {
|
|
9
|
+
if (options.signal.aborted)
|
|
10
|
+
return;
|
|
11
|
+
const execution = task.webExecution;
|
|
12
|
+
if (task.serverOrigin !== options.serverOrigin || !execution?.ticketPath || execution.launchSubmission === "not-submitted" || task.cleanup?.agentStopped)
|
|
13
|
+
return;
|
|
14
|
+
try {
|
|
15
|
+
const ticket = await readTicket(options.homeDirectory, execution.launchId);
|
|
16
|
+
if (ticket.executionId !== execution.executionId || ticket.executionGeneration !== execution.executionGeneration || ticket.controllerInstanceId !== execution.controllerInstanceId || ticket.claimId !== task.claimId)
|
|
17
|
+
throw new Error("Controller credential renewal has conflicting execution evidence.");
|
|
18
|
+
await options.launcher.refreshGrant(task, ticket, options.signal);
|
|
19
|
+
failures.delete(execution.executionId);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (options.signal.aborted)
|
|
23
|
+
return;
|
|
24
|
+
const message = error instanceof Error ? error.message : "Controller credential renewal failed.";
|
|
25
|
+
if (failures.get(execution.executionId) !== message)
|
|
26
|
+
options.onError(message);
|
|
27
|
+
failures.set(execution.executionId, message);
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
const rejected = renewals.filter(result => result.status === "rejected");
|
|
31
|
+
if (rejected.length > 0)
|
|
32
|
+
throw new AggregateError(rejected.map(result => result.reason), "Controller credential renewal could not finish safely.");
|
|
33
|
+
try {
|
|
34
|
+
await delay(30_000, undefined, { signal: options.signal });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (!options.signal.aborted)
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=grant-renewal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-renewal.js","sourceRoot":"","sources":["../../../../src/commands/worker/backends/grant-renewal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,gFAAgF;AAChF,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EAAE,OAKpD,EAAiB,EAAE;IAClB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,gBAAgB,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,GAAG,CAAC,KAAK,EAAC,IAAI,EAAC,EAAE;YAC7F,IAA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C;QACH,CAAC,CAAC,CAAC,CAAC;QACJ,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;QACzE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,wDAAwD,CAAC,CAAC;QACnJ,IAAI,CAAC;YAAC,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAAC,CAAC;QACnE,OAAO,KAAK,EAAE,CAAC;YAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,MAAM,KAAK,CAAC;QAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SESSION_PROTOCOL } from "../../../session/protocol.js";
|
|
2
|
+
import { type ControllerGrantResponse } from "../../../session/controller-protocol.js";
|
|
3
|
+
import type { LocalTask, WebExecutionState } from "./web-types.js";
|
|
4
|
+
export declare const createWorkerSessionApi: (serverOrigin: string, serverToken: string) => {
|
|
5
|
+
verifyUnregistered: (identity: {
|
|
6
|
+
projectId: string;
|
|
7
|
+
taskId: string;
|
|
8
|
+
claimId: string;
|
|
9
|
+
}, signal: AbortSignal) => Promise<void>;
|
|
10
|
+
verifySupport: (provider: string, signal: AbortSignal) => Promise<void>;
|
|
11
|
+
register: (task: LocalTask, execution: WebExecutionState, signal: AbortSignal) => Promise<{
|
|
12
|
+
readonly claimId: string;
|
|
13
|
+
readonly testExecutionId?: never;
|
|
14
|
+
} & {
|
|
15
|
+
readonly sessionId: string;
|
|
16
|
+
readonly executionGeneration: import("../../../session/protocol.js").DecimalSequence;
|
|
17
|
+
} & {
|
|
18
|
+
readonly connectionEpoch: import("../../../session/protocol.js").DecimalSequence;
|
|
19
|
+
} & {
|
|
20
|
+
readonly controls?: import("../../../session/controls.js").SessionControls;
|
|
21
|
+
readonly turnStartedAt?: string | null;
|
|
22
|
+
readonly protocol: typeof SESSION_PROTOCOL;
|
|
23
|
+
readonly schemaVersion: typeof import("../../../session/protocol.js").SESSION_SCHEMA_VERSION;
|
|
24
|
+
readonly projectionVersion: typeof import("../../../session/protocol.js").SESSION_PROJECTION_VERSION;
|
|
25
|
+
readonly identity: ({
|
|
26
|
+
readonly projectId: string;
|
|
27
|
+
readonly taskId: string;
|
|
28
|
+
readonly workerId: string;
|
|
29
|
+
readonly worktreeId: string;
|
|
30
|
+
readonly ownerUserId?: never;
|
|
31
|
+
} | {
|
|
32
|
+
readonly ownerUserId: string;
|
|
33
|
+
readonly projectId?: never;
|
|
34
|
+
readonly taskId?: never;
|
|
35
|
+
readonly workerId?: never;
|
|
36
|
+
readonly worktreeId?: never;
|
|
37
|
+
}) & {
|
|
38
|
+
readonly controllerId: string;
|
|
39
|
+
readonly controllerInstanceId: string;
|
|
40
|
+
readonly agentControlMode: "web";
|
|
41
|
+
readonly provider: import("../../../session/protocol.js").SessionProvider;
|
|
42
|
+
readonly nativeSessionId: string | null;
|
|
43
|
+
};
|
|
44
|
+
readonly sessionRevision: import("../../../session/protocol.js").DecimalSequence;
|
|
45
|
+
readonly historyEpoch: string;
|
|
46
|
+
readonly lastEventSeq: import("../../../session/protocol.js").DecimalSequence;
|
|
47
|
+
readonly lastTimelineSeq: import("../../../session/protocol.js").DecimalSequence;
|
|
48
|
+
readonly initialInputState: import("../../../session/protocol.js").InitialInputState;
|
|
49
|
+
readonly synchronized: boolean;
|
|
50
|
+
readonly lifecycle: "active" | "draining" | "archived";
|
|
51
|
+
readonly connectionState: "connected" | "disconnected" | "synchronizing";
|
|
52
|
+
readonly activity: "initializing" | "idle" | "working" | "waiting_input" | "stopped" | "unknown";
|
|
53
|
+
readonly currentTurnId: string | null;
|
|
54
|
+
readonly capabilities: import("../../../session/protocol.js").SessionCapabilities;
|
|
55
|
+
readonly operations: import("../../../session/protocol.js").SessionOperations;
|
|
56
|
+
readonly cleanupInteractionIds?: readonly string[];
|
|
57
|
+
}>;
|
|
58
|
+
grant: (task: LocalTask, execution: WebExecutionState, signal: AbortSignal, previous?: {
|
|
59
|
+
generation: string;
|
|
60
|
+
instanceId: string;
|
|
61
|
+
recordId: string;
|
|
62
|
+
stoppedAt: string;
|
|
63
|
+
}) => Promise<ControllerGrantResponse>;
|
|
64
|
+
};
|
|
65
|
+
export declare const writeControllerCredential: (filename: string, grant: ControllerGrantResponse) => Promise<void>;
|
|
66
|
+
export type WorkerSessionApi = ReturnType<typeof createWorkerSessionApi>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { chmod, mkdir, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { SESSION_PROTOCOL } from "../../../session/protocol.js";
|
|
5
|
+
import { parseRegistrationResponse, parseControllerGrantResponse, parseCurrentSessionResponse } from "../../../session/controller-protocol.js";
|
|
6
|
+
export const createWorkerSessionApi = (serverOrigin, serverToken) => {
|
|
7
|
+
const request = async (target, body, signal, method = "POST") => {
|
|
8
|
+
const response = await fetch(`${serverOrigin}${target}`, { method, headers: { authorization: `Bearer ${serverToken}`, "content-type": "application/json" }, ...(body === undefined ? {} : { body: JSON.stringify(body) }), signal: AbortSignal.any([signal, AbortSignal.timeout(30000)]) });
|
|
9
|
+
const chunks = [];
|
|
10
|
+
let size = 0;
|
|
11
|
+
if (response.body !== null) {
|
|
12
|
+
const reader = response.body.getReader();
|
|
13
|
+
try {
|
|
14
|
+
while (true) {
|
|
15
|
+
const { done, value } = await reader.read();
|
|
16
|
+
if (done)
|
|
17
|
+
break;
|
|
18
|
+
size += value.byteLength;
|
|
19
|
+
if (size > 2 * 1024 * 1024) {
|
|
20
|
+
await reader.cancel();
|
|
21
|
+
throw new Error("Session registration response exceeds its limit.");
|
|
22
|
+
}
|
|
23
|
+
chunks.push(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
reader.releaseLock();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
31
|
+
if (!response.ok)
|
|
32
|
+
throw new Error(`Session registration failed with HTTP ${response.status}; read back the original registration before replacing its identity.`);
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error("Session registration returned invalid JSON; the result is unconfirmed.");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const prefix = (task) => `/api/v1/projects/${task.projectId}/tasks/${task.taskId}/sessions`;
|
|
41
|
+
return {
|
|
42
|
+
verifyUnregistered: async (identity, signal) => {
|
|
43
|
+
const result = parseCurrentSessionResponse(await request(`/api/v1/projects/${identity.projectId}/tasks/${identity.taskId}/sessions/current`, undefined, signal, "GET"));
|
|
44
|
+
if (result.status !== "not_registered" || result.claimId !== identity.claimId)
|
|
45
|
+
throw new Error("The original Web launch provenance is missing; an existing or superseded Session cannot be recreated or deleted. Restore its execution evidence.");
|
|
46
|
+
},
|
|
47
|
+
verifySupport: async (provider, signal) => {
|
|
48
|
+
const response = await fetch(`${serverOrigin}/api/v1/session-capabilities`, { headers: { authorization: `Bearer ${serverToken}` }, signal: AbortSignal.any([signal, AbortSignal.timeout(10000)]) });
|
|
49
|
+
if (!response.ok)
|
|
50
|
+
throw new Error("This service has not confirmed Web session protocol support; no claim was submitted.");
|
|
51
|
+
const value = await response.json();
|
|
52
|
+
if (value.protocol !== SESSION_PROTOCOL || value.schemaVersion !== 1 || value.projectionVersion !== 1 || !Array.isArray(value.providers) || !value.providers.includes(provider))
|
|
53
|
+
throw new Error("The service Web session protocol or provider is incompatible; no claim was submitted.");
|
|
54
|
+
},
|
|
55
|
+
register: async (task, execution, signal) => {
|
|
56
|
+
if (task.configuration?.agentControlMode !== "web")
|
|
57
|
+
throw new Error("Session registration requires a supported web execution.");
|
|
58
|
+
const input = { protocol: SESSION_PROTOCOL, registrationId: execution.registrationId, claimId: task.claimId, workerId: task.workerId, worktreeId: task.worktreeId, provider: task.configuration.agent, controllerId: execution.controllerId, controllerInstanceId: execution.controllerInstanceId };
|
|
59
|
+
const result = parseRegistrationResponse(await request(prefix(task), input, signal));
|
|
60
|
+
const session = result.session;
|
|
61
|
+
if (session.claimId !== task.claimId || session.identity.taskId !== task.taskId || session.identity.projectId !== task.projectId || session.identity.workerId !== task.workerId || session.identity.worktreeId !== task.worktreeId || session.identity.provider !== task.configuration.agent || session.identity.controllerId !== execution.controllerId || session.identity.controllerInstanceId !== execution.controllerInstanceId)
|
|
62
|
+
throw new Error("Registered session does not match the frozen execution.");
|
|
63
|
+
return session;
|
|
64
|
+
},
|
|
65
|
+
grant: async (task, execution, signal, previous) => {
|
|
66
|
+
if (execution.sessionId === null)
|
|
67
|
+
throw new Error("Controller authorization requires its registered session.");
|
|
68
|
+
const input = { protocol: SESSION_PROTOCOL, claimId: task.claimId, controllerId: execution.controllerId, controllerInstanceId: execution.controllerInstanceId, executionGeneration: execution.executionGeneration, kind: execution.launchSubmission === "not-submitted" ? "bootstrap" : "reconnect", previousGeneration: previous?.generation ?? null, stopProof: previous === undefined ? null : { recordId: previous.recordId, previousControllerInstanceId: previous.instanceId, stoppedAt: previous.stoppedAt } };
|
|
69
|
+
const grant = parseControllerGrantResponse(await request(`${prefix(task)}/${execution.sessionId}/controller-grant`, input, signal));
|
|
70
|
+
if (grant.sessionId !== execution.sessionId || grant.claimId !== task.claimId || grant.executionGeneration !== execution.executionGeneration || grant.controllerId !== execution.controllerId || grant.controllerInstanceId !== execution.controllerInstanceId)
|
|
71
|
+
throw new Error("Controller grant does not match the frozen execution.");
|
|
72
|
+
return grant;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export const writeControllerCredential = async (filename, grant) => {
|
|
77
|
+
await mkdir(path.dirname(filename), { recursive: true, mode: 0o700 });
|
|
78
|
+
await chmod(path.dirname(filename), 0o700);
|
|
79
|
+
const temporary = `${filename}.${randomUUID()}.tmp`;
|
|
80
|
+
await writeFile(temporary, `${JSON.stringify(grant)}\n`, { flag: "wx", mode: 0o600 });
|
|
81
|
+
await rename(temporary, filename);
|
|
82
|
+
await chmod(filename, 0o600);
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=session-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-api.js","sourceRoot":"","sources":["../../../../src/commands/worker/backends/session-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,2BAA2B,EAAuF,MAAM,yCAAyC,CAAC;AAEpO,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,YAAoB,EAAE,WAAmB,EAAE,EAAE;IAClF,MAAM,OAAO,GAAG,KAAK,EAAE,MAAc,EAAE,IAAa,EAAE,MAAmB,EAAE,MAAM,GAAG,MAAM,EAAoB,EAAE;QAC9G,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,YAAY,GAAG,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAA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KAAK,SAAS,CAAC,mBAAmB,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,YAAY,IAAI,KAAK,CAAC,oBAAoB,KAAK,SAAS,CAAC,oBAAoB;gBAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;YACzU,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,QAAgB,EAAE,KAA8B,EAAiB,EAAE;IACjH,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;IAClH,MAAM,SAAS,GAAG,GAAG,QAAQ,IAAI,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,SAAS,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAAC,MAAM,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAAC,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC9M,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type ControllerLaunchTicket } from "../../controller/launch-ticket.js";
|
|
2
|
+
import type { WebExecutionStore } from "./web-store.js";
|
|
3
|
+
import type { LocalTask } from "./web-types.js";
|
|
4
|
+
import type { WorkerSessionApi } from "./session-api.js";
|
|
5
|
+
export declare const createWebControllerLauncher: (options: {
|
|
6
|
+
homeDirectory: string;
|
|
7
|
+
packageDirectory: string;
|
|
8
|
+
store: WebExecutionStore;
|
|
9
|
+
sessionApi: WorkerSessionApi;
|
|
10
|
+
now: () => number;
|
|
11
|
+
}) => {
|
|
12
|
+
prepare: (...args: Parameters<(input: LocalTask, prompt: string, signal: AbortSignal) => Promise<ControllerLaunchTicket>>) => Promise<({
|
|
13
|
+
readonly schemaVersion: 1;
|
|
14
|
+
readonly launchId: string;
|
|
15
|
+
readonly executionId: string;
|
|
16
|
+
readonly controllerId: string;
|
|
17
|
+
readonly controllerInstanceId: string;
|
|
18
|
+
readonly sessionId: string;
|
|
19
|
+
readonly executionGeneration: string;
|
|
20
|
+
readonly serverOrigin: string;
|
|
21
|
+
readonly provider: "codex" | "claude" | "copilot";
|
|
22
|
+
readonly cwd: string;
|
|
23
|
+
readonly nativeHome: string;
|
|
24
|
+
readonly configuration: import("../types.js").FrozenExecutionConfiguration;
|
|
25
|
+
readonly initialOperationId: string;
|
|
26
|
+
readonly initialPrompt: string;
|
|
27
|
+
readonly resumeNativeSessionId: string | null;
|
|
28
|
+
readonly credentialFile: string;
|
|
29
|
+
readonly ipcEndpoint: string;
|
|
30
|
+
readonly ipcSecret: string;
|
|
31
|
+
readonly createdAt: string;
|
|
32
|
+
} & {
|
|
33
|
+
readonly claimId: string;
|
|
34
|
+
readonly testExecutionId?: never;
|
|
35
|
+
} & {
|
|
36
|
+
readonly claimId: string;
|
|
37
|
+
readonly projectId: string;
|
|
38
|
+
readonly taskId: string;
|
|
39
|
+
readonly workerId: string;
|
|
40
|
+
readonly worktreeId: string;
|
|
41
|
+
readonly userId: string;
|
|
42
|
+
readonly ownerUserId?: never;
|
|
43
|
+
readonly initialInput?: never;
|
|
44
|
+
}) | ({
|
|
45
|
+
readonly schemaVersion: 1;
|
|
46
|
+
readonly launchId: string;
|
|
47
|
+
readonly executionId: string;
|
|
48
|
+
readonly controllerId: string;
|
|
49
|
+
readonly controllerInstanceId: string;
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
readonly executionGeneration: string;
|
|
52
|
+
readonly serverOrigin: string;
|
|
53
|
+
readonly provider: "codex" | "claude" | "copilot";
|
|
54
|
+
readonly cwd: string;
|
|
55
|
+
readonly nativeHome: string;
|
|
56
|
+
readonly configuration: import("../types.js").FrozenExecutionConfiguration;
|
|
57
|
+
readonly initialOperationId: string;
|
|
58
|
+
readonly initialPrompt: string;
|
|
59
|
+
readonly resumeNativeSessionId: string | null;
|
|
60
|
+
readonly credentialFile: string;
|
|
61
|
+
readonly ipcEndpoint: string;
|
|
62
|
+
readonly ipcSecret: string;
|
|
63
|
+
readonly createdAt: string;
|
|
64
|
+
} & {
|
|
65
|
+
readonly testExecutionId: string;
|
|
66
|
+
readonly claimId?: never;
|
|
67
|
+
} & {
|
|
68
|
+
readonly testExecutionId: string;
|
|
69
|
+
readonly ownerUserId: string;
|
|
70
|
+
readonly initialInput: "none" | "prompt";
|
|
71
|
+
readonly projectId?: never;
|
|
72
|
+
readonly taskId?: never;
|
|
73
|
+
readonly workerId?: never;
|
|
74
|
+
readonly worktreeId?: never;
|
|
75
|
+
readonly userId?: never;
|
|
76
|
+
})>;
|
|
77
|
+
launch: (...args: Parameters<(input: LocalTask, ticket: ControllerLaunchTicket, signal: AbortSignal) => Promise<void>>) => Promise<void>;
|
|
78
|
+
refreshGrant: (...args: Parameters<(input: LocalTask, ticket: ControllerLaunchTicket, signal: AbortSignal) => Promise<void>>) => Promise<void>;
|
|
79
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { open, mkdir, readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
5
|
+
import { controllerExecutionDirectory, controllerTicketPath, readLaunchTicket, writeLaunchTicket } from "../../controller/launch-ticket.js";
|
|
6
|
+
import { readControllerSnapshot } from "../../controller/lifecycle-store.js";
|
|
7
|
+
import { requestController } from "../../controller/local-client.js";
|
|
8
|
+
import { captureProcessProof } from "../../controller/process-proof.js";
|
|
9
|
+
import { writeControllerCredential } from "./session-api.js";
|
|
10
|
+
export const createWebControllerLauncher = (options) => {
|
|
11
|
+
const current = (task) => { const latest = options.store.getTask(task); if (latest?.webExecution == null)
|
|
12
|
+
throw new Error("The web execution identity disappeared."); return latest; };
|
|
13
|
+
const tails = new Map();
|
|
14
|
+
const serialize = async (task, action) => {
|
|
15
|
+
const key = task.webExecution?.executionId ?? task.claimId;
|
|
16
|
+
const previous = tails.get(key) ?? Promise.resolve();
|
|
17
|
+
let release;
|
|
18
|
+
const gate = new Promise(resolve => { release = resolve; });
|
|
19
|
+
const tail = previous.then(() => gate);
|
|
20
|
+
tails.set(key, tail);
|
|
21
|
+
await previous;
|
|
22
|
+
try {
|
|
23
|
+
return await action();
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
release();
|
|
27
|
+
if (tails.get(key) === tail)
|
|
28
|
+
tails.delete(key);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const methods = {
|
|
32
|
+
prepare: async (input, prompt, signal) => {
|
|
33
|
+
let task = current(input);
|
|
34
|
+
let execution = task.webExecution;
|
|
35
|
+
if (execution.ticketPath !== null) {
|
|
36
|
+
const ticket = await readLaunchTicket(options.homeDirectory, execution.launchId);
|
|
37
|
+
if (execution.nativeHome === null)
|
|
38
|
+
options.store.updateWebExecution(task, { nativeHome: ticket.nativeHome }, options.now());
|
|
39
|
+
return ticket;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const existing = await readLaunchTicket(options.homeDirectory, execution.launchId);
|
|
43
|
+
if (existing.executionId !== execution.executionId || existing.claimId !== task.claimId || existing.executionGeneration !== execution.executionGeneration || existing.controllerInstanceId !== execution.controllerInstanceId || existing.initialOperationId !== execution.initialOperationId || existing.sessionId !== execution.sessionId || existing.initialPrompt !== execution.initialPrompt)
|
|
44
|
+
throw new Error("An existing launch ticket does not match the durable execution intent.");
|
|
45
|
+
options.store.updateWebExecution(task, { ticketPath: controllerTicketPath(options.homeDirectory, execution.launchId), nativeHome: existing.nativeHome }, options.now());
|
|
46
|
+
return existing;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
if (execution.initialPrompt === null) {
|
|
53
|
+
task = options.store.updateWebExecution(task, { initialPrompt: prompt }, options.now());
|
|
54
|
+
execution = task.webExecution;
|
|
55
|
+
}
|
|
56
|
+
if (task.resources.worktree === null || task.configuration === null || task.userId === null)
|
|
57
|
+
throw new Error("Controller launch requires its original worktree, provider and owner.");
|
|
58
|
+
if (execution.sessionId === null) {
|
|
59
|
+
const registered = await options.sessionApi.register(task, execution, signal);
|
|
60
|
+
task = options.store.updateWebExecution(task, { sessionId: registered.sessionId }, options.now());
|
|
61
|
+
execution = task.webExecution;
|
|
62
|
+
}
|
|
63
|
+
const directory = controllerExecutionDirectory(options.homeDirectory, execution.executionId);
|
|
64
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
65
|
+
const credentialFile = path.join(directory, "credential.json");
|
|
66
|
+
const previous = readControllerSnapshot(path.join(directory, "journal.sqlite"));
|
|
67
|
+
const stop = previous !== null && previous.executionGeneration !== execution.executionGeneration && previous.nativeStopped && previous.stoppedAt !== null ? { generation: previous.executionGeneration, instanceId: previous.controllerInstanceId, recordId: execution.launchId, stoppedAt: previous.stoppedAt } : undefined;
|
|
68
|
+
const grant = await options.sessionApi.grant(task, execution, signal, stop);
|
|
69
|
+
await writeControllerCredential(credentialFile, grant);
|
|
70
|
+
const endpointKey = createHash("sha256").update(`${options.homeDirectory}:${execution.launchId}`).digest("hex").slice(0, 20);
|
|
71
|
+
const ipcEndpoint = process.platform === "win32" ? `\\\\.\\pipe\\daynight-${endpointKey}` : path.join(options.homeDirectory, ".daynight", "c", `${endpointKey}.sock`);
|
|
72
|
+
if (process.platform !== "win32" && Buffer.byteLength(ipcEndpoint) > (process.platform === "darwin" ? 103 : 107))
|
|
73
|
+
throw new Error("The controller IPC endpoint exceeds this platform's socket path limit.");
|
|
74
|
+
if (process.platform !== "win32")
|
|
75
|
+
await mkdir(path.dirname(ipcEndpoint), { recursive: true, mode: 0o700 });
|
|
76
|
+
if (task.resources.worktree === null || task.configuration === null || task.userId === null)
|
|
77
|
+
throw new Error("The frozen launch binding disappeared.");
|
|
78
|
+
const nativeHome = execution.nativeHome ?? (task.configuration.agent === "codex" ? process.env.CODEX_HOME ?? path.join(options.homeDirectory, ".codex")
|
|
79
|
+
: task.configuration.agent === "claude" ? process.env.CLAUDE_CONFIG_DIR ?? path.join(options.homeDirectory, ".claude")
|
|
80
|
+
: process.env.COPILOT_HOME ?? path.join(options.homeDirectory, ".copilot"));
|
|
81
|
+
if (execution.nativeHome === null)
|
|
82
|
+
execution = options.store.updateWebExecution(task, { nativeHome }, options.now()).webExecution;
|
|
83
|
+
const initialPrompt = execution.initialPrompt ?? prompt;
|
|
84
|
+
const ticket = { schemaVersion: 1, launchId: execution.launchId, executionId: execution.executionId, controllerId: execution.controllerId, controllerInstanceId: execution.controllerInstanceId, sessionId: execution.sessionId, executionGeneration: execution.executionGeneration, serverOrigin: task.serverOrigin, projectId: task.projectId, taskId: task.taskId, claimId: task.claimId, workerId: task.workerId, worktreeId: task.worktreeId, userId: task.userId, provider: task.configuration.agent, cwd: task.resources.worktree.worktreePath, nativeHome, configuration: task.configuration, initialOperationId: execution.initialOperationId, initialPrompt, resumeNativeSessionId: task.resources.nativeSession?.sessionId ?? null, credentialFile, ipcEndpoint, ipcSecret: randomBytes(32).toString("hex"), createdAt: new Date(options.now()).toISOString() };
|
|
85
|
+
const ticketPath = await writeLaunchTicket(options.homeDirectory, ticket);
|
|
86
|
+
options.store.updateWebExecution(task, { ticketPath, initialPrompt }, options.now());
|
|
87
|
+
return ticket;
|
|
88
|
+
},
|
|
89
|
+
launch: async (input, ticket, signal) => {
|
|
90
|
+
let task = current(input);
|
|
91
|
+
if (task.webExecution.launchSubmission !== "not-submitted")
|
|
92
|
+
return;
|
|
93
|
+
// A reusable grant also supports the first hello, including a lost bootstrap handshake.
|
|
94
|
+
await writeControllerCredential(ticket.credentialFile, await options.sessionApi.grant(task, { ...task.webExecution, launchSubmission: "unknown" }, signal));
|
|
95
|
+
const directory = controllerExecutionDirectory(options.homeDirectory, ticket.executionId);
|
|
96
|
+
const log = await open(path.join(directory, "controller.log"), "a", 0o600);
|
|
97
|
+
try {
|
|
98
|
+
signal.throwIfAborted();
|
|
99
|
+
task = options.store.updateWebExecution(task, { launchSubmission: "unknown" }, options.now());
|
|
100
|
+
const child = spawn(process.execPath, [path.join(options.packageDirectory, "dist", "main.js"), "controller", ticket.provider, "--launch-id", ticket.launchId], { cwd: ticket.cwd, env: { ...process.env, HOME: options.homeDirectory, USERPROFILE: options.homeDirectory }, detached: process.platform !== "win32", stdio: ["ignore", log.fd, log.fd], windowsHide: true });
|
|
101
|
+
await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
|
|
102
|
+
child.unref();
|
|
103
|
+
if (child.pid === undefined)
|
|
104
|
+
throw new Error("Controller spawn did not establish its process identity.");
|
|
105
|
+
const proof = await captureProcessProof(child.pid);
|
|
106
|
+
task = options.store.updateWebExecution(task, { controllerProcess: proof }, options.now());
|
|
107
|
+
const deadline = Date.now() + 30000;
|
|
108
|
+
while (Date.now() < deadline) {
|
|
109
|
+
signal.throwIfAborted();
|
|
110
|
+
try {
|
|
111
|
+
const response = await requestController(ticket, { kind: "observe" }, { signal, timeoutMs: 1000 });
|
|
112
|
+
options.store.updateWebExecution(task, { launchSubmission: "acknowledged", nativeProcesses: response.snapshot.nativeProcesses }, options.now());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
117
|
+
throw new Error("Controller exited before its authenticated initialization; inspect its private log.");
|
|
118
|
+
}
|
|
119
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
120
|
+
}
|
|
121
|
+
throw new Error("Controller startup outcome is unknown; the original process and launch intent are retained.");
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
await log.close();
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
refreshGrant: async (input, ticket, signal) => {
|
|
128
|
+
const task = current(input);
|
|
129
|
+
if (task.webExecution.launchId !== ticket.launchId || task.cleanup?.agentStopped)
|
|
130
|
+
return;
|
|
131
|
+
let expiresAt;
|
|
132
|
+
try {
|
|
133
|
+
expiresAt = JSON.parse(await readFile(ticket.credentialFile, "utf8")).expiresAt;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw new Error("Controller credential state is unavailable; it cannot be silently replaced.");
|
|
137
|
+
}
|
|
138
|
+
if (typeof expiresAt !== "string" || !Number.isFinite(Date.parse(expiresAt)))
|
|
139
|
+
throw new Error("Controller credential expiry is invalid.");
|
|
140
|
+
if (Date.parse(expiresAt) - options.now() > 120_000)
|
|
141
|
+
return;
|
|
142
|
+
const grant = await options.sessionApi.grant(task, task.webExecution, signal);
|
|
143
|
+
const latest = current(task);
|
|
144
|
+
if (latest.webExecution.launchId !== ticket.launchId || latest.cleanup?.agentStopped)
|
|
145
|
+
return;
|
|
146
|
+
signal.throwIfAborted();
|
|
147
|
+
await writeControllerCredential(ticket.credentialFile, grant);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
prepare: (...args) => serialize(args[0], () => methods.prepare(...args)),
|
|
152
|
+
launch: (...args) => serialize(args[0], () => methods.launch(...args)),
|
|
153
|
+
refreshGrant: (...args) => serialize(args[0], () => methods.refreshGrant(...args)),
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=web-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-process.js","sourceRoot":"","sources":["../../../../src/commands/worker/backends/web-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IA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AAC;QAC5G,MAAM,EAAE,CAAC,GAAG,IAAuC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QACzG,YAAY,EAAE,CAAC,GAAG,IAA6C,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;KAC5H,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ExecutionConfiguration as FrozenExecutionConfiguration, WorkerProject, ResourceOwner } from "../types.js";
|
|
2
|
+
import type { LocalTask, ClaimIdentity, CleanupState, WorktreeBinding, WebExecutionState } from "./web-types.js";
|
|
3
|
+
export declare const openWebExecutionStore: (filename: string) => {
|
|
4
|
+
close: () => void;
|
|
5
|
+
getTask: (identity: ClaimIdentity) => LocalTask | null;
|
|
6
|
+
listUnfinishedTasks: () => LocalTask[];
|
|
7
|
+
register: (input: ResourceOwner & {
|
|
8
|
+
project: WorkerProject;
|
|
9
|
+
serverOrigin: string;
|
|
10
|
+
workerId: string;
|
|
11
|
+
userId: string;
|
|
12
|
+
configuration: FrozenExecutionConfiguration;
|
|
13
|
+
}, now: number) => LocalTask;
|
|
14
|
+
clearShutdown: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
15
|
+
beginRecovery: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
16
|
+
authorizeRecoveryRetry: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
17
|
+
bindNativeSession: (identity: ClaimIdentity, reference: {
|
|
18
|
+
source: "controller";
|
|
19
|
+
sessionId: string;
|
|
20
|
+
}, now: number) => LocalTask;
|
|
21
|
+
completeTask: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
22
|
+
initializeWebExecution: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
23
|
+
updateWebExecution: (identity: ClaimIdentity, patch: Partial<WebExecutionState>, now: number) => LocalTask;
|
|
24
|
+
beginWebGeneration: (identity: ClaimIdentity, previous: {
|
|
25
|
+
executionGeneration: string;
|
|
26
|
+
controllerInstanceId: string;
|
|
27
|
+
nativeSessionId: string | null;
|
|
28
|
+
nativeStopped: boolean;
|
|
29
|
+
}, now: number) => LocalTask;
|
|
30
|
+
confirmBackendResourcesClosed: (identity: ClaimIdentity, proof: {
|
|
31
|
+
controllerStopped: true;
|
|
32
|
+
endpointClosed: true;
|
|
33
|
+
}, now: number) => LocalTask;
|
|
34
|
+
bindWorktree: (identity: ClaimIdentity, binding: WorktreeBinding, now: number) => LocalTask;
|
|
35
|
+
beginCleanup: (identity: ClaimIdentity, input: {
|
|
36
|
+
kind: CleanupState["kind"];
|
|
37
|
+
deadline: number;
|
|
38
|
+
}, now: number) => LocalTask;
|
|
39
|
+
markCleanupInputSubmitting: (identity: ClaimIdentity, now: number) => LocalTask;
|
|
40
|
+
recordCleanupInputOutcome: (identity: ClaimIdentity, input: "submitted" | "rejected" | "unavailable", now: number) => LocalTask;
|
|
41
|
+
recordCleanupResult: (identity: ClaimIdentity, result: NonNullable<CleanupState["result"]>, error: string | null, now: number) => LocalTask;
|
|
42
|
+
confirmAgentStopped: (identity: ClaimIdentity, proof: {
|
|
43
|
+
agentStopped: true;
|
|
44
|
+
}, now: number) => LocalTask;
|
|
45
|
+
confirmWorktreeDeleted: (identity: ClaimIdentity, proof: {
|
|
46
|
+
worktreeDeleted: true;
|
|
47
|
+
}, now: number) => LocalTask;
|
|
48
|
+
};
|
|
49
|
+
export type WebExecutionStore = ReturnType<typeof openWebExecutionStore>;
|