Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-harness): createSessionView, a live store of a session for any UI #1546

ClosedAlemTuzlakwants to merge 8 commits intofeat/harness-p10-goal fromfeat/harness-p11-session-viewopened View on GitHub

AlemTuzlakcommented

Call createSessionView(session) and you get one live TanStack Store of everything a UI shows about a harness session. You draw it with any UI library, in a terminal or in a browser. You do not read session.events() and fold the events yourself. The view also gives you actions (send, approve, answer, cancel) and typed events such as view.on('approval', ...).

Stacked on #1540 (Phase 10) → #1538 → #1524 → #1523 → #1522 → #1521 → #1520 → #1519 → #1518 → #1515 → #1513 → #1509. Merge those first.

🎯 Changes

  • createSessionView(session | client) at @tanstack/ai-harness/view. view.store holds the messages with streaming text and reasoning, and tool calls with a status (running, done, failed, needs-approval). Child agents are nested, with their own parts. The store also holds approvals, questions, sign-ins, status, background agents, queued turns, commands, settings, tools, plugin state, and the connection state.
  • Actions: send (a prompt, a steer while a turn runs, or a /command), command, setConfig, cancel, approve, reject, approveAll, rejectAll, notice, and dispose. Each approval has approve() and reject(), and each question has answer(). When one turn has several approvals, the view sends all the decisions in one resolve.
  • Typed events: view.on('approval' | 'question' | 'signIn' | 'toolCall' | 'agent' | 'error' | 'turnEnd'), and view.on(PluginEvent) for any event from createPluginEvent.
  • New reads for the view: session.transcript(), session.describe(), and snapshot().plugins. On the client: transcript(), describe(), answer(), command(), setConfig(), and events({ onConnection }). createHarnessHandler serves GET .../transcript and GET .../describe.
  • selectGoal(state) at @tanstack/ai-harness/plugins reads the goal from a view.

Also in this PR:

  • New dependency: @tanstack/store ^0.11.1 in ai-harness. Any TanStack Store adapter reads the view (useSelector), or you can use store.subscribe. The /view subpath is browser-safe, so it works with createHarnessClient.
  • Examples: ts-code-mode-web, ts-react-chat, and ts-solid-chat listed @tanstack/store ^0.8.0 but did not import it. They move to ^0.11.1, so sherif sees one version.
  • Docs: docs/harness/custom-ui.md (new), after the goal page in the harness nav. Changeset: ai-harness (minor).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Testing

Commands run (not the full pnpm test:pr, see below):

  • ai-harness: vitest run (30 files, 259 tests pass; the view tests passed 3 runs in a row), test:types, test:oxlint (0 errors, warnings only in older files), build, and test:build (publint: all good).
  • Root: install --frozen-lockfile --offline (up to date), test:sherif (0 errors), test:knip (pass), test:docs (no broken links), and kiira check docs/harness/custom-ui.md (2 snippets pass, 5 ignored). The one sherif warning is old: examples/react has no package.json.
  • Examples: test:types passes in ts-code-mode-web, ts-react-chat, and ts-solid-chat. The first run failed only with "Cannot find module" for workspace packages that were not built in this worktree. After I built those packages, all three passed.
  • Skipped the full pnpm test:pr because it is slow on this machine. CI runs it. No new E2E test: this PR adds a library surface, and no browser app uses it yet.
  • No manual UI run. Phase 12 adds the example screen.

Manual test

  1. pnpm install && pnpm -C packages/ai-harness build.
  2. pnpm -C packages/ai-harness exec vitest run tests/view.test.ts tests/view-reduce.test.ts tests/view-paths.test.ts. Expect all tests to pass.
  3. To see a screen, copy the Ink sample from docs/harness/custom-ui.md into a script with a local session. This PR has no example app for it.

How this PR makes testing easy

  • tests/view-reduce.test.ts: the pure reducer. Streaming text and reasoning, tool call status, nested and sibling agents, notices, sign-ins, plugin state, snapshots, a saved transcript, and a table of events that must not change the state.
  • tests/view-paths.test.ts (41 tests): the view with a fake source, so each path is forced. Failed reads at start, a stream that throws or ends, reconnecting, actions that fail, approvals, handlers that throw, every event type, and actions after dispose. Each of 20 guards in the view code was broken on purpose once, and a test failed each time.
  • tests/view.test.ts (9 tests): the live view. Prompt, steer, one resolve for two approvals, commands, restart history, and dispose. One test runs the same flow through createHarnessHandler and createHarnessClient.
  • tests/session-reads.test.ts and tests/client-reads.test.ts: the new session reads, client reads and actions, and the connection state.
  • tests/goal.test.ts: selectGoal returns null with no goal, and the goal after /goal.

