@buffcore/cli 0.8.46 → 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 (187) hide show
  1. package/CHANGELOG.md +56 -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/critique-gate.d.ts +14 -0
  19. package/dist/commands/prototype/critique-gate.js +48 -0
  20. package/dist/commands/prototype/fence.d.ts +1 -0
  21. package/dist/commands/prototype/fence.js +12 -0
  22. package/dist/commands/prototype/final-approval-grant.js +18 -0
  23. package/dist/commands/prototype/final-approval.js +4 -1
  24. package/dist/commands/prototype/index.js +3 -0
  25. package/dist/commands/prototype/layout-hints.d.ts +34 -0
  26. package/dist/commands/prototype/layout-hints.js +194 -0
  27. package/dist/commands/prototype/layout-measure.d.ts +39 -0
  28. package/dist/commands/prototype/layout-measure.js +97 -0
  29. package/dist/commands/prototype/layout-words.d.ts +2 -0
  30. package/dist/commands/prototype/layout-words.js +11 -0
  31. package/dist/commands/prototype/layout.en.d.ts +6 -0
  32. package/dist/commands/prototype/layout.en.js +7 -0
  33. package/dist/commands/prototype/load-location.js +2 -3
  34. package/dist/commands/prototype/messages.en.d.ts +14 -0
  35. package/dist/commands/prototype/messages.en.js +15 -1
  36. package/dist/commands/prototype/messages.js +15 -1
  37. package/dist/commands/prototype/milestone-versions.d.ts +4 -0
  38. package/dist/commands/prototype/prune-command.d.ts +5 -0
  39. package/dist/commands/prototype/prune-command.js +25 -0
  40. package/dist/commands/prototype/prune-words.d.ts +1 -0
  41. package/dist/commands/prototype/prune-words.js +7 -0
  42. package/dist/commands/prototype/prune.d.ts +16 -0
  43. package/dist/commands/prototype/prune.en.d.ts +9 -0
  44. package/dist/commands/prototype/prune.en.js +9 -0
  45. package/dist/commands/prototype/prune.es.d.ts +2 -0
  46. package/dist/commands/prototype/prune.es.js +9 -0
  47. package/dist/commands/prototype/prune.js +140 -0
  48. package/dist/commands/prototype/reopen-messages.d.ts +9 -0
  49. package/dist/commands/prototype/reopen-messages.js +19 -0
  50. package/dist/commands/prototype/report.d.ts +14 -0
  51. package/dist/commands/prototype/report.js +5 -1
  52. package/dist/commands/prototype/scene-layout.d.ts +17 -0
  53. package/dist/commands/prototype/scene-layout.js +57 -0
  54. package/dist/commands/prototype/scene-ready.js +8 -2
  55. package/dist/commands/prototype/scene.d.ts +15 -2
  56. package/dist/commands/prototype/scene.js +54 -42
  57. package/dist/commands/prototype/selector-answer.d.ts +43 -0
  58. package/dist/commands/prototype/selector-answer.js +73 -0
  59. package/dist/commands/prototype/selector-misses.d.ts +19 -0
  60. package/dist/commands/prototype/selector-misses.js +78 -0
  61. package/dist/commands/prototype/selector-prompt.d.ts +23 -0
  62. package/dist/commands/prototype/selector-prompt.js +32 -0
  63. package/dist/commands/prototype/selector-run.d.ts +13 -0
  64. package/dist/commands/prototype/selector-run.js +113 -0
  65. package/dist/commands/prototype/selector.d.ts +54 -0
  66. package/dist/commands/prototype/selector.js +96 -0
  67. package/dist/commands/prototype/snapshot-ancestor.js +2 -0
  68. package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
  69. package/dist/commands/prototype/snapshot-bundle.js +69 -7
  70. package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
  71. package/dist/commands/prototype/snapshot-check-files.js +41 -0
  72. package/dist/commands/prototype/snapshot-command.d.ts +2 -0
  73. package/dist/commands/prototype/snapshot-command.js +3 -0
  74. package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
  75. package/dist/commands/prototype/snapshot-completion.js +30 -2
  76. package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
  77. package/dist/commands/prototype/snapshot-dependencies.js +120 -14
  78. package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
  79. package/dist/commands/prototype/snapshot-hashes.js +28 -0
  80. package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
  81. package/dist/commands/prototype/snapshot-inputs.js +140 -197
  82. package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
  83. package/dist/commands/prototype/snapshot-matrix.js +95 -0
  84. package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
  85. package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
  86. package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
  87. package/dist/commands/prototype/snapshot-owners.js +12 -3
  88. package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
  89. package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
  90. package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
  91. package/dist/commands/prototype/snapshot-progress.js +54 -102
  92. package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
  93. package/dist/commands/prototype/snapshot-registry.js +121 -0
  94. package/dist/commands/prototype/snapshot-report.d.ts +4 -0
  95. package/dist/commands/prototype/snapshot-report.js +77 -12
  96. package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
  97. package/dist/commands/prototype/snapshot-requests.js +68 -30
  98. package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
  99. package/dist/commands/prototype/snapshot-reuse.js +17 -7
  100. package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
  101. package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
  102. package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
  103. package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
  104. package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
  105. package/dist/commands/prototype/snapshot-server-record.js +135 -0
  106. package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
  107. package/dist/commands/prototype/snapshot-servers.js +50 -2
  108. package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
  109. package/dist/commands/prototype/snapshot-setup.js +2 -1
  110. package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
  111. package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
  112. package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
  113. package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
  114. package/dist/commands/prototype/snapshot.d.ts +5 -0
  115. package/dist/commands/prototype/snapshot.js +72 -10
  116. package/dist/commands/prototype/version-commands.d.ts +4 -0
  117. package/dist/commands/prototype/version-commands.js +36 -8
  118. package/dist/commands/prototype/versions.d.ts +28 -2
  119. package/dist/commands/prototype/versions.js +25 -1
  120. package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
  121. package/dist/commands/prototype/vite-fs-path.js +15 -0
  122. package/dist/commands/remove-links.d.ts +6 -0
  123. package/dist/commands/remove-links.js +17 -0
  124. package/dist/commands/size-docs.d.ts +9 -0
  125. package/dist/commands/size-docs.en.d.ts +6 -0
  126. package/dist/commands/size-docs.en.js +6 -0
  127. package/dist/commands/size-docs.es.d.ts +2 -0
  128. package/dist/commands/size-docs.es.js +6 -0
  129. package/dist/commands/size-docs.js +28 -0
  130. package/dist/commands/size.d.ts +5 -2
  131. package/dist/commands/size.js +27 -9
  132. package/dist/commands/ui/approval-authority.d.ts +10 -2
  133. package/dist/commands/ui/approval-authority.js +1 -0
  134. package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
  135. package/dist/commands/ui/autopilot-ai-approve.js +68 -0
  136. package/dist/commands/ui/autopilot-loop.js +5 -6
  137. package/dist/commands/ui/autopilot-merge.js +3 -0
  138. package/dist/commands/ui/autopilot.en.d.ts +23 -0
  139. package/dist/commands/ui/autopilot.en.js +23 -0
  140. package/dist/commands/ui/autopilot.es.d.ts +23 -0
  141. package/dist/commands/ui/autopilot.es.js +23 -0
  142. package/dist/commands/ui/chat/find.d.ts +2 -0
  143. package/dist/commands/ui/chat/find.js +13 -0
  144. package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
  145. package/dist/commands/ui/chat/fresh-codex.js +175 -0
  146. package/dist/commands/ui/chat/fresh-critique.js +13 -5
  147. package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
  148. package/dist/commands/ui/chat/fresh-launch.js +67 -11
  149. package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
  150. package/dist/commands/ui/chat/fresh-prompts.js +2 -0
  151. package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
  152. package/dist/commands/ui/chat/fresh-secrets.js +172 -0
  153. package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
  154. package/dist/commands/ui/chat/fresh.en.js +2 -1
  155. package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
  156. package/dist/commands/ui/chat/fresh.es.js +2 -1
  157. package/dist/commands/ui/chat/worktree.js +25 -5
  158. package/dist/commands/ui/index.js +3 -0
  159. package/dist/commands/ui/loop-approve.d.ts +30 -1
  160. package/dist/commands/ui/loop-approve.js +2 -2
  161. package/dist/commands/ui/merge-route.js +3 -0
  162. package/dist/commands/ui/places-change.d.ts +4 -0
  163. package/dist/commands/ui/prototype-main.d.ts +4 -0
  164. package/dist/commands/ui/reopen-route.d.ts +117 -0
  165. package/dist/commands/ui/reopen-route.js +97 -0
  166. package/dist/commands/ui/save-route.d.ts +2 -0
  167. package/dist/commands/ui/save-route.js +4 -0
  168. package/dist/commands/ui/studio-routes.js +2 -0
  169. package/dist/commands/ui/studio-state.d.ts +33 -0
  170. package/dist/commands/ui/studio-versions.d.ts +24 -0
  171. package/dist/commands/ui/worktrees.d.ts +1 -1
  172. package/dist/commands/ui/worktrees.js +19 -3
  173. package/dist/commands/worktree-sweep.d.ts +45 -0
  174. package/dist/commands/worktree-sweep.js +188 -0
  175. package/dist/commands/worktrees-command.d.ts +32 -0
  176. package/dist/commands/worktrees-command.en.d.ts +25 -0
  177. package/dist/commands/worktrees-command.en.js +55 -0
  178. package/dist/commands/worktrees-command.js +96 -0
  179. package/dist/main.js +2 -0
  180. package/dist/ui/page.js +82 -82
  181. package/docs/PROTOTYPE.md +6 -3
  182. package/docs/WORKBENCH.md +11 -6
  183. package/package.json +11 -11
  184. package/skills/ape-critique/SKILL.md +41 -6
  185. package/skills/ape-design-system/SKILL.md +3 -0
  186. package/skills/ape-plan-change/SKILL.md +6 -0
  187. package/skills/ape-prototype/SKILL.md +8 -4
@@ -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 {};
@@ -4,6 +4,7 @@ import { mergingChange } from '../change-merge.js';
4
4
  import { fourAtATime } from '../change-screens.js';
5
5
  import { mainCommit } from '../main-ref.js';
6
6
  import { hostGit } from '../safe-git.js';
7
+ import { keptAfterSweep, linkedTrees } from '../worktree-sweep.js';
7
8
  import { autoChoiceFacts } from './autopilot-facts.js';
8
9
  import { mergeHeld, mergeHoldPathAsync } from './merge-hold.js';
9
10
  import { mergedBranches } from './merged-branches.js';
@@ -108,8 +109,8 @@ async function facts(root, { head, ...tree }, git, main, merged) {
108
109
  }
109
110
  }
110
111
  /** Never checks out a branch or writes HEAD/the index. The injectable Git runner also tests old Git. */
111
- export async function listWorktrees(root, git = gitAt(root)) {
112
- const listed = trees(await git(['worktree', 'list', '--porcelain', '-z']));
112
+ export async function listWorktrees(root, git = gitAt(root), listing) {
113
+ const listed = trees(listing ?? (await git(['worktree', 'list', '--porcelain', '-z'])));
113
114
  if (!listed.length)
114
115
  return [];
115
116
  const [main, supported] = await Promise.all([
@@ -119,10 +120,24 @@ export async function listWorktrees(root, git = gitAt(root)) {
119
120
  const merged = main && supported ? await mergedBranches(main, git).catch(() => undefined) : undefined;
120
121
  return fourAtATime(listed, (tree) => facts(root, tree, git, main, merged));
121
122
  }
123
+ /** A merged worktree still here says why the last sweep kept it. */
124
+ function withKept(root, tree) {
125
+ const kept = tree.merge === 'merged' ? keptAfterSweep(root, tree.path) : undefined;
126
+ return kept === 'inUse' || kept === 'unknown' ? { ...tree, kept } : tree;
127
+ }
128
+ /** Every linked worktree that is no change's, by path and branch, from the listing already read. */
129
+ function otherWorktrees(listing) {
130
+ return linkedTrees(listing)
131
+ .filter((tree) => !tree.change)
132
+ .map(({ path, branch }) => ({ path, ...(branch ? { branch } : {}) }));
133
+ }
122
134
  /** Only changes with an active, unmerged worktree take part in clash warnings. */
123
135
  export async function workFacts(root, hostedAuthority = false) {
124
136
  try {
125
- const worktrees = await listWorktrees(root);
137
+ // One listing serves both readers, so a refresh reads it no more often than before.
138
+ const git = gitAt(root);
139
+ const listing = await git(['worktree', 'list', '--porcelain', '-z']);
140
+ const worktrees = (await listWorktrees(root, git, listing)).map((tree) => withKept(root, tree));
126
141
  const changes = (await readChanges(root)).changes;
127
142
  const active = worktrees.filter((tree) => tree.merge !== 'merged');
128
143
  const inFlight = await Promise.all(active.map(async (tree) => {
@@ -141,6 +156,7 @@ export async function workFacts(root, hostedAuthority = false) {
141
156
  worktrees,
142
157
  clashes: warnings,
143
158
  merging: await mergingChange(root),
159
+ others: otherWorktrees(listing),
144
160
  autopilotMergeHeld: mergeHeld(await mergeHoldPathAsync(root)),
145
161
  ...(autopilot?.length ? { autopilot } : {}),
146
162
  };
@@ -0,0 +1,45 @@
1
+ import { type MergeGit } from './change-merge.ts';
2
+ /** Why a worktree stays. */
3
+ export type Kept = 'unmerged' | 'dirty' | 'inUse' | 'unknown';
4
+ export interface LinkedTree {
5
+ path: string;
6
+ /** Absent for a detached HEAD. */
7
+ branch?: string;
8
+ head?: string;
9
+ /** The change id when the branch is a change's (`change/C-001-...`). */
10
+ change?: string;
11
+ locked?: true;
12
+ prunable?: true;
13
+ }
14
+ export interface TreeFact extends LinkedTree {
15
+ /** `merged`: merged, clean and unused, so it may go; `removed` once it went. */
16
+ state: 'merged' | 'removed' | Kept;
17
+ }
18
+ /** Every linked worktree (`git worktree list --porcelain -z`), without the main working tree. */
19
+ export declare function linkedTrees(porcelain: string): LinkedTree[];
20
+ /** Which of these folders something is using; throwing means "can't tell", so all are in use. */
21
+ export type Holders = (root: string, paths: readonly string[]) => Promise<Set<string>>;
22
+ /** The folders of `paths` a studio turn holds. */
23
+ export declare function studioHeld(root: string, paths: readonly string[]): Promise<Set<string>>;
24
+ /** The studio's turns, then every process's command line and (where readable) working folder. */
25
+ export declare const defaultHolders: Holders;
26
+ /** Each linked worktree's state, read only. Never throws; what cannot be read is `unknown`. */
27
+ export declare function treeFacts(root: string, { git, holders }?: {
28
+ git?: MergeGit | undefined;
29
+ holders?: Holders | undefined;
30
+ }): Promise<TreeFact[]>;
31
+ /** Remove each `merged` fact's worktree with the safe removal; the rest are returned unchanged. */
32
+ export declare function removeMerged(root: string, facts: readonly TreeFact[], tools?: {
33
+ git: MergeGit;
34
+ }): Promise<TreeFact[]>;
35
+ /** The last sweep's reason for keeping a merged worktree (in use, or its removal failed). */
36
+ export declare const keptAfterSweep: (root: string, path: string) => Kept | undefined;
37
+ /**
38
+ * The studio's sweep of its own change worktrees (`.ape/worktrees/<change>`): each merged, clean,
39
+ * unused one is removed; the rest stay, and why is kept for the Work page. One at a time per root.
40
+ */
41
+ export declare function sweepStudio(root: string, holders?: Holders): Promise<TreeFact[]>;
42
+ /** A running studio sweeps when it starts and after each merge (`sweepAfterMerge`). */
43
+ export declare function startSweeps(root: string): void;
44
+ /** After a merge went through: sweep, when this process runs the studio for `root`. */
45
+ export declare function sweepAfterMerge(root: string): void;