Skip to content

feat(permissions): server-side permission rules (ALLOW/DENY/ASK) with session-allow promotion - #239

Open
ikarys wants to merge 4 commits into
co-l:developfrom
ikarys:feat/add-rules
Open

feat(permissions): server-side permission rules (ALLOW/DENY/ASK) with session-allow promotion#239
ikarys wants to merge 4 commits into
co-l:developfrom
ikarys:feat/add-rules

Conversation

@ikarys

@ikarys ikarys commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds deterministic, server-side permission rules (ALLOW/DENY/ASK) for any tool action. Rules are evaluated in Node (not by the LLM), scoped globally or per-project, and merged at runtime with ephemeral session-scoped rules promoted from ASK via "Allow for this session".

Rule engine (src/server/permissions/)

  • schema.ts — Zod validation: non-pattern tools (web_fetch, call_sub_agent, ...) restricted to DENY-only, no pattern
  • rules.tsevaluateRulesWithMatch returns matched rule; precedence DENY (3) > ALLOW (2) > ASK (1)
  • registry.ts — load/save permissions.json (global: ~/.config/openfox/, project: .openfox/)

Enforcement (src/server/chat/, src/server/tools/)

  • agent-loop.ts — per-batch merge of disk rules + ephemeral session rules into batchContext.permissionRules
  • execute-tools.tsevaluateToolGate DENY-only gate for non-path tools (web_fetch, call_sub_agent, ...)
  • path-security.ts — 3-phase evaluation across all targets (command + paths): DENY throws, ALLOW skips sandbox, ASK prompts. Sub-agents fail-closed on ASK. "Allow for this session" promotes ASK → ephemeral ALLOW
  • Hardcoded safety guards: git --no-verify and dangerous commands always prompt, even with ALLOW rule

Cleanup

  • index.tsclearAllowedPaths on session delete + stop (purge ephemeral rules)
  • Removed deprecated path.confirm WS message (REST only)
  • .openfox/permissions.json gitignored (machine-specific, not committable)

UI (web/src/components/settings/, web/src/components/shared/)

  • permissions-shared.tsxRuleForm, RuleRow, PermissionsList with effect/pattern adapting to tool type
  • ProjectSettingsModal.tsx — project-scoped Permission Rules section
  • PathConfirmationButtons.tsx — "Allow for this session" button; hidden for dangerous_command/git_no_verify

Tests — 155 unit + 3 e2e (DENY blocks, ASK prompts, allow-for-session no re-prompt)

AI-Enhanced Development

  • AI Models: GLM-5.2, DeepSeek V4 Flash 0731

Cache Impact

  • Yes — Permission rules are explicitly excluded from the system prompt (buildTopLevelSystemPrompt), the dynamic context hash (computeDynamicContextHash), loadSessionContext, and buildCachedPrompt. The KV cache remains stable when rules are edited. Rules are enforced deterministically server-side via path-security.ts and evaluateToolGate — the LLM discovers DENY by receiving a blocked tool result (1 wasted round-trip), not from the prompt.

Test plan

  • npm run typecheck && npm run lint && npm run test:unit
  • cd e2e && npx vitest run permission-rules.test.ts
  • Manual: add DENY rule for run_command pattern rm -rf *, trigger it → blocked with rule_denied
  • Manual: add ASK rule, click "Allow for this session" → no re-prompt for same pattern in session
  • Manual: add ALLOW rule for read_file pattern **/.env* → reads without sensitive-file prompt
  • Manual: non-pattern tool (web_fetch) → effect dropdown forces DENY, pattern disabled

Anthony Bayle added 4 commits August 12, 2026 11:24
- Add permission schema, registry, and rules engine (src/server/permissions/)
- Add permissions API route (src/server/routes/permissions.ts)
- Integrate permission checks into agent loop, orchestrator, and tool execution
- Extend path-security with rule-based validation and confirmation flow
- Add shared permission types and protocol (src/shared/permissions.ts)
- Add PermissionsTab UI with rule editor and shared components
- Add permissions store (web/src/stores/permissions.ts)
- Wire permission events into MessageList and PathConfirmationButtons
- Add .openfox/permissions.json project-level permission config
- Add comprehensive tests across server, routes, tools, and web

Also fix flaky test timeouts (Markdown cache eviction, inspect-proxy unreachable target)
- Integrate permission checks in agent-loop, orchestrator, execute-tools
- Extend path-security with rule-based validation
- Add permission events to protocol and event types
- Wire PermissionsTab into GlobalSettingsModal
- Add permission confirmation flow in PathConfirmationButtons and MessageList
- Fix flaky test timeouts (Markdown cache eviction, inspect-proxy)
… session-allow promotion

- Rules evaluated deterministically server-side (DENY>ALLOW>ASK precedence)
- Scoped global or project; merged per-batch with ephemeral session rules
- Cache-safe: rules excluded from system prompt + dynamic context hash
- 'Allow for this session' promotes ASK rule to ephemeral ALLOW (pattern-based)
- Tool-level DENY gate for non-path tools (web_fetch, call_sub_agent, ...)
- Schema validation: non-pattern tools restricted to DENY-only, no pattern
- UI: effect/pattern adapt to tool type; hide session-allow for dangerous/git
- Removed deprecated path.confirm WS message (REST only)
- Clear ephemeral rules on session delete/stop
…ache-safety tests

- Gitignore .openfox/permissions.json (machine-specific, not committable)
- Replace inline SVG with EditSmallIcon/TrashIcon in permissions-shared.tsx
- Rewrite prompts.permissions.test.ts: meaningful cache-safety contract tests
- Remove orphaned permissionRules references from test assertions
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