Skip to content

fix: monorepo-aware setup commands and domain discovery improvements#67

Merged
LadyBluenotes merged 4 commits intomainfrom
fix/address-alem-feedback
Mar 11, 2026
Merged

fix: monorepo-aware setup commands and domain discovery improvements#67
LadyBluenotes merged 4 commits intomainfrom
fix/address-alem-feedback

Conversation

@KyleAMathews
Copy link
Collaborator

Summary

  • edit-package-json and add-library-bin now auto-detect monorepo roots and apply to all workspace packages that contain SKILL.md files, fixing the issue where only the root package.json was modified
  • Domain discovery skill now reads all in-repo docs before interviewing and distinguishes factual questions (search the codebase) from judgment questions (ask the maintainer)

Root Cause

When a library maintainer ran npx @tanstack/intent edit-package-json from a monorepo root, the command operated on process.cwd() only — modifying the root package.json instead of each workspace package's package.json. This meant "skills" and "bin" were never added to the individual packages, so npm publish excluded the skills directories entirely.

Separately, the domain-discovery skill's hard rules enforced interactive interviews so strictly that the agent would ask factual questions ("are there other backward compat middlewares?") instead of just grepping the codebase. And Phase 1 only read README + quickstart, not the full in-repo docs, so the agent lacked context it could have gathered autonomously.

Approach

Monorepo resolution (setup.ts):

  • readWorkspacePatterns() — reads workspace globs from pnpm-workspace.yaml or package.json workspaces
  • resolveWorkspacePackages() — resolves glob patterns (packages/*, packages/**) to actual package directories
  • findPackagesWithSkills() — filters to packages containing at least one SKILL.md file
  • runForEachPackage<T>() — generic wrapper that runs a command on each matching package, with proper fallback semantics

Key invariant: if workspace config is detected but no packages have skills, the command warns and returns empty — it never falls through to modify the monorepo root's package.json.

Domain discovery (SKILL.md):

Non-goals

  • Did not add monorepo awareness to setup-github-actions (it operates on the repo root by design)
  • Did not change the validate command (it already accepts a directory argument)

Trade-offs

The workspace glob resolution is a simple readdirSync-based implementation rather than using a full glob library. This handles the common patterns (packages/*, examples/**/*) but won't handle complex globs like packages/{foo,bar}. This covers the vast majority of real monorepo layouts; a full glob library can be added later if needed.

Verification

cd packages/intent && pnpm run build && pnpm test:lib
# 133 tests pass (6 new for monorepo-aware commands)

Files changed

File Change
meta/domain-discovery/SKILL.md New hard rule #3 (search before asking), Phase 1a item #5 (read all in-repo docs)
src/cli.ts Swap single-package imports to monorepo-aware *All variants
src/setup.ts Add workspace resolution, MonorepoResult<T>, runForEachPackage<T>, error handling
tests/setup.test.ts 6 new tests: pnpm workspace, package.json workspace, single-package fallback, empty monorepo warning, bin generation

🤖 Generated with Claude Code

KyleAMathews and others added 3 commits March 11, 2026 07:37
- Add hard rule #3 to domain-discovery: never ask factual questions the
  agent can answer by searching the codebase. Distinguishes factual
  questions (grep it) from judgment questions (ask the maintainer).
- Expand Phase 1a to read all in-repo markdown docs before the first
  interview, preventing the agent from asking questions docs already answer.
- Make edit-package-json and add-library-bin monorepo-aware: when run
  from a monorepo root, they find all workspace packages containing
  SKILL.md files and apply changes to each package's package.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Unify MonorepoEditResult/MonorepoBinResult into generic MonorepoResult<T>
- Extract runForEachPackage<T> to deduplicate monorepo-aware wrappers
- Add warning logs to empty catch blocks in readWorkspacePatterns
- Add error handling for readdirSync in collectPackageDirs
- Skip hidden directories during recursive workspace walks
- Distinguish "not a monorepo" from "monorepo with no skill packages"
  to avoid modifying root package.json incorrectly
- Add tests for monorepo-aware edit-package-json and add-library-bin

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot mentioned this pull request Mar 11, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@tanstack/intent@67

commit: 50b26b8

@LadyBluenotes LadyBluenotes merged commit 8177b47 into main Mar 11, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 11, 2026
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.

3 participants