@poe-platform/safe-bash 0.1.40 → 0.1.42
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 +45 -2
- package/dist/safe-bash/browser.d.ts +5 -0
- package/dist/safe-bash/browser.d.ts.map +1 -1
- package/dist/safe-bash/browser.js +878 -122
- package/dist/safe-bash/browser.js.map +4 -4
- package/dist/safe-bash/commands/apply-patch/shared.js +2 -2
- package/dist/safe-bash/commands/apply-patch/shared.js.map +1 -1
- package/dist/safe-bash/commands/archive/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/archive/internal.js +3 -2
- package/dist/safe-bash/commands/archive/internal.js.map +1 -1
- package/dist/safe-bash/commands/bytes/checksums/index.d.ts.map +1 -1
- package/dist/safe-bash/commands/bytes/checksums/index.js +3 -2
- package/dist/safe-bash/commands/bytes/checksums/index.js.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/gunzip.js +2 -2
- package/dist/safe-bash/commands/bytes/compression/gunzip.js.map +1 -1
- package/dist/safe-bash/commands/bytes/compression/stream.js +2 -2
- package/dist/safe-bash/commands/bytes/compression/stream.js.map +1 -1
- package/dist/safe-bash/commands/bytes/encoding/shared.js +3 -3
- package/dist/safe-bash/commands/bytes/encoding/shared.js.map +1 -1
- package/dist/safe-bash/commands/column/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/column/internal.js +2 -1
- package/dist/safe-bash/commands/column/internal.js.map +1 -1
- package/dist/safe-bash/commands/diff-patch/shared.js +2 -2
- package/dist/safe-bash/commands/diff-patch/shared.js.map +1 -1
- package/dist/safe-bash/commands/du/budget.d.ts.map +1 -1
- package/dist/safe-bash/commands/du/budget.js +3 -2
- package/dist/safe-bash/commands/du/budget.js.map +1 -1
- package/dist/safe-bash/commands/env-split.d.ts.map +1 -1
- package/dist/safe-bash/commands/env-split.js +2 -1
- package/dist/safe-bash/commands/env-split.js.map +1 -1
- package/dist/safe-bash/commands/expr/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/expr/internal.js +2 -1
- package/dist/safe-bash/commands/expr/internal.js.map +1 -1
- package/dist/safe-bash/commands/file/shared.d.ts.map +1 -1
- package/dist/safe-bash/commands/file/shared.js +3 -2
- package/dist/safe-bash/commands/file/shared.js.map +1 -1
- package/dist/safe-bash/commands/find.d.ts.map +1 -1
- package/dist/safe-bash/commands/find.js +12 -31
- package/dist/safe-bash/commands/find.js.map +1 -1
- package/dist/safe-bash/commands/html-to-markdown/budget.js +2 -2
- package/dist/safe-bash/commands/html-to-markdown/budget.js.map +1 -1
- package/dist/safe-bash/commands/metadata/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/metadata/internal.js +2 -1
- package/dist/safe-bash/commands/metadata/internal.js.map +1 -1
- package/dist/safe-bash/commands/move.d.ts.map +1 -1
- package/dist/safe-bash/commands/move.js +2 -1
- package/dist/safe-bash/commands/move.js.map +1 -1
- package/dist/safe-bash/commands/network/authorizer.d.ts +7 -0
- package/dist/safe-bash/commands/network/authorizer.d.ts.map +1 -0
- package/dist/safe-bash/commands/network/authorizer.js +48 -0
- package/dist/safe-bash/commands/network/authorizer.js.map +1 -0
- package/dist/safe-bash/commands/network/body.js +2 -2
- package/dist/safe-bash/commands/network/body.js.map +1 -1
- package/dist/safe-bash/commands/network/curl.js +2 -2
- package/dist/safe-bash/commands/network/curl.js.map +1 -1
- package/dist/safe-bash/commands/network/fetch-transport.d.ts +6 -0
- package/dist/safe-bash/commands/network/fetch-transport.d.ts.map +1 -0
- package/dist/safe-bash/commands/network/fetch-transport.js +80 -0
- package/dist/safe-bash/commands/network/fetch-transport.js.map +1 -0
- package/dist/safe-bash/commands/network/index.d.ts +2 -0
- package/dist/safe-bash/commands/network/index.d.ts.map +1 -1
- package/dist/safe-bash/commands/network/index.js +2 -0
- package/dist/safe-bash/commands/network/index.js.map +1 -1
- package/dist/safe-bash/commands/network/types.d.ts +1 -0
- package/dist/safe-bash/commands/network/types.d.ts.map +1 -1
- package/dist/safe-bash/commands/network/types.js +10 -0
- package/dist/safe-bash/commands/network/types.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/limits.js +2 -2
- package/dist/safe-bash/commands/regex-execution/ere/limits.js.map +1 -1
- package/dist/safe-bash/commands/safejs/io.js +2 -2
- package/dist/safe-bash/commands/safejs/io.js.map +1 -1
- package/dist/safe-bash/commands/search/shared.js +2 -2
- package/dist/safe-bash/commands/search/shared.js.map +1 -1
- package/dist/safe-bash/commands/split/io.js +2 -2
- package/dist/safe-bash/commands/split/io.js.map +1 -1
- package/dist/safe-bash/commands/stream-format/shared.d.ts.map +1 -1
- package/dist/safe-bash/commands/stream-format/shared.js +2 -1
- package/dist/safe-bash/commands/stream-format/shared.js.map +1 -1
- package/dist/safe-bash/commands/stream-inspection/shared.d.ts.map +1 -1
- package/dist/safe-bash/commands/stream-inspection/shared.js +2 -1
- package/dist/safe-bash/commands/stream-inspection/shared.js.map +1 -1
- package/dist/safe-bash/commands/structured/limits.js +2 -2
- package/dist/safe-bash/commands/structured/limits.js.map +1 -1
- package/dist/safe-bash/commands/table-text/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/table-text/internal.js +2 -1
- package/dist/safe-bash/commands/table-text/internal.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/shared.js +2 -2
- package/dist/safe-bash/commands/text-programs/shared.js.map +1 -1
- package/dist/safe-bash/commands/tree/io.js +2 -2
- package/dist/safe-bash/commands/tree/io.js.map +1 -1
- package/dist/safe-bash/contracts/yield.d.ts +13 -0
- package/dist/safe-bash/contracts/yield.d.ts.map +1 -0
- package/dist/safe-bash/contracts/yield.js +41 -0
- package/dist/safe-bash/contracts/yield.js.map +1 -0
- package/dist/safe-bash/shell/arithmetic.js +1 -1
- package/dist/safe-bash/shell/arithmetic.js.map +1 -1
- package/dist/safe-bash/shell/arrays/ledger.d.ts.map +1 -1
- package/dist/safe-bash/shell/arrays/ledger.js +2 -9
- package/dist/safe-bash/shell/arrays/ledger.js.map +1 -1
- package/dist/safe-bash/shell/conditional.d.ts.map +1 -1
- package/dist/safe-bash/shell/conditional.js +2 -1
- package/dist/safe-bash/shell/conditional.js.map +1 -1
- package/dist/safe-bash/shell/env-warning.d.ts +2 -0
- package/dist/safe-bash/shell/env-warning.d.ts.map +1 -0
- package/dist/safe-bash/shell/env-warning.js +18 -0
- package/dist/safe-bash/shell/env-warning.js.map +1 -0
- package/dist/safe-bash/shell/index.d.ts +1 -0
- package/dist/safe-bash/shell/index.d.ts.map +1 -1
- package/dist/safe-bash/shell/index.js +1 -0
- package/dist/safe-bash/shell/index.js.map +1 -1
- package/dist/safe-bash/shell/input.d.ts.map +1 -1
- package/dist/safe-bash/shell/input.js +4 -3
- package/dist/safe-bash/shell/input.js.map +1 -1
- package/dist/safe-bash/shell/parser.d.ts.map +1 -1
- package/dist/safe-bash/shell/parser.js +15 -1
- package/dist/safe-bash/shell/parser.js.map +1 -1
- package/dist/safe-bash/shell/pattern.d.ts.map +1 -1
- package/dist/safe-bash/shell/pattern.js +3 -2
- package/dist/safe-bash/shell/pattern.js.map +1 -1
- package/dist/safe-bash/shell/runtime.d.ts +3 -2
- package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
- package/dist/safe-bash/shell/runtime.js +57 -55
- package/dist/safe-bash/shell/runtime.js.map +1 -1
- package/dist/safe-bash/shell/shell.d.ts.map +1 -1
- package/dist/safe-bash/shell/shell.js +4 -1
- package/dist/safe-bash/shell/shell.js.map +1 -1
- package/dist/safe-bash/shell/types.d.ts +2 -0
- package/dist/safe-bash/shell/types.d.ts.map +1 -1
- package/dist/safe-bash/shell/types.js.map +1 -1
- package/dist/safe-bash/shell/worker-limits.d.ts +3 -0
- package/dist/safe-bash/shell/worker-limits.d.ts.map +1 -0
- package/dist/safe-bash/shell/worker-limits.js +14 -0
- package/dist/safe-bash/shell/worker-limits.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ These plugins are separate from `agentCommands()`; pass them to `shell.use(...)`
|
|
|
121
121
|
|
|
122
122
|
| Command | Plugin and configuration |
|
|
123
123
|
| --- | --- |
|
|
124
|
-
| `curl` | `networkCommands({ authorize, transport?, limits?, replace? })`: required authorization on every request, redirect, and retry.
|
|
124
|
+
| `curl` | `networkCommands({ authorize, transport?, limits?, replace? })`: required authorization on every request, redirect, and retry. Node uses the native HTTP transport; Workers can inject `createFetchTransport()`. `createOriginAuthorizer([...])` provides exact origin/hostname policy; its omitted allowlist is deliberately `*` (allow all). [Options and limits](src/commands/network/types.ts). |
|
|
125
125
|
| `node` | `nodeCommands({ runtime, limits?, replace? })`: runs JavaScript with an injected SafeJS runtime, virtual files, and shell streams. [Usage and supported subset](src/commands/node/README.md). |
|
|
126
126
|
| `safejs` | `safeJsCommands({ runtime, limits?, replace? })`: inject `run`, `createBudget`, `makeFsModule`, and `declareHostOperation` to execute programs. [Runtime contract](src/commands/safejs/types.ts). |
|
|
127
127
|
|
|
@@ -177,6 +177,40 @@ package/local-module loading, `process.exit()`, or native module fallback.
|
|
|
177
177
|
Pass `limits` for source/input/output bytes, timeout, and interpreter budgets;
|
|
178
178
|
see [defaults and configuration](src/commands/node/README.md#configuration).
|
|
179
179
|
|
|
180
|
+
## Wire an individual MCP tool
|
|
181
|
+
|
|
182
|
+
There is no generic safe-bash MCP server. Define each server and tool around the
|
|
183
|
+
specific operation it grants, then call `Shell.exec()` with fixed shell source.
|
|
184
|
+
For example, this server exposes name normalization without accepting arbitrary
|
|
185
|
+
Bash from the MCP client:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { Shell, agentCommands, createMemoryFileSystem } from "poe-code/safe-bash";
|
|
189
|
+
import { createServer, defineSchema } from "tiny-stdio-mcp-server";
|
|
190
|
+
|
|
191
|
+
const shell = new Shell({ fs: createMemoryFileSystem() }).use(agentCommands());
|
|
192
|
+
const input = defineSchema({ names: { type: "string" } });
|
|
193
|
+
|
|
194
|
+
const server = createServer({ name: "contacts-tools", version: "1.0.0" })
|
|
195
|
+
.tool("normalize_names", "Sort and deduplicate newline-separated names", input,
|
|
196
|
+
async ({ names }) => {
|
|
197
|
+
const result = await shell.exec("sort | uniq", { stdin: names });
|
|
198
|
+
if (result.exitCode !== 0) throw new Error(result.stderr);
|
|
199
|
+
return result.stdout;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
await server.listen();
|
|
204
|
+
} finally {
|
|
205
|
+
await shell.dispose();
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Install `poe-code` and the MCP transport package in that server's own project.
|
|
210
|
+
Choose its filesystem, command bundle, limits, and opt-in capabilities there;
|
|
211
|
+
do not expose caller-supplied shell source unless arbitrary shell execution is
|
|
212
|
+
the deliberate API.
|
|
213
|
+
|
|
180
214
|
## Add a command
|
|
181
215
|
|
|
182
216
|
A `CommandDefinition` has a name and an `execute(context)` handler. This example
|
|
@@ -237,7 +271,7 @@ For SafeJS host integration, `makeSafeJsShellModule` exposes shell execution and
|
|
|
237
271
|
| --- | --- |
|
|
238
272
|
| `fs` | Required filesystem; no implicit host access. |
|
|
239
273
|
| `cwd` | Initial virtual directory; defaults to `/`. |
|
|
240
|
-
| `env` | Initial exported variables; defaults to an empty map, with `PWD` set from `cwd`. No host environment inheritance. |
|
|
274
|
+
| `env` | Initial exported variables; defaults to an empty map, with `PWD` set from `cwd`. No host environment inheritance. Never pass host `process.env` or any secret-bearing object: everything in `env` is readable by executed scripts (`env`, `printenv`, `$VAR`), and on Cloudflare Workers with `nodejs_compat` `process.env` contains the Worker's secret bindings. The shell logs a warning when it detects this. |
|
|
241
275
|
| `commands` | Existing `CommandRegistry`; defaults to an empty registry. |
|
|
242
276
|
| `limits` | Resource limits listed below. |
|
|
243
277
|
|
|
@@ -255,10 +289,19 @@ provided. Pass an `AbortSignal` as `signal` to cancel. [Option types](src/shell/
|
|
|
255
289
|
| `maxSourceBytes` | 1 MiB |
|
|
256
290
|
| `maxExpansionFields` | 10,000 |
|
|
257
291
|
| `maxExpansionBytes` | 16 MiB |
|
|
292
|
+
| `maxWallClockMs` | 30 seconds |
|
|
293
|
+
| `maxCpuMs` | 30 seconds, checked at command and cooperative-yield checkpoints |
|
|
258
294
|
| `pipeHighWaterMark` | 64 KiB |
|
|
259
295
|
|
|
260
296
|
Always call `dispose()` when finished. Shell failures normally produce an exit
|
|
261
297
|
code and stderr; limit violations, cancellation, and host failures can reject `exec()`.
|
|
298
|
+
For Cloudflare Workers, start with the exported `cloudflareWorkerLimits` profile
|
|
299
|
+
and configure command-family buffers at no more than 8 MiB. Create a separate
|
|
300
|
+
`Shell`, environment object, and quota-wrapped filesystem view for each tenant or
|
|
301
|
+
request. Never reuse tenant state across requests; import `withFileSystemQuota`
|
|
302
|
+
from `poe-code/safe-fs` to bound cumulative writes, including command-initiated
|
|
303
|
+
copies and streaming output. Admission control and rate limiting remain host
|
|
304
|
+
responsibilities.
|
|
262
305
|
|
|
263
306
|
### Command configuration
|
|
264
307
|
|
|
@@ -5,6 +5,11 @@ export * from "./fs/memory/index.js";
|
|
|
5
5
|
export * from "./fs/readonly/index.js";
|
|
6
6
|
export * from "./fs/mount/index.js";
|
|
7
7
|
export * from "./fs/overlay/index.js";
|
|
8
|
+
export { createFetchTransport } from "./commands/network/fetch-transport.js";
|
|
9
|
+
export type { FetchTransportOptions } from "./commands/network/fetch-transport.js";
|
|
10
|
+
export { createOriginAuthorizer } from "./commands/network/authorizer.js";
|
|
11
|
+
export type { OriginAllowlist, OriginAuthorizerOptions } from "./commands/network/authorizer.js";
|
|
12
|
+
export { cloudflareWorkerNetworkLimits } from "./commands/network/types.js";
|
|
8
13
|
export interface BrowserCommandsOptions {
|
|
9
14
|
readonly replace?: boolean;
|
|
10
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAOlF,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAOlF,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,YAAY,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AACjG,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAE5E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,IAAI,SAAS,iBAAiB,EAAE,CAKpE;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,kBAAkB,CAaxF"}
|