@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,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage gate of the registration switch (hq-core-rust US-017).
|
|
3
|
+
*
|
|
4
|
+
* A switched event's new-core entry replaces the shell registration, so the
|
|
5
|
+
* new core must do everything the old dispatcher does for that event on that
|
|
6
|
+
* host. Both sides come from data, not from a list kept in the CLI:
|
|
7
|
+
*
|
|
8
|
+
* - The old dispatcher's hooks are read from this HQ root, the way
|
|
9
|
+
* `.claude/hooks/master-hook.sh` finds them: every `hook-registry.json`
|
|
10
|
+
* entry for the event (all matchers), and every `*.sh` in
|
|
11
|
+
* `core/hooks/<Event>`, `personal/hooks/<Event>`,
|
|
12
|
+
* `core/packages/<pack>/hooks/<Event>` and `companies/<co>/hooks/<Event>`
|
|
13
|
+
* (any company, since the active one is chosen at run time). Folder hooks
|
|
14
|
+
* are named by their path under the root. `master-hook:<Event>` stands for
|
|
15
|
+
* the dispatcher's own work for the event. On Codex and Grok the adapter's
|
|
16
|
+
* own work (`codex-adapter:<Event>`, `grok-adapter:<Event>`) and every
|
|
17
|
+
* other command `.claude/settings.json` registers for the event
|
|
18
|
+
* (`settings:<command>`) are added, because the adapters run those too.
|
|
19
|
+
* - What the new core does in full is what the installed engine reports in
|
|
20
|
+
* `hq-hook capabilities --json` under `covers`.
|
|
21
|
+
*
|
|
22
|
+
* An event switches only when every old hook is covered. A hook list that
|
|
23
|
+
* cannot be read counts as not covered, and an engine that reports no
|
|
24
|
+
* `covers` covers nothing, so the event stays on the old dispatcher.
|
|
25
|
+
*/
|
|
26
|
+
import * as fs from 'node:fs';
|
|
27
|
+
import * as path from 'node:path';
|
|
28
|
+
import { isCoreNextEntry } from './registration.js';
|
|
29
|
+
/** Stands for the hook list when it cannot be read; never covered. */
|
|
30
|
+
export const UNREADABLE = '(the old dispatcher hook list could not be read)';
|
|
31
|
+
/** Folder hook that master-hook.sh never dispatches (retired; `hq rescue` can leave it on disk). */
|
|
32
|
+
const RETIRED = new Set(['Stop/70-work-mesh-done.sh']);
|
|
33
|
+
function listDir(dir) {
|
|
34
|
+
try {
|
|
35
|
+
return fs.readdirSync(dir).sort();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Absent folder: no hooks there.
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The hooks the old dispatcher runs for `event` on `host` in this HQ root; null when they cannot be read exactly. */
|
|
43
|
+
export function shellHooks(root, host, event) {
|
|
44
|
+
const out = [`master-hook:${event}`];
|
|
45
|
+
let registry;
|
|
46
|
+
try {
|
|
47
|
+
registry = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'hooks', 'hook-registry.json'), 'utf8'));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const hooks = registry?.hooks;
|
|
53
|
+
if (!hooks || typeof hooks !== 'object' || Array.isArray(hooks))
|
|
54
|
+
return null;
|
|
55
|
+
const groups = hooks[event] ?? [];
|
|
56
|
+
if (!Array.isArray(groups))
|
|
57
|
+
return null;
|
|
58
|
+
for (const group of groups) {
|
|
59
|
+
const entries = group?.hooks;
|
|
60
|
+
if (!Array.isArray(entries))
|
|
61
|
+
return null;
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const id = entry?.id;
|
|
64
|
+
if (typeof id !== 'string' || id === '')
|
|
65
|
+
return null;
|
|
66
|
+
out.push(id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const folders = [`core/hooks/${event}`, `personal/hooks/${event}`];
|
|
70
|
+
for (const base of ['core/packages', 'companies']) {
|
|
71
|
+
for (const name of listDir(path.join(root, base)))
|
|
72
|
+
folders.push(`${base}/${name}/hooks/${event}`);
|
|
73
|
+
}
|
|
74
|
+
for (const folder of folders) {
|
|
75
|
+
for (const file of listDir(path.join(root, folder))) {
|
|
76
|
+
if (!file.endsWith('.sh'))
|
|
77
|
+
continue;
|
|
78
|
+
if (folder === `core/hooks/${event}` && RETIRED.has(`${event}/${file}`))
|
|
79
|
+
continue;
|
|
80
|
+
out.push(`${folder}/${file}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (host !== 'claude') {
|
|
84
|
+
out.push(`${host}-adapter:${event}`);
|
|
85
|
+
let settings;
|
|
86
|
+
try {
|
|
87
|
+
settings = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'settings.json'), 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const registered = (settings?.hooks ?? {})[event];
|
|
93
|
+
for (const group of Array.isArray(registered) ? registered : []) {
|
|
94
|
+
for (const entry of Array.isArray(group?.hooks) ? group.hooks : []) {
|
|
95
|
+
const command = entry?.command;
|
|
96
|
+
// HQ's own entry for the event (master-hook, or the Claude Code
|
|
97
|
+
// new-core entry that took its place) is the dispatcher counted above.
|
|
98
|
+
if (typeof command !== 'string' || command.includes('master-hook.sh') || isCoreNextEntry(entry, root))
|
|
99
|
+
continue;
|
|
100
|
+
out.push(`settings:${command}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
107
|
+
export function uncoveredHooks(root, host, event, covers) {
|
|
108
|
+
const hooks = shellHooks(root, host, event);
|
|
109
|
+
if (!hooks)
|
|
110
|
+
return [UNREADABLE];
|
|
111
|
+
const covered = covers?.[event] ?? [];
|
|
112
|
+
return hooks.filter((hook) => !covered.includes(hook));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
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),
|
|
117
|
+
* or when the target's host canary gate refuses `host` (US-019 criterion 4:
|
|
118
|
+
* no event on that host switches).
|
|
119
|
+
*/
|
|
120
|
+
export function forHost(target, root, host) {
|
|
121
|
+
if (!target)
|
|
122
|
+
return null;
|
|
123
|
+
const events = target.events.filter((event) => uncoveredHooks(root, host, event, target.covers).length === 0);
|
|
124
|
+
if (!events.length)
|
|
125
|
+
return null;
|
|
126
|
+
if (target.canary && !target.canary(root, host))
|
|
127
|
+
return null;
|
|
128
|
+
return { ...target, events };
|
|
129
|
+
}
|
|
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
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** Fleet uses the same flag, evaluator and complete-hook gate as reindex. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { checkStableEngine, coreNextOffReason, capableEvents, probeEngine, missingEvaluators, resolveCoreNextEngine } from '../../utils/host-registration.js';
|
|
5
|
+
import { verifyHookEngine } from './resolve.js';
|
|
6
|
+
import { forHost, uncoveredHooks } from './coverage.js';
|
|
7
|
+
import { quotePosix } from './registration.js';
|
|
8
|
+
export const FLEET_EVENTS = { pre_tool_call: 'PreToolUse', post_tool_call: 'PostToolUse', pre_llm_call: 'UserPromptSubmit', on_session_start: 'SessionStart', pre_verify: 'Stop', on_session_finalize: 'SessionEnd', subagent_stop: 'SubagentStop' };
|
|
9
|
+
/** Literal POSIX argv only. Never expands variables or executes shell syntax. */
|
|
10
|
+
export function literalArgv(command) {
|
|
11
|
+
const out = [];
|
|
12
|
+
let word = '';
|
|
13
|
+
let quote = '';
|
|
14
|
+
let started = false;
|
|
15
|
+
for (let i = 0; i < command.length; i++) {
|
|
16
|
+
const ch = command[i];
|
|
17
|
+
if (quote === "'") {
|
|
18
|
+
if (ch === quote)
|
|
19
|
+
quote = '';
|
|
20
|
+
else
|
|
21
|
+
word += ch;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (ch === '\\') {
|
|
25
|
+
const next = command[++i];
|
|
26
|
+
if (next === undefined)
|
|
27
|
+
return null;
|
|
28
|
+
word += next;
|
|
29
|
+
started = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (quote === '"') {
|
|
33
|
+
if (ch === quote)
|
|
34
|
+
quote = '';
|
|
35
|
+
else if ('$`'.includes(ch))
|
|
36
|
+
return null;
|
|
37
|
+
else
|
|
38
|
+
word += ch;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ch === "'" || ch === '"') {
|
|
42
|
+
quote = ch;
|
|
43
|
+
started = true;
|
|
44
|
+
}
|
|
45
|
+
else if (/\s/.test(ch)) {
|
|
46
|
+
if (started) {
|
|
47
|
+
out.push(word);
|
|
48
|
+
word = '';
|
|
49
|
+
started = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (';$`|&<>()\n\0'.includes(ch))
|
|
53
|
+
return null;
|
|
54
|
+
else {
|
|
55
|
+
word += ch;
|
|
56
|
+
started = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (quote)
|
|
60
|
+
return null;
|
|
61
|
+
if (started)
|
|
62
|
+
out.push(word);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
export function fallbackProblem(argv) {
|
|
66
|
+
if (!Array.isArray(argv) || argv.length < 2 || !argv.every(v => typeof v === 'string' && !v.includes('\0')))
|
|
67
|
+
return 'fallback must be a nonempty argv vector';
|
|
68
|
+
if (!path.isAbsolute(argv[0]))
|
|
69
|
+
return 'fallback executable must be absolute';
|
|
70
|
+
try {
|
|
71
|
+
fs.accessSync(argv[0], fs.constants.X_OK);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return 'fallback executable is unavailable';
|
|
75
|
+
}
|
|
76
|
+
if (['bash', 'sh'].includes(path.basename(argv[0]))) {
|
|
77
|
+
if (!path.isAbsolute(argv[1]) || path.basename(argv[1]) !== 'hq-fleet-local-hook-adapter.sh')
|
|
78
|
+
return 'fallback must name the fleet adapter script';
|
|
79
|
+
try {
|
|
80
|
+
fs.accessSync(argv[1], fs.constants.R_OK);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return 'fallback adapter is unavailable';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
return 'fallback must use the fleet shell adapter';
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
/** Self-check, then probe, then the fleet-local host claim. */
|
|
91
|
+
export function fleetEngineCapabilities(engine, probe = probeEngine, verify = verifyHookEngine) {
|
|
92
|
+
const problem = verify(engine);
|
|
93
|
+
if (problem)
|
|
94
|
+
throw new Error(problem);
|
|
95
|
+
const caps = probe(engine);
|
|
96
|
+
if (!caps.registrationHosts?.includes('fleet-local'))
|
|
97
|
+
throw new Error('engine does not support fleet-local registration');
|
|
98
|
+
return caps;
|
|
99
|
+
}
|
|
100
|
+
export function inspectFleetEngine(engine, home, probe = probeEngine, verify = verifyHookEngine, lookup = {}) {
|
|
101
|
+
const resolved = resolveCoreNextEngine(home, { mode: 'read-only', lookup, probe: e => fleetEngineCapabilities(e, probe, verify) });
|
|
102
|
+
checkStableEngine(engine, resolved.pinned);
|
|
103
|
+
return resolved.caps;
|
|
104
|
+
}
|
|
105
|
+
export function fleetRegistrationPlan(root, fallbacks, options) {
|
|
106
|
+
const env = options.env ?? process.env;
|
|
107
|
+
let reason = coreNextOffReason(options.home, env, options.platform ?? process.platform);
|
|
108
|
+
let caps;
|
|
109
|
+
let engine = '';
|
|
110
|
+
if (!reason) {
|
|
111
|
+
try {
|
|
112
|
+
const resolved = resolveCoreNextEngine(options.home, { mode: 'read-only', platform: options.platform, lookup: options.lookup, probe: options.inspect ?? (e => fleetEngineCapabilities(e)) });
|
|
113
|
+
engine = resolved.stable;
|
|
114
|
+
caps = resolved.caps;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
reason = error.message;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const target = caps ? forHost({ coreNext: engine, events: capableEvents(caps), covers: caps.covers }, root, 'fleet-local') : null;
|
|
121
|
+
const events = {};
|
|
122
|
+
for (const [event, canonical] of Object.entries(FLEET_EVENTS)) {
|
|
123
|
+
const fallback = fallbacks[event] ?? [];
|
|
124
|
+
const problem = fallbackProblem(fallback);
|
|
125
|
+
const native = !reason && !problem && target?.events.includes(canonical);
|
|
126
|
+
const argv = native ? [engine, 'run', '--host', 'fleet-local', event, '--hq-root', root, '--fleet-fallback', JSON.stringify(fallback)] : fallback;
|
|
127
|
+
const why = native ? 'complete evaluator and hook coverage' : reason ?? problem ?? (caps && missingEvaluators(caps, canonical)?.length ? 'required evaluators are missing' : `uncovered hooks: ${uncoveredHooks(root, 'fleet-local', canonical, caps?.covers).join(', ')}`);
|
|
128
|
+
events[event] = { mode: native ? 'native' : 'shell', argv, command: argv.map(quotePosix).join(' '), reason: why };
|
|
129
|
+
}
|
|
130
|
+
return { schema: 'hq.hook-registration-plan.v1', host: 'fleet-local', events };
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=fleet-registration.js.map
|