@indigoai-us/hq-cli 5.304.0 → 5.306.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 (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/command-catalog.generated.d.ts +3 -3
  3. package/dist/command-catalog.generated.js +5 -3
  4. package/dist/command-registration-plan.js +8 -0
  5. package/dist/commands/daemon.js +24 -23
  6. package/dist/commands/lanes.js +13 -0
  7. package/dist/commands/mcp-status.js +1 -0
  8. package/dist/commands/members.js +0 -1
  9. package/dist/commands/people.d.ts +3 -0
  10. package/dist/commands/people.js +27 -3
  11. package/dist/index.js +6 -1
  12. package/dist/lazy-commands.js +5 -2
  13. package/dist/lib/aws-sdk-node-warning-output.d.ts +12 -0
  14. package/dist/lib/aws-sdk-node-warning-output.js +22 -0
  15. package/dist/lib/company-errors-sdk-warning-flag.d.ts +5 -0
  16. package/dist/lib/company-errors-sdk-warning-flag.js +8 -0
  17. package/dist/lib/daemon/catalog.js +6 -2
  18. package/dist/lib/daemon/remote-control.d.ts +19 -8
  19. package/dist/lib/daemon/remote-control.js +62 -12
  20. package/dist/lib/daemon/supervisor.d.ts +2 -0
  21. package/dist/lib/daemon/supervisor.js +11 -0
  22. package/dist/lib/doctor/checks/work-context.js +2 -2
  23. package/dist/lib/lanes/keep-alive.js +13 -2
  24. package/dist/lib/mesh/live/daemon/doctor.js +2 -2
  25. package/dist/lib/mesh/live/flush.d.ts +2 -2
  26. package/dist/lib/mesh/live/flush.js +49 -29
  27. package/dist/lib/mesh/live/spool.d.ts +6 -0
  28. package/dist/lib/mesh/live/spool.js +203 -4
  29. package/dist/lib/work-context/bind-best.js +13 -1
  30. package/dist/main.js +16 -3
  31. package/dist/startup-registration.js +9 -3
  32. package/dist/utils/install-tree-torn.d.ts +13 -6
  33. package/dist/utils/install-tree-torn.js +42 -16
  34. package/dist/utils/self-update.d.ts +4 -0
  35. package/dist/utils/self-update.js +46 -9
  36. package/dist/utils/sentry-fingerprint.js +1 -0
  37. package/dist/utils/version-check.d.ts +7 -0
  38. package/dist/utils/version-check.js +30 -1
  39. package/dist/utils/version-gate.d.ts +28 -10
  40. package/dist/utils/version-gate.js +159 -29
  41. package/dist/utils/version-report.d.ts +2 -1
  42. package/dist/utils/version-report.js +8 -1
  43. package/package.json +1 -1
  44. package/dist/lib/work-context/index.d.ts +0 -26
  45. package/dist/lib/work-context/index.js +0 -22
@@ -28,14 +28,17 @@
28
28
  * to silence both check + gate).
29
29
  */
30
30
  import { spawnSync } from "node:child_process";
31
+ import { createHash } from "node:crypto";
31
32
  import { buildSpawnPlan, quoteForWindowsShell } from "./windows-spawn.js";
32
- import { accessSync, closeSync, constants as fsConstants, copyFileSync, existsSync, mkdtempSync, openSync, readdirSync, realpathSync, readFileSync, rmSync, } from "node:fs";
33
+ import { accessSync, closeSync, constants as fsConstants, copyFileSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, realpathSync, readFileSync, rmSync, } from "node:fs";
33
34
  import os from "node:os";
34
35
  import path from "node:path";
35
36
  import { fileURLToPath } from "node:url";
36
37
  import chalk from "chalk";
37
38
  import semver from "semver";
38
39
  import { CLI_NAME, CLI_VERSION } from "../cli-version.js";
40
+ import { Sentry } from "../sentry.js";
41
+ import { isCliTelemetryDisabled } from "./cli-telemetry.js";
39
42
  import { DEFAULT_VAULT_API_URL } from "./cognito-session.js";
