feat(analysis-view): project an environment manifest from web network captures (#4954)

* feat(analysis-view): project an environment manifest from web network captures

Add the environment-manifest view kind to inspect_analysis_view for retained
HAR Evidence: the primary origin's recorded request lines become a
deterministic tool surface (names, path templates, parameters with their
rule and basis, observed query names, value-free body shapes, record
pointers), with excluded groups, three fixed unknowns and the shared
projection budget. The four format rules always apply; after-uid-literal,
opaque-token and sibling-variance are opt-in and labelled, and literal
fold-in never touches a format-rule parameter. The api-surface accumulator
moves onto shared route, media-type and budget helpers without behaviour
change.

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test(web-network): check the manifest refusal text like the api-surface refusal

The real-capture verifier stringified the whole MCP result for the
environment-manifest refusal, so a declared "[" literal matched the result
envelope itself; compare the parsed refusal as the api-surface branch does.

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(specs): record the hosted web-network lane run for the manifest view

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(specs): reconcile the manifest view verification scope note with the hosted run

Refs morluto/rea#4933

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): bound body, route and name work in the environment manifest

Addresses the automated review findings on the PR: read request bodies at the
top level only instead of walking nested values; admit every literal route
part before materializing it; compare at most 32 segments in sibling-variance
and say so; keep stop words literal after a uid literal; keep the next
collision suffix per tool-name base; preserve a templated exclusion when two
groups print the same row.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): keep manifest folding, naming and media-type reads linear

Addresses the second automated review round: fold literal siblings through
set membership, key collision suffixes by the truncated name they share, and
charge a request media type before it is scanned.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): charge the manifest group key before building it

Addresses the third automated review round: the composite key copies the
method, origin, template and rules, so that copy is reserved before the key
is stringified.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): accept a +json suffix only on application media types

Addresses the fourth automated review round: `image/example+json` or
`text/example+json` no longer counts as JSON for origin selection, exclusion
or body shapes, matching the documented `application/json` and
`application/*+json` contract.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): require the capture parent's exact subject for a manifest

Addresses the fifth automated review round: the manifest cites the report
path and digest, so a parent whose subject is absent or names another path or
SHA-256 is refused at admission, as the capture view already does; the
api-surface view keeps its existing admission.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): share truncated suffix allocation work

Track suffix progress by the actual truncated prefix and suffix width. Distinct full names can collide only after suffix truncation; sharing that progress prevents quadratic rescanning while preserving shorter free names and existing allocation order.

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

* fix(analysis-view): merge only identifier-like siblings under sibling-variance

Addresses the sixth automated review finding: a bucket merged whenever one
literal carried a digit, folding plain words such as `mine` into the
parameter. The rule now partitions the bucket, merges the identifier-like
siblings and leaves the other literals as their own tools.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(analysis-view): combine qualifying sibling cohorts

Keep coded identifiers and a qualifying plural hyphenated cohort in one eligibility Set before checking the minimum merge size. Read each literal once and reuse the same membership at the consumer, preserving non-identifier routes and the three-hyphen minimum.

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

* docs(analysis-view): clarify opt-in sibling folding

State the additional sibling-variance selection in the guide, acceptance specification and MCP parameter description. Preserve the existing single-rule behavior and caller-selected inference rules.

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

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: gensokyo-dev <[email protected]>
Co-authored-by: Kaoru0822 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-19 07:07:37 +08:00
1 parent 65884350ff
commit 291059adb4
33 files changed
+4098 -363

No files matched your search

