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
@@ -27,38 +27,53 @@ import os
27
27
  import re
28
28
  import shutil
29
29
  import sys
30
- from datetime import datetime, timezone
31
-
32
- from utils import (
30
+ from datetime import datetime
31
+
32
+ _SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
33
+ if _SCRIPTS_DIR not in sys.path:
34
+ sys.path.insert(0, _SCRIPTS_DIR)
35
+
36
+ from status_common import ( # noqa: E402
37
+ CONTINUATION_COUNTER_FIELDS as CONTINUATION_COUNTER_FIELDS,
38
+ CONTINUATION_PENDING_FIELDS as CONTINUATION_PENDING_FIELDS,
39
+ SEMANTIC_CHECKPOINT_FIELDS as SEMANTIC_CHECKPOINT_FIELDS,
40
+ SESSION_STATUS_VALUES as SESSION_STATUS_VALUES,
41
+ STALL_REASON as STALL_REASON,
42
+ _default_project_root as _default_project_root,
43
+ _load_checkpoint_state as _load_checkpoint_state,
44
+ _load_progress_fingerprint as _load_progress_fingerprint,
45
+ _resolve_project_file as _resolve_project_file,
46
+ _set_ai_error_continuation_metadata as _set_ai_error_continuation_metadata,
47
+ _sync_semantic_checkpoint as _sync_semantic_checkpoint,
48
+ action_pause as _common_action_pause,
49
+ auto_skip_blocked_items,
50
+ cleanup_continuation_artifacts as cleanup_continuation_artifacts,
51
+ clear_pending_continuation_metadata as clear_pending_continuation_metadata,
52
+ continuation_metadata_summary as continuation_metadata_summary,
53
+ get_item_status_from_list,
54
+ has_pending_continuation_metadata as has_pending_continuation_metadata,
55
+ load_item_status,
56
+ load_session_status as load_session_status,
57
+ now_iso as now_iso,
58
+ read_checkpoint_phase,
59
+ reconcile_orphaned_auto_skipped_items,
60
+ reset_continuation_metadata as reset_continuation_metadata,
61
+ save_item_status,
62
+ set_context_overflow_continuation_metadata as set_context_overflow_continuation_metadata,
63
+ set_stalled_context_continuation_metadata as set_stalled_context_continuation_metadata,
64
+ update_item_in_list,
65
+ )
66
+ from utils import ( # noqa: E402
33
67
  load_json_file,
34
68
  write_json_file,
35
69
  error_out,
36
70
  pad_right,
37
71
  _build_progress_bar,
38
- read_checkpoint_cursor,
39
72
  dependency_rank_map,
40
73
  causal_reset_selection,
41
74
  orphaned_auto_skipped_ids,
42
75
  )
43
76
 
44
-
45
- SESSION_STATUS_VALUES = [
46
- "success",
47
- "partial_resumable",
48
- "partial_not_resumable",
49
- "failed",
50
- "crashed",
51
- "timed_out",
52
- "infra_error",
53
- "context_overflow",
54
- "stalled_context_continuation",
55
- "workflow_blocked",
56
- "workflow_skipped",
57
- "commit_missing",
58
- "docs_missing",
59
- "merge_conflict",
60
- ]
61
-
62
77
  TERMINAL_STATUSES = {"completed", "failed", "skipped", "auto_skipped", "split"}
63
78
  RESET_BLOCKING_ROOT_STATUSES = {"failed", "skipped"}
64
79
 
@@ -200,150 +215,37 @@ def parse_feature_filter(features_str):
200
215
  return result if result else None
201
216
 
202
217
 
203
- def now_iso():
204
- """Return the current UTC time in ISO8601 format."""
205
- return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
206
-
207
-
208
218
  def load_feature_status(state_dir, feature_id):
209
- """Load the runtime state from status.json for a feature.
210
-
211
- Returns runtime fields only (retry_count, sessions, etc.).
212
- The 'status' field is NOT included — status lives exclusively
213
- in feature-list.json.
214
- """
215
- status_path = os.path.join(state_dir, feature_id, "status.json")
216
- if not os.path.isfile(status_path):
217
- now = now_iso()
218
- return {
219
- "feature_id": feature_id,
220
- "retry_count": 0,
221
- "max_retries": 3,
222
- "max_infra_retries": 3,
223
- "infra_error_count": 0,
224
- "last_infra_error_session_id": None,
225
- "sessions": [],
226
- "last_session_id": None,
227
- "resume_from_phase": None,
228
- "created_at": now,
229
- "updated_at": now,
230
- }
231
- data, err = load_json_file(status_path)
232
- if err:
233
- now = now_iso()
234
- return {
235
- "feature_id": feature_id,
236
- "retry_count": 0,
237
- "max_retries": 3,
238
- "max_infra_retries": 3,
239
- "infra_error_count": 0,
240
- "last_infra_error_session_id": None,
241
- "sessions": [],
242
- "last_session_id": None,
243
- "resume_from_phase": None,
244
- "created_at": now,
245
- "updated_at": now,
246
- }
247
- # Defensively remove status if present (legacy data)
248
- data.pop("status", None)
249
- return data
219
+ """Load the runtime state from status.json for a feature."""
220
+ return load_item_status(state_dir, feature_id, id_key="feature_id")
250
221
 
251
222
 
252
223
  def save_feature_status(state_dir, feature_id, status_data):
253
224
  """Write the status.json for a feature (runtime fields only)."""
254
- # Defensively strip status — it belongs in feature-list.json
255
- status_data.pop("status", None)
256
- status_path = os.path.join(state_dir, feature_id, "status.json")
257
- return write_json_file(status_path, status_data)
225
+ return save_item_status(state_dir, feature_id, status_data, write_json_fn=write_json_file)
258
226
 
259
227
 
260
228
  def get_feature_status_from_list(feature_list_path, feature_id):
261
229
  """Read a single feature's status from feature-list.json."""
262
- data, err = load_json_file(feature_list_path)
263
- if err:
264
- return "pending"
265
- for f in data.get("features", []):
266
- if isinstance(f, dict) and f.get("id") == feature_id:
267
- return f.get("status", "pending")
268
- return "pending"
230
+ return get_item_status_from_list(feature_list_path, feature_id, list_key="features")
269
231
 
270
232
 
271
233
  def update_feature_in_list(feature_list_path, feature_id, new_status):
272
- """Update a feature's status field in .prizmkit/plans/feature-list.json.
273
-
274
- Reads the whole file, modifies the target feature's status, writes back.
275
- Returns an error string on failure, None on success.
276
- """
277
- data, err = load_json_file(feature_list_path)
278
- if err:
279
- return err
280
- features = data.get("features", [])
281
- found = False
282
- for feature in features:
283
- if isinstance(feature, dict) and feature.get("id") == feature_id:
284
- feature["status"] = new_status
285
- found = True
286
- break
287
- if not found:
288
- return "Feature '{}' not found in .prizmkit/plans/feature-list.json".format(feature_id)
289
- return write_json_file(feature_list_path, data)
290
-
291
-
292
- CONTINUATION_PENDING_FIELDS = [
293
- "active_dev_branch",
294
- "base_branch",
295
- "continuation_pending",
296
- "continuation_reason",
297
- "last_context_overflow_session_id",
298
- "previous_session_id",
299
- "last_fatal_error_code",
300
- "continuation_summary_path",
301
- "no_progress_count",
302
- "last_progress_fingerprint",
303
- "needs_attention",
304
- "stalled_context_continuation",
305
- "stalled_reason",
306
- ]
307
-
308
- CONTINUATION_COUNTER_FIELDS = [
309
- "context_overflow_count",
310
- "continuation_count",
311
- ]
312
-
313
-
314
- def has_pending_continuation_metadata(status_data):
315
- """Return True when runtime state still has pending continuation metadata."""
316
- return any(key in status_data for key in CONTINUATION_PENDING_FIELDS)
317
-
318
-
319
- def clear_pending_continuation_metadata(status_data):
320
- """Clear branch/pending continuation fields while preserving observability counters."""
321
- for key in CONTINUATION_PENDING_FIELDS:
322
- status_data.pop(key, None)
323
-
324
-
325
- def reset_continuation_metadata(status_data):
326
- """Clear all continuation runtime metadata, including manual-reset counters."""
327
- clear_pending_continuation_metadata(status_data)
328
- for key in CONTINUATION_COUNTER_FIELDS:
329
- status_data.pop(key, None)
330
-
331
-
332
- STALL_REASON = "context_overflow_without_git_checkpoint_or_artifact_progress"
234
+ """Update a feature's status field in .prizmkit/plans/feature-list.json."""
235
+ return update_item_in_list(
236
+ feature_list_path,
237
+ feature_id,
238
+ new_status,
239
+ list_key="features",
240
+ item_label="Feature",
241
+ list_display_path=".prizmkit/plans/feature-list.json",
242
+ write_json_fn=write_json_file,
243
+ )
333
244
 
334
245
 
335
246
  def _read_feature_checkpoint_phase(project_root, feature_slug):
336
- """Read the phase index from the feature checkpoint file.
337
-
338
- Returns an integer step index (e.g., 3 for S03) or None if the checkpoint
339
- is not available. The value is consumed by the terminal status display as
340
- ``CP-F-<n>``.
341
- """
342
- checkpoint_path = os.path.join(
343
- os.path.abspath(project_root) if project_root else _default_project_root(),
344
- ".prizmkit", "specs", feature_slug, "workflow-checkpoint.json",
345
- )
346
- return read_checkpoint_cursor(checkpoint_path)
247
+ """Read the phase index from the feature checkpoint file."""
248
+ return read_checkpoint_phase(project_root, "specs", feature_slug)
347
249
 
348
250
 
349
251
  def _checkpoint_phase_or_cached(project_root, feature_slug, status_data):
@@ -359,158 +261,6 @@ def _sync_checkpoint_phase(project_root, feature_slug, status_data):
359
261
  return status_data.get("resume_from_phase")
360
262
 
361
263
 
362
- def _load_progress_fingerprint(raw):
363
- if not raw:
364
- return None
365
- try:
366
- return json.loads(raw)
367
- except (TypeError, ValueError):
368
- return {"unparsed": str(raw)}
369
-
370
-
371
- SEMANTIC_CHECKPOINT_FIELDS = (
372
- "current_stage",
373
- "next_stage",
374
- "stage_result",
375
- "repair_scope",
376
- "repair_round",
377
- "blocked_reason",
378
- "terminal_status",
379
- )
380
-
381
-
382
- def _load_checkpoint_state(raw):
383
- if not raw:
384
- return {}
385
- try:
386
- data = json.loads(raw)
387
- except (TypeError, ValueError):
388
- return {}
389
- if not isinstance(data, dict):
390
- return {}
391
- return {key: data.get(key) for key in SEMANTIC_CHECKPOINT_FIELDS}
392
-
393
-
394
- def _sync_semantic_checkpoint(status_data, args):
395
- semantic = _load_checkpoint_state(getattr(args, "checkpoint_state", None))
396
- if semantic:
397
- status_data.update(semantic)
398
- return {key: status_data.get(key) for key in SEMANTIC_CHECKPOINT_FIELDS}
399
-
400
-
401
- def _set_continuation_common(status_data, args, session_id):
402
- if args.active_dev_branch:
403
- status_data["active_dev_branch"] = args.active_dev_branch
404
- if args.base_branch:
405
- status_data["base_branch"] = args.base_branch
406
- status_data["last_context_overflow_session_id"] = session_id
407
- status_data["previous_session_id"] = session_id
408
- status_data["last_fatal_error_code"] = args.last_fatal_error_code or "context_overflow"
409
- if args.continuation_summary_path:
410
- status_data["continuation_summary_path"] = args.continuation_summary_path
411
- else:
412
- status_data.pop("continuation_summary_path", None)
413
- if args.no_progress_count is not None:
414
- status_data["no_progress_count"] = max(0, args.no_progress_count)
415
- fingerprint = _load_progress_fingerprint(args.progress_fingerprint)
416
- if fingerprint is not None:
417
- status_data["last_progress_fingerprint"] = fingerprint
418
- status_data.pop("last_infra_error_session_id", None)
419
- status_data["resume_from_phase"] = None
420
- if session_id:
421
- status_data["last_session_id"] = session_id
422
-
423
-
424
- def _set_ai_error_continuation_metadata(status_data, args, session_id, reason):
425
- """Preserve durable task/session state for any retryable launched AI error."""
426
- if args.active_dev_branch:
427
- status_data["active_dev_branch"] = args.active_dev_branch
428
- if args.base_branch:
429
- status_data["base_branch"] = args.base_branch
430
- status_data["continuation_pending"] = True
431
- status_data["continuation_reason"] = reason
432
- status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
433
- status_data["previous_session_id"] = session_id
434
- status_data["last_fatal_error_code"] = args.last_fatal_error_code or reason
435
- if args.continuation_summary_path:
436
- status_data["continuation_summary_path"] = args.continuation_summary_path
437
- if args.no_progress_count is not None:
438
- status_data["no_progress_count"] = max(0, args.no_progress_count)
439
- fingerprint = _load_progress_fingerprint(args.progress_fingerprint)
440
- if fingerprint is not None:
441
- status_data["last_progress_fingerprint"] = fingerprint
442
- status_data["resume_from_phase"] = None
443
- if session_id:
444
- sessions = status_data.get("sessions", [])
445
- if session_id not in sessions:
446
- sessions.append(session_id)
447
- status_data["sessions"] = sessions
448
- status_data["last_session_id"] = session_id
449
-
450
-
451
- def set_context_overflow_continuation_metadata(status_data, args, session_id):
452
- """Record continuation metadata for a context-overflow outcome in status.json."""
453
- status_data["context_overflow_count"] = status_data.get("context_overflow_count", 0) + 1
454
- status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
455
- status_data["continuation_pending"] = True
456
- status_data["continuation_reason"] = "context_overflow"
457
- status_data.pop("needs_attention", None)
458
- status_data.pop("stalled_context_continuation", None)
459
- status_data.pop("stalled_reason", None)
460
- _set_continuation_common(status_data, args, session_id)
461
-
462
-
463
- def set_stalled_context_continuation_metadata(status_data, args, session_id):
464
- """Record no-progress context-overflow stall without consuming retry budgets."""
465
- status_data["context_overflow_count"] = status_data.get("context_overflow_count", 0) + 1
466
- status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
467
- _set_continuation_common(status_data, args, session_id)
468
- status_data["continuation_pending"] = False
469
- status_data["continuation_reason"] = STALL_REASON
470
- status_data["needs_attention"] = True
471
- status_data["stalled_context_continuation"] = True
472
- status_data["stalled_reason"] = STALL_REASON
473
- if args.no_progress_count is None or args.no_progress_count < 2:
474
- status_data["no_progress_count"] = 2
475
-
476
-
477
- def continuation_metadata_summary(status_data):
478
- """Return additive continuation fields for CLI JSON outputs."""
479
- return {
480
- "active_dev_branch": status_data.get("active_dev_branch"),
481
- "base_branch": status_data.get("base_branch"),
482
- "continuation_pending": status_data.get("continuation_pending", False),
483
- "continuation_reason": status_data.get("continuation_reason"),
484
- "last_context_overflow_session_id": status_data.get("last_context_overflow_session_id"),
485
- "last_fatal_error_code": status_data.get("last_fatal_error_code"),
486
- "previous_session_id": status_data.get("previous_session_id"),
487
- "context_overflow_count": status_data.get("context_overflow_count", 0),
488
- "continuation_count": status_data.get("continuation_count", 0),
489
- "no_progress_count": status_data.get("no_progress_count", 0),
490
- "last_progress_fingerprint": status_data.get("last_progress_fingerprint"),
491
- "needs_attention": status_data.get("needs_attention", False),
492
- "stalled_context_continuation": status_data.get("stalled_context_continuation", False),
493
- "stalled_reason": status_data.get("stalled_reason"),
494
- "continuation_summary_path": status_data.get("continuation_summary_path"),
495
- }
496
-
497
-
498
- def _default_project_root():
499
- # Script lives at <pipeline>/scripts/update-feature-status.py.
500
- # Pipeline may be either <project>/.prizmkit/dev-pipeline (user install)
501
- # or <repo>/dev-pipeline (framework source). Auto-detect by checking if
502
- # the parent of dev-pipeline is named ".prizmkit".
503
- env = os.environ.get("PROJECT_ROOT")
504
- if env:
505
- return os.path.abspath(env)
506
- script_dir = os.path.dirname(os.path.abspath(__file__))
507
- pipeline_dir = os.path.dirname(script_dir)
508
- pipeline_parent = os.path.dirname(pipeline_dir)
509
- if os.path.basename(pipeline_parent) == ".prizmkit":
510
- return os.path.dirname(pipeline_parent)
511
- return pipeline_parent
512
-
513
-
514
264
  def _build_feature_slug(feature_id, title):
515
265
  numeric = feature_id.replace("F-", "").replace("f-", "").zfill(3)
516
266
  cleaned = re.sub(r"[^a-z0-9\s-]", "", (title or "").lower())
@@ -531,45 +281,6 @@ def _get_feature_slug(feature_list_path, feature_id):
531
281
  return None
532
282
 
533
283
 
534
- def _resolve_project_file(project_root, path):
535
- if not path:
536
- return None
537
- if os.path.isabs(path):
538
- target = os.path.abspath(path)
539
- else:
540
- target = os.path.abspath(os.path.join(project_root, path))
541
- root = os.path.abspath(project_root)
542
- try:
543
- rel = os.path.relpath(target, root)
544
- except ValueError:
545
- return None
546
- if rel == os.pardir or rel.startswith(os.pardir + os.sep):
547
- return None
548
- return target
549
-
550
-
551
- def cleanup_continuation_artifacts(project_root, status_data, candidate_paths=None):
552
- """Delete durable continuation handoff files for a manual clean reset."""
553
- candidates = []
554
- if isinstance(status_data, dict):
555
- candidates.append(status_data.get("continuation_summary_path"))
556
- candidates.extend(candidate_paths or [])
557
-
558
- cleaned = []
559
- seen = set()
560
- for candidate in candidates:
561
- target = _resolve_project_file(project_root, candidate)
562
- if not target or target in seen:
563
- continue
564
- seen.add(target)
565
- if os.path.basename(target) != "continuation-summary.md":
566
- continue
567
- if os.path.isfile(target):
568
- os.remove(target)
569
- cleaned.append("Deleted continuation artifact {}".format(target))
570
- return cleaned
571
-
572
-
573
284
  def cleanup_feature_artifacts(feature_list_path, state_dir, feature_id, project_root=None):
574
285
  """Delete intermediate artifacts for a failed feature run.
575
286
 
@@ -628,162 +339,41 @@ def cleanup_feature_artifacts(feature_list_path, state_dir, feature_id, project_
628
339
  return cleaned
629
340
 
630
341
 
631
- def load_session_status(state_dir, feature_id, session_id):
632
- """Load a session's session-status.json file."""
633
- session_status_path = os.path.join(state_dir, feature_id, "sessions",
634
- session_id, "session-status.json"
635
- )
636
- data, err = load_json_file(session_status_path)
637
- if err:
638
- return None, err
639
- return data, None
640
-
641
-
642
342
  # ---------------------------------------------------------------------------
643
343
  # Auto-skip: cascade failure to blocked downstream features
644
344
  # ---------------------------------------------------------------------------
645
345
 
646
346
  def auto_skip_blocked_features(feature_list_path, state_dir, failed_feature_id):
647
- """Recursively mark all downstream features blocked by a failed feature as auto_skipped.
648
-
649
- When a feature is marked as failed, any feature whose dependency chain includes
650
- the failed feature can never be executed. This function propagates the failure
651
- by marking those blocked features as auto_skipped, allowing the pipeline to
652
- continue processing unblocked features and eventually reach PIPELINE_COMPLETE.
653
-
654
- Re-reads .prizmkit/plans/feature-list.json from disk to get the latest state (including the
655
- just-written failed status from update_feature_in_list).
656
-
657
- NOTE: This function performs a read-modify-write on .prizmkit/plans/feature-list.json without
658
- file locking. The caller (action_update) also writes to .prizmkit/plans/feature-list.json
659
- immediately before calling this. Safe for single-pipeline execution, but if
660
- multiple pipeline instances share the same .prizmkit/plans/feature-list.json concurrently,
661
- a race condition may cause lost writes. Add file locking if parallel pipelines
662
- are introduced.
663
- """
664
- data, err = load_json_file(feature_list_path)
665
- if err:
666
- return []
667
- features = data.get("features", [])
668
-
669
- # Build current status map
670
- status_map = {}
671
- for f in features:
672
- if isinstance(f, dict) and f.get("id"):
673
- status_map[f["id"]] = f.get("status", "pending")
674
-
675
- # Collect all features to auto-skip (recursive propagation)
676
- to_skip = set()
677
- changed = True
678
- while changed:
679
- changed = False
680
- for f in features:
681
- if not isinstance(f, dict):
682
- continue
683
- fid = f.get("id")
684
- if not fid or fid in to_skip:
685
- continue
686
- current = status_map.get(fid, "pending")
687
- if current in TERMINAL_STATUSES:
688
- continue
689
- deps = f.get("dependencies", [])
690
- for dep_id in deps:
691
- dep_status = status_map.get(dep_id, "pending")
692
- if dep_status in ("failed", "skipped", "auto_skipped") or dep_id in to_skip:
693
- to_skip.add(fid)
694
- status_map[fid] = "auto_skipped"
695
- changed = True
696
- break
697
-
698
- if not to_skip:
699
- return []
700
-
701
- # Batch-write to .prizmkit/plans/feature-list.json
702
- for f in features:
703
- if isinstance(f, dict) and f.get("id") in to_skip:
704
- f["status"] = "auto_skipped"
705
- write_json_file(feature_list_path, data)
706
-
707
- # Update timestamps in status.json for each auto-skipped feature
708
- for fid in to_skip:
709
- fs = load_feature_status(state_dir, fid)
710
- fs["updated_at"] = now_iso()
711
- save_feature_status(state_dir, fid, fs)
712
-
713
- # Build blocking reason map for logging
714
- skipped_info = []
715
- for f in features:
716
- if not isinstance(f, dict):
717
- continue
718
- fid = f.get("id")
719
- if fid not in to_skip:
720
- continue
721
- deps = f.get("dependencies", [])
722
- blockers = [
723
- d for d in deps
724
- if d == failed_feature_id or d in to_skip
725
- ]
726
- skipped_info.append({
727
- "feature_id": fid,
728
- "title": f.get("title", ""),
729
- "blocked_by": blockers,
730
- })
731
-
732
- print(
733
- "[auto-skip] {} feature(s) auto-skipped due to failed {}:".format(
734
- len(skipped_info), failed_feature_id
735
- ),
736
- file=sys.stderr,
347
+ """Recursively mark all downstream features blocked by a failed feature as auto_skipped."""
348
+ return auto_skip_blocked_items(
349
+ feature_list_path,
350
+ state_dir,
351
+ failed_feature_id,
352
+ list_key="features",
353
+ id_key="feature_id",
354
+ blocking_statuses=("failed", "skipped"),
355
+ terminal_statuses=TERMINAL_STATUSES,
356
+ error_on_load=False,
357
+ error_on_write=False,
358
+ item_noun="feature",
359
+ detailed_stderr=True,
360
+ write_json_fn=write_json_file,
737
361
  )
738
- for info in skipped_info:
739
- print(
740
- " {} ({}) — blocked by {}".format(
741
- info["feature_id"],
742
- info["title"],
743
- ", ".join(info["blocked_by"]),
744
- ),
745
- file=sys.stderr,
746
- )
747
-
748
- return skipped_info
749
362
 
750
363
 
751
364
  def reconcile_orphaned_auto_skipped_features(feature_list_path, state_dir):
752
365
  """Restore auto-skipped features that have no current blocking root."""
753
- data, err = load_json_file(feature_list_path)
754
- if err:
755
- raise RuntimeError("Cannot load feature list for orphan recovery: {}".format(err))
756
- features = data.get("features", [])
757
- orphan_ids = orphaned_auto_skipped_ids(
758
- features,
366
+ return reconcile_orphaned_auto_skipped_items(
367
+ feature_list_path,
368
+ state_dir,
369
+ list_key="features",
370
+ id_key="feature_id",
759
371
  blocking_root_statuses=RESET_BLOCKING_ROOT_STATUSES,
760
372
  item_label="Feature",
373
+ item_noun="feature",
374
+ list_noun="feature list",
375
+ write_json_fn=write_json_file,
761
376
  )
762
- if not orphan_ids:
763
- return []
764
-
765
- orphan_set = set(orphan_ids)
766
- for feature in features:
767
- if isinstance(feature, dict) and feature.get("id") in orphan_set:
768
- feature["status"] = "pending"
769
- err = write_json_file(feature_list_path, data)
770
- if err:
771
- raise RuntimeError("Failed to recover orphaned features: {}".format(err))
772
-
773
- for feature_id in orphan_ids:
774
- fs = load_feature_status(state_dir, feature_id)
775
- fs["updated_at"] = now_iso()
776
- err = save_feature_status(state_dir, feature_id, fs)
777
- if err:
778
- raise RuntimeError("Failed to save recovered feature status: {}".format(err))
779
-
780
- print(
781
- "[auto-skip] recovered {} orphaned feature(s): {}".format(
782
- len(orphan_ids), ", ".join(orphan_ids)
783
- ),
784
- file=sys.stderr,
785
- )
786
- return list(orphan_ids)
787
377
 
788
378
 
789
379
  # ---------------------------------------------------------------------------
@@ -1941,30 +1531,7 @@ def action_reset_state(args, feature_list_path, state_dir):
1941
1531
 
1942
1532
  def action_pause(state_dir):
1943
1533
  """Save current pipeline state for graceful shutdown."""
1944
- pipeline_path = os.path.join(state_dir, "pipeline.json")
1945
-
1946
- data, err = load_json_file(pipeline_path)
1947
- if err:
1948
- # If pipeline.json doesn't exist, create a minimal one
1949
- data = {
1950
- "status": "paused",
1951
- "paused_at": now_iso(),
1952
- }
1953
- else:
1954
- data["status"] = "paused"
1955
- data["paused_at"] = now_iso()
1956
-
1957
- err = write_json_file(pipeline_path, data)
1958
- if err:
1959
- error_out("Failed to write pipeline.json: {}".format(err))
1960
- return
1961
-
1962
- result = {
1963
- "action": "pause",
1964
- "status": "paused",
1965
- "paused_at": data["paused_at"],
1966
- }
1967
- print(json.dumps(result, indent=2, ensure_ascii=False))
1534
+ return _common_action_pause(state_dir, write_json_fn=write_json_file)
1968
1535
 
1969
1536
 
1970
1537
  # ---------------------------------------------------------------------------