@buffcore/cli 0.8.45 → 0.8.47

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 (199) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/commands/change-merge-remove.d.ts +9 -2
  3. package/dist/commands/change-merge-remove.js +27 -15
  4. package/dist/commands/design/check.d.ts +1 -1
  5. package/dist/commands/design/check.js +2 -1
  6. package/dist/commands/design/contract-size.d.ts +7 -0
  7. package/dist/commands/design/contract-size.js +47 -0
  8. package/dist/commands/design/tells.en.d.ts +2 -0
  9. package/dist/commands/design/tells.en.js +2 -0
  10. package/dist/commands/design/tells.es.js +2 -0
  11. package/dist/commands/extension/places-approval.d.ts +4 -0
  12. package/dist/commands/process-paths.d.ts +14 -0
  13. package/dist/commands/process-paths.js +90 -0
  14. package/dist/commands/prototype/ai-approval.d.ts +27 -0
  15. package/dist/commands/prototype/ai-approval.js +60 -0
  16. package/dist/commands/prototype/approver.d.ts +71 -0
  17. package/dist/commands/prototype/approver.js +168 -0
  18. package/dist/commands/prototype/browser.d.ts +4 -24
  19. package/dist/commands/prototype/browser.js +13 -76
  20. package/dist/commands/prototype/critique-gate.d.ts +14 -0
  21. package/dist/commands/prototype/critique-gate.js +48 -0
  22. package/dist/commands/prototype/fence.d.ts +1 -0
  23. package/dist/commands/prototype/fence.js +12 -0
  24. package/dist/commands/prototype/final-approval-grant.js +18 -0
  25. package/dist/commands/prototype/final-approval.js +4 -1
  26. package/dist/commands/prototype/index.js +3 -0
  27. package/dist/commands/prototype/layout-hints.d.ts +34 -0
  28. package/dist/commands/prototype/layout-hints.js +194 -0
  29. package/dist/commands/prototype/layout-measure.d.ts +39 -0
  30. package/dist/commands/prototype/layout-measure.js +97 -0
  31. package/dist/commands/prototype/layout-words.d.ts +2 -0
  32. package/dist/commands/prototype/layout-words.js +11 -0
  33. package/dist/commands/prototype/layout.en.d.ts +6 -0
  34. package/dist/commands/prototype/layout.en.js +7 -0
  35. package/dist/commands/prototype/load-location.js +2 -3
  36. package/dist/commands/prototype/loaded-garbage.d.ts +10 -0
  37. package/dist/commands/prototype/loaded-garbage.js +20 -0
  38. package/dist/commands/prototype/media-ready.d.ts +9 -3
  39. package/dist/commands/prototype/media-ready.js +9 -4
  40. package/dist/commands/prototype/messages.en.d.ts +15 -0
  41. package/dist/commands/prototype/messages.en.js +15 -0
  42. package/dist/commands/prototype/messages.js +15 -0
  43. package/dist/commands/prototype/milestone-versions.d.ts +4 -0
  44. package/dist/commands/prototype/prune-command.d.ts +5 -0
  45. package/dist/commands/prototype/prune-command.js +25 -0
  46. package/dist/commands/prototype/prune-words.d.ts +1 -0
  47. package/dist/commands/prototype/prune-words.js +7 -0
  48. package/dist/commands/prototype/prune.d.ts +16 -0
  49. package/dist/commands/prototype/prune.en.d.ts +9 -0
  50. package/dist/commands/prototype/prune.en.js +9 -0
  51. package/dist/commands/prototype/prune.es.d.ts +2 -0
  52. package/dist/commands/prototype/prune.es.js +9 -0
  53. package/dist/commands/prototype/prune.js +140 -0
  54. package/dist/commands/prototype/reopen-messages.d.ts +9 -0
  55. package/dist/commands/prototype/reopen-messages.js +19 -0
  56. package/dist/commands/prototype/report.d.ts +14 -0
  57. package/dist/commands/prototype/report.js +5 -1
  58. package/dist/commands/prototype/scene-check.d.ts +37 -0
  59. package/dist/commands/prototype/scene-check.js +68 -0
  60. package/dist/commands/prototype/scene-layout.d.ts +17 -0
  61. package/dist/commands/prototype/scene-layout.js +57 -0
  62. package/dist/commands/prototype/scene-look.d.ts +14 -0
  63. package/dist/commands/prototype/scene-look.js +89 -0
  64. package/dist/commands/prototype/scene-ready.d.ts +46 -0
  65. package/dist/commands/prototype/scene-ready.js +122 -0
  66. package/dist/commands/prototype/scene.d.ts +37 -3
  67. package/dist/commands/prototype/scene.js +103 -36
  68. package/dist/commands/prototype/selector-answer.d.ts +43 -0
  69. package/dist/commands/prototype/selector-answer.js +73 -0
  70. package/dist/commands/prototype/selector-misses.d.ts +19 -0
  71. package/dist/commands/prototype/selector-misses.js +78 -0
  72. package/dist/commands/prototype/selector-prompt.d.ts +23 -0
  73. package/dist/commands/prototype/selector-prompt.js +32 -0
  74. package/dist/commands/prototype/selector-run.d.ts +13 -0
  75. package/dist/commands/prototype/selector-run.js +113 -0
  76. package/dist/commands/prototype/selector.d.ts +54 -0
  77. package/dist/commands/prototype/selector.js +96 -0
  78. package/dist/commands/prototype/snapshot-ancestor.js +2 -0
  79. package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
  80. package/dist/commands/prototype/snapshot-bundle.js +69 -7
  81. package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
  82. package/dist/commands/prototype/snapshot-check-files.js +41 -0
  83. package/dist/commands/prototype/snapshot-command.d.ts +2 -0
  84. package/dist/commands/prototype/snapshot-command.js +23 -10
  85. package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
  86. package/dist/commands/prototype/snapshot-completion.js +30 -2
  87. package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
  88. package/dist/commands/prototype/snapshot-dependencies.js +120 -14
  89. package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
  90. package/dist/commands/prototype/snapshot-hashes.js +28 -0
  91. package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
  92. package/dist/commands/prototype/snapshot-inputs.js +140 -190
  93. package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
  94. package/dist/commands/prototype/snapshot-matrix.js +95 -0
  95. package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
  96. package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
  97. package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
  98. package/dist/commands/prototype/snapshot-owners.js +12 -3
  99. package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
  100. package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
  101. package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
  102. package/dist/commands/prototype/snapshot-progress.js +54 -102
  103. package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
  104. package/dist/commands/prototype/snapshot-registry.js +121 -0
  105. package/dist/commands/prototype/snapshot-report.d.ts +4 -0
  106. package/dist/commands/prototype/snapshot-report.js +77 -12
  107. package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
  108. package/dist/commands/prototype/snapshot-requests.js +68 -30
  109. package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
  110. package/dist/commands/prototype/snapshot-reuse.js +17 -7
  111. package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
  112. package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
  113. package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
  114. package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
  115. package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
  116. package/dist/commands/prototype/snapshot-server-record.js +135 -0
  117. package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
  118. package/dist/commands/prototype/snapshot-servers.js +54 -4
  119. package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
  120. package/dist/commands/prototype/snapshot-setup.js +2 -1
  121. package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
  122. package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
  123. package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
  124. package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
  125. package/dist/commands/prototype/snapshot.d.ts +6 -0
  126. package/dist/commands/prototype/snapshot.js +73 -10
  127. package/dist/commands/prototype/version-commands.d.ts +4 -0
  128. package/dist/commands/prototype/version-commands.js +36 -8
  129. package/dist/commands/prototype/versions.d.ts +28 -2
  130. package/dist/commands/prototype/versions.js +25 -1
  131. package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
  132. package/dist/commands/prototype/vite-fs-path.js +15 -0
  133. package/dist/commands/remove-links.d.ts +6 -0
  134. package/dist/commands/remove-links.js +17 -0
  135. package/dist/commands/size-docs.d.ts +9 -0
  136. package/dist/commands/size-docs.en.d.ts +6 -0
  137. package/dist/commands/size-docs.en.js +6 -0
  138. package/dist/commands/size-docs.es.d.ts +2 -0
  139. package/dist/commands/size-docs.es.js +6 -0
  140. package/dist/commands/size-docs.js +28 -0
  141. package/dist/commands/size.d.ts +5 -2
  142. package/dist/commands/size.js +27 -9
  143. package/dist/commands/ui/approval-authority.d.ts +10 -2
  144. package/dist/commands/ui/approval-authority.js +1 -0
  145. package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
  146. package/dist/commands/ui/autopilot-ai-approve.js +68 -0
  147. package/dist/commands/ui/autopilot-loop.js +5 -6
  148. package/dist/commands/ui/autopilot-merge.js +3 -0
  149. package/dist/commands/ui/autopilot.en.d.ts +23 -0
  150. package/dist/commands/ui/autopilot.en.js +23 -0
  151. package/dist/commands/ui/autopilot.es.d.ts +23 -0
  152. package/dist/commands/ui/autopilot.es.js +23 -0
  153. package/dist/commands/ui/chat/find.d.ts +2 -0
  154. package/dist/commands/ui/chat/find.js +13 -0
  155. package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
  156. package/dist/commands/ui/chat/fresh-codex.js +175 -0
  157. package/dist/commands/ui/chat/fresh-critique.js +13 -5
  158. package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
  159. package/dist/commands/ui/chat/fresh-launch.js +67 -11
  160. package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
  161. package/dist/commands/ui/chat/fresh-prompts.js +2 -0
  162. package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
  163. package/dist/commands/ui/chat/fresh-secrets.js +172 -0
  164. package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
  165. package/dist/commands/ui/chat/fresh.en.js +2 -1
  166. package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
  167. package/dist/commands/ui/chat/fresh.es.js +2 -1
  168. package/dist/commands/ui/chat/worktree.js +25 -5
  169. package/dist/commands/ui/index.js +3 -0
  170. package/dist/commands/ui/loop-approve.d.ts +30 -1
  171. package/dist/commands/ui/loop-approve.js +2 -2
  172. package/dist/commands/ui/merge-route.js +3 -0
  173. package/dist/commands/ui/places-change.d.ts +4 -0
  174. package/dist/commands/ui/prototype-main.d.ts +4 -0
  175. package/dist/commands/ui/reopen-route.d.ts +117 -0
  176. package/dist/commands/ui/reopen-route.js +97 -0
  177. package/dist/commands/ui/save-route.d.ts +2 -0
  178. package/dist/commands/ui/save-route.js +4 -0
  179. package/dist/commands/ui/studio-routes.js +2 -0
  180. package/dist/commands/ui/studio-state.d.ts +33 -0
  181. package/dist/commands/ui/studio-versions.d.ts +24 -0
  182. package/dist/commands/ui/worktrees.d.ts +1 -1
  183. package/dist/commands/ui/worktrees.js +19 -3
  184. package/dist/commands/worktree-sweep.d.ts +45 -0
  185. package/dist/commands/worktree-sweep.js +188 -0
  186. package/dist/commands/worktrees-command.d.ts +32 -0
  187. package/dist/commands/worktrees-command.en.d.ts +25 -0
  188. package/dist/commands/worktrees-command.en.js +55 -0
  189. package/dist/commands/worktrees-command.js +96 -0
  190. package/dist/main.js +2 -0
  191. package/dist/ui/page.js +82 -82
  192. package/docs/PROTOTYPE.md +6 -3
  193. package/docs/WORKBENCH.md +11 -6
  194. package/package.json +11 -11
  195. package/skills/ape-critique/SKILL.md +41 -6
  196. package/skills/ape-design-system/SKILL.md +3 -0
  197. package/skills/ape-plan-change/SKILL.md +6 -0
  198. package/skills/ape-prototype/SKILL.md +8 -4
  199. package/templates/product/apps/app/app.json +3 -0
@@ -1,7 +1,8 @@
1
1
  export const es = {
2
- 'fresh.review': 'Eres un revisor nuevo, no el agente que escribió este paso. Sigue AGENTS.md. Solo lectura: no cambies ningún archivo ni ejecutes ningún comando. El paso: {step}. Sus archivos: {files}. Los archivos de los pasos anteriores: {earlier}. Léelos y revisa el paso frente al resumen, los pasos anteriores y las reglas del producto en AGENTS.md: qué falta, qué contradice un paso anterior, qué rompe una regla. Responde solo con un objeto JSON, sin nada antes ni después, con esta forma:',
2
+ 'fresh.review': 'Eres un revisor nuevo, no el agente que escribió este paso. Sigue AGENTS.md. Solo lectura: no cambies ningún archivo ni ejecutes ningún comando. El paso: {step}. Sus archivos: {files}. Los archivos de los pasos anteriores: {earlier}. Lee los archivos del paso; de los archivos de los pasos anteriores, lista primero los encabezados de cada uno (las líneas que empiezan por «## ») y lee solo las secciones de las que depende este paso. Después revisa el paso frente al resumen, los pasos anteriores y las reglas del producto en AGENTS.md: qué falta, qué contradice un paso anterior, qué rompe una regla. Responde solo con un objeto JSON, sin nada antes ni después, con esta forma:',
3
3
  'fresh.reviewLimit': 'Como mucho siete hallazgos, cada uno una frase sencilla sobre la que la persona pueda actuar; una lista vacía cuando el paso se sostiene.',
4
4
  'fresh.example': 'Una frase sobre la que la persona pueda actuar.',
5
+ 'fresh.secret': 'La respuesta del turno nuevo citaba un valor de {file}, así que el estudio la descartó.',
5
6
  'fresh.none': 'ninguno aún',
6
7
  'fresh.critique': 'Sigue AGENTS.md y la habilidad ape-critique: lee primero .claude/skills/ape-critique/SKILL.md, porque este turno no carga habilidades por sí solo. Eres el agente nuevo que pide: no dibujaste estas escenas, así que lee el repositorio y la captura completa que pasó ({report}), no el relato de nadie sobre ellas. Solo lectura: no cambies ningún archivo; puedes ejecutar exactamente `pnpm ape design check` y `pnpm ape i18n check`. En este turno nuevo del estudio no escribes design/critique.md: responde con el Markdown completo del informe con la forma de la habilidad (desde “# Critique” con Scores, las siete dimensiones, Keep, Fix y Quick wins) y nada más, y el estudio escribe el archivo.',
7
8
  };
