WeKnora/internal/event
lyingbug ba253bcbac
feat(agent): unified agent permission model with grants and run modes (#4490)
* refactor(agent): route approval decisions through a single policy

Operations, assistant write tools, MCP tool approval, delegated-child
approval and the child tool guard each compared access levels on their
own. They now ask policy.Decide, which maps an action's risk and the
run's rules to allow or ask. Behaviour is unchanged: MCP tools still
follow only the workspace per-tool flag and delegation, and a write that
reaches a read-only run still asks.

Add design docs for the agent permission model and scheduled automation.

* refactor(agent): replace interactive flags with a run mode

Runs are attended, deferred or unattended. Unattended runs refuse every
approval, including MCP approvals that used to wait out the timeout;
deferred runs suspend at once.

* feat(agent): apply access levels to MCP tools and every agent

MCP tools get a risk: the workspace's explicit setting, else the service's
readOnlyHint, never lower than a risk the service declared before. The
run's access level now decides MCP calls as it does operations; read-only
runs neither see nor run tools that change data. Ordinary agents get a
configurable ceiling that defaults to auto_write, and delegated children
take the lower of their parent's level and their own ceiling instead of
asking for every MCP call.

* feat(agent): persist approval grants with session/automation scopes

Remembered "allow for this conversation" approvals move from prompt history
into an agent_grants table keyed by root session (or automation binding), so
delegated children share the root grant and unattended runs honour it.
MCP write tools now offer the grant, keyed by service, tool and input schema.
Users can list and revoke their grants from the chat header.

* feat(agent): acting-via identity, decision logs and grant lapse reasons

Principal gains ActingVia so work done on a user's behalf (automations) is
told apart in audit details and policy decision logs. Every non-read policy
decision is logged with its action, risk, level, mode and verdict.
Automation grants bind to a hash of the agent setup, owner role and access
ceiling; a grant that no longer applies asks again and the card says why.

* docs(agent): record permission model implementation status

* chore(handler): check c.Error in agent grant handlers

* chore(handler): check c.Error in MCP tool policy handler

* fix(agent): raise MCP observed risk atomically and scope worker access

- Compare observed_risk inside the upsert so a stale lower observation
  cannot overwrite a higher one recorded concurrently.
- Delegated workers use the same conditional level as attach: the
  assistant ceiling applies only under an assistant parent.
- Mock @/api/assistant in useModalShell tests; gofmt internal/mcp/client.go.

* docs(agent): allow destructive pre-grants only in automation scope

Decide against a level that skips every prompt: Always stays
unwaivable and destructive actions may only be pre-approved per resource
when an automation is set up. Note that automation runs must look up
both automation and session grants.

* feat(agent): standing grant scope and risk-bounded grants

Grants record the risk they were approved for and never cover a riskier
call. Destructive calls are now named for matching, so an automation's
standing grant can cover one, but the card still offers to remember only
writes. The gate looks up the run's own scope and then its standing
scope; approvals during a run are written only to the run's scope.
2026-10-19 20:52:15 +08:00
..
SUMMARY.md feat: Add agent configuration and cleanup scripts for database migrations 2025-11-05 23:18:44 +08:00
adapter.go refactor: Implement event-driven streaming and enhance session management 2025-11-07 22:41:41 +08:00
event.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
event_data.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
example_test.go fix: improve tenant access token logging and update test cases 2026-04-22 21:17:30 +08:00
global.go feat: Add agent configuration and cleanup scripts for database migrations 2025-11-05 23:18:44 +08:00
middleware.go feat: Add agent configuration and cleanup scripts for database migrations 2025-11-05 23:18:44 +08:00
usage_example.md feat: Add agent configuration and cleanup scripts for database migrations 2025-11-05 23:18:44 +08:00