@@ -2,6 +2,7 @@ import {
analysisViewCaptureFixture,
analysisViewCaptureEvidence,
analysisViewObjectDenseCapture,
environmentManifestCaptureFixture,
} from "../../../tests/fixtures/analysisView.js";
import { describe, expect, it } from "vitest";
@@ -446,24 +447,82 @@ it("refuses an object-dense borrowed capture before making a full schema clone",
if (!recorded.ok) throw recorded.error;
const borrowed = ledger.forAnalysis(parent.evidence_id)!;
expect(Object.isFrozen(borrowed.normalized_result)).toBe(true);
const result = inspectAnalysisView(
{
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
view: { kind: "api-surface", limit: 1 },
},
(id) => ledger.forAnalysis(id),
);
expect(result).toMatchObject({
ok: false,
error: {
_tag: "AnalysisResourceConstraintError",
resource: "memory",
},
});
for (const view of [
{ kind: "api-surface", limit: 1 },
{ kind: "environment-manifest" },
] as const) {
const result = inspectAnalysisView(
{
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
view,
},
(id) => ledger.forAnalysis(id),
);
expect(result).toMatchObject({
ok: false,
error: {
_tag: "AnalysisResourceConstraintError",
resource: "memory",
},
});
}
expect(ledger.forAnalysis(parent.evidence_id)).toBe(borrowed);
});
it.each(["summary", "capture", "api-surface"] as const)(
it("seals an inferred environment manifest and a derived manifest without templated groups", () => {
const parent = analysisViewCaptureEvidence(
environmentManifestCaptureFixture(),
);
const inferred = inspectAnalysisView({
source: { kind: "inline", evidence: parent },
view: { kind: "environment-manifest", template_rules: ["opaque-token"] },
});
if (!inferred.ok) throw inferred.error;
expect(inferred.value.confidence).toBe("inferred");
expect(inferred.value.authority).toBe(parent.authority);
expect(inferred.value.evidence_links).toEqual([parent.evidence_id]);
expect(inferred.value.parameters).toMatchObject({
view: {
kind: "environment-manifest",
template_rules: ["opaque-token"],
include_query_parameter_names: true,
},
});
expect(inferred.value.normalized_result).toMatchObject({
kind: "environment-manifest",
name: "grafana-example",
parent_evidence_id: parent.evidence_id,
});
expect(parseEvidence(inferred.value)).toEqual(inferred.value);
const literal = environmentManifestCaptureFixture();
literal.artifact.sha256 = null;
literal.records = [3, 4, 8].map((ordinal) => literal.records[ordinal]!);
const derived = inspectAnalysisView({
source: { kind: "inline", evidence: analysisViewCaptureEvidence(literal) },
view: { kind: "environment-manifest" },
});
if (!derived.ok) throw derived.error;
expect(derived.value.confidence).toBe("derived");
expect(derived.value.subject).toBeNull();
expect(derived.value.normalized_result).toMatchObject({
templated_groups: 0,
tools: [{ name: "get_org" }, { name: "get_search" }, { name: "get_user" }],
limitations: expect.arrayContaining([
"Parent contains an ordinal subset; the manifest covers only retained records.",
]),
});
expect(
inspectAnalysisView({
source: { kind: "inline", evidence: analysisViewLayoutEvidence() },
view: { kind: "environment-manifest" },
}),
).toMatchObject({
ok: false,
error: { _tag: "AnalysisUnsupportedTargetError" },
});
});
it.each(["summary", "capture", "api-surface", "environment-manifest"] as const)(
"rejects inline accessors before parsing a %s view",
(kind) => {
let accessed = false;
@@ -498,7 +557,7 @@ it.each(["summary", "capture", "api-surface"] as const)(
},
);
it.each(["summary", "capture", "api-surface"] as const)(
it.each(["summary", "capture", "api-surface", "environment-manifest"] as const)(
"rejects nested, hidden and inherited inline accessors for %s",
(kind) => {
const parent = analysisViewCaptureEvidence();
@@ -575,7 +634,12 @@ it.each([
},
});
if (inherited) Object.setPrototypeOf(array, owner);
for (const kind of ["summary", "capture", "api-surface"] as const) {
for (const kind of [
"summary",
"capture",
"api-surface",
"environment-manifest",
] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: { ...parent, raw_result: array } },
view: { kind },
@@ -606,7 +670,12 @@ it("rejects callable array overrides and subclass species before parsing", () =>
Object.defineProperty([], Symbol.iterator, { value: callback }),
new CustomArray(),
])
for (const kind of ["summary", "capture", "api-surface"] as const) {
for (const kind of [
"summary",
"capture",
"api-surface",
"environment-manifest",
] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: { ...parent, raw_result: array } },
view: { kind },
@@ -619,7 +688,7 @@ it("rejects callable array overrides and subclass species before parsing", () =>
expect(invoked).toBe(false);
});
it.each(["summary", "capture", "api-surface"] as const)(
it.each(["summary", "capture", "api-surface", "environment-manifest"] as const)(
"preserves ordinary inline Evidence for %s",
(kind) => {
const parent = analysisViewCaptureEvidence();
@@ -650,7 +719,12 @@ it("rejects executable constructor values before schema plain-object checks", ()
throw new Error("Constructor metadata must remain inert");
},
});
for (const kind of ["summary", "capture", "api-surface"] as const) {
for (const kind of [
"summary",
"capture",
"api-surface",
"environment-manifest",
] as const) {
expect(
inspectAnalysisView({
source: {
@@ -678,7 +752,12 @@ it("rejects inline proxy values before reflection or parsing can run traps", ()
new Proxy(() => undefined, { get: trap }),
revoked.proxy,
])
for (const kind of ["summary", "capture", "api-surface"] as const) {
for (const kind of [
"summary",
"capture",
"api-surface",
"environment-manifest",
] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: { ...parent, raw_result: value } },
view: { kind },
@@ -717,7 +796,12 @@ it("keeps ignored array metadata inert through parsing and projection", () => {
for (let index = 0; index < 10_000; index += 1)
Object.defineProperty(array, `metadata-${index}`, { get: getter });
Object.defineProperty(array, Symbol("metadata"), { get: getter });
for (const kind of ["summary", "capture", "api-surface"] as const) {
for (const kind of [
"summary",
"capture",
"api-surface",
"environment-manifest",
] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: parent },
view: { kind },
@@ -763,15 +847,16 @@ it("keeps inline-envelope admission live alongside capture validation and groupi
it("admits raw_result and parameters before authenticating a portable capture", () => {
const dense = analysisViewObjectDenseCapture();
const parent = analysisViewCaptureEvidence();
for (const field of ["raw_result", "parameters"] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: { ...parent, [field]: dense } },
view: { kind: "api-surface" },
});
// Refuse expansion before hashing can report the deliberately stale ID.
expect(result).toMatchObject({
ok: false,
error: { _tag: "AnalysisResourceConstraintError", resource: "memory" },
});
}
for (const field of ["raw_result", "parameters"] as const)
for (const kind of ["api-surface", "environment-manifest"] as const) {
const result = inspectAnalysisView({
source: { kind: "inline", evidence: { ...parent, [field]: dense } },
view: { kind },
});
// Refuse expansion before hashing can report the deliberately stale ID.
expect(result).toMatchObject({
ok: false,
error: { _tag: "AnalysisResourceConstraintError", resource: "memory" },
});
}
});