Skip to content

feat(environment): render more read tools from the state and describe responses - #5352

Merged
morluto merged 4 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-coverage
Oct 21, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
earakely-scale:feat/environment-state-coverage

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Raises how much of an environment the environment-state view (#5319) renders from its state, and makes served tools say what they return. Read-only documents hold every non-entity GET read with one initial request line, identity can come from an ...Id/..._id field when no fixed name identifies the items (proved by two distinct items), single entities wrapped in a one-element array ({"posts":[{...}]}) are located, served tool descriptions summarise each tool's recorded response, and served tools carry MCP annotations. On 44 recorded captures, 1,011 of 1,277 read tools render from the state, against 625 without this change.

Refs #4933 (design discussion; scope decision requested there).

Builds on #5319, now merged; the diff against main is this change only.

Problem and expected behavior

Half of the read tools still replayed recordings: settings, configuration and other singleton reads had no place in the state unless the capture wrote them, lists keyed by orgId-style fields had no identity, Ghost-style detail responses wrap their entity in an array, and agents saw only a method and path per tool. The expected outcome is a state that covers those reads and tool descriptions an agent can choose from.

Change and scope

  • EnvironmentStateExtraction.ts: documents for every non-entity GET read with one initial request line, written or not; not-entity is retired and path-varies names a read under more than one path. Identity inference still requires listed items, as feat(environment): extract the initial state a capture's reads observed #5319 does.
  • environmentStateRules.ts: suffix identity candidates after IDENTITY_NAMES, accepted only when two items in one recording show them distinct; pointers /0 and /<member>/0 for a one-element array.
  • environmentTools.ts: a response summary per tool from its first JSON-like recorded exchange (fields of an object, an array of objects, or an envelope's list), plus the manifest's statuses, charged to the catalog reservation.
  • serveEnvironment.ts: readOnlyHint, destructiveHint, idempotentHint and openWorldHint: false per tool; the card is unchanged.
  • Not included: lossless big integers, list filters and pagination, cross-endpoint entity linking.

Follow the contribution scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the state view's extraction rules and the served tool catalog
  • Contribution scope fit and linked maintainer decision: a further agent-environment increment of [Design] Project captures into an environment manifest, serve it over streamable HTTP, export agent-environment bundles #4933; scope decision requested there
  • CLI and MCP/tool-catalog contract: inspect_analysis_view environment-state results gain document views and the path-varies reason, lose not-entity; served tool descriptions and MCP annotations change; no new tool
  • Provider, bridge, target-format, or platform compatibility: none
  • Evidence, artifact, provenance, or reconstruction contract: documents copy recorded values with their record ordinal, like entities
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable; no target interaction
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): the generated catalog picks up the updated view description; no package or installation change

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: read-only documents, suffix identity (including the two-item proof and empty first recordings), array-wrapped items with a trailing-slash Ghost-like path, the merged view's rules about non-lists, tool descriptions for object, array, enveloped and non-JSON responses and the catalog budget, and advertised annotations.
  • Real captures, outside the suite: 44 recorded captures (39 HAR, 5 browser scenario), measured on the merged code with and without this change: 1,011 of 1,277 read tools state-backed against 625 (216 item, 416 list, 379 document views against 214, 409 and 2); no-identity 216 to 32, not-entity 310 to none.
  • Remaining proof gaps: agent tokens, CPU time and peak memory were not measured; the state Evidence grows with documents (about 19% on these captures before the merge).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • On the merged tree (this branch plus feat(environment): extract the initial state a capture's reads observed #5319's branch at 6ad63bc): npm run check:fast, npm run format:check, npx knip, npm run scan:todos, npm run docs:check: passed.
  • npm run jscpd: 3.39% duplicated lines over 3362 files (gate 3.5%).
  • npx vitest run --project domain --project services: 344 files, 5914 tests passed, 5 pre-existing skips.
  • npm run build:cached, then npm run test:focused -- serve and tool-definition adapters, serve MCP and CLI boundaries, export CLI, analysis-view MCP and CLI boundaries, compact input-schema budget and two contract tests: 10 files, 98 tests passed.
  • After merging main (feat(environment): extract the initial state a capture's reads observed #5319 squashed, perf(analysis-view): reuse validated immutable captures #5349): npm run check:fast passed; npx vitest run src/domain/analysisView src/application src/server/environment src/contracts: 137 files, 1801 tests passed, 5 pre-existing skips.
  • Review round in ef49dca, after merging main (a98df6c; the only conflict was the tool contract text, both sides kept): a document whose value changed between two of its line's reads across any recorded write (e.g. GET /api/me around POST /api/orders) is recorded as fields-differ instead of publishing the post-write value, matching entities; the RFC 9110 safe methods (GET, HEAD, OPTIONS, TRACE) are now readOnlyHint and idempotentHint, so a CORS preflight tool no longer falls to the destructive default. Two new tests. tsc, module boundaries, test discovery, knip and docs:check clean; vitest over src/domain, src/application, src/contracts, src/server and src/cli: 7256 passed, 5 skipped; after test:prepare, analysis-view and environment serve/export CLI/MCP and CLI-startup boundary files (55 tests) and tests/conformance (279) passed; mcp-catalog:check passed.
  • Second review round, b4b7ebc: Greptile's wide-list finding applied as suggested (list identity candidates intersect through a set after the first recording). A further review of ef49dca, the /0 item pointers and the new tests found nothing else; the branch still merges cleanly with main. vitest over src/domain, src/application, src/contracts, src/server and src/cli: 7256 passed, 5 skipped; module boundaries clean.
  • Third review round, f6c756a, after merging main again (dbd0dce; contract text only): captured field and member names in response summaries are written as JSON strings, so a key such as "x; recorded statuses 500" no longer makes a description claim a status the tool never recorded (new test). The CI failures on b4b7ebc (tests/boundary/cli/doctorCancellation.test.ts, kuna SIGINT/SIGTERM, a runId that is not a UUID) are main's: main's own CI run on eb7acc7 fails the same two tests, and this PR touches no doctor or Kuna code. vitest over src/domain, src/application, src/contracts, src/server and src/cli: 7270 passed, 5 skipped; after test:prepare, analysis-view and environment serve/export CLI/MCP and CLI-startup boundary files (55 tests) and tests/conformance (279) passed; mcp-catalog:check and docs:check passed.
  • Fourth review round, 665112e, after merging main (19ef539; contract text only, main's Frida addition kept beside this branch's): an envelope member too long to show whole is now a JSON-quoted prefix before the truncation note, so a newline in it cannot read as more of the description (Greptile). Its test fails on f6c756a. check:fast, format, knip, todos, docs, test discovery, module boundaries and catalog passed; domain and services 7262 (5 pre-existing skips); focused boundaries 66; conformance; jscpd 3.49%.
  • Fifth review round, 87cea71, after the squash onto main (95c8c9d) and morluto's 2a926a0:
    • The squash was compared with a merge of the previous head into main at 166fb08. It keeps both sides of every conflict and drops nothing of this branch.
    • 2a926a0 settled Greptile's oversized-document finding (rendered-oversize), kept description samples within budget after JSON quoting, and refitted the two tests the squash left failing.
    • Merged main d7ca93c in 82838a5, with no conflicts. In 87cea71 the replay-only card test pins this branch's 12,818-byte card in place of main's 11,131-byte one, since the descriptions now name each tool's recorded responses.
    • Gates passed on 87cea71: check:fast, format, knip, todos, docs, discovery, module boundaries and catalog, and jscpd (3.49%). The environment, analysis-view and contract tests across the boundary, MCP, CLI, process, acceptance and conformance projects pass: 37 files.
    • npm run test:fast passes apart from unrelated tests. JavaScriptRuntimeScope.cancellation "stops Inspector target authorization after the current stat settles" fails the same way on main here (macOS). The rest are timeouts in heavy domain, adapter and composition tests, which pass when rerun alone; one worker test fails on alternate runs.

Compatibility, safety, and release

  • Changes the environment-state result vocabulary of the unreleased feat(environment): extract the initial state a capture's reads observed #5319: documents for unwritten reads, path-varies added, not-entity removed.
  • Served tool descriptions are longer (median 136 bytes added per tool on these captures) and tools carry annotations; the card's tool shape is unchanged.
  • Gates ran on Node v22.23.1; the pinned 24.18.0 is not installed on this machine.

Author readiness

Human owner: @earakely-scale

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

@earakely-scale
earakely-scale marked this pull request as ready for review October 20, 2026 04:32
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T04:32:41.314219Z aa48c74 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issue was found.

Summary

Expands environment-state coverage and describes recorded responses in the served tool catalog.

  • More recorded reads can become part of the environment state.
  • Served tool descriptions now summarize recorded JSON responses.
  • MCP tool listings now include hints about each captured method.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Recorded reads] --> B{Entity plan passes checks?}
  B -->|Yes| C[Item or list view]
  B -->|No| D{One usable initial request line?}
  D -->|No| E[Recorded replay]
  D -->|Yes| F{Changed across a write or too large?}
  F -->|Yes| E
  F -->|No| G[Document view]
  A --> H[Bounded response summary]
  H --> I[Tool catalog with MCP hints]
Loading

Reviews (11) · Last reviewed commit: "test(environment): pin the replay card t..." · Reviewed by Greptile

… responses

Keep main's environment serving and fold in coverage for non-entity reads,
response summaries, and MCP tool annotations.

Squashed rebase of morluto#5352 onto main.
@morluto
morluto force-pushed the feat/environment-state-coverage branch from 67b94b1 to 95c8c9d Compare October 21, 2026 21:34
morluto pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
…tate

Serve write tools whose later reads confirm the effect, and keep main's
state-file ownership and part-wise reply measurement.

Squashed rebase of morluto#5600 onto the rebased morluto#5352 tip.
Repository owner deleted a comment from cursor Bot Oct 21, 2026
…heir budgets

A recorded body of exponential numbers can render past 256 KiB and turn a
working read into a state size error, so that document stays a recorded replay.
Description samples are measured after JSON quoting, and the replay-fallback
catalog check uses a tool count the longer response descriptions still separate.

Co-authored-by: morluto <[email protected]>
cursor Bot pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
… responses

Keep main's environment serving and fold in coverage for non-entity reads,
response summaries, and MCP tool annotations.

Squashed rebase of morluto#5352 onto main.
cursor Bot pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
…tate

Serve write tools whose later reads confirm the effect, and keep main's
state-file ownership and part-wise reply measurement.

Squashed rebase of morluto#5600 onto the rebased morluto#5352 tip.
cursor Bot pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
… responses

Keep main's environment serving and fold in coverage for non-entity reads,
response summaries, and MCP tool annotations.

Squashed rebase of morluto#5352 onto main.
cursor Bot pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
…tate

Serve write tools whose later reads confirm the effect, and keep main's
state-file ownership and part-wise reply measurement.

Squashed rebase of morluto#5600 onto the rebased morluto#5352 tip.
earakely-scale and others added 2 commits October 21, 2026 15:33
The replay-only card test pinned main's 11,131-byte card. This branch's descriptions name each tool's recorded responses, so the card it serves is 12,818 bytes; the pin and its name follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto merged commit 2e6b38c into morluto:main Oct 21, 2026
37 of 38 checks passed
cursor Bot pushed a commit to earakely-scale/rea that referenced this pull request Oct 21, 2026
Keep served write plans and the Greptile fixes, and keep morluto#5352's
response summaries, replay-card pin, and squash note. Restore the SAZ
zero-byte member note and the state-file close notes the write squash
had dropped from main.

Co-authored-by: morluto <[email protected]>
morluto added a commit that referenced this pull request Oct 22, 2026
…tate (#5600)

* feat(environment): render more read tools from the state and describe responses

Keep main's environment serving and fold in coverage for non-entity reads,
response summaries, and MCP tool annotations.

Squashed rebase of #5352 onto main.

* fix(environment): keep rendered documents and quoted samples inside their budgets

A recorded body of exponential numbers can render past 256 KiB and turn a
working read into a state size error, so that document stays a recorded replay.
Description samples are measured after JSON quoting, and the replay-fallback
catalog check uses a tool count the longer response descriptions still separate.

Co-authored-by: morluto <[email protected]>

* feat(environment): apply evidence-gated write effects to the served state

Serve write tools whose later reads confirm the effect, and keep main's
state-file ownership and part-wise reply measurement.

Squashed rebase of #5600 onto the rebased #5352 tip.

* fix(environment): bound and validate write state history

* feat(environment): render more read tools from the state and describe responses

Keep main's environment serving and fold in coverage for non-entity reads,
response summaries, and MCP tool annotations.

Squashed rebase of #5352 onto main.

* fix(environment): keep rendered documents and quoted samples inside their budgets

A recorded body of exponential numbers can render past 256 KiB and turn a
working read into a state size error, so that document stays a recorded replay.
Description samples are measured after JSON quoting, and the replay-fallback
catalog check uses a tool count the longer response descriptions still separate.

Co-authored-by: morluto <[email protected]>

* feat(environment): apply evidence-gated write effects to the served state

Serve write tools whose later reads confirm the effect, and keep main's
state-file ownership and part-wise reply measurement.

Squashed rebase of #5600 onto the rebased #5352 tip.

* fix(environment): bound and validate write state history

* fix(environment): bound additional collection history

* fix(environment): credit sent fields, negative sequences, and encoded targets

A later overwrite copied surviving derived fields into the sent-member
claim, so a members-only check rejected an update whose sent field still
matched. Serving floored sequences at zero and stored missing history as
zero, so a collection sequence learned from negative ranks skipped the
next value. An absence after a delete forgot the resolved collection, and
an encoded read could not observe an update spelled with another
collection encoding.

Regression tests cover each case.

Co-authored-by: morluto <[email protected]>

* test(environment): cover resolved encoded update identities

* fix: validate timed update observations

* fix(environment): share write overlap and check clocks on earlier calls

Observation search skips a read begun before the write ended. That
comparison now uses the same overlap as the check path.

A clock learned on a later call was not checked against earlier calls
that kept the field. Serving would stamp those calls too, so the plan
stays unserved. A clock learned earlier is still refused when a later
call does not advance it.

Regression tests cover an overlapping empty update and a published_at
clock that one recorded call leaves unchanged.

Co-authored-by: morluto <[email protected]>

* fix: preserve partial update evidence

* fix(environment): let an unmodelled write explain only the list members that differ

A failed whole-list read now reports which members alone account for the
difference. An unmodelled write excuses the read's writes only when it came
after each such member's last check and pending writes, so an older change
elsewhere no longer hides a newer write the list shows undone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 7b6aab9d7191e600051693f2c192afcfc743d083)

* fix(environment): explain added fields, tie creates to serving's collection, and bound write descriptions

An update explains a field the entity lacked before when the observing
view had shown the entity, so a server-filled field is not dropped. A
create is tied to the held collection serving picks for its path. Write
descriptions and body refusals quote member names and sample them within
a byte bound. The request body is indexed once per explanation, so copied
and slugged fields no longer rescan it.

Replays 07aca54e onto the restacked branch. Its rule that a read begun
before a write ended teaches nothing is already here (fb6785d), so only
its test is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(environment): state how list reads weigh unmodelled writes, added update fields and quoted members

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(environment): keep the observing view helpers with the observations

shownBefore and the item-or-list fields check move to the observe module,
keeping the write effects within the line limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): resolve unmodelled writes onto the held collection

