AGENTS.md
Project Mission
redact is a Rust CLI that lets users manage filesystem trees by editing text buffers in their preferred editor.
Primary UX model:
- Open directory as editable text.
- Edit lines to express filesystem changes.
- Save buffer to commit changes while staying in the same editor session.
- Buffer is refreshed in place after each successful commit.
Product Scope (v1)
In scope:
- Rename/move by editing existing lines.
- Move/delete-from-source by prefixing existing lines with
d(staged to clipboard). - Copy by prefixing existing lines with
c. - Paste from clipboard by adding new lines with
porp <name>. - Create new files/dirs by adding plain new lines.
- Directory creation using trailing
/. - Global clipboard/stash at
/tmp/redact/mv. - Parent navigation hint line
../. - Editor-native navigation only.
Out of scope:
- Editor-specific plugins/keymaps in core.
- Multi-clipboard history.
- Live apply-on-each-save daemon mode.
Core Semantics (Must Preserve)
- Prefix
don existing entry lines moves them to clipboard and removes from source on commit. - Prefix
con existing entry lines means copy to stash. - Prefix
pon a new line pastes the next clipboard item with its original name. - Prefix
p <name>on a new line pastes the next clipboard item and renames it to<name>. - Plain new lines (no prefix) create new files/dirs.
- New copy/cut batch replaces previous stash batch.
- Removing an existing line without
dis a validation error. - Rename is valid when the edited entry keeps its original
# idand stays on its original line position. - Paste collisions on equal names are resolved by adding
_cpybefore the extension (or at end when no extension). - Navigation into a folder is triggered by saving with an empty line immediately below an existing directory entry line.
- Navigation to parent is triggered by saving with an empty line immediately below
../. - If a new line starts with
cd <path>and<path>resolves to an existing directory, all other edits are ignored for that save and redact navigates to that directory. - Rendered listing keeps directories above regular files and aligns columns as: name | icon | size | modified | id.
Buffer Contract
Expected format:
- Comment lines start with
#. ../exists for navigation and is ignored by apply.- Existing entries include metadata token
# id:<stable_id>. canddprefixes apply only to known existing entries.- Trailing
/indicates directory for new entries. pandp <name>apply only to new lines.- Existing lines must not be removed silently; deletion must use
d. - Each redact process owns one stable buffer file at
/tmp/redact/buffer-<instance-id>.redactfor its entire lifetime. - Different redact instances must never share the same buffer file.
- Apply summaries/warnings/errors are written to
/tmp/redact/buffer-<instance-id>.logand must not be injected into the editable buffer UI. cd <path>is a navigation command (new line, no# id) and has precedence over normal apply operations when valid.
Never break backward compatibility of this format without explicit migration logic.
Architecture Guidelines
Use these modules:
cli.rsfor argument parsing and command dispatch.editor.rsfor editor process launch and environment handling.snapshot.rsfor reading directory state and stable ids.buffer.rsfor rendering/parsing textual buffers.diff.rsfor converting edits into planned operations.clipboard.rsfor stash manifest/payload lifecycle.apply.rsfor filesystem mutation ordering and safety.
Safety and Correctness Rules
- Source-removal behavior must be explicit (
dprefix). - Use deterministic operation ordering.
- Emit actionable diagnostics with path + reason.
- Preserve atomic intent where possible (especially rename ordering).
- Handle cross-device copy/move fallback for clipboard payload operations.
- Do not silently ignore malformed lines or omitted existing entries.
Testing Requirements
Before merge, cover:
- Parser correctness and error paths.
- Rename/copy/cut/paste/create scenarios.
- Stash replacement behavior.
- Ambiguous name matching.
- Hidden file behavior toggles.
- Integration tests over real temp directories.
CLI UX Rules
- Respect editor precedence:
--editor>REDACT_EDITOR>EDITOR>vi. - Launch editor with cwd set to target directory.
- Support
redact logs <buffer-id>andredact logs --follow <buffer-id>for instance log inspection. - Exit non-zero for fatal parse/apply failures.
- Do not print apply summaries directly into interactive editor sessions; write them to per-instance log files.
Change Policy
When extending features:
- Keep default behavior stable.
- Prefer additive flags/subcommands over semantic breaks.
- Document new behavior in README and examples.
- Add tests for both happy path and failure path.