Skip to content

feat(tools): edit_file + delete_file — full CRUD file capability (E12) - #32

Merged
ajianaz merged 2 commits into
developfrom
feat/e12-edit-delete-tools
Aug 27, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/e12-edit-delete-tools

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What

Adds edit_file and delete_file host 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_file output now includes hash: 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 quoted old_hash before any mutation — stale context is refused with an error that instructs a re-read (loop-guard-compatible recovery path).
  • old_text → new_text exact-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.
  • Returns new_hash so the model can chain edits without re-reading.
  • Atomic write (temp file + rename, O_NOFOLLOW on unix); refuses directories; 1 MiB cap (matches read_file).

delete_file (Destructive risk)

  • Registry structurally requires an interactive approver; AllowlistApprover denies on sight; the interactive gate prompts on every call — --yes and --allow never apply (PRD risk table).
  • Files only (directory deletion refused with a clear error; recursive delete is out of scope), same path jail as the other file tools.

Why

The agent could create and read files but not update or delete them (#31). E12's edit_file was 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

  • 10 new unit tests in file_tools.rs: hash stability/sensitivity, happy-path edit with hash chaining, stale-anchor refusal (file unchanged after), ambiguous/missing old_text, jail escapes, empty-new_text deletion, directory/missing-file errors, delete happy path, directory refusal, missing-file error.
  • 110/110 tests pass, clippy clean, release build OK.
  • Live smoke test (Bifrost/GLM): model performed read_file → edit_file (correctly quoted hash 85512ca65be8eb7a from the read) → write_file → delete_file, all verified in the durable log and on-disk state.
  • Approval gate verified live: delete_file prompted for approval even with --yes (structural Destructive enforcement), loop guard tripped correctly on degenerate empty write_file calls.
  • 3 cora findings on this diff were false positives (SQL-injection heuristics matching format! error strings in a file with no SQL) — dismissed with documented reasons.

Closes #24
Closes #31

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()))?;
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🔍 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
ajianaz merged commit 9af10aa into develop Aug 27, 2026
11 checks passed
@ajianaz
ajianaz deleted the feat/e12-edit-delete-tools branch August 27, 2026 04:56
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]>
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.

feat: delete_file tool (Destructive risk) — complete CRUD file capability E12: Content-hash anchored edits (hashline concept) for edit_file tool

2 participants