@@ -1,5 +1,6 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { existsSync } from 'node:fs';
2
- import { mkdir, readdir } from 'node:fs/promises';
3
+ import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
3
4
  import { join, resolve } from 'node:path';
4
5
  import { prototypeVersionsSchema } from '@buffcore/contracts/approvals';
5
6
  import { MilestoneVersionsPending, requireLegacyChangeAt } from '../../prototype/milestone-key.js';
@@ -13,13 +14,32 @@ const CHANGE = /^C-\d{3,}$/;
13
14
  /** Creating a change's worktree runs none of its branch's hooks (a `post-checkout`, say). */
14
15
  const git = async (root, args, maxBuffer = 1024 * 1024) => (await hostGit(root, args, { maxBuffer })).trim();
15
16
  /**
16
- * A product's worktree (it has a lockfile) without its packages gets them. pnpm writes
17
- * node_modules/.modules.yaml only when an install finishes, so a failed one is tried again.
17
+ * A product's worktree (it has a lockfile) gets its packages when it has none, or when its
18
+ * lockfile or workspace file changed since its last install (a catch-up merged main's, say). pnpm
19
+ * writes node_modules/.modules.yaml only when an install finishes, so a failed one is tried again;
20
+ * ape then writes the hash of what it installed from in node_modules/.ape-lockfile.
18
21
  */
