refactor: reorganize src/ directory structure (835 files, 0 TS errors)#1583
Merged
refactor: reorganize src/ directory structure (835 files, 0 TS errors)#1583
Conversation
- Move 7 readme translations (readme_{ch,es,jp,ko,pt,tr,tw}.md) to docs/readme/
- Move CODE_STYLE.md, SERVER_DEPLOY_GUIDE.md, WEBUI_GUIDE.md to docs/
- Update all cross-references in readme.md, WEBUI_GUIDE.md, install-ubuntu.sh
- Create lifecycle/ (ExtensionEventBus, hotReload, lifecycle, statePersistence) - Create sandbox/ (sandbox, sandboxWorker, permissions, pathSafety) - Create protocol/ (assetProtocol, uiProtocol) - Move utility resolvers to resolvers/utils/ - Update all imports in source and test files
Bridge subdirectories: conversation/, system/, data/, agent/, platform/ Task subdirectories: managers/, middleware/, worker/ Update all imports in source and test files
- Move skills/ → src/skills/, assistant/ → src/assistant/ - Update electron-builder.yml files and asarUnpack paths - Update electron.vite.config.ts viteStaticCopy source paths - Update assistantPresets.ts resourceDir references - Update initStorage.ts and fsBridge.ts resource resolution with fallback paths for both viteStaticCopy and direct inclusion - Update skillsMarket test paths
…cture # Conflicts: # electron-builder.yml
- adapter/ → common/adapter/ (cross-process bridge) - types/ → common/types/ (shared type declarations) - shared/ → common/ (merge i18n-config.json) - shims/ → common/shims/ (module alias shims) - utils/ → process/utils/ (main-process utilities) - assistant/ → process/assistant/ (static resources) - skills/ → process/skills/ (static resources) - Update all import paths and config references
- assistant/ + skills/ + builtinMcp/ → resources/ - database/ + i18n/ → services/ - 9 loose .ts files → utils/
…t paths globally Common directory restructure: - api/ ← adapters/, ApiKeyManager.ts, RotatingApiClient.ts, ClientFactory.ts - adapter/ ← keep + ipcBridge.ts - chat/ ← chatLib.ts, atCommandParser.ts, imageGenCore.ts, document/, slash/, navigation/, approval/ - config/ ← appEnv.ts, constants.ts, storage.ts, storageKeys.ts, presets/, i18n.ts, i18n-config.json - types/ ← keep + codex/ (flatten nested types/types/) - update/ ← keep + updateTypes.ts - utils/ ← keep + utils.ts + shims/ (add index.ts re-export) - index.ts Also fix 194 stale TS2307 module-not-found errors across the entire codebase: - Fix broken relative paths in process/bridge/, task/, services/, utils/ - Flatten bridge/index.ts subdirectory references (system/, conversation/, agent/, data/, platform/) - Fix task/ internal paths (managers/, worker/, middleware/ subdirs removed) - Convert deep relative paths to @/ and @process/ absolute aliases - Add process/utils/index.ts re-export barrel - Update all test file import paths - Fix dynamic import() and type-position import() paths
- fsBridge.ts: add 'assistant' to ResourceType union for dev path resolution - AcpConfigSelector.tsx: fix type annotation Set<AcpBackend> instead of AcpBackend[]
Adopt main's full-coverage strategy with updated paths for new directory structure: - src/shims/** → src/common/utils/shims/** - src/types/** → src/common/types/** - src/shared/** → src/common/config/i18n-config.json
- architecture/SKILL.md: update decision tree paths to src/process/ - pr-review/SKILL.md: update priority order paths - codecov.yml: update ignore paths (shims→common/utils/shims, types→common/types) - renderer/main.tsx: fix adapter/browser import to @/common/adapter/browser
- Fix i18n scripts path: src/shared/ → src/common/config/ (generate-i18n-types.js, check-i18n.js) - Add ES2023 lib to tsconfig.json for toSorted/toReversed support - Fix oxfmt formatting across 29 files - Fix circular dependency in src/process/utils/ (utils.ts ↔ initStorage.ts) - Fix stale mock paths in tests after directory restructuring: - @/process/initStorage → @process/utils/initStorage - @/webserver → @process/webserver - @process/message → @process/utils/message - @process/task/worker/workerTaskManagerSingleton → @process/task/workerTaskManagerSingleton - Add missing electron mock properties (app, ipcMain) in webuiConfig and cronService tests - Update src/shared references in AGENTS.md, i18n skill, and architecture skill docs
piorpua
approved these changes
Mar 20, 2026
kaizhou-lab
pushed a commit
that referenced
this pull request
Mar 20, 2026
The refactoring in PR #1583 changed `import { getSystemDir } from './initStorage'` to a lazy `require('./initStorage')` to break a circular dependency. However, Vite/Rollup does not transform dynamic `require()` relative paths in bundled output, causing `copyFilesToDirectory` to throw "Cannot find module './initStorage'" at runtime when `files` is a non-empty or empty array (not undefined). This broke the second message in ACP conversations because the first message passes `files: undefined` (skipping the require), while subsequent messages pass `files: []` (empty array), which reaches the broken require call. Replace `require('./initStorage')` with a static import. The circular dependency between utils.ts and initStorage.ts is safe because `getSystemDir` is only called at runtime inside function bodies, not during module initialization. This matches the pre-refactor behavior that worked correctly.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/directory structure to comply with the 10-item-per-directory conventionsrc/process/and shared modules undersrc/common/Changes
Phase 1: Module Migration into
src/process/worker/,webserver/,channels/,extensions/,agent/fromsrc/root intosrc/process/@worker/,@process/)Phase 2: Root Directory Cleanup
types/,shared/,adapter/,models/and loose files intosrc/common/assistant/,skills/,builtinMcp/intosrc/process/Phase 3: Documentation Updates
docs/tech/architecture.md,docs/conventions/file-structure.md,AGENTS.mdPhase 4: Sub-directory Reorganization
src/process/(24 → 11 items): mergeassistant/+skills/+builtinMcp/→resources/,database/+i18n/→services/, 9 loose.tsfiles →utils/src/common/(28 → 8 items): createapi/,chat/,config/groups; flatten nestedtypes/types/Phase 5: Global Path Fixes
@process/aliases, dynamic importsindex.tsforcommon/utils/andprocess/utils/Directory Structure (After)
Related Issue
Closes #1582
Test Plan
bunx tsc --noEmit— 0 errors (down from 194 TS2307)bun run test— 92/100 test files pass, 1109/1130 tests passelectron-vite buildsucceeds