Repository navigation
[AISAGE-502] refactor(web-shared): import web-shared by package name, not @/ fallback - #7099
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryFull re-review of the rebased Files Reviewed (2046 files)Hand-written commits (reviewed line by line):
Generated commits, verified by resolving every changed specifier against the filesystem:
Previous Review Summary (commit fcb36a9)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit fcb36a9)Status: No Issues Found | Recommendation: Merge Executive SummaryIncremental re-review of the rebased import-alias refactor (HEAD Files Reviewed (25 files)Newly covered by the regenerated import commits (each rewritten specifier resolves to an existing
Hand-written commits re-verified unchanged:
Reviewed by deepseek-v4.1-flash · Input: 66.7K · Output: 22.1K · Cached: 1.1M Review guidance: REVIEW.md from base branch |
fcb36a9 to
07a8969
Compare
Map @kilocode/web-shared/* to packages/web-shared/src in every place that resolves the @/ fallback today: the web, ai-gateway, scripts, trpc and web-shared tsconfigs, the web Jest config, the @kilocode/trpc rollup resolver and the Storybook webpack alias. Both specifiers resolve, so the following import rewrites can land without breaking anything in between.
…mers Generated. In apps/web, apps/ai-gateway, packages/trpc and apps/storybook, every '@/…' string that resolved to packages/web-shared/src through the tsconfig fallback now reads '@kilocode/web-shared/…'. Strings that resolve to the consumer's own src are untouched. The rewrite uses the fallback's resolution order: the consumer's '@/' root first, web-shared second. Two service tests use '@/' with the apps/web meaning and are rewritten the same way: the deploy-builder Postgres test, which runs under the apps/web Jest config, and a cloud-agent-next test that mocks the '@/' imports of an apps/web module it loads. Reproduce on the parent commit with the script from the PR description: node rewrite-web-shared-imports.mjs consumers git diff --name-only -z | xargs -0 pnpm exec oxfmt Formatting only rewraps imports that now exceed the line width.
Generated. Inside packages/web-shared, every '@/…' string now reads '@kilocode/web-shared/…'. These files are also compiled by apps/web and apps/ai-gateway, where '@/' means the app's own src first, so they must not rely on '@/' once the fallback is removed. Reproduce on the parent commit with the script from the PR description: node rewrite-web-shared-imports.mjs web-shared git diff --name-only -z | xargs -0 pnpm exec oxfmt
Every import of web-shared code now uses @kilocode/web-shared/…, so '@/' maps to the importing app's own src only. Drop the second '@/' target from the web, ai-gateway, scripts and trpc tsconfigs, the web Jest config, the @kilocode/trpc rollup resolver and the Storybook webpack alias, and drop '@/' from the web-shared tsconfig so a stray '@/' import there fails its typecheck. A file under apps/web/src can no longer shadow a web-shared file with the same path, so the rule that a path exists in only one tree goes away.
07a8969 to
bb68354
Compare
Resolve the models/up import conflict and switch the branch's new web-shared imports (dotenvx, trpc/init) to the @kilocode/web-shared package name, since #7099 removed the @/ fallback.
Summary
apps/web,apps/ai-gateway,packages/trpcand Storybook resolved@/*from two roots: the app's ownsrcfirst, thenpackages/web-shared/src. #6806 set this up so code could move into web-shared without changing its import specifiers. The result was that two folders behaved as one:lib/directories (kiloclaw,organizations,kilo-pass,user,trpc, …) exist in both trees, so you can't tell from@/lib/kiloclaw/xwhich package it is in.apps/web/srcwith the same path as a web-shared file would silently replace it inside apps/web. Only AGENTS.md prevented this.This PR imports web-shared code as
@kilocode/web-shared/<path under src>, like@kilocode/db/*.@/now always means the importing app's ownsrc. No file moves and no logic changes.Commits
@kilocode/web-shared/*mapping alongside the@/fallback@/)@/from the web-shared tsconfig, update AGENTS.mdEach commit typechecks on its own, because both forms resolve between commits 1 and 4.
Commit 3 is needed because web-shared files are also compiled by the apps. There,
@/meant the app'ssrcfirst, so web-shared's internal@/imports only worked because of the fallback.Verification
oxfmt, in a clean worktree.git diff --quietagainst each commit passed, so both generated commits are exactly the script's output.next build --experimental-build-mode=compileforapps/webcompiled. This checks how Turbopack resolves@kilocode/web-shared/*inside web-shared files.next buildforapps/ai-gatewaycompiled and passed its TypeScript step. Page-data collection then failed becauseNEXT_PUBLIC_GASTOWN_URLwas missing locally; that error came from a web-shared module that had already been imported, which shows the import chain resolved.build-storybooksucceeded (webpack alias).tsx --tsconfig tsconfig.scripts.jsonresolved a web-shared module and its web-shared imports, then stopped at the same missing environment variable.tsconfig.lib.jsonandtsconfig.json) and trpc.packages/trpc/dist/index.d.tsanddist/mobile.d.tsare byte-identical before and after commit 4.pnpm format:checkis clean.@/lib/dotenvxmock that only resolved through the removed fallback, which broke CI. Commits 2 and 3 are regenerated with the script; commits 1 and 4 are unchanged (git range-diffshows=).@/:services/deploy-infra/builder/test-postgres(runs under the apps/web Jest config) andservices/cloud-agent-next/src/telemetry/report-consumer.glanceable.test.ts(mocks the@/imports of an apps/web module). The script now covers both.kilo-deploy-builder test:postgrespasses (11 tests), as does the full cloud-agent-next unit suite (190 files). Both services typecheck.No visual changes and no runtime behaviour changes, so there was nothing to test manually beyond the builds above.
Visual Changes
N/A
Reviewer Notes
Review commits 1 and 4 by hand, and the script for commits 2 and 3. You don't need to read those two diffs; re-run the script instead:
@/root first, then web-shared. It rewrites every quoted@/…string, sojest.mock,jest.requireActual,import()and backticked file references in comments are updated too.oxfmtre-wrapped.@/strings were left alone on purpose:apps/web/src/lib/code-indexing/storage.tshas a commented-out import of a file that doesn't exist.packages/web-shared/src/lib/config.server.tspoints at an apps/web file. Commit 4 changes it to the repository path.@/imports of web-shared code will stop typechecking after rebasing onto this. Fixing them means changing those imports to@kilocode/web-shared/…, or re-running the script.rewrite-web-shared-imports.mjs