@indigoai-us/hq-cli 5.345.264 → 5.345.268

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 (68) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-grant.sh +4 -48
  3. package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +16 -10
  4. package/assets/scaffold/core/scripts/hq-delegate-send.sh +17 -1
  5. package/contracts/host-canary-release.json +7 -7
  6. package/dist/command-catalog.generated.d.ts +30 -1
  7. package/dist/command-catalog.generated.js +37 -1
  8. package/dist/commands/core-delegate-w1b.js +21 -40
  9. package/dist/commands/core-delegate.js +11 -8
  10. package/dist/commands/core-job-notify-native.d.ts +6 -0
  11. package/dist/commands/core-job-notify-native.js +64 -4
  12. package/dist/commands/core-jobs-native.js +3 -16
  13. package/dist/commands/files-browse.d.ts +83 -4
  14. package/dist/commands/files-browse.js +404 -54
  15. package/dist/commands/groups.js +2 -2
  16. package/dist/commands/install-global.js +54 -17
  17. package/dist/commands/skill.js +15 -0
  18. package/dist/lib/agent-kit/mcp/tools.js +2 -2
  19. package/dist/lib/agent-kit/skills.js +12 -6
  20. package/dist/lib/daemon/machine-check-owner.js +1 -1
  21. package/dist/lib/daemon/machine-checks.d.ts +3 -11
  22. package/dist/lib/daemon/machine-checks.js +4 -15
  23. package/dist/lib/daemon/merge-sections.d.ts +44 -9
  24. package/dist/lib/daemon/merge-sections.js +234 -37
  25. package/dist/lib/daemon/run.js +1 -0
  26. package/dist/lib/doctor/checks/antigravity-wiring.js +20 -4
  27. package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
  28. package/dist/lib/doctor/checks/codex-wiring.js +70 -13
  29. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
  30. package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
  31. package/dist/lib/doctor/checks/grok-wiring.js +38 -0
  32. package/dist/lib/doctor/checks/hook-engine.js +0 -2
  33. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  34. package/dist/lib/doctor/checks/host-core.js +17 -42
  35. package/dist/lib/doctor/fix/process-identity.d.ts +2 -0
  36. package/dist/lib/doctor/fix/process-identity.js +5 -2
  37. package/dist/lib/hook-engine/coverage.d.ts +10 -1
  38. package/dist/lib/hook-engine/coverage.js +76 -9
  39. package/dist/lib/hook-engine/fleet-registration.js +7 -4
  40. package/dist/lib/hook-engine/native-precompact-compatibility.json +8 -1
  41. package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
  42. package/dist/lib/hook-engine/reconcile.d.ts +10 -1
  43. package/dist/lib/hook-engine/reconcile.js +351 -44
  44. package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
  45. package/dist/lib/hook-engine/stable-gate.js +276 -0
  46. package/dist/lib/hot-channels/fleet-complete.js +2 -2
  47. package/dist/lib/install/antigravity-targets.js +2 -1
  48. package/dist/lib/install/claude-targets.d.ts +6 -6
  49. package/dist/lib/install/claude-targets.js +13 -9
  50. package/dist/lib/install/codex-targets.d.ts +4 -4
  51. package/dist/lib/install/codex-targets.js +26 -16
  52. package/dist/lib/install/hook-target.d.ts +23 -2
  53. package/dist/lib/install/hook-target.js +89 -16
  54. package/dist/lib/outpost-identity-env.d.ts +18 -0
  55. package/dist/lib/outpost-identity-env.js +29 -0
  56. package/dist/lib/signals/reply.js +25 -5
  57. package/dist/lib/signals/steps/extract.d.ts +28 -4
  58. package/dist/lib/signals/steps/extract.js +158 -10
  59. package/dist/lib/sync-core/release.d.ts +1 -1
  60. package/dist/lib/sync-core/release.js +2 -2
  61. package/dist/utils/core-next-kill.d.ts +2 -15
  62. package/dist/utils/core-next-kill.js +5 -36
  63. package/dist/utils/hook-engine-rollup.js +0 -1
  64. package/dist/utils/hook-trust.d.ts +2 -0
  65. package/dist/utils/hook-trust.js +156 -13
  66. package/dist/utils/host-registration.d.ts +158 -4
  67. package/dist/utils/host-registration.js +500 -17
  68. package/package.json +7 -7
