hunter-harness 0.1.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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/dist/bin.js +3356 -0
  4. package/package.json +34 -0
  5. package/resources/bootstrap-ir/manifest.json +19 -0
  6. package/resources/bootstrap-ir/skills/harness-apidoc.yaml +24 -0
  7. package/resources/bootstrap-ir/skills/harness-archive.yaml +24 -0
  8. package/resources/bootstrap-ir/skills/harness-codebase-map.yaml +24 -0
  9. package/resources/bootstrap-ir/skills/harness-knowledge-ingest.yaml +24 -0
  10. package/resources/bootstrap-ir/skills/harness-package.yaml +24 -0
  11. package/resources/bootstrap-ir/skills/harness-plan.yaml +24 -0
  12. package/resources/bootstrap-ir/skills/harness-review.yaml +24 -0
  13. package/resources/bootstrap-ir/skills/harness-run.yaml +24 -0
  14. package/resources/bootstrap-ir/skills/harness-skill-optimizer.yaml +28 -0
  15. package/resources/bootstrap-ir/skills/harness-submit.yaml +24 -0
  16. package/resources/bootstrap-ir/skills/harness-sync.yaml +24 -0
  17. package/resources/bootstrap-ir/skills/harness-test.yaml +24 -0
  18. package/resources/bootstrap-ir/templates/claude-code-skill.md +12 -0
  19. package/resources/harness/general/.harness-build.json +5 -0
  20. package/resources/harness/general/CONTEXT.md +65 -0
  21. package/resources/harness/general/README.md +478 -0
  22. package/resources/harness/general/agents/harness-evaluator.md +96 -0
  23. package/resources/harness/general/agents/harness-explorer.md +72 -0
  24. package/resources/harness/general/agents/harness-reviewer.md +69 -0
  25. package/resources/harness/general/harness-archive/SKILL.md +215 -0
  26. package/resources/harness/general/harness-archive/checklist.md +52 -0
  27. package/resources/harness/general/harness-archive/reference.md +103 -0
  28. package/resources/harness/general/harness-archive/scripts/gen-manifest.ps1 +31 -0
  29. package/resources/harness/general/harness-archive/templates/render-summary.mjs +171 -0
  30. package/resources/harness/general/harness-archive/templates/summary-data-template.json +128 -0
  31. package/resources/harness/general/harness-codebase-map/SKILL.md +112 -0
  32. package/resources/harness/general/harness-codebase-map/checklist.md +126 -0
  33. package/resources/harness/general/harness-codebase-map/reference.md +364 -0
  34. package/resources/harness/general/harness-codebase-map/templates/ARCHITECTURE.md +57 -0
  35. package/resources/harness/general/harness-codebase-map/templates/CONCERNS.md +49 -0
  36. package/resources/harness/general/harness-codebase-map/templates/CONVENTIONS.md +57 -0
  37. package/resources/harness/general/harness-codebase-map/templates/INTEGRATIONS.md +52 -0
  38. package/resources/harness/general/harness-codebase-map/templates/STACK.md +55 -0
  39. package/resources/harness/general/harness-codebase-map/templates/STRUCTURE.md +69 -0
  40. package/resources/harness/general/harness-codebase-map/templates/TESTING.md +64 -0
  41. package/resources/harness/general/harness-codebase-map/templates/map-manifest.schema.json +73 -0
  42. package/resources/harness/general/harness-codebase-map/templates/map-summary.md +64 -0
  43. package/resources/harness/general/harness-knowledge-ingest/SKILL.md +246 -0
  44. package/resources/harness/general/harness-knowledge-ingest/design.md +842 -0
  45. package/resources/harness/general/harness-knowledge-ingest/evaluations/harness_knowledge_evaluation.xml +42 -0
  46. package/resources/harness/general/harness-knowledge-ingest/mcp-config.example.json +10 -0
  47. package/resources/harness/general/harness-knowledge-ingest/reference.md +309 -0
  48. package/resources/harness/general/harness-knowledge-ingest/scripts/harness_knowledge.py +4082 -0
  49. package/resources/harness/general/harness-knowledge-ingest/scripts/harness_knowledge_mcp.py +273 -0
  50. package/resources/harness/general/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-01-10-ledger-reconciliation/reports/final/summary-data.json +43 -0
  51. package/resources/harness/general/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-02-14-ledger-snapshot-followup/reports/final/summary-data.json +38 -0
  52. package/resources/harness/general/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-03-05-webhook-contract/reports/final/summary-data.json +36 -0
  53. package/resources/harness/general/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/project.yaml +1 -0
  54. package/resources/harness/general/harness-knowledge-ingest/tests/test_harness_knowledge.py +1792 -0
  55. package/resources/harness/general/harness-knowledge-query/SKILL.md +164 -0
  56. package/resources/harness/general/harness-plan/SKILL.md +127 -0
  57. package/resources/harness/general/harness-plan/checklist.md +243 -0
  58. package/resources/harness/general/harness-plan/protocols.md +124 -0
  59. package/resources/harness/general/harness-plan/reference.md +376 -0
  60. package/resources/harness/general/harness-review/SKILL.md +156 -0
  61. package/resources/harness/general/harness-review/checklist.md +124 -0
  62. package/resources/harness/general/harness-review/protocols.md +68 -0
  63. package/resources/harness/general/harness-review/reference.md +86 -0
  64. package/resources/harness/general/harness-run/SKILL.md +132 -0
  65. package/resources/harness/general/harness-run/checklist.md +259 -0
  66. package/resources/harness/general/harness-run/protocols.md +78 -0
  67. package/resources/harness/general/harness-run/reference.md +834 -0
  68. package/resources/harness/general/harness-submit/SKILL.md +159 -0
  69. package/resources/harness/general/harness-submit/checklist.md +407 -0
  70. package/resources/harness/general/harness-submit/reference.md +152 -0
  71. package/resources/harness/general/harness-sync/SKILL.md +82 -0
  72. package/resources/harness/general/harness-sync/reference.md +153 -0
  73. package/resources/harness/general/harness-test/SKILL.md +180 -0
  74. package/resources/harness/general/harness-test/checklist.md +319 -0
  75. package/resources/harness/general/harness-test/pitfalls.md +260 -0
  76. package/resources/harness/general/harness-test/reference.md +791 -0
  77. package/resources/harness/general/protocols/archive-report-protocol.md +175 -0
  78. package/resources/harness/general/protocols/evidence-based-reporting-protocol.md +134 -0
  79. package/resources/harness/general/protocols/ledger-protocol.md +270 -0
  80. package/resources/harness/general/protocols/powershell-protocol.md +181 -0
  81. package/resources/harness/general/protocols/report-pipeline-protocol.md +150 -0
  82. package/resources/harness/general/protocols/sensitive-info-protocol.md +92 -0
  83. package/resources/harness/general/protocols/state-layout-protocol.md +131 -0
  84. package/resources/harness/general/protocols/submit-protocol.md +78 -0
  85. package/resources/harness/general/scripts/harness_archive.py +2319 -0
  86. package/resources/harness/general/scripts/harness_deploy.py +613 -0
  87. package/resources/harness/general/scripts/harness_events.py +680 -0
  88. package/resources/harness/general/scripts/harness_ledger.py +671 -0
  89. package/resources/harness/general/scripts/harness_preflight.py +780 -0
  90. package/resources/harness/general/scripts/harness_service.py +1331 -0
  91. package/resources/harness/java/.harness-build.json +5 -0
  92. package/resources/harness/java/CONTEXT.md +65 -0
  93. package/resources/harness/java/README.md +478 -0
  94. package/resources/harness/java/agents/harness-evaluator.md +96 -0
  95. package/resources/harness/java/agents/harness-explorer.md +72 -0
  96. package/resources/harness/java/agents/harness-reviewer.md +69 -0
  97. package/resources/harness/java/harness-apidoc/SKILL.md +86 -0
  98. package/resources/harness/java/harness-apidoc/checklist.md +142 -0
  99. package/resources/harness/java/harness-apidoc/reference.md +233 -0
  100. package/resources/harness/java/harness-archive/SKILL.md +215 -0
  101. package/resources/harness/java/harness-archive/checklist.md +52 -0
  102. package/resources/harness/java/harness-archive/reference.md +103 -0
  103. package/resources/harness/java/harness-archive/scripts/gen-manifest.ps1 +31 -0
  104. package/resources/harness/java/harness-archive/templates/render-summary.mjs +171 -0
  105. package/resources/harness/java/harness-archive/templates/summary-data-template.json +128 -0
  106. package/resources/harness/java/harness-codebase-map/SKILL.md +112 -0
  107. package/resources/harness/java/harness-codebase-map/checklist.md +126 -0
  108. package/resources/harness/java/harness-codebase-map/reference.md +364 -0
  109. package/resources/harness/java/harness-codebase-map/templates/ARCHITECTURE.md +57 -0
  110. package/resources/harness/java/harness-codebase-map/templates/CONCERNS.md +49 -0
  111. package/resources/harness/java/harness-codebase-map/templates/CONVENTIONS.md +57 -0
  112. package/resources/harness/java/harness-codebase-map/templates/INTEGRATIONS.md +52 -0
  113. package/resources/harness/java/harness-codebase-map/templates/STACK.md +55 -0
  114. package/resources/harness/java/harness-codebase-map/templates/STRUCTURE.md +69 -0
  115. package/resources/harness/java/harness-codebase-map/templates/TESTING.md +64 -0
  116. package/resources/harness/java/harness-codebase-map/templates/map-manifest.schema.json +73 -0
  117. package/resources/harness/java/harness-codebase-map/templates/map-summary.md +64 -0
  118. package/resources/harness/java/harness-knowledge-ingest/SKILL.md +246 -0
  119. package/resources/harness/java/harness-knowledge-ingest/design.md +842 -0
  120. package/resources/harness/java/harness-knowledge-ingest/evaluations/harness_knowledge_evaluation.xml +42 -0
  121. package/resources/harness/java/harness-knowledge-ingest/mcp-config.example.json +10 -0
  122. package/resources/harness/java/harness-knowledge-ingest/reference.md +309 -0
  123. package/resources/harness/java/harness-knowledge-ingest/scripts/harness_knowledge.py +4082 -0
  124. package/resources/harness/java/harness-knowledge-ingest/scripts/harness_knowledge_mcp.py +273 -0
  125. package/resources/harness/java/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-01-10-ledger-reconciliation/reports/final/summary-data.json +43 -0
  126. package/resources/harness/java/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-02-14-ledger-snapshot-followup/reports/final/summary-data.json +38 -0
  127. package/resources/harness/java/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/archive/2026-03-05-webhook-contract/reports/final/summary-data.json +36 -0
  128. package/resources/harness/java/harness-knowledge-ingest/tests/fixtures/mcp-eval-project/.harness/project.yaml +1 -0
  129. package/resources/harness/java/harness-knowledge-ingest/tests/test_harness_knowledge.py +1792 -0
  130. package/resources/harness/java/harness-knowledge-query/SKILL.md +164 -0
  131. package/resources/harness/java/harness-package/SKILL.md +87 -0
  132. package/resources/harness/java/harness-package/checklist.md +322 -0
  133. package/resources/harness/java/harness-package/reference.md +210 -0
  134. package/resources/harness/java/harness-plan/SKILL.md +127 -0
  135. package/resources/harness/java/harness-plan/checklist.md +243 -0
  136. package/resources/harness/java/harness-plan/protocols.md +124 -0
  137. package/resources/harness/java/harness-plan/reference.md +376 -0
  138. package/resources/harness/java/harness-review/SKILL.md +156 -0
  139. package/resources/harness/java/harness-review/checklist.md +124 -0
  140. package/resources/harness/java/harness-review/protocols.md +68 -0
  141. package/resources/harness/java/harness-review/reference.md +86 -0
  142. package/resources/harness/java/harness-run/SKILL.md +148 -0
  143. package/resources/harness/java/harness-run/checklist.md +250 -0
  144. package/resources/harness/java/harness-run/protocols.md +78 -0
  145. package/resources/harness/java/harness-run/reference.md +814 -0
  146. package/resources/harness/java/harness-submit/SKILL.md +166 -0
  147. package/resources/harness/java/harness-submit/checklist.md +407 -0
  148. package/resources/harness/java/harness-submit/reference.md +152 -0
  149. package/resources/harness/java/harness-sync/SKILL.md +82 -0
  150. package/resources/harness/java/harness-sync/reference.md +153 -0
  151. package/resources/harness/java/harness-test/SKILL.md +192 -0
  152. package/resources/harness/java/harness-test/checklist.md +317 -0
  153. package/resources/harness/java/harness-test/pitfalls-java.md +16 -0
  154. package/resources/harness/java/harness-test/pitfalls.md +260 -0
  155. package/resources/harness/java/harness-test/reference.md +788 -0
  156. package/resources/harness/java/protocols/archive-report-protocol.md +175 -0
  157. package/resources/harness/java/protocols/evidence-based-reporting-protocol.md +134 -0
  158. package/resources/harness/java/protocols/ledger-protocol.md +270 -0
  159. package/resources/harness/java/protocols/powershell-protocol.md +181 -0
  160. package/resources/harness/java/protocols/report-pipeline-protocol.md +150 -0
  161. package/resources/harness/java/protocols/sensitive-info-protocol.md +92 -0
  162. package/resources/harness/java/protocols/state-layout-protocol.md +131 -0
  163. package/resources/harness/java/protocols/submit-protocol.md +78 -0
  164. package/resources/harness/java/scripts/harness_archive.py +2319 -0
  165. package/resources/harness/java/scripts/harness_deploy.py +613 -0
  166. package/resources/harness/java/scripts/harness_events.py +680 -0
  167. package/resources/harness/java/scripts/harness_ledger.py +671 -0
  168. package/resources/harness/java/scripts/harness_preflight.py +780 -0
  169. package/resources/harness/java/scripts/harness_service.py +1331 -0
  170. package/resources/harness/manifests/general.json +296 -0
  171. package/resources/harness/manifests/java.json +324 -0
  172. package/resources/manifest.json +19 -0
  173. package/resources/skills/harness-apidoc/SKILL.md +50 -0
  174. package/resources/skills/harness-archive/SKILL.md +48 -0
  175. package/resources/skills/harness-codebase-map/SKILL.md +53 -0
  176. package/resources/skills/harness-knowledge-ingest/SKILL.md +48 -0
  177. package/resources/skills/harness-package/SKILL.md +48 -0
  178. package/resources/skills/harness-plan/SKILL.md +51 -0
  179. package/resources/skills/harness-review/SKILL.md +50 -0
  180. package/resources/skills/harness-run/SKILL.md +48 -0
  181. package/resources/skills/harness-skill-optimizer/SKILL.md +54 -0
  182. package/resources/skills/harness-submit/SKILL.md +47 -0
  183. package/resources/skills/harness-sync/SKILL.md +48 -0
  184. package/resources/skills/harness-test/SKILL.md +50 -0
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: harness-knowledge-query
3
+ description: "根据新需求、设计任务、代码修改请求或问题排查,在规划和编码前查询 .harness/knowledge 历史上下文。适用场景:query knowledge、查找历史需求、根据归档理解需求、继续之前类似开发、生成需求上下文包。"
4
+ argument-hint: "<需求文本> [--file <path>] [--status active|candidate|stale]"
5
+ effort: medium
6
+ allowed-tools: [Bash(powershell.exe:*), Read, Write, Edit, Glob, Grep]
7
+ disallowed-tools:
8
+ - Bash(git *)
9
+ - Bash(mvn *)
10
+ - Bash(ls *)
11
+ - Bash(find *)
12
+ - Bash(grep *)
13
+ - Bash(cat *)
14
+ - Bash(cp *)
15
+ - Bash(mv *)
16
+ - Bash(rm *)
17
+ - Bash(mkdir *)
18
+ - Bash(touch *)
19
+ - Bash(sed *)
20
+ - Bash(awk *)
21
+ - Bash(curl *)
22
+ ---
23
+ <!-- generated by harness_deploy.py; core=8917528f7dfdc5ca; overlay=java; do not edit -->
24
+ # harness-knowledge-query
25
+
26
+ 根据用户的新需求或排查问题,从项目本地 `.harness/knowledge` 中检索历史需求、决策、实现、风险和测试证据,并生成 AI 可读的 context pack。
27
+
28
+ 此 skill 只负责查询和使用知识。整理、同步和 promote 条目由 `harness-knowledge-ingest` 负责。
29
+
30
+ ## Triggers
31
+
32
+ - query knowledge
33
+ - knowledge query
34
+ - 查找相关历史需求
35
+ - 根据历史归档理解这个需求
36
+ - 结合之前做过的内容
37
+ - 继续之前类似开发
38
+ - 生成需求上下文包
39
+ - 在规划前查历史
40
+
41
+ ## Automatic Use
42
+
43
+ 当用户提出新功能、改造、排查、设计方案、继续历史任务,且项目存在 `.harness/archive` 或 `.harness/knowledge` 时,AI 应主动运行本 skill,不需要等用户提醒。
44
+
45
+ 如果 `.harness/knowledge/index.json` 不存在或已过期,先运行:
46
+
47
+ ```powershell
48
+ powershell.exe -Command "python '<ingest-skill-dir>\scripts\harness_knowledge.py' sync --project '<project-root>' --update"
49
+ ```
50
+
51
+ 然后再查询。
52
+
53
+ ## Commands
54
+
55
+ `<ingest-skill-dir>` 指同级 `harness-knowledge-ingest/` 目录;查询逻辑复用其脚本。所有 python 脚本命令通过 `powershell.exe -Command "..."` 执行,避开 Bash 在 Windows 中文路径下的编码/参数问题。
56
+
57
+ ### Query by requirement
58
+
59
+ ```powershell
60
+ powershell.exe -Command "python '<ingest-skill-dir>\scripts\harness_knowledge.py' query --project '<project-root>' --query '<用户需求原文>'"
61
+ ```
62
+
63
+ ### Query with metadata filters
64
+
65
+ ```powershell
66
+ powershell.exe -Command "python '<ingest-skill-dir>\scripts\harness_knowledge.py' query --project '<project-root>' --query '<需求或关键词>' --file '<source-file>' --status active"
67
+ ```
68
+
69
+ 可重复使用:
70
+
71
+ - `--file <path>`:只返回关联到指定文件的知识。
72
+ - `--status active|candidate|stale|superseded|conflicted`:按生命周期过滤。
73
+ - `--type requirement|decision|implementation|risk|test-evidence|pitfall|api-contract`:按知识类型过滤。
74
+ - `--limit <n>`:限制返回数量。
75
+
76
+ ## Workflow
77
+
78
+ 1. 确认项目根目录。
79
+ 2. 运行 `sync --project <root>`。
80
+ 3. 如果 `upToDate=false`,运行 `sync --update`。
81
+ 4. 用用户原始需求作为 `--query` 查询。
82
+ 5. 如已知道相关文件,追加 `--file` 过滤。
83
+ 6. 读取 JSON 输出中的 `contextPack`。
84
+ 7. 在 `harness-plan`、设计、代码探索或实现前,把 context pack 当作必读输入。
85
+
86
+ ## Output Contract
87
+
88
+ 查询输出 JSON 包含:
89
+
90
+ - `matchCount`
91
+ - `contextPack`
92
+ - `filters`
93
+ - `planInput`
94
+ - `matches`
95
+
96
+ `planInput.kind` 必须为 `harness-knowledge-context-pack`。后续 `harness-plan` 应读取 `planInput.path`。
97
+
98
+ 每次查询还会更新稳定指针:
99
+
100
+ ```text
101
+ .harness/knowledge/context-packs/latest.json
102
+ ```
103
+
104
+ 该文件包含最新 query、context pack 路径和 `matchIds`,供后续流程快速读取最近一次知识上下文。
105
+
106
+ ## Interpretation Rules
107
+
108
+ - `active`:可优先采用,但仍要结合当前代码验证。
109
+ - `candidate`:有参考价值,不是当前事实。
110
+ - `stale`:只能作为历史线索,必须重新检查代码和归档。
111
+ - `superseded` / `conflicted`:必须显式提示风险,不得静默采用。
112
+
113
+ ## Forbidden Actions
114
+
115
+ - rebuild_index_without_need
116
+ - treat_candidate_as_current_fact
117
+ - treat_stale_as_current_fact
118
+ - skip_context_pack_before_planning
119
+ - copy_large_archive_content_into_prompt
120
+
121
+ ## Verification
122
+
123
+ ```powershell
124
+ powershell.exe -Command "python -m unittest '<ingest-skill-dir>\tests\test_harness_knowledge.py'"
125
+ powershell.exe -Command "python '<ingest-skill-dir>\scripts\harness_knowledge.py' query --project '<real-project-root>' --query '<真实需求>'"
126
+ ```
127
+
128
+ 确认输出中存在 `contextPack`、`planInput.kind=harness-knowledge-context-pack`,且 context pack 文件包含 `Before planning`。
129
+
130
+ ## P0 执行可信度规则
131
+
132
+ - 命令结果不得靠猜测;普通 Bash 被拒 → 立即改用等价 PowerShell 重试一次
133
+ - 仅 PowerShell 成功且有明确证据(构建/git/测试输出、文件存在、exit 0)时可标 ✅OK;否则 ❌FAIL 或 🟡WARN
134
+ - 禁止把 hook 拒绝、静态验证、无输出、用户跳过说成成功 → 详见 [[../protocols/powershell-protocol.md|powershell-protocol]]、[[../protocols/evidence-based-reporting-protocol.md|evidence-based-reporting-protocol]]
135
+
136
+ ## Output Format
137
+
138
+ 执行完成后展示:
139
+
140
+ - 用户需求原文与生效的过滤条件(`--file`/`--status`/`--type`/`--limit`)。
141
+ - `matchCount` 与按状态分组的命中数(active/candidate/stale/superseded/conflicted)。
142
+ - `contextPack` 路径与 `latest.json` 指针。
143
+ - 命中 stale/superseded/conflicted 时显式提示风险。
144
+ - 下一步建议(context pack 已就绪 → 进入 `/harness-plan`;索引过期 → 先 `sync --update`)。
145
+
146
+ ## 渐进披露
147
+
148
+ - 本 skill 暂无 `checklist.md` / `reference.md` 支持文件,规则全部在 SKILL.md。若 Output Contract / Interpretation Rules 后续扩展变重,应拆到 `reference.md`。
149
+
150
+ ## 交互白名单
151
+
152
+ **无** AskUserQuestion;`stale`/`conflicted` 命中记 `issue`,不阻断 query。
153
+
154
+ ## 执行日志
155
+
156
+ `events.ndjson` 为唯一事实源(schema_version 2,`note` 承载人类可读摘要);`logs/execution-log.md` 由 `harness_events.py` 渲染,**禁止手工 Edit**。结构 → [[../protocols/report-pipeline-protocol.md|report-pipeline-protocol]]
157
+
158
+ ```powershell
159
+ python <skills-root>/scripts/harness_events.py append --change-dir ".harness/changes/<change-name>" --phase <phase> --type phase.start --note "<触发指令>"
160
+ ```
161
+
162
+ > **脚本接线**:`harness_events.py append`;`harness_archive.py finalize`;`harness_preflight.py check`;`harness_ledger.py can-reuse`;`harness_service.py ensure/stop`(须 `--files`/`serviceStart.inputFiles`)。JSON 输出按 D13 护栏解读。
163
+
164
+ > **Task 4 §6.1 写入契约**:普通 `append` = 加锁 -> 追加一行 -> fsync -> 解锁,**不 load 历史、不渲染**(O(1),跨进程锁 `events.ndjson.lock`,UUID 用完整 `uuid4().hex` 无需去重扫描)。仅 `--type phase.end` append 在追加成功后渲染一次 `execution-log.md`;显式 `harness_events.py render` 随时从完整 events 重建;`harness_archive.py finalize` 在 collect 前强制 render 一次。高频 command append 期间 log 可能滞后,phase 边界保持最新。
@@ -0,0 +1,87 @@
1
+ ---
2
+ name: harness-package
3
+ description: "增量模块打包:拉取最新→编译验证→mvn package→汇总 jar/war。使用场景:打包、package、发版准备"
4
+ argument-hint: "变更名或留空自动检测"
5
+ effort: medium
6
+ allowed-tools: [Bash(powershell.exe:*), Read, Write, Edit, Glob, Grep]
7
+ disallowed-tools:
8
+ - Bash(git *)
9
+ - Bash(mvn *)
10
+ - Bash(ls *)
11
+ - Bash(find *)
12
+ - Bash(grep *)
13
+ - Bash(cat *)
14
+ - Bash(cp *)
15
+ - Bash(mv *)
16
+ - Bash(rm *)
17
+ - Bash(mkdir *)
18
+ - Bash(touch *)
19
+ - Bash(sed *)
20
+ - Bash(awk *)
21
+ - Bash(curl *)
22
+ ---
23
+ <!-- generated by harness_deploy.py; core=8917528f7dfdc5ca; overlay=java; do not edit -->
24
+ # harness-package — 增量模块打包(Java overlay)
25
+
26
+ ## Purpose
27
+
28
+ 基于 final pushed commit 识别变更模块 → 增量 `mvn package` → 汇总 jar/war 路径与大小。
29
+
30
+ > 默认时序:`submit → package → archive`。test 已通过且 ledger 有效时可 `-DskipTests`。
31
+
32
+ ## When to Use
33
+
34
+ - submit 已推送,准备发版打包
35
+ - 触发语:"打包""package""发版准备"
36
+
37
+ ## 前置条件
38
+
39
+ - 推荐已完成 `/harness-submit`;`baseCommit` 以 submit 最终 hash 为准
40
+ - test 报告存在或 ledger 可复用;读 `meta/worktree.json` 决定 worktree 目录
41
+
42
+ ## 统一读取协议
43
+
44
+ 1. **`.harness/changes/<change-name>/` 是唯一真相源** — 所有输入从该目录读取,产物写入对应子目录
45
+ 2. **change-name 优先从 frontmatter 读取** — `spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
46
+ 3. **frontmatter 缺失时兼容旧格式** — 从路径推断,标记 `🟡 legacy-plan`,不失败
47
+ 4. **spec** — 设计真相源:`spec/<change>-design.md`
48
+ 5. **plan** — 任务真相源:`plans/<change>-plan.md`
49
+ 6. **implementation-detail** — 自适应执行参考;legacy 缺失 🟡WARN,不阻断
50
+ 7. **test-scenarios** — 测试真相源:`plans/<change>-test-scenarios.md`
51
+ 8. **禁止读取 `docs/superpowers/` 作为正式输入** — 旧草稿仅人工线索
52
+
53
+ 状态目录分层:新路径优先,旧路径兼容 → [[../protocols/state-layout-protocol.md|state-layout-protocol]]
54
+
55
+ ## Workflow
56
+
57
+ 1. 读 ledger + build-profile 的 `buildCommands.package`
58
+ 2. 识别变更模块(git diff + pom 结构)
59
+ 3. `mvn package -DskipTests`(ledger 不可复用时先跑必要测试)
60
+ 4. 写打包报告 + append 事件
61
+
62
+ ## P0 执行可信度规则
63
+
64
+ - 命令结果不得靠猜测;普通 Bash 被拒 → 立即改用等价 PowerShell 重试一次
65
+ - 仅 PowerShell 成功且有明确证据(构建/git/测试输出、文件存在、exit 0)时可标 ✅OK;否则 ❌FAIL 或 🟡WARN
66
+ - 禁止把 hook 拒绝、静态验证、无输出、用户跳过说成成功 → 详见 [[../protocols/powershell-protocol.md|powershell-protocol]]、[[../protocols/evidence-based-reporting-protocol.md|evidence-based-reporting-protocol]]
67
+
68
+ ## 渐进披露
69
+
70
+ - **Read `reference.md`** — 模块识别与报告格式
71
+ - **Read `checklist.md`** — 逐步勾选
72
+
73
+ ## 交互白名单
74
+
75
+ **无** AskUserQuestion;冲突/失败记 `issue`/`decision`。
76
+
77
+ ## 执行日志
78
+
79
+ `events.ndjson` 为唯一事实源(schema_version 2,`note` 承载人类可读摘要);`logs/execution-log.md` 由 `harness_events.py` 渲染,**禁止手工 Edit**。结构 → [[../protocols/report-pipeline-protocol.md|report-pipeline-protocol]]
80
+
81
+ ```powershell
82
+ python <skills-root>/scripts/harness_events.py append --change-dir ".harness/changes/<change-name>" --phase <phase> --type phase.start --note "<触发指令>"
83
+ ```
84
+
85
+ > **脚本接线**:`harness_events.py append`;`harness_archive.py finalize`;`harness_preflight.py check`;`harness_ledger.py can-reuse`;`harness_service.py ensure/stop`(须 `--files`/`serviceStart.inputFiles`)。JSON 输出按 D13 护栏解读。
86
+
87
+ > **Task 4 §6.1 写入契约**:普通 `append` = 加锁 -> 追加一行 -> fsync -> 解锁,**不 load 历史、不渲染**(O(1),跨进程锁 `events.ndjson.lock`,UUID 用完整 `uuid4().hex` 无需去重扫描)。仅 `--type phase.end` append 在追加成功后渲染一次 `execution-log.md`;显式 `harness_events.py render` 随时从完整 events 重建;`harness_archive.py finalize` 在 collect 前强制 render 一次。高频 command append 期间 log 可能滞后,phase 边界保持最新。
@@ -0,0 +1,322 @@
1
+ ---
2
+ description: harness-package 的8步工作流详细步骤、模块识别方法和执行日志记录格式。仅在执行打包流程时读取。
3
+ ---
4
+
5
+ # harness-package 检查清单
6
+
7
+ ## 步骤 0:启动准备
8
+
9
+ 确定变更名:用 Glob 搜索 `.harness/changes/*/plans/*-plan.md`(**排除 `.harness/archive/*/`**),读取 frontmatter 提取 `change-name`。默认最多一个未归档变更;如有多个,优先取最近修改的,或用 AskUserQuestion 询问用户。
10
+
11
+ 如果 `$ARGUMENTS` 非空且与检测到的变更名不一致,以 `$ARGUMENTS` 为准。
12
+
13
+ **读取 worktree 状态并切换**:读 `.harness/changes/<change-name>/meta/worktree.json`(旧路径 `worktree.json` 兼容)。`requested=true` 且 `.claude/worktrees/<change-name>/` 已创建 → cd 到该 worktree 目录;`requested=true` 但 worktree 不存在 → 停止,提示先修复 `harness-run`,不得静默回主目录;`requested=false` → 在主目录执行。切换后检查构建配置文件(`.mvn/maven.config`、`settings-*.xml` 等)是否完整,缺失时从主目录复制。
14
+
15
+ **强制前置检查 — harness-test(硬门禁)和 harness-review(参考性)**:
16
+
17
+ 通过 Glob 检查:
18
+ - `.harness/changes/<change-name>/reports/test/test-report-*.md` 是否存在(旧路径 `tests/` 兼容)
19
+ - `.harness/changes/<change-name>/reports/review/review-report-*.md` 是否存在(参考性,不阻塞;旧路径 `reviews/` 兼容)
20
+
21
+ 如果缺失 test 报告,使用 `AskUserQuestion` 询问用户:
22
+
23
+ ```
24
+ 检测到 harness-test 尚未运行(缺少测试报告):
25
+ - 测试报告: <存在/缺失>
26
+ - 审查报告: <存在/缺失>(参考性,不阻塞)
27
+
28
+ 打包前建议先运行测试。请选择:
29
+ 1. 先运行 harness-test — 退出 package 流程,运行 harness-test 后再 package(推荐)
30
+ 2. 跳过测试继续打包 — 风险自担,报告中明确标记
31
+ 3. 取消 package
32
+ ```
33
+
34
+ **默认不跳过 test**。用户确认跳过时,必须在执行日志和 package-report 中明确写明:
35
+ - 执行日志:`- **跳过**: 用户确认跳过 harness-test`
36
+ - package-report:`> ⚠️ 用户确认跳过 harness-test,打包结果未经测试验证`
37
+
38
+ **review 报告**:如果存在,记录路径和摘要供参考;如果不存在,不阻塞 package。review 结果不作为硬门禁。
39
+
40
+ **读取 verification-ledger + 确定 baseCommit**:
41
+
42
+ 1. 读取 `.harness/changes/<change-name>/evidence/verification-ledger.json`(旧路径 `verification-ledger.json` 兼容),记录 `unitTest`/`apiTest` 的 status、`diffHash`、`currentHead`
43
+ 2. 确定 `baseCommit`:优先取 `.harness/changes/<change-name>/logs/execution-log.md` 中 harness-submit 阶段的 `final pushed hash`(旧路径 `execution-log.md` 兼容);无 submit 记录时取当前 `git rev-parse HEAD`
44
+ 3. 判断 ledger 是否有效(全部满足才算有效):
45
+ - `unitTest.status=OK` 且 `apiTest.status=OK`
46
+ - `diffHash` 与当前提交一致
47
+ - submit 后无新提交(`git log <baseCommit>..HEAD` 为空)
48
+ - 无行为性 post-test 修改(`postTestClassification` ∈ {无, NON_BEHAVIORAL_CLEANUP, COMMENT_ONLY, TEST_ONLY})
49
+ 4. ledger 有效 → 默认 `mvn package -DskipTests` 复用测试;ledger 无效 → 带测试打包或要求先跑 `/harness-test`
50
+
51
+ **append `phase.start`**(含 worktree/baseCommit/ledger 摘要于 `note`):
52
+
53
+ ```powershell
54
+ python <skills-root>/scripts/harness_events.py append --change-dir ".harness/changes/<change-name>" --phase package --type phase.start --note "<触发指令>"
55
+ ```
56
+
57
+ ## 步骤 1:拉取最新代码
58
+
59
+ > **分支名自动读取**:不硬编码 `master` 或 `main`,使用 `git rev-parse --abbrev-ref @{u}` 自动读取 upstream 分支。
60
+
61
+ 合并他人提交,确保打包基于最新代码:
62
+
63
+ ```powershell
64
+ # 0. 自动读取当前分支的 upstream
65
+ powershell.exe -Command "git -C '<项目路径>' rev-parse --abbrev-ref @{u}"
66
+ # 输出示例:origin/master 或 origin/develop
67
+
68
+ # 1. 暂存当前变更
69
+ powershell.exe -Command "git -C '<项目路径>' stash"
70
+
71
+ # 2. 拉取远程最新代码(使用读取到的 upstream)
72
+ powershell.exe -Command "git -C '<项目路径>' pull"
73
+
74
+ # 3. 恢复暂存的变更
75
+ powershell.exe -Command "git -C '<项目路径>' stash pop"
76
+ ```
77
+
78
+ **冲突处理**:
79
+ - `git stash pop` 产生冲突 → **停止打包流程**,提示用户手动解决冲突
80
+ - `git pull` 失败(网络问题)→ 提示用户检查网络,询问是否继续(基于本地代码打包)
81
+ - 无冲突 → 继续步骤 2
82
+
83
+ **Shell 安全规则(强制)**:
84
+ - 如果 `git stash` / `git pull` 命令被 hook 拒绝(输出含 `Denied` / `PreToolUse:Bash hook error`),**必须停止流程**或重试 PowerShell 调用
85
+ - **不得基于被拒绝的输出继续后续步骤**(不能假装"拉取成功")
86
+ - 拉取成功的判断证据:git 输出包含 `Already up to date.` 或 `Fast-forward`、`Updating <hash>..<hash>`,且 exit code 为 0
87
+
88
+ ## 步骤 2:合并后重新验证(ledger 复用优先)
89
+
90
+ 合并后必须重新编译;测试是否重跑按 ledger 有效性决定。
91
+
92
+ **ledger 有效时**(步骤 0 已判定):跳过 `mvn test`,仅执行 `mvn compile` 确认合并后可编译,测试结果复用 ledger。
93
+
94
+ **ledger 无效时**:执行 `mvn compile` + `mvn test`,结果写回 ledger。
95
+
96
+ **合并后重新验证前,先检查依赖模块**:
97
+ ```powershell
98
+ # 检查上游依赖模块是否已 install 到本地仓库
99
+ powershell.exe -Command "Test-Path '$env:USERPROFILE\.m2\repository\<group-path>\<module>\*\*.jar'"
100
+ ```
101
+ 如果缺失,先安装:
102
+ ```powershell
103
+ powershell.exe -Command "mvn install -pl <upstream-modules> -am -DskipTests -nsu"
104
+ ```
105
+
106
+ ```powershell
107
+ # 编译验证(始终执行)
108
+ powershell.exe -Command "mvn compile -pl <module> -am"
109
+
110
+ # 测试验证(仅 ledger 无效或用户要求 package-with-tests 时执行)
111
+ powershell.exe -Command "mvn test -pl <module> -am"
112
+ ```
113
+
114
+ **编译/测试成功必须有明确证据**:
115
+ - `mvn compile` 输出必须包含 `BUILD SUCCESS`
116
+ - `mvn test` 输出必须包含 `Tests run: N, Failures: 0, Errors: 0`
117
+ - 命令被 hook 拒绝或 exit code 非 0 → 标记为 ❌ 失败,停止流程
118
+
119
+ **pull 后远程变更检查**:
120
+ ```powershell
121
+ # 检查 pull 是否引入了他人提交
122
+ powershell.exe -Command "git -C '<项目路径>' log HEAD@{1}..HEAD --oneline"
123
+ ```
124
+ - 如果有他人提交(输出非空),**ledger 失效**,必须重新 compile + test,即使 pull 前已验证过
125
+ - 如果没有他人提交(输出为空),ledger 仍然有效,可基于已有验证结果继续
126
+
127
+ **验证失败处理**:
128
+ - 编译失败 → 分析是否与本次变更相关。相关则修复后重试;无关(他人引入的问题)则记录并询问用户是否继续
129
+ - 测试失败 → 分析失败原因。如果是他人代码破坏了本次功能,记录冲突点并提示用户
130
+
131
+ > **为什么合并后必须重新编译**:他人代码可能引入新依赖(编译失败)、修改公共接口(调用点断裂)、修改数据库结构(测试数据不匹配)。即使 git 自动合并无冲突,语义层面可能存在冲突。ledger 复用仅在 pull 未引入他人提交时成立。
132
+
133
+ ## 步骤 3:变更模块识别
134
+
135
+ **变更模块识别必须区分四种来源,不得把远程他人变更误判为本次变更**:
136
+
137
+ | 来源 | git 命令 | 用途 |
138
+ |------|---------|------|
139
+ | a. 本地未提交变更(工作区) | `git diff --name-only` | 当前正在编辑但未 add 的变更 |
140
+ | b. staged 变更 | `git diff --cached --name-only` | 已 add 但未 commit 的变更 |
141
+ | c. 已提交但未推送变更 | `git log @{u}..HEAD --name-only --pretty=format:` | 本次开发的本地提交 |
142
+ | d. 远程 pull 进来的他人变更 | `git log HEAD@{1}..HEAD --name-only --pretty=format:` | pull 引入的他人提交,**不得纳入本次变更模块** |
143
+
144
+ **识别本次变更模块的标准来源**:
145
+ - 本次开发涉及的变更 = a + b + c(工作区 + staged + 本地未推送提交)
146
+ - 远程 pull 进来的 d 是他人变更,仅作为"合并验证"对象,不写入本次打包变更模块清单
147
+
148
+ 1. **确定本次变更比较基线**:使用 upstream(不硬编码 master/main):
149
+
150
+ ```powershell
151
+ # 自动读取 upstream 名称
152
+ powershell.exe -Command "git -C '<项目路径>' rev-parse --abbrev-ref @{u}"
153
+ # 输出示例:origin/master
154
+
155
+ # 计算 merge-base
156
+ powershell.exe -Command "git -C '<项目路径>' merge-base HEAD '@{u}'"
157
+ ```
158
+
159
+ 2. **获取本次变更文件列表(排除 pull 进来的他人变更)**:
160
+
161
+ ```powershell
162
+ # 获取本地未提交+本地已提交(不含远程拉入的他人提交)
163
+ powershell.exe -Command "git -C '<项目路径>' diff '@{u}'...HEAD --name-only"
164
+ ```
165
+
166
+ > 注意 `...HEAD`(三点)会自动排除从 upstream 合并进来的他人提交,只保留本地分叉后的变更。
167
+
168
+ 3. **映射到 Maven 模块**:逐个检查变更文件的路径,判断其所属的 Maven 模块:
169
+ - 找到变更文件所在目录及其父目录中的 `pom.xml`
170
+ - 模块路径 = `pom.xml` 所在目录的相对路径(如 `module-a/sub-module-b`)
171
+ - 同一模块的多个变更文件只记录一次
172
+ - 根目录 `pom.xml` 的变更属于父项目本身(用根路径 `.` 表示)
173
+
174
+ 4. **识别依赖链**:对每个变更模块,检查哪些其他模块依赖它:
175
+ - 扫描其他模块的 `pom.xml` 中 `<dependency>` 引用了变更模块的 `<groupId>:<artifactId>`
176
+ - 这些下游模块也需要打包(对应 Maven `-amd` 参数)
177
+ - 上游依赖模块(变更模块自身依赖的模块)由 `-am` 自动包含
178
+
179
+ 5. **输出模块清单**:汇总所有变更模块 + 依赖链涉及模块,展示给用户:
180
+
181
+ ```markdown
182
+ ## 变更模块识别结果
183
+
184
+ ### 直接变更模块 (N 个)
185
+ - `module-a` — 变更文件: 5 (src/main/java/..., src/main/resources/...)
186
+ - `module-b/sub-b` — 变更文件: 2
187
+
188
+ ### 依赖链涉及模块
189
+ - 上游(-am): parent-pom, module-common
190
+ - 下游(-amd): module-web (依赖 module-a)
191
+
192
+ ### 未变更模块(将跳过)
193
+ - module-c, module-d
194
+ ```
195
+
196
+ ## 步骤 4:打包模式选择
197
+
198
+ 使用 AskUserQuestion 向用户展示选项:
199
+
200
+ ```markdown
201
+ 已识别 N 个变更模块及其依赖链,请选择打包模式:
202
+
203
+ 1. 增量打包 — 只打包变更模块 + 上游依赖(-pl <modules> -am)
204
+ 适用:日常发版,构建速度快
205
+ 命令:mvn package -pl module-a,module-b/sub-b -am
206
+
207
+ 2. 增量打包(含下游) — 打包变更模块 + 上游 + 下游(-pl <modules> -am -amd)
208
+ 适用:需要验证下游模块兼容性
209
+
210
+ 3. 全量打包 — 打包所有模块
211
+ 适用:首次发版、重大重构、不确定依赖关系时
212
+ 命令:mvn package
213
+
214
+ 4. 自定义 — 手动指定模块列表
215
+ ```
216
+
217
+ 降级策略:用户无明确偏好时,默认选择选项 1(增量打包 + 上游依赖)。
218
+
219
+ ## 步骤 5:执行打包
220
+
221
+ 根据步骤 4 的选择构建 Maven 命令。**是否带 `-DskipTests` 由 ledger 有效性决定**:
222
+
223
+ **ledger 有效时(默认)**:复用 test 阶段验证,跳过测试
224
+
225
+ ```powershell
226
+ # 增量打包(选项 1)
227
+ powershell.exe -Command "mvn package -pl <module-list> -am -DskipTests"
228
+ # 增量打包含下游(选项 2)
229
+ powershell.exe -Command "mvn package -pl <module-list> -am -amd -DskipTests"
230
+ # 全量打包(选项 3)
231
+ powershell.exe -Command "mvn package -DskipTests"
232
+ ```
233
+
234
+ **ledger 无效时或用户要求 package-with-tests**:去掉 `-DskipTests`
235
+
236
+ ```powershell
237
+ powershell.exe -Command "mvn package -pl <module-list> -am"
238
+ ```
239
+
240
+ **关键规则**:
241
+ - **ledger 有效时默认 `-DskipTests`**,复用 test 阶段的 unitTest + apiTest 结果(不是"跳过测试",是"复用已验证结果")
242
+ - ledger 无效 / 用户要求 `package-with-tests` / test 报告缺失 → 必须带测试打包
243
+ - `-pl` 中的模块路径使用相对于根 pom.xml 的路径,多模块用逗号分隔
244
+ - 记录开始时间用于计算耗时
245
+ - 打包失败时**立即停止**,不继续后续步骤,转入错误处理
246
+
247
+ **失败处理**:
248
+ - 输出失败模块名称和错误信息
249
+ - 提示用户检查:
250
+ 1. 依赖是否完整(是否需要先 `mvn install` 安装上游模块)
251
+ 2. 版本冲突(参考 `reference.md` 常见问题)
252
+ 3. 编译错误(是否遗漏了某个变更文件)
253
+ - 用 AskUserQuestion 询问用户:重试 / 调整模块范围 / 停止
254
+
255
+ ## 步骤 6:结果收集
256
+
257
+ 打包成功后,逐模块扫描产物(**必须通过 Glob 实际扫描确认,不能仅根据 Maven 输出猜测**):
258
+
259
+ 1. **扫描 target/ 目录**:对每个打包模块,用 **Glob 工具实际扫描**:
260
+
261
+ ```
262
+ <module-path>/target/*.jar
263
+ <module-path>/target/*.war
264
+ ```
265
+
266
+ 2. **收集信息**(基于 Glob 实际返回的文件):
267
+ - 产物文件名
268
+ - 产物相对路径(相对于项目根目录)
269
+ - 文件大小(用 `powershell.exe -Command "Get-Item '<path>' | Select-Object Length"` 获取)
270
+ - **sha256**(必填,用于 ledger 和部署校验:`powershell.exe -Command "Get-FileHash '<path>' -Algorithm SHA256"`)
271
+
272
+ 3. **构建状态判定(必须基于实际证据)**:
273
+ - ✅ SUCCESS — Glob 扫描确认 target/ 中存在预期的 jar/war 文件 + Maven 输出含 `BUILD SUCCESS`
274
+ - 🟡 SKIPPED — 模块不含主产物(如 parent-pom 模块只有 pom.xml)
275
+ - ❌ FAILED — 打包命令报错(已在步骤 5 处理)/ Glob 扫描未找到产物 / Maven 输出含 `BUILD FAILURE`
276
+
277
+ 4. **汇总产物表**:
278
+
279
+ ```markdown
280
+ | 模块 | 产物 | 路径 | 大小 | 状态 |
281
+ |------|------|------|------|------|
282
+ | module-a | xxx-service.jar | module-a/target/xxx-service-1.0.jar | 12.5 MB | ✅ SUCCESS |
283
+ | module-web | xxx-web.war | module-web/target/xxx-web-1.0.war | 45.2 MB | ✅ SUCCESS |
284
+ | parent-pom | — | — | — | 🟡 SKIPPED |
285
+ ```
286
+
287
+ ## 步骤 7:持久化报告 + 写回 ledger
288
+
289
+ 将打包报告写入 `.harness/changes/<change-name>/reports/package/package-report-YYYYMMDD-HHmm.md`。
290
+
291
+ 时间戳取当前时间,格式 `YYYYMMDD-HHmm`(如 `20260617-1430`)。
292
+
293
+ 报告内容格式见 `reference.md` 的"报告格式示例"。报告必须包含「测试执行策略」段落(见 reference.md)。
294
+
295
+ **写回 `evidence/verification-ledger.json` 的 `package` 项**:
296
+
297
+ ```json
298
+ "package": {
299
+ "status": "OK",
300
+ "command": "mvn package -pl <module> -am -DskipTests",
301
+ "baseCommit": "<final pushed hash 或当前 HEAD>",
302
+ "deployArtifact": "<module>/target/<artifact>.jar",
303
+ "sha256": "<artifact sha256>",
304
+ "testsExecuted": false,
305
+ "testsReusedFrom": "unitTest+apiTest",
306
+ "evidence": "BUILD SUCCESS + Glob 扫描确认 jar 存在",
307
+ "startedAt": "...",
308
+ "finishedAt": "...",
309
+ "durationMs": 0
310
+ }
311
+ ```
312
+
313
+ - `testsExecuted`:本次 package 是否真实跑了测试(ledger 有效且用了 `-DskipTests` → false)
314
+ - `testsReusedFrom`:`testsExecuted=false` 时必须指明复用来源(`unitTest+apiTest`)
315
+
316
+ ## 步骤 8:events 结束
317
+
318
+ **append `phase.complete`**(`note` 含 baseCommit/打包策略/结果/报告路径):
319
+
320
+ ```powershell
321
+ python <skills-root>/scripts/harness_events.py append --change-dir ".harness/changes/<change-name>" --phase package --type phase.complete --note "OK|WARN|FAIL — <摘要>"
322
+ ```