Skip to content

fix: resolve stale targets from workspace package context#102

Merged
LadyBluenotes merged 4 commits intomainfrom
repo-aware
Mar 31, 2026
Merged

fix: resolve stale targets from workspace package context#102
LadyBluenotes merged 4 commits intomainfrom
repo-aware

Conversation

@LadyBluenotes
Copy link
Copy Markdown
Member

@LadyBluenotes LadyBluenotes commented Mar 30, 2026

Summary

  • fix stale so monorepo package paths resolve to the intended workspace package
  • add CLI regression coverage for workspace-package monorepo behavior

Notes

  • intent stale packages/<pkg>/skills now checks only that package
  • intent stale from inside packages/<pkg> now checks only that package
  • added a CLI test confirming setup-github-actions still writes workflows to the workspace root from a workspace package

Summary by CodeRabbit

  • Bug Fixes

    • Fixed monorepo package path resolution so CLI commands target the intended workspace package (including when run from a workspace directory or with absolute paths), preventing scanning of the whole workspace and ensuring correct per-package reports.
  • Tests

    • Added tests for GitHub Actions setup and expanded stale-detection coverage for monorepo scenarios, including workspace-root, workspace-dir, and absolute-path targets.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 30, 2026

View your CI Pipeline Execution ↗ for commit 2cb672d

