@indigoai-us/hq-cli 5.345.223 → 5.345.225

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 (96) hide show
  1. package/CHANGELOG.md +66 -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 +78 -4
  5. package/dist/command-catalog.generated.js +94 -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 +67 -1
  24. package/dist/commands/lanes-hold.d.ts +2 -27
  25. package/dist/commands/lanes-hold.js +3 -75
  26. package/dist/commands/lanes-loop.js +1 -1
  27. package/dist/commands/lanes-session-start.js +2 -2
  28. package/dist/commands/mesh.d.ts +12 -0
  29. package/dist/commands/mesh.js +13 -4
  30. package/dist/commands/monitor.js +1 -1
  31. package/dist/commands/packs.js +1 -1
  32. package/dist/commands/whoami.d.ts +10 -17
  33. package/dist/commands/whoami.js +7 -79
  34. package/dist/data/command-states.json +13 -0
  35. package/dist/index.js +1 -1
  36. package/dist/lib/daemon/catalog.d.ts +8 -5
  37. package/dist/lib/daemon/catalog.js +13 -7
  38. package/dist/lib/daemon/config.d.ts +5 -0
  39. package/dist/lib/daemon/config.js +6 -0
  40. package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
  41. package/dist/lib/daemon/lanes-monitor-state.js +129 -0
  42. package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
  43. package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
  44. package/dist/lib/daemon/merge-sections.d.ts +165 -0
  45. package/dist/lib/daemon/merge-sections.js +556 -0
  46. package/dist/lib/daemon/ops/policy.d.ts +1 -1
  47. package/dist/lib/daemon/ops/policy.js +1 -1
  48. package/dist/lib/daemon/protocol.d.ts +1 -1
  49. package/dist/lib/daemon/protocol.js +0 -6
  50. package/dist/lib/daemon/run.js +73 -1
  51. package/dist/lib/daemon/selfcheck.js +2 -2
  52. package/dist/lib/daemon/server.d.ts +2 -4
  53. package/dist/lib/daemon/server.js +5 -48
  54. package/dist/lib/daemon/state-file.d.ts +74 -4
  55. package/dist/lib/daemon/state-file.js +159 -19
  56. package/dist/lib/daemon/supervisor.d.ts +1 -1
  57. package/dist/lib/daemon/updater.d.ts +2 -6
  58. package/dist/lib/daemon/updater.js +4 -11
  59. package/dist/lib/daemon/whoami-cache.d.ts +96 -0
  60. package/dist/lib/daemon/whoami-cache.js +244 -0
  61. package/dist/lib/hook-engine/coverage.d.ts +2 -0
  62. package/dist/lib/hook-engine/coverage.js +71 -0
  63. package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
  64. package/dist/lib/hook-engine/reconcile.js +14 -8
  65. package/dist/lib/install/hook-target.d.ts +13 -3
  66. package/dist/lib/install/hook-target.js +14 -11
  67. package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
  68. package/dist/lib/lanes/monitor.d.ts +2 -0
  69. package/dist/lib/lanes/monitor.js +2 -1
  70. package/dist/lib/lanes/registry-flag.d.ts +6 -0
  71. package/dist/lib/lanes/registry-flag.js +3 -2
  72. package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
  73. package/dist/lib/lanes/repo-merge-hold.js +90 -0
  74. package/dist/lib/lanes/watcher-main.js +3 -3
  75. package/dist/lib/mesh/live/daemon/doctor.js +1 -1
  76. package/dist/lib/mesh/live/daemon/install.js +2 -2
  77. package/dist/lib/windows/install-followup.js +1 -1
  78. package/dist/utils/client-health-contract.d.ts +1 -0
  79. package/dist/utils/client-health-contract.js +5 -0
  80. package/dist/utils/client-health.d.ts +2 -0
  81. package/dist/utils/client-health.js +40 -0
  82. package/dist/utils/cognito-session.d.ts +2 -14
  83. package/dist/utils/cognito-session.js +2 -40
  84. package/dist/utils/daemon-cli-version.d.ts +13 -0
  85. package/dist/utils/daemon-cli-version.js +47 -0
  86. package/dist/utils/duplicate-command-usage.js +1 -1
  87. package/dist/utils/machine-token-cache.d.ts +21 -0
  88. package/dist/utils/machine-token-cache.js +49 -0
  89. package/dist/utils/resident-package-preload.js +4 -0
  90. package/dist/utils/whoami-identity.d.ts +54 -0
  91. package/dist/utils/whoami-identity.js +108 -0
  92. package/package.json +7 -7
  93. package/dist/lib/daemon/ops/memory.d.ts +0 -18
  94. package/dist/lib/daemon/ops/memory.js +0 -65
  95. package/dist/lib/daemon/ops/mesh.d.ts +0 -38
  96. package/dist/lib/daemon/ops/mesh.js +0 -70
@@ -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.225",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -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.225",
128
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.225",
129
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.225",
130
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.225",
131
+ "@indigoai-us/hq-hook-linux-x64": "5.345.225",
132
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.225"
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