prizmkit 1.1.161 → 1.1.164

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.
Files changed (62) hide show
  1. package/bin/create-prizmkit.js +4 -4
  2. package/bundled/VERSION.json +3 -3
  3. package/bundled/adapters/cursor/assets/prizmkit-hook.cjs +65 -0
  4. package/bundled/adapters/cursor/hooks-adapter.js +139 -0
  5. package/bundled/adapters/cursor/paths.js +11 -0
  6. package/bundled/adapters/cursor/rules-adapter.js +49 -0
  7. package/bundled/adapters/cursor/skill-adapter.js +27 -0
  8. package/bundled/dev-pipeline/README.md +21 -6
  9. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +3 -25
  10. package/bundled/dev-pipeline/prizmkit_runtime/config.py +71 -14
  11. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +28 -4
  12. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +5 -2
  13. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +21 -3
  14. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +82 -9
  15. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +123 -0
  16. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +123 -28
  17. package/bundled/dev-pipeline/prizmkit_runtime/status.py +2 -0
  18. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +1 -42
  19. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +43 -6
  20. package/bundled/dev-pipeline/scripts/init-pipeline.py +46 -8
  21. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +41 -6
  22. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +143 -27
  23. package/bundled/dev-pipeline/scripts/update-bug-status.py +8 -4
  24. package/bundled/dev-pipeline/scripts/update-feature-status.py +12 -8
  25. package/bundled/dev-pipeline/scripts/update-refactor-status.py +8 -4
  26. package/bundled/dev-pipeline/scripts/utils.py +3 -12
  27. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +4 -2
  28. package/bundled/dev-pipeline/templates/feature-list-schema.json +4 -2
  29. package/bundled/dev-pipeline/templates/refactor-list-schema.json +4 -2
  30. package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +2 -1
  31. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +5 -23
  32. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +2 -2
  33. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +452 -6
  34. package/bundled/dev-pipeline/tests/test_runtime_commit.py +138 -1
  35. package/bundled/dev-pipeline/tests/test_unified_cli.py +406 -30
  36. package/bundled/dev-pipeline/tests/test_utils.py +23 -0
  37. package/bundled/rules/USAGE.md +3 -0
  38. package/bundled/skills/_metadata.json +1 -1
  39. package/bundled/skills/bug-planner/SKILL.md +0 -1
  40. package/bundled/skills/bug-planner/references/verification.md +0 -2
  41. package/bundled/skills/bug-planner/scripts/validate-bug-list.py +37 -7
  42. package/bundled/skills/feature-planner/SKILL.md +5 -8
  43. package/bundled/skills/feature-planner/scripts/validate-and-generate.py +43 -19
  44. package/bundled/skills/prizmkit-init/SKILL.md +1 -1
  45. package/bundled/skills/prizmkit-init/references/config-schema.md +2 -2
  46. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +2 -3
  47. package/bundled/skills/prizmkit-prizm-docs/assets/prizm-docs-format.md +1 -1
  48. package/bundled/skills/prizmkit-prizm-docs/references/op-init.md +1 -1
  49. package/bundled/skills/refactor-planner/SKILL.md +1 -3
  50. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +38 -9
  51. package/package.json +4 -2
  52. package/src/ai-cli-launch.js +9 -2
  53. package/src/clean.js +42 -6
  54. package/src/config.js +51 -10
  55. package/src/detect-platform.js +30 -8
  56. package/src/external-skills.js +33 -99
  57. package/src/index.js +5 -0
  58. package/src/manifest.js +30 -4
  59. package/src/platforms.js +11 -4
  60. package/src/prompts.js +12 -4
  61. package/src/scaffold.js +75 -4
  62. package/src/upgrade.js +15 -14
