Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-harness): build a harness into a worker artifact, and run it as a worker #1760

MergedAlemTuzlakmerged 32 commits intofeat/harness-core fromrefs/pull/1760/headmerged by AlemTuzlak View on GitHub

AlemTuzlakcommented

With 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 the HarnessManifestV1 type, ported from #1555.
  • src/worker.ts: runHarnessWorker(harness, { input, output, persistence }), ported from #1555. The first frame must be harness.subscribe.
  • ./build and ./worker subpath exports, and their vite.config.ts entries. No new dependencies.

Changes from #1555 (from the code review):

  1. 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.
  2. A stream that stops early (abort, or break) sends cancel for its turn, so the worker does not keep spending tokens.
  3. The prompt keeps the content parts of the last user message. On #1555 a message with parts became an empty prompt. build-stub.test.ts now expects the parts, and its stub worker ignores the cancel input.
  4. The digest is checked again before each worker starts, not only once in artifactText().
  5. The worker reports a failed event feed as a harness.error frame, not an unhandled rejection. The describe script escapes the entry path in its error text, and the temp files are made inside the try, so a failed write cleans up.

Not changed (decisions):

  • manifest.requires reads 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 are false / model-only. They are claims, and deploy policy decides.
  • artifactText stays separate from harnessText. 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.

  1. Install Bun.
  2. Run buildHarness({ entry: './src/studio.ts', export: 'studio', outDir: './dist/studio' }).
  3. Open dist/studio/harness.manifest.json. It names the harness and has the digest.
  4. Run chat({ adapter: await artifactText('./dist/studio'), messages, threadId: 't1' }). The answer streams from the worker process.
  5. Change one byte of harness.js. artifactText refuses it.

How this PR makes testing easy. Three test files in packages/ai-harness/tests/:

  • build-stub.test.ts uses a small fake Bun script, so it runs on CI without Bun.
  • build.test.ts does a real Bun build. It skips when Bun is not installed.
  • remote-worker.test.ts drives runHarnessWorker with 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. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 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
      NameType
      @tanstack/ai-harnessMinor
      @tanstack/ai-acpPatch
      @tanstack/ai-code-modePatch
      @tanstack/ai-mcpPatch
      @tanstack/ai-skillsPatch

      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

    2. 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: d4c86d11-38db-40a5-8a8d-11872cf57821

      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
      • 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.

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

      View your CI Pipeline Execution ↗ for commit 7f137ea292f0f1707e2158683bebad64586a3e8f

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded5m 53sView ↗
      nx run-many --targets=test:coverage --projects=...✅ Succeeded3sView ↗
      nx run-many --targets=build --exclude=examples/...✅ Succeeded53sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-15 12:37:05 UTC

    4. 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@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@1760

      commit: 7f137ea

    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      Coverage

      ✅ 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.

      packagestatementsbranchesfunctionslines
      ai-acp82.32% (0.00)71.27% (0.00)77.08% (0.00)83.97% (0.00)ok
      ai-claude-code88.93% (0.00)76.88% (0.00)86.88% (0.00)90.40% (0.00)ok
      ai-code-mode92.71% (0.00)85.66% (0.00)89.06% (0.00)93.51% (0.00)ok
      ai-code-mode-snippets87.13% (0.00)75.67% (0.00)91.11% (0.00)88.39% (0.00)ok
      ai-codex94.55% (0.00)85.10% (0.00)89.28% (0.00)95.56% (0.00)ok
      ai-durable-stream86.70% (0.00)82.25% (0.00)92.30% (0.00)88.72% (0.00)ok
      ai-grok-build79.19% (0.00)63.56% (0.00)77.39% (0.00)81.02% (0.00)ok
      ai-harness93.04% (+0.18)87.48% (+0.08)93.27% (-0.03)94.59% (+0.17)ok
      ai-isolate-cloudflare94.11% (0.00)70.66% (0.00)100.00% (0.00)93.96% (0.00)ok
      ai-isolate-daytona90.25% (0.00)80.59% (0.00)100.00% (0.00)90.15% (0.00)ok
      ai-isolate-e2b92.11% (0.00)81.48% (0.00)97.36% (0.00)95.05% (0.00)ok
      ai-isolate-node84.00% (0.00)43.39% (0.00)100.00% (0.00)83.78% (0.00)ok
      ai-isolate-quickjs89.07% (0.00)76.41% (0.00)90.90% (0.00)90.30% (0.00)ok
      ai-isolate-quickjs-bun7.76% (0.00)8.08% (0.00)5.00% (0.00)8.33% (0.00)ok
      ai-mcp96.71% (0.00)91.77% (0.00)96.86% (0.00)98.66% (0.00)ok
      ai-opencode68.77% (0.00)60.82% (0.00)64.04% (0.00)70.78% (0.00)ok
      ai-sandbox77.45% (0.00)82.80% (0.00)74.47% (0.00)77.97% (0.00)ok
      ai-sandbox-blaxel87.64% (0.00)77.18% (0.00)82.26% (0.00)89.71% (0.00)ok
      ai-sandbox-boxd95.86% (0.00)87.12% (0.00)95.31% (0.00)98.17% (0.00)ok
      ai-sandbox-cloudflare67.91% (0.00)57.47% (0.00)71.79% (0.00)69.62% (0.00)ok
      ai-sandbox-daytona82.70% (0.00)81.89% (0.00)67.14% (0.00)85.18% (0.00)ok
      ai-sandbox-docker80.15% (0.00)71.49% (0.00)77.38% (0.00)82.13% (0.00)ok
      ai-sandbox-e2b94.42% (0.00)88.97% (0.00)93.24% (0.00)98.63% (0.00)ok
      ai-sandbox-local-process68.00% (0.00)53.59% (0.00)75.86% (0.00)68.88% (0.00)ok
      ai-sandbox-railway94.75% (0.00)92.68% (0.00)90.90% (0.00)97.59% (0.00)ok
      ai-sandbox-sprites73.23% (0.00)59.70% (0.00)73.83% (0.00)76.17% (0.00)ok
      ai-sandbox-upstash-box94.82% (0.00)91.52% (0.00)91.04% (0.00)97.76% (0.00)ok
      ai-sandbox-vercel44.67% (0.00)38.18% (0.00)35.18% (0.00)45.76% (0.00)ok
      ai-skills83.39% (0.00)68.53% (0.00)87.36% (0.00)85.48% (0.00)ok
    6. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

    7. github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts

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

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

    10. jherr approved these changes

      Seems pretty safe. LGTM.

    11. github-actions[bot](GitHub profile, opens in a new tab) added labelsready-to-merge

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

    13. github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author

    14. github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts

    15. AlemTuzlak merged this0fef405

    16. AlemTuzlak closed this

Sign in to join this conversation.