Skip to content

refactor: simplify prebuilt-payload internals (post-#71 follow-up) - #86

Merged
ScriptedAlchemy merged 5 commits into
mainfrom
chore/prebuilt-simplify-followup
Aug 31, 2026
Merged

refactor: simplify prebuilt-payload internals (post-#71 follow-up)#86
ScriptedAlchemy merged 5 commits into
mainfrom
chore/prebuilt-simplify-followup

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

PR #71 merged before its deferred /simplify pass ran (the in-branch cleanup commit did land in the squash; this covers what three post-merge reviewers found beyond it). Scope: git show 28830bd5. All changes are behavior-preserving for valid configurations; the pinned manifest/path/diagnostic tests are untouched except where noted.

Findings → fixes

Finding (reviewer) Fix
Perf: the AB4750 freshness scan does a blocking synchronous full-project mtime walk (plus per-payload dist-tree walks) on every ProjectService preparation — watch rebuilds and workbench request bursts — while its info/warning diagnostics are discarded for every command except validate validateSource takes { payloadFreshness }; ProjectService passes command === 'validate'. Default true preserves the public API contract
Quality + reuse: the payload-declaration parse (string-or-{source} → nonempty → resolve → containment) was open-coded five times across discover/normalize/validate with three different malformed-input tolerances one exported payloadDeclarationEntry/payloadDeclarationSource pair in discover.ts, consumed everywhere; validatePayload keeps its own diagnostics for the malformed shapes
Reuse: the innermost-payload ownership rule existed twice — an imperative loop in prebuiltArtifactPath and a filter/sort in validatePrebuiltReference — and the validate copy used the file's local inside-or-equal containment, so the two could disagree shared owningPayload export in normalize.ts
Quality: PreparedProject.snapshotSource was optional, and the artifact-service fallback re-snapshotted without payload roots — silently recreating the always-drifted failure the closure was introduced to fix the field is required; every producer supplies the correct closure and the fallback is gone
Perf/quality trivia AB4748 probes hit one precomputed Set; one parameterized AB4748 emitter; discoverPayloads reuses fast-glob stats instead of an extra per-file stat; normalizeHook trusts the declared readonly string[] args type instead of silently filtering (validation already errors via AB4746); normalizeMcpApps derives prebuilt-ness from normalized provenance instead of re-inspecting raw config
Reuse (test-only): prebuilt-payload.test.ts re-implemented the shared project fixture migrated to createProjectFixture/removeProjectFixture

Edge-case notes (deliberate)

  • Unifying validate's payload containment onto the shared strict helper means a payload declared as the project root itself ('.') now consistently gets AB4742 instead of passing validation and then silently vanishing during normalization; likewise a prebuilt entry pointing at a payload directory is now consistently AB4744 in both validate and normalize. No test pins the old accidental behavior.
  • normalizePayloads now applies the same containment filter as discovery/validation, so a root-escaping declaration can no longer reach the normalized model through a direct normalizeProject call.

Skipped (owner context needed)

  • Symlinked project roots silently drop payload files from the project identity (payloadSourcePaths containment-checks requested-root-resolved paths against the realpath'd root; output roots solve this with component translation). Real bug candidate, needs a decision on supported semantics.
  • Replacing the stringly args[0] reverse-parse for prebuilt MCP identity with a prebuiltPath field (mirrors hooks) — perturbs canonical model digests.
  • AB4750 counting payload outputs as "newest project source" (payloads outside dist/ can flag each other as stale) — semantics change.
  • Unifying the triple payload-tree enumeration per preparation across discover/snapshot — touches snapshot identity ordering.
  • isSafePayloadName vs core/paths.isSafePathSegment — the trailing-character restriction may or may not be deliberate.

Test plan

  • pnpm build
  • pnpm typecheck (clean; pre-existing self-referencing TS2307s resolve after build)
  • pnpm lint
  • pnpm test:unit (full suite green)

Deferred /simplify pass on PR #71's merged diff, applying the reviewer
findings that survived aggregation:

- Skip the AB4750 payload-freshness mtime walk unless the operator ran
  `validate` — every dev/inspect/build preparation was paying a blocking
  full-project stat sweep whose diagnostics were then discarded.
- Extract payloadDeclarationEntry/payloadDeclarationSource in discover.ts
  and consume them from configuredPayloadRoots, discoverPayloads,
  normalizePayloads, declaredPayloads, and validatePayload, replacing five
  open-coded copies with three divergent malformed-input policies.
- Extract owningPayload and share the innermost-payload ownership rule
  between prebuiltArtifactPath and validatePrebuiltReference, which had
  drifted to inside-or-equal semantics in validate.ts.
- Make PreparedProject.snapshotSource required so the artifact-service
  fallback that silently dropped payload roots (recreating the drift bug
  the closure exists to prevent) is unrepresentable.
- Probe prebuilt references against one Set of artifact paths, share the
  AB4748 emitter, reuse fast-glob stats over per-file stat calls, trust
  the declared hook-args type instead of silently filtering, and derive
  MCP-app prebuilt-ness from normalized provenance instead of raw config.
- Migrate prebuilt-payload.test.ts onto the shared project fixture
  helpers used by the sibling suites.
@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3d2ddf

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

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 Completed 2026-08-31T17:38:18.176361Z 77a93ec PR opened
ℹ️ 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.

@pkg-pr-new

pkg-pr-new Bot commented Aug 31, 2026

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

commit: 77a93ec

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