Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-harness): goal() plugin that keeps working until a judge says the goal is met #1762

MergedAlemTuzlakmerged 15 commits intofeat/harness-core fromrefs/pull/1762/headmerged by AlemTuzlak View on GitHub

AlemTuzlakcommented

With this PR, a harness can keep working until a goal is met. goal({ judge }) from @tanstack/ai-harness/plugins adds /goal <text>. After each turn, the judge model reads the goal and the end of the conversation, and the plugin starts the next turn until the goal is met.

This PR targets the first-party plugins PR #1759 (feat/harness-plugins), which targets the core harness PR #1755 (feat/harness-core). It is split out of #1555.

🎯 Changes

Source (packages/ai-harness):

  • src/first-party/goal.ts: the goal({ judge, maxRounds }) plugin, ported from #1555.
    • /goal <text>, /goal, /goal stop, and /goal resume.
    • The loop stops when the goal is met, at the round limit, when a turn waits for approval or fails, and when the user sends a message.
    • The GoalMet event, and selectGoal(state) for a UI.
  • src/first-party/index.ts exports goal, GoalMet, selectGoal, and the Goal type from ./plugins.

Changes from #1555:

  1. selectGoal takes any state with plugins, for example session.snapshot(). #1555 typed it as the session view state, and the view is in another PR (feat/harness-view). A view state still fits this type.
  2. The session view test reads session.snapshot() instead of a view.
  3. From the code review: /goal resume also starts an active goal again when no turn runs or waits (for example, after its queued turn was cancelled). Before, the goal stayed active and nothing ran. New unit test for this case. isGoal also checks reason, note, and queued.

