Skip to content

refactor(annotation): use #src/* subpath imports over ../ relative imports - #250

Merged
jcarver989 merged 1 commit into
mainfrom
cb-bot/task-1785946617525
Aug 5, 2026
Merged

refactor(annotation): use #src/* subpath imports over ../ relative imports#250
jcarver989 merged 1 commit into
mainfrom
cb-bot/task-1785946617525

Conversation

@contextbotai

@contextbotai contextbotai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What & why

The root AGENTS.md Imports convention states:

Subpath imports for intra-package refs: every package declares "imports": { "#src/*": "./src/*" } in its package.json. Code writes import { x } from '#src/context.ts'; for cross-directory imports. Same-directory siblings … may stay relative.

A repo-wide scan found this was the single most-violated convention class. All 26 cross-directory ../ / ../../ intra-package imports lived in @contextbridge/annotation — the one library package that also failed to declare the #src/* mapping. Every other package (cli, context, harness, instrumentation, server, shared, skills, storage, ui) already declares the mapping and uses #src/*.

This is the most egregious class by all three ranking axes: highest frequency (26 instances vs. 0–1 for other candidates), unambiguous contradiction of an explicit convention, and safe to fix with zero runtime behavior change.

Changes

  • packages/annotation/package.json — added "imports": { "#src/*": "./src/*" } (placed after "type", matching sibling packages).
  • Rewrote all 26 cross-directory imports across 11 files in packages/annotation/src/** from ../ / ../../ to #src/*. Same-directory ./ sibling imports were intentionally left relative, as the convention permits.

Files touched: demo/DemoStage.tsx, element/ElementAdapter.ts, element/mermaid/MermaidBlock.tsx, element/mermaid/mermaidAdapter.ts, element/mermaid/mermaidAdapter.test.ts, element/useElementTargets.ts, testHelpers/FakeThemeController.ts, testHelpers/appContextDecorator.tsx, testHelpers/createFakeAppContext.ts, testHelpers/index.tsx, testHelpers/renderAnnotationHook.tsx.

Verification

  • bun run --cwd packages/annotation typecheck — passes (confirms #src/* resolves under tsc bundler resolution and Node package imports).
  • bun run format:check — passes.
  • bun run lint (--max-warnings 0) — passes.
  • Annotation vitest browser suite — 13 files / 159 tests pass (installed the Playwright Chromium headless shell locally, which was missing from the sandbox, to run the browser-mode tests and confirm the new import paths resolve at runtime).

The only remaining ../../ references in the codebase are cross-package bundled-asset text imports (../../../annotation/dist/index.html, ../../../harnessIntegrations/.../SKILL.md) which intentionally reach into build outputs and are outside the intra-package subpath convention.

Other violation classes noted (not addressed, per one-class-per-run)

  • Missing #src/* mapping in packages/review — the review package also lacks the imports field, but it's a WIP scaffold with no cross-directory imports yet, so there's nothing to convert.
  • Hand-rolled createDeferred in packages/instrumentation/src/node/harnessDiscovery.test.ts (1 instance) — violates the testing-patterns rule "Use the shared deferred-promise helper; do not hand-roll it" (@contextbridge/shared/testHelpers).
  • Hand-rolled createXxx() test fixtures with inline object literals (e.g. createHookDependencies, createFakeReviewDeps, createReportFixture, createFakeClient) instead of Fishery Factory.define<T>() factories — several instances across cli/context/instrumentation test files.

…ports

The 'Subpath imports for intra-package refs' convention requires
cross-directory imports to use the #src/* alias; only same-directory
siblings may stay relative. The annotation package was the sole holdout:
it lacked the imports mapping and used ../ / ../../ for all 26
cross-directory references.

- Declare "imports": { "#src/*": "./src/*" } in packages/annotation/package.json
- Rewrite all 26 ../ and ../../ imports to #src/* paths
@jcarver989
jcarver989 enabled auto-merge (squash) August 5, 2026 16:22
@jcarver989
jcarver989 merged commit 8a469e3 into main Aug 5, 2026
13 of 14 checks passed
@jcarver989
jcarver989 deleted the cb-bot/task-1785946617525 branch August 5, 2026 16:23
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