@indigoai-us/hq-cli 5.345.223 → 5.345.226

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 (130) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/assets/bot-workers/setup/context/quick-reference.md +2 -2
  3. package/assets/mesh-daemon/README.md +11 -12
  4. package/dist/command-catalog.generated.d.ts +156 -4
  5. package/dist/command-catalog.generated.js +191 -4
  6. package/dist/commands/cloud-provision.d.ts +4 -1
  7. package/dist/commands/cloud-provision.js +7 -3
  8. package/dist/commands/cloud-retire.js +1 -1
  9. package/dist/commands/core-delegate-w1b.js +3 -1
  10. package/dist/commands/core-delegate.d.ts +5 -0
  11. package/dist/commands/core-dm-bind-native.d.ts +5 -1
  12. package/dist/commands/core-dm-bind-native.js +4 -0
  13. package/dist/commands/core-job-notify-native.d.ts +5 -1
  14. package/dist/commands/core-job-notify-native.js +8 -2
  15. package/dist/commands/core-jobs-native.d.ts +27 -1
  16. package/dist/commands/core-jobs-native.js +49 -28
  17. package/dist/commands/core-pipeline-conductor-native.js +7 -7
  18. package/dist/commands/core-pipeline-driver-native.js +5 -5
  19. package/dist/commands/core-refresh-vault-access-native.d.ts +5 -0
  20. package/dist/commands/core-refresh-vault-access-native.js +3 -1
  21. package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
  22. package/dist/commands/daemon.d.ts +2 -0
  23. package/dist/commands/daemon.js +68 -2
  24. package/dist/commands/deploy-domains.js +38 -2
  25. package/dist/commands/lanes-accounts.d.ts +14 -0
  26. package/dist/commands/lanes-accounts.js +119 -0
  27. package/dist/commands/lanes-hold.d.ts +2 -27
  28. package/dist/commands/lanes-hold.js +3 -75
  29. package/dist/commands/lanes-loop.js +1 -1
  30. package/dist/commands/lanes-move.js +10 -0
  31. package/dist/commands/lanes-session-start.js +2 -2
  32. package/dist/commands/lanes-shared.js +9 -0
  33. package/dist/commands/lanes.js +137 -12
  34. package/dist/commands/mesh.d.ts +12 -0
  35. package/dist/commands/mesh.js +13 -4
  36. package/dist/commands/monitor.js +1 -1
  37. package/dist/commands/packs.js +1 -1
  38. package/dist/commands/sync-held.d.ts +22 -0
  39. package/dist/commands/sync-held.js +167 -18
  40. package/dist/commands/whoami.d.ts +10 -17
  41. package/dist/commands/whoami.js +7 -79
  42. package/dist/data/command-states.json +13 -0
  43. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
  44. package/dist/hq-cloud-sync-runner/package.json +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/lib/capacity/accounts.d.ts +4 -0
  47. package/dist/lib/capacity/accounts.js +4 -0
  48. package/dist/lib/capacity/route.js +14 -0
  49. package/dist/lib/capacity/sign-in.d.ts +18 -0
  50. package/dist/lib/capacity/sign-in.js +34 -1
  51. package/dist/lib/daemon/catalog.d.ts +9 -5
  52. package/dist/lib/daemon/catalog.js +14 -8
  53. package/dist/lib/daemon/config.d.ts +5 -0
  54. package/dist/lib/daemon/config.js +6 -0
  55. package/dist/lib/daemon/hook-requests.d.ts +76 -0
  56. package/dist/lib/daemon/hook-requests.js +481 -0
  57. package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
  58. package/dist/lib/daemon/lanes-monitor-state.js +129 -0
  59. package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
  60. package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
  61. package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
  62. package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
  63. package/dist/lib/daemon/merge-sections.d.ts +165 -0
  64. package/dist/lib/daemon/merge-sections.js +556 -0
  65. package/dist/lib/daemon/ops/policy.d.ts +2 -2
  66. package/dist/lib/daemon/ops/policy.js +44 -5
  67. package/dist/lib/daemon/protocol.d.ts +1 -1
  68. package/dist/lib/daemon/protocol.js +0 -6
  69. package/dist/lib/daemon/run.js +110 -5
  70. package/dist/lib/daemon/selfcheck.js +2 -2
  71. package/dist/lib/daemon/server.d.ts +2 -4
  72. package/dist/lib/daemon/server.js +11 -49
  73. package/dist/lib/daemon/state-file.d.ts +74 -4
  74. package/dist/lib/daemon/state-file.js +159 -19
  75. package/dist/lib/daemon/supervisor.d.ts +3 -1
  76. package/dist/lib/daemon/updater.d.ts +2 -6
  77. package/dist/lib/daemon/updater.js +4 -11
  78. package/dist/lib/daemon/whoami-cache.d.ts +96 -0
  79. package/dist/lib/daemon/whoami-cache.js +244 -0
  80. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  81. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  82. package/dist/lib/hook-engine/coverage.d.ts +2 -0
  83. package/dist/lib/hook-engine/coverage.js +71 -0
  84. package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
  85. package/dist/lib/hook-engine/reconcile.js +14 -8
  86. package/dist/lib/install/hook-target.d.ts +13 -3
  87. package/dist/lib/install/hook-target.js +14 -11
  88. package/dist/lib/lanes/account-company.d.ts +7 -1
  89. package/dist/lib/lanes/account-company.js +22 -4
  90. package/dist/lib/lanes/account-ownership.d.ts +65 -0
  91. package/dist/lib/lanes/account-ownership.js +134 -0
  92. package/dist/lib/lanes/accounts.js +9 -2
  93. package/dist/lib/lanes/claude-balance.js +9 -3
  94. package/dist/lib/lanes/config.js +17 -0
  95. package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
  96. package/dist/lib/lanes/host-capacity.d.ts +19 -0
  97. package/dist/lib/lanes/host-capacity.js +37 -0
  98. package/dist/lib/lanes/monitor.d.ts +2 -0
  99. package/dist/lib/lanes/monitor.js +2 -1
  100. package/dist/lib/lanes/reconcile.js +44 -3
  101. package/dist/lib/lanes/registry-flag.d.ts +6 -0
  102. package/dist/lib/lanes/registry-flag.js +3 -2
  103. package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
  104. package/dist/lib/lanes/repo-merge-hold.js +90 -0
  105. package/dist/lib/lanes/spawn.d.ts +0 -10
  106. package/dist/lib/lanes/spawn.js +51 -1
  107. package/dist/lib/lanes/types.d.ts +12 -0
  108. package/dist/lib/lanes/watcher-main.js +3 -3
  109. package/dist/lib/mesh/live/daemon/doctor.js +1 -1
  110. package/dist/lib/mesh/live/daemon/install.js +2 -2
  111. package/dist/lib/windows/install-followup.js +1 -1
  112. package/dist/utils/client-health-contract.d.ts +1 -0
  113. package/dist/utils/client-health-contract.js +5 -0
  114. package/dist/utils/client-health.d.ts +2 -0
  115. package/dist/utils/client-health.js +40 -0
  116. package/dist/utils/cognito-session.d.ts +2 -14
  117. package/dist/utils/cognito-session.js +2 -40
  118. package/dist/utils/daemon-cli-version.d.ts +13 -0
  119. package/dist/utils/daemon-cli-version.js +47 -0
  120. package/dist/utils/duplicate-command-usage.js +1 -1
  121. package/dist/utils/machine-token-cache.d.ts +21 -0
  122. package/dist/utils/machine-token-cache.js +49 -0
  123. package/dist/utils/resident-package-preload.js +4 -0
  124. package/dist/utils/whoami-identity.d.ts +54 -0
  125. package/dist/utils/whoami-identity.js +108 -0
  126. package/package.json +8 -8
  127. package/dist/lib/daemon/ops/memory.d.ts +0 -18
  128. package/dist/lib/daemon/ops/memory.js +0 -65
  129. package/dist/lib/daemon/ops/mesh.d.ts +0 -38
  130. package/dist/lib/daemon/ops/mesh.js +0 -70
