Skip to content

feat: TUI rule builder with CRUD and config persistence#2

Open
Fraser-Isbester wants to merge 5 commits into
mainfrom
feature/rule-builder
Open

feat: TUI rule builder with CRUD and config persistence#2
Fraser-Isbester wants to merge 5 commits into
mainfrom
feature/rule-builder

Conversation

@Fraser-Isbester
Copy link
Copy Markdown
Owner

@Fraser-Isbester Fraser-Isbester commented Apr 30, 2026

Summary

  • Rule builder form accessible from the Rules tab via n (new), e (edit), d (delete) key bindings
  • Full CRUD — create, edit, and delete rules entirely from the TUI
  • Config persistence — rules are written atomically to ~/.config/tusk/config.yaml and survive restarts
  • Hot-swap — engine updates at runtime via UpdateRules(), no restart needed. First rule bootstraps the engine if none exists
  • CEL autocomplete — When field suggests resource variables and CEL builtins as you type, filtered by prefix
  • Live validation — CEL expressions validated on every keystroke with green/red feedback
  • Status bar and help panel updated with rule builder hints

Changed files

File Change
internal/tui/views/rule_form.go New — form with Name, Resource, When (CEL + autocomplete), Action, Cooldown, Enabled, Dry Run
internal/tui/app.go CRUD methods, key bindings, engine lifecycle, status/help updates
internal/config/config.go Save() for atomic YAML persistence
internal/tui/views/rules.go SetEngine() for nil→initialized transition
internal/tui/views/violations.go SetEngine() for nil→initialized transition
cmd/tusk/main.go Pass *config.Config to NewApp

Test plan

  • Navigate to Rules tab, press n — form appears
  • Tab through fields, type a CEL expression — autocomplete suggestions appear
  • Verify live validation (green "Expression valid" / red error)
  • Save — rule appears in table, check ~/.config/tusk/config.yaml
  • Press e — form pre-populated, modify, save
  • Press d — confirmation, delete, verify removed from config
  • Restart tusk — rules persist
  • Start with zero rules — create first rule, engine bootstraps

- TUI form (n/e/d keys on rules view) for creating, editing, deleting rules
- Live CEL expression validation as you type
- Persists rules to ~/.config/tusk/config.yaml atomically
- Hot-swaps engine at runtime via UpdateRules()
- Handles nil engine → first rule creates engine and wires all views
- Status bar and help panel updated with rule builder hints
- Name and When fields expand to fill available width (no more truncation)
- When field offers autocomplete for resource variables and CEL builtins
- Suggestions filter by prefix of the current token being typed
- Accepting a suggestion re-validates the expression immediately
…ions

- Fix struct field alignment in NewApp (gofmt)
- Separate stdlib/third-party/internal import groups in rule_form.go (goimports)
- Tighten config dir to 0750, config file to 0600 (gosec G301/G306)
- Add CI-before-push requirement to AGENTS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant