@indigoai-us/hq-cli 5.345.245 → 5.345.247

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 (127) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/command-catalog.generated.d.ts +96 -9
  3. package/dist/command-catalog.generated.js +117 -9
  4. package/dist/commands/bot.js +1 -1
  5. package/dist/commands/core-checkpoint-native.d.ts +5 -1
  6. package/dist/commands/core-checkpoint-native.js +13 -5
  7. package/dist/commands/deploy-comments.js +139 -0
  8. package/dist/commands/deploy-list.d.ts +5 -0
  9. package/dist/commands/deploy-list.js +8 -0
  10. package/dist/commands/dm.d.ts +4 -1
  11. package/dist/commands/dm.js +11 -2
  12. package/dist/commands/files.d.ts +11 -2
  13. package/dist/commands/files.js +48 -3
  14. package/dist/commands/install-global.d.ts +15 -0
  15. package/dist/commands/install-global.js +98 -4
  16. package/dist/commands/lanes-loop.js +4 -1
  17. package/dist/commands/lanes.js +16 -5
  18. package/dist/commands/mcp-registration.d.ts +17 -0
  19. package/dist/commands/mcp-registration.js +119 -0
  20. package/dist/commands/mesh.d.ts +2 -0
  21. package/dist/commands/mesh.js +26 -6
  22. package/dist/commands/pkg-install.js +1 -1
  23. package/dist/commands/reindex.js +3 -2
  24. package/dist/commands/rescue.d.ts +22 -1
  25. package/dist/commands/rescue.js +56 -9
  26. package/dist/commands/sources.d.ts +1 -1
  27. package/dist/commands/sources.js +1 -1
  28. package/dist/commands/storage.d.ts +15 -2
  29. package/dist/commands/storage.js +74 -7
  30. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +232 -225
  31. package/dist/hq-cloud-sync-runner/package.json +1 -1
  32. package/dist/lib/agent-kit/mcp/tools.js +22 -0
  33. package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
  34. package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
  35. package/dist/lib/daemon/fleet-members-cache.js +266 -0
  36. package/dist/lib/daemon/handoff.d.ts +4 -0
  37. package/dist/lib/daemon/handoff.js +2 -1
  38. package/dist/lib/daemon/hook-requests.d.ts +2 -1
  39. package/dist/lib/daemon/hook-requests.js +19 -2
  40. package/dist/lib/daemon/install.d.ts +9 -1
  41. package/dist/lib/daemon/install.js +11 -2
  42. package/dist/lib/daemon/ops/policy.d.ts +23 -3
  43. package/dist/lib/daemon/ops/policy.js +62 -15
  44. package/dist/lib/daemon/run.js +12 -0
  45. package/dist/lib/daemon/server.d.ts +5 -0
  46. package/dist/lib/daemon/server.js +1 -1
  47. package/dist/lib/daemon/supervisor.d.ts +6 -0
  48. package/dist/lib/daemon/supervisor.js +31 -2
  49. package/dist/lib/doctor/checks/antigravity-wiring.d.ts +21 -0
  50. package/dist/lib/doctor/checks/antigravity-wiring.js +75 -0
  51. package/dist/lib/doctor/checks/anywhere.js +30 -0
  52. package/dist/lib/doctor/checks/runtime-probe.js +13 -0
  53. package/dist/lib/doctor/checks/sync-runtime.js +8 -1
  54. package/dist/lib/doctor/platform.d.ts +1 -1
  55. package/dist/lib/doctor/platform.js +5 -0
  56. package/dist/lib/doctor/registry.js +3 -0
  57. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  58. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  59. package/dist/lib/hook-engine/coverage.d.ts +159 -0
  60. package/dist/lib/hook-engine/coverage.js +347 -0
  61. package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
  62. package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
  63. package/dist/lib/hot-channels/signals-pass.js +65 -3
  64. package/dist/lib/install/antigravity-targets.d.ts +39 -0
  65. package/dist/lib/install/antigravity-targets.js +122 -0
  66. package/dist/lib/install/claude-targets.d.ts +6 -0
  67. package/dist/lib/install/claude-targets.js +9 -1
  68. package/dist/lib/lanes/reconcile-result.d.ts +1 -1
  69. package/dist/lib/lanes/reconcile.js +19 -4
  70. package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
  71. package/dist/lib/lanes/remote-control-lane.js +10 -1
  72. package/dist/lib/lanes/spawn.d.ts +2 -0
  73. package/dist/lib/lanes/spawn.js +19 -3
  74. package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
  75. package/dist/lib/lanes/worker-env-scrub.js +146 -0
  76. package/dist/lib/lanes/worker-process.js +4 -1
  77. package/dist/lib/mesh/client.js +5 -1
  78. package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
  79. package/dist/lib/mesh/live/daemon/doctor.js +51 -6
  80. package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
  81. package/dist/lib/mesh/live/daemon/install.js +70 -0
  82. package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
  83. package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
  84. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  85. package/dist/lib/mesh/live/daemon/run.js +48 -3
  86. package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
  87. package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
  88. package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
  89. package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
  90. package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
  91. package/dist/lib/mesh/live/direct-drain.js +3 -1
  92. package/dist/lib/mesh/live/emit.js +4 -2
  93. package/dist/lib/mesh/live/flush.d.ts +61 -0
  94. package/dist/lib/mesh/live/flush.js +434 -114
  95. package/dist/lib/mesh/live/paths.d.ts +10 -0
  96. package/dist/lib/mesh/live/paths.js +14 -0
  97. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
  98. package/dist/lib/mesh/live/reporting-privacy.js +81 -7
  99. package/dist/lib/mesh/live/spool.d.ts +171 -17
  100. package/dist/lib/mesh/live/spool.js +777 -62
  101. package/dist/lib/signals/engine.d.ts +82 -2
  102. package/dist/lib/signals/engine.js +389 -53
  103. package/dist/lib/signals/steps/extract.js +5 -0
  104. package/dist/lib/work-context/organize.d.ts +22 -4
  105. package/dist/lib/work-context/organize.js +50 -21
  106. package/dist/lib/work-context/paths.d.ts +6 -0
  107. package/dist/lib/work-context/paths.js +9 -0
  108. package/dist/lib/work-context/reconcile.d.ts +1 -1
  109. package/dist/lib/work-context/reconcile.js +1 -1
  110. package/dist/startup-registration.d.ts +14 -0
  111. package/dist/startup-registration.js +26 -0
  112. package/dist/utils/cli-telemetry.d.ts +6 -0
  113. package/dist/utils/cli-telemetry.js +154 -9
  114. package/dist/utils/github-tag-fallback.d.ts +7 -2
  115. package/dist/utils/github-tag-fallback.js +17 -8
  116. package/dist/utils/hq-core-source.d.ts +31 -0
  117. package/dist/utils/hq-core-source.js +144 -0
  118. package/dist/utils/interactive-caller.d.ts +6 -0
  119. package/dist/utils/interactive-caller.js +8 -0
  120. package/dist/utils/shipped-codex-hooks.d.ts +6 -4
  121. package/dist/utils/shipped-codex-hooks.js +22 -10
  122. package/dist/utils/vault-api.js +1 -0
  123. package/dist/utils/version-report.d.ts +3 -1
  124. package/dist/utils/version-report.js +13 -5
  125. package/docs/anywhere-runtime.md +2 -2
  126. package/package.json +8 -8
  127. package/scripts/check-function-manifest.mjs +99 -18
