@indigoai-us/hq-cli 5.345.226 → 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 (132) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/dist/command-catalog.generated.d.ts +137 -0
  3. package/dist/command-catalog.generated.js +164 -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 +2 -2
  18. package/dist/commands/index-cmd.d.ts +3 -1
  19. package/dist/commands/index-cmd.js +12 -0
  20. package/dist/commands/lanes-checks.js +1 -1
  21. package/dist/commands/lanes-session-start.d.ts +1 -2
  22. package/dist/commands/lanes-session-start.js +9 -145
  23. package/dist/commands/lanes-shared.d.ts +3 -0
  24. package/dist/commands/lanes.d.ts +3 -0
  25. package/dist/commands/lanes.js +94 -27
  26. package/dist/commands/link.d.ts +8 -3
  27. package/dist/commands/link.js +14 -17
  28. package/dist/commands/mcp-registration.d.ts +65 -7
  29. package/dist/commands/mcp-registration.js +289 -51
  30. package/dist/commands/mesh.d.ts +12 -0
  31. package/dist/commands/mesh.js +92 -10
  32. package/dist/commands/reindex.js +6 -0
  33. package/dist/commands/repo.d.ts +13 -0
  34. package/dist/commands/repo.js +39 -1
  35. package/dist/commands/sync-mode.d.ts +3 -1
  36. package/dist/commands/sync-mode.js +11 -1
  37. package/dist/lazy-commands.js +3 -4
  38. package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
  39. package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
  40. package/dist/lib/checkpoint-ontology/plan.js +2 -1
  41. package/dist/lib/core-utils/archive-old-threads.js +5 -2
  42. package/dist/lib/core-utils/session-company.d.ts +13 -1
  43. package/dist/lib/core-utils/session-company.js +75 -4
  44. package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
  45. package/dist/lib/core-utils/worktree-resume.js +8 -4
  46. package/dist/lib/daemon/background-qos.d.ts +7 -0
  47. package/dist/lib/daemon/background-qos.js +13 -0
  48. package/dist/lib/daemon/catalog.d.ts +9 -0
  49. package/dist/lib/daemon/catalog.js +8 -1
  50. package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
  51. package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
  52. package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
  53. package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
  54. package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
  55. package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
  56. package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
  57. package/dist/lib/daemon/hook-requests-mesh.js +559 -0
  58. package/dist/lib/daemon/hook-requests.d.ts +349 -8
  59. package/dist/lib/daemon/hook-requests.js +1312 -46
  60. package/dist/lib/daemon/machine-checks.d.ts +12 -2
  61. package/dist/lib/daemon/machine-checks.js +27 -10
  62. package/dist/lib/daemon/merge-sections.d.ts +24 -2
  63. package/dist/lib/daemon/merge-sections.js +58 -16
  64. package/dist/lib/daemon/ops/policy.js +4 -2
  65. package/dist/lib/daemon/resolver.js +9 -2
  66. package/dist/lib/daemon/run.d.ts +11 -7
  67. package/dist/lib/daemon/run.js +168 -24
  68. package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
  69. package/dist/lib/daemon/search-index-worker-v1.js +25 -0
  70. package/dist/lib/daemon/session-registry.d.ts +0 -1
  71. package/dist/lib/daemon/session-registry.js +0 -3
  72. package/dist/lib/daemon/supervisor.d.ts +3 -1
  73. package/dist/lib/daemon/supervisor.js +1 -1
  74. package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
  75. package/dist/lib/daemon/tcc-eperm.js +110 -8
  76. package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
  77. package/dist/lib/doctor/fix/process-identity.js +48 -5
  78. package/dist/lib/hook-engine/canary-gate.js +1 -0
  79. package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
  80. package/dist/lib/hot-channels/adapters/attio.js +2 -1
  81. package/dist/lib/hot-channels/adapters/meetings.js +2 -1
  82. package/dist/lib/lanes/company-outposts.d.ts +37 -0
  83. package/dist/lib/lanes/company-outposts.js +164 -0
  84. package/dist/lib/lanes/liveness.d.ts +6 -0
  85. package/dist/lib/lanes/liveness.js +49 -8
  86. package/dist/lib/lanes/orphan-report.d.ts +15 -0
  87. package/dist/lib/lanes/orphan-report.js +223 -0
  88. package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
  89. package/dist/lib/lanes/orphan-sweep.js +152 -0
  90. package/dist/lib/lanes/reaper.d.ts +2 -0
  91. package/dist/lib/lanes/reaper.js +11 -8
  92. package/dist/lib/lanes/reconcile.d.ts +8 -7
  93. package/dist/lib/lanes/reconcile.js +39 -0
  94. package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
  95. package/dist/lib/mesh/live/backfill-held.js +23 -0
  96. package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
  97. package/dist/lib/mesh/live/daemon/mode.js +8 -4
  98. package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
  99. package/dist/lib/mesh/live/daemon/run.js +116 -7
  100. package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
  101. package/dist/lib/mesh/live/direct-drain.js +315 -0
  102. package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
  103. package/dist/lib/mesh/live/emit-replay.js +10 -0
  104. package/dist/lib/mesh/live/flush.d.ts +15 -0
  105. package/dist/lib/mesh/live/flush.js +27 -0
  106. package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
  107. package/dist/lib/mesh/live/liveness-carry.js +141 -0
  108. package/dist/lib/mesh/live/spool.d.ts +19 -0
  109. package/dist/lib/mesh/live/spool.js +80 -0
  110. package/dist/lib/safe-store.d.ts +2 -0
  111. package/dist/lib/safe-store.js +8 -6
  112. package/dist/lib/search-index/index.d.ts +9 -3
  113. package/dist/lib/search-index/index.js +35 -10
  114. package/dist/lib/search-index/worker-process.d.ts +9 -0
  115. package/dist/lib/search-index/worker-process.js +171 -0
  116. package/dist/lib/session-company-lock.d.ts +3 -1
  117. package/dist/lib/session-company-lock.js +3 -2
  118. package/dist/utils/delegate-command-supervisor.d.ts +3 -0
  119. package/dist/utils/delegate-command-supervisor.js +44 -0
  120. package/dist/utils/delegate-lock.d.ts +12 -0
  121. package/dist/utils/delegate-lock.js +88 -0
  122. package/dist/utils/frontmatter.d.ts +27 -0
  123. package/dist/utils/frontmatter.js +33 -0
  124. package/dist/utils/hook-trust.d.ts +1 -0
  125. package/dist/utils/hook-trust.js +18 -2
  126. package/dist/utils/host-registration.d.ts +13 -1
  127. package/dist/utils/host-registration.js +98 -5
  128. package/dist/utils/package-use-lease.d.ts +1 -1
  129. package/dist/utils/package-use-lease.js +15 -7
  130. package/docs/anywhere-runtime.md +17 -0
  131. package/package.json +8 -7
  132. package/scripts/check-function-manifest.mjs +17 -3
