@indigoai-us/hq-cli 5.345.251 → 5.345.253

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 (188) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/assets/scaffold/core/scripts/hq-session.sh +9 -0
  3. package/contracts/host-canary-release.json +9 -3
  4. package/dist/command-catalog.generated.d.ts +269 -1
  5. package/dist/command-catalog.generated.js +330 -1
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/bot.js +7 -2
  9. package/dist/commands/ci-intake.d.ts +15 -0
  10. package/dist/commands/ci-intake.js +252 -0
  11. package/dist/commands/ci-metrics.d.ts +8 -0
  12. package/dist/commands/ci-metrics.js +55 -0
  13. package/dist/commands/ci.d.ts +13 -0
  14. package/dist/commands/ci.js +10 -0
  15. package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
  16. package/dist/commands/core-hq-session-binding.d.ts +140 -0
  17. package/dist/commands/core-hq-session-binding.js +363 -0
  18. package/dist/commands/core-hq-session-native.d.ts +23 -0
  19. package/dist/commands/core-hq-session-native.js +59 -9
  20. package/dist/commands/core-stop-autosave.js +1 -1
  21. package/dist/commands/core.js +10 -0
  22. package/dist/commands/doctor.d.ts +5 -1
  23. package/dist/commands/doctor.js +42 -5
  24. package/dist/commands/files.d.ts +62 -0
  25. package/dist/commands/files.js +250 -9
  26. package/dist/commands/install-global.js +4 -2
  27. package/dist/commands/logout.js +4 -0
  28. package/dist/commands/ontology-graph.d.ts +2 -0
  29. package/dist/commands/ontology-graph.js +33 -0
  30. package/dist/commands/report.js +35 -2
  31. package/dist/commands/storage-gate.js +1 -1
  32. package/dist/commands/vault-retention-flag.js +2 -1
  33. package/dist/commands/whoami.js +1 -1
  34. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
  35. package/dist/hq-cloud-sync-runner/package.json +1 -1
  36. package/dist/index.js +3 -1
  37. package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
  38. package/dist/lib/agent-kit/mcp/tools.js +48 -0
  39. package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
  40. package/dist/lib/bot/fleet-cron.d.ts +50 -0
  41. package/dist/lib/bot/fleet-cron.js +173 -32
  42. package/dist/lib/bot/fleet-local.d.ts +18 -0
  43. package/dist/lib/bot/fleet-local.js +51 -5
  44. package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
  45. package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
  46. package/dist/lib/bot/signals-engine-flag.js +1 -1
  47. package/dist/lib/cli-invite-nudge.js +1 -1
  48. package/dist/lib/client-version.d.ts +2 -0
  49. package/dist/lib/client-version.js +24 -0
  50. package/dist/lib/company-flag-gate.d.ts +30 -0
  51. package/dist/lib/company-flag-gate.js +104 -0
  52. package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
  53. package/dist/lib/daemon/flag.js +2 -1
  54. package/dist/lib/daemon/legacy-journal-gate.js +3 -1
  55. package/dist/lib/daemon/run.js +4 -3
  56. package/dist/lib/daemon/shared-flag-reads.js +1 -1
  57. package/dist/lib/delivery/migrations.d.ts +32 -1
  58. package/dist/lib/delivery/migrations.js +69 -8
  59. package/dist/lib/doctor/checks/host-core.js +22 -4
  60. package/dist/lib/doctor/checks/jq.d.ts +27 -6
  61. package/dist/lib/doctor/checks/jq.js +46 -8
  62. package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
  63. package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
  64. package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
  65. package/dist/lib/flag-client-gate-headers.d.ts +38 -0
  66. package/dist/lib/flag-client-gate-headers.js +62 -0
  67. package/dist/lib/flag-client-headers.d.ts +15 -0
  68. package/dist/lib/flag-client-headers.js +25 -0
  69. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  70. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  71. package/dist/lib/flag-registry-worker.js +35 -0
  72. package/dist/lib/flag-registry.d.ts +1 -20
  73. package/dist/lib/flag-registry.js +5 -81
  74. package/dist/lib/hook-engine/adapter-core-pin.d.ts +30 -0
  75. package/dist/lib/hook-engine/adapter-core-pin.js +30 -0
  76. package/dist/lib/hook-engine/coverage.d.ts +65 -1
  77. package/dist/lib/hook-engine/coverage.js +173 -8
  78. package/dist/lib/hook-engine/reconcile.js +3 -2
  79. package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
  80. package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
  81. package/dist/lib/hot-channels/signal-changes.js +683 -0
  82. package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
  83. package/dist/lib/hot-channels/signals-pass.js +232 -12
  84. package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
  85. package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
  86. package/dist/lib/lanes/registry-flag.js +2 -1
  87. package/dist/lib/lanes/spawn.js +11 -1
  88. package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
  89. package/dist/lib/mesh/live/binding-intent.js +201 -0
  90. package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
  91. package/dist/lib/mesh/live/binding-receipt.js +365 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
  93. package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
  94. package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
  95. package/dist/lib/mesh/live/daemon/install.js +2 -1
  96. package/dist/lib/mesh/live/daemon/presence.js +9 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
  98. package/dist/lib/mesh/live/daemon/run.js +33 -1
  99. package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
  100. package/dist/lib/ontology-graph/lineage/index.js +1027 -0
  101. package/dist/lib/ontology-graph/model/index.d.ts +54 -0
  102. package/dist/lib/ontology-graph/model/index.js +112 -0
  103. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
  104. package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
  105. package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
  106. package/dist/lib/ontology-graph/model/pass.js +9 -2
  107. package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
  108. package/dist/lib/ontology-graph/model/pending-items.js +24 -1
  109. package/dist/lib/ontology-graph/model/step.d.ts +1 -1
  110. package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
  111. package/dist/lib/ontology-graph/model/tasks.js +20 -7
  112. package/dist/lib/ontology-graph/read/brief.js +41 -6
  113. package/dist/lib/ontology-graph/read/index.d.ts +4 -0
  114. package/dist/lib/ontology-graph/read/index.js +173 -29
  115. package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
  116. package/dist/lib/ontology-graph/read/lineage.js +262 -0
  117. package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
  118. package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
  119. package/dist/lib/ontology-graph/replay/engine.js +213 -8
  120. package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
  121. package/dist/lib/ontology-graph/replay/extractors.js +25 -1
  122. package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
  123. package/dist/lib/ontology-graph/replay/index.js +9 -3
  124. package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
  125. package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
  126. package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
  127. package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
  128. package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
  129. package/dist/lib/ontology-graph/schema/index.js +1 -0
  130. package/dist/lib/ontology-graph/setup/index.js +13 -3
  131. package/dist/lib/search-index/index.d.ts +33 -1
  132. package/dist/lib/search-index/index.js +180 -25
  133. package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
  134. package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
  135. package/dist/lib/signals/adapters-catalog.js +1 -1
  136. package/dist/lib/smart-ci/cost.d.ts +72 -0
  137. package/dist/lib/smart-ci/cost.js +120 -0
  138. package/dist/lib/smart-ci/github.d.ts +112 -0
  139. package/dist/lib/smart-ci/github.js +267 -0
  140. package/dist/lib/smart-ci/intake.d.ts +288 -0
  141. package/dist/lib/smart-ci/intake.js +1078 -0
  142. package/dist/lib/smart-ci/ledger.d.ts +218 -0
  143. package/dist/lib/smart-ci/ledger.js +527 -0
  144. package/dist/lib/smart-ci/metrics.d.ts +137 -0
  145. package/dist/lib/smart-ci/metrics.js +249 -0
  146. package/dist/lib/smart-ci/records.d.ts +265 -0
  147. package/dist/lib/smart-ci/records.js +281 -0
  148. package/dist/lib/smart-ci/reducer.d.ts +67 -0
  149. package/dist/lib/smart-ci/reducer.js +261 -0
  150. package/dist/lib/sync-core/engine-holds.d.ts +15 -0
  151. package/dist/lib/sync-core/engine-holds.js +104 -11
  152. package/dist/lib/sync-core/engine-home.d.ts +3 -0
  153. package/dist/lib/sync-core/engine-home.js +41 -1
  154. package/dist/lib/sync-core/flag.js +2 -1
  155. package/dist/lib/sync-core/hand-back.d.ts +1 -0
  156. package/dist/lib/sync-core/hand-back.js +7 -2
  157. package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
  158. package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
  159. package/dist/lib/sync-core/legacy-journal-export.js +120 -55
  160. package/dist/lib/sync-core/reconcile.d.ts +2 -1
  161. package/dist/lib/sync-core/reconcile.js +40 -7
  162. package/dist/lib/sync-invalid-entity-warning.js +2 -1
  163. package/dist/lib/windows/install-followup.d.ts +41 -0
  164. package/dist/lib/windows/install-followup.js +87 -0
  165. package/dist/lib/windows/jq.d.ts +59 -0
  166. package/dist/lib/windows/jq.js +154 -3
  167. package/dist/lib/windows/user-path.d.ts +5 -0
  168. package/dist/lib/windows/user-path.js +1 -1
  169. package/dist/lib/work-context/auto-bind.d.ts +12 -0
  170. package/dist/lib/work-context/auto-bind.js +49 -3
  171. package/dist/lib/work-context/organize.d.ts +4 -2
  172. package/dist/lib/work-context/organize.js +18 -8
  173. package/dist/lib/work-context/reconcile.js +16 -1
  174. package/dist/main.js +12 -1
  175. package/dist/utils/client-health-contract.d.ts +30 -0
  176. package/dist/utils/client-health-contract.js +111 -0
  177. package/dist/utils/client-health.d.ts +5 -2
  178. package/dist/utils/client-health.js +74 -5
  179. package/dist/utils/exclusive-lock.d.ts +5 -1
  180. package/dist/utils/exclusive-lock.js +9 -2
  181. package/dist/utils/host-registration.d.ts +7 -0
  182. package/dist/utils/host-registration.js +10 -1
  183. package/dist/utils/pid.d.ts +31 -0
  184. package/dist/utils/pid.js +65 -0
  185. package/dist/utils/resident-package-preload.js +12 -4
  186. package/dist/utils/sentry-fingerprint.js +3 -0
  187. package/package.json +10 -8
  188. package/scripts/install-hook-engine.mjs +5 -3
@@ -197,5 +197,5 @@ export declare const REFRESH_PREEMPT_POLL_MS = 500;
197
197
  * cooperative one; the same staged writes and atomic journal keep completed
198
198
  * work.
199
199
  */
200
- export declare const REFRESH_SUPERVISOR_SOURCE = "\nconst fs = require(\"node:fs\");\nconst path = require(\"node:path\");\nconst { spawn, spawnSync } = require(\"node:child_process\");\nconst [logPath, exitPath, hbPath, pidPath, cancelPath, locksDir, maxMs, cmd, ...args] = process.argv.slice(1);\nconst isWin = process.platform === \"win32\";\nconst beat = () => { try { fs.writeFileSync(hbPath, String(Date.now())); } catch {} };\nbeat();\nconst hb = setInterval(beat, 10000);\nlet fd;\ntry { fd = fs.openSync(logPath, \"a\", 0o600); } catch { fd = \"ignore\"; }\nlet finished = false;\nlet preempted = false;\nlet capped = false;\nlet stopAt = 0;\nlet watch;\n// Its own process group on POSIX, so a stop reaches every process the pull started.\nconst child = spawn(cmd, args, { stdio: [\"ignore\", fd, fd], windowsHide: true, detached: !isWin });\ntry { fs.writeFileSync(pidPath, String(child.pid)); } catch {}\nif (!isWin && child.pid) {\n try {\n const r = spawnSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(child.pid)], { encoding: \"utf8\" });\n const started = (r.stdout || \"\").trim();\n if (started) fs.writeFileSync(path.join(path.dirname(pidPath), path.basename(pidPath, \".pid\") + \".start\"), started);\n } catch {}\n}\nconst killTree = (sig) => {\n if (isWin) {\n try { spawnSync(\"taskkill\", [\"/PID\", String(child.pid), \"/T\", \"/F\"], { stdio: \"ignore\", windowsHide: true }); } catch {}\n return;\n }\n try { process.kill(-child.pid, sig); } catch {}\n};\nconst stop = () => {\n if (stopAt) return;\n stopAt = Date.now();\n killTree(\"SIGTERM\");\n setTimeout(() => killTree(\"SIGKILL\"), 5000);\n};\nconst exitNow = (status) => process.exit(typeof status === \"number\" ? status : 1);\nconst done = (status, signal) => {\n if (finished) return;\n finished = true;\n clearInterval(hb);\n clearInterval(watch);\n clearTimeout(stopper);\n try {\n fs.writeFileSync(exitPath + \".tmp\", JSON.stringify({ status, signal, preempted, capped }));\n fs.renameSync(exitPath + \".tmp\", exitPath);\n } catch {}\n if (!stopAt) return exitNow(status);\n // A stopped pull's group is always SIGKILLed after the grace period, even\n // when the pull itself exited on SIGTERM, so no grandchild survives.\n const left = Math.max(0, stopAt + 5000 - Date.now());\n setTimeout(() => { killTree(\"SIGKILL\"); exitNow(status); }, left);\n};\nconst stopper = setTimeout(() => {\n capped = true;\n // At the cap the pull is no longer live: stop heartbeating so nothing reads it as in progress.\n clearInterval(hb);\n try { fs.writeFileSync(hbPath, \"capped:\" + Date.now()); } catch {}\n stop();\n}, Number(maxMs));\nconst alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return Boolean(e && e.code === \"EPERM\"); } };\nlet lockName = null;\nconst findLock = () => {\n let names;\n try { names = fs.readdirSync(locksDir); } catch { return null; }\n for (const name of names) {\n // A sync holds shared membership: <lock>.shared-<pid>-<hex>.\n const shared = /^(.+\\.lock)\\.shared-(\\d+)-/.exec(name);\n if (shared && Number(shared[2]) === child.pid) return shared[1];\n if (!name.endsWith(\".lock\")) continue;\n // An exclusive holder writes its record into the lock file itself.\n try {\n const info = JSON.parse(fs.readFileSync(path.join(locksDir, name), \"utf8\"));\n if (info && info.pid === child.pid) return name;\n } catch {}\n }\n return null;\n};\nconst someoneWaiting = () => {\n if (fs.existsSync(cancelPath)) return true;\n if (!lockName) lockName = findLock();\n if (!lockName) return false;\n let names;\n try { names = fs.readdirSync(locksDir); } catch { return false; }\n const prefix = lockName + \".wait-\";\n for (const name of names) {\n if (!name.startsWith(prefix)) continue;\n const waiter = Number(name.slice(prefix.length).split(\"-\")[0]);\n if (Number.isInteger(waiter) && waiter > 0 && waiter !== child.pid && waiter !== process.pid && alive(waiter)) return true;\n }\n return false;\n};\nwatch = setInterval(() => {\n if (finished || stopAt) return;\n if (someoneWaiting()) {\n preempted = true;\n stop();\n }\n}, 500);\nchild.on(\"error\", (error) => {\n try { fs.appendFileSync(logPath, String((error && error.code) || error) + \"\\n\"); } catch {}\n done(null, null);\n});\nchild.on(\"exit\", (status, signal) => done(status, signal));\n";
200
+ export declare const REFRESH_SUPERVISOR_SOURCE = "\nconst fs = require(\"node:fs\");\nconst path = require(\"node:path\");\nconst { spawn, spawnSync } = require(\"node:child_process\");\nconst [logPath, exitPath, hbPath, pidPath, cancelPath, locksDir, maxMs, cmd, ...args] = process.argv.slice(1);\nconst isWin = process.platform === \"win32\";\nconst beat = () => { try { fs.writeFileSync(hbPath, String(Date.now())); } catch {} };\nbeat();\nconst hb = setInterval(beat, 10000);\nlet fd;\ntry { fd = fs.openSync(logPath, \"a\", 0o600); } catch { fd = \"ignore\"; }\nlet finished = false;\nlet preempted = false;\nlet capped = false;\nlet stopAt = 0;\nlet watch;\n// Its own process group on POSIX, so a stop reaches every process the pull started.\nconst child = spawn(cmd, args, { stdio: [\"ignore\", fd, fd], windowsHide: true, detached: !isWin });\ntry { fs.writeFileSync(pidPath + \".tmp\", String(child.pid)); fs.renameSync(pidPath + \".tmp\", pidPath); } catch {}\nif (!isWin && child.pid) {\n try {\n const r = spawnSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(child.pid)], { encoding: \"utf8\" });\n const started = (r.stdout || \"\").trim();\n if (started) fs.writeFileSync(path.join(path.dirname(pidPath), path.basename(pidPath, \".pid\") + \".start\"), started);\n } catch {}\n}\nconst killTree = (sig) => {\n if (isWin) {\n try { spawnSync(\"taskkill\", [\"/PID\", String(child.pid), \"/T\", \"/F\"], { stdio: \"ignore\", windowsHide: true }); } catch {}\n return;\n }\n try { process.kill(-child.pid, sig); } catch {}\n};\nconst stop = () => {\n if (stopAt) return;\n stopAt = Date.now();\n killTree(\"SIGTERM\");\n setTimeout(() => killTree(\"SIGKILL\"), 5000);\n};\nconst exitNow = (status) => process.exit(typeof status === \"number\" ? status : 1);\nconst done = (status, signal) => {\n if (finished) return;\n finished = true;\n clearInterval(hb);\n clearInterval(watch);\n clearTimeout(stopper);\n try {\n fs.writeFileSync(exitPath + \".tmp\", JSON.stringify({ status, signal, preempted, capped }));\n fs.renameSync(exitPath + \".tmp\", exitPath);\n } catch {}\n if (!stopAt) return exitNow(status);\n // A stopped pull's group is always SIGKILLed after the grace period, even\n // when the pull itself exited on SIGTERM, so no grandchild survives.\n const left = Math.max(0, stopAt + 5000 - Date.now());\n setTimeout(() => { killTree(\"SIGKILL\"); exitNow(status); }, left);\n};\nconst stopper = setTimeout(() => {\n capped = true;\n // At the cap the pull is no longer live: stop heartbeating so nothing reads it as in progress.\n clearInterval(hb);\n try { fs.writeFileSync(hbPath, \"capped:\" + Date.now()); } catch {}\n stop();\n}, Number(maxMs));\nconst alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return Boolean(e && e.code === \"EPERM\"); } };\nlet lockName = null;\nconst findLock = () => {\n let names;\n try { names = fs.readdirSync(locksDir); } catch { return null; }\n for (const name of names) {\n // A sync holds shared membership: <lock>.shared-<pid>-<hex>.\n const shared = /^(.+\\.lock)\\.shared-(\\d+)-/.exec(name);\n if (shared && Number(shared[2]) === child.pid) return shared[1];\n if (!name.endsWith(\".lock\")) continue;\n // An exclusive holder writes its record into the lock file itself.\n try {\n const info = JSON.parse(fs.readFileSync(path.join(locksDir, name), \"utf8\"));\n if (info && info.pid === child.pid) return name;\n } catch {}\n }\n return null;\n};\nconst someoneWaiting = () => {\n if (fs.existsSync(cancelPath)) return true;\n if (!lockName) lockName = findLock();\n if (!lockName) return false;\n let names;\n try { names = fs.readdirSync(locksDir); } catch { return false; }\n const prefix = lockName + \".wait-\";\n for (const name of names) {\n if (!name.startsWith(prefix)) continue;\n const waiter = Number(name.slice(prefix.length).split(\"-\")[0]);\n if (Number.isInteger(waiter) && waiter > 0 && waiter !== child.pid && waiter !== process.pid && alive(waiter)) return true;\n }\n return false;\n};\nwatch = setInterval(() => {\n if (finished || stopAt) return;\n if (someoneWaiting()) {\n preempted = true;\n stop();\n }\n}, 500);\nchild.on(\"error\", (error) => {\n try { fs.appendFileSync(logPath, String((error && error.code) || error) + \"\\n\"); } catch {}\n done(null, null);\n});\nchild.on(\"exit\", (status, signal) => done(status, signal));\n";
201
201
  //# sourceMappingURL=refresh-sync-handoff.d.ts.map
