@indigoai-us/hq-cli 5.345.222 → 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 (128) hide show
  1. package/CHANGELOG.md +89 -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 +79 -5
  5. package/dist/command-catalog.generated.js +95 -5
  6. package/dist/commands/bot.d.ts +1 -1
  7. package/dist/commands/bot.js +34 -33
  8. package/dist/commands/cloud-provision.d.ts +4 -1
  9. package/dist/commands/cloud-provision.js +7 -3
  10. package/dist/commands/cloud-retire.js +1 -1
  11. package/dist/commands/core-delegate-w1b.js +210 -188
  12. package/dist/commands/core-delegate.d.ts +5 -0
  13. package/dist/commands/core-dm-bind-native.d.ts +5 -1
  14. package/dist/commands/core-dm-bind-native.js +4 -0
  15. package/dist/commands/core-job-notify-native.d.ts +5 -1
  16. package/dist/commands/core-job-notify-native.js +8 -2
  17. package/dist/commands/core-jobs-native.d.ts +27 -1
  18. package/dist/commands/core-jobs-native.js +49 -28
  19. package/dist/commands/core-pipeline-conductor-native.js +7 -7
  20. package/dist/commands/core-pipeline-driver-native.js +5 -5
  21. package/dist/commands/core-refresh-vault-access-native.d.ts +5 -0
  22. package/dist/commands/core-refresh-vault-access-native.js +3 -1
  23. package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
  24. package/dist/commands/daemon.d.ts +2 -0
  25. package/dist/commands/daemon.js +67 -1
  26. package/dist/commands/lanes-hold.d.ts +2 -27
  27. package/dist/commands/lanes-hold.js +3 -75
  28. package/dist/commands/lanes-loop.js +1 -1
  29. package/dist/commands/lanes-session-start.js +2 -2
  30. package/dist/commands/mesh.d.ts +12 -0
  31. package/dist/commands/mesh.js +13 -4
  32. package/dist/commands/monitor.js +1 -1
  33. package/dist/commands/packs.js +14 -3
  34. package/dist/commands/sync-core.js +31 -12
  35. package/dist/commands/whoami.d.ts +10 -17
  36. package/dist/commands/whoami.js +7 -79
  37. package/dist/data/command-states.json +13 -0
  38. package/dist/index.js +1 -1
  39. package/dist/lib/bot/fleet-cron.d.ts +26 -3
  40. package/dist/lib/bot/fleet-cron.js +44 -4
  41. package/dist/lib/bot/run.d.ts +4 -4
  42. package/dist/lib/bot/run.js +5 -3
  43. package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
  44. package/dist/lib/bot/signals-engine-flag.js +202 -9
  45. package/dist/lib/daemon/catalog.d.ts +8 -5
  46. package/dist/lib/daemon/catalog.js +13 -7
  47. package/dist/lib/daemon/config.d.ts +5 -0
  48. package/dist/lib/daemon/config.js +6 -0
  49. package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
  50. package/dist/lib/daemon/lanes-monitor-state.js +129 -0
  51. package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
  52. package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
  53. package/dist/lib/daemon/machine-checks.d.ts +45 -0
  54. package/dist/lib/daemon/machine-checks.js +95 -11
  55. package/dist/lib/daemon/merge-sections.d.ts +165 -0
  56. package/dist/lib/daemon/merge-sections.js +556 -0
  57. package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
  58. package/dist/lib/daemon/native-notice-ledger.js +43 -0
  59. package/dist/lib/daemon/ops/policy.d.ts +1 -1
  60. package/dist/lib/daemon/ops/policy.js +1 -1
  61. package/dist/lib/daemon/protocol.d.ts +1 -1
  62. package/dist/lib/daemon/protocol.js +0 -6
  63. package/dist/lib/daemon/run.js +76 -3
  64. package/dist/lib/daemon/selfcheck.js +2 -2
  65. package/dist/lib/daemon/server.d.ts +2 -4
  66. package/dist/lib/daemon/server.js +5 -48
  67. package/dist/lib/daemon/state-file.d.ts +74 -4
  68. package/dist/lib/daemon/state-file.js +159 -19
  69. package/dist/lib/daemon/supervisor.d.ts +11 -1
  70. package/dist/lib/daemon/supervisor.js +86 -0
  71. package/dist/lib/daemon/updater.d.ts +2 -6
  72. package/dist/lib/daemon/updater.js +4 -11
  73. package/dist/lib/daemon/whoami-cache.d.ts +96 -0
  74. package/dist/lib/daemon/whoami-cache.js +244 -0
  75. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  76. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  77. package/dist/lib/flag-registry-worker.js +33 -3
  78. package/dist/lib/flag-registry.js +13 -0
  79. package/dist/lib/hook-engine/coverage.d.ts +2 -0
  80. package/dist/lib/hook-engine/coverage.js +71 -0
  81. package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
  82. package/dist/lib/hook-engine/reconcile.js +14 -8
  83. package/dist/lib/install/hook-target.d.ts +13 -3
  84. package/dist/lib/install/hook-target.js +14 -11
  85. package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
  86. package/dist/lib/lanes/monitor.d.ts +2 -0
  87. package/dist/lib/lanes/monitor.js +2 -1
  88. package/dist/lib/lanes/registry-flag.d.ts +6 -0
  89. package/dist/lib/lanes/registry-flag.js +3 -2
  90. package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
  91. package/dist/lib/lanes/repo-merge-hold.js +90 -0
  92. package/dist/lib/lanes/watcher-main.js +3 -3
  93. package/dist/lib/mesh/live/daemon/doctor.js +1 -1
  94. package/dist/lib/mesh/live/daemon/install.js +2 -2
  95. package/dist/lib/scan-packages/index.js +8 -9
  96. package/dist/lib/signals/engine.d.ts +8 -0
  97. package/dist/lib/signals/engine.js +15 -5
  98. package/dist/lib/sync-core/flag.d.ts +18 -0
  99. package/dist/lib/sync-core/flag.js +66 -0
  100. package/dist/lib/sync-core/reconcile.d.ts +6 -0
  101. package/dist/lib/sync-core/reconcile.js +15 -0
  102. package/dist/lib/sync-core/rollout-state.d.ts +2 -0
  103. package/dist/lib/sync-core/rollout-state.js +7 -0
  104. package/dist/lib/sync-core/vault-settings.d.ts +12 -1
  105. package/dist/lib/sync-core/vault-settings.js +23 -7
  106. package/dist/lib/windows/install-followup.js +1 -1
  107. package/dist/utils/client-health-contract.d.ts +1 -0
  108. package/dist/utils/client-health-contract.js +5 -0
  109. package/dist/utils/client-health.d.ts +2 -0
  110. package/dist/utils/client-health.js +40 -0
  111. package/dist/utils/cognito-session.d.ts +2 -14
  112. package/dist/utils/cognito-session.js +2 -40
  113. package/dist/utils/daemon-cli-version.d.ts +13 -0
  114. package/dist/utils/daemon-cli-version.js +47 -0
  115. package/dist/utils/duplicate-command-usage.js +1 -1
  116. package/dist/utils/machine-token-cache.d.ts +21 -0
  117. package/dist/utils/machine-token-cache.js +49 -0
  118. package/dist/utils/pack-contributions.d.ts +14 -2
  119. package/dist/utils/pack-contributions.js +31 -5
  120. package/dist/utils/resident-package-preload.js +4 -0
  121. package/dist/utils/whoami-identity.d.ts +54 -0
  122. package/dist/utils/whoami-identity.js +108 -0
  123. package/package.json +7 -7
  124. package/scripts/bench-core.mjs +34 -3
  125. package/dist/lib/daemon/ops/memory.d.ts +0 -18
  126. package/dist/lib/daemon/ops/memory.js +0 -65
  127. package/dist/lib/daemon/ops/mesh.d.ts +0 -38
  128. package/dist/lib/daemon/ops/mesh.js +0 -70
@@ -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.222",
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.222",
128
- "@indigoai-us/hq-hook-win32-arm64": "5.345.222",
129
- "@indigoai-us/hq-hook-darwin-x64": "5.345.222",
130
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.222",
131
- "@indigoai-us/hq-hook-linux-x64": "5.345.222",
132
- "@indigoai-us/hq-hook-linux-arm64": "5.345.222"
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
  }
@@ -39,7 +39,9 @@
39
39
  // (master-hook.sh or the host's adapter script).
40
40
  // A bot host's adapter is not in this
41
41
  // repository: give it with --core-cmd old=...
42
- // new hq-hook run --host <host> <Event>; a bot host
42
+ // new hq-hook run --host <host> <Event>
43
+ // --hq-root <root>, as host registration
44
+ // writes it; a bot host
43
45
  // gets its own event name (pre_tool_call,
44
46
  // post_tool_call, pre_llm_call)
45
47
  // selected whatever the host's registration under
@@ -849,6 +851,34 @@ function botSelected({ host, event, options, rootEnv }) {
849
851
  return { steps, detected: describeCore(steps.map((step) => step.named)), profile: candidates[0].profile.file };
850
852
  }
851
853
 
854
+ // The spelling of a script path that Git Bash can run and resolve its own
855
+ // folder from: on Windows, forward slashes and /c/... for a drive path (the
856
+ // same conversion src/utils/run-bundled-script.ts uses). master-hook.sh finds
857
+ // its sibling scripts from BASH_SOURCE, and a backslash path makes that the
858
+ // working directory instead. Other platforms get the path unchanged.
859
+ export function bashScriptPath(value, platform = process.platform) {
860
+ if (platform !== "win32") return value;
861
+ const normalized = value.replaceAll("\\", "/");
862
+ const drive = /^([A-Za-z]):\/(.*)$/u.exec(normalized);
863
+ return drive ? `/${drive[1].toLowerCase()}/${drive[2]}` : normalized;
864
+ }
865
+
866
+ // The HQ root as a host registration writes it after --hq-root: trailing
867
+ // separators removed, except for a bare drive or the filesystem root (the
868
+ // same rule as launcherRoot in src/lib/hook-engine/registration-identity.ts).
869
+ export function registrationRoot(root) {
870
+ const trimmed = root.replace(/[\\/]+$/u, "");
871
+ return trimmed === "" || /^[A-Za-z]:$/u.test(trimmed) ? root : trimmed;
872
+ }
873
+
874
+ // Arguments for --core new: what host registration writes for a project
875
+ // entry, `run --host <host> <Event> --hq-root <root>`. The root is given
876
+ // explicitly, as registration does on every platform, so the engine does not
877
+ // fall back to CLAUDE_PROJECT_DIR (which it does not read on Windows).
878
+ export function newCoreArgs(host, word, root) {
879
+ return ["run", "--host", host, word, "--hq-root", registrationRoot(root)];
880
+ }
881
+
852
882
  function defaultBash(platform) {
853
883
  if (platform !== "win32") return "bash";
854
884
  for (const base of [process.env.ProgramFiles, process.env["ProgramFiles(x86)"], process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, "Programs")]) {
@@ -880,14 +910,15 @@ export function resolveInvocation({ host, core, event, tool, options, platform =
880
910
  }
881
911
 
882
912
  if (core === "new") {
883
- const args = ["run", "--host", host, word];
913
+ const args = newCoreArgs(host, word, root);
884
914
  return { steps: [{ file: options.hqHook, args, env: rootEnv, cwd: root, display: `${options.hqHook} ${args.join(" ")}` }], detected: "new" };
885
915
  }
886
916
 
887
917
  if (core === "old") {
888
918
  const script = path.join(root, ...OLD_ENTRY[host]);
889
919
  if (!fs.existsSync(script)) return { steps: [], detected: "old", missing: `the old core is not under --root (${script} is missing)` };
890
- const args = host === "claude" ? [script, event] : [script];
920
+ const scriptArg = bashScriptPath(script, platform);
921
+ const args = host === "claude" ? [scriptArg, event] : [scriptArg];
891
922
  const env = { ...rootEnv, BASH_ENV: os.devNull };
892
923
  if (host === "grok") Object.assign(env, { GROK_WORKSPACE_ROOT: root, GROK_HOOK_EVENT: event });
893
924
  return { steps: [{ file: bash, args, env, cwd: root, display: `bash ${args.join(" ")}` }], detected: "old" };
@@ -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