Skip to content

Improve saved package export usability - #383

Merged
kentcdodds merged 4 commits into
mainfrom
cursor/fix-importable-package-artifacts-9ae5
May 7, 2026
Merged

kentcdodds merged 4 commits into
mainfrom
cursor/fix-importable-package-artifacts-9ae5

Conversation

@kentcdodds

@kentcdodds kentcdodds commented May 7, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Resolves transitive imports back to the root package source during package rebuilds, unblocking packages that import each other while importable artifacts are being regenerated.
  • Adds export surfaces to package_get, including ready-to-use kody: import specifiers and runtime/type targets.
  • Shares package import-specifier formatting across package detail and search formatting.
  • Adds regression coverage for package rebuild cycles and package_get export details.

Validation

  • npx vitest run "packages/worker/src/package-runtime/module-graph.node.test.ts" "packages/worker/src/mcp/capabilities/packages/get-package.node.test.ts" "packages/worker/src/package-runtime/published-bundle-artifacts.node.test.ts" "packages/worker/src/package-registry/service.node.test.ts"
  • npx vitest run "packages/worker/src/mcp/capabilities/packages/get-package.node.test.ts" "packages/worker/src/mcp/tools/search.node.test.ts"
  • npm run typecheck
  • npm run lint
  • npm run format:check

Review loop

  • Addressed Cursor Bugbot feedback by extracting the duplicate import-specifier helper.
  • Addressed CodeRabbit feedback by adding a defensive export fallback and an explicit root-bypass assertion.
  • Latest GitHub Actions, Cursor Bugbot, and CodeRabbit checks are green.

Operational follow-up after deploy

  • Republish the packages that currently fail on the root-package artifact cycle: personal-history, journaling, discord-personal-history, discord-general-chat, and discord-gateway.
  • Rerun the cross-package import smoke test to confirm explicit import call arguments win over outer execute params.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features

    • Package queries now return detailed export surfaces including ready-to-use import specifiers, runtime targets, type paths, descriptions, and type definitions.
  • Improvements

    • Better resolution of package-root exports and transitive package imports to produce more accurate module bundles and dependency records.
  • Tests

    • Added/updated tests validating package detail responses and module-bundling resolution across package boundaries.

cursoragent and others added 2 commits May 7, 2026 04:33
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds package export surface schemas and import-specifier helper; expands the MCP package_get capability to include ready-to-import export entries; updates module-graph to parse the root package.json and resolve root kody: exports directly; and updates tests and search formatting to use the new helper.

Changes

Package detail + import-specifier + module-graph

Layer / File(s) Summary
Data Shapes
packages/worker/src/mcp/capabilities/packages/shared.ts
Adds packageExportSurfaceSchema (subpath, import_specifier, runtime_target, types_path, description, type_definition) and packageDetailSchema (extends packageSummarySchema with exports array).
Helper
packages/worker/src/package-registry/package-import-specifier.ts
Adds exported buildPackageImportSpecifier(packageName, exportName) that emits kody:pkg for '.' and kody:pkg/<subpath> otherwise (strips leading ./).
Core Capability Logic
packages/worker/src/mcp/capabilities/packages/get-package.ts
Capability updated to outputSchema: packageDetailSchema, updated description/keywords; handler now loads manifest via loadPackageManifestBySourceId, projects exports with buildPackageSearchProjection, and maps each export to include import_specifier via buildPackageImportSpecifier.
Module Graph Resolution
packages/worker/src/package-runtime/module-graph.ts
Adds readRootPackage() to parse root package.json into RewriteState.rootPackage; ensurePackageProxy resolves kody:* exports for the root package directly from the parsed manifest and root prefix instead of using saved-package resolution.
Search Formatting / Wiring
packages/worker/src/mcp/tools/search-format.ts
Replaces local helper with import of buildPackageImportSpecifier and removes the file-local implementation.
Tests
packages/worker/src/mcp/capabilities/packages/get-package.node.test.ts, packages/worker/src/package-runtime/module-graph.node.test.ts
Adds/updates tests: capability test asserts manifest is loaded and returned payload includes normalized exports with import specifiers; module-graph test verifies transitive import resolution against root package during bundle rebuilds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • kentcdodds/kody#259: Modifies kody: package import specifier construction and resolution; closely related to the new buildPackageImportSpecifier usage.
  • kentcdodds/kody#307: Changes module-graph logic and tests concerning package export path resolution; related to the root-package handling updates.

Poem

🐇 I peeked inside the manifest door,