Risk / rollback

Low. The view is a new subpath. The other changes add reads and routes, and they do not change the old ones. Two type changes can break code that builds these objects by hand:

  • SessionSnapshot has a new plugins field. A hand-made snapshot, for example in a test fake, must add it.
  • HarnessClient has new members. A hand-made client must add them.

A session start now reads the saved state of each plugin one time. Revert the PR to undo.

Public API change

Before

for await (const event of session.events()) {
  // Join text deltas, follow tool calls, keep a list of open approvals.
  state = fold(state, event)
  draw(state)
}

After

import { createSessionView } from '@tanstack/ai-harness/view'

const view = createSessionView(session)
view.store.subscribe(draw)
view.on('approval', (a) => a.approve())
await view.send('hi')

🤖 Generated with Claude Code

https://claude.ai/code/session_01APYv1qshKyjPPpkFyRZhfZ

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on base/target branches other than the default branch.

      Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository: TanStack/ai/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 02d2f60f-6489-4240-809b-e4b8a8584dee

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 556d68a9f8f08e18301711aad42d97dc3d0d7c36

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/...✅ Succeeded2m 15sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-09-28 15:06:22 UTC

    3. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented

      Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1546

      @tanstack/ai-acp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1546

      @tanstack/ai-angular

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1546

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1546

      @tanstack/ai-bedrock

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1546

      @tanstack/ai-byteplus

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1546

      @tanstack/ai-claude-code

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1546

      @tanstack/ai-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1546

      @tanstack/ai-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1546

      @tanstack/ai-code-mode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1546

      @tanstack/ai-code-mode-snippets

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1546

      @tanstack/ai-codex

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1546

      @tanstack/ai-cohere

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1546

      @tanstack/ai-compaction

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1546

      @tanstack/ai-dashboard

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-dashboard@1546

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1546

      @tanstack/ai-durable-stream

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1546

      @tanstack/ai-elevenlabs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1546

      @tanstack/ai-event-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1546

      @tanstack/ai-fal

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1546

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1546

      @tanstack/ai-grok

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1546

      @tanstack/ai-grok-build

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1546

      @tanstack/ai-groq

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1546

      @tanstack/ai-harness

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1546

      @tanstack/ai-harness-cli

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness-cli@1546

      @tanstack/ai-isolate-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1546

      @tanstack/ai-isolate-daytona

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1546

      @tanstack/ai-isolate-node

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1546

      @tanstack/ai-isolate-quickjs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1546

      @tanstack/ai-isolate-quickjs-bun

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1546

      @tanstack/ai-llmgateway

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1546

      @tanstack/ai-lovable

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1546

      @tanstack/ai-mcp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1546

      @tanstack/ai-memory

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1546

      @tanstack/ai-mistral

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1546

      @tanstack/ai-octane

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1546

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1546

      @tanstack/ai-openai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1546

      @tanstack/ai-opencode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1546

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1546

      @tanstack/ai-perplexity

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1546

      @tanstack/ai-persistence

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1546

      @tanstack/ai-preact

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1546

      @tanstack/ai-react

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1546

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1546

      @tanstack/ai-reactor

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1546

      @tanstack/ai-remix

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1546

      @tanstack/ai-sandbox

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1546

      @tanstack/ai-sandbox-blaxel

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1546

      @tanstack/ai-sandbox-boxd

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1546

      @tanstack/ai-sandbox-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1546

      @tanstack/ai-sandbox-daytona

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1546

      @tanstack/ai-sandbox-docker

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1546

      @tanstack/ai-sandbox-e2b

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1546

      @tanstack/ai-sandbox-local-process

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1546

      @tanstack/ai-sandbox-sprites

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1546

      @tanstack/ai-sandbox-upstash-box

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1546

      @tanstack/ai-sandbox-vercel

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1546

      @tanstack/ai-skills

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1546

      @tanstack/ai-solid

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1546

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1546

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1546

      @tanstack/ai-typesafe

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1546

      @tanstack/ai-utils

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1546

      @tanstack/ai-vercel-gateway

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1546

      @tanstack/ai-vertex

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1546

      @tanstack/ai-vue

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1546

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1546

      @tanstack/ai-worldlabs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1546

      @tanstack/openai-base

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1546

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1546

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1546

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1546

      @tanstack/svelte-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1546

      commit: 556d68a

    4. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

    5. AlemTuzlakcommented

      Closed in favor of the combined PR #1555, which holds this phase and every other phase of the harness (P0 to P14) on one branch against main. All further fixes go there. This PR stays as the review record of P11.

    6. AlemTuzlak closed this

Sign in to join this conversation.