Skip to main content

Module work

Module work 

Source
Expand description

~/.mecha/work/<producer>/ — where a run’s generated output goes.

Two directories, and they mean opposite things:

~/.mecha/work/<producer>/     generated · mutable · disposable · cleanable
~/.mecha/bundles/<id>/<ver>/  published · immutable · versioned · never deleted

A producer is whatever made the output: a trigger’s name, or chat, or a session id. The directory is stable across runs of the same producer, which is the whole point — yesterday’s briefing is an ordinary file in today’s run rather than something that has to be fetched back from somewhere. It is also the run’s workspace, and that fixes three things at once:

  • The jail default. A trigger with no explicit workspace fell through to std::env::current_dir(), and the daemon’s unit sets WorkingDirectory=%h. So an unattended run with filesystem tools was path-jailed to $HOME, which contains ~/.mecha/ — the mail OAuth tokens, every session transcript, the learning store. Rooting it here roots it somewhere holding nothing sensitive. (The interactive half of that hazard is ensure_outside_mecha_home.)
  • Cross-run read-back, as above.
  • notify. The shipped morning trigger ended with mkdir -p ~/.mecha/briefings && cat > … — a shell redirect into a directory it created on the way past, outside every path jail, so no later run could read it. That existed only because there was no designated place to write.

Retention is a policy, not an intention. Anything without one becomes a pile nobody opens, so clean keeps the last N entries per producer and says what it removed. One hard rule: it never removes anything a published bundle names as a source, because “regenerate last week’s report” must not silently lose its input.

Structs§

CleanReport
What a clean did, or would do.
Entry
One top-level entry in a producer’s directory. A run’s output may be a file or a directory (a rendered bundle is a directory), so retention counts entries rather than files.
Producer
One producer’s directory, as list reports it.

Constants§

DEFAULT_KEEP
How many entries per producer survive a clean that does not say.

Functions§

bundles_root
~/.mecha/bundles — the published mirror. Written by the publisher, read here only to find out what clean must not remove.
clean
Keep the keep most recent entries in each producer’s directory and remove the rest.
ensure
The directory for one producer, created if absent.
ensure_outside_mecha_home
Refuse a workspace that contains the mecha home.
list
Every producer with a directory, alphabetically.
mecha_home
~/.mecha, or $MECHA_HOME.
producer_dir
The directory for one producer, without creating it.
protected_sources
Paths a published bundle names as its source, which clean must never remove.
root
~/.mecha/work.
valid_producer
A producer name is a directory name, a CLI argument and a log line. Keep it to what is unambiguous in all three — the same rule trigger names follow, because a trigger name is a producer name.