Skip to content

Provider activity notices and provider-requested confirmations in the chat turn #1639

Backlog

Description

@smart-ssh-planner

Goal

A provider can show what it is doing in the chat (for example "reading file X", "plan updated") and can ask the user for a yes/no-style decision in the chat while its answer is streaming. The chat turn passes the decision back to the provider. Nothing a provider shows or asks executes anything by itself.

Context

  • AiEvent (crates/core/src/ai/types.rs) has WebActivity as the only informational event from a provider. It is handled in crates/app-logic/src/orchestration/chat_turn.rs:857 / handle_web_activity (:982).
  • The chat turn already has a confirmation flow for proposed actions (crates/app-logic/src/orchestration/pending_confirmation.rs, confirmation.rs) and an AskUser path (chat_turn.rs:740). There is no way for a provider to ask the user something and get the answer back during the same stream.
  • AiProvider (crates/core/src/ai/provider.rs:24) has send, disable_web_research and last_request_id, and no channel back from the app to a running stream.
  • Spec 0039 (untrusted content), ADR 0141 (fencing of extension content).

Requirements

  • Activity event. A new AiEvent variant for provider activity, e.g. ProviderActivity { id, kind, title, detail, status }.
    • kind is a closed list: tool, plan, thought, notice.
    • status is pending, running, completed or failed.
    • A later event with the same id updates the entry.
    • It is informational only, like WebActivity: it triggers no filter engine, no follow-up round and no execution.
    • The chat turn forwards it to the frontend and stores it in the chat history so it shows again after reload.
    • It is never sent back to any provider as model input.
    • Titles and details are untrusted text: length-limited and redacted with the session's output redactor before display and storage.
  • Confirmation event. A new AiEvent variant for a provider confirmation, e.g. ConfirmationRequested { request_id, title, detail, options }.
    • Each option has an id, a label and a kind from a closed list: allow once, allow for this chat, reject.
    • The chat turn shows it in the chat as a confirmation the user answers.
    • The answer goes back to the provider through a new trait method, e.g. AiProvider::resolve_confirmation(request_id, ConfirmationOutcome), with a no-op default.
    • The outcome is the chosen option id, or Cancelled when the turn is stopped, the session closes, the stream ends or the request is unknown. Unanswered means rejected.
  • Effect on existing confirmations. A provider confirmation never changes how proposed actions are filtered or confirmed. It is not an ActionProposed and never passes or affects FilterEngine::evaluate().
  • Built-in providers. They emit neither event. Their behaviour is unchanged.
  • Spec. Spec 0006 (events) describes both events and the outcome rules.

Acceptance Criteria

  • A test provider emitting ProviderActivity with two updates of one id results in one stored, updated activity entry, no follow-up round and no execution.
  • Activity text containing a known secret of the session is stored and forwarded redacted (test). Over-long text is truncated.
  • A test provider emitting ConfirmationRequested receives exactly the option the (test) user chose through resolve_confirmation.
  • Stopping the turn, closing the session or dropping the stream while a provider confirmation is open resolves it as Cancelled (one test each).
  • An unknown request_id answer is ignored and logged without panicking.
  • A proposed command in the same response still goes through filter engine and confirmation unchanged (test with both events in one stream).
  • Existing chat-turn tests pass unchanged.
  • Relevant automated tests pass.

Technical Notes

  • Security-critical area: the chat turn and the confirmation path. The provider's text is untrusted (Spec 0039). Show it as plain text, never as markdown links or HTML, and never as an instruction to the model.
  • The frontend rendering is a separate issue. This issue defines and emits the IPC events and the answer command, and regenerates generated/ipc.ts.
  • AiEvent derives Clone, PartialEq, so the reply path cannot be a channel inside the event. Hence the trait method.

Files: crates/core/src/ai/types.rs, crates/core/src/ai/provider.rs, crates/app-logic/src/orchestration/chat_turn.rs, crates/app-logic/src/orchestration/ (new module for provider confirmations), crates/app-shell/src/commands/, crates/persistence-sqlite/ (only if chat history storage needs a new entry kind), apps/smart-ssh-community/frontend/src/generated/ipc.ts, docs/specs/0006-ai-provider-trait.md

Spec impact: update 0006

Open questions

  • Storage of activity entries: (a) as a new message content variant in the chat history, (b) in the same place as WebActivity entries. Recommendation: (b) if WebActivity storage can be generalised without a migration, otherwise (a).

Related Work

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsecurity

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions