@adhdev/mesh-shared 1.0.60-rc.5 → 1.0.60-rc.50

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 (41) hide show
  1. package/dist/index.d.ts +10 -0
  2. package/dist/index.js +2788 -17
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +2464 -17
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/mesh-tool-names.d.ts +2 -2
  7. package/dist/mesh-vocabulary.d.ts +70 -0
  8. package/dist/mission-brief.d.ts +62 -0
  9. package/dist/outbound-message.d.ts +202 -0
  10. package/dist/path-ownership.d.ts +101 -0
  11. package/dist/protocol/daemon-server.d.ts +388 -0
  12. package/dist/protocol/dashboard-daemon-p2p.d.ts +212 -0
  13. package/dist/protocol/dashboard-server.d.ts +240 -0
  14. package/dist/protocol/envelope.d.ts +55 -0
  15. package/dist/protocol/index.d.ts +15 -0
  16. package/dist/session-launch.d.ts +113 -0
  17. package/dist/session-status.d.ts +61 -0
  18. package/dist/turn-evidence.d.ts +438 -0
  19. package/dist/turn-ipc.d.ts +974 -0
  20. package/dist/types.d.ts +11 -0
  21. package/dist/worker-protocol.d.ts +69 -0
  22. package/dist/ws-protocol.d.ts +71 -41
  23. package/package.json +1 -1
  24. package/src/index.ts +10 -0
  25. package/src/mesh-tool-names.ts +0 -1
  26. package/src/mesh-vocabulary.ts +98 -0
  27. package/src/mission-brief.ts +153 -0
  28. package/src/outbound-message.ts +320 -0
  29. package/src/path-ownership.ts +271 -0
  30. package/src/protocol/daemon-server.ts +552 -0
  31. package/src/protocol/dashboard-daemon-p2p.ts +272 -0
  32. package/src/protocol/dashboard-server.ts +340 -0
  33. package/src/protocol/envelope.ts +75 -0
  34. package/src/protocol/index.ts +16 -0
  35. package/src/session-launch.ts +247 -0
  36. package/src/session-status.ts +140 -0
  37. package/src/turn-evidence.ts +602 -0
  38. package/src/turn-ipc.ts +2231 -0
  39. package/src/types.ts +8 -0
  40. package/src/worker-protocol.ts +164 -0
  41. package/src/ws-protocol.ts +102 -93
package/dist/index.js CHANGED
@@ -20,52 +20,361 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ CANCEL_REASONS: () => CANCEL_REASONS,
23
24
  CANONICAL_MESH_TOOL_COUNT: () => CANONICAL_MESH_TOOL_COUNT,
24
25
  CANONICAL_MESH_TOOL_NAMES: () => CANONICAL_MESH_TOOL_NAMES,
25
26
  CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX: () => CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX,
26
27
  CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX: () => CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX,
27
28
  CLI_SLOT_RECIPES: () => CLI_SLOT_RECIPES,
29
+ COMMIT_STRENGTHS: () => COMMIT_STRENGTHS,
30
+ CONSUME_PROFILES: () => CONSUME_PROFILES,
31
+ COORDINATOR_ACK_OUTCOMES: () => COORDINATOR_ACK_OUTCOMES,
32
+ DAEMON_P2P_SIGNAL_TYPES: () => DAEMON_P2P_SIGNAL_TYPES,
33
+ DAEMON_STATUS_EVENT_NAMES: () => DAEMON_STATUS_EVENT_NAMES,
34
+ DAEMON_TO_DASHBOARD_P2P_TYPES: () => DAEMON_TO_DASHBOARD_P2P_TYPES,
35
+ DAEMON_TO_SERVER_TYPES: () => DAEMON_TO_SERVER_TYPES,
28
36
  DAEMON_TO_SERVER_WS_MSGS: () => DAEMON_TO_SERVER_WS_MSGS,
37
+ DASHBOARD_P2P_MESSAGE_KINDS: () => DASHBOARD_P2P_MESSAGE_KINDS,
38
+ DASHBOARD_P2P_SIGNAL_TYPES: () => DASHBOARD_P2P_SIGNAL_TYPES,
39
+ DASHBOARD_STATUS_EVENT_NAMES: () => DASHBOARD_STATUS_EVENT_NAMES,
40
+ DASHBOARD_TO_DAEMON_P2P_TYPES: () => DASHBOARD_TO_DAEMON_P2P_TYPES,
41
+ DASHBOARD_TO_USER_SESSION_TYPES: () => DASHBOARD_TO_USER_SESSION_TYPES,
29
42
  DEFAULT_DIFFICULTY_BRAINS: () => DEFAULT_DIFFICULTY_BRAINS,
43
+ DELIVERY_OUTCOMES: () => DELIVERY_OUTCOMES,
44
+ DELIVERY_VIAS: () => DELIVERY_VIAS,
45
+ DISPATCH_FAILURE_REASONS: () => DISPATCH_FAILURE_REASONS,
46
+ EVIDENCE_ENVELOPE_FIELD_SPECS: () => EVIDENCE_ENVELOPE_FIELD_SPECS,
47
+ EVIDENCE_SOURCE_IDS: () => EVIDENCE_SOURCE_IDS,
48
+ GRAPH_AUDIT_EVENTS: () => GRAPH_AUDIT_EVENTS,
49
+ HOLD_REASONS: () => HOLD_REASONS,
50
+ LIVENESS_RESULTS: () => LIVENESS_RESULTS,
30
51
  MAGI_RAW_ANSWER_CAP: () => MAGI_RAW_ANSWER_CAP,
52
+ MAX_MESH_RECORD_STRING: () => MAX_MESH_RECORD_STRING,
53
+ MAX_OWNED_PATHS: () => MAX_OWNED_PATHS,
31
54
  MESH_CHUNK_KIND: () => MESH_CHUNK_KIND,
32
55
  MESH_CHUNK_PAYLOAD_CHARS: () => MESH_CHUNK_PAYLOAD_CHARS,
33
56
  MESH_CHUNK_TTL_MS: () => MESH_CHUNK_TTL_MS,
57
+ MESH_DELIVERY_MODES: () => MESH_DELIVERY_MODES,
58
+ MESH_INDEX_QUERY_WRITER_SCOPES: () => MESH_INDEX_QUERY_WRITER_SCOPES,
34
59
  MESH_MAX_CHUNKS: () => MESH_MAX_CHUNKS,
35
60
  MESH_MAX_INLINE_FRAME_BYTES: () => MESH_MAX_INLINE_FRAME_BYTES,
36
61
  MESH_MAX_REASSEMBLED_BYTES: () => MESH_MAX_REASSEMBLED_BYTES,
62
+ MESH_MISSION_SOURCES: () => MESH_MISSION_SOURCES,
63
+ MESH_MISSION_STATUSES: () => MESH_MISSION_STATUSES,
64
+ MESH_P2P_SIGNAL_TYPES: () => MESH_P2P_SIGNAL_TYPES,
65
+ MESH_RECORD_PAYLOAD_KEYS: () => MESH_RECORD_PAYLOAD_KEYS,
66
+ MESH_SESSION_CLEANUP_MODES: () => MESH_SESSION_CLEANUP_MODES,
37
67
  MESH_TASK_DIFFICULTIES: () => MESH_TASK_DIFFICULTIES,
68
+ MESH_TASK_MODES: () => MESH_TASK_MODES,
69
+ MESH_TASK_PRIORITIES: () => MESH_TASK_PRIORITIES,
70
+ MESH_TASK_STATUSES: () => MESH_TASK_STATUSES,
71
+ MESH_TERMINAL_TASK_STATUSES: () => MESH_TERMINAL_TASK_STATUSES,
72
+ MESH_THINKING_LEVELS: () => MESH_THINKING_LEVELS,
73
+ MESH_TOPIC_ENTRY_KINDS: () => MESH_TOPIC_ENTRY_KINDS,
74
+ MESH_TOPIC_PROTOCOL_VERSION: () => MESH_TOPIC_PROTOCOL_VERSION,
75
+ MISSION_BRIEF_RENDER_MAX_CHARS: () => MISSION_BRIEF_RENDER_MAX_CHARS,
76
+ MODEL_AXIS_SOURCES: () => MODEL_AXIS_SOURCES,
77
+ MODEL_SELECTION_HISTORY_LIMIT: () => MODEL_SELECTION_HISTORY_LIMIT,
38
78
  MeshChunkAssembler: () => MeshChunkAssembler,
79
+ NATIVE_TURN_OUTCOMES: () => NATIVE_TURN_OUTCOMES,
80
+ NOTIFY_KINDS: () => NOTIFY_KINDS,
81
+ NO_PROGRESS_OBSERVED_STATUSES: () => NO_PROGRESS_OBSERVED_STATUSES,
82
+ NPM_UPDATE_TAGS: () => NPM_UPDATE_TAGS,
83
+ OPERATING_NOTE_CATEGORIES: () => OPERATING_NOTE_CATEGORIES,
84
+ OPERATOR_STATUSES: () => OPERATOR_STATUSES,
85
+ OPERATOR_STATUS_REASONS: () => OPERATOR_STATUS_REASONS,
86
+ OPERATOR_STATUS_REASON_VALUES: () => OPERATOR_STATUS_REASON_VALUES,
87
+ OPERATOR_STATUS_VALUES: () => OPERATOR_STATUS_VALUES,
88
+ OUTBOUND_MESSAGE_ORIGINS: () => OUTBOUND_MESSAGE_ORIGINS,
89
+ P2P_SIGNAL_TYPES: () => P2P_SIGNAL_TYPES,
90
+ PROVIDER_FAILURES: () => PROVIDER_FAILURES,
39
91
  QUOTA_SUPPORTED_PROVIDERS: () => QUOTA_SUPPORTED_PROVIDERS,
92
+ RECENT_SESSION_BUCKETS: () => RECENT_SESSION_BUCKETS,
93
+ RECLAIMING_SEND_REFUSALS: () => RECLAIMING_SEND_REFUSALS,
94
+ RELEASE_CHANNELS: () => RELEASE_CHANNELS,
95
+ SEND_POLICY_MODES: () => SEND_POLICY_MODES,
96
+ SEND_REFUSAL_REASONS: () => SEND_REFUSAL_REASONS,
97
+ SERVER_STATUS_EVENT_NAMES: () => SERVER_STATUS_EVENT_NAMES,
98
+ SERVER_TO_DAEMON_CONTROL_TYPES: () => SERVER_TO_DAEMON_CONTROL_TYPES,
40
99
  SERVER_TO_DAEMON_WS_MSGS: () => SERVER_TO_DAEMON_WS_MSGS,
100
+ SESSION_ERROR_REASONS: () => SESSION_ERROR_REASONS,
101
+ SESSION_LAUNCHED_BY: () => SESSION_LAUNCHED_BY,
102
+ SESSION_REBOUND_REASONS: () => SESSION_REBOUND_REASONS,
103
+ SESSION_STATUSES: () => SESSION_STATUSES,
104
+ SESSION_STATUS_ALIASES: () => SESSION_STATUS_ALIASES,
105
+ SESSION_STATUS_CLASS: () => SESSION_STATUS_CLASS,
106
+ SHARED_SESSION_TO_VIEWER_TYPES: () => SHARED_SESSION_TO_VIEWER_TYPES,
41
107
  STATUS_PROBE_ARG_KEY: () => STATUS_PROBE_ARG_KEY,
108
+ SUSPENSION_MODALS: () => SUSPENSION_MODALS,
109
+ SUSPENSION_RESOLUTIONS: () => SUSPENSION_RESOLUTIONS,
110
+ SUSPENSION_RESOLUTION_VIAS: () => SUSPENSION_RESOLUTION_VIAS,
111
+ SYSTEM_ANNOUNCEMENT_TYPES: () => SYSTEM_ANNOUNCEMENT_TYPES,
112
+ TERMINAL_CLASS_EVIDENCE_KINDS: () => TERMINAL_CLASS_EVIDENCE_KINDS,
113
+ TOOL_CALLER_ROLES: () => TOOL_CALLER_ROLES,
114
+ TURN_END_BLOCK_REASONS: () => TURN_END_BLOCK_REASONS,
115
+ TURN_END_STRENGTHS: () => TURN_END_STRENGTHS,
116
+ TURN_EVIDENCE_FIELD_SPECS: () => TURN_EVIDENCE_FIELD_SPECS,
117
+ TURN_EVIDENCE_FLAGS: () => TURN_EVIDENCE_FLAGS,
118
+ TURN_EVIDENCE_KINDS: () => TURN_EVIDENCE_KINDS,
119
+ TURN_IPC_COMMANDS: () => TURN_IPC_COMMANDS,
120
+ TURN_IPC_ERROR_CODES: () => TURN_IPC_ERROR_CODES,
121
+ TURN_IPC_PROTOCOL_VERSION: () => TURN_IPC_PROTOCOL_VERSION,
122
+ TURN_OBSERVE_VERDICTS: () => TURN_OBSERVE_VERDICTS,
123
+ TURN_OUTCOMES: () => TURN_OUTCOMES,
124
+ TURN_REASONS: () => TURN_REASONS,
125
+ TURN_SCOPES: () => TURN_SCOPES,
42
126
  UNKNOWN_CLI_SLOT_RECIPE: () => UNKNOWN_CLI_SLOT_RECIPE,
127
+ USER_SESSION_TO_DASHBOARD_TYPES: () => USER_SESSION_TO_DASHBOARD_TYPES,
128
+ VERSION_UPDATE_REASONS: () => VERSION_UPDATE_REASONS,
129
+ VIEWER_TO_SHARED_SESSION_TYPES: () => VIEWER_TO_SHARED_SESSION_TYPES,
130
+ WORKER_BRANCH_STATES: () => WORKER_BRANCH_STATES,
131
+ WORKER_PROTOCOL_FOOTER_MARKER: () => WORKER_PROTOCOL_FOOTER_MARKER,
132
+ WORKER_REPORT_OUTCOMES: () => WORKER_REPORT_OUTCOMES,
133
+ WORKER_TOOLS: () => WORKER_TOOLS,
134
+ appendWorkerProtocolFooter: () => appendWorkerProtocolFooter,
43
135
  argsCarryStatusProbeMarker: () => argsCarryStatusProbeMarker,
44
136
  buildMagiPanelProposal: () => buildMagiPanelProposal,
45
137
  buildSlotProposal: () => buildSlotProposal,
46
138
  canonicalDaemonId: () => canonicalDaemonId,
139
+ classifySessionStatus: () => classifySessionStatus,
47
140
  compareSemver: () => compareSemver,
48
141
  daemonIdsEquivalent: () => daemonIdsEquivalent,
142
+ decodeActiveWorkQueryRequest: () => decodeActiveWorkQueryRequest,
143
+ decodeActiveWorkQueryResponse: () => decodeActiveWorkQueryResponse,
144
+ decodeDaemonToDashboardP2P: () => decodeDaemonToDashboardP2P,
145
+ decodeDaemonToServer: () => decodeDaemonToServer,
146
+ decodeDashboardToDaemonP2P: () => decodeDashboardToDaemonP2P,
147
+ decodeDashboardToDaemonP2PChunk: () => decodeDashboardToDaemonP2PChunk,
148
+ decodeDashboardToUserSession: () => decodeDashboardToUserSession,
149
+ decodeDirectDispatchRecordRequest: () => decodeDirectDispatchRecordRequest,
150
+ decodeDirectDispatchRecordResponse: () => decodeDirectDispatchRecordResponse,
151
+ decodeGraphAuditRecordRequest: () => decodeGraphAuditRecordRequest,
152
+ decodeGraphAuditRecordResponse: () => decodeGraphAuditRecordResponse,
153
+ decodeGraphGateAbandonRequest: () => decodeGraphGateAbandonRequest,
154
+ decodeGraphGateAbandonResponse: () => decodeGraphGateAbandonResponse,
155
+ decodeGraphGateClaimRequest: () => decodeGraphGateClaimRequest,
156
+ decodeGraphGateClaimResponse: () => decodeGraphGateClaimResponse,
157
+ decodeGraphGateReleaseRequest: () => decodeGraphGateReleaseRequest,
158
+ decodeGraphGateReleaseResponse: () => decodeGraphGateReleaseResponse,
159
+ decodeGraphNodePatchRequest: () => decodeGraphNodePatchRequest,
160
+ decodeGraphNodePatchResponse: () => decodeGraphNodePatchResponse,
161
+ decodeGraphViewQueryRequest: () => decodeGraphViewQueryRequest,
162
+ decodeGraphViewQueryResponse: () => decodeGraphViewQueryResponse,
163
+ decodeLedgerQueryRequest: () => decodeLedgerQueryRequest,
164
+ decodeLedgerQueryResponse: () => decodeLedgerQueryResponse,
165
+ decodeMeshIndexQueryRequest: () => decodeMeshIndexQueryRequest,
166
+ decodeMeshIndexQueryResponse: () => decodeMeshIndexQueryResponse,
167
+ decodeMeshRecordRequest: () => decodeMeshRecordRequest,
168
+ decodeMeshRecordResponse: () => decodeMeshRecordResponse,
169
+ decodeMissionListQueryRequest: () => decodeMissionListQueryRequest,
170
+ decodeMissionListQueryResponse: () => decodeMissionListQueryResponse,
171
+ decodeMissionQueryRequest: () => decodeMissionQueryRequest,
172
+ decodeMissionQueryResponse: () => decodeMissionQueryResponse,
173
+ decodeMissionUpsertRequest: () => decodeMissionUpsertRequest,
174
+ decodeMissionUpsertResponse: () => decodeMissionUpsertResponse,
175
+ decodeNoteForgetRequest: () => decodeNoteForgetRequest,
176
+ decodeNoteForgetResponse: () => decodeNoteForgetResponse,
177
+ decodeNoteUpsertRequest: () => decodeNoteUpsertRequest,
178
+ decodeNoteUpsertResponse: () => decodeNoteUpsertResponse,
179
+ decodeOperatorStatusRequest: () => decodeOperatorStatusRequest,
180
+ decodeOperatorStatusResponse: () => decodeOperatorStatusResponse,
181
+ decodeOrphanedPinNotifyRequest: () => decodeOrphanedPinNotifyRequest,
182
+ decodeOrphanedPinNotifyResponse: () => decodeOrphanedPinNotifyResponse,
183
+ decodePruneStaleDirectRequest: () => decodePruneStaleDirectRequest,
184
+ decodePruneStaleDirectResponse: () => decodePruneStaleDirectResponse,
185
+ decodeQueueCancelRequest: () => decodeQueueCancelRequest,
186
+ decodeQueueCancelResponse: () => decodeQueueCancelResponse,
187
+ decodeQueueEnqueueGraphRequest: () => decodeQueueEnqueueGraphRequest,
188
+ decodeQueueEnqueueGraphResponse: () => decodeQueueEnqueueGraphResponse,
189
+ decodeQueueEnqueueRequest: () => decodeQueueEnqueueRequest,
190
+ decodeQueueEnqueueResponse: () => decodeQueueEnqueueResponse,
191
+ decodeQueueQueryRequest: () => decodeQueueQueryRequest,
192
+ decodeQueueQueryResponse: () => decodeQueueQueryResponse,
193
+ decodeQueueRequeueRequest: () => decodeQueueRequeueRequest,
194
+ decodeQueueRequeueResponse: () => decodeQueueRequeueResponse,
195
+ decodeRecordLocalRequest: () => decodeRecordLocalRequest,
196
+ decodeRecordLocalResponse: () => decodeRecordLocalResponse,
197
+ decodeRecoveryContextQueryRequest: () => decodeRecoveryContextQueryRequest,
198
+ decodeRecoveryContextQueryResponse: () => decodeRecoveryContextQueryResponse,
199
+ decodeServerToDaemon: () => decodeServerToDaemon,
200
+ decodeTaskStatsQueryRequest: () => decodeTaskStatsQueryRequest,
201
+ decodeTaskStatsQueryResponse: () => decodeTaskStatsQueryResponse,
202
+ decodeToolCallRecordRequest: () => decodeToolCallRecordRequest,
203
+ decodeToolCallRecordResponse: () => decodeToolCallRecordResponse,
204
+ decodeTurnCancelRequest: () => decodeTurnCancelRequest,
205
+ decodeTurnCancelResponse: () => decodeTurnCancelResponse,
206
+ decodeTurnObserveRequest: () => decodeTurnObserveRequest,
207
+ decodeTurnObserveResponse: () => decodeTurnObserveResponse,
208
+ decodeTurnQueryRequest: () => decodeTurnQueryRequest,
209
+ decodeTurnQueryResponse: () => decodeTurnQueryResponse,
210
+ decodeTypeField: () => decodeTypeField,
211
+ decodeUserSessionToDashboard: () => decodeUserSessionToDashboard,
212
+ decodeViewerToSharedSession: () => decodeViewerToSharedSession,
49
213
  deriveProviderPriorityFromSlots: () => deriveProviderPriorityFromSlots,
50
214
  deriveSlotsFromLegacy: () => deriveSlotsFromLegacy,
215
+ describeModelSelection: () => describeModelSelection,
216
+ effectiveModelSelectionValue: () => effectiveModelSelectionValue,
217
+ enumOf: () => enumOf,
51
218
  expandDaemonIdForms: () => expandDaemonIdForms,
219
+ findOwnershipConflicts: () => findOwnershipConflicts,
52
220
  formatQuotaAccount: () => formatQuotaAccount,
53
221
  hasGitStatusEvidence: () => hasGitStatusEvidence,
222
+ hasWorkerProtocolFooter: () => hasWorkerProtocolFooter,
54
223
  interpolateArgs: () => interpolateArgs,
55
224
  interpolateString: () => interpolateString,
225
+ isActiveWorkQueryRequest: () => isActiveWorkQueryRequest,
226
+ isActiveWorkQueryResponse: () => isActiveWorkQueryResponse,
227
+ isBlockedStatus: () => isBlockedStatus,
228
+ isBusyStatus: () => isBusyStatus,
229
+ isChunkType: () => isChunkType,
230
+ isCommitStrength: () => isCommitStrength,
231
+ isDaemonDirectCommandType: () => isDaemonDirectCommandType,
232
+ isDaemonP2PSignalType: () => isDaemonP2PSignalType,
233
+ isDaemonStatusEventName: () => isDaemonStatusEventName,
234
+ isDaemonToDashboardP2PType: () => isDaemonToDashboardP2PType,
235
+ isDaemonToServerType: () => isDaemonToServerType,
56
236
  isDaemonToServerWsMsg: () => isDaemonToServerWsMsg,
237
+ isDashboardP2PSignalType: () => isDashboardP2PSignalType,
238
+ isDashboardStatusEventName: () => isDashboardStatusEventName,
239
+ isDashboardToDaemonChunkType: () => isDashboardToDaemonChunkType,
240
+ isDashboardToDaemonP2PType: () => isDashboardToDaemonP2PType,
241
+ isDashboardToUserSessionType: () => isDashboardToUserSessionType,
242
+ isDeadStatus: () => isDeadStatus,
243
+ isDirectDispatchRecordRequest: () => isDirectDispatchRecordRequest,
244
+ isDirectDispatchRecordResponse: () => isDirectDispatchRecordResponse,
57
245
  isDowngrade: () => isDowngrade,
