prizmkit 1.1.191 → 1.1.193

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 (165) 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 +28 -44
  8. package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
  9. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +6 -6
  10. package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
  11. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
  12. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
  13. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
  14. package/bundled/dev-pipeline/prizmkit_runtime/config.py +48 -78
  15. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +127 -67
  16. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +158 -462
  17. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +102 -50
  18. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -25
  19. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
  20. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +47 -21
  21. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +217 -156
  22. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +39 -27
  23. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +34 -174
  24. package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
  25. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +133 -110
  26. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
  27. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -95
  28. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
  29. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
  30. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +540 -262
  31. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +175 -135
  32. package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
  33. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +214 -133
  34. package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
  35. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2783 -0
  36. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -102
  37. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
  38. package/bundled/dev-pipeline/scripts/check-session-status.py +56 -20
  39. package/bundled/dev-pipeline/scripts/continuation.py +8 -7
  40. package/bundled/dev-pipeline/scripts/detect-stuck.py +47 -33
  41. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +13 -16
  42. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +20 -10
  43. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
  44. package/bundled/dev-pipeline/scripts/init-change-artifact.py +25 -4
  45. package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
  46. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
  47. package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
  48. package/bundled/dev-pipeline/scripts/prompt_framework.py +85 -20
  49. package/bundled/dev-pipeline/scripts/status_common.py +591 -0
  50. package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
  51. package/bundled/dev-pipeline/scripts/update-checkpoint.py +254 -65
  52. package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
  53. package/bundled/dev-pipeline/scripts/utils.py +5 -12
  54. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +5 -5
  55. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
  56. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +7 -7
  57. package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
  58. package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
  59. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
  60. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
  61. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
  62. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
  63. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
  64. package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
  65. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
  66. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
  67. package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
  68. package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
  69. package/bundled/skills/_metadata.json +9 -63
  70. package/bundled/skills/app-planner/SKILL.md +32 -303
  71. package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
  72. package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
  73. package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
  74. package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
  75. package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
  76. package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
  77. package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
  78. package/bundled/skills/bug-planner/SKILL.md +54 -435
  79. package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
  80. package/bundled/skills/bug-planner/references/input-formats.md +32 -0
  81. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
  82. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
  83. package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
  84. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
  85. package/bundled/skills/feature-planner/SKILL.md +60 -439
  86. package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
  87. package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
  88. package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
  89. package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
  90. package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
  91. package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
  92. package/bundled/skills/feature-workflow/SKILL.md +1 -2
  93. package/bundled/skills/prizmkit/SKILL.md +7 -1
  94. package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
  95. package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
  96. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
  97. package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
  98. package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
  99. package/bundled/skills/prizmkit-init/SKILL.md +24 -127
  100. package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
  101. package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
  102. package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
  103. package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
  104. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
  105. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
  106. package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
  107. package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
  108. package/bundled/skills/prizmkit-test/SKILL.md +25 -133
  109. package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
  110. package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
  111. package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
  112. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
  113. package/bundled/skills/recovery-workflow/SKILL.md +7 -7
  114. package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
  115. package/bundled/skills/recovery-workflow/references/detection.md +1 -3
  116. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
  117. package/bundled/templates/project-memory-template.md +1 -2
  118. package/package.json +1 -1
  119. package/src/scaffold.js +28 -7
  120. package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
  121. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
  122. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
  123. package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
  124. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
  125. package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
  126. package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
  127. package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
  128. package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
  129. package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
  130. package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
  131. package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
  132. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
  133. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
  134. package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
  135. package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
  136. package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
  137. package/bundled/dev-pipeline/tests/conftest.py +0 -29
  138. package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
  139. package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1871
  140. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1314
  141. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1712
  142. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -627
  143. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
  144. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -5641
  145. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -322
  146. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -252
  147. package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1208
  148. package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -957
  149. package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
  150. package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -303
  151. package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -5504
  152. package/bundled/dev-pipeline/tests/test_utils.py +0 -170
  153. package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
  154. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
  155. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
  156. package/bundled/skills/refactor-planner/SKILL.md +0 -467
  157. package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
  158. package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
  159. package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
  160. package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
  161. package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
  162. package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
  163. package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
  164. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
  165. 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,138 @@ 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
