Skip to content

Commit 5890baf

Browse files
tombeckenhamclaude
andcommitted
Merge origin/main into feat/improve-usage
Reconcile the usage-detail work with main's restructure (packages/typescript/* β†’ packages/*), shared @tanstack/openai-base adapters, summarize delegation, and the IterationCard devtools rewrite. - Drop the separate `TokenUsage` type; fold its detail fields (promptTokensDetails, completionTokensDetails, durationSeconds, providerUsageDetails) into the existing `UsageTotals`, alongside main's cost/costDetails. All references updated to `UsageTotals`. - Consolidate OpenAI-family usage extraction into @tanstack/openai-base (buildChatCompletionsUsage / buildResponsesUsage), so OpenAI, Grok, Groq and any future chat-completions/responses provider get cached + reasoning token detail. Remove the now-redundant per-adapter usage.ts for grok/openai; their end-to-end usage-extraction tests now validate the shared path. - Keep standalone-SDK helpers (Anthropic, Gemini, Ollama, OpenRouter) and wire them into main's adapters; OpenRouter merges detail with extractUsageCost. - Omit usage entirely when a provider reports none (no fabricated zeros), consistent across every finish path under exactOptionalPropertyTypes. - Port the cached/reasoning token badges from the deleted MessageCard/ MessageGroup into IterationCard. - Fix two usage-extraction tests whose `class { chat }` SDK mocks collided with the `chat` named import under useDefineForClassFields. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 parents bb8a668 + 980ff9b commit 5890baf

1,827 files changed

