@adhdev/mesh-shared 1.0.60-rc.4 → 1.0.60-rc.40

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 (39) hide show
  1. package/dist/index.d.ts +10 -0
  2. package/dist/index.js +2758 -17
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +2435 -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 +400 -0
  19. package/dist/turn-ipc.d.ts +974 -0
  20. package/dist/worker-protocol.d.ts +69 -0
  21. package/dist/ws-protocol.d.ts +71 -41
  22. package/package.json +1 -1
  23. package/src/index.ts +10 -0
  24. package/src/mesh-tool-names.ts +0 -1
  25. package/src/mesh-vocabulary.ts +98 -0
  26. package/src/mission-brief.ts +153 -0
  27. package/src/outbound-message.ts +320 -0
  28. package/src/path-ownership.ts +271 -0
  29. package/src/protocol/daemon-server.ts +552 -0
  30. package/src/protocol/dashboard-daemon-p2p.ts +272 -0
  31. package/src/protocol/dashboard-server.ts +340 -0
  32. package/src/protocol/envelope.ts +75 -0
  33. package/src/protocol/index.ts +16 -0
  34. package/src/session-launch.ts +247 -0
  35. package/src/session-status.ts +140 -0
  36. package/src/turn-evidence.ts +549 -0
  37. package/src/turn-ipc.ts +2231 -0
  38. package/src/worker-protocol.ts +142 -0
  39. package/src/ws-protocol.ts +102 -93