Exports aligned and paths to explore,
kody: names stitched neat and true,
Root knows itself — no roundabout view,
A rabbit hops, the graph blooms new. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title "Improve saved package export usability" directly and clearly summarizes the main change: enhancing how package exports are presented and usable, including adding export surfaces with ready-to-use import specifiers and resolving transitive package imports.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 cursor/fix-importable-package-artifacts-9ae5

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@kentcdodds
kentcdodds marked this pull request as ready for review May 7, 2026 04:46
@github-actions

github-actions Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-383.kentcdodds.workers.dev

Worker: kody-pr-383
D1: kody-pr-383-db
KV: kody-pr-383-oauth-kv

Mocks:

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7e8c173. Configure here.

Comment thread packages/worker/src/mcp/capabilities/packages/get-package.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/worker/src/package-runtime/module-graph.node.test.ts (1)

697-785: ⚡ Quick win

LGTM — the cycle-resolution regression test is well-constructed.

The test correctly establishes the transitive cycle (personal-history → journaling → personal-history) with no published artifacts, and would fail if the root-package bypass in ensurePackageProxy were absent (because resolvePackageExportPath would throw looking for ./state-ensure in journaling's manifest).

One optional improvement: add an explicit assertion that getSavedPackageByName was called exactly once (for journaling only) to make the bypass guarantee explicit, rather than leaving it as a side-effect check.

🧪 Suggested assertion
 	}).resolves.toEqual({
 		...
 	})
+
+	// Explicit bypass guarantee: root package must not be resolved through the saved-package DB path.
+	expect(mockModule.getSavedPackageByName).toHaveBeenCalledTimes(1)
+	expect(mockModule.getSavedPackageByName).toHaveBeenCalledWith(
+		{},
+		{ userId: 'user-1', name: '@kentcdodds/journaling' },
+	)
 })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/src/package-runtime/module-graph.node.test.ts` around lines
697 - 785, Add an explicit assertion that mockModule.getSavedPackageByName was
invoked exactly once for the transitive package to make the bypass guarantee
explicit: in the test that calls buildKodyModuleBundle (the test named
"buildKodyModuleBundle resolves transitive imports back to the root package
source during rebuilds"), after awaiting the resolved result, assert
mockModule.getSavedPackageByName was called once with '@kentcdodds/journaling'
(referencing the mockModule.getSavedPackageByName mock and the
buildKodyModuleBundle call) so the test fails if the root-package bypass is not
used.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/worker/src/package-runtime/module-graph.node.test.ts`:
- Around line 697-785: Add an explicit assertion that
mockModule.getSavedPackageByName was invoked exactly once for the transitive
package to make the bypass guarantee explicit: in the test that calls
buildKodyModuleBundle (the test named "buildKodyModuleBundle resolves transitive
imports back to the root package source during rebuilds"), after awaiting the
resolved result, assert mockModule.getSavedPackageByName was called once with
'@kentcdodds/journaling' (referencing the mockModule.getSavedPackageByName mock
and the buildKodyModuleBundle call) so the test fails if the root-package bypass
is not used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 692e9c4e-2190-4862-ba8c-4d23c5c474bb

📥 Commits

Reviewing files that changed from the base of the PR and between cd41c2e and 7e8c173.

📒 Files selected for processing (5)
  • packages/worker/src/mcp/capabilities/packages/get-package.node.test.ts
  • packages/worker/src/mcp/capabilities/packages/get-package.ts
  • packages/worker/src/mcp/capabilities/packages/shared.ts
  • packages/worker/src/package-runtime/module-graph.node.test.ts
  • packages/worker/src/package-runtime/module-graph.ts

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/worker/src/mcp/capabilities/packages/get-package.ts`:
- Around line 51-61: The code calls projection.exports.map(...) which will throw
if projection.exports is null or undefined; change the mapping to use a
null-coalescing fallback like (projection.exports ?? []).map(...) so an empty
array is used when no exports are present, e.g., update the exports assignment
in get-package.ts to exports: (projection.exports ?? []).map(...) while keeping
the existing mapping body that uses buildPackageImportSpecifier and saved.name.
🪄 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 Plus

Run ID: db95df8a-dc5f-47de-a2a4-f321b1f99a1d

📥 Commits

Reviewing files that changed from the base of the PR and between 7e8c173 and aee6ee9.

📒 Files selected for processing (3)
  • packages/worker/src/mcp/capabilities/packages/get-package.ts
  • packages/worker/src/mcp/tools/search-format.ts
  • packages/worker/src/package-registry/package-import-specifier.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/worker/src/mcp/tools/search-format.ts
  • packages/worker/src/package-registry/package-import-specifier.ts

Comment thread packages/worker/src/mcp/capabilities/packages/get-package.ts Outdated
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds merged commit b04efa4 into main May 7, 2026
9 checks passed
@kentcdodds
kentcdodds deleted the cursor/fix-importable-package-artifacts-9ae5 branch May 7, 2026 05:14
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