@@ -1,4 +1,7 @@
1
- import { hookTargetFor } from '../lib/install/hook-target.js';
1
+ import { resolveInstallHookTarget } from '../lib/install/hook-target.js';
2
+ import { isNativeOnlyCoreRoot } from '../lib/hook-engine/coverage.js';
3
+ import { HQ_CLI_NPM_REPAIR_COMMAND } from '../utils/npm-install-flags.js';
4
+ import { resolvePortableEngineForNativeOnly } from '../utils/host-registration.js';
2
5
  /**
3
6
  * `hq install --global --runtime claude` / `hq uninstall --global --runtime claude`
4
7
  * (hq-anywhere-runtime US-005).
@@ -138,16 +141,39 @@ function canonical(v) {
138
141
  : val);
139
142
  }
140
143
  /** JSON settings format whose verify step checks every HQ hook is registered. */
141
- function settingsInstallFormat(hqRoot, target) {
144
+ function settingsInstallFormat(hqRoot, target, platform = process.platform) {
142
145
  return {
143
146
  ...jsonFormat,
144
147
  emptyDoc: () => ({}),
145
148
  assertEntry(doc) {
146
- if (!hasAllHqHooks(doc, hqRoot, target))
149
+ if (!hasAllHqHooks(doc, hqRoot, target, platform))
147
150
  throw new Error('HQ hooks not present after write');
148
151
  },
149
152
  };
150
153
  }
154
+ /**
155
+ * When writing a portable native wrapper for a native-only HQ root, ensure
156
+ * `<home>/.hq/bin/hq-hook/stable` exists and points to an accepted engine
157
+ * before writing any host settings. When `core.next` is on and the host canary
158
+ * gate refused the new engine (M-2), falls back only to a previously accepted
159
+ * engine already linked at `stable` and never links the refused engine.
160
+ * Refuses clearly when no accepted engine is available so global install never
161
+ * writes a wrapper that blocks every session or runs a canary-refused engine.
162
+ */
163
+ function ensurePortableEngineOrThrow(hqRoot, home, target, env, host, platform, refusedCandidate) {
164
+ if (target !== 'portable')
165
+ return;
166
+ const resolution = resolvePortableEngineForNativeOnly(home, {
167
+ platform,
168
+ env,
169
+ host,
170
+ root: hqRoot,
171
+ candidate: refusedCandidate ?? null,
172
+ });
173
+ if (!resolution.stable) {
174
+ throw Object.assign(new Error(`Cannot install HQ global hooks for native-only HQ root ${hqRoot}: ${resolution.refusalReason ?? `repair with: ${HQ_CLI_NPM_REPAIR_COMMAND}`}`), { expected: true });
175
+ }
176
+ }
151
177
  /**
152
178
  * Removal format: verifies no HQ hook remains, and serializes a doc that equals
153
179
  * the pre-install document back to the ORIGINAL bytes (byte-identical uninstall).
@@ -347,7 +373,10 @@ function readState(t) {
347
373
  function assertHqRoot(hqRoot) {
348
374
  if (!path.isAbsolute(hqRoot))
349
375
  throw new Error(`HQ root must be absolute: ${hqRoot}`);
350
- for (const p of [charterPath(hqRoot), masterHookPath(hqRoot)]) {
376
+ const required = isNativeOnlyCoreRoot(hqRoot)
377
+ ? [charterPath(hqRoot)]
378
+ : [charterPath(hqRoot), masterHookPath(hqRoot)];
379
+ for (const p of required) {
351
380
  if (!fs.existsSync(p))
352
381
  throw new Error(`${hqRoot} is not an HQ checkout (missing ${p})`);
353
382
  }
@@ -419,10 +448,11 @@ export function installGlobalClaude(opts) {
419
448
  const marketplaceNeedsAdd = !!pluginSource && existingMarketplace === undefined;
420
449
  const pluginAdded = !!pluginSource && (prior?.plugin?.pluginAdded === true || pluginNeedsInstall);
421
450
  const marketplaceAdded = !!pluginSource && (prior?.plugin?.marketplaceAdded === true || marketplaceNeedsAdd);
422
- const hookTarget = hookTargetFor(hqRoot, home, opts.daemonInstalled, env);
451
+ const platform = opts.platform ?? process.platform;
452
+ const { target: hookTarget, refusedCandidate } = resolveInstallHookTarget(hqRoot, home, opts.daemonInstalled, env, 'claude', platform);
423
453
  const settingsNext = pluginSource
424
454
  ? cleanupRoots.reduce((doc, root) => removeHqHooks(doc, root), settingsDoc)
425
- : addHqHooks(settingsDoc, hqRoot, hookTarget);
455
+ : addHqHooks(settingsDoc, hqRoot, hookTarget, platform);
426
456
  const skillLinksToRemove = [...new Set(pluginSource
427
457
  ? cleanupRoots.flatMap((root) => hqSkillLinksForRoot(t.skillsDir, root))
428
458
  : cleanupRoots.flatMap((root) => hqCompanySkillLinksForRoot(t.skillsDir, root)))];
@@ -468,6 +498,8 @@ export function installGlobalClaude(opts) {
468
498
  log(`Would run: claude plugin marketplace add --scope user ${pluginSource.sourceDir}; claude plugin install --scope user -y ${pluginSource.pluginId}`);
469
499
  return touched;
470
500
  }
501
+ if (!pluginSource)
502
+ ensurePortableEngineOrThrow(hqRoot, home, hookTarget, env, 'claude', platform, refusedCandidate);
471
503
  if (pluginSource && (marketplaceNeedsAdd || pluginNeedsInstall)) {
472
504
  let marketplaceMayNeedRollback = false;
473
505
  try {
@@ -555,8 +587,8 @@ export function installGlobalClaude(opts) {
555
587
  writeConfigAtomic({
556
588
  target: t.settingsJson,
557
589
  pack: HQ_ANYWHERE_PACK,
558
- format: settingsInstallFormat(hqRoot, hookTarget),
559
- merge: (doc) => addHqHooks(doc, hqRoot, hookTarget),
590
+ format: settingsInstallFormat(hqRoot, hookTarget, platform),
591
+ merge: (doc) => addHqHooks(doc, hqRoot, hookTarget, platform),
560
592
  assertName: 'hooks',
561
593
  env: { home },
562
594
  });
@@ -607,7 +639,7 @@ export function installGlobalClaude(opts) {
607
639
  if (pluginSource)
608
640
  log(` plugin: ${pluginSource.pluginId} installed from ${pluginSource.sourceDir}; direct hooks and MCP entries removed`);
609
641
  else {
610
- log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'shim' ? 'hqd-hook-shim.sh' : 'master-hook.sh'} registered in ${t.settingsJson}`);
642
+ log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'portable' ? 'hq-hook (portable)' : hookTarget === 'shim' ? 'hqd-hook-shim.sh' : 'master-hook.sh'} registered in ${t.settingsJson}`);
611
643
  log(` MCP: "${HQ_MCP_SERVER_NAME}" registered in ${t.claudeJson}`);
612
644
  }
613
645
  log(` registry: ${seeded.length} manifest entr${seeded.length === 1 ? 'y' : 'ies'} seeded`);
@@ -792,17 +824,20 @@ function readCodexState(t) {
792
824
  function assertCodexHqRoot(hqRoot) {
793
825
  if (!path.isAbsolute(hqRoot))
794
826
  throw new Error(`HQ root must be absolute: ${hqRoot}`);
795
- for (const p of [codexCharterSource(hqRoot), codexAdapterPath(hqRoot)]) {
827
+ const required = isNativeOnlyCoreRoot(hqRoot)
828
+ ? [codexCharterSource(hqRoot)]
829
+ : [codexCharterSource(hqRoot), codexAdapterPath(hqRoot)];
830
+ for (const p of required) {
796
831
  if (!fs.existsSync(p))
797
832
  throw new Error(`${hqRoot} is not an HQ checkout (missing ${p})`);
798
833
  }
799
834
  }
800
- function hooksInstallFormat(hqRoot, target) {
835
+ function hooksInstallFormat(hqRoot, target, platform = process.platform) {
801
836
  return {
802
837
  ...jsonFormat,
803
838
  emptyDoc: () => ({}),
804
839
  assertEntry(doc) {
805
- if (!hasAllCodexHooks(doc, hqRoot, target))
840
+ if (!hasAllCodexHooks(doc, hqRoot, target, platform))
806
841
  throw new Error('HQ Codex hooks not present after write');
807
842
  },
808
843
  };
@@ -850,10 +885,11 @@ export function installGlobalCodex(opts) {
850
885
  }
851
886
  const skills = planSkills(hqRoot, t);
852
887
  const companySkillLinksToRemove = [...new Set(cleanupRoots.flatMap((root) => hqCompanySkillLinksForRoot(t.skillsDir, root)))];
888
+ const platform = opts.platform ?? process.platform;
853
889
  const hooksOld = readOrNull(t.hooksJson);
854
890
  const hooksDoc = readConfigDoc(t.hooksJson, jsonFormat).doc;
855
- const hookTarget = hookTargetFor(hqRoot, home, opts.daemonInstalled, env, 'codex');
856
- const hooksNext = addCodexHooks(hooksDoc, hqRoot, hookTarget);
891
+ const { target: hookTarget, refusedCandidate } = resolveInstallHookTarget(hqRoot, home, opts.daemonInstalled, env, 'codex', platform);
892
+ const hooksNext = addCodexHooks(hooksDoc, hqRoot, hookTarget, platform);
857
893
  const tomlOld = readOrNull(t.configToml);
858
894
  const tomlDoc = readConfigDoc(t.configToml, codexConfigFormat).doc;
859
895
  const codexServers = tomlDoc.value.mcp_servers;
@@ -903,6 +939,7 @@ export function installGlobalCodex(opts) {
903
939
  log(lineDiff(codexConfigFormat.serialize(tomlDoc), codexConfigFormat.serialize(tomlNext)));
904
940
  return touched;
905
941
  }
942
+ ensurePortableEngineOrThrow(hqRoot, home, hookTarget, env, 'codex', platform, refusedCandidate);
906
943
  // Skill links go first so a link failure leaves no pointer or AGENTS.md
907
944
  // block behind (see installGlobalClaude).
908
945
  const skillsDirExisted = fs.existsSync(t.skillsDir);
@@ -945,8 +982,8 @@ export function installGlobalCodex(opts) {
945
982
  writeConfigAtomic({
946
983
  target: t.hooksJson,
947
984
  pack: HQ_ANYWHERE_PACK,
948
- format: hooksInstallFormat(hqRoot, hookTarget),
949
- merge: (doc) => addCodexHooks(doc, hqRoot, hookTarget),
985
+ format: hooksInstallFormat(hqRoot, hookTarget, platform),
986
+ merge: (doc) => addCodexHooks(doc, hqRoot, hookTarget, platform),
950
987
  assertName: 'hooks',
951
988
  env: { home },
952
989
  });
@@ -986,7 +1023,7 @@ export function installGlobalCodex(opts) {
986
1023
  log(` skills linked: ${skills.link.length} new, ${skills.already.length} already present, ${skills.skipped.length} skipped`);
987
1024
  reportSkillCopies(linkKinds, log);
988
1025
  reportSkippedSkills(skills, log, false);
989
- log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'shim' ? shimPath(hqRoot) : codexAdapterPath(hqRoot)} registered in ${t.hooksJson}`);
1026
+ log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'portable' ? 'hq-hook (portable)' : hookTarget === 'shim' ? shimPath(hqRoot) : codexAdapterPath(hqRoot)} registered in ${t.hooksJson}`);
990
1027
  log(` MCP: "${HQ_MCP_SERVER_NAME}" registered in ${t.configToml}`);
991
1028
  return touched;
992
1029
  }
@@ -68,6 +68,15 @@ function skillUploadRefused(skillUid, filePath, companySlug, refused) {
68
68
  ...(refused.upgradeUrl ? { upgradeUrl: refused.upgradeUrl } : {}),
69
69
  });
70
70
  }
71
+ /**
72
+ * share() returned without aborting or a plan-limit, but uploaded nothing.
73
+ * Printing "Sync: complete" here is how a registered skill showed up in the
74
+ * company list with no vault SKILL.md (feedback_9ad15468).
75
+ */
76
+ function skillUploadDidNotReachVault(skillUid, filePath, companySlug) {
77
+ console.warn(chalk.yellow(`⚠ Skill ${skillUid} is stamped locally at '${filePath}', but the file was not uploaded.`));
78
+ return localSkillError(`The skill file was not uploaded. Upload it with: hq sync push --company ${companySlug} '${filePath}'`);
79
+ }
71
80
  export function parseSkillUid(markdown) {
72
81
  const match = markdown.match(FRONTMATTER_RE);
73
82
  if (!match)
@@ -605,6 +614,9 @@ export function registerSkillCommand(program, deps = {}) {
605
614
  if (syncResult.planLimit) {
606
615
  throw skillUploadRefused(registered.skillUid, filePath, companySlug, syncResult.planLimit);
607
616
  }
617
+ if (syncResult.filesUploaded === 0) {
618
+ throw skillUploadDidNotReachVault(registered.skillUid, filePath, companySlug);
619
+ }
608
620
  }
609
621
  console.log(chalk.green(`Skill ready: ${registered.skillUid}`));
610
622
  console.log(` File: ${filePath}`);
@@ -772,6 +784,9 @@ export function registerSkillCommand(program, deps = {}) {
772
784
  if (syncResult.planLimit) {
773
785
  throw skillUploadRefused(skillUid, canonicalPath, companySlug, syncResult.planLimit);
774
786
  }
787
+ if (syncResult.filesUploaded === 0) {
788
+ throw skillUploadDidNotReachVault(skillUid, canonicalPath, companySlug);
789
+ }
775
790
  }
776
791
  console.log(chalk.green(`Skill promoted: ${skillUid}`));
777
792
  console.log(` File: ${canonicalPath}`);
@@ -131,7 +131,7 @@ export function buildAgentMcpTools(clients) {
131
131
  name: "hq_search",
132
132
  description: clients.syncFiles
133
133
  ? "Search the synced company vault (local qmd index). Modes: keyword (default), semantic, hybrid."
134
- : "Search the company vault by file name and path, server-side (no local copy is kept). Content and semantic search need a kit installed with --sync-files.",
134
+ : "Search the company vault by file name and path (no local copy is kept). Slow on large companies: it lists the entire company vault, which can take minutes. If you know the path, use hq_files_read; to look inside a folder, use hq_files_list with a narrow path. Content and semantic search need a kit installed with --sync-files.",
135
135
  inputSchema: {
136
136
  type: "object",
137
137
  properties: {
@@ -155,7 +155,7 @@ export function buildAgentMcpTools(clients) {
155
155
  if (mode && mode !== "keyword") {
156
156
  throw new McpToolInputError(`"${mode}" search needs a local copy of the vault; this agent reads files on demand. Use keyword, or reinstall the kit with \`hq agent kit install --sync-files\`.`);
157
157
  }
158
- return fromRun(await clients.runHq(["files", "search", query, "--company", company]), "hq files search");
158
+ return fromRun(await clients.runHq(["files", "search", query, "--company", company, "--no-local", "--quiet"]), "hq files search");
159
159
  }
160
160
  const hqArgs = ["search", query, "--mode", mode ?? "keyword", "-n", String(count), "--json"];
161
161
  return fromRun(await clients.runHq(hqArgs), "hq search");
@@ -62,17 +62,23 @@ mark each item done.
62
62
  description: "Find things in the company vault (documents, knowledge, meeting notes) with the hq CLI.",
63
63
  body: `# HQ search
64
64
 
65
- By default this agent keeps no local copy of the vault, so search runs
66
- server-side and matches file NAMES and paths, not file contents:
65
+ By default this agent keeps no local copy of the vault. Without it, search
66
+ matches file NAMES and paths, not file contents:
67
67
 
68
68
  \`\`\`bash
69
- hq files search "<query>" --company <slug> # find files by name/path
70
- hq files browse companies/<slug>/<folder> # list a folder
69
+ hq files get companies/<slug>/<file> # fetch one file when you know its path
71
70
  hq files cat companies/<slug>/<file> # read one file
71
+ hq files browse companies/<slug>/<folder> # list one folder
72
+ hq files search "<query>" --company <slug> # find files by name/path (slow)
72
73
  \`\`\`
73
74
 
74
- A good pattern for a question you cannot answer from names alone: search or
75
- browse to narrow to a few likely files, then read them with \`hq files cat\`.
75
+ \`hq files search\` lists the entire company vault and filters it locally, so
76
+ on a large company it can take several minutes. If you know the path, use
77
+ \`hq files get\` or \`hq files cat\`. To look inside a folder, use \`hq files browse\`
78
+ with a narrow prefix. Search only when you know neither.
79
+
80
+ A good pattern for a question you cannot answer from names alone: browse a
81
+ narrow folder to find a few likely files, then read them with \`hq files cat\`.
76
82
 
77
83
  Content and semantic search need a local copy and its index, which only exists
78
84
  if the kit was installed with \`--sync-files\`. In that case (check
@@ -46,7 +46,7 @@ function decideOwner(env, home, now, platform) {
46
46
  if (platform === "win32")
47
47
  return { owner: "legacy", reason: "windows: machine checks need /bin/bash" };
48
48
  if (!machineChecksScheduleOn(env, home))
49
- return { owner: "legacy", reason: "core.next is off or a kill switch is set" };
49
+ return { owner: "legacy", reason: "core.next is off" };
50
50
  const sessionRoot = env.HQ_ROOT?.trim();
51
51
  let daemonRoot;
52
52
  try {
@@ -155,20 +155,12 @@ export declare const MACHINE_CHECKS_INTERVAL_MS: number;
155
155
  export declare const MACHINE_CHECKS_MIN_INTERVAL_MS: number;
156
156
  /** Use the same offline flag decision as hook registration. */
157
157
  export declare const machineChecksCoreNextOn: typeof coreNextEnabled;
158
- /**
159
- * A switch that sends this machine back to the old hook core is set:
160
- * HQ_CORE_NEXT is off, 0, false or no; HQ_HOOK_ENGINE is off (both trimmed,
161
- * any ASCII case); or `<home>/.hq/state/core-next.off` or
162
- * `<home>/.hq/hook-engine.off` exists (any file type, a link counts). These
163
- * are the switches the hook engine checks.
164
- */
165
- export declare function machineChecksKillSwitchSet(env: NodeJS.ProcessEnv, home: string): boolean;
166
158
  /**
167
159
  * The daemon's schedule runs when the new hook core (`core.next`) is on for
168
- * this machine and no kill switch is set, so the checks leave the hook path
169
- * exactly when the machine moves to the new core and nothing runs twice.
160
+ * this machine, so the checks leave the hook path when the machine moves to
161
+ * the new core and nothing runs twice.
170
162
  */
171
- export declare function machineChecksScheduleOn(env: NodeJS.ProcessEnv, home: string): boolean;
163
+ export declare function machineChecksScheduleOn(env: NodeJS.ProcessEnv, _home: string): boolean;
172
164
  export interface MachineCheckScheduleOptions {
173
165
  env: NodeJS.ProcessEnv;
174
166
  /** The home folder that holds the kill-switch files. */
@@ -37,7 +37,6 @@ import { createHash } from "node:crypto";
37
37
  import * as fs from "node:fs";
38
38
  import * as path from "node:path";
39
39
  import { coreNextEnabled } from "../../utils/core-next-flag.js";
40
- import { coreNextKillReason } from "../../utils/core-next-kill.js";
41
40
  import { isExcludedWindowsBash, resolveWindowsBash } from "../../utils/windows-bash.js";
42
41
  import { anyNativeSessionStartRegistered } from "./machine-check-registration.js";
43
42
  import { nativeNoticeLedgerUsable, nativeNoticeShownFingerprints } from "./native-notice-ledger.js";
@@ -428,23 +427,13 @@ export const MACHINE_CHECKS_INTERVAL_MS = 60 * 60_000;
428
427
  export const MACHINE_CHECKS_MIN_INTERVAL_MS = 15 * 60_000;
429
428
  /** Use the same offline flag decision as hook registration. */
430
429
  export const machineChecksCoreNextOn = coreNextEnabled;
431
- /**
432
- * A switch that sends this machine back to the old hook core is set:
433
- * HQ_CORE_NEXT is off, 0, false or no; HQ_HOOK_ENGINE is off (both trimmed,
434
- * any ASCII case); or `<home>/.hq/state/core-next.off` or
435
- * `<home>/.hq/hook-engine.off` exists (any file type, a link counts). These
436
- * are the switches the hook engine checks.
437
- */
438
- export function machineChecksKillSwitchSet(env, home) {
439
- return coreNextKillReason(home, env) !== null;
440
- }
441
430
  /**
442
431
  * The daemon's schedule runs when the new hook core (`core.next`) is on for
443
- * this machine and no kill switch is set, so the checks leave the hook path
444
- * exactly when the machine moves to the new core and nothing runs twice.
432
+ * this machine, so the checks leave the hook path when the machine moves to
433
+ * the new core and nothing runs twice.
445
434
  */
446
- export function machineChecksScheduleOn(env, home) {
447
- return !machineChecksKillSwitchSet(env, home) && machineChecksCoreNextOn(env);
435
+ export function machineChecksScheduleOn(env, _home) {
436
+ return machineChecksCoreNextOn(env);
448
437
  }
449
438
  /**
450
439
  * The checks to commit in this batch: each whose last result (the results
@@ -4,16 +4,27 @@
4
4
  * - merge_holds: every repository merge hold record under
5
5
  * <hqRoot>/workspace/lanes/holds, grouped by the company that owns it, with
6
6
  * that company's `lanes.repo-merge-hold` flag;
7
- * - merge_approvals: per session id, the conduct-link decision queue that
8
- * gates the session's merges, the session's company, and whether the
9
- * `lanes.review-before-merge` gate applies to it, with the lane review
10
- * records.
7
+ * - merge_approvals: per session id, the conduct link whose decision queue
8
+ * gates the session's merges and whether that queue could be read (closed
9
+ * links and stale conductor pointers omitted), the session's company, and
10
+ * whether the `lanes.review-before-merge` gate applies to it, with the lane
11
+ * review records.
12
+ *
13
+ * `decisions` is always written as an empty array. The native owner-approval
14
+ * gate (crates/hq-hook/src/rules/conduct_files.rs) reads the conduct link and
15
+ * its decision queue from disk when the merge is called, so unanswered,
16
+ * withdrawn and superseded decisions are decided there; no reader decides from
17
+ * this section's copy. Copying the queue once per session made the section
18
+ * grow with sessions x queue length (4.5 MB on one machine). The key stays,
19
+ * as an empty array, because released hook binaries require it when
20
+ * queue_status is "present".
11
21
  *
12
22
  * The native merge check in crates/hq-hook reads only these two sections and
13
23
  * starts no process. It refuses every merge while a section is missing, has a
14
- * missing or wrongly typed field, or its `refreshed_at` is older than
15
- * min(max_age_seconds, 60) seconds, so whenever a decision cannot be made here
16
- * the section (or the session) is written so the check refuses:
24
+ * missing or wrongly typed field, exceeds MAX_SECTION_BYTES (256 KiB), or its
25
+ * `refreshed_at` is older than min(max_age_seconds, 60) seconds, so whenever a
26
+ * decision cannot be made here the section (or the session) is written so the
27
+ * check refuses:
17
28
  *
18
29
  * - a hold file `hq runners hold` would refuse, an unreadable holds folder, or
19
30
  * an unreadable `lanes.repo-merge-hold` flag omits merge_holds;
@@ -22,7 +33,12 @@
22
33
  * whose company cannot be resolved is written with queue_status
23
34
  * "unreadable";
24
35
  * - an unreadable `lanes.review-before-merge` flag writes review_required
25
- * true with no reviews.
36
+ * true with no reviews;
37
+ * - if merge_approvals would still exceed MERGE_APPROVALS_MAX_SECTION_BYTES
38
+ * (a backstop: with no decisions copied it is not expected), the largest
39
+ * sessions lose their review records while keeping review_required, so
40
+ * only those sessions refuse, rather than letting the whole section exceed
41
+ * the reader's cap and refuse every session.
26
42
  *
27
43
  * Files are read through src/lib/safe-store.ts (a regular single-link file of
28
44
  * this user in a folder no other user can write), except lane records and
@@ -33,6 +49,12 @@ import { type RepoMergeHold } from "../lanes/repo-merge-hold.js";
33
49
  import { type LaneCompanyRef } from "../lanes/types.js";
34
50
  export declare const MERGE_HOLDS_SCHEMA = "merge-holds.v1";
35
51
  export declare const MERGE_APPROVALS_SCHEMA = "merge-approvals.v1";
52
+ export declare const MERGE_APPROVALS_SECTION_NAME = "merge_approvals";
53
+ /**
54
+ * Per-section cap enforced by `crates/hq-hook/src/state.rs` (`MAX_SECTION_BYTES`):
55
+ * the section name (`"merge_approvals"`) plus compact UTF-8 JSON bytes.
56
+ */
57
+ export declare const MERGE_APPROVALS_MAX_SECTION_BYTES: number;
36
58
  /** Written as each section's max_age_seconds; the native check caps it at 60 anyway. */
37
59
  export declare const MERGE_SECTION_MAX_AGE_SECONDS = 60;
38
60
  /**
@@ -79,7 +101,8 @@ export interface MergeApprovalSession {
79
101
  company_slug: string;
80
102
  link_id: string;
81
103
  queue_status: MergeQueueStatus;
82
- decisions: MergeDecision[];
104
+ /** Always empty: the owner-approval gate reads the queue file itself. */
105
+ decisions: [];
83
106
  review_required: boolean;
84
107
  reviews: MergeReview[];
85
108
  }
@@ -109,11 +132,16 @@ export interface MergeSections {
109
132
  }
110
133
  /** A lanes flag for one company: its value, or null when it could not be read. */
111
134
  export type MergeFlagReader = (flag: string, company: LaneCompanyRef) => Promise<boolean | null>;
135
+ export type MergeSectionLog = (level: "info" | "warn" | "error", message: string) => void;
112
136
  export interface MergeSectionInput {
113
137
  hqRoot: string;
114
138
  /** Written as refreshed_at; take it before any file is read. */
115
139
  now: Date;
116
140
  readFlag: MergeFlagReader;
141
+ /** Optional log sink for size-guard warnings. */
142
+ log?: MergeSectionLog;
143
+ /** Test seam: override MERGE_APPROVALS_MAX_SECTION_BYTES. */
144
+ maxApprovalsSectionBytes?: number;
117
145
  }
118
146
  /**
119
147
  * Every hold record, or null when any of them is one `hq runners hold list`
@@ -134,6 +162,11 @@ export interface FoldedQueue {
134
162
  * lines (a torn last line among them) and rows without an id are skipped.
135
163
  */
136
164
  export declare function foldDecisionQueue(text: string): FoldedQueue;
165
+ /**
166
+ * Exact byte size `crates/hq-hook/src/state.rs` measures against
167
+ * `MAX_SECTION_BYTES`: section name plus compact UTF-8 JSON bytes.
168
+ */
169
+ export declare function mergeApprovalsSectionBytes(section: MergeApprovalsSection): number;
137
170
  /** The merge_approvals section, or null to leave it out of the state file. */
138
171
  export declare function buildMergeApprovalsSection(input: MergeSectionInput): Promise<MergeApprovalsSection | null>;
139
172
  /** Both sections, read at `input.now`. A builder that throws leaves its section out. */
@@ -174,6 +207,8 @@ export interface MergeSectionRefresherOptions {
174
207
  readFlag: MergeFlagReader;
175
208
  /** Called after each refresh, to rewrite the state file. */
176
209
  onRefresh?: () => void;
210
+ /** Optional log sink for size-guard warnings (deduplicated across identical ticks). */
211
+ log?: MergeSectionLog;
177
212
  intervalMs?: number;
178
213
  wallClock?: () => Date;
179
214
  /** Start the timer (default true). */