@50arms/platform-mcp 0.1.464 → 0.1.465

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) 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 +6 -2
  15. package/dist/handlers.js +66 -14
  16. package/dist/heartbeat-reporter.js +8 -3
  17. package/dist/http-client.js +4 -2
  18. package/dist/index.js +242 -80
  19. package/dist/job-key.js +3 -1
  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.js +6 -2
  52. package/dist/session-access.js +110 -32
  53. package/dist/session-connection.js +23 -7
  54. package/dist/session-control-file.js +1 -1
  55. package/dist/session-key.js +12 -4
  56. package/dist/session-options.js +6 -2
  57. package/dist/session-stats.js +2 -1
  58. package/dist/session-stream.js +81 -20
  59. package/dist/shutdown.js +3 -1
  60. package/dist/subagents-live.js +8 -2
  61. package/dist/terms-halt.js +4 -2
  62. package/dist/tool-access.js +17 -4
  63. package/dist/tool-surface.js +9 -2
  64. package/dist/transcript-lineage.js +5 -2
  65. package/dist/urgent-records.js +1 -0
  66. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { assertVersionFloorSatisfied, MCP_MIN_VERSION_HEADER } from "./version-floor.js";
1
+ import { assertVersionFloorSatisfied, MCP_MIN_VERSION_HEADER, } from "./version-floor.js";
2
2
  function baseOf(dashboardUrl) {
3
3
  return dashboardUrl.replace(/\/+$/, "");
4
4
  }
@@ -7,7 +7,10 @@ export async function postPublic(fetchImpl, url, body) {
7
7
  try {
8
8
  res = await fetchImpl(url, {
9
9
  method: "POST",
10
- headers: { "Content-Type": "application/json", Accept: "application/json" },
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ Accept: "application/json",
13
+ },
11
14
  body: JSON.stringify(body),
12
15
  });
13
16
  }
