Skip to content

Resolve platform scopes live in kody: package imports - #1337

Merged
kody-bot merged 3 commits into
mainfrom
cursor/kody-live-packages-c0a2
Aug 9, 2026
Merged

kody-bot merged 3 commits into
mainfrom
cursor/kody-live-packages-c0a2

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

import gh from 'kody:@kody/github/issues' now works for every user without forking: when the caller has no package with that name and the scope's username belongs to a platform account (users.account_type = 'platform'), the import resolves live from the platform account's current published version — and platform packages appear in ranked search so agents discover them. Official helper packages ship once, update fleet-wide instantly for ad hoc callers, and never require codemodding thousands of forks. See decision record docs/contributing/decisions/0014-platform-live-packages.md.

Isolation bounds (the important part)

  • Read-only source widening only. Platform resolution changes whose published source the bundler may read — nothing else. Person-account scopes never resolve cross-user; the platform check is structural (account_type), not policy.
  • Caller runtime, caller boundaries. Resolved modules execute in the calling user's runtime against the caller's secrets, storage grants, and entitlements — exactly like a fork would.
  • The caller's own copy always wins, so fork-to-customize keeps working unchanged (in imports and in search results).
  • Stateless in the caller: platform-owned dependency ids are excluded from packageStorage() grants (platformOwned on BundleArtifactDependency), so packageStorage() inside live platform code fails closed.
  • Static imports only: the dynamic hydration lane persists rebuilt artifacts under the caller's identity, so dynamic platform imports throw a teaching error pointing at the static form.
  • Hidden/private platform packages resolve only for their owner; the published-artifact fast path reads under the owner's identity (persisted by the owner at publish).
  • Search tripwire stays strict: the package plugin admits only rows the loader explicitly marked with platformScope; any other foreign row still fails the lane closed with the warning.

What changed

  • resolveSavedPackageImport returns a resolution (row, sourceOwnerUserId, platformScope) with the platform-scope fallback; ensurePackageLoaded, dependency recording, and the artifact fast path load under the resolved owner.
  • Search surfacing: the loader injects platform-account package rows (deduped against caller rows), slim matches and entity detail carry platformScope plus "no fork needed, resolves live" guidance, and entity detail falls back to platform accounts. Platform rows rank lexically only (the vector index is per-user); noted in the decision record for revisiting.
  • scanCrossScopeReferences gains allowedForeignScopes and community fork passes the platform usernames, so forks keep @kody/... references instead of being told to rewrite them.
  • Docs: decision record 0014, the import contract in data-storage.md, docs/use/packages.md, and the execute tool description.
  • Deferred: the platform-app → recommended-package pairing column.

Testing

  • npm run validate fully green.
  • New coverage: platform-scope resolution (own copy wins, hidden unresolvable, person scopes never resolve, dynamic lane opt-out), packageStorage grant exclusion for platform-owned deps, fork-scan allowlist behavior, and search ranking (platform row ranks with platformScope; unmarked foreign rows still dropped with the tripwire warning).
System recap — extends the packages primitive (medium risk)

Mode: recap · Base: main @ f84f38d6 · Head: 7bb8e27d

Classification: extends — package import resolution gains a structural platform-scope lane and ranked search surfaces platform packages; no new primitive, the per-user isolation exception is documented in decision record 0014 as read-only source widening.

Primitives touched

Primitive Group Impact
packages assistant extends — platform scopes resolve live in kody:@ imports; own copy wins
mcp-server surfaces extends — search ranks platform package rows (marked lane through the ownership tripwire)
capabilities-execute runtime composes — bundler provenance carries platformOwned; storage grants exclude platform ids
community assistant composes — fork cross-scope scan allowlists platform scopes

System map

An agent searches "github", finds the @kody/github platform package, and imports it: the bundler resolves the platform account's published source, the code runs in the caller's runtime, and storage grants exclude the platform package id.

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).

flowchart LR
	mcpServer["mcp-server<br/>MCP endpoint"]:::extended
	execute["capabilities-execute<br/>Execute runtime"]:::touched
	packages["packages<br/>Saved packages"]:::extended
	community["community<br/>Community listings"]:::touched
	d1AppDb["d1-app-db<br/>D1 app database"]:::untouched
	mcpServer -->|"search injects platformScope-marked rows; detail falls back to platform accounts"| packages
	execute -->|"kody:@kody/... static import (caller runtime)"| packages
	packages -->|"account_type='platform' scope lookup + owner-keyed source/artifact reads"| d1AppDb
	community -->|"fork scan allowlists platform scopes"| packages
	packages -->|"platformOwned deps excluded from packageStorage grants"| execute
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