+ if l4_state.get("terminal_status") == "WORKFLOW_COMPLETED":
451
+ return {
452
+ "ok": False,
453
+ "error": (
454
+ "Workflow checkpoint is already WORKFLOW_COMPLETED; reset or rewind the task "
455
+ "instead of continuing step mutations."
456
+ ),
457
+ }
458
+
459
+ existing_round = l4_state.get("repair_round", 0)
460
+ requested_round = semantic_update.get("repair_round")
461
+ if (
462
+ isinstance(existing_round, int)
463
+ and not isinstance(existing_round, bool)
464
+ and requested_round is not None
465
+ and requested_round < existing_round
466
+ ):
467
+ return {
468
+ "ok": False,
469
+ "error": "Cannot downgrade persisted repair_round {} to {}".format(
470
+ existing_round, requested_round
382
471
  ),
383
472
  }
473
+
474
+ delta_review_reentry = (
475
+ new_status == "in_progress"
476
+ and step.get("skill") == "prizmkit-code-review"
477
+ and step.get("status") == "completed"
478
+ and step.get("stage_result") == "REVIEW_PASS"
479
+ and (
480
+ semantic_update.get("repair_scope") == "production"
481
+ or any(
482
+ later.get("skill") == "prizmkit-test"
483
+ and _declared_test_pass_changed_production(checkpoint_path, later)
484
+ for later in data["steps"][index + 1:]
485
+ )
486
+ )
487
+ )
488
+
489
+ stage_result = semantic_update.get("stage_result")
490
+ project_root = _checkpoint_project_root(checkpoint_path)
491
+ if new_status == "completed" and workflow_type in {"feature-pipeline", "bugfix-pipeline"}:
492
+ required_completed_results = {
493
+ "prizmkit-plan": "PLAN_READY",
494
+ "context-snapshot-and-plan": "PLAN_READY",
495
+ "bug-diagnosis-and-plan": "PLAN_READY",
496
+ "prizmkit-implement": "IMPLEMENTED",
497
+ "prizmkit-retrospective": "RETRO_COMPLETE",
498
+ }
499
+ expected_completed_result = required_completed_results.get(step.get("skill"))
500
+ if expected_completed_result is not None:
501
+ resolved_result = stage_result or step.get("stage_result")
502
+ if resolved_result != expected_completed_result:
503
+ return {
504
+ "ok": False,
505
+ "error": "{} completion requires {}".format(
506
+ step.get("skill"), expected_completed_result
507
+ ),
508
+ }
509
+ stage_result = resolved_result
384
510
  if new_status == "completed" and step.get("skill") == "prizmkit-code-review":
385
511
  stage_result = stage_result or step.get("stage_result")
386
512
  if stage_result != "REVIEW_PASS":
387
513
  return {"ok": False, "error": "Code Review completion requires REVIEW_PASS"}
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": "Code Review completion requires a valid review-report.md with Verdict: PASS",
520
+ }
388
521
  if new_status == "completed" and step.get("skill") == "prizmkit-test":
389
522
  stage_result = stage_result or step.get("stage_result")
390
523
  if stage_result != "TEST_PASS":
391
524
  return {"ok": False, "error": "Test completion requires TEST_PASS"}
525
+ if _declared_test_pass_changed_production(checkpoint_path, step):
526
+ return {
527
+ "ok": False,
528
+ "error": (
529
+ "TEST_PASS with production_changed=true requires delta Code Review "
530
+ "re-entry before completing prizmkit-test."
531
+ ),
532
+ }
533
+ if (workflow_type in {"feature-pipeline", "bugfix-pipeline"} or step.get("required_artifacts")) and not required_step_artifacts_valid(
534
+ step, index=index, checkpoint_path=checkpoint_path, project_root=project_root
535
+ ):
536
+ return {
537
+ "ok": False,
538
+ "error": "Test completion requires a valid agreeing test-report.md and test-result.json with Result: TEST_PASS",
539
+ }
540
+ if new_status == "completed" and step.get("skill") == "prizmkit-retrospective":
541
+ if (workflow_type in {"feature-pipeline", "bugfix-pipeline"} or step.get("required_artifacts")) and not required_step_artifacts_valid(
542
+ step, index=index, checkpoint_path=checkpoint_path, project_root=project_root
543
+ ):
544
+ return {
545
+ "ok": False,
546
+ "error": "Retrospective completion requires a valid retrospective-result.json artifact",
547
+ }
392
548
  if new_status == "completed" and step.get("skill") == "prizmkit-committer":
393
549
  stage_result = stage_result or step.get("stage_result")
394
550
  if stage_result != "COMMITTED":
395
551
  return {"ok": False, "error": "Committer completion requires Runtime-owned COMMITTED"}
