# Improve the workflow, Corrections and Agent files This file says how reflect applies lessons, how `/pstack:correct` encodes a rule, and how agent files change. The pstack block in `AGENTS.md` points here. The `sync-pstack` skill renders this file from its shared source in `udecode/dotai`, so change it there. - **Improve the workflow mid-task.** For a shell or tool mistake, `/pstack:correct`'s order means a helper that removes the need, then a hook, then text. A `/pstack:correct` change's commits follow Delivery. A new check claims only the forms its proof ran. Before a rules table calls a rule enforced, the lead runs the class's common variants through the check, keys any baseline on each finding's full identity, never a count or truncated text, and narrows the row's claim to what failed. A correction that forbids a command names the invariant the command broke, and the fix removes the need for that operation instead of swapping in another command that does the same thing, such as a stash for a removal. When applying a lesson, reread every section that governs the same process for a rule the new text contradicts, or for an instruction that restarts a loop the lesson bounds, such as rerun, again or until, and resolve each in the same edit. The lead reads the scoped transcript itself, as pstack's reflect does, and starts no reviewer. A reflect scoped by a user message starts at that message's own record, never at a summary that quotes it, and a second reflect in one session starts right after the first reflect's call. Every scoped transcript ends at the last record before this reflect's call, which is the owner's typed command or the lead's skill call. The reflect skill's expanded body and the lead's setup commands after that call stay out of what it mines. The lead reads both anchor lines before it starts. The lead applies without waiting only two kinds of Accepted lesson. These two kinds bound only what a reflect applies from its own findings. The lead still fixes at once any skill, rule, script or helper that gets in the way of the current task, as the block's Improve the workflow mid-task rule says. One fixes a script, check, hook or helper that crashes on, or refuses, a case its own rule allows. The fix handles that case as the rule says and behaves as before on every other input, so it refuses, writes, sends and commits nothing new, and the lead runs the corrected case and one case the rule must still refuse. The other rewords rule text, adding no net words, and applies only after one fresh-context reader on the lead's model, given only the old and new text, finds no permission, prohibition, obligation, gate, stop, trigger, pass condition or qualifier changed. The lead cites the rule each lesson keeps. Such a lesson for the pstack block, its rule files or a shared helper runs the `sync-pstack` skill's Lesson mode. Every other Accepted lesson goes to Backlog with `owner:` the owner and `stop:` the owner takes or drops it, and binds nothing; so does a rewording the reader flags and a lesson whose effect the lead cannot show. The lead also builds a Backlog item from the same reflect in the same run, like an Accepted lesson, when the item repeats an earlier reflect's Backlog item or prevents a mistake the owner corrected. Its mechanism must be a small script, helper or hook that the project or the shared source owns, that needs no owner decision and that runs a step a rule already requires, at the trigger that rule names, writing, sending and blocking nothing; it cites that rule. An item whose script already exists is not built again; when it repeats because that script went unused, its mechanism is a hook that runs the script read-only at that trigger and shows its output. Any other item, one whose step writes included, goes to Backlog with `owner:` the owner and `stop:` the owner takes or drops it. Every other Backlog item names its `owner:` and a dated or observable `stop:`. An applied lesson saved as a patch binds the lead's own work from the moment it is written, not from when its sync lands; a tool defect the run has recorded binds the lead only to avoid that defect, never to a new requirement. The applied lessons and built items that change a script, check, hook or helper get one panel on their combined diff with the configured seats before they land, in place of the owner's approval and without pausing the run. That panel follows the Panel review rule, and its rows go in the run's log. The reflect that produced the batch is the run's last; a lesson from a later reflect goes to Backlog. The Accepted, Rejected and Backlog lists go on the run's page as a record. When the transcript it mines interleaves records from more than one process, told apart by their `version` field or `parentUuid` chain, the lead keeps only the chain that leads to the reflect call before it mines it, and names the other process as a co-tenant. An applied lesson that changes a rule in the pstack block or its rule files goes to its shared source through the `sync-pstack` skill; without that skill, write it outside the block for the owner to upstream. - **Corrections.** These add to `/pstack:correct`. Its sweep also reads committed decision-log and panel rows as their own lane, and CI run history through `gh run list` and `gh run view --log-failed`, which its lane briefs may run. A deferred top level does not count as the highest level that works. While the architecture fix waits, the next level down, such as a baseline lint whose error names the owner module, ships now to stop growth. Before baselining a rule's live hits, sort a sample into mistakes and deliberate design, and narrow the rule when deliberate code is the majority. A new check's past-mistake proof runs the past file version through the real tool and configuration, with the fixed file as the control; a hand-written case named after a commit does not count. A hook that refuses commands replays this project's past transcript commands before it ships, the lead reads a sample of each denial class, and the lead checks its deny message against every rule here that prescribes the command. A new check counts only once the one blocking gate runs it, and the first correction adds a reachability test that fails on any check-shaped script that is neither a gate step nor listed as manual with its reason. When that gate is red at base, "fail only when a change adds more" covers its red steps and failing tests too, through a known-failure list that only shrinks. Before a new gate counts as done, list every way to pass it without fixing code, such as editing the baseline, touching an exempting file, writing an approver's name or dropping the base, try each one, and make the check fail closed when it cannot resolve a reference input it was given, such as an unreachable base commit. A way that passes blocks the gate until an existing mechanism closes it or a `look` Defaults row accepts it. A closed way names the try that now fails, and the list holds defects, never limits. A lint checks only an exception's reason and expiry; approval comes from the owner reviewing changes to exception lines, the lint configuration and the baseline. In the rules table, a row names only the rule and its enforcer, an enforced row lands together with the cut of the prose it replaces, and a rule-only row points to the section that holds its text instead of restating it. - **Agent files.** Before cutting or folding a skill, command or plugin, count the user's typed invocations over all history, not load counts. Keep every typed command and every working integration as an entry point, and count a replacement only once it works in this setup. An integration counts as working only after a probe through the exact call chain the rule prescribes, with real inputs such as a full-size payload, flag-like tokens and the longest expected run; until then the old default stays live. Never edit a vendor skill installed from another repository; override it in `AGENTS.md` outside the pstack block or in a project rule instead. A reflect lesson for a pstack skill never edits a copy of that skill. One for every project goes to the pstack block or its rule files through the `sync-pstack` skill's Lesson mode, which commits and pushes the shared source, and one for this project alone goes outside the block. After editing a rule in `.agents/rules`, run `pnpm run prepare` and check the generated `.agents/skills//SKILL.md`; never edit a generated skill. Run user-scope `claude plugin` commands from the home directory; from the repository they rewrite `.claude/settings.json`. After any plugin command, check `git diff .claude/settings.json`. Changes to agent instructions, plugin settings or the skill set reach every teammate and runtime on the next pull. Before sharing one, run a fresh read-only session in each runtime (`sync-pstack smoke` runs both) with a plain fake request that does not name the answer to confirm routing, and state which runtimes and committers gain or lose what, in the commit body or, when the user owns commits, on the page.