@hunter-harness/workflow-harness 0.2.31 → 0.2.33

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 (50) hide show
  1. package/harness/bundles/general/claude-code/harness-plan/SKILL.md +1 -1
  2. package/harness/bundles/general/claude-code/harness-plan/checklist.md +2 -0
  3. package/harness/bundles/general/claude-code/harness-plan/reference.md +6 -0
  4. package/harness/bundles/general/claude-code/scripts/harness_gate.py +8 -19
  5. package/harness/bundles/general/claude-code/scripts/harness_plan_finalize.py +179 -58
  6. package/harness/bundles/general/codebuddy/harness-plan/SKILL.md +1 -1
  7. package/harness/bundles/general/codebuddy/harness-plan/checklist.md +2 -0
  8. package/harness/bundles/general/codebuddy/harness-plan/reference.md +6 -0
  9. package/harness/bundles/general/codebuddy/scripts/harness_gate.py +8 -19
  10. package/harness/bundles/general/codebuddy/scripts/harness_plan_finalize.py +179 -58
  11. package/harness/bundles/general/codex/harness-plan/SKILL.md +1 -1
  12. package/harness/bundles/general/codex/harness-plan/checklist.md +2 -0
  13. package/harness/bundles/general/codex/harness-plan/reference.md +6 -0
  14. package/harness/bundles/general/codex/scripts/harness_gate.py +8 -19
  15. package/harness/bundles/general/codex/scripts/harness_plan_finalize.py +179 -58
  16. package/harness/bundles/general/cursor/harness-plan/SKILL.md +1 -1
  17. package/harness/bundles/general/cursor/harness-plan/checklist.md +2 -0
  18. package/harness/bundles/general/cursor/harness-plan/reference.md +6 -0
  19. package/harness/bundles/general/cursor/scripts/harness_gate.py +8 -19
  20. package/harness/bundles/general/cursor/scripts/harness_plan_finalize.py +179 -58
  21. package/harness/bundles/java/claude-code/harness-plan/SKILL.md +1 -1
  22. package/harness/bundles/java/claude-code/harness-plan/checklist.md +2 -0
  23. package/harness/bundles/java/claude-code/harness-plan/reference.md +6 -0
  24. package/harness/bundles/java/claude-code/scripts/harness_gate.py +8 -19
  25. package/harness/bundles/java/claude-code/scripts/harness_plan_finalize.py +179 -58
  26. package/harness/bundles/java/codebuddy/harness-plan/SKILL.md +1 -1
  27. package/harness/bundles/java/codebuddy/harness-plan/checklist.md +2 -0
  28. package/harness/bundles/java/codebuddy/harness-plan/reference.md +6 -0
  29. package/harness/bundles/java/codebuddy/scripts/harness_gate.py +8 -19
  30. package/harness/bundles/java/codebuddy/scripts/harness_plan_finalize.py +179 -58
  31. package/harness/bundles/java/codex/harness-plan/SKILL.md +1 -1
  32. package/harness/bundles/java/codex/harness-plan/checklist.md +2 -0
  33. package/harness/bundles/java/codex/harness-plan/reference.md +6 -0
  34. package/harness/bundles/java/codex/scripts/harness_gate.py +8 -19
  35. package/harness/bundles/java/codex/scripts/harness_plan_finalize.py +179 -58
  36. package/harness/bundles/java/cursor/harness-plan/SKILL.md +1 -1
  37. package/harness/bundles/java/cursor/harness-plan/checklist.md +2 -0
  38. package/harness/bundles/java/cursor/harness-plan/reference.md +6 -0
  39. package/harness/bundles/java/cursor/scripts/harness_gate.py +8 -19
  40. package/harness/bundles/java/cursor/scripts/harness_plan_finalize.py +179 -58
  41. package/harness/manifests/general/claude-code.json +7 -7
  42. package/harness/manifests/general/codebuddy.json +7 -7
  43. package/harness/manifests/general/codex.json +7 -7
  44. package/harness/manifests/general/cursor.json +7 -7
  45. package/harness/manifests/java/claude-code.json +7 -7
  46. package/harness/manifests/java/codebuddy.json +7 -7
  47. package/harness/manifests/java/codex.json +7 -7
  48. package/harness/manifests/java/cursor.json +7 -7
  49. package/hunter-workflow-family.json +4 -4
  50. package/package.json +1 -1
@@ -106,7 +106,7 @@ change-name 范围变更 → 提示重命名或记 🟡WARN(→ `reference.md`
106
106
  |------|------|
107
107
  | 产物路径 | 只写 `.harness/changes/<cn>/`;禁止 superpowers 输入 |
108
108
  | 设计审批包 | 一次 blocking user confirmation 含 worktree(读 `harness.json` `defaultWorktree`) |
109
- | 阶段 8 | spec/plan/detail/scenarios/worktree.json 先进入 staging;仅 finalizer 校验成功后发布并写唯一 `phase.end`/log;随后 `verify` 必须确认 start/end、收据哈希、全部任务表和非空场景清单一致,失败不得手工补终态 |
109
+ | 阶段 8 | spec/plan/detail/scenarios/gate-policy/worktree 六项标准产物先进入 staging;仅 finalizer 校验成功后发布并写唯一 `phase.end`/log;随后 `verify` 必须确认 start/end、收据完整覆盖六项标准产物、哈希、全部任务表和非空场景清单一致,失败不得手工补终态 |
110
110
  | Plan 结束 | **禁止**询问执行模式;只提示 `/harness-run` |
111
111
  | 知识查询 | 0.5 失败不得假装已读历史 |
112
112
  | 歧义优先检查 | 否定、对比、动作对象或范围存在多种合理解释时,最小取证后先给推荐理解并一次一问;确认前不深挖错误方向 |
@@ -214,6 +214,7 @@ source: harness-plan
214
214
  - [ ] finalizer 返回 `ok=true` 与 `artifactsHash`;重复执行返回 `idempotent=true`
215
215
  - [ ] 紧接着执行 `harness_plan_finalize.py verify --change-dir ... --json`
216
216
  - [ ] verify 返回 `phaseStartCount=1`、`phaseEndCount=1`、`phaseEndStatus=OK`、`receiptConsistent=true`
217
+ - [ ] 收据 `files` 完整包含 design / plan / implementation-detail / test-scenarios / gate-policy / worktree 六项标准产物;不得省略、重复或经 symlink/junction/reparse point 引用
217
218
  - [ ] verify 的 `taskCount` 等于全部任务表行数,`scenarioCount` 等于 Markdown 中全部唯一场景 ID 数;任一为 0 或不一致即 ❌FAIL
218
219
  - [ ] finalizer 失败时正式目录无半发布产物、无成功 `phase.end`、无伪造 execution log
219
220
  - [ ] 禁止在 finalizer 之前手工追加成功 `phase.end`
@@ -224,6 +225,7 @@ source: harness-plan
224
225
  | `.harness/changes/<change>/plans/<change>-plan.md` | ✅ | □ |
225
226
  | `.harness/changes/<change>/plans/<change>-implementation-detail.md` | ✅ | □ |
226
227
  | `.harness/changes/<change>/plans/<change>-test-scenarios.md` | ✅ | □ |
228
+ | `.harness/changes/<change>/meta/gate-policy.json` | ✅ | □ |
227
229
  | `.harness/changes/<change>/meta/worktree.json` | ✅ | □ |
228
230
  | `.harness/changes/<change>/meta/implementation-checkpoints.json` | ✅ | □ |
229
231
  | `.harness/changes/<change>/meta/scenario-manifest.json`(非空且计数一致) | ✅ | □ |
@@ -335,10 +335,16 @@ status: approved
335
335
  | `.harness/changes/<change>/plans/<change>-plan.md` | ✅ |
336
336
  | `.harness/changes/<change>/plans/<change>-implementation-detail.md` | ✅ |
337
337
  | `.harness/changes/<change>/plans/<change>-test-scenarios.md` | ✅ |
338
+ | `.harness/changes/<change>/meta/gate-policy.json` | ✅ |
338
339
  | `.harness/changes/<change>/meta/worktree.json` | ✅ |
340
+ | `.harness/changes/<change>/meta/implementation-checkpoints.json` | ✅ |
341
+ | `.harness/changes/<change>/meta/scenario-manifest.json` | ✅ |
342
+ | `.harness/changes/<change>/meta/plan-finalization.json` | ✅ |
339
343
  | `.harness/changes/<change>/logs/execution-log.md` | ✅ |
340
344
  | `.harness/changes/<change>/events.ndjson` | ✅ |
341
345
 
346
+ `plan-finalization.json.files` 必须完整列出 design、plan、implementation-detail、test-scenarios、gate-policy、worktree 六项标准输入。`verify` 对缺项、重复项、越界路径以及 symlink/junction/reparse point 一律 fail-closed;不得通过删减收据文件集后重算哈希来绕过完整性检查。
347
+
342
348
  ### Plan 结束行为规则
343
349
 
344
350
  - **禁止询问执行模式**:Subagent-Driven / Inline Execution 属于 /harness-run 阶段
@@ -1635,31 +1635,27 @@ def _validate_scenario_coverage(change_dir: Path) -> dict[str, Any]:
1635
1635
  for s in scenarios
1636
1636
  if isinstance(s, dict)
1637
1637
  and (
1638
- s.get("requiredEvidenceKind") == "ledger"
1639
- or (
1640
- not s.get("requiredEvidenceKind")
1641
- and str(s.get("priority", "")).upper() in {"P0", "P1"}
1642
- )
1638
+ str(s.get("priority", "")).upper() in {"P0", "P1"}
1639
+ or s.get("requiredEvidenceKind") == "ledger"
1643
1640
  )
1644
1641
  }
1645
1642
  if not required_ids:
1646
1643
  return {"ok": True, "code": "NO_LEDGER_REQUIRED_SCENARIOS"}
1647
1644
 
1648
- ledger_path = change_dir / "evidence" / "verification-ledger.json"
1649
- if not ledger_path.is_file():
1645
+ try:
1646
+ ledger, ledger_path = hl.load_ledger(change_dir)
1647
+ except (OSError, ValueError, json.JSONDecodeError) as exc:
1650
1648
  return {
1651
1649
  "ok": False,
1652
1650
  "code": "SCENARIO_COVERAGE_FAILED",
1653
- "message": "ledger missing; cannot verify required scenario coverage",
1651
+ "message": f"ledger unreadable: {exc}",
1654
1652
  "missing": sorted(required_ids),
1655
1653
  }
1656
- try:
1657
- ledger = json.loads(ledger_path.read_text(encoding="utf-8-sig"))
1658
- except (OSError, json.JSONDecodeError) as exc:
1654
+ if ledger is None or ledger_path is None:
1659
1655
  return {
1660
1656
  "ok": False,
1661
1657
  "code": "SCENARIO_COVERAGE_FAILED",
1662
- "message": f"ledger unreadable: {exc}",
1658
+ "message": "ledger missing; cannot verify required scenario coverage",
1663
1659
  "missing": sorted(required_ids),
1664
1660
  }
1665
1661
  covered: set[str] = set()
@@ -1728,13 +1724,6 @@ def cmd_begin(args: argparse.Namespace) -> int:
1728
1724
  or plan_verification.get("message")
1729
1725
  or "finalized plan verification failed"
1730
1726
  )
1731
- record_blocked_attempt(
1732
- change_dir,
1733
- phase=args.phase,
1734
- code=code,
1735
- message=message,
1736
- run_id=args.run_id or os.environ.get("HUNTER_HARNESS_RUN_ID"),
1737
- )
1738
1727
  return emit_error(
1739
1728
  code,
1740
1729
  message,
@@ -11,9 +11,10 @@ import json
11
11
  import os
12
12
  import re
13
13
  import shutil
14
+ import stat
14
15
  import sys
15
16
  import tempfile
16
- from pathlib import Path
17
+ from pathlib import Path, PurePosixPath
17
18
  from typing import Any
18
19
 
19
20
  SCRIPTS_DIR = Path(__file__).resolve().parent
@@ -45,12 +46,19 @@ PRIORITY_EVIDENCE_KIND = {
45
46
  "P1": "ledger",
46
47
  "P2": "advisory",
47
48
  }
49
+ _FILE_ATTRIBUTE_REPARSE_POINT = getattr(stat, "FILE_ATTRIBUTE_REPARSE_POINT", 0x400)
48
50
 
49
51
 
50
52
  def _result_error(code: str, message: str) -> dict[str, Any]:
51
53
  return {"ok": False, "code": code, "error": message}
52
54
 
53
55
 
56
+ class PlanParseError(ValueError):
57
+ def __init__(self, code: str, message: str) -> None:
58
+ super().__init__(message)
59
+ self.code = code
60
+
61
+
54
62
  def _normalize_header(value: str) -> str:
55
63
  return re.sub(r"[\s_-]+", "", value).lower()
56
64
 
@@ -127,13 +135,23 @@ def parse_test_scenarios(scenarios_path: Path) -> list[dict[str, str]]:
127
135
  break
128
136
  cells = _table_cells(row)
129
137
  if max(id_index, scenario_index) >= len(cells):
130
- row_index += 1
131
- continue
138
+ raise PlanParseError(
139
+ "PLAN_SCENARIO_ROW_INVALID",
140
+ f"{scenarios_path.name}: line {row_index + 1} is missing scenario ID or description",
141
+ )
132
142
  complete_row = len(cells) == len(headers)
133
143
  scenario_id = cells[id_index].strip()
134
144
  if not scenario_id or set(scenario_id) <= {"-", ":"}:
135
- row_index += 1
136
- continue
145
+ raise PlanParseError(
146
+ "PLAN_SCENARIO_ROW_INVALID",
147
+ f"{scenarios_path.name}: line {row_index + 1} has an empty scenario ID",
148
+ )
149
+ scenario_text = cells[scenario_index].strip()
150
+ if not scenario_text or set(scenario_text) <= {"-", ":"}:
151
+ raise PlanParseError(
152
+ "PLAN_SCENARIO_ROW_INVALID",
153
+ f"{scenarios_path.name}: line {row_index + 1} has an empty scenario description",
154
+ )
137
155
  priority = (
138
156
  cells[priority_index].strip().upper()
139
157
  if priority_index is not None
@@ -144,7 +162,7 @@ def parse_test_scenarios(scenarios_path: Path) -> list[dict[str, str]]:
144
162
  scenario = {
145
163
  "id": scenario_id,
146
164
  "priority": priority,
147
- "scenario": cells[scenario_index].strip(),
165
+ "scenario": scenario_text,
148
166
  "ownerPhase": (
149
167
  cells[owner_phase_index].strip()
150
168
  if owner_phase_index is not None
@@ -219,19 +237,34 @@ def parse_plan_tasks(plan_path: Path) -> list[dict[str, str]]:
219
237
  if not row.startswith("|"):
220
238
  break
221
239
  cells = _table_cells(row)
222
- if len(cells) < len(headers):
223
- row_index += 1
224
- continue
240
+ if max(number_index, task_index) >= len(cells):
241
+ raise PlanParseError(
242
+ "PLAN_TASK_ROW_INVALID",
243
+ f"{plan_path.name}: line {row_index + 1} is missing task ID or description",
244
+ )
245
+ complete_row = len(cells) == len(headers)
225
246
  number = cells[number_index].strip()
226
247
  task_text = cells[task_index].strip()
227
- if not number or not task_text or set(number) <= {"-", ":"}:
228
- row_index += 1
229
- continue
248
+ if (
249
+ not number
250
+ or not task_text
251
+ or set(number) <= {"-", ":"}
252
+ or set(task_text) <= {"-", ":"}
253
+ ):
254
+ raise PlanParseError(
255
+ "PLAN_TASK_ROW_INVALID",
256
+ f"{plan_path.name}: line {row_index + 1} has an empty task ID or description",
257
+ )
230
258
  task: dict[str, str] = {"num": number, "task": task_text}
231
259
  if cluster_index is not None and cells[cluster_index].strip():
232
260
  task["cluster"] = cells[cluster_index].strip()
233
261
  for name, index in optional_indices.items():
234
- if index is not None and cells[index].strip():
262
+ if (
263
+ complete_row
264
+ and index is not None
265
+ and index < len(cells)
266
+ and cells[index].strip()
267
+ ):
235
268
  task[name] = cells[index].strip()
236
269
  tasks.append(task)
237
270
  row_index += 1
@@ -271,6 +304,28 @@ def _frontmatter(text: str) -> dict[str, str] | None:
271
304
  return None
272
305
 
273
306
 
307
+ def _required_artifact_names(change_name: str) -> set[str]:
308
+ return {
309
+ f"spec/{change_name}-design.md",
310
+ f"plans/{change_name}-plan.md",
311
+ f"plans/{change_name}-implementation-detail.md",
312
+ f"plans/{change_name}-test-scenarios.md",
313
+ "meta/gate-policy.json",
314
+ "meta/worktree.json",
315
+ }
316
+
317
+
318
+ def _is_link_or_reparse(path: Path) -> bool:
319
+ """Detect symlinks and Windows reparse points on every supported Python."""
320
+ try:
321
+ if path.is_symlink():
322
+ return True
323
+ attributes = getattr(os.lstat(path), "st_file_attributes", 0)
324
+ except OSError:
325
+ return False
326
+ return bool(attributes & _FILE_ATTRIBUTE_REPARSE_POINT)
327
+
328
+
274
329
  def lint_slice_plan(plan_path: Path) -> dict[str, Any]:
275
330
  """Validate the identity, reuse, and storage contract for a slice plan."""
276
331
  text = Path(plan_path).read_text(encoding="utf-8-sig")
@@ -338,7 +393,7 @@ def lint_slice_plan(plan_path: Path) -> dict[str, Any]:
338
393
  def _artifact_files(staging: Path) -> list[Path]:
339
394
  files: list[Path] = []
340
395
  for path in staging.rglob("*"):
341
- if path.is_symlink():
396
+ if _is_link_or_reparse(path):
342
397
  raise ValueError(f"PLAN_ARTIFACT_SYMLINK: {path}")
343
398
  if path.is_file():
344
399
  files.append(path)
@@ -347,14 +402,7 @@ def _artifact_files(staging: Path) -> list[Path]:
347
402
 
348
403
  def validate_staging(staging: Path, change_name: str) -> dict[str, Any]:
349
404
  staging = staging.resolve()
350
- required = {
351
- Path("spec") / f"{change_name}-design.md",
352
- Path("plans") / f"{change_name}-plan.md",
353
- Path("plans") / f"{change_name}-implementation-detail.md",
354
- Path("plans") / f"{change_name}-test-scenarios.md",
355
- Path("meta") / "gate-policy.json",
356
- Path("meta") / "worktree.json",
357
- }
405
+ required = {Path(name) for name in _required_artifact_names(change_name)}
358
406
  try:
359
407
  files = _artifact_files(staging)
360
408
  except ValueError as exc:
@@ -416,7 +464,10 @@ def validate_staging(staging: Path, change_name: str) -> dict[str, Any]:
416
464
 
417
465
  # C8: validate ownerPhase values in plan.md task table.
418
466
  plan_path = staging / "plans" / f"{change_name}-plan.md"
419
- tasks = parse_plan_tasks(plan_path)
467
+ try:
468
+ tasks = parse_plan_tasks(plan_path)
469
+ except PlanParseError as exc:
470
+ return _result_error(exc.code, str(exc))
420
471
  if not tasks:
421
472
  return _result_error(
422
473
  "PLAN_TASKS_EMPTY",
@@ -444,7 +495,10 @@ def validate_staging(staging: Path, change_name: str) -> dict[str, Any]:
444
495
 
445
496
  # C9: parse test-scenarios.md for scenario manifest.
446
497
  scenarios_path = staging / "plans" / f"{change_name}-test-scenarios.md"
447
- scenarios = parse_test_scenarios(scenarios_path)
498
+ try:
499
+ scenarios = parse_test_scenarios(scenarios_path)
500
+ except PlanParseError as exc:
501
+ return _result_error(exc.code, str(exc))
448
502
  if not scenarios:
449
503
  return _result_error(
450
504
  "PLAN_SCENARIOS_EMPTY",
@@ -542,6 +596,64 @@ def _validate_plan_start(
542
596
  return {"ok": True, "phaseStartCount": 1}
543
597
 
544
598
 
599
+ def _receipt_artifact_targets(
600
+ change_dir: Path,
601
+ files_list: list[Any],
602
+ ) -> tuple[list[tuple[str, Path]] | None, dict[str, Any] | None]:
603
+ targets: list[tuple[str, Path]] = []
604
+ seen: set[str] = set()
605
+ for index, value in enumerate(files_list):
606
+ if not isinstance(value, str):
607
+ return None, _result_error(
608
+ "RECEIPT_FILE_PATH_INVALID",
609
+ f"receipt files[{index}] must be a string",
610
+ )
611
+ raw = value
612
+ segments = raw.split("/")
613
+ rel = PurePosixPath(raw)
614
+ invalid = (
615
+ not raw
616
+ or raw != raw.strip()
617
+ or "\\" in raw
618
+ or ":" in raw
619
+ or rel.is_absolute()
620
+ or any(segment in {"", ".", ".."} for segment in segments)
621
+ or any(segment.endswith((".", " ")) for segment in segments)
622
+ or not rel.parts
623
+ or rel.parts[0] not in {"spec", "plans", "meta"}
624
+ )
625
+ if invalid:
626
+ return None, _result_error(
627
+ "RECEIPT_FILE_PATH_INVALID",
628
+ f"receipt files[{index}] is not a safe artifact-relative path: {raw!r}",
629
+ )
630
+ normalized = rel.as_posix()
631
+ if normalized in seen:
632
+ return None, _result_error(
633
+ "RECEIPT_FILE_PATH_INVALID",
634
+ f"receipt contains duplicate artifact path: {normalized}",
635
+ )
636
+ seen.add(normalized)
637
+ target = change_dir.joinpath(*rel.parts)
638
+ cursor = change_dir
639
+ for part in rel.parts:
640
+ cursor = cursor / part
641
+ if _is_link_or_reparse(cursor):
642
+ return None, _result_error(
643
+ "RECEIPT_FILE_PATH_INVALID",
644
+ f"receipt artifact path traverses a link: {normalized}",
645
+ )
646
+ try:
647
+ target.resolve(strict=False).relative_to(change_dir)
648
+ except (OSError, RuntimeError, ValueError):
649
+ return None, _result_error(
650
+ "RECEIPT_FILE_PATH_INVALID",
651
+ f"receipt artifact path resolves outside the change directory: {normalized}",
652
+ )
653
+ targets.append((normalized, target))
654
+ return targets, None
655
+
656
+
545
657
  def verify_plan(change_dir: Path) -> dict[str, Any]:
546
658
  """Read-only verification of a finalized plan (retro §5.8).
547
659
 
@@ -565,6 +677,11 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
565
677
  change_name = str(receipt.get("changeName") or "").strip()
566
678
  if not change_name:
567
679
  return _result_error("RECEIPT_INVALID", "receipt missing changeName")
680
+ if change_name != change_dir.name:
681
+ return _result_error(
682
+ "RECEIPT_CHANGE_NAME_INVALID",
683
+ f"receipt changeName {change_name!r} does not match {change_dir.name!r}",
684
+ )
568
685
 
569
686
  expected_hash = str(receipt.get("artifactsHash") or "").strip()
570
687
  if not expected_hash.startswith("sha256:"):
@@ -573,6 +690,19 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
573
690
  files_list = receipt.get("files")
574
691
  if not isinstance(files_list, list) or not files_list:
575
692
  return _result_error("RECEIPT_INVALID", "receipt files list missing or empty")
693
+ artifact_targets, path_error = _receipt_artifact_targets(change_dir, files_list)
694
+ if path_error is not None:
695
+ return path_error
696
+ assert artifact_targets is not None
697
+ artifact_name_set = {rel for rel, _ in artifact_targets}
698
+ missing_required = sorted(
699
+ _required_artifact_names(change_name) - artifact_name_set
700
+ )
701
+ if missing_required:
702
+ return _result_error(
703
+ "RECEIPT_FILES_INCOMPLETE",
704
+ "receipt omits required artifacts: " + ", ".join(missing_required),
705
+ )
576
706
  if receipt.get("status") != "finalized":
577
707
  return _result_error(
578
708
  "RECEIPT_NOT_FINALIZED",
@@ -589,9 +719,7 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
589
719
  # Recompute artifacts hash from published files.
590
720
  digest = hashlib.sha256()
591
721
  artifact_names: list[str] = []
592
- for rel_text in files_list:
593
- rel = rel_text.as_posix() if hasattr(rel_text, "as_posix") else str(rel_text)
594
- target = change_dir / rel
722
+ for rel, target in artifact_targets:
595
723
  if not target.is_file():
596
724
  return _result_error(
597
725
  "ARTIFACT_MISSING", f"published artifact missing: {rel}"
@@ -634,7 +762,10 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
634
762
  }
635
763
 
636
764
  plan_path = change_dir / "plans" / f"{change_name}-plan.md"
637
- expected_tasks = parse_plan_tasks(plan_path)
765
+ try:
766
+ expected_tasks = parse_plan_tasks(plan_path)
767
+ except PlanParseError as exc:
768
+ return _result_error(exc.code, str(exc))
638
769
  if not expected_tasks:
639
770
  return _result_error(
640
771
  "PLAN_TASKS_EMPTY",
@@ -652,24 +783,25 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
652
783
  )
653
784
  except (OSError, json.JSONDecodeError) as exc:
654
785
  return _result_error("IMPLEMENTATION_CHECKPOINTS_INVALID", str(exc))
655
- actual_tasks = checkpoints.get("tasks") if isinstance(checkpoints, dict) else None
656
- expected_task_ids = [str(item.get("num") or "") for item in expected_tasks]
657
- actual_task_ids = (
658
- [str(item.get("num") or "") for item in actual_tasks if isinstance(item, dict)]
659
- if isinstance(actual_tasks, list)
660
- else []
661
- )
662
- if expected_task_ids != actual_task_ids:
786
+ expected_checkpoints = {
787
+ "schemaVersion": 1,
788
+ "changeName": change_name,
789
+ "tasks": expected_tasks,
790
+ "foundationGate": "approved",
791
+ }
792
+ if checkpoints != expected_checkpoints:
663
793
  return _result_error(
664
794
  "IMPLEMENTATION_CHECKPOINTS_DRIFT",
665
- "derived task IDs do not match the finalized plan: "
666
- f"expected={expected_task_ids}, actual={actual_task_ids}",
795
+ "derived implementation checkpoints do not match the finalized plan",
667
796
  )
668
797
 
669
798
  scenarios_path = (
670
799
  change_dir / "plans" / f"{change_name}-test-scenarios.md"
671
800
  )
672
- expected_scenarios = parse_test_scenarios(scenarios_path)
801
+ try:
802
+ expected_scenarios = parse_test_scenarios(scenarios_path)
803
+ except PlanParseError as exc:
804
+ return _result_error(exc.code, str(exc))
673
805
  if not expected_scenarios:
674
806
  return _result_error(
675
807
  "PLAN_SCENARIOS_EMPTY",
@@ -694,26 +826,15 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
694
826
  "scenario-manifest.json must contain at least one scenario",
695
827
  )
696
828
 
697
- def scenario_identity(item: dict[str, Any]) -> tuple[str, str, str, str]:
698
- return (
699
- str(item.get("id") or ""),
700
- str(item.get("priority") or ""),
701
- str(item.get("ownerPhase") or ""),
702
- str(item.get("requiredEvidenceKind") or ""),
703
- )
704
-
705
- expected_scenario_identities = [
706
- scenario_identity(item) for item in expected_scenarios
707
- ]
708
- actual_scenario_identities = [
709
- scenario_identity(item)
710
- for item in actual_scenarios
711
- if isinstance(item, dict)
712
- ]
713
- if expected_scenario_identities != actual_scenario_identities:
829
+ expected_manifest = {
830
+ "schemaVersion": 1,
831
+ "changeName": change_name,
832
+ "scenarios": expected_scenarios,
833
+ }
834
+ if manifest != expected_manifest:
714
835
  return _result_error(
715
836
  "SCENARIO_MANIFEST_DRIFT",
716
- "derived scenario identities do not match the finalized scenario table",
837
+ "derived scenario manifest does not match the finalized scenario table",
717
838
  )
718
839
 
719
840
  # Validate gate-policy.json is parseable JSON.
@@ -730,7 +851,7 @@ def verify_plan(change_dir: Path) -> dict[str, Any]:
730
851
  gate_policy_consistent = True
731
852
 
732
853
  # Validate events.ndjson: require one matching start/end lifecycle.
733
- events_path = change_dir / "events.ndjson"
854
+ events_path = harness_events.events_path(change_dir)
734
855
  phase_start_count = 0
735
856
  phase_end_count = 0
736
857
  phase_end_status: str | None = None
@@ -88,7 +88,7 @@ change-name 范围变更 → 提示重命名或记 🟡WARN(→ `reference.md`
88
88
  |------|------|
89
89
  | 产物路径 | 只写 `.harness/changes/<cn>/`;禁止 superpowers 输入 |
90
90
  | 设计审批包 | 一次 blocking user confirmation 含 worktree(读 `harness.json` `defaultWorktree`) |
91
- | 阶段 8 | spec/plan/detail/scenarios/worktree.json 先进入 staging;仅 finalizer 校验成功后发布并写唯一 `phase.end`/log;随后 `verify` 必须确认 start/end、收据哈希、全部任务表和非空场景清单一致,失败不得手工补终态 |
91
+ | 阶段 8 | spec/plan/detail/scenarios/gate-policy/worktree 六项标准产物先进入 staging;仅 finalizer 校验成功后发布并写唯一 `phase.end`/log;随后 `verify` 必须确认 start/end、收据完整覆盖六项标准产物、哈希、全部任务表和非空场景清单一致,失败不得手工补终态 |
92
92
  | Plan 结束 | **禁止**询问执行模式;只提示 `/harness-run` |
93
93
  | 知识查询 | 0.5 失败不得假装已读历史 |
94
94
  | 歧义优先检查 | 否定、对比、动作对象或范围存在多种合理解释时,最小取证后先给推荐理解并一次一问;确认前不深挖错误方向 |
@@ -214,6 +214,7 @@ source: harness-plan
214
214
  - [ ] finalizer 返回 `ok=true` 与 `artifactsHash`;重复执行返回 `idempotent=true`
215
215
  - [ ] 紧接着执行 `harness_plan_finalize.py verify --change-dir ... --json`
216
216
  - [ ] verify 返回 `phaseStartCount=1`、`phaseEndCount=1`、`phaseEndStatus=OK`、`receiptConsistent=true`
217
+ - [ ] 收据 `files` 完整包含 design / plan / implementation-detail / test-scenarios / gate-policy / worktree 六项标准产物;不得省略、重复或经 symlink/junction/reparse point 引用
217
218
  - [ ] verify 的 `taskCount` 等于全部任务表行数,`scenarioCount` 等于 Markdown 中全部唯一场景 ID 数;任一为 0 或不一致即 ❌FAIL
218
219
  - [ ] finalizer 失败时正式目录无半发布产物、无成功 `phase.end`、无伪造 execution log
219
220
  - [ ] 禁止在 finalizer 之前手工追加成功 `phase.end`
@@ -224,6 +225,7 @@ source: harness-plan
224
225
  | `.harness/changes/<change>/plans/<change>-plan.md` | ✅ | □ |
225
226
  | `.harness/changes/<change>/plans/<change>-implementation-detail.md` | ✅ | □ |
226
227
  | `.harness/changes/<change>/plans/<change>-test-scenarios.md` | ✅ | □ |
228
+ | `.harness/changes/<change>/meta/gate-policy.json` | ✅ | □ |
227
229
  | `.harness/changes/<change>/meta/worktree.json` | ✅ | □ |
228
230
  | `.harness/changes/<change>/meta/implementation-checkpoints.json` | ✅ | □ |
229
231
  | `.harness/changes/<change>/meta/scenario-manifest.json`(非空且计数一致) | ✅ | □ |
@@ -335,10 +335,16 @@ status: approved
335
335
  | `.harness/changes/<change>/plans/<change>-plan.md` | ✅ |
336
336
  | `.harness/changes/<change>/plans/<change>-implementation-detail.md` | ✅ |
337
337
  | `.harness/changes/<change>/plans/<change>-test-scenarios.md` | ✅ |
338
+ | `.harness/changes/<change>/meta/gate-policy.json` | ✅ |
338
339
  | `.harness/changes/<change>/meta/worktree.json` | ✅ |
340
+ | `.harness/changes/<change>/meta/implementation-checkpoints.json` | ✅ |
341
+ | `.harness/changes/<change>/meta/scenario-manifest.json` | ✅ |
342
+ | `.harness/changes/<change>/meta/plan-finalization.json` | ✅ |
339
343
  | `.harness/changes/<change>/logs/execution-log.md` | ✅ |
340
344
  | `.harness/changes/<change>/events.ndjson` | ✅ |
341
345
 
346
+ `plan-finalization.json.files` 必须完整列出 design、plan、implementation-detail、test-scenarios、gate-policy、worktree 六项标准输入。`verify` 对缺项、重复项、越界路径以及 symlink/junction/reparse point 一律 fail-closed;不得通过删减收据文件集后重算哈希来绕过完整性检查。
347
+
342
348
  ### Plan 结束行为规则
343
349
 
344
350
  - **禁止询问执行模式**:Subagent-Driven / Inline Execution 属于 /harness-run 阶段
@@ -1635,31 +1635,27 @@ def _validate_scenario_coverage(change_dir: Path) -> dict[str, Any]:
1635
1635
  for s in scenarios
1636
1636
  if isinstance(s, dict)
1637
1637
  and (
1638
- s.get("requiredEvidenceKind") == "ledger"
1639
- or (
1640
- not s.get("requiredEvidenceKind")
1641
- and str(s.get("priority", "")).upper() in {"P0", "P1"}
1642
- )
1638
+ str(s.get("priority", "")).upper() in {"P0", "P1"}
1639
+ or s.get("requiredEvidenceKind") == "ledger"
1643
1640
  )
1644
1641
  }
1645
1642
  if not required_ids:
1646
1643
  return {"ok": True, "code": "NO_LEDGER_REQUIRED_SCENARIOS"}
1647
1644
 
1648
- ledger_path = change_dir / "evidence" / "verification-ledger.json"
1649
- if not ledger_path.is_file():
1645
+ try:
1646
+ ledger, ledger_path = hl.load_ledger(change_dir)
1647
+ except (OSError, ValueError, json.JSONDecodeError) as exc:
1650
1648
  return {
1651
1649
  "ok": False,
1652
1650
  "code": "SCENARIO_COVERAGE_FAILED",
1653
- "message": "ledger missing; cannot verify required scenario coverage",
1651
+ "message": f"ledger unreadable: {exc}",
1654
1652
  "missing": sorted(required_ids),
1655
1653
  }
1656
- try:
1657
- ledger = json.loads(ledger_path.read_text(encoding="utf-8-sig"))
1658
- except (OSError, json.JSONDecodeError) as exc:
1654
+ if ledger is None or ledger_path is None:
1659
1655
  return {
1660
1656
  "ok": False,
1661
1657
  "code": "SCENARIO_COVERAGE_FAILED",
1662
- "message": f"ledger unreadable: {exc}",
1658
+ "message": "ledger missing; cannot verify required scenario coverage",
1663
1659
  "missing": sorted(required_ids),
1664
1660
  }
1665
1661
  covered: set[str] = set()
@@ -1728,13 +1724,6 @@ def cmd_begin(args: argparse.Namespace) -> int:
1728
1724
  or plan_verification.get("message")
1729
1725
  or "finalized plan verification failed"
1730
1726
  )
1731
- record_blocked_attempt(
1732
- change_dir,
1733
- phase=args.phase,
1734
- code=code,
1735
- message=message,
1736
- run_id=args.run_id or os.environ.get("HUNTER_HARNESS_RUN_ID"),
1737
- )
1738
1727
  return emit_error(
1739
1728
  code,
1740
1729
  message,