@@ -0,0 +1,25 @@
1
+ import { workerData } from "node:worker_threads";
2
+ import { syncScheduledSearchIndex } from "../../commands/index-cmd.js";
3
+ import { qmdWorkerSpawn } from "../search-index/worker-process.js";
4
+ import { backgroundQosCommand } from "./background-qos.js";
5
+ const { root, backgroundQos, qmdPort, stopBuffer } = workerData;
6
+ try {
7
+ const spawnQmd = qmdWorkerSpawn(qmdPort);
8
+ const stop = new Int32Array(stopBuffer);
9
+ const waitForWriter = (milliseconds) => {
10
+ if (Atomics.wait(stop, 0, 0, milliseconds) !== "timed-out") {
11
+ throw new Error("The scheduled search index was stopped");
12
+ }
13
+ };
14
+ waitForWriter(0);
15
+ const result = syncScheduledSearchIndex(root, (command, args, options) => {
16
+ const [file, argv] = backgroundQosCommand([command, args], backgroundQos);
17
+ return spawnQmd(file, argv, options);
18
+ }, waitForWriter);
19
+ if (result.status === "updated")
20
+ console.log(`Updated search index for ${root}.`);
21
+ }
22
+ finally {
23
+ qmdPort.close();
24
+ }
25
+ //# sourceMappingURL=search-index-worker-v1.js.map
@@ -25,7 +25,6 @@ export declare class SessionRegistry {
25
25
  get(runtime: string, sessionId: string): HqdSession | null;
26
26
  close(runtime: string, sessionId: string): boolean;
27
27
  clear(): void;
28
- list(): HqdSession[];
29
28
  get size(): number;
30
29
  }
31
30
  //# sourceMappingURL=session-registry.d.ts.map
