Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
b49177e
fix(environment): keep read-only POSTs out of the write list
earakely-scale Oct 22, 2026
d5a1fa9
fix(environment): take an entity an unplanned write made when a read …
earakely-scale Oct 22, 2026
004b064
fix(environment): plan a create into the type its returned id is read…
earakely-scale Oct 22, 2026
d8f9c05
fix(environment): end a type's initial reads at the write its reads d…
earakely-scale Oct 22, 2026
64e472a
fix(environment): replay request lines that show entities in another …
earakely-scale Oct 22, 2026
28c3ae9
docs(environment): specify and record the state-target changes
earakely-scale Oct 22, 2026
48d7fae
fix(environment): keep a read-only POST a write when its evidence is …
earakely-scale Oct 22, 2026
5d48df7
fix(environment): answer a field selection only when the state shows …
earakely-scale Oct 22, 2026
ce2301d
fix(environment): hold adopted entities and linked creates to what th…
earakely-scale Oct 22, 2026
48106e1
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 22, 2026
6656816
docs(environment): record the review fixes' measurements
earakely-scale Oct 22, 2026
22e27b1
fix(environment): release a discarded planning pass before planning a…
earakely-scale Oct 22, 2026
5702983
fix(environment): link no create whose id an earlier read showed, and…
earakely-scale Oct 22, 2026
0cf3b27
fix(environment): let the gate skip exactly the reads serving replays
earakely-scale Oct 22, 2026
096b1ca
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 22, 2026
197b1a3
docs(environment): record the second review round's checks
earakely-scale Oct 22, 2026
5e2e84c
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
0ed9e8c
fix(environment): read writes, links and creation cuts only from evid…
earakely-scale Oct 23, 2026
ed78be2
docs(environment): record the third review round's checks
earakely-scale Oct 23, 2026
c983edf
fix(environment): tie linked creates to their returned ids and order …
earakely-scale Oct 23, 2026
fa9f69c
docs(environment): record the fourth review round's checks
earakely-scale Oct 23, 2026
b8c164e
Merge commit '5d6b8a0ab' into st
earakely-scale Oct 23, 2026
f044816
Merge commit 3c5c887a2 into st
earakely-scale Oct 23, 2026
a6adf12
Merge commit '5f702dd6c^' into st
earakely-scale Oct 23, 2026
92f88a9
Merge commit 5f702dd6c into st
earakely-scale Oct 23, 2026
d04ba9d
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
294fa3c
fix(environment): keep foreign keys, stale reads and double decoding …
earakely-scale Oct 23, 2026
ce9a153
docs(environment): record the fifth review round's checks
earakely-scale Oct 23, 2026
169842b
fix(environment): compare linked sources by position, decode path fie…
earakely-scale Oct 23, 2026
e3c5b23
docs(environment): record the sixth review round's checks
earakely-scale Oct 23, 2026
a3dbf79
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
ca3eead
fix(environment): replay late and variant-only items, fill linked pat…
earakely-scale Oct 23, 2026
eb9344b
docs(environment): record the seventh review round's checks
earakely-scale Oct 23, 2026
94b8c55
fix(environment): blame a failed read on the writes whose fields it d…
earakely-scale Oct 23, 2026
fcf8d1a
fix(environment): explain unsent update changes and nested clocks by …
earakely-scale Oct 23, 2026
b1ca254
fix(environment): order collections by whole lines and sort only arra…
earakely-scale Oct 23, 2026
59439f5
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
189152d
feat(environment): serve bulk writes at a collection and target item …
earakely-scale Oct 23, 2026
147ff45
fix(environment): decide late item lines against the lines left, char…
earakely-scale Oct 23, 2026
8876143
docs(environment): record the eighth review round's checks
earakely-scale Oct 23, 2026
6037875
fix(environment): set aside response members a path mints anew on eve…
earakely-scale Oct 23, 2026
342933e
fix(environment): count only reads finished before a linked create be…
earakely-scale Oct 23, 2026
0caf400
Merge #6385 head 342933ea into feat/environment-write-rules
earakely-scale Oct 23, 2026
cfa8310
fix(environment): count a list total nested in a paging object
earakely-scale Oct 23, 2026
65ba035
fix(environment): take a created entity's nested clocks from its read…
earakely-scale Oct 23, 2026
9d0dc27
fix(environment): import the compare tool definition as a type
earakely-scale Oct 23, 2026
c567281
docs(environment): describe the new write rules and trim repeated par…
earakely-scale Oct 23, 2026
7ef08a3
fix(environment): confirm no update whose clocks or fields the eviden…
earakely-scale Oct 23, 2026
434db04
fix(environment): show pinned query and body values in the served cat…
earakely-scale Oct 23, 2026
08c2532
docs(environment): specify and record the write-rule changes
earakely-scale Oct 23, 2026
456cfdf
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
e08f003
fix(environment): keep served creates' items missing, check same-type…
earakely-scale Oct 23, 2026
e4c4940
docs(environment): record the ninth review round's checks
earakely-scale Oct 23, 2026
fd67f4f
Merge commit '0bbd635ab^' into wr2
earakely-scale Oct 23, 2026
d447349
Merge commit 0bbd635ab into wr2
earakely-scale Oct 23, 2026
391fe2c
Merge commit 'e4c494087' into wr2
earakely-scale Oct 23, 2026
1c8588a
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
6ee9703
fix(environment): link creates past empty item reads, sweep repeated …
earakely-scale Oct 23, 2026
88ee22e
docs(environment): record the tenth review round's checks
earakely-scale Oct 23, 2026
72f0442
Merge commit '88ee22e2d' into wr2
earakely-scale Oct 23, 2026
d3828d5
fix(environment): take bulk ids literally, check each recorded call's…
earakely-scale Oct 23, 2026
364891b
docs(environment): record the review fixes' checks
earakely-scale Oct 23, 2026
2c0e7bd
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 23, 2026
12e4df7
Merge remote-tracking branch 'origin/main' into wr2
earakely-scale Oct 24, 2026
5d612dc
Merge commit '2c0e7bdde' into wr2
earakely-scale Oct 24, 2026
c166a69
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 24, 2026
4e622bb
Merge commit 'c166a694e6abd7e9c3c16ae4f938d0ef9f0d8fb6' into wr2
earakely-scale Oct 24, 2026
9614465
perf(environment): compare variant lines through shared entities and …
earakely-scale Oct 24, 2026
53b2966
docs(environment): record the eleventh review round's checks
earakely-scale Oct 24, 2026
715c578
Merge commit '53b2966c5' into wr2
earakely-scale Oct 24, 2026
f151988
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
kaoru0822-kitauji Oct 24, 2026
b82e276
Merge remote-tracking branch 'origin/main' into feat/environment-writ…
kaoru0822-kitauji Oct 24, 2026
3dd85f2
perf(environment): list a type's collections only when the path's own…
earakely-scale Oct 24, 2026
f55c731
Merge remote-tracking branch 'origin/main' into st
earakely-scale Oct 24, 2026
6273d9b
Merge commit 'f55c73151' into wr2
earakely-scale Oct 24, 2026
dee4dd7
docs(environment): record the twelfth review round's checks and the s…
earakely-scale Oct 24, 2026
751af03
Merge commit 'dee4dd757a5a55f920f32c956f951ab4509c07f0' into wr2
earakely-scale Oct 24, 2026
f01215d
docs(environment): record the 50-capture sweep's wall, CPU and peak m…
earakely-scale Oct 24, 2026
3608c5a
Merge remote-tracking branch 'fork/feat/environment-state-targets' in…
earakely-scale Oct 24, 2026
5a6b4f1
Merge commit '3608c5aa2c2bd5aaa4c9786bdb9855996134e11b' into wr2
earakely-scale Oct 24, 2026
7584387
Merge remote-tracking branch 'fork/feat/environment-write-rules' into…
earakely-scale Oct 24, 2026
192db6c
chore: integrate latest main into environment write rules
gensokyo-dev Oct 24, 2026
3b66ee2
fix(environment): remove duplicate schema after main integration
gensokyo-dev Oct 24, 2026
f501e23
fix(environment): honor recorded bulk identity kinds
gensokyo-dev Oct 24, 2026
2c62bb9
fix(environment): retain scoped evidence and honor write defaults
gensokyo-dev Oct 24, 2026
352c027
test(environment): keep SDK regressions independently scoped
gensokyo-dev Oct 24, 2026
de4035a
docs(environment): record scoped write verification and measured costs
gensokyo-dev Oct 24, 2026
9942863
Merge remote-tracking branch 'origin/main' into integrate/6897-write-…
gensokyo-dev Oct 24, 2026
b3d706f
chore: merge main into environment write rules
morluto Oct 24, 2026
41aff3d
fix(environment): serve bulk writes whose response lists each entity …
earakely-scale Oct 24, 2026
a319ba1
docs(environment): measure the 50 captures at the scoped-envelope head
earakely-scale Oct 24, 2026
3fe3b0a
fix(environment): classify bulk responses and release verifier transf…
morluto Oct 24, 2026
f4bc513
fix(environment): classify and verify complete bulk responses
gensokyo-dev Oct 24, 2026
390541e
fix(javascript): retain capture context along covered mutation paths
morluto Oct 24, 2026
72ce7d6
merge: retain author bulk regressions with shared response verification
gensokyo-dev Oct 24, 2026
5ae634f
test(environment): verify bulk responses through the real MCP SDK
gensokyo-dev Oct 24, 2026
585d71c
test(environment): separate bulk response proof regressions
gensokyo-dev Oct 24, 2026
e73355e
chore: retain concurrent bulk response verification
morluto Oct 24, 2026
3e1b023
fix(environment): preserve request absence and generated value relati…
gensokyo-dev Oct 24, 2026
ac5f217
Merge commit 'e73355e1326aeaf4558d5a913596de627ae35bb2' into integrat…
gensokyo-dev Oct 24, 2026
034eed4
merge: sync main and keep its canonical JavaScript mutation analysis
gensokyo-dev Oct 24, 2026
75817ba
fix(environment): verify complete nested clocks on creates
gensokyo-dev Oct 24, 2026
5b91c99
fix(javascript): erase inline type imports before binding values
morluto Oct 24, 2026
ea64ca4
chore: sync main and retain canonical JavaScript binding fixes
morluto Oct 24, 2026
130121f
fix(environment): share complete generated value verification
gensokyo-dev Oct 24, 2026
7f01865
fix(verifiers): load the Windows source graph only when needed
gensokyo-dev Oct 24, 2026
7360127
fix(environment): validate write responses before stored clock restamps
gensokyo-dev Oct 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(environment): serve bulk writes at a collection and target item …
…actions

