@wrongstack/core 0.265.1 → 0.268.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-DrkBxszZ.d.ts → agent-bridge-UhojbpWx.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-DM2pP-B6.d.ts → agent-subagent-runner-Bvtf1o9K.d.ts} +25 -7
  3. package/dist/{brain-BXd_61kQ.d.ts → brain-69wzMKp1.d.ts} +73 -1
  4. package/dist/{compactor-B8pOf45Y.d.ts → compactor-CBQAJoDc.d.ts} +19 -1
  5. package/dist/{config-BMCj_XDs.d.ts → config-VKfOZ-6X.d.ts} +122 -3
  6. package/dist/{context-MRk5PhNv.d.ts → context-C0U8B9NF.d.ts} +88 -1
  7. package/dist/coordination/index.d.ts +57 -161
  8. package/dist/coordination/index.js +471 -177
  9. package/dist/coordination/index.js.map +1 -1
  10. package/dist/defaults/index.d.ts +26 -25
  11. package/dist/defaults/index.js +1818 -844
  12. package/dist/defaults/index.js.map +1 -1
  13. package/dist/execution/index.d.ts +72 -16
  14. package/dist/execution/index.js +1270 -265
  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 +7 -6
  18. package/dist/global-mailbox-KByEFFBa.d.ts +663 -0
  19. package/dist/{goal-preamble-DvHDSKSe.d.ts → goal-preamble-CrYjmdw4.d.ts} +28 -11
  20. package/dist/{goal-store-DtLMySNb.d.ts → goal-store-Y_zdLZ3q.d.ts} +1 -1
  21. package/dist/hq/index.d.ts +195 -0
  22. package/dist/hq/index.js +1884 -0
  23. package/dist/hq/index.js.map +1 -0
  24. package/dist/index-BfaS-f_m.d.ts +82 -0
  25. package/dist/{index-B-ch8K9C.d.ts → index-CtQnmkaS.d.ts} +8 -8
  26. package/dist/{index-CEDeNodM.d.ts → index-gCv830d7.d.ts} +5 -5
  27. package/dist/index.d.ts +124 -47
  28. package/dist/index.js +5600 -2662
  29. package/dist/index.js.map +1 -1
  30. package/dist/infrastructure/index.d.ts +6 -6
  31. package/dist/infrastructure/index.js +117 -19
  32. package/dist/infrastructure/index.js.map +1 -1
  33. package/dist/kernel/index.d.ts +10 -9
  34. package/dist/kernel/index.js.map +1 -1
  35. package/dist/{pipeline-DPDxH_7m.d.ts → mailbox-types-Ct2hJq0P.d.ts} +1 -244
  36. package/dist/{mcp-servers-2x4w6Jn9.d.ts → mcp-servers-HT3Fi7Bl.d.ts} +10 -4
  37. package/dist/models/index.d.ts +5 -5
  38. package/dist/models/index.js +33 -3
  39. package/dist/models/index.js.map +1 -1
  40. package/dist/{models-registry-DmJlKuNp.d.ts → models-registry-Bvcl3Vaa.d.ts} +1 -1
  41. package/dist/{multi-agent-coordinator-DyCkCZnU.d.ts → multi-agent-coordinator-BACjsmkC.d.ts} +1 -1
  42. package/dist/{null-fleet-bus-CG9QY2aP.d.ts → null-fleet-bus-DA7fvhUg.d.ts} +14 -9
  43. package/dist/observability/index.d.ts +2 -2
  44. package/dist/{parallel-eternal-engine-Jw9uhEoT.d.ts → parallel-eternal-engine-Ci71gYu_.d.ts} +11 -15
  45. package/dist/{path-resolver-Dy2ej-gE.d.ts → path-resolver-O1IJnmKE.d.ts} +4 -3
  46. package/dist/{permission-B9SB45lp.d.ts → permission-Bd-57Lbl.d.ts} +1 -1
  47. package/dist/{permission-policy-CkjSXabK.d.ts → permission-policy-uNXC6Kge.d.ts} +2 -3
  48. package/dist/pipeline-BDNvENyV.d.ts +245 -0
  49. package/dist/{plan-templates-CzD9GnAU.d.ts → plan-templates-EMsalEtN.d.ts} +5 -5
  50. package/dist/{llm-selector-C0tfTCUe.d.ts → provider-model-resolve-CEb9x886.d.ts} +40 -3
  51. package/dist/{provider-runner-DMa70ODu.d.ts → provider-runner-DWJbpo70.d.ts} +3 -3
  52. package/dist/{retry-policy-CN0khdlj.d.ts → retry-policy-C3s_lvdK.d.ts} +1 -1
  53. package/dist/sdd/index.d.ts +9 -8
  54. package/dist/sdd/index.js +44 -14
  55. package/dist/sdd/index.js.map +1 -1
  56. package/dist/{secret-vault-B2yw84VT.d.ts → secret-vault-Cgduf5xL.d.ts} +2 -2
  57. package/dist/security/index.d.ts +5 -67
  58. package/dist/security/index.js +129 -99
  59. package/dist/security/index.js.map +1 -1
  60. package/dist/{selector-CzHh_igB.d.ts → selector-47LBnBVk.d.ts} +1 -1
  61. package/dist/{session-event-bridge-BUI6Jf-4.d.ts → session-event-bridge-Cw7oqmW2.d.ts} +1 -1
  62. package/dist/{session-reader-CMgdMSRP.d.ts → session-reader-DD4v2Obw.d.ts} +1 -1
  63. package/dist/storage/index.d.ts +14 -12
  64. package/dist/storage/index.js +144 -120
  65. package/dist/storage/index.js.map +1 -1
  66. package/dist/tools/index.d.ts +4 -2
  67. package/dist/tools/index.js +166 -31
  68. package/dist/tools/index.js.map +1 -1
  69. package/dist/types/index.d.ts +20 -19
  70. package/dist/types/index.js +1358 -476
  71. package/dist/types/index.js.map +1 -1
  72. package/dist/utils/index.d.ts +472 -405
  73. package/dist/utils/index.js +2321 -1193
  74. package/dist/utils/index.js.map +1 -1
  75. package/package.json +5 -1
