@sontoriyama/mcp-code-mode 0.0.0-stage → 0.4.1
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/CHANGELOG.md +175 -0
- package/LICENSE +21 -0
- package/README.md +212 -3
- package/SKILL.md +68 -0
- package/docs/pig.md +132 -0
- package/examples/codemode.tools.json +23 -0
- package/examples/pr-status.program.mjs +64 -0
- package/package.json +58 -4
- package/skills/commandcode/SKILL.md +75 -0
- package/skills/pig/SKILL.md +48 -0
- package/src/core.mjs +135 -0
- package/src/executor.mjs +454 -0
- package/src/manifest.mjs +154 -0
- package/src/mcp-client.mjs +891 -0
- package/src/mcp-server.mjs +607 -0
- package/src/plugins/engram.mjs +32 -0
- package/src/plugins/gh.mjs +83 -0
- package/src/run.mjs +347 -0
- package/src/tools.mjs +136 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
6
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.4.1] - 2026-12-06
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **A `notifications/cancelled` could arrive before its target request registered its `AbortController`.**
|
|
13
|
+
`readline` emits every buffered line of one stdin chunk in the same tick, and `dispatch` reached the
|
|
14
|
+
`tools/call` branch only after `await rejectEra(...)` — an `async` function with no `await` inside — so a
|
|
15
|
+
cold server that received request + cancellation together saw an empty `inflight` map and ran the whole
|
|
16
|
+
program anyway. `rejectEra` is now synchronous (registration happens before yielding) and `cancelledEarly`
|
|
17
|
+
(bounded to 256 ids) remembers cancellations for ids that have not registered yet.
|
|
18
|
+
- **CI `pack-smoke` could never pass:** the job grepped `'"name": "run_code"'` against the server's compact
|
|
19
|
+
JSON, which has no space after the colon. The greps now tolerate whitespace (`"name"\s*:\s*"run_code"`).
|
|
20
|
+
- **`read_spill` rejected the path it had just handed out on macOS.** `resolveSpillTarget` realpath'd
|
|
21
|
+
`CODEMODE_OUT_DIR` and compared the resolved target against a lexical path built from an envelope that
|
|
22
|
+
carries the directory **as configured**. On macOS `os.tmpdir()` lives under `/var`, a symlink to
|
|
23
|
+
`/private/var`, so every `read_spill({ path })` after a spill failed with
|
|
24
|
+
`spill.read path must stay inside CODEMODE_OUT_DIR`. The lexical containment check now accepts the
|
|
25
|
+
configured base and its realpath; the symlink-traversal guard still resolves and checks against the single
|
|
26
|
+
real base, so no escape becomes reachable.
|
|
27
|
+
|
|
28
|
+
### Tests
|
|
29
|
+
|
|
30
|
+
- New deterministic regression test: one stdin chunk carrying a `run_code`, a queued `run_code` and the
|
|
31
|
+
cancellation. It fails without the fix and passes with it.
|
|
32
|
+
- Regression test for the spill-path case above, using a symlinked/junctioned output prefix (skipped where
|
|
33
|
+
directory symlinks are unavailable).
|
|
34
|
+
|
|
35
|
+
## [0.4.0] - 2026-12-06
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- **`--serve-mcp`: dual-era MCP stdio server.** Exposes `run_code` and `read_spill` (plus `list_tools` when the
|
|
40
|
+
embedded catalog exceeds the ~6 KB budget) so a host can batch any number of upstream calls in one turn.
|
|
41
|
+
Serves modern `2026-07-28` requests carrying per-request `_meta` (`io.modelcontextprotocol/protocolVersion`,
|
|
42
|
+
`clientCapabilities`, `clientInfo`) statelessly, and answers the legacy `initialize` handshake (echoing the
|
|
43
|
+
requested version, else `2025-11-25`) for dual-era clients. `server/discover` advertises supported versions,
|
|
44
|
+
capabilities, server info and short instructions; unsupported versions return `-32022` with
|
|
45
|
+
`{ requested, supported }`; unknown tools/methods return `-32602`/`-32601` without crashing.
|
|
46
|
+
- **`listTools(filter)` and `callTool(name, args, opts)` inside `run_code`**: discovery and execution in the
|
|
47
|
+
same call, so the embedded catalog is a hint instead of a hard limit.
|
|
48
|
+
- **`read_spill`** with `offset`/`maxChars` returning `{ text, totalChars, offset, truncated, nextOffset }`,
|
|
49
|
+
path-contained to `CODEMODE_OUT_DIR`.
|
|
50
|
+
- **`--allow-tools <csv>`** (exact names or `prefix*`): filters `tools/list`, `listTools()` and the embedded
|
|
51
|
+
catalog, and rejects denied calls through `tools.*`, `callTool()` and `tools.call()`.
|
|
52
|
+
- **`--timeout-ms`** hard timeout per `run_code` (default `120000`).
|
|
53
|
+
- Shared `src/executor.mjs` used by both front-ends: `executeProgram()` owns console/stdout/exit capture, the
|
|
54
|
+
spill envelope and an optional `AbortSignal`/timeout.
|
|
55
|
+
- CI `pack-smoke` now drives `--serve-mcp` over the installed tarball (`server/discover` + `tools/list`), which
|
|
56
|
+
catches files missing from the package.
|
|
57
|
+
|
|
58
|
+
### Changed
|
|
59
|
+
|
|
60
|
+
- **MCP client negotiation is now dual-era and spec-verified.** It probes `server/discover` first on stdio,
|
|
61
|
+
caches the era per server process, accepts the version the server announces, and falls back to `initialize`
|
|
62
|
+
on any non-modern error. `clientInfo.version` comes from `package.json` instead of a hardcoded string.
|
|
63
|
+
- `run_code` calls are serialized in a FIFO queue: one global stdout/console/exit patch per execution, no races
|
|
64
|
+
across concurrent MCP calls, while `mapBounded` keeps parallelism inside a program. Queued calls can be
|
|
65
|
+
cancelled before they start.
|
|
66
|
+
- Cancellation aborts only the affected `run_code` (per-request `AbortController`); shared upstream clients are
|
|
67
|
+
never killed for a cancellation. A client that ignores cancellation and accumulates timeouts is recycled and
|
|
68
|
+
its in-flight requests fail with an explicit error.
|
|
69
|
+
- `process.stdout.write` and `process.exit` are captured while a program runs, so a program cannot corrupt
|
|
70
|
+
the JSON envelope or the MCP transport. In `--serve-mcp` the stdout writer is additionally diverted to
|
|
71
|
+
stderr for the whole server lifetime, so late writes from timers or floating promises after a run cannot
|
|
72
|
+
corrupt the JSON-RPC stream.
|
|
73
|
+
- **Renamed the package to `mcp-code-mode`** (was `agent-maxicodemode`) ahead of the first npm publish. The CLI
|
|
74
|
+
binary, `bin` entry and MCP `serverInfo`/`clientInfo` names follow the package name; GitHub repository URLs
|
|
75
|
+
are unchanged.
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
|
|
79
|
+
- `run_code` output in `--serve-mcp` is now bounded to `CODEMODE_MAX_OUTPUT_CHARS`: when the envelope spills,
|
|
80
|
+
the host receives a compact, valid-JSON envelope with `truncated`, `totalChars` and `spill.path` instead of
|
|
81
|
+
the full payload. `read_spill` still pages the complete envelope.
|
|
82
|
+
- A `run_code` timeout now aborts in-flight upstream calls: the timeout fires the same `AbortController` the
|
|
83
|
+
scoped tools receive, and per-call signals (e.g. `mapBounded`) are composed instead of shadowing it, so
|
|
84
|
+
upstreams get `notifications/cancelled` instead of being left running.
|
|
85
|
+
- Removed an unused helper from `src/run.mjs`.
|
|
86
|
+
- In `--serve-mcp`, writes that outlive a `run_code` (fired timers, floating promises, an aborted program)
|
|
87
|
+
are diverted to stderr instead of the JSON-RPC stdout, so a stray `console.log`/`process.stdout.write` can
|
|
88
|
+
no longer corrupt the transport.
|
|
89
|
+
- `read_spill` resolves symlinks with `realpath`, rejects non-regular files (FIFO/device/directory) via
|
|
90
|
+
`lstat`, and reads the file in bounded chunks instead of loading it whole, so a large spill cannot OOM the
|
|
91
|
+
server; paging also no longer splits surrogate pairs at page boundaries.
|
|
92
|
+
- `--allow-tools ""` (or any explicit empty list) now denies every tool instead of silently allowing all;
|
|
93
|
+
only an absent flag disables the filter.
|
|
94
|
+
|
|
95
|
+
### Security
|
|
96
|
+
|
|
97
|
+
- `--serve-mcp` is the only opt-in. No consent theatre flag is added; `--allow-tools` is documented as the only
|
|
98
|
+
enforceable control.
|
|
99
|
+
- `gh`/`engram` plugins stay disabled by default in server mode.
|
|
100
|
+
- README documents the prompt-injection threat model and warns against declaring the same upstreams twice
|
|
101
|
+
(host + wrapper).
|
|
102
|
+
|
|
103
|
+
## [0.3.3] - 2026-12-06
|
|
104
|
+
|
|
105
|
+
### Added
|
|
106
|
+
|
|
107
|
+
- `--version` / `-v` and `--help` / `-h`: both print to stdout and exit `0`.
|
|
108
|
+
- Every envelope now carries `version`. When stdout had to be truncated it also carries
|
|
109
|
+
`spill.path`, so an agent can filter the full file on the next turn without parsing stderr.
|
|
110
|
+
Keeping the path out of non-truncated envelopes avoids paying ~30 tokens per call for a path the
|
|
111
|
+
caller does not need (visible in `bench/benchmark.mjs`).
|
|
112
|
+
- Tests for the CLI meta flags, usage errors, envelope fields, and module-syntax detection.
|
|
113
|
+
- Benchmark scenario with synthetic ~4 KB payloads (10.3k payload tokens across 10 direct calls
|
|
114
|
+
vs ~102 in one turn) and a reproducible Node/platform/date header. The tiny-payload scenario now
|
|
115
|
+
states that it saves turns, not tokens.
|
|
116
|
+
- `CHANGELOG.md`, a `prepublishOnly` test gate, and a publish workflow that uses npm provenance.
|
|
117
|
+
- CI installs the packed tarball into a clean prefix and runs the installed binary.
|
|
118
|
+
|
|
119
|
+
### Changed
|
|
120
|
+
|
|
121
|
+
- Unknown `--flags` are usage errors with exit `2`. They are no longer imported as program paths,
|
|
122
|
+
which used to fail with exit `1` and leave a `--version-*.json` spill behind.
|
|
123
|
+
- Snippet vs. module detection now comes from the parser: `new AsyncFunction` is tried first and
|
|
124
|
+
the `data:` module path is used only for real module syntax. Export-like text inside strings no
|
|
125
|
+
longer misroutes a snippet.
|
|
126
|
+
- CI matrix adds Node 24 on Linux, macOS and Windows.
|
|
127
|
+
- README: reframed around who the tool is for (shell-only harnesses without native Code Mode),
|
|
128
|
+
added explicit limitations and security model, a harness-fit table, an FAQ ("why not `node -e`?"),
|
|
129
|
+
the real Install section, and refreshed flags/exit-code docs.
|
|
130
|
+
|
|
131
|
+
## [0.3.2] - 2026-12-06
|
|
132
|
+
|
|
133
|
+
### Added
|
|
134
|
+
|
|
135
|
+
- Contributor `AGENTS.md` with the repository's architectural invariants.
|
|
136
|
+
- PiG variant of the skill (`skills/pig/SKILL.md`) and `docs/pig.md` mapping PiG's native
|
|
137
|
+
`codemode` tool against this runner.
|
|
138
|
+
|
|
139
|
+
### Changed
|
|
140
|
+
|
|
141
|
+
- README: package size wording and release metadata.
|
|
142
|
+
|
|
143
|
+
## [0.3.1] - 2026-12-06
|
|
144
|
+
|
|
145
|
+
### Added
|
|
146
|
+
|
|
147
|
+
- Credits for the Code Mode lineage, Engram and gentle-ai.
|
|
148
|
+
|
|
149
|
+
### Fixed
|
|
150
|
+
|
|
151
|
+
- CI: list test files explicitly so Windows + Node 20 pass.
|
|
152
|
+
|
|
153
|
+
## [0.3.0] - 2026-12-06
|
|
154
|
+
|
|
155
|
+
### Added
|
|
156
|
+
|
|
157
|
+
- `spill.read()` for follow-up filtering without re-running tools.
|
|
158
|
+
- Reproducible benchmark and a Linux/macOS/Windows CI matrix.
|
|
159
|
+
- Zero-dependency stdio MCP client (`--mcp` / `--mcp-config`) with `.cmd`/`.bat` support,
|
|
160
|
+
bidirectional ping, buffer caps and process-tree teardown on Windows.
|
|
161
|
+
- Package metadata and hardened `mapBounded` concurrency/abort handling.
|
|
162
|
+
|
|
163
|
+
## [0.2.0] - 2026-12-06
|
|
164
|
+
|
|
165
|
+
### Added
|
|
166
|
+
|
|
167
|
+
- Inline (`-e` / `--code`) and stdin (`-` / `--stdin`) execution.
|
|
168
|
+
- Declarative CLI manifests (`--manifest`) and progressive tool discovery (`--list-tools`).
|
|
169
|
+
|
|
170
|
+
## [0.1.0] - 2026-12-06
|
|
171
|
+
|
|
172
|
+
### Added
|
|
173
|
+
|
|
174
|
+
- Initial release: zero-dependency local Code Mode runner with bounded stdout, lossless disk spill
|
|
175
|
+
and an honest non-sandbox security model.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sontoriyama
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,212 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# mcp-code-mode
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sontoriyama/mcp-code-mode/actions)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
**Batch N stdio MCP or CLI tool calls into 1 shell turn, with bounded stdout and lossless disk spill.**
|
|
10
|
+
Pure Node.js (`>= 20`) ESM, `~44 kB` packed (`~147 kB` unpacked), zero dependencies, no daemon, no cloud sandbox.
|
|
11
|
+
|
|
12
|
+
> **Who this is for:** coding harnesses that have a shell tool but **no native Code Mode**, MCP hosts that want to collapse multiple upstream MCP servers into 2–3 tools via `--serve-mcp`, and CI/cron scripts that need a zero-dep stdio MCP batch client. If your harness already ships native Code Mode, use its built-in tool instead.
|
|
13
|
+
|
|
14
|
+
### Before vs. After (fetch 10 GitHub issues, return only open ones)
|
|
15
|
+
|
|
16
|
+
| | Direct MCP tool calls | `mcp-code-mode` |
|
|
17
|
+
| :--- | :--- | :--- |
|
|
18
|
+
| **LLM turns** | 10 sequential turns + approval prompts | **1 turn** |
|
|
19
|
+
| **Context window** | 10 raw JSON payloads dumped into context | **Filtered JSON only** (full payload spilled to `.agent/out/`, `0600`) |
|
|
20
|
+
| **Execution** | Serial round-trips | **Bounded concurrency** (`mapBounded`) |
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# 1 turn, zero temp files for the program — lazy-spawns only the touched MCP server from .mcp.json
|
|
24
|
+
mcp-code-mode --no-default-plugins --mcp-config .mcp.json -e '
|
|
25
|
+
const issues = await mapBounded(args.ids, 4, (id, _i, signal) =>
|
|
26
|
+
tools.mcp.github.get_issue({ id }, { signal })
|
|
27
|
+
);
|
|
28
|
+
return issues.filter((x) => x.state === "open").map(({ id, title }) => ({ id, title }));
|
|
29
|
+
' '{"ids":[1,2,3,4,5,6,7,8,9,10]}'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Explicit Limitations & Security Model
|
|
33
|
+
|
|
34
|
+
- **Not a sandbox:** Scripts execute with normal host Node.js privileges (`execTool` and `execJson` are in scope). Argument/manifest validation prevents accidental flag injection and context blowups, not hostile code. Designed for read/filter/batch orchestration; keep writes and external side effects in explicit, visible tool calls.
|
|
35
|
+
- **stdio MCP only:** Supports local stdio JSON-RPC 2.0 MCP servers (`tools/list`, `tools/call`, `ping`, `notifications/cancelled`). No HTTP/SSE transport, no MCP `resources`/`prompts`, and no built-in OAuth/auth layer.
|
|
36
|
+
- **Requires agent instructions:** An agent will not invoke this CLI automatically unless you drop [`SKILL.md`](./SKILL.md) into its skills folder or add a short rule to `AGENTS.md` (e.g., use for `>= 4` homogeneous read queries).
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Harness Fit
|
|
41
|
+
|
|
42
|
+
| Environment | Recommended? | Why |
|
|
43
|
+
| :--- | :---: | :--- |
|
|
44
|
+
| **Shell-only coding harnesses** (e.g. Command Code, or any agent with shell access and no native Code Mode) | **Yes** | Collapses multi-step MCP/CLI fan-outs into 1 shell turn with bounded stdout. |
|
|
45
|
+
| **MCP hosts with tool bloat** (e.g. Claude Desktop, Cursor, Windsurf, custom MCP clients) | **Yes (`--serve-mcp`)** | Collapses multiple upstream stdio MCP servers into 2–3 tools (`run_code`, `read_spill`, optional `list_tools`) to save prompt context. |
|
|
46
|
+
| **PiG (`pig`)** | **No (use native)** | PiG ships an in-process QuickJS `codemode` tool. See [`docs/pig.md`](./docs/pig.md) for the 5 fallback cases where this runner still helps. |
|
|
47
|
+
| **Harnesses with parallel native file tools** (e.g. Antigravity) | **Partial** | Keep file reads/edits on native tools; use this runner only for batched stdio MCP or external CLI (`gh`, `engram`) queries. |
|
|
48
|
+
| **Non-agentic automation** (CI, cron, local scripts) | **Yes** | Deterministic, zero-dep CLI to query stdio MCP servers and emit compact JSON with spill. |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Why this exists
|
|
53
|
+
|
|
54
|
+
Direct tool-by-tool calling breaks down on multi-step read workflows in two ways:
|
|
55
|
+
|
|
56
|
+
1. **The N+1 round-trip tax:** Chaining 6–20 MCP or CLI calls burns turns, latency, and repeated approval prompts.
|
|
57
|
+
2. **Context rot from large intermediate payloads:** Dumping 10 raw 2–10 KB JSON objects into the context window inflates token costs and degrades reasoning. (On tiny payloads, batching saves turns and approvals rather than tokens—see the benchmark below.)
|
|
58
|
+
|
|
59
|
+
**What the runner provides:**
|
|
60
|
+
|
|
61
|
+
- **Zero-dep stdio MCP bridge (`--mcp-config` / `--mcp`):** Reads standard `mcpServers` configs (`claude_desktop_config.json`, `.mcp.json`), lazy-spawns servers only when touched via `Proxy`, compacts JSON Schemas in `--list-tools`, handles bidirectional JSON-RPC 2.0 (`ping`), tolerates dirty stdout, wires `notifications/cancelled` to `AbortSignal`, and cleans up process trees on exit (POSIX process groups + Windows `taskkill /T /F` + `.cmd`/`.bat` shim support).
|
|
62
|
+
- **No temp files for the program:** Run one-shot scripts inline (`-e` / `--code`) or via `stdin` (`-`, capped by `CODEMODE_MAX_STDIN_BYTES`, default `1 MiB`). `mapBounded(items, concurrency, fn)` is injected automatically (`1..16` concurrency clamp + shared `AbortSignal`).
|
|
63
|
+
- **Bounded stdout + lossless spill + `spill.read()`:** Full valid JSON is always written to `.agent/out/` (`0o600`, `wx`). Oversized stdout is truncated head+tail so one huge payload never blows up a session, and follow-up turns can filter the spilled file in JS via `spill.read()` without re-running tools.
|
|
64
|
+
- **Declarative CLI manifests & optional plugins:** Plug in internal CLIs with `--manifest <file>` (typed validation + anti-flag-injection via `execFile` without shell) or use the optional `gh` / `engram` plugins (`--plugins` / `--no-default-plugins`).
|
|
65
|
+
|
|
66
|
+
> **Important:** Keep `.agent/out/` in your project's `.gitignore` so spilled payloads are never committed accidentally.
|
|
67
|
+
|
|
68
|
+
## Honest Benchmark (`node bench/benchmark.mjs`)
|
|
69
|
+
|
|
70
|
+
Reproducible local benchmark against the pure-Node mock MCP server (`Node v24.22.1`, `win32/x64`, `2026-12-06`). It includes a tiny-payload case (token parity), a synthetic ~4 KB payload case (where the context win actually comes from), and a 1-step case where direct calling wins. Timings vary ±10–20% per run; run it yourself:
|
|
71
|
+
|
|
72
|
+
| Scenario | Direct tool calls | `mcp-code-mode` | Winner |
|
|
73
|
+
| :--- | :---: | :---: | :--- |
|
|
74
|
+
| 1. 10x small MCP fetch + aggregate | 10 turns \| ~55 ms \| ~56 stdout tok | **1 turn** \| ~117 ms \| ~54 stdout tok | **`mcp-code-mode`** (10x fewer turns; tiny payloads) |
|
|
75
|
+
| 2. 10x ~4 KB synthetic MCP payloads + filter | 10 turns \| ~48 ms \| ~10,321 stdout tok | **1 turn** \| ~113 ms \| **~102 stdout tok** | **`mcp-code-mode`** (~101x fewer payload tok; scenario-specific) |
|
|
76
|
+
| 3. 6x concurrent slow MCP ops (40 ms) | 6 turns \| ~325 ms \| ~20 stdout tok | **1 turn** \| **~177 ms** \| ~49 stdout tok | **`mcp-code-mode`** (parallel + 6x fewer turns) |
|
|
77
|
+
| 4. Single 1-step MCP call | **1 turn \| ~50 ms \| ~6 stdout tok** | 1 turn \| ~109 ms \| ~54 stdout tok | **Direct call** (lower overhead) |
|
|
78
|
+
|
|
79
|
+
*Note: wall-clock times measure local Node process + IPC only, and `stdout tok` measures returned payload bytes (`chars / 4`, including the runner's ~50-token JSON envelope). In real agent sessions, each extra LLM turn also adds 2–10 s and prompt/history overhead.*
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
Requires Node.js >= 20. Zero npm dependencies.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Run on demand
|
|
87
|
+
npx @sontoriyama/mcp-code-mode --version
|
|
88
|
+
|
|
89
|
+
# Or install globally
|
|
90
|
+
npm install -g @sontoriyama/mcp-code-mode
|
|
91
|
+
|
|
92
|
+
# Or clone and run directly from source
|
|
93
|
+
git clone https://github.com/sontoriyama/mcp-code-mode.git
|
|
94
|
+
cd mcp-code-mode
|
|
95
|
+
npm test
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The binary is `mcp-code-mode` after a global install. A freshly published version can be rejected
|
|
99
|
+
by an npm `min-release-age`/`minimumReleaseAge` gate (`ENOVERSIONS`/`ETARGET`); relax it for that
|
|
100
|
+
single install with `--min-release-age=0`.
|
|
101
|
+
|
|
102
|
+
## Quick Start
|
|
103
|
+
|
|
104
|
+
*Shell note: examples below use POSIX / PowerShell single quotes; on Windows `cmd.exe`, use double quotes or `--stdin`.*
|
|
105
|
+
*These examples use the mock MCP fixture, which ships only in the repo, so they run from a clone
|
|
106
|
+
(`node src/run.mjs`). With the global install, use the `mcp-code-mode` binary instead and point
|
|
107
|
+
`--mcp-config` at your own servers.*
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 1. Discover tools from the bundled mock MCP server (or pass --mcp-config .mcp.json)
|
|
111
|
+
node src/run.mjs --no-default-plugins --mcp 'mock=node test/fixtures/mock-mcp-server.mjs' --list-tools
|
|
112
|
+
|
|
113
|
+
# 2. Batch 4 MCP calls in 1 turn (writes full JSON spill to .agent/out/)
|
|
114
|
+
node src/run.mjs --no-default-plugins --mcp 'mock=node test/fixtures/mock-mcp-server.mjs' -e '
|
|
115
|
+
return await mapBounded([1, 2, 3, 4], 4, (id, _i, signal) =>
|
|
116
|
+
tools.mcp.mock.echo_item({ id, tag: id % 2 === 0 ? "b" : "a" }, { signal })
|
|
117
|
+
);
|
|
118
|
+
'
|
|
119
|
+
|
|
120
|
+
# 3. Filter the spilled JSON from step 2 without re-running tools
|
|
121
|
+
node src/run.mjs -e 'return spill.read().result.filter((x) => x.tag === "b");'
|
|
122
|
+
|
|
123
|
+
# 4. Declarative CLI manifest discovery
|
|
124
|
+
node src/run.mjs --no-default-plugins --manifest examples/codemode.tools.json --list-tools
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## MCP Server Mode (`--serve-mcp`)
|
|
128
|
+
|
|
129
|
+
`--serve-mcp` turns the runner into a local stdio MCP server that exposes **two or three** tools instead of one per upstream:
|
|
130
|
+
|
|
131
|
+
- **`run_code`** — runs a JS program with `tools.<ns>.<tool>()`, `args`, `mapBounded`, `execTool`, `execJson` and `spill.read()`, plus `listTools()` and `callTool()` injected into the program scope. Discovery and execution happen in the same turn, so the embedded catalog is a hint, not a hard limit. Output is bounded; oversized envelopes carry `spill.path`.
|
|
132
|
+
- **`read_spill`** — paginated read of a spilled envelope (`offset`, `maxChars`) returning `{ text, totalChars, offset, truncated, nextOffset }`. Last resort: prefer returning summaries from `run_code`.
|
|
133
|
+
- **`list_tools`** — only exposed when the upstream catalog does not fit in the ~6 KB embedded budget.
|
|
134
|
+
|
|
135
|
+
Wire format: JSON-RPC 2.0 over NDJSON. The server is **dual-era**: modern `2026-07-28` requests carry `_meta` (`io.modelcontextprotocol/protocolVersion`, `.../clientCapabilities`, optional `.../clientInfo`) and are served statelessly; legacy clients use `initialize`, and the handshake echoes the requested version (or `2025-11-25`). `server/discover` returns supported versions, capabilities, server info and short instructions. Unsupported versions fail with `-32022` plus `{ requested, supported }`; unknown tools and methods return `-32602`/`-32601`, never a crash. `run_code` calls are serialized in a FIFO queue — the parallelism you want is `mapBounded` *inside* the program — so the one console/stdout/exit patch per execution never races.
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"mcpServers": {
|
|
140
|
+
"codemode": {
|
|
141
|
+
"command": "npx",
|
|
142
|
+
"args": ["-y", "@sontoriyama/mcp-code-mode", "--serve-mcp"]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
To batch upstream MCP servers, declare them **inside** the wrapper (inline `--mcp` or a config file):
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"mcpServers": {
|
|
153
|
+
"codemode": {
|
|
154
|
+
"command": "npx",
|
|
155
|
+
"args": [
|
|
156
|
+
"-y", "@sontoriyama/mcp-code-mode", "--serve-mcp",
|
|
157
|
+
"--mcp-config", "C:\\Users\\you\\.codemode\\upstreams.json"
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Do not declare the same upstream twice** (once at the host level and once inside the wrapper): you duplicate the tools, the context cost and the spawned processes. In server mode the `gh`/`engram` plugins are disabled by default; enable them explicitly with `--plugins`.
|
|
165
|
+
|
|
166
|
+
**`--allow-tools` is the only enforceable control:** a CSV of exact names or `prefix*` patterns (e.g. `mcp.gh.*`). It filters `tools/list`, `listTools()` and the embedded catalog **and** rejects denied calls made through `tools.*`, `callTool()` or `tools.call()` — filtering alone would be cosmetic. Cancellation is per `run_code` (`notifications/cancelled` aborts only that call); shared upstream clients are never killed for cancelling one execution, and a client that keeps ignoring cancellation and timing out is recycled with an explicit error so no zombies remain. Hard timeout defaults to `120 s` (`--timeout-ms`, or per-call `timeoutMs`).
|
|
167
|
+
|
|
168
|
+
> **Threat model:** this is not a sandbox. `--serve-mcp` *is* the opt-in. Anything the host can invoke runs with your user privileges, and untrusted content read by a program (a file, an issue body, a web page) is a prompt-injection path into `run_code`. Stdout/console/`process.exit` interception covers JavaScript writes only — not `fs.writeSync(1)` nor child processes with inherited stdio.
|
|
169
|
+
|
|
170
|
+
### CLI Modes, Flags & Environment Variables
|
|
171
|
+
|
|
172
|
+
- `<program.mjs> [jsonArgs]`: execute a local ESM module exporting `run({ tools, args, mapBounded, spill })` or a default function (supports relative `./` imports).
|
|
173
|
+
- `--code <js>` / `-e <js>`: execute inline async JS body (`tools`, `args`, `mapBounded`, `execTool`, `execJson`, `spill` in scope).
|
|
174
|
+
- `-` / `--stdin`: read inline JS body or ESM `export async function run` module from `stdin` (ESM snippets via `data:` URL do not support relative `./` imports; use `<program.mjs>` for local imports).
|
|
175
|
+
- `--mcp-config <file>` / `CODEMODE_MCP_CONFIG`: load standard `{ "mcpServers": { ... } }` JSON config.
|
|
176
|
+
- `--mcp "alias=cmd arg1 arg2"`: attach an inline stdio MCP server (repeatable).
|
|
177
|
+
- `--manifest <file>` / `CODEMODE_MANIFEST`: load declarative CLI tools from JSON.
|
|
178
|
+
- `--plugins <csv>` / `CODEMODE_PLUGINS` / `--no-default-plugins`: select or disable built-in plugins (`gh,engram`).
|
|
179
|
+
- `--list-tools [filter]`: print compact JSON catalog (including compacted MCP schemas) and exit.
|
|
180
|
+
- `--serve-mcp`: run as a dual-era stdio MCP server (see [MCP Server Mode](#mcp-server-mode---serve-mcp)). Implies `--no-default-plugins` unless `--plugins` is passed explicitly; never reads a program from stdin.
|
|
181
|
+
- `--allow-tools <csv>`: enforce a tool allowlist (exact names or `prefix*`) in `tools/list`, `listTools()` and execution.
|
|
182
|
+
- `--timeout-ms <n>`: hard timeout per `run_code` in server mode (default `120000`).
|
|
183
|
+
- `--version` / `-v`, `--help` / `-h`: print the version or the usage text to stdout and exit `0`.
|
|
184
|
+
- `CODEMODE_MAX_OUTPUT_CHARS` (`32000`), `CODEMODE_MAX_STDIN_BYTES` (`1048576`), `CODEMODE_OUT_DIR` (`.agent/out`), `CODEMODE_MCP_VERBOSE` (`1`).
|
|
185
|
+
|
|
186
|
+
Unknown `--flags` are usage errors (`exit 2`), never treated as program paths. Every run prints a JSON envelope with a `version` field; when stdout had to be truncated the envelope also carries `spill.path`, so the next turn can filter the full file without parsing stderr. The spill file always holds the unbounded envelope, and stderr names it on every run. Exit codes: `0` program ran (`ok: true`), `1` program threw (`ok: false` plus `error`), `2` invalid usage or `jsonArgs` (nothing runs, no spill).
|
|
187
|
+
|
|
188
|
+
## FAQ
|
|
189
|
+
|
|
190
|
+
**Why not just run `node -e`?**
|
|
191
|
+
For plain CLI commands, `node -e` is fine. What `node -e` cannot do out of the box is talk JSON-RPC 2.0 to stdio MCP servers configured in `.mcp.json`, lazy-spawn and tear down process trees cleanly (including Windows `.cmd` shims), wire `AbortSignal` to `notifications/cancelled`, or cap stdout while spilling the full JSON for a follow-up `spill.read()` pass.
|
|
192
|
+
|
|
193
|
+
**Why not write a normal checked-in script?**
|
|
194
|
+
If you run the same workflow every week, a checked-in script is better. `mcp-code-mode` is for ad-hoc, one-shot batching during an agent session where you do not want to create throwaway `.mjs` files or re-implement MCP client boilerplate on every task.
|
|
195
|
+
|
|
196
|
+
## Agent Integration
|
|
197
|
+
|
|
198
|
+
Drop [`SKILL.md`](./SKILL.md) into your agent's skills directory or copy its rules into your `AGENTS.md`.
|
|
199
|
+
|
|
200
|
+
### PiG (`pig`)
|
|
201
|
+
|
|
202
|
+
PiG ships code mode natively (`codemode`: JavaScript in QuickJS/WASM, in-process, no Node), so this runner is **not** the right tool there. [`docs/pig.md`](./docs/pig.md) has the API mapping, the one settings line that enables the native tool, a one-turn verification recipe, and the five cases where the runner still wins. A ready-to-install PiG skill lives in [`skills/pig`](./skills/pig/SKILL.md).
|
|
203
|
+
|
|
204
|
+
## Credits
|
|
205
|
+
|
|
206
|
+
- **Engram** — persistent memory system for AI coding agents ([Gentleman-Programming/engram](https://github.com/Gentleman-Programming/engram)). It is also a reference integration for this tool: many homogeneous read-only CLI queries collapse into one turn. The optional `engram` plugin wraps its read-only CLI; this credit is a thank-you to the Gentleman Programming ecosystem, not a dependency or an official endorsement.
|
|
207
|
+
- **gentle-ai** — agent configuration harness and ODD workflow ([Gentleman-Programming/gentle-ai](https://github.com/Gentleman-Programming/gentle-ai)), which shaped the local agent workflow this tool was extracted from. Thanks to Alan Buscaglia and the Gentleman Programming community.
|
|
208
|
+
- **Code Mode lineage** — inspired by Cloudflare's Code Mode, Anthropic's Code Execution with MCP, the `run_code` design in dsh (deepseek-harness), and qwen-code's `exec`/CodeModeOnly. This is an independent implementation: it reuses their ideas, not their code.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT © 2026 [sontoriyama](https://github.com/sontoriyama) — also building [Vozflow](https://vozflow.dev), fast voice dictation.
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mcp-code-mode
|
|
3
|
+
description: Batch 4+ homogeneous read-only MCP or CLI queries into one tool call via inline/stdin/file JS execution with lazy stdio MCP bridge, progressive tool discovery, bounded output, and disk spill.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# mcp-code-mode
|
|
7
|
+
|
|
8
|
+
Use local Code Mode when a task needs **>= 4 read-only MCP or CLI calls** (or multi-step chaining/filtering/pagination) and you want a compact summary without flooding the context window.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @sontoriyama/mcp-code-mode # binary: mcp-code-mode
|
|
14
|
+
npx @sontoriyama/mcp-code-mode --version # on demand, no install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
From a clone, replace `mcp-code-mode` with `node src/run.mjs`. Node `>= 20`, zero dependencies.
|
|
18
|
+
|
|
19
|
+
## When to use
|
|
20
|
+
|
|
21
|
+
- **Use `mcp-code-mode`** for:
|
|
22
|
+
- Multi-step MCP workflows (`--mcp-config .mcp.json` or `--mcp "alias=cmd args"`) where you need to chain calls, filter/paginate in RAM, or fan out concurrently with `mapBounded`.
|
|
23
|
+
- >= 4 homogeneous CLI read queries (`--manifest` or built-in `gh`/`engram` plugins).
|
|
24
|
+
- Filtering a previous large spill from `.agent/out/` via `spill.read()` without re-running tools.
|
|
25
|
+
- **Do NOT use it** for:
|
|
26
|
+
- Single 1-step queries (direct tool call has lower overhead).
|
|
27
|
+
- Local file reads, searches, or edits when your harness already provides fast native parallel file tools.
|
|
28
|
+
- Irreversible writes or external side effects (comments, pushes, merges, deletes) — keep those in explicit, visible tool calls.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 1. Progressive discovery (compacted MCP + CLI schemas)
|
|
34
|
+
mcp-code-mode --no-default-plugins --mcp-config .mcp.json --list-tools [filter]
|
|
35
|
+
|
|
36
|
+
# 2. Inline MCP batching (no temp file)
|
|
37
|
+
mcp-code-mode --no-default-plugins --mcp-config .mcp.json -e '
|
|
38
|
+
return await mapBounded(args.ids, 4, (id, _i, signal) => tools.mcp.server.tool({ id }, { signal }));
|
|
39
|
+
' '{"ids":[1,2,3,4]}'
|
|
40
|
+
|
|
41
|
+
# 3. Follow-up filter on the latest spilled output in .agent/out/
|
|
42
|
+
mcp-code-mode -e 'return spill.read().result.slice(0, 10);'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Hosts with MCP support
|
|
46
|
+
|
|
47
|
+
Instead of the CLI, register the runner as one stdio MCP server; it exposes `run_code` (batch anything in one turn), `read_spill` (paginated follow-up) and, only when the catalog overflows, `list_tools`:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"mcpServers": {
|
|
52
|
+
"codemode": {
|
|
53
|
+
"command": "npx",
|
|
54
|
+
"args": ["-y", "@sontoriyama/mcp-code-mode", "--serve-mcp"]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Declare upstream servers **inside** the wrapper (`--mcp-config`), never twice, and use `--allow-tools` when you want an enforceable allowlist.
|
|
61
|
+
|
|
62
|
+
## Rules
|
|
63
|
+
|
|
64
|
+
1. Prefer `-e` / `stdin` (`-`) for one-off batches so you do not leave temp `.mjs` files on disk.
|
|
65
|
+
2. Always pass `{ signal }` from `mapBounded(items, concurrency, (item, idx, signal) => ...)` to `tools.mcp.*` / `tools.*` so failures cancel in-flight work immediately.
|
|
66
|
+
3. Return compact summaries (counts, statuses, short excerpts), never raw unedited payloads.
|
|
67
|
+
4. `mcp-code-mode` is an output-bounding runner, not a security sandbox; keep programs strictly read-only.
|
|
68
|
+
5. Ensure `.agent/out/` is in `.gitignore`.
|
package/docs/pig.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Using this with PiG (`pig`)
|
|
2
|
+
|
|
3
|
+
**Short version: on PiG you should not use this runner.** PiG ships code mode natively — a
|
|
4
|
+
`codemode` tool that runs JavaScript in QuickJS compiled to WebAssembly, inside the `pig`
|
|
5
|
+
process, with no Node.js involved. This page exists so PiG users find that out before wiring
|
|
6
|
+
a Node runner they do not need, and so the five cases where the runner still wins are
|
|
7
|
+
written down honestly.
|
|
8
|
+
|
|
9
|
+
Measured against `pig` 1.7.0 on Windows 11 (Node 24.22.1 available).
|
|
10
|
+
|
|
11
|
+
## The native equivalent
|
|
12
|
+
|
|
13
|
+
```jsonc
|
|
14
|
+
// ~/.pig/agent/settings.json
|
|
15
|
+
{
|
|
16
|
+
"defaultTools": ["+codemode"],
|
|
17
|
+
"codemode": { "mode": "on", "inlineBudget": 3000 }
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`+codemode` keeps the default `read`, `bash`, `edit`, `write` and adds the script tool.
|
|
22
|
+
`tool_search` is deliberately left out: with no MCP servers configured it has nothing to
|
|
23
|
+
search, and PiG activates it by itself for a server with `deferred` exposure.
|
|
24
|
+
|
|
25
|
+
Reference: `pig docs path` → `codemode.md`.
|
|
26
|
+
|
|
27
|
+
## API mapping
|
|
28
|
+
|
|
29
|
+
Same job, different runtime. The differences that bite when you port a script:
|
|
30
|
+
|
|
31
|
+
| This repo (Node) | PiG `codemode` |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `mapBounded(items, n, fn)` + `{ signal }` | `Promise.allSettled([...])` — there is **no** `mapBounded` |
|
|
34
|
+
| `tools.mcp.github.get_issue(...)` | `tools.mcp__github__get_issue({...})` (double underscore) |
|
|
35
|
+
| `tools.gh.*`, `tools.engram.*` plugins | `tools.bash({ command })`, or an MCP server's tools |
|
|
36
|
+
| `--mcp-config .mcp.json` / `--mcp "alias=cmd"` | `mcp.json` managed by `pig` / `/mcp`; exposure `codemode` by default |
|
|
37
|
+
| `--list-tools [filter]` | `searchTools(q)`, `describeTool(name)`, `describeNamespace(ns)`, `ALL_TOOLS` |
|
|
38
|
+
| `--manifest tools.json` | no equivalent — see *Where the runner still wins* |
|
|
39
|
+
| `CODEMODE_MAX_OUTPUT_CHARS` (32000) | `// @options: {"max_output_tokens": N}` (default 10000) |
|
|
40
|
+
| `spill.read()` on `.agent/out/` | the tool result names a temp file; `tools.read({ path })` it |
|
|
41
|
+
| `jsonArgs` argument | `args` is not a thing; inline the data in the script or `load(key)` it |
|
|
42
|
+
| (none) | `store(key, value)` / `load(key)` between calls |
|
|
43
|
+
| (none) | `models.classify()` / `models.generateImages()` |
|
|
44
|
+
|
|
45
|
+
An options line must be the **first line** of the script:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
// @options: {"max_output_tokens": 2000, "timeout_ms": 60000}
|
|
49
|
+
const [a, b] = await Promise.allSettled([
|
|
50
|
+
tools.bash({ command: "gh pr view 1 --json state,title" }),
|
|
51
|
+
tools.bash({ command: "gh issue view 2 --json state,labels" }),
|
|
52
|
+
]);
|
|
53
|
+
return [a, b].map((r) => (r.status === "fulfilled" ? r.value.output.trim().slice(0, 200) : r.reason.message));
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The sandbox has no Node APIs, no file system of its own, no network and **no timers**. A script
|
|
57
|
+
reaches the outside world only through `tools.*` and `models`. The script is isolated; the tools
|
|
58
|
+
it calls are not — `tools.bash` runs on the host with your privileges. Keep reads inside the
|
|
59
|
+
script and external side effects in explicit tool calls, exactly as `SKILL.md` says.
|
|
60
|
+
|
|
61
|
+
Limits worth knowing: 256 MB per VM, at most two live VMs per `pig` process
|
|
62
|
+
(`PI_CODEMODE_MAX_WORKERS`), no nested `codemode` calls.
|
|
63
|
+
|
|
64
|
+
## Verify it in one turn
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pig -p 'Use the codemode tool ONCE: inside the script call tools.bash three times in
|
|
68
|
+
parallel (Promise.allSettled) with "node --version", "git --version" and "echo hello".
|
|
69
|
+
Return only {nodeVersion, gitVersion, echo}. Do not use any other tool.'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Observed on 2026-12-06, pig 1.7.0: **one** `codemode` call, and the model received only
|
|
73
|
+
`{"nodeVersion":"v24.22.1","gitVersion":"git version 2.51.0.windows.2","echo":"hello"}`. Same
|
|
74
|
+
three commands through this runner cost one `node` startup (~130 ms) plus a `cmd.exe` quoting
|
|
75
|
+
hazard on Windows.
|
|
76
|
+
|
|
77
|
+
Two traps the recipe deliberately avoids, both found the hard way:
|
|
78
|
+
|
|
79
|
+
- **Use version commands, not repository ones.** `git rev-parse --short HEAD` outside a git
|
|
80
|
+
repository returns `fatal: Needed a single revision`, which lands in your summary as a value
|
|
81
|
+
(`head: "fatal: ..."`) instead of failing the script — `tools.bash` resolves for non-zero exit
|
|
82
|
+
codes too. Inside a repository, prefer `git -C <path> rev-parse` so the answer does not depend
|
|
83
|
+
on the session's working directory.
|
|
84
|
+
- **Record only output you produced.** A doctored "observed" line, even for a cosmetic edit, is
|
|
85
|
+
the one thing this page cannot afford.
|
|
86
|
+
|
|
87
|
+
## Where the runner still wins
|
|
88
|
+
|
|
89
|
+
Be specific, keep it short. Inside PiG, reach for `mcp-code-mode` (or `node src/run.mjs` from a
|
|
90
|
+
clone) only when one of these applies:
|
|
91
|
+
|
|
92
|
+
1. **The program needs Node APIs.** `fs`, `net`, `crypto`, `timers`, `process`, a local socket, a
|
|
93
|
+
library from `node_modules`. `codemode` forbids all of it.
|
|
94
|
+
2. **You want declarative CLI manifests.** `--manifest` gives typed argument validation and
|
|
95
|
+
`execFile` without a shell, which is what keeps flag injection and context blowups out. PiG's
|
|
96
|
+
`codemode` has no manifest layer.
|
|
97
|
+
3. **You want the spill inside the repo.** `.agent/out/` is a stable, `.gitignore`-able path you
|
|
98
|
+
own; PiG writes to its own temp files with generated names.
|
|
99
|
+
4. **One script shared across harnesses.** A `.mjs` program that Claude Code, Codex and Command
|
|
100
|
+
Code run unchanged has value that an in-session script does not.
|
|
101
|
+
5. **A stable tool catalog as an artifact.** `--list-tools` prints compacted JSON you can commit,
|
|
102
|
+
diff, or use in CI. `codemode`'s discovery lives inside the session.
|
|
103
|
+
|
|
104
|
+
For everything else on PiG — N homogeneous read queries, fan-out with a concurrency cap, filtering
|
|
105
|
+
a payload before it reaches the model — the native tool is faster to start and has no quoting
|
|
106
|
+
layer.
|
|
107
|
+
|
|
108
|
+
## Installing the skill variant
|
|
109
|
+
|
|
110
|
+
`SKILL.md` at the repository root is written for harnesses where this runner is the only code
|
|
111
|
+
mode. Feeding it to PiG would send the model down the wrong path, so the PiG variant ships
|
|
112
|
+
separately:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cp -r skills/pig ~/.agents/skills/mcp-code-mode-pig
|
|
116
|
+
# or: ~/.pig/agent/skills/mcp-code-mode-pig/SKILL.md
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
It says: use native `codemode`; fall back to `mcp-code-mode` only for the five cases
|
|
120
|
+
above. Check it loads with `pig --skill mcp-code-mode-pig -p 'say ok'`, or just look at the
|
|
121
|
+
skill list in a session.
|
|
122
|
+
|
|
123
|
+
## What a genuinely PiG-native variant would be
|
|
124
|
+
|
|
125
|
+
Not implemented, and probably not worth it now that `codemode` exists: a Go extension that
|
|
126
|
+
declares `gh` and `engram` as codemode **namespaces**, so a script calls `tools.gh.pr_status(...)`
|
|
127
|
+
instead of `tools.bash({ command: "gh pr view ... --json ..." })`. That is the only piece of this
|
|
128
|
+
runner PiG lacks, and it is a `durable.Extension` with a `ToolNamespace`, not a Node program.
|
|
129
|
+
|
|
130
|
+
Everything else here — the stdio MCP bridge, parallel fan-out (`Promise.allSettled`), the output
|
|
131
|
+
bounding, the spill — PiG already does in-process. Duplicating it as a Node sidecar would add a
|
|
132
|
+
process, a config file and a quoting layer to buy nothing.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tools": {
|
|
3
|
+
"git.status": {
|
|
4
|
+
"description": "Short git status for a repository directory",
|
|
5
|
+
"cmd": "git",
|
|
6
|
+
"args": ["-C", "{{dir}}", "status", "--short"],
|
|
7
|
+
"params": {
|
|
8
|
+
"dir": { "type": "string", "default": "." }
|
|
9
|
+
},
|
|
10
|
+
"parse": "text"
|
|
11
|
+
},
|
|
12
|
+
"git.recentCommits": {
|
|
13
|
+
"description": "List recent git commit subjects in a repository directory",
|
|
14
|
+
"cmd": "git",
|
|
15
|
+
"args": ["-C", "{{dir}}", "log", "-n", "{{limit}}", "--oneline"],
|
|
16
|
+
"params": {
|
|
17
|
+
"dir": { "type": "string", "default": "." },
|
|
18
|
+
"limit": { "type": "int", "default": 10 }
|
|
19
|
+
},
|
|
20
|
+
"parse": "text"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|