@indigoai-us/hq-cli 5.345.220 → 5.345.222

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 (184) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/dist/command-catalog.generated.d.ts +175 -2
  3. package/dist/command-catalog.generated.js +213 -2
  4. package/dist/commands/auth.js +6 -2
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +39 -2
  8. package/dist/commands/bot.js +140 -11
  9. package/dist/commands/core-delegate-w1b.js +9 -3
  10. package/dist/commands/core-stop-autosave.d.ts +21 -0
  11. package/dist/commands/core-stop-autosave.js +300 -0
  12. package/dist/commands/core.js +2 -0
  13. package/dist/commands/daemon.d.ts +6 -0
  14. package/dist/commands/daemon.js +46 -8
  15. package/dist/commands/doctor-usage.d.ts +5 -0
  16. package/dist/commands/doctor-usage.js +25 -0
  17. package/dist/commands/env.d.ts +49 -4
  18. package/dist/commands/env.js +355 -5
  19. package/dist/commands/lanes-shared.d.ts +3 -0
  20. package/dist/commands/lanes.d.ts +3 -0
  21. package/dist/commands/lanes.js +87 -3
  22. package/dist/commands/link.d.ts +2 -0
  23. package/dist/commands/link.js +14 -2
  24. package/dist/commands/mesh.js +23 -3
  25. package/dist/commands/sources.js +3 -3
  26. package/dist/commands/sync-core.d.ts +7 -0
  27. package/dist/commands/sync-core.js +132 -3
  28. package/dist/commands/whoami.js +96 -80
  29. package/dist/data/command-states.json +3 -0
  30. package/dist/lib/bot/config.d.ts +17 -0
  31. package/dist/lib/bot/config.js +13 -0
  32. package/dist/lib/bot/fleet-cron.js +24 -2
  33. package/dist/lib/bot/fleet-local.d.ts +30 -2
  34. package/dist/lib/bot/fleet-local.js +60 -1
  35. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  36. package/dist/lib/bot/grok-login-scope.js +93 -0
  37. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  38. package/dist/lib/bot/legacy-provider-login.js +28 -22
  39. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  40. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  41. package/dist/lib/core-utils/sentry-report.js +2 -0
  42. package/dist/lib/daemon/catalog.js +2 -0
  43. package/dist/lib/daemon/install.d.ts +2 -1
  44. package/dist/lib/daemon/install.js +9 -0
  45. package/dist/lib/daemon/legacy.d.ts +1 -0
  46. package/dist/lib/daemon/legacy.js +5 -2
  47. package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
  48. package/dist/lib/daemon/machine-check-owner.js +6 -1
  49. package/dist/lib/daemon/machine-checks.d.ts +29 -2
  50. package/dist/lib/daemon/machine-checks.js +64 -13
  51. package/dist/lib/daemon/mesh-owner.d.ts +45 -0
  52. package/dist/lib/daemon/mesh-owner.js +166 -0
  53. package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
  54. package/dist/lib/daemon/native-notice-ledger.js +113 -0
  55. package/dist/lib/daemon/run.d.ts +15 -0
  56. package/dist/lib/daemon/run.js +137 -11
  57. package/dist/lib/daemon/selfcheck.d.ts +35 -2
  58. package/dist/lib/daemon/selfcheck.js +118 -9
  59. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  60. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  61. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  62. package/dist/lib/daemon/stop-autosave.js +111 -0
  63. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  64. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  65. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  66. package/dist/lib/daemon/stop-job-executor.js +126 -0
  67. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  68. package/dist/lib/daemon/stop-jobs.js +599 -0
  69. package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
  70. package/dist/lib/doctor/checks/host-core.js +1 -1
  71. package/dist/lib/environment/access-probes.d.ts +234 -0
  72. package/dist/lib/environment/access-probes.js +918 -0
  73. package/dist/lib/environment/profile.d.ts +15 -2
  74. package/dist/lib/environment/profile.js +55 -20
  75. package/dist/lib/environment/rfc3339.d.ts +8 -0
  76. package/dist/lib/environment/rfc3339.js +26 -0
  77. package/dist/lib/environment/work-requirements.d.ts +169 -0
  78. package/dist/lib/environment/work-requirements.js +389 -0
  79. package/dist/lib/hook-engine/coverage.d.ts +146 -7
  80. package/dist/lib/hook-engine/coverage.js +1480 -4
  81. package/dist/lib/hook-engine/fleet-registration.js +2 -2
  82. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  83. package/dist/lib/hook-engine/native-stop-compatibility.json +362 -0
  84. package/dist/lib/hook-engine/reconcile.js +2 -2
  85. package/dist/lib/hot-channels/alert.d.ts +2 -2
  86. package/dist/lib/hot-channels/alert.js +8 -5
  87. package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
  88. package/dist/lib/hot-channels/signals-pass.js +296 -17
  89. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  90. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  91. package/dist/lib/install/hook-target.js +1 -1
  92. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  93. package/dist/lib/lanes/host-capacity.js +17 -2
  94. package/dist/lib/lanes/host-compute.d.ts +90 -0
  95. package/dist/lib/lanes/host-compute.js +185 -0
  96. package/dist/lib/lanes/index.d.ts +2 -0
  97. package/dist/lib/lanes/index.js +1 -0
  98. package/dist/lib/lanes/reconcile.js +22 -1
  99. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  100. package/dist/lib/lanes/resource-usage.js +589 -0
  101. package/dist/lib/lanes/run-size.d.ts +46 -0
  102. package/dist/lib/lanes/run-size.js +197 -0
  103. package/dist/lib/lanes/store.js +27 -0
  104. package/dist/lib/lanes/throttle.d.ts +36 -1
  105. package/dist/lib/lanes/throttle.js +47 -10
  106. package/dist/lib/lanes/types.d.ts +40 -0
  107. package/dist/lib/lanes/types.js +2 -2
  108. package/dist/lib/lanes/watcher.js +13 -4
  109. package/dist/lib/lanes/worker-process.d.ts +25 -2
  110. package/dist/lib/lanes/worker-process.js +71 -19
  111. package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
  112. package/dist/lib/mesh/live/daemon/config.js +16 -0
  113. package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
  114. package/dist/lib/mesh/live/daemon/install.js +142 -1
  115. package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
  116. package/dist/lib/mesh/live/daemon/login-home.js +27 -0
  117. package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
  118. package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/registry/registry.d.ts +35 -7
  122. package/dist/lib/registry/registry.js +88 -13
  123. package/dist/lib/safe-store.d.ts +14 -0
  124. package/dist/lib/safe-store.js +77 -4
  125. package/dist/lib/scan-packages/index.js +24 -2
  126. package/dist/lib/search-index/index.d.ts +88 -4
  127. package/dist/lib/search-index/index.js +288 -24
  128. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  129. package/dist/lib/search-index/max-doc-bytes.js +49 -23
  130. package/dist/lib/service-manager/startup-migration.d.ts +1 -0
  131. package/dist/lib/service-manager/startup-migration.js +3 -0
  132. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  133. package/dist/lib/signals/codex-lockdown.js +271 -0
  134. package/dist/lib/signals/codex-login.d.ts +37 -0
  135. package/dist/lib/signals/codex-login.js +83 -0
  136. package/dist/lib/signals/engine.d.ts +27 -0
  137. package/dist/lib/signals/engine.js +70 -0
  138. package/dist/lib/signals/reply.js +22 -1
  139. package/dist/lib/signals/run-record.js +6 -1
  140. package/dist/lib/signals/settings.d.ts +5 -0
  141. package/dist/lib/signals/settings.js +2 -0
  142. package/dist/lib/signals/steps/extract.d.ts +85 -9
  143. package/dist/lib/signals/steps/extract.js +317 -68
  144. package/dist/lib/signals/steps/types.d.ts +2 -0
  145. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  146. package/dist/lib/sync-core/engine-holds.js +60 -0
  147. package/dist/lib/sync-core/engine-home.d.ts +37 -1
  148. package/dist/lib/sync-core/engine-home.js +119 -16
  149. package/dist/lib/sync-core/reconcile.js +8 -0
  150. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  151. package/dist/lib/sync-core/rollout-state.js +5 -2
  152. package/dist/lib/sync-core/vault-settings.d.ts +21 -0
  153. package/dist/lib/sync-core/vault-settings.js +131 -0
  154. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  155. package/dist/lib/sync-core/vault-uid.js +4 -0
  156. package/dist/lib/windows/install-followup.d.ts +2 -0
  157. package/dist/lib/windows/install-followup.js +4 -1
  158. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  159. package/dist/utils/auth-session-check.d.ts +16 -0
  160. package/dist/utils/auth-session-check.js +16 -0
  161. package/dist/utils/client-health-contract.d.ts +6 -0
  162. package/dist/utils/client-health-contract.js +13 -0
  163. package/dist/utils/client-health.d.ts +7 -0
  164. package/dist/utils/client-health.js +22 -1
  165. package/dist/utils/command-usage.d.ts +40 -0
  166. package/dist/utils/command-usage.js +61 -0
  167. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  168. package/dist/utils/duplicate-command-usage.js +125 -0
  169. package/dist/utils/host-registration.js +5 -2
  170. package/dist/utils/pack-contributions.d.ts +3 -0
  171. package/dist/utils/pack-contributions.js +110 -23
  172. package/dist/utils/resident-package-preload.js +4 -0
  173. package/dist/utils/self-update.d.ts +3 -1
  174. package/dist/utils/self-update.js +56 -11
  175. package/dist/utils/sentry-fingerprint.js +9 -0
  176. package/dist/utils/update-lock.d.ts +151 -14
  177. package/dist/utils/update-lock.js +782 -46
  178. package/dist/utils/version-gate.js +12 -2
  179. package/dist/utils/windows-bash.d.ts +2 -0
  180. package/dist/utils/windows-bash.js +2 -1
  181. package/package.json +9 -8
  182. package/scripts/bench-core-compare.mjs +313 -0
  183. package/scripts/bench-core.mjs +399 -12
  184. package/scripts/check-function-manifest.mjs +116 -3
