diff --git a/INTERFACE.md b/INTERFACE.md index a3a4efca..8a4f632e 100644 --- a/INTERFACE.md +++ b/INTERFACE.md @@ -2749,7 +2749,7 @@ far as "words go in and events come back" and no further.)* The composer makes the browser the **originator** of agent mutations for the first time. Nothing today refreshes the read caches when the agent writes: -`queries.ts` defines `keys.{project,parts,build,script,properties,checks,dfm, +`queries.ts` defines `keys.{project,parts,build,script,params,properties,checks,dfm, gitStatus,gitLog,gitTags}` and a 5s project staleness, and no mutation path invalidates any of them. The blank-canvas flow would therefore end with a transcript full of successful tool calls and a rail that still says the project @@ -2759,8 +2759,11 @@ has no parts. this project — and on the prompt response, which §7A.6 already makes the authority for turn completion — the client invalidates `keys.project`, `keys.parts`, `keys.build(part)`, `keys.script(part)`, -`keys.properties(part)`, `keys.checks(part)`, `keys.dfm(part)` and -`keys.gitStatus()`. +`keys.params(part)`, `keys.properties(part)`, `keys.checks(part)`, +`keys.dfm(part)` and `keys.gitStatus()`. A slider commit that rebuilds the part +invalidates the same set (§10): Results / Checks / DFM / properties are +projections of that build, and an invalidation of only `params` + `build` +leaves those panels stale. **TIGHTENING (binds §1).** The invalidation is a **refetch of the server projection**, never a client-side merge of tool results. A composer that patched diff --git a/web/src/api/refresh.ts b/web/src/api/refresh.ts index 5c041b4f..3115c352 100644 --- a/web/src/api/refresh.ts +++ b/web/src/api/refresh.ts @@ -41,15 +41,14 @@ import { keys } from "./queries"; * The keys §7A.11 enumerates, resolved for one part. * * Exported as data so the test asserts the **list** rather than the effect of - * calling it: §7A.11 names eight keys, and a key quietly dropped from an + * calling it: §7A.11 names these keys, and a key quietly dropped from an * invalidation is a panel that quietly goes stale. * * `part === null` is the blank canvas — no part is selected, so the * part-scoped keys have no argument to resolve against. The three * project-scoped keys still fire, and they are the ones that matter in exactly * that case: `keys.parts()` is how a part the agent has just created appears in - * the tree. `keys.params` is the ninth key: §10's sliders read a projection - * §7A.11 did not name because the panel had not shipped. + * the tree. */ export function refreshKeys(part: string | null): readonly (readonly unknown[])[] { const projectScoped: readonly (readonly unknown[])[] = [ @@ -79,7 +78,7 @@ export function refreshKeys(part: string | null): readonly (readonly unknown[])[ * this function computed. * * Deliberately fire-and-forget: the caller has already rendered the turn, and a - * composer that waited for eight refetches before re-enabling its textarea would + * composer that waited for the refetches before re-enabling its textarea would * make the agent's own latency the operator's. */ export function refreshAfterTurn(client: QueryClient, part: string | null): void { @@ -87,3 +86,22 @@ export function refreshAfterTurn(client: QueryClient, part: string | null): void void client.invalidateQueries({ queryKey }); } } + +/** + * After a PARAMS slider write (§10). + * + * A rebuild dirties the same projections an agent turn does — Results, Checks, + * DFM, properties, the script snapshot, the tree. Conflict is params-only: + * nothing persisted and nothing rebuilt, so the other panels are still right. + */ +export function refreshAfterParamWrite( + client: QueryClient, + part: string, + outcome: "rebuilt" | "conflict", +): void { + if (outcome === "conflict") { + void client.invalidateQueries({ queryKey: keys.params(part) }); + return; + } + refreshAfterTurn(client, part); +} diff --git a/web/src/components/stage/ParamSliders.tsx b/web/src/components/stage/ParamSliders.tsx index 3b3c427a..686866e7 100644 --- a/web/src/components/stage/ParamSliders.tsx +++ b/web/src/components/stage/ParamSliders.tsx @@ -13,7 +13,8 @@ import { useEffect, useRef, useState } from "react"; import { useQueryClient } from "@tanstack/react-query"; import { postBuild, postParams } from "../../api/params"; -import { keys, useParams } from "../../api/queries"; +import { useParams } from "../../api/queries"; +import { refreshAfterParamWrite } from "../../api/refresh"; import { uuid7 } from "../../api/idempotency"; import type { ParamRejection, ParamRow, ParamsDocument } from "../../api/types"; import { copy } from "../../copy"; @@ -176,7 +177,7 @@ export function ParamSliders(): React.JSX.Element { rejected: [], conflict: true, })); - void client.invalidateQueries({ queryKey: keys.params(part) }); + refreshAfterParamWrite(client, part, "conflict"); return; } if (result.rejected.length > 0) { @@ -189,8 +190,7 @@ export function ParamSliders(): React.JSX.Element { return; } return postBuild(part, uuid7()).then(() => { - void client.invalidateQueries({ queryKey: keys.params(part) }); - void client.invalidateQueries({ queryKey: keys.build(part) }); + refreshAfterParamWrite(client, part, "rebuilt"); }); }) .finally(() => { diff --git a/web/test/params.test.tsx b/web/test/params.test.tsx index 5ea13f07..3efde23a 100644 --- a/web/test/params.test.tsx +++ b/web/test/params.test.tsx @@ -8,8 +8,11 @@ import { describe, expect, it } from "vitest"; import { renderToStaticMarkup } from "react-dom/server"; import type { ReactElement } from "react"; +import type { QueryClient } from "@tanstack/react-query"; import paramsJson from "./fixtures/params.json"; import type { ParamRejection, ParamsDocument } from "../src/api/types"; +import { keys } from "../src/api/queries"; +import { refreshAfterParamWrite, refreshKeys } from "../src/api/refresh"; import { controlStep, isIntegerParam, @@ -95,6 +98,38 @@ describe("G5.3 — rejected[] is verbatim, and the primitive does not clamp", () expect(message?.textContent).toContain("10"); }); + it("a successful commit invalidates the refreshKeys set, not just params+build", () => { + const invalidated: unknown[] = []; + const client = { + invalidateQueries: ({ queryKey }: { queryKey: readonly unknown[] }) => { + invalidated.push(queryKey); + }, + } as Pick as QueryClient; + refreshAfterParamWrite(client, "tread", "rebuilt"); + expect(invalidated).toEqual(refreshKeys("tread")); + expect(invalidated).toEqual( + expect.arrayContaining([ + keys.params("tread"), + keys.build("tread"), + keys.properties("tread"), + keys.checks("tread"), + keys.dfm("tread"), + ]), + ); + expect(invalidated).not.toEqual([keys.params("tread"), keys.build("tread")]); + }); + + it("a conflict re-reads params only — nothing rebuilt", () => { + const invalidated: unknown[] = []; + const client = { + invalidateQueries: ({ queryKey }: { queryKey: readonly unknown[] }) => { + invalidated.push(queryKey); + }, + } as Pick as QueryClient; + refreshAfterParamWrite(client, "tread", "conflict"); + expect(invalidated).toEqual([keys.params("tread")]); + }); + it("the number input has no min/max when clamp is off, so a typed 11 can leave", () => { const host = render( undefined} />, diff --git a/web/test/stream/composer.test.tsx b/web/test/stream/composer.test.tsx index f597b091..974bb2c2 100644 --- a/web/test/stream/composer.test.tsx +++ b/web/test/stream/composer.test.tsx @@ -189,7 +189,7 @@ describe("the chip row", () => { // §7A.11 — the read-refresh boundary describe("the read-refresh boundary", () => { - it("names the §7A.11 keys plus the PARAMS projection for a selected part", () => { + it("names the §7A.11 keys for a selected part", () => { expect(refreshKeys("tread")).toEqual([ keys.project(), keys.parts(),