@indigoai-us/hq-cli 5.108.25 → 5.108.26

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 (34) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/commands/integrations-api.d.ts +15 -0
  3. package/dist/commands/integrations-connect.js +84 -3
  4. package/dist/commands/integrations-oauth.js +62 -3
  5. package/dist/commands/mcp-registration.d.ts +17 -7
  6. package/dist/commands/mcp-registration.js +16 -27
  7. package/dist/commands/mesh.js +174 -50
  8. package/dist/commands/pack-install.js +5 -5
  9. package/dist/commands/secrets.d.ts +7 -0
  10. package/dist/commands/secrets.js +26 -2
  11. package/dist/lib/mesh/live/backfill-held.d.ts +42 -1
  12. package/dist/lib/mesh/live/backfill-held.js +95 -13
  13. package/dist/lib/mesh/live/daemon/doctor.d.ts +15 -0
  14. package/dist/lib/mesh/live/daemon/doctor.js +41 -10
  15. package/dist/lib/mesh/live/daemon/mode.d.ts +37 -0
  16. package/dist/lib/mesh/live/daemon/mode.js +88 -0
  17. package/dist/lib/mesh/live/daemon/run.d.ts +8 -0
  18. package/dist/lib/mesh/live/daemon/run.js +39 -28
  19. package/dist/lib/mesh/live/daemon/state.d.ts +2 -0
  20. package/dist/lib/mesh/live/emit-client.d.ts +99 -0
  21. package/dist/lib/mesh/live/emit-client.js +193 -0
  22. package/dist/lib/mesh/live/emit-evidence.d.ts +49 -0
  23. package/dist/lib/mesh/live/emit-evidence.js +77 -0
  24. package/dist/lib/mesh/live/emit-replay.d.ts +26 -0
  25. package/dist/lib/mesh/live/emit-replay.js +157 -0
  26. package/dist/lib/mesh/live/emit-retry.d.ts +25 -0
  27. package/dist/lib/mesh/live/emit-retry.js +79 -0
  28. package/dist/lib/mesh/live/emit.d.ts +54 -0
  29. package/dist/lib/mesh/live/emit.js +153 -0
  30. package/dist/lib/narrow-hint-banner.d.ts +3 -7
  31. package/dist/lib/narrow-hint-banner.js +13 -34
  32. package/dist/lib/plan-limit-nag.d.ts +0 -3
  33. package/dist/lib/plan-limit-nag.js +10 -20
  34. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,74 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.108.26] — 2026-09-08
