@indigoai-us/hq-cli 5.345.219 → 5.345.221

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 (199) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/command-catalog.generated.d.ts +169 -3
  3. package/dist/command-catalog.generated.js +206 -3
  4. package/dist/commands/auth.js +4 -1
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +85 -0
  8. package/dist/commands/bot.js +245 -16
  9. package/dist/commands/cloud.d.ts +16 -0
  10. package/dist/commands/cloud.js +112 -102
  11. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  12. package/dist/commands/core-checkpoint-native.js +167 -52
  13. package/dist/commands/core-hook-registration-plan.js +5 -4
  14. package/dist/commands/core-stop-autosave.d.ts +21 -0
  15. package/dist/commands/core-stop-autosave.js +300 -0
  16. package/dist/commands/core.js +2 -0
  17. package/dist/commands/daemon.d.ts +5 -0
  18. package/dist/commands/daemon.js +52 -9
  19. package/dist/commands/doctor-usage.d.ts +5 -0
  20. package/dist/commands/doctor-usage.js +25 -0
  21. package/dist/commands/env.d.ts +49 -4
  22. package/dist/commands/env.js +355 -5
  23. package/dist/commands/integrations.js +84 -3
  24. package/dist/commands/lanes-shared.d.ts +3 -0
  25. package/dist/commands/lanes.d.ts +3 -0
  26. package/dist/commands/lanes.js +87 -3
  27. package/dist/commands/packs.js +23 -0
  28. package/dist/commands/pkg-update.d.ts +6 -0
  29. package/dist/commands/pkg-update.js +15 -7
  30. package/dist/commands/run.js +55 -45
  31. package/dist/commands/sources.js +4 -3
  32. package/dist/commands/sync-core.d.ts +1 -0
  33. package/dist/commands/sync-core.js +77 -3
  34. package/dist/commands/whoami.js +96 -80
  35. package/dist/lib/bot/config.d.ts +17 -0
  36. package/dist/lib/bot/config.js +13 -0
  37. package/dist/lib/bot/fleet-cron.js +29 -4
  38. package/dist/lib/bot/fleet-local.d.ts +30 -2
  39. package/dist/lib/bot/fleet-local.js +60 -1
  40. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  41. package/dist/lib/bot/grok-login-scope.js +93 -0
  42. package/dist/lib/bot/inflight.d.ts +9 -0
  43. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  44. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  45. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  46. package/dist/lib/bot/legacy-provider-login.js +28 -22
  47. package/dist/lib/bot/run.d.ts +29 -5
  48. package/dist/lib/bot/run.js +203 -1
  49. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  50. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  51. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  52. package/dist/lib/bot/signals-try-now.js +111 -0
  53. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  54. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  55. package/dist/lib/capacity/scheduler.d.ts +8 -0
  56. package/dist/lib/capacity/scheduler.js +5 -2
  57. package/dist/lib/core-utils/sentry-report.js +2 -0
  58. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  59. package/dist/lib/daemon/machine-checks.js +54 -12
  60. package/dist/lib/daemon/run.js +71 -8
  61. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  62. package/dist/lib/daemon/runtime-notifications.js +50 -0
  63. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  64. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  65. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  66. package/dist/lib/daemon/stop-autosave.js +111 -0
  67. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  68. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  69. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  70. package/dist/lib/daemon/stop-job-executor.js +126 -0
  71. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  72. package/dist/lib/daemon/stop-jobs.js +599 -0
  73. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
  74. package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
  75. package/dist/lib/doctor/checks/host-core.js +1 -1
  76. package/dist/lib/environment/access-probes.d.ts +234 -0
  77. package/dist/lib/environment/access-probes.js +918 -0
  78. package/dist/lib/environment/profile.d.ts +15 -2
  79. package/dist/lib/environment/profile.js +55 -20
  80. package/dist/lib/environment/rfc3339.d.ts +8 -0
  81. package/dist/lib/environment/rfc3339.js +26 -0
  82. package/dist/lib/environment/work-requirements.d.ts +169 -0
  83. package/dist/lib/environment/work-requirements.js +389 -0
  84. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  85. package/dist/lib/hook-engine/coverage.js +1424 -4
  86. package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
  87. package/dist/lib/hook-engine/fleet-registration.js +53 -17
  88. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  89. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  90. package/dist/lib/hook-engine/reconcile.js +2 -2
  91. package/dist/lib/hot-channels/alert.d.ts +10 -1
  92. package/dist/lib/hot-channels/alert.js +38 -8
  93. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  94. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  95. package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
  96. package/dist/lib/hot-channels/signals-pass.js +324 -17
  97. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  98. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  99. package/dist/lib/install/hook-target.js +1 -1
  100. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  101. package/dist/lib/lanes/host-capacity.js +17 -2
  102. package/dist/lib/lanes/host-compute.d.ts +90 -0
  103. package/dist/lib/lanes/host-compute.js +185 -0
  104. package/dist/lib/lanes/index.d.ts +2 -0
  105. package/dist/lib/lanes/index.js +1 -0
  106. package/dist/lib/lanes/reconcile.js +22 -1
  107. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  108. package/dist/lib/lanes/resource-usage.js +589 -0
  109. package/dist/lib/lanes/run-size.d.ts +46 -0
  110. package/dist/lib/lanes/run-size.js +197 -0
  111. package/dist/lib/lanes/store.js +27 -0
  112. package/dist/lib/lanes/throttle.d.ts +36 -1
  113. package/dist/lib/lanes/throttle.js +47 -10
  114. package/dist/lib/lanes/types.d.ts +40 -0
  115. package/dist/lib/lanes/types.js +2 -2
  116. package/dist/lib/lanes/watcher.js +13 -4
  117. package/dist/lib/lanes/worker-process.d.ts +25 -2
  118. package/dist/lib/lanes/worker-process.js +71 -19
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/safe-store.d.ts +14 -0
  122. package/dist/lib/safe-store.js +77 -4
  123. package/dist/lib/search-index/index.d.ts +88 -4
  124. package/dist/lib/search-index/index.js +299 -25
  125. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  126. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  127. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  128. package/dist/lib/signals/codex-lockdown.js +271 -0
  129. package/dist/lib/signals/codex-login.d.ts +37 -0
  130. package/dist/lib/signals/codex-login.js +83 -0
  131. package/dist/lib/signals/engine.d.ts +28 -0
  132. package/dist/lib/signals/engine.js +77 -0
  133. package/dist/lib/signals/reply.d.ts +48 -0
  134. package/dist/lib/signals/reply.js +94 -12
  135. package/dist/lib/signals/run-record.js +6 -1
  136. package/dist/lib/signals/settings.d.ts +5 -0
  137. package/dist/lib/signals/settings.js +2 -0
  138. package/dist/lib/signals/steps/adapters.js +6 -0
  139. package/dist/lib/signals/steps/extract.d.ts +135 -12
  140. package/dist/lib/signals/steps/extract.js +416 -84
  141. package/dist/lib/signals/steps/types.d.ts +21 -0
  142. package/dist/lib/sync-core/engine-home.d.ts +41 -2
  143. package/dist/lib/sync-core/engine-home.js +132 -19
  144. package/dist/lib/sync-core/reconcile.js +1 -1
  145. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  146. package/dist/lib/sync-core/release-compare.js +16 -0
  147. package/dist/lib/sync-core/release.d.ts +2 -1
  148. package/dist/lib/sync-core/release.js +2 -10
  149. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  150. package/dist/lib/sync-core/rollout-state.js +5 -2
  151. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  152. package/dist/lib/sync-core/vault-uid.js +4 -0
  153. package/dist/run/schema-env-overrides.d.ts +24 -0
  154. package/dist/run/schema-env-overrides.js +72 -0
  155. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  156. package/dist/utils/auth-session-check.d.ts +16 -0
  157. package/dist/utils/auth-session-check.js +16 -0
  158. package/dist/utils/client-health-contract.d.ts +6 -0
  159. package/dist/utils/client-health-contract.js +13 -0
  160. package/dist/utils/client-health.d.ts +7 -0
  161. package/dist/utils/client-health.js +22 -1
  162. package/dist/utils/command-usage.d.ts +40 -0
  163. package/dist/utils/command-usage.js +61 -0
  164. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  165. package/dist/utils/duplicate-command-usage.js +125 -0
  166. package/dist/utils/host-registration.d.ts +1 -1
  167. package/dist/utils/host-registration.js +6 -1
  168. package/dist/utils/resident-package-preload.js +4 -0
  169. package/dist/utils/sentry-fingerprint.js +9 -0
  170. package/dist/utils/windows-bash.d.ts +2 -0
  171. package/dist/utils/windows-bash.js +2 -1
  172. package/package.json +15 -10
  173. package/scripts/bench-core-compare.mjs +313 -0
  174. package/scripts/bench-core.mjs +399 -12
  175. package/scripts/check-function-manifest.mjs +121 -7
  176. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  177. package/dist/commands/__fixtures__/access-vault.js +0 -166
  178. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  179. package/dist/commands/__fixtures__/make-tar.js +0 -102
  180. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  181. package/dist/commands/secrets-public-types.test-d.js +0 -18
  182. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  183. package/dist/lib/decisions/fixtures/us001.js +0 -21
  184. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  185. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  186. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  187. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  188. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  189. package/dist/lib/fingerprint/fixtures.js +0 -61
  190. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  191. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  192. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  193. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  194. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  195. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  196. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  197. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  198. package/scripts/hook-engine-manifest.mjs +0 -22
  199. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -40,6 +40,8 @@ export interface StepContext {
40
40
  catchUp: boolean;
41
41
  maxTurns: number;
42
42
  maxBudgetUsd: number;
43
+ /** What a source counts as against the budget when the runtime reports no cost (core/settings/signals.yaml). */
44
+ unpricedSourceEstimateUsd?: number;
43
45
  now: () => Date;
44
46
  spawn: SpawnSyncFn;
45
47
  /** Guarded writer bound to hqRoot. Every engine write goes through it. */
@@ -62,6 +64,19 @@ export interface StepContext {
62
64
  * with the worklist's `--redo` before it lists that channel.
63
65
  */
64
66
  redo?: readonly string[];
67
+ /**
68
+ * The steps this run already finished, in order. Extract reads the adapters
69
+ * step to tell whether the meetings hot channel ran.
70
+ */
71
+ priorSteps?: readonly PriorStep[];
72
+ }
73
+ /** What a later step may read of an earlier step in the same run. */
74
+ export interface PriorStep {
75
+ name: StepName;
76
+ status: StepStatus;
77
+ skippedReason?: string;
78
+ adapterSkips?: Record<string, string>;
79
+ adapterOutcomes?: Record<string, string>;
65
80
  }
66
81
  export interface StepResult {
67
82
  status: StepStatus;
@@ -78,6 +93,12 @@ export interface StepResult {
78
93
  tokenLevels?: Record<string, string>;
79
94
  /** Adapter id -> reason it did not run (`flag-off`). */
80
95
  adapterSkips?: Record<string, string>;
96
+ /**
97
+ * Adapter id -> how its sync ended this run (`ok`, `failed`, `unavailable`,
98
+ * `no-connection`, `gated`). An adapter with several connections is `failed`
99
+ * when any failed, else `ok` when any was ok.
100
+ */
101
+ adapterOutcomes?: Record<string, string>;
81
102
  uploaded?: {
82
103
  count: number;
83
104
  bytes: number;
@@ -14,10 +14,13 @@ export interface SyncCoreVaultPlan extends SyncCoreVault {
14
14
  blockedReason?: string;
15
15
  }
16
16
  export declare const SYNC_CORE_REQUESTS_PER_DAY = 20000;
17
+ export declare const SYNC_CORE_REQUEST_COUNT_REMOVED_IN = "v0.1.29";
17
18
  export declare function syncCoreEngineHome(home: string, vaultUid: string): string;
18
19
  export declare function syncCoreUnitId(vaultUid: string): string;
19
- export declare function isSyncCoreVaultUid(value: unknown): value is string;
20
- export declare function engineConfigToml(vault: SyncCoreVault, hqRoot: string, phase: SyncCoreVaultPhase, tokenPath?: string): string;
20
+ export { isSyncCoreVaultUid } from "./vault-uid.js";
21
+ export declare function engineConfigToml(vault: SyncCoreVault, hqRoot: string, phase: SyncCoreVaultPhase, tokenPath?: string,
22
+ /** The engine release this vault runs. Not given: treated as an engine that still counts requests. */
23
+ release?: string): string;
21
24
  export interface WriteEngineHomeOptions {
22
25
  home: string;
23
26
  hqRoot: string;
@@ -25,6 +28,8 @@ export interface WriteEngineHomeOptions {
25
28
  phase: SyncCoreVaultPhase;
26
29
  tokenFile: string;
27
30
  platform?: NodeJS.Platform;
31
+ /** The engine release this vault runs; decides whether the config carries `requests_per_day`. */
32
+ release?: string;
28
33
  }
29
34
  export declare function writeEngineHome(opts: WriteEngineHomeOptions): {
30
35
  engineHome: string;
@@ -47,6 +52,40 @@ export interface SyncCoreFirstCycle {
47
52
  }
48
53
  export declare const SYNC_CORE_STATUS_WORK_LIMIT = 20;
49
54
  export declare function engineFirstCycle(engineHome: string, vaultUid: string, since: string): SyncCoreFirstCycle | null;
55
+ export interface SyncCoreLastCycle extends SyncCoreFirstCycle {
56
+ fullVault: boolean;
57
+ success: boolean;
58
+ unsupported: number;
59
+ skipped: number;
60
+ transferFailures: number;
61
+ snapshotWaitUntil?: string;
62
+ requestPauseUntil?: string;
63
+ requestBreakerUntil?: string;
64
+ transferWaitUntil?: string;
65
+ transfersQueued?: number;
66
+ }
67
+ export interface SyncCoreRunningCycle {
68
+ startedAt: string;
69
+ updatedAt?: string;
70
+ phase: string;
71
+ planned: number;
72
+ uploadsTotal: number;
73
+ uploadsDone: number;
74
+ downloadsTotal: number;
75
+ downloadsDone: number;
76
+ failed: number;
77
+ currentPath?: string;
78
+ stale: boolean;
79
+ }
80
+ export interface SyncCoreEngineStatus {
81
+ engineVersion?: string;
82
+ startedAt?: string;
83
+ requests24h?: number;
84
+ cycle?: SyncCoreRunningCycle;
85
+ lastCycle?: SyncCoreLastCycle;
86
+ }
87
+ export declare const SYNC_CORE_CYCLE_STALE_MS = 120000;
88
+ export declare function readEngineStatus(engineHome: string, vaultUid: string, now?: Date): SyncCoreEngineStatus | null;
50
89
  export declare function clearEngineStatus(home: string, vaultUid: string): void;
51
90
  export declare function removeEngineOwnership(home: string, vaultUid: string): void;
52
91
  export declare function inspectEngineHome(home: string, hqRoot: string | undefined, plan: SyncCoreVaultPlan, platform: NodeJS.Platform): SyncCoreVaultPlan;
@@ -1,17 +1,25 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { parse as parseToml } from "smol-toml";
4
+ import { compareSyncCoreReleases } from "./release-compare.js";
4
5
  export const SYNC_CORE_REQUESTS_PER_DAY = 20_000;
6
+ // The first engine release with no daily request count; it ignores `requests_per_day`.
7
+ export const SYNC_CORE_REQUEST_COUNT_REMOVED_IN = "v0.1.29";
5
8
  export function syncCoreEngineHome(home, vaultUid) {
6
9
  return path.join(home, ".hq", "sync-core", "engines", vaultUid);
7
10
  }
8
11
  export function syncCoreUnitId(vaultUid) {
9
12
  return `sync-core:${vaultUid}`;
10
13
  }
11
- export function isSyncCoreVaultUid(value) {
12
- return typeof value === "string" && /^(prs|cmp)_[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value);
13
- }
14
- export function engineConfigToml(vault, hqRoot, phase, tokenPath) {
14
+ export { isSyncCoreVaultUid } from "./vault-uid.js";
15
+ export function engineConfigToml(vault, hqRoot, phase, tokenPath,
16
+ /** The engine release this vault runs. Not given: treated as an engine that still counts requests. */
17
+ release) {
18
+ // Engines before the removal fall back to 10,000 a day when the line is missing.
19
+ // A release that is not a plain vX.Y.Z (a pre-release, a mislabelled marker) keeps the line too.
20
+ const countsRequests = release === undefined ||
21
+ !/^v?\d+\.\d+\.\d+$/.test(release) ||
22
+ compareSyncCoreReleases(release, SYNC_CORE_REQUEST_COUNT_REMOVED_IN) < 0;
15
23
  const lines = [
16
24
  "[sync]",
17
25
  'engine = "rust-test"',
@@ -19,7 +27,7 @@ export function engineConfigToml(vault, hqRoot, phase, tokenPath) {
19
27
  ...(phase === "full" ? ["full_vault = true"] : []),
20
28
  `vaults = [${JSON.stringify(vault.uid)}]`,
21
29
  `hq_root = ${JSON.stringify(hqRoot)}`,
22
- `requests_per_day = ${SYNC_CORE_REQUESTS_PER_DAY}`,
30
+ ...(countsRequests ? [`requests_per_day = ${SYNC_CORE_REQUESTS_PER_DAY}`] : []),
23
31
  ...(tokenPath ? [`token_path = ${JSON.stringify(tokenPath)}`] : []),
24
32
  ];
25
33
  if (vault.kind === "company") {
@@ -70,7 +78,7 @@ export function writeEngineHome(opts) {
70
78
  replaceSymlink(path.join(hq, "work-mesh"), path.join(opts.home, ".hq", "work-mesh"));
71
79
  replaceSymlink(path.join(hq, "cognito-tokens.json"), opts.tokenFile);
72
80
  }
73
- const configChanged = writeIfChanged(path.join(root, "config.toml"), engineConfigToml(opts.vault, opts.hqRoot, opts.phase, windows ? opts.tokenFile : undefined));
81
+ const configChanged = writeIfChanged(path.join(root, "config.toml"), engineConfigToml(opts.vault, opts.hqRoot, opts.phase, windows ? opts.tokenFile : undefined, opts.release));
74
82
  const ownedPath = path.join(root, "owned", `${opts.vault.uid}.json`);
75
83
  let ownedChanged = false;
76
84
  if (opts.phase === "full") {
@@ -86,26 +94,19 @@ export const SYNC_CORE_STATUS_WORK_LIMIT = 20;
86
94
  function count(value) {
87
95
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
88
96
  }
89
- export function engineFirstCycle(engineHome, vaultUid, since) {
90
- let status;
97
+ function readStatusFile(engineHome) {
91
98
  try {
92
- status = record(JSON.parse(fs.readFileSync(path.join(engineHome, ".hq", "sync-core", "status.json"), "utf8")));
99
+ return record(JSON.parse(fs.readFileSync(path.join(engineHome, ".hq", "sync-core", "status.json"), "utf8")));
93
100
  }
94
101
  catch {
95
- return null;
102
+ return undefined;
96
103
  }
97
- if (record(status?.mode)?.value !== "full")
98
- return null;
99
- const cycle = record(status?.last_canary);
100
- if (!cycle || cycle.vault !== vaultUid || cycle.full_vault !== true)
101
- return null;
102
- const sinceMs = Date.parse(since);
103
- if (typeof cycle.at_ms !== "number" || cycle.at_ms <= 0 || !Number.isFinite(sinceMs) || cycle.at_ms < sinceMs)
104
- return null;
104
+ }
105
+ function cycleSummary(cycle, atMs) {
105
106
  const work = (Array.isArray(cycle.work) ? cycle.work : []).map(record).filter((item) => item !== undefined);
106
107
  const actions = (...names) => work.filter((item) => names.includes(String(item.action))).length;
107
108
  return {
108
- at: new Date(cycle.at_ms).toISOString(),
109
+ at: new Date(atMs).toISOString(),
109
110
  planned: count(cycle.planned),
110
111
  completed: count(cycle.completed),
111
112
  pending: count(cycle.pending),
@@ -120,6 +121,118 @@ export function engineFirstCycle(engineHome, vaultUid, since) {
120
121
  truncated: work.length >= SYNC_CORE_STATUS_WORK_LIMIT,
121
122
  };
122
123
  }
124
+ function timestampMs(value) {
125
+ return typeof value === "number" && Number.isFinite(value) && value > 0 && value <= 8.64e15 ? value : undefined;
126
+ }
127
+ function isoTime(value) {
128
+ const ms = timestampMs(value);
129
+ return ms === undefined ? undefined : new Date(ms).toISOString();
130
+ }
131
+ export function engineFirstCycle(engineHome, vaultUid, since) {
132
+ const status = readStatusFile(engineHome);
133
+ if (!status)
134
+ return null;
135
+ if (record(status?.mode)?.value !== "full")
136
+ return null;
137
+ const cycle = record(status?.last_canary);
138
+ if (!cycle || cycle.vault !== vaultUid || cycle.full_vault !== true)
139
+ return null;
140
+ const sinceMs = Date.parse(since);
141
+ if (typeof cycle.at_ms !== "number" || cycle.at_ms <= 0 || !Number.isFinite(sinceMs) || cycle.at_ms < sinceMs)
142
+ return null;
143
+ return cycleSummary(cycle, cycle.at_ms);
144
+ }
145
+ export const SYNC_CORE_CYCLE_STALE_MS = 120_000;
146
+ const CYCLE_PATH_LIMIT = 200;
147
+ function wholeCount(value) {
148
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
149
+ }
150
+ const UNPRINTED_CODE_POINTS = [
151
+ [0x00, 0x1f],
152
+ [0x7f, 0x9f],
153
+ [0xad, 0xad],
154
+ [0x61c, 0x61c],
155
+ [0x180e, 0x180e],
156
+ [0x200b, 0x200f],
157
+ [0x2028, 0x202e],
158
+ [0x2060, 0x206f],
159
+ [0xfeff, 0xfeff],
160
+ [0xfff9, 0xfffb],
161
+ [0xe0000, 0xe007f],
162
+ ];
163
+ function printablePath(value) {
164
+ if (typeof value !== "string")
165
+ return "";
166
+ const points = Array.from(value).filter((char) => {
167
+ const code = char.codePointAt(0) ?? 0;
168
+ return !UNPRINTED_CODE_POINTS.some(([from, to]) => code >= from && code <= to);
169
+ });
170
+ return points.length > CYCLE_PATH_LIMIT ? `${points.slice(0, CYCLE_PATH_LIMIT - 1).join("")}…` : points.join("");
171
+ }
172
+ function runningCycle(value, vaultUid, now) {
173
+ const cycle = record(value);
174
+ if (!cycle || cycle.vault !== vaultUid)
175
+ return undefined;
176
+ const startedMs = timestampMs(cycle.started_at_ms);
177
+ if (startedMs === undefined)
178
+ return undefined;
179
+ const updatedMs = timestampMs(cycle.updated_at_ms);
180
+ const phase = typeof cycle.phase === "string" && /^[a-z][a-z_]{0,31}$/.test(cycle.phase) ? cycle.phase : "unknown";
181
+ const transferring = phase === "uploading" || phase === "downloading";
182
+ const currentPath = printablePath(cycle.current_path);
183
+ return {
184
+ startedAt: new Date(startedMs).toISOString(),
185
+ ...(updatedMs !== undefined ? { updatedAt: new Date(updatedMs).toISOString() } : {}),
186
+ phase,
187
+ planned: wholeCount(cycle.planned),
188
+ uploadsTotal: wholeCount(cycle.uploads_total),
189
+ uploadsDone: wholeCount(cycle.uploads_done),
190
+ downloadsTotal: wholeCount(cycle.downloads_total),
191
+ downloadsDone: wholeCount(cycle.downloads_done),
192
+ failed: wholeCount(cycle.failed),
193
+ ...(currentPath ? { currentPath } : {}),
194
+ stale: transferring && updatedMs !== undefined && now.getTime() - updatedMs > SYNC_CORE_CYCLE_STALE_MS,
195
+ };
196
+ }
197
+ export function readEngineStatus(engineHome, vaultUid, now = new Date()) {
198
+ const status = readStatusFile(engineHome);
199
+ if (!status)
200
+ return null;
201
+ const startedAt = isoTime(status.started_at_ms);
202
+ const cycle = record(status.last_canary);
203
+ const atMs = cycle && cycle.vault === vaultUid ? timestampMs(cycle.at_ms) : undefined;
204
+ const snapshotWaitUntil = cycle ? isoTime(cycle.snapshot_wait_until_ms) : undefined;
205
+ const requestPauseUntil = cycle ? isoTime(cycle.request_pause_until_ms) : undefined;
206
+ const requestBreakerUntil = cycle ? isoTime(cycle.request_breaker_until_ms) : undefined;
207
+ const transferWaitUntil = cycle ? isoTime(cycle.transfer_wait_until_ms) : undefined;
208
+ const transfersQueued = cycle ? wholeCount(cycle.transfers_queued) : 0;
209
+ const running = runningCycle(status.cycle, vaultUid, now);
210
+ return {
211
+ ...(typeof status.engine_version === "string" && status.engine_version ? { engineVersion: status.engine_version } : {}),
212
+ ...(startedAt ? { startedAt } : {}),
213
+ ...(typeof status.requests_24h === "number" && Number.isFinite(status.requests_24h) && status.requests_24h >= 0
214
+ ? { requests24h: status.requests_24h }
215
+ : {}),
216
+ ...(running ? { cycle: running } : {}),
217
+ ...(cycle && atMs !== undefined
218
+ ? {
219
+ lastCycle: {
220
+ ...cycleSummary(cycle, atMs),
221
+ fullVault: cycle.full_vault === true,
222
+ success: cycle.success === true,
223
+ unsupported: count(cycle.unsupported),
224
+ skipped: count(cycle.skipped),
225
+ transferFailures: Array.isArray(cycle.transfer_failures) ? cycle.transfer_failures.length : 0,
226
+ ...(snapshotWaitUntil ? { snapshotWaitUntil } : {}),
227
+ ...(requestPauseUntil ? { requestPauseUntil } : {}),
228
+ ...(requestBreakerUntil ? { requestBreakerUntil } : {}),
229
+ ...(transferWaitUntil ? { transferWaitUntil } : {}),
230
+ ...(transfersQueued > 0 ? { transfersQueued } : {}),
231
+ },
232
+ }
233
+ : {}),
234
+ };
235
+ }
123
236
  export function clearEngineStatus(home, vaultUid) {
124
237
  fs.rmSync(path.join(syncCoreEngineHome(home, vaultUid), ".hq", "sync-core", "status.json"), { force: true });
125
238
  }
@@ -179,7 +179,7 @@ export async function reconcileSyncCore(deps) {
179
179
  const engineHome = syncCoreEngineHome(deps.home, vault.uid);
180
180
  if (!before)
181
181
  clearEngineStatus(deps.home, vault.uid);
182
- writeEngineHome({ home: deps.home, hqRoot: deps.hqRoot, vault, phase: "full", tokenFile: deps.tokenFile, platform });
182
+ writeEngineHome({ home: deps.home, hqRoot: deps.hqRoot, vault, phase: "full", tokenFile: deps.tokenFile, platform, release: engineRelease });
183
183
  const wasFull = before?.phase === "full";
184
184
  const alreadyOff = vault.kind === "personal"
185
185
  ? switchesBefore.personalOff
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compares two engine releases ("v0.1.28", "0.1.29"). Negative when `a` is older.
3
+ * Kept apart from release.ts, which downloads, so callers that only compare
4
+ * versions do not pull networking into their import closure.
5
+ */
6
+ export declare function compareSyncCoreReleases(a: string, b: string): number;
7
+ //# sourceMappingURL=release-compare.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Compares two engine releases ("v0.1.28", "0.1.29"). Negative when `a` is older.
3
+ * Kept apart from release.ts, which downloads, so callers that only compare
4
+ * versions do not pull networking into their import closure.
5
+ */
6
+ export function compareSyncCoreReleases(a, b) {
7
+ const parse = (release) => release.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
8
+ const [x, y] = [parse(a), parse(b)];
9
+ for (let i = 0; i < Math.max(x.length, y.length); i += 1) {
10
+ const diff = (x[i] ?? 0) - (y[i] ?? 0);
11
+ if (diff !== 0)
12
+ return diff;
13
+ }
14
+ return 0;
15
+ }
16
+ //# sourceMappingURL=release-compare.js.map
@@ -7,7 +7,8 @@ export declare const SYNC_CORE_FULL_RELEASE: string | null;
7
7
  */
8
8
  export declare const SYNC_CORE_WINDOWS_FULL_RELEASE: string | null;
9
9
  export declare const SYNC_CORE_WINDOWS_FULL_RELEASE_ENV = "HQ_SYNC_CORE_WINDOWS_FULL_RELEASE";
10
- export declare function compareSyncCoreReleases(a: string, b: string): number;
10
+ import { compareSyncCoreReleases } from "./release-compare.js";
11
+ export { compareSyncCoreReleases };
11
12
  export declare function windowsFullRelease(env?: NodeJS.ProcessEnv): string | null;
12
13
  export declare function fullModeAllowed(release: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): boolean;
13
14
  export declare const SYNC_CORE_DOWNLOAD_BASE = "https://indigoai-public.s3.amazonaws.com/hq-sync-core";
@@ -12,16 +12,8 @@ export const SYNC_CORE_FULL_RELEASE = "v0.1.23";
12
12
  */
13
13
  export const SYNC_CORE_WINDOWS_FULL_RELEASE = null;
14
14
  export const SYNC_CORE_WINDOWS_FULL_RELEASE_ENV = "HQ_SYNC_CORE_WINDOWS_FULL_RELEASE";
15
- export function compareSyncCoreReleases(a, b) {
16
- const parse = (release) => release.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
17
- const [x, y] = [parse(a), parse(b)];
18
- for (let i = 0; i < Math.max(x.length, y.length); i += 1) {
19
- const diff = (x[i] ?? 0) - (y[i] ?? 0);
20
- if (diff !== 0)
21
- return diff;
22
- }
23
- return 0;
24
- }
15
+ import { compareSyncCoreReleases } from "./release-compare.js";
16
+ export { compareSyncCoreReleases };
25
17
  export function windowsFullRelease(env = process.env) {
26
18
  const override = env[SYNC_CORE_WINDOWS_FULL_RELEASE_ENV]?.trim();
27
19
  return override && /^v?\d+\.\d+\.\d+$/.test(override) ? override : SYNC_CORE_WINDOWS_FULL_RELEASE;
@@ -1,4 +1,4 @@
1
- import { type SyncCoreFirstCycle, type SyncCoreVaultKind, type SyncCoreVaultPhase } from "./engine-home.js";
1
+ import type { SyncCoreFirstCycle, SyncCoreVaultKind, SyncCoreVaultPhase } from "./engine-home.js";
2
2
  export interface RolloutVault {
3
3
  uid: string;
4
4
  kind: SyncCoreVaultKind;
@@ -28,5 +28,6 @@ export interface SyncCoreRolloutState {
28
28
  }
29
29
  export declare function syncCoreRolloutStatePath(home: string): string;
30
30
  export declare function readSyncCoreRolloutState(home: string): SyncCoreRolloutState | null;
31
+ export declare function readSyncCoreRolloutStateFile(file: string): SyncCoreRolloutState | null;
31
32
  export declare function writeSyncCoreRolloutState(home: string, state: SyncCoreRolloutState): void;
32
33
  //# sourceMappingURL=rollout-state.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
- import { isSyncCoreVaultUid } from "./engine-home.js";
3
+ import { isSyncCoreVaultUid } from "./vault-uid.js";
4
4
  const FIRST_CYCLE_COUNTS = [
5
5
  "planned",
6
6
  "completed",
@@ -75,9 +75,12 @@ function vault(value) {
75
75
  };
76
76
  }
77
77
  export function readSyncCoreRolloutState(home) {
78
+ return readSyncCoreRolloutStateFile(syncCoreRolloutStatePath(home));
79
+ }
80
+ export function readSyncCoreRolloutStateFile(file) {
78
81
  let raw;
79
82
  try {
80
- raw = JSON.parse(fs.readFileSync(syncCoreRolloutStatePath(home), "utf8"));
83
+ raw = JSON.parse(fs.readFileSync(file, "utf8"));
81
84
  }
82
85
  catch {
83
86
  return null;
@@ -0,0 +1,2 @@
1
+ export declare function isSyncCoreVaultUid(value: unknown): value is string;
2
+ //# sourceMappingURL=vault-uid.d.ts.map
@@ -0,0 +1,4 @@
1
+ export function isSyncCoreVaultUid(value) {
2
+ return typeof value === "string" && /^(prs|cmp)_[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value);
3
+ }
4
+ //# sourceMappingURL=vault-uid.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `hq run` must not let inherited process.env values replace .env.schema
3
+ * (feedback_d5698e57). Varlock treats process.env as overrides: an item whose
4
+ * key is already in the environment is marked overridden and the hq() resolver
5
+ * is never called. `hq secrets exec` injects last, so the vault value wins.
6
+ * These helpers make `hq run` match that: schema and .env.local files win,
7
+ * inherited env does not.
8
+ */
9
+ /** Env keys declared in schema / .env.local files (KEY=... lines). */
10
+ export declare function schemaDeclaredKeys(paths: string[]): string[];
11
+ export interface EnvOverrideGraph {
12
+ overrideValues?: Record<string, string | undefined>;
13
+ }
14
+ /**
15
+ * Drop inherited process.env overrides for schema-declared keys so varlock
16
+ * resolves the file (and hq()) instead of the caller's shell.
17
+ */
18
+ export declare function clearInheritedSchemaOverrides(graph: EnvOverrideGraph, keys: string[]): void;
19
+ /**
20
+ * Run `fn` with schema-declared keys removed from process.env, then restore.
21
+ * Covers a varlock that re-reads process.env at load/resolve time.
22
+ */
23
+ export declare function withoutInheritedSchemaEnv<T>(keys: string[], fn: () => Promise<T>): Promise<T>;
24
+ //# sourceMappingURL=schema-env-overrides.d.ts.map
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `hq run` must not let inherited process.env values replace .env.schema
3
+ * (feedback_d5698e57). Varlock treats process.env as overrides: an item whose
4
+ * key is already in the environment is marked overridden and the hq() resolver
5
+ * is never called. `hq secrets exec` injects last, so the vault value wins.
6
+ * These helpers make `hq run` match that: schema and .env.local files win,
7
+ * inherited env does not.
8
+ */
9
+ import * as fs from "node:fs";
10
+ const KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
11
+ /** Env keys declared in schema / .env.local files (KEY=... lines). */
12
+ export function schemaDeclaredKeys(paths) {
13
+ const keys = new Set();
14
+ for (const file of paths) {
15
+ let text;
16
+ try {
17
+ text = fs.readFileSync(file, "utf8");
18
+ }
19
+ catch {
20
+ continue;
21
+ }
22
+ for (const raw of text.split(/\r?\n/)) {
23
+ const line = raw.trim();
24
+ if (line === "" || line.startsWith("#"))
25
+ continue;
26
+ const eq = line.indexOf("=");
27
+ if (eq < 1)
28
+ continue;
29
+ const key = line.slice(0, eq).trim();
30
+ if (KEY.test(key))
31
+ keys.add(key);
32
+ }
33
+ }
34
+ return [...keys];
35
+ }
36
+ /**
37
+ * Drop inherited process.env overrides for schema-declared keys so varlock
38
+ * resolves the file (and hq()) instead of the caller's shell.
39
+ */
40
+ export function clearInheritedSchemaOverrides(graph, keys) {
41
+ const ov = graph.overrideValues;
42
+ if (!ov)
43
+ return;
44
+ for (const key of keys) {
45
+ delete ov[key];
46
+ }
47
+ }
48
+ /**
49
+ * Run `fn` with schema-declared keys removed from process.env, then restore.
50
+ * Covers a varlock that re-reads process.env at load/resolve time.
51
+ */
52
+ export async function withoutInheritedSchemaEnv(keys, fn) {
53
+ const saved = [];
54
+ for (const key of keys) {
55
+ if (!Object.prototype.hasOwnProperty.call(process.env, key))
56
+ continue;
57
+ saved.push([key, process.env[key]]);
58
+ delete process.env[key];
59
+ }
60
+ try {
61
+ return await fn();
62
+ }
63
+ finally {
64
+ for (const [key, value] of saved) {
65
+ if (value === undefined)
66
+ delete process.env[key];
67
+ else
68
+ process.env[key] = value;
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=schema-env-overrides.js.map
@@ -0,0 +1,145 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:hq:schema:hq-work-requirements:v1",
4
+ "title": "hq-work-requirements.v1",
5
+ "description": "What one piece of work (lane, story, scheduled job or message to a bot) needs from an environment. Hard needs are filtered in pass 1; soft preferences are ranked in pass 2. Secret entries are names only. Work that declares nothing gets a derived document (src/lib/environment/work-requirements.ts) whose on_no_fit is conductor-harness (owner decision 3).",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schema_version", "id", "origin", "company", "engines", "needs", "size", "continuity", "tolerates", "on_no_fit"],
9
+ "properties": {
10
+ "schema_version": { "const": "hq-work-requirements.v1" },
11
+ "id": { "type": "string", "minLength": 1 },
12
+ "title": { "type": "string" },
13
+ "origin": {
14
+ "type": "object",
15
+ "additionalProperties": false,
16
+ "required": ["kind", "ref"],
17
+ "properties": {
18
+ "kind": { "enum": ["lane", "story", "job", "message", "session-move"] },
19
+ "ref": { "type": "string", "description": "Lane id, project/story id, job name or message id this declaration is attached to." },
20
+ "derived_from": { "type": "array", "items": { "type": "string" }, "description": "Real records the values were taken from." }
21
+ }
22
+ },
23
+ "company": { "$ref": "#/$defs/company_slug" },
24
+ "engines": {
25
+ "type": "object",
26
+ "additionalProperties": false,
27
+ "required": ["any_of"],
28
+ "properties": {
29
+ "any_of": {
30
+ "type": "array",
31
+ "minItems": 1,
32
+ "uniqueItems": true,
33
+ "items": { "enum": ["claude", "codex", "grok"] },
34
+ "description": "Acceptable engines in order of preference. Order is a pass 2 input; membership is a pass 1 filter."
35
+ },
36
+ "account_pin": {
37
+ "type": ["string", "null"],
38
+ "description": "Optional lane-config account id. When set, only that account is paired."
39
+ }
40
+ }
41
+ },
42
+ "needs": {
43
+ "type": "object",
44
+ "additionalProperties": false,
45
+ "required": ["labels", "repos", "secrets", "integrations"],
46
+ "properties": {
47
+ "labels": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/label" } },
48
+ "repos": {
49
+ "type": "array",
50
+ "uniqueItems": true,
51
+ "items": { "type": "string", "pattern": "^[A-Za-z0-9._-]+$" },
52
+ "description": "Matched against access probes repo:<name>."
53
+ },
54
+ "secrets": {
55
+ "type": "array",
56
+ "uniqueItems": true,
57
+ "items": { "type": "string", "pattern": "^[A-Z0-9_]+(/[A-Z0-9_]+)*$" },
58
+ "description": "Vault secret names only. Matched against access probes secret:<NAME>."
59
+ },
60
+ "integrations": {
61
+ "type": "array",
62
+ "uniqueItems": true,
63
+ "items": { "type": "string", "pattern": "^[a-z0-9-]+$" },
64
+ "description": "Matched against access probes integration:<name>."
65
+ },
66
+ "data": {
67
+ "type": "array",
68
+ "uniqueItems": true,
69
+ "items": { "type": "string", "pattern": "^[a-z0-9-]+(:[a-z0-9-]+)*$" },
70
+ "description": "Local data that must already be on the environment. Matched against access probes data:<name>."
71
+ }
72
+ }
73
+ },
74
+ "prefers": {
75
+ "type": "object",
76
+ "additionalProperties": false,
77
+ "properties": {
78
+ "labels": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/label" } }
79
+ }
80
+ },
81
+ "size": {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["vcpu", "memory_mb", "disk_gb", "expected_run_seconds"],
85
+ "properties": {
86
+ "vcpu": { "type": "number", "exclusiveMinimum": 0 },
87
+ "memory_mb": { "type": "integer", "minimum": 1 },
88
+ "disk_gb": { "type": "number", "minimum": 0 },
89
+ "expected_run_seconds": { "type": "integer", "minimum": 1, "description": "Checked against the environment's max_run_seconds in pass 1." },
90
+ "provenance": {
91
+ "type": "object",
92
+ "additionalProperties": false,
93
+ "required": ["source", "verified"],
94
+ "properties": { "source": { "type": "string" }, "verified": { "type": "boolean" } }
95
+ }
96
+ }
97
+ },
98
+ "continuity": {
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": ["mode"],
102
+ "properties": {
103
+ "mode": {
104
+ "enum": ["none", "workspace-must-survive", "session-move"],
105
+ "description": "workspace-must-survive and session-move both need workspace_survives true on the environment."
106
+ },
107
+ "checkpoint_ref": { "type": ["string", "null"] }
108
+ },
109
+ "allOf": [
110
+ {
111
+ "if": { "properties": { "mode": { "const": "session-move" } } },
112
+ "then": { "required": ["checkpoint_ref"], "properties": { "checkpoint_ref": { "type": "string" } } }
113
+ }
114
+ ]
115
+ },
116
+ "tolerates": {
117
+ "type": "array",
118
+ "uniqueItems": true,
119
+ "items": { "$ref": "#/$defs/label" },
120
+ "description": "Taint keys (key:value) the work accepts. Exact string match."
121
+ },
122
+ "on_no_fit": {
123
+ "enum": ["ask", "queue", "start", "conductor-harness"],
124
+ "description": "ask: one owner decision listing each rejection and the cheapest fix. queue: wait and re-match on the next reading. start: start a feasible template within max_cost_usd. conductor-harness: run on the harness the conductor itself runs on; the default for work that declares nothing (owner decision 3)."
125
+ },
126
+ "max_cost_usd": { "type": ["number", "null"], "minimum": 0 },
127
+ "priority": { "type": "integer", "minimum": 0 },
128
+ "assumptions": {
129
+ "type": "array",
130
+ "items": { "type": "string" },
131
+ "description": "Values in this declaration that were not taken from a record."
132
+ }
133
+ },
134
+ "allOf": [
135
+ {
136
+ "description": "Starting a paid environment needs a cost cap.",
137
+ "if": { "properties": { "on_no_fit": { "const": "start" } } },
138
+ "then": { "required": ["max_cost_usd"], "properties": { "max_cost_usd": { "type": "number" } } }
139
+ }
140
+ ],
141
+ "$defs": {
142
+ "company_slug": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
143
+ "label": { "type": "string", "pattern": "^[a-z][a-z0-9-]*:[A-Za-z0-9._/@*-]+$" }
144
+ }
145
+ }