A DELETE, PUT or PATCH at a collection, or a POST at its delete path, whose body names
held entities by id is applied to each named entity, and serving refuses it unless every
id is held. A POST to an entity's action path that answers nothing or the entity is an
update of it; it is served only when a recorded call found each scalar it sets already
at that value. Served bulk bodies advertise their items, and compare probes pass them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 23, 2026
commit 189152d92380d4cf1c228a993625e1cc327f6d73
6 changes: 6 additions & 0 deletions docs/specs/agent-environments/state-targets/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ its cause in the recordings and the code. The five largest shared causes:
after the initial window is a variant too when it names a new shaping parameter and its object carries or lacks
members the planned lines' do not, and an item only a replayed line showed, which the state never started with,
answers with its own recording.
- **Item actions.** A write to an item path plus a literal segment that names no collection, whose calls answer nothing
or the entity (never a 201, and with every field its item read always shows), updates that entity; a scalar it
changes without sending is set on every call. It is served only once a call found every field it sets already at
that value, so a toggle is never served. An action never takes a read another write to the entity still needs.
- **Bulk writes.** A write at a type's collection whose body names entities by id, as an id array or objects carrying
the id field, deletes or updates each one; serving takes the body as recorded, a `DELETE` included.

## Acceptance

Expand Down
49 changes: 48 additions & 1 deletion docs/specs/agent-environments/state-writes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,43 @@ same root regenerates values on every read.
| `document` | `PUT`, `PATCH` or `POST` to a document view's path | that document |
| `none` | anything else | reason `no-state-target` |

