Commit Graph

4 Commits (main)

Author SHA1 Message Date
lyingbug eecfe4b3c8
feat(automation): scheduled agent runs with in-app notifications (#4492)
* feat(automation): scheduled agent runs with in-app notifications

Automations let a user have an agent run a task on a schedule as them.
The scheduler is database driven: every instance claims due rows with a
version CAS, so Lite and multi-instance deployments share one path.
Runs execute in deferred mode, suspend on approvals and notify the
owner; an answered prompt resumes the run from its snapshot. Standing
grants are promoted from approvals past runs asked for, bound to the
agent configuration and the owner's role.

Adds the automation, run and notification APIs, the automation.*
assistant operations, and regenerates the Swagger document.

* feat(frontend): automations page and notification bell

Adds an Automations page to the sidebar: a list with schedule, agent,
next run and last status; an editor with schedule presets, a custom
cron field, timezone and a live preview of the next runs; and a detail
drawer with run history, links into each run's conversation and the
standing approvals the owner can grant from past approval requests.

The top-right bell now merges pending invitations with in-app
notifications and polls for new ones.

* fix(automation): let the assistant schedule tasks and match the settings UI

The assistant never searched for automation operations, one-time times failed unless they were RFC3339, and the create, detail, and notification surfaces did not match the rest of the app.
2026-10-20 00:11:36 +08:00
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
lyingbug 966d841d19
feat(assistant): add durable multi-agent collaboration and live task views (#4438)
* feat(assistant): add persistent multi-agent collaboration and live task views

* fix(ci): wrap runtime notice message append

* fix(agent): preserve collaboration results and prevent duplicate execution

* fix(agent): fence panic followups and preserve approval timelines

* test(frontend): stub connector labels in assistant refresh fixture

* fix(migrations): avoid collaboration migration collision with main

* fix(assistant): preserve child continuations and artifact access

* fix(frontend): align artifact and icon checks with updated UI

* fix: enforce child approvals and finalize interrupted collaboration runs

* feat: support inherited temporary agent workers

* docs: clarify inherited worker scope and lifecycle

* fix: harden assistant retrieval and final delivery

* fix(agent): keep closed child prompts continuable and renew active deadlines

Expired child approvals were looked up by the child session, so the parent group stayed open and the run became needs_attention. Active collaborations also expired one hour after creation.

* fix(lint): clear golangci-lint findings on the collaboration PR

The previous CI run failed on line length, gofumpt, unchecked closes, and an unused dial parameter.

* fix(ci): use the public npm registry for frontend dependencies

* fix(agent): address collaboration review findings

- keep ordinary fallbacks when a turn delegated no work
- throttle lease/deadline heartbeats and drop duplicated child answers
- force-close or compact aggregates that exceed the size limit
- clamp completion budget to the model output limit
- honor prompt_suspend for non-collaboration tools
- clean up collaborations and child sessions on session delete, prune old rows
- bound concurrent child executions globally
- retry prompt classification and tolerate transient heartbeat errors
- scope prompt history to listed messages, reject nil tenants
2026-10-19 12:14:15 +08:00
lyingbug 383d26535a
feat(agent): persist human-in-the-loop prompts with a shared broker (#4250)
* feat(agent): persist human-in-the-loop prompts with a shared broker

Tool approvals and MCP OAuth prompts are now rows in agent_prompts,
awaited through hitl.Broker (lease, DB polling, Redis wake-up, per-kind
answer validation). Resolve is bound to session and kind. This is P1 of
the suspend/resume design; runs still block as before.

* feat(agent): suspend runs whose prompt outlives a short in-memory wait

Behind agent.prompt_suspend_enabled (off by default). A run raised from the
HTTP stream saves its state when a tool approval is raised; after the hot
wait the prompt moves to suspended and the assistant message is saved as
awaiting_input instead of blocking. A reaper takes over prompts whose
waiting replica stopped renewing its lease. Resume comes in a later change.

* feat(agent): resume suspended runs once their prompt is answered

The replica that records the answer resumes the run in process under the
prompt's lease. Superseded, expired and abandoned runs are closed with a
result for every tool call, and approved tools are never replayed.

* feat(agent): let users answer suspended tool approvals and follow the resumed run

* feat(agent): ask_user tool and generic prompt answer endpoint

- ask_user built-in tool: options, short forms or free text; validated
  answers, decline, suspend/resume like tool approval; non-interactive
  callers (IM, API keys) are told to ask in the reply instead
- POST /agent/prompts/{prompt_id} (and embed variant) answers ask_user
  and tool_approval prompts, returns resumed; SDK ResolveAgentPrompt
- agent_prompt_required/resolved events; AskUserCard sharing the
  countdown with ToolApprovalCard; answered questions rebuilt as cards
  from history
- awaiting-input messages keep their steps expanded so the pending card
  stays visible; prompt cards keyed by their own id
- i18n for all locales; design doc updated

* fix(agent): keep prompt answers that race a suspending or vanished owner

- Resolve suspends a pending prompt whose owner's lease lapsed, as the
  reaper would, so the answer resumes the run instead of waking nobody.
- Resuming waits for the suspending run to persist its message and clear
  its live-run marker; a marker left by a vanished owner is cleared.
- A resumed run that suspends again on a new prompt no longer has its
  message closed from the old state.
- tool_approval answers are decoded strictly and require "approved";
  fix the SDK doc that showed {"decision": "approve"}.
- API-key runs block instead of suspending, since they cannot answer.
- A run state that cannot be saved falls back to an in-memory wait, and
  NUL escapes are stripped from snapshots for jsonb.

* style(chat): align the ask_user card with the other interaction cards

Question and answer use the timeline's step text styles instead of
primary-colored and monospace text; options and form controls use the
compact step size, the number input spans the row, and the free-text
character counter is hidden.

* feat(chat): dock pending agent prompts above the composer

Tool approvals, ask_user questions and MCP OAuth prompts were answered
inline in the agent timeline, where a long answer or scrolling back
pushes them out of view. Open prompts of a streaming or suspended run
now gather in a dock above the composer (main chat and embed), one at a
time with a pager, lettered options and Enter to submit. The timeline
keeps a one-line record with a link back to the dock and the outcome
once answered. Views without a dock still answer inline.

* fix(agent): fence prompt ownership and preserve resumed turn context

* fix(agent): keep runs through consume errors and file prompts under the caller

Consume reported a store error as a lost claim, so an answer consumed
during a database hiccup detached its run: the message was never
persisted, the live-run marker stayed, and the reaper skipped the row
because the waiter had already dropped the snapshot. Consume now retries,
then decides from the row, and gives a run up only when the prompt is
known to have moved on.

Tool approvals and OAuth prompts of a shared agent were filed under the
agent's workspace, so the user's answer failed the tenant check and the
prompt timed out. Like ask_user, they now use the caller's workspace;
policy and token lookups stay in the agent's.

Enter on a picked option submits it instead of toggling it off, and
resume errors no longer report a nil cause.

* fix(agent): validate prompt choices and require durable approval claims

Reject malformed serialized option lists so the model can retry with valid arguments. Distinguish prompt consumption failures from lost ownership without authorizing side effects, and preserve native Enter selection for unselected choices.

* fix(agent): resolve prompt workflow lint errors
2026-10-14 20:37:28 +08:00