@@ -266,8 +266,40 @@ export const DEFAULT_SIGNALS_TIMEOUT_MS = 120_000;
266
266
  export const AUTH_PREFLIGHT_TIMEOUT_MS = 10_000;
267
267
  /** Budget for one worklist script call. */
268
268
  export const WORKLIST_TIMEOUT_MS = 60_000;
269
- /** Documents one pass sends to claude across all adapters of a run. */
270
- export const DEFAULT_MAX_SIGNAL_DOCS = 20;
269
+ /**
270
+ * Documents one pass sends to claude across all adapters of a run.
271
+ *
272
+ * 40, raised from 20 on 2026-11-22 (owner decision: raise the limit rather
273
+ * than reword the warning). The 2026-11-21 06:30 PT indigo job had 31
274
+ * documents waiting after four days of signed-out runs: 20 were read in about
275
+ * 2m45s for the whole job (about 8s a document) and 11 were left for the next
276
+ * day, so a run with nothing wrong was reported as partial. 40 covers that
277
+ * backlog, and a 24-meeting re-run, in one pass.
278
+ *
279
+ * The cap still bounds the run. Calls stay subscription-only (an API-key or
280
+ * third-party login is refused before the first document), a usage-limit reply
281
+ * stops the pass at once, and BAD_OUTPUT_STOP_AFTER stops a run of unusable
282
+ * replies, so raising the cap adds no per-token spend. At the observed rate 40
283
+ * documents take about 5-6 minutes; each call keeps its own
284
+ * DEFAULT_SIGNALS_TIMEOUT_MS budget, and the sync lock is heartbeated, so a
285
+ * longer pass is not taken over as stale.
286
+ *
287
+ * Worst-case duration (not expected; it needs nearly every call to run to its
288
+ * full 120 s budget without BAD_OUTPUT_STOP_AFTER documents failing in a row):
289
+ * - Unusable replies: 40 documents x BAD_OUTPUT_ATTEMPTS (3) calls x 120 s =
290
+ * 4 hours (2 hours at the old cap of 20). That is longer than the 3 hours
291
+ * after which the engine's company run lock can be taken over (LOCK_STALE_MS
292
+ * in src/lib/signals/run-lock.ts, counted from the lock's start, with no
293
+ * heartbeat).
294
+ * - Once a timed-out document is skipped instead of sent again (PR 3438, not
295
+ * merged when this was written): 40 x 120 s = 80 minutes (40 minutes at the
296
+ * old cap). That is longer than the 60 minutes after which the bot releases
297
+ * an in-flight job (IN_FLIGHT_RELEASE_MS in src/lib/bot/local-jobs.ts).
298
+ * The worklist listing keeps its fixed WORKLIST_TIMEOUT_MS (60 s) at
299
+ * `--limit 40`; it does not grow with the limit the way the extract step's
300
+ * listing budget does (src/lib/signals/steps/extract.ts).
301
+ */
302
+ export const DEFAULT_MAX_SIGNAL_DOCS = 40;
271
303
  /**
272
304
  * Claude calls per document when the reply is unusable (`claude-bad-output`).
273
305
  * The reply differs from call to call, so a document whose first reply has a
@@ -412,6 +444,29 @@ export function signalCitation(at, segments, sourceRef) {
412
444
  const seg = startMs === null ? undefined : segments.get(startMs);
413
445
  return seg ? { source_ref: sourceRef, start_ms: seg.startMs, end_ms: seg.endMs } : undefined;
414
446
  }
447
+ /**
448
+ * A meeting recap cites the span of the segments it is given: the earliest
449
+ * segment start and the latest segment end, whatever order the markers come
450
+ * in, so an out-of-order or overlapping marker cannot give a start after the
451
+ * end or a span shorter than one segment. `segments` comes from the payload
452
+ * text the pass read, which is capped at MAX_PAYLOAD_BYTES, so a longer
453
+ * transcript is cited up to the last marker inside that cap, not to its end.
454
+ * Undefined when there are no segments. Nothing is inferred beyond the
455
+ * markers already in `segments`.
456
+ */
457
+ export function summaryTranscriptCitation(segments, sourceRef) {
458
+ let startMs;
459
+ let endMs;
460
+ for (const seg of segments.values()) {
461
+ if (startMs === undefined || seg.startMs < startMs)
462
+ startMs = seg.startMs;
463
+ if (endMs === undefined || seg.endMs > endMs)
464
+ endMs = seg.endMs;
465
+ }
466
+ if (startMs === undefined || endMs === undefined)
467
+ return undefined;
468
+ return { source_ref: sourceRef, start_ms: startMs, end_ms: endMs };
469
+ }
415
470
  export function defaultPromptFile() {
416
471
  return path.join(path.dirname(fileURLToPath(import.meta.url)), "prompts", "signals-pass.md");
417
472
  }
