@aragon-agent/cli 0.6.35 → 0.6.37

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 (146) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +3173 -3071
  3. package/dist/agent/agent-mode.d.ts +20 -4
  4. package/dist/agent/agent-mode.js +20 -4
  5. package/dist/agent/controller.d.ts +38 -3
  6. package/dist/agent/controller.js +64 -4
  7. package/dist/agent/headless.js +31 -0
  8. package/dist/agent/reducer.d.ts +13 -2
  9. package/dist/agent/reducer.js +1 -0
  10. package/dist/cli.js +12 -0
  11. package/dist/commands/agents-command.d.ts +15 -0
  12. package/dist/commands/agents-command.js +27 -0
  13. package/dist/commands/builtins.js +131 -4
  14. package/dist/commands/perf.d.ts +11 -0
  15. package/dist/commands/perf.js +2 -1
  16. package/dist/commands/registry.d.ts +14 -0
  17. package/dist/config/app-paths.d.ts +15 -0
  18. package/dist/config/app-paths.js +33 -2
  19. package/dist/config/env.d.ts +4 -1
  20. package/dist/config/env.js +28 -2
  21. package/dist/config/load.d.ts +10 -0
  22. package/dist/config/load.js +8 -1
  23. package/dist/config/schema.d.ts +68 -0
  24. package/dist/config/schema.js +39 -0
  25. package/dist/config/store.js +12 -1
  26. package/dist/config/ui-state.d.ts +18 -0
  27. package/dist/config/ui-state.js +9 -0
  28. package/dist/exec/events.d.ts +25 -0
  29. package/dist/exec/events.js +4 -0
  30. package/dist/exec/index.js +16 -1
  31. package/dist/exec/runner.js +10 -0
  32. package/dist/proc/limits.d.ts +16 -0
  33. package/dist/proc/limits.js +16 -0
  34. package/dist/proc/supervisor.d.ts +20 -1
  35. package/dist/proc/supervisor.js +42 -14
  36. package/dist/prompts/command.d.ts +34 -0
  37. package/dist/prompts/command.js +237 -0
  38. package/dist/prompts/copy.d.ts +89 -0
  39. package/dist/prompts/copy.js +131 -0
  40. package/dist/prompts/fill.d.ts +51 -0
  41. package/dist/prompts/fill.js +46 -0
  42. package/dist/prompts/limits.d.ts +53 -0
  43. package/dist/prompts/limits.js +53 -0
  44. package/dist/prompts/normalize.d.ts +53 -0
  45. package/dist/prompts/normalize.js +190 -0
  46. package/dist/prompts/resolve.d.ts +31 -0
  47. package/dist/prompts/resolve.js +60 -0
  48. package/dist/prompts/search.d.ts +58 -0
  49. package/dist/prompts/search.js +146 -0
  50. package/dist/prompts/store.d.ts +86 -0
  51. package/dist/prompts/store.js +453 -0
  52. package/dist/prompts/types.d.ts +204 -0
  53. package/dist/prompts/types.js +13 -0
  54. package/dist/session/checkpoint.d.ts +8 -1
  55. package/dist/session/checkpoint.js +6 -0
  56. package/dist/session/persist.d.ts +19 -1
  57. package/dist/session/persist.js +13 -1
  58. package/dist/session/startup-session.d.ts +7 -2
  59. package/dist/session/startup-session.js +5 -2
  60. package/dist/session/store.js +3 -0
  61. package/dist/session/validate-session.js +64 -1
  62. package/dist/team/limits.d.ts +25 -0
  63. package/dist/team/limits.js +26 -0
  64. package/dist/team/runtime.js +27 -2
  65. package/dist/team/settled.d.ts +57 -0
  66. package/dist/team/settled.js +87 -0
  67. package/dist/team/subagent.js +48 -2
  68. package/dist/team/timeline.d.ts +74 -0
  69. package/dist/team/timeline.js +101 -0
  70. package/dist/team/types.d.ts +24 -1
  71. package/dist/todo/acceptance.d.ts +120 -0
  72. package/dist/todo/acceptance.js +399 -0
  73. package/dist/todo/follow-through.d.ts +48 -23
  74. package/dist/todo/follow-through.js +110 -44
  75. package/dist/todo/limits.d.ts +62 -1
  76. package/dist/todo/limits.js +62 -1
  77. package/dist/todo/panel-rows.d.ts +29 -39
  78. package/dist/todo/panel-rows.js +37 -83
  79. package/dist/todo/plan-sections.d.ts +60 -0
  80. package/dist/todo/plan-sections.js +108 -0
  81. package/dist/todo/prompt.d.ts +17 -12
  82. package/dist/todo/prompt.js +59 -40
  83. package/dist/todo/row-window.d.ts +51 -0
  84. package/dist/todo/row-window.js +107 -0
  85. package/dist/todo/store.d.ts +139 -31
  86. package/dist/todo/store.js +271 -73
  87. package/dist/todo/todo-tool.d.ts +33 -8
  88. package/dist/todo/todo-tool.js +186 -30
  89. package/dist/todo/types.d.ts +58 -0
  90. package/dist/ui/App.js +310 -46
  91. package/dist/ui/Composer.d.ts +6 -2
  92. package/dist/ui/Composer.js +2 -2
  93. package/dist/ui/Header.d.ts +9 -1
  94. package/dist/ui/Header.js +2 -2
  95. package/dist/ui/PromptInput.d.ts +21 -1
  96. package/dist/ui/PromptInput.js +21 -1
  97. package/dist/ui/ScrollbackShell.d.ts +19 -19
  98. package/dist/ui/ScrollbackShell.js +8 -1
  99. package/dist/ui/StatusBar.d.ts +5 -0
  100. package/dist/ui/StatusBar.js +1 -0
  101. package/dist/ui/TeamPanel.d.ts +26 -44
  102. package/dist/ui/TeamPanel.js +46 -135
  103. package/dist/ui/TodoPanel.d.ts +17 -14
  104. package/dist/ui/TodoPanel.js +146 -38
  105. package/dist/ui/Transcript.js +1 -1
  106. package/dist/ui/composer-input.d.ts +10 -0
  107. package/dist/ui/composer-input.js +57 -24
  108. package/dist/ui/entries/TodoCard.d.ts +26 -11
  109. package/dist/ui/entries/TodoCard.js +56 -15
  110. package/dist/ui/glyphs.d.ts +19 -0
  111. package/dist/ui/glyphs.js +4 -0
  112. package/dist/ui/layout/agents-board.d.ts +102 -0
  113. package/dist/ui/layout/agents-board.js +389 -0
  114. package/dist/ui/layout/cells.d.ts +61 -0
  115. package/dist/ui/layout/cells.js +156 -0
  116. package/dist/ui/layout/header-hints.d.ts +13 -3
  117. package/dist/ui/layout/header-hints.js +48 -14
  118. package/dist/ui/layout/status-detail-layout.js +9 -0
  119. package/dist/ui/layout/status-layout.d.ts +13 -0
  120. package/dist/ui/layout/team-row.d.ts +139 -0
  121. package/dist/ui/layout/team-row.js +246 -0
  122. package/dist/ui/layout/todo-layout.d.ts +38 -0
  123. package/dist/ui/layout/todo-layout.js +75 -0
  124. package/dist/ui/layout/virtual-window.js +23 -3
  125. package/dist/ui/overlays/AgentsBoardOverlay.d.ts +57 -0
  126. package/dist/ui/overlays/AgentsBoardOverlay.js +183 -0
  127. package/dist/ui/overlays/HelpOverlay.js +17 -2
  128. package/dist/ui/overlays/PromptEditorPage.d.ts +48 -0
  129. package/dist/ui/overlays/PromptEditorPage.js +227 -0
  130. package/dist/ui/overlays/PromptLibraryOverlay.d.ts +37 -0
  131. package/dist/ui/overlays/PromptLibraryOverlay.js +191 -0
  132. package/dist/ui/overlays/PromptPicker.d.ts +36 -0
  133. package/dist/ui/overlays/PromptPicker.js +129 -0
  134. package/dist/ui/overlays/PromptTextArea.d.ts +86 -0
  135. package/dist/ui/overlays/PromptTextArea.js +141 -0
  136. package/dist/ui/overlays/prompt-library-state.d.ts +162 -0
  137. package/dist/ui/overlays/prompt-library-state.js +335 -0
  138. package/dist/ui/overlays/prompt-picker-state.d.ts +71 -0
  139. package/dist/ui/overlays/prompt-picker-state.js +98 -0
  140. package/dist/ui/scrollback/band.js +14 -1
  141. package/dist/ui/team-status.d.ts +25 -0
  142. package/dist/ui/team-status.js +31 -3
  143. package/dist/ui/use-startup-notices.d.ts +35 -1
  144. package/dist/ui/use-startup-notices.js +29 -2
  145. package/dist/ui/use-wheel-routing.js +9 -1
  146. package/package.json +2 -2
@@ -0,0 +1,335 @@
1
+ /**
2
+ * The prompt manager's state machine and view models (quick-prompt-library §4.4).
3
+ *
4
+ * ASCII ONLY - `src/ui/**` is inside `glyphs.test.ts::inScope`. Every sentence the
5
+ * user reads comes from `prompts/copy.ts`; nothing in this file may hold a literal
6
+ * non-ASCII byte.
7
+ *
8
+ * WHY A PURE REDUCER AND NOT `useState` INSIDE THE COMPONENT: the page stack has two
9
+ * transitions that are easy to get wrong and impossible to see on screen - "the
10
+ * second Esc discards, the first does not" and "the intent is consumed exactly
11
+ * once" - and both are assertions, not screenshots. Everything below can be driven
12
+ * from a test with no Ink mounted.
13
+ */
14
+ import { PROMPT_LIMITS } from '../../prompts/limits.js';
15
+ import { parsePromptTags, validatePromptDraft } from '../../prompts/store.js';
16
+ // The list's read-only preview is the ONE place `wrapToRows` belongs: it is a prose
17
+ // wrapper, so it would destroy the caret-to-cell mapping in an editable field
18
+ // (D-11), and there is no caret here.
19
+ import { wrapToRows } from '../layout/wrap-rows.js';
20
+ /** The six rows `Tab` cycles on the editor page, in visual order. */
21
+ export const PROMPT_EDITOR_FIELDS = [
22
+ 'title', 'content', 'description', 'tags', 'save', 'cancel',
23
+ ];
24
+ /** A new, empty draft. `id: null` is what makes `Save` a create rather than an update. */
25
+ export const EMPTY_PROMPT_DRAFT = {
26
+ id: null,
27
+ title: '',
28
+ content: '',
29
+ description: '',
30
+ tags: '',
31
+ favorite: false,
32
+ };
33
+ export const INITIAL_PROMPT_LIBRARY_STATE = {
34
+ page: 'list',
35
+ index: 0,
36
+ focusId: null,
37
+ draft: EMPTY_PROMPT_DRAFT,
38
+ baseline: null,
39
+ escArmed: false,
40
+ pendingDeleteId: null,
41
+ error: null,
42
+ errorField: null,
43
+ consumedIntentNonce: 0,
44
+ };
45
+ /** The editable projection of a stored entry. */
46
+ export function draftFromEntry(entry) {
47
+ return {
48
+ id: entry.id,
49
+ title: entry.title,
50
+ content: entry.content,
51
+ description: entry.description ?? '',
52
+ tags: (entry.tags ?? []).join(' '),
53
+ favorite: entry.favorite === true,
54
+ };
55
+ }
56
+ /** A create draft seeded from a command (`/prompts add title :: body`). */
57
+ export function seededDraft(seed) {
58
+ return {
59
+ ...EMPTY_PROMPT_DRAFT,
60
+ title: seed?.title ?? '',
61
+ content: seed?.content ?? '',
62
+ };
63
+ }
64
+ /** Structural equality is enough: every field is a string or a boolean. */
65
+ export function draftIsDirty(draft, baseline) {
66
+ if (baseline === null) {
67
+ return draft.title.length > 0 || draft.content.length > 0
68
+ || draft.description.length > 0 || draft.tags.length > 0;
69
+ }
70
+ return draft.title !== baseline.title || draft.content !== baseline.content
71
+ || draft.description !== baseline.description || draft.tags !== baseline.tags
72
+ || draft.favorite !== baseline.favorite;
73
+ }
74
+ /**
75
+ * Validate a draft and turn it into what the store accepts (D-12).
76
+ *
77
+ * THE VALIDATOR IS `store.ts`'S, not a second copy here: the sentence the editor
78
+ * shows and the rule the write applies have to be the same rule, or a user can be
79
+ * told a title is fine by the form and refused by the store.
80
+ */
81
+ export function finishPromptEditor(draft) {
82
+ return validatePromptDraft({
83
+ title: draft.title,
84
+ content: draft.content,
85
+ description: draft.description,
86
+ tags: parsePromptTags(draft.tags),
87
+ favorite: draft.favorite,
88
+ });
89
+ }
90
+ /** Index of the first focusable row, for a refusal that named a field. */
91
+ export function fieldIndex(field) {
92
+ if (field === null)
93
+ return 0;
94
+ const at = PROMPT_EDITOR_FIELDS.indexOf(field);
95
+ return at < 0 ? 0 : at;
96
+ }
97
+ function enterEditor(state, draft, baseline) {
98
+ return {
99
+ ...state,
100
+ page: 'editor',
101
+ draft,
102
+ baseline,
103
+ escArmed: false,
104
+ error: null,
105
+ errorField: null,
106
+ };
107
+ }
108
+ /**
109
+ * The reducer.
110
+ *
111
+ * `init` is the ONLY action that can jump straight to the editor or the delete page:
112
+ * that is what makes `/prompts edit 2` land where it should (D-21). The intent's
113
+ * nonce is stored as `consumedIntentNonce` by the component before dispatching, so a
114
+ * replayed intent is a no-op at the component, not a second edit here.
115
+ */
116
+ export function promptLibraryReducer(state, action, library) {
117
+ switch (action.type) {
118
+ case 'init': {
119
+ if (action.nonce <= state.consumedIntentNonce)
120
+ return state;
121
+ const consumed = { ...state, consumedIntentNonce: action.nonce };
122
+ const entry = action.entry;
123
+ if (entry.kind === 'create') {
124
+ return enterEditor(consumed, seededDraft(entry.seed), null);
125
+ }
126
+ if (entry.kind === 'edit') {
127
+ const found = action.library.prompts.find((prompt) => prompt.id === entry.id);
128
+ if (!found)
129
+ return { ...consumed, page: 'list', focusId: null };
130
+ const draft = draftFromEntry(found);
131
+ return enterEditor(consumed, draft, { ...draft });
132
+ }
133
+ if (entry.kind === 'delete') {
134
+ const found = action.library.prompts.find((prompt) => prompt.id === entry.id);
135
+ if (!found)
136
+ return { ...consumed, page: 'list', focusId: null };
137
+ return { ...consumed, page: 'delete', pendingDeleteId: entry.id };
138
+ }
139
+ return { ...consumed, page: 'list', focusId: entry.focusId ?? null, index: 0 };
140
+ }
141
+ case 'list':
142
+ return {
143
+ ...state,
144
+ page: 'list',
145
+ focusId: action.focusId ?? state.focusId,
146
+ escArmed: false,
147
+ pendingDeleteId: null,
148
+ error: null,
149
+ errorField: null,
150
+ };
151
+ case 'focus':
152
+ return { ...state, index: Math.max(0, Math.floor(action.index)) };
153
+ case 'create':
154
+ return enterEditor(state, seededDraft(action.seed), null);
155
+ case 'edit': {
156
+ const found = action.library.prompts.find((prompt) => prompt.id === action.id);
157
+ if (!found)
158
+ return { ...state, page: 'list', error: 'not_found' };
159
+ const draft = draftFromEntry(found);
160
+ return enterEditor(state, draft, { ...draft });
161
+ }
162
+ case 'delete':
163
+ return { ...state, page: 'delete', pendingDeleteId: action.id };
164
+ case 'draft':
165
+ return { ...state, draft: { ...state.draft, ...action.patch }, escArmed: false };
166
+ case 'commit':
167
+ return {
168
+ ...state,
169
+ page: 'list',
170
+ focusId: action.id,
171
+ baseline: null,
172
+ escArmed: false,
173
+ error: null,
174
+ errorField: null,
175
+ draft: EMPTY_PROMPT_DRAFT,
176
+ };
177
+ case 'failed':
178
+ return { ...state, error: action.code, errorField: action.field ?? null };
179
+ case 'esc': {
180
+ if (state.page !== 'editor')
181
+ return { ...state, page: 'list', pendingDeleteId: null };
182
+ // A CLEAN EDITOR CLOSES ON THE FIRST Esc. A dirty one asks once, and the answer
183
+ // has to be a second Esc rather than a modal: losing a body typed into a
184
+ // multi-line field because one key was pressed is the failure this guards.
185
+ if (!draftIsDirty(state.draft, state.baseline)) {
186
+ return { ...state, page: 'list', baseline: null, draft: EMPTY_PROMPT_DRAFT };
187
+ }
188
+ if (state.escArmed) {
189
+ return {
190
+ ...state, page: 'list', baseline: null, escArmed: false, draft: EMPTY_PROMPT_DRAFT,
191
+ };
192
+ }
193
+ return { ...state, escArmed: true };
194
+ }
195
+ case 'cancelled':
196
+ return { ...state, page: 'list', baseline: null, escArmed: false, draft: EMPTY_PROMPT_DRAFT };
197
+ }
198
+ }
199
+ /** `1.2k` for anything a fixed-width column cannot show in full. */
200
+ export function formatCount(count) {
201
+ if (count < 1000)
202
+ return String(count);
203
+ return `${(count / 1000).toFixed(1)}k`;
204
+ }
205
+ /** `3d ago` / `2h ago` / `just now`. Deliberately coarse: it is a hint, not a clock. */
206
+ export function formatAgo(timestamp, now) {
207
+ if (timestamp === undefined || timestamp <= 0)
208
+ return 'never';
209
+ const seconds = Math.max(0, Math.floor((now - timestamp) / 1000));
210
+ if (seconds < 60)
211
+ return 'just now';
212
+ const minutes = Math.floor(seconds / 60);
213
+ if (minutes < 60)
214
+ return `${minutes}m ago`;
215
+ const hours = Math.floor(minutes / 60);
216
+ if (hours < 24)
217
+ return `${hours}h ago`;
218
+ return `${Math.floor(hours / 24)}d ago`;
219
+ }
220
+ /**
221
+ * The list, one row per entry, in the library's own order.
222
+ *
223
+ * DUPLICATE TITLES GET AN ID PREFIX (I-2), exactly as `kit-picker-state.ts` does for
224
+ * duplicate kit names: two rows reading the same words make `Enter` a coin flip.
225
+ */
226
+ export function libraryRows(library) {
227
+ const seen = new Map();
228
+ for (const prompt of library.prompts) {
229
+ seen.set(prompt.title, (seen.get(prompt.title) ?? 0) + 1);
230
+ }
231
+ return library.prompts.map((prompt) => {
232
+ const duplicate = (seen.get(prompt.title) ?? 0) > 1;
233
+ const identity = duplicate ? `#${prompt.id.slice(0, 8)} ` : '';
234
+ const marks = [];
235
+ if (prompt.favorite === true)
236
+ marks.push('[fav]');
237
+ const tags = prompt.tags ?? [];
238
+ for (const tag of tags.slice(0, 2))
239
+ marks.push(`#${tag}`);
240
+ if (tags.length > 2)
241
+ marks.push(`+#${tags.length - 2}`);
242
+ marks.push(`${formatCount([...prompt.content].length)}c`);
243
+ if (prompt.useCount > 0)
244
+ marks.push(`${formatCount(prompt.useCount)}x`);
245
+ return {
246
+ id: prompt.id,
247
+ label: `${identity}${prompt.title} ${marks.join(' ')}`,
248
+ markers: {
249
+ favorite: prompt.favorite === true,
250
+ hasTags: tags.length > 0,
251
+ uses: prompt.useCount,
252
+ },
253
+ chars: [...prompt.content].length,
254
+ };
255
+ });
256
+ }
257
+ /**
258
+ * The detail block under the list: at most `detailMaxLines` rows, fixed shape.
259
+ *
260
+ * FIXED, because `OverlayFrame`'s window is shared with the list (D-16): a body that
261
+ * participated in row height would squeeze six prompts into two visible rows. The
262
+ * full text has exactly one home, and it is the editor.
263
+ */
264
+ export function libraryDetail(row, library, cols, now = Date.now()) {
265
+ if (!row)
266
+ return [];
267
+ const prompt = library.prompts.find((entry) => entry.id === row.id);
268
+ if (!prompt)
269
+ return [];
270
+ const tags = (prompt.tags ?? []).map((tag) => `#${tag}`).join(' ');
271
+ const facts = [
272
+ `${formatCount(row.chars)} chars`,
273
+ `${prompt.useCount} uses`,
274
+ formatAgo(prompt.lastUsedAt, now),
275
+ prompt.favorite === true ? '[fav]' : '',
276
+ ].filter(Boolean).join(' ');
277
+ const body = prompt.content.split('\n').slice(0, PROMPT_LIMITS.detailPreviewLines).join('\n');
278
+ const preview = wrapToRows(body, Math.max(8, cols - 8))
279
+ .slice(0, PROMPT_LIMITS.detailPreviewLines);
280
+ return [prompt.title, ...(tags.length > 0 ? [tags] : []), facts, ...preview]
281
+ .slice(0, PROMPT_LIMITS.detailMaxLines);
282
+ }
283
+ /**
284
+ * The list page's footer.
285
+ *
286
+ * THE LAST CLAUSE IS ALWAYS THE WAY OUT (§9.5): a narrow terminal clips from the
287
+ * left, so the reader always keeps `Esc close`. The reorder keys are named here
288
+ * rather than in the row above it because they are the one affordance a user cannot
289
+ * discover by pressing a key they already know.
290
+ */
291
+ export function libraryHint(state, count) {
292
+ if (state.page === 'delete')
293
+ return 'Enter delete | Esc cancel';
294
+ if (state.page === 'editor')
295
+ return editorHint(state);
296
+ if (count === 0)
297
+ return 'a create your first prompt | Esc close';
298
+ return 'Enter edit | a new | d delete | f favorite | ^up/^dn reorder | Esc close';
299
+ }
300
+ function editorHint(state) {
301
+ if (state.escArmed)
302
+ return 'Esc again discards the draft | Tab next field';
303
+ return 'Tab next field | Ctrl+S save | Esc close';
304
+ }
305
+ /** The delete page's four lines: what it is, how big, and what it costs. */
306
+ export function deleteDetail(library, id) {
307
+ const prompt = library.prompts.find((entry) => entry.id === id);
308
+ if (!prompt)
309
+ return [];
310
+ return [
311
+ prompt.title,
312
+ `${[...prompt.content].length} chars, ${prompt.content.split('\n').length} lines`,
313
+ 'This cannot be undone.',
314
+ 'Enter or y deletes it; Esc or n keeps it.',
315
+ ];
316
+ }
317
+ /**
318
+ * The draft as the store accepts it.
319
+ *
320
+ * THE TAGS FIELD IS PARSED HERE, ONCE, and nowhere else: the editor edits a raw
321
+ * string, the store validates a `string[]`, and a second parser between them is how
322
+ * `a,b` and `a b` come to mean different things depending on which surface saved it.
323
+ */
324
+ export function draftToInput(draft) {
325
+ const input = {
326
+ title: draft.title,
327
+ content: draft.content,
328
+ tags: parsePromptTags(draft.tags),
329
+ favorite: draft.favorite,
330
+ };
331
+ const description = draft.description.trim();
332
+ if (description.length > 0)
333
+ input.description = description;
334
+ return input;
335
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The prompt picker's view model (quick-prompt-library §4.5).
3
+ *
4
+ * ASCII ONLY - `src/ui/**` is inside `glyphs.test.ts::inScope`.
5
+ *
6
+ * THE ROWS ARE COMPUTED OUTSIDE THE COMPONENT for the reason `kit-picker-state.ts`
7
+ * records one surface over: the same library is rendered by two overlays and by
8
+ * `/prompts list`, and three independent row builders is how "the manager says four
9
+ * entries and the picker says five" becomes possible without a single failing test.
10
+ */
11
+ import type { PromptLibrary, PromptSortView } from '../../prompts/types.js';
12
+ export interface PromptPickerRow {
13
+ id: string;
14
+ /** 1-based position in the CURRENT view, i.e. the number `1`-`9` addresses. */
15
+ index: number;
16
+ title: string;
17
+ tags: string[];
18
+ favorite: boolean;
19
+ }
20
+ export interface PromptPickerInput {
21
+ library: PromptLibrary;
22
+ query: string;
23
+ view: PromptSortView;
24
+ }
25
+ /**
26
+ * Filter the library and number the result.
27
+ *
28
+ * THE VIEW IS APPLIED FIRST, THEN THE FILTER: searching inside `recent` must return
29
+ * the recent order, not the manual one. Reversing the two would make `Ctrl+S` appear
30
+ * to do nothing whenever a query is active - which is exactly when the user is
31
+ * looking at the footer to see whether it worked.
32
+ */
33
+ export declare function pickerRows(input: PromptPickerInput): PromptPickerRow[];
34
+ /**
35
+ * The block under the list: at most four rows, and never the whole body.
36
+ *
37
+ * The picker exists to CHOOSE. The full text belongs to the editor, and printing it
38
+ * here would push the chosen row off the frame that has to show it.
39
+ */
40
+ export declare function pickerDetail(row: PromptPickerRow | undefined, library: PromptLibrary, now?: number): string[];
41
+ /**
42
+ * The empty-library guidance (AC-23).
43
+ *
44
+ * IT NAMES TWO WAYS OUT, because the picker is reachable from two directions: the
45
+ * user who typed `/prompts` on an empty library can press `a` here, and the user who
46
+ * does not want to type can press `Ctrl+P` later. Naming only one of them leaves the
47
+ * other audience pressing a key that does nothing.
48
+ */
49
+ export declare const NO_PROMPTS_HINT = "No prompts yet. Press Ctrl+P to create one, or a to add one here.";
50
+ /**
51
+ * The footer, ordered by WHICH PATH SURVIVES ON THE WORST TERMINAL (§9.11).
52
+ *
53
+ * `Enter fill` comes before `^Enter fill & send` because a terminal without keyboard
54
+ * enhancement delivers `Ctrl+Enter` as a plain `Enter`: the reader who works left to
55
+ * right must meet the path that always works first. `tab manage` sits after the two
56
+ * fill actions for the same reason - it is navigation, not the point of the screen.
57
+ */
58
+ export declare function pickerHint(input: {
59
+ count: number;
60
+ query: string;
61
+ view: PromptSortView;
62
+ }): string;
63
+ /**
64
+ * The `1`-`9` shortcut, or `null`.
65
+ *
66
+ * A DIGIT IS ONLY A SHORTCUT WHILE THE QUERY IS EMPTY. Otherwise `3` is the third
67
+ * character of what the user is searching for, and stealing it would make numeric
68
+ * queries impossible to type - so the guard is the emptiness of the query, not the
69
+ * shape of the key.
70
+ */
71
+ export declare function pickerDigitTarget(rows: readonly PromptPickerRow[], input: string): string | null;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The prompt picker's view model (quick-prompt-library §4.5).
3
+ *
4
+ * ASCII ONLY - `src/ui/**` is inside `glyphs.test.ts::inScope`.
5
+ *
6
+ * THE ROWS ARE COMPUTED OUTSIDE THE COMPONENT for the reason `kit-picker-state.ts`
7
+ * records one surface over: the same library is rendered by two overlays and by
8
+ * `/prompts list`, and three independent row builders is how "the manager says four
9
+ * entries and the picker says five" becomes possible without a single failing test.
10
+ */
11
+ import { PROMPT_PICKER_LIMITS } from '../../prompts/limits.js';
12
+ import { searchPrompts, viewOrder } from '../../prompts/search.js';
13
+ import { formatAgo, formatCount } from './prompt-library-state.js';
14
+ /**
15
+ * Filter the library and number the result.
16
+ *
17
+ * THE VIEW IS APPLIED FIRST, THEN THE FILTER: searching inside `recent` must return
18
+ * the recent order, not the manual one. Reversing the two would make `Ctrl+S` appear
19
+ * to do nothing whenever a query is active - which is exactly when the user is
20
+ * looking at the footer to see whether it worked.
21
+ */
22
+ export function pickerRows(input) {
23
+ const ordered = viewOrder(input.library.prompts, input.view);
24
+ return searchPrompts(ordered, input.query).map(({ prompt }, at) => ({
25
+ id: prompt.id,
26
+ index: at + 1,
27
+ title: prompt.title,
28
+ tags: prompt.tags ?? [],
29
+ favorite: prompt.favorite === true,
30
+ }));
31
+ }
32
+ /**
33
+ * The block under the list: at most four rows, and never the whole body.
34
+ *
35
+ * The picker exists to CHOOSE. The full text belongs to the editor, and printing it
36
+ * here would push the chosen row off the frame that has to show it.
37
+ */
38
+ export function pickerDetail(row, library, now = Date.now()) {
39
+ if (!row)
40
+ return [];
41
+ const prompt = library.prompts.find((entry) => entry.id === row.id);
42
+ if (!prompt)
43
+ return [];
44
+ const lines = [
45
+ `${formatCount([...prompt.content].length)} chars, `
46
+ + `${prompt.content.split('\n').length} lines, ${formatAgo(prompt.lastUsedAt, now)}`,
47
+ ];
48
+ if ((prompt.tags ?? []).length > 0)
49
+ lines.push((prompt.tags ?? []).map((t) => `#${t}`).join(' '));
50
+ const firstLine = prompt.content.split('\n')[0] ?? '';
51
+ if (firstLine.length > 0)
52
+ lines.push(firstLine);
53
+ if (prompt.description !== undefined)
54
+ lines.push(prompt.description);
55
+ return lines.slice(0, PROMPT_PICKER_LIMITS.detailMaxLines);
56
+ }
57
+ /**
58
+ * The empty-library guidance (AC-23).
59
+ *
60
+ * IT NAMES TWO WAYS OUT, because the picker is reachable from two directions: the
61
+ * user who typed `/prompts` on an empty library can press `a` here, and the user who
62
+ * does not want to type can press `Ctrl+P` later. Naming only one of them leaves the
63
+ * other audience pressing a key that does nothing.
64
+ */
65
+ export const NO_PROMPTS_HINT = 'No prompts yet. Press Ctrl+P to create one, or a to add one here.';
66
+ /**
67
+ * The footer, ordered by WHICH PATH SURVIVES ON THE WORST TERMINAL (§9.11).
68
+ *
69
+ * `Enter fill` comes before `^Enter fill & send` because a terminal without keyboard
70
+ * enhancement delivers `Ctrl+Enter` as a plain `Enter`: the reader who works left to
71
+ * right must meet the path that always works first. `tab manage` sits after the two
72
+ * fill actions for the same reason - it is navigation, not the point of the screen.
73
+ */
74
+ export function pickerHint(input) {
75
+ if (input.count === 0) {
76
+ return input.query.length > 0
77
+ ? 'No match | Backspace to widen | Esc close'
78
+ : `${NO_PROMPTS_HINT} Esc close`;
79
+ }
80
+ return 'Enter fill | ^Enter fill & send | 1-9 pick | '
81
+ + `^S sort: ${input.view} | tab manage | Esc close`;
82
+ }
83
+ /**
84
+ * The `1`-`9` shortcut, or `null`.
85
+ *
86
+ * A DIGIT IS ONLY A SHORTCUT WHILE THE QUERY IS EMPTY. Otherwise `3` is the third
87
+ * character of what the user is searching for, and stealing it would make numeric
88
+ * queries impossible to type - so the guard is the emptiness of the query, not the
89
+ * shape of the key.
90
+ */
91
+ export function pickerDigitTarget(rows, input) {
92
+ if (input.length !== 1)
93
+ return null;
94
+ const digit = input.charCodeAt(0) - 48;
95
+ if (digit < 1 || digit > PROMPT_PICKER_LIMITS.quickDigits)
96
+ return null;
97
+ return rows[digit - 1]?.id ?? null;
98
+ }
@@ -109,7 +109,20 @@ export function buildLiveBand(input) {
109
109
  // now gets the pool too. The branch stays as the named expression of the older policy.
110
110
  : Math.max(0, remaining - teamRows - railReserved);
111
111
  const bandRows = fill ? remaining : Math.max(railReserved, teamRows + previewRows);
112
- const railRows = railVisible ? bandRows : 0;
112
+ // THE RAIL NO LONGER OWNS THE BAND'S FULL HEIGHT WHEN A ROSTER IS DRAWN
113
+ // (tui-subagent-panel §4.1.2 / D-3). The roster is now a FULL-WIDTH slot below
114
+ // the rail's row region, so the two no longer overlap: the rail gets exactly the
115
+ // rows the roster does not take. With no roster this is `bandRows`, i.e.
116
+ // byte-identical to the previous behaviour (I-6).
117
+ //
118
+ // I-6a, WHY THIS CANNOT STARVE THE RAIL: `teamRows <= teamCeiling =
119
+ // min(teamRowsNatural, remaining - panelMinRows - 1)` (step 2 above) and in
120
+ // `fill` mode `bandRows === remaining`, so `railRows >= panelMinRows + 1 = 4`.
121
+ // Four satisfies both `TODO_LIMITS.panelMinRows(3)` (the rail stays mounted) and
122
+ // `SCROLLBACK_LIMITS.railBandMinRows(4)` (the band still reports
123
+ // `reason === 'visible'`). The price of a screen-right clock is a SHORTER rail
124
+ // during a dispatch, never a missing one - see §4.1.4's worked example.
125
+ const railRows = railVisible ? Math.max(0, bandRows - teamRows) : 0;
113
126
  const railColsOut = railVisible ? railCols : 0;
114
127
  return {
115
128
  reason,
@@ -76,6 +76,15 @@ export declare function isSettledStatus(status: ChildStatus): boolean;
76
76
  * glyph for the spinner when it may animate.
77
77
  */
78
78
  export declare function statusGlyph(status: ChildStatus, glyphs: Glyphs): string;
79
+ /**
80
+ * The widest marker this terminal's tier can produce (1 in Unicode, 4 in ASCII).
81
+ *
82
+ * EXPORTED (tui-subagent-panel §4.2.1): the panel row's geometry has to know how
83
+ * many columns the marker cell spends before it can divide the rest, and the cell
84
+ * width is a property of the TIER rather than of a status. `statusMarkerCell`
85
+ * keeps using it, so the padder and the measurer can never disagree.
86
+ */
87
+ export declare function statusMarkerWidth(glyphs: Glyphs): number;
79
88
  /**
80
89
  * The marker padded to the tier's widest one, for the leading cell of a row.
81
90
  *
@@ -139,3 +148,19 @@ export declare function outcomePhrase(counts: RosterCounts): string;
139
148
  * normalisation depend on it staying there.
140
149
  */
141
150
  export declare function isLiveTeamCard(entry: Entry): boolean;
151
+ /**
152
+ * The MOST RECENT dispatch card in the transcript, live or settled.
153
+ *
154
+ * ONE PREDICATE, TWO CONSUMERS (tui-subagent-panel §6.4): the `/agents` command
155
+ * and `App`'s `Ctrl+B` branch both have to answer "is there anything to show?"
156
+ * before opening the board, and the board itself falls back to this entry when a
157
+ * dispatch has already ended and `state.team` is `null` (`resolveBoardSource`).
158
+ * Asking the question in one place is what stops the key and the command from
159
+ * disagreeing about whether the board exists.
160
+ *
161
+ * Scans BACKWARDS and returns the first match: the newest card is the last one in
162
+ * `entries`, and a dispatch-heavy session can hold hundreds of them.
163
+ */
164
+ export declare function lastTeamEntry(entries: readonly Entry[]): Extract<Entry, {
165
+ kind: 'team';
166
+ }> | null;
@@ -92,8 +92,15 @@ export function statusGlyph(status, glyphs) {
92
92
  return glyphs.warn;
93
93
  }
94
94
  }
95
- /** The widest marker this terminal's tier can produce (1 in Unicode, 4 in ASCII). */
96
- function markerWidth(glyphs) {
95
+ /**
96
+ * The widest marker this terminal's tier can produce (1 in Unicode, 4 in ASCII).
97
+ *
98
+ * EXPORTED (tui-subagent-panel §4.2.1): the panel row's geometry has to know how
99
+ * many columns the marker cell spends before it can divide the rest, and the cell
100
+ * width is a property of the TIER rather than of a status. `statusMarkerCell`
101
+ * keeps using it, so the padder and the measurer can never disagree.
102
+ */
103
+ export function statusMarkerWidth(glyphs) {
97
104
  return Math.max(glyphs.toolPending.length, glyphs.spinnerStill.length, glyphs.toolDone.length, glyphs.toolError.length, glyphs.warn.length);
98
105
  }
99
106
  /**
@@ -106,7 +113,7 @@ function markerWidth(glyphs) {
106
113
  * padding is a no-op there.
107
114
  */
108
115
  export function statusMarkerCell(status, glyphs) {
109
- return statusGlyph(status, glyphs).padEnd(markerWidth(glyphs));
116
+ return statusGlyph(status, glyphs).padEnd(statusMarkerWidth(glyphs));
110
117
  }
111
118
  /**
112
119
  * The colour of a status. One reading for the roster row, the card row and the
@@ -222,3 +229,24 @@ export function outcomePhrase(counts) {
222
229
  export function isLiveTeamCard(entry) {
223
230
  return entry.kind === 'team' && entry.active === true;
224
231
  }
232
+ /**
233
+ * The MOST RECENT dispatch card in the transcript, live or settled.
234
+ *
235
+ * ONE PREDICATE, TWO CONSUMERS (tui-subagent-panel §6.4): the `/agents` command
236
+ * and `App`'s `Ctrl+B` branch both have to answer "is there anything to show?"
237
+ * before opening the board, and the board itself falls back to this entry when a
238
+ * dispatch has already ended and `state.team` is `null` (`resolveBoardSource`).
239
+ * Asking the question in one place is what stops the key and the command from
240
+ * disagreeing about whether the board exists.
241
+ *
242
+ * Scans BACKWARDS and returns the first match: the newest card is the last one in
243
+ * `entries`, and a dispatch-heavy session can hold hundreds of them.
244
+ */
245
+ export function lastTeamEntry(entries) {
246
+ for (let index = entries.length - 1; index >= 0; index -= 1) {
247
+ const entry = entries[index];
248
+ if (entry?.kind === 'team')
249
+ return entry;
250
+ }
251
+ return null;
252
+ }
@@ -109,4 +109,38 @@ export interface VtInputNoticeOptions {
109
109
  */
110
110
  onSeen: () => void;
111
111
  }
112
- export declare function useStartupNotices(dispatch: (action: ViewAction) => void, mouseNotice?: MouseNoticeOptions, retainNotice?: RetainNoticeOptions, vtInputNotice?: VtInputNoticeOptions, scrollModeNotice?: ScrollModeNoticeOptions): void;
112
+ /**
113
+ * The one-shot prompt-key migration notice (quick-prompt-library D-20).
114
+ *
115
+ * IT EXISTS BECAUSE A KEY MOVED: `Ctrl+P` now opens the prompt library and the mode
116
+ * fallback is `Ctrl+N`. Every existing user is in the audience, so silence is not an
117
+ * option - and, exactly like the two notices above, the gate is a VERSION so a later
118
+ * rewording can reach the people who learned the first one.
119
+ */
120
+ export interface PromptKeyNoticeOptions {
121
+ /** Record that `PROMPT_KEY_NOTICE_VERSION` was shown (`state.json`). */
122
+ onSeen: () => void;
123
+ }
124
+ /**
125
+ * The revision of the prompt-key notice a user must have seen for it to stay quiet
126
+ * (`state.json::promptKeyNoticeVersion`, `0` when absent). BUMP IT WHENEVER THE ADVICE
127
+ * CHANGES, never for a rewording.
128
+ */
129
+ export declare const PROMPT_KEY_NOTICE_VERSION = 1;
130
+ /**
131
+ * The startup notices, as ONE options object.
132
+ *
133
+ * SIX NOTICES, TWO PARAMETERS. This hook used to take five POSITIONAL arguments and
134
+ * this feature would have made it six, which `CLAUDE.md` forbids outright ("函数形参不超过
135
+ * 5 个") and which has no good answer anyway: a sixth positional boolean-shaped
136
+ * argument is unreadable at the call site and un-diffable in review. The object also
137
+ * makes an older caller that passes nothing byte-identical to today.
138
+ */
139
+ export interface StartupNoticeOptions {
140
+ mouse?: MouseNoticeOptions;
141
+ retain?: RetainNoticeOptions;
142
+ vtInput?: VtInputNoticeOptions;
143
+ scrollMode?: ScrollModeNoticeOptions;
144
+ promptKeys?: PromptKeyNoticeOptions;
145
+ }
146
+ export declare function useStartupNotices(dispatch: (action: ViewAction) => void, options: StartupNoticeOptions): void;