@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
@@ -1,6 +1,5 @@
1
1
  // The comp page's reads: the newest comp snapshot's screens, the references beside them and the
2
2
  // approval; and each picture by its name (never by a path from the request).
3
- import { readFile } from 'node:fs/promises';
4
3
  import { extname, join } from 'node:path';
5
4
  import { frameSizes } from '@buffcore/config';
6
5
  import { workbenchApi } from '@buffcore/contracts/workbench';
@@ -9,6 +8,9 @@ import { referencePictures } from '../design/references.js';
9
8
  import { compDir, firstSurface, newestComp } from '../prototype/comp.js';
10
9
  import { compApproved, readCompApproval } from '../prototype/comp-record.js';
11
10
  import { snapshotsDir } from '../prototype/report.js';
11
+ import { authorityFor } from './approval-authority.js';
12
+ import { hostedComp } from './comp-approval.js';
13
+ import { readInside } from './real-file.js';
12
14
  const MAX = 12;
13
15
  /** The picture types the page shows, by extension; any other file is never served. */
14
16
  const TYPES = {
@@ -43,12 +45,15 @@ async function desktopWidth(root) {
43
45
  async function shownReferences(root, hosted) {
44
46
  return (await referencePictures(root))
45
47
  .slice(0, MAX)
46
- .map(({ file, inside }) => file && (inside || !hosted) && pictureType(file) ? file : undefined);
48
+ .map(({ file, inside }) => file && (inside || !hosted) && pictureType(file) ? { file, inside } : undefined);
47
49
  }
48
- export async function compReply(root, hosted = false) {
50
+ export async function compReply(root, hosted = false, context) {
49
51
  const surface = firstSurface(root);
50
52
  const comp = newestComp(root);
51
53
  const record = readCompApproval(root);
54
+ const approval = context
55
+ ? await hostedComp(root, record, comp, context)
56
+ : { approved: compApproved(record, comp), approval: record?.approval ?? null };
52
57
  const references = await shownReferences(root, hosted);
53
58
  const screens = (comp?.report.scenes ?? []).slice(0, MAX).map((scene, index) => {
54
59
  const { light, dark } = screenShots(scene);
@@ -63,13 +68,17 @@ export async function compReply(root, hosted = false) {
63
68
  surface,
64
69
  width: surface === 'phone' ? frameSizes().phone.width : await desktopWidth(root),
65
70
  screens,
66
- references: references.map((file, index) => (file ? `reference-${index}` : null)),
71
+ references: references.map((shown, index) => (shown ? `reference-${index}` : null)),
67
72
  ...(comp ? { fingerprint: comp.fingerprint } : {}),
68
- approved: compApproved(record, comp),
69
- approval: record?.approval ?? null,
73
+ ...approval,
70
74
  };
71
75
  }
72
- /** The file a picture name stands for, or undefined: only the comp's own shots and the references. */
76
+ /**
77
+ * The real file a picture name stands for, or undefined: only the comp's own shots and the
78
+ * references, and only a regular file whose real path (links followed) stays where it was listed:
79
+ * a shot inside the comp snapshot folder, a reference inside the product's folder unless the person's
80
+ * own studio lists it outside.
81
+ */
73
82
  export async function compPicture(root, name, hosted = false) {
74
83
  const screen = /^screen-(\d{1,2})-(light|dark)$/.exec(name);
75
84
  if (screen) {
@@ -78,11 +87,19 @@ export async function compPicture(root, name, hosted = false) {
78
87
  return;
79
88
  const look = screenShots(scene)[screen[2]];
80
89
  const path = look ? scene.screenshots[look] : undefined;
81
- return path && SHOT.test(path) ? join(compDir(snapshotsDir(root)), path) : undefined;
90
+ const folder = compDir(snapshotsDir(root));
91
+ return path && SHOT.test(path) ? picture(join(folder, path), [root, folder]) : undefined;
82
92
  }
83
- const reference = /^reference-(\d{1,2})$/.exec(name);
84
- if (reference)
85
- return (await shownReferences(root, hosted))[Number(reference[1])];
93
+ const index = /^reference-(\d{1,2})$/.exec(name)?.[1];
94
+ const shown = index === undefined ? undefined : (await shownReferences(root, hosted))[+index];
95
+ if (shown)
96
+ return picture(shown.file, shown.inside ? [root] : []);
97
+ }
98
+ /** The bytes read from the opened file, typed by its real name; any other file is never served. */
99
+ async function picture(file, folders) {
100
+ const read = await readInside(file, folders);
101
+ const type = read && pictureType(read.real);
102
+ return read && type ? { bytes: read.bytes, type } : undefined;
86
103
  }
87
104
  export function prototypeCompRoutes(root) {
88
105
  return [
@@ -90,18 +107,19 @@ export function prototypeCompRoutes(root) {
90
107
  method: 'GET',
91
108
  path: workbenchApi.prototypeComp,
92
109
  right: 'read:runs',
93
- handle: async ({ hosted }) => ({ status: 200, body: await compReply(root, !!hosted) }),
110
+ handle: async ({ hosted, identity, approval }) => ({
111
+ status: 200,
112
+ body: await compReply(root, !!hosted, authorityFor({ identity, approval })),
113
+ }),
94
114
  },
95
115
  {
96
116
  method: 'GET',
97
117
  path: `${workbenchApi.prototypeComp}/picture/:name`,
98
118
  right: 'read:runs',
99
119
  handle: async ({ params, hosted }) => {
100
- const file = await compPicture(root, params.name ?? '', !!hosted);
101
- const type = file ? pictureType(file) : undefined;
102
- const bytes = file && type ? await readFile(file).catch(() => undefined) : undefined;
103
- return bytes && type
104
- ? { status: 200, body: bytes, type }
120
+ const shown = await compPicture(root, params.name ?? '', !!hosted);
121
+ return shown
122
+ ? { status: 200, body: shown.bytes, type: shown.type }
105
123
  : { status: 404, body: { error: 'missing' } };
106
124
  },
107
125
  },
@@ -91,6 +91,10 @@ export declare function planPrototypeOnMain(root: string, plan: PlanFacts | unde
91
91
  fingerprint: string;
92
92
  role?: string | undefined;
93
93
  agent?: string | undefined;
94
+ ai?: {
95
+ model?: string | undefined;
96
+ reason: string;
97
+ } | undefined;
94
98
  }[];
95
99
  rule?: {
96
100
  kind: "one";
@@ -0,0 +1,11 @@
1
+ export type InsideFile = {
2
+ bytes: Buffer;
3
+ real: string;
4
+ };
5
+ /**
6
+ * The bytes of `file` and its real path, or undefined. `afterOpen` is for tests only: it runs
7
+ * between the open and the checks, where a folder swap would happen.
8
+ */
9
+ export declare function readInside(file: string, folders: readonly string[], afterOpen?: () => void | Promise<void>): Promise<InsideFile | undefined>;
10
+ /** `readInside` for synchronous readers: the bytes, or undefined. */
11
+ export declare function readInsideSync(file: string, folders: readonly string[]): Buffer | undefined;
@@ -0,0 +1,84 @@
1
+ // Read a file a route may show: open it first, then prove the open handle is the regular file, with
2
+ // one link, whose real path (links and junctions followed) stays inside every given folder, and read
3
+ // the bytes from that handle (as app-icon.ts does). A link or junction leading out, a hard link, a
4
+ // folder, a missing file or a path swapped while it was checked gives undefined.
5
+ import { closeSync, existsSync, fstatSync, openSync, readFileSync, realpathSync, statSync, } from 'node:fs';
6
+ import { open, realpath, stat } from 'node:fs/promises';
7
+ import { isAbsolute, relative, sep } from 'node:path';
8
+ /** Linux names an open file's true path; elsewhere (Windows, macOS) Node has no such name. */
9
+ const FDS = '/proc/self/fd';
10
+ const byHandle = existsSync(FDS);
11
+ const within = (folder, file) => {
12
+ const from = relative(folder, file);
13
+ return !!from && !isAbsolute(from) && from !== '..' && !from.startsWith(`..${sep}`);
14
+ };
15
+ /** The handle is that path's file: same device and file id, a regular file with one link. */
16
+ const same = (handle, path) => handle.isFile() && handle.nlink === 1n && handle.dev === path.dev && handle.ino === path.ino;
17
+ /**
18
+ * The bytes of `file` and its real path, or undefined. `afterOpen` is for tests only: it runs
19
+ * between the open and the checks, where a folder swap would happen.
20
+ */
21
+ export async function readInside(file, folders, afterOpen) {
22
+ const handle = await open(file, 'r').catch(() => undefined);
23
+ if (!handle)
24
+ return;
25
+ try {
26
+ const opened = await handle.stat({ bigint: true });
27
+ await afterOpen?.();
28
+ const real = await realpath(file);
29
+ for (const folder of folders)
30
+ if (!within(await realpath(folder), real))
31
+ return;
32
+ const checked = await stat(real, { bigint: true });
33
+ // The real path again: a swap during the checks changes it or the file id.
34
+ if (!same(opened, checked) || (await realpath(file)) !== real)
35
+ return;
36
+ // Where the system names the open file itself, that name must be inside too: no race left.
37
+ if (byHandle) {
38
+ const held = await realpath(`${FDS}/${handle.fd}`);
39
+ for (const folder of folders)
40
+ if (!within(await realpath(folder), held))
41
+ return;
42
+ }
43
+ return { bytes: await handle.readFile(), real };
44
+ }
45
+ catch {
46
+ return;
47
+ }
48
+ finally {
49
+ await handle.close().catch(() => { });
50
+ }
51
+ }
52
+ /** `readInside` for synchronous readers: the bytes, or undefined. */
53
+ export function readInsideSync(file, folders) {
54
+ let fd;
55
+ try {
56
+ fd = openSync(file, 'r');
57
+ }
58
+ catch {
59
+ return;
60
+ }
61
+ try {
62
+ const opened = fstatSync(fd, { bigint: true });
63
+ const real = realpathSync.native(file);
64
+ for (const folder of folders)
65
+ if (!within(realpathSync.native(folder), real))
66
+ return;
67
+ const checked = statSync(real, { bigint: true });
68
+ if (!same(opened, checked) || realpathSync.native(file) !== real)
69
+ return;
70
+ if (byHandle) {
71
+ const held = realpathSync.native(`${FDS}/${fd}`);
72
+ for (const folder of folders)
73
+ if (!within(realpathSync.native(folder), held))
74
+ return;
75
+ }
76
+ return readFileSync(fd);
77
+ }
78
+ catch {
79
+ return;
80
+ }
81
+ finally {
82
+ closeSync(fd);
83
+ }
84
+ }
@@ -0,0 +1,117 @@
1
+ import { type SaveSource } from './host-save.ts';
2
+ import type { UiRoute } from './server.ts';
3
+ /** The terminal's and the studio's one write: who and when, in its own isolated commit. */
4
+ export declare function reopenAndSave(root: string, change: string, by: string, source?: SaveSource): Promise<{
5
+ change: string;
6
+ versions: {
7
+ version: number;
8
+ commit: string;
9
+ report: string;
10
+ data: string;
11
+ design: string;
12
+ why: string;
13
+ at: string;
14
+ }[];
15
+ approved?: {
16
+ version: number;
17
+ approval: {
18
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
19
+ signatures: {
20
+ by: string;
21
+ at: string;
22
+ commit: string;
23
+ fingerprint: string;
24
+ role?: string | undefined;
25
+ agent?: string | undefined;
26
+ ai?: {
27
+ model?: string | undefined;
28
+ reason: string;
29
+ } | undefined;
30
+ }[];
31
+ rule?: {
32
+ kind: "one";
33
+ of: string[];
34
+ } | {
35
+ kind: "two";
36
+ of: string[];
37
+ } | {
38
+ kind: "majority";
39
+ of: string[];
40
+ by: string;
41
+ } | undefined;
42
+ };
43
+ reopened?: {
44
+ by: string;
45
+ at: string;
46
+ } | undefined;
47
+ } | undefined;
48
+ pending?: {
49
+ version: number;
50
+ approval: {
51
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
52
+ signatures: {
53
+ by: string;
54
+ at: string;
55
+ commit: string;
56
+ fingerprint: string;
57
+ role?: string | undefined;
58
+ agent?: string | undefined;
59
+ ai?: {
60
+ model?: string | undefined;
61
+ reason: string;
62
+ } | undefined;
63
+ }[];
64
+ rule?: {
65
+ kind: "one";
66
+ of: string[];
67
+ } | {
68
+ kind: "two";
69
+ of: string[];
70
+ } | {
71
+ kind: "majority";
72
+ of: string[];
73
+ by: string;
74
+ } | undefined;
75
+ };
76
+ reopened?: {
77
+ by: string;
78
+ at: string;
79
+ } | undefined;
80
+ } | undefined;
81
+ superseded?: {
82
+ version: number;
83
+ approval: {
84
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
85
+ signatures: {
86
+ by: string;
87
+ at: string;
88
+ commit: string;
89
+ fingerprint: string;
90
+ role?: string | undefined;
91
+ agent?: string | undefined;
92
+ ai?: {
93
+ model?: string | undefined;
94
+ reason: string;
95
+ } | undefined;
96
+ }[];
97
+ rule?: {
98
+ kind: "one";
99
+ of: string[];
100
+ } | {
101
+ kind: "two";
102
+ of: string[];
103
+ } | {
104
+ kind: "majority";
105
+ of: string[];
106
+ by: string;
107
+ } | undefined;
108
+ };
109
+ reopened?: {
110
+ by: string;
111
+ at: string;
112
+ } | undefined;
113
+ }[] | undefined;
114
+ }>;
115
+ /** How long the host may take to answer a reopen, as `bounded()` allows an approval. */
116
+ export declare const REOPEN_HOST_MS = 5000;
117
+ export declare function reopenRoute(root: string): UiRoute;
@@ -0,0 +1,97 @@
1
+ // Reopen (S4): a person reopens an AI approval at any level, from the studio or with `ape prototype
2
+ // reopen`. Locally the record says who and when, saved in the same isolated commit as an approval.
3
+ // Behind a host, the host's approval hook decides (`action: 'reopen'`); one that cannot says so
4
+ // plainly. A person's approval is refused before anything is asked or written.
5
+ import { z } from 'zod';
6
+ import { ApprovalRefusal } from '../approval-rules.js';
7
+ import { t } from '../prototype/messages.js';
8
+ import { requireLegacyChange } from '../prototype/milestone-key.js';
9
+ import { reopenT } from '../prototype/reopen-messages.js';
10
+ import { readVersions, reopenVersion, VersionRefusal } from '../prototype/versions.js';
11
+ import { hostGit } from '../safe-git.js';
12
+ import { hostedVersions } from './approval-artifact.js';
13
+ import { authorityFor } from './approval-authority.js';
14
+ import { HostSaveRefusal } from './host-save.js';
15
+ import { savePrototypeApproval } from './save-route.js';
16
+ const reopenBody = z.strictObject({ change: z.string().regex(/^C-\d{3,}$/) });
17
+ /** The held AI approval (a host's grant behind a host), as its artifact, or the refusal. */
18
+ async function heldAi(root, change, context) {
19
+ requireLegacyChange(root, change);
20
+ const record = readVersions(root, change);
21
+ const held = context ? (await hostedVersions(root, record, context)).approved : record.approved;
22
+ const signature = held?.approval.signatures.find((s) => s.ai);
23
+ if (!held || !signature)
24
+ throw new VersionRefusal(reopenT('reopen.none', { change }));
25
+ return Object.freeze({
26
+ kind: 'prototype',
27
+ version: Object.freeze({ change, version: held.version }),
28
+ commit: signature.commit,
29
+ fingerprint: signature.fingerprint,
30
+ });
31
+ }
32
+ /** The terminal's and the studio's one write: who and when, in its own isolated commit. */
33
+ export async function reopenAndSave(root, change, by, source) {
34
+ await heldAi(root, change);
35
+ if (!by.trim())
36
+ throw new VersionRefusal(t('prototype.identity'));
37
+ const now = new Date();
38
+ return savePrototypeApproval(root, change, (write = true) => reopenVersion(root, change, by, now, write), by, undefined, source);
39
+ }
40
+ /** How long the host may take to answer a reopen, as `bounded()` allows an approval. */
41
+ export const REOPEN_HOST_MS = 5_000;
42
+ /** Ask the host to reopen, in one bounded call; a late or ignored answer is never used. */
43
+ async function hostedReopen(root, change, context) {
44
+ const artifact = await heldAi(root, change, context);
45
+ const controller = new AbortController();
46
+ let timer;
47
+ const cannot = { status: 200, body: { reopened: false, error: reopenT('reopen.host') } };
48
+ const late = new Promise((done) => {
49
+ timer = setTimeout(() => {
50
+ controller.abort();
51
+ done(undefined);
52
+ }, REOPEN_HOST_MS);
53
+ });
54
+ const call = Promise.resolve()
55
+ .then(() => context.approval({
56
+ viewer: context.viewer,
57
+ artifact,
58
+ action: 'reopen',
59
+ signal: controller.signal,
60
+ }))
61
+ .catch(() => undefined);
62
+ try {
63
+ const answer = await Promise.race([call, late]);
64
+ return answer?.allowed === true ? { status: 200, body: { reopened: true } } : cannot;
65
+ }
66
+ finally {
67
+ clearTimeout(timer);
68
+ controller.abort();
69
+ }
70
+ }
71
+ export function reopenRoute(root) {
72
+ return {
73
+ method: 'POST',
74
+ path: '/api/prototype/reopen',
75
+ right: 'approve:prototype',
76
+ handle: async (source) => {
77
+ const { body, identity, hosted, approval } = source;
78
+ const { change } = reopenBody.parse(await body());
79
+ try {
80
+ const context = authorityFor({ identity, approval });
81
+ if (context)
82
+ return await hostedReopen(root, change, context);
83
+ const by = hosted
84
+ ? (identity?.viewer.email ?? identity?.viewer.name ?? '')
85
+ : (await hostGit(root, ['config', 'user.email']).catch(() => '')).trim();
86
+ return { status: 200, body: await reopenAndSave(root, change, by, source) };
87
+ }
88
+ catch (error) {
89
+ if (error instanceof HostSaveRefusal)
90
+ return { status: 409, body: error.result() };
91
+ if (error instanceof VersionRefusal || error instanceof ApprovalRefusal)
92
+ return { status: 409, body: { error: error.message } };
93
+ throw error;
94
+ }
95
+ },
96
+ };
97
+ }
@@ -21,3 +21,5 @@ export declare function savePrototypeApproval<T>(root: string, change: string, a
21
21
  /** The same isolated commit for a person's prototype or places approval. */
22
22
  export declare function saveApprovalRecord<T>(root: string, file: `prototype/versions/${string}.json` | 'plan/places.json', approve: (write?: boolean, committed?: string) => T | Promise<T>, by: string, agent?: string, source?: SaveSource, beforePublish?: () => unknown): Promise<T>;
23
23
  export declare function saveRoute(root: string): UiRoute;
24
+ /** The files a save's preview names, when it names them. */
25
+ export declare function saveFiles(value: unknown): value is string[];
@@ -9,6 +9,7 @@ import { autoProtection } from './autopilot-protection.js';
9
9
  import { requestRefusal } from './host.js';
10
10
  import { HostSaveRefusal } from './host-save.js';
11
11
  import { factsChanged, mergeEvent } from './merge-events.js';
12
+ import { afterLevel } from './merge-withdraw.js';
12
13
  import { reviewedStep, saveBody } from './save-body.js';
13
14
  import { saveBuildCompletion } from './save-build-completion.js';
14
15
  import { saveChangeStep } from './save-change-step.js';
@@ -102,8 +103,10 @@ export async function studioSave(root, body, viewer, automatic, options = {}) {
102
103
  factsChanged('levels');
103
104
  // Automatic saves already wake parked work when their turn finishes.
104
105
  if (!automatic && result.ok) {
105
- if (body.step === 'level' && effectiveLevel(root) !== 'auto')
106
+ if (body.step === 'level' && effectiveLevel(root) !== 'auto') {
106
107
  mergeEvent('level', root);
108
+ await afterLevel(root);
109
+ }
107
110
  mergeEvent('save', root);
108
111
  }
109
112
  return result;
@@ -206,3 +209,7 @@ export function saveRoute(root) {
206
209
  };
207
210
  return route;
208
211
  }
212
+ /** The files a save's preview names, when it names them. */
213
+ export function saveFiles(value) {
214
+ return Array.isArray(value) && value.every((file) => typeof file === 'string');
215
+ }
@@ -21,6 +21,7 @@ export { ChatEngine, type ChatEngineOptions } from './chat/turn.ts';
21
21
  export type { HostLevel, SignIn, UiIdentity } from './host.ts';
22
22
  export type { HostSave, HostSaveAnswer, HostSaveInput } from './host-save.ts';
23
23
  export type { HostMerge, HostMergeAnswer, HostMergeInput } from './merge-authority.ts';
24
+ export { type HostMergeSettled, type HostMergeSettlement, settleHostMerge, } from './merge-settle.ts';
24
25
  export type { AnswerResult, HostOutside, HostOutsideReadInput } from './outside.ts';
25
26
  export { pageScript } from './page.ts';
26
27
  export { readProductPlan } from './product-plan.ts';
@@ -21,6 +21,7 @@ export { FreshLooks } from './chat/fresh.js';
21
21
  export { freshRoutes } from './chat/fresh-routes.js';
22
22
  export { chatRoutes } from './chat/routes.js';
23
23
  export { ChatEngine } from './chat/turn.js';
24
+ export { settleHostMerge, } from './merge-settle.js';
24
25
  export { pageScript } from './page.js';
25
26
  export { readProductPlan } from './product-plan.js';
26
27
  export { Runner } from './runner.js';
@@ -15,6 +15,7 @@ import { outsideRoute } from './outside-route.js';
15
15
  import { prototypeCompRoutes } from './prototype-comp-route.js';
16
16
  import { planPrototypeOnMain } from './prototype-main.js';
17
17
  import { prototypeScenesRoute } from './prototype-scenes-route.js';
18
+ import { reopenRoute } from './reopen-route.js';
18
19
  import { saveRoute } from './save-route.js';
19
20
  import { structureSurfaceRoute } from './structure-surface.js';
20
21
  import { Latest } from './studio-facts.js';
@@ -83,6 +84,7 @@ cached = false) {
83
84
  ...mergeRoutes(root),
84
85
  saveRoute(root),
85
86
  brandApprovalRoute(root),
87
+ reopenRoute(root),
86
88
  agentsRoute(root),
87
89
  agentCheckRoute(root),
88
90
  prototypeScenesRoute(root),
@@ -99,6 +99,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
99
99
  fingerprint: string;
100
100
  role?: string | undefined;
101
101
  agent?: string | undefined;
102
+ ai?: {
103
+ model?: string | undefined;
104
+ reason: string;
105
+ } | undefined;
102
106
  }[];
103
107
  rule?: {
104
108
  kind: "one";
@@ -112,6 +116,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
112
116
  by: string;
113
117
  } | undefined;
114
118
  };
119
+ reopened?: {
120
+ by: string;
121
+ at: string;
122
+ } | undefined;
115
123
  } | undefined;
116
124
  pending?: {
117
125
  version: number;
@@ -124,6 +132,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
124
132
  fingerprint: string;
125
133
  role?: string | undefined;
126
134
  agent?: string | undefined;
135
+ ai?: {
136
+ model?: string | undefined;
137
+ reason: string;
138
+ } | undefined;
127
139
  }[];
128
140
  rule?: {
129
141
  kind: "one";
@@ -137,6 +149,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
137
149
  by: string;
138
150
  } | undefined;
139
151
  };
152
+ reopened?: {
153
+ by: string;
154
+ at: string;
155
+ } | undefined;
140
156
  } | undefined;
141
157
  superseded?: {
142
158
  version: number;
@@ -149,6 +165,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
149
165
  fingerprint: string;
150
166
  role?: string | undefined;
151
167
  agent?: string | undefined;
168
+ ai?: {
169
+ model?: string | undefined;
170
+ reason: string;
171
+ } | undefined;
152
172
  }[];
153
173
  rule?: {
154
174
  kind: "one";
@@ -162,6 +182,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
162
182
  by: string;
163
183
  } | undefined;
164
184
  };
185
+ reopened?: {
186
+ by: string;
187
+ at: string;
188
+ } | undefined;
165
189
  }[] | undefined;
166
190
  approvalRefusal?: string | undefined;
167
191
  milestone?: string | undefined;
@@ -256,6 +280,10 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
256
280
  fingerprint: string;
257
281
  role?: string | undefined;
258
282
  agent?: string | undefined;
283
+ ai?: {
284
+ model?: string | undefined;
285
+ reason: string;
286
+ } | undefined;
259
287
  }[];
260
288
  rule?: {
261
289
  kind: "one";
@@ -301,7 +329,12 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
301
329
  merge: "clean" | "conflict" | "merged" | "unknown";
302
330
  dirty: number;
303
331
  revision?: string | undefined;
332
+ kept?: "inUse" | "unknown" | undefined;
304
333
  }[];
334
+ others?: {
335
+ path: string;
336
+ branch?: string | undefined;
337
+ }[] | undefined;
305
338
  clashes: {
306
339
  a: string;
307
340
  b: string;
@@ -318,6 +351,7 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
318
351
  head: string;
319
352
  kind: "merged" | "refused" | "waiting";
320
353
  again?: true | undefined;
354
+ automatic?: true | undefined;
321
355
  at: string;
322
356
  detail: string;
323
357
  }[] | undefined;
@@ -22,6 +22,10 @@ export declare function authorityVersion(root: string, change: string): {
22
22
  fingerprint: string;
23
23
  role?: string | undefined;
24
24
  agent?: string | undefined;
25
+ ai?: {
26
+ model?: string | undefined;
27
+ reason: string;
28
+ } | undefined;
25
29
  }[];
26
30
  rule?: {
27
31
  kind: "one";
@@ -35,6 +39,10 @@ export declare function authorityVersion(root: string, change: string): {
35
39
  by: string;
36
40
  } | undefined;
37
41
  };
42
+ reopened?: {
43
+ by: string;
44
+ at: string;
45
+ } | undefined;
38
46
  } | undefined;
39
47
  pending?: {
40
48
  version: number;
@@ -47,6 +55,10 @@ export declare function authorityVersion(root: string, change: string): {
47
55
  fingerprint: string;
48
56
  role?: string | undefined;
49
57
  agent?: string | undefined;
58
+ ai?: {
59
+ model?: string | undefined;
60
+ reason: string;
61
+ } | undefined;
50
62
  }[];
51
63
  rule?: {
52
64
  kind: "one";
@@ -60,6 +72,10 @@ export declare function authorityVersion(root: string, change: string): {
60
72
  by: string;
61
73
  } | undefined;
62
74
  };
75
+ reopened?: {
76
+ by: string;
77
+ at: string;
78
+ } | undefined;
63
79
  } | undefined;
64
80
  superseded?: {
65
81
  version: number;
@@ -72,6 +88,10 @@ export declare function authorityVersion(root: string, change: string): {
72
88
  fingerprint: string;
73
89
  role?: string | undefined;
74
90
  agent?: string | undefined;
91
+ ai?: {
92
+ model?: string | undefined;
93
+ reason: string;
94
+ } | undefined;
75
95
  }[];
76
96
  rule?: {
77
97
  kind: "one";
@@ -85,6 +105,10 @@ export declare function authorityVersion(root: string, change: string): {
85
105
  by: string;
86
106
  } | undefined;
87
107
  };
108
+ reopened?: {
109
+ by: string;
110
+ at: string;
111
+ } | undefined;
88
112
  }[] | undefined;
89
113
  };
90
114
  /** A refused row is display data, never an approval and never a failed whole-Studio response. */