Repository navigation
web_fetch: opt-in default + save_to arg; allow curl in shell denylist - #144
Conversation
Three related changes that restore parity with picoclaw's shell+curl posture while keeping web_fetch as a managed alternative for operators who want it. 1. Drop 'curl ' and 'wget ' from the dangerous-shell denylist (Tools.Sandbox.ForbiddenSubstrings, array size 0..43). They were the model's conventional way to fetch arbitrary URLs and denying them put PasClaw strictly behind picoclaw on URL access. The full denylist remains toggleable via sandbox.shell_deny_enabled=false. 2. web_fetch is now off by default. New Cfg.WebFetchEnabled flag (off-by-default, serialised only when True) gates registration in all six callsites: Cmd.Agent (via NewBuiltinRegistry's new EnableWebFetch parameter), Cmd.TUI, Cmd.Gateway, Cmd.Serve, and the two PasClaw.Agent.pas InstallTools paths. Picoclaw doesn't ship a web_fetch — its model uses shell+curl — and the default posture now mirrors that. 3. web_fetch grows an optional `save_to` argument. When set, the full response body is written to that path under the workspace (gated by Sandbox.CanWritePath) and the tool returns a short receipt + 200-char preview rather than the inlined content. Skips the max_chars cap entirely so the model can pull arbitrary page sizes / JSON dumps without blowing the context window, and skips the text/* content-type check so binary downloads work. The schema + description on the registered tool both call out the new save_to convention so the model knows when to use it. https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ab99495ae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| a short receipt with a preview. } | ||
| if SaveTo <> '' then | ||
| begin | ||
| if not WriteBodyToFile(SaveTo, Resp.Body, ErrMsg) then Exit; |
There was a problem hiding this comment.
Serialize save_to fetches before dependent reads
When save_to is used, this branch mutates the workspace, but RegisterWebFetchTool still marks web_fetch as tcReadOnly. I checked PasClaw.Tools.ToolLoop.pas: consecutive read-only calls are batched and run in parallel, so a model turn that calls web_fetch {save_to:"page.html"} followed by fs_read/fs_grep of that file can race and have the read run before the download finishes. This write mode needs to be treated as mutating (or otherwise excluded from read-only batching) to preserve tool-call ordering for saved files.
Useful? React with 👍 / 👎.
| Bytes := TEncoding.UTF8.GetBytes(Body); | ||
| if Length(Bytes) > 0 then | ||
| FS.WriteBuffer(Bytes[0], Length(Bytes)); |
There was a problem hiding this comment.
Preserve raw bytes for saved downloads
For save_to, binary responses are first decoded into Resp.Body via TStringStream(..., TEncoding.UTF8) in the HTTP wrapper and then re-encoded here with TEncoding.UTF8.GetBytes, so non-text payloads such as PDFs, images, or zip files will not be saved byte-for-byte and may be corrupted. This matters because the new schema explicitly advertises save_to for binary downloads; it should use the existing stream-based HTTP path (or another byte-preserving path) instead of round-tripping through a string.
Useful? React with 👍 / 👎.
Two Codex P2 findings on the web_fetch save_to path: 1. Category mismatch. The tool was registered as tcReadOnly so the gateway scheduler would parallelise follow-up tool calls, but save_to writes to the workspace — a concurrent fs_read could observe a half-written file. Flip to tcMutating; the tool-level tag is the only signal the registry exposes (the inlined-text path doesn't mutate, but we can't tag per-call). 2. Binary content corruption. The save_to branch was fetching via GetURL (which returns a UTF-8 string body) then re-encoding to UTF-8 bytes via TEncoding.UTF8.GetBytes. For text the round trip is lossless, but for PDFs / images / archives the decode step replaces invalid byte sequences with U+FFFD and the file on disk ends up structurally broken — exactly the use case save_to was added to support. Fix: add GetURLToStreamGuarded to the HTTP wrapper (both Indy and NetHTTP backends) — same SSRF redirect guard + UA/Accept overrides as GetURL, but writes raw response bytes into a caller stream instead of decoding through TStringStream. WebFetch's save_to branch now opens a TFileStream and streams bytes directly to disk; the receipt preview is reconstructed by reading the first 200 bytes back and only decoding when the Content-Type looks textual. The non-save_to path is unchanged.
Summary
Three related changes that restore parity with picoclaw's shell+curl posture while keeping
web_fetchas a managed alternative for operators who want it.1. Allow
curl/wgetin the shell denylistPicoclaw's model fetches arbitrary URLs by shelling out to
curl. Our denylist blocked bothcurlandwget, which put PasClaw strictly behind picoclaw on URL access. Removed both entries fromTools.Sandbox.ForbiddenSubstrings(array size updated0..45→0..43). The rest of the denylist (sudo,rm -rf,dd, command-substitution,curl | sh-style pipes, package-manager installs,git push, etc.) is untouched. Operators who want the old posture can still flip the whole list off viasandbox.shell_deny_enabled = false.2.
web_fetchoff by defaultNew
Cfg.WebFetchEnabled: Boolean(default False, JSON-serialised only when True). Gates registration in all six callsites:Cmd.Agent(viaNewBuiltinRegistry's newEnableWebFetchparameter, same shape asEnableVault/EnableWebSearch)Cmd.TUI,Cmd.Gateway,Cmd.Serve(inlineif Cfg.WebFetchEnabled then …)PasClaw.Agent.pasInstallToolspaths (also inline)Picoclaw doesn't ship a
web_fetch— the model uses shell+curl — and the default posture now mirrors that. Operators on containerised / sandboxed deploys without curl can flip"web_fetch_enabled": trueinconfig.json.3.
web_fetchgrowssave_toOptional argument; when set, the full response body is written to that workspace-relative path (gated by
Sandbox.CanWritePath) and the tool returns a short receipt + 200-char preview instead of the inlined content:Skips the
max_charscap entirely so the model can pull arbitrary page sizes / JSON dumps / API dumps without blowing the context window, and skips thetext/*content-type check so binary downloads work (image, PDF, etc.). The schema + description on the registered tool both call out the new convention so the model knows when to use it.Test plan
make clean && makeclean,make smokegreen.pasclaw agentwith default config (noweb_fetch_enabled): tool absent from the registry, model uses shell+curl.pasclaw agentwith"web_fetch_enabled": true: tool registered.web_fetch {url: "..."}returns inline text (existing behaviour).web_fetch {url: "...", save_to: "workspace/test.html"}writes the file, returns the receipt + preview, file readable viafs_read.web_fetch {url: ".../bigfile.json", save_to: "workspace/dump.json"}works for content types that used to error.shell_execwithcurl https://example.comno longer hits the denylist (returns curl's output).https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code