@50arms/platform-mcp 0.1.576 → 0.1.578
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/http-client.js +40 -4
- package/dist/index.js +9 -12
- package/dist/listen.js +2 -7
- package/dist/listener-reminder.js +13 -0
- package/dist/machine-toolkit.js +1 -1
- package/dist/reply-files.js +35 -9
- package/dist/reply-reminders-header.js +25 -0
- package/dist/result-limit.js +2 -2
- package/dist/route-board-scope.generated.js +1 -0
- package/package.json +1 -1
- package/dist/role-instruction-file.js +0 -47
package/dist/http-client.js
CHANGED
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
*/
|
|
59
59
|
import { appVersionOf } from "./app-version.js";
|
|
60
60
|
import { BEHAVIOR_SIGNOFFS_HEADER } from "./behavior-signoffs.js";
|
|
61
|
+
import { mergeReminders } from "./listener-reminder.js";
|
|
62
|
+
import { replyRemindersOf } from "./reply-reminders-header.js";
|
|
61
63
|
import { boardStampOf, isReadRoute, takesBoardInBody, } from "./route-board-scope.js";
|
|
62
64
|
import { assertVersionFloorSatisfied, clientVersionHeaders, MCP_MIN_VERSION_HEADER, } from "./version-floor.js";
|
|
63
65
|
import { PLUGIN_BACKGROUND_HEADER } from "./session-options.js";
|
|
@@ -105,6 +107,21 @@ function describeFailure(err) {
|
|
|
105
107
|
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
106
108
|
return `${err.message}${cause}`;
|
|
107
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* DX-8178 - whether an answer has no JSON body, decided by its status and its Content-Type, never by what headers the dashboard added: any 3xx (handed over with its `location`), a body-less
|
|
112
|
+
* 204, and a Content-Type that is present and is not JSON (`application/json` or `+json`).
|
|
113
|
+
*/
|
|
114
|
+
function isNonJsonAnswer(status, headers) {
|
|
115
|
+
if ((status >= 300 && status < 400) || status === 204)
|
|
116
|
+
return true;
|
|
117
|
+
const type = (headers.get("content-type") ?? "")
|
|
118
|
+
.split(";")[0]
|
|
119
|
+
.trim()
|
|
120
|
+
.toLowerCase();
|
|
121
|
+
return !(type === "" ||
|
|
122
|
+
type === "application/json" ||
|
|
123
|
+
type.endsWith("+json"));
|
|
124
|
+
}
|
|
108
125
|
/** Whether an attempt got the dashboard's own answer, was told to come back (it is up, and busy), or got none. */
|
|
109
126
|
function verdictOf(attempt) {
|
|
110
127
|
if (attempt.kind === "failed")
|
|
@@ -272,6 +289,8 @@ export class DashboardHttpClient {
|
|
|
272
289
|
headers: init.headers,
|
|
273
290
|
body: init.body,
|
|
274
291
|
signal: bound.signal,
|
|
292
|
+
// DX-8178: a 3xx is the route's answer (an attachment's signed URL), handed to the agent with its `location`, never followed.
|
|
293
|
+
redirect: "manual",
|
|
275
294
|
});
|
|
276
295
|
return {
|
|
277
296
|
kind: "response",
|
|
@@ -340,8 +359,15 @@ export class DashboardHttpClient {
|
|
|
340
359
|
if (res.status >= 500) {
|
|
341
360
|
throw new DashboardServerError(`[platform-mcp] server error ${res.status} on ${method} ${url}: ${text.slice(0, 500)}`, { status: res.status, write, text: text.slice(0, 500) });
|
|
342
361
|
}
|
|
362
|
+
// DX-8178: the reply policy of every answer rides the header `X-Danx-Reply-Reminders`; a JSON answer also has its body's `reminders[]`, a non-JSON one has only this.
|
|
363
|
+
const headerReminders = replyRemindersOf(res.headers);
|
|
364
|
+
const redirected = res.status >= 300 && res.status < 400;
|
|
365
|
+
const jsonBody = !isNonJsonAnswer(res.status, res.headers);
|
|
366
|
+
// A non-JSON refusal (a 4xx that is not JSON) is a server-side fault as before: fail loud with its text. The envelope below is for a 3xx, a 204 or a download.
|
|
367
|
+
if (!jsonBody && res.status >= 400)
|
|
368
|
+
throw new Error(`[platform-mcp] non-JSON response (status ${res.status}) from ${method} ${url}: ${text.slice(0, 200)}`);
|
|
343
369
|
let parsed = null;
|
|
344
|
-
if (text !== "") {
|
|
370
|
+
if (jsonBody && text !== "") {
|
|
345
371
|
try {
|
|
346
372
|
parsed = JSON.parse(text);
|
|
347
373
|
}
|
|
@@ -354,10 +380,20 @@ export class DashboardHttpClient {
|
|
|
354
380
|
// DX-7767: the plugin sees no HTTP headers, so the app version rides the envelope.
|
|
355
381
|
const appVersion = appVersionOf(res.headers);
|
|
356
382
|
const version = appVersion === undefined ? {} : { app_version: appVersion };
|
|
357
|
-
|
|
358
|
-
|
|
383
|
+
const ok = res.status >= 200 && res.status < 400;
|
|
384
|
+
if (!jsonBody) {
|
|
385
|
+
const location = res.headers.get("location");
|
|
386
|
+
return {
|
|
387
|
+
ok,
|
|
388
|
+
status: res.status,
|
|
389
|
+
...version,
|
|
390
|
+
body: null,
|
|
391
|
+
reminders: headerReminders,
|
|
392
|
+
...(redirected && location !== null ? { location } : {}),
|
|
393
|
+
};
|
|
359
394
|
}
|
|
360
|
-
|
|
395
|
+
const answer = { ok, status: res.status, ...version, body: parsed };
|
|
396
|
+
return mergeReminders(answer, headerReminders);
|
|
361
397
|
}
|
|
362
398
|
/**
|
|
363
399
|
* DX-7110 - one `GET /health` attempt, for the reachability ping: whether 50 Arms answered healthy. The probe is public (no bearer) and
|
package/dist/index.js
CHANGED
|
@@ -106,7 +106,6 @@ import { miniAppPublish } from "./mini-app-publish.js";
|
|
|
106
106
|
import { miniAppRestore } from "./mini-app-restore.js";
|
|
107
107
|
import { pluginPublish } from "./plugin-publish.js";
|
|
108
108
|
import { docsRead, docsSearch, docsSourceShape } from "./docs-tools.js";
|
|
109
|
-
import { spillRoleInstruction } from "./role-instruction-file.js";
|
|
110
109
|
import { removeStaleReplyFiles } from "./reply-files.js";
|
|
111
110
|
import { DEFAULT_LIMIT, MAX_SEARCH_LIMIT } from "@50arms/docs/agent";
|
|
112
111
|
import { boundedResultText } from "./result-limit.js";
|
|
@@ -649,12 +648,13 @@ const boardField = {
|
|
|
649
648
|
renamedTool("50arms_api",
|
|
650
649
|
// DX-3997 — `reminders[]` also relays the dashboard's own listener reminder
|
|
651
650
|
// to a plan-connected session; the reminder's text explains itself.
|
|
652
|
-
|
|
651
|
+
// DX-8178: a route that answers other than JSON (a redirect, a file, an image, a text download) has `body: null` and `reminders` at the top level; a redirect is never followed.
|
|
652
|
+
"Call any dashboard API route your credential may reach. The answer is the route's JSON body (non-JSON: `body: null`): act on its " +
|
|
653
653
|
"`reminders[]` when present. " +
|
|
654
654
|
// DX-4015 / DX-4525 — narrows SERVER_INSTRUCTIONS' general spec-first rule: a write shown below is
|
|
655
655
|
// copied from its example (3 of 3 canary sessions did, with zero 4xx), so only a write NOT shown, and
|
|
656
656
|
// always the retro, needs a spec call first.
|
|
657
|
-
"Before
|
|
657
|
+
"Before a write to a route not shown below, and always before `PUT /api/issues/:id/retro`, " +
|
|
658
658
|
"call `50arms_api_spec`. " +
|
|
659
659
|
// DX-3923 — the shapes agents guessed wrong most often, shown before the
|
|
660
660
|
// first call instead of learned from a 4xx.
|
|
@@ -726,18 +726,16 @@ renamedTool("50arms_api",
|
|
|
726
726
|
const halt = termsHaltFor(result);
|
|
727
727
|
if (halt)
|
|
728
728
|
return haltResult(halt);
|
|
729
|
-
// DX-6089: `GET /api/plan-sessions/me/role`'s role text lands in a local file; the reply names it.
|
|
730
|
-
const spilled = spillRoleInstruction(result);
|
|
731
729
|
// DX-6556: a manual pickup that connected the session is a connect, whatever tool carried it.
|
|
732
|
-
if (isPickupConnect(
|
|
730
|
+
if (isPickupConnect(result)) {
|
|
733
731
|
// DX-8226 (82640, DEC-2598): the connect's answer reaches the caller through the same bounded path as every other `50arms_api` answer, with what the connect adds beside `body`.
|
|
734
|
-
const outcome = await finishConnect(calledAs,
|
|
732
|
+
const outcome = await finishConnect(calledAs, result, false);
|
|
735
733
|
return boundedJsonResult(outcome.kind === "connected" ? outcome.answer : outcome.result, { toFile: args.reply_to_file === true });
|
|
736
734
|
}
|
|
737
735
|
// DX-7110: an answer that says 50 Arms is unreachable is not followed by a health read of it; either way the notices no relay carried ride on it.
|
|
738
|
-
const answered = isUnreachableAnswer(
|
|
739
|
-
?
|
|
740
|
-
: await listenerReminder.apply(
|
|
736
|
+
const answered = isUnreachableAnswer(result)
|
|
737
|
+
? result
|
|
738
|
+
: await listenerReminder.apply(result);
|
|
741
739
|
return boundedJsonResult(mergeReminders(answered, client.reachability.takePending()), { toFile: args.reply_to_file === true });
|
|
742
740
|
});
|
|
743
741
|
// ---------------- 50arms_api_list (DX-3465 A5, PLN-11 R-25) ----------------
|
|
@@ -1186,8 +1184,7 @@ async (args) => {
|
|
|
1186
1184
|
: {}),
|
|
1187
1185
|
});
|
|
1188
1186
|
}
|
|
1189
|
-
|
|
1190
|
-
const result = spillRoleInstruction(await sessionConnect(client, args));
|
|
1187
|
+
const result = await sessionConnect(client, args);
|
|
1191
1188
|
// DX-4418 — a person revoked this key: the stop halt, and nothing asks again.
|
|
1192
1189
|
const revokedHalt = access.refusalHalt(result);
|
|
1193
1190
|
if (revokedHalt !== null)
|
package/dist/listen.js
CHANGED
|
@@ -829,8 +829,6 @@ export function invalidAgentCreatedReason(value) {
|
|
|
829
829
|
if (value.titleInstruction !== null &&
|
|
830
830
|
typeof value.titleInstruction !== "string")
|
|
831
831
|
return "titleInstruction is neither null nor a string";
|
|
832
|
-
if (value.rolePointer !== null && typeof value.rolePointer !== "string")
|
|
833
|
-
return "rolePointer is neither null nor a string";
|
|
834
832
|
if (value.owedComments !== null && typeof value.owedComments !== "string")
|
|
835
833
|
return "owedComments is neither null nor a string";
|
|
836
834
|
if (value.missedEvents !== null) {
|
|
@@ -865,22 +863,19 @@ export function formatAgentCreatedLine(event) {
|
|
|
865
863
|
const missedLines = missed === null || missed.events.length === 0
|
|
866
864
|
? ""
|
|
867
865
|
: `Missed while you waited for your agent: ${missed.events.map((e) => formatActivityLine(e)).join(" ")}${missed.omitted > 0 ? ` (${missed.omitted} more not shown)` : ""}`;
|
|
868
|
-
// DX-6157: no connect is needed to take what Create gave the session; a naming
|
|
866
|
+
// DX-6157: no connect is needed to take what Create gave the session; a naming step that follows still makes its own call.
|
|
869
867
|
const held = event.plan !== null
|
|
870
868
|
? "this agent and plan"
|
|
871
869
|
: event.card !== null
|
|
872
870
|
? "this agent and card"
|
|
873
871
|
: "this agent";
|
|
874
|
-
const ownCalls = thread !== ""
|
|
875
|
-
? "; the steps below keep their own calls"
|
|
876
|
-
: "";
|
|
872
|
+
const ownCalls = thread !== "" ? "; the steps below keep their own calls" : "";
|
|
877
873
|
const parts = [
|
|
878
874
|
`${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}.`,
|
|
879
875
|
oneLine(event.agentInstruction, 800),
|
|
880
876
|
thread === "" ? "" : oneLine(thread, 800),
|
|
881
877
|
event.owedComments === null ? "" : oneLine(event.owedComments),
|
|
882
878
|
missedLines,
|
|
883
|
-
event.rolePointer === null ? "" : oneLine(event.rolePointer, 800),
|
|
884
879
|
"Then carry on with the work you were asked to do.",
|
|
885
880
|
];
|
|
886
881
|
return parts.filter((part) => part !== "").join(" ");
|
|
@@ -27,8 +27,21 @@ function readReminders(result) {
|
|
|
27
27
|
/**
|
|
28
28
|
* DX-7110 - `result` with `extra` appended to its body's `reminders[]` (a key the body already carries is not repeated). A body that is not a
|
|
29
29
|
* JSON object, or whose own `reminders` is not an array, is returned as it is: a reminder never alters an answer it cannot sit beside.
|
|
30
|
+
* DX-8178: an answer with no JSON body (it carries its own top-level `reminders`, `NonJsonAnswer`) takes them there, by the same key rule.
|
|
30
31
|
*/
|
|
31
32
|
export function mergeReminders(result, extra) {
|
|
33
|
+
if (Array.isArray(result.reminders)) {
|
|
34
|
+
const present = new Set(result.reminders.map((r) => r.key));
|
|
35
|
+
const fresh = extra.filter((r) => {
|
|
36
|
+
if (present.has(r.key))
|
|
37
|
+
return false;
|
|
38
|
+
present.add(r.key);
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
return fresh.length === 0
|
|
42
|
+
? result
|
|
43
|
+
: { ...result, reminders: [...result.reminders, ...fresh] };
|
|
44
|
+
}
|
|
32
45
|
const body = result.body;
|
|
33
46
|
if (typeof body !== "object" || body === null || Array.isArray(body))
|
|
34
47
|
return result;
|
package/dist/machine-toolkit.js
CHANGED
|
@@ -630,7 +630,7 @@ var readOwnManifest = () => JSON.parse(
|
|
|
630
630
|
readFileSync(new URL("../../package.json", import.meta.url), "utf8")
|
|
631
631
|
).version;
|
|
632
632
|
var TOOLKIT_VERSION = resolveToolkitVersion(
|
|
633
|
-
false ? void 0 : "0.1.
|
|
633
|
+
false ? void 0 : "0.1.578",
|
|
634
634
|
readOwnManifest
|
|
635
635
|
);
|
|
636
636
|
function envelope(now) {
|
package/dist/reply-files.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DX-8228, DX-8249 - the one place this package saves a reply to a file and hands the path back (`result-limit.ts`, `docs-tools.ts
|
|
3
|
-
*
|
|
4
|
-
* user that wrote it, and a stale one is removed when the server starts. The
|
|
2
|
+
* DX-8228, DX-8249 - the one place this package saves a reply to a file and hands the path back (`result-limit.ts`, `docs-tools.ts`).
|
|
3
|
+
* The files hold whole reply bodies (card text, a session's role, the behavior bundle), so each is readable only by the
|
|
4
|
+
* user that wrote it, and a stale one is removed when the server starts. DX-7804: nothing writes the `role` folder any more (the role-file spill is gone: a session's role reaches it through the plugin's hook); the start's cleanup empties and removes it (`RETIRED_REPLY_FOLDER`). The three folders sit under one root, `~/.config/danxbot/replies`
|
|
5
5
|
* (`replyRoot`), the folder the 50arms plugin already reads this server's files from; there is no other location and no fallback to the temporary
|
|
6
6
|
* folder. The files earlier versions wrote under the temporary folder are left for the system to clear (no code for an old layout). The writer and
|
|
7
7
|
* the sweep act on the root only through `verifiedRoot`, and the sweep never follows a link.
|
|
8
8
|
* The sweep runs only at server start, before this process has written any file, so it never removes a file this server handed back; a file
|
|
9
9
|
* another session of the same user handed back survives until it is older than `REPLY_FILE_MAX_AGE_MS`.
|
|
10
10
|
*/
|
|
11
|
-
import { chmodSync, lstatSync, mkdirSync, readdirSync, unlinkSync, } from "node:fs";
|
|
11
|
+
import { chmodSync, lstatSync, mkdirSync, readdirSync, rmdirSync, unlinkSync, } from "node:fs";
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import { writeFileDurable } from "./durable-write.js";
|
|
15
15
|
import { sessionControlDir } from "./session-control-file.js";
|
|
16
16
|
/** The folders, under the reply root, that reply files live in: `docs_read` writes `docs/<repo>/<id>.md`, the others write flat files. */
|
|
17
|
-
export const REPLY_FOLDERS = ["api", "
|
|
17
|
+
export const REPLY_FOLDERS = ["api", "docs", "product-docs"];
|
|
18
|
+
/**
|
|
19
|
+
* DX-7804: the folder older versions wrote a session's role text to (`role/<profile>-<hash>.md`, the role-file spill this version no longer has). The start's cleanup sweeps it like the others, so its files go by the
|
|
20
|
+
* same age rule (an older server still running in another session may have just handed one out), and removes the folder itself once it is empty: after that it is gone for good, and the entry does nothing.
|
|
21
|
+
*/
|
|
22
|
+
const RETIRED_REPLY_FOLDER = "role";
|
|
18
23
|
/**
|
|
19
24
|
* How old a reply file must be before the server's start removes it. A session reads a path it was handed within that session, and a
|
|
20
25
|
* session that outlives a week is rare; the files hold whole reply bodies, so they should not stay longer than that.
|
|
@@ -24,7 +29,7 @@ export const REPLY_FILE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
24
29
|
const DIR_MODE = 0o700;
|
|
25
30
|
const FILE_MODE = 0o600;
|
|
26
31
|
/**
|
|
27
|
-
* The folder the
|
|
32
|
+
* The folder the three reply folders live in: `<home>/.config/danxbot/replies` (`sessionControlDir`, the one owner of the `~/.config/danxbot` layout), beside the other files this server keeps for the plugin
|
|
28
33
|
* (`plan-sessions`, `session-keys`). Never `os.userInfo()`, which throws for a user with no passwd entry.
|
|
29
34
|
*/
|
|
30
35
|
export function replyRoot(home = os.homedir()) {
|
|
@@ -76,8 +81,8 @@ export function writeReplyFile(folder, rest, data, deps = {}) {
|
|
|
76
81
|
return file;
|
|
77
82
|
}
|
|
78
83
|
/**
|
|
79
|
-
* Remove every regular file this user owns under the `REPLY_FOLDERS` last modified more than `REPLY_FILE_MAX_AGE_MS` before `now`. Run once at
|
|
80
|
-
* server start, before this process writes anything: no timer, no background process. It never follows a link: a linked folder among the
|
|
84
|
+
* Remove every regular file this user owns under the `REPLY_FOLDERS` (and the retired `role` folder, then that folder once it is empty) last modified more than `REPLY_FILE_MAX_AGE_MS` before `now`. Run once at
|
|
85
|
+
* server start, before this process writes anything: no timer, no background process. It never follows a link: a linked folder among the three,
|
|
81
86
|
* and any linked entry below them, is skipped. A missing folder is nothing to clean; a file another server removed first is skipped. Housekeeping
|
|
82
87
|
* nobody reads must never stop a server from starting, so a root that cannot be trusted, or a folder whose cleanup fails, is reported on stderr
|
|
83
88
|
* (its path and the error) and the rest go on; a write that fails still fails its own call.
|
|
@@ -103,8 +108,29 @@ export function removeStaleReplyFiles(now, deps = {}) {
|
|
|
103
108
|
report(dir, err);
|
|
104
109
|
}
|
|
105
110
|
}
|
|
111
|
+
const retired = path.join(root, RETIRED_REPLY_FOLDER);
|
|
112
|
+
try {
|
|
113
|
+
sweep(retired, now - REPLY_FILE_MAX_AGE_MS, true);
|
|
114
|
+
removeIfEmpty(retired);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
report(retired, err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Remove `dir` when it is a real, empty folder; a missing one, a link, or one that still holds anything is left as it is. */
|
|
121
|
+
function removeIfEmpty(dir) {
|
|
122
|
+
try {
|
|
123
|
+
if (!lstatSync(dir).isDirectory())
|
|
124
|
+
return;
|
|
125
|
+
rmdirSync(dir);
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
const code = err.code;
|
|
129
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
106
132
|
}
|
|
107
|
-
/** `top` is one of the
|
|
133
|
+
/** `top` is one of the three folders: it is walked only if it is itself a real folder, never a link. */
|
|
108
134
|
function sweep(dir, cutoff, top) {
|
|
109
135
|
let entries;
|
|
110
136
|
try {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Must match the dashboard's own header name verbatim. */
|
|
2
|
+
export const REPLY_REMINDERS_HEADER = "X-Danx-Reply-Reminders";
|
|
3
|
+
/**
|
|
4
|
+
* The reminders the response header carries, in its order; an answer with no header carries none. A header that is not base64url of a JSON list of `{key, text}` strings throws:
|
|
5
|
+
* a reply policy the agent cannot read must not pass as an answer with none.
|
|
6
|
+
*/
|
|
7
|
+
export function replyRemindersOf(headers) {
|
|
8
|
+
const value = headers.get(REPLY_REMINDERS_HEADER);
|
|
9
|
+
if (value === null || value === "")
|
|
10
|
+
return [];
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error(`[platform-mcp] the ${REPLY_REMINDERS_HEADER} header is not base64url of a JSON list`);
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(parsed) ||
|
|
19
|
+
!parsed.every((r) => typeof r === "object" &&
|
|
20
|
+
r !== null &&
|
|
21
|
+
typeof r.key === "string" &&
|
|
22
|
+
typeof r.text === "string"))
|
|
23
|
+
throw new Error(`[platform-mcp] the ${REPLY_REMINDERS_HEADER} header is not a list of {key, text} strings`);
|
|
24
|
+
return parsed.map(({ key, text }) => ({ key, text }));
|
|
25
|
+
}
|
package/dist/result-limit.js
CHANGED
|
@@ -14,8 +14,8 @@ const FILE_INSTRUCTION = "The reply was over the inline limit, so its body is th
|
|
|
14
14
|
/**
|
|
15
15
|
* The text the agent receives for `result`: its compact JSON when that fits `MCP_MAX_RESULT_CHARS` and the caller
|
|
16
16
|
* did not ask for a file (`toFile`, DX-8226), otherwise the envelope with `reply_file:{path, bytes, chars, sha256, instruction}`
|
|
17
|
-
* in place of `body`: the body written whole to `<reply root>/api/<first 16 hex of sha256>.json` (DX-6117, DX-8228: through `writeReplyFile`, as `docs_read`
|
|
18
|
-
*
|
|
17
|
+
* in place of `body`: the body written whole to `<reply root>/api/<first 16 hex of sha256>.json` (DX-6117, DX-8228: through `writeReplyFile`, as `docs_read` does).
|
|
18
|
+
* `sha256` is the full hex digest of the file's bytes. Never truncates, never forwards a part. Every other
|
|
19
19
|
* field of the envelope (`ok` and `status`, so a write that already committed is still reported as committed, `app_version`, and
|
|
20
20
|
* what the MCP adds beside `body` such as a connect's `dashboard`, DEC-2598) stays beside `reply_file`; the file holds only the route's reply.
|
|
21
21
|
*/
|
|
@@ -49,6 +49,7 @@ export const GET_ROUTE_BOARD_SCOPE = [
|
|
|
49
49
|
["/api/pacing/history", "refuse"],
|
|
50
50
|
["/api/permission-requests", "refuse"],
|
|
51
51
|
["/api/plan-sessions", "refuse"],
|
|
52
|
+
["/api/plan-sessions/me/role", "refuse"],
|
|
52
53
|
["/api/plan-sessions/ready", "refuse"],
|
|
53
54
|
["/api/plans", "refuse"],
|
|
54
55
|
["/api/plans/:planId/architecture/sections", "refuse"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@50arms/platform-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.578",
|
|
4
4
|
"description": "Stdio MCP server fronting the 50 Arms dashboard API for agents (operator sessions and dispatched workers alike): the generic 50arms_api/50arms_api_list/50arms_api_spec tools reach any route the caller's credential may call, plus dedicated agent-specific tools (session_connect, request_permission, attach_file, and 50arms_slack_reply) (DX-3465, PLN-11 R-25).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DX-6089 - a session's role text reaches it as a local file, never inline. The dashboard answers `roleInstruction: {profile, text}` on
|
|
3
|
-
* `session_connect` and `GET /api/plan-sessions/me/role`; the text runs to tens of KB, and a tool reply that large is
|
|
4
|
-
* saved to a file by the client with only a short preview, which also hides every field after it (the briefing, the agent instruction, the
|
|
5
|
-
* reminders). So this server writes the text to `<reply root>/role/<profile>-<content hash>.md` and answers `{profile, path, bytes, instruction}`
|
|
6
|
-
* in its place, leaving every other field inline, as `docs_read` does for a docs page (`docs-tools.ts`). The name carries the content hash, so a
|
|
7
|
-
* changed text never overwrites a file a session is reading, and the file is written under a temp name and renamed into place, so a reader never
|
|
8
|
-
* sees half of it.
|
|
9
|
-
*/
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
|
-
import { writeReplyFile } from "./reply-files.js";
|
|
12
|
-
export const ROLE_FILE_INSTRUCTION = "Read this file in full now, with Read (in parts with offset and limit when it is long): it is your role's workflow, the procedure you work by.";
|
|
13
|
-
// The profile names the file, so it must be a plain name: never a path a reply could steer. DX-7462: a card type's own profile is a team profile, whose name may hold `_` (`AGENT_NAME_SHAPE`).
|
|
14
|
-
const PROFILE_NAME = /^[a-z][a-z0-9_-]*$/;
|
|
15
|
-
/**
|
|
16
|
-
* `result` with its body's `roleInstruction` written to a file and replaced by where it is. A body without the key, or with `null` (nothing to
|
|
17
|
-
* send), passes unchanged. A `roleInstruction` of any other shape is a dashboard contract break and throws (CP1).
|
|
18
|
-
*/
|
|
19
|
-
export function spillRoleInstruction(result, deps = {}) {
|
|
20
|
-
const body = result.body;
|
|
21
|
-
if (typeof body !== "object" ||
|
|
22
|
-
body === null ||
|
|
23
|
-
!Object.hasOwn(body, "roleInstruction"))
|
|
24
|
-
return result;
|
|
25
|
-
const role = body.roleInstruction;
|
|
26
|
-
if (role === null)
|
|
27
|
-
return result;
|
|
28
|
-
const { profile, text } = (role ?? {});
|
|
29
|
-
if (typeof profile !== "string" ||
|
|
30
|
-
!PROFILE_NAME.test(profile) ||
|
|
31
|
-
typeof text !== "string") {
|
|
32
|
-
throw new Error(`the dashboard answered a roleInstruction that is not {profile, text}: ${JSON.stringify(role).slice(0, 200)}`);
|
|
33
|
-
}
|
|
34
|
-
const file = writeReplyFile("role", [
|
|
35
|
-
`${profile}-${createHash("sha256").update(text).digest("hex").slice(0, 16)}.md`,
|
|
36
|
-
], text, deps);
|
|
37
|
-
const spilled = {
|
|
38
|
-
profile,
|
|
39
|
-
path: file,
|
|
40
|
-
bytes: Buffer.byteLength(text, "utf8"),
|
|
41
|
-
instruction: ROLE_FILE_INSTRUCTION,
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
...result,
|
|
45
|
-
body: { ...body, roleInstruction: spilled },
|
|
46
|
-
};
|
|
47
|
-
}
|