Skip to content

refactor(annotation): use #src subpath imports instead of parent-relative paths - #237

Open
contextbotai[bot] wants to merge 2 commits into
mainfrom
cb-bot/task-1783527417690
Open

refactor(annotation): use #src subpath imports instead of parent-relative paths#237
contextbotai[bot] wants to merge 2 commits into
mainfrom
cb-bot/task-1783527417690

Conversation

@contextbotai

@contextbotai contextbotai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What & why

The repo's AGENTS.md mandates subpath imports for intra-package references:

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 (e.g. plan.test.ts./plan.ts) may stay relative.

Every workspace package that has cross-directory code already declares and uses #src/* (9 of them: cli, context, harness, instrumentation, server, shared, skills, storage, ui). The @contextbridge/annotation package was the sole outlier — it never declared the imports map and reached across directories with parent-relative paths (../, ../../) instead of #src/*.

This was the single most egregious, clearly-defined, and safely-fixable violation class:

  • Frequency: 23 offending import specifiers across 8 files.
  • Severity: direct, unambiguous contradiction of a written convention that the rest of the monorepo already follows uniformly.
  • Fixability: pure import-path rewrite; zero runtime-behavior change.

Changes

  • Added "imports": { "#src/*": "./src/*" } to packages/annotation/package.json (matching the other packages).
  • Rewrote all 23 parent-relative cross-directory imports to #src/* equivalents across:
    • src/demo/DemoStage.tsx
    • src/element/ElementAdapter.ts
    • src/element/useElementTargets.ts
    • src/element/mermaid/mermaidAdapter.ts
    • src/element/mermaid/mermaidAdapter.test.ts
    • src/element/mermaid/MermaidBlock.tsx
    • src/testHelpers/index.tsx
    • src/testHelpers/appContextDecorator.tsx
    • src/testHelpers/createFakeAppContext.ts
    • src/testHelpers/renderAnnotationHook.tsx
  • Left same-directory sibling imports (./x) untouched, exactly as the convention permits.

Verification

  • bun run format:check — clean
  • bun run lint — clean (--max-warnings 0)
  • bun run --cwd packages/annotation typecheck — clean
  • packages/annotation vitest browser suite (Playwright/Chromium) — 151 tests / 12 files passing, confirming #src/* resolves in vitest browser mode.
  • vite build (the production single-file bundle) — succeeds, confirming #src/* resolves through the vite bundler with no extra alias config.

Notes for reviewer / future runs

Other convention-violation classes I noticed but intentionally left for follow-up runs (one class per run):

  • ?? fallbacks vs. destructured defaults — many ?? uses exist but most are legitimate (non-options-bag) usages; needs case-by-case review to avoid behavior changes.
  • Hand-rolled createDeferred in packages/instrumentation/src/node/harnessDiscovery.test.ts should use the shared createDeferred from @contextbridge/shared/testHelpers per the testing-patterns rule.
  • packages/cli/src/environment.ts uses .min(1) on a numeric PortSchema — the .nonempty() convention is specifically for string schemas, so this is likely NOT a violation.

…tive paths

The @contextbridge/annotation package used ../ parent-directory relative
imports for cross-directory intra-package references, violating the
subpath-import convention in AGENTS.md ('Subpath imports for intra-package
refs ... Code writes import { x } from #src/context.ts for cross-directory
imports'). Every other package that has cross-directory code already
declares and uses #src/*.

- Add "imports": { "#src/*": "./src/*" } to packages/annotation/package.json
- Rewrite all 23 parent-relative (../, ../../) imports across 8 files to
  #src/* equivalents
- Same-directory sibling imports (./) left as-is, per the convention
@contextbotai
contextbotai Bot requested review from blimmer and jcarver989 as code owners July 8, 2026 16:24
@jcarver989
jcarver989 enabled auto-merge (squash) July 10, 2026 22:17
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