Repository navigation
Fix #249: project rules (ratchet) from agent failures with incident and expiry - #254
Merged
Merged
Conversation
Rules in .tinyagent/ratchet.toml keep their incident and an expiry date or review condition. Active rules go into the system prompt, rules with a deny matcher are enforced as permission deny rules, expired rules are skipped with a warning, and tinyagent ratchet add|list|remove|path manages the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #249
Summary
Adds project rules ("ratchet"): when an agent fails, record a rule in
.tinyagent/ratchet.tomlwith the incident that caused it and an expiry date or review condition.tinyagent ratchet add "<rule>" --incident "..." [--expires YYYY-MM-DD | --review "..."] [--deny-command|--deny-path|--deny-host|--deny-tool ...], plusratchet list [--json],ratchet remove <id>,ratchet path(flag forms--ratchet-*). No model request, no credentials.denymatcher are also enforced as permission deny rules (blocked by project rule <id>: ...); deny wins over every allow.ratchet.loadedJSON event (path,loaded,ids,expired,enforced);--verbosesummary line.--no-ratchetskips the rules for a run.New code lives in
internal/ratchetandcmd/tinyagent/ratchet_cmd.go;main.gogets only registration, dispatch and the load/start calls. No dependency changes (TOML via the existing BurntSushi dep).Testing
gofmt -l .clean,go build ./...,go vet ./...,go test -count=1 ./...all pass locally.internal/ratchet: load/validate (unknown keys, duplicate ids, bad dates, expires-or-review, one matcher), expiry split, prompt section, permission rule mapping, add/remove with atomic save, missing file and.tinyagentbeing a file.cmd/tinyagent(fake model server only): add/list/list --json/path/remove via both subcommand and flags; usage errors exit 2 without creating the file; a run injects active rules, omits expired ones, warns, emitsratchet.loaded, and blocks a deniedbashcommand before it runs; no file means no event and nothing created;--no-ratchet; an invalid file exits 2.Docs updated
docs/ratchet.md(file format, commands, run behavior, enforcement, limits).README.md: feature list entry with link, documentation table row, subcommand examples.docs/subcommands.md:ratchetsubcommand rows, subcommand lists, and all 12 new flags in the full flag reference.docs/json-output.md:ratchet.loadedevent.docs/permissions.md: notes that ratchet deny rules are the one repository-sourced (deny-only) addition to the policy.docs/config.md: unchanged, since no new config keys were added.Decisions on open questions
.tinyagent/ratchet.tomlat the project root (plain, reviewable TOML); the docs recommend committing it and un-ignoring it if.tinyagent/is gitignored.--no-ratchetopts out. No config key, to keep the surface small.--expiresor--reviewdefaults to expiring in 90 days, so nothing lives forever by accident.expiredfield; nothing is deleted automatically.--resume/follow-ups replay the checkpoint's saved system prompt, and ACP sessions don't load rules yet (documented).r1,r2, ...;ratchet remove <id>for pruning. No automatic rule drafting from failures, to keep humans in the loop.