@indigoai-us/hq-cli 5.345.220 → 5.345.221
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 +118 -0
- package/dist/command-catalog.generated.d.ts +144 -2
- package/dist/command-catalog.generated.js +175 -2
- package/dist/commands/auth.js +4 -1
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +39 -2
- package/dist/commands/bot.js +140 -11
- package/dist/commands/core-stop-autosave.d.ts +21 -0
- package/dist/commands/core-stop-autosave.js +300 -0
- package/dist/commands/core.js +2 -0
- package/dist/commands/daemon.d.ts +5 -0
- package/dist/commands/daemon.js +31 -7
- package/dist/commands/doctor-usage.d.ts +5 -0
- package/dist/commands/doctor-usage.js +25 -0
- package/dist/commands/env.d.ts +49 -4
- package/dist/commands/env.js +355 -5
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +87 -3
- package/dist/commands/sources.js +3 -3
- package/dist/commands/sync-core.d.ts +1 -0
- package/dist/commands/sync-core.js +77 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +24 -2
- package/dist/lib/bot/fleet-local.d.ts +30 -2
- package/dist/lib/bot/fleet-local.js +60 -1
- package/dist/lib/bot/grok-login-scope.d.ts +36 -0
- package/dist/lib/bot/grok-login-scope.js +93 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
- package/dist/lib/bot/legacy-provider-login.js +28 -22
- package/dist/lib/bot/runtime-sign-in-check.js +6 -1
- package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/machine-checks.d.ts +22 -1
- package/dist/lib/daemon/machine-checks.js +54 -12
- package/dist/lib/daemon/run.js +66 -8
- package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
- package/dist/lib/daemon/stop-autosave-lock.js +166 -0
- package/dist/lib/daemon/stop-autosave.d.ts +28 -0
- package/dist/lib/daemon/stop-autosave.js +111 -0
- package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
- package/dist/lib/daemon/stop-diagnostics.js +136 -0
- package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
- package/dist/lib/daemon/stop-job-executor.js +126 -0
- package/dist/lib/daemon/stop-jobs.d.ts +93 -0
- package/dist/lib/daemon/stop-jobs.js +599 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +1 -1
- package/dist/lib/environment/access-probes.d.ts +234 -0
- package/dist/lib/environment/access-probes.js +918 -0
- package/dist/lib/environment/profile.d.ts +15 -2
- package/dist/lib/environment/profile.js +55 -20
- package/dist/lib/environment/rfc3339.d.ts +8 -0
- package/dist/lib/environment/rfc3339.js +26 -0
- package/dist/lib/environment/work-requirements.d.ts +169 -0
- package/dist/lib/environment/work-requirements.js +389 -0
- package/dist/lib/hook-engine/coverage.d.ts +137 -7
- package/dist/lib/hook-engine/coverage.js +1424 -4
- package/dist/lib/hook-engine/fleet-registration.js +2 -2
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +2 -2
- package/dist/lib/hot-channels/alert.js +8 -5
- package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
- package/dist/lib/hot-channels/signals-pass.js +296 -17
- package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
- package/dist/lib/hot-channels/signals-runtime.js +82 -0
- package/dist/lib/install/hook-target.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +26 -2
- package/dist/lib/lanes/host-capacity.js +17 -2
- package/dist/lib/lanes/host-compute.d.ts +90 -0
- package/dist/lib/lanes/host-compute.js +185 -0
- package/dist/lib/lanes/index.d.ts +2 -0
- package/dist/lib/lanes/index.js +1 -0
- package/dist/lib/lanes/reconcile.js +22 -1
- package/dist/lib/lanes/resource-usage.d.ts +155 -0
- package/dist/lib/lanes/resource-usage.js +589 -0
- package/dist/lib/lanes/run-size.d.ts +46 -0
- package/dist/lib/lanes/run-size.js +197 -0
- package/dist/lib/lanes/store.js +27 -0
- package/dist/lib/lanes/throttle.d.ts +36 -1
- package/dist/lib/lanes/throttle.js +47 -10
- package/dist/lib/lanes/types.d.ts +40 -0
- package/dist/lib/lanes/types.js +2 -2
- package/dist/lib/lanes/watcher.js +13 -4
- package/dist/lib/lanes/worker-process.d.ts +25 -2
- package/dist/lib/lanes/worker-process.js +71 -19
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +288 -24
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +48 -23
- package/dist/lib/signals/codex-lockdown.d.ts +79 -0
- package/dist/lib/signals/codex-lockdown.js +271 -0
- package/dist/lib/signals/codex-login.d.ts +37 -0
- package/dist/lib/signals/codex-login.js +83 -0
- package/dist/lib/signals/engine.d.ts +27 -0
- package/dist/lib/signals/engine.js +70 -0
- package/dist/lib/signals/reply.js +22 -1
- package/dist/lib/signals/run-record.js +6 -1
- package/dist/lib/signals/settings.d.ts +5 -0
- package/dist/lib/signals/settings.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +85 -9
- package/dist/lib/signals/steps/extract.js +317 -68
- package/dist/lib/signals/steps/types.d.ts +2 -0
- package/dist/lib/sync-core/engine-home.d.ts +35 -1
- package/dist/lib/sync-core/engine-home.js +119 -16
- package/dist/lib/sync-core/rollout-state.d.ts +2 -1
- package/dist/lib/sync-core/rollout-state.js +5 -2
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
- package/dist/utils/auth-session-check.d.ts +16 -0
- package/dist/utils/auth-session-check.js +16 -0
- package/dist/utils/client-health-contract.d.ts +6 -0
- package/dist/utils/client-health-contract.js +13 -0
- package/dist/utils/client-health.d.ts +7 -0
- package/dist/utils/client-health.js +22 -1
- package/dist/utils/command-usage.d.ts +40 -0
- package/dist/utils/command-usage.js +61 -0
- package/dist/utils/duplicate-command-usage.d.ts +72 -0
- package/dist/utils/duplicate-command-usage.js +125 -0
- package/dist/utils/host-registration.js +2 -1
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +9 -8
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +116 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** Delivers native Stop timeout diagnostics through the existing closed
|
|
2
|
+
* Sentry transport. It never reads hook payloads or executable text. */
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { openStoreDir } from "../safe-store.js";
|
|
5
|
+
import { reportSentryEvent } from "../core-utils/sentry-report.js";
|
|
6
|
+
const FIELDS = new Set(["hook_name", "hook_event", "hook_path", "session_id", "declared_timeout_ms", "elapsed_ms", "remaining_ms", "exit_code", "watchdog_timeout_ms", "tool_name", "hq_version", "platform", "load_average", "bash_env_set", "shell", "cwd_kind", "root_storage_class", "timing_precision", "nproc", "hook_script", "slow_phase", "slow_child", "slow_child_ms"]);
|
|
7
|
+
const activeRoots = new Set();
|
|
8
|
+
const cursors = new Map();
|
|
9
|
+
export function closeStopDiagnosticCursor(root) {
|
|
10
|
+
const key = path.resolve(root);
|
|
11
|
+
const held = cursors.get(key);
|
|
12
|
+
if (!held)
|
|
13
|
+
return;
|
|
14
|
+
held.cursor.close();
|
|
15
|
+
held.store.close();
|
|
16
|
+
cursors.delete(key);
|
|
17
|
+
}
|
|
18
|
+
export async function drainStopDiagnostics(options) {
|
|
19
|
+
if (!options.ownsQueue()) {
|
|
20
|
+
closeStopDiagnosticCursor(options.root);
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
const key = path.resolve(options.root);
|
|
24
|
+
if (activeRoots.has(key))
|
|
25
|
+
return 0;
|
|
26
|
+
activeRoots.add(key);
|
|
27
|
+
let done = 0;
|
|
28
|
+
try {
|
|
29
|
+
let held = cursors.get(key);
|
|
30
|
+
if (!held) {
|
|
31
|
+
const opened = openStoreDir(path.join(options.root, "workspace/.hook-timeout-native"));
|
|
32
|
+
if (!opened.ok)
|
|
33
|
+
return 0;
|
|
34
|
+
const cursor = opened.value.nameCursor();
|
|
35
|
+
if (!cursor.ok) {
|
|
36
|
+
opened.value.close();
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
held = { store: opened.value, cursor: cursor.value };
|
|
40
|
+
cursors.set(key, held);
|
|
41
|
+
}
|
|
42
|
+
const { store } = held;
|
|
43
|
+
const names = held.cursor.read(64);
|
|
44
|
+
if (!names.ok) {
|
|
45
|
+
closeStopDiagnosticCursor(key);
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
for (const name of names.value.names) {
|
|
49
|
+
if (!options.ownsQueue()) {
|
|
50
|
+
closeStopDiagnosticCursor(key);
|
|
51
|
+
return done;
|
|
52
|
+
}
|
|
53
|
+
if (!/^[a-f0-9]{64}\.json$/.test(name))
|
|
54
|
+
continue;
|
|
55
|
+
const data = store.read(name, { maxBytes: 16384 });
|
|
56
|
+
if (!data.ok)
|
|
57
|
+
continue;
|
|
58
|
+
const receipt = store.read(`${name}.reported`, { maxBytes: 16 });
|
|
59
|
+
if (receipt.ok && receipt.value.toString() === "done\n")
|
|
60
|
+
continue;
|
|
61
|
+
const attempts = store.read(`${name}.attempts`, { maxBytes: 16 });
|
|
62
|
+
const count = attempts.ok ? Number(attempts.value.toString()) : 0;
|
|
63
|
+
if (!Number.isSafeInteger(count) || count < 0 || count >= 3)
|
|
64
|
+
continue;
|
|
65
|
+
let value;
|
|
66
|
+
try {
|
|
67
|
+
value = JSON.parse(data.value.toString());
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (value.type !== "hook_timeout_warning" || value.level !== "warning"
|
|
73
|
+
|| value.message !== "HQ hook is approaching configured timeout" || typeof value.fingerprint !== "string" || !/^hook-timeout:Stop:[a-f0-9]{64}$/.test(value.fingerprint)
|
|
74
|
+
|| value.metadata === null || typeof value.metadata !== "object" || Array.isArray(value.metadata))
|
|
75
|
+
continue;
|
|
76
|
+
if (Object.keys(value).some(key => !["type", "level", "message", "fingerprint", "metadata", "breadcrumb"].includes(key)))
|
|
77
|
+
continue;
|
|
78
|
+
if (value.breadcrumb !== undefined && (typeof value.breadcrumb !== "string"
|
|
79
|
+
|| !/^[a-f0-9]{64}\/(absolute|relative)-[a-f0-9]{64}\.json$/.test(value.breadcrumb)))
|
|
80
|
+
continue;
|
|
81
|
+
const metadata = value.metadata;
|
|
82
|
+
const { hook_sequence: sequence, ...scalars } = metadata;
|
|
83
|
+
if (sequence !== undefined && (!Array.isArray(sequence) || sequence.length > 20 || sequence.some(row => {
|
|
84
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
85
|
+
return true;
|
|
86
|
+
const value = row;
|
|
87
|
+
return Object.keys(value).sort().join() !== "event,ms,script" || typeof value.script !== "string" || !/^[A-Za-z0-9._-]{1,48}$/.test(value.script)
|
|
88
|
+
|| typeof value.event !== "string" || !/^[A-Za-z0-9._-]{1,48}$/.test(value.event)
|
|
89
|
+
|| !Number.isSafeInteger(value.ms) || Number(value.ms) < 0 || Number(value.ms) > 86400000;
|
|
90
|
+
})))
|
|
91
|
+
continue;
|
|
92
|
+
if (Object.entries(scalars).some(([key, val]) => !FIELDS.has(key)
|
|
93
|
+
|| (typeof val !== "string" && typeof val !== "number"))
|
|
94
|
+
|| metadata.hook_name !== "master-hook.sh" || metadata.hook_event !== "Stop")
|
|
95
|
+
continue;
|
|
96
|
+
if (Object.values(scalars).some(val => typeof val === "string" && (val.length > 256 || /[\r\n\0]/.test(val)))
|
|
97
|
+
|| Object.values(scalars).some(val => typeof val === "number" && (!Number.isFinite(val) || val < 0)))
|
|
98
|
+
continue;
|
|
99
|
+
if (!store.writeAtomic(`${name}.attempts`, String(count + 1)).ok)
|
|
100
|
+
continue;
|
|
101
|
+
const report = options.report ?? (body => reportSentryEvent(body, { hqRoot: options.root, timeoutMs: 750 }));
|
|
102
|
+
let timer;
|
|
103
|
+
try {
|
|
104
|
+
const timeout = new Promise(resolve => { timer = setTimeout(() => resolve({ code: 1 }), 1000); });
|
|
105
|
+
const { breadcrumb, ...event } = value;
|
|
106
|
+
const result = await Promise.race([report(JSON.stringify(event)), timeout]);
|
|
107
|
+
let receiptReady = true;
|
|
108
|
+
if (result.code === 0 && typeof breadcrumb === "string") {
|
|
109
|
+
const [session, file] = breadcrumb.split("/");
|
|
110
|
+
const warnings = openStoreDir(path.join(options.root, "workspace/.hook-timeout-breadcrumbs", session));
|
|
111
|
+
receiptReady = false;
|
|
112
|
+
if (warnings.ok) {
|
|
113
|
+
receiptReady = warnings.value.writeAtomic(`${file}.reported`, "").ok;
|
|
114
|
+
warnings.value.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (result.code === 0 && receiptReady && store.writeAtomic(`${name}.reported`, "done\n").ok)
|
|
118
|
+
done++;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
options.log("Stop timeout diagnostic delivery failed; retained for retry");
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
if (timer)
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (names.value.done)
|
|
129
|
+
closeStopDiagnosticCursor(key);
|
|
130
|
+
return done;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
activeRoots.delete(key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=stop-diagnostics.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type StopJob } from "./stop-jobs.js";
|
|
2
|
+
/** Completion receipts are read only from this job's private root. */
|
|
3
|
+
export declare function stopJobCompleted(job: StopJob, allowedRoot?: string): boolean;
|
|
4
|
+
/** Remove completion proofs written before `olderThan` (ms since the epoch)
|
|
5
|
+
* from `root`'s private results folder. The drainer calls this only when its
|
|
6
|
+
* queue is fully consumed, so every proof removed is for a job behind its
|
|
7
|
+
* cursor; a proof is read only to settle an interrupted receipt. Bounded per call.
|
|
8
|
+
*/
|
|
9
|
+
export declare function pruneStopJobResults(root: string, olderThan: number, limit?: number): void;
|
|
10
|
+
export declare function executeStopJob(job: StopJob, options: {
|
|
11
|
+
nodeBinary: string;
|
|
12
|
+
hqBinary: string;
|
|
13
|
+
allowedRoot: string | undefined;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
code: number;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=stop-job-executor.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Execute typed Stop jobs through the running CLI's own entry point. */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { STOP_JOB_KILL_MS, stopJobArguments } from "./stop-jobs.js";
|
|
6
|
+
import { openStoreDir } from "../safe-store.js";
|
|
7
|
+
/** Completion receipts are read only from this job's private root. */
|
|
8
|
+
export function stopJobCompleted(job, allowedRoot = job.root) {
|
|
9
|
+
try {
|
|
10
|
+
if (fs.realpathSync(job.root) !== fs.realpathSync(allowedRoot))
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const opened = openStoreDir(path.join(job.root, "workspace/orchestrator/stop-job-results"));
|
|
17
|
+
if (!opened.ok)
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
const read = opened.value.read(`${job.digest}.json`, { maxBytes: 4096 });
|
|
21
|
+
if (!read.ok)
|
|
22
|
+
return false;
|
|
23
|
+
const value = JSON.parse(read.value.toString());
|
|
24
|
+
return value !== null && typeof value === "object"
|
|
25
|
+
&& value.id === job.id
|
|
26
|
+
&& value.digest === job.digest
|
|
27
|
+
&& value.status === "completed";
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
opened.value.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Remove completion proofs written before `olderThan` (ms since the epoch)
|
|
37
|
+
* from `root`'s private results folder. The drainer calls this only when its
|
|
38
|
+
* queue is fully consumed, so every proof removed is for a job behind its
|
|
39
|
+
* cursor; a proof is read only to settle an interrupted receipt. Bounded per call.
|
|
40
|
+
*/
|
|
41
|
+
export function pruneStopJobResults(root, olderThan, limit = 4096) {
|
|
42
|
+
const opened = openStoreDir(path.join(root, "workspace/orchestrator/stop-job-results"));
|
|
43
|
+
if (!opened.ok)
|
|
44
|
+
return;
|
|
45
|
+
const store = opened.value;
|
|
46
|
+
try {
|
|
47
|
+
const names = store.nameCursor();
|
|
48
|
+
if (!names.ok)
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
let scanned = 0;
|
|
52
|
+
while (scanned < limit) {
|
|
53
|
+
const batch = names.value.read(256);
|
|
54
|
+
if (!batch.ok)
|
|
55
|
+
return;
|
|
56
|
+
for (const name of batch.value.names) {
|
|
57
|
+
scanned += 1;
|
|
58
|
+
if (!/^[0-9a-f]{64}\.json$/.test(name))
|
|
59
|
+
continue;
|
|
60
|
+
const facts = store.stat(name);
|
|
61
|
+
if (facts.ok && facts.value.mtimeMs < olderThan)
|
|
62
|
+
store.remove(name);
|
|
63
|
+
}
|
|
64
|
+
if (batch.value.done)
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
names.value.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
store.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function executeStopJob(job, options) {
|
|
77
|
+
// A disappeared working directory never falls back to the daemon's cwd.
|
|
78
|
+
try {
|
|
79
|
+
if (!options.allowedRoot || fs.realpathSync(job.root) !== fs.realpathSync(options.allowedRoot))
|
|
80
|
+
return Promise.resolve({ code: 1 });
|
|
81
|
+
if (!fs.statSync(job.cwd).isDirectory())
|
|
82
|
+
return Promise.resolve({ code: 1 });
|
|
83
|
+
if (!fs.statSync(path.join(job.root, "core/core.yaml")).isFile())
|
|
84
|
+
return Promise.resolve({ code: 1 });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return Promise.resolve({ code: 1 });
|
|
88
|
+
}
|
|
89
|
+
const args = stopJobArguments(job);
|
|
90
|
+
const env = { ...job.env, HQ_ROOT: job.root, CLAUDE_PROJECT_DIR: job.root, HQ_NO_UPDATE_CHECK: "1", HQ_STOP_JOB_ID: job.id };
|
|
91
|
+
return new Promise(resolve => {
|
|
92
|
+
if (options.signal?.aborted) {
|
|
93
|
+
resolve({ code: 1 });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const child = spawn(options.nodeBinary, [options.hqBinary, ...args], {
|
|
97
|
+
cwd: job.cwd, env, shell: false, windowsHide: true, stdio: "ignore",
|
|
98
|
+
});
|
|
99
|
+
const stop = () => { child.kill("SIGTERM"); };
|
|
100
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
101
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), options.timeoutMs ?? STOP_JOB_KILL_MS);
|
|
102
|
+
let settled = false;
|
|
103
|
+
const finish = (code) => {
|
|
104
|
+
if (settled)
|
|
105
|
+
return;
|
|
106
|
+
settled = true;
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
options.signal?.removeEventListener("abort", stop);
|
|
109
|
+
if (code === 0) {
|
|
110
|
+
const opened = openStoreDir(path.join(job.root, "workspace/orchestrator/stop-job-results"), { create: true });
|
|
111
|
+
if (opened.ok) {
|
|
112
|
+
try {
|
|
113
|
+
opened.value.writeAtomic(`${job.digest}.json`, JSON.stringify({ id: job.id, digest: job.digest, status: "completed" }));
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
opened.value.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
resolve({ code });
|
|
121
|
+
};
|
|
122
|
+
child.once("error", () => finish(1));
|
|
123
|
+
child.once("close", code => finish(code ?? 1));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=stop-job-executor.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export type StopOperation = {
|
|
2
|
+
kind: "checkpoint";
|
|
3
|
+
session: string;
|
|
4
|
+
transcript: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "probe";
|
|
8
|
+
runtime: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "refresh";
|
|
11
|
+
company: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "autosave";
|
|
14
|
+
session: string;
|
|
15
|
+
};
|
|
16
|
+
export interface StopJob {
|
|
17
|
+
id: string;
|
|
18
|
+
digest: string;
|
|
19
|
+
root: string;
|
|
20
|
+
cwd: string;
|
|
21
|
+
operation: StopOperation;
|
|
22
|
+
env: NodeJS.ProcessEnv;
|
|
23
|
+
}
|
|
24
|
+
export declare function parseStopJob(text: string, home: string): StopJob | undefined;
|
|
25
|
+
export interface StopDrainOptions {
|
|
26
|
+
home: string;
|
|
27
|
+
/** Must prove ownership of the canonical per-user daemon lease. */
|
|
28
|
+
ownsQueue: () => boolean;
|
|
29
|
+
/** Runs a validated operation, never the original argv. No shell evaluation. */
|
|
30
|
+
execute: (job: StopJob) => Promise<{
|
|
31
|
+
code: number;
|
|
32
|
+
detail?: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** True only after the operation's own durable output proves completion. */
|
|
35
|
+
completed?: (job: StopJob) => boolean;
|
|
36
|
+
/** Removes completion proofs older than the given time (ms since the epoch). Runs only when the queue is fully consumed. */
|
|
37
|
+
pruneResults?: (olderThan: number) => void;
|
|
38
|
+
log: (message: string) => void;
|
|
39
|
+
/** Clock (tests). */
|
|
40
|
+
now?: () => number;
|
|
41
|
+
/** Whether a process is running; undefined when unknown (tests). */
|
|
42
|
+
alive?: (pid: number) => boolean | undefined;
|
|
43
|
+
/** Queue size at which a fully consumed queue file is rotated (tests). */
|
|
44
|
+
rotateBytes?: number;
|
|
45
|
+
/** How long a rotated queue file is kept for a writer that opened it before the rotation (tests). */
|
|
46
|
+
rotateGraceMs?: number;
|
|
47
|
+
}
|
|
48
|
+
/** The longest a job runs before the executor kills it. */
|
|
49
|
+
export declare const STOP_JOB_KILL_MS = 60000;
|
|
50
|
+
/** A `started` receipt older than this has no running job behind it: the kill timer plus a margin. */
|
|
51
|
+
export declare const STOP_JOB_STALE_MS: number;
|
|
52
|
+
/** Receipts and completion proofs are kept this long; a record older than this is never run. */
|
|
53
|
+
export declare const STOP_JOB_RETENTION_MS: number;
|
|
54
|
+
/** Lines consumed per pass (run, skipped or already receipted); the drainer schedules another pass at once when reached. */
|
|
55
|
+
export declare const STOP_JOB_PASS_LIMIT = 64;
|
|
56
|
+
/** Builds only known CLI arguments from the validated operation. */
|
|
57
|
+
export declare function stopJobArguments(job: StopJob): string[];
|
|
58
|
+
/** Startup scan plus file notifications, with a bounded fallback scan when
|
|
59
|
+
* a watcher is unavailable or an event was missed. The singleton daemon owns
|
|
60
|
+
* this consumer and close waits for its current operation to finish. */
|
|
61
|
+
export declare function startStopJobDrainer(options: StopDrainOptions): {
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Drain the queue. It always makes progress: no input stops it for good.
|
|
66
|
+
*
|
|
67
|
+
* - The cursor names the queue file by identity. A replaced, truncated or
|
|
68
|
+
* rewritten queue (or an unreadable cursor) restarts at the start of the
|
|
69
|
+
* file now there. That is safe because every consumed line has a receipt
|
|
70
|
+
* keyed by its digest, so a line seen again is not run again, and a line
|
|
71
|
+
* older than the receipt retention is never run (`expired`).
|
|
72
|
+
* - A line that is not UTF-8, or a record longer than the producer's line
|
|
73
|
+
* limit, is skipped (logged) and the cursor moves past it.
|
|
74
|
+
* - A `started` receipt with no completion proof is a job that was
|
|
75
|
+
* interrupted (daemon killed, crash, power loss). Once no job can still be
|
|
76
|
+
* running behind it (its daemon is gone, or it is older than the kill timer
|
|
77
|
+
* plus a margin) it runs once more: checkpoint, gate probe, setting refresh
|
|
78
|
+
* and autosave each recompute their result from current state, so a second
|
|
79
|
+
* run repeats work rather than duplicating it, and losing the job would
|
|
80
|
+
* lose the checkpoint or autosave the shell always made. A job interrupted
|
|
81
|
+
* twice is skipped with a warning, so a job that itself kills the daemon
|
|
82
|
+
* cannot stall the queue.
|
|
83
|
+
* - Pruning: when the whole queue is consumed and has grown past a bound, it
|
|
84
|
+
* is renamed to `stop-jobs.1.jsonl` (the Rust writer opens the name with
|
|
85
|
+
* O_APPEND and writes each line in one call, with no lock, so a writer that
|
|
86
|
+
* opened the old name before the rename appends to the renamed file). The
|
|
87
|
+
* renamed file is drained first and removed only after a grace period with
|
|
88
|
+
* no write. Receipts and completion proofs older than the retention are
|
|
89
|
+
* removed only when the queue is fully consumed, so only for jobs behind
|
|
90
|
+
* the cursor.
|
|
91
|
+
*/
|
|
92
|
+
export declare function drainStopJobs(options: StopDrainOptions): Promise<number>;
|
|
93
|
+
//# sourceMappingURL=stop-jobs.d.ts.map
|