@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.
- 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 +6 -2
- package/dist/handlers.js +66 -14
- package/dist/heartbeat-reporter.js +8 -3
- package/dist/http-client.js +4 -2
- package/dist/index.js +242 -80
- package/dist/job-key.js +3 -1
- 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.js +6 -2
- package/dist/session-access.js +110 -32
- 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
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
* mint / inventory requests are aborted by `close()`, and `close()` also clears a pending call's wait timer (the one ref'd timer,
|
|
57
57
|
* held only until the call answers). The server calls `close()` when its transport closes and when its stdin ends (`shutdown.ts`).
|
|
58
58
|
*/
|
|
59
|
-
import { fileOf, formatCompactionAskLine } from "./compaction-control.js";
|
|
60
|
-
import { clearFileOf, formatClearAskLine } from "./clear-control.js";
|
|
59
|
+
import { fileOf, formatCompactionAskLine, } from "./compaction-control.js";
|
|
60
|
+
import { clearFileOf, formatClearAskLine, } from "./clear-control.js";
|
|
61
61
|
import { DigestHold } from "./digest-hold.js";
|
|
62
62
|
import { HeartbeatReporter } from "./heartbeat-reporter.js";
|
|
63
63
|
import { capResumeIds, DELIVERED_ID_MEMORY, HEALTHY_CONNECTION_MS, INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, runListener, } from "./listen.js";
|
|
@@ -83,8 +83,13 @@ export const formatCursor = (cursor) => `${cursor.seq}:${cursor.ids.join(",")}`;
|
|
|
83
83
|
export function parseCursor(raw) {
|
|
84
84
|
const match = CURSOR_PATTERN.exec(raw);
|
|
85
85
|
const seq = match === null ? NaN : Number(match[1]);
|
|
86
|
-
const ids = match === null || match[2] === undefined
|
|
87
|
-
|
|
86
|
+
const ids = match === null || match[2] === undefined
|
|
87
|
+
? []
|
|
88
|
+
: match[2].split(",").map(Number);
|
|
89
|
+
const valid = Number.isSafeInteger(seq) &&
|
|
90
|
+
ids.length <= CURSOR_IDS_MAX &&
|
|
91
|
+
ids.every(Number.isSafeInteger) &&
|
|
92
|
+
new Set(ids).size === ids.length;
|
|
88
93
|
if (!valid) {
|
|
89
94
|
throw new Error(`plan_events_wait: cursor ${JSON.stringify(raw)} is not one this server issued (expected "<seq>:<id>,<id>,...": a whole number, a colon, then up to ${CURSOR_IDS_MAX} distinct positive event ids)`);
|
|
90
95
|
}
|
|
@@ -152,7 +157,10 @@ export class PlanEventRelay {
|
|
|
152
157
|
this.recentIds = boundedIds([...cursor.ids, ...this.recentIds]);
|
|
153
158
|
// What the caller delivered precedes every record still buffered, so each of their cursors carries it (a dropped
|
|
154
159
|
// plan-scoped record's ids were taken out of them, and the caller's own delivered ids go back in).
|
|
155
|
-
this.buffer = this.buffer.map((r) => ({
|
|
160
|
+
this.buffer = this.buffer.map((r) => ({
|
|
161
|
+
...r,
|
|
162
|
+
recent: boundedIds([...cursor.ids, ...r.recent]),
|
|
163
|
+
}));
|
|
156
164
|
}
|
|
157
165
|
this.touch();
|
|
158
166
|
this.ensureReporter(args.transcriptPath);
|
|
@@ -171,7 +179,9 @@ export class PlanEventRelay {
|
|
|
171
179
|
}
|
|
172
180
|
// DX-4233: a server holding no key answers a stop without calling the dashboard (a dispatch always holds its env key, so it never takes this branch).
|
|
173
181
|
if (this.deps.auth() === null) {
|
|
174
|
-
return {
|
|
182
|
+
return {
|
|
183
|
+
stopped: this.stopRecord("credential_unavailable", "this session holds no dashboard key"),
|
|
184
|
+
};
|
|
175
185
|
}
|
|
176
186
|
if (this.run === null)
|
|
177
187
|
this.start(cursor);
|
|
@@ -216,7 +226,14 @@ export class PlanEventRelay {
|
|
|
216
226
|
}
|
|
217
227
|
/** Everything buffered, each record with the cursor to store once it is delivered. */
|
|
218
228
|
answer() {
|
|
219
|
-
return {
|
|
229
|
+
return {
|
|
230
|
+
events: this.buffer.map(({ seq, recent, text, urgent, acks }) => ({
|
|
231
|
+
cursor: formatCursor({ seq, ids: recent }),
|
|
232
|
+
text,
|
|
233
|
+
urgent,
|
|
234
|
+
acks,
|
|
235
|
+
})),
|
|
236
|
+
};
|
|
220
237
|
}
|
|
221
238
|
// ------------------------------------------------------------------------------------------------------------ the buffer
|
|
222
239
|
/**
|
|
@@ -233,7 +250,15 @@ export class PlanEventRelay {
|
|
|
233
250
|
this.seenIds.shift();
|
|
234
251
|
}
|
|
235
252
|
this.seq += 1;
|
|
236
|
-
this.buffer.push({
|
|
253
|
+
this.buffer.push({
|
|
254
|
+
seq: this.seq,
|
|
255
|
+
own,
|
|
256
|
+
recent: [...this.recentIds],
|
|
257
|
+
text: event.text,
|
|
258
|
+
scope: event.scope ?? "plan",
|
|
259
|
+
urgent: event.urgent,
|
|
260
|
+
acks: event.acks,
|
|
261
|
+
});
|
|
237
262
|
const waiter = this.waiter;
|
|
238
263
|
if (waiter === null)
|
|
239
264
|
return;
|
|
@@ -250,7 +275,10 @@ export class PlanEventRelay {
|
|
|
250
275
|
const dropped = new Set(this.buffer.filter((r) => r.scope === "plan").flatMap((r) => r.own));
|
|
251
276
|
this.buffer = this.buffer
|
|
252
277
|
.filter((r) => r.scope === "session")
|
|
253
|
-
.map((r) => ({
|
|
278
|
+
.map((r) => ({
|
|
279
|
+
...r,
|
|
280
|
+
recent: r.recent.filter((id) => !dropped.has(id)),
|
|
281
|
+
}));
|
|
254
282
|
this.recentIds = this.recentIds.filter((id) => !dropped.has(id));
|
|
255
283
|
// DX-4233: `seenIds` (the listener's duplicate guard for a re-mint on the SAME run) deliberately keeps them. A plan move's
|
|
256
284
|
// dropped events belong to a plan the session left, and the dashboard replays only the session's current plan, so nothing
|
|
@@ -271,7 +299,10 @@ export class PlanEventRelay {
|
|
|
271
299
|
const auth = this.deps.auth();
|
|
272
300
|
if (planId === null || run === null || auth === null)
|
|
273
301
|
return;
|
|
274
|
-
void this.readInventory(run, auth, {
|
|
302
|
+
void this.readInventory(run, auth, {
|
|
303
|
+
...this.deps,
|
|
304
|
+
signal: run.abort.signal,
|
|
305
|
+
});
|
|
275
306
|
}
|
|
276
307
|
/** The inventory is a property of the credential and the plan: read best effort, never a gate; a failed read is reported on the heartbeat (`inventory: unavailable`) and tried again at the next re-mint. */
|
|
277
308
|
async readInventory(run, auth, http) {
|
|
@@ -307,7 +338,15 @@ export class PlanEventRelay {
|
|
|
307
338
|
connection: () => heartbeatConnection(this.connectionState, this.stoppedReason, this.lastInventoryError),
|
|
308
339
|
streaming: () => this.connectionState === "streaming",
|
|
309
340
|
// `origin: null` skips the agent/machine hold: the notice reaches the session at once. It is about the session, not a plan.
|
|
310
|
-
announce: (text, source) => this.digest.route({
|
|
341
|
+
announce: (text, source) => this.digest.route({
|
|
342
|
+
type: "event",
|
|
343
|
+
id: null,
|
|
344
|
+
text,
|
|
345
|
+
origin: null,
|
|
346
|
+
scope: "session",
|
|
347
|
+
urgent: isUrgent({ source }),
|
|
348
|
+
acks: [],
|
|
349
|
+
}),
|
|
311
350
|
forceReconnect: () => this.run?.forceReconnect?.(),
|
|
312
351
|
}, transcriptPath ?? null);
|
|
313
352
|
}
|
|
@@ -330,7 +369,8 @@ export class PlanEventRelay {
|
|
|
330
369
|
}
|
|
331
370
|
heartbeatTick() {
|
|
332
371
|
// DX-4233: a pending call keeps the relay alive however long it waits; only a gap with no call at all suspends it.
|
|
333
|
-
if (this.waiter === null &&
|
|
372
|
+
if (this.waiter === null &&
|
|
373
|
+
this.deps.now() - this.lastActivityAt > HEARTBEAT_ACTIVITY_WINDOW_MS) {
|
|
334
374
|
// Nobody is reading this session's events any more: stop heartbeating (the dashboard then reads the listener not
|
|
335
375
|
// healthy) and let go of the stream. The next call starts it again from its cursor; the dashboard replays what it missed.
|
|
336
376
|
void this.suspend();
|
|
@@ -387,7 +427,10 @@ export class PlanEventRelay {
|
|
|
387
427
|
start(cursor) {
|
|
388
428
|
// The listener's duplicate guard starts with every event the caller was handed and everything still buffered: the dashboard
|
|
389
429
|
// replays its 30 s overlap before the highest of them, so a replayed one is dropped and a never-delivered one is delivered.
|
|
390
|
-
this.seenIds = capResumeIds([
|
|
430
|
+
this.seenIds = capResumeIds([
|
|
431
|
+
...(cursor?.ids ?? []),
|
|
432
|
+
...this.buffer.flatMap((r) => r.own),
|
|
433
|
+
]);
|
|
391
434
|
this.stoppedReason = null;
|
|
392
435
|
this.inventoryRead = false;
|
|
393
436
|
const run = { abort: new AbortController(), forceReconnect: null };
|
|
@@ -401,11 +444,25 @@ export class PlanEventRelay {
|
|
|
401
444
|
}
|
|
402
445
|
/** DX-4993: the compaction control's file, ask line and fault wording. */
|
|
403
446
|
compactionKind() {
|
|
404
|
-
return {
|
|
447
|
+
return {
|
|
448
|
+
files: this.deps.compactionFiles,
|
|
449
|
+
fileOf,
|
|
450
|
+
askLine: formatCompactionAskLine,
|
|
451
|
+
askSource: { source: "compaction_ask" },
|
|
452
|
+
what: "compaction control",
|
|
453
|
+
faultEffect: "so its compaction gate cannot work",
|
|
454
|
+
};
|
|
405
455
|
}
|
|
406
456
|
/** DX-6692: the clear control's file, ask line and fault wording. */
|
|
407
457
|
clearKind() {
|
|
408
|
-
return {
|
|
458
|
+
return {
|
|
459
|
+
files: this.deps.clearFiles,
|
|
460
|
+
fileOf: clearFileOf,
|
|
461
|
+
askLine: formatClearAskLine,
|
|
462
|
+
askSource: { source: "clear_ask" },
|
|
463
|
+
what: "clear control",
|
|
464
|
+
faultEffect: "so the ready loop cannot see an agreed clear",
|
|
465
|
+
};
|
|
409
466
|
}
|
|
410
467
|
/**
|
|
411
468
|
* DX-4993 / DX-6692 - a control (compaction, clear) arrived: show the agent an ask it has not been shown, and write the file the plugin reads. A control with a new ask (`ask.at`) is
|
|
@@ -434,12 +491,28 @@ export class PlanEventRelay {
|
|
|
434
491
|
if (unreadable !== null)
|
|
435
492
|
process.stderr.write(`plan_events_wait: the ${kind.what} file of session ${auth.sessionId} could not be read (${unreadable}); it was replaced\n`);
|
|
436
493
|
if (show) {
|
|
437
|
-
this.digest.route({
|
|
494
|
+
this.digest.route({
|
|
495
|
+
type: "event",
|
|
496
|
+
id: null,
|
|
497
|
+
text: kind.askLine(ask),
|
|
498
|
+
origin: null,
|
|
499
|
+
urgent: isUrgent(kind.askSource),
|
|
500
|
+
acks: [],
|
|
501
|
+
scope: "session",
|
|
502
|
+
});
|
|
438
503
|
}
|
|
439
504
|
}
|
|
440
505
|
catch (err) {
|
|
441
506
|
const detail = err instanceof Error ? err.message : String(err);
|
|
442
|
-
this.digest.route({
|
|
507
|
+
this.digest.route({
|
|
508
|
+
type: "event",
|
|
509
|
+
id: null,
|
|
510
|
+
text: `${LINE_PREFIX} the ${kind.what} could not be kept for this session (${detail}), ${kind.faultEffect}`,
|
|
511
|
+
origin: null,
|
|
512
|
+
urgent: isUrgent({ source: "fault" }),
|
|
513
|
+
acks: [],
|
|
514
|
+
scope: "session",
|
|
515
|
+
});
|
|
443
516
|
}
|
|
444
517
|
}
|
|
445
518
|
current(run) {
|
|
@@ -498,7 +571,10 @@ export class PlanEventRelay {
|
|
|
498
571
|
return;
|
|
499
572
|
}
|
|
500
573
|
backoff = INITIAL_BACKOFF_MS;
|
|
501
|
-
const attempt = {
|
|
574
|
+
const attempt = {
|
|
575
|
+
stopped: null,
|
|
576
|
+
emitted: false,
|
|
577
|
+
};
|
|
502
578
|
const startedAt = this.deps.now();
|
|
503
579
|
await runListener({
|
|
504
580
|
streamUrl: minted.streamUrl,
|
|
@@ -559,7 +635,8 @@ export class PlanEventRelay {
|
|
|
559
635
|
continue;
|
|
560
636
|
}
|
|
561
637
|
if (stopped.reason === "refused") {
|
|
562
|
-
const provedHealthy = attempt.emitted ||
|
|
638
|
+
const provedHealthy = attempt.emitted ||
|
|
639
|
+
this.deps.now() - startedAt >= HEALTHY_CONNECTION_MS;
|
|
563
640
|
refusedInRow = provedHealthy ? 1 : refusedInRow + 1;
|
|
564
641
|
if (refusedInRow >= MAX_REFUSED_TICKETS_IN_A_ROW) {
|
|
565
642
|
return this.terminal(run, "refused", `${stopped.detail} (a freshly minted ticket was refused ${refusedInRow} times in a row)`);
|
package/dist/plan-events-tool.js
CHANGED
|
@@ -4,6 +4,13 @@ import { checkedTranscriptPath } from "./session-stats.js";
|
|
|
4
4
|
* and a cancelled request (`signal`, the SDK's `extra.signal`) drops the pending wait. A malformed cursor is refused by the relay.
|
|
5
5
|
*/
|
|
6
6
|
export function servePlanEventsWait(relay, args, signal) {
|
|
7
|
-
const transcriptPath = args.transcript_path === undefined
|
|
8
|
-
|
|
7
|
+
const transcriptPath = args.transcript_path === undefined
|
|
8
|
+
? undefined
|
|
9
|
+
: checkedTranscriptPath(args.transcript_path, "plan_events_wait transcript_path");
|
|
10
|
+
return relay.wait({
|
|
11
|
+
planId: args.plan_id,
|
|
12
|
+
cursor: args.cursor,
|
|
13
|
+
timeoutMs: args.timeout_ms,
|
|
14
|
+
transcriptPath,
|
|
15
|
+
}, signal);
|
|
9
16
|
}
|
package/dist/plugin-publish.js
CHANGED
|
@@ -11,19 +11,26 @@
|
|
|
11
11
|
* screenshot, and only then the upload. The dashboard is the only validator; its refusal comes back verbatim with the step it refused.
|
|
12
12
|
*/
|
|
13
13
|
import path from "node:path";
|
|
14
|
-
import { archiveSource, assertNote, buildPlugin, uploadRevision, withScreenshot } from "@50arms/plugin-sdk/publish";
|
|
14
|
+
import { archiveSource, assertNote, buildPlugin, uploadRevision, withScreenshot, } from "@50arms/plugin-sdk/publish";
|
|
15
15
|
import { capturePluginRender } from "./plugin-screenshot.js";
|
|
16
16
|
/** The agent's authenticated dashboard client as the publish flow's transport. */
|
|
17
17
|
function clientTransport(client) {
|
|
18
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
request: ({ method, path: route, query, body }) => client.request({ method, path: route, basePath: "", query, body }),
|
|
20
|
+
};
|
|
19
21
|
}
|
|
20
22
|
export async function pluginPublish(client, args, deps) {
|
|
21
23
|
assertNote(args.note);
|
|
22
24
|
const projectDir = path.resolve(deps.cwd, args.dir);
|
|
23
25
|
const built = await buildPlugin(projectDir);
|
|
24
26
|
const source = await archiveSource(projectDir);
|
|
25
|
-
const shot = await capturePluginRender(built, deps.baseUrl, {
|
|
26
|
-
|
|
27
|
+
const shot = await capturePluginRender(built, deps.baseUrl, {
|
|
28
|
+
rootAbs: projectDir,
|
|
29
|
+
cwd: deps.cwd,
|
|
30
|
+
});
|
|
31
|
+
const toUpload = shot.png_base64 === null
|
|
32
|
+
? built
|
|
33
|
+
: withScreenshot(built, Buffer.from(shot.png_base64, "base64"));
|
|
27
34
|
const result = await uploadRevision(clientTransport(client), {
|
|
28
35
|
plugin: args.plugin,
|
|
29
36
|
name: args.name,
|
|
@@ -33,6 +40,16 @@ export async function pluginPublish(client, args, deps) {
|
|
|
33
40
|
dashboardUrl: deps.baseUrl,
|
|
34
41
|
});
|
|
35
42
|
if (!result.ok)
|
|
36
|
-
return {
|
|
37
|
-
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
status: result.status,
|
|
46
|
+
body: result.body,
|
|
47
|
+
plugin: args.plugin,
|
|
48
|
+
step: result.step,
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
ok: true,
|
|
52
|
+
status: result.status,
|
|
53
|
+
body: { ...result.body, screenshot: shot.screenshot },
|
|
54
|
+
};
|
|
38
55
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { captureWith } from "./design-screenshot.js";
|
|
1
|
+
import { captureWith, } from "./design-screenshot.js";
|
|
2
2
|
/** The route the app draws the plugin on, the prefix its files are requested under, the window global it is handed the manifest on, and the attribute the page reports through: restated from `frontend/src/lib/plugin-preview-contract.ts` (this package cannot import the app); `src/dispatch/design-publish-restated-constants.test.ts` ties them. */
|
|
3
3
|
export const PLUGIN_PREVIEW_ROUTE = "/plugin-preview";
|
|
4
4
|
export const PLUGIN_PREVIEW_FILES = "/__plugin-preview__/";
|
|
@@ -28,7 +28,7 @@ export const CONTENT_TYPES = {
|
|
|
28
28
|
woff2: "font/woff2",
|
|
29
29
|
};
|
|
30
30
|
function contentTypeOf(filePath) {
|
|
31
|
-
return CONTENT_TYPES[filePath.slice(filePath.lastIndexOf(".") + 1).toLowerCase()] ?? "application/octet-stream";
|
|
31
|
+
return (CONTENT_TYPES[filePath.slice(filePath.lastIndexOf(".") + 1).toLowerCase()] ?? "application/octet-stream");
|
|
32
32
|
}
|
|
33
33
|
/** The build's files by path. Only what the build listed can be requested. */
|
|
34
34
|
function servedFiles(built) {
|
|
@@ -45,10 +45,18 @@ async function answer(route, prefix, served) {
|
|
|
45
45
|
}
|
|
46
46
|
const bytes = served.get(requested);
|
|
47
47
|
if (bytes === undefined) {
|
|
48
|
-
await route.fulfill({
|
|
48
|
+
await route.fulfill({
|
|
49
|
+
status: 404,
|
|
50
|
+
contentType: "text/plain",
|
|
51
|
+
body: `no such plugin file: ${pathname}`,
|
|
52
|
+
});
|
|
49
53
|
return;
|
|
50
54
|
}
|
|
51
|
-
await route.fulfill({
|
|
55
|
+
await route.fulfill({
|
|
56
|
+
status: 200,
|
|
57
|
+
contentType: contentTypeOf(pathname),
|
|
58
|
+
body: bytes,
|
|
59
|
+
});
|
|
52
60
|
}
|
|
53
61
|
const REPORT_EXPRESSION = `(() => { const el = document.querySelector("[${PLUGIN_PREVIEW_ATTRIBUTE}]"); return { state: el ? el.getAttribute("${PLUGIN_PREVIEW_ATTRIBUTE}") : null, text: el ? el.textContent : "" }; })()`;
|
|
54
62
|
/** Settled: the page said `ready` or `failed`, and nothing on it is still loading (`aria-busy`). */
|
|
@@ -63,12 +71,16 @@ export async function capturePluginRender(built, dashboardUrl, where) {
|
|
|
63
71
|
return captureWith(where, false, async (page) => {
|
|
64
72
|
await page.addInitScript(`window[${JSON.stringify(PLUGIN_PREVIEW_MANIFEST_GLOBAL)}] = ${JSON.stringify({ entry: built.manifest.entry, styles: built.manifest.styles, runtime: built.manifest.runtime, mode: previewModeOf(built.manifest.exports) })};`);
|
|
65
73
|
await page.route(`${origin}${PLUGIN_PREVIEW_FILES}**`, (route) => answer(route, PLUGIN_PREVIEW_FILES, served));
|
|
66
|
-
const response = await page.goto(`${origin}${PLUGIN_PREVIEW_ROUTE}`, {
|
|
74
|
+
const response = await page.goto(`${origin}${PLUGIN_PREVIEW_ROUTE}`, {
|
|
75
|
+
waitUntil: "load",
|
|
76
|
+
});
|
|
67
77
|
const status = response?.status();
|
|
68
78
|
if (status !== undefined && (status < 200 || status > 299))
|
|
69
79
|
return `the dashboard answered ${status} for its ${PLUGIN_PREVIEW_ROUTE} page; a dashboard older than this tool does not serve it`;
|
|
70
80
|
try {
|
|
71
|
-
await page.waitForFunction(SETTLED_EXPRESSION, undefined, {
|
|
81
|
+
await page.waitForFunction(SETTLED_EXPRESSION, undefined, {
|
|
82
|
+
timeout: RENDER_WAIT_MS,
|
|
83
|
+
});
|
|
72
84
|
}
|
|
73
85
|
catch {
|
|
74
86
|
const report = await page.evaluate(REPORT_EXPRESSION);
|
package/dist/restart-notice.js
CHANGED
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
*/
|
|
43
43
|
import { z } from "zod";
|
|
44
44
|
import { boundRequest } from "./request-bound.js";
|
|
45
|
-
import { PLUGIN_BACKGROUND_HEADER, resolveDashboardAuth, SESSION_ID_HEADER, SessionStartError } from "./session-options.js";
|
|
46
|
-
import { findPredecessorCandidates, projectKeyOf, readSessionConnection } from "./session-connection.js";
|
|
45
|
+
import { PLUGIN_BACKGROUND_HEADER, resolveDashboardAuth, SESSION_ID_HEADER, SessionStartError, } from "./session-options.js";
|
|
46
|
+
import { findPredecessorCandidates, projectKeyOf, readSessionConnection, } from "./session-connection.js";
|
|
47
47
|
import { checkedTranscriptPath } from "./session-stats.js";
|
|
48
|
-
import { readTranscriptLineage, TranscriptReadAborted, TranscriptUnreadable } from "./transcript-lineage.js";
|
|
48
|
+
import { readTranscriptLineage, TranscriptReadAborted, TranscriptUnreadable, } from "./transcript-lineage.js";
|
|
49
49
|
import { fixForStop } from "./stop-fixes.js";
|
|
50
50
|
/**
|
|
51
51
|
* One authenticated HTTP call to this session's dashboard, with a hard
|
|
@@ -62,7 +62,9 @@ export async function sendSessionRequest(options, path, init, deps) {
|
|
|
62
62
|
headers: {
|
|
63
63
|
Authorization: `Bearer ${options.token}`,
|
|
64
64
|
Accept: "application/json",
|
|
65
|
-
...(init.body !== undefined
|
|
65
|
+
...(init.body !== undefined
|
|
66
|
+
? { "Content-Type": "application/json" }
|
|
67
|
+
: {}),
|
|
66
68
|
[SESSION_ID_HEADER]: options.sessionId,
|
|
67
69
|
// DX-5354: the session-start hook's lookup is the plugin's own work, never the agent acting, so it does not extend the session's key.
|
|
68
70
|
[PLUGIN_BACKGROUND_HEADER]: "1",
|
|
@@ -77,7 +79,10 @@ export async function sendSessionRequest(options, path, init, deps) {
|
|
|
77
79
|
// DX-3367 fix-up — the caught value is never inspected (an aborted
|
|
78
80
|
// fetch's own rejection shape varies by runtime), so binding it to a
|
|
79
81
|
// name the code never reads was dead weight the linter never caught.
|
|
80
|
-
return {
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
reason: bound.aborted() ? "timeout" : "request_failed",
|
|
85
|
+
};
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
finally {
|
|
@@ -109,7 +114,11 @@ export const RESTART_NOTICE_REMINDER_KEY = "plan_restart.waiting_events";
|
|
|
109
114
|
/** One authenticated GET (`sendSessionRequest` above, so its bound and its failure names are the same), answering the notice text or `null`. */
|
|
110
115
|
export async function fetchRestartNotice(target, deps) {
|
|
111
116
|
// The bearer is the predecessor's; the session id header names the ASKING session.
|
|
112
|
-
const auth = {
|
|
117
|
+
const auth = {
|
|
118
|
+
dashboardUrl: target.dashboardUrl,
|
|
119
|
+
token: target.token,
|
|
120
|
+
sessionId: target.askingSessionId,
|
|
121
|
+
};
|
|
113
122
|
const sent = await sendSessionRequest(auth, `/api/plan-sessions/${encodeURIComponent(target.predecessorId)}/restart-notice${target.named === true ? "?named=1" : ""}`, { method: "GET" }, deps);
|
|
114
123
|
if ("ok" in sent)
|
|
115
124
|
return { ok: false, reason: sent.reason };
|
|
@@ -121,14 +130,18 @@ export async function fetchRestartNotice(target, deps) {
|
|
|
121
130
|
if (status < 200 || status >= 300)
|
|
122
131
|
return { ok: false, reason: "http_error" };
|
|
123
132
|
const parsed = tryParseJsonBody(text);
|
|
124
|
-
const body = parsed.ok
|
|
133
|
+
const body = parsed.ok
|
|
134
|
+
? parsed.body
|
|
135
|
+
: null;
|
|
125
136
|
if (typeof body !== "object" || body === null || !("restart" in body))
|
|
126
137
|
return { ok: false, reason: "bad_response" };
|
|
127
138
|
if (body.restart === null)
|
|
128
139
|
return { ok: true, text: null };
|
|
129
140
|
// A notice exists, so the registry row MUST have answered with its text: a
|
|
130
141
|
// missing one is a server/registry fault, reported rather than papered over.
|
|
131
|
-
const reminders = Array.isArray(body.reminders)
|
|
142
|
+
const reminders = Array.isArray(body.reminders)
|
|
143
|
+
? body.reminders
|
|
144
|
+
: [];
|
|
132
145
|
const notice = reminders.find((r) => r.key === RESTART_NOTICE_REMINDER_KEY);
|
|
133
146
|
if (typeof notice?.text !== "string" || notice.text === "")
|
|
134
147
|
return { ok: false, reason: "bad_response" };
|
|
@@ -147,7 +160,9 @@ export const RESTART_NOTICE_ARGS = {
|
|
|
147
160
|
.optional()
|
|
148
161
|
.describe("Absolute path of this session's transcript (.jsonl file): a forked session's copied rows name the session it was forked from."),
|
|
149
162
|
};
|
|
150
|
-
const stop = (reason, detail) => ({
|
|
163
|
+
const stop = (reason, detail) => ({
|
|
164
|
+
stopped: { reason, detail, fix: fixForStop(reason) },
|
|
165
|
+
});
|
|
151
166
|
/**
|
|
152
167
|
* DX-4234 - the module docblock's precedence: a named id, else the transcript's lineage, else the project scan. Throws
|
|
153
168
|
* `TranscriptReadAborted` when the deadline fires mid-read; every other failure is an answer.
|
|
@@ -165,7 +180,10 @@ async function choosePredecessors(lookup, ownId, signal) {
|
|
|
165
180
|
}
|
|
166
181
|
let lineage;
|
|
167
182
|
try {
|
|
168
|
-
lineage = await readTranscriptLineage(path, ownId, {
|
|
183
|
+
lineage = await readTranscriptLineage(path, ownId, {
|
|
184
|
+
signal,
|
|
185
|
+
open: lookup.openTranscript,
|
|
186
|
+
});
|
|
169
187
|
}
|
|
170
188
|
catch (err) {
|
|
171
189
|
if (err instanceof TranscriptUnreadable)
|
|
@@ -178,22 +196,32 @@ async function choosePredecessors(lookup, ownId, signal) {
|
|
|
178
196
|
namedBy = "transcript_path";
|
|
179
197
|
}
|
|
180
198
|
if (namedId === undefined) {
|
|
181
|
-
const found = findPredecessorCandidates(projectKeyOf(lookup.cwd), ownId, {
|
|
182
|
-
|
|
199
|
+
const found = findPredecessorCandidates(projectKeyOf(lookup.cwd), ownId, {
|
|
200
|
+
home: lookup.home,
|
|
201
|
+
now: lookup.now,
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
candidates: found.slice(0, RESTART_NOTICE_MAX_CANDIDATES),
|
|
205
|
+
named: false,
|
|
206
|
+
};
|
|
183
207
|
}
|
|
184
208
|
let record;
|
|
185
209
|
try {
|
|
186
210
|
record = readSessionConnection(namedId, { home: lookup.home });
|
|
187
211
|
}
|
|
188
212
|
catch (err) {
|
|
189
|
-
return {
|
|
213
|
+
return {
|
|
214
|
+
answer: stop("no_predecessor_record", `session ${namedId} (${namedBy}) has no usable dashboard connection record: ${err.message}`),
|
|
215
|
+
};
|
|
190
216
|
}
|
|
191
217
|
if (record === null) {
|
|
192
218
|
// A parent found through the transcript that never connected a plan has nothing to tell; an id the caller NAMED that has
|
|
193
219
|
// no record is something the caller must hear about.
|
|
194
220
|
if (namedBy === "transcript_path")
|
|
195
221
|
return { answer: { notice: null } };
|
|
196
|
-
return {
|
|
222
|
+
return {
|
|
223
|
+
answer: stop("no_predecessor_record", `session ${namedId} (${namedBy}) has no dashboard connection record on this machine`),
|
|
224
|
+
};
|
|
197
225
|
}
|
|
198
226
|
return { candidates: [record], named: true };
|
|
199
227
|
}
|
|
@@ -243,7 +271,11 @@ export async function lookupRestartNotice(lookup) {
|
|
|
243
271
|
predecessorId: predecessor.sessionId,
|
|
244
272
|
askingSessionId: ownId,
|
|
245
273
|
named,
|
|
246
|
-
}, {
|
|
274
|
+
}, {
|
|
275
|
+
fetch: lookup.fetch,
|
|
276
|
+
requestTimeoutMs: lookup.requestTimeoutMs ?? RESTART_NOTICE_REQUEST_TIMEOUT_MS,
|
|
277
|
+
signal: deadline.signal,
|
|
278
|
+
});
|
|
247
279
|
// A notice the dashboard fully answered is kept even when the deadline fired right after it; every other outcome of a
|
|
248
280
|
// deadline that passed is the stop below (this is the lookup's one deadline check).
|
|
249
281
|
if (output.ok && output.text !== null)
|
package/dist/result-limit.js
CHANGED
|
@@ -26,6 +26,11 @@ export function boundedResultText(result, deps = {}) {
|
|
|
26
26
|
return JSON.stringify({
|
|
27
27
|
ok: result.ok,
|
|
28
28
|
status: result.status,
|
|
29
|
-
reply_file: {
|
|
29
|
+
reply_file: {
|
|
30
|
+
path: file,
|
|
31
|
+
bytes: Buffer.byteLength(body, "utf8"),
|
|
32
|
+
chars: body.length,
|
|
33
|
+
instruction: FILE_INSTRUCTION,
|
|
34
|
+
},
|
|
30
35
|
});
|
|
31
36
|
}
|
|
@@ -20,17 +20,29 @@ const PROFILE_NAME = /^[a-z][a-z0-9-]*$/;
|
|
|
20
20
|
*/
|
|
21
21
|
export function spillRoleInstruction(result, deps = {}) {
|
|
22
22
|
const body = result.body;
|
|
23
|
-
if (typeof body !== "object" ||
|
|
23
|
+
if (typeof body !== "object" ||
|
|
24
|
+
body === null ||
|
|
25
|
+
!Object.hasOwn(body, "roleInstruction"))
|
|
24
26
|
return result;
|
|
25
27
|
const role = body.roleInstruction;
|
|
26
28
|
if (role === null)
|
|
27
29
|
return result;
|
|
28
30
|
const { profile, text } = (role ?? {});
|
|
29
|
-
if (typeof profile !== "string" ||
|
|
31
|
+
if (typeof profile !== "string" ||
|
|
32
|
+
!PROFILE_NAME.test(profile) ||
|
|
33
|
+
typeof text !== "string") {
|
|
30
34
|
throw new Error(`the dashboard answered a roleInstruction that is not {profile, text}: ${JSON.stringify(role).slice(0, 200)}`);
|
|
31
35
|
}
|
|
32
36
|
const file = path.join(deps.tmpDir ?? os.tmpdir(), "danx-role", `${profile}-${createHash("sha256").update(text).digest("hex").slice(0, 16)}.md`);
|
|
33
37
|
writeFileDurable(file, text);
|
|
34
|
-
const spilled = {
|
|
35
|
-
|
|
38
|
+
const spilled = {
|
|
39
|
+
profile,
|
|
40
|
+
path: file,
|
|
41
|
+
bytes: Buffer.byteLength(text, "utf8"),
|
|
42
|
+
instruction: ROLE_FILE_INSTRUCTION,
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
...result,
|
|
46
|
+
body: { ...body, roleInstruction: spilled },
|
|
47
|
+
};
|
|
36
48
|
}
|
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
* Only GET routes are listed - the server refuses an unknown query key on a read alone - so every other method takes the key. A
|
|
12
12
|
* GET path no template matches takes it too: the server answers it with a 404 whatever the query.
|
|
13
13
|
*/
|
|
14
|
-
import { BODY_BOARD_ROUTES, GET_ROUTE_BOARD_SCOPE } from "./route-board-scope.generated.js";
|
|
14
|
+
import { BODY_BOARD_ROUTES, GET_ROUTE_BOARD_SCOPE, } from "./route-board-scope.generated.js";
|
|
15
15
|
const RANK = { literal: 2, param: 1, rest: 0 };
|
|
16
16
|
function compile(template, stamp) {
|
|
17
17
|
const segments = template
|
|
18
18
|
.slice(1)
|
|
19
19
|
.split("/")
|
|
20
|
-
.map((s) =>
|
|
20
|
+
.map((s) => s === "*"
|
|
21
|
+
? { kind: "rest" }
|
|
22
|
+
: s.startsWith(":")
|
|
23
|
+
? { kind: "param" }
|
|
24
|
+
: { kind: "literal", value: s });
|
|
21
25
|
return { segments, rank: segments.map((s) => RANK[s.kind]), stamp };
|
|
22
26
|
}
|
|
23
27
|
function compareRank(a, b) {
|