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
@@ -1,23 +1,21 @@
1
- """Durable task checkout identity for pipeline branch and worktree reuse."""
1
+ """Durable task checkout identity for pipeline branch reuse."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
- import os
7
- import shutil
8
- import tempfile
9
- import time
10
6
  from contextlib import contextmanager
11
7
  from dataclasses import asdict, dataclass
12
8
  from pathlib import Path
13
9
  from typing import Iterator
14
10
 
11
+ from .atomic_io import write_json_atomic
12
+ from .processes import PidLockError, exclusive_pid_lock
13
+
15
14
 
16
15
  CHECKOUT_STATE_ACTIVE = "active"
17
16
  CHECKOUT_STATE_COMPLETED = "completed"
18
17
  CHECKOUT_STATE_RESET = "reset"
19
18
  CHECKOUT_MODE_BRANCH = "branch"
20
- CHECKOUT_MODE_WORKTREE = "worktree"
21
19
 
22
20
 
23
21
  class TaskCheckoutError(RuntimeError):
@@ -34,7 +32,6 @@ class TaskCheckout:
34
32
  active_dev_branch: str = ""
35
33
  base_branch: str = ""
36
34
  checkout_mode: str = CHECKOUT_MODE_BRANCH
37
- worktree_path: str = ""
38
35
 
39
36
  @classmethod
40
37
  def active(
@@ -45,21 +42,15 @@ class TaskCheckout:
45
42
  base_branch: str,
46
43
  *,
47
44
  checkout_mode: str = CHECKOUT_MODE_BRANCH,
48
- worktree_path: str = "",
49
45
  ) -> "TaskCheckout":
50
46
  branch = active_dev_branch.strip()
51
47
  base = base_branch.strip()
52
48
  mode = checkout_mode.strip()
53
- path = worktree_path.strip()
54
49
  if not branch or not base:
55
50
  raise TaskCheckoutError("Active task checkout requires development and base branches")
56
- if mode not in {CHECKOUT_MODE_BRANCH, CHECKOUT_MODE_WORKTREE}:
51
+ if mode != CHECKOUT_MODE_BRANCH:
57
52
  raise TaskCheckoutError(f"Unsupported task checkout mode: {mode or '(empty)'}")
58
- if mode == CHECKOUT_MODE_WORKTREE and not path:
59
- raise TaskCheckoutError("Worktree task checkout requires a canonical worktree path")
60
- if mode == CHECKOUT_MODE_BRANCH:
61
- path = ""
62
- return cls(task_type, task_id, CHECKOUT_STATE_ACTIVE, branch, base, mode, path)
53
+ return cls(task_type, task_id, CHECKOUT_STATE_ACTIVE, branch, base, mode)
63
54
 
64
55
  @classmethod
65
56
  def reset(cls, task_type: str, task_id: str) -> "TaskCheckout":
@@ -75,7 +66,6 @@ class TaskCheckout:
75
66
  active_dev_branch=self.active_dev_branch,
76
67
  base_branch=self.base_branch,
77
68
  checkout_mode=self.checkout_mode,
78
- worktree_path=self.worktree_path,
79
69
  )
80
70
 
81
71
  @property
@@ -90,10 +80,6 @@ class TaskCheckout:
90
80
  def is_reset(self) -> bool:
91
81
  return self.state == CHECKOUT_STATE_RESET
92
82
 
93
- @property
94
- def uses_worktree(self) -> bool:
95
- return self.checkout_mode == CHECKOUT_MODE_WORKTREE
96
-
97
83
 
98
84
  def task_checkout_path(state_dir: Path | str, task_id: str) -> Path:
99
85
  """Return the canonical checkout identity path for one task."""
@@ -117,116 +103,56 @@ def load_task_checkout(state_dir: Path | str, task_type: str, task_id: str) -> T
117
103
  if not isinstance(data, dict):
118
104
  raise TaskCheckoutError(f"Invalid task checkout identity {path}: expected a JSON object")
119
105
 
106
+ raw_mode = str(data.get("checkout_mode") or CHECKOUT_MODE_BRANCH).strip()
107
+ if raw_mode == "worktree":
108
+ raw_worktree = str(data.get("worktree_path") or "").strip()
109
+ location = f" ({raw_worktree})" if raw_worktree else ""
110
+ raise TaskCheckoutError(
111
+ f"Task {task_id} uses retired worktree checkout mode{location}; "
112
+ "remove any leftover linked worktree manually and reset/clean the task before rerunning."
113
+ )
114
+ if raw_mode != CHECKOUT_MODE_BRANCH:
115
+ raise TaskCheckoutError(f"Invalid task checkout mode in {path}: {raw_mode or '(empty)'}")
116
+
120
117
  checkout = TaskCheckout(
121
118
  task_type=str(data.get("task_type") or ""),
122
119
  task_id=str(data.get("task_id") or ""),
123
120
  state=str(data.get("state") or ""),
124
121
  active_dev_branch=str(data.get("active_dev_branch") or ""),
125
122
  base_branch=str(data.get("base_branch") or ""),
126
- checkout_mode=str(data.get("checkout_mode") or CHECKOUT_MODE_BRANCH),
127
- worktree_path=str(data.get("worktree_path") or ""),
123
+ checkout_mode=raw_mode,
128
124
  )
129
125
  if checkout.task_type != task_type or checkout.task_id != task_id:
130
126
  raise TaskCheckoutError(f"Task checkout identity mismatch in {path}")
131
127
  if checkout.state not in {CHECKOUT_STATE_ACTIVE, CHECKOUT_STATE_COMPLETED, CHECKOUT_STATE_RESET}:
132
128
  raise TaskCheckoutError(f"Invalid task checkout state in {path}: {checkout.state or '(empty)'}")
133
- if checkout.checkout_mode not in {CHECKOUT_MODE_BRANCH, CHECKOUT_MODE_WORKTREE}:
134
- raise TaskCheckoutError(f"Invalid task checkout mode in {path}: {checkout.checkout_mode or '(empty)'}")
135
129
  if checkout.is_active or checkout.is_completed:
136
130
  if not checkout.active_dev_branch.strip() or not checkout.base_branch.strip():
137
131
  raise TaskCheckoutError(f"Incomplete task checkout identity in {path}")
138
- if checkout.uses_worktree and not checkout.worktree_path.strip():
139
- raise TaskCheckoutError(f"Missing worktree path in task checkout identity {path}")
140
132
  return checkout
141
133
 
142
134
 
143
- def _process_is_running(pid: int) -> bool:
144
- if pid <= 0:
145
- return False
146
- try:
147
- os.kill(pid, 0)
148
- except ProcessLookupError:
149
- return False
150
- except PermissionError:
151
- return True
152
- except OSError:
153
- return False
154
- return True
155
-
156
-
157
- def _lock_owner_pid(lock_path: Path) -> int:
158
- for _attempt in range(5):
159
- try:
160
- data = json.loads((lock_path / "owner.json").read_text(encoding="utf-8"))
161
- return int(data.get("pid") or 0) if isinstance(data, dict) else 0
162
- except FileNotFoundError:
163
- time.sleep(0.01)
164
- except (OSError, ValueError, json.JSONDecodeError):
165
- return 0
166
- return 0
167
-
168
-
169
- def _remove_stale_lock(lock_path: Path) -> None:
170
- stale_path = lock_path.with_name(f"{lock_path.name}.stale-{os.getpid()}-{os.urandom(6).hex()}")
171
- try:
172
- os.rename(lock_path, stale_path)
173
- except FileNotFoundError:
174
- return
175
- except OSError as exc:
176
- raise TaskCheckoutError(f"Cannot claim stale task checkout lock {lock_path}: {exc}") from exc
177
- shutil.rmtree(stale_path, ignore_errors=True)
178
-
179
-
180
135
  @contextmanager
181
136
  def task_checkout_guard(state_dir: Path | str, task_id: str) -> Iterator[None]:
182
137
  """Exclusively guard one task lifecycle, reclaiming locks from dead processes."""
183
138
  lock_path = task_checkout_lock_path(state_dir, task_id)
184
- lock_path.parent.mkdir(parents=True, exist_ok=True)
185
- acquired = False
186
- for _attempt in range(3):
187
- try:
188
- lock_path.mkdir()
189
- (lock_path / "owner.json").write_text(json.dumps({"pid": os.getpid()}) + "\n", encoding="utf-8")
190
- acquired = True
191
- break
192
- except FileExistsError:
193
- owner_pid = _lock_owner_pid(lock_path)
194
- if _process_is_running(owner_pid):
195
- raise TaskCheckoutError(f"Task {task_id} is already running or being reset (PID {owner_pid})")
196
- _remove_stale_lock(lock_path)
197
- except OSError as exc:
198
- raise TaskCheckoutError(f"Cannot acquire task checkout lock {lock_path}: {exc}") from exc
199
- if not acquired:
200
- raise TaskCheckoutError(f"Cannot acquire task checkout lock {lock_path}")
201
139
  try:
202
- yield
203
- finally:
204
- shutil.rmtree(lock_path, ignore_errors=True)
140
+ with exclusive_pid_lock(
141
+ lock_path,
142
+ busy_message=f"Task {task_id} is already running or being reset (PID {{pid}})",
143
+ error_label="task checkout lock",
144
+ ):
145
+ yield
146
+ except PidLockError as exc:
147
+ raise TaskCheckoutError(str(exc)) from exc
205
148
 
206
149
 
207
150
  def persist_task_checkout(state_dir: Path | str, checkout: TaskCheckout) -> Path:
208
151
  """Atomically persist checkout identity while the caller holds its task guard."""
209
152
  path = task_checkout_path(state_dir, checkout.task_id)
210
- path.parent.mkdir(parents=True, exist_ok=True)
211
- descriptor = -1
212
- temporary = ""
213
153
  try:
214
- descriptor, temporary = tempfile.mkstemp(prefix=".checkout-", suffix=".json", dir=path.parent)
215
- with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
216
- descriptor = -1
217
- json.dump(asdict(checkout), handle, indent=2, ensure_ascii=False)
218
- handle.write("\n")
219
- handle.flush()
220
- os.fsync(handle.fileno())
221
- os.replace(temporary, path)
154
+ write_json_atomic(path, asdict(checkout))
222
155
  except OSError as exc:
223
- if descriptor >= 0:
224
- os.close(descriptor)
225
- if temporary:
226
- try:
227
- os.unlink(temporary)
228
- except OSError:
229
- pass
230
156
  raise TaskCheckoutError(f"Cannot persist task checkout identity {path}: {exc}") from exc
231
157
  return path
232
158
 
@@ -262,7 +188,6 @@ def replace_missing_recorded_base_locked(
262
188
  existing.active_dev_branch,
263
189
  base_branch,
264
190
  checkout_mode=existing.checkout_mode,
265
- worktree_path=existing.worktree_path,
266
191
  )
267
192
  current = load_task_checkout(state_dir, existing.task_type, existing.task_id)
268
193
  if current != existing:
@@ -15,6 +15,9 @@ _RESULT_LINE_PATTERN = re.compile(
15
15
  _BARE_RESULT_LINE_PATTERN = re.compile(
16
16
  r"(?m)^(TEST_PASS|TEST_NEEDS_FIXES|TEST_BLOCKED)\s*$"
17
17
  )
18
+ _PRODUCTION_CHANGED_LINE_PATTERN = re.compile(
19
+ r"(?im)^-\s*Production changed during test:\s*(.+?)\s*$"
20
+ )
18
21
  _RESULT_KEYS = {
19
22
  "schema_version",
20
23
  "result",
@@ -108,21 +111,42 @@ def valid_test_artifact_pair(
108
111
  result_path: str | Path,
109
112
  *,
110
113
  required_result: str | None = None,
114
+ require_no_production_change: bool | None = None,
111
115
  ) -> bool:
112
116
  """Validate one strict sibling report/result pair and terminal result."""
113
117
  return _valid_test_artifact_pair(
114
118
  report_path,
115
119
  result_path,
116
120
  required_result=required_result,
121
+ require_no_production_change=require_no_production_change,
117
122
  )
118
123
 
119
124
 
125
+ def test_pass_requires_delta_review(
126
+ report_path: str | Path,
127
+ result_path: str | Path,
128
+ ) -> bool:
129
+ """Return whether valid TEST_PASS artifacts require delta Code Review."""
130
+ if not _valid_test_artifact_pair(
131
+ report_path,
132
+ result_path,
133
+ required_result="TEST_PASS",
134
+ require_no_production_change=False,
135
+ ):
136
+ return False
137
+ projection = load_test_result(result_path)
138
+ return bool(projection and projection.get("production_changed") is True)
139
+
140
+
120
141
  def _valid_test_artifact_pair(
121
142
  report_path: str | Path,
122
143
  result_path: str | Path,
123
144
  *,
124
145
  required_result: str | None,
146
+ require_no_production_change: bool | None = None,
125
147
  ) -> bool:
148
+ if require_no_production_change is None:
149
+ require_no_production_change = required_result == "TEST_PASS"
126
150
  report = Path(report_path)
127
151
  result = Path(result_path)
128
152
  if not report.is_file() or not result.is_file():
@@ -134,15 +158,45 @@ def _valid_test_artifact_pair(
134
158
  return False
135
159
  if required_result is not None and projection.get("result") != required_result:
136
160
  return False
161
+ if require_no_production_change and projection.get("production_changed"):
162
+ return False
137
163
  try:
138
164
  report_text = report.read_text(encoding="utf-8")
139
165
  except OSError:
140
166
  return False
141
167
  final_result = _report_final_result(report_text)
142
- return (
143
- report_text.startswith("# Test Report")
144
- and final_result == projection["result"]
145
- )
168
+ if not report_text.startswith("# Test Report") or final_result != projection["result"]:
169
+ return False
170
+ report_changed_valid, report_changed = _parse_report_production_changed(report_text)
171
+ if not report_changed_valid:
172
+ return False
173
+ if report_changed is not None and report_changed != projection["production_changed"]:
174
+ return False
175
+ return True
176
+
177
+
178
+ def _parse_report_production_changed(report: str) -> tuple[bool, bool | None]:
179
+ """Parse explicit production-change flags from test-report.md."""
180
+ values: list[bool] = []
181
+ for match in _PRODUCTION_CHANGED_LINE_PATTERN.finditer(report):
182
+ normalized = match.group(1).strip().lower()
183
+ if normalized == "yes":
184
+ values.append(True)
185
+ elif normalized == "no":
186
+ values.append(False)
187
+ else:
188
+ return False, None
189
+ if not values:
190
+ return True, None
191
+ if len(set(values)) != 1:
192
+ return False, None
193
+ return True, values[0]
194
+
195
+
196
+ def _report_production_changed(report: str) -> bool | None:
197
+ """Return unambiguous production-change boolean declared in test-report.md."""
198
+ valid, value = _parse_report_production_changed(report)
199
+ return value if valid else None
146
200
 
147
201
 
148
202
  def _report_final_result(report: str) -> str | None:
@@ -18,7 +18,7 @@ from utils import setup_logging
18
18
 
19
19
  REQUIRED_FIELDS = ["session_id", "status", "timestamp"]
20
20
  # At least one of these ID fields must be present (depends on pipeline type)
21
- ID_FIELDS = ["feature_id", "bug_id", "refactor_id"]
21
+ ID_FIELDS = ["feature_id", "bug_id"]
22
22
 
23
23
  LOGGER = setup_logging("check-session-status")
24
24
 
@@ -124,24 +124,41 @@ def load_status_file(path):
124
124
  def validate_required_fields(data):
125
125
  """Check that all required fields are present and non-empty.
