@indigoai-us/hq-cli 5.345.113 → 5.345.115

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 (61) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-send.sh +5 -1
  3. package/dist/commands/bot-jobs.d.ts +1 -11
  4. package/dist/commands/bot-jobs.js +13 -34
  5. package/dist/commands/capacity.js +2 -0
  6. package/dist/commands/core-audit-log-native.js +1 -1
  7. package/dist/commands/core-checkpoint-native.d.ts +27 -0
  8. package/dist/commands/core-checkpoint-native.js +85 -2
  9. package/dist/commands/core-dm-bind-native.js +1 -1
  10. package/dist/commands/core-git-pack-extension-check-native.js +1 -1
  11. package/dist/commands/core-job-native-utils.d.ts +2 -2
  12. package/dist/commands/core-job-native-utils.js +3 -11
  13. package/dist/commands/core-job-notify-native.js +1 -2
  14. package/dist/commands/core-job-probe-native.d.ts +2 -3
  15. package/dist/commands/core-job-probe-native.js +14 -22
  16. package/dist/commands/core-job-remediate-native.js +1 -2
  17. package/dist/commands/core-job-run-native.js +58 -54
  18. package/dist/commands/core-jobs-native.d.ts +1 -3
  19. package/dist/commands/core-jobs-native.js +16 -271
  20. package/dist/commands/core-jobs-schedule.d.ts +7 -0
  21. package/dist/commands/core-jobs-schedule.js +243 -0
  22. package/dist/commands/core-native-utilities.d.ts +2 -3
  23. package/dist/commands/core-native-utilities.js +2 -19
  24. package/dist/commands/core-pin-native.js +1 -1
  25. package/dist/commands/core-refresh-vault-access-native.js +1 -1
  26. package/dist/commands/core-resolve-company-command.js +2 -17
  27. package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
  28. package/dist/commands/core.js +1 -17
  29. package/dist/commands/lanes.js +1 -0
  30. package/dist/fast-scaffold.d.ts +1 -1
  31. package/dist/fast-scaffold.js +0 -38
  32. package/dist/lib/capacity/lane-login.js +73 -6
  33. package/dist/lib/capacity/route.d.ts +1 -1
  34. package/dist/lib/capacity/route.js +5 -1
  35. package/dist/lib/capacity/sign-in.d.ts +12 -0
  36. package/dist/lib/capacity/sign-in.js +65 -16
  37. package/dist/lib/daemon/catalog.d.ts +0 -2
  38. package/dist/lib/daemon/catalog.js +3 -6
  39. package/dist/lib/daemon/run.js +0 -7
  40. package/dist/utils/resident-package-preload.js +2 -7
  41. package/package.json +1 -1
  42. package/assets/scaffold/core/scripts/audit-log.sh +0 -384
  43. package/assets/scaffold/core/scripts/git-pack-extension-check.sh +0 -164
  44. package/assets/scaffold/core/scripts/hq-dm-bind.sh +0 -590
  45. package/assets/scaffold/core/scripts/hq-job-notify.sh +0 -389
  46. package/assets/scaffold/core/scripts/hq-job-probe.sh +0 -865
  47. package/assets/scaffold/core/scripts/hq-job-remediate.sh +0 -359
  48. package/assets/scaffold/core/scripts/hq-job-run.sh +0 -1025
  49. package/assets/scaffold/core/scripts/hq-pin.sh +0 -118
  50. package/assets/scaffold/core/scripts/jobs-schedule-parse.sh +0 -310
  51. package/assets/scaffold/core/scripts/jobs-validate.sh +0 -482
  52. package/assets/scaffold/core/scripts/outpost-jobs-reconcile.sh +0 -836
  53. package/assets/scaffold/core/scripts/refresh-vault-access.sh +0 -188
  54. package/assets/scaffold/core/scripts/resolve-company.sh +0 -331
  55. package/assets/scaffold/core/scripts/work-mesh-live-bind-trusted.sh +0 -184
  56. package/dist/commands/core-job-post-exit-assets.d.ts +0 -8
  57. package/dist/commands/core-job-post-exit-assets.js +0 -37
  58. package/dist/commands/core-native-jobs-flag.d.ts +0 -4
  59. package/dist/commands/core-native-jobs-flag.js +0 -7
  60. package/dist/commands/core-native-utilities-flag.d.ts +0 -4
  61. package/dist/commands/core-native-utilities-flag.js +0 -7