@@ -34,7 +37,9 @@ export async function postPublic(fetchImpl, url, body) {
34
37
  const DEFAULT_RETRY_AFTER_SECONDS = 1;
35
38
  export function retryAfterSeconds(headers) {
36
39
  const seconds = Number(headers.get("retry-after"));
37
- return Number.isFinite(seconds) && seconds > 0 ? seconds : DEFAULT_RETRY_AFTER_SECONDS;
40
+ return Number.isFinite(seconds) && seconds > 0
41
+ ? seconds
42
+ : DEFAULT_RETRY_AFTER_SECONDS;
38
43
  }
39
44
  function isCreated(value) {
40
45
  if (typeof value !== "object" || value === null)
@@ -50,7 +55,9 @@ function isCreated(value) {
50
55
  export async function createAccessRequest(fetchImpl, dashboardUrl, input) {
51
56
  const url = `${baseOf(dashboardUrl)}/api/access-requests`;
52
57
  const { status, headers, json } = await postPublic(fetchImpl, url, input);
53
- if (status === 403 && json?.error === "machine_registration_mismatch")
58
+ if (status === 403 &&
59
+ json?.error ===
60
+ "machine_registration_mismatch")
54
61
  return { kind: "machine_registration_mismatch" };
55
62
  if (status === 201) {
56
63
  if (!isCreated(json)) {
@@ -61,7 +68,10 @@ export async function createAccessRequest(fetchImpl, dashboardUrl, input) {
61
68
  if (status === 404)
62
69
  return { kind: "dashboard_outdated" };
63
70
  if (status === 429)
64
- return { kind: "rate_limited", retryAfterSeconds: retryAfterSeconds(headers) };
71
+ return {
72
+ kind: "rate_limited",
73
+ retryAfterSeconds: retryAfterSeconds(headers),
74
+ };
65
75
  return { kind: "refused", status, body: json };
66
76
  }
67
77
  /**
@@ -75,7 +85,10 @@ export async function claimAccessRequest(fetchImpl, dashboardUrl, secret, labelI
75
85
  if (status === 404)
76
86
  return { kind: "not_found" };
77
87
  if (status === 429)
78
- return { kind: "rate_limited", retryAfterSeconds: retryAfterSeconds(headers) };
88
+ return {
89
+ kind: "rate_limited",
90
+ retryAfterSeconds: retryAfterSeconds(headers),
91
+ };
79
92
  if (status !== 200)
80
93
  return { kind: "refused", status, body: json };
81
94
  const body = json;
@@ -6,7 +6,9 @@ export function agentBlockedReplyOf(body) {
6
6
  return null;
7
7
  const state = body.state;
8
8
  const instruction = body.instruction;
9
- if (typeof state !== "string" || !BLOCKED_STATES.has(state) || typeof instruction !== "string")
9
+ if (typeof state !== "string" ||
10
+ !BLOCKED_STATES.has(state) ||
11
+ typeof instruction !== "string")
10
12
  return null;
11
13
  return body;
12
14
  }
@@ -47,16 +49,22 @@ export function agentGateHalt(gate) {
47
49
  * DX-5724 / DX-5765: the ONE list of the two routes a session with no agent may still reach (propose an agent, then attach its avatar), as the route templates
48
50
  * `50arms_api_list` reports and `50arms_api_spec` takes. Pinned to the server's AGENT_GATE_OPEN_ROUTES by src/dashboard/agent-gate-mcp-pin.test.ts.
49
51
  */
50
- export const AGENT_PROPOSAL_ENDPOINTS = ["POST /api/team/agent-proposals", "POST /api/team/agent-proposals/:publicId/avatar"];
52
+ export const AGENT_PROPOSAL_ENDPOINTS = [
53
+ "POST /api/team/agent-proposals",
54
+ "POST /api/team/agent-proposals/:publicId/avatar",
55
+ ];
51
56
  /** The call regex, derived from {@link AGENT_PROPOSAL_ENDPOINTS}: a proposal's public id is 32 hex characters. */
52
- const AGENT_PROPOSAL_ROUTE = new RegExp("^(?:" + AGENT_PROPOSAL_ENDPOINTS.map((e) => e.replace(/^POST /, "").replace(":publicId", "[0-9a-f]{32}")).join("|") + ")$");
57
+ const AGENT_PROPOSAL_ROUTE = new RegExp("^(?:" +
58
+ AGENT_PROPOSAL_ENDPOINTS.map((e) => e.replace(/^POST /, "").replace(":publicId", "[0-9a-f]{32}")).join("|") +
59
+ ")$");
53
60
  /** Whether `50arms_api` may make this call with the gate closed. */
54
61
  export function isAgentGateOpenCall(method, path) {
55
62
  return method === "POST" && AGENT_PROPOSAL_ROUTE.test(path);
56
63
  }
57
64
  /** Whether `50arms_api_spec` may answer with the gate closed: only when every named endpoint is one of the two proposal routes. */
58
65
  export function isAgentGateOpenSpec(endpoints) {
59
- return endpoints.length > 0 && endpoints.every((e) => AGENT_PROPOSAL_ENDPOINTS.includes(e));
66
+ return (endpoints.length > 0 &&
67
+ endpoints.every((e) => AGENT_PROPOSAL_ENDPOINTS.includes(e)));
60
68
  }
61
69
  /** The `50arms_api_list` answer with the gate closed: the dashboard's list narrowed to the two proposal routes; a refusal passes through. */
62
70
  export function onlyAgentProposalRoutes(result) {
@@ -65,5 +73,11 @@ export function onlyAgentProposalRoutes(result) {
65
73
  const routes = result.body.routes;
66
74
  if (!Array.isArray(routes))
67
75
  return result;
68
- return { ...result, body: { ...result.body, routes: routes.filter((r) => AGENT_PROPOSAL_ENDPOINTS.includes(r)) } };
76
+ return {
77
+ ...result,
78
+ body: {
79
+ ...result.body,
80
+ routes: routes.filter((r) => AGENT_PROPOSAL_ENDPOINTS.includes(r)),
81
+ },
82
+ };
69
83
  }
package/dist/board-id.js CHANGED
@@ -21,7 +21,13 @@ export function parseBoardRefText(raw) {
21
21
  }
22
22
  /** The `board` tool argument: a board ref as a number or its decimal text, always handed on as the number (an overflowing text is refused by the pipe). */
23
23
  export const boardRefArgSchema = z
24
- .union([z.number().int().positive(), z.string().regex(BOARD_ID_PATTERN).transform(Number)])
24
+ .union([
25
+ z.number().int().positive(),
26
+ z.string().regex(BOARD_ID_PATTERN).transform(Number),
27
+ ])
25
28
  .pipe(z.number().int().positive().safe());
26
29
  /** The `repo` tool argument (DX-6554, DEC-269): a repo's name, in the characters a name may hold (the `repos_name_url_safe` constraint), so it is safe in a URL path and a file name. */
27
- export const repoNameArgSchema = z.string().regex(/^[A-Za-z0-9._-]+$/).refine((name) => name !== "." && name !== "..", "a repo name is not . or ..");
30
+ export const repoNameArgSchema = z
31
+ .string()
32
+ .regex(/^[A-Za-z0-9._-]+$/)
33
+ .refine((name) => name !== "." && name !== "..", "a repo name is not . or ..");
@@ -35,7 +35,10 @@ export async function readCheckoutDocsRoot(cwd, git = runGit, exists = existsSyn
35
35
  return null;
36
36
  try {
37
37
  const top = await git(cwd, ["rev-parse", "--show-toplevel"]);
38
- return { repo, docs_root: exists(join(top, ...DOCS_ROOT.split("/"))) ? DOCS_ROOT : "" };
38
+ return {
39
+ repo,
40
+ docs_root: exists(join(top, ...DOCS_ROOT.split("/"))) ? DOCS_ROOT : "",
41
+ };
39
42
  }
40
43
  catch {
41
44
  return null;
@@ -43,7 +46,12 @@ export async function readCheckoutDocsRoot(cwd, git = runGit, exists = existsSyn
43
46
  }
44
47
  export function reportCheckoutDocsRoot(client, report) {
45
48
  // This process reports on its own, never as the agent working: `requestOwn` marks it background (DX-5076, DX-5354).
46
- return client.requestOwn({ method: "POST", path: "/me/docs-root", basePath: "/api/plan-sessions", body: { ...report } });
49
+ return client.requestOwn({
50
+ method: "POST",
51
+ path: "/me/docs-root",
52
+ basePath: "/api/plan-sessions",
53
+ body: { ...report },
54
+ });
47
55
  }
48
56
  /** Started by each connect that holds an agent and never awaited by it, so it never throws. */
49
57
  export function createCheckoutDocsRootReporter(client, cwd, read = readCheckoutDocsRoot) {
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import { homedir } from "node:os";
18
18
  import { prefixedLine } from "./one-line.js";
19
- import { sessionControlDir, sessionControlFilePath, sessionControlFilesIn } from "./session-control-file.js";
19
+ import { sessionControlDir, sessionControlFilePath, sessionControlFilesIn, } from "./session-control-file.js";
20
20
  /** The longest ask line relayed whole (the compaction request's bound): the dashboard's ask fits well under it, with a job's capped label. */
21
21
  export const CLEAR_ASK_MAX_CODE_POINTS = 1500;
22
22
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -32,7 +32,10 @@ export function invalidClearReason(value) {
32
32
  return "control is not an object or null";
33
33
  if (c.v !== 1)
34
34
  return `control version ${JSON.stringify(c.v)} is not 1`;
35
- if (c.ask !== null && !(isRecord(c.ask) && isNonEmptyString(c.ask.at) && isNonEmptyString(c.ask.text)))
35
+ if (c.ask !== null &&
36
+ !(isRecord(c.ask) &&
37
+ isNonEmptyString(c.ask.at) &&
38
+ isNonEmptyString(c.ask.text)))
36
39
  return "ask must be null or {at, text}";
37
40
  if (c.release_id !== null && !isNonEmptyString(c.release_id))
38
41
  return "release_id must be a string or null";
@@ -51,7 +54,14 @@ export function formatClearAskLine(ask) {
51
54
  }
52
55
  /** The file of session `sessionId` for `control` after the ask `askedAt` was shown last. */
53
56
  export function clearFileOf(control, askedAt, sessionId) {
54
- return { v: 1, sessionId, control: control === null || control.release_id === null ? null : { releaseId: control.release_id }, askedAt };
57
+ return {
58
+ v: 1,
59
+ sessionId,
60
+ control: control === null || control.release_id === null
61
+ ? null
62
+ : { releaseId: control.release_id },
63
+ askedAt,
64
+ };
55
65
  }
56
66
  const CLEAR_DIR = "clear";
57
67
  export function clearDir(home = homedir()) {
@@ -63,7 +73,11 @@ export function clearFilePath(sessionId, home = homedir()) {
63
73
  }
64
74
  export function parseClearFile(text, where) {
65
75
  const parsed = JSON.parse(text);
66
- if (!isRecord(parsed) || parsed.v !== 1 || typeof parsed.sessionId !== "string" || !("control" in parsed) || (parsed.askedAt !== null && typeof parsed.askedAt !== "string")) {
76
+ if (!isRecord(parsed) ||
77
+ parsed.v !== 1 ||
78
+ typeof parsed.sessionId !== "string" ||
79
+ !("control" in parsed) ||
80
+ (parsed.askedAt !== null && typeof parsed.askedAt !== "string")) {
67
81
  throw new Error(`${where} is not a clear file`);
68
82
  }
69
83
  const c = parsed.control;
@@ -23,13 +23,18 @@
23
23
  */
24
24
  import { homedir } from "node:os";
25
25
  import { prefixedLine } from "./one-line.js";
26
- import { sessionControlDir, sessionControlFilePath, sessionControlFilesIn } from "./session-control-file.js";
26
+ import { sessionControlDir, sessionControlFilePath, sessionControlFilesIn, } from "./session-control-file.js";
27
27
  /** The longest request line relayed whole (the pacing line's bound): the dashboard's request is a few hundred characters. */
28
28
  export const COMPACTION_ASK_MAX_CODE_POINTS = 1000;
29
29
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
30
30
  const isCount = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
31
31
  const isTime = (v) => typeof v === "number" && Number.isFinite(v);
32
- const isAsk = (a) => isRecord(a) && isCount(a.seq) && typeof a.at === "string" && a.at !== "" && typeof a.text === "string" && a.text.trim() !== "";
32
+ const isAsk = (a) => isRecord(a) &&
33
+ isCount(a.seq) &&
34
+ typeof a.at === "string" &&
35
+ a.at !== "" &&
36
+ typeof a.text === "string" &&
37
+ a.text.trim() !== "";
33
38
  /** Why an ask / release pair (the main agent's, or a sub-agent's) cannot be read, or `null` when it can. */
34
39
  function invalidAskAndRelease(c) {
35
40
  if (c.ask !== null && !isAsk(c.ask))
@@ -38,7 +43,8 @@ function invalidAskAndRelease(c) {
38
43
  return "releaseUntilMs and releaseId are both set or both null";
39
44
  if (c.releaseUntilMs !== null && !isTime(c.releaseUntilMs))
40
45
  return "releaseUntilMs must be a number or null";
41
- if (c.releaseId !== null && (typeof c.releaseId !== "string" || c.releaseId === ""))
46
+ if (c.releaseId !== null &&
47
+ (typeof c.releaseId !== "string" || c.releaseId === ""))
42
48
  return "releaseId must be a string or null";
43
49
  return null;
44
50
  }
@@ -53,7 +59,9 @@ export function invalidCompactionReason(value) {
53
59
  return "control is not an object or null";
54
60
  if (c.v !== 1)
55
61
  return `control version ${JSON.stringify(c.v)} is not 1`;
56
- if (!isCount(c.floorTokens) || !isCount(c.passAtTokens) || !isCount(c.windowTokens))
62
+ if (!isCount(c.floorTokens) ||
63
+ !isCount(c.passAtTokens) ||
64
+ !isCount(c.windowTokens))
57
65
  return "floorTokens, passAtTokens and windowTokens must be whole numbers";
58
66
  // DX-4993: the plugin refuses a control whose valve is not above its floor, and the dashboard never sends one; a frame that would become such a file is a fault line
59
67
  if (c.passAtTokens <= c.floorTokens)
@@ -111,7 +119,10 @@ export function fileOf(control, askedAt, sessionId) {
111
119
  windowTokens: control.windowTokens,
112
120
  releaseUntilMs: control.releaseUntilMs,
113
121
  releaseId: control.releaseId,
114
- agents: Object.fromEntries(Object.entries(control.agents).map(([id, a]) => [id, { passAtTokens: a.passAtTokens }])),
122
+ agents: Object.fromEntries(Object.entries(control.agents).map(([id, a]) => [
123
+ id,
124
+ { passAtTokens: a.passAtTokens },
125
+ ])),
115
126
  valves: control.valves,
116
127
  mode: control.mode,
117
128
  },
@@ -128,10 +139,22 @@ export function compactionFilePath(sessionId, home = homedir()) {
128
139
  }
129
140
  export function parseCompactionFile(text, where) {
130
141
  const parsed = JSON.parse(text);
131
- if (!isRecord(parsed) || parsed.v !== 1 || typeof parsed.sessionId !== "string" || !("control" in parsed) || (parsed.askedAt !== null && typeof parsed.askedAt !== "string")) {
142
+ if (!isRecord(parsed) ||
143
+ parsed.v !== 1 ||
144
+ typeof parsed.sessionId !== "string" ||
145
+ !("control" in parsed) ||
146
+ (parsed.askedAt !== null && typeof parsed.askedAt !== "string")) {
132
147
  throw new Error(`${where} is not a compaction file`);
133
148
  }
134
- const reason = parsed.control === null ? null : invalidCompactionReason({ control: { ...parsed.control, v: 1, ask: null } });
149
+ const reason = parsed.control === null
150
+ ? null
151
+ : invalidCompactionReason({
152
+ control: {
153
+ ...parsed.control,
154
+ v: 1,
155
+ ask: null,
156
+ },
157
+ });
135
158
  if (reason !== null)
136
159
  throw new Error(`${where}: ${reason}`);
137
160
  return parsed;
@@ -83,7 +83,11 @@ export function resolveSessionKeyCredential(where) {
83
83
  const path = sessionKeyPath(where.dashboardUrl, where.sessionId, where.home ?? homedir());
84
84
  try {
85
85
  const key = readSessionKeyFile(path);
86
- return { source: { kind: "session-key", path }, token: key, fingerprint: credentialFingerprint(key) };
86
+ return {
87
+ source: { kind: "session-key", path },
88
+ token: key,
89
+ fingerprint: credentialFingerprint(key),
90
+ };
87
91
  }
88
92
  catch (err) {
89
93
  if (err instanceof SessionKeyAbsentError)
@@ -98,7 +102,11 @@ export function resolveSessionKeyCredential(where) {
98
102
  export function resolveBootCredential(env, where) {
99
103
  const token = readEnv(env, CREDENTIAL_TOKEN_ENV);
100
104
  if (token !== null) {
101
- return { source: { kind: "env", name: CREDENTIAL_TOKEN_ENV }, token, fingerprint: credentialFingerprint(token) };
105
+ return {
106
+ source: { kind: "env", name: CREDENTIAL_TOKEN_ENV },
107
+ token,
108
+ fingerprint: credentialFingerprint(token),
109
+ };
102
110
  }
103
111
  return resolveSessionKeyCredential(where);
104
112
  }
@@ -35,7 +35,15 @@ export const DANXBOT_API_EXAMPLES = {
35
35
  cardRead: {
36
36
  method: "GET",
37
37
  path: "/api/issues/<id>",
38
- query: { fields: { description: true, agent_notes: true, comments: true, checklists: true, parent_title: true } },
38
+ query: {
39
+ fields: {
40
+ description: true,
41
+ agent_notes: true,
42
+ comments: true,
43
+ checklists: true,
44
+ parent_title: true,
45
+ },
46
+ },
39
47
  },
40
48
  cardCreate: {
41
49
  method: "POST",
@@ -52,7 +60,11 @@ export const DANXBOT_API_EXAMPLES = {
52
60
  cardEdit: {
53
61
  method: "PATCH",
54
62
  path: "/api/issues/<id>/edit",
55
- body: { description: "<markdown>", ac: [{ title: "<criterion>" }], content_hash: "<content_hash from your read>" },
63
+ body: {
64
+ description: "<markdown>",
65
+ ac: [{ title: "<criterion>" }],
66
+ content_hash: "<content_hash from your read>",
67
+ },
56
68
  },
57
69
  acTick: {
58
70
  method: "PATCH",
@@ -82,7 +94,12 @@ export const DANXBOT_API_EXAMPLES = {
82
94
  export const RETRO_TEST_KIND_EXAMPLES = ["group", "e2e"];
83
95
  function render(example) {
84
96
  const { method, path, query, body } = example;
85
- return JSON.stringify({ method, path, ...(query ? { query } : {}), ...(body ? { body } : {}) });
97
+ return JSON.stringify({
98
+ method,
99
+ path,
100
+ ...(query ? { query } : {}),
101
+ ...(body ? { body } : {}),
102
+ });
86
103
  }
87
104
  /** The description sentence `50arms_api` carries. */
88
105
  export function danxbotApiExamplesText() {
@@ -67,7 +67,10 @@ function resolvePlaywright(rootAbs, cwd) {
67
67
  catch {
68
68
  continue;
69
69
  }
70
- return { module: req(resolved), from: `${name} from ${base}` };
70
+ return {
71
+ module: req(resolved),
72
+ from: `${name} from ${base}`,
73
+ };
71
74
  }
72
75
  }
73
76
  return null;
@@ -96,7 +99,11 @@ export async function captureWith(where, offline, drive) {
96
99
  return none(`the browser could not be launched (${playwright.from}): ${oneLine(err)}`);
97
100
  }
98
101
  try {
99
- const context = await browser.newContext({ viewport: { width: SCREENSHOT_WIDTH, height: SCREENSHOT_HEIGHT }, deviceScaleFactor: 1, offline });
102
+ const context = await browser.newContext({
103
+ viewport: { width: SCREENSHOT_WIDTH, height: SCREENSHOT_HEIGHT },
104
+ deviceScaleFactor: 1,
105
+ offline,
106
+ });
100
107
  const page = await context.newPage();
101
108
  const refusal = await drive(page);
102
109
  if (typeof refusal === "string")
@@ -112,7 +119,9 @@ export async function captureWith(where, offline, drive) {
112
119
  }
113
120
  finally {
114
121
  // A browser that will not close must not fail a publish whose screenshot is already decided.
115
- await browser.close().catch((err) => console.error(`[platform-mcp] could not close the browser: ${oneLine(err)}`));
122
+ await browser
123
+ .close()
124
+ .catch((err) => console.error(`[platform-mcp] could not close the browser: ${oneLine(err)}`));
116
125
  }
117
126
  }
118
127
  /** DX-5319: where the built html is served for the capture: a route answered by the capture itself, so the page is a real navigation and never reaches a network. */
@@ -130,9 +139,17 @@ export function captureScreenshot(html, where, optionGroups) {
130
139
  const options = designOptionsStub(optionGroups);
131
140
  if (options !== null)
132
141
  await page.addInitScript(options);
133
- await page.route(DESIGN_PAGE_URL, (route) => route.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: html }));
142
+ await page.route(DESIGN_PAGE_URL, (route) => route.fulfill({
143
+ status: 200,
144
+ contentType: "text/html; charset=utf-8",
145
+ body: html,
146
+ }));
134
147
  await page.goto(DESIGN_PAGE_URL, { waitUntil: "load" });
135
148
  // The page has loaded; a design that never posts ready (it threw) is still captured as it stands.
136
- await page.waitForFunction("window.__danxDesignReady === true", undefined, { timeout: READY_WAIT_MS }).catch(() => undefined);
149
+ await page
150
+ .waitForFunction("window.__danxDesignReady === true", undefined, {
151
+ timeout: READY_WAIT_MS,
152
+ })
153
+ .catch(() => undefined);
137
154
  });
138
155
  }
@@ -22,7 +22,8 @@ export class DigestHold {
22
22
  */
23
23
  route(event) {
24
24
  // DX-5846 / problem 2579: an event carrying acks is sent at once whoever made it (a changes-requested review is machine-made); the digest cannot carry one ack per event.
25
- if ((event.origin === "agent" || event.origin === "machine") && event.acks.length === 0) {
25
+ if ((event.origin === "agent" || event.origin === "machine") &&
26
+ event.acks.length === 0) {
26
27
  if (event.id !== null && this.heldIds().includes(event.id))
27
28
  return;
28
29
  this.held.push(event);
@@ -40,8 +41,18 @@ export class DigestHold {
40
41
  return;
41
42
  const entries = this.held;
42
43
  this.held = [];
43
- const ids = entries.map((e) => e.id).filter((id) => id !== null);
44
- this.emit({ type: "event", id: ids.length === 0 ? null : Math.max(...ids), ids, text: formatDigest(entries), origin: null, urgent: isUrgent({ source: "digest" }), acks: [] });
44
+ const ids = entries
45
+ .map((e) => e.id)
46
+ .filter((id) => id !== null);
47
+ this.emit({
48
+ type: "event",
49
+ id: ids.length === 0 ? null : Math.max(...ids),
50
+ ids,
51
+ text: formatDigest(entries),
52
+ origin: null,
53
+ urgent: isUrgent({ source: "digest" }),
54
+ acks: [],
55
+ });
45
56
  }
46
57
  /**
47
58
  * Stop the timer WITHOUT flushing. For a stop where a newer listener already streams this session and will receive (and
@@ -20,15 +20,23 @@ import { statSync } from "node:fs";
20
20
  import os from "node:os";
21
21
  import path from "node:path";
22
22
  import { z } from "zod";
23
- import { MAX_SEARCH_LIMIT, UnknownNodeIdError, loadLocalDocs, locateLocalPage, searchLocalDocs } from "@50arms/docs/agent";
23
+ import { MAX_SEARCH_LIMIT, UnknownNodeIdError, loadLocalDocs, locateLocalPage, searchLocalDocs, } from "@50arms/docs/agent";
24
24
  import { repoNameArgSchema } from "./board-id.js";
25
25
  import { writeFileDurable } from "./durable-write.js";
26
26
  /** The tools' shared `source` argument (one flat object so the schema stays plain: `path` goes with `dir`, `repo` with `remote`; `sourceProblem` enforces it). */
27
27
  export const docsSourceShape = z
28
28
  .object({
29
- kind: z.enum(["local", "dir", "remote", "product"]).describe("local: this checkout's docs/pages. dir: another docs root here (set path). remote: a team repo's hosted docs (set repo). product: 50 Arms' own product docs, which every team may read."),
30
- path: z.string().min(1).optional().describe("kind dir: the docs root directory."),
31
- repo: repoNameArgSchema.optional().describe("kind remote: the repo's name."),
29
+ kind: z
30
+ .enum(["local", "dir", "remote", "product"])
31
+ .describe("local: this checkout's docs/pages. dir: another docs root here (set path). remote: a team repo's hosted docs (set repo). product: 50 Arms' own product docs, which every team may read."),
32
+ path: z
33
+ .string()
34
+ .min(1)
35
+ .optional()
36
+ .describe("kind dir: the docs root directory."),
37
+ repo: repoNameArgSchema
38
+ .optional()
39
+ .describe("kind remote: the repo's name."),
32
40
  })
33
41
  .strict();
34
42
  const REFUSED = 400;
@@ -58,11 +66,15 @@ function sourceProblem(source) {
58
66
  }
59
67
  /** Where a hosted source's routes live: a repo's under `/api/docs/<repo>`, the product docs' under `/api/product-docs`. Only called once `sourceProblem` passed. */
60
68
  function hostedBase(source) {
61
- return source.kind === "product" ? "/api/product-docs" : `/api/docs/${source.repo}`;
69
+ return source.kind === "product"
70
+ ? "/api/product-docs"
71
+ : `/api/docs/${source.repo}`;
62
72
  }
63
73
  /** The local docs root a non-hosted source names; a missing path or one that is not a directory is an error naming it, never an empty search. */
64
74
  function localRoot(source, deps) {
65
- const root = source.kind === "local" ? path.join(deps.cwd, "docs", "pages") : path.resolve(deps.cwd, source.path);
75
+ const root = source.kind === "local"
76
+ ? path.join(deps.cwd, "docs", "pages")
77
+ : path.resolve(deps.cwd, source.path);
66
78
  const kind = source.kind === "local" ? "local" : "dir";
67
79
  const stat = statSync(root, { throwIfNoEntry: false });
68
80
  if (stat === undefined)
@@ -79,7 +91,10 @@ export async function docsSearch(client, args, deps) {
79
91
  // tool schema's `.min(1)` already refuses `""`; this catches a query of only whitespace.
80
92
  if (args.query.trim() === "")
81
93
  return refusal(REFUSED, "query is empty: say what to look for");
82
- if (args.limit !== undefined && (!Number.isInteger(args.limit) || args.limit < 1 || args.limit > MAX_SEARCH_LIMIT)) {
94
+ if (args.limit !== undefined &&
95
+ (!Number.isInteger(args.limit) ||
96
+ args.limit < 1 ||
97
+ args.limit > MAX_SEARCH_LIMIT)) {
83
98
  return refusal(REFUSED, `limit must be a whole number from 1 to ${MAX_SEARCH_LIMIT}`);
84
99
  }
85
100
  if (args.source.kind === "remote" || args.source.kind === "product") {
@@ -87,7 +102,10 @@ export async function docsSearch(client, args, deps) {
87
102
  method: "GET",
88
103
  path: "/search",
89
104
  basePath: hostedBase(args.source),
90
- query: { q: args.query, ...(args.limit === undefined ? {} : { limit: args.limit }) },
105
+ query: {
106
+ q: args.query,
107
+ ...(args.limit === undefined ? {} : { limit: args.limit }),
108
+ },
91
109
  });
92
110
  }
93
111
  const root = localRoot(args.source, deps);
@@ -113,15 +131,26 @@ export async function docsRead(client, args, deps) {
113
131
  if (args.source.kind === "remote" || args.source.kind === "product") {
114
132
  if (!SAFE_NAME.test(args.id))
115
133
  return refusal(REFUSED, `"${args.id}" is not a docs page id`);
116
- const fetched = await client.request({ method: "GET", path: `/pages/${args.id}`, basePath: hostedBase(args.source) });
134
+ const fetched = await client.request({
135
+ method: "GET",
136
+ path: `/pages/${args.id}`,
137
+ basePath: hostedBase(args.source),
138
+ });
117
139
  if (!fetched.ok)
118
140
  return fetched;
119
141
  const page = fetched.body;
120
142
  // DX-5597: the file is named by the id this call validated, never by a field of the answer, and lands whole: a temp name, then a rename.
121
143
  const tmp = deps.tmpDir ?? os.tmpdir();
122
- const file = args.source.kind === "product" ? path.join(tmp, "danx-product-docs", `${args.id}.md`) : path.join(tmp, "danx-docs", args.source.repo, `${args.id}.md`);
144
+ const file = args.source.kind === "product"
145
+ ? path.join(tmp, "danx-product-docs", `${args.id}.md`)
146
+ : path.join(tmp, "danx-docs", args.source.repo, `${args.id}.md`);
123
147
  writeFileDurable(file, page.content);
124
- const body = { id: args.id, path: file, bytes: page.bytes, lines: page.lines };
148
+ const body = {
149
+ id: args.id,
150
+ path: file,
151
+ bytes: page.bytes,
152
+ lines: page.lines,
153
+ };
125
154
  return { ok: true, status: 200, body };
126
155
  }
127
156
  const root = localRoot(args.source, deps);
@@ -129,7 +158,12 @@ export async function docsRead(client, args, deps) {
129
158
  return root;
130
159
  try {
131
160
  const located = locateLocalPage(loadLocalDocs(root), args.id);
132
- const body = { id: located.id, path: located.path, bytes: located.bytes, lines: located.lines };
161
+ const body = {
162
+ id: located.id,
163
+ path: located.path,
164
+ bytes: located.bytes,
165
+ lines: located.lines,
166
+ };
133
167
  return { ok: true, status: 200, body };
134
168
  }
135
169
  catch (err) {
@@ -4,9 +4,17 @@
4
4
  * DX-6117: the parent directory is created here (recursive), so no caller repeats it; a failure before the rename removes the temp sibling and rethrows.
5
5
  * The parent directory is synced after the rename on POSIX only; Windows cannot open a directory for fsync and NTFS journals the rename itself.
6
6
  */
7
- import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, unlinkSync, writeSync } from "node:fs";
7
+ import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, unlinkSync, writeSync, } from "node:fs";
8
8
  import { dirname } from "node:path";
9
- const realFs = { openSync, writeSync: (fd, data, offset) => writeSync(fd, data, offset), fsyncSync, closeSync, renameSync, mkdirSync: (path, options) => void mkdirSync(path, options), unlinkSync };
9
+ const realFs = {
10
+ openSync,
11
+ writeSync: (fd, data, offset) => writeSync(fd, data, offset),
12
+ fsyncSync,
13
+ closeSync,
14
+ renameSync,
15
+ mkdirSync: (path, options) => void mkdirSync(path, options),
16
+ unlinkSync,
17
+ };
10
18
  let tempSeq = 0;
11
19
  /**
12
20
  * Write `data` to a temp sibling of `target` (named here, unique per process and call), flush it, then rename it over `target`.
@@ -12,12 +12,23 @@ export function withForbiddenHint(result) {
12
12
  if (typeof body !== "object" || body === null || Array.isArray(body))
13
13
  return result;
14
14
  const { error, permission, reminders } = body;
15
- if (error !== "forbidden" || typeof permission !== "string" || permission === "")
15
+ if (error !== "forbidden" ||
16
+ typeof permission !== "string" ||
17
+ permission === "")
16
18
  return result;
17
19
  if (reminders !== undefined && !Array.isArray(reminders))
18
20
  return result;
19
21
  const existing = (reminders ?? []);
20
22
  if (existing.some((r) => r?.key === FORBIDDEN_HINT_KEY))
21
23
  return result;
22
- return { ...result, body: { ...body, reminders: [...existing, { key: FORBIDDEN_HINT_KEY, text: hintText(permission) }] } };
24
+ return {
25
+ ...result,
26
+ body: {
27
+ ...body,
28
+ reminders: [
29
+ ...existing,
30
+ { key: FORBIDDEN_HINT_KEY, text: hintText(permission) },
31
+ ],
32
+ },
33
+ };
23
34
  }
@@ -15,8 +15,12 @@ export function makeGuardedCalls(deps) {
15
15
  if (noAgent !== null)
16
16
  return { halt: noAgent };
17
17
  }
18
- const guarded = await deps.access().guard(run, { foreignKey: opts.foreignKey === true });
19
- return "halt" in guarded ? guarded : { result: withForbiddenHint(guarded.result) };
18
+ const guarded = await deps
19
+ .access()
20
+ .guard(run, { foreignKey: opts.foreignKey === true });
21
+ return "halt" in guarded
22
+ ? guarded
23
+ : { result: withForbiddenHint(guarded.result) };
20
24
  };
21
25
  return { guardedCall };
22
26
  }