@50arms/platform-mcp 0.1.575 → 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.
@@ -6,11 +6,9 @@
6
6
  *
7
7
  * Only `owner/name` leaves this machine, never the remote URL, which can carry a credential.
8
8
  */
9
- import { execFile } from "node:child_process";
10
9
  import { existsSync } from "node:fs";
11
10
  import { join } from "node:path";
12
- import { promisify } from "node:util";
13
- const execFileAsync = promisify(execFile);
11
+ import { execFileAsync } from "./hidden-process.mjs";
14
12
  /** The folder every detector checks (`DETECTED_DOCS_ROOT` in `src/issues/docs-root-detection.ts`). */
15
13
  const DOCS_ROOT = "docs/pages";
16
14
  /** `owner/name` of a GitHub remote, an SSH host alias (`git@github.com-work:owner/name.git`) included, or null for any other remote. */
@@ -18,7 +16,7 @@ export function githubSlugOf(remote) {
18
16
  const match = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]*github[^/:]*)[/:]([^/]+)\/([^/]+?)(?:\.git)?\/?$/i.exec(remote.trim());
19
17
  return match === null ? null : `${match[2]}/${match[3]}`;
20
18
  }
21
- const runGit = async (cwd, args) => (await execFileAsync("git", [...args], { cwd, windowsHide: true })).stdout.trim();
19
+ const runGit = async (cwd, args) => (await execFileAsync("git", [...args], { cwd })).stdout.trim();
22
20
  /** DX-6888: `owner/name` of the GitHub repo `cwd`'s checkout was cloned from, or null for a folder with no checkout, no `origin`, or a remote that is not on GitHub. Sent with the session's sign-in request so the guide and the approver can name the repo. */
23
21
  export async function readCheckoutRepo(cwd, git = runGit) {
24
22
  try {
@@ -0,0 +1,42 @@
1
+ // Generated from src/util/hidden-process.d.mts by src/util/hidden-process-copies.mjs (DX-7918). Never edit it and never commit it: the package's build writes it.
2
+ import type * as cp from "node:child_process";
3
+
4
+ export type {
5
+ ChildProcess,
6
+ ChildProcessWithoutNullStreams,
7
+ ExecFileException,
8
+ ExecFileOptions,
9
+ ExecFileSyncOptions,
10
+ ExecOptions,
11
+ ExecSyncOptions,
12
+ ForkOptions,
13
+ SpawnOptions,
14
+ SpawnSyncOptions,
15
+ SpawnSyncOptionsWithStringEncoding,
16
+ SpawnSyncReturns,
17
+ StdioOptions,
18
+ } from "node:child_process";
19
+
20
+ /** Node's `child_process.spawn`, with `windowsHide: true` forced on. */
21
+ export const spawn: typeof cp.spawn;
22
+ export const spawnSync: typeof cp.spawnSync;
23
+ export const execFile: typeof cp.execFile;
24
+ export const execFileSync: typeof cp.execFileSync;
25
+ export const exec: typeof cp.exec;
26
+ export const execSync: typeof cp.execSync;
27
+ export const fork: typeof cp.fork;
28
+ /** `promisify(execFile)`: resolves `{ stdout, stderr }`. */
29
+ export const execFileAsync: (
30
+ file: string,
31
+ args?: readonly string[] | null,
32
+ options?: cp.ExecFileOptions,
33
+ ) => Promise<{ stdout: string; stderr: string }>;
34
+ export const execAsync: (
35
+ command: string,
36
+ options?: cp.ExecOptions,
37
+ ) => Promise<{ stdout: string; stderr: string }>;
38
+ export function withWindowsHidden(
39
+ args: readonly unknown[],
40
+ optionsAfterArgs: boolean,
41
+ ): unknown[];
42
+ export function hideWindowsOfChildProcesses(target?: typeof cp): void;
@@ -0,0 +1,93 @@
1
+ // Generated from src/util/hidden-process.mjs by src/util/hidden-process-copies.mjs (DX-7918). Never edit it and never commit it: the package's build writes it.
2
+ /**
3
+ * DX-7917 - the ONE way host code starts a child process.
4
+ *
5
+ * On Windows a console program (git, docker, node) started by a process with no console gets a visible console
6
+ * window that steals focus, and under load fails with 0xC0000142 (CLAUDE.md "No command ever opens a window").
7
+ * Every function here is node's own `child_process` function with the same signature, except that `windowsHide: true`
8
+ * is set AFTER the caller's options, so no caller can turn it off. `hidden-process-preload.mjs` applies the same
9
+ * rule to raw `child_process` calls a wrapper import missed.
10
+ *
11
+ * Plain `.mjs` (typed by `hidden-process.d.mts`) so the preload and standalone scripts can load it with no build step.
12
+ * Every `child_process` binding is read at call time, never at import time, so a test that mocks `node:child_process`
13
+ * with only the functions it uses still loads this module.
14
+ */
15
+ import * as cp from "node:child_process";
16
+ import { promisify } from "node:util";
17
+
18
+ /**
19
+ * `args` with `windowsHide: true` forced into its options object, found by node's argument rules: `(file, args?, options?, callback?)`
20
+ * when `optionsAfterArgs` (spawn family, execFile, fork), else `(command, options?, callback?)` (exec family).
21
+ */
22
+ export function withWindowsHidden(args, optionsAfterArgs) {
23
+ const out = [...args];
24
+ let at = 1;
25
+ // Node reads `(file, undefined | null, options)` as no args with the options in slot 2.
26
+ if (
27
+ optionsAfterArgs &&
28
+ (Array.isArray(out[1]) ||
29
+ ((out[1] === undefined || out[1] === null) &&
30
+ out.length > 2 &&
31
+ typeof out[2] !== "function"))
32
+ ) {
33
+ at = 2;
34
+ }
35
+ const given = out[at];
36
+ if (given === undefined || given === null) out[at] = { windowsHide: true };
37
+ else if (typeof given === "function")
38
+ out.splice(at, 0, { windowsHide: true });
39
+ else out[at] = { ...given, windowsHide: true };
40
+ return out;
41
+ }
42
+
43
+ export const spawn = (...args) => cp.spawn(...withWindowsHidden(args, true));
44
+ export const spawnSync = (...args) =>
45
+ cp.spawnSync(...withWindowsHidden(args, true));
46
+ export const execFileSync = (...args) =>
47
+ cp.execFileSync(...withWindowsHidden(args, true));
48
+ export const execSync = (...args) =>
49
+ cp.execSync(...withWindowsHidden(args, false));
50
+ export const fork = (...args) => cp.fork(...withWindowsHidden(args, true));
51
+
52
+ /** Promisified `execFile`: resolves `{ stdout, stderr }`, rejects with node's error (carrying `stdout`, `stderr`, `code`). */
53
+ export const execFileAsync = (...args) =>
54
+ promisify(cp.execFile)(...withWindowsHidden(args, true));
55
+ /** Promisified `exec`, the same way. */
56
+ export const execAsync = (...args) =>
57
+ promisify(cp.exec)(...withWindowsHidden(args, false));
58
+
59
+ export const execFile = (...args) =>
60
+ cp.execFile(...withWindowsHidden(args, true));
61
+ export const exec = (...args) => cp.exec(...withWindowsHidden(args, false));
62
+ // `promisify(execFile)` keeps resolving `{ stdout, stderr }`, as it does for node's own.
63
+ execFile[promisify.custom] = execFileAsync;
64
+ exec[promisify.custom] = execAsync;
65
+
66
+ /**
67
+ * Patch the live `node:child_process` so every call gets `windowsHide: true`, whoever made it
68
+ * (the preload's job). Idempotent: a function already patched is left alone.
69
+ */
70
+ export function hideWindowsOfChildProcesses(target = cp) {
71
+ const patches = {
72
+ spawn: [spawn, true],
73
+ spawnSync: [spawnSync, true],
74
+ execFile: [execFile, true],
75
+ execFileSync: [execFileSync, true],
76
+ exec: [exec, false],
77
+ execSync: [execSync, false],
78
+ fork: [fork, true],
79
+ };
80
+ for (const [name, [, optionsAfterArgs]] of Object.entries(patches)) {
81
+ const original = target[name];
82
+ if (original.__windowsHidden) continue;
83
+ const patched = (...args) =>
84
+ original(...withWindowsHidden(args, optionsAfterArgs));
85
+ patched.__windowsHidden = true;
86
+ const custom = original[promisify.custom];
87
+ if (custom !== undefined) {
88
+ patched[promisify.custom] = (...args) =>
89
+ custom(...withWindowsHidden(args, optionsAfterArgs));
90
+ }
91
+ target[name] = patched;
92
+ }
93
+ }
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(" ");
@@ -16,13 +16,13 @@
16
16
  * A daemon whose bearer the dashboard refused stops on purpose and disables its entry (`disableAutostart`), so neither the
17
17
  * repeating trigger nor the next logon starts it into the same refusal; `install-daemon` enables it again.
18
18
  *
19
- * Every child process is started with `windowsHide: true`. The XML, unit and plist text are pure functions so the tests pin them.
19
+ * Every child process is started through `../hidden-process.mjs` (a window is never opened). The XML, unit and plist text are pure functions so the tests pin them.
20
20
  * The task XML is UTF-16: `schtasks /XML` reads no other encoding (a UTF-8 file is refused "unable to switch the encoding").
21
21
  */
22
- import { execFileSync } from "node:child_process";
23
22
  import { mkdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
24
23
  import { homedir } from "node:os";
25
24
  import { join } from "node:path";
25
+ import { execFileSync } from "../hidden-process.mjs";
26
26
  export const TASK_NAME = "danxbot-machine-daemon";
27
27
  export const UNIT_NAME = "danxbot-machine-daemon.service";
28
28
  export const LAUNCH_AGENT_LABEL = "ai.50arms.danxbot-machine-daemon";
@@ -126,7 +126,6 @@ export function currentUid() {
126
126
  export function runHidden(file, args) {
127
127
  return execFileSync(file, args, {
128
128
  encoding: "utf8",
129
- windowsHide: true,
130
129
  stdio: ["ignore", "pipe", "pipe"],
131
130
  });
132
131
  }
@@ -123,7 +123,7 @@ foreach ($id in @(${pids.join(",")})) {
123
123
  }
124
124
  `;
125
125
  const SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
126
- /** Reads `CLAUDE_CODE_SESSION_ID` out of each process's environment; a pid that answers nothing is absent from the map. `run` is the same injectable command runner the listings use (windowsHide set there). */
126
+ /** Reads `CLAUDE_CODE_SESSION_ID` out of each process's environment; a pid that answers nothing is absent from the map. `run` is the same injectable command runner the listings use (started with no window there). */
127
127
  export async function readSessionsFromEnvironment(pids, run = runCommand) {
128
128
  const found = new Map();
129
129
  if (pids.length === 0)
@@ -1,5 +1,4 @@
1
1
  // src/machine-daemon/run.ts
2
- import { spawn } from "node:child_process";
3
2
  import { existsSync as existsSync3 } from "node:fs";
4
3
  import { homedir as homedir3 } from "node:os";
5
4
 
@@ -11,7 +10,32 @@ import {
11
10
  totalmem,
12
11
  platform as osPlatform
13
12
  } from "node:os";
14
- import { execFileSync } from "node:child_process";
13
+
14
+ // ../../src/util/hidden-process.mjs
15
+ import * as cp from "node:child_process";
16
+ import { promisify } from "node:util";
17
+ function withWindowsHidden(args, optionsAfterArgs) {
18
+ const out = [...args];
19
+ let at = 1;
20
+ if (optionsAfterArgs && (Array.isArray(out[1]) || (out[1] === void 0 || out[1] === null) && out.length > 2 && typeof out[2] !== "function")) {
21
+ at = 2;
22
+ }
23
+ const given = out[at];
24
+ if (given === void 0 || given === null) out[at] = { windowsHide: true };
25
+ else if (typeof given === "function")
26
+ out.splice(at, 0, { windowsHide: true });
27
+ else out[at] = { ...given, windowsHide: true };
28
+ return out;
29
+ }
30
+ var execFileSync2 = (...args) => cp.execFileSync(...withWindowsHidden(args, true));
31
+ var execFileAsync = (...args) => promisify(cp.execFile)(...withWindowsHidden(args, true));
32
+ var execAsync = (...args) => promisify(cp.exec)(...withWindowsHidden(args, false));
33
+ var execFile2 = (...args) => cp.execFile(...withWindowsHidden(args, true));
34
+ var exec2 = (...args) => cp.exec(...withWindowsHidden(args, false));
35
+ execFile2[promisify.custom] = execFileAsync;
36
+ exec2[promisify.custom] = execAsync;
37
+
38
+ // ../machine-vitals/src/probes.ts
15
39
  function readDisk(path, statfs = statfsSync) {
16
40
  const stats = statfs(path);
17
41
  return {
@@ -104,10 +128,10 @@ function readSwap(deps = {}) {
104
128
  );
105
129
  }
106
130
  if (platform === "win32") {
107
- const run = deps.runPowerShell ?? ((script) => execFileSync(
131
+ const run = deps.runPowerShell ?? ((script) => execFileSync2(
108
132
  "powershell.exe",
109
133
  ["-NoProfile", "-NonInteractive", "-Command", script],
110
- { encoding: "utf8", windowsHide: true }
134
+ { encoding: "utf8" }
111
135
  ));
112
136
  return parsePageFileJson(run(PAGEFILE_SCRIPT).trim() || "[]");
113
137
  }
@@ -137,8 +161,32 @@ function createMachineVitalsCollector(deps) {
137
161
  };
138
162
  }
139
163
 
164
+ // src/hidden-process.mjs
165
+ import * as cp2 from "node:child_process";
166
+ import { promisify as promisify2 } from "node:util";
167
+ function withWindowsHidden2(args, optionsAfterArgs) {
168
+ const out = [...args];
169
+ let at = 1;
170
+ if (optionsAfterArgs && (Array.isArray(out[1]) || (out[1] === void 0 || out[1] === null) && out.length > 2 && typeof out[2] !== "function")) {
171
+ at = 2;
172
+ }
173
+ const given = out[at];
174
+ if (given === void 0 || given === null) out[at] = { windowsHide: true };
175
+ else if (typeof given === "function")
176
+ out.splice(at, 0, { windowsHide: true });
177
+ else out[at] = { ...given, windowsHide: true };
178
+ return out;
179
+ }
180
+ var spawn3 = (...args) => cp2.spawn(...withWindowsHidden2(args, true));
181
+ var execFileSync4 = (...args) => cp2.execFileSync(...withWindowsHidden2(args, true));
182
+ var execFileAsync2 = (...args) => promisify2(cp2.execFile)(...withWindowsHidden2(args, true));
183
+ var execAsync2 = (...args) => promisify2(cp2.exec)(...withWindowsHidden2(args, false));
184
+ var execFile4 = (...args) => cp2.execFile(...withWindowsHidden2(args, true));
185
+ var exec4 = (...args) => cp2.exec(...withWindowsHidden2(args, false));
186
+ execFile4[promisify2.custom] = execFileAsync2;
187
+ exec4[promisify2.custom] = execAsync2;
188
+
140
189
  // src/machine-daemon/autostart.ts
141
- import { execFileSync as execFileSync2 } from "node:child_process";
142
190
  var TASK_NAME = "danxbot-machine-daemon";
143
191
  var UNIT_NAME = "danxbot-machine-daemon.service";
144
192
  var LAUNCH_AGENT_LABEL = "ai.50arms.danxbot-machine-daemon";
@@ -153,9 +201,8 @@ function currentUid() {
153
201
  return process.getuid?.() ?? null;
154
202
  }
155
203
  function runHidden(file, args) {
156
- return execFileSync2(file, args, {
204
+ return execFileSync4(file, args, {
157
205
  encoding: "utf8",
158
- windowsHide: true,
159
206
  stdio: ["ignore", "pipe", "pipe"]
160
207
  });
161
208
  }
@@ -288,9 +335,6 @@ import { join } from "node:path";
288
335
  var LEFTOVER_REMINDER_TTL_MS = 10 * 60 * 1e3;
289
336
  var LEFTOVER_COMMAND_MAX_CHARS = 140;
290
337
 
291
- // src/machine-toolkit/processes.ts
292
- import { execFile } from "node:child_process";
293
-
294
338
  // src/machine-toolkit/errors.ts
295
339
  function errorCode(err) {
296
340
  const failure = err;
@@ -348,13 +392,12 @@ function parseWslListing(stdout, now) {
348
392
  return rows;
349
393
  }
350
394
  var runCommand = (file, args, timeoutMs, signal) => new Promise((resolve, reject) => {
351
- execFile(
395
+ execFile2(
352
396
  file,
353
397
  args,
354
398
  {
355
399
  timeout: timeoutMs,
356
400
  maxBuffer: LISTING_MAX_BUFFER_BYTES,
357
- windowsHide: true,
358
401
  signal
359
402
  },
360
403
  (err, stdout) => err ? reject(err) : resolve(stdout)
@@ -979,7 +1022,6 @@ function runRefreshChild(opts) {
979
1022
  "npx",
980
1023
  ["-y", "@50arms/platform-mcp@latest", "refresh-daemon"],
981
1024
  {
982
- windowsHide: true,
983
1025
  shell: process.platform === "win32",
984
1026
  stdio: "ignore"
985
1027
  }
@@ -1206,7 +1248,7 @@ function runHealthChild(opts) {
1206
1248
  const child = opts.spawnFn(
1207
1249
  opts.nodePath,
1208
1250
  [opts.toolkitPath, "health", "--json"],
1209
- { windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }
1251
+ { stdio: ["ignore", "pipe", "ignore"] }
1210
1252
  );
1211
1253
  cancel = schedule(() => {
1212
1254
  child.kill();
@@ -1471,12 +1513,12 @@ async function runDaemonProcess() {
1471
1513
  reporter: createReporter({
1472
1514
  config,
1473
1515
  runHealth: () => runHealthChild({
1474
- spawnFn: spawn,
1516
+ spawnFn: spawn3,
1475
1517
  nodePath: process.execPath,
1476
1518
  toolkitPath: toolkitBundlePath()
1477
1519
  }),
1478
1520
  fetchFn,
1479
- refresh: (needs) => refreshBundles({ needs, now: now(), spawnFn: spawn, log }),
1521
+ refresh: (needs) => refreshBundles({ needs, now: now(), spawnFn: spawn3, log }),
1480
1522
  leftovers: createSystemLeftoverTracker(log),
1481
1523
  writeStatus: status.report,
1482
1524
  log,
@@ -1,8 +1,32 @@
1
1
  // src/machine-toolkit/cli.ts
2
- import { spawn } from "node:child_process";
3
2
  import { realpathSync } from "node:fs";
4
3
  import { pathToFileURL } from "node:url";
5
4
 
5
+ // ../../src/util/hidden-process.mjs
6
+ import * as cp from "node:child_process";
7
+ import { promisify } from "node:util";
8
+ function withWindowsHidden(args, optionsAfterArgs) {
9
+ const out = [...args];
10
+ let at = 1;
11
+ if (optionsAfterArgs && (Array.isArray(out[1]) || (out[1] === void 0 || out[1] === null) && out.length > 2 && typeof out[2] !== "function")) {
12
+ at = 2;
13
+ }
14
+ const given = out[at];
15
+ if (given === void 0 || given === null) out[at] = { windowsHide: true };
16
+ else if (typeof given === "function")
17
+ out.splice(at, 0, { windowsHide: true });
18
+ else out[at] = { ...given, windowsHide: true };
19
+ return out;
20
+ }
21
+ var spawn2 = (...args) => cp.spawn(...withWindowsHidden(args, true));
22
+ var execFileSync2 = (...args) => cp.execFileSync(...withWindowsHidden(args, true));
23
+ var execFileAsync = (...args) => promisify(cp.execFile)(...withWindowsHidden(args, true));
24
+ var execAsync = (...args) => promisify(cp.exec)(...withWindowsHidden(args, false));
25
+ var execFile2 = (...args) => cp.execFile(...withWindowsHidden(args, true));
26
+ var exec2 = (...args) => cp.exec(...withWindowsHidden(args, false));
27
+ execFile2[promisify.custom] = execFileAsync;
28
+ exec2[promisify.custom] = execAsync;
29
+
6
30
  // src/machine-toolkit/contract.ts
7
31
  var CONTRACT_VERSION = 3;
8
32
  var EXIT = {
@@ -248,7 +272,6 @@ import { join as join4 } from "node:path";
248
272
  import { performance } from "node:perf_hooks";
249
273
 
250
274
  // src/machine-toolkit/machine-home.mjs
251
- import { execFileSync } from "node:child_process";
252
275
  import { existsSync } from "node:fs";
253
276
  import { homedir, release } from "node:os";
254
277
  import { join as join3 } from "node:path";
@@ -257,8 +280,7 @@ function isWsl(kernelRelease = release(), platform = process.platform, hasDrvFs
257
280
  }
258
281
  var WSL_CALL_TIMEOUT_MS = 1e4;
259
282
  function windowsHomeFromWsl() {
260
- const raw = execFileSync("cmd.exe", ["/c", "echo %USERPROFILE%"], {
261
- windowsHide: true,
283
+ const raw = execFileSync2("cmd.exe", ["/c", "echo %USERPROFILE%"], {
262
284
  encoding: "utf8",
263
285
  stdio: ["ignore", "pipe", "ignore"],
264
286
  timeout: WSL_CALL_TIMEOUT_MS
@@ -267,8 +289,7 @@ function windowsHomeFromWsl() {
267
289
  throw new Error(
268
290
  `could not resolve the Windows home from cmd.exe (it said '${raw}')`
269
291
  );
270
- const path = execFileSync("wslpath", ["-u", raw], {
271
- windowsHide: true,
292
+ const path = execFileSync2("wslpath", ["-u", raw], {
272
293
  encoding: "utf8",
273
294
  stdio: ["ignore", "pipe", "ignore"],
274
295
  timeout: WSL_CALL_TIMEOUT_MS
@@ -288,7 +309,6 @@ function machineHome() {
288
309
  }
289
310
 
290
311
  // src/machine-toolkit/processes.ts
291
- import { execFile } from "node:child_process";
292
312
  var ORPHAN_MIN_AGE_MS = 10 * 60 * 1e3;
293
313
  var COMMAND_LINE_MAX_CHARS = 140;
294
314
  var PROCESS_LISTING_TIMEOUT_MS = 2e4;
@@ -370,13 +390,12 @@ function parseWslListing(stdout, now) {
370
390
  return rows;
371
391
  }
372
392
  var runCommand = (file, args, timeoutMs, signal) => new Promise((resolve, reject) => {
373
- execFile(
393
+ execFile2(
374
394
  file,
375
395
  args,
376
396
  {
377
397
  timeout: timeoutMs,
378
398
  maxBuffer: LISTING_MAX_BUFFER_BYTES,
379
- windowsHide: true,
380
399
  signal
381
400
  },
382
401
  (err, stdout) => err ? reject(err) : resolve(stdout)
@@ -491,7 +510,6 @@ function probeProcessStart(opts) {
491
510
  return new Promise((resolve, reject) => {
492
511
  const startedAt = nowMs();
493
512
  const child = opts.spawnFn(file, args, {
494
- windowsHide: true,
495
513
  stdio: "ignore",
496
514
  signal: opts.signal
497
515
  });
@@ -612,7 +630,7 @@ var readOwnManifest = () => JSON.parse(
612
630
  readFileSync(new URL("../../package.json", import.meta.url), "utf8")
613
631
  ).version;
614
632
  var TOOLKIT_VERSION = resolveToolkitVersion(
615
- false ? void 0 : "0.1.575",
633
+ false ? void 0 : "0.1.577",
616
634
  readOwnManifest
617
635
  );
618
636
  function envelope(now) {
@@ -751,7 +769,7 @@ function collectFromThisMachine() {
751
769
  dataDisk: () => readDockerDataDisk(),
752
770
  orphans: (now, signal) => reportOrphanProcesses(now, void 0, void 0, signal, "when-running"),
753
771
  compactionWindowOpen: () => compactionWindowOpen(),
754
- processStartMs: (signal) => probeProcessStart({ spawnFn: spawn, signal }),
772
+ processStartMs: (signal) => probeProcessStart({ spawnFn: spawn2, signal }),
755
773
  kernelTokenCount: (signal) => readKernelTokenCount({ signal })
756
774
  });
757
775
  }
@@ -10,11 +10,11 @@
10
10
  * This module carries no validator for the document it produces: that the document is self-contained is checked by exactly ONE
11
11
  * validator, the dashboard's own parse5 check on the revision route, whose 400 comes back to the caller verbatim.
12
12
  */
13
- import { spawn } from "node:child_process";
14
13
  import { randomBytes } from "node:crypto";
15
14
  import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
16
15
  import os from "node:os";
17
16
  import path from "node:path";
17
+ import { spawn } from "./hidden-process.mjs";
18
18
  import { foldBuildOutput } from "./mini-app-output.js";
19
19
  /** A build id unique per call, so two publishes never share a local page. */
20
20
  export function newBuildId() {
@@ -42,7 +42,6 @@ async function killProcessTree(pid, child) {
42
42
  if (process.platform === "win32") {
43
43
  const status = await new Promise((resolve) => {
44
44
  const killer = spawn("taskkill", ["/T", "/F", "/PID", String(pid)], {
45
- windowsHide: true,
46
45
  stdio: "ignore",
47
46
  });
48
47
  killer.once("error", () => resolve(null));
@@ -74,7 +73,6 @@ export async function runBuildCommand(input, timeoutMs = BUILD_TIMEOUT_MS, pipeG
74
73
  cwd: input.repoRoot,
75
74
  shell: false,
76
75
  stdio: ["ignore", "pipe", "pipe"],
77
- windowsHide: true,
78
76
  detached: process.platform !== "win32",
79
77
  });
80
78
  let text = "";
@@ -6,11 +6,9 @@
6
6
  * module only checks them against the filesystem and git, which are facts of a checkout, not a setting. It never reads `.danxbot/` or any
7
7
  * `config.yml`.
8
8
  */
9
- import { execFile } from "node:child_process";
10
9
  import { readdir, readFile, realpath, stat } from "node:fs/promises";
11
10
  import path from "node:path";
12
- import { promisify } from "node:util";
13
- const execFileAsync = promisify(execFile);
11
+ import { execFileAsync } from "./hidden-process.mjs";
14
12
  /** The two keys of the one canonical target shape (no version field, no repair of a row missing one). */
15
13
  export const MINI_APP_TARGET_KEYS = ["name", "command"];
16
14
  /**
@@ -72,7 +70,11 @@ export function relativePosix(base, p) {
72
70
  /** Run `git -C <repoDir> <args>` (no shell); a non-zero exit is data (`ls-files --error-unmatch`, `diff --quiet` and `check-ignore -q` answer through it). */
73
71
  async function git(repoDir, args) {
74
72
  try {
75
- const { stdout, stderr } = await execFileAsync("git", ["-C", repoDir, ...args], { windowsHide: true });
73
+ const { stdout, stderr } = await execFileAsync("git", [
74
+ "-C",
75
+ repoDir,
76
+ ...args,
77
+ ]);
76
78
  return { code: 0, stdout, stderr };
77
79
  }
78
80
  catch (err) {
@@ -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"],
@@ -75,7 +75,7 @@ export const MCP_STREAM_MIN_VERSION_HEADER = "X-Danx-Stream-Min-Version";
75
75
  export const MCP_PACKAGE_NAME = "@50arms/platform-mcp";
76
76
  /**
77
77
  * Numeric-dotted version compare (major.minor.patch, ...) — mirrors
78
- * `compareMcpVersions` in danxbot's `src/mcp-contract.ts` behavior
78
+ * `compareMcpVersions` in danxbot's `src/mcp-version-compare.ts` behavior
79
79
  * byte-for-byte (duplicated, not imported — see module doc). Both sides of
80
80
  * this contract have only ever used plain numeric dotted versions, so this
81
81
  * throws rather than silently falling back to a lexical compare, which
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@50arms/platform-mcp",
3
- "version": "0.1.575",
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",
@@ -28,12 +28,12 @@
28
28
  "scripts": {
29
29
  "prepublishOnly": "bash ../../scripts/assert-tree-contains-origin-main.sh @50arms/platform-mcp",
30
30
  "generate": "tsx ../../scripts/ensure-platform-mcp-generated.ts ../..",
31
- "build": "npm run generate && node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"require('fs').chmodSync('dist/index.js', 0o755)\" && node scripts/build-machine-daemon.mjs",
32
- "prepack": "node scripts/build-machine-daemon.mjs",
31
+ "build": "npm run generate && node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node ../../src/util/hidden-process-copies.mjs dist && node -e \"require('fs').chmodSync('dist/index.js', 0o755)\" && node scripts/build-machine-daemon.mjs",
32
+ "prepack": "node ../../src/util/hidden-process-copies.mjs src && node scripts/build-machine-daemon.mjs",
33
33
  "verify:boot": "bash scripts/verify-boot.sh",
34
34
  "start": "node dist/index.js",
35
- "dev": "tsx src/index.ts",
36
- "gen-tool-defs": "tsx scripts/gen-tool-defs.ts",
35
+ "dev": "node ../../src/util/hidden-process-copies.mjs src && tsx src/index.ts",
36
+ "gen-tool-defs": "node ../../src/util/hidden-process-copies.mjs src && tsx scripts/gen-tool-defs.ts",
37
37
  "pretest": "npm run generate",
38
38
  "test": "vitest run",
39
39
  "test:watch": "vitest"
@@ -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
- }