@indigoai-us/hq-cli 5.345.218 → 5.345.219
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 +78 -0
- package/dist/command-catalog.generated.d.ts +69 -0
- package/dist/command-catalog.generated.js +83 -0
- package/dist/commands/agents.d.ts +22 -0
- package/dist/commands/agents.js +92 -1
- package/dist/commands/core-hook-registration-plan.d.ts +8 -0
- package/dist/commands/core-hook-registration-plan.js +21 -0
- package/dist/commands/core.js +9 -0
- package/dist/commands/doctor.js +4 -0
- 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/reindex.js +6 -0
- 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/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 +30 -4
- 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 +4 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +103 -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 +30 -0
- package/dist/lib/hook-engine/fleet-registration.js +132 -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/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/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 +86 -66
- package/package.json +8 -8
|
@@ -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,4 @@
|
|
|
1
|
+
import { type EngineCapabilities } from '../../../utils/host-registration.js';
|
|
2
|
+
import type { CheckResult } from '../types.js';
|
|
3
|
+
export declare function fleetHookCoreResults(home: string, env: NodeJS.ProcessEnv, inspect?: (engine: string) => EngineCapabilities): CheckResult[];
|
|
4
|
+
//# sourceMappingURL=fleet-hook-core.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
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_EVENTS, literalArgv, fallbackProblem, inspectFleetEngine } from '../../hook-engine/fleet-registration.js';
|
|
7
|
+
import { uncoveredHooks } from '../../hook-engine/coverage.js';
|
|
8
|
+
export function fleetHookCoreResults(home, env, inspect = (engine) => inspectFleetEngine(engine, home)) {
|
|
9
|
+
const base = env.HQ_FLEET_HOME?.trim() || path.join(home, '.hq-fleet');
|
|
10
|
+
let profiles;
|
|
11
|
+
if (fs.existsSync(path.join(base, 'config.yaml')))
|
|
12
|
+
profiles = [base];
|
|
13
|
+
else {
|
|
14
|
+
try {
|
|
15
|
+
profiles = fs.readdirSync(path.join(base, 'profiles')).sort().map(name => path.join(base, 'profiles', name));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const results = [];
|
|
22
|
+
const cache = new Map();
|
|
23
|
+
for (const profile of profiles) {
|
|
24
|
+
const file = path.join(profile, 'config.yaml');
|
|
25
|
+
const name = path.basename(profile);
|
|
26
|
+
try {
|
|
27
|
+
if (!fs.lstatSync(file).isFile() || fs.lstatSync(file).isSymbolicLink())
|
|
28
|
+
continue;
|
|
29
|
+
const document = load(fs.readFileSync(file, 'utf8'));
|
|
30
|
+
const cores = {};
|
|
31
|
+
const problems = [];
|
|
32
|
+
for (const [event, entries] of Object.entries(document?.hooks ?? {})) {
|
|
33
|
+
if (!Array.isArray(entries))
|
|
34
|
+
continue;
|
|
35
|
+
const commands = entries.map(entry => literalArgv(String(entry?.command ?? ''))).filter((argv) => argv !== null);
|
|
36
|
+
const native = commands.filter(argv => path.basename(argv[0] ?? '') === 'hq-hook' && argv[1] === 'run' && argv[2] === '--host' && ['fleet-local', 'agents-v2'].includes(argv[3] ?? ''));
|
|
37
|
+
const shell = commands.filter(argv => argv.some(arg => path.basename(arg) === 'hq-fleet-local-hook-adapter.sh') && argv[1] !== 'run');
|
|
38
|
+
if (!native.length && !shell.length)
|
|
39
|
+
continue;
|
|
40
|
+
cores[event] = native.length ? 'native' : 'shell';
|
|
41
|
+
if (native.length && (shell.length || native.length > 1))
|
|
42
|
+
problems.push(`${event}: duplicate hook registrations`);
|
|
43
|
+
for (const argv of native) {
|
|
44
|
+
if (argv[3] === 'agents-v2') {
|
|
45
|
+
problems.push(`${event}: agents-v2 native registration is unsupported`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const value = (flag) => { const index = argv.indexOf(flag); return index < 0 ? undefined : argv[index + 1]; };
|
|
49
|
+
const killed = coreNextKillReason(home, env);
|
|
50
|
+
if (killed) {
|
|
51
|
+
cores[event] = 'shell fallback';
|
|
52
|
+
problems.push(`${event}: kill switch is on (${killed}); re-render the profile`);
|
|
53
|
+
}
|
|
54
|
+
let fallback;
|
|
55
|
+
try {
|
|
56
|
+
fallback = JSON.parse(value('--fleet-fallback') ?? 'null');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
fallback = null;
|
|
60
|
+
}
|
|
61
|
+
const invalid = fallbackProblem(fallback);
|
|
62
|
+
if (invalid)
|
|
63
|
+
problems.push(`${event}: ${invalid}`);
|
|
64
|
+
if (argv[4] !== event || !path.isAbsolute(value('--hq-root') ?? '')) {
|
|
65
|
+
problems.push(`${event}: malformed native event or HQ root`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const engine = argv[0];
|
|
69
|
+
let caps = cache.get(engine);
|
|
70
|
+
if (!caps) {
|
|
71
|
+
try {
|
|
72
|
+
caps = inspect(engine);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
caps = error;
|
|
76
|
+
}
|
|
77
|
+
cache.set(engine, caps);
|
|
78
|
+
}
|
|
79
|
+
if (caps instanceof Error) {
|
|
80
|
+
problems.push(`${event}: ${caps.message}`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const canonical = FLEET_EVENTS[event];
|
|
84
|
+
const missing = canonical ? missingEvaluators(caps, canonical) : null;
|
|
85
|
+
if (missing === null || missing.length)
|
|
86
|
+
problems.push(`${event}: required evaluators are missing`);
|
|
87
|
+
if (canonical) {
|
|
88
|
+
const left = uncoveredHooks(value('--hq-root'), 'fleet-local', canonical, caps.covers);
|
|
89
|
+
if (left.length)
|
|
90
|
+
problems.push(`${event}: uncovered hooks: ${left.join(', ')}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
results.push({ status: problems.length ? 'FAIL' : 'PASS', checkId: `fleet-hook-core:${name}`, target: file,
|
|
95
|
+
message: `Fleet profile ${name}: ${problems.length ? problems.join('; ') : Object.entries(cores).map(([event, core]) => `${event}=${core}`).join(', ') || 'no HQ hook registrations'}.`, details: { cores, problems } });
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
results.push({ status: 'WARN', checkId: `fleet-hook-core:${name}`, target: file, message: `Fleet profile ${name} hook configuration could not be read.` });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return results;
|
|
102
|
+
}
|
|
103
|
+
//# 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
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host canary gate (hq-core-rust US-019 criterion 4).
|
|
3
|
+
*
|
|
4
|
+
* `scripts/host-canary.mjs` runs a real Claude Code, Codex or Grok Build
|
|
5
|
+
* session against the hook core in a disposable copy of an HQ root. Before
|
|
6
|
+
* any event on a host is moved to the new core (the registration switch,
|
|
7
|
+
* US-017, and the flip, US-026) or the old core is deleted (US-027/028), a
|
|
8
|
+
* passing canary for that host must exist for:
|
|
9
|
+
*
|
|
10
|
+
* - the hq-hook engine version the switch would register (`hq-hook --version`);
|
|
11
|
+
* - the hq-core policy gate this HQ root ships
|
|
12
|
+
* (`.claude/hooks/policy-enforcement-gate.sh`, by SHA-256, the same hash
|
|
13
|
+
* the engine pins its gate port to; `null` when the root has none);
|
|
14
|
+
* - a run no older than [`CANARY_MAX_AGE_MS`].
|
|
15
|
+
*
|
|
16
|
+
* The canary keeps one small record per machine at
|
|
17
|
+
* `~/.hq/state/host-canary.json` ([`HOST_CANARY_RECORD`]): per host, whether
|
|
18
|
+
* the last standard run passed, when, and what it ran against. No paths,
|
|
19
|
+
* prompts, hook payloads, output or secrets go in it. The last run of a host
|
|
20
|
+
* replaces its entry, so a failure after a pass refuses again.
|
|
21
|
+
*
|
|
22
|
+
* Windows is never allowed: the canary does not run there yet, and the
|
|
23
|
+
* registration switch keeps Windows on the old core (US-022).
|
|
24
|
+
*
|
|
25
|
+
* The override, `HQ_SKIP_HOST_CANARY_GATE=1` (or `hq reindex
|
|
26
|
+
* --skip-host-canary-gate`), lets the switch go on without a passing canary
|
|
27
|
+
* and prints a warning that says so. The canary itself sets it for the
|
|
28
|
+
* reindex it runs on its disposable root: that reindex is what the canary
|
|
29
|
+
* tests.
|
|
30
|
+
*/
|
|
31
|
+
import { createHash } from 'node:crypto';
|
|
32
|
+
import * as fs from 'node:fs';
|
|
33
|
+
import * as path from 'node:path';
|
|
34
|
+
/** The canary result record, under the home folder. */
|
|
35
|
+
export const HOST_CANARY_RECORD = path.join('.hq', 'state', 'host-canary.json');
|
|
36
|
+
/** Schema of [`HOST_CANARY_RECORD`]. */
|
|
37
|
+
export const CANARY_RECORD_SCHEMA = 'hq.host-canary-result.v1';
|
|
38
|
+
/** The hosts the canary runs and the switch covers. */
|
|
39
|
+
export const CANARY_HOSTS = ['claude', 'codex', 'grok'];
|
|
40
|
+
/** The oldest canary run the gate accepts: seven days. */
|
|
41
|
+
export const CANARY_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
42
|
+
/** Clock skew tolerated for a run recorded in the future. */
|
|
43
|
+
const FUTURE_SKEW_MS = 5 * 60 * 1000;
|
|
44
|
+
/** The override: switch events without a passing canary. */
|
|
45
|
+
export const SKIP_CANARY_GATE_ENV = 'HQ_SKIP_HOST_CANARY_GATE';
|
|
46
|
+
/** The hq-core gate script whose hash a canary run is bound to. */
|
|
47
|
+
export const GATE_SCRIPT = path.join('.claude', 'hooks', 'policy-enforcement-gate.sh');
|
|
48
|
+
/** SHA-256 of `<root>/.claude/hooks/policy-enforcement-gate.sh`, or null when it is absent. */
|
|
49
|
+
export function gateScriptSha256(root) {
|
|
50
|
+
let bytes;
|
|
51
|
+
try {
|
|
52
|
+
bytes = fs.readFileSync(path.join(root, GATE_SCRIPT));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'ENOENT')
|
|
56
|
+
return null;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
60
|
+
}
|
|
61
|
+
/** True when the override is set in `env`. */
|
|
62
|
+
export function canaryGateSkipped(env = process.env) {
|
|
63
|
+
return /^(1|true|yes|on)$/i.test((env[SKIP_CANARY_GATE_ENV] ?? '').trim());
|
|
64
|
+
}
|
|
65
|
+
/** 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. */
|
|
66
|
+
export function readCanaryRecord(home) {
|
|
67
|
+
const file = path.join(home, HOST_CANARY_RECORD);
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = fs.readFileSync(file, 'utf8');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code === 'ENOENT')
|
|
74
|
+
return null;
|
|
75
|
+
throw new Error(`${file} cannot be read (${error.code ?? 'error'})`);
|
|
76
|
+
}
|
|
77
|
+
let doc;
|
|
78
|
+
try {
|
|
79
|
+
doc = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new Error(`${file} is not JSON`);
|
|
83
|
+
}
|
|
84
|
+
const record = doc;
|
|
85
|
+
if (!record || record.schema !== CANARY_RECORD_SCHEMA || !record.hosts || typeof record.hosts !== 'object' || Array.isArray(record.hosts)) {
|
|
86
|
+
throw new Error(`${file} is not a ${CANARY_RECORD_SCHEMA} record`);
|
|
87
|
+
}
|
|
88
|
+
return record;
|
|
89
|
+
}
|
|
90
|
+
/** Why `record` does not let `host` switch, or null when it does. */
|
|
91
|
+
export function canaryRefusal(record, expected) {
|
|
92
|
+
const { host, engineVersion, gateSha256 } = expected;
|
|
93
|
+
const platform = expected.platform ?? process.platform;
|
|
94
|
+
if (platform === 'win32')
|
|
95
|
+
return 'Windows host canaries are not supported yet';
|
|
96
|
+
if (!CANARY_HOSTS.includes(host))
|
|
97
|
+
return `${host} is not a host the canary runs`;
|
|
98
|
+
if (!record)
|
|
99
|
+
return `no host canary result (${HOST_CANARY_RECORD} is missing)`;
|
|
100
|
+
const result = record.hosts[host];
|
|
101
|
+
if (!result || typeof result !== 'object')
|
|
102
|
+
return `no host canary result for ${host}`;
|
|
103
|
+
if (result.passed !== true)
|
|
104
|
+
return `the last ${host} canary failed`;
|
|
105
|
+
if (result.engineVersion === null)
|
|
106
|
+
return `the last ${host} canary reached no event on the new core`;
|
|
107
|
+
if (result.engineVersion !== engineVersion) {
|
|
108
|
+
return `the last ${host} canary ran hq-hook ${String(result.engineVersion)}, not ${engineVersion}`;
|
|
109
|
+
}
|
|
110
|
+
if (result.gateSha256 !== gateSha256) {
|
|
111
|
+
return `the last ${host} canary ran hq-core gate ${short(result.gateSha256)}, not ${short(gateSha256)}`;
|
|
112
|
+
}
|
|
113
|
+
const at = typeof result.at === 'string' ? Date.parse(result.at) : Number.NaN;
|
|
114
|
+
if (!Number.isFinite(at))
|
|
115
|
+
return `the last ${host} canary has no valid time`;
|
|
116
|
+
const now = expected.now ?? Date.now();
|
|
117
|
+
const maxAgeMs = expected.maxAgeMs ?? CANARY_MAX_AGE_MS;
|
|
118
|
+
if (at > now + FUTURE_SKEW_MS)
|
|
119
|
+
return `the last ${host} canary is dated in the future (${result.at})`;
|
|
120
|
+
if (now - at > maxAgeMs) {
|
|
121
|
+
return `the last ${host} canary is from ${result.at}, older than ${Math.round(maxAgeMs / 3_600_000)} hours`;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function short(hash) {
|
|
126
|
+
return typeof hash === 'string' ? hash.slice(0, 12) : 'none';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The gate for one host and HQ root: allowed when the record has a current
|
|
130
|
+
* passing canary for it, or when the override is set (then `skipped` is true
|
|
131
|
+
* and `reason` says what was bypassed). A record that cannot be read refuses.
|
|
132
|
+
*/
|
|
133
|
+
export function checkHostCanary(options) {
|
|
134
|
+
let reason;
|
|
135
|
+
try {
|
|
136
|
+
reason = canaryRefusal(readCanaryRecord(options.home), { ...options, gateSha256: gateScriptSha256(options.root) });
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
reason = error.message;
|
|
140
|
+
}
|
|
141
|
+
if (!reason)
|
|
142
|
+
return { allowed: true, reason: null, skipped: false };
|
|
143
|
+
if (canaryGateSkipped(options.env))
|
|
144
|
+
return { allowed: true, reason, skipped: true };
|
|
145
|
+
return { allowed: false, reason, skipped: false };
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=canary-gate.js.map
|
|
@@ -7,7 +7,9 @@ export declare function shellHooks(root: string, host: CoreNextHost, event: stri
|
|
|
7
7
|
export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined): string[];
|
|
8
8
|
/**
|
|
9
9
|
* `target` narrowed to the events it covers in full on `host` in this HQ
|
|
10
|
-
* root; null when none is covered (every event stays on the old dispatcher)
|
|
10
|
+
* root; null when none is covered (every event stays on the old dispatcher),
|
|
11
|
+
* or when the target's host canary gate refuses `host` (US-019 criterion 4:
|
|
12
|
+
* no event on that host switches).
|
|
11
13
|
*/
|
|
12
14
|
export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost): CoreNextTarget | null;
|
|
13
15
|
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -113,12 +113,18 @@ export function uncoveredHooks(root, host, event, covers) {
|
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* `target` narrowed to the events it covers in full on `host` in this HQ
|
|
116
|
-
* root; null when none is covered (every event stays on the old dispatcher)
|
|
116
|
+
* root; null when none is covered (every event stays on the old dispatcher),
|
|
117
|
+
* or when the target's host canary gate refuses `host` (US-019 criterion 4:
|
|
118
|
+
* no event on that host switches).
|
|
117
119
|
*/
|
|
118
120
|
export function forHost(target, root, host) {
|
|
119
121
|
if (!target)
|
|
120
122
|
return null;
|
|
121
123
|
const events = target.events.filter((event) => uncoveredHooks(root, host, event, target.covers).length === 0);
|
|
122
|
-
|
|
124
|
+
if (!events.length)
|
|
125
|
+
return null;
|
|
126
|
+
if (target.canary && !target.canary(root, host))
|
|
127
|
+
return null;
|
|
128
|
+
return { ...target, events };
|
|
123
129
|
}
|
|
124
130
|
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { probeEngine, type CoreNextEngineLookup, type EngineCapabilities } from '../../utils/host-registration.js';
|
|
2
|
+
import { verifyHookEngine } from './resolve.js';
|
|
3
|
+
export declare const FLEET_EVENTS: Record<string, string>;
|
|
4
|
+
/** Literal POSIX argv only. Never expands variables or executes shell syntax. */
|
|
5
|
+
export declare function literalArgv(command: string): string[] | null;
|
|
6
|
+
export declare function fallbackProblem(argv: unknown): string | null;
|
|
7
|
+
export type FleetEngineLookup = CoreNextEngineLookup;
|
|
8
|
+
/** Self-check, then probe, then the fleet-local host claim. */
|
|
9
|
+
export declare function fleetEngineCapabilities(engine: string, probe?: typeof probeEngine, verify?: typeof verifyHookEngine): EngineCapabilities;
|
|
10
|
+
export declare function inspectFleetEngine(engine: string, home: string, probe?: typeof probeEngine, verify?: typeof verifyHookEngine, lookup?: FleetEngineLookup): EngineCapabilities;
|
|
11
|
+
export interface FleetPlanOptions {
|
|
12
|
+
home: string;
|
|
13
|
+
env?: NodeJS.ProcessEnv;
|
|
14
|
+
platform?: NodeJS.Platform;
|
|
15
|
+
inspect?: (engine: string) => EngineCapabilities;
|
|
16
|
+
/** Test injection. Production passes nothing and uses the desktop lookup. */
|
|
17
|
+
lookup?: FleetEngineLookup;
|
|
18
|
+
}
|
|
19
|
+
export interface FleetPlanEntry {
|
|
20
|
+
mode: 'native' | 'shell';
|
|
21
|
+
command: string;
|
|
22
|
+
argv: string[];
|
|
23
|
+
reason: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function fleetRegistrationPlan(root: string, fallbacks: Record<string, string[]>, options: FleetPlanOptions): {
|
|
26
|
+
schema: string;
|
|
27
|
+
host: string;
|
|
28
|
+
events: Record<string, FleetPlanEntry>;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=fleet-registration.d.ts.map
|