prizmkit 1.1.191 → 1.1.192

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 (169) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/adapters/antigravity/skill-adapter.js +13 -4
  3. package/bundled/adapters/codex/skill-adapter.js +28 -8
  4. package/bundled/adapters/cursor/skill-adapter.js +13 -4
  5. package/bundled/adapters/pi/skill-adapter.js +28 -7
  6. package/bundled/dev-pipeline/.env.example +4 -12
  7. package/bundled/dev-pipeline/README.md +5 -10
  8. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -6
  9. package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
  10. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
  11. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
  12. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
  13. package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -76
  14. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
  15. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +77 -430
  16. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
  17. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
  18. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
  19. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +36 -14
  20. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
  21. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
  22. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
  23. package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
  24. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
  25. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
  26. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
  27. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
  28. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
  29. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +276 -217
  30. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
  31. package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
  32. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +183 -130
  33. package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
  34. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
  35. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
  36. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
  37. package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
  38. package/bundled/dev-pipeline/scripts/continuation.py +6 -4
  39. package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
  40. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
  41. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
  42. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
  43. package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
  44. package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
  45. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
  46. package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
  47. package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
  48. package/bundled/dev-pipeline/scripts/status_common.py +591 -0
  49. package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
  50. package/bundled/dev-pipeline/scripts/update-checkpoint.py +227 -65
  51. package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
  52. package/bundled/dev-pipeline/scripts/utils.py +5 -12
  53. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
  54. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
  55. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
  56. package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
  57. package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
  58. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
  59. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
  60. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
  61. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
  62. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
  63. package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
  64. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
  65. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
  66. package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
  67. package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
  68. package/bundled/dev-pipeline/tests/_helpers.py +418 -0
  69. package/bundled/dev-pipeline/tests/conftest.py +45 -1
  70. package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
  71. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
  72. package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
  73. package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
  74. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
  75. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
  76. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +431 -3099
  77. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
  78. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
  79. package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
  80. package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
  81. package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
  82. package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
  83. package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
  84. package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
  85. package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
  86. package/bundled/dev-pipeline/tests/test_unified_cli.py +155 -2034
  87. package/bundled/dev-pipeline/tests/test_utils.py +3 -3
  88. package/bundled/skills/_metadata.json +9 -63
  89. package/bundled/skills/app-planner/SKILL.md +32 -303
  90. package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
  91. package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
  92. package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
  93. package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
  94. package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
  95. package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
  96. package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
  97. package/bundled/skills/bug-planner/SKILL.md +54 -435
  98. package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
  99. package/bundled/skills/bug-planner/references/input-formats.md +32 -0
  100. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
  101. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
  102. package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
  103. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
  104. package/bundled/skills/feature-planner/SKILL.md +60 -439
  105. package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
  106. package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
  107. package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
  108. package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
  109. package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
  110. package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
  111. package/bundled/skills/feature-workflow/SKILL.md +1 -2
  112. package/bundled/skills/prizmkit/SKILL.md +7 -1
  113. package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
  114. package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
  115. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
  116. package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
  117. package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
  118. package/bundled/skills/prizmkit-init/SKILL.md +24 -127
  119. package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
  120. package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
  121. package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
  122. package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
  123. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
  124. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
  125. package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
  126. package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
  127. package/bundled/skills/prizmkit-test/SKILL.md +25 -133
  128. package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
  129. package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
  130. package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
  131. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
  132. package/bundled/skills/recovery-workflow/SKILL.md +7 -7
  133. package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
  134. package/bundled/skills/recovery-workflow/references/detection.md +1 -3
  135. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
  136. package/bundled/templates/project-memory-template.md +1 -2
  137. package/package.json +1 -1
  138. package/src/scaffold.js +28 -7
  139. package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
  140. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
  141. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
  142. package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
  143. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
  144. package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
  145. package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
  146. package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
  147. package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
  148. package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
  149. package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
  150. package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
  151. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
  152. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
  153. package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
  154. package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
  155. package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
  156. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
  157. package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
  158. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
  159. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
  160. package/bundled/skills/refactor-planner/SKILL.md +0 -467
  161. package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
  162. package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
  163. package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
  164. package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
  165. package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
  166. package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
  167. package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
  168. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
  169. package/bundled/skills/refactor-workflow/SKILL.md +0 -205
