WeKnora/internal/agent
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
..
approval feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
collaboration feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
compaction fix(agent): 将空闲超时覆盖到模型流建立阶段 2026-10-10 20:40:58 +08:00
hitl feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
operations feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
policy feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
skills feat(lite): install and run skills on the host (#3661) 2026-09-24 21:30:34 +08:00
token refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
tools feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
act.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
act_order_test.go feat(assistant): manage agents and skills, separate history, refresh pages (#4344) 2026-10-15 21:43:20 +08:00
attachment_timeout_test.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
calibration.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
calibration_test.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
checkpoint.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
collaboration.go fix(agent): let open_page finish the turn with the answer above it (#4472) 2026-10-19 14:47:43 +08:00
collaboration_delivery_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
collaboration_test.go fix(agent): let open_page finish the turn with the answer above it (#4472) 2026-10-19 14:47:43 +08:00
complete_event_model_test.go feat(agent): name the turn's chat model on the completion event (#4252) 2026-10-13 23:07:32 +08:00
const.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
const_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
context_debug.go refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
engine.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
engine_image_test.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
engine_memory_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
engine_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
finalize.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
grounding_prompt.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
grounding_prompt_test.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
knowledge_base_profile_prompt_test.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
langfuse_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
length_truncation_test.go fix(agent): end the turn when the completion cap truncates an answer (#3449) 2026-09-20 13:17:50 +08:00
mcp_exposure_test.go fix(mcp): normalize JSON-encoded argument envelopes 2026-09-09 16:11:52 +08:00
mcp_proxy_test.go fix(mcp): normalize JSON-encoded argument envelopes 2026-09-09 16:11:52 +08:00
observe.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
observe_test.go feat(assistant): trial runs, session grants, page links, and MCP/model/skill management (#4375) 2026-10-16 23:36:01 +08:00
orphan_think_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
page_button_finish_test.go fix(agent): let open_page finish the turn with the answer above it (#4472) 2026-10-19 14:47:43 +08:00
prompt_composition_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
prompts.go feat(assistant): trial runs, session grants, page links, and MCP/model/skill management (#4375) 2026-10-16 23:36:01 +08:00
prompts_browser.go fix(browser): align BrowserSkill 0.3.0 and repair task lifecycle 2026-09-17 11:54:12 +08:00
prompts_browser_test.go feat(browser): polish connection settings, open tasks in a new window, and streamline prompts (#3193) 2026-09-11 21:28:58 +08:00
prompts_shell_test.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
prompts_wiki.go fix(wiki): 整页重写被补全预算截断时续写,续写用尽则拒绝写回(长名单 146→119) (#3582) 2026-09-23 12:17:07 +08:00
prompts_wiki_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
protocol_artifact_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
resume.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
resume_mcp_test.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
resume_test.go feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
retry_delay_test.go fix(models): keep Retry-After on HTTPError and honour it in agent LLM retries 2026-09-29 01:22:15 +08:00
steer.go feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
steer_order_test.go fix(agent): preserve steering order across persistence failures (#4078) 2026-10-10 20:32:20 +08:00
steer_test.go fix(chat): preserve steering continuity and composer focus 2026-09-09 20:15:23 +08:00
stream_start_timeout_test.go fix(agent): 将空闲超时覆盖到模型流建立阶段 2026-10-10 20:40:58 +08:00
suspend.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
suspend_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
terminal_event_test.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
think.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
tool_goroutine_panic_test.go fix(agent): 工具自起 goroutine 的 panic 自行兜底,MCP 预热不再带走进程 (#3846) 2026-10-08 01:24:36 +08:00
tool_images.go fix(agent): clarify attachment image paths and chart readings (#4283) 2026-10-14 14:23:28 +08:00
tool_images_test.go fix(agent): clarify attachment image paths and chart readings (#4283) 2026-10-14 14:23:28 +08:00
turn_usage_test.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00