feat(tui): learn Always-allow answers into the project policy file - #1
Draft
wesleymatosdev wants to merge 1 commit into
Draft
feat(tui): learn Always-allow answers into the project policy file#1wesleymatosdev wants to merge 1 commit into
wesleymatosdev wants to merge 1 commit into
Conversation
Mirrors the dialog's 'Always allow in this project' response (the runtime's addRules payload) into a project-local policy overlay at <workspace>/.zcode/auto-permissions.json. Learned rules are sparse (only learnings are stored), merged over the built-ins at load time, and re-read on every prompt, so a dialog answer teaches the classifier for the rest of the session and future sessions in the same project. Layering: built-ins <- learned file <- ZCODE_AUTO_PERMISSIONS_CONFIG. The learned file preserves an existing defaults.unmatched value and deduplicates identical rules. Learnings are best-effort: failures log a notice and never disturb the permission flow. Live proof over a PTY (isolated HOME): an 'Always allow' answer on third.txt produced the learned rule in the probe project, and a fresh session auto-answered a later Write to the same path in 14s with no dialog (covered by the learned rule), while an unrelated path still rendered the human dialog.
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.
feat(tui): learn "Always allow" answers into the project policy file
Stacked on kingsword09#137 (auto permission classifier) — merge that first.
What it adds
The base PR's classifier answers prompts from a static policy. This PR closes the loop with claude-code-style learning: when the human dialog's "Always allow in this project" is chosen, the client mirrors that answer into a project-local policy overlay, so the classifier learns it for every later prompt — in this session and future sessions in the same project.
How it works
addRulespayload ({ behavior: "allow", type: "addRules", rules: [{ toolName, ruleContent }] }— seedefaultPermissionChoices). After the response is sent,extractLearningRule()pulls the rule out.appendLearnedRule()appends it to<workspace>/.zcode/auto-permissions.json— deliberately a sparse overlay: only learned rules are stored, never a flattened copy of the built-ins, so the file stays small, diffable, and committable.ZCODE_AUTO_PERMISSIONS_CONFIG(explicit user override wins). The file is re-read on every permission request, so no restart is needed for learned rules to take effect.defaults.unmatchedvalues in the file are preserved; identical rules are deduplicated; a deny-learning would land insoftDenyas an escaped regex, never as an allow.Testing
test/auto-permissions-learn.test.ts(7): payload extraction (incl. non-addRules / empty / null responses), project-local path, file creation, merge-over-duplicates, preservation of custom rules anddefaults.unmatched, deny-never-becomes-allow.bun run typecheckclean;biome checkclean.third.txtproduced{"tool":"Write","note":"learned from dialog","pathPrefix":"…/probe2/third.txt"}in the probe project's.zcode/auto-permissions.json; a fresh session then auto-answered a later Write to the same path in 14s with no dialog, while an unrelated path (fourth.txt) still rendered the human dialog.Known edges (documented behavior, not bugs)
pathPrefix), same scoping as the runtime's own project rules: a learned rule forthird.txtdoes not coverfourth.txt./tmpvs/private/tmp) are distinct strings and match distinctly — consistent with literal prefix semantics.