@wrongstack/core 0.268.0 → 0.269.0

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 (75) hide show
  1. package/dist/{agent-bridge-UhojbpWx.d.ts → agent-bridge-PcHQl_UQ.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-Bvtf1o9K.d.ts → agent-subagent-runner-SHJW7t8q.d.ts} +8 -8
  3. package/dist/{brain-69wzMKp1.d.ts → brain-BYcK__Ym.d.ts} +1 -1
  4. package/dist/{compactor-CBQAJoDc.d.ts → compactor-C2RKEBtC.d.ts} +1 -1
  5. package/dist/{config-VKfOZ-6X.d.ts → config-C_ae2k86.d.ts} +11 -2
  6. package/dist/{context-C0U8B9NF.d.ts → context-Dp87Bcaq.d.ts} +24 -1
  7. package/dist/coordination/index.d.ts +22 -16
  8. package/dist/coordination/index.js +233 -86
  9. package/dist/coordination/index.js.map +1 -1
  10. package/dist/defaults/index.d.ts +25 -25
  11. package/dist/defaults/index.js +272 -69
  12. package/dist/defaults/index.js.map +1 -1
  13. package/dist/execution/index.d.ts +15 -15
  14. package/dist/execution/index.js +116 -19
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/execution/prompt-enhancer.d.ts +1 -1
  17. package/dist/extension/index.d.ts +6 -6
  18. package/dist/{global-mailbox-KByEFFBa.d.ts → global-mailbox-Bvrz1P3f.d.ts} +2 -1
  19. package/dist/{goal-preamble-CrYjmdw4.d.ts → goal-preamble-CA_4yiGQ.d.ts} +9 -9
  20. package/dist/{goal-store-Y_zdLZ3q.d.ts → goal-store-DhuJoUNG.d.ts} +1 -1
  21. package/dist/hq/index.d.ts +15 -6
  22. package/dist/hq/index.js +55 -8
  23. package/dist/hq/index.js.map +1 -1
  24. package/dist/{index-CtQnmkaS.d.ts → index-CZQ6Pwbs.d.ts} +8 -8
  25. package/dist/{index-gCv830d7.d.ts → index-W4VJCzHa.d.ts} +5 -5
  26. package/dist/{index-BfaS-f_m.d.ts → index-whDfTANu.d.ts} +2 -2
  27. package/dist/index.d.ts +41 -41
  28. package/dist/index.js +531 -167
  29. package/dist/index.js.map +1 -1
  30. package/dist/infrastructure/index.d.ts +6 -6
  31. package/dist/infrastructure/index.js +3 -3
  32. package/dist/infrastructure/index.js.map +1 -1
  33. package/dist/kernel/index.d.ts +9 -9
  34. package/dist/{mcp-servers-HT3Fi7Bl.d.ts → mcp-servers-DJdZiRcv.d.ts} +3 -3
  35. package/dist/models/index.d.ts +5 -5
  36. package/dist/models/index.js +1 -1
  37. package/dist/models/index.js.map +1 -1
  38. package/dist/{models-registry-Bvcl3Vaa.d.ts → models-registry-C3a-2-Yd.d.ts} +1 -1
  39. package/dist/{multi-agent-coordinator-BACjsmkC.d.ts → multi-agent-coordinator-CJSpTe5O.d.ts} +1 -1
  40. package/dist/{null-fleet-bus-DA7fvhUg.d.ts → null-fleet-bus-QVshIsDx.d.ts} +6 -6
  41. package/dist/observability/index.d.ts +2 -2
  42. package/dist/{parallel-eternal-engine-Ci71gYu_.d.ts → parallel-eternal-engine-D9y5Pkcc.d.ts} +9 -9
  43. package/dist/{path-resolver-O1IJnmKE.d.ts → path-resolver-CnQ8SIfh.d.ts} +3 -3
  44. package/dist/{permission-Bd-57Lbl.d.ts → permission-CvYQNUqZ.d.ts} +1 -1
  45. package/dist/{permission-policy-uNXC6Kge.d.ts → permission-policy-D5Ss8j4B.d.ts} +2 -2
  46. package/dist/{pipeline-BDNvENyV.d.ts → pipeline-l_zzFRh3.d.ts} +2 -2
  47. package/dist/{plan-templates-EMsalEtN.d.ts → plan-templates-NtPgyeJA.d.ts} +6 -5
  48. package/dist/{provider-model-resolve-CEb9x886.d.ts → provider-model-resolve-d5poT5y0.d.ts} +3 -3
  49. package/dist/{provider-runner-DWJbpo70.d.ts → provider-runner-gkctlQV_.d.ts} +3 -3
  50. package/dist/{retry-policy-C3s_lvdK.d.ts → retry-policy-CtFhfwa8.d.ts} +1 -1
  51. package/dist/sdd/index.d.ts +8 -8
  52. package/dist/sdd/index.js +1 -1
  53. package/dist/sdd/index.js.map +1 -1
  54. package/dist/{secret-vault-Cgduf5xL.d.ts → secret-vault-BLsVmTIK.d.ts} +1 -1
  55. package/dist/security/index.d.ts +5 -5
  56. package/dist/security/index.js.map +1 -1
  57. package/dist/{selector-47LBnBVk.d.ts → selector-CXl2_y9W.d.ts} +1 -1
  58. package/dist/{session-event-bridge-Cw7oqmW2.d.ts → session-event-bridge-Ccud20CC.d.ts} +1 -1
  59. package/dist/{session-reader-DD4v2Obw.d.ts → session-reader-ZeXQmsmE.d.ts} +1 -1
  60. package/dist/skills/index.js.map +1 -1
  61. package/dist/storage/index.d.ts +13 -11
  62. package/dist/storage/index.js +210 -64
  63. package/dist/storage/index.js.map +1 -1
  64. package/dist/tools/index.d.ts +2 -2
  65. package/dist/tools/index.js.map +1 -1
  66. package/dist/types/index.d.ts +21 -21
  67. package/dist/types/index.js +110 -19
  68. package/dist/types/index.js.map +1 -1
  69. package/dist/utils/index.d.ts +2 -2
  70. package/dist/utils/index.js +58 -24
  71. package/dist/utils/index.js.map +1 -1
  72. package/package.json +1 -1
  73. package/skills/chimera/SKILL.md +1 -1
  74. package/skills/typescript-strict/SKILL.md +3 -3
  75. package/skills/typescript-strict/SKILL.save.md +1 -1
@@ -1,4 +1,4 @@
1
- import { P as Provider, M as Message } from '../context-C0U8B9NF.js';
1
+ import { P as Provider, M as Message } from '../context-Dp87Bcaq.js';
2
2
 
3
3
  /**
4
4
  * Prompt refinement ("did you mean this?").
@@ -1,9 +1,9 @@
1
- export { i as AfterIterationHook, j as AfterRunHook, k as AfterToolExecutionHook, l as AgentExtension, B as BeforeIterationHook, m as BeforeRunHook, n as BeforeToolExecutionHook, E as ExtensionRegistry, O as OnErrorHook, v as ProviderRunnerFn, t as ProviderRunnerWrapper } from '../index-gCv830d7.js';
2
- import '../context-C0U8B9NF.js';
1
+ export { i as AfterIterationHook, j as AfterRunHook, k as AfterToolExecutionHook, l as AgentExtension, B as BeforeIterationHook, m as BeforeRunHook, n as BeforeToolExecutionHook, E as ExtensionRegistry, O as OnErrorHook, v as ProviderRunnerFn, t as ProviderRunnerWrapper } from '../index-W4VJCzHa.js';
2
+ import '../context-Dp87Bcaq.js';
3
3
  import '../logger-B63L5bTg.js';
4
- import '../pipeline-BDNvENyV.js';
4
+ import '../pipeline-l_zzFRh3.js';
5
5
  import '../mailbox-types-Ct2hJq0P.js';
6
- import '../config-VKfOZ-6X.js';
6
+ import '../config-C_ae2k86.js';
7
7
  import '../observability-D-HZN_mF.js';
8
- import '../brain-69wzMKp1.js';
9
- import '../permission-Bd-57Lbl.js';
8
+ import '../brain-BYcK__Ym.js';
9
+ import '../permission-CvYQNUqZ.js';
@@ -1,4 +1,4 @@
1
- import { E as EventBus } from './brain-69wzMKp1.js';
1
+ import { E as EventBus } from './brain-BYcK__Ym.js';
2
2
  import { M as MailboxMessage, a as MailboxAgentStatus, b as Mailbox, c as MailboxSendInput, d as MailboxQuery, e as MailboxAckInput, f as MailboxAckBatchInput, A as AgentRegistrationInput, g as AgentHeartbeatInput, C as ClientRegistrationInput, h as ClientHeartbeatInput, i as ClientStatus, P as PurgeOptions, j as PurgeResult } from './mailbox-types-Ct2hJq0P.js';
3
3
 
4
4
  declare const HQ_PROTOCOL_VERSION: 1;
@@ -129,6 +129,7 @@ type HqMailboxMessageType = 'note' | 'ask' | 'assign' | 'steer' | 'btw' | 'broad
129
129
  type HqMailboxPriority = 'low' | 'normal' | 'high';
130
130
  type HqMailboxAgentStatus = 'idle' | 'running' | 'streaming' | 'waiting_user' | 'error' | 'offline';
131
131
  interface HqMailboxMessageSummary {
132
+ mailId: string;
132
133
  messageId: string;
133
134
  from: string;
134
135
  to: string;
@@ -1,14 +1,14 @@
1
1
  import { S as SkillLoader, a as SkillManifest, b as SkillEntry } from './skill-DGIXCtdv.js';
2
2
  import { W as WstackPaths } from './wstack-paths-hOpNLmvf.js';
3
- import { P as Provider, C as Context } from './context-C0U8B9NF.js';
4
- import { C as Compactor, a as CompactReport } from './compactor-CBQAJoDc.js';
5
- import { M as MessageSelector } from './selector-47LBnBVk.js';
6
- import { E as EventBus } from './brain-69wzMKp1.js';
7
- import { M as MiddlewareHandler } from './pipeline-BDNvENyV.js';
8
- import { S as SessionEventBridge } from './session-event-bridge-Cw7oqmW2.js';
9
- import { C as ContextWindowAggressiveOn, h as ContextWindowPolicy } from './config-VKfOZ-6X.js';
10
- import { g as Agent, D as DoneCondition } from './agent-subagent-runner-Bvtf1o9K.js';
11
- import { R as RunResult, S as SystemPromptContributor } from './index-gCv830d7.js';
3
+ import { P as Provider, C as Context } from './context-Dp87Bcaq.js';
4
+ import { C as Compactor, a as CompactReport } from './compactor-C2RKEBtC.js';
5
+ import { M as MessageSelector } from './selector-CXl2_y9W.js';
6
+ import { E as EventBus } from './brain-BYcK__Ym.js';
7
+ import { M as MiddlewareHandler } from './pipeline-l_zzFRh3.js';
8
+ import { S as SessionEventBridge } from './session-event-bridge-Ccud20CC.js';
9
+ import { C as ContextWindowAggressiveOn, h as ContextWindowPolicy } from './config-C_ae2k86.js';
10
+ import { g as Agent, D as DoneCondition } from './agent-subagent-runner-SHJW7t8q.js';
11
+ import { R as RunResult, S as SystemPromptContributor } from './index-W4VJCzHa.js';
12
12
 
13
13
  interface SkillLoaderOptions {
14
14
  paths: WstackPaths;
@@ -1,4 +1,4 @@
1
- import { E as EventBus } from './brain-69wzMKp1.js';
1
+ import { E as EventBus } from './brain-BYcK__Ym.js';
2
2
 
3
3
  /**
4
4
  * Long-running autonomous mission. A goal survives across sessions and
@@ -1,9 +1,9 @@
1
- import { W as HqRedactionPolicy, p as HqEventEnvelope, R as HqPublisher, l as HqClientIdentity, a2 as HqSocketFactory, G as GlobalMailbox } from '../global-mailbox-KByEFFBa.js';
2
- export { D as DEFAULT_HQ_REDACTION_POLICY, H as HQ_PROTOCOL_VERSION, a as HqAlertMessage, b as HqBrowserEventMessage, c as HqBrowserMessage, d as HqBrowserSnapshotMessage, e as HqClientCapability, f as HqClientCommandAckMessage, g as HqClientCommandPollMessage, h as HqClientEventMessage, i as HqClientHeartbeatPayload, j as HqClientHelloMessage, k as HqClientHelloPayload, m as HqClientKind, n as HqClientMessage, o as HqClientRecord, q as HqEventPayloadResult, r as HqEventType, s as HqFleetEventPayload, t as HqFleetSnapshotPayload, u as HqFleetSummary, v as HqGitSnapshotPayload, w as HqMailboxAgentStatus, x as HqMailboxAgentSummary, y as HqMailboxEventAction, z as HqMailboxEventPayload, A as HqMailboxMappingOptions, B as HqMailboxMessageSummary, C as HqMailboxMessageType, E as HqMailboxPriority, F as HqMailboxSnapshotOptions, I as HqMailboxSnapshotPayload, J as HqMailboxSummary, K as HqParseResult, L as HqPathPolicy, M as HqProjectIdentity, N as HqProjectRecord, O as HqProjectStatus, P as HqProtocolVersion, Q as HqPublishEventOptions, S as HqPublisherCommandHandler, T as HqPublisherCommandResult, U as HqPublisherOptions, V as HqQueuedCommand, X as HqServerCommandBatchMessage, Y as HqServerMessage, Z as HqSessionStartedPayload, _ as HqSessionStatus, $ as HqSessionStatusPayload, a0 as HqSessionSummary, a1 as HqSnapshot, a3 as HqSocketLike, a4 as HqSubagentSummary, a5 as HqToolArgsPolicy, a6 as HqToolCompletedPayload, a7 as HqToolStartedPayload, a8 as HqUsagePayload, a9 as HqWelcomePayload, aa as HqWorklistCounts, ab as HqWorklistSnapshotPayload, ac as HqWorkspaceKind, ad as createHqEventEnvelope, ae as createMailboxEventPayload, af as createMailboxSnapshotPayload, ag as createMailboxSnapshotPayloadFromMailbox, ah as mapMailboxAgentToHqSummary, ai as mapMailboxMessageToHqSummary, aj as parseHqEventPayload, ak as parseHqFrame } from '../global-mailbox-KByEFFBa.js';
3
- import { E as EventBus } from '../brain-69wzMKp1.js';
4
- import { w as HqClientConfig } from '../config-VKfOZ-6X.js';
1
+ import { W as HqRedactionPolicy, p as HqEventEnvelope, R as HqPublisher, l as HqClientIdentity, a2 as HqSocketFactory, G as GlobalMailbox } from '../global-mailbox-Bvrz1P3f.js';
2
+ export { D as DEFAULT_HQ_REDACTION_POLICY, H as HQ_PROTOCOL_VERSION, a as HqAlertMessage, b as HqBrowserEventMessage, c as HqBrowserMessage, d as HqBrowserSnapshotMessage, e as HqClientCapability, f as HqClientCommandAckMessage, g as HqClientCommandPollMessage, h as HqClientEventMessage, i as HqClientHeartbeatPayload, j as HqClientHelloMessage, k as HqClientHelloPayload, m as HqClientKind, n as HqClientMessage, o as HqClientRecord, q as HqEventPayloadResult, r as HqEventType, s as HqFleetEventPayload, t as HqFleetSnapshotPayload, u as HqFleetSummary, v as HqGitSnapshotPayload, w as HqMailboxAgentStatus, x as HqMailboxAgentSummary, y as HqMailboxEventAction, z as HqMailboxEventPayload, A as HqMailboxMappingOptions, B as HqMailboxMessageSummary, C as HqMailboxMessageType, E as HqMailboxPriority, F as HqMailboxSnapshotOptions, I as HqMailboxSnapshotPayload, J as HqMailboxSummary, K as HqParseResult, L as HqPathPolicy, M as HqProjectIdentity, N as HqProjectRecord, O as HqProjectStatus, P as HqProtocolVersion, Q as HqPublishEventOptions, S as HqPublisherCommandHandler, T as HqPublisherCommandResult, U as HqPublisherOptions, V as HqQueuedCommand, X as HqServerCommandBatchMessage, Y as HqServerMessage, Z as HqSessionStartedPayload, _ as HqSessionStatus, $ as HqSessionStatusPayload, a0 as HqSessionSummary, a1 as HqSnapshot, a3 as HqSocketLike, a4 as HqSubagentSummary, a5 as HqToolArgsPolicy, a6 as HqToolCompletedPayload, a7 as HqToolStartedPayload, a8 as HqUsagePayload, a9 as HqWelcomePayload, aa as HqWorklistCounts, ab as HqWorklistSnapshotPayload, ac as HqWorkspaceKind, ad as createHqEventEnvelope, ae as createMailboxEventPayload, af as createMailboxSnapshotPayload, ag as createMailboxSnapshotPayloadFromMailbox, ah as mapMailboxAgentToHqSummary, ai as mapMailboxMessageToHqSummary, aj as parseHqEventPayload, ak as parseHqFrame } from '../global-mailbox-Bvrz1P3f.js';
3
+ import { E as EventBus } from '../brain-BYcK__Ym.js';
4
+ import { x as HqClientConfig } from '../config-C_ae2k86.js';
5
5
  import '../mailbox-types-Ct2hJq0P.js';
6
- import '../context-C0U8B9NF.js';
6
+ import '../context-Dp87Bcaq.js';
7
7
 
8
8
  interface HqRedactOptions {
9
9
  policy?: Partial<HqRedactionPolicy>;
@@ -96,6 +96,11 @@ interface HqToken {
96
96
  */
97
97
  type HqBrowserToken = HqToken;
98
98
  /** On-disk shape of `<dataDir>/auth.json`. */
99
+ interface HqRuntimeFile {
100
+ url: string;
101
+ updatedAt: string;
102
+ pid?: number;
103
+ }
99
104
  interface HqAuthFile {
100
105
  version: typeof HQ_AUTH_FILE_VERSION;
101
106
  updatedAt: string;
@@ -114,6 +119,10 @@ interface HqAuthFile {
114
119
  declare function emptyHqAuthFile(): HqAuthFile;
115
120
  /** Path to `auth.json` under the given data directory. */
116
121
  declare function hqAuthFilePath(dataDir: string): string;
122
+ /** Path to the best-effort runtime endpoint marker under the given data directory. */
123
+ declare function hqRuntimeFilePath(dataDir: string): string;
124
+ declare function writeHqRuntimeFile(dataDir: string, file: Omit<HqRuntimeFile, 'updatedAt'>): Promise<void>;
125
+ declare function readHqRuntimeFileSync(dataDir: string): HqRuntimeFile | undefined;
117
126
  /**
118
127
  * Read `auth.json` from disk. Returns `emptyHqAuthFile()` when:
119
128
  * - the file does not exist (ENOENT), or
@@ -192,4 +201,4 @@ declare function watchHqAuthFile(dataDir: string, onChange: (file: HqAuthFile) =
192
201
  close: () => void;
193
202
  };
194
203
 
195
- export { type CreateGlobalMailboxOptions, type CreateHqPublisherOptions, type EnsureHqFirstRunAuthResult, HQ_AUTH_FILE_VERSION, type HqAuthFile, type HqBrowserToken, HqClientIdentity, HqEventEnvelope, HqPublisher, type HqPublisherEnvConfig, type HqRedactOptions, HqRedactionPolicy, type HqRedactionResult, HqSocketFactory, type HqToken, createGlobalMailbox, createHqPublisherFromEnv, defaultHqDataDir, emptyHqAuthFile, ensureHqFirstRunAuthFile, hqAuthFilePath, mintHqBrowserToken, mintHqToken, mutateHqAuthFile, readHqAuthFile, redactHqEvent, redactHqValue, resolveHqConfig, resolveHqConfigFromEnv, resolveHqDataDir, scrubAndTruncateHqPreview, summarizeHqToolArgs, watchHqAuthFile, writeHqAuthFile };
204
+ export { type CreateGlobalMailboxOptions, type CreateHqPublisherOptions, type EnsureHqFirstRunAuthResult, HQ_AUTH_FILE_VERSION, type HqAuthFile, type HqBrowserToken, HqClientIdentity, HqEventEnvelope, HqPublisher, type HqPublisherEnvConfig, type HqRedactOptions, HqRedactionPolicy, type HqRedactionResult, type HqRuntimeFile, HqSocketFactory, type HqToken, createGlobalMailbox, createHqPublisherFromEnv, defaultHqDataDir, emptyHqAuthFile, ensureHqFirstRunAuthFile, hqAuthFilePath, hqRuntimeFilePath, mintHqBrowserToken, mintHqToken, mutateHqAuthFile, readHqAuthFile, readHqRuntimeFileSync, redactHqEvent, redactHqValue, resolveHqConfig, resolveHqConfigFromEnv, resolveHqDataDir, scrubAndTruncateHqPreview, summarizeHqToolArgs, watchHqAuthFile, writeHqAuthFile, writeHqRuntimeFile };
package/dist/hq/index.js CHANGED
@@ -559,6 +559,8 @@ function mapMailboxMessageToHqSummary(message, options = {}) {
559
559
  const outcomePreview = previewText(message.outcome, previewLength, options.redactionPolicy);
560
560
  const task = taskSummary(message);
561
561
  return {
562
+ mailId: message.id,
563
+ // unique UUID per message record, used for deduplication
562
564
  messageId: message.id,
563
565
  from: message.from,
564
566
  to: message.to,
@@ -702,9 +704,15 @@ var HqPublisher = class {
702
704
  lastCommandId;
703
705
  connect() {
704
706
  if (this.socket !== null || this.stopped) return;
705
- const socket = this.socketFactory(toClientUrl(this.options.url, this.options.token), {
706
- ...this.options.token !== void 0 ? { token: this.options.token } : {}
707
- });
707
+ let socket;
708
+ try {
709
+ socket = this.socketFactory(toClientUrl(this.options.url, this.options.token), {
710
+ ...this.options.token !== void 0 ? { token: this.options.token } : {}
711
+ });
712
+ } catch {
713
+ this.scheduleReconnect();
714
+ return;
715
+ }
708
716
  this.socket = socket;
709
717
  const onOpen = () => {
710
718
  this.reconnectAttempt = 0;
@@ -843,6 +851,7 @@ var HqPublisher = class {
843
851
  startCommandPolling() {
844
852
  if (this.options.onCommand === void 0 || this.commandPollTimer !== null) return;
845
853
  this.commandPollTimer = setInterval(() => this.pollCommands(), this.options.commandPollIntervalMs ?? DEFAULT_COMMAND_POLL_INTERVAL_MS);
854
+ this.commandPollTimer.unref?.();
846
855
  }
847
856
  stopCommandPolling() {
848
857
  if (this.commandPollTimer === null) return;
@@ -901,6 +910,7 @@ var HqPublisher = class {
901
910
  this.reconnectTimer = null;
902
911
  this.connect();
903
912
  }, delay);
913
+ this.reconnectTimer.unref?.();
904
914
  }
905
915
  };
906
916
  async function atomicWrite(targetPath, content, opts = {}) {
@@ -1360,6 +1370,7 @@ var GlobalMailbox = class {
1360
1370
  name: input.name,
1361
1371
  source: input.source
1362
1372
  });
1373
+ this.publishHqMailboxSnapshot();
1363
1374
  }
1364
1375
  async clientHeartbeat(input) {
1365
1376
  const last = this._lastClientHeartbeat.get(input.clientId) ?? 0;
@@ -1381,6 +1392,7 @@ var GlobalMailbox = class {
1381
1392
  this._events?.emitCustom("mailbox.client_heartbeat", {
1382
1393
  clientId: input.clientId
1383
1394
  });
1395
+ this.publishHqMailboxSnapshot();
1384
1396
  }
1385
1397
  async getClientStatuses() {
1386
1398
  await this._ensureClientRegistry();
@@ -1602,7 +1614,7 @@ var GlobalMailbox = class {
1602
1614
  obj[id] = agent;
1603
1615
  }
1604
1616
  const tmp = `${this.registryPath}.${randomUUID().slice(0, 8)}.tmp`;
1605
- await fsp.writeFile(tmp, JSON.stringify(obj, null, 2), "utf8");
1617
+ await fsp.writeFile(tmp, JSON.stringify(obj), "utf8");
1606
1618
  await fsp.rename(tmp, this.registryPath);
1607
1619
  }
1608
1620
  // ── Client registry internals ───────────────────────────────────────────
@@ -1647,7 +1659,7 @@ var GlobalMailbox = class {
1647
1659
  obj[id] = client;
1648
1660
  }
1649
1661
  const tmp = `${this.clientRegistryPath}.${randomUUID().slice(0, 8)}.tmp`;
1650
- await fsp.writeFile(tmp, JSON.stringify(obj, null, 2), "utf8");
1662
+ await fsp.writeFile(tmp, JSON.stringify(obj), "utf8");
1651
1663
  await fsp.rename(tmp, this.clientRegistryPath);
1652
1664
  }
1653
1665
  };
@@ -1669,6 +1681,40 @@ function emptyHqAuthFile() {
1669
1681
  function hqAuthFilePath(dataDir) {
1670
1682
  return path3.join(dataDir, "auth.json");
1671
1683
  }
1684
+ function hqRuntimeFilePath(dataDir) {
1685
+ return path3.join(dataDir, "runtime.json");
1686
+ }
1687
+ async function writeHqRuntimeFile(dataDir, file) {
1688
+ const payload = {
1689
+ ...file,
1690
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1691
+ };
1692
+ await atomicWrite(hqRuntimeFilePath(dataDir), `${JSON.stringify(payload, null, 2)}
1693
+ `, { mode: 384 });
1694
+ }
1695
+ function isProcessAlive(pid) {
1696
+ if (!Number.isInteger(pid) || pid <= 0) return false;
1697
+ try {
1698
+ process.kill(pid, 0);
1699
+ return true;
1700
+ } catch {
1701
+ return false;
1702
+ }
1703
+ }
1704
+ function readHqRuntimeFileSync(dataDir) {
1705
+ try {
1706
+ const parsed = JSON.parse(syncFs.readFileSync(hqRuntimeFilePath(dataDir), "utf8"));
1707
+ if (typeof parsed.url !== "string" || parsed.url.trim().length === 0) return void 0;
1708
+ if (typeof parsed.pid === "number" && !isProcessAlive(parsed.pid)) return void 0;
1709
+ return {
1710
+ url: parsed.url,
1711
+ updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : "",
1712
+ ...typeof parsed.pid === "number" ? { pid: parsed.pid } : {}
1713
+ };
1714
+ } catch {
1715
+ return void 0;
1716
+ }
1717
+ }
1672
1718
  async function readHqAuthFile(dataDir, opts = {}) {
1673
1719
  const file = hqAuthFilePath(dataDir);
1674
1720
  let raw;
@@ -1813,12 +1859,13 @@ function resolveHqConfig(options = {}) {
1813
1859
  const enabled = envEnabledRaw !== void 0 && envEnabledRaw.length > 0 ? envEnabledRaw !== "0" : fileConfig?.enabled;
1814
1860
  const dataDir = resolveHqDataDir(fileConfig?.dataDir, env);
1815
1861
  const token = envToken || configToken || readFirstClientTokenFromAuthFile(dataDir);
1862
+ const runtimeUrl = readHqRuntimeFileSync(dataDir)?.url.trim();
1816
1863
  const url = envUrl || configUrl;
1817
1864
  if (!url) {
1818
1865
  if (enabled === false) return void 0;
1819
- if (enabled === true || token) {
1866
+ if (enabled === true || token || runtimeUrl) {
1820
1867
  return {
1821
- url: "http://localhost:3499",
1868
+ url: runtimeUrl || "http://127.0.0.1:3499",
1822
1869
  enabled: true,
1823
1870
  ...token ? { token } : {}
1824
1871
  };
@@ -1879,6 +1926,6 @@ function createGlobalMailbox(options) {
1879
1926
  return new GlobalMailbox(options.projectDir, options.events, options.hqPublisher);
1880
1927
  }
1881
1928
 
1882
- export { DEFAULT_HQ_REDACTION_POLICY, HQ_AUTH_FILE_VERSION, HQ_PROTOCOL_VERSION, HqPublisher, createGlobalMailbox, createHqEventEnvelope, createHqPublisherFromEnv, createMailboxEventPayload, createMailboxSnapshotPayload, createMailboxSnapshotPayloadFromMailbox, defaultHqDataDir, emptyHqAuthFile, ensureHqFirstRunAuthFile, hqAuthFilePath, mapMailboxAgentToHqSummary, mapMailboxMessageToHqSummary, mintHqBrowserToken, mintHqToken, mutateHqAuthFile, parseHqEventPayload, parseHqFrame, readHqAuthFile, redactHqEvent, redactHqValue, resolveHqConfig, resolveHqConfigFromEnv, resolveHqDataDir, scrubAndTruncateHqPreview, summarizeHqToolArgs, watchHqAuthFile, writeHqAuthFile };
1929
+ export { DEFAULT_HQ_REDACTION_POLICY, HQ_AUTH_FILE_VERSION, HQ_PROTOCOL_VERSION, HqPublisher, createGlobalMailbox, createHqEventEnvelope, createHqPublisherFromEnv, createMailboxEventPayload, createMailboxSnapshotPayload, createMailboxSnapshotPayloadFromMailbox, defaultHqDataDir, emptyHqAuthFile, ensureHqFirstRunAuthFile, hqAuthFilePath, hqRuntimeFilePath, mapMailboxAgentToHqSummary, mapMailboxMessageToHqSummary, mintHqBrowserToken, mintHqToken, mutateHqAuthFile, parseHqEventPayload, parseHqFrame, readHqAuthFile, readHqRuntimeFileSync, redactHqEvent, redactHqValue, resolveHqConfig, resolveHqConfigFromEnv, resolveHqDataDir, scrubAndTruncateHqPreview, summarizeHqToolArgs, watchHqAuthFile, writeHqAuthFile, writeHqRuntimeFile };
1883
1930
  //# sourceMappingURL=index.js.map
1884
1931
  //# sourceMappingURL=index.js.map