@indigoai-us/hq-cli 5.345.222 → 5.345.225
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 +89 -0
- package/assets/bot-workers/setup/context/quick-reference.md +2 -2
- package/assets/mesh-daemon/README.md +11 -12
- package/dist/command-catalog.generated.d.ts +79 -5
- package/dist/command-catalog.generated.js +95 -5
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- package/dist/commands/cloud-provision.d.ts +4 -1
- package/dist/commands/cloud-provision.js +7 -3
- package/dist/commands/cloud-retire.js +1 -1
- package/dist/commands/core-delegate-w1b.js +210 -188
- package/dist/commands/core-delegate.d.ts +5 -0
- package/dist/commands/core-dm-bind-native.d.ts +5 -1
- package/dist/commands/core-dm-bind-native.js +4 -0
- package/dist/commands/core-job-notify-native.d.ts +5 -1
- package/dist/commands/core-job-notify-native.js +8 -2
- package/dist/commands/core-jobs-native.d.ts +27 -1
- package/dist/commands/core-jobs-native.js +49 -28
- package/dist/commands/core-pipeline-conductor-native.js +7 -7
- package/dist/commands/core-pipeline-driver-native.js +5 -5
- package/dist/commands/core-refresh-vault-access-native.d.ts +5 -0
- package/dist/commands/core-refresh-vault-access-native.js +3 -1
- package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
- package/dist/commands/daemon.d.ts +2 -0
- package/dist/commands/daemon.js +67 -1
- package/dist/commands/lanes-hold.d.ts +2 -27
- package/dist/commands/lanes-hold.js +3 -75
- package/dist/commands/lanes-loop.js +1 -1
- package/dist/commands/lanes-session-start.js +2 -2
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +13 -4
- package/dist/commands/monitor.js +1 -1
- package/dist/commands/packs.js +14 -3
- package/dist/commands/sync-core.js +31 -12
- package/dist/commands/whoami.d.ts +10 -17
- package/dist/commands/whoami.js +7 -79
- package/dist/data/command-states.json +13 -0
- package/dist/index.js +1 -1
- package/dist/lib/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- package/dist/lib/daemon/catalog.d.ts +8 -5
- package/dist/lib/daemon/catalog.js +13 -7
- package/dist/lib/daemon/config.d.ts +5 -0
- package/dist/lib/daemon/config.js +6 -0
- package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
- package/dist/lib/daemon/lanes-monitor-state.js +129 -0
- package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
- package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
- package/dist/lib/daemon/machine-checks.d.ts +45 -0
- package/dist/lib/daemon/machine-checks.js +95 -11
- package/dist/lib/daemon/merge-sections.d.ts +165 -0
- package/dist/lib/daemon/merge-sections.js +556 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
- package/dist/lib/daemon/native-notice-ledger.js +43 -0
- package/dist/lib/daemon/ops/policy.d.ts +1 -1
- package/dist/lib/daemon/ops/policy.js +1 -1
- package/dist/lib/daemon/protocol.d.ts +1 -1
- package/dist/lib/daemon/protocol.js +0 -6
- package/dist/lib/daemon/run.js +76 -3
- package/dist/lib/daemon/selfcheck.js +2 -2
- package/dist/lib/daemon/server.d.ts +2 -4
- package/dist/lib/daemon/server.js +5 -48
- package/dist/lib/daemon/state-file.d.ts +74 -4
- package/dist/lib/daemon/state-file.js +159 -19
- package/dist/lib/daemon/supervisor.d.ts +11 -1
- package/dist/lib/daemon/supervisor.js +86 -0
- package/dist/lib/daemon/updater.d.ts +2 -6
- package/dist/lib/daemon/updater.js +4 -11
- package/dist/lib/daemon/whoami-cache.d.ts +96 -0
- package/dist/lib/daemon/whoami-cache.js +244 -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/flag-registry-worker.js +33 -3
- package/dist/lib/flag-registry.js +13 -0
- package/dist/lib/hook-engine/coverage.d.ts +2 -0
- package/dist/lib/hook-engine/coverage.js +71 -0
- package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
- package/dist/lib/hook-engine/reconcile.js +14 -8
- package/dist/lib/install/hook-target.d.ts +13 -3
- package/dist/lib/install/hook-target.js +14 -11
- package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
- package/dist/lib/lanes/monitor.d.ts +2 -0
- package/dist/lib/lanes/monitor.js +2 -1
- package/dist/lib/lanes/registry-flag.d.ts +6 -0
- package/dist/lib/lanes/registry-flag.js +3 -2
- package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
- package/dist/lib/lanes/repo-merge-hold.js +90 -0
- package/dist/lib/lanes/watcher-main.js +3 -3
- package/dist/lib/mesh/live/daemon/doctor.js +1 -1
- package/dist/lib/mesh/live/daemon/install.js +2 -2
- package/dist/lib/scan-packages/index.js +8 -9
- package/dist/lib/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- package/dist/lib/sync-core/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +15 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +12 -1
- package/dist/lib/sync-core/vault-settings.js +23 -7
- package/dist/lib/windows/install-followup.js +1 -1
- package/dist/utils/client-health-contract.d.ts +1 -0
- package/dist/utils/client-health-contract.js +5 -0
- package/dist/utils/client-health.d.ts +2 -0
- package/dist/utils/client-health.js +40 -0
- package/dist/utils/cognito-session.d.ts +2 -14
- package/dist/utils/cognito-session.js +2 -40
- package/dist/utils/daemon-cli-version.d.ts +13 -0
- package/dist/utils/daemon-cli-version.js +47 -0
- package/dist/utils/duplicate-command-usage.js +1 -1
- package/dist/utils/machine-token-cache.d.ts +21 -0
- package/dist/utils/machine-token-cache.js +49 -0
- package/dist/utils/pack-contributions.d.ts +14 -2
- package/dist/utils/pack-contributions.js +31 -5
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/whoami-identity.d.ts +54 -0
- package/dist/utils/whoami-identity.js +108 -0
- package/package.json +7 -7
- package/scripts/bench-core.mjs +34 -3
- package/dist/lib/daemon/ops/memory.d.ts +0 -18
- package/dist/lib/daemon/ops/memory.js +0 -65
- package/dist/lib/daemon/ops/mesh.d.ts +0 -38
- package/dist/lib/daemon/ops/mesh.js +0 -70
|
@@ -58,6 +58,20 @@ export type MachineCheckResult = DaemonStateMachineCheck;
|
|
|
58
58
|
export interface RunMachineChecksOptions {
|
|
59
59
|
hqRoot: string;
|
|
60
60
|
env?: NodeJS.ProcessEnv;
|
|
61
|
+
/**
|
|
62
|
+
* Run every script in collect-only mode (HQ_MACHINE_CHECK_COLLECT_ONLY=1):
|
|
63
|
+
* it reports its finding but writes no delivery stamp. Set only for a core
|
|
64
|
+
* that advertises the mode (machineCheckCollectOnlySupported). Default off,
|
|
65
|
+
* and the variable is then removed from the script's environment.
|
|
66
|
+
*/
|
|
67
|
+
collectOnly?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* With collectOnly: checks that run once in normal mode anyway, because the
|
|
70
|
+
* native notice has delivered their last finding. Normal mode writes the
|
|
71
|
+
* script's own show-once record and prints the same text, so the finding
|
|
72
|
+
* keeps its fingerprint and is not shown again.
|
|
73
|
+
*/
|
|
74
|
+
commitIds?: ReadonlySet<string>;
|
|
61
75
|
now?: () => Date;
|
|
62
76
|
/** Write the results here (through the store rules) after the batch. */
|
|
63
77
|
resultsFile?: string;
|
|
@@ -97,6 +111,19 @@ type ScriptCheck = {
|
|
|
97
111
|
};
|
|
98
112
|
/** The script's absolute path when it may be run; else why not. */
|
|
99
113
|
export declare function checkMachineCheckScript(hqRoot: string, relative: string, platform?: NodeJS.Platform): ScriptCheck;
|
|
114
|
+
/** The core.yaml key that advertises collect-only support. */
|
|
115
|
+
export declare const MACHINE_CHECK_COLLECT_ONLY_KEY = "machineCheckCollectOnly";
|
|
116
|
+
/**
|
|
117
|
+
* Whether the installed core's scripts support collect-only mode: a
|
|
118
|
+
* top-level `machineCheckCollectOnly: 1` line in `<root>/core/core.yaml`
|
|
119
|
+
* (hq-core-staging, Q47). In that mode a script reports its finding but
|
|
120
|
+
* leaves its delivery stamp (the setup nag's .last file, the welcome-brief
|
|
121
|
+
* marker, client-health's and ensure-hq-desktop's show-once records) to the
|
|
122
|
+
* session that shows the finding. Operational caches and throttles are kept.
|
|
123
|
+
* An older core, or a core.yaml that cannot be read, answers false and the
|
|
124
|
+
* batch runs as before.
|
|
125
|
+
*/
|
|
126
|
+
export declare function machineCheckCollectOnlySupported(hqRoot: string): boolean;
|
|
100
127
|
/**
|
|
101
128
|
* Run every machine check once, one at a time. A call while a batch is
|
|
102
129
|
* running returns that batch. Inside a machine check
|
|
@@ -149,7 +176,18 @@ export interface MachineCheckScheduleOptions {
|
|
|
149
176
|
registered?: (root: string, home: string, env: NodeJS.ProcessEnv) => boolean;
|
|
150
177
|
/** Test seam: whether the native notice can use its ledger. Default nativeNoticeLedgerUsable. */
|
|
151
178
|
ledgerUsable?: (env: NodeJS.ProcessEnv, home: string) => boolean;
|
|
179
|
+
/** Test seam: whether the core supports collect-only. Default machineCheckCollectOnlySupported. */
|
|
180
|
+
collectOnlySupported?: (hqRoot: string) => boolean;
|
|
181
|
+
/** Test seam: the fingerprints the native notice delivered. Default nativeNoticeShownFingerprints. */
|
|
182
|
+
shownFingerprints?: (env: NodeJS.ProcessEnv, home: string) => ReadonlySet<string>;
|
|
152
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* The checks to commit in this batch: each whose last result (the results
|
|
186
|
+
* file the native notice reads) carries a fingerprint the native notice has
|
|
187
|
+
* recorded as delivered, unless this schedule already committed that same
|
|
188
|
+
* fingerprint.
|
|
189
|
+
*/
|
|
190
|
+
export declare function machineChecksToCommit(previous: readonly MachineCheckResult[], shown: ReadonlySet<string>, committed: ReadonlyMap<string, string>): Map<string, string>;
|
|
153
191
|
export interface MachineCheckSchedule {
|
|
154
192
|
/** One scheduled tick (tests). Resolves when the tick is done; never rejects. */
|
|
155
193
|
tick(): Promise<void>;
|
|
@@ -165,6 +203,13 @@ export interface MachineCheckSchedule {
|
|
|
165
203
|
* here would run them a second time and leave cooldown stamps that silence
|
|
166
204
|
* the legacy run, so neither path would show the finding. A batch already running finishes. A failed batch
|
|
167
205
|
* logs one line with the error's name only.
|
|
206
|
+
*
|
|
207
|
+
* When the installed core advertises collect-only support
|
|
208
|
+
* (machineCheckCollectOnlySupported), the batch runs its scripts in that mode
|
|
209
|
+
* and they write no delivery stamp. That also covers the split-HOME edge the
|
|
210
|
+
* ledger rule cannot see: the daemon's HOME passes the rule while the
|
|
211
|
+
* session's is refused, both run, and the session's legacy run still shows
|
|
212
|
+
* the finding. With an older core nothing changes.
|
|
168
213
|
*/
|
|
169
214
|
export declare function startMachineCheckSchedule(options: MachineCheckScheduleOptions): MachineCheckSchedule;
|
|
170
215
|
export {};
|
|
@@ -40,7 +40,7 @@ import { coreNextEnabled } from "../../utils/core-next-flag.js";
|
|
|
40
40
|
import { coreNextKillReason } from "../../utils/core-next-kill.js";
|
|
41
41
|
import { isExcludedWindowsBash, resolveWindowsBash } from "../../utils/windows-bash.js";
|
|
42
42
|
import { anyNativeSessionStartRegistered } from "./machine-check-registration.js";
|
|
43
|
-
import { nativeNoticeLedgerUsable } from "./native-notice-ledger.js";
|
|
43
|
+
import { nativeNoticeLedgerUsable, nativeNoticeShownFingerprints } from "./native-notice-ledger.js";
|
|
44
44
|
import { openStoreDir } from "../safe-store.js";
|
|
45
45
|
import { readStoreFile, writeStoreFile } from "./paths.js";
|
|
46
46
|
import { cutUtf8, MACHINE_CHECK_DETAIL_BYTES } from "./state-file.js";
|
|
@@ -185,6 +185,31 @@ export function checkMachineCheckScript(hqRoot, relative, platform = process.pla
|
|
|
185
185
|
store.close();
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
+
/** The core.yaml key that advertises collect-only support. */
|
|
189
|
+
export const MACHINE_CHECK_COLLECT_ONLY_KEY = "machineCheckCollectOnly";
|
|
190
|
+
const COLLECT_ONLY_LINE = /^machineCheckCollectOnly:[ \t]*1[ \t]*(?:#.*)?$/m;
|
|
191
|
+
/**
|
|
192
|
+
* Whether the installed core's scripts support collect-only mode: a
|
|
193
|
+
* top-level `machineCheckCollectOnly: 1` line in `<root>/core/core.yaml`
|
|
194
|
+
* (hq-core-staging, Q47). In that mode a script reports its finding but
|
|
195
|
+
* leaves its delivery stamp (the setup nag's .last file, the welcome-brief
|
|
196
|
+
* marker, client-health's and ensure-hq-desktop's show-once records) to the
|
|
197
|
+
* session that shows the finding. Operational caches and throttles are kept.
|
|
198
|
+
* An older core, or a core.yaml that cannot be read, answers false and the
|
|
199
|
+
* batch runs as before.
|
|
200
|
+
*/
|
|
201
|
+
export function machineCheckCollectOnlySupported(hqRoot) {
|
|
202
|
+
try {
|
|
203
|
+
const file = path.join(path.resolve(hqRoot), "core", "core.yaml");
|
|
204
|
+
const stat = fs.statSync(file);
|
|
205
|
+
if (!stat.isFile() || stat.size > 256 * 1024)
|
|
206
|
+
return false;
|
|
207
|
+
return COLLECT_ONLY_LINE.test(fs.readFileSync(file, "utf8"));
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
188
213
|
function payload(event, hqRoot) {
|
|
189
214
|
return event === "SessionStart"
|
|
190
215
|
? JSON.stringify({ hook_event_name: "SessionStart", source: "startup", session_id: SESSION_ID, cwd: hqRoot })
|
|
@@ -199,21 +224,26 @@ function payload(event, hqRoot) {
|
|
|
199
224
|
* TerminateProcess for either signal (there are no POSIX process groups), so
|
|
200
225
|
* the first kill already ends it and the second is a no-op.
|
|
201
226
|
*/
|
|
202
|
-
function runScript(shell, file, spec, hqRoot, env, killGraceMs, drainMs) {
|
|
227
|
+
function runScript(shell, file, spec, hqRoot, env, killGraceMs, drainMs, collectOnly) {
|
|
203
228
|
return new Promise((resolve) => {
|
|
204
229
|
const chunks = [];
|
|
205
230
|
let kept = 0;
|
|
206
231
|
let child;
|
|
232
|
+
const scriptEnv = {
|
|
233
|
+
...env,
|
|
234
|
+
CLAUDE_PROJECT_DIR: hqRoot,
|
|
235
|
+
HQ_ROOT: hqRoot,
|
|
236
|
+
HQ_MACHINE_CHECK: "1",
|
|
237
|
+
HQ_MACHINE_CHECKS_RUNNING: "1",
|
|
238
|
+
};
|
|
239
|
+
if (collectOnly)
|
|
240
|
+
scriptEnv.HQ_MACHINE_CHECK_COLLECT_ONLY = "1";
|
|
241
|
+
else
|
|
242
|
+
delete scriptEnv.HQ_MACHINE_CHECK_COLLECT_ONLY;
|
|
207
243
|
try {
|
|
208
244
|
child = spawn(shell, [file], {
|
|
209
245
|
cwd: hqRoot,
|
|
210
|
-
env:
|
|
211
|
-
...env,
|
|
212
|
-
CLAUDE_PROJECT_DIR: hqRoot,
|
|
213
|
-
HQ_ROOT: hqRoot,
|
|
214
|
-
HQ_MACHINE_CHECK: "1",
|
|
215
|
-
HQ_MACHINE_CHECKS_RUNNING: "1",
|
|
216
|
-
},
|
|
246
|
+
env: scriptEnv,
|
|
217
247
|
stdio: ["pipe", "pipe", "ignore"],
|
|
218
248
|
shell: false,
|
|
219
249
|
windowsHide: true,
|
|
@@ -269,7 +299,7 @@ async function runOne(spec, options, env, disabled, shell) {
|
|
|
269
299
|
const checked = checkMachineCheckScript(options.hqRoot, spec.path, options.platform ?? process.platform);
|
|
270
300
|
if (!checked.ok)
|
|
271
301
|
return { id: spec.id, status: "unknown", checked_at: at(), summary: checked.summary };
|
|
272
|
-
const run = await runScript(shell, checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS);
|
|
302
|
+
const run = await runScript(shell, checked.file, spec, path.resolve(options.hqRoot), env, options.killGraceMs ?? MACHINE_CHECK_KILL_GRACE_MS, options.drainMs ?? MACHINE_CHECK_DRAIN_MS, options.collectOnly === true && !(options.commitIds?.has(spec.id) ?? false));
|
|
273
303
|
if (run.outcome === "timed-out") {
|
|
274
304
|
return { id: spec.id, status: "unknown", checked_at: at(), summary: `timed out after ${Math.round(spec.timeoutMs / 1000)}s` };
|
|
275
305
|
}
|
|
@@ -399,6 +429,22 @@ export function machineChecksKillSwitchSet(env, home) {
|
|
|
399
429
|
export function machineChecksScheduleOn(env, home) {
|
|
400
430
|
return !machineChecksKillSwitchSet(env, home) && machineChecksCoreNextOn(env);
|
|
401
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* The checks to commit in this batch: each whose last result (the results
|
|
434
|
+
* file the native notice reads) carries a fingerprint the native notice has
|
|
435
|
+
* recorded as delivered, unless this schedule already committed that same
|
|
436
|
+
* fingerprint.
|
|
437
|
+
*/
|
|
438
|
+
export function machineChecksToCommit(previous, shown, committed) {
|
|
439
|
+
const out = new Map();
|
|
440
|
+
for (const result of previous) {
|
|
441
|
+
const print = result.fingerprint;
|
|
442
|
+
if (!print || !shown.has(print) || committed.get(result.id) === print)
|
|
443
|
+
continue;
|
|
444
|
+
out.set(result.id, print);
|
|
445
|
+
}
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
402
448
|
/**
|
|
403
449
|
* The daemon's machine-check timer. Each tick runs a batch only when the new
|
|
404
450
|
* hook core (`core.next`) is on for this machine and no kill switch is set;
|
|
@@ -409,6 +455,13 @@ export function machineChecksScheduleOn(env, home) {
|
|
|
409
455
|
* here would run them a second time and leave cooldown stamps that silence
|
|
410
456
|
* the legacy run, so neither path would show the finding. A batch already running finishes. A failed batch
|
|
411
457
|
* logs one line with the error's name only.
|
|
458
|
+
*
|
|
459
|
+
* When the installed core advertises collect-only support
|
|
460
|
+
* (machineCheckCollectOnlySupported), the batch runs its scripts in that mode
|
|
461
|
+
* and they write no delivery stamp. That also covers the split-HOME edge the
|
|
462
|
+
* ledger rule cannot see: the daemon's HOME passes the rule while the
|
|
463
|
+
* session's is refused, both run, and the session's legacy run still shows
|
|
464
|
+
* the finding. With an older core nothing changes.
|
|
412
465
|
*/
|
|
413
466
|
export function startMachineCheckSchedule(options) {
|
|
414
467
|
const now = options.now ?? (() => Date.now());
|
|
@@ -417,6 +470,8 @@ export function startMachineCheckSchedule(options) {
|
|
|
417
470
|
const enabled = options.enabled ?? machineChecksScheduleOn;
|
|
418
471
|
let lastStart;
|
|
419
472
|
let closed = false;
|
|
473
|
+
/** Check id to the fingerprint last committed for it (in memory; a restart may commit once more, which is harmless). */
|
|
474
|
+
const committed = new Map();
|
|
420
475
|
const tick = async () => {
|
|
421
476
|
try {
|
|
422
477
|
if (closed)
|
|
@@ -437,7 +492,36 @@ export function startMachineCheckSchedule(options) {
|
|
|
437
492
|
return;
|
|
438
493
|
}
|
|
439
494
|
lastStart = now();
|
|
440
|
-
|
|
495
|
+
// Q47: the batch only collects. A core that supports it leaves every
|
|
496
|
+
// delivery stamp to the session that shows the finding, so a batch can
|
|
497
|
+
// never silence a session that would otherwise have shown it.
|
|
498
|
+
//
|
|
499
|
+
// While the daemon owns the checks the native notice shows the finding
|
|
500
|
+
// and records only its fingerprint, never the script's own record
|
|
501
|
+
// (the setup nag's stamp, the desktop result claim, client-health's
|
|
502
|
+
// pending files). So a check whose last finding the notice has
|
|
503
|
+
// delivered runs once in normal mode, which writes that record. In the
|
|
504
|
+
// split-HOME edge the session's notice refused its ledger and recorded
|
|
505
|
+
// nothing, so the check stays collect-only and the legacy run shows it.
|
|
506
|
+
// If the owner flips from daemon to legacy between the notice's show
|
|
507
|
+
// and this commit, the legacy run finds the record unwritten and shows
|
|
508
|
+
// the finding once more, then writes the record itself: one repeat at
|
|
509
|
+
// most, inside one batch interval.
|
|
510
|
+
const collectOnly = (options.collectOnlySupported ?? machineCheckCollectOnlySupported)(hqRoot);
|
|
511
|
+
let commit = new Map();
|
|
512
|
+
if (collectOnly) {
|
|
513
|
+
const shown = (options.shownFingerprints ?? nativeNoticeShownFingerprints)(options.env, options.home);
|
|
514
|
+
if (shown.size > 0)
|
|
515
|
+
commit = machineChecksToCommit(readMachineCheckResults(options.resultsFile), shown, committed);
|
|
516
|
+
}
|
|
517
|
+
const results = await run({ hqRoot, env: options.env, resultsFile: options.resultsFile, collectOnly, commitIds: new Set(commit.keys()) });
|
|
518
|
+
// A commit run that timed out, crashed or exited non-zero may not have
|
|
519
|
+
// written the script's record. It is not marked committed, so the next
|
|
520
|
+
// batch that collects the same finding commits it again.
|
|
521
|
+
for (const [id, print] of commit) {
|
|
522
|
+
if (results.some((each) => each.id === id && each.status !== "unknown"))
|
|
523
|
+
committed.set(id, print);
|
|
524
|
+
}
|
|
441
525
|
}
|
|
442
526
|
catch (error) {
|
|
443
527
|
options.log("warn", `machine checks failed (${error instanceof Error ? error.name : "UnknownError"})`);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two merge sections of the daemon's state file (state-file.ts):
|
|
3
|
+
*
|
|
4
|
+
* - merge_holds: every repository merge hold record under
|
|
5
|
+
* <hqRoot>/workspace/lanes/holds, grouped by the company that owns it, with
|
|
6
|
+
* that company's `lanes.repo-merge-hold` flag;
|
|
7
|
+
* - merge_approvals: per session id, the conduct-link decision queue that
|
|
8
|
+
* gates the session's merges, the session's company, and whether the
|
|
9
|
+
* `lanes.review-before-merge` gate applies to it, with the lane review
|
|
10
|
+
* records.
|
|
11
|
+
*
|
|
12
|
+
* The native merge check in crates/hq-hook reads only these two sections and
|
|
13
|
+
* starts no process. It refuses every merge while a section is missing, has a
|
|
14
|
+
* missing or wrongly typed field, or its `refreshed_at` is older than
|
|
15
|
+
* min(max_age_seconds, 60) seconds, so whenever a decision cannot be made here
|
|
16
|
+
* the section (or the session) is written so the check refuses:
|
|
17
|
+
*
|
|
18
|
+
* - a hold file `hq lanes hold` would refuse, an unreadable holds folder, or
|
|
19
|
+
* an unreadable `lanes.repo-merge-hold` flag omits merge_holds;
|
|
20
|
+
* - an unreadable link folder omits merge_approvals;
|
|
21
|
+
* - a session the conduct gate covers (a link pointer and a decision queue)
|
|
22
|
+
* whose company cannot be resolved is written with queue_status
|
|
23
|
+
* "unreadable";
|
|
24
|
+
* - an unreadable `lanes.review-before-merge` flag writes review_required
|
|
25
|
+
* true with no reviews.
|
|
26
|
+
*
|
|
27
|
+
* Files are read through src/lib/safe-store.ts (a regular single-link file of
|
|
28
|
+
* this user in a folder no other user can write), except lane records and
|
|
29
|
+
* review records, which are read with their stores' own validating readers.
|
|
30
|
+
* Nothing here starts a process; the flags are read from the flag registry.
|
|
31
|
+
*/
|
|
32
|
+
import { type RepoMergeHold } from "../lanes/repo-merge-hold.js";
|
|
33
|
+
import { type LaneCompanyRef } from "../lanes/types.js";
|
|
34
|
+
export declare const MERGE_HOLDS_SCHEMA = "merge-holds.v1";
|
|
35
|
+
export declare const MERGE_APPROVALS_SCHEMA = "merge-approvals.v1";
|
|
36
|
+
/** Written as each section's max_age_seconds; the native check caps it at 60 anyway. */
|
|
37
|
+
export declare const MERGE_SECTION_MAX_AGE_SECONDS = 60;
|
|
38
|
+
/**
|
|
39
|
+
* How long after one refresh finishes the next starts. A section is refused
|
|
40
|
+
* past 60 s, so this plus two refresh durations (each bounded by
|
|
41
|
+
* MERGE_FLAG_READ_TIMEOUT_MS) stays under it.
|
|
42
|
+
*/
|
|
43
|
+
export declare const MERGE_SECTION_REFRESH_INTERVAL_MS = 15000;
|
|
44
|
+
/** A flag value is asked of the registry again after this long. */
|
|
45
|
+
export declare const MERGE_FLAG_TTL_MS = 30000;
|
|
46
|
+
/** A flag read that takes longer than this counts as unreadable. */
|
|
47
|
+
export declare const MERGE_FLAG_READ_TIMEOUT_MS = 12000;
|
|
48
|
+
export interface MergeHoldEntry {
|
|
49
|
+
repo: string;
|
|
50
|
+
reason: string;
|
|
51
|
+
set_at: string;
|
|
52
|
+
until: string;
|
|
53
|
+
released_at: string | null;
|
|
54
|
+
}
|
|
55
|
+
export interface MergeHoldsCompany {
|
|
56
|
+
slug: string;
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
holds: MergeHoldEntry[];
|
|
59
|
+
}
|
|
60
|
+
export interface MergeHoldsSection {
|
|
61
|
+
schema: typeof MERGE_HOLDS_SCHEMA;
|
|
62
|
+
refreshed_at: string;
|
|
63
|
+
max_age_seconds: number;
|
|
64
|
+
companies: Record<string, MergeHoldsCompany>;
|
|
65
|
+
}
|
|
66
|
+
export interface MergeDecision {
|
|
67
|
+
status: string;
|
|
68
|
+
ref: string;
|
|
69
|
+
answer: string;
|
|
70
|
+
}
|
|
71
|
+
export interface MergeReview {
|
|
72
|
+
repo: string;
|
|
73
|
+
pr: number;
|
|
74
|
+
head_sha: string;
|
|
75
|
+
}
|
|
76
|
+
export type MergeQueueStatus = "present" | "absent" | "unreadable";
|
|
77
|
+
export interface MergeApprovalSession {
|
|
78
|
+
company_uid: string;
|
|
79
|
+
company_slug: string;
|
|
80
|
+
link_id: string;
|
|
81
|
+
queue_status: MergeQueueStatus;
|
|
82
|
+
decisions: MergeDecision[];
|
|
83
|
+
review_required: boolean;
|
|
84
|
+
reviews: MergeReview[];
|
|
85
|
+
}
|
|
86
|
+
export interface MergeApprovalsSection {
|
|
87
|
+
schema: typeof MERGE_APPROVALS_SCHEMA;
|
|
88
|
+
refreshed_at: string;
|
|
89
|
+
max_age_seconds: number;
|
|
90
|
+
sessions: Record<string, MergeApprovalSession>;
|
|
91
|
+
}
|
|
92
|
+
export interface MergeSections {
|
|
93
|
+
merge_holds: MergeHoldsSection | null;
|
|
94
|
+
merge_approvals: MergeApprovalsSection | null;
|
|
95
|
+
}
|
|
96
|
+
/** A lanes flag for one company: its value, or null when it could not be read. */
|
|
97
|
+
export type MergeFlagReader = (flag: string, company: LaneCompanyRef) => Promise<boolean | null>;
|
|
98
|
+
export interface MergeSectionInput {
|
|
99
|
+
hqRoot: string;
|
|
100
|
+
/** Written as refreshed_at; take it before any file is read. */
|
|
101
|
+
now: Date;
|
|
102
|
+
readFlag: MergeFlagReader;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Every hold record, or null when any of them is one `hq lanes hold list`
|
|
106
|
+
* would refuse (unreadable, not JSON, invalid fields, or a file name that
|
|
107
|
+
* does not match its repository), or when the folder cannot be read.
|
|
108
|
+
*/
|
|
109
|
+
export declare function readMergeHoldRecords(hqRoot: string): RepoMergeHold[] | null;
|
|
110
|
+
/** The merge_holds section, or null to leave it out of the state file. */
|
|
111
|
+
export declare function buildMergeHoldsSection(input: MergeSectionInput): Promise<MergeHoldsSection | null>;
|
|
112
|
+
export interface FoldedQueue {
|
|
113
|
+
decisions: MergeDecision[];
|
|
114
|
+
/** Rows with an id whose latest state lacks a string status, ref or answer. */
|
|
115
|
+
skipped: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A conduct decision queue folded to the latest state of each row id, in
|
|
119
|
+
* first-seen order: later rows override earlier fields. Blank and unparseable
|
|
120
|
+
* lines (a torn last line among them) and rows without an id are skipped.
|
|
121
|
+
*/
|
|
122
|
+
export declare function foldDecisionQueue(text: string): FoldedQueue;
|
|
123
|
+
/** The merge_approvals section, or null to leave it out of the state file. */
|
|
124
|
+
export declare function buildMergeApprovalsSection(input: MergeSectionInput): Promise<MergeApprovalsSection | null>;
|
|
125
|
+
/** Both sections, read at `input.now`. A builder that throws leaves its section out. */
|
|
126
|
+
export declare function buildMergeSections(input: MergeSectionInput): Promise<MergeSections>;
|
|
127
|
+
export interface RegistryMergeFlagReaderOptions {
|
|
128
|
+
env: NodeJS.ProcessEnv;
|
|
129
|
+
ttlMs?: number;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
now?: () => number;
|
|
132
|
+
/** Test seam: one registry read; null when it could not be read. */
|
|
133
|
+
read?: (flag: string, company: LaneCompanyRef, env: NodeJS.ProcessEnv) => Promise<boolean | null>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Lanes flags as `hq lanes hold check` reads them (readLanesRegistryFlag: local
|
|
137
|
+
* override, then the registry, then its last-known-good cache on a transient
|
|
138
|
+
* failure), asked again after `ttlMs`. A read that fails, throws or takes
|
|
139
|
+
* longer than `timeoutMs` is null and is not kept.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createRegistryMergeFlagReader(options: RegistryMergeFlagReaderOptions): MergeFlagReader;
|
|
142
|
+
export interface MergeSectionRefresher {
|
|
143
|
+
/** The latest sections, each only while younger than its max age. */
|
|
144
|
+
latest(): MergeSections;
|
|
145
|
+
/** Build once now (tests); resolves when the result is kept. */
|
|
146
|
+
refresh(): Promise<void>;
|
|
147
|
+
close(): void;
|
|
148
|
+
}
|
|
149
|
+
export interface MergeSectionRefresherOptions {
|
|
150
|
+
/** The HQ root, or undefined when none is configured (both sections are left out). */
|
|
151
|
+
hqRoot: () => string | undefined;
|
|
152
|
+
readFlag: MergeFlagReader;
|
|
153
|
+
/** Called after each refresh, to rewrite the state file. */
|
|
154
|
+
onRefresh?: () => void;
|
|
155
|
+
intervalMs?: number;
|
|
156
|
+
wallClock?: () => Date;
|
|
157
|
+
/** Start the timer (default true). */
|
|
158
|
+
start?: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Rebuild both sections now and then every `intervalMs` after the previous
|
|
162
|
+
* build finished, and hand each result to `onRefresh`. Builds never overlap.
|
|
163
|
+
*/
|
|
164
|
+
export declare function startMergeSectionRefresh(options: MergeSectionRefresherOptions): MergeSectionRefresher;
|
|
165
|
+
//# sourceMappingURL=merge-sections.d.ts.map
|