@indigoai-us/hq-cli 5.345.218 → 5.345.219

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/command-catalog.generated.d.ts +69 -0
  3. package/dist/command-catalog.generated.js +83 -0
  4. package/dist/commands/agents.d.ts +22 -0
  5. package/dist/commands/agents.js +92 -1
  6. package/dist/commands/core-hook-registration-plan.d.ts +8 -0
  7. package/dist/commands/core-hook-registration-plan.js +21 -0
  8. package/dist/commands/core.js +9 -0
  9. package/dist/commands/doctor.js +4 -0
  10. package/dist/commands/lanes-shared.d.ts +2 -0
  11. package/dist/commands/lanes-watch.js +28 -1
  12. package/dist/commands/lanes.d.ts +2 -0
  13. package/dist/commands/lanes.js +99 -9
  14. package/dist/commands/reindex.js +6 -0
  15. package/dist/index.js +8 -0
  16. package/dist/lib/anywhere-person-setting.d.ts +2 -2
  17. package/dist/lib/anywhere-person-setting.js +2 -2
  18. package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
  19. package/dist/lib/daemon/anywhere-listener.js +86 -4
  20. package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
  21. package/dist/lib/daemon/machine-check-owner.js +95 -0
  22. package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
  23. package/dist/lib/daemon/machine-check-registration.js +64 -0
  24. package/dist/lib/daemon/machine-checks.d.ts +144 -0
  25. package/dist/lib/daemon/machine-checks.js +412 -0
  26. package/dist/lib/daemon/run.js +30 -4
  27. package/dist/lib/daemon/server.d.ts +2 -0
  28. package/dist/lib/daemon/server.js +6 -0
  29. package/dist/lib/daemon/state-file.d.ts +12 -1
  30. package/dist/lib/daemon/state-file.js +23 -1
  31. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -0
  32. package/dist/lib/doctor/checks/fleet-hook-core.js +103 -0
  33. package/dist/lib/doctor/checks/host-core.js +3 -1
  34. package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
  35. package/dist/lib/doctor/checks/machine-checks.js +103 -0
  36. package/dist/lib/doctor/registry.js +4 -0
  37. package/dist/lib/doctor/types.d.ts +4 -0
  38. package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
  39. package/dist/lib/hook-engine/canary-gate.js +147 -0
  40. package/dist/lib/hook-engine/coverage.d.ts +3 -1
  41. package/dist/lib/hook-engine/coverage.js +8 -2
  42. package/dist/lib/hook-engine/fleet-registration.d.ts +30 -0
  43. package/dist/lib/hook-engine/fleet-registration.js +132 -0
  44. package/dist/lib/hook-engine/reconcile.js +3 -2
  45. package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
  46. package/dist/lib/hook-engine/registration-identity.js +97 -0
  47. package/dist/lib/hook-engine/registration.d.ts +1 -30
  48. package/dist/lib/hook-engine/registration.js +1 -88
  49. package/dist/lib/hook-engine/resolve.d.ts +2 -0
  50. package/dist/lib/hook-engine/resolve.js +7 -3
  51. package/dist/lib/lanes/canonical-host.d.ts +8 -1
  52. package/dist/lib/lanes/canonical-host.js +9 -3
  53. package/dist/lib/lanes/machine-identity.d.ts +15 -0
  54. package/dist/lib/lanes/machine-identity.js +26 -0
  55. package/dist/lib/lanes/spawn.js +17 -3
  56. package/dist/utils/core-next-flag.d.ts +4 -0
  57. package/dist/utils/core-next-flag.js +22 -0
  58. package/dist/utils/core-next-kill.d.ts +16 -0
  59. package/dist/utils/core-next-kill.js +35 -0
  60. package/dist/utils/host-registration.d.ts +33 -23
  61. package/dist/utils/host-registration.js +86 -66
  62. package/package.json +8 -8
@@ -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
@@ -6,6 +6,7 @@ import { addHqHooks, removeHqHooks } from '../install/claude-targets.js';
6
6
  import { legacyHookTarget } from '../install/hook-target.js';
7
7
  import { addCodexHooks, removeCodexHooks, codexHookEntry, codexHookTrustKeys } from '../install/codex-targets.js';
