@namewta/speculo 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/template/skills/typescript-engineering-standards/README.md +36 -0
  4. package/template/skills/typescript-engineering-standards/SKILL.md +158 -0
  5. package/template/skills/typescript-engineering-standards/examples/comment-patterns.md +47 -0
  6. package/template/skills/typescript-engineering-standards/examples/naming-patterns.md +42 -0
  7. package/template/skills/typescript-engineering-standards/examples/project-layouts.md +75 -0
  8. package/template/skills/typescript-engineering-standards/examples/review-output-example.md +25 -0
  9. package/template/skills/typescript-engineering-standards/examples/type-modeling-patterns.md +66 -0
  10. package/template/skills/typescript-engineering-standards/manifest.txt +33 -0
  11. package/template/skills/typescript-engineering-standards/references/00-standard-levels-and-precedence.md +51 -0
  12. package/template/skills/typescript-engineering-standards/references/01-project-architecture-and-directory-layout.md +105 -0
  13. package/template/skills/typescript-engineering-standards/references/02-file-directory-and-symbol-naming.md +117 -0
  14. package/template/skills/typescript-engineering-standards/references/03-modules-imports-exports-and-dependencies.md +111 -0
  15. package/template/skills/typescript-engineering-standards/references/04-typescript-type-system.md +150 -0
  16. package/template/skills/typescript-engineering-standards/references/05-functions-async-errors-and-resources.md +142 -0
  17. package/template/skills/typescript-engineering-standards/references/06-comments-jsdoc-and-documentation.md +104 -0
  18. package/template/skills/typescript-engineering-standards/references/07-testing-strategy.md +84 -0
  19. package/template/skills/typescript-engineering-standards/references/08-react-and-frontend.md +91 -0
  20. package/template/skills/typescript-engineering-standards/references/09-node-cli-and-cross-platform.md +92 -0
  21. package/template/skills/typescript-engineering-standards/references/10-formatting-lint-and-complexity.md +107 -0
  22. package/template/skills/typescript-engineering-standards/references/11-configuration-dependencies-and-ci.md +86 -0
  23. package/template/skills/typescript-engineering-standards/references/12-security-performance-and-i18n.md +65 -0
  24. package/template/skills/typescript-engineering-standards/references/13-git-review-and-delivery.md +79 -0
  25. package/template/skills/typescript-engineering-standards/references/14-adoption-exceptions-and-migration.md +84 -0
  26. package/template/skills/typescript-engineering-standards/references/15-orca-derived-observations.md +54 -0
  27. package/template/skills/typescript-engineering-standards/references/README.md +45 -0
  28. package/template/skills/typescript-engineering-standards/templates/.editorconfig +12 -0
  29. package/template/skills/typescript-engineering-standards/templates/AGENTS.typescript.md +21 -0
  30. package/template/skills/typescript-engineering-standards/templates/code-review-checklist.md +37 -0
  31. package/template/skills/typescript-engineering-standards/templates/package-scripts.json +11 -0
  32. package/template/skills/typescript-engineering-standards/templates/prettier.json +6 -0
  33. package/template/skills/typescript-engineering-standards/templates/pull-request-template.md +37 -0
  34. package/template/skills/typescript-engineering-standards/templates/tsconfig.base.json +17 -0
  35. package/template/skills/typescript-engineering-standards/templates/tsconfig.project-references.json +8 -0
package/README.md CHANGED
@@ -49,7 +49,7 @@ After initialization, the target project gains the following AI agent-callable a
49
49
  | `retro` | Retrospective analysis with `gh issue` creation |
50
50
  | `status` | Summary of installed workflows, active changes, and anomalies |
51
51
 
52
- ### 6 Skills
52
+ ### 7 Skills
53
53
 
54
54
  | Skill | Purpose |
55
55
  |---|---|
@@ -58,7 +58,8 @@ After initialization, the target project gains the following AI agent-callable a
58
58
  | `docs-sync` | Core documentation audit and synchronization |
59
59
  | `github-npm-ops` | GitHub issue/PR triage and npm operations |
60
60
  | `speculo-retro` | Retrospective analysis |
61
- | `dev-worktree` | Git worktree isolation for development |
61
+ | `typescript-engineering-standards` | Progressive TypeScript/JS/React/Node engineering standards with references, templates, and examples |
62
+ | `writing-great-skills` | Authoring guidance for agent skills |
62
63
 
63
64
  ### 2 Workflow Packages
64
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namewta/speculo",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Workflow-packaged specification-driven development assets with install, update, and migration tooling.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,36 @@
1
+ # TypeScript Engineering Standards Skill
2
+
3
+ 这是一个采用渐进式披露结构的通用 TypeScript 工程规范 Skill。
4
+
5
+ ## 使用方式
6
+
7
+ 将整个 `typescript-engineering-standards/` 目录放入支持 Skill 的目录中,并以 `SKILL.md` 作为入口。不同平台的 Skill 安装位置可能不同;保持目录内部相对路径不变即可。
8
+
9
+ ## 目录说明
10
+
11
+ ```text
12
+ typescript-engineering-standards/
13
+ ├── SKILL.md # 主入口:触发条件、工作流、参考路由
14
+ ├── references/ # 详细规范,按任务最小化读取
15
+ ├── templates/ # AGENTS、tsconfig、格式化、PR 与评审模板
16
+ ├── examples/ # 目录、命名、类型、注释和审查示例
17
+ └── manifest.txt # 包内文件清单
18
+ ```
19
+
20
+ ## 设计原则
21
+
22
+ - `SKILL.md` 保持相对精简,不承载所有细节。
23
+ - 详细规则按主题拆分到 `references/`。
24
+ - 执行具体任务时只读取必要参考。
25
+ - 模板是起点,不直接覆盖现有仓库配置。
26
+ - 用户要求、平台约束和仓库事实优先于通用默认规则。
27
+
28
+ ## 推荐入口
29
+
30
+ - 创建或审查项目目录:`references/01-project-architecture-and-directory-layout.md`
31
+ - 文件和标识符命名:`references/02-file-directory-and-symbol-naming.md`
32
+ - TypeScript 类型安全:`references/04-typescript-type-system.md`
33
+ - 注释和 JSDoc:`references/06-comments-jsdoc-and-documentation.md`
34
+ - 测试:`references/07-testing-strategy.md`
35
+ - 格式化、Lint、复杂度:`references/10-formatting-lint-and-complexity.md`
36
+ - CI 和质量门禁:`references/11-configuration-dependencies-and-ci.md`
@@ -0,0 +1,158 @@
1
+ ---
2
+ name: typescript-engineering-standards
3
+ description: 为 TypeScript、JavaScript、React、Node.js、Electron、CLI、npm 库与 Monorepo 项目提供可渐进加载的工程规范。用于新建项目、生成代码、目录设计、命名、类型建模、代码审查、重构、测试、Lint、CI、安全与质量门禁;详细规则按任务从 references/ 中最小化读取。
4
+ ---
5
+
6
+ # TypeScript Engineering Standards Skill
7
+
8
+ 本 Skill 将 TypeScript 工程规范拆成一个轻量主入口和多个主题参考文档。执行任务时采用**渐进式披露**:先判断任务类型,再只读取必要参考,避免把全部规范一次性加入上下文。
9
+
10
+ ## 适用任务
11
+
12
+ 在以下任务中使用本 Skill:
13
+
14
+ - 设计或调整 TypeScript 项目目录。
15
+ - 创建、重命名、移动 `.ts`、`.tsx`、测试或声明文件。
16
+ - 编写、补全、重构或审查 TypeScript/React/Node.js 代码。
17
+ - 制定团队编码规范、`AGENTS.md`、`CONTRIBUTING.md` 或 PR 检查清单。
18
+ - 配置 TypeScript、格式化、Lint、测试、构建与 CI。
19
+ - 处理类型安全、异步、错误、资源清理、安全、性能或跨平台问题。
20
+ - 对现有仓库做工程质量审计。
21
+
22
+ 不在以下场景机械套用:
23
+
24
+ - 用户明确指定了不同规范。
25
+ - 框架、生成器或公开 API 有不可违背的约定。
26
+ - 任务仅是解释一段代码且不涉及代码修改或规范判断。
27
+
28
+ ## 规则优先级
29
+
30
+ 发生冲突时依次遵循:
31
+
32
+ 1. 用户的明确要求。
33
+ 2. 当前仓库已生效的配置、公共 API 与框架约定。
34
+ 3. 当前模块已经形成且一致的局部惯例。
35
+ 4. 本 Skill 的通用默认规则。
36
+
37
+ 不要为了符合本 Skill 而进行与任务无关的大规模重命名、格式化或架构迁移。发现历史问题时,区分“本次必须修复”和“建议后续治理”。
38
+
39
+ ## 核心执行流程
40
+
41
+ ### 1. 识别任务和边界
42
+
43
+ 先判断:
44
+
45
+ - 项目类型:Web、React、Node.js、Electron、CLI、库或 Monorepo。
46
+ - 任务类型:新建、增量开发、重构、审查、修复、规范制定或配置。
47
+ - 运行边界:浏览器、服务端、主进程、预加载、Worker、测试环境。
48
+ - 变更范围:单文件、单领域、跨模块或全仓库。
49
+
50
+ ### 2. 检查仓库事实
51
+
52
+ 修改现有项目时,优先检查:
53
+
54
+ - `package.json` 与锁文件。
55
+ - `tsconfig*.json`。
56
+ - ESLint、Oxlint、Prettier、Oxfmt、Biome 等配置。
57
+ - 测试配置与现有测试命名。
58
+ - `src/` 目录结构、路径别名和导出方式。
59
+ - `AGENTS.md`、`CONTRIBUTING.md`、README 与 CI 工作流。
60
+
61
+ 不要假设项目使用 React、ESLint、Prettier、Vitest、Zod 或某种模块系统。
62
+
63
+ ### 3. 最小化读取参考文档
64
+
65
+ 仅加载与任务直接相关的参考文档。只有进行全仓库规范设计或综合审计时,才读取多个主题。
66
+
67
+ | 任务 | 首选参考 |
68
+ |---|---|
69
+ | 判断规则强度、处理冲突 | `references/00-standard-levels-and-precedence.md` |
70
+ | 设计目录、拆模块、平铺策略 | `references/01-project-architecture-and-directory-layout.md` |
71
+ | 文件、目录、变量、类型命名 | `references/02-file-directory-and-symbol-naming.md` |
72
+ | 导入、导出、Barrel、依赖方向 | `references/03-modules-imports-exports-and-dependencies.md` |
73
+ | 类型、`unknown`、联合、声明文件 | `references/04-typescript-type-system.md` |
74
+ | 函数、异步、错误、资源生命周期 | `references/05-functions-async-errors-and-resources.md` |
75
+ | 注释、JSDoc、TODO、文档 | `references/06-comments-jsdoc-and-documentation.md` |
76
+ | 单元、集成、契约、E2E 测试 | `references/07-testing-strategy.md` |
77
+ | React、Hook、状态、可访问性 | `references/08-react-and-frontend.md` |
78
+ | Node.js、CLI、路径、环境变量 | `references/09-node-cli-and-cross-platform.md` |
79
+ | 格式、Lint、文件大小、复杂度 | `references/10-formatting-lint-and-complexity.md` |
80
+ | 配置、依赖、脚本、CI | `references/11-configuration-dependencies-and-ci.md` |
81
+ | 安全、性能、国际化 | `references/12-security-performance-and-i18n.md` |
82
+ | Git、PR、评审和交付 | `references/13-git-review-and-delivery.md` |
83
+ | 老项目迁移、例外和渐进治理 | `references/14-adoption-exceptions-and-migration.md` |
84
+ | 了解 Orca 中提炼出的工程习惯 | `references/15-orca-derived-observations.md` |
85
+
86
+ 完整索引见 `references/README.md`。
87
+
88
+ ### 4. 应用核心默认规则
89
+
90
+ 除非仓库事实或用户要求另有规定,默认遵守:
91
+
92
+ - 先按运行环境和业务领域划分边界,领域内部局部平铺。
93
+ - 文件名表达“领域 + 职责”,避免 `utils`、`helpers`、`common`、`misc` 等模糊名称。
94
+ - 一个文件只有一个主要职责;不要为单个文件机械创建目录。
95
+ - 默认使用命名导出,控制公共 API,禁止无意义全局 Barrel。
96
+ - TypeScript 开启严格模式;外部输入先作为 `unknown` 并在边界验证。
97
+ - 优先使用可辨识联合表达状态,使无效状态难以构造。
98
+ - 所有 Promise、监听器、Timer、连接和进程都有明确处理与清理路径。
99
+ - 注释解释原因、约束与权衡,不逐行翻译代码。
100
+ - 单元测试靠近源码;跨模块集成与 E2E 测试放在独立测试目录。
101
+ - 通过格式化、Lint、类型检查、测试和构建形成自动化门禁。
102
+
103
+ ### 5. 生成或修改代码
104
+
105
+ 生成代码时:
106
+
107
+ - 遵循仓库现有模块系统和格式风格。
108
+ - 新公开函数写明确返回类型。
109
+ - 不引入未经请求的新框架或依赖。
110
+ - 不用 `any`、双重断言、规则禁用或删除测试掩盖问题。
111
+ - 需要外部验证时,在边界层完成,不把不可信类型传播到内部。
112
+ - 修复缺陷时优先补回归测试。
113
+ - 只修改任务相关文件,避免格式噪声。
114
+
115
+ ### 6. 审查和输出
116
+
117
+ 代码审查时按以下优先级报告:
118
+
119
+ 1. 正确性、安全和数据损坏风险。
120
+ 2. 类型系统未覆盖的运行时风险。
121
+ 3. 资源泄漏、竞态、取消与错误处理。
122
+ 4. 架构边界、循环依赖和公共 API。
123
+ 5. 测试缺口。
124
+ 6. 命名、文件大小和可维护性。
125
+ 7. 纯风格建议。
126
+
127
+ 每条问题尽量包含:位置、风险、触发条件、修复方向。不要把个人偏好描述成缺陷。
128
+
129
+ ## 常用模板
130
+
131
+ - 精简团队规则:`templates/AGENTS.typescript.md`
132
+ - 严格 TypeScript 基线:`templates/tsconfig.base.json`
133
+ - 多环境项目引用:`templates/tsconfig.project-references.json`
134
+ - 格式化基线:`templates/prettier.json`
135
+ - 编辑器基线:`templates/.editorconfig`
136
+ - npm 脚本示例:`templates/package-scripts.json`
137
+ - PR 模板:`templates/pull-request-template.md`
138
+ - 代码评审清单:`templates/code-review-checklist.md`
139
+
140
+ 模板是起点,不得在未检查项目工具链时直接覆盖现有配置。
141
+
142
+ ## 示例
143
+
144
+ - 项目目录示例:`examples/project-layouts.md`
145
+ - 命名模式示例:`examples/naming-patterns.md`
146
+ - 类型建模示例:`examples/type-modeling-patterns.md`
147
+ - 注释示例:`examples/comment-patterns.md`
148
+ - 审查输出示例:`examples/review-output-example.md`
149
+
150
+ ## 交付要求
151
+
152
+ 完成任务前确认:
153
+
154
+ - 变更符合当前仓库事实,而非仅符合抽象规范。
155
+ - 必要测试和质量检查已执行,或明确说明未能执行的项目。
156
+ - 没有增加无意义目录、模糊文件名或隐藏依赖。
157
+ - 没有通过削弱类型、关闭规则或跳过测试来获得表面通过。
158
+ - 输出聚焦本次任务;更广泛的治理建议单独列出,不混入必要修复。
@@ -0,0 +1,47 @@
1
+ # 注释模式示例
2
+
3
+ ## 兼容性
4
+
5
+ ```ts
6
+ // Why: Windows reports the executable path with inconsistent drive-letter casing.
7
+ const normalizedPath = normalizeWindowsDriveLetter(executablePath)
8
+ ```
9
+
10
+ ## 第三方缺陷
11
+
12
+ ```ts
13
+ // Why: SDK 4.2 can invoke this callback twice after cancellation.
14
+ if (requestState.isSettled) {
15
+ return
16
+ }
17
+ ```
18
+
19
+ ## 安全顺序
20
+
21
+ ```ts
22
+ // Validate before resolving the path so traversal segments cannot escape the root.
23
+ const safeRelativePath = parseRelativePath(input)
24
+ ```
25
+
26
+ ## 性能
27
+
28
+ ```ts
29
+ // Keep the compiled expression outside the hot loop; this runs for every log line.
30
+ const ansiPattern = createAnsiPattern()
31
+ ```
32
+
33
+ ## 不推荐
34
+
35
+ ```ts
36
+ // Loop through items.
37
+ for (const item of items) {
38
+ // Add the item.
39
+ results.push(item)
40
+ }
41
+ ```
42
+
43
+ ## TODO
44
+
45
+ ```ts
46
+ // TODO(PROJ-1423): Remove the v2 fallback after desktop 3.8 reaches 95% adoption.
47
+ ```
@@ -0,0 +1,42 @@
1
+ # 命名示例
2
+
3
+ ## 从模糊名称改为具体名称
4
+
5
+ | 模糊 | 推荐 |
6
+ |---|---|
7
+ | `utils.ts` | `shell-command-quote.ts` |
8
+ | `helpers.ts` | `workspace-path-normalize.ts` |
9
+ | `manager.ts` | `terminal-process-registry.ts` |
10
+ | `handler.ts` | `payment-webhook-handler.ts` |
11
+ | `service.ts` | `user-session-service.ts` |
12
+ | `data.ts` | `workspace-summary.ts` |
13
+ | `types.ts` | `payment-contract.ts` |
14
+ | `constants.ts` | `terminal-limits.ts` |
15
+
16
+ ## 函数
17
+
18
+ | 含义弱 | 推荐 |
19
+ |---|---|
20
+ | `handle()` | `handleWorkspaceClosed()` |
21
+ | `process()` | `parseTerminalOutput()` |
22
+ | `check()` | `validateWorkspacePath()` |
23
+ | `getData()` | `loadUserProfile()` |
24
+ | `doRetry()` | `retryPaymentCapture()` |
25
+
26
+ ## 布尔值
27
+
28
+ | 含义弱 | 推荐 |
29
+ |---|---|
30
+ | `flag` | `shouldPersist` |
31
+ | `enabled` | `isTelemetryEnabled` |
32
+ | `valid` | `isWorkspacePathValid` |
33
+ | `notReady` | `isInitializing` 或 `isReady` |
34
+
35
+ ## 单位
36
+
37
+ | 含义弱 | 推荐 |
38
+ |---|---|
39
+ | `timeout` | `timeoutMs` |
40
+ | `size` | `payloadSizeBytes` |
41
+ | `delay` | `retryDelayMs` |
42
+ | `limit` | `pageSizeLimit` |
@@ -0,0 +1,75 @@
1
+ # 项目目录示例
2
+
3
+ ## 小型 Node 服务
4
+
5
+ ```text
6
+ src/
7
+ ├── app/
8
+ │ ├── create-server.ts
9
+ │ └── load-environment.ts
10
+ ├── features/
11
+ │ └── user-auth/
12
+ │ ├── authenticate-user.ts
13
+ │ ├── authenticate-user.test.ts
14
+ │ └── user-token.ts
15
+ ├── infrastructure/
16
+ │ ├── database/
17
+ │ └── http/
18
+ └── shared/
19
+ └── result.ts
20
+ ```
21
+
22
+ ## React 应用
23
+
24
+ ```text
25
+ src/
26
+ ├── app/
27
+ │ ├── App.tsx
28
+ │ └── routes.tsx
29
+ ├── features/
30
+ │ ├── workspace-search/
31
+ │ │ ├── WorkspaceSearchPanel.tsx
32
+ │ │ ├── workspace-search-query.ts
33
+ │ │ └── use-workspace-search.ts
34
+ │ └── user-settings/
35
+ ├── shared/
36
+ │ ├── components/
37
+ │ └── hooks/
38
+ └── infrastructure/
39
+ └── api/
40
+ ```
41
+
42
+ `shared/components` 只放真正无业务归属且有多个真实调用方的组件。
43
+
44
+ ## Electron
45
+
46
+ ```text
47
+ src/
48
+ ├── main/
49
+ │ ├── app-lifecycle.ts
50
+ │ └── windows/
51
+ ├── preload/
52
+ │ └── workspace-api.ts
53
+ ├── renderer/
54
+ │ ├── app/
55
+ │ └── features/
56
+ ├── shared/
57
+ │ └── workspace-contract.ts
58
+ └── types/
59
+ └── electron-api.d.ts
60
+ ```
61
+
62
+ ## Monorepo
63
+
64
+ ```text
65
+ apps/
66
+ ├── web/
67
+ └── api/
68
+ packages/
69
+ ├── domain/
70
+ ├── contracts/
71
+ ├── ui/
72
+ └── test-support/
73
+ ```
74
+
75
+ 包边界应与独立发布、运行环境或稳定依赖方向对应,不要仅为缩短相对路径拆包。
@@ -0,0 +1,25 @@
1
+ # 代码审查输出示例
2
+
3
+ ## 阻塞问题
4
+
5
+ ### `src/features/workspace/load-workspace.ts:42`
6
+
7
+ `JSON.parse()` 的结果被直接断言为 `WorkspaceConfig`。当配置缺少 `rootPath` 时,错误会延迟到文件系统调用,并可能访问错误位置。
8
+
9
+ 建议在配置边界使用 Schema 验证,将解析函数返回类型固定为已验证的 `WorkspaceConfig`,并补充缺失字段和路径穿越测试。
10
+
11
+ ## 重要问题
12
+
13
+ ### `src/main/process-registry.ts:88`
14
+
15
+ 关闭窗口时只移除了事件监听器,没有终止仍在运行的子进程。重复打开窗口会留下孤儿进程。
16
+
17
+ 建议让注册函数返回统一 `dispose()`,在窗口关闭和应用退出两个路径都调用,并增加清理回归测试。
18
+
19
+ ## 建议
20
+
21
+ ### `src/features/search/utils.ts`
22
+
23
+ 该文件同时包含查询解析、排序和本地存储。当前功能仍正确,但后续修改会持续扩大职责。
24
+
25
+ 建议在下一次触及该模块时拆为 `search-query-parser.ts`、`search-result-sort.ts` 和 `search-history-storage.ts`。本问题不必阻塞当前仅修复文案的变更。
@@ -0,0 +1,66 @@
1
+ # 类型建模示例
2
+
3
+ ## 状态机
4
+
5
+ 不推荐:
6
+
7
+ ```ts
8
+ type RequestState = {
9
+ isLoading: boolean
10
+ hasError: boolean
11
+ data?: Data
12
+ error?: Error
13
+ }
14
+ ```
15
+
16
+ 推荐:
17
+
18
+ ```ts
19
+ type RequestState =
20
+ | { kind: 'idle' }
21
+ | { kind: 'loading' }
22
+ | { kind: 'success'; data: Data }
23
+ | { kind: 'failure'; error: Error }
24
+ ```
25
+
26
+ ## 外部边界
27
+
28
+ ```ts
29
+ export function parseWorkspaceMessage(input: unknown): WorkspaceMessage {
30
+ return workspaceMessageSchema.parse(input)
31
+ }
32
+ ```
33
+
34
+ 内部代码只接收已经验证的 `WorkspaceMessage`。
35
+
36
+ ## `satisfies`
37
+
38
+ ```ts
39
+ const routes = {
40
+ home: '/',
41
+ settings: '/settings'
42
+ } satisfies Record<string, `/${string}`>
43
+ ```
44
+
45
+ 保留具体字面量,同时验证整体契约。
46
+
47
+ ## 结果类型
48
+
49
+ ```ts
50
+ type Result<TValue, TError> =
51
+ | { ok: true; value: TValue }
52
+ | { ok: false; error: TError }
53
+ ```
54
+
55
+ 适合调用方需要显式分支、失败属于正常业务结果的场景。不可恢复的程序错误仍可抛异常。
56
+
57
+ ## 单位类型
58
+
59
+ 高风险领域可使用品牌类型避免单位混用:
60
+
61
+ ```ts
62
+ type Milliseconds = number & { readonly __brand: 'Milliseconds' }
63
+ type Bytes = number & { readonly __brand: 'Bytes' }
64
+ ```
65
+
66
+ 仅在实际能降低错误且不会制造大量转换噪声时采用。
@@ -0,0 +1,33 @@
1
+ README.md
2
+ SKILL.md
3
+ examples/comment-patterns.md
4
+ examples/naming-patterns.md
5
+ examples/project-layouts.md
6
+ examples/review-output-example.md
7
+ examples/type-modeling-patterns.md
8
+ references/00-standard-levels-and-precedence.md
9
+ references/01-project-architecture-and-directory-layout.md
10
+ references/02-file-directory-and-symbol-naming.md
11
+ references/03-modules-imports-exports-and-dependencies.md
12
+ references/04-typescript-type-system.md
13
+ references/05-functions-async-errors-and-resources.md
14
+ references/06-comments-jsdoc-and-documentation.md
15
+ references/07-testing-strategy.md
16
+ references/08-react-and-frontend.md
17
+ references/09-node-cli-and-cross-platform.md
18
+ references/10-formatting-lint-and-complexity.md
19
+ references/11-configuration-dependencies-and-ci.md
20
+ references/12-security-performance-and-i18n.md
21
+ references/13-git-review-and-delivery.md
22
+ references/14-adoption-exceptions-and-migration.md
23
+ references/15-orca-derived-observations.md
24
+ references/README.md
25
+ templates/.editorconfig
26
+ templates/AGENTS.typescript.md
27
+ templates/code-review-checklist.md
28
+ templates/package-scripts.json
29
+ templates/prettier.json
30
+ templates/pull-request-template.md
31
+ templates/tsconfig.base.json
32
+ templates/tsconfig.project-references.json
33
+ manifest.txt
@@ -0,0 +1,51 @@
1
+ # 规则级别与优先顺序
2
+
3
+ ## 规范词义
4
+
5
+ - **必须**:影响正确性、安全、类型边界、资源生命周期或团队一致性的硬性要求。
6
+ - **应当**:绝大多数情况下适用;偏离时应有可说明的理由。
7
+ - **建议**:默认推荐,但可根据规模、框架和团队经验调整。
8
+ - **禁止**:高概率制造缺陷、隐藏风险或显著降低维护性的做法。
9
+
10
+ ## 冲突优先级
11
+
12
+ 从高到低:
13
+
14
+ 1. 用户明确要求和产品约束。
15
+ 2. 运行平台、框架、协议或公开 API 的硬约束。
16
+ 3. 已生效的仓库配置与自动化检查。
17
+ 4. 当前模块一致、可解释的局部惯例。
18
+ 5. 本 Skill 的默认规范。
19
+
20
+ ## 事实优先
21
+
22
+ 审查现有项目时,不要仅凭文件名或技术栈推断规则。应读取配置和相邻实现,确认:
23
+
24
+ - 模块系统是 ESM、CommonJS 还是打包器模式。
25
+ - 测试框架和测试命名。
26
+ - 格式化与 Lint 工具。
27
+ - 路径别名和包边界。
28
+ - React、Node、Electron 等运行环境。
29
+ - 哪些文件由代码生成器维护。
30
+
31
+ ## 一致性不是绝对理由
32
+
33
+ “项目一直这么写”不能自动证明做法正确。以下问题即使历史代码广泛存在,也应阻止继续扩散:
34
+
35
+ - 不可信输入未经验证。
36
+ - 敏感信息泄露。
37
+ - 无法清理的监听器、Timer、连接或进程。
38
+ - `any` 向公共 API 传播。
39
+ - 循环依赖或跨运行环境非法导入。
40
+ - 测试被删除、跳过或规则被关闭以掩盖失败。
41
+
42
+ 处理方式应以增量治理为主:新代码不继续引入,触及旧代码时适度修复,避免无关全仓库改写。
43
+
44
+ ## 建议与缺陷的区分
45
+
46
+ 代码审查中:
47
+
48
+ - 能导致错误、安全问题或维护阻塞的,标记为缺陷。
49
+ - 存在合理替代方案、但当前实现仍正确的,标记为建议。
50
+ - 纯偏好且仓库已有统一风格的,不应提出。
51
+ - 无法证明风险的猜测,应明确说明不确定性。
@@ -0,0 +1,105 @@
1
+ # 项目架构与目录布局
2
+
3
+ ## 先表达边界
4
+
5
+ 目录优先表达以下稳定边界之一:
6
+
7
+ - 运行环境:`main/`、`renderer/`、`server/`、`worker/`、`cli/`。
8
+ - 产品领域:`user-auth/`、`orders/`、`payments/`。
9
+ - 架构职责:`domain/`、`application/`、`infrastructure/`。
10
+ - 独立发布单元:`apps/`、`packages/`。
11
+
12
+ 不要在同一层混合互不相干的分类逻辑,例如同时出现全局 `components/`、`payments/`、`services/`、`cli/`。
13
+
14
+ ## 领域优先,技术类型局部化
15
+
16
+ 项目很小时可按技术类型组织;业务增长后应将技术目录移动到领域内部。
17
+
18
+ 推荐:
19
+
20
+ ```text
21
+ src/
22
+ ├── app/
23
+ ├── features/
24
+ │ ├── user-auth/
25
+ │ │ ├── login-service.ts
26
+ │ │ ├── login-service.test.ts
27
+ │ │ └── components/
28
+ │ └── payments/
29
+ ├── shared/
30
+ └── infrastructure/
31
+ ```
32
+
33
+ 不推荐长期维持:
34
+
35
+ ```text
36
+ src/
37
+ ├── components/
38
+ ├── hooks/
39
+ ├── services/
40
+ ├── types/
41
+ └── utils/
42
+ ```
43
+
44
+ ## 局部平铺
45
+
46
+ 一个职责明确的领域目录应默认平铺文件,不为每个文件建立同名目录。
47
+
48
+ 建议增加子目录的条件:
49
+
50
+ - 形成稳定、可命名的子领域。
51
+ - 同级实现文件长期超过约 8~12 个,定位成本明显上升。
52
+ - 文件组拥有独立入口、资源、测试夹具或生命周期。
53
+ - 文件组需要整体移动、替换或发布。
54
+ - 依赖方向或运行环境需要物理隔离。
55
+
56
+ 不要创建仅包含一个普通实现文件的目录,也不要为了对称而制造空层级。
57
+
58
+ ## `shared/` 准入
59
+
60
+ 代码进入共享层前应满足:
61
+
62
+ 1. 至少有两个真实调用方。
63
+ 2. 不依赖具体业务领域。
64
+ 3. 具有具体、可命名的能力。
65
+ 4. API 相对稳定。
66
+ 5. 不会造成反向依赖。
67
+ 6. 共享确实减少重复,而非提前抽象。
68
+
69
+ `shared/` 不是“不知道放哪里”的收容区。
70
+
71
+ ## 多运行环境
72
+
73
+ Electron、全栈、Worker 或混合运行环境项目应物理隔离:
74
+
75
+ ```text
76
+ src/
77
+ ├── main/
78
+ ├── preload/
79
+ ├── renderer/
80
+ ├── shared/
81
+ └── types/
82
+ ```
83
+
84
+ 要求:
85
+
86
+ - 各环境使用独立 `tsconfig` 或项目引用。
87
+ - 浏览器代码不导入 Node 专属模块。
88
+ - 服务端代码不无意依赖 DOM。
89
+ - 跨环境数据通过显式、可序列化契约。
90
+ - 桥接层 API 最小化,并验证来自外部边界的数据。
91
+
92
+ ## 推荐深度
93
+
94
+ 目录深度不是硬性指标,但从领域根目录到普通实现文件通常不应超过三层。深层目录往往表示过度分类、缺少领域命名或每文件一目录。
95
+
96
+ ## 拆分信号
97
+
98
+ 出现以下情况时考虑拆模块或拆包:
99
+
100
+ - 一个目录同时包含多个运行环境代码。
101
+ - 改动一个领域经常触发另一个无关领域。
102
+ - 同一目录的文件命名需要大量前缀才能区分。
103
+ - 公共入口不断扩大。
104
+ - 依赖图出现循环。
105
+ - 不同部分需要不同构建、发布或权限策略。