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
@@ -0,0 +1,591 @@
1
+ """Shared status, continuation, checkpoint, and auto-skip helpers for pipeline updaters."""
2
+
3
+ from datetime import datetime, timezone
4
+ import json
5
+ import os
6
+ import sys
7
+
8
+ from utils import (
9
+ error_out,
10
+ load_json_file,
11
+ orphaned_auto_skipped_ids,
12
+ read_checkpoint_cursor,
13
+ write_json_file,
14
+ )
15
+
16
+
17
+ SESSION_STATUS_VALUES = [
18
+ "success",
19
+ "partial_resumable",
20
+ "partial_not_resumable",
21
+ "failed",
22
+ "crashed",
23
+ "timed_out",
24
+ "infra_error",
25
+ "context_overflow",
26
+ "stalled_context_continuation",
27
+ "workflow_blocked",
28
+ "workflow_skipped",
29
+ "commit_missing",
30
+ "docs_missing",
31
+ "merge_conflict",
32
+ ]
33
+
34
+ CONTINUATION_PENDING_FIELDS = [
35
+ "active_dev_branch",
36
+ "base_branch",
37
+ "continuation_pending",
38
+ "continuation_reason",
39
+ "last_context_overflow_session_id",
40
+ "previous_session_id",
41
+ "last_fatal_error_code",
42
+ "continuation_summary_path",
43
+ "no_progress_count",
44
+ "last_progress_fingerprint",
45
+ "needs_attention",
46
+ "stalled_context_continuation",
47
+ "stalled_reason",
48
+ ]
49
+
50
+ CONTINUATION_COUNTER_FIELDS = [
51
+ "context_overflow_count",
52
+ "continuation_count",
53
+ ]
54
+
55
+ STALL_REASON = "context_overflow_without_git_checkpoint_or_artifact_progress"
56
+
57
+ SEMANTIC_CHECKPOINT_FIELDS = (
58
+ "current_stage",
59
+ "next_stage",
60
+ "stage_result",
61
+ "repair_scope",
62
+ "repair_round",
63
+ "blocked_reason",
64
+ "terminal_status",
65
+ )
66
+
67
+
68
+ def now_iso():
69
+ """Return the current UTC time in ISO8601 format."""
70
+ return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
71
+
72
+
73
+ def _default_project_root():
74
+ env = os.environ.get("PROJECT_ROOT")
75
+ if env:
76
+ return os.path.abspath(env)
77
+ script_dir = os.path.dirname(os.path.abspath(__file__))
78
+ pipeline_dir = os.path.dirname(script_dir)
79
+ pipeline_parent = os.path.dirname(pipeline_dir)
80
+ if os.path.basename(pipeline_parent) == ".prizmkit":
81
+ return os.path.dirname(pipeline_parent)
82
+ return pipeline_parent
83
+
84
+
85
+ def _default_item_status(item_id, id_key):
86
+ now = now_iso()
87
+ return {
88
+ id_key: item_id,
89
+ "retry_count": 0,
90
+ "max_retries": 3,
91
+ "max_infra_retries": 3,
92
+ "infra_error_count": 0,
93
+ "last_infra_error_session_id": None,
94
+ "sessions": [],
95
+ "last_session_id": None,
96
+ "resume_from_phase": None,
97
+ "created_at": now,
98
+ "updated_at": now,
99
+ }
100
+
101
+
102
+ def load_item_status(state_dir, item_id, *, id_key="feature_id"):
103
+ """Load runtime state from status.json for a task item."""
104
+ status_path = os.path.join(state_dir, item_id, "status.json")
105
+ if not os.path.isfile(status_path):
106
+ return _default_item_status(item_id, id_key)
107
+ data, err = load_json_file(status_path)
108
+ if err:
109
+ return _default_item_status(item_id, id_key)
110
+ data.pop("status", None)
111
+ return data
112
+
113
+
114
+ def save_item_status(state_dir, item_id, status_data, *, write_json_fn=None):
115
+ """Write status.json for a task item (runtime fields only)."""
116
+ writer = write_json_fn or write_json_file
117
+ status_data.pop("status", None)
118
+ status_path = os.path.join(state_dir, item_id, "status.json")
119
+ return writer(status_path, status_data)
120
+
121
+
122
+ def get_item_status_from_list(list_path, item_id, *, list_key="features"):
123
+ """Read a single item's status from its plan list."""
124
+ data, err = load_json_file(list_path)
125
+ if err:
126
+ return "pending"
127
+ for item in data.get(list_key, []):
128
+ if isinstance(item, dict) and item.get("id") == item_id:
129
+ return item.get("status", "pending")
130
+ return "pending"
131
+
132
+
133
+ def update_item_in_list(
134
+ list_path,
135
+ item_id,
136
+ new_status,
137
+ *,
138
+ list_key="features",
139
+ item_label="Feature",
140
+ list_display_path=".prizmkit/plans/feature-list.json",
141
+ write_json_fn=None,
142
+ ):
143
+ """Update an item's status in the target plan list JSON."""
144
+ writer = write_json_fn or write_json_file
145
+ data, err = load_json_file(list_path)
146
+ if err:
147
+ return err
148
+ items = data.get(list_key, [])
149
+ found = False
150
+ for item in items:
151
+ if isinstance(item, dict) and item.get("id") == item_id:
152
+ item["status"] = new_status
153
+ found = True
154
+ break
155
+ if not found:
156
+ return "{} '{}' not found in {}".format(item_label, item_id, list_display_path)
157
+ return writer(list_path, data)
158
+
159
+
160
+ def has_pending_continuation_metadata(status_data):
161
+ """Return True when runtime state still has pending continuation metadata."""
162
+ return any(key in status_data for key in CONTINUATION_PENDING_FIELDS)
163
+
164
+
165
+ def clear_pending_continuation_metadata(status_data):
166
+ """Clear branch/pending continuation fields while preserving observability counters."""
167
+ for key in CONTINUATION_PENDING_FIELDS:
168
+ status_data.pop(key, None)
169
+
170
+
171
+ def reset_continuation_metadata(status_data):
172
+ """Clear all continuation runtime metadata, including manual-reset counters."""
173
+ clear_pending_continuation_metadata(status_data)
174
+ for key in CONTINUATION_COUNTER_FIELDS:
175
+ status_data.pop(key, None)
176
+
177
+
178
+ def read_checkpoint_phase(project_root, *artifact_parts):
179
+ """Read the integer step cursor from a task family workflow checkpoint."""
180
+ checkpoint_path = os.path.join(
181
+ os.path.abspath(project_root) if project_root else _default_project_root(),
182
+ ".prizmkit",
183
+ *artifact_parts,
184
+ "workflow-checkpoint.json",
185
+ )
186
+ return read_checkpoint_cursor(checkpoint_path)
187
+
188
+
189
+ def _load_progress_fingerprint(raw):
190
+ if not raw:
191
+ return None
192
+ try:
193
+ return json.loads(raw)
194
+ except (TypeError, ValueError):
195
+ return {"unparsed": str(raw)}
196
+
197
+
198
+ def _load_checkpoint_state(raw):
199
+ if not raw:
200
+ return {}
201
+ try:
202
+ data = json.loads(raw)
203
+ except (TypeError, ValueError):
204
+ return {}
205
+ if not isinstance(data, dict):
206
+ return {}
207
+ return {key: data.get(key) for key in SEMANTIC_CHECKPOINT_FIELDS}
208
+
209
+
210
+ def _sync_semantic_checkpoint(status_data, args):
211
+ semantic = _load_checkpoint_state(getattr(args, "checkpoint_state", None))
212
+ if semantic:
213
+ status_data.update(semantic)
214
+ return {key: status_data.get(key) for key in SEMANTIC_CHECKPOINT_FIELDS}
215
+
216
+
217
+ def _set_continuation_common(status_data, args, session_id, *, pop_infra_error_session=True):
218
+ if args.active_dev_branch:
219
+ status_data["active_dev_branch"] = args.active_dev_branch
220
+ if args.base_branch:
221
+ status_data["base_branch"] = args.base_branch
222
+ status_data["last_context_overflow_session_id"] = session_id
223
+ status_data["previous_session_id"] = session_id
224
+ status_data["last_fatal_error_code"] = args.last_fatal_error_code or "context_overflow"
225
+ if args.continuation_summary_path:
226
+ status_data["continuation_summary_path"] = args.continuation_summary_path
227
+ else:
228
+ status_data.pop("continuation_summary_path", None)
229
+ if args.no_progress_count is not None:
230
+ status_data["no_progress_count"] = max(0, args.no_progress_count)
231
+ fingerprint = _load_progress_fingerprint(args.progress_fingerprint)
232
+ if fingerprint is not None:
233
+ status_data["last_progress_fingerprint"] = fingerprint
234
+ if pop_infra_error_session:
235
+ status_data.pop("last_infra_error_session_id", None)
236
+ else:
237
+ status_data["last_infra_error_session_id"] = None
238
+ status_data["resume_from_phase"] = None
239
+ if session_id:
240
+ status_data["last_session_id"] = session_id
241
+
242
+
243
+ def _set_ai_error_continuation_metadata(status_data, args, session_id, reason):
244
+ """Preserve durable task/session state for any retryable launched AI error."""
245
+ if args.active_dev_branch:
246
+ status_data["active_dev_branch"] = args.active_dev_branch
247
+ if args.base_branch:
248
+ status_data["base_branch"] = args.base_branch
249
+ status_data["continuation_pending"] = True
250
+ status_data["continuation_reason"] = reason
251
+ status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
252
+ status_data["previous_session_id"] = session_id
253
+ status_data["last_fatal_error_code"] = args.last_fatal_error_code or reason
254
+ if args.continuation_summary_path:
255
+ status_data["continuation_summary_path"] = args.continuation_summary_path
256
+ if args.no_progress_count is not None:
257
+ status_data["no_progress_count"] = max(0, args.no_progress_count)
258
+ fingerprint = _load_progress_fingerprint(args.progress_fingerprint)
259
+ if fingerprint is not None:
260
+ status_data["last_progress_fingerprint"] = fingerprint
261
+ status_data["resume_from_phase"] = None
262
+ if session_id:
263
+ sessions = status_data.get("sessions", [])
264
+ if session_id not in sessions:
265
+ sessions.append(session_id)
266
+ status_data["sessions"] = sessions
267
+ status_data["last_session_id"] = session_id
268
+
269
+
270
+ def set_context_overflow_continuation_metadata(
271
+ status_data,
272
+ args,
273
+ session_id,
274
+ *,
275
+ pop_infra_error_session=True,
276
+ ):
277
+ """Record continuation metadata for a context-overflow outcome in status.json."""
278
+ status_data["context_overflow_count"] = status_data.get("context_overflow_count", 0) + 1
279
+ status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
280
+ status_data["continuation_pending"] = True
281
+ status_data["continuation_reason"] = "context_overflow"
282
+ status_data.pop("needs_attention", None)
283
+ status_data.pop("stalled_context_continuation", None)
284
+ status_data.pop("stalled_reason", None)
285
+ _set_continuation_common(
286
+ status_data,
287
+ args,
288
+ session_id,
289
+ pop_infra_error_session=pop_infra_error_session,
290
+ )
291
+
292
+
293
+ def set_stalled_context_continuation_metadata(
294
+ status_data,
295
+ args,
296
+ session_id,
297
+ *,
298
+ pop_infra_error_session=True,
299
+ ):
300
+ """Record no-progress context-overflow stall without consuming retry budgets."""
301
+ status_data["context_overflow_count"] = status_data.get("context_overflow_count", 0) + 1
302
+ status_data["continuation_count"] = status_data.get("continuation_count", 0) + 1
303
+ _set_continuation_common(
304
+ status_data,
305
+ args,
306
+ session_id,
307
+ pop_infra_error_session=pop_infra_error_session,
308
+ )
309
+ status_data["continuation_pending"] = False
310
+ status_data["continuation_reason"] = STALL_REASON
311
+ status_data["needs_attention"] = True
312
+ status_data["stalled_context_continuation"] = True
313
+ status_data["stalled_reason"] = STALL_REASON
314
+ if args.no_progress_count is None or args.no_progress_count < 2:
315
+ status_data["no_progress_count"] = 2
316
+
317
+
318
+ def continuation_metadata_summary(status_data):
319
+ """Return additive continuation fields for CLI JSON outputs."""
320
+ return {
321
+ "active_dev_branch": status_data.get("active_dev_branch"),
322
+ "base_branch": status_data.get("base_branch"),
323
+ "continuation_pending": status_data.get("continuation_pending", False),
324
+ "continuation_reason": status_data.get("continuation_reason"),
325
+ "last_context_overflow_session_id": status_data.get("last_context_overflow_session_id"),
326
+ "last_fatal_error_code": status_data.get("last_fatal_error_code"),
327
+ "previous_session_id": status_data.get("previous_session_id"),
328
+ "context_overflow_count": status_data.get("context_overflow_count", 0),
329
+ "continuation_count": status_data.get("continuation_count", 0),
330
+ "no_progress_count": status_data.get("no_progress_count", 0),
331
+ "last_progress_fingerprint": status_data.get("last_progress_fingerprint"),
332
+ "needs_attention": status_data.get("needs_attention", False),
333
+ "stalled_context_continuation": status_data.get("stalled_context_continuation", False),
334
+ "stalled_reason": status_data.get("stalled_reason"),
335
+ "continuation_summary_path": status_data.get("continuation_summary_path"),
336
+ }
337
+
338
+
339
+ def _resolve_project_file(project_root, path):
340
+ if not path:
341
+ return None
342
+ if os.path.isabs(path):
343
+ target = os.path.abspath(path)
344
+ else:
345
+ target = os.path.abspath(os.path.join(project_root, path))
346
+ root = os.path.abspath(project_root)
347
+ try:
348
+ rel = os.path.relpath(target, root)
349
+ except ValueError:
350
+ return None
351
+ if rel == os.pardir or rel.startswith(os.pardir + os.sep):
352
+ return None
353
+ return target
354
+
355
+
356
+ def cleanup_continuation_artifacts(project_root, status_data, candidate_paths=None):
357
+ """Delete durable continuation handoff files for a manual clean reset."""
358
+ candidates = []
359
+ if isinstance(status_data, dict):
360
+ candidates.append(status_data.get("continuation_summary_path"))
361
+ candidates.extend(candidate_paths or [])
362
+
363
+ cleaned = []
364
+ seen = set()
365
+ for candidate in candidates:
366
+ target = _resolve_project_file(project_root, candidate)
367
+ if not target or target in seen:
368
+ continue
369
+ seen.add(target)
370
+ if os.path.basename(target) != "continuation-summary.md":
371
+ continue
372
+ if os.path.isfile(target):
373
+ os.remove(target)
374
+ cleaned.append("Deleted continuation artifact {}".format(target))
375
+ return cleaned
376
+
377
+
378
+ def load_session_status(state_dir, item_id, session_id):
379
+ """Read session-status.json for a specific task session."""
380
+ session_status_path = os.path.join(
381
+ state_dir,
382
+ item_id,
383
+ "sessions",
384
+ session_id,
385
+ "session-status.json",
386
+ )
387
+ data, err = load_json_file(session_status_path)
388
+ if err:
389
+ return None, err
390
+ return data, None
391
+
392
+
393
+ def auto_skip_blocked_items(
394
+ list_path,
395
+ state_dir,
396
+ blocking_item_id=None,
397
+ *,
398
+ list_key,
399
+ id_key,
400
+ blocking_statuses,
401
+ skip_only_when_status=None,
402
+ terminal_statuses=None,
403
+ error_on_load=False,
404
+ error_on_write=False,
405
+ load_load_label="list",
406
+ item_noun="item",
407
+ detailed_stderr=False,
408
+ write_json_fn=None,
409
+ ):
410
+ """Recursively propagate terminal blockers to pending downstream items."""
411
+ writer = write_json_fn or write_json_file
412
+ data, err = load_json_file(list_path)
413
+ if err:
414
+ if error_on_load:
415
+ error_out("Cannot load {} for auto-skip: {}".format(load_load_label, err))
416
+ return []
417
+ items = data.get(list_key, [])
418
+ status_map = {
419
+ item.get("id"): item.get("status", "pending")
420
+ for item in items
421
+ if isinstance(item, dict) and item.get("id")
422
+ }
423
+
424
+ blocker_and_skip_statuses = set(blocking_statuses) | {"auto_skipped"}
425
+ to_skip = set()
426
+ changed = True
427
+ while changed:
428
+ changed = False
429
+ for item in items:
430
+ if not isinstance(item, dict):
431
+ continue
432
+ item_id = item.get("id")
433
+ if not item_id or item_id in to_skip:
434
+ continue
435
+ current = status_map.get(item_id, "pending")
436
+ if skip_only_when_status is not None:
437
+ if current != skip_only_when_status:
438
+ continue
439
+ elif terminal_statuses is not None and current in terminal_statuses:
440
+ continue
441
+ deps = item.get("dependencies", [])
442
+ if not isinstance(deps, list):
443
+ continue
444
+ if any(
445
+ status_map.get(dep_id, "pending") in blocker_and_skip_statuses
446
+ or dep_id in to_skip
447
+ for dep_id in deps
448
+ ):
449
+ to_skip.add(item_id)
450
+ status_map[item_id] = "auto_skipped"
451
+ changed = True
452
+
453
+ if not to_skip:
454
+ return []
455
+
456
+ for item in items:
457
+ if isinstance(item, dict) and item.get("id") in to_skip:
458
+ item["status"] = "auto_skipped"
459
+ err = writer(list_path, data)
460
+ if err and error_on_write:
461
+ error_out("Failed to write auto-skipped {}s: {}".format(item_noun, err))
462
+ return []
463
+
464
+ for item_id in to_skip:
465
+ item_state = load_item_status(state_dir, item_id, id_key=id_key)
466
+ item_state["updated_at"] = now_iso()
467
+ err = save_item_status(state_dir, item_id, item_state, write_json_fn=writer)
468
+ if err and error_on_write:
469
+ error_out("Failed to save auto-skipped {} status: {}".format(item_noun, err))
470
+ return []
471
+
472
+ skipped_info = []
473
+ for item in items:
474
+ if not isinstance(item, dict) or item.get("id") not in to_skip:
475
+ continue
476
+ item_id = item["id"]
477
+ deps = item.get("dependencies", [])
478
+ blockers = [
479
+ dep_id
480
+ for dep_id in deps
481
+ if dep_id == blocking_item_id
482
+ or status_map.get(dep_id, "pending") in blocker_and_skip_statuses
483
+ or dep_id in to_skip
484
+ ]
485
+ skipped_info.append(
486
+ {
487
+ id_key: item_id,
488
+ "title": item.get("title", ""),
489
+ "blocked_by": blockers,
490
+ }
491
+ )
492
+
493
+ if detailed_stderr:
494
+ print(
495
+ "[auto-skip] {} feature(s) auto-skipped due to failed {}:".format(
496
+ len(skipped_info), blocking_item_id
497
+ ),
498
+ file=sys.stderr,
499
+ )
500
+ for info in skipped_info:
501
+ print(
502
+ " {} ({}) — blocked by {}".format(
503
+ info[id_key],
504
+ info["title"],
505
+ ", ".join(info["blocked_by"]),
506
+ ),
507
+ file=sys.stderr,
508
+ )
509
+ else:
510
+ cause = blocking_item_id or "existing terminal blockers"
511
+ print(
512
+ "[auto-skip] {} {}(s) auto-skipped due to {}".format(
513
+ len(skipped_info), item_noun, cause
514
+ ),
515
+ file=sys.stderr,
516
+ )
517
+ return skipped_info
518
+
519
+
520
+ def reconcile_orphaned_auto_skipped_items(
521
+ list_path,
522
+ state_dir,
523
+ *,
524
+ list_key,
525
+ id_key,
526
+ blocking_root_statuses,
527
+ item_label,
528
+ item_noun,
529
+ list_noun,
530
+ write_json_fn=None,
531
+ ):
532
+ """Restore auto-skipped items that have no current blocking root."""
533
+ writer = write_json_fn or write_json_file
534
+ data, err = load_json_file(list_path)
535
+ if err:
536
+ raise RuntimeError("Cannot load {} for orphan recovery: {}".format(list_noun, err))
537
+ items = data.get(list_key, [])
538
+ orphan_ids = orphaned_auto_skipped_ids(
539
+ items,
540
+ blocking_root_statuses=blocking_root_statuses,
541
+ item_label=item_label,
542
+ )
543
+ if not orphan_ids:
544
+ return []
545
+
546
+ orphan_set = set(orphan_ids)
547
+ for item in items:
548
+ if isinstance(item, dict) and item.get("id") in orphan_set:
549
+ item["status"] = "pending"
550
+ err = writer(list_path, data)
551
+ if err:
552
+ raise RuntimeError("Failed to recover orphaned {}s: {}".format(item_noun, err))
553
+
554
+ for item_id in orphan_ids:
555
+ item_state = load_item_status(state_dir, item_id, id_key=id_key)
556
+ item_state["updated_at"] = now_iso()
557
+ err = save_item_status(state_dir, item_id, item_state, write_json_fn=writer)
558
+ if err:
559
+ raise RuntimeError("Failed to save recovered {} status: {}".format(item_noun, err))
560
+
561
+ print(
562
+ "[auto-skip] recovered {} orphaned {}(s): {}".format(
563
+ len(orphan_ids), item_noun, ", ".join(orphan_ids)
564
+ ),
565
+ file=sys.stderr,
566
+ )
567
+ return list(orphan_ids)
568
+
569
+
570
+ def action_pause(state_dir, *, write_json_fn=None):
571
+ """Save current pipeline state for graceful shutdown."""
572
+ writer = write_json_fn or write_json_file
573
+ pipeline_path = os.path.join(state_dir, "pipeline.json")
574
+ data, err = load_json_file(pipeline_path)
575
+ if err:
576
+ data = {"status": "paused", "paused_at": now_iso()}
577
+ else:
578
+ data["status"] = "paused"
579
+ data["paused_at"] = now_iso()
580
+
581
+ err = writer(pipeline_path, data)
582
+ if err:
583
+ error_out("Failed to write pipeline.json: {}".format(err))
584
+ return
585
+
586
+ result = {
587
+ "action": "pause",
588
+ "status": "paused",
589
+ "paused_at": data["paused_at"],
590
+ }
591
+ print(json.dumps(result, indent=2, ensure_ascii=False))