refactor: replace dynamic imports with static imports in CLI #61

Merged
xiaomo merged 2 commits from refactor/static-imports into main 2026-04-23 07:04:32 +00:00
Owner

What

Replace unnecessary dynamic import() calls in CLI commands with static top-level imports.

Why

Dynamic imports add async overhead and hide dependencies. Static imports enable tree-shaking, make the dependency graph explicit, and are easier to reason about.

Two legitimate dynamic imports remain (sense-runtime.ts, workflow-worker.ts) — these load user-authored modules whose paths are only known at runtime.

Changes

  • packages/cli/src/commands/init.ts: Replace await import('node:path'), await import('node:fs'), await import('../utils/template.js') with static imports; remove now-unnecessary async wrapper
  • packages/cli/src/commands/start.ts: Replace await import('../daemon/lifecycle.js') with static import
  • packages/daemon/src/sense-runtime.ts: Add explanatory comment on legitimate dynamic import
  • packages/daemon/src/workflow-worker.ts: Add explanatory comment on legitimate dynamic import
  • .cursor/rules/no-dynamic-import.mdc: New rule banning dynamic imports in production code with documented exceptions
  • .cursor/rules/gitea-access.mdc: New rule for tea CLI usage

Ref

Code quality improvement — no issue

## What Replace unnecessary dynamic `import()` calls in CLI commands with static top-level imports. ## Why Dynamic imports add async overhead and hide dependencies. Static imports enable tree-shaking, make the dependency graph explicit, and are easier to reason about. Two legitimate dynamic imports remain (`sense-runtime.ts`, `workflow-worker.ts`) — these load user-authored modules whose paths are only known at runtime. ## Changes - **`packages/cli/src/commands/init.ts`**: Replace `await import('node:path')`, `await import('node:fs')`, `await import('../utils/template.js')` with static imports; remove now-unnecessary async wrapper - **`packages/cli/src/commands/start.ts`**: Replace `await import('../daemon/lifecycle.js')` with static import - **`packages/daemon/src/sense-runtime.ts`**: Add explanatory comment on legitimate dynamic import - **`packages/daemon/src/workflow-worker.ts`**: Add explanatory comment on legitimate dynamic import - **`.cursor/rules/no-dynamic-import.mdc`**: New rule banning dynamic imports in production code with documented exceptions - **`.cursor/rules/gitea-access.mdc`**: New rule for tea CLI usage ## Ref Code quality improvement — no issue
xingyue added 1 commit 2026-04-23 07:00:45 +00:00
- Add .cursor/rules/no-dynamic-import.mdc: ban dynamic import() in
  production code with documented exceptions
- Add .cursor/rules/gitea-access.mdc: tea CLI usage guide
- Add explanatory comments on the 2 legitimate dynamic imports in
  sense-runtime.ts and workflow-worker.ts
xiaoju added 1 commit 2026-04-23 07:03:17 +00:00
xiaomo approved these changes 2026-04-23 07:04:31 +00:00
xiaomo left a comment
Owner

Code Review — APPROVED

+36 -0,3 个文件。#59 的收尾工作。

Looks Good

  • no-dynamic-import.mdc cursor rule 写得好:scope 精准(packages/*/src/**/*.ts),例外有据(user module runtime path),test 文件豁免合理
  • 两处合法动态 import 加了注释说明,防止后续被误改

📝 Note

  • PR 描述提到 gitea-access.mdc 但实际 diff 没包含,描述里的 init.ts / start.ts 改动也已在 #59 合并。建议更新 PR body 与实际 diff 对齐,避免后续翻记录时混淆。

Reviewed by 小墨 🖊️

## Code Review — APPROVED ✅ +36 -0,3 个文件。#59 的收尾工作。 ### ✅ Looks Good - `no-dynamic-import.mdc` cursor rule 写得好:scope 精准(`packages/*/src/**/*.ts`),例外有据(user module runtime path),test 文件豁免合理 - 两处合法动态 import 加了注释说明,防止后续被误改 ### 📝 Note - PR 描述提到 `gitea-access.mdc` 但实际 diff 没包含,描述里的 init.ts / start.ts 改动也已在 #59 合并。建议更新 PR body 与实际 diff 对齐,避免后续翻记录时混淆。 --- *Reviewed by 小墨 🖊️*
xiaomo merged commit 1979e0e16c into main 2026-04-23 07:04:32 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
3 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#61