@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
@@ -628,7 +628,7 @@ export const COMMAND_CATALOG = [
628
628
  },
629
629
  {
630
630
  "flags": "--registry",
631
- "description": "Update installed registry packages instead (same as `hq packages update [slug]`; [name] is the package slug)",
631
+ "description": "Update installed registry packages instead of content packs ([name] is the package slug)",
632
632
  "hidden": false
633
633
  }
634
634
  ],
@@ -799,7 +799,7 @@ export const COMMAND_CATALOG = [
799
799
  },
800
800
  {
801
801
  "flags": "--registry",
802
- "description": "Update installed registry packages instead (same as `hq packages update [slug]`; [name] is the package slug)",
802
+ "description": "Update installed registry packages instead of content packs ([name] is the package slug)",
803
803
  "hidden": false
804
804
  }
805
805
  ],
@@ -1498,6 +1498,11 @@ export const COMMAND_CATALOG = [
1498
1498
  "description": "Do not ask for confirmation",
1499
1499
  "hidden": false
1500
1500
  },
1501
+ {
1502
+ "flags": "--confirm-unproven",
1503
+ "description": "Restore an unreadable identity file and keep every upload held until you confirm which files are yours",
1504
+ "hidden": false
1505
+ },
1501
1506
  {
1502
1507
  "flags": "--json",
1503
1508
  "description": "Print the result as JSON",
@@ -1772,7 +1777,7 @@ export const COMMAND_CATALOG = [
1772
1777
  },
1773
1778
  {
1774
1779
  "flags": "--check",
1775
- "description": "Exit 1 when there is no usable session, like `hq auth status`",
1780
+ "description": "Exit 1 when there is no usable session, so a script can test the exit status",
1776
1781
  "hidden": false
1777
1782
  }
1778
1783
  ],
@@ -11000,6 +11005,16 @@ export const COMMAND_CATALOG = [
11000
11005
  "description": "Outpost id (defaults to your primary box)",
11001
11006
  "hidden": false
11002
11007
  },
