feat(01KVTB3Z): resolve each target repo's own build toolchain structurally instead of hardcoding pnpm at plugins/flow#441
Merged
Conversation
…urally instead of hardcoding pnpm at plugins/flow Add resolve-project-toolchain.ts: one resolver consumed by BOTH the dev pre-PR build/test/bloat gates and the reviewer's vitest runner, so they agree on where and how to build/test any target repo. Resolution order: (1) optional .flow/ config.yaml build: block (escape hatch, zod-validated, typed ToolchainConfigError on a bad packageManager); (2) structural build-home detection (pnpm-workspace member owning a build script, else nearest package.json with a build script, else repo root); (3) package-manager detection by lockfile at the resolved cwd. The Flow dogfood path no longer depends on the gitignored .flow/config.yaml: structural detection alone resolves pnpm + plugins/flow for the crew repo on a clean worktree. An external npm repo resolves to npm + repo root with the bloat (knip) gate skipped when no dead-code check applies. run-reviewer-session.ts aligns its vitest invocation to the resolved toolchain (local node_modules/.bin/vitest first, else the package manager's run command) while preserving the findPackageRoot re-export and leaving find-package-root.ts intact. Claude-Session: https://claude.ai/code/session_01E5VyKQMGJSL6fRfRmCzuvs
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Flow's Stage-1 pre-PR build/test/bloat gates and the reviewer's vitest runner were hardcoded to assume the target IS the Flow repo: a pnpm monorepo rooted at
plugins/flow. Run Flow against any external repo (an npm project with noplugins/dir) and the pre-PR build gate failed before a PR could open — the dev's only escape was fabricating a fakeplugins/flow/package, contaminating the target.This adds one toolchain resolver —
plugins/flow/mcp-server/src/lib/resolve-project-toolchain.ts— consumed by both the dev pre-PR gates and the reviewer test runner, so they agree on where and how to build/test any target repo.Resolution order
.flow/config.yamlhas abuild:block, it is zod-validated and itspackageManager/cwd/buildCmd/testCmd/knipCmdwin over structural + lockfile detection. An unrecognisedpackageManagerraises a typedToolchainConfigError(no silent fallback).pnpm-workspace.yamlmember whose package.json owns abuildscript; else the nearest package.json (root downward) with abuildscript; else the repo root.pnpm-lock.yaml→pnpm,package-lock.json→npm,yarn.lock→yarn,bun.lockb→bun, default npm (flaggedpmAssumed).Returns
{ packageManager, cwd, buildCmd, testCmd, knipCmd | null, pmAssumed, source }.knipCmdisnull(bloat gate skipped) when nobuild.knipCmd, noknipscript, and no knip config apply.How each AC is met
runProjectBuild/runProjectTestsrunnpm run build/npm testat the REPO ROOT;runProjectBloatCheckis a no-op (skipped: true, no subprocess) becauseknipCmdis null. No fabricatedplugins/flow/and no straypnpm-lock.yaml. Covered inrun-project-build-toolchain.test.ts+resolve-project-toolchain.test.ts.build:block overrides structural + lockfile detection (incl. a partial block that overrides onlypackageManagerbut still derives the structural cwd).build:block (badpackageManager, unknown field) raisesToolchainConfigErrorrather than falling back..flow/config.yamlis gitignored, so it does NOT reach a clean checkout or a per-story worktree. Structural detection alone resolvespackageManager=pnpmandcwd=plugins/flowfor the crew repo, purely from the on-diskplugins/flow/pnpm-workspace.yaml+pnpm-lock.yaml+ theplugins/flowpackage.json'sbuildscript — verified against the REAL repo root on this clean worktree (no.flow/config.yamlpresent), and inresolve-project-toolchain.test.ts's Flow-shaped fixture.Reviewer alignment
run-reviewer-session.ts'srunVitestCheckno longer hardcodespnpm vitest. It resolves the vitest binary from the package root'snode_modules/.bin/vitestfirst, else the resolved package manager's run command (resolveVitestInvocation). ThefindPackageRootre-export is preserved (the discipline validator depends on it) andlib/find-package-root.tsis untouched.Flow dogfood path unchanged
The dev pre-PR gate and reviewer still build/test at
plugins/flowwith pnpm — now via the structural resolver rather than a hardcode. Existing pre-PR-gate / reviewer-vitest tests were re-pointed (Flow-shaped fixtures seeded so the resolver lands on the same place).FLOW_REPO_DISK_SENTINELinwrite-native-story.tswas left untouched (out of scope).Checks
dist/index.js+dist/cli.jsrebuilt.https://claude.ai/code/session_01E5VyKQMGJSL6fRfRmCzuvs