Changes from the #1779 merge (feat/harness-core and feat/harness-plugins now take one object):

  1. Merged feat/harness-plugins (with #1779) in, with no conflict.
  2. No code change was needed here. goal() calls none of the methods that now take one object. It is a session plugin, so it can still add /goal.

Not changed (review findings left as they are in #1555):

  • A turn that is not from the user (a wake note, a background agent) also pauses the goal with "You sent a message". Telling them apart needs a core change.
  • The judge runs in onFinish, so the goal turn ends after the check. This is the design: the next turn queues behind it.
  • A crashed goal turn that the host replays pauses the goal. /goal resume continues it.

Docs. New page docs/harness/goal.md ("Work until a goal is met") and a docs/config.json entry (addedAt 2026-10-13). The samples use only the core harness and ./plugins: no CLI or coding tools. Readers: agent builders on @tanstack/ai-harness. Tone: plain second person, short sentences.

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 #1779 merge, all of these passed:

  • nx run-many --targets=test:types,test:oxlint,test:lib: @tanstack/ai-harness: 64 test files, 886 tests.
  • nx run-many --targets=test:types --projects='examples/**,testing/**': 27 projects.
  • pnpm test:docs, kiira check docs/harness (28 snippets), pnpm test:knip, pnpm test:sherif.

Not run: the full pnpm test:pr and the E2E suite. CI runs them.

Manual test.

  1. Run pnpm --filter @tanstack/ai-e2e test:e2e --grep "goal\(\)".
  2. The route runs /goal, the main model answers, and the judge (gpt-5.4-nano on aimock) says the goal is met.
  3. The spec checks the goal state, the /goal text, and that there were only 2 model calls.

How this PR makes testing easy.

  • packages/ai-harness/tests/goal.test.ts (13 cases) runs the plugin in a real harness host with a fake adapter and a scripted judge.
  • E2E: the goal scenario in testing/e2e/src/routes/api.harness-first-party.ts and tests/harness-first-party.spec.ts.

Risk / rollback

Low. The plugin is opt-in. Revert the PR to remove it.

Public API change

Before: no goal plugin.

After

import { goal } from '@tanstack/ai-harness/plugins'

defineHarness({
  name: 'acme/coder',
  adapter: openaiText('gpt-6.1-sol'),
  plugins: () => [goal({ judge: openaiText('gpt-6-luna') })],
})
await session.command('goal', 'all tests pass')

🤖 Generated with Claude Code

    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: 3262b132-1dd8-4e1a-a3d6-aa34b251b744

      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.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit d4c65d79a3354485a9da2c67e641d40ff8a7ba1c

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

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

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

      🦋 Changeset detected

      Latest commit: d4c65d79a3354485a9da2c67e641d40ff8a7ba1c

      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

    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@1762

      @tanstack/ai-acp

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

      @tanstack/ai-angular

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

      @tanstack/ai-anthropic

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

      @tanstack/ai-bedrock

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

      @tanstack/ai-byteplus

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

      @tanstack/ai-claude-code

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

      @tanstack/ai-client

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

      @tanstack/ai-cloudflare

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

      @tanstack/ai-code-mode

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

      @tanstack/ai-code-mode-snippets

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

      @tanstack/ai-codex

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

      @tanstack/ai-cohere

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

      @tanstack/ai-compaction

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

      @tanstack/ai-devtools-core

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

      @tanstack/ai-durable-stream

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

      @tanstack/ai-elevenlabs

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

      @tanstack/ai-event-client

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

      @tanstack/ai-fal

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

      @tanstack/ai-gemini

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

      @tanstack/ai-grok

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

      @tanstack/ai-grok-build

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

      @tanstack/ai-groq

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

      @tanstack/ai-harness

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

      @tanstack/ai-isolate-cloudflare

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

      @tanstack/ai-isolate-daytona

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

      @tanstack/ai-isolate-e2b

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@1762

      @tanstack/ai-isolate-node

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

      @tanstack/ai-isolate-quickjs

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

      @tanstack/ai-isolate-quickjs-bun

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

      @tanstack/ai-llmgateway

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

      @tanstack/ai-lovable

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

      @tanstack/ai-mcp

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

      @tanstack/ai-memory

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

      @tanstack/ai-mistral

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

      @tanstack/ai-octane

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

      @tanstack/ai-ollama

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

      @tanstack/ai-ollaya

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@1762

      @tanstack/ai-openai

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

      @tanstack/ai-opencode

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

      @tanstack/ai-openrouter

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

      @tanstack/ai-perplexity

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

      @tanstack/ai-persistence

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

      @tanstack/ai-preact

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

      @tanstack/ai-react

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

      @tanstack/ai-react-ui

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

      @tanstack/ai-reactor

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

      @tanstack/ai-remix

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

      @tanstack/ai-sandbox

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

      @tanstack/ai-sandbox-blaxel

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

      @tanstack/ai-sandbox-boxd

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

      @tanstack/ai-sandbox-cloudflare

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

      @tanstack/ai-sandbox-daytona

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

      @tanstack/ai-sandbox-docker

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

      @tanstack/ai-sandbox-e2b

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

      @tanstack/ai-sandbox-local-process

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

      @tanstack/ai-sandbox-railway

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

      @tanstack/ai-sandbox-sprites

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

      @tanstack/ai-sandbox-upstash-box

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

      @tanstack/ai-sandbox-vercel

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

      @tanstack/ai-skills

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

      @tanstack/ai-solid

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

      @tanstack/ai-solid-ui

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

      @tanstack/ai-svelte

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

      @tanstack/ai-typesafe

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

      @tanstack/ai-utils

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

      @tanstack/ai-vercel-gateway

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

      @tanstack/ai-vertex

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

      @tanstack/ai-vue

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

      @tanstack/ai-vue-ui

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

      @tanstack/ai-worldlabs

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

      @tanstack/openai-base

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

      @tanstack/preact-ai-devtools

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

      @tanstack/react-ai-devtools

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

      @tanstack/solid-ai-devtools

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

      @tanstack/svelte-ai-devtools

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

      commit: d4c65d7

    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-harness92.90% (+0.04)87.48% (+0.08)93.34% (+0.04)94.46% (+0.04)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. jherr approved these changes

      Man it's cool that /goal is this straightforward.

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

    9. AlemTuzlak merged thisa8b7bf5

    10. AlemTuzlak closed this

Sign in to join this conversation.