@@ -1,4 +1,4 @@
1
- import { P as Provider, M as Message } from '../context-MRk5PhNv.js';
1
+ import { P as Provider, M as Message } from '../context-C0U8B9NF.js';
2
2
 
3
3
  /**
4
4
  * Prompt refinement ("did you mean this?").
@@ -1,8 +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-CEDeNodM.js';
2
- import '../context-MRk5PhNv.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-gCv830d7.js';
2
+ import '../context-C0U8B9NF.js';
3
3
  import '../logger-B63L5bTg.js';
4
- import '../pipeline-DPDxH_7m.js';
5
- import '../config-BMCj_XDs.js';
4
+ import '../pipeline-BDNvENyV.js';
5
+ import '../mailbox-types-Ct2hJq0P.js';
6
+ import '../config-VKfOZ-6X.js';
6
7
  import '../observability-D-HZN_mF.js';
7
- import '../brain-BXd_61kQ.js';
8
- import '../permission-B9SB45lp.js';
8
+ import '../brain-69wzMKp1.js';
9
+ import '../permission-Bd-57Lbl.js';
@@ -0,0 +1,663 @@
1
+ import { E as EventBus } from './brain-69wzMKp1.js';
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
+
4
+ declare const HQ_PROTOCOL_VERSION: 1;
5
+ type HqProtocolVersion = typeof HQ_PROTOCOL_VERSION;
6
+ type HqClientKind = 'tui' | 'repl' | 'webui' | 'cli' | 'unknown';
7
+ type HqWorkspaceKind = 'git' | 'directory' | 'unknown';
8
+ type HqProjectStatus = 'active' | 'idle' | 'stale' | 'error';
9
+ type HqClientCapability = 'telemetry.publish' | 'session.summary' | 'fleet.summary' | 'mailbox.summary' | 'control.receive';
10
+ type HqToolArgsPolicy = 'none' | 'summary' | 'redacted';
11
+ type HqPathPolicy = 'none' | 'project-relative' | 'redacted' | 'full';
12
+ interface HqRedactionPolicy {
13
+ rawContent: boolean;
14
+ toolArgs: HqToolArgsPolicy;
15
+ paths: HqPathPolicy;
16
+ }
17
+ declare const DEFAULT_HQ_REDACTION_POLICY: HqRedactionPolicy;
18
+ interface HqClientIdentity {
19
+ clientId: string;
20
+ kind: HqClientKind;
21
+ version?: string;
22
+ machineId: string;
23
+ hostname?: string;
24
+ pid?: number;
25
+ startedAt: string;
26
+ }
27
+ interface HqProjectIdentity {
28
+ projectId: string;
29
+ projectRoot: string;
30
+ projectName: string;
31
+ gitRemote?: string;
32
+ gitBranch?: string;
33
+ machineId: string;
34
+ workspaceKind: HqWorkspaceKind;
35
+ }
36
+ interface HqClientHelloPayload {
37
+ protocolVersion: HqProtocolVersion;
38
+ client: HqClientIdentity;
39
+ project: HqProjectIdentity;
40
+ capabilities: readonly HqClientCapability[];
41
+ }
42
+ interface HqWelcomePayload {
43
+ type: 'hq.welcome';
44
+ protocolVersion: HqProtocolVersion;
45
+ serverTime: string;
46
+ acceptedCapabilities: readonly HqClientCapability[];
47
+ redactionPolicy: HqRedactionPolicy;
48
+ }
49
+ interface HqEventEnvelope<TPayload = unknown> {
50
+ id: string;
51
+ type: HqEventType | (string & {});
52
+ schemaVersion: HqProtocolVersion;
53
+ timestamp: string;
54
+ clientId: string;
55
+ projectId: string;
56
+ sessionId?: string;
57
+ runId?: string;
58
+ seq: number;
59
+ payload: TPayload;
60
+ }
61
+ type HqEventType = 'client.hello' | 'client.heartbeat' | 'session.started' | 'session.status' | 'session.usage' | 'tool.started' | 'tool.completed' | 'fleet.snapshot' | 'fleet.event' | 'mailbox.snapshot' | 'mailbox.event' | 'worklist.snapshot' | 'git.snapshot';
62
+ interface HqClientHeartbeatPayload {
63
+ uptimeMs: number;
64
+ activeSessionId?: string;
65
+ activeRunId?: string;
66
+ status: HqProjectStatus;
67
+ activeSubagents?: number;
68
+ queuedTasks?: number;
69
+ }
70
+ type HqSessionStatus = 'idle' | 'running' | 'paused' | 'completed' | 'failed';
71
+ interface HqSessionStartedPayload {
72
+ sessionId: string;
73
+ provider?: string;
74
+ model?: string;
75
+ startedAt: string;
76
+ }
77
+ interface HqSessionStatusPayload {
78
+ status: HqSessionStatus;
79
+ phase?: string;
80
+ message?: string;
81
+ }
82
+ interface HqUsagePayload {
83
+ inputTokens?: number;
84
+ outputTokens?: number;
85
+ totalTokens?: number;
86
+ costUsd?: number;
87
+ durationMs?: number;
88
+ }
89
+ interface HqToolStartedPayload {
90
+ toolName: string;
91
+ capabilities?: readonly string[];
92
+ risk?: string;
93
+ inputSummary?: unknown;
94
+ }
95
+ interface HqToolCompletedPayload {
96
+ toolName: string;
97
+ status: 'success' | 'error' | 'timeout' | 'cancelled';
98
+ durationMs: number;
99
+ outputSummary?: unknown;
100
+ errorClass?: string;
101
+ }
102
+ interface HqSubagentSummary {
103
+ subagentId: string;
104
+ role?: string;
105
+ status: 'pending' | 'running' | 'idle' | 'completed' | 'failed' | 'stopped';
106
+ task?: string;
107
+ currentTool?: string;
108
+ runtimeMs?: number;
109
+ costUsd?: number;
110
+ lastActivityAt?: string;
111
+ }
112
+ interface HqFleetSnapshotPayload {
113
+ runId: string;
114
+ activeSubagents: number;
115
+ queuedTasks: number;
116
+ completedTasks: number;
117
+ failedTasks: number;
118
+ totalCostUsd?: number;
119
+ subagents: readonly HqSubagentSummary[];
120
+ }
121
+ interface HqFleetEventPayload {
122
+ runId: string;
123
+ subagentId?: string;
124
+ event: string;
125
+ summary?: string;
126
+ data?: unknown;
127
+ }
128
+ type HqMailboxMessageType = 'note' | 'ask' | 'assign' | 'steer' | 'btw' | 'broadcast' | 'status' | 'result' | 'control';
129
+ type HqMailboxPriority = 'low' | 'normal' | 'high';
130
+ type HqMailboxAgentStatus = 'idle' | 'running' | 'streaming' | 'waiting_user' | 'error' | 'offline';
131
+ interface HqMailboxMessageSummary {
132
+ messageId: string;
133
+ from: string;
134
+ to: string;
135
+ type: HqMailboxMessageType;
136
+ subject: string;
137
+ priority: HqMailboxPriority;
138
+ timestamp: string;
139
+ replyTo?: string;
140
+ senderSessionId?: string;
141
+ completed: boolean;
142
+ completedBy?: string;
143
+ completedAt?: string;
144
+ unreadCount?: number;
145
+ readCount?: number;
146
+ hasBody: boolean;
147
+ bodyPreview?: string;
148
+ outcomePreview?: string;
149
+ task?: {
150
+ taskId?: string;
151
+ agentRole?: string;
152
+ agentName?: string;
153
+ status?: 'pending' | 'in_progress' | 'completed' | 'failed';
154
+ };
155
+ }
156
+ interface HqMailboxAgentSummary {
157
+ agentId: string;
158
+ name: string;
159
+ role?: string;
160
+ sessionId: string;
161
+ status: HqMailboxAgentStatus;
162
+ currentTool?: string;
163
+ currentTask?: string;
164
+ iterations: number;
165
+ toolCalls: number;
166
+ lastActivityAt: string;
167
+ lastSeenAt: string;
168
+ online: boolean;
169
+ source?: 'cli' | 'webui' | 'mcp' | 'acp';
170
+ }
171
+ interface HqMailboxSnapshotPayload {
172
+ mailboxId: string;
173
+ scope: 'project' | 'global';
174
+ messages: readonly HqMailboxMessageSummary[];
175
+ agents: readonly HqMailboxAgentSummary[];
176
+ totals: {
177
+ messages: number;
178
+ unread: number;
179
+ incomplete: number;
180
+ highPriority: number;
181
+ onlineAgents: number;
182
+ };
183
+ }
184
+ interface HqMailboxEventPayload {
185
+ mailboxId: string;
186
+ action: 'message.sent' | 'message.read' | 'message.completed' | 'message.updated' | 'agent.registered' | 'agent.heartbeat' | 'agent.offline';
187
+ message?: HqMailboxMessageSummary;
188
+ agent?: HqMailboxAgentSummary;
189
+ summary?: string;
190
+ }
191
+ interface HqWorklistSnapshotPayload {
192
+ todos?: HqWorklistCounts;
193
+ tasks?: HqWorklistCounts;
194
+ plans?: HqWorklistCounts;
195
+ activeItem?: string;
196
+ }
197
+ interface HqWorklistCounts {
198
+ total: number;
199
+ pending: number;
200
+ inProgress: number;
201
+ completed: number;
202
+ failed?: number;
203
+ }
204
+ interface HqGitSnapshotPayload {
205
+ branch?: string;
206
+ dirtyFiles?: number;
207
+ stagedFiles?: number;
208
+ ahead?: number;
209
+ behind?: number;
210
+ }
211
+ interface HqClientRecord {
212
+ clientId: string;
213
+ kind: HqClientKind;
214
+ machineId: string;
215
+ hostname?: string;
216
+ pid?: number;
217
+ version?: string;
218
+ connected: boolean;
219
+ connectedAt?: string;
220
+ lastSeenAt: string;
221
+ projectId: string;
222
+ sessionId?: string;
223
+ capabilities: readonly HqClientCapability[];
224
+ }
225
+ interface HqProjectRecord {
226
+ projectId: string;
227
+ projectName: string;
228
+ projectRootDisplay: string;
229
+ machineIds: readonly string[];
230
+ gitBranch?: string;
231
+ activeClients: number;
232
+ activeSessions: number;
233
+ activeSubagents: number;
234
+ totalCostUsd: number;
235
+ lastActivityAt: string;
236
+ status: HqProjectStatus;
237
+ }
238
+ interface HqSessionSummary {
239
+ sessionId: string;
240
+ projectId: string;
241
+ clientId: string;
242
+ status: HqSessionStatus;
243
+ provider?: string;
244
+ model?: string;
245
+ startedAt?: string;
246
+ lastActivityAt: string;
247
+ costUsd?: number;
248
+ }
249
+ interface HqFleetSummary {
250
+ runId: string;
251
+ projectId: string;
252
+ clientId: string;
253
+ activeSubagents: number;
254
+ queuedTasks: number;
255
+ completedTasks: number;
256
+ failedTasks: number;
257
+ totalCostUsd?: number;
258
+ lastActivityAt: string;
259
+ }
260
+ interface HqMailboxSummary {
261
+ mailboxId: string;
262
+ projectId: string;
263
+ scope: 'project' | 'global';
264
+ messageCount: number;
265
+ unreadCount: number;
266
+ incompleteCount: number;
267
+ highPriorityCount: number;
268
+ onlineAgentCount: number;
269
+ lastActivityAt: string;
270
+ }
271
+ interface HqSnapshot {
272
+ generatedAt: string;
273
+ clients: readonly HqClientRecord[];
274
+ projects: readonly HqProjectRecord[];
275
+ sessions: readonly HqSessionSummary[];
276
+ fleets: readonly HqFleetSummary[];
277
+ mailboxes: readonly HqMailboxSummary[];
278
+ totals: {
279
+ activeProjects: number;
280
+ activeClients: number;
281
+ activeSessions: number;
282
+ activeSubagents: number;
283
+ unreadMailboxMessages: number;
284
+ incompleteMailboxMessages: number;
285
+ totalCostUsd: number;
286
+ };
287
+ }
288
+ interface HqBrowserSnapshotMessage {
289
+ type: 'hq.snapshot';
290
+ snapshot: HqSnapshot;
291
+ }
292
+ interface HqBrowserEventMessage<TPayload = unknown> {
293
+ type: 'hq.event';
294
+ event: HqEventEnvelope<TPayload>;
295
+ }
296
+ interface HqAlertMessage {
297
+ type: 'hq.alert';
298
+ severity: 'info' | 'warn' | 'error';
299
+ message: string;
300
+ timestamp: string;
301
+ }
302
+ type HqBrowserMessage = HqBrowserSnapshotMessage | HqBrowserEventMessage | HqAlertMessage;
303
+ interface HqClientHelloMessage {
304
+ type: 'client.hello';
305
+ payload: HqClientHelloPayload;
306
+ }
307
+ interface HqClientEventMessage<TPayload = unknown> {
308
+ type: 'client.event';
309
+ event: HqEventEnvelope<TPayload>;
310
+ }
311
+ interface HqClientCommandPollMessage {
312
+ type: 'client.command_poll';
313
+ clientId: string;
314
+ projectId: string;
315
+ afterCommandId?: string;
316
+ limit?: number;
317
+ }
318
+ interface HqClientCommandAckMessage {
319
+ type: 'client.command_ack';
320
+ clientId: string;
321
+ projectId: string;
322
+ commandId: string;
323
+ status: 'accepted' | 'completed' | 'failed' | 'rejected';
324
+ message?: string;
325
+ }
326
+ interface HqQueuedCommand {
327
+ commandId: string;
328
+ type: string;
329
+ createdAt: string;
330
+ payload: unknown;
331
+ requiresAck?: boolean;
332
+ }
333
+ interface HqServerCommandBatchMessage {
334
+ type: 'hq.command_batch';
335
+ commands: readonly HqQueuedCommand[];
336
+ }
337
+ type HqClientMessage = HqClientHelloMessage | HqClientEventMessage | HqClientCommandPollMessage | HqClientCommandAckMessage;
338
+ type HqServerMessage = HqServerCommandBatchMessage | HqWelcomePayload;
339
+ /**
340
+ * Discriminated parse result for {@link parseHqFrame}. The `reason` field
341
+ * is only present when `ok` is `false`; consumers should narrow on `ok`
342
+ * before accessing `frame` or `reason`.
343
+ */
344
+ type HqParseResult = {
345
+ ok: true;
346
+ frame: HqClientMessage;
347
+ } | {
348
+ ok: false;
349
+ reason: 'invalid-json' | 'unknown-type' | 'malformed';
350
+ };
351
+ /**
352
+ * Strictly parse a raw client → server frame into a {@link HqParseResult}.
353
+ *
354
+ * Validates, in order:
355
+ * 1. JSON syntax (`invalid-json` on failure)
356
+ * 2. Top-level object with string `type` discriminator
357
+ * 3. `type` is one of {@link HqClientMessage} union members (`unknown-type`)
358
+ * 4. Per-type field-shape presence checks (`malformed` on failure)
359
+ *
360
+ * On success, `frame` is narrowed to {@link HqClientMessage} and consumers
361
+ * can switch on `frame.type` for type-safe access to per-union-member
362
+ * fields without `as` casts.
363
+ */
364
+ declare function parseHqFrame(raw: string | Buffer): HqParseResult;
365
+ /**
366
+ * Validate the `payload` field of a {@link HqEventEnvelope} for known
367
+ * event types. Returns `{ ok: true, payload }` with a narrowed payload
368
+ * type when the event type has a registered shape guard and the payload
369
+ * matches it; `{ ok: true, payload: unknown }` for event types that the
370
+ * server does not yet validate; or `{ ok: false, reason }` when the
371
+ * payload fails the registered guard.
372
+ *
373
+ * Use this after {@link parseHqFrame} has produced a valid frame, when
374
+ * the frame is `client.event` and the server is about to consume the
375
+ * event payload.
376
+ */
377
+ type HqEventPayloadResult<T> = {
378
+ ok: true;
379
+ payload: T;
380
+ } | {
381
+ ok: false;
382
+ reason: 'unknown-event-type' | 'malformed-payload';
383
+ };
384
+ declare function parseHqEventPayload(eventType: string, payload: unknown): HqEventPayloadResult<unknown>;
385
+ declare function createHqEventEnvelope<TPayload>(input: {
386
+ id: string;
387
+ type: HqEventType | (string & {});
388
+ timestamp: string;
389
+ clientId: string;
390
+ projectId: string;
391
+ seq: number;
392
+ payload: TPayload;
393
+ sessionId?: string;
394
+ runId?: string;
395
+ }): HqEventEnvelope<TPayload>;
396
+
397
+ interface HqMailboxMappingOptions {
398
+ mailboxId: string;
399
+ scope?: 'project' | 'global';
400
+ limit?: number;
401
+ previewLength?: number;
402
+ redactionPolicy?: Partial<HqRedactionPolicy>;
403
+ }
404
+ interface HqMailboxSnapshotOptions extends HqMailboxMappingOptions {
405
+ includeCompleted?: boolean;
406
+ }
407
+ type HqMailboxEventAction = HqMailboxEventPayload['action'];
408
+ declare function mapMailboxMessageToHqSummary(message: MailboxMessage, options?: Pick<HqMailboxMappingOptions, 'previewLength' | 'redactionPolicy'>): HqMailboxMessageSummary;
409
+ declare function mapMailboxAgentToHqSummary(agent: MailboxAgentStatus): HqMailboxAgentSummary;
410
+ declare function createMailboxSnapshotPayload(messages: readonly MailboxMessage[], agents: readonly MailboxAgentStatus[], options: HqMailboxSnapshotOptions): HqMailboxSnapshotPayload;
411
+ declare function createMailboxSnapshotPayloadFromMailbox(mailbox: Pick<Mailbox, 'query' | 'getAgentStatuses'>, options: HqMailboxSnapshotOptions): Promise<HqMailboxSnapshotPayload>;
412
+ declare function createMailboxEventPayload(input: {
413
+ mailboxId: string;
414
+ action: HqMailboxEventAction;
415
+ message?: MailboxMessage;
416
+ agent?: MailboxAgentStatus;
417
+ summary?: string;
418
+ previewLength?: number;
419
+ redactionPolicy?: Partial<HqRedactionPolicy>;
420
+ }): HqMailboxEventPayload;
421
+
422
+ interface HqSocketLike {
423
+ readyState: number;
424
+ send(data: string): void;
425
+ close(code?: number, reason?: string): void;
426
+ addEventListener?(type: 'open' | 'close' | 'error' | 'message', listener: (event: unknown) => void): void;
427
+ removeEventListener?(type: 'open' | 'close' | 'error' | 'message', listener: (event: unknown) => void): void;
428
+ on?(type: 'open' | 'close' | 'error' | 'message', listener: (event: unknown) => void): void;
429
+ off?(type: 'open' | 'close' | 'error' | 'message', listener: (event: unknown) => void): void;
430
+ }
431
+ type HqSocketFactory = (url: string, init: {
432
+ token?: string;
433
+ }) => HqSocketLike;
434
+ interface HqPublisherCommandResult {
435
+ commandId: string;
436
+ status: 'accepted' | 'completed' | 'failed' | 'rejected';
437
+ message?: string;
438
+ }
439
+ type HqPublisherCommandHandler = (command: HqQueuedCommand) => void | HqPublisherCommandResult | Promise<void | HqPublisherCommandResult>;
440
+ interface HqPublisherOptions {
441
+ url: string;
442
+ token?: string;
443
+ client: HqClientIdentity;
444
+ project: HqProjectIdentity;
445
+ capabilities?: readonly HqClientCapability[];
446
+ socketFactory?: HqSocketFactory;
447
+ now?: () => string;
448
+ idFactory?: () => string;
449
+ reconnect?: boolean;
450
+ reconnectBaseMs?: number;
451
+ reconnectMaxMs?: number;
452
+ maxQueuedMessages?: number;
453
+ redactionPolicy?: Partial<HqRedactionPolicy>;
454
+ commandPollIntervalMs?: number;
455
+ commandPollLimit?: number;
456
+ onCommand?: HqPublisherCommandHandler;
457
+ }
458
+ interface HqPublishEventOptions {
459
+ type: HqEventType | (string & {});
460
+ payload: unknown;
461
+ sessionId?: string;
462
+ runId?: string;
463
+ timestamp?: string;
464
+ }
465
+ declare class HqPublisher {
466
+ private readonly options;
467
+ private readonly socketFactory;
468
+ private readonly now;
469
+ private readonly idFactory;
470
+ private readonly capabilities;
471
+ private readonly reconnect;
472
+ private readonly reconnectBaseMs;
473
+ private readonly reconnectMaxMs;
474
+ private readonly maxQueuedMessages;
475
+ private socket;
476
+ private seq;
477
+ private queue;
478
+ private stopped;
479
+ private reconnectAttempt;
480
+ private reconnectTimer;
481
+ private commandPollTimer;
482
+ private lastCommandId;
483
+ constructor(options: HqPublisherOptions);
484
+ connect(): void;
485
+ close(): void;
486
+ publishEvent<TPayload>(options: HqPublishEventOptions & {
487
+ payload: TPayload;
488
+ }): HqEventEnvelope<TPayload>;
489
+ publishMailboxSnapshot(mailbox: Pick<Mailbox, 'query' | 'getAgentStatuses'>, options: Omit<HqMailboxSnapshotOptions, 'redactionPolicy'> & {
490
+ sessionId?: string;
491
+ timestamp?: string;
492
+ }): Promise<HqEventEnvelope<HqMailboxSnapshotPayload>>;
493
+ publishMailboxEvent(input: {
494
+ mailboxId: string;
495
+ action: HqMailboxEventAction;
496
+ message?: MailboxMessage;
497
+ agent?: MailboxAgentStatus;
498
+ summary?: string;
499
+ previewLength?: number;
500
+ sessionId?: string;
501
+ timestamp?: string;
502
+ }): HqEventEnvelope<HqMailboxEventPayload>;
503
+ pollCommands(): void;
504
+ ackCommand(result: HqPublisherCommandResult): void;
505
+ private sendHello;
506
+ private sendFrame;
507
+ private enqueue;
508
+ private flushQueue;
509
+ private startCommandPolling;
510
+ private stopCommandPolling;
511
+ private handleServerMessage;
512
+ private parseServerMessage;
513
+ private extractMessageData;
514
+ private handleCommandBatch;
515
+ private scheduleReconnect;
516
+ }
517
+
518
+ /**
519
+ * GlobalMailbox — project-level inter-agent mailbox with cross-session support.
520
+ *
521
+ * Stores messages at `~/.wrongstack/projects/<slug>/_mailbox.jsonl` so all
522
+ * sessions (terminals, WebUIs) working on the same project share one inbox.
523
+ *
524
+ * Features:
525
+ * - Agent registration + heartbeat (agents go stale after 60s without heartbeat)
526
+ * - Per-recipient read receipts (readBy[agentId] = ISO8601)
527
+ * - Atomic file-locking for concurrent multi-process writes
528
+ * - Unread count for new-mail notifications
529
+ * - Online agent list
530
+ *
531
+ * @module GlobalMailbox
532
+ */
533
+
534
+ /**
535
+ * Derive the project-level mailbox directory path.
536
+ *
537
+ * Delegates to the CANONICAL `projectSlug()` from wstack-paths so every
538
+ * surface (CLI, TUI, WebUI, mailbox tool, loop checker) lands in the exact
539
+ * same `~/.wrongstack/projects/<slug>/` directory. A previous inline copy
540
+ * skipped the leading/trailing-hyphen strip, which silently split agents
541
+ * working on projects with non-alphanumeric name edges into TWO mailboxes.
542
+ *
543
+ * @param projectRoot — absolute path to the project root
544
+ * @param globalRoot — `~/.wrongstack` (or custom global root)
545
+ */
546
+ declare function resolveProjectDir(projectRoot: string, globalRoot: string): string;
547
+ declare class GlobalMailbox implements Mailbox {
548
+ /** Path to the JSONL message file. */
549
+ readonly messagePath: string;
550
+ /** Path to the JSON agent registry file. */
551
+ readonly registryPath: string;
552
+ /** Path to the JSON client registry file. */
553
+ readonly clientRegistryPath: string;
554
+ /** Optional event bus for emitting agent registration/heartbeat events. */
555
+ private readonly _events?;
556
+ /** Optional HQ publisher for cross-project command-center telemetry. */
557
+ private readonly _hqPublisher?;
558
+ /**
559
+ * Local cache of the agent registry to avoid re-reading on every call.
560
+ * Time-bounded: the registry file is shared ACROSS PROCESSES (that's the
561
+ * whole point of GlobalMailbox), so a cache served forever would never see
562
+ * agents registered by other sessions. Writers always bypass it.
563
+ */
564
+ private _registryCache;
565
+ /** When the registry cache was last refreshed from disk (epoch ms). */
566
+ private _registryCacheAt;
567
+ /**
568
+ * Local cache of the client registry to avoid re-reading on every call.
569
+ * Same reasoning as agent registry cache.
570
+ */
571
+ private _clientRegistryCache;
572
+ /** When the client registry cache was last refreshed from disk (epoch ms). */
573
+ private _clientRegistryCacheAt;
574
+ /** Last time each local agent sent a heartbeat (throttle). */
575
+ private _lastHeartbeat;
576
+ /** Last time each local client sent a heartbeat (throttle). */
577
+ private _lastClientHeartbeat;
578
+ /**
579
+ * In-memory mirror of the JSONL message file. The mailbox is shared
580
+ * ACROSS PROCESSES, so reads cannot trust the cache blindly — we pair it
581
+ * with an mtime check. The file lock serializes every write, so a
582
+ * changed mtimeMs is a definitive signal that another process (or this
583
+ * one) wrote; an unchanged mtimeMs guarantees no write happened and the
584
+ * cache is current. This collapses the per-iteration `query()` cost from
585
+ * O(file_size) disk + parse to O(messages) in memory.
586
+ */
587
+ private _messageCache;
588
+ /** mtimeMs of the file when `_messageCache` was populated. */
589
+ private _messageCacheMtime;
590
+ /** Size of the file when `_messageCache` was populated (extra guard). */
591
+ private _messageCacheSize;
592
+ /**
593
+ * @param projectDir — `~/.wrongstack/projects/<slug>/`
594
+ * @param events — optional EventBus for real-time TUI/WebUI notifications
595
+ * @param hqPublisher — optional HQ publisher for cross-project telemetry
596
+ */
597
+ constructor(projectDir: string, events?: EventBus, hqPublisher?: HqPublisher);
598
+ private get hqMailboxId();
599
+ private publishHqMailboxEvent;
600
+ private publishHqMailboxSnapshot;
601
+ send(input: MailboxSendInput): Promise<MailboxMessage>;
602
+ query(q: MailboxQuery): Promise<MailboxMessage[]>;
603
+ ack(input: MailboxAckInput): Promise<MailboxMessage | null>;
604
+ ackMany(input: MailboxAckBatchInput): Promise<MailboxMessage[]>;
605
+ unreadCount(forAgentId: string): Promise<number>;
606
+ registerAgent(input: AgentRegistrationInput): Promise<void>;
607
+ heartbeat(input: AgentHeartbeatInput): Promise<void>;
608
+ getAgentStatuses(): Promise<MailboxAgentStatus[]>;
609
+ getOnlineAgents(): Promise<MailboxAgentStatus[]>;
610
+ registerClient(input: ClientRegistrationInput): Promise<void>;
611
+ clientHeartbeat(input: ClientHeartbeatInput): Promise<void>;
612
+ getClientStatuses(): Promise<ClientStatus[]>;
613
+ close(): Promise<void>;
614
+ clearAll(): Promise<void>;
615
+ purgeStale(opts?: PurgeOptions): Promise<PurgeResult>;
616
+ /**
617
+ * Read all messages from the JSONL file. Always reads + parses the file.
618
+ * Callers that can tolerate a stale-by-mtime view should use
619
+ * {@link _readMessagesCached}; writers that need the post-lock truth
620
+ * should call this directly (it's what {@link _readMessagesFresh} aliases).
621
+ */
622
+ private _readMessages;
623
+ /**
624
+ * Read messages, then adopt the result as the in-memory cache. Use this
625
+ * from writers that just took the file lock — the read reflects the
626
+ * authoritative post-lock state and should be served to subsequent
627
+ * queries without re-reading.
628
+ */
629
+ private _readMessagesFresh;
630
+ /**
631
+ * Read messages, consulting the mtime-bounded in-memory cache first.
632
+ * The mailbox file is shared across processes; every `send`/`ack`/
633
+ * `clearAll`/`purgeStale` takes the file lock, so writes are serialized
634
+ * and a changed mtimeMs is a definitive freshness signal. When the
635
+ * stat matches the cached mtime+size we return the cached array — no
636
+ * file read and no JSON.parse — collapsing the per-iteration query
637
+ * cost on the mailbox-loop hot path.
638
+ */
639
+ private _readMessagesCached;
640
+ /**
641
+ * Replace the in-memory cache. Caller is responsible for guaranteeing
642
+ * that `messages` reflects the current on-disk state (e.g. they just
643
+ * read or wrote it under the file lock).
644
+ */
645
+ private _setMessageCache;
646
+ /**
647
+ * Append a single just-sent message to the in-memory cache without
648
+ * re-reading the file. The caller must hold the file lock (or have
649
+ * just released it after a successful append) so the cache stays
650
+ * consistent with on-disk state.
651
+ */
652
+ private _pushToCache;
653
+ private _ensureRegistry;
654
+ private _readRegistry;
655
+ private _pruneStaleInPlace;
656
+ private _writeRegistry;
657
+ private _ensureClientRegistry;
658
+ private _readClientRegistry;
659
+ private _pruneStaleClientsInPlace;
660
+ private _writeClientRegistry;
661
+ }
662
+
663
+ export { type HqSessionStatusPayload as $, type HqMailboxMappingOptions as A, type HqMailboxMessageSummary as B, type HqMailboxMessageType as C, DEFAULT_HQ_REDACTION_POLICY as D, type HqMailboxPriority as E, type HqMailboxSnapshotOptions as F, GlobalMailbox as G, HQ_PROTOCOL_VERSION as H, type HqMailboxSnapshotPayload as I, type HqMailboxSummary as J, type HqParseResult as K, type HqPathPolicy as L, type HqProjectIdentity as M, type HqProjectRecord as N, type HqProjectStatus as O, type HqProtocolVersion as P, type HqPublishEventOptions as Q, HqPublisher as R, type HqPublisherCommandHandler as S, type HqPublisherCommandResult as T, type HqPublisherOptions as U, type HqQueuedCommand as V, type HqRedactionPolicy as W, type HqServerCommandBatchMessage as X, type HqServerMessage as Y, type HqSessionStartedPayload as Z, type HqSessionStatus as _, type HqAlertMessage as a, type HqSessionSummary as a0, type HqSnapshot as a1, type HqSocketFactory as a2, type HqSocketLike as a3, type HqSubagentSummary as a4, type HqToolArgsPolicy as a5, type HqToolCompletedPayload as a6, type HqToolStartedPayload as a7, type HqUsagePayload as a8, type HqWelcomePayload as a9, type HqWorklistCounts as aa, type HqWorklistSnapshotPayload as ab, type HqWorkspaceKind as ac, createHqEventEnvelope as ad, createMailboxEventPayload as ae, createMailboxSnapshotPayload as af, createMailboxSnapshotPayloadFromMailbox as ag, mapMailboxAgentToHqSummary as ah, mapMailboxMessageToHqSummary as ai, parseHqEventPayload as aj, parseHqFrame as ak, resolveProjectDir as al, type HqBrowserEventMessage as b, type HqBrowserMessage as c, type HqBrowserSnapshotMessage as d, type HqClientCapability as e, type HqClientCommandAckMessage as f, type HqClientCommandPollMessage as g, type HqClientEventMessage as h, type HqClientHeartbeatPayload as i, type HqClientHelloMessage as j, type HqClientHelloPayload as k, type HqClientIdentity as l, type HqClientKind as m, type HqClientMessage as n, type HqClientRecord as o, type HqEventEnvelope as p, type HqEventPayloadResult as q, type HqEventType as r, type HqFleetEventPayload as s, type HqFleetSnapshotPayload as t, type HqFleetSummary as u, type HqGitSnapshotPayload as v, type HqMailboxAgentStatus as w, type HqMailboxAgentSummary as x, type HqMailboxEventAction as y, type HqMailboxEventPayload as z };