@50arms/platform-mcp 0.1.548 → 0.1.550

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.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * DX-7803 (PLAN-151 section 565, AC 72314) - the behavior bundle's version, as this package relays it to the 50arms plugin.
3
+ *
4
+ * The plugin caches the one bundle of texts 50 Arms renders for its session (`GET /api/behavior-events/bundle`) and evaluates each plugin event from it locally. It needs to know when what it holds is stale: the session's stream carries a
5
+ * `behavior_bundle` frame (`event: behavior_bundle`, data `{"version": <the bundle's current version>}`, level-triggered like `compaction` and `clear`: no `id:` line, no replay, the current version on every connect and again whenever it changes;
6
+ * the dashboard's `src/issues/plan-session-stream.ts`). The relay writes it to ONE local file the plugin reads: `~/.config/danxbot/behavior-bundle/<sessionId>.json`, `{v: 1, sessionId, version}`. The plugin re-reads the bundle (with its
7
+ * `known_version`) when the file's version is not the one it holds. A frame says nothing to the agent, so nothing is shown.
8
+ *
9
+ * The frame's shape mirrors the dashboard's; this published package cannot import it. A frame this relay cannot read is a fault line to the agent, never silence. A relay older than this one never writes the file, so the dashboard raises the
10
+ * stream's floor (`src/mcp-contract.ts`) and an older relay stops with its restart notice.
11
+ */
12
+ import { homedir } from "node:os";
13
+ import { sessionControlDir, sessionControlFilePath, sessionControlFilesIn, } from "./session-control-file.js";
14
+ const BUNDLE_VERSION = /^[0-9a-f]{64}$/;
15
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
16
+ /** Why a `behavior_bundle` frame's data cannot be read, or `null` when it can. */
17
+ export function invalidBehaviorBundleReason(value) {
18
+ if (!isRecord(value) || !("version" in value))
19
+ return "the frame has no version";
20
+ if (typeof value.version !== "string" || !BUNDLE_VERSION.test(value.version))
21
+ return "version is not a bundle version (64 hex characters)";
22
+ return null;
23
+ }
24
+ /** The version of a valid frame's data (`invalidBehaviorBundleReason` is `null`). */
25
+ export function behaviorBundleVersionOfFrame(value) {
26
+ const reason = invalidBehaviorBundleReason(value);
27
+ if (reason !== null)
28
+ throw new Error(`malformed behavior_bundle frame: ${reason}`);
29
+ return value.version;
30
+ }
31
+ /** The file of session `sessionId` for the bundle `version`. */
32
+ export function behaviorBundleFileOf(version, sessionId) {
33
+ return { v: 1, sessionId, version };
34
+ }
35
+ const BEHAVIOR_BUNDLE_DIR = "behavior-bundle";
36
+ export function behaviorBundleDir(home = homedir()) {
37
+ return sessionControlDir(BEHAVIOR_BUNDLE_DIR, home);
38
+ }
39
+ /** `~/.config/danxbot/behavior-bundle/<sessionId>.json`, next to the compaction and clear control files. */
40
+ export function behaviorBundleFilePath(sessionId, home = homedir()) {
41
+ return sessionControlFilePath(BEHAVIOR_BUNDLE_DIR, sessionId, home);
42
+ }
43
+ export function parseBehaviorBundleFile(text, where) {
44
+ const parsed = JSON.parse(text);
45
+ if (!isRecord(parsed) ||
46
+ parsed.v !== 1 ||
47
+ typeof parsed.sessionId !== "string" ||
48
+ typeof parsed.version !== "string" ||
49
+ !BUNDLE_VERSION.test(parsed.version))
50
+ throw new Error(`${where} is not a behavior bundle file`);
51
+ return parsed;
52
+ }
53
+ /** The real store, under `home` (`sessionControlFilesIn`, as the other controls'). */
54
+ export function behaviorBundleFilesIn(home = homedir(), now = Date.now) {
55
+ return sessionControlFilesIn(BEHAVIOR_BUNDLE_DIR, parseBehaviorBundleFile, home, now);
56
+ }
package/dist/index.js CHANGED
@@ -76,6 +76,7 @@ import { MACHINE_DAEMON_SUBCOMMANDS, runMachineDaemonCommand, } from "./machine-
76
76
  import { isEntrypointModule } from "./entrypoint.js";
77
77
  import { compactionFilesIn } from "./compaction-control.js";
78
78
  import { clearFilesIn } from "./clear-control.js";
79
+ import { behaviorBundleFilesIn } from "./behavior-bundle-control.js";
79
80
  import { PlanEventRelay, WAIT_MAX_MS, WAIT_MIN_MS, } from "./plan-events-relay.js";
80
81
  import { READ_IDLE_TIMEOUT_MS } from "./listen.js";
81
82
  import { realScheduleInterval, realSleep } from "./session-stream.js";
@@ -271,6 +272,7 @@ async function boot() {
271
272
  scheduleInterval: realScheduleInterval,
272
273
  compactionFiles: compactionFilesIn(),
273
274
  clearFiles: clearFilesIn(),
275
+ behaviorBundleFiles: behaviorBundleFilesIn(),
274
276
  onAgentCreated: adoptCreatedAgent,
275
277
  });
