@buffcore/cli 0.8.46 → 0.8.48

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 (271) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/commands/build/server-text.en.d.ts +5 -0
  3. package/dist/commands/build/server-text.en.js +5 -0
  4. package/dist/commands/build/server-text.js +5 -0
  5. package/dist/commands/build/server.d.ts +4 -0
  6. package/dist/commands/build/server.js +10 -1
  7. package/dist/commands/change-merge-remove.d.ts +9 -2
  8. package/dist/commands/change-merge-remove.js +27 -15
  9. package/dist/commands/change-merge.d.ts +2 -2
  10. package/dist/commands/design/check.d.ts +1 -1
  11. package/dist/commands/design/check.js +2 -1
  12. package/dist/commands/design/contract-size.d.ts +7 -0
  13. package/dist/commands/design/contract-size.js +47 -0
  14. package/dist/commands/design/tells.en.d.ts +2 -0
  15. package/dist/commands/design/tells.en.js +2 -0
  16. package/dist/commands/design/tells.es.js +2 -0
  17. package/dist/commands/dev.d.ts +9 -2
  18. package/dist/commands/dev.js +24 -5
  19. package/dist/commands/extension/places-approval.d.ts +4 -0
  20. package/dist/commands/hardening.d.ts +3 -0
  21. package/dist/commands/hardening.en.d.ts +3 -0
  22. package/dist/commands/hardening.en.js +3 -0
  23. package/dist/commands/hardening.es.d.ts +2 -0
  24. package/dist/commands/hardening.es.js +3 -0
  25. package/dist/commands/hardening.js +19 -0
  26. package/dist/commands/process-paths.d.ts +14 -0
  27. package/dist/commands/process-paths.js +90 -0
  28. package/dist/commands/prototype/ai-approval.d.ts +27 -0
  29. package/dist/commands/prototype/ai-approval.js +60 -0
  30. package/dist/commands/prototype/approver.d.ts +71 -0
  31. package/dist/commands/prototype/approver.js +168 -0
  32. package/dist/commands/prototype/comp-record.d.ts +5 -0
  33. package/dist/commands/prototype/comp-record.js +22 -0
  34. package/dist/commands/prototype/critique-gate.d.ts +14 -0
  35. package/dist/commands/prototype/critique-gate.js +48 -0
  36. package/dist/commands/prototype/fence.d.ts +1 -0
  37. package/dist/commands/prototype/fence.js +12 -0
  38. package/dist/commands/prototype/final-approval-grant.js +18 -0
  39. package/dist/commands/prototype/final-approval.js +4 -1
  40. package/dist/commands/prototype/index.js +3 -0
  41. package/dist/commands/prototype/layout-hints.d.ts +34 -0
  42. package/dist/commands/prototype/layout-hints.js +194 -0
  43. package/dist/commands/prototype/layout-measure.d.ts +39 -0
  44. package/dist/commands/prototype/layout-measure.js +97 -0
  45. package/dist/commands/prototype/layout-words.d.ts +2 -0
  46. package/dist/commands/prototype/layout-words.js +11 -0
  47. package/dist/commands/prototype/layout.en.d.ts +6 -0
  48. package/dist/commands/prototype/layout.en.js +7 -0
  49. package/dist/commands/prototype/load-location.js +2 -3
  50. package/dist/commands/prototype/messages.en.d.ts +14 -0
  51. package/dist/commands/prototype/messages.en.js +15 -1
  52. package/dist/commands/prototype/messages.js +15 -1
  53. package/dist/commands/prototype/milestone-versions.d.ts +4 -0
  54. package/dist/commands/prototype/prune-command.d.ts +5 -0
  55. package/dist/commands/prototype/prune-command.js +25 -0
  56. package/dist/commands/prototype/prune-words.d.ts +1 -0
  57. package/dist/commands/prototype/prune-words.js +7 -0
  58. package/dist/commands/prototype/prune.d.ts +16 -0
  59. package/dist/commands/prototype/prune.en.d.ts +9 -0
  60. package/dist/commands/prototype/prune.en.js +9 -0
  61. package/dist/commands/prototype/prune.es.d.ts +2 -0
  62. package/dist/commands/prototype/prune.es.js +9 -0
  63. package/dist/commands/prototype/prune.js +140 -0
  64. package/dist/commands/prototype/reopen-messages.d.ts +9 -0
  65. package/dist/commands/prototype/reopen-messages.js +19 -0
  66. package/dist/commands/prototype/report.d.ts +14 -0
  67. package/dist/commands/prototype/report.js +5 -1
  68. package/dist/commands/prototype/scene-layout.d.ts +17 -0
  69. package/dist/commands/prototype/scene-layout.js +57 -0
  70. package/dist/commands/prototype/scene-ready.js +8 -2
  71. package/dist/commands/prototype/scene.d.ts +15 -2
  72. package/dist/commands/prototype/scene.js +54 -42
  73. package/dist/commands/prototype/selector-answer.d.ts +43 -0
  74. package/dist/commands/prototype/selector-answer.js +73 -0
  75. package/dist/commands/prototype/selector-misses.d.ts +19 -0
  76. package/dist/commands/prototype/selector-misses.js +78 -0
  77. package/dist/commands/prototype/selector-prompt.d.ts +23 -0
  78. package/dist/commands/prototype/selector-prompt.js +32 -0
  79. package/dist/commands/prototype/selector-run.d.ts +13 -0
  80. package/dist/commands/prototype/selector-run.js +113 -0
  81. package/dist/commands/prototype/selector.d.ts +54 -0
  82. package/dist/commands/prototype/selector.js +96 -0
  83. package/dist/commands/prototype/snapshot-ancestor.js +2 -0
  84. package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
  85. package/dist/commands/prototype/snapshot-bundle.js +69 -7
  86. package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
  87. package/dist/commands/prototype/snapshot-check-files.js +41 -0
  88. package/dist/commands/prototype/snapshot-command.d.ts +2 -0
  89. package/dist/commands/prototype/snapshot-command.js +3 -0
  90. package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
  91. package/dist/commands/prototype/snapshot-completion.js +30 -2
  92. package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
  93. package/dist/commands/prototype/snapshot-dependencies.js +120 -14
  94. package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
  95. package/dist/commands/prototype/snapshot-hashes.js +28 -0
  96. package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
  97. package/dist/commands/prototype/snapshot-inputs.js +140 -197
  98. package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
  99. package/dist/commands/prototype/snapshot-matrix.js +95 -0
  100. package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
  101. package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
  102. package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
  103. package/dist/commands/prototype/snapshot-owners.js +12 -3
  104. package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
  105. package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
  106. package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
  107. package/dist/commands/prototype/snapshot-progress.js +54 -102
  108. package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
  109. package/dist/commands/prototype/snapshot-registry.js +121 -0
  110. package/dist/commands/prototype/snapshot-report.d.ts +4 -0
  111. package/dist/commands/prototype/snapshot-report.js +77 -12
  112. package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
  113. package/dist/commands/prototype/snapshot-requests.js +68 -30
  114. package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
  115. package/dist/commands/prototype/snapshot-reuse.js +17 -7
  116. package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
  117. package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
  118. package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
  119. package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
  120. package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
  121. package/dist/commands/prototype/snapshot-server-record.js +135 -0
  122. package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
  123. package/dist/commands/prototype/snapshot-servers.js +50 -2
  124. package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
  125. package/dist/commands/prototype/snapshot-setup.js +2 -1
  126. package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
  127. package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
  128. package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
  129. package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
  130. package/dist/commands/prototype/snapshot.d.ts +5 -0
  131. package/dist/commands/prototype/snapshot.js +72 -10
  132. package/dist/commands/prototype/version-commands.d.ts +4 -0
  133. package/dist/commands/prototype/version-commands.js +36 -8
  134. package/dist/commands/prototype/versions.d.ts +28 -2
  135. package/dist/commands/prototype/versions.js +25 -1
  136. package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
  137. package/dist/commands/prototype/vite-fs-path.js +15 -0
  138. package/dist/commands/remove-links.d.ts +6 -0
  139. package/dist/commands/remove-links.js +17 -0
  140. package/dist/commands/server/build.d.ts +2 -1
  141. package/dist/commands/server/build.js +10 -2
  142. package/dist/commands/server/deploy-local.d.ts +3 -0
  143. package/dist/commands/server/deploy-local.js +9 -0
  144. package/dist/commands/server/deploy-plan.d.ts +5 -0
  145. package/dist/commands/server/deploy-plan.js +56 -0
  146. package/dist/commands/server/deploy-result.d.ts +7 -0
  147. package/dist/commands/server/deploy-result.js +1 -0
  148. package/dist/commands/server/deploy-script.d.ts +2 -0
  149. package/dist/commands/server/deploy-script.js +3 -2
  150. package/dist/commands/server/deploy.d.ts +9 -6
  151. package/dist/commands/server/deploy.js +39 -61
  152. package/dist/commands/server/files.d.ts +9 -1
  153. package/dist/commands/server/files.js +25 -5
  154. package/dist/commands/server/image.d.ts +4 -2
  155. package/dist/commands/server/image.js +6 -5
  156. package/dist/commands/server/setup.js +4 -0
  157. package/dist/commands/server/system-packages.d.ts +29 -0
  158. package/dist/commands/server/system-packages.js +103 -0
  159. package/dist/commands/services/compose.d.ts +1 -1
  160. package/dist/commands/services/compose.js +5 -3
  161. package/dist/commands/size-docs.d.ts +9 -0
  162. package/dist/commands/size-docs.en.d.ts +6 -0
  163. package/dist/commands/size-docs.en.js +6 -0
  164. package/dist/commands/size-docs.es.d.ts +2 -0
  165. package/dist/commands/size-docs.es.js +6 -0
  166. package/dist/commands/size-docs.js +28 -0
  167. package/dist/commands/size.d.ts +5 -2
  168. package/dist/commands/size.js +27 -9
  169. package/dist/commands/ui/agents-route.js +2 -0
  170. package/dist/commands/ui/approval-authority.d.ts +10 -2
  171. package/dist/commands/ui/approval-authority.en.d.ts +1 -0
  172. package/dist/commands/ui/approval-authority.en.js +1 -0
  173. package/dist/commands/ui/approval-authority.es.d.ts +1 -0
  174. package/dist/commands/ui/approval-authority.es.js +1 -0
  175. package/dist/commands/ui/approval-authority.js +8 -2
  176. package/dist/commands/ui/approve.js +2 -4
  177. package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
  178. package/dist/commands/ui/autopilot-ai-approve.js +68 -0
  179. package/dist/commands/ui/autopilot-loop.js +5 -6
  180. package/dist/commands/ui/autopilot-merge.js +3 -0
  181. package/dist/commands/ui/autopilot-records.d.ts +2 -0
  182. package/dist/commands/ui/autopilot-records.js +5 -0
  183. package/dist/commands/ui/autopilot.en.d.ts +23 -0
  184. package/dist/commands/ui/autopilot.en.js +23 -0
  185. package/dist/commands/ui/autopilot.es.d.ts +23 -0
  186. package/dist/commands/ui/autopilot.es.js +23 -0
  187. package/dist/commands/ui/brand-approval.js +5 -1
  188. package/dist/commands/ui/chat/find.d.ts +2 -0
  189. package/dist/commands/ui/chat/find.js +13 -0
  190. package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
  191. package/dist/commands/ui/chat/fresh-codex.js +175 -0
  192. package/dist/commands/ui/chat/fresh-critique.js +13 -5
  193. package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
  194. package/dist/commands/ui/chat/fresh-launch.js +67 -11
  195. package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
  196. package/dist/commands/ui/chat/fresh-prompts.js +2 -0
  197. package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
  198. package/dist/commands/ui/chat/fresh-secrets.js +172 -0
  199. package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
  200. package/dist/commands/ui/chat/fresh.en.js +2 -1
  201. package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
  202. package/dist/commands/ui/chat/fresh.es.js +2 -1
  203. package/dist/commands/ui/chat/permissions.js +1 -1
  204. package/dist/commands/ui/chat/routes.js +4 -0
  205. package/dist/commands/ui/chat/worktree.js +25 -5
  206. package/dist/commands/ui/comp-approval.d.ts +14 -2
  207. package/dist/commands/ui/comp-approval.js +45 -8
  208. package/dist/commands/ui/index.js +3 -0
  209. package/dist/commands/ui/level-route.js +3 -0
  210. package/dist/commands/ui/loop-approve.d.ts +30 -1
  211. package/dist/commands/ui/loop-approve.js +2 -2
  212. package/dist/commands/ui/merge-authority.d.ts +4 -1
  213. package/dist/commands/ui/merge-authority.en.d.ts +4 -0
  214. package/dist/commands/ui/merge-authority.en.js +5 -1
  215. package/dist/commands/ui/merge-authority.es.d.ts +4 -0
  216. package/dist/commands/ui/merge-authority.es.js +5 -1
  217. package/dist/commands/ui/merge-authority.js +6 -3
  218. package/dist/commands/ui/merge-claims.d.ts +7 -0
  219. package/dist/commands/ui/merge-claims.js +21 -0
  220. package/dist/commands/ui/merge-delegation.js +8 -3
  221. package/dist/commands/ui/merge-hold-name.d.ts +5 -0
  222. package/dist/commands/ui/merge-hold-name.js +5 -0
  223. package/dist/commands/ui/merge-hold.d.ts +6 -1
  224. package/dist/commands/ui/merge-hold.js +23 -5
  225. package/dist/commands/ui/merge-publish-host.d.ts +1 -0
  226. package/dist/commands/ui/merge-publish-host.js +2 -2
  227. package/dist/commands/ui/merge-record.d.ts +2 -0
  228. package/dist/commands/ui/merge-record.js +1 -1
  229. package/dist/commands/ui/merge-route.js +20 -1
  230. package/dist/commands/ui/merge-settle.d.ts +32 -0
  231. package/dist/commands/ui/merge-settle.js +133 -0
  232. package/dist/commands/ui/merge-state.d.ts +5 -0
  233. package/dist/commands/ui/merge-state.js +7 -1
  234. package/dist/commands/ui/merge-withdraw.d.ts +9 -0
  235. package/dist/commands/ui/merge-withdraw.js +29 -0
  236. package/dist/commands/ui/places-change.d.ts +4 -0
  237. package/dist/commands/ui/plan-files.js +5 -2
  238. package/dist/commands/ui/plan-structure.js +5 -7
  239. package/dist/commands/ui/prototype-comp-route.d.ts +12 -3
  240. package/dist/commands/ui/prototype-comp-route.js +35 -17
  241. package/dist/commands/ui/prototype-main.d.ts +4 -0
  242. package/dist/commands/ui/real-file.d.ts +11 -0
  243. package/dist/commands/ui/real-file.js +84 -0
  244. package/dist/commands/ui/reopen-route.d.ts +117 -0
  245. package/dist/commands/ui/reopen-route.js +97 -0
  246. package/dist/commands/ui/save-route.d.ts +2 -0
  247. package/dist/commands/ui/save-route.js +8 -1
  248. package/dist/commands/ui/server.d.ts +1 -0
  249. package/dist/commands/ui/server.js +1 -0
  250. package/dist/commands/ui/studio-routes.js +2 -0
  251. package/dist/commands/ui/studio-state.d.ts +34 -0
  252. package/dist/commands/ui/studio-versions.d.ts +24 -0
  253. package/dist/commands/ui/studio-versions.js +19 -3
  254. package/dist/commands/ui/worktrees.d.ts +1 -1
  255. package/dist/commands/ui/worktrees.js +19 -3
  256. package/dist/commands/worktree-sweep.d.ts +45 -0
  257. package/dist/commands/worktree-sweep.js +188 -0
  258. package/dist/commands/worktrees-command.d.ts +32 -0
  259. package/dist/commands/worktrees-command.en.d.ts +25 -0
  260. package/dist/commands/worktrees-command.en.js +55 -0
  261. package/dist/commands/worktrees-command.js +96 -0
  262. package/dist/main.js +2 -0
  263. package/dist/ui/page.js +89 -89
  264. package/docs/PROTOTYPE.md +19 -3
  265. package/docs/WORKBENCH.md +41 -6
  266. package/package.json +11 -11
  267. package/skills/ape-critique/SKILL.md +41 -6
  268. package/skills/ape-deploy/SKILL.md +4 -2
  269. package/skills/ape-design-system/SKILL.md +3 -0
  270. package/skills/ape-plan-change/SKILL.md +6 -0
  271. package/skills/ape-prototype/SKILL.md +8 -4
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Under the publication lock the caller holds: withdraw each waiting Autopilot claim (of the named
3
+ * changes, or all) whose head main does not hold, so a host's later settle of it is unknown. A
4
+ * head main already holds is a merge, left for the next read to record. A Git that cannot say
5
+ * withdraws: Autopilot never keeps a claim it cannot judge.
6
+ */
7
+ export declare function withdrawWaiting(root: string, changes?: readonly string[]): Promise<number>;
@@ -0,0 +1,21 @@
1
+ import { readRecord } from './autopilot-records.js';
2
+ import { mainHas } from './merge-observed.js';
3
+ import { closeRecord, withdraw } from './merge-record.js';
4
+ /**
5
+ * Under the publication lock the caller holds: withdraw each waiting Autopilot claim (of the named
6
+ * changes, or all) whose head main does not hold, so a host's later settle of it is unknown. A
7
+ * head main already holds is a merge, left for the next read to record. A Git that cannot say
8
+ * withdraws: Autopilot never keeps a claim it cannot judge.
9
+ */
10
+ export async function withdrawWaiting(root, changes) {
11
+ let count = 0;
12
+ for (const pending of readRecord(root)?.pending ?? []) {
13
+ if (!pending.automatic || (changes && !changes.includes(pending.change)))
14
+ continue;
15
+ if (await mainHas(root, pending.head).catch(() => false))
16
+ continue;
17
+ if (await closeRecord(root, withdraw(pending, undefined)))
18
+ count++;
19
+ }
20
+ return count;
21
+ }
@@ -1,4 +1,4 @@
1
- import { randomUUID } from 'node:crypto';
1
+ import { createHash, randomBytes, randomUUID } from 'node:crypto';
2
2
  import { defaultMergeTools, locked } from '../change-merge.js';
3
3
  import { readRecord, updateRecord, } from './autopilot-records.js';
4
4
  import { mergeRefusal, mergeWaiting, } from './merge-authority.js';
@@ -74,6 +74,8 @@ const alreadyMerged = (root, facts) => isAncestor(root, facts.head, facts.base);
74
74
  async function requestMerge(root, authority, facts, signal, saw, current, artifact, previous, holdFile, checkMain) {
75
75
  if (await alreadyMerged(root, facts))
76
76
  return mergeWaiting();
77
+ // Autopilot's ask names itself to the host with a secret; the record keeps only its hash.
78
+ const secret = holdFile ? randomBytes(32).toString('base64url') : undefined;
77
79
  const claim = {
78
80
  change: facts.change,
79
81
  head: facts.head,
@@ -82,14 +84,17 @@ async function requestMerge(root, authority, facts, signal, saw, current, artifa
82
84
  // The base this merge verified, not a fresh read: a host merge landing meanwhile must not become
83
85
  // the claim's main, or the wait could never be observed (currentMerge checks main again).
84
86
  main: facts.base,
85
- ...(holdFile && { automatic: true }),
87
+ ...(secret && {
88
+ automatic: true,
89
+ claimHash: createHash('sha256').update(secret).digest('hex'),
90
+ }),
86
91
  };
87
92
  if (holdFile && mergeHeld(holdFile))
88
93
  return heldMerge(facts.head);
89
94
  if (!updateRecord(root, ask(saw, claim)))
90
95
  return mergeWaiting();
91
96
  const { answer, withdrawn, publicationRefusal } = current()
92
- ? await askHost(authority, facts, signal, () => current() && artifact() && current() && !(holdFile && mergeHeld(holdFile)), holdFile ? { root, path: holdFile, claim } : undefined, current, checkMain)
97
+ ? await askHost(authority, facts, signal, () => current() && artifact() && current() && !(holdFile && mergeHeld(holdFile)), holdFile && secret ? { root, path: holdFile, claim, secret } : undefined, current, checkMain)
93
98
  : { answer: { status: 'not_merged', code: 'merge_artifact_changed' } };
94
99
  if (withdrawn && answer.status !== 'merged') {
95
100
  try {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The hold file's name, in a module with no imports: the turn permissions read it while the merge
3
+ * modules may still be loading (merge-hold imports merge-claims, which reaches back to chat).
4
+ */
5
+ export declare const mergeHoldName = "ape-autopilot-merge-hold";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The hold file's name, in a module with no imports: the turn permissions read it while the merge
3
+ * modules may still be loading (merge-hold imports merge-claims, which reaches back to chat).
4
+ */
5
+ export const mergeHoldName = 'ape-autopilot-merge-hold';
@@ -1,3 +1,4 @@
1
+ import { mergeHoldName } from './merge-hold-name.ts';
1
2
  export declare const heldMerge: (head?: string) => {
2
3
  ok: false;
3
4
  reason: 'held';
@@ -5,7 +6,7 @@ export declare const heldMerge: (head?: string) => {
5
6
  detail: string;
6
7
  head: string | undefined;
7
8
  };
8
- export declare const mergeHoldName = "ape-autopilot-merge-hold";
9
+ export { mergeHoldName };
9
10
  /** Both local and hosted Autopilot run the actual write inside this gate. */
10
11
  export declare function publishAutomatic<T>(path: string, head: string, current: () => boolean, write: () => Promise<T> | T): Promise<T | {
11
12
  ok: false;
@@ -28,6 +29,10 @@ export declare class MergePublicationLockError extends Error {
28
29
  }
29
30
  /** Order the switch write against an in-flight ref transaction, never against the merge checks. */
30
31
  export declare function mergePublication<T>(path: string, action: () => Promise<T> | T): Promise<T>;
32
+ /**
33
+ * Turning the hold on withdraws, under the same lock, the waiting Autopilot claims of every product
34
+ * root this process has seen for the file (a settle also refuses a hold written after its ask).
35
+ */
31
36
  export declare function writeMergeHold(path: string, held: boolean): Promise<void>;
32
37
  /** Release can come from another studio. Wait without holding the merge or turn reservation. */
33
38
  export declare function waitForMergeHold(root: string, signal: AbortSignal, blocked: () => boolean): Promise<boolean>;
@@ -1,13 +1,15 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { lstatSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
- import { dirname, join } from 'node:path';
3
+ import { dirname, join, resolve } from 'node:path';
4
4
  import { setTimeout } from 'node:timers/promises';
5
5
  import { t } from '../change-merge.en.js';
6
6
  import { lockText, mergeLockName, reclaimDeadLock } from '../change-merge-lock.js';
7
7
  import { hostGit, hostGitSync, localGitEnv } from '../safe-git.js';
8
8
  import { autoT } from './autopilot-person.js';
9
9
  import { mergeHeldCode, mergeMessage } from './merge-authority.js';
10
+ import { withdrawWaiting } from './merge-claims.js';
10
11
  import { mergeEvent } from './merge-events.js';
12
+ import { mergeHoldName } from './merge-hold-name.js';
11
13
  export const heldMerge = (head) => ({
12
14
  ok: false,
13
15
  reason: 'held',
@@ -15,7 +17,7 @@ export const heldMerge = (head) => ({
15
17
  detail: autoT('auto.mergeHeld'),
16
18
  head,
17
19
  });
18
- export const mergeHoldName = 'ape-autopilot-merge-hold';
20
+ export { mergeHoldName };
19
21
  /** Both local and hosted Autopilot run the actual write inside this gate. */
20
22
  export function publishAutomatic(path, head, current, write) {
21
23
  return mergePublication(path, () => {
@@ -26,6 +28,15 @@ export function publishAutomatic(path, head, current, write) {
26
28
  return write();
27
29
  });
28
30
  }
31
+ /** Each product root seen per hold file: turning the hold on withdraws their waiting claims. */
32
+ const holdRoots = new Map();
33
+ function known(root, common) {
34
+ const path = join(common, mergeHoldName);
35
+ const roots = holdRoots.get(resolve(path)) ?? new Set();
36
+ roots.add(resolve(root));
37
+ holdRoots.set(resolve(path), roots);
38
+ return path;
39
+ }
29
40
  export function mergeHoldPath(root) {
30
41
  try {
31
42
  const common = hostGitSync(root, ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
@@ -33,7 +44,7 @@ export function mergeHoldPath(root) {
33
44
  env: localGitEnv,
34
45
  }).trim();
35
46
  if (common)
36
- return join(common, mergeHoldName);
47
+ return known(root, common);
37
48
  }
38
49
  catch {
39
50
  // Git did not identify the repository. Its state cannot grant permission to merge.
@@ -47,7 +58,7 @@ export async function mergeHoldPathAsync(root) {
47
58
  env: localGitEnv,
48
59
  })).trim();
49
60
  if (common)
50
- return join(common, mergeHoldName);
61
+ return known(root, common);
51
62
  }
52
63
  catch {
53
64
  // Git did not identify the repository. Its state cannot grant permission to merge.
@@ -140,8 +151,12 @@ export async function mergePublication(path, action) {
140
151
  await releasePublication(lock, owner);
141
152
  }
142
153
  }
154
+ /**
155
+ * Turning the hold on withdraws, under the same lock, the waiting Autopilot claims of every product
156
+ * root this process has seen for the file (a settle also refuses a hold written after its ask).
157
+ */
143
158
  export async function writeMergeHold(path, held) {
144
- await mergePublication(path, () => {
159
+ await mergePublication(path, async () => {
145
160
  const temporary = `${path}.${randomUUID()}.tmp`;
146
161
  try {
147
162
  writeFileSync(temporary, held ? 'on\n' : 'off\n', { flag: 'wx', mode: 0o600 });
@@ -152,6 +167,9 @@ export async function writeMergeHold(path, held) {
152
167
  finally {
153
168
  rmSync(temporary, { force: true });
154
169
  }
170
+ if (held)
171
+ for (const root of holdRoots.get(resolve(path)) ?? [])
172
+ await withdrawWaiting(root).catch(() => 0);
155
173
  });
156
174
  }
157
175
  /** Release can come from another studio. Wait without holding the merge or turn reservation. */
@@ -6,6 +6,7 @@ export declare function askHost(authority: MergeContext, facts: MergeFacts, sign
6
6
  root: string;
7
7
  path: string;
8
8
  claim: PendingMerge;
9
+ secret: string;
9
10
  } | undefined, permitted?: () => boolean, checkMain?: MainPublicationCheck): Promise<{
10
11
  answer: import("./merge-authority.ts").HostMergeAnswer;
11
12
  withdrawn?: undefined;
@@ -6,7 +6,7 @@ import { closeRecord, rememberPublication, withdraw } from './merge-record.js';
6
6
  export async function askHost(authority, facts, signal, current, automatic, permitted = () => true, checkMain) {
7
7
  if (!automatic)
8
8
  return { answer: await callMerge(authority, facts, 'person', signal, current) };
9
- const { root, path, claim } = automatic;
9
+ const { root, path, claim, secret } = automatic;
10
10
  const hold = new AbortController();
11
11
  let waiting = true;
12
12
  let eligible = true;
@@ -56,7 +56,7 @@ export async function askHost(authority, facts, signal, current, automatic, perm
56
56
  const timer = setInterval(inspect, 50);
57
57
  try {
58
58
  const ends = signal ? AbortSignal.any([signal, hold.signal]) : hold.signal;
59
- const answer = await callMerge(authority, facts, publish, ends, current);
59
+ const answer = await callMerge(authority, facts, publish, ends, current, secret);
60
60
  inspect();
61
61
  eligible = answer.status === 'pending' && !publicationRefusal;
62
62
  return {
@@ -18,6 +18,8 @@ export declare const asksAgain: (pending: PendingMerge, timeout: number, now?: n
18
18
  * file holds now and returns undefined (no write) when they differ, so a stale caller does nothing.
19
19
  */
20
20
  export declare const ask: (saw: PendingMerge | undefined, claim: PendingMerge) => (record: StudioRecord) => StudioRecord | undefined;
21
+ /** A queued automatic result is observable only after its guarded write returned success. */
22
+ export declare const published: (claim: PendingMerge) => (record: StudioRecord) => StudioRecord | undefined;
21
23
  export declare const hostPublished: (claim: PendingMerge) => boolean;
22
24
  export declare function rememberPublication(root: string, claim: PendingMerge): Promise<void>;
23
25
  /** Ends the wait this claim started and keeps what became of it; never touches another head's. */
@@ -44,7 +44,7 @@ export const ask = (saw, claim) => (record) => same(record.pending.find((entry)
44
44
  }
45
45
  : undefined;
46
46
  /** A queued automatic result is observable only after its guarded write returned success. */
47
- const published = (claim) => (record) => record.pending.some((entry) => same(entry, claim))
47
+ export const published = (claim) => (record) => record.pending.some((entry) => same(entry, claim))
48
48
  ? {
49
49
  ...record,
50
50
  pending: record.pending.map((entry) => same(entry, claim) ? { ...entry, published: true } : entry),
@@ -2,15 +2,17 @@ import { z } from 'zod';
2
2
  import { t } from '../change-merge.en.js';
3
3
  import { defaultMergeTools, mergeMigrationClash, mergeOne, removeWorktree, } from '../change-merge.js';
4
4
  import { hostGit } from '../safe-git.js';
5
+ import { sweepAfterMerge } from '../worktree-sweep.js';
5
6
  import { hostMergeAuthority } from './approval-artifact.js';
6
7
  import { authorityFor, authorityMessage } from './approval-authority.js';
7
8
  import { catchUpOne } from './catch-up.js';
8
- import { mergeContext, mergeWaiting } from './merge-authority.js';
9
+ import { mergeContext, mergeT, mergeWaiting } from './merge-authority.js';
9
10
  import { delegatedTools, waitingMerge } from './merge-delegation.js';
10
11
  import { factsChanged } from './merge-events.js';
11
12
  import { MergePublicationLockError } from './merge-hold.js';
12
13
  import { mergePreviewRoutes } from './merge-preview-route.js';
13
14
  import { beginLocalMerge, endLocalMerge } from './merge-record.js';
15
+ import { withdrawMerge } from './merge-withdraw.js';
14
16
  import { checkAfterMerge } from './post-merge.js';
15
17
  import { identityEnv } from './save-git.js';
16
18
  import { mergeView } from './snapshot-view.js';
@@ -28,6 +30,21 @@ export function mergeRoutes(root) {
28
30
  return [
29
31
  personMergeRoute(root),
30
32
  ...mergePreviewRoutes(root),
33
+ {
34
+ // A person ends a wait the host never answered, so it cannot hold Autopilot for good.
35
+ method: 'POST',
36
+ path: '/api/merge/withdraw',
37
+ right: 'build',
38
+ handle: async ({ body }) => {
39
+ const parsed = mergeBody.safeParse(await body());
40
+ if (!parsed.success)
41
+ return { status: 400, body: { error: t('change.merge.invalid') } };
42
+ const done = await withdrawMerge(root, parsed.data.change).catch(() => false);
43
+ return done
44
+ ? { status: 200, body: { ok: true, detail: mergeT('ui.merge.withdrawn') } }
45
+ : { status: 409, body: { ok: false, detail: mergeT('ui.merge.notWithdrawn') } };
46
+ },
47
+ },
31
48
  {
32
49
  method: 'POST',
33
50
  path: '/api/worktree',
@@ -103,6 +120,8 @@ async function personMerge(root, change, { identity, hosted, approval, stop, sig
103
120
  const context = authorityFor({ identity, approval });
104
121
  const authority = context ? hostMergeAuthority(context) : undefined;
105
122
  const result = await checkAfterMerge(root, await mergeOne(root, change, tools, authority, level), undefined, ends, change);
123
+ if (result.ok)
124
+ sweepAfterMerge(root);
106
125
  return {
107
126
  status: result.ok ? 200 : result.status === 'pending' ? 202 : 409,
108
127
  body: !result.ok && authority?.code
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The host's later word on a queued Autopilot merge it answered `pending`. `claim` is the
3
+ * `HostMergeInput.claim` the host was given with that ask. The studio's record keeps only its
4
+ * SHA-256, so reading the record does not give it; it names that one ask, never another.
5
+ */
6
+ export type HostMergeSettlement = Readonly<{
7
+ change: string;
8
+ head: string;
9
+ claim: string;
10
+ /** `check` writes nothing: whether a `merged` settle would pass the gate now (main aside). */
11
+ outcome: 'merged' | 'not_merged' | 'check';
12
+ code?: string;
13
+ }>;
14
+ export type HostMergeSettled = {
15
+ status: 'merged' | 'not_merged' | 'ready';
16
+ } | {
17
+ status: 'refused';
18
+ code: string;
19
+ detail: string;
20
+ };
21
+ /**
22
+ * Settles one waiting Autopilot claim from the host's own process; no HTTP route reaches it. It
23
+ * runs under the same publication gate as `publish`: a held repository, a level other than
24
+ * Autopilot, an edit of `plan/agents.md` or of the hold since the ask (which also withdraws the
25
+ * claim), another change's or head's claim, a withdrawn claim, a moved branch, or (for `merged`)
26
+ * a main without the exact head refuses; a record that cannot be written answers
27
+ * `merge_record_failed`, and a publication lock that stays busy `merge_publication_lock`. A claim
28
+ * that has ended is withdrawn by any settle, so Autopilot asks again. A `merged` settlement records what `publish` records; the studio's next
29
+ * read records the merge and starts its Snapshot, exactly as for a published claim. `check`
30
+ * answers `ready` when a `merged` settle would pass the gate now, and writes nothing.
31
+ */
32
+ export declare function settleHostMerge(root: string, input: HostMergeSettlement): Promise<HostMergeSettled>;
@@ -0,0 +1,133 @@
1
+ import { createHash, timingSafeEqual } from 'node:crypto';
2
+ import { statSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { z } from 'zod';
5
+ import { effectiveLevel, mainAgentsRoot } from '../agents-file.js';
6
+ import { readRecord } from './autopilot-records.js';
7
+ import { fullSha, mergeHeldCode, mergeT, refusalCode, reservedCode } from './merge-authority.js';
8
+ import { changeHead } from './merge-delegation.js';
9
+ import { MergePublicationLockError, mergeHoldPath, mergePublication, publishAutomatic, } from './merge-hold.js';
10
+ import { mainHas } from './merge-observed.js';
11
+ import { closeRecord, published, settle, withdraw } from './merge-record.js';
12
+ const settlement = z.strictObject({
13
+ change: z.string().regex(/^C-\d{3,}$/),
14
+ head: fullSha,
15
+ claim: z.string().min(1).max(200),
16
+ outcome: z.enum(['merged', 'not_merged', 'check']),
17
+ code: refusalCode.optional(),
18
+ });
19
+ /** The claim matches the ask's hash, compared in constant time. */
20
+ const claimed = (pending, claim) => {
21
+ if (!pending.claimHash)
22
+ return false;
23
+ const given = createHash('sha256').update(claim).digest();
24
+ return timingSafeEqual(given, Buffer.from(pending.claimHash, 'hex'));
25
+ };
26
+ const modified = (file) => {
27
+ try {
28
+ return statSync(file).mtimeMs;
29
+ }
30
+ catch (error) {
31
+ if (error.code === 'ENOENT')
32
+ return 0;
33
+ return Number.POSITIVE_INFINITY;
34
+ }
35
+ };
36
+ /**
37
+ * Any edit of `plan/agents.md` or of the hold since the ask ends the claim: the level may have left
38
+ * Autopilot and come back, or a person held merges meanwhile (an ask is never made while held).
39
+ */
40
+ const ended = (root, path, askedAt) => {
41
+ const asked = Date.parse(askedAt);
42
+ let agents = Number.POSITIVE_INFINITY;
43
+ try {
44
+ agents = modified(join(mainAgentsRoot(root), 'plan/agents.md')) || agents;
45
+ }
46
+ catch {
47
+ // An unknown checkout ends the claim.
48
+ }
49
+ return agents > asked || modified(path) > asked;
50
+ };
51
+ const refused = (code) => ({
52
+ status: 'refused',
53
+ code,
54
+ detail: mergeT(code === mergeHeldCode ? 'ui.merge.settleHeld' : 'ui.merge.settleRefused', {
55
+ code,
56
+ }),
57
+ });
58
+ /**
59
+ * Settles one waiting Autopilot claim from the host's own process; no HTTP route reaches it. It
60
+ * runs under the same publication gate as `publish`: a held repository, a level other than
61
+ * Autopilot, an edit of `plan/agents.md` or of the hold since the ask (which also withdraws the
62
+ * claim), another change's or head's claim, a withdrawn claim, a moved branch, or (for `merged`)
63
+ * a main without the exact head refuses; a record that cannot be written answers
64
+ * `merge_record_failed`, and a publication lock that stays busy `merge_publication_lock`. A claim
65
+ * that has ended is withdrawn by any settle, so Autopilot asks again. A `merged` settlement records what `publish` records; the studio's next
66
+ * read records the merge and starts its Snapshot, exactly as for a published claim. `check`
67
+ * answers `ready` when a `merged` settle would pass the gate now, and writes nothing.
68
+ */
69
+ export async function settleHostMerge(root, input) {
70
+ const parsed = settlement.safeParse(input);
71
+ if (!parsed.success ||
72
+ (parsed.data.outcome === 'not_merged') !== Boolean(parsed.data.code) ||
73
+ (parsed.data.code !== undefined && reservedCode(parsed.data.code)))
74
+ return refused('merge_settle_invalid');
75
+ const { change, head, claim, outcome, code } = parsed.data;
76
+ const path = mergeHoldPath(root);
77
+ if (!path)
78
+ return refused('merge_settle_unknown');
79
+ const pending = readRecord(root)?.pending.find((entry) => entry.change === change);
80
+ if (!pending?.automatic || pending.head !== head || !claimed(pending, claim))
81
+ return refused('merge_settle_unknown');
82
+ if ((await changeHead(root, change).catch(() => undefined)) !== head)
83
+ return refused('merge_settle_unknown');
84
+ // Read again under the lock: the claim still on file and Autopilot unchanged since the ask.
85
+ const onFile = () => readRecord(root)?.pending.some((entry) => entry.revision === pending.revision && entry.head === head) === true;
86
+ const stale = () => onFile() && (effectiveLevel(root) !== 'auto' || ended(root, path, pending.askedAt));
87
+ const current = () => effectiveLevel(root) === 'auto' && !ended(root, path, pending.askedAt) && onFile();
88
+ // A claim Autopilot no longer stands behind ends here, whatever the host asked: the merge, if
89
+ // any, stays Git's alone, and Autopilot asks again after its next turn.
90
+ const endStale = () => mergePublication(path, async () => {
91
+ if (stale())
92
+ await closeRecord(root, withdraw(pending, undefined));
93
+ }).catch(() => undefined);
94
+ try {
95
+ if (outcome !== 'not_merged') {
96
+ const result = await publishAutomatic(path, head, current, async () => {
97
+ if (outcome === 'check')
98
+ return { status: 'ready' };
99
+ if (!(await mainHas(root, head)))
100
+ return refused('merge_not_observed');
101
+ const recorded = await closeRecord(root, published(pending)).catch(() => false);
102
+ return recorded ? { status: 'merged' } : refused('merge_record_failed');
103
+ });
104
+ if ('status' in result)
105
+ return result;
106
+ await endStale();
107
+ return refused('code' in result && result.code ? result.code : 'merge_settle_unknown');
108
+ }
109
+ const result = await mergePublication(path, async () => {
110
+ if (!current() || (await mainHas(root, head)))
111
+ return undefined;
112
+ const at = new Date().toISOString();
113
+ const done = await closeRecord(root, settle(pending, {
114
+ change,
115
+ head,
116
+ at,
117
+ kind: 'refused',
118
+ code: code ?? 'merge_settle_invalid',
119
+ })).catch(() => false);
120
+ return done ? { status: 'not_merged' } : refused('merge_record_failed');
121
+ });
122
+ if (result)
123
+ return result;
124
+ await endStale();
125
+ return refused('merge_settle_unknown');
126
+ }
127
+ catch (error) {
128
+ // The publication lock stayed busy: the host asks again later.
129
+ if (error instanceof MergePublicationLockError)
130
+ return refused('merge_publication_lock');
131
+ throw error;
132
+ }
133
+ }
@@ -2,6 +2,11 @@ import type { StudioState, WorkFacts } from '@buffcore/contracts/workbench';
2
2
  import { type StudioRecord } from './autopilot-records.ts';
3
3
  import type { UiRequest } from './routes.ts';
4
4
  type Merge = NonNullable<WorkFacts['merges']>[number];
5
+ /** How long a wait has lasted, in whole minutes under two hours and whole hours after. */
6
+ export declare const waited: (at: string, now?: number) => {
7
+ minutes: number;
8
+ hours: number;
9
+ };
5
10
  /**
6
11
  * What the host's merge of each change amounts to, from facts on disk only: nothing here is
7
12
  * stored, so a read that is slow or out of order cannot leave a stale copy behind. With the ask's
@@ -9,6 +9,11 @@ import { checkAfterMerge } from './post-merge.js';
9
9
  const language = () => /^es(?:[-_.]|$)/i.test(process.env.LC_ALL || process.env.LANG || '') ? 'es' : 'en';
10
10
  // The server's own language and zone, and the long time style names the zone.
11
11
  const shown = (at) => new Intl.DateTimeFormat(language(), { dateStyle: 'medium', timeStyle: 'long' }).format(new Date(at));
12
+ /** How long a wait has lasted, in whole minutes under two hours and whole hours after. */
13
+ export const waited = (at, now = Date.now()) => {
14
+ const minutes = Math.max(0, Math.floor((now - Date.parse(at)) / 60_000));
15
+ return { minutes, hours: minutes < 120 ? 0 : Math.floor(minutes / 60) };
16
+ };
12
17
  /**
13
18
  * Git's own "no" (a numeric exit code) is an answer; a Git that did not answer (a timeout, a
14
19
  * failed spawn) throws, so the read is unknown rather than a quiet change.
@@ -44,10 +49,11 @@ export async function mergeEntries(root, record, timeout, run = studioRun) {
44
49
  ...(!merged && timeout !== undefined && asksAgain(pending, timeout)
45
50
  ? { again: true }
46
51
  : {}),
52
+ ...(!merged && pending.automatic ? { automatic: true } : {}),
47
53
  at: pending.askedAt,
48
54
  detail: merged
49
55
  ? mergeT('ui.merge.observed', { head: pending.head.slice(0, 12) })
50
- : mergeT('ui.merge.since', { at: shown(pending.askedAt) }),
56
+ : mergeT('ui.merge.since', { at: shown(pending.askedAt), ...waited(pending.askedAt) }),
51
57
  });
52
58
  }
53
59
  for (const done of record.outcomes) {
@@ -0,0 +1,9 @@
1
+ /** A person held, stopped or left Autopilot: its waiting claims end, under the publication lock. */
2
+ export declare function withdrawAutopilotClaims(root: string, changes?: readonly string[]): Promise<number>;
3
+ /** After a level write: a level other than Autopilot withdraws Autopilot's waiting claims. */
4
+ export declare function afterLevel(root: string): Promise<void>;
5
+ /**
6
+ * A person ends a wait the host never answered: only an Autopilot claim (a person's own wait is
7
+ * unchanged), and never a head main already holds. The change can then be merged again.
8
+ */
9
+ export declare function withdrawMerge(root: string, change: string): Promise<boolean>;
@@ -0,0 +1,29 @@
1
+ import { effectiveLevel } from '../agents-file.js';
2
+ import { readRecord } from './autopilot-records.js';
3
+ import { withdrawWaiting } from './merge-claims.js';
4
+ import { mergeHoldPath, mergePublication } from './merge-hold.js';
5
+ /** A person held, stopped or left Autopilot: its waiting claims end, under the publication lock. */
6
+ export async function withdrawAutopilotClaims(root, changes) {
7
+ // The record first: it needs no git, and most saves have no Autopilot claim waiting.
8
+ if (!readRecord(root)?.pending.some((entry) => entry.automatic))
9
+ return 0;
10
+ const path = mergeHoldPath(root);
11
+ if (!path)
12
+ return 0;
13
+ return mergePublication(path, () => withdrawWaiting(root, changes));
14
+ }
15
+ /** After a level write: a level other than Autopilot withdraws Autopilot's waiting claims. */
16
+ export async function afterLevel(root) {
17
+ if (effectiveLevel(root) !== 'auto')
18
+ await withdrawAutopilotClaims(root).catch(() => 0);
19
+ }
20
+ /**
21
+ * A person ends a wait the host never answered: only an Autopilot claim (a person's own wait is
22
+ * unchanged), and never a head main already holds. The change can then be merged again.
23
+ */
24
+ export async function withdrawMerge(root, change) {
25
+ const path = mergeHoldPath(root);
26
+ if (!path)
27
+ return false;
28
+ return mergePublication(path, async () => (await withdrawWaiting(root, [change])) > 0);
29
+ }
@@ -50,6 +50,10 @@ export declare function plannedPlaceApproval(root: string, change: string): Prom
50
50
  fingerprint: string;
51
51
  role?: string | undefined;
52
52
  agent?: string | undefined;
53
+ ai?: {
54
+ model?: string | undefined;
55
+ reason: string;
56
+ } | undefined;
53
57
  }[];
54
58
  rule?: {
55
59
  kind: "one";
@@ -1,4 +1,4 @@
1
- import { readdir, readFile } from 'node:fs/promises';
1
+ import { readdir } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { approvalHolds, approvalSchema } from '@buffcore/contracts/approvals';
4
4
  import { readChange } from '../change-file.js';
@@ -11,12 +11,15 @@ import { planHistory } from './plan-history.js';
11
11
  import { parseJourneys } from './plan-journeys.js';
12
12
  import { readNotThis } from './plan-not.js';
13
13
  import { structureFacts } from './plan-structure.js';
14
+ import { readInside } from './real-file.js';
14
15
  import { stepFiles } from './save-ownership.js';
15
16
  export { answer, briefSection, parseBrief, plain, planSections, withoutComments, } from './plan-brief.js';
16
17
  export { parseJourneys } from './plan-journeys.js';
18
+ /** A plan file's text, only when it is a regular file whose real path stays in the product. */
17
19
  async function rawTextAt(root, file) {
18
20
  try {
19
- return await readFile(join(root, file), 'utf8');
21
+ const read = await readInside(join(root, file), [root]);
22
+ return read === undefined ? null : read.bytes.toString('utf8');
20
23
  }
21
24
  catch {
22
25
  return null;
@@ -1,4 +1,3 @@
1
- import { readFile } from 'node:fs/promises';
2
1
  import { join } from 'node:path';
3
2
  import { createI18n } from '@buffcore/i18n';
4
3
  import { readChanges } from '../change-file.js';
@@ -6,6 +5,7 @@ import { adminScreens, appScreens } from '../inventory-screens.js';
6
5
  import { SURFACE_FIELD, SURFACE_LINE } from '../prototype/comp.js';
7
6
  import { en } from './plan-structure.en.js';
8
7
  import { es } from './plan-structure.es.js';
8
+ import { readInside } from './real-file.js';
9
9
  /** `/billing (planned, C-020)`: a first screen a change adds, before its route exists. */
10
10
  const PLANNED = /^(.*\S) \(planned, (C-\d{3,})\)$/u;
11
11
  const messages = createI18n({ catalogs: [{ en, es }] });
@@ -162,13 +162,11 @@ export function parseStructure(text, screens, changes) {
162
162
  }
163
163
  /** Reuse the inventory's discovery; no product code is loaded and no navigation is inferred. */
164
164
  export async function readStructure(root) {
165
- const text = await readFile(join(root, 'plan/structure.md'), 'utf8').catch((error) => {
166
- if (error.code === 'ENOENT')
167
- return null;
168
- throw error;
169
- });
170
- if (text === null)
165
+ // Missing, or a link, hard link or junction leading out of the product: no structure to show.
166
+ const read = await readInside(join(root, 'plan/structure.md'), [root]);
167
+ if (!read)
171
168
  return null;
169
+ const text = read.bytes.toString('utf8');
172
170
  const [app, admin, planned] = await Promise.all([
173
171
  appScreens(root, root),
174
172
  adminScreens(root, root),
@@ -1,7 +1,16 @@
1
1
  import { type PrototypeCompReply } from '@buffcore/contracts/workbench';
2
+ import { type ApprovalContext } from './approval-authority.ts';
2
3
  import type { ImageType, UiRoute } from './routes.ts';
3
4
  export declare const pictureType: (file: string) => ImageType | undefined;
4
- export declare function compReply(root: string, hosted?: boolean): Promise<PrototypeCompReply>;
5
- /** The file a picture name stands for, or undefined: only the comp's own shots and the references. */
6
- export declare function compPicture(root: string, name: string, hosted?: boolean): Promise<string | undefined>;
5
+ export declare function compReply(root: string, hosted?: boolean, context?: ApprovalContext): Promise<PrototypeCompReply>;
6
+ /**
7
+ * The real file a picture name stands for, or undefined: only the comp's own shots and the
8
+ * references, and only a regular file whose real path (links followed) stays where it was listed:
9
+ * a shot inside the comp snapshot folder, a reference inside the product's folder unless the person's
10
+ * own studio lists it outside.
11
+ */
12
+ export declare function compPicture(root: string, name: string, hosted?: boolean): Promise<{
13
+ bytes: Buffer;
14
+ type: ImageType;
15
+ } | undefined>;
7
16
  export declare function prototypeCompRoutes(root: string): UiRoute[];