19
22
  async function installed(path, install) {
23
+ if (!existsSync(join(path, 'pnpm-lock.yaml')))
24
+ return;
20
25
  const done = join(path, 'node_modules', '.modules.yaml');
21
- if (existsSync(join(path, 'pnpm-lock.yaml')) && !existsSync(done))
22
- await install(path);
26
+ const stamp = join(path, 'node_modules', '.ape-lockfile');
27
+ const want = await lockHash(path);
28
+ const had = await readFile(stamp, 'utf8').catch(() => undefined);
29
+ if (existsSync(done) && had === want)
30
+ return;
31
+ await install(path);
32
+ // Written as a new file, never through a link left in its place; a failed write only means the
33
+ // next turn installs again.
34
+ await rm(stamp, { force: true })
35
+ .then(() => writeFile(stamp, want, { flag: 'wx' }))
36
+ .catch(() => { });
37
+ }
38
+ async function lockHash(path) {
39
+ const hash = createHash('sha256');
40
+ for (const name of ['pnpm-lock.yaml', 'pnpm-workspace.yaml'])
41
+ hash.update(name).update(await readFile(join(path, name)).catch(() => Buffer.alloc(0)));
42
+ return hash.digest('hex');
23
43
  }
24
44
  /**
25
45
  * The one rule for what writes in a change's worktree: coding, tests and fixes. Planning, design
@@ -5,6 +5,7 @@ import { spawn } from 'node:child_process';
5
5
  import { createI18n } from '@buffcore/i18n';
6
6
  import { InvalidArgumentError } from 'commander';
7
7
  import { findRoot, loadEnv, loadProduct } from '../../project.js';
8
+ import { startSweeps } from '../worktree-sweep.js';
8
9
  import { FreshLooks } from './chat/fresh.js';
9
10
  import { freshRoutes } from './chat/fresh-routes.js';
10
11
  import { hostLaunchedEnv } from './chat/host-launched.js';
@@ -68,6 +69,8 @@ export async function ui(options) {
68
69
  const fresh = new FreshLooks(root, agentStart(root, agentEnvironment));
69
70
  const chats = new ChatEngine(root, { environment: agentEnvironment, migrations, fresh });
70
71
  await chats.ready;
72
+ // Merged, clean, unused change worktrees go now and after each merge.
73
+ startSweeps(root);
71
74
  const stack = new Stack(root, {
72
75
  app: env.APE_APP_URL,
73
76
  admin: env.APE_ADMIN_URL,
@@ -1,3 +1,4 @@
1
+ import { type Signature } from '@buffcore/contracts/approvals';
1
2
  import type { themes } from '@buffcore/tokens';
2
3
  import { type SaveSource } from './host-save.ts';
3
4
  export declare function brandApproval(root: string, direction: keyof typeof themes, signer?: string, role?: string, agent?: string, fingerprint?: string, source?: SaveSource): Promise<{
@@ -17,6 +18,10 @@ export declare function brandApproval(root: string, direction: keyof typeof them
17
18
  fingerprint: string;
18
19
  role?: string | undefined;
19
20
  agent?: string | undefined;
21
+ ai?: {
22
+ model?: string | undefined;
23
+ reason: string;
24
+ } | undefined;
20
25
  }[];
21
26
  rule?: {
22
27
  kind: "one";
@@ -54,7 +59,7 @@ export declare function brandApproval(root: string, direction: keyof typeof them
54
59
  export declare function prototypeApproval(root: string, request: {
55
60
  change: string;
56
61
  version: number;
57
- }, signer?: string, role?: string, agent?: string, source?: SaveSource): Promise<{
62
+ }, signer?: string, role?: string, agent?: string, source?: SaveSource, ai?: Signature['ai']): Promise<{
58
63
  status: number;
59
64
  body: {
60
65
  error: string;
@@ -83,6 +88,10 @@ export declare function prototypeApproval(root: string, request: {
83
88
  fingerprint: string;
84
89
  role?: string | undefined;
85
90
  agent?: string | undefined;
91
+ ai?: {
92
+ model?: string | undefined;
93
+ reason: string;
94
+ } | undefined;
86
95
  }[];
87
96
  rule?: {
88
97
  kind: "one";
@@ -96,6 +105,10 @@ export declare function prototypeApproval(root: string, request: {
96
105
  by: string;
97
106
  } | undefined;
98
107
  };
108
+ reopened?: {
109
+ by: string;
110
+ at: string;
111
+ } | undefined;
99
112
  } | undefined;
100
113
  pending?: {
101
114
  version: number;
@@ -108,6 +121,10 @@ export declare function prototypeApproval(root: string, request: {
108
121
  fingerprint: string;
109
122
  role?: string | undefined;
110
123
  agent?: string | undefined;
124
+ ai?: {
125
+ model?: string | undefined;
126
+ reason: string;
127
+ } | undefined;
111
128
  }[];
112
129
  rule?: {
113
130
  kind: "one";
@@ -121,6 +138,10 @@ export declare function prototypeApproval(root: string, request: {
121
138
  by: string;
122
139
  } | undefined;
123
140
  };
141
+ reopened?: {
142
+ by: string;
143
+ at: string;
144
+ } | undefined;
124
145
  } | undefined;
125
146
  superseded?: {
126
147
  version: number;
@@ -133,6 +154,10 @@ export declare function prototypeApproval(root: string, request: {
133
154
  fingerprint: string;
134
155
  role?: string | undefined;
135
156
  agent?: string | undefined;
157
+ ai?: {
158
+ model?: string | undefined;
159
+ reason: string;
160
+ } | undefined;
136
161
  }[];
137
162
  rule?: {
138
163
  kind: "one";
@@ -146,6 +171,10 @@ export declare function prototypeApproval(root: string, request: {
146
171
  by: string;
147
172
  } | undefined;
148
173
  };
174
+ reopened?: {
175
+ by: string;
176
+ at: string;
177
+ } | undefined;
149
178
  }[] | undefined;
150
179
  };
151
180
  } | {
@@ -67,7 +67,7 @@ const reasonOf = (error) => !(error instanceof Error)
67
67
  : 'status' in error && typeof error.status === 'number'
68
68
  ? 'command'
69
69
  : (error.code ?? error.name);
70
- export async function prototypeApproval(root, request, signer, role, agent, source) {
70
+ export async function prototypeApproval(root, request, signer, role, agent, source, ai) {
71
71
  let stage = 'unexpected';
72
72
  try {
73
73
  if (agent === '')
@@ -103,7 +103,7 @@ export async function prototypeApproval(root, request, signer, role, agent, sour
103
103
  }
104
104
  const approve = (write = true) => held
105
105
  ? record
106
- : approveVersion(root, request.change, request.version, by, new Date(), role, agent, write);
106
+ : approveVersion(root, request.change, request.version, by, new Date(), role, agent, write, ai);
107
107
  const body = await savePrototypeApproval(root, request.change, approve, by, agent, source);
108
108
  return { status: 201, body };
109
109
  }
@@ -2,6 +2,7 @@ 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';
@@ -103,6 +104,8 @@ async function personMerge(root, change, { identity, hosted, approval, stop, sig
103
104
  const context = authorityFor({ identity, approval });
104
105
  const authority = context ? hostMergeAuthority(context) : undefined;
105
106
  const result = await checkAfterMerge(root, await mergeOne(root, change, tools, authority, level), undefined, ends, change);
107
+ if (result.ok)
108
+ sweepAfterMerge(root);
106
109
  return {
107
110
  status: result.ok ? 200 : result.status === 'pending' ? 202 : 409,
108
111
  body: !result.ok && authority?.code
@@ -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";
@@ -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,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[];
@@ -206,3 +206,7 @@ export function saveRoute(root) {
206
206
  };
207
207
  return route;
208
208
  }
209
+ /** The files a save's preview names, when it names them. */
210
+ export function saveFiles(value) {
211
+ return Array.isArray(value) && value.every((file) => typeof file === 'string');
212
+ }
@@ -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;
@@ -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. */
@@ -3,7 +3,7 @@ type Worktree = WorkFacts['worktrees'][number];
3
3
  type Git = (args: string[], cwd?: string) => Promise<string>;
4
4
  export declare const worktreeMerge: (root: string, branch: string, main: string, head: string) => Worktree['merge'];
5
5
  /** Never checks out a branch or writes HEAD/the index. The injectable Git runner also tests old Git. */
6
- export declare function listWorktrees(root: string, git?: Git): Promise<Worktree[]>;
6
+ export declare function listWorktrees(root: string, git?: Git, listing?: string): Promise<Worktree[]>;
7
7
  /** Only changes with an active, unmerged worktree take part in clash warnings. */
8
8
  export declare function workFacts(root: string, hostedAuthority?: boolean): Promise<WorkFacts | undefined>;
9
9
  export {};