276
278
  permissionWatch = new PermissionWatch({
package/dist/listen.js CHANGED
@@ -43,6 +43,7 @@
43
43
  */
44
44
  import { controlOfFrame, invalidCompactionReason, } from "./compaction-control.js";
45
45
  import { clearControlOfFrame, invalidClearReason, } from "./clear-control.js";
46
+ import { behaviorBundleVersionOfFrame, invalidBehaviorBundleReason, } from "./behavior-bundle-control.js";
46
47
  import { LINE_PREFIX, oneLine } from "./one-line.js";
47
48
  import { clientVersionHeaders, MCP_STREAM_MIN_VERSION_HEADER, ownVersionBelow, pluginVersionFromEnv, readOwnVersion, } from "./version-floor.js";
48
49
  import { pacingRelayLine } from "./pacing-relay.js";
@@ -1161,6 +1162,12 @@ export async function runListener(options, deps) {
1161
1162
  type: "clear",
1162
1163
  control: clearControlOfFrame(p),
1163
1164
  }));
1165
+ // DX-7803 (AC 72314) - the behavior bundle's current version: level-triggered like the two controls above, never shown to the agent.
1166
+ if (message.event === "behavior_bundle")
1167
+ return emitControl(message, "behavior bundle version", invalidBehaviorBundleReason, (p) => ({
1168
+ type: "behavior_bundle",
1169
+ version: behaviorBundleVersionOfFrame(p),
1170
+ }));
1164
1171
  if (message.event === "team_agent_created")
1165
1172
  return emitAgentCreated(message);
1166
1173
  if (message.event !== "activity")
@@ -612,7 +612,7 @@ var readOwnManifest = () => JSON.parse(
612
612
  readFileSync(new URL("../../package.json", import.meta.url), "utf8")
613
613
  ).version;
614
614
  var TOOLKIT_VERSION = resolveToolkitVersion(
615
- false ? void 0 : "0.1.548",
615
+ false ? void 0 : "0.1.550",
616
616
  readOwnManifest
617
617
  );
618
618
  function envelope(now) {
@@ -58,6 +58,7 @@
58
58
  */
59
59
  import { fileOf, formatCompactionAskLine, } from "./compaction-control.js";
60
60
  import { clearFileOf, formatClearAskLine, } from "./clear-control.js";
61
+ import { behaviorBundleFileOf, } from "./behavior-bundle-control.js";
61
62
  import { DigestHold } from "./digest-hold.js";
62
63
  import { HeartbeatReporter } from "./heartbeat-reporter.js";
63
64
  import { capResumeIds, DELIVERED_ID_MEMORY, HEALTHY_CONNECTION_MS, INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, runListener, } from "./listen.js";
@@ -389,7 +390,12 @@ export class PlanEventRelay {
389
390
  * ends the heartbeat.
390
391
  */
391
392
  touchControlFiles(sessionId) {
392
- for (const kind of [this.compactionKind(), this.clearKind()]) {
393
+ const files = [
394
+ this.compactionKind(),
395
+ this.clearKind(),
396
+ { files: this.deps.behaviorBundleFiles, what: "behavior bundle version" },
397
+ ];
398
+ for (const kind of files) {
393
399
  try {
394
400
  kind.files.touch(sessionId);
395
401
  }
@@ -444,6 +450,30 @@ export class PlanEventRelay {
444
450
  this.terminal(run, "relay_failed", message);
445
451
  });
446
452
  }
453
+ /**
454
+ * DX-7803 (AC 72314): the bundle version the stream named, written to the file the plugin reads. A file that cannot be written is a line to the agent (the plugin would keep a stale bundle), never silence; the next frame (the dashboard repeats the version on every
455
+ * connect) writes it again.
456
+ */
457
+ writeBehaviorBundleVersion(version) {
458
+ const auth = this.deps.auth();
459
+ if (auth === null)
460
+ return;
461
+ try {
462
+ this.deps.behaviorBundleFiles.write(auth.sessionId, behaviorBundleFileOf(version, auth.sessionId));
463
+ }
464
+ catch (err) {
465
+ const detail = err instanceof Error ? err.message : String(err);
466
+ this.digest.route({
467
+ type: "event",
468
+ id: null,
469
+ text: `${LINE_PREFIX} the behavior bundle version could not be kept for this session (${detail}), so its plugin cannot tell when its cached behavior texts are stale`,
470
+ origin: null,
471
+ urgent: isUrgent({ source: "fault" }),
472
+ acks: [],
473
+ scope: "session",
474
+ });
475
+ }
476
+ }
447
477
  /** DX-4993: the compaction control's file, ask line and fault wording. */
448
478
  compactionKind() {
449
479
  return {
@@ -609,6 +639,10 @@ export class PlanEventRelay {
609
639
  this.applyControl(output.control, this.clearKind());
610
640
  return;
611
641
  }
642
+ if (output.type === "behavior_bundle") {
643
+ this.writeBehaviorBundleVersion(output.version);
644
+ return;
645
+ }
612
646
  this.digest.route(output);
613
647
  },
614
648
  onState: (state) => {
@@ -7,6 +7,7 @@ export const GET_ROUTE_BOARD_SCOPE = [
7
7
  ["/api/behavior-computed-sections", "refuse"],
8
8
  ["/api/behavior-events", "refuse"],
9
9
  ["/api/behavior-events/:event/attachments", "refuse"],
10
+ ["/api/behavior-events/bundle", "refuse"],
10
11
  ["/api/behavior-policies", "refuse"],
11
12
  ["/api/behavior-policies/:ref/comments", "refuse"],
12
13
  ["/api/behavior-policy-groups", "refuse"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@50arms/platform-mcp",
3
- "version": "0.1.548",
3
+ "version": "0.1.550",
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",