@hunter-harness/workflow-harness 0.2.60 → 0.2.62

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 (218) hide show
  1. package/harness/bundles/general/claude-code/.harness-build.json +1 -1
  2. package/harness/bundles/general/claude-code/README.md +7 -7
  3. package/harness/bundles/general/claude-code/harness-archive/SKILL.md +35 -35
  4. package/harness/bundles/general/claude-code/harness-archive/checklist.md +5 -2
  5. package/harness/bundles/general/claude-code/harness-archive/reference.md +23 -7
  6. package/harness/bundles/general/claude-code/harness-codebase-map/SKILL.md +1 -1
  7. package/harness/bundles/general/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  8. package/harness/bundles/general/claude-code/harness-knowledge-query/SKILL.md +1 -1
  9. package/harness/bundles/general/claude-code/harness-plan/SKILL.md +4 -4
  10. package/harness/bundles/general/claude-code/harness-review/SKILL.md +2 -2
  11. package/harness/bundles/general/claude-code/harness-run/SKILL.md +2 -2
  12. package/harness/bundles/general/claude-code/harness-submit/SKILL.md +2 -2
  13. package/harness/bundles/general/claude-code/harness-sync/SKILL.md +1 -1
  14. package/harness/bundles/general/claude-code/harness-test/SKILL.md +2 -2
  15. package/harness/bundles/general/claude-code/protocols/archive-report-protocol.md +7 -3
  16. package/harness/bundles/general/claude-code/protocols/ledger-protocol.md +1 -1
  17. package/harness/bundles/general/claude-code/protocols/report-pipeline-protocol.md +6 -4
  18. package/harness/bundles/general/claude-code/protocols/state-layout-protocol.md +3 -2
  19. package/harness/bundles/general/claude-code/scripts/harness_archive.py +829 -68
  20. package/harness/bundles/general/claude-code/scripts/harness_context.py +8 -2
  21. package/harness/bundles/general/claude-code/scripts/harness_events.py +5 -0
  22. package/harness/bundles/general/claude-code/scripts/harness_events_sync.py +191 -26
  23. package/harness/bundles/general/claude-code/scripts/harness_ledger.py +79 -2
  24. package/harness/bundles/general/claude-code/scripts/harness_profile.py +7 -0
  25. package/harness/bundles/general/claude-code/scripts/harness_state.py +22 -3
  26. package/harness/bundles/general/codebuddy/.harness-build.json +1 -1
  27. package/harness/bundles/general/codebuddy/README.md +7 -7
  28. package/harness/bundles/general/codebuddy/harness-archive/SKILL.md +35 -35
  29. package/harness/bundles/general/codebuddy/harness-archive/checklist.md +5 -2
  30. package/harness/bundles/general/codebuddy/harness-archive/reference.md +23 -7
  31. package/harness/bundles/general/codebuddy/harness-codebase-map/SKILL.md +1 -1
  32. package/harness/bundles/general/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  33. package/harness/bundles/general/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  34. package/harness/bundles/general/codebuddy/harness-plan/SKILL.md +4 -4
  35. package/harness/bundles/general/codebuddy/harness-review/SKILL.md +2 -2
  36. package/harness/bundles/general/codebuddy/harness-run/SKILL.md +2 -2
  37. package/harness/bundles/general/codebuddy/harness-submit/SKILL.md +2 -2
  38. package/harness/bundles/general/codebuddy/harness-sync/SKILL.md +1 -1
  39. package/harness/bundles/general/codebuddy/harness-test/SKILL.md +2 -2
  40. package/harness/bundles/general/codebuddy/protocols/archive-report-protocol.md +7 -3
  41. package/harness/bundles/general/codebuddy/protocols/ledger-protocol.md +1 -1
  42. package/harness/bundles/general/codebuddy/protocols/report-pipeline-protocol.md +6 -4
  43. package/harness/bundles/general/codebuddy/protocols/state-layout-protocol.md +3 -2
  44. package/harness/bundles/general/codebuddy/scripts/harness_archive.py +829 -68
  45. package/harness/bundles/general/codebuddy/scripts/harness_context.py +8 -2
  46. package/harness/bundles/general/codebuddy/scripts/harness_events.py +5 -0
  47. package/harness/bundles/general/codebuddy/scripts/harness_events_sync.py +191 -26
  48. package/harness/bundles/general/codebuddy/scripts/harness_ledger.py +79 -2
  49. package/harness/bundles/general/codebuddy/scripts/harness_profile.py +7 -0
  50. package/harness/bundles/general/codebuddy/scripts/harness_state.py +22 -3
  51. package/harness/bundles/general/codex/.harness-build.json +1 -1
  52. package/harness/bundles/general/codex/README.md +7 -7
  53. package/harness/bundles/general/codex/harness-archive/SKILL.md +35 -35
  54. package/harness/bundles/general/codex/harness-archive/checklist.md +5 -2
  55. package/harness/bundles/general/codex/harness-archive/reference.md +23 -7
  56. package/harness/bundles/general/codex/harness-codebase-map/SKILL.md +1 -1
  57. package/harness/bundles/general/codex/harness-knowledge-ingest/SKILL.md +1 -1
  58. package/harness/bundles/general/codex/harness-knowledge-query/SKILL.md +1 -1
  59. package/harness/bundles/general/codex/harness-plan/SKILL.md +4 -4
  60. package/harness/bundles/general/codex/harness-review/SKILL.md +2 -2
  61. package/harness/bundles/general/codex/harness-run/SKILL.md +2 -2
  62. package/harness/bundles/general/codex/harness-submit/SKILL.md +2 -2
  63. package/harness/bundles/general/codex/harness-sync/SKILL.md +1 -1
  64. package/harness/bundles/general/codex/harness-test/SKILL.md +2 -2
  65. package/harness/bundles/general/codex/protocols/archive-report-protocol.md +7 -3
  66. package/harness/bundles/general/codex/protocols/ledger-protocol.md +1 -1
  67. package/harness/bundles/general/codex/protocols/report-pipeline-protocol.md +6 -4
  68. package/harness/bundles/general/codex/protocols/state-layout-protocol.md +3 -2
  69. package/harness/bundles/general/codex/scripts/harness_archive.py +829 -68
  70. package/harness/bundles/general/codex/scripts/harness_context.py +8 -2
  71. package/harness/bundles/general/codex/scripts/harness_events.py +5 -0
  72. package/harness/bundles/general/codex/scripts/harness_events_sync.py +191 -26
  73. package/harness/bundles/general/codex/scripts/harness_ledger.py +79 -2
  74. package/harness/bundles/general/codex/scripts/harness_profile.py +7 -0
  75. package/harness/bundles/general/codex/scripts/harness_state.py +22 -3
  76. package/harness/bundles/general/cursor/.harness-build.json +1 -1
  77. package/harness/bundles/general/cursor/README.md +7 -7
  78. package/harness/bundles/general/cursor/harness-archive/SKILL.md +35 -35
  79. package/harness/bundles/general/cursor/harness-archive/checklist.md +5 -2
  80. package/harness/bundles/general/cursor/harness-archive/reference.md +23 -7
  81. package/harness/bundles/general/cursor/harness-codebase-map/SKILL.md +1 -1
  82. package/harness/bundles/general/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  83. package/harness/bundles/general/cursor/harness-knowledge-query/SKILL.md +1 -1
  84. package/harness/bundles/general/cursor/harness-plan/SKILL.md +4 -4
  85. package/harness/bundles/general/cursor/harness-review/SKILL.md +2 -2
  86. package/harness/bundles/general/cursor/harness-run/SKILL.md +2 -2
  87. package/harness/bundles/general/cursor/harness-submit/SKILL.md +2 -2
  88. package/harness/bundles/general/cursor/harness-sync/SKILL.md +1 -1
  89. package/harness/bundles/general/cursor/harness-test/SKILL.md +2 -2
  90. package/harness/bundles/general/cursor/protocols/archive-report-protocol.md +7 -3
  91. package/harness/bundles/general/cursor/protocols/ledger-protocol.md +1 -1
  92. package/harness/bundles/general/cursor/protocols/report-pipeline-protocol.md +6 -4
  93. package/harness/bundles/general/cursor/protocols/state-layout-protocol.md +3 -2
  94. package/harness/bundles/general/cursor/scripts/harness_archive.py +829 -68
  95. package/harness/bundles/general/cursor/scripts/harness_context.py +8 -2
  96. package/harness/bundles/general/cursor/scripts/harness_events.py +5 -0
  97. package/harness/bundles/general/cursor/scripts/harness_events_sync.py +191 -26
  98. package/harness/bundles/general/cursor/scripts/harness_ledger.py +79 -2
  99. package/harness/bundles/general/cursor/scripts/harness_profile.py +7 -0
  100. package/harness/bundles/general/cursor/scripts/harness_state.py +22 -3
  101. package/harness/bundles/java/claude-code/.harness-build.json +1 -1
  102. package/harness/bundles/java/claude-code/README.md +7 -7
  103. package/harness/bundles/java/claude-code/harness-apidoc/SKILL.md +2 -2
  104. package/harness/bundles/java/claude-code/harness-archive/SKILL.md +35 -35
  105. package/harness/bundles/java/claude-code/harness-archive/checklist.md +5 -2
  106. package/harness/bundles/java/claude-code/harness-archive/reference.md +23 -7
  107. package/harness/bundles/java/claude-code/harness-codebase-map/SKILL.md +1 -1
  108. package/harness/bundles/java/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  109. package/harness/bundles/java/claude-code/harness-knowledge-query/SKILL.md +1 -1
  110. package/harness/bundles/java/claude-code/harness-package/SKILL.md +2 -2
  111. package/harness/bundles/java/claude-code/harness-plan/SKILL.md +4 -4
  112. package/harness/bundles/java/claude-code/harness-review/SKILL.md +2 -2
  113. package/harness/bundles/java/claude-code/harness-run/SKILL.md +2 -2
  114. package/harness/bundles/java/claude-code/harness-submit/SKILL.md +2 -2
  115. package/harness/bundles/java/claude-code/harness-sync/SKILL.md +1 -1
  116. package/harness/bundles/java/claude-code/harness-test/SKILL.md +2 -2
  117. package/harness/bundles/java/claude-code/protocols/archive-report-protocol.md +7 -3
  118. package/harness/bundles/java/claude-code/protocols/ledger-protocol.md +1 -1
  119. package/harness/bundles/java/claude-code/protocols/report-pipeline-protocol.md +6 -4
  120. package/harness/bundles/java/claude-code/protocols/state-layout-protocol.md +3 -2
  121. package/harness/bundles/java/claude-code/scripts/harness_archive.py +829 -68
  122. package/harness/bundles/java/claude-code/scripts/harness_context.py +8 -2
  123. package/harness/bundles/java/claude-code/scripts/harness_events.py +5 -0
  124. package/harness/bundles/java/claude-code/scripts/harness_events_sync.py +191 -26
  125. package/harness/bundles/java/claude-code/scripts/harness_ledger.py +79 -2
  126. package/harness/bundles/java/claude-code/scripts/harness_profile.py +7 -0
  127. package/harness/bundles/java/claude-code/scripts/harness_state.py +22 -3
  128. package/harness/bundles/java/codebuddy/.harness-build.json +1 -1
  129. package/harness/bundles/java/codebuddy/README.md +7 -7
  130. package/harness/bundles/java/codebuddy/harness-apidoc/SKILL.md +2 -2
  131. package/harness/bundles/java/codebuddy/harness-archive/SKILL.md +35 -35
  132. package/harness/bundles/java/codebuddy/harness-archive/checklist.md +5 -2
  133. package/harness/bundles/java/codebuddy/harness-archive/reference.md +23 -7
  134. package/harness/bundles/java/codebuddy/harness-codebase-map/SKILL.md +1 -1
  135. package/harness/bundles/java/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  136. package/harness/bundles/java/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  137. package/harness/bundles/java/codebuddy/harness-package/SKILL.md +2 -2
  138. package/harness/bundles/java/codebuddy/harness-plan/SKILL.md +4 -4
  139. package/harness/bundles/java/codebuddy/harness-review/SKILL.md +2 -2
  140. package/harness/bundles/java/codebuddy/harness-run/SKILL.md +2 -2
  141. package/harness/bundles/java/codebuddy/harness-submit/SKILL.md +2 -2
  142. package/harness/bundles/java/codebuddy/harness-sync/SKILL.md +1 -1
  143. package/harness/bundles/java/codebuddy/harness-test/SKILL.md +2 -2
  144. package/harness/bundles/java/codebuddy/protocols/archive-report-protocol.md +7 -3
  145. package/harness/bundles/java/codebuddy/protocols/ledger-protocol.md +1 -1
  146. package/harness/bundles/java/codebuddy/protocols/report-pipeline-protocol.md +6 -4
  147. package/harness/bundles/java/codebuddy/protocols/state-layout-protocol.md +3 -2
  148. package/harness/bundles/java/codebuddy/scripts/harness_archive.py +829 -68
  149. package/harness/bundles/java/codebuddy/scripts/harness_context.py +8 -2
  150. package/harness/bundles/java/codebuddy/scripts/harness_events.py +5 -0
  151. package/harness/bundles/java/codebuddy/scripts/harness_events_sync.py +191 -26
  152. package/harness/bundles/java/codebuddy/scripts/harness_ledger.py +79 -2
  153. package/harness/bundles/java/codebuddy/scripts/harness_profile.py +7 -0
  154. package/harness/bundles/java/codebuddy/scripts/harness_state.py +22 -3
  155. package/harness/bundles/java/codex/.harness-build.json +1 -1
  156. package/harness/bundles/java/codex/README.md +7 -7
  157. package/harness/bundles/java/codex/harness-apidoc/SKILL.md +2 -2
  158. package/harness/bundles/java/codex/harness-archive/SKILL.md +35 -35
  159. package/harness/bundles/java/codex/harness-archive/checklist.md +5 -2
  160. package/harness/bundles/java/codex/harness-archive/reference.md +23 -7
  161. package/harness/bundles/java/codex/harness-codebase-map/SKILL.md +1 -1
  162. package/harness/bundles/java/codex/harness-knowledge-ingest/SKILL.md +1 -1
  163. package/harness/bundles/java/codex/harness-knowledge-query/SKILL.md +1 -1
  164. package/harness/bundles/java/codex/harness-package/SKILL.md +2 -2
  165. package/harness/bundles/java/codex/harness-plan/SKILL.md +4 -4
  166. package/harness/bundles/java/codex/harness-review/SKILL.md +2 -2
  167. package/harness/bundles/java/codex/harness-run/SKILL.md +2 -2
  168. package/harness/bundles/java/codex/harness-submit/SKILL.md +2 -2
  169. package/harness/bundles/java/codex/harness-sync/SKILL.md +1 -1
  170. package/harness/bundles/java/codex/harness-test/SKILL.md +2 -2
  171. package/harness/bundles/java/codex/protocols/archive-report-protocol.md +7 -3
  172. package/harness/bundles/java/codex/protocols/ledger-protocol.md +1 -1
  173. package/harness/bundles/java/codex/protocols/report-pipeline-protocol.md +6 -4
  174. package/harness/bundles/java/codex/protocols/state-layout-protocol.md +3 -2
  175. package/harness/bundles/java/codex/scripts/harness_archive.py +829 -68
  176. package/harness/bundles/java/codex/scripts/harness_context.py +8 -2
  177. package/harness/bundles/java/codex/scripts/harness_events.py +5 -0
  178. package/harness/bundles/java/codex/scripts/harness_events_sync.py +191 -26
  179. package/harness/bundles/java/codex/scripts/harness_ledger.py +79 -2
  180. package/harness/bundles/java/codex/scripts/harness_profile.py +7 -0
  181. package/harness/bundles/java/codex/scripts/harness_state.py +22 -3
  182. package/harness/bundles/java/cursor/.harness-build.json +1 -1
  183. package/harness/bundles/java/cursor/README.md +7 -7
  184. package/harness/bundles/java/cursor/harness-apidoc/SKILL.md +2 -2
  185. package/harness/bundles/java/cursor/harness-archive/SKILL.md +35 -35
  186. package/harness/bundles/java/cursor/harness-archive/checklist.md +5 -2
  187. package/harness/bundles/java/cursor/harness-archive/reference.md +23 -7
  188. package/harness/bundles/java/cursor/harness-codebase-map/SKILL.md +1 -1
  189. package/harness/bundles/java/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  190. package/harness/bundles/java/cursor/harness-knowledge-query/SKILL.md +1 -1
  191. package/harness/bundles/java/cursor/harness-package/SKILL.md +2 -2
  192. package/harness/bundles/java/cursor/harness-plan/SKILL.md +4 -4
  193. package/harness/bundles/java/cursor/harness-review/SKILL.md +2 -2
  194. package/harness/bundles/java/cursor/harness-run/SKILL.md +2 -2
  195. package/harness/bundles/java/cursor/harness-submit/SKILL.md +2 -2
  196. package/harness/bundles/java/cursor/harness-sync/SKILL.md +1 -1
  197. package/harness/bundles/java/cursor/harness-test/SKILL.md +2 -2
  198. package/harness/bundles/java/cursor/protocols/archive-report-protocol.md +7 -3
  199. package/harness/bundles/java/cursor/protocols/ledger-protocol.md +1 -1
  200. package/harness/bundles/java/cursor/protocols/report-pipeline-protocol.md +6 -4
  201. package/harness/bundles/java/cursor/protocols/state-layout-protocol.md +3 -2
  202. package/harness/bundles/java/cursor/scripts/harness_archive.py +829 -68
  203. package/harness/bundles/java/cursor/scripts/harness_context.py +8 -2
  204. package/harness/bundles/java/cursor/scripts/harness_events.py +5 -0
  205. package/harness/bundles/java/cursor/scripts/harness_events_sync.py +191 -26
  206. package/harness/bundles/java/cursor/scripts/harness_ledger.py +79 -2
  207. package/harness/bundles/java/cursor/scripts/harness_profile.py +7 -0
  208. package/harness/bundles/java/cursor/scripts/harness_state.py +22 -3
  209. package/harness/manifests/general/claude-code.json +27 -27
  210. package/harness/manifests/general/codebuddy.json +27 -27
  211. package/harness/manifests/general/codex.json +27 -27
  212. package/harness/manifests/general/cursor.json +27 -27
  213. package/harness/manifests/java/claude-code.json +29 -29
  214. package/harness/manifests/java/codebuddy.json +29 -29
  215. package/harness/manifests/java/codex.json +29 -29
  216. package/harness/manifests/java/cursor.json +29 -29
  217. package/hunter-workflow-family.json +5 -5
  218. package/package.json +1 -1
