Repository navigation
feat(analysis-view): project an environment manifest from web network captures #4954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
morluto
merged 18 commits into
morluto:main
from
earakely-scale:feat/environment-manifest-view
Oct 18, 2026
+4,096
−361
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
61d3536
feat(analysis-view): project an environment manifest from web network…
earakely-scale 2d95597
test(web-network): check the manifest refusal text like the api-surfa…
earakely-scale 6cb38b5
docs(specs): record the hosted web-network lane run for the manifest …
earakely-scale b6d18d2
docs(specs): reconcile the manifest view verification scope note with…
earakely-scale 44203ec
fix(analysis-view): bound body, route and name work in the environmen…
earakely-scale bfe5a36
fix(analysis-view): keep manifest folding, naming and media-type read…
earakely-scale 71d7513
fix(analysis-view): charge the manifest group key before building it
earakely-scale 2679323
fix(analysis-view): accept a +json suffix only on application media t…
earakely-scale 692453b
chore: merge main into environment manifest review
gensokyo-dev f73af11
fix(analysis-view): require the capture parent's exact subject for a …
earakely-scale d6cb57e
fix(analysis-view): share truncated suffix allocation work
gensokyo-dev 99be275
chore: incorporate environment manifest review updates
gensokyo-dev dd87f54
fix(analysis-view): merge only identifier-like siblings under sibling…
earakely-scale ef47ead
chore: update environment manifest review from main
gensokyo-dev 252b55d
fix(analysis-view): combine qualifying sibling cohorts
gensokyo-dev f2c3456
chore: refresh environment manifest validation from main
gensokyo-dev adbbbe5
docs(analysis-view): clarify opt-in sibling folding
gensokyo-dev 494e015
chore: merge main (d1adc607) into the environment manifest view branch
earakely-scale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Implementation plan | ||
|
|
||
| 1. Lift the api-surface accumulator's shared pieces into | ||
| `webNetworkRouteTemplates.ts` (format rules, media-type essence, request-line | ||
| and query-name readers, route scanning, byte allowances) and an abstract | ||
| `WebNetworkProjectionAccumulator` (retained/temporary budget, admission, | ||
| limitations) with `admitHarCaptureParent` for the shared parent guards, so | ||
| both grouping views own one interpretation. | ||
| 2. Add `environmentManifestRules.ts` as pure functions: the opt-in template | ||
| rules, re-bucketing and sibling merging, parameter naming, path templates and | ||
| deterministic tool names. | ||
| 3. Add `EnvironmentManifestAccumulator.ts`: per-record pointers, group state, | ||
| primary-origin selection, body-shape inference through `inferJsonShape`, | ||
| exclusion reasons, fixed unknowns and the finished manifest fields. | ||
| 4. Add `environmentManifestView.ts` with the strict request schema (defaults | ||
| applied in the echoed view), the result fields and the projector; register | ||
| the kind first in `projectAnalysisView`, extend the result union and | ||
| `UnsignedAnalysisView`, and wire the accumulator and confidence rule in | ||
| `AnalysisViewService`. | ||
| 5. Publish the `inspect_analysis_view` description and a fixture-generated | ||
| example; port the Grafana-shaped HAR into a source-owned TypeScript builder. | ||
| 6. Cover domain, accumulator budget, service, MCP boundary, CLI boundary and | ||
| acceptance behavior; extend the real-capture verifier; document the view in | ||
| the capture guide, the contracts reference and the authored skill. | ||
|
|
||
| No new tool, provider, side effect or network activity is introduced. The | ||
| manifest is a projection of already retained Evidence; replaying or serving it | ||
| is deferred. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Environment manifest view from web network captures | ||
|
|
||
| Issue: https://github.com/morluto/rea/issues/4933 | ||
|
|
||
| ## Outcome | ||
|
|
||
| `inspect_analysis_view` accepts `view: {"kind": "environment-manifest"}` for | ||
| retained HAR Evidence and projects the primary origin's recorded request lines | ||
| into a replayable tool surface: deterministic tool names, path templates, | ||
| parameters, observed query names, value-free body shapes, status and | ||
| content-type sets and record pointers, with excluded groups, three fixed | ||
| unknowns and the shared projection representation budget. This increment adds | ||
| the view kind only; serving and exporting an agent environment from the | ||
| manifest are later increments. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Accept only `inspect_web_network_capture` HAR parents; refuse native | ||
| mitmproxy, SAZ and qlog parents, and parents whose Evidence does not record | ||
| `sensitive_value_count: 0`, with the same typed unsupported errors as the | ||
| api-surface view. | ||
| - Without opt-in rules, every tool template must equal the api-surface template | ||
| of the same group; the four format rules always apply with `basis: inferred`. | ||
| - Apply `after-uid-literal`, `opaque-token` and `sibling-variance` only when | ||
| listed, each at most once, in that order, folding literal siblings of an | ||
| opt-in templated position into observed values whichever was recorded first, | ||
| never folding a literal into a format-rule parameter and never templating a | ||
| stop word; `sibling-variance` compares routes of at most 32 segments and the | ||
| manifest states when a route exceeded that. | ||
| - Derive tool names from the method and route literals deterministically, at | ||
| most 60 characters, unique within one manifest. | ||
| - Derive `body_shape` for `POST`, `PUT` and `PATCH` from the tool's earliest | ||
| record when it carries a JSON-typed request body, as top-level key types | ||
| only without walking nested values; copy no header, cookie, query or body | ||
| value anywhere in the result. | ||
| - List records as pointers (`ordinal`, `method`, `path`, `status`, | ||
| `content_type`) and excluded groups with reason `other-origin`, | ||
| `ui-page-or-asset` or `non-json`. | ||
| - Mark the Evidence inferred whenever any tool or excluded group is templated, | ||
| derived otherwise; keep the parent's authority. | ||
| - Admit the capture clone, the inline envelope, every retained pointer, group, | ||
| route part, observed value, query name and body-shape key before allocation, | ||
| and charge body parsing as temporary bytes, within the existing 96 MiB budget. | ||
|
|
||
| ## Acceptance and limits | ||
|
|
||
| A source-owned Grafana-shaped HAR fixture (28 recorded exchanges on two | ||
| origins) drives domain, service, MCP, CLI and acceptance coverage. Without | ||
| rules the templates equal the api-surface grouping; with all three rules the | ||
| fixture yields `/api/dashboards/uid/{uid}`, `/api/folders/{uid}` folding | ||
| `general`, `/api/plugins/{plugin_id}/settings` and | ||
| `/api/datasources/uid/{uid}/health`. A published contract example is | ||
| reproduced byte-for-byte from fixture bytes through the real decoder and view | ||
| service. The view performs no network activity and replays nothing; it does | ||
| not establish handler identity, schemas, authorization or state transitions. | ||
|
|
||
| ## Deferred issue criteria | ||
|
|
||
| Serving a manifest over streamable HTTP, exporting an agent environment from a | ||
| manifest and the hosted verification lane are later independent increments of | ||
| #4933. This PR must reference rather than close the whole issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Tasks | ||
|
|
||
| - [x] Record the view contract, requirements and deferred increments. | ||
| - [x] Factor shared route, media-type and budget helpers out of the api-surface | ||
| accumulator without changing its behavior. | ||
| - [x] Implement the opt-in template rules, naming and manifest accumulator. | ||
| - [x] Register the `environment-manifest` kind, result schema, service wiring and | ||
| confidence rule. | ||
| - [x] Port the Grafana-shaped HAR fixture and publish a reproducible example. | ||
| - [x] Add domain, service, MCP, CLI and acceptance coverage. | ||
| - [x] Document the view in the capture guide, contracts reference and skill. | ||
| - [x] Run static, formatting, duplication, documentation and test gates. |
165 changes: 165 additions & 0 deletions
165
docs/specs/agent-environments/manifest-view/verification.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Verification | ||
|
|
||
| Verified base: 18aa9af2b2c26fd114113dd39528a91224801840 (fetched main). | ||
|
|
||
| Executed on the implementation worktree after `npm ci`, `npm run build` and | ||
| `npm run test:prepare`; every check below ran as written in this pass. The | ||
| built-group projects and the built-CLI checks ran against a `dist/` rebuilt | ||
| after the last source change. | ||
|
|
||
| - `npm run check:fast`: typecheck and lint passed (2 tasks successful). | ||
| - `npm run format` then `npm run format:check`: all 4028 matched files use the | ||
| correct format. | ||
| - `npx knip`: ok (exit 0, no unused files, exports or dependencies reported). | ||
| - `npm run check:ci:tasks`: typecheck, lint:built (3730 files, 0 errors), format:check, knip, | ||
| metadata:check, jscpd (3.35% duplicated lines over 3140 files and 2581 | ||
| clones, under the 3.5% gate) and the tech-debt marker scan passed (8 tasks, | ||
| 3 replayed from this worktree's cache). | ||
| - `npm run docs:check`: the six built documentation checks and the README | ||
| consistency conformance test (5 tests) passed; no tracked generated file | ||
| changed. | ||
| - `npx vitest run --project domain --project services` (full source group): | ||
| 312 files, 5412 tests passed, 3 pre-existing skips. | ||
| - `npx vitest run --project cli-boundary` (full project): 111 files; 659 tests passed, 2 | ||
| pre-existing skips, 8 failed in three files that drive no analysis-view | ||
| command (`closedStdout`, `commandFinalizationCancellation`, | ||
| `javascriptApplicationJsonOutput`). Re-run in isolation on this worktree the | ||
| three WASM interrupt cases and the four JavaScript JSON-output cases passed | ||
| and only `closedStdout` "stops quietly when the reader closes during streamed | ||
| JSON" (`inspect-sqlite-database`) exited 1 instead of 141. The same three | ||
| files run on a clean export of 18aa9af2 (`git archive`, fresh `npm ci`, | ||
| `npm run build`, `npm run test:prepare`, nothing from this slice) reproduced | ||
| exactly that one failure and passed the other 16, so none of the eight is | ||
| attributable to this slice and none was changed here. | ||
| - `npx vitest run --project mcp-boundary` (full project): 153 files passed, 2 | ||
| pre-existing file skips; 901 tests passed, 7 pre-existing skips, no failures. | ||
| - `npx vitest run --project acceptance` (full project): 123 files passed, 1 | ||
| pre-existing file skip; 608 tests passed, 13 pre-existing skips, no failures. | ||
| - Built CLI end-to-end on the 28-record Grafana-shaped capture: | ||
| `inspect-web-network-capture ... har --format json` then | ||
| `inspect-analysis-view` with `environment-manifest`, with and without the | ||
| three opt-in rules, and with `api-surface`, twice each. Without rules the 22 | ||
| tool templates plus the 3 primary-origin exclusions equal the 25 api-surface | ||
| groups on that origin and every `path_template` equals its | ||
| `api_surface_template`; with rules `/api/dashboards/uid/{uid}`, | ||
| `/api/folders/{uid}` (observed values `fg1jo91e57e2ob` and `general`, records | ||
| 12 and 13), `/api/plugins/{plugin_id}/settings` and | ||
| `/api/datasources/uid/{uid}/health` appear across 19 tools with 13 templated | ||
| groups; `normalized_result` and `evidence_id` are identical across the two | ||
| runs of each view; records carry only pointer keys; no recorded body or query | ||
| value appears; three unknowns and `view_digest` are present; confidence is | ||
| `inferred` with authority `historical-reference`. | ||
| - Built CLI on the same capture extended with `GET /api/teams/search` and | ||
| `GET /api/teams/mine` (30 records), all three rules selected: | ||
| `/api/teams/{numeric}` keeps observed value `1` only and `get_teams_search` | ||
| and `get_teams_mine` stay their own tools; 21 tools, 13 templated groups. | ||
|
|
||
| ## Independent review | ||
|
|
||
| Findings repaired at their owning boundary: | ||
|
|
||
| 1. A `__proto__` key in a recorded JSON body became a prototype rather than an | ||
| own property, and the schema clone then dropped it silently. The manifest | ||
| accumulator builds body shapes with `Object.fromEntries`, omits that key and | ||
| states the omission as a limitation; a domain regression covers it. | ||
| 2. The contract example carried a readonly tuple that the mutable JSON example | ||
| type rejects; the example keeps a literal-typed mutable tuple. | ||
| 3. Folding a literal sibling into an already templated position took the parts | ||
| of the earliest group, so a literal recorded before the token kept its | ||
| literal, dropped the parameter and claimed the token's record under a | ||
| template it does not match. `mergeGroups` now takes the templated group as | ||
| the shape for parts while the earliest group still names | ||
| `api_surface_template`, `body_shape` and record order; a domain regression | ||
| with the literal recorded first covers it. | ||
| 4. The request-body parse accepted `text/plain` and `text/markdown` bodies; it | ||
| accepts only `application/json` and `application/*+json`, and the capture | ||
| guide states the earliest-record rule; a domain test covers both media | ||
| types. | ||
| 5. A repeated entry in `template_rules` was accepted, echoed and hashed into | ||
| `view_digest` while the accumulator deduplicated it; the request schema | ||
| refuses repeats with `template_rules must not repeat a rule`. | ||
| 6. The sibling-variance fold-in absorbed a non-conforming literal into a | ||
| parameter produced by one of the four format rules, so `/api/teams/mine` | ||
| became an observed value of `/api/teams/{numeric}` and the published rule no | ||
| longer described every observed value. Fold-in is restricted to parameters | ||
| produced by the opt-in rules; literal siblings of a format-rule parameter | ||
| stay their own tools or merge among themselves under `sibling-variance` | ||
| only when identifier-like. A domain test with `/api/teams/1`, | ||
| `/api/teams/2`, `/api/teams/search` and `/api/teams/mine`, the capture | ||
| guide and the spec state the rule; the built-CLI check above exercises it. | ||
|
|
||
| ## Hosted lane | ||
|
|
||
| - `real-web-network-captures` (hosted ubuntu-24.04, workflow run | ||
| https://github.com/earakely-scale/rea/actions/runs/39097105064 on the fork | ||
| at 2d95597f) passed with the manifest block of | ||
| `scripts/verify-web-network-captures.mjs` executed against the lane's | ||
| producer and mitmproxy captures. The first run at 61d35369 failed only in | ||
| that block: the refusal check stringified the whole MCP result, so the | ||
| declared `[` literal matched the result envelope; the follow-up compares the | ||
| parsed refusal as the api-surface branch does. | ||
|
|
||
| ## Scope and measurement limits | ||
|
|
||
| macOS `/usr/bin/time -l`, command accounting only: `npm run check:fast` | ||
| reported 5.23 seconds elapsed, 24.20 user and 2.92 system seconds, and | ||
| 4449140736 bytes maximum RSS; `npm run format` 0.74 seconds elapsed, 4.14 | ||
| user and 0.73 system seconds, and 223363072 bytes maximum RSS; | ||
| `npm run format:check` 0.66 seconds elapsed, 4.03 user and 0.61 system | ||
| seconds, and 218759168 bytes maximum RSS; the full source group reported | ||
| 25.10 seconds elapsed, 67.26 user and 2.72 system seconds, and 2659172352 | ||
| bytes maximum RSS; `npx knip` 3.68 seconds elapsed, 5.24 user and 0.70 system | ||
| seconds, and 865599488 bytes maximum RSS; `npm run check:ci:tasks` 4.65 | ||
| seconds elapsed, 15.03 user and 4.36 system seconds, and 843333632 bytes | ||
| maximum RSS; `npm run docs:check` 3.61 seconds elapsed, 3.81 user and 0.99 | ||
| system seconds, and 289472512 bytes maximum RSS; the full `cli-boundary` | ||
| project 425.66 seconds elapsed, 703.52 user and 206.77 system seconds, and | ||
| 630456320 bytes maximum RSS; the full `mcp-boundary` project 164.19 seconds | ||
| elapsed, 302.85 user and 47.08 system seconds, and 4457529344 bytes maximum | ||
| RSS; the full `acceptance` project 960.25 seconds elapsed, 1520.91 user and | ||
| 520.68 system seconds, and 800063488 bytes maximum RSS. `npx knip` ran while | ||
| the `cli-boundary` project was executing, and the clean 18aa9af2 export's | ||
| `npm ci`, build and test preparation overlapped the `mcp-boundary` and | ||
| `acceptance` runs, so those elapsed figures include host contention. Token usage and full process-family peak are | ||
| unmeasured. Local real-tool verification ran on macOS arm64; the hosted Linux lane result is recorded above. | ||
|
|
||
| ## Automated review findings on the PR (2026-10-18) | ||
|
|
||
| Codex and Greptile left seven inline findings on morluto/rea#4954 at | ||
| b6d18d23; each was checked against the code and addressed in one follow-up | ||
| commit, with a regression test where the behaviour is observable: | ||
|
|
||
| - Body shapes walked nested values (both reviewers, P1): `#bodyShape` passed | ||
| the text to `inferJsonShape`, whose per-node path copies grow with the square | ||
| of depth, so a small deeply nested body could exceed the budget it had | ||
| reserved. The reader now parses once and reads top-level key types from the | ||
| parsed object; a test feeds a 2,500-level nested body and gets the four | ||
| top-level types back. | ||
| - Literal route parts were not admitted (Codex, P2): a path of many short | ||
| literal segments materialized one part object per segment without a charge. | ||
| Every route part is now charged before the group is created; a test shows a | ||
| 5,000-segment path refused under a 1 MiB budget while a 100-segment path is | ||
| retained. | ||
| - `sibling-variance` rebuilt a key over the whole route at every position | ||
| (Greptile, P1): routes longer than 32 segments are no longer compared, the | ||
| manifest states it in a limitation, and a test shows two 39-segment siblings | ||
| left unmerged beside a merged short pair. | ||
| - `after-uid-literal` templated stop words (Greptile, P1): the rule now skips | ||
| them; a test keeps `/api/items/uid/search` literal beside | ||
| `/api/items/uid/{uid}`. | ||
| - Tool-name suffixes restarted at 2 on every collision (Greptile, P2): the | ||
| registry keeps the next suffix per base; a test projects 300 dotted literals | ||
| into `get_item` and `get_item_2` through `get_item_300`. | ||
| - An exclusion row could lose its templated flag when two groups printed the | ||
| same row (Codex, P2): the flag is now the logical or of both. The scenario | ||
| needs a literal segment spelled `{numeric}`, which the WHATWG URL parser | ||
| percent-encodes in recorded paths, so no capture reaches it; the one-line | ||
| defence is kept without a test. | ||
|
|
||
| Checks after the change: `oxfmt --check .` clean; `tsc --noEmit` clean; | ||
| `npm run lint` and `verify:module-boundaries` clean (the complexity warnings | ||
| on `#append` predate the change); `npx knip` no findings; `npm run jscpd` | ||
| 3.35 % duplicated lines; `scan:todos` none; `verify:test-discovery` 1,580 | ||
| files once; `vitest run` over the view, accumulator, JSON-shape and contract | ||
| example tests 32 passed in 4 files; `vitest run` over the service, CLI and | ||
| MCP boundary tests for analysis views 73 passed in 3 files. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.