40
43
  import { acquireUpdateLock, } from "./update-lock.js";
41
44
  const CLIENT_ID = "hq-cli";
@@ -385,9 +388,9 @@ export function resolveRunningPrefix() {
385
388
  return resolveRunningInstall().prefix;
386
389
  }
387
390
  /**
388
- * Whether the current process can write the npm global `prefix` — i.e. whether
389
- * an `npm install -g --prefix <prefix>` could actually replace the installed
390
- * CLI, or would fail with EACCES.
391
+ * Whether the current process can write the npm global install targets — i.e.
392
+ * whether an `npm install -g --prefix <prefix>` could actually replace the
393
+ * installed CLI, or would fail with EACCES.
391
394
  *
392
395
  * The path npm rewrites is the prefix's `bin` dir (`<prefix>/bin/hq` on unix
393
396
  * globals — the `rename /usr/bin/hq` EACCES the agent boxes hit), so that is
@@ -416,17 +419,119 @@ export function isPrefixWritable(prefix, access = (target, mode) => accessSync(t
416
419
  return false;
417
420
  }
418
421
  /**
419
- * One-line operator explanation for a failed global update whose prefix the
420
- * running user cannot write. This is the agent-box case: the CLI is a
421
- * root-owned `/usr` global install and the runtime is unprivileged, so the
422
- * update genuinely cannot converge from here and re-trying it silently would
423
- * loop. Says so plainly and points at the paths that CAN update it.
422
+ * Check the directories an npm global update must mutate before spawning npm.
423
+ * Npm replaces the package under node_modules and writes executable links
424
+ * under prefix/bin. The package's parent must be writable because npm renames
425
+ * the old package there.
426
+ *
427
+ * When one of those directories has not been created yet, check its nearest
428
+ * existing ancestor: npm can create a child only if that ancestor is writable.
424
429
  */
425
- export function nonWritablePrefixNote(prefix) {
426
- return (`The npm global prefix ${prefix} is not writable by the current user, so this update cannot ` +
427
- `take effect here. On an agent box this is expected: the CLI is a root-owned global install and ` +
428
- `updates land as root — via the box's hq-cli-update timer, or \`sudo npm install -g ${CLI_NAME}@latest\` — ` +
429
- `not from the unprivileged runtime.`);
430
+ export function canWriteNpmInstall(prefix, packageRoot, access = (target, mode) => accessSync(target, mode)) {
431
+ let nodeModulesRoot = path.join(prefix, process.platform === "win32" ? "node_modules" : "lib/node_modules");
432
+ let cursor = path.resolve(packageRoot);
433
+ while (true) {
434
+ if (path.basename(cursor).toLowerCase() === "node_modules") {
435
+ nodeModulesRoot = cursor;
436
+ break;
437
+ }
438
+ const parent = path.dirname(cursor);
439
+ if (parent === cursor)
440
+ break;
441
+ cursor = parent;
442
+ }
443
+ const mode = fsConstants.W_OK | fsConstants.X_OK;
444
+ // npm needs write access to the directories it replaces or links into. The
445
+ // prefix root itself need not be writable when those directories already
446
+ // exist; when one is missing, the nearest-existing-ancestor check below
447
+ // still verifies permission to create it.
448
+ const targets = [path.join(prefix, "bin"), nodeModulesRoot, path.dirname(packageRoot)];
449
+ return targets.every((target) => {
450
+ let candidate = path.resolve(target);
451
+ while (true) {
452
+ try {
453
+ access(candidate, mode);
454
+ return true;
455
+ }
456
+ catch (error) {
457
+ if (error?.code !== "ENOENT") {
458
+ return false;
459
+ }
460
+ const parent = path.dirname(candidate);
461
+ if (parent === candidate)
462
+ return false;
463
+ candidate = parent;
464
+ }
465
+ }
466
+ });
467
+ }
468
+ const nonWritablePrefixNotices = new Set();
469
+ /** Claim the one local warning/report for this installed version and prefix. */
470
+ export function claimNonWritableNpmPrefixNotice(install, fromVersion, homeDir = os.homedir(), kind = "user") {
471
+ const installIdentity = path.resolve(install.packageRoot ?? install.prefix ?? `${install.manager}:unknown-install`);
472
+ const identity = createHash("sha256")
473
+ .update(`${installIdentity}\0${fromVersion}`)
474
+ .digest("hex");
475
+ const localKey = path.join(homeDir, ".hq", "self-update", "prefix-not-writable", `${kind}-${identity}`);
476
+ if (nonWritablePrefixNotices.has(localKey))
477
+ return false;
478
+ try {
479
+ mkdirSync(path.dirname(localKey), { recursive: true, mode: 0o700 });
480
+ const descriptor = openSync(localKey, "wx", 0o600);
481
+ closeSync(descriptor);
482
+ nonWritablePrefixNotices.add(localKey);
483
+ return true;
484
+ }
485
+ catch (error) {
486
+ if (error?.code === "EEXIST") {
487
+ nonWritablePrefixNotices.add(localKey);
488
+ return false;
489
+ }
490
+ // Preserve the warning/report for this process if the home directory is
491
+ // unavailable. The marker is normally durable across CLI invocations.
492
+ console.error(chalk.dim("hq: could not persist the self-update permission notice rate limit."));
493
+ nonWritablePrefixNotices.add(localKey);
494
+ return true;
495
+ }
496
+ }
497
+ /** Emit one path-free warning event for a handled non-writable npm prefix. */
498
+ export function captureNonWritableNpmPrefixNotice(input) {
499
+ if (isCliTelemetryDisabled(input.env ?? process.env))
500
+ return Promise.resolve();
501
+ const claimed = claimNonWritableNpmPrefixNotice(input.install, input.fromVersion, input.homeDir, "report");
502
+ if (!claimed)
503
+ return Promise.resolve();
504
+ Sentry.captureMessage("Self-update deferred: npm prefix is not writable", {
505
+ level: "warning",
506
+ fingerprint: ["self-update", "npm-prefix-not-writable"],
507
+ tags: {
508
+ from_version: input.fromVersion,
509
+ target_version: input.targetVersion,
510
+ install_flavor: "npm",
511
+ error_class: "prefix_not_writable",
512
+ error_reason: "permission_denied",
513
+ },
514
+ });
515
+ return Sentry.flush(2_000).then((flushed) => {
516
+ if (!flushed) {
517
+ console.error(chalk.dim("hq: the self-update permission notice could not be sent to Sentry yet."));
518
+ }
519
+ });
520
+ }
521
+ /** One-line repair guidance for a global npm install the current user cannot write. */
522
+ export function nonWritablePrefixNote(prefix, platform = process.platform) {
523
+ const prefixArg = `'${prefix.replace(/'/g, "'\\''")}'`;
524
+ if (platform === "win32") {
525
+ const windowsPrefixArg = `"${prefix.replace(/"/g, '""')}"`;
526
+ return (`The npm global prefix ${prefix} is not writable by the current user, so hq-cli was not updated. ` +
527
+ `Open PowerShell as Administrator and run \`npm install -g --prefix ${windowsPrefixArg} ${CLI_NAME}@latest\`, ` +
528
+ `or set a user-owned prefix with \`npm config set prefix "$env:APPDATA\\npm"\` and run ` +
529
+ `\`npm install -g ${CLI_NAME}@latest\` from that PowerShell session.`);
530
+ }
531
+ return (`The npm global prefix ${prefix} is not writable by the current user, so hq-cli was not updated. ` +
532
+ `Run \`sudo npm install -g --prefix ${prefixArg} ${CLI_NAME}@latest\` to update this install, ` +
533
+ `or switch to a user-owned prefix with \`npm config set prefix ~/.npm-global\`, then run ` +
534
+ `\`npm install -g ${CLI_NAME}@latest\` after adding ~/.npm-global/bin to PATH.`);
430
535
  }
431
536
  /**
432
537
  * Derive `PNPM_HOME` from a pnpm-managed install's own path. pnpm resolves its
@@ -1236,19 +1341,29 @@ function enforceUpdateRequired(decision, deps = {}) {
1236
1341
  console.error(chalk.dim(" Another hq updater is already installing (update lock held); continuing on the current version."));
1237
1342
  return;
1238
1343
  }
1239
- let exitCode;
1344
+ let attempt;
1240
1345
  try {
1241
- exitCode = attemptRequiredUpdate(decision, deps, install);
1346
+ attempt = attemptRequiredUpdate(decision, deps, install);
1242
1347
  }
1243
- finally {
1244
- // `process.exit` skips `finally` blocks, so the exit itself lives OUTSIDE
1245
- // the lock scope; this `finally` releases on the normal path and on any
1246
- // unexpected throw from the install attempt.
1348
+ catch (error) {
1247
1349
  lock.release();
1350
+ throw error;
1248
1351
  }
1249
- if (exitCode === "continue")
1352
+ if (attempt instanceof Promise) {
1353
+ return attempt.then((exitCode) => {
1354
+ lock.release();
1355
+ if (exitCode !== "continue")
1356
+ process.exit(exitCode);
1357
+ }, (error) => {
1358
+ lock.release();
1359
+ throw error;
1360
+ });
1361
+ }
1362
+ // `process.exit` skips `finally`, so release explicitly before exiting.
1363
+ lock.release();
1364
+ if (attempt === "continue")
1250
1365
  return;
1251
- process.exit(exitCode);
1366
+ process.exit(attempt);
1252
1367
  }
1253
1368
  /**
1254
1369
  * The install attempt itself (npm/pnpm/bun routing, stale-partial cleanup,
@@ -1290,6 +1405,7 @@ function attemptRequiredUpdate(decision, deps, install) {
1290
1405
  // npm/bun and when PNPM_HOME is already set.
1291
1406
  const updateEnv = pnpmUpdateEnv(install);
1292
1407
  let result;
1408
+ let noticeFlush = null;
1293
1409
  if (isManagedOutsideNpm) {
1294
1410
  console.error(chalk.dim(` Detected a ${install.manager}-managed global install; updating with ${install.manager}`));
1295
1411
  console.error(chalk.dim(` Running: ${primaryCmd} ${primaryArgs.join(" ")}`));
@@ -1360,12 +1476,22 @@ function attemptRequiredUpdate(decision, deps, install) {
1360
1476
  }
1361
1477
  if (!result.ok) {
1362
1478
  console.error(chalk.red(`✗ Update failed${result.detail ? `: ${result.detail}` : ""}.`));
1363
- // A root-owned global prefix the running user cannot write is the agent-box
1364
- // case: even the `sudo -n` retry above cannot help without passwordless
1365
- // sudo, so name the wall plainly rather than leaving `exit 75` to read as a
1366
- // generic failure. Only for npm-prefix installs (pnpm/Bun route elsewhere).
1367
- if (!isManagedOutsideNpm && prefix && !isPrefixWritable(prefix)) {
1479
+ // If the npm prefix is still unwritable after the unprivileged and sudo
1480
+ // attempts, explain the permission wall plainly instead of leaving exit 75
1481
+ // as a generic failure. Only applies to npm-managed installs.
1482
+ const npmPrefixNotWritable = !isManagedOutsideNpm &&
1483
+ prefix &&
1484
+ install.packageRoot &&
1485
+ !(deps.canWriteNpmInstall ?? ((resolved) => canWriteNpmInstall(resolved.prefix, resolved.packageRoot)))(install);
1486
+ if (npmPrefixNotWritable) {
1368
1487
  console.error(chalk.yellow(` ${nonWritablePrefixNote(prefix)}`));
1488
+ noticeFlush = captureNonWritableNpmPrefixNotice({
1489
+ fromVersion: CLI_VERSION,
1490
+ targetVersion: decision.latestVersion,
1491
+ install,
1492
+ env: process.env,
1493
+ homeDir: deps.homeDir,
1494
+ });
1369
1495
  }
1370
1496
  // The package manager itself is missing from this environment — the usual
1371
1497
  // cause is a minimal-PATH parent (launchd, cron, a bare systemd unit) that
@@ -1391,7 +1517,7 @@ function attemptRequiredUpdate(decision, deps, install) {
1391
1517
  console.error(chalk.dim(" Continuing on the current hq-cli version."));
1392
1518
  return "continue";
1393
1519
  }
1394
- return 75;
1520
+ return noticeFlush ? noticeFlush.then(() => 75) : 75;
1395
1521
  }
1396
1522
  // Read-your-writes: a "successful" install into the npm prefix does not
1397
1523
  // prove the user's PATH resolves it. Verify BEFORE announcing, so a ghost
@@ -1427,7 +1553,9 @@ export async function enforceVersionGate(onUpdateRecommended, options = {}) {
1427
1553
  : undefined;
1428
1554
  // Exits the process, EXCEPT when another updater holds the shared update
1429
1555
  // lock — then it returns and the CLI continues on the current version.
1430
- enforceUpdateRequired(decision, { resolveInstall: () => install, installNpmPackageStaged });
1556
+ const requiredUpdate = enforceUpdateRequired(decision, { resolveInstall: () => install, installNpmPackageStaged });
1557
+ if (requiredUpdate)
1558
+ await requiredUpdate;
1431
1559
  return "continue";
1432
1560
  }
1433
1561
  if (decision.updateRecommended) {
@@ -1468,6 +1596,8 @@ export const __test__ = {
1468
1596
  buildPnpmInstallArgv,
1469
1597
  buildPrefixedInstallArgv,
1470
1598
  buildSpawnPlan,
1599
+ canWriteNpmInstall,
1600
+ claimNonWritableNpmPrefixNotice,
1471
1601
  cleanStalePartialInstall,
1472
1602
  derivePnpmHome,
1473
1603
  enforceUpdateRequired,
@@ -13,6 +13,7 @@ export interface VersionReportDeps {
13
13
  hqRoot?: string;
14
14
  readHq?: (hqRoot: string) => string | null;
15
15
  fetchLatest?: () => Promise<string | null>;
16
+ printUpdateNudge?: (stderr: Pick<NodeJS.WriteStream, "write">) => Promise<void>;
16
17
  }
17
18
  export declare function normalizeHqCoreTag(tag: string): string | null;
18
19
  export declare function fetchLatestHqCoreRelease(fetchImpl?: typeof fetch, timeoutMs?: number): Promise<string | null>;
@@ -22,5 +23,5 @@ export declare function versionReportJson(report: VersionReport): string;
22
23
  export { isVersionRequest, wantsJson } from "../version-request.js";
23
24
  export declare function runVersionCommand(argv?: readonly string[], deps?: VersionReportDeps, stdout?: {
24
25
  write(chunk: string): unknown;
25
- }): Promise<void>;
26
+ }, stderr?: Pick<NodeJS.WriteStream, "write">): Promise<void>;
26
27
  //# sourceMappingURL=version-report.d.ts.map
@@ -91,8 +91,15 @@ export function versionReportJson(report) {
91
91
  }, null, 2)}\n`;
92
92
  }
93
93
  export { isVersionRequest, wantsJson } from "../version-request.js";
94
- export async function runVersionCommand(argv = process.argv, deps = {}, stdout = process.stdout) {
94
+ export async function runVersionCommand(argv = process.argv, deps = {}, stdout = process.stdout, stderr = process.stderr) {
95
95
  const report = await collectVersionReport(deps);
96
96
  stdout.write(wantsJson(argv) ? versionReportJson(report) : formatVersionReport(report));
97
+ if (!wantsJson(argv)) {
98
+ const printUpdateNudge = deps.printUpdateNudge ?? (async (target) => {
99
+ const { printCachedVersionNudge } = await import("./version-check.js");
100
+ await printCachedVersionNudge(target);
101
+ });
102
+ await printUpdateNudge(stderr);
103
+ }
97
104
  }
98
105
  //# sourceMappingURL=version-report.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.304.0",
3
+ "version": "5.306.0",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -1,26 +0,0 @@
1
- /**
2
- * Work Context reconciliation package (consumable by hq-cli).
3
- * Contract (US-001) + reconcile / outbox / device default (US-007A)
4
- * + organize / project resolution (US-007B)
5
- * + cross-company correct / migrate (US-017B).
6
- */
7
- export * from "./contract.js";
8
- export * from "./errors.js";
9
- export * from "./paths.js";
10
- export * from "./atomic.js";
11
- export * from "./config.js";
12
- export * from "./state.js";
13
- export * from "./outbox.js";
14
- export * from "./company.js";
15
- export { companyBindingChanged, isNonCloudCompanySlug, presenceLeaveFromState, reboundSessionProjection, } from "./company-rebind.js";
16
- export * from "./project.js";
17
- export { decisionFromCandidates, digestOrganizePayload, formatOrganizeList, prepareOrganizeDecision, settleOrganizeAskWithoutBind, stableDecisionId, stableOrganizeOperationId, submitOrganizeDecision, } from "./organize.js";
18
- export type { CandidatesResponse, FetchCandidatesFn, OrganizeCandidate, OrganizeListResult, OrganizeReceipt, OrganizeSubmitDecision, OrganizeSubmitResult, PostOrganizeFn, } from "./organize.js";
19
- export { digestMigratePayload, formatMigrateConfirmation, stableMigrateOperationId, submitSessionMigration, } from "./migrate.js";
20
- export type { MigrateDestination, MigrateReceipt, MigrateSubmitResult, PostMigrateFn, } from "./migrate.js";
21
- export { deriveRemoteOwnerSlug, deriveRepoIdentityKey, findWorkTreeRoot, matchCompanySlugForRepo, normalizeRemoteOwnerName, } from "./repo-remote.js";
22
- export { matchMembershipAnswer, promptRepoCompany, } from "./repo-prompt.js";
23
- export type { RepoPromptCompany, RepoPromptDeps, RepoPromptOutcome, RepoPromptSkipReason, } from "./repo-prompt.js";
24
- export { loadObservationFromFile, markUntracked, parseObservationJson, reconcileObservation, } from "./reconcile.js";
25
- export type { ReconcileDeps, ReconcileObservation, ReconcileOutcome, } from "./reconcile.js";
26
- //# sourceMappingURL=index.d.ts.map
@@ -1,22 +0,0 @@
1
- /**
2
- * Work Context reconciliation package (consumable by hq-cli).
3
- * Contract (US-001) + reconcile / outbox / device default (US-007A)
4
- * + organize / project resolution (US-007B)
5
- * + cross-company correct / migrate (US-017B).
6
- */
7
- export * from "./contract.js";
8
- export * from "./errors.js";
9
- export * from "./paths.js";
10
- export * from "./atomic.js";
11
- export * from "./config.js";
12
- export * from "./state.js";
13
- export * from "./outbox.js";
14
- export * from "./company.js";
15
- export { companyBindingChanged, isNonCloudCompanySlug, presenceLeaveFromState, reboundSessionProjection, } from "./company-rebind.js";
16
- export * from "./project.js";
17
- export { decisionFromCandidates, digestOrganizePayload, formatOrganizeList, prepareOrganizeDecision, settleOrganizeAskWithoutBind, stableDecisionId, stableOrganizeOperationId, submitOrganizeDecision, } from "./organize.js";
18
- export { digestMigratePayload, formatMigrateConfirmation, stableMigrateOperationId, submitSessionMigration, } from "./migrate.js";
19
- export { deriveRemoteOwnerSlug, deriveRepoIdentityKey, findWorkTreeRoot, matchCompanySlugForRepo, normalizeRemoteOwnerName, } from "./repo-remote.js";
20
- export { matchMembershipAnswer, promptRepoCompany, } from "./repo-prompt.js";
21
- export { loadObservationFromFile, markUntracked, parseObservationJson, reconcileObservation, } from "./reconcile.js";
22
- //# sourceMappingURL=index.js.map