8
8
  import { engineArgs, isCoreNextEntry, isNativeEntry, registrationEngine } from './registration.js';
9
+ import { userHookSettingsFile } from './registration-identity.js';
9
10
  import { coreNextArgs, coreNextTargetOrWarn, placeEvent } from '../../utils/host-registration.js';
10
11
  import { forHost } from './coverage.js';
11
12
  /** The project master-hook command shipped in HQ's .claude/settings.json. */
@@ -157,8 +158,8 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
157
158
  result.failures.push(`${join(root, '.claude/settings.json')}: ${error.message}`);
158
159
  }
159
160
  for (const [file, runtime, global] of [
160
- [join(env.CLAUDE_CONFIG_DIR || join(home, '.claude'), 'settings.json'), 'claude', true],
161
- [join(env.CODEX_HOME || join(home, '.codex'), 'hooks.json'), 'codex', true],
161
+ [userHookSettingsFile('claude', home, env), 'claude', true],
162
+ [userHookSettingsFile('codex', home, env), 'codex', true],
162
163
  [join(root, '.codex/hooks.json'), 'codex', false],
163
164
  ]) {
164
165
  // Each file stands alone: an unreadable or locked project file must not
@@ -0,0 +1,33 @@
1
+ export interface NativeTarget {
2
+ engine: string;
3
+ }
4
+ /**
5
+ * Root spelling passed to the launcher. A trailing separator is dropped because
6
+ * Windows PowerShell 5.1 re-quotes a native argument containing a space as
7
+ * "...", and a final backslash would then escape the closing quote.
8
+ */
9
+ export declare function launcherRoot(root: string): string;
10
+ export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
11
+ /**
12
+ * True when an entry's `--hq-root` names this HQ root: the same spelling
13
+ * (trailing separators aside), or another spelling of the same folder
14
+ * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
15
+ * by resolving both. An entry for any other folder is not this root's.
16
+ */
17
+ export declare function sameHqRoot(value: string | undefined, root: string): boolean;
18
+ /** Recognize only our pinned executable with this root's argument. */
19
+ export declare function isNativeEntry(entry: Record<string, unknown>, root: string): boolean;
20
+ /**
21
+ * A registration that calls the new core's entry point, `hq-hook run --host
22
+ * <host> <Event> --hq-root <root>`, through the release-stable link
23
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
24
+ * words and a root argument that names this root ([`sameHqRoot`]), in exec
25
+ * form (`args`) or as a command string (Codex, Grok).
26
+ */
27
+ export declare const CORE_NEXT_LINK: RegExp;
28
+ export declare function isCoreNextEntry(entry: Record<string, unknown>, root: string): boolean;
29
+ export declare function quotePosix(value: string): string;
30
+ export declare function quoteWindows(value: string): string;
31
+ /** User-scope hook file `hq reindex` writes for this host. */
32
+ export declare function userHookSettingsFile(host: 'claude' | 'codex', home: string, env: NodeJS.ProcessEnv): string;
33
+ //# sourceMappingURL=registration-identity.d.ts.map
@@ -0,0 +1,97 @@
1
+ /** Pure registration recognition: no installer or package metadata imports. */
2
+ import { realpathSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * Root spelling passed to the launcher. A trailing separator is dropped because
6
+ * Windows PowerShell 5.1 re-quotes a native argument containing a space as
7
+ * "...", and a final backslash would then escape the closing quote.
8
+ */
9
+ export function launcherRoot(root) {
10
+ const trimmed = root.replace(/[\\/]+$/, '');
11
+ return trimmed === '' || /^[A-Za-z]:$/.test(trimmed) ? root : trimmed;
12
+ }
13
+ export function engineArgs(root, event, runtime, global = false) {
14
+ return [event, '--hq-root', launcherRoot(root), '--runtime', runtime, ...(global && runtime === 'claude' ? ['--global'] : [])];
15
+ }
16
+ /**
17
+ * The `--hq-root` value of an HQ entry: the argument after it in exec form,
18
+ * or the single-quoted word after it in a POSIX or PowerShell command string.
19
+ */
20
+ function hqRootArgument(entry) {
21
+ if (Array.isArray(entry.args)) {
22
+ const i = entry.args.indexOf('--hq-root');
23
+ const value = i >= 0 ? entry.args[i + 1] : undefined;
24
+ return typeof value === 'string' ? value : undefined;
25
+ }
26
+ if (typeof entry.command !== 'string')
27
+ return undefined;
28
+ // `& '...'` is the PowerShell form (quote doubled); anything else is POSIX (`'\''`).
29
+ if (entry.command.startsWith('& ')) {
30
+ const windows = entry.command.match(/'--hq-root' '((?:[^']|'')*)'/);
31
+ return windows ? windows[1].replace(/''/g, "'") : undefined;
32
+ }
33
+ const posix = entry.command.match(/'--hq-root' '((?:[^']|'\\'')*)'/);
34
+ return posix ? posix[1].replace(/'\\''/g, "'") : undefined;
35
+ }
36
+ function realpathOrNull(p) {
37
+ try {
38
+ return realpathSync(p);
39
+ }
40
+ catch {
41
+ // A path that does not exist names no folder, so it matches no root.
42
+ return null;
43
+ }
44
+ }
45
+ /**
46
+ * True when an entry's `--hq-root` names this HQ root: the same spelling
47
+ * (trailing separators aside), or another spelling of the same folder
48
+ * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
49
+ * by resolving both. An entry for any other folder is not this root's.
50
+ */
51
+ export function sameHqRoot(value, root) {
52
+ if (value === undefined)
53
+ return false;
54
+ if (value === launcherRoot(root) || launcherRoot(value) === launcherRoot(root))
55
+ return true;
56
+ const a = realpathOrNull(value);
57
+ return a !== null && a === realpathOrNull(root);
58
+ }
59
+ /** Recognize only our pinned executable with this root's argument. */
60
+ export function isNativeEntry(entry, root) {
61
+ if (typeof entry.command !== 'string')
62
+ return false;
63
+ const pinned = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]\d+\.\d+\.\d+[^\\/]*[\\/]/;
64
+ if (!pinned.test(entry.command))
65
+ return false;
66
+ return sameHqRoot(hqRootArgument(entry), root);
67
+ }
68
+ /**
69
+ * A registration that calls the new core's entry point, `hq-hook run --host
70
+ * <host> <Event> --hq-root <root>`, through the release-stable link
71
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
72
+ * words and a root argument that names this root ([`sameHqRoot`]), in exec
73
+ * form (`args`) or as a command string (Codex, Grok).
74
+ */
75
+ export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
76
+ export function isCoreNextEntry(entry, root) {
77
+ if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
78
+ return false;
79
+ const runHost = Array.isArray(entry.args)
80
+ ? entry.args[0] === 'run' && entry.args[1] === '--host'
81
+ : entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`);
82
+ return runHost && sameHqRoot(hqRootArgument(entry), root);
83
+ }
84
+ export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
85
+ export function quoteWindows(value) {
86
+ // Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
87
+ // Single-quoted literals prevent variable, subexpression and wildcard expansion.
88
+ // PowerShell also closes them on the typographic quotes U+2018-U+201B.
89
+ return "'" + value.replace(/['‘’‚‛]/g, '$&$&') + "'";
90
+ }
91
+ /** User-scope hook file `hq reindex` writes for this host. */
92
+ export function userHookSettingsFile(host, home, env) {
93
+ return host === 'claude'
94
+ ? join(env.CLAUDE_CONFIG_DIR || join(home, '.claude'), 'settings.json')
95
+ : join(env.CODEX_HOME || join(home, '.codex'), 'hooks.json');
96
+ }
97
+ //# sourceMappingURL=registration-identity.js.map
@@ -1,33 +1,4 @@
1
1
  export declare function launcherEnabled(env?: NodeJS.ProcessEnv): boolean;
2
2
  export declare function registrationEngine(home: string, env?: NodeJS.ProcessEnv): string | null;
3
- export interface NativeTarget {
4
- engine: string;
5
- }
6
- /**
7
- * Root spelling passed to the launcher. A trailing separator is dropped because
8
- * Windows PowerShell 5.1 re-quotes a native argument containing a space as
9
- * "...", and a final backslash would then escape the closing quote.
10
- */
11
- export declare function launcherRoot(root: string): string;
12
- export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
13
- /**
14
- * True when an entry's `--hq-root` names this HQ root: the same spelling
15
- * (trailing separators aside), or another spelling of the same folder
16
- * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
17
- * by resolving both. An entry for any other folder is not this root's.
18
- */
19
- export declare function sameHqRoot(value: string | undefined, root: string): boolean;
20
- /** Recognize only our pinned executable with this root's argument. */
21
- export declare function isNativeEntry(entry: Record<string, unknown>, root: string): boolean;
22
- /**
23
- * A registration that calls the new core's entry point, `hq-hook run --host
24
- * <host> <Event> --hq-root <root>`, through the release-stable link
25
- * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
26
- * words and a root argument that names this root ([`sameHqRoot`]), in exec
27
- * form (`args`) or as a command string (Codex, Grok).
28
- */
29
- export declare const CORE_NEXT_LINK: RegExp;
30
- export declare function isCoreNextEntry(entry: Record<string, unknown>, root: string): boolean;
31
- export declare function quotePosix(value: string): string;
32
- export declare function quoteWindows(value: string): string;
3
+ export { launcherRoot, engineArgs, isNativeEntry, isCoreNextEntry, sameHqRoot, CORE_NEXT_LINK, quotePosix, quoteWindows, type NativeTarget } from './registration-identity.js';
33
4
  //# sourceMappingURL=registration.d.ts.map
@@ -1,5 +1,4 @@
1
1
  /** Offline, default-off registration gate. No network work on the hook path. */
2
- import { realpathSync } from 'node:fs';
3
2
  import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from '../flag-snapshot-file.js';
4
3
  import { resolveProcessFlagCompanyContext } from '../process-flag-company-context.js';
5
4
  import { installHookEngine } from './resolve.js';
@@ -15,91 +14,5 @@ export function registrationEngine(home, env = process.env) {
15
14
  return null;
16
15
  return installHookEngine({ home });
17
16
  }
18
- /**
19
- * Root spelling passed to the launcher. A trailing separator is dropped because
20
- * Windows PowerShell 5.1 re-quotes a native argument containing a space as
21
- * "...", and a final backslash would then escape the closing quote.
22
- */
23
- export function launcherRoot(root) {
24
- const trimmed = root.replace(/[\\/]+$/, '');
25
- return trimmed === '' || /^[A-Za-z]:$/.test(trimmed) ? root : trimmed;
26
- }
27
- export function engineArgs(root, event, runtime, global = false) {
28
- return [event, '--hq-root', launcherRoot(root), '--runtime', runtime, ...(global && runtime === 'claude' ? ['--global'] : [])];
29
- }
30
- /**
31
- * The `--hq-root` value of an HQ entry: the argument after it in exec form,
32
- * or the single-quoted word after it in a POSIX or PowerShell command string.
33
- */
34
- function hqRootArgument(entry) {
35
- if (Array.isArray(entry.args)) {
36
- const i = entry.args.indexOf('--hq-root');
37
- const value = i >= 0 ? entry.args[i + 1] : undefined;
38
- return typeof value === 'string' ? value : undefined;
39
- }
40
- if (typeof entry.command !== 'string')
41
- return undefined;
42
- // `& '...'` is the PowerShell form (quote doubled); anything else is POSIX (`'\''`).
43
- if (entry.command.startsWith('& ')) {
44
- const windows = entry.command.match(/'--hq-root' '((?:[^']|'')*)'/);
45
- return windows ? windows[1].replace(/''/g, "'") : undefined;
46
- }
47
- const posix = entry.command.match(/'--hq-root' '((?:[^']|'\\'')*)'/);
48
- return posix ? posix[1].replace(/'\\''/g, "'") : undefined;
49
- }
50
- function realpathOrNull(p) {
51
- try {
52
- return realpathSync(p);
53
- }
54
- catch {
55
- // A path that does not exist names no folder, so it matches no root.
56
- return null;
57
- }
58
- }
59
- /**
60
- * True when an entry's `--hq-root` names this HQ root: the same spelling
61
- * (trailing separators aside), or another spelling of the same folder
62
- * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
63
- * by resolving both. An entry for any other folder is not this root's.
64
- */
65
- export function sameHqRoot(value, root) {
66
- if (value === undefined)
67
- return false;
68
- if (value === launcherRoot(root) || launcherRoot(value) === launcherRoot(root))
69
- return true;
70
- const a = realpathOrNull(value);
71
- return a !== null && a === realpathOrNull(root);
72
- }
73
- /** Recognize only our pinned executable with this root's argument. */
74
- export function isNativeEntry(entry, root) {
75
- if (typeof entry.command !== 'string')
76
- return false;
77
- const pinned = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]\d+\.\d+\.\d+[^\\/]*[\\/]/;
78
- if (!pinned.test(entry.command))
79
- return false;
80
- return sameHqRoot(hqRootArgument(entry), root);
81
- }
82
- /**
83
- * A registration that calls the new core's entry point, `hq-hook run --host
84
- * <host> <Event> --hq-root <root>`, through the release-stable link
85
- * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
86
- * words and a root argument that names this root ([`sameHqRoot`]), in exec
87
- * form (`args`) or as a command string (Codex, Grok).
88
- */
89
- export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
90
- export function isCoreNextEntry(entry, root) {
91
- if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
92
- return false;
93
- const runHost = Array.isArray(entry.args)
94
- ? entry.args[0] === 'run' && entry.args[1] === '--host'
95
- : entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`);
96
- return runHost && sameHqRoot(hqRootArgument(entry), root);
97
- }
98
- export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
99
- export function quoteWindows(value) {
100
- // Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
101
- // Single-quoted literals prevent variable, subexpression and wildcard expansion.
102
- // PowerShell also closes them on the typographic quotes U+2018-U+201B.
103
- return "'" + value.replace(/['‘’‚‛]/g, '$&$&') + "'";
104
- }
17
+ export { launcherRoot, engineArgs, isNativeEntry, isCoreNextEntry, sameHqRoot, CORE_NEXT_LINK, quotePosix, quoteWindows } from './registration-identity.js';
105
18
  //# sourceMappingURL=registration.js.map
@@ -20,6 +20,8 @@ export interface EnginePackage {
20
20
  export declare function hookEngineRequired(): boolean;
21
21
  /** Check the whole signed bundle, including its resource seal and stapled ticket. */
22
22
  export declare function pinnedHookEngineMatches(engine: EnginePackage): boolean;
23
+ /** The pinned bundle must be the package this CLI installed. */
24
+ export declare function assertPinnedHookEngineMatches(engine: EnginePackage): void;
23
25
  /** Offline lookup. Never silently use an engine from a different CLI version. */
24
26
  export declare function findHookEngine(options?: EngineOptions): EnginePackage | null;
25
27
  /** Never truncate or replace a running Windows executable. */
@@ -38,6 +38,12 @@ export function pinnedHookEngineMatches(engine) {
38
38
  }
39
39
  return equal(engine.sourceDirectory, engine.pinnedDirectory);
40
40
  }
41
+ /** The pinned bundle must be the package this CLI installed. */
42
+ export function assertPinnedHookEngineMatches(engine) {
43
+ if (!pinnedHookEngineMatches(engine)) {
44
+ throw new Error(`Hook engine ${engine.version} differs from its pinned copy; close HQ sessions and repair with: ${HOOK_ENGINE_REPAIR_PIN}`);
45
+ }
46
+ }
41
47
  /** Offline lookup. Never silently use an engine from a different CLI version. */
42
48
  export function findHookEngine(options = {}) {
43
49
  const platform = options.platform ?? process.platform;
@@ -105,9 +111,7 @@ export function installHookEngine(options = {}) {
105
111
  rmSync(stage, { recursive: true, force: true });
106
112
  }
107
113
  }
108
- if (!pinnedHookEngineMatches(engine)) {
109
- throw new Error(`Hook engine ${engine.version} differs from its pinned copy; close HQ sessions and repair with: ${HOOK_ENGINE_REPAIR_PIN}`);
110
- }
114
+ assertPinnedHookEngineMatches(engine);
111
115
  writeHookEnginePointer(engine.pinned, options);
112
116
  return engine.pinned;
113
117
  }
@@ -5,7 +5,8 @@
5
5
  * uses: the Outpost marker (`/etc/outpost/outpost-id`) on an Outpost, and the
6
6
  * stable id in `~/.hq/lane-host.json` elsewhere. This module only gathers the
7
7
  * aliases, from values that are already on disk. It makes no network call, so
8
- * the EC2 instance id and the registry instance name are not listed.
8
+ * the registry instance name is not listed, and the EC2 instance id is listed
9
+ * only when the caller read it from a local file.
9
10
  *
10
11
  * The list is for printing and for joining records. It includes ids taken from
11
12
  * lane records, so it must not be passed back into the local matcher to decide
@@ -29,6 +30,12 @@ export declare function resolveCanonicalHost(input: {
29
30
  identityAliases?: readonly string[];
30
31
  /** Stable local id from `~/.hq/lane-host.json` when `host` is an Outpost. */
31
32
  localIdentityId?: string;
33
+ /**
34
+ * This machine's EC2 instance id, read from disk (`readInstanceIdFromDisk`).
35
+ * Used only when `host` is an Outpost: a lane record whose `imds` origin is
36
+ * this exact id was created on this machine.
37
+ */
38
+ instanceId?: string;
32
39
  lanes?: readonly CanonicalHostLane[];
33
40
  now: Date;
34
41
  }): CanonicalHost;
@@ -5,7 +5,8 @@
5
5
  * uses: the Outpost marker (`/etc/outpost/outpost-id`) on an Outpost, and the
6
6
  * stable id in `~/.hq/lane-host.json` elsewhere. This module only gathers the
7
7
  * aliases, from values that are already on disk. It makes no network call, so
8
- * the EC2 instance id and the registry instance name are not listed.
8
+ * the registry instance name is not listed, and the EC2 instance id is listed
9
+ * only when the caller read it from a local file.
9
10
  *
10
11
  * The list is for printing and for joining records. It includes ids taken from
11
12
  * lane records, so it must not be passed back into the local matcher to decide
@@ -40,8 +41,10 @@ export function resolveCanonicalHost(input) {
40
41
  add(localId);
41
42
  // A lane stamped `local` belongs to this machine when the existing local
42
43
  // matcher says so. Outpost-stamped lanes carry the marker id or another
43
- // Outpost's id, and an `imds` origin cannot be compared without a network
44
- // read, so neither adds an alias.
44
+ // Outpost's id, so their host adds no alias. An `imds` origin is another
45
+ // machine's instance id unless it equals the one this machine read from its
46
+ // own disk; without that reading no `imds` origin is listed.
47
+ const instanceId = input.host.kind === "outpost" ? input.instanceId?.trim() : undefined;
45
48
  const match = {
46
49
  hostname,
47
50
  ...(localId ? { machineId: localId } : {}),
@@ -59,6 +62,9 @@ export function resolveCanonicalHost(input) {
59
62
  localHostIdsReferToSameMachine(lane.origin_host, match)) {
60
63
  add(lane.origin_host);
61
64
  }
65
+ if (instanceId && lane.origin_host_source === "imds" && lane.origin_host === instanceId) {
66
+ add(instanceId);
67
+ }
62
68
  }
63
69
  return { kind: input.host.kind, id, aliases };
64
70
  }
@@ -30,5 +30,20 @@ export interface MachineIdentityDeps {
30
30
  }
31
31
  /** IMDSv2 token then instance-id. Any failure is null, not a thrown guess. */
32
32
  export declare function defaultReadImdsInstanceId(): string | null;
33
+ /** Where a Nitro EC2 instance exposes its instance id as a file. */
34
+ export declare const DMI_BOARD_ASSET_TAG_PATH = "/sys/devices/virtual/dmi/id/board_asset_tag";
35
+ /**
36
+ * This machine's EC2 instance id read from a local file, with no network
37
+ * call. Null when the platform is not Linux, the file is missing, or its
38
+ * content is not an instance id (other hardware puts vendor text there).
39
+ *
40
+ * This is for listing the id as a host alias. It is not a replacement for
41
+ * `resolveMachineIdentity`, which stays the one reading used to stamp and
42
+ * compare `origin_host`.
43
+ */
44
+ export declare function readInstanceIdFromDisk(deps?: {
45
+ platform?: NodeJS.Platform;
46
+ readFileSync?: (file: string) => string;
47
+ }): string | null;
33
48
  export declare function resolveMachineIdentity(deps?: MachineIdentityDeps): MachineIdentity;
34
49
  //# sourceMappingURL=machine-identity.d.ts.map
@@ -10,6 +10,7 @@
10
10
  * lane must not touch IMDS / the network.
11
11
  */
12
12
  import { spawnSync } from "node:child_process";
13
+ import * as fs from "node:fs";
13
14
  import * as os from "node:os";
14
15
  export const IMDS_HOST = "169.254.169.254";
15
16
  export const IMDS_TOKEN_URL = `http://${IMDS_HOST}/latest/api/token`;
@@ -47,6 +48,31 @@ export function defaultReadImdsInstanceId() {
47
48
  "X-aws-ec2-metadata-token": token,
48
49
  });