Lines changed: 202771 additions & 117488 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fallback-counts.json
2+
*.bak
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Lessons Index
2+
3+
Read this index every turn. Each entry below is a routing condition.
4+
If a `Use when ...` condition matches the current task, read the full lesson file.
5+
6+
<!-- LESSONS:START -->
7+
<!-- Auto-managed by self-improve plugin. Manual edits preserved between markers. -->
8+
9+
- [build-before-running-examples](lessons/2026-05-14-build-before-running-examples.md) β€” Use when starting any tanstack/ai example dev server β€” build workspace packages first
10+
- [update-skills-with-feature-work](lessons/2026-05-19-update-skills-with-feature-work.md) β€” Use when implementing a feature in tanstack/ai that touches a surface covered by an agent skill β€” the skill needs to be updated in the same PR
11+
- [update-docs-with-new-cases](lessons/2026-05-19-update-docs-with-new-cases.md) β€” Use when adding a new use case, capability, or behavior change to tanstack/ai β€” public docs that cover the surface need updating in the same PR
12+
<!-- LESSONS:END -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Self-improve plugin behavior knobs. Edit and commit per repo.
2+
correction_detection:
3+
enabled: true
4+
regex_strictness: loose # loose | strict
5+
coupling_detection:
6+
enabled: true
7+
regex_strictness: loose
8+
enforcement:
9+
pre_push_block: true # false = warn only, do not block push
10+
curation:
11+
default_interval_days: 30
12+
promotion:
13+
auto_suggest_global: true
14+
skill_improve_threshold: 3
15+
skills_repo: ~/.claude/skills
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "./coupling.schema.json",
3+
"couplings": [
4+
{
5+
"id": "ai-source-touches-agent-skills",
6+
"trigger": "packages/ai*/src/**/*.ts",
7+
"impacts": [
8+
{
9+
"target": [
10+
"packages/ai/skills/ai-core/structured-outputs/SKILL.md",
11+
"packages/ai/skills/ai-core/chat-experience/SKILL.md",
12+
"packages/ai/skills/ai-core/tool-calling/SKILL.md",
13+
"packages/ai/skills/ai-core/adapter-configuration/SKILL.md",
14+
"packages/ai/skills/ai-core/middleware/SKILL.md",
15+
"packages/ai/skills/ai-core/media-generation/SKILL.md",
16+
"packages/ai/skills/ai-core/ag-ui-protocol/SKILL.md",
17+
"packages/ai/skills/ai-core/debug-logging/SKILL.md",
18+
"packages/ai/skills/ai-core/custom-backend-integration/SKILL.md",
19+
"packages/ai-code-mode/skills/ai-code-mode/SKILL.md"
20+
],
21+
"kind": "change-required",
22+
"why": "Agent skills are a contract with downstream coding agents. When the source surface they cover changes (new public API, changed type, new pattern, removed pattern, deprecation), the skill must be updated in the same PR β€” otherwise agents reading the skill keep generating obsolete or wrong code targeting a surface that no longer exists. Use this list to decide which skill(s) cover the file you're touching: `activities/chat/**` β†’ chat-experience / structured-outputs / tool-calling; `activities/generateImage|generateAudio|generateVideo|generateSpeech|generateTranscription|summarize/**` β†’ media-generation; `middleware/**` β†’ middleware; `protocol/**` β†’ ag-ui-protocol; `adapters/**` or anything that affects the adapter contract β†’ adapter-configuration. Skip only for pure refactors / perf / internal-only changes that don't surface a new pattern or change observable behavior."
23+
}
24+
]
25+
},
26+
{
27+
"id": "ai-source-touches-public-docs",
28+
"trigger": "packages/ai*/src/**/*.ts",
29+
"impacts": [
30+
{
31+
"target": [
32+
"docs/structured-outputs/**/*.md",
33+
"docs/chat/**/*.md",
34+
"docs/tools/**/*.md",
35+
"docs/adapters/**/*.md",
36+
"docs/advanced/**/*.md",
37+
"docs/api/**/*.md",
38+
"docs/getting-started/**/*.md",
39+
"docs/protocol/**/*.md",
40+
"docs/media/**/*.md",
41+
"docs/code-mode/**/*.md",
42+
"docs/migration/**/*.md"
43+
],
44+
"kind": "change-required",
45+
"why": "Public docs are the canonical source for users. When the source surface they describe changes β€” new capability, behavior change, deprecation β€” the docs must be updated in the same PR. Cases to watch for: (1) the new behavior contradicts existing doc advice (e.g. removing a hack the doc still recommends); (2) the new capability opens a use case no existing page covers (consider whether a new page is needed, plus nav config and cross-links); (3) a public type / function gains or loses generic parameters, optional fields, etc. Run `pnpm test:docs` after editing to catch cross-link rot. Skip only for pure refactors / perf / internal-only changes."
46+
}
47+
]
48+
},
49+
{
50+
"id": "ai-source-touches-e2e-coverage",
51+
"trigger": "packages/ai*/src/**/*.ts",
52+
"impacts": [
53+
{
54+
"target": [
55+
"testing/e2e/tests/**/*.spec.ts",
56+
"testing/e2e/fixtures/**",
57+
"testing/e2e/src/lib/feature-support.ts",
58+
"testing/e2e/src/lib/types.ts"
59+
],
60+
"kind": "new-code-required",
61+
"why": "Per CLAUDE.md, every feature / bug fix / behavior change MUST include E2E test coverage. When a new public capability is added, a corresponding spec under testing/e2e/tests/ plus a fixture under testing/e2e/fixtures/ are required β€” often plus a new entry in feature-support.ts and types.ts. The full pattern is: add the Feature flag, decide provider support, optionally add a per-feature config (system prompt, schema, tools), wire it through src/routes/api.chat.ts (or the relevant route), write the fixture(s), write the spec iterating `providersFor(feature)`. Spec must run against every supported provider so non-native-streaming providers exercise the fallback path. Skip only for refactors that don't change observable behavior."
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
last_curated: 2026-05-14
2+
next_nag: 2026-06-13
3+
default_interval_days: 30
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: build-before-running-examples
3+
description: Use when starting any tanstack/ai example dev server β€” build workspace packages first
4+
tags: [monorepo, examples, dev-workflow, build]
5+
scope: repo
6+
source:
7+
type: auto-captured
8+
created: 2026-05-14T13:05:00Z
9+
related_skill: null
10+
related: []
11+
---
12+
13+
# Build Workspace Packages Before Running Examples
14+
15+
**Rule:** Run `pnpm -w run build:all` from the repo root before starting any example dev server (`examples/ts-react-chat`, `ts-solid-chat`, `ts-vue-chat`, `ts-svelte-chat`, `vanilla-chat`, `ts-group-chat`).
16+
17+
**Why:** "this was a mistake by you, you should always build packages inside of this repo before you run the examples" β€” examples import workspace packages (`@tanstack/ai`, `@tanstack/react-ai-devtools`, `@tanstack/ai-devtools-core`, etc.) via `workspace:*` and resolve through each package's `exports` field pointing at `dist/`. If `dist/` is missing for any package β€” including transitive ones β€” vite's dep-scan fails and SSR returns a 500. Fixing the first missing package one at a time wastes round-trips: I tried `pnpm --filter @tanstack/react-ai-devtools build`, hit a missing `@tanstack/ai-devtools-core`, etc. The cure is one command up front.
18+
19+
**How to apply:** Before any `pnpm --filter "<example-name>" dev` (or running an example via its own directory), run `pnpm -w run build:all` from the worktree root. Nx caches the build so re-runs are cheap. Skip only if the user has just explicitly said the workspace is freshly built.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: update-docs-with-new-cases
3+
description: Use when adding a new use case, capability, or behavior change to tanstack/ai β€” public docs that cover the surface need updating in the same PR
4+
tags: [documentation, monorepo, pr-discipline]
5+
scope: repo
6+
source:
7+
type: user-correction
8+
created: 2026-05-19T11:50:00Z
9+
related_skill: null
10+
related: [update-skills-with-feature-work]
11+
---
12+
13+
# Docs Need to Be Updated When Adding New Cases
14+
15+
**Rule:** When a PR adds a new pattern, capability, or behavior change to the public surface of any tanstack/ai package, update the corresponding doc page(s) in `docs/**` in the same PR. New cases that aren't documented don't exist for users.
16+
17+
**Why:** The user flagged this after shipping the multi-turn structured-output PR. Initial commits added the typed `StructuredOutputPart` on `useChat`'s `messages`, the schema-generic flow through `UIMessage<TTools, TData>`, and the recipe-builder pattern β€” but the docs only got updated several turns later, after the user explicitly asked. The window between "feature ships" and "docs catch up" is a window where users following the docs hit either obsolete advice (the "hide TextPart" filter hack the PR removed) or missing capability (no mention of multi-turn structured chat at all). Both are silent failures.
18+
19+
**How to apply:**
20+
21+
1. **At feature-design time**, identify which doc pages cover the surface being changed. Grep `docs/**` for the symbols, types, hooks, or patterns the feature touches. Note them as part of the implementation plan, not as follow-up.
22+
2. **For each affected doc page, decide:** does it need a correction (the feature contradicts what's written) or an addition (the feature opens a new use case)? Often both.
23+
3. **If a new use case warrants its own page**, plan the page placement / IA at feature-design time. New pages often imply nav-config updates (`docs/config.json`), a deprecation stub at the old location, and cross-link edits in adapter / API reference docs.
24+
4. **Run `pnpm test:docs` after editing** β€” the link checker catches the cross-link rot reorgs introduce.
25+
5. **Fact-check the docs** the same way as agent skills β€” dispatch a verification pass against the current source. Hallucinated APIs in docs send users down dead ends.
26+
6. **Coordinate with the related skill update** (see [[update-skills-with-feature-work]]) β€” the same surface change usually needs both, and the same fact-check pattern catches the same kinds of bugs.
27+
28+
**Heuristic for "does this PR need doc updates":** if the answer to "would a user reading the existing docs after this PR ships be misled?" is yes, the docs need updating. If the answer to "would a user benefit from knowing about the new capability?" is yes, the docs need adding to. Most non-trivial PRs hit one of those two.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: update-skills-with-feature-work
3+
description: Use when implementing a feature in tanstack/ai that touches a surface covered by an agent skill β€” the skill needs to be updated in the same PR
4+
tags: [agent-skills, documentation, monorepo, pr-discipline]
5+
scope: repo
6+
source:
7+
type: user-correction
8+
created: 2026-05-19T11:50:00Z
9+
related_skill: null
10+
related: [update-docs-with-new-cases]
11+
---
12+
13+
# Agent Skills Need to Be Updated With the Feature Work That Touches Them
14+
15+
**Rule:** When implementing a feature that changes or extends a surface covered by an agent skill under `packages/ai/skills/**` or `packages/ai-code-mode/skills/**`, update the skill in the same PR. Don't treat skill updates as a follow-up β€” they ship to coding agents that read them as authoritative.
16+
17+
**Why:** The user pointed this out after I'd already landed code, docs, e2e tests, and the example UI for the multi-turn structured-output PR (#577) without touching `ai-core/structured-outputs/SKILL.md`. The skill was still documenting the old single-slot `partial` / `final` design and still telling agents to filter `TextPart`s out of `useChat` renderers β€” the exact hack the PR removes. Without the skill update, every coding agent reading that skill would continue generating the obsolete pattern. Skills are a contract with downstream agents the same way the public API is a contract with users.
18+
19+
**How to apply:**
20+
21+
1. **Before shipping any non-trivial feature**, grep `packages/ai*/skills/**/SKILL.md` for the symbols, types, hooks, or patterns the feature touches. If any skill mentions them, that skill needs review.
22+
2. **Check both directions:** does the skill teach something the feature now makes wrong? Does the feature introduce a pattern the skill should add? Both warrant edits.
23+
3. **Update in the same PR as the feature code.** Splitting into a follow-up means the skill is stale during the window between merges β€” and during that window, agents reading the skill generate broken code that targets a surface that no longer exists.
24+
4. **After updating, fact-check the skill the same way as the docs** β€” dispatch a verification pass against the current source code. Hallucinations in skills propagate further than hallucinations in docs because agents act on them autonomously.
25+
5. **Don't forget the description / sources frontmatter** β€” `sources:` paths break silently when docs get reorganized (e.g. when `chat/structured-outputs.md` becomes a redirect stub and the real content moves to `structured-outputs/*`).
26+
27+
**Heuristic for "is this feature skill-relevant":** if the feature adds a new public API, changes the shape of a public type, deprecates a pattern, or introduces a new way of consuming an existing surface, the answer is yes. Pure refactors and internal-only changes can usually skip it.
File renamed without changes.

β€Ž.changeset/audio-activity.mdβ€Ž

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
Β (0)