@indigoai-us/hq-cli 5.345.215 → 5.345.218
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 +168 -0
- package/README.md +46 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -0
- package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
- package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
- package/dist/command-catalog.generated.d.ts +59 -4
- package/dist/command-catalog.generated.js +74 -4
- package/dist/command-help.js +3 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +11 -52
- package/dist/commands/bot.js +11 -4
- package/dist/commands/cloud-demote.d.ts +19 -4
- package/dist/commands/cloud-demote.js +85 -12
- package/dist/commands/cloud-provision.d.ts +5 -1
- package/dist/commands/cloud-provision.js +6 -2
- package/dist/commands/cloud.d.ts +37 -1
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +4 -1
- package/dist/commands/dm.js +7 -0
- package/dist/commands/doctor-usage.d.ts +8 -0
- package/dist/commands/doctor-usage.js +20 -0
- package/dist/commands/doctor.js +7 -1
- package/dist/commands/env.d.ts +18 -0
- package/dist/commands/env.js +82 -0
- package/dist/commands/install-global.js +3 -3
- package/dist/commands/lanes.js +100 -24
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- 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/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +22 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +2 -1
- package/dist/lib/anywhere-person-setting.d.ts +2 -0
- package/dist/lib/anywhere-person-setting.js +6 -3
- package/dist/lib/billing/usage-card.d.ts +25 -4
- package/dist/lib/billing/usage-card.js +76 -9
- package/dist/lib/billing/usage-cost.d.ts +3 -3
- package/dist/lib/billing/usage-cost.js +40 -15
- package/dist/lib/billing/usage-only.js +4 -2
- package/dist/lib/billing/usage-rate-card.d.ts +2 -2
- package/dist/lib/billing/usage-rate-card.js +3 -0
- package/dist/lib/bot/fleet-cron.js +93 -6
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/inflight.js +10 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
- package/dist/lib/bot/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.js +2 -2
- package/dist/lib/bot/runtime/grok-acp.d.ts +1 -0
- package/dist/lib/bot/runtime/grok-acp.js +26 -11
- package/dist/lib/bot/runtime/grok.js +1 -1
- package/dist/lib/daemon/flag-monitor.d.ts +8 -0
- package/dist/lib/daemon/flag-monitor.js +17 -6
- package/dist/lib/daemon/flag.d.ts +65 -1
- package/dist/lib/daemon/flag.js +190 -40
- package/dist/lib/daemon/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/ops/policy.js +67 -8
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- package/dist/lib/daemon/run.js +32 -21
- package/dist/lib/daemon/selfcheck.d.ts +22 -0
- package/dist/lib/daemon/selfcheck.js +40 -1
- package/dist/lib/daemon/server.d.ts +3 -1
- package/dist/lib/daemon/server.js +7 -22
- package/dist/lib/daemon/state-file-switch.d.ts +57 -0
- package/dist/lib/daemon/state-file-switch.js +88 -0
- package/dist/lib/daemon/state-file.d.ts +198 -0
- package/dist/lib/daemon/state-file.js +419 -0
- package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/doctor/checks/host-core.d.ts +52 -0
- package/dist/lib/doctor/checks/host-core.js +337 -0
- package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
- package/dist/lib/doctor/checks/replay-recorder.js +261 -0
- package/dist/lib/doctor/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +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.d.ts +239 -0
- package/dist/lib/environment/profile.js +239 -0
- package/dist/lib/hook-engine/coverage.d.ts +13 -0
- package/dist/lib/hook-engine/coverage.js +124 -0
- package/dist/lib/hook-engine/reconcile.js +300 -94
- package/dist/lib/hook-engine/registration.d.ts +17 -1
- package/dist/lib/hook-engine/registration.js +62 -7
- package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
- package/dist/lib/hot-channels/adapters/slack.js +64 -21
- package/dist/lib/hot-channels/alert.d.ts +2 -0
- package/dist/lib/hot-channels/alert.js +8 -1
- package/dist/lib/hot-channels/contract.d.ts +12 -0
- package/dist/lib/hot-channels/contract.js +7 -0
- package/dist/lib/hot-channels/loop.js +1 -0
- package/dist/lib/hot-channels/run.d.ts +6 -0
- package/dist/lib/hot-channels/run.js +4 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +64 -1
- package/dist/lib/hot-channels/signals-pass.js +21 -49
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +70 -5
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +48 -5
- package/dist/lib/install/hook-target.d.ts +4 -1
- package/dist/lib/install/hook-target.js +14 -1
- package/dist/lib/lanes/canonical-host.d.ts +35 -0
- package/dist/lib/lanes/canonical-host.js +65 -0
- package/dist/lib/lanes/host-capacity.d.ts +30 -0
- package/dist/lib/lanes/host-capacity.js +29 -3
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +5 -2
- package/dist/lib/mesh/live/flush.d.ts +5 -1
- package/dist/lib/mesh/live/flush.js +12 -6
- package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
- package/dist/lib/mesh/live/reporting-privacy.js +56 -1
- package/dist/lib/mesh/live/spool.d.ts +7 -0
- package/dist/lib/mesh/live/spool.js +25 -0
- 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/lib/person-setting-cache.d.ts +38 -0
- package/dist/lib/person-setting-cache.js +98 -0
- package/dist/lib/safe-store.d.ts +245 -0
- package/dist/lib/safe-store.js +777 -0
- package/dist/lib/signals/engine.d.ts +29 -2
- package/dist/lib/signals/engine.js +103 -4
- package/dist/lib/signals/reply.js +73 -18
- package/dist/lib/signals/steps/adapters.js +7 -2
- package/dist/lib/signals/steps/extract.d.ts +13 -0
- package/dist/lib/signals/steps/extract.js +84 -4
- package/dist/main.js +47 -4
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- package/dist/utils/cli-telemetry.d.ts +21 -0
- package/dist/utils/cli-telemetry.js +34 -0
- package/dist/utils/command-usage.d.ts +275 -0
- package/dist/utils/command-usage.js +797 -0
- package/dist/utils/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +34 -4
- package/dist/utils/host-registration.d.ts +179 -0
- package/dist/utils/host-registration.js +505 -0
- package/dist/utils/resident-package-preload.js +2 -0
- package/package.json +10 -8
- package/scripts/bench-core.mjs +1096 -0
- package/scripts/check-function-manifest.mjs +702 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daemon's timed flag monitors: the four default-on kill switches read by
|
|
3
|
+
* the supervisor loop, and the HQ Anywhere runtime gate read by the hqd
|
|
4
|
+
* socket server. They are built here, apart from run.ts and server.ts, so the
|
|
5
|
+
* call-budget test (daemon-call-budget.test.ts) drives the same construction
|
|
6
|
+
* the daemon uses.
|
|
7
|
+
*
|
|
8
|
+
* Every monitor refreshes on the shared source's timer and reads the shared
|
|
9
|
+
* source's snapshot, so one 30-second tick costs one registry request however
|
|
10
|
+
* many flags are watched.
|
|
11
|
+
*/
|
|
12
|
+
import { HQ_ANYWHERE_RUNTIME_FLAG } from "../anywhere-runtime-flag-key.js";
|
|
13
|
+
import { readHqAnywherePersonSetting } from "../anywhere-person-setting.js";
|
|
14
|
+
import { createBoundedDaemonFlagMonitor, } from "./flag-monitor.js";
|
|
15
|
+
import { readDaemonFlag } from "./flag.js";
|
|
16
|
+
import { DAEMON_CHILD_BOOTSTRAP_HANDOFF_WATCH_FLAG, DAEMON_LANES_RECONCILE_FILE_WATCH_FLAG, DAEMON_SEARCH_INDEX_RUNNER_OWNS_INDEX_FLAG, DAEMON_SYNC_PROCESS_SCAN_ON_MISSING_FLAG, } from "./kill-switch-flags.js";
|
|
17
|
+
/** One default-on kill switch per daemon behavior that can be turned off from the registry. */
|
|
18
|
+
export function createDaemonKillSwitchMonitors(options) {
|
|
19
|
+
const { env, log, snapshots } = options;
|
|
20
|
+
const monitor = (flagKey) => createBoundedDaemonFlagMonitor({
|
|
21
|
+
fallback: true,
|
|
22
|
+
read: () => readDaemonFlag(flagKey, {
|
|
23
|
+
env,
|
|
24
|
+
fallback: true,
|
|
25
|
+
localOverrideMode: "ignore",
|
|
26
|
+
throwOnError: true,
|
|
27
|
+
...options.readOptions,
|
|
28
|
+
...(snapshots ? { snapshots } : {}),
|
|
29
|
+
}),
|
|
30
|
+
onReadError: (error) => log("warn", `could not read ${flagKey}; keeping its default-on behavior (${error instanceof Error ? error.name : "UnknownError"})`),
|
|
31
|
+
...(snapshots ? { scheduleRefresh: (tick) => snapshots.schedule(tick) } : {}),
|
|
32
|
+
});
|
|
33
|
+
const monitors = {
|
|
34
|
+
childBootstrapHandoffWatch: monitor(DAEMON_CHILD_BOOTSTRAP_HANDOFF_WATCH_FLAG),
|
|
35
|
+
lanesReconcileFileWatch: monitor(DAEMON_LANES_RECONCILE_FILE_WATCH_FLAG),
|
|
36
|
+
searchIndexRunnerOwnsIndex: monitor(DAEMON_SEARCH_INDEX_RUNNER_OWNS_INDEX_FLAG),
|
|
37
|
+
syncProcessScanOnMissing: monitor(DAEMON_SYNC_PROCESS_SCAN_ON_MISSING_FLAG),
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...monitors,
|
|
41
|
+
close() {
|
|
42
|
+
for (const each of Object.values(monitors))
|
|
43
|
+
each.close();
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** hqd's HQ Anywhere gate: the operator flag, then the person's own setting while the flag is on. */
|
|
48
|
+
export function createHqdRuntimeFlagMonitor(options) {
|
|
49
|
+
const { env, log, snapshots } = options;
|
|
50
|
+
return createBoundedDaemonFlagMonitor({
|
|
51
|
+
read: async () => {
|
|
52
|
+
const readOptions = {
|
|
53
|
+
env,
|
|
54
|
+
throwOnError: true,
|
|
55
|
+
// A local opt-out is honored, while a local opt-in cannot override the operator kill switch.
|
|
56
|
+
localOverrideMode: "off-only",
|
|
57
|
+
...(snapshots ? { snapshots } : {}),
|
|
58
|
+
};
|
|
59
|
+
const flagEnabled = await (options.runtimeFlagReader
|
|
60
|
+
? options.runtimeFlagReader(readOptions)
|
|
61
|
+
: readDaemonFlag(HQ_ANYWHERE_RUNTIME_FLAG, readOptions));
|
|
62
|
+
if (!flagEnabled)
|
|
63
|
+
return false;
|
|
64
|
+
const personSetting = await (options.personSettingReader ?? (() => readHqAnywherePersonSetting({
|
|
65
|
+
env,
|
|
66
|
+
onError: (name) => log("warn", `hqd person setting refresh failed (${name}); keeping HQ Anywhere off`),
|
|
67
|
+
})))();
|
|
68
|
+
return personSetting === true;
|
|
69
|
+
},
|
|
70
|
+
...(options.onChange ? { onChange: options.onChange } : {}),
|
|
71
|
+
...(options.onReadError ? { onReadError: options.onReadError } : {}),
|
|
72
|
+
...(snapshots ? { scheduleRefresh: (tick) => snapshots.schedule(tick) } : {}),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=timed-flag-monitors.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type EngineCapabilities } from '../../../utils/host-registration.js';
|
|
2
|
+
import type { CheckContext, CheckResult, FamilyRun } from '../types.js';
|
|
3
|
+
import { type DoctorRegistry } from '../registry.js';
|
|
4
|
+
export declare const HOST_CORE_FAMILY_ID = "host-core";
|
|
5
|
+
export declare const HOST_CORE_FAMILY_TITLE = "Hook core per host";
|
|
6
|
+
export type CoreKind = 'new-core' | 'launcher' | 'old-dispatcher';
|
|
7
|
+
export interface HostRegistrationFile {
|
|
8
|
+
host: 'claude' | 'codex' | 'grok';
|
|
9
|
+
scope: 'project' | 'user';
|
|
10
|
+
file: string;
|
|
11
|
+
/** A file the host merges over `file` (Claude Code's `.claude/settings.local.json`), read with it. */
|
|
12
|
+
overlay?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface HostCoreOptions {
|
|
15
|
+
home?: string;
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
platform?: NodeJS.Platform;
|
|
18
|
+
/** Reads an engine's capabilities; `probeEngine` by default. */
|
|
19
|
+
probe?: (engine: string) => EngineCapabilities;
|
|
20
|
+
}
|
|
21
|
+
/** The registration files `hq reindex` reconciles, per host. */
|
|
22
|
+
export declare function hostRegistrationFiles(root: string, home: string, env: NodeJS.ProcessEnv): HostRegistrationFile[];
|
|
23
|
+
/** Which core one HQ hook entry calls, or null when the entry is not HQ's. */
|
|
24
|
+
export declare function classifyEntry(entry: Record<string, unknown>, host: HostRegistrationFile['host'], root: string): CoreKind | null;
|
|
25
|
+
type Status = 'PASS' | 'WARN' | 'FAIL';
|
|
26
|
+
/** Which core one event of one registration file uses, and why. */
|
|
27
|
+
export interface EventCore {
|
|
28
|
+
event: string;
|
|
29
|
+
core: CoreKind;
|
|
30
|
+
status: Status;
|
|
31
|
+
reason: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One result per registration file, with each event's core and the reason
|
|
35
|
+
* for it. An event registered to the new core passes only when its engine
|
|
36
|
+
* runs and has every evaluator the event needs; a missing or dangling engine
|
|
37
|
+
* link, an engine that does not run, or a missing evaluator is FAIL with the
|
|
38
|
+
* fix. With the flag on, an event left on the old dispatcher says why.
|
|
39
|
+
*/
|
|
40
|
+
export declare function hostCoreResults(root: string, options?: HostCoreOptions): CheckResult[];
|
|
41
|
+
/** Flag and kill-switch state, shown once. */
|
|
42
|
+
export declare function coreSwitchResult(options?: HostCoreOptions): CheckResult;
|
|
43
|
+
/** The family `hq doctor` prints. */
|
|
44
|
+
export declare function hostCoreFamily(context: CheckContext, options?: HostCoreOptions): Promise<FamilyRun>;
|
|
45
|
+
/**
|
|
46
|
+
* The one call `hq doctor` makes on a run without `--only`: when the hook
|
|
47
|
+
* wiring family ran, add this family right after it. Registries without it
|
|
48
|
+
* (tests that register their own families) are left as they are.
|
|
49
|
+
*/
|
|
50
|
+
export declare function addHostCoreFamily(families: FamilyRun[], registry: Pick<DoctorRegistry, 'has'>, context: CheckContext, options?: HostCoreOptions): Promise<void>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=host-core.d.ts.map
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq doctor`: which core each host on this machine is using, per event, and
|
|
3
|
+
* why (hq-core-rust US-017). Reads the registration files `hq reindex` writes
|
|
4
|
+
* and the kill switch, and writes nothing. When an event is registered to the
|
|
5
|
+
* new core, or the flag is on, it starts the engine once (`--version` and
|
|
6
|
+
* `capabilities --json`) to see which evaluators it has. An event registered
|
|
7
|
+
* to a new core that is missing, does not run, or lacks the event's guards is
|
|
8
|
+
* FAIL; a host with no HQ registration is NA.
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as os from 'node:os';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import { jsonFormat } from '../../../commands/mcp-registration.js';
|
|
14
|
+
import { CORE_NEXT_LINK, isCoreNextEntry, isNativeEntry } from '../../hook-engine/registration.js';
|
|
15
|
+
import { isAdapterEntry } from '../../install/codex-targets.js';
|
|
16
|
+
import { uncoveredHooks } from '../../hook-engine/coverage.js';
|
|
17
|
+
import { masterHookPath, shimPath } from '../../install/claude-targets.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 { HOOKS_FAMILY_ID } from '../registry.js';
|
|
20
|
+
export const HOST_CORE_FAMILY_ID = 'host-core';
|
|
21
|
+
export const HOST_CORE_FAMILY_TITLE = 'Hook core per host';
|
|
22
|
+
/** The registration files `hq reindex` reconciles, per host. */
|
|
23
|
+
export function hostRegistrationFiles(root, home, env) {
|
|
24
|
+
return [
|
|
25
|
+
{ host: 'claude', scope: 'project', file: path.join(root, '.claude', 'settings.json'), overlay: path.join(root, '.claude', 'settings.local.json') },
|
|
26
|
+
{ host: 'claude', scope: 'user', file: path.join(env.CLAUDE_CONFIG_DIR || path.join(home, '.claude'), 'settings.json') },
|
|
27
|
+
{ host: 'codex', scope: 'project', file: path.join(root, '.codex', 'hooks.json') },
|
|
28
|
+
{ host: 'codex', scope: 'user', file: path.join(env.CODEX_HOME || path.join(home, '.codex'), 'hooks.json') },
|
|
29
|
+
{ host: 'grok', scope: 'user', file: path.join(home, '.grok', 'hooks', 'hq-hq-bridge.json') },
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
function hookEntries(doc) {
|
|
33
|
+
const hooks = doc?.hooks;
|
|
34
|
+
if (!hooks || typeof hooks !== 'object' || Array.isArray(hooks))
|
|
35
|
+
return [];
|
|
36
|
+
return Object.values(hooks).flatMap((groups) => Array.isArray(groups)
|
|
37
|
+
? groups.flatMap((g) => Array.isArray(g?.hooks) ? g.hooks.filter((h) => !!h && typeof h === 'object') : [])
|
|
38
|
+
: []);
|
|
39
|
+
}
|
|
40
|
+
/** Which core one HQ hook entry calls, or null when the entry is not HQ's. */
|
|
41
|
+
export function classifyEntry(entry, host, root) {
|
|
42
|
+
if (isCoreNextEntry(entry, root))
|
|
43
|
+
return 'new-core';
|
|
44
|
+
if (isNativeEntry(entry, root))
|
|
45
|
+
return 'launcher';
|
|
46
|
+
const command = entry.command;
|
|
47
|
+
if (typeof command !== 'string')
|
|
48
|
+
return null;
|
|
49
|
+
// A stable-path entry for another HQ root still calls the new core.
|
|
50
|
+
if (CORE_NEXT_LINK.test(command))
|
|
51
|
+
return 'new-core';
|
|
52
|
+
if (host === 'grok')
|
|
53
|
+
return command.includes('hq-hq-bridge.sh') ? 'old-dispatcher' : null;
|
|
54
|
+
if (host === 'codex') {
|
|
55
|
+
if (isAdapterEntry(entry, root))
|
|
56
|
+
return 'old-dispatcher';
|
|
57
|
+
return command.includes('hq-codex-hook-adapter.sh') ? 'old-dispatcher' : null;
|
|
58
|
+
}
|
|
59
|
+
return command.includes('master-hook.sh') || command.includes(masterHookPath(root)) || command.includes(shimPath(root)) ? 'old-dispatcher' : null;
|
|
60
|
+
}
|
|
61
|
+
const OLD_DISPATCHER = {
|
|
62
|
+
claude: 'old dispatcher (master-hook.sh)',
|
|
63
|
+
codex: 'old dispatcher (Codex hook adapter)',
|
|
64
|
+
grok: 'old dispatcher (Grok bash bridge)',
|
|
65
|
+
};
|
|
66
|
+
function label(kind, host) {
|
|
67
|
+
if (kind === 'new-core')
|
|
68
|
+
return 'new core (hq-hook run)';
|
|
69
|
+
if (kind === 'launcher')
|
|
70
|
+
return 'old dispatcher through the pinned hq-hook launcher';
|
|
71
|
+
return OLD_DISPATCHER[host];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The engine path a new-core entry runs: the command itself in exec form, or
|
|
75
|
+
* the first single-quoted word of a command string (POSIX or PowerShell form).
|
|
76
|
+
*/
|
|
77
|
+
function enginePathOf(entries, host, root) {
|
|
78
|
+
const entry = entries.find((e) => classifyEntry(e, host, root) === 'new-core');
|
|
79
|
+
const command = entry?.command;
|
|
80
|
+
if (typeof command !== 'string')
|
|
81
|
+
return undefined;
|
|
82
|
+
if (Array.isArray(entry.args))
|
|
83
|
+
return command;
|
|
84
|
+
const quoted = command.match(/^(?:& )?'((?:[^']|'\\'')*)'/)?.[1];
|
|
85
|
+
return quoted?.replace(/'\\''/g, "'");
|
|
86
|
+
}
|
|
87
|
+
const RANK = { PASS: 0, WARN: 1, FAIL: 2 };
|
|
88
|
+
/** The stable engine path for this platform (what a new-core registration names). */
|
|
89
|
+
function defaultStableEngine(home, platform) {
|
|
90
|
+
const binary = platform === 'darwin' ? path.join('hq-hook.app', 'Contents', 'MacOS', 'hq-hook') : 'hq-hook';
|
|
91
|
+
return path.join(home, '.hq', 'bin', 'hq-hook', STABLE_LINK_NAME, binary);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* One result per registration file, with each event's core and the reason
|
|
95
|
+
* for it. An event registered to the new core passes only when its engine
|
|
96
|
+
* runs and has every evaluator the event needs; a missing or dangling engine
|
|
97
|
+
* link, an engine that does not run, or a missing evaluator is FAIL with the
|
|
98
|
+
* fix. With the flag on, an event left on the old dispatcher says why.
|
|
99
|
+
*/
|
|
100
|
+
export function hostCoreResults(root, options = {}) {
|
|
101
|
+
const env = options.env ?? process.env;
|
|
102
|
+
const home = options.home ?? env.HOME ?? os.homedir();
|
|
103
|
+
const platform = options.platform ?? process.platform;
|
|
104
|
+
const probe = options.probe ?? probeEngine;
|
|
105
|
+
const flagOn = coreNextEnabled(env);
|
|
106
|
+
const killedBy = coreNextKillReason(home, env);
|
|
107
|
+
const probed = new Map();
|
|
108
|
+
const capabilities = (engine) => {
|
|
109
|
+
let found = probed.get(engine);
|
|
110
|
+
if (!found) {
|
|
111
|
+
try {
|
|
112
|
+
found = probe(engine);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
found = error;
|
|
116
|
+
}
|
|
117
|
+
probed.set(engine, found);
|
|
118
|
+
}
|
|
119
|
+
return found;
|
|
120
|
+
};
|
|
121
|
+
const newCore = (event, engine) => {
|
|
122
|
+
if (!engine)
|
|
123
|
+
return { status: 'FAIL', reason: 'the registration names no engine path' };
|
|
124
|
+
try {
|
|
125
|
+
fs.realpathSync(engine);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return { status: 'FAIL', reason: `${engine} does not resolve (missing or dangling ${STABLE_LINK_NAME} link), so this event has no hook running` };
|
|
129
|
+
}
|
|
130
|
+
const caps = capabilities(engine);
|
|
131
|
+
if (caps instanceof Error)
|
|
132
|
+
return { status: 'FAIL', reason: `the engine does not run (${caps.message})` };
|
|
133
|
+
const missing = missingEvaluators(caps, event);
|
|
134
|
+
if (missing === null)
|
|
135
|
+
return { status: 'FAIL', reason: 'no new-core port of the old hooks for this event' };
|
|
136
|
+
if (missing.length > 0)
|
|
137
|
+
return { status: 'FAIL', reason: `the new core lacks ${missing.join(', ')}` };
|
|
138
|
+
return { status: 'PASS', reason: `the new core has ${REQUIRED_EVALUATORS[event].join(', ')}` };
|
|
139
|
+
};
|
|
140
|
+
/** Old-dispatcher hooks for `event` on `host` that the engine's report does not cover. */
|
|
141
|
+
const uncovered = (caps, host, event) => uncoveredHooks(root, host, event, caps.covers);
|
|
142
|
+
const listed = (hooks) => (hooks.length > 6 ? `${hooks.slice(0, 6).join(', ')} and ${hooks.length - 6} more` : hooks.join(', '));
|
|
143
|
+
const oldCore = (event, host) => {
|
|
144
|
+
if (!flagOn)
|
|
145
|
+
return { status: 'PASS', reason: `flag ${CORE_NEXT_FLAG} is off` };
|
|
146
|
+
if (killedBy)
|
|
147
|
+
return { status: 'PASS', reason: `the kill switch is on (${killedBy})` };
|
|
148
|
+
if (platform === 'win32')
|
|
149
|
+
return { status: 'PASS', reason: 'Windows keeps the old registration until US-022' };
|
|
150
|
+
if (!REQUIRED_EVALUATORS[event])
|
|
151
|
+
return { status: 'PASS', reason: 'no new-core port of the old hooks for this event yet' };
|
|
152
|
+
const caps = capabilities(defaultStableEngine(home, platform));
|
|
153
|
+
if (caps instanceof Error)
|
|
154
|
+
return { status: 'PASS', reason: `the new core is not available (${caps.message})` };
|
|
155
|
+
const missing = missingEvaluators(caps, event);
|
|
156
|
+
if (missing.length > 0)
|
|
157
|
+
return { status: 'PASS', reason: `the new core lacks ${missing.join(', ')}` };
|
|
158
|
+
const left = uncovered(caps, host, event);
|
|
159
|
+
if (left.length > 0)
|
|
160
|
+
return { status: 'PASS', reason: `the new core does not cover ${listed(left)}` };
|
|
161
|
+
return { status: 'WARN', reason: 'the new core can take this event; run hq reindex to switch it' };
|
|
162
|
+
};
|
|
163
|
+
const results = [];
|
|
164
|
+
for (const target of hostRegistrationFiles(root, home, env)) {
|
|
165
|
+
const checkId = `host-core:${target.host}-${target.scope}`;
|
|
166
|
+
let text;
|
|
167
|
+
try {
|
|
168
|
+
text = fs.readFileSync(target.file, 'utf8');
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
results.push({ status: 'NA', checkId, target: target.file, message: `${target.host} (${target.scope}): no registration file` });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
let doc;
|
|
175
|
+
try {
|
|
176
|
+
doc = jsonFormat.parse(text);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
results.push({ status: 'WARN', checkId, target: target.file, message: `${target.host} (${target.scope}): registration file is not valid JSON` });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// Claude Code merges settings.local.json over settings.json and runs the
|
|
183
|
+
// entries of both, so an event's registrations are read from both.
|
|
184
|
+
let overlay;
|
|
185
|
+
if (target.overlay) {
|
|
186
|
+
let overlayText;
|
|
187
|
+
try {
|
|
188
|
+
overlayText = fs.readFileSync(target.overlay, 'utf8');
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// Absent: nothing merged over.
|
|
192
|
+
overlayText = undefined;
|
|
193
|
+
}
|
|
194
|
+
if (overlayText !== undefined) {
|
|
195
|
+
try {
|
|
196
|
+
overlay = jsonFormat.parse(overlayText);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// Claude Code cannot read it either; say so, since a new-core entry in it cannot be seen.
|
|
200
|
+
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` });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const merged = new Map(eventEntries(doc));
|
|
205
|
+
for (const [event, entries] of eventEntries(overlay))
|
|
206
|
+
merged.set(event, [...(merged.get(event) ?? []), ...entries]);
|
|
207
|
+
const events = [];
|
|
208
|
+
const mixed = [];
|
|
209
|
+
for (const [event, entries] of merged) {
|
|
210
|
+
const all = entries.map((entry) => classifyEntry(entry, target.host, root)).filter((k) => k !== null);
|
|
211
|
+
const kinds = [...new Set(all)];
|
|
212
|
+
if (kinds.length === 0)
|
|
213
|
+
continue;
|
|
214
|
+
if (kinds.includes('new-core')) {
|
|
215
|
+
// A switched event's new-core entry replaces the shell registration:
|
|
216
|
+
// the engine must do every hook the old dispatcher runs for it here.
|
|
217
|
+
const shell = kinds.filter((k) => k !== 'new-core');
|
|
218
|
+
let verdict;
|
|
219
|
+
if (killedBy) {
|
|
220
|
+
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` };
|
|
221
|
+
}
|
|
222
|
+
else if (shell.length > 0) {
|
|
223
|
+
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` };
|
|
224
|
+
}
|
|
225
|
+
else if (all.filter((k) => k === 'new-core').length > 1) {
|
|
226
|
+
verdict = { status: 'WARN', reason: 'registered to the new core more than once, so its checks run twice' };
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const engine = enginePathOf(entries, target.host, root);
|
|
230
|
+
verdict = newCore(event, engine);
|
|
231
|
+
const caps = verdict.status === 'PASS' && engine ? capabilities(engine) : undefined;
|
|
232
|
+
const left = caps && !(caps instanceof Error) ? uncovered(caps, target.host, event) : [];
|
|
233
|
+
if (left.length > 0)
|
|
234
|
+
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` };
|
|
235
|
+
}
|
|
236
|
+
if (verdict.status === 'WARN')
|
|
237
|
+
mixed.push(event);
|
|
238
|
+
events.push({ event, core: 'new-core', ...verdict });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (kinds.length > 1) {
|
|
242
|
+
mixed.push(event);
|
|
243
|
+
events.push({ event, core: kinds[0], status: 'WARN', reason: `two HQ registrations: ${kinds.map((k) => label(k, target.host)).join(', ')}` });
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const core = kinds[0];
|
|
247
|
+
events.push({ event, core, ...oldCore(event, target.host) });
|
|
248
|
+
}
|
|
249
|
+
if (events.length === 0) {
|
|
250
|
+
results.push({ status: 'NA', checkId, target: target.file, message: `${target.host} (${target.scope}): no HQ hook registered` });
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const status = events.reduce((worst, e) => (RANK[e.status] > RANK[worst] ? e.status : worst), 'PASS');
|
|
254
|
+
// Events grouped by core and reason, in file order: "<core> for A, B (reason)".
|
|
255
|
+
const groups = new Map();
|
|
256
|
+
for (const e of events) {
|
|
257
|
+
const key = `${label(e.core, target.host)}\u0000${e.reason}`;
|
|
258
|
+
groups.set(key, [...(groups.get(key) ?? []), e.event]);
|
|
259
|
+
}
|
|
260
|
+
const summary = [...groups].map(([key, names]) => {
|
|
261
|
+
const [label, reason] = key.split('\u0000');
|
|
262
|
+
return `${label} for ${names.join(', ')} (${reason})`;
|
|
263
|
+
}).join('; ');
|
|
264
|
+
const cores = [...new Set(events.map((e) => e.core))];
|
|
265
|
+
const failed = events.filter((e) => e.status === 'FAIL').map((e) => e.event);
|
|
266
|
+
results.push({
|
|
267
|
+
status,
|
|
268
|
+
checkId,
|
|
269
|
+
target: target.file,
|
|
270
|
+
message: `${target.host} (${target.scope}): ${summary}`,
|
|
271
|
+
details: { ...(cores.length === 1 ? { core: cores[0] } : {}), cores, events },
|
|
272
|
+
...(failed.length > 0
|
|
273
|
+
? { 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.` }
|
|
274
|
+
: mixed.length > 0
|
|
275
|
+
? { remediation: 'Run hq reindex to leave one HQ registration per event.' }
|
|
276
|
+
: {}),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return results;
|
|
280
|
+
}
|
|
281
|
+
/** HQ-relevant entries per event, in file order. */
|
|
282
|
+
function eventEntries(doc) {
|
|
283
|
+
const hooks = doc?.hooks;
|
|
284
|
+
if (!hooks || typeof hooks !== 'object' || Array.isArray(hooks))
|
|
285
|
+
return [];
|
|
286
|
+
return Object.entries(hooks).map(([event, groups]) => [event, hookEntries({ hooks: { [event]: groups } })]);
|
|
287
|
+
}
|
|
288
|
+
/** Flag and kill-switch state, shown once. */
|
|
289
|
+
export function coreSwitchResult(options = {}) {
|
|
290
|
+
const env = options.env ?? process.env;
|
|
291
|
+
const home = options.home ?? env.HOME ?? os.homedir();
|
|
292
|
+
const on = coreNextEnabled(env);
|
|
293
|
+
const killedBy = [
|
|
294
|
+
/^(off|0|false|no)$/i.test((env[CORE_NEXT_KILL_ENV] ?? '').trim()) ? `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}` : '',
|
|
295
|
+
/^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()) ? `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}` : '',
|
|
296
|
+
exists(path.join(home, CORE_NEXT_KILL_FILE)) ? path.join(home, CORE_NEXT_KILL_FILE) : '',
|
|
297
|
+
exists(path.join(home, ENGINE_KILL_FILE)) ? path.join(home, ENGINE_KILL_FILE) : '',
|
|
298
|
+
].filter(Boolean);
|
|
299
|
+
const flag = `flag ${CORE_NEXT_FLAG} is ${on ? 'on' : 'off'}`;
|
|
300
|
+
const kill = killedBy.length
|
|
301
|
+
? `; kill switch on (${killedBy.join(', ')}): new-core registrations hand each event to the old dispatcher, and hq reindex removes them`
|
|
302
|
+
: '';
|
|
303
|
+
// The engine reads the kill switch from each hook's own environment; this
|
|
304
|
+
// check and hq reindex read it from theirs.
|
|
305
|
+
const hostEnv = on || killedBy.length
|
|
306
|
+
? `. ${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`
|
|
307
|
+
: '';
|
|
308
|
+
return { status: 'PASS', checkId: 'host-core:switch', message: `${flag}${kill}${hostEnv}`, details: { flag: on, killSwitch: killedBy } };
|
|
309
|
+
}
|
|
310
|
+
function exists(file) {
|
|
311
|
+
try {
|
|
312
|
+
fs.lstatSync(file);
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/** The family `hq doctor` prints. */
|
|
320
|
+
export async function hostCoreFamily(context, options = {}) {
|
|
321
|
+
return {
|
|
322
|
+
family: { id: HOST_CORE_FAMILY_ID, title: HOST_CORE_FAMILY_TITLE },
|
|
323
|
+
results: [coreSwitchResult(options), ...hostCoreResults(context.hqRoot, options)],
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The one call `hq doctor` makes on a run without `--only`: when the hook
|
|
328
|
+
* wiring family ran, add this family right after it. Registries without it
|
|
329
|
+
* (tests that register their own families) are left as they are.
|
|
330
|
+
*/
|
|
331
|
+
export async function addHostCoreFamily(families, registry, context, options = {}) {
|
|
332
|
+
if (!registry.has(HOOKS_FAMILY_ID))
|
|
333
|
+
return;
|
|
334
|
+
const hooks = families.findIndex((run) => run.family.id === HOOKS_FAMILY_ID);
|
|
335
|
+
families.splice(hooks + 1, 0, await hostCoreFamily(context, options));
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=host-core.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay recorder: is it on, and how much does it hold?
|
|
3
|
+
*
|
|
4
|
+
* The recorder (`hq-hook record`, crates/hq-hook/src/recorder.rs) appends
|
|
5
|
+
* redacted hook events to `~/.hq/replay-recorder/` when the flag
|
|
6
|
+
* `core.replay-recorder` is on for the person or machine. It is off by default.
|
|
7
|
+
* This check reads the same three inputs the recorder reads (the kill switch
|
|
8
|
+
* variable, the kill switch file and the cached person flag snapshot) and the
|
|
9
|
+
* size of the store. It starts no process and makes no network call.
|
|
10
|
+
*/
|
|
11
|
+
import type { CheckFamily, CheckResult } from "../types.js";
|
|
12
|
+
export declare const REPLAY_RECORDER_FLAG = "core.replay-recorder";
|
|
13
|
+
export declare const REPLAY_RECORDER_KILL_ENV = "HQ_REPLAY_RECORDER";
|
|
14
|
+
export declare const REPLAY_RECORDER_MAX_BYTES_ENV = "HQ_REPLAY_RECORDER_MAX_BYTES";
|
|
15
|
+
export interface ReplayRecorderProbe {
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
/** Home directory. Default: `os.homedir()`. */
|
|
18
|
+
home?: string;
|
|
19
|
+
/** Clock in epoch milliseconds. Default: `Date.now()`. */
|
|
20
|
+
now?: number;
|
|
21
|
+
/** Temporary folder that holds the permission-fallback snapshot. Default: `os.tmpdir()`. */
|
|
22
|
+
tmpdir?: string;
|
|
23
|
+
/** Operating system. Default: `process.platform`. */
|
|
24
|
+
platform?: NodeJS.Platform;
|
|
25
|
+
}
|
|
26
|
+
export type ReplayRecorderOffReason = "kill-switch-env" | "kill-switch-file" | "flag-off" | "store-inside-repo" | "store-not-private" | "off-on-windows";
|
|
27
|
+
/** `HQ_REPLAY_RECORDER` values that turn recording off, in any case. Mirrors `recorder::KILL_SWITCH_VALUES`. */
|
|
28
|
+
export declare const REPLAY_RECORDER_KILL_VALUES: readonly string[];
|
|
29
|
+
export interface ReplayRecorderStore {
|
|
30
|
+
segments: number;
|
|
31
|
+
bytes: number;
|
|
32
|
+
}
|
|
33
|
+
/** Why the recorder is off, or `null` when it is recording. Mirrors `recorder::gate`. */
|
|
34
|
+
export declare function replayRecorderOffReason(probe?: ReplayRecorderProbe): ReplayRecorderOffReason | null;
|
|
35
|
+
/** Segment count and total size of the store. An absent store holds nothing. */
|
|
36
|
+
export declare function readReplayRecorderStore(home?: string): ReplayRecorderStore;
|
|
37
|
+
export declare function checkReplayRecorder(probe?: ReplayRecorderProbe): CheckResult;
|
|
38
|
+
export declare const replayRecorderFamily: CheckFamily;
|
|
39
|
+
//# sourceMappingURL=replay-recorder.d.ts.map
|