package/dist/index.mjs CHANGED
@@ -287,8 +287,8 @@ function meshWorkspacesEquivalent(a, b) {
287
287
 
288
288
  // src/daemon-normalize.ts
289
289
  var DAEMON_ID_PREFIXES = ["daemon_", "standalone_"];
290
- function isRawDaemonDoId(id) {
291
- const trimmed = readString(id);
290
+ function isRawDaemonDoId(id2) {
291
+ const trimmed = readString(id2);
292
292
  return !!trimmed && /^[0-9a-f]{64}$/i.test(trimmed);
293
293
  }
294
294
  function isPhantomDaemonEntry(entry) {
@@ -299,8 +299,8 @@ function isPhantomDaemonEntry(entry) {
299
299
  );
300
300
  return !hasMachineEvidence;
301
301
  }
302
- function machineCoreFromDaemonId(id) {
303
- const trimmed = readString(id);
302
+ function machineCoreFromDaemonId(id2) {
303
+ const trimmed = readString(id2);
304
304
  if (!trimmed) return void 0;
305
305
  for (const prefix of DAEMON_ID_PREFIXES) {
306
306
  if (trimmed.startsWith(prefix)) {
@@ -310,8 +310,8 @@ function machineCoreFromDaemonId(id) {
310
310
  }
311
311
  return trimmed;
312
312
  }
313
- function canonicalDaemonId(id) {
314
- const core = machineCoreFromDaemonId(id);
313
+ function canonicalDaemonId(id2) {
314
+ const core = machineCoreFromDaemonId(id2);
315
315
  if (!core) return void 0;
316
316
  if (!core.startsWith("mach_")) return core;
317
317
  return `daemon_${core}`;
@@ -704,7 +704,6 @@ var CANONICAL_MESH_TOOL_NAMES = [
704
704
  "mesh_record_note",
705
705
  "mesh_forget_note",
706
706
  "mesh_reconcile_ledger",
707
- "mesh_requeue_held_events",
708
707
  "mesh_mission_upsert",
709
708
  "mesh_mission_list",
710
709
  "mesh_review_inbox",
@@ -957,8 +956,54 @@ function isDowngrade(current, target) {
957
956
  return direction < 0;
958
957
  }
959
958
 
960
- // src/ws-protocol.ts
961
- var DAEMON_TO_SERVER_WS_MSGS = [
959
+ // src/protocol/envelope.ts
960
+ function isRecord(value) {
961
+ return typeof value === "object" && value !== null && !Array.isArray(value);
962
+ }
963
+ function isNonEmptyString(value) {
964
+ return typeof value === "string" && value.length > 0;
965
+ }
966
+ function isFiniteNumber(value) {
967
+ return typeof value === "number" && Number.isFinite(value);
968
+ }
969
+ function makeTypeGuard(names) {
970
+ const set = new Set(names);
971
+ return (value) => typeof value === "string" && set.has(value);
972
+ }
973
+ function decodeTypeField(raw, isType) {
974
+ if (!isRecord(raw)) return null;
975
+ if (!isType(raw.type)) return null;
976
+ return { type: raw.type, frame: raw };
977
+ }
978
+ function readEnvelopeFields(frame) {
979
+ return {
980
+ ...isNonEmptyString(frame.id) ? { id: frame.id } : {},
981
+ ...isFiniteNumber(frame.timestamp) ? { timestamp: frame.timestamp } : {}
982
+ };
983
+ }
984
+
985
+ // src/protocol/daemon-server.ts
986
+ var DAEMON_STATUS_EVENT_NAMES = [
987
+ "agent:generating_started",
988
+ "agent:waiting_approval",
989
+ "agent:waiting_choice",
990
+ "agent:generating_completed",
991
+ "agent:stopped",
992
+ "monitor:no_progress",
993
+ /** Legacy alias for `monitor:no_progress`, still emitted by older daemons. */
994
+ "monitor:long_generating"
995
+ ];
996
+ var isDaemonStatusEventName = makeTypeGuard(DAEMON_STATUS_EVENT_NAMES);
997
+ var RELEASE_CHANNELS = ["stable", "preview"];
998
+ var NPM_UPDATE_TAGS = ["latest", "next"];
999
+ var VERSION_UPDATE_REASONS = ["force_update_below", "major_minor_mismatch", "patch_mismatch", "daemon_ahead"];
1000
+ var P2P_SIGNAL_TYPES = ["p2p_ready", "p2p_offer", "p2p_answer", "p2p_ice"];
1001
+ var isP2PSignalType = makeTypeGuard(P2P_SIGNAL_TYPES);
1002
+ var DAEMON_P2P_SIGNAL_TYPES = ["p2p_offer", "p2p_ice"];
1003
+ var isDaemonP2PSignalType = makeTypeGuard(DAEMON_P2P_SIGNAL_TYPES);
1004
+ var MESH_P2P_SIGNAL_TYPES = ["mesh_p2p_ready", "mesh_p2p_offer", "mesh_p2p_answer", "mesh_p2p_ice"];
1005
+ var isMeshP2PSignalType = makeTypeGuard(MESH_P2P_SIGNAL_TYPES);
1006
+ var DAEMON_TO_SERVER_TYPES = [
962
1007
  "auth",
963
1008
  "status_report",
964
1009
  "status_heartbeat",
@@ -966,10 +1011,29 @@ var DAEMON_TO_SERVER_WS_MSGS = [
966
1011
  "command_result",
967
1012
  "error",
968
1013
  "agent_event",
969
- "log",
970
- "beacon_vectors"
1014
+ "beacon_vectors",
1015
+ "daemon_mesh_command",
1016
+ "p2p_offer",
1017
+ "p2p_ice"
971
1018
  ];
972
- var SERVER_TO_DAEMON_WS_MSGS = [
1019
+ var isDaemonToServerType = makeTypeGuard(DAEMON_TO_SERVER_TYPES);
1020
+ function decodeDaemonToServer(raw) {
1021
+ if (!isRecord(raw) || !isDaemonToServerType(raw.type)) return null;
1022
+ if (raw.type === "daemon_mesh_command") {
1023
+ return {
1024
+ type: "daemon_mesh_command",
1025
+ requestId: typeof raw.requestId === "string" ? raw.requestId : String(raw.requestId ?? ""),
1026
+ targetDaemonId: typeof raw.targetDaemonId === "string" ? raw.targetDaemonId : "",
1027
+ command: raw.command,
1028
+ args: isRecord(raw.args) ? raw.args : {},
1029
+ timestamp: typeof raw.timestamp === "number" ? raw.timestamp : Date.now()
1030
+ };
1031
+ }
1032
+ if (!isRecord(raw.payload)) return null;
1033
+ if (raw.type === "auth" && !isNonEmptyString(raw.payload.token)) return null;
1034
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
1035
+ }
1036
+ var SERVER_TO_DAEMON_CONTROL_TYPES = [
973
1037
  "auth_ok",
974
1038
  "auth_error",
975
1039
  "machine_evicted",
@@ -980,65 +1044,2405 @@ var SERVER_TO_DAEMON_WS_MSGS = [
980
1044
  "command",
981
1045
  "agent_command",
982
1046
  "resolve_action",
983
- "beacon_vectors_result"
1047
+ "beacon_vectors_result",
1048
+ "daemon_mesh_result",
1049
+ "p2p_ready",
1050
+ "p2p_offer",
1051
+ "p2p_answer",
1052
+ "p2p_ice",
1053
+ "mesh_p2p_ready",
1054
+ "mesh_p2p_offer",
1055
+ "mesh_p2p_answer",
1056
+ "mesh_p2p_ice"
1057
+ ];
1058
+ var isServerToDaemonControlType = makeTypeGuard(SERVER_TO_DAEMON_CONTROL_TYPES);
1059
+ function isServerDirectCommandMsg(msg) {
1060
+ return !isServerToDaemonControlType(msg.type);
1061
+ }
1062
+ var DIRECT_COMMAND_TYPE_PATTERN = /^[a-z][a-z0-9_:.-]{0,63}$/;
1063
+ function isDaemonDirectCommandType(value) {
1064
+ return typeof value === "string" && DIRECT_COMMAND_TYPE_PATTERN.test(value) && !isServerToDaemonControlType(value);
1065
+ }
1066
+ function decodeServerToDaemon(raw) {
1067
+ if (!isRecord(raw) || typeof raw.type !== "string") return null;
1068
+ const relay = {
1069
+ ...readEnvelopeFields(raw),
1070
+ ...isNonEmptyString(raw.source) ? { source: raw.source } : {}
1071
+ };
1072
+ if (raw.type === "beacon_vectors_result" || raw.type === "daemon_mesh_result") {
1073
+ if (!isNonEmptyString(raw.requestId)) return null;
1074
+ const base = { requestId: raw.requestId, success: raw.success === true };
1075
+ if (raw.type === "beacon_vectors_result") {
1076
+ return {
1077
+ type: "beacon_vectors_result",
1078
+ ...base,
1079
+ ...Array.isArray(raw.reports) ? { reports: raw.reports } : {},
1080
+ ...typeof raw.truncated === "number" ? { truncated: raw.truncated } : {},
1081
+ ...typeof raw.error === "string" ? { error: raw.error } : {}
1082
+ };
1083
+ }
1084
+ return {
1085
+ type: "daemon_mesh_result",
1086
+ ...base,
1087
+ ..."result" in raw ? { result: raw.result } : {},
1088
+ ...typeof raw.error === "string" ? { error: raw.error } : {}
1089
+ };
1090
+ }
1091
+ if (!isRecord(raw.payload)) return null;
1092
+ if (isServerToDaemonControlType(raw.type)) {
1093
+ return { type: raw.type, payload: raw.payload, ...relay };
1094
+ }
1095
+ if (!isDaemonDirectCommandType(raw.type)) return null;
1096
+ return { type: raw.type, payload: raw.payload, ...relay };
1097
+ }
1098
+
1099
+ // src/protocol/dashboard-server.ts
1100
+ var SERVER_STATUS_EVENT_NAMES = [
1101
+ "daemon:disconnect",
1102
+ "team:session_viewed",
1103
+ "team:view_request",
1104
+ "team:view_request_approved",
1105
+ "team:view_request_rejected"
984
1106
  ];
985
- function isDaemonToServerWsMsg(value) {
986
- return typeof value === "string" && DAEMON_TO_SERVER_WS_MSGS.includes(value);
1107
+ var DASHBOARD_STATUS_EVENT_NAMES = [...DAEMON_STATUS_EVENT_NAMES, ...SERVER_STATUS_EVENT_NAMES];
1108
+ var isDashboardStatusEventName = makeTypeGuard(DASHBOARD_STATUS_EVENT_NAMES);
1109
+ var SYSTEM_ANNOUNCEMENT_TYPES = ["info", "warning", "critical"];
1110
+ var USER_SESSION_TO_DASHBOARD_TYPES = [
1111
+ "connected",
1112
+ "initial_state",
1113
+ "daemon_status",
1114
+ "status_event",
1115
+ "system_announcement",
1116
+ "auth_error",
1117
+ "heartbeat",
1118
+ "p2p_offer",
1119
+ "p2p_ice"
1120
+ ];
1121
+ var isUserSessionToDashboardType = makeTypeGuard(USER_SESSION_TO_DASHBOARD_TYPES);
1122
+ function decodeUserSessionToDashboard(raw) {
1123
+ if (!isRecord(raw) || !isUserSessionToDashboardType(raw.type)) return null;
1124
+ if (raw.type === "heartbeat") {
1125
+ return { type: "heartbeat", payload: isRecord(raw.payload) ? raw.payload : {}, ...readEnvelopeFields(raw) };
1126
+ }
1127
+ if (!isRecord(raw.payload)) return null;
1128
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
987
1129
  }
988
- function isServerToDaemonWsMsg(value) {
989
- return typeof value === "string" && SERVER_TO_DAEMON_WS_MSGS.includes(value);
1130
+ var DASHBOARD_TO_USER_SESSION_TYPES = ["heartbeat", "refresh", "p2p_ready", "p2p_answer", "p2p_ice"];
1131
+ var isDashboardToUserSessionType = makeTypeGuard(DASHBOARD_TO_USER_SESSION_TYPES);
1132
+ var DASHBOARD_P2P_SIGNAL_TYPES = ["p2p_ready", "p2p_answer", "p2p_ice"];
1133
+ var isDashboardP2PSignalType = makeTypeGuard(DASHBOARD_P2P_SIGNAL_TYPES);
1134
+ function decodeDashboardToUserSession(raw) {
1135
+ if (!isRecord(raw) || !isDashboardToUserSessionType(raw.type)) return null;
1136
+ if (raw.type === "heartbeat") return { type: "heartbeat", ...readEnvelopeFields(raw) };
1137
+ if (raw.type === "refresh") return { type: "refresh" };
1138
+ if (!isRecord(raw.payload) || typeof raw.payload.daemonId !== "string") return null;
1139
+ return { type: raw.type, payload: raw.payload, ...readEnvelopeFields(raw) };
1140
+ }
1141
+ var SHARED_SESSION_TO_VIEWER_TYPES = [
1142
+ "share:connected",
1143
+ "share:revoked",
1144
+ "share:expired",
1145
+ "share:error",
1146
+ "share:viewer_count",
1147
+ "p2p_offer",
1148
+ "p2p_ice"
1149
+ ];
1150
+ var isSharedSessionToViewerType = makeTypeGuard(SHARED_SESSION_TO_VIEWER_TYPES);
1151
+ var VIEWER_TO_SHARED_SESSION_TYPES = ["p2p_ready", "p2p_offer", "p2p_answer", "p2p_ice"];
1152
+ var isViewerToSharedSessionType = makeTypeGuard(VIEWER_TO_SHARED_SESSION_TYPES);
1153
+ function decodeViewerToSharedSession(raw) {
1154
+ if (!isRecord(raw) || !isViewerToSharedSessionType(raw.type)) return null;
1155
+ const payload = isRecord(raw.payload) ? raw.payload : {};
1156
+ return { type: raw.type, payload, ...readEnvelopeFields(raw) };
1157
+ }
1158
+
1159
+ // src/protocol/dashboard-daemon-p2p.ts
1160
+ function isChunkType(value) {
1161
+ return typeof value === "string" && value.endsWith("_chunk") && value.length > "_chunk".length;
1162
+ }
1163
+ function readChunkFields(frame) {
1164
+ if (!isNonEmptyString(frame.chunkId)) return null;
1165
+ if (!Number.isInteger(frame.index) || !Number.isInteger(frame.total)) return null;
1166
+ if (typeof frame.data !== "string") return null;
1167
+ return {
1168
+ ...isNonEmptyString(frame.id) ? { id: frame.id } : {},
1169
+ chunkId: frame.chunkId,
1170
+ index: frame.index,
1171
+ total: frame.total,
1172
+ data: frame.data
1173
+ };
1174
+ }
1175
+ var DASHBOARD_TO_DAEMON_P2P_TYPES = [
1176
+ "ping",
1177
+ "pong",
1178
+ "command",
1179
+ "input",
1180
+ "pty_input",
1181
+ "pty_resize",
1182
+ "screenshot_start",
1183
+ "screenshot_stop",
1184
+ "subscribe",
1185
+ "unsubscribe",
1186
+ "seqscribe_session_interest",
1187
+ "read",
1188
+ "write",
1189
+ "list"
1190
+ ];
1191
+ var isDashboardToDaemonP2PType = makeTypeGuard(DASHBOARD_TO_DAEMON_P2P_TYPES);
1192
+ function isDashboardToDaemonChunkType(value) {
1193
+ return isChunkType(value) && isDashboardToDaemonP2PType(value.slice(0, -"_chunk".length));
1194
+ }
1195
+ var DASHBOARD_REQUEST_TYPES = /* @__PURE__ */ new Set(["command", "input", "read", "write", "list"]);
1196
+ function decodeDashboardToDaemonP2PChunk(raw) {
1197
+ if (!isRecord(raw) || !isDashboardToDaemonChunkType(raw.type)) return null;
1198
+ const fields = readChunkFields(raw);
1199
+ return fields ? { type: raw.type, ...fields } : null;
1200
+ }
1201
+ function decodeDashboardToDaemonP2P(raw) {
1202
+ if (!isRecord(raw) || !isDashboardToDaemonP2PType(raw.type)) return null;
1203
+ if (DASHBOARD_REQUEST_TYPES.has(raw.type) && !isNonEmptyString(raw.id)) return null;
1204
+ return raw;
1205
+ }
1206
+ var DAEMON_TO_DASHBOARD_P2P_TYPES = [
1207
+ "ping",
1208
+ "pong",
1209
+ "p2p_evicted",
1210
+ "status_report",
1211
+ "status_event",
1212
+ "topic_update",
1213
+ "topic_update_chunk",
1214
+ "session_output",
1215
+ "session_output_chunk",
1216
+ "session_io_error",
1217
+ "command_result",
1218
+ "command_result_chunk",
1219
+ "response"
1220
+ ];
1221
+ var isDaemonToDashboardP2PType = makeTypeGuard(DAEMON_TO_DASHBOARD_P2P_TYPES);
1222
+ function decodeDaemonToDashboardP2P(raw) {
1223
+ if (!isRecord(raw)) return null;
1224
+ if (raw.type === void 0 && isNonEmptyString(raw.id) && typeof raw.success === "boolean") {
1225
+ return { ...raw, type: "response" };
1226
+ }
1227
+ if (!isDaemonToDashboardP2PType(raw.type)) return null;
1228
+ switch (raw.type) {
1229
+ case "ping":
1230
+ case "pong":
1231
+ case "p2p_evicted":
1232
+ return raw;
1233
+ case "status_report":
1234
+ case "status_event":
1235
+ return isRecord(raw.payload) ? raw : null;
1236
+ case "topic_update":
1237
+ return isRecord(raw.update) ? raw : null;
1238
+ case "topic_update_chunk":
1239
+ case "command_result_chunk":
1240
+ case "session_output_chunk": {
1241
+ const fields = readChunkFields(raw);
1242
+ if (!fields) return null;
1243
+ if (raw.type === "session_output_chunk") {
1244
+ return isNonEmptyString(raw.sessionId) ? { type: raw.type, sessionId: raw.sessionId, ...fields } : null;
1245
+ }
1246
+ return { type: raw.type, ...fields };
1247
+ }
1248
+ case "session_output":
1249
+ return isNonEmptyString(raw.sessionId) && typeof raw.data === "string" ? raw : null;
1250
+ case "session_io_error":
1251
+ return isNonEmptyString(raw.sessionId) ? raw : null;
1252
+ case "command_result":
1253
+ case "response":
1254
+ return isNonEmptyString(raw.id) ? raw : null;
1255
+ }
1256
+ }
1257
+ var DASHBOARD_P2P_MESSAGE_KINDS = [
1258
+ .../* @__PURE__ */ new Set([...DASHBOARD_TO_DAEMON_P2P_TYPES, ...DAEMON_TO_DASHBOARD_P2P_TYPES])
1259
+ ];
1260
+
1261
+ // src/ws-protocol.ts
1262
+ var DAEMON_TO_SERVER_WS_MSGS = DAEMON_TO_SERVER_TYPES;
1263
+ var SERVER_TO_DAEMON_WS_MSGS = SERVER_TO_DAEMON_CONTROL_TYPES;
1264
+ var isDaemonToServerWsMsg = isDaemonToServerType;
1265
+ var isServerToDaemonWsMsg = isServerToDaemonControlType;
1266
+ function normalizeAuthOkLimits(raw) {
1267
+ if (!raw || typeof raw !== "object") return null;
1268
+ const src = raw;
1269
+ const num = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
1270
+ return {
1271
+ maxP2Pconnections: num(
1272
+ src.maxP2Pconnections !== void 0 ? src.maxP2Pconnections : src.maxP2PConnections,
1273
+ -1
1274
+ ),
1275
+ screenshotIntervalSeconds: num(src.screenshotIntervalSeconds, 0),
1276
+ dailyScreenshotMinutes: num(src.dailyScreenshotMinutes, -1),
1277
+ maxMachines: num(src.maxMachines, -1)
1278
+ };
990
1279
  }
991
1280
 
992
1281
  // src/interactive-prompt-constants.ts
993
1282
  var CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX = "Claude TUI review page is not focused";
994
1283
  var CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX = "Claude TUI answer delivered but not confirmed";
1284
+
1285
+ // src/session-status.ts
1286
+ var SESSION_STATUSES = [
1287
+ "idle",
1288
+ "generating",
1289
+ "waiting_approval",
1290
+ "waiting_choice",
1291
+ "finalizing",
1292
+ "error",
1293
+ "stopped",
1294
+ "starting",
1295
+ "panel_hidden",
1296
+ "not_monitored",
1297
+ "disconnected"
1298
+ ];
1299
+ var RECENT_SESSION_BUCKETS = ["needs_attention", "working", "task_complete", "idle"];
1300
+ var SESSION_STATUS_CLASS = {
1301
+ generating: "working",
1302
+ finalizing: "working",
1303
+ starting: "working",
1304
+ waiting_approval: "blocked",
1305
+ waiting_choice: "blocked",
1306
+ idle: "ready",
1307
+ panel_hidden: "ready",
1308
+ not_monitored: "ready",
1309
+ error: "dead",
1310
+ stopped: "dead",
1311
+ disconnected: "dead"
1312
+ };
1313
+ var SESSION_STATUS_ALIASES = {
1314
+ running: "generating",
1315
+ streaming: "generating",
1316
+ busy: "generating",
1317
+ working: "generating",
1318
+ loading: "generating",
1319
+ loading_reference: "generating",
1320
+ thinking: "generating",
1321
+ active: "generating",
1322
+ // Status-lane refinements of a turn that is still owned by the agent.
1323
+ no_progress: "generating",
1324
+ long_generating: "generating",
1325
+ initializing: "starting",
1326
+ waiting: "waiting_approval"
1327
+ };
1328
+ var SESSION_STATUS_SET = new Set(SESSION_STATUSES);
1329
+ function isSessionStatus(value) {
1330
+ return typeof value === "string" && SESSION_STATUS_SET.has(value);
1331
+ }
1332
+ function normalizeSessionStatus(raw) {
1333
+ if (typeof raw !== "string") return null;
1334
+ const value = raw.trim().toLowerCase();
1335
+ if (SESSION_STATUS_SET.has(value)) return value;
1336
+ return SESSION_STATUS_ALIASES[value] ?? null;
1337
+ }
1338
+ function classifySessionStatus(raw) {
1339
+ const status = normalizeSessionStatus(raw);
1340
+ return status ? SESSION_STATUS_CLASS[status] : "unknown";
1341
+ }
1342
+ function isWorkingStatus(raw) {
1343
+ return classifySessionStatus(raw) === "working";
1344
+ }
1345
+ function isBlockedStatus(raw) {
1346
+ return classifySessionStatus(raw) === "blocked";
1347
+ }
1348
+ function isReadyStatus(raw) {
1349
+ return classifySessionStatus(raw) === "ready";
1350
+ }
1351
+ function isDeadStatus(raw) {
1352
+ return classifySessionStatus(raw) === "dead";
1353
+ }
1354
+ function isBusyStatus(raw) {
1355
+ const cls = classifySessionStatus(raw);
1356
+ return cls === "working" || cls === "blocked";
1357
+ }
1358
+ function statusesOfClass(cls) {
1359
+ return SESSION_STATUSES.filter((status) => SESSION_STATUS_CLASS[status] === cls);
1360
+ }
1361
+
1362
+ // src/mesh-vocabulary.ts
1363
+ var MESH_TASK_STATUSES = ["pending", "assigned", "completed", "failed", "cancelled"];
1364
+ var MESH_TERMINAL_TASK_STATUSES = ["completed", "failed", "cancelled"];
1365
+ var MESH_TASK_MODES = ["code_change", "validation", "live_debug_readonly", "launch_app", "convergence"];
1366
+ var MESH_TASK_PRIORITIES = ["low", "normal", "high"];
1367
+ var MESH_THINKING_LEVELS = ["low", "medium", "high"];
1368
+ var MESH_DELIVERY_MODES = ["when_idle", "interrupt"];
1369
+ var MESH_SESSION_CLEANUP_MODES = ["preserve", "stop", "delete_stopped", "stop_and_delete"];
1370
+ var WORKER_REPORT_OUTCOMES = ["completed", "blocked", "failed"];
1371
+ var WORKER_BRANCH_STATES = [
1372
+ "merged_to_main",
1373
+ "pushed_feature_branch_needs_merge",
1374
+ "blocked_review",
1375
+ "cleanup_candidate",
1376
+ "not_mergeable"
1377
+ ];
1378
+ function makeGuard(values) {
1379
+ const set = new Set(values);
1380
+ return (value) => typeof value === "string" && set.has(value);
1381
+ }
1382
+ var isMeshTaskStatus = makeGuard(MESH_TASK_STATUSES);
1383
+ var isMeshTerminalTaskStatus = makeGuard(MESH_TERMINAL_TASK_STATUSES);
1384
+ var isMeshTaskMode = makeGuard(MESH_TASK_MODES);
1385
+ var isMeshTaskPriority = makeGuard(MESH_TASK_PRIORITIES);
1386
+ var isMeshThinkingLevel = makeGuard(MESH_THINKING_LEVELS);
1387
+ var isMeshDeliveryMode = makeGuard(MESH_DELIVERY_MODES);
1388
+ var isMeshSessionCleanupMode = makeGuard(MESH_SESSION_CLEANUP_MODES);
1389
+ var isWorkerReportOutcome = makeGuard(WORKER_REPORT_OUTCOMES);
1390
+ var isWorkerBranchState = makeGuard(WORKER_BRANCH_STATES);
1391
+ function enumOf(values, description) {
1392
+ return {
1393
+ type: "string",
1394
+ enum: [...values],
1395
+ ...description ? { description } : {}
1396
+ };
1397
+ }
1398
+
1399
+ // src/outbound-message.ts
1400
+ var outboundMessageIdCounter = 0;
1401
+ function mintMessageId(now = Date.now()) {
1402
+ try {
1403
+ const cryptoRef = typeof globalThis !== "undefined" ? globalThis.crypto : void 0;
1404
+ if (typeof cryptoRef?.randomUUID === "function") return `msg_${cryptoRef.randomUUID()}`;
1405
+ } catch {
1406
+ }
1407
+ outboundMessageIdCounter += 1;
1408
+ return `msg_${now}_${outboundMessageIdCounter}`;
1409
+ }
1410
+ var MESSAGE_ID_PREFIX = "msg_";
1411
+ function isMessageId(value) {
1412
+ return typeof value === "string" && value.length > MESSAGE_ID_PREFIX.length && value.startsWith(MESSAGE_ID_PREFIX);
1413
+ }
1414
+ var OUTBOUND_MESSAGE_ORIGINS = ["dashboard", "mcp", "mesh", "api", "cli"];
1415
+ function isOutboundMessageOrigin(value) {
1416
+ return typeof value === "string" && OUTBOUND_MESSAGE_ORIGINS.includes(value);
1417
+ }
1418
+ var SEND_POLICY_MODES = ["queue", "send_now", "interrupt"];
1419
+ function isSendPolicyMode(value) {
1420
+ return typeof value === "string" && SEND_POLICY_MODES.includes(value);
1421
+ }
1422
+ function isSendPolicy(value) {
1423
+ return !!value && typeof value === "object" && isSendPolicyMode(value.mode);
1424
+ }
1425
+ var SEND_REFUSAL_REASONS = [
1426
+ "not_ready",
1427
+ "send_in_flight",
1428
+ "not_generating",
1429
+ "not_supported",
1430
+ "platform_unsupported",
1431
+ "modal_parked",
1432
+ "interrupt_not_implemented",
1433
+ "interrupt_refused",
1434
+ "idle_timeout",
1435
+ "session_exited",
1436
+ "unsupported_input",
1437
+ "no_target",
1438
+ "bootstrap_pending",
1439
+ "duplicate_dispatch",
1440
+ "internal_error"
1441
+ ];
1442
+ function isSendRefusal(value) {
1443
+ return typeof value === "string" && SEND_REFUSAL_REASONS.includes(value);
1444
+ }
1445
+ var SUBMIT_OUTCOME_KINDS = ["delivered", "queued", "duplicate", "refused"];
1446
+ function isSubmitOutcome(value) {
1447
+ if (!value || typeof value !== "object") return false;
1448
+ const kind = value.kind;
1449
+ if (typeof kind !== "string" || !SUBMIT_OUTCOME_KINDS.includes(kind)) return false;
1450
+ if (kind === "queued") return typeof value.position === "number";
1451
+ if (kind === "duplicate") return typeof value.of === "string";
1452
+ if (kind === "refused") return isSendRefusal(value.reason);
1453
+ return true;
1454
+ }
1455
+ function isInputPartWire(value) {
1456
+ if (!value || typeof value !== "object") return false;
1457
+ const type = value.type;
1458
+ return type === "text" || type === "image" || type === "audio" || type === "video" || type === "resource" || type === "resource_link";
1459
+ }
1460
+ function isInputEnvelopeWire(value) {
1461
+ if (!value || typeof value !== "object") return false;
1462
+ const parts = value.parts;
1463
+ const textFallback = value.textFallback;
1464
+ return Array.isArray(parts) && parts.every(isInputPartWire) && typeof textFallback === "string";
1465
+ }
1466
+ function isOutboundMessage(value) {
1467
+ if (!value || typeof value !== "object") return false;
1468
+ const candidate = value;
1469
+ 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";
1470
+ }
1471
+
1472
+ // src/mission-brief.ts
1473
+ var GOAL_MAX = 500;
1474
+ var LIST_ITEM_MAX = 200;
1475
+ var LIST_MAX_ITEMS = 12;
1476
+ var MISSION_BRIEF_RENDER_MAX_CHARS = 1200;
1477
+ function truncateString(value, max) {
1478
+ if (value.length <= max) return value;
1479
+ return `${value.slice(0, max - 1).trimEnd()}\u2026`;
1480
+ }
1481
+ function normalizeStringList(value, field, truncated) {
1482
+ if (value === void 0 || value === null) return void 0;
1483
+ if (!Array.isArray(value)) return void 0;
1484
+ const items = [];
1485
+ let itemTruncated = false;
1486
+ for (const raw of value) {
1487
+ if (typeof raw !== "string") continue;
1488
+ const trimmed = raw.trim();
1489
+ if (!trimmed) continue;
1490
+ if (trimmed.length > LIST_ITEM_MAX) itemTruncated = true;
1491
+ items.push(truncateString(trimmed, LIST_ITEM_MAX));
1492
+ }
1493
+ if (itemTruncated) truncated.push({ field, reason: "item_too_long" });
1494
+ if (items.length > LIST_MAX_ITEMS) {
1495
+ truncated.push({ field, reason: "list_too_long" });
1496
+ return items.slice(0, LIST_MAX_ITEMS);
1497
+ }
1498
+ return items.length > 0 ? items : void 0;
1499
+ }
1500
+ function normalizeMissionBrief(input) {
1501
+ const truncated = [];
1502
+ if (!input || typeof input !== "object") {
1503
+ return { brief: null, truncated };
1504
+ }
1505
+ const raw = input;
1506
+ const rawGoal = typeof raw.goal === "string" ? raw.goal.trim() : "";
1507
+ if (!rawGoal) {
1508
+ return { brief: null, truncated };
1509
+ }
1510
+ if (rawGoal.length > GOAL_MAX) truncated.push({ field: "goal", reason: "field_too_long" });
1511
+ const goal = truncateString(rawGoal, GOAL_MAX);
1512
+ const constraints = normalizeStringList(raw.constraints, "constraints", truncated);
1513
+ const doneCriteria = normalizeStringList(raw.doneCriteria ?? raw.done_criteria, "doneCriteria", truncated);
1514
+ const handoffNotes = normalizeStringList(raw.handoffNotes ?? raw.handoff_notes, "handoffNotes", truncated);
1515
+ const ownedPaths = normalizeStringList(raw.ownedPaths ?? raw.owned_paths, "ownedPaths", truncated);
1516
+ const brief = { goal };
1517
+ if (constraints) brief.constraints = constraints;
1518
+ if (doneCriteria) brief.doneCriteria = doneCriteria;
1519
+ if (handoffNotes) brief.handoffNotes = handoffNotes;
1520
+ if (ownedPaths) brief.ownedPaths = ownedPaths;
1521
+ return { brief, truncated };
1522
+ }
1523
+ function renderList(heading, items) {
1524
+ if (!items || items.length === 0) return [];
1525
+ return [`${heading}:`, ...items.map((item) => `- ${item}`)];
1526
+ }
1527
+ function renderMissionBriefBlock(brief) {
1528
+ const sections = [`Mission goal: ${brief.goal}`];
1529
+ sections.push(...renderList("Constraints", brief.constraints));
1530
+ sections.push(...renderList("Done when", brief.doneCriteria));
1531
+ sections.push(...renderList("Owned paths", brief.ownedPaths));
1532
+ sections.push(...renderList("Handoff notes", brief.handoffNotes));
1533
+ const full = sections.join("\n");
1534
+ if (full.length <= MISSION_BRIEF_RENDER_MAX_CHARS) return full;
1535
+ const marker = "\n(brief truncated)";
1536
+ const budget = MISSION_BRIEF_RENDER_MAX_CHARS - marker.length;
1537
+ const lines = full.split("\n");
1538
+ let acc = "";
1539
+ for (const line of lines) {
1540
+ const next = acc ? `${acc}
1541
+ ${line}` : line;
1542
+ if (next.length > budget) break;
1543
+ acc = next;
1544
+ }
1545
+ if (!acc) acc = truncateString(lines[0] ?? "", Math.max(budget, 0));
1546
+ return `${acc}${marker}`;
1547
+ }
1548
+
1549
+ // src/worker-protocol.ts
1550
+ var WORKER_TOOLS = [
1551
+ "report_completion",
1552
+ "progress_update",
1553
+ "peer_context_pull",
1554
+ "git_status",
1555
+ "git_log",
1556
+ "git_diff"
1557
+ ];
1558
+ var WORKER_TOOL_SET = new Set(WORKER_TOOLS);
1559
+ function isWorkerTool(value) {
1560
+ return typeof value === "string" && WORKER_TOOL_SET.has(value);
1561
+ }
1562
+ var WORKER_PROTOCOL_FOOTER_MARKER = "--- adhdev worker protocol ---";
1563
+ function hasWorkerProtocolFooter(body) {
1564
+ return typeof body === "string" && body.includes(WORKER_PROTOCOL_FOOTER_MARKER);
1565
+ }
1566
+ function renderWorkerProtocolFooter(input = {}) {
1567
+ const briefBlock = input.missionBrief ? renderMissionBriefBlock(input.missionBrief) : null;
1568
+ const lines = briefBlock ? [briefBlock, "", WORKER_PROTOCOL_FOOTER_MARKER] : [WORKER_PROTOCOL_FOOTER_MARKER];
1569
+ const scope = [];
1570
+ if (input.taskId) scope.push(`task ${input.taskId}`);
1571
+ if (input.taskMode) scope.push(`mode ${input.taskMode}`);
1572
+ if (input.difficulty) scope.push(`difficulty ${input.difficulty}`);
1573
+ if (input.readonly) scope.push("read-only");
1574
+ if (scope.length) lines.push(`You are a delegated worker (${scope.join(", ")}).`);
1575
+ else lines.push("You are a delegated worker.");
1576
+ lines.push(
1577
+ "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.",
1578
+ "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.",
1579
+ "`peer_context_pull` shows what sibling tasks in this mission have reported; `git_status` / `git_diff` / `git_log` inspect your own workspace (pass its absolute path as `workspace`).",
1580
+ "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`."
1581
+ );
1582
+ if (input.enclosedHandoffNotes && input.enclosedHandoffNotes > 0) {
1583
+ lines.push(
1584
+ `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.`
1585
+ );
1586
+ }
1587
+ return lines.join("\n");
1588
+ }
1589
+ function stripWorkerProtocolFooter(body) {
1590
+ if (typeof body !== "string") return body;
1591
+ const at = body.indexOf(WORKER_PROTOCOL_FOOTER_MARKER);
1592
+ if (at < 0) return body;
1593
+ return body.slice(0, at).replace(/\s+$/, "");
1594
+ }
1595
+ function appendWorkerProtocolFooter(body, input = {}) {
1596
+ if (hasWorkerProtocolFooter(body)) return body;
1597
+ const trimmed = body.replace(/\s+$/, "");
1598
+ return `${trimmed}
1599
+
1600
+ ${renderWorkerProtocolFooter(input)}`;
1601
+ }
1602
+ function renderCoordinatorWorkerSection() {
1603
+ return [
1604
+ "## Workers",
1605
+ "",
1606
+ `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.`,
1607
+ "- 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.",
1608
+ "- `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.",
1609
+ "- 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.",
1610
+ "- `mesh_status` is for node health and capacity before delegating, never for progress.",
1611
+ "- 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."
1612
+ ].join("\n");
1613
+ }
1614
+
1615
+ // src/turn-evidence.ts
1616
+ var MESH_TOPIC_PROTOCOL_VERSION = 2;
1617
+ var EVIDENCE_SOURCE_IDS = [
1618
+ "fsm_edge",
1619
+ "short_gen_inline",
1620
+ "completion_flush_genuine",
1621
+ "completion_flush_weak",
1622
+ "monitor_final_summary",
1623
+ "pre_cleanup_transcript",
1624
+ "stall_transcript",
1625
+ "startup_grace_collapse",
1626
+ "acp_prompt_response",
1627
+ "cdp_state",
1628
+ "approval_gate",
1629
+ "modal_button",
1630
+ "mesh_stall_watchdog",
1631
+ "status_monitor",
1632
+ "pty_exit",
1633
+ "provider_error",
1634
+ "coordinator_probe",
1635
+ "mcp_probe",
1636
+ "worker_tool",
1637
+ "dispatch",
1638
+ "input_service",
1639
+ "operator",
1640
+ "intentional_cleanup",
1641
+ "scheduler",
1642
+ "git_probe",
1643
+ "session_registry"
1644
+ ];
1645
+ var TURN_SCOPES = ["mesh_queue", "mesh_direct", "plain"];
1646
+ var RECLAIMING_SEND_REFUSALS = ["session_exited", "no_target", "unsupported_input"];
1647
+ var DELIVERY_OUTCOMES = ["delivered", "queued"];
1648
+ var DELIVERY_VIAS = ["local", "p2p"];
1649
+ var DISPATCH_FAILURE_REASONS = ["worker_absent", "transport_error", "spawn_failed", "rejected_by_worker", "timeout"];
1650
+ var CONSUME_PROFILES = ["default", "native_source"];
1651
+ var SESSION_REBOUND_REASONS = ["restart", "live_holder"];
1652
+ var SUSPENSION_MODALS = ["approval", "choice"];
1653
+ var SUSPENSION_RESOLUTIONS = ["approved", "rejected", "answered"];
1654
+ var SUSPENSION_RESOLUTION_VIAS = ["modal_button", "auto_approve", "prompt_answer"];
1655
+ var TURN_END_STRENGTHS = ["genuine", "weak"];
1656
+ var TURN_END_BLOCK_REASONS = [
1657
+ "missing_final_assistant",
1658
+ "finalization_timeout",
1659
+ "terminal_block_hard_cap",
1660
+ "decoupled_completion"
1661
+ ];
1662
+ var NATIVE_TURN_OUTCOMES = ["completed", "aborted"];
1663
+ var LIVENESS_RESULTS = ["alive", "unknown", "read_failed", "dead"];
1664
+ var PROVIDER_FAILURES = ["auth_failed", "billing_failed"];
1665
+ var SESSION_ERROR_REASONS = ["provider_error", "adapter_error", "spawn_failed", "auth_failed", "billing_failed", "unknown", "daemon_restart"];
1666
+ var CANCEL_REASONS = ["operator_cancel", "intentional_cleanup", "task_removed", "mission_abandoned", "superseded"];
1667
+ var OPERATOR_STATUSES = ["completed", "failed"];
1668
+ var OPERATOR_STATUS_REASONS = ["operator_update", "refine_terminal", "validation_terminal"];
1669
+ var COORDINATOR_ACK_OUTCOMES = ["delivered", "queued", "duplicate"];
1670
+ var NO_PROGRESS_OBSERVED_STATUSES = [...SESSION_STATUSES, "unknown"];
1671
+ var HOLD_REASONS = [
1672
+ "await_delivery",
1673
+ "await_consume",
1674
+ "await_turn",
1675
+ "liveness",
1676
+ "hard_ceiling",
1677
+ "live_pending",
1678
+ "transcript_quiet",
1679
+ "weak_candidate",
1680
+ "suspension_before_consumed"
1681
+ ];
1682
+ var TURN_OUTCOMES = ["completed", "failed", "cancelled"];
1683
+ var COMMIT_STRENGTHS = ["genuine", "weak", "tool_report", "operator"];
1684
+ var TURN_REASONS = [
1685
+ // commits
1686
+ "turn_end",
1687
+ "weak_end_confirmed",
1688
+ "transcript_final",
1689
+ "worker_reported",
1690
+ "finalization_timeout_no_response",
1691
+ "session_error",
1692
+ "provider_auth_failed",
1693
+ "provider_billing_failed",
1694
+ "operator_cancel",
1695
+ "intentional_cleanup",
1696
+ "task_removed",
1697
+ "mission_abandoned",
1698
+ "superseded",
1699
+ "operator_update",
1700
+ "refine_terminal",
1701
+ "validation_terminal",
1702
+ "hard_ceiling",
1703
+ "reclaim_budget_exhausted",
1704
+ "hollow_max_retries",
1705
+ "migration_orphan",
1706
+ // reclaims (generation + 1)
1707
+ "dispatch_refused_session_exited",
1708
+ "dispatch_refused_no_target",
1709
+ "dispatch_refused_unsupported_input",
1710
+ "dispatch_failed",
1711
+ "session_exit",
1712
+ "session_exit_before_turn",
1713
+ "session_dead",
1714
+ "hollow_completion",
1715
+ "assigned_stranded_dispatch_unconfirmed",
1716
+ "delivered_not_consumed_redrive",
1717
+ "delivered_no_turn_deadline"
1718
+ ];
1719
+ var NOTIFY_KINDS = [
1720
+ "completed",
1721
+ "failed",
1722
+ "cancelled",
1723
+ "stopped",
1724
+ "approval",
1725
+ "choice",
1726
+ "approval_resolved",
1727
+ "candidate",
1728
+ "no_progress",
1729
+ "progress",
1730
+ "late_completion",
1731
+ "mesh_event"
1732
+ ];
1733
+ var id = { t: "id" };
1734
+ var idOpt = { t: "id", optional: true };
1735
+ var bool = { t: "bool" };
1736
+ var boolOpt = { t: "bool", optional: true };
1737
+ var ms = { t: "ms" };
1738
+ var msOpt = { t: "ms", optional: true };
1739
+ var intOpt = { t: "int", optional: true };
1740
+ var en = (values) => ({ t: "enum", values });
1741
+ var enOpt = (values) => ({ t: "enum", values, optional: true });
1742
+ var EVIDENCE_ENVELOPE_FIELD_SPECS = {
1743
+ eventId: id,
1744
+ at: ms,
1745
+ source: en(EVIDENCE_SOURCE_IDS),
1746
+ sessionId: id,
1747
+ attemptRef: { t: "attempt_ref", optional: true },
1748
+ taskId: idOpt,
1749
+ observedBy: id
1750
+ };
1751
+ var TURN_EVIDENCE_FIELD_SPECS = {
1752
+ dispatch_accepted: {
1753
+ scope: en(TURN_SCOPES),
1754
+ messageId: id,
1755
+ meshId: idOpt,
1756
+ nodeId: idOpt,
1757
+ providerType: idOpt,
1758
+ attemptNo: intOpt,
1759
+ dispatchNonce: intOpt,
1760
+ consumeProfile: enOpt(CONSUME_PROFILES),
1761
+ maxTaskRetries: intOpt,
1762
+ coordinator: { t: "coordinator", optional: true }
1763
+ },
1764
+ delivered: { messageId: id, outcome: en(DELIVERY_OUTCOMES), via: en(DELIVERY_VIAS) },
1765
+ delivery_refused: { messageId: id, reason: en(SEND_REFUSAL_REASONS) },
1766
+ dispatch_failed: { workerAbsent: bool, reason: en(DISPATCH_FAILURE_REASONS) },
1767
+ duplicate_dispatch_refusal: { holderSessionId: id, holderAttemptId: idOpt },
1768
+ session_rebound: { toSessionId: id, reason: en(SESSION_REBOUND_REASONS) },
1769
+ turn_started: { retro: bool },
1770
+ suspension: { modal: en(SUSPENSION_MODALS), modalKey: idOpt },
1771
+ suspension_resolved: { resolution: en(SUSPENSION_RESOLUTIONS), via: en(SUSPENSION_RESOLUTION_VIAS) },
1772
+ turn_end: {
1773
+ strength: en(TURN_END_STRENGTHS),
1774
+ afterFinalizationTimeout: boolOpt,
1775
+ hollow: boolOpt,
1776
+ summary: { t: "summary_ref", optional: true },
1777
+ blockReason: enOpt(TURN_END_BLOCK_REASONS),
1778
+ releasedByHardCap: boolOpt,
1779
+ nativeOutcome: enOpt(NATIVE_TURN_OUTCOMES),
1780
+ live: { t: "live", optional: true }
1781
+ },
1782
+ transcript_final: {
1783
+ selfAttributing: bool,
1784
+ nativeRead: bool,
1785
+ nativeMarker: { t: "native_marker", optional: true },
1786
+ live: { t: "live" },
1787
+ summary: { t: "summary_ref", optional: true },
1788
+ messageAt: msOpt
1789
+ },
1790
+ transcript_activity: { newestActivityAt: ms },
1791
+ no_progress: { stalledMs: ms, observedStatus: en(NO_PROGRESS_OBSERVED_STATUSES), finalAssistantPresent: bool },
1792
+ liveness: { result: en(LIVENESS_RESULTS) },
1793
+ process_exit: { exitCode: { t: "int", nullable: true }, providerFailure: enOpt(PROVIDER_FAILURES) },
1794
+ session_error: { reason: en(SESSION_ERROR_REASONS) },
1795
+ worker_report: {
1796
+ outcome: en(WORKER_REPORT_OUTCOMES),
1797
+ summary: { t: "summary_ref" },
1798
+ hasHandoffNotes: bool,
1799
+ branchState: enOpt(WORKER_BRANCH_STATES),
1800
+ touchedFileCount: intOpt
1801
+ },
1802
+ worker_progress: { note: { t: "summary_ref", optional: true } },
1803
+ git_side_effect: { dirty: bool, commitsSinceDispatch: { t: "int" }, attributable: bool },
1804
+ cancel: { reason: en(CANCEL_REASONS) },
1805
+ operator_status: { status: en(OPERATOR_STATUSES), reason: en(OPERATOR_STATUS_REASONS) },
1806
+ coordinator_ack: { notify: en(NOTIFY_KINDS), outcome: en(COORDINATOR_ACK_OUTCOMES) },
1807
+ hold_expired: { holdId: id, reason: en(HOLD_REASONS) }
1808
+ };
1809
+ var TURN_EVIDENCE_KINDS = Object.keys(TURN_EVIDENCE_FIELD_SPECS);
1810
+ var TERMINAL_CLASS_EVIDENCE_KINDS = [
1811
+ "turn_end",
1812
+ "transcript_final",
1813
+ "no_progress",
1814
+ "worker_report",
1815
+ "session_error",
1816
+ "process_exit",
1817
+ "cancel",
1818
+ "operator_status"
1819
+ ];
1820
+ var IDENTIFIER_RE = /^[^\s\u0000-\u001f\u007f]{1,256}$/;
1821
+ function makeGuard2(values) {
1822
+ const set = new Set(values);
1823
+ return (value) => typeof value === "string" && set.has(value);
1824
+ }
1825
+ var isEvidenceSourceId = makeGuard2(EVIDENCE_SOURCE_IDS);
1826
+ var isTurnEvidenceKind = makeGuard2(TURN_EVIDENCE_KINDS);
1827
+ var isTurnReason = makeGuard2(TURN_REASONS);
1828
+ var isNotifyKind = makeGuard2(NOTIFY_KINDS);
1829
+ var isHoldReason = makeGuard2(HOLD_REASONS);
1830
+ var isTurnOutcome = makeGuard2(TURN_OUTCOMES);
1831
+ var isCommitStrength = makeGuard2(COMMIT_STRENGTHS);
1832
+ function isRecord2(value) {
1833
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1834
+ }
1835
+ function isEvidenceIdentifier(value) {
1836
+ return typeof value === "string" && IDENTIFIER_RE.test(value);
1837
+ }
1838
+ function isFiniteNumber2(value) {
1839
+ return typeof value === "number" && Number.isFinite(value);
1840
+ }
1841
+ function isSummaryRef(value) {
1842
+ return isRecord2(value) && hasOnlyKeys(value, ["topic", "writer", "seq"]) && isEvidenceIdentifier(value.topic) && isEvidenceIdentifier(value.writer) && Number.isSafeInteger(value.seq) && value.seq >= 0;
1843
+ }
1844
+ function isTurnAttemptRef(value) {
1845
+ return isRecord2(value) && hasOnlyKeys(value, ["attemptId", "generation"]) && isEvidenceIdentifier(value.attemptId) && Number.isSafeInteger(value.generation) && value.generation >= 0;
1846
+ }
1847
+ function isLiveTurnPending(value) {
1848
+ 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));
1849
+ }
1850
+ function isNativeMarkerRef(value) {
1851
+ return isRecord2(value) && hasOnlyKeys(value, ["outcome", "turnId"]) && NATIVE_TURN_OUTCOMES.includes(value.outcome) && (value.turnId === void 0 || isEvidenceIdentifier(value.turnId));
1852
+ }
1853
+ function isCoordinatorIdentity(value) {
1854
+ return isRecord2(value) && hasOnlyKeys(value, ["daemonId", "coordinatorRunId", "sessionId"]) && isEvidenceIdentifier(value.daemonId) && isEvidenceIdentifier(value.coordinatorRunId) && (value.sessionId === void 0 || isEvidenceIdentifier(value.sessionId));
1855
+ }
1856
+ function hasOnlyKeys(value, allowed) {
1857
+ for (const key of Object.keys(value)) {
1858
+ if (!allowed.includes(key)) return false;
1859
+ }
1860
+ return true;
1861
+ }
1862
+ function fieldMatches(spec, value) {
1863
+ if (value === void 0) return spec.optional === true;
1864
+ switch (spec.t) {
1865
+ case "id":
1866
+ return isEvidenceIdentifier(value);
1867
+ case "enum":
1868
+ return typeof value === "string" && spec.values.includes(value);
1869
+ case "bool":
1870
+ return typeof value === "boolean";
1871
+ case "int":
1872
+ return value === null && spec.nullable === true || Number.isSafeInteger(value);
1873
+ case "ms":
1874
+ return isFiniteNumber2(value) && value >= 0;
1875
+ case "summary_ref":
1876
+ return isSummaryRef(value);
1877
+ case "attempt_ref":
1878
+ return isTurnAttemptRef(value);
1879
+ case "live":
1880
+ return isLiveTurnPending(value);
1881
+ case "native_marker":
1882
+ return isNativeMarkerRef(value);
1883
+ case "coordinator":
1884
+ return isCoordinatorIdentity(value);
1885
+ }
1886
+ }
1887
+ function isTurnEvidence(value) {
1888
+ if (!isRecord2(value) || !isTurnEvidenceKind(value.kind)) return false;
1889
+ const bodySpecs = TURN_EVIDENCE_FIELD_SPECS[value.kind];
1890
+ const envelopeSpecs = EVIDENCE_ENVELOPE_FIELD_SPECS;
1891
+ for (const key of Object.keys(value)) {
1892
+ if (key === "kind") continue;
1893
+ if (!(key in bodySpecs) && !(key in envelopeSpecs)) return false;
1894
+ }
1895
+ for (const [key, spec] of Object.entries(envelopeSpecs)) {
1896
+ if (!fieldMatches(spec, value[key])) return false;
1897
+ }
1898
+ for (const [key, spec] of Object.entries(bodySpecs)) {
1899
+ if (!fieldMatches(spec, value[key])) return false;
1900
+ }
1901
+ return true;
1902
+ }
1903
+ function isTerminalClassEvidenceKind(kind) {
1904
+ return TERMINAL_CLASS_EVIDENCE_KINDS.includes(kind);
1905
+ }
1906
+ var TURN_EVIDENCE_FLAGS = ["hollow", "afterFinalizationTimeout", "nativeMarker", "selfAttributing"];
1907
+ var MESH_TOPIC_ENTRY_KINDS = ["turn.evidence", "turn.committed", "turn.notify", "mesh.record"];
1908
+ var isMeshTopicEntryKind = makeGuard2(MESH_TOPIC_ENTRY_KINDS);
1909
+ function isOptionalId(value) {
1910
+ return value === void 0 || isEvidenceIdentifier(value);
1911
+ }
1912
+ function isGeneration(value) {
1913
+ return Number.isSafeInteger(value) && value >= 0;
1914
+ }
1915
+ function isProjectedScalars(value) {
1916
+ if (!isRecord2(value)) return false;
1917
+ for (const v of Object.values(value)) {
1918
+ if (!(v === null || typeof v === "number" || typeof v === "boolean" || typeof v === "string")) return false;
1919
+ }
1920
+ return true;
1921
+ }
1922
+ function isMeshTopicEntry(value) {
1923
+ if (!isRecord2(value)) return false;
1924
+ if (value.v !== MESH_TOPIC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.eventId) || !isFiniteNumber2(value.at)) return false;
1925
+ switch (value.k) {
1926
+ case "turn.evidence": {
1927
+ if (!isEvidenceIdentifier(value.attemptId) || !isGeneration(value.generation)) return false;
1928
+ if (!isEvidenceIdentifier(value.ownerDaemonId) || !isEvidenceIdentifier(value.sessionId) || !isOptionalId(value.taskId)) return false;
1929
+ if (!isTurnEvidenceKind(value.ev)) return false;
1930
+ if (value.strength !== void 0 && !TURN_END_STRENGTHS.includes(value.strength)) return false;
1931
+ if (value.flags !== void 0) {
1932
+ if (!isRecord2(value.flags)) return false;
1933
+ for (const [flag, on] of Object.entries(value.flags)) {
1934
+ if (!TURN_EVIDENCE_FLAGS.includes(flag) || typeof on !== "boolean") return false;
1935
+ }
1936
+ }
1937
+ if (value.evidence !== void 0 && !(isTurnEvidence(value.evidence) && value.evidence.kind === value.ev)) return false;
1938
+ return true;
1939
+ }
1940
+ case "turn.committed":
1941
+ return isEvidenceIdentifier(value.attemptId) && isGeneration(value.generation) && isOptionalId(value.taskId) && isTurnOutcome(value.outcome) && isCommitStrength(value.strength) && isTurnReason(value.reason);
1942
+ case "turn.notify":
1943
+ return isOptionalId(value.attemptId) && isNotifyKind(value.notify) && isEvidenceIdentifier(value.targetDaemonId) && isOptionalId(value.targetSessionId) && isOptionalId(value.taskId);
1944
+ case "mesh.record":
1945
+ return isEvidenceIdentifier(value.ledgerKind) && isOptionalId(value.nodeId) && isOptionalId(value.sessionId) && isOptionalId(value.taskId) && isProjectedScalars(value.payload);
1946
+ default:
1947
+ return false;
1948
+ }
1949
+ }
1950
+ function projectTurnEvidenceEntry(evidence, attempt) {
1951
+ const flags = {};
1952
+ if (evidence.kind === "turn_end") {
1953
+ if (evidence.hollow) flags.hollow = true;
1954
+ if (evidence.afterFinalizationTimeout) flags.afterFinalizationTimeout = true;
1955
+ }
1956
+ if (evidence.kind === "transcript_final") {
1957
+ if (evidence.nativeMarker) flags.nativeMarker = true;
1958
+ if (evidence.selfAttributing) flags.selfAttributing = true;
1959
+ }
1960
+ const taskId = evidence.taskId;
1961
+ return {
1962
+ v: MESH_TOPIC_PROTOCOL_VERSION,
1963
+ eventId: evidence.eventId,
1964
+ at: evidence.at,
1965
+ k: "turn.evidence",
1966
+ attemptId: attempt.attemptId,
1967
+ generation: attempt.generation,
1968
+ ownerDaemonId: attempt.ownerDaemonId,
1969
+ ...taskId ? { taskId } : {},
1970
+ sessionId: evidence.sessionId,
1971
+ ev: evidence.kind,
1972
+ ...evidence.kind === "turn_end" ? { strength: evidence.strength } : {},
1973
+ ...Object.keys(flags).length > 0 ? { flags } : {},
1974
+ evidence
1975
+ };
1976
+ }
1977
+
1978
+ // src/session-launch.ts
1979
+ var MODEL_AXIS_SOURCES = [
1980
+ /** Picked explicitly for this launch (dashboard dropdown, coordinator dialog). */
1981
+ "user",
1982
+ /** The dashboard dialog restored it from the last launch (browser-local memory). */
1983
+ "remembered",
1984
+ /** A mesh capability slot supplied it (or a difficulty preset the slot outranked). */
1985
+ "mesh_slot",
1986
+ /** An explicit per-task model / thinking level on a mesh queue task. */
1987
+ "task_override",
1988
+ /** Nothing was requested; the provider's default is known (discovery / manifest). */
1989
+ "provider_default",
1990
+ /** A value was requested without saying where it came from, or nothing is known. */
1991
+ "unspecified"
1992
+ ];
1993
+ function isModelAxisSource(value) {
1994
+ return typeof value === "string" && MODEL_AXIS_SOURCES.includes(value);
1995
+ }
1996
+ var SESSION_LAUNCHED_BY = ["dashboard", "mesh", "cli", "api", "restore"];
1997
+ function isSessionLaunchedBy(value) {
1998
+ return typeof value === "string" && SESSION_LAUNCHED_BY.includes(value);
1999
+ }
2000
+ var MODEL_SELECTION_HISTORY_LIMIT = 20;
2001
+ function effectiveModelSelectionValue(selection) {
2002
+ if (!selection) return void 0;
2003
+ const last = Array.isArray(selection.history) ? selection.history[selection.history.length - 1] : void 0;
2004
+ return last?.value ?? selection.current ?? selection.observed ?? launchModelSelectionValue(selection);
2005
+ }
2006
+ function launchModelSelectionValue(selection) {
2007
+ if (!selection) return void 0;
2008
+ const launch = Array.isArray(selection.history) ? selection.history.find((entry) => entry.via === "launch") : void 0;
2009
+ return launch?.value ?? selection.launchValue ?? selection.requested ?? selection.resolvedDefault;
2010
+ }
2011
+ function describeModelSelection(selection) {
2012
+ const value = effectiveModelSelectionValue(selection);
2013
+ if (!selection || !value) return void 0;
2014
+ const launched = launchModelSelectionValue(selection);
2015
+ return {
2016
+ value,
2017
+ ...launched && launched !== value ? { changedFrom: launched } : {},
2018
+ source: isModelAxisSource(selection.source) ? selection.source : "unspecified"
2019
+ };
2020
+ }
2021
+ var MODEL_IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/@[\]+-]{0,95}$/;
2022
+ function sanitizeModelIdentifier(value) {
2023
+ if (typeof value !== "string") return void 0;
2024
+ const trimmed = value.trim();
2025
+ return MODEL_IDENTIFIER_PATTERN.test(trimmed) ? trimmed : void 0;
2026
+ }
2027
+ function readString2(value) {
2028
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
2029
+ }
2030
+ function readFiniteNumber(value) {
2031
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
2032
+ }
2033
+ function parseModelSelection(raw) {
2034
+ if (!raw || typeof raw !== "object") return void 0;
2035
+ const record = raw;
2036
+ const history = [];
2037
+ if (Array.isArray(record.history)) {
2038
+ for (const entry of record.history) {
2039
+ if (!entry || typeof entry !== "object") continue;
2040
+ const e = entry;
2041
+ const value = readString2(e.value);
2042
+ const at = readFiniteNumber(e.at);
2043
+ const via = e.via === "launch" || e.via === "change_model" || e.via === "observed" ? e.via : void 0;
2044
+ if (value && at !== void 0 && via) history.push({ at, value, via });
2045
+ }
2046
+ }
2047
+ const requested = readString2(record.requested);
2048
+ const launchValue = readString2(record.launchValue);
2049
+ const resolvedDefault = readString2(record.resolvedDefault);
2050
+ const current = readString2(record.current);
2051
+ const observed = readString2(record.observed);
2052
+ const observedAt = readFiniteNumber(record.observedAt);
2053
+ return {
2054
+ source: isModelAxisSource(record.source) ? record.source : "unspecified",
2055
+ ...requested ? { requested } : {},
2056
+ ...launchValue ? { launchValue } : {},
2057
+ ...resolvedDefault ? { resolvedDefault } : {},
2058
+ ...current ? { current } : {},
2059
+ ...observed ? { observed } : {},
2060
+ ...observedAt !== void 0 ? { observedAt } : {},
2061
+ history: history.slice(-MODEL_SELECTION_HISTORY_LIMIT)
2062
+ };
2063
+ }
2064
+ function parseSessionLaunchRecord(raw) {
2065
+ if (!raw || typeof raw !== "object") return void 0;
2066
+ const record = raw;
2067
+ const sessionId = readString2(record.sessionId);
2068
+ const providerType = readString2(record.providerType);
2069
+ const launchedAt = readFiniteNumber(record.launchedAt);
2070
+ const model = parseModelSelection(record.model);
2071
+ const thinkingLevel = parseModelSelection(record.thinkingLevel);
2072
+ if (!sessionId || !providerType || launchedAt === void 0 || !model || !thinkingLevel) return void 0;
2073
+ const providerVersion = readString2(record.providerVersion);
2074
+ const workspace = readString2(record.workspace);
2075
+ const autoApproveModeId = readString2(record.autoApproveModeId);
2076
+ return {
2077
+ sessionId,
2078
+ providerType,
2079
+ ...providerVersion ? { providerVersion } : {},
2080
+ ...record.providerChannel === "stable" || record.providerChannel === "preview" ? { providerChannel: record.providerChannel } : {},
2081
+ launchedBy: isSessionLaunchedBy(record.launchedBy) ? record.launchedBy : "api",
2082
+ launchedAt,
2083
+ ...workspace ? { workspace } : {},
2084
+ model,
2085
+ thinkingLevel,
2086
+ ...autoApproveModeId ? { autoApproveModeId } : {}
2087
+ };
2088
+ }
2089
+
2090
+ // src/turn-ipc.ts
2091
+ var TURN_IPC_PROTOCOL_VERSION = 1;
2092
+ function isFiniteNumber3(value) {
2093
+ return typeof value === "number" && Number.isFinite(value);
2094
+ }
2095
+ function isNonNegativeInt(value) {
2096
+ return Number.isSafeInteger(value) && value >= 0;
2097
+ }
2098
+ function isOptionalId2(value) {
2099
+ return value === void 0 || isEvidenceIdentifier(value);
2100
+ }
2101
+ function hasOnlyKeys2(value, allowed) {
2102
+ for (const key of Object.keys(value)) {
2103
+ if (!allowed.includes(key)) return false;
2104
+ }
2105
+ return true;
2106
+ }
2107
+ var TURN_IPC_ERROR_CODES = ["daemon_required", "turn_ledger_unavailable", "ledger_not_owner"];
2108
+ function makeGuard3(values) {
2109
+ const set = new Set(values);
2110
+ return (value) => typeof value === "string" && set.has(value);
2111
+ }
2112
+ var isTurnIpcErrorCode = makeGuard3(TURN_IPC_ERROR_CODES);
2113
+ function isTurnIpcError(value) {
2114
+ return isRecord(value) && hasOnlyKeys2(value, ["code", "detail"]) && isTurnIpcErrorCode(value.code) && (value.detail === void 0 || typeof value.detail === "string");
2115
+ }
2116
+ var TURN_OBSERVE_VERDICTS = ["applied", "recorded", "rejected"];
2117
+ var isTurnObserveVerdict = makeGuard3(TURN_OBSERVE_VERDICTS);
2118
+ function isTurnObserveRequest(value) {
2119
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "evidence"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isTurnEvidence(value.evidence);
2120
+ }
2121
+ function decodeTurnObserveRequest(value) {
2122
+ return isTurnObserveRequest(value) ? value : null;
2123
+ }
2124
+ function isTurnAttemptRefValue(value) {
2125
+ return isRecord(value) && hasOnlyKeys2(value, ["attemptId", "generation"]) && isEvidenceIdentifier(value.attemptId) && isNonNegativeInt(value.generation);
2126
+ }
2127
+ function isTurnObserveResponse(value) {
2128
+ return isRecord(value) && hasOnlyKeys2(value, ["verdict", "attemptRef", "outcome"]) && isTurnObserveVerdict(value.verdict) && isTurnAttemptRefValue(value.attemptRef) && (value.outcome === void 0 || isTurnOutcomeValue(value.outcome));
2129
+ }
2130
+ var TURN_OUTCOMES_LOCAL = ["completed", "failed", "cancelled"];
2131
+ function isTurnOutcomeValue(value) {
2132
+ return typeof value === "string" && TURN_OUTCOMES_LOCAL.includes(value);
2133
+ }
2134
+ function decodeTurnObserveResponse(value) {
2135
+ return isTurnObserveResponse(value) ? value : null;
2136
+ }
2137
+ var MESH_RECORD_PAYLOAD_KEYS = [
2138
+ // Identifiers
2139
+ "taskId",
2140
+ "deliveryId",
2141
+ "attemptId",
2142
+ "missionId",
2143
+ "checkpointId",
2144
+ "promptId",
2145
+ "providerSessionId",
2146
+ "targetNoteId",
2147
+ // Routing / addressing
2148
+ "nodeId",
2149
+ "sessionId",
2150
+ "providerType",
2151
+ "transport",
2152
+ "attemptedSessionId",
2153
+ "holderSessionId",
2154
+ // Outcome enums
2155
+ "reason",
2156
+ "status",
2157
+ "outcome",
2158
+ "terminalKind",
2159
+ "event",
2160
+ "source",
2161
+ "intentionalStopReason",
2162
+ // Booleans
2163
+ "retryable",
2164
+ "rebound",
2165
+ "forced",
2166
+ "fallback",
2167
+ "membershipRemoved",
2168
+ "requestedForce",
2169
+ "removedByRemoteDaemon",
2170
+ "completedViaReady",
2171
+ "intentional",
2172
+ "weak",
2173
+ // Counters
2174
+ "attempt",
2175
+ "attemptCount",
2176
+ "count"
2177
+ ];
2178
+ var MESH_RECORD_PAYLOAD_KEY_SET = new Set(MESH_RECORD_PAYLOAD_KEYS);
2179
+ var MAX_MESH_RECORD_STRING = 200;
2180
+ function isProjectedScalarsValue(value) {
2181
+ if (!isRecord(value)) return false;
2182
+ for (const v of Object.values(value)) {
2183
+ if (v === null) continue;
2184
+ if (typeof v === "boolean" || typeof v === "number") continue;
2185
+ if (typeof v === "string") {
2186
+ if (v.length > MAX_MESH_RECORD_STRING) return false;
2187
+ continue;
2188
+ }
2189
+ return false;
2190
+ }
2191
+ return true;
2192
+ }
2193
+ function isMeshRecordPayload(value) {
2194
+ if (!isProjectedScalarsValue(value)) return false;
2195
+ for (const key of Object.keys(value)) {
2196
+ if (!MESH_RECORD_PAYLOAD_KEY_SET.has(key)) return false;
2197
+ }
2198
+ return true;
2199
+ }
2200
+ function isMeshRecordRequest(value) {
2201
+ 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);
2202
+ }
2203
+ function decodeMeshRecordRequest(value) {
2204
+ return isMeshRecordRequest(value) ? value : null;
2205
+ }
2206
+ function isMeshRecordResponse(value) {
2207
+ return isRecord(value) && hasOnlyKeys2(value, ["eventId", "seq"]) && isEvidenceIdentifier(value.eventId) && isNonNegativeInt(value.seq);
2208
+ }
2209
+ function decodeMeshRecordResponse(value) {
2210
+ return isMeshRecordResponse(value) ? value : null;
2211
+ }
2212
+ function isTurnCancelRequest(value) {
2213
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "attemptId", "taskId", "reason"])) return false;
2214
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2215
+ const hasAttempt = value.attemptId !== void 0;
2216
+ const hasTask = value.taskId !== void 0;
2217
+ if (hasAttempt === hasTask) return false;
2218
+ if (hasAttempt && !isEvidenceIdentifier(value.attemptId)) return false;
2219
+ if (hasTask && !isEvidenceIdentifier(value.taskId)) return false;
2220
+ return isTurnReason(value.reason);
2221
+ }
2222
+ function decodeTurnCancelRequest(value) {
2223
+ return isTurnCancelRequest(value) ? value : null;
2224
+ }
2225
+ function isTurnCancelResponse(value) {
2226
+ return isRecord(value) && hasOnlyKeys2(value, ["attemptRef", "verdict"]) && isTurnAttemptRefValue(value.attemptRef) && isTurnObserveVerdict(value.verdict);
2227
+ }
2228
+ function decodeTurnCancelResponse(value) {
2229
+ return isTurnCancelResponse(value) ? value : null;
2230
+ }
2231
+ var OPERATOR_STATUS_VALUES = ["completed", "failed"];
2232
+ var isOperatorStatusValue = makeGuard3(OPERATOR_STATUS_VALUES);
2233
+ var OPERATOR_STATUS_REASON_VALUES = ["operator_update", "refine_terminal", "validation_terminal"];
2234
+ var isOperatorStatusReasonValue = makeGuard3(OPERATOR_STATUS_REASON_VALUES);
2235
+ function isOperatorStatusRequest(value) {
2236
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "taskId", "status", "reason"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.taskId) && isOperatorStatusValue(value.status) && isOperatorStatusReasonValue(value.reason);
2237
+ }
2238
+ function decodeOperatorStatusRequest(value) {
2239
+ return isOperatorStatusRequest(value) ? value : null;
2240
+ }
2241
+ function isOperatorStatusResponse(value) {
2242
+ return isRecord(value) && hasOnlyKeys2(value, ["accepted"]) && value.accepted === true;
2243
+ }
2244
+ function decodeOperatorStatusResponse(value) {
2245
+ return isOperatorStatusResponse(value) ? value : null;
2246
+ }
2247
+ function isTurnQueryRequest(value) {
2248
+ 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));
2249
+ }
2250
+ function decodeTurnQueryRequest(value) {
2251
+ return isTurnQueryRequest(value) ? value : null;
2252
+ }
2253
+ var TURN_QUERY_ATTEMPT_ROW_KEYS = [
2254
+ "attemptId",
2255
+ "generation",
2256
+ "meshId",
2257
+ "taskId",
2258
+ "sessionId",
2259
+ "nodeId",
2260
+ "providerType",
2261
+ "state",
2262
+ "terminalOutcome",
2263
+ "terminalReason",
2264
+ "acceptedAt",
2265
+ "terminalAt"
2266
+ ];
2267
+ function isTurnQueryAttemptRow(value) {
2268
+ if (!isRecord(value) || !hasOnlyKeys2(value, TURN_QUERY_ATTEMPT_ROW_KEYS)) return false;
2269
+ if (!isEvidenceIdentifier(value.attemptId) || !isNonNegativeInt(value.generation)) return false;
2270
+ if (!isOptionalId2(value.meshId) || !isOptionalId2(value.taskId)) return false;
2271
+ if (!isEvidenceIdentifier(value.sessionId)) return false;
2272
+ if (!isOptionalId2(value.nodeId) || !isOptionalId2(value.providerType)) return false;
2273
+ if (typeof value.state !== "string") return false;
2274
+ if (value.terminalOutcome !== void 0 && !isTurnOutcomeValue(value.terminalOutcome)) return false;
2275
+ if (value.terminalReason !== void 0 && !isTurnReason(value.terminalReason)) return false;
2276
+ if (!isFiniteNumber3(value.acceptedAt)) return false;
2277
+ if (value.terminalAt !== void 0 && !isFiniteNumber3(value.terminalAt)) return false;
2278
+ return true;
2279
+ }
2280
+ var TURN_QUERY_EVENT_VERDICTS = ["applied", "recorded", "rejected", "forwarded"];
2281
+ var TURN_QUERY_EVENT_ROW_KEYS = ["eventId", "attemptId", "generation", "sessionId", "kind", "source", "verdict", "atMs"];
2282
+ function isTurnQueryEventRow(value) {
2283
+ if (!isRecord(value) || !hasOnlyKeys2(value, TURN_QUERY_EVENT_ROW_KEYS)) return false;
2284
+ if (!isEvidenceIdentifier(value.eventId)) return false;
2285
+ if (!isOptionalId2(value.attemptId)) return false;
2286
+ if (value.generation !== void 0 && !isNonNegativeInt(value.generation)) return false;
2287
+ if (!isEvidenceIdentifier(value.sessionId)) return false;
2288
+ if (typeof value.kind !== "string") return false;
2289
+ if (typeof value.source !== "string") return false;
2290
+ if (!TURN_QUERY_EVENT_VERDICTS.includes(value.verdict)) return false;
2291
+ if (!isFiniteNumber3(value.atMs)) return false;
2292
+ return true;
2293
+ }
2294
+ function isTurnQueryResponse(value) {
2295
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["attempts", "events", "replicationPending"])) return false;
2296
+ if (!Array.isArray(value.attempts) || !value.attempts.every(isTurnQueryAttemptRow)) return false;
2297
+ if (!Array.isArray(value.events) || !value.events.every(isTurnQueryEventRow)) return false;
2298
+ if (value.replicationPending !== void 0 && typeof value.replicationPending !== "boolean") return false;
2299
+ return true;
2300
+ }
2301
+ function decodeTurnQueryResponse(value) {
2302
+ return isTurnQueryResponse(value) ? value : null;
2303
+ }
2304
+ var MESH_INDEX_QUERY_WRITER_SCOPES = ["own", "fleet"];
2305
+ var isMeshIndexQueryWriterScope = makeGuard3(MESH_INDEX_QUERY_WRITER_SCOPES);
2306
+ function isMeshIndexQueryRequest(value) {
2307
+ 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));
2308
+ }
2309
+ function decodeMeshIndexQueryRequest(value) {
2310
+ return isMeshIndexQueryRequest(value) ? value : null;
2311
+ }
2312
+ var MESH_TOPIC_INDEX_ROW_KEYS = [
2313
+ "writer",
2314
+ "seq",
2315
+ "meshId",
2316
+ "eventId",
2317
+ "kind",
2318
+ "ledgerKind",
2319
+ "taskId",
2320
+ "sessionId",
2321
+ "nodeId",
2322
+ "atMs",
2323
+ "payload"
2324
+ ];
2325
+ function isMeshTopicIndexRow(value) {
2326
+ if (!isRecord(value) || !hasOnlyKeys2(value, MESH_TOPIC_INDEX_ROW_KEYS)) return false;
2327
+ if (!isEvidenceIdentifier(value.writer) || !isNonNegativeInt(value.seq)) return false;
2328
+ if (!isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.eventId)) return false;
2329
+ if (typeof value.kind !== "string") return false;
2330
+ if (!isOptionalId2(value.ledgerKind) || !isOptionalId2(value.taskId) || !isOptionalId2(value.sessionId) || !isOptionalId2(value.nodeId)) return false;
2331
+ if (!isFiniteNumber3(value.atMs)) return false;
2332
+ if (!isMeshRecordPayload(value.payload)) return false;
2333
+ return true;
2334
+ }
2335
+ function isMeshIndexQueryResponse(value) {
2336
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["rows", "replicationPending"])) return false;
2337
+ if (!Array.isArray(value.rows) || !value.rows.every(isMeshTopicIndexRow)) return false;
2338
+ if (value.replicationPending !== void 0 && typeof value.replicationPending !== "boolean") return false;
2339
+ return true;
2340
+ }
2341
+ function decodeMeshIndexQueryResponse(value) {
2342
+ return isMeshIndexQueryResponse(value) ? value : null;
2343
+ }
2344
+ var MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
2345
+ var isMeshMissionStatusValue = makeGuard3(MESH_MISSION_STATUSES);
2346
+ var MESH_MISSION_SOURCES = ["magi", "coordinator"];
2347
+ var isMeshMissionSourceValue = makeGuard3(MESH_MISSION_SOURCES);
2348
+ function isStringArray(value) {
2349
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
2350
+ }
2351
+ function isMissionBriefWire(value) {
2352
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["goal", "constraints", "doneCriteria", "handoffNotes", "ownedPaths"])) return false;
2353
+ if (typeof value.goal !== "string" || value.goal.trim().length === 0) return false;
2354
+ for (const k of ["constraints", "doneCriteria", "handoffNotes", "ownedPaths"]) {
2355
+ if (value[k] !== void 0 && !isStringArray(value[k])) return false;
2356
+ }
2357
+ return true;
2358
+ }
2359
+ function isMeshMissionRecordWire(value) {
2360
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["id", "meshId", "title", "goal", "status", "source", "brief"])) return false;
2361
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2362
+ if (typeof value.title !== "string" || typeof value.goal !== "string") return false;
2363
+ if (!isMeshMissionStatusValue(value.status)) return false;
2364
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2365
+ if (value.brief !== void 0 && !isMissionBriefWire(value.brief)) return false;
2366
+ return true;
2367
+ }
2368
+ function isMissionUpsertRequest(value) {
2369
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "id", "title", "goal", "status", "source", "brief"])) return false;
2370
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2371
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2372
+ if (value.id !== void 0 && !isEvidenceIdentifier(value.id)) return false;
2373
+ if (typeof value.title !== "string" || value.title.trim().length === 0) return false;
2374
+ if (value.goal !== void 0 && typeof value.goal !== "string") return false;
2375
+ if (value.status !== void 0 && !isMeshMissionStatusValue(value.status)) return false;
2376
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2377
+ if (value.brief !== void 0 && value.brief !== null && !isMissionBriefWire(value.brief)) return false;
2378
+ return true;
2379
+ }
2380
+ function decodeMissionUpsertRequest(value) {
2381
+ return isMissionUpsertRequest(value) ? value : null;
2382
+ }
2383
+ function isMissionUpsertResponse(value) {
2384
+ return isRecord(value) && hasOnlyKeys2(value, ["mission"]) && isMeshMissionRecordWire(value.mission);
2385
+ }
2386
+ function decodeMissionUpsertResponse(value) {
2387
+ return isMissionUpsertResponse(value) ? value : null;
2388
+ }
2389
+ function isMissionQueryRequest(value) {
2390
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "id"])) return false;
2391
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2392
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2393
+ if (value.id !== void 0 && !isEvidenceIdentifier(value.id)) return false;
2394
+ if (value.statuses !== void 0) {
2395
+ if (!Array.isArray(value.statuses) || value.statuses.length === 0) return false;
2396
+ if (!value.statuses.every(isMeshMissionStatusValue)) return false;
2397
+ }
2398
+ return true;
2399
+ }
2400
+ function decodeMissionQueryRequest(value) {
2401
+ return isMissionQueryRequest(value) ? value : null;
2402
+ }
2403
+ function isMissionQueryResponse(value) {
2404
+ return isRecord(value) && hasOnlyKeys2(value, ["missions"]) && Array.isArray(value.missions) && value.missions.every(isMeshMissionRecordWire);
2405
+ }
2406
+ function decodeMissionQueryResponse(value) {
2407
+ return isMissionQueryResponse(value) ? value : null;
2408
+ }
2409
+ function isMissionListQueryRequest(value) {
2410
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "verbose", "includeMagi", "withStats", "limit", "historyIdLimit"])) return false;
2411
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2412
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2413
+ if (value.statuses !== void 0) {
2414
+ if (!Array.isArray(value.statuses) || value.statuses.length === 0) return false;
2415
+ if (!value.statuses.every(isMeshMissionStatusValue)) return false;
2416
+ }
2417
+ if (value.verbose !== void 0 && typeof value.verbose !== "boolean") return false;
2418
+ if (value.includeMagi !== void 0 && typeof value.includeMagi !== "boolean") return false;
2419
+ if (value.withStats !== void 0 && typeof value.withStats !== "boolean") return false;
2420
+ if (value.limit !== void 0 && !isNonNegativeInt(value.limit)) return false;
2421
+ if (value.historyIdLimit !== void 0 && !isNonNegativeInt(value.historyIdLimit)) return false;
2422
+ return true;
2423
+ }
2424
+ function decodeMissionListQueryRequest(value) {
2425
+ return isMissionListQueryRequest(value) ? value : null;
2426
+ }
2427
+ function isMeshMissionTaskAggregateWire(value) {
2428
+ const keys = ["total", "pending", "assigned", "completed", "failed", "cancelled", "blocked", "lastActivityAt"];
2429
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
2430
+ for (const k of ["total", "pending", "assigned", "completed", "failed", "cancelled", "blocked"]) {
2431
+ if (!isNonNegativeInt(value[k])) return false;
2432
+ }
2433
+ return value.lastActivityAt === null || typeof value.lastActivityAt === "string";
2434
+ }
2435
+ function isMeshMissionStatsWire(value) {
2436
+ const keys = ["missionId", "taskCount", "completed", "failed", "totalDurationMs", "wallClockMs", "retries", "incompleteTaskIds"];
2437
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
2438
+ if (!isEvidenceIdentifier(value.missionId)) return false;
2439
+ for (const k of ["taskCount", "completed", "failed", "totalDurationMs", "retries"]) {
2440
+ if (!isNonNegativeInt(value[k])) return false;
2441
+ }
2442
+ if (value.wallClockMs !== null && !isNonNegativeInt(value.wallClockMs)) return false;
2443
+ if (!Array.isArray(value.incompleteTaskIds) || !value.incompleteTaskIds.every(isEvidenceIdentifier)) return false;
2444
+ return true;
2445
+ }
2446
+ function isMissionListSummaryWire(value) {
2447
+ if (!isRecord(value)) return false;
2448
+ const hasGoal = "goal" in value;
2449
+ const hasPreview = "goalPreview" in value && "goalTruncated" in value;
2450
+ if (hasGoal === hasPreview) return false;
2451
+ const baseKeys = ["id", "meshId", "title", "status", "source", "tasks", "stats", "brief"];
2452
+ const allowed = hasGoal ? [...baseKeys, "goal"] : [...baseKeys, "goalPreview", "goalTruncated"];
2453
+ if (!hasOnlyKeys2(value, allowed)) return false;
2454
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2455
+ if (typeof value.title !== "string") return false;
2456
+ if (!isMeshMissionStatusValue(value.status)) return false;
2457
+ if (value.source !== void 0 && !isMeshMissionSourceValue(value.source)) return false;
2458
+ if (!isMeshMissionTaskAggregateWire(value.tasks)) return false;
2459
+ if (value.stats !== void 0 && !isMeshMissionStatsWire(value.stats)) return false;
2460
+ if (value.brief !== void 0 && !isMissionBriefWire(value.brief)) return false;
2461
+ if (hasGoal && typeof value.goal !== "string") return false;
2462
+ if (hasPreview && (typeof value.goalPreview !== "string" || typeof value.goalTruncated !== "boolean")) return false;
2463
+ return true;
2464
+ }
2465
+ function isMeshMissionHistoryFoldWire(value) {
2466
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["count", "byStatus", "missionIds", "note"])) return false;
2467
+ if (!isNonNegativeInt(value.count)) return false;
2468
+ if (!isRecord(value.byStatus) || !Object.values(value.byStatus).every((n) => isNonNegativeInt(n))) return false;
2469
+ if (!Array.isArray(value.missionIds) || !value.missionIds.every(isEvidenceIdentifier)) return false;
2470
+ return typeof value.note === "string";
2471
+ }
2472
+ function isMissionListQueryResponse(value) {
2473
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["missions", "historyFold", "truncated", "matched", "overflowIds"])) return false;
2474
+ if (!Array.isArray(value.missions) || !value.missions.every(isMissionListSummaryWire)) return false;
2475
+ if (value.historyFold !== null && !isMeshMissionHistoryFoldWire(value.historyFold)) return false;
2476
+ if (typeof value.truncated !== "boolean") return false;
2477
+ if (!isNonNegativeInt(value.matched)) return false;
2478
+ if (value.overflowIds !== void 0 && (!Array.isArray(value.overflowIds) || !value.overflowIds.every(isEvidenceIdentifier))) return false;
2479
+ return true;
2480
+ }
2481
+ function decodeMissionListQueryResponse(value) {
2482
+ return isMissionListQueryResponse(value) ? value : null;
2483
+ }
2484
+ var OPERATING_NOTE_CATEGORIES = ["provider_quirk", "pattern_to_avoid", "recovery_lesson"];
2485
+ var isOperatingNoteCategory = makeGuard3(OPERATING_NOTE_CATEGORIES);
2486
+ function isOptionalShortString(value, max = 512) {
2487
+ return value === void 0 || typeof value === "string" && value.trim().length > 0 && value.length <= max;
2488
+ }
2489
+ function isNoteUpsertRequest(value) {
2490
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "text", "category", "pinned", "expiresAt", "supersedes", "subjectKey", "sourceCoordinator"])) return false;
2491
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2492
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2493
+ if (typeof value.text !== "string" || value.text.trim().length === 0) return false;
2494
+ if (value.category !== void 0 && !isOperatingNoteCategory(value.category)) return false;
2495
+ if (value.pinned !== void 0 && typeof value.pinned !== "boolean") return false;
2496
+ if (value.expiresAt !== void 0 && (typeof value.expiresAt !== "string" || Number.isNaN(Date.parse(value.expiresAt)))) return false;
2497
+ return isOptionalShortString(value.supersedes) && isOptionalShortString(value.subjectKey) && isOptionalShortString(value.sourceCoordinator);
2498
+ }
2499
+ function decodeNoteUpsertRequest(value) {
2500
+ return isNoteUpsertRequest(value) ? value : null;
2501
+ }
2502
+ function isNoteUpsertResponse(value) {
2503
+ return isRecord(value) && hasOnlyKeys2(value, ["noteId", "deduped", "createdAt"]) && isEvidenceIdentifier(value.noteId) && typeof value.deduped === "boolean" && typeof value.createdAt === "string";
2504
+ }
2505
+ function decodeNoteUpsertResponse(value) {
2506
+ return isNoteUpsertResponse(value) ? value : null;
2507
+ }
2508
+ function isNoteForgetRequest(value) {
2509
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "noteId", "text", "reason"])) return false;
2510
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2511
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2512
+ if (value.noteId !== void 0 && !isEvidenceIdentifier(value.noteId)) return false;
2513
+ if (value.text !== void 0 && (typeof value.text !== "string" || value.text.trim().length === 0)) return false;
2514
+ if (value.noteId === void 0 && value.text === void 0) return false;
2515
+ return value.reason === void 0 || typeof value.reason === "string";
2516
+ }
2517
+ function decodeNoteForgetRequest(value) {
2518
+ return isNoteForgetRequest(value) ? value : null;
2519
+ }
2520
+ function isNoteForgetResponse(value) {
2521
+ return isRecord(value) && hasOnlyKeys2(value, ["matched", "tombstoneId"]) && typeof value.matched === "number" && Number.isInteger(value.matched) && value.matched >= 0 && isEvidenceIdentifier(value.tombstoneId);
2522
+ }
2523
+ function decodeNoteForgetResponse(value) {
2524
+ return isNoteForgetResponse(value) ? value : null;
2525
+ }
2526
+ var TOOL_CALLER_ROLES = ["coordinator", "unknown"];
2527
+ var isToolCallerRole = makeGuard3(TOOL_CALLER_ROLES);
2528
+ function isToolCallRecordRequest(value) {
2529
+ 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);
2530
+ }
2531
+ function decodeToolCallRecordRequest(value) {
2532
+ return isToolCallRecordRequest(value) ? value : null;
2533
+ }
2534
+ function isToolCallRecordResponse(value) {
2535
+ return isRecord(value) && hasOnlyKeys2(value, ["rateLimitExceeded", "callsInWindow", "advisory"]) && typeof value.rateLimitExceeded === "boolean" && isNonNegativeInt(value.callsInWindow) && (value.advisory === null || typeof value.advisory === "string");
2536
+ }
2537
+ function decodeToolCallRecordResponse(value) {
2538
+ return isToolCallRecordResponse(value) ? value : null;
2539
+ }
2540
+ function isLedgerQueryRequest(value) {
2541
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "kind", "since", "node", "tail", "includeSummary"])) return false;
2542
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2543
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2544
+ if (value.kind !== void 0 && (!Array.isArray(value.kind) || value.kind.length === 0 || !value.kind.every(isEvidenceIdentifier))) return false;
2545
+ if (value.since !== void 0 && typeof value.since !== "string") return false;
2546
+ if (!isOptionalId2(value.node)) return false;
2547
+ if (value.tail !== void 0 && !isNonNegativeInt(value.tail)) return false;
2548
+ if (value.includeSummary !== void 0 && typeof value.includeSummary !== "boolean") return false;
2549
+ return true;
2550
+ }
2551
+ function decodeLedgerQueryRequest(value) {
2552
+ return isLedgerQueryRequest(value) ? value : null;
2553
+ }
2554
+ var LEDGER_QUERY_ENTRY_KEYS = ["id", "meshId", "timestamp", "kind", "nodeId", "sessionId", "providerType", "taskId", "payload"];
2555
+ function isLedgerQueryEntryWire(value) {
2556
+ if (!isRecord(value) || !hasOnlyKeys2(value, LEDGER_QUERY_ENTRY_KEYS)) return false;
2557
+ if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2558
+ if (typeof value.timestamp !== "string" || typeof value.kind !== "string") return false;
2559
+ if (!isOptionalId2(value.nodeId) || !isOptionalId2(value.sessionId) || !isOptionalId2(value.providerType) || !isOptionalId2(value.taskId)) return false;
2560
+ if (!isRecord(value.payload)) return false;
2561
+ return true;
2562
+ }
2563
+ function isLedgerQuerySummaryWire(value) {
2564
+ const keys = ["meshId", "totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskStalled", "sessionLaunched", "checkpointCreated", "lastActivityAt", "recentFailures"];
2565
+ if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
2566
+ if (!isEvidenceIdentifier(value.meshId)) return false;
2567
+ for (const k of ["totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskStalled", "sessionLaunched", "checkpointCreated", "recentFailures"]) {
2568
+ if (!isNonNegativeInt(value[k])) return false;
2569
+ }
2570
+ if (value.lastActivityAt !== null && typeof value.lastActivityAt !== "string") return false;
2571
+ return true;
2572
+ }
2573
+ function isLedgerQueryResponse(value) {
2574
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["entries", "summary"])) return false;
2575
+ if (!Array.isArray(value.entries) || !value.entries.every(isLedgerQueryEntryWire)) return false;
2576
+ if (value.summary !== void 0 && !isLedgerQuerySummaryWire(value.summary)) return false;
2577
+ return true;
2578
+ }
2579
+ function decodeLedgerQueryResponse(value) {
2580
+ return isLedgerQueryResponse(value) ? value : null;
2581
+ }
2582
+ function isRecordArray(value) {
2583
+ return Array.isArray(value) && value.every(isRecord);
2584
+ }
2585
+ function isOptionalRecord(value) {
2586
+ return value === void 0 || isRecord(value);
2587
+ }
2588
+ function isOptionalBoolean(value) {
2589
+ return value === void 0 || typeof value === "boolean";
2590
+ }
2591
+ function isOptionalString(value) {
2592
+ return value === void 0 || typeof value === "string";
2593
+ }
2594
+ function isQueueEntryWire(value) {
2595
+ return isRecord(value) && isEvidenceIdentifier(value.id) && typeof value.status === "string";
2596
+ }
2597
+ function isRecordLocalRequest(value) {
2598
+ 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);
2599
+ }
2600
+ function decodeRecordLocalRequest(value) {
2601
+ return isRecordLocalRequest(value) ? value : null;
2602
+ }
2603
+ function isRecordLocalResponse(value) {
2604
+ return isRecord(value) && hasOnlyKeys2(value, ["eventId", "timestamp", "storedLocally", "published"]) && isEvidenceIdentifier(value.eventId) && typeof value.timestamp === "string" && typeof value.storedLocally === "boolean" && typeof value.published === "boolean";
2605
+ }
2606
+ function decodeRecordLocalResponse(value) {
2607
+ return isRecordLocalResponse(value) ? value : null;
2608
+ }
2609
+ function isQueueQueryRequest(value) {
2610
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "taskId", "view"])) return false;
2611
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2612
+ if (value.statuses !== void 0 && (!Array.isArray(value.statuses) || !value.statuses.every(isEvidenceIdentifier))) return false;
2613
+ return isOptionalId2(value.taskId) && isOptionalBoolean(value.view);
2614
+ }
2615
+ function decodeQueueQueryRequest(value) {
2616
+ return isQueueQueryRequest(value) ? value : null;
2617
+ }
2618
+ function isQueueQueryResponse(value) {
2619
+ return isRecord(value) && hasOnlyKeys2(value, ["entries"]) && Array.isArray(value.entries) && value.entries.every(isQueueEntryWire);
2620
+ }
2621
+ function decodeQueueQueryResponse(value) {
2622
+ return isQueueQueryResponse(value) ? value : null;
2623
+ }
2624
+ function isQueueEnqueueRequest(value) {
2625
+ 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);
2626
+ }
2627
+ function decodeQueueEnqueueRequest(value) {
2628
+ return isQueueEnqueueRequest(value) ? value : null;
2629
+ }
2630
+ function isQueueEnqueueResponse(value) {
2631
+ return isRecord(value) && hasOnlyKeys2(value, ["entry"]) && isQueueEntryWire(value.entry);
2632
+ }
2633
+ function decodeQueueEnqueueResponse(value) {
2634
+ return isQueueEnqueueResponse(value) ? value : null;
2635
+ }
2636
+ function isQueueEnqueueGraphRequest(value) {
2637
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "mode", "specs", "plan", "audit"])) return false;
2638
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2639
+ if (value.mode === "compat") return isRecordArray(value.specs) && value.plan === void 0 && isOptionalRecord(value.audit);
2640
+ if (value.mode === "graph") return isRecord(value.plan) && value.specs === void 0 && isOptionalRecord(value.audit);
2641
+ return false;
2642
+ }
2643
+ function decodeQueueEnqueueGraphRequest(value) {
2644
+ return isQueueEnqueueGraphRequest(value) ? value : null;
2645
+ }
2646
+ function isQueueEnqueueGraphResponse(value) {
2647
+ if (!isRecord(value)) return false;
2648
+ if (value.ok === true) {
2649
+ return hasOnlyKeys2(value, ["ok", "tasks", "graph"]) && Array.isArray(value.tasks) && value.tasks.every(isQueueEntryWire) && isOptionalRecord(value.graph);
2650
+ }
2651
+ if (value.ok === false) {
2652
+ return hasOnlyKeys2(value, ["ok", "refusalCode", "message", "extra"]) && typeof value.message === "string" && isOptionalString(value.refusalCode) && isOptionalRecord(value.extra);
2653
+ }
2654
+ return false;
2655
+ }
2656
+ function decodeQueueEnqueueGraphResponse(value) {
2657
+ return isQueueEnqueueGraphResponse(value) ? value : null;
2658
+ }
2659
+ function isQueueCancelRequest(value) {
2660
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "reason"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.taskId) && isOptionalString(value.reason);
2661
+ }
2662
+ function decodeQueueCancelRequest(value) {
2663
+ return isQueueCancelRequest(value) ? value : null;
2664
+ }
2665
+ function isQueueCancelResponse(value) {
2666
+ return isRecord(value) && hasOnlyKeys2(value, ["task", "before"]) && (value.task === null || isQueueEntryWire(value.task)) && (value.before === null || isQueueEntryWire(value.before));
2667
+ }
2668
+ function decodeQueueCancelResponse(value) {
2669
+ return isQueueCancelResponse(value) ? value : null;
2670
+ }
2671
+ function isQueueRequeueRequest(value) {
2672
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "taskId", "options"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isEvidenceIdentifier(value.taskId) && isOptionalRecord(value.options);
2673
+ }
2674
+ function decodeQueueRequeueRequest(value) {
2675
+ return isQueueRequeueRequest(value) ? value : null;
2676
+ }
2677
+ function isQueueRequeueResponse(value) {
2678
+ return isRecord(value) && hasOnlyKeys2(value, ["task"]) && (value.task === null || isQueueEntryWire(value.task));
2679
+ }
2680
+ function decodeQueueRequeueResponse(value) {
2681
+ return isQueueRequeueResponse(value) ? value : null;
2682
+ }
2683
+ function isDirectDispatchRecordRequest(value) {
2684
+ 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);
2685
+ }
2686
+ function decodeDirectDispatchRecordRequest(value) {
2687
+ return isDirectDispatchRecordRequest(value) ? value : null;
2688
+ }
2689
+ function isDirectDispatchRecordResponse(value) {
2690
+ return isRecord(value) && hasOnlyKeys2(value, ["taskRecorded", "decisionRecorded"]) && typeof value.taskRecorded === "boolean" && typeof value.decisionRecorded === "boolean";
2691
+ }
2692
+ function decodeDirectDispatchRecordResponse(value) {
2693
+ return isDirectDispatchRecordResponse(value) ? value : null;
2694
+ }
2695
+ var GRAPH_AUDIT_EVENTS = ["gate_claimed", "gate_released", "gate_abandoned", "node_patched"];
2696
+ var isGraphAuditEvent = makeGuard3(GRAPH_AUDIT_EVENTS);
2697
+ function isGraphAuditRecordRequest(value) {
2698
+ return isRecord(value) && hasOnlyKeys2(value, ["v", "meshId", "event", "fields"]) && value.v === TURN_IPC_PROTOCOL_VERSION && isEvidenceIdentifier(value.meshId) && isGraphAuditEvent(value.event) && isRecord(value.fields);
2699
+ }
2700
+ function decodeGraphAuditRecordRequest(value) {
2701
+ return isGraphAuditRecordRequest(value) ? value : null;
2702
+ }
2703
+ function isGraphAuditRecordResponse(value) {
2704
+ return isRecord(value) && hasOnlyKeys2(value, ["recorded"]) && typeof value.recorded === "boolean";
2705
+ }
2706
+ function decodeGraphAuditRecordResponse(value) {
2707
+ return isGraphAuditRecordResponse(value) ? value : null;
2708
+ }
2709
+ function isActiveWorkQueryRequest(value) {
2710
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "nodes", "queue", "recordTail", "includeTerminalDirect", "compute", "includeInputs", "includeSummary", "includeSchedulingRuntime", "mesh"])) return false;
2711
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2712
+ if (value.nodes !== void 0 && !isRecordArray(value.nodes)) return false;
2713
+ if (value.queue !== void 0 && !isRecordArray(value.queue)) return false;
2714
+ if (value.recordTail !== void 0 && !isNonNegativeInt(value.recordTail)) return false;
2715
+ if (value.includeSchedulingRuntime === true && !isRecord(value.mesh)) return false;
2716
+ return isOptionalBoolean(value.includeTerminalDirect) && isOptionalBoolean(value.compute) && isOptionalBoolean(value.includeInputs) && isOptionalBoolean(value.includeSummary) && isOptionalBoolean(value.includeSchedulingRuntime) && isOptionalRecord(value.mesh);
2717
+ }
2718
+ function decodeActiveWorkQueryRequest(value) {
2719
+ return isActiveWorkQueryRequest(value) ? value : null;
2720
+ }
2721
+ function isActiveWorkQueryResponse(value) {
2722
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["activeWork", "records", "directDispatches", "summary", "schedulingRuntime"])) return false;
2723
+ if (value.records !== void 0 && !isRecordArray(value.records)) return false;
2724
+ if (value.directDispatches !== void 0 && !isRecordArray(value.directDispatches)) return false;
2725
+ return isOptionalRecord(value.activeWork) && isOptionalRecord(value.summary) && isOptionalRecord(value.schedulingRuntime);
2726
+ }
2727
+ function decodeActiveWorkQueryResponse(value) {
2728
+ return isActiveWorkQueryResponse(value) ? value : null;
2729
+ }
2730
+ function isRecoveryContextQueryRequest(value) {
2731
+ 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);
2732
+ }
2733
+ function decodeRecoveryContextQueryRequest(value) {
2734
+ return isRecoveryContextQueryRequest(value) ? value : null;
2735
+ }
2736
+ function isRecoveryContextQueryResponse(value) {
2737
+ return isRecord(value) && hasOnlyKeys2(value, ["context"]) && isRecord(value.context) && typeof value.context.consecutiveNodeFailures === "number";
2738
+ }
2739
+ function decodeRecoveryContextQueryResponse(value) {
2740
+ return isRecoveryContextQueryResponse(value) ? value : null;
2741
+ }
2742
+ function isGraphGateClaimRequest(value) {
2743
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "coordinatorSessionId", "leaseSeconds", "extendDeadlineSeconds", "probeConvergenceEvidence"])) return false;
2744
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId) || !isEvidenceIdentifier(value.coordinatorSessionId)) return false;
2745
+ if (value.leaseSeconds !== void 0 && !isFiniteNumber3(value.leaseSeconds)) return false;
2746
+ if (value.extendDeadlineSeconds !== void 0 && !isFiniteNumber3(value.extendDeadlineSeconds)) return false;
2747
+ return isOptionalBoolean(value.probeConvergenceEvidence);
2748
+ }
2749
+ function decodeGraphGateClaimRequest(value) {
2750
+ return isGraphGateClaimRequest(value) ? value : null;
2751
+ }
2752
+ function isGraphGateClaimResponse(value) {
2753
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["claimed", "reason", "gate", "leaseGeneration", "fencingToken", "leaseExpiresAt", "deadlineAt", "ambiguousExternalOutcome", "previousLeaseOwnerSessionId", "convergenceEvidence"])) return false;
2754
+ if (typeof value.claimed !== "boolean") return false;
2755
+ return isOptionalRecord(value.gate) && isOptionalRecord(value.convergenceEvidence) && isOptionalBoolean(value.ambiguousExternalOutcome);
2756
+ }
2757
+ function decodeGraphGateClaimResponse(value) {
2758
+ return isGraphGateClaimResponse(value) ? value : null;
2759
+ }
2760
+ function isGraphGateReleaseRequest(value) {
2761
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "fencingToken", "leaseGeneration", "idempotencyKey", "outcome", "result", "evidence", "patches"])) return false;
2762
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId)) return false;
2763
+ if (typeof value.fencingToken !== "string" || !value.fencingToken) return false;
2764
+ if (!isFiniteNumber3(value.leaseGeneration)) return false;
2765
+ if (typeof value.idempotencyKey !== "string" || !value.idempotencyKey) return false;
2766
+ if (typeof value.outcome !== "string" || !value.outcome) return false;
2767
+ if (value.patches !== void 0) {
2768
+ if (!Array.isArray(value.patches)) return false;
2769
+ for (const p of value.patches) {
2770
+ if (!isRecord(p) || typeof p.node !== "string" || !p.node || !isRecord(p.baseSpecPatch)) return false;
2771
+ }
2772
+ }
2773
+ return true;
2774
+ }
2775
+ function decodeGraphGateReleaseRequest(value) {
2776
+ return isGraphGateReleaseRequest(value) ? value : null;
2777
+ }
2778
+ function isGraphGateReleaseResponse(value) {
2779
+ if (!isRecord(value)) return false;
2780
+ if (value.released === true) {
2781
+ if (!hasOnlyKeys2(value, ["released", "duplicate", "gate", "materializedNodeIds", "downstreamNodeCount", "graphCompleted"])) return false;
2782
+ if (typeof value.duplicate !== "boolean") return false;
2783
+ if (!Array.isArray(value.materializedNodeIds) || !value.materializedNodeIds.every((n) => typeof n === "string")) return false;
2784
+ if (value.downstreamNodeCount !== void 0 && !isNonNegativeInt(value.downstreamNodeCount)) return false;
2785
+ return isOptionalRecord(value.gate) && isOptionalBoolean(value.graphCompleted);
2786
+ }
2787
+ if (value.released === false) {
2788
+ return hasOnlyKeys2(value, ["released", "refusalCode", "message"]) && typeof value.message === "string" && isOptionalString(value.refusalCode);
2789
+ }
2790
+ return false;
2791
+ }
2792
+ function decodeGraphGateReleaseResponse(value) {
2793
+ return isGraphGateReleaseResponse(value) ? value : null;
2794
+ }
2795
+ function isGraphGateAbandonRequest(value) {
2796
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "gateId", "reason", "coordinatorSessionId", "force"])) return false;
2797
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.gateId)) return false;
2798
+ if (typeof value.reason !== "string" || !value.reason) return false;
2799
+ if (value.coordinatorSessionId !== void 0 && !isEvidenceIdentifier(value.coordinatorSessionId)) return false;
2800
+ return isOptionalBoolean(value.force);
2801
+ }
2802
+ function decodeGraphGateAbandonRequest(value) {
2803
+ return isGraphGateAbandonRequest(value) ? value : null;
2804
+ }
2805
+ function isGraphGateAbandonResponse(value) {
2806
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["abandoned", "reason", "gate", "cancelledNodeIds", "cancelledTaskIds", "graphStatus"])) return false;
2807
+ if (typeof value.abandoned !== "boolean") return false;
2808
+ if (!Array.isArray(value.cancelledNodeIds) || !value.cancelledNodeIds.every((n) => typeof n === "string")) return false;
2809
+ if (!Array.isArray(value.cancelledTaskIds) || !value.cancelledTaskIds.every((n) => typeof n === "string")) return false;
2810
+ return isOptionalRecord(value.gate);
2811
+ }
2812
+ function decodeGraphGateAbandonResponse(value) {
2813
+ return isGraphGateAbandonResponse(value) ? value : null;
2814
+ }
2815
+ function isGraphNodePatchRequest(value) {
2816
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "node", "graphId", "baseSpecPatch"])) return false;
2817
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2818
+ if (typeof value.node !== "string" || !value.node) return false;
2819
+ if (value.graphId !== void 0 && !isEvidenceIdentifier(value.graphId)) return false;
2820
+ return isRecord(value.baseSpecPatch) && Object.keys(value.baseSpecPatch).length > 0;
2821
+ }
2822
+ function decodeGraphNodePatchRequest(value) {
2823
+ return isGraphNodePatchRequest(value) ? value : null;
2824
+ }
2825
+ function isGraphNodePatchResponse(value) {
2826
+ if (!isRecord(value)) return false;
2827
+ if (value.patched === true) {
2828
+ if (!hasOnlyKeys2(value, ["patched", "graphId", "nodeId", "ref", "queueTaskId", "materializationVersion", "state", "outcomeKind", "skippedReason", "blockedReason"])) return false;
2829
+ if (!isEvidenceIdentifier(value.graphId) || !isEvidenceIdentifier(value.nodeId)) return false;
2830
+ if (!isNonNegativeInt(value.materializationVersion)) return false;
2831
+ return typeof value.state === "string" && typeof value.outcomeKind === "string";
2832
+ }
2833
+ if (value.patched === false) {
2834
+ return hasOnlyKeys2(value, ["patched", "refusalCode", "message"]) && typeof value.message === "string" && isOptionalString(value.refusalCode);
2835
+ }
2836
+ return false;
2837
+ }
2838
+ function decodeGraphNodePatchResponse(value) {
2839
+ return isGraphNodePatchResponse(value) ? value : null;
2840
+ }
2841
+ function isGraphViewQueryRequest(value) {
2842
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "graphId", "batchId", "activeOnly", "limit", "probeGateEvidence"])) return false;
2843
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2844
+ if (value.graphId !== void 0 && !isEvidenceIdentifier(value.graphId)) return false;
2845
+ if (value.batchId !== void 0 && !isEvidenceIdentifier(value.batchId)) return false;
2846
+ if (value.limit !== void 0 && !isNonNegativeInt(value.limit)) return false;
2847
+ return isOptionalBoolean(value.activeOnly) && isOptionalBoolean(value.probeGateEvidence);
2848
+ }
2849
+ function decodeGraphViewQueryRequest(value) {
2850
+ return isGraphViewQueryRequest(value) ? value : null;
2851
+ }
2852
+ function isGraphViewQueryResponse(value) {
2853
+ return isRecord(value) && hasOnlyKeys2(value, ["graphs"]) && isRecordArray(value.graphs);
2854
+ }
2855
+ function decodeGraphViewQueryResponse(value) {
2856
+ return isGraphViewQueryResponse(value) ? value : null;
2857
+ }
2858
+ function isTaskStatsQueryRequest(value) {
2859
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "taskIds", "missionId", "tail", "rollup"])) return false;
2860
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2861
+ if (value.taskIds !== void 0) {
2862
+ if (!Array.isArray(value.taskIds) || value.taskIds.length === 0 || !value.taskIds.every(isEvidenceIdentifier)) return false;
2863
+ }
2864
+ if (value.missionId !== void 0 && !isEvidenceIdentifier(value.missionId)) return false;
2865
+ if (value.tail !== void 0 && !isNonNegativeInt(value.tail)) return false;
2866
+ if (value.rollup === true && value.missionId === void 0) return false;
2867
+ return isOptionalBoolean(value.rollup);
2868
+ }
2869
+ function decodeTaskStatsQueryRequest(value) {
2870
+ return isTaskStatsQueryRequest(value) ? value : null;
2871
+ }
2872
+ function isTaskStatsQueryResponse(value) {
2873
+ return isRecord(value) && hasOnlyKeys2(value, ["tasks", "mission"]) && isRecordArray(value.tasks) && isOptionalRecord(value.mission);
2874
+ }
2875
+ function decodeTaskStatsQueryResponse(value) {
2876
+ return isTaskStatsQueryResponse(value) ? value : null;
2877
+ }
2878
+ function isPruneStaleDirectRequest(value) {
2879
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "execute", "includeTerminal", "source"])) return false;
2880
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId)) return false;
2881
+ if (value.source !== void 0 && typeof value.source !== "string") return false;
2882
+ return isOptionalBoolean(value.execute) && isOptionalBoolean(value.includeTerminal);
2883
+ }
2884
+ function decodePruneStaleDirectRequest(value) {
2885
+ return isPruneStaleDirectRequest(value) ? value : null;
2886
+ }
2887
+ function isPruneStaleDirectResponse(value) {
2888
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["mode", "includeTerminal", "candidateCount", "prunable", "prunedCount", "preservedUnacknowledged", "preservedLedgerOnly", "preservedNotOrphan"])) return false;
2889
+ if (value.mode !== "execute" && value.mode !== "dry_run") return false;
2890
+ if (typeof value.includeTerminal !== "boolean") return false;
2891
+ if (!isNonNegativeInt(value.candidateCount) || !isNonNegativeInt(value.prunedCount)) return false;
2892
+ return isRecordArray(value.prunable) && isRecordArray(value.preservedUnacknowledged) && isRecordArray(value.preservedLedgerOnly) && isRecordArray(value.preservedNotOrphan);
2893
+ }
2894
+ function decodePruneStaleDirectResponse(value) {
2895
+ return isPruneStaleDirectResponse(value) ? value : null;
2896
+ }
2897
+ function isOrphanedPinnedTaskWire(value) {
2898
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["taskId", "title", "targetSessionId", "targetNodeId", "missionId"])) return false;
2899
+ if (!isEvidenceIdentifier(value.taskId) || !isEvidenceIdentifier(value.targetSessionId)) return false;
2900
+ if (typeof value.title !== "string") return false;
2901
+ if (value.targetNodeId !== void 0 && !isEvidenceIdentifier(value.targetNodeId)) return false;
2902
+ return value.missionId === void 0 || isEvidenceIdentifier(value.missionId);
2903
+ }
2904
+ function isOrphanedPinNotifyRequest(value) {
2905
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "stoppedSessionId", "excludeTaskId", "cause", "nodeId", "coordinatorSessionId"])) return false;
2906
+ if (value.v !== TURN_IPC_PROTOCOL_VERSION || !isEvidenceIdentifier(value.meshId) || !isEvidenceIdentifier(value.stoppedSessionId)) return false;
2907
+ if (value.excludeTaskId !== void 0 && !isEvidenceIdentifier(value.excludeTaskId)) return false;
2908
+ if (value.cause !== void 0 && typeof value.cause !== "string") return false;
2909
+ if (value.nodeId !== void 0 && !isEvidenceIdentifier(value.nodeId)) return false;
2910
+ return value.coordinatorSessionId === void 0 || isEvidenceIdentifier(value.coordinatorSessionId);
2911
+ }
2912
+ function decodeOrphanedPinNotifyRequest(value) {
2913
+ return isOrphanedPinNotifyRequest(value) ? value : null;
2914
+ }
2915
+ function isOrphanedPinNotifyResponse(value) {
2916
+ return isRecord(value) && hasOnlyKeys2(value, ["orphans"]) && Array.isArray(value.orphans) && value.orphans.every(isOrphanedPinnedTaskWire);
2917
+ }
2918
+ function decodeOrphanedPinNotifyResponse(value) {
2919
+ return isOrphanedPinNotifyResponse(value) ? value : null;
2920
+ }
2921
+ var TURN_IPC_COMMANDS = [
2922
+ "turn_observe",
2923
+ "mesh_record",
2924
+ "turn_cancel",
2925
+ "operator_status",
2926
+ "turn_query",
2927
+ "mesh_index_query",
2928
+ "mission_upsert",
2929
+ "mission_query",
2930
+ "note_upsert",
2931
+ "note_forget",
2932
+ // C-W9b additions (2026-09-24 14:00 stamp "C-W9"):
2933
+ "tool_call_record",
2934
+ "ledger_query",
2935
+ "mission_list_query",
2936
+ // C-W9a additions (the event ledger retired; the queue behind IPC):
2937
+ "record_local",
2938
+ "queue_query",
2939
+ "queue_enqueue",
2940
+ "queue_enqueue_graph",
2941
+ "queue_cancel",
2942
+ "queue_requeue",
2943
+ "direct_dispatch_record",
2944
+ "graph_audit_record",
2945
+ "active_work_query",
2946
+ "recovery_context_query",
2947
+ // C-W9c additions (2026-09-24 19:00 stamp — the last mcp-server in-process
2948
+ // daemon-core paths: graph gates/plan/patch, mission reads (MAGI), task/
2949
+ // mission stats, orphaned-pin helpers, one prune audit):
2950
+ "graph_gate_claim",
2951
+ "graph_gate_release",
2952
+ "graph_gate_abandon",
2953
+ "graph_node_patch",
2954
+ "graph_view_query",
2955
+ "task_stats_query",
2956
+ "prune_stale_direct",
2957
+ "orphaned_pin_notify"
2958
+ ];
2959
+ var isTurnIpcCommand = makeGuard3(TURN_IPC_COMMANDS);
2960
+
2961
+ // src/path-ownership.ts
2962
+ var MAX_OWNED_PATHS = 64;
2963
+ function toPosix(raw) {
2964
+ return raw.replace(/\\/g, "/");
2965
+ }
2966
+ function normalizeOne(raw, rejected) {
2967
+ if (typeof raw !== "string") {
2968
+ rejected.push({ input: String(raw), reason: "not_a_string" });
2969
+ return null;
2970
+ }
2971
+ const trimmed = raw.trim();
2972
+ if (!trimmed) {
2973
+ rejected.push({ input: raw, reason: "empty" });
2974
+ return null;
2975
+ }
2976
+ let posix = toPosix(trimmed);
2977
+ if (posix.startsWith("/") || /^[a-zA-Z]:\//.test(posix) || posix.startsWith("~")) {
2978
+ rejected.push({ input: raw, reason: "absolute_path" });
2979
+ return null;
2980
+ }
2981
+ posix = posix.replace(/^\.\/+/, "");
2982
+ const segments = posix.split("/").filter(Boolean);
2983
+ if (segments.some((seg) => seg === "..")) {
2984
+ rejected.push({ input: raw, reason: "parent_traversal" });
2985
+ return null;
2986
+ }
2987
+ if (segments.length === 0) {
2988
+ rejected.push({ input: raw, reason: "empty" });
2989
+ return null;
2990
+ }
2991
+ let subtree = false;
2992
+ if (segments[segments.length - 1] === "**") {
2993
+ subtree = true;
2994
+ segments.pop();
2995
+ if (segments.length === 0) {
2996
+ }
2997
+ }
2998
+ if (segments.some((seg) => seg.includes("*") || seg.includes("?"))) {
2999
+ rejected.push({ input: raw, reason: "unsupported_glob" });
3000
+ return null;
3001
+ }
3002
+ return { path: segments.join("/"), subtree };
3003
+ }
3004
+ function normalizeOwnedPaths(input) {
3005
+ const rejected = [];
3006
+ if (input === void 0 || input === null) {
3007
+ return { declaration: { paths: [] }, rejected };
3008
+ }
3009
+ if (!Array.isArray(input)) {
3010
+ return { declaration: { paths: [] }, rejected: [{ input: String(input), reason: "not_an_array" }] };
3011
+ }
3012
+ const byPath = /* @__PURE__ */ new Map();
3013
+ for (const raw of input) {
3014
+ const entry = normalizeOne(raw, rejected);
3015
+ if (!entry) continue;
3016
+ const existing = byPath.get(entry.path);
3017
+ if (!existing) {
3018
+ byPath.set(entry.path, entry);
3019
+ } else if (entry.subtree && !existing.subtree) {
3020
+ byPath.set(entry.path, entry);
3021
+ }
3022
+ }
3023
+ const all = [...byPath.values()];
3024
+ const kept = all.slice(0, MAX_OWNED_PATHS);
3025
+ for (const dropped of all.slice(MAX_OWNED_PATHS)) {
3026
+ rejected.push({ input: dropped.path, reason: "over_cap" });
3027
+ }
3028
+ return { declaration: { paths: kept }, rejected };
3029
+ }
3030
+ function entryContains(base, path) {
3031
+ if (path === base.path) return true;
3032
+ if (base.subtree && (path === base.path || path.startsWith(`${base.path}/`))) return true;
3033
+ return false;
3034
+ }
3035
+ function entriesOverlap(a, b) {
3036
+ if (a.path === b.path) return true;
3037
+ if (a.subtree && (b.path === a.path || b.path.startsWith(`${a.path}/`))) return true;
3038
+ if (b.subtree && (a.path === b.path || a.path.startsWith(`${b.path}/`))) return true;
3039
+ return false;
3040
+ }
3041
+ function pathsOverlap(a, b) {
3042
+ if (a.paths.length === 0 || b.paths.length === 0) return false;
3043
+ for (const pa of a.paths) {
3044
+ for (const pb of b.paths) {
3045
+ if (entriesOverlap(pa, pb)) return true;
3046
+ }
3047
+ }
3048
+ return false;
3049
+ }
3050
+ function findOwnershipConflicts(candidate, inFlight) {
3051
+ if (candidate.paths.length === 0) return [];
3052
+ const conflicts = [];
3053
+ for (const other of inFlight) {
3054
+ if (other.paths.paths.length === 0) continue;
3055
+ const overlappingPaths = [];
3056
+ for (const pa of candidate.paths) {
3057
+ for (const pb of other.paths.paths) {
3058
+ if (entriesOverlap(pa, pb)) {
3059
+ const narrower = pa.path.length >= pb.path.length ? pa.path : pb.path;
3060
+ if (!overlappingPaths.includes(narrower)) overlappingPaths.push(narrower);
3061
+ }
3062
+ }
3063
+ }
3064
+ if (overlappingPaths.length > 0) {
3065
+ conflicts.push({ taskId: other.taskId, overlappingPaths });
3066
+ }
3067
+ }
3068
+ return conflicts;
3069
+ }
3070
+ function touchedFilesOutsideOwnership(touched, owned) {
3071
+ const undeclaredTouched = [];
3072
+ const usedDeclarations = /* @__PURE__ */ new Set();
3073
+ for (const raw of touched ?? []) {
3074
+ const rejectedSink = [];
3075
+ const entry = normalizeOne(raw, rejectedSink);
3076
+ if (!entry) {
3077
+ undeclaredTouched.push(raw);
3078
+ continue;
3079
+ }
3080
+ const matches = owned.paths.filter((base) => entryContains(base, entry.path));
3081
+ if (matches.length === 0) {
3082
+ undeclaredTouched.push(entry.path);
3083
+ } else {
3084
+ for (const m of matches) usedDeclarations.add(m.path);
3085
+ }
3086
+ }
3087
+ const unusedDeclarations = owned.paths.map((p) => p.path).filter((p) => !usedDeclarations.has(p));
3088
+ return { undeclaredTouched, unusedDeclarations };
3089
+ }
995
3090
  export {
3091
+ CANCEL_REASONS,
996
3092
  CANONICAL_MESH_TOOL_COUNT,
997
3093
  CANONICAL_MESH_TOOL_NAMES,
998
3094
  CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX,
999
3095
  CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX,
1000
3096
  CLI_SLOT_RECIPES,
3097
+ COMMIT_STRENGTHS,
3098
+ CONSUME_PROFILES,
3099
+ COORDINATOR_ACK_OUTCOMES,
3100
+ DAEMON_P2P_SIGNAL_TYPES,
3101
+ DAEMON_STATUS_EVENT_NAMES,
3102
+ DAEMON_TO_DASHBOARD_P2P_TYPES,
3103
+ DAEMON_TO_SERVER_TYPES,
1001
3104
  DAEMON_TO_SERVER_WS_MSGS,
3105
+ DASHBOARD_P2P_MESSAGE_KINDS,
3106
+ DASHBOARD_P2P_SIGNAL_TYPES,
3107
+ DASHBOARD_STATUS_EVENT_NAMES,
3108
+ DASHBOARD_TO_DAEMON_P2P_TYPES,
3109
+ DASHBOARD_TO_USER_SESSION_TYPES,
1002
3110
  DEFAULT_DIFFICULTY_BRAINS,
3111
+ DELIVERY_OUTCOMES,
3112
+ DELIVERY_VIAS,
3113
+ DISPATCH_FAILURE_REASONS,
3114
+ EVIDENCE_ENVELOPE_FIELD_SPECS,
3115
+ EVIDENCE_SOURCE_IDS,
3116
+ GRAPH_AUDIT_EVENTS,
3117
+ HOLD_REASONS,
3118
+ LIVENESS_RESULTS,
1003
3119
  MAGI_RAW_ANSWER_CAP,
3120
+ MAX_MESH_RECORD_STRING,
3121
+ MAX_OWNED_PATHS,
1004
3122
  MESH_CHUNK_KIND,
1005
3123
  MESH_CHUNK_PAYLOAD_CHARS,
1006
3124
  MESH_CHUNK_TTL_MS,
3125
+ MESH_DELIVERY_MODES,
3126
+ MESH_INDEX_QUERY_WRITER_SCOPES,
1007
3127
  MESH_MAX_CHUNKS,
1008
3128
  MESH_MAX_INLINE_FRAME_BYTES,
1009
3129
  MESH_MAX_REASSEMBLED_BYTES,
3130
+ MESH_MISSION_SOURCES,
3131
+ MESH_MISSION_STATUSES,
3132
+ MESH_P2P_SIGNAL_TYPES,
3133
+ MESH_RECORD_PAYLOAD_KEYS,
3134
+ MESH_SESSION_CLEANUP_MODES,
1010
3135
  MESH_TASK_DIFFICULTIES,
3136
+ MESH_TASK_MODES,
3137
+ MESH_TASK_PRIORITIES,
3138
+ MESH_TASK_STATUSES,
3139
+ MESH_TERMINAL_TASK_STATUSES,
3140
+ MESH_THINKING_LEVELS,
3141
+ MESH_TOPIC_ENTRY_KINDS,
3142
+ MESH_TOPIC_PROTOCOL_VERSION,
3143
+ MISSION_BRIEF_RENDER_MAX_CHARS,
3144
+ MODEL_AXIS_SOURCES,
3145
+ MODEL_SELECTION_HISTORY_LIMIT,
1011
3146
  MeshChunkAssembler,
3147
+ NATIVE_TURN_OUTCOMES,
3148
+ NOTIFY_KINDS,
3149
+ NO_PROGRESS_OBSERVED_STATUSES,
3150
+ NPM_UPDATE_TAGS,
3151
+ OPERATING_NOTE_CATEGORIES,
3152
+ OPERATOR_STATUSES,
3153
+ OPERATOR_STATUS_REASONS,
3154
+ OPERATOR_STATUS_REASON_VALUES,
3155
+ OPERATOR_STATUS_VALUES,
3156
+ OUTBOUND_MESSAGE_ORIGINS,
3157
+ P2P_SIGNAL_TYPES,
3158
+ PROVIDER_FAILURES,
1012
3159
  QUOTA_SUPPORTED_PROVIDERS,
3160
+ RECENT_SESSION_BUCKETS,
3161
+ RECLAIMING_SEND_REFUSALS,
3162
+ RELEASE_CHANNELS,
3163
+ SEND_POLICY_MODES,
3164
+ SEND_REFUSAL_REASONS,
3165
+ SERVER_STATUS_EVENT_NAMES,
3166
+ SERVER_TO_DAEMON_CONTROL_TYPES,
1013
3167
  SERVER_TO_DAEMON_WS_MSGS,
3168
+ SESSION_ERROR_REASONS,
3169
+ SESSION_LAUNCHED_BY,
3170
+ SESSION_REBOUND_REASONS,
3171
+ SESSION_STATUSES,
3172
+ SESSION_STATUS_ALIASES,
3173
+ SESSION_STATUS_CLASS,
3174
+ SHARED_SESSION_TO_VIEWER_TYPES,
1014
3175
  STATUS_PROBE_ARG_KEY,
3176
+ SUSPENSION_MODALS,
3177
+ SUSPENSION_RESOLUTIONS,
3178
+ SUSPENSION_RESOLUTION_VIAS,
3179
+ SYSTEM_ANNOUNCEMENT_TYPES,
3180
+ TERMINAL_CLASS_EVIDENCE_KINDS,
3181
+ TOOL_CALLER_ROLES,
3182
+ TURN_END_BLOCK_REASONS,
3183
+ TURN_END_STRENGTHS,
3184
+ TURN_EVIDENCE_FIELD_SPECS,
3185
+ TURN_EVIDENCE_FLAGS,
3186
+ TURN_EVIDENCE_KINDS,
3187
+ TURN_IPC_COMMANDS,
3188
+ TURN_IPC_ERROR_CODES,
3189
+ TURN_IPC_PROTOCOL_VERSION,
3190
+ TURN_OBSERVE_VERDICTS,
3191
+ TURN_OUTCOMES,
3192
+ TURN_REASONS,
3193
+ TURN_SCOPES,
1015
3194
  UNKNOWN_CLI_SLOT_RECIPE,
3195
+ USER_SESSION_TO_DASHBOARD_TYPES,
3196
+ VERSION_UPDATE_REASONS,
3197
+ VIEWER_TO_SHARED_SESSION_TYPES,
3198
+ WORKER_BRANCH_STATES,
3199
+ WORKER_PROTOCOL_FOOTER_MARKER,
3200
+ WORKER_REPORT_OUTCOMES,
3201
+ WORKER_TOOLS,
3202
+ appendWorkerProtocolFooter,
1016
3203
  argsCarryStatusProbeMarker,
1017
3204
  buildMagiPanelProposal,
1018
3205
  buildSlotProposal,
1019
3206
  canonicalDaemonId,
3207
+ classifySessionStatus,
1020
3208
  compareSemver,
1021
3209
  daemonIdsEquivalent,
3210
+ decodeActiveWorkQueryRequest,
3211
+ decodeActiveWorkQueryResponse,
3212
+ decodeDaemonToDashboardP2P,
3213
+ decodeDaemonToServer,
3214
+ decodeDashboardToDaemonP2P,
3215
+ decodeDashboardToDaemonP2PChunk,
3216
+ decodeDashboardToUserSession,
3217
+ decodeDirectDispatchRecordRequest,
3218
+ decodeDirectDispatchRecordResponse,
3219
+ decodeGraphAuditRecordRequest,
3220
+ decodeGraphAuditRecordResponse,
3221
+ decodeGraphGateAbandonRequest,
3222
+ decodeGraphGateAbandonResponse,
3223
+ decodeGraphGateClaimRequest,
3224
+ decodeGraphGateClaimResponse,
3225
+ decodeGraphGateReleaseRequest,
3226
+ decodeGraphGateReleaseResponse,
3227
+ decodeGraphNodePatchRequest,
3228
+ decodeGraphNodePatchResponse,
3229
+ decodeGraphViewQueryRequest,
3230
+ decodeGraphViewQueryResponse,
3231
+ decodeLedgerQueryRequest,
3232
+ decodeLedgerQueryResponse,
3233
+ decodeMeshIndexQueryRequest,
3234
+ decodeMeshIndexQueryResponse,
3235
+ decodeMeshRecordRequest,
3236
+ decodeMeshRecordResponse,
3237
+ decodeMissionListQueryRequest,
3238
+ decodeMissionListQueryResponse,
3239
+ decodeMissionQueryRequest,
3240
+ decodeMissionQueryResponse,
3241
+ decodeMissionUpsertRequest,
3242
+ decodeMissionUpsertResponse,
3243
+ decodeNoteForgetRequest,
3244
+ decodeNoteForgetResponse,
3245
+ decodeNoteUpsertRequest,
3246
+ decodeNoteUpsertResponse,
3247
+ decodeOperatorStatusRequest,
3248
+ decodeOperatorStatusResponse,
3249
+ decodeOrphanedPinNotifyRequest,
3250
+ decodeOrphanedPinNotifyResponse,
3251
+ decodePruneStaleDirectRequest,
3252
+ decodePruneStaleDirectResponse,
3253
+ decodeQueueCancelRequest,
3254
+ decodeQueueCancelResponse,
3255
+ decodeQueueEnqueueGraphRequest,
3256
+ decodeQueueEnqueueGraphResponse,
3257
+ decodeQueueEnqueueRequest,
3258
+ decodeQueueEnqueueResponse,
3259
+ decodeQueueQueryRequest,
3260
+ decodeQueueQueryResponse,
3261
+ decodeQueueRequeueRequest,
3262
+ decodeQueueRequeueResponse,
3263
+ decodeRecordLocalRequest,
3264
+ decodeRecordLocalResponse,
3265
+ decodeRecoveryContextQueryRequest,
3266
+ decodeRecoveryContextQueryResponse,
3267
+ decodeServerToDaemon,
3268
+ decodeTaskStatsQueryRequest,
3269
+ decodeTaskStatsQueryResponse,
3270
+ decodeToolCallRecordRequest,
3271
+ decodeToolCallRecordResponse,
3272
+ decodeTurnCancelRequest,
3273
+ decodeTurnCancelResponse,
3274
+ decodeTurnObserveRequest,
3275
+ decodeTurnObserveResponse,
3276
+ decodeTurnQueryRequest,
3277
+ decodeTurnQueryResponse,
3278
+ decodeTypeField,
3279
+ decodeUserSessionToDashboard,
3280
+ decodeViewerToSharedSession,
1022
3281
  deriveProviderPriorityFromSlots,
1023
3282
  deriveSlotsFromLegacy,
3283
+ describeModelSelection,
3284
+ effectiveModelSelectionValue,
3285
+ enumOf,
1024
3286
  expandDaemonIdForms,
3287
+ findOwnershipConflicts,
1025
3288
  formatQuotaAccount,
1026
3289
  hasGitStatusEvidence,
3290
+ hasWorkerProtocolFooter,
1027
3291
  interpolateArgs,
1028
3292
  interpolateString,
3293
+ isActiveWorkQueryRequest,
3294
+ isActiveWorkQueryResponse,
3295
+ isBlockedStatus,
3296
+ isBusyStatus,
3297
+ isChunkType,
3298
+ isCommitStrength,
3299
+ isDaemonDirectCommandType,
3300
+ isDaemonP2PSignalType,
3301
+ isDaemonStatusEventName,
3302
+ isDaemonToDashboardP2PType,
3303
+ isDaemonToServerType,
1029
3304
  isDaemonToServerWsMsg,
3305
+ isDashboardP2PSignalType,
3306
+ isDashboardStatusEventName,
3307
+ isDashboardToDaemonChunkType,
3308
+ isDashboardToDaemonP2PType,
3309
+ isDashboardToUserSessionType,
3310
+ isDeadStatus,
3311
+ isDirectDispatchRecordRequest,
3312
+ isDirectDispatchRecordResponse,
1030
3313
  isDowngrade,
3314
+ isEvidenceIdentifier,
3315
+ isEvidenceSourceId,
3316
+ isFiniteNumber,
3317
+ isGraphAuditEvent,
3318
+ isGraphAuditRecordRequest,
3319
+ isGraphAuditRecordResponse,
3320
+ isGraphGateAbandonRequest,
3321
+ isGraphGateAbandonResponse,
3322
+ isGraphGateClaimRequest,
3323
+ isGraphGateClaimResponse,
3324
+ isGraphGateReleaseRequest,
3325
+ isGraphGateReleaseResponse,
3326
+ isGraphNodePatchRequest,
3327
+ isGraphNodePatchResponse,
3328
+ isGraphViewQueryRequest,
3329
+ isGraphViewQueryResponse,
3330
+ isHoldReason,
3331
+ isInputEnvelopeWire,
3332
+ isLedgerQueryRequest,
3333
+ isLedgerQueryResponse,
3334
+ isMeshDeliveryMode,
3335
+ isMeshIndexQueryRequest,
3336
+ isMeshIndexQueryResponse,
3337
+ isMeshIndexQueryWriterScope,
3338
+ isMeshMissionSourceValue,
3339
+ isMeshMissionStatusValue,
3340
+ isMeshP2PSignalType,
3341
+ isMeshRecordPayload,
3342
+ isMeshRecordRequest,
3343
+ isMeshRecordResponse,
3344
+ isMeshSessionCleanupMode,
1031
3345
  isMeshTaskDifficulty,
3346
+ isMeshTaskMode,
3347
+ isMeshTaskPriority,
3348
+ isMeshTaskStatus,
3349
+ isMeshTerminalTaskStatus,
3350
+ isMeshThinkingLevel,
3351
+ isMeshTopicEntry,
3352
+ isMeshTopicEntryKind,
3353
+ isMessageId,
3354
+ isMissionListQueryRequest,
3355
+ isMissionListQueryResponse,
3356
+ isMissionQueryRequest,
3357
+ isMissionQueryResponse,
3358
+ isMissionUpsertRequest,
3359
+ isMissionUpsertResponse,
3360
+ isModelAxisSource,
3361
+ isNonEmptyString,
3362
+ isNoteForgetRequest,
3363
+ isNoteForgetResponse,
3364
+ isNoteUpsertRequest,
3365
+ isNoteUpsertResponse,
3366
+ isNotifyKind,
3367
+ isOperatingNoteCategory,
3368
+ isOperatorStatusReasonValue,
3369
+ isOperatorStatusRequest,
3370
+ isOperatorStatusResponse,
3371
+ isOperatorStatusValue,
3372
+ isOrphanedPinNotifyRequest,
3373
+ isOrphanedPinNotifyResponse,
3374
+ isOutboundMessage,
3375
+ isOutboundMessageOrigin,
3376
+ isP2PSignalType,
1032
3377
  isPhantomDaemonEntry,
3378
+ isPruneStaleDirectRequest,
3379
+ isPruneStaleDirectResponse,
3380
+ isQueueCancelRequest,
3381
+ isQueueCancelResponse,
3382
+ isQueueEnqueueGraphRequest,
3383
+ isQueueEnqueueGraphResponse,
3384
+ isQueueEnqueueRequest,
3385
+ isQueueEnqueueResponse,
3386
+ isQueueQueryRequest,
3387
+ isQueueQueryResponse,
3388
+ isQueueRequeueRequest,
3389
+ isQueueRequeueResponse,
1033
3390
  isRawDaemonDoId,
3391
+ isReadyStatus,
3392
+ isRecord,
3393
+ isRecordLocalRequest,
3394
+ isRecordLocalResponse,
3395
+ isRecoveryContextQueryRequest,
3396
+ isRecoveryContextQueryResponse,
3397
+ isSendPolicy,
3398
+ isSendPolicyMode,
3399
+ isSendRefusal,
3400
+ isServerDirectCommandMsg,
3401
+ isServerToDaemonControlType,
1034
3402
  isServerToDaemonWsMsg,
3403
+ isSessionLaunchedBy,
3404
+ isSessionStatus,
3405
+ isSharedSessionToViewerType,
3406
+ isSubmitOutcome,
3407
+ isSummaryRef,
3408
+ isTaskStatsQueryRequest,
3409
+ isTaskStatsQueryResponse,
3410
+ isTerminalClassEvidenceKind,
3411
+ isToolCallRecordRequest,
3412
+ isToolCallRecordResponse,
3413
+ isToolCallerRole,
3414
+ isTurnAttemptRef,
3415
+ isTurnCancelRequest,
3416
+ isTurnCancelResponse,
3417
+ isTurnEvidence,
3418
+ isTurnEvidenceKind,
3419
+ isTurnIpcCommand,
3420
+ isTurnIpcError,
3421
+ isTurnIpcErrorCode,
3422
+ isTurnObserveRequest,
3423
+ isTurnObserveResponse,
3424
+ isTurnObserveVerdict,
3425
+ isTurnOutcome,
3426
+ isTurnQueryRequest,
3427
+ isTurnQueryResponse,
3428
+ isTurnReason,
3429
+ isUserSessionToDashboardType,
3430
+ isViewerToSharedSessionType,
3431
+ isWorkerBranchState,
3432
+ isWorkerReportOutcome,
3433
+ isWorkerTool,
3434
+ isWorkingStatus,
1035
3435
  joinRepoPath,
3436
+ launchModelSelectionValue,
1036
3437
  machineCoreFromDaemonId,
3438
+ makeTypeGuard,
1037
3439
  measureWorstCaseChunkEnvelopeBytes,
1038
3440
  meshFrameNeedsChunking,
1039
3441
  meshNodeIdMatches,
1040
3442
  meshUtf8ByteLength,
1041
3443
  meshWorkspacesEquivalent,
3444
+ mintMessageId,
3445
+ normalizeAuthOkLimits,
1042
3446
  normalizeBrainSlot,
1043
3447
  normalizeDifficultyBrainMap,
1044
3448
  normalizeGitStatus,
@@ -1046,25 +3450,39 @@ export {
1046
3450
  normalizeMeshNodeId,
1047
3451
  normalizeMeshSessionRecord,
1048
3452
  normalizeMeshWorkspaceForCompare,
3453
+ normalizeMissionBrief,
1049
3454
  normalizeNodeCapabilitySlot,
1050
3455
  normalizeNodeCapabilitySlots,
3456
+ normalizeOwnedPaths,
3457
+ normalizeSessionStatus,
1051
3458
  normalizeThinkingLevel,
1052
3459
  parseJsonRecord,
1053
3460
  parseSemver,
3461
+ parseSessionLaunchRecord,
3462
+ pathsOverlap,
1054
3463
  pickBestTransitGitStatus,
3464
+ projectTurnEvidenceEntry,
1055
3465
  readBoolean,
3466
+ readEnvelopeFields,
1056
3467
  readGitSubmodules,
1057
3468
  readNumber,
1058
3469
  readRecord,
1059
3470
  readString,
1060
3471
  readStringArray,
3472
+ renderCoordinatorWorkerSection,
3473
+ renderMissionBriefBlock,
3474
+ renderWorkerProtocolFooter,
3475
+ sanitizeModelIdentifier,
1061
3476
  scoreGitStatusCandidate,
1062
3477
  scoreGitUpstreamFreshness,
1063
3478
  sessionIdsEquivalent,
1064
3479
  splitMeshFrame,
3480
+ statusesOfClass,
1065
3481
  stripStatusProbeMarker,
3482
+ stripWorkerProtocolFooter,
1066
3483
  summarizeGitShape,
1067
3484
  supportsQuota,
3485
+ touchedFilesOutsideOwnership,
1068
3486
  withStatusProbeMarker
1069
3487
  };
1070
3488
  //# sourceMappingURL=index.mjs.map