246
+ isEvidenceIdentifier: () => isEvidenceIdentifier,
247
+ isEvidenceSourceId: () => isEvidenceSourceId,
248
+ isFiniteNumber: () => isFiniteNumber,
249
+ isGraphAuditEvent: () => isGraphAuditEvent,
250
+ isGraphAuditRecordRequest: () => isGraphAuditRecordRequest,
251
+ isGraphAuditRecordResponse: () => isGraphAuditRecordResponse,
252
+ isGraphGateAbandonRequest: () => isGraphGateAbandonRequest,
253
+ isGraphGateAbandonResponse: () => isGraphGateAbandonResponse,
254
+ isGraphGateClaimRequest: () => isGraphGateClaimRequest,
255
+ isGraphGateClaimResponse: () => isGraphGateClaimResponse,
256
+ isGraphGateReleaseRequest: () => isGraphGateReleaseRequest,
257
+ isGraphGateReleaseResponse: () => isGraphGateReleaseResponse,
258
+ isGraphNodePatchRequest: () => isGraphNodePatchRequest,
259
+ isGraphNodePatchResponse: () => isGraphNodePatchResponse,
260
+ isGraphViewQueryRequest: () => isGraphViewQueryRequest,
261
+ isGraphViewQueryResponse: () => isGraphViewQueryResponse,
262
+ isHoldReason: () => isHoldReason,
263
+ isInputEnvelopeWire: () => isInputEnvelopeWire,
264
+ isLedgerQueryRequest: () => isLedgerQueryRequest,
265
+ isLedgerQueryResponse: () => isLedgerQueryResponse,
266
+ isMeshDeliveryMode: () => isMeshDeliveryMode,
267
+ isMeshIndexQueryRequest: () => isMeshIndexQueryRequest,
268
+ isMeshIndexQueryResponse: () => isMeshIndexQueryResponse,
269
+ isMeshIndexQueryWriterScope: () => isMeshIndexQueryWriterScope,
270
+ isMeshMissionSourceValue: () => isMeshMissionSourceValue,
271
+ isMeshMissionStatusValue: () => isMeshMissionStatusValue,
272
+ isMeshP2PSignalType: () => isMeshP2PSignalType,
273
+ isMeshRecordPayload: () => isMeshRecordPayload,
274
+ isMeshRecordRequest: () => isMeshRecordRequest,
275
+ isMeshRecordResponse: () => isMeshRecordResponse,
276
+ isMeshSessionCleanupMode: () => isMeshSessionCleanupMode,
58
277
  isMeshTaskDifficulty: () => isMeshTaskDifficulty,
278
+ isMeshTaskMode: () => isMeshTaskMode,
279
+ isMeshTaskPriority: () => isMeshTaskPriority,
280
+ isMeshTaskStatus: () => isMeshTaskStatus,
281
+ isMeshTerminalTaskStatus: () => isMeshTerminalTaskStatus,
282
+ isMeshThinkingLevel: () => isMeshThinkingLevel,
283
+ isMeshTopicEntry: () => isMeshTopicEntry,
284
+ isMeshTopicEntryKind: () => isMeshTopicEntryKind,
285
+ isMessageId: () => isMessageId,
286
+ isMissionListQueryRequest: () => isMissionListQueryRequest,
287
+ isMissionListQueryResponse: () => isMissionListQueryResponse,
288
+ isMissionQueryRequest: () => isMissionQueryRequest,
289
+ isMissionQueryResponse: () => isMissionQueryResponse,
290
+ isMissionUpsertRequest: () => isMissionUpsertRequest,
291
+ isMissionUpsertResponse: () => isMissionUpsertResponse,
292
+ isModelAxisSource: () => isModelAxisSource,
293
+ isNonEmptyString: () => isNonEmptyString,
294
+ isNoteForgetRequest: () => isNoteForgetRequest,
295
+ isNoteForgetResponse: () => isNoteForgetResponse,
296
+ isNoteUpsertRequest: () => isNoteUpsertRequest,
297
+ isNoteUpsertResponse: () => isNoteUpsertResponse,
298
+ isNotifyKind: () => isNotifyKind,
299
+ isOperatingNoteCategory: () => isOperatingNoteCategory,
300
+ isOperatorStatusReasonValue: () => isOperatorStatusReasonValue,
301
+ isOperatorStatusRequest: () => isOperatorStatusRequest,
302
+ isOperatorStatusResponse: () => isOperatorStatusResponse,
303
+ isOperatorStatusValue: () => isOperatorStatusValue,
304
+ isOrphanedPinNotifyRequest: () => isOrphanedPinNotifyRequest,
305
+ isOrphanedPinNotifyResponse: () => isOrphanedPinNotifyResponse,
306
+ isOutboundMessage: () => isOutboundMessage,
307
+ isOutboundMessageOrigin: () => isOutboundMessageOrigin,
308
+ isP2PSignalType: () => isP2PSignalType,
59
309
  isPhantomDaemonEntry: () => isPhantomDaemonEntry,
310
+ isPruneStaleDirectRequest: () => isPruneStaleDirectRequest,
311
+ isPruneStaleDirectResponse: () => isPruneStaleDirectResponse,
312
+ isQueueCancelRequest: () => isQueueCancelRequest,
313
+ isQueueCancelResponse: () => isQueueCancelResponse,
314
+ isQueueEnqueueGraphRequest: () => isQueueEnqueueGraphRequest,
315
+ isQueueEnqueueGraphResponse: () => isQueueEnqueueGraphResponse,
316
+ isQueueEnqueueRequest: () => isQueueEnqueueRequest,
317
+ isQueueEnqueueResponse: () => isQueueEnqueueResponse,
318
+ isQueueQueryRequest: () => isQueueQueryRequest,
319
+ isQueueQueryResponse: () => isQueueQueryResponse,
320
+ isQueueRequeueRequest: () => isQueueRequeueRequest,
321
+ isQueueRequeueResponse: () => isQueueRequeueResponse,
60
322
  isRawDaemonDoId: () => isRawDaemonDoId,
323
+ isReadyStatus: () => isReadyStatus,
324
+ isRecord: () => isRecord,
325
+ isRecordLocalRequest: () => isRecordLocalRequest,
326
+ isRecordLocalResponse: () => isRecordLocalResponse,
327
+ isRecoveryContextQueryRequest: () => isRecoveryContextQueryRequest,
328
+ isRecoveryContextQueryResponse: () => isRecoveryContextQueryResponse,
329
+ isSendPolicy: () => isSendPolicy,
330
+ isSendPolicyMode: () => isSendPolicyMode,
331
+ isSendRefusal: () => isSendRefusal,
332
+ isServerDirectCommandMsg: () => isServerDirectCommandMsg,
333
+ isServerToDaemonControlType: () => isServerToDaemonControlType,
61
334
  isServerToDaemonWsMsg: () => isServerToDaemonWsMsg,
335
+ isSessionLaunchedBy: () => isSessionLaunchedBy,
336
+ isSessionStatus: () => isSessionStatus,
337
+ isSharedSessionToViewerType: () => isSharedSessionToViewerType,
338
+ isSubmitOutcome: () => isSubmitOutcome,
339
+ isSummaryRef: () => isSummaryRef,
340
+ isTaskStatsQueryRequest: () => isTaskStatsQueryRequest,
341
+ isTaskStatsQueryResponse: () => isTaskStatsQueryResponse,
342
+ isTerminalClassEvidenceKind: () => isTerminalClassEvidenceKind,
343
+ isToolCallRecordRequest: () => isToolCallRecordRequest,
344
+ isToolCallRecordResponse: () => isToolCallRecordResponse,
345
+ isToolCallerRole: () => isToolCallerRole,
346
+ isTurnAttemptRef: () => isTurnAttemptRef,
347
+ isTurnCancelRequest: () => isTurnCancelRequest,
348
+ isTurnCancelResponse: () => isTurnCancelResponse,
349
+ isTurnEvidence: () => isTurnEvidence,
350
+ isTurnEvidenceKind: () => isTurnEvidenceKind,
351
+ isTurnIpcCommand: () => isTurnIpcCommand,
352
+ isTurnIpcError: () => isTurnIpcError,
353
+ isTurnIpcErrorCode: () => isTurnIpcErrorCode,
354
+ isTurnObserveRequest: () => isTurnObserveRequest,
355
+ isTurnObserveResponse: () => isTurnObserveResponse,
356
+ isTurnObserveVerdict: () => isTurnObserveVerdict,
357
+ isTurnOutcome: () => isTurnOutcome,
358
+ isTurnQueryRequest: () => isTurnQueryRequest,
359
+ isTurnQueryResponse: () => isTurnQueryResponse,
360
+ isTurnReason: () => isTurnReason,
361
+ isUserSessionToDashboardType: () => isUserSessionToDashboardType,
362
+ isViewerToSharedSessionType: () => isViewerToSharedSessionType,
363
+ isWorkerBranchState: () => isWorkerBranchState,
364
+ isWorkerReportOutcome: () => isWorkerReportOutcome,
365
+ isWorkerTool: () => isWorkerTool,
366
+ isWorkingStatus: () => isWorkingStatus,
62
367
  joinRepoPath: () => joinRepoPath,
368
+ launchModelSelectionValue: () => launchModelSelectionValue,
63
369
  machineCoreFromDaemonId: () => machineCoreFromDaemonId,
370
+ makeTypeGuard: () => makeTypeGuard,
64
371
  measureWorstCaseChunkEnvelopeBytes: () => measureWorstCaseChunkEnvelopeBytes,
65
372
  meshFrameNeedsChunking: () => meshFrameNeedsChunking,
66
373
  meshNodeIdMatches: () => meshNodeIdMatches,
67
374
  meshUtf8ByteLength: () => meshUtf8ByteLength,
68
375
  meshWorkspacesEquivalent: () => meshWorkspacesEquivalent,
376
+ mintMessageId: () => mintMessageId,
377
+ normalizeAuthOkLimits: () => normalizeAuthOkLimits,
69
378
  normalizeBrainSlot: () => normalizeBrainSlot,
70
379
  normalizeDifficultyBrainMap: () => normalizeDifficultyBrainMap,
71
380
  normalizeGitStatus: () => normalizeGitStatus,
@@ -73,25 +382,40 @@ __export(index_exports, {
73
382
  normalizeMeshNodeId: () => normalizeMeshNodeId,
74
383
  normalizeMeshSessionRecord: () => normalizeMeshSessionRecord,
75
384
  normalizeMeshWorkspaceForCompare: () => normalizeMeshWorkspaceForCompare,
385
+ normalizeMissionBrief: () => normalizeMissionBrief,
76
386
  normalizeNodeCapabilitySlot: () => normalizeNodeCapabilitySlot,
77
387
  normalizeNodeCapabilitySlots: () => normalizeNodeCapabilitySlots,
388
+ normalizeOwnedPaths: () => normalizeOwnedPaths,
389
+ normalizeSessionStatus: () => normalizeSessionStatus,
78
390
  normalizeThinkingLevel: () => normalizeThinkingLevel,
79
391
  parseJsonRecord: () => parseJsonRecord,
80
392
  parseSemver: () => parseSemver,
393
+ parseSessionLaunchRecord: () => parseSessionLaunchRecord,
394
+ pathsOverlap: () => pathsOverlap,
81
395
  pickBestTransitGitStatus: () => pickBestTransitGitStatus,
396
+ projectTurnEvidenceEntry: () => projectTurnEvidenceEntry,
82
397
  readBoolean: () => readBoolean,
398
+ readEnvelopeFields: () => readEnvelopeFields,
83
399
  readGitSubmodules: () => readGitSubmodules,
84
400
  readNumber: () => readNumber,
85
401
  readRecord: () => readRecord,
86
402
  readString: () => readString,
87
403
  readStringArray: () => readStringArray,
404
+ renderCoordinatorWorkerSection: () => renderCoordinatorWorkerSection,
405
+ renderMissionBriefBlock: () => renderMissionBriefBlock,
406
+ renderWorkerProtocolFooter: () => renderWorkerProtocolFooter,
407
+ sanitizeModelIdentifier: () => sanitizeModelIdentifier,
408
+ sanitizeRefusalCode: () => sanitizeRefusalCode,
88
409
  scoreGitStatusCandidate: () => scoreGitStatusCandidate,
89
410
  scoreGitUpstreamFreshness: () => scoreGitUpstreamFreshness,
90
411
  sessionIdsEquivalent: () => sessionIdsEquivalent,
91
412
  splitMeshFrame: () => splitMeshFrame,
413
+ statusesOfClass: () => statusesOfClass,
92
414
  stripStatusProbeMarker: () => stripStatusProbeMarker,
415
+ stripWorkerProtocolFooter: () => stripWorkerProtocolFooter,
93
416
  summarizeGitShape: () => summarizeGitShape,
94
417
  supportsQuota: () => supportsQuota,
418
+ touchedFilesOutsideOwnership: () => touchedFilesOutsideOwnership,
95
419
  withStatusProbeMarker: () => withStatusProbeMarker
96
420
  });
97
421
  module.exports = __toCommonJS(index_exports);