126
126
 
127
- Returns a list of missing/invalid field names.
128
- In addition to the always-required fields, at least one of
129
- feature_id / bug_id / refactor_id must be present.
127
+ Supports both canonical runtime session-status.json records
128
+ (``session_id``, ``status``, ``task_id``, ``task_type``; ``timestamp`` optional)
129
+ and legacy session-status.json records
130
+ (``session_id``, ``status``, ``feature_id``|``bug_id``, ``timestamp``).
130
131
  """
132
+ if not isinstance(data, dict):
133
+ return ["session_id", "status", "task_id|feature_id|bug_id"]
134
+
131
135
  missing = []
132
- for field in REQUIRED_FIELDS:
133
- if field not in data:
134
- missing.append(field)
135
- elif not isinstance(data[field], str) or not data[field].strip():
136
+ for field in ("session_id", "status"):
137
+ value = data.get(field)
138
+ if not isinstance(value, str) or not value.strip():
136
139
  missing.append(field)
137
140
 
138
- # Check that at least one ID field is present and non-empty
139
- has_id = any(
140
- field in data and isinstance(data[field], str) and data[field].strip()
141
+ task_id = data.get("task_id")
142
+ task_type = data.get("task_type")
143
+ has_canonical_id = (
144
+ isinstance(task_id, str)
145
+ and bool(task_id.strip())
146
+ and task_type in ("feature", "bugfix")
147
+ )
148
+ has_legacy_id = any(
149
+ isinstance(data.get(field), str) and bool(data[field].strip())
141
150
  for field in ID_FIELDS
142
151
  )
143
- if not has_id:
144
- missing.append("feature_id|bug_id|refactor_id")
152
+
153
+ if not has_canonical_id and not has_legacy_id:
154
+ if isinstance(task_id, str) and task_id.strip():
155
+ missing.append("task_type")
156
+ else:
157
+ missing.append("task_id|feature_id|bug_id")
158
+ elif not has_canonical_id:
159
+ ts = data.get("timestamp")
160
+ if not isinstance(ts, str) or not ts.strip():
161
+ missing.append("timestamp")
145
162
 
146
163
  return missing
147
164
 
@@ -158,7 +175,19 @@ def determine_status(data):
158
175
 
159
176
  if status == "success":
160
177
  return "success"
161
- if status == "context_overflow" or has_context_overflow_signal(data):
178
+ if status == "context_overflow":
179
+ return "context_overflow"
180
+ explicit_terminal_statuses = {
181
+ "stalled_context_continuation",
182
+ "commit_missing",
183
+ "docs_missing",
184
+ "merge_conflict",
185
+ "workflow_blocked",
186
+ "workflow_skipped",
187
+ }
188
+ if status in explicit_terminal_statuses:
189
+ return status
190
+ if has_context_overflow_signal(data):
162
191
  return "context_overflow"
163
192
  elif status == "partial":
164
193
  can_resume = data.get("can_resume", False)
@@ -202,11 +231,13 @@ def build_detail_report(data, resolved_status):
202
231
 
203
232
  return {
204
233
  "status": resolved_status,
234
+ "task_id": data.get("task_id"),
235
+ "task_type": data.get("task_type"),
205
236
  "feature_id": data.get("feature_id"),
206
237
  "bug_id": data.get("bug_id"),
207
- "refactor_id": data.get("refactor_id"),
208
238
  "completed_phases": data.get("completed_phases", []),
209
239
  "checkpoint_reached": data.get("checkpoint_reached"),
240
+ "checkpoint_state": data.get("checkpoint_state"),
210
241
  "tasks_completed": data.get("tasks_completed", 0),
211
242
  "tasks_total": data.get("tasks_total", 0),
212
243
  "error_count": error_count,
@@ -241,13 +272,18 @@ def main():
241
272
  # Validate required fields
242
273
  missing = validate_required_fields(data)
243
274
  if missing:
275
+ safe_data = data if isinstance(data, dict) else {}
244
276
  detail = {
245
277
  "status": "crashed",
246
- "feature_id": data.get("feature_id"),
247
- "completed_phases": data.get("completed_phases", []),
248
- "checkpoint_reached": data.get("checkpoint_reached"),
249
- "tasks_completed": data.get("tasks_completed", 0),
250
- "tasks_total": data.get("tasks_total", 0),
278
+ "task_id": safe_data.get("task_id"),
279
+ "task_type": safe_data.get("task_type"),
280
+ "feature_id": safe_data.get("feature_id"),
281
+ "bug_id": safe_data.get("bug_id"),
282
+ "completed_phases": safe_data.get("completed_phases", []),
283
+ "checkpoint_reached": safe_data.get("checkpoint_reached"),
284
+ "checkpoint_state": safe_data.get("checkpoint_state"),
285
+ "tasks_completed": safe_data.get("tasks_completed", 0),
286
+ "tasks_total": safe_data.get("tasks_total", 0),
251
287
  "error_count": 1,
252
288
  "can_resume": False,
253
289
  "resume_from_phase": None,
@@ -8,10 +8,11 @@ _PIPELINE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
8
8
  if _PIPELINE_ROOT not in sys.path:
9
9
  sys.path.insert(0, _PIPELINE_ROOT)
10
10
 
11
+ from prizmkit_runtime.atomic_io import write_text_atomic # noqa: E402
11
12
  from prizmkit_runtime.checkpoint_state import checkpoint_cursor as shared_checkpoint_cursor # noqa: E402
12
13
 
13
14
  SUPPORTED_CONTINUATION_MODES = {"context_overflow", "ai_error"}
14
- TASK_TYPES = {"feature", "bugfix", "refactor"}
15
+ TASK_TYPES = {"feature", "bugfix"}
15
16
 
16
17
 
17
18
  def add_continuation_args(parser, default_task_type):
@@ -138,9 +139,11 @@ def continuation_summary_paths(task_type, task_id, task_slug, override_path=""):
138
139
  )
139
140
  return _dedupe([override_path, default_path])
140
141
 
141
- task_dir = "bugfix" if task_type == "bugfix" else "refactor"
142
+ if task_type != "bugfix":
143
+ raise ValueError(f"Unsupported task_type: {task_type}")
144
+
142
145
  task_local = os.path.join(
143
- ".prizmkit", task_dir, task_id, "continuation-summary.md",
146
+ ".prizmkit", "bugfix", task_id, "continuation-summary.md",
144
147
  )
145
148
  specs_path = os.path.join(
146
149
  ".prizmkit", "specs", task_slug or task_id, "continuation-summary.md",
@@ -155,7 +158,7 @@ def durable_paths(task_type, task_id, task_slug):
155
158
  elif task_type == "bugfix":
156
159
  artifact_dir = os.path.join(".prizmkit", "bugfix", task_id)
157
160
  else:
158
- artifact_dir = os.path.join(".prizmkit", "refactor", task_id)
161
+ raise ValueError(f"Unsupported task_type: {task_type}")
159
162
 
160
163
  return {
161
164
  "artifact_dir": artifact_dir,
@@ -374,9 +377,7 @@ def append_continuation_handoff(rendered_prompt, args, project_root, task_type,
374
377
  summary_text = _build_summary(context)
375
378
  for summary_path in paths:
376
379
  abs_summary = os.path.join(project_root, summary_path)
377
- os.makedirs(os.path.dirname(abs_summary), exist_ok=True)
378
- with open(abs_summary, "w", encoding="utf-8") as f:
379
- f.write(summary_text)
380
+ write_text_atomic(abs_summary, summary_text)
380
381
 
381
382
  addendum = _build_addendum(context)
382
383
  return rendered_prompt.rstrip() + "\n\n" + addendum
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python3
2
- """Detect stuck items in the dev-pipeline (features, bugs, or refactors).
2
+ """Detect stuck items in the dev-pipeline (features or bugs).
3
3
 
4
4
  Checks each item for conditions that indicate it is stuck:
5
5
  1. Max retries exceeded
@@ -43,9 +43,9 @@ def parse_args():
43
43
  )
44
44
  parser.add_argument(
45
45
  "--pipeline-type",
46
- choices=["feature", "bugfix", "refactor"],
46
+ choices=["feature", "bugfix"],
47
47
  default=None,
48
- help="Pipeline type (auto-detected from --feature-id/--bug-id/--refactor-id if omitted)",
48
+ help="Pipeline type (auto-detected from --feature-id/--bug-id if omitted)",
49
49
  )
50
50
  parser.add_argument(
51
51
  "--item-id",
@@ -63,11 +63,6 @@ def parse_args():
63
63
  default=None,
64
64
  help="Bug ID — equivalent to --pipeline-type bugfix --item-id <id>",
65
65
  )
66
- parser.add_argument(
67
- "--refactor-id",
68
- default=None,
69
- help="Refactor ID — equivalent to --pipeline-type refactor --item-id <id>",
70
- )
71
66
  parser.add_argument(
72
67
  "--max-retries",
73
68
  type=int,
@@ -90,15 +85,10 @@ def parse_args():
90
85
  default=None,
91
86
  help="Path to bug-fix-list.json",
92
87
  )
93
- parser.add_argument(
94
- "--refactor-list",
95
- default=None,
96
- help="Path to refactor-list.json",
97
- )
98
88
  parser.add_argument(
99
89
  "--task-list",
100
90
  default=None,
101
- help="Path to the task list JSON (feature-list, bug-fix-list, or refactor-list)",
91
+ help="Path to the task list JSON (feature-list or bug-fix-list)",
102
92
  )
103
93
  return parser.parse_args()
104
94
 
@@ -198,6 +188,23 @@ def check_max_retries(item_status, max_retries):
198
188
  return None
199
189
 
200
190
 
191
+ def _session_checkpoint_marker(data):
192
+ """Extract a stable checkpoint progress marker from legacy or canonical status."""
193
+ if not isinstance(data, dict):
194
+ return None
195
+ legacy = data.get("checkpoint_reached")
196
+ if legacy is not None:
197
+ return legacy
198
+ state = data.get("checkpoint_state")
199
+ if not isinstance(state, dict) or not state:
200
+ return None
201
+ stage = str(state.get("current_stage") or state.get("next_stage") or "").strip()
202
+ result = str(state.get("stage_result") or "").strip()
203
+ terminal = str(state.get("terminal_status") or "").strip()
204
+ parts = [part for part in (stage, result, terminal) if part]
205
+ return ":".join(parts) if parts else None
206
+
207
+
201
208
  def check_stuck_checkpoint(item_dir):
202
209
  """Check 2: Is the item stuck at the same checkpoint for 3 consecutive sessions?
203
210
 
@@ -211,8 +218,7 @@ def check_stuck_checkpoint(item_dir):
211
218
  last_three = session_statuses[-3:]
212
219
  checkpoints = []
213
220
  for _sid, data in last_three:
214
- cp = data.get("checkpoint_reached")
215
- checkpoints.append(cp)
221
+ checkpoints.append(_session_checkpoint_marker(data))
216
222
 
217
223
  # All three must be non-None and identical
218
224
  if checkpoints[0] is not None and all(cp == checkpoints[0] for cp in checkpoints):
@@ -246,11 +252,16 @@ def check_stale_heartbeat(item_id, item_status, state_dir, items_subdir, stale_t
246
252
  if not session_id:
247
253
  return None
248
254
 
249
- # Check heartbeat file
255
+ # Check heartbeat file (canonical logs/heartbeat.json first, legacy fallback)
250
256
  heartbeat_path = os.path.join(
257
+ state_dir, items_subdir, item_id, "sessions", session_id, "logs", "heartbeat.json"
258
+ )
259
+ legacy_heartbeat_path = os.path.join(
251
260
  state_dir, items_subdir, item_id, "sessions", session_id, "heartbeat.json"
252
261
  )
253
262
  heartbeat = load_json(heartbeat_path)
263
+ if heartbeat is None and os.path.exists(legacy_heartbeat_path):
264
+ heartbeat = load_json(legacy_heartbeat_path)
254
265
 
255
266
  if heartbeat is None:
256
267
  return {
@@ -262,12 +273,22 @@ def check_stale_heartbeat(item_id, item_status, state_dir, items_subdir, stale_t
262
273
  }
263
274
 
264
275
  # Parse heartbeat timestamp and check staleness
265
- ts_str = heartbeat.get("timestamp")
266
- heartbeat_time = parse_iso_timestamp(ts_str)
276
+ epoch_val = heartbeat.get("last_seen_epoch")
277
+ ts_str = (
278
+ heartbeat.get("timestamp")
279
+ or heartbeat.get("last_heartbeat_at")
280
+ or heartbeat.get("updated_at")
281
+ )
282
+ if isinstance(epoch_val, (int, float)) and not isinstance(epoch_val, bool):
283
+ heartbeat_time = datetime.fromtimestamp(float(epoch_val), tz=timezone.utc)
284
+ else:
285
+ heartbeat_time = parse_iso_timestamp(ts_str)
267
286
  if heartbeat_time is None:
268
287
  return {
269
288
  "reason": "stale_heartbeat",
270
- "details": "Heartbeat has invalid or unparseable timestamp: {}".format(ts_str),
289
+ "details": "Heartbeat has invalid or unparseable timestamp: {}".format(
290
+ epoch_val if epoch_val is not None else ts_str
291
+ ),
271
292
  "suggestion": "Check the agent session - heartbeat timestamp is malformed",
272
293
  }
273
294
 
@@ -345,7 +366,6 @@ def find_task_list(state_dir):
345
366
  fl_path = (
346
367
  pipeline.get("feature_list_path")
347
368
  or pipeline.get("bug_list_path")
348
- or pipeline.get("refactor_list_path")
349
369
  )
350
370
  if not fl_path:
351
371
  return None
@@ -365,7 +385,6 @@ def find_task_list(state_dir):
365
385
  PIPELINE_CONFIG = {
366
386
  "feature": {"subdir": "", "items_key": "features", "id_label": "feature_id"},
367
387
  "bugfix": {"subdir": "", "items_key": "bugs", "id_label": "bug_id"},
368
- "refactor": {"subdir": "", "items_key": "refactors", "id_label": "refactor_id"},
369
388
  }
370
389
 
371
390
 
@@ -390,6 +409,9 @@ def check_item(item_id, state_dir, items_subdir, items_key, task_list_data, max_
390
409
  task_list_status = item.get("status", "pending")
391
410
  break
392
411
 
412
+ if task_list_status in {"completed", "failed", "skipped", "auto_skipped", "needs_info", "split"}:
413
+ return []
414
+
393
415
  reports = []
394
416
 
395
417
  # Check 1: Max retries exceeded
@@ -424,9 +446,9 @@ def resolve_pipeline_type(args):
424
446
  # Explicit --pipeline-type takes precedence
425
447
  if args.pipeline_type:
426
448
  ptype = args.pipeline_type
427
- item_id = args.item_id
428
- task_list = args.task_list
429
- # Legacy / shorthand: --feature-id, --bug-id, --refactor-id
449
+ item_id = args.item_id or (args.feature_id if ptype == "feature" else args.bug_id)
450
+ task_list = args.task_list or (args.feature_list if ptype == "feature" else args.bug_list)
451
+ # Legacy / shorthand: --feature-id, --bug-id
430
452
  elif args.feature_id:
431
453
  ptype = "feature"
432
454
  item_id = args.feature_id
@@ -435,10 +457,6 @@ def resolve_pipeline_type(args):
435
457
  ptype = "bugfix"
436
458
  item_id = args.bug_id
437
459
  task_list = args.bug_list or args.task_list
438
- elif args.refactor_id:
439
- ptype = "refactor"
440
- item_id = args.refactor_id
441
- task_list = args.refactor_list or args.task_list
442
460
  # Legacy: --feature-list without --feature-id means check all features
443
461
  elif args.feature_list:
444
462
  ptype = "feature"
@@ -448,10 +466,6 @@ def resolve_pipeline_type(args):
448
466
  ptype = "bugfix"
449
467
  item_id = None
450
468
  task_list = args.bug_list
451
- elif args.refactor_list:
452
- ptype = "refactor"
453
- item_id = None
454
- task_list = args.refactor_list
455
469
  else:
456
470
  # Default to feature for backward compat
457
471
  ptype = "feature"