@@ -0,0 +1,389 @@
1
+ /**
2
+ * hq-work-requirements.v1: what one piece of work (a lane, a story, a
3
+ * scheduled job, a message to a bot) needs from an environment.
4
+ *
5
+ * This module holds the TypeScript shape, a validator for
6
+ * src/schemas/hq-work-requirements.v1.schema.json that refuses any other
7
+ * schema_version, and deriveWorkRequirements(), which builds the document for
8
+ * work that declares nothing:
9
+ *
10
+ * - company: the lane's own company when it has one, otherwise the primary
11
+ * company of the session lock (workspace/sessions/<id>/meta.yaml), and
12
+ * "personal" when neither exists;
13
+ * - engines: any (every engine the schema knows);
14
+ * - needs.repos: the repo under repos/public or repos/private that the work
15
+ * was created in, including from a git worktree of that repo;
16
+ * - on_no_fit: conductor-harness, the conductor's own harness (owner
17
+ * decision 3, 2026-11-13).
18
+ *
19
+ * The derivation reads only paths and the session lock's company line. It
20
+ * never reads environment values other than the session id, and secret needs
21
+ * are names only, so a derived document cannot carry a secret value.
22
+ *
23
+ * Failure text never contains a value taken from the document, apart from a
24
+ * shortened schema_version, for the same reason as the environment profile
25
+ * loader: a rejected field may be holding a credential.
26
+ */
27
+ import * as fs from "node:fs";
28
+ import * as path from "node:path";
29
+ import { fileURLToPath } from "node:url";
30
+ import Ajv2020 from "ajv/dist/2020.js";
31
+ import { sessionIdFromEnv } from "../core-utils/session-id.js";
32
+ import { sessionMetaCompanies } from "../core-utils/session-company.js";
33
+ import { credentialShapesIn } from "./credential-shapes.js";
34
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
35
+ export const WORK_REQUIREMENTS_SCHEMA_VERSION = "hq-work-requirements.v1";
36
+ export const WORK_REQUIREMENTS_SCHEMA_ID = "urn:hq:schema:hq-work-requirements:v1";
37
+ export const WORK_REQUIREMENTS_SCHEMA_PATH = path.join(HERE, "..", "..", "schemas", "hq-work-requirements.v1.schema.json");
38
+ /** Every engine the schema knows. A derived document lists all of them, which means any. */
39
+ export const WORK_ENGINES_ANY = ["claude", "codex", "grok"];
40
+ export const WORK_ON_NO_FIT_CONDUCTOR_HARNESS = "conductor-harness";
41
+ export const WORK_REQUIREMENTS_MAX_ISSUES = 100;
42
+ const COMPANY_SLUG = /^[a-z0-9][a-z0-9-]*$/;
43
+ const REPO_NAME = /^[A-Za-z0-9._-]+$/;
44
+ /** Same pattern as needs.secrets in the schema. */
45
+ export const WORK_SECRET_NAME = /^[A-Z0-9_]+(\/[A-Z0-9_]+)*$/;
46
+ const PLAIN_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,40}$/;
47
+ let cachedValidate;
48
+ function validator() {
49
+ if (cachedValidate)
50
+ return cachedValidate;
51
+ const schema = JSON.parse(fs.readFileSync(WORK_REQUIREMENTS_SCHEMA_PATH, "utf8"));
52
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
53
+ cachedValidate = ajv.compile(schema);
54
+ return cachedValidate;
55
+ }
56
+ function printable(value, limit) {
57
+ const short = value.length > limit ? `${value.slice(0, limit)}...` : value;
58
+ return short.replace(/[^\x20-\x7e]/g, "?");
59
+ }
60
+ function pointerSegment(key) {
61
+ return key.replace(/~/g, "~0").replace(/\//g, "~1");
62
+ }
63
+ /** A lane id as mintLaneId writes it: a ULID, an underscore and a sanitized host name. */
64
+ const LANE_ID = /^[0-9A-HJKMNP-TV-Z]{26}_[a-z0-9-]{1,32}$/;
65
+ /**
66
+ * JSON pointers of the identifiers deriveWorkRequirements itself filled in:
67
+ * the company slug it resolved, the repo directory names it found and the
68
+ * lane id it was given. A company, repo or host whose real name happens to
69
+ * start like a token ("sk-...") is still only a name, so the derivation's own
70
+ * check does not credential-scan these. The public validator scans every
71
+ * field, so a token pasted into a declared document is always rejected.
72
+ */
73
+ function identifierPaths(value) {
74
+ const paths = new Set(["/company"]);
75
+ const needs = value.needs;
76
+ if (needs && Array.isArray(needs.repos))
77
+ needs.repos.forEach((_, index) => paths.add(`/needs/repos/${index}`));
78
+ const origin = value.origin;
79
+ if (origin && origin.kind === "lane" && typeof origin.ref === "string" && LANE_ID.test(origin.ref)) {
80
+ paths.add("/origin/ref");
81
+ if (value.id === `work:lane:${origin.ref}`)
82
+ paths.add("/id");
83
+ }
84
+ return paths;
85
+ }
86
+ /** A string or property name shaped like a credential is an issue; the string is not printed. */
87
+ function credentialIssues(value, at, out, skip = new Set()) {
88
+ if (skip.has(at))
89
+ return;
90
+ if (typeof value === "string") {
91
+ const shapes = credentialShapesIn(value);
92
+ if (shapes.length > 0)
93
+ out.push({ path: at, message: `holds a string shaped like a credential (${shapes.join(", ")})` });
94
+ return;
95
+ }
96
+ if (Array.isArray(value)) {
97
+ value.forEach((entry, index) => credentialIssues(entry, `${at}/${index}`, out, skip));
98
+ return;
99
+ }
100
+ if (value === null || typeof value !== "object")
101
+ return;
102
+ for (const [key, child] of Object.entries(value)) {
103
+ const shapes = credentialShapesIn(key);
104
+ if (shapes.length > 0) {
105
+ out.push({ path: at, message: `has a property name shaped like a credential (${shapes.join(", ")})` });
106
+ continue;
107
+ }
108
+ credentialIssues(child, `${at}/${pointerSegment(key)}`, out, skip);
109
+ }
110
+ }
111
+ function issueFrom(error) {
112
+ if (error.keyword === "if")
113
+ return null;
114
+ let message = error.message ?? "is not valid";
115
+ const params = error.params;
116
+ const extra = params.additionalProperty;
117
+ if (typeof extra === "string") {
118
+ message = PLAIN_FIELD_NAME.test(extra) && credentialShapesIn(extra).length === 0
119
+ ? `must not have property "${extra}"`
120
+ : "must not have an unexpected property";
121
+ }
122
+ // Ajv's other messages quote the rule (a pattern, the allowed values, a
123
+ // required property), never the rejected value.
124
+ return { path: error.instancePath, message };
125
+ }
126
+ function failure(code, message, issues = [], omitted = 0) {
127
+ return { ok: false, code, message, issues, issues_omitted: omitted };
128
+ }
129
+ /**
130
+ * Validate a parsed document against hq-work-requirements.v1. A document of
131
+ * another schema_version is refused by name. Strings shaped like a credential
132
+ * are rejected anywhere in the document, identifiers included.
133
+ */
134
+ export function validateWorkRequirements(value) {
135
+ return validateDocument(value, false);
136
+ }
137
+ /**
138
+ * The validator body. tolerateDerivedIdentifiers is used only by
139
+ * deriveWorkRequirements, for the identifiers it resolved itself.
140
+ */
141
+ function validateDocument(value, tolerateDerivedIdentifiers) {
142
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
143
+ return failure("not_an_object", "a work requirements document must be a JSON object");
144
+ }
145
+ const version = value.schema_version;
146
+ if (version === undefined) {
147
+ return failure("missing_schema_version", `schema_version is missing; this CLI reads ${WORK_REQUIREMENTS_SCHEMA_VERSION}`);
148
+ }
149
+ if (version !== WORK_REQUIREMENTS_SCHEMA_VERSION) {
150
+ const named = typeof version === "string" ? `"${printable(version, 80)}"` : `of type ${typeof version}`;
151
+ return failure("unsupported_schema_version", `unsupported schema_version ${named}; this CLI reads ${WORK_REQUIREMENTS_SCHEMA_VERSION}`);
152
+ }
153
+ const validate = validator();
154
+ const schemaValid = validate(value);
155
+ const all = [];
156
+ credentialIssues(value, "", all, tolerateDerivedIdentifiers ? identifierPaths(value) : new Set());
157
+ if (!schemaValid) {
158
+ for (const error of validate.errors ?? []) {
159
+ const issue = issueFrom(error);
160
+ if (issue)
161
+ all.push(issue);
162
+ }
163
+ }
164
+ const seen = new Set();
165
+ const unique = all.filter((issue) => {
166
+ const key = `${issue.path}\u0000${issue.message}`;
167
+ if (seen.has(key))
168
+ return false;
169
+ seen.add(key);
170
+ return true;
171
+ });
172
+ if (unique.length === 0)
173
+ return { ok: true, requirements: value };
174
+ const kept = unique.slice(0, WORK_REQUIREMENTS_MAX_ISSUES);
175
+ kept.sort((a, b) => (a.path === b.path ? a.message.localeCompare(b.message) : a.path < b.path ? -1 : 1));
176
+ const omitted = unique.length - kept.length;
177
+ const count = unique.length === 1 ? "1 issue" : `${unique.length} issues`;
178
+ return failure("invalid", `not a valid ${WORK_REQUIREMENTS_SCHEMA_VERSION} document (${count})`, kept, omitted);
179
+ }
180
+ /** Parse JSON text and validate it. The text is never echoed in a failure. */
181
+ export function parseWorkRequirements(text) {
182
+ let value;
183
+ try {
184
+ value = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
185
+ }
186
+ catch {
187
+ return failure("invalid_json", "the document is not valid JSON");
188
+ }
189
+ return validateWorkRequirements(value);
190
+ }
191
+ function realpathOrSelf(target) {
192
+ try {
193
+ return fs.realpathSync(target);
194
+ }
195
+ catch {
196
+ return path.resolve(target);
197
+ }
198
+ }
199
+ /** The first path segment of `child` below `parent`, or null when it is not below it. */
200
+ function firstSegmentBelow(parent, child) {
201
+ const rel = path.relative(parent, child);
202
+ if (!rel || rel.startsWith("..") || path.isAbsolute(rel))
203
+ return null;
204
+ return rel.split(path.sep)[0] ?? null;
205
+ }
206
+ function repoUnderRepos(hqRoot, dir) {
207
+ const root = realpathOrSelf(hqRoot);
208
+ const target = realpathOrSelf(dir);
209
+ for (const visibility of ["public", "private"]) {
210
+ const base = path.join(root, "repos", visibility);
211
+ const name = firstSegmentBelow(base, target);
212
+ if (name)
213
+ return { name, repo_path: path.posix.join("repos", visibility, name), via: "repo-directory" };
214
+ }
215
+ return null;
216
+ }
217
+ /** For a linked git worktree, the main checkout the worktree belongs to. */
218
+ function worktreeMainCheckout(dir) {
219
+ let current = realpathOrSelf(dir);
220
+ for (let depth = 0; depth < 64; depth += 1) {
221
+ const dotGit = path.join(current, ".git");
222
+ let stat;
223
+ try {
224
+ stat = fs.lstatSync(dotGit);
225
+ }
226
+ catch {
227
+ stat = undefined;
228
+ }
229
+ if (stat?.isDirectory())
230
+ return null;
231
+ if (stat?.isFile()) {
232
+ let text;
233
+ try {
234
+ text = fs.readFileSync(dotGit, "utf8");
235
+ }
236
+ catch {
237
+ return null;
238
+ }
239
+ const gitdir = /^gitdir:\s*(.+?)\s*$/m.exec(text)?.[1];
240
+ if (!gitdir)
241
+ return null;
242
+ const absolute = path.resolve(current, gitdir);
243
+ const marker = `${path.sep}.git${path.sep}worktrees${path.sep}`;
244
+ const at = absolute.lastIndexOf(marker);
245
+ return at > 0 ? absolute.slice(0, at) : null;
246
+ }
247
+ const parent = path.dirname(current);
248
+ if (parent === current)
249
+ return null;
250
+ current = parent;
251
+ }
252
+ return null;
253
+ }
254
+ /**
255
+ * The HQ repo that `cwd` is in: a directory under repos/public or
256
+ * repos/private, or a linked git worktree whose main checkout is one.
257
+ */
258
+ export function workRepoFromCwd(hqRoot, cwd) {
259
+ const direct = repoUnderRepos(hqRoot, cwd);
260
+ if (direct)
261
+ return direct;
262
+ const main = worktreeMainCheckout(cwd);
263
+ if (!main)
264
+ return null;
265
+ const viaWorktree = repoUnderRepos(hqRoot, main);
266
+ return viaWorktree ? { ...viaWorktree, via: "git-worktree" } : null;
267
+ }
268
+ /** Defaults for the size block; nothing about undeclared work is measured. */
269
+ export const DERIVED_WORK_SIZE = {
270
+ vcpu: 1,
271
+ memory_mb: 1024,
272
+ disk_gb: 1,
273
+ expected_run_seconds: 3600,
274
+ };
275
+ /**
276
+ * Requirements for work that declares nothing. The result always validates
277
+ * against hq-work-requirements.v1; an input that cannot be used (a company
278
+ * slug or repo name outside the schema's patterns) is left out and named in
279
+ * assumptions.
280
+ */
281
+ export function deriveWorkRequirements(input) {
282
+ const env = input.env ?? process.env;
283
+ const derivedFrom = [];
284
+ const assumptions = [
285
+ "No requirements were declared; this document was derived (hq-work-requirements.v1 defaults).",
286
+ "engines lists every engine the schema knows, meaning any; the order is not a preference.",
287
+ "size is a default, not a measurement.",
288
+ "on_no_fit conductor-harness: run on the conductor's own harness when no environment fits (owner decision 3).",
289
+ ];
290
+ let company = null;
291
+ const own = input.company?.trim();
292
+ if (own) {
293
+ if (COMPANY_SLUG.test(own)) {
294
+ company = own;
295
+ derivedFrom.push("company: the work's own company");
296
+ }
297
+ else {
298
+ assumptions.push("The work's own company slug is outside the schema pattern and was not used.");
299
+ }
300
+ }
301
+ if (company === null) {
302
+ const sessionId = sessionIdFromEnv(env);
303
+ let locked = [];
304
+ try {
305
+ locked = sessionId ? sessionMetaCompanies(input.hqRoot, sessionId, env) : [];
306
+ }
307
+ catch {
308
+ assumptions.push("The session lock could not be read.");
309
+ }
310
+ const primary = locked[0];
311
+ if (primary && COMPANY_SLUG.test(primary)) {
312
+ company = primary;
313
+ derivedFrom.push("company: session lock (workspace/sessions/<session>/meta.yaml company_slug)");
314
+ }
315
+ else if (primary) {
316
+ assumptions.push("The session lock's company slug is outside the schema pattern and was not used.");
317
+ }
318
+ }
319
+ if (company === null) {
320
+ company = "personal";
321
+ assumptions.push("No company on the work and no session lock; company is personal.");
322
+ }
323
+ const repos = [];
324
+ const repo = workRepoFromCwd(input.hqRoot, input.cwd);
325
+ if (repo && REPO_NAME.test(repo.name)) {
326
+ repos.push(repo.name);
327
+ // The repo name is in needs.repos; it is not repeated in free text,
328
+ // where the credential scan applies.
329
+ derivedFrom.push(repo.via === "git-worktree"
330
+ ? "repo: created in a git worktree of a repo under repos/"
331
+ : "repo: created in a repo under repos/");
332
+ }
333
+ else if (repo) {
334
+ assumptions.push("The repo directory name is outside the schema pattern and was not used.");
335
+ }
336
+ else {
337
+ assumptions.push("The work was not created inside a repo under repos/; needs.repos is empty.");
338
+ }
339
+ const document = {
340
+ schema_version: WORK_REQUIREMENTS_SCHEMA_VERSION,
341
+ id: `work:${input.origin.kind}:${input.origin.ref}`,
342
+ ...(input.title !== undefined && input.title.trim() ? { title: input.title.trim() } : {}),
343
+ origin: { kind: input.origin.kind, ref: input.origin.ref, derived_from: derivedFrom },
344
+ company,
345
+ engines: { any_of: [...WORK_ENGINES_ANY], account_pin: null },
346
+ needs: { labels: [], repos, secrets: [], integrations: [] },
347
+ size: {
348
+ ...DERIVED_WORK_SIZE,
349
+ provenance: { source: "default for work that declares nothing; not measured", verified: false },
350
+ },
351
+ continuity: { mode: "none", checkpoint_ref: null },
352
+ tolerates: [],
353
+ on_no_fit: WORK_ON_NO_FIT_CONDUCTOR_HARNESS,
354
+ max_cost_usd: null,
355
+ assumptions,
356
+ };
357
+ const checked = validateDocument(document, true);
358
+ if (!checked.ok) {
359
+ // Only reachable through a ref or title that breaks the schema or looks
360
+ // like a credential. Drop the title and fall back to a plain id rather
361
+ // than refuse to create the work.
362
+ delete document.title;
363
+ document.id = `work:${input.origin.kind}`;
364
+ document.origin = { kind: input.origin.kind, ref: "unknown", derived_from: derivedFrom };
365
+ document.assumptions = [...assumptions, "The origin ref or title could not be recorded."];
366
+ const retry = validateDocument(document, true);
367
+ if (!retry.ok) {
368
+ throw new Error(`derived ${WORK_REQUIREMENTS_SCHEMA_VERSION} document is invalid: ${retry.issues.map((i) => `${i.path} ${i.message}`).join("; ")}`);
369
+ }
370
+ }
371
+ return document;
372
+ }
373
+ /**
374
+ * A derived document after the work's company was repaired (hq lanes
375
+ * repair-company). The company and the company line of derived_from are
376
+ * replaced; a slug outside the schema pattern leaves the document as it is.
377
+ */
378
+ export function withRepairedCompany(document, company) {
379
+ if (!COMPANY_SLUG.test(company))
380
+ return document;
381
+ const derivedFrom = (document.origin.derived_from ?? []).filter((entry) => !entry.startsWith("company:"));
382
+ return {
383
+ ...document,
384
+ company,
385
+ origin: { ...document.origin, derived_from: ["company: the work's own company (set by hq lanes repair-company)", ...derivedFrom] },
386
+ assumptions: (document.assumptions ?? []).filter((entry) => !entry.startsWith("No company on the work")),
387
+ };
388
+ }
389
+ //# sourceMappingURL=work-requirements.js.map
@@ -1,15 +1,154 @@
1
1
  import type { CoreNextHost, CoreNextTarget } from '../../utils/host-registration.js';
2
2
  /** Stands for the hook list when it cannot be read; never covered. */
3
3
  export declare const UNREADABLE = "(the old dispatcher hook list could not be read)";
4
+ /** One item of a Git config file as git 2.50 reads it: a section header, or a variable under the last one. */
5
+ export type GitConfigItem = {
6
+ header: true;
7
+ section: string;
8
+ subsection: string | null;
9
+ } | {
10
+ header: false;
11
+ section: string;
12
+ subsection: string | null;
13
+ key: string;
14
+ value: string | null;
15
+ };
16
+ /**
17
+ * Review r18b, as Rust `stop::compat::git_config_parse`: git 2.50's own config tokenizer (config.c
18
+ * `git_parse_source`, `get_base_var`, `get_extended_base_var`, `get_value`, `parse_value`), so a value is read
19
+ * exactly as git reads it: double quotes, the escapes `\"` `\\` `\n` `\t` `\b`, `#` and `;` comments outside
20
+ * quotes, a trailing `\` continuing the value on the next line, and blanks trimmed outside quotes. Section and
21
+ * key are ASCII-lowercased; a subsection keeps its case (`\` escapes the next character). A variable before
22
+ * any header has section `''` (git lists it and ignores it). `text` has no CR or NUL (the caller holds those).
23
+ * Returns null where git stops with "bad config line" (an unterminated quote, an unknown escape, a bad key or
24
+ * header), and also for the legacy `[section.sub]` spelling, which is not modeled.
25
+ */
26
+ export declare function gitConfigParse(text: string): GitConfigItem[] | null;
27
+ /** Whether hook `id` runs under `HQ_HOOK_PROFILE` and `HQ_DISABLED_HOOKS` (`stop::enabled_by`). Empty values count as unset. */
28
+ export declare function enabledBy(env: NodeJS.ProcessEnv, id: string): boolean;
29
+ /**
30
+ * The `GIT_*` variables that do not hold the native Stop
31
+ * (`gitEnvironmentAllowlist`, shared with `stop::compat::git_environment_allowlist`).
32
+ * Each is exempt only because it cannot change what the Git-reading Stop hooks'
33
+ * commands (`rev-parse --abbrev-ref HEAD`, `rev-parse --short HEAD`,
34
+ * `rev-parse --show-toplevel`, `log --oneline -50`, `status --porcelain=v1 -z
35
+ * --untracked-files=all`, `check-ignore -q --no-index`, `commit -m`) or `git
36
+ * config -l` print, or whether git dies. Lab, git 2.50.1: each set to empty,
37
+ * `bogus`, `0`, `1`, `false`, `/nonexistent/prog` and a non-UTF-8 value left
38
+ * every one of those commands' stdout, stderr and exit status unchanged.
39
+ *
40
+ * - `GIT_EDITOR`: read only when git starts an editor, which no Stop hook
41
+ * does. Claude Code exports it to the shells and hooks it starts, so without
42
+ * it every native Stop under Claude Code would be refused.
43
+ * - `GIT_PAGER`: read only when git pages to a terminal; hook output is a
44
+ * pipe. (`GIT_PAGER_IN_USE` is a different, boolean variable and holds.)
45
+ * - `GIT_ASKPASS`, `GIT_TERMINAL_PROMPT`: read only when git prompts for
46
+ * credentials, which local reads and commits never do.
47
+ *
48
+ * Everything else under `GIT_` holds, `GIT_CONFIG_COUNT` and its
49
+ * `GIT_CONFIG_KEY_<n>`/`GIT_CONFIG_VALUE_<n>` pairs included (review r17 C3).
50
+ */
51
+ export declare const GIT_ENVIRONMENT_ALLOWLIST: readonly string[];
52
+ /**
53
+ * The first `GIT_*` variable name in `env` (sorted) outside the allowlist, or
54
+ * null. Names only: a variable is present whatever its value, empty included
55
+ * (review r17 C4: Rust reads names with `vars_os`, so a non-UTF-8 value counts
56
+ * on both sides). Windows variable names are not case-sensitive, so there the
57
+ * prefix and the allowlist are compared without case, as in Rust.
58
+ */
59
+ export declare function gitEnvironmentOverride(env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string | null;
60
+ /**
61
+ * Review r20 C1, as `git_discovery::version_zero_extension`: the repository
62
+ * extensions git accepts at `repositoryformatversion = 0` (and 1), other than
63
+ * `worktreeConfig`. `key` is lowercase; `value` is null for a bare key.
64
+ */
65
+ export declare function versionZeroExtension(key: string, value: string | null): boolean;
66
+ /** One allowlisted variable of `git-stop-config.json` (`Allowed` in crates/hq-hook/src/stop/compat.rs). */
67
+ export interface GitAllowed {
68
+ type: 'bool' | 'text' | 'path' | 'uint' | 'words' | 'color';
69
+ bare?: boolean;
70
+ empty?: boolean;
71
+ words?: string[];
72
+ /** `words` compared ignoring ASCII case, where git uses strcasecmp. */
73
+ fold?: boolean;
74
+ min?: string;
75
+ max?: string;
76
+ units?: boolean;
77
+ }
78
+ /** As Rust `Allowed::accepts`: whether the native Stop models `value` (null: a bare key). `home`: HOME is set. */
79
+ export declare function gitAllowedValue(entry: GitAllowed, value: string | null, home: boolean): boolean;
80
+ /** As Rust `git_color`: a subset of git's color grammar (color.c `color_parse_mem`). */
81
+ export declare function gitColor(value: string): boolean;
82
+ /**
83
+ * Reviews r20 C2 and r21, as Rust `git_key_modeled`: in a section git reads during the legacy
84
+ * observe-patterns' commands (`git-stop-config.json`, derived by running git), a variable is modeled
85
+ * only when it is allowlisted and its value fits the entry's grammar. Variables in other sections
86
+ * pass: the lab shows git reads none of them there. Returns the hold, or null. `section` and `key` are lowercase.
87
+ */
88
+ export declare function gitKeyHold(section: string, subsection: string | null, key: string, value: string | null, home: boolean): string | null;
89
+ /**
90
+ * Why the native Stop cannot stand in for master-hook in this root, or null.
91
+ * Read-only; no hook registration is written here. The same rules as
92
+ * `crates/hq-hook/src/stop/compat.rs`, from the same policy file:
93
+ *
94
+ * - The native Stop runs the ported hooks the registry lists, so a listed
95
+ * ported hook must keep its canonical relative order and default execution
96
+ * settings. A listed hook with no port is left to `covers` (not covered).
97
+ * - Parallel dispatch and a per-child timeout override are holds.
98
+ * - Any `GIT_*` variable outside the allowlist (`gitEnvironmentOverride`) is
99
+ * a hold only when a Git-reading hook will
100
+ * run; Git configuration files and linked-worktree metadata only when
101
+ * observe-patterns will run. A hook runs when it is listed (or there is no
102
+ * registry) and neither the hook profile nor `HQ_DISABLED_HOOKS` turns it
103
+ * off (`enabledBy`, as `stop::enabled_by`).
104
+ * - A ported script on disk that is not a released version is a hold
105
+ * (`unreleasedScript`, as `stop::compat::released_scripts`).
106
+ * - A Git config file is read as bytes; one that is not valid UTF-8 is a hold
107
+ * ("unmodeled Git config encoding"), and lines are trimmed, split and
108
+ * lowercased with Rust's `str::trim`, `char::is_whitespace` and ASCII-only
109
+ * lowercasing, so both sides read the same keys (`scanGitConfig`). Both
110
+ * sides run the shared cases in
111
+ * crates/hq-hook/tests/fixtures/stop-git-config/cases.json.
112
+ */
113
+ export declare function stopCompatibilityHold(root: string, env?: NodeJS.ProcessEnv, fixed?: (p: string) => string): string | null;
114
+ /**
115
+ * The Git configuration observe-patterns' in-process reader does not apply,
116
+ * as `stop::compat::git_files_with`, with Xcode's developer-directory link
117
+ * at `link`. Exported for tests.
118
+ */
119
+ export declare function gitFilesHold(root: string, env: NodeJS.ProcessEnv, link: string, fixed?: (p: string) => string): string | null;
120
+ /**
121
+ * `rest` under `base` as Rust's `Path::join` and the kernel read it: an
122
+ * absolute `rest` stands alone, and nothing is normalized (`a/link/..` is
123
+ * the parent of the link's target). Windows joins with `path.join`.
124
+ */
125
+ export declare function joinRaw(base: string, rest: string, platform?: NodeJS.Platform): string;
126
+ /**
127
+ * As Rust `stop::mode_bits_executable`: macOS bash's mode-bit rule. Any x bit for `root`; else the owner bit for
128
+ * the `owner`; else the group bit for a `member` of the file's group; else the other bit. Setuid, setgid and
129
+ * sticky are not x bits. Both sides check it on the `modeBits` table in the shared cases.json.
130
+ */
131
+ export declare function modeBitsExecutable(mode: number, root: boolean, owner: boolean, member: boolean): boolean;
132
+ /**
133
+ * As `stop::compat::generation`: the Stop files (and master-hook.sh, which only votes) of hq-core
134
+ * v16.0.48-beta.104 and later are one side, every earlier release the other (`generations` in the
135
+ * shared policy). A file present at a released version of one side votes for it; another version,
136
+ * or a missing or unreadable file, casts no vote. Votes for both sides hold: no released core ships
137
+ * that mix, so the Stop master-hook would run cannot be told. On the later side, a master-hook.sh
138
+ * that is present and not a released later version holds too. Exported for tests.
139
+ */
140
+ export declare function generationHold(root: string): string | null;
4
141
  /** The hooks the old dispatcher runs for `event` on `host` in this HQ root; null when they cannot be read exactly. */
5
142
  export declare function shellHooks(root: string, host: CoreNextHost, event: string): string[] | null;
6
- /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
7
- export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined): string[];
8
143
  /**
9
- * `target` narrowed to the events it covers in full on `host` in this HQ
10
- * root; null when none is covered (every event stays on the old dispatcher),
11
- * or when the target's host canary gate refuses `host` (US-019 criterion 4:
12
- * no event on that host switches).
144
+ * Whether the engine's claim `pattern` covers `hook`. A claim may name folder
145
+ * hooks by pattern, `*` standing for one path segment
146
+ * (`personal/hooks/Stop/*.sh`); any other claim names one hook exactly.
13
147
  */
14
- export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost): CoreNextTarget | null;
148
+ export declare function claimCovers(pattern: string, hook: string): boolean;
149
+ /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
150
+ export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined, env?: NodeJS.ProcessEnv): string[];
151
+ /** Records the environment `target` was resolved under; returns `target`. */
152
+ export declare function resolvedUnder<T extends CoreNextTarget | null>(target: T, env: NodeJS.ProcessEnv): T;
153
+ export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost, env?: NodeJS.ProcessEnv): CoreNextTarget | null;
15
154
  //# sourceMappingURL=coverage.d.ts.map