prizmkit 1.1.190 → 1.1.192
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create-prizmkit.js +4 -4
- package/bundled/VERSION.json +3 -3
- package/bundled/adapters/antigravity/assets/prizmkit-hook.cjs +150 -0
- package/bundled/adapters/antigravity/hooks-adapter.js +195 -0
- package/bundled/adapters/antigravity/paths.js +14 -0
- package/bundled/adapters/antigravity/rules-adapter.js +54 -0
- package/bundled/adapters/antigravity/skill-adapter.js +38 -0
- 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 +21 -15
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -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 +29 -70
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -442
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
- package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +49 -18
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
- package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
- package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
- 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 +282 -217
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +369 -154
- package/bundled/dev-pipeline/prizmkit_runtime/status.py +3 -3
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
- package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
- package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
- package/bundled/dev-pipeline/scripts/continuation.py +6 -4
- package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
- package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
- package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2328
- package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
- package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
- 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 +227 -65
- package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
- package/bundled/dev-pipeline/scripts/utils.py +10 -15
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
- package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
- 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/dev-pipeline/tests/_helpers.py +418 -0
- package/bundled/dev-pipeline/tests/conftest.py +45 -1
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +1 -0
- package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +561 -3094
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
- package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
- package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
- package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
- package/bundled/dev-pipeline/tests/test_unified_cli.py +490 -2006
- package/bundled/dev-pipeline/tests/test_utils.py +3 -3
- package/bundled/rules/USAGE.md +1 -0
- 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 +25 -128
- package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
- package/bundled/skills/prizmkit-init/references/config-schema.md +2 -2
- 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/assets/prizm-docs-format.md +1 -1
- package/bundled/skills/prizmkit-prizm-docs/references/op-init.md +1 -1
- 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/ai-cli-launch.js +1 -1
- package/src/clean.js +40 -4
- package/src/config.js +64 -4
- package/src/detect-platform.js +10 -6
- package/src/external-skills.js +2 -2
- package/src/index.js +1 -0
- package/src/manifest.js +1 -1
- package/src/platforms.js +6 -2
- package/src/prompts.js +11 -3
- package/src/scaffold.js +87 -11
- package/src/upgrade.js +9 -3
- 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/test_generate_refactor_prompt.py +0 -478
- 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,12 @@ 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
|
|
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
|
+
abort_in_progress_git_operation,
|
|
21
23
|
branch_create_plan,
|
|
22
24
|
branch_ensure_return,
|
|
23
25
|
branch_fast_forward_possible,
|
|
@@ -27,24 +29,20 @@ from .gitops import (
|
|
|
27
29
|
default_branch,
|
|
28
30
|
ensure_branch_has_commit,
|
|
29
31
|
ensure_git_repository,
|
|
30
|
-
ensure_linked_worktree,
|
|
31
32
|
local_branch_exists,
|
|
32
|
-
guarded_worktree_remove,
|
|
33
|
-
materialize_worktree_support_assets,
|
|
34
|
-
merge_linked_worktree,
|
|
35
33
|
restore_runtime_wip,
|
|
36
34
|
run_git_command,
|
|
37
35
|
run_git_plan,
|
|
38
|
-
worktree_runtime_context,
|
|
39
|
-
worktree_save_wip,
|
|
40
36
|
)
|
|
41
37
|
from .processes import RuntimeInterruption, describe_interruption, shield_interruption_signals
|
|
38
|
+
from .results import CommandResult
|
|
42
39
|
from .runner_bookkeeping import (
|
|
43
40
|
commit_final_bookkeeping,
|
|
44
41
|
commit_pre_branch_bookkeeping,
|
|
45
42
|
commit_preflight_ready_changes,
|
|
46
43
|
commit_task_branch_changes,
|
|
47
44
|
commit_wip_changes,
|
|
45
|
+
sync_terminal_failure_bookkeeping_to_base,
|
|
48
46
|
)
|
|
49
47
|
from .runner_classification import classify_session, has_branch_completion_evidence, has_completed_artifact_path
|
|
50
48
|
from .runner_models import (
|
|
@@ -67,7 +65,6 @@ from .runner_status import get_next, start_item, status_text, update_item
|
|
|
67
65
|
from .sessions import AISessionConfig, AISessionLauncher, detect_stream_json_support
|
|
68
66
|
from .task_checkout import (
|
|
69
67
|
CHECKOUT_MODE_BRANCH,
|
|
70
|
-
CHECKOUT_MODE_WORKTREE,
|
|
71
68
|
TaskCheckout,
|
|
72
69
|
complete_task_checkout_locked,
|
|
73
70
|
load_task_checkout,
|
|
@@ -98,7 +95,7 @@ def _bridge_sigterm_to_interrupt() -> Iterator[None]:
|
|
|
98
95
|
|
|
99
96
|
|
|
100
97
|
def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], paths) -> CommandResult:
|
|
101
|
-
"""Dispatch a feature
|
|
98
|
+
"""Dispatch a feature or bugfix Python foreground command."""
|
|
102
99
|
family = family_for(kind, paths)
|
|
103
100
|
invocation = parse_invocation(family, action, legacy_args)
|
|
104
101
|
invocation = _resolve_invocation_paths(invocation, paths.project_root)
|
|
@@ -123,7 +120,9 @@ def run_pipeline_command(kind: str, action: str, legacy_args: tuple[str, ...], p
|
|
|
123
120
|
with _bridge_sigterm_to_interrupt():
|
|
124
121
|
result = _run_pipeline(family, invocation, paths)
|
|
125
122
|
except Exception as exc: # keep CLI boundary traceback-free
|
|
126
|
-
|
|
123
|
+
detail = str(exc).strip()
|
|
124
|
+
message = f"{type(exc).__name__}: {detail}" if detail else type(exc).__name__
|
|
125
|
+
return CommandResult(1, f"Python {kind} runner failed", message)
|
|
127
126
|
details = result.details + ((f"last_status: {result.last_status}",) if result.last_status else ())
|
|
128
127
|
return CommandResult(
|
|
129
128
|
0 if result.completed or result.last_status == "dry_run" else 1,
|
|
@@ -178,7 +177,7 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
|
|
|
178
177
|
return PipelineRunResult(False, processed, "pipeline_blocked", details=details)
|
|
179
178
|
if not isinstance(next_result.data, dict):
|
|
180
179
|
return PipelineRunResult(False, processed, "invalid_get_next_output", details=(marker[:500],))
|
|
181
|
-
item_id = str(next_result.data.get(f"{family.kind}_id") or next_result.data.get("feature_id") or next_result.data.get("bug_id") or
|
|
180
|
+
item_id = str(next_result.data.get(f"{family.kind}_id") or next_result.data.get("feature_id") or next_result.data.get("bug_id") or "")
|
|
182
181
|
if not item_id:
|
|
183
182
|
return PipelineRunResult(False, processed, "missing_item_id", details=(marker[:500],))
|
|
184
183
|
if item_id in item_statuses:
|
|
@@ -227,10 +226,8 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
|
|
|
227
226
|
if final_status == "pending":
|
|
228
227
|
continue
|
|
229
228
|
details = _render_item_statuses(item_statuses)
|
|
230
|
-
if
|
|
229
|
+
if _runner_env_for_paths(paths).stop_on_failure:
|
|
231
230
|
return PipelineRunResult(False, processed, "stop_on_failure", final_status, details)
|
|
232
|
-
if final_status in {"failed", "needs_info"}:
|
|
233
|
-
return PipelineRunResult(False, processed, "item_failed", final_status, details)
|
|
234
231
|
|
|
235
232
|
|
|
236
233
|
_COMPLETION_COMPATIBLE_STATUSES = {"completed"}
|
|
@@ -277,13 +274,25 @@ def _emit_warning(message: str) -> None:
|
|
|
277
274
|
|
|
278
275
|
|
|
279
276
|
def _family_label(family: RunnerFamily) -> str:
|
|
280
|
-
return {"feature": "Feature", "bugfix": "Bug"
|
|
277
|
+
return {"feature": "Feature", "bugfix": "Bug"}.get(family.kind, family.kind.title())
|
|
281
278
|
|
|
282
279
|
|
|
283
|
-
def
|
|
280
|
+
def _runner_env_for_paths(paths, config=None) -> RunnerEnvironment:
|
|
281
|
+
env_values = getattr(config, "env_values", None) if config is not None else None
|
|
282
|
+
if isinstance(env_values, Mapping) and env_values:
|
|
283
|
+
return RunnerEnvironment.from_env(env_values)
|
|
284
|
+
prizmkit_dir = getattr(paths, "prizmkit_dir", None)
|
|
285
|
+
if prizmkit_dir is None and hasattr(paths, "project_root"):
|
|
286
|
+
prizmkit_dir = Path(paths.project_root) / ".prizmkit"
|
|
287
|
+
if prizmkit_dir is not None:
|
|
288
|
+
return RunnerEnvironment.from_env(load_env_file(Path(prizmkit_dir) / ".env", os.environ))
|
|
289
|
+
return RunnerEnvironment.from_env()
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _max_retries(invocation: RunnerInvocation, paths=None) -> int:
|
|
284
293
|
if invocation.max_retries is not None:
|
|
285
294
|
return max(0, invocation.max_retries)
|
|
286
|
-
return RunnerEnvironment.from_env().max_retries
|
|
295
|
+
return _runner_env_for_paths(paths).max_retries if paths is not None else RunnerEnvironment.from_env().max_retries
|
|
287
296
|
|
|
288
297
|
|
|
289
298
|
def _emit_item_header(family: RunnerFamily, invocation: RunnerInvocation, item_id: str, metadata: dict[str, object]) -> None:
|
|
@@ -352,12 +361,22 @@ def _latest_session_status(state_dir: Path, item_id: str) -> dict[str, object]:
|
|
|
352
361
|
|
|
353
362
|
def _resolve_base_branch(project_root: Path, metadata: dict[str, object], active_branch: str, family: RunnerFamily, item_id: str) -> str:
|
|
354
363
|
recorded = str(metadata.get("base_branch") or "").strip()
|
|
355
|
-
if recorded and local_branch_exists(project_root, recorded):
|
|
364
|
+
if recorded and recorded != "HEAD" and local_branch_exists(project_root, recorded):
|
|
356
365
|
return recorded
|
|
366
|
+
active = "" if active_branch == "HEAD" else active_branch
|
|
357
367
|
detected_default = default_branch(project_root)
|
|
358
|
-
if
|
|
359
|
-
|
|
360
|
-
|
|
368
|
+
if detected_default == "HEAD":
|
|
369
|
+
detected_default = ""
|
|
370
|
+
if _is_current_task_branch(active, family, item_id) or _is_recovery_side_effect_branch(active, family, item_id):
|
|
371
|
+
resolved = detected_default
|
|
372
|
+
else:
|
|
373
|
+
resolved = active or detected_default
|
|
374
|
+
if not resolved or resolved == "HEAD":
|
|
375
|
+
raise RuntimeError(
|
|
376
|
+
f"Cannot resolve base branch for {family.kind} task {item_id} from detached HEAD; "
|
|
377
|
+
"check out a named branch before running the pipeline."
|
|
378
|
+
)
|
|
379
|
+
return resolved
|
|
361
380
|
|
|
362
381
|
|
|
363
382
|
def _resolve_working_branch(family: RunnerFamily, item_id: str, metadata: dict[str, object], env: RunnerEnvironment, active_branch: str) -> str:
|
|
@@ -506,6 +525,12 @@ def _process_item(
|
|
|
506
525
|
raise
|
|
507
526
|
|
|
508
527
|
|
|
528
|
+
def _validate_effort_config(config) -> None:
|
|
529
|
+
effort_validation = getattr(config, "effort_validation", None)
|
|
530
|
+
if effort_validation is not None and not effort_validation.valid:
|
|
531
|
+
raise RuntimeError(effort_validation.message)
|
|
532
|
+
|
|
533
|
+
|
|
509
534
|
def _preview_item(
|
|
510
535
|
family: RunnerFamily,
|
|
511
536
|
invocation: RunnerInvocation,
|
|
@@ -517,8 +542,7 @@ def _preview_item(
|
|
|
517
542
|
config = load_runtime_config(paths)
|
|
518
543
|
if not config.ai_client.command:
|
|
519
544
|
raise RuntimeError("No supported AI CLI command was found")
|
|
520
|
-
|
|
521
|
-
raise RuntimeError(config.effort_validation.message)
|
|
545
|
+
_validate_effort_config(config)
|
|
522
546
|
metadata = _with_recovery_metadata(family, item_id, initial_metadata)
|
|
523
547
|
retry_count = int(metadata.get("retry_count") or 0)
|
|
524
548
|
session_id = f"{item_id}-dry-run"
|
|
@@ -554,12 +578,11 @@ def _process_item_locked(
|
|
|
554
578
|
*,
|
|
555
579
|
initial_metadata: dict[str, object],
|
|
556
580
|
) -> str:
|
|
557
|
-
env = RunnerEnvironment.from_env()
|
|
558
581
|
config = load_runtime_config(paths)
|
|
582
|
+
env = _runner_env_for_paths(paths, config)
|
|
559
583
|
if not config.ai_client.command:
|
|
560
584
|
raise RuntimeError("No supported AI CLI command was found")
|
|
561
|
-
|
|
562
|
-
raise RuntimeError(config.effort_validation.message)
|
|
585
|
+
_validate_effort_config(config)
|
|
563
586
|
|
|
564
587
|
repository = ensure_git_repository(paths.project_root)
|
|
565
588
|
if repository.return_code != 0:
|
|
@@ -577,14 +600,7 @@ def _process_item_locked(
|
|
|
577
600
|
base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
|
|
578
601
|
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch)
|
|
579
602
|
branch_context = BranchContext(base_branch, branch_name, paths.project_root)
|
|
580
|
-
worktree_runtime = None
|
|
581
603
|
reusing_checkout = checkout is not None and checkout.is_active
|
|
582
|
-
if reusing_checkout:
|
|
583
|
-
use_worktree = checkout.uses_worktree
|
|
584
|
-
worktree_path = Path(checkout.worktree_path) if checkout.worktree_path else None
|
|
585
|
-
else:
|
|
586
|
-
use_worktree = _use_worktree_for_family(env, family)
|
|
587
|
-
worktree_path = None
|
|
588
604
|
execution_root = paths.project_root
|
|
589
605
|
session_id = ""
|
|
590
606
|
session_paths: SessionPaths | None = None
|
|
@@ -629,54 +645,35 @@ def _process_item_locked(
|
|
|
629
645
|
checkout = replace_missing_recorded_base_locked(family.state_dir, checkout, base_branch)
|
|
630
646
|
_emit_info(f"Checkout: recorded base {previous_base} is missing; using {base_branch}")
|
|
631
647
|
|
|
632
|
-
if use_worktree:
|
|
633
|
-
worktree_runtime = worktree_runtime_context(
|
|
634
|
-
branch_context,
|
|
635
|
-
WorktreePolicy(
|
|
636
|
-
use_worktree=True,
|
|
637
|
-
cleanup_on_success=True,
|
|
638
|
-
preserve_on_failure=True,
|
|
639
|
-
worktree_root=(worktree_path.parent if worktree_path is not None else paths.state_dir / "worktrees"),
|
|
640
|
-
),
|
|
641
|
-
)
|
|
642
|
-
if worktree_path is not None and worktree_runtime.worktree_path != worktree_path.resolve():
|
|
643
|
-
raise RuntimeError(f"Task {item_id} worktree identity resolves to an unexpected path")
|
|
644
648
|
checkout_candidate = TaskCheckout.active(
|
|
645
649
|
family.task_type,
|
|
646
650
|
item_id,
|
|
647
651
|
branch_name,
|
|
648
652
|
base_branch,
|
|
649
|
-
checkout_mode=
|
|
650
|
-
worktree_path=str(worktree_runtime.worktree_path) if worktree_runtime is not None else "",
|
|
653
|
+
checkout_mode=CHECKOUT_MODE_BRANCH,
|
|
651
654
|
)
|
|
652
655
|
checkout = reserve_task_checkout_locked(family.state_dir, checkout_candidate)
|
|
653
656
|
_emit_info(f"Checkout: reserved task identity at {family.state_dir / item_id / 'checkout.json'}")
|
|
654
657
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
_emit_info(f"Worktree: {worktree_runtime.worktree_path}")
|
|
662
|
-
support_assets = materialize_worktree_support_assets(worktree_runtime)
|
|
663
|
-
if not support_assets.ok:
|
|
664
|
-
return _record_setup_failure(
|
|
658
|
+
branch_result = run_git_plan(paths.project_root, branch_create_plan(branch_context))
|
|
659
|
+
_emit_branch_setup_result(branch_context, branch_result)
|
|
660
|
+
if not branch_result.ok:
|
|
661
|
+
_emit_git_plan_output(branch_result)
|
|
662
|
+
if invocation.list_path.is_file():
|
|
663
|
+
update = update_item(
|
|
665
664
|
family,
|
|
666
665
|
invocation,
|
|
667
666
|
item_id,
|
|
667
|
+
"infra_error",
|
|
668
|
+
"",
|
|
668
669
|
paths.project_root,
|
|
669
|
-
|
|
670
|
-
base_branch,
|
|
671
|
-
branch_name,
|
|
672
|
-
worktree_runtime=worktree_runtime,
|
|
670
|
+
active_dev_branch=branch_name,
|
|
671
|
+
base_branch=base_branch,
|
|
673
672
|
)
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if not branch_result.ok:
|
|
679
|
-
return "infra_error"
|
|
673
|
+
if update.ok:
|
|
674
|
+
commit_final_bookkeeping(paths.project_root, family, item_id, _status_from_update(update))
|
|
675
|
+
return _status_from_update(update)
|
|
676
|
+
return "infra_error"
|
|
680
677
|
|
|
681
678
|
if reusing_checkout:
|
|
682
679
|
restored_wip = restore_runtime_wip(
|
|
@@ -698,7 +695,6 @@ def _process_item_locked(
|
|
|
698
695
|
execution_root,
|
|
699
696
|
base_branch,
|
|
700
697
|
branch_name,
|
|
701
|
-
worktree_runtime=worktree_runtime,
|
|
702
698
|
)
|
|
703
699
|
if restored_wip.restored:
|
|
704
700
|
_emit_info(
|
|
@@ -709,11 +705,26 @@ def _process_item_locked(
|
|
|
709
705
|
_emit_info(f"Recovery: no Runtime-owned WIP tip to restore for {item_id}")
|
|
710
706
|
|
|
711
707
|
_emit_item_header(family, invocation, item_id, metadata)
|
|
712
|
-
status_root =
|
|
713
|
-
status_family =
|
|
714
|
-
status_invocation =
|
|
708
|
+
status_root = paths.project_root
|
|
709
|
+
status_family = family
|
|
710
|
+
status_invocation = invocation
|
|
715
711
|
recovered_session_id = _latest_session_id(family.state_dir, item_id)
|
|
716
712
|
recovery_artifact = _artifact_path_for_item(execution_root, family, item_id, metadata)
|
|
713
|
+
recovery_checkpoint = recovery_artifact / "workflow-checkpoint.json"
|
|
714
|
+
recovery_request = recovery_artifact / REQUEST_FILENAME
|
|
715
|
+
if recovery_checkpoint.is_file() and (
|
|
716
|
+
recovery_request.is_file()
|
|
717
|
+
or load_checkpoint_state(recovery_checkpoint, project_root=execution_root).semantic_commit_ready
|
|
718
|
+
):
|
|
719
|
+
pending_commit = finalize_runtime_commit(
|
|
720
|
+
execution_root,
|
|
721
|
+
artifact_dir=recovery_artifact,
|
|
722
|
+
checkpoint_path=recovery_checkpoint,
|
|
723
|
+
)
|
|
724
|
+
if pending_commit.committed:
|
|
725
|
+
_emit_success(f"Recovery: finalized pending Runtime commit {pending_commit.commit_hash}")
|
|
726
|
+
elif pending_commit.status == "failed":
|
|
727
|
+
_emit_warning(f"Recovery: pending Runtime commit failed ({pending_commit.reason})")
|
|
717
728
|
if recovered_session_id and has_completed_artifact_path(recovery_artifact) and has_branch_completion_evidence(execution_root, base_branch, branch_name, recovery_artifact):
|
|
718
729
|
session_paths = SessionPaths.for_item(family.state_dir, item_id, recovered_session_id)
|
|
719
730
|
_write_session_status(
|
|
@@ -724,7 +735,6 @@ def _process_item_locked(
|
|
|
724
735
|
task_type=family.task_type,
|
|
725
736
|
base_branch=base_branch,
|
|
726
737
|
active_dev_branch=branch_name,
|
|
727
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
728
738
|
reason="completed_branch_recovered_from_late_runtime_error",
|
|
729
739
|
)
|
|
730
740
|
return _finalize_recovered_success(
|
|
@@ -740,7 +750,6 @@ def _process_item_locked(
|
|
|
740
750
|
base_branch,
|
|
741
751
|
recovered_session_id,
|
|
742
752
|
session_paths,
|
|
743
|
-
worktree_runtime,
|
|
744
753
|
)
|
|
745
754
|
start = start_item(status_family, status_invocation, item_id, status_root)
|
|
746
755
|
if not start.ok:
|
|
@@ -769,7 +778,7 @@ def _process_item_locked(
|
|
|
769
778
|
"context_overflow_count": context_overflow_count,
|
|
770
779
|
"retry_count": retry_count,
|
|
771
780
|
"infra_error_count": infra_error_count,
|
|
772
|
-
"max_retries": _max_retries(invocation),
|
|
781
|
+
"max_retries": _max_retries(invocation, paths),
|
|
773
782
|
"max_infra_retries": invocation.max_infra_retries,
|
|
774
783
|
"no_progress_count": previous_no_progress_count,
|
|
775
784
|
"progress_fingerprint": previous_fingerprint or {},
|
|
@@ -784,7 +793,9 @@ def _process_item_locked(
|
|
|
784
793
|
"task_type": family.task_type,
|
|
785
794
|
"active_dev_branch": branch_name,
|
|
786
795
|
"base_branch": base_branch,
|
|
787
|
-
"continuation_summary_path": _continuation_summary_path(
|
|
796
|
+
"continuation_summary_path": _continuation_summary_path(
|
|
797
|
+
execution_root, family, item_id, None, metadata=metadata
|
|
798
|
+
),
|
|
788
799
|
}
|
|
789
800
|
prompt = generate_prompt(
|
|
790
801
|
family,
|
|
@@ -809,6 +820,12 @@ def _process_item_locked(
|
|
|
809
820
|
"Cursor Agent CLI is incompatible with PrizmKit headless execution: "
|
|
810
821
|
f"{details}. Install or update Cursor Agent and verify `agent --help`."
|
|
811
822
|
)
|
|
823
|
+
if config.ai_client.platform == "antigravity" and not stream_json:
|
|
824
|
+
details = "; ".join(stream_support.notes) or "required stream-json flags were not found"
|
|
825
|
+
raise RuntimeError(
|
|
826
|
+
"Antigravity CLI is incompatible with PrizmKit headless execution: "
|
|
827
|
+
f"{details}. Install or update Antigravity CLI (`agy`) and verify `agy --help`."
|
|
828
|
+
)
|
|
812
829
|
base_head = run_git_command(execution_root, ("rev-parse", "HEAD")).stdout.strip()
|
|
813
830
|
session_result = AISessionLauncher(
|
|
814
831
|
AISessionConfig(
|
|
@@ -844,6 +861,7 @@ def _process_item_locked(
|
|
|
844
861
|
prompt=prompt,
|
|
845
862
|
previous_fingerprint=previous_fingerprint,
|
|
846
863
|
previous_no_progress_count=previous_no_progress_count,
|
|
864
|
+
stream_json=stream_json,
|
|
847
865
|
)
|
|
848
866
|
if runtime_commit.status == "failed":
|
|
849
867
|
classification = SessionClassification(
|
|
@@ -869,7 +887,9 @@ def _process_item_locked(
|
|
|
869
887
|
)
|
|
870
888
|
_emit_session_summary(session_result, session_paths, classification)
|
|
871
889
|
final_session_status = classification.session_status
|
|
872
|
-
summary_path = _continuation_summary_path(
|
|
890
|
+
summary_path = _continuation_summary_path(
|
|
891
|
+
execution_root, family, item_id, prompt, metadata=metadata
|
|
892
|
+
)
|
|
873
893
|
|
|
874
894
|
_write_session_status(
|
|
875
895
|
session_paths,
|
|
@@ -879,7 +899,6 @@ def _process_item_locked(
|
|
|
879
899
|
task_type=family.task_type,
|
|
880
900
|
base_branch=base_branch,
|
|
881
901
|
active_dev_branch=branch_name,
|
|
882
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
883
902
|
reason=classification.reason,
|
|
884
903
|
fatal_error_code=classification.fatal_error_code,
|
|
885
904
|
checkpoint_state=classification.checkpoint_state,
|
|
@@ -926,15 +945,31 @@ def _process_item_locked(
|
|
|
926
945
|
|
|
927
946
|
accepted_with_warning = accepted_with_warning and new_status == "completed"
|
|
928
947
|
if final_session_status != "success" and not accepted_with_warning:
|
|
948
|
+
failure_bookkeeping = _capture_terminal_failure_bookkeeping(
|
|
949
|
+
status_family,
|
|
950
|
+
status_invocation,
|
|
951
|
+
item_id,
|
|
952
|
+
new_status,
|
|
953
|
+
update_data,
|
|
954
|
+
)
|
|
929
955
|
commit_final_bookkeeping(status_root, status_family, item_id, new_status)
|
|
930
|
-
wip = _save_failure_wip(execution_root, family, item_id, new_status
|
|
956
|
+
wip = _save_failure_wip(execution_root, family, item_id, new_status)
|
|
931
957
|
if not getattr(wip, "ok", True):
|
|
932
958
|
_emit_warning(f"WIP preservation failed for {item_id}; leaving the task checkout active")
|
|
933
959
|
return new_status
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
960
|
+
returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
|
|
961
|
+
if not getattr(returned, "ok", True):
|
|
962
|
+
_emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
|
|
963
|
+
elif failure_bookkeeping:
|
|
964
|
+
synced = sync_terminal_failure_bookkeeping_to_base(
|
|
965
|
+
status_root,
|
|
966
|
+
status_family,
|
|
967
|
+
item_id,
|
|
968
|
+
new_status,
|
|
969
|
+
failure_bookkeeping,
|
|
970
|
+
)
|
|
971
|
+
if synced.attempted and not synced.ok:
|
|
972
|
+
_emit_warning(f"Could not commit {item_id} terminal status bookkeeping on {base_branch}")
|
|
938
973
|
return new_status
|
|
939
974
|
|
|
940
975
|
completed_status = _complete_success_merge(
|
|
@@ -951,7 +986,6 @@ def _process_item_locked(
|
|
|
951
986
|
base_branch,
|
|
952
987
|
session_id,
|
|
953
988
|
session_paths,
|
|
954
|
-
worktree_runtime,
|
|
955
989
|
classification_fatal_error_code=classification.fatal_error_code,
|
|
956
990
|
)
|
|
957
991
|
if accepted_with_warning and completed_status == "completed":
|
|
@@ -963,25 +997,26 @@ def _process_item_locked(
|
|
|
963
997
|
)
|
|
964
998
|
return completed_status
|
|
965
999
|
except KeyboardInterrupt as interruption:
|
|
966
|
-
try:
|
|
967
|
-
_emit_task_interruption_diagnostics(
|
|
968
|
-
interruption,
|
|
969
|
-
family=family,
|
|
970
|
-
invocation=invocation,
|
|
971
|
-
item_id=item_id,
|
|
972
|
-
session_id=session_id,
|
|
973
|
-
session_paths=session_paths,
|
|
974
|
-
retry_count=retry_count,
|
|
975
|
-
infra_error_count=infra_error_count,
|
|
976
|
-
branch_name=branch_name,
|
|
977
|
-
base_branch=base_branch,
|
|
978
|
-
)
|
|
979
|
-
except Exception as diagnostic_error:
|
|
980
|
-
_emit_warning(
|
|
981
|
-
f"Interrupt diagnostic collection failed ({type(diagnostic_error).__name__}); "
|
|
982
|
-
"continuing existing WIP preservation and checkout recovery behavior"
|
|
983
|
-
)
|
|
984
1000
|
with shield_interruption_signals():
|
|
1001
|
+
try:
|
|
1002
|
+
_emit_task_interruption_diagnostics(
|
|
1003
|
+
interruption,
|
|
1004
|
+
family=family,
|
|
1005
|
+
invocation=invocation,
|
|
1006
|
+
item_id=item_id,
|
|
1007
|
+
session_id=session_id,
|
|
1008
|
+
session_paths=session_paths,
|
|
1009
|
+
retry_count=retry_count,
|
|
1010
|
+
infra_error_count=infra_error_count,
|
|
1011
|
+
branch_name=branch_name,
|
|
1012
|
+
base_branch=base_branch,
|
|
1013
|
+
paths=paths,
|
|
1014
|
+
)
|
|
1015
|
+
except Exception as diagnostic_error:
|
|
1016
|
+
_emit_warning(
|
|
1017
|
+
f"Interrupt diagnostic collection failed ({type(diagnostic_error).__name__}); "
|
|
1018
|
+
"continuing existing WIP preservation and checkout recovery behavior"
|
|
1019
|
+
)
|
|
985
1020
|
_cleanup_interrupted_task(
|
|
986
1021
|
item_id=item_id,
|
|
987
1022
|
paths=paths,
|
|
@@ -989,7 +1024,7 @@ def _process_item_locked(
|
|
|
989
1024
|
base_branch=base_branch,
|
|
990
1025
|
branch_name=branch_name,
|
|
991
1026
|
)
|
|
992
|
-
|
|
1027
|
+
raise
|
|
993
1028
|
|
|
994
1029
|
|
|
995
1030
|
def _emit_task_interruption_diagnostics(
|
|
@@ -1004,6 +1039,7 @@ def _emit_task_interruption_diagnostics(
|
|
|
1004
1039
|
infra_error_count: int | None,
|
|
1005
1040
|
branch_name: str,
|
|
1006
1041
|
base_branch: str,
|
|
1042
|
+
paths=None,
|
|
1007
1043
|
) -> None:
|
|
1008
1044
|
"""Emit task-level interruption context without mutating pipeline state."""
|
|
1009
1045
|
details = describe_interruption(interruption)
|
|
@@ -1025,7 +1061,7 @@ def _emit_task_interruption_diagnostics(
|
|
|
1025
1061
|
f"phase={phase}; tool={tool}; branch={branch_name}; base={base_branch}"
|
|
1026
1062
|
)
|
|
1027
1063
|
_emit_warning(
|
|
1028
|
-
f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation)}; "
|
|
1064
|
+
f"Retry accounting unchanged: code={code_retry}/{_max_retries(invocation, paths)}; "
|
|
1029
1065
|
f"infrastructure={infra_retry}/{invocation.max_infra_retries}"
|
|
1030
1066
|
)
|
|
1031
1067
|
_emit_warning(
|
|
@@ -1044,6 +1080,7 @@ def _cleanup_interrupted_task(
|
|
|
1044
1080
|
) -> None:
|
|
1045
1081
|
"""Commit interrupted task WIP, then leave the caller checkout on its base branch."""
|
|
1046
1082
|
_emit_warning(f"Interrupted while processing {item_id}; preserving task WIP before base return")
|
|
1083
|
+
abort_in_progress_git_operation(execution_root)
|
|
1047
1084
|
execution_branch = current_branch(execution_root)
|
|
1048
1085
|
if execution_root.resolve() == paths.project_root.resolve() and execution_branch == base_branch:
|
|
1049
1086
|
preserved = None
|
|
@@ -1186,7 +1223,6 @@ def _finalize_recovered_success(
|
|
|
1186
1223
|
base_branch: str,
|
|
1187
1224
|
session_id: str,
|
|
1188
1225
|
session_paths: SessionPaths,
|
|
1189
|
-
worktree_runtime,
|
|
1190
1226
|
) -> str:
|
|
1191
1227
|
update = update_item(
|
|
1192
1228
|
status_family,
|
|
@@ -1215,11 +1251,63 @@ def _finalize_recovered_success(
|
|
|
1215
1251
|
base_branch,
|
|
1216
1252
|
session_id,
|
|
1217
1253
|
session_paths,
|
|
1218
|
-
worktree_runtime,
|
|
1219
1254
|
classification_fatal_error_code="",
|
|
1220
1255
|
)
|
|
1221
1256
|
|
|
1222
1257
|
|
|
1258
|
+
def _patch_completion_notes_if_present(
|
|
1259
|
+
execution_root: Path,
|
|
1260
|
+
paths,
|
|
1261
|
+
status_root: Path,
|
|
1262
|
+
status_family: RunnerFamily,
|
|
1263
|
+
status_invocation: RunnerInvocation,
|
|
1264
|
+
item_id: str,
|
|
1265
|
+
) -> None:
|
|
1266
|
+
summary_file = _artifact_path_for_item(execution_root, status_family, item_id, {}) / "completion-summary.json"
|
|
1267
|
+
pipeline_root = getattr(paths, "pipeline_root", None)
|
|
1268
|
+
if pipeline_root is None or not summary_file.is_file() or not status_invocation.list_path.is_file():
|
|
1269
|
+
return
|
|
1270
|
+
patch_script = Path(pipeline_root) / "scripts" / "patch-completion-notes.py"
|
|
1271
|
+
if not patch_script.is_file():
|
|
1272
|
+
return
|
|
1273
|
+
completed = subprocess.run(
|
|
1274
|
+
[
|
|
1275
|
+
sys.executable,
|
|
1276
|
+
str(patch_script),
|
|
1277
|
+
status_family.list_arg,
|
|
1278
|
+
str(status_invocation.list_path),
|
|
1279
|
+
status_family.item_id_arg,
|
|
1280
|
+
item_id,
|
|
1281
|
+
"--summary",
|
|
1282
|
+
str(summary_file),
|
|
1283
|
+
],
|
|
1284
|
+
cwd=str(status_root),
|
|
1285
|
+
stdout=subprocess.PIPE,
|
|
1286
|
+
stderr=subprocess.PIPE,
|
|
1287
|
+
text=True,
|
|
1288
|
+
encoding="utf-8",
|
|
1289
|
+
errors="replace",
|
|
1290
|
+
check=False,
|
|
1291
|
+
)
|
|
1292
|
+
if completed.returncode != 0:
|
|
1293
|
+
detail = (completed.stderr or completed.stdout).strip()
|
|
1294
|
+
_emit_warning(
|
|
1295
|
+
f"Could not patch completion_notes for {item_id} (exit={completed.returncode})"
|
|
1296
|
+
+ (f": {detail.splitlines()[0][:240]}" if detail else "")
|
|
1297
|
+
)
|
|
1298
|
+
return
|
|
1299
|
+
notes_count = None
|
|
1300
|
+
if (completed.stdout or "").strip():
|
|
1301
|
+
try:
|
|
1302
|
+
notes_count = json.loads(completed.stdout).get("notes_count")
|
|
1303
|
+
except (ValueError, json.JSONDecodeError, AttributeError):
|
|
1304
|
+
notes_count = None
|
|
1305
|
+
if notes_count:
|
|
1306
|
+
_emit_info(f"Patched {notes_count} completion note(s) for {item_id}")
|
|
1307
|
+
else:
|
|
1308
|
+
_emit_info(f"Checked completion-summary.json for {item_id}; no non-empty completion notes patched")
|
|
1309
|
+
|
|
1310
|
+
|
|
1223
1311
|
def _complete_success_merge(
|
|
1224
1312
|
family: RunnerFamily,
|
|
1225
1313
|
item_id: str,
|
|
@@ -1234,11 +1322,19 @@ def _complete_success_merge(
|
|
|
1234
1322
|
base_branch: str,
|
|
1235
1323
|
session_id: str,
|
|
1236
1324
|
session_paths: SessionPaths,
|
|
1237
|
-
worktree_runtime,
|
|
1238
1325
|
*,
|
|
1239
1326
|
classification_fatal_error_code: str = "",
|
|
1240
1327
|
) -> str:
|
|
1241
|
-
env =
|
|
1328
|
+
env = _runner_env_for_paths(paths)
|
|
1329
|
+
if new_status == "completed":
|
|
1330
|
+
_patch_completion_notes_if_present(
|
|
1331
|
+
execution_root,
|
|
1332
|
+
paths,
|
|
1333
|
+
status_root,
|
|
1334
|
+
status_family,
|
|
1335
|
+
status_invocation,
|
|
1336
|
+
item_id,
|
|
1337
|
+
)
|
|
1242
1338
|
final_bookkeeping = commit_final_bookkeeping(status_root, status_family, item_id, new_status)
|
|
1243
1339
|
task_commit = commit_task_branch_changes(execution_root, family, item_id, new_status)
|
|
1244
1340
|
finalization_committed = getattr(final_bookkeeping, "ok", True) and getattr(task_commit, "ok", True)
|
|
@@ -1252,7 +1348,6 @@ def _complete_success_merge(
|
|
|
1252
1348
|
task_type=family.task_type,
|
|
1253
1349
|
base_branch=base_branch,
|
|
1254
1350
|
active_dev_branch=branch_name,
|
|
1255
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
1256
1351
|
reason="commit_missing",
|
|
1257
1352
|
fatal_error_code=classification_fatal_error_code,
|
|
1258
1353
|
)
|
|
@@ -1272,41 +1367,34 @@ def _complete_success_merge(
|
|
|
1272
1367
|
_emit_update_summary(family, item_id, update)
|
|
1273
1368
|
commit_missing_status = _status_from_update(update)
|
|
1274
1369
|
commit_final_bookkeeping(status_root, status_family, item_id, commit_missing_status)
|
|
1275
|
-
_save_failure_wip(execution_root, family, item_id, commit_missing_status
|
|
1370
|
+
_save_failure_wip(execution_root, family, item_id, commit_missing_status)
|
|
1276
1371
|
return commit_missing_status
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
guarded_worktree_remove(worktree_runtime, delete_branch=True)
|
|
1287
|
-
_emit_success(f"Merged {branch_name} into {base_branch}")
|
|
1288
|
-
return new_status
|
|
1289
|
-
else:
|
|
1290
|
-
_emit_info(f"Merging {branch_name} into {base_branch}...")
|
|
1291
|
-
merge = run_git_plan(
|
|
1292
|
-
paths.project_root,
|
|
1293
|
-
branch_merge_plan(
|
|
1372
|
+
|
|
1373
|
+
_emit_info(f"Merging {branch_name} into {base_branch}...")
|
|
1374
|
+
merge = run_git_plan(
|
|
1375
|
+
paths.project_root,
|
|
1376
|
+
branch_merge_plan(
|
|
1377
|
+
branch_context,
|
|
1378
|
+
auto_push=env.auto_push,
|
|
1379
|
+
rebase=not branch_fast_forward_possible(
|
|
1380
|
+
paths.project_root,
|
|
1294
1381
|
branch_context,
|
|
1295
|
-
auto_push=env.auto_push,
|
|
1296
|
-
rebase=not branch_fast_forward_possible(
|
|
1297
|
-
paths.project_root,
|
|
1298
|
-
branch_context,
|
|
1299
|
-
),
|
|
1300
1382
|
),
|
|
1301
|
-
)
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1383
|
+
),
|
|
1384
|
+
)
|
|
1385
|
+
_emit_git_plan_output(merge)
|
|
1386
|
+
if merge.ok:
|
|
1387
|
+
checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
1388
|
+
if checkout is None:
|
|
1389
|
+
raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
|
|
1390
|
+
complete_task_checkout_locked(family.state_dir, checkout)
|
|
1391
|
+
_emit_success(f"Merged {branch_name} into {base_branch}")
|
|
1392
|
+
return new_status
|
|
1393
|
+
_emit_warning(
|
|
1394
|
+
f"Merge failed for {item_id} ({branch_name} -> {base_branch}); "
|
|
1395
|
+
"aborted in-progress git operation and recorded merge_conflict"
|
|
1396
|
+
)
|
|
1397
|
+
abort_in_progress_git_operation(paths.project_root)
|
|
1310
1398
|
|
|
1311
1399
|
_write_session_status(
|
|
1312
1400
|
session_paths,
|
|
@@ -1316,7 +1404,6 @@ def _complete_success_merge(
|
|
|
1316
1404
|
task_type=family.task_type,
|
|
1317
1405
|
base_branch=base_branch,
|
|
1318
1406
|
active_dev_branch=branch_name,
|
|
1319
|
-
worktree_path=worktree_runtime.worktree_path if worktree_runtime is not None else None,
|
|
1320
1407
|
reason="merge_conflict",
|
|
1321
1408
|
fatal_error_code=classification_fatal_error_code,
|
|
1322
1409
|
)
|
|
@@ -1336,21 +1423,53 @@ def _complete_success_merge(
|
|
|
1336
1423
|
_emit_update_summary(family, item_id, update)
|
|
1337
1424
|
merged_status = _status_from_update(update)
|
|
1338
1425
|
commit_final_bookkeeping(status_root, status_family, item_id, merged_status)
|
|
1339
|
-
wip = _save_failure_wip(execution_root, family, item_id, merged_status
|
|
1340
|
-
if
|
|
1426
|
+
wip = _save_failure_wip(execution_root, family, item_id, merged_status)
|
|
1427
|
+
if getattr(wip, "ok", True):
|
|
1341
1428
|
returned = branch_ensure_return(paths.project_root, base_branch, branch_name)
|
|
1342
1429
|
if not returned.ok:
|
|
1343
1430
|
_emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
|
|
1344
1431
|
return merged_status
|
|
1345
1432
|
|
|
1346
1433
|
|
|
1347
|
-
def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str
|
|
1434
|
+
def _save_failure_wip(execution_root: Path, family: RunnerFamily, item_id: str, status: str):
|
|
1348
1435
|
"""Preserve failure work and return an observable bookkeeping result."""
|
|
1349
|
-
if worktree_runtime is not None:
|
|
1350
|
-
return worktree_save_wip(worktree_runtime)
|
|
1351
1436
|
return commit_wip_changes(execution_root, family, item_id, status)
|
|
1352
1437
|
|
|
1353
1438
|
|
|
1439
|
+
def _capture_terminal_failure_bookkeeping(
|
|
1440
|
+
family: RunnerFamily,
|
|
1441
|
+
invocation: RunnerInvocation,
|
|
1442
|
+
item_id: str,
|
|
1443
|
+
new_status: str,
|
|
1444
|
+
update_data: Mapping[str, object],
|
|
1445
|
+
) -> dict[Path, str]:
|
|
1446
|
+
"""Snapshot terminal failure status files before branch return reverts the checkout."""
|
|
1447
|
+
if new_status not in {"failed", "skipped", "auto_skipped"}:
|
|
1448
|
+
return {}
|
|
1449
|
+
candidates: list[Path] = [
|
|
1450
|
+
invocation.list_path,
|
|
1451
|
+
family.state_dir / item_id / "status.json",
|
|
1452
|
+
]
|
|
1453
|
+
for key in ("auto_skipped_features", "auto_skipped_bugs"):
|
|
1454
|
+
entries = update_data.get(key)
|
|
1455
|
+
if not isinstance(entries, list):
|
|
1456
|
+
continue
|
|
1457
|
+
for entry in entries:
|
|
1458
|
+
if not isinstance(entry, Mapping):
|
|
1459
|
+
continue
|
|
1460
|
+
dep_id = str(entry.get("feature_id") or entry.get("bug_id") or "").strip()
|
|
1461
|
+
if dep_id:
|
|
1462
|
+
candidates.append(family.state_dir / dep_id / "status.json")
|
|
1463
|
+
snapshots: dict[Path, str] = {}
|
|
1464
|
+
for candidate in candidates:
|
|
1465
|
+
try:
|
|
1466
|
+
if candidate.is_file():
|
|
1467
|
+
snapshots[candidate] = candidate.read_text(encoding="utf-8")
|
|
1468
|
+
except OSError:
|
|
1469
|
+
continue
|
|
1470
|
+
return snapshots
|
|
1471
|
+
|
|
1472
|
+
|
|
1354
1473
|
def _record_setup_failure(
|
|
1355
1474
|
family: RunnerFamily,
|
|
1356
1475
|
invocation: RunnerInvocation,
|
|
@@ -1359,14 +1478,12 @@ def _record_setup_failure(
|
|
|
1359
1478
|
status_root: Path,
|
|
1360
1479
|
base_branch: str,
|
|
1361
1480
|
branch_name: str,
|
|
1362
|
-
*,
|
|
1363
|
-
worktree_runtime=None,
|
|
1364
1481
|
) -> str:
|
|
1365
1482
|
"""Record setup-time infra failures on a task branch when one exists."""
|
|
1366
1483
|
if status_root.resolve() == project_root.resolve() and current_branch(project_root) != branch_name:
|
|
1367
1484
|
return "infra_error"
|
|
1368
|
-
status_family =
|
|
1369
|
-
status_invocation =
|
|
1485
|
+
status_family = family
|
|
1486
|
+
status_invocation = invocation
|
|
1370
1487
|
start = start_item(status_family, status_invocation, item_id, status_root)
|
|
1371
1488
|
if start.ok:
|
|
1372
1489
|
commit_pre_branch_bookkeeping(status_root, status_family, item_id)
|
|
@@ -1383,64 +1500,16 @@ def _record_setup_failure(
|
|
|
1383
1500
|
new_status = _status_from_update(update) if update.ok else "infra_error"
|
|
1384
1501
|
if update.ok:
|
|
1385
1502
|
commit_final_bookkeeping(status_root, status_family, item_id, new_status)
|
|
1386
|
-
wip = _save_failure_wip(status_root, family, item_id, new_status
|
|
1503
|
+
wip = _save_failure_wip(status_root, family, item_id, new_status)
|
|
1387
1504
|
else:
|
|
1388
1505
|
wip = None
|
|
1389
1506
|
if (
|
|
1390
|
-
|
|
1391
|
-
and current_branch(project_root) == branch_name
|
|
1507
|
+
current_branch(project_root) == branch_name
|
|
1392
1508
|
and getattr(wip, "ok", True)
|
|
1393
1509
|
):
|
|
1394
1510
|
branch_ensure_return(project_root, base_branch, branch_name)
|
|
1395
1511
|
return new_status
|
|
1396
1512
|
|
|
1397
|
-
def _use_worktree_for_family(env: RunnerEnvironment, family: RunnerFamily) -> bool:
|
|
1398
|
-
return env.use_worktree and family.kind in {"feature", "bugfix"}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
def _family_for_execution_root(family: RunnerFamily, project_root: Path, execution_root: Path) -> RunnerFamily:
|
|
1402
|
-
"""Return family paths rooted in the task execution checkout."""
|
|
1403
|
-
if execution_root.resolve() == project_root.resolve():
|
|
1404
|
-
return family
|
|
1405
|
-
return RunnerFamily(
|
|
1406
|
-
kind=family.kind,
|
|
1407
|
-
id_prefix=family.id_prefix,
|
|
1408
|
-
list_key=family.list_key,
|
|
1409
|
-
list_arg=family.list_arg,
|
|
1410
|
-
item_id_arg=family.item_id_arg,
|
|
1411
|
-
state_dir=_path_in_execution_root(family.state_dir, project_root, execution_root),
|
|
1412
|
-
plan_path=_path_in_execution_root(family.plan_path, project_root, execution_root),
|
|
1413
|
-
updater_script=family.updater_script,
|
|
1414
|
-
prompt_script=family.prompt_script,
|
|
1415
|
-
branch_prefix=family.branch_prefix,
|
|
1416
|
-
artifact_root_name=family.artifact_root_name,
|
|
1417
|
-
)
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
def _invocation_for_execution_family(invocation: RunnerInvocation, family: RunnerFamily) -> RunnerInvocation:
|
|
1421
|
-
return RunnerInvocation(
|
|
1422
|
-
action=invocation.action,
|
|
1423
|
-
list_path=family.plan_path,
|
|
1424
|
-
item_id=invocation.item_id,
|
|
1425
|
-
item_filter=invocation.item_filter,
|
|
1426
|
-
max_retries=invocation.max_retries,
|
|
1427
|
-
max_infra_retries=invocation.max_infra_retries,
|
|
1428
|
-
dry_run=invocation.dry_run,
|
|
1429
|
-
clean=invocation.clean,
|
|
1430
|
-
no_reset=invocation.no_reset,
|
|
1431
|
-
resume_phase=invocation.resume_phase,
|
|
1432
|
-
help_requested=invocation.help_requested,
|
|
1433
|
-
unknown_args=invocation.unknown_args,
|
|
1434
|
-
raw_args=invocation.raw_args,
|
|
1435
|
-
)
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
def _path_in_execution_root(path: Path, project_root: Path, execution_root: Path) -> Path:
|
|
1439
|
-
try:
|
|
1440
|
-
return execution_root / path.resolve().relative_to(project_root.resolve())
|
|
1441
|
-
except ValueError:
|
|
1442
|
-
return path
|
|
1443
|
-
|
|
1444
1513
|
|
|
1445
1514
|
def _latest_session_id(state_dir: Path, item_id: str) -> str:
|
|
1446
1515
|
sessions_dir = state_dir / item_id / "sessions"
|
|
@@ -1488,7 +1557,6 @@ def _write_session_status(
|
|
|
1488
1557
|
task_type: str,
|
|
1489
1558
|
base_branch: str,
|
|
1490
1559
|
active_dev_branch: str,
|
|
1491
|
-
worktree_path: Path | None = None,
|
|
1492
1560
|
reason: str = "",
|
|
1493
1561
|
fatal_error_code: str = "",
|
|
1494
1562
|
checkpoint_state: object | None = None,
|
|
@@ -1501,19 +1569,13 @@ def _write_session_status(
|
|
|
1501
1569
|
"base_branch": base_branch,
|
|
1502
1570
|
"active_dev_branch": active_dev_branch,
|
|
1503
1571
|
}
|
|
1504
|
-
if worktree_path is not None:
|
|
1505
|
-
payload["worktree_path"] = str(worktree_path)
|
|
1506
1572
|
if reason:
|
|
1507
1573
|
payload["reason"] = reason
|
|
1508
1574
|
if fatal_error_code:
|
|
1509
1575
|
payload["fatal_error_code"] = fatal_error_code
|
|
1510
1576
|
if isinstance(checkpoint_state, dict):
|
|
1511
1577
|
payload["checkpoint_state"] = checkpoint_state
|
|
1512
|
-
session_paths.session_status_json
|
|
1513
|
-
session_paths.session_status_json.write_text(
|
|
1514
|
-
json.dumps(payload, indent=2, sort_keys=True) + "\n",
|
|
1515
|
-
encoding="utf-8",
|
|
1516
|
-
)
|
|
1578
|
+
write_json_atomic(session_paths.session_status_json, payload, sort_keys=True)
|
|
1517
1579
|
|
|
1518
1580
|
def _status_from_update(update_result) -> str:
|
|
1519
1581
|
if isinstance(update_result.data, dict):
|
|
@@ -1529,12 +1591,17 @@ def _session_id(item_id: str) -> str:
|
|
|
1529
1591
|
return f"{item_id}-{time.strftime('%Y%m%d%H%M%S')}-{time.time_ns()}"
|
|
1530
1592
|
|
|
1531
1593
|
|
|
1532
|
-
def _continuation_summary_path(
|
|
1594
|
+
def _continuation_summary_path(
|
|
1595
|
+
project_root: Path,
|
|
1596
|
+
family: RunnerFamily,
|
|
1597
|
+
item_id: str,
|
|
1598
|
+
prompt: PromptGenerationResult | None,
|
|
1599
|
+
*,
|
|
1600
|
+
metadata: dict[str, object] | None = None,
|
|
1601
|
+
) -> Path:
|
|
1533
1602
|
if prompt and prompt.artifact_path:
|
|
1534
1603
|
return prompt.artifact_path / "continuation-summary.md"
|
|
1535
|
-
|
|
1536
|
-
return project_root / ".prizmkit" / "specs" / item_id / "continuation-summary.md"
|
|
1537
|
-
return project_root / ".prizmkit" / family.artifact_root_name / item_id / "continuation-summary.md"
|
|
1604
|
+
return _artifact_path_for_item(project_root, family, item_id, dict(metadata or {})) / "continuation-summary.md"
|
|
1538
1605
|
|
|
1539
1606
|
|
|
1540
1607
|
def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path) -> RunnerInvocation:
|
|
@@ -1548,8 +1615,6 @@ def _resolve_invocation_paths(invocation: RunnerInvocation, project_root: Path)
|
|
|
1548
1615
|
max_retries=invocation.max_retries,
|
|
1549
1616
|
max_infra_retries=invocation.max_infra_retries,
|
|
1550
1617
|
dry_run=invocation.dry_run,
|
|
1551
|
-
clean=invocation.clean,
|
|
1552
|
-
no_reset=invocation.no_reset,
|
|
1553
1618
|
resume_phase=invocation.resume_phase,
|
|
1554
1619
|
help_requested=invocation.help_requested,
|
|
1555
1620
|
unknown_args=invocation.unknown_args,
|