6
+
7
+ ### Added
8
+
9
+ - **Daemon receive-only mode** (owner decision 2026-09-08; contract
10
+ direct-emit-v1 §6.3). `hq mesh mode <get|legacy|direct|check>` selects the
11
+ daemon's emit mode, resolved from `HQ_MESH_MODE` then `~/.hq/work-mesh/config.json`
12
+ (`emitMode`), defaulting to **legacy**. In `legacy` the daemon runs the spool
13
+ watch + flush + held + outbox replay + transcript-watch emit path (unchanged).
14
+ In `direct` it runs **receive-only** — the presence subscriber keeps the cache
15
+ the desktop app reads warm on `hq/{personUid}/mesh`, with no spool/held/outbox/
16
+ flush/transcript-watch — because sessions POST events directly. `hq mesh mode
17
+ check` probes whether `/v1/mesh/events` is live so the flag can flip after the
18
+ server route lands. `hq mesh daemon doctor` reports `mode` + `subscription`
19
+ state and omits the spool/held/outbox lines in direct mode.
20
+ - **Direct-emit path** (owner decision 2026-09-08 "retire the client daemon";
21
+ contract `direct-emit-v1`). `hq mesh session <kind>` now POSTs each Work Mesh
22
+ event straight to `POST /v1/mesh/events` with the caller's normal HQ bearer
23
+ token instead of appending to the local spool; the server attributes the event
24
+ to a company server-side and fans it out over MQTT. Evidence for attribution
25
+ travels in an `evidence` object gathered client-side: `companySlug` (from the
26
+ session meta), `cwd`, `hqRoot`, `touchedPaths` (`--touched-path`, repeatable),
27
+ `repoPath` (derived from the enclosing git work-tree), `project`, `task`. On a
28
+ network/5xx/429 failure the batch is written to a tiny local retry file that the
29
+ next invocation drains — no long-lived process. `--enqueue` is retained as a
30
+ no-op for hook back-compat (it now emits directly).
31
+ - `hq mesh emit` — drains the retry file; `--replay-legacy` also replays the
32
+ legacy `spool.jsonl` + `held.jsonl` backlog through the new endpoint, lifting
33
+ each event's local-only fields into `evidence` and reusing its `eventId` so the
34
+ server dedupes.
35
+ - `hq mesh daemon doctor` now reports the direct-emit path: `emit last post`
36
+ (lastPostAt), per-status counts from the last attempt, and `emit retry depth`.
37
+ - `hq integrations connect --scopes "<list>"` sends an explicit permissions list
38
+ on the OAuth start request, for a vendor whose requirements HQ does not yet
39
+ know. Space- or comma-separated; order preserved, duplicates dropped. Omitting
40
+ the flag is unchanged — the request carries no `scopes` field at all and
41
+ hq-pro keeps choosing, because an empty list would ask a vendor for no access
42
+ rather than for its default. Refused up front where it could never be honoured
43
+ (alongside `--token`, or against an app whose auth mode is known to be `key`
44
+ or `none`), and carried through the printed bring-your-own-client command. A
45
+ console hand-off cannot carry it, and now says so.
46
+
47
+ ### Changed
48
+
49
+ - The loopback sign-in callback page — the one HQ surface a person sees in a
50
+ browser during `hq integrations connect` — now carries the hq-console visual
51
+ language instead of an unstyled white page: near-black ground, hairline-bordered
52
+ card, one 13px size, grey heading over bright body, and a dim `HQ` mark.
53
+ Deliberately ships no webfont: the page is served by a local port and is often
54
+ the browser's first paint after a redirect, where a blocking font request would
55
+ delay it and would fail outright offline — exactly when a loopback callback
56
+ still works.
57
+
58
+ ### Fixed
59
+
60
+ - `hq secrets set` now attributes its writes to a `cli_secrets_set` telemetry
61
+ surface, so CLI-created secrets are no longer recorded as generic `api` traffic.
62
+ - `hq mesh context backfill-held` now forwards the company evidence each held
63
+ event recorded at enqueue time (`cwd`, `hqRoot`, the session's bound
64
+ `companySlug`, and any `project`/`task`) into the synthesized reconcile
65
+ observation, so an ended session attributes to the company it was actually
66
+ bound to (or its `companies/{slug}/` cwd) instead of resolving to
67
+ `needs_company` and staying held forever. `--dry-run` now predicts with the
68
+ same evidence + shared resolver the write path uses, so its `reconciled`/
69
+ `unresolved` counts match a real run — previously `--dry-run` reported every
70
+ unattributed session as would-reconcile while the write run, given no
71
+ evidence in its observation, resolved none.
72
+
5
73
  ## [5.108.25] — 2026-09-08
6
74
 
7
75
  ## [5.108.24] — 2026-09-08
@@ -212,6 +212,21 @@ export interface OAuthStartInput {
212
212
  * state row and attaches it at code exchange; it is never logged.
213
213
  */
214
214
  clientSecret?: string;
215
+ /**
216
+ * The exact permissions to request at the authorize step.
217
+ *
218
+ * Normally leave this alone: hq-pro sends whatever a vendor needs, either
219
+ * the scopes a pre-registered client was granted or, for the vendors that
220
+ * reject a scope-less request outright, a server-side list. This exists for
221
+ * the case that list does not cover — an app that wants narrower access
222
+ * than the default, or a vendor whose requirement HQ does not yet know.
223
+ *
224
+ * hq-pro honours it on EVERY connect path (catalog, domain, discovery
225
+ * receipt, direct `mcpUrl`) and it beats both the static-client and
226
+ * registry-derived scopes, unlike `clientId`, which is read only on the
227
+ * direct `mcpUrl` path.
228
+ */
229
+ scopes?: string[];
215
230
  }
216
231
  export declare function startOAuth(token: string, companyUid: string, input: OAuthStartInput): Promise<OAuthStartResult>;