@@ -28,8 +28,8 @@ import chalk from "chalk";
28
28
  import { isExpiring, refreshTokens, saveCachedTokens, browserLogin, detectHqCoreVersion, isMachineIdentity, getValidMachineTokens, CognitoRefreshError, accessTokenFingerprint, invalidateCachedTokensByFingerprint, } from "@indigoai-us/hq-cloud";
29
29
  import { hasPersonCachedSession, isMachineCredsFileEnvSet, probeMachineIdentity, wantsMachineCognitoTokens, } from "./machine-principal-state.js";
30
30
  import { CLI_NAME, CLI_VERSION } from "../cli-version.js";
31
- import { daemonDir } from "../lib/mesh/live/daemon/paths.js";
32
- import { workMeshRoot } from "../lib/mesh/live/paths.js";
31
+ import { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir, } from "./machine-token-cache.js";
32
+ export { HQ_MACHINE_TOKEN_STATE_DIR_ENV, loadMachineCachedTokens, machineTokenCacheFile, machineTokenStateDir };
33
33
  import { defaultHqRootFallback, hqDiscoveryCandidates, pathForPlatform, } from "./hq-root-resolver.js";
34
34
  import { acquireLockFileExclusively } from "./exclusive-lock.js";
35
35
  import { interactiveLoginConfig, resolveCognitoCallbackPort } from "./cognito-callback-port.js";
