@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217

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 (241) hide show
  1. package/CHANGELOG.md +206 -1
  2. package/README.md +45 -0
  3. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  4. package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
  5. package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
  6. package/dist/command-catalog.generated.d.ts +105 -10
  7. package/dist/command-catalog.generated.js +127 -10
  8. package/dist/command-help.js +3 -1
  9. package/dist/command-registration-plan.d.ts +6 -0
  10. package/dist/command-registration-plan.js +1 -0
  11. package/dist/commands/auth.d.ts +1 -1
  12. package/dist/commands/auth.js +11 -52
  13. package/dist/commands/bot.js +75 -10
  14. package/dist/commands/capacity.d.ts +4 -1
  15. package/dist/commands/capacity.js +46 -10
  16. package/dist/commands/cloud-demote.d.ts +19 -4
  17. package/dist/commands/cloud-demote.js +85 -12
  18. package/dist/commands/cloud-provision.d.ts +5 -1
  19. package/dist/commands/cloud-provision.js +6 -2
  20. package/dist/commands/cloud.d.ts +36 -0
  21. package/dist/commands/cloud.js +110 -27
  22. package/dist/commands/core-delegate-w1b.js +15 -1
  23. package/dist/commands/core-policy.js +67 -8
  24. package/dist/commands/core.js +1 -0
  25. package/dist/commands/daemon.js +9 -1
  26. package/dist/commands/dm.js +7 -0
  27. package/dist/commands/doctor-usage.d.ts +8 -0
  28. package/dist/commands/doctor-usage.js +20 -0
  29. package/dist/commands/doctor.js +7 -1
  30. package/dist/commands/env.d.ts +18 -0
  31. package/dist/commands/env.js +82 -0
  32. package/dist/commands/files-browse.d.ts +11 -4
  33. package/dist/commands/files-browse.js +21 -4
  34. package/dist/commands/files.d.ts +1 -1
  35. package/dist/commands/files.js +25 -11
  36. package/dist/commands/install-global.js +2 -2
  37. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  38. package/dist/commands/integrations-auth-rules.js +79 -0
  39. package/dist/commands/integrations-import.js +124 -12
  40. package/dist/commands/lanes.js +102 -26
  41. package/dist/commands/logout.d.ts +7 -0
  42. package/dist/commands/logout.js +41 -34
  43. package/dist/commands/mesh.d.ts +2 -0
  44. package/dist/commands/mesh.js +60 -35
  45. package/dist/commands/sources.d.ts +8 -2
  46. package/dist/commands/sources.js +65 -9
  47. package/dist/commands/sync-held.js +5 -2
  48. package/dist/commands/whoami.js +26 -1
  49. package/dist/data/command-states.json +15 -0
  50. package/dist/index.js +52 -4
  51. package/dist/lazy-commands.js +5 -6
  52. package/dist/lib/anywhere-person-setting.d.ts +2 -0
  53. package/dist/lib/anywhere-person-setting.js +6 -3
  54. package/dist/lib/billing/usage-card.d.ts +25 -4
  55. package/dist/lib/billing/usage-card.js +76 -9
  56. package/dist/lib/billing/usage-cost.d.ts +3 -3
  57. package/dist/lib/billing/usage-cost.js +35 -13
  58. package/dist/lib/billing/usage-only.js +4 -2
  59. package/dist/lib/billing/usage-rate-card.d.ts +2 -2
  60. package/dist/lib/billing/usage-rate-card.js +3 -0
  61. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  62. package/dist/lib/bot/fleet-cron.js +126 -7
  63. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  64. package/dist/lib/bot/fleet-daemon.js +99 -1
  65. package/dist/lib/bot/inflight.d.ts +9 -0
  66. package/dist/lib/bot/inflight.js +10 -0
  67. package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
  68. package/dist/lib/bot/probe.js +7 -1
  69. package/dist/lib/bot/run.js +20 -1
  70. package/dist/lib/bot/runtime/codex.js +1 -1
  71. package/dist/lib/bot/runtime/grok-acp.d.ts +6 -1
  72. package/dist/lib/bot/runtime/grok-acp.js +32 -14
  73. package/dist/lib/bot/runtime/grok.js +1 -1
  74. package/dist/lib/bot/runtime/index.js +19 -9
  75. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  76. package/dist/lib/bot/runtime/types.d.ts +15 -0
  77. package/dist/lib/bot/runtime/types.js +9 -0
  78. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  79. package/dist/lib/bot/runtime-failure.js +43 -1
  80. package/dist/lib/capacity/accounts.d.ts +8 -0
  81. package/dist/lib/capacity/accounts.js +19 -0
  82. package/dist/lib/capacity/available.d.ts +154 -0
  83. package/dist/lib/capacity/available.js +905 -0
  84. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  85. package/dist/lib/capacity/codex-availability.js +26 -1
  86. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  87. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  88. package/dist/lib/capacity/collectors/codex.js +10 -7
  89. package/dist/lib/capacity/ledger.d.ts +37 -1
  90. package/dist/lib/capacity/ledger.js +207 -30
  91. package/dist/lib/capacity/project.d.ts +26 -0
  92. package/dist/lib/capacity/project.js +137 -8
  93. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  94. package/dist/lib/capacity/refusal-rows.js +61 -0
  95. package/dist/lib/capacity/refusal.d.ts +53 -2
  96. package/dist/lib/capacity/refusal.js +284 -65
  97. package/dist/lib/capacity/route.js +46 -11
  98. package/dist/lib/capacity/widget.d.ts +12 -1
  99. package/dist/lib/capacity/widget.js +91 -3
  100. package/dist/lib/daemon/flag-monitor.d.ts +8 -0
  101. package/dist/lib/daemon/flag-monitor.js +17 -6
  102. package/dist/lib/daemon/flag.d.ts +65 -1
  103. package/dist/lib/daemon/flag.js +190 -40
  104. package/dist/lib/daemon/ops/policy.js +62 -5
  105. package/dist/lib/daemon/paths.d.ts +72 -2
  106. package/dist/lib/daemon/paths.js +154 -3
  107. package/dist/lib/daemon/resolver.d.ts +2 -0
  108. package/dist/lib/daemon/resolver.js +3 -0
  109. package/dist/lib/daemon/run.d.ts +9 -0
  110. package/dist/lib/daemon/run.js +79 -21
  111. package/dist/lib/daemon/selfcheck.d.ts +22 -0
  112. package/dist/lib/daemon/selfcheck.js +40 -1
  113. package/dist/lib/daemon/server.d.ts +5 -1
  114. package/dist/lib/daemon/server.js +17 -23
  115. package/dist/lib/daemon/state-file-switch.d.ts +57 -0
  116. package/dist/lib/daemon/state-file-switch.js +88 -0
  117. package/dist/lib/daemon/state-file.d.ts +198 -0
  118. package/dist/lib/daemon/state-file.js +419 -0
  119. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  120. package/dist/lib/daemon/tcc-eperm.js +310 -0
  121. package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
  122. package/dist/lib/daemon/timed-flag-monitors.js +75 -0
  123. package/dist/lib/delivery/admission.d.ts +86 -0
  124. package/dist/lib/delivery/admission.js +148 -0
  125. package/dist/lib/delivery/artifacts.d.ts +7 -1
  126. package/dist/lib/delivery/artifacts.js +29 -10
  127. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  128. package/dist/lib/delivery/attempt-id.js +16 -0
  129. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  130. package/dist/lib/delivery/disposable-target.js +111 -0
  131. package/dist/lib/delivery/effects.d.ts +136 -0
  132. package/dist/lib/delivery/effects.js +541 -0
  133. package/dist/lib/delivery/enrollment.d.ts +21 -17
  134. package/dist/lib/delivery/enrollment.js +83 -5
  135. package/dist/lib/delivery/escalations.d.ts +51 -0
  136. package/dist/lib/delivery/escalations.js +60 -0
  137. package/dist/lib/delivery/lease.d.ts +80 -0
  138. package/dist/lib/delivery/lease.js +134 -0
  139. package/dist/lib/delivery/migrations.d.ts +120 -4
  140. package/dist/lib/delivery/migrations.js +215 -15
  141. package/dist/lib/delivery/mqtt.d.ts +2 -0
  142. package/dist/lib/delivery/mqtt.js +7 -0
  143. package/dist/lib/delivery/reconciler.d.ts +65 -1
  144. package/dist/lib/delivery/reconciler.js +224 -13
  145. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  146. package/dist/lib/delivery/rpc/client.js +159 -0
  147. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  148. package/dist/lib/delivery/rpc/port.js +16 -0
  149. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  150. package/dist/lib/delivery/rpc/server.js +205 -0
  151. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  152. package/dist/lib/delivery/rpc/wire.js +143 -0
  153. package/dist/lib/delivery/store.d.ts +2 -0
  154. package/dist/lib/delivery/store.js +4 -0
  155. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  156. package/dist/lib/delivery/windows-service-install.js +892 -0
  157. package/dist/lib/delivery/workers/macos.d.ts +16 -1
  158. package/dist/lib/delivery/workers/macos.js +54 -12
  159. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  160. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  161. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  162. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  163. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  164. package/dist/lib/delivery/workers/windows-service.js +584 -0
  165. package/dist/lib/delivery/workers/windows.d.ts +32 -22
  166. package/dist/lib/delivery/workers/windows.js +50 -64
  167. package/dist/lib/doctor/checks/host-core.d.ts +50 -0
  168. package/dist/lib/doctor/checks/host-core.js +269 -0
  169. package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
  170. package/dist/lib/doctor/checks/replay-recorder.js +261 -0
  171. package/dist/lib/doctor/registry.js +4 -0
  172. package/dist/lib/environment/profile.d.ts +239 -0
  173. package/dist/lib/environment/profile.js +251 -0
  174. package/dist/lib/hook-engine/reconcile.js +39 -13
  175. package/dist/lib/hook-engine/registration.d.ts +9 -0
  176. package/dist/lib/hook-engine/registration.js +19 -0
  177. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  178. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  179. package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
  180. package/dist/lib/hot-channels/adapters/slack.js +64 -21
  181. package/dist/lib/hot-channels/alert.d.ts +2 -0
  182. package/dist/lib/hot-channels/alert.js +8 -1
  183. package/dist/lib/hot-channels/contract.d.ts +12 -0
  184. package/dist/lib/hot-channels/contract.js +7 -0
  185. package/dist/lib/hot-channels/loop.js +1 -0
  186. package/dist/lib/hot-channels/run.d.ts +6 -0
  187. package/dist/lib/hot-channels/run.js +4 -0
  188. package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
  189. package/dist/lib/hot-channels/signals-pass.js +82 -41
  190. package/dist/lib/hot-channels/signals-redo.js +10 -2
  191. package/dist/lib/install/claude-targets.d.ts +12 -1
  192. package/dist/lib/install/claude-targets.js +57 -5
  193. package/dist/lib/install/codex-targets.d.ts +2 -2
  194. package/dist/lib/install/codex-targets.js +36 -6
  195. package/dist/lib/install/hook-target.d.ts +3 -0
  196. package/dist/lib/install/hook-target.js +11 -0
  197. package/dist/lib/lanes/canonical-host.d.ts +35 -0
  198. package/dist/lib/lanes/canonical-host.js +65 -0
  199. package/dist/lib/lanes/host-capacity.d.ts +30 -0
  200. package/dist/lib/lanes/host-capacity.js +29 -3
  201. package/dist/lib/lanes/watcher.js +35 -0
  202. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  203. package/dist/lib/mesh/live/daemon/run.js +5 -2
  204. package/dist/lib/mesh/live/flush.d.ts +5 -1
  205. package/dist/lib/mesh/live/flush.js +12 -6
  206. package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
  207. package/dist/lib/mesh/live/reporting-privacy.js +56 -1
  208. package/dist/lib/mesh/live/spool.d.ts +7 -0
  209. package/dist/lib/mesh/live/spool.js +25 -0
  210. package/dist/lib/person-setting-cache.d.ts +38 -0
  211. package/dist/lib/person-setting-cache.js +98 -0
  212. package/dist/lib/safe-store.d.ts +245 -0
  213. package/dist/lib/safe-store.js +777 -0
  214. package/dist/lib/signals/engine.d.ts +29 -2
  215. package/dist/lib/signals/engine.js +103 -4
  216. package/dist/lib/signals/reply.js +73 -18
  217. package/dist/lib/signals/steps/adapters.js +7 -2
  218. package/dist/lib/signals/steps/extract.d.ts +13 -0
  219. package/dist/lib/signals/steps/extract.js +122 -6
  220. package/dist/main.js +46 -3
  221. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  222. package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
  223. package/dist/utils/auth-expiry.d.ts +8 -0
  224. package/dist/utils/auth-expiry.js +53 -0
  225. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  226. package/dist/utils/catalog-runtime-paths.js +53 -0
  227. package/dist/utils/cli-telemetry.d.ts +21 -0
  228. package/dist/utils/cli-telemetry.js +34 -0
  229. package/dist/utils/command-usage.d.ts +275 -0
  230. package/dist/utils/command-usage.js +797 -0
  231. package/dist/utils/files-browse-acl.js +1 -1
  232. package/dist/utils/hook-trust.d.ts +7 -0
  233. package/dist/utils/hook-trust.js +31 -4
  234. package/dist/utils/host-registration.d.ts +126 -0
  235. package/dist/utils/host-registration.js +378 -0
  236. package/dist/utils/resident-package-preload.js +2 -0
  237. package/package.json +10 -8
  238. package/scripts/bench-core.mjs +1096 -0
  239. package/scripts/check-function-manifest.mjs +702 -0
  240. package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
  241. package/dist/lib/delivery/workers/windows-boundary.js +0 -693
@@ -0,0 +1,251 @@
1
+ /**
2
+ * hq-environment-profile.v1: one profile per place that can do work (the
3
+ * local machine, an Outpost, a MicroVM, a bot, a fleet box), published as a
4
+ * company-scoped view.
5
+ *
6
+ * This module holds the TypeScript shape, and a loader that validates a
7
+ * document against src/schemas/hq-environment-profile.v1.schema.json and
8
+ * refuses any other schema_version. It reads; it does not write a profile and
9
+ * it does not match work to an environment.
10
+ *
11
+ * Failure text never contains a value taken from the document, apart from a
12
+ * shortened schema_version. A rejected field may be holding a credential, so
13
+ * issues carry the path, the rule that failed and at most a property name,
14
+ * and a property name is printed only when it looks like a plain field name.
15
+ */
16
+ import { readFileSync } from "node:fs";
17
+ import { dirname, join } from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ import Ajv2020 from "ajv/dist/2020.js";
20
+ import { SECRET_PATTERN_BOUNDARY, SECRET_PATTERNS } from "../core-utils/secret-patterns.js";
21
+ const HERE = dirname(fileURLToPath(import.meta.url));
22
+ export const ENVIRONMENT_PROFILE_SCHEMA_VERSION = "hq-environment-profile.v1";
23
+ export const ENVIRONMENT_PROFILE_SCHEMA_ID = "urn:hq:schema:hq-environment-profile:v1";
24
+ export const ENVIRONMENT_PROFILE_SCHEMA_PATH = join(HERE, "..", "..", "schemas", "hq-environment-profile.v1.schema.json");
25
+ const TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-](\d{2}):(\d{2}))$/;
26
+ /** RFC 3339 date-time with a real calendar date and in-range clock fields. */
27
+ export function isRfc3339DateTime(value) {
28
+ const match = TIMESTAMP.exec(value);
29
+ if (!match)
30
+ return false;
31
+ const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
32
+ if (month < 1 || month > 12 || day < 1)
33
+ return false;
34
+ // Day 0 of the next month is the last day of this one.
35
+ const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
36
+ if (day > daysInMonth)
37
+ return false;
38
+ // 60 is allowed for a leap second.
39
+ if (hour > 23 || minute > 59 || second > 60)
40
+ return false;
41
+ if (match[9] !== undefined && (Number(match[9]) > 23 || Number(match[10]) > 59))
42
+ return false;
43
+ return true;
44
+ }
45
+ /** At most this many issues are listed; the rest are counted. */
46
+ export const ENVIRONMENT_PROFILE_MAX_ISSUES = 100;
47
+ /**
48
+ * Replace every local `#/$defs/...` reference with the schema it names.
49
+ *
50
+ * Ajv compiles a `$ref` that itself contains a `$ref` as a function call, and
51
+ * with allErrors it copies the whole error list after each call. A document
52
+ * with many invalid readings then costs time in the square of their number
53
+ * (16,000 invalid probes took 1.3 s). The schema has no recursive reference,
54
+ * so it can be flattened, and the compiled validator appends errors in place.
55
+ */
56
+ function inlineLocalRefs(node, defs, depth = 0) {
57
+ if (depth > 32)
58
+ throw new Error("hq-environment-profile.v1 schema has a recursive $ref");
59
+ if (Array.isArray(node))
60
+ return node.map((entry) => inlineLocalRefs(entry, defs, depth));
61
+ if (node === null || typeof node !== "object")
62
+ return node;
63
+ const record = node;
64
+ const out = {};
65
+ for (const [key, value] of Object.entries(record)) {
66
+ if (key === "$ref" || key === "$defs")
67
+ continue;
68
+ out[key] = inlineLocalRefs(value, defs, depth);
69
+ }
70
+ const ref = record.$ref;
71
+ if (typeof ref !== "string")
72
+ return out;
73
+ const name = /^#\/\$defs\/([A-Za-z0-9_]+)$/.exec(ref)?.[1];
74
+ if (!name || !(name in defs))
75
+ throw new Error(`hq-environment-profile.v1 schema has an unresolved $ref ${ref}`);
76
+ const target = inlineLocalRefs(defs[name], defs, depth + 1);
77
+ const siblings = Object.keys(out).filter((key) => key !== "description");
78
+ if (siblings.length === 0)
79
+ return { ...target, ...out };
80
+ const existing = Array.isArray(out.allOf) ? out.allOf : [];
81
+ return { ...out, allOf: [...existing, target] };
82
+ }
83
+ let cachedValidate;
84
+ function validator() {
85
+ if (cachedValidate)
86
+ return cachedValidate;
87
+ const schema = JSON.parse(readFileSync(ENVIRONMENT_PROFILE_SCHEMA_PATH, "utf8"));
88
+ const defs = (schema.$defs ?? {});
89
+ const ajv = new Ajv2020({
90
+ allErrors: true,
91
+ strict: false,
92
+ formats: { "date-time": isRfc3339DateTime },
93
+ });
94
+ cachedValidate = ajv.compile(inlineLocalRefs(schema, defs));
95
+ return cachedValidate;
96
+ }
97
+ /** A short printable form of a string from the document. */
98
+ function printable(value, limit) {
99
+ const short = value.length > limit ? `${value.slice(0, limit)}...` : value;
100
+ return short.replace(/[^\x20-\x7e]/g, "?");
101
+ }
102
+ /** A property name is printed only when it looks like a field name. */
103
+ const PLAIN_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,40}$/;
104
+ // The shapes `hq core secret-scan` uses (src/lib/core-utils/secret-patterns.ts),
105
+ // compiled once. Each needs a known credential prefix, so ordinary sentences
106
+ // that mention a token or a key do not match.
107
+ const CREDENTIAL_SHAPES = SECRET_PATTERNS.map(({ pattern, name }) => ({
108
+ name,
109
+ expression: new RegExp(`${SECRET_PATTERN_BOUNDARY}${pattern}`),
110
+ }));
111
+ function credentialShapes(text) {
112
+ if (text.length < 6)
113
+ return [];
114
+ return CREDENTIAL_SHAPES.flatMap(({ name, expression }) => (expression.test(text) ? [name] : []));
115
+ }
116
+ function pointerSegment(key) {
117
+ return key.replace(/~/g, "~0").replace(/\//g, "~1");
118
+ }
119
+ /**
120
+ * Every string in a profile is a name, a label or a sentence about where a
121
+ * value came from. None may hold a credential, so a string or property name
122
+ * shaped like one is an issue. The shape is named; the string is not printed.
123
+ */
124
+ function credentialIssues(value, at, out) {
125
+ if (typeof value === "string") {
126
+ const shapes = credentialShapes(value);
127
+ if (shapes.length > 0)
128
+ out.push({ path: at, message: `holds a string shaped like a credential (${shapes.join(", ")})` });
129
+ return;
130
+ }
131
+ if (Array.isArray(value)) {
132
+ value.forEach((entry, index) => credentialIssues(entry, `${at}/${index}`, out));
133
+ return;
134
+ }
135
+ if (value === null || typeof value !== "object")
136
+ return;
137
+ for (const [key, child] of Object.entries(value)) {
138
+ const shapes = credentialShapes(key);
139
+ if (shapes.length > 0) {
140
+ out.push({ path: at, message: `has a property name shaped like a credential (${shapes.join(", ")})` });
141
+ continue;
142
+ }
143
+ credentialIssues(child, `${at}/${pointerSegment(key)}`, out);
144
+ }
145
+ }
146
+ /** view.company must be one of declared.companies. */
147
+ function companyIssues(value) {
148
+ const view = value.view;
149
+ const declared = value.declared;
150
+ const company = view && typeof view === "object" ? view.company : undefined;
151
+ const companies = declared && typeof declared === "object" ? declared.companies : undefined;
152
+ if (typeof company !== "string" || !Array.isArray(companies))
153
+ return [];
154
+ if (companies.includes(company))
155
+ return [];
156
+ return [{ path: "/view/company", message: "must be one of declared.companies" }];
157
+ }
158
+ function issueFrom(error) {
159
+ // An "if" error only says that the paired "then" failed; the "then" errors
160
+ // carry the path and the rule.
161
+ if (error.keyword === "if")
162
+ return null;
163
+ let message = error.message ?? "is not valid";
164
+ const params = error.params;
165
+ const extra = params.additionalProperty ?? params.unevaluatedProperty;
166
+ if (typeof extra === "string") {
167
+ message = PLAIN_FIELD_NAME.test(extra) && credentialShapes(extra).length === 0
168
+ ? `must not have property "${extra}"`
169
+ : "must not have an unexpected property";
170
+ }
171
+ else if (error.keyword === "false schema") {
172
+ message = "is not allowed here";
173
+ }
174
+ return { path: error.instancePath, message };
175
+ }
176
+ function failure(code, message, issues = [], omitted = 0) {
177
+ return { ok: false, code, message, issues, issues_omitted: omitted };
178
+ }
179
+ /**
180
+ * Validate a parsed document. The schema_version is checked first, so a
181
+ * document from a later major version is refused by name and is not reported
182
+ * as a list of field errors against the v1 schema.
183
+ *
184
+ * Beyond the schema, two rules are checked here because JSON Schema cannot
185
+ * express them: view.company is one of declared.companies, and no string is
186
+ * shaped like a credential. At most ENVIRONMENT_PROFILE_MAX_ISSUES issues are
187
+ * returned; issues_omitted counts the rest.
188
+ */
189
+ export function validateEnvironmentProfile(value) {
190
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
191
+ return failure("not_an_object", "an environment profile must be a JSON object");
192
+ }
193
+ const version = value.schema_version;
194
+ if (version === undefined) {
195
+ return failure("missing_schema_version", `schema_version is missing; this CLI reads ${ENVIRONMENT_PROFILE_SCHEMA_VERSION}`);
196
+ }
197
+ if (version !== ENVIRONMENT_PROFILE_SCHEMA_VERSION) {
198
+ const named = typeof version === "string" ? `"${printable(version, 80)}"` : `of type ${typeof version}`;
199
+ return failure("unsupported_schema_version", `unsupported schema_version ${named}; this CLI reads ${ENVIRONMENT_PROFILE_SCHEMA_VERSION}`);
200
+ }
201
+ const validate = validator();
202
+ const schemaValid = validate(value);
203
+ const kept = [];
204
+ const seen = new Set();
205
+ let total = 0;
206
+ const add = (issue) => {
207
+ if (!issue)
208
+ return;
209
+ // Duplicates come from two branches reporting the same rule at the same
210
+ // path, close together, so remembering a bounded number of keys is enough.
211
+ const key = `${issue.path}\u0000${issue.message}`;
212
+ if (seen.has(key))
213
+ return;
214
+ if (seen.size < ENVIRONMENT_PROFILE_MAX_ISSUES * 100)
215
+ seen.add(key);
216
+ total += 1;
217
+ if (kept.length < ENVIRONMENT_PROFILE_MAX_ISSUES)
218
+ kept.push(issue);
219
+ };
220
+ // Rules outside the schema first, so a credential-shaped string is always
221
+ // among the listed issues however many schema errors follow.
222
+ const credentials = [];
223
+ credentialIssues(value, "", credentials);
224
+ for (const issue of credentials)
225
+ add(issue);
226
+ for (const issue of companyIssues(value))
227
+ add(issue);
228
+ if (!schemaValid)
229
+ for (const error of validate.errors ?? [])
230
+ add(issueFrom(error));
231
+ if (total === 0)
232
+ return { ok: true, profile: value };
233
+ kept.sort((a, b) => (a.path === b.path ? a.message.localeCompare(b.message) : a.path < b.path ? -1 : 1));
234
+ const omitted = total - kept.length;
235
+ const count = total === 1 ? "1 issue" : `${total} issues`;
236
+ const listed = omitted > 0 ? `; the first ${kept.length} are listed` : "";
237
+ return failure("invalid", `not a valid ${ENVIRONMENT_PROFILE_SCHEMA_VERSION} document (${count}${listed})`, kept, omitted);
238
+ }
239
+ /** Parse JSON text and validate it. The text is never echoed in a failure. */
240
+ export function parseEnvironmentProfile(text) {
241
+ let value;
242
+ try {
243
+ // A leading UTF-8 byte-order mark is not part of the JSON.
244
+ value = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
245
+ }
246
+ catch {
247
+ return failure("invalid_json", "the document is not valid JSON");
248
+ }
249
+ return validateEnvironmentProfile(value);
250
+ }
251
+ //# sourceMappingURL=profile.js.map
@@ -3,9 +3,10 @@ import { writeConfigAtomic, jsonFormat } from '../../commands/mcp-registration.j
3
3
  import { join } from 'node:path';
4
4
  import { homedir } from 'node:os';
5
5
  import { addHqHooks, removeHqHooks } from '../install/claude-targets.js';
6
- import { hookTargetFor } from '../install/hook-target.js';
6
+ import { legacyHookTarget } from '../install/hook-target.js';
7
7
  import { addCodexHooks, removeCodexHooks, codexHookEntry, codexHookTrustKeys } from '../install/codex-targets.js';
8
- import { engineArgs, isNativeEntry, registrationEngine } from './registration.js';
8
+ import { engineArgs, isCoreNextEntry, isNativeEntry, registrationEngine } from './registration.js';
9
+ import { coreNextArgs, coreNextTargetOrWarn } from '../../utils/host-registration.js';
9
10
  /** The project master-hook command shipped in HQ's .claude/settings.json. */
10
11
  function projectClaudeCommand(event) {
11
12
  return 'env BASH_ENV=/dev/null bash "$CLAUDE_PROJECT_DIR/.claude/hooks/master-hook.sh" ' + event;
@@ -24,7 +25,7 @@ function rewriteEntries(doc, convert) {
24
25
  return group;
25
26
  return { ...group, hooks: group.hooks.map((entry) => {
26
27
  const next = entry && typeof entry === 'object' ? convert(entry, event) : undefined;
27
- if (!next)
28
+ if (!next || JSON.stringify(next) === JSON.stringify(entry))
28
29
  return entry;
29
30
  changed = true;
30
31
  return next;
@@ -36,12 +37,23 @@ function rewriteEntries(doc, convert) {
36
37
  /** Reconcile existing registrations only; reindex must not install a runtime. */
37
38
  export function reconcileHookRegistrations(root, home = homedir(), env = process.env, daemonInstalled) {
38
39
  const result = { codexUserKeys: [], failures: [] };
39
- const engine = registrationEngine(home, env);
40
+ // `core.next` (hq-core-rust US-017) wins over the pinned launcher flag. Both
41
+ // off: registrations are left exactly as they are, or rolled back to the
42
+ // bash target when an earlier pass wrote a native entry.
43
+ // With `core.next` on, only the events the engine has every guard for
44
+ // switch (`coreNext.events`); the others keep the flag-off registration. A
45
+ // failure to set up the new core is one warning and the flag-off path.
46
+ const coreNext = coreNextTargetOrWarn(home, env);
47
+ const launcher = registrationEngine(home, env);
48
+ const native = coreNext ?? (launcher ? { engine: launcher } : null);
49
+ const ours = (entry) => isNativeEntry(entry, root) || isCoreNextEntry(entry, root);
40
50
  // Flag-off rollback restores the same bash target install would choose (the
41
51
  // hqd shim when the daemon serves this root). Resolved only when a
42
52
  // registration is rewritten, so the default-off path reads no daemon state.
43
53
  let target;
44
- const globalTarget = () => (target ??= engine ? { engine } : hookTargetFor(root, home, daemonInstalled, env));
54
+ const globalTarget = () => (target ??= coreNext
55
+ ? { ...coreNext, fallback: legacyHookTarget(root, home, daemonInstalled, env) }
56
+ : legacyHookTarget(root, home, daemonInstalled, env));
45
57
  const codexBash = (event) => [codexHookEntry(root, event, 'master').command, codexHookEntry(root, event, 'shim').command];
46
58
  for (const [file, runtime, global] of [
47
59
  [join(root, '.claude/settings.json'), 'claude', false],
@@ -57,7 +69,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
57
69
  // Default-off must not acquire a write lock or create backups for a legacy
58
70
  // registration. The merge below repeats this check under the lock when a
59
71
  // native entry was found, so a concurrent writer still wins safely.
60
- if (!engine) {
72
+ if (!native) {
61
73
  let current;
62
74
  // A file we cannot parse holds no native entry of ours; leave it untouched.
63
75
  try {
@@ -69,7 +81,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
69
81
  const entries = current?.hooks && typeof current.hooks === 'object'
70
82
  ? Object.values(current.hooks).flatMap(groups => Array.isArray(groups) ? groups.flatMap(g => Array.isArray(g?.hooks) ? g.hooks : []) : [])
71
83
  : [];
72
- if (!entries.some(e => e && isNativeEntry(e, root)))
84
+ if (!entries.some(e => e && ours(e)))
73
85
  continue;
74
86
  }
75
87
  let expected;
@@ -84,7 +96,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
84
96
  if (!doc || typeof doc !== 'object' || !doc.hooks || typeof doc.hooks !== 'object')
85
97
  return doc;
86
98
  const entries = Object.values(doc.hooks).flatMap(groups => Array.isArray(groups) ? groups.flatMap(g => Array.isArray(g?.hooks) ? g.hooks : []) : []);
87
- if (!engine && !entries.some(e => e && isNativeEntry(e, root)))
99
+ if (!native && !entries.some(e => e && ours(e)))
88
100
  return doc;
89
101
  if (global && (runtime === 'codex' ? removeCodexHooks(doc, root) : removeHqHooks(doc, root)) === doc)
90
102
  return doc;
@@ -95,10 +107,17 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
95
107
  // Only an entry install itself writes is converted. HQ's own project
96
108
  // file routes through hook-gate.sh and has none, so it stays as is.
97
109
  next = rewriteEntries(doc, (entry, event) => {
98
- if (!isNativeEntry(entry, root) && !codexBash(event).includes(entry.command))
110
+ if (!ours(entry) && !codexBash(event).includes(entry.command))
99
111
  return undefined;
100
112
  const { command: _command, commandWindows: _windows, ...rest } = entry;
101
113
  const { command, commandWindows } = codexHookEntry(root, event, globalTarget());
114
+ // To or from the new core (US-017), `command` keeps its place so
115
+ // switching back restores the original bytes. The launcher path
116
+ // keeps its existing key order.
117
+ if (isCoreNextEntry(entry, root) || coreNext) {
118
+ const { commandWindows: _old, ...inPlace } = entry;
119
+ return { ...inPlace, command, ...(commandWindows ? { commandWindows } : {}) };
120
+ }
102
121
  return { ...rest, command, ...(commandWindows ? { commandWindows } : {}) };
103
122
  });
104
123
  }
@@ -106,12 +125,19 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
106
125
  // Only the exact shipped master-hook command is converted; a wrapped
107
126
  // or extended invocation is someone's edit and is left alone.
108
127
  next = rewriteEntries(doc, (entry, event) => {
109
- if (!isNativeEntry(entry, root) && entry.command !== projectClaudeCommand(event))
128
+ if (!ours(entry) && entry.command !== projectClaudeCommand(event))
110
129
  return undefined;
111
130
  const { args, commandWindows: _windows, ...rest } = entry;
112
- if (engine)
113
- return { ...rest, command: engine, args: engineArgs(root, event, 'claude') };
114
- return { ...rest, command: projectClaudeCommand(Array.isArray(args) && typeof args[0] === 'string' ? args[0] : event) };
131
+ // The event an existing native entry was written for: the first
132
+ // launcher argument, or the one after `run --host claude`.
133
+ const written = Array.isArray(args) ? (args[0] === 'run' ? args[3] : args[0]) : undefined;
134
+ const original = typeof written === 'string' ? written : event;
135
+ // The new core only for an event it has every guard for.
136
+ if (coreNext?.events.includes(original))
137
+ return { ...rest, command: coreNext.coreNext, args: coreNextArgs('claude', original, root, 'project') };
138
+ if (launcher)
139
+ return { ...rest, command: launcher, args: engineArgs(root, original, 'claude') };
140
+ return { ...rest, command: projectClaudeCommand(original) };
115
141
  });
116
142
  }
117
143
  expected = JSON.stringify(next);
@@ -12,6 +12,15 @@ export declare function launcherRoot(root: string): string;
12
12
  export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
13
13
  /** Recognize only our pinned executable with the exact root argument. */
14
14
  export declare function isNativeEntry(entry: Record<string, unknown>, root: string): boolean;
15
+ /**
16
+ * A registration that calls the new core's entry point, `hq-hook run --host
17
+ * <host> <Event> --hq-root <root>`, through the release-stable link
18
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
19
+ * words and the exact root argument, in exec form (`args`) or as a command
20
+ * string (Codex, Grok).
21
+ */
22
+ export declare const CORE_NEXT_LINK: RegExp;
23
+ export declare function isCoreNextEntry(entry: Record<string, unknown>, root: string): boolean;
15
24
  export declare function quotePosix(value: string): string;
16
25
  export declare function quoteWindows(value: string): string;
17
26
  //# sourceMappingURL=registration.d.ts.map
@@ -40,6 +40,25 @@ export function isNativeEntry(entry, root) {
40
40
  }
41
41
  return entry.command.includes(quotePosix('--hq-root') + ' ' + quotePosix(spelling));
42
42
  }
43
+ /**
44
+ * A registration that calls the new core's entry point, `hq-hook run --host
45
+ * <host> <Event> --hq-root <root>`, through the release-stable link
46
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
47
+ * words and the exact root argument, in exec form (`args`) or as a command
48
+ * string (Codex, Grok).
49
+ */
50
+ export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
51
+ export function isCoreNextEntry(entry, root) {
52
+ if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
53
+ return false;
54
+ const spelling = launcherRoot(root);
55
+ if (Array.isArray(entry.args)) {
56
+ const i = entry.args.indexOf('--hq-root');
57
+ return entry.args[0] === 'run' && entry.args[1] === '--host' && i >= 0 && entry.args[i + 1] === spelling;
58
+ }
59
+ return entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`)
60
+ && entry.command.includes(`${quotePosix('--hq-root')} ${quotePosix(spelling)}`);
61
+ }
43
62
  export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
44
63
  export function quoteWindows(value) {
45
64
  // Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
@@ -72,6 +72,21 @@ export interface MeetingsAdapterOptions {
72
72
  /** Where a failing provider is reported. Default: a line on stderr. */
73
73
  warn?: (message: string) => void;
74
74
  }
75
+ /**
76
+ * The `signal_source_ref` alias for a bot transcript, or undefined when the
77
+ * transcript carries no id that is a safe path segment.
78
+ *
79
+ * Transcripts without `recall_bot_id` or `transcript_id` (Recall desktop-SDK
80
+ * recordings, legacy exports) fall back to the document `id`, which the
81
+ * meeting pipeline writes as `meeting:<id>`. A leading `meeting:` is stripped
82
+ * once from whichever id is used, so the alias is `meeting:<id>`, not
83
+ * `meeting:meeting:<id>`. An unsafe `recall_bot_id` does not fall back to
84
+ * another field: it names the bot, so a different id would split the
85
+ * transcript's signals from the live rider's. Anything still unsafe
86
+ * (a slash, `..`, another colon) gets no alias: the signals pass then keys the
87
+ * document by its file, and one odd record never fails the whole adapter.
88
+ */
89
+ export declare function transcriptSignalSourceRef(frontmatter: Record<string, unknown>, transcriptId: string): string | undefined;
75
90
  /** The adapter cursor: see the file comment. */
76
91
  export interface MeetingsCursor {
77
92
  vault: string | null;
@@ -193,7 +193,32 @@ async function readTranscript(dir, file, names) {
193
193
  },
194
194
  };
195
195
  }
196
- function toEvent(t) {
196
+ const MEETING_DOC_ID_PREFIX = "meeting:";
197
+ /**
198
+ * The `signal_source_ref` alias for a bot transcript, or undefined when the
199
+ * transcript carries no id that is a safe path segment.
200
+ *
201
+ * Transcripts without `recall_bot_id` or `transcript_id` (Recall desktop-SDK
202
+ * recordings, legacy exports) fall back to the document `id`, which the
203
+ * meeting pipeline writes as `meeting:<id>`. A leading `meeting:` is stripped
204
+ * once from whichever id is used, so the alias is `meeting:<id>`, not
205
+ * `meeting:meeting:<id>`. An unsafe `recall_bot_id` does not fall back to
206
+ * another field: it names the bot, so a different id would split the
207
+ * transcript's signals from the live rider's. Anything still unsafe
208
+ * (a slash, `..`, another colon) gets no alias: the signals pass then keys the
209
+ * document by its file, and one odd record never fails the whole adapter.
210
+ */
211
+ export function transcriptSignalSourceRef(frontmatter, transcriptId) {
212
+ const raw = nonEmptyString(frontmatter.recall_bot_id) ?? transcriptId;
213
+ const id = raw.startsWith(MEETING_DOC_ID_PREFIX) ? raw.slice(MEETING_DOC_ID_PREFIX.length) : raw;
214
+ try {
215
+ return meetingSignalSourceRef(id);
216
+ }
217
+ catch {
218
+ return undefined;
219
+ }
220
+ }
221
+ function toEvent(t, warn) {
197
222
  const when = new Date(t.tsMs).toISOString();
198
223
  const who = nonEmptyString(t.frontmatter.person_uid) ?? "unknown";
199
224
  const where = nonEmptyString(t.frontmatter.meeting_platform) ?? "meeting";
@@ -208,6 +233,10 @@ function toEvent(t) {
208
233
  `- Transcript: ${payloadRef}`,
209
234
  "",
210
235
  ].join("\n");
236
+ const signalSourceRef = transcriptSignalSourceRef(t.frontmatter, t.transcriptId);
237
+ if (signalSourceRef === undefined) {
238
+ warn(`meetings: ${t.file} has no meeting id that is a safe path segment; landing it without a signal_source_ref`);
239
+ }
211
240
  return {
212
241
  providerId: t.transcriptId,
213
242
  version: `${t.audienceVersion}.${t.bodyDigest}`,
@@ -219,7 +248,11 @@ function toEvent(t) {
219
248
  title: t.title,
220
249
  body,
221
250
  payloadRef,
222
- frontmatter: { audience_source: t.audienceSource, provider: MEETINGS_VAULT_SOURCE, signal_source_ref: meetingSignalSourceRef(nonEmptyString(t.frontmatter.recall_bot_id) ?? t.transcriptId) },
251
+ frontmatter: {
252
+ audience_source: t.audienceSource,
253
+ provider: MEETINGS_VAULT_SOURCE,
254
+ ...(signalSourceRef !== undefined ? { signal_source_ref: signalSourceRef } : {}),
255
+ },
223
256
  raw: { transcript: payloadRef, frontmatter: t.frontmatter, audience: [...t.audience], audience_source: t.audienceSource },
224
257
  };
225
258
  }
@@ -350,7 +383,7 @@ export function createMeetingsAdapter(options) {
350
383
  const page = newer.slice(0, end);
351
384
  const last = page[page.length - 1];
352
385
  return {
353
- events: [...atCursor, ...page].map(toEvent),
386
+ events: [...atCursor, ...page].map((t) => toEvent(t, warn)),
354
387
  cursor: last ? new Date(last.tsMs).toISOString() : cursor,
355
388
  hasMore: end < newer.length,
356
389
  all,
@@ -27,11 +27,18 @@
27
27
  * `slack_participants`.
28
28
  *
29
29
  * Slack pauses event delivery to an app that exceeds its rate limit and sends
30
- * `app_rate_limited`. A marker newer than the cursor (`_app_rate_limited.json`
31
- * or a document with `type: app_rate_limited` in `sources/slack/`, without a
32
- * `resolved_at`) fails the adapter with `SlackAppRateLimitedError`, whose
33
- * message lands in the run ledger's `error`. The cursor does not move.
34
- * Writing that marker from the webhook is an hq-pro-agents follow-up.
30
+ * `app_rate_limited`. hq-pro-agents' Slack receiver writes that as
31
+ * `_app_rate_limited.json` in `sources/slack/`: `at` is the first pause of an
32
+ * unresolved run, `last_at` the newest, and `resolved_at` is set once a later
33
+ * event for the same team arrives. A landed document with
34
+ * `type: app_rate_limited` counts the same way. A marker fails the adapter
35
+ * with `SlackAppRateLimitedError`, whose message lands in the run ledger's
36
+ * `error`, while all of these hold: it has no `resolved_at`, its newest pause
37
+ * (newest readable of `last_at`, `at`, `ingested_at`) is under an hour old,
38
+ * and that newest pause is after the cursor. The cursor does not move. A
39
+ * marker time more than five minutes ahead of now is ignored on its own. The
40
+ * hour limit exists because a quiet company may never send the later event
41
+ * that sets `resolved_at`.
35
42
  */
36
43
  import { type PollHotChannelAdapter } from "../contract.js";
37
44
  export declare const SLACK_ADAPTER_ID = "slack";
@@ -66,5 +73,14 @@ export interface SlackAdapterOptions {
66
73
  /** Threads newer than the cursor per page. Default 100. */
67
74
  pageSize?: number;
68
75
  }
76
+ /**
77
+ * An open marker whose newest pause is older than this is treated as resolved.
78
+ * While Slack keeps an app paused it sends `app_rate_limited` about once a
79
+ * minute and the receiver moves `last_at` forward, so an ongoing pause stays
80
+ * well inside this window. The receiver only sets `resolved_at` when a later
81
+ * event for the team arrives, so a quiet company would otherwise keep an open
82
+ * marker, and a failing Slack sync, forever.
83
+ */
84
+ export declare const SLACK_RATE_LIMIT_MARKER_MAX_AGE_MS: number;
69
85
  export declare function createSlackAdapter(options: SlackAdapterOptions): PollHotChannelAdapter;
70
86
  //# sourceMappingURL=slack.d.ts.map