@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.
Files changed (67) hide show
  1. package/dist/access-request.js +19 -6
  2. package/dist/agent-gate.js +19 -5
  3. package/dist/board-id.js +8 -2
  4. package/dist/checkout-docs-root.js +10 -2
  5. package/dist/clear-control.js +18 -4
  6. package/dist/compaction-control.js +30 -7
  7. package/dist/credential.js +10 -2
  8. package/dist/danxbot-api-examples.js +20 -3
  9. package/dist/design-screenshot.js +22 -5
  10. package/dist/digest-hold.js +14 -3
  11. package/dist/docs-tools.js +46 -12
  12. package/dist/durable-write.js +10 -2
  13. package/dist/forbidden-hint.js +13 -2
  14. package/dist/guarded-calls.js +7 -2
  15. package/dist/handlers.js +70 -15
  16. package/dist/heartbeat-reporter.js +8 -3
  17. package/dist/http-client.js +5 -3
  18. package/dist/index.js +252 -82
  19. package/dist/job-key.js +47 -0
  20. package/dist/json-body.js +3 -1
  21. package/dist/key-revoked-halt.js +2 -1
  22. package/dist/leftover-wire.js +17 -4
  23. package/dist/lifecycle.js +11 -3
  24. package/dist/listen.js +242 -64
  25. package/dist/listener-reminder.js +8 -2
  26. package/dist/machine-daemon/autostart.js +16 -4
  27. package/dist/machine-daemon/beat.js +18 -4
  28. package/dist/machine-daemon/cli.js +15 -4
  29. package/dist/machine-daemon/install.js +33 -9
  30. package/dist/machine-daemon/leftovers.js +134 -30
  31. package/dist/machine-daemon/state.js +9 -3
  32. package/dist/machine-daemon.js +531 -128
  33. package/dist/machine-registration.js +27 -6
  34. package/dist/machine-secret.js +8 -3
  35. package/dist/machine-toolkit.js +377 -81
  36. package/dist/mini-app-build.js +19 -5
  37. package/dist/mini-app-checkout.js +38 -10
  38. package/dist/mini-app-output.js +22 -5
  39. package/dist/mini-app-publish.js +34 -11
  40. package/dist/mini-app-restore.js +30 -9
  41. package/dist/one-line.js +3 -1
  42. package/dist/permission-request.js +14 -3
  43. package/dist/permission-watch.js +10 -3
  44. package/dist/plan-events-relay.js +96 -19
  45. package/dist/plan-events-tool.js +9 -2
  46. package/dist/plugin-publish.js +23 -6
  47. package/dist/plugin-screenshot.js +18 -6
  48. package/dist/restart-notice.js +47 -15
  49. package/dist/result-limit.js +6 -1
  50. package/dist/role-instruction-file.js +16 -4
  51. package/dist/route-board-scope.generated.js +5 -0
  52. package/dist/route-board-scope.js +6 -2
  53. package/dist/session-access.js +114 -33
  54. package/dist/session-connection.js +23 -7
  55. package/dist/session-control-file.js +1 -1
  56. package/dist/session-key.js +12 -4
  57. package/dist/session-options.js +6 -2
  58. package/dist/session-stats.js +2 -1
  59. package/dist/session-stream.js +81 -20
  60. package/dist/shutdown.js +3 -1
  61. package/dist/subagents-live.js +8 -2
  62. package/dist/terms-halt.js +4 -2
  63. package/dist/tool-access.js +17 -4
  64. package/dist/tool-surface.js +9 -2
  65. package/dist/transcript-lineage.js +5 -2
  66. package/dist/urgent-records.js +1 -0
  67. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -72,30 +72,31 @@
72
72
  * agent reads `body.error` + structured fields to decide next action.
73
73
  * 5xx and network failures throw — never silently swallowed.
74
74
  */
75
- import { MACHINE_DAEMON_SUBCOMMANDS, runMachineDaemonCommand } from "./machine-daemon/cli.js";
75
+ import { MACHINE_DAEMON_SUBCOMMANDS, runMachineDaemonCommand, } from "./machine-daemon/cli.js";
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 { PlanEventRelay, WAIT_MAX_MS, WAIT_MIN_MS } from "./plan-events-relay.js";
79
+ import { PlanEventRelay, WAIT_MAX_MS, WAIT_MIN_MS, } from "./plan-events-relay.js";
80
80
  import { READ_IDLE_TIMEOUT_MS } from "./listen.js";
81
- import { REQUEST_TIMEOUT_MS, realScheduleInterval, realSleep } from "./session-stream.js";
81
+ import { REQUEST_TIMEOUT_MS, realScheduleInterval, realSleep, } from "./session-stream.js";
82
82
  import { servePlanEventsWait } from "./plan-events-tool.js";
83
83
  import { lookupRestartNotice, RESTART_NOTICE_ARGS } from "./restart-notice.js";
84
84
  import { makeSessionStop, stopWhenSessionEnds } from "./shutdown.js";
85
- import { SUBAGENTS_LIVE_SUBCOMMAND, runSubagentsLiveCommand } from "./subagents-live.js";
86
- import { resolveBootCredential } from "./credential.js";
85
+ import { SUBAGENTS_LIVE_SUBCOMMAND, runSubagentsLiveCommand, } from "./subagents-live.js";
86
+ import { resolveBootCredential, } from "./credential.js";
87
87
  import { SessionKeyUnusableError, deleteSessionKey } from "./session-key.js";
88
88
  import { SessionAccess } from "./session-access.js";
89
89
  import { PermissionRequests } from "./permission-request.js";
90
90
  import { makeGuardedCalls } from "./guarded-calls.js";
