@spaceflow/core 0.9.0 → 0.11.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/README.md +75 -56
- package/dist/index.js +14 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/cli-runtime/index.ts +18 -2
- package/src/commands/mcp/mcp.service.ts +5 -0
- package/src/locales/en/mcp.json +4 -2
- package/src/locales/zh-cn/mcp.json +4 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@spaceflow/core)
|
|
4
4
|
[](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
|
-
|
|
43
|
-
|
|
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
|
-
│ ├──
|
|
61
|
-
│ ├──
|
|
62
|
-
│ │
|
|
63
|
-
│
|
|
64
|
-
│
|
|
65
|
-
│
|
|
66
|
-
│
|
|
67
|
-
│
|
|
68
|
-
│
|
|
69
|
-
│
|
|
70
|
-
│
|
|
71
|
-
│
|
|
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
|
|
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
|
-
- **
|
|
100
|
-
- **
|
|
118
|
+
- **Commander.js** — CLI 命令框架
|
|
119
|
+
- **ServiceContainer** — 自定义 DI 容器
|
|
101
120
|
- **Rspack** — 构建工具
|
|
102
121
|
- **i18next** — 国际化
|
|
103
122
|
- **Zod** — 配置校验
|
package/dist/index.js
CHANGED
|
@@ -5471,9 +5471,9 @@ var list_namespaceObject = JSON.parse('{"description":"列出已安装的技能
|
|
|
5471
5471
|
;// CONCATENATED MODULE: ./src/locales/en/list.json
|
|
5472
5472
|
var en_list_namespaceObject = JSON.parse('{"description":"List installed skill packages","extensionDescription":"List installed plugins/skills","noSkills":"📦 No skill packages installed","installHint":"Install skill packages with:","installedExtensions":"📦 Installed extensions ({{installed}}/{{total}}):","commands":"Commands: {{commands}}"}')
|
|
5473
5473
|
;// CONCATENATED MODULE: ./src/locales/zh-cn/mcp.json
|
|
5474
|
-
var zh_cn_mcp_namespaceObject = JSON.parse('{"description":"启动 MCP Server,提供所有已安装扩展的 MCP 工具","options.inspector":"启动 MCP Inspector 进行交互式调试","inspectorStarting":"🔍 启动 MCP Inspector...","inspectorDebugCmd":" 调试命令: pnpm space mcp","inspectorFailed":"❌ 启动 MCP Inspector 失败: {{error}}","extensionDescription":"启动 MCP Server,提供所有已安装扩展的 MCP 工具","scanning":"🔍 扫描已安装的扩展...","foundExtensions":" 发现 {{count}} 个扩展","checkingExport":" 检查 {{key}}: __mcp_server__={{hasMcpServer}}","containerSuccess":" ✅ 从容器获取 {{key}} 实例成功","containerFailed":" ⚠️ 从容器获取 {{key}} 失败: {{error}}","loadToolsFailed":" ⚠️ {{name}}: 加载 MCP 工具失败","noToolsFound":"❌ 没有找到任何 MCP 工具","noToolsHint":" 提示: 确保已安装支持 MCP 的扩展,并导出 mcpService 或 getMcpTools","toolsFound":"✅ 共发现 {{count}} 个 MCP 工具","ttyHint":"💡 MCP Server 需要由 MCP 客户端(如 Cursor、Claude Desktop)通过管道启动。\\n 请将以下配置添加到你的 MCP 客户端中:\\n\\n \\"spaceflow\\": {\\n \\"command\\": \\"
|
|
5474
|
+
var zh_cn_mcp_namespaceObject = JSON.parse('{"description":"启动 MCP Server,提供所有已安装扩展的 MCP 工具","options.inspector":"启动 MCP Inspector 进行交互式调试","inspectorStarting":"🔍 启动 MCP Inspector...","inspectorDebugCmd":" 调试命令: pnpm space mcp","inspectorFailed":"❌ 启动 MCP Inspector 失败: {{error}}","extensionDescription":"启动 MCP Server,提供所有已安装扩展的 MCP 工具","cwdInfo":"📂 工作目录: {{cwd}}","cwdEnvHint":" 💡 可通过环境变量 SPACEFLOW_CWD 指定工作区路径","scanning":"🔍 扫描已安装的扩展...","foundExtensions":" 发现 {{count}} 个扩展","checkingExport":" 检查 {{key}}: __mcp_server__={{hasMcpServer}}","containerSuccess":" ✅ 从容器获取 {{key}} 实例成功","containerFailed":" ⚠️ 从容器获取 {{key}} 失败: {{error}}","loadToolsFailed":" ⚠️ {{name}}: 加载 MCP 工具失败","noToolsFound":"❌ 没有找到任何 MCP 工具","noToolsHint":" 提示: 确保已安装支持 MCP 的扩展,并导出 mcpService 或 getMcpTools\\n 如果工作目录不正确,请在 MCP 配置中设置环境变量:\\n \\"env\\": { \\"SPACEFLOW_CWD\\": \\"/path/to/your/project\\" }","toolsFound":"✅ 共发现 {{count}} 个 MCP 工具","ttyHint":"💡 MCP Server 需要由 MCP 客户端(如 Cursor、Claude Desktop)通过管道启动。\\n 请将以下配置添加到你的 MCP 客户端中:\\n\\n \\"spaceflow\\": {\\n \\"command\\": \\"npx\\",\\n \\"args\\": [\\"@spaceflow/cli\\", \\"mcp\\"],\\n \\"env\\": { \\"SPACEFLOW_CWD\\": \\"/path/to/your/project\\" }\\n }","serverStarted":"🚀 MCP Server 已启动,共 {{count}} 个工具"}')
|
|
5475
5475
|
;// CONCATENATED MODULE: ./src/locales/en/mcp.json
|
|
5476
|
-
var en_mcp_namespaceObject = JSON.parse('{"description":"Start MCP Server with all installed extension tools","options.inspector":"Start MCP Inspector for interactive debugging","inspectorStarting":"🔍 Starting MCP Inspector...","inspectorDebugCmd":" Debug command: pnpm space mcp","inspectorFailed":"❌ Failed to start MCP Inspector: {{error}}","extensionDescription":"Start MCP Server with all installed extension tools","scanning":"🔍 Scanning installed extensions...","foundExtensions":" Found {{count}} extensions","checkingExport":" Checking {{key}}: __mcp_server__={{hasMcpServer}}","containerSuccess":" ✅ Got {{key}} instance from container","containerFailed":" ⚠️ Failed to get {{key}} from container: {{error}}","loadToolsFailed":" ⚠️ {{name}}: Failed to load MCP tools","noToolsFound":"❌ No MCP tools found","noToolsHint":" Hint: Make sure you have installed MCP-enabled extensions that export mcpService or getMcpTools","toolsFound":"✅ Found {{count}} MCP tools","ttyHint":"💡 MCP Server must be started by an MCP client (e.g. Cursor, Claude Desktop) via pipe.\\n Add the following config to your MCP client:\\n\\n \\"spaceflow\\": {\\n \\"command\\": \\"
|
|
5476
|
+
var en_mcp_namespaceObject = JSON.parse('{"description":"Start MCP Server with all installed extension tools","options.inspector":"Start MCP Inspector for interactive debugging","inspectorStarting":"🔍 Starting MCP Inspector...","inspectorDebugCmd":" Debug command: pnpm space mcp","inspectorFailed":"❌ Failed to start MCP Inspector: {{error}}","extensionDescription":"Start MCP Server with all installed extension tools","cwdInfo":"📂 Working directory: {{cwd}}","cwdEnvHint":" 💡 Set SPACEFLOW_CWD environment variable to specify workspace path","scanning":"🔍 Scanning installed extensions...","foundExtensions":" Found {{count}} extensions","checkingExport":" Checking {{key}}: __mcp_server__={{hasMcpServer}}","containerSuccess":" ✅ Got {{key}} instance from container","containerFailed":" ⚠️ Failed to get {{key}} from container: {{error}}","loadToolsFailed":" ⚠️ {{name}}: Failed to load MCP tools","noToolsFound":"❌ No MCP tools found","noToolsHint":" Hint: Make sure you have installed MCP-enabled extensions that export mcpService or getMcpTools\\n If the working directory is incorrect, set the environment variable in your MCP config:\\n \\"env\\": { \\"SPACEFLOW_CWD\\": \\"/path/to/your/project\\" }","toolsFound":"✅ Found {{count}} MCP tools","ttyHint":"💡 MCP Server must be started by an MCP client (e.g. Cursor, Claude Desktop) via pipe.\\n Add the following config to your MCP client:\\n\\n \\"spaceflow\\": {\\n \\"command\\": \\"npx\\",\\n \\"args\\": [\\"@spaceflow/cli\\", \\"mcp\\"],\\n \\"env\\": { \\"SPACEFLOW_CWD\\": \\"/path/to/your/project\\" }\\n }","serverStarted":"🚀 MCP Server started with {{count}} tools"}')
|
|
5477
5477
|
;// CONCATENATED MODULE: ./src/locales/zh-cn/runx.json
|
|
5478
5478
|
var runx_namespaceObject = JSON.parse('{"description":"全局安装依赖并运行命令","options.name":"指定命令名称(默认从 source 自动提取)","noSource":"❌ 请指定要运行的依赖源","usage":" 用法: spaceflow x <source> [args...]","runFailed":"❌ 运行失败: {{error}}","extensionDescription":"执行插件提供的脚本命令","runningCommand":"▶️ 运行命令: {{command}}","npxExitCode":"npx {{package}} 退出码: {{code}}","commandNotInstalled":"命令 {{name}} 未安装","commandNotBuilt":"命令 {{name}} 未构建,缺少 dist/index.js","pluginNoExport":"插件 {{name}} 没有默认导出"}')
|
|
5479
5479
|
;// CONCATENATED MODULE: ./src/locales/en/runx.json
|
|
@@ -9906,6 +9906,13 @@ class McpService {
|
|
|
9906
9906
|
return;
|
|
9907
9907
|
}
|
|
9908
9908
|
if (shouldLog(verbose, 1)) {
|
|
9909
|
+
const cwd = process.env.SPACEFLOW_CWD || process.cwd();
|
|
9910
|
+
console.error(i18n_t("mcp:cwdInfo", {
|
|
9911
|
+
cwd
|
|
9912
|
+
}));
|
|
9913
|
+
if (!process.env.SPACEFLOW_CWD) {
|
|
9914
|
+
console.error(i18n_t("mcp:cwdEnvHint"));
|
|
9915
|
+
}
|
|
9909
9916
|
console.error(i18n_t("mcp:scanning"));
|
|
9910
9917
|
}
|
|
9911
9918
|
// 获取所有扩展(已在 exec() 阶段通过 registerExtension 注册完毕)
|
|
@@ -11239,12 +11246,7 @@ class UpdateService {
|
|
|
11239
11246
|
|
|
11240
11247
|
|
|
11241
11248
|
|
|
11242
|
-
|
|
11243
|
-
* Core.exec() — CLI 运行时入口
|
|
11244
|
-
* 接收外部扩展列表,结合内部扩展,构建并执行 commander 程序
|
|
11245
|
-
*
|
|
11246
|
-
* @param extensions 外部扩展定义列表(来自 .spaceflow/bin/index.js 的静态导入)
|
|
11247
|
-
*/ async function exec(extensions = []) {
|
|
11249
|
+
async function exec(extensions = [], options = {}) {
|
|
11248
11250
|
// 1. 初始化 i18n(如果尚未初始化,由生成的 bin/index.js 提前调用)
|
|
11249
11251
|
initCliI18n();
|
|
11250
11252
|
// 2. 创建并初始化服务容器
|
|
@@ -11263,7 +11265,10 @@ class UpdateService {
|
|
|
11263
11265
|
}
|
|
11264
11266
|
// 6. 创建 CLI 程序
|
|
11265
11267
|
const program = new Command();
|
|
11266
|
-
|
|
11268
|
+
const cliVersion = options.cliVersion || "0.0.0";
|
|
11269
|
+
const coreVersion = true ? "0.11.0" : 0;
|
|
11270
|
+
const versionOutput = `spaceflow/${cliVersion} core/${coreVersion}`;
|
|
11271
|
+
program.name("spaceflow").description("Spaceflow CLI").version(versionOutput, "-V, --version", "显示版本信息");
|
|
11267
11272
|
// 定义全局 verbose 选项(支持计数:-v, -vv, -vvv)
|
|
11268
11273
|
program.option("-v, --verbose", "详细输出(可叠加:-v, -vv, -vvv)", (_, prev)=>prev + 1, 0);
|
|
11269
11274
|
// 全局选项列表
|