ccjk 12.2.2 → 12.3.1
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-teams.mjs +3 -3
- package/dist/chunks/agent.mjs +2 -2
- package/dist/chunks/agents.mjs +4 -5
- package/dist/chunks/api-cli.mjs +5 -5
- package/dist/chunks/api-providers.mjs +1 -1
- package/dist/chunks/api.mjs +4 -4
- package/dist/chunks/auto-bootstrap.mjs +1 -1
- package/dist/chunks/auto-fixer.mjs +3 -3
- package/dist/chunks/auto-init.mjs +3 -3
- package/dist/chunks/auto-updater.mjs +9 -9
- package/dist/chunks/banner.mjs +2 -2
- package/dist/chunks/boost.mjs +4 -4
- package/dist/chunks/ccjk-agents.mjs +3 -3
- package/dist/chunks/ccjk-all.mjs +6 -6
- package/dist/chunks/ccjk-config.mjs +2 -2
- package/dist/chunks/ccjk-hooks.mjs +4 -4
- package/dist/chunks/ccjk-mcp.mjs +5 -5
- package/dist/chunks/ccjk-setup.mjs +5 -5
- package/dist/chunks/ccjk-skills.mjs +5 -5
- package/dist/chunks/ccr.mjs +14 -14
- package/dist/chunks/ccu.mjs +2 -2
- package/dist/chunks/check-updates.mjs +6 -6
- package/dist/chunks/claude-code-config-manager.mjs +5 -4
- package/dist/chunks/claude-code-incremental-manager.mjs +6 -6
- package/dist/chunks/claude-config.mjs +1 -1
- package/dist/chunks/claude-wrapper.mjs +1 -1
- package/dist/chunks/cli-hook.mjs +9 -10
- package/dist/chunks/codex-config-switch.mjs +6 -6
- package/dist/chunks/codex-provider-manager.mjs +6 -6
- package/dist/chunks/codex-uninstaller.mjs +2 -2
- package/dist/chunks/codex.mjs +5 -5
- package/dist/chunks/commands.mjs +2 -2
- package/dist/chunks/commands2.mjs +1 -1
- package/dist/chunks/commit.mjs +2 -2
- package/dist/chunks/completion.mjs +2 -2
- package/dist/chunks/config-consolidator.mjs +2 -2
- package/dist/chunks/config-switch.mjs +7 -7
- package/dist/chunks/config.mjs +3 -3
- package/dist/chunks/config2.mjs +4 -4
- package/dist/chunks/config3.mjs +3 -3
- package/dist/chunks/constants.mjs +1 -1
- package/dist/chunks/context-opt.mjs +442 -0
- package/dist/chunks/convoy-manager.mjs +355 -3
- package/dist/chunks/dashboard.mjs +2 -2
- package/dist/chunks/doctor.mjs +4 -4
- package/dist/chunks/evolution.mjs +2 -2
- package/dist/chunks/health-alerts.mjs +530 -4
- package/dist/chunks/help.mjs +1 -1
- package/dist/chunks/index.mjs +0 -23
- package/dist/chunks/index10.mjs +571 -634
- package/dist/chunks/index11.mjs +569 -1061
- package/dist/chunks/index12.mjs +1076 -914
- package/dist/chunks/index13.mjs +951 -135
- package/dist/chunks/index14.mjs +184 -209
- package/dist/chunks/index15.mjs +218 -0
- package/dist/chunks/index2.mjs +24 -19
- package/dist/chunks/index3.mjs +12 -19085
- package/dist/chunks/index4.mjs +19092 -16
- package/dist/chunks/index5.mjs +16 -7602
- package/dist/chunks/index6.mjs +7590 -159
- package/dist/chunks/index7.mjs +171 -1602
- package/dist/chunks/index8.mjs +1602 -19
- package/dist/chunks/index9.mjs +15 -612
- package/dist/chunks/init.mjs +13 -13
- package/dist/chunks/installer.mjs +5 -5
- package/dist/chunks/installer2.mjs +1 -1
- package/dist/chunks/interview.mjs +4 -4
- package/dist/chunks/manager.mjs +1 -1
- package/dist/chunks/marketplace.mjs +2 -2
- package/dist/chunks/mcp-cli.mjs +9 -9
- package/dist/chunks/mcp.mjs +7 -7
- package/dist/chunks/memory.mjs +3 -3
- package/dist/chunks/menu-hierarchical.mjs +14 -14
- package/dist/chunks/menu.mjs +12 -12
- package/dist/chunks/metrics-display.mjs +1 -1
- package/dist/chunks/migrator.mjs +1 -1
- package/dist/chunks/monitor.mjs +2 -2
- package/dist/chunks/notification.mjs +4 -4
- package/dist/chunks/onboarding-wizard.mjs +2 -2
- package/dist/chunks/onboarding.mjs +4 -4
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/paradigm.mjs +1 -1
- package/dist/chunks/permission-manager.mjs +2 -2
- package/dist/chunks/permissions.mjs +3 -3
- package/dist/chunks/persistence-manager.mjs +3 -3
- package/dist/chunks/plugin.mjs +2 -2
- package/dist/chunks/prompts.mjs +5 -5
- package/dist/chunks/providers.mjs +2 -2
- package/dist/chunks/quick-actions.mjs +2 -2
- package/dist/chunks/quick-provider.mjs +6 -5
- package/dist/chunks/quick-setup.mjs +10 -10
- package/dist/chunks/remote.mjs +5 -5
- package/dist/chunks/session.mjs +2 -2
- package/dist/chunks/sessions.mjs +1 -1
- package/dist/chunks/silent-updater.mjs +1 -1
- package/dist/chunks/simple-config.mjs +1 -1
- package/dist/chunks/skill2.mjs +3 -3
- package/dist/chunks/skills-sync.mjs +4 -4
- package/dist/chunks/skills.mjs +3 -3
- package/dist/chunks/slash-commands.mjs +3 -3
- package/dist/chunks/startup.mjs +1 -1
- package/dist/chunks/stats.mjs +2 -2
- package/dist/chunks/status.mjs +2 -2
- package/dist/chunks/team.mjs +3 -3
- package/dist/chunks/thinking.mjs +4 -4
- package/dist/chunks/trace.mjs +2 -2
- package/dist/chunks/uninstall.mjs +8 -8
- package/dist/chunks/update.mjs +9 -9
- package/dist/chunks/upgrade-manager.mjs +3 -3
- package/dist/chunks/version-checker.mjs +4 -4
- package/dist/chunks/vim.mjs +3 -3
- package/dist/chunks/workflows.mjs +1 -1
- package/dist/chunks/wsl.mjs +1 -1
- package/dist/chunks/zero-config.mjs +3 -3
- package/dist/cli.mjs +56 -23
- package/dist/index.mjs +5 -5
- package/dist/shared/{ccjk.CCcQfbni.mjs → ccjk.B1TwPltj.mjs} +1 -1
- package/dist/shared/{ccjk.CePkJq2S.mjs → ccjk.BfIpomdz.mjs} +1 -1
- package/dist/shared/{ccjk.D8ZLYSZZ.mjs → ccjk.CXzjn01x.mjs} +1 -1
- package/dist/shared/{ccjk.Cjj8SVrn.mjs → ccjk.Cot9p9_n.mjs} +1 -1
- package/dist/shared/{ccjk.CvChMYvB.mjs → ccjk.DCw2WnZU.mjs} +1 -1
- package/dist/shared/{ccjk.DG_o24cZ.mjs → ccjk.DJdmgr2d.mjs} +1 -1
- package/dist/shared/{ccjk.BIxuVL3_.mjs → ccjk.DcKLglJQ.mjs} +2 -2
- package/dist/shared/{ccjk.DLLw-h4Y.mjs → ccjk.DfXjf8EC.mjs} +2 -2
- package/dist/shared/{ccjk.KpFl2RDA.mjs → ccjk.DpstNaeR.mjs} +3 -3
- package/dist/shared/{ccjk.DOBWBkFR.mjs → ccjk.XsJWJuQP.mjs} +5 -5
- package/dist/shared/{ccjk._dESH4Rk.mjs → ccjk.dYDLfmph.mjs} +1 -1
- package/dist/shared/{ccjk.DS7UESmF.mjs → ccjk.hrRv8G6j.mjs} +4 -4
- package/dist/shared/{ccjk.BWFpnOr3.mjs → ccjk.mJpVRDZ8.mjs} +1 -1
- package/dist/templates/claude-code/common/settings.json +3 -1
- package/package.json +20 -18
- package/templates/claude-code/common/settings.json +3 -1
- package/dist/chunks/context-loader.mjs +0 -351
- package/dist/chunks/context.mjs +0 -372
- package/dist/chunks/health-check.mjs +0 -532
package/dist/chunks/index12.mjs
CHANGED
|
@@ -1,1009 +1,1171 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import path__default from 'node:path';
|
|
6
|
-
import { exec } from 'node:child_process';
|
|
7
|
-
import { promisify } from 'node:util';
|
|
8
|
-
import '../shared/ccjk.BAGoDD49.mjs';
|
|
9
|
-
import 'node:process';
|
|
10
|
-
import '../shared/ccjk.Cjgrln_h.mjs';
|
|
11
|
-
import '../shared/ccjk.DeWpAShp.mjs';
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as process from 'node:process';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
12
5
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
function getFixCommits(options) {
|
|
7
|
+
const { since, until, limit = 100, cwd = process.cwd() } = options;
|
|
8
|
+
let gitCmd = 'git log --pretty=format:"%H|%h|%s|%an|%ai" --name-only';
|
|
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 [];
|
|
16
18
|
}
|
|
17
|
-
return path__default.join(os__default.homedir(), ".ccjk");
|
|
18
|
-
}
|
|
19
|
-
function getInstallPath(pluginType, name) {
|
|
20
|
-
const configDir = getCcjkConfigDir();
|
|
21
|
-
const typeDir = {
|
|
22
|
-
skill: "skills",
|
|
23
|
-
mcp: "mcp-servers",
|
|
24
|
-
agent: "agents",
|
|
25
|
-
hook: "hooks"
|
|
26
|
-
}[pluginType];
|
|
27
|
-
return path__default.join(configDir, typeDir, name);
|
|
28
19
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const entries =
|
|
20
|
+
function parseGitLog(output) {
|
|
21
|
+
const commits = [];
|
|
22
|
+
const entries = output.trim().split("\n\n");
|
|
32
23
|
for (const entry of entries) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
const lines = entry.split("\n");
|
|
25
|
+
if (lines.length === 0)
|
|
26
|
+
continue;
|
|
27
|
+
const [firstLine, ...fileLines] = lines;
|
|
28
|
+
const parts = firstLine.split("|");
|
|
29
|
+
if (parts.length < 5)
|
|
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
|
+
});
|
|
39
42
|
}
|
|
40
43
|
}
|
|
44
|
+
return commits;
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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));
|
|
54
62
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
63
|
+
function analyzeFixCommit(commit, cwd = process.cwd()) {
|
|
64
|
+
const diff = getCommitDiff(commit.hash, cwd);
|
|
65
|
+
const bugType = detectBugType(commit.message, diff);
|
|
66
|
+
const severity = detectSeverity(commit.message, diff, commit.files);
|
|
67
|
+
const rootCause = extractRootCause(commit.message, diff);
|
|
68
|
+
const solution = extractSolution(diff);
|
|
69
|
+
const preventionSuggestions = generatePreventionSuggestions(bugType);
|
|
70
|
+
return {
|
|
71
|
+
commit,
|
|
72
|
+
bugType,
|
|
73
|
+
severity,
|
|
74
|
+
rootCause,
|
|
75
|
+
solution,
|
|
76
|
+
preventionSuggestions,
|
|
77
|
+
relatedPostmortems: []
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function getCommitDiff(hash, cwd) {
|
|
59
81
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
success: false,
|
|
69
|
-
source: sourceInfo.originalUrl,
|
|
70
|
-
sourceType: "github",
|
|
71
|
-
pluginType,
|
|
72
|
-
error: `Plugin already exists at ${installPath}. Use --force to overwrite.`
|
|
73
|
-
};
|
|
74
|
-
} catch {
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (dryRun) {
|
|
78
|
-
const files = await listRepoFiles(owner, repo, actualRef, subpath);
|
|
79
|
-
return {
|
|
80
|
-
success: true,
|
|
81
|
-
source: sourceInfo.originalUrl,
|
|
82
|
-
sourceType: "github",
|
|
83
|
-
pluginType,
|
|
84
|
-
installedPath: installPath,
|
|
85
|
-
details: {
|
|
86
|
-
name: repo,
|
|
87
|
-
version: actualRef,
|
|
88
|
-
description: repoInfo.description || void 0,
|
|
89
|
-
files: files.slice(0, 20)
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const tempDir = await downloadRepo(owner, repo, actualRef);
|
|
94
|
-
const sourcePath = subpath ? path__default.join(tempDir, subpath) : tempDir;
|
|
95
|
-
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
96
|
-
await copyDirectory(sourcePath, installPath);
|
|
97
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
98
|
-
const installedFiles = await listInstalledFiles$1(installPath);
|
|
99
|
-
return {
|
|
100
|
-
success: true,
|
|
101
|
-
source: sourceInfo.originalUrl,
|
|
102
|
-
sourceType: "github",
|
|
103
|
-
pluginType,
|
|
104
|
-
installedPath: installPath,
|
|
105
|
-
details: {
|
|
106
|
-
name: repo,
|
|
107
|
-
version: actualRef,
|
|
108
|
-
description: repoInfo.description || void 0,
|
|
109
|
-
files: installedFiles
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
} catch (error) {
|
|
113
|
-
return {
|
|
114
|
-
success: false,
|
|
115
|
-
source: sourceInfo.originalUrl,
|
|
116
|
-
sourceType: "github",
|
|
117
|
-
pluginType,
|
|
118
|
-
error: error instanceof Error ? error.message : String(error)
|
|
119
|
-
};
|
|
82
|
+
return execSync(`git show ${hash} --pretty="" --patch`, {
|
|
83
|
+
cwd,
|
|
84
|
+
encoding: "utf-8",
|
|
85
|
+
maxBuffer: 1024 * 1024 * 10
|
|
86
|
+
// 10MB
|
|
87
|
+
});
|
|
88
|
+
} catch {
|
|
89
|
+
return "";
|
|
120
90
|
}
|
|
121
91
|
}
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
92
|
+
function detectBugType(message, diff) {
|
|
93
|
+
const content = `${message}
|
|
94
|
+
${diff}`.toLowerCase();
|
|
95
|
+
const patterns = [
|
|
96
|
+
{
|
|
97
|
+
category: "type-safety",
|
|
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
|
+
]
|
|
128
164
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
|
|
165
|
+
];
|
|
166
|
+
for (const { category, patterns: categoryPatterns } of patterns) {
|
|
167
|
+
if (categoryPatterns.some((p) => p.test(content))) {
|
|
168
|
+
return category;
|
|
133
169
|
}
|
|
134
|
-
throw new Error(`Failed to fetch repository info: ${response.statusText}`);
|
|
135
170
|
}
|
|
136
|
-
return
|
|
171
|
+
return "other";
|
|
137
172
|
}
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
"Accept": "application/vnd.github.v3+json",
|
|
144
|
-
"User-Agent": "ccjk-cli"
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
if (!response.ok) {
|
|
148
|
-
return [];
|
|
173
|
+
function detectSeverity(message, diff, files) {
|
|
174
|
+
const content = `${message}
|
|
175
|
+
${diff}`.toLowerCase();
|
|
176
|
+
if (/critical|crash|data.*loss|security.*vuln/i.test(content) || files.some((f) => /auth|security|payment/i.test(f))) {
|
|
177
|
+
return "critical";
|
|
149
178
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const zipPath = path__default.join(tempDir, "repo.zip");
|
|
158
|
-
await fs.mkdir(tempDir, { recursive: true });
|
|
159
|
-
await downloadFile(zipUrl, zipPath);
|
|
160
|
-
const extractedDir = await extractZip(zipPath, tempDir);
|
|
161
|
-
await fs.unlink(zipPath);
|
|
162
|
-
return extractedDir;
|
|
179
|
+
if (/breaking|major|important|urgent/i.test(content) || files.length > 10) {
|
|
180
|
+
return "high";
|
|
181
|
+
}
|
|
182
|
+
if (/moderate|minor.*issue/i.test(content) || files.length > 3) {
|
|
183
|
+
return "medium";
|
|
184
|
+
}
|
|
185
|
+
return "low";
|
|
163
186
|
}
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
187
|
+
function extractRootCause(message, diff) {
|
|
188
|
+
const causePatterns = [
|
|
189
|
+
/caused by[:\s]+(.+)/i,
|
|
190
|
+
/root cause[:\s]+(.+)/i,
|
|
191
|
+
/because[:\s]+(.+)/i,
|
|
192
|
+
/due to[:\s]+(.+)/i,
|
|
193
|
+
/原因[::]\s*(.+)/,
|
|
194
|
+
/由于\s*(.+)/
|
|
195
|
+
];
|
|
196
|
+
for (const pattern of causePatterns) {
|
|
197
|
+
const match = message.match(pattern);
|
|
198
|
+
if (match) {
|
|
199
|
+
return match[1].trim();
|
|
175
200
|
}
|
|
176
201
|
}
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
180
|
-
|
|
202
|
+
const removedLines = diff.match(/^-[^-].*/gm) || [];
|
|
203
|
+
const addedLines = diff.match(/^\+[^+].*/gm) || [];
|
|
204
|
+
if (removedLines.length > 0 && addedLines.length > 0) {
|
|
205
|
+
return `\u4EE3\u7801\u53D8\u66F4: \u79FB\u9664 ${removedLines.length} \u884C, \u65B0\u589E ${addedLines.length} \u884C`;
|
|
181
206
|
}
|
|
182
|
-
return
|
|
207
|
+
return "\u9700\u8981\u8FDB\u4E00\u6B65\u5206\u6790";
|
|
183
208
|
}
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
await walk(path__default.join(currentDir, entry.name), relativePath);
|
|
192
|
-
} else {
|
|
193
|
-
files.push(relativePath);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
209
|
+
function extractSolution(diff) {
|
|
210
|
+
const addedLines = diff.match(/^\+[^+].*/gm) || [];
|
|
211
|
+
if (addedLines.length === 0) {
|
|
212
|
+
return "\u5220\u9664\u4E86\u95EE\u9898\u4EE3\u7801";
|
|
213
|
+
}
|
|
214
|
+
if (addedLines.length <= 5) {
|
|
215
|
+
return addedLines.map((l) => l.substring(1)).join("\n");
|
|
196
216
|
}
|
|
197
|
-
|
|
198
|
-
return files;
|
|
217
|
+
return `\u65B0\u589E ${addedLines.length} \u884C\u4EE3\u7801\u4FEE\u590D\u95EE\u9898`;
|
|
199
218
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
219
|
+
function generatePreventionSuggestions(bugType, _diff) {
|
|
220
|
+
const suggestions = {
|
|
221
|
+
"type-safety": [
|
|
222
|
+
"\u542F\u7528 TypeScript strict \u6A21\u5F0F",
|
|
223
|
+
"\u4F7F\u7528\u53EF\u9009\u94FE\u64CD\u4F5C\u7B26 (?.) \u8FDB\u884C\u7A7A\u503C\u68C0\u67E5",
|
|
224
|
+
"\u4E3A\u6240\u6709\u5916\u90E8\u6570\u636E\u6DFB\u52A0\u8FD0\u884C\u65F6\u9A8C\u8BC1",
|
|
225
|
+
"\u4F7F\u7528 zod \u6216 io-ts \u8FDB\u884C\u7C7B\u578B\u9A8C\u8BC1"
|
|
226
|
+
],
|
|
227
|
+
"error-handling": [
|
|
228
|
+
"\u4E3A\u6240\u6709\u5F02\u6B65\u64CD\u4F5C\u6DFB\u52A0 try-catch",
|
|
229
|
+
"\u5B9E\u73B0\u5168\u5C40\u9519\u8BEF\u5904\u7406\u4E2D\u95F4\u4EF6",
|
|
230
|
+
"\u6DFB\u52A0\u9519\u8BEF\u8FB9\u754C\u7EC4\u4EF6 (React)",
|
|
231
|
+
"\u4F7F\u7528 Result \u7C7B\u578B\u66FF\u4EE3\u5F02\u5E38"
|
|
232
|
+
],
|
|
233
|
+
"performance": [
|
|
234
|
+
"\u6DFB\u52A0\u6027\u80FD\u76D1\u63A7\u548C\u544A\u8B66",
|
|
235
|
+
"\u5B9E\u73B0\u7F13\u5B58\u7B56\u7565",
|
|
236
|
+
"\u4F7F\u7528\u61D2\u52A0\u8F7D\u548C\u4EE3\u7801\u5206\u5272",
|
|
237
|
+
"\u5B9A\u671F\u8FDB\u884C\u6027\u80FD\u6D4B\u8BD5"
|
|
238
|
+
],
|
|
239
|
+
"security": [
|
|
240
|
+
"\u5B9E\u65BD\u5B89\u5168\u4EE3\u7801\u5BA1\u67E5",
|
|
241
|
+
"\u4F7F\u7528\u5B89\u5168\u626B\u63CF\u5DE5\u5177",
|
|
242
|
+
"\u9075\u5FAA OWASP \u5B89\u5168\u6307\u5357",
|
|
243
|
+
"\u5B9A\u671F\u66F4\u65B0\u4F9D\u8D56"
|
|
244
|
+
],
|
|
245
|
+
"race-condition": [
|
|
246
|
+
"\u4F7F\u7528\u9002\u5F53\u7684\u9501\u673A\u5236",
|
|
247
|
+
"\u907F\u514D\u5171\u4EAB\u53EF\u53D8\u72B6\u6001",
|
|
248
|
+
"\u4F7F\u7528\u539F\u5B50\u64CD\u4F5C",
|
|
249
|
+
"\u6DFB\u52A0\u5E76\u53D1\u6D4B\u8BD5"
|
|
250
|
+
],
|
|
251
|
+
"logic-error": [
|
|
252
|
+
"\u589E\u52A0\u5355\u5143\u6D4B\u8BD5\u8986\u76D6",
|
|
253
|
+
"\u5B9E\u65BD\u4EE3\u7801\u5BA1\u67E5",
|
|
254
|
+
"\u6DFB\u52A0\u65AD\u8A00\u548C\u4E0D\u53D8\u91CF\u68C0\u67E5",
|
|
255
|
+
"\u4F7F\u7528\u5F62\u5F0F\u5316\u9A8C\u8BC1\u5DE5\u5177"
|
|
256
|
+
],
|
|
257
|
+
"api-misuse": [
|
|
258
|
+
"\u5B8C\u5584 API \u6587\u6863",
|
|
259
|
+
"\u6DFB\u52A0\u53C2\u6570\u9A8C\u8BC1",
|
|
260
|
+
"\u63D0\u4F9B\u4F7F\u7528\u793A\u4F8B",
|
|
261
|
+
"\u5B9E\u73B0 API \u7248\u672C\u63A7\u5236"
|
|
262
|
+
],
|
|
263
|
+
"configuration": [
|
|
264
|
+
"\u4F7F\u7528\u914D\u7F6E\u9A8C\u8BC1",
|
|
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"
|
|
246
323
|
}
|
|
247
324
|
};
|
|
248
|
-
|
|
249
|
-
if (isFile) {
|
|
250
|
-
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
251
|
-
if (absolutePath.endsWith(".md")) {
|
|
252
|
-
await fs.copyFile(absolutePath, installPath);
|
|
253
|
-
} else {
|
|
254
|
-
await fs.mkdir(installPath, { recursive: true });
|
|
255
|
-
await fs.copyFile(
|
|
256
|
-
absolutePath,
|
|
257
|
-
path__default.join(installPath, path__default.basename(absolutePath))
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
await fs.mkdir(path__default.dirname(installPath), { recursive: true });
|
|
262
|
-
await copyDirectory(absolutePath, installPath);
|
|
263
|
-
}
|
|
264
|
-
const installedFiles = isFile ? [path__default.basename(absolutePath)] : await listFiles(installPath);
|
|
265
|
-
return {
|
|
266
|
-
success: true,
|
|
267
|
-
source: originalPath,
|
|
268
|
-
sourceType: "local",
|
|
269
|
-
pluginType,
|
|
270
|
-
installedPath: installPath,
|
|
271
|
-
details: {
|
|
272
|
-
name: pluginInfo.name || pluginName,
|
|
273
|
-
version: pluginInfo.version,
|
|
274
|
-
description: pluginInfo.description,
|
|
275
|
-
files: installedFiles
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
} catch (error) {
|
|
279
|
-
return {
|
|
280
|
-
success: false,
|
|
281
|
-
source: originalPath,
|
|
282
|
-
sourceType: "local",
|
|
283
|
-
pluginType,
|
|
284
|
-
error: error instanceof Error ? error.message : String(error)
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
async function listFiles(dir) {
|
|
289
|
-
const files = [];
|
|
290
|
-
async function walk(currentDir, prefix = "") {
|
|
291
|
-
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
292
|
-
for (const entry of entries) {
|
|
293
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules") {
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
297
|
-
if (entry.isDirectory()) {
|
|
298
|
-
await walk(path__default.join(currentDir, entry.name), relativePath);
|
|
299
|
-
} else {
|
|
300
|
-
files.push(relativePath);
|
|
301
|
-
}
|
|
325
|
+
reports.push(report);
|
|
302
326
|
}
|
|
303
327
|
}
|
|
304
|
-
|
|
305
|
-
return files;
|
|
328
|
+
return reports;
|
|
306
329
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const packageJsonPath = path__default.join(sourcePath, "package.json");
|
|
314
|
-
const content = await fs.readFile(packageJsonPath, "utf-8");
|
|
315
|
-
const packageJson = JSON.parse(content);
|
|
316
|
-
return {
|
|
317
|
-
name: packageJson.name,
|
|
318
|
-
version: packageJson.version,
|
|
319
|
-
description: packageJson.description
|
|
320
|
-
};
|
|
321
|
-
} catch {
|
|
322
|
-
}
|
|
323
|
-
const metaFiles = ["SKILL.md", "skill.md", "README.md", "readme.md"];
|
|
324
|
-
for (const metaFile of metaFiles) {
|
|
325
|
-
try {
|
|
326
|
-
const metaPath = path__default.join(sourcePath, metaFile);
|
|
327
|
-
const content = await fs.readFile(metaPath, "utf-8");
|
|
328
|
-
const titleMatch = content.match(/^#\s+(.+)$/m);
|
|
329
|
-
if (titleMatch) {
|
|
330
|
-
return { name: titleMatch[1].trim() };
|
|
331
|
-
}
|
|
332
|
-
} catch {
|
|
330
|
+
function groupByCategory(analyses) {
|
|
331
|
+
const grouped = {};
|
|
332
|
+
for (const analysis of analyses) {
|
|
333
|
+
const category = analysis.bugType;
|
|
334
|
+
if (!grouped[category]) {
|
|
335
|
+
grouped[category] = [];
|
|
333
336
|
}
|
|
337
|
+
grouped[category].push(analysis);
|
|
334
338
|
}
|
|
335
|
-
return
|
|
339
|
+
return grouped;
|
|
336
340
|
}
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const installPath = getInstallPath(pluginType, shortName);
|
|
347
|
-
if (!force) {
|
|
348
|
-
try {
|
|
349
|
-
await fs.access(installPath);
|
|
350
|
-
return {
|
|
351
|
-
success: false,
|
|
352
|
-
source: packageName,
|
|
353
|
-
sourceType: "npm",
|
|
354
|
-
pluginType,
|
|
355
|
-
error: `Plugin already exists at ${installPath}. Use --force to overwrite.`
|
|
356
|
-
};
|
|
357
|
-
} catch {
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (dryRun) {
|
|
361
|
-
const files = packageInfo.files || ["(package files)"];
|
|
362
|
-
return {
|
|
363
|
-
success: true,
|
|
364
|
-
source: packageName,
|
|
365
|
-
sourceType: "npm",
|
|
366
|
-
pluginType,
|
|
367
|
-
installedPath: installPath,
|
|
368
|
-
details: {
|
|
369
|
-
name: packageName,
|
|
370
|
-
version: packageVersion,
|
|
371
|
-
description: packageInfo.description,
|
|
372
|
-
files
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
if (pluginType === "mcp") {
|
|
377
|
-
await installMcpPackage(packageName, packageVersion, installPath);
|
|
341
|
+
function mergeAnalyses(analyses) {
|
|
342
|
+
const merged = [];
|
|
343
|
+
for (const analysis of analyses) {
|
|
344
|
+
const similar = merged.find(
|
|
345
|
+
(m) => calculateFileOverlap(m.commit.files, analysis.commit.files) > 0.5
|
|
346
|
+
);
|
|
347
|
+
if (similar) {
|
|
348
|
+
similar.commit.files = Array.from(/* @__PURE__ */ new Set([...similar.commit.files, ...analysis.commit.files]));
|
|
349
|
+
similar.preventionSuggestions = Array.from(/* @__PURE__ */ new Set([...similar.preventionSuggestions, ...analysis.preventionSuggestions]));
|
|
378
350
|
} else {
|
|
379
|
-
|
|
351
|
+
merged.push({ ...analysis });
|
|
380
352
|
}
|
|
381
|
-
const installedFiles = await listInstalledFiles(installPath);
|
|
382
|
-
return {
|
|
383
|
-
success: true,
|
|
384
|
-
source: packageName,
|
|
385
|
-
sourceType: "npm",
|
|
386
|
-
pluginType,
|
|
387
|
-
installedPath: installPath,
|
|
388
|
-
details: {
|
|
389
|
-
name: packageName,
|
|
390
|
-
version: packageVersion,
|
|
391
|
-
description: packageInfo.description,
|
|
392
|
-
files: installedFiles
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
} catch (error) {
|
|
396
|
-
return {
|
|
397
|
-
success: false,
|
|
398
|
-
source: packageName,
|
|
399
|
-
sourceType: "npm",
|
|
400
|
-
pluginType,
|
|
401
|
-
error: error instanceof Error ? error.message : String(error)
|
|
402
|
-
};
|
|
403
353
|
}
|
|
354
|
+
return merged;
|
|
404
355
|
}
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
throw new Error(`Failed to fetch package info: ${response.statusText}`);
|
|
413
|
-
}
|
|
414
|
-
const data = await response.json();
|
|
415
|
-
return {
|
|
416
|
-
version: data.version,
|
|
417
|
-
description: data.description,
|
|
418
|
-
files: data.files
|
|
419
|
-
};
|
|
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;
|
|
420
362
|
}
|
|
421
|
-
function
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return parts[1] || packageName;
|
|
425
|
-
}
|
|
426
|
-
return packageName;
|
|
363
|
+
function getNextId(existingIds) {
|
|
364
|
+
const numbers = existingIds.map((id) => Number.parseInt(id.replace("PM-", ""), 10)).filter((n) => !Number.isNaN(n));
|
|
365
|
+
return numbers.length > 0 ? Math.max(...numbers) + 1 : 1;
|
|
427
366
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
367
|
+
function generateTitle(analysis) {
|
|
368
|
+
const categoryTitles = {
|
|
369
|
+
"type-safety": "\u7C7B\u578B\u5B89\u5168\u95EE\u9898",
|
|
370
|
+
"error-handling": "\u9519\u8BEF\u5904\u7406\u7F3A\u5931",
|
|
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"
|
|
437
380
|
};
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
)
|
|
442
|
-
|
|
443
|
-
await execAsync("npm install", { cwd: installPath });
|
|
444
|
-
} catch (error) {
|
|
445
|
-
try {
|
|
446
|
-
await execAsync("pnpm install", { cwd: installPath });
|
|
447
|
-
} catch {
|
|
448
|
-
throw new Error(
|
|
449
|
-
`Failed to install package. Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
450
|
-
);
|
|
451
|
-
}
|
|
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}`;
|
|
452
386
|
}
|
|
387
|
+
return baseTitle;
|
|
453
388
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
const tarballResponse = await fetch(tarballUrl);
|
|
466
|
-
if (!tarballResponse.ok) {
|
|
467
|
-
throw new Error(`Failed to download tarball: ${tarballResponse.statusText}`);
|
|
468
|
-
}
|
|
469
|
-
await fs.mkdir(installPath, { recursive: true });
|
|
470
|
-
const tarballBuffer = Buffer.from(await tarballResponse.arrayBuffer());
|
|
471
|
-
const tarballPath = path__default.join(installPath, "package.tgz");
|
|
472
|
-
await fs.writeFile(tarballPath, tarballBuffer);
|
|
473
|
-
try {
|
|
474
|
-
await execAsync(`tar -xzf package.tgz --strip-components=1`, { cwd: installPath });
|
|
475
|
-
} finally {
|
|
476
|
-
await fs.unlink(tarballPath).catch(() => {
|
|
477
|
-
});
|
|
478
|
-
}
|
|
389
|
+
function generateDescription(analysis) {
|
|
390
|
+
return `
|
|
391
|
+
\u5728 ${analysis.commit.date} \u53D1\u73B0\u5E76\u4FEE\u590D\u4E86\u4E00\u4E2A ${analysis.bugType} \u7C7B\u578B\u7684\u95EE\u9898\u3002
|
|
392
|
+
|
|
393
|
+
**\u63D0\u4EA4\u4FE1\u606F**: ${analysis.commit.message}
|
|
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();
|
|
479
400
|
}
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
401
|
+
function generateAiDirectives(analysis) {
|
|
402
|
+
const directives = [];
|
|
403
|
+
const categoryDirectives = {
|
|
404
|
+
"type-safety": [
|
|
405
|
+
"\u5904\u7406\u5916\u90E8\u6570\u636E\u65F6\u5FC5\u987B\u8FDB\u884C\u7A7A\u503C\u68C0\u67E5",
|
|
406
|
+
"\u4F7F\u7528 TypeScript \u4E25\u683C\u6A21\u5F0F",
|
|
407
|
+
"\u907F\u514D\u4F7F\u7528 any \u7C7B\u578B"
|
|
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`);
|
|
463
|
+
}
|
|
464
|
+
if (file.includes("config")) {
|
|
465
|
+
directives.push(`\u4FEE\u6539\u914D\u7F6E\u6587\u4EF6\u65F6\u786E\u4FDD\u5411\u540E\u517C\u5BB9`);
|
|
496
466
|
}
|
|
497
467
|
}
|
|
498
|
-
|
|
499
|
-
return files;
|
|
468
|
+
return Array.from(new Set(directives));
|
|
500
469
|
}
|
|
470
|
+
function generateDetectionPatterns(analysis) {
|
|
471
|
+
const patterns = [];
|
|
472
|
+
const categoryPatterns = {
|
|
473
|
+
"type-safety": [
|
|
474
|
+
{
|
|
475
|
+
type: "regex",
|
|
476
|
+
pattern: "\\.\\w+\\.\\w+\\.\\w+(?!\\?)",
|
|
477
|
+
description: "\u8FDE\u7EED\u5C5E\u6027\u8BBF\u95EE\u672A\u4F7F\u7528\u53EF\u9009\u94FE",
|
|
478
|
+
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
479
|
+
severity: "medium"
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
type: "regex",
|
|
483
|
+
pattern: "as any",
|
|
484
|
+
description: "\u4F7F\u7528 any \u7C7B\u578B\u65AD\u8A00",
|
|
485
|
+
fileTypes: [".ts", ".tsx"],
|
|
486
|
+
severity: "low"
|
|
487
|
+
}
|
|
488
|
+
],
|
|
489
|
+
"error-handling": [
|
|
490
|
+
{
|
|
491
|
+
type: "regex",
|
|
492
|
+
pattern: "catch\\s*\\(\\s*\\w*\\s*\\)\\s*\\{\\s*\\}",
|
|
493
|
+
description: "\u7A7A\u7684 catch \u5757",
|
|
494
|
+
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
495
|
+
severity: "high"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
type: "regex",
|
|
499
|
+
pattern: "\\.then\\([^)]+\\)(?!\\.catch)",
|
|
500
|
+
description: "Promise \u672A\u5904\u7406 rejection",
|
|
501
|
+
fileTypes: [".ts", ".tsx", ".js", ".jsx"],
|
|
502
|
+
severity: "medium"
|
|
503
|
+
}
|
|
504
|
+
],
|
|
505
|
+
"performance": [
|
|
506
|
+
{
|
|
507
|
+
type: "regex",
|
|
508
|
+
pattern: "for\\s*\\([^)]+\\)\\s*\\{[^}]*await",
|
|
509
|
+
description: "\u5FAA\u73AF\u4E2D\u4F7F\u7528 await",
|
|
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"
|
|
542
|
+
}
|
|
543
|
+
],
|
|
544
|
+
"other": []
|
|
545
|
+
};
|
|
546
|
+
patterns.push(...categoryPatterns[analysis.bugType] || []);
|
|
547
|
+
return patterns;
|
|
548
|
+
}
|
|
549
|
+
const PostmortemAnalyzer = {
|
|
550
|
+
getFixCommits,
|
|
551
|
+
analyzeFixCommit,
|
|
552
|
+
generatePostmortem
|
|
553
|
+
};
|
|
501
554
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
555
|
+
const DEFAULT_CONFIG = {
|
|
556
|
+
enabled: true,
|
|
557
|
+
directory: "./postmortem",
|
|
558
|
+
autoSyncToClaudeMd: true,
|
|
559
|
+
maxSyncItems: 10,
|
|
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"
|
|
507
568
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
569
|
+
};
|
|
570
|
+
const INDEX_FILE = "index.json";
|
|
571
|
+
const CLAUDE_MD_SECTION_START = "<!-- POSTMORTEM_START -->";
|
|
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);
|
|
511
581
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
};
|
|
582
|
+
// ==========================================================================
|
|
583
|
+
// Initialization
|
|
584
|
+
// ==========================================================================
|
|
585
|
+
/**
|
|
586
|
+
* 初始化 Postmortem 系统
|
|
587
|
+
*/
|
|
588
|
+
async init() {
|
|
589
|
+
this.ensureDirectories();
|
|
590
|
+
const commits = PostmortemAnalyzer.getFixCommits({
|
|
591
|
+
limit: 200,
|
|
592
|
+
cwd: this.projectRoot
|
|
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 };
|
|
524
610
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
611
|
+
/**
|
|
612
|
+
* 确保目录存在
|
|
613
|
+
*/
|
|
614
|
+
ensureDirectories() {
|
|
615
|
+
const dirs = [
|
|
616
|
+
this.postmortemDir,
|
|
617
|
+
path.join(this.postmortemDir, "categories"),
|
|
618
|
+
path.join(this.postmortemDir, "summaries")
|
|
619
|
+
];
|
|
620
|
+
for (const dir of dirs) {
|
|
621
|
+
if (!fs.existsSync(dir)) {
|
|
622
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
623
|
+
}
|
|
624
|
+
}
|
|
537
625
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
626
|
+
// ==========================================================================
|
|
627
|
+
// Report Management
|
|
628
|
+
// ==========================================================================
|
|
629
|
+
/**
|
|
630
|
+
* 保存 Postmortem 报告
|
|
631
|
+
*/
|
|
632
|
+
saveReport(report) {
|
|
633
|
+
const filename = `${report.id}-${this.slugify(report.title)}.md`;
|
|
634
|
+
const filepath = path.join(this.postmortemDir, filename);
|
|
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;
|
|
547
640
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
if (
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
641
|
+
/**
|
|
642
|
+
* 读取 Postmortem 报告
|
|
643
|
+
*/
|
|
644
|
+
getReport(id) {
|
|
645
|
+
const jsonPath = path.join(this.postmortemDir, `${id}.json`);
|
|
646
|
+
if (!fs.existsSync(jsonPath)) {
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
try {
|
|
650
|
+
const content = fs.readFileSync(jsonPath, "utf-8");
|
|
651
|
+
return JSON.parse(content);
|
|
652
|
+
} catch {
|
|
653
|
+
return null;
|
|
559
654
|
}
|
|
560
|
-
return {
|
|
561
|
-
type: "local",
|
|
562
|
-
absolutePath,
|
|
563
|
-
originalPath: source
|
|
564
|
-
};
|
|
565
655
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
656
|
+
/**
|
|
657
|
+
* 列出所有 Postmortem
|
|
658
|
+
*/
|
|
659
|
+
listReports() {
|
|
660
|
+
const index = this.loadIndex();
|
|
661
|
+
return index?.reports || [];
|
|
572
662
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
scope: scopedMatch[1],
|
|
583
|
-
packageName: `${scopedMatch[1]}/${scopedMatch[2]}`,
|
|
584
|
-
version: scopedMatch[3]
|
|
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}"
|
|
585
672
|
};
|
|
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
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* 生成 slug
|
|
742
|
+
*/
|
|
743
|
+
slugify(text) {
|
|
744
|
+
return text.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").substring(0, 50);
|
|
586
745
|
}
|
|
587
|
-
|
|
588
|
-
|
|
746
|
+
// ==========================================================================
|
|
747
|
+
// Index Management
|
|
748
|
+
// ==========================================================================
|
|
749
|
+
/**
|
|
750
|
+
* 创建空索引
|
|
751
|
+
*/
|
|
752
|
+
createEmptyIndex() {
|
|
589
753
|
return {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
754
|
+
version: "1.0.0",
|
|
755
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
756
|
+
stats: {
|
|
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: []
|
|
593
775
|
};
|
|
594
776
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
return `https://raw.githubusercontent.com/${info.owner}/${info.repo}/${ref}/${filePath}`;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
async function detectPluginType(sourceInfo) {
|
|
606
|
-
const result = await detectPluginTypeWithConfidence(sourceInfo);
|
|
607
|
-
return result.type;
|
|
608
|
-
}
|
|
609
|
-
async function detectPluginTypeWithConfidence(sourceInfo) {
|
|
610
|
-
switch (sourceInfo.type) {
|
|
611
|
-
case "github":
|
|
612
|
-
return detectFromGitHub(sourceInfo);
|
|
613
|
-
case "npm":
|
|
614
|
-
return detectFromNpm(sourceInfo);
|
|
615
|
-
case "local":
|
|
616
|
-
return detectFromLocal(sourceInfo);
|
|
617
|
-
default:
|
|
618
|
-
return { type: "skill", confidence: "low", reason: "Unknown source type" };
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
async function detectFromGitHub(info) {
|
|
622
|
-
const repoNameResult = detectFromRepoName(info.repo);
|
|
623
|
-
if (repoNameResult.confidence === "high") {
|
|
624
|
-
return repoNameResult;
|
|
625
|
-
}
|
|
626
|
-
try {
|
|
627
|
-
const packageJsonUrl = buildGitHubRawUrl(info, "package.json");
|
|
628
|
-
const response = await fetch(packageJsonUrl);
|
|
629
|
-
if (response.ok) {
|
|
630
|
-
const packageJson = await response.json();
|
|
631
|
-
const pkgResult = detectFromPackageJson(packageJson);
|
|
632
|
-
if (pkgResult.confidence !== "low") {
|
|
633
|
-
return pkgResult;
|
|
634
|
-
}
|
|
777
|
+
/**
|
|
778
|
+
* 加载索引
|
|
779
|
+
*/
|
|
780
|
+
loadIndex() {
|
|
781
|
+
const indexPath = path.join(this.postmortemDir, INDEX_FILE);
|
|
782
|
+
if (!fs.existsSync(indexPath)) {
|
|
783
|
+
return null;
|
|
635
784
|
}
|
|
636
|
-
} catch {
|
|
637
|
-
}
|
|
638
|
-
const filePatterns = [
|
|
639
|
-
{ file: "SKILL.md", type: "skill" },
|
|
640
|
-
{ file: "skill.md", type: "skill" },
|
|
641
|
-
{ file: "AGENT.md", type: "agent" },
|
|
642
|
-
{ file: "agent.md", type: "agent" },
|
|
643
|
-
{ file: "mcp.json", type: "mcp" },
|
|
644
|
-
{ file: "hook.json", type: "hook" }
|
|
645
|
-
];
|
|
646
|
-
for (const pattern of filePatterns) {
|
|
647
785
|
try {
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
if (response.ok) {
|
|
651
|
-
return {
|
|
652
|
-
type: pattern.type,
|
|
653
|
-
confidence: "high",
|
|
654
|
-
reason: `Found ${pattern.file}`
|
|
655
|
-
};
|
|
656
|
-
}
|
|
786
|
+
const content = fs.readFileSync(indexPath, "utf-8");
|
|
787
|
+
return JSON.parse(content);
|
|
657
788
|
} catch {
|
|
789
|
+
return null;
|
|
658
790
|
}
|
|
659
791
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
792
|
+
/**
|
|
793
|
+
* 保存索引
|
|
794
|
+
*/
|
|
795
|
+
saveIndex(index) {
|
|
796
|
+
const indexPath = path.join(this.postmortemDir, INDEX_FILE);
|
|
797
|
+
fs.writeFileSync(indexPath, JSON.stringify(index, null, 2), "utf-8");
|
|
666
798
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
799
|
+
/**
|
|
800
|
+
* 更新索引
|
|
801
|
+
*/
|
|
802
|
+
updateIndex() {
|
|
803
|
+
const index = this.createEmptyIndex();
|
|
804
|
+
const files = fs.readdirSync(this.postmortemDir).filter((f) => f.startsWith("PM-") && f.endsWith(".json"));
|
|
805
|
+
for (const file of files) {
|
|
806
|
+
try {
|
|
807
|
+
const content = fs.readFileSync(path.join(this.postmortemDir, file), "utf-8");
|
|
808
|
+
const report = JSON.parse(content);
|
|
809
|
+
index.stats.total++;
|
|
810
|
+
index.stats.bySeverity[report.severity]++;
|
|
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 {
|
|
679
823
|
}
|
|
680
824
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
return
|
|
825
|
+
index.reports.sort((a, b) => {
|
|
826
|
+
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
827
|
+
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
828
|
+
if (severityDiff !== 0)
|
|
829
|
+
return severityDiff;
|
|
830
|
+
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
|
|
831
|
+
});
|
|
832
|
+
index.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
833
|
+
this.saveIndex(index);
|
|
834
|
+
return index;
|
|
691
835
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
836
|
+
// ==========================================================================
|
|
837
|
+
// CLAUDE.md Integration
|
|
838
|
+
// ==========================================================================
|
|
839
|
+
/**
|
|
840
|
+
* 同步到 CLAUDE.md
|
|
841
|
+
*/
|
|
842
|
+
async syncToClaudeMd() {
|
|
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");
|
|
699
848
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
{ file: "skill.md", type: "skill" },
|
|
705
|
-
{ file: "AGENT.md", type: "agent" },
|
|
706
|
-
{ file: "agent.md", type: "agent" },
|
|
707
|
-
{ file: "mcp.json", type: "mcp" },
|
|
708
|
-
{ file: "hook.json", type: "hook" }
|
|
709
|
-
];
|
|
710
|
-
for (const pattern of filePatterns) {
|
|
711
|
-
try {
|
|
712
|
-
const filePath = path__default.join(absolutePath, pattern.file);
|
|
713
|
-
await fs.access(filePath);
|
|
714
|
-
return {
|
|
715
|
-
type: pattern.type,
|
|
716
|
-
confidence: "high",
|
|
717
|
-
reason: `Found ${pattern.file}`
|
|
718
|
-
};
|
|
719
|
-
} catch {
|
|
849
|
+
const startIndex = content.indexOf(CLAUDE_MD_SECTION_START);
|
|
850
|
+
const endIndex = content.indexOf(CLAUDE_MD_SECTION_END);
|
|
851
|
+
if (startIndex !== -1 && endIndex !== -1) {
|
|
852
|
+
content = content.substring(0, startIndex) + content.substring(endIndex + CLAUDE_MD_SECTION_END.length);
|
|
720
853
|
}
|
|
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
|
+
};
|
|
721
868
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
869
|
+
/**
|
|
870
|
+
* 生成 CLAUDE.md 注入内容
|
|
871
|
+
*/
|
|
872
|
+
generateClaudeMdInjection() {
|
|
873
|
+
const index = this.loadIndex();
|
|
874
|
+
const reports = [];
|
|
875
|
+
if (index) {
|
|
876
|
+
const severityOrder = {
|
|
877
|
+
critical: 0,
|
|
878
|
+
high: 1,
|
|
879
|
+
medium: 2,
|
|
880
|
+
low: 3
|
|
729
881
|
};
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
return { type: "agent", confidence: "medium", reason: `Name contains agent pattern: ${name}` };
|
|
742
|
-
}
|
|
743
|
-
if (lowerName.includes("hook") || lowerName.includes("-hook") || lowerName.endsWith("-hook")) {
|
|
744
|
-
return { type: "hook", confidence: "medium", reason: `Name contains hook pattern: ${name}` };
|
|
745
|
-
}
|
|
746
|
-
if (lowerName.includes("skill") || lowerName.includes("-skill") || lowerName.endsWith("-skill")) {
|
|
747
|
-
return { type: "skill", confidence: "medium", reason: `Name contains skill pattern: ${name}` };
|
|
748
|
-
}
|
|
749
|
-
return { type: "skill", confidence: "low", reason: "No pattern matched" };
|
|
750
|
-
}
|
|
751
|
-
function detectFromPackageName(packageName) {
|
|
752
|
-
const lowerName = packageName.toLowerCase();
|
|
753
|
-
if (lowerName.startsWith("@modelcontextprotocol/")) {
|
|
754
|
-
return { type: "mcp", confidence: "high", reason: "MCP official scope" };
|
|
755
|
-
}
|
|
756
|
-
if (lowerName.includes("mcp-server") || lowerName.includes("mcp_server")) {
|
|
757
|
-
return { type: "mcp", confidence: "high", reason: "MCP server pattern in name" };
|
|
758
|
-
}
|
|
759
|
-
return detectFromRepoName(packageName);
|
|
760
|
-
}
|
|
761
|
-
function detectFromPackageJson(packageJson) {
|
|
762
|
-
if (packageJson.ccjk && typeof packageJson.ccjk === "object") {
|
|
763
|
-
const ccjk = packageJson.ccjk;
|
|
764
|
-
if (ccjk.type && typeof ccjk.type === "string") {
|
|
765
|
-
const type = ccjk.type;
|
|
766
|
-
if (["skill", "mcp", "agent", "hook"].includes(type)) {
|
|
767
|
-
return { type, confidence: "high", reason: "Explicit ccjk.type field" };
|
|
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
|
+
}
|
|
768
893
|
}
|
|
769
894
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
"
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
"
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
895
|
+
const lines = [
|
|
896
|
+
"## \u26A0\uFE0F \u5DF2\u77E5\u95EE\u9898\u9884\u8B66 (Postmortem Intelligence)",
|
|
897
|
+
"",
|
|
898
|
+
"> \u57FA\u4E8E\u5386\u53F2 bug \u5206\u6790\u81EA\u52A8\u751F\u6210\uFF0C\u5E2E\u52A9\u907F\u514D\u91CD\u590D\u72AF\u9519",
|
|
899
|
+
""
|
|
900
|
+
];
|
|
901
|
+
if (reports.length === 0) {
|
|
902
|
+
lines.push("\u6682\u65E0\u9700\u8981\u5173\u6CE8\u7684\u95EE\u9898\u3002");
|
|
903
|
+
} else {
|
|
904
|
+
const critical = reports.filter((r) => r.severity === "critical");
|
|
905
|
+
const high = reports.filter((r) => r.severity === "high");
|
|
906
|
+
const medium = reports.filter((r) => r.severity === "medium");
|
|
907
|
+
if (critical.length > 0) {
|
|
908
|
+
lines.push("### \u{1F534} \u4E25\u91CD");
|
|
909
|
+
for (const r of critical) {
|
|
910
|
+
lines.push(`- **${r.id}**: ${r.title}`);
|
|
911
|
+
lines.push(` - ${r.aiDirectives[0] || r.preventionMeasures[0]}`);
|
|
912
|
+
}
|
|
913
|
+
lines.push("");
|
|
914
|
+
}
|
|
915
|
+
if (high.length > 0) {
|
|
916
|
+
lines.push("### \u{1F7E0} \u9AD8\u4F18\u5148\u7EA7");
|
|
917
|
+
for (const r of high) {
|
|
918
|
+
lines.push(`- **${r.id}**: ${r.title}`);
|
|
919
|
+
lines.push(` - ${r.aiDirectives[0] || r.preventionMeasures[0]}`);
|
|
920
|
+
}
|
|
921
|
+
lines.push("");
|
|
922
|
+
}
|
|
923
|
+
if (medium.length > 0) {
|
|
924
|
+
lines.push("### \u{1F7E1} \u4E2D\u4F18\u5148\u7EA7");
|
|
925
|
+
for (const r of medium) {
|
|
926
|
+
lines.push(`- **${r.id}**: ${r.title}`);
|
|
927
|
+
}
|
|
928
|
+
lines.push("");
|
|
929
|
+
}
|
|
930
|
+
lines.push("### \u{1F4CB} \u5F00\u53D1\u6307\u4EE4");
|
|
931
|
+
const allDirectives = /* @__PURE__ */ new Set();
|
|
932
|
+
for (const r of reports.slice(0, 5)) {
|
|
933
|
+
for (const d of r.aiDirectives.slice(0, 2)) {
|
|
934
|
+
allDirectives.add(d);
|
|
935
|
+
}
|
|
786
936
|
}
|
|
937
|
+
for (const d of allDirectives) {
|
|
938
|
+
lines.push(`- ${d}`);
|
|
939
|
+
}
|
|
940
|
+
lines.push("");
|
|
941
|
+
lines.push(`> \u8BE6\u7EC6\u4FE1\u606F\u8BF7\u67E5\u770B \`${this.config.directory}/\` \u76EE\u5F55`);
|
|
787
942
|
}
|
|
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
|
+
};
|
|
788
951
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
952
|
+
// ==========================================================================
|
|
953
|
+
// Code Checking
|
|
954
|
+
// ==========================================================================
|
|
955
|
+
/**
|
|
956
|
+
* 检查代码是否可能触发已知问题
|
|
957
|
+
*/
|
|
958
|
+
async checkCode(options = {}) {
|
|
959
|
+
const { files, staged } = options;
|
|
960
|
+
let filesToCheck = [];
|
|
961
|
+
if (files && files.length > 0) {
|
|
962
|
+
filesToCheck = files;
|
|
963
|
+
} else if (staged) {
|
|
964
|
+
filesToCheck = this.getStagedFiles();
|
|
965
|
+
} else {
|
|
966
|
+
filesToCheck = this.getAllSourceFiles();
|
|
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 });
|
|
794
982
|
}
|
|
795
983
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
984
|
+
for (const file of filesToCheck) {
|
|
985
|
+
const fullPath = path.isAbsolute(file) ? file : path.join(this.projectRoot, file);
|
|
986
|
+
if (!fs.existsSync(fullPath))
|
|
987
|
+
continue;
|
|
988
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
989
|
+
const lines = content.split("\n");
|
|
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
|
+
}
|
|
1015
|
+
}
|
|
801
1016
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
} catch (error) {
|
|
815
|
-
spinner?.fail(i18n.parseFailed);
|
|
816
|
-
const result = {
|
|
817
|
-
success: false,
|
|
818
|
-
source,
|
|
819
|
-
sourceType: "local",
|
|
820
|
-
pluginType: "skill",
|
|
821
|
-
error: error instanceof Error ? error.message : String(error)
|
|
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
|
|
822
1029
|
};
|
|
823
|
-
if (json) {
|
|
824
|
-
console.log(JSON.stringify(result, null, 2));
|
|
825
|
-
} else {
|
|
826
|
-
console.error(a.red(`
|
|
827
|
-
${i18n.error}: ${result.error}
|
|
828
|
-
`));
|
|
829
|
-
}
|
|
830
|
-
return result;
|
|
831
1030
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1031
|
+
/**
|
|
1032
|
+
* 获取暂存的文件
|
|
1033
|
+
*/
|
|
1034
|
+
getStagedFiles() {
|
|
835
1035
|
try {
|
|
836
|
-
|
|
837
|
-
|
|
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);
|
|
838
1041
|
} catch {
|
|
839
|
-
|
|
840
|
-
pluginType = "skill";
|
|
1042
|
+
return [];
|
|
841
1043
|
}
|
|
842
1044
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1045
|
+
/**
|
|
1046
|
+
* 获取所有源文件
|
|
1047
|
+
*/
|
|
1048
|
+
getAllSourceFiles() {
|
|
1049
|
+
const files = [];
|
|
1050
|
+
const walk = (dir) => {
|
|
1051
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
1052
|
+
for (const entry of entries) {
|
|
1053
|
+
const fullPath = path.join(dir, entry.name);
|
|
1054
|
+
const relativePath = path.relative(this.projectRoot, fullPath);
|
|
1055
|
+
if (this.config.detection.excludePatterns.some((p) => this.matchGlob(relativePath, p))) {
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (entry.isDirectory()) {
|
|
1059
|
+
walk(fullPath);
|
|
1060
|
+
} else if (entry.isFile()) {
|
|
1061
|
+
if (this.config.detection.includePatterns.some((p) => this.matchGlob(relativePath, p))) {
|
|
1062
|
+
files.push(relativePath);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
walk(this.projectRoot);
|
|
1068
|
+
return files;
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* 简单的 glob 匹配
|
|
1072
|
+
*/
|
|
1073
|
+
matchGlob(filepath, pattern) {
|
|
1074
|
+
const regexPattern = pattern.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\?/g, ".");
|
|
1075
|
+
return new RegExp(`^${regexPattern}$`).test(filepath);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* 创建空的检查报告
|
|
1079
|
+
*/
|
|
1080
|
+
createEmptyCheckReport(filesChecked) {
|
|
1081
|
+
return {
|
|
1082
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1083
|
+
filesChecked,
|
|
1084
|
+
issuesFound: [],
|
|
1085
|
+
summary: { critical: 0, high: 0, medium: 0, low: 0 },
|
|
1086
|
+
passed: true
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
// ==========================================================================
|
|
1090
|
+
// Release Summary
|
|
1091
|
+
// ==========================================================================
|
|
1092
|
+
/**
|
|
1093
|
+
* 生成发布摘要
|
|
1094
|
+
*/
|
|
1095
|
+
async generateReleaseSummary(options) {
|
|
1096
|
+
const { version, since, until } = options;
|
|
1097
|
+
const commits = PostmortemAnalyzer.getFixCommits({
|
|
1098
|
+
since,
|
|
1099
|
+
until,
|
|
1100
|
+
cwd: this.projectRoot
|
|
1101
|
+
});
|
|
1102
|
+
const analyses = commits.map(
|
|
1103
|
+
(c) => PostmortemAnalyzer.analyzeFixCommit(c, this.projectRoot)
|
|
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);
|
|
874
1112
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1113
|
+
this.updateIndex();
|
|
1114
|
+
const summary = {
|
|
1115
|
+
version,
|
|
1116
|
+
releaseDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1117
|
+
fixCommitCount: commits.length,
|
|
1118
|
+
newPostmortems: newIds,
|
|
1119
|
+
updatedPostmortems: [],
|
|
1120
|
+
summary: this.generateReleaseSummaryText(commits, newReports),
|
|
1121
|
+
keyLessons: this.extractKeyLessons(newReports)
|
|
884
1122
|
};
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
${i18n.error}: ${result.error}
|
|
890
|
-
`));
|
|
1123
|
+
const summaryPath = path.join(this.postmortemDir, "summaries", `${version}.json`);
|
|
1124
|
+
fs.writeFileSync(summaryPath, JSON.stringify(summary, null, 2), "utf-8");
|
|
1125
|
+
if (this.config.autoSyncToClaudeMd) {
|
|
1126
|
+
await this.syncToClaudeMd();
|
|
891
1127
|
}
|
|
892
|
-
return
|
|
1128
|
+
return summary;
|
|
893
1129
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
case "mcp":
|
|
912
|
-
console.log(` ${a.gray("\u2022")} ${i18n.mcpHint}`);
|
|
913
|
-
break;
|
|
914
|
-
case "agent":
|
|
915
|
-
console.log(` ${a.gray("\u2022")} ${i18n.agentHint}`);
|
|
916
|
-
break;
|
|
917
|
-
case "hook":
|
|
918
|
-
console.log(` ${a.gray("\u2022")} ${i18n.hookHint}`);
|
|
919
|
-
break;
|
|
920
|
-
}
|
|
921
|
-
console.log();
|
|
922
|
-
}
|
|
923
|
-
function printPreviewMessage(result, i18n) {
|
|
924
|
-
console.log();
|
|
925
|
-
console.log(a.yellow.bold(`\u26A1 ${i18n.preview}`));
|
|
926
|
-
console.log();
|
|
927
|
-
console.log(` ${a.gray(i18n.source)}: ${result.source}`);
|
|
928
|
-
console.log(` ${a.gray(i18n.type)}: ${result.pluginType}`);
|
|
929
|
-
console.log(` ${a.gray(i18n.target)}: ${result.installedPath}`);
|
|
930
|
-
if (result.details?.files?.length) {
|
|
931
|
-
console.log(` ${a.gray(i18n.files)}:`);
|
|
932
|
-
for (const file of result.details.files.slice(0, 5)) {
|
|
933
|
-
console.log(` ${a.gray("\u2022")} ${file}`);
|
|
1130
|
+
/**
|
|
1131
|
+
* 生成发布摘要文本
|
|
1132
|
+
*/
|
|
1133
|
+
generateReleaseSummaryText(commits, reports) {
|
|
1134
|
+
const lines = [
|
|
1135
|
+
`\u672C\u6B21\u53D1\u5E03\u5305\u542B ${commits.length} \u4E2A bug \u4FEE\u590D\uFF0C\u751F\u6210\u4E86 ${reports.length} \u4E2A\u65B0\u7684 Postmortem \u62A5\u544A\u3002`,
|
|
1136
|
+
""
|
|
1137
|
+
];
|
|
1138
|
+
if (reports.length > 0) {
|
|
1139
|
+
lines.push("\u4E3B\u8981\u95EE\u9898\u7C7B\u578B:");
|
|
1140
|
+
const categories = /* @__PURE__ */ new Map();
|
|
1141
|
+
for (const r of reports) {
|
|
1142
|
+
categories.set(r.category, (categories.get(r.category) || 0) + 1);
|
|
1143
|
+
}
|
|
1144
|
+
for (const [cat, count] of categories) {
|
|
1145
|
+
lines.push(`- ${cat}: ${count} \u4E2A`);
|
|
1146
|
+
}
|
|
934
1147
|
}
|
|
935
|
-
|
|
936
|
-
|
|
1148
|
+
return lines.join("\n");
|
|
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
|
+
}
|
|
937
1159
|
}
|
|
1160
|
+
return Array.from(lessons).slice(0, 10);
|
|
938
1161
|
}
|
|
939
|
-
console.log();
|
|
940
|
-
console.log(a.gray(i18n.dryRunNote));
|
|
941
|
-
console.log();
|
|
942
1162
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
detectingType: "\u68C0\u6D4B\u63D2\u4EF6\u7C7B\u578B...",
|
|
950
|
-
detectedType: (type) => `\u68C0\u6D4B\u5230\u7C7B\u578B: ${type}`,
|
|
951
|
-
defaultType: "\u4F7F\u7528\u9ED8\u8BA4\u7C7B\u578B: skill",
|
|
952
|
-
installing: "\u5B89\u88C5\u4E2D...",
|
|
953
|
-
previewInstall: "\u9884\u89C8\u5B89\u88C5...",
|
|
954
|
-
installSuccess: "\u5B89\u88C5\u6210\u529F",
|
|
955
|
-
previewSuccess: "\u9884\u89C8\u5B8C\u6210",
|
|
956
|
-
installFailed: "\u5B89\u88C5\u5931\u8D25",
|
|
957
|
-
error: "\u9519\u8BEF",
|
|
958
|
-
installed: "\u63D2\u4EF6\u5DF2\u5B89\u88C5",
|
|
959
|
-
preview: "\u5B89\u88C5\u9884\u89C8 (dry-run)",
|
|
960
|
-
name: "\u540D\u79F0",
|
|
961
|
-
version: "\u7248\u672C",
|
|
962
|
-
type: "\u7C7B\u578B",
|
|
963
|
-
path: "\u8DEF\u5F84",
|
|
964
|
-
source: "\u6765\u6E90",
|
|
965
|
-
target: "\u76EE\u6807",
|
|
966
|
-
files: "\u6587\u4EF6",
|
|
967
|
-
nextSteps: "\u4E0B\u4E00\u6B65:",
|
|
968
|
-
skillHint: "\u4F7F\u7528 /skill-name \u5728 Claude Code \u4E2D\u8C03\u7528",
|
|
969
|
-
mcpHint: "\u8FD0\u884C ccjk mcp status \u67E5\u770B\u72B6\u6001",
|
|
970
|
-
agentHint: "\u4F7F\u7528 ccjk agent list \u67E5\u770B\u5DF2\u5B89\u88C5\u7684 agent",
|
|
971
|
-
hookHint: "\u8FD0\u884C ccjk hooks list \u67E5\u770B\u5DF2\u5B89\u88C5\u7684 hook",
|
|
972
|
-
dryRunNote: "\u8FD9\u662F\u9884\u89C8\u6A21\u5F0F\uFF0C\u672A\u5B9E\u9645\u5B89\u88C5\u3002\u79FB\u9664 --dry-run \u6267\u884C\u5B89\u88C5\u3002",
|
|
973
|
-
andMore: (n) => `\u8FD8\u6709 ${n} \u4E2A\u6587\u4EF6`
|
|
974
|
-
},
|
|
975
|
-
"en": {
|
|
976
|
-
parsing: "Parsing source...",
|
|
977
|
-
parsed: (type) => `Source type: ${type}`,
|
|
978
|
-
parseFailed: "Failed to parse source",
|
|
979
|
-
detectingType: "Detecting plugin type...",
|
|
980
|
-
detectedType: (type) => `Detected type: ${type}`,
|
|
981
|
-
defaultType: "Using default type: skill",
|
|
982
|
-
installing: "Installing...",
|
|
983
|
-
previewInstall: "Previewing installation...",
|
|
984
|
-
installSuccess: "Installation successful",
|
|
985
|
-
previewSuccess: "Preview complete",
|
|
986
|
-
installFailed: "Installation failed",
|
|
987
|
-
error: "Error",
|
|
988
|
-
installed: "Plugin installed",
|
|
989
|
-
preview: "Installation preview (dry-run)",
|
|
990
|
-
name: "Name",
|
|
991
|
-
version: "Version",
|
|
992
|
-
type: "Type",
|
|
993
|
-
path: "Path",
|
|
994
|
-
source: "Source",
|
|
995
|
-
target: "Target",
|
|
996
|
-
files: "Files",
|
|
997
|
-
nextSteps: "Next steps:",
|
|
998
|
-
skillHint: "Use /skill-name in Claude Code to invoke",
|
|
999
|
-
mcpHint: "Run ccjk mcp status to check status",
|
|
1000
|
-
agentHint: "Use ccjk agent list to see installed agents",
|
|
1001
|
-
hookHint: "Run ccjk hooks list to see installed hooks",
|
|
1002
|
-
dryRunNote: "This is preview mode, nothing was installed. Remove --dry-run to install.",
|
|
1003
|
-
andMore: (n) => `and ${n} more files`
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
return texts[lang];
|
|
1163
|
+
let managerInstance = null;
|
|
1164
|
+
function getPostmortemManager(projectRoot, config) {
|
|
1165
|
+
if (!managerInstance || projectRoot) {
|
|
1166
|
+
managerInstance = new PostmortemManager(projectRoot, config);
|
|
1167
|
+
}
|
|
1168
|
+
return managerInstance;
|
|
1007
1169
|
}
|
|
1008
1170
|
|
|
1009
|
-
export {
|
|
1171
|
+
export { PostmortemAnalyzer, PostmortemManager, getPostmortemManager };
|