openplanr 3.3.0 → 3.5.0

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 (493) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/dist/cli/commands/artifact-design-share.d.ts +9 -0
  3. package/dist/cli/commands/artifact-design-share.d.ts.map +1 -0
  4. package/dist/cli/commands/artifact-design-share.js +200 -0
  5. package/dist/cli/commands/artifact-design-share.js.map +1 -0
  6. package/dist/cli/commands/artifact.d.ts.map +1 -1
  7. package/dist/cli/commands/artifact.js +5 -18
  8. package/dist/cli/commands/artifact.js.map +1 -1
  9. package/dist/cli/commands/design.d.ts +3 -0
  10. package/dist/cli/commands/design.d.ts.map +1 -0
  11. package/dist/cli/commands/design.js +137 -0
  12. package/dist/cli/commands/design.js.map +1 -0
  13. package/dist/cli/commands/groups/operations.d.ts.map +1 -1
  14. package/dist/cli/commands/groups/operations.js +2 -0
  15. package/dist/cli/commands/groups/operations.js.map +1 -1
  16. package/dist/cli/commands/ship.d.ts.map +1 -1
  17. package/dist/cli/commands/ship.js +2 -0
  18. package/dist/cli/commands/ship.js.map +1 -1
  19. package/dist/dashboard/.vite/manifest.json +2 -2
  20. package/dist/dashboard/assets/index-B-l_941W.js +75 -0
  21. package/dist/dashboard/assets/index-B-l_941W.js.map +1 -0
  22. package/dist/dashboard/assets/index-Cv4Vwhuw.css +2 -0
  23. package/dist/dashboard/dashboard-manifest.json +14 -14
  24. package/dist/dashboard/index.html +2 -2
  25. package/dist/services/design-artifact-service.d.ts +42 -1
  26. package/dist/services/design-artifact-service.d.ts.map +1 -1
  27. package/dist/services/design-artifact-service.js +198 -19
  28. package/dist/services/design-artifact-service.js.map +1 -1
  29. package/dist/services/runtime-manager/runtime-package.js +1 -1
  30. package/dist/services/runtime-manager/runtime-package.js.map +1 -1
  31. package/dist/services/ship-checks/contract.d.ts +3 -1
  32. package/dist/services/ship-checks/contract.d.ts.map +1 -1
  33. package/dist/services/ship-checks/contract.js +1 -1
  34. package/dist/services/ship-checks/contract.js.map +1 -1
  35. package/dist/services/ship-checks/discover.d.ts.map +1 -1
  36. package/dist/services/ship-checks/discover.js +2 -1
  37. package/dist/services/ship-checks/discover.js.map +1 -1
  38. package/dist/services/ship-checks/package-contents.d.ts +4 -0
  39. package/dist/services/ship-checks/package-contents.d.ts.map +1 -0
  40. package/dist/services/ship-checks/package-contents.js +91 -0
  41. package/dist/services/ship-checks/package-contents.js.map +1 -0
  42. package/dist/services/ship-checks/packages.d.ts +2 -0
  43. package/dist/services/ship-checks/packages.d.ts.map +1 -1
  44. package/dist/services/ship-checks/packages.js +4 -0
  45. package/dist/services/ship-checks/packages.js.map +1 -1
  46. package/dist/services/ship-checks/scope.js +2 -1
  47. package/dist/services/ship-checks/scope.js.map +1 -1
  48. package/dist/utils/splice-managed-block.js +1 -1
  49. package/dist/utils/splice-managed-block.js.map +1 -1
  50. package/docs/CLI.md +67 -1
  51. package/lib/host-packages/adapter-registry.json +5 -5
  52. package/lib/host-packages/capability-map.json +1 -1
  53. package/lib/host-packages/claude/.claude-plugin/marketplace.json +3 -3
  54. package/lib/host-packages/claude/openplanr/.claude-plugin/plugin.json +6 -6
  55. package/lib/host-packages/claude/openplanr/.openplanr-content.json +57 -429
  56. package/lib/host-packages/claude/openplanr/README.md +16 -16
  57. package/lib/host-packages/claude/openplanr/references/agents/shared/modes/shared/task-context-resolution.md +4 -4
  58. package/lib/host-packages/claude/openplanr/skills/artifact/references/design-sharing.md +2 -2
  59. package/lib/host-packages/claude/openplanr/skills/delegate/SKILL.md +2 -1
  60. package/lib/host-packages/claude/openplanr/skills/delegate/references/integration-review.md +26 -20
  61. package/lib/host-packages/claude/openplanr/skills/delegate/references/operator-guide.md +25 -1
  62. package/lib/host-packages/claude/openplanr/skills/delegate/references/run-handoff.md +2 -2
  63. package/lib/host-packages/claude/openplanr/skills/delegate/references/worktree-custody.md +17 -9
  64. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/adapters/claude.mjs +15 -3
  65. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/adapters/codex.mjs +38 -2
  66. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/adapters/native.mjs +5 -0
  67. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/custody.mjs +217 -10
  68. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/handoff.mjs +1080 -0
  69. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/integrate.mjs +96 -201
  70. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/integration-files.mjs +3 -382
  71. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/presentation.mjs +29 -12
  72. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/run-contract.mjs +11 -0
  73. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/run-execution.mjs +1 -1
  74. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/run-lifecycle.mjs +14 -10
  75. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/run-preparation.mjs +4 -0
  76. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/run-record.mjs +2 -2
  77. package/lib/host-packages/claude/openplanr/skills/design/SKILL.md +23 -12
  78. package/lib/host-packages/claude/openplanr/skills/design/references/design-system.md +2 -2
  79. package/lib/host-packages/claude/openplanr/skills/design/references/generation.md +3 -3
  80. package/lib/host-packages/claude/openplanr/skills/design/references/hosted-canvas.md +6 -3
  81. package/lib/host-packages/claude/openplanr/skills/design/references/review.md +6 -6
  82. package/lib/host-packages/claude/openplanr/skills/design/references/team-review.md +3 -4
  83. package/lib/host-packages/claude/openplanr/skills/design/references/utilities.md +78 -32
  84. package/lib/host-packages/claude/openplanr/skills/design-loop/SKILL.md +15 -7
  85. package/lib/host-packages/claude/openplanr/skills/design-loop/references/design-system.md +2 -2
  86. package/lib/host-packages/claude/openplanr/skills/design-loop/references/generation.md +3 -3
  87. package/lib/host-packages/claude/openplanr/skills/design-loop/references/review.md +6 -6
  88. package/lib/host-packages/claude/openplanr/skills/design-loop/references/team-review.md +3 -4
  89. package/lib/host-packages/claude/openplanr/skills/design-loop/references/utilities.md +78 -32
  90. package/lib/host-packages/claude/openplanr/skills/design-review/SKILL.md +25 -5
  91. package/lib/host-packages/claude/openplanr/skills/design-review/references/design-system.md +2 -2
  92. package/lib/host-packages/claude/openplanr/skills/design-review/references/generation.md +3 -3
  93. package/lib/host-packages/claude/openplanr/skills/design-review/references/review.md +6 -6
  94. package/lib/host-packages/claude/openplanr/skills/design-review/references/team-review.md +3 -4
  95. package/lib/host-packages/claude/openplanr/skills/design-review/references/utilities.md +78 -32
  96. package/lib/host-packages/claude/openplanr/skills/investigate/SKILL.md +1 -0
  97. package/lib/host-packages/claude/openplanr/skills/investigate/references/fail-first.md +40 -0
  98. package/lib/host-packages/claude/openplanr/skills/plan/SKILL.md +7 -3
  99. package/lib/host-packages/claude/openplanr/skills/ship/SKILL.md +22 -10
  100. package/lib/host-packages/claude/openplanr/skills/ship/references/fail-first.md +40 -0
  101. package/lib/host-packages/claude/openplanr/skills/ship/references/result-contract.md +7 -3
  102. package/lib/host-packages/cursor/openplanr/.openplanr-content.json +55 -427
  103. package/lib/host-packages/cursor/openplanr/manifest.json +1 -1
  104. package/lib/host-packages/cursor/openplanr/rules/planr-artifact/references/design-sharing.md +2 -2
  105. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/references/integration-review.md +26 -20
  106. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/references/operator-guide.md +25 -1
  107. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/references/run-handoff.md +2 -2
  108. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/references/worktree-custody.md +17 -9
  109. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/adapters/claude.mjs +15 -3
  110. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/adapters/codex.mjs +38 -2
  111. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/adapters/native.mjs +5 -0
  112. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/custody.mjs +217 -10
  113. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/handoff.mjs +1080 -0
  114. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/integrate.mjs +96 -201
  115. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/integration-files.mjs +3 -382
  116. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/presentation.mjs +29 -12
  117. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/run-contract.mjs +11 -0
  118. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/run-execution.mjs +1 -1
  119. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/run-lifecycle.mjs +14 -10
  120. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/run-preparation.mjs +4 -0
  121. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/run-record.mjs +2 -2
  122. package/lib/host-packages/cursor/openplanr/rules/planr-delegate.mdc +2 -1
  123. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/design-system.md +2 -2
  124. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/generation.md +3 -3
  125. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/hosted-canvas.md +6 -3
  126. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/review.md +6 -6
  127. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/team-review.md +3 -4
  128. package/lib/host-packages/cursor/openplanr/rules/planr-design/references/utilities.md +78 -32
  129. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/references/design-system.md +2 -2
  130. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/references/generation.md +3 -3
  131. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/references/review.md +6 -6
  132. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/references/team-review.md +3 -4
  133. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/references/utilities.md +78 -32
  134. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop.mdc +15 -7
  135. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/references/design-system.md +2 -2
  136. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/references/generation.md +3 -3
  137. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/references/review.md +6 -6
  138. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/references/team-review.md +3 -4
  139. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/references/utilities.md +78 -32
  140. package/lib/host-packages/cursor/openplanr/rules/planr-design-review.mdc +25 -5
  141. package/lib/host-packages/cursor/openplanr/rules/planr-design.mdc +23 -12
  142. package/lib/host-packages/cursor/openplanr/rules/planr-investigate/references/fail-first.md +40 -0
  143. package/lib/host-packages/cursor/openplanr/rules/planr-investigate.mdc +1 -0
  144. package/lib/host-packages/cursor/openplanr/rules/planr-plan.mdc +7 -3
  145. package/lib/host-packages/cursor/openplanr/rules/planr-ship/references/fail-first.md +40 -0
  146. package/lib/host-packages/cursor/openplanr/rules/planr-ship/references/result-contract.md +7 -3
  147. package/lib/host-packages/cursor/openplanr/rules/planr-ship.mdc +22 -10
  148. package/lib/host-packages/openai/.claude-plugin/marketplace.json +3 -3
  149. package/lib/host-packages/openai/openplanr/.codex-plugin/plugin.json +2 -2
  150. package/lib/host-packages/openai/openplanr/.openplanr-content.json +62 -434
  151. package/lib/host-packages/openai/openplanr/skills/artifact/references/design-sharing.md +2 -2
  152. package/lib/host-packages/openai/openplanr/skills/delegate/SKILL.md +2 -1
  153. package/lib/host-packages/openai/openplanr/skills/delegate/openplanr.skill.json +1 -1
  154. package/lib/host-packages/openai/openplanr/skills/delegate/references/integration-review.md +26 -20
  155. package/lib/host-packages/openai/openplanr/skills/delegate/references/operator-guide.md +25 -1
  156. package/lib/host-packages/openai/openplanr/skills/delegate/references/run-handoff.md +2 -2
  157. package/lib/host-packages/openai/openplanr/skills/delegate/references/worktree-custody.md +17 -9
  158. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/adapters/claude.mjs +15 -3
  159. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/adapters/codex.mjs +38 -2
  160. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/adapters/native.mjs +5 -0
  161. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/custody.mjs +217 -10
  162. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/handoff.mjs +1080 -0
  163. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/integrate.mjs +96 -201
  164. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/integration-files.mjs +3 -382
  165. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/presentation.mjs +29 -12
  166. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/run-contract.mjs +11 -0
  167. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/run-execution.mjs +1 -1
  168. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/run-lifecycle.mjs +14 -10
  169. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/run-preparation.mjs +4 -0
  170. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/run-record.mjs +2 -2
  171. package/lib/host-packages/openai/openplanr/skills/design/SKILL.md +23 -12
  172. package/lib/host-packages/openai/openplanr/skills/design/openplanr.skill.json +0 -11
  173. package/lib/host-packages/openai/openplanr/skills/design/references/design-system.md +2 -2
  174. package/lib/host-packages/openai/openplanr/skills/design/references/generation.md +3 -3
  175. package/lib/host-packages/openai/openplanr/skills/design/references/hosted-canvas.md +6 -3
  176. package/lib/host-packages/openai/openplanr/skills/design/references/review.md +6 -6
  177. package/lib/host-packages/openai/openplanr/skills/design/references/team-review.md +3 -4
  178. package/lib/host-packages/openai/openplanr/skills/design/references/utilities.md +78 -32
  179. package/lib/host-packages/openai/openplanr/skills/design-loop/SKILL.md +15 -7
  180. package/lib/host-packages/openai/openplanr/skills/design-loop/openplanr.skill.json +0 -11
  181. package/lib/host-packages/openai/openplanr/skills/design-loop/references/design-system.md +2 -2
  182. package/lib/host-packages/openai/openplanr/skills/design-loop/references/generation.md +3 -3
  183. package/lib/host-packages/openai/openplanr/skills/design-loop/references/review.md +6 -6
  184. package/lib/host-packages/openai/openplanr/skills/design-loop/references/team-review.md +3 -4
  185. package/lib/host-packages/openai/openplanr/skills/design-loop/references/utilities.md +78 -32
  186. package/lib/host-packages/openai/openplanr/skills/design-review/SKILL.md +25 -5
  187. package/lib/host-packages/openai/openplanr/skills/design-review/openplanr.skill.json +0 -11
  188. package/lib/host-packages/openai/openplanr/skills/design-review/references/design-system.md +2 -2
  189. package/lib/host-packages/openai/openplanr/skills/design-review/references/generation.md +3 -3
  190. package/lib/host-packages/openai/openplanr/skills/design-review/references/review.md +6 -6
  191. package/lib/host-packages/openai/openplanr/skills/design-review/references/team-review.md +3 -4
  192. package/lib/host-packages/openai/openplanr/skills/design-review/references/utilities.md +78 -32
  193. package/lib/host-packages/openai/openplanr/skills/investigate/SKILL.md +1 -0
  194. package/lib/host-packages/openai/openplanr/skills/investigate/openplanr.skill.json +12 -1
  195. package/lib/host-packages/openai/openplanr/skills/investigate/references/fail-first.md +40 -0
  196. package/lib/host-packages/openai/openplanr/skills/plan/SKILL.md +7 -3
  197. package/lib/host-packages/openai/openplanr/skills/plan/openplanr.skill.json +0 -11
  198. package/lib/host-packages/openai/openplanr/skills/ship/SKILL.md +22 -10
  199. package/lib/host-packages/openai/openplanr/skills/ship/openplanr.skill.json +12 -1
  200. package/lib/host-packages/openai/openplanr/skills/ship/references/fail-first.md +40 -0
  201. package/lib/host-packages/openai/openplanr/skills/ship/references/result-contract.md +7 -3
  202. package/package.json +8 -8
  203. package/dist/dashboard/assets/index-BU5fzjyz.css +0 -1
  204. package/dist/dashboard/assets/index-B_96uzCl.js +0 -572
  205. package/dist/dashboard/assets/index-B_96uzCl.js.map +0 -1
  206. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-artifact-shell.mjs +0 -1774
  207. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +0 -555
  208. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-compression.mjs +0 -4180
  209. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-document.mjs +0 -2937
  210. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +0 -647
  211. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-entities.mjs +0 -439
  212. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-handoff.mjs +0 -1576
  213. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-loopback-server.mjs +0 -359
  214. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-owner-custody.mjs +0 -129
  215. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-parse5-parser.mjs +0 -3970
  216. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-parse5-tokenizer.mjs +0 -3501
  217. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-resource-pack.mjs +0 -698
  218. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-review.mjs +0 -3385
  219. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-runtime-home.mjs +0 -39
  220. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-runtime-support-25485dbf1cb2.mjs +0 -24
  221. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-sandbox-guards.mjs +0 -1102
  222. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-share.mjs +0 -1993
  223. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs +0 -1113
  224. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs +0 -505
  225. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +0 -222
  226. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-shared-protocol-contracts-b5f28f94.mjs +0 -5907
  227. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-upload-spool.mjs +0 -198
  228. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design.mjs +0 -1430
  229. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -2050
  230. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +0 -2
  231. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +0 -18
  232. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +0 -809
  233. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +0 -5693
  234. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +0 -4175
  235. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +0 -65
  236. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +0 -1755
  237. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +0 -62
  238. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +0 -2633
  239. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +0 -124
  240. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/package.json +0 -65
  241. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/enhancements.css +0 -388
  242. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/handoff-center.css +0 -81
  243. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.css +0 -1
  244. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.js +0 -133
  245. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +0 -1159
  246. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +0 -30
  247. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +0 -900
  248. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +0 -2261
  249. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +0 -1595
  250. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +0 -1467
  251. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +0 -1860
  252. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +0 -914
  253. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +0 -2578
  254. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +0 -582
  255. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +0 -17
  256. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +0 -12
  257. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-protocol-contracts.js +0 -285
  258. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-design-review-experience.js +0 -2773
  259. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-studio-shell.js +0 -134
  260. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-canvas-engine.js +0 -2207
  261. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-design-review-experience.js +0 -16
  262. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-studio-shell.js +0 -8
  263. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/18-interface-primitives.js +0 -3883
  264. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/19-interface-primitives.js +0 -966
  265. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/20-studio-shell.js +0 -520
  266. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/21-design-studio.js +0 -1597
  267. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +0 -311
  268. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +0 -159
  269. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/registries/artifact-theme.json +0 -64
  270. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.0.0/design-manifest.schema.json +0 -90
  271. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-envelope.schema.json +0 -142
  272. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-paste.schema.json +0 -49
  273. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  274. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-bundle.schema.json +0 -584
  275. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-context.schema.json +0 -191
  276. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-handoff.schema.json +0 -407
  277. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-metadata-payload.schema.json +0 -106
  278. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-handoff-readiness.schema.json +0 -398
  279. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-implementation-handoff.schema.json +0 -518
  280. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-planning-lineage.schema.json +0 -106
  281. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-review-metadata-payload.schema.json +0 -107
  282. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.14.0/artifact-theme.schema.json +0 -316
  283. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/artifact-envelope.schema.json +0 -408
  284. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/design-review-bundle.schema.json +0 -590
  285. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-document.schema.json +0 -506
  286. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-review-bundle.schema.json +0 -822
  287. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-bundle.schema.json +0 -346
  288. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-workspace.schema.json +0 -108
  289. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-create.schema.json +0 -170
  290. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-event.schema.json +0 -97
  291. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-revision.schema.json +0 -56
  292. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +0 -5468
  293. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/design.mjs +0 -2844
  294. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -21
  295. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +0 -159
  296. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  297. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/integration-transaction.mjs +0 -958
  298. package/lib/host-packages/claude/openplanr/skills/design/scripts/design.mjs +0 -12
  299. package/lib/host-packages/claude/openplanr/skills/design-loop/scripts/design.mjs +0 -12
  300. package/lib/host-packages/claude/openplanr/skills/design-review/scripts/design.mjs +0 -12
  301. package/lib/host-packages/claude/openplanr/skills/plan/scripts/design.mjs +0 -12
  302. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/integration-transaction.mjs +0 -958
  303. package/lib/host-packages/cursor/openplanr/rules/planr-design/scripts/design.mjs +0 -12
  304. package/lib/host-packages/cursor/openplanr/rules/planr-design-loop/scripts/design.mjs +0 -12
  305. package/lib/host-packages/cursor/openplanr/rules/planr-design-review/scripts/design.mjs +0 -12
  306. package/lib/host-packages/cursor/openplanr/rules/planr-plan/scripts/design.mjs +0 -12
  307. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-artifact-shell.mjs +0 -1774
  308. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +0 -555
  309. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-compression.mjs +0 -4180
  310. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-document.mjs +0 -2937
  311. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +0 -647
  312. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-entities.mjs +0 -439
  313. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-handoff.mjs +0 -1576
  314. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-loopback-server.mjs +0 -359
  315. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-owner-custody.mjs +0 -129
  316. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-parse5-parser.mjs +0 -3970
  317. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-parse5-tokenizer.mjs +0 -3501
  318. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-resource-pack.mjs +0 -698
  319. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-review.mjs +0 -3385
  320. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-runtime-home.mjs +0 -39
  321. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-runtime-support-25485dbf1cb2.mjs +0 -24
  322. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-sandbox-guards.mjs +0 -1102
  323. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-share.mjs +0 -1993
  324. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs +0 -1113
  325. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs +0 -505
  326. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +0 -222
  327. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-shared-protocol-contracts-b5f28f94.mjs +0 -5907
  328. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-upload-spool.mjs +0 -198
  329. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design.mjs +0 -1430
  330. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -2050
  331. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +0 -2
  332. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +0 -18
  333. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +0 -809
  334. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +0 -5693
  335. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +0 -4175
  336. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +0 -65
  337. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +0 -1755
  338. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +0 -62
  339. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +0 -2633
  340. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +0 -124
  341. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/package.json +0 -65
  342. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/enhancements.css +0 -388
  343. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/handoff-center.css +0 -81
  344. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.css +0 -1
  345. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.js +0 -133
  346. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +0 -1159
  347. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +0 -30
  348. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +0 -900
  349. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +0 -2261
  350. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +0 -1595
  351. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +0 -1467
  352. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +0 -1860
  353. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +0 -914
  354. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +0 -2578
  355. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +0 -582
  356. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +0 -17
  357. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +0 -12
  358. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-protocol-contracts.js +0 -285
  359. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-design-review-experience.js +0 -2773
  360. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-studio-shell.js +0 -134
  361. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-canvas-engine.js +0 -2207
  362. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-design-review-experience.js +0 -16
  363. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-studio-shell.js +0 -8
  364. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/18-interface-primitives.js +0 -3883
  365. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/19-interface-primitives.js +0 -966
  366. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/20-studio-shell.js +0 -520
  367. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/21-design-studio.js +0 -1597
  368. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +0 -311
  369. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +0 -159
  370. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/registries/artifact-theme.json +0 -64
  371. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.0.0/design-manifest.schema.json +0 -90
  372. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-envelope.schema.json +0 -142
  373. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-paste.schema.json +0 -49
  374. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  375. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-bundle.schema.json +0 -584
  376. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-context.schema.json +0 -191
  377. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-handoff.schema.json +0 -407
  378. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-metadata-payload.schema.json +0 -106
  379. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-handoff-readiness.schema.json +0 -398
  380. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-implementation-handoff.schema.json +0 -518
  381. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-planning-lineage.schema.json +0 -106
  382. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-review-metadata-payload.schema.json +0 -107
  383. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.14.0/artifact-theme.schema.json +0 -316
  384. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/artifact-envelope.schema.json +0 -408
  385. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/design-review-bundle.schema.json +0 -590
  386. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-document.schema.json +0 -506
  387. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-review-bundle.schema.json +0 -822
  388. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-bundle.schema.json +0 -346
  389. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-workspace.schema.json +0 -108
  390. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-create.schema.json +0 -170
  391. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-event.schema.json +0 -97
  392. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-revision.schema.json +0 -56
  393. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +0 -5468
  394. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/design.mjs +0 -2844
  395. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -21
  396. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +0 -159
  397. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  398. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-artifact-shell.mjs +0 -1774
  399. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +0 -555
  400. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-compression.mjs +0 -4180
  401. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-document.mjs +0 -2937
  402. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +0 -647
  403. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-entities.mjs +0 -439
  404. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-handoff.mjs +0 -1576
  405. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-loopback-server.mjs +0 -359
  406. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-owner-custody.mjs +0 -129
  407. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-parse5-parser.mjs +0 -3970
  408. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-parse5-tokenizer.mjs +0 -3501
  409. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-resource-pack.mjs +0 -698
  410. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-review.mjs +0 -3385
  411. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-runtime-home.mjs +0 -39
  412. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-runtime-support-25485dbf1cb2.mjs +0 -24
  413. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-sandbox-guards.mjs +0 -1102
  414. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-share.mjs +0 -1993
  415. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs +0 -1113
  416. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs +0 -505
  417. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +0 -222
  418. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-shared-protocol-contracts-b5f28f94.mjs +0 -5907
  419. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-upload-spool.mjs +0 -198
  420. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design.mjs +0 -1430
  421. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -2050
  422. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +0 -2
  423. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +0 -18
  424. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +0 -809
  425. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +0 -5693
  426. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +0 -4175
  427. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +0 -65
  428. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +0 -1755
  429. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +0 -62
  430. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +0 -2633
  431. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +0 -124
  432. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/package.json +0 -65
  433. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/enhancements.css +0 -388
  434. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/handoff-center.css +0 -81
  435. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.css +0 -1
  436. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/share.js +0 -133
  437. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +0 -1159
  438. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +0 -30
  439. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +0 -900
  440. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +0 -2261
  441. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +0 -1595
  442. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +0 -1467
  443. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +0 -1860
  444. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +0 -914
  445. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +0 -2578
  446. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +0 -582
  447. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +0 -17
  448. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +0 -12
  449. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-protocol-contracts.js +0 -285
  450. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-design-review-experience.js +0 -2773
  451. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-studio-shell.js +0 -134
  452. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-canvas-engine.js +0 -2207
  453. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-design-review-experience.js +0 -16
  454. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-studio-shell.js +0 -8
  455. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/18-interface-primitives.js +0 -3883
  456. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/19-interface-primitives.js +0 -966
  457. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/20-studio-shell.js +0 -520
  458. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/21-design-studio.js +0 -1597
  459. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +0 -311
  460. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +0 -159
  461. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/registries/artifact-theme.json +0 -64
  462. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.0.0/design-manifest.schema.json +0 -90
  463. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-envelope.schema.json +0 -142
  464. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-paste.schema.json +0 -49
  465. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  466. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-bundle.schema.json +0 -584
  467. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-context.schema.json +0 -191
  468. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-handoff.schema.json +0 -407
  469. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.10.0/design-review-metadata-payload.schema.json +0 -106
  470. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-handoff-readiness.schema.json +0 -398
  471. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-implementation-handoff.schema.json +0 -518
  472. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-planning-lineage.schema.json +0 -106
  473. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.11.0/design-review-metadata-payload.schema.json +0 -107
  474. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.14.0/artifact-theme.schema.json +0 -316
  475. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/artifact-envelope.schema.json +0 -408
  476. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.16.0/design-review-bundle.schema.json +0 -590
  477. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-document.schema.json +0 -506
  478. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.22.0/design-review-bundle.schema.json +0 -822
  479. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-bundle.schema.json +0 -346
  480. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-review-workspace.schema.json +0 -108
  481. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-create.schema.json +0 -170
  482. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-event.schema.json +0 -97
  483. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/schemas/v1.9.0/design-workspace-revision.schema.json +0 -56
  484. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +0 -5468
  485. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/design.mjs +0 -2844
  486. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/runtime/notices/THIRD_PARTY_NOTICES.txt +0 -21
  487. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +0 -159
  488. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/runtime/packages/protocol/schemas/v1.1.0/artifact-review.schema.json +0 -97
  489. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/integration-transaction.mjs +0 -958
  490. package/lib/host-packages/openai/openplanr/skills/design/scripts/design.mjs +0 -12
  491. package/lib/host-packages/openai/openplanr/skills/design-loop/scripts/design.mjs +0 -12
  492. package/lib/host-packages/openai/openplanr/skills/design-review/scripts/design.mjs +0 -12
  493. package/lib/host-packages/openai/openplanr/skills/plan/scripts/design.mjs +0 -12
