@spaceflow/review 0.39.0 → 0.41.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.40.0](https://github.com/Lydanne/spaceflow/compare/@spaceflow/review@0.39.0...@spaceflow/review@0.40.0) (2026-02-26)
4
+
5
+ ### 代码重构
6
+
7
+ * **cli:** 从配置文件读取扩展依赖,自动同步到 .spaceflow/package.json ([0f3a0ae](https://github.com/Lydanne/spaceflow/commit/0f3a0ae3f1e580b6fed627e29caf55d8207ece14))
8
+ * **cli:** 将 .env 加载提前至主流程最开始,确保子进程启动前环境变量已就绪 ([8851359](https://github.com/Lydanne/spaceflow/commit/88513596b52299c2f8262548fa60ec89d1c466f4))
9
+ * **cli:** 将 .spaceflow/bin/ 添加到 .gitignore,移除静态生成的入口文件 ([df01d2d](https://github.com/Lydanne/spaceflow/commit/df01d2d6a8dc647d8b067e3f529b0967b2a6eabd))
10
+ * **cli:** 改用 dynamic import 加载扩展,确保 i18n 在扩展模块执行前初始化 ([926286d](https://github.com/Lydanne/spaceflow/commit/926286d98d867a7521e7943e15d62952df35c017))
11
+ * **cli:** 重构配置和 .env 文件查找逻辑,支持从 cwd 向上遍历目录树 ([62a381b](https://github.com/Lydanne/spaceflow/commit/62a381bac340033ce0ff9c39afca82d7f8f20311))
12
+ * **config:** 将 .env 加载逻辑迁移至 shared 包,并在 CLI 壳子阶段提前加载 ([4c6b825](https://github.com/Lydanne/spaceflow/commit/4c6b825d44a98d1fec92ed6a4e17b74a79f7206d))
13
+ * **core:** 移除 ConfigReaderService,统一使用 IConfigReader 接口 ([ea9ed2b](https://github.com/Lydanne/spaceflow/commit/ea9ed2b9d35886f768eac9c6d1a50ca4fc79b67d))
14
+ * **core:** 重构 CLI 架构,将运行时逻辑迁移至 Core 包 ([6539795](https://github.com/Lydanne/spaceflow/commit/653979503d720c8a37f1731044e3c65ac2dd6e1c))
15
+ * **core:** 重构 i18n 模块结构,统一导出路径至 cli-runtime/i18n ([b49ae95](https://github.com/Lydanne/spaceflow/commit/b49ae95cf99a41a91f9018e141afb5bbfb6b8884))
16
+ * **mcp:** 移除重复的扩展加载逻辑,新增 TTY 检测避免手动运行时阻塞 ([51fb35f](https://github.com/Lydanne/spaceflow/commit/51fb35fab28c11cf8d297d7950c31a60bc4c4e2a))
17
+ * 调整构建顺序,优先构建 shared 包并排除其重复构建 ([d7cd392](https://github.com/Lydanne/spaceflow/commit/d7cd392ed6578acb1e6ee85ae2097d92d81e5efb))
18
+
19
+ ### 其他修改
20
+
21
+ * **cli:** released version 0.30.0 [no ci] ([7af2925](https://github.com/Lydanne/spaceflow/commit/7af292524349effcfc85a26cf3285dba7726b441))
22
+ * **core:** released version 0.9.0 [no ci] ([e4bd091](https://github.com/Lydanne/spaceflow/commit/e4bd091c3f3cb4ae675f4e594d0c651cea481bc5))
23
+ * **publish:** released version 0.32.0 [no ci] ([77a2800](https://github.com/Lydanne/spaceflow/commit/77a2800d9b001ebd2b502db59c9a5994e54665c9))
24
+ * **review-summary:** released version 0.9.0 [no ci] ([c1a2322](https://github.com/Lydanne/spaceflow/commit/c1a2322bb7535d15c63251ea515ee21ea7a4e1bf))
25
+ * **scripts:** released version 0.9.0 [no ci] ([8db4c68](https://github.com/Lydanne/spaceflow/commit/8db4c681b6a00bb9717f05aa809bb4e13bbb7e53))
26
+ * **shared:** released version 0.1.0 [no ci] ([243e31d](https://github.com/Lydanne/spaceflow/commit/243e31de49dbde605d5a16ec9f0d589792b9cc30))
27
+ * **shell:** released version 0.9.0 [no ci] ([b161fe1](https://github.com/Lydanne/spaceflow/commit/b161fe17aec13f59f0dbc04a7a2d392ba6740cca))
28
+
29
+ ## [0.39.0](https://github.com/Lydanne/spaceflow/compare/@spaceflow/review@0.38.0...@spaceflow/review@0.39.0) (2026-02-26)
30
+
31
+ ### 修复BUG
32
+
33
+ * **cli:** 自动安装扩展时根据命令行参数动态设置 verbose 级别 ([d2da6f5](https://github.com/Lydanne/spaceflow/commit/d2da6f5eb30425e48bb4fd924c73bb9237a437ab))
34
+
35
+ ### 其他修改
36
+
37
+ * **cli:** released version 0.29.0 [no ci] ([5fd87d3](https://github.com/Lydanne/spaceflow/commit/5fd87d31511d13d4937b1b1a247ad8a322d6fc9c))
38
+ * **publish:** released version 0.31.0 [no ci] ([e928d60](https://github.com/Lydanne/spaceflow/commit/e928d6061e05c03fc92303a246b2563a5100740b))
39
+ * **review-summary:** released version 0.8.0 [no ci] ([0e73a97](https://github.com/Lydanne/spaceflow/commit/0e73a97b035692b0fe7f59e36585cffccf6c6854))
40
+ * **scripts:** released version 0.8.0 [no ci] ([efea246](https://github.com/Lydanne/spaceflow/commit/efea246fe1bbd8815c7af44e8fd40df57a0219d6))
41
+ * **shell:** released version 0.8.0 [no ci] ([607b93b](https://github.com/Lydanne/spaceflow/commit/607b93bd911e3da102a73dd4513a4733b40c8672))
42
+
3
43
  ## [0.38.0](https://github.com/Lydanne/spaceflow/compare/@spaceflow/review@0.37.0...@spaceflow/review@0.38.0) (2026-02-26)
4
44
 
5
45
  ### 修复BUG
package/dist/index.js CHANGED
@@ -1009,7 +1009,6 @@ const REVIEW_SCHEMA = {
1009
1009
  class ReviewService {
1010
1010
  gitProvider;
1011
1011
  config;
1012
- configReader;
1013
1012
  reviewSpecService;
1014
1013
  llmProxyService;
1015
1014
  reviewReportService;
@@ -1017,10 +1016,9 @@ class ReviewService {
1017
1016
  deletionImpactService;
1018
1017
  gitSdk;
1019
1018
  llmJsonPut;
1020
- constructor(gitProvider, config, configReader, reviewSpecService, llmProxyService, reviewReportService, issueVerifyService, deletionImpactService, gitSdk){
1019
+ constructor(gitProvider, config, reviewSpecService, llmProxyService, reviewReportService, issueVerifyService, deletionImpactService, gitSdk){
1021
1020
  this.gitProvider = gitProvider;
1022
1021
  this.config = config;
1023
- this.configReader = configReader;
1024
1022
  this.reviewSpecService = reviewSpecService;
1025
1023
  this.llmProxyService = llmProxyService;
1026
1024
  this.reviewReportService = reviewReportService;
@@ -1049,7 +1047,7 @@ class ReviewService {
1049
1047
  });
1050
1048
  }
1051
1049
  async getContextFromEnv(options) {
1052
- const reviewConf = this.configReader.getPluginConfig("review");
1050
+ const reviewConf = this.config.getPluginConfig("review");
1053
1051
  const ciConf = this.config.get("ci");
1054
1052
  const repository = ciConf?.repository;
1055
1053
  if (options.ci) {
@@ -1476,7 +1474,7 @@ class ReviewService {
1476
1474
  }
1477
1475
  // 如果文件有变更,将该文件的历史问题标记为无效
1478
1476
  // 简化策略:避免复杂的行号更新逻辑
1479
- const reviewConf = this.configReader.getPluginConfig("review");
1477
+ const reviewConf = this.config.getPluginConfig("review");
1480
1478
  if (reviewConf.invalidateChangedFiles !== "off" && reviewConf.invalidateChangedFiles !== "keep") {
1481
1479
  existingIssues = await this.invalidateIssuesForChangedFiles(existingIssues, pr?.head?.sha, owner, repo, verbose);
1482
1480
  }
@@ -2413,7 +2411,7 @@ ${fileChanges || "无"}`;
2413
2411
  }
2414
2412
  async postOrUpdateReviewComment(owner, repo, prNumber, result, verbose) {
2415
2413
  // 获取配置
2416
- const reviewConf = this.configReader.getPluginConfig("review");
2414
+ const reviewConf = this.config.getPluginConfig("review");
2417
2415
  // 如果配置启用且有 AI 生成的标题,只在第一轮审查时更新 PR 标题
2418
2416
  if (reviewConf.autoUpdatePrTitle && result.title && result.round === 1) {
2419
2417
  try {
@@ -5203,14 +5201,13 @@ const extension = defineExtension({
5203
5201
  process.exit(1);
5204
5202
  }
5205
5203
  const gitProvider = ctx.getService("gitProvider");
5206
- const configReader = ctx.getService("config");
5207
5204
  const llmProxy = ctx.hasService("llmProxy") ? ctx.getService("llmProxy") : undefined;
5208
5205
  const gitSdk = ctx.hasService("gitSdk") ? ctx.getService("gitSdk") : undefined;
5209
5206
  const reviewSpecService = new ReviewSpecService(gitProvider);
5210
5207
  const reviewReportService = new ReviewReportService();
5211
5208
  const issueVerifyService = new IssueVerifyService(llmProxy, reviewSpecService);
5212
5209
  const deletionImpactService = new DeletionImpactService(llmProxy, gitProvider);
5213
- const reviewService = new ReviewService(gitProvider, ctx.config, configReader, reviewSpecService, llmProxy, reviewReportService, issueVerifyService, deletionImpactService, gitSdk);
5210
+ const reviewService = new ReviewService(gitProvider, ctx.config, reviewSpecService, llmProxy, reviewReportService, issueVerifyService, deletionImpactService, gitSdk);
5214
5211
  const reviewOptions = {
5215
5212
  dryRun: !!options?.dryRun,
5216
5213
  ci: !!options?.ci,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaceflow/review",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "Spaceflow 代码审查插件,使用 LLM 对 PR 代码进行自动审查",
5
5
  "license": "MIT",
6
6
  "author": "Lydanne",
@@ -25,10 +25,10 @@
25
25
  "@vitest/coverage-v8": "^4.0.18",
26
26
  "unplugin-swc": "^1.5.9",
27
27
  "vitest": "^4.0.18",
28
- "@spaceflow/cli": "0.29.0"
28
+ "@spaceflow/cli": "0.31.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@spaceflow/core": "0.8.0"
31
+ "@spaceflow/core": "0.10.0"
32
32
  },
33
33
  "spaceflow": {
34
34
  "type": "flow",
package/src/README.md CHANGED
@@ -1,14 +1,12 @@
1
- # Review 模块
1
+ # Review 扩展
2
2
 
3
- Review 是 spaceflow 的核心模块,提供基于 LLM 的自动化代码审查功能。支持在 GitHub Actions CI 环境中运行,也可在本地命令行使用。
3
+ Review 是 Spaceflow 的核心扩展,提供基于 LLM 的自动化代码审查功能。支持在 GitHub Actions CI 环境中运行,也可在本地命令行使用。
4
4
 
5
5
  ## 目录结构
6
6
 
7
7
  ```text
8
- review/
9
- ├── index.ts # 模块导出入口
10
- ├── review.module.ts # NestJS 模块定义
11
- ├── review.command.ts # CLI 命令定义
8
+ review/src/
9
+ ├── index.ts # Extension 入口(defineExtension)
12
10
  ├── review.service.ts # 核心审查服务
13
11
  ├── review.service.spec.ts # 审查服务单元测试
14
12
  ├── issue-verify.service.ts # 历史问题验证服务
@@ -19,17 +17,16 @@ review/
19
17
  ├── parse-title-options.spec.ts # 标题解析单元测试
20
18
  ```
21
19
 
22
- ## 模块依赖
20
+ ## 依赖的共享模块
23
21
 
24
22
  ```text
25
- ReviewModule
26
- ├── ConfigModule # 配置管理
27
- ├── GitProviderModule # Git Provider 适配器
28
- ├── ClaudeSetupModule # Claude CLI 配置
29
- ├── ReviewSpecModule # 审查规范加载
30
- ├── ReviewReportModule # 审查报告格式化
31
- ├── GitSdkModule # Git 命令封装
32
- └── LlmProxyModule # LLM 统一代理(支持 OpenAI/Claude/Gemini)
23
+ review extension
24
+ ├── GitProviderService # Git 平台适配器
25
+ ├── GitSdkService # Git 命令封装
26
+ ├── LlmProxyService # LLM 统一代理(OpenAI / Claude)
27
+ ├── LoggerService # 日志系统
28
+ ├── StorageService # 缓存存储
29
+ └── ParallelService # 并行执行
33
30
  ```
34
31
 
35
32
  ## 核心功能
@@ -234,50 +231,24 @@ feat: 添加新功能 [/ai-review -l openai -v 2]
234
231
 
235
232
  ## 配置项
236
233
 
237
- 在 `spaceflow.json` 中配置:
238
-
239
- ```javascript
240
- module.exports = {
241
- review: {
242
- // LLM 模式:claude-code, openai, gemini
243
- llmMode: "openai",
244
-
245
- // 文件过滤模式
246
- includes: ["**/*.ts", "**/*.js"],
247
-
248
- // 是否验证历史问题
249
- verifyFixes: true,
250
- verifyFixesConcurrency: 10,
251
-
252
- // 删除代码分析
253
- analyzeDeletions: false,
254
- deletionAnalysisMode: "openai",
255
-
256
- // 并发和超时配置
257
- concurrency: 5,
258
- timeout: 60000,
259
- retries: 0,
260
- retryDelay: 1000,
261
-
262
- // 是否生成 PR 描述
263
- generateDescription: false,
264
-
265
- // 是否启用行级评论
266
- lineComments: false,
267
-
268
- // OpenAI 配置
269
- openai: {
270
- apiKey: "sk-xxx",
271
- baseUrl: "https://api.openai.com/v1",
272
- model: "gpt-4o",
273
- },
274
-
275
- // Claude Code 配置
276
- claudeCode: {
277
- // Claude CLI 配置
278
- },
279
- },
280
- };
234
+ `.spaceflowrc` 或 `.spaceflow/spaceflow.json` 中配置 `review` 字段:
235
+
236
+ ```json
237
+ {
238
+ "review": {
239
+ "includes": ["*/**/*.ts", "!*/**/*.spec.*", "!*/**/*.config.*"],
240
+ "references": ["./references"],
241
+ "generateDescription": true,
242
+ "autoUpdatePrTitle": false,
243
+ "lineComments": true,
244
+ "verifyFixes": true,
245
+ "analyzeDeletions": false,
246
+ "deletionAnalysisMode": "open-code",
247
+ "concurrency": 10,
248
+ "retries": 3,
249
+ "retryDelay": 1000
250
+ }
251
+ }
281
252
  ```
282
253
 
283
254
  ## 使用示例
@@ -297,7 +268,7 @@ jobs:
297
268
  steps:
298
269
  - uses: actions/checkout@v4
299
270
  - name: Review
300
- run: npx spaceflow review --ci -l openai
271
+ run: pnpm spaceflow review --ci -l openai
301
272
  env:
302
273
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
303
274
  ```
@@ -306,26 +277,26 @@ jobs:
306
277
 
307
278
  ```bash
308
279
  # 审查 PR
309
- npx spaceflow review -p 123 -l openai
280
+ spaceflow review -p 123 -l openai
310
281
 
311
282
  # 审查两个分支之间的差异
312
- npx spaceflow review -b main --head feature/xxx -l openai
283
+ spaceflow review -b main --head feature/xxx -l openai
313
284
 
314
285
  # 仅审查指定文件
315
- npx spaceflow review -f src/app.ts -l openai
286
+ spaceflow review -f src/app.ts -l openai
316
287
 
317
288
  # 详细输出
318
- npx spaceflow review -p 123 -l openai -v 2
289
+ spaceflow review -p 123 -l openai -vv
319
290
 
320
291
  # 仅分析删除代码
321
- npx spaceflow review -p 123 --deletion-only -l openai
292
+ spaceflow review -p 123 --deletion-only -l openai
322
293
  ```
323
294
 
324
295
  ## 审查规范
325
296
 
326
- 审查规范文件位于 `.spaceflow/review-spec/` 目录,使用 Markdown 格式定义规则。
297
+ 审查规范文件通过配置文件的 `review.references` 字段指定,支持本地目录和远程 Git 仓库 URL。
327
298
 
328
- 详见 [ReviewSpec 模块文档](../../shared/review-spec/README.md)。
299
+ 详见 [Review Spec 规范](/reference/review-spec)。
329
300
 
330
301
  ## 输出格式
331
302
 
package/src/index.ts CHANGED
@@ -1,12 +1,6 @@
1
1
  import "./locales";
2
2
  import { defineExtension, t } from "@spaceflow/core";
3
- import type {
4
- GitProviderService,
5
- ConfigReaderService,
6
- LlmProxyService,
7
- GitSdkService,
8
- LLMMode,
9
- } from "@spaceflow/core";
3
+ import type { GitProviderService, LlmProxyService, GitSdkService, LLMMode } from "@spaceflow/core";
10
4
  import { parseVerbose } from "@spaceflow/core";
11
5
  import { reviewSchema, type AnalyzeDeletionsMode } from "./review.config";
12
6
  import { ReviewService } from "./review.service";
@@ -65,7 +59,6 @@ export const extension = defineExtension({
65
59
  }
66
60
 
67
61
  const gitProvider = ctx.getService<GitProviderService>("gitProvider");
68
- const configReader = ctx.getService<ConfigReaderService>("config");
69
62
  const llmProxy = ctx.hasService("llmProxy")
70
63
  ? ctx.getService<LlmProxyService>("llmProxy")
71
64
  : (undefined as unknown as LlmProxyService);
@@ -81,7 +74,6 @@ export const extension = defineExtension({
81
74
  const reviewService = new ReviewService(
82
75
  gitProvider,
83
76
  ctx.config,
84
- configReader,
85
77
  reviewSpecService,
86
78
  llmProxy,
87
79
  reviewReportService,
@@ -49,7 +49,6 @@ describe("ReviewService", () => {
49
49
  let mockDeletionImpactService: any;
50
50
  let mockGitSdkService: any;
51
51
  let mockLlmProxyService: any;
52
- let mockConfigReaderService: any;
53
52
 
54
53
  beforeEach(() => {
55
54
  vi.clearAllMocks();
@@ -80,6 +79,8 @@ describe("ReviewService", () => {
80
79
 
81
80
  configService = {
82
81
  get: vi.fn(),
82
+ getPluginConfig: vi.fn().mockReturnValue({}),
83
+ registerSchema: vi.fn(),
83
84
  };
84
85
 
85
86
  mockReviewSpecService = {
@@ -140,15 +141,9 @@ describe("ReviewService", () => {
140
141
  getAvailableAdapters: vi.fn().mockReturnValue(["claude-code", "openai"]),
141
142
  };
142
143
 
143
- mockConfigReaderService = {
144
- getPluginConfig: vi.fn().mockReturnValue({}),
145
- getSystemConfig: vi.fn().mockReturnValue({}),
146
- };
147
-
148
144
  service = new ReviewService(
149
145
  gitProvider as any,
150
146
  configService as any,
151
- mockConfigReaderService as any,
152
147
  mockReviewSpecService as any,
153
148
  mockLlmProxyService as any,
154
149
  mockReviewReportService as any,
@@ -1,12 +1,11 @@
1
1
  import {
2
- ConfigReaderService,
3
2
  GitProviderService,
4
3
  PullRequest,
5
4
  PullRequestCommit,
6
5
  ChangedFile,
7
6
  CreatePullReviewComment,
8
7
  REVIEW_STATE,
9
- CiConfig,
8
+ type CiConfig,
10
9
  type LLMMode,
11
10
  LlmProxyService,
12
11
  logStreamEvent,
@@ -145,7 +144,6 @@ export class ReviewService {
145
144
  constructor(
146
145
  protected readonly gitProvider: GitProviderService,
147
146
  protected readonly config: IConfigReader,
148
- protected readonly configReader: ConfigReaderService,
149
147
  protected readonly reviewSpecService: ReviewSpecService,
150
148
  protected readonly llmProxyService: LlmProxyService,
151
149
  protected readonly reviewReportService: ReviewReportService,
@@ -171,7 +169,7 @@ export class ReviewService {
171
169
  }
172
170
 
173
171
  async getContextFromEnv(options: ReviewOptions): Promise<ReviewContext> {
174
- const reviewConf = this.configReader.getPluginConfig<ReviewConfig>("review");
172
+ const reviewConf = this.config.getPluginConfig<ReviewConfig>("review");
175
173
  const ciConf = this.config.get<CiConfig>("ci");
176
174
  const repository = ciConf?.repository;
177
175
 
@@ -705,7 +703,7 @@ export class ReviewService {
705
703
 
706
704
  // 如果文件有变更,将该文件的历史问题标记为无效
707
705
  // 简化策略:避免复杂的行号更新逻辑
708
- const reviewConf = this.configReader.getPluginConfig<ReviewConfig>("review");
706
+ const reviewConf = this.config.getPluginConfig<ReviewConfig>("review");
709
707
  if (
710
708
  reviewConf.invalidateChangedFiles !== "off" &&
711
709
  reviewConf.invalidateChangedFiles !== "keep"
@@ -1864,7 +1862,7 @@ ${fileChanges || "无"}`;
1864
1862
  verbose?: VerboseLevel,
1865
1863
  ): Promise<void> {
1866
1864
  // 获取配置
1867
- const reviewConf = this.configReader.getPluginConfig<ReviewConfig>("review");
1865
+ const reviewConf = this.config.getPluginConfig<ReviewConfig>("review");
1868
1866
 
1869
1867
  // 如果配置启用且有 AI 生成的标题,只在第一轮审查时更新 PR 标题
1870
1868
  if (reviewConf.autoUpdatePrTitle && result.title && result.round === 1) {