@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.
Files changed (101) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/README.md +1 -1
  3. package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
  4. package/assets/scaffold/core/scripts/hq-session.sh +4 -0
  5. package/dist/command-catalog.generated.d.ts +69 -0
  6. package/dist/command-catalog.generated.js +83 -0
  7. package/dist/commands/agents.d.ts +22 -0
  8. package/dist/commands/agents.js +92 -1
  9. package/dist/commands/cloud.d.ts +1 -1
  10. package/dist/commands/cloud.js +1 -1
  11. package/dist/commands/core-hook-registration-plan.d.ts +8 -0
  12. package/dist/commands/core-hook-registration-plan.js +21 -0
  13. package/dist/commands/core-hq-session-native.js +3 -0
  14. package/dist/commands/core.js +9 -0
  15. package/dist/commands/doctor.js +4 -0
  16. package/dist/commands/install-global.js +1 -1
  17. package/dist/commands/lanes-shared.d.ts +2 -0
  18. package/dist/commands/lanes-watch.js +28 -1
  19. package/dist/commands/lanes.d.ts +2 -0
  20. package/dist/commands/lanes.js +99 -9
  21. package/dist/commands/members.js +1 -1
  22. package/dist/commands/pack-start-bot.d.ts +1 -1
  23. package/dist/commands/pack-start-bot.js +2 -2
  24. package/dist/commands/pkg-update.js +1 -1
  25. package/dist/commands/reindex.js +6 -0
  26. package/dist/commands/sync-narrow.js +1 -1
  27. package/dist/commands/team-sync.js +1 -1
  28. package/dist/data/command-states.json +8 -1
  29. package/dist/index.js +8 -0
  30. package/dist/lib/anywhere-person-setting.d.ts +2 -2
  31. package/dist/lib/anywhere-person-setting.js +2 -2
  32. package/dist/lib/billing/usage-cost.js +5 -2
  33. package/dist/lib/bot/pack-link.d.ts +2 -2
  34. package/dist/lib/bot/pack-link.js +2 -2
  35. package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
  36. package/dist/lib/daemon/anywhere-listener.js +86 -4
  37. package/dist/lib/daemon/hook-env.d.ts +32 -0
  38. package/dist/lib/daemon/hook-env.js +51 -0
  39. package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
  40. package/dist/lib/daemon/machine-check-owner.js +95 -0
  41. package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
  42. package/dist/lib/daemon/machine-check-registration.js +64 -0
  43. package/dist/lib/daemon/machine-checks.d.ts +144 -0
  44. package/dist/lib/daemon/machine-checks.js +412 -0
  45. package/dist/lib/daemon/ops/policy.js +5 -3
  46. package/dist/lib/daemon/run.js +37 -5
  47. package/dist/lib/daemon/server.d.ts +2 -0
  48. package/dist/lib/daemon/server.js +6 -0
  49. package/dist/lib/daemon/state-file.d.ts +12 -1
  50. package/dist/lib/daemon/state-file.js +23 -1
  51. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -0
  52. package/dist/lib/doctor/checks/fleet-hook-core.js +103 -0
  53. package/dist/lib/doctor/checks/host-core.d.ts +2 -0
  54. package/dist/lib/doctor/checks/host-core.js +81 -11
  55. package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
  56. package/dist/lib/doctor/checks/machine-checks.js +103 -0
  57. package/dist/lib/doctor/checks/sync-runtime.js +3 -3
  58. package/dist/lib/doctor/registry.js +4 -0
  59. package/dist/lib/doctor/types.d.ts +4 -0
  60. package/dist/lib/environment/credential-shapes.d.ts +61 -0
  61. package/dist/lib/environment/credential-shapes.js +333 -0
  62. package/dist/lib/environment/profile.js +4 -16
  63. package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
  64. package/dist/lib/hook-engine/canary-gate.js +147 -0
  65. package/dist/lib/hook-engine/coverage.d.ts +15 -0
  66. package/dist/lib/hook-engine/coverage.js +130 -0
  67. package/dist/lib/hook-engine/fleet-registration.d.ts +30 -0
  68. package/dist/lib/hook-engine/fleet-registration.js +132 -0
  69. package/dist/lib/hook-engine/reconcile.js +297 -116
  70. package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
  71. package/dist/lib/hook-engine/registration-identity.js +97 -0
  72. package/dist/lib/hook-engine/registration.d.ts +1 -23
  73. package/dist/lib/hook-engine/registration.js +1 -52
  74. package/dist/lib/hook-engine/resolve.d.ts +2 -0
  75. package/dist/lib/hook-engine/resolve.js +7 -3
  76. package/dist/lib/install/claude-targets.js +28 -15
  77. package/dist/lib/install/codex-pack-contributions.js +1 -1
  78. package/dist/lib/install/codex-targets.js +24 -11
  79. package/dist/lib/install/hook-target.d.ts +2 -2
  80. package/dist/lib/install/hook-target.js +7 -5
  81. package/dist/lib/lanes/canonical-host.d.ts +8 -1
  82. package/dist/lib/lanes/canonical-host.js +9 -3
  83. package/dist/lib/lanes/machine-identity.d.ts +15 -0
  84. package/dist/lib/lanes/machine-identity.js +26 -0
  85. package/dist/lib/lanes/spawn.js +17 -3
  86. package/dist/lib/packages/setup-block.d.ts +2 -2
  87. package/dist/lib/packages/setup-block.js +2 -2
  88. package/dist/lib/packages/start-bot.d.ts +1 -1
  89. package/dist/lib/packages/start-bot.js +1 -1
  90. package/dist/main.js +1 -1
  91. package/dist/types.d.ts +1 -1
  92. package/dist/utils/callback-port-busy.d.ts +1 -1
  93. package/dist/utils/callback-port-busy.js +4 -4
  94. package/dist/utils/core-next-flag.d.ts +4 -0
  95. package/dist/utils/core-next-flag.js +22 -0
  96. package/dist/utils/core-next-kill.d.ts +16 -0
  97. package/dist/utils/core-next-kill.js +35 -0
  98. package/dist/utils/hook-trust.js +4 -1
  99. package/dist/utils/host-registration.d.ts +80 -17
  100. package/dist/utils/host-registration.js +194 -47
  101. package/package.json +8 -8
