prizmkit 1.1.191 → 1.1.192

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/adapters/antigravity/skill-adapter.js +13 -4
  3. package/bundled/adapters/codex/skill-adapter.js +28 -8
  4. package/bundled/adapters/cursor/skill-adapter.js +13 -4
  5. package/bundled/adapters/pi/skill-adapter.js +28 -7
  6. package/bundled/dev-pipeline/.env.example +4 -12
  7. package/bundled/dev-pipeline/README.md +5 -10
  8. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -6
  9. package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
  10. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
  11. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
  12. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
  13. package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -76
  14. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
  15. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +77 -430
  16. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
  17. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
  18. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
  19. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +36 -14
  20. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
  21. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
  22. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
  23. package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
  24. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
  25. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
  26. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
  27. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
  28. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
  29. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +276 -217
  30. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
  31. package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
  32. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +183 -130
  33. package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
  34. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
  35. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
  36. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
  37. package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
  38. package/bundled/dev-pipeline/scripts/continuation.py +6 -4
  39. package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
  40. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
  41. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
  42. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
  43. package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
  44. package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
  45. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
  46. package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
  47. package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
  48. package/bundled/dev-pipeline/scripts/status_common.py +591 -0
  49. package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
  50. package/bundled/dev-pipeline/scripts/update-checkpoint.py +227 -65
  51. package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
  52. package/bundled/dev-pipeline/scripts/utils.py +5 -12
  53. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
  54. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
  55. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
  56. package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
  57. package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
  58. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
  59. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
  60. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
  61. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
  62. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
  63. package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
  64. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
  65. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
  66. package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
  67. package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
  68. package/bundled/dev-pipeline/tests/_helpers.py +418 -0
  69. package/bundled/dev-pipeline/tests/conftest.py +45 -1
  70. package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
  71. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
  72. package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
  73. package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
  74. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
  75. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
  76. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +431 -3099
  77. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
  78. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
  79. package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
  80. package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
  81. package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
  82. package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
  83. package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
  84. package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
  85. package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
  86. package/bundled/dev-pipeline/tests/test_unified_cli.py +155 -2034
  87. package/bundled/dev-pipeline/tests/test_utils.py +3 -3
  88. package/bundled/skills/_metadata.json +9 -63
  89. package/bundled/skills/app-planner/SKILL.md +32 -303
  90. package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
  91. package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
  92. package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
  93. package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
  94. package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
  95. package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
  96. package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
  97. package/bundled/skills/bug-planner/SKILL.md +54 -435
  98. package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
  99. package/bundled/skills/bug-planner/references/input-formats.md +32 -0
  100. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
  101. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
  102. package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
  103. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
  104. package/bundled/skills/feature-planner/SKILL.md +60 -439
  105. package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
  106. package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
  107. package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
  108. package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
  109. package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
  110. package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
  111. package/bundled/skills/feature-workflow/SKILL.md +1 -2
  112. package/bundled/skills/prizmkit/SKILL.md +7 -1
  113. package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
  114. package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
  115. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
  116. package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
  117. package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
  118. package/bundled/skills/prizmkit-init/SKILL.md +24 -127
  119. package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
  120. package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
  121. package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
  122. package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
  123. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
  124. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
  125. package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
  126. package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
  127. package/bundled/skills/prizmkit-test/SKILL.md +25 -133
  128. package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
  129. package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
  130. package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
  131. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
  132. package/bundled/skills/recovery-workflow/SKILL.md +7 -7
  133. package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
  134. package/bundled/skills/recovery-workflow/references/detection.md +1 -3
  135. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
  136. package/bundled/templates/project-memory-template.md +1 -2
  137. package/package.json +1 -1
  138. package/src/scaffold.js +28 -7
  139. package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
  140. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
  141. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
  142. package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
  143. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
  144. package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
  145. package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
  146. package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
  147. package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
  148. package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
  149. package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
  150. package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
  151. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
  152. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
  153. package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
  154. package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
  155. package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
  156. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
  157. package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
  158. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
  159. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
  160. package/bundled/skills/refactor-planner/SKILL.md +0 -467
  161. package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
  162. package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
  163. package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
  164. package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
  165. package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
  166. package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
  167. package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
  168. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
  169. package/bundled/skills/refactor-workflow/SKILL.md +0 -205