@@ -0,0 +1,1080 @@
1
+ // Hand delegate work back through its run branch: snapshot, review, check at tip, git apply.
2
+ import { execFile } from 'node:child_process';
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { chmod, copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+ import { captureFileState, HOOKLESS_COMMIT, validateWorktreeCustody } from './custody.mjs';
8
+ import {
9
+ resolveSelectedChecks,
10
+ resolveSelectedGenerators,
11
+ runDelegateChecks,
12
+ runGenerator,
13
+ } from './integration-checks.mjs';
14
+ import {
15
+ assertSafeChanges,
16
+ changedSinceSnapshot,
17
+ covers,
18
+ IntegrationError,
19
+ safePath,
20
+ workingSnapshot,
21
+ } from './integration-files.mjs';
22
+ import {
23
+ acquireRunTransitionLock,
24
+ compactIntegrationState,
25
+ processIdentity,
26
+ processIdentityState,
27
+ } from './run-record.mjs';
28
+
29
+ const DIFF = [
30
+ '-c',
31
+ 'diff.noprefix=false',
32
+ '-c',
33
+ 'diff.ignoreSubmodules=none',
34
+ 'diff',
35
+ '--no-ext-diff',
36
+ '--no-textconv',
37
+ '--no-color',
38
+ '--no-relative',
39
+ '--no-renames',
40
+ '--submodule=short',
41
+ '--ignore-submodules=none',
42
+ ];
43
+ const APPLY = [
44
+ '-c',
45
+ 'apply.whitespace=nowarn',
46
+ '-c',
47
+ 'apply.ignoreWhitespace=no',
48
+ 'apply',
49
+ '--whitespace=nowarn',
50
+ ];
51
+ const BRANCH_VIOLATIONS = ['E_CUSTODY_BRANCH', 'E_CUSTODY_BASE'];
52
+ const SELECTION_ERRORS = [
53
+ 'E_INTEGRATION_CHECK_SELECTION',
54
+ 'E_INTEGRATION_GENERATOR_SELECTION',
55
+ 'E_INTEGRATION_GENERATOR_DRIFT',
56
+ ];
57
+
58
+ const ACTIVE_RECOVERY =
59
+ 'The delegate is still running: wait for this runId; if it stops for input, answer through resume, then review once it completes.';
60
+ const RUN_RECOVERY = {
61
+ question:
62
+ 'The delegate is waiting for an answer: run resume with this runId and an answer, then review once it completes.',
63
+ blocked:
64
+ 'The delegate stopped for attention: inspect status, resolve the cause, run resume with this runId and an answer or correction, then review once it completes.',
65
+ running: ACTIVE_RECOVERY,
66
+ resuming: ACTIVE_RECOVERY,
67
+ prepared: 'The run has not been dispatched: dispatch it, then review once it completes.',
68
+ };
69
+
70
+ function completed(run) {
71
+ return run?.status === 'completed' || run?.state === 'completed';
72
+ }
73
+
74
+ function reviewScope({ custody, run, scopePaths = [], preservePaths = [] } = {}) {
75
+ if (!custody?.repositoryRoot || !custody?.worktreePath)
76
+ throw new IntegrationError('E_INTEGRATION_RECORD', 'A custody record is required.');
77
+ if (!completed(run))
78
+ throw new IntegrationError(
79
+ 'E_INTEGRATION_RUN',
80
+ `Only a completed delegate run can be reviewed. ${RUN_RECOVERY[run?.status] ?? 'Inspect the run with status.'}`,
81
+ { status: run?.status ?? null },
82
+ );
83
+ if (!isBranchHandoff(custody))
84
+ throw new IntegrationError(
85
+ 'E_INTEGRATION_RECORD',
86
+ 'This custody has no run branch; finish the run with the helper pinned when it was prepared.',
87
+ );
88
+ if (!Array.isArray(scopePaths) || scopePaths.length === 0)
89
+ throw new IntegrationError(
90
+ 'E_INTEGRATION_SCOPE',
91
+ 'Explicit writable scope paths are required.',
92
+ );
93
+ const allowed = scopePaths.map(safePath);
94
+ const protectedPaths = [...(custody.preservePaths ?? []), ...preservePaths].map((entry) =>
95
+ safePath(typeof entry === 'string' ? entry : entry.path),
96
+ );
97
+ return { allowed, protectedPaths };
98
+ }
99
+
100
+ export async function checkoutLock(root) {
101
+ const path = join(
102
+ tmpdir(),
103
+ `planr-integration-lock-${createHash('sha256').update(root).digest('hex')}`,
104
+ );
105
+ // Serialize stale recovery with the same crash-safe acquisition used by runs.
106
+ // Keep the checkout owner file so retained helpers still observe an active apply.
107
+ const transitions = `${path}-transitions`;
108
+ await mkdir(join(transitions, 'checkout'), { recursive: true, mode: 0o700 });
109
+ let releaseTransition;
110
+ try {
111
+ releaseTransition = await acquireRunTransitionLock('checkout', { directory: transitions });
112
+ } catch (error) {
113
+ if (error.code === 'E_RUN_LOCKED')
114
+ throw new IntegrationError(
115
+ 'E_INTEGRATION_LOCKED',
116
+ 'Another integration holds this checkout.',
117
+ );
118
+ throw error;
119
+ }
120
+ const token = randomUUID();
121
+ try {
122
+ try {
123
+ await mkdir(path, { mode: 0o700 });
124
+ } catch (error) {
125
+ if (error.code !== 'EEXIST') throw error;
126
+ const owner = JSON.parse(await readFile(join(path, 'owner.json'), 'utf8'));
127
+ if (!['exited', 'reused'].includes(await processIdentityState(owner)))
128
+ throw new IntegrationError(
129
+ 'E_INTEGRATION_LOCKED',
130
+ 'Another integration holds this checkout.',
131
+ );
132
+ await rm(path, { recursive: true });
133
+ await mkdir(path, { mode: 0o700 });
134
+ }
135
+ await writeFile(
136
+ join(path, 'owner.json'),
137
+ JSON.stringify({ ...(await processIdentity()), token }),
138
+ {
139
+ flag: 'wx',
140
+ mode: 0o600,
141
+ },
142
+ );
143
+ } catch (error) {
144
+ await releaseTransition();
145
+ throw error;
146
+ }
147
+ return async () => {
148
+ try {
149
+ const owner = JSON.parse(await readFile(join(path, 'owner.json'), 'utf8'));
150
+ if (owner.token !== token)
151
+ throw new IntegrationError('E_INTEGRATION_LOCKED', 'Checkout lock ownership changed.');
152
+ await rm(path, { recursive: true });
153
+ } finally {
154
+ await releaseTransition();
155
+ }
156
+ };
157
+ }
158
+
159
+ async function compareWithBaseline(
160
+ results,
161
+ selectedChecks,
162
+ target,
163
+ { phase, timeoutMs, signal, onProcess },
164
+ ) {
165
+ const beforeBaseline = await workingSnapshot(target.root);
166
+ const failing = selectedChecks.filter((_check, index) => results[index]?.status === 'failed');
167
+ const baseline = await phase('baseline-checks', () =>
168
+ runDelegateChecks({
169
+ repositoryRoot: target.root,
170
+ checks: failing,
171
+ onProcess,
172
+ timeoutMs,
173
+ home: target.home,
174
+ signal: signal,
175
+ }),
176
+ );
177
+ const effects = await changedSinceSnapshot(target.root, beforeBaseline);
178
+ let index = 0;
179
+ const compared = results.map((result) => {
180
+ if (result.status !== 'failed') return result;
181
+ const evidence = baseline[index++];
182
+ const baselineStatus = effects.length ? 'unverified' : evidence.status;
183
+ return {
184
+ ...result,
185
+ baselineStatus,
186
+ baseline: evidence,
187
+ classification:
188
+ baselineStatus === 'failed'
189
+ ? 'baseline-failure'
190
+ : baselineStatus === 'passed'
191
+ ? 'regression'
192
+ : 'unverified',
193
+ };
194
+ });
195
+ return { results: compared, effects };
196
+ }
197
+
198
+ function gitOperation(args) {
199
+ return args.find((arg) => !arg.startsWith('-') && !arg.includes('='));
200
+ }
201
+
202
+ function git(cwd, args, { input, allowFailure = false, env } = {}) {
203
+ return new Promise((resolveResult, reject) => {
204
+ const child = execFile(
205
+ 'git',
206
+ args,
207
+ {
208
+ cwd,
209
+ encoding: 'buffer',
210
+ maxBuffer: 256 * 1024 * 1024,
211
+ ...(env ? { env: { ...process.env, ...env } } : {}),
212
+ },
213
+ (error, stdout, stderr) => {
214
+ const result = {
215
+ code: error ? (typeof error.code === 'number' ? error.code : -1) : 0,
216
+ stdout,
217
+ stderr: stderr.toString('utf8'),
218
+ };
219
+ if (!error || allowFailure) resolveResult(result);
220
+ else {
221
+ const operation = gitOperation(args);
222
+ reject(
223
+ new IntegrationError(
224
+ 'E_INTEGRATION_GIT',
225
+ `git ${operation} failed: ${result.stderr.trim().slice(-1024)}`,
226
+ { operation, exitCode: result.code },
227
+ ),
228
+ );
229
+ }
230
+ },
231
+ );
232
+ // Git may exit without reading stdin; its exit status, not the closed pipe, is the result.
233
+ child.stdin.on('error', (error) => {
234
+ if (error.code === 'EPIPE') return;
235
+ const operation = gitOperation(args);
236
+ reject(
237
+ new IntegrationError(
238
+ 'E_INTEGRATION_GIT',
239
+ `git ${operation} stdin failed: ${error.message}`,
240
+ { operation, cause: error.code },
241
+ ),
242
+ );
243
+ });
244
+ if (input === undefined) child.stdin.end();
245
+ else child.stdin.end(input);
246
+ });
247
+ }
248
+
249
+ async function text(cwd, args, options) {
250
+ return (await git(cwd, args, options)).stdout.toString('utf8').trim();
251
+ }
252
+
253
+ export function isBranchHandoff(custody) {
254
+ return custody?.handoff === 'branch';
255
+ }
256
+
257
+ /** Commits everything Git does not ignore in the run worktree and returns the run branch tip. */
258
+ export async function snapshotTip(custody) {
259
+ const root = custody.worktreePath;
260
+ await git(root, ['add', '-A']);
261
+ if ((await git(root, ['diff', '--cached', '--quiet'], { allowFailure: true })).code === 1)
262
+ await git(root, [...HOOKLESS_COMMIT, `planr-delegate tip ${custody.runId}`]);
263
+ return text(root, ['rev-parse', 'HEAD']);
264
+ }
265
+
266
+ async function statusPaths(root) {
267
+ const tokens = (
268
+ await git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all', '--no-renames'])
269
+ ).stdout
270
+ .toString('utf8')
271
+ .split('\0')
272
+ .filter(Boolean);
273
+ return tokens.map((row) => ({ code: row.slice(0, 2), path: row.slice(3) }));
274
+ }
275
+
276
+ const STATUS_CHANGE = { '??': 'extra', ' D': 'missing', D: 'missing' };
277
+
278
+ /** Lists how the run worktree differs from the reviewed tip. */
279
+ async function staleViolations(root, tip) {
280
+ const head = await text(root, ['rev-parse', 'HEAD']);
281
+ const violations = (await statusPaths(root)).map(({ code, path }) => ({
282
+ code: 'E_INTEGRATION_CANDIDATE_STALE',
283
+ path,
284
+ change: STATUS_CHANGE[code] ?? STATUS_CHANGE[code.trim()] ?? 'changed',
285
+ }));
286
+ if (head !== tip) violations.unshift({ code: 'E_INTEGRATION_CANDIDATE_STALE', head });
287
+ return violations;
288
+ }
289
+
290
+ async function assertAtTip(root, tip, violations) {
291
+ const stale = await staleViolations(root, tip);
292
+ if (!stale.length) return;
293
+ violations.push(...stale);
294
+ throw new IntegrationError(
295
+ 'E_INTEGRATION_CANDIDATE_STALE',
296
+ 'The run worktree changed after review. Review the actual files before verification or acceptance.',
297
+ );
298
+ }
299
+
300
+ async function changedEntries(root, base, tip) {
301
+ const range = tip ? [base, tip] : [base];
302
+ const tokens = (await git(root, [...DIFF, '-z', '--raw', '--no-abbrev', ...range])).stdout
303
+ .toString('utf8')
304
+ .split('\0');
305
+ const entries = [];
306
+ for (let index = 0; index + 1 < tokens.length && tokens[index]; index += 2) {
307
+ const [beforeMode, afterMode, beforeOid, afterOid] = tokens[index].slice(1).split(' ');
308
+ entries.push({ path: tokens[index + 1], beforeMode, afterMode, beforeOid, afterOid });
309
+ }
310
+ return entries;
311
+ }
312
+
313
+ /** Lists submodules that differ from base, including ones `ignore` settings hide from `git add`. */
314
+ async function submodulePaths(root, base) {
315
+ const paths = new Set(
316
+ (await changedEntries(root, base))
317
+ .filter(({ beforeMode, afterMode }) => beforeMode === '160000' || afterMode === '160000')
318
+ .map(({ path }) => path),
319
+ );
320
+ const status = (
321
+ await git(root, ['status', '--porcelain=v2', '-z', '--ignore-submodules=none'])
322
+ ).stdout
323
+ .toString('utf8')
324
+ .split('\0');
325
+ for (const row of status) {
326
+ const fields = row.split(' ');
327
+ if (['1', '2'].includes(fields[0]) && fields[2]?.startsWith('S'))
328
+ paths.add(fields.slice(fields[0] === '1' ? 8 : 9).join(' '));
329
+ }
330
+ return [...paths];
331
+ }
332
+
333
+ async function objectState(root, mode, oid) {
334
+ if (/^0+$/u.test(mode)) return { kind: 'absent' };
335
+ if (mode === '160000') return { kind: 'gitlink', mode: null, bytes: null, commit: oid };
336
+ const bytes = Number(await text(root, ['cat-file', '-s', oid]));
337
+ if (mode === '120000')
338
+ return {
339
+ kind: 'symlink',
340
+ mode: 0o777,
341
+ bytes,
342
+ target: (await git(root, ['cat-file', 'blob', oid])).stdout.toString('utf8'),
343
+ };
344
+ return { kind: 'file', mode: mode === '100755' ? 0o755 : 0o644, bytes, oid };
345
+ }
346
+
347
+ async function applyCheck(root, patch, paths) {
348
+ const result = await git(root, [...APPLY, '--check', '-'], {
349
+ input: patch,
350
+ allowFailure: true,
351
+ });
352
+ if (result.code === 0) return [];
353
+ const lines = result.stderr.split('\n').filter((line) => line.startsWith('error: '));
354
+ const named = paths
355
+ .map((path) => ({
356
+ path,
357
+ line: lines.find(
358
+ (line) => line.startsWith(`error: ${path}: `) || line.includes(`patch failed: ${path}:`),
359
+ ),
360
+ }))
361
+ .filter(({ line }) => line);
362
+ return named.length
363
+ ? named.map(({ path, line }) => ({
364
+ code: 'E_INTEGRATION_SOURCE_DRIFT',
365
+ path,
366
+ reason: line.slice('error: '.length),
367
+ }))
368
+ : [{ code: 'E_INTEGRATION_SOURCE_DRIFT', reason: result.stderr.trim().slice(-1024) }];
369
+ }
370
+
371
+ /** Reviews base..tip of the run branch against scope, Preserve and the current parent checkout. */
372
+ export async function reviewBranchDelta(input = {}) {
373
+ const { custody, run } = input;
374
+ const { allowed, protectedPaths } = reviewScope(input);
375
+ const custodyCheck = await validateWorktreeCustody(custody, {
376
+ native: Boolean(run.nativeSelection),
377
+ });
378
+ const violations = [...custodyCheck.violations];
379
+ const empty = { ready: false, changedPaths: [], changes: [], violations, patch: [] };
380
+ if (violations.some(({ code }) => BRANCH_VIOLATIONS.includes(code))) return empty;
381
+ const root = custody.worktreePath;
382
+ const tip = await snapshotTip(custody);
383
+ // git apply without --index leaves a submodule untouched yet reports success.
384
+ const submodules = await submodulePaths(root, custody.base);
385
+ violations.push(...submodules.map((path) => ({ code: 'E_INTEGRATION_GITLINK', path })));
386
+ const changes = [];
387
+ for (const entry of await changedEntries(root, custody.base, tip)) {
388
+ const { path } = entry;
389
+ const before = await objectState(root, entry.beforeMode, entry.beforeOid);
390
+ const after = await objectState(root, entry.afterMode, entry.afterOid);
391
+ if (!allowed.some((rule) => covers(rule, path)))
392
+ violations.push({ code: 'E_INTEGRATION_SCOPE', path });
393
+ if (protectedPaths.some((rule) => covers(rule, path)))
394
+ violations.push({ code: 'E_INTEGRATION_PRESERVE', path });
395
+ if (before.kind === 'gitlink' || after.kind === 'gitlink') {
396
+ if (!submodules.includes(path)) violations.push({ code: 'E_INTEGRATION_GITLINK', path });
397
+ } else
398
+ try {
399
+ await assertSafeChanges(custody.repositoryRoot, [{ path, after }]);
400
+ } catch (error) {
401
+ if (!(error instanceof IntegrationError)) throw error;
402
+ violations.push({ code: error.code, path });
403
+ }
404
+ changes.push({
405
+ path,
406
+ before,
407
+ after,
408
+ origin: run.verificationMutations?.includes(path)
409
+ ? 'parent-verification'
410
+ : run.preparationProvenance?.paths?.includes(path)
411
+ ? 'preparation-and-delegate'
412
+ : 'delegate',
413
+ });
414
+ }
415
+ const patchBytes = (
416
+ await git(root, [
417
+ ...DIFF,
418
+ '--binary',
419
+ '--full-index',
420
+ '--src-prefix=a/',
421
+ '--dst-prefix=b/',
422
+ custody.base,
423
+ tip,
424
+ ])
425
+ ).stdout;
426
+ const changedPaths = changes.map(({ path }) => path);
427
+ if (changes.length && !violations.length)
428
+ violations.push(...(await applyCheck(custody.repositoryRoot, patchBytes, changedPaths)));
429
+ return {
430
+ ready: violations.length === 0,
431
+ changedPaths,
432
+ changes,
433
+ violations,
434
+ warnings: custodyCheck.warnings,
435
+ patch: changes.map(({ path, before, after }) => ({ path, before, after })),
436
+ base: custody.base,
437
+ tip,
438
+ patchBytes,
439
+ patchSha256: createHash('sha256').update(patchBytes).digest('hex'),
440
+ };
441
+ }
442
+
443
+ function restoreRef(runId) {
444
+ return `refs/planr-delegate/${runId}/restore`;
445
+ }
446
+
447
+ async function baselineWorktree(custody) {
448
+ const base = await mkdtemp(join(tmpdir(), 'planr-baseline-'));
449
+ const root = join(base, 'checkout');
450
+ await git(custody.repositoryRoot, ['worktree', 'add', '--detach', '--', root, custody.base]);
451
+ return { base, root };
452
+ }
453
+
454
+ async function removeBaseline(custody, target) {
455
+ await git(custody.repositoryRoot, ['worktree', 'remove', '--force', '--', target.root]);
456
+ await rm(target.base, { recursive: true, force: true });
457
+ }
458
+
459
+ async function physicalModes(root, changes) {
460
+ const modes = {};
461
+ for (const { path, before } of changes) {
462
+ if (before.kind !== 'file') continue;
463
+ const info = await lstat(join(root, path));
464
+ if (info.isFile()) modes[path] = info.mode & 0o777;
465
+ }
466
+ return modes;
467
+ }
468
+
469
+ // git apply and git restore write files with default permissions; only the executable bit belongs to the delta.
470
+ async function restorePhysicalModes(root, modes, paths) {
471
+ for (const path of paths) {
472
+ const before = modes?.[path];
473
+ if (before === undefined) continue;
474
+ let info;
475
+ try {
476
+ info = await lstat(join(root, path));
477
+ } catch (error) {
478
+ if (error.code === 'ENOENT') continue;
479
+ throw error;
480
+ }
481
+ if (!info.isFile()) continue;
482
+ const mode = (before & ~0o111) | (info.mode & 0o111);
483
+ if (mode !== (info.mode & 0o777)) await chmod(join(root, path), mode);
484
+ }
485
+ }
486
+
487
+ /** Verifies the reviewed tip in the run worktree, then applies base..tip to the parent checkout. */
488
+ export async function integrateBranchDelta({
489
+ custody,
490
+ run,
491
+ scopePaths,
492
+ preservePaths,
493
+ checks,
494
+ preparation,
495
+ generators,
496
+ timeoutMs,
497
+ reviewedDigest,
498
+ baselineComparison = false,
499
+ reviewOnlyReason,
500
+ patchPath,
501
+ onVerification,
502
+ onApplying,
503
+ onAccepted,
504
+ onRolledBack,
505
+ } = {}) {
506
+ const native = Boolean(run.nativeSelection);
507
+ const root = custody.worktreePath;
508
+ let review = await reviewBranchDelta({ custody, run, scopePaths, preservePaths });
509
+ if (!review.ready)
510
+ return {
511
+ status: 'blocked',
512
+ ...review,
513
+ nextAction: 'Inspect the retained worktree and resolve the reported conflicts.',
514
+ };
515
+ if (reviewedDigest && reviewedDigest !== review.tip)
516
+ throw new IntegrationError(
517
+ 'E_INTEGRATION_REVIEW_DRIFT',
518
+ 'The delegate patch changed since review; review it again.',
519
+ );
520
+ const release = await checkoutLock(custody.repositoryRoot);
521
+ const controller = new AbortController();
522
+ const interrupt = () => controller.abort();
523
+ process.once('SIGINT', interrupt);
524
+ process.once('SIGTERM', interrupt);
525
+ const verification = {
526
+ status: 'running',
527
+ phase: 'candidate-selection',
528
+ candidateIdentity: review.tip,
529
+ candidatePath: root,
530
+ candidateKind: 'prepared-worktree',
531
+ startedAt: new Date().toISOString(),
532
+ phases: [],
533
+ preparation: [],
534
+ checks: [],
535
+ };
536
+ const progress = () => onVerification?.(verification);
537
+ const onProcess = async (identity) => {
538
+ verification.commandProcess = identity;
539
+ await progress();
540
+ };
541
+ async function phase(name, operation) {
542
+ verification.phase = name;
543
+ const step = { phase: name, startedAt: new Date().toISOString() };
544
+ verification.phases.push(step);
545
+ await progress();
546
+ try {
547
+ return await operation();
548
+ } finally {
549
+ step.finishedAt = new Date().toISOString();
550
+ step.durationMs = Date.parse(step.finishedAt) - Date.parse(step.startedAt);
551
+ await progress();
552
+ }
553
+ }
554
+ function recordMutations(effects) {
555
+ verification.mutatedPaths = [
556
+ ...new Set([...(verification.mutatedPaths ?? []), ...effects.map(({ path }) => path)]),
557
+ ];
558
+ }
559
+ async function prepare(target, steps, targetName) {
560
+ const before = await workingSnapshot(target);
561
+ const results = await runDelegateChecks({
562
+ repositoryRoot: target,
563
+ checks: steps,
564
+ timeoutMs,
565
+ signal: controller.signal,
566
+ onProcess,
567
+ stopOnFailure: true,
568
+ onResult: async (result) => {
569
+ verification.preparation.push({ ...result, target: targetName });
570
+ await progress();
571
+ },
572
+ });
573
+ if (results.some((result) => result.processTerminationConfirmed === false))
574
+ throw new IntegrationError(
575
+ 'E_INTEGRATION_PROCESS',
576
+ 'An owned preparation process could not be stopped.',
577
+ );
578
+ const effects = await changedSinceSnapshot(target, before);
579
+ if (effects.length) {
580
+ if (target === root) recordMutations(effects);
581
+ const code = native ? 'E_INTEGRATION_REVIEW_DRIFT' : 'E_INTEGRATION_PREPARATION_SIDE_EFFECT';
582
+ review.violations.push(...effects.map(({ path }) => ({ code, path })));
583
+ throw new IntegrationError(
584
+ code,
585
+ 'Preparation changed reviewable files. Inspect the updated candidate and review again.',
586
+ );
587
+ }
588
+ if (results.some(({ status }) => status !== 'passed'))
589
+ throw new IntegrationError('E_INTEGRATION_PREPARATION', 'Preparation failed before checks.');
590
+ }
591
+ const generatorRuns = [];
592
+ const generatedPaths = [];
593
+ const delegatePaths = [...review.changedPaths];
594
+ let results = [];
595
+ let failureCode;
596
+ let applying = false;
597
+ let baseline;
598
+ let restoreCreated = false;
599
+ try {
600
+ const protectedPaths = reviewScope({ custody, run, scopePaths, preservePaths }).protectedPaths;
601
+ const selectedGenerators = await resolveSelectedGenerators(
602
+ custody.repositoryRoot,
603
+ generators,
604
+ delegatePaths,
605
+ scopePaths,
606
+ protectedPaths,
607
+ );
608
+ const selectedChecks = await resolveSelectedChecks(root, checks, { legacy: !native });
609
+ const selectedPreparation = (
610
+ await resolveSelectedChecks(root, preparation ?? [], { legacy: !native })
611
+ ).map((step) => ({ ...step, kind: 'preparation' }));
612
+ if (
613
+ native &&
614
+ !selectedChecks.length &&
615
+ (typeof reviewOnlyReason !== 'string' || !reviewOnlyReason.trim())
616
+ )
617
+ throw new IntegrationError(
618
+ 'E_INTEGRATION_CHECKS_REQUIRED',
619
+ 'Select applicable independent commands or provide a reviewOnlyReason. Zero checks remains unverified.',
620
+ );
621
+ verification.reviewOnlyReason = selectedChecks.length ? null : reviewOnlyReason;
622
+ const selected = new Set(custody.selectedPaths ?? []);
623
+ const unselected = (await statusPaths(custody.repositoryRoot))
624
+ .map(({ path }) => path)
625
+ .filter((path) => !selected.has(path));
626
+ // Bounded: the list is kept in the size-limited run record.
627
+ verification.unselectedDirtyPaths = unselected.slice(0, 50);
628
+ verification.unselectedDirtyCount = unselected.length;
629
+ await phase('candidate-selection', () => assertAtTip(root, review.tip, review.violations));
630
+ if (selectedPreparation.length)
631
+ await phase('build-preparation', () => prepare(root, selectedPreparation, 'candidate'));
632
+ for (const generator of selectedGenerators) {
633
+ const generated = await phase('generation', () =>
634
+ runGenerator(root, { ...generator, signal: controller.signal, onProcess }, timeoutMs),
635
+ );
636
+ generatorRuns.push({
637
+ packagePath: generator.packagePath,
638
+ script: generator.script,
639
+ ...generated.result,
640
+ });
641
+ if (generated.result.processTerminationConfirmed === false)
642
+ throw new IntegrationError(
643
+ 'E_INTEGRATION_PROCESS',
644
+ 'An owned generator process could not be stopped. Recover it before inspecting or accepting the candidate.',
645
+ );
646
+ if (native) recordMutations(generated.changes);
647
+ if (!generated.passed)
648
+ throw new IntegrationError('E_INTEGRATION_GENERATION', 'A declared generator failed.', {
649
+ results: [generated.result],
650
+ });
651
+ const unexpected = generated.changes.filter(
652
+ ({ path }) => !generator.outputPaths.includes(path),
653
+ );
654
+ if (unexpected.length) {
655
+ review.violations.push(
656
+ ...unexpected.map(({ path }) => ({ code: 'E_INTEGRATION_GENERATOR_SCOPE', path })),
657
+ );
658
+ throw new IntegrationError(
659
+ 'E_INTEGRATION_GENERATOR_SCOPE',
660
+ 'Generator changed undeclared files.',
661
+ );
662
+ }
663
+ generatedPaths.push(...generated.changes.map(({ path }) => path));
664
+ }
665
+ if (generatedPaths.length) {
666
+ if (native)
667
+ throw new IntegrationError(
668
+ 'E_INTEGRATION_REVIEW_DRIFT',
669
+ 'Generated files changed the candidate. Review the resulting files before accepting.',
670
+ );
671
+ const regenerated = await reviewBranchDelta({ custody, run, scopePaths, preservePaths });
672
+ if (!regenerated.ready) {
673
+ review = regenerated;
674
+ throw new IntegrationError('E_INTEGRATION_GENERATOR_SCOPE', 'Generated files are unsafe.');
675
+ }
676
+ for (const change of regenerated.changes)
677
+ if (generatedPaths.includes(change.path)) change.origin = 'generator';
678
+ review = regenerated;
679
+ verification.candidateIdentity = review.tip;
680
+ }
681
+ await assertAtTip(root, review.tip, review.violations);
682
+ const beforeChecks = await workingSnapshot(root);
683
+ results = await phase('checks', () =>
684
+ runDelegateChecks({
685
+ repositoryRoot: root,
686
+ checks: selectedChecks,
687
+ timeoutMs,
688
+ signal: controller.signal,
689
+ onProcess,
690
+ onResult: async (_result, current) => {
691
+ verification.checks = [...current];
692
+ await progress();
693
+ },
694
+ }),
695
+ );
696
+ if (results.some((result) => result.processTerminationConfirmed === false))
697
+ throw new IntegrationError(
698
+ 'E_INTEGRATION_PROCESS',
699
+ 'An owned check process could not be stopped. Recover it before verification or acceptance.',
700
+ );
701
+ const checkEffects = await changedSinceSnapshot(root, beforeChecks);
702
+ if (checkEffects.length) {
703
+ recordMutations(checkEffects);
704
+ review.violations.push(
705
+ ...checkEffects.map(({ path }) => ({ code: 'E_INTEGRATION_CHECK_SIDE_EFFECT', path })),
706
+ );
707
+ throw new IntegrationError(
708
+ native ? 'E_INTEGRATION_REVIEW_DRIFT' : 'E_INTEGRATION_CHECK_SIDE_EFFECT',
709
+ 'Verification changed reviewable files. Inspect this candidate and review again.',
710
+ );
711
+ }
712
+ if (results.some((result) => result.status === 'timed-out'))
713
+ throw new IntegrationError('E_INTEGRATION_CHECK_TIMEOUT', 'An independent check timed out.');
714
+ if (results.some((result) => result.status === 'failed') && (!native || baselineComparison)) {
715
+ baseline = await phase('baseline-preparation', async () => {
716
+ const target = await baselineWorktree(custody);
717
+ baseline = target;
718
+ await prepare(target.root, selectedPreparation, 'baseline');
719
+ for (const generator of selectedGenerators) {
720
+ const generated = await runGenerator(
721
+ target.root,
722
+ { ...generator, signal: controller.signal, onProcess },
723
+ timeoutMs,
724
+ );
725
+ if (
726
+ !generated.passed ||
727
+ generated.changes.some(({ path }) => !generator.outputPaths.includes(path))
728
+ )
729
+ throw new IntegrationError(
730
+ 'E_INTEGRATION_BASELINE_GENERATION',
731
+ 'Baseline generation could not be verified.',
732
+ );
733
+ }
734
+ return target;
735
+ });
736
+ const comparison = await compareWithBaseline(results, selectedChecks, baseline, {
737
+ phase,
738
+ timeoutMs,
739
+ signal: controller.signal,
740
+ onProcess,
741
+ });
742
+ results = comparison.results;
743
+ if (comparison.effects.length)
744
+ review.violations.push(
745
+ ...comparison.effects.map(({ path }) => ({
746
+ code: 'E_INTEGRATION_BASELINE_SIDE_EFFECT',
747
+ path,
748
+ })),
749
+ );
750
+ verification.checks = results;
751
+ await progress();
752
+ throw new IntegrationError(
753
+ comparison.effects.length ? 'E_INTEGRATION_BASELINE_SIDE_EFFECT' : 'E_INTEGRATION_CHECKS',
754
+ 'Independent checks failed.',
755
+ );
756
+ }
757
+ if (results.some((result) => result.status !== 'passed'))
758
+ throw new IntegrationError(
759
+ 'E_INTEGRATION_CHECKS',
760
+ 'Independent checks failed. Baseline comparison is an explicit diagnostic action.',
761
+ );
762
+ await assertAtTip(root, review.tip, review.violations);
763
+ const custodyCheck = await validateWorktreeCustody(custody, { native });
764
+ review.warnings = custodyCheck.warnings;
765
+ if (!custodyCheck.valid) {
766
+ review.violations.push(...custodyCheck.violations);
767
+ throw new IntegrationError(
768
+ 'E_INTEGRATION_CUSTODY',
769
+ 'Run branch custody changed during verification.',
770
+ );
771
+ }
772
+ if (controller.signal.aborted)
773
+ throw new IntegrationError('E_INTEGRATION_INTERRUPTED', 'Integration was interrupted.');
774
+ const parent = custody.repositoryRoot;
775
+ const accepted = {
776
+ delegatePaths,
777
+ generatedPaths,
778
+ changedPaths: review.changedPaths,
779
+ checks: results,
780
+ generators: generatorRuns,
781
+ preparation: verification.preparation,
782
+ candidateIdentity: review.tip,
783
+ verified: results.length > 0 && results.every((result) => result.status === 'passed'),
784
+ reviewOnlyReason: verification.reviewOnlyReason,
785
+ base: review.base,
786
+ tip: review.tip,
787
+ patchSha256: review.patchSha256,
788
+ patchPath: null,
789
+ restoreRef: null,
790
+ restore: null,
791
+ };
792
+ if (review.changedPaths.length) {
793
+ const drift = await applyCheck(parent, review.patchBytes, review.changedPaths);
794
+ if (drift.length) {
795
+ review.violations.push(...drift);
796
+ throw new IntegrationError(
797
+ 'E_INTEGRATION_SOURCE_DRIFT',
798
+ 'The parent checkout no longer accepts the reviewed patch.',
799
+ );
800
+ }
801
+ if (patchPath) await writeFile(patchPath, review.patchBytes, { mode: 0o600 });
802
+ accepted.patchPath = patchPath ?? null;
803
+ accepted.restoreRef = restoreRef(custody.runId);
804
+ accepted.restore =
805
+ (await text(parent, ['stash', 'create'])) || (await text(parent, ['rev-parse', 'HEAD']));
806
+ await git(parent, ['update-ref', accepted.restoreRef, accepted.restore]);
807
+ restoreCreated = true;
808
+ accepted.modes = await physicalModes(parent, review.changes);
809
+ verification.phase = 'source-write';
810
+ verification.phases.push({ phase: 'source-write', startedAt: new Date().toISOString() });
811
+ await progress();
812
+ await onApplying?.(accepted);
813
+ applying = true;
814
+ const applied = await git(parent, [...APPLY, '-'], {
815
+ input: review.patchBytes,
816
+ allowFailure: true,
817
+ });
818
+ if (applied.code !== 0) {
819
+ const states = await pathStates(parent, accepted, review.patchBytes, review.changedPaths);
820
+ if (Object.values(states).some((state) => ['applied', 'unknown'].includes(state)))
821
+ throw new IntegrationError(
822
+ 'E_INTEGRATION_APPLY_INTERRUPTED',
823
+ `git apply failed after its check: ${applied.stderr.trim().slice(-1024)}`,
824
+ );
825
+ // Nothing was written, so the run returns to review instead of recovery.
826
+ await onRolledBack?.({ rollbackErrors: [], code: 'E_INTEGRATION_SOURCE_DRIFT' });
827
+ applying = false;
828
+ review.violations.push(
829
+ ...Object.entries(states)
830
+ .filter(([, state]) => state === 'conflict')
831
+ .map(([path]) => ({ code: 'E_INTEGRATION_SOURCE_DRIFT', path })),
832
+ );
833
+ throw new IntegrationError(
834
+ 'E_INTEGRATION_SOURCE_DRIFT',
835
+ `The parent checkout changed after the apply check: ${applied.stderr.trim().slice(-1024)}`,
836
+ );
837
+ }
838
+ await restorePhysicalModes(parent, accepted.modes, review.changedPaths);
839
+ }
840
+ const states = {};
841
+ for (const path of review.changedPaths)
842
+ states[path] = compactIntegrationState(await captureFileState(parent, path));
843
+ await onAccepted?.({ ...accepted, states });
844
+ applying = false;
845
+ if (restoreCreated) await git(parent, ['update-ref', '-d', accepted.restoreRef]);
846
+ return {
847
+ status: 'completed',
848
+ ...review,
849
+ unselectedDirtyPaths: verification.unselectedDirtyPaths,
850
+ unselectedDirtyCount: verification.unselectedDirtyCount,
851
+ checks: results,
852
+ generatedPaths,
853
+ generators: generatorRuns,
854
+ nextAction:
855
+ 'Review the uncommitted local diff. The owned worktree is removed unless retention was requested.',
856
+ };
857
+ } catch (error) {
858
+ failureCode = error.code ?? 'E_INTEGRATION_APPLY';
859
+ if (SELECTION_ERRORS.includes(error.code)) throw error;
860
+ if (error.details?.path) review.violations.push({ code: failureCode, ...error.details });
861
+ if (restoreCreated && !applying)
862
+ await git(custody.repositoryRoot, ['update-ref', '-d', restoreRef(custody.runId)]);
863
+ return {
864
+ status: 'blocked',
865
+ ...review,
866
+ code: failureCode,
867
+ checks: results,
868
+ generatedPaths,
869
+ generators: generatorRuns,
870
+ rollbackErrors: [],
871
+ nextAction: applying
872
+ ? 'Run integrate recover with this runId: rollback (default) or accept after inspecting the listed paths.'
873
+ : failureCode === 'E_INTEGRATION_PROCESS'
874
+ ? 'Recover the recorded owned parent command before checks, continuation or cleanup.'
875
+ : failureCode === 'E_INTEGRATION_CHECK_TIMEOUT'
876
+ ? 'Retry apply with a measured timeoutMs.'
877
+ : 'Send the findings to the same delegate session for correction; the worktree remains available.',
878
+ };
879
+ } finally {
880
+ process.removeListener('SIGINT', interrupt);
881
+ process.removeListener('SIGTERM', interrupt);
882
+ for (const step of verification.phases) {
883
+ if (!step.finishedAt) {
884
+ step.finishedAt = new Date().toISOString();
885
+ step.durationMs = Date.parse(step.finishedAt) - Date.parse(step.startedAt);
886
+ }
887
+ }
888
+ if (verification.commandProcess && baseline)
889
+ verification.retainedCandidatePaths = [baseline.root];
890
+ verification.status = failureCode ? 'blocked' : 'completed';
891
+ verification.phase = failureCode ? 'blocked' : 'integrated';
892
+ verification.finishedAt = new Date().toISOString();
893
+ verification.durationMs =
894
+ Date.parse(verification.finishedAt) - Date.parse(verification.startedAt);
895
+ verification.code = failureCode ?? null;
896
+ verification.checks = results.length ? results : verification.checks;
897
+ try {
898
+ await progress();
899
+ } finally {
900
+ if (baseline && !verification.commandProcess) await removeBaseline(custody, baseline);
901
+ await release();
902
+ }
903
+ }
904
+ }
905
+
906
+ async function workingObject(root, path) {
907
+ let info;
908
+ try {
909
+ info = await lstat(join(root, path));
910
+ } catch (error) {
911
+ if (error.code === 'ENOENT') return ABSENT;
912
+ throw error;
913
+ }
914
+ if (info.isSymbolicLink()) {
915
+ const state = await captureFileState(root, path);
916
+ return {
917
+ mode: '120000',
918
+ oid: await text(root, ['hash-object', '--stdin'], { input: state.target }),
919
+ };
920
+ }
921
+ return {
922
+ mode: info.mode & 0o111 ? '100755' : '100644',
923
+ oid: await text(root, ['--literal-pathspecs', 'hash-object', '--', path]),
924
+ };
925
+ }
926
+
927
+ const ABSENT = { mode: null, oid: 'absent' };
928
+ const UNKNOWN = { mode: null, oid: 'unknown' };
929
+
930
+ async function imageObjects(root, integration, patch, paths) {
931
+ const directory = await mkdtemp(join(tmpdir(), 'planr-recover-'));
932
+ const env = { GIT_INDEX_FILE: join(directory, 'index') };
933
+ const objects = async () => {
934
+ const found = {};
935
+ for (const line of (
936
+ await text(root, ['--literal-pathspecs', 'ls-files', '-s', '-z', '--', ...paths], { env })
937
+ ).split('\0')) {
938
+ const separator = line.indexOf('\t');
939
+ if (separator > 0) {
940
+ const [mode, oid] = line.slice(0, separator).split(' ');
941
+ found[line.slice(separator + 1)] = { mode, oid };
942
+ }
943
+ }
944
+ return Object.fromEntries(paths.map((path) => [path, found[path] ?? ABSENT]));
945
+ };
946
+ try {
947
+ await git(root, ['read-tree', integration.restore], { env });
948
+ // The restore point holds tracked files only; selected untracked files start at base.
949
+ for (const path of paths) {
950
+ const listed = await text(root, ['--literal-pathspecs', 'ls-files', '-s', '--', path], {
951
+ env,
952
+ });
953
+ const fromBase = await text(root, [
954
+ '--literal-pathspecs',
955
+ 'ls-tree',
956
+ integration.base,
957
+ '--',
958
+ path,
959
+ ]);
960
+ if (!listed && fromBase) {
961
+ const [mode, , oid] = fromBase.split('\t')[0].split(' ');
962
+ await git(root, ['update-index', '--add', '--cacheinfo', `${mode},${oid},${path}`], {
963
+ env,
964
+ });
965
+ }
966
+ }
967
+ const pre = await objects();
968
+ const preIndex = join(directory, 'pre-index');
969
+ await copyFile(env.GIT_INDEX_FILE, preIndex);
970
+ if (
971
+ (await git(root, [...APPLY, '--cached', '-'], { input: patch, env, allowFailure: true }))
972
+ .code === 0
973
+ )
974
+ return { pre, post: await objects() };
975
+ // The owner changed a path before the restore point; only that path's post-image is unknown.
976
+ const post = {};
977
+ for (const path of paths) {
978
+ await copyFile(preIndex, env.GIT_INDEX_FILE);
979
+ const include = `--include=${path.replace(/[*?[\]\\]/gu, '\\$&')}`;
980
+ const result = await git(root, [...APPLY, '--cached', include, '-'], {
981
+ input: patch,
982
+ env,
983
+ allowFailure: true,
984
+ });
985
+ post[path] = result.code === 0 ? (await objects())[path] : UNKNOWN;
986
+ }
987
+ return { pre, post };
988
+ } finally {
989
+ await rm(directory, { recursive: true, force: true });
990
+ }
991
+ }
992
+
993
+ function matches(current, image, other) {
994
+ if (current.oid !== image.oid) return false;
995
+ return image.oid !== other.oid || current.mode === image.mode;
996
+ }
997
+
998
+ /** Classifies each patch path as applied, pending or conflict against its pre and post images. */
999
+ async function pathStates(root, integration, patch, paths) {
1000
+ const { pre, post } = await imageObjects(root, integration, patch, paths);
1001
+ const states = {};
1002
+ for (const path of paths) {
1003
+ const current = await workingObject(root, path);
1004
+ states[path] = matches(current, post[path], pre[path])
1005
+ ? 'applied'
1006
+ : matches(current, pre[path], post[path])
1007
+ ? 'pending'
1008
+ : post[path] === UNKNOWN
1009
+ ? 'unknown'
1010
+ : 'conflict';
1011
+ }
1012
+ return states;
1013
+ }
1014
+
1015
+ /** Resolves an apply interrupted between its check and completion without overwriting user edits. */
1016
+ export async function recoverBranchApply(record, resolution = 'rollback') {
1017
+ if (!['rollback', 'accept'].includes(resolution))
1018
+ throw new IntegrationError(
1019
+ 'E_INTEGRATION_RECOVERY',
1020
+ 'Recovery resolution must be rollback or accept.',
1021
+ );
1022
+ const integration = record.integration;
1023
+ const root = record.repositoryRoot;
1024
+ if (integration.patchPath !== join(record.runPath, 'patch.diff'))
1025
+ throw new IntegrationError('E_INTEGRATION_PATCH', 'Recorded patch pointer is invalid.');
1026
+ const patch = await readFile(integration.patchPath);
1027
+ if (createHash('sha256').update(patch).digest('hex') !== integration.patchSha256)
1028
+ throw new IntegrationError('E_INTEGRATION_PATCH', 'Recorded patch changed after apply began.');
1029
+ const paths = integration.changedPaths;
1030
+ const release = await checkoutLock(root);
1031
+ try {
1032
+ const states = await pathStates(root, integration, patch, paths);
1033
+ const applied = paths.filter((path) => states[path] === 'applied');
1034
+ if (resolution === 'accept') {
1035
+ if (applied.length !== paths.length)
1036
+ throw new IntegrationError(
1037
+ 'E_INTEGRATION_RECOVERY_INCOMPLETE',
1038
+ applied.length
1039
+ ? 'The patch was applied partially; recover with rollback.'
1040
+ : 'The patch was not applied; recover with rollback.',
1041
+ );
1042
+ await restorePhysicalModes(root, integration.modes, paths);
1043
+ return { state: 'applied', restored: [], conflicts: [] };
1044
+ }
1045
+ for (const path of applied) {
1046
+ const source = (await text(root, [
1047
+ '--literal-pathspecs',
1048
+ 'ls-tree',
1049
+ integration.restore,
1050
+ '--',
1051
+ path,
1052
+ ]))
1053
+ ? integration.restore
1054
+ : (await text(root, ['--literal-pathspecs', 'ls-tree', integration.base, '--', path]))
1055
+ ? integration.base
1056
+ : null;
1057
+ if (!source) await rm(join(root, path), { force: true });
1058
+ else
1059
+ await git(root, [
1060
+ '--literal-pathspecs',
1061
+ 'restore',
1062
+ `--source=${source}`,
1063
+ '--worktree',
1064
+ '--',
1065
+ path,
1066
+ ]);
1067
+ }
1068
+ await restorePhysicalModes(root, integration.modes, applied);
1069
+ const conflicts = paths
1070
+ .filter((path) => ['conflict', 'unknown'].includes(states[path]))
1071
+ .map((path) => ({ path, code: 'E_INTEGRATION_ROLLBACK_CONFLICT' }));
1072
+ return {
1073
+ state: conflicts.length ? 'interrupted' : 'rolled-back',
1074
+ restored: applied,
1075
+ conflicts,
1076
+ };
1077
+ } finally {
1078
+ await release();
1079
+ }
1080
+ }