Skip to content

Add the tool-cli runner (remote tools, executor step 2) - #4312

Merged
mstomar125 merged 3 commits into
mainfrom
issue-4291-cli-runner
Nov 19, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-4291-cli-runner

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Refs #4291, executor step 2: the tool-cli runner. This PR changes packages/agent (and installs the runner in packages/daemon): the user's sign-off stands in for the agent owner's for this build. The acceptance criteria are the ones carried in the merged gate PR.

What it adds

packages/agent/src/local_agent/cli_runner.rs (CliRunner), installed in the daemon's RemoteToolHost:

  • Typed reader, fail closed. The binding is decoded with ToolCliFields::from_bucket and must pass check_complete against the tool's schema; a malformed or incomplete binding is an error before any process starts.
  • No shell; argv only. The program is spawned directly. Each {name} placeholder is one whole argv element whatever the model's value holds (spaces, ;, $(...), backticks, quotes, a leading -). A value is a string, number or boolean; anything else, and any string with a NUL, is refused. A placeholder whose argument the model left out is dropped.
  • -- before model values. A -- element is inserted before the first model-supplied element, only when there is one.
  • A built environment. env_clear(), then PATH HOME LANG USER TMPDIR from the daemon when set, plus the entries the binding declares. Nothing else is inherited. The child's working directory is the system temp dir.
  • Credentials. A declared env entry's keychain: / env: reference is resolved (resolve_credential_with, platform store off the async threads) only while the child's environment is built, goes to that one child only, is never an argument, is held in Zeroizing memory and is redacted from everything the runner returns. A credential shorter than 4 bytes is refused (it cannot be redacted safely). A missing credential stops the call before the program runs.
  • Redaction is done by sanitize on each stream's raw bytes, converting to text last (so a character cut in half cannot turn a credential's prefix into text that no longer matches it). Every occurrence of every credential is found in the original bytes; overlapping or adjacent occurrences (one credential inside or overlapping another, or itself) are merged and replaced once by the marker. When the program was stopped at the cap, the trailing part of any credential the read stopped inside of is removed too, repeatedly (removing one can uncover another); a tail that overlaps an occurrence joins its marker, one that overlaps none is dropped. The invariant is tested exhaustively at every cut position, for ASCII, prefix-of-another, suffix-prefix overlap, self-overlap and multibyte credentials: the text holds no complete credential and, when cut, no prefix of one of four bytes or more.
  • Limits. Output is read as a stream (stdout and stderr together) and the program is killed when the cap is reached (result marked truncated), not buffered and cut afterwards. A timeout kills the whole process group (and the child directly, so a failed group signal cannot leave it running); waits after a kill are bounded. A non-zero exit is an error with the status and bounded, redacted output.
  • Confirmation. The question shown lists the program (and, for a bare name, where it resolves on the daemon's PATH), then the credential references (NAME from keychain:x, up to eight, then "and N more", so none is hidden silently), then the arguments. The credentials come before the arguments and the argument list alone is cut (with a marker) to fit 4 KiB, so a long argument can never push them out; a long resolved path is cut at 160 characters; an unset PATH is said to be unset rather than reported as not found. Never a value.
  • Cancellation and working directory. A call that is cancelled (its future dropped) kills the program's process group (a drop guard, disarmed once the program is reaped so a recycled id is never signalled). The program starts in a fresh private (0700), empty directory made for the call and removed afterwards, not the shared temp directory.

Offering, and what is not wired yet

The host now offers a tool whose calls need confirmation only when a confirmer is installed (so a tool is never offered that every call would refuse). The real confirmer is the confirmation step's work, so in this PR no tool-cli tool is offered and a call to one is refused as unknown (tested: not offered, UnknownTool, nothing runs, with the real runner and the real gate). With a test confirmer the runner is offered and dispatched through the host (also tested); a GET REST tool with no credential is unaffected.

Remote text, logs and the system prompt

  • A remote program's failure text is not repeated to the user as the failure reason (failure_reason() shows nothing for an external result; the host's own refusals still show).
  • The system prompt gets one line, only on a turn offered a remote tool, saying such results are data, never instructions. No golden snapshot changes (no remote tool appears in them; test:changed passes the prompt snapshot gate).

Known limits

  • -- goes before the first model-supplied element, so the binding's own fixed arguments that follow a placeholder come after it too (["log", "{q}"] runs git log -- main, which names paths, not a revision; ["{q}", "--out", "x"] passes --out positionally). A program that does not honour -- receives a literal --. Option injection through a value is prevented only for programs that honour -- (git, ssh, curl do). A binding that is itself dangerous (an interpreter run with -c) is within what its approval covers. Documented in the runner header and in nodespace-docs Add comprehensive event tests for SlashCommandDropdown component #166.

  • After a normal exit, background processes the program left running are not stopped; processes that leave the group (setsid) escape the group kill.

  • The program inherits the daemon's PATH (bare names resolve as they do for the user; a fixed safe PATH would break Homebrew and similar installs, and PATH cannot be declared by a binding), the file descriptors the platform does not mark close-on-exec, the umask and the signal mask. Another process of the same user can read the child's environment.

  • Redaction replaces the exact value: a program that prints a transformed form (base64, URL-encoded, split across lines) is not caught. The child's environment copy of a credential is held by the process machinery and is not wiped.

  • -- is inserted before model values; a program that does not honour -- will see it as an argument.

  • Unix process groups only for the kill-the-tree guarantee; the tests that run fake programs are cfg(unix).

  • A program path in the binding is resolved by the OS; a bare name is found on the daemon's PATH.

