@layernorm/overlay-agent-host 0.4.2 → 0.5.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 +40 -27
- package/dist/cli.js +56 -189
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +13 -277
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -48
- package/dist/config.js.map +1 -1
- package/dist/connection.d.ts +10 -10
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1 -1
- package/dist/connection.js.map +1 -1
- package/dist/doctor.d.ts +2 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -23
- package/dist/doctor.js.map +1 -1
- package/dist/enrollment.d.ts +4 -4
- package/dist/enrollment.d.ts.map +1 -1
- package/dist/enrollment.js +4 -16
- package/dist/enrollment.js.map +1 -1
- package/dist/host-capabilities.d.ts +5 -9
- package/dist/host-capabilities.d.ts.map +1 -1
- package/dist/host-capabilities.js +7 -63
- package/dist/host-capabilities.js.map +1 -1
- package/dist/index.d.ts +2 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/local-tools-browser.d.ts +54 -0
- package/dist/local-tools-browser.d.ts.map +1 -0
- package/dist/local-tools-browser.js +360 -0
- package/dist/local-tools-browser.js.map +1 -0
- package/dist/local-tools-errors.d.ts +8 -0
- package/dist/local-tools-errors.d.ts.map +1 -0
- package/dist/local-tools-errors.js +14 -0
- package/dist/local-tools-errors.js.map +1 -0
- package/dist/local-tools-exec.d.ts +27 -0
- package/dist/local-tools-exec.d.ts.map +1 -0
- package/dist/local-tools-exec.js +128 -0
- package/dist/local-tools-exec.js.map +1 -0
- package/dist/local-tools-macos.d.ts +20 -0
- package/dist/local-tools-macos.d.ts.map +1 -0
- package/dist/local-tools-macos.js +217 -0
- package/dist/local-tools-macos.js.map +1 -0
- package/dist/local-tools-paths.d.ts +13 -0
- package/dist/local-tools-paths.d.ts.map +1 -0
- package/dist/local-tools-paths.js +76 -0
- package/dist/local-tools-paths.js.map +1 -0
- package/dist/local-tools-terminal.d.ts +19 -0
- package/dist/local-tools-terminal.d.ts.map +1 -0
- package/dist/local-tools-terminal.js +201 -0
- package/dist/local-tools-terminal.js.map +1 -0
- package/dist/local-tools.d.ts +53 -0
- package/dist/local-tools.d.ts.map +1 -0
- package/dist/local-tools.js +219 -0
- package/dist/local-tools.js.map +1 -0
- package/dist/preview-hosting-access.d.ts +1 -1
- package/dist/preview-hosting-access.d.ts.map +1 -1
- package/dist/preview-hosting-access.js +1 -1
- package/dist/preview-hosting-access.js.map +1 -1
- package/dist/preview-hosting.d.ts +2 -7
- package/dist/preview-hosting.d.ts.map +1 -1
- package/dist/preview-hosting.js +2 -11
- package/dist/preview-hosting.js.map +1 -1
- package/dist/runtime.d.ts +11 -124
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +32 -551
- package/dist/runtime.js.map +1 -1
- package/dist/transport.d.ts +12 -29
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +15 -73
- package/dist/transport.js.map +1 -1
- package/docker-compose.example.yml +1 -1
- package/package.json +4 -8
- package/dist/acp-adapter.d.ts +0 -85
- package/dist/acp-adapter.d.ts.map +0 -1
- package/dist/acp-adapter.js +0 -418
- package/dist/acp-adapter.js.map +0 -1
- package/dist/acp-settings.d.ts +0 -29
- package/dist/acp-settings.d.ts.map +0 -1
- package/dist/acp-settings.js +0 -48
- package/dist/acp-settings.js.map +0 -1
- package/dist/acpx-adapter.d.ts +0 -122
- package/dist/acpx-adapter.d.ts.map +0 -1
- package/dist/acpx-adapter.js +0 -444
- package/dist/acpx-adapter.js.map +0 -1
- package/dist/acpx-session-identity.d.ts +0 -35
- package/dist/acpx-session-identity.d.ts.map +0 -1
- package/dist/acpx-session-identity.js +0 -55
- package/dist/acpx-session-identity.js.map +0 -1
- package/dist/action-title.d.ts +0 -3
- package/dist/action-title.d.ts.map +0 -1
- package/dist/action-title.js +0 -11
- package/dist/action-title.js.map +0 -1
- package/dist/adapter-manifests.d.ts +0 -49
- package/dist/adapter-manifests.d.ts.map +0 -1
- package/dist/adapter-manifests.js +0 -47
- package/dist/adapter-manifests.js.map +0 -1
- package/dist/adapter.d.ts +0 -50
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -10
- package/dist/adapter.js.map +0 -1
- package/dist/agent-options.d.ts +0 -4
- package/dist/agent-options.d.ts.map +0 -1
- package/dist/agent-options.js +0 -49
- package/dist/agent-options.js.map +0 -1
- package/dist/discovery-workspace.d.ts +0 -6
- package/dist/discovery-workspace.d.ts.map +0 -1
- package/dist/discovery-workspace.js +0 -20
- package/dist/discovery-workspace.js.map +0 -1
- package/dist/drive-cache.d.ts +0 -58
- package/dist/drive-cache.d.ts.map +0 -1
- package/dist/drive-cache.js +0 -243
- package/dist/drive-cache.js.map +0 -1
- package/dist/drive-client.d.ts +0 -112
- package/dist/drive-client.d.ts.map +0 -1
- package/dist/drive-client.js +0 -273
- package/dist/drive-client.js.map +0 -1
- package/dist/drive-journal.d.ts +0 -1218
- package/dist/drive-journal.d.ts.map +0 -1
- package/dist/drive-journal.js +0 -290
- package/dist/drive-journal.js.map +0 -1
- package/dist/drive-lease.d.ts +0 -15
- package/dist/drive-lease.d.ts.map +0 -1
- package/dist/drive-lease.js +0 -79
- package/dist/drive-lease.js.map +0 -1
- package/dist/drive-restoration.d.ts +0 -16
- package/dist/drive-restoration.d.ts.map +0 -1
- package/dist/drive-restoration.js +0 -36
- package/dist/drive-restoration.js.map +0 -1
- package/dist/drive-sync-state.d.ts +0 -2346
- package/dist/drive-sync-state.d.ts.map +0 -1
- package/dist/drive-sync-state.js +0 -100
- package/dist/drive-sync-state.js.map +0 -1
- package/dist/drive-sync.d.ts +0 -56
- package/dist/drive-sync.d.ts.map +0 -1
- package/dist/drive-sync.js +0 -539
- package/dist/drive-sync.js.map +0 -1
- package/dist/drive-writer.d.ts +0 -27
- package/dist/drive-writer.d.ts.map +0 -1
- package/dist/drive-writer.js +0 -64
- package/dist/drive-writer.js.map +0 -1
- package/dist/eve-adapter.d.ts +0 -75
- package/dist/eve-adapter.d.ts.map +0 -1
- package/dist/eve-adapter.js +0 -332
- package/dist/eve-adapter.js.map +0 -1
- package/dist/export-config.d.ts +0 -20
- package/dist/export-config.d.ts.map +0 -1
- package/dist/export-config.js +0 -128
- package/dist/export-config.js.map +0 -1
- package/dist/fake-adapter.d.ts +0 -43
- package/dist/fake-adapter.d.ts.map +0 -1
- package/dist/fake-adapter.js +0 -43
- package/dist/fake-adapter.js.map +0 -1
- package/dist/filesystem-policy.d.ts +0 -7
- package/dist/filesystem-policy.d.ts.map +0 -1
- package/dist/filesystem-policy.js +0 -23
- package/dist/filesystem-policy.js.map +0 -1
- package/dist/hermes-readiness.d.ts +0 -6
- package/dist/hermes-readiness.d.ts.map +0 -1
- package/dist/hermes-readiness.js +0 -21
- package/dist/hermes-readiness.js.map +0 -1
- package/dist/image-check.d.ts +0 -29
- package/dist/image-check.d.ts.map +0 -1
- package/dist/image-check.js +0 -61
- package/dist/image-check.js.map +0 -1
- package/dist/native-restoration.d.ts +0 -7
- package/dist/native-restoration.d.ts.map +0 -1
- package/dist/native-restoration.js +0 -21
- package/dist/native-restoration.js.map +0 -1
- package/dist/native-start-barrier.d.ts +0 -27
- package/dist/native-start-barrier.d.ts.map +0 -1
- package/dist/native-start-barrier.js +0 -28
- package/dist/native-start-barrier.js.map +0 -1
- package/dist/native-start-preparation.d.ts +0 -6
- package/dist/native-start-preparation.d.ts.map +0 -1
- package/dist/native-start-preparation.js +0 -23
- package/dist/native-start-preparation.js.map +0 -1
- package/dist/ordered-acp-updates.d.ts +0 -11
- package/dist/ordered-acp-updates.d.ts.map +0 -1
- package/dist/ordered-acp-updates.js +0 -38
- package/dist/ordered-acp-updates.js.map +0 -1
- package/dist/outbox-packing.d.ts +0 -22
- package/dist/outbox-packing.d.ts.map +0 -1
- package/dist/outbox-packing.js +0 -51
- package/dist/outbox-packing.js.map +0 -1
- package/dist/outbox-receipts.d.ts +0 -20
- package/dist/outbox-receipts.d.ts.map +0 -1
- package/dist/outbox-receipts.js +0 -44
- package/dist/outbox-receipts.js.map +0 -1
- package/dist/preparation-command-polling.d.ts +0 -13
- package/dist/preparation-command-polling.d.ts.map +0 -1
- package/dist/preparation-command-polling.js +0 -62
- package/dist/preparation-command-polling.js.map +0 -1
- package/dist/preparation-failure.d.ts +0 -2
- package/dist/preparation-failure.d.ts.map +0 -1
- package/dist/preparation-failure.js +0 -19
- package/dist/preparation-failure.js.map +0 -1
- package/dist/preview-mcp-relay.d.ts +0 -8
- package/dist/preview-mcp-relay.d.ts.map +0 -1
- package/dist/preview-mcp-relay.js +0 -127
- package/dist/preview-mcp-relay.js.map +0 -1
- package/dist/process-group.d.ts +0 -4
- package/dist/process-group.d.ts.map +0 -1
- package/dist/process-group.js +0 -38
- package/dist/process-group.js.map +0 -1
- package/dist/process-host-command.d.ts +0 -14
- package/dist/process-host-command.d.ts.map +0 -1
- package/dist/process-host-command.js +0 -55
- package/dist/process-host-command.js.map +0 -1
- package/dist/provider-run-credentials.d.ts +0 -13
- package/dist/provider-run-credentials.d.ts.map +0 -1
- package/dist/provider-run-credentials.js +0 -27
- package/dist/provider-run-credentials.js.map +0 -1
- package/dist/run-preparation.d.ts +0 -9
- package/dist/run-preparation.d.ts.map +0 -1
- package/dist/run-preparation.js +0 -21
- package/dist/run-preparation.js.map +0 -1
- package/dist/run-stream.d.ts +0 -20
- package/dist/run-stream.d.ts.map +0 -1
- package/dist/run-stream.js +0 -96
- package/dist/run-stream.js.map +0 -1
- package/dist/runtime-drive-controller.d.ts +0 -26
- package/dist/runtime-drive-controller.d.ts.map +0 -1
- package/dist/runtime-drive-controller.js +0 -118
- package/dist/runtime-drive-controller.js.map +0 -1
- package/dist/runtime-drive.d.ts +0 -30
- package/dist/runtime-drive.d.ts.map +0 -1
- package/dist/runtime-drive.js +0 -151
- package/dist/runtime-drive.js.map +0 -1
- package/dist/runtime-session-admission.d.ts +0 -24
- package/dist/runtime-session-admission.d.ts.map +0 -1
- package/dist/runtime-session-admission.js +0 -46
- package/dist/runtime-session-admission.js.map +0 -1
- package/dist/runtime-shutdown.d.ts +0 -21
- package/dist/runtime-shutdown.d.ts.map +0 -1
- package/dist/runtime-shutdown.js +0 -27
- package/dist/runtime-shutdown.js.map +0 -1
- package/dist/runtime-terminal-boundary.d.ts +0 -18
- package/dist/runtime-terminal-boundary.d.ts.map +0 -1
- package/dist/runtime-terminal-boundary.js +0 -36
- package/dist/runtime-terminal-boundary.js.map +0 -1
- package/dist/state.d.ts +0 -87
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -348
- package/dist/state.js.map +0 -1
- package/dist/text-coalescer.d.ts +0 -16
- package/dist/text-coalescer.d.ts.map +0 -1
- package/dist/text-coalescer.js +0 -55
- package/dist/text-coalescer.js.map +0 -1
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { agentSettingsSchema } from './acp-settings.js';
|
|
2
|
-
import { requireNativeRestorationSource } from './native-restoration.js';
|
|
3
|
-
function restorationSource(command, adapter, state) {
|
|
4
|
-
if (!command.payload.restore)
|
|
5
|
-
return undefined;
|
|
6
|
-
if (!adapter.capability.recovery?.fencedSessionRestoration || !adapter.capability.recovery.sessionLoading)
|
|
7
|
-
throw Error('This adapter cannot admit fenced native restoration');
|
|
8
|
-
return requireNativeRestorationSource(command, state.getSession(command.runId));
|
|
9
|
-
}
|
|
10
|
-
function claimStart(command, state, restored) {
|
|
11
|
-
if (!command.execution)
|
|
12
|
-
return;
|
|
13
|
-
// Restoration transfers ownership only after credentials/drive preparation, immediately before native startup.
|
|
14
|
-
if (restored)
|
|
15
|
-
return;
|
|
16
|
-
if (!state.claimExecution(command.runId, command.execution.attemptId))
|
|
17
|
-
throw Error('execution start outcome is unknown; inspect the existing process before continuing');
|
|
18
|
-
}
|
|
19
|
-
/** Validate before teardown; transfer durable ownership once, retaining native identity on restoration. */
|
|
20
|
-
export async function admitHostSession(input) {
|
|
21
|
-
const { command, adapter, state, sessions } = input;
|
|
22
|
-
const settings = agentSettingsSchema.parse(command.payload.metadata);
|
|
23
|
-
const restored = restorationSource(command, adapter, state);
|
|
24
|
-
const requested = command.payload.metadata.recoveryTextOffset;
|
|
25
|
-
let offset;
|
|
26
|
-
if (requested !== undefined) {
|
|
27
|
-
if ((!restored && command.payload.fresh !== true) || typeof requested !== 'number' || !Number.isSafeInteger(requested) || requested < 0)
|
|
28
|
-
throw Error('Invalid recovery text offset');
|
|
29
|
-
offset = requested;
|
|
30
|
-
}
|
|
31
|
-
if (command.payload.fresh) {
|
|
32
|
-
await sessions.get(command.runId)?.stop('Starting a fresh session');
|
|
33
|
-
sessions.delete(command.runId);
|
|
34
|
-
state.deleteSession(command.runId);
|
|
35
|
-
state.deleteAdapterSessionState(command.runId);
|
|
36
|
-
}
|
|
37
|
-
else if (!restored) {
|
|
38
|
-
if (sessions.has(command.runId))
|
|
39
|
-
return { kind: 'already-active' };
|
|
40
|
-
if (state.getSession(command.runId))
|
|
41
|
-
throw Error('persisted execution exists; observe or inspect its outcome before starting again');
|
|
42
|
-
}
|
|
43
|
-
claimStart(command, state, restored);
|
|
44
|
-
return { kind: 'admitted', settings, offset, restored };
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=runtime-session-admission.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-session-admission.js","sourceRoot":"","sources":["../src/runtime-session-admission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,mBAAmB,EAAqB,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAC,8BAA8B,EAAC,MAAM,yBAAyB,CAAA;AAMtE,SAAS,iBAAiB,CAAC,OAAqB,EAAE,OAAqB,EAAE,KAA2B;IAClG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAC9C,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EA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CAAC,CAAA;QAC7C,MAAM,GAAG,SAAS,CAAA;IACpB,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAA;QACnE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC9B,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAClC,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAChD,CAAC;SAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACrB,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,EAAC,IAAI,EAAE,gBAAgB,EAAC,CAAA;QAChE,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC,kFAAkF,CAAC,CAAA;IACtI,CAAC;IACD,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;IACpC,OAAO,EAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC,CAAA;AACvD,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { AgentAdapterSession } from './adapter.js';
|
|
2
|
-
/** A host cannot close SQLite while a prompt can still call its event callbacks. */
|
|
3
|
-
export declare class PendingHostPrompts {
|
|
4
|
-
private readonly onError;
|
|
5
|
-
private readonly pending;
|
|
6
|
-
constructor(onError: (error: unknown) => void);
|
|
7
|
-
track(work: Promise<void>): void;
|
|
8
|
-
settle(): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
export declare function quiesceHostRuns(input: {
|
|
11
|
-
sessions: Iterable<AgentAdapterSession>;
|
|
12
|
-
prompts: PendingHostPrompts;
|
|
13
|
-
streams: Iterable<{
|
|
14
|
-
drain(): Promise<void>;
|
|
15
|
-
}>;
|
|
16
|
-
drives: Iterable<{
|
|
17
|
-
stopScheduling(): void;
|
|
18
|
-
closeAfterStopped(): Promise<void>;
|
|
19
|
-
}>;
|
|
20
|
-
}): Promise<void>;
|
|
21
|
-
//# sourceMappingURL=runtime-shutdown.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-shutdown.d.ts","sourceRoot":"","sources":["../src/runtime-shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAA;AAErD,oFAAoF;AACpF,qBAAa,kBAAkB;IAEjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;gBACtB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;IAE9D,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAK1B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAC9B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE;IAC3C,QAAQ,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAA;IACvC,OAAO,EAAE,kBAAkB,CAAA;IAC3B,OAAO,EAAE,QAAQ,CAAC;QAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;KAAC,CAAC,CAAA;IAC3C,MAAM,EAAE,QAAQ,CAAC;QAAC,cAAc,IAAI,IAAI,CAAC;QAAC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;KAAC,CAAC,CAAA;CAC/E,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhB"}
|
package/dist/runtime-shutdown.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** A host cannot close SQLite while a prompt can still call its event callbacks. */
|
|
2
|
-
export class PendingHostPrompts {
|
|
3
|
-
onError;
|
|
4
|
-
pending = new Set();
|
|
5
|
-
constructor(onError) {
|
|
6
|
-
this.onError = onError;
|
|
7
|
-
}
|
|
8
|
-
track(work) {
|
|
9
|
-
const settled = work.catch(this.onError).finally(() => { this.pending.delete(settled); });
|
|
10
|
-
this.pending.add(settled);
|
|
11
|
-
}
|
|
12
|
-
async settle() { await Promise.all([...this.pending]); }
|
|
13
|
-
}
|
|
14
|
-
export async function quiesceHostRuns(input) {
|
|
15
|
-
const drives = [...input.drives];
|
|
16
|
-
for (const drive of drives)
|
|
17
|
-
drive.stopScheduling();
|
|
18
|
-
const stopped = await Promise.allSettled([...input.sessions].map(session => session.stop('Agent host shutting down')));
|
|
19
|
-
const failures = stopped.flatMap(result => result.status === 'rejected' ? [result.reason] : []);
|
|
20
|
-
// Keep cache ownership when an old writer is uncertain. Do not attest that shutdown drained.
|
|
21
|
-
if (failures.length)
|
|
22
|
-
throw new AggregateError(failures, 'Provider termination was not confirmed during host shutdown');
|
|
23
|
-
await input.prompts.settle();
|
|
24
|
-
await Promise.all([...input.streams].map(stream => stream.drain()));
|
|
25
|
-
await Promise.all(drives.map(drive => drive.closeAfterStopped()));
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=runtime-shutdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-shutdown.js","sourceRoot":"","sources":["../src/runtime-shutdown.ts"],"names":[],"mappings":"AAEA,oFAAoF;AACpF,MAAM,OAAO,kBAAkB;IAEA;IADZ,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAA;IACnD,YAA6B,OAAiC;QAAjC,YAAO,GAAP,OAAO,CAA0B;IAAG,CAAC;IAElE,KAAK,CAAC,IAAmB;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA,CAAA,CAA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nE,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AgentHostEvent } from '@layernorm/overlay-agent-bridge-protocol';
|
|
2
|
-
import type { AgentAdapterSession, EmitAgentEvent } from './adapter.js';
|
|
3
|
-
type Execution = AgentHostEvent['execution'];
|
|
4
|
-
type NativeTerminalIntentOptions = {
|
|
5
|
-
execution: Execution;
|
|
6
|
-
currentExecution(): Execution;
|
|
7
|
-
shuttingDown(): boolean;
|
|
8
|
-
markEnded(): void;
|
|
9
|
-
};
|
|
10
|
-
export declare function createNativeTerminalIntent(options: NativeTerminalIntentOptions): () => void;
|
|
11
|
-
/** An observation started earlier cannot revoke a finished or replaced execution. */
|
|
12
|
-
export declare function observeActiveNativeRuns(sessions: ReadonlyMap<string, AgentAdapterSession>, executions: ReadonlyMap<string, Execution>, ended: ReadonlySet<string>, report: (runId: string, process: 'live' | 'lost' | 'unknown', execution: Execution) => Promise<void>): Promise<void>;
|
|
13
|
-
/** Native work can finish before the host has drained its final text and file writes. */
|
|
14
|
-
export declare function withNativeTerminalBoundary(options: NativeTerminalIntentOptions & {
|
|
15
|
-
forward: EmitAgentEvent;
|
|
16
|
-
}): EmitAgentEvent;
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=runtime-terminal-boundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-terminal-boundary.d.ts","sourceRoot":"","sources":["../src/runtime-terminal-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAA;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAEvE,KAAK,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;AAC5C,KAAK,2BAA2B,GAAG;IACjC,SAAS,EAAE,SAAS,CAAA;IACpB,gBAAgB,IAAI,SAAS,CAAA;IAC7B,YAAY,IAAI,OAAO,CAAA;IACvB,SAAS,IAAI,IAAI,CAAA;CAClB,CAAA;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,MAAM,IAAI,CAO3F;AAED,qFAAqF;AACrF,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,EAC9F,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/H,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,yFAAyF;AACzF,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG;IAChF,OAAO,EAAE,cAAc,CAAA;CACxB,GAAG,cAAc,CASjB"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function createNativeTerminalIntent(options) {
|
|
2
|
-
return () => {
|
|
3
|
-
if (options.shuttingDown())
|
|
4
|
-
return;
|
|
5
|
-
const current = options.currentExecution();
|
|
6
|
-
if (options.execution?.attemptId === current?.attemptId
|
|
7
|
-
&& options.execution?.generation === current?.generation)
|
|
8
|
-
options.markEnded();
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/** An observation started earlier cannot revoke a finished or replaced execution. */
|
|
12
|
-
export async function observeActiveNativeRuns(sessions, executions, ended, report) {
|
|
13
|
-
for (const [runId, session] of sessions) {
|
|
14
|
-
const execution = executions.get(runId);
|
|
15
|
-
if (!execution || ended.has(runId))
|
|
16
|
-
continue;
|
|
17
|
-
const process = await session.observe?.() ?? 'unknown';
|
|
18
|
-
if (ended.has(runId) || executions.get(runId) !== execution)
|
|
19
|
-
continue;
|
|
20
|
-
await report(runId, process, execution);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/** Native work can finish before the host has drained its final text and file writes. */
|
|
24
|
-
export function withNativeTerminalBoundary(options) {
|
|
25
|
-
const markEnded = createNativeTerminalIntent(options);
|
|
26
|
-
return event => {
|
|
27
|
-
const terminal = ['completed', 'failed', 'cancelled'].includes(event.type);
|
|
28
|
-
if (options.shuttingDown() && terminal)
|
|
29
|
-
return Promise.resolve();
|
|
30
|
-
// A stale provider callback must never stop the replacement writer's probes.
|
|
31
|
-
if (terminal)
|
|
32
|
-
markEnded();
|
|
33
|
-
return options.forward(event);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=runtime-terminal-boundary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-terminal-boundary.js","sourceRoot":"","sources":["../src/runtime-terminal-boundary.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,0BAA0B,CAAC,OAAoC;IAC7E,OAAO,GAAG,EAAE;QACV,IAAI,OAAO,CAAC,YAAY,EAAE;YAAE,OAAM;QAClC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAA;QAC1C,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,EAAE,SAAS;eAClD,OAAO,CAAC,SAAS,EAAE,UAAU,KAAK,OAAO,EAAE,UAAU;YAAE,OAAO,CAAC,SAAS,EAAE,CAAA;IACjF,CAAC,CAAA;AACH,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,QAAkD,EAAE,UAA0C,EAC9F,KAA0B,EAAE,MAAoG;IAEhI,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACvC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,SAAQ;QAC5C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,IAAI,SAAS,CAAA;QACtD,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS;YAAE,SAAQ;QACrE,MAAM,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IACzC,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,0BAA0B,CAAC,OAE1C;IACC,MAAM,SAAS,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAA;IACrD,OAAO,KAAK,CAAC,EAAE;QACb,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC1E,IAAI,OAAO,CAAC,YAAY,EAAE,IAAI,QAAQ;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAChE,6EAA6E;QAC7E,IAAI,QAAQ;YAAE,SAAS,EAAE,CAAA;QACzB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC,CAAA;AACH,CAAC"}
|
package/dist/state.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { type AgentHostEvent } from '@layernorm/overlay-agent-bridge-protocol';
|
|
2
|
-
import type { AgentSettings } from './acp-settings.js';
|
|
3
|
-
export type StoredRemoteSession = {
|
|
4
|
-
config?: AgentSettings & {
|
|
5
|
-
version: 1;
|
|
6
|
-
configReference?: string;
|
|
7
|
-
toolsReference?: string;
|
|
8
|
-
};
|
|
9
|
-
execution?: {
|
|
10
|
-
attemptId: string;
|
|
11
|
-
generation: number;
|
|
12
|
-
hostBootId?: string;
|
|
13
|
-
};
|
|
14
|
-
runId: string;
|
|
15
|
-
adapterId: string;
|
|
16
|
-
remoteSessionId: string;
|
|
17
|
-
workingDirectory: string;
|
|
18
|
-
};
|
|
19
|
-
export type StoredCommandResult = {
|
|
20
|
-
accepted: boolean;
|
|
21
|
-
errorCode?: string;
|
|
22
|
-
errorMessage?: string;
|
|
23
|
-
sequence: number;
|
|
24
|
-
};
|
|
25
|
-
export type StoredAdapterSessionState = {
|
|
26
|
-
runId: string;
|
|
27
|
-
adapterId: string;
|
|
28
|
-
state: Record<string, unknown>;
|
|
29
|
-
};
|
|
30
|
-
export type HostStateScope = {
|
|
31
|
-
environmentId: string;
|
|
32
|
-
workspaceId: string;
|
|
33
|
-
};
|
|
34
|
-
export declare class SqliteHostStateStore {
|
|
35
|
-
private readonly database;
|
|
36
|
-
constructor(path: string, scope?: HostStateScope);
|
|
37
|
-
close(): void;
|
|
38
|
-
private assertScope;
|
|
39
|
-
private scopeValue;
|
|
40
|
-
hasProcessedCommand(commandId: string): boolean;
|
|
41
|
-
getProcessedCommand(commandId: string): StoredCommandResult | undefined;
|
|
42
|
-
claimCommand(commandId: string): boolean;
|
|
43
|
-
claimNativePreparation(commandId: string, fingerprint: string): boolean;
|
|
44
|
-
nativePreparationPending(commandId: string, fingerprint: string): boolean;
|
|
45
|
-
/** Commit the native-start boundary, ownership transfer and recoverable original identity together. */
|
|
46
|
-
enterNativeProviderStart(input: {
|
|
47
|
-
commandId: string;
|
|
48
|
-
fingerprint: string;
|
|
49
|
-
previous: StoredRemoteSession;
|
|
50
|
-
nextExecution: NonNullable<StoredRemoteSession['execution']>;
|
|
51
|
-
}): void;
|
|
52
|
-
commandCursor(): number;
|
|
53
|
-
adoptCommandCursor(lastConsumedSequence: number): boolean;
|
|
54
|
-
resumeCommandCursor(resolvedThroughSequence: number): boolean;
|
|
55
|
-
recordCommandResult(commandId: string, result: StoredCommandResult, now?: number): void;
|
|
56
|
-
claimExecution(runId: string, attemptId: string): boolean;
|
|
57
|
-
replaceExecutionClaim(runId: string, previousAttemptId: string, nextAttemptId: string): boolean;
|
|
58
|
-
saveSession(session: StoredRemoteSession, now?: number): void;
|
|
59
|
-
getSession(runId: string): StoredRemoteSession | undefined;
|
|
60
|
-
deleteSession(runId: string): void;
|
|
61
|
-
saveAdapterSessionState(runId: string, adapterId: string, state: Record<string, unknown>, now?: number): void;
|
|
62
|
-
getAdapterSessionState(runId: string, adapterId: string): Record<string, unknown> | undefined;
|
|
63
|
-
deleteAdapterSessionState(runId: string): void;
|
|
64
|
-
appendEvent(event: Omit<AgentHostEvent, 'sourceSequence'>): AgentHostEvent;
|
|
65
|
-
/**
|
|
66
|
-
* Appends a text checkpoint, or replaces the queued one when it is the newest event of its stream and is not
|
|
67
|
-
* being uploaded (`inFlightThrough` is the highest sequence currently in flight). Only the latest checkpoint
|
|
68
|
-
* matters to the transcript, so while uploads are slow the backlog stays one row instead of growing with every
|
|
69
|
-
* flush. Sequence numbers stay contiguous because the replaced row keeps its own.
|
|
70
|
-
*/
|
|
71
|
-
appendOrReplaceTextCheckpoint(event: Omit<AgentHostEvent, 'sourceSequence'>, inFlightThrough: number): AgentHostEvent;
|
|
72
|
-
/** Rewrites one queued event in place (same stream and sequence), e.g. to shrink a checkpoint that cannot be sent. */
|
|
73
|
-
replaceQueuedEvent(event: AgentHostEvent): void;
|
|
74
|
-
/** An upload may have reached the server even when its response was lost. Never rewrite those sequences. */
|
|
75
|
-
markUploadAttempt(events: AgentHostEvent[]): void;
|
|
76
|
-
private attemptedThrough;
|
|
77
|
-
pendingEvents(limit: number): AgentHostEvent[];
|
|
78
|
-
/** A retry cannot absorb events recorded after its acknowledgement was lost. */
|
|
79
|
-
pendingUploadEvents(limit: number): AgentHostEvent[];
|
|
80
|
-
uploadAttemptWatermark(runId: string, attemptId?: string): number;
|
|
81
|
-
acknowledgeEvents(runId: string, throughSequence: number, attemptId?: string): void;
|
|
82
|
-
discardEventsBefore(runId: string, expectedSequence: number, attemptId?: string): void;
|
|
83
|
-
outboxSize(): number;
|
|
84
|
-
lastEventSequence(runId: string, attemptId: string): number;
|
|
85
|
-
hasPendingEventsThrough(runId: string, attemptId: string, throughSequence: number): bool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AE,SAAS,EAAE,MAAM,GAAG,MAAM;IAK3D,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CAI5F"}
|
package/dist/state.js
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { mkdirSync } from 'node:fs';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
-
import { agentHostEventSchema } from '@layernorm/overlay-agent-bridge-protocol';
|
|
5
|
-
export class SqliteHostStateStore {
|
|
6
|
-
database;
|
|
7
|
-
constructor(path, scope) {
|
|
8
|
-
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
9
|
-
this.database = new DatabaseSync(path);
|
|
10
|
-
this.database.exec('PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON;');
|
|
11
|
-
this.database.exec(`
|
|
12
|
-
CREATE TABLE IF NOT EXISTS command_claims (command_id TEXT PRIMARY KEY);
|
|
13
|
-
CREATE TABLE IF NOT EXISTS native_start_preparations (command_id TEXT PRIMARY KEY, fingerprint TEXT NOT NULL,
|
|
14
|
-
phase TEXT NOT NULL CHECK(phase IN ('preparing','provider_starting')));
|
|
15
|
-
CREATE TABLE IF NOT EXISTS processed_commands (
|
|
16
|
-
command_id TEXT PRIMARY KEY,
|
|
17
|
-
sequence INTEGER NOT NULL,
|
|
18
|
-
accepted INTEGER NOT NULL,
|
|
19
|
-
error_code TEXT,
|
|
20
|
-
error_message TEXT,
|
|
21
|
-
processed_at INTEGER NOT NULL
|
|
22
|
-
);
|
|
23
|
-
CREATE TABLE IF NOT EXISTS host_state (
|
|
24
|
-
key TEXT PRIMARY KEY,
|
|
25
|
-
value INTEGER NOT NULL
|
|
26
|
-
);
|
|
27
|
-
CREATE TABLE IF NOT EXISTS host_scope (
|
|
28
|
-
key TEXT PRIMARY KEY,
|
|
29
|
-
value TEXT NOT NULL
|
|
30
|
-
);
|
|
31
|
-
CREATE TABLE IF NOT EXISTS remote_sessions (
|
|
32
|
-
run_id TEXT PRIMARY KEY,
|
|
33
|
-
adapter_id TEXT NOT NULL,
|
|
34
|
-
remote_session_id TEXT NOT NULL,
|
|
35
|
-
working_directory TEXT NOT NULL,
|
|
36
|
-
updated_at INTEGER NOT NULL
|
|
37
|
-
);
|
|
38
|
-
CREATE TABLE IF NOT EXISTS execution_claims (run_id TEXT PRIMARY KEY, attempt_id TEXT NOT NULL);
|
|
39
|
-
CREATE TABLE IF NOT EXISTS remote_session_config (run_id TEXT PRIMARY KEY, config_json TEXT NOT NULL);
|
|
40
|
-
CREATE TABLE IF NOT EXISTS adapter_session_state (
|
|
41
|
-
run_id TEXT PRIMARY KEY,
|
|
42
|
-
adapter_id TEXT NOT NULL,
|
|
43
|
-
state_json TEXT NOT NULL,
|
|
44
|
-
updated_at INTEGER NOT NULL
|
|
45
|
-
);
|
|
46
|
-
CREATE TABLE IF NOT EXISTS event_outbox (
|
|
47
|
-
event_id TEXT PRIMARY KEY,
|
|
48
|
-
environment_id TEXT NOT NULL,
|
|
49
|
-
run_id TEXT NOT NULL,
|
|
50
|
-
source_sequence INTEGER NOT NULL,
|
|
51
|
-
body TEXT NOT NULL,
|
|
52
|
-
created_at INTEGER NOT NULL,
|
|
53
|
-
UNIQUE(run_id, source_sequence)
|
|
54
|
-
);
|
|
55
|
-
CREATE TABLE IF NOT EXISTS attempted_uploads (run_id TEXT PRIMARY KEY, through_sequence INTEGER NOT NULL);
|
|
56
|
-
CREATE TABLE IF NOT EXISTS run_sequences (
|
|
57
|
-
run_id TEXT PRIMARY KEY,
|
|
58
|
-
last_sequence INTEGER NOT NULL
|
|
59
|
-
);
|
|
60
|
-
CREATE INDEX IF NOT EXISTS event_outbox_run_sequence ON event_outbox(run_id, source_sequence);
|
|
61
|
-
`);
|
|
62
|
-
// Queued rows from an older host may already have reached the server. Treat them as immutable on upgrade too.
|
|
63
|
-
this.database.exec(`INSERT INTO attempted_uploads(run_id, through_sequence)
|
|
64
|
-
SELECT run_id, MAX(source_sequence) FROM event_outbox GROUP BY run_id
|
|
65
|
-
ON CONFLICT(run_id) DO NOTHING`);
|
|
66
|
-
if (scope)
|
|
67
|
-
this.assertScope(scope);
|
|
68
|
-
}
|
|
69
|
-
close() { this.database.close(); }
|
|
70
|
-
assertScope(scope) {
|
|
71
|
-
const environmentId = this.scopeValue('environment_id');
|
|
72
|
-
const workspaceId = this.scopeValue('workspace_id');
|
|
73
|
-
if (environmentId && workspaceId && (environmentId !== scope.environmentId || workspaceId !== scope.workspaceId)) {
|
|
74
|
-
this.database.close();
|
|
75
|
-
throw new Error('host state scope does not match the host configuration');
|
|
76
|
-
}
|
|
77
|
-
this.database.prepare('INSERT OR IGNORE INTO host_scope(key, value) VALUES (?, ?)').run('environment_id', scope.environmentId);
|
|
78
|
-
this.database.prepare('INSERT OR IGNORE INTO host_scope(key, value) VALUES (?, ?)').run('workspace_id', scope.workspaceId);
|
|
79
|
-
}
|
|
80
|
-
scopeValue(key) {
|
|
81
|
-
const row = this.database.prepare('SELECT value FROM host_scope WHERE key = ?').get(key);
|
|
82
|
-
return row?.value;
|
|
83
|
-
}
|
|
84
|
-
hasProcessedCommand(commandId) {
|
|
85
|
-
return this.getProcessedCommand(commandId) !== undefined;
|
|
86
|
-
}
|
|
87
|
-
getProcessedCommand(commandId) {
|
|
88
|
-
const row = this.database.prepare('SELECT sequence, accepted, error_code, error_message FROM processed_commands WHERE command_id = ?').get(commandId);
|
|
89
|
-
if (!row)
|
|
90
|
-
return undefined;
|
|
91
|
-
return {
|
|
92
|
-
sequence: Number(row.sequence), accepted: Number(row.accepted) === 1,
|
|
93
|
-
...(row.error_code ? { errorCode: String(row.error_code) } : {}),
|
|
94
|
-
...(row.error_message ? { errorMessage: String(row.error_message) } : {}),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
claimCommand(commandId) {
|
|
98
|
-
return this.database.prepare('INSERT OR IGNORE INTO command_claims(command_id) VALUES (?)').run(commandId).changes === 1;
|
|
99
|
-
}
|
|
100
|
-
claimNativePreparation(commandId, fingerprint) {
|
|
101
|
-
this.database.exec('BEGIN IMMEDIATE');
|
|
102
|
-
try {
|
|
103
|
-
const existing = this.database.prepare('SELECT fingerprint,phase FROM native_start_preparations WHERE command_id=?').get(commandId);
|
|
104
|
-
let accepted = false;
|
|
105
|
-
if (existing)
|
|
106
|
-
accepted = existing.fingerprint === fingerprint && existing.phase === 'preparing'
|
|
107
|
-
&& Boolean(this.database.prepare('SELECT command_id FROM command_claims WHERE command_id=?').get(commandId));
|
|
108
|
-
else if (this.claimCommand(commandId)) {
|
|
109
|
-
this.database.prepare("INSERT INTO native_start_preparations(command_id,fingerprint,phase) VALUES(?,?,'preparing')").run(commandId, fingerprint);
|
|
110
|
-
accepted = true;
|
|
111
|
-
}
|
|
112
|
-
this.database.exec('COMMIT');
|
|
113
|
-
return accepted;
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
this.database.exec('ROLLBACK');
|
|
117
|
-
throw error;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
nativePreparationPending(commandId, fingerprint) {
|
|
121
|
-
const row = this.database.prepare('SELECT fingerprint,phase FROM native_start_preparations WHERE command_id=?').get(commandId);
|
|
122
|
-
return row?.fingerprint === fingerprint && row.phase === 'preparing'
|
|
123
|
-
&& Boolean(this.database.prepare('SELECT command_id FROM command_claims WHERE command_id=?').get(commandId));
|
|
124
|
-
}
|
|
125
|
-
/** Commit the native-start boundary, ownership transfer and recoverable original identity together. */
|
|
126
|
-
enterNativeProviderStart(input) {
|
|
127
|
-
this.database.exec('BEGIN IMMEDIATE');
|
|
128
|
-
try {
|
|
129
|
-
const stage = this.database.prepare('SELECT fingerprint,phase FROM native_start_preparations WHERE command_id=?').get(input.commandId);
|
|
130
|
-
const current = this.getSession(input.previous.runId), previous = input.previous.execution;
|
|
131
|
-
if (stage?.phase !== 'preparing' || stage.fingerprint !== input.fingerprint || !previous
|
|
132
|
-
|| !this.database.prepare('SELECT command_id FROM command_claims WHERE command_id=?').get(input.commandId)
|
|
133
|
-
|| current?.remoteSessionId !== input.previous.remoteSessionId || current.adapterId !== input.previous.adapterId
|
|
134
|
-
|| current.workingDirectory !== input.previous.workingDirectory || current.execution?.attemptId !== previous.attemptId
|
|
135
|
-
|| current.execution.generation !== previous.generation || current.execution.hostBootId !== previous.hostBootId
|
|
136
|
-
|| input.nextExecution.attemptId === previous.attemptId || input.nextExecution.generation !== previous.generation + 1
|
|
137
|
-
|| !this.replaceExecutionClaim(input.previous.runId, previous.attemptId, input.nextExecution.attemptId))
|
|
138
|
-
throw Error('Native restoration outcome is unknown; the execution claim cannot be replayed');
|
|
139
|
-
this.database.prepare("UPDATE native_start_preparations SET phase='provider_starting' WHERE command_id=?").run(input.commandId);
|
|
140
|
-
this.saveSession({ ...input.previous, execution: input.nextExecution });
|
|
141
|
-
this.database.exec('COMMIT');
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
this.database.exec('ROLLBACK');
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
commandCursor() {
|
|
149
|
-
const row = this.database.prepare("SELECT value FROM host_state WHERE key = 'command_cursor'").get();
|
|
150
|
-
return Number(row?.value ?? 0);
|
|
151
|
-
}
|
|
152
|
-
adoptCommandCursor(lastConsumedSequence) {
|
|
153
|
-
if (lastConsumedSequence < 1)
|
|
154
|
-
return false;
|
|
155
|
-
if (this.commandCursor() !== 0)
|
|
156
|
-
return false;
|
|
157
|
-
this.database.prepare(`INSERT INTO host_state(key, value) VALUES ('command_cursor', ?)
|
|
158
|
-
ON CONFLICT(key) DO UPDATE SET value=MAX(value, excluded.value)`).run(lastConsumedSequence);
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
// Forward-only cursor move used when the server attests that skipped numbers are resolved:
|
|
162
|
-
// unlike adoptCommandCursor this also runs once a cursor exists, and it can never move back.
|
|
163
|
-
resumeCommandCursor(resolvedThroughSequence) {
|
|
164
|
-
if (resolvedThroughSequence < 1)
|
|
165
|
-
return false;
|
|
166
|
-
this.database.prepare(`INSERT INTO host_state(key, value) VALUES ('command_cursor', ?)
|
|
167
|
-
ON CONFLICT(key) DO UPDATE SET value=MAX(value, excluded.value)`).run(resolvedThroughSequence);
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
recordCommandResult(commandId, result, now = Date.now()) {
|
|
171
|
-
this.database.exec('BEGIN IMMEDIATE');
|
|
172
|
-
try {
|
|
173
|
-
this.database.prepare(`INSERT OR IGNORE INTO processed_commands(
|
|
174
|
-
command_id, sequence, accepted, error_code, error_message, processed_at
|
|
175
|
-
) VALUES (?, ?, ?, ?, ?, ?)`).run(commandId, result.sequence, result.accepted ? 1 : 0, result.errorCode ?? null, result.errorMessage ?? null, now);
|
|
176
|
-
this.database.prepare(`INSERT INTO host_state(key, value) VALUES ('command_cursor', ?)
|
|
177
|
-
ON CONFLICT(key) DO UPDATE SET value=MAX(value, excluded.value)`).run(result.sequence);
|
|
178
|
-
this.database.prepare('DELETE FROM command_claims WHERE command_id = ?').run(commandId);
|
|
179
|
-
this.database.exec('COMMIT');
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
this.database.exec('ROLLBACK');
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
claimExecution(runId, attemptId) {
|
|
187
|
-
// Commit before the process can perform an external action. An unknown outcome is never re-prompted.
|
|
188
|
-
return this.database.prepare('INSERT OR IGNORE INTO execution_claims(run_id, attempt_id) VALUES (?, ?)').run(runId, attemptId).changes === 1;
|
|
189
|
-
}
|
|
190
|
-
replaceExecutionClaim(runId, previousAttemptId, nextAttemptId) {
|
|
191
|
-
if (previousAttemptId === nextAttemptId)
|
|
192
|
-
return false;
|
|
193
|
-
return this.database.prepare('UPDATE execution_claims SET attempt_id=? WHERE run_id=? AND attempt_id=?')
|
|
194
|
-
.run(nextAttemptId, runId, previousAttemptId).changes === 1;
|
|
195
|
-
}
|
|
196
|
-
saveSession(session, now = Date.now()) {
|
|
197
|
-
this.database.prepare(`
|
|
198
|
-
INSERT INTO remote_sessions(run_id, adapter_id, remote_session_id, working_directory, updated_at)
|
|
199
|
-
VALUES (?, ?, ?, ?, ?)
|
|
200
|
-
ON CONFLICT(run_id) DO UPDATE SET adapter_id=excluded.adapter_id, remote_session_id=excluded.remote_session_id,
|
|
201
|
-
working_directory=excluded.working_directory, updated_at=excluded.updated_at
|
|
202
|
-
`).run(session.runId, session.adapterId, session.remoteSessionId, session.workingDirectory, now);
|
|
203
|
-
if (session.config || session.execution)
|
|
204
|
-
this.database.prepare('INSERT INTO remote_session_config(run_id, config_json) VALUES (?, ?) ON CONFLICT(run_id) DO UPDATE SET config_json=excluded.config_json').run(session.runId, JSON.stringify({ config: session.config, execution: session.execution }));
|
|
205
|
-
}
|
|
206
|
-
getSession(runId) {
|
|
207
|
-
const row = this.database.prepare('SELECT run_id, adapter_id, remote_session_id, working_directory FROM remote_sessions WHERE run_id = ?').get(runId);
|
|
208
|
-
if (!row)
|
|
209
|
-
return undefined;
|
|
210
|
-
const saved = this.database.prepare('SELECT config_json FROM remote_session_config WHERE run_id = ?').get(runId);
|
|
211
|
-
const configuration = saved ? JSON.parse(saved.config_json) : {};
|
|
212
|
-
return { ...configuration, runId: String(row.run_id), adapterId: String(row.adapter_id), remoteSessionId: String(row.remote_session_id), workingDirectory: String(row.working_directory) };
|
|
213
|
-
}
|
|
214
|
-
deleteSession(runId) {
|
|
215
|
-
this.database.prepare('DELETE FROM remote_sessions WHERE run_id = ?').run(runId);
|
|
216
|
-
this.database.prepare('DELETE FROM remote_session_config WHERE run_id = ?').run(runId);
|
|
217
|
-
this.database.prepare('DELETE FROM execution_claims WHERE run_id = ?').run(runId);
|
|
218
|
-
}
|
|
219
|
-
saveAdapterSessionState(runId, adapterId, state, now = Date.now()) {
|
|
220
|
-
this.database.prepare(`
|
|
221
|
-
INSERT INTO adapter_session_state(run_id, adapter_id, state_json, updated_at)
|
|
222
|
-
VALUES (?, ?, ?, ?)
|
|
223
|
-
ON CONFLICT(run_id) DO UPDATE SET adapter_id=excluded.adapter_id,
|
|
224
|
-
state_json=excluded.state_json, updated_at=excluded.updated_at
|
|
225
|
-
`).run(runId, adapterId, JSON.stringify(state), now);
|
|
226
|
-
}
|
|
227
|
-
getAdapterSessionState(runId, adapterId) {
|
|
228
|
-
const row = this.database.prepare('SELECT adapter_id, state_json FROM adapter_session_state WHERE run_id = ?').get(runId);
|
|
229
|
-
if (!row)
|
|
230
|
-
return undefined;
|
|
231
|
-
if (row.adapter_id !== adapterId)
|
|
232
|
-
throw new Error('adapter session state belongs to a different adapter');
|
|
233
|
-
const parsed = JSON.parse(row.state_json);
|
|
234
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
235
|
-
throw new Error('adapter session state is invalid');
|
|
236
|
-
return parsed;
|
|
237
|
-
}
|
|
238
|
-
deleteAdapterSessionState(runId) {
|
|
239
|
-
this.database.prepare('DELETE FROM adapter_session_state WHERE run_id = ?').run(runId);
|
|
240
|
-
}
|
|
241
|
-
appendEvent(event) {
|
|
242
|
-
this.database.exec('BEGIN IMMEDIATE');
|
|
243
|
-
try {
|
|
244
|
-
const streamId = eventStreamId(event.runId, event.execution?.attemptId);
|
|
245
|
-
const row = this.database.prepare('SELECT last_sequence FROM run_sequences WHERE run_id = ?').get(streamId);
|
|
246
|
-
const stored = agentHostEventSchema.parse({ ...event, sourceSequence: Number(row?.last_sequence ?? 0) + 1 });
|
|
247
|
-
this.database.prepare('INSERT INTO event_outbox(event_id, environment_id, run_id, source_sequence, body, created_at) VALUES (?, ?, ?, ?, ?, ?)')
|
|
248
|
-
.run(stored.eventId, stored.environmentId, streamId, stored.sourceSequence, JSON.stringify(stored), Date.now());
|
|
249
|
-
this.database.prepare(`INSERT INTO run_sequences(run_id, last_sequence) VALUES (?, ?)
|
|
250
|
-
ON CONFLICT(run_id) DO UPDATE SET last_sequence=excluded.last_sequence`).run(streamId, stored.sourceSequence);
|
|
251
|
-
this.database.exec('COMMIT');
|
|
252
|
-
return stored;
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
this.database.exec('ROLLBACK');
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Appends a text checkpoint, or replaces the queued one when it is the newest event of its stream and is not
|
|
261
|
-
* being uploaded (`inFlightThrough` is the highest sequence currently in flight). Only the latest checkpoint
|
|
262
|
-
* matters to the transcript, so while uploads are slow the backlog stays one row instead of growing with every
|
|
263
|
-
* flush. Sequence numbers stay contiguous because the replaced row keeps its own.
|
|
264
|
-
*/
|
|
265
|
-
appendOrReplaceTextCheckpoint(event, inFlightThrough) {
|
|
266
|
-
if (event.type !== 'text_checkpoint')
|
|
267
|
-
return this.appendEvent(event);
|
|
268
|
-
this.database.exec('BEGIN IMMEDIATE');
|
|
269
|
-
try {
|
|
270
|
-
const streamId = eventStreamId(event.runId, event.execution?.attemptId);
|
|
271
|
-
const tail = this.database.prepare('SELECT source_sequence, body FROM event_outbox WHERE run_id = ? ORDER BY source_sequence DESC LIMIT 1')
|
|
272
|
-
.get(streamId);
|
|
273
|
-
const tailEvent = tail ? JSON.parse(tail.body) : undefined;
|
|
274
|
-
if (tail && tailEvent?.type === 'text_checkpoint' && Number(tail.source_sequence) > Math.max(inFlightThrough, this.attemptedThrough(streamId))
|
|
275
|
-
&& JSON.stringify(tailEvent.execution ?? null) === JSON.stringify(event.execution ?? null)) {
|
|
276
|
-
const stored = agentHostEventSchema.parse({ ...event, sourceSequence: Number(tail.source_sequence) });
|
|
277
|
-
this.database.prepare('UPDATE event_outbox SET event_id = ?, body = ? WHERE run_id = ? AND source_sequence = ?')
|
|
278
|
-
.run(stored.eventId, JSON.stringify(stored), streamId, stored.sourceSequence);
|
|
279
|
-
this.database.exec('COMMIT');
|
|
280
|
-
return stored;
|
|
281
|
-
}
|
|
282
|
-
this.database.exec('COMMIT');
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
this.database.exec('ROLLBACK');
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
return this.appendEvent(event);
|
|
289
|
-
}
|
|
290
|
-
/** Rewrites one queued event in place (same stream and sequence), e.g. to shrink a checkpoint that cannot be sent. */
|
|
291
|
-
replaceQueuedEvent(event) {
|
|
292
|
-
const stored = agentHostEventSchema.parse(event);
|
|
293
|
-
this.database.prepare('UPDATE event_outbox SET body = ? WHERE run_id = ? AND source_sequence = ?')
|
|
294
|
-
.run(JSON.stringify(stored), eventStreamId(stored.runId, stored.execution?.attemptId), stored.sourceSequence);
|
|
295
|
-
}
|
|
296
|
-
/** An upload may have reached the server even when its response was lost. Never rewrite those sequences. */
|
|
297
|
-
markUploadAttempt(events) {
|
|
298
|
-
const last = events.at(-1);
|
|
299
|
-
if (!last)
|
|
300
|
-
return;
|
|
301
|
-
this.database.prepare(`INSERT INTO attempted_uploads(run_id, through_sequence) VALUES (?, ?)
|
|
302
|
-
ON CONFLICT(run_id) DO UPDATE SET through_sequence = MAX(through_sequence, excluded.through_sequence)`)
|
|
303
|
-
.run(eventStreamId(last.runId, last.execution?.attemptId), last.sourceSequence);
|
|
304
|
-
}
|
|
305
|
-
attemptedThrough(streamId) {
|
|
306
|
-
const row = this.database.prepare('SELECT through_sequence FROM attempted_uploads WHERE run_id = ?').get(streamId);
|
|
307
|
-
return Number(row?.through_sequence ?? 0);
|
|
308
|
-
}
|
|
309
|
-
pendingEvents(limit) {
|
|
310
|
-
const first = this.database.prepare('SELECT run_id FROM event_outbox ORDER BY created_at, source_sequence LIMIT 1').get();
|
|
311
|
-
if (!first)
|
|
312
|
-
return [];
|
|
313
|
-
const rows = this.database.prepare('SELECT body FROM event_outbox WHERE run_id = ? ORDER BY source_sequence LIMIT ?').all(first.run_id, limit);
|
|
314
|
-
return rows.map((row) => agentHostEventSchema.parse(JSON.parse(row.body)));
|
|
315
|
-
}
|
|
316
|
-
/** A retry cannot absorb events recorded after its acknowledgement was lost. */
|
|
317
|
-
pendingUploadEvents(limit) {
|
|
318
|
-
const events = this.pendingEvents(limit);
|
|
319
|
-
const first = events[0];
|
|
320
|
-
if (!first)
|
|
321
|
-
return events;
|
|
322
|
-
const attempted = this.uploadAttemptWatermark(first.runId, first.execution?.attemptId);
|
|
323
|
-
return attempted >= first.sourceSequence ? events.filter(event => event.sourceSequence <= attempted) : events;
|
|
324
|
-
}
|
|
325
|
-
uploadAttemptWatermark(runId, attemptId) {
|
|
326
|
-
return this.attemptedThrough(eventStreamId(runId, attemptId));
|
|
327
|
-
}
|
|
328
|
-
acknowledgeEvents(runId, throughSequence, attemptId) {
|
|
329
|
-
this.database.prepare('DELETE FROM event_outbox WHERE run_id = ? AND source_sequence <= ?').run(eventStreamId(runId, attemptId), throughSequence);
|
|
330
|
-
}
|
|
331
|
-
discardEventsBefore(runId, expectedSequence, attemptId) {
|
|
332
|
-
this.database.prepare('DELETE FROM event_outbox WHERE run_id = ? AND source_sequence < ?').run(eventStreamId(runId, attemptId), expectedSequence);
|
|
333
|
-
}
|
|
334
|
-
outboxSize() {
|
|
335
|
-
const row = this.database.prepare('SELECT COUNT(*) AS count FROM event_outbox').get();
|
|
336
|
-
return Number(row.count);
|
|
337
|
-
}
|
|
338
|
-
lastEventSequence(runId, attemptId) {
|
|
339
|
-
const row = this.database.prepare('SELECT last_sequence FROM run_sequences WHERE run_id = ?').get(eventStreamId(runId, attemptId));
|
|
340
|
-
return Number(row?.last_sequence ?? 0);
|
|
341
|
-
}
|
|
342
|
-
hasPendingEventsThrough(runId, attemptId, throughSequence) {
|
|
343
|
-
return Boolean(this.database.prepare('SELECT 1 FROM event_outbox WHERE run_id = ? AND source_sequence <= ? LIMIT 1')
|
|
344
|
-
.get(eventStreamId(runId, attemptId), throughSequence));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function eventStreamId(runId, attemptId) { return attemptId ? JSON.stringify([runId, attemptId]) : runId; }
|
|
348
|
-
//# sourceMappingURL=state.js.map
|