prizmkit 1.1.198 → 1.1.199

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.198",
3
- "bundledAt": "2026-11-22T04:55:25.219Z",
4
- "bundledFrom": "46b197d"
2
+ "frameworkVersion": "1.1.199",
3
+ "bundledAt": "2026-11-22T06:16:45.333Z",
4
+ "bundledFrom": "12335b7"
5
5
  }
@@ -295,21 +295,43 @@ def _wip_pathspecs(paths: Sequence[str] | None) -> tuple[str, ...]:
295
295
  return _literal_pathspecs(paths) if paths is not None else (".",)
296
296
 
297
297
 
298
+ def partition_addable_paths(
299
+ add_paths: Sequence[str],
300
+ indexed_result: GitCommandResult,
301
+ ) -> tuple[tuple[str, ...], tuple[str, ...]]:
302
+ """Split addable paths into tracked index entries and untracked paths."""
303
+ indexed_paths = {path for path in indexed_result.stdout.split("\0") if path}
304
+ tracked = tuple(path for path in add_paths if path in indexed_paths)
305
+ untracked = tuple(path for path in add_paths if path not in indexed_paths)
306
+ return tracked, untracked
307
+
308
+
298
309
  def branch_save_wip_plan(
299
310
  context: BranchContext,
300
311
  *,
301
312
  commit_paths: Sequence[str] | None = None,
302
313
  add_paths: Sequence[str] | None = None,
314
+ tracked_add_paths: Sequence[str] | None = None,
303
315
  ) -> GitCommandPlan:
304
316
  """Plan WIP preservation that fails when task state cannot be committed."""
305
317
  commit_pathspecs = _wip_pathspecs(commit_paths)
306
- add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
307
318
  commands = [
308
319
  _git("rev-parse", "--abbrev-ref", "HEAD", description="verify current branch"),
309
320
  _git("ls-files", "-u", description="require no unmerged paths before WIP commit"),
310
321
  ]