@@ -5,13 +5,13 @@ import argparse
5
5
  import json
6
6
  import os
7
7
  import sys
8
- import tempfile
9
8
  from pathlib import Path
10
9
 
11
10
  _PIPELINE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
12
11
  if _PIPELINE_ROOT not in sys.path:
13
12
  sys.path.insert(0, _PIPELINE_ROOT)
14
13
 
14
+ from prizmkit_runtime.atomic_io import write_json_atomic # noqa: E402
15
15
  from prizmkit_runtime.checkpoint_state import ( # noqa: E402
16
16
  MAX_OUTER_REPAIR_ROUNDS,
17
17
  PLAN_RESULTS,
@@ -25,13 +25,26 @@ from prizmkit_runtime.checkpoint_state import ( # noqa: E402
25
25
  VALID_REPAIR_SCOPES,
26
26
  VALID_TERMINAL_STATUSES,
27
27
  expected_status_for_stage_result,
28
+ infer_project_root,
29
+ required_step_artifacts_valid,
28
30
  stage_result_allowed_for_skill,
29
31
  load_checkpoint_state,
30
32
  semantic_state_key,
31
33
  validate_checkpoint_data,
32
34
  )
35
+ from prizmkit_runtime.test_result import test_pass_requires_delta_review # noqa: E402
33
36
 
34
37
  VALID_STATUSES = VALID_CHECKPOINT_STATUSES
38
+ _BLOCKING_STAGE_RESULTS = frozenset({
39
+ "PLAN_BLOCKED",
40
+ "IMPLEMENT_REPAIR",
41
+ "IMPLEMENT_BLOCKED",
42
+ "REVIEW_NEEDS_FIXES",
43
+ "TEST_NEEDS_FIXES",
44
+ "TEST_BLOCKED",
45
+ "RETRO_BLOCKED",
46
+ "COMMIT_BLOCKED",
47
+ })
35
48
 
36
49
 
37
50
  def _load_checkpoint(path):
@@ -53,23 +66,10 @@ def _load_checkpoint(path):
53
66
 
54
67
 
55
68
  def _write_checkpoint(path, data):
56
- """Write checkpoint JSON atomically using a temp file and rename."""
57
- parent = os.path.dirname(os.path.abspath(path))
58
- if parent and not os.path.isdir(parent):
59
- os.makedirs(parent, exist_ok=True)
60
-
61
- tmp_path = None
69
+ """Write checkpoint JSON atomically using shared atomic_io."""
62
70
  try:
63
- fd, tmp_path = tempfile.mkstemp(
64
- dir=parent, suffix=".tmp", prefix=".checkpoint-"
65
- )
66
- with os.fdopen(fd, "w", encoding="utf-8") as f:
67
- json.dump(data, f, indent=2, ensure_ascii=False)
68
- f.write("\n")
69
- os.replace(tmp_path, os.path.abspath(path))
71
+ write_json_atomic(path, data)
70
72
  except (IOError, OSError) as exc:
71
- if tmp_path is not None and os.path.exists(tmp_path):
72
- os.unlink(tmp_path)
73
73
  return "Cannot write file: {}".format(exc)
74
74
  return None
75
75
 
@@ -106,7 +106,7 @@ def _predecessors_terminal(steps, index):
106
106
 
107
107
 
108
108
  def _mandatory_predecessor_verdict_error(steps, index, workflow_type):
109
- if workflow_type not in {"feature-pipeline", "bugfix-pipeline", "refactor-pipeline"}:
109
+ if workflow_type not in {"feature-pipeline", "bugfix-pipeline"}:
110
110
  return None
111
111
  preceding = steps[:index]
112
112
  review = next((item for item in preceding if item.get("skill") == "prizmkit-code-review"), None)
@@ -124,7 +124,7 @@ def _mandatory_predecessor_verdict_error(steps, index, workflow_type):
124
124
  if skill == "prizmkit-test":
125
125
  if not review or review.get("status") != "completed" or review.get("stage_result") != "REVIEW_PASS":
126
126
  return "Test stage requires a completed REVIEW_PASS predecessor"
127
- if skill in {"prizmkit-retrospective", "prizmkit-committer", "completion-summary", "bug-report", "refactor-report"}:
127
+ if skill in {"prizmkit-retrospective", "prizmkit-committer", "completion-summary", "bug-report"}:
128
128
  if not review or review.get("status") != "completed" or review.get("stage_result") != "REVIEW_PASS":
129
129
  return "Finalization requires a completed REVIEW_PASS predecessor"
130
130
  if not test or test.get("status") != "completed" or test.get("stage_result") != "TEST_PASS":
@@ -162,7 +162,7 @@ def _validate_semantic_update(step, semantic_update):
162
162
  if terminal_status is not None and terminal_status not in VALID_TERMINAL_STATUSES:
163
163
  return "Invalid terminal_status '{}'".format(terminal_status)
164
164
  blocked_reason = semantic_update.get("blocked_reason")
165
- blocked_policy_result = stage_result in {"TEST_NEEDS_FIXES", "TEST_BLOCKED"}
165
+ blocked_policy_result = stage_result in _BLOCKING_STAGE_RESULTS
166
166
  if terminal_status == "WORKFLOW_COMPLETED" and blocked_policy_result:
167
167
  return "WORKFLOW_COMPLETED conflicts with blocking stage result {}".format(stage_result)
168
168
  if blocked_reason is not None:
@@ -188,6 +188,7 @@ def _apply_repair_policy(l4_state, stage_result, repair_scope):
188
188
  }
