Skip to content

feat(chat): add the run cards and the runs tray - #1787

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-cards
Oct 29, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-cards

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat P0, part D2: the run cards and the runs tray, built from D1's pieces (#1760) and copied from the approved Chat v2 mockup (#s-plan, #s-need, #s-done, #s-denied, #s-failed). Behind CHAT_AGENTIC. The engine (C3) feeds them.

Cards (web/src/components/agentic/)

  • plan-card.tsx:
    • Each step with its approval pill (Auto / Asks you / Auto · logged / Needs your click), plus Uses, connections, About, AI usage (%) and Outputs.
    • Edit plan reorders or removes steps; Start runs the edited plan.
    • A role that can't run it sees "Ask your Admin" instead of Start.
  • approval-card.tsx:
    • WRITE: before/after, why, sources; Skip, Edit, Approve, Save & approve. "Don't ask again" shows only when canDontAskAgain.
    • EXECUTE: the one dark "Needs your click" pill and a button naming the effect ("Publish"). It is disabled with the reason while it can't run, and never offers "Don't ask again".
    • States: waiting, saving, approved, skipped, error.
  • result-card.tsx:
    • "Generated …" and "Data as of …" as absolute times, with the GMT offset in a tooltip.
    • The steps fold under "Worked for …".
    • Open goes only to /dashboard/… (A1's isChatHref).
  • denial-card.tsx:
    • The four parts: what was asked; why not and where the rule is; who can; what you can do.
    • A plan refusal adds "Growth adds".
    • "Ask your Admin" takes an onAskAdmin prop, which B2's action fills.
  • error-card.tsx: the red avatar, "Stopped at step 2 of 3", the reason, and Retry step / Retry.
  • run-steps.tsx, step-list.tsx (CHAT-03): "Working on it · N steps · m:ss" while running, then "Worked for 1m 12s · 7 steps · 4 sources". Each new step is announced (aria-live="polite").
  • Approve, Start, Retry and Ask your Admin go through useUpgradeGate().guard. Motion stops under reduced motion, coloured states have dark pairs, and copy lives in en.json.

Runs tray

  • runs-tray.tsx (data-action="runs.toggleTray"):
    • The header pill ("1 running", with an amber count) opens "Your runs" with Review, progress and Open.
    • It refreshes every 4 s while open and every 15 s when closed, and never while the tab is hidden.
  • api/chat/runs/tray/route.ts:

Preview (/dashboard/chat/preview) adds every card in every state and the tray (empty and live), using sample data from the mockup.

Notes

Related issue

None (Chat P0, Drive › Chat).

Type of change

  • feat — New feature (behind CHAT_AGENTIC)

How to test

  1. CHAT_AGENTIC=true, then open /dashboard/chat/preview: every card state, in light and dark mode, with reduced motion on.
  2. cd web && yarn vitest run src/components/agentic/ src/lib/chat/runs-tray.test.ts 'src/app/api/chat/runs/tray/'. The 16 files, 345 tests, cover:
    • card states, "Don't ask again" visibility, the EXECUTE pill and the four denial parts;
    • guard, aria-live, reduced motion and dark mode;
    • the tray route: 404 with the flag off; another person's chat or another brand's draft never shows; no */tool select; the failure JSON.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: related tests (345) pass; typecheck, eslint and prettier clean
  • Browser check (light and dark, 1024 px): in the next batched local test
  • Full suite and build: CI

🤖 Generated with Claude Code

Chat P0, D2, from the approved Chat v2 mockups (#s-plan, #s-need,
#s-done, #s-denied, #s-failed and the header's runs pill), on D1's
agent pieces:

- Plan card: the steps with how each runs (Auto, Asks you, Auto ·
  logged, Needs your click), what the run uses and connects to, time,
  AI usage and outputs; Edit plan moves or removes steps, Start runs
  the edited plan. A role that can't start runs gets Ask your Admin.
- Approval card: a WRITE's change as before and after, why, sources,
  Skip · Edit · Approve and Save & approve; "Don't ask again" only when
  the precedence allows it (canDontAskAgain). An EXECUTE is the one dark
  "Needs your click" pill and a button naming the effect, off with its
  reason until it can be made. Pending, saving, approved, skipped and
  failed states.
- Result card: "Generated …" and "Data as of …" in absolute time with
  the GMT offset, the steps folded under "Worked for …", counts, files
  whose Open goes only to a path in the app (ChatHref), and the click
  card that waits above it.
- Out-of-permission card: what was asked, why not and where it is set,
  who can by role, and what next; Ask your Admin goes through
  onAskAdmin (B2 wires access.request), then says Sent.
- Failed run: the agent in red, where it stopped and why, and Retry
  from the failed step or the whole run.
- Run steps (CHAT-03): "Working on it" with the step count and clock,
  "Worked for 1m 12s · 7 steps · 4 sources" once done, a one-step run as
  that step's line; each new step said to screen readers (aria-live).
- Every approve, start, retry and request goes through the read-only
  gate (useUpgradeGate().guard). Motion stops with reduced motion.
- Runs tray: the runs pill with the amber needs-you count and the
  "Your runs" list (Review, progress, Open), read again every few
  seconds, not while the tab is hidden. GET /api/chat/runs/tray reads
  the person's own Chat runs (steps by CHAT_RUN_STEP_SELECT) and the
  brand's Content Agent runs, newest first; 404 while CHAT_AGENTIC is
  off; failures come back as { ok: false, failure, error }.
- The preview page (/dashboard/chat/preview) shows every card in every
  state, and the tray, also live.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good: ec60ab3 merges into main cleanly as it is.

What I checked

  • Flag off.
    • The tray route answers 404 before any chat_* read.
    • The preview page calls notFound().
  • Who sees what.
    • The tray reads as the signed-in person, through RLS: chats are the author's own (there's also an .eq('user_id')), and runs and steps follow their chats.
    • The brand id must be a UUID. Content runs are limited by the drafts' organization RLS.
  • What reaches the browser.
    • At most 10 runs.
    • No dollar amounts and no tool names. The only ids are in the links.
  • Embeds. One, content_drafts!content_agent_runs_draft_id_fkey!inner(title, brand_id). There is one foreign key between the two tables, and the hint names it.
  • Client imports. No client component reaches a server module (plan-row.test.ts passes).
  • No migration.

Follow-ups (not blocking while the tray is on the preview page only)

  1. The tray keeps polling every 15 s after a 401 or a 404. It could stop at the first one.
  2. The chat_run_steps read has no .limit. Only the 30 runs bound it.

Tests: cards, runs-tray and the tray route pass. The stack passes as a whole (see #1794).

@gkhngyk
gkhngyk merged commit 9c5da13 into ansvisor:main Oct 29, 2026
4 of 5 checks passed
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.

2 participants