@indigoai-us/hq-cli 5.345.218 → 5.345.220
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 +130 -0
- package/dist/command-catalog.generated.d.ts +94 -1
- package/dist/command-catalog.generated.js +114 -1
- package/dist/commands/agents.d.ts +22 -0
- package/dist/commands/agents.js +92 -1
- package/dist/commands/bot.d.ts +48 -0
- package/dist/commands/bot.js +108 -8
- package/dist/commands/cloud.d.ts +16 -0
- package/dist/commands/cloud.js +112 -102
- package/dist/commands/core-checkpoint-native.d.ts +13 -0
- package/dist/commands/core-checkpoint-native.js +167 -52
- package/dist/commands/core-hook-registration-plan.d.ts +8 -0
- package/dist/commands/core-hook-registration-plan.js +22 -0
- package/dist/commands/core.js +9 -0
- package/dist/commands/daemon.js +21 -2
- package/dist/commands/doctor.js +4 -0
- package/dist/commands/integrations.js +84 -3
- package/dist/commands/lanes-shared.d.ts +2 -0
- package/dist/commands/lanes-watch.js +28 -1
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +99 -9
- package/dist/commands/packs.js +23 -0
- package/dist/commands/pkg-update.d.ts +6 -0
- package/dist/commands/pkg-update.js +15 -7
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/run.js +55 -45
- package/dist/commands/sources.js +3 -2
- package/dist/index.js +8 -0
- package/dist/lib/anywhere-person-setting.d.ts +2 -2
- package/dist/lib/anywhere-person-setting.js +2 -2
- package/dist/lib/bot/fleet-cron.js +5 -2
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
- package/dist/lib/bot/run.d.ts +29 -5
- package/dist/lib/bot/run.js +203 -1
- package/dist/lib/bot/signals-try-now.d.ts +76 -0
- package/dist/lib/bot/signals-try-now.js +111 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
- package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
- package/dist/lib/capacity/scheduler.d.ts +8 -0
- package/dist/lib/capacity/scheduler.js +5 -2
- package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
- package/dist/lib/daemon/anywhere-listener.js +86 -4
- package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
- package/dist/lib/daemon/machine-check-owner.js +95 -0
- package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
- package/dist/lib/daemon/machine-check-registration.js +64 -0
- package/dist/lib/daemon/machine-checks.d.ts +144 -0
- package/dist/lib/daemon/machine-checks.js +412 -0
- package/dist/lib/daemon/run.js +35 -4
- package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
- package/dist/lib/daemon/runtime-notifications.js +50 -0
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +6 -0
- package/dist/lib/daemon/state-file.d.ts +12 -1
- package/dist/lib/daemon/state-file.js +23 -1
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +12 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +127 -0
- package/dist/lib/doctor/checks/host-core.js +3 -1
- package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
- package/dist/lib/doctor/checks/machine-checks.js +103 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/doctor/types.d.ts +4 -0
- package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
- package/dist/lib/hook-engine/canary-gate.js +147 -0
- package/dist/lib/hook-engine/coverage.d.ts +3 -1
- package/dist/lib/hook-engine/coverage.js +8 -2
- package/dist/lib/hook-engine/fleet-registration.d.ts +42 -0
- package/dist/lib/hook-engine/fleet-registration.js +168 -0
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
- package/dist/lib/hook-engine/registration-identity.js +97 -0
- package/dist/lib/hook-engine/registration.d.ts +1 -30
- package/dist/lib/hook-engine/registration.js +1 -88
- package/dist/lib/hook-engine/resolve.d.ts +2 -0
- package/dist/lib/hook-engine/resolve.js +7 -3
- package/dist/lib/hot-channels/alert.d.ts +10 -1
- package/dist/lib/hot-channels/alert.js +34 -7
- package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
- package/dist/lib/hot-channels/signals-claude-login.js +96 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +17 -0
- package/dist/lib/hot-channels/signals-pass.js +31 -3
- package/dist/lib/lanes/canonical-host.d.ts +8 -1
- package/dist/lib/lanes/canonical-host.js +9 -3
- package/dist/lib/lanes/machine-identity.d.ts +15 -0
- package/dist/lib/lanes/machine-identity.js +26 -0
- package/dist/lib/lanes/spawn.js +17 -3
- package/dist/lib/search-index/index.js +11 -1
- package/dist/lib/signals/engine.d.ts +1 -0
- package/dist/lib/signals/engine.js +7 -0
- package/dist/lib/signals/reply.d.ts +48 -0
- package/dist/lib/signals/reply.js +72 -11
- package/dist/lib/signals/steps/adapters.js +6 -0
- package/dist/lib/signals/steps/extract.d.ts +50 -3
- package/dist/lib/signals/steps/extract.js +100 -17
- package/dist/lib/signals/steps/types.d.ts +19 -0
- package/dist/lib/sync-core/engine-home.d.ts +6 -1
- package/dist/lib/sync-core/engine-home.js +13 -3
- package/dist/lib/sync-core/reconcile.js +1 -1
- package/dist/lib/sync-core/release-compare.d.ts +7 -0
- package/dist/lib/sync-core/release-compare.js +16 -0
- package/dist/lib/sync-core/release.d.ts +2 -1
- package/dist/lib/sync-core/release.js +2 -10
- package/dist/run/schema-env-overrides.d.ts +24 -0
- package/dist/run/schema-env-overrides.js +72 -0
- package/dist/utils/core-next-flag.d.ts +4 -0
- package/dist/utils/core-next-flag.js +22 -0
- package/dist/utils/core-next-kill.d.ts +16 -0
- package/dist/utils/core-next-kill.js +35 -0
- package/dist/utils/host-registration.d.ts +33 -23
- package/dist/utils/host-registration.js +90 -66
- package/package.json +14 -10
- package/scripts/check-function-manifest.mjs +5 -4
- package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
- package/dist/commands/__fixtures__/access-vault.js +0 -166
- package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
- package/dist/commands/__fixtures__/make-tar.js +0 -102
- package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
- package/dist/commands/secrets-public-types.test-d.js +0 -18
- package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
- package/dist/lib/decisions/fixtures/us001.js +0 -21
- package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
- package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
- package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
- package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
- package/dist/lib/fingerprint/fixtures.d.ts +0 -19
- package/dist/lib/fingerprint/fixtures.js +0 -61
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
- package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
- package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
- package/scripts/hook-engine-manifest.mjs +0 -22
- package/scripts/mesh-daemon-if-stale.mjs +0 -20
package/dist/lib/daemon/run.js
CHANGED
|
@@ -15,6 +15,7 @@ import { loadCachedTokens } from "@indigoai-us/hq-cloud";
|
|
|
15
15
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
16
16
|
import { anywhereRuntimeEnabled } from "../../commands/anywhere-runtime-flag.js";
|
|
17
17
|
import { anywhereRuntimeAllowed, readHqAnywherePersonSetting, stickyPersonSettingReader } from "../anywhere-person-setting.js";
|
|
18
|
+
import { watchRuntimeInputs } from "./runtime-notifications.js";
|
|
18
19
|
import { currentPackageUseLeaseInstall, currentPackageUseUpdateRequested } from "../../utils/package-use-lease.js";
|
|
19
20
|
import { isLocalDependencyInstall, resolveRunningInstall } from "../../utils/version-gate.js";
|
|
20
21
|
import { agentKitPaths } from "../agent-kit/paths.js";
|
|
@@ -32,6 +33,7 @@ import { daemonLanesReconcileHandler } from "../lanes/daemon-reconcile.js";
|
|
|
32
33
|
import { ensureDaemonLanesReconcileHandler } from "./lanes-reconcile-loader.js";
|
|
33
34
|
import { SUPERVISOR_HANDOFF_FLAG, createDaemonFlagSnapshotSource, readDaemonFlag } from "./flag.js";
|
|
34
35
|
import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
|
|
36
|
+
import { MACHINE_CHECKS_RESULT_FILE, readMachineCheckResults, startMachineCheckSchedule } from "./machine-checks.js";
|
|
35
37
|
import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
|
|
36
38
|
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
|
|
37
39
|
import { readLegacySyncEnv } from "./legacy-sync-env.js";
|
|
@@ -50,7 +52,7 @@ import { SELF_CHECK_RESULT_FILE, readSelfCheckResult } from "./selfcheck.js";
|
|
|
50
52
|
import { createDaemonStateWriter, daemonStateFilePath, defaultDaemonStateFilePath, readVaultAccessManifest, selfCheckMachineChecks, } from "./state-file.js";
|
|
51
53
|
import { hqdSocketPath } from "./protocol.js";
|
|
52
54
|
import { startHqdServer, syncHqdEnabledMarker } from "./server.js";
|
|
53
|
-
import { startHqdRuntimeListener } from "./anywhere-listener.js";
|
|
55
|
+
import { createHqdRuntimeEvents, observeHqdRuntimeFlag, startHqdRuntimeListener } from "./anywhere-listener.js";
|
|
54
56
|
import { heartbeatFile, startHeartbeat } from "./heartbeat.js";
|
|
55
57
|
import { daemonStartEnv } from "./hook-env.js";
|
|
56
58
|
import { createProtocolTail, ensureProtocolFifo, openProtocolWriter } from "./protocol-tail.js";
|
|
@@ -922,14 +924,37 @@ export async function runDaemon(opts) {
|
|
|
922
924
|
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
923
925
|
return readVaultAccessManifest(configured && fs.existsSync(configured) ? configured : undefined);
|
|
924
926
|
},
|
|
925
|
-
readMachineChecks: () =>
|
|
927
|
+
readMachineChecks: () => [
|
|
928
|
+
...selfCheckMachineChecks(readSelfCheckResult(path.join(paths.root, SELF_CHECK_RESULT_FILE))),
|
|
929
|
+
...readMachineCheckResults(path.join(paths.root, MACHINE_CHECKS_RESULT_FILE)),
|
|
930
|
+
],
|
|
931
|
+
});
|
|
932
|
+
// The hqd listener checks again when a shared read's HQ Anywhere answer
|
|
933
|
+
// changes, or the running server's runtime gate changes; it has no timer of
|
|
934
|
+
// its own beyond a rare fallback (anywhere-listener.ts).
|
|
935
|
+
const hqdRuntimeEvents = createHqdRuntimeEvents();
|
|
936
|
+
const observeHqdRuntime = observeHqdRuntimeFlag(() => hqdRuntimeEvents.emit());
|
|
937
|
+
const flagSnapshots = createDaemonFlagSnapshotSource({
|
|
938
|
+
onRead: (read, readEnv) => {
|
|
939
|
+
observeHqdRuntime(read, readEnv);
|
|
940
|
+
stateWriter.onRegistryRead(read, readEnv);
|
|
941
|
+
},
|
|
926
942
|
});
|
|
927
|
-
const flagSnapshots = createDaemonFlagSnapshotSource({ onRead: stateWriter.onRegistryRead });
|
|
928
943
|
const killSwitches = createDaemonKillSwitchMonitors({ env, log, snapshots: flagSnapshots });
|
|
929
944
|
const childBootstrapHandoffWatchFlag = killSwitches.childBootstrapHandoffWatch;
|
|
930
945
|
const lanesReconcileFileWatchFlag = killSwitches.lanesReconcileFileWatch;
|
|
931
946
|
const searchIndexRunnerOwnsIndexFlag = killSwitches.searchIndexRunnerOwnsIndex;
|
|
932
947
|
const syncProcessScanOnMissingFlag = killSwitches.syncProcessScanOnMissing;
|
|
948
|
+
const machineChecks = startMachineCheckSchedule({
|
|
949
|
+
env,
|
|
950
|
+
home,
|
|
951
|
+
log,
|
|
952
|
+
hqRoot: () => {
|
|
953
|
+
const configured = readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined);
|
|
954
|
+
return configured && fs.existsSync(configured) ? configured : undefined;
|
|
955
|
+
},
|
|
956
|
+
resultsFile: path.join(paths.root, MACHINE_CHECKS_RESULT_FILE),
|
|
957
|
+
});
|
|
933
958
|
let laneReconcileWatcher = null;
|
|
934
959
|
let laneReconcileWatcherRoot = null;
|
|
935
960
|
let laneReconcileWatchFailedRoot = null;
|
|
@@ -957,6 +982,7 @@ export async function runDaemon(opts) {
|
|
|
957
982
|
laneReconcileWatcher = null;
|
|
958
983
|
laneReconcileWatcherRoot = null;
|
|
959
984
|
killSwitches.close();
|
|
985
|
+
machineChecks.close();
|
|
960
986
|
flagSnapshots.close();
|
|
961
987
|
stateWriter.close();
|
|
962
988
|
};
|
|
@@ -1488,6 +1514,7 @@ export async function runDaemon(opts) {
|
|
|
1488
1514
|
hqRoot,
|
|
1489
1515
|
log,
|
|
1490
1516
|
flagSnapshots,
|
|
1517
|
+
onRuntimeChange: () => hqdRuntimeEvents.emit(),
|
|
1491
1518
|
onShutdown: () => hqdShutdown?.(),
|
|
1492
1519
|
reportError: reportHqdCrash,
|
|
1493
1520
|
observeError: (err) => tccEpermGuard.observe(err),
|
|
@@ -1506,10 +1533,14 @@ export async function runDaemon(opts) {
|
|
|
1506
1533
|
log,
|
|
1507
1534
|
});
|
|
1508
1535
|
},
|
|
1509
|
-
|
|
1536
|
+
subscribe: (notify) => hqdRuntimeEvents.subscribe(notify),
|
|
1510
1537
|
log: (error) => log("error", `hqd socket listener update failed: ${error.message ?? String(error)}`),
|
|
1511
1538
|
});
|
|
1539
|
+
// A sign-in or daemon config change can flip the hqd gate before the next
|
|
1540
|
+
// shared read; the watch wakes the listener so it checks now.
|
|
1541
|
+
const stopHqdInputWatch = watchRuntimeInputs([paths.configPath, path.join(home, ".hq", "cognito-tokens.json")], () => hqdRuntimeEvents.emit(), (error) => log("warn", `hqd runtime input watch failed: ${error instanceof Error ? error.name : "UnknownError"}`));
|
|
1512
1542
|
const closeHqd = () => {
|
|
1543
|
+
stopHqdInputWatch();
|
|
1513
1544
|
void hqdListener.close().catch((err) => log("warn", `hqd socket did not close cleanly: ${err.message}`));
|
|
1514
1545
|
};
|
|
1515
1546
|
return await new Promise((resolve) => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Watch the directories of the given files, so atomic replacement is seen.
|
|
2
|
+
* The interval only re-arms a watch that failed or whose directory did not
|
|
3
|
+
* exist yet; a newly armed watch reports a change, since the file may have
|
|
4
|
+
* appeared unseen. Missed events are covered by the hqd listener's own rare
|
|
5
|
+
* fallback check (anywhere-listener.ts), not here. */
|
|
6
|
+
export declare function watchRuntimeInputs(files: readonly string[], changed: () => void, onError: (error: unknown) => void, intervalMs?: number): () => void;
|
|
7
|
+
//# sourceMappingURL=runtime-notifications.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
/** Watch the directories of the given files, so atomic replacement is seen.
|
|
4
|
+
* The interval only re-arms a watch that failed or whose directory did not
|
|
5
|
+
* exist yet; a newly armed watch reports a change, since the file may have
|
|
6
|
+
* appeared unseen. Missed events are covered by the hqd listener's own rare
|
|
7
|
+
* fallback check (anywhere-listener.ts), not here. */
|
|
8
|
+
export function watchRuntimeInputs(files, changed, onError, intervalMs = 60_000) {
|
|
9
|
+
const watched = new Map();
|
|
10
|
+
const directories = [...new Set(files.map((file) => path.dirname(file)))];
|
|
11
|
+
let closed = false;
|
|
12
|
+
const arm = () => {
|
|
13
|
+
let armed = false;
|
|
14
|
+
for (const directory of directories) {
|
|
15
|
+
if (watched.has(directory))
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const watcher = fs.watch(directory, { persistent: false }, (_event, filename) => {
|
|
19
|
+
if (!filename || files.some((file) => path.dirname(file) === directory && path.basename(file) === filename.toString()))
|
|
20
|
+
changed();
|
|
21
|
+
});
|
|
22
|
+
watcher.on("error", (error) => {
|
|
23
|
+
watcher.close();
|
|
24
|
+
watched.delete(directory);
|
|
25
|
+
onError(error);
|
|
26
|
+
});
|
|
27
|
+
watcher.on("close", () => { watched.delete(directory); });
|
|
28
|
+
watched.set(directory, watcher);
|
|
29
|
+
armed = true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code !== "ENOENT")
|
|
33
|
+
onError(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return armed;
|
|
37
|
+
};
|
|
38
|
+
arm();
|
|
39
|
+
const timer = setInterval(() => { if (!closed && arm())
|
|
40
|
+
changed(); }, intervalMs);
|
|
41
|
+
timer.unref();
|
|
42
|
+
return () => {
|
|
43
|
+
closed = true;
|
|
44
|
+
clearInterval(timer);
|
|
45
|
+
for (const watcher of watched.values())
|
|
46
|
+
watcher.close();
|
|
47
|
+
watched.clear();
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=runtime-notifications.js.map
|
|
@@ -47,6 +47,8 @@ export interface HqdServerOptions {
|
|
|
47
47
|
personSettingReader?: () => Promise<boolean | null>;
|
|
48
48
|
/** The daemon's shared flag read, so this server's runtime gate adds no registry request of its own. */
|
|
49
49
|
flagSnapshots?: DaemonFlagSnapshotSource;
|
|
50
|
+
/** Told when this server's runtime gate (flag and person setting) changes, so the daemon's listener checks at once. */
|
|
51
|
+
onRuntimeChange?: (enabled: boolean) => void;
|
|
50
52
|
/** Test seam for the hosted Streamable HTTP MCP transport. */
|
|
51
53
|
mcpBridge?: HqMcpBridge;
|
|
52
54
|
/** Test seam for machine login while keeping production credentials off disk. */
|
|
@@ -411,6 +411,12 @@ export async function startHqdServer(opts) {
|
|
|
411
411
|
ephemeralMachineToken = undefined;
|
|
412
412
|
sessions.clear();
|
|
413
413
|
}
|
|
414
|
+
try {
|
|
415
|
+
opts.onRuntimeChange?.(enabled);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
log("warn", `hqd runtime change observer failed (${error instanceof Error ? error.name : "UnknownError"})`);
|
|
419
|
+
}
|
|
414
420
|
},
|
|
415
421
|
onReadError: (error) => {
|
|
416
422
|
log("warn", `hqd runtime flag refresh failed (${error instanceof Error ? error.name : "UnknownError"}); retaining the last decision only until its 60-second limit`);
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* list is enforced, and the granted paths with their permission. It is
|
|
11
11
|
* copied from <hqRoot>/.hq/vault-access.json, field by field;
|
|
12
12
|
* - machine_checks: the latest results of the machine checks the daemon has
|
|
13
|
-
* today (id, status, time, optional one-line summary
|
|
13
|
+
* today (id, status, time, optional one-line summary, and for a finding
|
|
14
|
+
* its text, cut to 4096 bytes, and a fingerprint the hook engine uses to
|
|
15
|
+
* show it once). The finding text can name local paths, so like the rest
|
|
16
|
+
* of the file it is never logged or sent.
|
|
14
17
|
*
|
|
15
18
|
* No token, key or other secret is written. The vault access list tells which
|
|
16
19
|
* companies and paths a person can reach, so the file lives in the per-host
|
|
@@ -64,7 +67,15 @@ export interface DaemonStateMachineCheck {
|
|
|
64
67
|
status: "ok" | "warn" | "fail" | "unknown";
|
|
65
68
|
checked_at: string;
|
|
66
69
|
summary?: string;
|
|
70
|
+
/** The finding text, at most MACHINE_CHECK_DETAIL_BYTES, cut on a UTF-8 boundary. */
|
|
71
|
+
detail?: string;
|
|
72
|
+
/** 64 lowercase hex characters; any other value is dropped. */
|
|
73
|
+
fingerprint?: string;
|
|
67
74
|
}
|
|
75
|
+
/** The longest machine-check `detail` written, in UTF-8 bytes. */
|
|
76
|
+
export declare const MACHINE_CHECK_DETAIL_BYTES = 4096;
|
|
77
|
+
/** `text` cut to at most `maxBytes` of UTF-8, never inside a character. */
|
|
78
|
+
export declare function cutUtf8(text: string, maxBytes: number): string;
|
|
68
79
|
export interface DaemonStateFile {
|
|
69
80
|
schema: typeof DAEMON_STATE_SCHEMA;
|
|
70
81
|
written_at: string;
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* list is enforced, and the granted paths with their permission. It is
|
|
11
11
|
* copied from <hqRoot>/.hq/vault-access.json, field by field;
|
|
12
12
|
* - machine_checks: the latest results of the machine checks the daemon has
|
|
13
|
-
* today (id, status, time, optional one-line summary
|
|
13
|
+
* today (id, status, time, optional one-line summary, and for a finding
|
|
14
|
+
* its text, cut to 4096 bytes, and a fingerprint the hook engine uses to
|
|
15
|
+
* show it once). The finding text can name local paths, so like the rest
|
|
16
|
+
* of the file it is never logged or sent.
|
|
14
17
|
*
|
|
15
18
|
* No token, key or other secret is written. The vault access list tells which
|
|
16
19
|
* companies and paths a person can reach, so the file lives in the per-host
|
|
@@ -54,6 +57,19 @@ const HOOK_ENGINE_PORT_MODES = new Set(["off", "shadow", "on"]);
|
|
|
54
57
|
const VAULT_PERMISSIONS = new Set(["read", "write", "admin"]);
|
|
55
58
|
const VAULT_ROLES = new Set(["owner", "admin", "member", "guest", "unknown"]);
|
|
56
59
|
const MACHINE_CHECK_STATUSES = new Set(["ok", "warn", "fail", "unknown"]);
|
|
60
|
+
/** The longest machine-check `detail` written, in UTF-8 bytes. */
|
|
61
|
+
export const MACHINE_CHECK_DETAIL_BYTES = 4096;
|
|
62
|
+
const FINGERPRINT = /^[0-9a-f]{64}$/;
|
|
63
|
+
/** `text` cut to at most `maxBytes` of UTF-8, never inside a character. */
|
|
64
|
+
export function cutUtf8(text, maxBytes) {
|
|
65
|
+
const bytes = Buffer.from(text, "utf8");
|
|
66
|
+
if (bytes.length <= maxBytes)
|
|
67
|
+
return bytes.toString("utf8");
|
|
68
|
+
let end = maxBytes;
|
|
69
|
+
while (end > 0 && (bytes[end] & 0xc0) === 0x80)
|
|
70
|
+
end -= 1;
|
|
71
|
+
return bytes.subarray(0, end).toString("utf8");
|
|
72
|
+
}
|
|
57
73
|
/** `HQ_STATE_FILE` when set (tests and isolated daemons), else `<daemon folder>/hq-state.json`. */
|
|
58
74
|
export function daemonStateFilePath(home, env = process.env) {
|
|
59
75
|
const explicit = env.HQ_STATE_FILE?.trim();
|
|
@@ -176,6 +192,12 @@ function machineChecksOf(results) {
|
|
|
176
192
|
status: result.status,
|
|
177
193
|
checked_at: result.checked_at,
|
|
178
194
|
...(typeof result.summary === "string" && result.summary ? { summary: result.summary.slice(0, 240) } : {}),
|
|
195
|
+
...(typeof result.detail === "string" && result.detail
|
|
196
|
+
? { detail: cutUtf8(result.detail, MACHINE_CHECK_DETAIL_BYTES) }
|
|
197
|
+
: {}),
|
|
198
|
+
...(typeof result.fingerprint === "string" && FINGERPRINT.test(result.fingerprint)
|
|
199
|
+
? { fingerprint: result.fingerprint }
|
|
200
|
+
: {}),
|
|
179
201
|
});
|
|
180
202
|
}
|
|
181
203
|
return out;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EngineCapabilities } from '../../../utils/host-registration.js';
|
|
2
|
+
import { type FleetHost } from '../../hook-engine/fleet-registration.js';
|
|
3
|
+
import type { CheckResult } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* One result per hq-fleet profile: per event, which core the bot runtime uses
|
|
6
|
+
* (`native`, `shell`, or `shell fallback` under a kill switch) and on which
|
|
7
|
+
* host (`fleet-local` or `agents-v2`). A native entry passes only when the
|
|
8
|
+
* engine advertises its host and covers every old hook for the event, and its
|
|
9
|
+
* fallback is that host's exact adapter command.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fleetHookCoreResults(home: string, env: NodeJS.ProcessEnv, inspect?: (engine: string, host: FleetHost) => EngineCapabilities): CheckResult[];
|
|
12
|
+
//# sourceMappingURL=fleet-hook-core.d.ts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** Read-only validation; fallback commands are never executed. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { load } from 'js-yaml';
|
|
5
|
+
import { coreNextKillReason, missingEvaluators } from '../../../utils/host-registration.js';
|
|
6
|
+
import { FLEET_ADAPTERS, FLEET_EVENTS, isFleetHost, literalArgv, fallbackProblem, inspectFleetEngine } from '../../hook-engine/fleet-registration.js';
|
|
7
|
+
import { uncoveredHooks } from '../../hook-engine/coverage.js';
|
|
8
|
+
/** The Fleet host whose shell adapter `argv` runs, if any. */
|
|
9
|
+
function shellHost(argv) {
|
|
10
|
+
if (argv[1] === 'run')
|
|
11
|
+
return undefined;
|
|
12
|
+
for (const host of Object.keys(FLEET_ADAPTERS)) {
|
|
13
|
+
if (argv.some(arg => path.basename(arg) === FLEET_ADAPTERS[host]))
|
|
14
|
+
return host;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One result per hq-fleet profile: per event, which core the bot runtime uses
|
|
20
|
+
* (`native`, `shell`, or `shell fallback` under a kill switch) and on which
|
|
21
|
+
* host (`fleet-local` or `agents-v2`). A native entry passes only when the
|
|
22
|
+
* engine advertises its host and covers every old hook for the event, and its
|
|
23
|
+
* fallback is that host's exact adapter command.
|
|
24
|
+
*/
|
|
25
|
+
export function fleetHookCoreResults(home, env, inspect = (engine, host) => inspectFleetEngine(engine, home, undefined, undefined, undefined, host)) {
|
|
26
|
+
const base = env.HQ_FLEET_HOME?.trim() || path.join(home, '.hq-fleet');
|
|
27
|
+
let profiles;
|
|
28
|
+
if (fs.existsSync(path.join(base, 'config.yaml')))
|
|
29
|
+
profiles = [base];
|
|
30
|
+
else {
|
|
31
|
+
try {
|
|
32
|
+
profiles = fs.readdirSync(path.join(base, 'profiles')).sort().map(name => path.join(base, 'profiles', name));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const results = [];
|
|
39
|
+
const cache = new Map();
|
|
40
|
+
for (const profile of profiles) {
|
|
41
|
+
const file = path.join(profile, 'config.yaml');
|
|
42
|
+
const name = path.basename(profile);
|
|
43
|
+
try {
|
|
44
|
+
if (!fs.lstatSync(file).isFile() || fs.lstatSync(file).isSymbolicLink())
|
|
45
|
+
continue;
|
|
46
|
+
const document = load(fs.readFileSync(file, 'utf8'));
|
|
47
|
+
const cores = {};
|
|
48
|
+
const hosts = {};
|
|
49
|
+
const problems = [];
|
|
50
|
+
for (const [event, entries] of Object.entries(document?.hooks ?? {})) {
|
|
51
|
+
if (!Array.isArray(entries))
|
|
52
|
+
continue;
|
|
53
|
+
const commands = entries.map(entry => literalArgv(String(entry?.command ?? ''))).filter((argv) => argv !== null);
|
|
54
|
+
const native = commands.filter(argv => path.basename(argv[0] ?? '') === 'hq-hook' && argv[1] === 'run' && argv[2] === '--host' && isFleetHost(argv[3]));
|
|
55
|
+
const shell = commands.filter(argv => shellHost(argv) !== undefined);
|
|
56
|
+
if (!native.length && !shell.length)
|
|
57
|
+
continue;
|
|
58
|
+
cores[event] = native.length ? 'native' : 'shell';
|
|
59
|
+
const seen = [...new Set([...native.map(argv => argv[3]), ...shell.map(argv => shellHost(argv))])];
|
|
60
|
+
hosts[event] = seen[0];
|
|
61
|
+
// fleet-local keeps its rule (a native entry alongside any other); any
|
|
62
|
+
// second entry where agents-v2 is involved is a duplicate too, so a
|
|
63
|
+
// toggle that leaves two adapter entries fails.
|
|
64
|
+
const duplicate = native.length ? shell.length > 0 || native.length > 1 : seen.includes('agents-v2') && shell.length > 1;
|
|
65
|
+
if (duplicate)
|
|
66
|
+
problems.push(`${event}: duplicate hook registrations`);
|
|
67
|
+
if (seen.length > 1)
|
|
68
|
+
problems.push(`${event}: registrations for more than one fleet host (${seen.join(', ')})`);
|
|
69
|
+
for (const argv of native) {
|
|
70
|
+
const host = argv[3];
|
|
71
|
+
const value = (flag) => { const index = argv.indexOf(flag); return index < 0 ? undefined : argv[index + 1]; };
|
|
72
|
+
const killed = coreNextKillReason(home, env);
|
|
73
|
+
if (killed) {
|
|
74
|
+
cores[event] = 'shell fallback';
|
|
75
|
+
problems.push(`${event}: kill switch is on (${killed}); re-render the profile`);
|
|
76
|
+
}
|
|
77
|
+
let fallback;
|
|
78
|
+
try {
|
|
79
|
+
fallback = JSON.parse(value('--fleet-fallback') ?? 'null');
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
fallback = null;
|
|
83
|
+
}
|
|
84
|
+
const invalid = fallbackProblem(fallback, host, event);
|
|
85
|
+
if (invalid)
|
|
86
|
+
problems.push(`${event}: ${invalid}`);
|
|
87
|
+
if (argv[4] !== event || !path.isAbsolute(value('--hq-root') ?? '')) {
|
|
88
|
+
problems.push(`${event}: malformed native event or HQ root`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const engine = argv[0];
|
|
92
|
+
const key = `${host}\0${engine}`;
|
|
93
|
+
let caps = cache.get(key);
|
|
94
|
+
if (!caps) {
|
|
95
|
+
try {
|
|
96
|
+
caps = inspect(engine, host);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
caps = error;
|
|
100
|
+
}
|
|
101
|
+
cache.set(key, caps);
|
|
102
|
+
}
|
|
103
|
+
if (caps instanceof Error) {
|
|
104
|
+
problems.push(`${event}: ${caps.message}`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const canonical = FLEET_EVENTS[event];
|
|
108
|
+
const missing = canonical ? missingEvaluators(caps, canonical) : null;
|
|
109
|
+
if (missing === null || missing.length)
|
|
110
|
+
problems.push(`${event}: required evaluators are missing`);
|
|
111
|
+
if (canonical) {
|
|
112
|
+
const left = uncoveredHooks(value('--hq-root'), host, canonical, caps.covers);
|
|
113
|
+
if (left.length)
|
|
114
|
+
problems.push(`${event}: uncovered hooks: ${left.join(', ')}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
results.push({ status: problems.length ? 'FAIL' : 'PASS', checkId: `fleet-hook-core:${name}`, target: file,
|
|
119
|
+
message: `Fleet profile ${name}: ${problems.length ? problems.join('; ') : Object.entries(cores).map(([event, core]) => `${event}=${core}${hosts[event] === 'agents-v2' ? ' (agents-v2)' : ''}`).join(', ') || 'no HQ hook registrations'}.`, details: { cores, problems, ...(Object.keys(hosts).length ? { hosts } : {}) } });
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
results.push({ status: 'WARN', checkId: `fleet-hook-core:${name}`, target: file, message: `Fleet profile ${name} hook configuration could not be read.` });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return results;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=fleet-hook-core.js.map
|
|
@@ -16,6 +16,7 @@ import { isAdapterEntry } from '../../install/codex-targets.js';
|
|
|
16
16
|
import { uncoveredHooks } from '../../hook-engine/coverage.js';
|
|
17
17
|
import { masterHookPath, shimPath } from '../../install/claude-targets.js';
|
|
18
18
|
import { CORE_NEXT_FLAG, CORE_NEXT_KILL_ENV, CORE_NEXT_KILL_FILE, ENGINE_KILL_ENV, ENGINE_KILL_FILE, REQUIRED_EVALUATORS, STABLE_LINK_NAME, coreNextEnabled, coreNextKillReason, missingEvaluators, probeEngine, } from '../../../utils/host-registration.js';
|
|
19
|
+
import { fleetHookCoreResults } from './fleet-hook-core.js';
|
|
19
20
|
import { HOOKS_FAMILY_ID } from '../registry.js';
|
|
20
21
|
export const HOST_CORE_FAMILY_ID = 'host-core';
|
|
21
22
|
export const HOST_CORE_FAMILY_TITLE = 'Hook core per host';
|
|
@@ -320,7 +321,8 @@ function exists(file) {
|
|
|
320
321
|
export async function hostCoreFamily(context, options = {}) {
|
|
321
322
|
return {
|
|
322
323
|
family: { id: HOST_CORE_FAMILY_ID, title: HOST_CORE_FAMILY_TITLE },
|
|
323
|
-
results: [coreSwitchResult(options), ...hostCoreResults(context.hqRoot, options)
|
|
324
|
+
results: [coreSwitchResult(options), ...hostCoreResults(context.hqRoot, options),
|
|
325
|
+
...fleetHookCoreResults(options.home ?? options.env?.HOME ?? os.homedir(), options.env ?? process.env)],
|
|
324
326
|
};
|
|
325
327
|
}
|
|
326
328
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Machine checks are cached for ordinary doctor runs. Explicit
|
|
2
|
+
* --only machine-checks runs repair-capable scripts and refreshes the cache. */
|
|
3
|
+
import { type MachineCheckResult, type RunMachineChecksOptions } from "../../daemon/machine-checks.js";
|
|
4
|
+
import type { CheckFamily } from "../types.js";
|
|
5
|
+
export declare const MACHINE_CHECKS_FAMILY_ID = "machine-checks";
|
|
6
|
+
export declare const MACHINE_CHECKS_FAMILY_TITLE = "Machine checks";
|
|
7
|
+
export interface MachineChecksFamilyDeps {
|
|
8
|
+
env: NodeJS.ProcessEnv;
|
|
9
|
+
run: (options: RunMachineChecksOptions) => Promise<MachineCheckResult[]>;
|
|
10
|
+
record: (file: string, results: readonly MachineCheckResult[]) => void;
|
|
11
|
+
}
|
|
12
|
+
/** Where to record the results: the daemon's results file when `hqRoot` is the daemon's root, else nowhere. */
|
|
13
|
+
export declare function machineCheckResultsFileFor(hqRoot: string, env: NodeJS.ProcessEnv): string | undefined;
|
|
14
|
+
export declare function createMachineChecksFamily(deps?: Partial<MachineChecksFamilyDeps>): CheckFamily;
|
|
15
|
+
export declare const machineChecksFamily: CheckFamily;
|
|
16
|
+
//# sourceMappingURL=machine-checks.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Machine checks are cached for ordinary doctor runs. Explicit
|
|
2
|
+
* --only machine-checks runs repair-capable scripts and refreshes the cache. */
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { readDaemonConfig } from "../../daemon/config.js";
|
|
5
|
+
import { MACHINE_CHECKS_RESULT_FILE, runMachineChecks, readMachineCheckResults, writeMachineCheckResults, } from "../../daemon/machine-checks.js";
|
|
6
|
+
import { sameHqRoot } from "../../hook-engine/registration-identity.js";
|
|
7
|
+
import { daemonPaths } from "../../daemon/paths.js";
|
|
8
|
+
export const MACHINE_CHECKS_FAMILY_ID = "machine-checks";
|
|
9
|
+
export const MACHINE_CHECKS_FAMILY_TITLE = "Machine checks";
|
|
10
|
+
/** Where to record the results: the daemon's results file when `hqRoot` is the daemon's root, else nowhere. */
|
|
11
|
+
export function machineCheckResultsFileFor(hqRoot, env) {
|
|
12
|
+
const paths = daemonPaths(env.HOME || env.USERPROFILE, env);
|
|
13
|
+
let configured;
|
|
14
|
+
try {
|
|
15
|
+
configured = readDaemonConfig(paths.configPath).hqRoot;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
configured = undefined;
|
|
19
|
+
}
|
|
20
|
+
const daemonRoot = configured ?? (env.HQ_ROOT?.trim() || undefined);
|
|
21
|
+
if (!daemonRoot || !sameHqRoot(daemonRoot, hqRoot))
|
|
22
|
+
return undefined;
|
|
23
|
+
return path.join(paths.root, MACHINE_CHECKS_RESULT_FILE);
|
|
24
|
+
}
|
|
25
|
+
function toCheckResult(result, verbose) {
|
|
26
|
+
const checkId = `machine-checks.${result.id}`;
|
|
27
|
+
if (result.status === "ok") {
|
|
28
|
+
return { status: "PASS", checkId, target: result.id, message: result.summary ?? "nothing to report" };
|
|
29
|
+
}
|
|
30
|
+
if (result.status === "unknown") {
|
|
31
|
+
return { status: "UNTESTED", checkId, target: result.id, message: result.summary ?? "could not be run" };
|
|
32
|
+
}
|
|
33
|
+
const summary = result.summary ?? "has a finding";
|
|
34
|
+
const detail = result.detail ?? "";
|
|
35
|
+
const shown = verbose && detail
|
|
36
|
+
? `${summary}\n${detail.split(/\r?\n/).map((line) => ` ${line}`).join("\n")}`
|
|
37
|
+
: summary;
|
|
38
|
+
return {
|
|
39
|
+
status: result.status === "fail" ? "FAIL" : "WARN",
|
|
40
|
+
checkId,
|
|
41
|
+
target: result.id,
|
|
42
|
+
message: shown,
|
|
43
|
+
details: {
|
|
44
|
+
...(result.detail !== undefined ? { detail: result.detail } : {}),
|
|
45
|
+
...(result.fingerprint !== undefined ? { fingerprint: result.fingerprint } : {}),
|
|
46
|
+
checkedAt: result.checked_at,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function createMachineChecksFamily(deps = {}) {
|
|
51
|
+
return {
|
|
52
|
+
id: MACHINE_CHECKS_FAMILY_ID,
|
|
53
|
+
title: MACHINE_CHECKS_FAMILY_TITLE,
|
|
54
|
+
async run(context) {
|
|
55
|
+
const env = deps.env ?? process.env;
|
|
56
|
+
if (env.HQ_MACHINE_CHECKS_RUNNING === "1") {
|
|
57
|
+
return [{
|
|
58
|
+
status: "UNTESTED",
|
|
59
|
+
checkId: "machine-checks.nested",
|
|
60
|
+
message: "nested run: hq doctor was started from inside a machine check, so none were run",
|
|
61
|
+
}];
|
|
62
|
+
}
|
|
63
|
+
const resultsFile = machineCheckResultsFileFor(context.hqRoot, env);
|
|
64
|
+
if (!context.runMachineChecks) {
|
|
65
|
+
const cached = resultsFile ? readMachineCheckResults(resultsFile) : [];
|
|
66
|
+
if (cached.length === 0)
|
|
67
|
+
return [{ status: "UNTESTED", checkId: "machine-checks.cached", message: "no scheduled results for this HQ root; run hq doctor --only machine-checks to run repair actions" }];
|
|
68
|
+
return cached.map((result) => {
|
|
69
|
+
const age = Math.max(0, Date.now() - Date.parse(result.checked_at));
|
|
70
|
+
const row = toCheckResult(result, context.verbose === true);
|
|
71
|
+
return { ...row, message: `${row.message} (cached, ${Math.floor(age / 1000)}s old)` };
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
let results;
|
|
75
|
+
try {
|
|
76
|
+
results = await (deps.run ?? runMachineChecks)({ hqRoot: context.hqRoot, env });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return [{
|
|
80
|
+
status: "UNKNOWN",
|
|
81
|
+
checkId: "machine-checks.run",
|
|
82
|
+
message: `the machine checks could not be run (${error instanceof Error ? error.name : "UnknownError"})`,
|
|
83
|
+
}];
|
|
84
|
+
}
|
|
85
|
+
const out = results.map((result) => toCheckResult(result, context.verbose === true));
|
|
86
|
+
if (resultsFile) {
|
|
87
|
+
try {
|
|
88
|
+
(deps.record ?? writeMachineCheckResults)(resultsFile, results);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
out.push({
|
|
92
|
+
status: "WARN",
|
|
93
|
+
checkId: "machine-checks.record",
|
|
94
|
+
message: `the results could not be recorded for the daemon (${error instanceof Error ? error.name : "UnknownError"})`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export const machineChecksFamily = createMachineChecksFamily();
|
|
103
|
+
//# sourceMappingURL=machine-checks.js.map
|
|
@@ -33,6 +33,7 @@ import { cliPathFamily } from "./checks/cli-path.js";
|
|
|
33
33
|
import { ps1ShimsFamily } from "./checks/ps1-shims.js";
|
|
34
34
|
import { tempHomesFamily } from "./checks/temp-homes.js";
|
|
35
35
|
import { replayRecorderFamily } from "./checks/replay-recorder.js";
|
|
36
|
+
import { machineChecksFamily } from "./checks/machine-checks.js";
|
|
36
37
|
import { fixtureCoverageFamily } from "./fixtures/discover.js";
|
|
37
38
|
import { checkClaudeWiring } from "./checks/claude-wiring.js";
|
|
38
39
|
/**
|
|
@@ -293,6 +294,9 @@ export function createDefaultRegistry() {
|
|
|
293
294
|
// Replay recorder (flag core.replay-recorder, off by default): whether hook
|
|
294
295
|
// events are being recorded on this machine and how much the store holds.
|
|
295
296
|
registry.register(replayRecorderFamily);
|
|
297
|
+
// Machine checks (US-016): the scripts the daemon runs on its schedule,
|
|
298
|
+
// run now for this HQ root; no daemon or socket needed.
|
|
299
|
+
registry.register(machineChecksFamily);
|
|
296
300
|
return registry;
|
|
297
301
|
}
|
|
298
302
|
//# sourceMappingURL=registry.js.map
|
|
@@ -84,6 +84,10 @@ export interface CheckContext {
|
|
|
84
84
|
* membership against. Absent reads `HQ_HOOK_PROFILE`, default `standard`.
|
|
85
85
|
*/
|
|
86
86
|
hookProfile?: string;
|
|
87
|
+
/** `--verbose`: families may add the full text of a finding to its message. */
|
|
88
|
+
verbose?: boolean;
|
|
89
|
+
/** Explicit repair-capable machine-check request. */
|
|
90
|
+
runMachineChecks?: boolean;
|
|
87
91
|
}
|
|
88
92
|
/**
|
|
89
93
|
* A check family: an id, a human title, and an async `run` returning per-item
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** The canary result record, under the home folder. */
|
|
2
|
+
export declare const HOST_CANARY_RECORD: string;
|
|
3
|
+
/** Schema of [`HOST_CANARY_RECORD`]. */
|
|
4
|
+
export declare const CANARY_RECORD_SCHEMA = "hq.host-canary-result.v1";
|
|
5
|
+
/** The hosts the canary runs and the switch covers. */
|
|
6
|
+
export declare const CANARY_HOSTS: readonly ["claude", "codex", "grok"];
|
|
7
|
+
export type CanaryHost = (typeof CANARY_HOSTS)[number];
|
|
8
|
+
/** The oldest canary run the gate accepts: seven days. */
|
|
9
|
+
export declare const CANARY_MAX_AGE_MS: number;
|
|
10
|
+
/** The override: switch events without a passing canary. */
|
|
11
|
+
export declare const SKIP_CANARY_GATE_ENV = "HQ_SKIP_HOST_CANARY_GATE";
|
|
12
|
+
/** The hq-core gate script whose hash a canary run is bound to. */
|
|
13
|
+
export declare const GATE_SCRIPT: string;
|
|
14
|
+
/** One host's last standard canary run. */
|
|
15
|
+
export interface CanaryHostResult {
|
|
16
|
+
passed: boolean;
|
|
17
|
+
/** When the run finished (ISO 8601). */
|
|
18
|
+
at: string;
|
|
19
|
+
/** The hq-hook version the run's registrations called; null when no event reached the new core. */
|
|
20
|
+
engineVersion: string | null;
|
|
21
|
+
/** SHA-256 of the root's hq-core gate script; null when the root has none. */
|
|
22
|
+
gateSha256: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface CanaryRecord {
|
|
25
|
+
schema: typeof CANARY_RECORD_SCHEMA;
|
|
26
|
+
hosts: Partial<Record<CanaryHost, CanaryHostResult>>;
|
|
27
|
+
}
|
|
28
|
+
/** SHA-256 of `<root>/.claude/hooks/policy-enforcement-gate.sh`, or null when it is absent. */
|
|
29
|
+
export declare function gateScriptSha256(root: string): string | null;
|
|
30
|
+
/** True when the override is set in `env`. */
|
|
31
|
+
export declare function canaryGateSkipped(env?: NodeJS.ProcessEnv): boolean;
|
|
32
|
+
/** The record at `<home>/.hq/state/host-canary.json`; null when there is none. Throws when it cannot be read or is not a record. */
|
|
33
|
+
export declare function readCanaryRecord(home: string): CanaryRecord | null;
|
|
34
|
+
export interface CanaryExpectation {
|
|
35
|
+
host: string;
|
|
36
|
+
/** The hq-hook version the switch would register. */
|
|
37
|
+
engineVersion: string;
|
|
38
|
+
/** The current root's gate hash ([`gateScriptSha256`]). */
|
|
39
|
+
gateSha256: string | null;
|
|
40
|
+
now?: number;
|
|
41
|
+
maxAgeMs?: number;
|
|
42
|
+
platform?: NodeJS.Platform;
|
|
43
|
+
}
|
|
44
|
+
/** Why `record` does not let `host` switch, or null when it does. */
|
|
45
|
+
export declare function canaryRefusal(record: CanaryRecord | null, expected: CanaryExpectation): string | null;
|
|
46
|
+
export interface CanaryGateOptions extends Omit<CanaryExpectation, 'gateSha256'> {
|
|
47
|
+
home: string;
|
|
48
|
+
root: string;
|
|
49
|
+
env?: NodeJS.ProcessEnv;
|
|
50
|
+
}
|
|
51
|
+
export interface CanaryGateResult {
|
|
52
|
+
allowed: boolean;
|
|
53
|
+
/** Why the canary does not allow the switch; null when it does. */
|
|
54
|
+
reason: string | null;
|
|
55
|
+
/** True when the override let a refused switch go on. */
|
|
56
|
+
skipped: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The gate for one host and HQ root: allowed when the record has a current
|
|
60
|
+
* passing canary for it, or when the override is set (then `skipped` is true
|
|
61
|
+
* and `reason` says what was bypassed). A record that cannot be read refuses.
|
|
62
|
+
*/
|
|
63
|
+
export declare function checkHostCanary(options: CanaryGateOptions): CanaryGateResult;
|
|
64
|
+
//# sourceMappingURL=canary-gate.d.ts.map
|