@@ -46,7 +46,6 @@ export { hasPersonCachedSession, isMachineCredsFileEnvSet, wantsMachineCognitoTo
46
46
  * Default: the work-mesh daemon state dir (`~/.hq/work-mesh/daemon`), so a
47
47
  * machine mint never overwrites a person's `~/.hq/cognito-tokens.json`.
48
48
  */
49
- export const HQ_MACHINE_TOKEN_STATE_DIR_ENV = "HQ_MACHINE_TOKEN_STATE_DIR";
50
49
  export const DEFAULT_COGNITO = {
51
50
  region: process.env.AWS_REGION ?? "us-east-1",
52
51
  userPoolDomain: process.env.HQ_COGNITO_DOMAIN ?? "vault-indigo-hq-prod",
@@ -230,21 +229,6 @@ function isHqRoot(dir, p = path) {
230
229
  }
231
230
  }
232
231
  export const DEFAULT_HQ_ROOT = resolveDefaultHqRoot();
233
- /**
234
- * Directory used as `HQ_STATE_DIR` while minting/caching machine Cognito
235
- * tokens. Never the person's `~/.hq` — agent boxes write under the daemon
236
- * state dir so a mint cannot clobber a human login cache.
237
- */
238
- export function machineTokenStateDir(home = os.homedir(), env = process.env) {
239
- const override = env[HQ_MACHINE_TOKEN_STATE_DIR_ENV]?.trim();
240
- if (override)
241
- return override;
242
- return daemonDir(workMeshRoot(home, env), home, env);
243
- }
244
- /** Absolute path of the machine-token cache file (daemon state dir). */
245
- export function machineTokenCacheFile(home = os.homedir(), env = process.env) {
246
- return path.join(machineTokenStateDir(home, env), "cognito-tokens.json");
247
- }
248
232
  /** Default machine-creds path hq-cloud also checks when the env is unset. */
249
233
  export function defaultMachineCredsFile(home = os.homedir()) {
250
234
  return path.join(home, ".hq-agent", "machine-creds.json");
@@ -662,28 +646,6 @@ export function actorKindFromIdToken(idToken) {
662
646
  }
663
647
  return "human";
664
648
  }
665
- /**
666
- * Peek the machine-token cache under the daemon state dir without minting.
667
- * Used by doctor; never logs token material.
668
- */
669
- export function loadMachineCachedTokens(home = os.homedir(), env = process.env) {
670
- const file = machineTokenCacheFile(home, env);
671
- try {
672
- if (!fs.existsSync(file))
673
- return null;
674
- const raw = JSON.parse(fs.readFileSync(file, "utf8"));
675
- if (typeof raw.accessToken !== "string" ||
676
- typeof raw.idToken !== "string" ||
677
- raw.accessToken.length === 0 ||
678
- raw.idToken.length === 0) {
679
- return null;
680
- }
681
- return raw;
682
- }
683
- catch {
684
- return null;
685
- }
686
- }
687
649
  /**
688
650
  * Report token source + actor kind for `hq mesh daemon doctor`. Does not mint
689
651
  * or hit the network. Machine identity without a readable cache still reports
@@ -0,0 +1,13 @@
1
+ export declare const PARENT_COMMAND_LINE_TIMEOUT_MS = 2000;
2
+ export interface DaemonCliVersionDeps {
3
+ env?: NodeJS.ProcessEnv;
4
+ parentCommandLine?: () => Promise<string | null>;
5
+ }
6
+ /**
7
+ * The version a daemon handed to the staged child bootstrap that started this
8
+ * unit: `<node> <...>/hq-child-bootstrap.mjs <prefix> <version> [args]`.
9
+ * Daemons have started units this way since 2026-10-05 (#1541).
10
+ */
11
+ export declare function daemonVersionFromBootstrapCommandLine(line: string | null): string | null;
12
+ export declare function resolveDaemonCliVersion(deps?: DaemonCliVersionDeps): Promise<string | null>;
13
+ //# sourceMappingURL=daemon-cli-version.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { execFile } from "node:child_process";
2
+ const SEMVER = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
3
+ export const PARENT_COMMAND_LINE_TIMEOUT_MS = 2_000;
4
+ function readParentCommandLine() {
5
+ const pid = Math.trunc(process.ppid);
6
+ const [cmd, args] = process.platform === "win32"
7
+ ? [
8
+ "powershell.exe",
9
+ [
10
+ "-NoProfile",
11
+ "-NonInteractive",
12
+ "-Command",
13
+ `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CommandLine`,
14
+ ],
15
+ ]
16
+ : ["ps", ["-ww", "-o", "args=", "-p", String(pid)]];
17
+ return new Promise((resolve) => {
18
+ const child = execFile(cmd, args, { encoding: "utf8", windowsHide: true, timeout: PARENT_COMMAND_LINE_TIMEOUT_MS }, (error, stdout) => {
19
+ const line = error ? "" : String(stdout).trim();
20
+ resolve(line || null);
21
+ });
22
+ child.unref?.();
23
+ });
24
+ }
25
+ /**
26
+ * The version a daemon handed to the staged child bootstrap that started this
27
+ * unit: `<node> <...>/hq-child-bootstrap.mjs <prefix> <version> [args]`.
28
+ * Daemons have started units this way since 2026-10-05 (#1541).
29
+ */
30
+ export function daemonVersionFromBootstrapCommandLine(line) {
31
+ if (!line)
32
+ return null;
33
+ const match = /hq-child-bootstrap\.m?js\s.*?(?:^|\s)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)(?=\s|$)/.exec(line);
34
+ return match?.[1] ?? null;
35
+ }
36
+ export async function resolveDaemonCliVersion(deps = {}) {
37
+ const env = deps.env ?? process.env;
38
+ if (!env.HQ_DAEMON_UNIT?.trim())
39
+ return null;
40
+ const fromEnv = env.HQ_DAEMON_CLI_VERSION?.trim();
41
+ if (fromEnv)
42
+ return SEMVER.test(fromEnv) ? fromEnv : null;
43
+ const line = await (deps.parentCommandLine ?? readParentCommandLine)();
44
+ const fromBootstrap = daemonVersionFromBootstrapCommandLine(line);
45
+ return fromBootstrap !== null && SEMVER.test(fromBootstrap) ? fromBootstrap : null;
46
+ }
47
+ //# sourceMappingURL=daemon-cli-version.js.map
@@ -31,7 +31,7 @@ export const DUPLICATE_COMMANDS = [
31
31
  { command: "sync mode", countedAs: ["sync mode"], owner: "daemon sync mode" },
32
32
  { command: "packages install", countedAs: ["packages install"], owner: "install" },
33
33
  { command: "packages list", countedAs: ["packages list", "packages ls"], owner: "packs list" },
34
- { command: "packages update", countedAs: ["packages update"], owner: null },
34
+ { command: "packages update", countedAs: ["packages update"], owner: "packs update" },
35
35
  { command: "packages remove", countedAs: ["packages remove"], owner: "remove" },
36
36
  ];