@@ -1348,7 +1403,14 @@ export function createClaudeSignalsPass(options) {
1348
1403
  origin: SIGNAL_ORIGIN,
1349
1404
  written_at: at,
1350
1405
  };
1351
- const citation = signalCitation(signal.at, segments, sourceRef);
1406
+ let citation = signalCitation(signal.at, segments, sourceRef);
1407
+ // A recap has no single `at`. Cite the span of the segments read (the
1408
+ // payload is capped at MAX_PAYLOAD_BYTES) so upload can keep it. Only a
1409
+ // signal written by this run gets one: a signal file already on disk is
1410
+ // skipped above and is not rewritten.
1411
+ if (citation === undefined && signal.type === "summary") {
1412
+ citation = summaryTranscriptCitation(segments, sourceRef);
1413
+ }
1352
1414
  if (citation !== undefined)
1353
1415
  frontmatter.citations = [citation];
1354
1416
  if (input.payloadRef !== undefined)
@@ -0,0 +1,39 @@
1
+ export declare const ANTIGRAVITY_BUNDLE_ID = "com.google.antigravity";
2
+ export declare const ANTIGRAVITY_CLI_BINARY = "agy";
3
+ export declare const ANTIGRAVITY_RULE_MARKER = "<!-- hq-anywhere:antigravity (managed by `hq install --global`; edits are overwritten) -->";
4
+ export declare const ANTIGRAVITY_HOOKS_ADVISORY = "Antigravity hooks: not wired yet \u2014 HQ policies load through the always-on rule and AGENTS.md; hook guards arrive in a later release";
5
+ export interface AntigravityTargets {
6
+ configDir: string;
7
+ rulesDir: string;
8
+ ruleFile: string;
9
+ mcpConfig: string;
10
+ stateDir: string;
11
+ cliStateDir: string;
12
+ }
13
+ export declare function antigravityTargets(home: string): AntigravityTargets;
14
+ export interface AntigravityDetectOptions {
15
+ home: string;
16
+ env?: NodeJS.ProcessEnv;
17
+ platform?: NodeJS.Platform;
18
+ /** Override for the macOS app bundle path (env HQ_ANTIGRAVITY_APP_PATH also works). */
19
+ appPath?: string;
20
+ }
21
+ export interface AntigravityDetection {
22
+ detected: boolean;
23
+ signals: string[];
24
+ }
25
+ /** Antigravity is present when any of: the macOS app, a config/state dir, or `agy` on PATH. */
26
+ export declare function detectAntigravity(opts: AntigravityDetectOptions): AntigravityDetection;
27
+ /** The full HQ-owned rule file. Deterministic so a re-run is a byte-for-byte no-op. */
28
+ export declare function antigravityRuleContent(hqRoot: string): string;
29
+ export type RulePlan = {
30
+ action: 'write' | 'noop';
31
+ content: string;
32
+ } | {
33
+ action: 'foreign';
34
+ content: string;
35
+ };
36
+ /** Decide what to do with the rule file: HQ-owned files are replaced, others are left alone. */
37
+ export declare function planAntigravityRule(current: string | null, hqRoot: string): RulePlan;
38
+ export declare function isHqAntigravityRule(current: string | null): boolean;
39
+ //# sourceMappingURL=antigravity-targets.d.ts.map
@@ -0,0 +1,122 @@
1
+ /** Google Antigravity host integration.
2
+ *
3
+ * Antigravity (App, IDE and the `agy` CLI) reads a shared user config root at
4
+ * `~/.gemini/config/`. HQ writes two things there:
5
+ *
6
+ * - `rules/hq.md`: an always-on global rule (frontmatter `trigger: always_on`
7
+ * is required; a rule without valid frontmatter is silently discarded) that
8
+ * points the agent at the HQ charter. The file is whole-file owned by HQ and
9
+ * carries {@link ANTIGRAVITY_RULE_MARKER}; a file without the marker is
10
+ * user content and is never overwritten.
11
+ * - `mcp_config.json`: the HQ MCP server under `mcpServers`, merged through the
12
+ * mcp-registration safe-write path.
13
+ *
14
+ * Antigravity hooks exist but are not wired by HQ yet.
15
+ */
16
+ import * as fs from 'node:fs';
17
+ import * as path from 'node:path';
18
+ import { charterPath } from './claude-targets.js';
19
+ import { matchFrontmatter } from '../../utils/frontmatter.js';
20
+ export const ANTIGRAVITY_BUNDLE_ID = 'com.google.antigravity';
21
+ export const ANTIGRAVITY_CLI_BINARY = 'agy';
22
+ export const ANTIGRAVITY_RULE_MARKER = '<!-- hq-anywhere:antigravity (managed by `hq install --global`; edits are overwritten) -->';
23
+ export const ANTIGRAVITY_HOOKS_ADVISORY = 'Antigravity hooks: not wired yet — HQ policies load through the always-on rule and AGENTS.md; hook guards arrive in a later release';
24
+ export function antigravityTargets(home) {
25
+ const configDir = path.join(home, '.gemini', 'config');
26
+ return {
27
+ configDir,
28
+ rulesDir: path.join(configDir, 'rules'),
29
+ ruleFile: path.join(configDir, 'rules', 'hq.md'),
30
+ mcpConfig: path.join(configDir, 'mcp_config.json'),
31
+ stateDir: path.join(home, '.gemini', 'antigravity'),
32
+ cliStateDir: path.join(home, '.gemini', 'antigravity-cli'),
33
+ };
34
+ }
35
+ function isDir(p) {
36
+ try {
37
+ return fs.statSync(p).isDirectory();
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ }
43
+ function onPath(binary, env, platform) {
44
+ const sep = platform === 'win32' ? ';' : ':';
45
+ const exts = platform === 'win32' ? ['.exe', '.cmd', ''] : [''];
46
+ for (const dir of (env.PATH ?? '').split(sep)) {
47
+ if (!dir)
48
+ continue;
49
+ for (const ext of exts) {
50
+ const candidate = path.join(dir, binary + ext);
51
+ try {
52
+ if (fs.statSync(candidate).isFile())
53
+ return candidate;
54
+ }
55
+ catch {
56
+ // keep looking
57
+ }
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ /** Antigravity is present when any of: the macOS app, a config/state dir, or `agy` on PATH. */
63
+ export function detectAntigravity(opts) {
64
+ const env = opts.env ?? process.env;
65
+ const platform = opts.platform ?? process.platform;
66
+ const t = antigravityTargets(opts.home);
67
+ const signals = [];
68
+ const appPath = opts.appPath ?? env.HQ_ANTIGRAVITY_APP_PATH ?? (platform === 'darwin' ? '/Applications/Antigravity.app' : '');
69
+ if (appPath && isDir(appPath))
70
+ signals.push(`app: ${appPath}`);
71
+ if (isDir(t.configDir))
72
+ signals.push(`config: ${t.configDir}`);
73
+ if (isDir(t.stateDir))
74
+ signals.push(`state: ${t.stateDir}`);
75
+ const agy = onPath(ANTIGRAVITY_CLI_BINARY, env, platform);
76
+ if (agy)
77
+ signals.push(`cli: ${agy}`);
78
+ return { detected: signals.length > 0, signals };
79
+ }
80
+ /** Rule includes use forward slashes on every OS. */
81
+ function posix(p) {
82
+ return p.split('\\').join('/');
83
+ }
84
+ /** The full HQ-owned rule file. Deterministic so a re-run is a byte-for-byte no-op. */
85
+ export function antigravityRuleContent(hqRoot) {
86
+ const charter = posix(charterPath(hqRoot));
87
+ const agents = posix(path.join(hqRoot, 'AGENTS.md'));
88
+ return [
89
+ '---',
90
+ 'trigger: always_on',
91
+ '---',
92
+ ANTIGRAVITY_RULE_MARKER,
93
+ '',
94
+ '# HQ',
95
+ '',
96
+ `HQ is installed from ${posix(hqRoot)}. Follow the HQ charter in every workspace:`,
97
+ '',
98
+ `@[HQ charter](${charter})`,
99
+ '',
100
+ `If the charter above did not load, read ${charter} and ${agents} before acting.`,
101
+ 'HQ tools are available through the "hq" MCP server.',
102
+ '',
103
+ ].join('\n');
104
+ }
105
+ /** Decide what to do with the rule file: HQ-owned files are replaced, others are left alone. */
106
+ export function planAntigravityRule(current, hqRoot) {
107
+ const content = antigravityRuleContent(hqRoot);
108
+ if (current === null)
109
+ return { action: 'write', content };
110
+ if (current === content)
111
+ return { action: 'noop', content };
112
+ if (current.includes(ANTIGRAVITY_RULE_MARKER))
113
+ return { action: 'write', content };
114
+ return { action: 'foreign', content };
115
+ }
116
+ export function isHqAntigravityRule(current) {
117
+ if (current === null || !current.includes(ANTIGRAVITY_RULE_MARKER))
118
+ return false;
119
+ const fence = matchFrontmatter(current);
120
+ return fence !== null && /^trigger:\s*always_on\s*$/m.test(fence[1] ?? '');
121
+ }
122
+ //# sourceMappingURL=antigravity-targets.js.map
@@ -25,6 +25,12 @@ export declare function shimPath(hqRoot: string): string;
25
25
  /** Which HQ hook script the user-scope install registers. */
26
26
  export type HookTarget = 'master' | 'shim' | NativeTarget | CoreNextTarget;
27
27
  export declare function charterPath(hqRoot: string): string;
28
+ /**
29
+ * Claude Code @imports do not load when the path contains backslashes.
30
+ * `path.join` on Windows writes `\`; convert those (and any `\` already in
31
+ * hqRoot) so the managed CLAUDE.md block uses forward slashes on every OS.
32
+ */
33
+ export declare function claudeMdImportPath(hqRoot: string): string;
28
34
  export declare function hqSkillsSource(hqRoot: string): string;
29
35
  /** The exact hook command registered for one event (absolute path, quoted). */
30
36
  export declare function hookCommand(hqRoot: string, event: string, target?: HookTarget): string;
@@ -46,6 +46,14 @@ export function shimPath(hqRoot) {
46
46
  export function charterPath(hqRoot) {
47
47
  return path.join(hqRoot, '.claude', 'CLAUDE.md');
48
48
  }
49
+ /**
50
+ * Claude Code @imports do not load when the path contains backslashes.
51
+ * `path.join` on Windows writes `\`; convert those (and any `\` already in
52
+ * hqRoot) so the managed CLAUDE.md block uses forward slashes on every OS.
53
+ */
54
+ export function claudeMdImportPath(hqRoot) {
55
+ return charterPath(hqRoot).split('\\').join('/');
56
+ }
49
57
  export function hqSkillsSource(hqRoot) {
50
58
  return path.join(hqRoot, '.claude', 'skills');
51
59
  }
@@ -69,7 +77,7 @@ function shellQuote(value) {
69
77
  // CLAUDE.md block.
70
78
  // ---------------------------------------------------------------------------
71
79
  function claudeMdBlock(hqRoot) {
72
- return `${CLAUDE_MD_BEGIN}\n@${charterPath(hqRoot)}\n${CLAUDE_MD_END}\n`;
80
+ return `${CLAUDE_MD_BEGIN}\n@${claudeMdImportPath(hqRoot)}\n${CLAUDE_MD_END}\n`;
73
81
  }
74
82
  /** Append the block (replacing any prior HQ block). `null` input = file absent. */
75
83
  export function addClaudeMdBlock(current, hqRoot) {
@@ -5,7 +5,7 @@ export interface ReconcilePassResult {
5
5
  message: string;
6
6
  }[];
7
7
  }
8
- type ReconcileFailureCode = "reconcile_step_failed" | "story_ledger_missing" | "story_close_ledger_read_failed";
8
+ type ReconcileFailureCode = "reconcile_step_failed" | "story_close_ledger_read_failed";
9
9
  export declare function recordReconcileFailure(result: ReconcilePassResult, code: ReconcileFailureCode): void;
10
10
  /** Only this module constructs a diagnostic from a closed set of codes. */
11
11
  export declare function reconcileFailureText(error: unknown): string;
@@ -147,6 +147,17 @@ function isMissingPathError(error) {
147
147
  const code = error?.code;
148
148
  return code === "ENOENT" || code === "ENOTDIR";
149
149
  }
150
+ const MISSING_STORY_LEDGER_NOTE_PREFIX = "Story close skipped for lane ";
151
+ function recordMissingStoryLedgerNote(summary, laneId) {
152
+ summary.notes ??= [];
153
+ // One stderr line per pass, however many lanes are affected: the daemon runs
154
+ // a pass every 15 s, and the per-lane detail is in the summary notes.
155
+ const firstThisPass = !summary.notes.some((note) => note.startsWith(MISSING_STORY_LEDGER_NOTE_PREFIX));
156
+ summary.notes.push(`${MISSING_STORY_LEDGER_NOTE_PREFIX}${laneId}: its story ledger is absent on this host`);
157
+ if (firstThisPass) {
158
+ process.stderr.write("hq runners reconcile: note: story close skipped, story ledger absent on this host\n");
159
+ }
160
+ }
150
161
  function recordMissingCodexHomeNote(summary, home) {
151
162
  const note = `Codex rollout retention skipped home absent on this host: ${home}`;
152
163
  summary.notes ??= [];
@@ -633,14 +644,18 @@ async function closeInterruptedDoneStoryWorkers(hqRoot, lanes, questions, summar
633
644
  ledger = laneStoryLedgerIsClosed(hqRoot, lane);
634
645
  }
635
646
  catch (err) {
636
- const code = err instanceof LanesError && err.error === "story_ledger_missing"
637
- ? "story_ledger_missing"
638
- : "story_close_ledger_read_failed";
647
+ if (err instanceof LanesError && err.error === "story_ledger_missing") {
648
+ // An absent ledger is an expected state (a project removed or not
649
+ // synced to this host), not a failed pass: the lane cannot be proven
650
+ // done, so it stays interrupted and the pass stays healthy.
651
+ recordMissingStoryLedgerNote(summary, lane.lane_id);
652
+ continue;
653
+ }
639
654
  markDirty(summary, {
640
655
  kind: "lane",
641
656
  id: lane.lane_id,
642
657
  why: `story close ledger read failed: ${err instanceof Error ? err.message : String(err)}`,
643
- }, code);
658
+ }, "story_close_ledger_read_failed");
644
659
  continue;
645
660
  }
646
661
  if (!ledger.closed)
@@ -29,5 +29,11 @@ declare function tmux(socket: string, args: string[]): {
29
29
  stderr: string;
30
30
  };
31
31
  export declare function remoteControlFailureText(socket: string, session: string, capture?: typeof tmux): string;
32
+ /**
33
+ * The env for the namespace that runs the Remote Control terminal. The tmux
34
+ * server and Claude inside it inherit this, so it carries no secret-bearing
35
+ * variables (worker-env-scrub.ts).
36
+ */
37
+ export declare function remoteControlNamespaceEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
32
38
  export {};
33
39
  //# sourceMappingURL=remote-control-lane.d.ts.map
@@ -18,6 +18,7 @@ import { LanesError } from "./errors.js";
18
18
  import { readLaneClaudeCredential } from "./claude-credential.js";
19
19
  import { defaultProbe } from "./models.js";
20
20
  import { encodeClaudeProjectDir } from "./move-account.js";
21
+ import { laneWorkerEnv } from "./worker-env-scrub.js";
21
22
  /** Keep every credential and network route tied to the selected pool. */
22
23
  export function configureRemoteControlChildEnv(env, launch) {
23
24
  // The default home runs with CLAUDE_CONFIG_DIR unset so it reads the same
@@ -237,6 +238,14 @@ async function runInside(args) {
237
238
  fs.rmSync(exitFile, { force: true });
238
239
  }
239
240
  }
241
+ /**
242
+ * The env for the namespace that runs the Remote Control terminal. The tmux
243
+ * server and Claude inside it inherit this, so it carries no secret-bearing
244
+ * variables (worker-env-scrub.ts).
245
+ */
246
+ export function remoteControlNamespaceEnv(env) {
247
+ return laneWorkerEnv(env);
248
+ }
240
249
  async function runOuter(args) {
241
250
  const [daemonRoot, laneId, accountId, address] = args;
242
251
  if (!daemonRoot || !laneId || !accountId || !address)
@@ -254,7 +263,7 @@ async function runOuter(args) {
254
263
  "--map-root-user", "--mount", "--fork", "--kill-child=TERM",
255
264
  "sh", "-c", script, "hq-lane-rc", overlay,
256
265
  process.execPath, fileURLToPath(import.meta.url), "inside", ...args,
257
- ], { cwd: process.cwd(), env: process.env, stdio: "inherit" });
266
+ ], { cwd: process.cwd(), env: remoteControlNamespaceEnv(process.env), stdio: "inherit" });
258
267
  let settled = false;
259
268
  const forward = () => child.kill("SIGTERM");
260
269
  const finish = (code) => {
@@ -164,6 +164,8 @@ export declare function stopLaneProcesses(hqRoot: string, laneId: string, deps?:
164
164
  export interface ProveDetachedDeps {
165
165
  /** Test seam: throw ENOENT to exercise the no-/proc fallback. */
166
166
  readProcStatText?: (pid: number) => string;
167
+ /** Test seam: Windows has no session-leader proof. */
168
+ platform?: NodeJS.Platform;
167
169
  }
168
170
  export declare function defaultProveDetached(pid: number, deps?: ProveDetachedDeps): DetachProof;
169
171
  export declare function nextEnvelopePath(runDir: string): string;
@@ -15,6 +15,7 @@ import * as fs from "node:fs";
15
15
  import * as path from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
17
  import { configureRemoteControlChildEnv, prepareRemoteControlLane, remoteControlSelectionConfig } from "./remote-control-lane.js";
18
+ import { laneWorkerEnv } from "./worker-env-scrub.js";
18
19
  import { PROVIDER_HOME_ENV, accountStatus, isDefaultProviderHome, isLoggedOut, isSignInExpired, resolveAccount, selectBalancedAccount, } from "./accounts.js";
19
20
  import { readLaneClaudeCredential } from "./claude-credential.js";
20
21
  import { effectiveAccountHome } from "./account-home.js";
@@ -1279,6 +1280,14 @@ export function defaultProveDetached(pid, deps = {}) {
1279
1280
  throw err;
1280
1281
  }
1281
1282
  }
1283
+ // Windows Node spawn({ detached: true, windowsHide: true }) already made an
1284
+ // independent process. There is no /proc session-leader, and Git Bash `ps`
1285
+ // either is missing or reports pgid != pid, so requiring Unix session
1286
+ // leadership fails every live worker (feedback_5f4676f9).
1287
+ const platform = deps.platform ?? process.platform;
1288
+ if (platform === "win32") {
1289
+ return { detached: true, pid, method: "pid_alive_without_proc" };
1290
+ }
1282
1291
  const psProof = proveDetachedViaPs(pid);
1283
1292
  if (psProof)
1284
1293
  return psProof;
@@ -1831,7 +1840,8 @@ export function workerEnv(base, resolved, laneId, hqRoot, autoCompactTokens, mes
1831
1840
  if (!accepted.includes(resolved.envVar)) {
1832
1841
  throw new LanesError("unknown_provider_home_env", `Unknown provider home variable ${JSON.stringify(resolved.envVar)}. Accepted: ${accepted.join(", ")}`, { accepted, value: resolved.envVar });
1833
1842
  }
1834
- const env = { ...base };
1843
+ // Lane workers start without secret-bearing variables (worker-env-scrub.ts).
1844
+ const env = laneWorkerEnv(base);
1835
1845
  delete env.HQ_PROJECT_ID;
1836
1846
  delete env.HQ_STORY_ID;
1837
1847
  delete env.HQ_POLICY_WORKER_DIR;
@@ -2095,7 +2105,10 @@ function spawnTrackedWorker(spawnProcess, command, args, env, cwd, stdoutPath, s
2095
2105
  throw error;
2096
2106
  }
2097
2107
  const runnerPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../dist/lib/lanes/worker-process.js");
2098
- return spawnDetached(spawnProcess, liveNodeBinary(), [runnerPath, command, ...args], { ...env, [LANE_WORKER_EXIT_PATH_ENV]: exitPath }, cwd, stdoutPath, stderrPath);
2108
+ return spawnDetached(spawnProcess, liveNodeBinary(), [runnerPath, command, ...args],
2109
+ // workerEnv already scrubbed this env; filtering again here keeps every
2110
+ // worker spawn safe even for a caller that did not build it with workerEnv.
2111
+ { ...laneWorkerEnv(env), [LANE_WORKER_EXIT_PATH_ENV]: exitPath }, cwd, stdoutPath, stderrPath);
2099
2112
  }
2100
2113
  function requireDetached(proveDetached, pid, kind) {
2101
2114
  const proof = proveDetached(pid);
@@ -2231,7 +2244,10 @@ export function armLaneWatcher(hqRoot, laneId, deps = {}) {
2231
2244
  throw new LanesError("watcher_cli_entry_unavailable", "Cannot arm the lane watcher without the current hq CLI entrypoint", { lane_id: laneId });
2232
2245
  }
2233
2246
  const watcherPid = spawnDetached(spawnProcess, liveNodeBinary(), [watcherMainPath(), laneId], {
2234
- ...env,
2247
+ // The watcher lives as long as the lane and runs as the same user, so a
2248
+ // worker could read its process environment. It only runs `hq`, which
2249
+ // needs none of the removed variables (worker-env-scrub.ts).
2250
+ ...laneWorkerEnv(env),
2235
2251
  HQ_ROOT: hqRoot,
2236
2252
  HQ_LANE_ID: laneId,
2237
2253
  HQ_LANE_CLI_ENTRY: path.resolve(cliEntry),
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The environment a lane worker process starts with.
3
+ *
4
+ * A lane worker runs a model CLI (codex, claude, grok) whose tool output goes
5
+ * to that model's provider. A worker that lists processes with their
6
+ * environments, or runs `env`, sends every inherited variable there. On
7
+ * 2026-11-20 a Codex lane worker did that and the owner's GitHub CLI token
8
+ * (GH_TOKEN) went to the provider. Lane workers therefore start without
9
+ * secret-bearing variables; everything else passes through unchanged.
10
+ *
11
+ * Each runner signs in to its own model provider from files in its account
12
+ * home, not from an API-key variable: claude reads `.credentials.json` in
13
+ * CLAUDE_CONFIG_DIR (or the Keychain item for the default ~/.claude home),
14
+ * codex reads `auth.json` in CODEX_HOME, and grok reads `auth.json` in
15
+ * GROK_HOME (see PROVIDER_CREDENTIAL_FILES in accounts.ts). So no provider
16
+ * API key is kept.
17
+ *
18
+ * gh inside a lane still works: with GH_TOKEN and GITHUB_TOKEN unset, gh uses
19
+ * the credentials stored by `gh auth login` (the system keyring or
20
+ * hosts.yml), as `gh help environment` documents.
21
+ *
22
+ * This module imports nothing from the lanes package, so every spawn path
23
+ * (spawn.ts, worker-process.ts, remote-control-lane.ts) can use it without
24
+ * an import cycle.
25
+ */
26
+ /** Removed by exact name, whatever the patterns below say. */
27
+ export declare const LANE_WORKER_SECRET_ENV_NAMES: readonly string[];
28
+ /** Name patterns of secret-bearing variables. */
29
+ export declare const LANE_WORKER_SECRET_ENV_PATTERNS: readonly RegExp[];
30
+ /**
31
+ * Kept even when a name matches a pattern above. Each one is a path, a socket
32
+ * or an on/off flag, never a secret value, and a runner or a tool inside the
33
+ * lane needs it.
34
+ */
35
+ export declare const LANE_WORKER_ENV_ALLOWLIST: readonly string[];
36
+ /**
37
+ * True when a lane worker must not inherit this variable. `value` is
38
+ * optional; when given, a URL with a password in it is removed whatever the
39
+ * name.
40
+ */
41
+ export declare function isLaneWorkerSecretEnvName(name: string, value?: string): boolean;
42
+ /**
43
+ * A copy of `parentEnv` without secret-bearing variables. The input is not
44
+ * changed. Every lane worker spawn, and every long-lived helper a lane
45
+ * starts (watcher, loop controller), builds its environment through this.
46
+ */
47
+ export declare function laneWorkerEnv(parentEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
48
+ //# sourceMappingURL=worker-env-scrub.d.ts.map
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The environment a lane worker process starts with.
3
+ *
4
+ * A lane worker runs a model CLI (codex, claude, grok) whose tool output goes
5
+ * to that model's provider. A worker that lists processes with their
6
+ * environments, or runs `env`, sends every inherited variable there. On
7
+ * 2026-11-20 a Codex lane worker did that and the owner's GitHub CLI token
8
+ * (GH_TOKEN) went to the provider. Lane workers therefore start without
9
+ * secret-bearing variables; everything else passes through unchanged.
10
+ *
11
+ * Each runner signs in to its own model provider from files in its account
12
+ * home, not from an API-key variable: claude reads `.credentials.json` in
13
+ * CLAUDE_CONFIG_DIR (or the Keychain item for the default ~/.claude home),
14
+ * codex reads `auth.json` in CODEX_HOME, and grok reads `auth.json` in
15
+ * GROK_HOME (see PROVIDER_CREDENTIAL_FILES in accounts.ts). So no provider
16
+ * API key is kept.
17
+ *
18
+ * gh inside a lane still works: with GH_TOKEN and GITHUB_TOKEN unset, gh uses
19
+ * the credentials stored by `gh auth login` (the system keyring or
20
+ * hosts.yml), as `gh help environment` documents.
21
+ *
22
+ * This module imports nothing from the lanes package, so every spawn path
23
+ * (spawn.ts, worker-process.ts, remote-control-lane.ts) can use it without
24
+ * an import cycle.
25
+ */
26
+ /** Removed by exact name, whatever the patterns below say. */
27
+ export const LANE_WORKER_SECRET_ENV_NAMES = [
28
+ "GH_TOKEN",
29
+ "GITHUB_TOKEN",
30
+ "GH_ENTERPRISE_TOKEN",
31
+ "GITHUB_ENTERPRISE_TOKEN",
32
+ "AWS_ACCESS_KEY_ID",
33
+ "AWS_SECRET_ACCESS_KEY",
34
+ "AWS_SESSION_TOKEN",
35
+ "NPM_TOKEN",
36
+ "NODE_AUTH_TOKEN",
37
+ "ANTHROPIC_API_KEY",
38
+ "OPENAI_API_KEY",
39
+ "XAI_API_KEY",
40
+ ];
41
+ /** Name patterns of secret-bearing variables. */
42
+ export const LANE_WORKER_SECRET_ENV_PATTERNS = [
43
+ // Slack bot, user and app tokens, signing secrets and webhook URLs.
44
+ /^SLACK_/i,
45
+ /(TOKEN|SECRET|PASSWORD|PASSWD|PRIVATE_KEY|API_KEY|ACCESS_KEY|CREDENTIALS?)$/i,
46
+ /^(.*_)?(TOKEN|SECRET)(_.*)?$/i,
47
+ // Keys without the API_ prefix (STRIPE_KEY, AZURE_OPENAI_KEY, SST_KEY) and
48
+ // run-together names (SENDGRID_APIKEY).
49
+ /_KEY$/i,
50
+ /APIKEY$/i,
51
+ // Personal access tokens (GITLAB_PAT) and basic-auth values (NPM_CONFIG__AUTH).
52
+ /_PAT$/i,
53
+ /_AUTH$/i,
54
+ // 1Password CLI session tokens (OP_SESSION_<account>).
55
+ /^OP_SESSION_/i,
56
+ // Connection strings and URLs that usually carry a password or a key.
57
+ /^DATABASE_URL$/i,
58
+ /_DSN$/i,
59
+ /_WEBHOOK_URL$/i,
60
+ ];
61
+ /**
62
+ * A URL with a password in it (scheme://user:password@host), whatever the
63
+ * variable is called. REDIS_URL, MONGO_URI and the like are removed by value.
64
+ */
65
+ const URL_WITH_PASSWORD = /^[a-z][a-z0-9+.-]*:\/\/[^/\s:@]*:[^/\s@]+@/i;
66
+ /**
67
+ * A name ending in _FILE holds a file path, not a secret value: for example
68
+ * AWS_WEB_IDENTITY_TOKEN_FILE or HQ_TOKEN_FILE. The lane can read that file
69
+ * anyway, because the worker runs as the same user, so dropping the variable
70
+ * protects nothing and breaks tools that read it. These are kept unless the
71
+ * value itself is a URL with a password.
72
+ */
73
+ const PATH_NAME = /_FILE$/i;
74
+ /**
75
+ * Proxy settings (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY, NO_PROXY and their
76
+ * lowercase forms) are kept even when they hold user:password@. Without them a
77
+ * runner behind a proxy that needs a login cannot reach its model provider, so
78
+ * the lane has no network. (Remote Control lanes still drop them later on
79
+ * purpose; see configureRemoteControlChildEnv.)
80
+ */
81
+ const PROXY_NAME = /_PROXY$/i;
82
+ /**
83
+ * Kept even when a name matches a pattern above. Each one is a path, a socket
84
+ * or an on/off flag, never a secret value, and a runner or a tool inside the
85
+ * lane needs it.
86
+ */
87
+ export const LANE_WORKER_ENV_ALLOWLIST = [
88
+ // Codex account home: holds the account's auth.json, the codex sign-in.
89
+ "CODEX_HOME",
90
+ // Claude account home: holds .credentials.json, the claude sign-in.
91
+ "CLAUDE_CONFIG_DIR",
92
+ // Grok account home: holds auth.json, the grok sign-in.
93
+ "GROK_HOME",
94
+ // Path to the HQ token file that `hq` commands in the lane read; a path, not the token.
95
+ "HQ_TOKEN_FILE",
96
+ // Directory where hq keeps machine token state; a path, not a token.
97
+ "HQ_MACHINE_TOKEN_STATE_DIR",
98
+ // ssh-agent socket path: git over SSH in the lane signs through the agent; no key material.
99
+ "SSH_AUTH_SOCK",
100
+ // On/off flag (src/utils/token-keychain.ts) that tells `hq` whether to read
101
+ // its token from the Keychain. Dropping it sends `hq` in a lane back to the
102
+ // Keychain, which can stall a detached process on a prompt.
103
+ "HQ_TOKEN_KEYCHAIN",
104
+ // Path to a Google service-account key file, not the key itself (see the
105
+ // _FILE note above: the file stays readable to the same user either way).
106
+ "GOOGLE_APPLICATION_CREDENTIALS",
107
+ // Public key hq uses to verify pack signatures; public by design.
108
+ "HQ_PACK_PUBLIC_KEY",
109
+ // Path override for the Codex auth.json that `hq core job probe` checks
110
+ // (src/commands/core-job-probe-native.ts); a path, not the auth file's contents.
111
+ "HQ_JOB_PROBE_CODEX_AUTH",
112
+ ];
113
+ const ALLOWED = new Set(LANE_WORKER_ENV_ALLOWLIST);
114
+ const SECRET_NAMES = new Set(LANE_WORKER_SECRET_ENV_NAMES);
115
+ /**
116
+ * True when a lane worker must not inherit this variable. `value` is
117
+ * optional; when given, a URL with a password in it is removed whatever the
118
+ * name.
119
+ */
120
+ export function isLaneWorkerSecretEnvName(name, value) {
121
+ if (ALLOWED.has(name))
122
+ return false;
123
+ if (PROXY_NAME.test(name))
124
+ return false;
125
+ if (value !== undefined && URL_WITH_PASSWORD.test(value.trim()))
126
+ return true;
127
+ if (SECRET_NAMES.has(name.toUpperCase()))
128
+ return true;
129
+ if (PATH_NAME.test(name))
130
+ return false;
131
+ return LANE_WORKER_SECRET_ENV_PATTERNS.some((pattern) => pattern.test(name));
132
+ }
133
+ /**
134
+ * A copy of `parentEnv` without secret-bearing variables. The input is not
135
+ * changed. Every lane worker spawn, and every long-lived helper a lane
136
+ * starts (watcher, loop controller), builds its environment through this.
137
+ */
138
+ export function laneWorkerEnv(parentEnv) {
139
+ const env = {};
140
+ for (const [name, value] of Object.entries(parentEnv)) {
141
+ if (!isLaneWorkerSecretEnvName(name, value))
142
+ env[name] = value;
143
+ }
144
+ return env;
145
+ }
146
+ //# sourceMappingURL=worker-env-scrub.js.map