11008
+ {
11009
+ "flags": "--company <slug>",
11010
+ "description": "Run on this company's Outpost (company owners and admins)",
11011
+ "hidden": false
11012
+ },
11013
+ {
11014
+ "flags": "--outpost <name|id>",
11015
+ "description": "Which company Outpost, when the company has more than one",
11016
+ "hidden": false
11017
+ },
11003
11018
  {
11004
11019
  "flags": "--root",
11005
11020
  "description": "Run the command as root (default: ec2-user)",
@@ -11054,6 +11069,16 @@ export const COMMAND_CATALOG = [
11054
11069
  "description": "Outpost id (defaults to your primary box)",
11055
11070
  "hidden": false
11056
11071
  },
11072
+ {
11073
+ "flags": "--company <slug>",
11074
+ "description": "Run on this company's Outpost (company owners and admins)",
11075
+ "hidden": false
11076
+ },
11077
+ {
11078
+ "flags": "--outpost <name|id>",
11079
+ "description": "Which company Outpost, when the company has more than one",
11080
+ "hidden": false
11081
+ },
11057
11082
  {
11058
11083
  "flags": "--json",
11059
11084
  "description": "Emit raw JSON",
@@ -11085,6 +11110,16 @@ export const COMMAND_CATALOG = [
11085
11110
  "description": "Outpost id (defaults to your primary box)",
11086
11111
  "hidden": false
11087
11112
  },
11113
+ {
11114
+ "flags": "--company <slug>",
11115
+ "description": "Run on this company's Outpost (company owners and admins)",
11116
+ "hidden": false
11117
+ },
11118
+ {
11119
+ "flags": "--outpost <name|id>",
11120
+ "description": "Which company Outpost, when the company has more than one",
11121
+ "hidden": false
11122
+ },
11088
11123
  {
11089
11124
  "flags": "--root",
11090
11125
  "description": "Run the command as root (default: ec2-user)",
@@ -11124,6 +11159,16 @@ export const COMMAND_CATALOG = [
11124
11159
  "description": "Outpost id (defaults to your primary box)",
11125
11160
  "hidden": false
11126
11161
  },
11162
+ {
11163
+ "flags": "--company <slug>",
11164
+ "description": "Run on this company's Outpost (company owners and admins)",
11165
+ "hidden": false
11166
+ },
11167
+ {
11168
+ "flags": "--outpost <name|id>",
11169
+ "description": "Which company Outpost, when the company has more than one",
11170
+ "hidden": false
11171
+ },
11127
11172
  {
11128
11173
  "flags": "--wait",
11129
11174
  "description": "Poll until the command reaches a terminal state",
@@ -11196,6 +11241,16 @@ export const COMMAND_CATALOG = [
11196
11241
  "description": "Outpost id (defaults to your primary box)",
11197
11242
  "hidden": false
11198
11243
  },
11244
+ {
11245
+ "flags": "--company <slug>",
11246
+ "description": "Run on this company's Outpost (company owners and admins)",
11247
+ "hidden": false
11248
+ },
11249
+ {
11250
+ "flags": "--outpost <name|id>",
11251
+ "description": "Which company Outpost, when the company has more than one",
11252
+ "hidden": false
11253
+ },
11199
11254
  {
11200
11255
  "flags": "--forward <port>",
11201
11256
  "description": "Forward this port on the box to your machine instead of opening a shell",
@@ -22401,6 +22456,48 @@ export const COMMAND_CATALOG = [
22401
22456
  ],
22402
22457
  "subcommands": []
22403
22458
  },
22459
+ {
22460
+ "name": "set-owner",
22461
+ "description": "Record which business owns a login and who holds it (labels only; no credential moves)",
22462
+ "aliases": [],
22463
+ "hidden": false,
22464
+ "helpOption": true,
22465
+ "helpCommand": false,
22466
+ "usage": "[options] <provider> <account-id>",
22467
+ "helpText": [],
22468
+ "arguments": [
22469
+ {
22470
+ "name": "provider",
22471
+ "required": true,
22472
+ "variadic": false,
22473
+ "description": "claude | codex | grok"
22474
+ },
22475
+ {
22476
+ "name": "account-id",
22477
+ "required": true,
22478
+ "variadic": false,
22479
+ "description": "Existing account id"
22480
+ }
22481
+ ],
22482
+ "options": [
22483
+ {
22484
+ "flags": "--owning-company <slug>",
22485
+ "description": "Company slug, personal, or unknown",
22486
+ "hidden": false
22487
+ },
22488
+ {
22489
+ "flags": "--holder <name>",
22490
+ "description": "owner, or the name of the person who holds the login",
22491
+ "hidden": false
22492
+ },
22493
+ {
22494
+ "flags": "--json",
22495
+ "description": "JSON on stdout (always)",
22496
+ "hidden": false
22497
+ }
22498
+ ],
22499
+ "subcommands": []
22500
+ },
22404
22501
  {
22405
22502
  "name": "login",
22406
22503
  "description": "Create a home, run the vendor login, and register the account",
@@ -23188,7 +23285,7 @@ export const COMMAND_CATALOG = [
23188
23285
  },
23189
23286
  {
23190
23287
  "name": "call",
23191
- "description": "Send one request to hqd (policy.check, journal.append, memory.get, memory.put, mesh.presence, mcp.call, …) and print the result as JSON",
23288
+ "description": "Send one request to hqd (policy.check, journal.append, mcp.call, …) and print the result as JSON",
23192
23289
  "aliases": [],
23193
23290
  "hidden": false,
23194
23291
  "helpOption": true,
@@ -23237,6 +23334,25 @@ export const COMMAND_CATALOG = [
23237
23334
  ],
23238
23335
  "subcommands": []
23239
23336
  },
23337
+ {
23338
+ "name": "doctor",
23339
+ "description": "Report Work Mesh health: running, MQTT, spool, held, dead-letter, outbox and flush (replaces the separate mesh daemon doctor)",
23340
+ "aliases": [],
23341
+ "hidden": false,
23342
+ "helpOption": true,
23343
+ "helpCommand": false,
23344
+ "usage": "[options]",
23345
+ "helpText": [],
23346
+ "arguments": [],
23347
+ "options": [
23348
+ {
23349
+ "flags": "--json",
23350
+ "description": "Print machine-readable JSON",
23351
+ "hidden": false
23352
+ }
23353
+ ],
23354
+ "subcommands": []
23355
+ },
23240
23356
  {
23241
23357
  "name": "sync",
23242
23358
  "description": "Inspect and control the daemon's company sync runner",
@@ -23659,6 +23775,58 @@ export const COMMAND_CATALOG = [
23659
23775
  "options": [],
23660
23776
  "subcommands": []
23661
23777
  },
23778
+ {
23779
+ "name": "pause",
23780
+ "description": "Stop sync-core and keep it stopped (watchdog and daemon restarts included) until resumed",
23781
+ "aliases": [],
23782
+ "hidden": false,
23783
+ "helpOption": true,
23784
+ "helpCommand": false,
23785
+ "usage": "[options] <service>",
23786
+ "helpText": [],
23787
+ "arguments": [
23788
+ {
23789
+ "name": "service",
23790
+ "required": true,
23791
+ "variadic": false,
23792
+ "description": ""
23793
+ }
23794
+ ],
23795
+ "options": [
23796
+ {
23797
+ "flags": "--json",
23798
+ "description": "Print machine-readable JSON",
23799
+ "hidden": false
23800
+ }
23801
+ ],
23802
+ "subcommands": []
23803
+ },
23804
+ {
23805
+ "name": "resume",
23806
+ "description": "Start a paused sync-core again",
23807
+ "aliases": [],
23808
+ "hidden": false,
23809
+ "helpOption": true,
23810
+ "helpCommand": false,
23811
+ "usage": "[options] <service>",
23812
+ "helpText": [],
23813
+ "arguments": [
23814
+ {
23815
+ "name": "service",
23816
+ "required": true,
23817
+ "variadic": false,
23818
+ "description": ""
23819
+ }
23820
+ ],
23821
+ "options": [
23822
+ {
23823
+ "flags": "--json",
23824
+ "description": "Print machine-readable JSON",
23825
+ "hidden": false
23826
+ }
23827
+ ],
23828
+ "subcommands": []
23829
+ },
23662
23830
  {
23663
23831
  "name": "pin-hq-cloud",
23664
23832
  "description": "Pin hq-cloud to an exact version, or clear the pin",
@@ -23789,6 +23957,25 @@ export const COMMAND_CATALOG = [
23789
23957
  "arguments": [],
23790
23958
  "options": [],
23791
23959
  "subcommands": [
23960
+ {
23961
+ "name": "mesh",
23962
+ "description": "Work Mesh Live: spool drain, MQTT presence and the live Board cache (the daemon's mesh service)",
23963
+ "aliases": [],
23964
+ "hidden": false,
23965
+ "helpOption": true,
23966
+ "helpCommand": false,
23967
+ "usage": "[options]",
23968
+ "helpText": [],
23969
+ "arguments": [],
23970
+ "options": [
23971
+ {
23972
+ "flags": "--hq-root <path>",
23973
+ "description": "HQ folder the service works against",
23974
+ "hidden": false
23975
+ }
23976
+ ],
23977
+ "subcommands": []
23978
+ },
23792
23979
  {
23793
23980
  "name": "self-update",
23794
23981
  "description": "Update the hq CLI, Claude, Codex and Grok, then restart the daemon onto a new CLI",
@@ -153,8 +153,11 @@ export interface VaultClient {
153
153
  * Soft-tombstone a company (`DELETE /entity/{uid}`). Owner-only. Leaves the
154
154
  * row, S3 bucket, KMS key, and memberships intact. Idempotent on an already
155
155
  * deleted company. Used by `hq cloud retire company`.
156
+ *
157
+ * hq-pro requires a JSON body `{ confirmName }` matching the company name
158
+ * or slug (`COMPANY_DELETE_CONFIRMATION_REQUIRED` otherwise).
156
159
  */
157
- softDeleteCompany(uid: string): Promise<{
160
+ softDeleteCompany(uid: string, confirmName: string): Promise<{
158
161
  deleted: true;
159
162
  uid: string;
160
163
  }>;
@@ -413,9 +413,13 @@ export function createDefaultVaultClient(apiUrl, accessToken) {
413
413
  return data.entity;
414
414
  });
415
415
  },
416
- async softDeleteCompany(uid) {
416
+ async softDeleteCompany(uid, confirmName) {
417
417
  const url = `${apiUrl.replace(/\/$/, "")}/entity/${encodeURIComponent(uid)}`;
418
- return withVaultRequest(url, { method: "DELETE", headers }, async (res) => {
418
+ return withVaultRequest(url, {
419
+ method: "DELETE",
420
+ headers,
421
+ body: JSON.stringify({ confirmName }),
422
+ }, async (res) => {
419
423
  if (res.status === 403) {
420
424
  const body = await safeBody(res);
421
425
  throw new ProvisionError(2, `Refusing to retire '${uid}': only the company owner can soft-tombstone it. ${body}`);
@@ -628,7 +632,7 @@ export async function provisionCompany(options) {
628
632
  let retired = false;
629
633
  if (createdEntity) {
630
634
  try {
631
- await vaultClient.softDeleteCompany(entity.uid);
635
+ await vaultClient.softDeleteCompany(entity.uid, entity.slug || options.slug);
632
636
  retired = true;
633
637
  log(`retired vault entity uid=${entity.uid} — assigned slug ${assigned} differs from requested ${options.slug}`);
634
638
  }
@@ -98,7 +98,7 @@ export async function retireCompany(options) {
98
98
  }
99
99
  }
100
100
  try {
101
- await client.softDeleteCompany(uid);
101
+ await client.softDeleteCompany(uid, options.slug);
102
102
  }
103
103
  catch (err) {
104
104
  if (err instanceof ProvisionError)
@@ -1,4 +1,5 @@
1
1
  /** Native implementations of the second Wave 1 delegate command family. */
2
+ import { daemonWhoamiOutput } from "../lib/daemon/whoami-cache.js";
2
3
  import { createHash, randomInt } from "node:crypto";
3
4
  import * as fs from "node:fs";
4
5
  import * as os from "node:os";
@@ -292,7 +293,8 @@ function runBundle(args, context, onMalformedWhoami) {
292
293
  const projectRelative = `companies/${company}/projects/${project}`;
293
294
  const brainstormPath = path.join(projectDir, "brainstorm.md");
294
295
  const brainstormRelative = `${projectRelative}/brainstorm.md`;
295
- const who = subprocess("hq", ["whoami", "--json"], context.cwd, { stdout: "capture" });
296
+ const cachedWho = (context.daemonWhoami ?? daemonWhoamiOutput)(true);
297
+ const who = cachedWho !== null ? { code: 0, stdout: cachedWho } : subprocess("hq", ["whoami", "--json"], context.cwd, { stdout: "capture" });
296
298
  if (who.code !== 0)
297
299
  return fail("bundle", "could not read sender identity; update hq-cli if --json is unsupported");
298
300
  let identity;
@@ -6,6 +6,11 @@ export declare const CORE_NATIVE_DELEGATE_FLAG = "core-native-delegate";
6
6
  export type DelegateContext = {
7
7
  cwd: string;
8
8
  root?: string;
9
+ /**
10
+ * The daemon's cached `hq whoami` output (json or plain), or null to run
11
+ * `hq whoami` (hq-core-rust US-036). Default: src/lib/daemon/whoami-cache.ts.
12
+ */
13
+ daemonWhoami?: (json: boolean) => string | null;
9
14
  atomicWriteFileSystem?: DelegateAtomicWriteFileSystem;
10
15
  bundleFileSystem?: DelegateBundleFileSystem;
11
16
  };
@@ -1,10 +1,14 @@
1
- /** Native implementation of core/scripts/hq-dm-bind.sh. */
2
1
  import * as fs from "node:fs";
3
2
  import type { Command } from "commander";
4
3
  import { type UtilityOutput } from "./core-native-utilities.js";
5
4
  export declare const DM_BIND_ASSET = "core/scripts/hq-dm-bind.sh";
6
5
  export declare const DM_BIND_HELP = "# hq-dm-bind.sh \u2014 bind the current session to one HQ DM channel, post\n# structured updates to it, and listen for replies (feedback / requests).\n#\n# Usage:\n# core/scripts/hq-dm-bind.sh bind <channel> # bind + set the read cursor to \"now\"\n# core/scripts/hq-dm-bind.sh status # show the binding and cursor\n# core/scripts/hq-dm-bind.sh post --title <t> [--state <s>] [--line <l>]... [--next <l>]... [--ask <l>]... [--to <name>]... [--topic <t>] [--under <id>] [--new-thread]\n# core/scripts/hq-dm-bind.sh post --title <t> - < body.md # body from stdin (already structured)\n# core/scripts/hq-dm-bind.sh threads # list the channel's recent top-level threads (id, replies, author, text)\n# core/scripts/hq-dm-bind.sh roster # print the channel members a post will @-mention\n# core/scripts/hq-dm-bind.sh poll # print new messages since the cursor, advance it\n# core/scripts/hq-dm-bind.sh listen [--interval 60] [--timeout 1800]\n# # block until a new message arrives (or timeout)\n# core/scripts/hq-dm-bind.sh unbind\n#\n# The binding lives in the session's meta.yaml (`dm_channel`) via hq-session.sh;\n# the cursor is `workspace/sessions/<sid>/dm-bind.cursor` (the last seen sort\n# key from `hq dm channel --json`). `listen` is meant to run detached\n# (Bash run_in_background): it exits 0 and prints the new messages the moment\n# one lands, exits 3 on timeout with nothing new.\n#\n# Every post opens with an @-mention of every other member of the channel, so\n# the update reaches people (HQ mentions are structured: the `hq` CLI resolves\n# the `@\"Display Name\"` tokens against the roster and sends the real mention\n# list; an unresolvable name fails the post rather than posting text that looks\n# addressed but is not). The CLI rewrites a resolved `@\"Display Name\"` token to\n# `@Display Name`, so the room never shows the quotes.\n#\n# Posts thread by topic. The first post on a topic (`--topic`, else the title)\n# is a top-level root; every later post on the same topic in this session goes\n# out as a reply under it. `--under <id>` replies under an existing thread that\n# someone else (or an earlier session) started \u2014 a top-level post is only for a\n# subject the channel has no thread for yet. `--new-thread` starts a fresh root. The topic \u2192 root\n# map is `workspace/sessions/<sid>/dm-bind.threads`.\n#\n# A post ALWAYS mentions someone. `--to <name>` (repeatable) narrows the line to\n# the named members, for a reply to one person; without it the line names every\n# other human member (bots are left out unless named with --to, because a tagged\n# bot wakes and replies). There is no way to post unmentioned: an update nobody is\n# notified about does not get read. `post` refuses when the roster cannot be\n# read rather than sending a silent update.\n#\n# Post format (kept deliberately plain \u2014 see .claude/skills/dm-bind/SKILL.md):\n# @\"Ada Lovelace\" @\"Grace Hopper\"\n#\n# <title> \u2014 <state>\n#\n# \u2022 line\n# \u2022 line\n#\n# Next: line\n# Need from you: line\n";
7
6
  export type DmBindDeps = {
7
+ /**
8
+ * The daemon's cached `hq whoami` output (json or plain), or null to run
9
+ * `hq whoami` (hq-core-rust US-036). Default: src/lib/daemon/whoami-cache.ts.
10
+ */
11
+ daemonWhoami?: (json: boolean) => string | null;
8
12
  root: string;
9
13
  cwd: string;
10
14
  env: NodeJS.ProcessEnv;
@@ -1,4 +1,5 @@
1
1
  /** Native implementation of core/scripts/hq-dm-bind.sh. */
2
+ import { daemonWhoamiOutput } from "../lib/daemon/whoami-cache.js";
2
3
  import * as fs from "node:fs";
3
4
  import * as os from "node:os";
4
5
  import * as path from "node:path";
@@ -177,6 +178,9 @@ function usesCliAuth(d) {
177
178
  }
178
179
  }
179
180
  function whoamiText(d, json = false) {
181
+ const cached = (d.daemonWhoami ?? ((asJson) => daemonWhoamiOutput(asJson, d.env)))(json);
182
+ if (cached !== null)
183
+ return cached;
180
184
  const result = d.runHq(json ? ["whoami", "--json"] : ["whoami"], { ...d.env, HQ_ROOT: d.root });
181
185
  return result.code === 0 ? result.stdout : "";
182
186
  }
@@ -1,4 +1,3 @@
1
- /** Native TypeScript port of hq-job-notify.sh. */
2
1
  import { Command } from "commander";
3
2
  type Environment = Record<string, string | undefined>;
4
3
  export type JobNotifyProcessResult = {
@@ -12,6 +11,11 @@ export type JobNotifyRunOptions = {
12
11
  logPath?: string;
13
12
  };
14
13
  export type JobNotifyDependencies = {
14
+ /**
15
+ * The daemon's cached `hq whoami` output (json or plain), or null to run
16
+ * `hq whoami` (hq-core-rust US-036). Default: src/lib/daemon/whoami-cache.ts.
17
+ */
18
+ daemonWhoami?: (json: boolean) => string | null;
15
19
  env: Environment;
16
20
  cwd: string;
17
21
  now: () => Date;
@@ -1,3 +1,5 @@
1
+ /** Native TypeScript port of hq-job-notify.sh. */
2
+ import { daemonWhoamiOutput } from "../lib/daemon/whoami-cache.js";
1
3
  import * as fs from "node:fs";
2
4
  import * as os from "node:os";
3
5
  import * as path from "node:path";
@@ -205,12 +207,16 @@ const COGNITO_SUB = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
205
207
  * to the signed-in identity's email when `hq whoami --json` reports the same
206
208
  * subject, directly or as the human an Outpost session acts for.
207
209
  */
210
+ function cachedWhoami(deps, json) {
211
+ return (deps.daemonWhoami ?? ((asJson) => daemonWhoamiOutput(asJson, deps.env)))(json);
212
+ }
208
213
  function resolveCognitoOwner(owner, deps) {
209
214
  if (!deps.commandExists("hq"))
210
215
  return "";
211
216
  let parsed;
212
217
  try {
213
- const raw = deps.run("hq", ["whoami", "--json"], { cwd: deps.cwd, env: deps.env, captureStdout: true }).stdout;
218
+ const raw = cachedWhoami(deps, true)
219
+ ?? deps.run("hq", ["whoami", "--json"], { cwd: deps.cwd, env: deps.env, captureStdout: true }).stdout;
214
220
  const value = JSON.parse(raw);
215
221
  if (!value || typeof value !== "object" || Array.isArray(value))
216
222
  return "";
@@ -285,7 +291,7 @@ export function runJobNotify(argv, options = {}) {
285
291
  if (!owner || owner === "null") {
286
292
  owner = "";
287
293
  if (deps.commandExists("hq")) {
288
- owner = emailFromWhoami(deps.run("hq", ["whoami"], {
294
+ owner = emailFromWhoami(cachedWhoami(deps, false) ?? deps.run("hq", ["whoami"], {
289
295
  cwd: deps.cwd, env: deps.env, captureStdout: true,
290
296
  }).stdout);
291
297
  }
@@ -1,4 +1,3 @@
1
- /** Native TypeScript ports for the Wave 4a scheduled-jobs scaffold tools. */
2
1
  import { Command } from "commander";
3
2
  export { detectHostTimezone, runScheduleParse, type ScheduleParseWriters } from "./core-jobs-schedule.js";
4
3
  export declare function validateJobs(args: string[]): number;
@@ -9,6 +8,11 @@ type ReconcileCommandResult = {
9
8
  };
10
9
  export type ReconcileRunner = (command: string, args: string[]) => ReconcileCommandResult;
11
10
  export type ReconcileOptions = {
11
+ /**
12
+ * The daemon's cached `hq whoami` output (json or plain), or null to run
13
+ * `hq whoami` (hq-core-rust US-036). Default: src/lib/daemon/whoami-cache.ts.
14
+ */
15
+ daemonWhoami?: (json: boolean) => string | null;
12
16
  schedulerRunner?: ReconcileRunner;
13
17
  commandRunner?: ReconcileRunner;
14
18
  identityFileReader?: (file: string) => string | undefined;
@@ -23,6 +27,28 @@ export type ReconcileOptions = {
23
27
  * exists, point systemctl at it. Caller-provided values are kept.
24
28
  */
25
29
  export declare function withUserBusEnvironment(env: NodeJS.ProcessEnv, uid: number | undefined, runtimeBase?: string, exists?: (file: string) => boolean): NodeJS.ProcessEnv;
30
+ /**
31
+ * How a PATH value is separated and which of its entries are absolute. The
32
+ * host's own rules by default: `:` and a leading `/` on POSIX, `;` and a drive
33
+ * or UNC root on Windows. Read with the POSIX rules, a Windows PATH has no
34
+ * entry left, so the service PATH was empty there and no `hq` was ever found.
35
+ */
36
+ export type ServicePathRules = {
37
+ delimiter: string;
38
+ isAbsolute: (entry: string) => boolean;
39
+ };
40
+ /**
41
+ * One `hq` lookup for the service PATH and the unit's ExecStart. ExecStart
42
+ * uses the PATH entry as found (`hq`), not its realpath: mise and Volta
43
+ * install `hq` as a symlink to one multi-call shim that dispatches on argv[0],
44
+ * so exec'ing the symlink target would run the shim as itself instead of as
45
+ * `hq`. `servicePath` is the absolute, de-duplicated entries of `pathValue`,
46
+ * with the real directory of that `hq` in front when it is not already listed.
47
+ */
48
+ export declare function resolveServicePath(pathValue: string | undefined, rules?: ServicePathRules): {
49
+ servicePath: string;
50
+ hq: string | undefined;
51
+ };
26
52
  export declare function runReconcile(argv: string[], rootArg?: string, options?: ReconcileOptions): Promise<number>;
27
53
  export declare function registerCoreJobsNativeCommand(core: Command): void;
28
54
  export declare function rawArgumentsForCommand(command: Command, fallback: string[], raw?: string[]): string[];
@@ -1,3 +1,5 @@
1
+ /** Native TypeScript ports for the Wave 4a scheduled-jobs scaffold tools. */
2
+ import { daemonWhoamiOutput } from "../lib/daemon/whoami-cache.js";
1
3
  import * as fs from "node:fs";
2
4
  import * as path from "node:path";
3
5
  import { spawnSync } from "node:child_process";
@@ -426,11 +428,11 @@ function isExecutable(file) {
426
428
  return false;
427
429
  }
428
430
  }
429
- function findExecutable(command, searchPath) {
431
+ function findExecutable(command, searchPath, delimiter = path.delimiter) {
430
432
  if (path.isAbsolute(command) || command.includes(path.sep)) {
431
433
  return isExecutable(command) ? command : undefined;
432
434
  }
433
- for (const directory of searchPath.split(path.delimiter)) {
435
+ for (const directory of searchPath.split(delimiter)) {
434
436
  if (!directory)
435
437
  continue;
436
438
  const candidate = path.join(directory, command);
@@ -490,12 +492,16 @@ function resolveBoxOwners(options) {
490
492
  add(process.env.HQ_JOB_OWNER_UID);
491
493
  add(process.env.OUTPOST_USER_ID);
492
494
  const searchPath = process.env.PATH ?? "";
493
- if (findExecutable("hq", searchPath)) {
495
+ const cachedWho = (options.daemonWhoami ?? daemonWhoamiOutput)(true);
496
+ if (cachedWho !== null || findExecutable("hq", searchPath)) {
494
497
  const run = options.commandRunner ?? commandResult;
495
- let result = run("hq", ["whoami", "--json"]);
496
- if (result.status !== 0)
497
- result = run("hq", ["whoami"]);
498
- const who = result.stdout;
498
+ let who = cachedWho;
499
+ if (who === null) {
500
+ let result = run("hq", ["whoami", "--json"]);
501
+ if (result.status !== 0)
502
+ result = run("hq", ["whoami"]);
503
+ who = result.stdout;
504
+ }
499
505
  if (who) {
500
506
  let parsed;
501
507
  try {
@@ -741,35 +747,51 @@ function cronToOnCalendar(fields) {
741
747
  time = `${hourValue}:${minuteValue}:00`;
742
748
  return dowValue ? `${dowValue} ${date} ${time}` : `${date} ${time}`;
743
749
  }
744
- function normalizeServicePath(value) {
750
+ const HOST_PATH_RULES = { delimiter: path.delimiter, isAbsolute: path.isAbsolute };
751
+ function normalizeServicePath(value, rules) {
745
752
  const entries = [];
746
- for (const entry of value.split(":")) {
747
- if (entry.startsWith("/") && !entries.includes(entry))
753
+ for (const entry of value.split(rules.delimiter)) {
754
+ if (rules.isAbsolute(entry) && !entries.includes(entry))
748
755
  entries.push(entry);
749
756
  }
750
- return entries.join(":");
757
+ return entries.join(rules.delimiter);
751
758
  }
752
- function servicePathValue() {
753
- let servicePath = normalizeServicePath(process.env.PATH || "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
754
- const hq = findExecutable("hq", servicePath);
755
- if (hq) {
756
- let binDirectory = "";
757
- try {
758
- binDirectory = fs.realpathSync(path.dirname(hq));
759
- }
760
- catch { /* `pwd -P` failed in the shell equivalent. */ }
761
- if (binDirectory && !servicePath.split(":").includes(binDirectory))
762
- servicePath = [binDirectory, servicePath].filter(Boolean).join(":");
759
+ const DEFAULT_SERVICE_DIRECTORIES = ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin"];
760
+ /**
761
+ * One `hq` lookup for the service PATH and the unit's ExecStart. ExecStart
762
+ * uses the PATH entry as found (`hq`), not its realpath: mise and Volta
763
+ * install `hq` as a symlink to one multi-call shim that dispatches on argv[0],
764
+ * so exec'ing the symlink target would run the shim as itself instead of as
765
+ * `hq`. `servicePath` is the absolute, de-duplicated entries of `pathValue`,
766
+ * with the real directory of that `hq` in front when it is not already listed.
767
+ */
768
+ export function resolveServicePath(pathValue, rules = HOST_PATH_RULES) {
769
+ const searchPath = normalizeServicePath(pathValue || DEFAULT_SERVICE_DIRECTORIES.join(rules.delimiter), rules);
770
+ const hq = findExecutable("hq", searchPath, rules.delimiter);
771
+ if (!hq)
772
+ return { servicePath: searchPath, hq };
773
+ let binDirectory = "";
774
+ try {
775
+ binDirectory = fs.realpathSync(path.dirname(hq));
763
776
  }
764
- return servicePath;
777
+ catch { /* `pwd -P` failed in the shell equivalent. */ }
778
+ if (binDirectory && !searchPath.split(rules.delimiter).includes(binDirectory)) {
779
+ return { servicePath: [binDirectory, searchPath].filter(Boolean).join(rules.delimiter), hq };
780
+ }
781
+ return { servicePath: searchPath, hq };
782
+ }
783
+ function serviceRunner(root, id, hq) {
784
+ const executable = hq ?? "/usr/bin/env hq";
785
+ return `${executable} core job run --hq-root ${root} --job-id ${id}`;
765
786
  }
766
787
  function systemdQuote(value) {
767
788
  return `"${value.replace(/%/g, "%%").replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")}"`;
768
789
  }
769
790
  function serviceUnit(root, id) {
770
- const pathValue = systemdQuote(`PATH=${servicePathValue()}`);
771
- const runner = path.resolve(root, "core/scripts/hq-job-run.sh");
772
- return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=oneshot\nEnvironment=HQ_ROOT=${root}\nEnvironment=${pathValue}\nEnvironment=HQ_SYNC_UNATTENDED=1\nExecStart=${runner} --hq-root ${root} --job-id ${id}\nNice=10\n\n[Install]\nWantedBy=default.target\n`;
791
+ const { servicePath, hq } = resolveServicePath(process.env.PATH);
792
+ const pathValue = systemdQuote(`PATH=${servicePath}`);
793
+ const runner = serviceRunner(root, id, hq);
794
+ return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=oneshot\nEnvironment=HQ_ROOT=${root}\nEnvironment=${pathValue}\nEnvironment=HQ_SYNC_UNATTENDED=1\nExecStart=${runner}\nNice=10\n\n[Install]\nWantedBy=default.target\n`;
773
795
  }
774
796
  function timerUnit(id, onCalendar, randomize, root) {
775
797
  return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job timer: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\n\n[Timer]\nOnCalendar=${onCalendar}\nPersistent=true\nRandomizedDelaySec=${randomize}\nUnit=hq-job-${id}.service\n\n[Install]\nWantedBy=timers.target\n`;
@@ -882,8 +904,7 @@ export async function runReconcile(argv, rootArg, options = {}) {
882
904
  }
883
905
  if (!root)
884
906
  root = resolveLiveRoot();
885
- const servicePath = servicePathValue();
886
- const hq = findExecutable("hq", servicePath) || "hq";
907
+ const hq = findExecutable("hq", resolveServicePath(process.env.PATH).servicePath) || "hq";
887
908
  const home = process.env.HOME ?? "";
888
909
  const unitDir = process.env.HQ_JOB_UNIT_DIR || path.join(home, ".config", "systemd", "user");
889
910
  const cacheDir = process.env.HQ_JOB_STATUS_CACHE_DIR || path.join(home, ".hq", "jobs", "status-cache");