feat: add write tool for creating and overwriting files - #16
Closed
minixalpha wants to merge 6 commits into
Closed
Conversation
A structured {path, content} call writes a whole UTF-8 text file: content
lands on disk as data instead of passing through shell quoting and
heredocs, which could silently corrupt it. Missing parent directories are
created; directories and non-regular files (FIFOs, device files) are
refused as targets; the result states created vs overwrote with byte and
line counts. The terminal echoes the target path with the content folded
to its first lines, matching the tool output shading.
The non-regular-file and cannot-write errors stated only what failed; now the first names bash as the escape hatch for a FIFO or device target, and the second hands the model an ls -ld command pointed at the blocking parent, following read's bash-hint conventions. The line-split logic duplicated between content_preview and run_write moves into a shared _logical_lines helper.
Owner
Author
|
Merged into main as 11bb0b7 — the merge API call was interrupted by a 502 upstream, which updated main but left this PR record open. Closing manually; all commits are contained in main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
writetool — the thin whole-file write chosen as Route A in the accompanying research — plus the research doc and dev notes that motivated it.Research (
docs/research/write_tool.md)writeexists next to bash, what each project implements, and what none of them actually guarantee.writeis worth building now for content/command separation (it removes the class of silently corrupted heredoc writes) and for terminal presentation — not as a control plane. Staleness guards and atomic replace are deliberately out of scope in a single-threaded agent, where they would be pretend safety.The tool (
src/nanopycodeagent/write_tool.py){path, content}input: content lands on disk as data — no shell expansion, heredoc delimiters, or quote escaping.read: absolute or relative to the working directory, leading~expanded.read-style — e.g. a quotedls -ld -- <parent>bash hint when the write fails, or bash as the escape hatch for a FIFO target.Wiring and display (
src/nanopycodeagent/agent.py)TOOLSand the system prompt. The terminal echoes[write] <path>plus the content folded to its first 10 lines (over-long lines cut at 200 chars) on the tool-use shade, with the result on the output shade.Tests
run_writeandcontent_preview(create/overwrite, parent creation, CRLF passthrough, FIFO rejection, symlink target, surrogate error, preview folding) plus an agent-loop dispatch test.Docs
[Unreleased]indocs/changelogs/0.6.x.md.