harveyz-skill 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/bin/cli.js +121 -37
- package/bin/preview.mjs +34 -3
- package/package.json +1 -1
- package/skills/coding/explain-pm/SKILL.md +14 -5
- package/skills/coding/init-workflow/references/acceptance-test.md +21 -6
- package/skills/coding/init-workflow/references/hook-templates.md +22 -1
- package/skills/research/extract-url/references/__pycache__/article_utils.cpython-314.pyc +0 -0
- package/skills/research/extract-url/scripts/__pycache__/config.cpython-314.pyc +0 -0
- package/skills/research/extract-url/scripts/__pycache__/migrate_to_folder_structure.cpython-314.pyc +0 -0
- package/skills/research/pdf-math-translate/SKILL.md +153 -83
- package/skills-index.json +2 -2
- package/tools/hub/docs/design-previews/git-textual-tui-design.html +0 -359
- package/tools/hub/docs/design-previews/tasks-textual-tui-design.html +0 -371
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.25.0] - 2026-07-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `hskill` install menu:新增按平台切换的循环视图(per-platform cycling view),一键升级快捷键
|
|
14
|
+
- `pdf-math-translate`:重写 frontmatter,补充 Init/Execute 两阶段流程与最新 CLI 参考
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- `explain-pm`:警示性意见调整为统一放在结尾,不再穿插
|
|
18
|
+
- `init-workflow`:修正 force-push 检测逻辑,合并提交(merge commit)豁免检查
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- 记录不新增 meta.json 完整性检查的 ADR 决策
|
|
22
|
+
|
|
10
23
|
## [0.24.0] - 2026-07-18
|
|
11
24
|
|
|
12
25
|
### Added
|
package/bin/cli.js
CHANGED
|
@@ -802,15 +802,34 @@ function requireFzf() {
|
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
-
|
|
806
|
-
function
|
|
807
|
-
|
|
808
|
-
|
|
805
|
+
const G = '\x1b[32m', Y = '\x1b[33m', C = '\x1b[36m', D = '\x1b[2m', R = '\x1b[0m'
|
|
806
|
+
function colorIcon(status) {
|
|
807
|
+
if (status === 'up-to-date') return G + '✓' + R
|
|
808
|
+
if (status === 'update') return Y + '↑' + R
|
|
809
|
+
return D + '—' + R
|
|
810
|
+
}
|
|
811
|
+
function scopeHint(installScope) {
|
|
812
|
+
if (installScope === 'essential') return Y + '»' + R
|
|
813
|
+
if (installScope === 'global' || installScope === 'project') return C + '▸' + R
|
|
814
|
+
return D + '—' + R
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// ── Hidden: fzf reload helper ─────────────────────────────────────────────────
|
|
818
|
+
// 供 fzf 的 reload()/execute() 动作回调,重新打印某个视图的最新内容(不进入交互模式)
|
|
819
|
+
if (subcommand === '__fzf-view') {
|
|
820
|
+
const key = args[1]
|
|
821
|
+
const content = key === 'skill' ? buildSkillViewInput() : buildSinglePlatformViewInput(key)
|
|
822
|
+
process.stdout.write(content + '\n')
|
|
823
|
+
process.exit(0)
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// 构建"按 skill 维度"的 fzf 输入行(skill/tool/hook 都在同一列表里)
|
|
827
|
+
function buildSkillViewInput() {
|
|
828
|
+
const skillItems = getAllSkillItems()
|
|
809
829
|
const toolItems = getAllToolItems()
|
|
810
830
|
const hookItems = getAllHookItems()
|
|
811
|
-
const previewPath = path.join(__dirname, 'preview.mjs')
|
|
812
831
|
|
|
813
|
-
//
|
|
832
|
+
// 每行 "NAME\tVERSION\tBUNDLE\tKIND\tSRCPATH\tINSTALLSCOPE"
|
|
814
833
|
const lines = [
|
|
815
834
|
...skillItems.map(s => {
|
|
816
835
|
const bundle = s.srcPath.split('/').slice(-2, -1)[0]
|
|
@@ -823,18 +842,6 @@ function fzfSelect() {
|
|
|
823
842
|
const nameWidth = Math.max(...lines.map(l => l.split('\t')[0].length))
|
|
824
843
|
const versionWidth = Math.max(...lines.map(l => l.split('\t')[1].length))
|
|
825
844
|
|
|
826
|
-
const G = '\x1b[32m', Y = '\x1b[33m', C = '\x1b[36m', D = '\x1b[2m', R = '\x1b[0m'
|
|
827
|
-
function colorIcon(status) {
|
|
828
|
-
if (status === 'up-to-date') return G + '✓' + R
|
|
829
|
-
if (status === 'update') return Y + '↑' + R
|
|
830
|
-
return D + '—' + R
|
|
831
|
-
}
|
|
832
|
-
function scopeHint(installScope) {
|
|
833
|
-
if (installScope === 'essential') return Y + '»' + R
|
|
834
|
-
if (installScope === 'global' || installScope === 'project') return C + '▸' + R
|
|
835
|
-
return D + '—' + R
|
|
836
|
-
}
|
|
837
|
-
|
|
838
845
|
// fzf 展示格式:NAME VERSION U:? P:? BUNDLE
|
|
839
846
|
const displayLines = lines.map(l => {
|
|
840
847
|
const [name, ver, bundle, kind, srcPath, installScope] = l.split('\t')
|
|
@@ -857,29 +864,106 @@ function fzfSelect() {
|
|
|
857
864
|
return `${name.padEnd(nameWidth)} ${ver.padEnd(versionWidth)} U:${uIcon} P:${pIcon} ${bundle}`
|
|
858
865
|
})
|
|
859
866
|
|
|
860
|
-
|
|
861
|
-
|
|
867
|
+
return displayLines.map((d, i) => `${d}\t${lines[i]}`).join('\n')
|
|
868
|
+
}
|
|
862
869
|
|
|
863
|
-
|
|
870
|
+
// 构建"单平台维度"的 fzf 输入行:每个 skill 一行,只展示该平台(user-scope)的安装状态
|
|
871
|
+
function buildSinglePlatformViewInput(targetName) {
|
|
872
|
+
const skillItems = getAllSkillItems()
|
|
873
|
+
const nameWidth = Math.max(...skillItems.map(s => s.skillName.length))
|
|
864
874
|
|
|
865
|
-
const
|
|
866
|
-
'
|
|
867
|
-
'
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
`--preview=node ${previewPath} {2} {3} {5} {6}`,
|
|
876
|
-
'--preview-window=right:42%:wrap',
|
|
877
|
-
], {
|
|
878
|
-
input: fzfInput,
|
|
879
|
-
encoding: 'utf8',
|
|
880
|
-
stdio: ['pipe', 'pipe', 'inherit'],
|
|
875
|
+
const lines = skillItems.map(s => {
|
|
876
|
+
const bundle = s.srcPath.split('/').slice(-2, -1)[0]
|
|
877
|
+
return `${s.skillName}\t${s.version ?? '—'}\t${bundle}\tskill\t${s.srcPath}\t${s.installScope ?? ''}`
|
|
878
|
+
})
|
|
879
|
+
|
|
880
|
+
const displayLines = skillItems.map(s => {
|
|
881
|
+
const installed = checkInstalled(s.skillName, s.version ?? '—')
|
|
882
|
+
const detail = installed.user[targetName]
|
|
883
|
+
const ver = detail.status === 'none' ? D + '—'.padEnd(7) + R : detail.version.padEnd(7)
|
|
884
|
+
return `${s.skillName.padEnd(nameWidth)} ${colorIcon(detail.status)} ${ver}`
|
|
881
885
|
})
|
|
882
886
|
|
|
887
|
+
return displayLines.map((d, i) => `${d}\t${lines[i]}`).join('\n')
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
function platformPrompt(key) {
|
|
891
|
+
return ` ${key} › `
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// 静态 header:不随视图切换而变化,避免把 ANSI/中文塞进 fzf 的 shell 动作字符串里
|
|
895
|
+
const COMBINED_HEADER = ` hskill · ${G}✓${R}=ok ${Y}↑${R}=update ${Y}»${R}=essential ${C}▸${R}=recommended ${D}—${R}=none · ctrl-t 切平台 ctrl-u 一键升级本平台 ctrl-g 升级该 skill 全平台 · tab 多选 · enter 确认`
|
|
896
|
+
|
|
897
|
+
// 用 fzf 交互式选择 skill/tool,返回选中的 item 列表
|
|
898
|
+
function fzfSelect() {
|
|
899
|
+
requireFzf()
|
|
900
|
+
const previewPath = path.join(__dirname, 'preview.mjs')
|
|
901
|
+
const selfPath = process.argv[1]
|
|
902
|
+
// 用不带 flag 的 read(bash/zsh 通用;-n/-p/-k 等 flag 在两者语义不同,混用会挂住)等待回车再回到 fzf
|
|
903
|
+
const pauseCmd = `; printf '\\n 按 enter 返回…'; read _`
|
|
904
|
+
|
|
905
|
+
// 视图顺序:skill 维度 → 逐个平台维度(每次只显示一个平台)→ 循环回 skill
|
|
906
|
+
const viewKeys = ['skill', ...SKILL_TARGETS]
|
|
907
|
+
const skillViewInput = buildSkillViewInput()
|
|
908
|
+
const viewFiles = Object.fromEntries(viewKeys.map(key => [key, `/tmp/hskill-view-${key}-${process.pid}.txt`]))
|
|
909
|
+
|
|
910
|
+
for (const key of viewKeys) {
|
|
911
|
+
const content = key === 'skill' ? skillViewInput : buildSinglePlatformViewInput(key)
|
|
912
|
+
writeFileSync(viewFiles[key], content)
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// 每个视图对应的 preview 命令:单平台视图额外传入平台 key,让 preview.mjs 只输出该平台的状态
|
|
916
|
+
function previewCmdFor(key) {
|
|
917
|
+
const base = `node ${previewPath} {2} {3} {5} {6}`
|
|
918
|
+
return key === 'skill' ? base : `${base} ${key}`
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// ctrl-t 循环切换:根据当前 prompt 找到下一个视图,reload 对应文件、更新 prompt 和 preview 命令
|
|
922
|
+
const cycleCases = viewKeys.map((key, i) => {
|
|
923
|
+
const next = viewKeys[(i + 1) % viewKeys.length]
|
|
924
|
+
return `"${platformPrompt(key)}") echo "reload(cat ${viewFiles[next]})+change-prompt(${platformPrompt(next)})+change-preview(${previewCmdFor(next)})" ;;`
|
|
925
|
+
}).join('\n')
|
|
926
|
+
const cycleScript = `case "$FZF_PROMPT" in\n${cycleCases}\nesac`
|
|
927
|
+
|
|
928
|
+
// ctrl-u:仅在单平台视图下生效,一键升级该平台上所有已装 skill(user scope),完成后刷新当前视图
|
|
929
|
+
const upgradeAllCases = viewKeys.map(key => {
|
|
930
|
+
if (key === 'skill') return `"${platformPrompt(key)}") echo "" ;;`
|
|
931
|
+
const upgradeCmd = `node ${selfPath} upgrade --target ${key} --scope user${pauseCmd}`
|
|
932
|
+
return `"${platformPrompt(key)}") echo "execute(${upgradeCmd})+reload(node ${selfPath} __fzf-view ${key})" ;;`
|
|
933
|
+
}).join('\n')
|
|
934
|
+
const upgradeAllScript = `case "$FZF_PROMPT" in\n${upgradeAllCases}\nesac`
|
|
935
|
+
|
|
936
|
+
// ctrl-g:任意视图下,把光标所在的 skill 升级到它已安装的所有平台(user scope),完成后刷新当前视图
|
|
937
|
+
const upgradeSkillScript = `if [ {5} = skill ]; then key=$(echo "$FZF_PROMPT" | awk '{print $1}'); echo "execute(node ${selfPath} upgrade --skill {2}${pauseCmd})+reload(node ${selfPath} __fzf-view $key)"; else echo ""; fi`
|
|
938
|
+
|
|
939
|
+
let result
|
|
940
|
+
try {
|
|
941
|
+
result = spawnSync('fzf', [
|
|
942
|
+
'--multi',
|
|
943
|
+
'--ansi',
|
|
944
|
+
'--delimiter=\t',
|
|
945
|
+
'--with-nth=1',
|
|
946
|
+
`--prompt=${platformPrompt('skill')}`,
|
|
947
|
+
`--header=${COMBINED_HEADER}`,
|
|
948
|
+
'--layout=reverse',
|
|
949
|
+
'--border=rounded',
|
|
950
|
+
'--color=header:italic:dim,prompt:cyan,pointer:cyan,hl:cyan,hl+:cyan:bold',
|
|
951
|
+
`--preview=node ${previewPath} {2} {3} {5} {6}`,
|
|
952
|
+
'--preview-window=right:42%:wrap',
|
|
953
|
+
`--bind=ctrl-t:transform:${cycleScript}`,
|
|
954
|
+
`--bind=ctrl-u:transform:${upgradeAllScript}`,
|
|
955
|
+
`--bind=ctrl-g:transform:${upgradeSkillScript}`,
|
|
956
|
+
], {
|
|
957
|
+
input: skillViewInput,
|
|
958
|
+
encoding: 'utf8',
|
|
959
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
960
|
+
})
|
|
961
|
+
} finally {
|
|
962
|
+
for (const file of Object.values(viewFiles)) {
|
|
963
|
+
try { unlinkSync(file) } catch { /* ignore */ }
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
883
967
|
if (result.status !== 0 || !result.stdout.trim()) return []
|
|
884
968
|
|
|
885
969
|
return result.stdout.trim().split('\n').map(line => {
|
package/bin/preview.mjs
CHANGED
|
@@ -11,6 +11,7 @@ const skillName = process.argv[2]?.trim()
|
|
|
11
11
|
const availableVersion = process.argv[3]?.trim() || '—'
|
|
12
12
|
const kind = process.argv[4]?.trim()
|
|
13
13
|
const srcPath = process.argv[5]?.trim()
|
|
14
|
+
const platformKey = process.argv[6]?.trim() || null
|
|
14
15
|
|
|
15
16
|
const G = '\x1b[32m', Y = '\x1b[33m', D = '\x1b[2m', R = '\x1b[0m', B = '\x1b[1m'
|
|
16
17
|
|
|
@@ -73,9 +74,7 @@ function statusLine(version, status) {
|
|
|
73
74
|
return ver + ' ' + D + '— not installed' + R
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
const
|
|
77
|
-
const projectTargets = SKILL_TARGETS.filter(t => !USER_ONLY_TARGETS.has(t))
|
|
78
|
-
const home = os.homedir()
|
|
77
|
+
const home = os.homedir()
|
|
79
78
|
|
|
80
79
|
function checkScope(targets, dirFn) {
|
|
81
80
|
return targets.map(t => {
|
|
@@ -87,6 +86,38 @@ function checkScope(targets, dirFn) {
|
|
|
87
86
|
})
|
|
88
87
|
}
|
|
89
88
|
|
|
89
|
+
// 单平台视图:只展示 ctrl-t 当前所在平台的状态,不展示全平台矩阵
|
|
90
|
+
if (platformKey && SKILL_TARGETS.includes(platformKey)) {
|
|
91
|
+
const cwd = process.cwd()
|
|
92
|
+
const userDir = path.join(home, `.${platformKey}`, 'skills')
|
|
93
|
+
const projectDir = path.join(cwd, `.${platformKey}`, 'skills')
|
|
94
|
+
const [userDetail] = checkScope([platformKey], () => userDir)
|
|
95
|
+
const projectDetail = USER_ONLY_TARGETS.has(platformKey) || cwd === home
|
|
96
|
+
? { version: '—', status: 'none' }
|
|
97
|
+
: checkScope([platformKey], () => projectDir)[0]
|
|
98
|
+
|
|
99
|
+
console.log(B + skillName + R)
|
|
100
|
+
console.log(D + 'available: ' + R + availableVersion)
|
|
101
|
+
console.log('')
|
|
102
|
+
|
|
103
|
+
console.log(B + platformKey.toUpperCase() + ' STATUS' + R)
|
|
104
|
+
console.log(' ' + 'user'.padEnd(8) + statusLine(userDetail.version, userDetail.status))
|
|
105
|
+
console.log(' ' + 'project'.padEnd(8) + statusLine(projectDetail.version, projectDetail.status))
|
|
106
|
+
console.log('')
|
|
107
|
+
|
|
108
|
+
if (userDetail.status === 'update' || projectDetail.status === 'update') {
|
|
109
|
+
console.log(Y + 'ACTION: update → ' + platformKey + R)
|
|
110
|
+
} else if (userDetail.status === 'none' && projectDetail.status === 'none') {
|
|
111
|
+
console.log(D + 'STATUS: not installed' + R)
|
|
112
|
+
} else {
|
|
113
|
+
console.log(G + 'STATUS: ok' + R)
|
|
114
|
+
}
|
|
115
|
+
process.exit(0)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const userTargets = SKILL_TARGETS
|
|
119
|
+
const projectTargets = SKILL_TARGETS.filter(t => !USER_ONLY_TARGETS.has(t))
|
|
120
|
+
|
|
90
121
|
const cwd = process.cwd()
|
|
91
122
|
const userDetails = checkScope(userTargets, t => path.join(home, `.${t}`, 'skills'))
|
|
92
123
|
const projectDetails = cwd === home
|
package/package.json
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: explain-pm
|
|
3
|
-
description: "Restate a recent technical explanation
|
|
3
|
+
description: "Restate a recent technical explanation from a product-manager's analytical lens — user experience, product philosophy, execution mechanics, and architectural health — rather than translating jargon, and flag product-perspective concerns like scope, over-engineering, priority, or drift from user need. Triggers: '/explain-pm', '/explain-pm <topic or file>', 'explain this like a PM', 'restate from a PM perspective'."
|
|
4
4
|
user_invocable: true
|
|
5
|
-
version: "1.
|
|
5
|
+
version: "1.1.1"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# explain-pm — PM 视角复述
|
|
9
9
|
|
|
10
|
-
把一段技术性表述从 PM
|
|
10
|
+
把一段技术性表述从 PM 视角复述:换成 PM 关注的分析维度,再视情况指出值得从产品角度重新考虑的地方。
|
|
11
11
|
|
|
12
12
|
## 触发
|
|
13
13
|
|
|
14
14
|
仅手动调用:`/explain-pm` 或 `/explain-pm <主题或文件路径>`。不自动检测触发,不主动插话。
|
|
15
15
|
|
|
16
|
+
## PM 视角的关注维度
|
|
17
|
+
|
|
18
|
+
不是语言转译——PM 本身熟悉基础技术语言。要转换的是关注点:
|
|
19
|
+
|
|
20
|
+
- **用户体验**:这个决定最终会让用户感受到什么变化?
|
|
21
|
+
- **产品哲学**:是否符合产品一贯的取舍和原则?
|
|
22
|
+
- **执行机制与流程**:具体怎么落地——谁来做、分几步、影响什么协作节奏?
|
|
23
|
+
- **架构健康度(次要)**:是否有明显的技术债或长期维护风险,只做提醒,不展开实现细节本身。
|
|
24
|
+
|
|
16
25
|
## 执行
|
|
17
26
|
|
|
18
27
|
1. **取材料**:带参数用参数指定的主题或文件;无参数则取调用前的最后一条 assistant 消息。
|
|
19
|
-
2.
|
|
20
|
-
3. **提出关注点(视情况)**:判断原表述从 PM
|
|
28
|
+
2. **换视角**:对照上面的关注维度重新审视材料——不必在回复里逐条列出,只是分析时的参考。
|
|
29
|
+
3. **提出关注点(视情况)**:判断原表述从 PM 角度是否有值得重新审视的地方,比如是否偏离用户实际需求、范围是否合理、是否过度工程化、优先级是否搞错了。如果原表述本身已经很贴近产品目标,挑不出问题,就只做视角复述,不硬造关注点。关注点如果成立,放在回复最后,不要打断前面的视角复述。
|
|
21
30
|
4. **输出**:在对话中直接回复,简短(几句话量级)。默认不写文件;仅当用户明确要求存档时,才把这段评论写入用户指定的文件。
|
|
22
31
|
|
|
23
32
|
## 不做
|
|
@@ -60,14 +60,23 @@ rm -f /tmp/gwi-test-msg-${TIMESTAMP}.txt
|
|
|
60
60
|
|
|
61
61
|
取 `push_rules.block_force_push` 第一个分支名作为 `PROTECTED_PUSH_BRANCH`。
|
|
62
62
|
|
|
63
|
+
`pre-push/force-push` 块用 `git merge-base --is-ancestor` 判断非 fast-forward,因此必须用真实存在于仓库历史中的两个 commit 来构造"远端不是本地祖先"的场景,不能用假造的 SHA 字符串(假 SHA 在真实仓库里既不是祖先也不是非祖先,`git merge-base` 会因对象不存在报错,不代表 force push 语义)。用当前 `HEAD` 作为 remote_sha、`HEAD~1` 作为 local_sha:remote(较新)不是 local(较旧)的祖先,等价于历史被回退重写。仓库只有一个提交(无 `HEAD~1`)时跳过此场景。
|
|
64
|
+
|
|
63
65
|
```bash
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
if git rev-parse -q --verify HEAD~1 >/dev/null 2>&1; then
|
|
67
|
+
REMOTE_SHA=$(git rev-parse HEAD)
|
|
68
|
+
LOCAL_SHA=$(git rev-parse HEAD~1)
|
|
69
|
+
output=$(printf "refs/heads/%s %s refs/heads/%s %s\n" \
|
|
70
|
+
"$PROTECTED_PUSH_BRANCH" "$LOCAL_SHA" "$PROTECTED_PUSH_BRANCH" "$REMOTE_SHA" \
|
|
71
|
+
| sh .githooks/pre-push 2>&1)
|
|
72
|
+
exit_code=$?
|
|
73
|
+
SKIPPED=0
|
|
74
|
+
else
|
|
75
|
+
SKIPPED=1
|
|
76
|
+
fi
|
|
68
77
|
```
|
|
69
78
|
|
|
70
|
-
**期望:** `exit_code = 1
|
|
79
|
+
**期望:** 仓库提交数 ≥ 2 时 `exit_code = 1`;仅有一个提交时标记为 SKIP,不计入 PASS/FAIL。
|
|
71
80
|
|
|
72
81
|
---
|
|
73
82
|
|
|
@@ -114,7 +123,13 @@ pre-push force push 到 <branch>(应拒绝) PASS ✅
|
|
|
114
123
|
pre-push 非法 tag 推送(应拒绝) PASS ✅
|
|
115
124
|
post-checkout 不合规分支名(应有 ⚠️ 警告) PASS ✅
|
|
116
125
|
──────────────────────────────────────────────────────
|
|
117
|
-
✅ 全部通过(N/N
|
|
126
|
+
✅ 全部通过(N/N,SKIP 不计入分母)。继续 Step 7...
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
若 force push 场景因仓库只有一个提交被跳过,对应行显示:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
pre-push force push 到 <branch>(应拒绝) SKIP ⏭️(仓库提交数 < 2,无法构造历史)
|
|
118
133
|
```
|
|
119
134
|
|
|
120
135
|
若有失败:
|
|
@@ -93,9 +93,22 @@ SUBJECT=$(printf '%s\n' "$SUBJECT" | sed '/^#/d' | sed 's/^[[:space:]]*//')
|
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
**格式检查 MANAGED 块(`commit-msg/format`):**
|
|
96
|
+
块内首行固定豁免合并提交(`MERGE_HEAD` 存在即视为合并提交,直接放行,不做格式/长度校验):
|
|
97
|
+
```sh
|
|
98
|
+
# --- BEGIN MANAGED: commit-msg/format (hash:<hash>) ---
|
|
99
|
+
[ -f "$(git rev-parse --git-dir)/MERGE_HEAD" ] && exit 0
|
|
100
|
+
if ! printf '%s\n' "$SUBJECT" | grep -qE "<pattern>"; then
|
|
101
|
+
echo "❌ 提交信息不符合 Conventional Commits 规范"
|
|
102
|
+
...
|
|
103
|
+
exit 1
|
|
104
|
+
fi
|
|
105
|
+
# --- END MANAGED: commit-msg/format ---
|
|
106
|
+
```
|
|
96
107
|
- `format: conventional`:将 `types` 列表拼接为正则 `^(feat|fix|...)(\(.+\))?: .+`;`require_scope: false` 时 scope 部分为可选 `(\(.+\))?`
|
|
97
108
|
- `format: regex`:使用配置的 `pattern` 字段直接作为 grep 表达式
|
|
98
109
|
|
|
110
|
+
若不豁免合并提交,git 默认生成的 "Merge branch '...'" 信息永远无法通过 Conventional Commits 校验;而若强行要求合并提交也写成 conventional 格式,pre-commit 中 `merge_source_branch()` 依赖 git 默认 `MERGE_MSG` 文本解析来源分支,自定义信息会导致解析失败。豁免合并提交让两个 hook 同时成立。
|
|
111
|
+
|
|
99
112
|
**长度检查 MANAGED 块(`commit-msg/length`):**
|
|
100
113
|
```sh
|
|
101
114
|
# --- BEGIN MANAGED: commit-msg/length (hash:<hash>) ---
|
|
@@ -145,15 +158,23 @@ while IFS=' ' read -r local_ref local_sha remote_ref remote_sha; do
|
|
|
145
158
|
# --- BEGIN MANAGED: pre-push/force-push (hash:<hash>) ---
|
|
146
159
|
refs/heads/main|refs/heads/staging)
|
|
147
160
|
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
|
|
148
|
-
echo "❌
|
|
161
|
+
echo "❌ 禁止删除受保护分支:$remote_ref"
|
|
149
162
|
exit 1
|
|
150
163
|
fi
|
|
164
|
+
if [ "$remote_sha" != "0000000000000000000000000000000000000000" ]; then
|
|
165
|
+
if ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then
|
|
166
|
+
echo "❌ 禁止强制推送到受保护分支:$remote_ref"
|
|
167
|
+
exit 1
|
|
168
|
+
fi
|
|
169
|
+
fi
|
|
151
170
|
;;
|
|
152
171
|
# --- END MANAGED: pre-push/force-push ---
|
|
153
172
|
```
|
|
154
173
|
|
|
155
174
|
`refs/heads/main|refs/heads/staging` 从 `push_rules.block_force_push` 列表动态生成。
|
|
156
175
|
|
|
176
|
+
`local_sha` 全零表示删除远端分支,与 force push 是两码事,单独拦截并报出不同的提示。真正的非 fast-forward(force push)检测用 `git merge-base --is-ancestor "$remote_sha" "$local_sha"`:若远端当前 SHA 不是本地待推送 SHA 的祖先,说明历史被重写,即 force push;`remote_sha` 全零(推送全新分支)时跳过该判断,因为此时没有旧历史可比较。
|
|
177
|
+
|
|
157
178
|
**固定尾部:**
|
|
158
179
|
```sh
|
|
159
180
|
esac
|
|
Binary file
|
|
Binary file
|