@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
@@ -6,3 +6,9 @@ export declare const removeLinks: (top: string) => Promise<void>;
6
6
  * cannot delete without `core.longpaths`.
7
7
  */
8
8
  export declare const emptyCheckout: (top: string) => Promise<void>;
9
+ /**
10
+ * A checkout's top `node_modules`, emptied and removed without following a link. Nothing happens
11
+ * when it is missing; a link there is removed as itself; a folder whose real path is not its own
12
+ * (a junction a listing calls a folder) throws.
13
+ */
14
+ export declare function removePackages(top: string): Promise<void>;
@@ -50,3 +50,20 @@ export const removeLinks = (top) => walk(top, false);
50
50
  * cannot delete without `core.longpaths`.
51
51
  */
52
52
  export const emptyCheckout = (top) => walk(top, true);
53
+ /**
54
+ * A checkout's top `node_modules`, emptied and removed without following a link. Nothing happens
55
+ * when it is missing; a link there is removed as itself; a folder whose real path is not its own
56
+ * (a junction a listing calls a folder) throws.
57
+ */
58
+ export async function removePackages(top) {
59
+ const folder = join(top, 'node_modules');
60
+ const entry = await lstat(folder).catch(() => undefined);
61
+ if (!entry)
62
+ return;
63
+ if (entry.isSymbolicLink())
64
+ return removeLink(folder);
65
+ if (!same(realpathSync.native(folder), join(realpathSync.native(top), 'node_modules')))
66
+ throw new Error('linked folder');
67
+ await walk(folder, true);
68
+ await rmdir(folder);
69
+ }
@@ -0,0 +1,9 @@
1
+ /** Whether `ape size` weighs this path as a process document. */
2
+ export declare const isProcessDoc: (path: string) => boolean;
3
+ /** One warning line per process document past its limit, in the person's language. */
4
+ export declare function docSizeWarnings(files: readonly {
5
+ path: string;
6
+ bytes: number;
7
+ }[], locale?: 'en' | 'es'): string[];
8
+ /** The person's language for the warnings, from the environment. */
9
+ export declare const docLocale: () => 'en' | 'es';
@@ -0,0 +1,6 @@
1
+ export declare const en: {
2
+ 'size.docWarning': string;
3
+ 'size.docCritique': string;
4
+ 'size.docChange': string;
5
+ 'size.docOther': string;
6
+ };
@@ -0,0 +1,6 @@
1
+ export const en = {
2
+ 'size.docWarning': 'Warning {path} {size} KB, over about {limit} KB: agents read this file; {advice}',
3
+ 'size.docCritique': 'keep only the newest review, earlier ones stay in git.',
4
+ 'size.docChange': 'keep the plan, not a log of rounds: what was built is in git.',
5
+ 'size.docOther': 'split it by heading so agents read one section, and keep history in git, not in the file.',
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { en } from './size-docs.en.ts';
2
+ export declare const es: typeof en;
@@ -0,0 +1,6 @@
1
+ export const es = {
2
+ 'size.docWarning': 'Aviso {path} {size} KB, más de unos {limit} KB: los agentes leen este archivo; {advice}',
3
+ 'size.docCritique': 'deja solo la revisión más reciente; las anteriores quedan en git.',
4
+ 'size.docChange': 'guarda el plan, no un registro de rondas: lo construido está en git.',
5
+ 'size.docOther': 'divídelo por encabezados para que los agentes lean una sección, y deja el historial en git, no en el archivo.',
6
+ };
@@ -0,0 +1,28 @@
1
+ // Process documents agents read again and again (the plan, the design, the critique, the change
2
+ // files) stay small enough to read. Past a size, `ape size` prints a warning; it never fails.
3
+ import { createI18n } from '@buffcore/i18n';
4
+ import { en } from './size-docs.en.js';
5
+ import { es } from './size-docs.es.js';
6
+ const messages = createI18n({ catalogs: [{ en, es }] });
7
+ const KB = 1024;
8
+ /** The first rule a path matches sets its limit and its advice. */
9
+ const RULES = [
10
+ { match: /(^|\/)design\/critique\.md$/, limit: 40 * KB, advice: 'size.docCritique' },
11
+ { match: /(^|\/)plan\/changes\/[^/]+\.md$/, limit: 15 * KB, advice: 'size.docChange' },
12
+ { match: /(^|\/)(design|plan)\/.+\.md$/, limit: 50 * KB, advice: 'size.docOther' },
13
+ ];
14
+ /** Whether `ape size` weighs this path as a process document. */
15
+ export const isProcessDoc = (path) => RULES.some((rule) => rule.match.test(path));
16
+ /** One warning line per process document past its limit, in the person's language. */
17
+ export function docSizeWarnings(files, locale = 'en') {
18
+ const t = (key, values) => messages.t(locale, key, values);
19
+ return files.flatMap(({ path, bytes }) => {
20
+ const rule = RULES.find((r) => r.match.test(path));
21
+ if (!rule || bytes <= rule.limit)
22
+ return [];
23
+ const size = Math.round(bytes / KB);
24
+ return [t('size.docWarning', { path, size, limit: rule.limit / KB, advice: t(rule.advice) })];
25
+ });
26
+ }
27
+ /** The person's language for the warnings, from the environment. */
28
+ export const docLocale = () => /^es(?:[-_.]|$)/i.test(process.env.LC_ALL || process.env.LANG || '') ? 'es' : 'en';
@@ -12,6 +12,9 @@ export declare function checkSizes(files: readonly {
12
12
  text: string;
13
13
  }[]): SizeReport;
14
14
  /** The size report of the repository at `dir`: its tracked source files, and new ones not ignored. */
15
- export declare function sizeReport(dir: string): SizeReport;
16
- /** `ape size`: fail when a source file in this repository passes the limit. */
15
+ export declare function sizeReport(dir: string, listed?: readonly string[]): SizeReport;
16
+ /**
17
+ * `ape size`: warn (never fail) on process documents past their size, and fail when a source file
18
+ * in this repository passes the limit.
19
+ */
17
20
  export declare function size(dir?: string): void;
@@ -1,6 +1,7 @@
1
1
  import { execFileSync } from 'node:child_process';
2
- import { readFileSync } from 'node:fs';
2
+ import { readFileSync, statSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
+ import { docLocale, docSizeWarnings, isProcessDoc } from './size-docs.js';
4
5
  /** Source files stay under this many lines (AGENTS.md: small files, one job each). */
5
6
  export const MAX_LINES = 300;
6
7
  /** A file over the limit may carry this marker near its top until it is split. */
@@ -25,14 +26,14 @@ export function checkSizes(files) {
25
26
  }
26
27
  return report;
27
28
  }
29
+ /** The repository's tracked files, and new ones not ignored. */
30
+ const listFiles = (dir) => execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard'], {
31
+ cwd: dir,
32
+ encoding: 'utf8',
33
+ }).split('\n');
28
34
  /** The size report of the repository at `dir`: its tracked source files, and new ones not ignored. */
