Repository navigation
feat(tools): edit_file + delete_file — full CRUD file capability (E12) - #32
Merged
Merged
Conversation
read_file now returns a 16-hex content hash; edit_file requires quoting it (hashline anchoring): stale anchors are refused before any mutation, with a re-read recovery instruction. old_text->new_text exact-match replacement (1 match required; 0/2+ are actionable errors). Atomic temp+rename write. delete_file is Destructive risk: interactive approver only, prompts every call, --yes/allowlists never apply. Live smoke (Bifrost/GLM): read->edit(hash quoted)->create->delete all verified via durable log + on-disk state. Loop guard correctly tripped on degenerate empty write_file calls. Closes #24, closes #31
| Ok(()) | ||
| } | ||
|
|
||
| /// Edit a file under a fixed root directory. Input: |
| .get("path") | ||
| .and_then(Value::as_str) | ||
| .unwrap_or("<missing path>"); | ||
| format!("delete file {path}") |
| }; | ||
| let target = jailed(&self.root, path, "delete_file")?; | ||
| let meta = std::fs::symlink_metadata(&target) | ||
| .map_err(|e| format!("delete_file: stat {}: {e}", target.display()))?; |
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
…ection FP CodeCora review on PR #32 caught a real bug: atomic_write's create_new refuses to overwrite a stale .tole-edit-{pid}.tmp left by a crashed attempt, bricking edit_file for the session. Now: on AlreadyExists the stale temp is removed once and the open retried; write/rename failures also clean the temp. Regression test included. Also adds 'SQL injection via string concatenation' to .cora.yaml ignore rules — the scanner flags format! error strings in file_tools.rs which contains no SQL (pure fs + json! tool). Same FP was dismissed locally (findings #1211-1213).
ajianaz
added a commit
that referenced
this pull request
Sep 22, 2026
… scrub, cora_search flag guard, uteke spec truth (#128) - tole mcp: --plan-mode now filters the SERVED registry to read-only tools and --on-pretool/--on-posttool error out loudly instead of being silently ignored (scan-3 #9 — global args parsed but unhandled by the mcp subcommand). - chat REPL: dropped_message is scoped per message; previously one drop warned on every later message forever (scan-3 #8). - hooks: hook subprocesses scrub secret-shaped env like every other child spawn (scan-3 #23). - cora_search: leading-dash query guard, mirroring uteke_recall (scan-3 #32). - uteke_document spec no longer advertises title/tags that execute() silently drops (scan-3 #33) — the spec now matches reality. Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Sep 22, 2026
… guard, uteke spec truth, mcp plan-mode, chat flag scope - hooks: hook subprocesses scrub secret-shaped env like every other child spawn (scan-3 #23). - cora_search: leading-dash query guard, mirroring uteke_recall (scan-3 #32). - uteke_document spec no longer advertises title/tags that execute() silently drops (scan-3 #33). - tole mcp honors --plan-mode (read-only served registry) and loudly rejects --on-pretool/--on-posttool (scan-3 #9). - chat REPL dropped_message scoped per message (scan-3 #8).
ajianaz
added a commit
that referenced
this pull request
Sep 22, 2026
… guard, uteke spec truth, mcp plan-mode, chat flag scope (#129) - hooks: hook subprocesses scrub secret-shaped env like every other child spawn (scan-3 #23). - cora_search: leading-dash query guard, mirroring uteke_recall (scan-3 #32). - uteke_document spec no longer advertises title/tags that execute() silently drops (scan-3 #33). - tole mcp honors --plan-mode (read-only served registry) and loudly rejects --on-pretool/--on-posttool (scan-3 #9). - chat REPL dropped_message scoped per message (scan-3 #8). Co-authored-by: ajianaz <[email protected]>
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.
What
Adds
edit_fileanddelete_filehost tools, completing the agent's file CRUD capability:read_file(read, now with content hash),write_file(create/overwrite),edit_file(update),delete_file(delete).edit_file (Write risk) — hashline anchored
read_fileoutput now includeshash: a 16-hex content hash (DefaultHasher, zero new deps; hash lifetime is a single session so std-hasher instability across versions is irrelevant).edit_file(path, old_hash, old_text, new_text): the live file's hash must equal the quotedold_hashbefore any mutation — stale context is refused with an error that instructs a re-read (loop-guard-compatible recovery path).old_text→new_textexact-match replacement: must match exactly once (0 or 2+ matches are actionable errors). Content anchors instead of line ranges — line numbers rot, exact text is the same evidence as the hash anchor.new_hashso the model can chain edits without re-reading.O_NOFOLLOWon unix); refuses directories; 1 MiB cap (matchesread_file).delete_file (Destructive risk)
AllowlistApproverdenies on sight; the interactive gate prompts on every call —--yesand--allownever apply (PRD risk table).Why
The agent could create and read files but not update or delete them (#31). E12's
edit_filewas parked until the E7 tool era matured (#24); E4.5 tool-calling is now live-proven, so the era starts here. Hash anchoring kills the classic LLM-edit failure mode: patching from stale context and silently corrupting code.Testing
file_tools.rs: hash stability/sensitivity, happy-path edit with hash chaining, stale-anchor refusal (file unchanged after), ambiguous/missingold_text, jail escapes, empty-new_textdeletion, directory/missing-file errors, delete happy path, directory refusal, missing-file error.read_file→edit_file(correctly quoted hash85512ca65be8eb7afrom the read) →write_file→delete_file, all verified in the durable log and on-disk state.delete_fileprompted for approval even with--yes(structural Destructive enforcement), loop guard tripped correctly on degenerate emptywrite_filecalls.format!error strings in a file with no SQL) — dismissed with documented reasons.Closes #24
Closes #31