@indigoai-us/hq-cli 5.273.0-alpha.0 → 5.274.0

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 (91) hide show
  1. package/CHANGELOG.md +65 -2
  2. package/README.md +32 -1
  3. package/dist/command-catalog.generated.d.ts +83 -536
  4. package/dist/command-catalog.generated.js +129 -714
  5. package/dist/command-registration-plan.d.ts +12 -0
  6. package/dist/command-registration-plan.js +2 -0
  7. package/dist/commands/cloud.js +40 -0
  8. package/dist/commands/core-checkpoint.js +3 -1
  9. package/dist/commands/core-command-catalog.d.ts +32 -0
  10. package/dist/commands/core-command-catalog.js +58 -0
  11. package/dist/commands/core-ontology.js +9 -4
  12. package/dist/commands/core.d.ts +4 -0
  13. package/dist/commands/core.js +79 -75
  14. package/dist/commands/daemon.d.ts +0 -3
  15. package/dist/commands/daemon.js +1 -173
  16. package/dist/commands/deploy-comments.d.ts +3 -0
  17. package/dist/commands/deploy-comments.js +159 -0
  18. package/dist/commands/lanes-checks.d.ts +0 -1
  19. package/dist/commands/lanes-checks.js +217 -54
  20. package/dist/commands/lanes-hold.js +40 -2
  21. package/dist/commands/lanes-message.js +98 -14
  22. package/dist/commands/lanes-move.d.ts +12 -0
  23. package/dist/commands/lanes-move.js +342 -0
  24. package/dist/commands/lanes-resume.js +3 -1
  25. package/dist/commands/lanes-shared.d.ts +39 -3
  26. package/dist/commands/lanes-shared.js +59 -0
  27. package/dist/commands/lanes.d.ts +3 -5
  28. package/dist/commands/lanes.js +206 -478
  29. package/dist/commands/report.js +2 -14
  30. package/dist/commands/sync-mode.d.ts +0 -11
  31. package/dist/commands/sync-mode.js +0 -30
  32. package/dist/fast-core.js +1 -1
  33. package/dist/{commands/scaffold-fast.d.ts → fast-scaffold.d.ts} +1 -1
  34. package/dist/{commands/scaffold-fast.js → fast-scaffold.js} +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +2 -2
  37. package/dist/lib/checkpoint-ontology/apply.d.ts +8 -0
  38. package/dist/lib/checkpoint-ontology/apply.js +33 -0
  39. package/dist/lib/checkpoint-ontology/plan.d.ts +15 -0
  40. package/dist/lib/checkpoint-ontology/plan.js +15 -0
  41. package/dist/lib/daemon/catalog.d.ts +2 -18
  42. package/dist/lib/daemon/catalog.js +2 -18
  43. package/dist/lib/daemon/config.d.ts +0 -6
  44. package/dist/lib/daemon/config.js +2 -15
  45. package/dist/lib/daemon/requests.d.ts +0 -4
  46. package/dist/lib/daemon/requests.js +0 -2
  47. package/dist/lib/daemon/run.js +19 -78
  48. package/dist/lib/daemon/supervisor.d.ts +0 -8
  49. package/dist/lib/daemon/supervisor.js +1 -101
  50. package/dist/lib/deploy-api.d.ts +6 -0
  51. package/dist/lib/deploy-api.js +21 -0
  52. package/dist/lib/doctor/checks/scaffold-cli-floor.d.ts +7 -0
  53. package/dist/lib/doctor/checks/scaffold-cli-floor.js +73 -0
  54. package/dist/lib/doctor/fix/apply.d.ts +17 -2
  55. package/dist/lib/doctor/fix/apply.js +111 -57
  56. package/dist/lib/doctor/fix/json-output.d.ts +9 -1
  57. package/dist/lib/doctor/fix/json-output.js +11 -0
  58. package/dist/lib/doctor/registry.js +2 -0
  59. package/dist/lib/first-sync-next-step.d.ts +37 -0
  60. package/dist/lib/first-sync-next-step.js +189 -0
  61. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  62. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  63. package/dist/lib/lanes/hire-grant-dispatch.d.ts +6 -1
  64. package/dist/lib/lanes/hire-grant-dispatch.js +78 -3
  65. package/dist/lib/lanes/keep-alive.d.ts +3 -2
  66. package/dist/lib/lanes/keep-alive.js +2 -2
  67. package/dist/lib/lanes/merge-command.d.ts +1 -0
  68. package/dist/lib/lanes/merge-command.js +299 -33
  69. package/dist/lib/lanes/orphans.d.ts +7 -0
  70. package/dist/lib/lanes/orphans.js +39 -4
  71. package/dist/lib/lanes/tracker-store.d.ts +2 -18
  72. package/dist/lib/lanes/tracker-store.js +1 -172
  73. package/dist/lib/scaffold-cli-floor.d.ts +9 -0
  74. package/dist/lib/scaffold-cli-floor.js +50 -0
  75. package/dist/main.js +4 -1
  76. package/dist/utils/cli-telemetry.d.ts +7 -1
  77. package/dist/utils/cli-telemetry.js +84 -8
  78. package/dist/utils/contribution-table.d.ts +1 -1
  79. package/dist/utils/scaffold-fast-import-guard.d.ts +3 -0
  80. package/dist/utils/scaffold-fast-import-guard.js +28 -0
  81. package/dist/utils/scaffold-packlist-guard.d.ts +7 -0
  82. package/dist/utils/scaffold-packlist-guard.js +23 -0
  83. package/dist/utils/scaffold-sibling-references.d.ts +21 -0
  84. package/dist/utils/scaffold-sibling-references.js +156 -0
  85. package/package.json +2 -2
  86. package/dist/commands/lanes-import.d.ts +0 -14
  87. package/dist/commands/lanes-import.js +0 -1210
  88. package/dist/commands/lanes-tracker.d.ts +0 -18
  89. package/dist/commands/lanes-tracker.js +0 -452
  90. package/dist/lib/daemon/sync-runner.d.ts +0 -58
  91. package/dist/lib/daemon/sync-runner.js +0 -277
@@ -1,277 +0,0 @@
1
- /** Local status and resource controls shared by the daemon and its sync runner. */
2
- import * as crypto from "node:crypto";
3
- import { spawnSync } from "node:child_process";
4
- import * as fs from "node:fs";
5
- import * as os from "node:os";
6
- import * as path from "node:path";
7
- export const SYNC_RUNNER_OWNER = "hq-daemon";
8
- export const SYNC_RUNNER_LEASE_CONFLICT_EXIT = 20;
9
- export const SYNC_RUNNER_LEASE_RETRY_MS = 15_000;
10
- export const DEFAULT_SYNC_HEARTBEAT_TIMEOUT_MS = 300_000;
11
- export const DEFAULT_SYNC_RUNNER_HEAP_MB = 3_584;
12
- export const SYNC_HEARTBEAT_TIMEOUT_ENV = "HQ_DAEMON_SYNC_HEARTBEAT_TIMEOUT_SECONDS";
13
- export const SYNC_RUNNER_HEAP_ENV = "HQ_SYNC_RUNNER_MAX_OLD_SPACE_MB";
14
- const SYNC_RUNNER_COMMAND = /(?:^|[\s/\\])(?:sync-runner\.js|hq-sync-runner(?:\.(?:cmd|exe))?)(?:[\s"']|$)/i;
15
- function record(value) {
16
- return value !== null && typeof value === "object" && !Array.isArray(value)
17
- ? value
18
- : null;
19
- }
20
- /** The status file path used by hq-cloud's watch-owner lease. */
21
- export function watchRunnerOwnerStatusPath(hqRoot, home = os.homedir(), env = process.env) {
22
- let canonicalRoot = path.resolve(hqRoot);
23
- try {
24
- canonicalRoot = fs.realpathSync.native(canonicalRoot);
25
- }
26
- catch (error) {
27
- // hq-cloud uses the resolved path until the HQ root can be canonicalized.
28
- if (error?.code !== "ENOENT") {
29
- throw new Error(`could not canonicalize HQ root ${canonicalRoot}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
30
- }
31
- }
32
- const rootHash = crypto.createHash("sha1").update(canonicalRoot).digest("hex").slice(0, 16);
33
- const stateDir = env.HQ_STATE_DIR?.trim() || path.join(home, ".hq");
34
- return path.join(stateDir, "locks", `watch-owner-${rootHash}.json`);
35
- }
36
- /** Read the watch-owner status JSON without taking or changing its lease. */
37
- export function readWatchRunnerOwnerStatus(statusPath) {
38
- let parsed;
39
- try {
40
- parsed = JSON.parse(fs.readFileSync(statusPath, "utf8"));
41
- }
42
- catch (error) {
43
- if (error?.code === "ENOENT")
44
- return null;
45
- throw new Error(`could not read watch-runner owner status at ${statusPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
46
- }
47
- const value = record(parsed);
48
- if (!value ||
49
- typeof value.owner !== "string" ||
50
- !Number.isInteger(value.pid) ||
51
- typeof value.version !== "string" ||
52
- typeof value.startedAt !== "string" ||
53
- typeof value.heartbeatAt !== "string") {
54
- throw new Error(`watch-runner owner status at ${statusPath} has an invalid shape`);
55
- }
56
- return value;
57
- }
58
- /** Match a live process command line to the hq-cloud watch runner executable. */
59
- export function isSyncRunnerCommandLine(commandLine) {
60
- return SYNC_RUNNER_COMMAND.test(commandLine);
61
- }
62
- function commandLineArgs(commandLine) {
63
- const args = [];
64
- let current = "";
65
- let quote = null;
66
- let started = false;
67
- for (let i = 0; i < commandLine.length; i++) {
68
- const char = commandLine[i];
69
- if (quote) {
70
- if (char === quote) {
71
- quote = null;
72
- started = true;
73
- }
74
- else if (char === "\\" && commandLine[i + 1] === quote) {
75
- current += commandLine[++i];
76
- started = true;
77
- }
78
- else {
79
- current += char;
80
- started = true;
81
- }
82
- continue;
83
- }
84
- if (char === "'" || char === '"') {
85
- quote = char;
86
- started = true;
87
- }
88
- else if (/\s/.test(char)) {
89
- if (started) {
90
- args.push(current);
91
- current = "";
92
- started = false;
93
- }
94
- }
95
- else {
96
- current += char;
97
- started = true;
98
- }
99
- }
100
- if (started)
101
- args.push(current);
102
- return args;
103
- }
104
- function syncRunnerHqRoot(commandLine) {
105
- const args = commandLineArgs(commandLine);
106
- for (let i = 0; i < args.length; i++) {
107
- const arg = args[i];
108
- if (arg === "--hq-root")
109
- return args[i + 1] || null;
110
- if (arg.startsWith("--hq-root="))
111
- return arg.slice("--hq-root=".length) || null;
112
- }
113
- return null;
114
- }
115
- function commandLineNamesRoot(commandLine, hqRoot, platform) {
116
- const parsedRoot = syncRunnerHqRoot(commandLine);
117
- if (parsedRoot !== null && canonicalRoot(parsedRoot, platform) === canonicalRoot(hqRoot, platform))
118
- return true;
119
- const pathApi = platform === "win32" ? path.win32 : path;
120
- const variants = new Set([pathApi.resolve(hqRoot)]);
121
- if (platform === process.platform) {
122
- try {
123
- variants.add(fs.realpathSync.native(pathApi.resolve(hqRoot)));
124
- }
125
- catch (error) {
126
- if (error?.code !== "ENOENT") {
127
- throw new Error(`could not canonicalize sync runner HQ root ${hqRoot}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
128
- }
129
- }
130
- }
131
- const compareFlags = platform === "win32" ? "i" : "";
132
- return [...variants].some((root) => {
133
- const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
134
- return new RegExp(`(?:^|\\s)--hq-root(?:=|\\s+)["']?${escaped}["']?(?=\\s|$)`, compareFlags).test(commandLine);
135
- });
136
- }
137
- function canonicalRoot(root, platform) {
138
- const pathApi = platform === "win32" ? path.win32 : path;
139
- let resolved = pathApi.resolve(root);
140
- if (platform === process.platform) {
141
- try {
142
- resolved = fs.realpathSync.native(resolved);
143
- }
144
- catch (error) {
145
- if (error?.code !== "ENOENT") {
146
- throw new Error(`could not canonicalize sync runner HQ root ${resolved}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
147
- }
148
- }
149
- }
150
- return platform === "win32" ? resolved.toLowerCase() : resolved;
151
- }
152
- /** Return a clear wait reason when an unleased runner already targets this HQ root. */
153
- export function syncRunnerUnleasedBlockReason(hqRoot, processes, ownerPid, platform = process.platform, daemonRunnerPids = new Set()) {
154
- const runner = processes.find((candidate) => {
155
- if (daemonRunnerPids.has(candidate.pid) || candidate.pid === ownerPid)
156
- return false;
157
- if (!isSyncRunnerCommandLine(candidate.commandLine))
158
- return false;
159
- return commandLineNamesRoot(candidate.commandLine, hqRoot, platform);
160
- });
161
- if (!runner)
162
- return undefined;
163
- const lease = ownerPid === null ? "missing" : `belongs to pid ${ownerPid}`;
164
- return `sync runner pid ${runner.pid} for ${hqRoot} is running without the watch-owner lease (status ${lease}); waiting for it to exit`;
165
- }
166
- /** Read complete process command lines so root matching can include trailing arguments. */
167
- export function listSyncRunnerProcesses(platform = process.platform, run = (command, args) => {
168
- const result = spawnSync(command, args, {
169
- encoding: "utf8",
170
- windowsHide: true,
171
- timeout: 15_000,
172
- maxBuffer: 8 * 1024 * 1024,
173
- });
174
- return {
175
- status: result.status,
176
- stdout: result.stdout ?? "",
177
- stderr: result.stderr ?? "",
178
- ...(result.error ? { error: result.error } : {}),
179
- };
180
- }) {
181
- const command = platform === "win32" ? "powershell.exe" : "ps";
182
- const args = platform === "win32"
183
- ? [
184
- "-NoProfile",
185
- "-NonInteractive",
186
- "-Command",
187
- "Get-CimInstance Win32_Process | Select-Object @{Name='pid';Expression={$_.ProcessId}},@{Name='commandLine';Expression={$_.CommandLine}} | ConvertTo-Json -Compress",
188
- ]
189
- : ["-eww", "-o", "pid=", "-o", "args="];
190
- const result = run(command, args);
191
- if (result.error)
192
- return { ok: false, error: `could not list process command lines: ${result.error.message}` };
193
- if (result.status !== 0) {
194
- return { ok: false, error: `could not list process command lines: ${(result.stderr ?? "").trim() || `exit ${result.status}`}` };
195
- }
196
- if (platform === "win32") {
197
- let parsed;
198
- try {
199
- parsed = JSON.parse(result.stdout || "[]");
200
- }
201
- catch (error) {
202
- return { ok: false, error: `could not parse Windows process list: ${error instanceof Error ? error.message : String(error)}` };
203
- }
204
- const rows = Array.isArray(parsed) ? parsed : [parsed];
205
- return {
206
- ok: true,
207
- processes: rows.flatMap((row) => {
208
- if (!row || typeof row !== "object")
209
- return [];
210
- const value = row;
211
- return Number.isInteger(value.pid) && typeof value.commandLine === "string"
212
- ? [{ pid: value.pid, commandLine: value.commandLine }]
213
- : [];
214
- }),
215
- };
216
- }
217
- const processes = [];
218
- for (const line of (result.stdout ?? "").split(/\r?\n/)) {
219
- const match = /^\s*(\d+)\s+(.+)$/.exec(line);
220
- if (match)
221
- processes.push({ pid: Number(match[1]), commandLine: match[2] });
222
- }
223
- return { ok: true, processes };
224
- }
225
- /** The watchdog follows the runner's NDJSON protocol, the same liveness signal used by the desktop app. */
226
- export function parseSyncRunnerProtocolLine(line) {
227
- if (!line.trim())
228
- return null;
229
- const parsed = record(JSON.parse(line));
230
- return parsed && typeof parsed.type === "string" && parsed.type.length > 0 ? parsed : null;
231
- }
232
- /** Summarize the runner's all-complete event for daemon status. */
233
- export function syncPassResult(event, completedAt = new Date().toISOString()) {
234
- if (event.type !== "all-complete")
235
- return null;
236
- const errors = Array.isArray(event.errors) ? event.errors.length : 0;
237
- const transient = Array.isArray(event.transient) ? event.transient.length : 0;
238
- const status = event.partial === true || transient > 0 ? "partial" : errors > 0 ? "failed" : "ok";
239
- return {
240
- status,
241
- completedAt,
242
- ...(typeof event.companiesAttempted === "number" ? { companiesAttempted: event.companiesAttempted } : {}),
243
- errors,
244
- transient,
245
- };
246
- }
247
- export function syncHeartbeatTimeoutMs(env) {
248
- const raw = env[SYNC_HEARTBEAT_TIMEOUT_ENV]?.trim();
249
- if (!raw || !/^\d+$/.test(raw))
250
- return DEFAULT_SYNC_HEARTBEAT_TIMEOUT_MS;
251
- const seconds = Number(raw);
252
- const maxSeconds = Math.floor(2_147_483_647 / 1_000);
253
- if (!Number.isSafeInteger(seconds) || seconds < 1 || seconds > maxSeconds)
254
- return DEFAULT_SYNC_HEARTBEAT_TIMEOUT_MS;
255
- return seconds * 1_000;
256
- }
257
- function hasHeapOption(options) {
258
- const tokens = options.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
259
- for (let i = 0; i < tokens.length; i++) {
260
- const token = tokens[i].replaceAll("--max_old_space_size", "--max-old-space-size");
261
- if (token === "--max-old-space-size" || token.startsWith("--max-old-space-size="))
262
- return true;
263
- }
264
- return false;
265
- }
266
- /** Preserve an explicit NODE_OPTIONS heap setting; otherwise apply the desktop runner's default/override. */
267
- export function syncRunnerNodeOptions(env) {
268
- const inherited = env.NODE_OPTIONS?.trim() ?? "";
269
- if (hasHeapOption(inherited))
270
- return inherited || undefined;
271
- const rawOverride = env[SYNC_RUNNER_HEAP_ENV]?.trim();
272
- const override = rawOverride && /^\d+$/.test(rawOverride) ? Number(rawOverride) : undefined;
273
- const heapMb = override && Number.isSafeInteger(override) && override > 0 ? override : DEFAULT_SYNC_RUNNER_HEAP_MB;
274
- const heapFlag = `--max-old-space-size=${heapMb}`;
275
- return inherited ? `${inherited} ${heapFlag}` : heapFlag;
276
- }
277
- //# sourceMappingURL=sync-runner.js.map