ccjk 9.5.6 → 9.7.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/dist/chunks/agent.mjs +1 -1
- package/dist/chunks/api-providers.mjs +1 -1
- package/dist/chunks/api.mjs +3 -3
- package/dist/chunks/auto-bootstrap.mjs +1 -1
- package/dist/chunks/auto-updater.mjs +1 -1
- package/dist/chunks/boost.mjs +160 -0
- package/dist/chunks/ccjk-agents.mjs +1 -1
- package/dist/chunks/ccjk-all.mjs +1 -1
- package/dist/chunks/ccjk-config.mjs +1 -1
- package/dist/chunks/ccjk-hooks.mjs +1 -1
- package/dist/chunks/ccjk-mcp.mjs +2 -2
- package/dist/chunks/ccjk-setup.mjs +1 -1
- package/dist/chunks/ccjk-skills.mjs +1 -1
- package/dist/chunks/ccr.mjs +25 -30
- package/dist/chunks/ccu.mjs +1 -1
- package/dist/chunks/check-updates.mjs +3 -4
- package/dist/chunks/claude-code-config-manager.mjs +7 -7
- package/dist/chunks/claude-code-incremental-manager.mjs +2 -2
- package/dist/chunks/claude-config.mjs +4 -4
- package/dist/chunks/claude-wrapper.mjs +2 -2
- package/dist/chunks/codex-config-switch.mjs +4 -5
- package/dist/chunks/codex-provider-manager.mjs +2 -3
- package/dist/chunks/codex-uninstaller.mjs +2 -2
- package/dist/chunks/codex.mjs +207 -6
- package/dist/chunks/commands.mjs +391 -88
- package/dist/chunks/commands2.mjs +88 -391
- package/dist/chunks/completion.mjs +1 -1
- package/dist/chunks/config-consolidator.mjs +2 -2
- package/dist/chunks/config-switch.mjs +3 -4
- package/dist/chunks/config.mjs +78 -7
- package/dist/chunks/config2.mjs +400 -410
- package/dist/chunks/config3.mjs +410 -400
- package/dist/chunks/constants.mjs +1 -1
- package/dist/chunks/doctor.mjs +4 -4
- package/dist/chunks/features.mjs +24 -17
- package/dist/chunks/index.mjs +178 -7
- package/dist/chunks/index2.mjs +1162 -169
- package/dist/chunks/index3.mjs +910 -1076
- package/dist/chunks/index4.mjs +137 -947
- package/dist/chunks/index5.mjs +635 -167
- package/dist/chunks/init.mjs +141 -99
- package/dist/chunks/installer.mjs +147 -649
- package/dist/chunks/installer2.mjs +649 -147
- package/dist/chunks/interview.mjs +2 -2
- package/dist/chunks/marketplace.mjs +1 -1
- package/dist/chunks/mcp.mjs +1058 -17
- package/dist/chunks/menu.mjs +147 -56
- package/dist/chunks/monitor.mjs +2 -2
- package/dist/chunks/notification.mjs +1 -1
- package/dist/chunks/onboarding.mjs +2 -2
- package/dist/chunks/package.mjs +2 -210
- package/dist/chunks/permission-manager.mjs +2 -2
- package/dist/chunks/permissions.mjs +1 -1
- package/dist/chunks/platform.mjs +1 -1
- package/dist/chunks/plugin.mjs +1 -1
- package/dist/chunks/prompts.mjs +1 -1
- package/dist/chunks/providers.mjs +1 -1
- package/dist/chunks/quick-setup.mjs +16 -20
- package/dist/chunks/silent-updater.mjs +1 -1
- package/dist/chunks/simple-config.mjs +2 -2
- package/dist/chunks/skill.mjs +1 -1
- package/dist/chunks/skills-sync.mjs +1 -1
- package/dist/chunks/skills.mjs +1 -1
- package/dist/chunks/startup.mjs +1 -1
- package/dist/chunks/stats.mjs +1 -1
- package/dist/chunks/status.mjs +159 -0
- package/dist/chunks/team.mjs +1 -1
- package/dist/chunks/thinking.mjs +2 -2
- package/dist/chunks/uninstall.mjs +6 -6
- package/dist/chunks/update.mjs +6 -9
- package/dist/chunks/upgrade-manager.mjs +2 -2
- package/dist/chunks/version-checker.mjs +3 -3
- package/dist/chunks/vim.mjs +1 -1
- package/dist/chunks/workflows.mjs +616 -215
- package/dist/cli.mjs +70 -121
- package/dist/index.d.mts +17 -1482
- package/dist/index.d.ts +17 -1482
- package/dist/index.mjs +950 -4740
- package/dist/shared/{ccjk.zCqdxT2Y.mjs → ccjk.Br91zBIG.mjs} +2 -2
- package/dist/shared/ccjk.CSkyCZIM.mjs +638 -0
- package/dist/shared/{ccjk.BKoi8-Hy.mjs → ccjk.DE91nClQ.mjs} +1 -1
- package/dist/shared/{ccjk.f40us0yY.mjs → ccjk.DvIrK0wz.mjs} +2 -2
- package/dist/shared/ccjk.LsPZ2PYo.mjs +1048 -0
- package/dist/shared/{ccjk.DRweXU5F.mjs → ccjk.q1koQxEE.mjs} +2 -2
- package/package.json +1 -1
- package/templates/claude-code/common/settings.json +15 -111
- package/dist/chunks/api-adapter.mjs +0 -180
- package/dist/chunks/cli.mjs +0 -2227
- package/dist/chunks/context-menu.mjs +0 -913
- package/dist/chunks/hooks-sync.mjs +0 -1627
- package/dist/chunks/index6.mjs +0 -663
- package/dist/chunks/mcp-market.mjs +0 -1077
- package/dist/chunks/mcp-server.mjs +0 -776
- package/dist/chunks/project-detector.mjs +0 -131
- package/dist/chunks/provider-registry.mjs +0 -92
- package/dist/chunks/setup-wizard.mjs +0 -362
- package/dist/chunks/tools.mjs +0 -143
- package/dist/chunks/workflows2.mjs +0 -633
- package/dist/shared/ccjk.BM_HZogn.mjs +0 -347
- package/dist/shared/ccjk.BaEp4UHQ.mjs +0 -75
- package/dist/shared/ccjk.CS0ybJCf.mjs +0 -490
- package/dist/shared/ccjk.CZgIwikC.mjs +0 -209
- package/dist/shared/ccjk.tO8zeFh1.mjs +0 -397
package/dist/chunks/index3.mjs
CHANGED
|
@@ -1,1171 +1,1005 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import ansis from 'ansis';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import os__default from 'node:os';
|
|
5
|
+
import path__default from 'node:path';
|
|
6
|
+
import { exec } from 'node:child_process';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
5
8
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (since) {
|
|
10
|
-
gitCmd += ` ${since}..${until || "HEAD"}`;
|
|
11
|
-
}
|
|
12
|
-
gitCmd += ` -n ${limit}`;
|
|
13
|
-
try {
|
|
14
|
-
const output = execSync(gitCmd, { cwd, encoding: "utf-8" });
|
|
15
|
-
return parseGitLog(output);
|
|
16
|
-
} catch {
|
|
17
|
-
return [];
|
|
9
|
+
function getCcjkConfigDir() {
|
|
10
|
+
if (process.env.CCJK_CONFIG_DIR) {
|
|
11
|
+
return process.env.CCJK_CONFIG_DIR;
|
|
18
12
|
}
|
|
13
|
+
return path__default.join(os__default.homedir(), ".ccjk");
|
|
14
|
+
}
|
|
15
|
+
function getInstallPath(pluginType, name) {
|
|
16
|
+
const configDir = getCcjkConfigDir();
|
|
17
|
+
const typeDir = {
|
|
18
|
+
skill: "skills",
|
|
19
|
+
mcp: "mcp-servers",
|
|
20
|
+
agent: "agents",
|
|
21
|
+
hook: "hooks"
|
|
22
|
+
}[pluginType];
|
|
23
|
+
return path__default.join(configDir, typeDir, name);
|
|
19
24
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
const entries =
|
|
25
|
+
async function copyDirectory(src, dest) {
|
|
26
|
+
await fs.mkdir(dest, { recursive: true });
|
|
27
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
23
28
|
for (const entry of entries) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
continue;
|
|
31
|
-
const [hash, shortHash, message, author, date] = parts;
|
|
32
|
-
const files = fileLines.filter((f) => f.trim());
|
|
33
|
-
if (isFixCommit(message)) {
|
|
34
|
-
commits.push({
|
|
35
|
-
hash,
|
|
36
|
-
shortHash,
|
|
37
|
-
message,
|
|
38
|
-
author,
|
|
39
|
-
date,
|
|
40
|
-
files
|
|
41
|
-
});
|
|
29
|
+
const srcPath = path__default.join(src, entry.name);
|
|
30
|
+
const destPath = path__default.join(dest, entry.name);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
await copyDirectory(srcPath, destPath);
|
|
33
|
+
} else {
|
|
34
|
+
await fs.copyFile(srcPath, destPath);
|
|
42
35
|
}
|
|
43
36
|
}
|
|
44
|
-
return commits;
|
|
45
|
-
}
|
|
46
|
-
function isFixCommit(message) {
|
|
47
|
-
const fixPatterns = [
|
|
48
|
-
/^fix[(:]/i,
|
|
49
|
-
/^bugfix[(:]/i,
|
|
50
|
-
/^hotfix[(:]/i,
|
|
51
|
-
/\bfix\b/i,
|
|
52
|
-
/\bbug\b/i,
|
|
53
|
-
/\brepair\b/i,
|
|
54
|
-
/\bresolve\b/i,
|
|
55
|
-
/\bcorrect\b/i,
|
|
56
|
-
/修复/,
|
|
57
|
-
/修正/,
|
|
58
|
-
/解决/,
|
|
59
|
-
/bug/i
|
|
60
|
-
];
|
|
61
|
-
return fixPatterns.some((p) => p.test(message));
|
|
62
37
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
solution,
|
|
76
|
-
preventionSuggestions,
|
|
77
|
-
relatedPostmortems: []
|
|
78
|
-
};
|
|
38
|
+
async function downloadFile(url, destPath) {
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
headers: {
|
|
41
|
+
"User-Agent": "ccjk-cli"
|
|
42
|
+
},
|
|
43
|
+
redirect: "follow"
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`Failed to download: ${response.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
49
|
+
await fs.writeFile(destPath, buffer);
|
|
79
50
|
}
|
|
80
|
-
|
|
51
|
+
|
|
52
|
+
async function installFromGitHub(sourceInfo, pluginType, options = {}) {
|
|
53
|
+
const { force = false, dryRun = false } = options;
|
|
54
|
+
const { owner, repo, ref = "main", subpath } = sourceInfo;
|
|
81
55
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
56
|
+
const repoInfo = await fetchRepoInfo(owner, repo);
|
|
57
|
+
const defaultBranch = repoInfo.default_branch || "main";
|
|
58
|
+
const actualRef = ref || defaultBranch;
|
|
59
|
+
const installPath = getInstallPath(pluginType, repo);
|
|
60
|
+
if (!force) {
|
|
61
|
+
try {
|
|
62
|
+
await fs.access(installPath);
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
source: sourceInfo.originalUrl,
|
|
66
|
+
sourceType: "github",
|
|
67
|
+
pluginType,
|
|
68
|
+
error: `Plugin already exists at ${installPath}. Use --force to overwrite.`
|
|
69
|
+
};
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (dryRun) {
|
|
74
|
+
const files = await listRepoFiles(owner, repo, actualRef, subpath);
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
source: sourceInfo.originalUrl,
|
|
78
|
+
sourceType: "github",
|
|
79
|
+
pluginType,
|
|
80
|
+
installedPath: installPath,
|
|
81
|
+
details: {
|
|
82
|
+
name: repo,
|
|
83
|
+
version: actualRef,
|
|
84
|
+
description: repoInfo.description || void 0,
|
|
85
|
+
files: files.slice(0, 20)
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const tempDir = await downloadRepo(owner, repo, actualRef);
|
|
90
|
+
const sourcePath = subpath ? path__default.join(tempDir, subpath) : tempDir;
|
|
91
|
+
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
92
|
+
await copyDirectory(sourcePath, installPath);
|
|
93
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
94
|
+
const installedFiles = await listInstalledFiles$1(installPath);
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
source: sourceInfo.originalUrl,
|
|
98
|
+
sourceType: "github",
|
|
99
|
+
pluginType,
|
|
100
|
+
installedPath: installPath,
|
|
101
|
+
details: {
|
|
102
|
+
name: repo,
|
|
103
|
+
version: actualRef,
|
|
104
|
+
description: repoInfo.description || void 0,
|
|
105
|
+
files: installedFiles
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
source: sourceInfo.originalUrl,
|
|
112
|
+
sourceType: "github",
|
|
113
|
+
pluginType,
|
|
114
|
+
error: error instanceof Error ? error.message : String(error)
|
|
115
|
+
};
|
|
90
116
|
}
|
|
91
117
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
patterns: [
|
|
99
|
-
/null|undefined|cannot read|typeerror/,
|
|
100
|
-
/类型|空值|未定义/,
|
|
101
|
-
/optional chaining|\?\./,
|
|
102
|
-
/strict.*null|null.*check/
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
category: "error-handling",
|
|
107
|
-
patterns: [
|
|
108
|
-
/try.*catch|exception|throw|error.*handling/,
|
|
109
|
-
/unhandled.*rejection|promise.*reject/,
|
|
110
|
-
/异常|错误处理|捕获/
|
|
111
|
-
]
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
category: "performance",
|
|
115
|
-
patterns: [
|
|
116
|
-
/performance|slow|timeout|memory|leak/,
|
|
117
|
-
/optimize|optimization|cache/,
|
|
118
|
-
/性能|优化|缓存|内存/
|
|
119
|
-
]
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
category: "security",
|
|
123
|
-
patterns: [
|
|
124
|
-
/security|xss|csrf|injection|auth/,
|
|
125
|
-
/vulnerability|exploit|sanitize/,
|
|
126
|
-
/安全|漏洞|注入|认证/
|
|
127
|
-
]
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
category: "race-condition",
|
|
131
|
-
patterns: [
|
|
132
|
-
/race.*condition|concurrent|async.*await/,
|
|
133
|
-
/deadlock|mutex|lock/,
|
|
134
|
-
/竞态|并发|死锁/
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
category: "logic-error",
|
|
139
|
-
patterns: [
|
|
140
|
-
/logic|incorrect|wrong.*result/,
|
|
141
|
-
/逻辑|错误结果|计算错误/
|
|
142
|
-
]
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
category: "api-misuse",
|
|
146
|
-
patterns: [
|
|
147
|
-
/api.*usage|incorrect.*call|wrong.*parameter/,
|
|
148
|
-
/接口|调用错误|参数错误/
|
|
149
|
-
]
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
category: "configuration",
|
|
153
|
-
patterns: [
|
|
154
|
-
/config|setting|environment|env/,
|
|
155
|
-
/配置|环境|设置/
|
|
156
|
-
]
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
category: "dependency",
|
|
160
|
-
patterns: [
|
|
161
|
-
/dependency|package|version|upgrade/,
|
|
162
|
-
/依赖|版本|升级/
|
|
163
|
-
]
|
|
118
|
+
async function fetchRepoInfo(owner, repo) {
|
|
119
|
+
const url = `https://api.github.com/repos/${owner}/${repo}`;
|
|
120
|
+
const response = await fetch(url, {
|
|
121
|
+
headers: {
|
|
122
|
+
"Accept": "application/vnd.github.v3+json",
|
|
123
|
+
"User-Agent": "ccjk-cli"
|
|
164
124
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
if (response.status === 404) {
|
|
128
|
+
throw new Error(`Repository not found: ${owner}/${repo}`);
|
|
169
129
|
}
|
|
130
|
+
throw new Error(`Failed to fetch repository info: ${response.statusText}`);
|
|
170
131
|
}
|
|
171
|
-
return
|
|
132
|
+
return response.json();
|
|
172
133
|
}
|
|
173
|
-
function
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
if (
|
|
183
|
-
return
|
|
134
|
+
async function listRepoFiles(owner, repo, ref, subpath) {
|
|
135
|
+
const treePath = subpath || "";
|
|
136
|
+
const url = `https://api.github.com/repos/${owner}/${repo}/git/trees/${ref}?recursive=1`;
|
|
137
|
+
const response = await fetch(url, {
|
|
138
|
+
headers: {
|
|
139
|
+
"Accept": "application/vnd.github.v3+json",
|
|
140
|
+
"User-Agent": "ccjk-cli"
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
if (!response.ok) {
|
|
144
|
+
return [];
|
|
184
145
|
}
|
|
185
|
-
|
|
146
|
+
const data = await response.json();
|
|
147
|
+
const files = (data.tree || []).filter((item) => item.type === "blob").map((item) => item.path).filter((filePath) => !treePath || filePath.startsWith(treePath));
|
|
148
|
+
return files;
|
|
186
149
|
}
|
|
187
|
-
function
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
150
|
+
async function downloadRepo(owner, repo, ref) {
|
|
151
|
+
const zipUrl = `https://github.com/${owner}/${repo}/archive/${ref}.zip`;
|
|
152
|
+
const tempDir = path__default.join(os__default.tmpdir(), `ccjk-${repo}-${Date.now()}`);
|
|
153
|
+
const zipPath = path__default.join(tempDir, "repo.zip");
|
|
154
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
155
|
+
await downloadFile(zipUrl, zipPath);
|
|
156
|
+
const extractedDir = await extractZip(zipPath, tempDir);
|
|
157
|
+
await fs.unlink(zipPath);
|
|
158
|
+
return extractedDir;
|
|
159
|
+
}
|
|
160
|
+
async function extractZip(zipPath, destDir) {
|
|
161
|
+
const { exec } = await import('node:child_process');
|
|
162
|
+
const { promisify } = await import('node:util');
|
|
163
|
+
const execAsync = promisify(exec);
|
|
164
|
+
try {
|
|
165
|
+
await execAsync(`unzip -q "${zipPath}" -d "${destDir}"`);
|
|
166
|
+
} catch {
|
|
167
|
+
try {
|
|
168
|
+
await execAsync(`tar -xf "${zipPath}" -C "${destDir}"`);
|
|
169
|
+
} catch {
|
|
170
|
+
throw new Error("Failed to extract archive. Please ensure unzip or tar is installed.");
|
|
200
171
|
}
|
|
201
172
|
}
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
|
|
173
|
+
const entries = await fs.readdir(destDir);
|
|
174
|
+
const extractedDir = entries.find((entry) => !entry.endsWith(".zip"));
|
|
175
|
+
if (!extractedDir) {
|
|
176
|
+
throw new Error("Failed to find extracted directory");
|
|
206
177
|
}
|
|
207
|
-
return
|
|
178
|
+
return path__default.join(destDir, extractedDir);
|
|
208
179
|
}
|
|
209
|
-
function
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
180
|
+
async function listInstalledFiles$1(dir) {
|
|
181
|
+
const files = [];
|
|
182
|
+
async function walk(currentDir, prefix = "") {
|
|
183
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
184
|
+
for (const entry of entries) {
|
|
185
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
186
|
+
if (entry.isDirectory()) {
|
|
187
|
+
await walk(path__default.join(currentDir, entry.name), relativePath);
|
|
188
|
+
} else {
|
|
189
|
+
files.push(relativePath);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
216
192
|
}
|
|
217
|
-
|
|
193
|
+
await walk(dir);
|
|
194
|
+
return files;
|
|
218
195
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
"\u63D0\u4F9B\u9ED8\u8BA4\u914D\u7F6E",
|
|
266
|
-
"\u6587\u6863\u5316\u6240\u6709\u914D\u7F6E\u9879",
|
|
267
|
-
"\u5B9E\u73B0\u914D\u7F6E\u70ED\u91CD\u8F7D"
|
|
268
|
-
],
|
|
269
|
-
"dependency": [
|
|
270
|
-
"\u9501\u5B9A\u4F9D\u8D56\u7248\u672C",
|
|
271
|
-
"\u5B9A\u671F\u66F4\u65B0\u4F9D\u8D56",
|
|
272
|
-
"\u4F7F\u7528\u4F9D\u8D56\u626B\u63CF\u5DE5\u5177",
|
|
273
|
-
"\u6D4B\u8BD5\u4F9D\u8D56\u5347\u7EA7"
|
|
274
|
-
],
|
|
275
|
-
"memory-leak": [
|
|
276
|
-
"\u5B9E\u73B0\u8D44\u6E90\u6E05\u7406",
|
|
277
|
-
"\u4F7F\u7528\u5185\u5B58\u5206\u6790\u5DE5\u5177",
|
|
278
|
-
"\u907F\u514D\u5FAA\u73AF\u5F15\u7528",
|
|
279
|
-
"\u5B9A\u671F\u8FDB\u884C\u5185\u5B58\u6D4B\u8BD5"
|
|
280
|
-
],
|
|
281
|
-
"other": [
|
|
282
|
-
"\u589E\u52A0\u6D4B\u8BD5\u8986\u76D6",
|
|
283
|
-
"\u5B9E\u65BD\u4EE3\u7801\u5BA1\u67E5",
|
|
284
|
-
"\u5B8C\u5584\u6587\u6863"
|
|
285
|
-
]
|
|
286
|
-
};
|
|
287
|
-
return suggestions[bugType] || suggestions.other;
|
|
288
|
-
}
|
|
289
|
-
function generatePostmortem(analyses, existingIds) {
|
|
290
|
-
const grouped = groupByCategory(analyses);
|
|
291
|
-
const reports = [];
|
|
292
|
-
let nextId = getNextId(existingIds);
|
|
293
|
-
for (const [category, categoryAnalyses] of Object.entries(grouped)) {
|
|
294
|
-
const merged = mergeAnalyses(categoryAnalyses);
|
|
295
|
-
for (const analysis of merged) {
|
|
296
|
-
const id = `PM-${String(nextId++).padStart(3, "0")}`;
|
|
297
|
-
const report = {
|
|
298
|
-
id,
|
|
299
|
-
title: generateTitle(analysis),
|
|
300
|
-
severity: analysis.severity,
|
|
301
|
-
category: analysis.bugType,
|
|
302
|
-
status: "active",
|
|
303
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
304
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
305
|
-
relatedCommits: [analysis.commit],
|
|
306
|
-
affectedVersions: {
|
|
307
|
-
from: "unknown",
|
|
308
|
-
to: "unknown"
|
|
309
|
-
},
|
|
310
|
-
description: generateDescription(analysis),
|
|
311
|
-
rootCause: [analysis.rootCause],
|
|
312
|
-
solution: {
|
|
313
|
-
description: analysis.solution
|
|
314
|
-
},
|
|
315
|
-
preventionMeasures: analysis.preventionSuggestions,
|
|
316
|
-
aiDirectives: generateAiDirectives(analysis),
|
|
317
|
-
detectionPatterns: generateDetectionPatterns(analysis),
|
|
318
|
-
relatedFiles: analysis.commit.files,
|
|
319
|
-
tags: [category, analysis.severity],
|
|
320
|
-
metadata: {
|
|
321
|
-
generatedBy: "ccjk-postmortem",
|
|
322
|
-
version: "1.0.0"
|
|
196
|
+
|
|
197
|
+
async function installFromLocal(sourceInfo, pluginType, options = {}) {
|
|
198
|
+
const { force = false, dryRun = false } = options;
|
|
199
|
+
const { absolutePath, originalPath } = sourceInfo;
|
|
200
|
+
try {
|
|
201
|
+
const stat = await fs.stat(absolutePath);
|
|
202
|
+
const isFile = stat.isFile();
|
|
203
|
+
const isDirectory = stat.isDirectory();
|
|
204
|
+
if (!isFile && !isDirectory) {
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
source: originalPath,
|
|
208
|
+
sourceType: "local",
|
|
209
|
+
pluginType,
|
|
210
|
+
error: `Source path is neither a file nor a directory: ${absolutePath}`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const pluginName = path__default.basename(absolutePath, path__default.extname(absolutePath));
|
|
214
|
+
const installPath = getInstallPath(pluginType, pluginName);
|
|
215
|
+
if (!force) {
|
|
216
|
+
try {
|
|
217
|
+
await fs.access(installPath);
|
|
218
|
+
return {
|
|
219
|
+
success: false,
|
|
220
|
+
source: originalPath,
|
|
221
|
+
sourceType: "local",
|
|
222
|
+
pluginType,
|
|
223
|
+
error: `Plugin already exists at ${installPath}. Use --force to overwrite.`
|
|
224
|
+
};
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const files = isFile ? [path__default.basename(absolutePath)] : await listFiles(absolutePath);
|
|
229
|
+
const pluginInfo = await readPluginInfo(absolutePath, isFile);
|
|
230
|
+
if (dryRun) {
|
|
231
|
+
return {
|
|
232
|
+
success: true,
|
|
233
|
+
source: originalPath,
|
|
234
|
+
sourceType: "local",
|
|
235
|
+
pluginType,
|
|
236
|
+
installedPath: installPath,
|
|
237
|
+
details: {
|
|
238
|
+
name: pluginInfo.name || pluginName,
|
|
239
|
+
version: pluginInfo.version,
|
|
240
|
+
description: pluginInfo.description,
|
|
241
|
+
files
|
|
323
242
|
}
|
|
324
243
|
};
|
|
325
|
-
|
|
244
|
+
}
|
|
245
|
+
if (isFile) {
|
|
246
|
+
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
247
|
+
if (absolutePath.endsWith(".md")) {
|
|
248
|
+
await fs.copyFile(absolutePath, installPath);
|
|
249
|
+
} else {
|
|
250
|
+
await fs.mkdir(installPath, { recursive: true });
|
|
251
|
+
await fs.copyFile(
|
|
252
|
+
absolutePath,
|
|
253
|
+
path__default.join(installPath, path__default.basename(absolutePath))
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
258
|
+
await copyDirectory(absolutePath, installPath);
|
|
259
|
+
}
|
|
260
|
+
const installedFiles = isFile ? [path__default.basename(absolutePath)] : await listFiles(installPath);
|
|
261
|
+
return {
|
|
262
|
+
success: true,
|
|
263
|
+
source: originalPath,
|
|
264
|
+
sourceType: "local",
|
|
265
|
+
pluginType,
|
|
266
|
+
installedPath: installPath,
|
|
267
|
+
details: {
|
|
268
|
+
name: pluginInfo.name || pluginName,
|
|
269
|
+
version: pluginInfo.version,
|
|
270
|
+
description: pluginInfo.description,
|
|
271
|
+
files: installedFiles
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
} catch (error) {
|
|
275
|
+
return {
|
|
276
|
+
success: false,
|
|
277
|
+
source: originalPath,
|
|
278
|
+
sourceType: "local",
|
|
279
|
+
pluginType,
|
|
280
|
+
error: error instanceof Error ? error.message : String(error)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
async function listFiles(dir) {
|
|
285
|
+
const files = [];
|
|
286
|
+
async function walk(currentDir, prefix = "") {
|
|
287
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
288
|
+
for (const entry of entries) {
|
|
289
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
293
|
+
if (entry.isDirectory()) {
|
|
294
|
+
await walk(path__default.join(currentDir, entry.name), relativePath);
|
|
295
|
+
} else {
|
|
296
|
+
files.push(relativePath);
|
|
297
|
+
}
|
|
326
298
|
}
|
|
327
299
|
}
|
|
328
|
-
|
|
300
|
+
await walk(dir);
|
|
301
|
+
return files;
|
|
329
302
|
}
|
|
330
|
-
function
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
303
|
+
async function readPluginInfo(sourcePath, isFile) {
|
|
304
|
+
if (isFile) {
|
|
305
|
+
const name = path__default.basename(sourcePath, path__default.extname(sourcePath));
|
|
306
|
+
return { name };
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
const packageJsonPath = path__default.join(sourcePath, "package.json");
|
|
310
|
+
const content = await fs.readFile(packageJsonPath, "utf-8");
|
|
311
|
+
const packageJson = JSON.parse(content);
|
|
312
|
+
return {
|
|
313
|
+
name: packageJson.name,
|
|
314
|
+
version: packageJson.version,
|
|
315
|
+
description: packageJson.description
|
|
316
|
+
};
|
|
317
|
+
} catch {
|
|
318
|
+
}
|
|
319
|
+
const metaFiles = ["SKILL.md", "skill.md", "README.md", "readme.md"];
|
|
320
|
+
for (const metaFile of metaFiles) {
|
|
321
|
+
try {
|
|
322
|
+
const metaPath = path__default.join(sourcePath, metaFile);
|
|
323
|
+
const content = await fs.readFile(metaPath, "utf-8");
|
|
324
|
+
const titleMatch = content.match(/^#\s+(.+)$/m);
|
|
325
|
+
if (titleMatch) {
|
|
326
|
+
return { name: titleMatch[1].trim() };
|
|
327
|
+
}
|
|
328
|
+
} catch {
|
|
336
329
|
}
|
|
337
|
-
grouped[category].push(analysis);
|
|
338
330
|
}
|
|
339
|
-
return
|
|
331
|
+
return {};
|
|
340
332
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
333
|
+
|
|
334
|
+
const execAsync = promisify(exec);
|
|
335
|
+
async function installFromNpm(sourceInfo, pluginType, options = {}) {
|
|
336
|
+
const { force = false, dryRun = false } = options;
|
|
337
|
+
const { packageName, version } = sourceInfo;
|
|
338
|
+
try {
|
|
339
|
+
const packageInfo = await fetchPackageInfo(packageName, version);
|
|
340
|
+
const packageVersion = version || packageInfo.version;
|
|
341
|
+
const shortName = getShortName(packageName);
|
|
342
|
+
const installPath = getInstallPath(pluginType, shortName);
|
|
343
|
+
if (!force) {
|
|
344
|
+
try {
|
|
345
|
+
await fs.access(installPath);
|
|
346
|
+
return {
|
|
347
|
+
success: false,
|
|
348
|
+
source: packageName,
|
|
349
|
+
sourceType: "npm",
|
|
350
|
+
pluginType,
|
|
351
|
+
error: `Plugin already exists at ${installPath}. Use --force to overwrite.`
|
|
352
|
+
};
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (dryRun) {
|
|
357
|
+
const files = packageInfo.files || ["(package files)"];
|
|
358
|
+
return {
|
|
359
|
+
success: true,
|
|
360
|
+
source: packageName,
|
|
361
|
+
sourceType: "npm",
|
|
362
|
+
pluginType,
|
|
363
|
+
installedPath: installPath,
|
|
364
|
+
details: {
|
|
365
|
+
name: packageName,
|
|
366
|
+
version: packageVersion,
|
|
367
|
+
description: packageInfo.description,
|
|
368
|
+
files
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (pluginType === "mcp") {
|
|
373
|
+
await installMcpPackage(packageName, packageVersion, installPath);
|
|
350
374
|
} else {
|
|
351
|
-
|
|
375
|
+
await installGenericPackage(packageName, packageVersion, installPath);
|
|
352
376
|
}
|
|
377
|
+
const installedFiles = await listInstalledFiles(installPath);
|
|
378
|
+
return {
|
|
379
|
+
success: true,
|
|
380
|
+
source: packageName,
|
|
381
|
+
sourceType: "npm",
|
|
382
|
+
pluginType,
|
|
383
|
+
installedPath: installPath,
|
|
384
|
+
details: {
|
|
385
|
+
name: packageName,
|
|
386
|
+
version: packageVersion,
|
|
387
|
+
description: packageInfo.description,
|
|
388
|
+
files: installedFiles
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return {
|
|
393
|
+
success: false,
|
|
394
|
+
source: packageName,
|
|
395
|
+
sourceType: "npm",
|
|
396
|
+
pluginType,
|
|
397
|
+
error: error instanceof Error ? error.message : String(error)
|
|
398
|
+
};
|
|
353
399
|
}
|
|
354
|
-
return merged;
|
|
355
|
-
}
|
|
356
|
-
function calculateFileOverlap(files1, files2) {
|
|
357
|
-
const set1 = new Set(files1);
|
|
358
|
-
const set2 = new Set(files2);
|
|
359
|
-
const intersection = Array.from(set1).filter((f) => set2.has(f));
|
|
360
|
-
const union = /* @__PURE__ */ new Set([...files1, ...files2]);
|
|
361
|
-
return intersection.length / union.size;
|
|
362
400
|
}
|
|
363
|
-
function
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
"performance": "\u6027\u80FD\u95EE\u9898",
|
|
372
|
-
"security": "\u5B89\u5168\u6F0F\u6D1E",
|
|
373
|
-
"race-condition": "\u7ADE\u6001\u6761\u4EF6",
|
|
374
|
-
"logic-error": "\u903B\u8F91\u9519\u8BEF",
|
|
375
|
-
"api-misuse": "API \u4F7F\u7528\u4E0D\u5F53",
|
|
376
|
-
"configuration": "\u914D\u7F6E\u95EE\u9898",
|
|
377
|
-
"dependency": "\u4F9D\u8D56\u95EE\u9898",
|
|
378
|
-
"memory-leak": "\u5185\u5B58\u6CC4\u6F0F",
|
|
379
|
-
"other": "\u5176\u4ED6\u95EE\u9898"
|
|
380
|
-
};
|
|
381
|
-
const baseTitle = categoryTitles[analysis.bugType] || "\u672A\u5206\u7C7B\u95EE\u9898";
|
|
382
|
-
const message = analysis.commit.message;
|
|
383
|
-
const specificPart = message.replace(/^(fix|bugfix|hotfix)[(:]\s*/i, "").split("\n")[0];
|
|
384
|
-
if (specificPart && specificPart.length < 50) {
|
|
385
|
-
return `${baseTitle}: ${specificPart}`;
|
|
401
|
+
async function fetchPackageInfo(packageName, version) {
|
|
402
|
+
const url = version ? `https://registry.npmjs.org/${packageName}/${version}` : `https://registry.npmjs.org/${packageName}/latest`;
|
|
403
|
+
const response = await fetch(url);
|
|
404
|
+
if (!response.ok) {
|
|
405
|
+
if (response.status === 404) {
|
|
406
|
+
throw new Error(`Package not found: ${packageName}`);
|
|
407
|
+
}
|
|
408
|
+
throw new Error(`Failed to fetch package info: ${response.statusText}`);
|
|
386
409
|
}
|
|
387
|
-
|
|
410
|
+
const data = await response.json();
|
|
411
|
+
return {
|
|
412
|
+
version: data.version,
|
|
413
|
+
description: data.description,
|
|
414
|
+
files: data.files
|
|
415
|
+
};
|
|
388
416
|
}
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
**\u5F71\u54CD\u6587\u4EF6**:
|
|
396
|
-
${analysis.commit.files.map((f) => `- ${f}`).join("\n")}
|
|
397
|
-
|
|
398
|
-
**\u6839\u672C\u539F\u56E0**: ${analysis.rootCause}
|
|
399
|
-
`.trim();
|
|
417
|
+
function getShortName(packageName) {
|
|
418
|
+
if (packageName.startsWith("@")) {
|
|
419
|
+
const parts = packageName.split("/");
|
|
420
|
+
return parts[1] || packageName;
|
|
421
|
+
}
|
|
422
|
+
return packageName;
|
|
400
423
|
}
|
|
401
|
-
function
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
"error-handling": [
|
|
410
|
-
"\u6240\u6709\u5F02\u6B65\u64CD\u4F5C\u5FC5\u987B\u6709\u9519\u8BEF\u5904\u7406",
|
|
411
|
-
"\u63D0\u4F9B\u6709\u610F\u4E49\u7684\u9519\u8BEF\u6D88\u606F",
|
|
412
|
-
"\u5B9E\u73B0\u4F18\u96C5\u964D\u7EA7"
|
|
413
|
-
],
|
|
414
|
-
"performance": [
|
|
415
|
-
"\u907F\u514D\u5728\u5FAA\u73AF\u4E2D\u8FDB\u884C I/O \u64CD\u4F5C",
|
|
416
|
-
"\u4F7F\u7528\u9002\u5F53\u7684\u7F13\u5B58\u7B56\u7565",
|
|
417
|
-
"\u6CE8\u610F\u5927\u6570\u636E\u96C6\u7684\u5904\u7406"
|
|
418
|
-
],
|
|
419
|
-
"security": [
|
|
420
|
-
"\u9A8C\u8BC1\u6240\u6709\u7528\u6237\u8F93\u5165",
|
|
421
|
-
"\u4F7F\u7528\u53C2\u6570\u5316\u67E5\u8BE2",
|
|
422
|
-
"\u4E0D\u8981\u5728\u65E5\u5FD7\u4E2D\u8BB0\u5F55\u654F\u611F\u4FE1\u606F"
|
|
423
|
-
],
|
|
424
|
-
"race-condition": [
|
|
425
|
-
"\u6CE8\u610F\u5F02\u6B65\u64CD\u4F5C\u7684\u6267\u884C\u987A\u5E8F",
|
|
426
|
-
"\u4F7F\u7528\u9002\u5F53\u7684\u540C\u6B65\u673A\u5236",
|
|
427
|
-
"\u907F\u514D\u5171\u4EAB\u53EF\u53D8\u72B6\u6001"
|
|
428
|
-
],
|
|
429
|
-
"logic-error": [
|
|
430
|
-
"\u6DFB\u52A0\u8FB9\u754C\u6761\u4EF6\u68C0\u67E5",
|
|
431
|
-
"\u4F7F\u7528\u65AD\u8A00\u9A8C\u8BC1\u5047\u8BBE",
|
|
432
|
-
"\u7F16\u5199\u5355\u5143\u6D4B\u8BD5\u8986\u76D6\u8FB9\u754C\u60C5\u51B5"
|
|
433
|
-
],
|
|
434
|
-
"api-misuse": [
|
|
435
|
-
"\u67E5\u9605 API \u6587\u6863\u786E\u8BA4\u6B63\u786E\u7528\u6CD5",
|
|
436
|
-
"\u68C0\u67E5\u53C2\u6570\u7C7B\u578B\u548C\u8303\u56F4",
|
|
437
|
-
"\u5904\u7406\u6240\u6709\u53EF\u80FD\u7684\u8FD4\u56DE\u503C"
|
|
438
|
-
],
|
|
439
|
-
"configuration": [
|
|
440
|
-
"\u63D0\u4F9B\u5408\u7406\u7684\u9ED8\u8BA4\u503C",
|
|
441
|
-
"\u9A8C\u8BC1\u914D\u7F6E\u503C\u7684\u6709\u6548\u6027",
|
|
442
|
-
"\u6587\u6863\u5316\u914D\u7F6E\u9009\u9879"
|
|
443
|
-
],
|
|
444
|
-
"dependency": [
|
|
445
|
-
"\u68C0\u67E5\u4F9D\u8D56\u7684\u517C\u5BB9\u6027",
|
|
446
|
-
"\u9605\u8BFB\u66F4\u65B0\u65E5\u5FD7",
|
|
447
|
-
"\u5728\u5347\u7EA7\u524D\u8FDB\u884C\u6D4B\u8BD5"
|
|
448
|
-
],
|
|
449
|
-
"memory-leak": [
|
|
450
|
-
"\u53CA\u65F6\u6E05\u7406\u4E0D\u518D\u4F7F\u7528\u7684\u8D44\u6E90",
|
|
451
|
-
"\u907F\u514D\u5FAA\u73AF\u5F15\u7528",
|
|
452
|
-
"\u4F7F\u7528 WeakMap/WeakSet"
|
|
453
|
-
],
|
|
454
|
-
"other": [
|
|
455
|
-
"\u4ED4\u7EC6\u5BA1\u67E5\u4EE3\u7801\u53D8\u66F4",
|
|
456
|
-
"\u6DFB\u52A0\u9002\u5F53\u7684\u6D4B\u8BD5"
|
|
457
|
-
]
|
|
458
|
-
};
|
|
459
|
-
directives.push(...categoryDirectives[analysis.bugType] || categoryDirectives.other);
|
|
460
|
-
for (const file of analysis.commit.files) {
|
|
461
|
-
if (file.includes("api") || file.includes("service")) {
|
|
462
|
-
directives.push(`\u4FEE\u6539 ${path.basename(file)} \u65F6\u6CE8\u610F API \u517C\u5BB9\u6027`);
|
|
424
|
+
async function installMcpPackage(packageName, version, installPath) {
|
|
425
|
+
await fs.mkdir(installPath, { recursive: true });
|
|
426
|
+
const packageJson = {
|
|
427
|
+
name: `ccjk-mcp-${getShortName(packageName)}`,
|
|
428
|
+
version: "1.0.0",
|
|
429
|
+
private: true,
|
|
430
|
+
dependencies: {
|
|
431
|
+
[packageName]: version
|
|
463
432
|
}
|
|
464
|
-
|
|
465
|
-
|
|
433
|
+
};
|
|
434
|
+
await fs.writeFile(
|
|
435
|
+
path__default.join(installPath, "package.json"),
|
|
436
|
+
JSON.stringify(packageJson, null, 2)
|
|
437
|
+
);
|
|
438
|
+
try {
|
|
439
|
+
await execAsync("npm install", { cwd: installPath });
|
|
440
|
+
} catch (error) {
|
|
441
|
+
try {
|
|
442
|
+
await execAsync("pnpm install", { cwd: installPath });
|
|
443
|
+
} catch {
|
|
444
|
+
throw new Error(
|
|
445
|
+
`Failed to install package. Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
446
|
+
);
|
|
466
447
|
}
|
|
467
448
|
}
|
|
468
|
-
return Array.from(new Set(directives));
|
|
469
449
|
}
|
|
470
|
-
function
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
511
|
-
severity: "medium"
|
|
512
|
-
}
|
|
513
|
-
],
|
|
514
|
-
"security": [
|
|
515
|
-
{
|
|
516
|
-
type: "regex",
|
|
517
|
-
pattern: "innerHTML\\s*=",
|
|
518
|
-
description: "\u76F4\u63A5\u8BBE\u7F6E innerHTML \u53EF\u80FD\u5BFC\u81F4 XSS",
|
|
519
|
-
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
520
|
-
severity: "high"
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
type: "regex",
|
|
524
|
-
pattern: "eval\\s*\\(",
|
|
525
|
-
description: "\u4F7F\u7528 eval \u5B58\u5728\u5B89\u5168\u98CE\u9669",
|
|
526
|
-
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
527
|
-
severity: "critical"
|
|
528
|
-
}
|
|
529
|
-
],
|
|
530
|
-
"race-condition": [],
|
|
531
|
-
"logic-error": [],
|
|
532
|
-
"api-misuse": [],
|
|
533
|
-
"configuration": [],
|
|
534
|
-
"dependency": [],
|
|
535
|
-
"memory-leak": [
|
|
536
|
-
{
|
|
537
|
-
type: "regex",
|
|
538
|
-
pattern: "addEventListener\\([^)]+\\)(?![\\s\\S]*removeEventListener)",
|
|
539
|
-
description: "\u6DFB\u52A0\u4E8B\u4EF6\u76D1\u542C\u5668\u4F46\u672A\u79FB\u9664",
|
|
540
|
-
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
541
|
-
severity: "medium"
|
|
450
|
+
async function installGenericPackage(packageName, version, installPath) {
|
|
451
|
+
const registryUrl = `https://registry.npmjs.org/${packageName}/${version}`;
|
|
452
|
+
const response = await fetch(registryUrl);
|
|
453
|
+
if (!response.ok) {
|
|
454
|
+
throw new Error(`Failed to fetch package info: ${response.statusText}`);
|
|
455
|
+
}
|
|
456
|
+
const data = await response.json();
|
|
457
|
+
const tarballUrl = data.dist?.tarball;
|
|
458
|
+
if (!tarballUrl) {
|
|
459
|
+
throw new Error("Failed to get tarball URL");
|
|
460
|
+
}
|
|
461
|
+
const tarballResponse = await fetch(tarballUrl);
|
|
462
|
+
if (!tarballResponse.ok) {
|
|
463
|
+
throw new Error(`Failed to download tarball: ${tarballResponse.statusText}`);
|
|
464
|
+
}
|
|
465
|
+
await fs.mkdir(installPath, { recursive: true });
|
|
466
|
+
const tarballBuffer = Buffer.from(await tarballResponse.arrayBuffer());
|
|
467
|
+
const tarballPath = path__default.join(installPath, "package.tgz");
|
|
468
|
+
await fs.writeFile(tarballPath, tarballBuffer);
|
|
469
|
+
try {
|
|
470
|
+
await execAsync(`tar -xzf package.tgz --strip-components=1`, { cwd: installPath });
|
|
471
|
+
} finally {
|
|
472
|
+
await fs.unlink(tarballPath).catch(() => {
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async function listInstalledFiles(dir) {
|
|
477
|
+
const files = [];
|
|
478
|
+
async function walk(currentDir, prefix = "") {
|
|
479
|
+
try {
|
|
480
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
481
|
+
for (const entry of entries) {
|
|
482
|
+
if (entry.name === "node_modules")
|
|
483
|
+
continue;
|
|
484
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
485
|
+
if (entry.isDirectory()) {
|
|
486
|
+
await walk(path__default.join(currentDir, entry.name), relativePath);
|
|
487
|
+
} else {
|
|
488
|
+
files.push(relativePath);
|
|
489
|
+
}
|
|
542
490
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
return
|
|
491
|
+
} catch {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
await walk(dir);
|
|
495
|
+
return files;
|
|
548
496
|
}
|
|
549
|
-
const PostmortemAnalyzer = {
|
|
550
|
-
getFixCommits,
|
|
551
|
-
analyzeFixCommit,
|
|
552
|
-
generatePostmortem
|
|
553
|
-
};
|
|
554
497
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
minSyncSeverity: "medium",
|
|
561
|
-
detection: {
|
|
562
|
-
enabled: true,
|
|
563
|
-
excludePatterns: ["node_modules/**", "dist/**", "*.test.*", "*.spec.*"],
|
|
564
|
-
includePatterns: ["src/**/*.ts", "src/**/*.tsx"]
|
|
565
|
-
},
|
|
566
|
-
aiAnalysis: {
|
|
567
|
-
provider: "claude"
|
|
498
|
+
function parseSource(source) {
|
|
499
|
+
const trimmed = source.trim();
|
|
500
|
+
const githubInfo = parseGitHubSource(trimmed);
|
|
501
|
+
if (githubInfo) {
|
|
502
|
+
return githubInfo;
|
|
568
503
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const CLAUDE_MD_SECTION_END = "<!-- POSTMORTEM_END -->";
|
|
573
|
-
class PostmortemManager {
|
|
574
|
-
config;
|
|
575
|
-
projectRoot;
|
|
576
|
-
postmortemDir;
|
|
577
|
-
constructor(projectRoot = process.cwd(), config = {}) {
|
|
578
|
-
this.projectRoot = projectRoot;
|
|
579
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
580
|
-
this.postmortemDir = path.join(projectRoot, this.config.directory);
|
|
504
|
+
const localInfo = parseLocalSource(trimmed);
|
|
505
|
+
if (localInfo) {
|
|
506
|
+
return localInfo;
|
|
581
507
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
if (commits.length === 0) {
|
|
595
|
-
this.saveIndex(this.createEmptyIndex());
|
|
596
|
-
return { created: 0, directory: this.postmortemDir };
|
|
597
|
-
}
|
|
598
|
-
const analyses = commits.map(
|
|
599
|
-
(commit) => PostmortemAnalyzer.analyzeFixCommit(commit, this.projectRoot)
|
|
600
|
-
);
|
|
601
|
-
const reports = PostmortemAnalyzer.generatePostmortem(analyses, []);
|
|
602
|
-
for (const report of reports) {
|
|
603
|
-
this.saveReport(report);
|
|
604
|
-
}
|
|
605
|
-
this.updateIndex();
|
|
606
|
-
if (this.config.autoSyncToClaudeMd) {
|
|
607
|
-
await this.syncToClaudeMd();
|
|
608
|
-
}
|
|
609
|
-
return { created: reports.length, directory: this.postmortemDir };
|
|
508
|
+
return parseNpmSource(trimmed);
|
|
509
|
+
}
|
|
510
|
+
function parseGitHubSource(source) {
|
|
511
|
+
const prefixMatch = source.match(/^(?:github|gh):([^/]+)\/([^#@/]+)(?:#(.+))?$/);
|
|
512
|
+
if (prefixMatch) {
|
|
513
|
+
return {
|
|
514
|
+
type: "github",
|
|
515
|
+
owner: prefixMatch[1],
|
|
516
|
+
repo: prefixMatch[2],
|
|
517
|
+
ref: prefixMatch[3],
|
|
518
|
+
originalUrl: source
|
|
519
|
+
};
|
|
610
520
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
}
|
|
521
|
+
const urlMatch = source.match(
|
|
522
|
+
/^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?(?:\/tree\/([^/]+))?(?:\/(.+))?$/
|
|
523
|
+
);
|
|
524
|
+
if (urlMatch) {
|
|
525
|
+
return {
|
|
526
|
+
type: "github",
|
|
527
|
+
owner: urlMatch[1],
|
|
528
|
+
repo: urlMatch[2],
|
|
529
|
+
ref: urlMatch[3],
|
|
530
|
+
subpath: urlMatch[4],
|
|
531
|
+
originalUrl: source
|
|
532
|
+
};
|
|
625
533
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const content = this.renderReportToMarkdown(report);
|
|
636
|
-
fs.writeFileSync(filepath, content, "utf-8");
|
|
637
|
-
const jsonPath = path.join(this.postmortemDir, `${report.id}.json`);
|
|
638
|
-
fs.writeFileSync(jsonPath, JSON.stringify(report, null, 2), "utf-8");
|
|
639
|
-
return filepath;
|
|
534
|
+
const shortMatch = source.match(/^([\w-]+)\/([\w.-]+)(?:#(.+))?$/);
|
|
535
|
+
if (shortMatch && !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("~")) {
|
|
536
|
+
return {
|
|
537
|
+
type: "github",
|
|
538
|
+
owner: shortMatch[1],
|
|
539
|
+
repo: shortMatch[2],
|
|
540
|
+
ref: shortMatch[3],
|
|
541
|
+
originalUrl: source
|
|
542
|
+
};
|
|
640
543
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
if (
|
|
647
|
-
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
} catch {
|
|
653
|
-
return null;
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
function parseLocalSource(source) {
|
|
547
|
+
if (source.startsWith("./") || source.startsWith("../") || source.startsWith("/") || source.startsWith("~/")) {
|
|
548
|
+
let absolutePath;
|
|
549
|
+
if (source.startsWith("~/")) {
|
|
550
|
+
absolutePath = path__default.join(os__default.homedir(), source.slice(2));
|
|
551
|
+
} else if (path__default.isAbsolute(source)) {
|
|
552
|
+
absolutePath = source;
|
|
553
|
+
} else {
|
|
554
|
+
absolutePath = path__default.resolve(process.cwd(), source);
|
|
654
555
|
}
|
|
556
|
+
return {
|
|
557
|
+
type: "local",
|
|
558
|
+
absolutePath,
|
|
559
|
+
originalPath: source
|
|
560
|
+
};
|
|
655
561
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
return index?.reports || [];
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* 渲染报告为 Markdown
|
|
665
|
-
*/
|
|
666
|
-
renderReportToMarkdown(report) {
|
|
667
|
-
const severityEmoji = {
|
|
668
|
-
critical: "\u{1F534}",
|
|
669
|
-
high: "\u{1F7E0}",
|
|
670
|
-
medium: "\u{1F7E1}",
|
|
671
|
-
low: "\u{1F7E2}"
|
|
562
|
+
if (/^[a-z]:[\\/]/i.test(source)) {
|
|
563
|
+
return {
|
|
564
|
+
type: "local",
|
|
565
|
+
absolutePath: path__default.resolve(source),
|
|
566
|
+
originalPath: source
|
|
672
567
|
};
|
|
673
|
-
return `# ${report.id}: ${report.title}
|
|
674
|
-
|
|
675
|
-
## \u5143\u6570\u636E
|
|
676
|
-
- **ID**: ${report.id}
|
|
677
|
-
- **\u4E25\u91CD\u7A0B\u5EA6**: ${severityEmoji[report.severity]} ${report.severity.toUpperCase()}
|
|
678
|
-
- **\u7C7B\u522B**: ${report.category}
|
|
679
|
-
- **\u72B6\u6001**: ${report.status}
|
|
680
|
-
- **\u521B\u5EFA\u65F6\u95F4**: ${report.createdAt}
|
|
681
|
-
- **\u66F4\u65B0\u65F6\u95F4**: ${report.updatedAt}
|
|
682
|
-
|
|
683
|
-
## \u76F8\u5173\u63D0\u4EA4
|
|
684
|
-
${report.relatedCommits.map((c) => `- \`${c.shortHash}\` - ${c.message} (${c.author}, ${c.date})`).join("\n")}
|
|
685
|
-
|
|
686
|
-
## \u5F71\u54CD\u7248\u672C
|
|
687
|
-
- **\u4ECE**: ${report.affectedVersions.from}
|
|
688
|
-
- **\u5230**: ${report.affectedVersions.to}
|
|
689
|
-
|
|
690
|
-
## \u95EE\u9898\u63CF\u8FF0
|
|
691
|
-
${report.description}
|
|
692
|
-
|
|
693
|
-
## \u6839\u672C\u539F\u56E0
|
|
694
|
-
${report.rootCause.map((c) => `- ${c}`).join("\n")}
|
|
695
|
-
|
|
696
|
-
## \u4FEE\u590D\u65B9\u6848
|
|
697
|
-
${report.solution.description}
|
|
698
|
-
|
|
699
|
-
${report.solution.codeExample ? `
|
|
700
|
-
### \u4EE3\u7801\u793A\u4F8B
|
|
701
|
-
|
|
702
|
-
**\u274C \u9519\u8BEF\u5199\u6CD5**
|
|
703
|
-
\`\`\`typescript
|
|
704
|
-
${report.solution.codeExample.bad}
|
|
705
|
-
\`\`\`
|
|
706
|
-
|
|
707
|
-
**\u2705 \u6B63\u786E\u5199\u6CD5**
|
|
708
|
-
\`\`\`typescript
|
|
709
|
-
${report.solution.codeExample.good}
|
|
710
|
-
\`\`\`
|
|
711
|
-
` : ""}
|
|
712
|
-
|
|
713
|
-
## \u9884\u9632\u63AA\u65BD
|
|
714
|
-
${report.preventionMeasures.map((m, i) => `${i + 1}. ${m}`).join("\n")}
|
|
715
|
-
|
|
716
|
-
## AI \u5F00\u53D1\u6307\u4EE4
|
|
717
|
-
> \u4EE5\u4E0B\u6307\u4EE4\u4F1A\u81EA\u52A8\u6CE8\u5165\u5230 CLAUDE.md \u4E2D\uFF0C\u6307\u5BFC AI \u5728\u5F00\u53D1\u65F6\u907F\u514D\u7C7B\u4F3C\u95EE\u9898
|
|
718
|
-
|
|
719
|
-
${report.aiDirectives.map((d) => `- ${d}`).join("\n")}
|
|
720
|
-
|
|
721
|
-
## \u68C0\u6D4B\u6A21\u5F0F
|
|
722
|
-
${report.detectionPatterns.length > 0 ? report.detectionPatterns.map((p) => `
|
|
723
|
-
### ${p.description}
|
|
724
|
-
- **\u7C7B\u578B**: ${p.type}
|
|
725
|
-
- **\u6A21\u5F0F**: \`${p.pattern}\`
|
|
726
|
-
- **\u9002\u7528\u6587\u4EF6**: ${p.fileTypes.join(", ")}
|
|
727
|
-
- **\u4E25\u91CD\u7A0B\u5EA6**: ${p.severity}
|
|
728
|
-
`).join("\n") : "\u6682\u65E0\u81EA\u52A8\u68C0\u6D4B\u6A21\u5F0F"}
|
|
729
|
-
|
|
730
|
-
## \u76F8\u5173\u6587\u4EF6
|
|
731
|
-
${report.relatedFiles.map((f) => `- \`${f}\``).join("\n")}
|
|
732
|
-
|
|
733
|
-
## \u6807\u7B7E
|
|
734
|
-
${report.tags.map((t) => `\`${t}\``).join(" ")}
|
|
735
|
-
|
|
736
|
-
---
|
|
737
|
-
*\u7531 CCJK Postmortem System \u81EA\u52A8\u751F\u6210*
|
|
738
|
-
`;
|
|
739
568
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
function parseNpmSource(source) {
|
|
572
|
+
const npmPrefixMatch = source.match(/^npm:(.+)$/);
|
|
573
|
+
const packageStr = npmPrefixMatch ? npmPrefixMatch[1] : source;
|
|
574
|
+
const scopedMatch = packageStr.match(/^(@[^/]+)\/([^@]+)(?:@(.+))?$/);
|
|
575
|
+
if (scopedMatch) {
|
|
576
|
+
return {
|
|
577
|
+
type: "npm",
|
|
578
|
+
scope: scopedMatch[1],
|
|
579
|
+
packageName: `${scopedMatch[1]}/${scopedMatch[2]}`,
|
|
580
|
+
version: scopedMatch[3]
|
|
581
|
+
};
|
|
745
582
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
// ==========================================================================
|
|
749
|
-
/**
|
|
750
|
-
* 创建空索引
|
|
751
|
-
*/
|
|
752
|
-
createEmptyIndex() {
|
|
583
|
+
const versionMatch = packageStr.match(/^([^@]+)@(.+)$/);
|
|
584
|
+
if (versionMatch) {
|
|
753
585
|
return {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
total: 0,
|
|
758
|
-
bySeverity: { critical: 0, high: 0, medium: 0, low: 0 },
|
|
759
|
-
byCategory: {
|
|
760
|
-
"type-safety": 0,
|
|
761
|
-
"error-handling": 0,
|
|
762
|
-
"performance": 0,
|
|
763
|
-
"security": 0,
|
|
764
|
-
"logic-error": 0,
|
|
765
|
-
"race-condition": 0,
|
|
766
|
-
"memory-leak": 0,
|
|
767
|
-
"api-misuse": 0,
|
|
768
|
-
"configuration": 0,
|
|
769
|
-
"dependency": 0,
|
|
770
|
-
"other": 0
|
|
771
|
-
},
|
|
772
|
-
byStatus: { active: 0, resolved: 0, monitoring: 0, archived: 0 }
|
|
773
|
-
},
|
|
774
|
-
reports: []
|
|
586
|
+
type: "npm",
|
|
587
|
+
packageName: versionMatch[1],
|
|
588
|
+
version: versionMatch[2]
|
|
775
589
|
};
|
|
776
590
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
591
|
+
return {
|
|
592
|
+
type: "npm",
|
|
593
|
+
packageName: packageStr
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function buildGitHubRawUrl(info, filePath) {
|
|
597
|
+
const ref = info.ref || "main";
|
|
598
|
+
return `https://raw.githubusercontent.com/${info.owner}/${info.repo}/${ref}/${filePath}`;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async function detectPluginType(sourceInfo) {
|
|
602
|
+
const result = await detectPluginTypeWithConfidence(sourceInfo);
|
|
603
|
+
return result.type;
|
|
604
|
+
}
|
|
605
|
+
async function detectPluginTypeWithConfidence(sourceInfo) {
|
|
606
|
+
switch (sourceInfo.type) {
|
|
607
|
+
case "github":
|
|
608
|
+
return detectFromGitHub(sourceInfo);
|
|
609
|
+
case "npm":
|
|
610
|
+
return detectFromNpm(sourceInfo);
|
|
611
|
+
case "local":
|
|
612
|
+
return detectFromLocal(sourceInfo);
|
|
613
|
+
default:
|
|
614
|
+
return { type: "skill", confidence: "low", reason: "Unknown source type" };
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
async function detectFromGitHub(info) {
|
|
618
|
+
const repoNameResult = detectFromRepoName(info.repo);
|
|
619
|
+
if (repoNameResult.confidence === "high") {
|
|
620
|
+
return repoNameResult;
|
|
621
|
+
}
|
|
622
|
+
try {
|
|
623
|
+
const packageJsonUrl = buildGitHubRawUrl(info, "package.json");
|
|
624
|
+
const response = await fetch(packageJsonUrl);
|
|
625
|
+
if (response.ok) {
|
|
626
|
+
const packageJson = await response.json();
|
|
627
|
+
const pkgResult = detectFromPackageJson(packageJson);
|
|
628
|
+
if (pkgResult.confidence !== "low") {
|
|
629
|
+
return pkgResult;
|
|
630
|
+
}
|
|
784
631
|
}
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
const filePatterns = [
|
|
635
|
+
{ file: "SKILL.md", type: "skill" },
|
|
636
|
+
{ file: "skill.md", type: "skill" },
|
|
637
|
+
{ file: "AGENT.md", type: "agent" },
|
|
638
|
+
{ file: "agent.md", type: "agent" },
|
|
639
|
+
{ file: "mcp.json", type: "mcp" },
|
|
640
|
+
{ file: "hook.json", type: "hook" }
|
|
641
|
+
];
|
|
642
|
+
for (const pattern of filePatterns) {
|
|
785
643
|
try {
|
|
786
|
-
const
|
|
787
|
-
|
|
644
|
+
const fileUrl = buildGitHubRawUrl(info, pattern.file);
|
|
645
|
+
const response = await fetch(fileUrl, { method: "HEAD" });
|
|
646
|
+
if (response.ok) {
|
|
647
|
+
return {
|
|
648
|
+
type: pattern.type,
|
|
649
|
+
confidence: "high",
|
|
650
|
+
reason: `Found ${pattern.file}`
|
|
651
|
+
};
|
|
652
|
+
}
|
|
788
653
|
} catch {
|
|
789
|
-
return null;
|
|
790
654
|
}
|
|
791
655
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
656
|
+
return repoNameResult.confidence !== "low" ? repoNameResult : { type: "skill", confidence: "low", reason: "Default type" };
|
|
657
|
+
}
|
|
658
|
+
async function detectFromNpm(info) {
|
|
659
|
+
const nameResult = detectFromPackageName(info.packageName);
|
|
660
|
+
if (nameResult.confidence === "high") {
|
|
661
|
+
return nameResult;
|
|
798
662
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
index.stats.byCategory[report.category]++;
|
|
812
|
-
index.stats.byStatus[report.status]++;
|
|
813
|
-
index.reports.push({
|
|
814
|
-
id: report.id,
|
|
815
|
-
title: report.title,
|
|
816
|
-
severity: report.severity,
|
|
817
|
-
category: report.category,
|
|
818
|
-
status: report.status,
|
|
819
|
-
createdAt: report.createdAt,
|
|
820
|
-
filePath: file.replace(".json", ".md")
|
|
821
|
-
});
|
|
822
|
-
} catch {
|
|
663
|
+
try {
|
|
664
|
+
const registryUrl = `https://registry.npmjs.org/${info.packageName}`;
|
|
665
|
+
const response = await fetch(registryUrl);
|
|
666
|
+
if (response.ok) {
|
|
667
|
+
const data = await response.json();
|
|
668
|
+
const latestVersion = data["dist-tags"]?.latest;
|
|
669
|
+
if (latestVersion && data.versions?.[latestVersion]) {
|
|
670
|
+
const packageJson = data.versions[latestVersion];
|
|
671
|
+
const pkgResult = detectFromPackageJson(packageJson);
|
|
672
|
+
if (pkgResult.confidence !== "low") {
|
|
673
|
+
return pkgResult;
|
|
674
|
+
}
|
|
823
675
|
}
|
|
824
676
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
return nameResult.confidence !== "low" ? nameResult : { type: "skill", confidence: "low", reason: "Default type" };
|
|
680
|
+
}
|
|
681
|
+
async function detectFromLocal(info) {
|
|
682
|
+
const { absolutePath } = info;
|
|
683
|
+
const dirName = path__default.basename(absolutePath);
|
|
684
|
+
const dirResult = detectFromRepoName(dirName);
|
|
685
|
+
if (dirResult.confidence === "high") {
|
|
686
|
+
return dirResult;
|
|
835
687
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const claudeMdPath = path.join(this.projectRoot, "CLAUDE.md");
|
|
844
|
-
const injection = this.generateClaudeMdInjection();
|
|
845
|
-
let content = "";
|
|
846
|
-
if (fs.existsSync(claudeMdPath)) {
|
|
847
|
-
content = fs.readFileSync(claudeMdPath, "utf-8");
|
|
688
|
+
try {
|
|
689
|
+
const packageJsonPath = path__default.join(absolutePath, "package.json");
|
|
690
|
+
const content = await fs.readFile(packageJsonPath, "utf-8");
|
|
691
|
+
const packageJson = JSON.parse(content);
|
|
692
|
+
const pkgResult = detectFromPackageJson(packageJson);
|
|
693
|
+
if (pkgResult.confidence !== "low") {
|
|
694
|
+
return pkgResult;
|
|
848
695
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
696
|
+
} catch {
|
|
697
|
+
}
|
|
698
|
+
const filePatterns = [
|
|
699
|
+
{ file: "SKILL.md", type: "skill" },
|
|
700
|
+
{ file: "skill.md", type: "skill" },
|
|
701
|
+
{ file: "AGENT.md", type: "agent" },
|
|
702
|
+
{ file: "agent.md", type: "agent" },
|
|
703
|
+
{ file: "mcp.json", type: "mcp" },
|
|
704
|
+
{ file: "hook.json", type: "hook" }
|
|
705
|
+
];
|
|
706
|
+
for (const pattern of filePatterns) {
|
|
707
|
+
try {
|
|
708
|
+
const filePath = path__default.join(absolutePath, pattern.file);
|
|
709
|
+
await fs.access(filePath);
|
|
710
|
+
return {
|
|
711
|
+
type: pattern.type,
|
|
712
|
+
confidence: "high",
|
|
713
|
+
reason: `Found ${pattern.file}`
|
|
714
|
+
};
|
|
715
|
+
} catch {
|
|
853
716
|
}
|
|
854
|
-
const injectionContent = `
|
|
855
|
-
${CLAUDE_MD_SECTION_START}
|
|
856
|
-
${injection.content}
|
|
857
|
-
${CLAUDE_MD_SECTION_END}
|
|
858
|
-
`;
|
|
859
|
-
content = `${content.trim()}
|
|
860
|
-
|
|
861
|
-
${injectionContent.trim()}
|
|
862
|
-
`;
|
|
863
|
-
fs.writeFileSync(claudeMdPath, content, "utf-8");
|
|
864
|
-
return {
|
|
865
|
-
synced: injection.sourcePostmortems.length,
|
|
866
|
-
claudeMdPath
|
|
867
|
-
};
|
|
868
717
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const severityOrder = {
|
|
877
|
-
critical: 0,
|
|
878
|
-
high: 1,
|
|
879
|
-
medium: 2,
|
|
880
|
-
low: 3
|
|
718
|
+
try {
|
|
719
|
+
const stat = await fs.stat(absolutePath);
|
|
720
|
+
if (stat.isFile() && absolutePath.endsWith(".md")) {
|
|
721
|
+
return {
|
|
722
|
+
type: "skill",
|
|
723
|
+
confidence: "high",
|
|
724
|
+
reason: "Single markdown file"
|
|
881
725
|
};
|
|
882
|
-
const minSeverityOrder = severityOrder[this.config.minSyncSeverity];
|
|
883
|
-
for (const meta of index.reports) {
|
|
884
|
-
if (severityOrder[meta.severity] <= minSeverityOrder && meta.status === "active") {
|
|
885
|
-
const report = this.getReport(meta.id);
|
|
886
|
-
if (report) {
|
|
887
|
-
reports.push(report);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
if (reports.length >= this.config.maxSyncItems) {
|
|
891
|
-
break;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
726
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
for (const r of reports.slice(0, 5)) {
|
|
933
|
-
for (const d of r.aiDirectives.slice(0, 2)) {
|
|
934
|
-
allDirectives.add(d);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
for (const d of allDirectives) {
|
|
938
|
-
lines.push(`- ${d}`);
|
|
727
|
+
} catch {
|
|
728
|
+
}
|
|
729
|
+
return dirResult.confidence !== "low" ? dirResult : { type: "skill", confidence: "low", reason: "Default type" };
|
|
730
|
+
}
|
|
731
|
+
function detectFromRepoName(name) {
|
|
732
|
+
const lowerName = name.toLowerCase();
|
|
733
|
+
if (lowerName.includes("mcp-server") || lowerName.includes("mcp_server") || lowerName.startsWith("mcp-") || lowerName.endsWith("-mcp")) {
|
|
734
|
+
return { type: "mcp", confidence: "high", reason: `Name contains MCP pattern: ${name}` };
|
|
735
|
+
}
|
|
736
|
+
if (lowerName.includes("agent") || lowerName.includes("-agent") || lowerName.endsWith("-agent")) {
|
|
737
|
+
return { type: "agent", confidence: "medium", reason: `Name contains agent pattern: ${name}` };
|
|
738
|
+
}
|
|
739
|
+
if (lowerName.includes("hook") || lowerName.includes("-hook") || lowerName.endsWith("-hook")) {
|
|
740
|
+
return { type: "hook", confidence: "medium", reason: `Name contains hook pattern: ${name}` };
|
|
741
|
+
}
|
|
742
|
+
if (lowerName.includes("skill") || lowerName.includes("-skill") || lowerName.endsWith("-skill")) {
|
|
743
|
+
return { type: "skill", confidence: "medium", reason: `Name contains skill pattern: ${name}` };
|
|
744
|
+
}
|
|
745
|
+
return { type: "skill", confidence: "low", reason: "No pattern matched" };
|
|
746
|
+
}
|
|
747
|
+
function detectFromPackageName(packageName) {
|
|
748
|
+
const lowerName = packageName.toLowerCase();
|
|
749
|
+
if (lowerName.startsWith("@modelcontextprotocol/")) {
|
|
750
|
+
return { type: "mcp", confidence: "high", reason: "MCP official scope" };
|
|
751
|
+
}
|
|
752
|
+
if (lowerName.includes("mcp-server") || lowerName.includes("mcp_server")) {
|
|
753
|
+
return { type: "mcp", confidence: "high", reason: "MCP server pattern in name" };
|
|
754
|
+
}
|
|
755
|
+
return detectFromRepoName(packageName);
|
|
756
|
+
}
|
|
757
|
+
function detectFromPackageJson(packageJson) {
|
|
758
|
+
if (packageJson.ccjk && typeof packageJson.ccjk === "object") {
|
|
759
|
+
const ccjk = packageJson.ccjk;
|
|
760
|
+
if (ccjk.type && typeof ccjk.type === "string") {
|
|
761
|
+
const type = ccjk.type;
|
|
762
|
+
if (["skill", "mcp", "agent", "hook"].includes(type)) {
|
|
763
|
+
return { type, confidence: "high", reason: "Explicit ccjk.type field" };
|
|
939
764
|
}
|
|
940
|
-
lines.push("");
|
|
941
|
-
lines.push(`> \u8BE6\u7EC6\u4FE1\u606F\u8BF7\u67E5\u770B \`${this.config.directory}/\` \u76EE\u5F55`);
|
|
942
765
|
}
|
|
943
|
-
return {
|
|
944
|
-
sectionId: "postmortem-warnings",
|
|
945
|
-
title: "\u5DF2\u77E5\u95EE\u9898\u9884\u8B66",
|
|
946
|
-
content: lines.join("\n"),
|
|
947
|
-
priority: 100,
|
|
948
|
-
sourcePostmortems: reports.map((r) => r.id),
|
|
949
|
-
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
950
|
-
};
|
|
951
766
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
const issues = [];
|
|
969
|
-
const index = this.loadIndex();
|
|
970
|
-
if (!index) {
|
|
971
|
-
return this.createEmptyCheckReport(filesToCheck.length);
|
|
972
|
-
}
|
|
973
|
-
const patterns = [];
|
|
974
|
-
for (const meta of index.reports) {
|
|
975
|
-
if (meta.status !== "active")
|
|
976
|
-
continue;
|
|
977
|
-
const report = this.getReport(meta.id);
|
|
978
|
-
if (!report)
|
|
979
|
-
continue;
|
|
980
|
-
for (const pattern of report.detectionPatterns) {
|
|
981
|
-
patterns.push({ pattern, postmortemId: report.id });
|
|
767
|
+
if (Array.isArray(packageJson.keywords)) {
|
|
768
|
+
const keywords = packageJson.keywords;
|
|
769
|
+
const keywordMap = {
|
|
770
|
+
"mcp-server": "mcp",
|
|
771
|
+
"mcp": "mcp",
|
|
772
|
+
"model-context-protocol": "mcp",
|
|
773
|
+
"ccjk-skill": "skill",
|
|
774
|
+
"claude-skill": "skill",
|
|
775
|
+
"ccjk-agent": "agent",
|
|
776
|
+
"ccjk-hook": "hook"
|
|
777
|
+
};
|
|
778
|
+
for (const keyword of keywords) {
|
|
779
|
+
const type = keywordMap[keyword.toLowerCase()];
|
|
780
|
+
if (type) {
|
|
781
|
+
return { type, confidence: "high", reason: `Keyword: ${keyword}` };
|
|
982
782
|
}
|
|
983
783
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
for (const { pattern, postmortemId } of patterns) {
|
|
991
|
-
if (!pattern.fileTypes.some((ft) => file.endsWith(ft))) {
|
|
992
|
-
continue;
|
|
993
|
-
}
|
|
994
|
-
if (pattern.type === "regex") {
|
|
995
|
-
try {
|
|
996
|
-
const regex = new RegExp(pattern.pattern, "g");
|
|
997
|
-
for (let i = 0; i < lines.length; i++) {
|
|
998
|
-
const line = lines[i];
|
|
999
|
-
const matches = line.match(regex);
|
|
1000
|
-
if (matches) {
|
|
1001
|
-
issues.push({
|
|
1002
|
-
file,
|
|
1003
|
-
line: i + 1,
|
|
1004
|
-
column: line.indexOf(matches[0]) + 1,
|
|
1005
|
-
pattern,
|
|
1006
|
-
postmortemId,
|
|
1007
|
-
message: `\u53EF\u80FD\u89E6\u53D1 ${postmortemId}: ${pattern.description}`,
|
|
1008
|
-
suggestion: `\u53C2\u8003 ${this.config.directory}/${postmortemId}.md`
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
} catch {
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
784
|
+
}
|
|
785
|
+
if (packageJson.bin) {
|
|
786
|
+
const binKeys = Object.keys(packageJson.bin);
|
|
787
|
+
for (const key of binKeys) {
|
|
788
|
+
if (key.includes("mcp") || key.includes("server")) {
|
|
789
|
+
return { type: "mcp", confidence: "medium", reason: `Binary name: ${key}` };
|
|
1015
790
|
}
|
|
1016
791
|
}
|
|
1017
|
-
const summary = {
|
|
1018
|
-
critical: issues.filter((i) => i.pattern.severity === "critical").length,
|
|
1019
|
-
high: issues.filter((i) => i.pattern.severity === "high").length,
|
|
1020
|
-
medium: issues.filter((i) => i.pattern.severity === "medium").length,
|
|
1021
|
-
low: issues.filter((i) => i.pattern.severity === "low").length
|
|
1022
|
-
};
|
|
1023
|
-
return {
|
|
1024
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1025
|
-
filesChecked: filesToCheck.length,
|
|
1026
|
-
issuesFound: issues,
|
|
1027
|
-
summary,
|
|
1028
|
-
passed: summary.critical === 0 && summary.high === 0
|
|
1029
|
-
};
|
|
1030
792
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
try {
|
|
1036
|
-
const output = execSync("git diff --cached --name-only", {
|
|
1037
|
-
cwd: this.projectRoot,
|
|
1038
|
-
encoding: "utf-8"
|
|
1039
|
-
});
|
|
1040
|
-
return output.trim().split("\n").filter(Boolean);
|
|
1041
|
-
} catch {
|
|
1042
|
-
return [];
|
|
793
|
+
if (typeof packageJson.main === "string") {
|
|
794
|
+
const main = packageJson.main.toLowerCase();
|
|
795
|
+
if (main.includes("server") || main.includes("mcp")) {
|
|
796
|
+
return { type: "mcp", confidence: "low", reason: `Main file: ${packageJson.main}` };
|
|
1043
797
|
}
|
|
1044
798
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
799
|
+
return { type: "skill", confidence: "low", reason: "No specific indicators" };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
async function addCommand(source, options = {}) {
|
|
803
|
+
const { force = false, dryRun = false, json = false, lang = "en" } = options;
|
|
804
|
+
const i18n = getI18n(lang);
|
|
805
|
+
const spinner = json ? null : ora(i18n.parsing).start();
|
|
806
|
+
let sourceInfo;
|
|
807
|
+
try {
|
|
808
|
+
sourceInfo = parseSource(source);
|
|
809
|
+
spinner?.succeed(i18n.parsed(sourceInfo.type));
|
|
810
|
+
} catch (error) {
|
|
811
|
+
spinner?.fail(i18n.parseFailed);
|
|
812
|
+
const result = {
|
|
813
|
+
success: false,
|
|
814
|
+
source,
|
|
815
|
+
sourceType: "local",
|
|
816
|
+
pluginType: "skill",
|
|
817
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1066
818
|
};
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
return new RegExp(`^${regexPattern}$`).test(filepath);
|
|
819
|
+
if (json) {
|
|
820
|
+
console.log(JSON.stringify(result, null, 2));
|
|
821
|
+
} else {
|
|
822
|
+
console.error(ansis.red(`
|
|
823
|
+
${i18n.error}: ${result.error}
|
|
824
|
+
`));
|
|
825
|
+
}
|
|
826
|
+
return result;
|
|
1076
827
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
};
|
|
828
|
+
let pluginType = options.type;
|
|
829
|
+
if (!pluginType) {
|
|
830
|
+
spinner?.start(i18n.detectingType);
|
|
831
|
+
try {
|
|
832
|
+
pluginType = await detectPluginType(sourceInfo);
|
|
833
|
+
spinner?.succeed(i18n.detectedType(pluginType));
|
|
834
|
+
} catch {
|
|
835
|
+
spinner?.info(i18n.defaultType);
|
|
836
|
+
pluginType = "skill";
|
|
837
|
+
}
|
|
1088
838
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
);
|
|
1105
|
-
const existingIds = this.listReports().map((r) => r.id);
|
|
1106
|
-
const newReports = PostmortemAnalyzer.generatePostmortem(analyses, existingIds);
|
|
1107
|
-
const newIds = [];
|
|
1108
|
-
for (const report of newReports) {
|
|
1109
|
-
report.affectedVersions = { from: since || "unknown", to: version };
|
|
1110
|
-
this.saveReport(report);
|
|
1111
|
-
newIds.push(report.id);
|
|
839
|
+
spinner?.start(dryRun ? i18n.previewInstall : i18n.installing);
|
|
840
|
+
try {
|
|
841
|
+
let result;
|
|
842
|
+
switch (sourceInfo.type) {
|
|
843
|
+
case "github":
|
|
844
|
+
result = await installFromGitHub(sourceInfo, pluginType, { force, dryRun });
|
|
845
|
+
break;
|
|
846
|
+
case "npm":
|
|
847
|
+
result = await installFromNpm(sourceInfo, pluginType, { force, dryRun });
|
|
848
|
+
break;
|
|
849
|
+
case "local":
|
|
850
|
+
result = await installFromLocal(sourceInfo, pluginType, { force, dryRun });
|
|
851
|
+
break;
|
|
852
|
+
default:
|
|
853
|
+
throw new Error(`Unsupported source type: ${sourceInfo.type}`);
|
|
1112
854
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
855
|
+
if (result.success) {
|
|
856
|
+
spinner?.succeed(dryRun ? i18n.previewSuccess : i18n.installSuccess);
|
|
857
|
+
} else {
|
|
858
|
+
spinner?.fail(i18n.installFailed);
|
|
859
|
+
}
|
|
860
|
+
if (json) {
|
|
861
|
+
console.log(JSON.stringify(result, null, 2));
|
|
862
|
+
} else if (result.success && !dryRun) {
|
|
863
|
+
printSuccessMessage(result, i18n);
|
|
864
|
+
} else if (result.success && dryRun) {
|
|
865
|
+
printPreviewMessage(result, i18n);
|
|
866
|
+
} else {
|
|
867
|
+
console.error(ansis.red(`
|
|
868
|
+
${i18n.error}: ${result.error}
|
|
869
|
+
`));
|
|
870
|
+
}
|
|
871
|
+
return result;
|
|
872
|
+
} catch (error) {
|
|
873
|
+
spinner?.fail(i18n.installFailed);
|
|
874
|
+
const result = {
|
|
875
|
+
success: false,
|
|
876
|
+
source,
|
|
877
|
+
sourceType: sourceInfo.type,
|
|
878
|
+
pluginType,
|
|
879
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1122
880
|
};
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
881
|
+
if (json) {
|
|
882
|
+
console.log(JSON.stringify(result, null, 2));
|
|
883
|
+
} else {
|
|
884
|
+
console.error(ansis.red(`
|
|
885
|
+
${i18n.error}: ${result.error}
|
|
886
|
+
`));
|
|
1127
887
|
}
|
|
1128
|
-
return
|
|
888
|
+
return result;
|
|
1129
889
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
890
|
+
}
|
|
891
|
+
function printSuccessMessage(result, i18n) {
|
|
892
|
+
console.log();
|
|
893
|
+
console.log(ansis.green.bold(`\u2713 ${i18n.installed}`));
|
|
894
|
+
console.log();
|
|
895
|
+
console.log(` ${ansis.gray(i18n.name)}: ${result.details?.name || result.source}`);
|
|
896
|
+
if (result.details?.version) {
|
|
897
|
+
console.log(` ${ansis.gray(i18n.version)}: ${result.details.version}`);
|
|
898
|
+
}
|
|
899
|
+
console.log(` ${ansis.gray(i18n.type)}: ${result.pluginType}`);
|
|
900
|
+
console.log(` ${ansis.gray(i18n.path)}: ${result.installedPath}`);
|
|
901
|
+
console.log();
|
|
902
|
+
console.log(ansis.cyan(i18n.nextSteps));
|
|
903
|
+
switch (result.pluginType) {
|
|
904
|
+
case "skill":
|
|
905
|
+
console.log(` ${ansis.gray("\u2022")} ${i18n.skillHint}`);
|
|
906
|
+
break;
|
|
907
|
+
case "mcp":
|
|
908
|
+
console.log(` ${ansis.gray("\u2022")} ${i18n.mcpHint}`);
|
|
909
|
+
break;
|
|
910
|
+
case "agent":
|
|
911
|
+
console.log(` ${ansis.gray("\u2022")} ${i18n.agentHint}`);
|
|
912
|
+
break;
|
|
913
|
+
case "hook":
|
|
914
|
+
console.log(` ${ansis.gray("\u2022")} ${i18n.hookHint}`);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
console.log();
|
|
918
|
+
}
|
|
919
|
+
function printPreviewMessage(result, i18n) {
|
|
920
|
+
console.log();
|
|
921
|
+
console.log(ansis.yellow.bold(`\u26A1 ${i18n.preview}`));
|
|
922
|
+
console.log();
|
|
923
|
+
console.log(` ${ansis.gray(i18n.source)}: ${result.source}`);
|
|
924
|
+
console.log(` ${ansis.gray(i18n.type)}: ${result.pluginType}`);
|
|
925
|
+
console.log(` ${ansis.gray(i18n.target)}: ${result.installedPath}`);
|
|
926
|
+
if (result.details?.files?.length) {
|
|
927
|
+
console.log(` ${ansis.gray(i18n.files)}:`);
|
|
928
|
+
for (const file of result.details.files.slice(0, 5)) {
|
|
929
|
+
console.log(` ${ansis.gray("\u2022")} ${file}`);
|
|
1147
930
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
* 提取关键教训
|
|
1152
|
-
*/
|
|
1153
|
-
extractKeyLessons(reports) {
|
|
1154
|
-
const lessons = /* @__PURE__ */ new Set();
|
|
1155
|
-
for (const report of reports) {
|
|
1156
|
-
for (const measure of report.preventionMeasures.slice(0, 2)) {
|
|
1157
|
-
lessons.add(measure);
|
|
1158
|
-
}
|
|
931
|
+
if (result.details.files.length > 5) {
|
|
932
|
+
console.log(` ${ansis.gray("...")} ${i18n.andMore(result.details.files.length - 5)}`);
|
|
1159
933
|
}
|
|
1160
|
-
return Array.from(lessons).slice(0, 10);
|
|
1161
934
|
}
|
|
935
|
+
console.log();
|
|
936
|
+
console.log(ansis.gray(i18n.dryRunNote));
|
|
937
|
+
console.log();
|
|
1162
938
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
939
|
+
function getI18n(lang) {
|
|
940
|
+
const texts = {
|
|
941
|
+
"zh-CN": {
|
|
942
|
+
parsing: "\u89E3\u6790\u6765\u6E90...",
|
|
943
|
+
parsed: (type) => `\u6765\u6E90\u7C7B\u578B: ${type}`,
|
|
944
|
+
parseFailed: "\u89E3\u6790\u6765\u6E90\u5931\u8D25",
|
|
945
|
+
detectingType: "\u68C0\u6D4B\u63D2\u4EF6\u7C7B\u578B...",
|
|
946
|
+
detectedType: (type) => `\u68C0\u6D4B\u5230\u7C7B\u578B: ${type}`,
|
|
947
|
+
defaultType: "\u4F7F\u7528\u9ED8\u8BA4\u7C7B\u578B: skill",
|
|
948
|
+
installing: "\u5B89\u88C5\u4E2D...",
|
|
949
|
+
previewInstall: "\u9884\u89C8\u5B89\u88C5...",
|
|
950
|
+
installSuccess: "\u5B89\u88C5\u6210\u529F",
|
|
951
|
+
previewSuccess: "\u9884\u89C8\u5B8C\u6210",
|
|
952
|
+
installFailed: "\u5B89\u88C5\u5931\u8D25",
|
|
953
|
+
error: "\u9519\u8BEF",
|
|
954
|
+
installed: "\u63D2\u4EF6\u5DF2\u5B89\u88C5",
|
|
955
|
+
preview: "\u5B89\u88C5\u9884\u89C8 (dry-run)",
|
|
956
|
+
name: "\u540D\u79F0",
|
|
957
|
+
version: "\u7248\u672C",
|
|
958
|
+
type: "\u7C7B\u578B",
|
|
959
|
+
path: "\u8DEF\u5F84",
|
|
960
|
+
source: "\u6765\u6E90",
|
|
961
|
+
target: "\u76EE\u6807",
|
|
962
|
+
files: "\u6587\u4EF6",
|
|
963
|
+
nextSteps: "\u4E0B\u4E00\u6B65:",
|
|
964
|
+
skillHint: "\u4F7F\u7528 /skill-name \u5728 Claude Code \u4E2D\u8C03\u7528",
|
|
965
|
+
mcpHint: "\u8FD0\u884C ccjk mcp status \u67E5\u770B\u72B6\u6001",
|
|
966
|
+
agentHint: "\u4F7F\u7528 ccjk agent list \u67E5\u770B\u5DF2\u5B89\u88C5\u7684 agent",
|
|
967
|
+
hookHint: "\u8FD0\u884C ccjk hooks list \u67E5\u770B\u5DF2\u5B89\u88C5\u7684 hook",
|
|
968
|
+
dryRunNote: "\u8FD9\u662F\u9884\u89C8\u6A21\u5F0F\uFF0C\u672A\u5B9E\u9645\u5B89\u88C5\u3002\u79FB\u9664 --dry-run \u6267\u884C\u5B89\u88C5\u3002",
|
|
969
|
+
andMore: (n) => `\u8FD8\u6709 ${n} \u4E2A\u6587\u4EF6`
|
|
970
|
+
},
|
|
971
|
+
"en": {
|
|
972
|
+
parsing: "Parsing source...",
|
|
973
|
+
parsed: (type) => `Source type: ${type}`,
|
|
974
|
+
parseFailed: "Failed to parse source",
|
|
975
|
+
detectingType: "Detecting plugin type...",
|
|
976
|
+
detectedType: (type) => `Detected type: ${type}`,
|
|
977
|
+
defaultType: "Using default type: skill",
|
|
978
|
+
installing: "Installing...",
|
|
979
|
+
previewInstall: "Previewing installation...",
|
|
980
|
+
installSuccess: "Installation successful",
|
|
981
|
+
previewSuccess: "Preview complete",
|
|
982
|
+
installFailed: "Installation failed",
|
|
983
|
+
error: "Error",
|
|
984
|
+
installed: "Plugin installed",
|
|
985
|
+
preview: "Installation preview (dry-run)",
|
|
986
|
+
name: "Name",
|
|
987
|
+
version: "Version",
|
|
988
|
+
type: "Type",
|
|
989
|
+
path: "Path",
|
|
990
|
+
source: "Source",
|
|
991
|
+
target: "Target",
|
|
992
|
+
files: "Files",
|
|
993
|
+
nextSteps: "Next steps:",
|
|
994
|
+
skillHint: "Use /skill-name in Claude Code to invoke",
|
|
995
|
+
mcpHint: "Run ccjk mcp status to check status",
|
|
996
|
+
agentHint: "Use ccjk agent list to see installed agents",
|
|
997
|
+
hookHint: "Run ccjk hooks list to see installed hooks",
|
|
998
|
+
dryRunNote: "This is preview mode, nothing was installed. Remove --dry-run to install.",
|
|
999
|
+
andMore: (n) => `and ${n} more files`
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
return texts[lang];
|
|
1169
1003
|
}
|
|
1170
1004
|
|
|
1171
|
-
export {
|
|
1005
|
+
export { addCommand, parseSource };
|