prizmkit 1.1.192 → 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.
- package/bundled/VERSION.json +3 -3
- package/bundled/dev-pipeline/README.md +23 -34
- package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -0
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -2
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +2 -0
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -40
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +9 -1
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +0 -22
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +11 -7
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +26 -20
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +37 -4
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +20 -41
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +74 -36
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +0 -66
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +271 -52
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +51 -13
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +43 -15
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +27 -24
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +0 -1
- package/bundled/dev-pipeline/scripts/check-session-status.py +13 -1
- package/bundled/dev-pipeline/scripts/continuation.py +2 -3
- package/bundled/dev-pipeline/scripts/detect-stuck.py +19 -5
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +6 -14
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +13 -8
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +17 -2
- package/bundled/dev-pipeline/scripts/prompt_framework.py +39 -21
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +27 -0
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +1 -1
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +6 -6
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +1 -1
- package/bundled/skills/_metadata.json +1 -1
- package/package.json +1 -1
- package/bundled/dev-pipeline/tests/_helpers.py +0 -418
- package/bundled/dev-pipeline/tests/conftest.py +0 -73
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
- package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1806
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1439
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +0 -257
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +0 -500
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1654
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -629
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -2973
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -321
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -251
- package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1196
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -872
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +0 -766
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +0 -1257
- package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -380
- package/bundled/dev-pipeline/tests/test_session_launch.py +0 -1101
- package/bundled/dev-pipeline/tests/test_stream_progress.py +0 -585
- package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -3625
- package/bundled/dev-pipeline/tests/test_utils.py +0 -170
|
@@ -184,11 +184,14 @@ def detect_stream_json_support(
|
|
|
184
184
|
if len(raw_command) >= 2 and raw_command[0] == raw_command[-1] and raw_command[0] in "'\""
|
|
185
185
|
else raw_command
|
|
186
186
|
)
|
|
187
|
-
|
|
188
|
-
unquoted
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
if len(unquoted) >= 3 and unquoted[1:3] in {":\\", ":/"} and unquoted.lower().endswith((".exe", ".cmd", ".bat")):
|
|
188
|
+
command_token = unquoted
|
|
189
|
+
else:
|
|
190
|
+
try:
|
|
191
|
+
tokens = shlex.split(raw_command)
|
|
192
|
+
command_token = tokens[0] if tokens else raw_command
|
|
193
|
+
except ValueError:
|
|
194
|
+
command_token = raw_command.split()[0].strip("'\"")
|
|
192
195
|
command_name = command_token.replace("\\", "/").rsplit("/", 1)[-1].lower()
|
|
193
196
|
for suffix in (".exe", ".cmd", ".bat"):
|
|
194
197
|
if command_name.endswith(suffix):
|
|
@@ -1293,8 +1296,10 @@ class AISessionLauncher:
|
|
|
1293
1296
|
display_heartbeat_state = None
|
|
1294
1297
|
handle: ProcessHandle | None = None
|
|
1295
1298
|
reader: threading.Thread | None = None
|
|
1299
|
+
stdin_writer: threading.Thread | None = None
|
|
1296
1300
|
heartbeat: HeartbeatMonitor | None = None
|
|
1297
1301
|
interrupted = False
|
|
1302
|
+
launcher_aborted = False
|
|
1298
1303
|
reader_result_queue: queue.Queue[dict[str, object]] = queue.Queue(maxsize=1)
|
|
1299
1304
|
|
|
1300
1305
|
try:
|
|
@@ -1314,13 +1319,6 @@ class AISessionLauncher:
|
|
|
1314
1319
|
daemon=True,
|
|
1315
1320
|
)
|
|
1316
1321
|
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
1322
|
|
|
1325
1323
|
heartbeat_path = self.config.heartbeat_path
|
|
1326
1324
|
if heartbeat_path is None and kill_threshold_seconds > 0:
|
|
@@ -1341,6 +1339,25 @@ class AISessionLauncher:
|
|
|
1341
1339
|
)
|
|
1342
1340
|
heartbeat.start()
|
|
1343
1341
|
|
|
1342
|
+
if handle.popen.stdin is not None:
|
|
1343
|
+
stdin_pipe = handle.popen.stdin
|
|
1344
|
+
stdin_text = command.stdin_text
|
|
1345
|
+
|
|
1346
|
+
def _write_stdin() -> None:
|
|
1347
|
+
try:
|
|
1348
|
+
if stdin_text is not None:
|
|
1349
|
+
stdin_pipe.write(stdin_text)
|
|
1350
|
+
except (BrokenPipeError, OSError):
|
|
1351
|
+
pass
|
|
1352
|
+
finally:
|
|
1353
|
+
try:
|
|
1354
|
+
stdin_pipe.close()
|
|
1355
|
+
except (BrokenPipeError, OSError):
|
|
1356
|
+
pass
|
|
1357
|
+
|
|
1358
|
+
stdin_writer = threading.Thread(target=_write_stdin, name="prizmkit-stdin", daemon=True)
|
|
1359
|
+
stdin_writer.start()
|
|
1360
|
+
|
|
1344
1361
|
while True:
|
|
1345
1362
|
timeout = 0.2
|
|
1346
1363
|
if self.config.total_timeout_seconds is not None:
|
|
@@ -1421,8 +1438,19 @@ class AISessionLauncher:
|
|
|
1421
1438
|
)
|
|
1422
1439
|
_emit_ai_interruption_termination(termination)
|
|
1423
1440
|
raise
|
|
1441
|
+
except Exception:
|
|
1442
|
+
launcher_aborted = True
|
|
1443
|
+
if handle is not None:
|
|
1444
|
+
terminate_process_tree(
|
|
1445
|
+
handle,
|
|
1446
|
+
"launcher_error",
|
|
1447
|
+
grace_seconds=self.config.stale_kill_grace_seconds,
|
|
1448
|
+
)
|
|
1449
|
+
raise
|
|
1424
1450
|
finally:
|
|
1425
|
-
if
|
|
1451
|
+
if stdin_writer is not None:
|
|
1452
|
+
stdin_writer.join(timeout=1.0)
|
|
1453
|
+
if reader is not None and not interrupted and not launcher_aborted:
|
|
1426
1454
|
reader.join(timeout=1.5)
|
|
1427
1455
|
if (
|
|
1428
1456
|
reader.is_alive()
|
|
@@ -1433,9 +1461,9 @@ class AISessionLauncher:
|
|
|
1433
1461
|
terminate_process_tree(handle, "lingering_child_pipes", grace_seconds=0.5)
|
|
1434
1462
|
reader.join(timeout=3.5)
|
|
1435
1463
|
heartbeat_result = heartbeat.stop() if heartbeat is not None else None
|
|
1436
|
-
if reader is not None and interrupted:
|
|
1464
|
+
if reader is not None and (interrupted or launcher_aborted):
|
|
1437
1465
|
reader.join(timeout=1.0)
|
|
1438
|
-
if not interrupted and heartbeat_result and heartbeat_result.killed:
|
|
1466
|
+
if not interrupted and not launcher_aborted and heartbeat_result and heartbeat_result.killed:
|
|
1439
1467
|
termination_reason = heartbeat_result.reason
|
|
1440
1468
|
stale_marker = heartbeat_result.marker_path
|
|
1441
1469
|
if interrupted:
|
|
@@ -2135,11 +2135,20 @@ class ProgressTracker:
|
|
|
2135
2135
|
text_parts = []
|
|
2136
2136
|
terminal_parts = []
|
|
2137
2137
|
|
|
2138
|
-
for key in ("fatal_error_code", "api_error_code", "error_code"
|
|
2138
|
+
for key in ("fatal_error_code", "api_error_code", "error_code"):
|
|
2139
2139
|
value = event.get(key)
|
|
2140
2140
|
if isinstance(value, (str, int, float)) and str(value).strip():
|
|
2141
2141
|
code_parts.append(str(value))
|
|
2142
2142
|
|
|
2143
|
+
raw_stop_reason = event.get("stop_reason")
|
|
2144
|
+
stop_reason_code = ""
|
|
2145
|
+
if isinstance(raw_stop_reason, (str, int, float)) and str(raw_stop_reason).strip():
|
|
2146
|
+
stop_reason_code = detect_api_error_code(
|
|
2147
|
+
str(raw_stop_reason).strip(),
|
|
2148
|
+
require_error_context=False,
|
|
2149
|
+
structured_code=True,
|
|
2150
|
+
)
|
|
2151
|
+
|
|
2143
2152
|
for key in ("terminal_result_text", "message", "result"):
|
|
2144
2153
|
value = event.get(key)
|
|
2145
2154
|
if isinstance(value, (str, int, float)) and str(value).strip():
|
|
@@ -2159,24 +2168,29 @@ class ProgressTracker:
|
|
|
2159
2168
|
|
|
2160
2169
|
combined_code_text = " ".join(code_parts)
|
|
2161
2170
|
combined_text = " ".join(code_parts + text_parts)
|
|
2162
|
-
if not combined_text:
|
|
2171
|
+
if not combined_text and not stop_reason_code:
|
|
2163
2172
|
return
|
|
2164
2173
|
|
|
2165
2174
|
error_like = (
|
|
2166
2175
|
bool(code_parts)
|
|
2176
|
+
or bool(stop_reason_code)
|
|
2167
2177
|
or event.get("api_error_status") not in (None, "")
|
|
2168
2178
|
or bool(event.get("last_result_is_error"))
|
|
2169
2179
|
or bool(event.get("is_error"))
|
|
2170
2180
|
or _has_error_context(combined_text)
|
|
2171
2181
|
)
|
|
2172
|
-
normalized_code =
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2182
|
+
normalized_code = (
|
|
2183
|
+
detect_api_error_code(
|
|
2184
|
+
combined_code_text,
|
|
2185
|
+
require_error_context=False,
|
|
2186
|
+
structured_code=True,
|
|
2187
|
+
)
|
|
2188
|
+
or stop_reason_code
|
|
2189
|
+
or detect_api_error_code(
|
|
2190
|
+
combined_text,
|
|
2191
|
+
require_error_context=not error_like,
|
|
2192
|
+
structured_code=bool(code_parts),
|
|
2193
|
+
)
|
|
2180
2194
|
)
|
|
2181
2195
|
if not normalized_code:
|
|
2182
2196
|
return
|
|
@@ -2255,6 +2269,9 @@ class ProgressTracker:
|
|
|
2255
2269
|
"""Record a Claude Code terminal result event."""
|
|
2256
2270
|
terminal_text = str(text or "")
|
|
2257
2271
|
self.last_result_is_error = bool(is_error)
|
|
2272
|
+
normalized_stop_reason = str(stop_reason or "").strip()
|
|
2273
|
+
if normalized_stop_reason:
|
|
2274
|
+
self.stop_reason = normalized_stop_reason
|
|
2258
2275
|
if api_error_status not in (None, ""):
|
|
2259
2276
|
try:
|
|
2260
2277
|
self.api_error_status = int(api_error_status)
|
|
@@ -2498,13 +2515,6 @@ class ProgressTracker:
|
|
|
2498
2515
|
return Path(claude_home).expanduser() / "projects"
|
|
2499
2516
|
return Path.home() / ".claude" / "projects"
|
|
2500
2517
|
|
|
2501
|
-
def _claude_project_key(self):
|
|
2502
|
-
"""Encode cwd the same way Claude Code stores project transcript dirs."""
|
|
2503
|
-
cwd = self.claude_cwd
|
|
2504
|
-
if not cwd:
|
|
2505
|
-
return ""
|
|
2506
|
-
return cwd.replace("\\", "-").replace("/", "-").replace(":", "")
|
|
2507
|
-
|
|
2508
2518
|
def _claude_candidate_project_keys(self, cwd: str) -> list[str]:
|
|
2509
2519
|
if not cwd:
|
|
2510
2520
|
return []
|
|
@@ -2569,13 +2579,6 @@ class ProgressTracker:
|
|
|
2569
2579
|
return Path(cb_home).expanduser() / "projects"
|
|
2570
2580
|
return Path.home() / ".codebuddy" / "projects"
|
|
2571
2581
|
|
|
2572
|
-
def _cb_project_key(self):
|
|
2573
|
-
"""Encode cwd the same way CodeBuddy stores project subdirs."""
|
|
2574
|
-
cwd = self.cb_cwd
|
|
2575
|
-
if not cwd:
|
|
2576
|
-
return ""
|
|
2577
|
-
return cwd.replace("\\", "-").replace("/", "-").replace(":", "").lstrip("-")
|
|
2578
|
-
|
|
2579
2582
|
def _cb_candidate_project_keys(self, cwd: str) -> list[str]:
|
|
2580
2583
|
if not cwd:
|
|
2581
2584
|
return []
|
|
@@ -175,7 +175,19 @@ def determine_status(data):
|
|
|
175
175
|
|
|
176
176
|
if status == "success":
|
|
177
177
|
return "success"
|
|
178
|
-
if status == "context_overflow"
|
|
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):
|
|
179
191
|
return "context_overflow"
|
|
180
192
|
elif status == "partial":
|
|
181
193
|
can_resume = data.get("can_resume", False)
|
|
@@ -8,6 +8,7 @@ _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"}
|
|
@@ -376,9 +377,7 @@ def append_continuation_handoff(rendered_prompt, args, project_root, task_type,
|
|
|
376
377
|
summary_text = _build_summary(context)
|
|
377
378
|
for summary_path in paths:
|
|
378
379
|
abs_summary = os.path.join(project_root, summary_path)
|
|
379
|
-
|
|
380
|
-
with open(abs_summary, "w", encoding="utf-8") as f:
|
|
381
|
-
f.write(summary_text)
|
|
380
|
+
write_text_atomic(abs_summary, summary_text)
|
|
382
381
|
|
|
383
382
|
addendum = _build_addendum(context)
|
|
384
383
|
return rendered_prompt.rstrip() + "\n\n" + addendum
|
|
@@ -252,11 +252,16 @@ def check_stale_heartbeat(item_id, item_status, state_dir, items_subdir, stale_t
|
|
|
252
252
|
if not session_id:
|
|
253
253
|
return None
|
|
254
254
|
|
|
255
|
-
# Check heartbeat file
|
|
255
|
+
# Check heartbeat file (canonical logs/heartbeat.json first, legacy fallback)
|
|
256
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(
|
|
257
260
|
state_dir, items_subdir, item_id, "sessions", session_id, "heartbeat.json"
|
|
258
261
|
)
|
|
259
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)
|
|
260
265
|
|
|
261
266
|
if heartbeat is None:
|
|
262
267
|
return {
|
|
@@ -268,16 +273,22 @@ def check_stale_heartbeat(item_id, item_status, state_dir, items_subdir, stale_t
|
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
# Parse heartbeat timestamp and check staleness
|
|
276
|
+
epoch_val = heartbeat.get("last_seen_epoch")
|
|
271
277
|
ts_str = (
|
|
272
278
|
heartbeat.get("timestamp")
|
|
273
279
|
or heartbeat.get("last_heartbeat_at")
|
|
274
280
|
or heartbeat.get("updated_at")
|
|
275
281
|
)
|
|
276
|
-
|
|
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)
|
|
277
286
|
if heartbeat_time is None:
|
|
278
287
|
return {
|
|
279
288
|
"reason": "stale_heartbeat",
|
|
280
|
-
"details": "Heartbeat has invalid or unparseable timestamp: {}".format(
|
|
289
|
+
"details": "Heartbeat has invalid or unparseable timestamp: {}".format(
|
|
290
|
+
epoch_val if epoch_val is not None else ts_str
|
|
291
|
+
),
|
|
281
292
|
"suggestion": "Check the agent session - heartbeat timestamp is malformed",
|
|
282
293
|
}
|
|
283
294
|
|
|
@@ -398,6 +409,9 @@ def check_item(item_id, state_dir, items_subdir, items_key, task_list_data, max_
|
|
|
398
409
|
task_list_status = item.get("status", "pending")
|
|
399
410
|
break
|
|
400
411
|
|
|
412
|
+
if task_list_status in {"completed", "failed", "skipped", "auto_skipped", "needs_info", "split"}:
|
|
413
|
+
return []
|
|
414
|
+
|
|
401
415
|
reports = []
|
|
402
416
|
|
|
403
417
|
# Check 1: Max retries exceeded
|
|
@@ -432,8 +446,8 @@ def resolve_pipeline_type(args):
|
|
|
432
446
|
# Explicit --pipeline-type takes precedence
|
|
433
447
|
if args.pipeline_type:
|
|
434
448
|
ptype = args.pipeline_type
|
|
435
|
-
item_id = args.item_id
|
|
436
|
-
task_list = args.task_list
|
|
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)
|
|
437
451
|
# Legacy / shorthand: --feature-id, --bug-id
|
|
438
452
|
elif args.feature_id:
|
|
439
453
|
ptype = "feature"
|
|
@@ -24,7 +24,7 @@ import os
|
|
|
24
24
|
import re
|
|
25
25
|
import sys
|
|
26
26
|
|
|
27
|
-
from utils import enrich_global_context, helper_replacements, load_json_file, resolve_prompt_platform, setup_logging
|
|
27
|
+
from utils import enrich_global_context, helper_replacements, load_json_file, resolve_prompt_platform, setup_logging, write_json_file
|
|
28
28
|
from continuation import add_continuation_args, append_continuation_handoff, is_continuation
|
|
29
29
|
from prompt_framework import (
|
|
30
30
|
artifact_exists,
|
|
@@ -268,19 +268,15 @@ def extract_baseline_failures(test_cmd, project_root):
|
|
|
268
268
|
|
|
269
269
|
try:
|
|
270
270
|
import subprocess
|
|
271
|
-
original_cwd = os.getcwd()
|
|
272
|
-
os.chdir(project_root)
|
|
273
|
-
|
|
274
271
|
result = subprocess.run(
|
|
275
272
|
test_cmd,
|
|
276
273
|
shell=True,
|
|
274
|
+
cwd=project_root,
|
|
277
275
|
capture_output=True,
|
|
278
276
|
text=True,
|
|
279
|
-
timeout=120
|
|
277
|
+
timeout=120,
|
|
280
278
|
)
|
|
281
279
|
|
|
282
|
-
os.chdir(original_cwd)
|
|
283
|
-
|
|
284
280
|
output = result.stdout + result.stderr
|
|
285
281
|
failures = []
|
|
286
282
|
|
|
@@ -296,11 +292,6 @@ def extract_baseline_failures(test_cmd, project_root):
|
|
|
296
292
|
|
|
297
293
|
except Exception as e:
|
|
298
294
|
return f"(error: {str(e)})"
|
|
299
|
-
finally:
|
|
300
|
-
try:
|
|
301
|
-
os.chdir(original_cwd)
|
|
302
|
-
except Exception:
|
|
303
|
-
pass
|
|
304
295
|
|
|
305
296
|
|
|
306
297
|
def format_ac_checklist(acceptance_criteria):
|
|
@@ -1273,8 +1264,9 @@ def main():
|
|
|
1273
1264
|
)
|
|
1274
1265
|
|
|
1275
1266
|
if not args.no_checkpoint_write:
|
|
1276
|
-
|
|
1277
|
-
|
|
1267
|
+
err = write_json_file(checkpoint_path, checkpoint)
|
|
1268
|
+
if err:
|
|
1269
|
+
emit_failure(err)
|
|
1278
1270
|
LOGGER.info("Wrote checkpoint to %s", checkpoint_path)
|
|
1279
1271
|
|
|
1280
1272
|
if is_continuation(args):
|
|
@@ -27,7 +27,15 @@ from prompt_framework import (
|
|
|
27
27
|
validate_rendered,
|
|
28
28
|
write_output,
|
|
29
29
|
)
|
|
30
|
-
from utils import
|
|
30
|
+
from utils import (
|
|
31
|
+
enrich_global_context,
|
|
32
|
+
helper_replacements,
|
|
33
|
+
load_json_file,
|
|
34
|
+
read_checkpoint_system_section,
|
|
35
|
+
resolve_prompt_platform,
|
|
36
|
+
setup_logging,
|
|
37
|
+
write_json_file,
|
|
38
|
+
)
|
|
31
39
|
|
|
32
40
|
|
|
33
41
|
LOGGER = setup_logging("generate-bugfix-prompt")
|
|
@@ -464,11 +472,7 @@ def generate_bugfix_checkpoint(
|
|
|
464
472
|
|
|
465
473
|
def merge_bugfix_checkpoint_state(existing, fresh, project_root):
|
|
466
474
|
"""Merge existing bugfix checkpoint state into fresh definition."""
|
|
467
|
-
|
|
468
|
-
existing_state = existing.get("bugfix_state")
|
|
469
|
-
if isinstance(existing_state, dict):
|
|
470
|
-
merged["bugfix_state"] = existing_state
|
|
471
|
-
return merged
|
|
475
|
+
return merge_checkpoint_state(existing, fresh, project_root, logger=LOGGER)
|
|
472
476
|
|
|
473
477
|
|
|
474
478
|
def emit_failure(message):
|
|
@@ -571,8 +575,9 @@ def main():
|
|
|
571
575
|
LOGGER.warning("Existing bugfix checkpoint corrupted (%s) — generating fresh", exc)
|
|
572
576
|
|
|
573
577
|
if not args.no_checkpoint_write:
|
|
574
|
-
|
|
575
|
-
|
|
578
|
+
err = write_json_file(checkpoint_path, checkpoint)
|
|
579
|
+
if err:
|
|
580
|
+
emit_failure(err)
|
|
576
581
|
LOGGER.info("Wrote bugfix checkpoint to %s", checkpoint_path)
|
|
577
582
|
|
|
578
583
|
if is_continuation(args):
|
|
@@ -48,6 +48,17 @@ def create_directories(project_root, feature_slug=None):
|
|
|
48
48
|
dirs_to_create = []
|
|
49
49
|
|
|
50
50
|
if feature_slug:
|
|
51
|
+
if (
|
|
52
|
+
os.path.isabs(feature_slug)
|
|
53
|
+
or "/" in feature_slug
|
|
54
|
+
or "\\" in feature_slug
|
|
55
|
+
or feature_slug in {".", ".."}
|
|
56
|
+
):
|
|
57
|
+
raise ValueError(f"Invalid feature_slug '{feature_slug}'")
|
|
58
|
+
specs_root = os.path.realpath(os.path.join(project_root, ".prizmkit", "specs"))
|
|
59
|
+
target_dir = os.path.realpath(os.path.join(specs_root, feature_slug))
|
|
60
|
+
if os.path.commonpath([specs_root, target_dir]) != specs_root or target_dir == specs_root:
|
|
61
|
+
raise ValueError(f"feature_slug escapes .prizmkit/specs: '{feature_slug}'")
|
|
51
62
|
dirs_to_create.extend([
|
|
52
63
|
".prizmkit/specs/{}".format(feature_slug),
|
|
53
64
|
])
|
|
@@ -71,8 +82,12 @@ def init_prizmkit_config(project_root, feature_id):
|
|
|
71
82
|
config_path = os.path.join(project_root, ".prizmkit", "config.json")
|
|
72
83
|
|
|
73
84
|
if os.path.exists(config_path):
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
try:
|
|
86
|
+
with open(config_path, "r", encoding="utf-8") as f:
|
|
87
|
+
loaded = json.load(f)
|
|
88
|
+
config = loaded if isinstance(loaded, dict) else {}
|
|
89
|
+
except (json.JSONDecodeError, IOError):
|
|
90
|
+
config = {}
|
|
76
91
|
config["current_feature"] = feature_id
|
|
77
92
|
config["updated_at"] = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
78
93
|
else:
|
|
@@ -14,6 +14,7 @@ _PIPELINE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
14
14
|
if _PIPELINE_ROOT not in sys.path:
|
|
15
15
|
sys.path.insert(0, _PIPELINE_ROOT)
|
|
16
16
|
|
|
17
|
+
from prizmkit_runtime.atomic_io import write_text_atomic # noqa: E402
|
|
17
18
|
from prizmkit_runtime.checkpoint_state import ( # noqa: E402
|
|
18
19
|
VALID_CHECKPOINT_STATUSES,
|
|
19
20
|
VALID_REPAIR_SCOPES,
|
|
@@ -230,18 +231,11 @@ def validate_rendered(content, required_markers=None, logger=None):
|
|
|
230
231
|
|
|
231
232
|
|
|
232
233
|
def write_output(output_path, content):
|
|
233
|
-
"""Write rendered prompt content to output_path."""
|
|
234
|
+
"""Write rendered prompt content atomically to output_path."""
|
|
234
235
|
abs_path = os.path.abspath(output_path)
|
|
235
|
-
output_dir = os.path.dirname(abs_path)
|
|
236
|
-
if output_dir and not os.path.isdir(output_dir):
|
|
237
|
-
try:
|
|
238
|
-
os.makedirs(output_dir, exist_ok=True)
|
|
239
|
-
except OSError as exc:
|
|
240
|
-
return "Cannot create output directory: {}".format(str(exc))
|
|
241
236
|
try:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
except IOError as exc:
|
|
237
|
+
write_text_atomic(abs_path, content)
|
|
238
|
+
except OSError as exc:
|
|
245
239
|
return "Cannot write output file: {}".format(str(exc))
|
|
246
240
|
return None
|
|
247
241
|
|
|
@@ -427,7 +421,8 @@ def merge_checkpoint_state(existing, fresh, project_root, validator=None, logger
|
|
|
427
421
|
return None
|
|
428
422
|
|
|
429
423
|
chain_broken = False
|
|
430
|
-
|
|
424
|
+
first_break_index = None
|
|
425
|
+
for index, step in enumerate(fresh.get("steps", [])):
|
|
431
426
|
if chain_broken:
|
|
432
427
|
step["status"] = "pending"
|
|
433
428
|
continue
|
|
@@ -463,6 +458,7 @@ def merge_checkpoint_state(existing, fresh, project_root, validator=None, logger
|
|
|
463
458
|
step["status"] = "skipped"
|
|
464
459
|
continue
|
|
465
460
|
chain_broken = True
|
|
461
|
+
first_break_index = index
|
|
466
462
|
step["status"] = "pending"
|
|
467
463
|
|
|
468
464
|
workflow_type = fresh.get("workflow_type", "")
|
|
@@ -471,31 +467,53 @@ def merge_checkpoint_state(existing, fresh, project_root, validator=None, logger
|
|
|
471
467
|
"bugfix-pipeline": "bugfix_state",
|
|
472
468
|
}.get(workflow_type)
|
|
473
469
|
if state_key:
|
|
470
|
+
existing_state = existing.get(state_key) if isinstance(existing.get(state_key), dict) else {}
|
|
474
471
|
merged_state = dict(fresh[state_key]) if isinstance(fresh.get(state_key), dict) else {}
|
|
475
|
-
if
|
|
476
|
-
merged_state.update(
|
|
472
|
+
if existing_state:
|
|
473
|
+
merged_state.update(existing_state)
|
|
477
474
|
if chain_broken and merged_state:
|
|
478
475
|
from prizmkit_runtime.checkpoint_state import (
|
|
479
476
|
SKILL_WORKFLOW_STAGES,
|
|
480
477
|
TERMINAL_STEP_STATUSES,
|
|
481
478
|
)
|
|
482
479
|
|
|
480
|
+
steps_list = fresh.get("steps", [])
|
|
483
481
|
first_active = next(
|
|
484
|
-
(s for s in
|
|
482
|
+
(s for s in steps_list if s.get("status") not in TERMINAL_STEP_STATUSES),
|
|
485
483
|
None,
|
|
486
484
|
)
|
|
487
485
|
next_skill = first_active.get("skill") if isinstance(first_active, dict) else None
|
|
486
|
+
repair_target = existing_state.get("next_stage")
|
|
487
|
+
repair_target_index = next(
|
|
488
|
+
(i for i, s in enumerate(steps_list) if s.get("skill") == repair_target),
|
|
489
|
+
None,
|
|
490
|
+
)
|
|
491
|
+
active_routed_repair = (
|
|
492
|
+
existing_state.get("stage_result") in {"REVIEW_NEEDS_FIXES", "TEST_NEEDS_FIXES"}
|
|
493
|
+
and repair_target == "prizmkit-implement"
|
|
494
|
+
and existing_state.get("terminal_status") is None
|
|
495
|
+
and repair_target_index is not None
|
|
496
|
+
and first_break_index is not None
|
|
497
|
+
and first_break_index >= repair_target_index
|
|
498
|
+
)
|
|
488
499
|
merged_state["terminal_status"] = None
|
|
489
500
|
merged_state["blocked_reason"] = None
|
|
490
|
-
merged_state["repair_scope"] = None
|
|
491
|
-
merged_state.pop("stage_result", None)
|
|
492
501
|
merged_state.pop("runtime_base_head", None)
|
|
493
502
|
merged_state.pop("runtime_commit_hash", None)
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
503
|
+
if active_routed_repair:
|
|
504
|
+
merged_state["next_stage"] = repair_target
|
|
505
|
+
merged_state["resume_from"] = repair_target
|
|
506
|
+
if not merged_state.get("current_stage") and next_skill:
|
|
507
|
+
merged_state["current_stage"] = next_skill
|
|
508
|
+
else:
|
|
509
|
+
merged_state["repair_scope"] = None
|
|
510
|
+
merged_state.pop("stage_result", None)
|
|
511
|
+
merged_state["status"] = "pending"
|
|
512
|
+
merged_state["current_stage"] = next_skill
|
|
513
|
+
merged_state["next_stage"] = next_skill
|
|
514
|
+
merged_state["resume_from"] = next_skill
|
|
515
|
+
if next_skill:
|
|
516
|
+
merged_state["stage"] = SKILL_WORKFLOW_STAGES.get(next_skill, next_skill)
|
|
499
517
|
if merged_state:
|
|
500
518
|
fresh[state_key] = merged_state
|
|
501
519
|
|
|
@@ -447,6 +447,14 @@ def update_checkpoint(
|
|
|
447
447
|
"instead of continuing step mutations."
|
|
448
448
|
),
|
|
449
449
|
}
|
|
450
|
+
if l4_state.get("terminal_status") == "WORKFLOW_COMPLETED":
|
|
451
|
+
return {
|
|
452
|
+
"ok": False,
|
|
453
|
+
"error": (
|
|
454
|
+
"Workflow checkpoint is already WORKFLOW_COMPLETED; reset or rewind the task "
|
|
455
|
+
"instead of continuing step mutations."
|
|
456
|
+
),
|
|
457
|
+
}
|
|
450
458
|
|
|
451
459
|
existing_round = l4_state.get("repair_round", 0)
|
|
452
460
|
requested_round = semantic_update.get("repair_round")
|
|
@@ -480,6 +488,25 @@ def update_checkpoint(
|
|
|
480
488
|
|
|
481
489
|
stage_result = semantic_update.get("stage_result")
|
|
482
490
|
project_root = _checkpoint_project_root(checkpoint_path)
|
|
491
|
+
if new_status == "completed" and workflow_type in {"feature-pipeline", "bugfix-pipeline"}:
|
|
492
|
+
required_completed_results = {
|
|
493
|
+
"prizmkit-plan": "PLAN_READY",
|
|
494
|
+
"context-snapshot-and-plan": "PLAN_READY",
|
|
495
|
+
"bug-diagnosis-and-plan": "PLAN_READY",
|
|
496
|
+
"prizmkit-implement": "IMPLEMENTED",
|
|
497
|
+
"prizmkit-retrospective": "RETRO_COMPLETE",
|
|
498
|
+
}
|
|
499
|
+
expected_completed_result = required_completed_results.get(step.get("skill"))
|
|
500
|
+
if expected_completed_result is not None:
|
|
501
|
+
resolved_result = stage_result or step.get("stage_result")
|
|
502
|
+
if resolved_result != expected_completed_result:
|
|
503
|
+
return {
|
|
504
|
+
"ok": False,
|
|
505
|
+
"error": "{} completion requires {}".format(
|
|
506
|
+
step.get("skill"), expected_completed_result
|
|
507
|
+
),
|
|
508
|
+
}
|
|
509
|
+
stage_result = resolved_result
|
|
483
510
|
if new_status == "completed" and step.get("skill") == "prizmkit-code-review":
|
|
484
511
|
stage_result = stage_result or step.get("stage_result")
|
|
485
512
|
if stage_result != "REVIEW_PASS":
|
|
@@ -406,7 +406,7 @@ After configured Browser/Manual verification, invoke the Feature test gate:
|
|
|
406
406
|
/prizmkit-test scope=this-change artifact_dir=.prizmkit/specs/{{FEATURE_SLUG}}/
|
|
407
407
|
```
|
|
408
408
|
|
|
409
|
-
Consume `.prizmkit/specs/{{FEATURE_SLUG}}/test-report.md` and `test-result.json`. They must agree. `TEST_PASS` completes the gate. For `TEST_NEEDS_FIXES`, classify the concrete correction into an allowed `repair_scope`; safe in-budget repair re-enters Implement through the helper and requires fresh Review, configured verification, and Test, while unknown/unsafe scope or exhausted budget blocks. `TEST_BLOCKED` preserves the blocker and becomes `WORKFLOW_BLOCKED`. Do not require an evidence package, manifest, hashes, attestation, or test-internal checkpoint, and do not reinterpret a testing result as an AI CLI crash.
|
|
409
|
+
Consume `.prizmkit/specs/{{FEATURE_SLUG}}/test-report.md` and `test-result.json`. They must agree. `TEST_PASS` with consistent `production_changed=false` completes the gate; `TEST_PASS` with consistent `production_changed=true` keeps `prizmkit-test` incomplete and re-enters `prizmkit-code-review` in delta mode within the shared 3-round outer repair budget (`repair_round_limit` records `WORKFLOW_BLOCKED`). For `TEST_NEEDS_FIXES`, classify the concrete correction into an allowed `repair_scope`; safe in-budget repair re-enters Implement through the helper and requires fresh Review, configured verification, and Test, while unknown/unsafe scope or exhausted budget blocks. `TEST_BLOCKED` preserves the blocker and becomes `WORKFLOW_BLOCKED`. Do not require an evidence package, manifest, hashes, attestation, or test-internal checkpoint, and do not reinterpret a testing result as an AI CLI crash.
|
|
410
410
|
|
|
411
411
|
Record only caller-owned `stage`, `status`, `stage_result`, `repair_scope`, `repair_round`, `next_stage`, and `resume_from` in recovery metadata. Keep testing reports/results separate from `workflow-checkpoint.json`. The skill owns its internal ten-round Main-Agent review, five-response optional independent review, and three-round execution-failure repair budgets.
|
|
412
412
|
|
|
@@ -207,12 +207,12 @@ After valid code-review PASS and before Test, execute the configured Browser Ver
|
|
|
207
207
|
|
|
208
208
|
{{END_IF_BROWSER_INTERACTION}}
|
|
209
209
|
{{IF_VERIFICATION_MANUAL_OR_HYBRID}}
|
|
210
|
-
### Phase
|
|
210
|
+
### Phase 4b: Manual / Hybrid Verification
|
|
211
211
|
|
|
212
212
|
Complete the declared UAT checklist automatically with available browser, CLI, API, fixture, and test evidence. Record the evidence before Test. If required evidence cannot be established, write `failure-log.md` and stop truthfully.
|
|
213
213
|
|
|
214
214
|
{{END_IF_VERIFICATION_MANUAL_OR_HYBRID}}
|
|
215
|
-
### Phase
|
|
215
|
+
### Phase 5: Post-Review Test Gate — PrizmKit Test
|
|
216
216
|
|
|
217
217
|
After valid code-review PASS and all configured Browser/Manual verification, run the mandatory test gate against the same artifact root:
|
|
218
218
|
|
|
@@ -220,18 +220,18 @@ After valid code-review PASS and all configured Browser/Manual verification, run
|
|
|
220
220
|
/prizmkit-test scope=this-change artifact_dir=.prizmkit/bugfix/{{BUG_ID}}/
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
-
Read the sibling `test-report.md` and `test-result.json`; they must agree. `TEST_PASS` proceeds to the fix report and retrospective. For `TEST_NEEDS_FIXES`, classify the concrete correction into an allowed `repair_scope`; safe in-budget repair re-enters Implement through the helper and requires fresh Review, configured verification, and Test, while unknown/unsafe scope or exhausted budget blocks. `TEST_BLOCKED` preserves its blocker and records `WORKFLOW_BLOCKED`. Do not require a manifest/attestation package, reinterpret the testing result as a runtime crash, or recreate the skill's internal loops.
|
|
223
|
+
Read the sibling `test-report.md` and `test-result.json`; they must agree. `TEST_PASS` with `production_changed=false` proceeds to the fix report and retrospective; `TEST_PASS` with consistent `production_changed=true` keeps `prizmkit-test` incomplete and re-enters `prizmkit-code-review` in delta mode within the shared 3-round outer repair budget (`repair_round_limit` records `WORKFLOW_BLOCKED`). For `TEST_NEEDS_FIXES`, classify the concrete correction into an allowed `repair_scope`; safe in-budget repair re-enters Implement through the helper and requires fresh Review, configured verification, and Test, while unknown/unsafe scope or exhausted budget blocks. `TEST_BLOCKED` preserves its blocker and records `WORKFLOW_BLOCKED`. Do not require a manifest/attestation package, reinterpret the testing result as a runtime crash, or recreate the skill's internal loops.
|
|
224
224
|
|
|
225
|
-
Only `TEST_PASS` may proceed to commit.
|
|
225
|
+
Only `TEST_PASS` with `production_changed=false` may proceed to commit.
|
|
226
226
|
|
|
227
227
|
{{IF_VERIFICATION_MANUAL_OR_HYBRID}}
|
|
228
228
|
**MANUAL/HYBRID AUTOMATION**: This pipeline session is always headless. Execute manual/hybrid verification with available deterministic browser, CLI/API, fixture, or test tooling. Document the method and verification basis, then continue through `/prizmkit-retrospective` and `/prizmkit-committer`; never ask for UAT, wait for a user, or stop as `partial`.
|
|
229
|
-
- Do not write `verifying` to the external bug-list status field; fine-grained verification is session/checkpoint metadata, while the external list status remains one of `pending`, `in_progress`, `completed`, `failed`, `skipped`, or `needs_info
|
|
229
|
+
- Do not write `verifying` to the external bug-list status field; fine-grained verification is session/checkpoint metadata, while the external list status remains one of `pending`, `in_progress`, `completed`, `failed`, `skipped`, or `needs_info` (plus runtime-managed `auto_skipped`).
|
|
230
230
|
{{END_IF_VERIFICATION_MANUAL_OR_HYBRID}}
|
|
231
231
|
|
|
232
232
|
---
|
|
233
233
|
|
|
234
|
-
### Phase
|
|
234
|
+
### Phase 6: Report, Retrospective & Runtime Commit Handoff
|
|
235
235
|
|
|
236
236
|
**a. Fix report before commit preparation**
|
|
237
237
|
|