@simoonfish/df-cli 1.0.5 → 1.0.6
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/dist/commands/install.js +2 -2
- package/dist/commands/sync.js +66 -31
- package/dist/config.d.ts +10 -2
- package/dist/config.js +45 -3
- package/package.json +1 -1
package/dist/commands/install.js
CHANGED
|
@@ -3,7 +3,7 @@ import chalk from "chalk";
|
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import { readConfig, findBinding,
|
|
6
|
+
import { readConfig, findBinding, resolvePlatform, getSkillInstallDir, getKnowledgeInstallDir, SUPPORTED_PLATFORMS } from "../config.js";
|
|
7
7
|
import { api } from "../api/client.js";
|
|
8
8
|
export const installCommand = new Command("install")
|
|
9
9
|
.description("安装指定 Skill 或知识库到工作区")
|
|
@@ -53,7 +53,7 @@ async function installSkill(config, binding, name, opts) {
|
|
|
53
53
|
process.exit(1);
|
|
54
54
|
}
|
|
55
55
|
// Platform compatibility check
|
|
56
|
-
const currentPlatform =
|
|
56
|
+
const currentPlatform = resolvePlatform(opts.platform, binding);
|
|
57
57
|
const skillPlatform = skill.platform || "claude_code";
|
|
58
58
|
if (skillPlatform !== currentPlatform && !opts.force) {
|
|
59
59
|
spinner.warn(`Skill "${skill.name}" 的目标平台是 ${chalk.cyan(skillPlatform)},` +
|
package/dist/commands/sync.js
CHANGED
|
@@ -3,13 +3,14 @@ import chalk from "chalk";
|
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import { readConfig, writeConfig, findBinding, getSkillInstallDir, getKnowledgeInstallDir, getDevForgeDir, getRuleFileName, getRulesCacheDir } from "../config.js";
|
|
6
|
+
import { readConfig, writeConfig, findBinding, getSkillInstallDir, getKnowledgeInstallDir, getDevForgeDir, getRuleFileName, getRulesCacheDir, resolvePlatform, cleanupBindingArtifacts } from "../config.js";
|
|
7
7
|
import { api } from "../api/client.js";
|
|
8
8
|
export const syncCommand = new Command("sync")
|
|
9
9
|
.description("绑定工作区并同步 Skill + 知识库到本地")
|
|
10
10
|
.option("--local-dir <path>", "指定本地工程目录(默认当前目录)")
|
|
11
|
-
.option("--workspace-id <id>", "工作区 ID
|
|
12
|
-
.option("--workspace <name>", "
|
|
11
|
+
.option("--workspace-id <id>", "工作区 ID(首次绑定时必填,重新绑定时更新)")
|
|
12
|
+
.option("--workspace <name>", "工作区名称(按名称搜索)")
|
|
13
|
+
.option("--platform <name>", "目标 AI 编码平台 (claude_code | codex),覆盖绑定上的平台")
|
|
13
14
|
.option("--skills", "仅同步 Skill")
|
|
14
15
|
.option("--knowledge", "仅同步知识库")
|
|
15
16
|
.action(async (opts) => {
|
|
@@ -21,41 +22,75 @@ export const syncCommand = new Command("sync")
|
|
|
21
22
|
process.exit(1);
|
|
22
23
|
}
|
|
23
24
|
const localDir = opts.localDir || process.cwd();
|
|
25
|
+
const platformOverride = opts.platform;
|
|
24
26
|
let binding = findBinding(config, localDir);
|
|
25
|
-
// ──
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
spinner.
|
|
39
|
-
|
|
40
|
-
if (!res.data?.length) {
|
|
41
|
-
spinner.fail(`未找到名为 "${workspaceName}" 的工作区`);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
wsId = res.data[0].id;
|
|
45
|
-
wsName = res.data[0].name;
|
|
27
|
+
// ── 解析目标工作区(如果命令行指定了 --workspace-id / --workspace)────────
|
|
28
|
+
let targetWsId;
|
|
29
|
+
let targetWsName;
|
|
30
|
+
if (opts.workspaceId) {
|
|
31
|
+
targetWsId = Number(opts.workspaceId);
|
|
32
|
+
spinner.text = "查询工作区...";
|
|
33
|
+
const ws = await api.getWorkspace(targetWsId);
|
|
34
|
+
targetWsName = ws.data?.name || `工作区 #${targetWsId}`;
|
|
35
|
+
}
|
|
36
|
+
else if (opts.workspace) {
|
|
37
|
+
spinner.text = `搜索工作区 "${opts.workspace}"...`;
|
|
38
|
+
const res = await api.get(`/workspaces?keyword=${encodeURIComponent(opts.workspace)}&pageSize=5`);
|
|
39
|
+
if (!res.data?.length) {
|
|
40
|
+
spinner.fail(`未找到名为 "${opts.workspace}" 的工作区`);
|
|
41
|
+
process.exit(1);
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
targetWsId = res.data[0].id;
|
|
44
|
+
targetWsName = res.data[0].name;
|
|
45
|
+
}
|
|
46
|
+
// ── 检测变更 & 执行清理 ──────────────────────────────────────
|
|
47
|
+
const workspaceChanged = binding && targetWsId && binding.workspace_id !== targetWsId;
|
|
48
|
+
const platformChanged = binding && platformOverride && resolvePlatform(undefined, binding) !== platformOverride;
|
|
49
|
+
let needsCleanup = workspaceChanged || platformChanged;
|
|
50
|
+
if (!binding) {
|
|
51
|
+
// ── 首次绑定 ─────────────────────────────────────────────
|
|
52
|
+
if (!targetWsId) {
|
|
48
53
|
spinner.fail("当前目录未绑定工作区,请通过 --workspace-id 或 --workspace 指定");
|
|
49
54
|
process.exit(1);
|
|
50
55
|
}
|
|
51
|
-
binding = {
|
|
56
|
+
binding = {
|
|
57
|
+
local_dir: localDir,
|
|
58
|
+
workspace_id: targetWsId,
|
|
59
|
+
workspace_name: targetWsName,
|
|
60
|
+
platform: platformOverride,
|
|
61
|
+
};
|
|
52
62
|
config.bindings.push(binding);
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
spinner.succeed(`已绑定工作区: ${targetWsName} (ID: ${targetWsId})`);
|
|
64
|
+
}
|
|
65
|
+
else if (needsCleanup) {
|
|
66
|
+
// ── 重新绑定(清理旧产物 → 更新绑定)────────────────────────
|
|
67
|
+
const oldPlatform = platformChanged ? resolvePlatform(undefined, binding) : undefined;
|
|
68
|
+
const oldWsLabel = workspaceChanged
|
|
69
|
+
? `${binding.workspace_name} (ID: ${binding.workspace_id})`
|
|
70
|
+
: "";
|
|
71
|
+
spinner.start("清理旧的同步数据...");
|
|
72
|
+
cleanupBindingArtifacts(localDir, workspaceChanged ? undefined : oldPlatform);
|
|
73
|
+
spinner.succeed("旧的同步数据已清理");
|
|
74
|
+
if (workspaceChanged) {
|
|
75
|
+
console.log(chalk.yellow(` 工作区变更: ${oldWsLabel} → ${targetWsName} (ID: ${targetWsId})`));
|
|
76
|
+
binding.workspace_id = targetWsId;
|
|
77
|
+
binding.workspace_name = targetWsName;
|
|
78
|
+
binding.last_synced = undefined;
|
|
79
|
+
}
|
|
80
|
+
if (platformOverride) {
|
|
81
|
+
binding.platform = platformOverride;
|
|
82
|
+
}
|
|
83
|
+
spinner.succeed(`已重新绑定工作区: ${binding.workspace_name} (ID: ${binding.workspace_id})`);
|
|
55
84
|
}
|
|
56
85
|
else {
|
|
86
|
+
// 无变更 — 仅更新 platform 空值(若未设置且命令行传入)
|
|
87
|
+
if (platformOverride && !binding.platform) {
|
|
88
|
+
binding.platform = platformOverride;
|
|
89
|
+
}
|
|
57
90
|
spinner.succeed(`已定位工作区: ${binding.workspace_name} (ID: ${binding.workspace_id})`);
|
|
58
91
|
}
|
|
92
|
+
// ── 确定生效平台(供写入规则文件时使用)─────────────────────────
|
|
93
|
+
const effectivePlatform = resolvePlatform(undefined, binding);
|
|
59
94
|
// ── 同步到 local-dir/.devforge ────────────────────────────
|
|
60
95
|
mkdirSync(getDevForgeDir(binding.local_dir), { recursive: true });
|
|
61
96
|
const syncAll = !opts.skills && !opts.knowledge;
|
|
@@ -127,15 +162,14 @@ export const syncCommand = new Command("sync")
|
|
|
127
162
|
spinner.succeed(`知识库同步完成 (${kbCount} 个)`);
|
|
128
163
|
}
|
|
129
164
|
let ruleCount = 0;
|
|
130
|
-
// Sync Rule — 写入工程根目录的 CLAUDE.md / .cursorrules
|
|
165
|
+
// Sync Rule — 写入工程根目录的 CLAUDE.md / .cursorrules / AGENTS.md
|
|
131
166
|
if (syncAll || opts.rules) {
|
|
132
167
|
spinner.start(`同步 AI 编码规则...`);
|
|
133
168
|
try {
|
|
134
169
|
const res = await api.getWorkspaceRule(binding.workspace_id);
|
|
135
170
|
const rule = res.data;
|
|
136
171
|
if (rule?.content) {
|
|
137
|
-
const
|
|
138
|
-
const fileName = getRuleFileName(platform);
|
|
172
|
+
const fileName = getRuleFileName(effectivePlatform);
|
|
139
173
|
const rulePath = join(localDir, fileName);
|
|
140
174
|
writeFileSync(rulePath, rule.content, "utf-8");
|
|
141
175
|
ruleCount = 1;
|
|
@@ -170,6 +204,7 @@ export const syncCommand = new Command("sync")
|
|
|
170
204
|
detail: JSON.stringify({ skills: skillCount, knowledge: kbCount, rules: ruleCount }),
|
|
171
205
|
});
|
|
172
206
|
console.log(chalk.gray(` 工作区: ${binding.workspace_name} (ID: ${binding.workspace_id})`));
|
|
207
|
+
console.log(chalk.gray(` 平台: ${chalk.cyan(effectivePlatform)}`));
|
|
173
208
|
console.log(chalk.green(` 同步完成 — Skill ${skillCount}, 知识库 ${kbCount}`));
|
|
174
209
|
}
|
|
175
210
|
catch (e) {
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export interface Binding {
|
|
|
2
2
|
local_dir: string;
|
|
3
3
|
workspace_id: number;
|
|
4
4
|
workspace_name: string;
|
|
5
|
+
/** 绑定到当前目录时的目标 AI 编码平台,留空则使用全局配置/环境变量/默认值 */
|
|
6
|
+
platform?: string;
|
|
5
7
|
last_synced?: string;
|
|
6
8
|
}
|
|
7
9
|
export interface DevForgeConfig {
|
|
@@ -16,8 +18,14 @@ export type SupportedPlatform = (typeof SUPPORTED_PLATFORMS)[number];
|
|
|
16
18
|
export declare function ensureConfigDir(): void;
|
|
17
19
|
export declare function readConfig(): DevForgeConfig | null;
|
|
18
20
|
export declare function writeConfig(config: DevForgeConfig): void;
|
|
19
|
-
/**
|
|
20
|
-
export declare function
|
|
21
|
+
/** 确定目标 AI 编码平台。优先级: 显示传入 > 绑定上的平台 > 全局配置 > 环境变量 > 默认 claude_code */
|
|
22
|
+
export declare function resolvePlatform(override?: string, binding?: Binding): string;
|
|
23
|
+
/**
|
|
24
|
+
* 清理绑定残留的同步产物。
|
|
25
|
+
* 工作区间切换时: 删除所有可能遗留的内容(知识库、规则缓存、规则文件、项目级 skill)。
|
|
26
|
+
* 平台切换时: 仅清理特定平台的文件。
|
|
27
|
+
*/
|
|
28
|
+
export declare function cleanupBindingArtifacts(localDir: string, oldPlatform?: string): void;
|
|
21
29
|
export declare function findBinding(config: DevForgeConfig, localDir?: string): Binding | null;
|
|
22
30
|
export declare function getWorkspaceDir(workspaceId: number): string;
|
|
23
31
|
export declare function ensureWorkspaceDir(workspaceId: number): string;
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
const CONFIG_DIR = join(homedir(), ".devforge");
|
|
@@ -23,11 +23,14 @@ export function writeConfig(config) {
|
|
|
23
23
|
ensureConfigDir();
|
|
24
24
|
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
export function
|
|
26
|
+
/** 确定目标 AI 编码平台。优先级: 显示传入 > 绑定上的平台 > 全局配置 > 环境变量 > 默认 claude_code */
|
|
27
|
+
export function resolvePlatform(override, binding) {
|
|
28
28
|
if (override && SUPPORTED_PLATFORMS.includes(override)) {
|
|
29
29
|
return override;
|
|
30
30
|
}
|
|
31
|
+
if (binding?.platform && SUPPORTED_PLATFORMS.includes(binding.platform)) {
|
|
32
|
+
return binding.platform;
|
|
33
|
+
}
|
|
31
34
|
const config = readConfig();
|
|
32
35
|
if (config?.platform && SUPPORTED_PLATFORMS.includes(config.platform)) {
|
|
33
36
|
return config.platform;
|
|
@@ -38,6 +41,45 @@ export function getPlatform(override) {
|
|
|
38
41
|
}
|
|
39
42
|
return "claude_code";
|
|
40
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* 清理绑定残留的同步产物。
|
|
46
|
+
* 工作区间切换时: 删除所有可能遗留的内容(知识库、规则缓存、规则文件、项目级 skill)。
|
|
47
|
+
* 平台切换时: 仅清理特定平台的文件。
|
|
48
|
+
*/
|
|
49
|
+
export function cleanupBindingArtifacts(localDir, oldPlatform) {
|
|
50
|
+
// 知识库目录(按工作区隔离,始终清理)
|
|
51
|
+
const kbDir = getKnowledgeInstallDir(localDir);
|
|
52
|
+
if (existsSync(kbDir))
|
|
53
|
+
rmSync(kbDir, { recursive: true, force: true });
|
|
54
|
+
// 规则元数据缓存(始终清理)
|
|
55
|
+
const rulesDir = getRulesCacheDir(localDir);
|
|
56
|
+
if (existsSync(rulesDir))
|
|
57
|
+
rmSync(rulesDir, { recursive: true, force: true });
|
|
58
|
+
if (oldPlatform) {
|
|
59
|
+
// 已知旧平台 → 只删除该平台的规则文件
|
|
60
|
+
const rulePath = join(localDir, getRuleFileName(oldPlatform));
|
|
61
|
+
if (existsSync(rulePath))
|
|
62
|
+
rmSync(rulePath, { force: true });
|
|
63
|
+
// 只删除该平台的项目级技能
|
|
64
|
+
const skillDir = getSkillInstallDir(localDir, "project", oldPlatform);
|
|
65
|
+
if (existsSync(skillDir))
|
|
66
|
+
rmSync(skillDir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// 不知道旧平台 → 扫一遍所有已知的规则文件名
|
|
70
|
+
for (const fileName of Object.values(RULE_FILE_NAMES)) {
|
|
71
|
+
const rulePath = join(localDir, fileName);
|
|
72
|
+
if (existsSync(rulePath))
|
|
73
|
+
rmSync(rulePath, { force: true });
|
|
74
|
+
}
|
|
75
|
+
// 与规则文件名列表同源遍历所有平台的项目级技能目录
|
|
76
|
+
for (const plat of Object.keys(RULE_FILE_NAMES)) {
|
|
77
|
+
const skillDir = getSkillInstallDir(localDir, "project", plat);
|
|
78
|
+
if (existsSync(skillDir))
|
|
79
|
+
rmSync(skillDir, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
41
83
|
export function findBinding(config, localDir) {
|
|
42
84
|
const dir = localDir || process.cwd();
|
|
43
85
|
return config.bindings.find((b) => b.local_dir === dir) || null;
|