29
- export function sizeReport(dir) {
30
- const listed = execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard'], {
31
- cwd: dir,
32
- encoding: 'utf8',
33
- });
35
+ export function sizeReport(dir, listed = listFiles(dir)) {
34
36
  const files = listed
35
- .split('\n')
36
37
  .filter((path) => SOURCE.test(path))
37
38
  .flatMap((path) => {
38
39
  try {
@@ -44,9 +45,26 @@ export function sizeReport(dir) {
44
45
  });
45
46
  return checkSizes(files);
46
47
  }
47
- /** `ape size`: fail when a source file in this repository passes the limit. */
48
+ /** The process documents among `listed`, with their sizes in bytes. */
49
+ function docFiles(dir, listed) {
50
+ return listed.filter(isProcessDoc).flatMap((path) => {
51
+ try {
52
+ return [{ path, bytes: statSync(join(dir, path)).size }];
53
+ }
54
+ catch {
55
+ return []; // deleted, still in the index
56
+ }
57
+ });
58
+ }
59
+ /**
60
+ * `ape size`: warn (never fail) on process documents past their size, and fail when a source file
61
+ * in this repository passes the limit.
62
+ */
48
63
  export function size(dir = process.cwd()) {
49
- const { over, pending } = sizeReport(dir);
64
+ const listed = listFiles(dir);
65
+ const { over, pending } = sizeReport(dir, listed);
66
+ for (const line of docSizeWarnings(docFiles(dir, listed), docLocale()))
67
+ console.log(line);
50
68
  if (pending.length > 0) {
51
69
  const files = pending.length === 1 ? '1 file' : `${pending.length} files`;
52
70
  console.log(`${files} over ${MAX_LINES} lines waiting to be split (marked "${PENDING}").`);
@@ -1,4 +1,4 @@
1
- import { type Approval, type ApprovalKind } from '@buffcore/contracts/approvals';
1
+ import { type Approval, type ApprovalKind, type Signature } from '@buffcore/contracts/approvals';
2
2
  import { type Viewer } from '@buffcore/contracts/workbench';
3
3
  import { en } from './approval-authority.en.ts';
4
4
  export type ApprovalArtifact = Readonly<{
@@ -20,8 +20,11 @@ export type HostApprovalAnswer = {
20
20
  export type HostApproval = (input: Readonly<{
21
21
  viewer: Readonly<Viewer>;
22
22
  artifact: ApprovalArtifact;
23
- action: 'approve' | 'check';
23
+ /** `reopen` (S4): a person reopens an AI approval; a host that cannot answers not allowed. */
24
+ action: 'approve' | 'check' | 'reopen';
24
25
  agent?: string;
26
+ /** An AI approval (S4): the approver's model and reason, for the host to keep on its signature. */
27
+ ai?: Signature['ai'];
25
28
  signal: AbortSignal;
26
29
  }>) => Promise<HostApprovalAnswer>;
27
30
  /** Request/turn-owned capabilities; never serialized into a chat, prompt or signature file. */
@@ -29,6 +32,7 @@ export type ApprovalContext = Readonly<{
29
32
  approval: HostApproval;
30
33
  viewer: Readonly<Viewer>;
31
34
  agent?: string;
35
+ ai?: Signature['ai'];
32
36
  }>;
33
37
  export declare function authorityFor(source: {
34
38
  approval?: HostApproval;
@@ -69,6 +73,10 @@ export declare function hostedApproval(context: ApprovalContext, resolve: () =>
69
73
  fingerprint: string;
70
74
  role?: string | undefined;
71
75
  agent?: string | undefined;
76
+ ai?: {
77
+ model?: string | undefined;
78
+ reason: string;
79
+ } | undefined;
72
80
  }[];
73
81
  rule?: {
74
82
  kind: "one";
@@ -94,6 +94,7 @@ async function bounded(context, artifact, action, root) {
94
94
  artifact,
95
95
  action,
96
96
  ...(context.agent ? { agent: context.agent } : {}),
97
+ ...(context.ai ? { ai: context.ai } : {}),
97
98
  signal: controller.signal,
98
99
  })))
99
100
  .then((answer) => validated(answer, artifact, context, action, root), () => refused('approval_authority_error'));
@@ -0,0 +1,18 @@
1
+ import type { PrototypeVersion } from '@buffcore/contracts/approvals';
2
+ import type { Chat } from '@buffcore/contracts/workbench';
3
+ import { type Approver, type Critic } from '../prototype/approver.ts';
4
+ /** What an AI approval records beside its signature: the approver's agent, model and reason. */
5
+ export interface AiDecision {
6
+ agent: string;
7
+ ai: {
8
+ model?: string;
9
+ reason: string;
10
+ };
11
+ }
12
+ /** The two fresh turns: the studio's critique for this report, then the approver. */
13
+ export interface AiTurns {
14
+ critic?: Critic;
15
+ approver?: Approver;
16
+ }
17
+ /** Approve by AI or throw the person's reason (AutoAsk); `chat` is the turn that built the change. */
18
+ export declare function aiApprove(root: string, change: string, version: PrototypeVersion, chat: Pick<Chat, 'session'>, allowed?: () => boolean, turns?: AiTurns): Promise<AiDecision>;
@@ -0,0 +1,68 @@
1
+ import { critiqueBlock, reportBlock } from '../prototype/ai-approval.js';
2
+ import { APPROVER_SECONDS, CRITIC_SECONDS, cliApprover, cliCritic, } from '../prototype/approver.js';
3
+ import { versionSnapshot } from '../prototype/versions.js';
4
+ import { hostGitBytes } from '../safe-git.js';
5
+ import { AutoAsk, autoT } from './autopilot-person.js';
6
+ const DIFF_CHARS = 40_000;
7
+ function versionDiff(root, commit) {
8
+ try {
9
+ const text = hostGitBytes(root, ['show', '--no-color', '--no-ext-diff', '--format=', commit]);
10
+ const diff = text.toString();
11
+ return diff.length > DIFF_CHARS ? `${diff.slice(0, DIFF_CHARS)}\n[diff cut]` : diff;
12
+ }
13
+ catch {
14
+ return '';
15
+ }
16
+ }
17
+ const waiting = (result, seconds) => new AutoAsk(autoT(`auto.ai.${result.state}`, {
18
+ agent: result.agent ?? '',
19
+ seconds,
20
+ file: result.file ?? '',
21
+ }));
22
+ /** Approve by AI or throw the person's reason (AutoAsk); `chat` is the turn that built the change. */
23
+ export async function aiApprove(root, change, version, chat, allowed = () => true, turns = {}) {
24
+ const { snapshot, report } = versionSnapshot(root, version.commit, version);
25
+ const block = reportBlock(report);
26
+ if (block)
27
+ throw new AutoAsk(autoT(`auto.ai.${block}`));
28
+ const folder = `prototype/snapshots/${snapshot}`;
29
+ // The critique is the studio's own fresh turn for this report, run here; a design/critique.md
30
+ // the building agent wrote is never read.
31
+ const critic = turns.critic ?? cliCritic(root);
32
+ const critique = await critic(folder).catch(() => ({ state: 'failed' }));
33
+ if (critique.state !== 'done')
34
+ throw critique.state === 'agent' || critique.state === 'codex-sandbox'
35
+ ? waiting(critique, CRITIC_SECONDS)
36
+ : new AutoAsk(autoT('auto.ai.critic', {
37
+ why: autoT(`auto.ai.why.${critique.state}`, {
38
+ file: 'file' in critique ? (critique.file ?? '') : '',
39
+ }),
40
+ }));
41
+ if (!allowed())
42
+ throw new AutoAsk(autoT('auto.failed'));
43
+ const unfit = critiqueBlock(report, critique.text);
44
+ if (unfit)
45
+ throw new AutoAsk(autoT(`auto.ai.${unfit}`));
46
+ const approver = turns.approver ?? cliApprover(root);
47
+ const result = await approver({
48
+ change,
49
+ version: version.version,
50
+ report: folder,
51
+ diff: versionDiff(root, version.commit),
52
+ critique: critique.text,
53
+ }).catch(() => ({ state: 'failed' }));
54
+ if (result.state !== 'done')
55
+ throw waiting(result, APPROVER_SECONDS);
56
+ // The turn may take minutes: the person may have taken the loop back meanwhile.
57
+ if (!allowed())
58
+ throw new AutoAsk(autoT('auto.failed'));
59
+ // A fresh session, never the one that built the change.
60
+ if (!result.session || result.session === chat.session)
61
+ throw new AutoAsk(autoT('auto.ai.builder'));
62
+ if (result.decision !== 'approve')
63
+ throw new AutoAsk(autoT('auto.ai.declined', { reason: result.reason }));
64
+ return {
65
+ agent: result.agent,
66
+ ai: { ...(result.model ? { model: result.model } : {}), reason: result.reason },
67
+ };
68
+ }
@@ -6,12 +6,13 @@ import { personHeld, personOnly } from '../prototype/supersede.js';
6
6
  import { pickVersion, readVersions, recordVersion, VersionRefusal, versionSnapshot, } from '../prototype/versions.js';
7
7
  import { brandResolver, hostedVersions, prototypeArtifact } from './approval-artifact.js';
8
8
  import { artifactCurrent, authorityFor, hostedApproval, judge } from './approval-authority.js';
9
+ import { aiApprove } from './autopilot-ai-approve.js';
9
10
  import { AutoAsk, autoPerson, autoT } from './autopilot-person.js';
10
11
  import { readAutoChoices } from './autopilot-records.js';
11
12
  import { publishSave } from './host-save.js';
12
13
  import { brandApproval, prototypeApproval } from './loop-approve.js';
13
14
  import { readPlan } from './plan-files.js';
14
- import { studioSave } from './save-route.js';
15
+ import { saveFiles, studioSave } from './save-route.js';
15
16
  import { runPrototypeSnapshot } from './server.js';
16
17
  import { diagnosticsText } from './snapshot-view.js';
17
18
  import { prototypeChange } from './studio-state.js';
@@ -160,9 +161,10 @@ async function approvePrototype(root, chat, person, allowed, signal) {
160
161
  const screen = versionSnapshot(root, version.commit, version).report.scenes[0]?.key;
161
162
  if (!allowed())
162
163
  throw new AutoAsk(autoT('auto.failed'));
164
+ const decision = await aiApprove(root, change, version, chat, allowed);
163
165
  const result = context
164
- ? await hostedApproval(context, () => prototypeArtifact(root, change, version.version, true, true))
165
- : await prototypeApproval(root, { change: record.change, version: version.version }, actor.by, actor.role, chat.agent, person);
166
+ ? await hostedApproval({ ...context, agent: decision.agent, ai: decision.ai }, () => prototypeArtifact(root, change, version.version, true, true))
167
+ : await prototypeApproval(root, { change: record.change, version: version.version }, actor.by, actor.role, decision.agent, person, decision.ai);
166
168
  if (result.status !== 201)
167
169
  throw new AutoAsk(result.body && 'error' in result.body && typeof result.body.error === 'string'
168
170
  ? result.body.error
@@ -197,6 +199,3 @@ export async function automaticLoop(root, chat, person, allowed, signal) {
197
199
  }
198
200
  return { step, agent: chat.agent, by: actor.by, at: new Date().toISOString(), commit, ...detail };
199
201
  }
200
- function saveFiles(value) {
201
- return Array.isArray(value) && value.every((file) => typeof file === 'string');
202
- }
@@ -3,6 +3,7 @@ import { context, defaultMergeTools, mergeOne, } from '../change-merge.js';
3
3
  import { unsavedPaths } from '../change-merge-clean.js';
4
4
  import { mainCommit } from '../main-ref.js';
5
5
  import { hostGit } from '../safe-git.js';
6
+ import { sweepAfterMerge } from '../worktree-sweep.js';
6
7
  import { hostMergeAuthority } from './approval-artifact.js';
7
8
  import { authorityFor } from './approval-authority.js';
8
9
  import { protectAutoLinks } from './autopilot-links.js';
@@ -42,6 +43,8 @@ export async function automaticMerge(root, change, person, allowed, fixtureTools
42
43
  const state = {};
43
44
  const tools = automaticTools(root, person, allowed, base, authority, signal, state, Boolean(delegation), holdFile, observeDirty);
44
45
  const result = await mergeOne(root, change, delegatedTools(root, { ...tools, expectedHead }, delegation, signal, () => allowed() && effectiveLevel(root) === 'auto', false, holdFile), authority);
46
+ if (result.ok)
47
+ sweepAfterMerge(root);
45
48
  if (state.refusal)
46
49
  throw state.refusal;
47
50
  const mainDirty = state.mainDirty;
@@ -36,4 +36,27 @@ export declare const en: {
36
36
  'auto.merged': string;
37
37
  'auto.revert': string;
38
38
  'auto.failed': string;
39
+ 'auto.ai.floor': string;
40
+ 'auto.ai.selector': string;
41
+ 'auto.ai.checks': string;
42
+ 'auto.ai.critique': string;
43
+ 'auto.ai.p0': string;
44
+ 'auto.ai.agreement': string;
45
+ 'auto.ai.agent': string;
46
+ 'auto.ai.codex-sandbox': string;
47
+ 'auto.ai.ci': string;
48
+ 'auto.ai.launch': string;
49
+ 'auto.ai.failed': string;
50
+ 'auto.ai.timeout': string;
51
+ 'auto.ai.shape': string;
52
+ 'auto.ai.builder': string;
53
+ 'auto.ai.declined': string;
54
+ 'auto.ai.critic': string;
55
+ 'auto.ai.secret': string;
56
+ 'auto.ai.why.secret': string;
57
+ 'auto.ai.why.ci': string;
58
+ 'auto.ai.why.launch': string;
59
+ 'auto.ai.why.failed': string;
60
+ 'auto.ai.why.timeout': string;
61
+ 'auto.ai.why.shape': string;
39
62
  };
@@ -36,4 +36,27 @@ export const en = {
36
36
  'auto.merged': 'Merged {change}. To undo, copy: {command}',
37
37
  'auto.revert': '{change} is on main, but no safe command to undo this kind of merge is known; look at main before continuing.',
38
38
  'auto.failed': 'the action could not be confirmed. Check its result before continuing.',
39
+ 'auto.ai.floor': 'this version waits for a person: its report did not draw the floor for every scene.',
40
+ 'auto.ai.selector': 'this version waits for a person: its report does not say whether the selector ran.',
41
+ 'auto.ai.checks': 'this version waits for a person: a check in its report did not pass.',
42
+ 'auto.ai.critique': 'this version waits for a person: design/critique.md does not review this commit.',
43
+ 'auto.ai.p0': 'this version waits for a person: the critique names a P0.',
44
+ 'auto.ai.agreement': 'this version waits for a person: the second selector turn added looks that were not drawn, or did not answer.',
45
+ 'auto.ai.agent': 'this version waits for a person: the approver runs only with Claude Code or Codex ({agent} is set for validation and has no read-only turn).',
46
+ 'auto.ai.codex-sandbox': 'this version waits for a person: Codex’s elevated Windows sandbox is not set up (set it up once in Codex, then try again).',
47
+ 'auto.ai.ci': 'this version waits for a person: no approver turn runs in tests or CI.',
48
+ 'auto.ai.launch': 'this version waits for a person: the approver turn could not start.',
49
+ 'auto.ai.failed': 'this version waits for a person: the approver turn failed.',
50
+ 'auto.ai.timeout': 'this version waits for a person: the approver turn took longer than {seconds} seconds.',
51
+ 'auto.ai.shape': 'this version waits for a person: the approver answered out of shape.',
52
+ 'auto.ai.builder': 'this version waits for a person: the approver could not prove it is not the agent that built the change.',
53
+ 'auto.ai.declined': 'this version waits for a person: the approver declined ({reason}).',
54
+ 'auto.ai.critic': "this version waits for a person: the studio's critique turn for this report did not finish ({why}).",
55
+ 'auto.ai.secret': 'this version waits for a person: the approver’s answer quoted a value from {file}, so it was dropped.',
56
+ 'auto.ai.why.secret': 'its answer quoted a value from {file} and was dropped',
57
+ 'auto.ai.why.ci': 'tests or CI',
58
+ 'auto.ai.why.launch': 'it could not start',
59
+ 'auto.ai.why.failed': 'it failed',
60
+ 'auto.ai.why.timeout': 'it took too long',
61
+ 'auto.ai.why.shape': 'its answer was out of shape',
39
62
  };
@@ -36,4 +36,27 @@ export declare const es: {
36
36
  'auto.merged': string;
37
37
  'auto.revert': string;
38
38
  'auto.failed': string;
39
+ 'auto.ai.floor': string;
40
+ 'auto.ai.selector': string;
41
+ 'auto.ai.checks': string;
42
+ 'auto.ai.critique': string;
43
+ 'auto.ai.p0': string;
44
+ 'auto.ai.agreement': string;
45
+ 'auto.ai.agent': string;
46
+ 'auto.ai.codex-sandbox': string;
47
+ 'auto.ai.ci': string;
48
+ 'auto.ai.launch': string;
49
+ 'auto.ai.failed': string;
50
+ 'auto.ai.timeout': string;
51
+ 'auto.ai.shape': string;
52
+ 'auto.ai.builder': string;
53
+ 'auto.ai.declined': string;
54
+ 'auto.ai.critic': string;
55
+ 'auto.ai.secret': string;
56
+ 'auto.ai.why.secret': string;
57
+ 'auto.ai.why.ci': string;
58
+ 'auto.ai.why.launch': string;
59
+ 'auto.ai.why.failed': string;
60
+ 'auto.ai.why.timeout': string;
61
+ 'auto.ai.why.shape': string;
39
62
  };
@@ -36,4 +36,27 @@ export const es = {
36
36
  'auto.merged': 'Se integró {change}. Para deshacerlo, copia: {command}',
37
37
  'auto.revert': '{change} está en main, pero no se conoce un comando seguro para deshacer este tipo de integración; revisa main antes de continuar.',
38
38
  'auto.failed': 'no se pudo confirmar la acción. Comprueba su resultado antes de continuar.',
39
+ 'auto.ai.floor': 'esta versión espera a una persona: su informe no dibujó el mínimo en cada escena.',
40
+ 'auto.ai.selector': 'esta versión espera a una persona: su informe no dice si el selector se ejecutó.',
41
+ 'auto.ai.checks': 'esta versión espera a una persona: una comprobación de su informe no pasó.',
42
+ 'auto.ai.critique': 'esta versión espera a una persona: design/critique.md no revisa este commit.',
43
+ 'auto.ai.p0': 'esta versión espera a una persona: la crítica señala un P0.',
44
+ 'auto.ai.agreement': 'esta versión espera a una persona: el segundo turno del selector añadió aspectos que no se dibujaron, o no respondió.',
45
+ 'auto.ai.agent': 'esta versión espera a una persona: el aprobador solo funciona con Claude Code o Codex ({agent} está elegido para validar y no tiene un turno de solo lectura).',
46
+ 'auto.ai.codex-sandbox': 'esta versión espera a una persona: el sandbox elevado de Windows de Codex no está configurado (configúralo una vez en Codex y vuelve a intentarlo).',
47
+ 'auto.ai.ci': 'esta versión espera a una persona: en pruebas o en CI no se ejecuta ningún turno de aprobación.',
48
+ 'auto.ai.launch': 'esta versión espera a una persona: el turno de aprobación no pudo empezar.',
49
+ 'auto.ai.failed': 'esta versión espera a una persona: el turno de aprobación falló.',
50
+ 'auto.ai.timeout': 'esta versión espera a una persona: el turno de aprobación tardó más de {seconds} segundos.',
51
+ 'auto.ai.shape': 'esta versión espera a una persona: la respuesta del aprobador no tiene la forma pedida.',
52
+ 'auto.ai.builder': 'esta versión espera a una persona: el aprobador no pudo demostrar que no es el agente que hizo el cambio.',
53
+ 'auto.ai.declined': 'esta versión espera a una persona: el aprobador la rechazó ({reason}).',
54
+ 'auto.ai.critic': 'esta versión espera a una persona: el turno de crítica del estudio para este informe no terminó ({why}).',
55
+ 'auto.ai.secret': 'esta versión espera a una persona: la respuesta del aprobador citaba un valor de {file}, así que se descartó.',
56
+ 'auto.ai.why.secret': 'su respuesta citaba un valor de {file} y se descartó',
57
+ 'auto.ai.why.ci': 'pruebas o CI',
58
+ 'auto.ai.why.launch': 'no pudo empezar',
59
+ 'auto.ai.why.failed': 'falló',
60
+ 'auto.ai.why.timeout': 'tardó demasiado',
61
+ 'auto.ai.why.shape': 'su respuesta no tenía la forma pedida',
39
62
  };
@@ -1,4 +1,6 @@
1
1
  import type { FoundAgent } from '@buffcore/contracts/workbench';
2
2
  import { type Start } from '../runner.ts';
3
+ /** The same check at once, for a fresh Codex turn (fresh-codex.ts): Codex's config only. */
4
+ export declare function codexElevated(): boolean;
3
5
  /** Fixed CLI probes and Codex's config only, never sign-in files. */
4
6
  export declare function findAgents(start?: Start, root?: string): Promise<FoundAgent[]>;
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from 'node:fs';
1
2
  import { readFile } from 'node:fs/promises';
2
3
  import { homedir } from 'node:os';
3
4
  import { isAbsolute, join } from 'node:path';
@@ -105,6 +106,18 @@ async function codexSetup() {
105
106
  return false;
106
107
  }
107
108
  }
109
+ /** The same check at once, for a fresh Codex turn (fresh-codex.ts): Codex's config only. */
110
+ export function codexElevated() {
111
+ const home = process.env.CODEX_HOME || join(homedir(), '.codex');
112
+ if (!isAbsolute(home))
113
+ return false;
114
+ try {
115
+ return elevated(readFileSync(join(home, 'config.toml'), 'utf8'));
116
+ }
117
+ catch {
118
+ return false;
119
+ }
120
+ }
108
121
  /** Fixed CLI probes and Codex's config only, never sign-in files. */
109
122
  export function findAgents(start, root = findRoot()) {
110
123
  const launch = start ?? agentStart(root);
@@ -0,0 +1,39 @@
1
+ import type { AgentEffort, AgentId } from '@buffcore/contracts/workbench';
2
+ /** The agents with a fresh read-only turn. OpenCode has none yet (see docs/PROTOTYPE.md). */
3
+ export declare const FRESH_AGENTS: readonly ['claude', 'codex'];
4
+ export type FreshAgent = (typeof FRESH_AGENTS)[number];
5
+ export declare const freshAgent: (id: AgentId | string) => id is FreshAgent;
6
+ /**
7
+ * Why the agent takes no fresh read-only turn in this folder, or undefined: an agent with none
8
+ * (`agent`), Codex whose project settings could widen it (`agent`, codexWidens), or Codex on Windows
9
+ * without its elevated sandbox, the studio's own readiness check (`codex-sandbox`).
10
+ */
11
+ export declare function freshUnready(id: AgentId | string, folder: string): 'agent' | 'codex-sandbox' | undefined;
12
+ /** The agent takes a fresh read-only turn in this folder. */
13
+ export declare const freshReady: (id: AgentId | string, folder: string) => id is FreshAgent;
14
+ /**
15
+ * What a fresh turn still needs of them: where Codex keeps its sign-in, the sign-in a person set
16
+ * for Claude Code, and the certificate authorities a company network adds.
17
+ */
18
+ export declare const FRESH_ALLOWED: string[];
19
+ /** The environment without the building turn's session; HOME and the rest pass. */
20
+ export declare const freshEnvironment: (env: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
21
+ /**
22
+ * Why the product's own Codex settings could widen a fresh turn, or undefined. `-s read-only` beats
23
+ * any sandbox or permission profile in them, but an MCP server runs outside Codex's sandbox and a
24
+ * hook runs a command of its own: a `.codex/config.toml` from the folder up with anything beyond
25
+ * the profile (`default_permissions`, `[permissions.*]`) and the studio's own `[mcp_servers.ape]`
26
+ * (turned off for the turn), or a `.codex/hooks.json`, up to the repository's root, gives no fresh
27
+ * Codex turn.
28
+ */
29
+ export declare function codexWidens(folder: string): string | undefined;
30
+ export interface CodexFreshLaunch {
31
+ folder: string;
32
+ model?: string;
33
+ effort?: AgentEffort;
34
+ }
35
+ /**
36
+ * The read-only arguments for one fresh Codex turn; the prompt goes in on stdin. No trust for the
37
+ * folder, so a project setting Codex would load only for a trusted folder stays out too.
38
+ */
39
+ export declare function freshCodexArgs(launch: CodexFreshLaunch): string[];