@@ -1,10 +1,11 @@
1
- """Python foreground runner dispatch for feature, bugfix, and refactor pipelines."""
1
+ """Python foreground runner dispatch for feature and bugfix pipelines."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
6
  import os
7
7
  import signal
8
+ import subprocess
8
9
  import sys
9
10
  import tempfile
10
11
  import threading
@@ -13,11 +14,12 @@ from collections.abc import Iterator, Mapping
13
14
  from contextlib import contextmanager
14
15
  from pathlib import Path
15
16
 
16
- from .commands import CommandResult # type: ignore # imported only at runtime by commands.py
17
- from .config import load_runtime_config
17
+ from .atomic_io import write_json_atomic
18
+ from .checkpoint_state import load_checkpoint_state
19
+ from .config import load_env_file, load_runtime_config
18
20
  from .gitops import (
19
21
  BranchContext,
20
- WorktreePolicy,
22
+ abort_in_progress_git_operation,
21
23
  branch_create_plan,
22
24
  branch_ensure_return,
23
25
  branch_fast_forward_possible,
@@ -27,24 +29,20 @@ from .gitops import (
27
29
  default_branch,
28
30
  ensure_branch_has_commit,
29
31
  ensure_git_repository,
30
- ensure_linked_worktree,
31
32
  local_branch_exists,
32
- guarded_worktree_remove,
33
- materialize_worktree_support_assets,
34
- merge_linked_worktree,
35
33
  restore_runtime_wip,
36
34
  run_git_command,
37
35
  run_git_plan,
38
- worktree_runtime_context,
39
- worktree_save_wip,
40
36
  )
41
37
  from .processes import RuntimeInterruption, describe_interruption, shield_interruption_signals
38
+ from .results import CommandResult
42
39
  from .runner_bookkeeping import (
43
40
  commit_final_bookkeeping,
44
41
  commit_pre_branch_bookkeeping,
45
42
  commit_preflight_ready_changes,
46
43
  commit_task_branch_changes,
47
44
  commit_wip_changes,
45
+ sync_terminal_failure_bookkeeping_to_base,
48
46
  )
49
47
  from .runner_classification import classify_session, has_branch_completion_evidence, has_completed_artifact_path
50
48
  from .runner_models import (
@@ -67,7 +65,6 @@ from .runner_status import get_next, start_item, status_text, update_item
67
65
  from .sessions import AISessionConfig, AISessionLauncher, detect_stream_json_support
68
66
  from .task_checkout import (
69
67
  CHECKOUT_MODE_BRANCH,
70
- CHECKOUT_MODE_WORKTREE,
71
68
  TaskCheckout,
72
69
  complete_task_checkout_locked,
73
70
  load_task_checkout,
@@ -98,7 +95,7 @@ def _bridge_sigterm_to_interrupt() -> Iterator[None]:
98
95
 
99
96
 
100
97
  def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], paths) -> CommandResult:
101
- """Dispatch a feature/bugfix/refactor Python foreground command."""
98
+ """Dispatch a feature or bugfix Python foreground command."""
102
99
  family = family_for(kind, paths)
103
100
  invocation = parse_invocation(family, action, legacy_args)
104
101
  invocation = _resolve_invocation_paths(invocation, paths.project_root)
@@ -123,7 +120,9 @@ def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], p
123
120
  with _bridge_sigterm_to_interrupt():
124
121
  result = _run_pipeline(family, invocation, paths)
125
122
  except Exception as exc: # keep CLI boundary traceback-free
126
- return CommandResult(1, f"Python {kind} runner failed", str(exc))
123
+ detail = str(exc).strip()
124
+ message = f"{type(exc).__name__}: {detail}" if detail else type(exc).__name__
125
+ return CommandResult(1, f"Python {kind} runner failed", message)
127
126
  details = result.details + ((f"last_status: {result.last_status}",) if result.last_status else ())
128
127
  return CommandResult(
129
128
  0 if result.completed or result.last_status == "dry_run" else 1,
@@ -178,7 +177,7 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
178
177
  return PipelineRunResult(False, processed, "pipeline_blocked", details=details)
179
178
  if not isinstance(next_result.data, dict):
180
179
  return PipelineRunResult(False, processed, "invalid_get_next_output", details=(marker[:500],))
181
- item_id = str(next_result.data.get(f"{family.kind}_id") or next_result.data.get("feature_id") or next_result.data.get("bug_id") or next_result.data.get("refactor_id") or "")
180
+ item_id = str(next_result.data.get(f"{family.kind}_id") or next_result.data.get("feature_id") or next_result.data.get("bug_id") or "")
182
181
  if not item_id:
183
182
  return PipelineRunResult(False, processed, "missing_item_id", details=(marker[:500],))
184
183
  if item_id in item_statuses:
@@ -227,10 +226,8 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
227
226
  if final_status == "pending":
228
227
  continue
229
228
  details = _render_item_statuses(item_statuses)
230
- if RunnerEnvironment.from_env().stop_on_failure:
229
+ if _runner_env_for_paths(paths).stop_on_failure:
231
230
  return PipelineRunResult(False, processed, "stop_on_failure", final_status, details)
232
- if final_status in {"failed", "needs_info"}:
233
- return PipelineRunResult(False, processed, "item_failed", final_status, details)
234
231
 
235
232
 
236
233
  _COMPLETION_COMPATIBLE_STATUSES = {"completed"}
@@ -277,13 +274,25 @@ def _emit_warning(message: str) -> None:
277
274
 
278
275
 
279
276
  def _family_label(family: RunnerFamily) -> str:
280
- return {"feature": "Feature", "bugfix": "Bug", "refactor": "Refactor"}.get(family.kind, family.kind.title())
277
+ return {"feature": "Feature", "bugfix": "Bug"}.get(family.kind, family.kind.title())
281
278
 
282
279
 
283
- def _max_retries(invocation: RunnerInvocation) -> int:
280
+ def _runner_env_for_paths(paths, config=None) -> RunnerEnvironment:
281
+ env_values = getattr(config, "env_values", None) if config is not None else None
282
+ if isinstance(env_values, Mapping) and env_values:
283
+ return RunnerEnvironment.from_env(env_values)
284
+ prizmkit_dir = getattr(paths, "prizmkit_dir", None)
285
+ if prizmkit_dir is None and hasattr(paths, "project_root"):
286
+ prizmkit_dir = Path(paths.project_root) / ".prizmkit"
287
+ if prizmkit_dir is not None:
288
+ return RunnerEnvironment.from_env(load_env_file(Path(prizmkit_dir) / ".env", os.environ))
289
+ return RunnerEnvironment.from_env()
290
+
291
+
292
+ def _max_retries(invocation: RunnerInvocation, paths=None) -> int:
284
293
  if invocation.max_retries is not None:
285
294
  return max(0, invocation.max_retries)
286
- return RunnerEnvironment.from_env().max_retries
295
+ return _runner_env_for_paths(paths).max_retries if paths is not None else RunnerEnvironment.from_env().max_retries
287
296
 
288
297
 
289
298
  def _emit_item_header(family: RunnerFamily, invocation: RunnerInvocation, item_id: str, metadata: dict[str, object]) -> None:
@@ -352,12 +361,22 @@ def _latest_session_status(state_dir: Path, item_id: str) -> dict[str, object]:
352
361
 
353
362
  def _resolve_base_branch(project_root: Path, metadata: dict[str, object], active_branch: str, family: RunnerFamily, item_id: str) -> str:
354
363
  recorded = str(metadata.get("base_branch") or "").strip()
355
- if recorded and local_branch_exists(project_root, recorded):
364
+ if recorded and recorded != "HEAD" and local_branch_exists(project_root, recorded):
356
365
  return recorded
366
+ active = "" if active_branch == "HEAD" else active_branch
357
367
  detected_default = default_branch(project_root)
358
- if _is_current_task_branch(active_branch, family, item_id) or _is_recovery_side_effect_branch(active_branch, family, item_id):
359
- return detected_default
360
- return active_branch or detected_default
368
+ if detected_default == "HEAD":
369
+ detected_default = ""
370
+ if _is_current_task_branch(active, family, item_id) or _is_recovery_side_effect_branch(active, family, item_id):
371
+ resolved = detected_default
372
+ else:
373
+ resolved = active or detected_default
374
+ if not resolved or resolved == "HEAD":
375
+ raise RuntimeError(
376
+ f"Cannot resolve base branch for {family.kind} task {item_id} from detached HEAD; "
377
+ "check out a named branch before running the pipeline."
378
+ )
379
+ return resolved
361
380
 
362
381
 
363
382
  def _resolve_working_branch(family: RunnerFamily, item_id: str, metadata: dict[str, object], env: RunnerEnvironment, active_branch: str) -> str:
@@ -506,6 +525,12 @@ def _process_item(
506
525
  raise
507
526
 
508
527
 
528
+ def _validate_effort_config(config) -> None:
529
+ effort_validation = getattr(config, "effort_validation", None)
530
+ if effort_validation is not None and not effort_validation.valid:
531
+ raise RuntimeError(effort_validation.message)
532
+
533
+
509
534
  def _preview_item(
510
535
  family: RunnerFamily,
511
536
  invocation: RunnerInvocation,
@@ -517,8 +542,7 @@ def _preview_item(
517
542
  config = load_runtime_config(paths)
518
543
  if not config.ai_client.command:
519
544
  raise RuntimeError("No supported AI CLI command was found")
520
- if config.ai_client.platform in {"cursor", "antigravity"} and not config.effort_validation.valid:
521
- raise RuntimeError(config.effort_validation.message)
545
+ _validate_effort_config(config)
522
546
  metadata = _with_recovery_metadata(family, item_id, initial_metadata)
523
547
  retry_count = int(metadata.get("retry_count") or 0)
524
548
  session_id = f"{item_id}-dry-run"
@@ -554,12 +578,11 @@ def _process_item_locked(
554
578
  *,
555
579
  initial_metadata: dict[str, object],
556
580
  ) -> str:
557
- env = RunnerEnvironment.from_env()
558
581
  config = load_runtime_config(paths)
582
+ env = _runner_env_for_paths(paths, config)
559
583
  if not config.ai_client.command:
560
584
  raise RuntimeError("No supported AI CLI command was found")
561
- if config.ai_client.platform in {"cursor", "antigravity"} and not config.effort_validation.valid:
562
- raise RuntimeError(config.effort_validation.message)
585
+ _validate_effort_config(config)
563
586
 
564
587
  repository = ensure_git_repository(paths.project_root)
565
588
  if repository.return_code != 0:
@@ -577,14 +600,7 @@ def _process_item_locked(
577
600
  base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
578
601
  branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch)
579
602
  branch_context = BranchContext(base_branch, branch_name, paths.project_root)
580
- worktree_runtime = None
581
603
  reusing_checkout = checkout is not None and checkout.is_active
582
- if reusing_checkout:
583
- use_worktree = checkout.uses_worktree
584
- worktree_path = Path(checkout.worktree_path) if checkout.worktree_path else None
585
- else:
586
- use_worktree = _use_worktree_for_family(env, family)
587
- worktree_path = None
588
604
  execution_root = paths.project_root
589
605
  session_id = ""
590
606
  session_paths: SessionPaths | None = None
@@ -629,54 +645,35 @@ def _process_item_locked(
629
645
  checkout = replace_missing_recorded_base_locked(family.state_dir, checkout, base_branch)
630
646
  _emit_info(f"Checkout: recorded base {previous_base} is missing; using {base_branch}")
631
647
 
632
- if use_worktree:
633
- worktree_runtime = worktree_runtime_context(
634
- branch_context,
635
- WorktreePolicy(
636
- use_worktree=True,
637
- cleanup_on_success=True,
638
- preserve_on_failure=True,
639
- worktree_root=(worktree_path.parent if worktree_path is not None else paths.state_dir / "worktrees"),
640
- ),
641
- )
642
- if worktree_path is not None and worktree_runtime.worktree_path != worktree_path.resolve():
643
- raise RuntimeError(f"Task {item_id} worktree identity resolves to an unexpected path")
644
648
  checkout_candidate = TaskCheckout.active(
645
649
  family.task_type,
646
650
  item_id,
647
651
  branch_name,
648
652
  base_branch,
649
- checkout_mode=CHECKOUT_MODE_WORKTREE if use_worktree else CHECKOUT_MODE_BRANCH,
650
- worktree_path=str(worktree_runtime.worktree_path) if worktree_runtime is not None else "",
653
+ checkout_mode=CHECKOUT_MODE_BRANCH,
651
654
  )
652
655
  checkout = reserve_task_checkout_locked(family.state_dir, checkout_candidate)
653
656
  _emit_info(f"Checkout: reserved task identity at {family.state_dir / item_id / 'checkout.json'}")
654
657
 
655
- if use_worktree:
656
- setup = ensure_linked_worktree(worktree_runtime)
657
- if not setup.ok:
658
- return "infra_error"
659
- worktree_runtime = setup.runtime or worktree_runtime
660
- _emit_info(f"Dev branch: {branch_name}")
661
- _emit_info(f"Worktree: {worktree_runtime.worktree_path}")
662
- support_assets = materialize_worktree_support_assets(worktree_runtime)
663
- if not support_assets.ok:
664
- return _record_setup_failure(
658
+ branch_result = run_git_plan(paths.project_root, branch_create_plan(branch_context))
659
+ _emit_branch_setup_result(branch_context, branch_result)
660
+ if not branch_result.ok:
661
+ _emit_git_plan_output(branch_result)
662
+ if invocation.list_path.is_file():
663
+ update = update_item(
665
664
  family,
666
665
  invocation,
667
666
  item_id,
667
+ "infra_error",
668
+ "",
668
669
  paths.project_root,
669
- worktree_runtime.worktree_path,
670
- base_branch,
671
- branch_name,
672
- worktree_runtime=worktree_runtime,
670
+ active_dev_branch=branch_name,
671
+ base_branch=base_branch,
673
672
  )
674
- execution_root = worktree_runtime.worktree_path
675
- else:
676
- branch_result = run_git_plan(paths.project_root, branch_create_plan(branch_context))
677
- _emit_branch_setup_result(branch_context, branch_result)
678
- if not branch_result.ok:
679
- return "infra_error"
673
+ if update.ok:
674
+ commit_final_bookkeeping(paths.project_root, family, item_id, _status_from_update(update))
675
+ return _status_from_update(update)
676
+ return "infra_error"
680
677
 
681
678
  if reusing_checkout:
682
679
  restored_wip = restore_runtime_wip(
@@ -698,7 +695,6 @@ def _process_item_locked(
698
695
  execution_root,
699
696
  base_branch,
700
697
  branch_name,
701
- worktree_runtime=worktree_runtime,
702
698
  )
703
699
  if restored_wip.restored:
704
700
  _emit_info(
@@ -709,11 +705,26 @@ def _process_item_locked(
709
705
  _emit_info(f"Recovery: no Runtime-owned WIP tip to restore for {item_id}")
710
706
 
711
707
  _emit_item_header(family, invocation, item_id, metadata)
712
- status_root = execution_root if use_worktree else paths.project_root
713
- status_family = _family_for_execution_root(family, paths.project_root, status_root)
714
- status_invocation = _invocation_for_execution_family(invocation, status_family)
708
+ status_root = paths.project_root
709
+ status_family = family
710
+ status_invocation = invocation
715
711
  recovered_session_id = _latest_session_id(family.state_dir, item_id)
716
712
  recovery_artifact = _artifact_path_for_item(execution_root, family, item_id, metadata)
713
+ recovery_checkpoint = recovery_artifact / "workflow-checkpoint.json"
714
+ recovery_request = recovery_artifact / REQUEST_FILENAME
715
+ if recovery_checkpoint.is_file() and (
716
+ recovery_request.is_file()
717
+ or load_checkpoint_state(recovery_checkpoint, project_root=execution_root).semantic_commit_ready
718
+ ):
719
+ pending_commit = finalize_runtime_commit(
720
+ execution_root,
721
+ artifact_dir=recovery_artifact,
722
+ checkpoint_path=recovery_checkpoint,
723
+ )
724
+ if pending_commit.committed:
725
+ _emit_success(f"Recovery: finalized pending Runtime commit {pending_commit.commit_hash}")
726
+ elif pending_commit.status == "failed":
727
+ _emit_warning(f"Recovery: pending Runtime commit failed ({pending_commit.reason})")
717
728
  if recovered_session_id and has_completed_artifact_path(recovery_artifact) and has_branch_completion_evidence(execution_root, base_branch, branch_name, recovery_artifact):
718
729
  session_paths = SessionPaths.for_item(family.state_dir, item_id, recovered_session_id)
719
730
  _write_session_status(
@@ -724,7 +735,6 @@ def _process_item_locked(
724
735
  task_type=family.task_type,
725
736
  base_branch=base_branch,
726
737
  active_dev_branch=branch_name,
727
- worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
728
738
  reason="completed_branch_recovered_from_late_runtime_error",
729
739
  )
730
740
  return _finalize_recovered_success(
@@ -740,7 +750,6 @@ def _process_item_locked(
740
750
  base_branch,
741
751
  recovered_session_id,
742
752
  session_paths,
743
- worktree_runtime,
744
753
  )
745
754
  start = start_item(status_family, status_invocation, item_id, status_root)
746
755
  if not start.ok:
@@ -769,7 +778,7 @@ def _process_item_locked(
769
778
  "context_overflow_count": context_overflow_count,
770
779
  "retry_count": retry_count,
771
780
  "infra_error_count": infra_error_count,
772
- "max_retries": _max_retries(invocation),
781
+ "max_retries": _max_retries(invocation, paths),
773
782
  "max_infra_retries": invocation.max_infra_retries,
774
783
  "no_progress_count": previous_no_progress_count,
775
784
  "progress_fingerprint": previous_fingerprint or {},
@@ -784,7 +793,9 @@ def _process_item_locked(
784
793
  "task_type": family.task_type,
785
794
  "active_dev_branch": branch_name,
786
795
  "base_branch": base_branch,
787
- "continuation_summary_path": _continuation_summary_path(execution_root, family, item_id, None),
796
+ "continuation_summary_path": _continuation_summary_path(
797
+ execution_root, family, item_id, None, metadata=metadata
798
+ ),
788
799
  }
789
800
  prompt = generate_prompt(
790
801
  family,
@@ -850,6 +861,7 @@ def _process_item_locked(
850
861
  prompt=prompt,
851
862
  previous_fingerprint=previous_fingerprint,
852
863
  previous_no_progress_count=previous_no_progress_count,
864
+ stream_json=stream_json,
853
865
  )
854
866
  if runtime_commit.status == "failed":
855
867
  classification = SessionClassification(
@@ -875,7 +887,9 @@ def _process_item_locked(
875
887
  )
876
888
  _emit_session_summary(session_result, session_paths, classification)
877
889
  final_session_status = classification.session_status
878
- summary_path = _continuation_summary_path(execution_root, family, item_id, prompt)
890
+ summary_path = _continuation_summary_path(
891
+ execution_root, family, item_id, prompt, metadata=metadata
892
+ )
879
893
 
880
894
  _write_session_status(
881
895
  session_paths,
@@ -885,7 +899,6 @@ def _process_item_locked(
885
899
  task_type=family.task_type,
886
900
  base_branch=base_branch,
887
901
  active_dev_branch=branch_name,
888
- worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
889
902
  reason=classification.reason,
890
903
  fatal_error_code=classification.fatal_error_code,
891
904
  checkpoint_state=classification.checkpoint_state,
@@ -932,15 +945,31 @@ def _process_item_locked(
932
945
 
933
946
  accepted_with_warning = accepted_with_warning and new_status == "completed"
934
947
  if final_session_status != "success" and not accepted_with_warning:
948
+ failure_bookkeeping = _capture_terminal_failure_bookkeeping(
949
+ status_family,
950
+ status_invocation,
951
+ item_id,
952
+ new_status,
953
+ update_data,
954
+ )
935
955
  commit_final_bookkeeping(status_root, status_family, item_id, new_status)
936
- wip = _save_failure_wip(execution_root, family, item_id, new_status, worktree_runtime)
956
+ wip = _save_failure_wip(execution_root, family, item_id, new_status)
937
957
  if not getattr(wip, "ok", True):
938
958
  _emit_warning(f"WIP preservation failed for {item_id}; leaving the task checkout active")
939
959
  return new_status
940
- if not use_worktree:
941
- returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
942
- if not getattr(returned, "ok", True):
943
- _emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
960
+ returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
961
+ if not getattr(returned, "ok", True):
962
+ _emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
963
+ elif failure_bookkeeping:
964
+ synced = sync_terminal_failure_bookkeeping_to_base(
965
+ status_root,
966
+ status_family,
967
+ item_id,
968
+ new_status,
969
+ failure_bookkeeping,
970
+ )
971
+ if synced.attempted and not synced.ok:
972
+ _emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
944
973
  return new_status
945
974
 
946
975
  completed_status = _complete_success_merge(
@@ -957,7 +986,6 @@ def _process_item_locked(
957
986
  base_branch,
958
987
  session_id,
959
988
  session_paths,
960
- worktree_runtime,
961
989
  classification_fatal_error_code=classification.fatal_error_code,
962
990
  )
963
991
  if accepted_with_warning and completed_status == "completed":
@@ -969,25 +997,26 @@ def _process_item_locked(
969
997
  )
970
998
  return completed_status
971
999
  except KeyboardInterrupt as interruption:
972
- try:
973
- _emit_task_interruption_diagnostics(
974
- interruption,
975
- family=family,
976
- invocation=invocation,
977
- item_id=item_id,
978
- session_id=session_id,
979
- session_paths=session_paths,
980
- retry_count=retry_count,
981
- infra_error_count=infra_error_count,
982
- branch_name=branch_name,
983
- base_branch=base_branch,
984
- )
985
- except Exception as diagnostic_error:
986
- _emit_warning(
987
- f"Interrupt diagnostic collection failed ({type(diagnostic_error).__name__}); "
988
- "continuing existing WIP preservation and checkout recovery behavior"
989
- )
990
1000
  with shield_interruption_signals():
1001
+ try:
1002
+ _emit_task_interruption_diagnostics(
1003
+ interruption,
1004
+ family=family,
1005
+ invocation=invocation,
1006
+ item_id=item_id,
1007
+ session_id=session_id,
1008
+ session_paths=session_paths,
1009
+ retry_count=retry_count,
1010
+ infra_error_count=infra_error_count,
1011
+ branch_name=branch_name,
1012
+ base_branch=base_branch,
1013
+ paths=paths,
1014
+ )
1015
+ except Exception as diagnostic_error:
1016
+ _emit_warning(
1017
+ f"Interrupt diagnostic collection failed ({type(diagnostic_error).__name__}); "
1018
+ "continuing existing WIP preservation and checkout recovery behavior"
1019
+ )
991
1020
  _cleanup_interrupted_task(
992
1021
  item_id=item_id,
993
1022
  paths=paths,
@@ -995,7 +1024,7 @@ def _process_item_locked(
995
1024
  base_branch=base_branch,
996
1025
  branch_name=branch_name,
997
1026
  )
998
- raise
1027
+ raise
999
1028
 
1000
1029
 
1001
1030
  def _emit_task_interruption_diagnostics(
@@ -1010,6 +1039,7 @@ def _emit_task_interruption_diagnostics(
1010
1039
  infra_error_count: int | None,
1011
1040
  branch_name: str,
1012
1041
  base_branch: str,
1042
+ paths=None,
1013
1043
  ) -> None:
1014
1044
  """Emit task-level interruption context without mutating pipeline state."""
1015
1045
  details = describe_interruption(interruption)
@@ -1031,7 +1061,7 @@ def _emit_task_interruption_diagnostics(
1031
1061
  f"phase={phase}; tool={tool}; branch={branch_name}; base={base_branch}"
1032
1062
  )
1033
1063
  _emit_warning(
1034
- f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation)}; "
1064
+ f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation, paths)}; "
1035
1065
  f"infrastructure={infra_retry}/{invocation.max_infra_retries}"
1036
1066
  )
1037
1067
  _emit_warning(
@@ -1050,6 +1080,7 @@ def _cleanup_interrupted_task(
1050
1080
  ) -> None:
1051
1081
  """Commit interrupted task WIP, then leave the caller checkout on its base branch."""
1052
1082
  _emit_warning(f"Interrupted while processing {item_id}; preserving task WIP before base return")
1083
+ abort_in_progress_git_operation(execution_root)
1053
1084
  execution_branch = current_branch(execution_root)
1054
1085
  if execution_root.resolve() == paths.project_root.resolve() and execution_branch == base_branch:
1055
1086
  preserved = None
@@ -1192,7 +1223,6 @@ def _finalize_recovered_success(
1192
1223
  base_branch: str,
1193
1224
  session_id: str,
1194
1225
  session_paths: SessionPaths,
1195
- worktree_runtime,
1196
1226
  ) -> str:
1197
1227
  update = update_item(
1198
1228
  status_family,
@@ -1221,11 +1251,63 @@ def _finalize_recovered_success(
1221
1251
  base_branch,
1222
1252
  session_id,
1223
1253
  session_paths,
1224
- worktree_runtime,
1225
1254
  classification_fatal_error_code="",
1226
1255
  )
1227
1256
 
1228
1257
 
1258
+ def _patch_completion_notes_if_present(
1259
+ execution_root: Path,
1260
+ paths,
1261
+ status_root: Path,
1262
+ status_family: RunnerFamily,
1263
+ status_invocation: RunnerInvocation,
1264
+ item_id: str,
1265
+ ) -> None:
1266
+ summary_file = _artifact_path_for_item(execution_root, status_family, item_id, {}) / "completion-summary.json"
1267
+ pipeline_root = getattr(paths, "pipeline_root", None)
1268
+ if pipeline_root is None or not summary_file.is_file() or not status_invocation.list_path.is_file():
1269
+ return
1270
+ patch_script = Path(pipeline_root) / "scripts" / "patch-completion-notes.py"
1271
+ if not patch_script.is_file():
1272
+ return
1273
+ completed = subprocess.run(
1274
+ [
1275
+ sys.executable,
1276
+ str(patch_script),
1277
+ status_family.list_arg,
1278
+ str(status_invocation.list_path),
1279
+ status_family.item_id_arg,
1280
+ item_id,
1281
+ "--summary",
1282
+ str(summary_file),
1283
+ ],
1284
+ cwd=str(status_root),
1285
+ stdout=subprocess.PIPE,
1286
+ stderr=subprocess.PIPE,
1287
+ text=True,
1288
+ encoding="utf-8",
1289
+ errors="replace",
1290
+ check=False,
1291
+ )
1292
+ if completed.returncode != 0:
1293
+ detail = (completed.stderr or completed.stdout).strip()
1294
+ _emit_warning(
1295
+ f"Could not patch completion_notes for {item_id} (exit={completed.returncode})"
1296
+ + (f": {detail.splitlines()[0][:240]}" if detail else "")
1297
+ )
1298
+ return
1299
+ notes_count = None
1300
+ if (completed.stdout or "").strip():
1301
+ try:
1302
+ notes_count = json.loads(completed.stdout).get("notes_count")
1303
+ except (ValueError, json.JSONDecodeError, AttributeError):
1304
+ notes_count = None
1305
+ if notes_count:
1306
+ _emit_info(f"Patched {notes_count} completion note(s) for {item_id}")
1307
+ else:
1308
+ _emit_info(f"Checked completion-summary.json for {item_id}; no non-empty completion notes patched")
1309
+
1310
+
1229
1311
  def _complete_success_merge(
1230
1312
  family: RunnerFamily,
1231
1313
  item_id: str,
@@ -1240,11 +1322,19 @@ def _complete_success_merge(
1240
1322
  base_branch: str,
1241
1323
  session_id: str,
1242
1324
  session_paths: SessionPaths,
1243
- worktree_runtime,
1244
1325
  *,
1245
1326
  classification_fatal_error_code: str = "",
1246
1327
  ) -> str:
1247
- env = RunnerEnvironment.from_env()
1328
+ env = _runner_env_for_paths(paths)
1329
+ if new_status == "completed":
1330
+ _patch_completion_notes_if_present(
1331
+ execution_root,
1332
+ paths,
1333
+ status_root,
1334
+ status_family,
1335
+ status_invocation,
1336
+ item_id,
1337
+ )
1248
1338
  final_bookkeeping = commit_final_bookkeeping(status_root, status_family, item_id, new_status)
1249
1339
  task_commit = commit_task_branch_changes(execution_root, family, item_id, new_status)
1250
1340
  finalization_committed = getattr(final_bookkeeping, "ok", True) and getattr(task_commit, "ok", True)
@@ -1258,7 +1348,6 @@ def _complete_success_merge(
1258
1348
  task_type=family.task_type,
1259
1349
  base_branch=base_branch,
1260
1350
  active_dev_branch=branch_name,
1261
- worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
1262
1351
  reason="commit_missing",
1263
1352
  fatal_error_code=classification_fatal_error_code,
1264
1353
  )
@@ -1278,41 +1367,34 @@ def _complete_success_merge(
1278
1367
  _emit_update_summary(family, item_id, update)
1279
1368
  commit_missing_status = _status_from_update(update)
1280
1369
  commit_final_bookkeeping(status_root, status_family, item_id, commit_missing_status)
1281
- _save_failure_wip(execution_root, family, item_id, commit_missing_status, worktree_runtime)
1370
+ _save_failure_wip(execution_root, family, item_id, commit_missing_status)
1282
1371
  return commit_missing_status
1283
- if worktree_runtime is not None:
1284
- _emit_info(f"Merging {branch_name} into {base_branch}...")
1285
- merge = merge_linked_worktree(worktree_runtime, auto_push=env.auto_push)
1286
- _emit_git_plan_output(merge)
1287
- if merge.ok:
1288
- checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
1289
- if checkout is None:
1290
- raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
1291
- complete_task_checkout_locked(family.state_dir, checkout)
1292
- guarded_worktree_remove(worktree_runtime, delete_branch=True)
1293
- _emit_success(f"Merged {branch_name} into {base_branch}")
1294
- return new_status
1295
- else:
1296
- _emit_info(f"Merging {branch_name} into {base_branch}...")
1297
- merge = run_git_plan(
1298
- paths.project_root,
1299
- branch_merge_plan(
1372
+
1373
+ _emit_info(f"Merging {branch_name} into {base_branch}...")
1374
+ merge = run_git_plan(
1375
+ paths.project_root,
1376
+ branch_merge_plan(
1377
+ branch_context,
1378
+ auto_push=env.auto_push,
1379
+ rebase=not branch_fast_forward_possible(
1380
+ paths.project_root,
1300
1381
  branch_context,
1301
- auto_push=env.auto_push,
1302
- rebase=not branch_fast_forward_possible(
1303
- paths.project_root,
1304
- branch_context,
1305
- ),
1306
1382
  ),
1307
- )
1308
- _emit_git_plan_output(merge)
1309
- if merge.ok:
1310
- checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
1311
- if checkout is None:
1312
- raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
1313
- complete_task_checkout_locked(family.state_dir, checkout)
1314
- _emit_success(f"Merged {branch_name} into {base_branch}")
1315
- return new_status
1383
+ ),
1384
+ )
1385
+ _emit_git_plan_output(merge)
1386
+ if merge.ok:
1387
+ checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
1388
+ if checkout is None:
1389
+ raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
1390
+ complete_task_checkout_locked(family.state_dir, checkout)
1391
+ _emit_success(f"Merged {branch_name} into {base_branch}")
1392
+ return new_status
1393
+ _emit_warning(
1394
+ f"Merge failed for {item_id} ({branch_name} -> {base_branch}); "
1395
+ "aborted in-progress git operation and recorded merge_conflict"
1396
+ )
1397
+ abort_in_progress_git_operation(paths.project_root)
1316
1398
 
1317
1399
  _write_session_status(
1318
1400
  session_paths,
@@ -1322,7 +1404,6 @@ def _complete_success_merge(
1322
1404
  task_type=family.task_type,
1323
1405
  base_branch=base_branch,
1324
1406
  active_dev_branch=branch_name,
1325
- worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
1326
1407
  reason="merge_conflict",
1327
1408
  fatal_error_code=classification_fatal_error_code,
1328
1409
  )
@@ -1342,21 +1423,53 @@ def _complete_success_merge(
1342
1423
  _emit_update_summary(family, item_id, update)
1343
1424
  merged_status = _status_from_update(update)
1344
1425
  commit_final_bookkeeping(status_root, status_family, item_id, merged_status)
1345
- wip = _save_failure_wip(execution_root, family, item_id, merged_status, worktree_runtime)
1346
- if worktree_runtime is None and getattr(wip, "ok", True):
1426
+ wip = _save_failure_wip(execution_root, family, item_id, merged_status)
1427
+ if getattr(wip, "ok", True):
1347
1428
  returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
1348
1429
  if not returned.ok:
1349
1430
  _emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
1350
1431
  return merged_status
1351
1432
 
1352
1433
 
1353
- def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str, worktree_runtime):
1434
+ def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str):
1354
1435
  """Preserve failure work and return an observable bookkeeping result."""
1355
- if worktree_runtime is not None:
1356
- return worktree_save_wip(worktree_runtime)
1357
1436
  return commit_wip_changes(execution_root, family, item_id, status)
1358
1437
 
1359
1438
 
1439
+ def _capture_terminal_failure_bookkeeping(
1440
+ family: RunnerFamily,
1441
+ invocation: RunnerInvocation,
1442
+ item_id: str,
1443
+ new_status: str,
1444
+ update_data: Mapping[str, object],
1445
+ ) -> dict[Path, str]:
1446
+ """Snapshot terminal failure status files before branch return reverts the checkout."""
1447
+ if new_status not in {"failed", "skipped", "auto_skipped"}:
1448
+ return {}
1449
+ candidates: list[Path] = [
1450
+ invocation.list_path,
1451
+ family.state_dir / item_id / "status.json",
1452
+ ]
1453
+ for key in ("auto_skipped_features", "auto_skipped_bugs"):
1454
+ entries = update_data.get(key)
1455
+ if not isinstance(entries, list):
1456
+ continue
1457
+ for entry in entries:
1458
+ if not isinstance(entry, Mapping):
1459
+ continue
1460
+ dep_id = str(entry.get("feature_id") or entry.get("bug_id") or "").strip()
1461
+ if dep_id:
1462
+ candidates.append(family.state_dir / dep_id / "status.json")
1463
+ snapshots: dict[Path, str] = {}
1464
+ for candidate in candidates:
1465
+ try:
1466
+ if candidate.is_file():
1467
+ snapshots[candidate] = candidate.read_text(encoding="utf-8")
1468
+ except OSError:
1469
+ continue
1470
+ return snapshots
1471
+
1472
+
1360
1473
  def _record_setup_failure(
1361
1474
  family: RunnerFamily,
1362
1475
  invocation: RunnerInvocation,
@@ -1365,14 +1478,12 @@ def _record_setup_failure(
1365
1478
  status_root: Path,
1366
1479
  base_branch: str,
1367
1480
  branch_name: str,
1368
- *,
1369
- worktree_runtime=None,
1370
1481
  ) -> str:
1371
1482
  """Record setup-time infra failures on a task branch when one exists."""
1372
1483
  if status_root.resolve() == project_root.resolve() and current_branch(project_root) != branch_name:
1373
1484
  return "infra_error"
1374
- status_family = _family_for_execution_root(family, project_root, status_root)
1375
- status_invocation = _invocation_for_execution_family(invocation, status_family)
1485
+ status_family = family
1486
+ status_invocation = invocation
1376
1487
  start = start_item(status_family, status_invocation, item_id, status_root)
1377
1488
  if start.ok:
1378
1489
  commit_pre_branch_bookkeeping(status_root, status_family, item_id)
@@ -1389,64 +1500,16 @@ def _record_setup_failure(
1389
1500
  new_status = _status_from_update(update) if update.ok else "infra_error"
1390
1501
  if update.ok:
1391
1502
  commit_final_bookkeeping(status_root, status_family, item_id, new_status)
1392
- wip = _save_failure_wip(status_root, family, item_id, new_status, worktree_runtime)
1503
+ wip = _save_failure_wip(status_root, family, item_id, new_status)
1393
1504
  else:
1394
1505
  wip = None
1395
1506
  if (
1396
- worktree_runtime is None
1397
- and current_branch(project_root) == branch_name
1507
+ current_branch(project_root) == branch_name
1398
1508
  and getattr(wip, "ok", True)
1399
1509
  ):
1400
1510
  branch_ensure_return(project_root, base_branch, branch_name)
1401
1511
  return new_status
1402
1512
 
1403
- def _use_worktree_for_family(env: RunnerEnvironment, family: RunnerFamily) -> bool:
1404
- return env.use_worktree and family.kind in {"feature", "bugfix"}
1405
-
1406
-
1407
- def _family_for_execution_root(family: RunnerFamily, project_root: Path, execution_root: Path) -> RunnerFamily:
1408
- """Return family paths rooted in the task execution checkout."""
1409
- if execution_root.resolve() == project_root.resolve():
1410
- return family
1411
- return RunnerFamily(
1412
- kind=family.kind,
1413
- id_prefix=family.id_prefix,
1414
- list_key=family.list_key,
1415
- list_arg=family.list_arg,
1416
- item_id_arg=family.item_id_arg,
1417
- state_dir=_path_in_execution_root(family.state_dir, project_root, execution_root),
1418
- plan_path=_path_in_execution_root(family.plan_path, project_root, execution_root),
1419
- updater_script=family.updater_script,
1420
- prompt_script=family.prompt_script,
1421
- branch_prefix=family.branch_prefix,
1422
- artifact_root_name=family.artifact_root_name,
1423
- )
1424
-
1425
-
1426
- def _invocation_for_execution_family(invocation: RunnerInvocation, family: RunnerFamily) -> RunnerInvocation:
1427
- return RunnerInvocation(
1428
- action=invocation.action,
1429
- list_path=family.plan_path,
1430
- item_id=invocation.item_id,
1431
- item_filter=invocation.item_filter,
1432
- max_retries=invocation.max_retries,
1433
- max_infra_retries=invocation.max_infra_retries,
1434
- dry_run=invocation.dry_run,
1435
- clean=invocation.clean,
1436
- no_reset=invocation.no_reset,
1437
- resume_phase=invocation.resume_phase,
1438
- help_requested=invocation.help_requested,
1439
- unknown_args=invocation.unknown_args,
1440
- raw_args=invocation.raw_args,
1441
- )
1442
-
1443
-
1444
- def _path_in_execution_root(path: Path, project_root: Path, execution_root: Path) -> Path:
1445
- try:
1446
- return execution_root / path.resolve().relative_to(project_root.resolve())
1447
- except ValueError:
1448
- return path
1449
-
1450
1513
 
1451
1514
  def _latest_session_id(state_dir: Path, item_id: str) -> str:
1452
1515
  sessions_dir = state_dir / item_id / "sessions"
@@ -1494,7 +1557,6 @@ def _write_session_status(
1494
1557
  task_type: str,
1495
1558
  base_branch: str,
1496
1559
  active_dev_branch: str,
1497
- worktree_path: Path | None = None,
1498
1560
  reason: str = "",
1499
1561
  fatal_error_code: str = "",
1500
1562
  checkpoint_state: object | None = None,
@@ -1507,19 +1569,13 @@ def _write_session_status(
1507
1569
  "base_branch": base_branch,
1508
1570
  "active_dev_branch": active_dev_branch,
1509
1571
  }
1510
- if worktree_path is not None:
1511
- payload["worktree_path"] = str(worktree_path)
1512
1572
  if reason:
1513
1573
  payload["reason"] = reason
1514
1574
  if fatal_error_code:
1515
1575
  payload["fatal_error_code"] = fatal_error_code
1516
1576
  if isinstance(checkpoint_state, dict):
1517
1577
  payload["checkpoint_state"] = checkpoint_state
1518
- session_paths.session_status_json.parent.mkdir(parents=True, exist_ok=True)
1519
- session_paths.session_status_json.write_text(
1520
- json.dumps(payload, indent=2, sort_keys=True) + "\n",
1521
- encoding="utf-8",
1522
- )
1578
+ write_json_atomic(session_paths.session_status_json, payload, sort_keys=True)
1523
1579
 
1524
1580
  def _status_from_update(update_result) -> str:
1525
1581
  if isinstance(update_result.data, dict):
@@ -1535,12 +1591,17 @@ def _session_id(item_id: str) -> str:
1535
1591
  return f"{item_id}-{time.strftime('%Y%m%d%H%M%S')}-{time.time_ns()}"
1536
1592
 
1537
1593
 
1538
- def _continuation_summary_path(project_root: Path, family: RunnerFamily, item_id: str, prompt: PromptGenerationResult | None) -> Path:
1594
+ def _continuation_summary_path(
1595
+ project_root: Path,
1596
+ family: RunnerFamily,
1597
+ item_id: str,
1598
+ prompt: PromptGenerationResult | None,
1599
+ *,
1600
+ metadata: dict[str, object] | None = None,
1601
+ ) -> Path:
1539
1602
  if prompt and prompt.artifact_path:
1540
1603
  return prompt.artifact_path / "continuation-summary.md"
1541
- if family.kind == "feature":
1542
- return project_root / ".prizmkit" / "specs" / item_id / "continuation-summary.md"
1543
- return project_root / ".prizmkit" / family.artifact_root_name / item_id / "continuation-summary.md"
1604
+ return _artifact_path_for_item(project_root, family, item_id, dict(metadata or {})) / "continuation-summary.md"
1544
1605
 
1545
1606
 
1546
1607
  def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path) -> RunnerInvocation:
@@ -1554,8 +1615,6 @@ def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path)
1554
1615
  max_retries=invocation.max_retries,
1555
1616
  max_infra_retries=invocation.max_infra_retries,
1556
1617
  dry_run=invocation.dry_run,
1557
- clean=invocation.clean,
1558
- no_reset=invocation.no_reset,
1559
1618
  resume_phase=invocation.resume_phase,
1560
1619
  help_requested=invocation.help_requested,
1561
1620
  unknown_args=invocation.unknown_args,