@50arms/platform-mcp 0.1.576 → 0.1.577

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/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";
@@ -726,18 +725,16 @@ renamedTool("50arms_api",
726
725
  const halt = termsHaltFor(result);
727
726
  if (halt)
728
727
  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
728
  // DX-6556: a manual pickup that connected the session is a connect, whatever tool carried it.
732
- if (isPickupConnect(spilled)) {
729
+ if (isPickupConnect(result)) {
733
730
  // 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, spilled, false);
731
+ const outcome = await finishConnect(calledAs, result, false);
735
732
  return boundedJsonResult(outcome.kind === "connected" ? outcome.answer : outcome.result, { toFile: args.reply_to_file === true });
736
733
  }
737
734
  // 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(spilled)
739
- ? spilled
740
- : await listenerReminder.apply(spilled);
735
+ const answered = isUnreachableAnswer(result)
736
+ ? result
737
+ : await listenerReminder.apply(result);
741
738
  return boundedJsonResult(mergeReminders(answered, client.reachability.takePending()), { toFile: args.reply_to_file === true });
742
739
  });
743
740
  // ---------------- 50arms_api_list (DX-3465 A5, PLN-11 R-25) ----------------
@@ -1186,8 +1183,7 @@ async (args) => {
1186
1183
  : {}),
1187
1184
  });
1188
1185
  }
1189
- // DX-6089: the role text lands in a local file; the reply names it (`role-instruction-file.ts`).
1190
- const result = spillRoleInstruction(await sessionConnect(client, args));
1186
+ const result = await sessionConnect(client, args);
1191
1187
  // DX-4418 — a person revoked this key: the stop halt, and nothing asks again.
1192
1188
  const revokedHalt = access.refusalHalt(result);
1193
1189
  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 or role step that follows still makes its own call.
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 !== "" || event.rolePointer !== null
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(" ");
@@ -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.576",
633
+ false ? void 0 : "0.1.577",
634
634
  readOwnManifest
635
635
  );
636
636
  function envelope(now) {
@@ -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
- * `role-instruction-file.ts`). The files hold whole reply bodies (card text, role texts, 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. The four folders sit under one root, `~/.config/danxbot/replies`
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", "role", "docs", "product-docs"];
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 four 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
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 four,
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 four folders: it is walked only if it is itself a real folder, never a link. */
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 {
@@ -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` and
18
- * the role text do). `sha256` is the full hex digest of the file's bytes. Never truncates, never forwards a part. Every other
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.576",
3
+ "version": "0.1.577",
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
- }