311
- if add_pathspecs:
312
- commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible work"))
322
+ if tracked_add_paths is None:
323
+ add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
324
+ if add_pathspecs:
325
+ commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible work"))
326
+ else:
327
+ if tracked_add_paths:
328
+ commands.append(
329
+ _git("add", "-u", "--", *_literal_pathspecs(tracked_add_paths), description="stage tracked Git-visible work")
330
+ )
331
+ if add_paths:
332
+ commands.append(
333
+ _git("add", "-A", "--", *_literal_pathspecs(add_paths), description="stage untracked Git-visible work")
334
+ )
313
335
  commands.extend(
314
336
  (
315
337
  _git(
@@ -343,18 +365,41 @@ def branch_ensure_return_plan(
343
365
  *,
344
366
  commit_paths: Sequence[str] | None = None,
345
367
  add_paths: Sequence[str] | None = None,
368
+ tracked_add_paths: Sequence[str] | None = None,
346
369
  ) -> GitCommandPlan:
347
370
  """Plan a fail-closed WIP commit followed by a clean base return."""
348
371
  commit_pathspecs = _wip_pathspecs(commit_paths)
349
- add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
350
372
  commands = [
351
373
  _git("rebase", "--abort", allow_failure=True, description="abort in-progress rebase"),
352
374
  _git("rev-parse", "--abbrev-ref", "HEAD", description="detect current branch"),
353
375
  _git("ls-files", "-u", description="require no unmerged paths before WIP commit"),
354
376
  _git("status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES, description="detect WIP before checkout"),
355
377
  ]
356
- if add_pathspecs:
357
- commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible WIP before checkout"))
378
+ if tracked_add_paths is None:
379
+ add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
380
+ if add_pathspecs:
381
+ commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible WIP before checkout"))
382
+ else:
383
+ if tracked_add_paths:
384
+ commands.append(
385
+ _git(
386
+ "add",
387
+ "-u",
388
+ "--",
389
+ *_literal_pathspecs(tracked_add_paths),
390
+ description="stage tracked Git-visible WIP before checkout",
391
+ )
392
+ )
393
+ if add_paths:
394
+ commands.append(
395
+ _git(
396
+ "add",
397
+ "-A",
398
+ "--",
399
+ *_literal_pathspecs(add_paths),
400
+ description="stage untracked Git-visible WIP before checkout",
401
+ )
402
+ )
358
403
  commands.extend(
359
404
  (
360
405
  _git(
@@ -543,9 +588,15 @@ def branch_save_wip(project_root: Path, working_branch: str) -> GitPlanResult:
543
588
  add_paths, indexed = addable_task_paths(project_root, paths)
544
589
  if indexed.return_code != 0:
545
590
  return _status_failure_plan(default_plan.name, indexed, "resolve task-visible WIP paths")
591
+ tracked_add, untracked_add = partition_addable_paths(add_paths, indexed)
546
592
  return run_git_plan(
547
593
  project_root,
548
- branch_save_wip_plan(context, commit_paths=paths, add_paths=add_paths),
594
+ branch_save_wip_plan(
595
+ context,
596
+ commit_paths=paths,
597
+ add_paths=untracked_add,
598
+ tracked_add_paths=tracked_add,
599
+ ),
549
600
  )
550
601
 
551
602
 
@@ -767,9 +818,15 @@ def branch_ensure_return(project_root: Path, base_branch: str, working_branch: s
767
818
  add_paths, indexed = addable_task_paths(project_root, paths)
768
819
  if indexed.return_code != 0:
769
820
  return _status_failure_plan("branch_ensure_return", indexed, "resolve task-visible WIP paths before base return")
821
+ tracked_add, untracked_add = partition_addable_paths(add_paths, indexed)
770
822
  return run_git_plan(
771
823
  project_root,
772
- branch_ensure_return_plan(context, commit_paths=paths, add_paths=add_paths),
824
+ branch_ensure_return_plan(
825
+ context,
826
+ commit_paths=paths,
827
+ add_paths=untracked_add,
828
+ tracked_add_paths=tracked_add,
829
+ ),
773
830
  )
774
831
 
775
832
 
@@ -19,6 +19,7 @@ from .gitops import (
19
19
  addable_task_paths,
20
20
  literal_pathspecs,
21
21
  parse_status_record_paths,
22
+ partition_addable_paths,
22
23
  run_git_command,
23
24
  visible_task_paths,
24
25
  )
@@ -182,6 +183,43 @@ def _changed_paths_in(project_root: Path, paths: Sequence[str]) -> tuple[str, ..
182
183
  return parse_status_record_paths(result.stdout)
183
184
 
184
185
 
186
+ def _stage_exact_paths(
187
+ project_root: Path,
188
+ paths: Sequence[str],
189
+ *,
190
+ add_paths: Sequence[str] | None = None,
191
+ indexed_result: GitCommandResult | None = None,
192
+ ) -> GitCommandResult | None:
193
+ """Stage tracked entries via ``git add -u`` and untracked entries via ``git add -A``.
194
+
195
+ Passing an already-tracked path under an ignored parent directory to ``git add -A``
196
+ causes Git to exit 1 with an ignored-file hint; using ``add -u`` for indexed paths
197
+ avoids false staging failures while keeping untracked ignored paths excluded.
198
+ """
199
+ if add_paths is None or indexed_result is None:
200
+ add_paths, indexed_result = addable_task_paths(project_root, paths)
201
+ if indexed_result.return_code != 0:
202
+ return indexed_result
203
+ if not add_paths:
204
+ return None
205
+ tracked_paths, untracked_paths = partition_addable_paths(add_paths, indexed_result)
206
+ if tracked_paths:
207
+ tracked_add = run_git_command(
208
+ project_root,
209
+ ("add", "-u", "--", *literal_pathspecs(tracked_paths)),
210
+ )
211
+ if tracked_add.return_code != 0:
212
+ return tracked_add
213
+ if untracked_paths:
214
+ untracked_add = run_git_command(
215
+ project_root,
216
+ ("add", "-A", "--", *literal_pathspecs(untracked_paths)),
217
+ )
218
+ if untracked_add.return_code != 0:
219
+ return untracked_add
220
+ return None
221
+
222
+
185
223
  def commit_bookkeeping_changes(
186
224
  project_root: Path,
187
225
  family: RunnerFamily,
@@ -197,10 +235,10 @@ def commit_bookkeeping_changes(
197
235
  )
198
236
  if not paths:
199
237
  return BookkeepingResult(attempted=False, committed=False)
238
+ stage_failure = _stage_exact_paths(project_root, paths)
239
+ if stage_failure is not None:
240
+ return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
200
241
  pathspecs = literal_pathspecs(paths)
201
- add = run_git_command(project_root, ("add", "-A", "--", *pathspecs))
202
- if add.return_code != 0:
203
- return BookkeepingResult(attempted=True, committed=False, result=add)
204
242
  result = run_git_command(project_root, ("commit", "--no-verify", "-m", message, "--", *pathspecs))
205
243
  return BookkeepingResult(attempted=True, committed=result.return_code == 0, result=result)
206
244
 
@@ -279,9 +317,14 @@ def _commit_visible_task_paths(project_root: Path, commit_message_args: tuple[st
279
317
  if indexed_result.return_code != 0:
280
318
  return BookkeepingResult(attempted=True, committed=False, result=indexed_result)
281
319
  if add_paths:
282
- add_result = run_git_command(project_root, ("add", "-A", "--", *literal_pathspecs(add_paths)))
283
- if add_result.return_code != 0:
284
- return BookkeepingResult(attempted=True, committed=False, result=add_result)
320
+ stage_failure = _stage_exact_paths(
321
+ project_root,
322
+ paths,
323
+ add_paths=add_paths,
324
+ indexed_result=indexed_result,
325
+ )
326
+ if stage_failure is not None:
327
+ return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
285
328
  result = run_git_command(
286
329
  project_root,
287
330
  ("commit", "--no-verify", *commit_message_args, "--", *literal_pathspecs(paths)),
@@ -394,10 +437,10 @@ def sync_terminal_failure_bookkeeping_to_base(
394
437
  changed = _changed_paths_in(project_root, git_candidates)
395
438
  if not changed:
396
439
  return BookkeepingResult(attempted=False, committed=False)
440
+ stage_failure = _stage_exact_paths(project_root, changed)
441
+ if stage_failure is not None:
442
+ return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
397
443
  pathspecs = literal_pathspecs(changed)
398
- add = run_git_command(project_root, ("add", "-A", "--", *pathspecs))
399
- if add.return_code != 0:
400
- return BookkeepingResult(attempted=True, committed=False, result=add)
401
444
  commit = run_git_command(
402
445
  project_root,
403
446
  ("commit", "--no-verify", "-m", f"chore({item_id}): record {family.kind} status {status}", "--", *pathspecs),
@@ -10,7 +10,7 @@ import sys
10
10
  import tempfile
11
11
  import threading
12
12
  import time
13
- from collections.abc import Iterator, Mapping
13
+ from collections.abc import Iterator, Mapping, Sequence
14
14
  from contextlib import contextmanager
15
15
  from pathlib import Path
16
16
 
@@ -286,6 +286,62 @@ def _emit_warning(message: str) -> None:
286
286
  _emit_info(message, level="WARN")
287
287
 
288
288
 
289
+ def _emit_bookkeeping_failure(label: str, item_id: str, result_obj) -> None:
290
+ """Emit structured Git failure diagnostics without altering flow control."""
291
+ git_result = getattr(result_obj, "result", None)
292
+ if git_result is None:
293
+ return
294
+ args = " ".join(str(arg) for arg in getattr(git_result, "args", ())) or "(unknown)"
295
+ return_code = getattr(git_result, "return_code", None)
296
+ _emit_warning(f"{label} failed for {item_id} (git {args}, exit={return_code})")
297
+ detail = str(getattr(git_result, "stderr", "") or getattr(git_result, "stdout", "")).strip()
298
+ for line in detail.splitlines()[:3]:
299
+ text = line.strip()
300
+ if text:
301
+ _emit_warning(f" {text[:300]}")
302
+
303
+
304
+ def _load_item_metadata_from_list(list_path: Path, family: RunnerFamily, item_id: str) -> dict[str, object]:
305
+ """Read title/description metadata for one item from its plan list when available."""
306
+ if not item_id or not list_path.is_file():
307
+ return {}
308
+ try:
309
+ payload = json.loads(list_path.read_text(encoding="utf-8"))
310
+ except (OSError, ValueError, TypeError):
311
+ return {}
312
+ if not isinstance(payload, Mapping):
313
+ return {}
314
+ items = payload.get(family.list_key)
315
+ if not isinstance(items, list):
316
+ return {}
317
+ for entry in items:
318
+ if not isinstance(entry, Mapping) or str(entry.get("id") or "") != item_id:
319
+ continue
320
+ loaded: dict[str, object] = {}
321
+ for key in ("title", "description"):
322
+ value = entry.get(key)
323
+ if isinstance(value, str) and value.strip():
324
+ loaded[key] = value
325
+ return loaded
326
+ return {}
327
+
328
+
329
+ def _enrich_item_metadata(
330
+ metadata: Mapping[str, object] | None,
331
+ list_path: Path,
332
+ family: RunnerFamily,
333
+ item_id: str,
334
+ ) -> dict[str, object]:
335
+ """Ensure item metadata includes title/description when the caller omitted them."""
336
+ enriched = dict(metadata or {})
337
+ if enriched.get("title") and enriched.get("description"):
338
+ return enriched
339
+ for key, value in _load_item_metadata_from_list(list_path, family, item_id).items():
340
+ if not enriched.get(key):
341
+ enriched[key] = value
342
+ return enriched
343
+
344
+
289
345
  def _family_label(family: RunnerFamily) -> str:
290
346
  return {"feature": "Feature", "bugfix": "Bug"}.get(family.kind, family.kind.title())
291
347
 
@@ -648,7 +704,8 @@ def _preview_item(
648
704
  if not config.ai_client.command:
649
705
  raise RuntimeError("No supported AI CLI command was found")
650
706
  _validate_effort_config(config)
651
- metadata = _with_recovery_metadata(family, item_id, initial_metadata)
707
+ enriched_initial = _enrich_item_metadata(initial_metadata, invocation.list_path, family, item_id)
708
+ metadata = _with_recovery_metadata(family, item_id, enriched_initial)
652
709
  retry_count = int(metadata.get("retry_count") or 0)
653
710
  session_id = f"{item_id}-dry-run"
654
711
  _emit_item_header(family, invocation, item_id, metadata, paths)
@@ -712,7 +769,8 @@ def _process_item_locked(
712
769
  checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
713
770
  if checkout is not None and checkout.is_completed:
714
771
  raise RuntimeError(f"Task {item_id} is completed; run explicit reset or clean before rerunning")
715
- metadata = _with_recovery_metadata(family, item_id, initial_metadata, checkout)
772
+ enriched_initial = _enrich_item_metadata(initial_metadata, invocation.list_path, family, item_id)
773
+ metadata = _with_recovery_metadata(family, item_id, enriched_initial, checkout)
716
774
  base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
717
775
  branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch, paths.project_root)
718
776
  branch_context = BranchContext(base_branch, branch_name, paths.project_root)
@@ -903,16 +961,20 @@ def _process_item_locked(
903
961
  base_branch,
904
962
  recovered_session_id,
905
963
  session_paths,
964
+ artifact_path=recovery_artifact,
965
+ metadata=metadata,
906
966
  )
907
967
  start = start_item(status_family, status_invocation, item_id, status_root)
908
968
  if not start.ok:
909
969
  raise RuntimeError(start.text)
910
- commit_pre_branch_bookkeeping(
970
+ pre_bookkeeping = commit_pre_branch_bookkeeping(
911
971
  status_root,
912
972
  status_family,
913
973
  item_id,
914
974
  **_bookkeeping_list_kwargs(status_family, status_invocation),
915
975
  )
976
+ if getattr(pre_bookkeeping, "attempted", False) and not getattr(pre_bookkeeping, "ok", True):
977
+ _emit_bookkeeping_failure("pre-branch bookkeeping", item_id, pre_bookkeeping)
916
978
 
917
979
  previous_fingerprint = metadata.get("last_progress_fingerprint")
918
980
  previous_no_progress_count = int(metadata.get("no_progress_count") or 0)
@@ -1135,6 +1197,8 @@ def _process_item_locked(
1135
1197
  session_id,
1136
1198
  session_paths,
1137
1199
  classification_fatal_error_code=classification.fatal_error_code,
1200
+ artifact_path=prompt.artifact_path,
1201
+ metadata=metadata,
1138
1202
  )
1139
1203
  if accepted_with_warning and completed_status == "completed":
1140
1204
  reason = classification.reason or "no_semantic_completion"
@@ -1371,6 +1435,9 @@ def _finalize_recovered_success(
1371
1435
  base_branch: str,
1372
1436
  session_id: str,
1373
1437
  session_paths: SessionPaths,
1438
+ *,
1439
+ artifact_path: Path | None = None,
1440
+ metadata: Mapping[str, object] | None = None,
1374
1441
  ) -> str:
1375
1442
  update = update_item(
1376
1443
  status_family,
@@ -1400,6 +1467,8 @@ def _finalize_recovered_success(
1400
1467
  session_id,
1401
1468
  session_paths,
1402
1469
  classification_fatal_error_code="",
1470
+ artifact_path=artifact_path,
1471
+ metadata=metadata,
1403
1472
  )
1404
1473
 
1405
1474
 
@@ -1410,8 +1479,15 @@ def _patch_completion_notes_if_present(
1410
1479
  status_family: RunnerFamily,
1411
1480
  status_invocation: RunnerInvocation,
1412
1481
  item_id: str,
1482
+ *,
1483
+ artifact_path: Path | None = None,
1484
+ metadata: Mapping[str, object] | None = None,
1413
1485
  ) -> None:
1414
- summary_file = _artifact_path_for_item(execution_root, status_family, item_id, {}) / "completion-summary.json"
1486
+ resolved_artifact_dir = artifact_path
1487
+ if resolved_artifact_dir is None:
1488
+ resolved_metadata = _enrich_item_metadata(metadata, status_invocation.list_path, status_family, item_id)
1489
+ resolved_artifact_dir = _artifact_path_for_item(execution_root, status_family, item_id, resolved_metadata)
1490
+ summary_file = resolved_artifact_dir / "completion-summary.json"
1415
1491
  pipeline_root = getattr(paths, "pipeline_root", None)
1416
1492
  if pipeline_root is None or not summary_file.is_file() or not status_invocation.list_path.is_file():
1417
1493
  return
@@ -1456,6 +1532,34 @@ def _patch_completion_notes_if_present(
1456
1532
  _emit_info(f"Checked completion-summary.json for {item_id}; no non-empty completion notes patched")
1457
1533
 
1458
1534
 
1535
+ def _resolve_post_merge_artifact_dir(
1536
+ project_root: Path,
1537
+ execution_root: Path,
1538
+ status_family: RunnerFamily,
1539
+ status_invocation: RunnerInvocation,
1540
+ item_id: str,
1541
+ artifact_path: Path | None,
1542
+ metadata: Mapping[str, object] | None,
1543
+ ) -> Path:
1544
+ if artifact_path is not None:
1545
+ if execution_root != project_root:
1546
+ try:
1547
+ rel = artifact_path.resolve().relative_to(execution_root.resolve())
1548
+ project_candidate = project_root / rel
1549
+ if (project_candidate / "retrospective-result.json").is_file():
1550
+ return project_candidate
1551
+ except (OSError, ValueError):
1552
+ pass
1553
+ return artifact_path
1554
+ resolved_metadata = _enrich_item_metadata(metadata, status_invocation.list_path, status_family, item_id)
1555
+ artifact_dir = _artifact_path_for_item(project_root, status_family, item_id, resolved_metadata)
1556
+ if not (artifact_dir / "retrospective-result.json").is_file() and execution_root != project_root:
1557
+ fallback_dir = _artifact_path_for_item(execution_root, status_family, item_id, resolved_metadata)
1558
+ if (fallback_dir / "retrospective-result.json").is_file():
1559
+ return fallback_dir
1560
+ return artifact_dir
1561
+
1562
+
1459
1563
  def _complete_success_merge(
1460
1564
  family: RunnerFamily,
1461
1565
  item_id: str,
@@ -1472,6 +1576,8 @@ def _complete_success_merge(
1472
1576
  session_paths: SessionPaths,
1473
1577
  *,
1474
1578
  classification_fatal_error_code: str = "",
1579
+ artifact_path: Path | None = None,
1580
+ metadata: Mapping[str, object] | None = None,
1475
1581
  ) -> str:
1476
1582
  env = _runner_env_for_paths(paths)
1477
1583
  if new_status == "completed":
@@ -1482,6 +1588,8 @@ def _complete_success_merge(
1482
1588
  status_family,
1483
1589
  status_invocation,
1484
1590
  item_id,
1591
+ artifact_path=artifact_path,
1592
+ metadata=metadata,
1485
1593
  )
1486
1594
  final_bookkeeping = commit_final_bookkeeping(
1487
1595
  status_root,
@@ -1491,9 +1599,21 @@ def _complete_success_merge(
1491
1599
  **_bookkeeping_list_kwargs(status_family, status_invocation),
1492
1600
  )
1493
1601
  task_commit = commit_task_branch_changes(execution_root, family, item_id, new_status)
1494
- finalization_committed = getattr(final_bookkeeping, "ok", True) and getattr(task_commit, "ok", True)
1602
+ final_bookkeeping_ok = getattr(final_bookkeeping, "ok", True)
1603
+ task_commit_ok = getattr(task_commit, "ok", True)
1604
+ finalization_committed = final_bookkeeping_ok and task_commit_ok
1495
1605
  if not finalization_committed:
1496
1606
  _emit_warning(f"Task finalization commit failed for {item_id}; merge was not attempted and the task checkout remains active")
1607
+ if not final_bookkeeping_ok:
1608
+ _emit_bookkeeping_failure("final bookkeeping", item_id, final_bookkeeping)
1609
+ if not task_commit_ok:
1610
+ _emit_bookkeeping_failure("task branch finalization", item_id, task_commit)
1611
+ if not final_bookkeeping_ok and not task_commit_ok:
1612
+ failure_reason = "finalization_commit_failed"
1613
+ elif not final_bookkeeping_ok:
1614
+ failure_reason = "finalization_bookkeeping_commit_failed"
1615
+ else:
1616
+ failure_reason = "finalization_task_commit_failed"
1497
1617
  _write_session_status(
1498
1618
  session_paths,
1499
1619
  status="commit_missing",
@@ -1502,7 +1622,7 @@ def _complete_success_merge(
1502
1622
  task_type=family.task_type,
1503
1623
  base_branch=base_branch,
1504
1624
  active_dev_branch=branch_name,
1505
- reason="commit_missing",
1625
+ reason=failure_reason,
1506
1626
  fatal_error_code=classification_fatal_error_code,
1507
1627
  )
1508
1628
  update = update_item(
@@ -1520,14 +1640,18 @@ def _complete_success_merge(
1520
1640
  raise RuntimeError(update.text)
1521
1641
  _emit_update_summary(family, item_id, update)
1522
1642
  commit_missing_status = _status_from_update(update)
1523
- commit_final_bookkeeping(
1643
+ fallback_bookkeeping = commit_final_bookkeeping(
1524
1644
  status_root,
1525
1645
  status_family,
1526
1646
  item_id,
1527
1647
  commit_missing_status,
1528
1648
  **_bookkeeping_list_kwargs(status_family, status_invocation),
1529
1649
  )
1530
- _save_failure_wip(execution_root, family, item_id, commit_missing_status)
1650
+ if getattr(fallback_bookkeeping, "attempted", False) and not getattr(fallback_bookkeeping, "ok", True):
1651
+ _emit_bookkeeping_failure("commit_missing bookkeeping", item_id, fallback_bookkeeping)
1652
+ wip = _save_failure_wip(execution_root, family, item_id, commit_missing_status)
1653
+ if getattr(wip, "attempted", False) and not getattr(wip, "ok", True):
1654
+ _emit_bookkeeping_failure("commit_missing WIP preservation", item_id, wip)
1531
1655
  return commit_missing_status
1532
1656
 
1533
1657
  _emit_info(f"Merging {branch_name} into {base_branch}...")
@@ -1549,12 +1673,22 @@ def _complete_success_merge(
1549
1673
  raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
1550
1674
  complete_task_checkout_locked(family.state_dir, checkout)
1551
1675
  _emit_success(f"Merged {branch_name} into {base_branch}")
1552
- artifact_dir = _artifact_path_for_item(paths.project_root, status_family, item_id, {})
1553
- if not (artifact_dir / "retrospective-result.json").is_file() and execution_root != paths.project_root:
1554
- fallback_dir = _artifact_path_for_item(execution_root, status_family, item_id, {})
1555
- if (fallback_dir / "retrospective-result.json").is_file():
1556
- artifact_dir = fallback_dir
1557
- _emit_pending_rule_proposals_for_item(family, item_id, artifact_dir, paths.project_root)
1676
+ artifact_dir = _resolve_post_merge_artifact_dir(
1677
+ paths.project_root,
1678
+ execution_root,
1679
+ status_family,
1680
+ status_invocation,
1681
+ item_id,
1682
+ artifact_path,
1683
+ metadata,
1684
+ )
1685
+ _emit_pending_rule_proposals_for_item(
1686
+ family,
1687
+ item_id,
1688
+ artifact_dir,
1689
+ paths.project_root,
1690
+ metadata=metadata,
1691
+ )
1558
1692
  return new_status
1559
1693
  abort_in_progress_git_operation(paths.project_root)
1560
1694
  _emit_warning(
@@ -1761,6 +1895,37 @@ def _latest_session_id(state_dir: Path, item_id: str) -> str:
1761
1895
  return sorted(sessions)[-1] if sessions else ""
1762
1896
 
1763
1897
 
1898
+ def _spec_match_rank(candidate: Path, item_id: str, index: int) -> tuple[int, int, int, int]:
1899
+ """Rank same-prefix spec directories so active v1 checkpoints beat legacy siblings."""
1900
+ checkpoint = candidate / "workflow-checkpoint.json"
1901
+ if not checkpoint.is_file():
1902
+ return (0, 0, 0, -index)
1903
+ try:
1904
+ data = json.loads(checkpoint.read_text(encoding="utf-8"))
1905
+ except (OSError, ValueError, TypeError):
1906
+ return (0, 0, 0, -index)
1907
+ if not isinstance(data, Mapping):
1908
+ return (0, 0, 0, -index)
1909
+ matches_item = int(str(data.get("item_id") or "") == item_id)
1910
+ has_active_v1 = int(
1911
+ bool(matches_item)
1912
+ and isinstance(data.get("feature_state"), Mapping)
1913
+ and bool(data.get("feature_state"))
1914
+ )
1915
+ try:
1916
+ mtime_ns = checkpoint.stat().st_mtime_ns if matches_item else 0
1917
+ except OSError:
1918
+ mtime_ns = 0
1919
+ return (has_active_v1, matches_item, mtime_ns, -index)
1920
+
1921
+
1922
+ def _select_best_spec_match(matches: Sequence[Path], item_id: str) -> Path:
1923
+ return max(
1924
+ enumerate(matches),
1925
+ key=lambda pair: _spec_match_rank(pair[1], item_id, pair[0]),
1926
+ )[1]
1927
+
1928
+
1764
1929
  def _artifact_path_for_item(project_root: Path, family: RunnerFamily, item_id: str, metadata: dict[str, object]) -> Path:
1765
1930
  if family.kind == "feature":
1766
1931
  title = str(metadata.get("title") or "")
@@ -1773,7 +1938,7 @@ def _artifact_path_for_item(project_root: Path, family: RunnerFamily, item_id: s
1773
1938
  except OSError:
1774
1939
  matches = []
1775
1940
  if matches:
1776
- return matches[0]
1941
+ return _select_best_spec_match(matches, item_id)
1777
1942
  return project_root / ".prizmkit" / family.artifact_root_name / item_id
1778
1943
 
1779
1944
 
@@ -1782,18 +1947,19 @@ def _emit_pending_rule_proposals_for_item(
1782
1947
  item_id: str,
1783
1948
  artifact_dir: Path | None,
1784
1949
  project_root: Path,
1950
+ metadata: Mapping[str, object] | None = None,
1785
1951
  ) -> list[dict[str, str]]:
1786
1952
  """Log RULES_PROPOSED entries from retrospective-result.json on completion."""
1787
1953
  candidate_dirs: list[Path] = []
1788
1954
  if artifact_dir is not None:
1789
1955
  candidate_dirs.append(artifact_dir)
1790
- resolved_dir = _artifact_path_for_item(project_root, family, item_id, {})
1791
- if resolved_dir not in candidate_dirs:
1956
+ else:
1957
+ resolved_dir = _artifact_path_for_item(project_root, family, item_id, dict(metadata or {}))
1792
1958
  candidate_dirs.append(resolved_dir)
1793
- if family.kind == "feature":
1794
- exact_dir = project_root / ".prizmkit" / "specs" / item_id
1795
- if exact_dir not in candidate_dirs:
1796
- candidate_dirs.append(exact_dir)
1959
+ if family.kind == "feature":
1960
+ exact_dir = project_root / ".prizmkit" / "specs" / item_id
1961
+ if exact_dir not in candidate_dirs:
1962
+ candidate_dirs.append(exact_dir)
1797
1963
 
1798
1964
  result_file = next(
1799
1965
  (candidate / "retrospective-result.json" for candidate in candidate_dirs if (candidate / "retrospective-result.json").is_file()),
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.198",
2
+ "version": "1.1.199",
3
3
  "skills": {
4
4
  "prizmkit": {
5
5
  "description": "Framework introduction and navigation for the formal single-requirement lifecycle, project initialization, Prizm docs, and independent deployment.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizmkit",
3
- "version": "1.1.198",
3
+ "version": "1.1.199",
4
4
  "description": "Create a new PrizmKit-powered project with clean initialization — no framework dev files, just what you need.",
5
5
  "type": "module",
6
6
  "bin": {