@@ -10,30 +10,76 @@ import * as fs from "node:fs";
10
10
  import * as os from "node:os";
11
11
  import * as path from "node:path";
12
12
  import { createLaneAccountsHandlers } from "../../commands/lanes-accounts.js";
13
+ import { effectiveAccountHome } from "../lanes/account-home.js";
14
+ import { canonicalizeHome, DEFAULT_ACCOUNT_HOMES, loadLanesConfig } from "../lanes/config.js";
13
15
  import { resolveLanesHqRoot } from "../lanes/hq-root.js";
14
16
  import { defaultProbe } from "../lanes/models.js";
17
+ import { parseLaneProvider } from "../lanes/types.js";
15
18
  const ACCOUNT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
16
19
  const RESERVED_ACCOUNT_IDS = new Set(["a", "default"]);
17
20
  export async function loginLaneAccount(input) {
18
- if (!ACCOUNT_ID_PATTERN.test(input.accountId) || RESERVED_ACCOUNT_IDS.has(input.accountId)) {
19
- throw new Error(`Refusing account id ${input.accountId}. Use letters, numbers, dots, underscores, or hyphens, and not a reserved id.`);
21
+ if (!ACCOUNT_ID_PATTERN.test(input.accountId)) {
22
+ throw new Error(`Refusing account id ${input.accountId}. Use letters, numbers, dots, underscores, or hyphens.`);
20
23
  }
21
24
  const hqRoot = input.hqRoot ?? resolveLanesHqRoot({ env: input.env });
25
+ const provider = parseLaneProvider(input.provider);
26
+ const homedir = input.homedir ?? os.homedir;
27
+ const hostname = input.hostname ?? os.hostname();
28
+ const existing = existingAccount(hqRoot, provider, input.accountId, hostname, homedir);
22
29
  let captured;
23
30
  const handlers = createLaneAccountsHandlers(handlerDeps((value) => {
24
31
  captured = value;
25
32
  }));
26
33
  // One registry write. capacityOnly stores enabled:false and the capacity-only
27
34
  // reason in that write, re-checking whether lanes already use the account.
28
- await handlers.runAccountsLogin(loginCtx(input, hqRoot), input.provider, input.accountId, {
35
+ // A registered id signs in again into the home the registry already names.
36
+ await handlers.runAccountsLogin(loginCtx(input, hqRoot), provider, existing?.id ?? input.accountId, {
29
37
  capacityOnly: true,
30
38
  });
31
39
  const account = captured?.account;
32
40
  if (!account?.id || !account.home) {
33
- throw new Error(`lanes accounts login did not register ${input.provider} ${input.accountId}`);
41
+ throw new Error(`lanes accounts login did not register ${provider} ${input.accountId}`);
42
+ }
43
+ if (existing && (account.id !== existing.id || account.home !== existing.home)) {
44
+ throw new Error(`Sign-in for ${provider} ${existing.id} moved it to ${account.id} at ${account.home}; expected ${existing.home}`);
34
45
  }
35
46
  return { id: account.id, home: account.home };
36
47
  }
48
+ /**
49
+ * The registry account an id names, with the home lanes use on this host.
50
+ * `default` names the account registered at the provider's default home.
51
+ * Reserved ids sign in again only when they name a registered account, so a
52
+ * new account never takes `a` or `default`.
53
+ */
54
+ function existingAccount(hqRoot, provider, accountId, hostname, homedir) {
55
+ const accounts = loadLanesConfig(hqRoot).providers[provider].accounts;
56
+ const canonical = (home) => canonicalHome(home, homedir);
57
+ if (accountId === "default") {
58
+ const defaultHome = canonical(DEFAULT_ACCOUNT_HOMES[provider]);
59
+ for (const [id, entry] of Object.entries(accounts)) {
60
+ if (!entry)
61
+ continue;
62
+ const home = canonical(effectiveAccountHome(entry, hostname).home);
63
+ if (home === defaultHome)
64
+ return { id, home };
65
+ }
66
+ throw new Error(`No ${provider} account is registered at the default home. Run hq capacity login ${provider} to add one.`);
67
+ }
68
+ const entry = accounts[accountId];
69
+ if (entry)
70
+ return { id: accountId, home: canonical(effectiveAccountHome(entry, hostname).home) };
71
+ if (RESERVED_ACCOUNT_IDS.has(accountId)) {
72
+ throw new Error(`Refusing account id ${accountId}. It is reserved and no ${provider} account uses it.`);
73
+ }
74
+ return null;
75
+ }
76
+ function canonicalHome(home, homedir) {
77
+ return canonicalizeHome(home, {
78
+ homedir,
79
+ realpathSync: (target) => fs.realpathSync(target),
80
+ existsSync: (target) => fs.existsSync(target),
81
+ });
82
+ }
37
83
  function handlerDeps(printJson) {
38
84
  return {
39
85
  automaticBalanceMoveHistoryReason: () => unused("automaticBalanceMoveHistoryReason"),
@@ -59,8 +105,8 @@ function loginCtx(input, hqRoot) {
59
105
  hostname: () => input.hostname ?? os.hostname(),
60
106
  homedir: input.homedir ?? os.homedir,
61
107
  existsSync: (target) => fs.existsSync(target),
62
- spawnLogin: input.spawnLogin ?? defaultSpawnLogin,
63
- probeProvider: input.probeProvider ?? defaultProbe,
108
+ spawnLogin: defaultHomeEnv(input.spawnLogin ?? defaultSpawnLogin, input.homedir ?? os.homedir),
109
+ probeProvider: defaultHomeProbe(input.probeProvider ?? defaultProbe, input.homedir ?? os.homedir),
64
110
  };
65
111
  return new Proxy(fields, {
66
112
  get(target, prop) {
@@ -72,6 +118,27 @@ function loginCtx(input, hqRoot) {
72
118
  },
73
119
  });
74
120
  }
121
+ /**
122
+ * Claude Code keys its Keychain item on CLAUDE_CONFIG_DIR. The default home
123
+ * keeps the plain `Claude Code-credentials` item only when the variable is
124
+ * unset, so a sign-in into ~/.claude runs without it.
125
+ */
126
+ function defaultHomeEnv(spawnLogin, homedir) {
127
+ return (opts) => spawnLogin({ ...opts, env: withoutDefaultClaudeDir(opts.env, homedir) });
128
+ }
129
+ /** The sign-in check reads the same Keychain item the sign-in wrote. */
130
+ function defaultHomeProbe(probe, homedir) {
131
+ return (command, args, env) => probe(command, args, withoutDefaultClaudeDir(env, homedir));
132
+ }
133
+ function withoutDefaultClaudeDir(env, homedir) {
134
+ const configDir = env.CLAUDE_CONFIG_DIR;
135
+ if (!configDir || canonicalHome(configDir, homedir) !== canonicalHome(DEFAULT_ACCOUNT_HOMES.claude, homedir)) {
136
+ return env;
137
+ }
138
+ const next = { ...env };
139
+ delete next.CLAUDE_CONFIG_DIR;
140
+ return next;
141
+ }
75
142
  function defaultSpawnLogin(opts) {
76
143
  return new Promise((resolve, reject) => {
77
144
  const child = spawn(opts.command, opts.args, {
@@ -1,6 +1,6 @@
1
1
  import type { LaneRecord, LaneState, LanesConfig } from "../lanes/types.js";
2
2
  import { type LaneProvider } from "../lanes/types.js";
3
- import type { NowLimit, NowView } from "./ledger.js";
3
+ import { type NowLimit, type NowView } from "./ledger.js";
4
4
  /** All lane providers, in the stable order boss-route uses for ranking ties. */
5
5
  export declare const ROUTE_PROVIDERS: readonly LaneProvider[];
6
6
  /** Lane states that count against an account's live load. */
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { canonicalizeHome } from "../lanes/config.js";
17
17
  import { LANE_PROVIDERS } from "../lanes/types.js";
18
+ import { capacityLoginCommand } from "./ledger.js";
18
19
  /** All lane providers, in the stable order boss-route uses for ranking ties. */
19
20
  export const ROUTE_PROVIDERS = LANE_PROVIDERS;
20
21
  /** Lane states that count against an account's live load. */
@@ -225,7 +226,10 @@ export function pickAccount(input) {
225
226
  skipped.push({
226
227
  ...base,
227
228
  reason: account.reason ?? `sign-in ${authState}`,
228
- fix: account.fixCommand ?? null,
229
+ // Every signed-out reason (revoked, missing credential, missing
230
+ // scope, auth-failed lane) is fixed by signing the lane account in
231
+ // again, so the fix names the registry id lanes use.
232
+ fix: capacityLoginCommand(providerId, laneMatch.id),
229
233
  });
230
234
  continue;
231
235
  }
@@ -88,6 +88,18 @@ export interface CapacityLoginResult {
88
88
  json?: unknown;
89
89
  }
90
90
  export declare function executeCapacityLogin(request: CapacityLoginRequest, deps: CapacityLoginDeps): Promise<CapacityLoginResult>;
91
+ export interface RepairFixed {
92
+ provider: string;
93
+ label: string;
94
+ account: string;
95
+ home: string;
96
+ }
97
+ export interface RepairSkipped {
98
+ provider: string;
99
+ label: string;
100
+ reason: string;
101
+ fix: string | null;
102
+ }
91
103
  export declare function organizationFor(view: NowView, provider: string, home: string): string | null;
92
104
  export declare function renameCapacityAccount(hqRoot: string, providerRaw: string, fromRaw: string, toRaw: string, options?: {
93
105
  force?: boolean;
@@ -278,8 +278,11 @@ export async function executeCapacityLogin(request, deps) {
278
278
  if (request.account && !request.provider) {
279
279
  throw new SignInUsageError("Pass a provider before --account.");
280
280
  }
281
+ // A reserved id (a, default) is accepted here so a registered account can
282
+ // sign in again into its home. The lane login refuses one that names no
283
+ // registered account.
281
284
  if (request.account)
282
- assertRegistryAccountId(request.account);
285
+ assertAccountIdShape(request.account);
283
286
  const providerFilter = request.provider;
284
287
  const wantsSignIn = Boolean(request.provider || request.account || request.repair);
285
288
  if (!request.interactive && wantsSignIn && !request.json) {
@@ -308,19 +311,69 @@ export async function executeCapacityLogin(request, deps) {
308
311
  }
309
312
  return { exitCode: 0, text: lines.join("\n\n") };
310
313
  }
314
+ /**
315
+ * Signs in again for each signed-out account, one at a time, in roster order.
316
+ * A failed sign-in is reported and the next account still runs. Expired
317
+ * accounts are reported as skipped: opening the account refreshes them.
318
+ */
311
319
  async function runRepair(request, deps) {
312
320
  const plan = repairSelection(deps.rows, request.provider);
313
321
  const lines = [formatRepairPlan(plan)];
322
+ const fixed = [];
323
+ const skipped = [];
314
324
  for (const row of plan.signedOut) {
315
- if (row.label === "default" || RESERVED_IDS.has(row.label)) {
316
- lines.push(`${row.provider} ${row.label}: ${defaultVendorLogin(row.provider)}`);
325
+ const fix = row.command ?? `hq capacity login ${row.provider} --account ${row.label}`;
326
+ let logged;
327
+ try {
328
+ logged = await deps.loginAccount(row.provider, row.label);
329
+ }
330
+ catch (err) {
331
+ skipped.push({ provider: row.provider, label: row.label, reason: errorText(err), fix });
317
332
  continue;
318
333
  }
319
- const logged = await deps.loginAccount(row.provider, row.label);
320
- const view = await deps.readAccount(row.provider, row.label, logged.home);
321
- lines.push(deps.formatReading(view, row.provider, row.label, logged.home));
334
+ fixed.push({ provider: row.provider, label: row.label, account: logged.id, home: logged.home });
335
+ try {
336
+ const view = await deps.readAccount(row.provider, logged.id, logged.home);
337
+ lines.push(deps.formatReading(view, row.provider, row.label, logged.home));
338
+ }
339
+ catch (err) {
340
+ lines.push(`${row.provider} ${row.label}: signed in; usage read failed: ${errorText(err)}`);
341
+ }
322
342
  }
323
- return { exitCode: 0, text: lines.join("\n\n") };
343
+ for (const row of plan.expired) {
344
+ skipped.push({
345
+ provider: row.provider,
346
+ label: row.label,
347
+ reason: row.reason ?? EXPIRED_REASON,
348
+ fix: row.command ? formatRefreshLine(row.provider, row.command) : null,
349
+ });
350
+ }
351
+ lines.push(formatRepairSummary(fixed, skipped));
352
+ const failed = skipped.some((item) => plan.signedOut.some((row) => row.provider === item.provider && row.label === item.label));
353
+ return {
354
+ exitCode: failed ? 1 : 0,
355
+ text: lines.join("\n\n"),
356
+ json: { repair: { fixed, skipped } },
357
+ };
358
+ }
359
+ function formatRepairSummary(fixed, skipped) {
360
+ const lines = ["Fixed:"];
361
+ if (fixed.length === 0)
362
+ lines.push(" none");
363
+ for (const item of fixed)
364
+ lines.push(` ${item.provider} ${item.label}`);
365
+ lines.push("Skipped:");
366
+ if (skipped.length === 0)
367
+ lines.push(" none");
368
+ for (const item of skipped) {
369
+ lines.push(` ${item.provider} ${item.label}: ${item.reason}`);
370
+ if (item.fix)
371
+ lines.push(` ${item.fix}`);
372
+ }
373
+ return lines.join("\n");
374
+ }
375
+ function errorText(err) {
376
+ return err instanceof Error ? err.message : String(err);
324
377
  }
325
378
  async function signInOne(provider, account, deps) {
326
379
  const id = account ?? deps.newAccountId();
@@ -489,20 +542,16 @@ function isAncestor(parent, child) {
489
542
  const relative = path.relative(parent, child);
490
543
  return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
491
544
  }
545
+ function assertAccountIdShape(id) {
546
+ if (!ID_PATTERN.test(id)) {
547
+ throw new SignInUsageError("Account id must start with a letter or number and contain only letters, numbers, dots, underscores, or hyphens.");
548
+ }
549
+ }
492
550
  function assertRegistryAccountId(id) {
493
551
  if (!ID_PATTERN.test(id) || RESERVED_IDS.has(id)) {
494
552
  throw new SignInUsageError("Account id must start with a letter or number, contain only letters, numbers, dots, underscores, or hyphens, and must not be reserved (a, default).");
495
553
  }
496
554
  }
497
- function defaultVendorLogin(provider) {
498
- if (provider === "claude")
499
- return "claude auth login";
500
- if (provider === "codex")
501
- return "codex login";
502
- if (provider === "grok")
503
- return "grok login";
504
- return `hq capacity login ${provider}`;
505
- }
506
555
  function requiredId(value, name) {
507
556
  const id = value.trim();
508
557
  if (!id || id !== value)
@@ -121,8 +121,6 @@ export interface PlanContext {
121
121
  legacyOwner: (unitId: string) => string | null;
122
122
  /** This CLI is a global install the updater can replace (not a project dependency). */
123
123
  cliSelfUpdatable: boolean;
124
- /** `<hqRoot>/core/scripts/outpost-jobs-reconcile.sh` when it exists. */
125
- jobsReconcileScript: string | null;
126
124
  /** Absolute paths of the claude and tmux binaries, or null when not installed. */
127
125
  claudePath: string | null;
128
126
  tmuxPath: string | null;
@@ -279,21 +279,18 @@ function planService(service, ctx) {
279
279
  case "jobs-reconcile": {
280
280
  if (ctx.platform === "win32")
281
281
  return [unavailable(service, "needs bash; not supported on Windows")];
282
- const script = ctx.jobsReconcileScript;
283
282
  return [
284
283
  base(service, {
285
284
  kind: "scheduled",
286
285
  intervalSec: 600,
287
286
  initialDelaySec: 600,
288
287
  command: {
289
- type: "exec",
290
- file: "bash",
291
- args: [script ?? "", "--hq-root", ctx.hqRoot ?? "", "--ensure-hook", "--after-sync"],
288
+ type: "hq",
289
+ args: ["core", "--hq-root", ctx.hqRoot ?? "", "jobs", "reconcile", "--ensure-hook", "--after-sync"],
292
290
  },
293
- env: ctx.hqRoot ? { HQ_ROOT: ctx.hqRoot } : {},
291
+ env: ctx.hqRoot ? { HQ_ROOT: ctx.hqRoot, HQ_NO_UPDATE_CHECK: "1" } : { HQ_NO_UPDATE_CHECK: "1" },
294
292
  blocked: firstBlock([
295
293
  [!ctx.hqRoot, NO_HQ_ROOT],
296
- [!script, "this HQ folder has no core/scripts/outpost-jobs-reconcile.sh"],
297
294
  ]),
298
295
  }),
299
296
  ];
@@ -350,12 +350,6 @@ export function desktopAppManagesSync(opts) {
350
350
  return false;
351
351
  return opts.legacy.some((u) => u.service === "sync" && !u.migratable) || opts.appRunning();
352
352
  }
353
- function jobsReconcileScript(hqRoot) {
354
- if (!hqRoot)
355
- return null;
356
- const script = path.join(hqRoot, "core", "scripts", "outpost-jobs-reconcile.sh");
357
- return fs.existsSync(script) ? script : null;
358
- }
359
353
  function signedIn(env, home, log) {
360
354
  if (fs.existsSync(agentKitPaths(home, env).machineCredsPath))
361
355
  return true;
@@ -859,7 +853,6 @@ export async function runDaemon(opts) {
859
853
  bots: listLocalBots(),
860
854
  legacyOwner: legacyOwnerLookup(legacy),
861
855
  cliSelfUpdatable: updatable,
862
- jobsReconcileScript: jobsReconcileScript(hqRoot),
863
856
  claudePath: findUserBinary("claude", env, home),
864
857
  codexPath: findUserBinary("codex", env, home),
865
858
  codexRunnerScript: platform === "linux" && fs.existsSync(CODEX_RUNNER_SCRIPT) ? CODEX_RUNNER_SCRIPT : null,
@@ -42,7 +42,7 @@ export const RESIDENT_PACKAGE_MODULES = {
42
42
  "bot-logs-follow": [],
43
43
  mcp: ["../lib/mcp/tools.js", "../lib/mcp/prompts.js", "../lib/anywhere-person-setting.js", "../utils/cognito-session.js", "@indigoai-us/hq-cloud", "../sentry.js", "../lib/doctor/client-health-reason-codes-flag.js", "@indigoai-us/hq-flags-client"],
44
44
  childWrapper: ["../main.js", "../lib/service-manager/startup-migration.js", "../commands/storage-gate.js", "../lib/storage-feature-flag.js"],
45
- coreJobRun: ["../commands/core-native-jobs-flag.js", "../commands/core-native-family-flag.js", "../lib/flag-registry.js", "../lib/flag-snapshot-file.js"],
45
+ coreJobRun: [],
46
46
  "daemon-call": ["../lib/daemon/protocol.js"],
47
47
  daemon: [
48
48
  "../sentry.js",
@@ -204,12 +204,7 @@ const LOADERS = {
204
204
  () => import("../commands/storage-gate.js"),
205
205
  () => import("../lib/storage-feature-flag.js"),
206
206
  ],
207
- coreJobRun: [
208
- () => import("../commands/core-native-jobs-flag.js"),
209
- () => import("../commands/core-native-family-flag.js"),
210
- () => import("../lib/flag-registry.js"),
211
- () => import("../lib/flag-snapshot-file.js"),
212
- ],
207
+ coreJobRun: [],
213
208
  "daemon-call": [
214
209
  () => import("../lib/daemon/protocol.js"),
215
210
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.113",
3
+ "version": "5.345.115",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {