Skip to main content

Module scratch

Module scratch 

Source
Expand description

The scratch file service (createscratchfile, movescratchfile), moved out of register_editor_handlers unchanged as named functions. Spec: docs/specs/SPEC_EDITOR_WIDGET_DEFAULT_UX_2026_06_14.md. Each takes the user’s home folder as a parameter, so a test can point it at a temp dir.

StructsΒ§

Candidate πŸ”’
A saved-nowhere scratch buffer that could be handed out again.

ConstantsΒ§

OUTSIDE_HOME πŸ”’
The refusal for a destination the Editor may not write: the same limit as its saves.
THIRTY_DAYS_MS πŸ”’

FunctionsΒ§

claim_most_recent πŸ”’
Phase 2: try to atomically claim the most recent candidate. Claim files stop two concurrent calls returning the same backing file to different panes. Each claim file stores the per-process session token; a claim from a previous process (crash/restart) has a different token and is cleared so recovery works.
copy_to_new_file πŸ”’
Writes all of from to a new file at dest. The file is created exclusively, so one that appeared since any earlier check is never replaced; a write that fails part-way leaves nothing behind.
create_scratch_file πŸ”’
Creates a scratch buffer file in ~/.agentmux/cache/scratch/, or hands out the most recent unclaimed one.
mint_scratch πŸ”’
No reusable candidate: a fresh UUID pair, claimed so subsequent calls don’t immediately reuse it.
move_scratch_file πŸ”’
Promotes a scratch buffer to a real user-chosen path (Save As, or a name typed into its tab). The errors are sentences, shown to the person as they are.
save_error πŸ”’
A failed save as a sentence for the person.
scan_candidates πŸ”’
Phase 1: scan the .md.meta files, collecting candidates (not saved, not expired, not in exclude_scratch_ids) and pruning expired pairs.
scratch_dir_of πŸ”’