Invariants

  • Per-user isolation: narrowed exception, documented in decision record 0014 — read-only resolution of published platform-account package source, structurally limited to account_type = 'platform'. Execution, secrets, storage, and entitlements stay caller-scoped; person-account scopes remain unrepresentable cross-user, and the search ownership tripwire admits only host-marked platform rows.
  • packageStorage provenance: unchanged rule (bundler-controlled ids only), tightened for the new lane (platform ids never granted).
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features

    • Added live static imports from published platform packages when no local copy exists.
    • Local packages take precedence, while platform code runs with the caller’s runtime, secrets, and permissions.
    • Platform packages now appear in search results with ownership scope and enhanced package details.
    • Platform-owned dependencies cannot access the caller’s package storage.
    • Dynamic imports of platform packages fail closed with guidance to use static imports.
  • Documentation

    • Documented platform package imports, runtime behavior, restrictions, and resolution rules.
    • Added an architectural decision record for platform-scoped package resolution.

Static imports like 'kody:@kody/github/issues' now resolve from a
platform account's current published version when the caller has no
copy of their own (decision record 0014). Users get official helper
packages with zero fork friction and operator fixes reach every ad hoc
caller immediately.

Bounds keeping isolation intact:
- read-only source widening: only *which published source the bundler
  reads* changes; person-account scopes never resolve cross-user
  (structural account_type check)
- resolved modules execute in the caller's runtime against the
  caller's secrets, storage grants, and entitlements
- the caller's own copy always wins (fork-to-customize unchanged)
- platform-owned dependency ids are excluded from packageStorage()
  grants, so live platform code stays stateless in the caller
- static imports only: the dynamic hydration lane persists artifacts
  under the caller's identity, so platform targets get a teaching error
- hidden platform packages resolve only for their owner
- published-artifact fast path reads under the owner's identity

Community fork policy follows: scanCrossScopeReferences accepts
platform scopes so forks keep @kody/... references instead of
rewriting them.

Search surfacing is deferred (decision record): the package search
plugin asserts caller ownership per row and vector scoring is per-user,
so surfacing needs its own design.

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

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 14dff04e-ebab-4f0d-aa54-ff67040e0223

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb8e27 and ef4cc13.

📒 Files selected for processing (6)
  • docs/contributing/decisions/0014-platform-live-packages.md
  • docs/use/packages.md
  • packages/worker/src/mcp/instructions/execute-tool-description.ts
  • packages/worker/src/mcp/tools/search-entity-plugins/package.ts
  • packages/worker/src/package-runtime/package-import-resolution.node.test.ts
  • packages/worker/src/package-runtime/package-import-resolution.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • docs/contributing/decisions/0014-platform-live-packages.md
  • docs/use/packages.md
  • packages/worker/src/package-runtime/package-import-resolution.node.test.ts
  • packages/worker/src/mcp/tools/search-entity-plugins/package.ts
  • packages/worker/src/mcp/instructions/execute-tool-description.ts
  • packages/worker/src/package-runtime/package-import-resolution.ts

📝 Walkthrough

Walkthrough

Platform accounts can provide live static package imports when callers lack local copies. Runtime loading preserves source ownership and excludes platform-owned storage grants. Search exposes platform packages, and community fork scanning preserves approved platform scopes.

Changes

Platform live packages

Layer / File(s) Summary
Platform package discovery and import resolution
packages/worker/src/package-registry/..., packages/worker/src/package-runtime/package-import-resolution*
Platform accounts provide visible packages when callers have no local copy. Caller-owned packages remain preferred. Resolution returns source-owner and platform-scope metadata.
Runtime ownership and storage boundaries
packages/worker/src/package-runtime/..., packages/worker/src/mcp/run-kody-registry.ts
Runtime loading uses the resolved package owner. Dynamic platform imports are rejected. Platform-owned dependencies do not receive package-storage grants.
Platform package search and details
packages/worker/src/mcp/tools/..., packages/worker/src/mcp/capabilities/meta/search.node.test.ts
Search merges platform and user-owned packages, preserves user-owned precedence, applies lexical ranking to platform rows, and exposes platform scope and owner metadata.
Fork cross-scope compatibility
packages/worker/src/community/...
Community fork scanning allowlists platform scopes for manifest dependencies and source imports.
Documentation and package-use guidance
docs/contributing/..., docs/use/packages.md, packages/worker/src/mcp/instructions/execute-tool-description.ts
Documentation describes live platform imports, runtime and storage boundaries, search behavior, and dynamic-import restrictions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant PackageImportResolution
  participant PlatformPackageRegistry
  participant ModuleGraph
  participant StorageGrants
  Caller->>PackageImportResolution: request static package import
  PackageImportResolution->>PlatformPackageRegistry: resolve platform package
  PlatformPackageRegistry-->>PackageImportResolution: package and source-owner metadata
  PackageImportResolution->>ModuleGraph: load source under resolved owner
  ModuleGraph->>StorageGrants: mark platform-owned dependency
  StorageGrants-->>Caller: runtime graph without platform storage grant
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.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 clearly and concisely describes the main change: live resolution of platform scopes in Kody package imports.
Description check ✅ Passed The description explains the intent, changes, isolation boundaries, system impact, testing, and deferred work in sufficient detail.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/kody-live-packages-c0a2

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.