49
50
  }
51
+ /** Where a Nitro EC2 instance exposes its instance id as a file. */
52
+ export const DMI_BOARD_ASSET_TAG_PATH = "/sys/devices/virtual/dmi/id/board_asset_tag";
53
+ const EC2_INSTANCE_ID_PATTERN = /^i-[0-9a-f]{8,32}$/;
54
+ /**
55
+ * This machine's EC2 instance id read from a local file, with no network
56
+ * call. Null when the platform is not Linux, the file is missing, or its
57
+ * content is not an instance id (other hardware puts vendor text there).
58
+ *
59
+ * This is for listing the id as a host alias. It is not a replacement for
60
+ * `resolveMachineIdentity`, which stays the one reading used to stamp and
61
+ * compare `origin_host`.
62
+ */
63
+ export function readInstanceIdFromDisk(deps = {}) {
64
+ if ((deps.platform ?? process.platform) !== "linux")
65
+ return null;
66
+ let text;
67
+ try {
68
+ text = (deps.readFileSync ?? ((file) => fs.readFileSync(file, "utf8")))(DMI_BOARD_ASSET_TAG_PATH);
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ const id = text.trim();
74
+ return EC2_INSTANCE_ID_PATTERN.test(id) ? id : null;
75
+ }
50
76
  export function resolveMachineIdentity(deps = {}) {
51
77
  const readImds = deps.readImdsInstanceId ?? defaultReadImdsInstanceId;
52
78
  let imdsId = null;
@@ -44,7 +44,7 @@ import { ensureSessionHome } from "./session-relink.js";
44
44
  import { emitDispatchAdvisory } from "../capacity/read.js";
45
45
  import { MESSAGE_REPLAY_STATE_NAME } from "./message-replay.js";
46
46
  import { markAnsweredQuestionsDelivered } from "./questions.js";
47
- import { hasEarlierEligibleQueuedLane, laneAdmissionCapReason, withLaneAdmissionLock, } from "./admission.js";
47
+ import { hasEarlierEligibleQueuedLane, laneAdmissionCapReason, laneRunsOnHost, withLaneAdmissionLock, } from "./admission.js";
48
48
  import { resolveAdmissionHost } from "./admission-host.js";
49
49
  import { offlineFingerprint } from "../fingerprint/offline.js";
50
50
  import { SESSION_ID_ENV_VARS } from "../fingerprint/self-core.js";
@@ -244,7 +244,7 @@ function spawnModelFailure(provider, accountId, config, pinnedModel, profileMode
244
244
  }
245
245
  }
246
246
  function selectSpawnAccount(input) {
247
- const { hqRoot, lane, config, existsSync, accountDeps, modelDeps, pinnedModel, profileModel, currentModelValidated, hostname, repairRecordedAccount, recordedModel, now } = input;
247
+ const { hqRoot, lane, config, existsSync, accountDeps, modelDeps, pinnedModel, profileModel, currentModelValidated, hostname, admissionHost, repairRecordedAccount, recordedModel, now } = input;
248
248
  const context = {
249
249
  hqRoot,
250
250
  existsSync,
@@ -356,11 +356,24 @@ function selectSpawnAccount(input) {
356
356
  (reason === "recorded_account_logged_out" ||
357
357
  (reason === "account_unavailable" && repairRecordedAccount && recordedModel !== undefined));
358
358
  if (recoverRecordedClaudeModel) {
359
+ // A local lane that admission runs on this machine shares its accounts
360
+ // with every other local lane admission runs here, whichever of the
361
+ // machine's ids each record carries. Without a resolved admission host,
362
+ // or for any other lane, only records with the same host id count.
363
+ const localMatch = lane.host.kind === "local" && admissionHost !== undefined && laneRunsOnHost(lane, { ...admissionHost, outpostId: null })
364
+ ? {
365
+ hostname: admissionHost.hostname,
366
+ ...(admissionHost.machineId !== undefined ? { machineId: admissionHost.machineId } : {}),
367
+ ...(admissionHost.aliases !== undefined ? { aliases: admissionHost.aliases } : {}),
368
+ }
369
+ : undefined;
359
370
  const lanes = listLaneIds(hqRoot)
360
371
  .map((laneId) => readLane(hqRoot, laneId))
361
- .filter((record) => record.host.kind === lane.host.kind && record.host.id === lane.host.id);
372
+ .filter((record) => (record.host.kind === lane.host.kind && record.host.id === lane.host.id) ||
373
+ (localMatch !== undefined && laneRunsOnHost(record, { ...localMatch, outpostId: null })));
362
374
  const capacity = buildHostCapacitySnapshot({
363
375
  host: lane.host,
376
+ ...(localMatch !== undefined ? { localMatch } : {}),
364
377
  lanes,
365
378
  config,
366
379
  existsSync,
@@ -2504,6 +2517,7 @@ export function spawnLaneWorker(hqRoot, lane, deps = {}, launch = {}) {
2504
2517
  profileModel,
2505
2518
  currentModelValidated: deps.currentModelValidated === true,
2506
2519
  hostname,
2520
+ ...(deps.admissionHost !== undefined ? { admissionHost: deps.admissionHost } : {}),
2507
2521
  repairRecordedAccount,
2508
2522
  ...(recordedModel !== undefined ? { recordedModel } : {}),
2509
2523
  now: (deps.now ?? (() => new Date()))(),
@@ -0,0 +1,4 @@
1
+ export declare const CORE_NEXT_FLAG = "core.next";
2
+ /** `core.next` for this machine, person or company, offline. */
3
+ export declare function coreNextEnabled(env?: NodeJS.ProcessEnv): boolean;
4
+ //# sourceMappingURL=core-next-flag.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The offline `core.next` decision, kept free of the hook-engine modules so
3
+ * daemon code can read it without loading them (they read the CLI's
4
+ * package.json at import, which breaks bundled daemon children).
5
+ */
6
+ import { readLocalOverride } from '@indigoai-us/hq-flags-client';
7
+ import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from '../lib/flag-snapshot-file.js';
8
+ import { resolveProcessFlagCompanyContext } from '../lib/process-flag-company-context.js';
9
+ export const CORE_NEXT_FLAG = 'core.next';
10
+ /** `core.next` for this machine, person or company, offline. */
11
+ export function coreNextEnabled(env = process.env) {
12
+ const override = readLocalOverride(CORE_NEXT_FLAG, env);
13
+ if (override !== null)
14
+ return override;
15
+ const { companyUid: uid, companySlug } = resolveProcessFlagCompanyContext(env);
16
+ // An explicit company slug that does not resolve stays off, as for the launcher flag.
17
+ if (!uid && companySlug)
18
+ return false;
19
+ const snapshot = uid ? readFlagSnapshotFile(uid, { env }) : readPersonFlagSnapshotFile({ env });
20
+ return snapshot?.flags[CORE_NEXT_FLAG] === true;
21
+ }
22
+ //# sourceMappingURL=core-next-flag.js.map