@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.
- package/harness/bundles/general/claude-code/.harness-build.json +1 -1
- package/harness/bundles/general/claude-code/README.md +7 -7
- package/harness/bundles/general/claude-code/harness-archive/SKILL.md +35 -35
- package/harness/bundles/general/claude-code/harness-archive/checklist.md +5 -2
- package/harness/bundles/general/claude-code/harness-archive/reference.md +23 -7
- package/harness/bundles/general/claude-code/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/general/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/general/claude-code/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/general/claude-code/harness-plan/SKILL.md +4 -4
- package/harness/bundles/general/claude-code/harness-review/SKILL.md +2 -2
- package/harness/bundles/general/claude-code/harness-run/SKILL.md +2 -2
- package/harness/bundles/general/claude-code/harness-submit/SKILL.md +2 -2
- package/harness/bundles/general/claude-code/harness-sync/SKILL.md +1 -1
- package/harness/bundles/general/claude-code/harness-test/SKILL.md +2 -2
- package/harness/bundles/general/claude-code/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/general/claude-code/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/general/claude-code/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/general/claude-code/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/general/claude-code/scripts/harness_archive.py +829 -68
- package/harness/bundles/general/claude-code/scripts/harness_context.py +8 -2
- package/harness/bundles/general/claude-code/scripts/harness_events.py +5 -0
- package/harness/bundles/general/claude-code/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/general/claude-code/scripts/harness_ledger.py +79 -2
- package/harness/bundles/general/claude-code/scripts/harness_profile.py +7 -0
- package/harness/bundles/general/claude-code/scripts/harness_state.py +22 -3
- package/harness/bundles/general/codebuddy/.harness-build.json +1 -1
- package/harness/bundles/general/codebuddy/README.md +7 -7
- package/harness/bundles/general/codebuddy/harness-archive/SKILL.md +35 -35
- package/harness/bundles/general/codebuddy/harness-archive/checklist.md +5 -2
- package/harness/bundles/general/codebuddy/harness-archive/reference.md +23 -7
- package/harness/bundles/general/codebuddy/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/general/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/general/codebuddy/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/general/codebuddy/harness-plan/SKILL.md +4 -4
- package/harness/bundles/general/codebuddy/harness-review/SKILL.md +2 -2
- package/harness/bundles/general/codebuddy/harness-run/SKILL.md +2 -2
- package/harness/bundles/general/codebuddy/harness-submit/SKILL.md +2 -2
- package/harness/bundles/general/codebuddy/harness-sync/SKILL.md +1 -1
- package/harness/bundles/general/codebuddy/harness-test/SKILL.md +2 -2
- package/harness/bundles/general/codebuddy/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/general/codebuddy/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/general/codebuddy/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/general/codebuddy/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/general/codebuddy/scripts/harness_archive.py +829 -68
- package/harness/bundles/general/codebuddy/scripts/harness_context.py +8 -2
- package/harness/bundles/general/codebuddy/scripts/harness_events.py +5 -0
- package/harness/bundles/general/codebuddy/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/general/codebuddy/scripts/harness_ledger.py +79 -2
- package/harness/bundles/general/codebuddy/scripts/harness_profile.py +7 -0
- package/harness/bundles/general/codebuddy/scripts/harness_state.py +22 -3
- package/harness/bundles/general/codex/.harness-build.json +1 -1
- package/harness/bundles/general/codex/README.md +7 -7
- package/harness/bundles/general/codex/harness-archive/SKILL.md +35 -35
- package/harness/bundles/general/codex/harness-archive/checklist.md +5 -2
- package/harness/bundles/general/codex/harness-archive/reference.md +23 -7
- package/harness/bundles/general/codex/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/general/codex/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/general/codex/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/general/codex/harness-plan/SKILL.md +4 -4
- package/harness/bundles/general/codex/harness-review/SKILL.md +2 -2
- package/harness/bundles/general/codex/harness-run/SKILL.md +2 -2
- package/harness/bundles/general/codex/harness-submit/SKILL.md +2 -2
- package/harness/bundles/general/codex/harness-sync/SKILL.md +1 -1
- package/harness/bundles/general/codex/harness-test/SKILL.md +2 -2
- package/harness/bundles/general/codex/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/general/codex/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/general/codex/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/general/codex/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/general/codex/scripts/harness_archive.py +829 -68
- package/harness/bundles/general/codex/scripts/harness_context.py +8 -2
- package/harness/bundles/general/codex/scripts/harness_events.py +5 -0
- package/harness/bundles/general/codex/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/general/codex/scripts/harness_ledger.py +79 -2
- package/harness/bundles/general/codex/scripts/harness_profile.py +7 -0
- package/harness/bundles/general/codex/scripts/harness_state.py +22 -3
- package/harness/bundles/general/cursor/.harness-build.json +1 -1
- package/harness/bundles/general/cursor/README.md +7 -7
- package/harness/bundles/general/cursor/harness-archive/SKILL.md +35 -35
- package/harness/bundles/general/cursor/harness-archive/checklist.md +5 -2
- package/harness/bundles/general/cursor/harness-archive/reference.md +23 -7
- package/harness/bundles/general/cursor/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/general/cursor/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/general/cursor/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/general/cursor/harness-plan/SKILL.md +4 -4
- package/harness/bundles/general/cursor/harness-review/SKILL.md +2 -2
- package/harness/bundles/general/cursor/harness-run/SKILL.md +2 -2
- package/harness/bundles/general/cursor/harness-submit/SKILL.md +2 -2
- package/harness/bundles/general/cursor/harness-sync/SKILL.md +1 -1
- package/harness/bundles/general/cursor/harness-test/SKILL.md +2 -2
- package/harness/bundles/general/cursor/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/general/cursor/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/general/cursor/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/general/cursor/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/general/cursor/scripts/harness_archive.py +829 -68
- package/harness/bundles/general/cursor/scripts/harness_context.py +8 -2
- package/harness/bundles/general/cursor/scripts/harness_events.py +5 -0
- package/harness/bundles/general/cursor/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/general/cursor/scripts/harness_ledger.py +79 -2
- package/harness/bundles/general/cursor/scripts/harness_profile.py +7 -0
- package/harness/bundles/general/cursor/scripts/harness_state.py +22 -3
- package/harness/bundles/java/claude-code/.harness-build.json +1 -1
- package/harness/bundles/java/claude-code/README.md +7 -7
- package/harness/bundles/java/claude-code/harness-apidoc/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/harness-archive/SKILL.md +35 -35
- package/harness/bundles/java/claude-code/harness-archive/checklist.md +5 -2
- package/harness/bundles/java/claude-code/harness-archive/reference.md +23 -7
- package/harness/bundles/java/claude-code/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/java/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/java/claude-code/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/java/claude-code/harness-package/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/harness-plan/SKILL.md +4 -4
- package/harness/bundles/java/claude-code/harness-review/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/harness-run/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/harness-submit/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/harness-sync/SKILL.md +1 -1
- package/harness/bundles/java/claude-code/harness-test/SKILL.md +2 -2
- package/harness/bundles/java/claude-code/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/java/claude-code/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/java/claude-code/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/java/claude-code/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/java/claude-code/scripts/harness_archive.py +829 -68
- package/harness/bundles/java/claude-code/scripts/harness_context.py +8 -2
- package/harness/bundles/java/claude-code/scripts/harness_events.py +5 -0
- package/harness/bundles/java/claude-code/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/java/claude-code/scripts/harness_ledger.py +79 -2
- package/harness/bundles/java/claude-code/scripts/harness_profile.py +7 -0
- package/harness/bundles/java/claude-code/scripts/harness_state.py +22 -3
- package/harness/bundles/java/codebuddy/.harness-build.json +1 -1
- package/harness/bundles/java/codebuddy/README.md +7 -7
- package/harness/bundles/java/codebuddy/harness-apidoc/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/harness-archive/SKILL.md +35 -35
- package/harness/bundles/java/codebuddy/harness-archive/checklist.md +5 -2
- package/harness/bundles/java/codebuddy/harness-archive/reference.md +23 -7
- package/harness/bundles/java/codebuddy/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/java/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/java/codebuddy/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/java/codebuddy/harness-package/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/harness-plan/SKILL.md +4 -4
- package/harness/bundles/java/codebuddy/harness-review/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/harness-run/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/harness-submit/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/harness-sync/SKILL.md +1 -1
- package/harness/bundles/java/codebuddy/harness-test/SKILL.md +2 -2
- package/harness/bundles/java/codebuddy/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/java/codebuddy/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/java/codebuddy/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/java/codebuddy/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/java/codebuddy/scripts/harness_archive.py +829 -68
- package/harness/bundles/java/codebuddy/scripts/harness_context.py +8 -2
- package/harness/bundles/java/codebuddy/scripts/harness_events.py +5 -0
- package/harness/bundles/java/codebuddy/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/java/codebuddy/scripts/harness_ledger.py +79 -2
- package/harness/bundles/java/codebuddy/scripts/harness_profile.py +7 -0
- package/harness/bundles/java/codebuddy/scripts/harness_state.py +22 -3
- package/harness/bundles/java/codex/.harness-build.json +1 -1
- package/harness/bundles/java/codex/README.md +7 -7
- package/harness/bundles/java/codex/harness-apidoc/SKILL.md +2 -2
- package/harness/bundles/java/codex/harness-archive/SKILL.md +35 -35
- package/harness/bundles/java/codex/harness-archive/checklist.md +5 -2
- package/harness/bundles/java/codex/harness-archive/reference.md +23 -7
- package/harness/bundles/java/codex/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/java/codex/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/java/codex/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/java/codex/harness-package/SKILL.md +2 -2
- package/harness/bundles/java/codex/harness-plan/SKILL.md +4 -4
- package/harness/bundles/java/codex/harness-review/SKILL.md +2 -2
- package/harness/bundles/java/codex/harness-run/SKILL.md +2 -2
- package/harness/bundles/java/codex/harness-submit/SKILL.md +2 -2
- package/harness/bundles/java/codex/harness-sync/SKILL.md +1 -1
- package/harness/bundles/java/codex/harness-test/SKILL.md +2 -2
- package/harness/bundles/java/codex/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/java/codex/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/java/codex/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/java/codex/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/java/codex/scripts/harness_archive.py +829 -68
- package/harness/bundles/java/codex/scripts/harness_context.py +8 -2
- package/harness/bundles/java/codex/scripts/harness_events.py +5 -0
- package/harness/bundles/java/codex/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/java/codex/scripts/harness_ledger.py +79 -2
- package/harness/bundles/java/codex/scripts/harness_profile.py +7 -0
- package/harness/bundles/java/codex/scripts/harness_state.py +22 -3
- package/harness/bundles/java/cursor/.harness-build.json +1 -1
- package/harness/bundles/java/cursor/README.md +7 -7
- package/harness/bundles/java/cursor/harness-apidoc/SKILL.md +2 -2
- package/harness/bundles/java/cursor/harness-archive/SKILL.md +35 -35
- package/harness/bundles/java/cursor/harness-archive/checklist.md +5 -2
- package/harness/bundles/java/cursor/harness-archive/reference.md +23 -7
- package/harness/bundles/java/cursor/harness-codebase-map/SKILL.md +1 -1
- package/harness/bundles/java/cursor/harness-knowledge-ingest/SKILL.md +1 -1
- package/harness/bundles/java/cursor/harness-knowledge-query/SKILL.md +1 -1
- package/harness/bundles/java/cursor/harness-package/SKILL.md +2 -2
- package/harness/bundles/java/cursor/harness-plan/SKILL.md +4 -4
- package/harness/bundles/java/cursor/harness-review/SKILL.md +2 -2
- package/harness/bundles/java/cursor/harness-run/SKILL.md +2 -2
- package/harness/bundles/java/cursor/harness-submit/SKILL.md +2 -2
- package/harness/bundles/java/cursor/harness-sync/SKILL.md +1 -1
- package/harness/bundles/java/cursor/harness-test/SKILL.md +2 -2
- package/harness/bundles/java/cursor/protocols/archive-report-protocol.md +7 -3
- package/harness/bundles/java/cursor/protocols/ledger-protocol.md +1 -1
- package/harness/bundles/java/cursor/protocols/report-pipeline-protocol.md +6 -4
- package/harness/bundles/java/cursor/protocols/state-layout-protocol.md +3 -2
- package/harness/bundles/java/cursor/scripts/harness_archive.py +829 -68
- package/harness/bundles/java/cursor/scripts/harness_context.py +8 -2
- package/harness/bundles/java/cursor/scripts/harness_events.py +5 -0
- package/harness/bundles/java/cursor/scripts/harness_events_sync.py +191 -26
- package/harness/bundles/java/cursor/scripts/harness_ledger.py +79 -2
- package/harness/bundles/java/cursor/scripts/harness_profile.py +7 -0
- package/harness/bundles/java/cursor/scripts/harness_state.py +22 -3
- package/harness/manifests/general/claude-code.json +27 -27
- package/harness/manifests/general/codebuddy.json +27 -27
- package/harness/manifests/general/codex.json +27 -27
- package/harness/manifests/general/cursor.json +27 -27
- package/harness/manifests/java/claude-code.json +29 -29
- package/harness/manifests/java/codebuddy.json +29 -29
- package/harness/manifests/java/codex.json +29 -29
- package/harness/manifests/java/cursor.json +29 -29
- package/hunter-workflow-family.json +5 -5
- 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 [
|
|
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(
|
|
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
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
|
418
|
+
if acked > maximum_lines:
|
|
419
|
+
acked = 0
|
|
378
420
|
valid = False
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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(
|
|
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({
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
2841
|
+
change_dir_raw = getattr(args, "change_dir", None)
|
|
2799
2842
|
try:
|
|
2800
|
-
|
|
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
|
-
|
|
254
|
-
|
|
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,
|