An unmodelled path kept the request's collection spelling. An archive under
the plain spelling of a collection held encoded marked only that plain
collection unknown, so a later update was blamed for the archive's fields
and dropped. Name that entity the way a modelled write does.

Co-authored-by: morluto <[email protected]>

* fix(environment): confirm no write through volatile fields or overwritten replacements, and bound the served clock

A members-only check no longer compares volatile fields, which render
from the read itself. A document replacement credits the members it
wrote or removed at its object, so a later merge that overwrites them
takes its confirmation away. A recorded time past the range of a date
gives no served clock instead of throwing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): leave unknown entities unchecked by failed reads, volatile fields and unchecked calls

A failed item read that is no absence leaves an unknown entity unknown, so
a later usable read still checks its writes. A read showing an unknown
entity again checks no write on a volatile field. An update of an unknown
entity takes its recorded outcome and adds nothing to a built plan. A later
update that does not answer with its entity is observed only by a read
whose view shows every learned clock; without one it is unmodelled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): fill a create's path fields from the collection serving selects

The gate built a later create's path fields from the recorded request path,
while serving fills them from the held collection it selects for that path,
so a read showing the other spelling's parent could confirm a create serving
cannot reproduce. Rules still learn from the recorded path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): name unmodelled writes as modelled ones, count fields updates write, and keep later members' types

An unmodelled write below an item path names its entity through itemTarget,
and one at or above a collection resolves the held collection, as modelled
writes do, so an encoded spelling no longer hides the entity it changed.
An update's answer counts the fields its rules write, other than increments,
as available, so a field only the update writes no longer makes it
incomplete-entities. A member a later call first stores keeps that call's
JSON type in the body's kinds, which the body check falls back to.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): let a document replacement overwrite everything under its object

A replacement claims only the members it wrote or removed, but it now
overwrites every earlier effect under its object, so a merge that wrote
the object it replaces loses its confirmation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(environment): start the served clock from the records whose times a date can hold

A record timed past the range of a date no longer leaves the served clock
without a start, which the store read as zero and stamped writes in 1970;
the clock starts after the latest record a date can hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: morluto <[email protected]>
Co-authored-by: morluto <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added enhancement New feature or request area: setup Setup, packaging, upgrade, install, Doctor, and client registration labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants