@minhtri2710/pi-durable-shared 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Install with `npm install @minhtri2710/pi-durable-shared`. Import each as `@minh
8
8
 
9
9
  - `process-state`: `processState(key, init)`, the one way to keep state on `globalThis` so it outlives a `/reload` and is shared by every copy of this package in the process. The key is used as given (`pi-guards` reads `pi-worker-mcp`).
10
10
  - `durable-runtime`, `session-store`, `session-lock`: the per-session durable harness, its SQLite store and its lock (a stale reclaim claim ages by `ctime`).
11
- - `mcp-tools`, `mcp-oauth`: MCP servers for workers, from `pi-worker-mcp.json` and `mcp.json`. `$NAME`, `${NAME}` and `$$` expand in `env` and `headers`. A script sees the limited content, not the server's raw blocks or `_meta`.
11
+ - `mcp-tools`, `mcp-oauth`: MCP servers for workers: every server of the user-level `<agent dir>/mcp.json` that is not `enabled: false`, connected separately from Pi's own. An invalid or failing server is reported in `errors`, not thrown. `$NAME`, `${NAME}` and `$$` expand in `env` and `headers`. A script sees the limited content, not the server's raw blocks or `_meta`.
12
12
  - `worker-codemode`: the code mode sandbox and tool. Scripts run at most `max(4, availableParallelism)` at a time (`PI_CODEMODE_MAX_WORKERS` overrides); one over the limit waits, and leaves the queue when its signal aborts. `configureWorkerCodemode({ inlineBudget })` sets the budget the sandbox is created with.
13
13
  - `search-tools`: `grep` and `find` for workers. `execWithTimeout` takes milliseconds and passes seconds to `exec`.
14
14
  - `retention`: removes `pi-mcp-*` temp files that are regular, owned by the current user, mode 0600 and older than 7 days; runs once per process.
@@ -33,7 +33,7 @@ npm run typecheck # tsc -p .
33
33
 
34
34
  ## Publish to npm
35
35
 
36
- Consumers depend on `"@minhtri2710/pi-durable-shared": "^1.0.0"`. The package ships a prebuilt `dist`, so installing it runs no scripts. `prepublishOnly` builds and tests before each publish.
36
+ Consumers depend on `"@minhtri2710/pi-durable-shared": "^2.0.0"`. The package ships a prebuilt `dist`, so installing it runs no scripts. `prepublishOnly` builds and tests before each publish.
37
37
 
38
38
  ```sh
39
39
  npm login # once, in your terminal
@@ -1,7 +1,5 @@
1
1
  import { type Extension, type ToolRegistration } from "@earendil-works/pi-durable";
2
2
  import { McpClient } from "@earendil-works/pi-mcp";
3
- /** `<agent dir>/pi-worker-mcp.json`: `{ "servers": ["name", ...] }`, names from the user's `mcp.json`. Workers get no MCP tool unless listed. */
4
- export declare const WORKER_MCP_FILE = "pi-worker-mcp.json";
5
3
  /** `extensions`: one per connected server, each a code mode namespace. `tools`: all their tools. */
6
4
  type Link = {
7
5
  client: McpClient;
@@ -28,12 +26,12 @@ type AuthResolver = (provider: string) => Promise<string | undefined>;
28
26
  export declare function setWorkerMcpAuthResolver(resolver: AuthResolver | undefined): void;
29
27
  export declare const expand: (text: string) => string;
30
28
  /**
31
- * The MCP tools workers may call, connected once per process; `errors` names servers that were listed but unusable.
29
+ * The MCP tools workers may call, connected once per process; `errors` names servers of `mcp.json` that were unusable.
32
30
  * A set with errors is opened again once `RETRY_MS` have passed, so a server that was down, or a fixed configuration, is
33
31
  * picked up without a restart.
34
32
  */
35
33
  export declare function workerMcp(): Promise<Connected>;
36
- /** Marks the cached MCP set stale so the next `workerMcp()` call reconciles `mcp.json` / `pi-worker-mcp.json`. */
34
+ /** Marks the cached MCP set stale so the next `workerMcp()` call reconciles the user-level `mcp.json`. */
37
35
  export declare function invalidateWorkerMcp(): void;
38
36
  /** Closes the connections; the next `workerMcp()` connects again. */
39
37
  export declare function closeWorkerMcp(): Promise<void>;
package/dist/mcp-tools.js CHANGED
@@ -10,8 +10,6 @@ import { McpOAuthAuthorizationRequiredError } from "@earendil-works/pi-mcp/oauth
10
10
  import { processState } from "./process-state.js";
11
11
  import { sweepTempFilesOnce } from "./retention.js";
12
12
  import { checkMetadataDocumentCallback, usesOAuth, workerAuthProvider } from "./mcp-oauth.js";
13
- /** `<agent dir>/pi-worker-mcp.json`: `{ "servers": ["name", ...] }`, names from the user's `mcp.json`. Workers get no MCP tool unless listed. */
14
- export const WORKER_MCP_FILE = "pi-worker-mcp.json";
15
13
  const CONNECT_MS = 20_000;
16
14
  /** A set with an unusable server is opened again by a call this long after it, keeping the servers that connected. */
17
15
  const RETRY_MS = 30_000;
@@ -82,22 +80,15 @@ async function saveToTempFile(data, extension) {
82
80
  await writeFile(file, data, { flag: "wx", mode: 0o600 });
83
81
  return file;
84
82
  }
85
- /** The servers workers may use: those named in the allowlist that the user-level `mcp.json` defines and enables. */
83
+ /** The servers workers use: every server the user-level `<agent dir>/mcp.json` defines that is not `enabled: false`. An invalid one is reported in `errors`. */
86
84
  function selectedServers(errors) {
87
- const listed = readJson(join(getAgentDir(), WORKER_MCP_FILE))?.servers;
88
- if (listed === undefined)
89
- return [];
90
- if (!Array.isArray(listed) || listed.some((name) => typeof name !== "string")) {
91
- errors.push(`${WORKER_MCP_FILE}: servers must be a list of server names`);
92
- return [];
93
- }
94
85
  const defined = readJson(join(getAgentDir(), "mcp.json"))?.mcpServers ?? {};
95
86
  const chosen = [];
96
87
  const namespaces = new Map();
97
- for (const name of new Set(listed)) {
88
+ for (const name of Object.keys(defined)) {
98
89
  const checked = validateMcpServerConfig(name, defined[name], { checkMetadataDocumentCallback });
99
90
  if (checked.kind === "invalid") {
100
- errors.push(defined[name] === undefined ? `${name}: not defined in mcp.json` : checked.error);
91
+ errors.push(checked.error);
101
92
  continue;
102
93
  }
103
94
  if (checked.config.enabled === false)
@@ -300,7 +291,7 @@ async function open(previous) {
300
291
  return { served, links: served.map((item) => item.link), errors, extensions, tools: extensions.flatMap((extension) => [...(extension.tools ?? [])]), at: Date.now() };
301
292
  }
302
293
  /**
303
- * The MCP tools workers may call, connected once per process; `errors` names servers that were listed but unusable.
294
+ * The MCP tools workers may call, connected once per process; `errors` names servers of `mcp.json` that were unusable.
304
295
  * A set with errors is opened again once `RETRY_MS` have passed, so a server that was down, or a fixed configuration, is
305
296
  * picked up without a restart.
306
297
  */
@@ -318,7 +309,7 @@ export function workerMcp() {
318
309
  shared.connecting = undefined; throw error; });
319
310
  return connecting;
320
311
  }
321
- /** Marks the cached MCP set stale so the next `workerMcp()` call reconciles `mcp.json` / `pi-worker-mcp.json`. */
312
+ /** Marks the cached MCP set stale so the next `workerMcp()` call reconciles the user-level `mcp.json`. */
322
313
  export function invalidateWorkerMcp() {
323
314
  if (shared.settled)
324
315
  shared.stale = true;
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@minhtri2710/pi-durable-shared",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Durable runtime, MCP, search and code mode helpers shared by the pi-orchestrator, pi-swarm, pi-teamwork and pi-schedule extensions.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "keywords": ["pi", "pi-extension", "durable", "mcp", "codemode"],
7
+ "keywords": [
8
+ "pi",
9
+ "pi-extension",
10
+ "durable",
11
+ "mcp",
12
+ "codemode"
13
+ ],
8
14
  "repository": {
9
15
  "type": "git",
10
16
  "url": "git+https://github.com/minhtri2710/pi-durable-shared.git"