feat(tui): integrated rules editor (#3)#10
Merged
Conversation
Add an integrated rules editor to the terminal UI (issue #3). In the rules view: `n` creates a rule, `e` edits the selected rule, `d` deletes it (with confirmation), and Space toggles enabled/disabled. Rules are authored via a tview form with per-resource CEL autocomplete and live validation (compiles against the resource's CEL env and requires a bool result). Edits are persisted to ~/.config/tusk/config.yaml and the running engine is hot-swapped so changes take effect on the next tick. Persistence is comment-preserving: SaveProfileRules edits only the profile's `rules:` node in the YAML tree, so comments, key order, and every other field (other profiles, connection URLs) are left untouched — and env-derived defaults (port, refresh_interval) and passwords are never written. Output is 2-space indented to match the documented style. RuleConfig gains omitempty on optional fields so saved rules stay clean. Hardening over the prototype: save/delete/toggle surface errors via a modal and only swap on success; duplicate rule names are rejected; the rules view auto-selects the first row so edit/delete/toggle work on entry; and editing is guarded when there is no config-backed profile (e.g. the positional-URL "cli" path) with a clear message instead of a no-op or crash. SetEngine was added to the rules and violations views for the zero-rules→engine bootstrap. Tests: comment/secret/default-omission round-trips for SaveProfileRules. Verified end-to-end against local Postgres (create, toggle, guard, and bootstrap from a profile with no rules). Closes #3 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fraser-Isbester
commented
Jul 7, 2026
Fraser-Isbester
left a comment
Owner
Author
There was a problem hiding this comment.
Reviewed for simplicity and data integrity.
Good reuse rather than new machinery — it leans on BuildRules/UpdateRules and the existing view/engine wiring. The persistence choice is the right one: editing only the profile's rules: node preserves comments and unrelated keys, keeps env-derived defaults and passwords out of the file, and the temp-file + rename write is atomic. Errors surface to the user instead of being swallowed, and the positional-URL path is guarded rather than silently no-oping. Validating CEL in the form before save keeps invalid expressions off disk and out of the engine.
No blocking concerns.
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.
What
Adds an integrated rules editor to the TUI. In the
:rulesview:n— new rule,e— edit selected,d— delete (with confirm),Space— toggle enabled/disabled.tviewform with per-resource CEL autocomplete and live validation (compiles against the resource's CEL env; requires aboolresult).~/.config/tusk/config.yamland the running engine is hot-swapped (effective next tick).Why
Issue #3: "Add the ability to manage Rules directly in the TUI." Previously rules were read-only in the UI and only editable by hand-editing the config file.
How persistence works
config.SaveProfileRulesedits only the profile'srules:node in the YAML tree, so:port,refresh_interval) and env passwords are never written.RuleConfigoptional fields gainomitempty.Hardening beyond the prototype
clipath) with a clear message — no no-op, no crash.SetEngineadded to the rules and violations views for the zero-rules→engine bootstrap.Validation
go build ./...,go vet ./...,golangci-lint run ./...(0 issues),go test -race ./...pass;go mod tidyclean.SaveProfileRulesround-trips — creates file when absent; preserves comments & unrelated keys; omits defaults and never writes an env password; add/edit/remove.dry_run/cooldownnoise), toggled it, exercised the engine-bootstrap path (profile started with zero rules), and confirmed the positional-URL guard doesn't crash.Review guide
internal/config/config.go—SaveProfileRules(comment-preserving YAML-node edit).internal/tui/views/rule_form.go— the form (CEL validation/autocomplete).internal/tui/app.go— key wiring +saveRule/deleteRule/toggleRule/recompileAndSwap+ guards.Closes #3