37
37
  /** Default window. */
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The machine-token cache location and reader, without any network code, so
3
+ * network-free callers (the daemon's cached whoami check in native commands)
4
+ * can read it. Re-exported by cognito-session.ts.
5
+ */
6
+ import type { CognitoTokens } from "@indigoai-us/hq-cloud";
7
+ export declare const HQ_MACHINE_TOKEN_STATE_DIR_ENV = "HQ_MACHINE_TOKEN_STATE_DIR";
8
+ /**
9
+ * Directory used as `HQ_STATE_DIR` while minting/caching machine Cognito
10
+ * tokens. Never the person's `~/.hq` — agent boxes write under the daemon
11
+ * state dir so a mint cannot clobber a human login cache.
12
+ */
13
+ export declare function machineTokenStateDir(home?: string, env?: NodeJS.ProcessEnv): string;
14
+ /** Absolute path of the machine-token cache file (daemon state dir). */
15
+ export declare function machineTokenCacheFile(home?: string, env?: NodeJS.ProcessEnv): string;
16
+ /**
17
+ * Peek the machine-token cache under the daemon state dir without minting.
18
+ * Used by doctor; never logs token material.
19
+ */
20
+ export declare function loadMachineCachedTokens(home?: string, env?: NodeJS.ProcessEnv): CognitoTokens | null;
21
+ //# sourceMappingURL=machine-token-cache.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The machine-token cache location and reader, without any network code, so
3
+ * network-free callers (the daemon's cached whoami check in native commands)
4
+ * can read it. Re-exported by cognito-session.ts.
5
+ */
6
+ import * as fs from "node:fs";
7
+ import * as os from "node:os";
8
+ import * as path from "node:path";
9
+ import { daemonDir } from "../lib/mesh/live/daemon/paths.js";
10
+ import { workMeshRoot } from "../lib/mesh/live/paths.js";
11
+ export const HQ_MACHINE_TOKEN_STATE_DIR_ENV = "HQ_MACHINE_TOKEN_STATE_DIR";
12
+ /**
13
+ * Directory used as `HQ_STATE_DIR` while minting/caching machine Cognito
14
+ * tokens. Never the person's `~/.hq` — agent boxes write under the daemon
15
+ * state dir so a mint cannot clobber a human login cache.
16
+ */
17
+ export function machineTokenStateDir(home = os.homedir(), env = process.env) {
18
+ const override = env[HQ_MACHINE_TOKEN_STATE_DIR_ENV]?.trim();
19
+ if (override)
20
+ return override;
21
+ return daemonDir(workMeshRoot(home, env), home, env);
22
+ }
23
+ /** Absolute path of the machine-token cache file (daemon state dir). */
24
+ export function machineTokenCacheFile(home = os.homedir(), env = process.env) {
25
+ return path.join(machineTokenStateDir(home, env), "cognito-tokens.json");
26
+ }
27
+ /**
28
+ * Peek the machine-token cache under the daemon state dir without minting.
29
+ * Used by doctor; never logs token material.
30
+ */
31
+ export function loadMachineCachedTokens(home = os.homedir(), env = process.env) {
32
+ const file = machineTokenCacheFile(home, env);
33
+ try {
34
+ if (!fs.existsSync(file))
35
+ return null;
36
+ const raw = JSON.parse(fs.readFileSync(file, "utf8"));
37
+ if (typeof raw.accessToken !== "string" ||
38
+ typeof raw.idToken !== "string" ||
39
+ raw.accessToken.length === 0 ||
40
+ raw.idToken.length === 0) {
41
+ return null;
42
+ }
43
+ return raw;
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ //# sourceMappingURL=machine-token-cache.js.map
@@ -64,6 +64,8 @@ export const RESIDENT_PACKAGE_MODULES = {
64
64
  "../utils/plan-gate-error.js", "../utils/deleted-company-notice.js",
65
65
  "../lib/daemon/mcp-oauth.js",
66
66
  "../commands/lanes.js",
67
+ "../utils/whoami-identity.js",
68
+ "../commands/whoami.js",
67
69
  "commander",
68
70
  "@modelcontextprotocol/sdk/client/index.js",
69
71
  "@modelcontextprotocol/sdk/client/streamableHttp.js",
@@ -271,6 +273,8 @@ const LOADERS = {
271
273
  () => import("../utils/deleted-company-notice.js"),
272
274
  () => import("../lib/daemon/mcp-oauth.js"),
273
275
  () => import("../commands/lanes.js"),
276
+ () => import("../utils/whoami-identity.js"),
277
+ () => import("../commands/whoami.js"),
274
278
  () => import("commander"),
275
279
  () => import("@modelcontextprotocol/sdk/client/index.js"),
276
280
  () => import("@modelcontextprotocol/sdk/client/streamableHttp.js"),
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The identity `hq whoami --json` prints, built from the local token caches.
3
+ *
4
+ * Shared by `hq whoami` itself and by the daemon's cached answer
5
+ * (src/lib/daemon/whoami-cache.ts), so both report the same fields the same
6
+ * way. Building it reads local files only; the one network lookup, the
7
+ * person's `prs_*` uid, is passed in by the caller.
8
+ */
9
+ import { loadCachedTokens } from '@indigoai-us/hq-cloud';
10
+ import { loadMachineCachedTokens } from './machine-token-cache.js';
11
+ export interface WhoamiTokenIdentity {
12
+ email?: string;
13
+ sub?: string;
14
+ delegatedEmail?: string;
15
+ delegatedSub?: string;
16
+ entityType?: string;
17
+ entityUid?: string;
18
+ }
19
+ export interface WhoamiDisplayIdentity {
20
+ email?: string;
21
+ sub?: string;
22
+ }
23
+ /** Every `hq whoami --json` field except `planLimits`. */
24
+ export interface WhoamiIdentity {
25
+ schemaVersion: 1;
26
+ authenticated: boolean;
27
+ tokenSource: 'machine' | 'person';
28
+ email: string | null;
29
+ sub: string | null;
30
+ delegatedEmail: string | null;
31
+ delegatedSub: string | null;
32
+ personUid: string | null;
33
+ agentUid: string | null;
34
+ username: string | null;
35
+ sessionExpiresAt: string | null;
36
+ sessionExpiring: boolean | null;
37
+ }
38
+ type CachedTokens = ReturnType<typeof loadCachedTokens>;
39
+ /**
40
+ * Resolves the person represented by an ID token without pairing a delegated
41
+ * email with the token subject of the delegating machine.
42
+ */
43
+ export declare function resolveWhoamiIdentity(identity: WhoamiTokenIdentity): WhoamiDisplayIdentity;
44
+ export declare function peekWhoamiTokenIdentity(idToken: string): WhoamiTokenIdentity;
45
+ /**
46
+ * The whoami identity for `machine` (the effective token source) and the
47
+ * cached person tokens. `readPersonUid` runs only for an authenticated person
48
+ * session; it is the caller's network lookup, or a cached value.
49
+ */
50
+ export declare function buildWhoamiIdentity(machine: boolean, cached: CachedTokens, readPersonUid: (identity: WhoamiTokenIdentity) => Promise<string | null> | string | null, readMachineTokens?: typeof loadMachineCachedTokens): Promise<WhoamiIdentity>;
51
+ /** The local part of the whoami identity: no network, `personUid` null. */
52
+ export declare function localWhoamiIdentity(env?: NodeJS.ProcessEnv): WhoamiIdentity;
53
+ export {};
54
+ //# sourceMappingURL=whoami-identity.d.ts.map
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The identity `hq whoami --json` prints, built from the local token caches.
3
+ *
4
+ * Shared by `hq whoami` itself and by the daemon's cached answer
5
+ * (src/lib/daemon/whoami-cache.ts), so both report the same fields the same
6
+ * way. Building it reads local files only; the one network lookup, the
7
+ * person's `prs_*` uid, is passed in by the caller.
8
+ */
9
+ import { isExpiring, loadCachedTokens, loadMachineCreds, } from '@indigoai-us/hq-cloud';
10
+ import { peekIdToken as decodeIdToken } from './id-token.js';
11
+ import { loadMachineCachedTokens } from './machine-token-cache.js';
12
+ import { wantsMachineCognitoTokens } from './machine-principal-state.js';
13
+ import { authExpiryIso } from './auth-expiry.js';
14
+ /**
15
+ * Resolves the person represented by an ID token without pairing a delegated
16
+ * email with the token subject of the delegating machine.
17
+ */
18
+ export function resolveWhoamiIdentity(identity) {
19
+ if (identity.email !== undefined && identity.sub !== undefined) {
20
+ return { email: identity.email, sub: identity.sub };
21
+ }
22
+ if (identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined) {
23
+ return { email: identity.delegatedEmail, sub: identity.delegatedSub };
24
+ }
25
+ if (identity.email !== undefined || identity.sub !== undefined) {
26
+ return { email: identity.email, sub: identity.sub };
27
+ }
28
+ return {};
29
+ }
30
+ export function peekWhoamiTokenIdentity(idToken) {
31
+ const decoded = decodeIdToken(idToken);
32
+ return {
33
+ email: typeof decoded.email === "string" ? decoded.email : undefined,
34
+ sub: typeof decoded.sub === "string" ? decoded.sub : undefined,
35
+ delegatedEmail: typeof decoded["custom:delegatedEmail"] === "string"
36
+ ? decoded["custom:delegatedEmail"]
37
+ : undefined,
38
+ delegatedSub: typeof decoded["custom:delegatedSub"] === "string"
39
+ ? decoded["custom:delegatedSub"]
40
+ : undefined,
41
+ entityType: typeof decoded["custom:entityType"] === "string"
42
+ ? decoded["custom:entityType"]
43
+ : undefined,
44
+ entityUid: typeof decoded["custom:entityUid"] === "string"
45
+ ? decoded["custom:entityUid"]
46
+ : undefined,
47
+ };
48
+ }
49
+ /**
50
+ * The whoami identity for `machine` (the effective token source) and the
51
+ * cached person tokens. `readPersonUid` runs only for an authenticated person
52
+ * session; it is the caller's network lookup, or a cached value.
53
+ */
54
+ export async function buildWhoamiIdentity(machine, cached, readPersonUid, readMachineTokens = loadMachineCachedTokens) {
55
+ const base = whoamiIdentityWithoutPersonUid(machine, cached, readMachineTokens);
56
+ const personUid = !machine && base.authenticated ? await readPersonUid(base.token) : null;
57
+ return { ...base.identity, personUid };
58
+ }
59
+ /** The local part of the whoami identity: no network, `personUid` null. */
60
+ export function localWhoamiIdentity(env = process.env) {
61
+ // Same rule as cognito-session.ts resolveCognitoTokenSource, without its network code.
62
+ const machine = wantsMachineCognitoTokens({}, env);
63
+ return whoamiIdentityWithoutPersonUid(machine, loadCachedTokens()).identity;
64
+ }
65
+ function whoamiIdentityWithoutPersonUid(machine, cached, readMachineTokens = loadMachineCachedTokens) {
66
+ const machineCreds = machine ? loadMachineCreds() : null;
67
+ const identityCache = machine ? readMachineTokens() : cached;
68
+ const identity = identityCache ? peekWhoamiTokenIdentity(identityCache.idToken) : {};
69
+ const displayedIdentity = resolveWhoamiIdentity(identity);
70
+ const claims = identityCache ? decodeIdToken(identityCache.idToken) : {};
71
+ // Modern credentials carry the canonical UID. Legacy caches may only
72
+ // supply a UID when their subject is bound to the selected username.
73
+ const boundLegacyAgent = machineCreds && identity.entityType === 'agent'
74
+ && (claims['cognito:username'] === machineCreds.username
75
+ || claims.username === machineCreds.username || claims.sub === machineCreds.username)
76
+ ? identity.entityUid ?? null : null;
77
+ const agentUid = machineCreds?.entityUid !== undefined
78
+ ? (machineCreds.entityUid.startsWith('agt_') ? machineCreds.entityUid : null)
79
+ : boundLegacyAgent;
80
+ const authenticated = machine ? Boolean(machineCreds) : Boolean(cached && !isExpiring(cached, 0));
81
+ const delegated = identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined;
82
+ return {
83
+ token: identity,
84
+ authenticated,
85
+ identity: {
86
+ schemaVersion: 1,
87
+ authenticated,
88
+ tokenSource: machine ? 'machine' : 'person',
89
+ email: machine ? null : displayedIdentity.email ?? null,
90
+ // Cognito subject of the person shown in `email` (null for machine
91
+ // identities). Outpost jobs record owners by this id.
92
+ sub: machine ? null : displayedIdentity.sub ?? null,
93
+ // The human an Outpost session acts for, from the token's
94
+ // delegated claims, for machine and person sources alike.
95
+ delegatedEmail: delegated ? identity.delegatedEmail : null,
96
+ delegatedSub: delegated ? identity.delegatedSub : null,
97
+ personUid: null,
98
+ agentUid,
99
+ username: machineCreds?.username ?? null,
100
+ // Additive (what `hq auth status` reported): when the cached
101
+ // session expires, and whether it is inside the refresh window.
102
+ // Both are null when no session is cached.
103
+ sessionExpiresAt: identityCache ? authExpiryIso(identityCache.expiresAt) : null,
104
+ sessionExpiring: identityCache ? isExpiring(identityCache) : null,
105
+ },
106
+ };
107
+ }
108
+ //# sourceMappingURL=whoami-identity.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.223",
3
+ "version": "5.345.226",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -62,7 +62,7 @@
62
62
  "@aws-sdk/client-iot-data-plane": "^3.1096.0",
63
63
  "@aws-sdk/client-s3": "^3.1049.0",
64
64
  "@aws-sdk/dsql-signer": "^3.1146.0",
65
- "@indigoai-us/hq-cloud": "6.18.109",
65
+ "@indigoai-us/hq-cloud": "6.18.110",
66
66
  "@indigoai-us/hq-flags-client": "^0.2.0",
67
67
  "@modelcontextprotocol/sdk": "1.32.2",
68
68
  "@sentry/node": "^10.49.0",
@@ -124,11 +124,11 @@
124
124
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
125
125
  },
126
126
  "optionalDependencies": {
127
- "@indigoai-us/hq-hook-win32-x64": "5.345.223",
128
- "@indigoai-us/hq-hook-win32-arm64": "5.345.223",
129
- "@indigoai-us/hq-hook-darwin-x64": "5.345.223",
130
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.223",
131
- "@indigoai-us/hq-hook-linux-x64": "5.345.223",
132
- "@indigoai-us/hq-hook-linux-arm64": "5.345.223"
127
+ "@indigoai-us/hq-hook-win32-x64": "5.345.226",
128
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.226",
129
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.226",
130
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.226",
131
+ "@indigoai-us/hq-hook-linux-x64": "5.345.226",
132
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.226"
133
133
  }
134
134
  }
@@ -1,18 +0,0 @@
1
- /**
2
- * memory.get / memory.put ops (hq-anywhere US-009): session-scoped notes
3
- * persisted at workspace/sessions/<sid>/hqd-memory.json under HQ_ROOT.
4
- */
5
- export declare class MemoryOpError extends Error {
6
- readonly code: string;
7
- constructor(code: string, message: string);
8
- }
9
- export declare function memoryPut(hqRoot: string, sessionId: string, key: string, value: unknown, now?: Date): {
10
- key: string;
11
- updatedAt: string;
12
- };
13
- export declare function memoryGet(hqRoot: string, sessionId: string, key?: string): {
14
- value: unknown;
15
- } | {
16
- entries: Record<string, unknown>;
17
- };
18
- //# sourceMappingURL=memory.d.ts.map
@@ -1,65 +0,0 @@
1
- /**
2
- * memory.get / memory.put ops (hq-anywhere US-009): session-scoped notes
3
- * persisted at workspace/sessions/<sid>/hqd-memory.json under HQ_ROOT.
4
- */
5
- import * as fs from "node:fs";
6
- import * as path from "node:path";
7
- const SESSION_RE = /^[A-Za-z0-9._-]+$/;
8
- const MEMORY_FILE = "hqd-memory.json";
9
- const MAX_VALUE_BYTES = 256 * 1024;
10
- export class MemoryOpError extends Error {
11
- code;
12
- constructor(code, message) {
13
- super(message);
14
- this.code = code;
15
- this.name = "MemoryOpError";
16
- }
17
- }
18
- function memoryPath(hqRoot, sessionId) {
19
- if (!SESSION_RE.test(sessionId) || sessionId === "." || sessionId === "..") {
20
- throw new MemoryOpError("bad_args", "sessionId may only contain letters, digits, '.', '_' and '-'");
21
- }
22
- return path.join(hqRoot, "workspace", "sessions", sessionId, MEMORY_FILE);
23
- }
24
- function readAll(file) {
25
- let raw;
26
- try {
27
- raw = fs.readFileSync(file, "utf8");
28
- }
29
- catch (err) {
30
- if (err.code === "ENOENT")
31
- return {};
32
- throw err;
33
- }
34
- const parsed = JSON.parse(raw);
35
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
36
- throw new MemoryOpError("corrupt_memory", `${file} is not a JSON object`);
37
- }
38
- return parsed;
39
- }
40
- export function memoryPut(hqRoot, sessionId, key, value, now = new Date()) {
41
- if (!key.trim())
42
- throw new MemoryOpError("bad_args", "key must be non-empty");
43
- const serialized = JSON.stringify(value ?? null);
44
- if (Buffer.byteLength(serialized, "utf8") > MAX_VALUE_BYTES)
45
- throw new MemoryOpError("too_large", `value is over ${MAX_VALUE_BYTES} bytes`);
46
- const file = memoryPath(hqRoot, sessionId);
47
- const all = readAll(file);
48
- const updatedAt = now.toISOString();
49
- if (value === null || value === undefined)
50
- delete all[key];
51
- else
52
- all[key] = { value, updatedAt };
53
- fs.mkdirSync(path.dirname(file), { recursive: true });
54
- const tmp = `${file}.${process.pid}.tmp`;
55
- fs.writeFileSync(tmp, `${JSON.stringify(all, null, 2)}\n`, { mode: 0o600 });
56
- fs.renameSync(tmp, file);
57
- return { key, updatedAt };
58
- }
59
- export function memoryGet(hqRoot, sessionId, key) {
60
- const all = readAll(memoryPath(hqRoot, sessionId));
61
- if (key !== undefined)
62
- return { value: all[key]?.value ?? null };
63
- return { entries: Object.fromEntries(Object.entries(all).map(([k, e]) => [k, e.value])) };
64
- }
65
- //# sourceMappingURL=memory.js.map
@@ -1,38 +0,0 @@
1
- /**
2
- * mesh.presence op (hq-anywhere US-009).
3
- *
4
- * Writes one schema-valid session event to the Work Mesh Live spool through
5
- * the same enqueue path as `hq mesh session … --enqueue`. The daemon's mesh
6
- * drainer service already flushes that spool, so presence from a session in a
7
- * foreign cwd reaches Work Mesh Live without any new transport.
8
- */
9
- export declare class MeshOpError extends Error {
10
- readonly code: string;
11
- constructor(code: string, message: string);
12
- }
13
- export interface MeshPresenceArgs {
14
- sessionId: string;
15
- harness: string;
16
- kind: string;
17
- cwd?: string;
18
- company?: string;
19
- project?: string;
20
- task?: string;
21
- taskId?: string;
22
- status?: string;
23
- summary?: string;
24
- reason?: string;
25
- }
26
- export interface MeshPresenceDeps {
27
- hqRoot?: string;
28
- /** Work-mesh root override (tests); defaults to ~/.hq/work-mesh or HQ_WORK_MESH_ROOT. */
29
- workMeshRoot?: string;
30
- env?: NodeJS.ProcessEnv;
31
- now?: () => Date;
32
- }
33
- export declare function meshPresence(args: MeshPresenceArgs, deps?: MeshPresenceDeps): {
34
- eventId: string;
35
- seq: number;
36
- spoolPath: string;
37
- };
38
- //# sourceMappingURL=mesh.d.ts.map
@@ -1,70 +0,0 @@
1
- /**
2
- * mesh.presence op (hq-anywhere US-009).
3
- *
4
- * Writes one schema-valid session event to the Work Mesh Live spool through
5
- * the same enqueue path as `hq mesh session … --enqueue`. The daemon's mesh
6
- * drainer service already flushes that spool, so presence from a session in a
7
- * foreign cwd reaches Work Mesh Live without any new transport.
8
- */
9
- import { CLI_VERSION } from "../../../cli-version.js";
10
- import { CLI_KIND_TO_SCHEMA, EnqueueValidationError, enqueueSessionEvent } from "../../mesh/live/enqueue.js";
11
- import { reserveSessionSeq } from "../../mesh/live/session-seq.js";
12
- const HARNESSES = ["claude-code", "claude-desktop", "codex", "grok", "hq-sessions", "agent-box", "agents-v2"];
13
- const SCHEMA_KINDS = new Set(Object.values(CLI_KIND_TO_SCHEMA));
14
- const STATUSES = new Set(["queued", "in_progress", "review", "done"]);
15
- export class MeshOpError extends Error {
16
- code;
17
- constructor(code, message) {
18
- super(message);
19
- this.code = code;
20
- this.name = "MeshOpError";
21
- }
22
- }
23
- export function meshPresence(args, deps = {}) {
24
- const env = deps.env ?? process.env;
25
- if (!HARNESSES.includes(args.harness)) {
26
- throw new MeshOpError("bad_args", `harness must be one of ${HARNESSES.join(", ")}`);
27
- }
28
- const kind = (CLI_KIND_TO_SCHEMA[args.kind] ?? (SCHEMA_KINDS.has(args.kind) ? args.kind : undefined));
29
- if (!kind)
30
- throw new MeshOpError("bad_args", `kind must be one of ${Object.keys(CLI_KIND_TO_SCHEMA).join(", ")}`);
31
- if (args.status !== undefined && !STATUSES.has(args.status))
32
- throw new MeshOpError("bad_args", "status must be queued, in_progress, review or done");
33
- let seq;
34
- try {
35
- seq = reserveSessionSeq(args.sessionId, 1, env);
36
- }
37
- catch (err) {
38
- throw new MeshOpError("bad_args", `sessionId rejected: ${err.message}`);
39
- }
40
- let result;
41
- try {
42
- result = enqueueSessionEvent({
43
- kind,
44
- sessionId: args.sessionId,
45
- harness: args.harness,
46
- adapterVersion: CLI_VERSION,
47
- source: "hooks",
48
- seq,
49
- cwd: args.cwd,
50
- hqRoot: deps.hqRoot,
51
- companySlug: args.company,
52
- project: args.project,
53
- task: args.task,
54
- taskId: args.taskId,
55
- status: args.status,
56
- summary: args.summary,
57
- reason: args.reason,
58
- root: deps.workMeshRoot,
59
- env,
60
- now: deps.now,
61
- });
62
- }
63
- catch (err) {
64
- if (err instanceof EnqueueValidationError)
65
- throw new MeshOpError("bad_args", err.message);
66
- throw err;
67
- }
68
- return { eventId: result.event.eventId, seq, spoolPath: result.spoolPath };
69
- }
70
- //# sourceMappingURL=mesh.js.map