@@ -810,10 +810,15 @@ def close_transition(
810
810
  artifact_entries: list[dict[str, Any]] = []
811
811
  for raw in artifacts or []:
812
812
  requested = Path(raw)
813
+ artifact_bases: list[Path] = []
814
+ for base in (project, contract_root, state_root):
815
+ resolved_base = base.resolve()
816
+ if resolved_base not in artifact_bases:
817
+ artifact_bases.append(resolved_base)
813
818
  candidates = (
814
819
  [requested]
815
820
  if requested.is_absolute()
816
- else [project / requested, contract_root / requested]
821
+ else [base / requested for base in artifact_bases]
817
822
  )
818
823
  valid: list[Path] = []
819
824
  for candidate in candidates:
@@ -838,10 +843,11 @@ def close_transition(
838
843
  "ok": False,
839
844
  "code": "TRANSITION_ARTIFACT_INVALID",
840
845
  "path": raw,
841
- "acceptedBases": [str(project), str(contract_root)],
846
+ "acceptedBases": [str(base) for base in artifact_bases],
842
847
  "examples": [
843
848
  str(contract_root / "meta" / "plan-finalization.json"),
844
849
  f".harness/changes/{change}/meta/plan-finalization.json",
850
+ f".harness/state/changes/{change}/evidence/verification-ledger.json",
845
851
  "meta/plan-finalization.json",
846
852
  ],
847
853
  }
@@ -1077,6 +1077,11 @@ def split_phase_attempts(phase_events: list[dict[str, Any]]) -> list[dict[str, A
1077
1077
  "external.wait",
1078
1078
  "issue",
1079
1079
  "ci.wait",
1080
+ # Preparation is intentionally outside the formal phase lifecycle.
1081
+ # A blocked preflight must remain visible in the raw timeline without
1082
+ # manufacturing an attempt or inflating the phase duration/count.
1083
+ "phase.prepare.start",
1084
+ "phase.prepare.end",
1080
1085
  }
1081
1086
  for event in phase_events:
1082
1087
  if event.get("type") == "phase.start":
@@ -350,36 +350,97 @@ def _state_dir(change_dir: Path) -> Path:
350
350
  return Path(harness_paths.resolve_state_dir_for_contract(change_dir))
351
351
 
352
352
 
353
- def load_cursor(
353
+ def _cursor_values(path: Path) -> tuple[int, int, bool]:
354
+ if not path.is_file():
355
+ return 0, 0, True
356
+ try:
357
+ data = json.loads(path.read_text(encoding="utf-8"))
358
+ except (OSError, json.JSONDecodeError):
359
+ return 0, 0, False
360
+ raw_acked = data.get("acked_lines") if isinstance(data, dict) else None
361
+ raw_base = data.get("producer_seq_base", 0) if isinstance(data, dict) else None
362
+ acked_valid = (
363
+ not isinstance(raw_acked, bool)
364
+ and isinstance(raw_acked, int)
365
+ and raw_acked >= 0
366
+ )
367
+ base_valid = (
368
+ not isinstance(raw_base, bool)
369
+ and isinstance(raw_base, int)
370
+ and raw_base >= 0
371
+ )
372
+ return (
373
+ raw_acked if acked_valid else 0,
374
+ raw_base if base_valid else 0,
375
+ acked_valid and base_valid,
376
+ )
377
+
378
+
379
+ def _complete_line_count(path: Path) -> int:
380
+ if not path.is_file():
381
+ return 0
382
+ try:
383
+ data = path.read_bytes()
384
+ except OSError:
385
+ return 0
386
+ if not data:
387
+ return 0
388
+ return data.count(b"\n")
389
+
390
+
391
+ def _initial_producer_seq_base(change_dir: Path) -> int:
392
+ """Keep producer sequence monotonic when a legacy stream becomes split-v1."""
393
+ state_dir = _state_dir(change_dir).resolve()
394
+ contract_dir = change_dir.resolve()
395
+ if state_dir == contract_dir:
396
+ return 0
397
+ legacy_acked, legacy_base, _ = _cursor_values(
398
+ contract_dir / "meta" / "events-sync-cursor.json"
399
+ )
400
+ legacy_lines = _complete_line_count(contract_dir / "events.ndjson")
401
+ return legacy_base + max(legacy_acked, legacy_lines)
402
+
403
+
404
+ def load_cursor_state(
354
405
  change_dir: Path,
355
406
  *,
356
407
  maximum_lines: int | None = None,
357
408
  repair: bool = False,
358
- ) -> int:
409
+ ) -> dict[str, int]:
359
410
  path = cursor_path(change_dir)
360
- if not path.is_file():
361
- return 0
362
- valid = True
363
- try:
364
- data = json.loads(path.read_text(encoding="utf-8"))
365
- except (OSError, json.JSONDecodeError):
366
- data = None
367
- valid = False
368
- raw = data.get("acked_lines") if isinstance(data, dict) else None
369
- if isinstance(raw, bool) or not isinstance(raw, int) or raw < 0:
370
- valid = False
371
- value = 0
372
- else:
373
- value = raw
411
+ exists = path.is_file()
412
+ acked, producer_seq_base, valid = _cursor_values(path)
413
+ if not exists:
414
+ producer_seq_base = _initial_producer_seq_base(change_dir)
374
415
  if maximum_lines is not None:
375
416
  if maximum_lines < 0:
376
417
  raise ValueError("maximum_lines must be non-negative")
377
- if value > maximum_lines:
418
+ if acked > maximum_lines:
419
+ acked = 0
378
420
  valid = False
379
- value = 0
380
- if not valid and repair:
381
- save_cursor(change_dir, 0)
382
- return value
421
+ if (not valid or not exists) and repair:
422
+ save_cursor(
423
+ change_dir,
424
+ acked,
425
+ producer_seq_base=producer_seq_base,
426
+ )
427
+ return {
428
+ "acked_lines": acked,
429
+ "producer_seq_base": producer_seq_base,
430
+ }
431
+
432
+
433
+ def load_cursor(
434
+ change_dir: Path,
435
+ *,
436
+ maximum_lines: int | None = None,
437
+ repair: bool = False,
438
+ ) -> int:
439
+ return load_cursor_state(
440
+ change_dir,
441
+ maximum_lines=maximum_lines,
442
+ repair=repair,
443
+ )["acked_lines"]
383
444
 
384
445
 
385
446
  def _fsync_parent(path: Path) -> None:
@@ -392,14 +453,31 @@ def _fsync_parent(path: Path) -> None:
392
453
  os.close(descriptor)
393
454
 
394
455
 
395
- def save_cursor(change_dir: Path, acked_lines: int) -> None:
456
+ def save_cursor(
457
+ change_dir: Path,
458
+ acked_lines: int,
459
+ *,
460
+ producer_seq_base: int | None = None,
461
+ ) -> None:
396
462
  if isinstance(acked_lines, bool) or not isinstance(acked_lines, int) or acked_lines < 0:
397
463
  raise ValueError("acked_lines must be a non-negative integer")
398
464
  path = cursor_path(change_dir)
465
+ if producer_seq_base is None:
466
+ _, producer_seq_base, _ = _cursor_values(path)
467
+ if (
468
+ isinstance(producer_seq_base, bool)
469
+ or not isinstance(producer_seq_base, int)
470
+ or producer_seq_base < 0
471
+ ):
472
+ raise ValueError("producer_seq_base must be a non-negative integer")
399
473
  path.parent.mkdir(parents=True, exist_ok=True)
400
474
  temporary = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
401
475
  encoded = (
402
- json.dumps({"schemaVersion": 1, "acked_lines": acked_lines}, indent=2) + "\n"
476
+ json.dumps({
477
+ "schemaVersion": 2,
478
+ "acked_lines": acked_lines,
479
+ "producer_seq_base": producer_seq_base,
480
+ }, indent=2) + "\n"
403
481
  ).encode("utf-8")
404
482
  descriptor = os.open(
405
483
  str(temporary), os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600
@@ -489,6 +567,85 @@ def _event_lines_snapshot(events_file: Path) -> list[str]:
489
567
  return data.decode("utf-8-sig").splitlines()
490
568
 
491
569
 
570
+ def _complete_stream_bytes(path: Path) -> bytes:
571
+ data = path.read_bytes() if path.is_file() else b""
572
+ if data and not data.endswith(b"\n"):
573
+ last_newline = data.rfind(b"\n")
574
+ data = b"" if last_newline < 0 else data[:last_newline + 1]
575
+ return data
576
+
577
+
578
+ def _atomic_replace_bytes(path: Path, data: bytes) -> None:
579
+ path.parent.mkdir(parents=True, exist_ok=True)
580
+ temporary = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
581
+ descriptor = os.open(
582
+ str(temporary), os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600
583
+ )
584
+ try:
585
+ with os.fdopen(descriptor, "wb") as stream:
586
+ descriptor = -1
587
+ stream.write(data)
588
+ stream.flush()
589
+ os.fsync(stream.fileno())
590
+ os.replace(temporary, path)
591
+ _fsync_parent(path)
592
+ finally:
593
+ if descriptor >= 0:
594
+ os.close(descriptor)
595
+ try:
596
+ temporary.unlink()
597
+ except FileNotFoundError:
598
+ pass
599
+
600
+
601
+ def _migrate_pending_legacy_stream(change_dir: Path) -> None:
602
+ """Prefix unsent colocated events before the first split-v1 state upload."""
603
+ contract_dir = change_dir.resolve()
604
+ state_dir = _state_dir(change_dir).resolve()
605
+ legacy_events = contract_dir / "events.ndjson"
606
+ target_events = state_dir / "events.ndjson"
607
+ target_cursor = state_dir / "meta" / "events-sync-cursor.json"
608
+ if state_dir == contract_dir or not legacy_events.is_file() or target_cursor.exists():
609
+ return
610
+ legacy_cursor = contract_dir / "meta" / "events-sync-cursor.json"
611
+ legacy_acked, _, _ = _cursor_values(legacy_cursor)
612
+ legacy_line_count = _complete_line_count(legacy_events)
613
+ if legacy_acked >= legacy_line_count:
614
+ return
615
+
616
+ locks = [
617
+ _CrossProcessLock(path.with_name(path.name + ".lock"))
618
+ for path in sorted((legacy_events, target_events), key=lambda item: str(item).casefold())
619
+ ]
620
+ for lock in locks:
621
+ lock.acquire(blocking=True)
622
+ try:
623
+ if target_cursor.exists() or not legacy_events.is_file():
624
+ return
625
+ legacy_data = _complete_stream_bytes(legacy_events)
626
+ target_data = _complete_stream_bytes(target_events)
627
+ if target_data.startswith(legacy_data):
628
+ merged = target_data
629
+ else:
630
+ merged = legacy_data + target_data
631
+ _atomic_replace_bytes(target_events, merged)
632
+
633
+ target_cursor.parent.mkdir(parents=True, exist_ok=True)
634
+ if legacy_cursor.is_file():
635
+ os.replace(legacy_cursor, target_cursor)
636
+ else:
637
+ save_cursor(change_dir, 0, producer_seq_base=0)
638
+
639
+ legacy_quarantine = contract_dir / "meta" / "events-sync-quarantine.ndjson"
640
+ target_quarantine = state_dir / "meta" / "events-sync-quarantine.ndjson"
641
+ if legacy_quarantine.is_file() and not target_quarantine.exists():
642
+ os.replace(legacy_quarantine, target_quarantine)
643
+ legacy_events.unlink()
644
+ finally:
645
+ for lock in reversed(locks):
646
+ lock.release()
647
+
648
+
492
649
  def sync_change(
493
650
  project: Path,
494
651
  change_dir: Path,
@@ -525,6 +682,7 @@ def sync_change(
525
682
  if heartbeat_only:
526
683
  return {"ok": True, "heartbeat": True, "run_id": rid, "change_key": resolved_key}
527
684
 
685
+ _migrate_pending_legacy_stream(change_dir)
528
686
  events_file = _state_dir(change_dir) / "events.ndjson"
529
687
  if not events_file.is_file():
530
688
  return {
@@ -536,11 +694,13 @@ def sync_change(
536
694
  }
537
695
 
538
696
  lines = _event_lines_snapshot(events_file)
539
- acked = load_cursor(
697
+ cursor = load_cursor_state(
540
698
  change_dir,
541
699
  maximum_lines=len(lines),
542
700
  repair=True,
543
701
  )
702
+ acked = cursor["acked_lines"]
703
+ producer_seq_base = cursor["producer_seq_base"]
544
704
  pending_raw = lines[acked:]
545
705
  phase_plan = _workflow_plan(change_dir)
546
706
  uploaded = 0
@@ -571,7 +731,7 @@ def sync_change(
571
731
  event_id = str(event.get("id") or f"{resolved_key}:{line_number}")
572
732
  item: dict[str, Any] = {
573
733
  "event_id": event_id,
574
- "producer_seq": line_number,
734
+ "producer_seq": producer_seq_base + line_number,
575
735
  "event_type": str(event.get("type") or "unknown"),
576
736
  "occurred_at": str(event.get("timestamp") or event.get("ts") or client_time),
577
737
  "payload": _event_payload(event, phase_plan),
@@ -664,7 +824,11 @@ def sync_change(
664
824
  status="local_invalid",
665
825
  )
666
826
  quarantined += 1
667
- save_cursor(change_dir, acked + chunk_start + len(raw_chunk))
827
+ save_cursor(
828
+ change_dir,
829
+ acked + chunk_start + len(raw_chunk),
830
+ producer_seq_base=producer_seq_base,
831
+ )
668
832
 
669
833
  return {
670
834
  "ok": True,
@@ -674,6 +838,7 @@ def sync_change(
674
838
  "quarantined": quarantined,
675
839
  "batch_size": min(MAX_BATCH_SIZE, len(pending_raw)),
676
840
  "acked_lines": len(lines),
841
+ "producer_seq_base": producer_seq_base,
677
842
  "server": last_result,
678
843
  }
679
844
 
@@ -1053,6 +1053,40 @@ def ledger_evidence_identity(ledger: dict[str, Any]) -> str:
1053
1053
  return "sha256:" + hashlib.sha256(canonical).hexdigest()
1054
1054
 
1055
1055
 
1056
+ def _immutable_change_base(
1057
+ change_dir: Path,
1058
+ project_root: Path,
1059
+ ) -> str:
1060
+ roots = [change_dir]
1061
+ try:
1062
+ state_root = harness_paths.resolve_state_dir_for_contract(
1063
+ change_dir,
1064
+ project_root,
1065
+ )
1066
+ if state_root.resolve() != change_dir.resolve():
1067
+ roots.insert(0, state_root)
1068
+ except (OSError, ValueError):
1069
+ pass
1070
+ for root in roots:
1071
+ for relative in (
1072
+ Path("meta") / "state-snapshot.json",
1073
+ Path("state-snapshot.json"),
1074
+ ):
1075
+ path = root / relative
1076
+ if not path.is_file():
1077
+ continue
1078
+ try:
1079
+ payload = json.loads(path.read_text(encoding="utf-8-sig"))
1080
+ except (OSError, json.JSONDecodeError, TypeError):
1081
+ continue
1082
+ if not isinstance(payload, dict):
1083
+ continue
1084
+ value = str(payload.get("changeBase") or "").strip()
1085
+ if value:
1086
+ return value
1087
+ return ""
1088
+
1089
+
1056
1090
  def migrate_ledger_for_write(
1057
1091
  change_dir: Path,
1058
1092
  ledger: dict[str, Any],
@@ -1089,6 +1123,15 @@ def migrate_ledger_for_write(
1089
1123
  if not _nonempty_str(resolved_base):
1090
1124
  resolved_base = ledger.get("baseCommit")
1091
1125
  if not _nonempty_str(resolved_base):
1126
+ resolved_base = _immutable_change_base(change_dir, repo_root)
1127
+ if not _nonempty_str(resolved_base):
1128
+ if record_migration:
1129
+ raise LedgerMigrationError(
1130
+ "immutable change base is missing; recapture the Plan boundary "
1131
+ "or pass an explicit --base-commit instead of using write-time HEAD"
1132
+ )
1133
+ # A genuinely new ledger establishes its identity at the first write.
1134
+ # Existing ledgers are handled above and may never take this fallback.
1092
1135
  resolved_base = current_head
1093
1136
  resolved_diff = diff_hash
1094
1137
  if not _nonempty_str(resolved_diff):
@@ -2795,9 +2838,43 @@ def cmd_diff_hash(args: argparse.Namespace) -> int:
2795
2838
  repo_raw = getattr(args, "repo", None)
2796
2839
  repo = Path(repo_raw).expanduser().resolve() if repo_raw else Path.cwd().resolve()
2797
2840
  base = getattr(args, "base", None)
2798
- change_dir = getattr(args, "change_dir", None)
2841
+ change_dir_raw = getattr(args, "change_dir", None)
2799
2842
  try:
2800
- diff_hash, meta = compute_diff_hash(repo, base=base, change_dir=change_dir)
2843
+ change_dir = resolve_path(change_dir_raw) if change_dir_raw else None
2844
+ if change_dir is not None and _contract_is_v2(change_dir):
2845
+ resolved_base = str(base or "").strip()
2846
+ if not resolved_base:
2847
+ existing, _ = load_ledger(change_dir)
2848
+ if isinstance(existing, dict):
2849
+ resolved_base = str(existing.get("baseCommit") or "").strip()
2850
+ if not resolved_base:
2851
+ resolved_base = _immutable_change_base(change_dir, repo)
2852
+ if not resolved_base:
2853
+ raise ValueError(
2854
+ "immutable change base is missing; capture the Plan boundary "
2855
+ "or pass --base"
2856
+ )
2857
+ detail = compute_ownership_diff(
2858
+ repo,
2859
+ base=resolved_base,
2860
+ change_dir=change_dir,
2861
+ )
2862
+ payload = {
2863
+ "ok": True,
2864
+ "action": "diff-hash",
2865
+ "identityScope": "change-ownership",
2866
+ "algorithmVersion": "ownership-content-changeset-1",
2867
+ "base": resolved_base,
2868
+ "head": _git_text(repo, "rev-parse", "--verify", "HEAD"),
2869
+ **detail,
2870
+ }
2871
+ emit_json(payload, as_json=as_json)
2872
+ return 0
2873
+ diff_hash, meta = compute_diff_hash(
2874
+ repo,
2875
+ base=base,
2876
+ change_dir=str(change_dir) if change_dir is not None else None,
2877
+ )
2801
2878
  except (OSError, RuntimeError, ValueError) as exc:
2802
2879
  return emit_error(str(exc), as_json=as_json)
2803
2880
  payload = {"ok": True, "action": "diff-hash", "diffHash": diff_hash}
@@ -838,13 +838,20 @@ def _node_commands(project: Path) -> dict[str, Any]:
838
838
  "src/**/*.tsx",
839
839
  "test/**/*.ts",
840
840
  "test/**/*.tsx",
841
+ "tests/**/*.ts",
842
+ "tests/**/*.tsx",
841
843
  "packages/*/src/**/*.ts",
842
844
  "packages/*/src/**/*.tsx",
843
845
  "packages/*/test/**/*.ts",
844
846
  "packages/*/test/**/*.tsx",
847
+ "packages/*/tests/**/*.ts",
848
+ "packages/*/tests/**/*.tsx",
845
849
  "apps/*/src/**/*.ts",
846
850
  "apps/*/src/**/*.tsx",
847
851
  "apps/*/test/**/*.ts",
852
+ "apps/*/test/**/*.tsx",
853
+ "apps/*/tests/**/*.ts",
854
+ "apps/*/tests/**/*.tsx",
848
855
  ]
849
856
  # harness dogfood: canonical Python + .mjs sources feed npm run check (vitest
850
857
  # imports harness-test/scripts; smoke:pack runs sync-harness.mjs).
@@ -119,6 +119,10 @@ def capture_snapshot(
119
119
  "schemaVersion": SNAPSHOT_SCHEMA_VERSION,
120
120
  "generatedAt": now_iso(),
121
121
  "changeName": change_name,
122
+ # The first captured Git boundary is the immutable identity of the
123
+ # change. Later phases may advance HEAD, but must never silently move
124
+ # the base and collapse the archive range.
125
+ "changeBase": base or "",
122
126
  "project": {"root": str(project.resolve())},
123
127
  "worktree": {"root": str(Path(worktree_root).resolve())},
124
128
  "git": {"base": base or "", "head": head or ""},
@@ -250,10 +254,25 @@ def capture_current_state(
250
254
  base: str = "",
251
255
  head: str = "HEAD",
252
256
  ) -> tuple[dict[str, Any], list[str]]:
253
- resolved_head = _git(project, "rev-parse", head) or head
254
- resolved_base = _git(project, "rev-parse", base) if base else ""
255
- files = discover_segment_files(project, change_dir, base=resolved_base, head=resolved_head)
257
+ git_head = _git(project, "rev-parse", head)
258
+ resolved_head = git_head or head
256
259
  previous = load_snapshot(change_dir)
260
+ previous_git = previous.get("git") if isinstance(previous, dict) else None
261
+ previous_base = (
262
+ str(previous.get("changeBase") or "").strip()
263
+ if isinstance(previous, dict)
264
+ else ""
265
+ )
266
+ if not previous_base and isinstance(previous_git, dict):
267
+ previous_base = str(
268
+ previous_git.get("base") or previous_git.get("baseCommit") or ""
269
+ ).strip()
270
+ requested_base = _git(project, "rev-parse", base) if base else ""
271
+ # First capture establishes the boundary. A later --base value is an
272
+ # observation hint only; changing the boundary requires the explicit
273
+ # archive range-adoption receipt.
274
+ resolved_base = previous_base or requested_base or git_head
275
+ files = discover_segment_files(project, change_dir, base=resolved_base, head=resolved_head)
257
276
  fresh = capture_snapshot(
258
277
  change_dir,
259
278
  change_name=change_name,
@@ -2,5 +2,5 @@
2
2
  "schemaVersion": 1,
3
3
  "overlay": "none",
4
4
  "agent": "codex",
5
- "coreHash": "af08899f70332067"
5
+ "coreHash": "778d0b1b9d303ef3"
6
6
  }
@@ -34,7 +34,7 @@
34
34
  | `protocols/state-layout-protocol.md` | 状态目录分层:`.harness/changes/<cn>/` 下按 `meta/`、`logs/`、`evidence/`、`reports/`、`scripts/`、`backups/` 子目录分层写入;读取时先读新路径再兼容旧路径 |
35
35
  | `protocols/submit-protocol.md` | 固定提交交互:提交方式与 commit message 确认使用固定选项模板,禁止 AI footer |
36
36
  | `protocols/archive-report-protocol.md` | 归档报告:`summary-data.json`、manifest/checksum 与真实性规则 |
37
- | `protocols/report-pipeline-protocol.md` | 报告流水线:`events.ndjson` + `harness_archive.py finalize/replay` + 数据一致性校验 |
37
+ | `protocols/report-pipeline-protocol.md` | 报告流水线:`events.ndjson` + `harness_archive.py execute/replay` + 数据一致性校验 |
38
38
 
39
39
  每个 skill 的 SKILL.md 关键规则章节都通过相对路径引用这些 protocol(`../protocols/powershell-protocol.md` 等)。
40
40
 
@@ -159,9 +159,9 @@
159
159
  - **Bash 拒绝、PowerShell 重试、降级、跳过、用户确认都必须记录**
160
160
  - 日志状态统一使用 `✅OK / 🟡WARN(原因) / ❌FAIL(原因)`
161
161
  - harness-archive 归档时从日志汇总:时间线、总用时、Skill 调用统计
162
- - `harness_archive.py finalize/replay` 优先从 `events.ndjson` 汇总命令、验证、artifact、问题和决策;旧 archive 缺少 events 时才回放 execution-log/ledger/manifest
162
+ - `harness_archive.py execute/replay` 优先从 `events.ndjson` 汇总命令、验证、artifact、问题和决策;旧 archive 缺少 events 时才回放 execution-log/ledger/manifest
163
163
  - sync 默认不关联具体变更目录,仅在已有变更目录时追加日志和 events
164
- - archive 是例外:finalize 内部负责且仅负责一次 `phase.start` / `phase.end`,调用者不得重复追加阶段边界
164
+ - archive 是例外:`execute` 负责一次准备记录和一次正式 `phase.start` / `phase.end`,调用者不得重复追加阶段边界,也不得串行运行 `auto-gate`、`status`、`finalize`
165
165
 
166
166
  ## Skill 目录结构
167
167
 
@@ -278,7 +278,7 @@ harness-skills/
278
278
  | **submit hash 记录** | pre-pull local hash + final pushed hash 双标注(主目录);worktree 模式 submit 段只本地 commit,合并段产生 `mergeFinalHash`,archive 以 `mergeFinalHash` 为准(无则回退 final pushed hash) |
279
279
  | **archive 阶段 1** | 归档前确认实际计划阶段的证据与结局;有 Git 时核对最终提交身份,无 Git、无 upstream 或跳过 submit 时使用内容清单身份。发布候选资格与本地封存分开判断;阶段边界由 finalize 单进程维护,调用者不额外 append |
280
280
  | **archive 文件移动** | 只用 PowerShell 或 Read+Write+验证,**禁止 Bash mv/cp/rm**;移动失败时不删除原目录 |
281
- | **archive 最终报告** | 必须运行 `harness_archive.py finalize` 生成权威 `summary-data.json` 并完成 validate。平台直接读取该 JSON;本地不生成重复的 HTML 报告。无测试或无 review 时必须标记 `NOT_RUN` / `ADVISORY_NOT_RUN`,禁止伪造 100% 通过率。状态演进须真实展示(✅OK / 🟡WARN / 🔁REUSED / 🔁RETESTED / 📝ADVISORY / 🧹NON_BEHAVIORAL_CLEANUP) |
281
+ | **archive 最终报告** | 必须运行 `harness_archive.py execute`,由内部 finalize 生成权威 `summary-data.json` 并完成 validate。平台直接读取该 JSON;本地不生成重复的 HTML 报告。无测试或无 review 时必须标记 `NOT_RUN` / `ADVISORY_NOT_RUN`,禁止伪造 100% 通过率。状态演进须真实展示(✅OK / 🟡WARN / 🔁REUSED / 🔁RETESTED / 📝ADVISORY / 🧹NON_BEHAVIORAL_CLEANUP) |
282
282
 
283
283
  ### 敏感信息脱敏
284
284
 
@@ -424,7 +424,7 @@ npx hunter-harness # 初始化阶段检查环境/CodeGraph/基础状态(非
424
424
  /harness-test # 运行测试(30条避坑规则)
425
425
  /harness-review # 代码审查
426
426
  /harness-submit # 提交代码(worktree 模式含合并;/harness-merge 为别名)
427
- /harness-archive # 归档产出(harness_archive.py finalize),释放工作区
427
+ /harness-archive # 归档产出(harness_archive.py execute),释放工作区
428
428
  ```
429
429
 
430
430
  ## 避坑知识来源
@@ -454,7 +454,7 @@ npx hunter-harness # 初始化阶段检查环境/CodeGraph/基础状态(非
454
454
  - `protocols/evidence-based-reporting-protocol.md`:证据化报告(✅/🟡/❌ 三态,已取代原 `harness-plan/evidence-based-reporting.md`,各 skill 引用此版本)。
455
455
  - `protocols/submit-protocol.md`:固定提交交互、中文 commit 文件、禁止 AI footer。
456
456
  - `protocols/archive-report-protocol.md`:summary-data、manifest/checksum 与平台归档展示合同。
457
- - `protocols/report-pipeline-protocol.md`:events.ndjson + `harness_archive.py finalize/replay` + summary-data 一致性校验。
457
+ - `protocols/report-pipeline-protocol.md`:events.ndjson + `harness_archive.py execute/replay` + summary-data 一致性校验。
458
458
  - `protocols/state-layout-protocol.md`:`.harness/changes/<cn>/` 子目录分层(meta/logs/evidence/reports/scripts/backups),读取先新后旧。
459
459
 
460
460
  各 skill 的 `SKILL.md` 只保留阶段目标和硬门禁,细节优先引用这些协议,避免在多个 skill 中复制并产生冲突。
@@ -475,4 +475,4 @@ backups/ 未提交但用于验证的测试文件等备份
475
475
 
476
476
  读取时先读新路径,再兼容旧路径。详见 `protocols/state-layout-protocol.md`。
477
477
 
478
- Archive 最终报告由 `harness_archive.py finalize` 生成 `summary-data.json`。Hunter Platform 直接读取该文件,避免本地重复渲染和两份报告数据不一致。
478
+ Archive 常规入口为 `harness_archive.py execute`,内部 finalize 生成 `summary-data.json`。Hunter Platform 直接读取该文件,避免本地重复渲染和两份报告数据不一致。