feat(ai-harness): build a harness into a worker artifact, and run it as a worker #1760
feat/harness-core fromrefs/pull/1760/head·merged by AlemTuzlak View on GitHubWith this PR, you can ship a harness as a built artifact. buildHarness bundles a harness with Bun into harness.js plus a harness.manifest.json with a sha256 digest, and can also build a single executable. artifactText(dir) checks the digest and runs the artifact as the model of a chat() call, one worker process per thread. runHarnessWorker runs a harness on stdin and stdout.
This PR targets the transport PR #1757 (feat/harness-transport), which targets the core harness PR #1755. It is split out of #1555.
🎯 Changes#
Why the base is the transport PR, not core. The split manifest put this feature on feat/harness-core. But the worker speaks the session frames of src/protocol.ts (parseControlFrame, applyInput, HostFrame), and protocol.ts is in the transport PR. Copying it here would conflict with #1757. GitHub retargets this PR when #1757 merges.
Source (packages/ai-harness):
src/build.ts:buildHarness,readManifest,artifactText, and theHarnessManifestV1type, ported from #1555.src/worker.ts:runHarnessWorker(harness, { input, output, persistence }), ported from #1555. The first frame must beharness.subscribe../buildand./workersubpath exports, and theirvite.config.tsentries. No new dependencies.
Changes from #1555 (from the code review):
- A worker that fails to start or stops now fails the waiting stream with an error. On #1555 the stream waited forever, and a failed spawn was an uncaught error in the host process.
- A stream that stops early (abort, or
break) sendscancelfor its turn, so the worker does not keep spending tokens. - The prompt keeps the content parts of the last user message. On #1555 a message with parts became an empty prompt.
build-stub.test.tsnow expects the parts, and its stub worker ignores thecancelinput. - The digest is checked again before each worker starts, not only once in
artifactText(). - The worker reports a failed event feed as a
harness.errorframe, not an unhandled rejection. The describe script escapes the entry path in its error text, and the temp files are made inside thetry, so a failed write cleans up.
Not changed (decisions):
manifest.requiresreads plugin names (tanstack/workspace-tools,tanstack/snapshots,tanstack/project-instructions,connector/*). Those plugins arrive with the plugins and coding-tools PRs. Until then the fields arefalse/model-only. They are claims, and deploy policy decides.artifactTextstays separate fromharnessText. A shared frame adapter is a refactor of transport code, so it is out of scope here.
Docs. New page docs/harness/deploy.md ("Deploy a harness", addedAt 2026-10-13) and a docs/config.json entry. On #1555 the page used runCli --serve for "another machine" and a CLI file for the executable. The CLI package is not in this stack yet, so the page uses createHarnessHandler with a bearer token (it links to the "Connect clients" page) and "the file that starts your app". Readers: agent builders who deploy a harness. Tone: matches the existing pages.
Update: merged transport with #1779. The package.json exports and the Vite entries keep ./build, ./worker, and the new ./view from transport. Since #1779, the remote harnessText fails a stream that closes before RUN_FINISHED. So the remote-worker case for a response with no body now expects RUN_ERROR. The worker and artifactText needed no change: they end a turn on harness.operation.finished, and they call no method that #1779 changed.
Changeset. @tanstack/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 (after the merge, Node 24.8.0):
nx run-many -t test:types test:oxlint test:lib -p @tanstack/ai-harness: pass (73 files, 1013 tests).nx run-many -t test:types -p "examples/**" "testing/**": pass (27 projects).pnpm test:docs,kiira check docs/harness,pnpm test:knip,pnpm test:sherif: pass.- A code review of the merge found no issues.
- Not run locally: E2E and the full
pnpm test:pr.
Manual test.
- Install Bun.
- Run
buildHarness({ entry: './src/studio.ts', export: 'studio', outDir: './dist/studio' }). - Open
dist/studio/harness.manifest.json. It names the harness and has the digest. - Run
chat({ adapter: await artifactText('./dist/studio'), messages, threadId: 't1' }). The answer streams from the worker process. - Change one byte of
harness.js.artifactTextrefuses it.
How this PR makes testing easy. Three test files in packages/ai-harness/tests/:
build-stub.test.tsuses a small fake Bun script, so it runs on CI without Bun.build.test.tsdoes a real Bun build. It skips when Bun is not installed.remote-worker.test.tsdrivesrunHarnessWorkerwith in-memory streams.
No E2E spec: the build needs Bun and a child process, and the E2E app runs in a browser against one server.
Risk / rollback#
Low. Two new opt-in subpaths, no change to existing code. Revert the PR to remove them.
Public API change#
Before: no build or worker entry.
After
import { artifactText, buildHarness } from '@tanstack/ai-harness/build'
await buildHarness({ entry: './src/studio.ts', export: 'studio', outDir: './dist/studio' })
const model = await artifactText('./dist/studio')- 1
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:
d4c86d11-38db-40a5-8a8d-11872cf57821
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 7f137ea292f0f1707e2158683bebad64586a3e8f
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 5m 53s View ↗ nx run-many --targets=test:coverage --projects=...✅ Succeeded 3s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 53s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-15 12:37:05UTC@tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1760@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1760@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1760@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1760@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1760@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1760@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1760@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1760@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1760@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1760@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1760@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1760@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1760@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1760@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1760@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1760@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1760@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1760@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1760@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1760@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1760@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1760@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1760@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1760@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1760@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1760@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@1760@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1760@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1760@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1760@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1760@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1760@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1760@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1760@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1760@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1760@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1760@tanstack/ai-ollaya
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@1760@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1760@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1760@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1760@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1760@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1760@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1760@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1760@tanstack/ai-react-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1760@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1760@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1760@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1760@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1760@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1760@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1760@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1760@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1760@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1760@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1760@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@1760@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1760@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1760@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1760@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1760@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1760@tanstack/ai-solid-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1760@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1760@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1760@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1760@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1760@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1760@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1760@tanstack/ai-vue-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1760@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1760@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1760@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1760@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1760@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1760@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1760commit:
7f137eaCoverage#
✅ Coverage held across 29 compared package(s).
Each package is measured twice in this job — on this PR and on its merge-base with
main— and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.package statements branches functions lines ai-acp 82.32% (0.00) 71.27% (0.00) 77.08% (0.00) 83.97% (0.00) ok ai-claude-code 88.93% (0.00) 76.88% (0.00) 86.88% (0.00) 90.40% (0.00) ok ai-code-mode 92.71% (0.00) 85.66% (0.00) 89.06% (0.00) 93.51% (0.00) ok ai-code-mode-snippets 87.13% (0.00) 75.67% (0.00) 91.11% (0.00) 88.39% (0.00) ok ai-codex 94.55% (0.00) 85.10% (0.00) 89.28% (0.00) 95.56% (0.00) ok ai-durable-stream 86.70% (0.00) 82.25% (0.00) 92.30% (0.00) 88.72% (0.00) ok ai-grok-build 79.19% (0.00) 63.56% (0.00) 77.39% (0.00) 81.02% (0.00) ok ai-harness 93.04% (+0.18) 87.48% (+0.08) 93.27% (-0.03) 94.59% (+0.17) ok ai-isolate-cloudflare 94.11% (0.00) 70.66% (0.00) 100.00% (0.00) 93.96% (0.00) ok ai-isolate-daytona 90.25% (0.00) 80.59% (0.00) 100.00% (0.00) 90.15% (0.00) ok ai-isolate-e2b 92.11% (0.00) 81.48% (0.00) 97.36% (0.00) 95.05% (0.00) ok ai-isolate-node 84.00% (0.00) 43.39% (0.00) 100.00% (0.00) 83.78% (0.00) ok ai-isolate-quickjs 89.07% (0.00) 76.41% (0.00) 90.90% (0.00) 90.30% (0.00) ok ai-isolate-quickjs-bun 7.76% (0.00) 8.08% (0.00) 5.00% (0.00) 8.33% (0.00) ok ai-mcp 96.71% (0.00) 91.77% (0.00) 96.86% (0.00) 98.66% (0.00) ok ai-opencode 68.77% (0.00) 60.82% (0.00) 64.04% (0.00) 70.78% (0.00) ok ai-sandbox 77.45% (0.00) 82.80% (0.00) 74.47% (0.00) 77.97% (0.00) ok ai-sandbox-blaxel 87.64% (0.00) 77.18% (0.00) 82.26% (0.00) 89.71% (0.00) ok ai-sandbox-boxd 95.86% (0.00) 87.12% (0.00) 95.31% (0.00) 98.17% (0.00) ok ai-sandbox-cloudflare 67.91% (0.00) 57.47% (0.00) 71.79% (0.00) 69.62% (0.00) ok ai-sandbox-daytona 82.70% (0.00) 81.89% (0.00) 67.14% (0.00) 85.18% (0.00) ok ai-sandbox-docker 80.15% (0.00) 71.49% (0.00) 77.38% (0.00) 82.13% (0.00) ok ai-sandbox-e2b 94.42% (0.00) 88.97% (0.00) 93.24% (0.00) 98.63% (0.00) ok ai-sandbox-local-process 68.00% (0.00) 53.59% (0.00) 75.86% (0.00) 68.88% (0.00) ok ai-sandbox-railway 94.75% (0.00) 92.68% (0.00) 90.90% (0.00) 97.59% (0.00) ok ai-sandbox-sprites 73.23% (0.00) 59.70% (0.00) 73.83% (0.00) 76.17% (0.00) ok ai-sandbox-upstash-box 94.82% (0.00) 91.52% (0.00) 91.04% (0.00) 97.76% (0.00) ok ai-sandbox-vercel 44.67% (0.00) 38.18% (0.00) 35.18% (0.00) 45.76% (0.00) ok ai-skills 83.39% (0.00) 68.53% (0.00) 87.36% (0.00) 85.48% (0.00) ok github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
jherr approved these changes
Seems pretty safe. LGTM.
github-actions[bot](GitHub profile, opens in a new tab) added labelsready-to-merge
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
AlemTuzlak merged this0fef405
AlemTuzlak closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 7f137ea292f0f1707e2158683bebad64586a3e8f
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR