@50arms/platform-mcp 0.1.463 → 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.
- package/dist/access-request.js +19 -6
- package/dist/agent-gate.js +19 -5
- package/dist/board-id.js +8 -2
- package/dist/checkout-docs-root.js +10 -2
- package/dist/clear-control.js +18 -4
- package/dist/compaction-control.js +30 -7
- package/dist/credential.js +10 -2
- package/dist/danxbot-api-examples.js +20 -3
- package/dist/design-screenshot.js +22 -5
- package/dist/digest-hold.js +14 -3
- package/dist/docs-tools.js +46 -12
- package/dist/durable-write.js +10 -2
- package/dist/forbidden-hint.js +13 -2
- package/dist/guarded-calls.js +7 -2
- package/dist/handlers.js +70 -15
- package/dist/heartbeat-reporter.js +8 -3
- package/dist/http-client.js +5 -3
- package/dist/index.js +252 -82
- package/dist/job-key.js +47 -0
- package/dist/json-body.js +3 -1
- package/dist/key-revoked-halt.js +2 -1
- package/dist/leftover-wire.js +17 -4
- package/dist/lifecycle.js +11 -3
- package/dist/listen.js +242 -64
- package/dist/listener-reminder.js +8 -2
- package/dist/machine-daemon/autostart.js +16 -4
- package/dist/machine-daemon/beat.js +18 -4
- package/dist/machine-daemon/cli.js +15 -4
- package/dist/machine-daemon/install.js +33 -9
- package/dist/machine-daemon/leftovers.js +134 -30
- package/dist/machine-daemon/state.js +9 -3
- package/dist/machine-daemon.js +531 -128
- package/dist/machine-registration.js +27 -6
- package/dist/machine-secret.js +8 -3
- package/dist/machine-toolkit.js +377 -81
- package/dist/mini-app-build.js +19 -5
- package/dist/mini-app-checkout.js +38 -10
- package/dist/mini-app-output.js +22 -5
- package/dist/mini-app-publish.js +34 -11
- package/dist/mini-app-restore.js +30 -9
- package/dist/one-line.js +3 -1
- package/dist/permission-request.js +14 -3
- package/dist/permission-watch.js +10 -3
- package/dist/plan-events-relay.js +96 -19
- package/dist/plan-events-tool.js +9 -2
- package/dist/plugin-publish.js +23 -6
- package/dist/plugin-screenshot.js +18 -6
- package/dist/restart-notice.js +47 -15
- package/dist/result-limit.js +6 -1
- package/dist/role-instruction-file.js +16 -4
- package/dist/route-board-scope.generated.js +5 -0
- package/dist/route-board-scope.js +6 -2
- package/dist/session-access.js +114 -33
- package/dist/session-connection.js +23 -7
- package/dist/session-control-file.js +1 -1
- package/dist/session-key.js +12 -4
- package/dist/session-options.js +6 -2
- package/dist/session-stats.js +2 -1
- package/dist/session-stream.js +81 -20
- package/dist/shutdown.js +3 -1
- package/dist/subagents-live.js +8 -2
- package/dist/terms-halt.js +4 -2
- package/dist/tool-access.js +17 -4
- package/dist/tool-surface.js +9 -2
- package/dist/transcript-lineage.js +5 -2
- package/dist/urgent-records.js +1 -0
- package/package.json +1 -1
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([
|
|
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) &&
|
|
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) &&
|
|
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" &&
|
|
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)
|
|
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)
|
|
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)
|
|
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 &&
|
|
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 &&
|
|
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) &&
|
|
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) ||
|
|
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) ||
|
|
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) ||
|
|
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"
|
|
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) ||
|
|
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)
|
|
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)
|
|
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"
|
|
253
|
-
|
|
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"
|
|
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)
|
|
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
|
|
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
|
|
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) &&
|
|
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) &&
|
|
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) &&
|
|
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" ||
|
|
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 &&
|
|
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 = [
|
|
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 &&
|
|
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" ||
|
|
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) ||
|
|
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" ||
|
|
684
|
+
if (typeof value.agentInstruction !== "string" ||
|
|
685
|
+
value.agentInstruction.trim() === "")
|
|
616
686
|
return "agentInstruction is empty";
|
|
617
|
-
if (value.plan !== null &&
|
|
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 &&
|
|
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) ||
|
|
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" &&
|
|
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 &&
|
|
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) ||
|
|
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
|
|
650
|
-
|
|
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
|
|
657
|
-
|
|
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([
|
|
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 {
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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 {
|
|
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) => ({
|
|
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
|
|
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
|
|
929
|
-
|
|
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(), {
|
|
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, {
|
|
961
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
|
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));
|
|
@@ -3,7 +3,10 @@ import { readSessionConnection } from "./session-connection.js";
|
|
|
3
3
|
export const HEALTH_CACHE_WINDOW_MS = 30_000;
|
|
4
4
|
function isReminder(value) {
|
|
5
5
|
const r = value;
|
|
6
|
-
return typeof r === "object" &&
|
|
6
|
+
return (typeof r === "object" &&
|
|
7
|
+
r !== null &&
|
|
8
|
+
typeof r.key === "string" &&
|
|
9
|
+
typeof r.text === "string");
|
|
7
10
|
}
|
|
8
11
|
/** The reminders the health response carries, or a thrown Error naming why it cannot be read. */
|
|
9
12
|
function readReminders(result) {
|
|
@@ -104,7 +107,10 @@ export function createListenerReminder(deps) {
|
|
|
104
107
|
});
|
|
105
108
|
if (fresh.length === 0)
|
|
106
109
|
return result;
|
|
107
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
...result,
|
|
112
|
+
body: { ...body, reminders: [...(existing ?? []), ...fresh] },
|
|
113
|
+
};
|
|
108
114
|
},
|
|
109
115
|
invalidate() {
|
|
110
116
|
generation += 1;
|