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
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import importlib.util
6
5
  import json
7
6
  import os
8
7
  import queue
@@ -17,6 +16,7 @@ from collections.abc import Callable, Mapping, Sequence
17
16
  from dataclasses import dataclass, field
18
17
  from pathlib import Path
19
18
 
19
+ from .atomic_io import write_json_atomic
20
20
  from .checkpoint_state import load_checkpoint_state
21
21
  from .heartbeat import HeartbeatConfig, HeartbeatMonitor, HeartbeatState, observe_heartbeat_state, write_stale_marker
22
22
  from .launch_profiles import HeadlessLaunchProfile
@@ -30,6 +30,7 @@ from .processes import (
30
30
  terminate_process_tree,
31
31
  )
32
32
  from .status import ProgressSummary
33
+ from .stream_progress import ProgressTracker, SemanticLogNormalizer
33
34
 
34
35
 
35
36
  @dataclass(frozen=True)
@@ -67,6 +68,7 @@ class AISessionConfig:
67
68
  heartbeat_stale_threshold_seconds: float = 0
68
69
  stale_kill_grace_seconds: float = 10
69
70
  live_progress_interval_seconds: float = 30
71
+ heartbeat_interval_seconds: float = 1.0
70
72
  live_banner: bool = True
71
73
  suppress_stream_output: bool = False
72
74
  codex_subagent_timeout_seconds: int = 3300
@@ -139,6 +141,8 @@ def _default_help_runner(command: Sequence[str]) -> str:
139
141
  stdout=subprocess.PIPE,
140
142
  stderr=subprocess.STDOUT,
141
143
  text=True,
144
+ encoding="utf-8",
145
+ errors="replace",
142
146
  check=False,
143
147
  timeout=10,
144
148
  )
@@ -155,6 +159,8 @@ def _default_cursor_probe_runner(command: Sequence[str]) -> str:
155
159
  stdout=subprocess.PIPE,
156
160
  stderr=subprocess.STDOUT,
157
161
  text=True,
162
+ encoding="utf-8",
163
+ errors="replace",
158
164
  check=False,
159
165
  timeout=10,
160
166
  )
@@ -320,14 +326,15 @@ def build_ai_session_command(config: AISessionConfig) -> AISessionCommand:
320
326
  return AISessionCommand(tuple(argv), prompt, "cursor", "stdin", prompt)
321
327
 
322
328
  if platform == "claude":
323
- argv = [
324
- config.cli_command,
325
- "-p",
326
- prompt,
329
+ use_stdin = os.name == "nt"
330
+ argv = [config.cli_command, "-p"]
331
+ if not use_stdin:
332
+ argv.append(prompt)
333
+ argv.extend([
327
334
  "--dangerously-skip-permissions",
328
335
  "--disallowedTools",
329
336
  "EnterWorktree",
330
- ]
337
+ ])
331
338
  if config.verbose or config.use_stream_json:
332
339
  argv.append("--verbose")
333
340
  if config.use_stream_json:
@@ -337,7 +344,13 @@ def build_ai_session_command(config: AISessionConfig) -> AISessionCommand:
337
344
  if config.model:
338
345
  argv.extend(["--model", config.model])
339
346
  argv.extend(config.extra_args)
340
- return AISessionCommand(tuple(argv), None, "claude", "argument", prompt)
347
+ return AISessionCommand(
348
+ tuple(argv),
349
+ prompt if use_stdin else None,
350
+ "claude",
351
+ "stdin" if use_stdin else "argument",
352
+ prompt,
353
+ )
341
354
 
342
355
  if platform == "codex":
343
356
  argv = [
@@ -424,8 +437,11 @@ def recover_session_log(session_log: Path, backup_log: Path, min_size: int = 102
424
437
  recovered = True
425
438
  cleaned = False
426
439
  if backup_log.exists():
427
- backup_log.unlink()
428
- cleaned = True
440
+ try:
441
+ backup_log.unlink()
442
+ cleaned = True
443
+ except OSError:
444
+ cleaned = False
429
445
  return LogRecoveryResult(
430
446
  recovered=recovered,
431
447
  cleaned_backup=cleaned,
@@ -679,22 +695,7 @@ class _FallbackProgressTracker:
679
695
 
680
696
 
681
697
  def _load_stream_parser_classes() -> tuple[type | None, type | None]:
682
- parser_path = Path(__file__).resolve().parents[1] / "scripts" / "parse-stream-progress.py"
683
- spec = importlib.util.spec_from_file_location("prizmkit_parse_stream_progress", parser_path)
684
- if spec is None or spec.loader is None:
685
- return None, None
686
- module = importlib.util.module_from_spec(spec)
687
- spec.loader.exec_module(module)
688
- return (
689
- getattr(module, "ProgressTracker", None),
690
- getattr(module, "SemanticLogNormalizer", None),
691
- )
692
-
693
-
694
- def _load_progress_tracker_class():
695
- """Backward-compatible access to the shared aggregate tracker class."""
696
- tracker_class, _ = _load_stream_parser_classes()
697
- return tracker_class
698
+ return ProgressTracker, SemanticLogNormalizer
698
699
 
699
700
 
700
701
  def _fallback_semantic_output(line: str, event: object | None) -> str:
@@ -710,13 +711,6 @@ def _fallback_semantic_output(line: str, event: object | None) -> str:
710
711
  return f"[OUTPUT] event={event_type}\n"
711
712
 
712
713
 
713
- def _write_progress_summary(progress_path: Path | None, summary: ProgressSummary) -> None:
714
- if progress_path is None:
715
- return
716
- progress_path.parent.mkdir(parents=True, exist_ok=True)
717
- progress_path.write_text(json.dumps(summary.to_dict(), indent=2, sort_keys=True) + "\n", encoding="utf-8")
718
-
719
-
720
714
  def _progress_refresh_key(data: Mapping[str, object]) -> tuple[object, ...]:
721
715
  event_counts = data.get("event_type_counts")
722
716
  return (
@@ -735,8 +729,7 @@ def _progress_refresh_key(data: Mapping[str, object]) -> tuple[object, ...]:
735
729
 
736
730
 
737
731
  def _write_progress_data(progress_path: Path, data: Mapping[str, object]) -> None:
738
- progress_path.parent.mkdir(parents=True, exist_ok=True)
739
- progress_path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
732
+ write_json_atomic(progress_path, dict(data), indent=2, sort_keys=True, ensure_ascii=True, fsync=False)
740
733
 
741
734
 
742
735
  def _start_idle_progress_refresh(
@@ -751,8 +744,13 @@ def _start_idle_progress_refresh(
751
744
 
752
745
  def maybe_write(force: bool = False) -> None:
753
746
  nonlocal last_key
754
- with tracker_lock:
755
- data = tracker.to_dict()
747
+ if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
748
+ tracker.refresh_child_session_activity(lock=tracker_lock)
749
+ with tracker_lock:
750
+ data = tracker.to_dict(refresh_child_activity=False)
751
+ else:
752
+ with tracker_lock:
753
+ data = tracker.to_dict()
756
754
  key = _progress_refresh_key(data)
757
755
  if force or key != last_key:
758
756
  _write_progress_data(progress_path, data)
@@ -1151,6 +1149,18 @@ def _reader_thread(
1151
1149
  backup_fh.flush()
1152
1150
  if live_output:
1153
1151
  _emit_live_output(rendered)
1152
+ if (
1153
+ refresh_progress is not None
1154
+ and isinstance(event, dict)
1155
+ and (
1156
+ event.get("type") in {"result", "turn.completed", "turn.failed", "agent_end"}
1157
+ or event.get("event") == "result"
1158
+ )
1159
+ ):
1160
+ try:
1161
+ refresh_progress(True)
1162
+ except Exception:
1163
+ pass
1154
1164
  if normalizer is not None:
1155
1165
  trailing = normalizer.finish()
1156
1166
  if trailing:
@@ -1160,8 +1170,13 @@ def _reader_thread(
1160
1170
  backup_fh.flush()
1161
1171
  if live_output:
1162
1172
  _emit_live_output(trailing)
1163
- with tracker_lock:
1164
- final_data = tracker.to_dict()
1173
+ if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
1174
+ tracker.refresh_child_session_activity(lock=tracker_lock)
1175
+ with tracker_lock:
1176
+ final_data = tracker.to_dict(refresh_child_activity=False)
1177
+ else:
1178
+ with tracker_lock:
1179
+ final_data = tracker.to_dict()
1165
1180
  finally:
1166
1181
  if refresh_progress is not None:
1167
1182
  try:
@@ -1174,7 +1189,10 @@ def _reader_thread(
1174
1189
  if not final_data:
1175
1190
  try:
1176
1191
  with tracker_lock:
1177
- final_data = tracker.to_dict()
1192
+ if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
1193
+ final_data = tracker.to_dict(refresh_child_activity=False)
1194
+ else:
1195
+ final_data = tracker.to_dict()
1178
1196
  except Exception:
1179
1197
  final_data = {}
1180
1198
  try:
@@ -1255,52 +1273,16 @@ class AISessionLauncher:
1255
1273
  if self.config.live_output and self.config.live_banner:
1256
1274
  _emit_session_start(self.config, command, session_log, backup_log)
1257
1275
 
1258
- handle = launch_process(spec, stderr=subprocess.STDOUT)
1259
- assert handle.popen is not None
1260
- reader_result_queue: queue.Queue[dict[str, object]] = queue.Queue(maxsize=1)
1261
- reader = threading.Thread(
1262
- target=_reader_thread,
1263
- args=(
1264
- handle.popen.stdout,
1265
- session_log,
1266
- backup_log,
1267
- reader_result_queue,
1268
- self.config.progress_path,
1269
- self.config.live_output and self.config.verbose and not self.config.suppress_stream_output,
1270
- self.config.platform,
1271
- ),
1272
- daemon=True,
1273
- )
1274
- reader.start()
1275
- if handle.popen.stdin is not None:
1276
- if command.stdin_text is not None:
1277
- handle.popen.stdin.write(command.stdin_text)
1278
- handle.popen.stdin.close()
1279
-
1280
- heartbeat = None
1281
1276
  live_progress_interval = max(1.0, float(self.config.live_progress_interval_seconds or 30))
1282
1277
  kill_threshold_seconds = max(0.0, float(self.config.stale_kill_threshold_seconds or 0))
1283
1278
  stale_threshold_seconds = max(0.0, float(self.config.heartbeat_stale_threshold_seconds or 0))
1284
1279
  if stale_threshold_seconds <= 0:
1285
1280
  stale_threshold_seconds = kill_threshold_seconds
1286
- heartbeat_path = self.config.heartbeat_path
1287
- if heartbeat_path is None and kill_threshold_seconds > 0:
1288
- heartbeat_path = session_log.with_name("heartbeat.json")
1289
- if heartbeat_path is not None:
1290
- heartbeat = HeartbeatMonitor(
1291
- handle,
1292
- HeartbeatConfig(
1293
- heartbeat_file=heartbeat_path,
1294
- session_log=session_log,
1295
- progress_file=self.config.progress_path,
1296
- marker_dir=session_log.parent,
1297
- interval_seconds=0.1,
1298
- stale_after_seconds=stale_threshold_seconds,
1299
- kill_after_seconds=kill_threshold_seconds,
1300
- grace_seconds=self.config.stale_kill_grace_seconds,
1301
- ),
1302
- )
1303
- heartbeat.start()
1281
+ heartbeat_interval = (
1282
+ min(1.0, max(0.05, kill_threshold_seconds / 4.0))
1283
+ if 0 < kill_threshold_seconds < 4.0
1284
+ else min(5.0, max(0.5, float(self.config.heartbeat_interval_seconds or 1.0)))
1285
+ )
1304
1286
 
1305
1287
  started = time.time()
1306
1288
  timed_out = False
@@ -1309,7 +1291,56 @@ class AISessionLauncher:
1309
1291
  last_progress_line = ""
1310
1292
  last_progress_emit = 0.0
1311
1293
  display_heartbeat_state = None
1294
+ handle: ProcessHandle | None = None
1295
+ reader: threading.Thread | None = None
1296
+ heartbeat: HeartbeatMonitor | None = None
1297
+ interrupted = False
1298
+ reader_result_queue: queue.Queue[dict[str, object]] = queue.Queue(maxsize=1)
1299
+
1312
1300
  try:
1301
+ handle = launch_process(spec, stderr=subprocess.STDOUT)
1302
+ assert handle.popen is not None
1303
+ reader = threading.Thread(
1304
+ target=_reader_thread,
1305
+ args=(
1306
+ handle.popen.stdout,
1307
+ session_log,
1308
+ backup_log,
1309
+ reader_result_queue,
1310
+ self.config.progress_path,
1311
+ self.config.live_output and self.config.verbose and not self.config.suppress_stream_output,
1312
+ self.config.platform,
1313
+ ),
1314
+ daemon=True,
1315
+ )
1316
+ reader.start()
1317
+ if handle.popen.stdin is not None:
1318
+ try:
1319
+ if command.stdin_text is not None:
1320
+ handle.popen.stdin.write(command.stdin_text)
1321
+ handle.popen.stdin.close()
1322
+ except (BrokenPipeError, OSError):
1323
+ pass
1324
+
1325
+ heartbeat_path = self.config.heartbeat_path
1326
+ if heartbeat_path is None and kill_threshold_seconds > 0:
1327
+ heartbeat_path = session_log.with_name("heartbeat.json")
1328
+ if heartbeat_path is not None:
1329
+ heartbeat = HeartbeatMonitor(
1330
+ handle,
1331
+ HeartbeatConfig(
1332
+ heartbeat_file=heartbeat_path,
1333
+ session_log=session_log,
1334
+ progress_file=self.config.progress_path,
1335
+ marker_dir=session_log.parent,
1336
+ interval_seconds=heartbeat_interval,
1337
+ stale_after_seconds=stale_threshold_seconds,
1338
+ kill_after_seconds=kill_threshold_seconds,
1339
+ grace_seconds=self.config.stale_kill_grace_seconds,
1340
+ ),
1341
+ )
1342
+ heartbeat.start()
1343
+
1313
1344
  while True:
1314
1345
  timeout = 0.2
1315
1346
  if self.config.total_timeout_seconds is not None:
@@ -1339,59 +1370,81 @@ class AISessionLauncher:
1339
1370
  stale_threshold_seconds=stale_threshold_seconds,
1340
1371
  )
1341
1372
  last_progress_emit = now
1342
- except KeyboardInterrupt as interruption:
1343
- monitor_state = heartbeat.state if heartbeat is not None else display_heartbeat_state
1344
- try:
1345
- _emit_ai_interruption_received(
1346
- interruption,
1347
- command=command,
1348
- handle=handle,
1349
- started_epoch=started,
1350
- session_log=session_log,
1351
- progress_path=self.config.progress_path,
1352
- checkpoint_path=self.config.checkpoint_path,
1353
- heartbeat_state=monitor_state,
1354
- )
1355
- except Exception as diagnostic_error:
1356
- _emit_interrupt_line(
1357
- f"diagnostic collection failed error={type(diagnostic_error).__name__}; "
1358
- "continuing existing process-tree cleanup"
1359
- )
1360
- with shield_interruption_signals():
1361
- termination = terminate_process_tree(
1362
- handle,
1363
- "interrupted",
1364
- grace_seconds=self.config.stale_kill_grace_seconds,
1365
- )
1366
- _emit_ai_interruption_termination(termination)
1367
- raise
1368
- if self.config.live_output and (not self.config.verbose or self.config.suppress_stream_output):
1369
- final_heartbeat_state = _display_heartbeat_state(
1370
- session_log,
1371
- self.config.progress_path,
1372
- heartbeat.state if heartbeat is not None else None,
1373
- display_heartbeat_state,
1374
- interval_seconds=live_progress_interval,
1375
- stale_threshold_seconds=stale_threshold_seconds,
1376
- )
1377
- display_heartbeat_state = final_heartbeat_state
1378
- if final_heartbeat_state.details == "progress":
1379
- final_line = _compact_progress_line(
1380
- started,
1373
+
1374
+ if self.config.live_output and (not self.config.verbose or self.config.suppress_stream_output):
1375
+ final_heartbeat_state = _display_heartbeat_state(
1381
1376
  session_log,
1382
1377
  self.config.progress_path,
1383
- final_heartbeat_state,
1384
- checkpoint_path=self.config.checkpoint_path,
1378
+ heartbeat.state if heartbeat is not None else None,
1379
+ display_heartbeat_state,
1380
+ interval_seconds=live_progress_interval,
1385
1381
  stale_threshold_seconds=stale_threshold_seconds,
1386
1382
  )
1387
- if final_line != last_progress_line:
1388
- _emit_live_line(final_line)
1389
- last_progress_line = final_line
1390
- reader.join(timeout=5)
1391
- heartbeat_result = heartbeat.stop() if heartbeat is not None else None
1392
- if heartbeat_result and heartbeat_result.killed:
1393
- termination_reason = heartbeat_result.reason
1394
- stale_marker = heartbeat_result.marker_path
1383
+ display_heartbeat_state = final_heartbeat_state
1384
+ if final_heartbeat_state.details == "progress":
1385
+ final_line = _compact_progress_line(
1386
+ started,
1387
+ session_log,
1388
+ self.config.progress_path,
1389
+ final_heartbeat_state,
1390
+ checkpoint_path=self.config.checkpoint_path,
1391
+ stale_threshold_seconds=stale_threshold_seconds,
1392
+ )
1393
+ if final_line != last_progress_line:
1394
+ _emit_live_line(final_line)
1395
+ last_progress_line = final_line
1396
+ except KeyboardInterrupt as interruption:
1397
+ interrupted = True
1398
+ with shield_interruption_signals():
1399
+ monitor_state = heartbeat.state if heartbeat is not None else display_heartbeat_state
1400
+ if handle is not None:
1401
+ try:
1402
+ _emit_ai_interruption_received(
1403
+ interruption,
1404
+ command=command,
1405
+ handle=handle,
1406
+ started_epoch=started,
1407
+ session_log=session_log,
1408
+ progress_path=self.config.progress_path,
1409
+ checkpoint_path=self.config.checkpoint_path,
1410
+ heartbeat_state=monitor_state,
1411
+ )
1412
+ except Exception as diagnostic_error:
1413
+ _emit_interrupt_line(
1414
+ f"diagnostic collection failed error={type(diagnostic_error).__name__}; "
1415
+ "continuing existing process-tree cleanup"
1416
+ )
1417
+ termination = terminate_process_tree(
1418
+ handle,
1419
+ "interrupted",
1420
+ grace_seconds=self.config.stale_kill_grace_seconds,
1421
+ )
1422
+ _emit_ai_interruption_termination(termination)
1423
+ raise
1424
+ finally:
1425
+ if reader is not None and not interrupted:
1426
+ reader.join(timeout=1.5)
1427
+ if (
1428
+ reader.is_alive()
1429
+ and handle is not None
1430
+ and handle.popen is not None
1431
+ and handle.popen.poll() is not None
1432
+ ):
1433
+ terminate_process_tree(handle, "lingering_child_pipes", grace_seconds=0.5)
1434
+ reader.join(timeout=3.5)
1435
+ heartbeat_result = heartbeat.stop() if heartbeat is not None else None
1436
+ if reader is not None and interrupted:
1437
+ reader.join(timeout=1.0)
1438
+ if not interrupted and heartbeat_result and heartbeat_result.killed:
1439
+ termination_reason = heartbeat_result.reason
1440
+ stale_marker = heartbeat_result.marker_path
1441
+ if interrupted:
1442
+ try:
1443
+ recover_session_log(session_log, backup_log)
1444
+ except OSError:
1445
+ pass
1446
+
1447
+ assert handle is not None and handle.popen is not None
1395
1448
  if termination_reason is None and kill_threshold_seconds > 0 and handle.popen.returncode is None:
1396
1449
  stale_marker = write_stale_marker(
1397
1450
  session_log.parent,
@@ -1417,7 +1470,7 @@ class AISessionLauncher:
1417
1470
  merged_progress.update(reader_progress)
1418
1471
  fallback_summary = ProgressSummary()
1419
1472
  if self.config.progress_path is not None:
1420
- self.config.progress_path.write_text(json.dumps(merged_progress, indent=2, sort_keys=True) + "\n", encoding="utf-8")
1473
+ _write_progress_data(self.config.progress_path, merged_progress)
1421
1474
  final_summary = _summary_from_progress_dict(merged_progress, fallback_summary)
1422
1475
  ended = time.time()
1423
1476
  result = AISessionResult(
@@ -72,7 +72,6 @@ def default_status_targets(paths: RuntimePaths) -> dict[str, StatusTarget]:
72
72
  return {
73
73
  "feature": StatusTarget("feature", paths.feature_plan, paths.feature_state_dir),
74
74
  "bugfix": StatusTarget("bugfix", paths.bugfix_plan, paths.bugfix_state_dir),
75
- "refactor": StatusTarget("refactor", paths.refactor_plan, paths.refactor_state_dir),
76
75
  }
77
76
 
78
77
 
@@ -87,7 +86,6 @@ class AggregateStatusResult:
87
86
  _FAMILY_PLAN_KEYS = {
88
87
  "feature": "features",
89
88
  "bugfix": "bugs",
90
- "refactor": "refactors",
91
89
  }
92
90
 
93
91
 
@@ -154,7 +152,7 @@ def aggregate_family_status(
154
152
  sections: list[str] = []
155
153
  failed = False
156
154
 
157
- for family in ("feature", "bugfix", "refactor"):
155
+ for family in ("feature", "bugfix"):
158
156
  target = targets[family]
159
157
  label = family.upper()
160
158
  body: str