@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
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Where hq-core lives. Every hq-cli call site that reads hq-core releases,
3
+ * tags, contents or clone URLs gets the address from here.
4
+ *
5
+ * Lookup order:
6
+ * 1. `HQ_CORE_SOURCE` env var (a JSON object).
7
+ * 2. `~/.hq/core-source.json` (same JSON shape), only when the env var is unset.
8
+ * 3. Built-in GitHub defaults.
9
+ *
10
+ * Every key is optional; a missing or invalid key keeps its GitHub default.
11
+ * Invalid JSON or an invalid field prints one warning to stderr naming
12
+ * `HQ_CORE_SOURCE` and never throws.
13
+ */
14
+ import * as fs from 'node:fs';
15
+ import * as os from 'node:os';
16
+ import * as path from 'node:path';
17
+ export const DEFAULT_HQ_CORE_SOURCE = Object.freeze({
18
+ repo: 'indigoai-us/hq-core',
19
+ stagingRepo: 'indigoai-us/hq-core-staging',
20
+ apiBase: 'https://api.github.com',
21
+ codeloadBase: 'https://codeload.github.com',
22
+ webBase: 'https://github.com',
23
+ });
24
+ export const HQ_CORE_SOURCE_ENV = 'HQ_CORE_SOURCE';
25
+ const REPO_KEYS = ['repo', 'stagingRepo'];
26
+ const BASE_KEYS = ['apiBase', 'codeloadBase', 'webBase'];
27
+ const REPO_PATTERN = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
28
+ const GITHUB_HOSTS = new Set(['github.com', 'api.github.com', 'codeload.github.com']);
29
+ const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1']);
30
+ export function hqCoreSourceFile(homeDir = os.homedir()) {
31
+ return path.join(homeDir, '.hq', 'core-source.json');
32
+ }
33
+ const warnedMessages = new Set();
34
+ function defaultWarn(message) {
35
+ // One line per distinct problem per process, so a bad value does not repeat
36
+ // on every lookup a single command makes.
37
+ if (warnedMessages.has(message))
38
+ return;
39
+ warnedMessages.add(message);
40
+ process.stderr.write(`${message}\n`);
41
+ }
42
+ function normalizeBase(value) {
43
+ if (typeof value !== 'string')
44
+ return undefined;
45
+ let url;
46
+ try {
47
+ url = new URL(value.trim());
48
+ }
49
+ catch {
50
+ return undefined;
51
+ }
52
+ if (url.username || url.password || url.search || url.hash)
53
+ return undefined;
54
+ const secure = url.protocol === 'https:';
55
+ const local = url.protocol === 'http:' && LOCAL_HOSTS.has(url.hostname);
56
+ if (!secure && !local)
57
+ return undefined;
58
+ return `${url.origin}${url.pathname}`.replace(/\/+$/, '');
59
+ }
60
+ /** Parse one JSON value into a full source, collecting the names of bad fields. */
61
+ function parseSource(raw) {
62
+ const source = { ...DEFAULT_HQ_CORE_SOURCE };
63
+ let parsed;
64
+ try {
65
+ parsed = JSON.parse(raw);
66
+ }
67
+ catch {
68
+ return { source, problems: ['invalid JSON'] };
69
+ }
70
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
71
+ return { source, problems: ['not a JSON object'] };
72
+ }
73
+ const obj = parsed;
74
+ const problems = [];
75
+ for (const key of REPO_KEYS) {
76
+ if (obj[key] === undefined)
77
+ continue;
78
+ const value = typeof obj[key] === 'string' ? obj[key].trim() : undefined;
79
+ if (value && REPO_PATTERN.test(value))
80
+ source[key] = value;
81
+ else
82
+ problems.push(`${key} must be owner/name`);
83
+ }
84
+ for (const key of BASE_KEYS) {
85
+ if (obj[key] === undefined)
86
+ continue;
87
+ const value = normalizeBase(obj[key]);
88
+ if (value)
89
+ source[key] = value;
90
+ else
91
+ problems.push(`${key} must be an https:// URL (http:// only for localhost)`);
92
+ }
93
+ return { source, problems };
94
+ }
95
+ /** Resolve the hq-core source address. Never throws. */
96
+ export function resolveHqCoreSource(options = {}) {
97
+ const env = options.env ?? process.env;
98
+ const warn = options.warn ?? defaultWarn;
99
+ const fromEnv = env[HQ_CORE_SOURCE_ENV];
100
+ if (fromEnv !== undefined && fromEnv.trim() !== '') {
101
+ const { source, problems } = parseSource(fromEnv);
102
+ if (problems.length > 0) {
103
+ warn(`${HQ_CORE_SOURCE_ENV}: ${problems.join('; ')}. Using the GitHub default for the bad field(s).`);
104
+ }
105
+ return source;
106
+ }
107
+ let file;
108
+ try {
109
+ file = hqCoreSourceFile(options.homeDir);
110
+ }
111
+ catch {
112
+ return { ...DEFAULT_HQ_CORE_SOURCE };
113
+ }
114
+ let raw;
115
+ try {
116
+ raw = fs.readFileSync(file, 'utf8');
117
+ }
118
+ catch {
119
+ return { ...DEFAULT_HQ_CORE_SOURCE };
120
+ }
121
+ const { source, problems } = parseSource(raw);
122
+ if (problems.length > 0) {
123
+ warn(`${HQ_CORE_SOURCE_ENV} (${file}): ${problems.join('; ')}. Using the GitHub default for the bad field(s).`);
124
+ }
125
+ return source;
126
+ }
127
+ /** True when `url` targets github.com, api.github.com or codeload.github.com over https. */
128
+ export function isGitHubHost(url) {
129
+ try {
130
+ const parsed = new URL(url);
131
+ return parsed.protocol === 'https:' && GITHUB_HOSTS.has(parsed.hostname.toLowerCase());
132
+ }
133
+ catch {
134
+ return false;
135
+ }
136
+ }
137
+ /**
138
+ * The GitHub token to send to `url`, or undefined. A GitHub token is never
139
+ * forwarded to an overridden non-GitHub host.
140
+ */
141
+ export function githubTokenFor(url, token) {
142
+ return token && isGitHubHost(url) ? token : undefined;
143
+ }
144
+ //# sourceMappingURL=hq-core-source.js.map
@@ -2,6 +2,12 @@
2
2
  export declare const HQ_NO_BROWSER_LOGIN_ENV = "HQ_NO_BROWSER_LOGIN";
