@hunter-harness/workflow-harness 0.2.12 → 0.2.14

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 (194) hide show
  1. package/harness/bundles/general/claude-code/.harness-build.json +1 -1
  2. package/harness/bundles/general/claude-code/harness-archive/SKILL.md +1 -1
  3. package/harness/bundles/general/claude-code/harness-codebase-map/SKILL.md +1 -1
  4. package/harness/bundles/general/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  5. package/harness/bundles/general/claude-code/harness-knowledge-query/SKILL.md +1 -1
  6. package/harness/bundles/general/claude-code/harness-plan/SKILL.md +1 -1
  7. package/harness/bundles/general/claude-code/harness-review/SKILL.md +1 -1
  8. package/harness/bundles/general/claude-code/harness-run/SKILL.md +1 -1
  9. package/harness/bundles/general/claude-code/harness-submit/SKILL.md +2 -2
  10. package/harness/bundles/general/claude-code/harness-submit/checklist.md +1 -1
  11. package/harness/bundles/general/claude-code/harness-sync/SKILL.md +2 -2
  12. package/harness/bundles/general/claude-code/harness-sync/reference.md +5 -4
  13. package/harness/bundles/general/claude-code/harness-test/SKILL.md +1 -1
  14. package/harness/bundles/general/claude-code/scripts/harness_archive.py +124 -0
  15. package/harness/bundles/general/claude-code/scripts/harness_change.py +54 -0
  16. package/harness/bundles/general/claude-code/scripts/harness_deploy.py +177 -0
  17. package/harness/bundles/general/claude-code/scripts/harness_events.py +99 -1
  18. package/harness/bundles/general/claude-code/scripts/harness_gate.py +57 -4
  19. package/harness/bundles/general/claude-code/scripts/harness_integration.py +3 -0
  20. package/harness/bundles/general/claude-code/scripts/harness_ledger.py +15 -3
  21. package/harness/bundles/general/claude-code/scripts/harness_preflight.py +47 -0
  22. package/harness/bundles/general/claude-code/scripts/harness_test_guard.py +86 -13
  23. package/harness/bundles/general/codebuddy/.harness-build.json +1 -1
  24. package/harness/bundles/general/codebuddy/harness-archive/SKILL.md +1 -1
  25. package/harness/bundles/general/codebuddy/harness-codebase-map/SKILL.md +1 -1
  26. package/harness/bundles/general/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  27. package/harness/bundles/general/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  28. package/harness/bundles/general/codebuddy/harness-plan/SKILL.md +1 -1
  29. package/harness/bundles/general/codebuddy/harness-review/SKILL.md +1 -1
  30. package/harness/bundles/general/codebuddy/harness-run/SKILL.md +1 -1
  31. package/harness/bundles/general/codebuddy/harness-submit/SKILL.md +2 -2
  32. package/harness/bundles/general/codebuddy/harness-submit/checklist.md +1 -1
  33. package/harness/bundles/general/codebuddy/harness-sync/SKILL.md +2 -2
  34. package/harness/bundles/general/codebuddy/harness-sync/reference.md +5 -4
  35. package/harness/bundles/general/codebuddy/harness-test/SKILL.md +1 -1
  36. package/harness/bundles/general/codebuddy/scripts/harness_archive.py +124 -0
  37. package/harness/bundles/general/codebuddy/scripts/harness_change.py +54 -0
  38. package/harness/bundles/general/codebuddy/scripts/harness_deploy.py +177 -0
  39. package/harness/bundles/general/codebuddy/scripts/harness_events.py +99 -1
  40. package/harness/bundles/general/codebuddy/scripts/harness_gate.py +57 -4
  41. package/harness/bundles/general/codebuddy/scripts/harness_integration.py +3 -0
  42. package/harness/bundles/general/codebuddy/scripts/harness_ledger.py +15 -3
  43. package/harness/bundles/general/codebuddy/scripts/harness_preflight.py +47 -0
  44. package/harness/bundles/general/codebuddy/scripts/harness_test_guard.py +86 -13
  45. package/harness/bundles/general/codex/.harness-build.json +1 -1
  46. package/harness/bundles/general/codex/harness-archive/SKILL.md +1 -1
  47. package/harness/bundles/general/codex/harness-codebase-map/SKILL.md +1 -1
  48. package/harness/bundles/general/codex/harness-knowledge-ingest/SKILL.md +1 -1
  49. package/harness/bundles/general/codex/harness-knowledge-query/SKILL.md +1 -1
  50. package/harness/bundles/general/codex/harness-plan/SKILL.md +1 -1
  51. package/harness/bundles/general/codex/harness-review/SKILL.md +1 -1
  52. package/harness/bundles/general/codex/harness-run/SKILL.md +1 -1
  53. package/harness/bundles/general/codex/harness-submit/SKILL.md +2 -2
  54. package/harness/bundles/general/codex/harness-submit/checklist.md +1 -1
  55. package/harness/bundles/general/codex/harness-sync/SKILL.md +2 -2
  56. package/harness/bundles/general/codex/harness-sync/reference.md +5 -4
  57. package/harness/bundles/general/codex/harness-test/SKILL.md +1 -1
  58. package/harness/bundles/general/codex/scripts/harness_archive.py +124 -0
  59. package/harness/bundles/general/codex/scripts/harness_change.py +54 -0
  60. package/harness/bundles/general/codex/scripts/harness_deploy.py +177 -0
  61. package/harness/bundles/general/codex/scripts/harness_events.py +99 -1
  62. package/harness/bundles/general/codex/scripts/harness_gate.py +57 -4
  63. package/harness/bundles/general/codex/scripts/harness_integration.py +3 -0
  64. package/harness/bundles/general/codex/scripts/harness_ledger.py +15 -3
  65. package/harness/bundles/general/codex/scripts/harness_preflight.py +47 -0
  66. package/harness/bundles/general/codex/scripts/harness_test_guard.py +86 -13
  67. package/harness/bundles/general/cursor/.harness-build.json +1 -1
  68. package/harness/bundles/general/cursor/harness-archive/SKILL.md +1 -1
  69. package/harness/bundles/general/cursor/harness-codebase-map/SKILL.md +1 -1
  70. package/harness/bundles/general/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  71. package/harness/bundles/general/cursor/harness-knowledge-query/SKILL.md +1 -1
  72. package/harness/bundles/general/cursor/harness-plan/SKILL.md +1 -1
  73. package/harness/bundles/general/cursor/harness-review/SKILL.md +1 -1
  74. package/harness/bundles/general/cursor/harness-run/SKILL.md +1 -1
  75. package/harness/bundles/general/cursor/harness-submit/SKILL.md +2 -2
  76. package/harness/bundles/general/cursor/harness-submit/checklist.md +1 -1
  77. package/harness/bundles/general/cursor/harness-sync/SKILL.md +2 -2
  78. package/harness/bundles/general/cursor/harness-sync/reference.md +5 -4
  79. package/harness/bundles/general/cursor/harness-test/SKILL.md +1 -1
  80. package/harness/bundles/general/cursor/scripts/harness_archive.py +124 -0
  81. package/harness/bundles/general/cursor/scripts/harness_change.py +54 -0
  82. package/harness/bundles/general/cursor/scripts/harness_deploy.py +177 -0
  83. package/harness/bundles/general/cursor/scripts/harness_events.py +99 -1
  84. package/harness/bundles/general/cursor/scripts/harness_gate.py +57 -4
  85. package/harness/bundles/general/cursor/scripts/harness_integration.py +3 -0
  86. package/harness/bundles/general/cursor/scripts/harness_ledger.py +15 -3
  87. package/harness/bundles/general/cursor/scripts/harness_preflight.py +47 -0
  88. package/harness/bundles/general/cursor/scripts/harness_test_guard.py +86 -13
  89. package/harness/bundles/java/claude-code/.harness-build.json +1 -1
  90. package/harness/bundles/java/claude-code/harness-apidoc/SKILL.md +1 -1
  91. package/harness/bundles/java/claude-code/harness-archive/SKILL.md +1 -1
  92. package/harness/bundles/java/claude-code/harness-codebase-map/SKILL.md +1 -1
  93. package/harness/bundles/java/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  94. package/harness/bundles/java/claude-code/harness-knowledge-query/SKILL.md +1 -1
  95. package/harness/bundles/java/claude-code/harness-package/SKILL.md +1 -1
  96. package/harness/bundles/java/claude-code/harness-plan/SKILL.md +1 -1
  97. package/harness/bundles/java/claude-code/harness-review/SKILL.md +1 -1
  98. package/harness/bundles/java/claude-code/harness-run/SKILL.md +1 -1
  99. package/harness/bundles/java/claude-code/harness-submit/SKILL.md +2 -2
  100. package/harness/bundles/java/claude-code/harness-submit/checklist.md +1 -1
  101. package/harness/bundles/java/claude-code/harness-sync/SKILL.md +2 -2
  102. package/harness/bundles/java/claude-code/harness-sync/reference.md +5 -4
  103. package/harness/bundles/java/claude-code/harness-test/SKILL.md +1 -1
  104. package/harness/bundles/java/claude-code/scripts/harness_archive.py +124 -0
  105. package/harness/bundles/java/claude-code/scripts/harness_change.py +54 -0
  106. package/harness/bundles/java/claude-code/scripts/harness_deploy.py +177 -0
  107. package/harness/bundles/java/claude-code/scripts/harness_events.py +99 -1
  108. package/harness/bundles/java/claude-code/scripts/harness_gate.py +57 -4
  109. package/harness/bundles/java/claude-code/scripts/harness_integration.py +3 -0
  110. package/harness/bundles/java/claude-code/scripts/harness_ledger.py +15 -3
  111. package/harness/bundles/java/claude-code/scripts/harness_preflight.py +47 -0
  112. package/harness/bundles/java/claude-code/scripts/harness_test_guard.py +86 -13
  113. package/harness/bundles/java/codebuddy/.harness-build.json +1 -1
  114. package/harness/bundles/java/codebuddy/harness-apidoc/SKILL.md +1 -1
  115. package/harness/bundles/java/codebuddy/harness-archive/SKILL.md +1 -1
  116. package/harness/bundles/java/codebuddy/harness-codebase-map/SKILL.md +1 -1
  117. package/harness/bundles/java/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  118. package/harness/bundles/java/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  119. package/harness/bundles/java/codebuddy/harness-package/SKILL.md +1 -1
  120. package/harness/bundles/java/codebuddy/harness-plan/SKILL.md +1 -1
  121. package/harness/bundles/java/codebuddy/harness-review/SKILL.md +1 -1
  122. package/harness/bundles/java/codebuddy/harness-run/SKILL.md +1 -1
  123. package/harness/bundles/java/codebuddy/harness-submit/SKILL.md +2 -2
  124. package/harness/bundles/java/codebuddy/harness-submit/checklist.md +1 -1
  125. package/harness/bundles/java/codebuddy/harness-sync/SKILL.md +2 -2
  126. package/harness/bundles/java/codebuddy/harness-sync/reference.md +5 -4
  127. package/harness/bundles/java/codebuddy/harness-test/SKILL.md +1 -1
  128. package/harness/bundles/java/codebuddy/scripts/harness_archive.py +124 -0
  129. package/harness/bundles/java/codebuddy/scripts/harness_change.py +54 -0
  130. package/harness/bundles/java/codebuddy/scripts/harness_deploy.py +177 -0
  131. package/harness/bundles/java/codebuddy/scripts/harness_events.py +99 -1
  132. package/harness/bundles/java/codebuddy/scripts/harness_gate.py +57 -4
  133. package/harness/bundles/java/codebuddy/scripts/harness_integration.py +3 -0
  134. package/harness/bundles/java/codebuddy/scripts/harness_ledger.py +15 -3
  135. package/harness/bundles/java/codebuddy/scripts/harness_preflight.py +47 -0
  136. package/harness/bundles/java/codebuddy/scripts/harness_test_guard.py +86 -13
  137. package/harness/bundles/java/codex/.harness-build.json +1 -1
  138. package/harness/bundles/java/codex/harness-apidoc/SKILL.md +1 -1
  139. package/harness/bundles/java/codex/harness-archive/SKILL.md +1 -1
  140. package/harness/bundles/java/codex/harness-codebase-map/SKILL.md +1 -1
  141. package/harness/bundles/java/codex/harness-knowledge-ingest/SKILL.md +1 -1
  142. package/harness/bundles/java/codex/harness-knowledge-query/SKILL.md +1 -1
  143. package/harness/bundles/java/codex/harness-package/SKILL.md +1 -1
  144. package/harness/bundles/java/codex/harness-plan/SKILL.md +1 -1
  145. package/harness/bundles/java/codex/harness-review/SKILL.md +1 -1
  146. package/harness/bundles/java/codex/harness-run/SKILL.md +1 -1
  147. package/harness/bundles/java/codex/harness-submit/SKILL.md +2 -2
  148. package/harness/bundles/java/codex/harness-submit/checklist.md +1 -1
  149. package/harness/bundles/java/codex/harness-sync/SKILL.md +2 -2
  150. package/harness/bundles/java/codex/harness-sync/reference.md +5 -4
  151. package/harness/bundles/java/codex/harness-test/SKILL.md +1 -1
  152. package/harness/bundles/java/codex/scripts/harness_archive.py +124 -0
  153. package/harness/bundles/java/codex/scripts/harness_change.py +54 -0
  154. package/harness/bundles/java/codex/scripts/harness_deploy.py +177 -0
  155. package/harness/bundles/java/codex/scripts/harness_events.py +99 -1
  156. package/harness/bundles/java/codex/scripts/harness_gate.py +57 -4
  157. package/harness/bundles/java/codex/scripts/harness_integration.py +3 -0
  158. package/harness/bundles/java/codex/scripts/harness_ledger.py +15 -3
  159. package/harness/bundles/java/codex/scripts/harness_preflight.py +47 -0
  160. package/harness/bundles/java/codex/scripts/harness_test_guard.py +86 -13
  161. package/harness/bundles/java/cursor/.harness-build.json +1 -1
  162. package/harness/bundles/java/cursor/harness-apidoc/SKILL.md +1 -1
  163. package/harness/bundles/java/cursor/harness-archive/SKILL.md +1 -1
  164. package/harness/bundles/java/cursor/harness-codebase-map/SKILL.md +1 -1
  165. package/harness/bundles/java/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  166. package/harness/bundles/java/cursor/harness-knowledge-query/SKILL.md +1 -1
  167. package/harness/bundles/java/cursor/harness-package/SKILL.md +1 -1
  168. package/harness/bundles/java/cursor/harness-plan/SKILL.md +1 -1
  169. package/harness/bundles/java/cursor/harness-review/SKILL.md +1 -1
  170. package/harness/bundles/java/cursor/harness-run/SKILL.md +1 -1
  171. package/harness/bundles/java/cursor/harness-submit/SKILL.md +2 -2
  172. package/harness/bundles/java/cursor/harness-submit/checklist.md +1 -1
  173. package/harness/bundles/java/cursor/harness-sync/SKILL.md +2 -2
  174. package/harness/bundles/java/cursor/harness-sync/reference.md +5 -4
  175. package/harness/bundles/java/cursor/harness-test/SKILL.md +1 -1
  176. package/harness/bundles/java/cursor/scripts/harness_archive.py +124 -0
  177. package/harness/bundles/java/cursor/scripts/harness_change.py +54 -0
  178. package/harness/bundles/java/cursor/scripts/harness_deploy.py +177 -0
  179. package/harness/bundles/java/cursor/scripts/harness_events.py +99 -1
  180. package/harness/bundles/java/cursor/scripts/harness_gate.py +57 -4
  181. package/harness/bundles/java/cursor/scripts/harness_integration.py +3 -0
  182. package/harness/bundles/java/cursor/scripts/harness_ledger.py +15 -3
  183. package/harness/bundles/java/cursor/scripts/harness_preflight.py +47 -0
  184. package/harness/bundles/java/cursor/scripts/harness_test_guard.py +86 -13
  185. package/harness/manifests/general/claude-code.json +23 -23
  186. package/harness/manifests/general/codebuddy.json +23 -23
  187. package/harness/manifests/general/codex.json +23 -23
  188. package/harness/manifests/general/cursor.json +23 -23
  189. package/harness/manifests/java/claude-code.json +25 -25
  190. package/harness/manifests/java/codebuddy.json +25 -25
  191. package/harness/manifests/java/codex.json +25 -25
  192. package/harness/manifests/java/cursor.json +25 -25
  193. package/hunter-workflow-family.json +2 -2
  194. package/package.json +15 -15
@@ -623,6 +623,107 @@ def collect_files(root: Path) -> dict[str, str]:
623
623
  return files
624
624
 
625
625
 
626
+ # --- Per-file bundle manifest (retro 2026-07-20 §5.1/5.25) -----------------
627
+ #
628
+ # registry_version + bundle_hash alone cannot prove every installed file
629
+ # belongs to the declared bundle. The bundle therefore ships a per-file
630
+ # manifest (relpath/sha256/size/mode/adapterTransformationId); install
631
+ # verifies staging content against it BEFORE the atomic switch and never
632
+ # updates metadata on partial failure.
633
+
634
+ BUNDLE_MANIFEST_NAME = "bundle-manifest.json"
635
+ _MANIFEST_EXCLUDED = frozenset(
636
+ {BUILD_MARKER, MANIFEST_NAME, AGENTS_MANAGED_NAME, BUNDLE_MANIFEST_NAME}
637
+ )
638
+
639
+
640
+ def build_manifest(root: Path, transformation_id: str = "raw") -> list[dict[str, Any]]:
641
+ """Return per-file manifest entries for every bundle file under ``root``.
642
+
643
+ Install metadata (build marker, managed manifests, the manifest itself)
644
+ is excluded. Entries are sorted by relpath for deterministic output.
645
+ """
646
+ root = root.resolve()
647
+ entries: list[dict[str, Any]] = []
648
+ for path in sorted(root.rglob("*")):
649
+ if not path.is_file() or "__pycache__" in path.parts:
650
+ continue
651
+ rel = path.relative_to(root).as_posix()
652
+ if rel in _MANIFEST_EXCLUDED:
653
+ continue
654
+ stat = path.stat()
655
+ entries.append(
656
+ {
657
+ "relpath": rel,
658
+ "sha256": sha256_file(path),
659
+ "size": stat.st_size,
660
+ "mode": stat.st_mode,
661
+ "adapterTransformationId": transformation_id,
662
+ }
663
+ )
664
+ return entries
665
+
666
+
667
+ def compute_bundle_manifest_hash(entries: list[dict[str, Any]]) -> str:
668
+ """Deterministic aggregate hash over manifest entries (order-independent).
669
+
670
+ Must match packages/contracts/src/bundle-manifest.ts computeBundleManifestHash.
671
+ """
672
+ ordered = sorted(entries, key=lambda entry: entry["relpath"])
673
+ lines = [
674
+ f"{entry['relpath']}:{entry['sha256']}:{entry['size']}:{entry['mode']}:{entry['adapterTransformationId']}"
675
+ for entry in ordered
676
+ ]
677
+ return hashlib.sha256("\n".join(lines).encode("utf-8")).hexdigest()
678
+
679
+
680
+ def aggregate_installed_content_hash(files: dict[str, str]) -> str:
681
+ """Deterministic aggregate hash over actually-installed relpath->sha256."""
682
+ lines = [f"{rel}:{files[rel]}" for rel in sorted(files)]
683
+ return hashlib.sha256("\n".join(lines).encode("utf-8")).hexdigest()
684
+
685
+
686
+ def _verify_tree_against_manifest(
687
+ root: Path, entries: list[dict[str, Any]]
688
+ ) -> list[dict[str, str]]:
689
+ """Return mismatch details for files under ``root`` vs manifest entries."""
690
+ mismatches: list[dict[str, str]] = []
691
+ actual = collect_files(root)
692
+ declared = {entry["relpath"]: entry["sha256"] for entry in entries}
693
+ for rel, expected in sorted(declared.items()):
694
+ if rel not in actual:
695
+ mismatches.append({"relpath": rel, "expected": expected, "actual": "<missing>"})
696
+ elif actual[rel] != expected:
697
+ mismatches.append(
698
+ {"relpath": rel, "expected": expected, "actual": actual[rel]}
699
+ )
700
+ return mismatches
701
+
702
+
703
+ def cmd_verify_installed(
704
+ installed_dir: Path, entries: list[dict[str, Any]], bundle_version: str
705
+ ) -> dict[str, Any]:
706
+ """Verify installed content against the bundle manifest, per file."""
707
+ installed_dir = installed_dir.resolve()
708
+ mismatches = _verify_tree_against_manifest(installed_dir, entries)
709
+ actual = collect_files(installed_dir)
710
+ declared = {entry["relpath"] for entry in entries}
711
+ content = {
712
+ rel: digest
713
+ for rel, digest in actual.items()
714
+ if rel not in _MANIFEST_EXCLUDED and rel in declared
715
+ }
716
+ return {
717
+ "ok": not mismatches,
718
+ "action": "verify-installed",
719
+ "bundleVersion": bundle_version,
720
+ "verificationStatus": "verified" if not mismatches else "degraded",
721
+ "installedContentHash": aggregate_installed_content_hash(content),
722
+ "verifiedAt": now_iso(),
723
+ "mismatchDetails": mismatches,
724
+ }
725
+
726
+
626
727
  def cmd_install(build_out: Path, project: Path, target: Path | None) -> dict[str, Any]:
627
728
  build_out = build_out.resolve()
628
729
  project = project.resolve()
@@ -644,6 +745,23 @@ def cmd_install(build_out: Path, project: Path, target: Path | None) -> dict[str
644
745
  backup: str | None = None
645
746
  staging = dest.parent / f".{dest.name}.staging-{uuid.uuid4().hex[:8]}"
646
747
  shutil.copytree(build_out, staging)
748
+ # Per-file content proof (retro §5.1): if the build carries a
749
+ # bundle-manifest.json, staging must match it exactly before anything is
750
+ # switched. A mismatch aborts the install without touching dest or any
751
+ # metadata — never a partial install under a fresh version label.
752
+ manifest_path = staging / BUNDLE_MANIFEST_NAME
753
+ if manifest_path.is_file():
754
+ manifest_data = json.loads(manifest_path.read_text(encoding="utf-8"))
755
+ manifest_entries = (
756
+ manifest_data.get("files", []) if isinstance(manifest_data, dict) else []
757
+ )
758
+ mismatches = _verify_tree_against_manifest(staging, manifest_entries)
759
+ if mismatches:
760
+ shutil.rmtree(staging, ignore_errors=True)
761
+ raise ValueError(
762
+ "BUNDLE_CONTENT_MISMATCH: staging diverges from bundle-manifest.json: "
763
+ + ", ".join(m["relpath"] for m in mismatches)
764
+ )
647
765
  if dest.exists() and any(dest.iterdir()):
648
766
  managed_old = _read_managed_set(dest / MANIFEST_NAME)
649
767
  # Preserve user-owned files: anything in dest that was NOT managed by a
@@ -771,6 +889,28 @@ def build_parser() -> argparse.ArgumentParser:
771
889
  v.add_argument("--bundle", type=Path, required=True)
772
890
  v.add_argument("--manifest", type=Path, required=True)
773
891
  v.add_argument("--json", action="store_true")
892
+
893
+ g = sub.add_parser(
894
+ "generate-manifest",
895
+ help="Generate per-file bundle-manifest.json for a bundle dir",
896
+ )
897
+ g.add_argument("--bundle", type=Path, required=True)
898
+ g.add_argument("--bundle-version", required=True)
899
+ g.add_argument(
900
+ "--transformation",
901
+ choices=["raw", "adapted", "workflow-packaged"],
902
+ default="raw",
903
+ )
904
+ g.add_argument("--out", type=Path)
905
+ g.add_argument("--json", action="store_true")
906
+
907
+ vi = sub.add_parser(
908
+ "verify-installed",
909
+ help="Verify installed tree content against bundle-manifest.json",
910
+ )
911
+ vi.add_argument("--installed", type=Path, required=True)
912
+ vi.add_argument("--manifest", type=Path, required=True)
913
+ vi.add_argument("--json", action="store_true")
774
914
  return p
775
915
 
776
916
 
@@ -794,6 +934,43 @@ def main(argv: list[str] | None = None) -> int:
794
934
  if args.json:
795
935
  return emit_json(result)
796
936
  return 0 if result["ok"] else 1
937
+ if args.command == "generate-manifest":
938
+ entries = build_manifest(args.bundle, transformation_id=args.transformation)
939
+ manifest = {
940
+ "schemaVersion": 1,
941
+ "bundleVersion": args.bundle_version,
942
+ "bundleManifestHash": compute_bundle_manifest_hash(entries),
943
+ "files": entries,
944
+ }
945
+ text = json.dumps(manifest, ensure_ascii=False, indent=2) + "\n"
946
+ if args.out is not None:
947
+ args.out.parent.mkdir(parents=True, exist_ok=True)
948
+ args.out.write_text(text, encoding="utf-8", newline="\n")
949
+ result = {
950
+ "ok": True,
951
+ "action": "generate-manifest",
952
+ "bundleVersion": args.bundle_version,
953
+ "bundleManifestHash": manifest["bundleManifestHash"],
954
+ "fileCount": len(entries),
955
+ "out": str(args.out) if args.out is not None else None,
956
+ }
957
+ if args.json:
958
+ return emit_json(result)
959
+ if args.out is None:
960
+ print(text, end="")
961
+ return 0
962
+ if args.command == "verify-installed":
963
+ manifest_data = json.loads(args.manifest.read_text(encoding="utf-8"))
964
+ if not isinstance(manifest_data, dict):
965
+ raise ValueError("manifest must be a JSON object")
966
+ result = cmd_verify_installed(
967
+ args.installed,
968
+ manifest_data.get("files", []),
969
+ str(manifest_data.get("bundleVersion", "")),
970
+ )
971
+ if args.json:
972
+ return emit_json(result)
973
+ return 0 if result["ok"] else 1
797
974
  except (FileNotFoundError, KeyError, RuntimeError, ValueError) as exc:
798
975
  if getattr(args, "json", False):
799
976
  return emit_json({"ok": False, "error": str(exc)}, ok=False)
@@ -506,6 +506,81 @@ def new_event_id(existing: list[dict[str, Any]] | None = None) -> str:
506
506
  return f"evt-{uuid.uuid4().hex}"
507
507
 
508
508
 
509
+ def append_event(
510
+ change_dir: Path,
511
+ *,
512
+ phase: str,
513
+ type_: str,
514
+ note: str = "",
515
+ kind: str | None = None,
516
+ path: str | None = None,
517
+ run_id: str | None = None,
518
+ executor_tool: str | None = None,
519
+ ) -> dict[str, Any]:
520
+ """Programmatic append API (retro §5.31 C5/T16).
521
+
522
+ Validates and appends an event without going through argparse. Returns
523
+ a payload dict with ``ok``/``code``/``event``.
524
+ """
525
+ args = argparse.Namespace(
526
+ change_dir=str(change_dir),
527
+ phase=phase,
528
+ type=type_,
529
+ note=note,
530
+ kind=kind,
531
+ path=path,
532
+ run_id=run_id,
533
+ executor_tool=executor_tool,
534
+ command=None,
535
+ exit_code=None,
536
+ duration_ms=None,
537
+ status=None,
538
+ name=None,
539
+ code=None,
540
+ severity=None,
541
+ message=None,
542
+ decision=None,
543
+ reason=None,
544
+ issue_id=None,
545
+ scope=None,
546
+ target_event_id=None,
547
+ target_field=None,
548
+ old_value_hash=None,
549
+ new_value_json=None,
550
+ attempt=None,
551
+ executor_agent=None,
552
+ executor_model=None,
553
+ handoff_from_tool=None,
554
+ handoff_reason=None,
555
+ trace_id=None,
556
+ span_id=None,
557
+ parent_span_id=None,
558
+ runner_ms=None,
559
+ orchestration_active_ms=None,
560
+ wall_clock_ms=None,
561
+ user_wait_ms=None,
562
+ legacy_lenient=False,
563
+ json=True,
564
+ )
565
+ as_json = True
566
+ if type_ not in EVENT_TYPES:
567
+ return {"ok": False, "code": "EVENT_TYPE_INVALID", "message": f"unsupported type: {type_}"}
568
+ validation = validate_append_event(args)
569
+ if validation:
570
+ error_code, message = validation
571
+ return {"ok": False, "code": error_code, "message": message}
572
+ archived = archived_change_dir(change_dir)
573
+ if archived is not None:
574
+ return {"ok": False, "code": "ARCHIVED_CHANGE_IMMUTABLE", "message": str(archived)}
575
+ events_path_obj = events_path(change_dir)
576
+ lock_path = events_path_obj.with_name(events_path_obj.name + ".lock")
577
+ existing = []
578
+ event = build_event(args, existing)
579
+ with event_file_lock(lock_path):
580
+ atomic_append_line(events_path_obj, json.dumps(event, ensure_ascii=False))
581
+ return {"ok": True, "event": event, "events_path": str(events_path_obj), "rendered": False}
582
+
583
+
509
584
  def build_event(args: argparse.Namespace, existing: list[dict[str, Any]]) -> dict[str, Any]:
510
585
  event: dict[str, Any] = {
511
586
  "schema_version": SCHEMA_VERSION,
@@ -588,8 +663,31 @@ def validate_append_event(args: argparse.Namespace) -> tuple[str, str] | None:
588
663
  except json.JSONDecodeError as exc:
589
664
  return (
590
665
  "CORRECTION_VALUE_INVALID_JSON",
591
- f"CORRECTION_VALUE_INVALID_JSON: {exc.msg}",
666
+ f"CORRECTION_VALUE_INVALID_JSON: {exc}",
667
+ )
668
+ # Retro §5.31: artifact events must distinguish file-backed from
669
+ # informational. file-backed requires a change-relative path; informational
670
+ # (preview/summary) must not masquerade as a file artifact. Legacy kind
671
+ # values (ledger, report, etc.) are treated as file-backed aliases.
672
+ if event_type == "artifact":
673
+ kind = str(getattr(args, "kind", "") or "").strip()
674
+ path = str(getattr(args, "path", "") or "").strip()
675
+ is_informational = kind == "informational"
676
+ if kind == "file-backed" and not path:
677
+ return (
678
+ "ARTIFACT_PATH_REQUIRED",
679
+ "ARTIFACT_PATH_REQUIRED: file-backed artifact requires --path",
680
+ )
681
+ # If kind is explicitly informational, path is optional. If kind is
682
+ # absent and path is absent, reject (can't infer file-backed without path).
683
+ if not kind and not path:
684
+ return (
685
+ "ARTIFACT_PATH_REQUIRED",
686
+ "ARTIFACT_PATH_REQUIRED: artifact without --kind or --path is ambiguous; "
687
+ "use --kind informational for previews or --path for file artifacts",
592
688
  )
689
+ # If no kind is provided, infer from path presence: a path implies
690
+ # file-backed, absence implies informational (legacy compatibility).
593
691
  return None
594
692
 
595
693
 
@@ -329,6 +329,12 @@ def validate_ledger_entry_v2(entry: dict[str, Any], verification: str) -> tuple[
329
329
 
330
330
  Returns ``(missing_fields, degraded_ok)`` where ``degraded_ok`` is True only when
331
331
  the entry is a valid DEGRADED NOT_RUN record with no other missing fields.
332
+
333
+ Retro §5.14: ``status=OK``/``status=NOT_RUN``/``status=FAIL`` in the
334
+ missing list is a *status value* hint, not a field-completeness defect.
335
+ Callers consuming this under ``phase_status=FAIL`` must filter out
336
+ ``status=*`` entries from the missing list before treating them as
337
+ blocking problems.
332
338
  """
333
339
  missing: list[str] = []
334
340
  degraded = is_degraded_ledger_entry(entry)
@@ -341,7 +347,7 @@ def validate_ledger_entry_v2(entry: dict[str, Any], verification: str) -> tuple[
341
347
  missing.append("inputsFiles(non-empty)")
342
348
  elif field == "status":
343
349
  if value != "OK" and not degraded:
344
- missing.append("status=OK")
350
+ missing.append(f"status={value}")
345
351
  elif not (isinstance(value, str) and value.strip()):
346
352
  missing.append(field)
347
353
  elif field == "coverage" and str(value).strip() not in hl.COVERAGE_RANK:
@@ -357,8 +363,16 @@ def validate_ledger_for_phase_close(
357
363
  policy: dict[str, Any],
358
364
  *,
359
365
  execution_root: Path | None = None,
366
+ phase_status: str = "OK",
360
367
  ) -> dict[str, Any]:
361
- """Validate ledger v2 fields required for phase close (UT-026)."""
368
+ """Validate ledger v2 fields required for phase close (UT-026).
369
+
370
+ Retro §5.14: ``phase_status`` separates phase outcome from promotion gate.
371
+ ``phase_status=OK`` (default) requires all required validations to be OK;
372
+ ``phase_status=FAIL`` validates field completeness and identity but allows
373
+ individual validation status to be FAIL/NOT_RUN, so a failing phase can
374
+ close honestly without polluting evidence or blocking lease release.
375
+ """
362
376
  required = policy.get("requiredValidations", {}).get(phase, [])
363
377
  if not required:
364
378
  return {"ok": True, "code": "LEDGER_NOT_REQUIRED", "phase": phase}
@@ -443,6 +457,7 @@ def validate_ledger_for_phase_close(
443
457
 
444
458
  problems: list[dict[str, Any]] = []
445
459
  degraded: list[str] = []
460
+ fail_status: list[str] = []
446
461
  for verification in required:
447
462
  entry = validations.get(verification)
448
463
  if not isinstance(entry, dict):
@@ -455,6 +470,12 @@ def validate_ledger_for_phase_close(
455
470
  )
456
471
  continue
457
472
  missing, is_degraded = validate_ledger_entry_v2(entry, verification)
473
+ # Retro §5.14: under phase_status=FAIL/WARN, status value hints
474
+ # (status=FAIL, status=NOT_RUN) are acceptable; only real field-
475
+ # completeness defects block close. Under phase_status=OK, status
476
+ # value hints are blocking.
477
+ if phase_status.upper() in {"FAIL", "WARN"}:
478
+ missing = [m for m in missing if not m.startswith("status=")]
458
479
  if missing:
459
480
  code = (
460
481
  "MISSING_V2_FIELDS"
@@ -476,8 +497,21 @@ def validate_ledger_for_phase_close(
476
497
  "code": code,
477
498
  }
478
499
  )
479
- elif is_degraded:
500
+ continue
501
+ if is_degraded:
480
502
  degraded.append(verification)
503
+ continue
504
+ # Under phase_status=FAIL/WARN, a FAIL/NOT_RUN status is acceptable.
505
+ entry_status = str(entry.get("status") or "").upper()
506
+ if entry_status in {"FAIL", "NOT_RUN"}:
507
+ if phase_status.upper() in {"FAIL", "WARN"}:
508
+ fail_status.append(verification)
509
+ else:
510
+ problems.append({
511
+ "verification": verification,
512
+ "missing": [f"status={entry_status}"],
513
+ "code": "VALIDATION_NOT_OK",
514
+ })
481
515
 
482
516
  if problems:
483
517
  return {
@@ -489,6 +523,16 @@ def validate_ledger_for_phase_close(
489
523
  "ledgerPath": str(ledger_path) if ledger_path else None,
490
524
  "detail": "natural-language override is not permitted",
491
525
  }
526
+ if fail_status:
527
+ return {
528
+ "ok": True,
529
+ "code": "LEDGER_OK_FAIL",
530
+ "phase": phase,
531
+ "validated": required,
532
+ "failed": fail_status,
533
+ "degraded": degraded,
534
+ "ledgerPath": str(ledger_path) if ledger_path else None,
535
+ }
492
536
  if degraded:
493
537
  return {
494
538
  "ok": True,
@@ -1169,6 +1213,14 @@ def cmd_begin(args: argparse.Namespace) -> int:
1169
1213
  extra={k: v for k, v in resolved.items() if k not in {"ok", "message"}},
1170
1214
  )
1171
1215
  change_dir = Path(resolved["changeDir"])
1216
+ concurrency_block = hc.check_concurrency_block(project, resolved["changeId"])
1217
+ if concurrency_block is not None:
1218
+ return emit_error(
1219
+ str(concurrency_block.get("code", "CONCURRENCY_BLOCKED")),
1220
+ str(concurrency_block.get("message", "concurrency mode blocked begin")),
1221
+ as_json=as_json,
1222
+ extra={k: v for k, v in concurrency_block.items() if k not in {"ok", "message"}},
1223
+ )
1172
1224
  blocked = foundation_gate_blocks(getattr(args, "task", None), change_dir)
1173
1225
  if blocked:
1174
1226
  return emit_error(
@@ -1407,7 +1459,8 @@ def cmd_close(args: argparse.Namespace) -> int:
1407
1459
  return emit_error("PHASE_CAPSULE_MISMATCH", str(exc), as_json=as_json)
1408
1460
 
1409
1461
  ledger_result = validate_ledger_for_phase_close(
1410
- change_dir, args.phase, policy, execution_root=execution_root
1462
+ change_dir, args.phase, policy, execution_root=execution_root,
1463
+ phase_status=args.status,
1411
1464
  )
1412
1465
  if not ledger_result.get("ok") and args.phase in {"run", "test", "package"}:
1413
1466
  return emit_error(
@@ -422,6 +422,9 @@ class IntegrationTransaction:
422
422
  else:
423
423
  result = hl.record_integration_hashes(
424
424
  ledger_path,
425
+ change_dir=(
426
+ self.project_root / ".harness" / "changes" / self.change_id
427
+ ),
425
428
  repository_id=str(journal["repositoryId"]),
426
429
  merge_final_hash=merge_commit,
427
430
  ci_expected_head=merge_commit,
@@ -621,12 +621,13 @@ def validate_ledger_identity(ledger: dict[str, Any]) -> list[str]:
621
621
  def record_integration_hashes(
622
622
  ledger_path: Path,
623
623
  *,
624
+ change_dir: Path | None = None,
624
625
  repository_id: str,
625
626
  merge_final_hash: str,
626
627
  ci_expected_head: str,
627
628
  remote_head: str,
628
629
  ) -> dict[str, Any]:
629
- """Atomically attach post-push identity to an existing ledger v3."""
630
+ """Atomically attach post-push hashes using the change contract's ledger rules."""
630
631
  path = Path(ledger_path).resolve()
631
632
  if not path.is_file():
632
633
  return {"ok": False, "code": "LEDGER_MISSING", "ledgerPath": str(path)}
@@ -637,15 +638,26 @@ def record_integration_hashes(
637
638
  "ok": False, "code": "LEDGER_INVALID", "ledgerPath": str(path),
638
639
  "message": str(exc),
639
640
  }
641
+ legacy_contract = False
642
+ if change_dir is not None:
643
+ resolved_change_dir = Path(change_dir).resolve()
644
+ if ledger.get("changeName") != resolved_change_dir.name:
645
+ return {
646
+ "ok": False,
647
+ "code": "LEDGER_CHANGE_MISMATCH",
648
+ "ledgerPath": str(path),
649
+ }
650
+ legacy_contract = not _contract_is_v2(resolved_change_dir)
651
+
640
652
  missing = validate_ledger_identity(ledger)
641
- if missing:
653
+ if missing and not legacy_contract:
642
654
  return {
643
655
  "ok": False,
644
656
  "code": "LEDGER_IDENTITY_INVALID",
645
657
  "ledgerPath": str(path),
646
658
  "missing": missing,
647
659
  }
648
- if ledger.get("repositoryId") != repository_id:
660
+ if not missing and ledger.get("repositoryId") != repository_id:
649
661
  return {
650
662
  "ok": False,
651
663
  "code": "LEDGER_REPOSITORY_MISMATCH",
@@ -29,6 +29,7 @@ if hasattr(sys.stderr, "reconfigure"):
29
29
  sys.stderr.reconfigure(encoding="utf-8")
30
30
 
31
31
 
32
+ import harness_change as hc # noqa: E402
32
33
  import harness_profile as hprof # noqa: E402
33
34
 
34
35
 
@@ -69,6 +70,52 @@ def cmd_check(project: Path) -> dict[str, Any]:
69
70
  return result
70
71
 
71
72
 
73
+ def check_concurrency(project: Path) -> dict[str, Any]:
74
+ """Report the configured concurrency mode and active Change landscape.
75
+
76
+ Retro §5.2: preflight must surface concurrencyMode, activeChanges, and
77
+ allowedParallelLevels so agents don't have to guess whether parallel
78
+ Changes are supported.
79
+ """
80
+ mode = hc.read_concurrency_mode(project)
81
+ active = hc.list_active_changes(project)
82
+ shared_conflicts: list[dict[str, Any]] = []
83
+ # In isolated-multi-active, surface any shared-state conflicts (e.g. same
84
+ # worktree path) so callers know isolation is incomplete.
85
+ if mode == "isolated-multi-active" and len(active) > 1:
86
+ seen_worktrees: dict[str, str] = {}
87
+ for entry in active:
88
+ change_dir = Path(entry["path"])
89
+ worktree_meta = change_dir / "meta" / "worktree.json"
90
+ if not worktree_meta.is_file():
91
+ continue
92
+ try:
93
+ meta = json.loads(worktree_meta.read_text(encoding="utf-8"))
94
+ except (OSError, json.JSONDecodeError):
95
+ continue
96
+ wt = meta.get("path") if isinstance(meta, dict) else None
97
+ if isinstance(wt, str) and wt:
98
+ if wt in seen_worktrees:
99
+ shared_conflicts.append({
100
+ "kind": "worktree",
101
+ "path": wt,
102
+ "changes": [seen_worktrees[wt], entry["changeId"]],
103
+ })
104
+ else:
105
+ seen_worktrees[wt] = entry["changeId"]
106
+ levels = ["change-internal"] if mode == "single-active" else [
107
+ "change-internal",
108
+ "multi-change",
109
+ ]
110
+ return {
111
+ "ok": True,
112
+ "concurrencyMode": mode,
113
+ "activeChanges": active,
114
+ "sharedStateConflicts": shared_conflicts,
115
+ "allowedParallelLevels": levels,
116
+ }
117
+
118
+
72
119
  # ---------------------------------------------------------------------------
73
120
  # record-quirk — 适配 v2 commands(source=user override)
74
121
  # ---------------------------------------------------------------------------