@indigoai-us/hq-cli 5.345.217 → 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 +105 -0
- package/README.md +1 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -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/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +1 -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-hq-session-native.js +3 -0
- package/dist/commands/core.js +9 -0
- package/dist/commands/doctor.js +4 -0
- package/dist/commands/install-global.js +1 -1
- 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/members.js +1 -1
- package/dist/commands/pack-start-bot.d.ts +1 -1
- package/dist/commands/pack-start-bot.js +2 -2
- package/dist/commands/pkg-update.js +1 -1
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/data/command-states.json +8 -1
- 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/billing/usage-cost.js +5 -2
- package/dist/lib/bot/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.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/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- 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/ops/policy.js +5 -3
- package/dist/lib/daemon/run.js +37 -5
- 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.d.ts +2 -0
- package/dist/lib/doctor/checks/host-core.js +81 -11
- 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/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/doctor/types.d.ts +4 -0
- package/dist/lib/environment/credential-shapes.d.ts +61 -0
- package/dist/lib/environment/credential-shapes.js +333 -0
- package/dist/lib/environment/profile.js +4 -16
- 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 +15 -0
- package/dist/lib/hook-engine/coverage.js +130 -0
- 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 +297 -116
- 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 -23
- package/dist/lib/hook-engine/registration.js +1 -52
- package/dist/lib/hook-engine/resolve.d.ts +2 -0
- package/dist/lib/hook-engine/resolve.js +7 -3
- package/dist/lib/install/claude-targets.js +28 -15
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.js +24 -11
- package/dist/lib/install/hook-target.d.ts +2 -2
- package/dist/lib/install/hook-target.js +7 -5
- 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/packages/setup-block.d.ts +2 -2
- package/dist/lib/packages/setup-block.js +2 -2
- package/dist/lib/packages/start-bot.d.ts +1 -1
- package/dist/lib/packages/start-bot.js +1 -1
- package/dist/main.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- 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/hook-trust.js +4 -1
- package/dist/utils/host-registration.d.ts +80 -17
- package/dist/utils/host-registration.js +194 -47
- package/package.json +8 -8
|
@@ -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
|
|
@@ -8,6 +8,8 @@ export interface HostRegistrationFile {
|
|
|
8
8
|
host: 'claude' | 'codex' | 'grok';
|
|
9
9
|
scope: 'project' | 'user';
|
|
10
10
|
file: string;
|
|
11
|
+
/** A file the host merges over `file` (Claude Code's `.claude/settings.local.json`), read with it. */
|
|
12
|
+
overlay?: string;
|
|
11
13
|
}
|
|
12
14
|
export interface HostCoreOptions {
|
|
13
15
|
home?: string;
|
|
@@ -13,15 +13,17 @@ import * as path from 'node:path';
|
|
|
13
13
|
import { jsonFormat } from '../../../commands/mcp-registration.js';
|
|
14
14
|
import { CORE_NEXT_LINK, isCoreNextEntry, isNativeEntry } from '../../hook-engine/registration.js';
|
|
15
15
|
import { isAdapterEntry } from '../../install/codex-targets.js';
|
|
16
|
+
import { uncoveredHooks } from '../../hook-engine/coverage.js';
|
|
16
17
|
import { masterHookPath, shimPath } from '../../install/claude-targets.js';
|
|
17
|
-
import { CORE_NEXT_FLAG, CORE_NEXT_KILL_ENV, CORE_NEXT_KILL_FILE, ENGINE_KILL_ENV, ENGINE_KILL_FILE, REQUIRED_EVALUATORS, STABLE_LINK_NAME, coreNextEnabled, missingEvaluators, probeEngine, } from '../../../utils/host-registration.js';
|
|
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';
|
|
18
20
|
import { HOOKS_FAMILY_ID } from '../registry.js';
|
|
19
21
|
export const HOST_CORE_FAMILY_ID = 'host-core';
|
|
20
22
|
export const HOST_CORE_FAMILY_TITLE = 'Hook core per host';
|
|
21
23
|
/** The registration files `hq reindex` reconciles, per host. */
|
|
22
24
|
export function hostRegistrationFiles(root, home, env) {
|
|
23
25
|
return [
|
|
24
|
-
{ host: 'claude', scope: 'project', file: path.join(root, '.claude', 'settings.json') },
|
|
26
|
+
{ host: 'claude', scope: 'project', file: path.join(root, '.claude', 'settings.json'), overlay: path.join(root, '.claude', 'settings.local.json') },
|
|
25
27
|
{ host: 'claude', scope: 'user', file: path.join(env.CLAUDE_CONFIG_DIR || path.join(home, '.claude'), 'settings.json') },
|
|
26
28
|
{ host: 'codex', scope: 'project', file: path.join(root, '.codex', 'hooks.json') },
|
|
27
29
|
{ host: 'codex', scope: 'user', file: path.join(env.CODEX_HOME || path.join(home, '.codex'), 'hooks.json') },
|
|
@@ -102,6 +104,7 @@ export function hostCoreResults(root, options = {}) {
|
|
|
102
104
|
const platform = options.platform ?? process.platform;
|
|
103
105
|
const probe = options.probe ?? probeEngine;
|
|
104
106
|
const flagOn = coreNextEnabled(env);
|
|
107
|
+
const killedBy = coreNextKillReason(home, env);
|
|
105
108
|
const probed = new Map();
|
|
106
109
|
const capabilities = (engine) => {
|
|
107
110
|
let found = probed.get(engine);
|
|
@@ -135,9 +138,14 @@ export function hostCoreResults(root, options = {}) {
|
|
|
135
138
|
return { status: 'FAIL', reason: `the new core lacks ${missing.join(', ')}` };
|
|
136
139
|
return { status: 'PASS', reason: `the new core has ${REQUIRED_EVALUATORS[event].join(', ')}` };
|
|
137
140
|
};
|
|
138
|
-
|
|
141
|
+
/** Old-dispatcher hooks for `event` on `host` that the engine's report does not cover. */
|
|
142
|
+
const uncovered = (caps, host, event) => uncoveredHooks(root, host, event, caps.covers);
|
|
143
|
+
const listed = (hooks) => (hooks.length > 6 ? `${hooks.slice(0, 6).join(', ')} and ${hooks.length - 6} more` : hooks.join(', '));
|
|
144
|
+
const oldCore = (event, host) => {
|
|
139
145
|
if (!flagOn)
|
|
140
146
|
return { status: 'PASS', reason: `flag ${CORE_NEXT_FLAG} is off` };
|
|
147
|
+
if (killedBy)
|
|
148
|
+
return { status: 'PASS', reason: `the kill switch is on (${killedBy})` };
|
|
141
149
|
if (platform === 'win32')
|
|
142
150
|
return { status: 'PASS', reason: 'Windows keeps the old registration until US-022' };
|
|
143
151
|
if (!REQUIRED_EVALUATORS[event])
|
|
@@ -148,6 +156,9 @@ export function hostCoreResults(root, options = {}) {
|
|
|
148
156
|
const missing = missingEvaluators(caps, event);
|
|
149
157
|
if (missing.length > 0)
|
|
150
158
|
return { status: 'PASS', reason: `the new core lacks ${missing.join(', ')}` };
|
|
159
|
+
const left = uncovered(caps, host, event);
|
|
160
|
+
if (left.length > 0)
|
|
161
|
+
return { status: 'PASS', reason: `the new core does not cover ${listed(left)}` };
|
|
151
162
|
return { status: 'WARN', reason: 'the new core can take this event; run hq reindex to switch it' };
|
|
152
163
|
};
|
|
153
164
|
const results = [];
|
|
@@ -169,19 +180,72 @@ export function hostCoreResults(root, options = {}) {
|
|
|
169
180
|
results.push({ status: 'WARN', checkId, target: target.file, message: `${target.host} (${target.scope}): registration file is not valid JSON` });
|
|
170
181
|
continue;
|
|
171
182
|
}
|
|
183
|
+
// Claude Code merges settings.local.json over settings.json and runs the
|
|
184
|
+
// entries of both, so an event's registrations are read from both.
|
|
185
|
+
let overlay;
|
|
186
|
+
if (target.overlay) {
|
|
187
|
+
let overlayText;
|
|
188
|
+
try {
|
|
189
|
+
overlayText = fs.readFileSync(target.overlay, 'utf8');
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Absent: nothing merged over.
|
|
193
|
+
overlayText = undefined;
|
|
194
|
+
}
|
|
195
|
+
if (overlayText !== undefined) {
|
|
196
|
+
try {
|
|
197
|
+
overlay = jsonFormat.parse(overlayText);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Claude Code cannot read it either; say so, since a new-core entry in it cannot be seen.
|
|
201
|
+
results.push({ status: 'WARN', checkId: `${checkId}-local`, target: target.overlay, message: `${target.host} (${target.scope}): ${path.basename(target.overlay)} is not valid JSON, so its hook entries cannot be checked; hq reindex reports it and leaves it as it is` });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const merged = new Map(eventEntries(doc));
|
|
206
|
+
for (const [event, entries] of eventEntries(overlay))
|
|
207
|
+
merged.set(event, [...(merged.get(event) ?? []), ...entries]);
|
|
172
208
|
const events = [];
|
|
173
209
|
const mixed = [];
|
|
174
|
-
for (const [event, entries] of
|
|
175
|
-
const
|
|
210
|
+
for (const [event, entries] of merged) {
|
|
211
|
+
const all = entries.map((entry) => classifyEntry(entry, target.host, root)).filter((k) => k !== null);
|
|
212
|
+
const kinds = [...new Set(all)];
|
|
176
213
|
if (kinds.length === 0)
|
|
177
214
|
continue;
|
|
215
|
+
if (kinds.includes('new-core')) {
|
|
216
|
+
// A switched event's new-core entry replaces the shell registration:
|
|
217
|
+
// the engine must do every hook the old dispatcher runs for it here.
|
|
218
|
+
const shell = kinds.filter((k) => k !== 'new-core');
|
|
219
|
+
let verdict;
|
|
220
|
+
if (killedBy) {
|
|
221
|
+
verdict = { status: 'FAIL', reason: `the kill switch is on (${killedBy}) but this event is still registered to the new core; run hq reindex to remove the new-core entry` };
|
|
222
|
+
}
|
|
223
|
+
else if (shell.length > 0) {
|
|
224
|
+
verdict = { status: 'FAIL', reason: `registered to the new core beside the ${shell.map((k) => label(k, target.host)).join(', ')}, so both run and the kill switch would run the old dispatcher twice` };
|
|
225
|
+
}
|
|
226
|
+
else if (all.filter((k) => k === 'new-core').length > 1) {
|
|
227
|
+
verdict = { status: 'WARN', reason: 'registered to the new core more than once, so its checks run twice' };
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
const engine = enginePathOf(entries, target.host, root);
|
|
231
|
+
verdict = newCore(event, engine);
|
|
232
|
+
const caps = verdict.status === 'PASS' && engine ? capabilities(engine) : undefined;
|
|
233
|
+
const left = caps && !(caps instanceof Error) ? uncovered(caps, target.host, event) : [];
|
|
234
|
+
if (left.length > 0)
|
|
235
|
+
verdict = { status: 'FAIL', reason: `the new core does not cover ${listed(left)}, so they do not run; run hq reindex to put this event back on the old dispatcher` };
|
|
236
|
+
}
|
|
237
|
+
if (verdict.status === 'WARN')
|
|
238
|
+
mixed.push(event);
|
|
239
|
+
events.push({ event, core: 'new-core', ...verdict });
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
178
242
|
if (kinds.length > 1) {
|
|
179
243
|
mixed.push(event);
|
|
180
|
-
events.push({ event, core: kinds
|
|
244
|
+
events.push({ event, core: kinds[0], status: 'WARN', reason: `two HQ registrations: ${kinds.map((k) => label(k, target.host)).join(', ')}` });
|
|
181
245
|
continue;
|
|
182
246
|
}
|
|
183
247
|
const core = kinds[0];
|
|
184
|
-
events.push({ event, core, ...(
|
|
248
|
+
events.push({ event, core, ...oldCore(event, target.host) });
|
|
185
249
|
}
|
|
186
250
|
if (events.length === 0) {
|
|
187
251
|
results.push({ status: 'NA', checkId, target: target.file, message: `${target.host} (${target.scope}): no HQ hook registered` });
|
|
@@ -207,7 +271,7 @@ export function hostCoreResults(root, options = {}) {
|
|
|
207
271
|
message: `${target.host} (${target.scope}): ${summary}`,
|
|
208
272
|
details: { ...(cores.length === 1 ? { core: cores[0] } : {}), cores, events },
|
|
209
273
|
...(failed.length > 0
|
|
210
|
-
? { remediation: `Run hq reindex: it puts ${failed.join(', ')} back on the old dispatcher when the new core cannot take them, or repairs the ${STABLE_LINK_NAME} link. Until then those events run no HQ hook,
|
|
274
|
+
? { remediation: `Run hq reindex: it puts ${failed.join(', ')} back on the old dispatcher when the new core cannot take them, or repairs the ${STABLE_LINK_NAME} link. It also puts an event back on the old dispatcher when the new core no longer covers every hook the old dispatcher runs for it, leaves one registration per event, and removes the new-core entries while the kill switch is on. Until then those events run no HQ hook, a new core without their guards, hooks twice, or none of the hooks the new core does not cover.` }
|
|
211
275
|
: mixed.length > 0
|
|
212
276
|
? { remediation: 'Run hq reindex to leave one HQ registration per event.' }
|
|
213
277
|
: {}),
|
|
@@ -235,9 +299,14 @@ export function coreSwitchResult(options = {}) {
|
|
|
235
299
|
].filter(Boolean);
|
|
236
300
|
const flag = `flag ${CORE_NEXT_FLAG} is ${on ? 'on' : 'off'}`;
|
|
237
301
|
const kill = killedBy.length
|
|
238
|
-
? `; kill switch on (${killedBy.join(', ')}): new-core registrations hand each event to the old dispatcher`
|
|
302
|
+
? `; kill switch on (${killedBy.join(', ')}): new-core registrations hand each event to the old dispatcher, and hq reindex removes them`
|
|
303
|
+
: '';
|
|
304
|
+
// The engine reads the kill switch from each hook's own environment; this
|
|
305
|
+
// check and hq reindex read it from theirs.
|
|
306
|
+
const hostEnv = on || killedBy.length
|
|
307
|
+
? `. ${CORE_NEXT_KILL_ENV} or ${ENGINE_KILL_ENV} set only in a host's environment (for example Claude Code settings env) is honored by the engine at run time only; hq reindex and this check do not see it, so use the file ${path.join('~', CORE_NEXT_KILL_FILE)} to switch the registrations back`
|
|
239
308
|
: '';
|
|
240
|
-
return { status: 'PASS', checkId: 'host-core:switch', message: `${flag}${kill}`, details: { flag: on, killSwitch: killedBy } };
|
|
309
|
+
return { status: 'PASS', checkId: 'host-core:switch', message: `${flag}${kill}${hostEnv}`, details: { flag: on, killSwitch: killedBy } };
|
|
241
310
|
}
|
|
242
311
|
function exists(file) {
|
|
243
312
|
try {
|
|
@@ -252,7 +321,8 @@ function exists(file) {
|
|
|
252
321
|
export async function hostCoreFamily(context, options = {}) {
|
|
253
322
|
return {
|
|
254
323
|
family: { id: HOST_CORE_FAMILY_ID, title: HOST_CORE_FAMILY_TITLE },
|
|
255
|
-
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)],
|
|
256
326
|
};
|
|
257
327
|
}
|
|
258
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
|
|
@@ -85,13 +85,13 @@ function receiverPermissionRemediation(byCall) {
|
|
|
85
85
|
const parts = [];
|
|
86
86
|
if (queueLeg) {
|
|
87
87
|
parts.push("The queue credentials vended by POST /v1/sync/subscribe were refused on the per-device queue leg; " +
|
|
88
|
-
"restart the sync runner so it re-subscribes, then run `hq sync status`. If it repeats, the device roster entry for this machine needs attention (hq-pro device slots).");
|
|
88
|
+
"restart the sync runner so it re-subscribes, then run `hq daemon sync status`. If it repeats, the device roster entry for this machine needs attention (hq-pro device slots).");
|
|
89
89
|
}
|
|
90
90
|
if (pullLeg) {
|
|
91
91
|
parts.push("The object pull after a change event was refused; see sync.runtime.pull-access-denied for the refused keys and the grant to compare.");
|
|
92
92
|
}
|
|
93
93
|
if (parts.length === 0) {
|
|
94
|
-
parts.push("Run `hq sync status` and inspect the selected sync log under ~/.hq/logs/, ~/.hq/daemon/logs/, or the configured HQ_DAEMON_DIR/logs/.");
|
|
94
|
+
parts.push("Run `hq daemon sync status` and inspect the selected sync log under ~/.hq/logs/, ~/.hq/daemon/logs/, or the configured HQ_DAEMON_DIR/logs/.");
|
|
95
95
|
}
|
|
96
96
|
return parts.join(" ");
|
|
97
97
|
}
|
|
@@ -313,7 +313,7 @@ export function analyzeSyncRuntimeLog(lines, options) {
|
|
|
313
313
|
message: check.message ?? `${check.count} ${check.label} in the last hour.`,
|
|
314
314
|
...(check.details ? { details: check.details } : {}),
|
|
315
315
|
remediation: check.remediation ??
|
|
316
|
-
"Run `hq sync status` and inspect the selected sync log under ~/.hq/logs/, ~/.hq/daemon/logs/, or the configured HQ_DAEMON_DIR/logs/.",
|
|
316
|
+
"Run `hq daemon sync status` and inspect the selected sync log under ~/.hq/logs/, ~/.hq/daemon/logs/, or the configured HQ_DAEMON_DIR/logs/.",
|
|
317
317
|
}
|
|
318
318
|
: {
|
|
319
319
|
status: "PASS",
|
|
@@ -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,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential shapes in environment profile text.
|
|
3
|
+
*
|
|
4
|
+
* What counts as a credential is decided by SECRET_PATTERNS in
|
|
5
|
+
* src/lib/core-utils/secret-patterns.ts, the list `hq core secret-scan` uses.
|
|
6
|
+
* This module does not keep a second set of shapes. It applies the shared
|
|
7
|
+
* expressions, unchanged, to bounded windows of the text, so that:
|
|
8
|
+
*
|
|
9
|
+
* - the result for a string is the result the shared list gives for it
|
|
10
|
+
* (`sharedShapesIn`, checked against `matchingSecretPatterns` in
|
|
11
|
+
* credential-equivalence.test.ts), and
|
|
12
|
+
* - the time is linear in the length of the string. Applied to one long
|
|
13
|
+
* string as a whole, the JWT expression restarts at every candidate and
|
|
14
|
+
* rescans to the end, which took 29 s for a 320 KB note.
|
|
15
|
+
*
|
|
16
|
+
* Windows.
|
|
17
|
+
*
|
|
18
|
+
* - Every expression except JWT is run on consecutive chunks of CHUNK
|
|
19
|
+
* characters that overlap by OVERLAP. A match of any of those expressions
|
|
20
|
+
* has a shortest form of at most 41 characters from its start (a prefix
|
|
21
|
+
* and a minimum count), so every match start lies in a chunk that holds
|
|
22
|
+
* that shortest form. The cost of one chunk is bounded by its size.
|
|
23
|
+
* - A JWT match is three dot-separated runs of [A-Za-z0-9_-]. Only the
|
|
24
|
+
* minimum counts (20, 20, 10) matter to the expression, so a long run can
|
|
25
|
+
* be cut after 64 characters without changing the answer. Each window is
|
|
26
|
+
* one piece of a first segment (at most 320 characters), the first 64
|
|
27
|
+
* characters of the next segment and the first 64 of the one after.
|
|
28
|
+
*
|
|
29
|
+
* Exemptions. Profile text is sentences, hostnames and labels, and a match
|
|
30
|
+
* rejects the profile. Three exemptions accept ordinary text that matches the
|
|
31
|
+
* shared list: a Slack prefix named in a sentence, a host name that starts
|
|
32
|
+
* with the key prefix letters, and an Authorization header followed by a
|
|
33
|
+
* secret's NAME. Each fails closed: it reads the whole white-space-delimited
|
|
34
|
+
* token and accepts only a closed form. Nothing else the shared list rejects
|
|
35
|
+
* is accepted here, and some ordinary text is rejected as the price of that.
|
|
36
|
+
*
|
|
37
|
+
* There is no exemption for a private key header. Any string that holds a
|
|
38
|
+
* BEGIN ... PRIVATE KEY line is rejected, as on main, with or without key
|
|
39
|
+
* material after it, because the body can sit in another string of the same
|
|
40
|
+
* profile. To mention a key in a profile, name its type in words.
|
|
41
|
+
*
|
|
42
|
+
* One rule is added to the shared list: a URL with an inline password.
|
|
43
|
+
*/
|
|
44
|
+
import { SECRET_PATTERNS } from "../core-utils/secret-patterns.js";
|
|
45
|
+
type SharedShapeName = (typeof SECRET_PATTERNS)[number]["name"];
|
|
46
|
+
declare const URL_PASSWORD = "URL with an inline password";
|
|
47
|
+
export type CredentialShapeName = SharedShapeName | typeof URL_PASSWORD;
|
|
48
|
+
export declare const CREDENTIAL_SHAPE_NAMES: CredentialShapeName[];
|
|
49
|
+
/**
|
|
50
|
+
* The shared shape names that match `text`, in the shared list's order: the
|
|
51
|
+
* same answer as `matchingSecretPatterns(text)`, computed on bounded windows.
|
|
52
|
+
*/
|
|
53
|
+
export declare function sharedShapesIn(text: string): SharedShapeName[];
|
|
54
|
+
/**
|
|
55
|
+
* The credential shapes present in `text` for the profile loader: the shared
|
|
56
|
+
* shapes, less the six ordinary-text exemptions, plus a URL with an inline
|
|
57
|
+
* password. Returns names, never the matched text.
|
|
58
|
+
*/
|
|
59
|
+
export declare function credentialShapesIn(text: string): CredentialShapeName[];
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=credential-shapes.d.ts.map
|