@@ -35,9 +35,6 @@ export class SessionRegistry {
35
35
  clear() {
36
36
  this.sessions.clear();
37
37
  }
38
- list() {
39
- return [...this.sessions.values()];
40
- }
41
38
  get size() {
42
39
  return this.sessions.size;
43
40
  }
@@ -84,6 +84,8 @@ export declare function lockHolderPidFromOutput(output: string | undefined): num
84
84
  export declare function heartbeatProgressBytes(event: Record<string, unknown>): number | null;
85
85
  export interface SupervisedChild {
86
86
  pid?: number;
87
+ /** A scheduled attempt that finished without starting its work. */
88
+ readonly skipped?: true;
87
89
  stdout?: {
88
90
  on(event: "data" | "end", handler: (chunk?: Buffer | string) => void): unknown;
89
91
  };
@@ -145,7 +147,7 @@ interface UnitState {
145
147
  };
146
148
  lastRunAt?: number;
147
149
  nextRunAt?: number;
148
- lastResult?: "ok" | "failed";
150
+ lastResult?: "ok" | "failed" | "skipped";
149
151
  /** Why the last run failed: one redacted, truncated line. Set for the in-process lanes reconcile. */
150
152
  lastError?: string;
151
153
  lastHeartbeatAt?: string;
@@ -872,7 +872,7 @@ export function createSupervisor(deps) {
872
872
  return;
873
873
  if (slot.plan.kind === "scheduled") {
874
874
  slot.busy = false;
875
- slot.state.lastResult = code === 0 ? "ok" : "failed";
875
+ slot.state.lastResult = child.skipped ? "skipped" : code === 0 ? "ok" : "failed";
876
876
  slot.state.status = "idle";
877
877
  if (code !== 0)
878
878
  deps.log("warn", `${slot.plan.id} run failed (code=${code ?? "null"} signal=${signal ?? "none"})`);
@@ -16,6 +16,14 @@
16
16
  * TCC_EPERM_EXIT_CODE. The daemon's LaunchAgent has KeepAlive=true, so launchd
17
17
  * starts it again (after its ThrottleInterval) whatever the exit code.
18
18
  *
19
+ * A daemon whose every op stops at the same file (policy.check opening the
20
+ * caller's session meta.yaml, for one) never shows a second path. So when the
21
+ * window holds enough hits on one path only, hqd lists the HQ root itself:
22
+ * macOS privacy refuses that with EPERM too, while one odd file (flags, an
23
+ * ACL) leaves the root readable. A refused root counts as the trip; a
24
+ * readable one does not, and is asked again at most once per
25
+ * TCC_EPERM_ROOT_CHECK_INTERVAL_MS.
26
+ *
19
27
  * It never exits for EPERM outside the HQ root, for EACCES, off macOS, while
20
28
  * the daemon is already stopping, or when no service manager would start it
21
29
  * again. A permission that stays revoked would otherwise restart the daemon
@@ -32,8 +40,13 @@ export declare const TCC_EPERM_EXIT_CODE = 74;
32
40
  export declare const TCC_EPERM_WINDOW_MS = 60000;
33
41
  /** Hits needed inside the window. */
34
42
  export declare const TCC_EPERM_MIN_EVENTS = 3;
35
- /** Distinct paths needed inside the window, so one odd file cannot trip it. */
43
+ /**
44
+ * Distinct paths needed inside the window, so one odd file cannot trip it.
45
+ * With fewer, the guard trips only if listing the HQ root is refused as well.
46
+ */
36
47
  export declare const TCC_EPERM_MIN_PATHS = 2;
48
+ /** While enough hits sit on too few paths, the guard lists the HQ root at most this often. */
49
+ export declare const TCC_EPERM_ROOT_CHECK_INTERVAL_MS = 10000;
37
50
  /** Exits allowed inside TCC_EPERM_EXIT_WINDOW_MS before the daemon stays up instead. */
38
51
  export declare const TCC_EPERM_MAX_EXITS = 3;
39
52
  export declare const TCC_EPERM_EXIT_WINDOW_MS: number;
@@ -41,7 +54,30 @@ export declare const TCC_EPERM_EXIT_WINDOW_MS: number;
41
54
  export declare const TCC_EPERM_EXITS_FILE = "tcc-eperm-exits.json";
42
55
  /** Under the daemon dir: present while hqd is up but cannot read the HQ folder. */
43
56
  export declare const FILES_ACCESS_NEEDED_MARKER = "files-access-needed.json";
44
- export declare const FILES_ACCESS_NEEDED_MESSAGE: string;
57
+ /**
58
+ * Which program macOS checks for the daemon's file access:
59
+ * - "node-direct": launchd runs the node binary itself (the LaunchAgent with
60
+ * no HQ.app launcher). macOS checks that binary; allowing HQ does not cover it.
61
+ * - "hq-app": HQ.app runs the daemon (desktop host, or the LaunchAgent still
62
+ * going through the HQ.app launcher). Allowing HQ covers it.
63
+ * - "terminal": started by hand, so the terminal app it ran from is checked.
64
+ */
65
+ export type FilesAccessLaunch = "node-direct" | "hq-app" | "terminal";
66
+ /**
67
+ * How this daemon was started, from its run options and parent pid. launchd
68
+ * is pid 1, so a managed daemon whose parent is launchd runs node directly;
69
+ * under the HQ.app launcher (--hq-launchd-task) the parent is the launcher.
70
+ */
71
+ export declare function filesAccessLaunch(opts: {
72
+ managed?: boolean;
73
+ host?: string;
74
+ ppid: number;
75
+ }): FilesAccessLaunch;
76
+ /**
77
+ * What to tell the user. With no known launch (a marker from an older
78
+ * daemon) this is the HQ-app wording the daemon always used.
79
+ */
80
+ export declare function filesAccessNeededMessage(launch?: FilesAccessLaunch, program?: string): string;
45
81
  export declare const TCC_EPERM_SENTRY_FINGERPRINT: readonly string[];
46
82
  export interface EpermHit {
47
83
  path: string;
@@ -98,7 +134,14 @@ export declare function decideEpermExit(input: EpermDecisionInput): EpermDecisio
98
134
  export declare function readEpermExits(daemonDir: string): number[];
99
135
  /** Add an exit at `now`, dropping ones older than the backoff window. */
100
136
  export declare function recordEpermExit(daemonDir: string, now: number, exitWindowMs?: number): number[];
101
- export declare function writeFilesAccessNeeded(daemonDir: string, now: number, reason: StayReason): void;
137
+ /**
138
+ * `launch`: how the daemon was started (filesAccessLaunch). `program`: the
139
+ * binary launchd runs (process.execPath in hqd); recorded only for
140
+ * "node-direct", the one case where it is the program macOS checks.
141
+ */
142
+ export declare function writeFilesAccessNeeded(daemonDir: string, now: number, reason: StayReason, launch?: FilesAccessLaunch, program?: string): void;
143
+ /** The message for the marker a running daemon wrote, from the launch and program it recorded. */
144
+ export declare function filesAccessNeededMessageFromMarker(daemonDir: string): string;
102
145
  export declare function clearFilesAccessNeeded(daemonDir: string): void;
103
146
  export declare function filesAccessNeeded(daemonDir: string): boolean;
104
147
  /** The one structured event logged and reported per trip. Holds counts only: no paths, no file contents. */
@@ -108,6 +151,8 @@ export interface TccEpermEvent {
108
151
  hits: number;
109
152
  distinctPaths: number;
110
153
  syscalls: string[];
154
+ /** Set when too few paths failed and the trip rests on the HQ root itself being refused. */
155
+ rootRefused?: true;
111
156
  windowMs: number;
112
157
  decision: EpermDecision["action"];
113
158
  reason?: string;
@@ -131,12 +176,22 @@ export interface TccEpermGuardDeps {
131
176
  window?: EpermWindowOptions;
132
177
  maxExits?: number;
133
178
  exitWindowMs?: number;
134
- /** Throws while the HQ root cannot be read. Default: list the root. */
179
+ /**
180
+ * Throws while the HQ root cannot be read. Default: list the root. Also
181
+ * confirms a window whose hits sit on too few paths: only an EPERM from it
182
+ * counts there.
183
+ */
135
184
  probe?: (hqRoot: string) => void;
185
+ /** How often that confirmation may list the root. Default: TCC_EPERM_ROOT_CHECK_INTERVAL_MS. */
186
+ rootCheckIntervalMs?: number;
136
187
  /** How often a daemon that stayed up checks whether access came back. */
137
188
  probeIntervalMs?: number;
138
189
  /** Run `fn` every `ms`; returns a cancel. Default: an unref'd setInterval. */
139
190
  schedule?: (fn: () => void, ms: number) => () => void;
191
+ /** How the daemon was started (filesAccessLaunch); picks the access message. Unset: the HQ-app wording. */
192
+ launch?: FilesAccessLaunch;
193
+ /** The binary launchd runs, named when `launch` is "node-direct". Default: process.execPath. */
194
+ program?: string;
140
195
  }
141
196
  export type TccEpermGuardState = "watching" | "exiting" | "access-needed";
142
197
  export interface TccEpermGuard {
@@ -16,6 +16,14 @@
16
16
  * TCC_EPERM_EXIT_CODE. The daemon's LaunchAgent has KeepAlive=true, so launchd
17
17
  * starts it again (after its ThrottleInterval) whatever the exit code.
18
18
  *
19
+ * A daemon whose every op stops at the same file (policy.check opening the
20
+ * caller's session meta.yaml, for one) never shows a second path. So when the
21
+ * window holds enough hits on one path only, hqd lists the HQ root itself:
22
+ * macOS privacy refuses that with EPERM too, while one odd file (flags, an
23
+ * ACL) leaves the root readable. A refused root counts as the trip; a
24
+ * readable one does not, and is asked again at most once per
25
+ * TCC_EPERM_ROOT_CHECK_INTERVAL_MS.
26
+ *
19
27
  * It never exits for EPERM outside the HQ root, for EACCES, off macOS, while
20
28
  * the daemon is already stopping, or when no service manager would start it
21
29
  * again. A permission that stays revoked would otherwise restart the daemon
@@ -34,8 +42,13 @@ export const TCC_EPERM_EXIT_CODE = 74;
34
42
  export const TCC_EPERM_WINDOW_MS = 60_000;
35
43
  /** Hits needed inside the window. */
36
44
  export const TCC_EPERM_MIN_EVENTS = 3;
37
- /** Distinct paths needed inside the window, so one odd file cannot trip it. */
45
+ /**
46
+ * Distinct paths needed inside the window, so one odd file cannot trip it.
47
+ * With fewer, the guard trips only if listing the HQ root is refused as well.
48
+ */
38
49
  export const TCC_EPERM_MIN_PATHS = 2;
50
+ /** While enough hits sit on too few paths, the guard lists the HQ root at most this often. */
51
+ export const TCC_EPERM_ROOT_CHECK_INTERVAL_MS = 10_000;
39
52
  /** Exits allowed inside TCC_EPERM_EXIT_WINDOW_MS before the daemon stays up instead. */
40
53
  export const TCC_EPERM_MAX_EXITS = 3;
41
54
  export const TCC_EPERM_EXIT_WINDOW_MS = 30 * 60_000;
@@ -43,8 +56,47 @@ export const TCC_EPERM_EXIT_WINDOW_MS = 30 * 60_000;
43
56
  export const TCC_EPERM_EXITS_FILE = "tcc-eperm-exits.json";
44
57
  /** Under the daemon dir: present while hqd is up but cannot read the HQ folder. */
45
58
  export const FILES_ACCESS_NEEDED_MARKER = "files-access-needed.json";
46
- export const FILES_ACCESS_NEEDED_MESSAGE = "HQ needs Full Disk Access (or Files and Folders access) to your HQ folder. macOS is refusing the daemon's file reads and writes there. " +
47
- "Open System Settings > Privacy & Security > Full Disk Access, allow HQ, then run: hq daemon restart";
59
+ const FILES_ACCESS_LAUNCHES = new Set(["node-direct", "hq-app", "terminal"]);
60
+ /**
61
+ * How this daemon was started, from its run options and parent pid. launchd
62
+ * is pid 1, so a managed daemon whose parent is launchd runs node directly;
63
+ * under the HQ.app launcher (--hq-launchd-task) the parent is the launcher.
64
+ */
65
+ export function filesAccessLaunch(opts) {
66
+ if (opts.host !== undefined)
67
+ return "hq-app";
68
+ if (opts.managed !== true)
69
+ return "terminal";
70
+ return opts.ppid === 1 ? "node-direct" : "hq-app";
71
+ }
72
+ /**
73
+ * What to tell the user. With no known launch (a marker from an older
74
+ * daemon) this is the HQ-app wording the daemon always used.
75
+ */
76
+ export function filesAccessNeededMessage(launch, program) {
77
+ const settings = "Open System Settings > Privacy & Security > Full Disk Access";
78
+ if (launch === "node-direct") {
79
+ const who = program ? `the program that runs the HQ daemon, ${program}` : "the node program that runs the HQ daemon";
80
+ const add = program ? `click +, press Cmd+Shift+G, enter ${program}, add it` : "click +, add that node program";
81
+ return (`HQ needs Full Disk Access for ${who}. macOS is refusing that program's file reads and writes in your HQ folder, ` +
82
+ "and allowing the HQ app does not cover it. " +
83
+ `${settings}, ${add}, then run: hq daemon restart. ` +
84
+ "Upgrading node (for example with Homebrew) can change that path; add the new path again after an upgrade.");
85
+ }
86
+ if (launch === "terminal") {
87
+ return ("HQ needs Full Disk Access for the terminal app the HQ daemon was started from. macOS is refusing the daemon's file reads and writes in your HQ folder. " +
88
+ `${settings}, allow that terminal app, then start the daemon again`);
89
+ }
90
+ return ("HQ needs Full Disk Access (or Files and Folders access) to your HQ folder. macOS is refusing the daemon's file reads and writes there. " +
91
+ `${settings}, allow HQ, then run: hq daemon restart`);
92
+ }
93
+ /** A usable program path from the marker: absolute, one line, bounded. */
94
+ function markerProgram(value) {
95
+ if (typeof value !== "string" || value.length > 1024 || !path.isAbsolute(value))
96
+ return undefined;
97
+ // eslint-disable-next-line no-control-regex
98
+ return /[\u0000-\u001f\u007f]/.test(value) ? undefined : value;
99
+ }
48
100
  export const TCC_EPERM_SENTRY_FINGERPRINT = ["hqd", "tcc-eperm-under-hq-root"];
49
101
  /**
50
102
  * Syscalls that read. macOS privacy refuses these with EPERM when it cuts a
@@ -167,13 +219,36 @@ export function recordEpermExit(daemonDir, now, exitWindowMs = TCC_EPERM_EXIT_WI
167
219
  writePrivateJson(path.join(daemonDir, TCC_EPERM_EXITS_FILE), { exits });
168
220
  return exits;
169
221
  }
170
- export function writeFilesAccessNeeded(daemonDir, now, reason) {
222
+ /**
223
+ * `launch`: how the daemon was started (filesAccessLaunch). `program`: the
224
+ * binary launchd runs (process.execPath in hqd); recorded only for
225
+ * "node-direct", the one case where it is the program macOS checks.
226
+ */
227
+ export function writeFilesAccessNeeded(daemonDir, now, reason, launch, program) {
228
+ const usable = launch === "node-direct" ? markerProgram(program) : undefined;
171
229
  writePrivateJson(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), {
172
230
  since: new Date(now).toISOString(),
173
231
  reason,
174
- message: FILES_ACCESS_NEEDED_MESSAGE,
232
+ ...(launch ? { launch } : {}),
233
+ ...(usable ? { program: usable } : {}),
234
+ message: filesAccessNeededMessage(launch, usable),
175
235
  });
176
236
  }
237
+ /** The message for the marker a running daemon wrote, from the launch and program it recorded. */
238
+ export function filesAccessNeededMessageFromMarker(daemonDir) {
239
+ let launch;
240
+ let program;
241
+ try {
242
+ const marker = JSON.parse(fs.readFileSync(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), "utf8"));
243
+ launch = typeof marker.launch === "string" && FILES_ACCESS_LAUNCHES.has(marker.launch) ? marker.launch : undefined;
244
+ program = launch === "node-direct" ? markerProgram(marker.program) : undefined;
245
+ }
246
+ catch {
247
+ launch = undefined;
248
+ program = undefined;
249
+ }
250
+ return filesAccessNeededMessage(launch, program);
251
+ }
177
252
  export function clearFilesAccessNeeded(daemonDir) {
178
253
  fs.rmSync(path.join(daemonDir, FILES_ACCESS_NEEDED_MARKER), { force: true });
179
254
  }
@@ -191,8 +266,13 @@ export function createTccEpermGuard(deps) {
191
266
  const now = deps.now ?? Date.now;
192
267
  const probe = deps.probe ?? ((root) => void fs.readdirSync(root));
193
268
  const schedule = deps.schedule ?? defaultSchedule;
269
+ const launch = deps.launch;
270
+ const program = launch === "node-direct" ? markerProgram(deps.program ?? process.execPath) : undefined;
194
271
  let window = createEpermWindow(deps.window);
195
272
  const windowMs = deps.window?.windowMs ?? TCC_EPERM_WINDOW_MS;
273
+ const minEvents = deps.window?.minEvents ?? TCC_EPERM_MIN_EVENTS;
274
+ const rootCheckIntervalMs = deps.rootCheckIntervalMs ?? TCC_EPERM_ROOT_CHECK_INTERVAL_MS;
275
+ let lastRootCheck = null;
196
276
  let state = "watching";
197
277
  let cancelProbe = null;
198
278
  if (deps.platform === "darwin") {
@@ -220,6 +300,7 @@ export function createTccEpermGuard(deps) {
220
300
  cancelProbe?.();
221
301
  cancelProbe = null;
222
302
  window = createEpermWindow(deps.window);
303
+ lastRootCheck = null;
223
304
  state = "watching";
224
305
  try {
225
306
  clearFilesAccessNeeded(deps.daemonDir);
@@ -233,13 +314,32 @@ export function createTccEpermGuard(deps) {
233
314
  const stayUp = (at, reason) => {
234
315
  state = "access-needed";
235
316
  try {
236
- writeFilesAccessNeeded(deps.daemonDir, at, reason);
317
+ writeFilesAccessNeeded(deps.daemonDir, at, reason, launch, program);
237
318
  }
238
319
  catch (writeErr) {
239
320
  deps.log("warn", `could not write ${FILES_ACCESS_NEEDED_MARKER}: ${writeErr.message}`);
240
321
  }
241
322
  cancelProbe ??= schedule(() => void checkAccess(), deps.probeIntervalMs ?? TCC_EPERM_PROBE_INTERVAL_MS);
242
323
  };
324
+ /**
325
+ * Enough hits, too few paths: is the HQ root itself refused? Only EPERM
326
+ * counts; a root that is missing or fails some other way is not a privacy
327
+ * refusal. Lists the root at most once per rootCheckIntervalMs.
328
+ */
329
+ const rootRefused = (hqRoot, at) => {
330
+ if (window.summary().hits < minEvents)
331
+ return false;
332
+ if (lastRootCheck !== null && at >= lastRootCheck && at - lastRootCheck < rootCheckIntervalMs)
333
+ return false;
334
+ lastRootCheck = at;
335
+ try {
336
+ probe(hqRoot);
337
+ return false;
338
+ }
339
+ catch (err) {
340
+ return err?.code === "EPERM";
341
+ }
342
+ };
243
343
  return {
244
344
  state: () => state,
245
345
  checkAccess,
@@ -257,7 +357,8 @@ export function createTccEpermGuard(deps) {
257
357
  if (!hit)
258
358
  return;
259
359
  const at = now();
260
- if (!window.record(hit, at))
360
+ const byRoot = !window.record(hit, at);
361
+ if (byRoot && !rootRefused(hqRoot, at))
261
362
  return;
262
363
  const recentExits = readEpermExits(deps.daemonDir);
263
364
  let decision = decideEpermExit({
@@ -289,6 +390,7 @@ export function createTccEpermGuard(deps) {
289
390
  event: "hqd.tcc_eperm",
290
391
  platform: deps.platform,
291
392
  ...window.summary(),
393
+ ...(byRoot ? { rootRefused: true } : {}),
292
394
  windowMs,
293
395
  decision: decision.action,
294
396
  ...(decision.action === "stay" ? { reason: decision.reason } : { exitCode: decision.code }),
@@ -301,7 +403,7 @@ export function createTccEpermGuard(deps) {
301
403
  void report(event).finally(() => deps.exit(code));
302
404
  }
303
405
  else {
304
- deps.log("error", `hqd: staying up; ${FILES_ACCESS_NEEDED_MESSAGE}`);
406
+ deps.log("error", `hqd: staying up; ${filesAccessNeededMessage(launch, program)}`);
305
407
  void report(event);
306
408
  }
307
409
  },
@@ -3,11 +3,29 @@
3
3
  * that reused it (feedback cd56a501).
4
4
  */
5
5
  import type { RefreshOwnerIdentity } from "./refresh-sync-handoff.js";
6
+ /** Inputs for locating the system process tool; tests inject them. */
7
+ export interface ProcessToolProbe {
8
+ platform?: NodeJS.Platform;
9
+ env?: NodeJS.ProcessEnv;
10
+ isExecutable?: (file: string) => boolean;
11
+ }
12
+ /** The fixed POSIX locations of `ps`, tried in order. */
13
+ export declare const POSIX_PS_PATHS: readonly string[];
14
+ /**
15
+ * The absolute path of the system tool that reads a process start time, found
16
+ * at a fixed location and never through PATH, so the answer is the same on
17
+ * every machine whatever PATH holds. POSIX: the first executable of /bin/ps and
18
+ * /usr/bin/ps. Windows: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
19
+ * (SystemRoot defaults to C:\Windows). Null if the tool is not there.
20
+ */
21
+ export declare function processStartTool(probe?: ProcessToolProbe): string | null;
6
22
  /**
7
23
  * A process's start time, or null if it cannot be read: `ps -o lstart=` on
8
- * POSIX, the process StartTime from PowerShell on Windows.
24
+ * POSIX, the process StartTime from PowerShell on Windows. Both tools are
25
+ * found by fixed path (processStartTool); if neither is there the answer is
26
+ * null, which lock callers treat as busy.
9
27
  */
10
- export declare function processStartTime(pid: number): string | null;
28
+ export declare function processStartTime(pid: number, probe?: ProcessToolProbe): string | null;
11
29
  /** Real process-table identity for the refresh spawn lock. */
12
30
  export declare const DEFAULT_OWNER_IDENTITY: RefreshOwnerIdentity;
13
31
  //# sourceMappingURL=process-identity.d.ts.map
@@ -3,22 +3,65 @@
3
3
  * that reused it (feedback cd56a501).
4
4
  */
5
5
  import { spawnSync } from "node:child_process";
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ /** The fixed POSIX locations of `ps`, tried in order. */
9
+ export const POSIX_PS_PATHS = ["/bin/ps", "/usr/bin/ps"];
10
+ function defaultIsExecutable(platform) {
11
+ return (file) => {
12
+ try {
13
+ if (!fs.statSync(file).isFile())
14
+ return false;
15
+ if (platform !== "win32")
16
+ fs.accessSync(file, fs.constants.X_OK);
17
+ return true;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ };
23
+ }
24
+ /**
25
+ * The absolute path of the system tool that reads a process start time, found
26
+ * at a fixed location and never through PATH, so the answer is the same on
27
+ * every machine whatever PATH holds. POSIX: the first executable of /bin/ps and
28
+ * /usr/bin/ps. Windows: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
29
+ * (SystemRoot defaults to C:\Windows). Null if the tool is not there.
30
+ */
31
+ export function processStartTool(probe = {}) {
32
+ const platform = probe.platform ?? process.platform;
33
+ const isExecutable = probe.isExecutable ?? defaultIsExecutable(platform);
34
+ if (platform === "win32") {
35
+ const env = probe.env ?? process.env;
36
+ const key = Object.keys(env).find((name) => name.toUpperCase() === "SYSTEMROOT");
37
+ const systemRoot = (key ? env[key] : undefined) || "C:\\Windows";
38
+ const powershell = path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
39
+ return isExecutable(powershell) ? powershell : null;
40
+ }
41
+ return POSIX_PS_PATHS.find((candidate) => isExecutable(candidate)) ?? null;
42
+ }
6
43
  /**
7
44
  * A process's start time, or null if it cannot be read: `ps -o lstart=` on
8
- * POSIX, the process StartTime from PowerShell on Windows.
45
+ * POSIX, the process StartTime from PowerShell on Windows. Both tools are
46
+ * found by fixed path (processStartTool); if neither is there the answer is
47
+ * null, which lock callers treat as busy.
9
48
  */
10
- export function processStartTime(pid) {
49
+ export function processStartTime(pid, probe = {}) {
11
50
  if (!Number.isInteger(pid) || pid <= 0)
12
51
  return null;
52
+ const tool = processStartTool(probe);
53
+ if (!tool)
54
+ return null;
55
+ const platform = probe.platform ?? process.platform;
13
56
  try {
14
- const result = process.platform === "win32"
15
- ? spawnSync("powershell.exe", [
57
+ const result = platform === "win32"
58
+ ? spawnSync(tool, [
16
59
  "-NoProfile",
17
60
  "-NonInteractive",
18
61
  "-Command",
19
62
  `(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().ToString('o')`,
20
63
  ], { encoding: "utf8", timeout: 10_000, windowsHide: true })
21
- : spawnSync("ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
64
+ : spawnSync(tool, ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
22
65
  const text = (result.stdout ?? "").trim();
23
66
  return result.status === 0 && text ? text : null;
24
67
  }
@@ -104,6 +104,7 @@ export function canaryRefusal(record, expected) {
104
104
  return `the last ${host} canary failed`;
105
105
  if (result.engineVersion === null)
106
106
  return `the last ${host} canary reached no event on the new core`;
107
+ // Preserve metadata: semver precedence equality would accept another source build.
107
108
  if (result.engineVersion !== engineVersion) {
108
109
  return `the last ${host} canary ran hq-hook ${String(result.engineVersion)}, not ${engineVersion}`;
109
110
  }
@@ -82,7 +82,8 @@
82
82
  ],
83
83
  ".claude/hooks/lanes-senior-monitor-stop-gate.sh": [
84
84
  "c34e55aa10cf2c768943711a6a3cd89a69c7d5947050cb0f4cebb1289b55f671",
85
- "03d8896cac9756c84f8fb8e5d51af9ee26bac3e6e024795bb0d10c2823c01208"
85
+ "03d8896cac9756c84f8fb8e5d51af9ee26bac3e6e024795bb0d10c2823c01208",
86
+ "1741275eef31d7f656ed618f4c08814ff630b6664f98f18ebdd822b3d2270827"
86
87
  ],
87
88
  ".claude/hooks/conduct-lanes-link-deliver.sh": [
88
89
  "b1124363238ba405a0efd4bca08b4601430a596614037fbd30bf92b2e6bf8465"
@@ -82,6 +82,7 @@ import * as fs from "node:fs/promises";
82
82
  import * as path from "node:path";
83
83
  import * as yaml from "js-yaml";
84
84
  import { MAX_CATCH_UP_WINDOW_MS } from "../contract.js";
85
+ import { matchFrontmatter } from "../../../utils/frontmatter.js";
85
86
  import { eventKey, HOT_SIGNAL_ORIGIN, hotSourceId } from "../landing.js";
86
87
  export const ATTIO_ADAPTER_ID = "attio";
87
88
  export const ATTIO_CHANNEL = "attio-events";
@@ -203,7 +204,7 @@ function parseTime(value) {
203
204
  }
204
205
  /** Split `---\n{yaml}\n---\n{body}` and return the frontmatter. Unparseable or non-object is null. */
205
206
  function readFrontmatter(text) {
206
- const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
207
+ const match = matchFrontmatter(text);
207
208
  if (!match)
208
209
  return null;
209
210
  let parsed;
@@ -46,6 +46,7 @@ import * as fs from "node:fs/promises";
46
46
  import * as path from "node:path";
47
47
  import * as yaml from "js-yaml";
48
48
  import { isAuthError } from "../../../utils/auth-error.js";
49
+ import { matchFrontmatter } from "../../../utils/frontmatter.js";
49
50
  import { MAX_CATCH_UP_WINDOW_MS } from "../contract.js";
50
51
  import { assertSafeSegment, HOT_SIGNAL_ORIGIN, writeFileAtomic } from "../landing.js";
51
52
  import { SyncLockLostError } from "../sync-lock.js";
@@ -92,7 +93,7 @@ function toVersion(value) {
92
93
  }
93
94
  /** Split `---\n{yaml}\n---\n{body}`. Unparseable or non-object frontmatter is null. */
94
95
  function splitFrontmatter(text) {
95
- const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
96
+ const match = matchFrontmatter(text);
96
97
  if (!match)
97
98
  return null;
98
99
  let parsed;
@@ -0,0 +1,37 @@
1
+ import { type OutpostsClient } from "@indigoai-us/hq-cloud/outposts";
2
+ import { LanesError } from "./errors.js";
3
+ import type { OutpostExecPort } from "./outpost-dispatch.js";
4
+ import type { LaneCompanyRef } from "./types.js";
5
+ type CompanyIdentity = {
6
+ uid: string;
7
+ slug?: string;
8
+ };
9
+ export interface CompanyOutpostCandidate {
10
+ outpostId: string;
11
+ lifecycle?: string;
12
+ canUse?: boolean;
13
+ lanesReady?: boolean;
14
+ }
15
+ export type CompanyOutpostListPort = Pick<OutpostsClient, "request">;
16
+ export type CompanyOutpostExecClient = Pick<OutpostsClient, "stageExecInput" | "submitExec" | "waitForExecResult">;
17
+ export declare function isCompanyOutpostId(id: string): boolean;
18
+ export declare function companyUidOfFirstOutpostId(id: string): string | undefined;
19
+ export declare function companyOutpostAccessRequired(outpostId: string, company: CompanyIdentity): LanesError;
20
+ export declare function companyOutpostRefusal(err: unknown, outpostId: string, company: CompanyIdentity): LanesError | undefined;
21
+ export declare function isCompanyOutpostRefusal(err: unknown): err is LanesError;
22
+ export declare function assertCompanyOutpostBelongsTo(outpostId: string, company: LaneCompanyRef): void;
23
+ export declare function companyOutpostNeedsCompany(outpostId: string): LanesError;
24
+ export declare function isNoCompanyOutposts(err: unknown): boolean;
25
+ export declare class CompanyOutpostTargets {
26
+ private readonly lookupRecordedCompany;
27
+ private readonly companies;
28
+ constructor(lookupRecordedCompany?: (outpostId: string) => LaneCompanyRef | undefined);
29
+ remember(company: LaneCompanyRef, outpostIds: readonly string[]): void;
30
+ companyOf(outpostId: string): CompanyIdentity | undefined;
31
+ }
32
+ export declare function listCompanyOutpostCandidates(port: CompanyOutpostListPort, company: LaneCompanyRef): Promise<CompanyOutpostCandidate[]>;
33
+ export declare function readyCompanyOutpostIds(candidates: readonly CompanyOutpostCandidate[]): string[];
34
+ export declare function companyOutpostNotLaneReady(outpostId: string, company: CompanyIdentity): LanesError;
35
+ export declare function companyAwareExecPort(client: CompanyOutpostExecClient, targets: CompanyOutpostTargets): OutpostExecPort;
36
+ export {};
37
+ //# sourceMappingURL=company-outposts.d.ts.map