prizmkit 1.1.167 → 1.1.170

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "frameworkVersion": "1.1.167",
3
- "bundledAt": "2026-08-02T23:32:27.810Z",
4
- "bundledFrom": "118f7b4"
2
+ "frameworkVersion": "1.1.170",
3
+ "bundledAt": "2026-08-05T18:03:01.414Z",
4
+ "bundledFrom": "e849c27"
5
5
  }
@@ -561,6 +561,25 @@ class GitPlanResult:
561
561
  return True
562
562
 
563
563
 
564
+ @dataclass(frozen=True)
565
+ class WipRestoreResult:
566
+ """Observable result of restoring one exact Runtime-owned WIP tip."""
567
+
568
+ status: str
569
+ reason: str
570
+ wip_head: str = ""
571
+ restored_head: str = ""
572
+ results: tuple[GitCommandResult, ...] = ()
573
+
574
+ @property
575
+ def ok(self) -> bool:
576
+ return self.status in {"restored", "not_needed"}
577
+
578
+ @property
579
+ def restored(self) -> bool:
580
+ return self.status == "restored"
581
+
582
+
564
583
  def _git(*args: str, allow_failure: bool = False, description: str = "") -> GitCommand:
565
584
  return GitCommand(args=args, allow_failure=allow_failure, description=description)
566
585
 
@@ -888,6 +907,178 @@ def worktree_save_wip(runtime: WorktreeRuntimeContext) -> GitPlanResult:
888
907
  return branch_save_wip(runtime.worktree_path, runtime.context.working_branch)
889
908
 
890
909
 