Platform (built-in) packages now appear in search results alongside the
caller's own packages, so agents discover them without knowing names in
advance:

- the search loader injects platform-account package rows (non-hidden,
  non-private) with a host-set platformScope marker; the caller's own
  copy of a name or kody id wins and replaces the platform row
- the package plugin's ownership tripwire admits exactly those marked
  rows; unmarked foreign rows still fail the lane closed with the
  warning
- slim matches and entity detail carry platformScope, and the next-step
  text tells agents the import resolves live with no fork needed
- entity detail falls back to platform accounts when the caller owns no
  matching package; source and hosted-app URLs resolve under the
  platform owner
- hydration loads package source under the record owner's id (identical
  for caller rows)
- platform rows rank lexically only: the vector index is per-user, so
  platform packages have no vectors in the caller's namespace (noted in
  decision record 0014)

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds marked this pull request as ready for review August 9, 2026 08:03

@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 using default effort and found 2 potential issues.

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 7bb8e27. Configure here.

Comment thread packages/worker/src/package-runtime/package-import-resolution.ts
Comment thread packages/worker/src/mcp/tools/search-entity-plugins/package.ts
@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-1337.kody-a99.workers.dev

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

Mocks:

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/worker/src/mcp/tools/search-entity-plugins/package.ts (1)

450-472: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the platform owner for platform hosted URLs.

formatSlimMatch adds platformScope, but hostedUrl below still uses username. For a platform package with an app, search returns a URL under the caller account instead of the platform account.

Use match.platformScope ?? username as the hosted URL owner.

Proposed fix
 		const hostedAppOrigin = packageAppBaseUrl ?? baseUrl
+		const ownerUsername = match.platformScope ?? username
 		const rootImportUsage = buildPackageRootImportUsage(match.name)
@@
 			hostedUrl:
-				match.hasApp && username
-					? buildPackageHostedUrl(hostedAppOrigin, username, match.kodyId)
+				match.hasApp && ownerUsername
+					? buildPackageHostedUrl(hostedAppOrigin, ownerUsername, match.kodyId)
 					: null,
🤖 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/mcp/tools/search-entity-plugins/package.ts` around lines
450 - 472, Update hosted URL construction in formatSlimMatch to use
match.platformScope ?? username as the owner, while preserving username for
non-platform packages. Ensure platform packages with apps resolve URLs under the
platform account.
🧹 Nitpick comments (1)
packages/worker/src/community/community-service.node.test.ts (1)

50-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise the allowlist at the forkCommunityListing boundary.

The mock returns [] for every test, so the changed call in packages/worker/src/community/service.ts never receives a platform scope in this suite. The direct scanner test covers scanCrossScopeReferences, but it does not verify that the fork flow passes the database result through.

Make listPlatformAccountUsernames configurable. Add a fork test with ['kody']. Assert that kody:@kody/... is omitted from crossScopeReferences while kody:@owner/... remains reported.

Suggested mock change
-	listPlatformAccountUsernames: async () => [],
+	listPlatformAccountUsernames: vi.fn().mockResolvedValue([]),

This verifies the fork-flow contract described in the PR objectives and the supplied downstream graph.

🤖 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/community/community-service.node.test.ts` around lines 50
- 53, Update the package-registry mock in the community service tests so
listPlatformAccountUsernames is configurable per test, then add a
forkCommunityListing test configured with ['kody']. Assert that kody:`@kody/`...
is excluded from crossScopeReferences while kody:`@owner/`... remains reported,
verifying the fork boundary passes the database allowlist through.
🤖 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 `@docs/use/packages.md`:
- Around line 147-156: Update the package-storage guidance in
docs/use/packages.md:147-156 so the declaring-package bucket rule explicitly
applies only to caller-owned packages, while platform-owned dependencies receive
no packageStorage() grant and fail closed. Repeat this no-grant and fail-closed
behavior in packages/worker/src/mcp/instructions/execute-tool-description.ts:17
within the sandbox guidance, preserving per-user isolation.
- Around line 147-156: Qualify live platform-package resolution by visibility
across all affected documentation and instruction text: in docs/use/packages.md
(147-156), describe only visible platform packages as live-resolvable and
discoverable in search; update execute-tool-description.ts (17-17) to replace
“for every user” with visibility-qualified wording; restrict the public-source
rationale in docs/contributing/decisions/0014-platform-live-packages.md (24-38)
to visible packages, explicitly state in (52-53) that hidden/private packages
remain owner-only, and clarify in docs/contributing/architecture/data-storage.md
(1331-1337) that callers without a local copy can resolve only visible platform
scopes, while preserving per-user isolation.