91
+ import { JobKeyHolder } from "./job-key.js";
91
92
  import { readOwnVersion } from "./version-floor.js";
92
- import { createCheckoutDocsRootReporter, readCheckoutRepo } from "./checkout-docs-root.js";
93
- import { isPickupConnect, projectKeyOf, recordSessionConnectionAfterConnect, removeSessionConnectionAfterLeave } from "./session-connection.js";
93
+ import { createCheckoutDocsRootReporter, readCheckoutRepo, } from "./checkout-docs-root.js";
94
+ import { isPickupConnect, projectKeyOf, recordSessionConnectionAfterConnect, removeSessionConnectionAfterLeave, } from "./session-connection.js";
94
95
  import { createListenerReminder, isPlanConnectedOnThisMachine, } from "./listener-reminder.js";
95
96
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
96
97
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
97
98
  import { z } from "zod";
98
- import { boardRefArgSchema, parseBoardRefText, repoNameArgSchema } from "./board-id.js";
99
+ import { boardRefArgSchema, parseBoardRefText, repoNameArgSchema, } from "./board-id.js";
99
100
  import { DashboardHttpClient } from "./http-client.js";
100
101
  import { claimSessionAgent, sessionConnect, danxbotApi, danxbotApiList, danxbotApiSpec, attachFile, DANXBOT_API_METHODS, } from "./handlers.js";
101
102
  import { miniAppPublish } from "./mini-app-publish.js";
@@ -109,11 +110,11 @@ import { bodyValueSchema, queryValueSchema } from "./types.js";
109
110
  import { termsAcceptanceCallHalt, termsHaltFor } from "./terms-halt.js";
110
111
  import { danxbotApiExamplesText } from "./danxbot-api-examples.js";
111
112
  import { assertWithinTextLimit } from "./text-limit.js";
112
- import { registerLifecycleTools, presentCallbacksFromEnv } from "./lifecycle.js";
113
+ import { registerLifecycleTools, presentCallbacksFromEnv, } from "./lifecycle.js";
113
114
  import { LEGACY_TOOL_NAMES, TOOL_ACCESS } from "./tool-access.js";
114
115
  import { ToolAccessSync, ToolSurface } from "./tool-surface.js";
115
116
  import { PermissionWatch } from "./permission-watch.js";
116
- import { AgentGate, isAgentGateOpenCall, isAgentGateOpenSpec, onlyAgentProposalRoutes } from "./agent-gate.js";
117
+ import { AgentGate, isAgentGateOpenCall, isAgentGateOpenSpec, onlyAgentProposalRoutes, } from "./agent-gate.js";
117
118
  import { SYNC_ATTEMPTS, retryBounded } from "./bounded-retry.js";
118
119
  import { dashboardIdentity } from "./dashboard-identity.js";
119
120
  function readEnvOrDie(name) {
@@ -212,7 +213,11 @@ function boot() {
212
213
  });