910
+ def _matches_runtime_wip_identity(
911
+ subject: str,
912
+ body: str,
913
+ *,
914
+ family_kind: str,
915
+ item_id: str,
916
+ working_branch: str,
917
+ ) -> bool:
918
+ failure_subject = re.fullmatch(
919
+ rf"wip\({re.escape(item_id)}\): preserve {re.escape(family_kind)} [a-z][a-z0-9_]* state",
920
+ subject,
921
+ )
922
+ failure_body = "Pipeline preserved task branch work without merging it to the base branch."
923
+ if failure_subject is not None and body == failure_body:
924
+ return True
925
+
926
+ interruption_subject = f"wip({working_branch}): interrupted — uncommitted work saved"
927
+ interruption_body = (
928
+ "Pipeline was interrupted by signal. This commit preserves work-in-progress.\n\n"
929
+ f"To resume: git checkout {working_branch}"
930
+ )
931
+ return subject == interruption_subject and body == interruption_body
932
+
933
+
934
+ def restore_runtime_wip(
935
+ project_root: Path,
936
+ *,
937
+ family_kind: str,
938
+ item_id: str,
939
+ working_branch: str,
940
+ ) -> WipRestoreResult:
941
+ """Rehydrate one exact Runtime-owned WIP tip into the reused task workspace."""
942
+ results: list[GitCommandResult] = []
943
+ active = run_git_command(project_root, ("rev-parse", "--abbrev-ref", "HEAD"))
944
+ results.append(active)
945
+ if active.return_code != 0:
946
+ return WipRestoreResult("failed", "runtime_wip_branch_unavailable", results=tuple(results))
947
+ if active.stdout.strip() != working_branch:
948
+ return WipRestoreResult("failed", "runtime_wip_branch_mismatch", results=tuple(results))
949
+
950
+ unmerged = run_git_command(project_root, ("ls-files", "-u"))
951
+ results.append(unmerged)
952
+ if unmerged.return_code != 0:
953
+ return WipRestoreResult("failed", "runtime_wip_merge_state_unavailable", results=tuple(results))
954
+ if unmerged.stdout.strip():
955
+ return WipRestoreResult("failed", "runtime_wip_unresolved_merge", results=tuple(results))
956
+
957
+ identity = run_git_command(project_root, ("show", "-s", "--format=%H%x00%P%x00%s%x00%b", "HEAD"))
958
+ results.append(identity)
959
+ if identity.return_code != 0:
960
+ return WipRestoreResult("failed", "runtime_wip_identity_unavailable", results=tuple(results))
961
+ parts = identity.stdout.rstrip("\n").split("\0", 3)
962
+ if len(parts) != 4:
963
+ return WipRestoreResult("failed", "runtime_wip_identity_invalid", results=tuple(results))
964
+ head, parents_text, subject, body = parts
965
+ body = body.rstrip("\n")
966
+ if not _matches_runtime_wip_identity(
967
+ subject,
968
+ body,
969
+ family_kind=family_kind,
970
+ item_id=item_id,
971
+ working_branch=working_branch,
972
+ ):
973
+ return WipRestoreResult(
974
+ "not_needed",
975
+ "runtime_wip_not_found",
976
+ wip_head=head,
977
+ restored_head=head,
978
+ results=tuple(results),
979
+ )
980
+
981
+ staged = run_git_command(project_root, ("diff", "--cached", "--name-only", "-z"))
982
+ results.append(staged)
983
+ if staged.return_code != 0:
984
+ return WipRestoreResult(
985
+ "failed",
986
+ "runtime_wip_staged_state_unavailable",
987
+ wip_head=head,
988
+ restored_head=head,
989
+ results=tuple(results),
990
+ )
991
+ if staged.stdout.strip("\0"):
992
+ return WipRestoreResult(
993
+ "failed",
994
+ "runtime_wip_staged_changes",
995
+ wip_head=head,
996
+ restored_head=head,
997
+ results=tuple(results),
998
+ )
999
+
1000
+ parents = parents_text.split()
1001
+ if len(parents) != 1:
1002
+ return WipRestoreResult(
1003
+ "failed",
1004
+ "runtime_wip_parent_invalid",
1005
+ wip_head=head,
1006
+ restored_head=head,
1007
+ results=tuple(results),
1008
+ )
1009
+ parent = parents[0]
1010
+ changed = run_git_command(
1011
+ project_root,
1012
+ ("diff-tree", "--no-commit-id", "--name-only", "--no-renames", "-r", "-z", head),
1013
+ )
1014
+ results.append(changed)
1015
+ if changed.return_code != 0:
1016
+ return WipRestoreResult(
1017
+ "failed",
1018
+ "runtime_wip_paths_unavailable",
1019
+ wip_head=head,
1020
+ restored_head=head,
1021
+ results=tuple(results),
1022
+ )
1023
+ wip_paths = {path for path in changed.stdout.split("\0") if path}
1024
+ if not wip_paths:
1025
+ return WipRestoreResult(
1026
+ "failed",
1027
+ "runtime_wip_empty_commit",
1028
+ wip_head=head,
1029
+ restored_head=head,
1030
+ results=tuple(results),
1031
+ )
1032
+
1033
+ reset = run_git_command(project_root, ("reset", "--mixed", parent))
1034
+ results.append(reset)
1035
+ if reset.return_code != 0:
1036
+ return WipRestoreResult(
1037
+ "failed",
1038
+ "runtime_wip_restore_failed",
1039
+ wip_head=head,
1040
+ restored_head=head,
1041
+ results=tuple(results),
1042
+ )
1043
+
1044
+ restored_head_result = run_git_command(project_root, ("rev-parse", "HEAD"))
1045
+ results.append(restored_head_result)
1046
+ visible_paths, visible_result = visible_task_paths(project_root)
1047
+ results.append(visible_result)
1048
+ visible_set = set(visible_paths)
1049
+ verified = (
1050
+ restored_head_result.return_code == 0
1051
+ and restored_head_result.stdout.strip() == parent
1052
+ and visible_result.return_code == 0
1053
+ and wip_paths.issubset(visible_set)
1054
+ )
1055
+ if not verified:
1056
+ rollback = run_git_command(project_root, ("reset", "--mixed", head))
1057
+ results.append(rollback)
1058
+ reason = (
1059
+ "runtime_wip_restore_rollback_failed"
1060
+ if rollback.return_code != 0
1061
+ else "runtime_wip_restore_verification_failed"
1062
+ )
1063
+ current = run_git_command(project_root, ("rev-parse", "HEAD"))
1064
+ results.append(current)
1065
+ return WipRestoreResult(
1066
+ "failed",
1067
+ reason,
1068
+ wip_head=head,
1069
+ restored_head=current.stdout.strip() if current.return_code == 0 else "",
1070
+ results=tuple(results),
1071
+ )
1072
+
1073
+ return WipRestoreResult(
1074
+ "restored",
1075
+ "runtime_wip_restored",
1076
+ wip_head=head,
1077
+ restored_head=parent,
1078
+ results=tuple(results),
1079
+ )
1080
+
1081
+
891
1082
  def branch_ensure_return(project_root: Path, base_branch: str, working_branch: str = "") -> GitPlanResult:
892
1083
  """Commit Git-visible task WIP when needed, then return the caller checkout to base."""
893
1084
  active = current_branch(project_root)
@@ -29,6 +29,7 @@ from .gitops import (
29
29
  guarded_worktree_remove,
30
30
  materialize_worktree_support_assets,
31
31
  merge_linked_worktree,
32
+ restore_runtime_wip,
32
33
  run_git_command,
33
34
  run_git_plan,
34
35
  worktree_runtime_context,
@@ -228,7 +229,7 @@ def _run_pipeline(family: RunnerFamily, invocation: RunnerInvocation, paths) ->
228
229
  return PipelineRunResult(False, processed, "item_failed", final_status, details)
229
230
 
230
231
 
231
- _COMPLETION_COMPATIBLE_STATUSES = {"completed", "auto_skipped"}
232
+ _COMPLETION_COMPATIBLE_STATUSES = {"completed"}
232
233
 
233
234
 
234
235
  def _completion_compatible_statuses(family: RunnerFamily) -> set[str]:
@@ -565,7 +566,8 @@ def _process_item_locked(
565
566
  branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch)
566
567
  branch_context = BranchContext(base_branch, branch_name, paths.project_root)
567
568
  worktree_runtime = None
568
- if checkout is not None and checkout.is_active:
569
+ reusing_checkout = checkout is not None and checkout.is_active
570
+ if reusing_checkout:
569
571
  use_worktree = checkout.uses_worktree
570
572
  worktree_path = Path(checkout.worktree_path) if checkout.worktree_path else None
571
573
  else:
@@ -641,6 +643,36 @@ def _process_item_locked(
641
643
  if not branch_result.ok:
642
644
  return "infra_error"
643
645
 
646
+ if reusing_checkout:
647
+ restored_wip = restore_runtime_wip(
648
+ execution_root,
649
+ family_kind=family.kind,
650
+ item_id=item_id,
651
+ working_branch=branch_name,
652
+ )
653
+ if not restored_wip.ok:
654
+ _emit_warning(
655
+ f"Runtime WIP recovery failed for {item_id}: {restored_wip.reason}; "
656
+ "AI launch was blocked and the preserved checkout remains active"
657
+ )
658
+ return _record_setup_failure(
659
+ family,
660
+ invocation,
661
+ item_id,
662
+ paths.project_root,
663
+ execution_root,
664
+ base_branch,
665
+ branch_name,
666
+ worktree_runtime=worktree_runtime,
667
+ )
668
+ if restored_wip.restored:
669
+ _emit_info(
670
+ f"Recovery: restored Runtime-owned WIP {restored_wip.wip_head[:12]} "
671
+ f"into the workspace for {item_id}"
672
+ )
673
+ else:
674
+ _emit_info(f"Recovery: no Runtime-owned WIP tip to restore for {item_id}")
675
+
644
676
  _emit_item_header(family, invocation, item_id, metadata)
645
677
  status_root = execution_root if use_worktree else paths.project_root
646
678
  status_family = _family_for_execution_root(family, paths.project_root, status_root)
@@ -35,6 +35,7 @@ from utils import (
35
35
  read_checkpoint_cursor,
36
36
  dependency_rank_map,
37
37
  causal_reset_selection,
38
+ orphaned_auto_skipped_ids,
38
39
  )
39
40
 
40
41
 
@@ -475,6 +476,44 @@ def auto_skip_blocked_bugs(bug_list_path, state_dir, blocking_bug_id=None):
475
476
  return skipped_info
476
477
 
477
478
 
479
+ def reconcile_orphaned_auto_skipped_bugs(bug_list_path, state_dir):
480
+ """Restore auto-skipped bugs that have no current blocking root."""
481
+ data, err = load_json_file(bug_list_path)
482
+ if err:
483
+ raise RuntimeError("Cannot load bug fix list for orphan recovery: {}".format(err))
484
+ bugs = data.get("bugs", [])
485
+ orphan_ids = orphaned_auto_skipped_ids(
486
+ bugs,
487
+ blocking_root_statuses=RESET_BLOCKING_ROOT_STATUSES,
488
+ item_label="Bug",
489
+ )
490
+ if not orphan_ids:
491
+ return []
492
+
493
+ orphan_set = set(orphan_ids)
494
+ for bug in bugs:
495
+ if isinstance(bug, dict) and bug.get("id") in orphan_set:
496
+ bug["status"] = "pending"
497
+ err = write_json_file(bug_list_path, data)
498
+ if err:
499
+ raise RuntimeError("Failed to recover orphaned bugs: {}".format(err))
500
+
501
+ for bug_id in orphan_ids:
502
+ bs = load_bug_status(state_dir, bug_id)
503
+ bs["updated_at"] = now_iso()
504
+ err = save_bug_status(state_dir, bug_id, bs)
505
+ if err:
506
+ raise RuntimeError("Failed to save recovered bug status: {}".format(err))
507
+
508
+ print(
509
+ "[auto-skip] recovered {} orphaned bug(s): {}".format(
510
+ len(orphan_ids), ", ".join(orphan_ids)
511
+ ),
512
+ file=sys.stderr,
513
+ )
514
+ return list(orphan_ids)
515
+
516
+
478
517
  # ---------------------------------------------------------------------------
479
518
  # Action: get_next
480
519
  # ---------------------------------------------------------------------------
@@ -491,6 +530,14 @@ def action_get_next(bug_list_data, state_dir, project_root=None, bug_list_path=N
491
530
  """
492
531
  if bug_list_path:
493
532
  auto_skip_blocked_bugs(bug_list_path, state_dir)
533
+ try:
534
+ reconcile_orphaned_auto_skipped_bugs(bug_list_path, state_dir)
535
+ except ValueError:
536
+ print("PIPELINE_BLOCKED")
537
+ return
538
+ except RuntimeError as exc:
539
+ error_out(str(exc))
540
+ return
494
541
  refreshed, refresh_error = load_json_file(bug_list_path)
495
542
  if refresh_error:
496
543
  error_out("Cannot reload bug fix list after auto-skip: {}".format(refresh_error))
@@ -785,10 +832,19 @@ def action_update(args, bug_list_path, state_dir):
785
832
  return
786
833
 
787
834
  auto_skipped_bugs = []
835
+ recovered_auto_skipped = []
788
836
  if new_status in RESET_BLOCKING_ROOT_STATUSES:
789
837
  auto_skipped_bugs = auto_skip_blocked_bugs(
790
838
  bug_list_path, state_dir, bug_id
791
839
  )
840
+ else:
841
+ try:
842
+ recovered_auto_skipped = reconcile_orphaned_auto_skipped_bugs(
843
+ bug_list_path, state_dir
844
+ )
845
+ except (ValueError, RuntimeError) as exc:
846
+ error_out(str(exc))
847
+ return
792
848
 
793
849
  summary = {
794
850
  "action": "update",
@@ -804,6 +860,8 @@ def action_update(args, bug_list_path, state_dir):
804
860
  }
805
861
  if auto_skipped_bugs:
806
862
  summary["auto_skipped"] = [info["bug_id"] for info in auto_skipped_bugs]
863
+ if recovered_auto_skipped:
864
+ summary["recovered_auto_skipped"] = recovered_auto_skipped
807
865
  if session_status in ("commit_missing", "docs_missing", "merge_conflict"):
808
866
  summary["degraded_reason"] = session_status
809
867
  summary["restart_policy"] = "finalization_retry"
@@ -992,6 +1050,14 @@ def action_status(bug_list_data, state_dir, project_root=None):
992
1050
  for bug in bugs
993
1051
  if isinstance(bug, dict) and bug.get("id")
994
1052
  }
1053
+ try:
1054
+ orphaned_ids = set(orphaned_auto_skipped_ids(
1055
+ bugs,
1056
+ blocking_root_statuses=RESET_BLOCKING_ROOT_STATUSES,
1057
+ item_label="Bug",
1058
+ ))
1059
+ except ValueError:
1060
+ orphaned_ids = set()
995
1061
  bug_lines = []
996
1062
 
997
1063
  for bug in bugs:
@@ -1049,15 +1115,18 @@ def action_status(bug_list_data, state_dir, project_root=None):
1049
1115
  elif bstatus == "needs_info":
1050
1116
  detail = " (needs more info)"
1051
1117
  elif bstatus == "auto_skipped":
1052
- blockers = [
1053
- dependency_id
1054
- for dependency_id in bug.get("dependencies", [])
1055
- if status_map.get(dependency_id, "pending")
1056
- in RESET_BLOCKING_ROOT_STATUSES | {"auto_skipped"}
1057
- ]
1058
- detail = " (blocked by {})".format(
1059
- ", ".join(blockers) if blockers else "dependency chain"
1060
- )
1118
+ if bid in orphaned_ids:
1119
+ detail = " (orphaned: no blocking dependency)"
1120
+ else:
1121
+ blockers = [
1122
+ dependency_id
1123
+ for dependency_id in bug.get("dependencies", [])
1124
+ if status_map.get(dependency_id, "pending")
1125
+ in RESET_BLOCKING_ROOT_STATUSES | {"auto_skipped"}
1126
+ ]
1127
+ detail = " (blocked by {})".format(
1128
+ ", ".join(blockers) if blockers else "dependency chain"
1129
+ )
1061
1130
 
1062
1131
  # Colorize
1063
1132
  if bstatus == "completed":
@@ -1302,6 +1371,14 @@ def action_start(args, bug_list_path, state_dir):
1302
1371
  error_out("Failed to update .prizmkit/plans/bug-fix-list.json: {}".format(err))
1303
1372
  return
1304
1373
 
1374
+ try:
1375
+ recovered_auto_skipped = reconcile_orphaned_auto_skipped_bugs(
1376
+ bug_list_path, state_dir
1377
+ )
1378
+ except (ValueError, RuntimeError) as exc:
1379
+ error_out(str(exc))
1380
+ return
1381
+
1305
1382
  result = {
1306
1383
  "action": "start",
1307
1384
  "bug_id": bug_id,
@@ -1311,6 +1388,8 @@ def action_start(args, bug_list_path, state_dir):
1311
1388
  "infra_error_count": bs.get("infra_error_count", 0),
1312
1389
  "updated_at": bs["updated_at"],
1313
1390
  }
1391
+ if recovered_auto_skipped:
1392
+ result["recovered_auto_skipped"] = recovered_auto_skipped
1314
1393
  print(json.dumps(result, indent=2, ensure_ascii=False))
1315
1394
 
1316
1395