**Item actions.** A `POST`, `PUT` or `PATCH` to an item path plus one literal
segment (`/{type}/{id}/archive`) is an `update` of the entity the item path
names, recorded as `address: {by: "action", segment}`, when the segment names
no collection (no state type ends in it, and it is not `delete`, `remove` or
`destroy`) and every successful call answered nothing or that entity: never a
201, and an object holding the id at the type's id field where an item read of
the type shows its entity, with every field that read always shows. A call
answering anything else made a sub-resource, as a comment `POST` does, and
stays `none`. An action's unsent change of a scalar that no other rule
explains takes the value its observation showed, a `set` rule applied on every
call (`archived: true`); a changed object, list or instant has no rule, so the
plan is `unexplained-change`. An action is served only when it sets something
and a recorded call found every field it sets already at that value, since one
change cannot tell a set from a toggle; otherwise it stays `unconfirmed`. Its
call may send no body. An action is observed in its own response, or in a
later item read only while no other tool's modelled write to the entity awaits
a check: that read then checks the other write, and the action's call is one
the gate does not model.

**Bulk writes.** A `DELETE`, `PUT` or `PATCH` at a type's
`collection_template`, or a `POST` to it plus `delete`, `remove` or `destroy`,
names its entities in its body: an array of ids of one JSON kind, or of
objects carrying the type's `id_field`, at the root or as the body's one array
member (`{"IDs": […], "Read": true}`, `[{"Id": 9}]`). Every successful call
must name them the same way, recorded as `address: {by: "ids", member, kind}`
or `{by: "elements", member}`. A path whose last segment is the type's
singular or plural (`/messages` for `/message`) writes that type. An `ids`
member applies the body's other members to every id, an element its own
members; a root id array updates nothing. Each named entity gets the effect as
an item call would, checked by the same reads; one the state does not hold
leaves the call unmodelled there. A bulk update's observation must show the
members the call sent. Serving answers any ids only when the exemplar's
response fits: no body, a body naming none of the recorded ids and holding no
number equal to how many it named (a count), or an array with one element per
id, each showing it as the first does; otherwise the reason is
`body-unusable`.

A `POST` whose path gives it no target is a `create` into the type its returned
id is read under: its exemplar's response names an id (an identity member of the
body or of an object member, or a scalar body or sole member of four characters
Expand Down Expand Up @@ -583,7 +620,17 @@ covers its arguments; otherwise it keeps the recorded page members.

**Provenance.** Write answers carry `state: {source: "state", view: "create" |
"update" | "delete", type, collection, id}`, or `{source: "state", view:
"document-write", path}`.
"document-write", path}`. A bulk answer adds `ids`, every entity it wrote in
body order, `id` naming the first.

**Bulk and action calls.** A served bulk tool takes its body as recorded (an
array of objects or of ids of the recorded kind, or an object), a `DELETE`
included, and `environment-compare` sends a probe's body to it; every id must
name an entity the state holds, else the call is refused and the state is
unchanged. A bulk
update with a `unique` or `renewed` rule writes one entity per call, since one
call draws those values once. A served item action's path names its entity
before the action segment.

**Data plane and export.**

Expand Down
14 changes: 9 additions & 5 deletions docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,10 @@ recorded lines; a line they do not reproduce keeps its recorded members.
`writes` lists one plan per tool whose request may change state, in tool
order. Its `effect` is `create` for a `POST` to a type's
`collection_template`, `update` for a `PUT`, `PATCH` or `POST` to that template
plus one trailing parameter, `delete` for a `DELETE` to it, `document` for a
`PUT`, `PATCH` or `POST` to a document's path, and otherwise `none` with reason
plus one trailing parameter, or to that item path plus one action segment,
`delete` for a `DELETE` to it, `document` for a `PUT`, `PATCH` or `POST` to a
document's path, an `update` or `delete` of each entity a write at the
collection names by id in its body, and otherwise `none` with reason
`no-state-target`. A plan is built from the tool's first successful call: its
request body must be a usable JSON object (as response bodies are usable), and
the written entity must show in that call's response or in a later read before
Expand All @@ -684,9 +686,11 @@ echo when stored as sent; a member stored differently is accepted only with its
recorded value (`body.fixed`) and stores the value the call that showed it
recorded (the `value` of its `constant` rule), and a field it changed without
sending must be a clock, a nested clock, an increment, a slug, a fresh `unique`
value, a `stamp` of the acting user or a value `derived` from the one member it
stores nowhere, or the plan is `unexplained-change`; an increment, slug, stamp
or derived value must hold for every call of the tool. A write is served only
value, a `stamp` of the acting user, a value `derived` from the one member it
stores nowhere, or for an item action a `set` of a scalar to the value it
showed, or the plan is `unexplained-change`; an increment, slug, stamp, derived
value or set must hold for every call of the tool, and an action is served
only once a call found what it sets already set. A write is served only
with the query its first call sent. Every member the first call sent is required, except by `PATCH` and
`POST` updates.

Expand Down
31 changes: 16 additions & 15 deletions src/application/environment/environmentCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
import {
collectionScope,
literalPositions,
bodyTools,
matchProbeRequest,
probeArguments,
parameterScopes,
type ProbeToolCall,
} from "./environmentCompareMatch.js";
Expand Down Expand Up @@ -52,10 +54,7 @@ import {
environmentToolAnswer,
type EnvironmentToolAnswer,
} from "./environmentToolAnswer.js";
import {
environmentToolArguments,
type EnvironmentToolDefinition,
} from "./environmentTools.js";
import { type EnvironmentToolDefinition } from "./environmentTools.js";
import { same } from "../../domain/analysisView/environmentStateRules.js";

/** One probe capture file: its label for the report and its parsed JSON. */
Expand Down Expand Up @@ -216,7 +215,7 @@ const answersCall = (
!selectsRecordedLine(call.tool, exchange, args)
)
return false;
const body = environmentToolArguments(call.tool).body;
const body = probeArguments(call.tool, run.bodies).body;
// A tool with no body parameter matches; one that takes a body matches only the body this call sent, including none.
if (body === undefined) return true;
return same(run.recordedBodies.get(exchange.ordinal), args[body]);
Expand Down Expand Up @@ -246,6 +245,8 @@ interface ProbeRun {
readonly store: EnvironmentStateStore | undefined;
/** The tools the environment offers, by name, with their input checks. */
readonly served: ReadonlyMap<string, InputCheck>;
/** The served tools that take a body their method does not, as a bulk delete names its entities. */
readonly bodies: ReadonlySet<string>;
readonly map: IdMap;
readonly normalised: Normalised;
}
Expand Down Expand Up @@ -298,22 +299,20 @@ const compareStep = (
// Matched in the environment's terms, so a tool whose path holds a seeded id literally still matches. Scopes and
// literals come from the live path: translating a parent id first would name a different collection than learning did.
const liveSegments = request.path.slice(1).split("/");
const fitted = matchProbeRequest(manifest, request);
const fitted = matchProbeRequest(manifest, request, run.bodies);
const scopes =
fitted === undefined
? undefined
: parameterScopes(fitted.tool, liveSegments);
const literals =
fitted === undefined ? undefined : literalPositions(fitted.tool);
const call = matchProbeRequest(manifest, {
...request,
path: translatePath(
request.path,
run.map,
(index) => scopes?.get(index),
(index) => literals?.has(index) === true,
),
});
const path = translatePath(
request.path,
run.map,
(index) => scopes?.get(index),
(index) => literals?.has(index) === true,
);
const call = matchProbeRequest(manifest, { ...request, path }, run.bodies);
Comment thread
earakely-scale marked this conversation as resolved.
Resolved
if (call === undefined)
return report(call, {
env_status: null,
Expand Down Expand Up @@ -460,6 +459,7 @@ export const compareEnvironment = (input: {
inputCheck(definition),
]),
);
const bodies = bodyTools(catalog.value.tools);
const recorded = parseCaptureEvidence(
operation,
input.captureValue,
Expand Down Expand Up @@ -507,6 +507,7 @@ export const compareEnvironment = (input: {
answer: environmentToolAnswer(source, store),
store,
served,
bodies,
map: new IdMap(),
normalised: emptyNormalised(),
};
Expand Down
50 changes: 50 additions & 0 deletions src/application/environment/environmentCompareBulk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it } from "vitest";

import {
timedCaptureEvidence,
type TimedCaptureRow,
} from "../../../tests/fixtures/analysisView.js";
import {
environmentServeSource,
environmentStateServeFixture,
} from "../../../tests/fixtures/environmentServe.js";
import {
BOOK_INIT_ROWS,
BOOK_NOT_FOUND,
FIRST_BOOK,
} from "../../../tests/fixtures/environmentStateWrites.js";
import { compareEnvironment } from "./environmentCompare.js";

const RECORDED: readonly TimedCaptureRow[] = [
...BOOK_INIT_ROWS,
["DELETE", "/api/books", [{ id: 2 }], 200, [{ id: 2 }]],
["GET", "/api/books/2", BOOK_NOT_FOUND, 404],
["GET", "/api/books", [FIRST_BOOK]],
];

describe("environment comparison of bulk writes", () => {
it("sends a probe's bulk delete body to the served tool, which answers it from the state", () => {
const fixture = environmentStateServeFixture(
timedCaptureEvidence(RECORDED),
);
const report = compareEnvironment({
source: environmentServeSource(fixture),
captureValue: fixture.capture,
probes: [
{
label: "bulk-delete",
value: timedCaptureEvidence([
["GET", "/api/books/1", FIRST_BOOK],
["DELETE", "/api/books", [{ id: 1 }], 200, [{ id: 1 }]],
["GET", "/api/books/1", BOOK_NOT_FOUND, 404],
]),
},
],
operation: "environment-compare",
});
if (!report.ok) throw report.error;
const [, deleted, read] = report.value.probes[0]!.results;
expect(deleted).toMatchObject({ env_status: 200, equal: true });
expect(read).toMatchObject({ env_status: 404, equal: true });
});
});
31 changes: 28 additions & 3 deletions src/application/environment/environmentCompareMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import type {
EnvironmentManifest,
EnvironmentManifestTool,
} from "./environmentSource.js";
import { environmentToolArguments } from "./environmentTools.js";
import {
environmentToolArguments,
type EnvironmentToolDefinition,
} from "./environmentTools.js";

const FORMAT_RULES: ReadonlySet<string> = new Set([
"numeric",
Expand Down Expand Up @@ -136,10 +139,32 @@ const fitOf = (
return { tool, literals };
};

/** The tool of the request's method whose template fits the path with the most literal segments; the manifest's order breaks ties. */
/** A tool's arguments as the served catalog offers them: a body too when `bodies` names it. */
export const probeArguments = (
tool: EnvironmentManifestTool,
bodies: ReadonlySet<string>,
) => environmentToolArguments(tool, bodies.has(tool.name) ? true : undefined);

/** The served tools whose catalog takes a body, by name, as a bulk delete names its entities in one. */
export const bodyTools = (
definitions: readonly EnvironmentToolDefinition[],
): Set<string> =>
new Set(
definitions.flatMap((definition) =>
Object.hasOwn(
definition.inputSchema.properties,
environmentToolArguments(definition.tool, true).body!,
)
? [definition.name]
: [],
),
);

/** The tool of the request's method whose template fits the path with the most literal segments; the manifest's order breaks ties. `bodies` names the tools a served catalog gives a body beyond their method's. */
export const matchProbeRequest = (
manifest: EnvironmentManifest,
request: ProbeRequest,
bodies: ReadonlySet<string> = new Set(),
): ProbeToolCall | undefined => {
const segments = request.path.slice(1).split("/");
let best: Fit | undefined;
Expand All @@ -154,7 +179,7 @@ export const matchProbeRequest = (
}
if (best === undefined) return undefined;
const { tool } = best;
const names = environmentToolArguments(tool);
const names = probeArguments(tool, bodies);
const args: Record<string, JsonValue> = {};
const pathArguments: string[] = [];
for (const param of tool.params) {
Expand Down
10 changes: 8 additions & 2 deletions src/application/environment/environmentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
} from "./environmentSource.js";
import { STATE_INTAKE_LIMIT_BYTES } from "./environmentStateDocument.js";
import { initialStateBytes } from "./environmentStateStore.js";
import { describeWrite } from "./environmentStateWriteDescription.js";
import {
describeWrite,
writeBody,
} from "./environmentStateWriteDescription.js";
import {
environmentToolDefinitions,
type EnvironmentDataPlane,
Expand Down Expand Up @@ -101,7 +104,10 @@ export const servedCatalog = (
dataPlane,
...(state === undefined
? {}
: { describe: (tool) => describeWrite(state.writes.get(tool.name)) }),
: {
describe: (tool) => describeWrite(state.writes.get(tool.name)),
body: (tool) => writeBody(state.writes.get(tool.name)),
}),
},
);
return tools.ok ? ok({ tools: tools.value, dataPlane }) : tools;
Expand Down
6 changes: 5 additions & 1 deletion src/application/environment/environmentStateAnswer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export type StateProvenance =
readonly type: string;
readonly collection: string;
readonly id: string;
/** Every entity a bulk call wrote, in body order; `id` is the first. */
readonly ids?: readonly string[];
};

/** A replay answer that also says whether the state or a recording produced it. */
Expand Down Expand Up @@ -206,12 +208,14 @@ export interface ItemCall {
readonly id: string;
}

/** What an item call names, or undefined when a path argument is missing. */
/** What an item call names, or undefined when a path argument is missing; an item action's id comes before its action segment. */
export const itemCall = (
tool: EnvironmentManifestTool,
args: ReplayArguments,
action = false,
): ItemCall | undefined => {
const segments = callSegments(tool, args);
if (action && segments?.pop()?.supplied !== false) return undefined;
const last = segments?.pop();
return segments !== undefined && last?.supplied === true
? { segments, id: last.text }
Expand Down
Loading