Skip to content

fix: resolve stale targets from workspace package context#102

Open
LadyBluenotes wants to merge 2 commits intomainfrom
repo-aware
Open

fix: resolve stale targets from workspace package context#102
LadyBluenotes wants to merge 2 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 package path resolution in monorepos to correctly target the intended workspace package instead of scanning the entire workspace.
  • Tests

    • Added test coverage for GitHub Actions setup and stale detection commands in monorepo environments.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 30, 2026

View your CI Pipeline Execution ↗ for commit b49d1ce

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

☁️ Nx Cloud last updated this comment at 2026-03-30 17:30:59 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: b49d1ce

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

This PR enhances monorepo package path resolution in the Intent CLI by targeting the intended workspace package directly rather than scanning the entire workspace. It updates the core path resolution logic and introduces comprehensive test coverage for monorepo scenarios.

Changes

Cohort / File(s) Summary
Changelog
.changeset/vast-bags-switch.md
Patch-level release note documenting the monorepo package path resolution fix.
Path Resolution Logic
packages/intent/src/cli-support.ts
Modified resolveStaleTargets to use path.resolve over path.join, compute project context via resolveProjectContext, and return early for targeted workspace packages instead of defaulting to full workspace scan.
Test Coverage
packages/intent/tests/cli.test.ts
Added tests for setup-github-actions and stale commands in monorepo scenarios, verifying that workflows are placed at workspace root and that targeted package runs only check the specified package, not the entire workspace.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI
    participant ResolveStale as resolveStaleTargets
    participant Context as resolveProjectContext
    participant Check as checkStaleness
    participant Workspace as Workspace Scan

    rect rgba(100, 150, 200, 0.5)
        note over CLI,Workspace: New Flow
        CLI->>ResolveStale: invoke with targetDir
        ResolveStale->>ResolveStale: resolve path with path.resolve()
        ResolveStale->>Context: call with project context
        Context-->>ResolveStale: return context (packageRoot, targetSkillsDir, workspaceRoot)
        alt Is targeted package?
            ResolveStale->>Check: call for context.packageRoot
            Check-->>ResolveStale: return staleness report
            ResolveStale-->>CLI: return single-item report (early exit)
        else Not a targeted package
            ResolveStale->>Workspace: scan workspace patterns and intents
            Workspace-->>ResolveStale: discover packages
            ResolveStale->>Check: check staleness across packages
            Check-->>ResolveStale: return staleness reports
            ResolveStale-->>CLI: return full workspace report
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 In monorepo lands where packages reside,
No more wild scans across the countryside!
With context resolved and paths held tight,
We target just one package—clean and right! ✨
The workspace breathes easy, the logic runs true,
Intent CLI works better for me and for you!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
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.
Description check ❓ Inconclusive The pull request description includes a Summary section detailing the changes and Notes explaining the behavioral impact, but does not follow the required template structure with 🎯 Changes, ✅ Checklist, and 🚀 Release Impact sections. Reformat the description to match the template structure: add the required 🎯 Changes, ✅ Checklist, and 🚀 Release Impact sections with proper checkboxes and confirmation of changeset generation.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: resolving stale targets from the workspace package context, which directly aligns with the primary change in the changeset and code modifications.

✏️ 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.

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