@indigoai-us/hq-cli 5.345.231 → 5.345.233
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 +48 -0
- package/README.md +3 -2
- package/assets/lanes-reconcile/hq-lanes-reconcile.service +1 -1
- package/assets/scaffold/core/scripts/pipeline-conductor.sh +14 -14
- package/assets/scaffold/core/scripts/pipeline-driver.sh +7 -7
- package/assets/scaffold/core/scripts/session-project.sh +19 -4
- package/dist/command-catalog.generated.d.ts +213 -177
- package/dist/command-catalog.generated.js +263 -212
- package/dist/command-registration-plan.d.ts +6 -24
- package/dist/command-registration-plan.js +4 -8
- package/dist/commands/auth.js +3 -2
- package/dist/commands/core-handoff.d.ts +1 -0
- package/dist/commands/core-handoff.js +2 -28
- package/dist/commands/core-pipeline-conductor-command.js +1 -1
- package/dist/commands/core-pipeline-conductor-native.js +5 -5
- package/dist/commands/core-pipeline-driver-native.js +5 -5
- package/dist/commands/daemon.js +7 -36
- package/dist/commands/deploy-access.js +6 -13
- package/dist/commands/deploy-comments.js +5 -13
- package/dist/commands/deploy-domains.js +6 -13
- package/dist/commands/deploy-list.js +25 -11
- package/dist/commands/deploy-mutations.d.ts +3 -0
- package/dist/commands/deploy-mutations.js +147 -0
- package/dist/commands/link.js +29 -0
- package/dist/commands/mcp-serve-gate.d.ts +22 -0
- package/dist/commands/mcp-serve-gate.js +37 -0
- package/dist/commands/mcp-serve.js +2 -8
- package/dist/commands/mesh.js +3 -1
- package/dist/commands/report.js +8 -9
- package/dist/data/command-states.json +10 -7
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +257 -214
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/bot/fleet-bots-update-pass.d.ts +8 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +40 -0
- package/dist/lib/bot/fleet-bots-update-task.d.ts +12 -0
- package/dist/lib/bot/fleet-bots-update-task.js +52 -0
- package/dist/lib/bot/fleet-bots-update-worker-v1.d.ts +2 -0
- package/dist/lib/bot/fleet-bots-update-worker-v1.js +5 -0
- package/dist/lib/daemon/catalog.d.ts +8 -5
- package/dist/lib/daemon/catalog.js +15 -8
- package/dist/lib/daemon/flag.d.ts +2 -0
- package/dist/lib/daemon/flag.js +6 -4
- package/dist/lib/daemon/lock.js +33 -37
- package/dist/lib/daemon/ops/skill-command.d.ts +99 -0
- package/dist/lib/daemon/ops/skill-command.js +260 -0
- package/dist/lib/daemon/protocol.d.ts +1 -1
- package/dist/lib/daemon/protocol.js +1 -0
- package/dist/lib/daemon/run.js +10 -18
- package/dist/lib/daemon/server.js +7 -0
- package/dist/lib/daemon/shared-flag-reads.d.ts +70 -0
- package/dist/lib/daemon/shared-flag-reads.js +173 -0
- package/dist/lib/daemon/supervisor.d.ts +5 -0
- package/dist/lib/daemon/supervisor.js +17 -2
- package/dist/lib/db/app-ref.js +10 -15
- package/dist/lib/deploy-apps.d.ts +29 -0
- package/dist/lib/deploy-apps.js +37 -0
- package/dist/lib/doctor/checks/search-index.d.ts +16 -0
- package/dist/lib/doctor/checks/search-index.js +61 -0
- package/dist/lib/doctor/checks/stranded-lanes.js +1 -1
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/lanes/accounts.js +3 -3
- package/dist/lib/lanes/admission-host.js +1 -1
- package/dist/lib/lanes/admission.js +4 -4
- package/dist/lib/lanes/autopilot.js +2 -2
- package/dist/lib/lanes/blocker-freshness.js +1 -1
- package/dist/lib/lanes/compaction.js +5 -5
- package/dist/lib/lanes/delivery.js +1 -1
- package/dist/lib/lanes/depth-cap.js +1 -1
- package/dist/lib/lanes/disk-guard.js +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +1 -1
- package/dist/lib/lanes/imported-question.js +1 -1
- package/dist/lib/lanes/keep-alive.d.ts +2 -2
- package/dist/lib/lanes/keep-alive.js +3 -3
- package/dist/lib/lanes/kr-freshness.js +1 -1
- package/dist/lib/lanes/links.js +4 -4
- package/dist/lib/lanes/loop.js +2 -2
- package/dist/lib/lanes/machine-identity.js +3 -3
- package/dist/lib/lanes/models.js +6 -6
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/reconcile-install.js +3 -3
- package/dist/lib/lanes/reconcile.js +16 -16
- package/dist/lib/lanes/remote-control-lane.js +6 -6
- package/dist/lib/lanes/reviews.js +2 -2
- package/dist/lib/lanes/spawn.js +24 -24
- package/dist/lib/lanes/status-fields.js +4 -4
- package/dist/lib/lanes/wait.js +4 -4
- package/dist/lib/lanes/watch.js +2 -2
- package/dist/lib/lanes/watcher-main.js +1 -1
- package/dist/lib/lanes/watcher.js +38 -38
- package/dist/lib/lanes/worker-process.js +5 -5
- package/dist/lib/mesh/live/daemon/pid-lock.d.ts +2 -4
- package/dist/lib/mesh/live/daemon/pid-lock.js +38 -55
- package/dist/utils/cognito-session.d.ts +2 -56
- package/dist/utils/cognito-session.js +6 -164
- package/dist/utils/exclusive-lock.d.ts +60 -0
- package/dist/utils/exclusive-lock.js +65 -0
- package/package.json +9 -8
- package/dist/commands/staff/listings.d.ts +0 -41
- package/dist/commands/staff/listings.js +0 -160
- package/dist/commands/staff/reset-test-account.d.ts +0 -121
- package/dist/commands/staff/reset-test-account.js +0 -285
- package/dist/commands/staff/test-account.d.ts +0 -51
- package/dist/commands/staff/test-account.js +0 -196
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill.command op (hq-core-rust US-049, 40-skill-command-script, ANSWERS-1645 option (c)).
|
|
3
|
+
*
|
|
4
|
+
* hq-hook starts no program on UserPromptSubmit, so when the native
|
|
5
|
+
* classifier (`crates/hq-hook/src/skill_command_script.rs`) finds that the
|
|
6
|
+
* released hook would run a skill's `command.sh`, the hook asks hqd to do it
|
|
7
|
+
* over the socket and waits a bounded time for the answer.
|
|
8
|
+
*
|
|
9
|
+
* For exact parity hqd runs the released hook itself, byte-checked against
|
|
10
|
+
* the pinned copy (hq-core-staging v16.0.48-beta.124, b1e484afe): the hook
|
|
11
|
+
* and the `hook-lib.sh` it sources must hash to the pinned sha256 values,
|
|
12
|
+
* and so must `session-scope-capability.sh` and `perl-child-locale.sh`
|
|
13
|
+
* when present (the hook sources them only then), or the op refuses. The hook gets the caller's payload on stdin and the
|
|
14
|
+
* caller's cwd. Its stdout (one `{"systemMessage":...}` line, or nothing) is
|
|
15
|
+
* returned as is.
|
|
16
|
+
*
|
|
17
|
+
* hqd builds the hook's environment itself (`childEnv`; Reviewer O2,
|
|
18
|
+
* ANSWERS-1736): only the hook's own settings and a few plain locale and
|
|
19
|
+
* user variables are taken from the request, PATH is hqd's own, HQ_ROOT is
|
|
20
|
+
* the root hqd verified, and BASH_ENV, ENV, BASH_FUNC_*, SHELLOPTS, BASHOPTS
|
|
21
|
+
* and CDPATH are never set. A request that carries any of these, or a
|
|
22
|
+
* hostile PATH or HQ_ROOT, has them ignored, so a caller cannot make the
|
|
23
|
+
* pinned hook source or run anything else.
|
|
24
|
+
*
|
|
25
|
+
* The op refuses (never answers "nothing") when it cannot run the hook as
|
|
26
|
+
* released: a root that is not hqd's own, a hook or library that differs
|
|
27
|
+
* from the pinned bytes, bash missing, or the hook still running at the
|
|
28
|
+
* request deadline (it is killed then).
|
|
29
|
+
*/
|
|
30
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
31
|
+
import { createHash } from "node:crypto";
|
|
32
|
+
import * as fs from "node:fs";
|
|
33
|
+
import * as path from "node:path";
|
|
34
|
+
/** The hook, relative to the HQ root. */
|
|
35
|
+
export const SKILL_COMMAND_HOOK = "core/hooks/UserPromptSubmit/40-skill-command-script.sh";
|
|
36
|
+
/** The library the hook sources, relative to the HQ root. */
|
|
37
|
+
export const SKILL_COMMAND_LIB = "core/scripts/hook-lib.sh";
|
|
38
|
+
/** sha256 of the pinned hook (same value as `skill_command_script::HOOK_SHA256`). */
|
|
39
|
+
export const SKILL_COMMAND_HOOK_SHA256 = "e6ddbaf1fe8f996fa0ade56cc89c3634782db49ab90becff3380bcb0ef6c5c3c";
|
|
40
|
+
/** sha256 of the pinned `hook-lib.sh` (same value as `skill_command_script::LIB_SHA256`). */
|
|
41
|
+
export const SKILL_COMMAND_LIB_SHA256 = "9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f";
|
|
42
|
+
/**
|
|
43
|
+
* The libraries the hook sources only when they are present (ANSWERS-1817
|
|
44
|
+
* Q-SCS8 (b)): absent is the released behaviour; present, they must be the
|
|
45
|
+
* pinned bytes (same values as `skill_command_script::SCOPE_LIB_SHA256` and
|
|
46
|
+
* `PERL_LOCALE_LIB_SHA256`).
|
|
47
|
+
*/
|
|
48
|
+
export const SKILL_COMMAND_OPTIONAL_LIBS = [
|
|
49
|
+
{ rel: "core/scripts/lib/session-scope-capability.sh", sha256: "388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead" },
|
|
50
|
+
{ rel: "core/scripts/lib/perl-child-locale.sh", sha256: "18e6b9d0e22874eea00ecc868b4dcfebbc3bb42434d8d0c81b20baec1194df2e" },
|
|
51
|
+
];
|
|
52
|
+
/** The hook's stdout is a capped message; anything larger is not the released hook's answer. */
|
|
53
|
+
const STDOUT_MAX_BYTES = 256 * 1024;
|
|
54
|
+
export class SkillCommandOpError extends Error {
|
|
55
|
+
code;
|
|
56
|
+
constructor(code, message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.code = code;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The only variables taken from the request: the released hook's own
|
|
63
|
+
* settings (its header's Env list and the master-hook exports it reads), and
|
|
64
|
+
* plain user and locale variables a skill's command.sh may print with.
|
|
65
|
+
* Nothing here names a program, a file to source or a search path.
|
|
66
|
+
*/
|
|
67
|
+
export const CHILD_ENV_FROM_REQUEST = [
|
|
68
|
+
"HQ_SKILL_COMMAND_SCRIPTS",
|
|
69
|
+
"HQ_DISABLED_HOOKS",
|
|
70
|
+
"HQ_SKILL_COMMAND_FILE",
|
|
71
|
+
"HQ_SKILL_COMMAND_TIMEOUT",
|
|
72
|
+
"HQ_SKILL_COMMAND_MAX_BYTES",
|
|
73
|
+
"HQ_HOOK_EVENT",
|
|
74
|
+
"HQ_HOOK_SESSION_ID",
|
|
75
|
+
"HQ_HOOK_AGENT_ID",
|
|
76
|
+
"HOME",
|
|
77
|
+
"USER",
|
|
78
|
+
"LOGNAME",
|
|
79
|
+
"LANG",
|
|
80
|
+
"LANGUAGE",
|
|
81
|
+
"LC_ALL",
|
|
82
|
+
"LC_CTYPE",
|
|
83
|
+
"LC_COLLATE",
|
|
84
|
+
"LC_MESSAGES",
|
|
85
|
+
"LC_NUMERIC",
|
|
86
|
+
"LC_TIME",
|
|
87
|
+
"LC_MONETARY",
|
|
88
|
+
"TZ",
|
|
89
|
+
"TERM",
|
|
90
|
+
"TMPDIR",
|
|
91
|
+
];
|
|
92
|
+
/** Never set in the hook's environment, whatever the request holds. */
|
|
93
|
+
export const CHILD_ENV_NEVER = ["BASH_ENV", "ENV", "SHELLOPTS", "BASHOPTS", "CDPATH"];
|
|
94
|
+
/**
|
|
95
|
+
* The hook's environment, built by hqd: `CHILD_ENV_FROM_REQUEST` from the
|
|
96
|
+
* request, PATH from hqd's own environment, HQ_ROOT the verified root.
|
|
97
|
+
*/
|
|
98
|
+
export function childEnv(requested, verifiedRoot, ownPath) {
|
|
99
|
+
const env = {};
|
|
100
|
+
for (const name of CHILD_ENV_FROM_REQUEST) {
|
|
101
|
+
const value = requested[name];
|
|
102
|
+
if (typeof value === "string")
|
|
103
|
+
env[name] = value;
|
|
104
|
+
}
|
|
105
|
+
if (ownPath !== undefined)
|
|
106
|
+
env.PATH = ownPath;
|
|
107
|
+
env.HQ_ROOT = verifiedRoot;
|
|
108
|
+
for (const name of Object.keys(env)) {
|
|
109
|
+
if (CHILD_ENV_NEVER.includes(name) || name.startsWith("BASH_FUNC_"))
|
|
110
|
+
delete env[name];
|
|
111
|
+
}
|
|
112
|
+
return env;
|
|
113
|
+
}
|
|
114
|
+
function sha256File(file) {
|
|
115
|
+
try {
|
|
116
|
+
return createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function realDir(dir) {
|
|
123
|
+
try {
|
|
124
|
+
return fs.realpathSync(dir);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Kill the hook and everything it started. The released hook runs
|
|
132
|
+
* `command.sh` under coreutils `timeout`, which moves itself into its own
|
|
133
|
+
* process group, so killing the hook's group alone would leave the script
|
|
134
|
+
* running: every descendant is found from the process table and killed.
|
|
135
|
+
*/
|
|
136
|
+
export function killTree(pid) {
|
|
137
|
+
if (!pid)
|
|
138
|
+
return;
|
|
139
|
+
if (process.platform === "win32") {
|
|
140
|
+
spawnSync("taskkill", ["/T", "/F", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const parents = new Map();
|
|
144
|
+
const table = spawnSync("ps", ["-A", "-o", "pid=", "-o", "ppid="], { encoding: "utf8" });
|
|
145
|
+
for (const line of (table.stdout ?? "").split("\n")) {
|
|
146
|
+
const [p, pp] = line.trim().split(/\s+/).map(Number);
|
|
147
|
+
if (!Number.isInteger(p) || !Number.isInteger(pp))
|
|
148
|
+
continue;
|
|
149
|
+
parents.set(pp, [...(parents.get(pp) ?? []), p]);
|
|
150
|
+
}
|
|
151
|
+
const all = [];
|
|
152
|
+
const queue = [pid];
|
|
153
|
+
while (queue.length) {
|
|
154
|
+
const next = queue.shift();
|
|
155
|
+
if (all.includes(next))
|
|
156
|
+
continue;
|
|
157
|
+
all.push(next);
|
|
158
|
+
queue.push(...(parents.get(next) ?? []));
|
|
159
|
+
}
|
|
160
|
+
for (const target of all) {
|
|
161
|
+
for (const id of [-target, target]) {
|
|
162
|
+
try {
|
|
163
|
+
process.kill(id, "SIGKILL");
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
/* not a group leader, or already gone */
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** Parse and check the op's arguments. Never trusts a path but the root, which must be hqd's own. */
|
|
172
|
+
export function parseSkillCommandArgs(args) {
|
|
173
|
+
const { hqRoot, input, env, cwd } = args;
|
|
174
|
+
if (typeof hqRoot !== "string" || !hqRoot)
|
|
175
|
+
throw new SkillCommandOpError("bad_args", "hqRoot must be a non-empty string");
|
|
176
|
+
if (typeof input !== "string")
|
|
177
|
+
throw new SkillCommandOpError("bad_args", "input must be a string");
|
|
178
|
+
if (typeof cwd !== "string" || !cwd)
|
|
179
|
+
throw new SkillCommandOpError("bad_args", "cwd must be a non-empty string");
|
|
180
|
+
if (!env || typeof env !== "object" || Array.isArray(env))
|
|
181
|
+
throw new SkillCommandOpError("bad_args", "env must be an object");
|
|
182
|
+
const plain = {};
|
|
183
|
+
for (const [key, value] of Object.entries(env)) {
|
|
184
|
+
if (typeof value !== "string")
|
|
185
|
+
throw new SkillCommandOpError("bad_args", `env.${key} must be a string`);
|
|
186
|
+
plain[key] = value;
|
|
187
|
+
}
|
|
188
|
+
return { hqRoot, input, env: plain, cwd };
|
|
189
|
+
}
|
|
190
|
+
/** Run the pinned hook for one prompt. */
|
|
191
|
+
export function runSkillCommand(req, deps) {
|
|
192
|
+
const now = deps.now ?? Date.now;
|
|
193
|
+
const root = realDir(req.hqRoot);
|
|
194
|
+
const daemonRoot = realDir(deps.daemonRoot);
|
|
195
|
+
if (!root || !daemonRoot || root !== daemonRoot) {
|
|
196
|
+
return Promise.reject(new SkillCommandOpError("root_mismatch", "skill.command runs only in hqd's own HQ root"));
|
|
197
|
+
}
|
|
198
|
+
const hook = path.join(root, SKILL_COMMAND_HOOK);
|
|
199
|
+
if (sha256File(hook) !== SKILL_COMMAND_HOOK_SHA256 || sha256File(path.join(root, SKILL_COMMAND_LIB)) !== SKILL_COMMAND_LIB_SHA256) {
|
|
200
|
+
return Promise.reject(new SkillCommandOpError("hook_not_pinned", `${SKILL_COMMAND_HOOK} or ${SKILL_COMMAND_LIB} is not the pinned release (hq-core-staging v16.0.48-beta.124)`));
|
|
201
|
+
}
|
|
202
|
+
for (const lib of SKILL_COMMAND_OPTIONAL_LIBS) {
|
|
203
|
+
const file = path.join(root, lib.rel);
|
|
204
|
+
if (fs.existsSync(file) && sha256File(file) !== lib.sha256) {
|
|
205
|
+
return Promise.reject(new SkillCommandOpError("hook_not_pinned", `${lib.rel} is not the pinned release (hq-core-staging v16.0.48-beta.124)`));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const remainingMs = Math.floor(deps.deadlineMs - now());
|
|
209
|
+
if (remainingMs <= 0) {
|
|
210
|
+
return Promise.reject(new SkillCommandOpError("timeout", "skill.command reached its deadline before the hook started"));
|
|
211
|
+
}
|
|
212
|
+
return new Promise((resolve, reject) => {
|
|
213
|
+
let settled = false;
|
|
214
|
+
const settle = (fn) => {
|
|
215
|
+
if (settled)
|
|
216
|
+
return;
|
|
217
|
+
settled = true;
|
|
218
|
+
clearTimeout(timer);
|
|
219
|
+
fn();
|
|
220
|
+
};
|
|
221
|
+
const child = spawn(deps.bash ?? "bash", [hook], {
|
|
222
|
+
cwd: req.cwd,
|
|
223
|
+
env: childEnv(req.env, root, process.env.PATH),
|
|
224
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
225
|
+
detached: process.platform !== "win32",
|
|
226
|
+
});
|
|
227
|
+
const kill = () => killTree(child.pid);
|
|
228
|
+
const timer = setTimeout(() => {
|
|
229
|
+
kill();
|
|
230
|
+
settle(() => reject(new SkillCommandOpError("timeout", `the skill command hook did not finish within ${remainingMs}ms`)));
|
|
231
|
+
}, remainingMs);
|
|
232
|
+
const chunks = [];
|
|
233
|
+
let size = 0;
|
|
234
|
+
child.stdout.on("data", (chunk) => {
|
|
235
|
+
size += chunk.length;
|
|
236
|
+
if (size > STDOUT_MAX_BYTES) {
|
|
237
|
+
kill();
|
|
238
|
+
settle(() => reject(new SkillCommandOpError("too_large", "the skill command hook wrote more than the released hook can")));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
chunks.push(chunk);
|
|
242
|
+
});
|
|
243
|
+
child.on("error", (err) => settle(() => reject(new SkillCommandOpError("spawn_failed", `bash could not start: ${err.message}`))));
|
|
244
|
+
child.on("close", (code, signal) => {
|
|
245
|
+
settle(() => {
|
|
246
|
+
// The released hook always exits 0; anything else is not its answer.
|
|
247
|
+
if (code !== 0) {
|
|
248
|
+
reject(new SkillCommandOpError("hook_failed", `the skill command hook ended with ${signal ?? `exit ${code}`}`));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
resolve({ stdout: Buffer.concat(chunks).toString("utf8") });
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
child.stdin.on("error", () => {
|
|
255
|
+
/* the hook may exit before reading all of stdin */
|
|
256
|
+
});
|
|
257
|
+
child.stdin.end(req.input);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=skill-command.js.map
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* out of order, so clients match them by `id`.
|
|
8
8
|
*/
|
|
9
9
|
export declare const HQD_SOCKET_NAME = "hqd.sock";
|
|
10
|
-
export declare const HQD_OPS: readonly ["ping", "health", "resolve", "session.open", "session.close", "policy.check", "journal.append", "mcp.call", "auth.login", "auth.status"];
|
|
10
|
+
export declare const HQD_OPS: readonly ["ping", "health", "resolve", "session.open", "session.close", "policy.check", "journal.append", "mcp.call", "auth.login", "auth.status", "skill.command"];
|
|
11
11
|
export type HqdOp = (typeof HQD_OPS)[number];
|
|
12
12
|
export type HqdHealthFallbackReason = "registry_unavailable" | "manifest_missing_or_malformed" | "company_not_in_manifest" | "no_match";
|
|
13
13
|
export interface HqdHealthResult {
|
package/dist/lib/daemon/run.js
CHANGED
|
@@ -24,7 +24,7 @@ import { agentKitPaths } from "../agent-kit/paths.js";
|
|
|
24
24
|
import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "../bot/config.js";
|
|
25
25
|
import { clearStaleReadyBeforeGatewayStart, planFleetBots } from "../bot/fleet-daemon.js";
|
|
26
26
|
import { botsRoot } from "../bot/paths.js";
|
|
27
|
-
import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices,
|
|
27
|
+
import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices, planUnits, SEARCH_INDEX_WORKER_UNAVAILABLE } from "./catalog.js";
|
|
28
28
|
import { effectiveSyncOwner, readDaemonConfig } from "./config.js";
|
|
29
29
|
import { backgroundQosCommand } from "./background-qos.js";
|
|
30
30
|
import { serveQmdWorker } from "../search-index/worker-process.js";
|
|
@@ -1518,8 +1518,10 @@ export async function runDaemon(opts) {
|
|
|
1518
1518
|
daemonSyncRunnerPids,
|
|
1519
1519
|
lanesReconcileInProcess: Boolean(laneReconcileWatcher && laneReconcileWatcherRoot === hqRoot),
|
|
1520
1520
|
// The first plan runs under the daemon startup lease. If it cannot be
|
|
1521
|
-
// released,
|
|
1522
|
-
|
|
1521
|
+
// released, or a rollback left an install without the worker, the plan
|
|
1522
|
+
// marks search-index unavailable; the timer never starts `hq index sync`.
|
|
1523
|
+
searchIndexWorkerAvailable: (startupPlanOpen || !cliPackagePrefix || packageUseLeaseReleased)
|
|
1524
|
+
&& (!cliPackagePrefix || fs.existsSync(searchIndexWorkerEntry)),
|
|
1523
1525
|
searchIndexOwnedBySyncRunner: searchIndexRunnerOwnsIndexFlag.status().enabled &&
|
|
1524
1526
|
hqCloud !== null && !hqCloudVersionOlder(hqCloud.version, "6.18.75") &&
|
|
1525
1527
|
syncOwner === "daemon" && services.includes("sync") && !config.syncPaused &&
|
|
@@ -1577,17 +1579,16 @@ export async function runDaemon(opts) {
|
|
|
1577
1579
|
return { skipped: true, on: events.on.bind(events), kill: () => false };
|
|
1578
1580
|
}
|
|
1579
1581
|
const controller = new AbortController();
|
|
1580
|
-
|
|
1581
|
-
const stop = (signal = "SIGTERM") => {
|
|
1582
|
+
const stop = () => {
|
|
1582
1583
|
controller.abort();
|
|
1583
|
-
return
|
|
1584
|
+
return true;
|
|
1584
1585
|
};
|
|
1585
|
-
let needsFallback = false;
|
|
1586
1586
|
const done = withSearchIndexPackageLease(packageUseLeaseReleased ? cliPackagePrefix : null, () => {
|
|
1587
1587
|
// A running daemon can survive a rollback to a package without v1.
|
|
1588
|
+
// It fails the pass and starts nothing; the next plan marks the unit
|
|
1589
|
+
// unavailable with the reason `hq daemon status` and `hq doctor` show.
|
|
1588
1590
|
if (cliPackagePrefix && !fs.existsSync(searchIndexWorkerEntry)) {
|
|
1589
|
-
|
|
1590
|
-
return Promise.resolve(true);
|
|
1591
|
+
return Promise.reject(new Error(SEARCH_INDEX_WORKER_UNAVAILABLE));
|
|
1591
1592
|
}
|
|
1592
1593
|
return runSearchIndexWorker({
|
|
1593
1594
|
root,
|
|
@@ -1597,15 +1598,6 @@ export async function runDaemon(opts) {
|
|
|
1597
1598
|
signal: controller.signal,
|
|
1598
1599
|
});
|
|
1599
1600
|
}, acquirePackageUseLease, stop).then((ok) => {
|
|
1600
|
-
if (!needsFallback || controller.signal.aborted)
|
|
1601
|
-
return ok;
|
|
1602
|
-
// The compatibility child acquires its own lease during bootstrap.
|
|
1603
|
-
return new Promise((resolve, reject) => {
|
|
1604
|
-
fallback = spawnUnit({ ...unit, command: legacySearchIndexCommand(root) });
|
|
1605
|
-
fallback.on("exit", (code) => resolve(code === 0));
|
|
1606
|
-
fallback.on("error", reject);
|
|
1607
|
-
});
|
|
1608
|
-
}).then((ok) => {
|
|
1609
1601
|
if (activeIndexWorker?.stop === stop)
|
|
1610
1602
|
activeIndexWorker = undefined;
|
|
1611
1603
|
if (controller.signal.aborted)
|
|
@@ -18,6 +18,7 @@ import { createLineSplitter, encodeMessage, HQD_DEFAULT_REQUEST_TIMEOUT_MS, HQD_
|
|
|
18
18
|
import { SessionRegistry } from "./session-registry.js";
|
|
19
19
|
import { sessionMetaCompanies } from "../core-utils/session-company.js";
|
|
20
20
|
import { journalAppend, JournalOpError } from "./ops/journal.js";
|
|
21
|
+
import { parseSkillCommandArgs, runSkillCommand, SkillCommandOpError } from "./ops/skill-command.js";
|
|
21
22
|
import { PolicyIndex, PolicyOpError, policyCheck } from "./ops/policy.js";
|
|
22
23
|
import { defaultMcpToken, HqMcpBridge, jsonResult, McpOpError, runWorker } from "./ops/mcp.js";
|
|
23
24
|
import { authenticateMachineCredentials, machineTokenExpiresAt, MachineLoginError, parseStdinMachineCredentials } from "./machine-login.js";
|
|
@@ -555,6 +556,11 @@ export async function startHqdServer(opts) {
|
|
|
555
556
|
throw new OpError("bad_args", "company is required (or a cwd linked to a company)");
|
|
556
557
|
return journalAppend({ company, project: stringArg(args, "project"), section: stringArg(args, "section"), text: stringArg(args, "text") }, requireRoot(), clock());
|
|
557
558
|
}
|
|
559
|
+
case "skill.command":
|
|
560
|
+
return runSkillCommand(parseSkillCommandArgs(args), {
|
|
561
|
+
daemonRoot: requireRoot(),
|
|
562
|
+
deadlineMs: requestStartedAt + HQD_DEFAULT_REQUEST_TIMEOUT_MS,
|
|
563
|
+
});
|
|
558
564
|
case "mcp.call": {
|
|
559
565
|
const name = stringArg(args, "name");
|
|
560
566
|
const raw = args.arguments ?? {};
|
|
@@ -679,6 +685,7 @@ export async function startHqdServer(opts) {
|
|
|
679
685
|
const error = err instanceof OpError ||
|
|
680
686
|
err instanceof PolicyOpError ||
|
|
681
687
|
err instanceof JournalOpError ||
|
|
688
|
+
err instanceof SkillCommandOpError ||
|
|
682
689
|
err instanceof McpOpError ||
|
|
683
690
|
err instanceof MachineLoginError
|
|
684
691
|
? { code: err.code, message: err.message }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daemon's one flag poller (hq-core-rust US-009 c1, US-036 c2).
|
|
3
|
+
*
|
|
4
|
+
* Every timed flag read in the daemon shares one DaemonFlagSnapshotSource
|
|
5
|
+
* (flag.ts): the four kill switches, the hqd HQ Anywhere runtime gate and the
|
|
6
|
+
* state file writer. The hqd listener's `isEnabled` used to make a second
|
|
7
|
+
* registry request of its own on every listener event and on its fallback
|
|
8
|
+
* timer, through the flag-registry worker, only so that the on-disk flag
|
|
9
|
+
* snapshot it reads afterwards was fresh.
|
|
10
|
+
*
|
|
11
|
+
* Here the shared request writes that snapshot itself, for the daemon's own
|
|
12
|
+
* scope, the way the worker does: a company uid writes that company's
|
|
13
|
+
* snapshot, no company context writes the person snapshot, and a slug that
|
|
14
|
+
* resolves to no uid writes nothing. The listener then reads the snapshot
|
|
15
|
+
* without any request of its own (hqdListenerFlagGate), so the daemon makes
|
|
16
|
+
* one registry request per refresh interval for every flag reader.
|
|
17
|
+
*
|
|
18
|
+
* As the worker did, an agent token with a company context also refreshes the
|
|
19
|
+
* agent's person snapshot from one more request without company selectors
|
|
20
|
+
* (the service maps that caller to personUid=agentUid), and a failed snapshot
|
|
21
|
+
* write is reported to Sentry with the worker's event tags
|
|
22
|
+
* (component flag-snapshot-cache-write).
|
|
23
|
+
*
|
|
24
|
+
* Nothing here can turn a flag on. A signed-out or failed read writes nothing,
|
|
25
|
+
* so the snapshot keeps the last answer the registry gave, exactly as it did
|
|
26
|
+
* when the worker's refresh failed.
|
|
27
|
+
*/
|
|
28
|
+
import { type FlagClientOptions, type FlagSnapshot } from "@indigoai-us/hq-flags-client";
|
|
29
|
+
import { type DaemonFlagClient, type DaemonFlagRegistryRead, type DaemonFlagSnapshotSource, type DaemonFlagSnapshotSourceOptions } from "./flag.js";
|
|
30
|
+
export type SharedFlagSnapshotWrite = "company" | "person" | "skipped";
|
|
31
|
+
/** Receives a failed snapshot write with the flag-registry worker's Sentry tags. */
|
|
32
|
+
export type FlagSnapshotWriteReporter = (error: Error, tags: Record<string, string>) => void;
|
|
33
|
+
export interface WriteSharedFlagSnapshotOptions {
|
|
34
|
+
writeCompany?: (companyUid: string, flags: FlagSnapshot["flags"], options: {
|
|
35
|
+
env: NodeJS.ProcessEnv;
|
|
36
|
+
}) => unknown;
|
|
37
|
+
writePerson?: (flags: FlagSnapshot["flags"], options: {
|
|
38
|
+
env: NodeJS.ProcessEnv;
|
|
39
|
+
}) => unknown;
|
|
40
|
+
/** Defaults to the CLI's Sentry captureException, as flag-registry.ts reports the same failure. */
|
|
41
|
+
report?: FlagSnapshotWriteReporter;
|
|
42
|
+
/** The agent person request, for tests. Defaults to the registry client. */
|
|
43
|
+
createClient?: (options: FlagClientOptions) => DaemonFlagClient;
|
|
44
|
+
}
|
|
45
|
+
/** Write the on-disk flag snapshot from one shared registry read. Never throws. */
|
|
46
|
+
export declare function writeSharedFlagSnapshotFile(read: DaemonFlagRegistryRead, env: NodeJS.ProcessEnv, options?: WriteSharedFlagSnapshotOptions): SharedFlagSnapshotWrite;
|
|
47
|
+
/**
|
|
48
|
+
* The worker's agent person refresh: when a loaded shared read was made for a
|
|
49
|
+
* company context with an agent token, resolve again without company selectors
|
|
50
|
+
* and write the result as the person snapshot. Company-scoped answers are never
|
|
51
|
+
* relabelled as person answers. A failed person request writes nothing. Never
|
|
52
|
+
* rejects.
|
|
53
|
+
*/
|
|
54
|
+
export declare function refreshAgentPersonFlagSnapshot(read: DaemonFlagRegistryRead, env: NodeJS.ProcessEnv, options?: WriteSharedFlagSnapshotOptions): Promise<"person" | "skipped">;
|
|
55
|
+
export interface DaemonSharedFlagReadsOptions extends Omit<DaemonFlagSnapshotSourceOptions, "onRead"> {
|
|
56
|
+
/** Told about every shared read after the snapshot file is written, in order. One that throws does not stop the rest. */
|
|
57
|
+
observers?: ReadonlyArray<(read: DaemonFlagRegistryRead, env: NodeJS.ProcessEnv) => void>;
|
|
58
|
+
snapshotFile?: WriteSharedFlagSnapshotOptions;
|
|
59
|
+
}
|
|
60
|
+
/** The daemon's one flag source: the shared read, which also keeps the on-disk flag snapshot fresh. */
|
|
61
|
+
export declare function createDaemonSharedFlagReads(options?: DaemonSharedFlagReadsOptions): DaemonFlagSnapshotSource;
|
|
62
|
+
/**
|
|
63
|
+
* The flag half of the hqd listener's `isEnabled`, for anywhereRuntimeAllowed:
|
|
64
|
+
* the HQ Anywhere flag as the shared read last wrote it to the snapshot. It
|
|
65
|
+
* has no `refreshFlag`, so a listener check makes no registry request.
|
|
66
|
+
*/
|
|
67
|
+
export declare function hqdListenerFlagGate(): {
|
|
68
|
+
readFlag: (env: NodeJS.ProcessEnv) => boolean;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=shared-flag-reads.d.ts.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daemon's one flag poller (hq-core-rust US-009 c1, US-036 c2).
|
|
3
|
+
*
|
|
4
|
+
* Every timed flag read in the daemon shares one DaemonFlagSnapshotSource
|
|
5
|
+
* (flag.ts): the four kill switches, the hqd HQ Anywhere runtime gate and the
|
|
6
|
+
* state file writer. The hqd listener's `isEnabled` used to make a second
|
|
7
|
+
* registry request of its own on every listener event and on its fallback
|
|
8
|
+
* timer, through the flag-registry worker, only so that the on-disk flag
|
|
9
|
+
* snapshot it reads afterwards was fresh.
|
|
10
|
+
*
|
|
11
|
+
* Here the shared request writes that snapshot itself, for the daemon's own
|
|
12
|
+
* scope, the way the worker does: a company uid writes that company's
|
|
13
|
+
* snapshot, no company context writes the person snapshot, and a slug that
|
|
14
|
+
* resolves to no uid writes nothing. The listener then reads the snapshot
|
|
15
|
+
* without any request of its own (hqdListenerFlagGate), so the daemon makes
|
|
16
|
+
* one registry request per refresh interval for every flag reader.
|
|
17
|
+
*
|
|
18
|
+
* As the worker did, an agent token with a company context also refreshes the
|
|
19
|
+
* agent's person snapshot from one more request without company selectors
|
|
20
|
+
* (the service maps that caller to personUid=agentUid), and a failed snapshot
|
|
21
|
+
* write is reported to Sentry with the worker's event tags
|
|
22
|
+
* (component flag-snapshot-cache-write).
|
|
23
|
+
*
|
|
24
|
+
* Nothing here can turn a flag on. A signed-out or failed read writes nothing,
|
|
25
|
+
* so the snapshot keeps the last answer the registry gave, exactly as it did
|
|
26
|
+
* when the worker's refresh failed.
|
|
27
|
+
*/
|
|
28
|
+
import { createFlagClient } from "@indigoai-us/hq-flags-client";
|
|
29
|
+
import { anywhereRuntimeEnabledFromSnapshot } from "../anywhere-runtime-fast-flag.js";
|
|
30
|
+
import { resolveFlagRegistryEndpoint } from "../flag-registry-endpoint.js";
|
|
31
|
+
import { flagSnapshotWriteFailureTags, writeFlagSnapshotFile, writePersonFlagSnapshotFile, } from "../flag-snapshot-file.js";
|
|
32
|
+
import { resolveProcessFlagCompanyContext } from "../process-flag-company-context.js";
|
|
33
|
+
import { createDaemonFlagSnapshotSource, } from "./flag.js";
|
|
34
|
+
import { decodeJwtClaims } from "./machine-token-identity.js";
|
|
35
|
+
const PERSON_READ_TIMEOUT_MS = 5_000;
|
|
36
|
+
const AGENT_UID_RE = /^agt_[A-Za-z0-9]+$/;
|
|
37
|
+
/** The flag-registry worker's Sentry event for a failed snapshot write. Loaded lazily, as run.ts loads Sentry. */
|
|
38
|
+
function reportToSentry(error, tags) {
|
|
39
|
+
void import("../../sentry.js").then(({ Sentry }) => { Sentry.captureException(error, { tags }); }, () => { });
|
|
40
|
+
}
|
|
41
|
+
function reportWriteFailure(error, companyUidPresent, report) {
|
|
42
|
+
try {
|
|
43
|
+
let tags;
|
|
44
|
+
try {
|
|
45
|
+
tags = flagSnapshotWriteFailureTags(error);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
tags = {};
|
|
49
|
+
}
|
|
50
|
+
(report ?? reportToSentry)(error instanceof Error ? error : new Error(String(error)), {
|
|
51
|
+
component: "flag-snapshot-cache-write",
|
|
52
|
+
company_uid_present: companyUidPresent ? "true" : "false",
|
|
53
|
+
...tags,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// a reporter cannot reach the flag read
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function loadedSnapshot(read) {
|
|
61
|
+
if (read.signedOut || read.errors.length > 0 || !read.client)
|
|
62
|
+
return null;
|
|
63
|
+
return read.client.snapshot?.() ?? null;
|
|
64
|
+
}
|
|
65
|
+
/** Write the on-disk flag snapshot from one shared registry read. Never throws. */
|
|
66
|
+
export function writeSharedFlagSnapshotFile(read, env, options = {}) {
|
|
67
|
+
let companyUidPresent = false;
|
|
68
|
+
try {
|
|
69
|
+
const snapshot = loadedSnapshot(read);
|
|
70
|
+
if (!snapshot)
|
|
71
|
+
return "skipped";
|
|
72
|
+
const company = resolveProcessFlagCompanyContext(env);
|
|
73
|
+
if (company.companyUid) {
|
|
74
|
+
companyUidPresent = true;
|
|
75
|
+
(options.writeCompany ?? writeFlagSnapshotFile)(company.companyUid, snapshot.flags, { env });
|
|
76
|
+
return "company";
|
|
77
|
+
}
|
|
78
|
+
if (company.companySlug)
|
|
79
|
+
return "skipped";
|
|
80
|
+
(options.writePerson ?? writePersonFlagSnapshotFile)(snapshot.flags, { env });
|
|
81
|
+
return "person";
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
reportWriteFailure(error, companyUidPresent, options.report);
|
|
85
|
+
return "skipped";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The worker's agent person refresh: when a loaded shared read was made for a
|
|
90
|
+
* company context with an agent token, resolve again without company selectors
|
|
91
|
+
* and write the result as the person snapshot. Company-scoped answers are never
|
|
92
|
+
* relabelled as person answers. A failed person request writes nothing. Never
|
|
93
|
+
* rejects.
|
|
94
|
+
*/
|
|
95
|
+
export async function refreshAgentPersonFlagSnapshot(read, env, options = {}) {
|
|
96
|
+
let personClient;
|
|
97
|
+
try {
|
|
98
|
+
if (!loadedSnapshot(read))
|
|
99
|
+
return "skipped";
|
|
100
|
+
const token = read.token;
|
|
101
|
+
if (typeof token !== "string" || token.trim() === "")
|
|
102
|
+
return "skipped";
|
|
103
|
+
const company = resolveProcessFlagCompanyContext(env);
|
|
104
|
+
if (!company.companyUid && !company.companySlug)
|
|
105
|
+
return "skipped";
|
|
106
|
+
// The claims of the token the request was made with; the service authenticates it again.
|
|
107
|
+
const claims = decodeJwtClaims(token);
|
|
108
|
+
const agentUid = claims?.["custom:entityUid"];
|
|
109
|
+
if (claims?.["custom:entityType"] !== "agent" || typeof agentUid !== "string" || !AGENT_UID_RE.test(agentUid)) {
|
|
110
|
+
return "skipped";
|
|
111
|
+
}
|
|
112
|
+
personClient = (options.createClient ?? createFlagClient)({
|
|
113
|
+
endpoint: resolveFlagRegistryEndpoint(undefined, env),
|
|
114
|
+
getToken: () => token,
|
|
115
|
+
env: {},
|
|
116
|
+
refreshIntervalMs: 0,
|
|
117
|
+
requestTimeoutMs: PERSON_READ_TIMEOUT_MS,
|
|
118
|
+
onError: () => { },
|
|
119
|
+
});
|
|
120
|
+
await personClient.ready();
|
|
121
|
+
const personSnapshot = personClient.snapshot?.() ?? null;
|
|
122
|
+
if (!personSnapshot)
|
|
123
|
+
return "skipped";
|
|
124
|
+
try {
|
|
125
|
+
(options.writePerson ?? writePersonFlagSnapshotFile)(personSnapshot.flags, { env });
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
reportWriteFailure(error, false, options.report);
|
|
129
|
+
return "skipped";
|
|
130
|
+
}
|
|
131
|
+
return "person";
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// The company snapshot stands when person scope is offline, as in the worker.
|
|
135
|
+
return "skipped";
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
try {
|
|
139
|
+
personClient?.close();
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// same isolated failure boundary
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** The daemon's one flag source: the shared read, which also keeps the on-disk flag snapshot fresh. */
|
|
147
|
+
export function createDaemonSharedFlagReads(options = {}) {
|
|
148
|
+
const { observers = [], snapshotFile, ...sourceOptions } = options;
|
|
149
|
+
return createDaemonFlagSnapshotSource({
|
|
150
|
+
...sourceOptions,
|
|
151
|
+
onRead: (read, env) => {
|
|
152
|
+
writeSharedFlagSnapshotFile(read, env, snapshotFile);
|
|
153
|
+
void refreshAgentPersonFlagSnapshot(read, env, snapshotFile);
|
|
154
|
+
for (const observe of observers) {
|
|
155
|
+
try {
|
|
156
|
+
observe(read, env);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// one observer cannot stop the others
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The flag half of the hqd listener's `isEnabled`, for anywhereRuntimeAllowed:
|
|
167
|
+
* the HQ Anywhere flag as the shared read last wrote it to the snapshot. It
|
|
168
|
+
* has no `refreshFlag`, so a listener check makes no registry request.
|
|
169
|
+
*/
|
|
170
|
+
export function hqdListenerFlagGate() {
|
|
171
|
+
return { readFlag: anywhereRuntimeEnabledFromSnapshot };
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=shared-flag-reads.js.map
|
|
@@ -188,6 +188,11 @@ export interface SupervisorDeps {
|
|
|
188
188
|
plan: () => UnitPlan[];
|
|
189
189
|
spawn: (unit: UnitPlan) => SupervisedChild;
|
|
190
190
|
runInternal: (task: string) => Promise<boolean>;
|
|
191
|
+
/** The fleet-bots-update internal task; defaults to one pass on a worker thread (tests replace it). */
|
|
192
|
+
runFleetBotsUpdate?: (options: {
|
|
193
|
+
env: NodeJS.ProcessEnv;
|
|
194
|
+
log: (line: string) => void;
|
|
195
|
+
}) => Promise<boolean>;
|
|
191
196
|
takeRequests: () => ControlRequest[];
|
|
192
197
|
/** Restart the whole daemon process (a `restart-daemon` request). */
|
|
193
198
|
restartDaemon?: () => void | boolean | Promise<boolean | void>;
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import { createHash } from "node:crypto";
|
|
31
31
|
import { StringDecoder } from "node:string_decoder";
|
|
32
32
|
import { classifyExit } from "./exit-cause.js";
|
|
33
|
+
import { runFleetBotsUpdateWorker } from "../bot/fleet-bots-update-task.js";
|
|
33
34
|
import { SYNC_RUNNER_LEASE_CONFLICT_EXIT, SYNC_RUNNER_LEASE_RETRY_MS, parseSyncRunnerProtocolLine, syncPassResult, } from "./sync-runner.js";
|
|
34
35
|
const BACKOFF_BASE_MS = 1_000;
|
|
35
36
|
const BACKOFF_MAX_MS = 60_000;
|
|
@@ -1125,8 +1126,22 @@ export function createSupervisor(deps) {
|
|
|
1125
1126
|
const command = slot.plan.command;
|
|
1126
1127
|
if (command?.type === "internal") {
|
|
1127
1128
|
slot.state.status = "running";
|
|
1128
|
-
|
|
1129
|
-
|
|
1129
|
+
// A thrown error, a rejection or a crash of the fleet update's worker
|
|
1130
|
+
// thread ends only this run; other units keep their schedule.
|
|
1131
|
+
let run;
|
|
1132
|
+
try {
|
|
1133
|
+
run =
|
|
1134
|
+
command.task === "fleet-bots-update"
|
|
1135
|
+
? (deps.runFleetBotsUpdate ?? runFleetBotsUpdateWorker)({
|
|
1136
|
+
env: { ...process.env, ...slot.plan.env },
|
|
1137
|
+
log: (line) => deps.log("info", `${slot.plan.id}: ${line}`),
|
|
1138
|
+
})
|
|
1139
|
+
: deps.runInternal(command.task);
|
|
1140
|
+
}
|
|
1141
|
+
catch (err) {
|
|
1142
|
+
run = Promise.reject(err);
|
|
1143
|
+
}
|
|
1144
|
+
run
|
|
1130
1145
|
.then((ok) => {
|
|
1131
1146
|
slot.state.lastResult = ok ? "ok" : "failed";
|
|
1132
1147
|
}, (err) => {
|