Turning Agent History into Repeatable Workflows
I want repeated work in my AI coding sessions to become something I can run again, not something an agent has to rediscover. The raw material is already accumulating on my machines: Atuin’s shell history and the conversation database and raw mirror maintained by cass. They contain more than transcripts and commands. They contain sequences of work, variations between attempts, and failed steps that can help explain how a successful workflow came about.
There is an important limit to what I have preserved so far. These stores are not the same as every agent’s own session directory, and those directories are not included in this backup. The cass raw mirror is included, but its scheduled jobs currently have raw mirroring disabled. I want to keep that distinction visible rather than describe the backup as more complete than it is.
The project I have in mind is a pipeline: collect that history, identify recurring workflows, group the variations, and turn the stable parts into deterministic programs. An agent would still be useful for unusual inputs, failed assumptions, and decisions that cannot yet be reduced to a reliable procedure. I am not trying to make an agent remember everything. I want to reduce how much repeated work needs an agent in the first place.
I am thinking about personal projects and prototype-to-alpha development, not enterprise process governance or another dashboard. The value would be practical: a workflow that I have already worked through should eventually run as code, with the agent brought in where execution departs from what the code can safely handle.
I have not built the miner or compiler yet. Today I built part of the prerequisite: a recovery path for the history stores I can currently collect.
Finding the structure in the history
The field closest to what I am describing is process mining. It starts with event data and tries to reconstruct how a process actually runs. Process discovery derives a model from observed events. Conformance checking compares recorded behavior with a model and identifies where real executions differ. Those are two separate jobs I need: discover the recurring path, then examine the deviations rather than treating every run as identical. Wil van der Aalst’s overview of process mining explains the relationship between event data, discovered models, and the other forms of process analysis.
There is a useful connection to sequence compression as well. The SEQUITUR algorithm finds repeated phrases in a sequence and replaces them with grammar rules, recursively building a hierarchy. I like this as a model for reusable sub-workflows: a repeated sequence can become one named unit, and larger workflows can be expressed in terms of those units.
But shell history and agent transcripts are not ready-made process logs, and repeated text does not necessarily mean repeated work. The same command can mean different things in different repositories or states. A useful representation will have to preserve context: which task was underway, what tool or command ran, what it acted on, what result it produced, and which choices were made by the user or the agent. Sequence structure is a starting point, not proof that two executions are interchangeable.
Minimum Description Length gives me a way to think about deciding which patterns are worth keeping. The model itself has a cost, and so does the history that remains unexplained by it. The useful model is not simply the one with the fewest steps; it is the one that describes the recurring behavior compactly without hiding meaningful exceptions. In pattern mining, compression is a way to compare candidate models, not an end in itself. Esther Galbrun’s survey of MDL for pattern mining develops that distinction.
I use compression here as a way to reason about the problem, not as a claim that an AI model literally compresses a workflow. An agent may help interpret messy histories and propose patterns. The patterns still need to be checked against actual executions. Otherwise, a convenient summary could turn an accidental sequence into an automation rule.
Today: making the history recoverable
Before mining anything, I need to know that the source data will still be there. I built an encrypted backup using Restic and Backblaze B2. It stores Atuin’s history database, cass’s conversation database, and cass’s raw mirror in a per-host B2 bucket. Home Manager installs the scripts and schedules the backup through launchd at 01:30.
Before choosing the storage provider or the secret manager, I had to decide what I wanted the security model to guarantee. This is a private archive of my working history: shell commands, agent conversations, project context, and the sequence of decisions that led to an implementation. Losing it would defeat the purpose of the project, but putting it in the cloud also creates another place where that history and the credentials protecting it can be exposed. I did not want to solve the first problem by casually creating the second.
I was trying to establish four boundaries. The contents should be encrypted before leaving the machine. The credential used by an unattended backup should have only the authority needed to write that machine’s archive, not the authority to destroy the archive. Secrets should be available to the process that needs them without becoming part of the repository, configuration, shell history, or logs. And the operations that create or change privileged cloud credentials should remain under my control rather than being delegated to the agent or folded into the nightly job.
Those requirements led to a distinction between the data plane and the authority used to operate it. Restic encrypts the repository on the machine before it is sent to Backblaze B2. The bucket is private as a second access-control layer, and each machine gets its own bucket so that the recurring credential can be limited to that machine’s backup. B2 is storage for an encrypted repository, not the place where I want plaintext history to live.
The more important decision was to assume that the routine backup process itself could fail, be misconfigured, or be compromised. The nightly job needs to create snapshots and read the repository to verify or restore them. It does not need permission to permanently delete stored file versions. So I separated provisioning from operation. I used an administrative B2 key once, as the account owner, to create the bucket and a bucket-scoped application key. The key installed for nightly use can list, read, and write, but it does not have deleteFiles. I also configured the bucket to retain all file versions and deliberately left pruning out of the automated job. That gives an ordinary writer a narrower ability to damage the archive: it can write, and the design does not pretend it cannot alter or hide current files, but it does not have the permission to permanently erase the older versions on which recovery may depend.
This is not an immutable backup system, and it is not protection against every form of compromise. Someone with the administrative B2 credentials or control of the account can still change the storage configuration or delete data. The restricted key can still write to its bucket, and version retention is not the same thing as a separate offline copy or a WORM guarantee. The point was more specific: the credential used every night should not also be the credential that can erase the recovery history. I accepted the cost and operational burden of keeping old versions rather than giving the unattended process cleanup authority. Nothing runs Restic’s forget or prune; cleanup is a separate, deliberate administrative decision.
The same separation applies to secrets. The B2 application key and Restic repository password live in a dedicated 1Password vault. The recurring process authenticates to that vault with a separate service-account token stored in the macOS Keychain, with a permission-restricted file as a fallback. The service account is granted access to the backup vault, not my general 1Password account. At runtime, op run resolves references such as op://backup-ops/... and supplies the values to the process that needs them. The temporary environment file contains references, not secret values; the token is removed before Restic is started. The credentials necessarily exist in the runtime environment of the command that uses them, but they are not written into the checked-in configuration, command arguments, or logs.
I kept the initial setup separate from that recurring path. The provisioning script uses my human 1Password session and the administrative B2 key; it does not use the runtime service account. It creates the restricted key and stores the resulting credentials without printing their values. The B2 CLI temporarily caches the administrative key locally, so clearing that cache after setup was part of the procedure, not an optional cleanup. I also ran the B2 CLI ephemerally through the pinned Nix input rather than installing an administrative tool as part of the everyday system configuration. The provisioning script was removed from the working tree after it had served its purpose; its implementation remains in Git history.
There are limits to the local secret boundary too. The Keychain keeps the service token out of an ordinary plaintext configuration file, but it should not be mistaken for isolation from every process running as my macOS user. The handoff explicitly records that another program running as that user may be able to read the token. A compromise of the logged-in account, or of the 1Password account and vault, is outside what this arrangement can fully contain. I wanted to reduce exposure and constrain the routine cloud credential, not claim that a single-user machine can protect its secrets from an attacker who already controls that user.
There is also a recovery gap I do not want to disguise as a design feature. An offline recovery copy of the Restic password was part of the plan, but the current setup keeps the password in 1Password only; that offline copy has not been made. Losing access to the item would make the encrypted backups unreadable. The operational path is centralized, but recovery still depends on retaining access to 1Password. The backup is therefore recoverable under the conditions tested so far, not independent of every account or credential on which the recovery path depends.
This is implemented in my public home-manager repository. I pushed eleven commits directly to main today; this was not a pull request or a detached demo. The commit history shows the implementation developing from the first backup module into provisioning, hardening, tests, and an operational handoff.
The main pieces are visible in the code:
- The initial backup implementation adds the Home Manager module, the backup wrapper, the
agents-doctorchecks, and the launchd schedule. - The provisioning script creates a private per-host bucket, a restricted B2 application key, and the 1Password items. The Restic version pin was necessary because the version in my main package set could not authenticate with keys created through B2’s v4 API.
- The hardening and monitoring change moves success and failure reporting to a monitoring check, puts system tools ahead of user-writable directories in the execution path, reads the config as data rather than sourcing it as shell code, and refuses to upload if any tracked count is zero or has fallen below 80% of the previous successful run.
- The synthetic end-to-end test uses a local Restic repository, synthetic databases, and stand-ins for the external tools. It is designed to run without network access or reading real user data.
- The operational runbook and handoff record what was verified, what remains open, and how restoration is supposed to work.
The data-consistency problem was more interesting than simply copying three paths. cass has its own locking protocol. I clone its database and raw mirror while holding cass’s locks, then let SQLite inspect the clone rather than opening the live database while cass may be writing to it. Atuin’s database is copied through SQLite’s backup mechanism. Before uploading, the script checks database integrity, checks that every raw-mirror manifest points to a blob of the recorded size, and records counts for the data being backed up.
Those counts are also a safety check. A backup command can succeed while faithfully preserving an accidental deletion or a suddenly incomplete source. I compare the staged counts with the last successful run. If a count is zero or drops below 80% of its previous value, the script refuses to upload unless I explicitly pass --accept-drop. That is a small rule, but it changes what a successful backup means: success requires not only that Restic can upload, but also that the source has not unexpectedly shrunk.
Restic itself is pinned at 0.20.0 through a dedicated Nix input because the earlier version could not log in with B2’s v4 keys. This is a compatibility constraint rather than a security control, but pinning the working version makes the deployed backup path reproducible instead of allowing an ordinary package update to silently change a critical recovery dependency.
I also had to account for behavior outside the backup script. B2 daily caps can return HTTP 403, after which Restic retries for many minutes; a low download cap can prevent a restore. I raised the caps manually and documented the behavior, but the scripts do not control those account-level limits. The backup sends a success or failure ping to a monitoring check, which can alert when a failure occurs or a success stops arriving. The failure-email path has not yet been tested.
What has actually been verified
I did not treat the presence of a snapshot as proof of recoverability. On the first snapshot, a full Restic data check completed without errors, and a restore from B2 passed the database integrity checks with counts matching those recorded at backup. An earlier lock test deliberately killed a Restic operation, left a stale lock, and verified that the restricted credential could clear it; that test was against an earlier version of the script.
With the later scripts, I ran a backup through launchd and ran agents-doctor; the handoff records thirteen passing checks and no failures. The doctor checks the installed tools, the loaded launchd job, source data, snapshot age, Atuin and cass counts, a marked Atuin canary, cass health, and a read-only subset of the Restic data.
There is also a synthetic end-to-end test in the repository. It creates temporary databases and a local Restic repository, then exercises initialization, backup, verification, stale-lock recovery, count-drop protection, failure reporting, and staging behavior. That gives me a repeatable way to test the wrapper without involving the real account or network.
But I am not calling the system fully proven yet. The current verify command has not been run against B2; an unattended 01:30 run has not yet been observed; the failure-email delivery has not been tested; and restoration on a second machine has not been rehearsed. The Restic password is kept in 1Password only, with no offline recovery copy, so losing access to that item would make the backups unreadable. The backup also does not include the agents’ own session directories, and cass’s scheduled jobs currently have raw mirroring disabled. Finally, nothing prunes old snapshots, so storage grows until I make a deliberate retention decision.
That list is not a reason to dismiss the work. It is the difference between saying that a system has been implemented and tested in specific ways, and pretending that every recovery scenario has already been demonstrated. I want the operational record to preserve that distinction.
What I let the agent do
I worked with the agent by describing the conditions that had to hold rather than giving it a sequence of commands to execute. The backup had to be encrypted and restorable; secret values could not be committed or written to logs; the recurring credential could not have general delete permission; and anything that touched the cloud account or Keychain needed my approval.
I asked it to show proposed changes before applying them, provide evidence for each condition with secrets redacted, rehearse the flow against a throwaway local repository, and document the steps that only I should perform. That gave me a way to use the agent for investigation and implementation without handing it every authority involved in the setup.
It was useful at the technical details. It examined the database’s locking behavior, found that the B2 CLI had cached my administrative key on disk, identified that my planned SQLite copy method was unsafe for the database in use, and helped investigate the Restic/B2 compatibility issue. Those findings changed what I did. They also illustrate why I did not want the agent to decide the trust boundaries for me.
I kept several decisions in my own hands: creating and holding the administrative credential, choosing the vault and the recurring key’s permissions, setting the bucket’s retention behavior, approving cloud and Keychain operations, checking the account-level settings, clearing the cached administrative key, and deciding what recovery risks I was willing to leave open. I delegated script writing, linting, failure diagnosis, the test harness, and documentation.
For this setup, the test was whether a mistake would be visible and reversible. If it was, delegation was useful. If it could silently expose credentials, destroy the only recovery path, or change who had authority over the backups, I kept the decision.
The compiler comes later
The same boundary will matter in the workflow compiler I want to build. The system should discover repeated behavior, propose a compact representation, and test that representation against the history it is meant to explain. Only the stable, well-understood parts should become deterministic code. The agent should remain available for the exceptions and decisions that the model cannot yet account for.
That is the point of preserving the history. I do not want to automate every sequence just because it happened more than once. I want to identify the work that has become predictable, turn that work into something repeatable, and keep the uncertain parts visible.
The goal is not to remove agents from my workflow. It is to stop spending their reasoning on work that has already become predictable. Today’s backup work is the first step: making sure that some of the evidence for that future automation is still available when I am ready to mine it.
This post was constructed with the help of AI and is the result of reflection on my work and ideas.