@namzu/cli 23.0.0 → 25.0.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/CHANGELOG.md +845 -0
- package/README.md +13 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +18 -10
- package/dist/cli.js.map +1 -1
- package/dist/commands/drain.d.ts +0 -23
- package/dist/commands/drain.d.ts.map +1 -1
- package/dist/commands/drain.js +23 -9
- package/dist/commands/drain.js.map +1 -1
- package/dist/commands/resident-flags.d.ts +24 -0
- package/dist/commands/resident-flags.d.ts.map +1 -0
- package/dist/commands/resident-flags.js +191 -0
- package/dist/commands/resident-flags.js.map +1 -0
- package/dist/commands/resident-learning.d.ts +6 -0
- package/dist/commands/resident-learning.d.ts.map +1 -0
- package/dist/commands/resident-learning.js +293 -0
- package/dist/commands/resident-learning.js.map +1 -0
- package/dist/commands/resident.d.ts +20 -0
- package/dist/commands/resident.d.ts.map +1 -0
- package/dist/commands/resident.js +418 -0
- package/dist/commands/resident.js.map +1 -0
- package/dist/commands/run-flags.d.ts +2 -2
- package/dist/commands/run-flags.d.ts.map +1 -1
- package/dist/commands/run-flags.js +6 -6
- package/dist/commands/run-flags.js.map +1 -1
- package/dist/commands/run-stream.d.ts.map +1 -1
- package/dist/commands/run-stream.js +9 -10
- package/dist/commands/run-stream.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +3 -2
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/upgrade.d.ts +1 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +6 -3
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +27 -4
- package/dist/config/load.js.map +1 -1
- package/dist/config/run-limits.d.ts +11 -0
- package/dist/config/run-limits.d.ts.map +1 -0
- package/dist/config/run-limits.js +64 -0
- package/dist/config/run-limits.js.map +1 -0
- package/dist/config/schema.d.ts +12 -4
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/context/runtime-message.d.ts.map +1 -1
- package/dist/context/runtime-message.js +2 -0
- package/dist/context/runtime-message.js.map +1 -1
- package/dist/integrations/npm-invocation.d.ts +10 -0
- package/dist/integrations/npm-invocation.d.ts.map +1 -0
- package/dist/integrations/npm-invocation.js +23 -0
- package/dist/integrations/npm-invocation.js.map +1 -0
- package/dist/integrations/plugins/runtime.d.ts +19 -1
- package/dist/integrations/plugins/runtime.d.ts.map +1 -1
- package/dist/integrations/plugins/runtime.js +89 -1
- package/dist/integrations/plugins/runtime.js.map +1 -1
- package/dist/integrations/plugins/settings.d.ts +15 -0
- package/dist/integrations/plugins/settings.d.ts.map +1 -0
- package/dist/integrations/plugins/settings.js +106 -0
- package/dist/integrations/plugins/settings.js.map +1 -0
- package/dist/integrations/providers/credential-store.d.ts +8 -7
- package/dist/integrations/providers/credential-store.d.ts.map +1 -1
- package/dist/integrations/providers/credential-store.js +44 -17
- package/dist/integrations/providers/credential-store.js.map +1 -1
- package/dist/integrations/providers/discover.d.ts.map +1 -1
- package/dist/integrations/providers/discover.js +7 -2
- package/dist/integrations/providers/discover.js.map +1 -1
- package/dist/integrations/providers/harness-credentials.d.ts +2 -2
- package/dist/integrations/providers/harness-credentials.d.ts.map +1 -1
- package/dist/integrations/providers/harness-credentials.js +13 -8
- package/dist/integrations/providers/harness-credentials.js.map +1 -1
- package/dist/integrations/providers/setup.d.ts.map +1 -1
- package/dist/integrations/providers/setup.js +52 -5
- package/dist/integrations/providers/setup.js.map +1 -1
- package/dist/integrations/resident/foreground.d.ts +19 -0
- package/dist/integrations/resident/foreground.d.ts.map +1 -0
- package/dist/integrations/resident/foreground.js +95 -0
- package/dist/integrations/resident/foreground.js.map +1 -0
- package/dist/integrations/resident/inspection.d.ts +10 -0
- package/dist/integrations/resident/inspection.d.ts.map +1 -0
- package/dist/integrations/resident/inspection.js +263 -0
- package/dist/integrations/resident/inspection.js.map +1 -0
- package/dist/integrations/resident/learning-sources.d.ts +4 -0
- package/dist/integrations/resident/learning-sources.d.ts.map +1 -0
- package/dist/integrations/resident/learning-sources.js +79 -0
- package/dist/integrations/resident/learning-sources.js.map +1 -0
- package/dist/integrations/resident/learning-storage.d.ts +5 -0
- package/dist/integrations/resident/learning-storage.d.ts.map +1 -0
- package/dist/integrations/resident/learning-storage.js +51 -0
- package/dist/integrations/resident/learning-storage.js.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts +9 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.js +15 -0
- package/dist/integrations/resident/lifecycle-errors.js.map +1 -0
- package/dist/integrations/resident/owned-runner.d.ts +17 -0
- package/dist/integrations/resident/owned-runner.d.ts.map +1 -0
- package/dist/integrations/resident/owned-runner.js +91 -0
- package/dist/integrations/resident/owned-runner.js.map +1 -0
- package/dist/integrations/resident/runner-control.d.ts +47 -0
- package/dist/integrations/resident/runner-control.d.ts.map +1 -0
- package/dist/integrations/resident/runner-control.js +238 -0
- package/dist/integrations/resident/runner-control.js.map +1 -0
- package/dist/integrations/resident/runner-launch.d.ts +52 -0
- package/dist/integrations/resident/runner-launch.d.ts.map +1 -0
- package/dist/integrations/resident/runner-launch.js +142 -0
- package/dist/integrations/resident/runner-launch.js.map +1 -0
- package/dist/integrations/resident/runner-store.d.ts +44 -0
- package/dist/integrations/resident/runner-store.d.ts.map +1 -0
- package/dist/integrations/resident/runner-store.js +281 -0
- package/dist/integrations/resident/runner-store.js.map +1 -0
- package/dist/integrations/resident/runner-worker.d.ts +2 -0
- package/dist/integrations/resident/runner-worker.d.ts.map +1 -0
- package/dist/integrations/resident/runner-worker.js +146 -0
- package/dist/integrations/resident/runner-worker.js.map +1 -0
- package/dist/integrations/resident/session-step.d.ts +29 -0
- package/dist/integrations/resident/session-step.d.ts.map +1 -0
- package/dist/integrations/resident/session-step.js +462 -0
- package/dist/integrations/resident/session-step.js.map +1 -0
- package/dist/integrations/resident/storage.d.ts +17 -0
- package/dist/integrations/resident/storage.d.ts.map +1 -0
- package/dist/integrations/resident/storage.js +140 -0
- package/dist/integrations/resident/storage.js.map +1 -0
- package/dist/integrations/resident/tool-evidence.d.ts +6 -0
- package/dist/integrations/resident/tool-evidence.d.ts.map +1 -0
- package/dist/integrations/resident/tool-evidence.js +117 -0
- package/dist/integrations/resident/tool-evidence.js.map +1 -0
- package/dist/integrations/resident/verification.d.ts +11 -0
- package/dist/integrations/resident/verification.d.ts.map +1 -0
- package/dist/integrations/resident/verification.js +109 -0
- package/dist/integrations/resident/verification.js.map +1 -0
- package/dist/integrations/sessions/compaction-evidence.d.ts +5 -0
- package/dist/integrations/sessions/compaction-evidence.d.ts.map +1 -0
- package/dist/integrations/sessions/compaction-evidence.js +59 -0
- package/dist/integrations/sessions/compaction-evidence.js.map +1 -0
- package/dist/integrations/sessions/context-inventory.js +1 -1
- package/dist/integrations/sessions/context-inventory.js.map +1 -1
- package/dist/integrations/sessions/conversation-search.d.ts +56 -8
- package/dist/integrations/sessions/conversation-search.d.ts.map +1 -1
- package/dist/integrations/sessions/conversation-search.js +600 -63
- package/dist/integrations/sessions/conversation-search.js.map +1 -1
- package/dist/integrations/sessions/database.d.ts +5 -0
- package/dist/integrations/sessions/database.d.ts.map +1 -0
- package/dist/integrations/sessions/database.js +34 -0
- package/dist/integrations/sessions/database.js.map +1 -0
- package/dist/integrations/sessions/evidence-page-validation.d.ts +8 -0
- package/dist/integrations/sessions/evidence-page-validation.d.ts.map +1 -0
- package/dist/integrations/sessions/evidence-page-validation.js +74 -0
- package/dist/integrations/sessions/evidence-page-validation.js.map +1 -0
- package/dist/integrations/sessions/evidence-recall.d.ts +5 -0
- package/dist/integrations/sessions/evidence-recall.d.ts.map +1 -0
- package/dist/integrations/sessions/evidence-recall.js +173 -0
- package/dist/integrations/sessions/evidence-recall.js.map +1 -0
- package/dist/integrations/sessions/paths.d.ts +7 -0
- package/dist/integrations/sessions/paths.d.ts.map +1 -0
- package/dist/integrations/sessions/paths.js +14 -0
- package/dist/integrations/sessions/paths.js.map +1 -0
- package/dist/integrations/sessions/run-discovery.d.ts +24 -0
- package/dist/integrations/sessions/run-discovery.d.ts.map +1 -0
- package/dist/integrations/sessions/run-discovery.js +142 -0
- package/dist/integrations/sessions/run-discovery.js.map +1 -0
- package/dist/integrations/sessions/store.d.ts +8 -18
- package/dist/integrations/sessions/store.d.ts.map +1 -1
- package/dist/integrations/sessions/store.js +14 -39
- package/dist/integrations/sessions/store.js.map +1 -1
- package/dist/integrations/sessions/transcript-export.d.ts +0 -1
- package/dist/integrations/sessions/transcript-export.d.ts.map +1 -1
- package/dist/integrations/sessions/transcript-export.js +3 -2
- package/dist/integrations/sessions/transcript-export.js.map +1 -1
- package/dist/integrations/sessions/turn-evidence.d.ts +0 -9
- package/dist/integrations/sessions/turn-evidence.d.ts.map +1 -1
- package/dist/integrations/sessions/turn-evidence.js +5 -2
- package/dist/integrations/sessions/turn-evidence.js.map +1 -1
- package/dist/integrations/state/private-directory.d.ts +4 -2
- package/dist/integrations/state/private-directory.d.ts.map +1 -1
- package/dist/integrations/state/private-directory.js +6 -4
- package/dist/integrations/state/private-directory.js.map +1 -1
- package/dist/integrations/state/report.d.ts.map +1 -1
- package/dist/integrations/state/report.js +78 -21
- package/dist/integrations/state/report.js.map +1 -1
- package/dist/integrations/subagents/parent.d.ts +3 -2
- package/dist/integrations/subagents/parent.d.ts.map +1 -1
- package/dist/integrations/subagents/parent.js +11 -6
- package/dist/integrations/subagents/parent.js.map +1 -1
- package/dist/integrations/subagents/policy.d.ts +2 -5
- package/dist/integrations/subagents/policy.d.ts.map +1 -1
- package/dist/integrations/subagents/policy.js +2 -5
- package/dist/integrations/subagents/policy.js.map +1 -1
- package/dist/integrations/subagents/runtime.d.ts +7 -0
- package/dist/integrations/subagents/runtime.d.ts.map +1 -1
- package/dist/integrations/subagents/runtime.js +9 -7
- package/dist/integrations/subagents/runtime.js.map +1 -1
- package/dist/permissions/rules.d.ts +2 -8
- package/dist/permissions/rules.d.ts.map +1 -1
- package/dist/permissions/rules.js +19 -10
- package/dist/permissions/rules.js.map +1 -1
- package/dist/tui/App.d.ts +0 -12
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +235 -15
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/ChoicePicker.d.ts +2 -1
- package/dist/tui/ChoicePicker.d.ts.map +1 -1
- package/dist/tui/ChoicePicker.js +10 -8
- package/dist/tui/ChoicePicker.js.map +1 -1
- package/dist/tui/ToolOutputViewer.js +1 -1
- package/dist/tui/ToolOutputViewer.js.map +1 -1
- package/dist/tui/agent.d.ts +29 -3
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/agent.js +233 -46
- package/dist/tui/agent.js.map +1 -1
- package/dist/tui/conversation-evidence-view.d.ts +6 -0
- package/dist/tui/conversation-evidence-view.d.ts.map +1 -0
- package/dist/tui/conversation-evidence-view.js +96 -0
- package/dist/tui/conversation-evidence-view.js.map +1 -0
- package/dist/tui/conversation-history.d.ts +3 -1
- package/dist/tui/conversation-history.d.ts.map +1 -1
- package/dist/tui/conversation-history.js +16 -1
- package/dist/tui/conversation-history.js.map +1 -1
- package/dist/tui/exit-summary.d.ts +1 -1
- package/dist/tui/exit-summary.d.ts.map +1 -1
- package/dist/tui/exit-summary.js +17 -5
- package/dist/tui/exit-summary.js.map +1 -1
- package/dist/tui/markdownParser.d.ts.map +1 -1
- package/dist/tui/markdownParser.js +2 -1
- package/dist/tui/markdownParser.js.map +1 -1
- package/dist/tui/plugin-view.d.ts +9 -0
- package/dist/tui/plugin-view.d.ts.map +1 -0
- package/dist/tui/plugin-view.js +59 -0
- package/dist/tui/plugin-view.js.map +1 -0
- package/dist/tui/run-interruption.d.ts +2 -2
- package/dist/tui/run-interruption.d.ts.map +1 -1
- package/dist/tui/run-interruption.js +5 -1
- package/dist/tui/run-interruption.js.map +1 -1
- package/dist/tui/run-limits-settings.d.ts +39 -0
- package/dist/tui/run-limits-settings.d.ts.map +1 -0
- package/dist/tui/run-limits-settings.js +88 -0
- package/dist/tui/run-limits-settings.js.map +1 -0
- package/dist/tui/slashCommands.d.ts +6 -1
- package/dist/tui/slashCommands.d.ts.map +1 -1
- package/dist/tui/slashCommands.js +40 -9
- package/dist/tui/slashCommands.js.map +1 -1
- package/dist/tui/types.d.ts +4 -2
- package/dist/tui/types.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
declare const PHASES: readonly ["starting", "idle", "working", "stopping"];
|
|
2
|
+
export type RunnerControlPhase = (typeof PHASES)[number];
|
|
3
|
+
export type RunnerControlAction = 'status' | 'stop';
|
|
4
|
+
export interface RunnerControlStatus {
|
|
5
|
+
readonly pid: number;
|
|
6
|
+
readonly phase: RunnerControlPhase;
|
|
7
|
+
/** Callback entries admitted by this runner, independent of final settlement. */
|
|
8
|
+
readonly stepsStarted: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RunnerControlServerOptions {
|
|
11
|
+
readonly instanceId: string;
|
|
12
|
+
readonly token: string;
|
|
13
|
+
readonly getStatus: () => RunnerControlStatus;
|
|
14
|
+
/** Signal owned work once. A response acknowledges this request, not drainage. */
|
|
15
|
+
readonly onStop: () => void;
|
|
16
|
+
}
|
|
17
|
+
export interface RunnerControlServer {
|
|
18
|
+
readonly port: number;
|
|
19
|
+
/** Refuse new clients and destroy remaining sockets before resolving. */
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface RunnerControlRecord {
|
|
23
|
+
readonly instanceId: string;
|
|
24
|
+
readonly token: string;
|
|
25
|
+
readonly port: number | null;
|
|
26
|
+
readonly pid: number | null;
|
|
27
|
+
}
|
|
28
|
+
export type RunnerControlResult = ({
|
|
29
|
+
readonly kind: 'responsive';
|
|
30
|
+
readonly instanceId: string;
|
|
31
|
+
readonly stopRequested: boolean;
|
|
32
|
+
} & RunnerControlStatus) | {
|
|
33
|
+
readonly kind: 'unresponsive';
|
|
34
|
+
/** No observation here establishes that the process is dead. */
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* One private, local control endpoint. Authentication is bound to an immutable
|
|
39
|
+
* runner instance, never to a PID alone. No request runs tools or shell commands.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createRunnerControlServer(options: RunnerControlServerOptions): Promise<RunnerControlServer>;
|
|
42
|
+
/** An authenticated response proves responsiveness; absence never proves death. */
|
|
43
|
+
export declare function queryRunner(record: RunnerControlRecord, action: RunnerControlAction, options?: {
|
|
44
|
+
readonly timeoutMs?: number;
|
|
45
|
+
}): Promise<RunnerControlResult>;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=runner-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-control.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/runner-control.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,MAAM,sDAAuD,CAAA;AAEnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AACxD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEnD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;IAClC,iFAAiF;IACjF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,mBAAmB,CAAA;IAC7C,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,yEAAyE;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,MAAM,mBAAmB,GAC5B,CAAC;IACD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;CAC9B,GAAG,mBAAmB,CAAC,GACxB;IACA,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACtB,CAAA;AA8BJ;;;GAGG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,0BAA0B,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAwH9B;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAC1B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAC3C,OAAO,CAAC,mBAAmB,CAAC,CAgF9B"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { createConnection, createServer } from 'node:net';
|
|
3
|
+
const MAX_MESSAGE_BYTES = 4_096;
|
|
4
|
+
const MAX_OPEN_SOCKETS = 16;
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 1_500;
|
|
6
|
+
const PHASES = ['starting', 'idle', 'working', 'stopping'];
|
|
7
|
+
function object(value) {
|
|
8
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function exactKeys(value, keys) {
|
|
11
|
+
const actual = Object.keys(value);
|
|
12
|
+
return actual.length === keys.length && actual.every((key) => keys.includes(key));
|
|
13
|
+
}
|
|
14
|
+
function validIdentity(instanceId, token) {
|
|
15
|
+
return (instanceId.length > 0 && instanceId.length <= 256 && token.length > 0 && token.length <= 512);
|
|
16
|
+
}
|
|
17
|
+
function validStatus(value) {
|
|
18
|
+
return (typeof value.pid === 'number' &&
|
|
19
|
+
Number.isSafeInteger(value.pid) &&
|
|
20
|
+
value.pid > 0 &&
|
|
21
|
+
typeof value.phase === 'string' &&
|
|
22
|
+
PHASES.includes(value.phase) &&
|
|
23
|
+
typeof value.stepsStarted === 'number' &&
|
|
24
|
+
Number.isSafeInteger(value.stepsStarted) &&
|
|
25
|
+
value.stepsStarted >= 0);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One private, local control endpoint. Authentication is bound to an immutable
|
|
29
|
+
* runner instance, never to a PID alone. No request runs tools or shell commands.
|
|
30
|
+
*/
|
|
31
|
+
export async function createRunnerControlServer(options) {
|
|
32
|
+
if (!validIdentity(options.instanceId, options.token))
|
|
33
|
+
throw new Error('Runner control requires a bounded instance identity and secret token.');
|
|
34
|
+
const expectedToken = Buffer.from(options.token);
|
|
35
|
+
const sockets = new Set();
|
|
36
|
+
let stopRequested = false;
|
|
37
|
+
let stopFailed = false;
|
|
38
|
+
let closing = false;
|
|
39
|
+
let closePromise;
|
|
40
|
+
const requestStop = () => {
|
|
41
|
+
if (stopRequested)
|
|
42
|
+
return;
|
|
43
|
+
stopRequested = true;
|
|
44
|
+
try {
|
|
45
|
+
options.onStop();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
stopFailed = true;
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const server = createServer((socket) => {
|
|
53
|
+
socket.on('error', () => { });
|
|
54
|
+
if (closing || sockets.size >= MAX_OPEN_SOCKETS) {
|
|
55
|
+
socket.destroy();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
sockets.add(socket);
|
|
59
|
+
socket.once('close', () => sockets.delete(socket));
|
|
60
|
+
// A total deadline, rather than an inactivity timeout a slow sender can reset.
|
|
61
|
+
const deadline = setTimeout(() => socket.destroy(), DEFAULT_TIMEOUT_MS);
|
|
62
|
+
socket.once('close', () => clearTimeout(deadline));
|
|
63
|
+
let buffered = Buffer.alloc(0);
|
|
64
|
+
let handled = false;
|
|
65
|
+
socket.on('data', (chunk) => {
|
|
66
|
+
if (handled || buffered.length + chunk.length > MAX_MESSAGE_BYTES) {
|
|
67
|
+
socket.destroy();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
buffered = Buffer.concat([buffered, chunk]);
|
|
71
|
+
const newline = buffered.indexOf(10);
|
|
72
|
+
if (newline < 0)
|
|
73
|
+
return;
|
|
74
|
+
handled = true;
|
|
75
|
+
if (newline !== buffered.length - 1) {
|
|
76
|
+
socket.destroy();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const request = JSON.parse(buffered.subarray(0, newline).toString('utf8'));
|
|
81
|
+
if (!object(request) ||
|
|
82
|
+
!exactKeys(request, ['version', 'instanceId', 'token', 'action']) ||
|
|
83
|
+
request.version !== 1 ||
|
|
84
|
+
request.instanceId !== options.instanceId ||
|
|
85
|
+
typeof request.token !== 'string' ||
|
|
86
|
+
(request.action !== 'status' && request.action !== 'stop')) {
|
|
87
|
+
socket.destroy();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const token = Buffer.from(request.token);
|
|
91
|
+
if (token.length !== expectedToken.length || !timingSafeEqual(token, expectedToken)) {
|
|
92
|
+
socket.destroy();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (request.action === 'stop')
|
|
96
|
+
requestStop();
|
|
97
|
+
if (stopFailed)
|
|
98
|
+
throw new Error('Runner stop callback failed.');
|
|
99
|
+
const state = options.getStatus();
|
|
100
|
+
if (!object(state) || !validStatus(state))
|
|
101
|
+
throw new Error('Invalid runner state.');
|
|
102
|
+
socket.end(`${JSON.stringify({
|
|
103
|
+
version: 1,
|
|
104
|
+
instanceId: options.instanceId,
|
|
105
|
+
pid: state.pid,
|
|
106
|
+
phase: stopRequested ? 'stopping' : state.phase,
|
|
107
|
+
stepsStarted: state.stepsStarted,
|
|
108
|
+
stopRequested,
|
|
109
|
+
})}\n`);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Request bytes and the secret never enter logs or error responses.
|
|
113
|
+
socket.destroy();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
const close = () => {
|
|
118
|
+
if (closePromise)
|
|
119
|
+
return closePromise;
|
|
120
|
+
closing = true;
|
|
121
|
+
closePromise = new Promise((resolve, reject) => {
|
|
122
|
+
server.close((error) => {
|
|
123
|
+
if (error && error.code !== 'ERR_SERVER_NOT_RUNNING')
|
|
124
|
+
reject(error);
|
|
125
|
+
else
|
|
126
|
+
resolve();
|
|
127
|
+
});
|
|
128
|
+
for (const socket of sockets)
|
|
129
|
+
socket.destroy();
|
|
130
|
+
});
|
|
131
|
+
return closePromise;
|
|
132
|
+
};
|
|
133
|
+
await new Promise((resolve, reject) => {
|
|
134
|
+
const failed = (error) => reject(error);
|
|
135
|
+
server.once('error', failed);
|
|
136
|
+
server.listen({ host: '127.0.0.1', port: 0, exclusive: true }, () => {
|
|
137
|
+
server.removeListener('error', failed);
|
|
138
|
+
resolve();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
// Losing the installed control endpoint stops admission through the same
|
|
142
|
+
// callback; it does not leave an uncontrolled runner claiming to be healthy.
|
|
143
|
+
server.on('error', () => {
|
|
144
|
+
try {
|
|
145
|
+
requestStop();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
/* The owner is already being stopped. */
|
|
149
|
+
}
|
|
150
|
+
void close().catch(() => { });
|
|
151
|
+
});
|
|
152
|
+
const address = server.address();
|
|
153
|
+
if (address === null || typeof address === 'string') {
|
|
154
|
+
await close();
|
|
155
|
+
throw new Error('Runner control did not acquire a loopback port.');
|
|
156
|
+
}
|
|
157
|
+
return { port: address.port, close };
|
|
158
|
+
}
|
|
159
|
+
/** An authenticated response proves responsiveness; absence never proves death. */
|
|
160
|
+
export function queryRunner(record, action, options = {}) {
|
|
161
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
162
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 60_000)
|
|
163
|
+
throw new Error('Runner control timeout must be a whole number from 1 to 60000 milliseconds.');
|
|
164
|
+
if (!validIdentity(record.instanceId, record.token) ||
|
|
165
|
+
!Number.isSafeInteger(record.port) ||
|
|
166
|
+
(record.port ?? 0) < 1 ||
|
|
167
|
+
(record.port ?? 0) > 65_535 ||
|
|
168
|
+
!Number.isSafeInteger(record.pid) ||
|
|
169
|
+
(record.pid ?? 0) < 1 ||
|
|
170
|
+
(action !== 'status' && action !== 'stop'))
|
|
171
|
+
return Promise.resolve({
|
|
172
|
+
kind: 'unresponsive',
|
|
173
|
+
reason: 'Runner control endpoint is unavailable.',
|
|
174
|
+
});
|
|
175
|
+
return new Promise((resolve) => {
|
|
176
|
+
const socket = createConnection({ host: '127.0.0.1', port: record.port });
|
|
177
|
+
let settled = false;
|
|
178
|
+
let buffered = Buffer.alloc(0);
|
|
179
|
+
const finish = (result) => {
|
|
180
|
+
if (settled)
|
|
181
|
+
return;
|
|
182
|
+
settled = true;
|
|
183
|
+
clearTimeout(deadline);
|
|
184
|
+
socket.destroy();
|
|
185
|
+
resolve(result);
|
|
186
|
+
};
|
|
187
|
+
const unresponsive = (reason) => finish({ kind: 'unresponsive', reason });
|
|
188
|
+
const deadline = setTimeout(() => unresponsive('Runner control response timed out.'), timeoutMs);
|
|
189
|
+
socket.once('error', () => unresponsive('Runner control connection failed.'));
|
|
190
|
+
socket.once('close', () => unresponsive('Runner control closed without a valid response.'));
|
|
191
|
+
socket.once('connect', () => {
|
|
192
|
+
socket.write(`${JSON.stringify({ version: 1, instanceId: record.instanceId, token: record.token, action })}\n`);
|
|
193
|
+
});
|
|
194
|
+
socket.on('data', (chunk) => {
|
|
195
|
+
if (buffered.length + chunk.length > MAX_MESSAGE_BYTES) {
|
|
196
|
+
unresponsive('Runner control response exceeded its size limit.');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
buffered = Buffer.concat([buffered, chunk]);
|
|
200
|
+
const newline = buffered.indexOf(10);
|
|
201
|
+
if (newline < 0)
|
|
202
|
+
return;
|
|
203
|
+
try {
|
|
204
|
+
const response = JSON.parse(buffered.subarray(0, newline).toString('utf8'));
|
|
205
|
+
if (newline !== buffered.length - 1 ||
|
|
206
|
+
!object(response) ||
|
|
207
|
+
!exactKeys(response, [
|
|
208
|
+
'version',
|
|
209
|
+
'instanceId',
|
|
210
|
+
'pid',
|
|
211
|
+
'phase',
|
|
212
|
+
'stepsStarted',
|
|
213
|
+
'stopRequested',
|
|
214
|
+
]) ||
|
|
215
|
+
response.version !== 1 ||
|
|
216
|
+
response.instanceId !== record.instanceId ||
|
|
217
|
+
response.pid !== record.pid ||
|
|
218
|
+
!validStatus(response) ||
|
|
219
|
+
typeof response.stopRequested !== 'boolean' ||
|
|
220
|
+
(response.stopRequested && response.phase !== 'stopping') ||
|
|
221
|
+
(action === 'stop' && !response.stopRequested))
|
|
222
|
+
throw new Error('Invalid response.');
|
|
223
|
+
finish({
|
|
224
|
+
kind: 'responsive',
|
|
225
|
+
instanceId: record.instanceId,
|
|
226
|
+
pid: response.pid,
|
|
227
|
+
phase: response.phase,
|
|
228
|
+
stepsStarted: response.stepsStarted,
|
|
229
|
+
stopRequested: response.stopRequested,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
unresponsive('Runner control returned an invalid response.');
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=runner-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-control.js","sourceRoot":"","sources":["../../../src/integrations/resident/runner-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAe,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEtE,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAC/B,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAC3B,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAChC,MAAM,MAAM,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,CAAU,CAAA;AA6CnE,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5E,CAAC;AAED,SAAS,SAAS,CAAC,KAA8B,EAAE,IAAuB;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjC,OAAO,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;AAClF,CAAC;AAED,SAAS,aAAa,CAAC,UAAkB,EAAE,KAAa;IACvD,OAAO,CACN,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAC5F,CAAA;AACF,CAAC;AAED,SA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AAC,UAAU;oBACzC,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG;oBAC3B,CAAC,WAAW,CAAC,QAAQ,CAAC;oBACtB,OAAO,QAAQ,CAAC,aAAa,KAAK,SAAS;oBAC3C,CAAC,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,KAAK,KAAK,UAAU,CAAC;oBACzD,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;oBAE9C,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;gBACrC,MAAM,CAAC;oBACN,IAAI,EAAE,YAAY;oBAClB,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,GAAG,EAAE,QAAQ,CAAC,GAAa;oBAC3B,KAAK,EAAE,QAAQ,CAAC,KAA2B;oBAC3C,YAAY,EAAE,QAAQ,CAAC,YAAsB;oBAC7C,aAAa,EAAE,QAAQ,CAAC,aAAa;iBACrC,CAAC,CAAA;YACH,CAAC;YAAC,MAAM,CAAC;gBACR,YAAY,CAAC,8CAA8C,CAAC,CAAA;YAC7D,CAAC;QACF,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { RunFlags } from '../../commands/run-flags.js';
|
|
2
|
+
import type { CommandContext } from '../../commands/types.js';
|
|
3
|
+
import { type RunnerRecord } from './runner-store.js';
|
|
4
|
+
import type { CliResident } from './storage.js';
|
|
5
|
+
import type { ResidentVerificationSpec } from './verification.js';
|
|
6
|
+
export interface ResidentWorkerLaunch {
|
|
7
|
+
readonly version: 1;
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly agentKey: string;
|
|
10
|
+
readonly instanceId: string;
|
|
11
|
+
readonly config: CommandContext['config'];
|
|
12
|
+
readonly flags: RunFlags;
|
|
13
|
+
readonly toolLoading?: 'eager' | 'deferred';
|
|
14
|
+
readonly contextProfile?: 'resident' | 'interactive';
|
|
15
|
+
readonly learningDisclosure?: 'eager' | 'on-demand';
|
|
16
|
+
readonly verification?: ResidentVerificationSpec;
|
|
17
|
+
readonly maxIdleMs: number;
|
|
18
|
+
}
|
|
19
|
+
/** Launch the same installation with no terminal streams or on-disk credentials/config. */
|
|
20
|
+
export declare function startResidentRunner(options: {
|
|
21
|
+
readonly resident: CliResident;
|
|
22
|
+
readonly ctx: CommandContext;
|
|
23
|
+
readonly flags: RunFlags;
|
|
24
|
+
readonly toolLoading?: 'eager' | 'deferred';
|
|
25
|
+
readonly contextProfile?: 'resident' | 'interactive';
|
|
26
|
+
readonly learningDisclosure?: 'eager' | 'on-demand';
|
|
27
|
+
readonly verification?: ResidentVerificationSpec;
|
|
28
|
+
readonly maxSteps: number;
|
|
29
|
+
readonly maxIdleMs: number;
|
|
30
|
+
}): Promise<Omit<RunnerRecord, "token">>;
|
|
31
|
+
export declare function residentRunnerStatus(resident: CliResident): Promise<{
|
|
32
|
+
owner: null;
|
|
33
|
+
live: null;
|
|
34
|
+
} | {
|
|
35
|
+
owner: Omit<RunnerRecord, "token">;
|
|
36
|
+
live: import("./runner-control.js").RunnerControlResult | null;
|
|
37
|
+
}>;
|
|
38
|
+
/** Caller durably closes admission first. No signals are sent to recorded PIDs. */
|
|
39
|
+
export declare function stopResidentRunner(resident: CliResident, options: {
|
|
40
|
+
readonly owner: RunnerRecord | null;
|
|
41
|
+
readonly waitMs?: number;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
status: "absent";
|
|
44
|
+
owner: null;
|
|
45
|
+
} | {
|
|
46
|
+
status: "drained";
|
|
47
|
+
owner: Omit<RunnerRecord, "token">;
|
|
48
|
+
} | {
|
|
49
|
+
status: "unconfirmed";
|
|
50
|
+
owner: Omit<RunnerRecord, "token"> | null;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=runner-launch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-launch.d.ts","sourceRoot":"","sources":["../../../src/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AAA;IACpD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;IACnD,QAAQ,CAAC,YAAY,CAAC,EAAE,wBAAwB,CAAA;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC1B,wCA+GA;AAED,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,WAAW;;;;;;GAO/D;AAED,mFAAmF;AACnF,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;;;;;GAkB1E"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
4
|
+
import { queryRunner } from './runner-control.js';
|
|
5
|
+
import { finishRunner, publicRunner, readRunner, readRunnerInstance, reserveRunner, } from './runner-store.js';
|
|
6
|
+
/** Launch the same installation with no terminal streams or on-disk credentials/config. */
|
|
7
|
+
export async function startResidentRunner(options) {
|
|
8
|
+
const { resident } = options;
|
|
9
|
+
const existing = readRunner(resident);
|
|
10
|
+
if (existing && (existing.phase === 'reserved' || existing.phase === 'running'))
|
|
11
|
+
throw new Error(`Runner ${existing.instanceId} already owns this resident. Use resident status or stop; a second start cannot reset its limit.`);
|
|
12
|
+
const agenda = await resident.agenda.read();
|
|
13
|
+
if (!agenda || agenda.paused || agenda.pursuits.some((p) => p.state.phase === 'running'))
|
|
14
|
+
throw new Error('Starting requires open admission and no unresolved pursuit claims.');
|
|
15
|
+
const owner = reserveRunner(resident, {
|
|
16
|
+
mode: 'background',
|
|
17
|
+
maxSteps: options.maxSteps,
|
|
18
|
+
pauseGeneration: agenda.pauseGeneration ?? 0,
|
|
19
|
+
});
|
|
20
|
+
const source = import.meta.url.endsWith('.ts');
|
|
21
|
+
const worker = new URL(`./runner-worker.${source ? 'ts' : 'js'}`, import.meta.url);
|
|
22
|
+
const launch = {
|
|
23
|
+
version: 1,
|
|
24
|
+
cwd: resident.cwd,
|
|
25
|
+
agentKey: resident.agentKey,
|
|
26
|
+
instanceId: owner.instanceId,
|
|
27
|
+
config: options.ctx.config,
|
|
28
|
+
flags: options.flags,
|
|
29
|
+
toolLoading: options.toolLoading,
|
|
30
|
+
contextProfile: options.contextProfile,
|
|
31
|
+
learningDisclosure: options.learningDisclosure,
|
|
32
|
+
verification: options.verification,
|
|
33
|
+
maxIdleMs: options.maxIdleMs,
|
|
34
|
+
};
|
|
35
|
+
let child;
|
|
36
|
+
try {
|
|
37
|
+
child = fork(worker, [], {
|
|
38
|
+
cwd: resident.cwd,
|
|
39
|
+
env: { ...process.env, NAMZU_HOME: resident.root },
|
|
40
|
+
detached: true,
|
|
41
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
42
|
+
execArgv: source ? ['--import', createRequire(import.meta.url).resolve('tsx')] : [],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
finishRunner(resident, owner, 'launch_failed');
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
return await new Promise((resolve, reject) => {
|
|
50
|
+
let settled = false;
|
|
51
|
+
const finish = (error) => {
|
|
52
|
+
if (settled)
|
|
53
|
+
return;
|
|
54
|
+
settled = true;
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
child.removeListener('message', message);
|
|
57
|
+
child.removeListener('exit', exited);
|
|
58
|
+
// Keep the error listener: asynchronous IPC teardown must not crash the launcher.
|
|
59
|
+
if (child.connected)
|
|
60
|
+
child.disconnect();
|
|
61
|
+
child.unref();
|
|
62
|
+
if (error)
|
|
63
|
+
reject(error);
|
|
64
|
+
else {
|
|
65
|
+
try {
|
|
66
|
+
const current = readRunnerInstance(resident, owner.instanceId);
|
|
67
|
+
if (!current)
|
|
68
|
+
throw new Error('Runner startup receipt disappeared.');
|
|
69
|
+
resolve(publicRunner(current));
|
|
70
|
+
}
|
|
71
|
+
catch (readError) {
|
|
72
|
+
reject(readError);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const message = (raw) => {
|
|
77
|
+
if (!raw || typeof raw !== 'object')
|
|
78
|
+
return;
|
|
79
|
+
const value = raw;
|
|
80
|
+
if (value.instanceId !== owner.instanceId)
|
|
81
|
+
return;
|
|
82
|
+
if (value.kind === 'error') {
|
|
83
|
+
finish(new Error(typeof value.message === 'string' ? value.message : 'Runner startup failed.'));
|
|
84
|
+
}
|
|
85
|
+
else if (value.kind === 'ready') {
|
|
86
|
+
// The child will not admit a model step before this explicit handoff.
|
|
87
|
+
child.send({ kind: 'go', instanceId: owner.instanceId }, (error) => finish(error ?? undefined));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const exited = () => finish(new Error('Resident worker exited before startup was acknowledged. Inspect resident status.'));
|
|
91
|
+
const timer = setTimeout(() => finish(new Error('Resident startup was not acknowledged. Ownership is retained; inspect resident status before retrying.')), 15_000);
|
|
92
|
+
child.on('message', message);
|
|
93
|
+
child.once('exit', exited);
|
|
94
|
+
child.on('error', (error) => {
|
|
95
|
+
if (!child.pid) {
|
|
96
|
+
try {
|
|
97
|
+
finishRunner(resident, owner, 'launch_failed');
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
/* Keep the exact-owner conflict visible in status. */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finish(error);
|
|
104
|
+
});
|
|
105
|
+
child.send(launch, (error) => {
|
|
106
|
+
if (error)
|
|
107
|
+
finish(error);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export async function residentRunnerStatus(resident) {
|
|
112
|
+
const record = readRunner(resident);
|
|
113
|
+
if (!record)
|
|
114
|
+
return { owner: null, live: null };
|
|
115
|
+
return {
|
|
116
|
+
owner: publicRunner(record),
|
|
117
|
+
live: record.phase === 'running' ? await queryRunner(record, 'status') : null,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Caller durably closes admission first. No signals are sent to recorded PIDs. */
|
|
121
|
+
export async function stopResidentRunner(resident, options) {
|
|
122
|
+
const record = options.owner;
|
|
123
|
+
const waitMs = options.waitMs ?? 5_000;
|
|
124
|
+
if (!record)
|
|
125
|
+
return { status: 'absent', owner: null };
|
|
126
|
+
if (record.phase === 'stopped')
|
|
127
|
+
return { status: 'drained', owner: publicRunner(record) };
|
|
128
|
+
if (record.phase === 'released')
|
|
129
|
+
return { status: 'unconfirmed', owner: publicRunner(record) };
|
|
130
|
+
if (record.phase === 'running')
|
|
131
|
+
await queryRunner(record, 'stop');
|
|
132
|
+
const deadline = Date.now() + waitMs;
|
|
133
|
+
while (true) {
|
|
134
|
+
const current = readRunnerInstance(resident, record.instanceId);
|
|
135
|
+
if (current?.phase === 'stopped')
|
|
136
|
+
return { status: 'drained', owner: publicRunner(current) };
|
|
137
|
+
if (!current || current.phase === 'released' || Date.now() >= deadline)
|
|
138
|
+
return { status: 'unconfirmed', owner: current ? publicRunner(current) : null };
|
|
139
|
+
await sleep(Math.min(50, Math.max(1, deadline - Date.now())));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=runner-launch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-launch.js","sourceRoot":"","sources":["../../../src/integrations/resident/runner-launch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OA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,OAAO,IAAI,OAAO,CAAC,KAAK,KAAK,UAAU,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ;YACrE,OAAO,EAAE,MAAM,EAAE,aAAsB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACzF,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9D,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ProjectId, type TenantId } from '@namzu/sdk';
|
|
2
|
+
import type { CliResident } from './storage.js';
|
|
3
|
+
export interface RunnerRecord {
|
|
4
|
+
readonly version: 1;
|
|
5
|
+
readonly revision: number;
|
|
6
|
+
readonly instanceId: string;
|
|
7
|
+
readonly tenantId: TenantId;
|
|
8
|
+
readonly projectId: ProjectId;
|
|
9
|
+
readonly agentKey: string;
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
readonly mode: 'foreground' | 'background';
|
|
12
|
+
readonly phase: 'reserved' | 'running' | 'stopped' | 'released';
|
|
13
|
+
readonly reservedAt: number;
|
|
14
|
+
readonly maxSteps: number;
|
|
15
|
+
readonly pauseGeneration: number;
|
|
16
|
+
readonly pid: number | null;
|
|
17
|
+
readonly port: number | null;
|
|
18
|
+
/** Private authentication material; never include this in status output. */
|
|
19
|
+
readonly token: string;
|
|
20
|
+
readonly endedAt: number | null;
|
|
21
|
+
readonly outcome: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface ReserveRunnerOptions {
|
|
24
|
+
readonly mode: RunnerRecord['mode'];
|
|
25
|
+
readonly maxSteps: number;
|
|
26
|
+
readonly pauseGeneration: number;
|
|
27
|
+
}
|
|
28
|
+
/** An absent runner is a read-only result, never an instruction to initialize it. */
|
|
29
|
+
export declare function readRunner(resident: CliResident): RunnerRecord | null;
|
|
30
|
+
/** The original runner's final evidence remains visible after a successor starts. */
|
|
31
|
+
export declare function readRunnerInstance(resident: CliResident, instanceId: string): RunnerRecord | null;
|
|
32
|
+
/** Reserve one explicitly authorized invocation; an occupied owner is never stolen. */
|
|
33
|
+
export declare function reserveRunner(resident: CliResident, options: ReserveRunnerOptions): RunnerRecord;
|
|
34
|
+
export declare function attachRunning(resident: CliResident, expected: RunnerRecord, process: {
|
|
35
|
+
readonly pid: number;
|
|
36
|
+
readonly port: number | null;
|
|
37
|
+
}): RunnerRecord;
|
|
38
|
+
/** Publish only after the executor and its controls have drained. */
|
|
39
|
+
export declare function finishRunner(resident: CliResident, expected: RunnerRecord, outcome: string): RunnerRecord;
|
|
40
|
+
/** Explicit operator recovery of an exact owner; this is never proof of drainage. */
|
|
41
|
+
export declare function releaseRunner(resident: CliResident, expected: RunnerRecord): RunnerRecord;
|
|
42
|
+
/** Status reports retain ownership evidence without disclosing the control nonce. */
|
|
43
|
+
export declare function publicRunner(record: RunnerRecord): Omit<RunnerRecord, 'token'>;
|
|
44
|
+
//# sourceMappingURL=runner-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-store.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/runner-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAyB,KAAK,QAAQ,EAAc,MAAM,YAAY,CAAA;AAI7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IA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