552
+ if step.get("skill") == "prizmkit-committer" and (
553
+ _declared_runtime_request_exists(checkpoint_path, step)
554
+ or step.get("stage_result") in {"COMMIT_PENDING", "COMMITTED"}
555
+ ):
556
+ return {
557
+ "ok": False,
558
+ "error": (
559
+ "A Runtime commit request already exists or handoff is COMMITTED for prizmkit-committer; "
560
+ "stop and let Python Runtime own all remaining committer transitions."
561
+ ),
562
+ }
563
+ if semantic_update.get("terminal_status") == "WORKFLOW_BLOCKED" and new_status in {"in_progress", "completed"}:
564
+ return {
565
+ "ok": False,
566
+ "error": "WORKFLOW_BLOCKED cannot have status={}".format(new_status),
567
+ }
396
568
  expected_status = expected_status_for_stage_result(stage_result)
397
569
  if expected_status is not None and new_status != expected_status:
398
570
  return {
@@ -400,6 +572,47 @@ def update_checkpoint(
400
572
  "error": "{} requires status={}".format(stage_result, expected_status),
401
573
  }
402
574
 
575
+ if delta_review_reentry:
576
+ current_round = l4_state.get("repair_round", 0)
577
+ if isinstance(current_round, bool) or not isinstance(current_round, int):
578
+ current_round = MAX_OUTER_REPAIR_ROUNDS
579
+ if current_round >= MAX_OUTER_REPAIR_ROUNDS:
580
+ test_step = next(
581
+ (later for later in data["steps"][index + 1:] if later.get("skill") == "prizmkit-test"),
582
+ None,
583
+ )
584
+ old_status = (test_step or step).get("status", "unknown")
585
+ if test_step is not None:
586
+ test_step["status"] = "failed"
587
+ test_step.pop("stage_result", None)
588
+ if note:
589
+ test_step["note"] = note
590
+ l4_state["schema_version"] = 1
591
+ l4_state["orchestrator"] = "pipeline-runtime"
592
+ l4_state["stage"] = "test" if test_step is not None else "code-review"
593
+ l4_state["status"] = "failed"
594
+ l4_state.pop("stage_result", None)
595
+ l4_state["repair_round"] = MAX_OUTER_REPAIR_ROUNDS
596
+ l4_state["repair_scope"] = "production"
597
+ l4_state["terminal_status"] = "WORKFLOW_BLOCKED"
598
+ l4_state["blocked_reason"] = "repair_round_limit"
599
+ _sync_cursor(data, l4_state)
600
+ _finalize_semantics(checkpoint_path, data, state_key)
601
+ return _persist_validated_checkpoint(
602
+ checkpoint_path, data, test_step or step, old_status, "failed"
603
+ )
604
+
605
+ for later in data["steps"][index + 1:]:
606
+ later["status"] = "pending"
607
+ later.pop("stage_result", None)
608
+ later.pop("note", None)
609
+ l4_state["repair_round"] = current_round + 1
610
+ l4_state["repair_scope"] = "production"
611
+ l4_state["terminal_status"] = None
612
+ l4_state["blocked_reason"] = None
613
+ if not note:
614
+ step.pop("note", None)
615
+
403
616
  old_status = step.get("status", "unknown")
404
617
  step["status"] = new_status
405
618
  if note:
@@ -409,11 +622,6 @@ def update_checkpoint(
409
622
  else:
410
623
  step.pop("stage_result", None)
411
624
 
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
625
  for key in (
418
626
  "stage_result",
419
627
  "repair_scope",
@@ -421,7 +629,9 @@ def update_checkpoint(
421
629
  "blocked_reason",
422
630
  "terminal_status",
423
631
  ):
424
- if key in semantic_update:
632
+ if key in semantic_update and not (
633
+ delta_review_reentry and key in {"repair_scope", "repair_round", "blocked_reason", "terminal_status"}
634
+ ):
425
635
  l4_state[key] = semantic_update[key]
426
636
  l4_state["schema_version"] = 1
427
637
  l4_state["orchestrator"] = "pipeline-runtime"
@@ -435,41 +645,20 @@ def update_checkpoint(
435
645
  repair_route_selected = _apply_repair_policy(
436
646
  l4_state,
437
647
  stage_result,
438
- semantic_update.get("repair_scope") or l4_state.get("repair_scope"),
648
+ semantic_update.get("repair_scope"),
439
649
  )
650
+ if (
651
+ not repair_route_selected
652
+ and not delta_review_reentry
653
+ and new_status == "completed"
654
+ and stage_result not in _BLOCKING_STAGE_RESULTS
655
+ ):
656
+ l4_state["repair_scope"] = None
440
657
  _sync_cursor(data, l4_state, preserve_next_stage=repair_route_selected)
441
658
  _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),
659
+ return _persist_validated_checkpoint(
660
+ checkpoint_path, data, step, old_status, new_status
448
661
  )
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
662
 
474
663
 
475
664
  def main():