213
214
  listenerReminder = createListenerReminder({
214
215
  sessionId: config.session?.id,
215
- fetchHealth: () => dashboardClient.requestOwn({ method: "GET", basePath: "", path: "/api/plan-sessions/me/listener-health" }),
216
+ fetchHealth: () => dashboardClient.requestOwn({
217
+ method: "GET",
218
+ basePath: "",
219
+ path: "/api/plan-sessions/me/listener-health",
220
+ }),
216
221
  isPlanConnected: isPlanConnectedOnThisMachine,
217
222
  now: Date.now,
218
223
  logLine: (line) => console.error(line),
@@ -238,7 +243,11 @@ function boot() {
238
243
  const connection = access.connection();
239
244
  return connection === null || session === undefined
240
245
  ? null
241
- : { dashboardUrl: connection.dashboardUrl, token: access.currentToken(), sessionId: session.id };
246
+ : {
247
+ dashboardUrl: connection.dashboardUrl,
248
+ token: access.currentToken(),
249
+ sessionId: session.id,
250
+ };
242
251
  },
243
252
  fetch: (input, init) => fetch(input, init),
244
253
  sleep: realSleep,
@@ -265,7 +274,11 @@ async function readKeyPermissions() {
265
274
  if (!access.isSignedIn())
266
275
  return { outcome: "no-key" };
267
276
  // DX-5076: this process reading its own key's permissions is not the agent acting.
268
- const guarded = await access.guard(() => client.requestOwn({ method: "GET", basePath: "", path: "/api/auth/permissions" }));
277
+ const guarded = await access.guard(() => client.requestOwn({
278
+ method: "GET",
279
+ basePath: "",
280
+ path: "/api/auth/permissions",
281
+ }));
269
282
  if ("halt" in guarded)
270
283
  return { outcome: "no-key" };
271
284
  const { result } = guarded;
@@ -274,8 +287,10 @@ async function readKeyPermissions() {
274
287
  if (!result.ok) {
275
288
  throw new Error(`GET /api/auth/permissions answered ${result.status}: ${JSON.stringify(result.body)}`);
276
289
  }
277
- const permissions = result.body?.permissions;
278
- if (!Array.isArray(permissions) || !permissions.every((p) => typeof p === "string")) {
290
+ const permissions = result.body
291
+ ?.permissions;
292
+ if (!Array.isArray(permissions) ||
293
+ !permissions.every((p) => typeof p === "string")) {
279
294
  throw new Error(`GET /api/auth/permissions answered without a permissions list: ${JSON.stringify(result.body)}`);
280
295
  }
281
296
  return { outcome: "held", permissions: new Set(permissions) };
@@ -297,7 +312,10 @@ function syncPolicy() {
297
312
  async function syncToolsWithPolicy() {
298
313
  const { attempts, fatal } = syncPolicy();
299
314
  try {
300
- await retryBounded(() => toolAccessSync.sync(), { attempts, sleep: sleepHoldingProcess });
315
+ await retryBounded(() => toolAccessSync.sync(), {
316
+ attempts,
317
+ sleep: sleepHoldingProcess,
318
+ });
301
319
  }
302
320
  catch (err) {
303
321
  if (fatal)
@@ -331,7 +349,13 @@ function adoptCreatedAgent(created) {
331
349
  console.error("agent created: no credential after the dashboard signed this session in; the local connection record was not written");
332
350
  }
333
351
  else {
334
- const recorded = recordSessionConnectionAfterConnect({ ok: true }, { sessionId: config.session?.id, projectKey: projectKeyOf(process.cwd()), dashboardUrl: connection.dashboardUrl, source: connection.source, fingerprint: connection.fingerprint });
352
+ const recorded = recordSessionConnectionAfterConnect({ ok: true }, {
353
+ sessionId: config.session?.id,
354
+ projectKey: projectKeyOf(process.cwd()),
355
+ dashboardUrl: connection.dashboardUrl,
356
+ source: connection.source,
357
+ fingerprint: connection.fingerprint,
358
+ });
335
359
  if (recorded.connection_record_error !== undefined)
336
360
  console.error(`agent created: ${recorded.connection_record_error}`);
337
361
  }
@@ -459,25 +483,44 @@ function connectedDashboard() {
459
483
  function accessReply(ready, note) {
460
484
  // the dashboard this session is on is named in the sign-in answer, so a session aimed at the wrong dashboard shows it before any write
461
485
  if (ready.signedIn)
462
- return jsonResult({ state: "signed_in", ...(note ? { note } : {}), dashboard: connectedDashboard() });
486
+ return jsonResult({
487
+ state: "signed_in",
488
+ ...(note ? { note } : {}),
489
+ dashboard: connectedDashboard(),
490
+ });
463
491
  // DX-4418: a person revoked this session's access: the one stop halt, verbatim, never a request.
464
492
  if (ready.halt !== undefined)
465
493
  return haltResult(ready.halt);
466
494
  // DX-6392: every access answer names the dashboard it is on, not only the signed-in one (AC 57978).
467
- const answer = { ...ready.answer, dashboard: connectedDashboard(), ...(note ? { note } : {}) };
468
- return ready.isError ? haltResult(JSON.stringify(answer)) : jsonResult(answer);
495
+ const answer = {
496
+ ...ready.answer,
497
+ dashboard: connectedDashboard(),
498
+ ...(note ? { note } : {}),
499
+ };
500
+ return ready.isError
501
+ ? haltResult(JSON.stringify(answer))
502
+ : jsonResult(answer);
469
503
  }
470
504
  // DX-4390 / DX-4434 / DX-5549 / DX-5550: every tool's dashboard call goes through `guardedCall` (the agent gate, then the sign-in halt; see `guarded-calls.ts`).
471
- const { guardedCall } = makeGuardedCalls({ access: () => access, gate: agentGate });
505
+ const { guardedCall } = makeGuardedCalls({
506
+ access: () => access,
507
+ gate: agentGate,
508
+ });
509
+ // DX-7098 - the key of a system job this session's sub-agent took: memory only; `50arms_api` sends the model's calls with it while it is held.
510
+ const jobKey = new JobKeyHolder((line) => console.error(line));
472
511
  /** DX-4390 — a tool's dashboard call behind the sign-in halt (and the 401 sign-out). */
473
512
  async function guardedJson(run) {
474
513
  const guarded = await guardedCall(run);
475
- return "halt" in guarded ? haltResult(guarded.halt) : jsonResult(guarded.result);
514
+ return "halt" in guarded
515
+ ? haltResult(guarded.halt)
516
+ : jsonResult(guarded.result);
476
517
  }
477
518
  /** DX-4400 — `guardedJson` for the read tools whose answer can be a whole document: bounded. */
478
519
  async function guardedBoundedJson(run, opts) {
479
520
  const guarded = await guardedCall(run, opts);
480
- return "halt" in guarded ? haltResult(guarded.halt) : boundedJsonResult(guarded.result);
521
+ return "halt" in guarded
522
+ ? haltResult(guarded.halt)
523
+ : boundedJsonResult(guarded.result);
481
524
  }
482
525
  function jsonResult(value) {
483
526
  return {
@@ -605,7 +648,10 @@ renamedTool("50arms_api",
605
648
  .describe("Absolute path of an image file (png, jpg, webp, svg; max 1 MB) sent as the raw body instead of `body`."),
606
649
  ...boardField,
607
650
  // DX-5033 - sends x-danx-plugin-background (see DanxbotApiArgs.background); an agent setting it would hide its own calls from the pause and idle logic.
608
- background: z.boolean().optional().describe("Set only by plugin hooks; an agent never sets it."),
651
+ background: z
652
+ .boolean()
653
+ .optional()
654
+ .describe("Set only by plugin hooks; an agent never sets it."),
609
655
  },
610
656
  // DX-3997 — the result rides back verbatim, plus the dashboard's own `reminders[]` entries
611
657
  // for this plan-connected session (the server decides; `listener-reminder.ts` only relays).
@@ -614,10 +660,15 @@ renamedTool("50arms_api",
614
660
  const refused = termsAcceptanceCallHalt(args, config.baseUrl);
615
661
  if (refused)
616
662
  return haltResult(refused);
617
- const guarded = await guardedCall(() => danxbotApi(client, args), { gateOpen: isAgentGateOpenCall(args.method, args.path) });
663
+ // DX-7098: while a system job's key is held the model's calls go out on it (never the take, never a hook's background call).
664
+ const bearer = jobKey.bearerFor(args);
665
+ const guarded = await guardedCall(() => danxbotApi(client, args, {}, bearer ?? undefined), {
666
+ gateOpen: isAgentGateOpenCall(args.method, args.path),
667
+ foreignKey: bearer !== null,
668
+ });
618
669
  if ("halt" in guarded)
619
670
  return haltResult(guarded.halt);
620
- const result = guarded.result;
671
+ const result = jobKey.afterCall(args, guarded.result, bearer !== null);
621
672
  const halt = termsHaltFor(result);
622
673
  if (halt)
623
674
  return haltResult(halt);
@@ -632,7 +683,7 @@ renamedTool("50arms_api",
632
683
  renamedTool("50arms_api_list",
633
684
  // DX-3528 — the list is filtered by the same permission check every request takes.
634
685
  "Start here to find the route for any job: lists the dashboard API routes your credential may call, `{routes: " +
635
- "[\"METHOD /path/template\", ...]}`, the strings `50arms_api_spec` takes (`POST /api/issues/:id/transition`). A route " +
686
+ '["METHOD /path/template", ...]}`, the strings `50arms_api_spec` takes (`POST /api/issues/:id/transition`). A route ' +
636
687
  "not listed is not callable by you.", {},
637
688
  // DX-5765: with no agent held it lists exactly the two proposal routes an agent-less session may call.
638
689
  () => async () => {
@@ -655,7 +706,9 @@ renamedTool("50arms_api_spec",
655
706
  },
656
707
  // DX-5765: with no agent held it answers for the two proposal routes only; any other endpoint keeps the no-agent answer.
657
708
  () => async (args) => {
658
- return guardedBoundedJson(() => danxbotApiSpec(client, args), { gateOpen: isAgentGateOpenSpec(args.endpoints) });
709
+ return guardedBoundedJson(() => danxbotApiSpec(client, args), {
710
+ gateOpen: isAgentGateOpenSpec(args.endpoints),
711
+ });
659
712
  });
660
713
  // ---------------- attach_file (DX-3465 A4, checklist item 36140) ----------------
661
714
  //
@@ -668,24 +721,45 @@ renamedTool("50arms_api_spec",
668
721
  // — a role needs local-file-upload only when it deals with files an agent
669
722
  // might hold locally, e.g. the Slack recovery agent's CSV path).
670
723
  strictTool("attach_file", "Upload a LOCAL file. This server reads and uploads the bytes, so they never pass through your context. " +
671
- "`target: \"card\"` (default) attaches it to a card; `target: \"inline_image\"` uploads an image for a markdown body and replies `{url, markdown}` (below). The card attachment mirrors to the card's linked Trello card and Slack thread. 25 MB limit (413). " +
724
+ '`target: "card"` (default) attaches it to a card; `target: "inline_image"` uploads an image for a markdown body and replies `{url, markdown}` (below). The card attachment mirrors to the card\'s linked Trello card and Slack thread. 25 MB limit (413). ' +
672
725
  "Card target returns `{issue, attachment_id, url, thumbnail_url, is_primary}`: `url` is permanent, embed it in any " +
673
726
  "markdown field as `![description](url)` and it renders inline. Use it when a screenshot or file judges something faster than prose, or instead of pasting a " +
674
727
  "large CSV or log into a card field. " +
675
- "`target: \"inline_image\"` instead uploads a local png/jpeg/gif/webp/avif (25 MB) with NO card and returns `{url, markdown}`: put the " +
728
+ '`target: "inline_image"` instead uploads a local png/jpeg/gif/webp/avif (25 MB) with NO card and returns `{url, markdown}`: put the ' +
676
729
  "markdown in any markdown body, notably a `POST /api/feedback` body (`50arms_api`'s `body_file` sends one raw png/jpg/webp/svg of at most 1 MB to a route that takes a file; this tool adds the upload routes, gif/avif, and the 25 MB limit).", {
677
- target: z.enum(["card", "inline_image"]).optional().describe("`card` (default): attach to a card. `inline_image`: upload an image for a markdown body; takes only `path`."),
678
- card_id: z.string().min(1).optional().describe("The card id to attach the file to. Required for target `card`; not allowed with `inline_image`."),
679
- path: z.string().min(1).describe("Absolute local path on the machine this server runs on (`/tmp/a.png` or `C:\\x\\a.png`)."),
680
- filename: z.string().min(1).optional().describe("Override for the stored filename; default: path's basename."),
681
- content_type: z.string().min(1).optional().describe("Override for the stored MIME type; default: an extension guess."),
730
+ target: z
731
+ .enum(["card", "inline_image"])
732
+ .optional()
733
+ .describe("`card` (default): attach to a card. `inline_image`: upload an image for a markdown body; takes only `path`."),
734
+ card_id: z
735
+ .string()
736
+ .min(1)
737
+ .optional()
738
+ .describe("The card id to attach the file to. Required for target `card`; not allowed with `inline_image`."),
739
+ path: z
740
+ .string()
741
+ .min(1)
742
+ .describe("Absolute local path on the machine this server runs on (`/tmp/a.png` or `C:\\x\\a.png`)."),
743
+ filename: z
744
+ .string()
745
+ .min(1)
746
+ .optional()
747
+ .describe("Override for the stored filename; default: path's basename."),
748
+ content_type: z
749
+ .string()
750
+ .min(1)
751
+ .optional()
752
+ .describe("Override for the stored MIME type; default: an extension guess."),
682
753
  replaces: z
683
754
  .number()
684
755
  .int()
685
756
  .positive()
686
757
  .optional()
687
758
  .describe("Id of this card's attachment to replace in place: it keeps its id, name and cover flag. Not with `filename`."),
688
- primary: z.boolean().optional().describe("Make this attachment the card's single cover (lead image)."),
759
+ primary: z
760
+ .boolean()
761
+ .optional()
762
+ .describe("Make this attachment the card's single cover (lead image)."),
689
763
  ...boardField,
690
764
  }, async (args) => guardedJson(() => attachFile(client, args)));
691
765
  // ---------------- mini_app_publish (DX-5294, replaces DX-4077's design_publish) ----------------
@@ -713,8 +787,13 @@ strictTool("mini_app_publish", "Build a page with this repo's own mini app and p
713
787
  "design and call again. Limits: the frame has no network (use fixture props); on Windows name `node` and a committed script, never npm or npx.", {
714
788
  target: z
715
789
  .object({
716
- repo: repoNameArgSchema.optional().describe("The name of the repo whose mini app builds the page; default: the repo of the card's board."),
717
- name: z.string().min(1).describe("A mini app target's name, as listed in `mini_app_targets` of `GET /api/repos/<repo name>` (`50arms_api`, fields {mini_app_targets: true})."),
790
+ repo: repoNameArgSchema
791
+ .optional()
792
+ .describe("The name of the repo whose mini app builds the page; default: the repo of the card's board."),
793
+ name: z
794
+ .string()
795
+ .min(1)
796
+ .describe("A mini app target's name, as listed in `mini_app_targets` of `GET /api/repos/<repo name>` (`50arms_api`, fields {mini_app_targets: true})."),
718
797
  })
719
798
  .strict(),
720
799
  dir: z
@@ -727,21 +806,49 @@ strictTool("mini_app_publish", "Build a page with this repo's own mini app and p
727
806
  .describe("The revision note, shown beside the revision on the card: what changed since the last revision, which decision note it answers, what is still open."),
728
807
  destination: z
729
808
  .object({
730
- kind: z.literal("card_design").describe("Where the page goes: a design of a card."),
731
- card_id: z.string().min(1).describe("The card this design goes on: any existing card but an Epic or Feature."),
732
- design_no: z.number().int().positive().optional().describe("Add a revision to this existing design of the card (its `designs` relation). Not with `design_title`."),
733
- design_title: z.string().min(1).optional().describe("Start a NEW design on the card with this title, fixed for good. Not with `design_no`."),
734
- design_element: z.string().min(1).optional().describe("With `design_title` (required there, refused with `design_no`): the one thing this design decides, a few words (\"Indicator pill\", \"Popover layout\"). It joins that element's open design problem, matched ignoring case and extra spaces."),
809
+ kind: z
810
+ .literal("card_design")
811
+ .describe("Where the page goes: a design of a card."),
812
+ card_id: z
813
+ .string()
814
+ .min(1)
815
+ .describe("The card this design goes on: any existing card but an Epic or Feature."),
816
+ design_no: z
817
+ .number()
818
+ .int()
819
+ .positive()
820
+ .optional()
821
+ .describe("Add a revision to this existing design of the card (its `designs` relation). Not with `design_title`."),
822
+ design_title: z
823
+ .string()
824
+ .min(1)
825
+ .optional()
826
+ .describe("Start a NEW design on the card with this title, fixed for good. Not with `design_no`."),
827
+ design_element: z
828
+ .string()
829
+ .min(1)
830
+ .optional()
831
+ .describe('With `design_title` (required there, refused with `design_no`): the one thing this design decides, a few words ("Indicator pill", "Popover layout"). It joins that element\'s open design problem, matched ignoring case and extra spaces.'),
735
832
  })
736
833
  .strict(),
737
834
  option_groups: z
738
835
  .array(z
739
836
  .object({
740
- key: z.string().describe("The stable id a pick is recorded under (non-blank, at most 40 characters, unique among the groups)."),
741
- label: z.string().describe("The group's name as the viewer shows it (non-blank, at most 30 characters)."),
742
- options: z.array(z.string()).describe("The group's choices, each one short phrase, word or letter (non-blank, at most 30 characters, unique in the group)."),
743
- multiple: z.boolean().describe("true when a person may pick several options, false for exactly one."),
744
- recommended: z.array(z.string()).describe("Your recommended pick(s), each one of `options`: exactly one when `multiple` is false, at least one when true. Every group starts on them."),
837
+ key: z
838
+ .string()
839
+ .describe("The stable id a pick is recorded under (non-blank, at most 40 characters, unique among the groups)."),
840
+ label: z
841
+ .string()
842
+ .describe("The group's name as the viewer shows it (non-blank, at most 30 characters)."),
843
+ options: z
844
+ .array(z.string())
845
+ .describe("The group's choices, each one short phrase, word or letter (non-blank, at most 30 characters, unique in the group)."),
846
+ multiple: z
847
+ .boolean()
848
+ .describe("true when a person may pick several options, false for exactly one."),
849
+ recommended: z
850
+ .array(z.string())
851
+ .describe("Your recommended pick(s), each one of `options`: exactly one when `multiple` is false, at least one when true. Every group starts on them."),
745
852
  })
746
853
  .strict())
747
854
  .optional()
@@ -756,7 +863,9 @@ strictTool("mini_app_publish", "Build a page with this repo's own mini app and p
756
863
  "RESTATE it whole every revision (a new revision starts unticked). Ticking never blocks approval. A missing or empty list, or a blank item, is a 400."),
757
864
  browser_check: z
758
865
  .object({
759
- status: z.enum(["checked", "not_checked"]).describe("checked: you looked at it in a browser; not_checked: you had none."),
866
+ status: z
867
+ .enum(["checked", "not_checked"])
868
+ .describe("checked: you looked at it in a browser; not_checked: you had none."),
760
869
  note: z
761
870
  .string()
762
871
  .regex(/\S/)
@@ -770,9 +879,20 @@ strictTool("mini_app_publish", "Build a page with this repo's own mini app and p
770
879
  .min(1)
771
880
  .optional()
772
881
  .describe("With `design_title`; required when this publish opens a design problem (no open one for `design_element`), refused otherwise: one plain question naming what is being designed, at most 200 characters."),
773
- problem_summary: z.string().min(1).optional().describe("With `problem_statement`: 1-3 plain sentences."),
774
- problem_context: z.string().min(1).optional().describe("With `problem_statement`: markdown background for a first-time reader."),
775
- }, async (args) => guardedJson(() => miniAppPublish(client, args, { baseUrl: config.baseUrl, cwd: process.cwd() })));
882
+ problem_summary: z
883
+ .string()
884
+ .min(1)
885
+ .optional()
886
+ .describe("With `problem_statement`: 1-3 plain sentences."),
887
+ problem_context: z
888
+ .string()
889
+ .min(1)
890
+ .optional()
891
+ .describe("With `problem_statement`: markdown background for a first-time reader."),
892
+ }, async (args) => guardedJson(() => miniAppPublish(client, args, {
893
+ baseUrl: config.baseUrl,
894
+ cwd: process.cwd(),
895
+ })));
776
896
  // ---------------- mini_app_restore (DX-6070) ----------------
777
897
  //
778
898
  // Agent-specific like mini_app_publish: it WRITES local files, which `50arms_api` cannot. A design's source is stored with every revision on the
@@ -785,8 +905,17 @@ strictTool("mini_app_restore", "Write a design revision's stored source back to
785
905
  "Files with equal content are `unchanged`; files in the folder that the revision lacks are left alone and listed in `extra_local`. " +
786
906
  "Returns `{design_dir, revision_no, built_from_commit, written, unchanged, extra_local}`.", {
787
907
  card_id: z.string().min(1).describe("The card the design is on."),
788
- design_no: z.number().int().positive().describe("The design's number on the card (its `designs` relation)."),
789
- revision_no: z.number().int().positive().optional().describe("The revision to restore; default: the design's latest."),
908
+ design_no: z
909
+ .number()
910
+ .int()
911
+ .positive()
912
+ .describe("The design's number on the card (its `designs` relation)."),
913
+ revision_no: z
914
+ .number()
915
+ .int()
916
+ .positive()
917
+ .optional()
918
+ .describe("The revision to restore; default: the design's latest."),
790
919
  }, async (args) => guardedJson(() => miniAppRestore(client, args, { cwd: process.cwd() })));
791
920
  // ---------------- plugin_publish (DX-5237, parent DX-4679) ----------------
792
921
  //
@@ -797,11 +926,27 @@ strictTool("plugin_publish", "Build a card-type plugin project (Vite, `danxPlugi
797
926
  "`plugin` (a new key creates it): uploads `dist/`, the source `.tar.gz` and a screenshot of the plugin's own render (its `CardView` drawn with a sample card on the dashboard's `/plugin-preview` page). " +
798
927
  "Returns `{ok: true, status, body: {plugin, plugin_id, revision_id, revision_no, approval_url, screenshot}}`: `approval_url` is Settings > Plugins, where a team admin approves the revision; you cannot. " +
799
928
  "`screenshot` is `captured` or `none: <reason>` (the publish still succeeds). A build error throws with the build's output; a refused upload comes back verbatim as `{ok: false, status, body, plugin, step}`.", {
800
- dir: z.string().min(1).describe("The project directory: absolute, or relative to this server's cwd."),
801
- plugin: z.string().min(1).describe("The plugin's key: lowercase letters, digits, - and _, at most 64."),
802
- note: z.string().min(1).describe("What this revision changes, shown to the approver."),
803
- name: z.string().min(1).optional().describe("Display name for a plugin this call creates; default: the key."),
804
- }, async (args) => guardedJson(() => pluginPublish(client, args, { baseUrl: config.baseUrl, cwd: process.cwd() })));
929
+ dir: z
930
+ .string()
931
+ .min(1)
932
+ .describe("The project directory: absolute, or relative to this server's cwd."),
933
+ plugin: z
934
+ .string()
935
+ .min(1)
936
+ .describe("The plugin's key: lowercase letters, digits, - and _, at most 64."),
937
+ note: z
938
+ .string()
939
+ .min(1)
940
+ .describe("What this revision changes, shown to the approver."),
941
+ name: z
942
+ .string()
943
+ .min(1)
944
+ .optional()
945
+ .describe("Display name for a plugin this call creates; default: the key."),
946
+ }, async (args) => guardedJson(() => pluginPublish(client, args, {
947
+ baseUrl: config.baseUrl,
948
+ cwd: process.cwd(),
949
+ })));
805
950
  // ---------------- docs_search / docs_read (DX-5582) ----------------
806
951
  //
807
952
  // One pair of tools over three places a docs root lives (`source`): this checkout's `docs/pages`, another local docs root, or a team repo's hosted
@@ -810,13 +955,25 @@ strictTool("plugin_publish", "Build a card-type plugin project (Vite, `danxPlugi
810
955
  strictTool("docs_search", "Search docs with the shared @50arms/docs engine. Returns `{query, results: [{id, type, title, summary, file, bytes, lines, look_in?}]}`, best first, never a page body; " +
811
956
  "then `docs_read` the id you pick. `file` is an absolute path for local/dir and the page's path in the repo's docs for remote; `bytes`/`lines` size it for offset/limit reads.", {
812
957
  source: docsSourceShape,
813
- query: z.string().min(1).describe("A question or the words a page would use."),
814
- limit: z.number().int().min(1).max(MAX_SEARCH_LIMIT).optional().describe(`Most results (default ${DEFAULT_LIMIT}).`),
958
+ query: z
959
+ .string()
960
+ .min(1)
961
+ .describe("A question or the words a page would use."),
962
+ limit: z
963
+ .number()
964
+ .int()
965
+ .min(1)
966
+ .max(MAX_SEARCH_LIMIT)
967
+ .optional()
968
+ .describe(`Most results (default ${DEFAULT_LIMIT}).`),
815
969
  }, async (args) => guardedJson(() => docsSearch(client, args, { cwd: process.cwd() })));
816
970
  strictTool("docs_read", "Get a docs page as a file on this machine: returns `{id, path, bytes, lines}`, never the text. local/dir: the page's own file. remote: a fresh copy fetched from the dashboard into the temp directory. " +
817
971
  "Read `path` with your own file tools (offset/limit, grep). An unknown id is refused with the nearest ids.", {
818
972
  source: docsSourceShape,
819
- id: z.string().min(1).describe("A page id from docs_search, e.g. topic.mini-apps."),
973
+ id: z
974
+ .string()
975
+ .min(1)
976
+ .describe("A page id from docs_search, e.g. topic.mini-apps."),
820
977
  }, async (args) => guardedJson(() => docsRead(client, args, { cwd: process.cwd() })));
821
978
  // ---------------- request_permission (DX-4434, parent DX-4432) ----------------
822
979
  strictTool("request_permission", "Ask a person to grant this key ONE MORE permission. Call it when a call was refused `403 forbidden` naming a " +
@@ -830,7 +987,10 @@ strictTool("request_permission", "Ask a person to grant this key ONE MORE permis
830
987
  .array(z.string().min(1))
831
988
  .min(1)
832
989
  .describe("The permission keys to ask for: the `permission` a `403 forbidden` named."),
833
- reason: z.string().min(1).describe("Why you need them; shown to the person who approves."),
990
+ reason: z
991
+ .string()
992
+ .min(1)
993
+ .describe("Why you need them; shown to the person who approves."),
834
994
  }, async (args) => {
835
995
  const asked = await permissionRequests.ask(args);
836
996
  if ("halt" in asked)
@@ -878,15 +1038,19 @@ strictTool("session_connect",
878
1038
  .min(1)
879
1039
  .optional()
880
1040
  .describe("What to hold: `PLAN-n` (a plan's `ref` in `50arms_api` `GET /api/plans`) or a card's id as the board shows it, for a card on no plan. Omit only to sign in (it still takes your team agent)."),
881
- title: z
882
- .string()
883
- .min(1)
884
- .optional()
885
- .describe(
1041
+ title: z.string().min(1).optional().describe(
886
1042
  // DX-4608: stored as sent; a wrong one does not refuse the connect, the reply's `naming` says what to rename it to.
887
- 'The `naming` block\'s exact `{Name}: PLAN-NNN {short title}` or `{Name}: {CARD-ID} {card title}`, after renaming this thread. Omit on the first connect.'),
888
- assignment_id: z.number().int().positive().optional().describe("The assignment this connect answers, when a person's assignment message names one. Refused `assignment_ended` once it is over: then do nothing more about it."),
889
- disconnect: z.boolean().optional().describe("true = leave `target` (the plan or card you hold); no `title`."),
1043
+ "The `naming` block's exact `{Name}: PLAN-NNN {short title}` or `{Name}: {CARD-ID} {card title}`, after renaming this thread. Omit on the first connect."),
1044
+ assignment_id: z
1045
+ .number()
1046
+ .int()
1047
+ .positive()
1048
+ .optional()
1049
+ .describe("The assignment this connect answers, when a person's assignment message names one. Refused `assignment_ended` once it is over: then do nothing more about it."),
1050
+ disconnect: z
1051
+ .boolean()
1052
+ .optional()
1053
+ .describe("true = leave `target` (the plan or card you hold); no `title`."),
890
1054
  role: z
891
1055
  .string()
892
1056
  // Keep in step with `ROLE_KEY_PATTERN` (`src/lib/auth-rules.ts`): this published package cannot import the service's source.
@@ -900,16 +1064,10 @@ strictTool("session_connect",
900
1064
  .min(1)
901
1065
  .optional()
902
1066
  .describe("The one-use token the session that started this one passed in its prompt. With it a signed-out session signs in with no person approving it; a token that cannot be used says why and the session asks a person as usual. Omit it otherwise."),
903
- person_sign_in: z
904
- .boolean()
905
- .optional()
906
- .describe(
1067
+ person_sign_in: z.boolean().optional().describe(
907
1068
  // DX-6894 (DEC-589): set only by the plugin band when a PERSON presses its Sign in; the one call that leaves a revoked key's stop.
908
1069
  "Set only by the plugin's Sign in button when a person presses it; an agent never sets it. On a session whose key a person revoked it lifts the stop and starts a new access request a person must approve; any call without it still answers the stop."),
909
- registration_only: z
910
- .boolean()
911
- .optional()
912
- .describe(
1070
+ registration_only: z.boolean().optional().describe(
913
1071
  // DX-7010: set only by the plugin band; it answers before `ensureAccess`, so it makes no access request and claims no team agent.
914
1072
  "Set only by the plugin's band; an agent never sets it. Answers whether this machine is registered, `machine_registered` or the registration link, and makes no access request."),
915
1073
  },
@@ -918,7 +1076,10 @@ strictTool("session_connect",
918
1076
  // must resolve (the relay needs none of this: it lives in each server, with that server's own credential).
919
1077
  async (args) => {
920
1078
  if (args.registration_only === true)
921
- return accessReply({ signedIn: false, ...(await access.registrationOnly()) });
1079
+ return accessReply({
1080
+ signedIn: false,
1081
+ ...(await access.registrationOnly()),
1082
+ });
922
1083
  // DX-6894 — a person's Sign in press leaves the revoked stop; every call without it still answers that stop.
923
1084
  if (args.person_sign_in === true)
924
1085
  access.personSignIn();
@@ -945,7 +1106,11 @@ async (args) => {
945
1106
  void reportCheckoutDocsRoot();
946
1107
  return jsonResult({
947
1108
  ...claimed.body,
948
- ...(agentGate.current() === null ? { instruction: "This session is signed in. Call `session_connect` with `target` to connect it to a plan or a card." } : {}),
1109
+ ...(agentGate.current() === null
1110
+ ? {
1111
+ instruction: "This session is signed in. Call `session_connect` with `target` to connect it to a plan or a card.",
1112
+ }
1113
+ : {}),
949
1114
  });
950
1115
  }
951
1116
  // DX-6089: the role text lands in a local file; the reply names it (`role-instruction-file.ts`).
@@ -1014,7 +1179,12 @@ strictTool("plan_events_wait",
1014
1179
  "current turn ends. `acks`: events to acknowledge as `text` says, else re-sent. " +
1015
1180
  "One wait per session: a newer call ends the older. " +
1016
1181
  "`transcript_path` is the session's transcript file, for its usage and title.", {
1017
- plan_id: z.number().int().positive().nullable().describe("Number of the plan this session is connected to (the `n` of `PLAN-n`, within your team), or null when it is on no plan."),
1182
+ plan_id: z
1183
+ .number()
1184
+ .int()
1185
+ .positive()
1186
+ .nullable()
1187
+ .describe("Number of the plan this session is connected to (the `n` of `PLAN-n`, within your team), or null when it is on no plan."),
1018
1188
  cursor: z
1019
1189
  .string()
1020
1190
  .nullable()
@@ -0,0 +1,47 @@
1
+ /** The take route, `POST /api/issues/:id/system-job`. */
2
+ const TAKE_PATH = /^\/api\/issues\/[^/?]+\/system-job(?:\?.*)?$/;
3
+ /** The dispatch-complete call that ends a job. */
4
+ const COMPLETE_PATH = "/api/dispatch-callbacks/complete";
5
+ /** Stands in for `job_key` in the answer the model reads. */
6
+ export const JOB_KEY_HELD_NOTE = "held by the platform MCP: your 50arms_api calls now go out on the job's key until the dispatch-complete call answers";
7
+ export class JobKeyHolder {
8
+ log;
9
+ key = null;
10
+ constructor(log = () => undefined) {
11
+ this.log = log;
12
+ }
13
+ /** Whether a job key is held now. */
14
+ held() {
15
+ return this.key !== null;
16
+ }
17
+ /** The bearer `call` goes out with: the job key while one is held, except for a take and a background call; `null` means the session's own key. */
18
+ bearerFor(call) {
19
+ if (this.key === null || call.background === true || isTake(call))
20
+ return null;
21
+ return this.key;
22
+ }
23
+ /**
24
+ * After `call` answered `result` (`viaJobKey`: it went out on the job key): a take's answer gives up its `job_key` to this holder and the model reads the
25
+ * answer without it; the job key ends on a 2xx dispatch-complete answer or a 401 to a call made with it. Answers the result the model reads.
26
+ */
27
+ afterCall(call, result, viaJobKey) {
28
+ if (viaJobKey &&
29
+ (result.status === 401 ||
30
+ (result.ok && call.method === "POST" && pathOf(call) === COMPLETE_PATH))) {
31
+ this.key = null;
32
+ this.log(`[platform-mcp] the system job's key ended (${result.status} on ${call.method} ${pathOf(call)}); calls go out on the session's key again`);
33
+ return result;
34
+ }
35
+ if (!isTake(call) || !result.ok)
36
+ return result;
37
+ const body = result.body;
38
+ const jobKey = body?.job_key;
39
+ if (typeof jobKey !== "string" || jobKey === "")
40
+ throw new Error("[platform-mcp] a system-job take answered no job_key");
41
+ this.key = jobKey;
42
+ this.log(`[platform-mcp] took a system job (dispatch ${String(body?.dispatch_id)}); the model's calls go out on its key`);
43
+ return { ...result, body: { ...body, job_key: JOB_KEY_HELD_NOTE } };
44
+ }
45
+ }
46
+ const pathOf = (call) => call.path.split("?", 1)[0];
47
+ const isTake = (call) => call.method === "POST" && TAKE_PATH.test(call.path);
package/dist/json-body.js CHANGED
@@ -6,7 +6,9 @@
6
6
  * dashboard error name, only that a JSON object may carry a top-level string field named `error`.
7
7
  */
8
8
  export function errorCodeOf(body) {
9
- return typeof body === "object" && body !== null && typeof body.error === "string"
9
+ return typeof body === "object" &&
10
+ body !== null &&
11
+ typeof body.error === "string"
10
12
  ? body.error
11
13
  : null;
12
14
  }
@@ -8,7 +8,8 @@ export function keyRevocationOf(result) {
8
8
  const body = result.body;
9
9
  if (body?.error !== "key_revoked")
10
10
  return null;
11
- if (typeof body.revokedBy !== "string" || typeof body.revokedAt !== "string") {
11
+ if (typeof body.revokedBy !== "string" ||
12
+ typeof body.revokedAt !== "string") {
12
13
  throw new Error("[platform-mcp] a key_revoked refusal carried no revokedBy / revokedAt");
13
14
  }
14
15
  return { revokedBy: body.revokedBy, revokedAt: body.revokedAt };