@allin-ai/agent-client 0.1.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/LICENSE +21 -0
- package/README.md +53 -0
- package/bin/allinai-agent +4 -0
- package/dist/capabilities/context.d.ts +16 -0
- package/dist/capabilities/context.d.ts.map +1 -0
- package/dist/capabilities/context.js +98 -0
- package/dist/capabilities/context.js.map +1 -0
- package/dist/capabilities/input.d.ts +7 -0
- package/dist/capabilities/input.d.ts.map +1 -0
- package/dist/capabilities/input.js +224 -0
- package/dist/capabilities/input.js.map +1 -0
- package/dist/capabilities/manifest.d.ts +15 -0
- package/dist/capabilities/manifest.d.ts.map +1 -0
- package/dist/capabilities/manifest.js +292 -0
- package/dist/capabilities/manifest.js.map +1 -0
- package/dist/capabilities/policy.d.ts +17 -0
- package/dist/capabilities/policy.d.ts.map +1 -0
- package/dist/capabilities/policy.js +57 -0
- package/dist/capabilities/policy.js.map +1 -0
- package/dist/capabilities/shell-host.d.ts +32 -0
- package/dist/capabilities/shell-host.d.ts.map +1 -0
- package/dist/capabilities/shell-host.js +378 -0
- package/dist/capabilities/shell-host.js.map +1 -0
- package/dist/capabilities/shell-wire.d.ts +13 -0
- package/dist/capabilities/shell-wire.d.ts.map +1 -0
- package/dist/capabilities/shell-wire.js +60 -0
- package/dist/capabilities/shell-wire.js.map +1 -0
- package/dist/capabilities/types.d.ts +46 -0
- package/dist/capabilities/types.d.ts.map +1 -0
- package/dist/capabilities/types.js +7 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/cli/commands.d.ts +83 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +638 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +7 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client/state-store.d.ts +80 -0
- package/dist/client/state-store.d.ts.map +1 -0
- package/dist/client/state-store.js +422 -0
- package/dist/client/state-store.js.map +1 -0
- package/dist/client/supervisor.d.ts +118 -0
- package/dist/client/supervisor.d.ts.map +1 -0
- package/dist/client/supervisor.js +627 -0
- package/dist/client/supervisor.js.map +1 -0
- package/dist/client/transport.d.ts +30 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +2 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client/types.d.ts +65 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +13 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/wire.d.ts +32 -0
- package/dist/client/wire.d.ts.map +1 -0
- package/dist/client/wire.js +302 -0
- package/dist/client/wire.js.map +1 -0
- package/dist/client/ws-transport.d.ts +54 -0
- package/dist/client/ws-transport.d.ts.map +1 -0
- package/dist/client/ws-transport.js +229 -0
- package/dist/client/ws-transport.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +125 -0
- package/dist/config.js.map +1 -0
- package/dist/control.d.ts +59 -0
- package/dist/control.d.ts.map +1 -0
- package/dist/control.js +217 -0
- package/dist/control.js.map +1 -0
- package/dist/credentials.d.ts +44 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +229 -0
- package/dist/credentials.js.map +1 -0
- package/dist/hub.d.ts +83 -0
- package/dist/hub.d.ts.map +1 -0
- package/dist/hub.js +412 -0
- package/dist/hub.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +47 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +175 -0
- package/dist/logger.js.map +1 -0
- package/dist/paths.d.ts +29 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +50 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugins/git.d.ts +30 -0
- package/dist/plugins/git.d.ts.map +1 -0
- package/dist/plugins/git.js +80 -0
- package/dist/plugins/git.js.map +1 -0
- package/dist/plugins/manager.d.ts +41 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +328 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +9 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +63 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/types.d.ts +39 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/runtime/claude.d.ts +30 -0
- package/dist/runtime/claude.d.ts.map +1 -0
- package/dist/runtime/claude.js +163 -0
- package/dist/runtime/claude.js.map +1 -0
- package/dist/runtime/codex.d.ts +44 -0
- package/dist/runtime/codex.d.ts.map +1 -0
- package/dist/runtime/codex.js +192 -0
- package/dist/runtime/codex.js.map +1 -0
- package/dist/runtime/events.d.ts +7 -0
- package/dist/runtime/events.d.ts.map +1 -0
- package/dist/runtime/events.js +37 -0
- package/dist/runtime/events.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/pi.d.ts +34 -0
- package/dist/runtime/pi.d.ts.map +1 -0
- package/dist/runtime/pi.js +211 -0
- package/dist/runtime/pi.js.map +1 -0
- package/dist/runtime/registry.d.ts +16 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +22 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime/runner-child.d.ts +2 -0
- package/dist/runtime/runner-child.d.ts.map +1 -0
- package/dist/runtime/runner-child.js +41 -0
- package/dist/runtime/runner-child.js.map +1 -0
- package/dist/runtime/runner-manager.d.ts +77 -0
- package/dist/runtime/runner-manager.d.ts.map +1 -0
- package/dist/runtime/runner-manager.js +295 -0
- package/dist/runtime/runner-manager.js.map +1 -0
- package/dist/runtime/runner-wire.d.ts +23 -0
- package/dist/runtime/runner-wire.d.ts.map +1 -0
- package/dist/runtime/runner-wire.js +93 -0
- package/dist/runtime/runner-wire.js.map +1 -0
- package/dist/runtime/types.d.ts +43 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +3 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/zcode.d.ts +14 -0
- package/dist/runtime/zcode.d.ts.map +1 -0
- package/dist/runtime/zcode.js +21 -0
- package/dist/runtime/zcode.js.map +1 -0
- package/dist/service/launchd.d.ts +34 -0
- package/dist/service/launchd.d.ts.map +1 -0
- package/dist/service/launchd.js +86 -0
- package/dist/service/launchd.js.map +1 -0
- package/dist/service/systemd.d.ts +16 -0
- package/dist/service/systemd.d.ts.map +1 -0
- package/dist/service/systemd.js +89 -0
- package/dist/service/systemd.js.map +1 -0
- package/dist/wire.d.ts +24 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +7 -0
- package/dist/wire.js.map +1 -0
- package/package.json +140 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":"AAEA,wBAAsB,IAAI,CAAC,IAAI,WAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGtE"}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;QAAE,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ClientCommand, ClientEvent } from "./types.js";
|
|
2
|
+
import type { ActivePluginSnapshot, PluginStateStore, StoredPluginState } from "../plugins/types.js";
|
|
3
|
+
export declare const EXECUTION_STATES: readonly ["received", "awaiting_approval", "running", "rejected", "done", "failed", "cancelled", "recovery_required"];
|
|
4
|
+
export type ExecutionState = (typeof EXECUTION_STATES)[number];
|
|
5
|
+
export type StoredExecution = {
|
|
6
|
+
executionId: string;
|
|
7
|
+
command: ClientCommand;
|
|
8
|
+
state: ExecutionState;
|
|
9
|
+
attempt: number;
|
|
10
|
+
admittedAt: string;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
lastEventSeq: number;
|
|
13
|
+
pluginSnapshot: ActivePluginSnapshot[];
|
|
14
|
+
};
|
|
15
|
+
export type AdmissionResult = {
|
|
16
|
+
disposition: "inserted" | "duplicate";
|
|
17
|
+
execution: StoredExecution;
|
|
18
|
+
};
|
|
19
|
+
export type AdmissionOptions = {
|
|
20
|
+
pluginSnapshot?: ActivePluginSnapshot[];
|
|
21
|
+
};
|
|
22
|
+
export type EventToAppend = Omit<ClientEvent, "eventSeq"> & {
|
|
23
|
+
eventSeq?: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Durable local inbox/outbox for one Agent Client daemon.
|
|
27
|
+
*
|
|
28
|
+
* `last_event_seq` deliberately lives with the execution rather than the
|
|
29
|
+
* outbox: acknowledged rows are deleted, but a later event must never reuse
|
|
30
|
+
* their sequence number.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ClientStateStore implements PluginStateStore {
|
|
33
|
+
private readonly db;
|
|
34
|
+
constructor(dbPath: string);
|
|
35
|
+
close(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Atomically writes the inbox command and its initial received event. A
|
|
38
|
+
* redelivered execution returns the existing row without adding an event.
|
|
39
|
+
*/
|
|
40
|
+
admit(command: ClientCommand, options?: AdmissionOptions): AdmissionResult;
|
|
41
|
+
getExecution(executionId: string): StoredExecution | null;
|
|
42
|
+
listExecutions(): StoredExecution[];
|
|
43
|
+
/**
|
|
44
|
+
* Changes execution state and commits the matching state event in the same
|
|
45
|
+
* transaction. Callers cannot report a durable state without a durable
|
|
46
|
+
* outbox record for it.
|
|
47
|
+
*/
|
|
48
|
+
transition(executionId: string, nextState: ExecutionState, payload?: Record<string, unknown>): ClientEvent;
|
|
49
|
+
/**
|
|
50
|
+
* Appends a non-state runtime event supplied by the caller. If no sequence is
|
|
51
|
+
* supplied, this store allocates the next sequence. Explicit sequences are
|
|
52
|
+
* accepted only when they are the next sequence, preventing acknowledgement
|
|
53
|
+
* watermarks from skipping an event.
|
|
54
|
+
*/
|
|
55
|
+
appendEvent(event: EventToAppend): ClientEvent;
|
|
56
|
+
listUnackedEvents(executionId?: string): ClientEvent[];
|
|
57
|
+
/** Deletes only events at or below the Hub's acknowledgement watermark. */
|
|
58
|
+
acknowledge(executionId: string, eventSeqWatermark: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* On daemon boot, no in-process runner can be trusted to still exist. Mark
|
|
61
|
+
* every persisted running execution (or one selected execution) as needing
|
|
62
|
+
* recovery and enqueue a matching state event.
|
|
63
|
+
*/
|
|
64
|
+
markRecoveryRequired(executionId?: string): ClientEvent[];
|
|
65
|
+
private initialize;
|
|
66
|
+
private transaction;
|
|
67
|
+
private getExecutionRow;
|
|
68
|
+
private requireExecutionRow;
|
|
69
|
+
private toExecution;
|
|
70
|
+
getLastPluginSyncRevision(): string | null;
|
|
71
|
+
recordPluginSyncSuccess(revision: string): void;
|
|
72
|
+
listPluginStates(): StoredPluginState[];
|
|
73
|
+
savePluginState(state: StoredPluginState): void;
|
|
74
|
+
private assertLegalTransition;
|
|
75
|
+
private transitionRow;
|
|
76
|
+
private insertOutboxEvent;
|
|
77
|
+
private parseStoredEvent;
|
|
78
|
+
private assertValidEvent;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../../src/client/state-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAE9E,OAAO,KAAK,EACV,oBAAoB,EAEpB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,gBAAgB,uHASnB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,oBAAoB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,UAAU,GAAG,WAAW,CAAC;IACtC,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAmHF;;;;;;GAMG;AACH,qBAAa,gBAAiB,YAAW,gBAAgB;IACvD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAe;gBAEtB,MAAM,EAAE,MAAM;IAK1B,KAAK,IAAI,IAAI;IAIb;;;OAGG;IACH,KAAK,CACH,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,gBAAqB,GAC7B,eAAe;IAwDlB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAKzD,cAAc,IAAI,eAAe,EAAE;IAWnC;;;;OAIG;IACH,UAAU,CACR,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,WAAW;IAQd;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,WAAW;IAgC9C,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAoBtD,2EAA2E;IAC3E,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM;IAenE;;;;OAIG;IACH,oBAAoB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAuBzD,OAAO,CAAC,UAAU;IA4ClB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,WAAW;IAwBnB,yBAAyB,IAAI,MAAM,GAAG,IAAI;IAO1C,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAa/C,gBAAgB,IAAI,iBAAiB,EAAE;IAYvC,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAkB/C,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,gBAAgB;CAUzB"}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import { parseClientCommand, parseClientEventBatch } from "./wire.js";
|
|
3
|
+
export const EXECUTION_STATES = [
|
|
4
|
+
"received",
|
|
5
|
+
"awaiting_approval",
|
|
6
|
+
"running",
|
|
7
|
+
"rejected",
|
|
8
|
+
"done",
|
|
9
|
+
"failed",
|
|
10
|
+
"cancelled",
|
|
11
|
+
"recovery_required",
|
|
12
|
+
];
|
|
13
|
+
const LEGAL_TRANSITIONS = {
|
|
14
|
+
received: ["awaiting_approval", "running", "rejected", "cancelled"],
|
|
15
|
+
awaiting_approval: ["running", "rejected", "cancelled"],
|
|
16
|
+
running: ["done", "failed", "cancelled", "recovery_required"],
|
|
17
|
+
rejected: [],
|
|
18
|
+
done: [],
|
|
19
|
+
failed: [],
|
|
20
|
+
cancelled: [],
|
|
21
|
+
recovery_required: [],
|
|
22
|
+
};
|
|
23
|
+
function isExecutionState(value) {
|
|
24
|
+
return EXECUTION_STATES.includes(value);
|
|
25
|
+
}
|
|
26
|
+
function now() {
|
|
27
|
+
return new Date().toISOString();
|
|
28
|
+
}
|
|
29
|
+
function commandAttempt(command) {
|
|
30
|
+
return command.kind === "cancel" ? 0 : command.attempt;
|
|
31
|
+
}
|
|
32
|
+
function isPlainObject(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
function normalizePluginSnapshot(value) {
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
return value.map((plugin) => {
|
|
38
|
+
if (!plugin ||
|
|
39
|
+
typeof plugin.id !== "string" ||
|
|
40
|
+
!plugin.id ||
|
|
41
|
+
typeof plugin.resolvedCommit !== "string" ||
|
|
42
|
+
!/^[0-9a-f]{40}$/i.test(plugin.resolvedCommit) ||
|
|
43
|
+
seen.has(plugin.id)) {
|
|
44
|
+
throw new TypeError("Plugin snapshot must contain unique full commits");
|
|
45
|
+
}
|
|
46
|
+
seen.add(plugin.id);
|
|
47
|
+
return {
|
|
48
|
+
id: plugin.id,
|
|
49
|
+
resolvedCommit: plugin.resolvedCommit.toLowerCase(),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function parsePluginSnapshot(value) {
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(value);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new TypeError("Stored plugin snapshot is invalid JSON");
|
|
60
|
+
}
|
|
61
|
+
if (!Array.isArray(parsed))
|
|
62
|
+
throw new TypeError("Stored plugin snapshot is invalid");
|
|
63
|
+
return normalizePluginSnapshot(parsed);
|
|
64
|
+
}
|
|
65
|
+
function assertInstalledPlugin(value) {
|
|
66
|
+
if (!isPlainObject(value) ||
|
|
67
|
+
typeof value.id !== "string" ||
|
|
68
|
+
!value.id ||
|
|
69
|
+
typeof value.gitUrl !== "string" ||
|
|
70
|
+
!value.gitUrl ||
|
|
71
|
+
typeof value.enabled !== "boolean" ||
|
|
72
|
+
typeof value.resolvedCommit !== "string" ||
|
|
73
|
+
!value.resolvedCommit ||
|
|
74
|
+
typeof value.installedAt !== "string" ||
|
|
75
|
+
!value.installedAt ||
|
|
76
|
+
!["active", "blocked", "failed"].includes(value.status)) {
|
|
77
|
+
throw new TypeError("Plugin installation record is invalid");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function parseInstalledPlugin(value) {
|
|
81
|
+
let parsed;
|
|
82
|
+
try {
|
|
83
|
+
parsed = JSON.parse(value);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
throw new TypeError("Stored plugin record is invalid JSON");
|
|
87
|
+
}
|
|
88
|
+
assertInstalledPlugin(parsed);
|
|
89
|
+
return parsed;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Durable local inbox/outbox for one Agent Client daemon.
|
|
93
|
+
*
|
|
94
|
+
* `last_event_seq` deliberately lives with the execution rather than the
|
|
95
|
+
* outbox: acknowledged rows are deleted, but a later event must never reuse
|
|
96
|
+
* their sequence number.
|
|
97
|
+
*/
|
|
98
|
+
export class ClientStateStore {
|
|
99
|
+
db;
|
|
100
|
+
constructor(dbPath) {
|
|
101
|
+
this.db = new DatabaseSync(dbPath);
|
|
102
|
+
this.initialize();
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
this.db.close();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Atomically writes the inbox command and its initial received event. A
|
|
109
|
+
* redelivered execution returns the existing row without adding an event.
|
|
110
|
+
*/
|
|
111
|
+
admit(command, options = {}) {
|
|
112
|
+
return this.transaction(() => {
|
|
113
|
+
const previous = this.getExecutionRow(command.executionId);
|
|
114
|
+
if (previous) {
|
|
115
|
+
return {
|
|
116
|
+
disposition: "duplicate",
|
|
117
|
+
execution: this.toExecution(previous),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const admittedAt = now();
|
|
121
|
+
const pluginSnapshot = normalizePluginSnapshot(options.pluginSnapshot ?? []);
|
|
122
|
+
const received = {
|
|
123
|
+
executionId: command.executionId,
|
|
124
|
+
eventSeq: 1,
|
|
125
|
+
type: "received",
|
|
126
|
+
occurredAt: admittedAt,
|
|
127
|
+
};
|
|
128
|
+
if (pluginSnapshot.length > 0)
|
|
129
|
+
received.payload = { pluginSnapshot };
|
|
130
|
+
this.db
|
|
131
|
+
.prepare(`INSERT INTO executions (
|
|
132
|
+
execution_id, command_json, state, attempt, admitted_at, updated_at, last_event_seq, plugin_snapshot_json
|
|
133
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
134
|
+
.run(command.executionId, JSON.stringify(command), "received", commandAttempt(command), admittedAt, admittedAt, received.eventSeq, JSON.stringify(pluginSnapshot));
|
|
135
|
+
this.insertOutboxEvent(received);
|
|
136
|
+
return {
|
|
137
|
+
disposition: "inserted",
|
|
138
|
+
execution: {
|
|
139
|
+
executionId: command.executionId,
|
|
140
|
+
command,
|
|
141
|
+
state: "received",
|
|
142
|
+
attempt: commandAttempt(command),
|
|
143
|
+
admittedAt,
|
|
144
|
+
updatedAt: admittedAt,
|
|
145
|
+
lastEventSeq: received.eventSeq,
|
|
146
|
+
pluginSnapshot,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
getExecution(executionId) {
|
|
152
|
+
const row = this.getExecutionRow(executionId);
|
|
153
|
+
return row ? this.toExecution(row) : null;
|
|
154
|
+
}
|
|
155
|
+
listExecutions() {
|
|
156
|
+
const rows = this.db
|
|
157
|
+
.prepare(`SELECT execution_id, command_json, state, attempt, admitted_at, updated_at, last_event_seq, plugin_snapshot_json
|
|
158
|
+
FROM executions
|
|
159
|
+
ORDER BY admitted_at ASC, execution_id ASC`)
|
|
160
|
+
.all();
|
|
161
|
+
return rows.map((row) => this.toExecution(row));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Changes execution state and commits the matching state event in the same
|
|
165
|
+
* transaction. Callers cannot report a durable state without a durable
|
|
166
|
+
* outbox record for it.
|
|
167
|
+
*/
|
|
168
|
+
transition(executionId, nextState, payload) {
|
|
169
|
+
return this.transaction(() => {
|
|
170
|
+
const current = this.requireExecutionRow(executionId);
|
|
171
|
+
this.assertLegalTransition(current, nextState);
|
|
172
|
+
return this.transitionRow(current, nextState, payload);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Appends a non-state runtime event supplied by the caller. If no sequence is
|
|
177
|
+
* supplied, this store allocates the next sequence. Explicit sequences are
|
|
178
|
+
* accepted only when they are the next sequence, preventing acknowledgement
|
|
179
|
+
* watermarks from skipping an event.
|
|
180
|
+
*/
|
|
181
|
+
appendEvent(event) {
|
|
182
|
+
if (event.type !== "progress") {
|
|
183
|
+
throw new TypeError("Only progress events may be appended directly; state events must use transition");
|
|
184
|
+
}
|
|
185
|
+
return this.transaction(() => {
|
|
186
|
+
const current = this.requireExecutionRow(event.executionId);
|
|
187
|
+
const eventSeq = event.eventSeq ?? current.last_event_seq + 1;
|
|
188
|
+
if (!Number.isSafeInteger(eventSeq) ||
|
|
189
|
+
eventSeq !== current.last_event_seq + 1) {
|
|
190
|
+
throw new RangeError(`Event sequence for ${event.executionId} must be ${current.last_event_seq + 1}`);
|
|
191
|
+
}
|
|
192
|
+
const storedEvent = { ...event, eventSeq };
|
|
193
|
+
this.assertValidEvent(storedEvent);
|
|
194
|
+
this.insertOutboxEvent(storedEvent);
|
|
195
|
+
this.db
|
|
196
|
+
.prepare(`UPDATE executions
|
|
197
|
+
SET last_event_seq = ?, updated_at = ?
|
|
198
|
+
WHERE execution_id = ?`)
|
|
199
|
+
.run(storedEvent.eventSeq, now(), storedEvent.executionId);
|
|
200
|
+
return storedEvent;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
listUnackedEvents(executionId) {
|
|
204
|
+
const rows = executionId
|
|
205
|
+
? this.db
|
|
206
|
+
.prepare(`SELECT event_json FROM outbox
|
|
207
|
+
WHERE execution_id = ?
|
|
208
|
+
ORDER BY event_seq ASC`)
|
|
209
|
+
.all(executionId)
|
|
210
|
+
: this.db
|
|
211
|
+
.prepare(`SELECT event_json FROM outbox
|
|
212
|
+
ORDER BY execution_id ASC, event_seq ASC`)
|
|
213
|
+
.all();
|
|
214
|
+
return rows.map(({ event_json: eventJson }) => this.parseStoredEvent(eventJson));
|
|
215
|
+
}
|
|
216
|
+
/** Deletes only events at or below the Hub's acknowledgement watermark. */
|
|
217
|
+
acknowledge(executionId, eventSeqWatermark) {
|
|
218
|
+
if (!Number.isSafeInteger(eventSeqWatermark) || eventSeqWatermark < 0) {
|
|
219
|
+
throw new RangeError("Acknowledgement watermark must be a non-negative safe integer");
|
|
220
|
+
}
|
|
221
|
+
const result = this.db
|
|
222
|
+
.prepare(`DELETE FROM outbox
|
|
223
|
+
WHERE execution_id = ? AND event_seq <= ?`)
|
|
224
|
+
.run(executionId, eventSeqWatermark);
|
|
225
|
+
return Number(result.changes);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* On daemon boot, no in-process runner can be trusted to still exist. Mark
|
|
229
|
+
* every persisted running execution (or one selected execution) as needing
|
|
230
|
+
* recovery and enqueue a matching state event.
|
|
231
|
+
*/
|
|
232
|
+
markRecoveryRequired(executionId) {
|
|
233
|
+
return this.transaction(() => {
|
|
234
|
+
const rows = executionId
|
|
235
|
+
? this.db
|
|
236
|
+
.prepare(`SELECT execution_id, command_json, state, attempt, admitted_at, updated_at, last_event_seq, plugin_snapshot_json
|
|
237
|
+
FROM executions
|
|
238
|
+
WHERE execution_id = ? AND state = 'running'`)
|
|
239
|
+
.all(executionId)
|
|
240
|
+
: this.db
|
|
241
|
+
.prepare(`SELECT execution_id, command_json, state, attempt, admitted_at, updated_at, last_event_seq, plugin_snapshot_json
|
|
242
|
+
FROM executions
|
|
243
|
+
WHERE state = 'running'
|
|
244
|
+
ORDER BY admitted_at ASC, execution_id ASC`)
|
|
245
|
+
.all();
|
|
246
|
+
return rows.map((row) => this.transitionRow(row, "recovery_required"));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
initialize() {
|
|
250
|
+
this.transaction(() => {
|
|
251
|
+
this.db.exec(`
|
|
252
|
+
CREATE TABLE IF NOT EXISTS executions (
|
|
253
|
+
execution_id TEXT PRIMARY KEY,
|
|
254
|
+
command_json TEXT NOT NULL,
|
|
255
|
+
state TEXT NOT NULL,
|
|
256
|
+
attempt INTEGER NOT NULL,
|
|
257
|
+
admitted_at TEXT NOT NULL,
|
|
258
|
+
updated_at TEXT NOT NULL,
|
|
259
|
+
last_event_seq INTEGER NOT NULL DEFAULT 0,
|
|
260
|
+
plugin_snapshot_json TEXT NOT NULL DEFAULT '[]'
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
CREATE TABLE IF NOT EXISTS outbox (
|
|
264
|
+
execution_id TEXT NOT NULL,
|
|
265
|
+
event_seq INTEGER NOT NULL,
|
|
266
|
+
event_json TEXT NOT NULL,
|
|
267
|
+
PRIMARY KEY (execution_id, event_seq)
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
CREATE TABLE IF NOT EXISTS plugin_states (
|
|
271
|
+
plugin_id TEXT PRIMARY KEY,
|
|
272
|
+
plugin_json TEXT NOT NULL,
|
|
273
|
+
active_json TEXT
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
CREATE TABLE IF NOT EXISTS plugin_sync_state (
|
|
277
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
278
|
+
revision TEXT NOT NULL,
|
|
279
|
+
synced_at TEXT NOT NULL
|
|
280
|
+
);
|
|
281
|
+
`);
|
|
282
|
+
const columns = this.db
|
|
283
|
+
.prepare("PRAGMA table_info(executions)")
|
|
284
|
+
.all();
|
|
285
|
+
if (!columns.some((column) => column.name === "plugin_snapshot_json")) {
|
|
286
|
+
this.db.exec("ALTER TABLE executions ADD COLUMN plugin_snapshot_json TEXT NOT NULL DEFAULT '[]'");
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
transaction(fn) {
|
|
291
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
292
|
+
try {
|
|
293
|
+
const result = fn();
|
|
294
|
+
this.db.exec("COMMIT");
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
this.db.exec("ROLLBACK");
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
getExecutionRow(executionId) {
|
|
303
|
+
return (this.db
|
|
304
|
+
.prepare(`SELECT execution_id, command_json, state, attempt, admitted_at, updated_at, last_event_seq, plugin_snapshot_json
|
|
305
|
+
FROM executions
|
|
306
|
+
WHERE execution_id = ?`)
|
|
307
|
+
.get(executionId) ?? null);
|
|
308
|
+
}
|
|
309
|
+
requireExecutionRow(executionId) {
|
|
310
|
+
const row = this.getExecutionRow(executionId);
|
|
311
|
+
if (!row)
|
|
312
|
+
throw new Error(`Unknown execution ${executionId}`);
|
|
313
|
+
return row;
|
|
314
|
+
}
|
|
315
|
+
toExecution(row) {
|
|
316
|
+
if (!isExecutionState(row.state)) {
|
|
317
|
+
throw new TypeError(`Stored execution ${row.execution_id} has invalid state ${row.state}`);
|
|
318
|
+
}
|
|
319
|
+
const command = parseClientCommand(JSON.parse(row.command_json));
|
|
320
|
+
if (!command) {
|
|
321
|
+
throw new TypeError(`Stored execution ${row.execution_id} has an invalid command`);
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
executionId: row.execution_id,
|
|
325
|
+
command,
|
|
326
|
+
state: row.state,
|
|
327
|
+
attempt: row.attempt,
|
|
328
|
+
admittedAt: row.admitted_at,
|
|
329
|
+
updatedAt: row.updated_at,
|
|
330
|
+
lastEventSeq: row.last_event_seq,
|
|
331
|
+
pluginSnapshot: parsePluginSnapshot(row.plugin_snapshot_json),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
getLastPluginSyncRevision() {
|
|
335
|
+
const row = this.db
|
|
336
|
+
.prepare("SELECT revision FROM plugin_sync_state WHERE singleton = 1")
|
|
337
|
+
.get();
|
|
338
|
+
return row?.revision ?? null;
|
|
339
|
+
}
|
|
340
|
+
recordPluginSyncSuccess(revision) {
|
|
341
|
+
if (typeof revision !== "string" || revision.trim().length === 0) {
|
|
342
|
+
throw new TypeError("Plugin sync revision must be a nonempty string");
|
|
343
|
+
}
|
|
344
|
+
this.db
|
|
345
|
+
.prepare(`INSERT INTO plugin_sync_state (singleton, revision, synced_at)
|
|
346
|
+
VALUES (1, ?, ?)
|
|
347
|
+
ON CONFLICT(singleton) DO UPDATE SET revision = excluded.revision, synced_at = excluded.synced_at`)
|
|
348
|
+
.run(revision, now());
|
|
349
|
+
}
|
|
350
|
+
listPluginStates() {
|
|
351
|
+
const rows = this.db
|
|
352
|
+
.prepare("SELECT plugin_json, active_json FROM plugin_states ORDER BY plugin_id ASC")
|
|
353
|
+
.all();
|
|
354
|
+
return rows.map((row) => ({
|
|
355
|
+
plugin: parseInstalledPlugin(row.plugin_json),
|
|
356
|
+
active: row.active_json ? parseInstalledPlugin(row.active_json) : null,
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
359
|
+
savePluginState(state) {
|
|
360
|
+
assertInstalledPlugin(state.plugin);
|
|
361
|
+
if (state.active)
|
|
362
|
+
assertInstalledPlugin(state.active);
|
|
363
|
+
this.db
|
|
364
|
+
.prepare(`INSERT INTO plugin_states (plugin_id, plugin_json, active_json)
|
|
365
|
+
VALUES (?, ?, ?)
|
|
366
|
+
ON CONFLICT(plugin_id) DO UPDATE SET
|
|
367
|
+
plugin_json = excluded.plugin_json,
|
|
368
|
+
active_json = excluded.active_json`)
|
|
369
|
+
.run(state.plugin.id, JSON.stringify(state.plugin), state.active ? JSON.stringify(state.active) : null);
|
|
370
|
+
}
|
|
371
|
+
assertLegalTransition(current, nextState) {
|
|
372
|
+
if (!isExecutionState(current.state)) {
|
|
373
|
+
throw new TypeError(`Stored execution ${current.execution_id} has invalid state ${current.state}`);
|
|
374
|
+
}
|
|
375
|
+
if (!LEGAL_TRANSITIONS[current.state].includes(nextState)) {
|
|
376
|
+
throw new Error(`Cannot transition execution ${current.execution_id} from ${current.state} to ${nextState}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
transitionRow(current, nextState, payload) {
|
|
380
|
+
const occurredAt = now();
|
|
381
|
+
const event = {
|
|
382
|
+
executionId: current.execution_id,
|
|
383
|
+
eventSeq: current.last_event_seq + 1,
|
|
384
|
+
type: nextState,
|
|
385
|
+
occurredAt,
|
|
386
|
+
};
|
|
387
|
+
if (payload)
|
|
388
|
+
event.payload = payload;
|
|
389
|
+
this.db
|
|
390
|
+
.prepare(`UPDATE executions
|
|
391
|
+
SET state = ?, updated_at = ?, last_event_seq = ?
|
|
392
|
+
WHERE execution_id = ?`)
|
|
393
|
+
.run(nextState, occurredAt, event.eventSeq, current.execution_id);
|
|
394
|
+
this.insertOutboxEvent(event);
|
|
395
|
+
return event;
|
|
396
|
+
}
|
|
397
|
+
insertOutboxEvent(event) {
|
|
398
|
+
this.db
|
|
399
|
+
.prepare(`INSERT INTO outbox (execution_id, event_seq, event_json)
|
|
400
|
+
VALUES (?, ?, ?)`)
|
|
401
|
+
.run(event.executionId, event.eventSeq, JSON.stringify(event));
|
|
402
|
+
}
|
|
403
|
+
parseStoredEvent(eventJson) {
|
|
404
|
+
const parsed = parseClientEventBatch({
|
|
405
|
+
type: "event.push",
|
|
406
|
+
events: [JSON.parse(eventJson)],
|
|
407
|
+
});
|
|
408
|
+
if (!parsed) {
|
|
409
|
+
throw new TypeError("Stored outbox event is invalid");
|
|
410
|
+
}
|
|
411
|
+
return parsed[0];
|
|
412
|
+
}
|
|
413
|
+
assertValidEvent(event) {
|
|
414
|
+
if (!parseClientEventBatch({
|
|
415
|
+
type: "event.push",
|
|
416
|
+
events: [event],
|
|
417
|
+
})) {
|
|
418
|
+
throw new TypeError("Cannot append an invalid client event");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=state-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.js","sourceRoot":"","sources":["../../src/client/state-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQtE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU;IACV,mBAAmB;IACnB,SAAS;IACT,UAAU;IACV,MAAM;IACN,QAAQ;IACR,WAAW;IACX,mBAAmB;CACX,CAAC;AAgDX,MAAM,iBAAiB,GAEnB;IACF,QAAQ,EAAE,CAAC,mBAAmB,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC;IACnE,iBAAiB,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC;IACvD,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,mBAAmB,CAAC;IAC7D,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,EAAE;IACb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118 @@
|
|
|
1
|
+
import { ClientStateStore } from "./state-store.js";
|
|
2
|
+
import type { ClientCommand } from "./types.js";
|
|
3
|
+
import type { ClientTransport } from "./transport.js";
|
|
4
|
+
import type { ActivePluginSnapshot, InstalledPlugin, PluginConfig } from "../plugins/types.js";
|
|
5
|
+
import { type LocalContextSource } from "../capabilities/context.js";
|
|
6
|
+
import { type CapabilityLocalPolicy } from "../capabilities/policy.js";
|
|
7
|
+
import type { CapabilityEvent } from "../capabilities/shell-wire.js";
|
|
8
|
+
import type { ShellCapability } from "../capabilities/types.js";
|
|
9
|
+
import type { RunnerManager } from "../runtime/types.js";
|
|
10
|
+
type AgentRunCommand = Extract<ClientCommand, {
|
|
11
|
+
kind: "agent.run";
|
|
12
|
+
}>;
|
|
13
|
+
type CapabilityInvokeCommand = Extract<ClientCommand, {
|
|
14
|
+
kind: "capability.invoke";
|
|
15
|
+
}>;
|
|
16
|
+
export declare const LOCAL_POLICY_DECISIONS: readonly ["auto", "approval", "deny"];
|
|
17
|
+
export type LocalPolicyDecision = (typeof LOCAL_POLICY_DECISIONS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* The local daemon decides whether an admitted remote run may launch. The
|
|
20
|
+
* default is deny: receiving a Hub command must not implicitly execute an
|
|
21
|
+
* agent until a local policy has been deliberately configured.
|
|
22
|
+
*/
|
|
23
|
+
export type LocalPolicy = (command: AgentRunCommand) => LocalPolicyDecision | Promise<LocalPolicyDecision>;
|
|
24
|
+
export type ClientSupervisorOptions = {
|
|
25
|
+
store: ClientStateStore;
|
|
26
|
+
transport: ClientTransport;
|
|
27
|
+
runner: RunnerManager;
|
|
28
|
+
/** Maximum simultaneous local executions. Overflow is durably rejected. */
|
|
29
|
+
maxConcurrentRuns?: number;
|
|
30
|
+
policy?: LocalPolicy;
|
|
31
|
+
plugins?: PluginManagerPort;
|
|
32
|
+
capabilityHost?: CapabilityHostPort;
|
|
33
|
+
capabilityPolicy?: CapabilityLocalPolicy;
|
|
34
|
+
capabilityContext?: CapabilityContextResolver;
|
|
35
|
+
};
|
|
36
|
+
export type PluginManagerPort = {
|
|
37
|
+
sync(desired: PluginConfig[]): Promise<InstalledPlugin[]>;
|
|
38
|
+
snapshotActivePlugins(runtime?: AgentRunCommand["runtime"]): ActivePluginSnapshot[];
|
|
39
|
+
};
|
|
40
|
+
/** A locally validated capability plus the exact immutable plugin root it owns. */
|
|
41
|
+
export type ResolvedActiveCapability = {
|
|
42
|
+
plugin: InstalledPlugin;
|
|
43
|
+
capability: ShellCapability;
|
|
44
|
+
pluginRoot: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The Supervisor only knows how to resolve an active, local declaration and
|
|
48
|
+
* consume structured events. It cannot name an executable or provide argv.
|
|
49
|
+
*/
|
|
50
|
+
export type CapabilityHostPort = {
|
|
51
|
+
resolveActiveCapability(capabilityId: string): Promise<ResolvedActiveCapability | null>;
|
|
52
|
+
invoke(resolved: ResolvedActiveCapability, input: unknown, context: Record<string, unknown>, signal: AbortSignal): AsyncIterable<CapabilityEvent>;
|
|
53
|
+
};
|
|
54
|
+
/** Supplies only local metadata. Hub command fields are never spread into it. */
|
|
55
|
+
export type CapabilityContextResolver = (command: CapabilityInvokeCommand, resolved: ResolvedActiveCapability) => LocalContextSource;
|
|
56
|
+
/**
|
|
57
|
+
* Coordinates durable task admission, local execution policy, and outbox
|
|
58
|
+
* delivery. Vendor runtimes and shell hosts remain outside this class.
|
|
59
|
+
*/
|
|
60
|
+
export declare class ClientSupervisor {
|
|
61
|
+
private readonly options;
|
|
62
|
+
private readonly policy;
|
|
63
|
+
private readonly capabilityContext;
|
|
64
|
+
private readonly maxConcurrentRuns;
|
|
65
|
+
private readonly pluginSyncInFlight;
|
|
66
|
+
private readonly capabilityAbortControllers;
|
|
67
|
+
private readonly runnerConsumptionTasks;
|
|
68
|
+
private readonly capabilityConsumptionTasks;
|
|
69
|
+
private started;
|
|
70
|
+
private shuttingDown;
|
|
71
|
+
constructor(options: ClientSupervisorOptions);
|
|
72
|
+
start(): Promise<void>;
|
|
73
|
+
stop(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Service shutdown has a stricter lifecycle than an ordinary transport
|
|
76
|
+
* disconnect: persist cancellation and signal every locally owned child
|
|
77
|
+
* before the socket and state store are released.
|
|
78
|
+
*/
|
|
79
|
+
shutdown(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Approval only resumes the exact persisted structured command. It never
|
|
82
|
+
* accepts a replacement command, entrypoint, or argument vector.
|
|
83
|
+
*/
|
|
84
|
+
approve(executionId: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Pushes durable outbox rows and removes only the watermark each execution
|
|
87
|
+
* actually received. A failed push does not touch local state, so reconnect
|
|
88
|
+
* replay remains possible.
|
|
89
|
+
*/
|
|
90
|
+
flush(): Promise<void>;
|
|
91
|
+
private handleCommand;
|
|
92
|
+
private decide;
|
|
93
|
+
private handleCapabilityCommand;
|
|
94
|
+
private startApprovedCapability;
|
|
95
|
+
private resolveActiveCapability;
|
|
96
|
+
private validateCapabilityInput;
|
|
97
|
+
private startPersistedCapability;
|
|
98
|
+
private consumeCapabilityEvents;
|
|
99
|
+
/**
|
|
100
|
+
* Plugin desired state is independent of task admission. A failure records no
|
|
101
|
+
* successful revision, reports a typed rejection if the transport supports
|
|
102
|
+
* it, and deliberately leaves all in-flight runners untouched.
|
|
103
|
+
*/
|
|
104
|
+
private handlePluginSync;
|
|
105
|
+
private syncPluginRevision;
|
|
106
|
+
private reportPluginSync;
|
|
107
|
+
private startPersistedAgentRun;
|
|
108
|
+
private cancelActiveExecution;
|
|
109
|
+
private consumeRunnerEvents;
|
|
110
|
+
private hasCapacity;
|
|
111
|
+
private trackConsumptionTask;
|
|
112
|
+
private waitForConsumptionTasks;
|
|
113
|
+
private appendProgressIfRunning;
|
|
114
|
+
private transitionRunningExecution;
|
|
115
|
+
private requireExecution;
|
|
116
|
+
}
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMapping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