3
3
  /** Remedy printed when an implicit sign-in is refused. */
4
4
  export declare const NON_INTERACTIVE_LOGIN_MESSAGE: string;
5
+ /**
6
+ * True when `error` is the refusal above: no usable HQ session in a process
7
+ * that may not open a browser sign-in. Background callers treat it as
8
+ * "signed out" (an expected state), not as a failure.
9
+ */
10
+ export declare function isNonInteractiveLoginError(error: unknown): boolean;
5
11
  export type InteractiveCallerInput = {
6
12
  env?: NodeJS.ProcessEnv;
7
13
  argv?: readonly string[];
@@ -15,6 +15,14 @@ export const HQ_NO_BROWSER_LOGIN_ENV = "HQ_NO_BROWSER_LOGIN";
15
15
  /** Remedy printed when an implicit sign-in is refused. */
16
16
  export const NON_INTERACTIVE_LOGIN_MESSAGE = "No valid HQ session and interactive login is disabled. Run `hq login` first. " +
17
17
  "This process is not interactive (no terminal, or a background HQ runtime), so it did not open a browser sign-in.";
18
+ /**
19
+ * True when `error` is the refusal above: no usable HQ session in a process
20
+ * that may not open a browser sign-in. Background callers treat it as
21
+ * "signed out" (an expected state), not as a failure.
22
+ */
23
+ export function isNonInteractiveLoginError(error) {
24
+ return error instanceof Error && error.message.startsWith(NON_INTERACTIVE_LOGIN_MESSAGE);
25
+ }
18
26
  /** launchd job labels the HQ service manager installs (see main.ts runCli). */
19
27
  const HQ_LAUNCHD_LABEL_PREFIXES = ["ai.indigo.", "ai.getindigo."];
20
28
  /** Env markers set for background HQ runtimes. Any non-empty value counts. */
@@ -1,12 +1,14 @@
1
1
  import type { ShippedCodexHookFiles } from './hook-trust.js';
2
- /** The only repos rescue installs core from: the default and `--staging`. */
3
- export declare const PROD_SOURCE = "indigoai-us/hq-core";
4
- export declare const STAGING_SOURCE = "indigoai-us/hq-core-staging";
2
+ /** The hq-core repos and API base the re-trust reads from: the built-in defaults only. */
3
+ export declare const TRUSTED_CORE_SOURCE: Readonly<{
4
+ repos: readonly string[];
5
+ apiBase: string;
6
+ }>;
5
7
  /** Resolve a GitHub token: prefer `gh auth token`, fall back to env. */
6
8
  export declare function resolveGhToken(): string | undefined;
7
9
  /**
8
10
  * The upstream repo and commit the last rescue installed, from `core/core.yaml`.
9
- * Only the HQ core repos are accepted.
11
+ * Only the built-in HQ core repos (prod and staging) are accepted.
10
12
  */
11
13
  export declare function readCoreSyncStamp(hqRoot: string): {
12
14
  source: string;
@@ -6,15 +6,23 @@
6
6
  * The commit comes from the sync stamp rescue writes to `core/core.yaml`
7
7
  * (`replaced_from_source.source` + `last_sync_sha`); the files come from the
8
8
  * GitHub contents API for that repo and commit.
9
+ *
10
+ * Trust source. Which hooks count as core-shipped is a trust decision, so the
11
+ * repos and API base used here are the built-in defaults
12
+ * ({@link TRUSTED_CORE_SOURCE}), never HQ_CORE_SOURCE or
13
+ * ~/.hq/core-source.json. A rescue from an overridden source still installs
14
+ * core; its hooks are just not re-trusted automatically.
9
15
  */
10
16
  import { spawnSync } from 'child_process';
11
17
  import * as fs from 'fs';
12
18
  import * as path from 'path';
13
19
  import * as yaml from 'js-yaml';
14
- /** The only repos rescue installs core from: the default and `--staging`. */
15
- export const PROD_SOURCE = 'indigoai-us/hq-core';
16
- export const STAGING_SOURCE = 'indigoai-us/hq-core-staging';
17
- const CORE_SOURCES = [PROD_SOURCE, STAGING_SOURCE];
20
+ import { DEFAULT_HQ_CORE_SOURCE, githubTokenFor } from './hq-core-source.js';
21
+ /** The hq-core repos and API base the re-trust reads from: the built-in defaults only. */
22
+ export const TRUSTED_CORE_SOURCE = Object.freeze({
23
+ repos: Object.freeze([DEFAULT_HQ_CORE_SOURCE.repo, DEFAULT_HQ_CORE_SOURCE.stagingRepo]),
24
+ apiBase: DEFAULT_HQ_CORE_SOURCE.apiBase,
25
+ });
18
26
  /** Resolve a GitHub token: prefer `gh auth token`, fall back to env. */
19
27
  export function resolveGhToken() {
20
28
  try {
@@ -32,7 +40,7 @@ export function resolveGhToken() {
32
40
  }
33
41
  /**
34
42
  * The upstream repo and commit the last rescue installed, from `core/core.yaml`.
35
- * Only the HQ core repos are accepted.
43
+ * Only the built-in HQ core repos (prod and staging) are accepted.
36
44
  */
37
45
  export function readCoreSyncStamp(hqRoot) {
38
46
  const file = path.join(hqRoot, 'core', 'core.yaml');
@@ -45,6 +53,8 @@ export function readCoreSyncStamp(hqRoot) {
45
53
  }
46
54
  // Anyone who can edit core.yaml could otherwise point the comparison (and
47
55
  // the GitHub token) at a repo of their own and make a foreign hook "shipped".
56
+ // The list is the built-in one, so a user-writable source config cannot add to it.
57
+ const CORE_SOURCES = TRUSTED_CORE_SOURCE.repos;
48
58
  if (!CORE_SOURCES.includes(source)) {
49
59
  throw new Error(`core/core.yaml names ${source}, which is not an HQ core repo (${CORE_SOURCES.join(' or ')})`);
50
60
  }
@@ -56,15 +66,16 @@ export function readCoreSyncStamp(hqRoot) {
56
66
  // Same bound as rescue's own GitHub requests.
57
67
  const GITHUB_REQUEST_TIMEOUT_MS = 30_000;
58
68
  /** One file's raw text at `sha`, or undefined when the commit has no such file. */
59
- async function fetchRawFile(repo, sha, file, token, fetchImpl) {
69
+ async function fetchRawFile(apiBase, repo, sha, file, token, fetchImpl) {
60
70
  const headers = {
61
71
  Accept: 'application/vnd.github.raw',
62
72
  'User-Agent': 'hq-cli-rescue',
63
73
  'X-GitHub-Api-Version': '2022-11-28',
64
74
  };
65
- if (token)
66
- headers.Authorization = `Bearer ${token}`;
67
- const url = `https://api.github.com/repos/${repo}/contents/${file}?ref=${sha}`;
75
+ const url = `${apiBase}/repos/${repo}/contents/${file}?ref=${sha}`;
76
+ const auth = githubTokenFor(url, token);
77
+ if (auth)
78
+ headers.Authorization = 'Bearer ' + auth;
68
79
  const response = await fetchImpl(url, { headers, signal: AbortSignal.timeout(GITHUB_REQUEST_TIMEOUT_MS) });
69
80
  if (response.status === 404)
70
81
  return undefined;
@@ -75,9 +86,10 @@ async function fetchRawFile(repo, sha, file, token, fetchImpl) {
75
86
  /** The shipped `.codex/config.toml` and `.codex/hooks.json` for this HQ root's installed core. */
76
87
  export async function loadShippedCodexHookFiles(hqRoot, token = resolveGhToken(), fetchImpl = fetch) {
77
88
  const { source, sha } = readCoreSyncStamp(hqRoot);
89
+ const { apiBase } = TRUSTED_CORE_SOURCE;
78
90
  const shipped = {};
79
91
  for (const name of ['config.toml', 'hooks.json']) {
80
- const text = await fetchRawFile(source, sha, `.codex/${name}`, token, fetchImpl);
92
+ const text = await fetchRawFile(apiBase, source, sha, `.codex/${name}`, token, fetchImpl);
81
93
  if (text !== undefined)
82
94
  shipped[name] = text;
83
95
  }
@@ -284,6 +284,7 @@ export async function vaultApiFetch(opts) {
284
284
  // skew on EVERY authenticated request, not only health heartbeats.
285
285
  // Fixed build constant, never caller-supplied; attribution only.
286
286
  'x-hq-client-version': CLI_VERSION,
287
+ 'User-Agent': `hq-cli/${CLI_VERSION}`,
287
288
  ...opts.headers,
288
289
  },
289
290
  body: opts.body ? JSON.stringify(opts.body) : undefined,
@@ -1,5 +1,7 @@
1
1
  import { type GitHubLookupDeps } from "./github-tag-fallback.js";
2
- export declare const HQ_CORE_LATEST_URL = "https://api.github.com/repos/indigoai-us/hq-core/releases/latest";
2
+ import { type HqCoreSource } from "./hq-core-source.js";
3
+ /** The latest-release API URL for the HQ_CORE_SOURCE prod repo. */
4
+ export declare function hqCoreLatestUrl(source?: HqCoreSource): string;
3
5
  export declare const LATEST_FETCH_TIMEOUT_MS = 3000;
4
6
  export type LatestLookup = "ok" | "network-error";
5
7
  export interface VersionReport {
@@ -15,13 +15,21 @@ import { findHqRoot } from "./manifest.js";
15
15
  import { readHqVersion } from "./hq-core-yaml.js";
16
16
  import { resolveGhToken } from "./shipped-codex-hooks.js";
17
17
  import { GitHubApiUnavailable, isTransientGitHubStatus, withGitTagFallback } from "./github-tag-fallback.js";
18
- export const HQ_CORE_LATEST_URL = "https://api.github.com/repos/indigoai-us/hq-core/releases/latest";
18
+ import { githubTokenFor, resolveHqCoreSource } from "./hq-core-source.js";
19
+ /** The latest-release API URL for the HQ_CORE_SOURCE prod repo. */
20
+ export function hqCoreLatestUrl(source = resolveHqCoreSource()) {
21
+ return `${source.apiBase}/repos/${source.repo}/releases/latest`;
22
+ }
19
23
  export const LATEST_FETCH_TIMEOUT_MS = 3_000;
20
24
  export function normalizeHqCoreTag(tag) {
21
25
  const version = tag.trim().replace(/^v/i, "");
22
26
  return semver.valid(version) ? version : null;
23
27
  }
24
28
  export async function fetchLatestHqCoreRelease(fetchImpl = fetch, timeoutMs = LATEST_FETCH_TIMEOUT_MS, token = resolveGhToken(), deps = {}) {
29
+ const source = resolveHqCoreSource();
30
+ const latestUrl = hqCoreLatestUrl(source);
31
+ // Never forward a GitHub token to an overridden non-GitHub host.
32
+ token = githubTokenFor(latestUrl, token);
25
33
  try {
26
34
  return await withGitTagFallback(async () => {
27
35
  try {
@@ -32,7 +40,7 @@ export async function fetchLatestHqCoreRelease(fetchImpl = fetch, timeoutMs = LA
32
40
  };
33
41
  if (token)
34
42
  headers.Authorization = `Bearer ${token}`;
35
- let res = await fetchImpl(HQ_CORE_LATEST_URL, {
43
+ let res = await fetchImpl(latestUrl, {
36
44
  headers,
37
45
  signal: AbortSignal.timeout(timeoutMs),
38
46
  });
@@ -40,13 +48,13 @@ export async function fetchLatestHqCoreRelease(fetchImpl = fetch, timeoutMs = LA
40
48
  // lookup that used to work.
41
49
  if (token && (res.status === 401 || res.status === 403)) {
42
50
  const { Authorization: _drop, ...anonHeaders } = headers;
43
- res = await fetchImpl(HQ_CORE_LATEST_URL, {
51
+ res = await fetchImpl(latestUrl, {
44
52
  headers: anonHeaders,
45
53
  signal: AbortSignal.timeout(timeoutMs),
46
54
  });
47
55
  }
48
56
  if (isTransientGitHubStatus(res.status)) {
49
- throw new GitHubApiUnavailable(`GitHub releases/latest for indigoai-us/hq-core: HTTP ${res.status}`);
57
+ throw new GitHubApiUnavailable(`GitHub releases/latest for ${source.repo}: HTTP ${res.status}`);
50
58
  }
51
59
  if (!res.ok)
52
60
  return null;
@@ -60,7 +68,7 @@ export async function fetchLatestHqCoreRelease(fetchImpl = fetch, timeoutMs = LA
60
68
  throw error;
61
69
  throw new GitHubApiUnavailable('GitHub release request failed on the network or timed out', { cause: error });
62
70
  }
63
- }, 'indigoai-us/hq-core', undefined, normalizeHqCoreTag, { ...deps, fetchImpl });
71
+ }, source.repo, undefined, normalizeHqCoreTag, { webBase: source.webBase, ...deps, fetchImpl });
64
72
  }
65
73
  catch {
66
74
  return null;
@@ -11,10 +11,10 @@ archived, or unreadable. An explicit registry false or the local
11
11
  requires the current person to enable the `hq-anywhere` setting in HQ. If that
12
12
  setting cannot be read, runtime access stays off.
13
13
 
14
- Work Mesh reporting of company work is the exception. The person's setting and
14
+ Work Mesh reporting of company work is the exception only when `work-mesh-company-reporting-required` is confirmed on in the bound company's fresh HQ flag snapshot. Otherwise the member's switch wins. While that flag is confirmed on, the person's setting and
15
15
  the local `HQ_FLAG_HQ_ANYWHERE_RUNTIME=false|0` override do not stop Work Mesh
16
16
  events of a session with a verified company binding; only the operator's
17
- registry switch does. See "Company work has no member off switch" in
17
+ registry switch does. See "Company reporting enforcement flag" in
18
18
  [work-context-cli.md](work-context-cli.md).
19
19
 
20
20
  ## Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.245",
3
+ "version": "5.345.247",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -63,7 +63,7 @@
63
63
  "@aws-sdk/client-iot-data-plane": "^3.1096.0",
64
64
  "@aws-sdk/client-s3": "^3.1049.0",
65
65
  "@aws-sdk/dsql-signer": "^3.1146.0",
66
- "@indigoai-us/hq-cloud": "6.18.120",
66
+ "@indigoai-us/hq-cloud": "6.18.121",
67
67
  "@indigoai-us/hq-flags-client": "^0.2.0",
68
68
  "@modelcontextprotocol/sdk": "1.32.2",
69
69
  "@sentry/node": "^10.49.0",
@@ -126,11 +126,11 @@
126
126
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
127
127
  },
128
128
  "optionalDependencies": {
129
- "@indigoai-us/hq-hook-win32-x64": "5.345.245",
130
- "@indigoai-us/hq-hook-win32-arm64": "5.345.245",
131
- "@indigoai-us/hq-hook-darwin-x64": "5.345.245",
132
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.245",
133
- "@indigoai-us/hq-hook-linux-x64": "5.345.245",
134
- "@indigoai-us/hq-hook-linux-arm64": "5.345.245"
129
+ "@indigoai-us/hq-hook-win32-x64": "5.345.247",
130
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.247",
131
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.247",
132
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.247",
133
+ "@indigoai-us/hq-hook-linux-x64": "5.345.247",
134
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.247"
135
135
  }
136
136
  }
@@ -42,12 +42,29 @@
42
42
  // the release leaves out (* within a folder, ** across
43
43
  // folders, ?). Repeatable; none are built in
44
44
  // --json print the result as JSON
45
- // --max-seconds <n> time limit for the whole run (default 10). A run that
46
- // takes n seconds or longer fails (rule time-budget),
47
- // so the check stays fast enough to run locally
45
+ // --max-work <name>=<n> set one work limit (see "Work budget" below).
46
+ // Repeatable
47
+ // --max-seconds <n> also fail a run that takes n seconds or longer of
48
+ // wall time (rule time-budget). Off unless given. For a
49
+ // local timing check only: wall time depends on how
50
+ // busy the machine is, so CI never passes it
48
51
  //
49
52
  // Exit 0: no problem. Exit 1: at least one problem. Exit 2: usage error.
50
53
  //
54
+ // Work budget
55
+ // The check has to run locally in under 10 seconds (hq-core-rust US-003).
56
+ // Wall time on a shared CI machine depends on its load, so the check counts
57
+ // the work it does instead and fails (rule work-budget) when a count goes
58
+ // over its limit in WORK_LIMITS:
59
+ // subprocesses git and pwd processes started
60
+ // filesListed paths listed from git or a folder walk
61
+ // filesRead files read
62
+ // bytesRead bytes read from those files
63
+ // needleScans file x reference-target pairs searched for a needle
64
+ // lineChecks line x reference-target pairs run through a matcher
65
+ // The counts are the same on every machine and under any load. How the
66
+ // limits were set is in the comment on WORK_LIMITS.
67
+ //
51
68
  // Trees covered by the "exists on disk" rule
52
69
  // hq-core-staging: .claude/hooks, core/hooks, .codex/hooks, .grok/hooks (kind
53
70
  // hook) and core/scripts (kind script). Test folders (tests, __tests__,
@@ -131,8 +148,54 @@ const DOC_EXT_RE = /\.(md|mdx|mdc|txt|rst|html?)$/i;
131
148
  const COMMENT_RE = /^\s*(#(?!!)|\/\/|\/\*|\*(\s|$)|<!--|rem\s|::\s)/i;
132
149
  const SCRIPT_NAME_RE = /\.(sh|bash|mjs|cjs|js|py|ps1|cmd|awk)$/;
133
150
  const MAX_FILE_BYTES = 2_000_000;
134
- // The check has to run locally in under this many seconds.
135
- const DEFAULT_MAX_SECONDS = 10;
151
+ // Work limits (rule work-budget). They replace a 10 s wall-clock limit that
152
+ // failed on a busy shared CI machine (12.9 s on a loaded MBP5, 2026-11-21) for
153
+ // a run that passes in a few seconds on an idle one.
154
+ // The CI command (--cli-root . --manifest scripts/function-manifest.yaml
155
+ // --cli-states ... --require-cli-states) counted the same on the light Mac
156
+ // pool and on EC2 (draft run 44873969164, hq-cli 943393d0 plus this change):
157
+ // subprocesses 6, filesListed 20,507, filesRead 2,052, bytesRead 35.8 MB,
158
+ // needleScans 151,552, lineChecks 24.1 million.
159
+ // That run took 2.5 s on EC2 and 10.2 s on the busy light pool. At 2.5 s, 10 s
160
+ // is 4 times the work, so each limit is about 4 times its CI count: if one kind
161
+ // of work grows that much, the run reaches about 10 s on EC2. lineChecks is
162
+ // most of the run time (command targets search every line holding "hq").
163
+ // A local run with --core-root (hq-core-staging 412b358b5) and --cli-root
164
+ // counts subprocesses 12, filesListed 24,638, filesRead 3,632, bytesRead
165
+ // 50.6 MB, needleScans 264,844, lineChecks 30.3 million: under every limit.
166
+ export const WORK_LIMITS = Object.freeze({
167
+ subprocesses: 24,
168
+ filesListed: 82_000,
169
+ filesRead: 8_200,
170
+ bytesRead: 143_000_000,
171
+ needleScans: 606_000,
172
+ lineChecks: 96_500_000,
173
+ });
174
+ const WORK_KEYS = Object.keys(WORK_LIMITS);
175
+
176
+ // ---------- work counter ----------
177
+ // Every subprocess, listed path, file read and matcher call is counted here,
178
+ // so `work` holds the whole cost of a run.
179
+ let work = newWork();
180
+ function newWork() { return Object.fromEntries(WORK_KEYS.map((k) => [k, 0])); }
181
+ function runCommand(cmd, args, opts) {
182
+ work.subprocesses++;
183
+ return execFileSync(cmd, args, opts);
184
+ }
185
+ function readText(file) {
186
+ const buf = readFileSync(file);
187
+ work.filesRead++;
188
+ work.bytesRead += buf.length;
189
+ return buf.toString("utf8");
190
+ }
191
+ /** Work counts over their limits, as work-budget problems. */
192
+ export function checkWork(counts, limits = WORK_LIMITS) {
193
+ const problems = [];
194
+ for (const k of WORK_KEYS) {
195
+ if (counts[k] > limits[k]) problems.push({ rule: "work-budget", counter: k, count: counts[k], limit: limits[k], message: `the check did too much work: ${k} is ${counts[k]}, over its limit of ${limits[k]} (WORK_LIMITS in scripts/check-function-manifest.mjs). The limits keep the check under 10 s on a developer Mac; find what made it do more work before raising one` });
196
+ }
197
+ return problems;
198
+ }
136
199
 
137
200
  // ---------- small helpers ----------
138
201
  const posix = (p) => p.split(path.sep).join("/");
@@ -140,14 +203,14 @@ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
140
203
 
141
204
  function isGitRoot(root) {
142
205
  try {
143
- const top = execFileSync("git", ["-C", root, "rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
206
+ const top = runCommand("git", ["-C", root, "rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
144
207
  return path.resolve(top) === path.resolve(statSync(root).isDirectory() ? realPath(root) : root);
145
208
  } catch {
146
209
  return false;
147
210
  }
148
211
  }
149
212
  function realPath(p) {
150
- try { return execFileSync("pwd", ["-P"], { cwd: p, encoding: "utf8" }).trim(); } catch { return path.resolve(p); }
213
+ try { return runCommand("pwd", ["-P"], { cwd: p, encoding: "utf8" }).trim(); } catch { return path.resolve(p); }
151
214
  }
152
215
 
153
216
  /** Files under `dirs` (repo-relative, forward slashes) that exist on disk. */
@@ -157,12 +220,15 @@ function listFiles(root, dirs) {
157
220
  if (isGitRoot(root)) {
158
221
  // Tracked files plus new files that are not ignored, so a file added and
159
222
  // not yet committed is seen. A file deleted in the work tree is dropped.
160
- const out = execFileSync("git", ["-C", root, "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...present], { encoding: "utf8", maxBuffer: 512 * 1024 * 1024 });
161
- return [...new Set(out.split("\0").filter(Boolean))].filter((f) => !SKIP_DIR_RE.test(f) && existsSync(path.join(root, f)));
223
+ const out = runCommand("git", ["-C", root, "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...present], { encoding: "utf8", maxBuffer: 512 * 1024 * 1024 });
224
+ const listed = out.split("\0").filter(Boolean);
225
+ work.filesListed += listed.length;
226
+ return [...new Set(listed)].filter((f) => !SKIP_DIR_RE.test(f) && existsSync(path.join(root, f)));
162
227
  }
163
228
  const found = [];
164
229
  const walk = (rel) => {
165
230
  for (const entry of readdirSync(path.join(root, rel), { withFileTypes: true })) {
231
+ work.filesListed++;
166
232
  const child = rel === "." ? entry.name : `${rel}/${entry.name}`;
167
233
  if (SKIP_DIR_RE.test(child)) continue;
168
234
  if (entry.isDirectory()) walk(child);
@@ -305,7 +371,7 @@ function flattenCatalog(nodes, prefix = [], aliases = new Map(), out = []) {
305
371
  function readSourceCatalog(cliRoot) {
306
372
  const file = path.join(cliRoot, "src/command-catalog.generated.ts");
307
373
  if (!existsSync(file)) return null;
308
- const text = readFileSync(file, "utf8");
374
+ const text = readText(file);
309
375
  const marker = "export const COMMAND_CATALOG = ";
310
376
  const start = text.indexOf(marker);
311
377
  const end = text.lastIndexOf("] as const");
@@ -315,6 +381,8 @@ function readSourceCatalog(cliRoot) {
315
381
  async function readPackageCatalog(pkgRoot) {
316
382
  const file = path.join(pkgRoot, "dist/command-catalog.generated.js");
317
383
  if (!existsSync(file)) return null;
384
+ work.filesRead++;
385
+ work.bytesRead += statSync(file).size;
318
386
  const mod = await import(pathToFileURL(file).href);
319
387
  return flattenCatalog(mod.COMMAND_CATALOG);
320
388
  }
@@ -359,6 +427,7 @@ export function checkCliPackage(entries, pkgRoot, catalog) {
359
427
  const built = [];
360
428
  const walk = (abs) => {
361
429
  for (const entry of readdirSync(abs, { withFileTypes: true })) {
430
+ work.filesListed++;
362
431
  const child = path.join(abs, entry.name);
363
432
  if (entry.isDirectory()) walk(child);
364
433
  else if (entry.isFile()) built.push(posix(path.relative(pkgRoot, child)));
@@ -495,9 +564,10 @@ export function findReferences(targets, root, { allFiles, manifest } = {}) {
495
564
  let stat;
496
565
  try { stat = statSync(path.join(root, file)); } catch { continue; }
497
566
  if (!stat.isFile() || stat.size > MAX_FILE_BYTES) continue;
498
- const body = readFileSync(path.join(root, file), "utf8");
567
+ const body = readText(path.join(root, file));
499
568
  if (body.includes("\u0000")) continue;
500
569
  scanned++;
570
+ work.needleScans += targets.length;
501
571
  const live = targets.filter((t) => t.needles.some((n) => body.includes(n)));
502
572
  if (!live.length) continue;
503
573
  const isDoc = DOC_EXT_RE.test(file);
@@ -511,6 +581,7 @@ export function findReferences(targets, root, { allFiles, manifest } = {}) {
511
581
  const text = lines[i];
512
582
  if (text.length > 6000) continue;
513
583
  if (!isDoc && COMMENT_RE.test(text)) continue;
584
+ work.lineChecks++;
514
585
  const how = t.match(text, file);
515
586
  if (!how) continue;
516
587
  problems.push({
@@ -560,7 +631,7 @@ function referenceTargets(entries, aliases) {
560
631
  export function readCliStates(file) {
561
632
  if (!existsSync(file)) return { missing: true };
562
633
  let data;
563
- try { data = JSON.parse(readFileSync(file, "utf8")); } catch (err) { return { problems: [{ rule: "cli-states", message: `${file} is not JSON: ${err.message}` }] }; }
634
+ try { data = JSON.parse(readText(file)); } catch (err) { return { problems: [{ rule: "cli-states", message: `${file} is not JSON: ${err.message}` }] }; }
564
635
  const problems = [];
565
636
  if (data?.schema !== 1) problems.push({ rule: "cli-states", message: `${file}: schema must be 1` });
566
637
  const commands = data?.commands;
@@ -642,6 +713,7 @@ export function checkInstalledCore(root, { keep = [], tooling = [] } = {}) {
642
713
  const entries = readdirSync(rel ? path.join(root, rel) : root, { withFileTypes: true });
643
714
  entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
644
715
  for (const entry of entries) {
716
+ work.filesListed++;
645
717
  const child = rel ? `${rel}/${entry.name}` : entry.name;
646
718
  // Dirent types come from lstat: a symlink is never a directory here.
647
719
  if (entry.isDirectory()) {
@@ -666,12 +738,12 @@ export function checkInstalledCore(root, { keep = [], tooling = [] } = {}) {
666
738
 
667
739
  function readKeepFile(file) {
668
740
  if (!existsSync(file)) usage(`--keep-file ${file} does not exist`);
669
- return readFileSync(file, "utf8").split("\n").map((l) => l.replace(/\r$/, "").trim()).filter((l) => l && !l.startsWith("#"));
741
+ return readText(file).split("\n").map((l) => l.replace(/\r$/, "").trim()).filter((l) => l && !l.startsWith("#"));
670
742
  }
671
743
 
672
744
  // ---------- main ----------
673
745
  function parseArgs(argv) {
674
- const opt = { json: false, noManifest: false, keep: [], tooling: [], maxSeconds: DEFAULT_MAX_SECONDS };
746
+ const opt = { json: false, noManifest: false, keep: [], tooling: [], maxSeconds: null, maxWork: { ...WORK_LIMITS } };
675
747
  const value = (i) => {
676
748
  if (argv[i + 1] === undefined) usage(`${argv[i]} needs a value`);
677
749
  return argv[i + 1];
@@ -695,6 +767,12 @@ function parseArgs(argv) {
695
767
  if (!/^\d+(\.\d+)?$/.test(v)) usage(`--max-seconds needs a number of seconds, got ${v}`);
696
768
  opt.maxSeconds = Number(v);
697
769
  }
770
+ else if (a === "--max-work") {
771
+ const v = value(i++);
772
+ const m = /^([A-Za-z]+)=(\d+)$/.exec(v);
773
+ if (!m || !WORK_KEYS.includes(m[1])) usage(`--max-work needs <name>=<count> with a name from ${WORK_KEYS.join(", ")}, got ${v}`);
774
+ opt.maxWork[m[1]] = Number(m[2]);
775
+ }
698
776
  else if (a === "--help" || a === "-h") usage();
699
777
  else usage(`unknown argument: ${a}`);
700
778
  }
@@ -702,12 +780,13 @@ function parseArgs(argv) {
702
780
  }
703
781
  function usage(error) {
704
782
  if (error) console.error(`check-function-manifest: ${error}`);
705
- console.error("usage: node scripts/check-function-manifest.mjs [--manifest <file>] [--core-root <dir>] [--cli-root <dir> | --cli-package <dir>] [--cli-states <file> [--require-cli-states]] [--no-manifest] [--installed-core <dir> [--keep <path>]... [--keep-file <file>] [--tooling <glob>]...] [--max-seconds <n>] [--json]");
783
+ console.error("usage: node scripts/check-function-manifest.mjs [--manifest <file>] [--core-root <dir>] [--cli-root <dir> | --cli-package <dir>] [--cli-states <file> [--require-cli-states]] [--no-manifest] [--installed-core <dir> [--keep <path>]... [--keep-file <file>] [--tooling <glob>]...] [--max-work <name>=<n>]... [--max-seconds <n>] [--json]");
706
784
  process.exit(2);
707
785
  }
708
786
 
709
787
  export async function run(argv) {
710
788
  const started = Date.now();
789
+ work = newWork();
711
790
  const opt = parseArgs(argv);
712
791
  const here = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
713
792
  if (!opt.cliRoot && !opt.cliPackage) {
@@ -737,7 +816,7 @@ export async function run(argv) {
737
816
  if ((opt.cliRoot || opt.cliPackage) && !catalog) usage(`${opt.cliRoot || opt.cliPackage} has no command catalog`);
738
817
 
739
818
  if (opt.manifest) {
740
- const parsed = parseManifest(readFileSync(opt.manifest, "utf8"));
819
+ const parsed = parseManifest(readText(opt.manifest));
741
820
  entries = parsed.entries;
742
821
  problems.push(...parsed.problems, ...checkEntries(entries));
743
822
  const n = (pred) => entries.filter(pred).length;
@@ -797,15 +876,17 @@ export async function run(argv) {
797
876
  }
798
877
  if (opt.noManifest) notices.push("--no-manifest: the manifest rules did not run here; they run where the manifest is (hq-core-staging pull requests and a local run with --core-root)");
799
878
 
879
+ problems.push(...checkWork(work, opt.maxWork));
800
880
  const elapsedMs = Date.now() - started;
801
- if (elapsedMs >= opt.maxSeconds * 1000) {
881
+ if (opt.maxSeconds !== null && elapsedMs >= opt.maxSeconds * 1000) {
802
882
  problems.push({ rule: "time-budget", message: `the check took ${(elapsedMs / 1000).toFixed(1)} s; it must finish in under ${opt.maxSeconds} s (--max-seconds) so it stays fast enough to run locally` });
803
883
  }
804
884
  const seconds = (elapsedMs / 1000).toFixed(1);
805
885
  if (opt.json) {
806
- console.log(JSON.stringify({ ok: problems.length === 0, seconds: Number(seconds), checked, notices, problems }, null, 2));
886
+ console.log(JSON.stringify({ ok: problems.length === 0, seconds: Number(seconds), work: { ...work }, workLimits: opt.maxWork, checked, notices, problems }, null, 2));
807
887
  } else {
808
888
  for (const c of checked) console.log(`checked: ${c}`);
889
+ console.log(`work: ${WORK_KEYS.map((k) => `${k} ${work[k]} of ${opt.maxWork[k]}`).join(", ")}`);
809
890
  for (const n of notices) console.log(`note: ${n}`);
810
891
  for (const p of problems) console.error(`FAIL [${p.rule}] ${p.message}`);
811
892
  if (problems.length) console.error(`function manifest check failed: ${problems.length} problem${problems.length === 1 ? "" : "s"} (${seconds} s)`);