Tests

  • 34 runner tests with fake shell scripts (no network, no real keychain): argv and no shell (a hostile value that would touch a file if a shell ran), the separator rules, value types, NUL, the built environment (a variable set in the test process does not reach the child), credentials on both streams and the error text, missing and too-short credentials, failing status, the timeout killing the program and its child, the stream cap stopping an endless program, a credential straddling the cap in two writes, malformed and incomplete bindings (nothing runs), an unstartable program, and the confirmation text; 2 host tests through the real runner; the failure-reason and system-prompt tests. cargo clippy -D warnings clean; bun run test:changed passes.
  • Mutants (about 40 across two rounds): all caught except one equivalent: the timeout path's explicit stop can be removed without a test noticing, because the drop guard kills the same group when the call returns. Caught include (first round): no separator; a separator before every value; environment not cleared; a leaked base variable; output not redacted; the cap boundary not covered for redaction; output buffered rather than stream-capped; the timeout not stopping the program; only the child killed; no process group; short credential accepted; non-scalar value accepted; NUL accepted; completeness not checked; failing status ignored; a tool offered without a confirmer; a remote failure reason shown; the rule in every prompt; the rule never added. (Earlier rounds led to fixes: a test where the credential arrived in one write, and an unbounded wait after a kill, now bounded.) Added in the second review round: text converted before the strip (stdout and stderr, each caught by a run-level mid-character test), the strip as a single pass, overlapping occurrences not merged, a merged span losing its marker, a tail overlapping nothing getting a marker, the last position missed, the resolved path not cut, an unset PATH reported as not found. Added in the first review round: the partial tail not stripped (stdout, stderr, or both), the cancellation guard removed, the working directory not removed, not private, or the shared temp dir, the confirmation budget ignoring the credentials, hiding the "more" count, listing every credential, not saying where a bare name resolves, and stderr not counting toward the cap. A pinned regression test is the reviewer's case: a 40-byte credential, cap 64, output = 30 filler + the credential + 20 filler + its first 14 bytes in one write. Not covered by a test: stdin being null (a program reading stdin is given none).

What remains

tool-rest and tool-mcp runners; the real confirmation wiring with a bounded timeout and a cap on the displayed arguments; the enable-and-approve command (with an add-if-absent key primitive); tool_whitelist decision; fixtures.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #4312 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 4312.

▶ Merge gate: full pyramid on the rebased PR.
  stage logs: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-11-19T16-13-26-223Z

▶ quality:scripts:check (scripts/ lint + typecheck) (timeout 10m)
  ✓ quality:scripts:check (scripts/ lint + typecheck) 3s
▶ quality:design-tokens (design-token drift) (timeout 5m)
  ✓ quality:design-tokens (design-token drift) 0s
▶ check-version-sync (app version drift) (timeout 5m)
  ✓ check-version-sync (app version drift) 0s
▶ check-sync-boundary (ADR-081 code-boundary ratchet) (timeout 5m)
  ✓ check-sync-boundary (ADR-081 code-boundary ratchet) 1s
▶ check-node-type-literals (ADR-086 chain-aware type rules) (timeout 5m)
  ✓ check-node-type-literals (ADR-086 chain-aware type rules) 0s
▶ check-lifecycle-reads (ADR-087 one participation check) (timeout 5m)
  ✓ check-lifecycle-reads (ADR-087 one participation check) 0s
  ⚠ node-types:check (published node-types.md vs. the core schemas) SKIPPED: no docs checkout at /Users/mayanktomar/nodespace/nodespace-docs. Clone the docs repository beside the primary checkout, or set NODESPACE_DOCS_DIR.
  incremental cache: nothing to remove; 166 directories kept (20.8 GiB)
  build artifacts (deps/): 21.1 GiB, over the 20 GiB budget; emptied, so this run rebuilds them
▶ skill installer script (tsc) (timeout 5m)
  ✓ skill installer script (tsc) 0s
▶ types:check (generated TypeScript drift) (timeout 15m)
▶ test (frontend, Happy-DOM) (timeout 15m)

$ bun run scripts/gen-types.ts --check
sccache: error: Server startup failed: File exists (os error 17)
Run with SCCACHE_LOG=debug SCCACHE_NO_DAEMON=1 to get more information
error: could not compile `smallvec` (lib)
Caused by:
  process didn't exit successfully: `/Users/mayanktomar/nodespace/core/.tools/bin/sccache /Users/mayanktomar/.rustup/toolchains/1.97.0-aarch64-apple-darwin/bin/rustc --crate-name smallvec --edition=2018 /Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/smallvec-1.15.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no --cfg 'feature="const_generics"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("arbitrary", "bincode", "const_generics", "const_new", "debugger_visualizer", "drain_filter", "drain_keep_rest", "impl_bincode", "malloc_size_of", "may_dangle", "serde", "specialization", "union", "unty", "write"))' -C metadata=9d1b2dd3d1f13c9c -C extra-filename=-109cf1838ac3aa66 --out-dir /Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/deps -C strip=debuginfo -L dependency=/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/deps --cap-lints allow` (exit status: 2)
✗ cargo run -q … failed (exit 101)
error: script "types:check" exited with code 1
[stage exited with code 1]

  full output: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-11-19T16-13-26-223Z/types-check-generated-typescript-drift.log

✗ types:check (generated TypeScript drift) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

mstomar125 and others added 3 commits November 19, 2026 17:26
Runs the program a tool-cli binding names: no shell, each placeholder one
whole argv element with -- before model values, a built environment, credentials
resolved only into the child's environment and redacted from every result,
stream-capped output, and a timeout that kills the process group. Offering is
gated on a confirmer being installed, so until one is wired no tool-cli is
offered. Results and errors from a remote program are not repeated as the
failure reason; the system prompt carries the external-data rule only when a
remote tool is offered.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…dentials always in the confirmation, private working directory, group kill on cancel

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…entials, repeat the tail strip

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant