Skip to content

Web: replay an agent session and watch Sthira catch the drift - #35

Merged
HelloOjasMutreja merged 2 commits into
mainfrom
feat/web-agent-replay
Oct 18, 2026
Merged

HelloOjasMutreja merged 2 commits into
mainfrom
feat/web-agent-replay

Conversation

@Dang-ctrl

@Dang-ctrl Dang-ctrl commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #34.

Why

The live "an agent drifts and Sthira catches it" moment (POST /api/demo/drop) only works in desktop demo mode (STHIRA_DEMO_DROP plus the background watcher). On the hosted site there was no way to see it happen. This adds an in-browser replay that works on any host, next to the existing feed. The demo-drop button is unchanged and still shows only in demo mode.

What

  • GET /api/demo-session (web/app.py): returns {title, messages: [{role, text}]}, parsed from demo/claude_code/session.jsonl with sthira.ingest.claude_code.parse. Returns empty messages if the file is missing. Documented in docs/CONTRACTS.md.
  • "Watch an agent drift" section (web/static/index.html, right after "While you were away"), built in the page's own design system:
    • A terminal-style card (ink title bar, you / agent labels, a caret while typing) types the session out.
    • After each agent message over 40 characters it calls the existing POST /api/check. It shows "Sthira is checking…", then interrupts inline:
      • Contradiction: the confrontation card (agent's words ≠ the decision, the verbatim quote, date and source, the explanation), with an OVERRULED stamp. The agent's line gets a madder wavy underline.
      • Non-conflict: a quiet jade "Consistent" note.
      • Fallback verdicts are labelled: a keyword match · not a model verdict tag plus a note, or recorded run.
      • A failed check shows "The hosted model is busy right now" instead of breaking the replay.
    • Ends with a score ("2 of 2 drifts caught"), also shown in the title bar. The button is disabled while it runs, then reads "Replay again".
    • The copy says that in real use the watcher and the Claude Code hook do this in the background.
    • All text goes in through textContent. Typing is time-boxed per message (about 12 s for the whole session with checks) and skipped under prefers-reduced-motion. Progress is announced through an sr-only live region, so screen readers don't hear every character.
    • At 600px and below the labels stack and the cards go full width. No horizontal scroll at 375px.
  • Tour: one extra step ("Or watch it live") pointing at the section. It doesn't auto-run the replay.
  • Test: web/tests/test_demo_session.py checks the endpoint's shape and content, and that both agent messages are caught by the labelled keyword fallback when the model is unreachable.

Test plan

  • PYTHONPATH=. python -m pytest -q: 59 passed
  • Ran the app with the model unreachable (OLLAMA_HOST=http://127.0.0.1:9). At 1280px, the replay finished in about 12 s: both agent messages were caught by the labelled keyword fallback (MongoDB, email+password), and it showed "2 of 2 drifts caught"
  • At 375px: the replay works, there's no horizontal scroll (scrollWidth 375), and the stamp doesn't overlap the fallback tag
  • Button disabled while running, "Replay again" afterwards, and the replay runs again cleanly
  • Stubbed /api/check to fail with a 502: each message shows the busy-model note, and the score reads "0 of 2 drifts caught · 2 not checked (model busy)"
  • Stubbed a consistent verdict with HTML in the model name: the quiet note renders, and the HTML shows as text, not markup
  • Walked through the whole tour from Web: a guided 60-second tour for judges #34 (now 8 steps), including the auto-check that ends in OVERRULED
  • No console errors
  • prefers-reduced-motion: not emulated in the browser. The code path sets text instantly and skips the pauses

🤖 Generated with Claude Code

Summary by ShipWright

  • Added GET /api/demo-session, which parses demo/claude_code/session.jsonl with sthira.ingest.claude_code.parse and returns {title, messages: [{role, text}]}, or empty messages when the file is missing.
  • Added an agent replay section to web/static/index.html that fetches the demo session, types out each message, and posts agent messages longer than 40 characters to /api/check.
  • Rendered check results inline: a drift card with the conflicting decision and source quote for contradicts verdicts, a consistent note otherwise, and an error note when the check request fails.
  • Added web/tests/test_demo_session.py covering the endpoint response shape and the keyword-fallback verdicts for the demo agent messages.

Change: Feature · Merge risk: 🟢 Low · updated on each push

The server-side demo drop only works in desktop demo mode, so the hosted
site had no live "an agent drifts and Sthira catches it" moment. Add
GET /api/demo-session (the demo Claude Code session, parsed) and a
"Watch an agent drift" section that types the session out and runs each
agent message through /api/check, interrupting inline with the
OVERRULED confrontation card, honest fallback labels, a busy-model note
and a final score. Adds a tour step pointing at it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shipwright-agent

shipwright-agent Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Shipwright · Approve

Recommendation: approve PR #35 · Tier T1

Next step: ready to merge.

Walkthrough

The PR adds a /api/demo-session endpoint that returns a parsed Claude Code session, and a browser replay UI that types the session out and runs each agent message through /api/check, showing Sthira's verdict inline.

Area / files Summary
Demo session endpoint
web/app.py
Added GET /api/demo-session that reads demo/claude_code/session.jsonl, parses it with sthira.ingest.claude_code.parse, and returns the title and role/text messages, or empty values if the file is absent.
Agent replay UI
web/static/index.html
Added a replay section, styles, and JavaScript that loads the demo session, types out each message, posts agent messages over 40 characters to /api/check, and renders drift, consistent, or error results with a final caught count.
API contract docs
docs/CONTRACTS.md
Documented the new GET /api/demo-session endpoint and its response shape.
Demo session tests
web/tests/test_demo_session.py
Added tests asserting the endpoint returns the parsed session with the expected roles and that each agent message yields a contradicts verdict with the keyword fallback when the model is unreachable.

Estimated review effort: 3 (Moderate) · ~20 minutes
Change: Feature
Merge risk: 🟢 Low · tier T1

Review

✅ Full review input coverage: 10/10 changed files · 4 review shard(s) · 638 changed lines.
✅ No actionable findings.

Open the Shipwright check for full evidence and the audit bundle. Use /shipwright rerun to verify again.

@shipwright-agent shipwright-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ShipWright reviewed this commit. See the ShipWright summary comment in the conversation for the walkthrough and findings.

@HelloOjasMutreja
HelloOjasMutreja changed the base branch from feat/web-tour to main October 18, 2026 11:36

@shipwright-agent shipwright-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ShipWright reviewed this commit. See the ShipWright summary comment in the conversation for the walkthrough and findings.

@HelloOjasMutreja
HelloOjasMutreja merged commit 4a3baf7 into main Oct 18, 2026
3 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