@indigoai-us/hq-cli 5.345.225 → 5.345.228

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 (164) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/dist/command-catalog.generated.d.ts +215 -0
  3. package/dist/command-catalog.generated.js +261 -0
  4. package/dist/commands/auth.d.ts +2 -2
  5. package/dist/commands/auth.js +3 -3
  6. package/dist/commands/core-delegate-w1b.js +92 -69
  7. package/dist/commands/core-delegate.d.ts +19 -1
  8. package/dist/commands/core-delegate.js +411 -6
  9. package/dist/commands/core-dm-bind-native.js +2 -1
  10. package/dist/commands/core-handoff.d.ts +5 -0
  11. package/dist/commands/core-handoff.js +1008 -14
  12. package/dist/commands/core-pin-native.d.ts +1 -0
  13. package/dist/commands/core-pin-native.js +3 -15
  14. package/dist/commands/core-register-project-native.d.ts +6 -0
  15. package/dist/commands/core-register-project-native.js +182 -52
  16. package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
  17. package/dist/commands/daemon.js +3 -3
  18. package/dist/commands/deploy-domains.js +38 -2
  19. package/dist/commands/index-cmd.d.ts +3 -1
  20. package/dist/commands/index-cmd.js +12 -0
  21. package/dist/commands/lanes-accounts.d.ts +14 -0
  22. package/dist/commands/lanes-accounts.js +119 -0
  23. package/dist/commands/lanes-checks.js +1 -1
  24. package/dist/commands/lanes-move.js +10 -0
  25. package/dist/commands/lanes-session-start.d.ts +1 -2
  26. package/dist/commands/lanes-session-start.js +9 -145
  27. package/dist/commands/lanes-shared.d.ts +3 -0
  28. package/dist/commands/lanes-shared.js +9 -0
  29. package/dist/commands/lanes.d.ts +3 -0
  30. package/dist/commands/lanes.js +231 -39
  31. package/dist/commands/link.d.ts +8 -3
  32. package/dist/commands/link.js +14 -17
  33. package/dist/commands/mcp-registration.d.ts +65 -7
  34. package/dist/commands/mcp-registration.js +289 -51
  35. package/dist/commands/mesh.d.ts +12 -0
  36. package/dist/commands/mesh.js +92 -10
  37. package/dist/commands/reindex.js +6 -0
  38. package/dist/commands/repo.d.ts +13 -0
  39. package/dist/commands/repo.js +39 -1
  40. package/dist/commands/sync-held.d.ts +22 -0
  41. package/dist/commands/sync-held.js +167 -18
  42. package/dist/commands/sync-mode.d.ts +3 -1
  43. package/dist/commands/sync-mode.js +11 -1
  44. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
  45. package/dist/hq-cloud-sync-runner/package.json +1 -1
  46. package/dist/lazy-commands.js +3 -4
  47. package/dist/lib/capacity/accounts.d.ts +4 -0
  48. package/dist/lib/capacity/accounts.js +4 -0
  49. package/dist/lib/capacity/route.js +14 -0
  50. package/dist/lib/capacity/sign-in.d.ts +18 -0
  51. package/dist/lib/capacity/sign-in.js +34 -1
  52. package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
  53. package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
  54. package/dist/lib/checkpoint-ontology/plan.js +2 -1
  55. package/dist/lib/core-utils/archive-old-threads.js +5 -2
  56. package/dist/lib/core-utils/session-company.d.ts +13 -1
  57. package/dist/lib/core-utils/session-company.js +75 -4
  58. package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
  59. package/dist/lib/core-utils/worktree-resume.js +8 -4
  60. package/dist/lib/daemon/background-qos.d.ts +7 -0
  61. package/dist/lib/daemon/background-qos.js +13 -0
  62. package/dist/lib/daemon/catalog.d.ts +10 -0
  63. package/dist/lib/daemon/catalog.js +9 -2
  64. package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
  65. package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
  66. package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
  67. package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
  68. package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
  69. package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
  70. package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
  71. package/dist/lib/daemon/hook-requests-mesh.js +559 -0
  72. package/dist/lib/daemon/hook-requests.d.ts +417 -0
  73. package/dist/lib/daemon/hook-requests.js +1747 -0
  74. package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
  75. package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
  76. package/dist/lib/daemon/machine-checks.d.ts +12 -2
  77. package/dist/lib/daemon/machine-checks.js +27 -10
  78. package/dist/lib/daemon/merge-sections.d.ts +24 -2
  79. package/dist/lib/daemon/merge-sections.js +58 -16
  80. package/dist/lib/daemon/ops/policy.d.ts +1 -1
  81. package/dist/lib/daemon/ops/policy.js +47 -6
  82. package/dist/lib/daemon/resolver.js +9 -2
  83. package/dist/lib/daemon/run.d.ts +11 -7
  84. package/dist/lib/daemon/run.js +195 -18
  85. package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
  86. package/dist/lib/daemon/search-index-worker-v1.js +25 -0
  87. package/dist/lib/daemon/server.js +6 -1
  88. package/dist/lib/daemon/session-registry.d.ts +0 -1
  89. package/dist/lib/daemon/session-registry.js +0 -3
  90. package/dist/lib/daemon/supervisor.d.ts +5 -1
  91. package/dist/lib/daemon/supervisor.js +1 -1
  92. package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
  93. package/dist/lib/daemon/tcc-eperm.js +110 -8
  94. package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
  95. package/dist/lib/doctor/fix/process-identity.js +48 -5
  96. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  97. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  98. package/dist/lib/hook-engine/canary-gate.js +1 -0
  99. package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
  100. package/dist/lib/hot-channels/adapters/attio.js +2 -1
  101. package/dist/lib/hot-channels/adapters/meetings.js +2 -1
  102. package/dist/lib/lanes/account-company.d.ts +7 -1
  103. package/dist/lib/lanes/account-company.js +22 -4
  104. package/dist/lib/lanes/account-ownership.d.ts +65 -0
  105. package/dist/lib/lanes/account-ownership.js +134 -0
  106. package/dist/lib/lanes/accounts.js +9 -2
  107. package/dist/lib/lanes/claude-balance.js +9 -3
  108. package/dist/lib/lanes/company-outposts.d.ts +37 -0
  109. package/dist/lib/lanes/company-outposts.js +164 -0
  110. package/dist/lib/lanes/config.js +17 -0
  111. package/dist/lib/lanes/host-capacity.d.ts +19 -0
  112. package/dist/lib/lanes/host-capacity.js +37 -0
  113. package/dist/lib/lanes/liveness.d.ts +6 -0
  114. package/dist/lib/lanes/liveness.js +49 -8
  115. package/dist/lib/lanes/orphan-report.d.ts +15 -0
  116. package/dist/lib/lanes/orphan-report.js +223 -0
  117. package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
  118. package/dist/lib/lanes/orphan-sweep.js +152 -0
  119. package/dist/lib/lanes/reaper.d.ts +2 -0
  120. package/dist/lib/lanes/reaper.js +11 -8
  121. package/dist/lib/lanes/reconcile.d.ts +8 -7
  122. package/dist/lib/lanes/reconcile.js +83 -3
  123. package/dist/lib/lanes/spawn.d.ts +0 -10
  124. package/dist/lib/lanes/spawn.js +51 -1
  125. package/dist/lib/lanes/types.d.ts +12 -0
  126. package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
  127. package/dist/lib/mesh/live/backfill-held.js +23 -0
  128. package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
  129. package/dist/lib/mesh/live/daemon/mode.js +8 -4
  130. package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
  131. package/dist/lib/mesh/live/daemon/run.js +116 -7
  132. package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
  133. package/dist/lib/mesh/live/direct-drain.js +315 -0
  134. package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
  135. package/dist/lib/mesh/live/emit-replay.js +10 -0
  136. package/dist/lib/mesh/live/flush.d.ts +15 -0
  137. package/dist/lib/mesh/live/flush.js +27 -0
  138. package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
  139. package/dist/lib/mesh/live/liveness-carry.js +141 -0
  140. package/dist/lib/mesh/live/spool.d.ts +19 -0
  141. package/dist/lib/mesh/live/spool.js +80 -0
  142. package/dist/lib/safe-store.d.ts +2 -0
  143. package/dist/lib/safe-store.js +8 -6
  144. package/dist/lib/search-index/index.d.ts +9 -3
  145. package/dist/lib/search-index/index.js +35 -10
  146. package/dist/lib/search-index/worker-process.d.ts +9 -0
  147. package/dist/lib/search-index/worker-process.js +171 -0
  148. package/dist/lib/session-company-lock.d.ts +3 -1
  149. package/dist/lib/session-company-lock.js +3 -2
  150. package/dist/utils/delegate-command-supervisor.d.ts +3 -0
  151. package/dist/utils/delegate-command-supervisor.js +44 -0
  152. package/dist/utils/delegate-lock.d.ts +12 -0
  153. package/dist/utils/delegate-lock.js +88 -0
  154. package/dist/utils/frontmatter.d.ts +27 -0
  155. package/dist/utils/frontmatter.js +33 -0
  156. package/dist/utils/hook-trust.d.ts +1 -0
  157. package/dist/utils/hook-trust.js +18 -2
  158. package/dist/utils/host-registration.d.ts +13 -1
  159. package/dist/utils/host-registration.js +98 -5
  160. package/dist/utils/package-use-lease.d.ts +1 -1
  161. package/dist/utils/package-use-lease.js +15 -7
  162. package/docs/anywhere-runtime.md +17 -0
  163. package/package.json +9 -8
  164. package/scripts/check-function-manifest.mjs +17 -3
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The status line of the in-process lanes reconcile.
3
+ *
4
+ * While the lane-store watcher owns reconcile the catalog plans no
5
+ * `lanes-reconcile` unit, so the supervisor has no state for it. This records
6
+ * the outcome of each watcher run and adds one unit entry to the state file
7
+ * `hq daemon status` reads.
8
+ */
9
+ import type { DaemonState } from "./supervisor.js";
10
+ type Unit = DaemonState["units"][number];
11
+ /** The longest `lastError` written to the state file, in UTF-8 bytes. */
12
+ export declare const LANES_RECONCILE_ERROR_BYTES = 300;
13
+ /** One line, no secrets, no control characters (it is printed to a terminal), at most LANES_RECONCILE_ERROR_BYTES. */
14
+ export declare function lanesReconcileErrorText(error: unknown): string;
15
+ export interface LanesReconcileStatus {
16
+ /** The same reconcile, with its outcome recorded. A failure is rethrown. */
17
+ track(reconcile: () => Promise<void>): () => Promise<void>;
18
+ /** Forget the recorded outcome (the watcher was closed or replaced). */
19
+ reset(): void;
20
+ /** The unit entry for the state file. */
21
+ unit(signedIn: boolean): Unit;
22
+ }
23
+ export declare function createLanesReconcileStatus(options?: {
24
+ now?: () => number;
25
+ /** Called after each run has been recorded. */
26
+ onChange?: () => void;
27
+ }): LanesReconcileStatus;
28
+ /**
29
+ * `state` with the in-process reconcile's unit, placed where the timed unit
30
+ * would be in `services` order. A planned `lanes-reconcile` unit (the timed
31
+ * fallback) is left alone.
32
+ */
33
+ export declare function withLanesReconcileUnit(state: DaemonState, unit: Unit | null, services: readonly string[]): DaemonState;
34
+ export {};
35
+ //# sourceMappingURL=lanes-reconcile-status.d.ts.map
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The status line of the in-process lanes reconcile.
3
+ *
4
+ * While the lane-store watcher owns reconcile the catalog plans no
5
+ * `lanes-reconcile` unit, so the supervisor has no state for it. This records
6
+ * the outcome of each watcher run and adds one unit entry to the state file
7
+ * `hq daemon status` reads.
8
+ */
9
+ import { redactForLog } from "../bot/log.js";
10
+ import { redactSecrets } from "../db/redact.js";
11
+ import { NOT_SIGNED_IN, SERVICE_DESCRIPTIONS } from "./catalog.js";
12
+ import { cutUtf8 } from "./state-file.js";
13
+ /** The longest `lastError` written to the state file, in UTF-8 bytes. */
14
+ export const LANES_RECONCILE_ERROR_BYTES = 300;
15
+ const UNIT_ID = "lanes-reconcile";
16
+ /** One line, no secrets, no control characters (it is printed to a terminal), at most LANES_RECONCILE_ERROR_BYTES. */
17
+ export function lanesReconcileErrorText(error) {
18
+ const raw = error instanceof Error ? error.message : String(error);
19
+ const oneLine = redactSecrets(redactForLog(raw)).replace(/\p{Cc}+/gu, " ").replace(/\s+/g, " ").trim();
20
+ return cutUtf8(oneLine, LANES_RECONCILE_ERROR_BYTES);
21
+ }
22
+ export function createLanesReconcileStatus(options = {}) {
23
+ const now = options.now ?? Date.now;
24
+ let lastRunAt;
25
+ let lastResult;
26
+ let lastError;
27
+ return {
28
+ track: (reconcile) => async () => {
29
+ lastRunAt = now();
30
+ try {
31
+ await reconcile();
32
+ lastResult = "ok";
33
+ lastError = undefined;
34
+ }
35
+ catch (error) {
36
+ lastResult = "failed";
37
+ lastError = lanesReconcileErrorText(error);
38
+ throw error;
39
+ }
40
+ finally {
41
+ try {
42
+ options.onChange?.();
43
+ }
44
+ catch {
45
+ // Reporting never changes the reconcile outcome.
46
+ }
47
+ }
48
+ },
49
+ reset: () => {
50
+ lastRunAt = undefined;
51
+ lastResult = undefined;
52
+ lastError = undefined;
53
+ },
54
+ unit: (signedIn) => {
55
+ const failed = lastResult === "failed";
56
+ const waiting = failed && !signedIn;
57
+ return {
58
+ id: UNIT_ID,
59
+ service: UNIT_ID,
60
+ kind: "scheduled",
61
+ description: SERVICE_DESCRIPTIONS[UNIT_ID],
62
+ status: waiting ? "waiting" : "idle",
63
+ ...(waiting ? { reason: NOT_SIGNED_IN } : {}),
64
+ restarts: 0,
65
+ ...(lastRunAt !== undefined ? { lastRunAt } : {}),
66
+ ...(lastResult ? { lastResult } : {}),
67
+ ...(failed && lastError !== undefined ? { lastError } : {}),
68
+ };
69
+ },
70
+ };
71
+ }
72
+ /**
73
+ * `state` with the in-process reconcile's unit, placed where the timed unit
74
+ * would be in `services` order. A planned `lanes-reconcile` unit (the timed
75
+ * fallback) is left alone.
76
+ */
77
+ export function withLanesReconcileUnit(state, unit, services) {
78
+ if (!unit || state.units.some((u) => u.id === unit.id))
79
+ return state;
80
+ const position = services.indexOf(unit.service);
81
+ const at = position < 0 ? -1 : state.units.findIndex((u) => services.indexOf(u.service) > position);
82
+ const units = [...state.units];
83
+ units.splice(at < 0 ? units.length : at, 0, unit);
84
+ return { ...state, units };
85
+ }
86
+ //# sourceMappingURL=lanes-reconcile-status.js.map
@@ -76,6 +76,14 @@ export interface RunMachineChecksOptions {
76
76
  /** Write the results here (through the store rules) after the batch. */
77
77
  resultsFile?: string;
78
78
  resultsWrite?: StoreFileWriteOptions;
79
+ /**
80
+ * One check run for a daemon request note, not a batch. It answers from a
81
+ * batch already running, but it never takes the in-flight slot: a batch
82
+ * started meanwhile is not handed its answer, runs every check and writes
83
+ * its results file. The batch waits for it first, so scripts still run one
84
+ * at a time.
85
+ */
86
+ single?: boolean;
79
87
  /** Test seams. */
80
88
  checks?: readonly MachineCheckSpec[];
81
89
  killGraceMs?: number;
@@ -126,8 +134,10 @@ export declare const MACHINE_CHECK_COLLECT_ONLY_KEY = "machineCheckCollectOnly";
126
134
  export declare function machineCheckCollectOnlySupported(hqRoot: string): boolean;
127
135
  /**
128
136
  * Run every machine check once, one at a time. A call while a batch is
129
- * running returns that batch. Inside a machine check
130
- * (HQ_MACHINE_CHECKS_RUNNING=1) nothing runs and the answer is empty.
137
+ * running returns that batch. A single run does not take that slot; a run
138
+ * that starts while one is going waits for it, then runs its own checks.
139
+ * Inside a machine check (HQ_MACHINE_CHECKS_RUNNING=1) nothing runs and the
140
+ * answer is empty.
131
141
  */
132
142
  export declare function runMachineChecks(options: RunMachineChecksOptions): Promise<MachineCheckResult[]>;
133
143
  /** Written atomically through src/lib/safe-store.ts in the daemon's private folder. */
@@ -312,10 +312,14 @@ async function runOne(spec, options, env, disabled, shell) {
312
312
  return resultFromStdout(spec.id, run.stdout, at());
313
313
  }
314
314
  let inFlight;
315
+ /** The last single run (options.single) still going. It never answers a batch. */
316
+ let singleTail;
315
317
  /**
316
318
  * Run every machine check once, one at a time. A call while a batch is
317
- * running returns that batch. Inside a machine check
318
- * (HQ_MACHINE_CHECKS_RUNNING=1) nothing runs and the answer is empty.
319
+ * running returns that batch. A single run does not take that slot; a run
320
+ * that starts while one is going waits for it, then runs its own checks.
321
+ * Inside a machine check (HQ_MACHINE_CHECKS_RUNNING=1) nothing runs and the
322
+ * answer is empty.
319
323
  */
320
324
  export function runMachineChecks(options) {
321
325
  const env = options.env ?? process.env;
@@ -323,7 +327,10 @@ export function runMachineChecks(options) {
323
327
  return Promise.resolve([]);
324
328
  if (inFlight)
325
329
  return inFlight;
326
- const batch = (async () => {
330
+ const before = singleTail;
331
+ const run = (async () => {
332
+ if (before)
333
+ await before.then(() => undefined, () => undefined);
327
334
  const disabled = disabledIds(env);
328
335
  const shell = machineCheckShell(options.platform ?? process.platform, env, options.resolveBash);
329
336
  const results = [];
@@ -334,13 +341,23 @@ export function runMachineChecks(options) {
334
341
  writeMachineCheckResults(options.resultsFile, results, options.resultsWrite);
335
342
  return results;
336
343
  })();
337
- inFlight = batch;
338
- const clear = () => {
339
- if (inFlight === batch)
340
- inFlight = undefined;
341
- };
342
- batch.then(clear, clear);
343
- return batch;
344
+ if (options.single === true) {
345
+ singleTail = run;
346
+ const clear = () => {
347
+ if (singleTail === run)
348
+ singleTail = undefined;
349
+ };
350
+ run.then(clear, clear);
351
+ }
352
+ else {
353
+ inFlight = run;
354
+ const clear = () => {
355
+ if (inFlight === run)
356
+ inFlight = undefined;
357
+ };
358
+ run.then(clear, clear);
359
+ }
360
+ return run;
344
361
  }
345
362
  /** Written atomically through src/lib/safe-store.ts in the daemon's private folder. */
346
363
  export function writeMachineCheckResults(file, results, options = {}) {
@@ -83,10 +83,24 @@ export interface MergeApprovalSession {
83
83
  review_required: boolean;
84
84
  reviews: MergeReview[];
85
85
  }
86
+ /** `lanes.review-before-merge` for one company, as the registry holds it. */
87
+ export interface MergeReviewFlag {
88
+ slug: string;
89
+ enabled: boolean;
90
+ }
86
91
  export interface MergeApprovalsSection {
87
92
  schema: typeof MERGE_APPROVALS_SCHEMA;
88
93
  refreshed_at: string;
89
94
  max_age_seconds: number;
95
+ /**
96
+ * By company uid, for every company a lane record resolves to. The native
97
+ * review check reads the lane and review records itself and takes only
98
+ * this flag from here. A company whose flag could not be read, or whose
99
+ * uid appears under two slugs, has no entry, and the native check refuses.
100
+ * The value is read as review_required is, with the daemon's own
101
+ * HQ_FLAG_LANES_REVIEW_BEFORE_MERGE kept.
102
+ */
103
+ review_flags: Record<string, MergeReviewFlag>;
90
104
  sessions: Record<string, MergeApprovalSession>;
91
105
  }
92
106
  export interface MergeSections {
@@ -133,11 +147,19 @@ export interface RegistryMergeFlagReaderOptions {
133
147
  read?: (flag: string, company: LaneCompanyRef, env: NodeJS.ProcessEnv) => Promise<boolean | null>;
134
148
  }
135
149
  /**
136
- * Lanes flags as `hq lanes hold check` reads them (readLanesRegistryFlag: local
137
- * override, then the registry, then its last-known-good cache on a transient
150
+ * Lanes flags as the registry holds them (readLanesRegistryFlag without the
151
+ * local override: the registry, then its last-known-good cache on a transient
138
152
  * failure), asked again after `ttlMs`. A read that fails, throws or takes
139
153
  * longer than `timeoutMs` is null and is not kept.
140
154
  */
155
+ /**
156
+ * The environment the hold flag is read under: the daemon's own, without
157
+ * the flag's local override (`HQ_FLAG_<KEY>`). The sections are read by the
158
+ * native merge gates of every session; each session applies its own override
159
+ * in process, as its `hq lanes hold check` would. An override set only in the
160
+ * daemon's environment must not be written as every company's registry value.
161
+ */
162
+ export declare function withoutLocalOverride(flag: string, env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
141
163
  export declare function createRegistryMergeFlagReader(options: RegistryMergeFlagReaderOptions): MergeFlagReader;
142
164
  export interface MergeSectionRefresher {
143
165
  /** The latest sections, each only while younger than its max age. */
@@ -29,6 +29,7 @@
29
29
  * review records, which are read with their stores' own validating readers.
30
30
  * Nothing here starts a process; the flags are read from the flag registry.
31
31
  */
32
+ import { localOverrideEnvVar } from "@indigoai-us/hq-flags-client";
32
33
  import * as fs from "node:fs";
33
34
  import * as path from "node:path";
34
35
  import { openStoreDir } from "../safe-store.js";
@@ -306,12 +307,9 @@ async function laneSessions(hqRoot, readFlag) {
306
307
  if (lane.senior.kind === "lane" && lane.senior.id)
307
308
  seniors.add(lane.senior.id);
308
309
  const live = [];
310
+ const companyKey = (company) => JSON.stringify([company.uid, company.slug]);
311
+ const byKey = new Map();
309
312
  for (const lane of lanes) {
310
- if (TERMINAL_STATES.has(lane.state))
311
- continue;
312
- const sessions = laneSessionIds(lane);
313
- if (sessions.length === 0)
314
- continue;
315
313
  let company;
316
314
  try {
317
315
  company = resolveLaneCompany(hqRoot, lane).company;
@@ -319,17 +317,37 @@ async function laneSessions(hqRoot, readFlag) {
319
317
  catch {
320
318
  company = null;
321
319
  }
320
+ // Every lane's company, whatever the lane's state: the native review
321
+ // check finds its caller by HQ_LANE_ID, not by a session listed here.
322
+ if (company)
323
+ byKey.set(companyKey(company), company);
324
+ if (TERMINAL_STATES.has(lane.state))
325
+ continue;
326
+ const sessions = laneSessionIds(lane);
327
+ if (sessions.length === 0)
328
+ continue;
322
329
  live.push({ lane, sessions, company });
323
330
  }
324
331
  // One read per company, all at once, so a slow registry costs one timeout.
325
- const companyKey = (company) => JSON.stringify([company.uid, company.slug]);
326
- const byKey = new Map();
327
- for (const { company } of live)
328
- if (company)
329
- byKey.set(companyKey(company), company);
330
332
  const keys = [...byKey.keys()];
331
333
  const values = await Promise.all(keys.map((key) => readFlag(LANES_REVIEW_BEFORE_MERGE_FLAG, byKey.get(key))));
332
334
  const flags = new Map(keys.map((key, index) => [key, values[index]]));
335
+ const reviewFlags = {};
336
+ const twoSlugs = new Set();
337
+ for (const key of keys.sort()) {
338
+ const company = byKey.get(key);
339
+ const enabled = flags.get(key);
340
+ const listed = reviewFlags[company.uid];
341
+ if (twoSlugs.has(company.uid) || (listed && listed.slug !== company.slug)) {
342
+ // One uid under two slugs cannot be matched to a lane's company.
343
+ twoSlugs.add(company.uid);
344
+ delete reviewFlags[company.uid];
345
+ continue;
346
+ }
347
+ // Never `enabled: false` for a flag that could not be read.
348
+ if (typeof enabled === "boolean")
349
+ reviewFlags[company.uid] = { slug: company.slug, enabled };
350
+ }
333
351
  for (const { lane, sessions, company } of live) {
334
352
  let review = "off";
335
353
  if (company) {
@@ -347,7 +365,7 @@ async function laneSessions(hqRoot, readFlag) {
347
365
  }
348
366
  }
349
367
  }
350
- return out;
368
+ return { sessions: out, reviewFlags };
351
369
  }
352
370
  /** The merge_approvals section, or null to leave it out of the state file. */
353
371
  export async function buildMergeApprovalsSection(input) {
@@ -370,9 +388,10 @@ export async function buildMergeApprovalsSection(input) {
370
388
  links.set(sid, queue);
371
389
  }
372
390
  }
373
- const lanes = await laneSessions(hqRoot, input.readFlag);
374
- if (!lanes)
391
+ const laneFacts = await laneSessions(hqRoot, input.readFlag);
392
+ if (!laneFacts)
375
393
  return null;
394
+ const lanes = laneFacts.sessions;
376
395
  let reviews;
377
396
  const allReviews = () => {
378
397
  reviews ??= listLaneReviews(hqRoot).reviews
@@ -421,6 +440,7 @@ export async function buildMergeApprovalsSection(input) {
421
440
  schema: MERGE_APPROVALS_SCHEMA,
422
441
  refreshed_at: input.now.toISOString(),
423
442
  max_age_seconds: MERGE_SECTION_MAX_AGE_SECONDS,
443
+ review_flags: laneFacts.reviewFlags,
424
444
  sessions,
425
445
  };
426
446
  }
@@ -449,11 +469,26 @@ async function registryRead(flag, company, env) {
449
469
  return result.state === "resolved" ? result.value : null;
450
470
  }
451
471
  /**
452
- * Lanes flags as `hq lanes hold check` reads them (readLanesRegistryFlag: local
453
- * override, then the registry, then its last-known-good cache on a transient
472
+ * Lanes flags as the registry holds them (readLanesRegistryFlag without the
473
+ * local override: the registry, then its last-known-good cache on a transient
454
474
  * failure), asked again after `ttlMs`. A read that fails, throws or takes
455
475
  * longer than `timeoutMs` is null and is not kept.
456
476
  */
477
+ /**
478
+ * The environment the hold flag is read under: the daemon's own, without
479
+ * the flag's local override (`HQ_FLAG_<KEY>`). The sections are read by the
480
+ * native merge gates of every session; each session applies its own override
481
+ * in process, as its `hq lanes hold check` would. An override set only in the
482
+ * daemon's environment must not be written as every company's registry value.
483
+ */
484
+ export function withoutLocalOverride(flag, env) {
485
+ const name = localOverrideEnvVar(flag);
486
+ if (!(name in env))
487
+ return env;
488
+ const rest = { ...env };
489
+ delete rest[name];
490
+ return rest;
491
+ }
457
492
  export function createRegistryMergeFlagReader(options) {
458
493
  const ttlMs = options.ttlMs ?? MERGE_FLAG_TTL_MS;
459
494
  const timeoutMs = options.timeoutMs ?? MERGE_FLAG_READ_TIMEOUT_MS;
@@ -473,7 +508,14 @@ export function createRegistryMergeFlagReader(options) {
473
508
  });
474
509
  let value;
475
510
  try {
476
- value = await Promise.race([read(flag, company, options.env), timeout]);
511
+ // Only the hold flag: the native hold check applies the session's own
512
+ // override in process. The review-before-merge flag keeps the daemon's
513
+ // override: the row-based review gate (review_required) is still
514
+ // decided from this section, and the record-file review gate, which
515
+ // runs beside it, reads the same value from review_flags. Dropping the
516
+ // override here would let the row gate allow merges it refuses today.
517
+ const readEnv = flag === LANES_REPO_MERGE_HOLD_FLAG ? withoutLocalOverride(flag, options.env) : options.env;
518
+ value = await Promise.race([read(flag, company, readEnv), timeout]);
477
519
  }
478
520
  catch {
479
521
  value = null;
@@ -21,7 +21,7 @@ export declare const SCOPE_AUTHORIZER = ".claude/hooks/mandatory-scope-authorize
21
21
  export declare const POLICY_TRIGGER = ".claude/hooks/inject-policy-on-trigger.sh";
22
22
  export declare class PolicyOpError extends Error {
23
23
  readonly code: string;
24
- constructor(code: string, message: string);
24
+ constructor(code: string, message: string, options?: ErrorOptions);
25
25
  }
26
26
  export interface PolicyEntry {
27
27
  slug: string;
@@ -20,7 +20,7 @@
20
20
  import { spawn } from "node:child_process";
21
21
  import * as fs from "node:fs";
22
22
  import * as path from "node:path";
23
- import { sessionMetaCompanies } from "../../core-utils/session-company.js";
23
+ import { isPendingManifestCompany, sessionMetaCompanies } from "../../core-utils/session-company.js";
24
24
  import { withoutHookEnv } from "../hook-env.js";
25
25
  export const SCOPE_AUTHORIZER = ".claude/hooks/mandatory-scope-authorizer.sh";
26
26
  export const POLICY_TRIGGER = ".claude/hooks/inject-policy-on-trigger.sh";
@@ -28,8 +28,8 @@ const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
28
28
  const SESSION_RE = /^[A-Za-z0-9._-]+$/;
29
29
  export class PolicyOpError extends Error {
30
30
  code;
31
- constructor(code, message) {
32
- super(message);
31
+ constructor(code, message, options) {
32
+ super(message, options);
33
33
  this.code = code;
34
34
  this.name = "PolicyOpError";
35
35
  }
@@ -308,16 +308,57 @@ function blockFromJson(stdout) {
308
308
  }
309
309
  return null;
310
310
  }
311
+ /**
312
+ * EPERM from the HQ root: on macOS, hqd runs under launchd and has no privacy
313
+ * consent for ~/Documents, ~/Desktop or iCloud Drive, so it cannot open the
314
+ * session files there although the user's own session can. Report it under its
315
+ * own code so the hook shim runs the scope check in the hook process (which has
316
+ * the host app's consent) instead of failing closed on a raw "internal" error.
317
+ */
318
+ function hqRootUnreadable(err, hqRoot) {
319
+ if (err?.code !== "EPERM")
320
+ return null;
321
+ return new PolicyOpError("hq_root_unreadable", `hqd cannot read the HQ folder at ${hqRoot} (operation not permitted). On macOS, grant Full Disk Access to the node binary hqd runs, or keep HQ outside Documents, Desktop and iCloud Drive.`,
322
+ // Keep the fs error as the cause: hqd's TCC EPERM guard (tcc-eperm.ts)
323
+ // follows `cause` to count EPERM reads under the HQ root. Only code and
324
+ // message go over the socket, so the cause is never sent to the caller.
325
+ { cause: err });
326
+ }
327
+ /** True when `file` exists. ENOENT/ENOTDIR are "no"; any other error (EPERM) is thrown. */
328
+ function fileExists(file) {
329
+ try {
330
+ fs.statSync(file);
331
+ return true;
332
+ }
333
+ catch (err) {
334
+ const code = err.code;
335
+ if (code === "ENOENT" || code === "ENOTDIR")
336
+ return false;
337
+ throw err;
338
+ }
339
+ }
311
340
  export async function policyCheck(args, deps) {
341
+ // Every step reads the HQ root (session files, hook scripts, the policy
342
+ // index, the scripts' cwd), so EPERM from any of them means the same thing.
343
+ try {
344
+ return await policyCheckUnmapped(args, deps);
345
+ }
346
+ catch (err) {
347
+ throw hqRootUnreadable(err, deps.hqRoot) ?? err;
348
+ }
349
+ }
350
+ async function policyCheckUnmapped(args, deps) {
312
351
  const { hqRoot } = deps;
313
352
  if (args.company !== undefined && !SLUG_RE.test(args.company))
314
353
  throw new PolicyOpError("bad_args", "company must be a company slug");
315
- if (args.company !== undefined && !isDir(path.join(hqRoot, "companies", args.company))) {
354
+ if (args.company !== undefined
355
+ && !isDir(path.join(hqRoot, "companies", args.company))
356
+ && !isPendingManifestCompany(hqRoot, args.company)) {
316
357
  throw new PolicyOpError("unknown_company", `no companies/${args.company} under ${hqRoot}`);
317
358
  }
318
359
  const authorizer = path.join(hqRoot, SCOPE_AUTHORIZER);
319
360
  const trigger = path.join(hqRoot, POLICY_TRIGGER);
320
- if (!fs.existsSync(authorizer)) {
361
+ if (!fileExists(authorizer)) {
321
362
  throw new PolicyOpError("policy_engine_unavailable", `scope authorizer not found at ${authorizer}`);
322
363
  }
323
364
  const event = args.event ?? "PreToolUse";
@@ -362,7 +403,7 @@ export async function policyCheck(args, deps) {
362
403
  }
363
404
  }
364
405
  let additionalContext = "";
365
- if (fs.existsSync(trigger)) {
406
+ if (fileExists(trigger)) {
366
407
  const r = await runScript(trigger, payload, env, hqRoot, timeoutMs);
367
408
  if (r.code === 0 && !r.timedOut)
368
409
  additionalContext = extractContext(r.stdout);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import * as fs from "node:fs";
6
6
  import * as path from "node:path";
7
- import { canonicalDir, emptyRegistry, readRegistry, resolveCompanyForDir } from "../registry/registry.js";
7
+ import { canonicalDir, companyFromHqLayout, emptyRegistry, readRegistry, resolveCompanyForDir, } from "../registry/registry.js";
8
8
  import { readCompaniesManifestMap } from "../work-context/repo-remote.js";
9
9
  /** Resolve cwd → company through the registry, cached until registry.json changes. */
10
10
  export function createResolver(registryPath, options = {}) {
@@ -55,8 +55,15 @@ export function createResolver(registryPath, options = {}) {
55
55
  return { company: null, reason: "HQ registry is unavailable; using personal context." };
56
56
  }
57
57
  const key = canonicalDir(cwd);
58
- const result = cache.get(key) ?? resolveCompanyForDir(registry, key);
58
+ let result = cache.get(key) ?? resolveCompanyForDir(registry, key);
59
59
  cache.set(key, result);
60
+ // With no registry hit, HQ's own companies/<slug> layout answers (#2823).
61
+ // Only the caller's HQ root counts, and the manifest check below still
62
+ // applies. Not cached: the cache is keyed to registry.json alone, and a
63
+ // company folder or manifest row can change without it.
64
+ if (!result.company && options.hqRoot) {
65
+ result = companyFromHqLayout(key, options.hqRoot) ?? result;
66
+ }
60
67
  if (result.company && options.hqRoot) {
61
68
  const manifestPath = path.join(options.hqRoot, "companies", "manifest.yaml");
62
69
  let currentManifestStamp;
@@ -5,6 +5,7 @@
5
5
  * legacy units, the desktop app), so enabling a service, creating a bot, or
6
6
  * signing in takes effect without restarting the daemon.
7
7
  */
8
+ import { acquirePackageUseLease } from "../../utils/package-use-lease.js";
8
9
  import { type LegacySyncHolder, type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
9
10
  import { type SyncCoreVaultPlan } from "../sync-core/engine-home.js";
10
11
  import { type LegacyUnit, type WindowsTaskOwner } from "./legacy.js";
@@ -89,12 +90,16 @@ export declare function syncRunnerSourceForPlan(stagedRunnerPath: string | null,
89
90
  }, currentSyncRunnerSource?: SyncRunnerSource | null): SyncRunnerSource;
90
91
  /** Whether every executable in the first service plan remains usable after the CLI package is replaced. */
91
92
  export declare function daemonPlanCanReleasePackageUseLease(plans: readonly UnitPlan[], replaceablePackageRoots: readonly string[], stagingFailed: boolean, hqBootstrapReady?: boolean): boolean;
92
- /**
93
- * Prefix a unit's command with `taskpolicy -b` on macOS. taskpolicy execs the
94
- * command in place, so the pid the supervisor tracks is the unit itself, and
95
- * PRIO_DARWIN_BG is inherited by everything the unit spawns (qmd included).
96
- */
97
- export declare function backgroundQosCommand(command: [string, string[]], backgroundQos: boolean, platform?: NodeJS.Platform | string, exists?: (file: string) => boolean): [string, string[]];
93
+ /** Keep the installed search-index entry and its qmd files stable for one pass. */
94
+ export declare function withSearchIndexPackageLease(releasedPackagePrefix: string | null, run: () => Promise<boolean>, acquire?: typeof acquirePackageUseLease, stopOnExpiry?: () => void): Promise<boolean>;
95
+ export declare function runSearchIndexWorker(options: {
96
+ root: string;
97
+ backgroundQos: boolean;
98
+ env: NodeJS.ProcessEnv;
99
+ logPath: string;
100
+ signal?: AbortSignal;
101
+ }, entry?: import("url").URL): Promise<boolean>;
102
+ export { backgroundQosCommand } from "./background-qos.js";
98
103
  export declare function daemonHqChildCommand(nodeBinary: string, hqBinary: string, args: readonly string[], bootstrapPath: string | null, packagePrefix: string | null, handoffWatchEnabled?: boolean): [string, string[]];
99
104
  export declare function daemonSyncUnitIsPresent(units: readonly {
100
105
  id: string;
@@ -188,5 +193,4 @@ export declare function checkMeshUnitHome(opts: {
188
193
  repair: () => MeshUnitRepairResult;
189
194
  }): boolean;
190
195
  export declare function runDaemon(opts: RunDaemonOptions): Promise<number>;
191
- export {};
192
196
  //# sourceMappingURL=run.d.ts.map