@@ -14,56 +14,5 @@ export function registrationEngine(home, env = process.env) {
14
14
  return null;
15
15
  return installHookEngine({ home });
16
16
  }
17
- /**
18
- * Root spelling passed to the launcher. A trailing separator is dropped because
19
- * Windows PowerShell 5.1 re-quotes a native argument containing a space as
20
- * "...", and a final backslash would then escape the closing quote.
21
- */
22
- export function launcherRoot(root) {
23
- const trimmed = root.replace(/[\\/]+$/, '');
24
- return trimmed === '' || /^[A-Za-z]:$/.test(trimmed) ? root : trimmed;
25
- }
26
- export function engineArgs(root, event, runtime, global = false) {
27
- return [event, '--hq-root', launcherRoot(root), '--runtime', runtime, ...(global && runtime === 'claude' ? ['--global'] : [])];
28
- }
29
- /** Recognize only our pinned executable with the exact root argument. */
30
- export function isNativeEntry(entry, root) {
31
- if (typeof entry.command !== 'string')
32
- return false;
33
- const pinned = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]\d+\.\d+\.\d+[^\\/]*[\\/]/;
34
- if (!pinned.test(entry.command))
35
- return false;
36
- const spelling = launcherRoot(root);
37
- if (Array.isArray(entry.args)) {
38
- const i = entry.args.indexOf('--hq-root');
39
- return i >= 0 && entry.args[i + 1] === spelling;
40
- }
41
- return entry.command.includes(quotePosix('--hq-root') + ' ' + quotePosix(spelling));
42
- }
43
- /**
44
- * A registration that calls the new core's entry point, `hq-hook run --host
45
- * <host> <Event> --hq-root <root>`, through the release-stable link
46
- * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
47
- * words and the exact root argument, in exec form (`args`) or as a command
48
- * string (Codex, Grok).
49
- */
50
- export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
51
- export function isCoreNextEntry(entry, root) {
52
- if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
53
- return false;
54
- const spelling = launcherRoot(root);
55
- if (Array.isArray(entry.args)) {
56
- const i = entry.args.indexOf('--hq-root');
57
- return entry.args[0] === 'run' && entry.args[1] === '--host' && i >= 0 && entry.args[i + 1] === spelling;
58
- }
59
- return entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`)
60
- && entry.command.includes(`${quotePosix('--hq-root')} ${quotePosix(spelling)}`);
61
- }
62
- export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
63
- export function quoteWindows(value) {
64
- // Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
65
- // Single-quoted literals prevent variable, subexpression and wildcard expansion.
66
- // PowerShell also closes them on the typographic quotes U+2018-U+201B.
67
- return "'" + value.replace(/['‘’‚‛]/g, '$&$&') + "'";
68
- }
17
+ export { launcherRoot, engineArgs, isNativeEntry, isCoreNextEntry, sameHqRoot, CORE_NEXT_LINK, quotePosix, quoteWindows } from './registration-identity.js';
69
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
  }
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import * as path from 'path';
8
8
  import { engineArgs, isCoreNextEntry, isNativeEntry } from '../hook-engine/registration.js';
9
- import { coreNextArgs, targetForEvent } from '../../utils/host-registration.js';
9
+ import { coreNextArgs, placeEvent, targetForEvent } from '../../utils/host-registration.js';
10
10
  /** Events master-hook.sh is registered for at user scope. */
11
11
  const GLOBAL_HOOK_EVENTS = [
12
12
  'SessionStart',
@@ -151,28 +151,41 @@ export function addHqHooks(doc, hqRoot, target = 'master') {
151
151
  const hooks = { ...(doc.hooks ?? {}) };
152
152
  let changed = false;
153
153
  for (const event of GLOBAL_HOOK_EVENTS) {
154
- // With the new core (US-017), an event it cannot take yet keeps the
155
- // flag-off target.
154
+ // With the new core (US-017), an event it does not cover in full keeps
155
+ // the flag-off target; a covered event's new-core entry takes the place of
156
+ // that target's entry (see `placeEvent`). The caller narrows `target` to
157
+ // the covered events (`hook-engine/coverage.ts` `forHost`).
156
158
  const t = targetForEvent(target, event);
157
- const want = typeof t !== 'object'
158
- ? { type: 'command', command: hookCommand(hqRoot, event, t), timeout: 300 }
159
- : 'coreNext' in t
160
- ? { type: 'command', command: t.coreNext, args: coreNextArgs('claude', event, hqRoot, 'global'), timeout: 300 }
161
- : { type: 'command', command: t.engine, args: engineArgs(hqRoot, event, 'claude', true), timeout: 300 };
159
+ const shellTarget = isCoreNext(t) ? (t.fallback ?? 'master') : t;
160
+ const shellWant = typeof shellTarget !== 'object'
161
+ ? { type: 'command', command: hookCommand(hqRoot, event, shellTarget), timeout: 300 }
162
+ : { type: 'command', command: shellTarget.engine, args: engineArgs(hqRoot, event, 'claude', true), timeout: 300 };
163
+ const want = isCoreNext(t)
164
+ ? { type: 'command', command: t.coreNext, args: coreNextArgs('claude', event, hqRoot, 'global'), timeout: 300 }
165
+ : shellWant;
162
166
  let groups = Array.isArray(hooks[event]) ? [...hooks[event]] : [];
163
- const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && JSON.stringify(h.args) === JSON.stringify('args' in want ? want.args : undefined)));
164
- if (present)
165
- continue;
166
167
  // To or from the new core, the HQ entry keeps its place among the user's
167
168
  // own entries, so their positions (and Codex's position-keyed trust) do
168
169
  // not move. Other target swaps keep today's behaviour.
169
170
  const inPlace = isCoreNext(target) || groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => isCoreNextEntry(h, hqRoot)));
170
- const replaced = inPlace ? replaceInPlace(groups, want, (h) => isHqHookEntry(h, hqRoot)) : null;
171
- if (replaced) {
172
- hooks[event] = replaced;
173
- changed = true;
171
+ if (inPlace) {
172
+ const next = placeEvent(groups, {
173
+ isShell: (h) => isHqHookEntry(h, hqRoot) && !isCoreNextEntry(h, hqRoot),
174
+ isNative: (h) => isCoreNextEntry(h, hqRoot),
175
+ toShell: () => shellWant,
176
+ toNative: isCoreNext(t) ? () => want : null,
177
+ restore: shellWant,
178
+ single: true,
179
+ });
180
+ if (JSON.stringify(next) !== JSON.stringify(groups)) {
181
+ hooks[event] = next;
182
+ changed = true;
183
+ }
174
184
  continue;
175
185
  }
186
+ const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && JSON.stringify(h.args) === JSON.stringify('args' in want ? want.args : undefined)));
187
+ if (present)
188
+ continue;
176
189
  groups = removeHqHooks({ hooks: { [event]: groups } }, hqRoot).hooks?.[event] ?? [];
177
190
  groups.push({ hooks: [want] });
178
191
  hooks[event] = groups;
@@ -204,7 +204,7 @@ export function syncCodexPackHooks(packDir, items, remove = false, home = os.hom
204
204
  return;
205
205
  const target = hooksPath(home);
206
206
  if (hqRoot && sharedAnywherePack) {
207
- const hookTarget = hookTargetFor(hqRoot, home);
207
+ const hookTarget = hookTargetFor(hqRoot, home, undefined, process.env, 'codex');
208
208
  writeConfigAtomic({
209
209
  target,
210
210
  pack: 'hq-anywhere',
@@ -12,8 +12,8 @@
12
12
  import * as fs from 'fs';
13
13
  import { engineArgs, isCoreNextEntry, isNativeEntry, quotePosix, quoteWindows } from '../hook-engine/registration.js';
14
14
  import * as path from 'path';
15
- import { replaceInPlace, shimPath } from './claude-targets.js';
16
- import { coreNextCommand, coreNextCommandWindows, targetForEvent } from '../../utils/host-registration.js';
15
+ import { shimPath } from './claude-targets.js';
16
+ import { coreNextCommand, coreNextCommandWindows, placeEvent, targetForEvent } from '../../utils/host-registration.js';
17
17
  /** Events the Codex hook adapter is registered for at user scope. */
18
18
  const CODEX_HOOK_EVENTS = [
19
19
  'SessionStart',
@@ -212,20 +212,33 @@ export function addCodexHooks(doc, hqRoot, target = 'master') {
212
212
  for (const event of CODEX_HOOK_EVENTS) {
213
213
  const want = codexUserHookEntry(hqRoot, event, target);
214
214
  let groups = Array.isArray(hooks[event]) ? [...hooks[event]] : [];
215
- const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && h.commandWindows === ('commandWindows' in want ? want.commandWindows : undefined)));
216
- if (present)
217
- continue;
218
215
  // To or from the new core, the HQ entry keeps its place: Codex keys a
219
216
  // user's trust of each hook by its position, so moving HQ's entry behind
220
- // the user's own would drop the user's trust. Other target swaps keep
221
- // today's behaviour.
217
+ // the user's own would drop the user's trust. Only an event the new core
218
+ // covers in full switches (the caller narrows `target`); the others keep
219
+ // the adapter entry. Other target swaps keep today's behaviour.
222
220
  const inPlace = (typeof target === 'object' && 'coreNext' in target) || groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => isCoreNextEntry(h, hqRoot)));
223
- const replaced = inPlace ? replaceInPlace(groups, want, (h) => isAdapterEntry(h, hqRoot)) : null;
224
- if (replaced) {
225
- hooks[event] = replaced;
226
- changed = true;
221
+ if (inPlace) {
222
+ const t = targetForEvent(target, event);
223
+ const switched = typeof t === 'object' && 'coreNext' in t;
224
+ const shellWant = switched ? codexUserHookEntry(hqRoot, event, t.fallback ?? 'master') : want;
225
+ const next = placeEvent(groups, {
226
+ isShell: (h) => isAdapterEntry(h, hqRoot) && !isCoreNextEntry(h, hqRoot),
227
+ isNative: (h) => isCoreNextEntry(h, hqRoot),
228
+ toShell: () => shellWant,
229
+ toNative: switched ? () => want : null,
230
+ restore: shellWant,
231
+ single: true,
232
+ });
233
+ if (JSON.stringify(next) !== JSON.stringify(groups)) {
234
+ hooks[event] = next;
235
+ changed = true;
236
+ }
227
237
  continue;
228
238
  }
239
+ const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && h.commandWindows === ('commandWindows' in want ? want.commandWindows : undefined)));
240
+ if (present)
241
+ continue;
229
242
  groups = removeCodexHooks({ hooks: { [event]: groups } }, hqRoot).hooks?.[event] ?? [];
230
243
  groups.push({ hooks: [want] });
231
244
  hooks[event] = groups;
@@ -1,4 +1,4 @@
1
- import { type FallbackTarget } from '../../utils/host-registration.js';
1
+ import { type CoreNextHost, type FallbackTarget } from '../../utils/host-registration.js';
2
2
  import { type HookTarget } from './claude-targets.js';
3
3
  /**
4
4
  * True when this user's hq daemon unit (launchd plist, systemd unit, or the
@@ -10,7 +10,7 @@ export declare function isDaemonInstalled(home: string, platform?: NodeJS.Platfo
10
10
  * US-010: with hqd installed (and the checkout shipping the shim), hooks go to
11
11
  * the hqd shim; otherwise to master-hook.sh / the Codex adapter.
12
12
  */
13
- export declare function hookTargetFor(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv): HookTarget;
13
+ export declare function hookTargetFor(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv, host?: CoreNextHost): HookTarget;
14
14
  /** The target with `core.next` off: the pinned launcher, the hqd shim, or master-hook.sh. */
15
15
  export declare function legacyHookTarget(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv): FallbackTarget;
16
16
  //# sourceMappingURL=hook-target.d.ts.map
@@ -13,6 +13,7 @@ import { readDaemonConfig } from '../daemon/config.js';
13
13
  import { daemonPaths } from '../daemon/paths.js';
14
14
  import { registrationEngine } from '../hook-engine/registration.js';
15
15
  import { coreNextTargetOrWarn } from '../../utils/host-registration.js';
16
+ import { forHost } from '../hook-engine/coverage.js';
16
17
  import { shimPath } from './claude-targets.js';
17
18
  /**
18
19
  * True when this user's hq daemon unit (launchd plist, systemd unit, or the
@@ -33,12 +34,13 @@ export function isDaemonInstalled(home, platform = process.platform, queryTask =
33
34
  * US-010: with hqd installed (and the checkout shipping the shim), hooks go to
34
35
  * the hqd shim; otherwise to master-hook.sh / the Codex adapter.
35
36
  */
36
- export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env) {
37
+ export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude') {
37
38
  // hq-core-rust US-017: `core.next` on registers the new core's entry point
38
- // for the events it can take; every other event keeps the flag-off target.
39
- // A failure to set up the new core is one warning, and install goes on
40
- // with the flag-off target for every event.
41
- const coreNext = coreNextTargetOrWarn(home, env);
39
+ // for the events it covers in full on this host in this HQ root; every
40
+ // other event keeps the flag-off target. A failure to set up the new core
41
+ // is one warning, and install goes on with the flag-off target for every
42
+ // event.
43
+ const coreNext = forHost(coreNextTargetOrWarn(home, env), hqRoot, host);
42
44
  const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env);
43
45
  return coreNext ? { ...coreNext, fallback } : fallback;
44
46
  }
@@ -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()))(),
@@ -5,7 +5,7 @@
5
5
  * A pack that declares one can be set up from the HQ app chat: the pack's own
6
6
  * bot (`setup.bot.name`, also a worker under `contributes.workers`) asks the
7
7
  * questions in order with tap-to-answer suggestions, then runs `setup.run`
8
- * with the answers. `hq packages install` validates the block and fails naming
8
+ * with the answers. `hq install` validates the block and fails naming
9
9
  * the field; a pack without the block is untouched.
10
10
  *
11
11
  * Validation (contract):
@@ -37,7 +37,7 @@ export interface SetupBlockContext {
37
37
  export declare function parseSetupBlock(raw: unknown, ctx: SetupBlockContext): PackSetup | undefined;
38
38
  /**
39
39
  * The validated setup block of an installed pack, or undefined when the pack
40
- * has none or the block is invalid (`hq packages list` prints `setup: no`).
40
+ * has none or the block is invalid (`hq packs list` prints `setup: no`).
41
41
  */
42
42
  export declare function readInstalledPackSetup(manifest: Pick<PackManifest, "setup" | "contributes"> | null | undefined, packDir: string, existsSync?: (p: string) => boolean): PackSetup | undefined;
43
43
  //# sourceMappingURL=setup-block.d.ts.map
@@ -5,7 +5,7 @@
5
5
  * A pack that declares one can be set up from the HQ app chat: the pack's own
6
6
  * bot (`setup.bot.name`, also a worker under `contributes.workers`) asks the
7
7
  * questions in order with tap-to-answer suggestions, then runs `setup.run`
8
- * with the answers. `hq packages install` validates the block and fails naming
8
+ * with the answers. `hq install` validates the block and fails naming
9
9
  * the field; a pack without the block is untouched.
10
10
  *
11
11
  * Validation (contract):
@@ -217,7 +217,7 @@ export function parseSetupBlock(raw, ctx) {
217
217
  }
218
218
  /**
219
219
  * The validated setup block of an installed pack, or undefined when the pack
220
- * has none or the block is invalid (`hq packages list` prints `setup: no`).
220
+ * has none or the block is invalid (`hq packs list` prints `setup: no`).
221
221
  */
222
222
  export function readInstalledPackSetup(manifest, packDir, existsSync) {
223
223
  if (!manifest || manifest.setup === undefined)
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `hq packages install <source> --start-bot` (sample-pack-in-app-setup US-003,
2
+ * `hq install <source> --start-bot` (sample-pack-in-app-setup US-003,
3
3
  * build contract section 3).
4
4
  *
5
5
  * After a pack with a valid `setup:` block is wired, create the personal bot
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `hq packages install <source> --start-bot` (sample-pack-in-app-setup US-003,
2
+ * `hq install <source> --start-bot` (sample-pack-in-app-setup US-003,
3
3
  * build contract section 3).
4
4
  *
5
5
  * After a pack with a valid `setup:` block is wired, create the personal bot
package/dist/main.js CHANGED
@@ -231,7 +231,7 @@ export async function runCli() {
231
231
  // Login must be usable before any identity or company is available, so do
232
232
  // not make a pre-auth feature-flag request on this path. Other commands
233
233
  // retain the shared asynchronous registry refresh.
234
- const isAuthLogin = process.argv[2] === "auth" && process.argv[3] === "login";
234
+ const isAuthLogin = process.argv[2] === "login" || (process.argv[2] === "auth" && process.argv[3] === "login");
235
235
  if (!isAuthLogin) {
236
236
  runGlobalNetworkLifecycle(process.argv, () => {
237
237
  void kickFlagRegistryReadiness({
package/dist/types.d.ts CHANGED
@@ -130,7 +130,7 @@ export interface PackManifest {
130
130
  /**
131
131
  * Guided in-app setup. Optional — absent on
132
132
  * legacy packs, which install unchanged. Validated by
133
- * `lib/packages/setup-block.ts`; `hq packages install --start-bot` creates the
133
+ * `lib/packages/setup-block.ts`; `hq install --start-bot` creates the
134
134
  * bot it names and the bot's system prompt renders the questions and the run
135
135
  * command from it.
136
136
  */
@@ -8,7 +8,7 @@ export declare const DEFAULT_CALLBACK_PORT = 8765;
8
8
  export declare function callbackPortBusyGuidance(port: number): string;
9
9
  /**
10
10
  * The LOOSE predicate for a caller that just invoked browserLogin and is
11
- * catching its own error (`hq auth login`/`hq login`): an EADDRINUSE by errno
11
+ * catching its own error (`hq login`): an EADDRINUSE by errno
12
12
  * code OR message is the callback-port collision, because the callback server is
13
13
  * the only listener that call could have opened. NOT for the shared boundary —
14
14
  * use {@link callbackPortBusyMessage} there.
@@ -21,14 +21,14 @@
21
21
  // address already in use 127.0.0.1:8765`. That Node error carries no `expected`
22
22
  // flag and is not an AuthError/CognitoAuthError/…, so every predicate in
23
23
  // handleTopLevelError returned false and the collision was captured as a
24
- // high-priority, unfixable "crash". `hq auth login` already classified the
24
+ // high-priority, unfixable "crash". `hq login` already classified the
25
25
  // identical condition in a file-private helper; this module lifts that
26
26
  // classification to the shared boundary so every implicit call site is covered
27
27
  // from one source of truth.
28
28
  //
29
29
  // Two predicates, differing ONLY by how much context the caller already has:
30
30
  // - isCallbackPortBusy(err): the LOOSE form for a call site that KNOWS it just
31
- // invoked browserLogin (`hq auth login`/`hq login`). There the only listener
31
+ // invoked browserLogin (`hq login`). There the only listener
32
32
  // in play is the callback server, so an EADDRINUSE — by code or message — is
33
33
  // unambiguously the callback port.
34
34
  // - callbackPortBusyMessage(err, port): the STRUCTURAL form for the shared
@@ -47,12 +47,12 @@ const EADDRINUSE = "EADDRINUSE";
47
47
  */
48
48
  export function callbackPortBusyGuidance(port) {
49
49
  return (`The browser-login callback port (127.0.0.1:${port}) is already in use. ` +
50
- "Another `hq auth login` may still be waiting for browser sign-in. Finish that login, " +
50
+ "Another `hq login` may still be waiting for browser sign-in. Finish that login, " +
51
51
  "or stop its terminal/process, then retry.");
52
52
  }
53
53
  /**
54
54
  * The LOOSE predicate for a caller that just invoked browserLogin and is
55
- * catching its own error (`hq auth login`/`hq login`): an EADDRINUSE by errno
55
+ * catching its own error (`hq login`): an EADDRINUSE by errno
56
56
  * code OR message is the callback-port collision, because the callback server is
57
57
  * the only listener that call could have opened. NOT for the shared boundary —
58
58
  * use {@link callbackPortBusyMessage} there.
@@ -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
@@ -0,0 +1,16 @@
1
+ /** Engine-side kill switch: environment variable and file under the home folder. */
2
+ export declare const CORE_NEXT_KILL_ENV = "HQ_CORE_NEXT";
3
+ export declare const CORE_NEXT_KILL_FILE: string;
4
+ /** The engine-wide kill switch the bridge already honors; the engine checks it too. */
5
+ export declare const ENGINE_KILL_ENV = "HQ_HOOK_ENGINE";
6
+ export declare const ENGINE_KILL_FILE: string;
7
+ /**
8
+ * Why the new core is switched off on this machine, or null. The same four
9
+ * switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
10
+ * `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
11
+ * `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
12
+ * for the engine). With any of them on, `hq reindex` removes the new-core
13
+ * entries it added, so the registrations are what they were before the switch.
14
+ */
15
+ export declare function coreNextKillReason(home: string, env?: NodeJS.ProcessEnv): string | null;
16
+ //# sourceMappingURL=core-next-kill.d.ts.map