@@ -690,7 +690,7 @@ let stopAt = 0;
690
690
  let watch;
691
691
  // Its own process group on POSIX, so a stop reaches every process the pull started.
692
692
  const child = spawn(cmd, args, { stdio: ["ignore", fd, fd], windowsHide: true, detached: !isWin });
693
- try { fs.writeFileSync(pidPath, String(child.pid)); } catch {}
693
+ try { fs.writeFileSync(pidPath + ".tmp", String(child.pid)); fs.renameSync(pidPath + ".tmp", pidPath); } catch {}
694
694
  if (!isWin && child.pid) {
695
695
  try {
696
696
  const r = spawnSync("ps", ["-o", "lstart=", "-p", String(child.pid)], { encoding: "utf8" });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Client-gate headers sent on every `/v1/flags/resolve` request, matching
3
+ * `hq-pro` `src/flags/client-gates.ts` (`x-hq-client-version` and
4
+ * `x-hq-client-platform`).
5
+ *
6
+ * This module has no file-system reads and no global `fetch` reference. The
7
+ * embedded flag-registry worker bundles it and runs as
8
+ * `new Worker(source, { eval: true })`, with no module URL, so the CLI version
9
+ * is passed in by the caller (workerData for the worker, `CLI_VERSION` in
10
+ * `flag-client-headers.ts` for the main thread). Nothing here may resolve a
11
+ * path relative to its own file.
12
+ */
13
+ import type { FlagClientOptions } from "@indigoai-us/hq-flags-client";
14
+ export declare const CLIENT_VERSION_HEADER = "x-hq-client-version";
15
+ export declare const CLIENT_PLATFORM_HEADER = "x-hq-client-platform";
16
+ /** The `fetch` shape `@indigoai-us/hq-flags-client` calls. */
17
+ export type FlagFetch = NonNullable<FlagClientOptions["fetch"]>;
18
+ /**
19
+ * Map Node's `process.platform` onto the header value expected by
20
+ * `hq-pro` `src/flags/client-gates.ts` (`darwin`, `linux`, `windows`).
21
+ */
22
+ export declare function clientGatePlatform(platform?: NodeJS.Platform): string;
23
+ /**
24
+ * The version header value, or undefined when the version could not be read.
25
+ * A missing header is stored as null by the server, and only rows that carry a
26
+ * gate deny on it, so an unreadable version is sent as no header at all
27
+ * rather than as a placeholder.
28
+ */
29
+ export declare function clientGateVersion(version: unknown): string | undefined;
30
+ /** Client-gate headers for `/v1/flags/resolve`. The version header is omitted when unreadable. */
31
+ export declare function clientGateHeaders(version: unknown, platform?: NodeJS.Platform): Record<string, string>;
32
+ /**
33
+ * Wrap a flag-client `fetch` so every request carries the client-gate headers.
34
+ * Headers stay a plain object, so a caller-supplied fetch that reads
35
+ * `init.headers.authorization` sees the same shape the flag client built.
36
+ */
37
+ export declare function withClientGateHeaders(baseFetch: FlagFetch, version: unknown, platform?: NodeJS.Platform): FlagFetch;
38
+ //# sourceMappingURL=flag-client-gate-headers.d.ts.map
@@ -0,0 +1,62 @@
1
+ export const CLIENT_VERSION_HEADER = "x-hq-client-version";
2
+ export const CLIENT_PLATFORM_HEADER = "x-hq-client-platform";
3
+ /** Longest version string `hq-pro` accepts in `x-hq-client-version`. */
4
+ const MAX_CLIENT_VERSION_LENGTH = 64;
5
+ /**
6
+ * Map Node's `process.platform` onto the header value expected by
7
+ * `hq-pro` `src/flags/client-gates.ts` (`darwin`, `linux`, `windows`).
8
+ */
9
+ export function clientGatePlatform(platform = process.platform) {
10
+ return platform === "win32" ? "windows" : platform;
11
+ }
12
+ /**
13
+ * The version header value, or undefined when the version could not be read.
14
+ * A missing header is stored as null by the server, and only rows that carry a
15
+ * gate deny on it, so an unreadable version is sent as no header at all
16
+ * rather than as a placeholder.
17
+ */
18
+ export function clientGateVersion(version) {
19
+ if (typeof version !== "string")
20
+ return undefined;
21
+ const trimmed = version.trim();
22
+ if (trimmed.length === 0 || trimmed.length > MAX_CLIENT_VERSION_LENGTH)
23
+ return undefined;
24
+ return trimmed;
25
+ }
26
+ /** Client-gate headers for `/v1/flags/resolve`. The version header is omitted when unreadable. */
27
+ export function clientGateHeaders(version, platform = process.platform) {
28
+ const headers = {};
29
+ const clientVersion = clientGateVersion(version);
30
+ if (clientVersion !== undefined)
31
+ headers[CLIENT_VERSION_HEADER] = clientVersion;
32
+ headers[CLIENT_PLATFORM_HEADER] = clientGatePlatform(platform);
33
+ return headers;
34
+ }
35
+ /** Copy request headers of any `HeadersInit` shape into a plain record. */
36
+ function plainHeaders(headers) {
37
+ if (headers === undefined || headers === null)
38
+ return {};
39
+ if (Array.isArray(headers))
40
+ return Object.fromEntries(headers.map(([key, value]) => [key, value]));
41
+ if (typeof headers.forEach === "function" &&
42
+ typeof headers.get === "function") {
43
+ const record = {};
44
+ headers
45
+ .forEach((value, key) => { record[key] = value; });
46
+ return record;
47
+ }
48
+ return { ...headers };
49
+ }
50
+ /**
51
+ * Wrap a flag-client `fetch` so every request carries the client-gate headers.
52
+ * Headers stay a plain object, so a caller-supplied fetch that reads
53
+ * `init.headers.authorization` sees the same shape the flag client built.
54
+ */
55
+ export function withClientGateHeaders(baseFetch, version, platform = process.platform) {
56
+ const gateHeaders = clientGateHeaders(version, platform);
57
+ return ((input, init) => baseFetch(input, {
58
+ ...init,
59
+ headers: { ...plainHeaders(init?.headers), ...gateHeaders },
60
+ }));
61
+ }
62
+ //# sourceMappingURL=flag-client-gate-headers.js.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Main-thread flag clients that send the client-gate headers
3
+ * (`x-hq-client-version`, `x-hq-client-platform`) on every
4
+ * `/v1/flags/resolve` request, matching `hq-pro` `src/flags/client-gates.ts`.
5
+ *
6
+ * The header logic lives in `flag-client-gate-headers.ts`; the embedded
7
+ * flag-registry worker keeps its own copy and gets the version through
8
+ * workerData. The version comes from `client-version.ts`, which never throws:
9
+ * an unreadable version sends the request without the version header.
10
+ */
11
+ import { type FlagClient, type FlagClientOptions } from "@indigoai-us/hq-flags-client";
12
+ export { CLIENT_PLATFORM_HEADER, CLIENT_VERSION_HEADER, clientGateHeaders, clientGatePlatform, clientGateVersion, withClientGateHeaders, type FlagFetch, } from "./flag-client-gate-headers.js";
13
+ /** Drop-in `createFlagClient` wrapper that injects client-gate headers on every request. */
14
+ export declare function createHqFlagClient(options: FlagClientOptions): FlagClient;
15
+ //# sourceMappingURL=flag-client-headers.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Main-thread flag clients that send the client-gate headers
3
+ * (`x-hq-client-version`, `x-hq-client-platform`) on every
4
+ * `/v1/flags/resolve` request, matching `hq-pro` `src/flags/client-gates.ts`.
5
+ *
6
+ * The header logic lives in `flag-client-gate-headers.ts`; the embedded
7
+ * flag-registry worker keeps its own copy and gets the version through
8
+ * workerData. The version comes from `client-version.ts`, which never throws:
9
+ * an unreadable version sends the request without the version header.
10
+ */
11
+ import { createFlagClient as createRawFlagClient, } from "@indigoai-us/hq-flags-client";
12
+ import { readClientVersion } from "./client-version.js";
13
+ import { withClientGateHeaders } from "./flag-client-gate-headers.js";
14
+ export { CLIENT_PLATFORM_HEADER, CLIENT_VERSION_HEADER, clientGateHeaders, clientGatePlatform, clientGateVersion, withClientGateHeaders, } from "./flag-client-gate-headers.js";
15
+ /** Drop-in `createFlagClient` wrapper that injects client-gate headers on every request. */
16
+ export function createHqFlagClient(options) {
17
+ const baseFetch = options.fetch ?? globalThis.fetch;
18
+ return createRawFlagClient({
19
+ ...options,
20
+ ...(typeof baseFetch === "function"
21
+ ? { fetch: withClientGateHeaders(baseFetch, readClientVersion()) }
22
+ : {}),
23
+ });
24
+ }
25
+ //# sourceMappingURL=flag-client-headers.js.map