claude-everything-workflow 0.2.11 → 0.2.12
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/.claude-plugin/hooks.json +1 -6
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/docs/plugins.md +3 -2
- package/evals/routing-scenarios.json +9 -0
- package/hooks/check-code-size.js +4 -126
- package/hooks/check-console-log.js +4 -79
- package/hooks/check-edited-file.js +139 -0
- package/hooks/commit-quality.js +1029 -72
- package/hooks/runtime/antigravity-pre-tool.js +116 -0
- package/package.json +4 -2
- package/rules/02-implementation.md +1 -1
- package/rules/common/hooks.md +2 -2
- package/scripts/cleanup-retired-skills.js +36 -3
- package/scripts/install-antigravity.js +63 -19
- package/scripts/install-rules.js +27 -7
- package/scripts/install.ps1 +21 -24
- package/scripts/install.sh +2 -1
- package/scripts/merge-claude-settings.cjs +14 -2
- package/scripts/retired-skill-files.json +12 -0
- package/scripts/verify/commit-quality.test.js +481 -0
- package/scripts/verify/install-rules.test.js +212 -5
- package/scripts/verify/metadata-checks.js +4 -1
- package/scripts/verify/runtime-checks.js +57 -2
- package/scripts/verify/workflow-checks.js +5 -1
- package/settings.json +1 -6
- package/skills/systematic-debugging/SKILL.md +7 -4
- package/skills/systematic-debugging/references/diagnostic-scenarios.md +7 -0
- package/agents/harness-optimizer.md +0 -93
|
@@ -6,12 +6,7 @@
|
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/runtime/run-with-flags.js\" post:edit:
|
|
10
|
-
"timeout": 5
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"type": "command",
|
|
14
|
-
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/runtime/run-with-flags.js\" post:edit:code-size hooks/check-code-size.js standard,strict",
|
|
9
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/runtime/run-with-flags.js\" post:edit:quality hooks/check-edited-file.js standard,strict",
|
|
15
10
|
"timeout": 5
|
|
16
11
|
}
|
|
17
12
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-everything-workflow",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Evidence-based engineering workflows: implement, debug, review and verify.",
|
|
5
5
|
"author": { "name": "xu91102" },
|
|
6
6
|
"homepage": "https://github.com/xu91102/claude-everything-Workflow",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-everything-workflow",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Evidence-based engineering workflows: implement, debug, review and verify.",
|
|
5
5
|
"author": { "name": "xu91102" },
|
|
6
6
|
"homepage": "https://github.com/xu91102/claude-everything-Workflow",
|
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ The CLI selects the shell or PowerShell installer for your platform. The same `-
|
|
|
69
69
|
| --- | --- | --- |
|
|
70
70
|
| Claude Code | `~/.claude/` | Shared workflow files, `CLAUDE.md` bootstrap, rules, and merged hook settings. |
|
|
71
71
|
| Codex | `~/.codex/` | Shared workflow files and `AGENTS.md`; Claude Code hooks are not automatically enabled. |
|
|
72
|
-
| Antigravity (Gemini) | `~/.gemini/config/plugins/claude-everything-workflow/` | Native plugin (`plugin.json`, `rules/AGENTS.md`, on-demand `references/rules/`, converted `skills/` and `agents/`, `scripts/learning/`). |
|
|
72
|
+
| Antigravity (Gemini) | `~/.gemini/config/plugins/claude-everything-workflow/` | Native plugin (`plugin.json`, `hooks.json` & `hooks/`, `rules/AGENTS.md`, on-demand `references/rules/`, converted `skills/` and `agents/`, `scripts/learning/`). |
|
|
73
73
|
|
|
74
74
|
Installation updates user-level files and can affect multiple projects. Changed top-level configuration files are backed up; matching files inside shared directories are synchronized from the repository. Unknown files are generally retained, while known retired files are removed by an explicit cleanup list. Back up any personal edits to shared files before upgrading. Use the installer instead of copying the entire `rules/` directory: it handles the different rule locations used by each host.
|
|
75
75
|
|
package/README.zh-CN.md
CHANGED
|
@@ -69,7 +69,7 @@ node bin/claude-everything-workflow.js install
|
|
|
69
69
|
| --- | --- | --- |
|
|
70
70
|
| Claude Code | `~/.claude/` | 共享工作流文件、`CLAUDE.md` 入口、规则,以及合并后的 hooks 配置。 |
|
|
71
71
|
| Codex | `~/.codex/` | 共享工作流文件和 `AGENTS.md`;不会自动启用 Claude Code hooks。 |
|
|
72
|
-
| Antigravity (Gemini) | `~/.gemini/config/plugins/claude-everything-workflow/` | 原生插件(`plugin.json`、`rules/AGENTS.md`、按需加载的 `references/rules/`、转换后的 `skills/` 与 `agents/`、`scripts/learning/`)。 |
|
|
72
|
+
| Antigravity (Gemini) | `~/.gemini/config/plugins/claude-everything-workflow/` | 原生插件(`plugin.json`、`hooks.json` 与 `hooks/`、`rules/AGENTS.md`、按需加载的 `references/rules/`、转换后的 `skills/` 与 `agents/`、`scripts/learning/`)。 |
|
|
73
73
|
|
|
74
74
|
安装修改的是用户级目录,可能影响多个项目。顶层配置内容不同时会先备份;共享目录中的同名文件按仓库版本同步。未知文件通常保留,已登记的退役文件按明确清单清理。升级前请备份对共享文件的个人修改。不要直接复制整个 `rules/` 目录,安装器会处理不同宿主各自的规则加载位置。
|
|
75
75
|
|
package/docs/plugins.md
CHANGED
|
@@ -66,12 +66,13 @@ npx claude-everything-workflow install --antigravity-only
|
|
|
66
66
|
或者运行 `npx claude-everything-workflow install`(当本机已存在非符号链接的 `~/.gemini` 时会自动同步 Antigravity;未存在时跳过,可随时用 `--antigravity-only` 显式安装)。安装器会自动生成或同步:
|
|
67
67
|
|
|
68
68
|
- `plugin.json`:原生插件清单(版本与 `package.json` 保持一致)。
|
|
69
|
+
- `hooks.json` & `hooks/`:注册 Antigravity 原生 `PreToolUse`(`run_command`)提交密钥与质量拦截钩子,沿用 `ECC_HOOK_PROFILE`、`ECC_DISABLED_HOOKS` 控制;不自动启用 Claude Code 专用编辑/观察 hooks。
|
|
69
70
|
- `rules/AGENTS.md`:唯一的常驻入口规则,指引按需读取 `references/rules/` 下的基础规则与 `common/` 专项规则。
|
|
70
|
-
- `skills/`:同步全部工作流技能,并把非重复命令(`pr`、`verify`、`to-spec`、`learn
|
|
71
|
+
- `skills/`:同步全部工作流技能,并把非重复命令(`pr`、`verify`、`to-spec`、`learn`)转换为原生技能,同时把内部 `commands/` 引用改写为插件内技能路径;自动清理已退役技能。
|
|
71
72
|
- `agents/`:转换工具名称与插件内引用路径为 Antigravity 原生子代理格式。
|
|
72
73
|
- `references/rules/02-implementation.md`:采用与 Codex 相同的 Git 三方合并机制,升级时保留个人修改。
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
若本机存在旧版 `~/.gemini/AGENTS.md`,安装器不会自动删除,仅在输出中提示手动确认。
|
|
75
76
|
|
|
76
77
|
### 浏览器验证 MCP
|
|
77
78
|
|
|
@@ -121,6 +121,15 @@
|
|
|
121
121
|
"requiredSignals": ["flaky", "根因"],
|
|
122
122
|
"rationale": "先定位间歇性超时的根因。根因确认后,需要维护或稳定浏览器测试时再使用验收 Skill 的 E2E 参考。"
|
|
123
123
|
},
|
|
124
|
+
{
|
|
125
|
+
"id": "debugging-third-round-recurrence",
|
|
126
|
+
"category": "debugging",
|
|
127
|
+
"prompt": "这个导入路径问题前两轮修复单测都过了,第三轮复审又在重试队列复现,帮我重查原因",
|
|
128
|
+
"expectedTarget": "skills/systematic-debugging/SKILL.md",
|
|
129
|
+
"expectedLane": "debugging",
|
|
130
|
+
"requiredSignals": ["复发", "证据闭环"],
|
|
131
|
+
"rationale": "同类问题在多轮修复或复审中复发应进入 systematic-debugging 证据闭环,重新检验共同假设而不是继续追加局部补丁。"
|
|
132
|
+
},
|
|
124
133
|
{
|
|
125
134
|
"id": "grilling-ambiguous-decision",
|
|
126
135
|
"category": "decision",
|
package/hooks/check-code-size.js
CHANGED
|
@@ -1,132 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Check Code Size Hook
|
|
4
|
-
*
|
|
5
|
-
* 编辑后只检查本次改动的代码文件:文件行数上限与单行长度。
|
|
6
|
-
* 正常静默,避免增加上下文噪音。对应 rules/02-implementation.md。
|
|
3
|
+
* Check Code Size Hook(兼容入口,实现已并入 hooks/check-edited-file.js)
|
|
7
4
|
*/
|
|
8
|
-
|
|
9
5
|
'use strict'
|
|
10
6
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const CODE_TARGET_LINES = 800
|
|
14
|
-
const TEST_MAX_LINES = 1000
|
|
15
|
-
const MAX_LINE_LENGTH = 120
|
|
16
|
-
const CODE_EXTENSIONS = new Set([
|
|
17
|
-
'.c',
|
|
18
|
-
'.cc',
|
|
19
|
-
'.cpp',
|
|
20
|
-
'.cs',
|
|
21
|
-
'.css',
|
|
22
|
-
'.go',
|
|
23
|
-
'.h',
|
|
24
|
-
'.hpp',
|
|
25
|
-
'.html',
|
|
26
|
-
'.java',
|
|
27
|
-
'.js',
|
|
28
|
-
'.jsx',
|
|
29
|
-
'.kt',
|
|
30
|
-
'.lua',
|
|
31
|
-
'.mjs',
|
|
32
|
-
'.php',
|
|
33
|
-
'.py',
|
|
34
|
-
'.rb',
|
|
35
|
-
'.rs',
|
|
36
|
-
'.sh',
|
|
37
|
-
'.swift',
|
|
38
|
-
'.ts',
|
|
39
|
-
'.tsx',
|
|
40
|
-
'.vue'
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
function getExtension(filePath) {
|
|
44
|
-
const match = filePath.match(/(\.[^.\\/]+)$/)
|
|
45
|
-
return match ? match[1].toLowerCase() : ''
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isCodeFile(filePath) {
|
|
49
|
-
return CODE_EXTENSIONS.has(getExtension(filePath))
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isTestFile(filePath) {
|
|
53
|
-
return /(^|[\\/])__tests__([\\/]|$)/.test(filePath) ||
|
|
54
|
-
/\.(test|spec)\.[^.\\/]+$/.test(filePath)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function getLineThreshold(filePath) {
|
|
58
|
-
return isTestFile(filePath) ? TEST_MAX_LINES : CODE_TARGET_LINES
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function countLines(content) {
|
|
62
|
-
if (content.length === 0) return 0
|
|
63
|
-
const lines = content.split(/\r?\n/)
|
|
64
|
-
return content.endsWith('\n') ? lines.length - 1 : lines.length
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function run(raw) {
|
|
68
|
-
let input
|
|
69
|
-
try {
|
|
70
|
-
input = JSON.parse(raw)
|
|
71
|
-
} catch {
|
|
72
|
-
return { exitCode: 0 }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const filePath = input.tool_input?.file_path
|
|
76
|
-
if (!filePath || !isCodeFile(filePath) || !fs.existsSync(filePath)) {
|
|
77
|
-
return { exitCode: 0 }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let content
|
|
81
|
-
try {
|
|
82
|
-
content = fs.readFileSync(filePath, 'utf8')
|
|
83
|
-
} catch {
|
|
84
|
-
return { exitCode: 0 }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const testFile = isTestFile(filePath)
|
|
88
|
-
const lineThreshold = getLineThreshold(filePath)
|
|
89
|
-
const lineCount = countLines(content)
|
|
90
|
-
|
|
91
|
-
const messages = []
|
|
92
|
-
if (lineCount > lineThreshold) {
|
|
93
|
-
messages.push(
|
|
94
|
-
testFile
|
|
95
|
-
? `测试文件超过 ${lineThreshold} 行上限 (${lineCount} 行),请拆分测试场景。`
|
|
96
|
-
: `代码文件超过约 ${lineThreshold} 行的参考值 (${lineCount} 行),请评估是否按职责拆分。`
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 最多提示前 3 处超长行
|
|
101
|
-
const longLineNumbers = []
|
|
102
|
-
content.split(/\r?\n/).forEach((line, index) => {
|
|
103
|
-
if (line.length > MAX_LINE_LENGTH && longLineNumbers.length < 3) {
|
|
104
|
-
longLineNumbers.push(index + 1)
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
if (longLineNumbers.length > 0) {
|
|
108
|
-
messages.push(
|
|
109
|
-
`存在超过 ${MAX_LINE_LENGTH} 字符的行(如第 ${longLineNumbers.join('、')} 行),请换行或提取。`
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (messages.length === 0) {
|
|
114
|
-
return { exitCode: 0 }
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return { exitCode: 0, stderr: `[Hook] ${filePath}: ${messages.join(' ')}\n` }
|
|
118
|
-
}
|
|
119
|
-
|
|
7
|
+
const { checkEditedFile, runCli } = require('./check-edited-file')
|
|
8
|
+
const run = raw => checkEditedFile(raw, false, true)
|
|
120
9
|
module.exports = { run }
|
|
121
|
-
|
|
122
|
-
if (require.main === module) {
|
|
123
|
-
let data = ''
|
|
124
|
-
process.stdin.setEncoding('utf8')
|
|
125
|
-
process.stdin.on('data', chunk => { data += chunk })
|
|
126
|
-
process.stdin.on('end', () => {
|
|
127
|
-
const result = run(data)
|
|
128
|
-
if (result.stderr) process.stderr.write(result.stderr)
|
|
129
|
-
if (result.stdout) process.stdout.write(result.stdout)
|
|
130
|
-
process.exit(result.exitCode || 0)
|
|
131
|
-
})
|
|
132
|
-
}
|
|
10
|
+
if (require.main === module) runCli(run)
|
|
@@ -1,85 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Check Forbidden Patterns Hook
|
|
4
|
-
*
|
|
5
|
-
* 在代码编辑后检测静态禁止模式:console.log、debugger,
|
|
6
|
-
* 以及 TypeScript 文件中的 @ts-ignore、@ts-nocheck、`: any`、`as any`。
|
|
7
|
-
* 对应 rules/02-implementation.md 的代码与安全禁止项;文档文件不受检查。
|
|
8
|
-
* 用于 PostToolUse hook,警告不阻塞。
|
|
3
|
+
* Check Forbidden Patterns Hook(兼容入口,实现已并入 hooks/check-edited-file.js)
|
|
9
4
|
*/
|
|
10
|
-
|
|
11
5
|
'use strict'
|
|
12
6
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const TS_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts'])
|
|
16
|
-
|
|
17
|
-
function getExtension(filePath) {
|
|
18
|
-
const match = filePath.match(/(\.[^.\\/]+)$/)
|
|
19
|
-
return match ? match[1].toLowerCase() : ''
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const FORBIDDEN_PATTERNS = [
|
|
23
|
-
{ label: 'console.log 调试残留', pattern: /\bconsole\.log\s*\(/ },
|
|
24
|
-
{ label: 'debugger 调试残留', pattern: /^\s*debugger\b/m },
|
|
25
|
-
{ label: '@ts-ignore', pattern: /@ts-ignore/ },
|
|
26
|
-
{ label: '@ts-nocheck', pattern: /@ts-nocheck/ },
|
|
27
|
-
{ label: 'any 类型(: any)', pattern: /:\s*any\b/ },
|
|
28
|
-
{ label: 'any 断言(as any)', pattern: /\bas\s+any\b/ }
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
function run(raw) {
|
|
32
|
-
let input
|
|
33
|
-
try {
|
|
34
|
-
input = JSON.parse(raw)
|
|
35
|
-
} catch {
|
|
36
|
-
return { exitCode: 0 }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const filePath = input.tool_input?.file_path
|
|
40
|
-
if (!filePath || !fs.existsSync(filePath)) {
|
|
41
|
-
return { exitCode: 0 }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const ext = getExtension(filePath)
|
|
45
|
-
const isCode = Boolean(ext) && !/^\.(md|json|txt)$/.test(ext)
|
|
46
|
-
const isTs = TS_EXTENSIONS.has(ext)
|
|
47
|
-
if (!isCode) {
|
|
48
|
-
return { exitCode: 0 }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let content
|
|
52
|
-
try {
|
|
53
|
-
content = fs.readFileSync(filePath, 'utf8')
|
|
54
|
-
} catch {
|
|
55
|
-
return { exitCode: 0 }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const hits = []
|
|
59
|
-
for (const rule of FORBIDDEN_PATTERNS) {
|
|
60
|
-
if (rule.label.includes('any') && !isTs) continue
|
|
61
|
-
if (rule.pattern.test(content)) hits.push(rule.label)
|
|
62
|
-
}
|
|
63
|
-
if (hits.length === 0) {
|
|
64
|
-
return { exitCode: 0 }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
exitCode: 0,
|
|
69
|
-
stderr: `[Hook] 警告: ${filePath} 含禁止模式: ${hits.join('、')},请按 rules/02-implementation.md 处理\n`
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
7
|
+
const { checkEditedFile, runCli } = require('./check-edited-file')
|
|
8
|
+
const run = raw => checkEditedFile(raw, true, false)
|
|
73
9
|
module.exports = { run }
|
|
74
|
-
|
|
75
|
-
if (require.main === module) {
|
|
76
|
-
let data = ''
|
|
77
|
-
process.stdin.setEncoding('utf8')
|
|
78
|
-
process.stdin.on('data', chunk => { data += chunk })
|
|
79
|
-
process.stdin.on('end', () => {
|
|
80
|
-
const result = run(data)
|
|
81
|
-
if (result.stderr) process.stderr.write(result.stderr)
|
|
82
|
-
if (result.stdout) process.stdout.write(result.stdout)
|
|
83
|
-
process.exit(result.exitCode || 0)
|
|
84
|
-
})
|
|
85
|
-
}
|
|
10
|
+
if (require.main === module) runCli(run)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const { isHookEnabled } = require('./runtime/hook-flags')
|
|
6
|
+
|
|
7
|
+
const CODE_TARGET_LINES = 800
|
|
8
|
+
const TEST_MAX_LINES = 1000
|
|
9
|
+
const MAX_LINE_LENGTH = 120
|
|
10
|
+
const MAX_STDIN_BYTES = 1024 * 1024
|
|
11
|
+
const CODE_EXTENSIONS = new Set([
|
|
12
|
+
'.c', '.cc', '.cpp', '.cs', '.css', '.go', '.h', '.hpp',
|
|
13
|
+
'.html', '.java', '.js', '.jsx', '.kt', '.lua', '.mjs', '.php',
|
|
14
|
+
'.py', '.rb', '.rs', '.sh', '.swift', '.ts', '.tsx', '.vue'
|
|
15
|
+
])
|
|
16
|
+
const TS_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts'])
|
|
17
|
+
const FORBIDDEN_PATTERNS = [
|
|
18
|
+
{ label: 'console.log 调试残留', pattern: /\bconsole\.log\s*\(/ },
|
|
19
|
+
{ label: 'debugger 调试残留', pattern: /^\s*debugger\b/m },
|
|
20
|
+
{ label: '@ts-ignore', pattern: /@ts-ignore/ },
|
|
21
|
+
{ label: '@ts-nocheck', pattern: /@ts-nocheck/ },
|
|
22
|
+
{ label: 'any 类型(: any)', pattern: /:\s*any\b/ },
|
|
23
|
+
{ label: 'any 断言(as any)', pattern: /\bas\s+any\b/ }
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
function getExtension(filePath) {
|
|
27
|
+
const match = filePath.match(/(\.[^.\\/]+)$/)
|
|
28
|
+
return match ? match[1].toLowerCase() : ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isTestFile(filePath) {
|
|
32
|
+
return /(^|[\\/])__tests__([\\/]|$)/.test(filePath) ||
|
|
33
|
+
/\.(test|spec)\.[^.\\/]+$/.test(filePath)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function countLines(content) {
|
|
37
|
+
if (content.length === 0) return 0
|
|
38
|
+
const lines = content.split(/\r?\n/)
|
|
39
|
+
return content.endsWith('\n') ? lines.length - 1 : lines.length
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sizeWarnings(filePath, content) {
|
|
43
|
+
const testFile = isTestFile(filePath)
|
|
44
|
+
const lineThreshold = testFile ? TEST_MAX_LINES : CODE_TARGET_LINES
|
|
45
|
+
const lineCount = countLines(content)
|
|
46
|
+
const messages = []
|
|
47
|
+
|
|
48
|
+
if (lineCount > lineThreshold) {
|
|
49
|
+
messages.push(
|
|
50
|
+
testFile
|
|
51
|
+
? `测试文件超过 ${lineThreshold} 行上限 (${lineCount} 行),请拆分测试场景。`
|
|
52
|
+
: `代码文件超过约 ${lineThreshold} 行的参考值 (${lineCount} 行),请评估是否按职责拆分。`
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const longLineNumbers = []
|
|
57
|
+
content.split(/\r?\n/).forEach((line, index) => {
|
|
58
|
+
if (line.length > MAX_LINE_LENGTH && longLineNumbers.length < 3) {
|
|
59
|
+
longLineNumbers.push(index + 1)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
if (longLineNumbers.length > 0) {
|
|
63
|
+
messages.push(
|
|
64
|
+
`存在超过 ${MAX_LINE_LENGTH} 字符的行(如第 ${longLineNumbers.join('、')} 行),请换行或提取。`
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return messages
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function checkEditedFile(raw, patterns, size) {
|
|
72
|
+
let filePath
|
|
73
|
+
try {
|
|
74
|
+
filePath = JSON.parse(raw)?.tool_input?.file_path
|
|
75
|
+
} catch {
|
|
76
|
+
return { exitCode: 0 }
|
|
77
|
+
}
|
|
78
|
+
if (typeof filePath !== 'string') return { exitCode: 0 }
|
|
79
|
+
|
|
80
|
+
const ext = getExtension(filePath)
|
|
81
|
+
const checkPatterns = patterns && ext && !/^\.(md|json|txt)$/.test(ext)
|
|
82
|
+
const checkSize = size && CODE_EXTENSIONS.has(ext)
|
|
83
|
+
if (!checkPatterns && !checkSize) return { exitCode: 0 }
|
|
84
|
+
|
|
85
|
+
let content
|
|
86
|
+
try {
|
|
87
|
+
content = fs.readFileSync(filePath, 'utf8')
|
|
88
|
+
} catch {
|
|
89
|
+
return { exitCode: 0 }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const warnings = []
|
|
93
|
+
if (checkPatterns) {
|
|
94
|
+
const hits = FORBIDDEN_PATTERNS
|
|
95
|
+
.filter(rule => (!rule.label.includes('any') || TS_EXTENSIONS.has(ext)) && rule.pattern.test(content))
|
|
96
|
+
.map(rule => rule.label)
|
|
97
|
+
if (hits.length) {
|
|
98
|
+
warnings.push(
|
|
99
|
+
`[Hook] 警告: ${filePath} 含禁止模式: ${hits.join('、')},请按 rules/02-implementation.md 处理`
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (checkSize) {
|
|
104
|
+
const messages = sizeWarnings(filePath, content)
|
|
105
|
+
if (messages.length) warnings.push(`[Hook] ${filePath}: ${messages.join(' ')}`)
|
|
106
|
+
}
|
|
107
|
+
return warnings.length ? { exitCode: 0, stderr: warnings.join('\n') + '\n' } : { exitCode: 0 }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isSubHookEnabled(hookId) {
|
|
111
|
+
// Allow ECC_DISABLED_HOOKS per sub-check without overriding the profile set on post:edit:quality.
|
|
112
|
+
return isHookEnabled(hookId, { profiles: 'minimal,standard,strict' })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function run(raw) {
|
|
116
|
+
return checkEditedFile(
|
|
117
|
+
raw,
|
|
118
|
+
isSubHookEnabled('post:edit:console-log'),
|
|
119
|
+
isSubHookEnabled('post:edit:code-size')
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function runCli(check) {
|
|
124
|
+
let raw = ''
|
|
125
|
+
process.stdin.setEncoding('utf8')
|
|
126
|
+
process.stdin.on('data', chunk => {
|
|
127
|
+
if (raw.length < MAX_STDIN_BYTES) raw += chunk.slice(0, MAX_STDIN_BYTES - raw.length)
|
|
128
|
+
})
|
|
129
|
+
process.stdin.on('end', () => {
|
|
130
|
+
const result = check(raw)
|
|
131
|
+
if (result.stderr) process.stderr.write(result.stderr)
|
|
132
|
+
if (result.stdout) process.stdout.write(result.stdout)
|
|
133
|
+
process.exit(result.exitCode || 0)
|
|
134
|
+
})
|
|
135
|
+
process.stdin.on('error', () => process.exit(0))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = { run, checkEditedFile, runCli }
|
|
139
|
+
if (require.main === module) runCli(run)
|