@spaceflow/core 0.8.0 → 0.10.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.
Files changed (87) hide show
  1. package/README.md +75 -56
  2. package/dist/index.js +5589 -970
  3. package/dist/index.js.map +1 -1
  4. package/package.json +9 -3
  5. package/src/cli-runtime/di/config.ts +157 -0
  6. package/src/cli-runtime/di/container.ts +120 -0
  7. package/src/cli-runtime/di/index.ts +3 -0
  8. package/src/cli-runtime/di/services.ts +53 -0
  9. package/src/cli-runtime/extension-loader.ts +74 -0
  10. package/src/{shared → cli-runtime}/i18n/index.ts +7 -1
  11. package/src/cli-runtime/i18n/init.ts +117 -0
  12. package/src/cli-runtime/index.ts +131 -0
  13. package/src/cli-runtime/internal-extensions.ts +33 -0
  14. package/src/commands/build/build.service.ts +323 -0
  15. package/src/commands/build/index.ts +49 -0
  16. package/src/commands/clear/clear.service.ts +159 -0
  17. package/src/commands/clear/index.ts +35 -0
  18. package/src/commands/commit/commit.config.ts +168 -0
  19. package/src/commands/commit/commit.service.ts +950 -0
  20. package/src/commands/commit/index.ts +58 -0
  21. package/src/commands/create/create.service.ts +318 -0
  22. package/src/commands/create/index.ts +42 -0
  23. package/src/commands/dev/index.ts +30 -0
  24. package/src/commands/install/index.ts +65 -0
  25. package/src/commands/install/install.service.ts +1539 -0
  26. package/src/commands/list/index.ts +33 -0
  27. package/src/commands/list/list.service.ts +127 -0
  28. package/src/commands/mcp/index.ts +37 -0
  29. package/src/commands/mcp/mcp.service.ts +246 -0
  30. package/src/commands/runx/index.ts +47 -0
  31. package/src/commands/runx/runx.service.ts +142 -0
  32. package/src/commands/runx/runx.utils.ts +83 -0
  33. package/src/commands/schema/index.ts +30 -0
  34. package/src/commands/setup/index.ts +34 -0
  35. package/src/commands/setup/setup.service.ts +234 -0
  36. package/src/commands/uninstall/index.ts +42 -0
  37. package/src/commands/uninstall/uninstall.service.ts +166 -0
  38. package/src/commands/update/index.ts +42 -0
  39. package/src/commands/update/update.service.ts +373 -0
  40. package/src/config/index.ts +1 -30
  41. package/src/config/spaceflow.config.ts +226 -278
  42. package/src/index.ts +11 -1
  43. package/src/locales/en/build.json +22 -0
  44. package/src/locales/en/clear.json +16 -0
  45. package/src/locales/en/commit.json +45 -0
  46. package/src/locales/en/create.json +27 -0
  47. package/src/locales/en/dev.json +5 -0
  48. package/src/locales/en/install.json +71 -0
  49. package/src/locales/en/list.json +8 -0
  50. package/src/locales/en/mcp.json +19 -0
  51. package/src/locales/en/runx.json +13 -0
  52. package/src/locales/en/schema.json +4 -0
  53. package/src/locales/en/setup.json +14 -0
  54. package/src/locales/en/uninstall.json +18 -0
  55. package/src/locales/en/update.json +28 -0
  56. package/src/locales/zh-cn/build.json +22 -0
  57. package/src/locales/zh-cn/clear.json +16 -0
  58. package/src/locales/zh-cn/commit.json +45 -0
  59. package/src/locales/zh-cn/create.json +27 -0
  60. package/src/locales/zh-cn/dev.json +5 -0
  61. package/src/locales/zh-cn/install.json +71 -0
  62. package/src/locales/zh-cn/list.json +8 -0
  63. package/src/locales/zh-cn/mcp.json +19 -0
  64. package/src/locales/zh-cn/runx.json +13 -0
  65. package/src/locales/zh-cn/schema.json +4 -0
  66. package/src/locales/zh-cn/setup.json +14 -0
  67. package/src/locales/zh-cn/uninstall.json +18 -0
  68. package/src/locales/zh-cn/update.json +28 -0
  69. package/src/shared/editor-config/index.ts +2 -21
  70. package/src/shared/llm-proxy/adapters/openai.adapter.ts +3 -1
  71. package/src/shared/package-manager/index.ts +5 -76
  72. package/src/shared/source-utils/index.ts +12 -130
  73. package/src/shared/spaceflow-dir/index.ts +13 -135
  74. package/src/shared/verbose/index.ts +10 -87
  75. package/dist/524.js +0 -9
  76. package/src/config/ci.config.ts +0 -29
  77. package/src/config/config-loader.ts +0 -100
  78. package/src/config/config-reader.service.ts +0 -128
  79. package/src/config/config-reader.ts +0 -75
  80. package/src/config/feishu.config.ts +0 -35
  81. package/src/config/git-provider.config.ts +0 -29
  82. package/src/config/llm.config.ts +0 -110
  83. package/src/config/load-env.ts +0 -15
  84. package/src/config/storage.config.ts +0 -33
  85. /package/src/{shared → cli-runtime}/i18n/i18n.spec.ts +0 -0
  86. /package/src/{shared → cli-runtime}/i18n/i18n.ts +0 -0
  87. /package/src/{shared → cli-runtime}/i18n/locale-detect.ts +0 -0
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@spaceflow/core?color=blue)](https://www.npmjs.com/package/@spaceflow/core)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- > Spaceflow 核心能力库,提供共享模块、扩展系统基础设施和平台适配层。
6
+ > Spaceflow 核心运行时,包含 CLI 运行时引擎、13 个内置命令、扩展系统和共享模块。
7
7
 
8
8
  ## 安装
9
9
 
@@ -11,71 +11,96 @@
11
11
  pnpm add @spaceflow/core
12
12
  ```
13
13
 
14
- ## 共享模块
14
+ ## 核心职责
15
15
 
16
- 核心库导出以下共享模块,供扩展开发使用:
17
-
18
- | 模块 | 导入路径 | 说明 |
19
- | ----------------- | --------------------------------- | ----------------------------------------- |
20
- | `git-provider` | `@spaceflow/core` | Git 平台适配器(GitHub / Gitea / GitLab) |
21
- | `git-sdk` | `@spaceflow/core` | Git 命令操作封装 |
22
- | `llm-proxy` | `@spaceflow/core/llm-proxy` | 多 LLM 适配器(OpenAI、Claude、Gemini) |
23
- | `llm-jsonput` | `@spaceflow/core/llm-jsonput` | LLM JSON 结构化输出 |
24
- | `feishu-sdk` | `@spaceflow/core` | 飞书 API 操作封装 |
25
- | `storage` | `@spaceflow/core` | 通用存储服务 |
26
- | `logger` | `@spaceflow/core` | 日志系统(TUI / Plain 双模式) |
27
- | `parallel` | `@spaceflow/core/parallel` | 并行执行工具 |
28
- | `verbose` | `@spaceflow/core/verbose` | 日志级别控制 |
29
- | `editor-config` | `@spaceflow/core/editor-config` | 编辑器配置管理 |
30
- | `source-utils` | `@spaceflow/core/source-utils` | 源码工具 |
31
- | `package-manager` | `@spaceflow/core/package-manager` | 包管理器抽象 |
32
- | `rspack-config` | `@spaceflow/core/rspack-config` | Rspack 构建配置 |
16
+ - **CLI 运行时** — `exec()` 入口函数,初始化 i18n、ServiceContainer、ExtensionLoader,构建 Commander 命令树
17
+ - **13 个内置命令** — install、uninstall、build、dev、create、update、list、clear、runx、schema、commit、setup、mcp
18
+ - **扩展系统** `defineExtension()` 纯函数式 API、类型定义(`ExtensionDefinition`、`CommandDefinition`、`SpaceflowContext`)
19
+ - **共享模块** Git、LLM、Logger、Storage 等服务
33
20
 
34
21
  ## 快速上手
35
22
 
36
23
  ```typescript
24
+ // 扩展开发 — 使用 defineExtension 定义扩展
25
+ import { defineExtension, t } from "@spaceflow/core";
26
+
27
+ export default defineExtension({
28
+ name: "my-extension",
29
+ commands: [
30
+ {
31
+ name: "hello",
32
+ description: "Say hello",
33
+ run: async (args, options, ctx) => {
34
+ ctx.output.info("Hello from my extension!");
35
+ },
36
+ },
37
+ ],
38
+ });
39
+ ```
40
+
41
+ ```typescript
42
+ // 共享模块 — 直接导入使用
37
43
  import {
38
44
  GitProviderService,
39
45
  GitSdkService,
40
46
  LlmProxyService,
41
47
  FeishuSdkService,
42
- StorageService,
43
- Logger,
44
-
45
- // NestJS 重导出
46
- Command,
47
- CommandRunner,
48
- Module,
49
- Injectable,
48
+ LoggerService,
49
+ ParallelService,
50
50
  } from "@spaceflow/core";
51
51
  ```
52
52
 
53
+ ## 共享模块
54
+
55
+ | 模块 | 说明 |
56
+ | ------------ | ----------------------------------------- |
57
+ | Git Provider | Git 平台适配器(GitHub / Gitea / GitLab) |
58
+ | Git SDK | Git 命令操作封装 |
59
+ | LLM Proxy | 多 LLM 统一代理(OpenAI、Claude) |
60
+ | Logger | 日志系统(TUI / Plain 双模式) |
61
+ | Feishu SDK | 飞书 API 操作封装 |
62
+ | Storage | 通用存储服务(支持 TTL) |
63
+ | Parallel | 并行执行工具 |
64
+ | i18n | 国际化(i18next) |
65
+
53
66
  ## 目录结构
54
67
 
55
68
  ```text
56
69
  core/
57
70
  ├── src/
71
+ │ ├── cli-runtime/ # CLI 运行时引擎
72
+ │ │ ├── exec.ts # exec() 入口
73
+ │ │ ├── service-container.ts # DI 容器
74
+ │ │ ├── extension-loader.ts # 扩展加载器
75
+ │ │ └── internal-extensions.ts # 内置扩展注册
76
+ │ ├── commands/ # 13 个内置命令
77
+ │ │ ├── build/
78
+ │ │ ├── clear/
79
+ │ │ ├── commit/
80
+ │ │ ├── create/
81
+ │ │ ├── dev/
82
+ │ │ ├── install/
83
+ │ │ ├── list/
84
+ │ │ ├── mcp/
85
+ │ │ ├── runx/
86
+ │ │ ├── schema/
87
+ │ │ ├── setup/
88
+ │ │ ├── uninstall/
89
+ │ │ └── update/
58
90
  │ ├── config/ # 配置管理(Zod Schema)
59
91
  │ ├── extension-system/ # 扩展系统核心
60
- │ ├── locales/ # 国际化资源(i18next)
61
- │ ├── shared/ # 共享模块
62
- │ │ ├── git-provider/ # Git 平台适配器
63
- │ │ └── adapters/ # GitHub / Gitea / GitLab 实现
64
- │ ├── git-sdk/ # Git 命令封装
65
- ├── llm-proxy/ # LLM 统一代理
66
- ├── llm-jsonput/ # JSON 结构化输出
67
- ├── feishu-sdk/ # 飞书 SDK
68
- ├── logger/ # 日志系统(TUI/Plain)
69
- ├── parallel/ # 并行执行工具
70
- ├── storage/ # 通用存储服务
71
- │ ├── editor-config/ # 编辑器配置管理
72
- │ │ ├── verbose/ # 日志级别控制
73
- │ │ ├── source-utils/ # 源码工具
74
- │ │ ├── package-manager/ # 包管理器抽象
75
- │ │ └── rspack-config/ # Rspack 构建配置
76
- │ ├── app.module.ts # NestJS 根模块
77
- │ └── index.ts # 库导出入口
78
- └── test/ # E2E 测试
92
+ ├── types.ts # ExtensionDefinition 等类型
93
+ ├── define-extension.ts # defineExtension 工厂函数
94
+ │ │ └── extension.interface.ts # package.json spaceflow 字段解析
95
+ ├── locales/ # 国际化资源(en + zh-cn)
96
+ └── shared/ # 共享模块
97
+ ├── git-provider/ # Git 平台适配器
98
+ ├── git-sdk/ # Git 命令封装
99
+ ├── llm-proxy/ # LLM 统一代理
100
+ ├── feishu-sdk/ # 飞书 SDK
101
+ ├── logger/ # 日志系统(TUI/Plain)
102
+ ├── parallel/ # 并行执行工具
103
+ └── storage/ # 通用存储服务
79
104
  ```
80
105
 
81
106
  ## 开发
@@ -84,20 +109,14 @@ core/
84
109
  # 构建
85
110
  pnpm run build
86
111
 
87
- # 测试
88
- pnpm run test
89
-
90
- # 代码检查
91
- pnpm run lint
92
-
93
- # 代码格式化
94
- pnpm run format
112
+ # 类型检查
113
+ pnpm run type-check
95
114
  ```
96
115
 
97
116
  ## 技术栈
98
117
 
99
- - **NestJS** — 依赖注入框架
100
- - **nest-commander** — CLI 命令框架
118
+ - **Commander.js** — CLI 命令框架
119
+ - **ServiceContainer** — 自定义 DI 容器
101
120
  - **Rspack** — 构建工具
102
121
  - **i18next** — 国际化
103
122
  - **Zod** — 配置校验