189
189
  if stage_result in terminal_blockers:
190
190
  l4_state.update(
191
+ repair_scope=None,
191
192
  terminal_status="WORKFLOW_BLOCKED",
192
193
  blocked_reason=terminal_blockers[stage_result],
193
194
  current_stage=None,
@@ -210,6 +211,7 @@ def _apply_repair_policy(l4_state, stage_result, repair_scope):
210
211
  return False
211
212
  if repair_scope not in VALID_REPAIR_SCOPES:
212
213
  l4_state.update(
214
+ repair_scope=None,
213
215
  terminal_status="WORKFLOW_BLOCKED",
214
216
  blocked_reason="unsafe_repair_scope",
215
217
  current_stage=None,
@@ -262,11 +264,36 @@ def _sync_cursor(data, l4_state, preserve_next_stage=False):
262
264
 
263
265
  def _checkpoint_project_root(checkpoint_path):
264
266
  """Resolve the project root from a conventional .prizmkit checkpoint path."""
265
- path = Path(os.path.abspath(checkpoint_path))
266
- for parent in (path.parent, *path.parents):
267
- if parent.name == ".prizmkit":
268
- return str(parent.parent)
269
- return str(path.parent)
267
+ return str(infer_project_root(Path(checkpoint_path)))
268
+
269
+
270
+ def _test_step_artifact_paths(checkpoint_path, step):
271
+ """Resolve declared sibling test-report.md and test-result.json paths safely."""
272
+ if not step or step.get("skill") != "prizmkit-test":
273
+ return None
274
+ artifacts = step.get("required_artifacts") or ()
275
+ reports = [item for item in artifacts if isinstance(item, str) and item.endswith("/test-report.md")]
276
+ results = [item for item in artifacts if isinstance(item, str) and item.endswith("/test-result.json")]
277
+ if len(reports) != 1 or len(results) != 1:
278
+ return None
279
+ project_root = Path(_checkpoint_project_root(checkpoint_path)).resolve()
280
+ report_path = (project_root / reports[0]).resolve()
281
+ result_path = (project_root / results[0]).resolve()
282
+ try:
283
+ report_path.relative_to(project_root)
284
+ result_path.relative_to(project_root)
285
+ except ValueError:
286
+ return None
287
+ return report_path, result_path
288
+
289
+
290
+ def _declared_test_pass_changed_production(checkpoint_path, step):
291
+ """Return whether a prizmkit-test step produced TEST_PASS with production_changed=true."""
292
+ paths = _test_step_artifact_paths(checkpoint_path, step)
293
+ if paths is None:
294
+ return False
295
+ report_path, result_path = paths
296
+ return test_pass_requires_delta_review(report_path, result_path)
270
297
 
271
298
 
272
299
  def _declared_runtime_request_exists(checkpoint_path, step):
@@ -287,6 +314,40 @@ def _declared_runtime_request_exists(checkpoint_path, step):
287
314
  return False
288
315
 
289
316
 
317
+ def _persist_validated_checkpoint(checkpoint_path, data, target_step, old_status, new_status):
318
+ """Validate and atomically write an updated checkpoint payload."""
319
+ final_state = validate_checkpoint_data(
320
+ data,
321
+ path=checkpoint_path,
322
+ exists=True,
323
+ project_root=_checkpoint_project_root(checkpoint_path),
324
+ )
325
+ if not final_state.valid or final_state.semantic.error_code:
326
+ error_code = final_state.error_code or final_state.semantic.error_code
327
+ error_message = final_state.error_message or final_state.semantic.error_message
328
+ return {
329
+ "ok": False,
330
+ "error": "Update would create invalid checkpoint ({}): {}".format(
331
+ error_code, error_message
332
+ ),
333
+ }
334
+
335
+ err = _write_checkpoint(checkpoint_path, data)
336
+ if err:
337
+ return {"ok": False, "error": err}
338
+
339
+ prompt_semantic = dict(final_state.semantic_snapshot)
340
+ prompt_semantic.pop("commit_ready", None)
341
+ return {
342
+ "ok": True,
343
+ "step_id": target_step.get("id"),
344
+ "skill": target_step.get("skill"),
345
+ "old_status": old_status,
346
+ "new_status": new_status,
347
+ "semantic": prompt_semantic,
348
+ }
349
+
350
+
290
351
  def _finalize_semantics(checkpoint_path, data, state_key):
291
352
  """Derive a deterministic terminal status after an atomic mutation."""
292
353
  candidate = validate_checkpoint_data(
@@ -372,27 +433,111 @@ def update_checkpoint(
372
433
  if semantic_error:
373
434
  return {"ok": False, "error": semantic_error}
374
435
 
375
- stage_result = semantic_update.get("stage_result")
376
- if stage_result == "COMMIT_BLOCKED" and _declared_runtime_request_exists(checkpoint_path, step):
436
+ workflow_type = str(data.get("workflow_type") or "")
437
+ state_key = semantic_state_key(workflow_type)
438
+ l4_state = data.setdefault(state_key, {})
439
+ if not isinstance(l4_state, dict):
440
+ return {"ok": False, "error": "Invalid semantic state object '{}'".format(state_key)}
441
+
442
+ if l4_state.get("terminal_status") == "WORKFLOW_BLOCKED":
377
443
  return {
378
444
  "ok": False,
379
445
  "error": (
380
- "A Runtime commit request already exists; the Prompt checkpoint helper cannot "
381
- "downgrade the committer to COMMIT_BLOCKED. Stop and let Python Runtime validate the handoff."
446
+ "Workflow checkpoint is already WORKFLOW_BLOCKED; reset or rewind the task "
447
+ "instead of continuing step mutations."
448
+ ),
449
+ }
450
+
451
+ existing_round = l4_state.get("repair_round", 0)
452
+ requested_round = semantic_update.get("repair_round")
453
+ if (
454
+ isinstance(existing_round, int)
455
+ and not isinstance(existing_round, bool)
456
+ and requested_round is not None
457
+ and requested_round < existing_round
458
+ ):
459
+ return {
460
+ "ok": False,
461
+ "error": "Cannot downgrade persisted repair_round {} to {}".format(
462
+ existing_round, requested_round
382
463
  ),
383
464
  }
465
+
466
+ delta_review_reentry = (
467
+ new_status == "in_progress"
468
+ and step.get("skill") == "prizmkit-code-review"
469
+ and step.get("status") == "completed"
470
+ and step.get("stage_result") == "REVIEW_PASS"
471
+ and (
472
+ semantic_update.get("repair_scope") == "production"
473
+ or any(
474
+ later.get("skill") == "prizmkit-test"
475
+ and _declared_test_pass_changed_production(checkpoint_path, later)
476
+ for later in data["steps"][index + 1:]
477
+ )
478
+ )
479
+ )
480
+
481
+ stage_result = semantic_update.get("stage_result")
482
+ project_root = _checkpoint_project_root(checkpoint_path)
384
483
  if new_status == "completed" and step.get("skill") == "prizmkit-code-review":
385
484
  stage_result = stage_result or step.get("stage_result")
386
485
  if stage_result != "REVIEW_PASS":
387
486
  return {"ok": False, "error": "Code Review completion requires REVIEW_PASS"}
487
+ if (workflow_type in {"feature-pipeline", "bugfix-pipeline"} or step.get("required_artifacts")) and not required_step_artifacts_valid(
488
+ step, index=index, checkpoint_path=checkpoint_path, project_root=project_root
489
+ ):
490
+ return {
491
+ "ok": False,
492
+ "error": "Code Review completion requires a valid review-report.md with Verdict: PASS",
493
+ }
388
494
  if new_status == "completed" and step.get("skill") == "prizmkit-test":
389
495
  stage_result = stage_result or step.get("stage_result")
390
496
  if stage_result != "TEST_PASS":
391
497
  return {"ok": False, "error": "Test completion requires TEST_PASS"}
498
+ if _declared_test_pass_changed_production(checkpoint_path, step):
499
+ return {
500
+ "ok": False,
501
+ "error": (
502
+ "TEST_PASS with production_changed=true requires delta Code Review "
503
+ "re-entry before completing prizmkit-test."
504
+ ),
505
+ }
506
+ if (workflow_type in {"feature-pipeline", "bugfix-pipeline"} or step.get("required_artifacts")) and not required_step_artifacts_valid(
507
+ step, index=index, checkpoint_path=checkpoint_path, project_root=project_root
508
+ ):
509
+ return {
510
+ "ok": False,
511
+ "error": "Test completion requires a valid agreeing test-report.md and test-result.json with Result: TEST_PASS",
512
+ }
513
+ if new_status == "completed" and step.get("skill") == "prizmkit-retrospective":
514
+ if (workflow_type in {"feature-pipeline", "bugfix-pipeline"} or step.get("required_artifacts")) and not required_step_artifacts_valid(
515
+ step, index=index, checkpoint_path=checkpoint_path, project_root=project_root
516
+ ):
517
+ return {
518
+ "ok": False,
519
+ "error": "Retrospective completion requires a valid retrospective-result.json artifact",
520
+ }
392
521
  if new_status == "completed" and step.get("skill") == "prizmkit-committer":
393
522
  stage_result = stage_result or step.get("stage_result")
394
523
  if stage_result != "COMMITTED":
395
524
  return {"ok": False, "error": "Committer completion requires Runtime-owned COMMITTED"}
525
+ if step.get("skill") == "prizmkit-committer" and (
526
+ _declared_runtime_request_exists(checkpoint_path, step)
527
+ or step.get("stage_result") in {"COMMIT_PENDING", "COMMITTED"}
528
+ ):
529
+ return {
530
+ "ok": False,
531
+ "error": (
532
+ "A Runtime commit request already exists or handoff is COMMITTED for prizmkit-committer; "
533
+ "stop and let Python Runtime own all remaining committer transitions."
534
+ ),
535
+ }
536
+ if semantic_update.get("terminal_status") == "WORKFLOW_BLOCKED" and new_status in {"in_progress", "completed"}:
537
+ return {
538
+ "ok": False,
539
+ "error": "WORKFLOW_BLOCKED cannot have status={}".format(new_status),
540
+ }
396
541
  expected_status = expected_status_for_stage_result(stage_result)
397
542
  if expected_status is not None and new_status != expected_status:
398
543
  return {
@@ -400,6 +545,47 @@ def update_checkpoint(
400
545
  "error": "{} requires status={}".format(stage_result, expected_status),
401
546
  }
402
547
 
548
+ if delta_review_reentry:
549
+ current_round = l4_state.get("repair_round", 0)
550
+ if isinstance(current_round, bool) or not isinstance(current_round, int):
551
+ current_round = MAX_OUTER_REPAIR_ROUNDS
552
+ if current_round >= MAX_OUTER_REPAIR_ROUNDS:
553
+ test_step = next(
554
+ (later for later in data["steps"][index + 1:] if later.get("skill") == "prizmkit-test"),
555
+ None,
556
+ )
557
+ old_status = (test_step or step).get("status", "unknown")
558
+ if test_step is not None:
559
+ test_step["status"] = "failed"
560
+ test_step.pop("stage_result", None)
561
+ if note:
562
+ test_step["note"] = note
563
+ l4_state["schema_version"] = 1
564
+ l4_state["orchestrator"] = "pipeline-runtime"
565
+ l4_state["stage"] = "test" if test_step is not None else "code-review"
566
+ l4_state["status"] = "failed"
567
+ l4_state.pop("stage_result", None)
568
+ l4_state["repair_round"] = MAX_OUTER_REPAIR_ROUNDS
569
+ l4_state["repair_scope"] = "production"
570
+ l4_state["terminal_status"] = "WORKFLOW_BLOCKED"
571
+ l4_state["blocked_reason"] = "repair_round_limit"
572
+ _sync_cursor(data, l4_state)
573
+ _finalize_semantics(checkpoint_path, data, state_key)
574
+ return _persist_validated_checkpoint(
575
+ checkpoint_path, data, test_step or step, old_status, "failed"
576
+ )
577
+
578
+ for later in data["steps"][index + 1:]:
579
+ later["status"] = "pending"
580
+ later.pop("stage_result", None)
581
+ later.pop("note", None)
582
+ l4_state["repair_round"] = current_round + 1
583
+ l4_state["repair_scope"] = "production"
584
+ l4_state["terminal_status"] = None
585
+ l4_state["blocked_reason"] = None
586
+ if not note:
587
+ step.pop("note", None)
588
+
403
589
  old_status = step.get("status", "unknown")
404
590
  step["status"] = new_status
405
591
  if note:
@@ -409,11 +595,6 @@ def update_checkpoint(
409
595
  else:
410
596
  step.pop("stage_result", None)
411
597
 
412
- workflow_type = str(data.get("workflow_type") or "")
413
- state_key = semantic_state_key(workflow_type)
414
- l4_state = data.setdefault(state_key, {})
415
- if not isinstance(l4_state, dict):
416
- return {"ok": False, "error": "Invalid semantic state object '{}'".format(state_key)}
417
598
  for key in (
418
599
  "stage_result",
419
600
  "repair_scope",
@@ -421,7 +602,9 @@ def update_checkpoint(
421
602
  "blocked_reason",
422
603
  "terminal_status",
423
604
  ):
424
- if key in semantic_update:
605
+ if key in semantic_update and not (
606
+ delta_review_reentry and key in {"repair_scope", "repair_round", "blocked_reason", "terminal_status"}
607
+ ):
425
608
  l4_state[key] = semantic_update[key]
426
609
  l4_state["schema_version"] = 1
427
610
  l4_state["orchestrator"] = "pipeline-runtime"
@@ -435,41 +618,20 @@ def update_checkpoint(
435
618
  repair_route_selected = _apply_repair_policy(
436
619
  l4_state,
437
620
  stage_result,
438
- semantic_update.get("repair_scope") or l4_state.get("repair_scope"),
621
+ semantic_update.get("repair_scope"),
439
622
  )
623
+ if (
624
+ not repair_route_selected
625
+ and not delta_review_reentry
626
+ and new_status == "completed"
627
+ and stage_result not in _BLOCKING_STAGE_RESULTS
628
+ ):
629
+ l4_state["repair_scope"] = None
440
630
  _sync_cursor(data, l4_state, preserve_next_stage=repair_route_selected)
441
631
  _finalize_semantics(checkpoint_path, data, state_key)
442
-
443
- final_state = validate_checkpoint_data(
444
- data,
445
- path=checkpoint_path,
446
- exists=True,
447
- project_root=_checkpoint_project_root(checkpoint_path),
632
+ return _persist_validated_checkpoint(
633
+ checkpoint_path, data, step, old_status, new_status
448
634
  )
449
- if not final_state.valid or final_state.semantic.error_code:
450
- error_code = final_state.error_code or final_state.semantic.error_code
451
- error_message = final_state.error_message or final_state.semantic.error_message
452
- return {
453
- "ok": False,
454
- "error": "Update would create invalid checkpoint ({}): {}".format(
455
- error_code, error_message
456
- ),
457
- }
458
-
459
- err = _write_checkpoint(checkpoint_path, data)
460
- if err:
461
- return {"ok": False, "error": err}
462
-
463
- prompt_semantic = dict(final_state.semantic_snapshot)
464
- prompt_semantic.pop("commit_ready", None)
465
- return {
466
- "ok": True,
467
- "step_id": step.get("id"),
468
- "skill": step.get("skill"),
469
- "old_status": old_status,
470
- "new_status": new_status,
471
- "semantic": prompt_semantic,
472
- }
473
635
 
474
636
 
475
637
  def main():