@@ -385,8 +709,8 @@ function meshWorkspacesEquivalent(a, b) {
385
709
 
386
710
  // src/daemon-normalize.ts
387
711
  var DAEMON_ID_PREFIXES = ["daemon_", "standalone_"];
388
- function isRawDaemonDoId(id) {
389
- const trimmed = readString(id);
712
+ function isRawDaemonDoId(id2) {
713
+ const trimmed = readString(id2);
390
714
  return !!trimmed && /^[0-9a-f]{64}$/i.test(trimmed);
391
715
  }
392
716
  function isPhantomDaemonEntry(entry) {
@@ -397,8 +721,8 @@ function isPhantomDaemonEntry(entry) {
397
721
  );
398
722
  return !hasMachineEvidence;
399
723
  }
400
- function machineCoreFromDaemonId(id) {
401
- const trimmed = readString(id);
724
+ function machineCoreFromDaemonId(id2) {
725
+ const trimmed = readString(id2);
402
726
  if (!trimmed) return void 0;
403
727
  for (const prefix of DAEMON_ID_PREFIXES) {
404
728
  if (trimmed.startsWith(prefix)) {
@@ -408,8 +732,8 @@ function machineCoreFromDaemonId(id) {
408
732
  }
409
733
  return trimmed;
410
734
  }
411
- function canonicalDaemonId(id) {
412
- const core = machineCoreFromDaemonId(id);
735
+ function canonicalDaemonId(id2) {
736
+ const core = machineCoreFromDaemonId(id2);
413
737
  if (!core) return void 0;
414
738
  if (!core.startsWith("mach_")) return core;
415
739
  return `daemon_${core}`;
@@ -802,7 +1126,6 @@ var CANONICAL_MESH_TOOL_NAMES = [
802
1126
  "mesh_record_note",
803
1127
  "mesh_forget_note",
804
1128
  "mesh_reconcile_ledger",
805
- "mesh_requeue_held_events",
806
1129
  "mesh_mission_upsert",
807
1130
  "mesh_mission_list",
808
1131
  "mesh_review_inbox",
@@ -1055,8 +1378,54 @@ function isDowngrade(current, target) {
1055
1378
  return direction < 0;
1056
1379
  }
1057
1380
 
1058
- // src/ws-protocol.ts
1059
- var DAEMON_TO_SERVER_WS_MSGS = [
1381
+ // src/protocol/envelope.ts
1382
+ function isRecord(value) {
1383
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1384
+ }
1385
+ function isNonEmptyString(value) {
1386
+ return typeof value === "string" && value.length > 0;
1387
+ }
1388
+ function isFiniteNumber(value) {
1389
+ return typeof value === "number" && Number.isFinite(value);
1390
+ }
1391
+ function makeTypeGuard(names) {
1392
+ const set = new Set(names);
1393
+ return (value) => typeof value === "string" && set.has(value);
1394
+ }
1395
+ function decodeTypeField(raw, isType) {
1396
+ if (!isRecord(raw)) return null;
1397
+ if (!isType(raw.type)) return null;
1398
+ return { type: raw.type, frame: raw };
1399
+ }
1400
+ function readEnvelopeFields(frame) {
1401
+ return {
1402
+ ...isNonEmptyString(frame.id) ? { id: frame.id } : {},
1403
+ ...isFiniteNumber(frame.timestamp) ? { timestamp: frame.timestamp } : {}
1404
+ };
1405
+ }
1406
+
1407
+ // src/protocol/daemon-server.ts
1408
+ var DAEMON_STATUS_EVENT_NAMES = [
1409
+ "agent:generating_started",
1410
+ "agent:waiting_approval",
1411
+ "agent:waiting_choice",
1412
+ "agent:generating_completed",
1413
+ "agent:stopped",
1414
+ "monitor:no_progress",
1415
+ /** Legacy alias for `monitor:no_progress`, still emitted by older daemons. */
1416
+ "monitor:long_generating"
1417
+ ];
1418
+ var isDaemonStatusEventName = makeTypeGuard(DAEMON_STATUS_EVENT_NAMES);
1419
+ var RELEASE_CHANNELS = ["stable", "preview"];
1420
+ var NPM_UPDATE_TAGS = ["latest", "next"];
1421
+ var VERSION_UPDATE_REASONS = ["force_update_below", "major_minor_mismatch", "patch_mismatch", "daemon_ahead"];
1422
+ var P2P_SIGNAL_TYPES = ["p2p_ready", "p2p_offer", "p2p_answer", "p2p_ice"];
1423
+ var isP2PSignalType = makeTypeGuard(P2P_SIGNAL_TYPES);
1424
+ var DAEMON_P2P_SIGNAL_TYPES = ["p2p_offer", "p2p_ice"];
1425
+ var isDaemonP2PSignalType = makeTypeGuard(DAEMON_P2P_SIGNAL_TYPES);
1426
+ var MESH_P2P_SIGNAL_TYPES = ["mesh_p2p_ready", "mesh_p2p_offer", "mesh_p2p_answer", "mesh_p2p_ice"];
1427
+ var isMeshP2PSignalType = makeTypeGuard(MESH_P2P_SIGNAL_TYPES);
1428
+ var DAEMON_TO_SERVER_TYPES = [
1060
1429
  "auth",
1061
1430
  "status_report",
1062
1431
  "status_heartbeat",
@@ -1064,10 +1433,29 @@ var DAEMON_TO_SERVER_WS_MSGS = [
1064
1433
  "command_result",
1065
1434
  "error",
1066
1435
  "agent_event",
1067
- "log",
1068
- "beacon_vectors"
1436
+ "beacon_vectors",
1437
+ "daemon_mesh_command",
1438
+ "p2p_offer",
1439
+ "p2p_ice"
1069
1440
  ];
1070
- var SERVER_TO_DAEMON_WS_MSGS = [
1441
+ var isDaemonToServerType = makeTypeGuard(DAEMON_TO_SERVER_TYPES);
1442
+ function decodeDaemonToServer(raw) {
1443
+ if (!isRecord(raw) || !isDaemonToServerType(raw.type)) return null;
1444
+ if (raw.type === "daemon_mesh_command") {
1445
+ return {
1446
+ type: "daemon_mesh_command",
1447
+ requestId: typeof raw.requestId === "string" ? raw.requestId : String(raw.requestId ?? ""),
1448
+ targetDaemonId: typeof raw.targetDaemonId === "string" ? raw.targetDaemonId : "",
1449
+ command: raw.command,
1450
+ args: isRecord(raw.args) ? raw.args : {},
1451
+ timestamp: typeof raw.timestamp === "number" ? raw.timestamp : Date.now()
1452
+ };
1453
+ }
1454
+ if (!isRecord(raw.payload)) return null;
1455
+ if (raw.type === "auth" && !isNonEmptyString(raw.payload.token)) return null;
1456
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
1457
+ }
1458
+ var SERVER_TO_DAEMON_CONTROL_TYPES = [
1071
1459
  "auth_ok",
1072
1460
  "auth_error",
1073
1461
  "machine_evicted",
@@ -1078,66 +1466,2434 @@ var SERVER_TO_DAEMON_WS_MSGS = [
1078
1466
  "command",
1079
1467
  "agent_command",
1080
1468
  "resolve_action",
1081
- "beacon_vectors_result"
1469
+ "beacon_vectors_result",
1470
+ "daemon_mesh_result",
1471
+ "p2p_ready",
1472
+ "p2p_offer",
1473
+ "p2p_answer",
1474
+ "p2p_ice",
1475
+ "mesh_p2p_ready",
1476
+ "mesh_p2p_offer",
1477
+ "mesh_p2p_answer",
1478
+ "mesh_p2p_ice"
1479
+ ];
1480
+ var isServerToDaemonControlType = makeTypeGuard(SERVER_TO_DAEMON_CONTROL_TYPES);
1481
+ function isServerDirectCommandMsg(msg) {
1482
+ return !isServerToDaemonControlType(msg.type);
1483
+ }
1484
+ var DIRECT_COMMAND_TYPE_PATTERN = /^[a-z][a-z0-9_:.-]{0,63}$/;
1485
+ function isDaemonDirectCommandType(value) {
1486
+ return typeof value === "string" && DIRECT_COMMAND_TYPE_PATTERN.test(value) && !isServerToDaemonControlType(value);
1487
+ }
1488
+ function decodeServerToDaemon(raw) {
1489
+ if (!isRecord(raw) || typeof raw.type !== "string") return null;
1490
+ const relay = {
1491
+ ...readEnvelopeFields(raw),
1492
+ ...isNonEmptyString(raw.source) ? { source: raw.source } : {}
1493
+ };
1494
+ if (raw.type === "beacon_vectors_result" || raw.type === "daemon_mesh_result") {
1495
+ if (!isNonEmptyString(raw.requestId)) return null;
1496
+ const base = { requestId: raw.requestId, success: raw.success === true };
1497
+ if (raw.type === "beacon_vectors_result") {
1498
+ return {
1499
+ type: "beacon_vectors_result",
1500
+ ...base,
1501
+ ...Array.isArray(raw.reports) ? { reports: raw.reports } : {},
1502
+ ...typeof raw.truncated === "number" ? { truncated: raw.truncated } : {},
1503
+ ...typeof raw.error === "string" ? { error: raw.error } : {}
1504
+ };
1505
+ }
1506
+ return {
1507
+ type: "daemon_mesh_result",
1508
+ ...base,
1509
+ ..."result" in raw ? { result: raw.result } : {},
1510
+ ...typeof raw.error === "string" ? { error: raw.error } : {}
1511
+ };
1512
+ }
1513
+ if (!isRecord(raw.payload)) return null;
1514
+ if (isServerToDaemonControlType(raw.type)) {
1515
+ return { type: raw.type, payload: raw.payload, ...relay };
1516
+ }
1517
+ if (!isDaemonDirectCommandType(raw.type)) return null;
1518
+ return { type: raw.type, payload: raw.payload, ...relay };
1519
+ }
1520
+
1521
+ // src/protocol/dashboard-server.ts
1522
+ var SERVER_STATUS_EVENT_NAMES = [
1523
+ "daemon:disconnect",
1524
+ "team:session_viewed",
1525
+ "team:view_request",
1526
+ "team:view_request_approved",
1527
+ "team:view_request_rejected"
1528
+ ];
1529
+ var DASHBOARD_STATUS_EVENT_NAMES = [...DAEMON_STATUS_EVENT_NAMES, ...SERVER_STATUS_EVENT_NAMES];
1530
+ var isDashboardStatusEventName = makeTypeGuard(DASHBOARD_STATUS_EVENT_NAMES);
1531
+ var SYSTEM_ANNOUNCEMENT_TYPES = ["info", "warning", "critical"];
1532
+ var USER_SESSION_TO_DASHBOARD_TYPES = [
1533
+ "connected",
1534
+ "initial_state",
1535
+ "daemon_status",
1536
+ "status_event",
1537
+ "system_announcement",
1538
+ "auth_error",
1539
+ "heartbeat",
1540
+ "p2p_offer",
1541
+ "p2p_ice"
1542
+ ];
1543
+ var isUserSessionToDashboardType = makeTypeGuard(USER_SESSION_TO_DASHBOARD_TYPES);
1544
+ function decodeUserSessionToDashboard(raw) {
1545
+ if (!isRecord(raw) || !isUserSessionToDashboardType(raw.type)) return null;
1546
+ if (raw.type === "heartbeat") {
1547
+ return { type: "heartbeat", payload: isRecord(raw.payload) ? raw.payload : {}, ...readEnvelopeFields(raw) };
1548
+ }
1549
+ if (!isRecord(raw.payload)) return null;
1550
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
1551
+ }
1552
+ var DASHBOARD_TO_USER_SESSION_TYPES = ["heartbeat", "refresh", "p2p_ready", "p2p_answer", "p2p_ice"];
1553
+ var isDashboardToUserSessionType = makeTypeGuard(DASHBOARD_TO_USER_SESSION_TYPES);
1554
+ var DASHBOARD_P2P_SIGNAL_TYPES = ["p2p_ready", "p2p_answer", "p2p_ice"];
1555
+ var isDashboardP2PSignalType = makeTypeGuard(DASHBOARD_P2P_SIGNAL_TYPES);
1556
+ function decodeDashboardToUserSession(raw) {
1557
+ if (!isRecord(raw) || !isDashboardToUserSessionType(raw.type)) return null;
1558
+ if (raw.type === "heartbeat") return { type: "heartbeat", ...readEnvelopeFields(raw) };
1559
+ if (raw.type === "refresh") return { type: "refresh" };
1560
+ if (!isRecord(raw.payload) || typeof raw.payload.daemonId !== "string") return null;
1561
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
1562
+ }
1563
+ var SHARED_SESSION_TO_VIEWER_TYPES = [
1564
+ "share:connected",
1565
+ "share:revoked",
1566
+ "share:expired",
1567
+ "share:error",
1568
+ "share:viewer_count",
1569
+ "p2p_offer",
1570
+ "p2p_ice"
1571
+ ];
1572
+ var isSharedSessionToViewerType = makeTypeGuard(SHARED_SESSION_TO_VIEWER_TYPES);
1573
+ var VIEWER_TO_SHARED_SESSION_TYPES = ["p2p_ready", "p2p_offer", "p2p_answer", "p2p_ice"];
1574
+ var isViewerToSharedSessionType = makeTypeGuard(VIEWER_TO_SHARED_SESSION_TYPES);
1575
+ function decodeViewerToSharedSession(raw) {
1576
+ if (!isRecord(raw) || !isViewerToSharedSessionType(raw.type)) return null;
1577
+ const payload = isRecord(raw.payload) ? raw.payload : {};
1578
+ return { type: raw.type, payload, ...readEnvelopeFields(raw) };
1579
+ }
1580
+
1581
+ // src/protocol/dashboard-daemon-p2p.ts
1582
+ function isChunkType(value) {
1583
+ return typeof value === "string" && value.endsWith("_chunk") && value.length > "_chunk".length;
1584
+ }
1585
+ function readChunkFields(frame) {
1586
+ if (!isNonEmptyString(frame.chunkId)) return null;
1587
+ if (!Number.isInteger(frame.index) || !Number.isInteger(frame.total)) return null;
1588
+ if (typeof frame.data !== "string") return null;
1589
+ return {
1590
+ ...isNonEmptyString(frame.id) ? { id: frame.id } : {},
1591
+ chunkId: frame.chunkId,
1592
+ index: frame.index,
1593
+ total: frame.total,
1594
+ data: frame.data
1595
+ };
1596
+ }
1597
+ var DASHBOARD_TO_DAEMON_P2P_TYPES = [
1598
+ "ping",
1599
+ "pong",
1600
+ "command",
1601
+ "input",
1602
+ "pty_input",
1603
+ "pty_resize",
1604
+ "screenshot_start",
1605
+ "screenshot_stop",
1606
+ "subscribe",
1607
+ "unsubscribe",
1608
+ "seqscribe_session_interest",
1609
+ "read",
1610
+ "write",
1611
+ "list"
1612
+ ];
1613
+ var isDashboardToDaemonP2PType = makeTypeGuard(DASHBOARD_TO_DAEMON_P2P_TYPES);
1614
+ function isDashboardToDaemonChunkType(value) {
1615
+ return isChunkType(value) && isDashboardToDaemonP2PType(value.slice(0, -"_chunk".length));
1616
+ }
1617
+ var DASHBOARD_REQUEST_TYPES = /* @__PURE__ */ new Set(["command", "input", "read", "write", "list"]);
1618
+ function decodeDashboardToDaemonP2PChunk(raw) {
1619
+ if (!isRecord(raw) || !isDashboardToDaemonChunkType(raw.type)) return null;
1620
+ const fields = readChunkFields(raw);
1621
+ return fields ? { type: raw.type, ...fields } : null;
1622
+ }
1623
+ function decodeDashboardToDaemonP2P(raw) {
1624
+ if (!isRecord(raw) || !isDashboardToDaemonP2PType(raw.type)) return null;
1625
+ if (DASHBOARD_REQUEST_TYPES.has(raw.type) && !isNonEmptyString(raw.id)) return null;
1626
+ return raw;
1627
+ }
1628
+ var DAEMON_TO_DASHBOARD_P2P_TYPES = [
1629
+ "ping",
1630
+ "pong",
1631
+ "p2p_evicted",
1632
+ "status_report",
1633
+ "status_event",
1634
+ "topic_update",
1635
+ "topic_update_chunk",
1636
+ "session_output",
1637
+ "session_output_chunk",
1638
+ "session_io_error",
1639
+ "command_result",
1640
+ "command_result_chunk",
1641
+ "response"
1082
1642
  ];
1083
- function isDaemonToServerWsMsg(value) {
1084
- return typeof value === "string" && DAEMON_TO_SERVER_WS_MSGS.includes(value);
1643
+ var isDaemonToDashboardP2PType = makeTypeGuard(DAEMON_TO_DASHBOARD_P2P_TYPES);
1644
+ function decodeDaemonToDashboardP2P(raw) {
1645
+ if (!isRecord(raw)) return null;
1646
+ if (raw.type === void 0 && isNonEmptyString(raw.id) && typeof raw.success === "boolean") {
1647
+ return { ...raw, type: "response" };
1648
+ }
1649
+ if (!isDaemonToDashboardP2PType(raw.type)) return null;
1650
+ switch (raw.type) {
1651
+ case "ping":
1652
+ case "pong":
1653
+ case "p2p_evicted":
1654
+ return raw;
1655
+ case "status_report":
1656
+ case "status_event":
1657
+ return isRecord(raw.payload) ? raw : null;
1658
+ case "topic_update":
1659
+ return isRecord(raw.update) ? raw : null;
1660
+ case "topic_update_chunk":
1661
+ case "command_result_chunk":
1662
+ case "session_output_chunk": {
1663
+ const fields = readChunkFields(raw);
1664
+ if (!fields) return null;
1665
+ if (raw.type === "session_output_chunk") {
1666
+ return isNonEmptyString(raw.sessionId) ? { type: raw.type, sessionId: raw.sessionId, ...fields } : null;
1667
+ }
1668
+ return { type: raw.type, ...fields };
1669
+ }
1670
+ case "session_output":
1671
+ return isNonEmptyString(raw.sessionId) && typeof raw.data === "string" ? raw : null;
1672
+ case "session_io_error":
1673
+ return isNonEmptyString(raw.sessionId) ? raw : null;
1674
+ case "command_result":
1675
+ case "response":
1676
+ return isNonEmptyString(raw.id) ? raw : null;
1677
+ }
1085
1678
  }
1086
- function isServerToDaemonWsMsg(value) {
1087
- return typeof value === "string" && SERVER_TO_DAEMON_WS_MSGS.includes(value);
1679
+ var DASHBOARD_P2P_MESSAGE_KINDS = [
1680
+ .../* @__PURE__ */ new Set([...DASHBOARD_TO_DAEMON_P2P_TYPES, ...DAEMON_TO_DASHBOARD_P2P_TYPES])
1681
+ ];
1682
+
1683
+ // src/ws-protocol.ts
1684
+ var DAEMON_TO_SERVER_WS_MSGS = DAEMON_TO_SERVER_TYPES;
1685
+ var SERVER_TO_DAEMON_WS_MSGS = SERVER_TO_DAEMON_CONTROL_TYPES;
1686
+ var isDaemonToServerWsMsg = isDaemonToServerType;
1687
+ var isServerToDaemonWsMsg = isServerToDaemonControlType;
1688
+ function normalizeAuthOkLimits(raw) {
1689
+ if (!raw || typeof raw !== "object") return null;
1690
+ const src = raw;
1691
+ const num = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
1692
+ return {
1693
+ maxP2Pconnections: num(
1694
+ src.maxP2Pconnections !== void 0 ? src.maxP2Pconnections : src.maxP2PConnections,
1695
+ -1
1696
+ ),
1697
+ screenshotIntervalSeconds: num(src.screenshotIntervalSeconds, 0),
1698
+ dailyScreenshotMinutes: num(src.dailyScreenshotMinutes, -1),
1699
+ maxMachines: num(src.maxMachines, -1)
1700
+ };
1088
1701
  }
1089
1702
 
1090
1703
  // src/interactive-prompt-constants.ts
1091
1704
  var CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX = "Claude TUI review page is not focused";
1092
1705
  var CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX = "Claude TUI answer delivered but not confirmed";
1706
+
1707
+ // src/session-status.ts
1708
+ var SESSION_STATUSES = [
1709
+ "idle",
1710
+ "generating",
1711
+ "waiting_approval",
1712
+ "waiting_choice",
1713
+ "finalizing",
1714
+ "error",
1715
+ "stopped",
1716
+ "starting",
1717
+ "panel_hidden",
1718
+ "not_monitored",
1719
+ "disconnected"
1720
+ ];
1721
+ var RECENT_SESSION_BUCKETS = ["needs_attention", "working", "task_complete", "idle"];
1722
+ var SESSION_STATUS_CLASS = {
1723
+ generating: "working",
1724
+ finalizing: "working",
1725
+ starting: "working",
1726
+ waiting_approval: "blocked",
1727
+ waiting_choice: "blocked",
1728
+ idle: "ready",
1729
+ panel_hidden: "ready",
1730
+ not_monitored: "ready",
1731
+ error: "dead",
1732
+ stopped: "dead",
1733
+ disconnected: "dead"
1734
+ };
1735
+ var SESSION_STATUS_ALIASES = {
1736
+ running: "generating",
1737
+ streaming: "generating",
1738
+ busy: "generating",
1739
+ working: "generating",
1740
+ loading: "generating",
1741
+ loading_reference: "generating",
1742
+ thinking: "generating",
1743
+ active: "generating",
1744
+ // Status-lane refinements of a turn that is still owned by the agent.
1745
+ no_progress: "generating",
1746
+ long_generating: "generating",
1747
+ initializing: "starting",
1748
+ waiting: "waiting_approval"
1749
+ };
1750
+ var SESSION_STATUS_SET = new Set(SESSION_STATUSES);
1751
+ function isSessionStatus(value) {
1752
+ return typeof value === "string" && SESSION_STATUS_SET.has(value);
1753
+ }
1754
+ function normalizeSessionStatus(raw) {
1755
+ if (typeof raw !== "string") return null;
1756
+ const value = raw.trim().toLowerCase();
1757
+ if (SESSION_STATUS_SET.has(value)) return value;
1758
+ return SESSION_STATUS_ALIASES[value] ?? null;
1759
+ }
1760
+ function classifySessionStatus(raw) {
1761
+ const status = normalizeSessionStatus(raw);
1762
+ return status ? SESSION_STATUS_CLASS[status] : "unknown";
1763
+ }
1764
+ function isWorkingStatus(raw) {
1765
+ return classifySessionStatus(raw) === "working";
1766
+ }
1767
+ function isBlockedStatus(raw) {
1768
+ return classifySessionStatus(raw) === "blocked";
1769
+ }
1770
+ function isReadyStatus(raw) {
1771
+ return classifySessionStatus(raw) === "ready";
1772
+ }
1773
+ function isDeadStatus(raw) {
1774
+ return classifySessionStatus(raw) === "dead";
1775
+ }
1776
+ function isBusyStatus(raw) {
1777
+ const cls = classifySessionStatus(raw);
1778
+ return cls === "working" || cls === "blocked";
1779
+ }
1780
+ function statusesOfClass(cls) {
1781
+ return SESSION_STATUSES.filter((status) => SESSION_STATUS_CLASS[status] === cls);
1782
+ }
1783
+
1784
+ // src/mesh-vocabulary.ts
1785
+ var MESH_TASK_STATUSES = ["pending", "assigned", "completed", "failed", "cancelled"];
1786
+ var MESH_TERMINAL_TASK_STATUSES = ["completed", "failed", "cancelled"];
1787
+ var MESH_TASK_MODES = ["code_change", "validation", "live_debug_readonly", "launch_app", "convergence"];
1788
+ var MESH_TASK_PRIORITIES = ["low", "normal", "high"];
1789
+ var MESH_THINKING_LEVELS = ["low", "medium", "high"];
1790
+ var MESH_DELIVERY_MODES = ["when_idle", "interrupt"];
1791
+ var MESH_SESSION_CLEANUP_MODES = ["preserve", "stop", "delete_stopped", "stop_and_delete"];
1792
+ var WORKER_REPORT_OUTCOMES = ["completed", "blocked", "failed"];
1793
+ var WORKER_BRANCH_STATES = [
1794
+ "merged_to_main",
1795
+ "pushed_feature_branch_needs_merge",
1796
+ "blocked_review",
1797
+ "cleanup_candidate",
1798
+ "not_mergeable"
1799
+ ];
1800
+ function makeGuard(values) {
1801
+ const set = new Set(values);
1802
+ return (value) => typeof value === "string" && set.has(value);
1803
+ }
1804
+ var isMeshTaskStatus = makeGuard(MESH_TASK_STATUSES);
1805
+ var isMeshTerminalTaskStatus = makeGuard(MESH_TERMINAL_TASK_STATUSES);
1806
+ var isMeshTaskMode = makeGuard(MESH_TASK_MODES);
1807
+ var isMeshTaskPriority = makeGuard(MESH_TASK_PRIORITIES);
1808
+ var isMeshThinkingLevel = makeGuard(MESH_THINKING_LEVELS);
1809
+ var isMeshDeliveryMode = makeGuard(MESH_DELIVERY_MODES);
1810
+ var isMeshSessionCleanupMode = makeGuard(MESH_SESSION_CLEANUP_MODES);
1811
+ var isWorkerReportOutcome = makeGuard(WORKER_REPORT_OUTCOMES);
1812
+ var isWorkerBranchState = makeGuard(WORKER_BRANCH_STATES);
1813
+ function enumOf(values, description) {
1814
+ return {
1815
+ type: "string",
1816
+ enum: [...values],
1817
+ ...description ? { description } : {}
1818
+ };
1819
+ }
1820
+
1821
+ // src/outbound-message.ts
1822
+ var outboundMessageIdCounter = 0;
1823
+ function mintMessageId(now = Date.now()) {
1824
+ try {
1825
+ const cryptoRef = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
1826
+ if (typeof cryptoRef?.randomUUID === "function") return `msg_${cryptoRef.randomUUID()}`;
1827
+ } catch {
1828
+ }
1829
+ outboundMessageIdCounter += 1;
1830
+ return `msg_${now}_${outboundMessageIdCounter}`;
1831
+ }
1832
+ var MESSAGE_ID_PREFIX = "msg_";
1833
+ function isMessageId(value) {
1834
+ return typeof value === "string" && value.length > MESSAGE_ID_PREFIX.length && value.startsWith(MESSAGE_ID_PREFIX);
1835
+ }
1836
+ var OUTBOUND_MESSAGE_ORIGINS = ["dashboard", "mcp", "mesh", "api", "cli"];
1837
+ function isOutboundMessageOrigin(value) {
1838
+ return typeof value === "string" && OUTBOUND_MESSAGE_ORIGINS.includes(value);
1839
+ }
1840
+ var SEND_POLICY_MODES = ["queue", "send_now", "interrupt"];
1841
+ function isSendPolicyMode(value) {
1842
+ return typeof value === "string" && SEND_POLICY_MODES.includes(value);
1843
+ }
1844
+ function isSendPolicy(value) {
1845
+ return !!value && typeof value === "object" && isSendPolicyMode(value.mode);
1846
+ }
1847
+ var SEND_REFUSAL_REASONS = [
1848
+ "not_ready",
1849
+ "send_in_flight",
1850
+ "not_generating",
1851
+ "not_supported",
1852
+ "platform_unsupported",
1853
+ "modal_parked",
1854
+ "interrupt_not_implemented",
1855
+ "interrupt_refused",
1856
+ "idle_timeout",
1857
+ "session_exited",
1858
+ "unsupported_input",
1859
+ "no_target",
1860
+ "bootstrap_pending",
1861
+ "duplicate_dispatch",
1862
+ "internal_error"
1863
+ ];
1864
+ function isSendRefusal(value) {
1865
+ return typeof value === "string" && SEND_REFUSAL_REASONS.includes(value);
1866
+ }
1867
+ var SUBMIT_OUTCOME_KINDS = ["delivered", "queued", "duplicate", "refused"];
1868
+ function isSubmitOutcome(value) {
1869
+ if (!value || typeof value !== "object") return false;
1870
+ const kind = value.kind;
1871
+ if (typeof kind !== "string" || !SUBMIT_OUTCOME_KINDS.includes(kind)) return false;
1872
+ if (kind === "queued") return typeof value.position === "number";
1873
+ if (kind === "duplicate") return typeof value.of === "string";
1874
+ if (kind === "refused") return isSendRefusal(value.reason);
1875
+ return true;
1876
+ }
1877
+ function isInputPartWire(value) {
1878
+ if (!value || typeof value !== "object") return false;
1879
+ const type = value.type;
1880
+ return type === "text" || type === "image" || type === "audio" || type === "video" || type === "resource" || type === "resource_link";
1881
+ }
1882
+ function isInputEnvelopeWire(value) {
1883
+ if (!value || typeof value !== "object") return false;
1884
+ const parts = value.parts;
1885
+ const textFallback = value.textFallback;
1886
+ return Array.isArray(parts) && parts.every(isInputPartWire) && typeof textFallback === "string";
1887
+ }
1888
+ function isOutboundMessage(value) {
1889
+ if (!value || typeof value !== "object") return false;
1890
+ const candidate = value;
1891
+ return isMessageId(candidate.messageId) && typeof candidate.sessionId === "string" && candidate.sessionId.length > 0 && isInputEnvelopeWire(candidate.input) && isOutboundMessageOrigin(candidate.origin) && isSendPolicy(candidate.policy) && typeof candidate.createdAt === "number";
1892
+ }
1893
+
1894
+ // src/mission-brief.ts
1895
+ var GOAL_MAX = 500;
1896
+ var LIST_ITEM_MAX = 200;
1897
+ var LIST_MAX_ITEMS = 12;
1898
+ var MISSION_BRIEF_RENDER_MAX_CHARS = 1200;
1899
+ function truncateString(value, max) {
1900
+ if (value.length <= max) return value;
1901
+ return `${value.slice(0, max - 1).trimEnd()}\u2026`;
1902
+ }
1903
+ function normalizeStringList(value, field, truncated) {
1904
+ if (value === void 0 || value === null) return void 0;
1905
+ if (!Array.isArray(value)) return void 0;
1906
+ const items = [];
1907
+ let itemTruncated = false;
1908
+ for (const raw of value) {
1909
+ if (typeof raw !== "string") continue;
1910
+ const trimmed = raw.trim();
1911
+ if (!trimmed) continue;
1912
+ if (trimmed.length > LIST_ITEM_MAX) itemTruncated = true;
1913
+ items.push(truncateString(trimmed, LIST_ITEM_MAX));
1914
+ }
1915
+ if (itemTruncated) truncated.push({ field, reason: "item_too_long" });
1916
+ if (items.length > LIST_MAX_ITEMS) {
1917
+ truncated.push({ field, reason: "list_too_long" });
1918
+ return items.slice(0, LIST_MAX_ITEMS);
1919
+ }
1920
+ return items.length > 0 ? items : void 0;
1921
+ }
1922
+ function normalizeMissionBrief(input) {
1923
+ const truncated = [];
1924
+ if (!input || typeof input !== "object") {
1925
+ return { brief: null, truncated };
1926
+ }
1927
+ const raw = input;
1928
+ const rawGoal = typeof raw.goal === "string" ? raw.goal.trim() : "";
1929
+ if (!rawGoal) {
1930
+ return { brief: null, truncated };
1931
+ }
1932
+ if (rawGoal.length > GOAL_MAX) truncated.push({ field: "goal", reason: "field_too_long" });
1933
+ const goal = truncateString(rawGoal, GOAL_MAX);
1934
+ const constraints = normalizeStringList(raw.constraints, "constraints", truncated);
1935
+ const doneCriteria = normalizeStringList(raw.doneCriteria ?? raw.done_criteria, "doneCriteria", truncated);
1936
+ const handoffNotes = normalizeStringList(raw.handoffNotes ?? raw.handoff_notes, "handoffNotes", truncated);
1937
+ const ownedPaths = normalizeStringList(raw.ownedPaths ?? raw.owned_paths, "ownedPaths", truncated);
1938
+ const brief = { goal };
1939
+ if (constraints) brief.constraints = constraints;
1940
+ if (doneCriteria) brief.doneCriteria = doneCriteria;
1941
+ if (handoffNotes) brief.handoffNotes = handoffNotes;
1942
+ if (ownedPaths) brief.ownedPaths = ownedPaths;
1943
+ return { brief, truncated };
1944
+ }
1945
+ function renderList(heading, items) {
1946
+ if (!items || items.length === 0) return [];
1947
+ return [`${heading}:`, ...items.map((item) => `- ${item}`)];
1948
+ }
1949
+ function renderMissionBriefBlock(brief) {
1950
+ const sections = [`Mission goal: ${brief.goal}`];
1951
+ sections.push(...renderList("Constraints", brief.constraints));
1952
+ sections.push(...renderList("Done when", brief.doneCriteria));
1953
+ sections.push(...renderList("Owned paths", brief.ownedPaths));
1954
+ sections.push(...renderList("Handoff notes", brief.handoffNotes));
1955
+ const full = sections.join("\n");
1956
+ if (full.length <= MISSION_BRIEF_RENDER_MAX_CHARS) return full;
1957
+ const marker = "\n(brief truncated)";
1958
+ const budget = MISSION_BRIEF_RENDER_MAX_CHARS - marker.length;
1959
+ const lines = full.split("\n");
1960
+ let acc = "";
1961
+ for (const line of lines) {
1962
+ const next = acc ? `${acc}
1963
+ ${line}` : line;
1964
+ if (next.length > budget) break;
1965
+ acc = next;
1966
+ }
1967
+ if (!acc) acc = truncateString(lines[0] ?? "", Math.max(budget, 0));
1968
+ return `${acc}${marker}`;
1969
+ }
1970
+
1971
+ // src/worker-protocol.ts
1972
+ var WORKER_TOOLS = [
1973
+ "report_completion",
1974
+ "progress_update",
1975
+ "peer_context_pull",
1976
+ "git_status",
1977
+ "git_log",
1978
+ "git_diff"
1979
+ ];
1980
+ var WORKER_TOOL_SET = new Set(WORKER_TOOLS);
1981
+ function isWorkerTool(value) {
1982
+ return typeof value === "string" && WORKER_TOOL_SET.has(value);
1983
+ }
1984
+ var WORKER_PROTOCOL_FOOTER_MARKER = "--- adhdev worker protocol ---";
1985
+ function hasWorkerProtocolFooter(body) {
1986
+ return typeof body === "string" && body.includes(WORKER_PROTOCOL_FOOTER_MARKER);
1987
+ }
1988
+ function renderWorkerProtocolFooter(input = {}) {
1989
+ const briefBlock = input.missionBrief ? renderMissionBriefBlock(input.missionBrief) : null;
1990
+ const lines = briefBlock ? [briefBlock, "", WORKER_PROTOCOL_FOOTER_MARKER] : [WORKER_PROTOCOL_FOOTER_MARKER];
1991
+ const scope = [];
1992
+ if (input.taskId) scope.push(`task ${input.taskId}`);
1993
+ if (input.taskMode) scope.push(`mode ${input.taskMode}`);
1994
+ if (input.difficulty) {
1995
+ if (isMeshTaskDifficulty(input.difficulty)) {
1996
+ scope.push(`difficulty ${input.difficulty}`);
1997
+ } else {
1998
+ console.warn(
1999
+ `[worker-protocol] task ${input.taskId ?? "(unknown)"}: dropping invalid difficulty '${input.difficulty}' from the worker footer (expected one of easy, medium, difficult, freeform)`
2000
+ );
2001
+ }
2002
+ }
2003
+ if (input.readonly) scope.push("read-only");
2004
+ if (scope.length) lines.push(`You are a delegated worker (${scope.join(", ")}).`);
2005
+ else lines.push("You are a delegated worker.");
2006
+ lines.push(
2007
+ "When your work is finished, blocked, or has failed, call `report_completion` exactly once. Its `summary` is recorded verbatim as the authoritative record of this task \u2014 your terminal is not scraped for it \u2014 so state what you did, what you found, and where you left the branch.",
2008
+ "For work that runs longer than a few minutes, call `progress_update` at natural checkpoints so the coordinator can see you are alive without polling.",
2009
+ "`peer_context_pull` shows what sibling tasks in this mission have reported; `git_status` / `git_diff` / `git_log` inspect your own workspace \u2014 all three REQUIRE the absolute path to it as `workspace`.",
2010
+ "You have no coordinator tools (no `mesh_*`) by design: do not enqueue, dispatch, or restart anything. If you need a decision from the coordinator, finish with `report_completion` and outcome `blocked`, listing what you need in `blockers`.",
2011
+ "On a code-changing task, `report_completion` with outcome `completed` requires `touched_files` \u2014 send `[]` if you changed nothing, omitting the field is what gets refused. `blocked`/`failed` never need it, and a read-only task should omit it or send `[]`.",
2012
+ "If `report_completion` is refused, the response carries `validationErrors` (or a `hint`) naming exactly what to fix \u2014 correct that field and call it again; a refusal records nothing."
2013
+ );
2014
+ if (input.enclosedHandoffNotes && input.enclosedHandoffNotes > 0) {
2015
+ lines.push(
2016
+ `The ${input.enclosedHandoffNotes} handoff note(s) above were written by agents who touched this code before you; honour their conflict guidance and add your own in \`handoff_notes\` when you report.`
2017
+ );
2018
+ }
2019
+ return lines.join("\n");
2020
+ }
2021
+ function stripWorkerProtocolFooter(body) {
2022
+ if (typeof body !== "string") return body;
2023
+ const at = body.indexOf(WORKER_PROTOCOL_FOOTER_MARKER);
2024
+ if (at < 0) return body;
2025
+ return body.slice(0, at).replace(/\s+$/, "");
2026
+ }
2027
+ function appendWorkerProtocolFooter(body, input = {}) {
2028
+ if (hasWorkerProtocolFooter(body)) return body;
2029
+ const trimmed = body.replace(/\s+$/, "");
2030
+ return `${trimmed}
2031
+
2032
+ ${renderWorkerProtocolFooter(input)}`;
2033
+ }
2034
+ function renderCoordinatorWorkerSection() {
2035
+ return [
2036
+ "## Workers",
2037
+ "",
2038
+ `Every task you dispatch is delivered with a worker protocol footer. Workers hold exactly these tools: ${WORKER_TOOLS.map((tool) => `\`${tool}\``).join(", ")} \u2014 and no \`mesh_*\` tools.`,
2039
+ "- A worker finishes by calling `report_completion`; its structured report (outcome, summary, touched files, branch state, handoff notes) is what reaches you as the completion event. Read that report \u2014 do not re-derive the outcome from `mesh_read_chat` or the terminal unless the report is missing.",
2040
+ "- `progress_update` from a worker arrives as a lightweight progress note. Do NOT poll `mesh_status`, `mesh_view_queue` or `mesh_read_chat` to check on a running worker; completion, progress, blocked and failure all arrive as events.",
2041
+ "- To reach a busy worker mid-task use `mesh_notify_worker`: the memo is delivered on the worker's next tool call (or when it becomes idle). A worker that reports `blocked` is asking you for a decision \u2014 answer it with `mesh_send_task` to the same session.",
2042
+ "- `mesh_status` is for node health and capacity before delegating, never for progress.",
2043
+ "- A `code_change` task's declared `owned_paths` (H1) is enforced at claim time: a second `code_change` task whose `owned_paths` overlaps an already-claimed task's is refused rather than silently racing it. A worker's `report_completion.touched_files` is compared against its own task's declaration afterward and any mismatch is surfaced back to you as evidence \u2014 it is never a validation failure, since a worker often cannot know its exact final file list at enqueue time."
2044
+ ].join("\n");
2045
+ }
2046
+
2047
+ // src/turn-evidence.ts
2048
+ var MESH_TOPIC_PROTOCOL_VERSION = 2;
2049
+ var EVIDENCE_SOURCE_IDS = [
2050
+ "fsm_edge",
2051
+ "short_gen_inline",
2052
+ "completion_flush_genuine",
2053
+ "completion_flush_weak",
2054
+ "monitor_final_summary",
2055
+ "pre_cleanup_transcript",
2056
+ "stall_transcript",
2057
+ "startup_grace_collapse",
2058
+ "acp_prompt_response",
2059
+ "cdp_state",
2060
+ "approval_gate",
2061
+ "modal_button",
2062
+ "mesh_stall_watchdog",
2063
+ "status_monitor",
2064
+ "pty_exit",
2065
+ "provider_error",
2066
+ "coordinator_probe",
2067
+ "mcp_probe",
2068
+ "worker_tool",
2069
+ "dispatch",
2070
+ "input_service",
2071
+ "operator",
2072
+ "intentional_cleanup",
2073
+ "scheduler",
2074
+ "git_probe",
2075
+ "session_registry"
2076
+ ];
2077
+ var TURN_SCOPES = ["mesh_queue", "mesh_direct", "plain"];
2078
+ var RECLAIMING_SEND_REFUSALS = ["session_exited", "no_target", "unsupported_input"];
2079
+ var DELIVERY_OUTCOMES = ["delivered", "queued"];
2080
+ var DELIVERY_VIAS = ["local", "p2p"];
2081
+ var DISPATCH_FAILURE_REASONS = ["worker_absent", "transport_error", "spawn_failed", "rejected_by_worker", "timeout"];
2082
+ function sanitizeRefusalCode(value) {
2083
+ if (typeof value !== "string") return void 0;
2084
+ const normalized = value.trim().toLowerCase().replace(/[^a-z_]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
2085
+ if (!normalized) return void 0;
2086
+ return normalized.slice(0, 64);
2087
+ }
2088
+ var CONSUME_PROFILES = ["default", "native_source"];
2089
+ var SESSION_REBOUND_REASONS = ["restart", "live_holder"];
2090
+ var SUSPENSION_MODALS = ["approval", "choice"];
2091
+ var SUSPENSION_RESOLUTIONS = ["approved", "rejected", "answered"];
2092
+ var SUSPENSION_RESOLUTION_VIAS = ["modal_button", "auto_approve", "prompt_answer"];
2093
+ var TURN_END_STRENGTHS = ["genuine", "weak"];
2094
+ var TURN_END_BLOCK_REASONS = [
2095
+ "missing_final_assistant",
2096
+ "finalization_timeout",
2097
+ "terminal_block_hard_cap",
2098
+ "decoupled_completion"
2099
+ ];
2100
+ var NATIVE_TURN_OUTCOMES = ["completed", "aborted"];
2101
+ var LIVENESS_RESULTS = ["alive", "unknown", "read_failed", "dead"];
2102
+ var PROVIDER_FAILURES = ["auth_failed", "billing_failed"];
2103
+ var SESSION_ERROR_REASONS = ["provider_error", "adapter_error", "spawn_failed", "auth_failed", "billing_failed", "unknown", "daemon_restart"];
2104
+ var CANCEL_REASONS = ["operator_cancel", "intentional_cleanup", "task_removed", "mission_abandoned", "superseded"];
2105
+ var OPERATOR_STATUSES = ["completed", "failed"];
2106
+ var OPERATOR_STATUS_REASONS = ["operator_update", "refine_terminal", "validation_terminal"];
2107
+ var COORDINATOR_ACK_OUTCOMES = ["delivered", "queued", "duplicate"];
2108
+ var NO_PROGRESS_OBSERVED_STATUSES = [...SESSION_STATUSES, "unknown"];
2109
+ var HOLD_REASONS = [
2110
+ "await_delivery",
2111
+ "await_consume",
2112
+ "await_turn",
2113
+ "liveness",
2114
+ "hard_ceiling",
2115
+ "live_pending",
2116
+ "transcript_quiet",
2117
+ "weak_candidate",
2118
+ "suspension_before_consumed",
2119
+ // A genuine FSM end of a mesh turn whose worker holds a live worker-MCP bind:
2120
+ // the structured report is the primary evidence (design §F2), so the idle edge
2121
+ // only opens this hold (R9r) — a report commits (R17), a new busy edge cancels
2122
+ // it as a false idle (R12r), expiry commits weak (R13r).
2123
+ "await_report",
2124
+ // A worker report recorded while the session is still generating (R17g):
2125
+ // the report is the verdict, the idle edge is only awaited as corroboration
2126
+ // — a turn_end commits the report (R9t), expiry commits it anyway (R13t) so
2127
+ // a session whose FSM never shows the idle edge again does not wait for
2128
+ // liveness / hard_ceiling.
2129
+ "await_end"
2130
+ ];
2131
+ var TURN_OUTCOMES = ["completed", "failed", "cancelled"];
2132
+ var COMMIT_STRENGTHS = ["genuine", "weak", "tool_report", "operator"];
2133
+ var TURN_REASONS = [
2134
+ // commits
2135
+ "turn_end",
2136
+ "weak_end_confirmed",
2137
+ "transcript_final",
2138
+ "worker_reported",
2139
+ "finalization_timeout_no_response",
2140
+ "session_error",
2141
+ "provider_auth_failed",
2142
+ "provider_billing_failed",
2143
+ "operator_cancel",
2144
+ "intentional_cleanup",
2145
+ "task_removed",
2146
+ "mission_abandoned",
2147
+ "superseded",
2148
+ "operator_update",
2149
+ "refine_terminal",
2150
+ "validation_terminal",
2151
+ "hard_ceiling",
2152
+ "reclaim_budget_exhausted",
2153
+ "hollow_max_retries",
2154
+ "migration_orphan",
2155
+ // reclaims (generation + 1)
2156
+ "dispatch_refused_session_exited",
2157
+ "dispatch_refused_no_target",
2158
+ "dispatch_refused_unsupported_input",
2159
+ "dispatch_failed",
2160
+ "session_exit",
2161
+ "session_exit_before_turn",
2162
+ "session_dead",
2163
+ "hollow_completion",
2164
+ "assigned_stranded_dispatch_unconfirmed",
2165
+ "delivered_not_consumed_redrive",
2166
+ "delivered_no_turn_deadline"
2167
+ ];
2168
+ var NOTIFY_KINDS = [
2169
+ "completed",
2170
+ "failed",
2171
+ "cancelled",
2172
+ "stopped",
2173
+ "approval",
2174
+ "choice",
2175
+ "approval_resolved",
2176
+ "candidate",
2177
+ "no_progress",
2178
+ "progress",
2179
+ "late_completion",
2180
+ "mesh_event"
2181
+ ];
2182
+ var id = { t: "id" };
2183
+ var idOpt = { t: "id", optional: true };
2184
+ var bool = { t: "bool" };
2185
+ var boolOpt = { t: "bool", optional: true };
2186
+ var ms = { t: "ms" };
2187
+ var msOpt = { t: "ms", optional: true };
2188
+ var intOpt = { t: "int", optional: true };
2189
+ var en = (values) => ({ t: "enum", values });
2190
+ var enOpt = (values) => ({ t: "enum", values, optional: true });
2191
+ var EVIDENCE_ENVELOPE_FIELD_SPECS = {
2192
+ eventId: id,
2193
+ at: ms,
2194
+ source: en(EVIDENCE_SOURCE_IDS),
2195
+ sessionId: id,
2196
+ attemptRef: { t: "attempt_ref", optional: true },
2197
+ taskId: idOpt,
2198
+ observedBy: id
2199
+ };
2200
+ var TURN_EVIDENCE_FIELD_SPECS = {
2201
+ dispatch_accepted: {
2202
+ scope: en(TURN_SCOPES),
2203
+ messageId: id,
2204
+ meshId: idOpt,
2205
+ nodeId: idOpt,
2206
+ providerType: idOpt,
2207
+ attemptNo: intOpt,
2208
+ dispatchNonce: intOpt,
2209
+ consumeProfile: enOpt(CONSUME_PROFILES),
2210
+ maxTaskRetries: intOpt,
2211
+ coordinator: { t: "coordinator", optional: true }
2212
+ },
2213
+ delivered: { messageId: id, outcome: en(DELIVERY_OUTCOMES), via: en(DELIVERY_VIAS) },
2214
+ delivery_refused: { messageId: id, reason: en(SEND_REFUSAL_REASONS) },
2215
+ dispatch_failed: { workerAbsent: bool, reason: en(DISPATCH_FAILURE_REASONS), refusalCode: idOpt },
2216
+ duplicate_dispatch_refusal: { holderSessionId: id, holderAttemptId: idOpt },
2217
+ session_rebound: { toSessionId: id, reason: en(SESSION_REBOUND_REASONS) },
2218
+ turn_started: { retro: bool },
2219
+ suspension: { modal: en(SUSPENSION_MODALS), modalKey: idOpt },
2220
+ suspension_resolved: { resolution: en(SUSPENSION_RESOLUTIONS), via: en(SUSPENSION_RESOLUTION_VIAS) },
2221
+ turn_end: {
2222
+ strength: en(TURN_END_STRENGTHS),
2223
+ afterFinalizationTimeout: boolOpt,
2224
+ hollow: boolOpt,
2225
+ summary: { t: "summary_ref", optional: true },
2226
+ blockReason: enOpt(TURN_END_BLOCK_REASONS),
2227
+ releasedByHardCap: boolOpt,
2228
+ nativeOutcome: enOpt(NATIVE_TURN_OUTCOMES),
2229
+ live: { t: "live", optional: true },
2230
+ reportExpected: boolOpt
2231
+ },
2232
+ transcript_final: {
2233
+ selfAttributing: bool,
2234
+ nativeRead: bool,
2235
+ nativeMarker: { t: "native_marker", optional: true },
2236
+ live: { t: "live" },
2237
+ summary: { t: "summary_ref", optional: true },
2238
+ messageAt: msOpt
2239
+ },
2240
+ transcript_activity: { newestActivityAt: ms },
2241
+ no_progress: { stalledMs: ms, observedStatus: en(NO_PROGRESS_OBSERVED_STATUSES), finalAssistantPresent: bool },
2242
+ liveness: { result: en(LIVENESS_RESULTS) },
2243
+ process_exit: { exitCode: { t: "int", nullable: true }, providerFailure: enOpt(PROVIDER_FAILURES) },
2244
+ session_error: { reason: en(SESSION_ERROR_REASONS) },
2245
+ worker_report: {
2246
+ outcome: en(WORKER_REPORT_OUTCOMES),
2247
+ summary: { t: "summary_ref", optional: true },
2248
+ hasHandoffNotes: bool,
2249
+ branchState: enOpt(WORKER_BRANCH_STATES),
2250
+ touchedFileCount: intOpt
2251
+ },
2252
+ worker_progress: { note: { t: "summary_ref", optional: true } },
2253
+ git_side_effect: { dirty: bool, commitsSinceDispatch: { t: "int" }, attributable: bool },
2254
+ cancel: { reason: en(CANCEL_REASONS) },
2255
+ operator_status: { status: en(OPERATOR_STATUSES), reason: en(OPERATOR_STATUS_REASONS) },
2256
+ coordinator_ack: { notify: en(NOTIFY_KINDS), outcome: en(COORDINATOR_ACK_OUTCOMES) },
2257
+ hold_expired: { holdId: id, reason: en(HOLD_REASONS) }
2258
+ };
2259
+ var TURN_EVIDENCE_KINDS = Object.keys(TURN_EVIDENCE_FIELD_SPECS);
2260
+ var TERMINAL_CLASS_EVIDENCE_KINDS = [
2261
+ "turn_end",
2262
+ "transcript_final",
2263
+ "no_progress",
2264
+ "worker_report",
2265
+ "session_error",
2266
+ "process_exit",
2267
+ "cancel",
2268
+ "operator_status"
2269
+ ];
2270
+ var IDENTIFIER_RE = /^[^\s\u0000-\u001f\u007f]{1,256}$/;
2271
+ function makeGuard2(values) {
2272
+ const set = new Set(values);
2273
+ return (value) => typeof value === "string" && set.has(value);
2274
+ }
2275
+ var isEvidenceSourceId = makeGuard2(EVIDENCE_SOURCE_IDS);
2276
+ var isTurnEvidenceKind = makeGuard2(TURN_EVIDENCE_KINDS);
2277
+ var isTurnReason = makeGuard2(TURN_REASONS);
2278
+ var isNotifyKind = makeGuard2(NOTIFY_KINDS);
2279
+ var isHoldReason = makeGuard2(HOLD_REASONS);
2280
+ var isTurnOutcome = makeGuard2(TURN_OUTCOMES);
2281
+ var isCommitStrength = makeGuard2(COMMIT_STRENGTHS);
2282
+ function isRecord2(value) {
2283
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2284
+ }
2285
+ function isEvidenceIdentifier(value) {
2286
+ return typeof value === "string" && IDENTIFIER_RE.test(value);
2287
+ }
2288
+ function isFiniteNumber2(value) {
2289
+ return typeof value === "number" && Number.isFinite(value);
2290
+ }
2291
+ function isSummaryRef(value) {
2292
+ return isRecord2(value) && hasOnlyKeys(value, ["topic", "writer", "seq"]) && isEvidenceIdentifier(value.topic) && isEvidenceIdentifier(value.writer) && Number.isSafeInteger(value.seq) && value.seq >= 0;
2293
+ }
2294
+ function isTurnAttemptRef(value) {
2295
+ return isRecord2(value) && hasOnlyKeys(value, ["attemptId", "generation"]) && isEvidenceIdentifier(value.attemptId) && Number.isSafeInteger(value.generation) && value.generation >= 0;
2296
+ }
2297
+ function isLiveTurnPending(value) {
2298
+ return isRecord2(value) && hasOnlyKeys(value, ["modal", "adapterPending", "trailingTool", "newestActivityAt"]) && typeof value.modal === "boolean" && typeof value.adapterPending === "boolean" && typeof value.trailingTool === "boolean" && (value.newestActivityAt === void 0 || isFiniteNumber2(value.newestActivityAt));
2299
+ }
2300
+ function isNativeMarkerRef(value) {
2301
+ return isRecord2(value) && hasOnlyKeys(value, ["outcome", "turnId"]) && NATIVE_TURN_OUTCOMES.includes(value.outcome) && (value.turnId === void 0 || isEvidenceIdentifier(value.turnId));
2302
+ }
2303
+ function isCoordinatorIdentity(value) {
2304
+ return isRecord2(value) && hasOnlyKeys(value, ["daemonId", "coordinatorRunId", "sessionId"]) && isEvidenceIdentifier(value.daemonId) && isEvidenceIdentifier(value.coordinatorRunId) && (value.sessionId === void 0 || isEvidenceIdentifier(value.sessionId));
2305
+ }
2306
+ function hasOnlyKeys(value, allowed) {
2307
+ for (const key of Object.keys(value)) {
2308
+ if (!allowed.includes(key)) return false;
2309
+ }
2310
+ return true;
2311
+ }
2312
+ function fieldMatches(spec, value) {
2313
+ if (value === void 0) return spec.optional === true;
2314
+ switch (spec.t) {
2315
+ case "id":
2316
+ return isEvidenceIdentifier(value);
2317
+ case "enum":
2318
+ return typeof value === "string" && spec.values.includes(value);
2319
+ case "bool":
2320
+ return typeof value === "boolean";
2321
+ case "int":
2322
+ return value === null && spec.nullable === true || Number.isSafeInteger(value);
2323
+ case "ms":
2324
+ return isFiniteNumber2(value) && value >= 0;
2325
+ case "summary_ref":
2326
+ return isSummaryRef(value);
2327
+ case "attempt_ref":
2328
+ return isTurnAttemptRef(value);
2329
+ case "live":
2330
+ return isLiveTurnPending(value);
2331
+ case "native_marker":
2332
+ return isNativeMarkerRef(value);
2333
+ case "coordinator":
2334
+ return isCoordinatorIdentity(value);
2335
+ }
2336
+ }
2337
+ function isTurnEvidence(value) {
2338
+ if (!isRecord2(value) || !isTurnEvidenceKind(value.kind)) return false;
2339
+ const bodySpecs = TURN_EVIDENCE_FIELD_SPECS[value.kind];
2340
+ const envelopeSpecs = EVIDENCE_ENVELOPE_FIELD_SPECS;
2341
+ for (const key of Object.keys(value)) {
2342
+ if (key === "kind") continue;
2343
+ if (!(key in bodySpecs) && !(key in envelopeSpecs)) return false;
2344
+ }
2345
+ for (const [key, spec] of Object.entries(envelopeSpecs)) {
2346
+ if (!fieldMatches(spec, value[key])) return false;
2347
+ }
2348
+ for (const [key, spec] of Object.entries(bodySpecs)) {
2349
+ if (!fieldMatches(spec, value[key])) return false;
2350
+ }
2351
+ return true;
2352
+ }
2353
+ function isTerminalClassEvidenceKind(kind) {
2354
+ return TERMINAL_CLASS_EVIDENCE_KINDS.includes(kind);
2355
+ }
2356
+ var TURN_EVIDENCE_FLAGS = ["hollow", "afterFinalizationTimeout", "nativeMarker", "selfAttributing"];
2357
+ var MESH_TOPIC_ENTRY_KINDS = ["turn.evidence", "turn.committed", "turn.notify", "mesh.record"];
2358
+ var isMeshTopicEntryKind = makeGuard2(MESH_TOPIC_ENTRY_KINDS);
2359
+ function isOptionalId(value) {
2360
+ return value === void 0 || isEvidenceIdentifier(value);
2361
+ }
2362
+ function isGeneration(value) {
2363
+ return Number.isSafeInteger(value) && value >= 0;
2364
+ }
2365
+ function isProjectedScalars(value) {
2366
+ if (!isRecord2(value)) return false;
2367
+ for (const v of Object.values(value)) {
2368
+ if (!(v === null || typeof v === "number" || typeof v === "boolean" || typeof v === "string")) return false;
2369
+ }
2370
+ return true;
2371
+ }
2372
+ function isMeshTopicEntry(value) {
2373
+ if (!isRecord2(value)) return false;
2374
+ if (value.v !== MESH_TOPIC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.eventId) || !isFiniteNumber2(value.at)) return false;
2375
+ switch (value.k) {
2376
+ case "turn.evidence": {
2377
+ if (!isEvidenceIdentifier(value.attemptId) || !isGeneration(value.generation)) return false;
2378
+ if (!isEvidenceIdentifier(value.ownerDaemonId) || !isEvidenceIdentifier(value.sessionId) || !isOptionalId(value.taskId)) return false;
2379
+ if (!isTurnEvidenceKind(value.ev)) return false;
2380
+ if (value.strength !== void 0 && !TURN_END_STRENGTHS.includes(value.strength)) return false;
2381
+ if (value.flags !== void 0) {
2382
+ if (!isRecord2(value.flags)) return false;
2383
+ for (const [flag, on] of Object.entries(value.flags)) {
2384
+ if (!TURN_EVIDENCE_FLAGS.includes(flag) || typeof on !== "boolean") return false;
2385
+ }
2386
+ }
2387
+ if (value.evidence !== void 0 && !(isTurnEvidence(value.evidence) && value.evidence.kind === value.ev)) return false;
2388
+ return true;
2389
+ }
2390
+ case "turn.committed":
2391
+ return isEvidenceIdentifier(value.attemptId) && isGeneration(value.generation) && isOptionalId(value.taskId) && isTurnOutcome(value.outcome) && isCommitStrength(value.strength) && isTurnReason(value.reason);
2392
+ case "turn.notify":
2393
+ return isOptionalId(value.attemptId) && isNotifyKind(value.notify) && isEvidenceIdentifier(value.targetDaemonId) && isOptionalId(value.targetSessionId) && isOptionalId(value.taskId);
2394
+ case "mesh.record":
2395
+ return isEvidenceIdentifier(value.ledgerKind) && isOptionalId(value.nodeId) && isOptionalId(value.sessionId) && isOptionalId(value.taskId) && isProjectedScalars(value.payload);
2396
+ default:
2397
+ return false;
2398
+ }
2399
+ }
2400
+ function projectTurnEvidenceEntry(evidence, attempt) {
2401
+ const flags = {};
2402
+ if (evidence.kind === "turn_end") {
2403
+ if (evidence.hollow) flags.hollow = true;
2404
+ if (evidence.afterFinalizationTimeout) flags.afterFinalizationTimeout = true;
2405
+ }
2406
+ if (evidence.kind === "transcript_final") {
2407
+ if (evidence.nativeMarker) flags.nativeMarker = true;
2408
+ if (evidence.selfAttributing) flags.selfAttributing = true;
2409
+ }
2410
+ const taskId = evidence.taskId;
2411
+ return {
2412
+ v: MESH_TOPIC_PROTOCOL_VERSION,
2413
+ eventId: evidence.eventId,
2414
+ at: evidence.at,
2415
+ k: "turn.evidence",
2416
+ attemptId: attempt.attemptId,
2417
+ generation: attempt.generation,
2418
+ ownerDaemonId: attempt.ownerDaemonId,
2419
+ ...taskId ? { taskId } : {},
2420
+ sessionId: evidence.sessionId,
2421
+ ev: evidence.kind,
2422
+ ...evidence.kind === "turn_end" ? { strength: evidence.strength } : {},
2423
+ ...Object.keys(flags).length > 0 ? { flags } : {},
2424
+ evidence
2425
+ };
2426
+ }
2427
+
2428
+ // src/session-launch.ts
2429
+ var MODEL_AXIS_SOURCES = [
2430
+ /** Picked explicitly for this launch (dashboard dropdown, coordinator dialog). */
2431
+ "user",
2432
+ /** The dashboard dialog restored it from the last launch (browser-local memory). */
2433
+ "remembered",
2434
+ /** A mesh capability slot supplied it (or a difficulty preset the slot outranked). */
2435
+ "mesh_slot",
2436
+ /** An explicit per-task model / thinking level on a mesh queue task. */
2437
+ "task_override",
2438
+ /** Nothing was requested; the provider's default is known (discovery / manifest). */
2439
+ "provider_default",
2440
+ /** A value was requested without saying where it came from, or nothing is known. */
2441
+ "unspecified"
2442
+ ];
2443
+ function isModelAxisSource(value) {
2444
+ return typeof value === "string" && MODEL_AXIS_SOURCES.includes(value);
2445
+ }
2446
+ var SESSION_LAUNCHED_BY = ["dashboard", "mesh", "cli", "api", "restore"];
2447
+ function isSessionLaunchedBy(value) {
2448
+ return typeof value === "string" && SESSION_LAUNCHED_BY.includes(value);
2449
+ }
2450
+ var MODEL_SELECTION_HISTORY_LIMIT = 20;
2451
+ function effectiveModelSelectionValue(selection) {
2452
+ if (!selection) return void 0;
2453
+ const last = Array.isArray(selection.history) ? selection.history[selection.history.length - 1] : void 0;
2454
+ return last?.value ?? selection.current ?? selection.observed ?? launchModelSelectionValue(selection);
2455
+ }
2456
+ function launchModelSelectionValue(selection) {
2457
+ if (!selection) return void 0;
2458
+ const launch = Array.isArray(selection.history) ? selection.history.find((entry) => entry.via === "launch") : void 0;
2459
+ return launch?.value ?? selection.launchValue ?? selection.requested ?? selection.resolvedDefault;
2460
+ }
2461
+ function describeModelSelection(selection) {
2462
+ const value = effectiveModelSelectionValue(selection);
2463
+ if (!selection || !value) return void 0;
2464
+ const launched = launchModelSelectionValue(selection);
2465
+ return {
2466
+ value,
2467
+ ...launched && launched !== value ? { changedFrom: launched } : {},
2468
+ source: isModelAxisSource(selection.source) ? selection.source : "unspecified"
2469
+ };
2470
+ }
2471
+ var MODEL_IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/@[\]+-]{0,95}$/;
2472
+ function sanitizeModelIdentifier(value) {
2473
+ if (typeof value !== "string") return void 0;
2474
+ const trimmed = value.trim();
2475
+ return MODEL_IDENTIFIER_PATTERN.test(trimmed) ? trimmed : void 0;
2476
+ }
2477
+ function readString2(value) {
2478
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
2479
+ }
2480
+ function readFiniteNumber(value) {
2481
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
2482
+ }
2483
+ function parseModelSelection(raw) {
2484
+ if (!raw || typeof raw !== "object") return void 0;
2485
+ const record = raw;
2486
+ const history = [];
2487
+ if (Array.isArray(record.history)) {
2488
+ for (const entry of record.history) {
2489
+ if (!entry || typeof entry !== "object") continue;
2490
+ const e = entry;
2491
+ const value = readString2(e.value);
2492
+ const at = readFiniteNumber(e.at);
2493
+ const via = e.via === "launch" || e.via === "change_model" || e.via === "observed" ? e.via : void 0;
2494
+ if (value && at !== void 0 && via) history.push({ at, value, via });
2495
+ }
2496
+ }
2497
+ const requested = readString2(record.requested);
2498
+ const launchValue = readString2(record.launchValue);
2499
+ const resolvedDefault = readString2(record.resolvedDefault);
2500
+ const current = readString2(record.current);
2501
+ const observed = readString2(record.observed);
2502
+ const observedAt = readFiniteNumber(record.observedAt);
2503
+ return {
2504
+ source: isModelAxisSource(record.source) ? record.source : "unspecified",
2505
+ ...requested ? { requested } : {},
2506
+ ...launchValue ? { launchValue } : {},
2507
+ ...resolvedDefault ? { resolvedDefault } : {},
2508
+ ...current ? { current } : {},
2509
+ ...observed ? { observed } : {},
2510
+ ...observedAt !== void 0 ? { observedAt } : {},
2511
+ history: history.slice(-MODEL_SELECTION_HISTORY_LIMIT)
2512
+ };
2513
+ }
2514
+ function parseSessionLaunchRecord(raw) {
2515
+ if (!raw || typeof raw !== "object") return void 0;
2516
+ const record = raw;
2517
+ const sessionId = readString2(record.sessionId);
2518
+ const providerType = readString2(record.providerType);
2519
+ const launchedAt = readFiniteNumber(record.launchedAt);
2520
+ const model = parseModelSelection(record.model);
2521
+ const thinkingLevel = parseModelSelection(record.thinkingLevel);
2522
+ if (!sessionId || !providerType || launchedAt === void 0 || !model || !thinkingLevel) return void 0;
2523
+ const providerVersion = readString2(record.providerVersion);
2524
+ const workspace = readString2(record.workspace);
2525
+ const autoApproveModeId = readString2(record.autoApproveModeId);
2526
+ return {
2527
+ sessionId,
2528
+ providerType,
2529
+ ...providerVersion ? { providerVersion } : {},
2530
+ ...record.providerChannel === "stable" || record.providerChannel === "preview" ? { providerChannel: record.providerChannel } : {},
2531
+ launchedBy: isSessionLaunchedBy(record.launchedBy) ? record.launchedBy : "api",
2532
+ launchedAt,
2533
+ ...workspace ? { workspace } : {},
2534
+ model,
2535
+ thinkingLevel,
2536
+ ...autoApproveModeId ? { autoApproveModeId } : {}
2537
+ };
2538
+ }
2539
+
2540
+ // src/turn-ipc.ts
2541
+ var TURN_IPC_PROTOCOL_VERSION = 1;
2542
+ function isFiniteNumber3(value) {
2543
+ return typeof value === "number" && Number.isFinite(value);
2544
+ }
2545
+ function isNonNegativeInt(value) {
2546
+ return Number.isSafeInteger(value) && value >= 0;
2547
+ }
2548
+ function isOptionalId2(value) {
2549
+ return value === void 0 || isEvidenceIdentifier(value);
2550
+ }
2551
+ function hasOnlyKeys2(value, allowed) {
2552
+ for (const key of Object.keys(value)) {
2553
+ if (!allowed.includes(key)) return false;
2554
+ }
2555
+ return true;
2556
+ }
2557
+ var TURN_IPC_ERROR_CODES = ["daemon_required", "turn_ledger_unavailable", "ledger_not_owner"];
2558
+ function makeGuard3(values) {
2559
+ const set = new Set(values);
2560
+ return (value) => typeof value === "string" && set.has(value);
2561
+ }
2562
+ var isTurnIpcErrorCode = makeGuard3(TURN_IPC_ERROR_CODES);
2563
+ function isTurnIpcError(value) {
2564
+ return isRecord(value) && hasOnlyKeys2(value, ["code", "detail"]) && isTurnIpcErrorCode(value.code) && (value.detail === void 0 || typeof value.detail === "string");
2565
+ }
2566
+ var TURN_OBSERVE_VERDICTS = ["applied", "recorded", "rejected"];
2567
+ var isTurnObserveVerdict = makeGuard3(TURN_OBSERVE_VERDICTS);
2568
+ function isTurnObserveRequest(value) {
2569
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "evidence"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isTurnEvidence(value.evidence);
2570
+ }
2571
+ function decodeTurnObserveRequest(value) {
2572
+ return isTurnObserveRequest(value) ? value : null;
2573
+ }
2574
+ function isTurnAttemptRefValue(value) {
2575
+ return isRecord(value) && hasOnlyKeys2(value, ["attemptId", "generation"]) && isEvidenceIdentifier(value.attemptId) && isNonNegativeInt(value.generation);
2576
+ }
2577
+ function isTurnObserveResponse(value) {
2578
+ return isRecord(value) && hasOnlyKeys2(value, ["verdict", "attemptRef", "outcome"]) && isTurnObserveVerdict(value.verdict) && isTurnAttemptRefValue(value.attemptRef) && (value.outcome === void 0 || isTurnOutcomeValue(value.outcome));
2579
+ }
2580
+ var TURN_OUTCOMES_LOCAL = ["completed", "failed", "cancelled"];
2581
+ function isTurnOutcomeValue(value) {
2582
+ return typeof value === "string" && TURN_OUTCOMES_LOCAL.includes(value);
2583
+ }
2584
+ function decodeTurnObserveResponse(value) {
2585
+ return isTurnObserveResponse(value) ? value : null;
2586
+ }
2587
+ var MESH_RECORD_PAYLOAD_KEYS = [
2588
+ // Identifiers
2589
+ "taskId",
2590
+ "deliveryId",
2591
+ "attemptId",
2592
+ "missionId",
2593
+ "checkpointId",
2594
+ "promptId",
2595
+ "providerSessionId",
2596
+ "targetNoteId",
2597
+ // Routing / addressing
2598
+ "nodeId",
2599
+ "sessionId",
2600
+ "providerType",
2601
+ "transport",
2602
+ "attemptedSessionId",
2603
+ "holderSessionId",
2604
+ // Outcome enums
2605
+ "reason",
2606
+ "status",
2607
+ "outcome",
2608
+ "terminalKind",
2609
+ "event",
2610
+ "source",
2611
+ "intentionalStopReason",
2612
+ // Booleans
2613
+ "retryable",
2614
+ "rebound",
2615
+ "forced",
2616
+ "fallback",
2617
+ "membershipRemoved",
2618
+ "requestedForce",
2619
+ "removedByRemoteDaemon",
2620
+ "completedViaReady",
2621
+ "intentional",
2622
+ "weak",
2623
+ // Counters
2624
+ "attempt",
2625
+ "attemptCount",
2626
+ "count"
2627
+ ];
2628
+ var MESH_RECORD_PAYLOAD_KEY_SET = new Set(MESH_RECORD_PAYLOAD_KEYS);
2629
+ var MAX_MESH_RECORD_STRING = 200;
2630
+ function isProjectedScalarsValue(value) {
2631
+ if (!isRecord(value)) return false;
2632
+ for (const v of Object.values(value)) {
2633
+ if (v === null) continue;
2634
+ if (typeof v === "boolean" || typeof v === "number") continue;
2635
+ if (typeof v === "string") {
2636
+ if (v.length > MAX_MESH_RECORD_STRING) return false;
2637
+ continue;
2638
+ }
2639
+ return false;
2640
+ }
2641
+ return true;
2642
+ }
2643
+ function isMeshRecordPayload(value) {
2644
+ if (!isProjectedScalarsValue(value)) return false;
2645
+ for (const key of Object.keys(value)) {
2646
+ if (!MESH_RECORD_PAYLOAD_KEY_SET.has(key)) return false;
2647
+ }
2648
+ return true;
2649
+ }
2650
+ function isMeshRecordRequest(value) {
2651
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "ledgerKind", "nodeId", "sessionId", "taskId", "payload"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.ledgerKind) && isOptionalId2(value.nodeId) && isOptionalId2(value.sessionId) && isOptionalId2(value.taskId) && isMeshRecordPayload(value.payload);
2652
+ }
2653
+ function decodeMeshRecordRequest(value) {
2654
+ return isMeshRecordRequest(value) ? value : null;
2655
+ }
2656
+ function isMeshRecordResponse(value) {
2657
+ return isRecord(value) && hasOnlyKeys2(value, ["eventId", "seq"]) && isEvidenceIdentifier(value.eventId) && isNonNegativeInt(value.seq);
2658
+ }
2659
+ function decodeMeshRecordResponse(value) {
2660
+ return isMeshRecordResponse(value) ? value : null;
2661
+ }
2662
+ function isTurnCancelRequest(value) {
2663
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "attemptId", "taskId", "reason"])) return false;
2664
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2665
+ const hasAttempt = value.attemptId !== void 0;
2666
+ const hasTask = value.taskId !== void 0;
2667
+ if (hasAttempt === hasTask) return false;
2668
+ if (hasAttempt && !isEvidenceIdentifier(value.attemptId)) return false;
2669
+ if (hasTask && !isEvidenceIdentifier(value.taskId)) return false;
2670
+ return isTurnReason(value.reason);
2671
+ }
2672
+ function decodeTurnCancelRequest(value) {
2673
+ return isTurnCancelRequest(value) ? value : null;
2674
+ }
2675
+ function isTurnCancelResponse(value) {
2676
+ return isRecord(value) && hasOnlyKeys2(value, ["attemptRef", "verdict"]) && isTurnAttemptRefValue(value.attemptRef) && isTurnObserveVerdict(value.verdict);
2677
+ }
2678
+ function decodeTurnCancelResponse(value) {
2679
+ return isTurnCancelResponse(value) ? value : null;
2680
+ }
2681
+ var OPERATOR_STATUS_VALUES = ["completed", "failed"];
2682
+ var isOperatorStatusValue = makeGuard3(OPERATOR_STATUS_VALUES);
2683
+ var OPERATOR_STATUS_REASON_VALUES = ["operator_update", "refine_terminal", "validation_terminal"];
2684
+ var isOperatorStatusReasonValue = makeGuard3(OPERATOR_STATUS_REASON_VALUES);
2685
+ function isOperatorStatusRequest(value) {
2686
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "taskId", "status", "reason"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.taskId) && isOperatorStatusValue(value.status) && isOperatorStatusReasonValue(value.reason);
2687
+ }
2688
+ function decodeOperatorStatusRequest(value) {
2689
+ return isOperatorStatusRequest(value) ? value : null;
2690
+ }
2691
+ function isOperatorStatusResponse(value) {
2692
+ return isRecord(value) && hasOnlyKeys2(value, ["accepted"]) && value.accepted === true;
2693
+ }
2694
+ function decodeOperatorStatusResponse(value) {
2695
+ return isOperatorStatusResponse(value) ? value : null;
2696
+ }
2697
+ function isTurnQueryRequest(value) {
2698
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "attemptId", "sessionId", "state", "since", "tail"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isOptionalId2(value.taskId) && isOptionalId2(value.attemptId) && isOptionalId2(value.sessionId) && (value.state === void 0 || isEvidenceIdentifier(value.state)) && (value.since === void 0 || isFiniteNumber3(value.since)) && (value.tail === void 0 || isNonNegativeInt(value.tail));
2699
+ }
2700
+ function decodeTurnQueryRequest(value) {
2701
+ return isTurnQueryRequest(value) ? value : null;
2702
+ }
2703
+ var TURN_QUERY_ATTEMPT_ROW_KEYS = [
2704
+ "attemptId",
2705
+ "generation",
2706
+ "meshId",
2707
+ "taskId",
2708
+ "sessionId",
2709
+ "nodeId",
2710
+ "providerType",
2711
+ "state",
2712
+ "terminalOutcome",
2713
+ "terminalReason",
2714
+ "acceptedAt",
2715
+ "terminalAt"
2716
+ ];
2717
+ function isTurnQueryAttemptRow(value) {
2718
+ if (!isRecord(value) || !hasOnlyKeys2(value, TURN_QUERY_ATTEMPT_ROW_KEYS)) return false;
2719
+ if (!isEvidenceIdentifier(value.attemptId) || !isNonNegativeInt(value.generation)) return false;
2720
+ if (!isOptionalId2(value.meshId) || !isOptionalId2(value.taskId)) return false;
2721
+ if (!isEvidenceIdentifier(value.sessionId)) return false;
2722
+ if (!isOptionalId2(value.nodeId) || !isOptionalId2(value.providerType)) return false;
2723
+ if (typeof value.state !== "string") return false;
2724
+ if (value.terminalOutcome !== void 0 && !isTurnOutcomeValue(value.terminalOutcome)) return false;
2725
+ if (value.terminalReason !== void 0 && !isTurnReason(value.terminalReason)) return false;
2726
+ if (!isFiniteNumber3(value.acceptedAt)) return false;
2727
+ if (value.terminalAt !== void 0 && !isFiniteNumber3(value.terminalAt)) return false;
2728
+ return true;
2729
+ }
2730
+ var TURN_QUERY_EVENT_VERDICTS = ["applied", "recorded", "rejected", "forwarded"];
2731
+ var TURN_QUERY_EVENT_ROW_KEYS = ["eventId", "attemptId", "generation", "sessionId", "kind", "source", "verdict", "atMs"];
2732
+ function isTurnQueryEventRow(value) {
2733
+ if (!isRecord(value) || !hasOnlyKeys2(value, TURN_QUERY_EVENT_ROW_KEYS)) return false;
2734
+ if (!isEvidenceIdentifier(value.eventId)) return false;
2735
+ if (!isOptionalId2(value.attemptId)) return false;
2736
+ if (value.generation !== void 0 && !isNonNegativeInt(value.generation)) return false;
2737
+ if (!isEvidenceIdentifier(value.sessionId)) return false;
2738
+ if (typeof value.kind !== "string") return false;
2739
+ if (typeof value.source !== "string") return false;
2740
+ if (!TURN_QUERY_EVENT_VERDICTS.includes(value.verdict)) return false;
2741
+ if (!isFiniteNumber3(value.atMs)) return false;
2742
+ return true;
2743
+ }
2744
+ function isTurnQueryResponse(value) {
2745
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["attempts", "events", "replicationPending"])) return false;
2746
+ if (!Array.isArray(value.attempts) || !value.attempts.every(isTurnQueryAttemptRow)) return false;
2747
+ if (!Array.isArray(value.events) || !value.events.every(isTurnQueryEventRow)) return false;
2748
+ if (value.replicationPending !== void 0 && typeof value.replicationPending !== "boolean") return false;
2749
+ return true;
2750
+ }
2751
+ function decodeTurnQueryResponse(value) {
2752
+ return isTurnQueryResponse(value) ? value : null;
2753
+ }
2754
+ var MESH_INDEX_QUERY_WRITER_SCOPES = ["own", "fleet"];
2755
+ var isMeshIndexQueryWriterScope = makeGuard3(MESH_INDEX_QUERY_WRITER_SCOPES);
2756
+ function isMeshIndexQueryRequest(value) {
2757
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "ledgerKind", "sessionId", "taskId", "writer", "since", "tail"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isOptionalId2(value.ledgerKind) && isOptionalId2(value.sessionId) && isOptionalId2(value.taskId) && (value.writer === void 0 || isMeshIndexQueryWriterScope(value.writer)) && (value.since === void 0 || isFiniteNumber3(value.since)) && (value.tail === void 0 || isNonNegativeInt(value.tail));
2758
+ }
2759
+ function decodeMeshIndexQueryRequest(value) {
2760
+ return isMeshIndexQueryRequest(value) ? value : null;
2761
+ }
2762
+ var MESH_TOPIC_INDEX_ROW_KEYS = [
2763
+ "writer",
2764
+ "seq",
2765
+ "meshId",
2766
+ "eventId",
2767
+ "kind",
2768
+ "ledgerKind",
2769
+ "taskId",
2770
+ "sessionId",
2771
+ "nodeId",
2772
+ "atMs",
2773
+ "payload"
2774
+ ];
2775
+ function isMeshTopicIndexRow(value) {
2776
+ if (!isRecord(value) || !hasOnlyKeys2(value, MESH_TOPIC_INDEX_ROW_KEYS)) return false;
2777
+ if (!isEvidenceIdentifier(value.writer) || !isNonNegativeInt(value.seq)) return false;
2778
+ if (!isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.eventId)) return false;
2779
+ if (typeof value.kind !== "string") return false;
2780
+ if (!isOptionalId2(value.ledgerKind) || !isOptionalId2(value.taskId) || !isOptionalId2(value.sessionId) || !isOptionalId2(value.nodeId)) return false;
2781
+ if (!isFiniteNumber3(value.atMs)) return false;
2782
+ if (!isMeshRecordPayload(value.payload)) return false;
2783
+ return true;
2784
+ }
2785
+ function isMeshIndexQueryResponse(value) {
2786
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["rows", "replicationPending"])) return false;
2787
+ if (!Array.isArray(value.rows) || !value.rows.every(isMeshTopicIndexRow)) return false;
2788
+ if (value.replicationPending !== void 0 && typeof value.replicationPending !== "boolean") return false;
2789
+ return true;
2790
+ }
2791
+ function decodeMeshIndexQueryResponse(value) {
2792
+ return isMeshIndexQueryResponse(value) ? value : null;
2793
+ }
2794
+ var MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
2795
+ var isMeshMissionStatusValue = makeGuard3(MESH_MISSION_STATUSES);
2796
+ var MESH_MISSION_SOURCES = ["magi", "coordinator"];
2797
+ var isMeshMissionSourceValue = makeGuard3(MESH_MISSION_SOURCES);
2798
+ function isStringArray(value) {
2799
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
2800
+ }
2801
+ function isMissionBriefWire(value) {
2802
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["goal", "constraints", "doneCriteria", "handoffNotes", "ownedPaths"])) return false;
2803
+ if (typeof value.goal !== "string" || value.goal.trim().length === 0) return false;
2804
+ for (const k of ["constraints", "doneCriteria", "handoffNotes", "ownedPaths"]) {
2805
+ if (value[k] !== void 0 && !isStringArray(value[k])) return false;
2806
+ }
2807
+ return true;
2808
+ }
2809
+ function isMeshMissionRecordWire(value) {
2810
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["id", "meshId", "title", "goal", "status", "source", "brief"])) return false;
2811
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2812
+ if (typeof value.title !== "string" || typeof value.goal !== "string") return false;
2813
+ if (!isMeshMissionStatusValue(value.status)) return false;
2814
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2815
+ if (value.brief !== void 0 && !isMissionBriefWire(value.brief)) return false;
2816
+ return true;
2817
+ }
2818
+ function isMissionUpsertRequest(value) {
2819
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "id", "title", "goal", "status", "source", "brief"])) return false;
2820
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2821
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2822
+ if (value.id !== void 0 && !isEvidenceIdentifier(value.id)) return false;
2823
+ if (typeof value.title !== "string" || value.title.trim().length === 0) return false;
2824
+ if (value.goal !== void 0 && typeof value.goal !== "string") return false;
2825
+ if (value.status !== void 0 && !isMeshMissionStatusValue(value.status)) return false;
2826
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2827
+ if (value.brief !== void 0 && value.brief !== null && !isMissionBriefWire(value.brief)) return false;
2828
+ return true;
2829
+ }
2830
+ function decodeMissionUpsertRequest(value) {
2831
+ return isMissionUpsertRequest(value) ? value : null;
2832
+ }
2833
+ function isMissionUpsertResponse(value) {
2834
+ return isRecord(value) && hasOnlyKeys2(value, ["mission"]) && isMeshMissionRecordWire(value.mission);
2835
+ }
2836
+ function decodeMissionUpsertResponse(value) {
2837
+ return isMissionUpsertResponse(value) ? value : null;
2838
+ }
2839
+ function isMissionQueryRequest(value) {
2840
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "id"])) return false;
2841
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2842
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2843
+ if (value.id !== void 0 && !isEvidenceIdentifier(value.id)) return false;
2844
+ if (value.statuses !== void 0) {
2845
+ if (!Array.isArray(value.statuses) || value.statuses.length === 0) return false;
2846
+ if (!value.statuses.every(isMeshMissionStatusValue)) return false;
2847
+ }
2848
+ return true;
2849
+ }
2850
+ function decodeMissionQueryRequest(value) {
2851
+ return isMissionQueryRequest(value) ? value : null;
2852
+ }
2853
+ function isMissionQueryResponse(value) {
2854
+ return isRecord(value) && hasOnlyKeys2(value, ["missions"]) && Array.isArray(value.missions) && value.missions.every(isMeshMissionRecordWire);
2855
+ }
2856
+ function decodeMissionQueryResponse(value) {
2857
+ return isMissionQueryResponse(value) ? value : null;
2858
+ }
2859
+ function isMissionListQueryRequest(value) {
2860
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "verbose", "includeMagi", "withStats", "limit", "historyIdLimit"])) return false;
2861
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2862
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2863
+ if (value.statuses !== void 0) {
2864
+ if (!Array.isArray(value.statuses) || value.statuses.length === 0) return false;
2865
+ if (!value.statuses.every(isMeshMissionStatusValue)) return false;
2866
+ }
2867
+ if (value.verbose !== void 0 && typeof value.verbose !== "boolean") return false;
2868
+ if (value.includeMagi !== void 0 && typeof value.includeMagi !== "boolean") return false;
2869
+ if (value.withStats !== void 0 && typeof value.withStats !== "boolean") return false;
2870
+ if (value.limit !== void 0 && !isNonNegativeInt(value.limit)) return false;
2871
+ if (value.historyIdLimit !== void 0 && !isNonNegativeInt(value.historyIdLimit)) return false;
2872
+ return true;
2873
+ }
2874
+ function decodeMissionListQueryRequest(value) {
2875
+ return isMissionListQueryRequest(value) ? value : null;
2876
+ }
2877
+ function isMeshMissionTaskAggregateWire(value) {
2878
+ const keys = ["total", "pending", "assigned", "completed", "failed", "cancelled", "blocked", "lastActivityAt"];
2879
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
2880
+ for (const k of ["total", "pending", "assigned", "completed", "failed", "cancelled", "blocked"]) {
2881
+ if (!isNonNegativeInt(value[k])) return false;
2882
+ }
2883
+ return value.lastActivityAt === null || typeof value.lastActivityAt === "string";
2884
+ }
2885
+ function isMeshMissionStatsWire(value) {
2886
+ const keys = ["missionId", "taskCount", "completed", "failed", "totalDurationMs", "wallClockMs", "retries", "incompleteTaskIds"];
2887
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
2888
+ if (!isEvidenceIdentifier(value.missionId)) return false;
2889
+ for (const k of ["taskCount", "completed", "failed", "totalDurationMs", "retries"]) {
2890
+ if (!isNonNegativeInt(value[k])) return false;
2891
+ }
2892
+ if (value.wallClockMs !== null && !isNonNegativeInt(value.wallClockMs)) return false;
2893
+ if (!Array.isArray(value.incompleteTaskIds) || !value.incompleteTaskIds.every(isEvidenceIdentifier)) return false;
2894
+ return true;
2895
+ }
2896
+ function isMissionListSummaryWire(value) {
2897
+ if (!isRecord(value)) return false;
2898
+ const hasGoal = "goal" in value;
2899
+ const hasPreview = "goalPreview" in value && "goalTruncated" in value;
2900
+ if (hasGoal === hasPreview) return false;
2901
+ const baseKeys = ["id", "meshId", "title", "status", "source", "tasks", "stats", "brief"];
2902
+ const allowed = hasGoal ? [...baseKeys, "goal"] : [...baseKeys, "goalPreview", "goalTruncated"];
2903
+ if (!hasOnlyKeys2(value, allowed)) return false;
2904
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2905
+ if (typeof value.title !== "string") return false;
2906
+ if (!isMeshMissionStatusValue(value.status)) return false;
2907
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2908
+ if (!isMeshMissionTaskAggregateWire(value.tasks)) return false;
2909
+ if (value.stats !== void 0 && !isMeshMissionStatsWire(value.stats)) return false;
2910
+ if (value.brief !== void 0 && !isMissionBriefWire(value.brief)) return false;
2911
+ if (hasGoal && typeof value.goal !== "string") return false;
2912
+ if (hasPreview && (typeof value.goalPreview !== "string" || typeof value.goalTruncated !== "boolean")) return false;
2913
+ return true;
2914
+ }
2915
+ function isMeshMissionHistoryFoldWire(value) {
2916
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["count", "byStatus", "missionIds", "note"])) return false;
2917
+ if (!isNonNegativeInt(value.count)) return false;
2918
+ if (!isRecord(value.byStatus) || !Object.values(value.byStatus).every((n) => isNonNegativeInt(n))) return false;
2919
+ if (!Array.isArray(value.missionIds) || !value.missionIds.every(isEvidenceIdentifier)) return false;
2920
+ return typeof value.note === "string";
2921
+ }
2922
+ function isMissionListQueryResponse(value) {
2923
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["missions", "historyFold", "truncated", "matched", "overflowIds"])) return false;
2924
+ if (!Array.isArray(value.missions) || !value.missions.every(isMissionListSummaryWire)) return false;
2925
+ if (value.historyFold !== null && !isMeshMissionHistoryFoldWire(value.historyFold)) return false;
2926
+ if (typeof value.truncated !== "boolean") return false;
2927
+ if (!isNonNegativeInt(value.matched)) return false;
2928
+ if (value.overflowIds !== void 0 && (!Array.isArray(value.overflowIds) || !value.overflowIds.every(isEvidenceIdentifier))) return false;
2929
+ return true;
2930
+ }
2931
+ function decodeMissionListQueryResponse(value) {
2932
+ return isMissionListQueryResponse(value) ? value : null;
2933
+ }
2934
+ var OPERATING_NOTE_CATEGORIES = ["provider_quirk", "pattern_to_avoid", "recovery_lesson"];
2935
+ var isOperatingNoteCategory = makeGuard3(OPERATING_NOTE_CATEGORIES);
2936
+ function isOptionalShortString(value, max = 512) {
2937
+ return value === void 0 || typeof value === "string" && value.trim().length > 0 && value.length <= max;
2938
+ }
2939
+ function isNoteUpsertRequest(value) {
2940
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "text", "category", "pinned", "expiresAt", "supersedes", "subjectKey", "sourceCoordinator"])) return false;
2941
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2942
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2943
+ if (typeof value.text !== "string" || value.text.trim().length === 0) return false;
2944
+ if (value.category !== void 0 && !isOperatingNoteCategory(value.category)) return false;
2945
+ if (value.pinned !== void 0 && typeof value.pinned !== "boolean") return false;
2946
+ if (value.expiresAt !== void 0 && (typeof value.expiresAt !== "string" || Number.isNaN(Date.parse(value.expiresAt)))) return false;
2947
+ return isOptionalShortString(value.supersedes) && isOptionalShortString(value.subjectKey) && isOptionalShortString(value.sourceCoordinator);
2948
+ }
2949
+ function decodeNoteUpsertRequest(value) {
2950
+ return isNoteUpsertRequest(value) ? value : null;
2951
+ }
2952
+ function isNoteUpsertResponse(value) {
2953
+ return isRecord(value) && hasOnlyKeys2(value, ["noteId", "deduped", "createdAt"]) && isEvidenceIdentifier(value.noteId) && typeof value.deduped === "boolean" && typeof value.createdAt === "string";
2954
+ }
2955
+ function decodeNoteUpsertResponse(value) {
2956
+ return isNoteUpsertResponse(value) ? value : null;
2957
+ }
2958
+ function isNoteForgetRequest(value) {
2959
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "noteId", "text", "reason"])) return false;
2960
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2961
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2962
+ if (value.noteId !== void 0 && !isEvidenceIdentifier(value.noteId)) return false;
2963
+ if (value.text !== void 0 && (typeof value.text !== "string" || value.text.trim().length === 0)) return false;
2964
+ if (value.noteId === void 0 && value.text === void 0) return false;
2965
+ return value.reason === void 0 || typeof value.reason === "string";
2966
+ }
2967
+ function decodeNoteForgetRequest(value) {
2968
+ return isNoteForgetRequest(value) ? value : null;
2969
+ }
2970
+ function isNoteForgetResponse(value) {
2971
+ return isRecord(value) && hasOnlyKeys2(value, ["matched", "tombstoneId"]) && typeof value.matched === "number" && Number.isInteger(value.matched) && value.matched >= 0 && isEvidenceIdentifier(value.tombstoneId);
2972
+ }
2973
+ function decodeNoteForgetResponse(value) {
2974
+ return isNoteForgetResponse(value) ? value : null;
2975
+ }
2976
+ var TOOL_CALLER_ROLES = ["coordinator", "unknown"];
2977
+ var isToolCallerRole = makeGuard3(TOOL_CALLER_ROLES);
2978
+ function isToolCallRecordRequest(value) {
2979
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "tool", "sessionId", "callerRole"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.tool) && isOptionalId2(value.sessionId) && isToolCallerRole(value.callerRole);
2980
+ }
2981
+ function decodeToolCallRecordRequest(value) {
2982
+ return isToolCallRecordRequest(value) ? value : null;
2983
+ }
2984
+ function isToolCallRecordResponse(value) {
2985
+ return isRecord(value) && hasOnlyKeys2(value, ["rateLimitExceeded", "callsInWindow", "advisory"]) && typeof value.rateLimitExceeded === "boolean" && isNonNegativeInt(value.callsInWindow) && (value.advisory === null || typeof value.advisory === "string");
2986
+ }
2987
+ function decodeToolCallRecordResponse(value) {
2988
+ return isToolCallRecordResponse(value) ? value : null;
2989
+ }
2990
+ function isLedgerQueryRequest(value) {
2991
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "kind", "since", "node", "tail", "includeSummary"])) return false;
2992
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2993
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2994
+ if (value.kind !== void 0 && (!Array.isArray(value.kind) || value.kind.length === 0 || !value.kind.every(isEvidenceIdentifier))) return false;
2995
+ if (value.since !== void 0 && typeof value.since !== "string") return false;
2996
+ if (!isOptionalId2(value.node)) return false;
2997
+ if (value.tail !== void 0 && !isNonNegativeInt(value.tail)) return false;
2998
+ if (value.includeSummary !== void 0 && typeof value.includeSummary !== "boolean") return false;
2999
+ return true;
3000
+ }
3001
+ function decodeLedgerQueryRequest(value) {
3002
+ return isLedgerQueryRequest(value) ? value : null;
3003
+ }
3004
+ var LEDGER_QUERY_ENTRY_KEYS = ["id", "meshId", "timestamp", "kind", "nodeId", "sessionId", "providerType", "taskId", "payload"];
3005
+ function isLedgerQueryEntryWire(value) {
3006
+ if (!isRecord(value) || !hasOnlyKeys2(value, LEDGER_QUERY_ENTRY_KEYS)) return false;
3007
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
3008
+ if (typeof value.timestamp !== "string" || typeof value.kind !== "string") return false;
3009
+ if (!isOptionalId2(value.nodeId) || !isOptionalId2(value.sessionId) || !isOptionalId2(value.providerType) || !isOptionalId2(value.taskId)) return false;
3010
+ if (!isRecord(value.payload)) return false;
3011
+ return true;
3012
+ }
3013
+ function isLedgerQuerySummaryWire(value) {
3014
+ const keys = ["meshId", "totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskStalled", "sessionLaunched", "checkpointCreated", "lastActivityAt", "recentFailures"];
3015
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
3016
+ if (!isEvidenceIdentifier(value.meshId)) return false;
3017
+ for (const k of ["totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskStalled", "sessionLaunched", "checkpointCreated", "recentFailures"]) {
3018
+ if (!isNonNegativeInt(value[k])) return false;
3019
+ }
3020
+ if (value.lastActivityAt !== null && typeof value.lastActivityAt !== "string") return false;
3021
+ return true;
3022
+ }
3023
+ function isLedgerQueryResponse(value) {
3024
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["entries", "summary"])) return false;
3025
+ if (!Array.isArray(value.entries) || !value.entries.every(isLedgerQueryEntryWire)) return false;
3026
+ if (value.summary !== void 0 && !isLedgerQuerySummaryWire(value.summary)) return false;
3027
+ return true;
3028
+ }
3029
+ function decodeLedgerQueryResponse(value) {
3030
+ return isLedgerQueryResponse(value) ? value : null;
3031
+ }
3032
+ function isRecordArray(value) {
3033
+ return Array.isArray(value) && value.every(isRecord);
3034
+ }
3035
+ function isOptionalRecord(value) {
3036
+ return value === void 0 || isRecord(value);
3037
+ }
3038
+ function isOptionalBoolean(value) {
3039
+ return value === void 0 || typeof value === "boolean";
3040
+ }
3041
+ function isOptionalString(value) {
3042
+ return value === void 0 || typeof value === "string";
3043
+ }
3044
+ function isQueueEntryWire(value) {
3045
+ return isRecord(value) && isEvidenceIdentifier(value.id) && typeof value.status === "string";
3046
+ }
3047
+ function isRecordLocalRequest(value) {
3048
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "kind", "nodeId", "sessionId", "providerType", "taskId", "payload"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.kind) && isOptionalId2(value.nodeId) && isOptionalId2(value.sessionId) && isOptionalId2(value.providerType) && isOptionalId2(value.taskId) && isRecord(value.payload);
3049
+ }
3050
+ function decodeRecordLocalRequest(value) {
3051
+ return isRecordLocalRequest(value) ? value : null;
3052
+ }
3053
+ function isRecordLocalResponse(value) {
3054
+ return isRecord(value) && hasOnlyKeys2(value, ["eventId", "timestamp", "storedLocally", "published"]) && isEvidenceIdentifier(value.eventId) && typeof value.timestamp === "string" && typeof value.storedLocally === "boolean" && typeof value.published === "boolean";
3055
+ }
3056
+ function decodeRecordLocalResponse(value) {
3057
+ return isRecordLocalResponse(value) ? value : null;
3058
+ }
3059
+ function isQueueQueryRequest(value) {
3060
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "taskId", "view"])) return false;
3061
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3062
+ if (value.statuses !== void 0 && (!Array.isArray(value.statuses) || !value.statuses.every(isEvidenceIdentifier))) return false;
3063
+ return isOptionalId2(value.taskId) && isOptionalBoolean(value.view);
3064
+ }
3065
+ function decodeQueueQueryRequest(value) {
3066
+ return isQueueQueryRequest(value) ? value : null;
3067
+ }
3068
+ function isQueueQueryResponse(value) {
3069
+ return isRecord(value) && hasOnlyKeys2(value, ["entries"]) && Array.isArray(value.entries) && value.entries.every(isQueueEntryWire);
3070
+ }
3071
+ function decodeQueueQueryResponse(value) {
3072
+ return isQueueQueryResponse(value) ? value : null;
3073
+ }
3074
+ function isQueueEnqueueRequest(value) {
3075
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "message", "options", "decision"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && typeof value.message === "string" && isOptionalRecord(value.options) && isOptionalRecord(value.decision);
3076
+ }
3077
+ function decodeQueueEnqueueRequest(value) {
3078
+ return isQueueEnqueueRequest(value) ? value : null;
3079
+ }
3080
+ function isQueueEnqueueResponse(value) {
3081
+ return isRecord(value) && hasOnlyKeys2(value, ["entry"]) && isQueueEntryWire(value.entry);
3082
+ }
3083
+ function decodeQueueEnqueueResponse(value) {
3084
+ return isQueueEnqueueResponse(value) ? value : null;
3085
+ }
3086
+ function isQueueEnqueueGraphRequest(value) {
3087
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "mode", "specs", "plan", "audit"])) return false;
3088
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3089
+ if (value.mode === "compat") return isRecordArray(value.specs) && value.plan === void 0 && isOptionalRecord(value.audit);
3090
+ if (value.mode === "graph") return isRecord(value.plan) && value.specs === void 0 && isOptionalRecord(value.audit);
3091
+ return false;
3092
+ }
3093
+ function decodeQueueEnqueueGraphRequest(value) {
3094
+ return isQueueEnqueueGraphRequest(value) ? value : null;
3095
+ }
3096
+ function isQueueEnqueueGraphResponse(value) {
3097
+ if (!isRecord(value)) return false;
3098
+ if (value.ok === true) {
3099
+ return hasOnlyKeys2(value, ["ok", "tasks", "graph"]) && Array.isArray(value.tasks) && value.tasks.every(isQueueEntryWire) && isOptionalRecord(value.graph);
3100
+ }
3101
+ if (value.ok === false) {
3102
+ return hasOnlyKeys2(value, ["ok", "refusalCode", "message", "extra"]) && typeof value.message === "string" && isOptionalString(value.refusalCode) && isOptionalRecord(value.extra);
3103
+ }
3104
+ return false;
3105
+ }
3106
+ function decodeQueueEnqueueGraphResponse(value) {
3107
+ return isQueueEnqueueGraphResponse(value) ? value : null;
3108
+ }
3109
+ function isQueueCancelRequest(value) {
3110
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "reason"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.taskId) && isOptionalString(value.reason);
3111
+ }
3112
+ function decodeQueueCancelRequest(value) {
3113
+ return isQueueCancelRequest(value) ? value : null;
3114
+ }
3115
+ function isQueueCancelResponse(value) {
3116
+ return isRecord(value) && hasOnlyKeys2(value, ["task", "before"]) && (value.task === null || isQueueEntryWire(value.task)) && (value.before === null || isQueueEntryWire(value.before));
3117
+ }
3118
+ function decodeQueueCancelResponse(value) {
3119
+ return isQueueCancelResponse(value) ? value : null;
3120
+ }
3121
+ function isQueueRequeueRequest(value) {
3122
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "options"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.taskId) && isOptionalRecord(value.options);
3123
+ }
3124
+ function decodeQueueRequeueRequest(value) {
3125
+ return isQueueRequeueRequest(value) ? value : null;
3126
+ }
3127
+ function isQueueRequeueResponse(value) {
3128
+ return isRecord(value) && hasOnlyKeys2(value, ["task"]) && (value.task === null || isQueueEntryWire(value.task));
3129
+ }
3130
+ function decodeQueueRequeueResponse(value) {
3131
+ return isQueueRequeueResponse(value) ? value : null;
3132
+ }
3133
+ function isDirectDispatchRecordRequest(value) {
3134
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "message", "task", "decision"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.taskId) && typeof value.message === "string" && isOptionalRecord(value.task) && isOptionalRecord(value.decision);
3135
+ }
3136
+ function decodeDirectDispatchRecordRequest(value) {
3137
+ return isDirectDispatchRecordRequest(value) ? value : null;
3138
+ }
3139
+ function isDirectDispatchRecordResponse(value) {
3140
+ return isRecord(value) && hasOnlyKeys2(value, ["taskRecorded", "decisionRecorded"]) && typeof value.taskRecorded === "boolean" && typeof value.decisionRecorded === "boolean";
3141
+ }
3142
+ function decodeDirectDispatchRecordResponse(value) {
3143
+ return isDirectDispatchRecordResponse(value) ? value : null;
3144
+ }
3145
+ var GRAPH_AUDIT_EVENTS = ["gate_claimed", "gate_released", "gate_abandoned", "node_patched"];
3146
+ var isGraphAuditEvent = makeGuard3(GRAPH_AUDIT_EVENTS);
3147
+ function isGraphAuditRecordRequest(value) {
3148
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "event", "fields"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isGraphAuditEvent(value.event) && isRecord(value.fields);
3149
+ }
3150
+ function decodeGraphAuditRecordRequest(value) {
3151
+ return isGraphAuditRecordRequest(value) ? value : null;
3152
+ }
3153
+ function isGraphAuditRecordResponse(value) {
3154
+ return isRecord(value) && hasOnlyKeys2(value, ["recorded"]) && typeof value.recorded === "boolean";
3155
+ }
3156
+ function decodeGraphAuditRecordResponse(value) {
3157
+ return isGraphAuditRecordResponse(value) ? value : null;
3158
+ }
3159
+ function isActiveWorkQueryRequest(value) {
3160
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "nodes", "queue", "recordTail", "includeTerminalDirect", "compute", "includeInputs", "includeSummary", "includeSchedulingRuntime", "mesh"])) return false;
3161
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3162
+ if (value.nodes !== void 0 && !isRecordArray(value.nodes)) return false;
3163
+ if (value.queue !== void 0 && !isRecordArray(value.queue)) return false;
3164
+ if (value.recordTail !== void 0 && !isNonNegativeInt(value.recordTail)) return false;
3165
+ if (value.includeSchedulingRuntime === true && !isRecord(value.mesh)) return false;
3166
+ return isOptionalBoolean(value.includeTerminalDirect) && isOptionalBoolean(value.compute) && isOptionalBoolean(value.includeInputs) && isOptionalBoolean(value.includeSummary) && isOptionalBoolean(value.includeSchedulingRuntime) && isOptionalRecord(value.mesh);
3167
+ }
3168
+ function decodeActiveWorkQueryRequest(value) {
3169
+ return isActiveWorkQueryRequest(value) ? value : null;
3170
+ }
3171
+ function isActiveWorkQueryResponse(value) {
3172
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["activeWork", "records", "directDispatches", "summary", "schedulingRuntime"])) return false;
3173
+ if (value.records !== void 0 && !isRecordArray(value.records)) return false;
3174
+ if (value.directDispatches !== void 0 && !isRecordArray(value.directDispatches)) return false;
3175
+ return isOptionalRecord(value.activeWork) && isOptionalRecord(value.summary) && isOptionalRecord(value.schedulingRuntime);
3176
+ }
3177
+ function decodeActiveWorkQueryResponse(value) {
3178
+ return isActiveWorkQueryResponse(value) ? value : null;
3179
+ }
3180
+ function isRecoveryContextQueryRequest(value) {
3181
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "nodeId", "sessionId", "maxRetries"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isOptionalId2(value.nodeId) && isOptionalId2(value.sessionId) && (value.maxRetries === void 0 || isNonNegativeInt(value.maxRetries)) && (value.nodeId !== void 0 || value.sessionId !== void 0);
3182
+ }
3183
+ function decodeRecoveryContextQueryRequest(value) {
3184
+ return isRecoveryContextQueryRequest(value) ? value : null;
3185
+ }
3186
+ function isRecoveryContextQueryResponse(value) {
3187
+ return isRecord(value) && hasOnlyKeys2(value, ["context"]) && isRecord(value.context) && typeof value.context.consecutiveNodeFailures === "number";
3188
+ }
3189
+ function decodeRecoveryContextQueryResponse(value) {
3190
+ return isRecoveryContextQueryResponse(value) ? value : null;
3191
+ }
3192
+ function isGraphGateClaimRequest(value) {
3193
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "coordinatorSessionId", "leaseSeconds", "extendDeadlineSeconds", "probeConvergenceEvidence"])) return false;
3194
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId) || !isEvidenceIdentifier(value.coordinatorSessionId)) return false;
3195
+ if (value.leaseSeconds !== void 0 && !isFiniteNumber3(value.leaseSeconds)) return false;
3196
+ if (value.extendDeadlineSeconds !== void 0 && !isFiniteNumber3(value.extendDeadlineSeconds)) return false;
3197
+ return isOptionalBoolean(value.probeConvergenceEvidence);
3198
+ }
3199
+ function decodeGraphGateClaimRequest(value) {
3200
+ return isGraphGateClaimRequest(value) ? value : null;
3201
+ }
3202
+ function isGraphGateClaimResponse(value) {
3203
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["claimed", "reason", "gate", "leaseGeneration", "fencingToken", "leaseExpiresAt", "deadlineAt", "ambiguousExternalOutcome", "previousLeaseOwnerSessionId", "convergenceEvidence"])) return false;
3204
+ if (typeof value.claimed !== "boolean") return false;
3205
+ return isOptionalRecord(value.gate) && isOptionalRecord(value.convergenceEvidence) && isOptionalBoolean(value.ambiguousExternalOutcome);
3206
+ }
3207
+ function decodeGraphGateClaimResponse(value) {
3208
+ return isGraphGateClaimResponse(value) ? value : null;
3209
+ }
3210
+ function isGraphGateReleaseRequest(value) {
3211
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "fencingToken", "leaseGeneration", "idempotencyKey", "outcome", "result", "evidence", "patches"])) return false;
3212
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId)) return false;
3213
+ if (typeof value.fencingToken !== "string" || !value.fencingToken) return false;
3214
+ if (!isFiniteNumber3(value.leaseGeneration)) return false;
3215
+ if (typeof value.idempotencyKey !== "string" || !value.idempotencyKey) return false;
3216
+ if (typeof value.outcome !== "string" || !value.outcome) return false;
3217
+ if (value.patches !== void 0) {
3218
+ if (!Array.isArray(value.patches)) return false;
3219
+ for (const p of value.patches) {
3220
+ if (!isRecord(p) || typeof p.node !== "string" || !p.node || !isRecord(p.baseSpecPatch)) return false;
3221
+ }
3222
+ }
3223
+ return true;
3224
+ }
3225
+ function decodeGraphGateReleaseRequest(value) {
3226
+ return isGraphGateReleaseRequest(value) ? value : null;
3227
+ }
3228
+ function isGraphGateReleaseResponse(value) {
3229
+ if (!isRecord(value)) return false;
3230
+ if (value.released === true) {
3231
+ if (!hasOnlyKeys2(value, ["released", "duplicate", "gate", "materializedNodeIds", "downstreamNodeCount", "graphCompleted"])) return false;
3232
+ if (typeof value.duplicate !== "boolean") return false;
3233
+ if (!Array.isArray(value.materializedNodeIds) || !value.materializedNodeIds.every((n) => typeof n === "string")) return false;
3234
+ if (value.downstreamNodeCount !== void 0 && !isNonNegativeInt(value.downstreamNodeCount)) return false;
3235
+ return isOptionalRecord(value.gate) && isOptionalBoolean(value.graphCompleted);
3236
+ }
3237
+ if (value.released === false) {
3238
+ return hasOnlyKeys2(value, ["released", "refusalCode", "message"]) && typeof value.message === "string" && isOptionalString(value.refusalCode);
3239
+ }
3240
+ return false;
3241
+ }
3242
+ function decodeGraphGateReleaseResponse(value) {
3243
+ return isGraphGateReleaseResponse(value) ? value : null;
3244
+ }
3245
+ function isGraphGateAbandonRequest(value) {
3246
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "reason", "coordinatorSessionId", "force"])) return false;
3247
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId)) return false;
3248
+ if (typeof value.reason !== "string" || !value.reason) return false;
3249
+ if (value.coordinatorSessionId !== void 0 && !isEvidenceIdentifier(value.coordinatorSessionId)) return false;
3250
+ return isOptionalBoolean(value.force);
3251
+ }
3252
+ function decodeGraphGateAbandonRequest(value) {
3253
+ return isGraphGateAbandonRequest(value) ? value : null;
3254
+ }
3255
+ function isGraphGateAbandonResponse(value) {
3256
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["abandoned", "reason", "gate", "cancelledNodeIds", "cancelledTaskIds", "graphStatus"])) return false;
3257
+ if (typeof value.abandoned !== "boolean") return false;
3258
+ if (!Array.isArray(value.cancelledNodeIds) || !value.cancelledNodeIds.every((n) => typeof n === "string")) return false;
3259
+ if (!Array.isArray(value.cancelledTaskIds) || !value.cancelledTaskIds.every((n) => typeof n === "string")) return false;
3260
+ return isOptionalRecord(value.gate);
3261
+ }
3262
+ function decodeGraphGateAbandonResponse(value) {
3263
+ return isGraphGateAbandonResponse(value) ? value : null;
3264
+ }
3265
+ function isGraphNodePatchRequest(value) {
3266
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "node", "graphId", "baseSpecPatch"])) return false;
3267
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3268
+ if (typeof value.node !== "string" || !value.node) return false;
3269
+ if (value.graphId !== void 0 && !isEvidenceIdentifier(value.graphId)) return false;
3270
+ return isRecord(value.baseSpecPatch) && Object.keys(value.baseSpecPatch).length > 0;
3271
+ }
3272
+ function decodeGraphNodePatchRequest(value) {
3273
+ return isGraphNodePatchRequest(value) ? value : null;
3274
+ }
3275
+ function isGraphNodePatchResponse(value) {
3276
+ if (!isRecord(value)) return false;
3277
+ if (value.patched === true) {
3278
+ if (!hasOnlyKeys2(value, ["patched", "graphId", "nodeId", "ref", "queueTaskId", "materializationVersion", "state", "outcomeKind", "skippedReason", "blockedReason"])) return false;
3279
+ if (!isEvidenceIdentifier(value.graphId) || !isEvidenceIdentifier(value.nodeId)) return false;
3280
+ if (!isNonNegativeInt(value.materializationVersion)) return false;
3281
+ return typeof value.state === "string" && typeof value.outcomeKind === "string";
3282
+ }
3283
+ if (value.patched === false) {
3284
+ return hasOnlyKeys2(value, ["patched", "refusalCode", "message"]) && typeof value.message === "string" && isOptionalString(value.refusalCode);
3285
+ }
3286
+ return false;
3287
+ }
3288
+ function decodeGraphNodePatchResponse(value) {
3289
+ return isGraphNodePatchResponse(value) ? value : null;
3290
+ }
3291
+ function isGraphViewQueryRequest(value) {
3292
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "graphId", "batchId", "activeOnly", "limit", "probeGateEvidence"])) return false;
3293
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3294
+ if (value.graphId !== void 0 && !isEvidenceIdentifier(value.graphId)) return false;
3295
+ if (value.batchId !== void 0 && !isEvidenceIdentifier(value.batchId)) return false;
3296
+ if (value.limit !== void 0 && !isNonNegativeInt(value.limit)) return false;
3297
+ return isOptionalBoolean(value.activeOnly) && isOptionalBoolean(value.probeGateEvidence);
3298
+ }
3299
+ function decodeGraphViewQueryRequest(value) {
3300
+ return isGraphViewQueryRequest(value) ? value : null;
3301
+ }
3302
+ function isGraphViewQueryResponse(value) {
3303
+ return isRecord(value) && hasOnlyKeys2(value, ["graphs"]) && isRecordArray(value.graphs);
3304
+ }
3305
+ function decodeGraphViewQueryResponse(value) {
3306
+ return isGraphViewQueryResponse(value) ? value : null;
3307
+ }
3308
+ function isTaskStatsQueryRequest(value) {
3309
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "taskIds", "missionId", "tail", "rollup"])) return false;
3310
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3311
+ if (value.taskIds !== void 0) {
3312
+ if (!Array.isArray(value.taskIds) || value.taskIds.length === 0 || !value.taskIds.every(isEvidenceIdentifier)) return false;
3313
+ }
3314
+ if (value.missionId !== void 0 && !isEvidenceIdentifier(value.missionId)) return false;
3315
+ if (value.tail !== void 0 && !isNonNegativeInt(value.tail)) return false;
3316
+ if (value.rollup === true && value.missionId === void 0) return false;
3317
+ return isOptionalBoolean(value.rollup);
3318
+ }
3319
+ function decodeTaskStatsQueryRequest(value) {
3320
+ return isTaskStatsQueryRequest(value) ? value : null;
3321
+ }
3322
+ function isTaskStatsQueryResponse(value) {
3323
+ return isRecord(value) && hasOnlyKeys2(value, ["tasks", "mission"]) && isRecordArray(value.tasks) && isOptionalRecord(value.mission);
3324
+ }
3325
+ function decodeTaskStatsQueryResponse(value) {
3326
+ return isTaskStatsQueryResponse(value) ? value : null;
3327
+ }
3328
+ function isPruneStaleDirectRequest(value) {
3329
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "execute", "includeTerminal", "source"])) return false;
3330
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
3331
+ if (value.source !== void 0 && typeof value.source !== "string") return false;
3332
+ return isOptionalBoolean(value.execute) && isOptionalBoolean(value.includeTerminal);
3333
+ }
3334
+ function decodePruneStaleDirectRequest(value) {
3335
+ return isPruneStaleDirectRequest(value) ? value : null;
3336
+ }
3337
+ function isPruneStaleDirectResponse(value) {
3338
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["mode", "includeTerminal", "candidateCount", "prunable", "prunedCount", "preservedUnacknowledged", "preservedLedgerOnly", "preservedNotOrphan"])) return false;
3339
+ if (value.mode !== "execute" && value.mode !== "dry_run") return false;
3340
+ if (typeof value.includeTerminal !== "boolean") return false;
3341
+ if (!isNonNegativeInt(value.candidateCount) || !isNonNegativeInt(value.prunedCount)) return false;
3342
+ return isRecordArray(value.prunable) && isRecordArray(value.preservedUnacknowledged) && isRecordArray(value.preservedLedgerOnly) && isRecordArray(value.preservedNotOrphan);
3343
+ }
3344
+ function decodePruneStaleDirectResponse(value) {
3345
+ return isPruneStaleDirectResponse(value) ? value : null;
3346
+ }
3347
+ function isOrphanedPinnedTaskWire(value) {
3348
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["taskId", "title", "targetSessionId", "targetNodeId", "missionId"])) return false;
3349
+ if (!isEvidenceIdentifier(value.taskId) || !isEvidenceIdentifier(value.targetSessionId)) return false;
3350
+ if (typeof value.title !== "string") return false;
3351
+ if (value.targetNodeId !== void 0 && !isEvidenceIdentifier(value.targetNodeId)) return false;
3352
+ return value.missionId === void 0 || isEvidenceIdentifier(value.missionId);
3353
+ }
3354
+ function isOrphanedPinNotifyRequest(value) {
3355
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "stoppedSessionId", "excludeTaskId", "cause", "nodeId", "coordinatorSessionId"])) return false;
3356
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.stoppedSessionId)) return false;
3357
+ if (value.excludeTaskId !== void 0 && !isEvidenceIdentifier(value.excludeTaskId)) return false;
3358
+ if (value.cause !== void 0 && typeof value.cause !== "string") return false;
3359
+ if (value.nodeId !== void 0 && !isEvidenceIdentifier(value.nodeId)) return false;
3360
+ return value.coordinatorSessionId === void 0 || isEvidenceIdentifier(value.coordinatorSessionId);
3361
+ }
3362
+ function decodeOrphanedPinNotifyRequest(value) {
3363
+ return isOrphanedPinNotifyRequest(value) ? value : null;
3364
+ }
3365
+ function isOrphanedPinNotifyResponse(value) {
3366
+ return isRecord(value) && hasOnlyKeys2(value, ["orphans"]) && Array.isArray(value.orphans) && value.orphans.every(isOrphanedPinnedTaskWire);
3367
+ }
3368
+ function decodeOrphanedPinNotifyResponse(value) {
3369
+ return isOrphanedPinNotifyResponse(value) ? value : null;
3370
+ }
3371
+ var TURN_IPC_COMMANDS = [
3372
+ "turn_observe",
3373
+ "mesh_record",
3374
+ "turn_cancel",
3375
+ "operator_status",
3376
+ "turn_query",
3377
+ "mesh_index_query",
3378
+ "mission_upsert",
3379
+ "mission_query",
3380
+ "note_upsert",
3381
+ "note_forget",
3382
+ // C-W9b additions (2026-09-24 14:00 stamp "C-W9"):
3383
+ "tool_call_record",
3384
+ "ledger_query",
3385
+ "mission_list_query",
3386
+ // C-W9a additions (the event ledger retired; the queue behind IPC):
3387
+ "record_local",
3388
+ "queue_query",
3389
+ "queue_enqueue",
3390
+ "queue_enqueue_graph",
3391
+ "queue_cancel",
3392
+ "queue_requeue",
3393
+ "direct_dispatch_record",
3394
+ "graph_audit_record",
3395
+ "active_work_query",
3396
+ "recovery_context_query",
3397
+ // C-W9c additions (2026-09-24 19:00 stamp — the last mcp-server in-process
3398
+ // daemon-core paths: graph gates/plan/patch, mission reads (MAGI), task/
3399
+ // mission stats, orphaned-pin helpers, one prune audit):
3400
+ "graph_gate_claim",
3401
+ "graph_gate_release",
3402
+ "graph_gate_abandon",
3403
+ "graph_node_patch",
3404
+ "graph_view_query",
3405
+ "task_stats_query",
3406
+ "prune_stale_direct",
3407
+ "orphaned_pin_notify"
3408
+ ];
3409
+ var isTurnIpcCommand = makeGuard3(TURN_IPC_COMMANDS);
3410
+
3411
+ // src/path-ownership.ts
3412
+ var MAX_OWNED_PATHS = 64;
3413
+ function toPosix(raw) {
3414
+ return raw.replace(/\\/g, "/");
3415
+ }
3416
+ function normalizeOne(raw, rejected) {
3417
+ if (typeof raw !== "string") {
3418
+ rejected.push({ input: String(raw), reason: "not_a_string" });
3419
+ return null;
3420
+ }
3421
+ const trimmed = raw.trim();
3422
+ if (!trimmed) {
3423
+ rejected.push({ input: raw, reason: "empty" });
3424
+ return null;
3425
+ }
3426
+ let posix = toPosix(trimmed);
3427
+ if (posix.startsWith("/") || /^[a-zA-Z]:\//.test(posix) || posix.startsWith("~")) {
3428
+ rejected.push({ input: raw, reason: "absolute_path" });
3429
+ return null;
3430
+ }
3431
+ posix = posix.replace(/^\.\/+/, "");
3432
+ const segments = posix.split("/").filter(Boolean);
3433
+ if (segments.some((seg) => seg === "..")) {
3434
+ rejected.push({ input: raw, reason: "parent_traversal" });
3435
+ return null;
3436
+ }
3437
+ if (segments.length === 0) {
3438
+ rejected.push({ input: raw, reason: "empty" });
3439
+ return null;
3440
+ }
3441
+ let subtree = false;
3442
+ if (segments[segments.length - 1] === "**") {
3443
+ subtree = true;
3444
+ segments.pop();
3445
+ if (segments.length === 0) {
3446
+ }
3447
+ }
3448
+ if (segments.some((seg) => seg.includes("*") || seg.includes("?"))) {
3449
+ rejected.push({ input: raw, reason: "unsupported_glob" });
3450
+ return null;
3451
+ }
3452
+ return { path: segments.join("/"), subtree };
3453
+ }
3454
+ function normalizeOwnedPaths(input) {
3455
+ const rejected = [];
3456
+ if (input === void 0 || input === null) {
3457
+ return { declaration: { paths: [] }, rejected };
3458
+ }
3459
+ if (!Array.isArray(input)) {
3460
+ return { declaration: { paths: [] }, rejected: [{ input: String(input), reason: "not_an_array" }] };
3461
+ }
3462
+ const byPath = /* @__PURE__ */ new Map();
3463
+ for (const raw of input) {
3464
+ const entry = normalizeOne(raw, rejected);
3465
+ if (!entry) continue;
3466
+ const existing = byPath.get(entry.path);
3467
+ if (!existing) {
3468
+ byPath.set(entry.path, entry);
3469
+ } else if (entry.subtree && !existing.subtree) {
3470
+ byPath.set(entry.path, entry);
3471
+ }
3472
+ }
3473
+ const all = [...byPath.values()];
3474
+ const kept = all.slice(0, MAX_OWNED_PATHS);
3475
+ for (const dropped of all.slice(MAX_OWNED_PATHS)) {
3476
+ rejected.push({ input: dropped.path, reason: "over_cap" });
3477
+ }
3478
+ return { declaration: { paths: kept }, rejected };
3479
+ }
3480
+ function entryContains(base, path) {
3481
+ if (path === base.path) return true;
3482
+ if (base.subtree && (path === base.path || path.startsWith(`${base.path}/`))) return true;
3483
+ return false;
3484
+ }
3485
+ function entriesOverlap(a, b) {
3486
+ if (a.path === b.path) return true;
3487
+ if (a.subtree && (b.path === a.path || b.path.startsWith(`${a.path}/`))) return true;
3488
+ if (b.subtree && (a.path === b.path || a.path.startsWith(`${b.path}/`))) return true;
3489
+ return false;
3490
+ }
3491
+ function pathsOverlap(a, b) {
3492
+ if (a.paths.length === 0 || b.paths.length === 0) return false;
3493
+ for (const pa of a.paths) {
3494
+ for (const pb of b.paths) {
3495
+ if (entriesOverlap(pa, pb)) return true;
3496
+ }
3497
+ }
3498
+ return false;
3499
+ }
3500
+ function findOwnershipConflicts(candidate, inFlight) {
3501
+ if (candidate.paths.length === 0) return [];
3502
+ const conflicts = [];
3503
+ for (const other of inFlight) {
3504
+ if (other.paths.paths.length === 0) continue;
3505
+ const overlappingPaths = [];
3506
+ for (const pa of candidate.paths) {
3507
+ for (const pb of other.paths.paths) {
3508
+ if (entriesOverlap(pa, pb)) {
3509
+ const narrower = pa.path.length >= pb.path.length ? pa.path : pb.path;
3510
+ if (!overlappingPaths.includes(narrower)) overlappingPaths.push(narrower);
3511
+ }
3512
+ }
3513
+ }
3514
+ if (overlappingPaths.length > 0) {
3515
+ conflicts.push({ taskId: other.taskId, overlappingPaths });
3516
+ }
3517
+ }
3518
+ return conflicts;
3519
+ }
3520
+ function touchedFilesOutsideOwnership(touched, owned) {
3521
+ const undeclaredTouched = [];
3522
+ const usedDeclarations = /* @__PURE__ */ new Set();
3523
+ for (const raw of touched ?? []) {
3524
+ const rejectedSink = [];
3525
+ const entry = normalizeOne(raw, rejectedSink);
3526
+ if (!entry) {
3527
+ undeclaredTouched.push(raw);
3528
+ continue;
3529
+ }
3530
+ const matches = owned.paths.filter((base) => entryContains(base, entry.path));
3531
+ if (matches.length === 0) {
3532
+ undeclaredTouched.push(entry.path);
3533
+ } else {
3534
+ for (const m of matches) usedDeclarations.add(m.path);
3535
+ }
3536
+ }
3537
+ const unusedDeclarations = owned.paths.map((p) => p.path).filter((p) => !usedDeclarations.has(p));
3538
+ return { undeclaredTouched, unusedDeclarations };
3539
+ }
1093
3540
  // Annotate the CommonJS export names for ESM import in node:
1094
3541
  0 && (module.exports = {
3542
+ CANCEL_REASONS,
1095
3543
  CANONICAL_MESH_TOOL_COUNT,
1096
3544
  CANONICAL_MESH_TOOL_NAMES,
1097
3545
  CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX,
1098
3546
  CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX,
1099
3547
  CLI_SLOT_RECIPES,
3548
+ COMMIT_STRENGTHS,
3549
+ CONSUME_PROFILES,
3550
+ COORDINATOR_ACK_OUTCOMES,
3551
+ DAEMON_P2P_SIGNAL_TYPES,
3552
+ DAEMON_STATUS_EVENT_NAMES,
3553
+ DAEMON_TO_DASHBOARD_P2P_TYPES,
3554
+ DAEMON_TO_SERVER_TYPES,
1100
3555
  DAEMON_TO_SERVER_WS_MSGS,
3556
+ DASHBOARD_P2P_MESSAGE_KINDS,
3557
+ DASHBOARD_P2P_SIGNAL_TYPES,
3558
+ DASHBOARD_STATUS_EVENT_NAMES,
3559
+ DASHBOARD_TO_DAEMON_P2P_TYPES,
3560
+ DASHBOARD_TO_USER_SESSION_TYPES,
1101
3561
  DEFAULT_DIFFICULTY_BRAINS,
3562
+ DELIVERY_OUTCOMES,
3563
+ DELIVERY_VIAS,
3564
+ DISPATCH_FAILURE_REASONS,
3565
+ EVIDENCE_ENVELOPE_FIELD_SPECS,
3566
+ EVIDENCE_SOURCE_IDS,
3567
+ GRAPH_AUDIT_EVENTS,
3568
+ HOLD_REASONS,
3569
+ LIVENESS_RESULTS,
1102
3570
  MAGI_RAW_ANSWER_CAP,
3571
+ MAX_MESH_RECORD_STRING,
3572
+ MAX_OWNED_PATHS,
1103
3573
  MESH_CHUNK_KIND,
1104
3574
  MESH_CHUNK_PAYLOAD_CHARS,
1105
3575
  MESH_CHUNK_TTL_MS,
3576
+ MESH_DELIVERY_MODES,
3577
+ MESH_INDEX_QUERY_WRITER_SCOPES,
1106
3578
  MESH_MAX_CHUNKS,
1107
3579
  MESH_MAX_INLINE_FRAME_BYTES,
1108
3580
  MESH_MAX_REASSEMBLED_BYTES,
3581
+ MESH_MISSION_SOURCES,
3582
+ MESH_MISSION_STATUSES,
3583
+ MESH_P2P_SIGNAL_TYPES,
3584
+ MESH_RECORD_PAYLOAD_KEYS,
3585
+ MESH_SESSION_CLEANUP_MODES,
1109
3586
  MESH_TASK_DIFFICULTIES,
3587
+ MESH_TASK_MODES,
3588
+ MESH_TASK_PRIORITIES,
3589
+ MESH_TASK_STATUSES,
3590
+ MESH_TERMINAL_TASK_STATUSES,
3591
+ MESH_THINKING_LEVELS,
3592
+ MESH_TOPIC_ENTRY_KINDS,
3593
+ MESH_TOPIC_PROTOCOL_VERSION,
3594
+ MISSION_BRIEF_RENDER_MAX_CHARS,
3595
+ MODEL_AXIS_SOURCES,
3596
+ MODEL_SELECTION_HISTORY_LIMIT,
1110
3597
  MeshChunkAssembler,
3598
+ NATIVE_TURN_OUTCOMES,
3599
+ NOTIFY_KINDS,
3600
+ NO_PROGRESS_OBSERVED_STATUSES,
3601
+ NPM_UPDATE_TAGS,
3602
+ OPERATING_NOTE_CATEGORIES,
3603
+ OPERATOR_STATUSES,
3604
+ OPERATOR_STATUS_REASONS,
3605
+ OPERATOR_STATUS_REASON_VALUES,
3606
+ OPERATOR_STATUS_VALUES,
3607
+ OUTBOUND_MESSAGE_ORIGINS,
3608
+ P2P_SIGNAL_TYPES,
3609
+ PROVIDER_FAILURES,
1111
3610
  QUOTA_SUPPORTED_PROVIDERS,
3611
+ RECENT_SESSION_BUCKETS,
3612
+ RECLAIMING_SEND_REFUSALS,
3613
+ RELEASE_CHANNELS,
3614
+ SEND_POLICY_MODES,
3615
+ SEND_REFUSAL_REASONS,
3616
+ SERVER_STATUS_EVENT_NAMES,
3617
+ SERVER_TO_DAEMON_CONTROL_TYPES,
1112
3618
  SERVER_TO_DAEMON_WS_MSGS,
3619
+ SESSION_ERROR_REASONS,
3620
+ SESSION_LAUNCHED_BY,
3621
+ SESSION_REBOUND_REASONS,
3622
+ SESSION_STATUSES,
3623
+ SESSION_STATUS_ALIASES,
3624
+ SESSION_STATUS_CLASS,
3625
+ SHARED_SESSION_TO_VIEWER_TYPES,
1113
3626
  STATUS_PROBE_ARG_KEY,
3627
+ SUSPENSION_MODALS,
3628
+ SUSPENSION_RESOLUTIONS,
3629
+ SUSPENSION_RESOLUTION_VIAS,
3630
+ SYSTEM_ANNOUNCEMENT_TYPES,
3631
+ TERMINAL_CLASS_EVIDENCE_KINDS,
3632
+ TOOL_CALLER_ROLES,
3633
+ TURN_END_BLOCK_REASONS,
3634
+ TURN_END_STRENGTHS,
3635
+ TURN_EVIDENCE_FIELD_SPECS,
3636
+ TURN_EVIDENCE_FLAGS,
3637
+ TURN_EVIDENCE_KINDS,
3638
+ TURN_IPC_COMMANDS,
3639
+ TURN_IPC_ERROR_CODES,
3640
+ TURN_IPC_PROTOCOL_VERSION,
3641
+ TURN_OBSERVE_VERDICTS,
3642
+ TURN_OUTCOMES,
3643
+ TURN_REASONS,
3644
+ TURN_SCOPES,
1114
3645
  UNKNOWN_CLI_SLOT_RECIPE,
3646
+ USER_SESSION_TO_DASHBOARD_TYPES,
3647
+ VERSION_UPDATE_REASONS,
3648
+ VIEWER_TO_SHARED_SESSION_TYPES,
3649
+ WORKER_BRANCH_STATES,
3650
+ WORKER_PROTOCOL_FOOTER_MARKER,
3651
+ WORKER_REPORT_OUTCOMES,
3652
+ WORKER_TOOLS,
3653
+ appendWorkerProtocolFooter,
1115
3654
  argsCarryStatusProbeMarker,
1116
3655
  buildMagiPanelProposal,
1117
3656
  buildSlotProposal,
1118
3657
  canonicalDaemonId,
3658
+ classifySessionStatus,
1119
3659
  compareSemver,
1120
3660
  daemonIdsEquivalent,
3661
+ decodeActiveWorkQueryRequest,
3662
+ decodeActiveWorkQueryResponse,
3663
+ decodeDaemonToDashboardP2P,
3664
+ decodeDaemonToServer,
3665
+ decodeDashboardToDaemonP2P,
3666
+ decodeDashboardToDaemonP2PChunk,
3667
+ decodeDashboardToUserSession,
3668
+ decodeDirectDispatchRecordRequest,
3669
+ decodeDirectDispatchRecordResponse,
3670
+ decodeGraphAuditRecordRequest,
3671
+ decodeGraphAuditRecordResponse,
3672
+ decodeGraphGateAbandonRequest,
3673
+ decodeGraphGateAbandonResponse,
3674
+ decodeGraphGateClaimRequest,
3675
+ decodeGraphGateClaimResponse,
3676
+ decodeGraphGateReleaseRequest,
3677
+ decodeGraphGateReleaseResponse,
3678
+ decodeGraphNodePatchRequest,
3679
+ decodeGraphNodePatchResponse,
3680
+ decodeGraphViewQueryRequest,
3681
+ decodeGraphViewQueryResponse,
3682
+ decodeLedgerQueryRequest,
3683
+ decodeLedgerQueryResponse,
3684
+ decodeMeshIndexQueryRequest,
3685
+ decodeMeshIndexQueryResponse,
3686
+ decodeMeshRecordRequest,
3687
+ decodeMeshRecordResponse,
3688
+ decodeMissionListQueryRequest,
3689
+ decodeMissionListQueryResponse,
3690
+ decodeMissionQueryRequest,
3691
+ decodeMissionQueryResponse,
3692
+ decodeMissionUpsertRequest,
3693
+ decodeMissionUpsertResponse,
3694
+ decodeNoteForgetRequest,
3695
+ decodeNoteForgetResponse,
3696
+ decodeNoteUpsertRequest,
3697
+ decodeNoteUpsertResponse,
3698
+ decodeOperatorStatusRequest,
3699
+ decodeOperatorStatusResponse,
3700
+ decodeOrphanedPinNotifyRequest,
3701
+ decodeOrphanedPinNotifyResponse,
3702
+ decodePruneStaleDirectRequest,
3703
+ decodePruneStaleDirectResponse,
3704
+ decodeQueueCancelRequest,
3705
+ decodeQueueCancelResponse,
3706
+ decodeQueueEnqueueGraphRequest,
3707
+ decodeQueueEnqueueGraphResponse,
3708
+ decodeQueueEnqueueRequest,
3709
+ decodeQueueEnqueueResponse,
3710
+ decodeQueueQueryRequest,
3711
+ decodeQueueQueryResponse,
3712
+ decodeQueueRequeueRequest,
3713
+ decodeQueueRequeueResponse,
3714
+ decodeRecordLocalRequest,
3715
+ decodeRecordLocalResponse,
3716
+ decodeRecoveryContextQueryRequest,
3717
+ decodeRecoveryContextQueryResponse,
3718
+ decodeServerToDaemon,
3719
+ decodeTaskStatsQueryRequest,
3720
+ decodeTaskStatsQueryResponse,
3721
+ decodeToolCallRecordRequest,
3722
+ decodeToolCallRecordResponse,
3723
+ decodeTurnCancelRequest,
3724
+ decodeTurnCancelResponse,
3725
+ decodeTurnObserveRequest,
3726
+ decodeTurnObserveResponse,
3727
+ decodeTurnQueryRequest,
3728
+ decodeTurnQueryResponse,
3729
+ decodeTypeField,
3730
+ decodeUserSessionToDashboard,
3731
+ decodeViewerToSharedSession,
1121
3732
  deriveProviderPriorityFromSlots,
1122
3733
  deriveSlotsFromLegacy,
3734
+ describeModelSelection,
3735
+ effectiveModelSelectionValue,
3736
+ enumOf,
1123
3737
  expandDaemonIdForms,
3738
+ findOwnershipConflicts,
1124
3739
  formatQuotaAccount,
1125
3740
  hasGitStatusEvidence,
3741
+ hasWorkerProtocolFooter,
1126
3742
  interpolateArgs,
1127
3743
  interpolateString,
3744
+ isActiveWorkQueryRequest,
3745
+ isActiveWorkQueryResponse,
3746
+ isBlockedStatus,
3747
+ isBusyStatus,
3748
+ isChunkType,
3749
+ isCommitStrength,
3750
+ isDaemonDirectCommandType,
3751
+ isDaemonP2PSignalType,
3752
+ isDaemonStatusEventName,
3753
+ isDaemonToDashboardP2PType,
3754
+ isDaemonToServerType,
1128
3755
  isDaemonToServerWsMsg,
3756
+ isDashboardP2PSignalType,
3757
+ isDashboardStatusEventName,
3758
+ isDashboardToDaemonChunkType,
3759
+ isDashboardToDaemonP2PType,
3760
+ isDashboardToUserSessionType,
3761
+ isDeadStatus,
3762
+ isDirectDispatchRecordRequest,
3763
+ isDirectDispatchRecordResponse,
1129
3764
  isDowngrade,
3765
+ isEvidenceIdentifier,
3766
+ isEvidenceSourceId,
3767
+ isFiniteNumber,
3768
+ isGraphAuditEvent,
3769
+ isGraphAuditRecordRequest,
3770
+ isGraphAuditRecordResponse,
3771
+ isGraphGateAbandonRequest,
3772
+ isGraphGateAbandonResponse,
3773
+ isGraphGateClaimRequest,
3774
+ isGraphGateClaimResponse,
3775
+ isGraphGateReleaseRequest,
3776
+ isGraphGateReleaseResponse,
3777
+ isGraphNodePatchRequest,
3778
+ isGraphNodePatchResponse,
3779
+ isGraphViewQueryRequest,
3780
+ isGraphViewQueryResponse,
3781
+ isHoldReason,
3782
+ isInputEnvelopeWire,
3783
+ isLedgerQueryRequest,
3784
+ isLedgerQueryResponse,
3785
+ isMeshDeliveryMode,
3786
+ isMeshIndexQueryRequest,
3787
+ isMeshIndexQueryResponse,
3788
+ isMeshIndexQueryWriterScope,
3789
+ isMeshMissionSourceValue,
3790
+ isMeshMissionStatusValue,
3791
+ isMeshP2PSignalType,
3792
+ isMeshRecordPayload,
3793
+ isMeshRecordRequest,
3794
+ isMeshRecordResponse,
3795
+ isMeshSessionCleanupMode,
1130
3796
  isMeshTaskDifficulty,
3797
+ isMeshTaskMode,
3798
+ isMeshTaskPriority,
3799
+ isMeshTaskStatus,
3800
+ isMeshTerminalTaskStatus,
3801
+ isMeshThinkingLevel,
3802
+ isMeshTopicEntry,
3803
+ isMeshTopicEntryKind,
3804
+ isMessageId,
3805
+ isMissionListQueryRequest,
3806
+ isMissionListQueryResponse,
3807
+ isMissionQueryRequest,
3808
+ isMissionQueryResponse,
3809
+ isMissionUpsertRequest,
3810
+ isMissionUpsertResponse,
3811
+ isModelAxisSource,
3812
+ isNonEmptyString,
3813
+ isNoteForgetRequest,
3814
+ isNoteForgetResponse,
3815
+ isNoteUpsertRequest,
3816
+ isNoteUpsertResponse,
3817
+ isNotifyKind,
3818
+ isOperatingNoteCategory,
3819
+ isOperatorStatusReasonValue,
3820
+ isOperatorStatusRequest,
3821
+ isOperatorStatusResponse,
3822
+ isOperatorStatusValue,
3823
+ isOrphanedPinNotifyRequest,
3824
+ isOrphanedPinNotifyResponse,
3825
+ isOutboundMessage,
3826
+ isOutboundMessageOrigin,
3827
+ isP2PSignalType,
1131
3828
  isPhantomDaemonEntry,
3829
+ isPruneStaleDirectRequest,
3830
+ isPruneStaleDirectResponse,
3831
+ isQueueCancelRequest,
3832
+ isQueueCancelResponse,
3833
+ isQueueEnqueueGraphRequest,
3834
+ isQueueEnqueueGraphResponse,
3835
+ isQueueEnqueueRequest,
3836
+ isQueueEnqueueResponse,
3837
+ isQueueQueryRequest,
3838
+ isQueueQueryResponse,
3839
+ isQueueRequeueRequest,
3840
+ isQueueRequeueResponse,
1132
3841
  isRawDaemonDoId,
3842
+ isReadyStatus,
3843
+ isRecord,
3844
+ isRecordLocalRequest,
3845
+ isRecordLocalResponse,
3846
+ isRecoveryContextQueryRequest,
3847
+ isRecoveryContextQueryResponse,
3848
+ isSendPolicy,
3849
+ isSendPolicyMode,
3850
+ isSendRefusal,
3851
+ isServerDirectCommandMsg,
3852
+ isServerToDaemonControlType,
1133
3853
  isServerToDaemonWsMsg,
3854
+ isSessionLaunchedBy,
3855
+ isSessionStatus,
3856
+ isSharedSessionToViewerType,
3857
+ isSubmitOutcome,
3858
+ isSummaryRef,
3859
+ isTaskStatsQueryRequest,
3860
+ isTaskStatsQueryResponse,
3861
+ isTerminalClassEvidenceKind,
3862
+ isToolCallRecordRequest,
3863
+ isToolCallRecordResponse,
3864
+ isToolCallerRole,
3865
+ isTurnAttemptRef,
3866
+ isTurnCancelRequest,
3867
+ isTurnCancelResponse,
3868
+ isTurnEvidence,
3869
+ isTurnEvidenceKind,
3870
+ isTurnIpcCommand,
3871
+ isTurnIpcError,
3872
+ isTurnIpcErrorCode,
3873
+ isTurnObserveRequest,
3874
+ isTurnObserveResponse,
3875
+ isTurnObserveVerdict,
3876
+ isTurnOutcome,
3877
+ isTurnQueryRequest,
3878
+ isTurnQueryResponse,
3879
+ isTurnReason,
3880
+ isUserSessionToDashboardType,
3881
+ isViewerToSharedSessionType,
3882
+ isWorkerBranchState,
3883
+ isWorkerReportOutcome,
3884
+ isWorkerTool,
3885
+ isWorkingStatus,
1134
3886
  joinRepoPath,
3887
+ launchModelSelectionValue,
1135
3888
  machineCoreFromDaemonId,
3889
+ makeTypeGuard,
1136
3890
  measureWorstCaseChunkEnvelopeBytes,
1137
3891
  meshFrameNeedsChunking,
1138
3892
  meshNodeIdMatches,
1139
3893
  meshUtf8ByteLength,
1140
3894
  meshWorkspacesEquivalent,
3895
+ mintMessageId,
3896
+ normalizeAuthOkLimits,
1141
3897
  normalizeBrainSlot,
1142
3898
  normalizeDifficultyBrainMap,
1143
3899
  normalizeGitStatus,
@@ -1145,25 +3901,40 @@ var CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX = "Claude TUI answer delivered but not
1145
3901
  normalizeMeshNodeId,
1146
3902
  normalizeMeshSessionRecord,
1147
3903
  normalizeMeshWorkspaceForCompare,
3904
+ normalizeMissionBrief,
1148
3905
  normalizeNodeCapabilitySlot,
1149
3906
  normalizeNodeCapabilitySlots,
3907
+ normalizeOwnedPaths,
3908
+ normalizeSessionStatus,
1150
3909
  normalizeThinkingLevel,
1151
3910
  parseJsonRecord,
1152
3911
  parseSemver,
3912
+ parseSessionLaunchRecord,
3913
+ pathsOverlap,
1153
3914
  pickBestTransitGitStatus,
3915
+ projectTurnEvidenceEntry,
1154
3916
  readBoolean,
3917
+ readEnvelopeFields,
1155
3918
  readGitSubmodules,
1156
3919
  readNumber,
1157
3920
  readRecord,
1158
3921
  readString,
1159
3922
  readStringArray,
3923
+ renderCoordinatorWorkerSection,
3924
+ renderMissionBriefBlock,
3925
+ renderWorkerProtocolFooter,
3926
+ sanitizeModelIdentifier,
3927
+ sanitizeRefusalCode,
1160
3928
  scoreGitStatusCandidate,
1161
3929
  scoreGitUpstreamFreshness,
1162
3930
  sessionIdsEquivalent,
1163
3931
  splitMeshFrame,
3932
+ statusesOfClass,
1164
3933
  stripStatusProbeMarker,
3934
+ stripWorkerProtocolFooter,
1165
3935
  summarizeGitShape,
1166
3936
  supportsQuota,
3937
+ touchedFilesOutsideOwnership,
1167
3938
  withStatusProbeMarker
1168
3939
  });
1169
3940
  //# sourceMappingURL=index.js.map