prizmkit 1.1.191 → 1.1.193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/VERSION.json +3 -3
- package/bundled/adapters/antigravity/skill-adapter.js +13 -4
- package/bundled/adapters/codex/skill-adapter.js +28 -8
- package/bundled/adapters/cursor/skill-adapter.js +13 -4
- package/bundled/adapters/pi/skill-adapter.js +28 -7
- package/bundled/dev-pipeline/.env.example +4 -12
- package/bundled/dev-pipeline/README.md +28 -44
- package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +6 -6
- package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
- package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
- package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
- package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +48 -78
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +127 -67
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +158 -462
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +102 -50
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -25
- package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +47 -21
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +217 -156
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +39 -27
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +34 -174
- package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +133 -110
- package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -95
- package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +540 -262
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +175 -135
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +214 -133
- package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2783 -0
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -102
- package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
- package/bundled/dev-pipeline/scripts/check-session-status.py +56 -20
- package/bundled/dev-pipeline/scripts/continuation.py +8 -7
- package/bundled/dev-pipeline/scripts/detect-stuck.py +47 -33
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +13 -16
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +20 -10
- package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +25 -4
- package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
- package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
- package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
- package/bundled/dev-pipeline/scripts/prompt_framework.py +85 -20
- package/bundled/dev-pipeline/scripts/status_common.py +591 -0
- package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +254 -65
- package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
- package/bundled/dev-pipeline/scripts/utils.py +5 -12
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +5 -5
- package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +7 -7
- package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
- package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
- package/bundled/skills/_metadata.json +9 -63
- package/bundled/skills/app-planner/SKILL.md +32 -303
- package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
- package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
- package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
- package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
- package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
- package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
- package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
- package/bundled/skills/bug-planner/SKILL.md +54 -435
- package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/bug-planner/references/input-formats.md +32 -0
- package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-planner/SKILL.md +60 -439
- package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
- package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
- package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
- package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
- package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
- package/bundled/skills/feature-workflow/SKILL.md +1 -2
- package/bundled/skills/prizmkit/SKILL.md +7 -1
- package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
- package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
- package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
- package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
- package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
- package/bundled/skills/prizmkit-init/SKILL.md +24 -127
- package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
- package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
- package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
- package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
- package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
- package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
- package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
- package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
- package/bundled/skills/prizmkit-test/SKILL.md +25 -133
- package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
- package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
- package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
- package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
- package/bundled/skills/recovery-workflow/SKILL.md +7 -7
- package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
- package/bundled/skills/recovery-workflow/references/detection.md +1 -3
- package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
- package/bundled/templates/project-memory-template.md +1 -2
- package/package.json +1 -1
- package/src/scaffold.js +28 -7
- package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
- package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
- package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
- package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
- package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
- package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
- package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
- package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
- package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
- package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
- package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
- package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
- package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
- package/bundled/dev-pipeline/tests/conftest.py +0 -29
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
- package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1871
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1314
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1712
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -627
- package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -5641
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -322
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -252
- package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1208
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -957
- package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -303
- package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -5504
- package/bundled/dev-pipeline/tests/test_utils.py +0 -170
- package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
- package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
- package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
- package/bundled/skills/refactor-planner/SKILL.md +0 -467
- package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
- package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
- package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
- package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
- package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
- package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
- package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
- package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
- package/bundled/skills/refactor-workflow/SKILL.md +0 -205
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"""Python foreground runner dispatch for feature
|
|
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,13 @@ from collections.abc import Iterator, Mapping
|
|
|
13
14
|
from contextlib import contextmanager
|
|
14
15
|
from pathlib import Path
|
|
15
16
|
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
17
|
+
from .atomic_io import write_json_atomic, write_text_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
|
-
|
|
22
|
+
_is_generated_task_branch,
|
|
23
|
+
abort_in_progress_git_operation,
|
|
21
24
|
branch_create_plan,
|
|
22
25
|
branch_ensure_return,
|
|
23
26
|
branch_fast_forward_possible,
|
|
@@ -27,24 +30,21 @@ from .gitops import (
|
|
|
27
30
|
default_branch,
|
|
28
31
|
ensure_branch_has_commit,
|
|
29
32
|
ensure_git_repository,
|
|
30
|
-
ensure_linked_worktree,
|
|
31
33
|
local_branch_exists,
|
|
32
|
-
guarded_worktree_remove,
|
|
33
|
-
materialize_worktree_support_assets,
|
|
34
|
-
merge_linked_worktree,
|
|
35
34
|
restore_runtime_wip,
|
|
36
35
|
run_git_command,
|
|
37
36
|
run_git_plan,
|
|
38
|
-
|
|
39
|
-
worktree_save_wip,
|
|
37
|
+
safe_task_branch_prefix,
|
|
40
38
|
)
|
|
41
39
|
from .processes import RuntimeInterruption, describe_interruption, shield_interruption_signals
|
|
40
|
+
from .results import CommandResult
|
|
42
41
|
from .runner_bookkeeping import (
|
|
43
42
|
commit_final_bookkeeping,
|
|
44
43
|
commit_pre_branch_bookkeeping,
|
|
45
44
|
commit_preflight_ready_changes,
|
|
46
45
|
commit_task_branch_changes,
|
|
47
46
|
commit_wip_changes,
|
|
47
|
+
sync_terminal_failure_bookkeeping_to_base,
|
|
48
48
|
)
|
|
49
49
|
from .runner_classification import classify_session, has_branch_completion_evidence, has_completed_artifact_path
|
|
50
50
|
from .runner_models import (
|
|
@@ -67,7 +67,6 @@ from .runner_status import get_next, start_item, status_text, update_item
|
|
|
67
67
|
from .sessions import AISessionConfig, AISessionLauncher, detect_stream_json_support
|
|
68
68
|
from .task_checkout import (
|
|
69
69
|
CHECKOUT_MODE_BRANCH,
|
|
70
|
-
CHECKOUT_MODE_WORKTREE,
|
|
71
70
|
TaskCheckout,
|
|
72
71
|
complete_task_checkout_locked,
|
|
73
72
|
load_task_checkout,
|
|
@@ -98,7 +97,7 @@ def _bridge_sigterm_to_interrupt() -> Iterator[None]:
|
|
|
98
97
|
|
|
99
98
|
|
|
100
99
|
def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], paths) -> CommandResult:
|
|
101
|
-
"""Dispatch a feature
|
|
100
|
+
"""Dispatch a feature or bugfix Python foreground command."""
|
|
102
101
|
family = family_for(kind, paths)
|
|
103
102
|
invocation = parse_invocation(family, action, legacy_args)
|
|
104
103
|
invocation = _resolve_invocation_paths(invocation, paths.project_root)
|
|
@@ -123,7 +122,9 @@ def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], p
|
|
|
123
122
|
with _bridge_sigterm_to_interrupt():
|
|
124
123
|
result = _run_pipeline(family, invocation, paths)
|
|
125
124
|
except Exception as exc: # keep CLI boundary traceback-free
|
|
126
|
-
|
|
125
|
+
detail = str(exc).strip()
|
|
126
|
+
message = f"{type(exc).__name__}: {detail}" if detail else type(exc).__name__
|
|
127
|
+
return CommandResult(1, f"Python {kind} runner failed", message)
|
|
127
128
|
details = result.details + ((f"last_status: {result.last_status}",) if result.last_status else ())
|
|
128
129
|
return CommandResult(
|
|
129
130
|
0 if result.completed or result.last_status == "dry_run" else 1,
|
|
@@ -152,7 +153,17 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
|
|
|
152
153
|
)
|
|
153
154
|
|
|
154
155
|
while True:
|
|
155
|
-
|
|
156
|
+
try:
|
|
157
|
+
next_result = get_next(family, invocation, paths.project_root)
|
|
158
|
+
except KeyboardInterrupt:
|
|
159
|
+
with shield_interruption_signals():
|
|
160
|
+
return PipelineRunResult(
|
|
161
|
+
False,
|
|
162
|
+
processed,
|
|
163
|
+
"interrupted",
|
|
164
|
+
"interrupted",
|
|
165
|
+
_render_item_statuses(item_statuses),
|
|
166
|
+
)
|
|
156
167
|
details = _render_item_statuses(item_statuses)
|
|
157
168
|
if not next_result.ok:
|
|
158
169
|
return PipelineRunResult(False, processed, "get_next_failed", details=(next_result.text,))
|
|
@@ -178,7 +189,7 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
|
|
|
178
189
|
return PipelineRunResult(False, processed, "pipeline_blocked", details=details)
|
|
179
190
|
if not isinstance(next_result.data, dict):
|
|
180
191
|
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
|
|
192
|
+
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
193
|
if not item_id:
|
|
183
194
|
return PipelineRunResult(False, processed, "missing_item_id", details=(marker[:500],))
|
|
184
195
|
if item_id in item_statuses:
|
|
@@ -224,13 +235,11 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
|
|
|
224
235
|
if final_status == "completed":
|
|
225
236
|
_emit_info(f"Pausing 5s before next {family.kind}...")
|
|
226
237
|
continue
|
|
227
|
-
if final_status == "pending":
|
|
228
|
-
continue
|
|
229
238
|
details = _render_item_statuses(item_statuses)
|
|
230
|
-
if
|
|
239
|
+
if _runner_env_for_paths(paths).stop_on_failure:
|
|
231
240
|
return PipelineRunResult(False, processed, "stop_on_failure", final_status, details)
|
|
232
|
-
if final_status
|
|
233
|
-
|
|
241
|
+
if final_status == "pending":
|
|
242
|
+
continue
|
|
234
243
|
|
|
235
244
|
|
|
236
245
|
_COMPLETION_COMPATIBLE_STATUSES = {"completed"}
|
|
@@ -277,35 +286,101 @@ def _emit_warning(message: str) -> None:
|
|
|
277
286
|
|
|
278
287
|
|
|
279
288
|
def _family_label(family: RunnerFamily) -> str:
|
|
280
|
-
return {"feature": "Feature", "bugfix": "Bug"
|
|
289
|
+
return {"feature": "Feature", "bugfix": "Bug"}.get(family.kind, family.kind.title())
|
|
290
|
+
|
|
281
291
|
|
|
292
|
+
def _runner_env_for_paths(paths, config=None) -> RunnerEnvironment:
|
|
293
|
+
env_values = getattr(config, "env_values", None) if config is not None else None
|
|
294
|
+
if isinstance(env_values, Mapping) and env_values:
|
|
295
|
+
return RunnerEnvironment.from_env(env_values)
|
|
296
|
+
prizmkit_dir = getattr(paths, "prizmkit_dir", None)
|
|
297
|
+
if prizmkit_dir is None and hasattr(paths, "project_root"):
|
|
298
|
+
prizmkit_dir = Path(paths.project_root) / ".prizmkit"
|
|
299
|
+
if prizmkit_dir is not None:
|
|
300
|
+
return RunnerEnvironment.from_env(load_env_file(Path(prizmkit_dir) / ".env", os.environ))
|
|
301
|
+
return RunnerEnvironment.from_env()
|
|
282
302
|
|
|
283
|
-
|
|
303
|
+
|
|
304
|
+
def _max_retries(invocation: RunnerInvocation, paths=None) -> int:
|
|
284
305
|
if invocation.max_retries is not None:
|
|
285
306
|
return max(0, invocation.max_retries)
|
|
286
|
-
return RunnerEnvironment.from_env().max_retries
|
|
307
|
+
return _runner_env_for_paths(paths).max_retries if paths is not None else RunnerEnvironment.from_env().max_retries
|
|
287
308
|
|
|
288
309
|
|
|
289
|
-
def _emit_item_header(
|
|
310
|
+
def _emit_item_header(
|
|
311
|
+
family: RunnerFamily,
|
|
312
|
+
invocation: RunnerInvocation,
|
|
313
|
+
item_id: str,
|
|
314
|
+
metadata: dict[str, object],
|
|
315
|
+
paths=None,
|
|
316
|
+
) -> None:
|
|
290
317
|
title = str(metadata.get("title") or metadata.get("description") or "").strip()
|
|
291
318
|
title_text = f" — {title}" if title else ""
|
|
292
319
|
retry_count = int(metadata.get("retry_count") or 0)
|
|
293
320
|
infra_count = int(metadata.get("infra_error_count") or 0)
|
|
294
321
|
_emit_separator()
|
|
295
322
|
_emit_info(f"{_family_label(family)}: {item_id}{title_text}")
|
|
296
|
-
_emit_info(f"Code retry: {retry_count} / {_max_retries(invocation)}")
|
|
323
|
+
_emit_info(f"Code retry: {retry_count} / {_max_retries(invocation, paths)}")
|
|
297
324
|
_emit_info(f"Infrastructure retry: {infra_count} / {invocation.max_infra_retries}")
|
|
298
325
|
_emit_separator()
|
|
299
326
|
|
|
300
327
|
|
|
328
|
+
def _candidate_task_prefixes(family: RunnerFamily) -> tuple[str, ...]:
|
|
329
|
+
base = family.branch_prefix
|
|
330
|
+
return (base, f"prizmkit/{base}", f"prizmkit-{base}")
|
|
331
|
+
|
|
332
|
+
|
|
301
333
|
def _is_recovery_side_effect_branch(branch: str, family: RunnerFamily, item_id: str) -> bool:
|
|
302
|
-
return bool(branch) and
|
|
334
|
+
return bool(branch) and "-recovery-" in branch and any(
|
|
335
|
+
branch.startswith(f"{prefix}/{item_id}-") for prefix in _candidate_task_prefixes(family)
|
|
336
|
+
)
|
|
303
337
|
|
|
304
338
|
|
|
305
339
|
def _is_current_task_branch(branch: str, family: RunnerFamily, item_id: str) -> bool:
|
|
306
340
|
if not branch or _is_recovery_side_effect_branch(branch, family, item_id):
|
|
307
341
|
return False
|
|
308
|
-
return
|
|
342
|
+
return any(
|
|
343
|
+
branch == f"{prefix}/{item_id}" or branch.startswith(f"{prefix}/{item_id}-")
|
|
344
|
+
for prefix in _candidate_task_prefixes(family)
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
_STATUS_RECOVERY_FIELDS = (
|
|
349
|
+
"retry_count",
|
|
350
|
+
"infra_error_count",
|
|
351
|
+
"continuation_pending",
|
|
352
|
+
"continuation_reason",
|
|
353
|
+
"continuation_count",
|
|
354
|
+
"context_overflow_count",
|
|
355
|
+
"previous_session_id",
|
|
356
|
+
"last_context_overflow_session_id",
|
|
357
|
+
"last_progress_fingerprint",
|
|
358
|
+
"no_progress_count",
|
|
359
|
+
"resume_from_phase",
|
|
360
|
+
"current_stage",
|
|
361
|
+
"next_stage",
|
|
362
|
+
"stage_result",
|
|
363
|
+
"repair_scope",
|
|
364
|
+
"repair_round",
|
|
365
|
+
"blocked_reason",
|
|
366
|
+
"terminal_status",
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _backfill_status_recovery_metadata(enriched: dict[str, object], state_dir: Path, item_id: str) -> None:
|
|
371
|
+
status_path = state_dir / item_id / "status.json"
|
|
372
|
+
if not status_path.is_file():
|
|
373
|
+
return
|
|
374
|
+
try:
|
|
375
|
+
status_data = json.loads(status_path.read_text(encoding="utf-8"))
|
|
376
|
+
except (OSError, json.JSONDecodeError):
|
|
377
|
+
return
|
|
378
|
+
if not isinstance(status_data, dict):
|
|
379
|
+
return
|
|
380
|
+
for key in _STATUS_RECOVERY_FIELDS:
|
|
381
|
+
if key not in enriched or enriched[key] in (None, ""):
|
|
382
|
+
if key in status_data and status_data[key] is not None:
|
|
383
|
+
enriched[key] = status_data[key]
|
|
309
384
|
|
|
310
385
|
|
|
311
386
|
def _with_recovery_metadata(
|
|
@@ -315,6 +390,7 @@ def _with_recovery_metadata(
|
|
|
315
390
|
checkout: TaskCheckout | None = None,
|
|
316
391
|
) -> dict[str, object]:
|
|
317
392
|
enriched = dict(metadata)
|
|
393
|
+
_backfill_status_recovery_metadata(enriched, family.state_dir, item_id)
|
|
318
394
|
checkout = checkout or load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
319
395
|
if checkout is not None:
|
|
320
396
|
if checkout.is_active:
|
|
@@ -352,15 +428,36 @@ def _latest_session_status(state_dir: Path, item_id: str) -> dict[str, object]:
|
|
|
352
428
|
|
|
353
429
|
def _resolve_base_branch(project_root: Path, metadata: dict[str, object], active_branch: str, family: RunnerFamily, item_id: str) -> str:
|
|
354
430
|
recorded = str(metadata.get("base_branch") or "").strip()
|
|
355
|
-
if recorded and local_branch_exists(project_root, recorded):
|
|
431
|
+
if recorded and recorded != "HEAD" and local_branch_exists(project_root, recorded):
|
|
356
432
|
return recorded
|
|
433
|
+
active = "" if active_branch == "HEAD" else active_branch
|
|
357
434
|
detected_default = default_branch(project_root)
|
|
358
|
-
if
|
|
359
|
-
|
|
360
|
-
|
|
435
|
+
if detected_default == "HEAD":
|
|
436
|
+
detected_default = ""
|
|
437
|
+
if (
|
|
438
|
+
_is_generated_task_branch(active)
|
|
439
|
+
or _is_current_task_branch(active, family, item_id)
|
|
440
|
+
or _is_recovery_side_effect_branch(active, family, item_id)
|
|
441
|
+
):
|
|
442
|
+
resolved = detected_default
|
|
443
|
+
else:
|
|
444
|
+
resolved = active or detected_default
|
|
445
|
+
if not resolved or resolved == "HEAD":
|
|
446
|
+
raise RuntimeError(
|
|
447
|
+
f"Cannot resolve base branch for {family.kind} task {item_id} from detached HEAD; "
|
|
448
|
+
"check out a named branch before running the pipeline."
|
|
449
|
+
)
|
|
450
|
+
return resolved
|
|
361
451
|
|
|
362
452
|
|
|
363
|
-
def _resolve_working_branch(
|
|
453
|
+
def _resolve_working_branch(
|
|
454
|
+
family: RunnerFamily,
|
|
455
|
+
item_id: str,
|
|
456
|
+
metadata: dict[str, object],
|
|
457
|
+
env: RunnerEnvironment,
|
|
458
|
+
active_branch: str,
|
|
459
|
+
project_root: Path | None = None,
|
|
460
|
+
) -> str:
|
|
364
461
|
recorded = str(metadata.get("active_dev_branch") or "").strip()
|
|
365
462
|
if recorded and not _is_recovery_side_effect_branch(recorded, family, item_id):
|
|
366
463
|
return recorded
|
|
@@ -368,7 +465,8 @@ def _resolve_working_branch(family: RunnerFamily, item_id: str, metadata: dict[s
|
|
|
368
465
|
return env.dev_branch
|
|
369
466
|
if _is_current_task_branch(active_branch, family, item_id):
|
|
370
467
|
return active_branch
|
|
371
|
-
|
|
468
|
+
prefix = safe_task_branch_prefix(project_root, family.branch_prefix) if project_root is not None else family.branch_prefix
|
|
469
|
+
return _default_branch_name(family, item_id, prefix=prefix)
|
|
372
470
|
|
|
373
471
|
|
|
374
472
|
def _emit_branch_setup_result(branch_context: BranchContext, result) -> None:
|
|
@@ -379,8 +477,6 @@ def _emit_branch_setup_result(branch_context: BranchContext, result) -> None:
|
|
|
379
477
|
_emit_info(f"Created and checked out branch: {branch_context.working_branch} (from {branch_context.base_branch})")
|
|
380
478
|
elif reused:
|
|
381
479
|
_emit_info(f"Reusing branch: {branch_context.working_branch} (from {branch_context.base_branch})")
|
|
382
|
-
else:
|
|
383
|
-
_emit_info(f"Dev branch: {branch_context.working_branch}")
|
|
384
480
|
_emit_info(f"Dev branch: {branch_context.working_branch}")
|
|
385
481
|
|
|
386
482
|
|
|
@@ -506,6 +602,39 @@ def _process_item(
|
|
|
506
602
|
raise
|
|
507
603
|
|
|
508
604
|
|
|
605
|
+
def _validate_effort_config(config) -> None:
|
|
606
|
+
effort_validation = getattr(config, "effort_validation", None)
|
|
607
|
+
if effort_validation is not None and not effort_validation.valid:
|
|
608
|
+
raise RuntimeError(effort_validation.message)
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def _resolve_stream_json_support(config) -> bool:
|
|
612
|
+
if getattr(config.ai_client, "launch_profile", None) is not None:
|
|
613
|
+
return False
|
|
614
|
+
stream_support = detect_stream_json_support(config.ai_client.command, config.ai_client.platform)
|
|
615
|
+
enabled = bool(getattr(stream_support, "enabled", False))
|
|
616
|
+
notes = getattr(stream_support, "notes", ()) or ()
|
|
617
|
+
if config.ai_client.platform == "cursor" and not enabled:
|
|
618
|
+
details = "; ".join(notes) or "required stream-json flags were not found"
|
|
619
|
+
raise RuntimeError(
|
|
620
|
+
"Cursor Agent CLI is incompatible with PrizmKit headless execution: "
|
|
621
|
+
f"{details}. Install or update Cursor Agent and verify `agent --help`."
|
|
622
|
+
)
|
|
623
|
+
if config.ai_client.platform == "antigravity" and not enabled:
|
|
624
|
+
details = "; ".join(notes) or "required stream-json flags were not found"
|
|
625
|
+
raise RuntimeError(
|
|
626
|
+
"Antigravity CLI is incompatible with PrizmKit headless execution: "
|
|
627
|
+
f"{details}. Install or update Antigravity CLI (`agy`) and verify `agy --help`."
|
|
628
|
+
)
|
|
629
|
+
return enabled
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
def _bookkeeping_list_kwargs(family: RunnerFamily, invocation: RunnerInvocation) -> dict[str, Path]:
|
|
633
|
+
if invocation.list_path != family.plan_path:
|
|
634
|
+
return {"list_path": invocation.list_path}
|
|
635
|
+
return {}
|
|
636
|
+
|
|
637
|
+
|
|
509
638
|
def _preview_item(
|
|
510
639
|
family: RunnerFamily,
|
|
511
640
|
invocation: RunnerInvocation,
|
|
@@ -517,12 +646,11 @@ def _preview_item(
|
|
|
517
646
|
config = load_runtime_config(paths)
|
|
518
647
|
if not config.ai_client.command:
|
|
519
648
|
raise RuntimeError("No supported AI CLI command was found")
|
|
520
|
-
|
|
521
|
-
raise RuntimeError(config.effort_validation.message)
|
|
649
|
+
_validate_effort_config(config)
|
|
522
650
|
metadata = _with_recovery_metadata(family, item_id, initial_metadata)
|
|
523
651
|
retry_count = int(metadata.get("retry_count") or 0)
|
|
524
652
|
session_id = f"{item_id}-dry-run"
|
|
525
|
-
_emit_item_header(family, invocation, item_id, metadata)
|
|
653
|
+
_emit_item_header(family, invocation, item_id, metadata, paths)
|
|
526
654
|
with tempfile.TemporaryDirectory(prefix="prizmkit-dry-run-") as temporary:
|
|
527
655
|
session_paths = SessionPaths.for_item(Path(temporary), item_id, session_id)
|
|
528
656
|
prompt = generate_prompt(
|
|
@@ -554,12 +682,12 @@ def _process_item_locked(
|
|
|
554
682
|
*,
|
|
555
683
|
initial_metadata: dict[str, object],
|
|
556
684
|
) -> str:
|
|
557
|
-
env = RunnerEnvironment.from_env()
|
|
558
685
|
config = load_runtime_config(paths)
|
|
686
|
+
env = _runner_env_for_paths(paths, config)
|
|
559
687
|
if not config.ai_client.command:
|
|
560
688
|
raise RuntimeError("No supported AI CLI command was found")
|
|
561
|
-
|
|
562
|
-
|
|
689
|
+
_validate_effort_config(config)
|
|
690
|
+
stream_json = _resolve_stream_json_support(config)
|
|
563
691
|
|
|
564
692
|
repository = ensure_git_repository(paths.project_root)
|
|
565
693
|
if repository.return_code != 0:
|
|
@@ -575,16 +703,12 @@ def _process_item_locked(
|
|
|
575
703
|
raise RuntimeError(f"Task {item_id} is completed; run explicit reset or clean before rerunning")
|
|
576
704
|
metadata = _with_recovery_metadata(family, item_id, initial_metadata, checkout)
|
|
577
705
|
base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
|
|
578
|
-
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch)
|
|
706
|
+
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch, paths.project_root)
|
|
579
707
|
branch_context = BranchContext(base_branch, branch_name, paths.project_root)
|
|
580
|
-
|
|
708
|
+
initial_branch_ref_existed = bool(
|
|
709
|
+
active_branch and active_branch != "HEAD" and local_branch_exists(paths.project_root, active_branch)
|
|
710
|
+
)
|
|
581
711
|
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
712
|
execution_root = paths.project_root
|
|
589
713
|
session_id = ""
|
|
590
714
|
session_paths: SessionPaths | None = None
|
|
@@ -613,10 +737,14 @@ def _process_item_locked(
|
|
|
613
737
|
raise RuntimeError(f"Cannot create the initial commit before {family.kind} task {item_id}: {first}")
|
|
614
738
|
if born.args and born.args[0] == "commit":
|
|
615
739
|
_emit_info(f"Git: created initial commit before {family.kind} task {item_id}")
|
|
740
|
+
if (not initial_branch_ref_existed or not local_branch_exists(paths.project_root, base_branch)) and (
|
|
741
|
+
preflight.committed or (born.args and born.args[0] == "commit")
|
|
742
|
+
):
|
|
616
743
|
active_branch = current_branch(paths.project_root)
|
|
617
744
|
if not local_branch_exists(paths.project_root, base_branch):
|
|
618
745
|
base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
|
|
619
|
-
|
|
746
|
+
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch, paths.project_root)
|
|
747
|
+
branch_context = BranchContext(base_branch, branch_name, paths.project_root)
|
|
620
748
|
|
|
621
749
|
if (
|
|
622
750
|
checkout is not None
|
|
@@ -629,54 +757,50 @@ def _process_item_locked(
|
|
|
629
757
|
checkout = replace_missing_recorded_base_locked(family.state_dir, checkout, base_branch)
|
|
630
758
|
_emit_info(f"Checkout: recorded base {previous_base} is missing; using {base_branch}")
|
|
631
759
|
|
|
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
760
|
checkout_candidate = TaskCheckout.active(
|
|
645
761
|
family.task_type,
|
|
646
762
|
item_id,
|
|
647
763
|
branch_name,
|
|
648
764
|
base_branch,
|
|
649
|
-
checkout_mode=
|
|
650
|
-
worktree_path=str(worktree_runtime.worktree_path) if worktree_runtime is not None else "",
|
|
765
|
+
checkout_mode=CHECKOUT_MODE_BRANCH,
|
|
651
766
|
)
|
|
652
767
|
checkout = reserve_task_checkout_locked(family.state_dir, checkout_candidate)
|
|
653
768
|
_emit_info(f"Checkout: reserved task identity at {family.state_dir / item_id / 'checkout.json'}")
|
|
654
769
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
770
|
+
base_bookkeeping_snapshots: dict[Path, str] = {}
|
|
771
|
+
if reusing_checkout and active_branch != branch_name:
|
|
772
|
+
for candidate in (invocation.list_path, family.state_dir / item_id / "status.json"):
|
|
773
|
+
if candidate.is_file():
|
|
774
|
+
try:
|
|
775
|
+
base_bookkeeping_snapshots[candidate] = candidate.read_text(encoding="utf-8")
|
|
776
|
+
except OSError:
|
|
777
|
+
pass
|
|
778
|
+
|
|
779
|
+
branch_result = run_git_plan(paths.project_root, branch_create_plan(branch_context))
|
|
780
|
+
_emit_branch_setup_result(branch_context, branch_result)
|
|
781
|
+
if not branch_result.ok:
|
|
782
|
+
_emit_git_plan_output(branch_result)
|
|
783
|
+
if invocation.list_path.is_file():
|
|
784
|
+
update = update_item(
|
|
665
785
|
family,
|
|
666
786
|
invocation,
|
|
667
787
|
item_id,
|
|
788
|
+
"infra_error",
|
|
789
|
+
"",
|
|
668
790
|
paths.project_root,
|
|
669
|
-
|
|
670
|
-
base_branch,
|
|
671
|
-
branch_name,
|
|
672
|
-
worktree_runtime=worktree_runtime,
|
|
791
|
+
active_dev_branch=branch_name,
|
|
792
|
+
base_branch=base_branch,
|
|
673
793
|
)
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
794
|
+
if update.ok:
|
|
795
|
+
commit_final_bookkeeping(
|
|
796
|
+
paths.project_root,
|
|
797
|
+
family,
|
|
798
|
+
item_id,
|
|
799
|
+
_status_from_update(update),
|
|
800
|
+
**_bookkeeping_list_kwargs(family, invocation),
|
|
801
|
+
)
|
|
802
|
+
return _status_from_update(update)
|
|
803
|
+
return "infra_error"
|
|
680
804
|
|
|
681
805
|
if reusing_checkout:
|
|
682
806
|
restored_wip = restore_runtime_wip(
|
|
@@ -698,7 +822,6 @@ def _process_item_locked(
|
|
|
698
822
|
execution_root,
|
|
699
823
|
base_branch,
|
|
700
824
|
branch_name,
|
|
701
|
-
worktree_runtime=worktree_runtime,
|
|
702
825
|
)
|
|
703
826
|
if restored_wip.restored:
|
|
704
827
|
_emit_info(
|
|
@@ -707,13 +830,37 @@ def _process_item_locked(
|
|
|
707
830
|
)
|
|
708
831
|
else:
|
|
709
832
|
_emit_info(f"Recovery: no Runtime-owned WIP tip to restore for {item_id}")
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
833
|
+
for snapshot_path, expected_text in base_bookkeeping_snapshots.items():
|
|
834
|
+
current_text = None
|
|
835
|
+
if snapshot_path.is_file():
|
|
836
|
+
try:
|
|
837
|
+
current_text = snapshot_path.read_text(encoding="utf-8")
|
|
838
|
+
except OSError:
|
|
839
|
+
current_text = None
|
|
840
|
+
if current_text != expected_text:
|
|
841
|
+
write_text_atomic(snapshot_path, expected_text)
|
|
842
|
+
|
|
843
|
+
_emit_item_header(family, invocation, item_id, metadata, paths)
|
|
844
|
+
status_root = paths.project_root
|
|
845
|
+
status_family = family
|
|
846
|
+
status_invocation = invocation
|
|
715
847
|
recovered_session_id = _latest_session_id(family.state_dir, item_id)
|
|
716
848
|
recovery_artifact = _artifact_path_for_item(execution_root, family, item_id, metadata)
|
|
849
|
+
recovery_checkpoint = recovery_artifact / "workflow-checkpoint.json"
|
|
850
|
+
recovery_request = recovery_artifact / REQUEST_FILENAME
|
|
851
|
+
if recovery_checkpoint.is_file() and (
|
|
852
|
+
recovery_request.is_file()
|
|
853
|
+
or load_checkpoint_state(recovery_checkpoint, project_root=execution_root).semantic_commit_ready
|
|
854
|
+
):
|
|
855
|
+
pending_commit = finalize_runtime_commit(
|
|
856
|
+
execution_root,
|
|
857
|
+
artifact_dir=recovery_artifact,
|
|
858
|
+
checkpoint_path=recovery_checkpoint,
|
|
859
|
+
)
|
|
860
|
+
if pending_commit.committed:
|
|
861
|
+
_emit_success(f"Recovery: finalized pending Runtime commit {pending_commit.commit_hash}")
|
|
862
|
+
elif pending_commit.status == "failed":
|
|
863
|
+
_emit_warning(f"Recovery: pending Runtime commit failed ({pending_commit.reason})")
|
|
717
864
|
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
865
|
session_paths = SessionPaths.for_item(family.state_dir, item_id, recovered_session_id)
|
|
719
866
|
_write_session_status(
|
|
@@ -724,7 +871,6 @@ def _process_item_locked(
|
|
|
724
871
|
task_type=family.task_type,
|
|
725
872
|
base_branch=base_branch,
|
|
726
873
|
active_dev_branch=branch_name,
|
|
727
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
728
874
|
reason="completed_branch_recovered_from_late_runtime_error",
|
|
729
875
|
)
|
|
730
876
|
return _finalize_recovered_success(
|
|
@@ -740,12 +886,16 @@ def _process_item_locked(
|
|
|
740
886
|
base_branch,
|
|
741
887
|
recovered_session_id,
|
|
742
888
|
session_paths,
|
|
743
|
-
worktree_runtime,
|
|
744
889
|
)
|
|
745
890
|
start = start_item(status_family, status_invocation, item_id, status_root)
|
|
746
891
|
if not start.ok:
|
|
747
892
|
raise RuntimeError(start.text)
|
|
748
|
-
commit_pre_branch_bookkeeping(
|
|
893
|
+
commit_pre_branch_bookkeeping(
|
|
894
|
+
status_root,
|
|
895
|
+
status_family,
|
|
896
|
+
item_id,
|
|
897
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
898
|
+
)
|
|
749
899
|
|
|
750
900
|
previous_fingerprint = metadata.get("last_progress_fingerprint")
|
|
751
901
|
previous_no_progress_count = int(metadata.get("no_progress_count") or 0)
|
|
@@ -769,7 +919,7 @@ def _process_item_locked(
|
|
|
769
919
|
"context_overflow_count": context_overflow_count,
|
|
770
920
|
"retry_count": retry_count,
|
|
771
921
|
"infra_error_count": infra_error_count,
|
|
772
|
-
"max_retries": _max_retries(invocation),
|
|
922
|
+
"max_retries": _max_retries(invocation, paths),
|
|
773
923
|
"max_infra_retries": invocation.max_infra_retries,
|
|
774
924
|
"no_progress_count": previous_no_progress_count,
|
|
775
925
|
"progress_fingerprint": previous_fingerprint or {},
|
|
@@ -784,7 +934,9 @@ def _process_item_locked(
|
|
|
784
934
|
"task_type": family.task_type,
|
|
785
935
|
"active_dev_branch": branch_name,
|
|
786
936
|
"base_branch": base_branch,
|
|
787
|
-
"continuation_summary_path": _continuation_summary_path(
|
|
937
|
+
"continuation_summary_path": _continuation_summary_path(
|
|
938
|
+
execution_root, family, item_id, None, metadata=metadata
|
|
939
|
+
),
|
|
788
940
|
}
|
|
789
941
|
prompt = generate_prompt(
|
|
790
942
|
family,
|
|
@@ -799,22 +951,6 @@ def _process_item_locked(
|
|
|
799
951
|
continuation=continuation,
|
|
800
952
|
)
|
|
801
953
|
_emit_prompt_summary(prompt, session_id)
|
|
802
|
-
stream_json = False
|
|
803
|
-
if getattr(config.ai_client, "launch_profile", None) is None:
|
|
804
|
-
stream_support = detect_stream_json_support(config.ai_client.command, config.ai_client.platform)
|
|
805
|
-
stream_json = stream_support.enabled
|
|
806
|
-
if config.ai_client.platform == "cursor" and not stream_json:
|
|
807
|
-
details = "; ".join(stream_support.notes) or "required stream-json flags were not found"
|
|
808
|
-
raise RuntimeError(
|
|
809
|
-
"Cursor Agent CLI is incompatible with PrizmKit headless execution: "
|
|
810
|
-
f"{details}. Install or update Cursor Agent and verify `agent --help`."
|
|
811
|
-
)
|
|
812
|
-
if config.ai_client.platform == "antigravity" and not stream_json:
|
|
813
|
-
details = "; ".join(stream_support.notes) or "required stream-json flags were not found"
|
|
814
|
-
raise RuntimeError(
|
|
815
|
-
"Antigravity CLI is incompatible with PrizmKit headless execution: "
|
|
816
|
-
f"{details}. Install or update Antigravity CLI (`agy`) and verify `agy --help`."
|
|
817
|
-
)
|
|
818
954
|
base_head = run_git_command(execution_root, ("rev-parse", "HEAD")).stdout.strip()
|
|
819
955
|
session_result = AISessionLauncher(
|
|
820
956
|
AISessionConfig(
|
|
@@ -850,6 +986,7 @@ def _process_item_locked(
|
|
|
850
986
|
prompt=prompt,
|
|
851
987
|
previous_fingerprint=previous_fingerprint,
|
|
852
988
|
previous_no_progress_count=previous_no_progress_count,
|
|
989
|
+
stream_json=stream_json,
|
|
853
990
|
)
|
|
854
991
|
if runtime_commit.status == "failed":
|
|
855
992
|
classification = SessionClassification(
|
|
@@ -875,7 +1012,9 @@ def _process_item_locked(
|
|
|
875
1012
|
)
|
|
876
1013
|
_emit_session_summary(session_result, session_paths, classification)
|
|
877
1014
|
final_session_status = classification.session_status
|
|
878
|
-
summary_path = _continuation_summary_path(
|
|
1015
|
+
summary_path = _continuation_summary_path(
|
|
1016
|
+
execution_root, family, item_id, prompt, metadata=metadata
|
|
1017
|
+
)
|
|
879
1018
|
|
|
880
1019
|
_write_session_status(
|
|
881
1020
|
session_paths,
|
|
@@ -885,7 +1024,6 @@ def _process_item_locked(
|
|
|
885
1024
|
task_type=family.task_type,
|
|
886
1025
|
base_branch=base_branch,
|
|
887
1026
|
active_dev_branch=branch_name,
|
|
888
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
889
1027
|
reason=classification.reason,
|
|
890
1028
|
fatal_error_code=classification.fatal_error_code,
|
|
891
1029
|
checkpoint_state=classification.checkpoint_state,
|
|
@@ -932,15 +1070,37 @@ def _process_item_locked(
|
|
|
932
1070
|
|
|
933
1071
|
accepted_with_warning = accepted_with_warning and new_status == "completed"
|
|
934
1072
|
if final_session_status != "success" and not accepted_with_warning:
|
|
935
|
-
|
|
936
|
-
|
|
1073
|
+
failure_bookkeeping = _capture_terminal_failure_bookkeeping(
|
|
1074
|
+
status_family,
|
|
1075
|
+
status_invocation,
|
|
1076
|
+
item_id,
|
|
1077
|
+
new_status,
|
|
1078
|
+
update_data,
|
|
1079
|
+
)
|
|
1080
|
+
commit_final_bookkeeping(
|
|
1081
|
+
status_root,
|
|
1082
|
+
status_family,
|
|
1083
|
+
item_id,
|
|
1084
|
+
new_status,
|
|
1085
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1086
|
+
)
|
|
1087
|
+
wip = _save_failure_wip(execution_root, family, item_id, new_status)
|
|
937
1088
|
if not getattr(wip, "ok", True):
|
|
938
1089
|
_emit_warning(f"WIP preservation failed for {item_id}; leaving the task checkout active")
|
|
939
1090
|
return new_status
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1091
|
+
returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
|
|
1092
|
+
if not getattr(returned, "ok", True):
|
|
1093
|
+
_emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
|
|
1094
|
+
elif failure_bookkeeping:
|
|
1095
|
+
synced = sync_terminal_failure_bookkeeping_to_base(
|
|
1096
|
+
status_root,
|
|
1097
|
+
status_family,
|
|
1098
|
+
item_id,
|
|
1099
|
+
new_status,
|
|
1100
|
+
failure_bookkeeping,
|
|
1101
|
+
)
|
|
1102
|
+
if synced.attempted and not synced.ok:
|
|
1103
|
+
_emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
|
|
944
1104
|
return new_status
|
|
945
1105
|
|
|
946
1106
|
completed_status = _complete_success_merge(
|
|
@@ -957,7 +1117,6 @@ def _process_item_locked(
|
|
|
957
1117
|
base_branch,
|
|
958
1118
|
session_id,
|
|
959
1119
|
session_paths,
|
|
960
|
-
worktree_runtime,
|
|
961
1120
|
classification_fatal_error_code=classification.fatal_error_code,
|
|
962
1121
|
)
|
|
963
1122
|
if accepted_with_warning and completed_status == "completed":
|
|
@@ -969,25 +1128,26 @@ def _process_item_locked(
|
|
|
969
1128
|
)
|
|
970
1129
|
return completed_status
|
|
971
1130
|
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
1131
|
with shield_interruption_signals():
|
|
1132
|
+
try:
|
|
1133
|
+
_emit_task_interruption_diagnostics(
|
|
1134
|
+
interruption,
|
|
1135
|
+
family=family,
|
|
1136
|
+
invocation=invocation,
|
|
1137
|
+
item_id=item_id,
|
|
1138
|
+
session_id=session_id,
|
|
1139
|
+
session_paths=session_paths,
|
|
1140
|
+
retry_count=retry_count,
|
|
1141
|
+
infra_error_count=infra_error_count,
|
|
1142
|
+
branch_name=branch_name,
|
|
1143
|
+
base_branch=base_branch,
|
|
1144
|
+
paths=paths,
|
|
1145
|
+
)
|
|
1146
|
+
except Exception as diagnostic_error:
|
|
1147
|
+
_emit_warning(
|
|
1148
|
+
f"Interrupt diagnostic collection failed ({type(diagnostic_error).__name__}); "
|
|
1149
|
+
"continuing existing WIP preservation and checkout recovery behavior"
|
|
1150
|
+
)
|
|
991
1151
|
_cleanup_interrupted_task(
|
|
992
1152
|
item_id=item_id,
|
|
993
1153
|
paths=paths,
|
|
@@ -995,7 +1155,7 @@ def _process_item_locked(
|
|
|
995
1155
|
base_branch=base_branch,
|
|
996
1156
|
branch_name=branch_name,
|
|
997
1157
|
)
|
|
998
|
-
|
|
1158
|
+
raise
|
|
999
1159
|
|
|
1000
1160
|
|
|
1001
1161
|
def _emit_task_interruption_diagnostics(
|
|
@@ -1010,6 +1170,7 @@ def _emit_task_interruption_diagnostics(
|
|
|
1010
1170
|
infra_error_count: int | None,
|
|
1011
1171
|
branch_name: str,
|
|
1012
1172
|
base_branch: str,
|
|
1173
|
+
paths=None,
|
|
1013
1174
|
) -> None:
|
|
1014
1175
|
"""Emit task-level interruption context without mutating pipeline state."""
|
|
1015
1176
|
details = describe_interruption(interruption)
|
|
@@ -1031,7 +1192,7 @@ def _emit_task_interruption_diagnostics(
|
|
|
1031
1192
|
f"phase={phase}; tool={tool}; branch={branch_name}; base={base_branch}"
|
|
1032
1193
|
)
|
|
1033
1194
|
_emit_warning(
|
|
1034
|
-
f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation)}; "
|
|
1195
|
+
f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation, paths)}; "
|
|
1035
1196
|
f"infrastructure={infra_retry}/{invocation.max_infra_retries}"
|
|
1036
1197
|
)
|
|
1037
1198
|
_emit_warning(
|
|
@@ -1050,6 +1211,7 @@ def _cleanup_interrupted_task(
|
|
|
1050
1211
|
) -> None:
|
|
1051
1212
|
"""Commit interrupted task WIP, then leave the caller checkout on its base branch."""
|
|
1052
1213
|
_emit_warning(f"Interrupted while processing {item_id}; preserving task WIP before base return")
|
|
1214
|
+
abort_in_progress_git_operation(execution_root)
|
|
1053
1215
|
execution_branch = current_branch(execution_root)
|
|
1054
1216
|
if execution_root.resolve() == paths.project_root.resolve() and execution_branch == base_branch:
|
|
1055
1217
|
preserved = None
|
|
@@ -1192,7 +1354,6 @@ def _finalize_recovered_success(
|
|
|
1192
1354
|
base_branch: str,
|
|
1193
1355
|
session_id: str,
|
|
1194
1356
|
session_paths: SessionPaths,
|
|
1195
|
-
worktree_runtime,
|
|
1196
1357
|
) -> str:
|
|
1197
1358
|
update = update_item(
|
|
1198
1359
|
status_family,
|
|
@@ -1221,11 +1382,63 @@ def _finalize_recovered_success(
|
|
|
1221
1382
|
base_branch,
|
|
1222
1383
|
session_id,
|
|
1223
1384
|
session_paths,
|
|
1224
|
-
worktree_runtime,
|
|
1225
1385
|
classification_fatal_error_code="",
|
|
1226
1386
|
)
|
|
1227
1387
|
|
|
1228
1388
|
|
|
1389
|
+
def _patch_completion_notes_if_present(
|
|
1390
|
+
execution_root: Path,
|
|
1391
|
+
paths,
|
|
1392
|
+
status_root: Path,
|
|
1393
|
+
status_family: RunnerFamily,
|
|
1394
|
+
status_invocation: RunnerInvocation,
|
|
1395
|
+
item_id: str,
|
|
1396
|
+
) -> None:
|
|
1397
|
+
summary_file = _artifact_path_for_item(execution_root, status_family, item_id, {}) / "completion-summary.json"
|
|
1398
|
+
pipeline_root = getattr(paths, "pipeline_root", None)
|
|
1399
|
+
if pipeline_root is None or not summary_file.is_file() or not status_invocation.list_path.is_file():
|
|
1400
|
+
return
|
|
1401
|
+
patch_script = Path(pipeline_root) / "scripts" / "patch-completion-notes.py"
|
|
1402
|
+
if not patch_script.is_file():
|
|
1403
|
+
return
|
|
1404
|
+
completed = subprocess.run(
|
|
1405
|
+
[
|
|
1406
|
+
sys.executable,
|
|
1407
|
+
str(patch_script),
|
|
1408
|
+
status_family.list_arg,
|
|
1409
|
+
str(status_invocation.list_path),
|
|
1410
|
+
status_family.item_id_arg,
|
|
1411
|
+
item_id,
|
|
1412
|
+
"--summary",
|
|
1413
|
+
str(summary_file),
|
|
1414
|
+
],
|
|
1415
|
+
cwd=str(status_root),
|
|
1416
|
+
stdout=subprocess.PIPE,
|
|
1417
|
+
stderr=subprocess.PIPE,
|
|
1418
|
+
text=True,
|
|
1419
|
+
encoding="utf-8",
|
|
1420
|
+
errors="replace",
|
|
1421
|
+
check=False,
|
|
1422
|
+
)
|
|
1423
|
+
if completed.returncode != 0:
|
|
1424
|
+
detail = (completed.stderr or completed.stdout).strip()
|
|
1425
|
+
_emit_warning(
|
|
1426
|
+
f"Could not patch completion_notes for {item_id} (exit={completed.returncode})"
|
|
1427
|
+
+ (f": {detail.splitlines()[0][:240]}" if detail else "")
|
|
1428
|
+
)
|
|
1429
|
+
return
|
|
1430
|
+
notes_count = None
|
|
1431
|
+
if (completed.stdout or "").strip():
|
|
1432
|
+
try:
|
|
1433
|
+
notes_count = json.loads(completed.stdout).get("notes_count")
|
|
1434
|
+
except (ValueError, json.JSONDecodeError, AttributeError):
|
|
1435
|
+
notes_count = None
|
|
1436
|
+
if notes_count:
|
|
1437
|
+
_emit_info(f"Patched {notes_count} completion note(s) for {item_id}")
|
|
1438
|
+
else:
|
|
1439
|
+
_emit_info(f"Checked completion-summary.json for {item_id}; no non-empty completion notes patched")
|
|
1440
|
+
|
|
1441
|
+
|
|
1229
1442
|
def _complete_success_merge(
|
|
1230
1443
|
family: RunnerFamily,
|
|
1231
1444
|
item_id: str,
|
|
@@ -1240,12 +1453,26 @@ def _complete_success_merge(
|
|
|
1240
1453
|
base_branch: str,
|
|
1241
1454
|
session_id: str,
|
|
1242
1455
|
session_paths: SessionPaths,
|
|
1243
|
-
worktree_runtime,
|
|
1244
1456
|
*,
|
|
1245
1457
|
classification_fatal_error_code: str = "",
|
|
1246
1458
|
) -> str:
|
|
1247
|
-
env =
|
|
1248
|
-
|
|
1459
|
+
env = _runner_env_for_paths(paths)
|
|
1460
|
+
if new_status == "completed":
|
|
1461
|
+
_patch_completion_notes_if_present(
|
|
1462
|
+
execution_root,
|
|
1463
|
+
paths,
|
|
1464
|
+
status_root,
|
|
1465
|
+
status_family,
|
|
1466
|
+
status_invocation,
|
|
1467
|
+
item_id,
|
|
1468
|
+
)
|
|
1469
|
+
final_bookkeeping = commit_final_bookkeeping(
|
|
1470
|
+
status_root,
|
|
1471
|
+
status_family,
|
|
1472
|
+
item_id,
|
|
1473
|
+
new_status,
|
|
1474
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1475
|
+
)
|
|
1249
1476
|
task_commit = commit_task_branch_changes(execution_root, family, item_id, new_status)
|
|
1250
1477
|
finalization_committed = getattr(final_bookkeeping, "ok", True) and getattr(task_commit, "ok", True)
|
|
1251
1478
|
if not finalization_committed:
|
|
@@ -1258,7 +1485,6 @@ def _complete_success_merge(
|
|
|
1258
1485
|
task_type=family.task_type,
|
|
1259
1486
|
base_branch=base_branch,
|
|
1260
1487
|
active_dev_branch=branch_name,
|
|
1261
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
1262
1488
|
reason="commit_missing",
|
|
1263
1489
|
fatal_error_code=classification_fatal_error_code,
|
|
1264
1490
|
)
|
|
@@ -1277,42 +1503,43 @@ def _complete_success_merge(
|
|
|
1277
1503
|
raise RuntimeError(update.text)
|
|
1278
1504
|
_emit_update_summary(family, item_id, update)
|
|
1279
1505
|
commit_missing_status = _status_from_update(update)
|
|
1280
|
-
commit_final_bookkeeping(
|
|
1281
|
-
|
|
1506
|
+
commit_final_bookkeeping(
|
|
1507
|
+
status_root,
|
|
1508
|
+
status_family,
|
|
1509
|
+
item_id,
|
|
1510
|
+
commit_missing_status,
|
|
1511
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1512
|
+
)
|
|
1513
|
+
_save_failure_wip(execution_root, family, item_id, commit_missing_status)
|
|
1282
1514
|
return commit_missing_status
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
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(
|
|
1515
|
+
|
|
1516
|
+
_emit_info(f"Merging {branch_name} into {base_branch}...")
|
|
1517
|
+
merge = run_git_plan(
|
|
1518
|
+
paths.project_root,
|
|
1519
|
+
branch_merge_plan(
|
|
1520
|
+
branch_context,
|
|
1521
|
+
auto_push=env.auto_push,
|
|
1522
|
+
rebase=not branch_fast_forward_possible(
|
|
1523
|
+
paths.project_root,
|
|
1300
1524
|
branch_context,
|
|
1301
|
-
auto_push=env.auto_push,
|
|
1302
|
-
rebase=not branch_fast_forward_possible(
|
|
1303
|
-
paths.project_root,
|
|
1304
|
-
branch_context,
|
|
1305
|
-
),
|
|
1306
1525
|
),
|
|
1307
|
-
)
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1526
|
+
),
|
|
1527
|
+
)
|
|
1528
|
+
_emit_git_plan_output(merge)
|
|
1529
|
+
if merge.ok:
|
|
1530
|
+
checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
1531
|
+
if checkout is None:
|
|
1532
|
+
raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
|
|
1533
|
+
complete_task_checkout_locked(family.state_dir, checkout)
|
|
1534
|
+
_emit_success(f"Merged {branch_name} into {base_branch}")
|
|
1535
|
+
return new_status
|
|
1536
|
+
abort_in_progress_git_operation(paths.project_root)
|
|
1537
|
+
_emit_warning(
|
|
1538
|
+
f"Merge failed for {item_id} ({branch_name} -> {base_branch}); "
|
|
1539
|
+
"aborted in-progress git operation and recorded merge_conflict"
|
|
1540
|
+
)
|
|
1541
|
+
if current_branch(paths.project_root) == base_branch and branch_name and local_branch_exists(paths.project_root, branch_name):
|
|
1542
|
+
run_git_command(paths.project_root, ("checkout", branch_name))
|
|
1316
1543
|
|
|
1317
1544
|
_write_session_status(
|
|
1318
1545
|
session_paths,
|
|
@@ -1322,7 +1549,6 @@ def _complete_success_merge(
|
|
|
1322
1549
|
task_type=family.task_type,
|
|
1323
1550
|
base_branch=base_branch,
|
|
1324
1551
|
active_dev_branch=branch_name,
|
|
1325
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
1326
1552
|
reason="merge_conflict",
|
|
1327
1553
|
fatal_error_code=classification_fatal_error_code,
|
|
1328
1554
|
)
|
|
@@ -1341,22 +1567,94 @@ def _complete_success_merge(
|
|
|
1341
1567
|
raise RuntimeError(update.text)
|
|
1342
1568
|
_emit_update_summary(family, item_id, update)
|
|
1343
1569
|
merged_status = _status_from_update(update)
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1570
|
+
update_data = update.data if isinstance(update.data, dict) else {}
|
|
1571
|
+
failure_bookkeeping = _capture_terminal_failure_bookkeeping(
|
|
1572
|
+
status_family,
|
|
1573
|
+
status_invocation,
|
|
1574
|
+
item_id,
|
|
1575
|
+
merged_status,
|
|
1576
|
+
update_data,
|
|
1577
|
+
)
|
|
1578
|
+
if current_branch(paths.project_root) == branch_name or not local_branch_exists(paths.project_root, branch_name):
|
|
1579
|
+
commit_final_bookkeeping(
|
|
1580
|
+
status_root,
|
|
1581
|
+
status_family,
|
|
1582
|
+
item_id,
|
|
1583
|
+
merged_status,
|
|
1584
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1585
|
+
)
|
|
1586
|
+
wip = _save_failure_wip(execution_root, family, item_id, merged_status)
|
|
1587
|
+
if getattr(wip, "ok", True):
|
|
1588
|
+
returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
|
|
1589
|
+
if not returned.ok:
|
|
1590
|
+
_emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
|
|
1591
|
+
elif failure_bookkeeping:
|
|
1592
|
+
synced = sync_terminal_failure_bookkeeping_to_base(
|
|
1593
|
+
status_root,
|
|
1594
|
+
status_family,
|
|
1595
|
+
item_id,
|
|
1596
|
+
merged_status,
|
|
1597
|
+
failure_bookkeeping,
|
|
1598
|
+
)
|
|
1599
|
+
if synced.attempted and not synced.ok:
|
|
1600
|
+
_emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
|
|
1601
|
+
elif failure_bookkeeping and current_branch(paths.project_root) == base_branch:
|
|
1602
|
+
synced = sync_terminal_failure_bookkeeping_to_base(
|
|
1603
|
+
status_root,
|
|
1604
|
+
status_family,
|
|
1605
|
+
item_id,
|
|
1606
|
+
merged_status,
|
|
1607
|
+
failure_bookkeeping,
|
|
1608
|
+
)
|
|
1609
|
+
if synced.attempted and not synced.ok:
|
|
1610
|
+
_emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
|
|
1350
1611
|
return merged_status
|
|
1351
1612
|
|
|
1352
1613
|
|
|
1353
|
-
def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str
|
|
1614
|
+
def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str):
|
|
1354
1615
|
"""Preserve failure work and return an observable bookkeeping result."""
|
|
1355
|
-
if worktree_runtime is not None:
|
|
1356
|
-
return worktree_save_wip(worktree_runtime)
|
|
1357
1616
|
return commit_wip_changes(execution_root, family, item_id, status)
|
|
1358
1617
|
|
|
1359
1618
|
|
|
1619
|
+
def _capture_terminal_failure_bookkeeping(
|
|
1620
|
+
family: RunnerFamily,
|
|
1621
|
+
invocation: RunnerInvocation,
|
|
1622
|
+
item_id: str,
|
|
1623
|
+
new_status: str,
|
|
1624
|
+
update_data: Mapping[str, object],
|
|
1625
|
+
) -> dict[Path, str]:
|
|
1626
|
+
"""Snapshot terminal failure status files before branch return reverts the checkout."""
|
|
1627
|
+
if new_status not in {"failed", "skipped", "auto_skipped", "needs_info"}:
|
|
1628
|
+
return {}
|
|
1629
|
+
candidates: list[Path] = [
|
|
1630
|
+
invocation.list_path,
|
|
1631
|
+
family.state_dir / item_id / "status.json",
|
|
1632
|
+
]
|
|
1633
|
+
raw_auto_skipped = update_data.get("auto_skipped")
|
|
1634
|
+
if isinstance(raw_auto_skipped, list):
|
|
1635
|
+
for entry in raw_auto_skipped:
|
|
1636
|
+
if isinstance(entry, str) and entry.strip():
|
|
1637
|
+
candidates.append(family.state_dir / entry.strip() / "status.json")
|
|
1638
|
+
for key in ("auto_skipped_features", "auto_skipped_bugs"):
|
|
1639
|
+
entries = update_data.get(key)
|
|
1640
|
+
if not isinstance(entries, list):
|
|
1641
|
+
continue
|
|
1642
|
+
for entry in entries:
|
|
1643
|
+
if not isinstance(entry, Mapping):
|
|
1644
|
+
continue
|
|
1645
|
+
dep_id = str(entry.get("feature_id") or entry.get("bug_id") or "").strip()
|
|
1646
|
+
if dep_id:
|
|
1647
|
+
candidates.append(family.state_dir / dep_id / "status.json")
|
|
1648
|
+
snapshots: dict[Path, str] = {}
|
|
1649
|
+
for candidate in candidates:
|
|
1650
|
+
try:
|
|
1651
|
+
if candidate.is_file():
|
|
1652
|
+
snapshots[candidate] = candidate.read_text(encoding="utf-8")
|
|
1653
|
+
except OSError:
|
|
1654
|
+
continue
|
|
1655
|
+
return snapshots
|
|
1656
|
+
|
|
1657
|
+
|
|
1360
1658
|
def _record_setup_failure(
|
|
1361
1659
|
family: RunnerFamily,
|
|
1362
1660
|
invocation: RunnerInvocation,
|
|
@@ -1365,17 +1663,20 @@ def _record_setup_failure(
|
|
|
1365
1663
|
status_root: Path,
|
|
1366
1664
|
base_branch: str,
|
|
1367
1665
|
branch_name: str,
|
|
1368
|
-
*,
|
|
1369
|
-
worktree_runtime=None,
|
|
1370
1666
|
) -> str:
|
|
1371
1667
|
"""Record setup-time infra failures on a task branch when one exists."""
|
|
1372
1668
|
if status_root.resolve() == project_root.resolve() and current_branch(project_root) != branch_name:
|
|
1373
1669
|
return "infra_error"
|
|
1374
|
-
status_family =
|
|
1375
|
-
status_invocation =
|
|
1670
|
+
status_family = family
|
|
1671
|
+
status_invocation = invocation
|
|
1376
1672
|
start = start_item(status_family, status_invocation, item_id, status_root)
|
|
1377
1673
|
if start.ok:
|
|
1378
|
-
commit_pre_branch_bookkeeping(
|
|
1674
|
+
commit_pre_branch_bookkeeping(
|
|
1675
|
+
status_root,
|
|
1676
|
+
status_family,
|
|
1677
|
+
item_id,
|
|
1678
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1679
|
+
)
|
|
1379
1680
|
update = update_item(
|
|
1380
1681
|
status_family,
|
|
1381
1682
|
status_invocation,
|
|
@@ -1387,66 +1688,46 @@ def _record_setup_failure(
|
|
|
1387
1688
|
base_branch=base_branch,
|
|
1388
1689
|
)
|
|
1389
1690
|
new_status = _status_from_update(update) if update.ok else "infra_error"
|
|
1691
|
+
update_data = update.data if isinstance(getattr(update, "data", None), dict) else {}
|
|
1692
|
+
failure_bookkeeping = (
|
|
1693
|
+
_capture_terminal_failure_bookkeeping(
|
|
1694
|
+
status_family,
|
|
1695
|
+
status_invocation,
|
|
1696
|
+
item_id,
|
|
1697
|
+
new_status,
|
|
1698
|
+
update_data,
|
|
1699
|
+
)
|
|
1700
|
+
if update.ok
|
|
1701
|
+
else {}
|
|
1702
|
+
)
|
|
1390
1703
|
if update.ok:
|
|
1391
|
-
commit_final_bookkeeping(
|
|
1392
|
-
|
|
1704
|
+
commit_final_bookkeeping(
|
|
1705
|
+
status_root,
|
|
1706
|
+
status_family,
|
|
1707
|
+
item_id,
|
|
1708
|
+
new_status,
|
|
1709
|
+
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1710
|
+
)
|
|
1711
|
+
wip = _save_failure_wip(status_root, family, item_id, new_status)
|
|
1393
1712
|
else:
|
|
1394
1713
|
wip = None
|
|
1395
1714
|
if (
|
|
1396
|
-
|
|
1397
|
-
and current_branch(project_root) == branch_name
|
|
1715
|
+
current_branch(project_root) == branch_name
|
|
1398
1716
|
and getattr(wip, "ok", True)
|
|
1399
1717
|
):
|
|
1400
|
-
branch_ensure_return(project_root, base_branch, branch_name)
|
|
1718
|
+
returned = branch_ensure_return(project_root, base_branch, branch_name)
|
|
1719
|
+
if getattr(returned, "ok", True) and failure_bookkeeping:
|
|
1720
|
+
synced = sync_terminal_failure_bookkeeping_to_base(
|
|
1721
|
+
status_root,
|
|
1722
|
+
status_family,
|
|
1723
|
+
item_id,
|
|
1724
|
+
new_status,
|
|
1725
|
+
failure_bookkeeping,
|
|
1726
|
+
)
|
|
1727
|
+
if synced.attempted and not synced.ok:
|
|
1728
|
+
_emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
|
|
1401
1729
|
return new_status
|
|
1402
1730
|
|
|
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
1731
|
|
|
1451
1732
|
def _latest_session_id(state_dir: Path, item_id: str) -> str:
|
|
1452
1733
|
sessions_dir = state_dir / item_id / "sessions"
|
|
@@ -1494,7 +1775,6 @@ def _write_session_status(
|
|
|
1494
1775
|
task_type: str,
|
|
1495
1776
|
base_branch: str,
|
|
1496
1777
|
active_dev_branch: str,
|
|
1497
|
-
worktree_path: Path | None = None,
|
|
1498
1778
|
reason: str = "",
|
|
1499
1779
|
fatal_error_code: str = "",
|
|
1500
1780
|
checkpoint_state: object | None = None,
|
|
@@ -1507,19 +1787,13 @@ def _write_session_status(
|
|
|
1507
1787
|
"base_branch": base_branch,
|
|
1508
1788
|
"active_dev_branch": active_dev_branch,
|
|
1509
1789
|
}
|
|
1510
|
-
if worktree_path is not None:
|
|
1511
|
-
payload["worktree_path"] = str(worktree_path)
|
|
1512
1790
|
if reason:
|
|
1513
1791
|
payload["reason"] = reason
|
|
1514
1792
|
if fatal_error_code:
|
|
1515
1793
|
payload["fatal_error_code"] = fatal_error_code
|
|
1516
1794
|
if isinstance(checkpoint_state, dict):
|
|
1517
1795
|
payload["checkpoint_state"] = checkpoint_state
|
|
1518
|
-
session_paths.session_status_json
|
|
1519
|
-
session_paths.session_status_json.write_text(
|
|
1520
|
-
json.dumps(payload, indent=2, sort_keys=True) + "\n",
|
|
1521
|
-
encoding="utf-8",
|
|
1522
|
-
)
|
|
1796
|
+
write_json_atomic(session_paths.session_status_json, payload, sort_keys=True)
|
|
1523
1797
|
|
|
1524
1798
|
def _status_from_update(update_result) -> str:
|
|
1525
1799
|
if isinstance(update_result.data, dict):
|
|
@@ -1527,20 +1801,26 @@ def _status_from_update(update_result) -> str:
|
|
|
1527
1801
|
return "unknown"
|
|
1528
1802
|
|
|
1529
1803
|
|
|
1530
|
-
def _default_branch_name(family: RunnerFamily, item_id: str) -> str:
|
|
1531
|
-
|
|
1804
|
+
def _default_branch_name(family: RunnerFamily, item_id: str, prefix: str | None = None) -> str:
|
|
1805
|
+
branch_prefix = prefix or family.branch_prefix
|
|
1806
|
+
return f"{branch_prefix}/{item_id}-{time.strftime('%Y%m%d%H%M%S')}"
|
|
1532
1807
|
|
|
1533
1808
|
|
|
1534
1809
|
def _session_id(item_id: str) -> str:
|
|
1535
1810
|
return f"{item_id}-{time.strftime('%Y%m%d%H%M%S')}-{time.time_ns()}"
|
|
1536
1811
|
|
|
1537
1812
|
|
|
1538
|
-
def _continuation_summary_path(
|
|
1813
|
+
def _continuation_summary_path(
|
|
1814
|
+
project_root: Path,
|
|
1815
|
+
family: RunnerFamily,
|
|
1816
|
+
item_id: str,
|
|
1817
|
+
prompt: PromptGenerationResult | None,
|
|
1818
|
+
*,
|
|
1819
|
+
metadata: dict[str, object] | None = None,
|
|
1820
|
+
) -> Path:
|
|
1539
1821
|
if prompt and prompt.artifact_path:
|
|
1540
1822
|
return prompt.artifact_path / "continuation-summary.md"
|
|
1541
|
-
|
|
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"
|
|
1823
|
+
return _artifact_path_for_item(project_root, family, item_id, dict(metadata or {})) / "continuation-summary.md"
|
|
1544
1824
|
|
|
1545
1825
|
|
|
1546
1826
|
def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path) -> RunnerInvocation:
|
|
@@ -1554,8 +1834,6 @@ def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path)
|
|
|
1554
1834
|
max_retries=invocation.max_retries,
|
|
1555
1835
|
max_infra_retries=invocation.max_infra_retries,
|
|
1556
1836
|
dry_run=invocation.dry_run,
|
|
1557
|
-
clean=invocation.clean,
|
|
1558
|
-
no_reset=invocation.no_reset,
|
|
1559
1837
|
resume_phase=invocation.resume_phase,
|
|
1560
1838
|
help_requested=invocation.help_requested,
|
|
1561
1839
|
unknown_args=invocation.unknown_args,
|