In `@packages/worker/src/mcp/tools/search-entity-plugins/package.ts`:
- Around line 227-236: The common scoring flow must keep platform package
ranking lexical-only. Update the logic around queryPackageVectorScores to
exclude platformScope rows from vector scoring, and assign those rows scores via
buildCandidateBaseScore({ lexical }) in every mode while preserving vector
scoring for non-platform rows.

In `@packages/worker/src/package-runtime/package-import-resolution.ts`:
- Around line 125-132: Update the platform-package resolution guard in the
visible resolver to return null when row is absent, hidden, or private by
checking row.isPrivate alongside row.hidden. Add a test that seeds a platform
package with is_private: 1 and verifies resolution returns null.

---

Outside diff comments:
In `@packages/worker/src/mcp/tools/search-entity-plugins/package.ts`:
- Around line 450-472: Update hosted URL construction in formatSlimMatch to use
match.platformScope ?? username as the owner, while preserving username for
non-platform packages. Ensure platform packages with apps resolve URLs under the
platform account.

---

Nitpick comments:
In `@packages/worker/src/community/community-service.node.test.ts`:
- Around line 50-53: Update the package-registry mock in the community service
tests so listPlatformAccountUsernames is configurable per test, then add a
forkCommunityListing test configured with ['kody']. Assert that kody:`@kody/`...
is excluded from crossScopeReferences while kody:`@owner/`... remains reported,
verifying the fork boundary passes the database allowlist through.
🪄 Autofix

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: 4d804d20-1a14-4317-becf-44e7214bb8d4

📥 Commits

Reviewing files that changed from the base of the PR and between f84f38d and 7bb8e27.

📒 Files selected for processing (30)
  • docs/contributing/architecture/data-storage.md
  • docs/contributing/decisions/0014-platform-live-packages.md
  • docs/contributing/decisions/index.md
  • docs/use/packages.md
  • packages/worker/src/community/community-flow-test-schema.ts
  • packages/worker/src/community/community-service.node.test.ts
  • packages/worker/src/community/fork-scan.node.test.ts
  • packages/worker/src/community/fork-scan.ts
  • packages/worker/src/community/service.ts
  • packages/worker/src/mcp/capabilities/meta/search.node.test.ts
  • packages/worker/src/mcp/instructions/execute-tool-description.ts
  • packages/worker/src/mcp/run-kody-registry.ts
  • packages/worker/src/mcp/tools/search-detail.node.test.ts
  • packages/worker/src/mcp/tools/search-detail.ts
  • packages/worker/src/mcp/tools/search-entity-plugins/package.ts
  • packages/worker/src/mcp/tools/search-format-types.ts
  • packages/worker/src/mcp/tools/search-handler.node.test.ts
  • packages/worker/src/mcp/tools/search-loaders.ts
  • packages/worker/src/mcp/tools/search-package-rows.ts
  • packages/worker/src/mcp/tools/search-types.ts
  • packages/worker/src/mcp/tools/search.node.test.ts
  • packages/worker/src/package-registry/platform-packages.ts
  • packages/worker/src/package-registry/scope-grants.ts
  • packages/worker/src/package-runtime/module-graph-hydration.ts
  • packages/worker/src/package-runtime/module-graph-import-rewriting.ts
  • packages/worker/src/package-runtime/module-graph-workspace.ts
  • packages/worker/src/package-runtime/module-graph.node.test.ts
  • packages/worker/src/package-runtime/package-import-resolution.node.test.ts
  • packages/worker/src/package-runtime/package-import-resolution.ts
  • packages/worker/src/package-runtime/published-runtime-artifacts.ts

Comment thread docs/use/packages.md
Comment thread packages/worker/src/mcp/tools/search-entity-plugins/package.ts
Comment thread packages/worker/src/package-runtime/package-import-resolution.ts Outdated
- private platform packages no longer resolve cross-user (isPrivate now
  checked alongside hidden at import resolution; search already
  excluded them)
- platform search rows rank lexically in every mode: excluded from the
  Vectorize query and from the offline deterministic-embedding
  fallback, keeping online/offline ranking consistent with the
  documented contract
- slim-match hostedUrl for platform packages with apps uses the
  platform account's username, matching entity detail
- storage guidance in packages.md and the execute tool description now
  states platform-owned dependencies get no packageStorage() grant and
  fail closed

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kody-bot
kody-bot merged commit f3af887 into main Aug 9, 2026
10 checks passed
@kody-bot
kody-bot deleted the cursor/kody-live-packages-c0a2 branch August 9, 2026 14:57
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