@50arms/platform-mcp 0.1.464 → 0.1.465

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 (66) hide show
  1. package/dist/access-request.js +19 -6
  2. package/dist/agent-gate.js +19 -5
  3. package/dist/board-id.js +8 -2
  4. package/dist/checkout-docs-root.js +10 -2
  5. package/dist/clear-control.js +18 -4
  6. package/dist/compaction-control.js +30 -7
  7. package/dist/credential.js +10 -2
  8. package/dist/danxbot-api-examples.js +20 -3
  9. package/dist/design-screenshot.js +22 -5
  10. package/dist/digest-hold.js +14 -3
  11. package/dist/docs-tools.js +46 -12
  12. package/dist/durable-write.js +10 -2
  13. package/dist/forbidden-hint.js +13 -2
  14. package/dist/guarded-calls.js +6 -2
  15. package/dist/handlers.js +66 -14
  16. package/dist/heartbeat-reporter.js +8 -3
  17. package/dist/http-client.js +4 -2
  18. package/dist/index.js +242 -80
  19. package/dist/job-key.js +3 -1
  20. package/dist/json-body.js +3 -1
  21. package/dist/key-revoked-halt.js +2 -1
  22. package/dist/leftover-wire.js +17 -4
  23. package/dist/lifecycle.js +11 -3
  24. package/dist/listen.js +242 -64
  25. package/dist/listener-reminder.js +8 -2
  26. package/dist/machine-daemon/autostart.js +16 -4
  27. package/dist/machine-daemon/beat.js +18 -4
  28. package/dist/machine-daemon/cli.js +15 -4
  29. package/dist/machine-daemon/install.js +33 -9
  30. package/dist/machine-daemon/leftovers.js +134 -30
  31. package/dist/machine-daemon/state.js +9 -3
  32. package/dist/machine-daemon.js +531 -128
  33. package/dist/machine-registration.js +27 -6
  34. package/dist/machine-secret.js +8 -3
  35. package/dist/machine-toolkit.js +377 -81
  36. package/dist/mini-app-build.js +19 -5
  37. package/dist/mini-app-checkout.js +38 -10
  38. package/dist/mini-app-output.js +22 -5
  39. package/dist/mini-app-publish.js +34 -11
  40. package/dist/mini-app-restore.js +30 -9
  41. package/dist/one-line.js +3 -1
  42. package/dist/permission-request.js +14 -3
  43. package/dist/permission-watch.js +10 -3
  44. package/dist/plan-events-relay.js +96 -19
  45. package/dist/plan-events-tool.js +9 -2
  46. package/dist/plugin-publish.js +23 -6
  47. package/dist/plugin-screenshot.js +18 -6
  48. package/dist/restart-notice.js +47 -15
  49. package/dist/result-limit.js +6 -1
  50. package/dist/role-instruction-file.js +16 -4
  51. package/dist/route-board-scope.js +6 -2
  52. package/dist/session-access.js +110 -32
  53. package/dist/session-connection.js +23 -7
  54. package/dist/session-control-file.js +1 -1
  55. package/dist/session-key.js +12 -4
  56. package/dist/session-options.js +6 -2
  57. package/dist/session-stats.js +2 -1
  58. package/dist/session-stream.js +81 -20
  59. package/dist/shutdown.js +3 -1
  60. package/dist/subagents-live.js +8 -2
  61. package/dist/terms-halt.js +4 -2
  62. package/dist/tool-access.js +17 -4
  63. package/dist/tool-surface.js +9 -2
  64. package/dist/transcript-lineage.js +5 -2
  65. package/dist/urgent-records.js +1 -0
  66. package/package.json +1 -1