@@ -42,6 +42,8 @@ HIDDEN_TOOL_WORKTREE_EXCLUDES = (
42
42
  ":(top,exclude,glob).agents/**",
43
43
  ":(top,exclude).pi",
44
44
  ":(top,exclude,glob).pi/**",
45
+ ":(top,exclude).cursor",
46
+ ":(top,exclude,glob).cursor/**",
45
47
  )
46
48
 
47
49
  UNTRACKED_TRANSIENT_EXCLUDES = (
@@ -54,7 +56,7 @@ UNTRACKED_TRANSIENT_EXCLUDES = (
54
56
  PIPELINE_FALLBACK_GIT_NAME = "PrizmKit Pipeline"
55
57
  PIPELINE_FALLBACK_GIT_EMAIL = "prizmkit-pipeline@example.invalid"
56
58
 
57
- WORKTREE_PLATFORM_SUPPORT_DIRS = (".claude", ".codebuddy", ".codex", ".agents", ".pi")
59
+ WORKTREE_PLATFORM_SUPPORT_DIRS = (".claude", ".codebuddy", ".codex", ".agents", ".pi", ".cursor")
58
60
  WORKTREE_ROOT_SUPPORT_FILES = ("skills-lock.json", "AGENTS.md")
59
61
  WORKTREE_PRIZMKIT_SUPPORT_ENTRIES = ("prizm-docs", "config.json", "manifest.json")
60
62
  WORKTREE_SUPPORT_IGNORE_NAMES = {"__pycache__", ".DS_Store", "settings.local.json"}
@@ -777,9 +779,17 @@ def current_branch(project_root: Path) -> str:
777
779
 
778
780
 
779
781
  def git_status_safe(project_root: Path) -> str:
780
- """Return task-visible status while excluding runner-owned support paths."""
782
+ """Return task-visible status while excluding copied support payloads."""
781
783
  result = run_git_command(project_root, ("status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES))
782
- return result.stdout if result.return_code == 0 else ""
784
+ if result.return_code != 0:
785
+ return ""
786
+ tracked_cursor = run_git_command(
787
+ project_root,
788
+ ("status", "--porcelain", "--untracked-files=no", "--", ".cursor"),
789
+ )
790
+ if tracked_cursor.return_code != 0:
791
+ return ""
792
+ return result.stdout + tracked_cursor.stdout
783
793
 
784
794
 
785
795
  def _status_record_paths(stdout: str) -> tuple[str, ...]:
@@ -805,7 +815,21 @@ def visible_task_paths(project_root: Path) -> tuple[tuple[str, ...], GitCommandR
805
815
  project_root,
806
816
  ("status", "--porcelain=v1", "-z", "--untracked-files=all", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES),
807
817
  )
808
- return (_status_record_paths(result.stdout) if result.return_code == 0 else ()), result
818
+ if result.return_code != 0:
819
+ return (), result
820
+
821
+ # Platform payloads copied into a task worktree stay hidden, but existing
822
+ # tracked Cursor project configuration remains part of complete-workspace
823
+ # commit semantics. `--untracked-files=no` admits only Git-owned Cursor
824
+ # changes and cannot sweep materialized support files into a task commit.
825
+ cursor_result = run_git_command(
826
+ project_root,
827
+ ("status", "--porcelain=v1", "-z", "--untracked-files=no", "--", ".cursor"),
828
+ )
829
+ if cursor_result.return_code != 0:
830
+ return (), cursor_result
831
+ paths = (*_status_record_paths(result.stdout), *_status_record_paths(cursor_result.stdout))
832
+ return tuple(dict.fromkeys(paths)), result
809
833
 
810
834
 
811
835
  def addable_task_paths(project_root: Path, paths: Sequence[str]) -> tuple[tuple[str, ...], GitCommandResult]:
@@ -69,13 +69,16 @@ def _progress_signature(path: Path | None) -> tuple[str, str, bool]:
69
69
  current_tool = data.get("current_tool")
70
70
  tool_active = isinstance(current_tool, str) and bool(current_tool.strip())
71
71
  child_signature = str(data.get("child_activity_signature") or "")
72
+ subagent_statistics = data.get("subagent_statistics")
73
+ if not isinstance(subagent_statistics, dict):
74
+ subagent_statistics = {}
72
75
  signature = json.dumps(
73
76
  [
74
77
  current_tool or "",
75
78
  int(data.get("message_count") or 0),
76
79
  int(data.get("total_tool_calls") or 0),
77
- int(data.get("active_subagent_count") or 0),
78
- int(data.get("subagent_spawn_count") or 0),
80
+ int(subagent_statistics.get("active") or 0),
81
+ int(subagent_statistics.get("spawned") or 0),
79
82
  child_signature,
80
83
  int(data.get("child_total_bytes") or 0),
81
84
  data.get("fatal_error_code") or "",
@@ -8,7 +8,7 @@ from collections.abc import Mapping
8
8
  from dataclasses import dataclass
9
9
  from pathlib import Path
10
10
 
11
- SUPPORTED_PLATFORMS = ("claude", "codex", "codebuddy", "pi")
11
+ SUPPORTED_PLATFORMS = ("claude", "codex", "codebuddy", "pi", "cursor")
12
12
 
13
13
 
14
14
  @dataclass(frozen=True)
@@ -45,6 +45,7 @@ _PLATFORM_MARKERS = {
45
45
  "codex": (".agents/skills",),
46
46
  "codebuddy": (".codebuddy/skills",),
47
47
  "pi": (".pi/skills",),
48
+ "cursor": (".cursor/skills", ".cursor/rules"),
48
49
  }
49
50
 
50
51
 
@@ -69,6 +70,11 @@ _PLATFORM_SKILL_PATTERNS = {
69
70
  ("project-agent-skill", ".agents/skills/{skill}"),
70
71
  ("home-skill", "~/.pi/agent/skills/{skill}"),
71
72
  ),
73
+ "cursor": (
74
+ ("project-skill", ".cursor/skills/{skill}"),
75
+ ("project-agent-skill", ".agents/skills/{skill}"),
76
+ ("home-skill", "~/.cursor/skills/{skill}"),
77
+ ),
72
78
  }
73
79
 
74
80
 
@@ -87,7 +93,17 @@ def platform_from_command(command: object) -> str:
87
93
  cmd = str(command or "").strip().lower()
88
94
  if not cmd:
89
95
  return ""
90
- base = os.path.basename(cmd.split()[0])
96
+ unquoted = cmd[1:-1] if len(cmd) >= 2 and cmd[0] == cmd[-1] and cmd[0] in "'\"" else cmd
97
+ token = (
98
+ unquoted
99
+ if len(unquoted) >= 3 and unquoted[1:3] in {":\\", ":/"} and unquoted.endswith((".exe", ".cmd", ".bat"))
100
+ else cmd.split()[0]
101
+ )
102
+ base = os.path.basename(token).replace("\\", "/").rsplit("/", 1)[-1]
103
+ for suffix in (".exe", ".cmd", ".bat"):
104
+ if base.endswith(suffix):
105
+ base = base[: -len(suffix)]
106
+ break
91
107
  if base in ("claude", "claude-code") or "claude" in base:
92
108
  return "claude"
93
109
  if base in ("codex", "openai-codex") or "codex" in base:
@@ -96,6 +112,8 @@ def platform_from_command(command: object) -> str:
96
112
  return "codebuddy"
97
113
  if base == "pi":
98
114
  return "pi"
115
+ if base == "agent":
116
+ return "cursor"
99
117
  return ""
100
118
 
101
119
 
@@ -152,7 +170,7 @@ def resolve_platform(project_root: str | Path, env: Mapping[str, str] | None = N
152
170
  "unresolved",
153
171
  (
154
172
  "No supported platform marker found. Set PRIZMKIT_PLATFORM, configure .prizmkit/config.json, "
155
- "or install Claude/Codex/CodeBuddy/Pi platform files.",
173
+ "or install Claude/Codex/CodeBuddy/Pi/Cursor platform files.",
156
174
  ),
157
175
  )
158
176
 
@@ -53,7 +53,12 @@ from .runner_models import (
53
53
  parse_invocation,
54
54
  )
55
55
  from .runner_prompts import PromptGenerationResult, generate_prompt
56
- from .runtime_commit import REQUEST_FILENAME, RuntimeCommitResult, finalize_runtime_commit
56
+ from .runtime_commit import (
57
+ REQUEST_FILENAME,
58
+ RuntimeCommitResult,
59
+ finalize_accepted_workspace_commit,
60
+ finalize_runtime_commit,
61
+ )
57
62
  from .runner_status import get_next, start_item, status_text, update_item
58
63
  from .sessions import AISessionConfig, AISessionLauncher, detect_stream_json_support
59
64
  from .task_checkout import (
@@ -411,7 +416,10 @@ def _progress_data(path: Path) -> dict[str, object]:
411
416
 
412
417
 
413
418
  def _subagent_state_summary(progress: Mapping[str, object]) -> str:
414
- states = progress.get("subagent_states")
419
+ statistics = progress.get("subagent_statistics")
420
+ if not isinstance(statistics, Mapping):
421
+ return ""
422
+ states = statistics.get("states")
415
423
  if not isinstance(states, list):
416
424
  return ""
417
425
  parts = []
@@ -453,9 +461,9 @@ def _emit_session_summary(session_result, session_paths: SessionPaths, classific
453
461
  providers = subagent_stats.get("providers")
454
462
  provider_text = ",".join(str(provider) for provider in providers) if isinstance(providers, list) else ""
455
463
  else:
456
- spawned = int(progress.get("subagent_spawn_count") or 0)
457
- active = int(progress.get("active_subagent_count") or 0)
458
- provider_text = str(progress.get("subagent_provider") or "")
464
+ spawned = 0
465
+ active = 0
466
+ provider_text = ""
459
467
  state_summary = _subagent_state_summary(progress)
460
468
  if spawned or active or state_summary:
461
469
  suffix = f" ({provider_text}; source=session.log)" if provider_text else " (source=session.log)"
@@ -504,6 +512,8 @@ def _preview_item(
504
512
  config = load_runtime_config(paths)
505
513
  if not config.ai_client.command:
506
514
  raise RuntimeError("No supported AI CLI command was found")
515
+ if config.ai_client.platform == "cursor" and not config.effort_validation.valid:
516
+ raise RuntimeError(config.effort_validation.message)
507
517
  metadata = _with_recovery_metadata(family, item_id, initial_metadata)
508
518
  retry_count = int(metadata.get("retry_count") or 0)
509
519
  session_id = f"{item_id}-dry-run"
@@ -543,6 +553,8 @@ def _process_item_locked(
543
553
  config = load_runtime_config(paths)
544
554
  if not config.ai_client.command:
545
555
  raise RuntimeError("No supported AI CLI command was found")
556
+ if config.ai_client.platform == "cursor" and not config.effort_validation.valid:
557
+ raise RuntimeError(config.effort_validation.message)
546
558
 
547
559
  active_branch = current_branch(paths.project_root)
548
560
  checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
@@ -722,7 +734,14 @@ def _process_item_locked(
722
734
  _emit_prompt_summary(prompt, session_id)
723
735
  stream_json = False
724
736
  if getattr(config.ai_client, "launch_profile", None) is None:
725
- stream_json = detect_stream_json_support(config.ai_client.command, config.ai_client.platform).enabled
737
+ stream_support = detect_stream_json_support(config.ai_client.command, config.ai_client.platform)
738
+ stream_json = stream_support.enabled
739
+ if config.ai_client.platform == "cursor" and not stream_json:
740
+ details = "; ".join(stream_support.notes) or "required stream-json flags were not found"
741
+ raise RuntimeError(
742
+ "Cursor Agent CLI is incompatible with PrizmKit headless execution: "
743
+ f"{details}. Install or update Cursor Agent and verify `agent --help`."
744
+ )
726
745
  base_head = run_git_command(execution_root, ("rev-parse", "HEAD")).stdout.strip()
727
746
  session_result = AISessionLauncher(
728
747
  AISessionConfig(
@@ -766,6 +785,21 @@ def _process_item_locked(
766
785
  progress_fingerprint=classification.progress_fingerprint,
767
786
  checkpoint_state=classification.checkpoint_state,
768
787
  )
788
+ elif classification.session_status == "workflow_skipped":
789
+ accepted_commit = _finalize_accepted_workflow_skip(
790
+ execution_root,
791
+ family,
792
+ item_id,
793
+ prompt,
794
+ base_head,
795
+ )
796
+ if accepted_commit.status not in {"committed", "not_needed"}:
797
+ classification = SessionClassification(
798
+ "commit_missing",
799
+ reason=accepted_commit.reason,
800
+ progress_fingerprint=classification.progress_fingerprint,
801
+ checkpoint_state=classification.checkpoint_state,
802
+ )
769
803
  _emit_session_summary(session_result, session_paths, classification)
770
804
  final_session_status = classification.session_status
771
805
  summary_path = _continuation_summary_path(execution_root, family, item_id, prompt)
@@ -784,11 +818,15 @@ def _process_item_locked(
784
818
  checkpoint_state=classification.checkpoint_state,
785
819
  )
786
820
 
821
+ accepted_with_warning = final_session_status == "workflow_skipped"
822
+ updater_session_status = (
823
+ "success" if accepted_with_warning else final_session_status
824
+ )
787
825
  update = update_item(
788
826
  status_family,
789
827
  status_invocation,
790
828
  item_id,
791
- final_session_status,
829
+ updater_session_status,
792
830
  session_id,
793
831
  status_root,
794
832
  active_dev_branch=branch_name,
@@ -819,7 +857,8 @@ def _process_item_locked(
819
857
  time.sleep(5)
820
858
  continue
821
859
 
822
- if final_session_status != "success":
860
+ accepted_with_warning = accepted_with_warning and new_status == "completed"
861
+ if final_session_status != "success" and not accepted_with_warning:
823
862
  commit_final_bookkeeping(status_root, status_family, item_id, new_status)
824
863
  wip = _save_failure_wip(execution_root, family, item_id, new_status, worktree_runtime)
825
864
  if not getattr(wip, "ok", True):
@@ -831,7 +870,7 @@ def _process_item_locked(
831
870
  _emit_warning(f"Could not safely return to {base_branch}; leaving {branch_name} active")
832
871
  return new_status
833
872
 
834
- return _complete_success_merge(
873
+ completed_status = _complete_success_merge(
835
874
  family,
836
875
  item_id,
837
876
  new_status,
@@ -848,6 +887,14 @@ def _process_item_locked(
848
887
  worktree_runtime,
849
888
  classification_fatal_error_code=classification.fatal_error_code,
850
889
  )
890
+ if accepted_with_warning and completed_status == "completed":
891
+ reason = classification.reason or "no_semantic_completion"
892
+ _emit_warning(
893
+ f"{item_id} was accepted with incomplete workflow evidence. "
894
+ f"Reason: {reason}. The task was finalized and merged; "
895
+ "manual review is recommended."
896
+ )
897
+ return completed_status
851
898
  except KeyboardInterrupt as interruption:
852
899
  try:
853
900
  _emit_task_interruption_diagnostics(
@@ -1017,6 +1064,32 @@ def _finalize_prepared_runtime_commit(
1017
1064
  return result
1018
1065
 
1019
1066
 
1067
+ def _finalize_accepted_workflow_skip(
1068
+ execution_root: Path,
1069
+ family: RunnerFamily,
1070
+ item_id: str,
1071
+ prompt: PromptGenerationResult,
1072
+ base_head: str,
1073
+ ) -> RuntimeCommitResult:
1074
+ """Commit accepted task output safely while retaining incomplete evidence."""
1075
+ if prompt.checkpoint_path is None or prompt.artifact_path is None:
1076
+ return RuntimeCommitResult("failed", "accepted_commit_handoff_unavailable")
1077
+ result = finalize_accepted_workspace_commit(
1078
+ execution_root,
1079
+ artifact_dir=prompt.artifact_path,
1080
+ checkpoint_path=prompt.checkpoint_path,
1081
+ base_head=base_head,
1082
+ commit_message=f"chore({item_id}): accept {family.kind} task with workflow warning",
1083
+ )
1084
+ if result.committed:
1085
+ _emit_success(f"Runtime committed accepted task output: {result.commit_hash}")
1086
+ elif result.status == "not_needed":
1087
+ _emit_info(f"Accepted task output required no additional Runtime commit ({result.reason})")
1088
+ else:
1089
+ _emit_warning(f"Accepted task output failed Runtime safety checks: {result.reason}")
1090
+ return result
1091
+
1092
+
1020
1093
  def _is_retryable_ai_outcome(session_status: str, new_status: str) -> bool:
1021
1094
  """Return whether a persisted post-launch outcome should continue in-process."""
1022
1095
  if session_status in {
@@ -214,6 +214,129 @@ def finalize_runtime_commit(
214
214
  return RuntimeCommitResult("committed", "runtime_commit_completed", head, recovered)
215
215
 
216
216
 
217
+ def finalize_accepted_workspace_commit(
218
+ project_root: Path,
219
+ *,
220
+ artifact_dir: Path,
221
+ checkpoint_path: Path,
222
+ base_head: str,
223
+ commit_message: str,
224
+ ) -> RuntimeCommitResult:
225
+ """Safely commit complete task output accepted without semantic completion.
226
+
227
+ The raw checkpoint remains incomplete diagnostic evidence. Only its exact
228
+ causal checkpoint/request paths are excluded from the accepted snapshot.
229
+ Any post-base commit is rejected so the Python Runtime remains the sole
230
+ automated commit owner for this degraded path.
231
+ """
232
+ try:
233
+ root = project_root.resolve()
234
+ artifact = artifact_dir.resolve()
235
+ checkpoint = checkpoint_path.resolve()
236
+ except (OSError, RuntimeError):
237
+ return RuntimeCommitResult("failed", "unsafe_artifact_identity")
238
+ if not _within(artifact, root) or not _within(checkpoint, artifact):
239
+ return RuntimeCommitResult("failed", "unsafe_artifact_identity")
240
+
241
+ request_path = artifact / REQUEST_FILENAME
242
+ current_head = _git(root, "rev-parse", "HEAD")
243
+ base = _git(root, "rev-parse", base_head)
244
+ if current_head.return_code != 0 or base.return_code != 0:
245
+ return RuntimeCommitResult("failed", "git_head_unavailable")
246
+ head = current_head.stdout.strip()
247
+ resolved_base = base.stdout.strip()
248
+ # The Python Runtime remains the sole automated commit owner. A HEAD change
249
+ # after the session base could hide sensitive content in intermediate commit
250
+ # history even when the final tree diff looks safe, so fail closed instead of
251
+ # adopting or merging provider-created commits on this degraded path.
252
+ if head != resolved_base:
253
+ return RuntimeCommitResult("failed", "unexpected_existing_commit")
254
+
255
+ unmerged = _git(root, "ls-files", "-u")
256
+ if unmerged.return_code != 0:
257
+ return RuntimeCommitResult("failed", "git_unmerged_state_unavailable")
258
+ if unmerged.stdout.strip():
259
+ return RuntimeCommitResult("failed", "unresolved_merge_state")
260
+
261
+ changed, status_error = _workspace_changed_paths(
262
+ root,
263
+ checkpoint_path=checkpoint,
264
+ request_path=request_path,
265
+ )
266
+ if status_error:
267
+ return RuntimeCommitResult("failed", status_error)
268
+ if any(_sensitive_commit_path(path) for path in changed):
269
+ return RuntimeCommitResult("failed", "sensitive_workspace_path")
270
+ bookkeeping_staged = _staged_bookkeeping_paths(
271
+ root,
272
+ checkpoint_path=checkpoint,
273
+ request_path=request_path,
274
+ )
275
+ if bookkeeping_staged is None:
276
+ return RuntimeCommitResult("failed", "git_staged_set_unavailable")
277
+ if bookkeeping_staged:
278
+ return RuntimeCommitResult("failed", "runtime_bookkeeping_staged")
279
+ if not changed:
280
+ return RuntimeCommitResult(
281
+ "not_needed",
282
+ "accepted_workspace_clean",
283
+ head,
284
+ )
285
+
286
+ staged = _stage_workspace(
287
+ root,
288
+ checkpoint_path=checkpoint,
289
+ request_path=request_path,
290
+ )
291
+ if staged.return_code != 0:
292
+ return RuntimeCommitResult("failed", "git_stage_failed")
293
+ staged_paths = _git(
294
+ root, "diff", "--cached", "--name-only", "--no-renames", "-z",
295
+ )
296
+ if staged_paths.return_code != 0:
297
+ return RuntimeCommitResult("failed", "git_staged_set_unavailable")
298
+ staged_set = {path for path in staged_paths.stdout.split("\0") if path}
299
+ if staged_set != set(changed):
300
+ return RuntimeCommitResult("failed", "staged_workspace_mismatch")
301
+ unstaged_candidates = _workspace_has_unstaged_candidates(
302
+ root,
303
+ checkpoint_path=checkpoint,
304
+ request_path=request_path,
305
+ )
306
+ if unstaged_candidates is None:
307
+ return RuntimeCommitResult("failed", "git_workspace_verification_failed")
308
+ if unstaged_candidates:
309
+ return RuntimeCommitResult("failed", "workspace_changed_during_staging")
310
+
311
+ committed = _git(
312
+ root,
313
+ "-c", "core.hooksPath=/dev/null",
314
+ "-c", "commit.gpgSign=false",
315
+ "commit", "-m", commit_message,
316
+ )
317
+ if committed.return_code != 0:
318
+ return RuntimeCommitResult("failed", "git_commit_failed")
319
+ new_head_result = _git(root, "rev-parse", "HEAD")
320
+ if new_head_result.return_code != 0:
321
+ return RuntimeCommitResult("failed", "commit_identity_unavailable")
322
+ new_head = new_head_result.stdout.strip()
323
+ parents = _git(root, "show", "-s", "--format=%P", new_head)
324
+ subject = _git(root, "show", "-s", "--format=%s", new_head)
325
+ committed_paths = _git(
326
+ root,
327
+ "diff-tree", "--no-commit-id", "--name-only", "--no-renames", "-r", "-z", new_head,
328
+ )
329
+ if any(result.return_code != 0 for result in (parents, subject, committed_paths)):
330
+ return RuntimeCommitResult("failed", "git_commit_content_mismatch", new_head)
331
+ if not (
332
+ parents.stdout.strip().split() == [head]
333
+ and subject.stdout.strip() == commit_message
334
+ and {path for path in committed_paths.stdout.split("\0") if path} == staged_set
335
+ ):
336
+ return RuntimeCommitResult("failed", "git_commit_content_mismatch", new_head)
337
+ return RuntimeCommitResult("committed", "accepted_workspace_committed", new_head)
338
+
339
+
217
340
  def _load_request(
218
341
  request_path: Path,
219
342
  project_root: Path,