217
232
  export declare function completeOAuth(token: string, companyUid: string, input: {
@@ -76,6 +76,64 @@ const BRING_YOUR_OWN_CLIENT_CODES = new Set([
76
76
  "OAUTH_REGISTRATION_UNSUPPORTED",
77
77
  "CLIENT_REGISTRATION_REFUSED",
78
78
  ]);
79
+ /**
80
+ * Server-side limits, restated here so a typo fails in the terminal with a
81
+ * sentence rather than as an opaque 400 three network hops away. Kept in step
82
+ * with hq-pro's own `parseRequestedScopes`; if that changes, change this.
83
+ */
84
+ const MAX_SCOPES = 32;
85
+ const MAX_SCOPE_LENGTH = 256;
86
+ /**
87
+ * Parses `--scopes`, accepting either separator a person would reach for:
88
+ * `--scopes "mcp:read mcp:write"` and `--scopes mcp:read,mcp:write` are the
89
+ * same request. Order is preserved and duplicates are dropped, so a repeated
90
+ * scope is not sent twice.
91
+ *
92
+ * Rejects rather than silently repairing. A scope list is a permissions
93
+ * request; quietly dropping a malformed entry would ask a vendor for something
94
+ * other than what the caller typed, and the caller would not find out until an
95
+ * agent hit a missing permission later.
96
+ */
97
+ function parseRequestedScopes(raw) {
98
+ if (raw === undefined)
99
+ return undefined;
100
+ const entries = raw.split(/[\s,]+/).filter((entry) => entry.length > 0);
101
+ if (entries.length === 0) {
102
+ throw new IntegrationsCliError("--scopes was empty — pass at least one permission.", {
103
+ expected: true,
104
+ });
105
+ }
106
+ if (entries.length > MAX_SCOPES) {
107
+ throw new IntegrationsCliError(`--scopes takes at most ${MAX_SCOPES} permissions; ${entries.length} were given.`, { expected: true });
108
+ }
109
+ const scopes = [];
110
+ for (const entry of entries) {
111
+ if (entry.length > MAX_SCOPE_LENGTH) {
112
+ throw new IntegrationsCliError(`--scopes entries must be at most ${MAX_SCOPE_LENGTH} characters.`, { expected: true });
113
+ }
114
+ if (!scopes.includes(entry))
115
+ scopes.push(entry);
116
+ }
117
+ return scopes;
118
+ }
119
+ /**
120
+ * Refuse a `--scopes` that could not possibly be honoured, before anything is
121
+ * sent. Permissions are an OAuth concept: an API-key app has none to ask for,
122
+ * and an app that needs no auth has nothing to ask.
123
+ */
124
+ function assertScopesApplicable(opts, target, authMode) {
125
+ if (opts.scopes === undefined)
126
+ return;
127
+ if (opts.token || opts.tokenStdin) {
128
+ throw new IntegrationsCliError("--scopes is for a browser sign-in and --token is for an API key; pass one or the other, not both.", { expected: true });
129
+ }
130
+ // An UNKNOWN mode is left alone for the same reason --client-id leaves it
131
+ // alone: the direct-endpoint path often learns it is OAuth only once hq-pro
132
+ // says so, and refusing here would block the very case this flag is for.
133
+ if (authMode === "key" || authMode === "none") {
134
+ throw new IntegrationsCliError(`${target.label} does not use a browser sign-in, so --scopes does not apply to it.`, { expected: true });
135
+ }
136
+ }
79
137
  /**
80
138
  * Looks-like-a-domain test for the positional `<app>` argument. Deliberately
81
139
  * loose — hq-pro does the real resolution — but tight enough that `linear.app`
@@ -398,13 +456,17 @@ async function connectViaOAuth(token, companyUid, target, opts) {
398
456
  expected: true,
399
457
  });
400
458
  }
401
- const startInput = { ...target.ref };
459
+ const requestedScopes = parseRequestedScopes(opts.scopes);
460
+ const startInput = {
461
+ ...target.ref,
462
+ ...(requestedScopes ? { scopes: requestedScopes } : {}),
463
+ };
402
464
  // A user-registered app pins the console callback and skips the loopback
403
465
  // entirely — see `userClientSignIn` for why an ephemeral port cannot be the
404
466
  // redirect URI here.
405
467
  const userClient = await resolveUserOAuthClient(opts, target.label);
406
468
  if (userClient)
407
- return await userClientSignIn(token, companyUid, target, opts, userClient);
469
+ return await userClientSignIn(token, companyUid, target, opts, userClient, requestedScopes);
408
470
  // A loopback listener only works if the browser runs on THIS machine. Over
409
471
  // SSH the person opens the printed URL on their workstation, so the provider
410
472
  // redirects to the workstation's 127.0.0.1 while the listener sits on the
@@ -567,6 +629,13 @@ async function consoleHandoff(target, opts) {
567
629
  const url = consoleIntegrationsUrl(opts.company, consoleOrigin());
568
630
  console.error(chalk.yellow(`${target.label} signs in through the console, not the terminal — this HQ backend finishes these sign-ins there.`));
569
631
  printConsoleDestination(target, opts, url);
632
+ // A console sign-in is started by the console, so there is nowhere to put a
633
+ // --scopes list. Saying nothing would let the connect finish with default
634
+ // permissions while the caller believes theirs were requested -- the exact
635
+ // silent-wrong-permissions failure --scopes exists to prevent.
636
+ if (opts.scopes) {
637
+ console.error(chalk.yellow(`Note: --scopes cannot be carried into a console sign-in, so this connect will use ${target.label}'s default permissions.`));
638
+ }
570
639
  if (url && opts.browser !== false)
571
640
  await open(url).catch(() => { });
572
641
  console.error(chalk.dim("When the browser says it connected, run `hq integrations list` to confirm."));
@@ -624,6 +693,11 @@ function byoClientCommand(target, opts) {
624
693
  if (provider)
625
694
  parts.push(`--provider ${shellQuote(provider)}`);
626
695
  parts.push("--client-id <client-id-from-the-provider>", "--client-secret-stdin");
696
+ // The whole point of --scopes is that this vendor needs permissions HQ would
697
+ // not otherwise send. Dropping them from the recovery command would hand the
698
+ // caller a line that reproduces the failure they are recovering from.
699
+ if (opts.scopes)
700
+ parts.push(`--scopes ${shellQuote(opts.scopes)}`);
627
701
  return parts.join(" ");
628
702
  }
629
703
  /**
@@ -705,11 +779,15 @@ async function resolveUserOAuthClient(opts, appLabel) {
705
779
  * `companyUid` is omitted, so the callback completes and the console names the
706
780
  * app it connected. Ship this only against a backend carrying both.
707
781
  */
708
- async function userClientSignIn(token, companyUid, target, opts, client) {
782
+ async function userClientSignIn(token, companyUid, target, opts, client, requestedScopes) {
709
783
  const started = await startOAuth(token, companyUid, {
710
784
  ...target.ref,
711
785
  clientId: client.clientId,
712
786
  ...(client.clientSecret ? { clientSecret: client.clientSecret } : {}),
787
+ // A caller who registered the app themselves is the one who knows which
788
+ // permissions that registration was granted, so their list must reach the
789
+ // authorize step on this path too.
790
+ ...(requestedScopes ? { scopes: requestedScopes } : {}),
713
791
  });
714
792
  console.error(`Open this URL to sign in to ${started.displayName || target.label}:`);
715
793
  console.error(` ${started.authorizationUrl}`);
@@ -772,6 +850,7 @@ async function connectApp(token, companyUid, app, opts, expectedRevivedConnectio
772
850
  const target = await resolveTarget(token, companyUid, app, opts, expectedRevivedConnectionId !== undefined);
773
851
  const authMode = opts.auth ?? target.authClass;
774
852
  assertUserClientApplicable(opts, target, authMode);
853
+ assertScopesApplicable(opts, target, authMode);
775
854
  if (authMode === "oauth") {
776
855
  const result = await connectViaOAuth(token, companyUid, target, opts);
777
856
  if (result)
@@ -932,6 +1011,7 @@ export function registerConnectCommands(integrations) {
932
1011
  .option("--auth <mode>", "Force the auth mode: none, key, or oauth (default: detect)")
933
1012
  .option("--client-id <id>", "Client id of an OAuth app you registered with the provider yourself")
934
1013
  .option("--client-secret-stdin", "Read that app's client secret from stdin")
1014
+ .option("--scopes <list>", "Permissions to request, space- or comma-separated (default: what the app needs)")
935
1015
  .option("--no-browser", "Print the sign-in URL instead of opening a browser")
936
1016
  .option("--timeout <seconds>", "How long to wait for a browser sign-in (default 300)")
937
1017
  .option("--json", "Machine-readable output")
@@ -1005,6 +1085,7 @@ export function registerConnectCommands(integrations) {
1005
1085
  // start an ordinary sign-in, and `--client-id` beside `--token` would
1006
1086
  // reinstall with the bearer token and drop the OAuth app.
1007
1087
  assertUserClientApplicable(opts, target, target.authClass);
1088
+ assertScopesApplicable(opts, target, target.authClass);
1008
1089
  if (target.authClass === "oauth") {
1009
1090
  const result = await connectViaOAuth(token, companyUid, target, opts);
1010
1091
  if (result)
@@ -23,10 +23,69 @@ import { IntegrationsCliError } from "./integrations-core.js";
23
23
  export const LOOPBACK_CALLBACK_PATH = "/hq/integrations/oauth/callback";
24
24
  /** How long to wait for the browser round trip before giving the port back. */
25
25
  const DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;
26
+ /**
27
+ * Escapes text destined for the callback page.
28
+ *
29
+ * Every caller passes a literal today, so nothing here is attacker-controlled.
30
+ * It is escaped anyway because this function builds HTML: the next person to
31
+ * pass a provider-supplied string through it should not have to notice that
32
+ * the escaping was missing.
33
+ */
34
+ function escapeHtml(value) {
35
+ return value
36
+ .replace(/&/g, "&amp;")
37
+ .replace(/</g, "&lt;")
38
+ .replace(/>/g, "&gt;")
39
+ .replace(/"/g, "&quot;");
40
+ }
41
+ /**
42
+ * The hq-console visual language, inlined.
43
+ *
44
+ * Deliberately NOT the console's webfont: this page is served by a local port
45
+ * and is often the browser's first paint after a redirect, so a blocking
46
+ * request to fonts.googleapis.com would either delay it or fail outright on a
47
+ * plane. Geist is named first so it is used when the machine has it, with the
48
+ * system stack behind. Token values track src/app/globals.css in hq-console —
49
+ * near-black ground, hairline border, one 13px size, weight 400 only, grey
50
+ * heading over bright body.
51
+ */
52
+ const CALLBACK_PAGE_STYLE = `
53
+ :root { color-scheme: dark }
54
+ * { box-sizing: border-box }
55
+ body {
56
+ margin: 0; min-height: 100vh; display: flex;
57
+ align-items: center; justify-content: center;
58
+ background: #17161a; color: #f2efe9;
59
+ font-family: Geist, ui-sans-serif, system-ui, -apple-system, sans-serif;
60
+ font-size: 13px; font-weight: 400; letter-spacing: -0.013em; line-height: 1.6;
61
+ }
62
+ main {
63
+ width: 100%; max-width: 26rem; margin: 2rem; padding: 1.75rem;
64
+ border: 1px solid rgba(255,255,255,0.1); border-radius: 10px;
65
+ background: #121116;
66
+ }
67
+ .mark { color: #6f6a62; margin-bottom: 1.5rem }
68
+ h1 { font-size: 13px; font-weight: 400; color: #a8a29a; margin: 0 0 0.5rem }
69
+ p { margin: 0; color: #f2efe9 }
70
+ .dot {
71
+ display: inline-block; width: 6px; height: 6px; border-radius: 50%;
72
+ margin-right: 0.5rem; vertical-align: 1px; background: var(--dot);
73
+ }
74
+ `;
26
75
  function respond(res, status, title, detail) {
27
- const body = `<!doctype html><meta charset="utf-8"><title>${title}</title>
28
- <body style="font:15px system-ui;margin:4rem auto;max-width:32rem;color:#111">
29
- <h1 style="font-size:1.1rem;font-weight:600">${title}</h1><p>${detail}</p></body>`;
76
+ // Green only when the browser leg genuinely succeeded. A cancelled or
77
+ // incomplete sign-in gets amber, because the page must not read as success
78
+ // when the terminal is about to report a failure.
79
+ const dot = status === 200 ? "#34d399" : "#fbbf24";
80
+ const body = `<!doctype html><html lang="en"><meta charset="utf-8">
81
+ <meta name="viewport" content="width=device-width,initial-scale=1">
82
+ <title>${escapeHtml(title)} · HQ</title>
83
+ <style>${CALLBACK_PAGE_STYLE}</style>
84
+ <body><main>
85
+ <div class="mark">HQ</div>
86
+ <h1><span class="dot" style="--dot:${dot}"></span>${escapeHtml(title)}</h1>
87
+ <p>${escapeHtml(detail)}</p>
88
+ </main></body></html>`;
30
89
  res.writeHead(status, {
31
90
  "content-type": "text/html; charset=utf-8",
32
91
  // The page is a terminal handoff, never something to keep or re-fetch.
@@ -52,7 +52,6 @@
52
52
  * first-class skip), and {@link registerMcpServers} is the pack-install routing
53
53
  * seam over it.
54
54
  */
55
- import { type FlagReader } from '../lib/flag-registry.js';
56
55
  /** Base for every MCP-registration error; carries a stable machine-checkable `code`. */
57
56
  export declare abstract class McpRegistrationError extends Error {
58
57
  abstract readonly code: string;
@@ -596,10 +595,17 @@ export declare function registerServer(opts: RegisterServerOptions): RegisterSer
596
595
  * when neither a url nor a command is present.
597
596
  */
598
597
  export declare function manifestTarget(manifest: McpManifest): string;
599
- /** Resolve the gate once at the start of an MCP registration operation. */
600
- export declare function isMcpRegistrationEnabled(flagReader?: FlagReader): boolean;
601
- /** Freeze a registration decision so multi-server work cannot split on refresh. */
602
- export declare function captureMcpRegistrationDecision(flagReader?: FlagReader): FlagReader;
598
+ /**
599
+ * Resolve the MCP registration kill switch from its env var alone.
600
+ *
601
+ * `HQ_DISABLE_MCP_REGISTRATION` is an operator's own machine-local opt-out, not
602
+ * a rollout flag, so it is read straight from the environment — no registry
603
+ * lookup. The polarity is inverted and the value match is asymmetric on
604
+ * purpose: ONLY the exact value "1" disables registration; unset and every
605
+ * other value (including "0" and "false") leave it enabled. Do not "tidy" this
606
+ * into a boolean parse — that would silently disable anyone who wrote "false".
607
+ */
608
+ export declare function isMcpRegistrationEnabled(env?: Readonly<Record<string, string | undefined>>): boolean;
603
609
  /**
604
610
  * Register one pack's MCP servers into the shared agent configs (the public seam
605
611
  * `pack-install` routes `wire:'merge'` keys to). For each declared server name it
@@ -627,8 +633,12 @@ export declare function registerMcpServers(pkg: string, names: string[], options
627
633
  /** Lock tuning + backup stamp passthrough (tests). */
628
634
  lock?: AcquireLockOptions;
629
635
  stamp?: string;
630
- /** Test seam: held registry snapshot reader. */
631
- flagReader?: FlagReader;
636
+ /**
637
+ * Pre-resolved kill-switch decision, frozen once before a multi-server loop
638
+ * so an install writes either all of a pack's servers or none of them.
639
+ * Omitted → read `HQ_DISABLE_MCP_REGISTRATION` directly.
640
+ */
641
+ registrationEnabled?: boolean;
632
642
  }): RegisterServerResult[];
633
643
  /** smol-toml's value-table type (its `parse` return + `stringify` input). */
634
644
  type TomlTable = Record<string, unknown>;
@@ -57,7 +57,6 @@ import * as fs from 'fs';
57
57
  import * as os from 'os';
58
58
  import * as path from 'path';
59
59
  import { parse as parseToml, stringify as stringifyToml } from 'smol-toml';
60
- import { resolveFlagGate, resolveProcessFlagGate, } from '../lib/flag-registry.js';
61
60
  // ---------------------------------------------------------------------------
62
61
  // Named error classes (no bare catch-all anywhere in this module).
63
62
  //
@@ -1226,28 +1225,18 @@ export function manifestTarget(manifest) {
1226
1225
  }
1227
1226
  return manifest.url ?? '';
1228
1227
  }
1229
- /** Registry vocabulary for the legacy MCP operator kill switch. */
1230
- const MCP_REGISTRATION_LOOKUP = {
1231
- globalEnvVar: 'HQ_DISABLE_MCP_REGISTRATION',
1232
- globalValueSemantics: {
1233
- onValues: [],
1234
- offValues: ['1'],
1235
- unrecognizedValue: true,
1236
- unsetValue: true,
1237
- },
1238
- fallback: true,
1239
- };
1240
- const mcpRegistrationLegacyFallback = () => process.env.HQ_DISABLE_MCP_REGISTRATION !== '1';
1241
- /** Resolve the gate once at the start of an MCP registration operation. */
1242
- export function isMcpRegistrationEnabled(flagReader) {
1243
- return flagReader
1244
- ? resolveFlagGate(flagReader, 'cli.mcp-registration', MCP_REGISTRATION_LOOKUP, mcpRegistrationLegacyFallback)
1245
- : resolveProcessFlagGate('cli.mcp-registration', MCP_REGISTRATION_LOOKUP, mcpRegistrationLegacyFallback);
1246
- }
1247
- /** Freeze a registration decision so multi-server work cannot split on refresh. */
1248
- export function captureMcpRegistrationDecision(flagReader) {
1249
- const enabled = isMcpRegistrationEnabled(flagReader);
1250
- return { isEnabled: () => enabled };
1228
+ /**
1229
+ * Resolve the MCP registration kill switch from its env var alone.
1230
+ *
1231
+ * `HQ_DISABLE_MCP_REGISTRATION` is an operator's own machine-local opt-out, not
1232
+ * a rollout flag, so it is read straight from the environment — no registry
1233
+ * lookup. The polarity is inverted and the value match is asymmetric on
1234
+ * purpose: ONLY the exact value "1" disables registration; unset and every
1235
+ * other value (including "0" and "false") leave it enabled. Do not "tidy" this
1236
+ * into a boolean parse — that would silently disable anyone who wrote "false".
1237
+ */
1238
+ export function isMcpRegistrationEnabled(env = process.env) {
1239
+ return env.HQ_DISABLE_MCP_REGISTRATION !== '1';
1251
1240
  }
1252
1241
  /**
1253
1242
  * Register one pack's MCP servers into the shared agent configs (the public seam
@@ -1275,14 +1264,14 @@ export function registerMcpServers(pkg, names, options) {
1275
1264
  // ORDERING: this is checked FIRST, BEFORE the loadManifest programmer-error guard
1276
1265
  // below. The kill-switch is a USER/OPERATOR condition; the missing-loadManifest
1277
1266
  // throw is a PROGRAMMER error. An operator who set the kill-switch must never hit a
1278
- // spurious McpManifestError, so the operator path wins. Its legacy environment
1279
- // predicate remains the outage fallback; `options.env` is the SafeWriteEnv
1280
- // home-path injector, not process env.
1267
+ // spurious McpManifestError, so the operator path wins. The decision is read
1268
+ // straight from `HQ_DISABLE_MCP_REGISTRATION`; `options.env` is the
1269
+ // SafeWriteEnv home-path injector, not the process env this switch reads.
1281
1270
  //
1282
1271
  // Returns an empty RegisterServerResult[] (`[]`) — the correct "no servers
1283
1272
  // registered" semantic — so callers (pack-install) consume it gracefully. The skip
1284
1273
  // NOTICE is emitted exactly once per registerMcpServers call.
1285
- if (!isMcpRegistrationEnabled(options?.flagReader)) {
1274
+ if (!(options?.registrationEnabled ?? isMcpRegistrationEnabled())) {
1286
1275
  process.stderr.write('MCP registration skipped (HQ_DISABLE_MCP_REGISTRATION=1)\n');
1287
1276
  return [];
1288
1277
  }