package/dist/lifecycle.js CHANGED
@@ -24,7 +24,10 @@ export function presentCallbacksFromEnv() {
24
24
  async function postJson(url, body, bearer) {
25
25
  return fetch(url, {
26
26
  method: "POST",
27
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${bearer}` },
27
+ headers: {
28
+ "Content-Type": "application/json",
29
+ Authorization: `Bearer ${bearer}`,
30
+ },
28
31
  body: JSON.stringify(body),
29
32
  });
30
33
  }
@@ -64,7 +67,10 @@ async function readAttachments(paths) {
64
67
  if (info.size > MAX_ATTACHMENT_BYTES) {
65
68
  throw new Error(`field "files"[${idx}] "${entry}" is ${info.size} bytes, over the ${MAX_ATTACHMENT_BYTES}-byte attachment limit`);
66
69
  }
67
- return { filename: basename(entry), base64: (await readFile(entry)).toString("base64") };
70
+ return {
71
+ filename: basename(entry),
72
+ base64: (await readFile(entry)).toString("base64"),
73
+ };
68
74
  }));
69
75
  }
70
76
  /** A refused callback's body is the only place the server says why — relay it, never just the status. */
@@ -83,7 +89,9 @@ export function registerLifecycleTools(renamedTool) {
83
89
  // `slack-agent` profile own the order (reply, link, attach, complete).
84
90
  "Post the final user-facing reply to the originating Slack thread, once per dispatch. Files in `files[]` " +
85
91
  "post with the text as one thread message. For a progress update, `50arms_api` `POST /api/slack/update` `{text}`.", {
86
- text: z.string().describe("The final reply text to post to the Slack thread."),
92
+ text: z
93
+ .string()
94
+ .describe("The final reply text to post to the Slack thread."),
87
95
  files: z
88
96
  .array(z.string())
89
97
  .optional()
package/dist/listen.js CHANGED
@@ -41,10 +41,10 @@
41
41
  * (`src/issues/db/issue-activity.ts`); this published package cannot import
42
42
  * danxbot source.
43
43
  */
44
- import { controlOfFrame, invalidCompactionReason } from "./compaction-control.js";
45
- import { clearControlOfFrame, invalidClearReason } from "./clear-control.js";
44
+ import { controlOfFrame, invalidCompactionReason, } from "./compaction-control.js";
45
+ import { clearControlOfFrame, invalidClearReason, } from "./clear-control.js";
46
46
  import { LINE_PREFIX, oneLine } from "./one-line.js";
47
- import { MCP_STREAM_MIN_VERSION_HEADER, ownVersionBelow, readOwnVersion } from "./version-floor.js";
47
+ import { MCP_STREAM_MIN_VERSION_HEADER, ownVersionBelow, readOwnVersion, } from "./version-floor.js";
48
48
  import { pacingRelayLine } from "./pacing-relay.js";
49
49
  import { isUrgent } from "./urgent-records.js";
50
50
  export const INITIAL_BACKOFF_MS = 1_000;
@@ -65,7 +65,11 @@ export const DELIVERED_ID_MEMORY = 1_000;
65
65
  export function capResumeIds(ids) {
66
66
  return ids.slice(-DELIVERED_ID_MEMORY);
67
67
  }
68
- const ACTIVITY_ORIGINS = new Set(["operator", "agent", "machine"]);
68
+ const ACTIVITY_ORIGINS = new Set([
69
+ "operator",
70
+ "agent",
71
+ "machine",
72
+ ]);
69
73
  function quoted(value) {
70
74
  return `"${value.text}${value.truncated ? "…" : ""}"`;
71
75
  }
@@ -73,17 +77,24 @@ function isRecord(value) {
73
77
  return typeof value === "object" && value !== null && !Array.isArray(value);
74
78
  }
75
79
  function isCappedText(value) {
76
- return isRecord(value) && typeof value.text === "string" && typeof value.truncated === "boolean";
80
+ return (isRecord(value) &&
81
+ typeof value.text === "string" &&
82
+ typeof value.truncated === "boolean");
77
83
  }
78
84
  function isAckList(value) {
79
85
  return (Array.isArray(value) &&
80
86
  value.length > 0 &&
81
- value.every((a) => isRecord(a) && Number.isSafeInteger(a.eventId) && a.eventId > 0 && Number.isSafeInteger(a.attempt) && a.attempt >= 1));
87
+ value.every((a) => isRecord(a) &&
88
+ Number.isSafeInteger(a.eventId) &&
89
+ a.eventId > 0 &&
90
+ Number.isSafeInteger(a.attempt) &&
91
+ a.attempt >= 1));
82
92
  }
83
93
  /** DX-4078 - hand-copied from `DESIGN_DECISION_OUTCOMES` (`src/issues/view-types.ts`): this published package cannot import danxbot source. */
84
94
  const DESIGN_OUTCOMES = ["approved", "rejected", "changes_requested"];
85
95
  function isDesignOutcome(value) {
86
- return typeof value === "string" && DESIGN_OUTCOMES.includes(value);
96
+ return (typeof value === "string" &&
97
+ DESIGN_OUTCOMES.includes(value));
87
98
  }
88
99
  /**
89
100
  * DX-3880 — the part `solution_answered` and `problem_answer_changed` share: the
@@ -97,14 +108,20 @@ function invalidDecisionBody(d) {
97
108
  if (d.solution === null) {
98
109
  if (d.outcome === "rejected")
99
110
  return "detail.solution is null on a rejection";
100
- return isCappedText(d.freeform) ? null : "detail.freeform is not capped text";
111
+ return isCappedText(d.freeform)
112
+ ? null
113
+ : "detail.freeform is not capped text";
101
114
  }
102
115
  if (!isRecord(d.solution) || typeof d.solution.title !== "string")
103
116
  return "detail.solution is not {title, note}";
104
117
  if (d.outcome === "rejected") {
105
- return isCappedText(d.solution.note) ? null : "detail.solution.note (the rejection reason) is not capped text";
118
+ return isCappedText(d.solution.note)
119
+ ? null
120
+ : "detail.solution.note (the rejection reason) is not capped text";
106
121
  }
107
- return d.solution.note === null || isCappedText(d.solution.note) ? null : "detail.solution.note is not capped text";
122
+ return d.solution.note === null || isCappedText(d.solution.note)
123
+ ? null
124
+ : "detail.solution.note is not capped text";
108
125
  }
109
126
  /**
110
127
  * DX-2735 — why an event cannot be described, or `null` when it can.
@@ -121,7 +138,10 @@ export function invalidEventReason(value) {
121
138
  if (typeof value.id !== "number" || !Number.isSafeInteger(value.id))
122
139
  return "id is not an integer";
123
140
  // DX-6211: the subject is a card (`cardId` a string) or the plan itself (`planId` a positive integer and `cardId` null), never both and never neither.
124
- if (value.planId !== null && !(typeof value.planId === "number" && Number.isSafeInteger(value.planId) && value.planId > 0)) {
141
+ if (value.planId !== null &&
142
+ !(typeof value.planId === "number" &&
143
+ Number.isSafeInteger(value.planId) &&
144
+ value.planId > 0)) {
125
145
  return "planId is not null or a positive integer";
126
146
  }
127
147
  if (typeof value.planId === "number") {
@@ -148,7 +168,10 @@ export function invalidEventReason(value) {
148
168
  return "origin is not one of operator, agent, machine";
149
169
  }
150
170
  // DX-4246 — the key snapshot is part of every event the dashboard sends, `null` when no key wrote it.
151
- if (value.viaKey !== null && !(isRecord(value.viaKey) && typeof value.viaKey.id === "number" && typeof value.viaKey.name === "string")) {
171
+ if (value.viaKey !== null &&
172
+ !(isRecord(value.viaKey) &&
173
+ typeof value.viaKey.id === "number" &&
174
+ typeof value.viaKey.name === "string")) {
152
175
  return "viaKey is not null or {id, name}";
153
176
  }
154
177
  if (value.release !== undefined && value.release !== true)
@@ -171,20 +194,26 @@ export function invalidEventReason(value) {
171
194
  if (d.problem === undefined)
172
195
  return null;
173
196
  const problem = d.problem;
174
- return isRecord(problem) && typeof problem.id === "number" && isCappedText(problem.statement)
197
+ return isRecord(problem) &&
198
+ typeof problem.id === "number" &&
199
+ isCappedText(problem.statement)
175
200
  ? null
176
201
  : "detail.problem is not {id, statement}";
177
202
  }
178
203
  case "solution_answered": {
179
204
  const problem = d.problem;
180
- if (!isRecord(problem) || typeof problem.id !== "number" || !isCappedText(problem.statement)) {
205
+ if (!isRecord(problem) ||
206
+ typeof problem.id !== "number" ||
207
+ !isCappedText(problem.statement)) {
181
208
  return "detail.problem is not {id, statement}";
182
209
  }
183
210
  return invalidDecisionBody(d);
184
211
  }
185
212
  case "problem_added": {
186
213
  const problem = d.problem;
187
- if (!isRecord(problem) || typeof problem.id !== "number" || !isCappedText(problem.statement)) {
214
+ if (!isRecord(problem) ||
215
+ typeof problem.id !== "number" ||
216
+ !isCappedText(problem.statement)) {
188
217
  return "detail.problem is not {id, statement}";
189
218
  }
190
219
  return null;
@@ -192,17 +221,23 @@ export function invalidEventReason(value) {
192
221
  // DX-2935 — the operator retracted a problem's answer with no new one yet.
193
222
  case "problem_unanswered": {
194
223
  const problem = d.problem;
195
- if (!isRecord(problem) || typeof problem.id !== "number" || !isCappedText(problem.statement)) {
224
+ if (!isRecord(problem) ||
225
+ typeof problem.id !== "number" ||
226
+ !isCappedText(problem.statement)) {
196
227
  return "detail.problem is not {id, statement}";
197
228
  }
198
- return typeof d.decision_id === "number" ? null : "detail.decision_id is not a number";
229
+ return typeof d.decision_id === "number"
230
+ ? null
231
+ : "detail.decision_id is not a number";
199
232
  }
200
233
  // DX-2935 — the operator retracted a problem's answer AND recorded a new
201
234
  // one, in one transaction — same either/or solution/freeform shape
202
235
  // `solution_answered` carries, plus which decision was retracted.
203
236
  case "problem_answer_changed": {
204
237
  const problem = d.problem;
205
- if (!isRecord(problem) || typeof problem.id !== "number" || !isCappedText(problem.statement)) {
238
+ if (!isRecord(problem) ||
239
+ typeof problem.id !== "number" ||
240
+ !isCappedText(problem.statement)) {
206
241
  return "detail.problem is not {id, statement}";
207
242
  }
208
243
  if (typeof d.retracted_decision_id !== "number")
@@ -217,14 +252,18 @@ export function invalidEventReason(value) {
217
252
  case "agent_note_added":
218
253
  if (typeof d.note_id !== "number")
219
254
  return "detail.note_id is not a number";
220
- return isCappedText(d.excerpt) ? null : "detail.excerpt is not capped text";
255
+ return isCappedText(d.excerpt)
256
+ ? null
257
+ : "detail.excerpt is not capped text";
221
258
  // DX-4622: a reviewer asked for changes on the card's pull request (GitHub review webhook).
222
259
  case "pull_request_changes_requested":
223
260
  if (typeof d.reviewer !== "string")
224
261
  return "detail.reviewer is not a string";
225
262
  if (typeof d.review_url !== "string")
226
263
  return "detail.review_url is not a string";
227
- return isCappedText(d.excerpt) ? null : "detail.excerpt is not capped text";
264
+ return isCappedText(d.excerpt)
265
+ ? null
266
+ : "detail.excerpt is not capped text";
228
267
  // DX-6478: a designer published a revision it could not check in a browser.
229
268
  case "design_published_unchecked":
230
269
  if (typeof d.design_no !== "number")
@@ -249,8 +288,12 @@ export function invalidEventReason(value) {
249
288
  if (!isDesignOutcome(d.outcome))
250
289
  return 'detail.outcome is not "approved", "rejected" or "changes_requested"';
251
290
  if (d.note === null)
252
- return d.outcome === "approved" ? null : `detail.note (the ${d.outcome} reason) is null`;
253
- return isCappedText(d.note) ? null : "detail.note is not null or capped text";
291
+ return d.outcome === "approved"
292
+ ? null
293
+ : `detail.note (the ${d.outcome} reason) is null`;
294
+ return isCappedText(d.note)
295
+ ? null
296
+ : "detail.note is not null or capped text";
254
297
  }
255
298
  default:
256
299
  return null;
@@ -286,7 +329,9 @@ export function planReplyInstruction(planId, commentId) {
286
329
  }
287
330
  /** DX-6211: the event's subject as the line names it: the card's id, or the plan's reference (`PLAN-72`, sent by the dashboard as `planRef`) for a plan event. Only called on an event `invalidEventReason` accepted. */
288
331
  function subjectRef(event) {
289
- return typeof event.planId === "number" ? event.planRef : event.cardId;
332
+ return typeof event.planId === "number"
333
+ ? event.planRef
334
+ : event.cardId;
290
335
  }
291
336
  function replyInstructionAt(path) {
292
337
  return `Answer it through its reply route: first call 50arms_api POST ${path} with {"phase":"ack","body":"<one short sentence of your own acknowledging it>"} so the person sees it was received, then do the work and call POST ${path} again with {"phase":"reply","body":"<your full answer>"}, which replaces your acknowledgement. Another event for a comment you already answered (a follow-up the person added to it before your answer) takes only another {"phase":"reply","body":"<your answer to the follow-up>"}, which is a new answer of its own under the comment, never written over the one you gave; never send "ack" after an answer, and never answer through the plain comment route`;
@@ -308,11 +353,15 @@ function describe(event) {
308
353
  return `${who} notice: ${quoted(d.excerpt)}`;
309
354
  // DX-6211: a comment written on the plan itself is answered through the plan's reply route, and the line says it was written on the plan.
310
355
  const onPlan = typeof event.planId === "number";
311
- const reply = !isPersonsComment(event) ? "" : `. ${onPlan ? planReplyInstruction(event.planId, d.comment_id) : replyInstruction(event.cardId, d.comment_id)}`;
356
+ const reply = !isPersonsComment(event)
357
+ ? ""
358
+ : `. ${onPlan ? planReplyInstruction(event.planId, d.comment_id) : replyInstruction(event.cardId, d.comment_id)}`;
312
359
  if (problem === undefined)
313
360
  return `${who} commented${onPlan ? " on the plan" : ""}: ${quoted(d.excerpt)}${reply}`;
314
361
  // DX-7108 (operator correction, comment 21778): a person's comment that answers the problem is recorded as its answer by the session, quoting the comment.
315
- const answerHint = !isPersonsComment(event) || onPlan ? "" : `. If the comment decides the problem, record it as the answer in the same turn: POST /api/issues/${event.cardId}/problems/${problem.id}/answer with the chosen solution_id or freeform and provenance {"source":"comment","source_ref":"${d.comment_id}","quote":"<their words>"}`;
362
+ const answerHint = !isPersonsComment(event) || onPlan
363
+ ? ""
364
+ : `. If the comment decides the problem, record it as the answer in the same turn: POST /api/issues/${event.cardId}/problems/${problem.id}/answer with the chosen solution_id or freeform and provenance {"source":"comment","source_ref":"${d.comment_id}","quote":"<their words>"}`;
316
365
  return `${who} commented on problem ${quoted(problem.statement)}: ${quoted(d.excerpt)}${reply}${answerHint}`;
317
366
  }
318
367
  case "solution_answered": {
@@ -353,7 +402,9 @@ function describe(event) {
353
402
  const solution = d.solution;
354
403
  if (d.outcome === "rejected")
355
404
  return `${who} changed the answer to ${quoted(problem.statement)}: now REJECTED the action "${solution.title}" — reason: ${quoted(solution.note)}. Do not perform it; re-plan from the reason`;
356
- const now = solution === null ? quoted(d.freeform) : `"${solution.title}"`;
405
+ const now = solution === null
406
+ ? quoted(d.freeform)
407
+ : `"${solution.title}"`;
357
408
  return `${who} changed the answer to ${quoted(problem.statement)}: now ${now}. ${UPDATE_RECORDS_NOW}`;
358
409
  }
359
410
  case "blocked":
@@ -415,22 +466,28 @@ const FILED_NOT_READIED_LABEL = "Filed, not readied";
415
466
  const REVIEWABLE_LABEL = "Review runnable now";
416
467
  const REVIEWABLE_INSTRUCTION = "start each card's named gate review (its next PRE gate): a depends_on never holds a review";
417
468
  function isNudgeCardRef(value) {
418
- return isRecord(value) && typeof value.id === "string" && typeof value.title === "string";
469
+ return (isRecord(value) &&
470
+ typeof value.id === "string" &&
471
+ typeof value.title === "string");
419
472
  }
420
473
  function isReviewableNudgeCardRefArray(value) {
421
- return Array.isArray(value) && value.every((c) => isNudgeCardRef(c) && typeof c.gate === "string");
474
+ return (Array.isArray(value) &&
475
+ value.every((c) => isNudgeCardRef(c) && typeof c.gate === "string"));
422
476
  }
423
477
  function isNudgeCardRefArray(value) {
424
478
  return Array.isArray(value) && value.every(isNudgeCardRef);
425
479
  }
426
480
  function isQueuedNudgeCardRefArray(value) {
427
- return Array.isArray(value) && value.every((c) => isNudgeCardRef(c) && typeof c.queueState === "string");
481
+ return (Array.isArray(value) &&
482
+ value.every((c) => isNudgeCardRef(c) &&
483
+ typeof c.queueState === "string"));
428
484
  }
429
485
  /** Why a nudge cannot be read, or `null` when it can — same checked-before-describing shape as `invalidEventReason`. */
430
486
  export function invalidNudgeReason(value) {
431
487
  if (!isRecord(value))
432
488
  return "the nudge is not an object";
433
- if (typeof value.idleMinutes !== "number" || !Number.isFinite(value.idleMinutes)) {
489
+ if (typeof value.idleMinutes !== "number" ||
490
+ !Number.isFinite(value.idleMinutes)) {
434
491
  return "idleMinutes is not a number";
435
492
  }
436
493
  if (!isQueuedNudgeCardRefArray(value.startable))
@@ -441,7 +498,10 @@ export function invalidNudgeReason(value) {
441
498
  return "unreadied is not a {id,title}[] array";
442
499
  if (!isReviewableNudgeCardRefArray(value.reviewable))
443
500
  return "reviewable is not a {id,title,gate}[] array";
444
- if (value.freeSlots !== null && !(typeof value.freeSlots === "number" && Number.isInteger(value.freeSlots) && value.freeSlots >= 0))
501
+ if (value.freeSlots !== null &&
502
+ !(typeof value.freeSlots === "number" &&
503
+ Number.isInteger(value.freeSlots) &&
504
+ value.freeSlots >= 0))
445
505
  return "freeSlots is not a count or null";
446
506
  return null;
447
507
  }
@@ -518,16 +578,24 @@ export function formatNudgeLine(event) {
518
578
  const tail = advice.length > 0 ? `. ${advice.join(" ")}` : ".";
519
579
  return oneLine(`${LINE_PREFIX} this session has not made an MCP call in ${event.idleMinutes}m — ${parts.join("; ")}${tail}`);
520
580
  }
521
- const PACING_LEVELS = ["on_pace", "over_pace", "critical"];
581
+ const PACING_LEVELS = [
582
+ "on_pace",
583
+ "over_pace",
584
+ "critical",
585
+ ];
522
586
  /** Why a pacing message cannot be read, or `null` when it can. */
523
587
  export function invalidPacingReason(value) {
524
588
  if (!isRecord(value))
525
589
  return "the pacing message is not an object";
526
590
  if (!PACING_LEVELS.includes(value.level))
527
591
  return "level is not on_pace, over_pace or critical";
528
- if (value.budget !== null && !(typeof value.budget === "number" && Number.isInteger(value.budget) && value.budget >= 0))
592
+ if (value.budget !== null &&
593
+ !(typeof value.budget === "number" &&
594
+ Number.isInteger(value.budget) &&
595
+ value.budget >= 0))
529
596
  return "budget is not a count or null";
530
- if (typeof value.resets_at !== "string" || Number.isNaN(Date.parse(value.resets_at)))
597
+ if (typeof value.resets_at !== "string" ||
598
+ Number.isNaN(Date.parse(value.resets_at)))
531
599
  return "resets_at is not a timestamp";
532
600
  if (typeof value.text !== "string" || value.text.trim() === "")
533
601
  return "text is empty";
@@ -591,7 +659,8 @@ export function invalidOwedCommentReason(value) {
591
659
  return "the owed-comment message is not an object";
592
660
  if (typeof value.text !== "string" || value.text.trim() === "")
593
661
  return "text is empty";
594
- if (!Array.isArray(value.comment_ids) || !value.comment_ids.every((id) => Number.isSafeInteger(id)))
662
+ if (!Array.isArray(value.comment_ids) ||
663
+ !value.comment_ids.every((id) => Number.isSafeInteger(id)))
595
664
  return "comment_ids is not a list of comment ids";
596
665
  return null;
597
666
  }
@@ -612,26 +681,39 @@ export function invalidAgentCreatedReason(value) {
612
681
  return "agent.id is not a positive integer";
613
682
  if (typeof value.agent.name !== "string" || value.agent.name.trim() === "")
614
683
  return "agent.name is empty";
615
- if (typeof value.agentInstruction !== "string" || value.agentInstruction.trim() === "")
684
+ if (typeof value.agentInstruction !== "string" ||
685
+ value.agentInstruction.trim() === "")
616
686
  return "agentInstruction is empty";
617
- if (value.plan !== null && (!isRecord(value.plan) || typeof value.plan.ref !== "string" || typeof value.plan.name !== "string"))
687
+ if (value.plan !== null &&
688
+ (!isRecord(value.plan) ||
689
+ typeof value.plan.ref !== "string" ||
690
+ typeof value.plan.name !== "string"))
618
691
  return "plan is neither null nor a {ref, name} object";
619
- if (value.card !== null && (!isRecord(value.card) || typeof value.card.id !== "string" || typeof value.card.title !== "string"))
692
+ if (value.card !== null &&
693
+ (!isRecord(value.card) ||
694
+ typeof value.card.id !== "string" ||
695
+ typeof value.card.title !== "string"))
620
696
  return "card is neither null nor a {id, title} object";
621
697
  if (value.naming !== null) {
622
- if (!isRecord(value.naming) || (value.naming.status !== "ok" && value.naming.status !== "needed"))
698
+ if (!isRecord(value.naming) ||
699
+ (value.naming.status !== "ok" && value.naming.status !== "needed"))
623
700
  return "naming is neither null nor a naming block";
624
- if (value.naming.status === "needed" && (typeof value.naming.instruction !== "string" || value.naming.instruction.trim() === ""))
701
+ if (value.naming.status === "needed" &&
702
+ (typeof value.naming.instruction !== "string" ||
703
+ value.naming.instruction.trim() === ""))
625
704
  return "naming.instruction is empty";
626
705
  }
627
- if (value.titleInstruction !== null && typeof value.titleInstruction !== "string")
706
+ if (value.titleInstruction !== null &&
707
+ typeof value.titleInstruction !== "string")
628
708
  return "titleInstruction is neither null nor a string";
629
709
  if (value.rolePointer !== null && typeof value.rolePointer !== "string")
630
710
  return "rolePointer is neither null nor a string";
631
711
  if (value.owedComments !== null && typeof value.owedComments !== "string")
632
712
  return "owedComments is neither null nor a string";
633
713
  if (value.missedEvents !== null) {
634
- if (!isRecord(value.missedEvents) || !Array.isArray(value.missedEvents.events) || !Number.isSafeInteger(value.missedEvents.omitted))
714
+ if (!isRecord(value.missedEvents) ||
715
+ !Array.isArray(value.missedEvents.events) ||
716
+ !Number.isSafeInteger(value.missedEvents.omitted))
635
717
  return "missedEvents is neither null nor an {events, omitted} object";
636
718
  for (const event of value.missedEvents.events) {
637
719
  const bad = invalidEventReason(event);
@@ -646,15 +728,29 @@ export function invalidAgentCreatedReason(value) {
646
728
  * validated the frame ({@link invalidAgentCreatedReason}).
647
729
  */
648
730
  export function formatAgentCreatedLine(event) {
649
- const where = event.plan !== null ? ` and connected to ${event.plan.ref} ${oneLine(event.plan.name, 80)}` : event.card !== null ? ` and connected to card ${event.card.id}` : "";
650
- const thread = event.naming !== null ? (event.naming.status === "needed" ? event.naming.instruction : "") : (event.titleInstruction ?? "");
731
+ const where = event.plan !== null
732
+ ? ` and connected to ${event.plan.ref} ${oneLine(event.plan.name, 80)}`
733
+ : event.card !== null
734
+ ? ` and connected to card ${event.card.id}`
735
+ : "";
736
+ const thread = event.naming !== null
737
+ ? event.naming.status === "needed"
738
+ ? event.naming.instruction
739
+ : ""
740
+ : (event.titleInstruction ?? "");
651
741
  const missed = event.missedEvents;
652
742
  const missedLines = missed === null || missed.events.length === 0
653
743
  ? ""
654
744
  : `Missed while you waited for your agent: ${missed.events.map((e) => formatActivityLine(e)).join(" ")}${missed.omitted > 0 ? ` (${missed.omitted} more not shown)` : ""}`;
655
745
  // DX-6157: no connect is needed to take what Create gave the session; a naming or role step that follows still makes its own call.
656
- const held = event.plan !== null ? "this agent and plan" : event.card !== null ? "this agent and card" : "this agent";
657
- const ownCalls = thread !== "" || event.rolePointer !== null ? "; the steps below keep their own calls" : "";
746
+ const held = event.plan !== null
747
+ ? "this agent and plan"
748
+ : event.card !== null
749
+ ? "this agent and card"
750
+ : "this agent";
751
+ const ownCalls = thread !== "" || event.rolePointer !== null
752
+ ? "; the steps below keep their own calls"
753
+ : "";
658
754
  const parts = [
659
755
  `${LINE_PREFIX} The person created your team agent ${oneLine(event.agent.name, 60)}: this session is now signed in as it${where}. Taking ${held} needs no \`session_connect\`${ownCalls}.`,
660
756
  oneLine(event.agentInstruction, 800),
@@ -716,7 +812,13 @@ function parseBlock(block) {
716
812
  * than passing the raw string through, which is what lets `Outcome`'s
717
813
  * `reason` field below be a closed union instead of `string`.
718
814
  */
719
- const KNOWN_WIRE_END_REASONS = new Set(["superseded", "replaced", "revoked", "not_connected", "plan_archived"]);
815
+ const KNOWN_WIRE_END_REASONS = new Set([
816
+ "superseded",
817
+ "replaced",
818
+ "revoked",
819
+ "not_connected",
820
+ "plan_archived",
821
+ ]);
720
822
  function isKnownWireEndReason(reason) {
721
823
  return KNOWN_WIRE_END_REASONS.has(reason);
722
824
  }
@@ -760,7 +862,10 @@ export async function runListener(options, deps) {
760
862
  return { parsed, invalid: invalidReason(parsed) };
761
863
  }
762
864
  catch (err) {
763
- return { parsed: undefined, invalid: `not JSON: ${err.message}` };
865
+ return {
866
+ parsed: undefined,
867
+ invalid: `not JSON: ${err.message}`,
868
+ };
764
869
  }
765
870
  };
766
871
  const faultText = (what, invalid, message) => `${LINE_PREFIX} could not read ${what} (${invalid}): ${oneLine(message.data, 300)}. This session's platform MCP (version ${readOwnVersion()}) cannot read what the dashboard sends: ` +
@@ -801,7 +906,15 @@ export async function runListener(options, deps) {
801
906
  const text = invalid === null ? format(parsed) : faultText(what, invalid, message);
802
907
  // DX-4721: an unreadable frame is a fault line, never the frame it failed to be (a malformed `critical` pacing frame is not a stop).
803
908
  const urgent = isUrgent(invalid === null ? sourceOf(parsed) : { source: "fault" });
804
- deps.write({ type: "event", id: knownId ? id : null, text, origin: null, urgent, acks: [], ...(scope === undefined ? {} : { scope }) });
909
+ deps.write({
910
+ type: "event",
911
+ id: knownId ? id : null,
912
+ text,
913
+ origin: null,
914
+ urgent,
915
+ acks: [],
916
+ ...(scope === undefined ? {} : { scope }),
917
+ });
805
918
  if (knownId)
806
919
  remember(id);
807
920
  return null;
@@ -814,7 +927,15 @@ export async function runListener(options, deps) {
814
927
  deps.write(outputOf(parsed));
815
928
  }
816
929
  else if (faultIsNew(what, invalid))
817
- deps.write({ type: "event", id: null, text: faultText(what, invalid, message), origin: null, urgent: isUrgent({ source: "fault" }), acks: [], scope: "session" });
930
+ deps.write({
931
+ type: "event",
932
+ id: null,
933
+ text: faultText(what, invalid, message),
934
+ origin: null,
935
+ urgent: isUrgent({ source: "fault" }),
936
+ acks: [],
937
+ scope: "session",
938
+ });
818
939
  return null;
819
940
  };
820
941
  // DX-5554 (AC6): the agent ids already announced to the session. The frame is level-triggered (written again on every reconnect while the agent is untaken), so one agent wakes the session once.
@@ -823,7 +944,15 @@ export async function runListener(options, deps) {
823
944
  const { parsed, invalid } = readFrame(message, invalidAgentCreatedReason);
824
945
  if (invalid !== null) {
825
946
  if (faultIsNew("agent-created frame", invalid))
826
- deps.write({ type: "event", id: null, text: faultText("agent-created frame", invalid, message), origin: null, urgent: isUrgent({ source: "fault" }), acks: [], scope: "session" });
947
+ deps.write({
948
+ type: "event",
949
+ id: null,
950
+ text: faultText("agent-created frame", invalid, message),
951
+ origin: null,
952
+ urgent: isUrgent({ source: "fault" }),
953
+ acks: [],
954
+ scope: "session",
955
+ });
827
956
  return null;
828
957
  }
829
958
  reportedFaults.delete("agent-created frame");
@@ -833,7 +962,15 @@ export async function runListener(options, deps) {
833
962
  return null;
834
963
  announcedAgentIds.add(agent.id);
835
964
  deps.onAgentCreated?.(created);
836
- deps.write({ type: "event", id: null, text: formatAgentCreatedLine(created), origin: null, urgent: isUrgent({ source: "agent_created" }), acks: [], scope: "session" });
965
+ deps.write({
966
+ type: "event",
967
+ id: null,
968
+ text: formatAgentCreatedLine(created),
969
+ origin: null,
970
+ urgent: isUrgent({ source: "agent_created" }),
971
+ acks: [],
972
+ scope: "session",
973
+ });
837
974
  return null;
838
975
  };
839
976
  const handle = (message) => {
@@ -853,7 +990,10 @@ export async function runListener(options, deps) {
853
990
  // newer dashboard's reason an older client hasn't shipped yet)
854
991
  // normalizes to "unknown" rather than passing the raw string through:
855
992
  // `Outcome`'s "ended" reason is a closed set (`EndedReason`).
856
- return { kind: "ended", reason: isKnownWireEndReason(reason) ? reason : "unknown" };
993
+ return {
994
+ kind: "ended",
995
+ reason: isKnownWireEndReason(reason) ? reason : "unknown",
996
+ };
857
997
  }
858
998
  if (message.event === "nudge")
859
999
  return emitAdvisory(message, "nudge", invalidNudgeReason, (p) => formatNudgeLine(p), () => ({ source: "nudge" }));
@@ -873,6 +1013,9 @@ export async function runListener(options, deps) {
873
1013
  // DX-6866 - a docs draft owed on this session's plan: the same one-line frame.
874
1014
  if (message.event === "docs_draft")
875
1015
  return emitAdvisory(message, "docs draft message", invalidAssignmentReason, (p) => formatAssignmentLine(p), () => ({ source: "docs_draft" }));
1016
+ // DX-7006 - a Compact job told to this session (on its plan or card, or as the ready agent that waited longest): the same one-line frame, session-scoped (a ready agent told a card's job holds nothing).
1017
+ if (message.event === "content_compaction")
1018
+ return emitAdvisory(message, "compact job message", invalidAssignmentReason, (p) => formatAssignmentLine(p), () => ({ source: "content_compaction" }), "session");
876
1019
  // DX-7107 - processes this session started and left running: a reminder, non-urgent and session-scoped like an owed comment.
877
1020
  if (message.event === "leftover_processes")
878
1021
  return emitAdvisory(message, "leftover-processes message", invalidLeftoverProcessesReason, (p) => formatLeftoverProcessesLine(p), () => ({ source: "leftover_processes" }), "session");
@@ -883,7 +1026,10 @@ export async function runListener(options, deps) {
883
1026
  return emitControl(message, "compaction control", invalidCompactionReason, (p) => ({ type: "compaction", control: controlOfFrame(p) }));
884
1027
  // DX-6692 - the clear control of a ready-list session whose job has ended: level-triggered like `compaction`.
885
1028
  if (message.event === "clear")
886
- return emitControl(message, "clear control", invalidClearReason, (p) => ({ type: "clear", control: clearControlOfFrame(p) }));
1029
+ return emitControl(message, "clear control", invalidClearReason, (p) => ({
1030
+ type: "clear",
1031
+ control: clearControlOfFrame(p),
1032
+ }));
887
1033
  if (message.event === "team_agent_created")
888
1034
  return emitAgentCreated(message);
889
1035
  if (message.event !== "activity")
@@ -923,10 +1069,22 @@ export async function runListener(options, deps) {
923
1069
  // DX-5846: a repeat of an event nobody acknowledged is the dashboard asking again: emitted at once like a pause release (never held for a digest, which would wait out the next attempt too).
924
1070
  const resent = acks.some((a) => a.attempt > 1);
925
1071
  // DX-4951: a pause release is the session's own notice: emitted at once (`origin: null`), and kept across a plan move (`scope: "session"`).
926
- const origin = invalid === null && !release && !resent ? parsed.origin : null;
1072
+ const origin = invalid === null && !release && !resent
1073
+ ? parsed.origin
1074
+ : null;
927
1075
  // DX-4721: an unreadable event is a fault line; a readable one is urgent by its kind (none is today).
928
- const urgent = isUrgent(invalid === null ? { source: "activity", kind: parsed.kind } : { source: "fault" });
929
- deps.write({ type: "event", id: knownId ? id : null, text, origin, urgent, acks, ...(release ? { scope: "session" } : {}) });
1076
+ const urgent = isUrgent(invalid === null
1077
+ ? { source: "activity", kind: parsed.kind }
1078
+ : { source: "fault" });
1079
+ deps.write({
1080
+ type: "event",
1081
+ id: knownId ? id : null,
1082
+ text,
1083
+ origin,
1084
+ urgent,
1085
+ acks,
1086
+ ...(release ? { scope: "session" } : {}),
1087
+ });
930
1088
  if (knownId)
931
1089
  remember(id);
932
1090
  return null;
@@ -938,7 +1096,9 @@ export async function runListener(options, deps) {
938
1096
  // attempt (including before the fetch even starts) targets exactly this
939
1097
  // controller, never a stale one from a previous attempt.
940
1098
  deps.onConnectionAttempt?.(() => controller.abort());
941
- deps.signal?.addEventListener("abort", () => controller.abort(), { once: true });
1099
+ deps.signal?.addEventListener("abort", () => controller.abort(), {
1100
+ once: true,
1101
+ });
942
1102
  let idle;
943
1103
  const armIdle = () => {
944
1104
  clearTimeout(idle);
@@ -957,14 +1117,26 @@ export async function runListener(options, deps) {
957
1117
  const healthy = () => gotEvent || deps.now() - openedAt >= HEALTHY_CONNECTION_MS;
958
1118
  try {
959
1119
  armIdle();
960
- const response = await deps.fetch(options.streamUrl, { headers, signal: controller.signal });
961
- if (response.status >= 400 && response.status < 500 && !RETRYABLE_CLIENT_STATUSES.has(response.status)) {
1120
+ const response = await deps.fetch(options.streamUrl, {
1121
+ headers,
1122
+ signal: controller.signal,
1123
+ });
1124
+ if (response.status >= 400 &&
1125
+ response.status < 500 &&
1126
+ !RETRYABLE_CLIENT_STATUSES.has(response.status)) {
962
1127
  const text = await response.text();
963
- return { kind: "refused", detail: `HTTP ${response.status} ${oneLine(text, 300)}` };
1128
+ return {
1129
+ kind: "refused",
1130
+ detail: `HTTP ${response.status} ${oneLine(text, 300)}`,
1131
+ };
964
1132
  }
965
1133
  if (!response.ok || response.body === null) {
966
1134
  await response.body?.cancel();
967
- return { kind: "dropped", healthy: false, detail: `HTTP ${response.status} with no readable body` };
1135
+ return {
1136
+ kind: "dropped",
1137
+ healthy: false,
1138
+ detail: `HTTP ${response.status} with no readable body`,
1139
+ };
968
1140
  }
969
1141
  // DX-6272: the stream says which relay version it needs; a relay below it reads no frame, so it cannot misread one into a line that wakes the session. A malformed floor throws (a named drop), never reads as no floor.
970
1142
  const floor = response.headers.get(MCP_STREAM_MIN_VERSION_HEADER);
@@ -996,7 +1168,11 @@ export async function runListener(options, deps) {
996
1168
  // "no healthy connection" once the lease finally expired. Preserving the
997
1169
  // message here is what lets `runListener` name the actual last failure
998
1170
  // in its final `lease_expired` stop record below.
999
- return { kind: "dropped", healthy: healthy(), detail: describeDropError(err) };
1171
+ return {
1172
+ kind: "dropped",
1173
+ healthy: healthy(),
1174
+ detail: describeDropError(err),
1175
+ };
1000
1176
  }
1001
1177
  finally {
1002
1178
  clearTimeout(idle);
@@ -1036,7 +1212,9 @@ export async function runListener(options, deps) {
1036
1212
  if (now - unhealthySince >= options.leaseMs) {
1037
1213
  // DX-2829 — names the last connection failure when one was ever recorded,
1038
1214
  // instead of only reporting the timeout itself.
1039
- const cause = lastDropDetail === null ? "" : ` — last connection attempt failed: ${lastDropDetail}`;
1215
+ const cause = lastDropDetail === null
1216
+ ? ""
1217
+ : ` — last connection attempt failed: ${lastDropDetail}`;
1040
1218
  return stop("lease_expired", `no healthy connection to ${options.streamUrl} for ${Math.round((now - unhealthySince) / 60_000)} minutes, past the ticket's lease${cause}`, 1);
1041
1219
  }
1042
1220
  await deps.sleep(Math.min(MAX_BACKOFF_MS, INITIAL_BACKOFF_MS * 2 ** attempt));