feat(ai-harness): createSessionView, a live store of a session for any UI #1546
feat/harness-p10-goal fromfeat/harness-p11-session-view·opened View on GitHubCall 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.storeholds 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, anddispose. Each approval hasapprove()andreject(), and each question hasanswer(). 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'), andview.on(PluginEvent)for any event fromcreatePluginEvent. - New reads for the view:
session.transcript(),session.describe(), andsnapshot().plugins. On the client:transcript(),describe(),answer(),command(),setConfig(), andevents({ onConnection }).createHarnessHandlerservesGET .../transcriptandGET .../describe. selectGoal(state)at@tanstack/ai-harness/pluginsreads the goal from a view.
Also in this PR:
- New dependency:
@tanstack/store^0.11.1in ai-harness. Any TanStack Store adapter reads the view (useSelector), or you can usestore.subscribe. The/viewsubpath is browser-safe, so it works withcreateHarnessClient. - Examples:
ts-code-mode-web,ts-react-chat, andts-solid-chatlisted@tanstack/store^0.8.0but 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, andtest:build(publint: all good). - Root:
install --frozen-lockfile --offline(up to date),test:sherif(0 errors),test:knip(pass),test:docs(no broken links), andkiira check docs/harness/custom-ui.md(2 snippets pass, 5 ignored). The one sherif warning is old:examples/reacthas nopackage.json. - Examples:
test:typespasses ints-code-mode-web,ts-react-chat, andts-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:prbecause 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
pnpm install && pnpm -C packages/ai-harness build.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.- To see a screen, copy the Ink sample from
docs/harness/custom-ui.mdinto 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 afterdispose. 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, anddispose. One test runs the same flow throughcreateHarnessHandlerandcreateHarnessClient.tests/session-reads.test.tsandtests/client-reads.test.ts: the new session reads, client reads and actions, and the connection state.tests/goal.test.ts:selectGoalreturnsnullwith 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:
SessionSnapshothas a newpluginsfield. A hand-made snapshot, for example in a test fake, must add it.HarnessClienthas 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
- 1
View your CI Pipeline Execution ↗ for commit 556d68a9f8f08e18301711aad42d97dc3d0d7c36
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 2m 15s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-28 15:06:22UTC@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@1546commit:
556d68agithub-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
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.
AlemTuzlak closed this
Sign in to join this conversation.
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.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository: TanStack/ai/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
02d2f60f-6489-4240-809b-e4b8a8584deeYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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