Command Status Duration Result
nx run-many --targets=build --exclude=examples/** ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-31 23:02:43 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 30, 2026

Open in StackBlitz

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

commit: 2cb672d

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

This PR changes Intent CLI path resolution to detect and target a specific workspace package (via project context and resolved paths) and adds monorepo-focused tests and a changeset documenting the fix.

Changes

Cohort / File(s) Summary
Changeset
\.changeset/vast-bags-switch.md
Adds a patch-level changeset noting the monorepo package path resolution fix.
Path resolution & CLI flow
packages/intent/src/cli-support.ts
Replaces path.join with path.resolve, calls resolveProjectContext(...), and adds an early-return branch to emit a single staleness report for a resolved workspace package when context indicates a targeted package.
Tests (monorepo scenarios)
packages/intent/tests/cli.test.ts
Adds tests for setup-github-actions and expanded stale scenarios covering workspace-root, workspace-package-dir, /skills suffix handling, and absolute targets; mocks fetch and asserts single-target behavior and output.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI
    participant Resolve as resolveStaleTargets
    participant Context as resolveProjectContext
    participant FS as Filesystem/Path
    participant Check as checkStaleness

    rect rgba(100, 150, 200, 0.5)
        CLI->>Resolve: invoke resolveStaleTargets(targetDir)
        Resolve->>FS: resolve path (path.resolve)
        Resolve->>Context: resolveProjectContext({cwd, targetPath})
        Context-->>Resolve: return {packageRoot, targetSkillsDir, workspaceRoot}
        alt context.packageRoot present AND (targetSkillsDir != null OR resolvedRoot != workspaceRoot)
            Resolve->>Check: readPackageName(packageRoot) & checkStaleness(packageRoot)
            Check-->>Resolve: single staleness report
            Resolve-->>CLI: return single-item report (early exit)
        else
            Resolve->>FS: look for `skills` under resolvedRoot and workspace patterns
            FS-->>Resolve: discovered packages/intents
            Resolve->>Check: checkStaleness for discovered packages
            Check-->>Resolve: aggregated staleness reports
            Resolve-->>CLI: return full workspace report
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 In workspaces wide where packages play,
I hop and sniff the paths today.
I find the one that’s meant to be,
No noisy scan across the tree.
Small, precise—my hopping's right, hooray! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing the required 'Changes' and 'Checklist' sections from the template, though it does convey the key information informally. Restructure the description to follow the template format with 🎯 Changes section and ✅ Checklist items, including mention of the changeset file added.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing stale target resolution to use workspace package context in a monorepo.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch repo-aware

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/intent/src/cli-support.ts`:
- Around line 59-71: The fast-path predicate incorrectly fires when
workspaceRoot is null or when packageRoot equals the workspace root; restrict it
so the branch only runs for explicit skills targets or true subpackages: change
the targetsResolvedPackage condition to only be true when
context.targetSkillsDir !== null OR (context.workspaceRoot !== null AND
resolvedRoot !== context.workspaceRoot), and keep the existing guard that
context.packageRoot is set before returning the single checkStaleness(report)
for that packageRoot/readPackageName; this ensures workspace-root-owned paths
and null workspaceRoot do not short-circuit the installed-package scan.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 936e7e05-4899-4835-82dc-69f5016976fe

📥 Commits

Reviewing files that changed from the base of the PR and between 2f29aa2 and b49d1ce.

📒 Files selected for processing (3)
  • .changeset/vast-bags-switch.md
  • packages/intent/src/cli-support.ts
  • packages/intent/tests/cli.test.ts

Comment on lines +59 to +71
const targetsResolvedPackage =
context.packageRoot !== null &&
(context.targetSkillsDir !== null || resolvedRoot !== context.workspaceRoot)

if (targetsResolvedPackage && context.packageRoot) {
return {
reports: [
await checkStaleness(
context.packageRoot,
readPackageName(context.packageRoot),
),
],
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Narrow this fast path to real package targets.

Line 61 is always true when context.workspaceRoot is null, so intent stale from a normal app root with a package.json now skips the installed-package scan at Lines 98-105 and reports the app package instead. The same branch also misclassifies workspace-root-owned paths like packages/ as a single-package target. Please gate this branch to explicit skills targets or subpackages whose packageRoot differs from the workspace root.

Suggested predicate tightening
-  const targetsResolvedPackage =
-    context.packageRoot !== null &&
-    (context.targetSkillsDir !== null || resolvedRoot !== context.workspaceRoot)
+  const targetsResolvedPackage =
+    context.packageRoot !== null &&
+    (
+      context.targetSkillsDir !== null ||
+      (
+        context.workspaceRoot !== null &&
+        context.packageRoot !== context.workspaceRoot &&
+        resolvedRoot !== context.workspaceRoot
+      )
+    )

Based on learnings, monorepo detection here intentionally needs to answer whether a package is inside a monorepo, not whether the workspace root itself should be treated as a targeted sub-package.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/intent/src/cli-support.ts` around lines 59 - 71, The fast-path
predicate incorrectly fires when workspaceRoot is null or when packageRoot
equals the workspace root; restrict it so the branch only runs for explicit
skills targets or true subpackages: change the targetsResolvedPackage condition
to only be true when context.targetSkillsDir !== null OR (context.workspaceRoot
!== null AND resolvedRoot !== context.workspaceRoot), and keep the existing
guard that context.packageRoot is set before returning the single
checkStaleness(report) for that packageRoot/readPackageName; this ensures
workspace-root-owned paths and null workspaceRoot do not short-circuit the
installed-package scan.

… cases

- Inline targetsResolvedPackage boolean to remove redundant null check
- Add fetchSpy call count assertions to verify only targeted package is processed
- Add test for targetDir without /skills suffix
- Add test for absolute targetDir path (validates join→resolve fix)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the fix and added a follow-up commit with improvements:

  • Simplified condition: Inlined the targetsResolvedPackage boolean — the redundant re-check of context.packageRoot was only needed for TypeScript narrowing, which the inlined truthy check handles directly.
  • Stronger test assertions: Added fetchSpy.toHaveBeenCalledTimes(1) to both staleness tests, proving the untargeted package is never even processed (not just excluded from reports).
  • New test coverage: Added tests for targeting a package path without the /skills suffix, and for absolute targetDir paths (which validates the joinresolve fix — red/green confirmed the old join code breaks with absolute paths).

All 29 tests pass.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/intent/tests/cli.test.ts (1)

490-691: Consider adding a test for non-monorepo single-package projects.

The current stale tests only cover monorepo scenarios. A test for a simple project (single package.json, no workspaces, with node_modules containing intent packages) would help catch the predicate issue flagged in cli-support.ts where the fast path incorrectly fires when workspaceRoot is null.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/intent/tests/cli.test.ts` around lines 490 - 691, Add a new test in
packages/intent/tests/cli.test.ts that sets up a non-monorepo single-package
project (a root with package.json that has no "workspaces"), writes a skills
file (using writeSkillMd) and simulates npm resolution (optionally create
node_modules or spy fetch), then chdir into that root and call
main(['stale','--json']) to ensure the CLI stale fast-path in cli-support.ts
does not incorrectly treat workspaceRoot === null as a monorepo: assert exit
code is 0 and the returned reports include the package (e.g., library name from
package.json); reference main and the stale command so the test targets the
predicate in cli-support.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/intent/tests/cli.test.ts`:
- Around line 490-691: Add a new test in packages/intent/tests/cli.test.ts that
sets up a non-monorepo single-package project (a root with package.json that has
no "workspaces"), writes a skills file (using writeSkillMd) and simulates npm
resolution (optionally create node_modules or spy fetch), then chdir into that
root and call main(['stale','--json']) to ensure the CLI stale fast-path in
cli-support.ts does not incorrectly treat workspaceRoot === null as a monorepo:
assert exit code is 0 and the returned reports include the package (e.g.,
library name from package.json); reference main and the stale command so the
test targets the predicate in cli-support.ts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 785cb391-3454-48fc-a36f-00287f4bf38b

📥 Commits

Reviewing files that changed from the base of the PR and between b49d1ce and 2cb672d.

📒 Files selected for processing (2)
  • packages/intent/src/cli-support.ts
  • packages/intent/tests/cli.test.ts

@LadyBluenotes LadyBluenotes merged commit a48b8b8 into main Mar 31, 2026
5 checks passed
@LadyBluenotes LadyBluenotes deleted the repo-aware branch March 31, 2026 23:09
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.

2 participants