@indigoai-us/hq-cli 5.345.91 → 5.345.93
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.
- package/CHANGELOG.md +17 -0
- package/assets/scaffold/core/scripts/qmd-reindex-bg.sh +17 -4
- package/dist/command-catalog.generated.d.ts +252 -0
- package/dist/command-catalog.generated.js +306 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/capacity.d.ts +71 -0
- package/dist/commands/capacity.js +666 -0
- package/dist/commands/integrations-connect.js +64 -5
- package/dist/commands/lanes-accounts.d.ts +1 -0
- package/dist/commands/lanes-accounts.js +6 -0
- package/dist/lib/capacity/accounts.d.ts +36 -0
- package/dist/lib/capacity/accounts.js +90 -0
- package/dist/lib/capacity/collect.d.ts +33 -0
- package/dist/lib/capacity/collect.js +164 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +145 -0
- package/dist/lib/capacity/collectors/claude-oauth.js +1211 -0
- package/dist/lib/capacity/collectors/claude-statusline.d.ts +72 -0
- package/dist/lib/capacity/collectors/claude-statusline.js +436 -0
- package/dist/lib/capacity/collectors/codex.d.ts +120 -0
- package/dist/lib/capacity/collectors/codex.js +1134 -0
- package/dist/lib/capacity/collectors/grok.d.ts +86 -0
- package/dist/lib/capacity/collectors/grok.js +588 -0
- package/dist/lib/capacity/lane-login.d.ts +29 -0
- package/dist/lib/capacity/lane-login.js +91 -0
- package/dist/lib/capacity/ledger.d.ts +399 -0
- package/dist/lib/capacity/ledger.js +1441 -0
- package/dist/lib/capacity/project.d.ts +12 -0
- package/dist/lib/capacity/project.js +264 -0
- package/dist/lib/capacity/read.d.ts +62 -0
- package/dist/lib/capacity/read.js +264 -0
- package/dist/lib/capacity/refusal.d.ts +30 -0
- package/dist/lib/capacity/refusal.js +183 -0
- package/dist/lib/capacity/scheduler.d.ts +76 -0
- package/dist/lib/capacity/scheduler.js +800 -0
- package/dist/lib/capacity/sign-in.d.ts +103 -0
- package/dist/lib/capacity/sign-in.js +517 -0
- package/dist/lib/capacity/widget.d.ts +22 -0
- package/dist/lib/capacity/widget.js +418 -0
- package/dist/lib/lanes/spawn.js +12 -0
- package/dist/lib/mesh/live/daemon/run.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/run.js +29 -1
- package/dist/lib/search-index/background.d.ts +31 -8
- package/dist/lib/search-index/background.js +86 -7
- package/dist/lib/search-index/index.d.ts +24 -0
- package/dist/lib/search-index/index.js +25 -0
- package/package.json +1 -1
|
@@ -8,6 +8,54 @@ import { applyIndexSizeLimit as defaultApplyIndexSizeLimit } from './max-doc-byt
|
|
|
8
8
|
import { acquireEmbedLock as acquireLock, installEmbedLockCleanup, lockPath, lockRoot, lockState, releaseEmbedLock as releaseLock, } from './embed-lock.js';
|
|
9
9
|
import { LoadGateConfigurationError, checkEmbedLoad, defaultLoadGateDependencies, recordSuccessfulEmbed, } from './load-gate.js';
|
|
10
10
|
const COMPLETE_NAME = 'qmd-reindex-bg.completed';
|
|
11
|
+
/**
|
|
12
|
+
* Default hard wall-clock limit for EACH qmd step (cleanup, update, embed) the
|
|
13
|
+
* detached worker runs. The worker has no terminal and nobody waiting on it, so
|
|
14
|
+
* an unbounded step could hold the single-flight lock and a CPU for days. Two
|
|
15
|
+
* hours leaves a first full CPU-only embed of a large HQ room to finish.
|
|
16
|
+
* Override with QMD_REINDEX_STEP_TIMEOUT_SEC (a positive integer).
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_STEP_TIMEOUT_MS = 2 * 60 * 60 * 1_000;
|
|
19
|
+
const WINDOWS_DRIVE_PATH = /^[A-Za-z]:[\\/]/;
|
|
20
|
+
/**
|
|
21
|
+
* Turn a requested worker log path (or HQ root) into an absolute native path,
|
|
22
|
+
* or undefined when it cannot be used safely.
|
|
23
|
+
*
|
|
24
|
+
* - On a non-Windows host a drive-letter path (`C:/tmp/qmd-handoff.log`) is the
|
|
25
|
+
* residue of a Windows-only `cygpath -m` conversion applied where it does not
|
|
26
|
+
* belong. POSIX treats it as RELATIVE, so honouring it would create a `C:`
|
|
27
|
+
* directory inside whatever the current directory happens to be. Reject it.
|
|
28
|
+
* - A relative path is resolved against `cwd` only when a cwd is supplied (the
|
|
29
|
+
* launcher, whose cwd is the caller's). The detached worker never resolves
|
|
30
|
+
* against its inherited cwd: that directory can be deleted under it (a test
|
|
31
|
+
* sandbox's temp dir), and Node's `fs.mkdirSync(relative, { recursive: true })`
|
|
32
|
+
* then loops forever at 100% CPU instead of failing.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveNativeAbsolutePath(logPath, options = {}) {
|
|
35
|
+
const platform = options.platform ?? process.platform;
|
|
36
|
+
const pathApi = platform === 'win32' ? path.win32 : path.posix;
|
|
37
|
+
if (!logPath)
|
|
38
|
+
return undefined;
|
|
39
|
+
if (platform !== 'win32' && WINDOWS_DRIVE_PATH.test(logPath))
|
|
40
|
+
return undefined;
|
|
41
|
+
if (pathApi.isAbsolute(logPath))
|
|
42
|
+
return logPath;
|
|
43
|
+
if (!options.cwd)
|
|
44
|
+
return undefined;
|
|
45
|
+
try {
|
|
46
|
+
return pathApi.resolve(options.cwd(), logPath);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Per-step qmd timeout for the detached worker (QMD_REINDEX_STEP_TIMEOUT_SEC). */
|
|
53
|
+
export function workerStepTimeoutMs(env) {
|
|
54
|
+
const raw = env.QMD_REINDEX_STEP_TIMEOUT_SEC;
|
|
55
|
+
if (raw && /^\d+$/.test(raw) && Number(raw) > 0)
|
|
56
|
+
return Number(raw) * 1_000;
|
|
57
|
+
return DEFAULT_STEP_TIMEOUT_MS;
|
|
58
|
+
}
|
|
11
59
|
function errnoInfo(error) {
|
|
12
60
|
const e = error;
|
|
13
61
|
return { code: e?.code, syscall: e?.syscall };
|
|
@@ -75,7 +123,7 @@ const defaultSpawnWorkerIo = {
|
|
|
75
123
|
spawn: (command, args, options) => spawn(command, args, options),
|
|
76
124
|
report: reportWorkerLogDegradation,
|
|
77
125
|
};
|
|
78
|
-
export function defaultSpawnWorker({ logPath, fallbackLogPath }, io = defaultSpawnWorkerIo) {
|
|
126
|
+
export function defaultSpawnWorker({ logPath, fallbackLogPath, hqRoot }, io = defaultSpawnWorkerIo) {
|
|
79
127
|
const opened = openWorkerLog(logPath, fallbackLogPath, io);
|
|
80
128
|
if (opened.error) {
|
|
81
129
|
io.report({ requested: logPath, used: opened.logPath, usedFallback: opened.usedFallback, ...opened.error });
|
|
@@ -91,7 +139,10 @@ export function defaultSpawnWorker({ logPath, fallbackLogPath }, io = defaultSpa
|
|
|
91
139
|
const stdio = opened.fd === null
|
|
92
140
|
? ['ignore', 'ignore', 'ignore']
|
|
93
141
|
: ['ignore', opened.fd, opened.fd];
|
|
94
|
-
|
|
142
|
+
// Forward the launcher's root so the worker indexes what the caller asked for
|
|
143
|
+
// instead of re-deriving a root from its inherited (possibly temporary) cwd.
|
|
144
|
+
const rootArgs = hqRoot ? ['--hq-root', hqRoot] : [];
|
|
145
|
+
const child = io.spawn(process.execPath, [entry, 'index', 'background', '--worker', ...rootArgs, ...logArgs], {
|
|
95
146
|
detached: true,
|
|
96
147
|
windowsHide: true,
|
|
97
148
|
stdio,
|
|
@@ -203,6 +254,10 @@ function workerLogPath(env) {
|
|
|
203
254
|
function appendWorkerLog(logPath, text) {
|
|
204
255
|
if (!text)
|
|
205
256
|
return;
|
|
257
|
+
// Never mkdir a relative path: in a deleted cwd Node's recursive mkdirSync
|
|
258
|
+
// spins forever (see resolveNativeAbsolutePath). Callers pass an absolute path.
|
|
259
|
+
if (!path.isAbsolute(logPath))
|
|
260
|
+
return;
|
|
206
261
|
try {
|
|
207
262
|
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
|
208
263
|
fs.appendFileSync(logPath, text.endsWith('\n') ? text : `${text}\n`);
|
|
@@ -217,6 +272,8 @@ function capWorkerLog(logPath, env) {
|
|
|
217
272
|
const max = Number(raw);
|
|
218
273
|
if (max === 0)
|
|
219
274
|
return;
|
|
275
|
+
if (!path.isAbsolute(logPath))
|
|
276
|
+
return;
|
|
220
277
|
try {
|
|
221
278
|
if (!fs.existsSync(logPath) || fs.statSync(logPath).size <= max)
|
|
222
279
|
return;
|
|
@@ -265,9 +322,26 @@ export function runBackgroundLauncher(dependencies) {
|
|
|
265
322
|
// openWorkerLog. `home` is validated non-empty above, so the fallback is
|
|
266
323
|
// always inside a directory this user owns.
|
|
267
324
|
const fallbackLogPath = path.join(home, '.hq', 'logs', 'qmd-handoff.log');
|
|
325
|
+
const platform = dependencies.platform ?? process.platform;
|
|
326
|
+
const cwd = dependencies.cwd ?? (() => process.cwd());
|
|
327
|
+
const requestedLogPath = workerLogPath(dependencies.env);
|
|
328
|
+
const logPath = resolveNativeAbsolutePath(requestedLogPath, { platform, cwd });
|
|
329
|
+
if (!logPath) {
|
|
330
|
+
try {
|
|
331
|
+
(dependencies.writeStderr ?? ((text) => process.stderr.write(text)))(`hq: background reindex log ${requestedLogPath} is not a usable absolute path on this platform; writing worker output to ${fallbackLogPath} instead.\n`);
|
|
332
|
+
}
|
|
333
|
+
catch { /* the notice is best-effort and must never crash the launcher */ }
|
|
334
|
+
}
|
|
335
|
+
// Hand the worker an absolute root resolved against the caller's cwd, which
|
|
336
|
+
// still exists now; a drive-letter root on POSIX is dropped like the log path.
|
|
337
|
+
const hqRoot = resolveNativeAbsolutePath(dependencies.hqRoot, { platform, cwd });
|
|
268
338
|
return {
|
|
269
339
|
state: 'launched',
|
|
270
|
-
pid: dependencies.spawnWorker({
|
|
340
|
+
pid: dependencies.spawnWorker({
|
|
341
|
+
logPath: logPath ?? fallbackLogPath,
|
|
342
|
+
fallbackLogPath,
|
|
343
|
+
...(hqRoot ? { hqRoot } : {}),
|
|
344
|
+
}),
|
|
271
345
|
};
|
|
272
346
|
}
|
|
273
347
|
/** Run the single-flight cleanup → update → embed pipeline in a worker only. */
|
|
@@ -290,7 +364,12 @@ export async function runBackgroundWorker(dependencies) {
|
|
|
290
364
|
// The cap lives inside the exit cleanup because a signal-path process.exit
|
|
291
365
|
// never unwinds to a `finally` — the shell capped in its EXIT trap for the
|
|
292
366
|
// same reason.
|
|
293
|
-
|
|
367
|
+
// The launcher always forwards an absolute --log. Anything else (a relative or
|
|
368
|
+
// drive-letter path from a direct invocation) goes to the per-user log rather
|
|
369
|
+
// than being resolved against this detached process's inherited cwd.
|
|
370
|
+
const logPath = resolveNativeAbsolutePath(workerLogPath(dependencies.env), { platform: dependencies.platform })
|
|
371
|
+
?? path.join(home, '.hq', 'logs', 'qmd-handoff.log');
|
|
372
|
+
const timeoutMs = workerStepTimeoutMs(dependencies.env);
|
|
294
373
|
let released = false;
|
|
295
374
|
const cleanup = () => {
|
|
296
375
|
if (released)
|
|
@@ -337,7 +416,7 @@ export async function runBackgroundWorker(dependencies) {
|
|
|
337
416
|
if (await signalWindow())
|
|
338
417
|
return { state: 'terminated' };
|
|
339
418
|
try {
|
|
340
|
-
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['cleanup'], { cwd: dependencies.hqRoot })));
|
|
419
|
+
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['cleanup'], { cwd: dependencies.hqRoot, timeoutMs })));
|
|
341
420
|
}
|
|
342
421
|
catch (error) {
|
|
343
422
|
appendWorkerLog(logPath, errorOutput(error)); // cleanup is intentionally best-effort
|
|
@@ -345,7 +424,7 @@ export async function runBackgroundWorker(dependencies) {
|
|
|
345
424
|
if (await signalWindow())
|
|
346
425
|
return { state: 'terminated' };
|
|
347
426
|
try {
|
|
348
|
-
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['update'], { cwd: dependencies.hqRoot })));
|
|
427
|
+
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['update'], { cwd: dependencies.hqRoot, timeoutMs })));
|
|
349
428
|
}
|
|
350
429
|
catch (error) {
|
|
351
430
|
appendWorkerLog(logPath, errorOutput(error));
|
|
@@ -376,7 +455,7 @@ export async function runBackgroundWorker(dependencies) {
|
|
|
376
455
|
if (loadDecision.forced)
|
|
377
456
|
(dependencies.writeStderr ?? ((text) => process.stderr.write(text)))(loadDecision.notice);
|
|
378
457
|
try {
|
|
379
|
-
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['embed'], { cwd: dependencies.hqRoot })));
|
|
458
|
+
appendWorkerLog(logPath, stepOutput(dependencies.runQmd(['embed'], { cwd: dependencies.hqRoot, timeoutMs })));
|
|
380
459
|
recordSuccessfulEmbed(home, loadGateDependencies);
|
|
381
460
|
}
|
|
382
461
|
catch (error) {
|
|
@@ -64,6 +64,8 @@ export type QmdSpawn = (cmd: string, args: string[], options: {
|
|
|
64
64
|
env?: NodeJS.ProcessEnv;
|
|
65
65
|
encoding: 'utf8';
|
|
66
66
|
timeout?: number;
|
|
67
|
+
/** Signal sent when `timeout` elapses (spawnSync default: SIGTERM). */
|
|
68
|
+
killSignal?: NodeJS.Signals;
|
|
67
69
|
shell?: boolean;
|
|
68
70
|
}) => {
|
|
69
71
|
status: number | null;
|
|
@@ -160,6 +162,20 @@ export declare class QmdTerminatedError extends QmdExitError {
|
|
|
160
162
|
name: string;
|
|
161
163
|
constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, signal: string);
|
|
162
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* qmd ran past the hard wall-clock limit its caller set (`RunQmdOptions.timeoutMs`)
|
|
167
|
+
* and was KILLED by hq-cli. Unlike the parent {@link QmdTerminatedError}, the
|
|
168
|
+
* signal here originates INSIDE hq-cli: spawnSync reports `error.code ===
|
|
169
|
+
* 'ETIMEDOUT'` after delivering `killSignal`. Raised only when the caller opted
|
|
170
|
+
* into a timeout, so every untimed qmd call keeps its existing classification.
|
|
171
|
+
* The background reindex worker uses this to bound each step instead of
|
|
172
|
+
* holding the single-flight lock indefinitely.
|
|
173
|
+
*/
|
|
174
|
+
export declare class QmdTimedOutError extends QmdTerminatedError {
|
|
175
|
+
readonly timeoutMs: number;
|
|
176
|
+
name: string;
|
|
177
|
+
constructor(message: string, args: string[], stdout: string, stderr: string, signal: string, timeoutMs: number);
|
|
178
|
+
}
|
|
163
179
|
/**
|
|
164
180
|
* qmd refused an LLM-backed operation because its local LLM is DISABLED IN CI:
|
|
165
181
|
* qmd hard-disables every LLM operation whenever `CI` is truthy in the
|
|
@@ -511,6 +527,14 @@ export type RunQmdOptions = {
|
|
|
511
527
|
* cwd / interpreter branches are provable without touching the real disk.
|
|
512
528
|
*/
|
|
513
529
|
exists?: (candidate: string) => boolean;
|
|
530
|
+
/**
|
|
531
|
+
* Hard wall-clock limit for the qmd child, in milliseconds. When it elapses
|
|
532
|
+
* the child is sent SIGKILL and {@link QmdTimedOutError} is thrown. Omitted
|
|
533
|
+
* (the default) means no limit, preserving every interactive caller's
|
|
534
|
+
* behaviour. Applies to the real spawn path only; the legacy `runner` seam
|
|
535
|
+
* has no process to kill.
|
|
536
|
+
*/
|
|
537
|
+
timeoutMs?: number;
|
|
514
538
|
};
|
|
515
539
|
/** Run qmd with captured output and typed failures. */
|
|
516
540
|
export declare function runQmd(args: string[], options?: RunQmdOptions): QmdProcessResult;
|
|
@@ -133,6 +133,23 @@ export class QmdTerminatedError extends QmdExitError {
|
|
|
133
133
|
this.signal = signal;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* qmd ran past the hard wall-clock limit its caller set (`RunQmdOptions.timeoutMs`)
|
|
138
|
+
* and was KILLED by hq-cli. Unlike the parent {@link QmdTerminatedError}, the
|
|
139
|
+
* signal here originates INSIDE hq-cli: spawnSync reports `error.code ===
|
|
140
|
+
* 'ETIMEDOUT'` after delivering `killSignal`. Raised only when the caller opted
|
|
141
|
+
* into a timeout, so every untimed qmd call keeps its existing classification.
|
|
142
|
+
* The background reindex worker uses this to bound each step instead of
|
|
143
|
+
* holding the single-flight lock indefinitely.
|
|
144
|
+
*/
|
|
145
|
+
export class QmdTimedOutError extends QmdTerminatedError {
|
|
146
|
+
timeoutMs;
|
|
147
|
+
name = 'QmdTimedOutError';
|
|
148
|
+
constructor(message, args, stdout, stderr, signal, timeoutMs) {
|
|
149
|
+
super(message, args, null, stdout, stderr, signal);
|
|
150
|
+
this.timeoutMs = timeoutMs;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
136
153
|
/**
|
|
137
154
|
* qmd refused an LLM-backed operation because its local LLM is DISABLED IN CI:
|
|
138
155
|
* qmd hard-disables every LLM operation whenever `CI` is truthy in the
|
|
@@ -557,6 +574,7 @@ const defaultSpawn = (cmd, args, options) => {
|
|
|
557
574
|
env: options.env,
|
|
558
575
|
encoding: 'utf8',
|
|
559
576
|
timeout: options.timeout,
|
|
577
|
+
killSignal: options.killSignal,
|
|
560
578
|
shell: options.shell,
|
|
561
579
|
});
|
|
562
580
|
return {
|
|
@@ -588,6 +606,7 @@ function spawnQmd(invocation, args, options = {}) {
|
|
|
588
606
|
env,
|
|
589
607
|
encoding: 'utf8',
|
|
590
608
|
timeout: options.timeout,
|
|
609
|
+
...(options.killSignal ? { killSignal: options.killSignal } : {}),
|
|
591
610
|
shell: plan.shell,
|
|
592
611
|
});
|
|
593
612
|
}
|
|
@@ -1286,12 +1305,18 @@ export function runQmd(args, options = {}) {
|
|
|
1286
1305
|
// above never opens a store).
|
|
1287
1306
|
ensureQmdStoreDir(options.env ?? process.env, { cwd: options.cwd });
|
|
1288
1307
|
const launcher = invocationBin(invocation);
|
|
1308
|
+
const timeoutMs = options.timeoutMs !== undefined && options.timeoutMs > 0 ? options.timeoutMs : undefined;
|
|
1289
1309
|
const result = spawnQmd(invocation, args, {
|
|
1290
1310
|
cwd: options.cwd,
|
|
1291
1311
|
env: options.env ?? process.env,
|
|
1292
1312
|
platform: options.platform,
|
|
1293
1313
|
spawn: options.spawn,
|
|
1314
|
+
...(timeoutMs !== undefined ? { timeout: timeoutMs, killSignal: 'SIGKILL' } : {}),
|
|
1294
1315
|
});
|
|
1316
|
+
if (timeoutMs !== undefined && result.error?.code === 'ETIMEDOUT') {
|
|
1317
|
+
const subcommand = typeof args[0] === 'string' && args[0].length > 0 ? redactErrorText(args[0]) || 'qmd' : 'qmd';
|
|
1318
|
+
throw new QmdTimedOutError(`qmd ${subcommand} exceeded its ${timeoutMs}ms limit and was killed`, args, result.stdout ?? '', result.stderr ?? '', String(result.signal ?? 'SIGKILL'), timeoutMs);
|
|
1319
|
+
}
|
|
1295
1320
|
// Thread attribution so finishRunQmd can attribute a spawn-level ENOENT to the
|
|
1296
1321
|
// right component — the working directory, the Node interpreter, or a
|
|
1297
1322
|
// genuinely missing qmd — instead of blaming the launcher for all three
|