Skip to content

build: persist compile evidence beside emitted files (#619 step 4) - #638

Merged
ScriptedAlchemy merged 6 commits into
mainfrom
feat/619-compile-evidence-record
Sep 5, 2026
Merged

build: persist compile evidence beside emitted files (#619 step 4)#638
ScriptedAlchemy merged 6 commits into
mainfrom
feat/619-compile-evidence-record

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Part of #619 — step (a) of the reordered PR 3 (owner audit, comment 17:11): persist compile evidence bound to the emitted files before any generated-JS scanner is deleted. Lands ahead of #634, which rebases onto it.

What

agent-bundle build now writes agent-bundle.compile-evidence.json at the artifact root, listed in the manifest as a generated file. For every compiled file it records:

  • output identity — the emitted path and the SHA-256 of the bytes the evidence describes;
  • external edges — every run-time load the compiler kept external (builtin or artifact-relative), with its external type, request, user request and issuer modules; an artifact-relative edge names the emitted sibling it loads (relative-file relationship);
  • inlined packages — the distinct ModuleIR.package values the compiler bundled into the file;
  • compiler / policy versionproducer (agent-bundle version, Rspack version) and policy (closed-world-externals@1, bumped when external-policy.ts changes what it permits);
  • coverage limitationscoverage.rewritable (a tools.rspack/tools.rsbuild hatch ran, so emitted bytes may differ from the module graph) and coverage.unobserved, the load forms Rslib's profile leaves verbatim (import(<expression>), require(<expression>), require.resolve(…), createRequire(…)(…), import.meta.resolve(…)), which the compiler neither bundles nor records.

agent-bundle validate --artifact re-checks the record against the manifest file table (AB6039): unreadable or non-strict record, policy mismatch, a compiled file the record does not cover, a sha256 that does not match the manifest, a recorded file the manifest does not list as a bundle, a builtin request that is not one, or an artifact-relative target the artifact lacks.

buildPackageOutputs returns the same record in process (PackageBuildResult.evidence, paths as a consumer sees them, dist/bin/<name>.js) — dist has no manifest to bind it to, and #634's AB7014 re-derivation reads it directly.

Plumbing

  • RslibSurfacePlan.finish receives the full CompileResult (externals and modules included), not just assets; compileRslibSurfaces returns { compileResults, results }. This closes gap (1) of the audit: the external/module report now reaches the emitted artifact record.
  • compileMcpApps lowers each App view's CompilationEvidence to a CompileResult through the same compileResultOf helper rslib.ts uses for surfaces, and exposes them as compileResults.
  • BuildResult.compileEvidence carries the record for in-process callers.

Not in this PR

Scanner deletion, the AB7014 re-derivation and the coverage matrix (steps b–d) stay in #634. The manifest itself is unchanged: the record is a separate root file the manifest lists, so #604's manifest work is not inflated.

Docs / changeset

docs/diagnostics.md (AB6039), docs/entry-conventions.md, website en+zh validation, architecture, targets-artifacts. One patch changeset.

Deslop

Fable-5.1-high, 7 edits: shared compileResultOf instead of a copied evidence→IR lowering in mcp-apps.ts; pathPrefix derived from the same toPosixRelative(projectRoot, outputRoot) the diagnostics use instead of a literal dist; import order in emit.ts/build.ts; redundant AB6039 message prefix removed; PackageBuildResult.evidence docblock; stray blank line; build-compose root listings and the epoch tamper test updated for the new root file.

Self-review

Reviewer: GPT-5.6 Sol (medium), full diff vs origin/main.

  1. High — compileEvidenceDiagnostics trusted the recorded kind/target: a bare request such as left-pad could claim an existing bundle as its target and pass AB6039. Fixed: every recorded external is re-judged with the build's own classifyExternal over the manifest's compiled files, and an artifact-relative target must equal the path the request resolves to from the asset. Spoofing tests added (compile-evidence.test.ts: bare request with a borrowed target, wrong target, non-compiled sibling, non-module-loading external type).
  2. Medium — malformed record reported twice (AB6039 + the generic AB6006 JSON check), hidden by an arrayContaining assertion. Fixed: validateGeneratedFiles skips the record (it has its own strict reader); the test asserts the exact diagnostic list.
  3. Docs — "kept in memory for prepack" overstated what this PR wires. Fixed: docs/diagnostics.md and website en+zh now say the package build returns the record in process (PackageBuildResult.evidence); build: AB7014 from consumer-runtime evidence (option A); gate the generated-JS walk on the compile evidence record (#619 steps b–d) #634 is the PR that reads it.

Breaking changes, changeset: none found.

Second pass — 4. High — one policy for two compilation boundaries: the re-judging accepted a built-in external on an MCP App view (views keep no externals at all) and let a node bundle claim a view as its sibling target. Fixed: an .html asset is a view and any recorded external is AB6039; node bundles are judged against the manifest's non-view compiled files. Regression tests for both; docs list the new message form.

Third pass: no remaining findings (bugs, breaking changes, tests, docs, changeset, parser/producer compatibility, manifest validation, MCP App boundary, sibling externals, API callers).

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3d377b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@638
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@638
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/rsc-markdown-stream@638
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@638

commit: 3d377b4

@ScriptedAlchemy
ScriptedAlchemy marked this pull request as ready for review September 5, 2026 18:23
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant