min-agent 0.5.1 → 0.6.0

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 (169) hide show
  1. package/README.md +18 -18
  2. package/dist/cli.js +538 -12
  3. package/docs/API.md +6 -6
  4. package/package.json +6 -6
  5. package/skills/self-config/SKILL.md +4 -2
  6. package/skills/self-config/reference.md +4 -1
  7. package/dist/agent.js +0 -1388
  8. package/dist/assistant-stream.js +0 -131
  9. package/dist/cli/commands/chat.js +0 -13
  10. package/dist/cli/commands/ctx.js +0 -7
  11. package/dist/cli/commands/exec.js +0 -35
  12. package/dist/cli/commands/history.js +0 -58
  13. package/dist/cli/commands/index.js +0 -249
  14. package/dist/cli/commands/init.js +0 -18
  15. package/dist/cli/commands/mcp.js +0 -173
  16. package/dist/cli/commands/memory.js +0 -87
  17. package/dist/cli/commands/models.js +0 -21
  18. package/dist/cli/commands/permission.js +0 -12
  19. package/dist/cli/commands/rules.js +0 -33
  20. package/dist/cli/commands/sandbox.js +0 -13
  21. package/dist/cli/commands/serve.js +0 -9
  22. package/dist/cli/commands/setup.js +0 -56
  23. package/dist/cli/commands/shared.js +0 -25
  24. package/dist/cli/commands/skills.js +0 -119
  25. package/dist/cli/commands/think.js +0 -12
  26. package/dist/cli/commands/update.js +0 -7
  27. package/dist/cli/commands/write-config.js +0 -52
  28. package/dist/cli/errors.js +0 -36
  29. package/dist/cli/exec-prompt.js +0 -26
  30. package/dist/cli/option-helpers.js +0 -65
  31. package/dist/cli/program.js +0 -223
  32. package/dist/cli/setup/detect.js +0 -17
  33. package/dist/cli/setup/flags.js +0 -12
  34. package/dist/cli/setup/flow.js +0 -108
  35. package/dist/cli/setup/provider-form.js +0 -102
  36. package/dist/cli/setup/ui.js +0 -534
  37. package/dist/clipboard.js +0 -142
  38. package/dist/code-mode.js +0 -184
  39. package/dist/compaction.js +0 -644
  40. package/dist/config.js +0 -363
  41. package/dist/confirm.js +0 -172
  42. package/dist/context-window.js +0 -256
  43. package/dist/ctx-cli.js +0 -30
  44. package/dist/ctx.js +0 -80
  45. package/dist/doom-loop.js +0 -278
  46. package/dist/fetch-timeout.js +0 -152
  47. package/dist/http-approvals.js +0 -60
  48. package/dist/http.js +0 -119
  49. package/dist/instructions.js +0 -196
  50. package/dist/logger.js +0 -95
  51. package/dist/markdown.js +0 -259
  52. package/dist/mcp.js +0 -1036
  53. package/dist/memory-cli.js +0 -33
  54. package/dist/memory.js +0 -295
  55. package/dist/model-catalog.js +0 -285
  56. package/dist/ollama-model.js +0 -234
  57. package/dist/ollama-openai-bridge.js +0 -383
  58. package/dist/output.js +0 -76
  59. package/dist/paste-handler.js +0 -41
  60. package/dist/permission-cli.js +0 -40
  61. package/dist/plugins.js +0 -131
  62. package/dist/pricing.js +0 -119
  63. package/dist/provider.js +0 -63
  64. package/dist/question-format.js +0 -60
  65. package/dist/reasoning-stream.js +0 -158
  66. package/dist/sandbox-cli.js +0 -79
  67. package/dist/sandbox.js +0 -403
  68. package/dist/save-throttle.js +0 -45
  69. package/dist/scope.js +0 -23
  70. package/dist/serve/common.js +0 -425
  71. package/dist/serve/routes-chat.js +0 -367
  72. package/dist/serve/routes-mcp.js +0 -212
  73. package/dist/serve/routes-memory.js +0 -95
  74. package/dist/serve/routes-meta.js +0 -268
  75. package/dist/serve/routes-sessions.js +0 -61
  76. package/dist/serve/routes-skills.js +0 -70
  77. package/dist/serve.js +0 -138
  78. package/dist/sessions.js +0 -265
  79. package/dist/skills.js +0 -599
  80. package/dist/structured-output.js +0 -29
  81. package/dist/synthetic.js +0 -7
  82. package/dist/think-cli.js +0 -36
  83. package/dist/thinking-wire.js +0 -239
  84. package/dist/thinking.js +0 -166
  85. package/dist/title-gen.js +0 -55
  86. package/dist/token-display.js +0 -39
  87. package/dist/tool-display.js +0 -178
  88. package/dist/tool-output.js +0 -126
  89. package/dist/tools/apply_patch.js +0 -265
  90. package/dist/tools/atomic-file.js +0 -35
  91. package/dist/tools/backend.js +0 -61
  92. package/dist/tools/bash.js +0 -231
  93. package/dist/tools/code_search.js +0 -98
  94. package/dist/tools/edit.js +0 -68
  95. package/dist/tools/explore.js +0 -232
  96. package/dist/tools/glob.js +0 -40
  97. package/dist/tools/grep.js +0 -174
  98. package/dist/tools/index.js +0 -34
  99. package/dist/tools/question.js +0 -54
  100. package/dist/tools/read.js +0 -109
  101. package/dist/tools/search-searxng.js +0 -223
  102. package/dist/tools/search-serper.js +0 -189
  103. package/dist/tools/task.js +0 -165
  104. package/dist/tools/todo.js +0 -213
  105. package/dist/tools/web_fetch.js +0 -195
  106. package/dist/tools/web_search.js +0 -228
  107. package/dist/tools/write.js +0 -55
  108. package/dist/tui/App.js +0 -138
  109. package/dist/tui/ConfirmBar.js +0 -66
  110. package/dist/tui/CtxPicker.js +0 -68
  111. package/dist/tui/InputBar.js +0 -618
  112. package/dist/tui/MessageList.js +0 -718
  113. package/dist/tui/ModelPicker.js +0 -113
  114. package/dist/tui/QuestionBar.js +0 -136
  115. package/dist/tui/SessionPicker.js +0 -79
  116. package/dist/tui/Spinner.js +0 -6
  117. package/dist/tui/StatusBar.js +0 -22
  118. package/dist/tui/ThinkPicker.js +0 -75
  119. package/dist/tui/agent-runner.js +0 -223
  120. package/dist/tui/bracketed-paste.js +0 -37
  121. package/dist/tui/caret-pos.js +0 -179
  122. package/dist/tui/caret.js +0 -69
  123. package/dist/tui/click-count.js +0 -13
  124. package/dist/tui/diff-view.js +0 -61
  125. package/dist/tui/drag-state.js +0 -49
  126. package/dist/tui/hydrate.js +0 -129
  127. package/dist/tui/index.js +0 -264
  128. package/dist/tui/input-history.js +0 -125
  129. package/dist/tui/layout.js +0 -105
  130. package/dist/tui/mouse.js +0 -46
  131. package/dist/tui/overlay-input.js +0 -12
  132. package/dist/tui/paste-draft.js +0 -173
  133. package/dist/tui/prompt-queue.js +0 -24
  134. package/dist/tui/selection.js +0 -232
  135. package/dist/tui/session-switch.js +0 -28
  136. package/dist/tui/slash-commands.js +0 -129
  137. package/dist/tui/slash-handler.js +0 -615
  138. package/dist/tui/text-width.js +0 -113
  139. package/dist/tui/theme.js +0 -12
  140. package/dist/tui/token-info.js +0 -7
  141. package/dist/tui/tool-children.js +0 -19
  142. package/dist/tui/types.js +0 -1
  143. package/dist/tui/undo-stack.js +0 -14
  144. package/dist/tui/use-sgr-mouse.js +0 -29
  145. package/dist/tui-chat.js +0 -478
  146. package/dist/updater.js +0 -116
  147. package/dist/xml-search.js +0 -194
  148. package/docs/superpowers/plans/2026-08-16-batch1-tui-improvements.md +0 -1510
  149. package/docs/superpowers/plans/2026-08-16-batch2-cli-tools-api.md +0 -2105
  150. package/docs/superpowers/plans/2026-08-16-batch3-config-engineering.md +0 -1595
  151. package/docs/superpowers/plans/2026-08-16-input-caret.md +0 -782
  152. package/docs/superpowers/plans/2026-08-20-tui-completeness.md +0 -873
  153. package/docs/superpowers/plans/2026-08-20-unified-tui-default.md +0 -631
  154. package/docs/superpowers/plans/2026-08-23-cli-setup.md +0 -501
  155. package/docs/superpowers/plans/2026-08-23-input-paste-attachments.md +0 -475
  156. package/docs/superpowers/plans/2026-08-23-thinking-wire-profile.md +0 -450
  157. package/docs/superpowers/specs/2026-08-16-batch1-tui-improvements-design.md +0 -183
  158. package/docs/superpowers/specs/2026-08-16-batch2-cli-tools-api-design.md +0 -220
  159. package/docs/superpowers/specs/2026-08-16-batch3-config-engineering-design.md +0 -196
  160. package/docs/superpowers/specs/2026-08-16-input-caret-design.md +0 -63
  161. package/docs/superpowers/specs/2026-08-17-mouse-selection-design.md +0 -116
  162. package/docs/superpowers/specs/2026-08-20-config-http-alignment-design.md +0 -47
  163. package/docs/superpowers/specs/2026-08-20-mcp-plugins-alignment-design.md +0 -37
  164. package/docs/superpowers/specs/2026-08-20-sandbox-permissions-design.md +0 -68
  165. package/docs/superpowers/specs/2026-08-20-tui-completeness-design.md +0 -273
  166. package/docs/superpowers/specs/2026-08-20-unified-tui-default-design.md +0 -165
  167. package/docs/superpowers/specs/2026-08-23-cli-setup-design.md +0 -282
  168. package/docs/superpowers/specs/2026-08-23-input-paste-attachments-design.md +0 -174
  169. package/docs/superpowers/specs/2026-08-23-thinking-wire-profile-design.md +0 -140
package/dist/tui/index.js DELETED
@@ -1,264 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { render } from "ink";
3
- import { App } from "./App.js";
4
- import { createCaretAwareStdout, setCaretPosition } from "./caret.js";
5
- import { mergeToolChild } from "./tool-children.js";
6
- import { normalizeQuestionOptions, normalizeQuestionPrompt } from "../question-format.js";
7
- /**
8
- * TUI renderer — manages the Ink app lifecycle and provides
9
- * imperative methods to update state from the agent loop.
10
- */
11
- export class TuiRenderer {
12
- state;
13
- rerender = null;
14
- inkInstance = null;
15
- callbacks;
16
- pendingDelta = "";
17
- deltaTimer = null;
18
- pendingThinking = "";
19
- thinkingTimer = null;
20
- copyNoticeTimer = null;
21
- constructor(callbacks, model, sessionId) {
22
- this.state = {
23
- messages: [],
24
- isRunning: false,
25
- model,
26
- sessionId,
27
- };
28
- this.callbacks = callbacks;
29
- }
30
- appElement() {
31
- return (_jsx(App, { initialState: this.state, onSubmit: this.callbacks.onSubmit, onConfirm: this.callbacks.onConfirm, onQuestionAnswer: this.callbacks.onQuestionAnswer, onModelPick: this.callbacks.onModelPick, onModelCancel: this.callbacks.onModelCancel, onThinkPick: this.callbacks.onThinkPick, onThinkCancel: this.callbacks.onThinkCancel, onCtxPick: this.callbacks.onCtxPick, onCtxCancel: this.callbacks.onCtxCancel, onSessionPick: this.callbacks.onSessionPick, onSessionCancel: this.callbacks.onSessionCancel, onToggleSelectionMode: this.callbacks.onToggleSelectionMode, onExitSelectionMode: this.callbacks.onExitSelectionMode, onExit: this.callbacks.onExit, onCopyNotice: (text) => this.showCopyNotice(text), onNotice: this.callbacks.onNotice }));
32
- }
33
- start() {
34
- this.inkInstance = render(this.appElement(), { exitOnCtrlC: false, stdout: createCaretAwareStdout(process.stdout) });
35
- }
36
- /** Update state and trigger re-render — always replaces the reference so React sees a new prop. */
37
- update(partial) {
38
- this.state = { ...this.state, ...partial };
39
- if (this.inkInstance)
40
- this.inkInstance.rerender(this.appElement());
41
- }
42
- addMessage(msg) {
43
- this.flushPendingDeltas();
44
- this.flushPendingThinking();
45
- this.state.messages = [...this.state.messages, msg];
46
- this.update({});
47
- }
48
- /** Number of messages currently rendered (used by /undo). */
49
- messageCount() {
50
- return this.state.messages.length;
51
- }
52
- /**
53
- * Attach a tool result to the row created by the matching tool call. Falls
54
- * back to the newest still-pending row of the same tool when the id is
55
- * unknown (e.g. a provider that does not echo it back).
56
- */
57
- setToolResult(toolCallId, toolName, summary, full, isError) {
58
- const msgs = [...this.state.messages];
59
- let idx = msgs.findIndex((m) => m.role === "tool" && m.toolCallId === toolCallId);
60
- if (idx === -1) {
61
- for (let i = msgs.length - 1; i >= 0; i--) {
62
- const m = msgs[i];
63
- if (m.role === "tool" && m.toolName === toolName && m.toolResult === undefined) {
64
- idx = i;
65
- break;
66
- }
67
- }
68
- }
69
- if (idx === -1)
70
- return;
71
- msgs[idx] = { ...msgs[idx], toolResultSummary: summary, toolResult: full, toolIsError: isError };
72
- this.state.messages = msgs;
73
- this.update({});
74
- }
75
- /** Keep only the first `count` messages (used by /undo). */
76
- truncateMessages(count) {
77
- this.state.messages = this.state.messages.slice(0, count);
78
- this.update({});
79
- }
80
- /**
81
- * Append text to the last assistant message (for streaming).
82
- * Deltas are coalesced (50ms) so a burst of stream tokens renders as a
83
- * handful of frames instead of one per token; flushed when the run ends.
84
- */
85
- appendToLast(delta) {
86
- this.pendingDelta += delta;
87
- if (this.deltaTimer !== null)
88
- return;
89
- this.deltaTimer = setTimeout(() => {
90
- this.deltaTimer = null;
91
- this.applyPendingDelta();
92
- }, 16);
93
- }
94
- appendToThinking(delta) {
95
- this.pendingThinking += delta;
96
- if (this.thinkingTimer !== null)
97
- return;
98
- this.thinkingTimer = setTimeout(() => {
99
- this.thinkingTimer = null;
100
- this.applyPendingThinking();
101
- }, 16);
102
- }
103
- applyPendingThinking() {
104
- const accumulated = this.pendingThinking;
105
- this.pendingThinking = "";
106
- if (!accumulated)
107
- return;
108
- const msgs = [...this.state.messages];
109
- const last = msgs[msgs.length - 1];
110
- if (last && last.role === "thinking") {
111
- msgs[msgs.length - 1] = { ...last, content: last.content + accumulated };
112
- this.state.messages = msgs;
113
- this.update({});
114
- }
115
- else {
116
- this.addMessage({
117
- id: `thinking-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
118
- role: "thinking",
119
- content: accumulated,
120
- timestamp: Date.now(),
121
- });
122
- }
123
- }
124
- flushPendingThinking() {
125
- if (this.thinkingTimer !== null) {
126
- clearTimeout(this.thinkingTimer);
127
- this.thinkingTimer = null;
128
- }
129
- this.applyPendingThinking();
130
- }
131
- applyPendingDelta() {
132
- const accumulated = this.pendingDelta;
133
- this.pendingDelta = "";
134
- if (!accumulated)
135
- return;
136
- const msgs = [...this.state.messages];
137
- const last = msgs[msgs.length - 1];
138
- if (last && last.role === "assistant") {
139
- msgs[msgs.length - 1] = { ...last, content: last.content + accumulated };
140
- this.state.messages = msgs;
141
- this.update({});
142
- }
143
- else if (accumulated.trim() !== "") {
144
- this.addMessage({
145
- id: `msg-${Date.now()}`,
146
- role: "assistant",
147
- content: accumulated,
148
- timestamp: Date.now(),
149
- });
150
- }
151
- }
152
- /** Apply any coalesced delta immediately (run end, new message, exit). */
153
- flushPendingDeltas() {
154
- if (this.deltaTimer !== null) {
155
- clearTimeout(this.deltaTimer);
156
- this.deltaTimer = null;
157
- }
158
- this.applyPendingDelta();
159
- }
160
- setRunning(running, spinnerText) {
161
- if (!running) {
162
- this.flushPendingDeltas();
163
- this.flushPendingThinking();
164
- }
165
- if (this.state.isRunning === running && this.state.spinnerText === spinnerText)
166
- return;
167
- this.update({ isRunning: running, spinnerText });
168
- }
169
- showConfirm(message) {
170
- this.update({ confirmMessage: message, selectionMode: false });
171
- }
172
- hideConfirm() {
173
- this.update({ confirmMessage: undefined });
174
- }
175
- showQuestion(prompt, options) {
176
- const choices = normalizeQuestionOptions(options);
177
- this.update({
178
- question: {
179
- prompt: normalizeQuestionPrompt(prompt),
180
- ...(choices.length > 0 ? { options: choices } : {}),
181
- },
182
- selectionMode: false,
183
- });
184
- }
185
- hideQuestion() {
186
- this.update({ question: undefined });
187
- }
188
- showModelPicker() {
189
- this.update({ modelPicker: true, selectionMode: false });
190
- }
191
- hideModelPicker() {
192
- this.update({ modelPicker: false });
193
- }
194
- showThinkPicker(scope = "global") {
195
- this.update({ thinkPicker: { scope }, selectionMode: false });
196
- }
197
- hideThinkPicker() {
198
- this.update({ thinkPicker: undefined });
199
- }
200
- showCtxPicker() {
201
- this.update({ ctxPicker: true, selectionMode: false });
202
- }
203
- hideCtxPicker() {
204
- this.update({ ctxPicker: undefined });
205
- }
206
- showSessionPicker() {
207
- this.update({ sessionPicker: true, selectionMode: false });
208
- }
209
- hideSessionPicker() {
210
- this.update({ sessionPicker: false });
211
- }
212
- setSessionId(id) {
213
- this.update({ sessionId: id });
214
- }
215
- setSelectionMode(on) {
216
- this.update({ selectionMode: on });
217
- }
218
- toggleSelectionMode() {
219
- this.update({ selectionMode: !this.state.selectionMode });
220
- }
221
- appendToolChild(parentToolCallId, child) {
222
- this.state.messages = mergeToolChild(this.state.messages, parentToolCallId, child);
223
- this.update({});
224
- }
225
- setModel(model) {
226
- this.update({ model });
227
- }
228
- setTokenInfo(info) {
229
- this.update({ tokenInfo: info });
230
- }
231
- /** Flash a transient copy confirmation in the status bar (2.5s). */
232
- showCopyNotice(text) {
233
- this.update({ copyNotice: text });
234
- if (this.copyNoticeTimer !== null)
235
- clearTimeout(this.copyNoticeTimer);
236
- this.copyNoticeTimer = setTimeout(() => {
237
- this.copyNoticeTimer = null;
238
- this.update({ copyNotice: undefined });
239
- }, 2500);
240
- }
241
- destroy() {
242
- this.flushPendingDeltas();
243
- this.flushPendingThinking();
244
- if (this.copyNoticeTimer !== null) {
245
- clearTimeout(this.copyNoticeTimer);
246
- this.copyNoticeTimer = null;
247
- }
248
- if (this.deltaTimer !== null) {
249
- clearTimeout(this.deltaTimer);
250
- this.deltaTimer = null;
251
- }
252
- if (this.thinkingTimer !== null) {
253
- clearTimeout(this.thinkingTimer);
254
- this.thinkingTimer = null;
255
- }
256
- setCaretPosition(null);
257
- try {
258
- process.stdout.write("\x1b[?1000l\x1b[?1002l\x1b[?1006l");
259
- }
260
- catch { }
261
- this.inkInstance?.unmount();
262
- this.inkInstance = null;
263
- }
264
- }
@@ -1,125 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, renameSync } from "fs";
2
- import path from "path";
3
- import { getConfigDir } from "../config.js";
4
- import { atomicWriteFileSync } from "../tools/atomic-file.js";
5
- export const HISTORY_LIMIT = 1000;
6
- function historyFile() {
7
- return path.join(getConfigDir(), "input-history.json");
8
- }
9
- export function createHistory(entries = []) {
10
- return { entries, index: -1, draft: "" };
11
- }
12
- export function parseHistoryFile(raw) {
13
- let data;
14
- try {
15
- data = JSON.parse(raw);
16
- }
17
- catch {
18
- return null;
19
- }
20
- if (typeof data !== "object" || data === null || Array.isArray(data))
21
- return null;
22
- const entries = data.entries;
23
- if (!Array.isArray(entries) || entries.some((e) => typeof e !== "string"))
24
- return null;
25
- return entries;
26
- }
27
- export function serializeHistoryFile(entries) {
28
- return JSON.stringify({ entries }, null, 2);
29
- }
30
- export function loadInputHistoryFrom(file) {
31
- if (!existsSync(file))
32
- return [];
33
- let raw;
34
- try {
35
- raw = readFileSync(file, "utf-8");
36
- }
37
- catch {
38
- return [];
39
- }
40
- const parsed = parseHistoryFile(raw);
41
- if (parsed)
42
- return parsed;
43
- try {
44
- renameSync(file, `${file}.corrupt-${Date.now()}`);
45
- }
46
- catch { }
47
- return [];
48
- }
49
- export function saveInputHistoryTo(file, entries) {
50
- try {
51
- mkdirSync(path.dirname(file), { recursive: true });
52
- atomicWriteFileSync(file, serializeHistoryFile(entries));
53
- }
54
- catch { }
55
- }
56
- export function loadInputHistory() {
57
- return loadInputHistoryFrom(historyFile());
58
- }
59
- export function saveInputHistory(entries) {
60
- saveInputHistoryTo(historyFile(), entries);
61
- }
62
- export function pushInput(state, text) {
63
- if (!text)
64
- return state;
65
- if (state.entries.length > 0 && state.entries[state.entries.length - 1] === text)
66
- return state;
67
- const entries = [...state.entries, text];
68
- if (entries.length > HISTORY_LIMIT)
69
- entries.splice(0, entries.length - HISTORY_LIMIT);
70
- return { entries, index: -1, draft: "" };
71
- }
72
- export function searchHistory(state, query) {
73
- const q = query.toLowerCase();
74
- if (!q)
75
- return null;
76
- for (let i = state.entries.length - 1; i >= 0; i--) {
77
- if (state.entries[i].toLowerCase().includes(q))
78
- return state.entries[i];
79
- }
80
- return null;
81
- }
82
- export function browseHistory(state, direction, skip) {
83
- const count = state.entries.length;
84
- if (count === 0)
85
- return { text: state.draft, state };
86
- const last = count - 1;
87
- const usable = (i) => i >= 0 && i <= last && !skip?.(state.entries[i]);
88
- const current = state.index === -1 ? -1 : Math.max(0, Math.min(last, state.index));
89
- if (direction === 1) {
90
- const start = current === -1 ? last : current - 1;
91
- for (let i = start; i >= 0; i--) {
92
- if (usable(i))
93
- return { text: state.entries[i], state: { ...state, index: i } };
94
- }
95
- if (current !== -1)
96
- return { text: state.entries[current], state };
97
- return { text: state.draft, state };
98
- }
99
- if (current === -1)
100
- return { text: state.draft, state };
101
- for (let i = current + 1; i <= last; i++) {
102
- if (usable(i))
103
- return { text: state.entries[i], state: { ...state, index: i } };
104
- }
105
- return { text: state.draft, state: { ...state, index: -1 } };
106
- }
107
- export function resetHistory(state, text) {
108
- if (state.index === -1 && state.draft === text)
109
- return state;
110
- return { entries: state.entries, index: -1, draft: text };
111
- }
112
- export function isCtrlC(input, key) {
113
- return (key.ctrl === true && input === "c") || input === "\x03";
114
- }
115
- export const EXIT_CTRL_C_WINDOW_MS = 2000;
116
- export function clearInputOnCtrlC(state, value, armedAt = null, now = 0) {
117
- if (value === "") {
118
- if (armedAt !== null && now - armedAt <= EXIT_CTRL_C_WINDOW_MS) {
119
- return { state, value: "", exit: true, armedAt: null };
120
- }
121
- return { state, value: "", exit: false, armedAt: now };
122
- }
123
- const next = value.trim() ? pushInput(state, value) : { entries: state.entries, index: -1, draft: "" };
124
- return { state: next, value: "", exit: false, armedAt: null };
125
- }
@@ -1,105 +0,0 @@
1
- export const BOX_CHROME = 4;
2
- export const GUTTER_WIDTH = 2;
3
- export const TEXT_START_COLUMN = 5;
4
- export const STATUS_BAR_ROWS = 2;
5
- export const INPUT_BAR_ROWS = 3;
6
- export const MIN_MESSAGE_ROWS = 2;
7
- export const SLASH_MENU_MIN_ITEMS = 4;
8
- export const SLASH_COMMAND_MENU_CHROME = 5;
9
- export const SLASH_ARG_MENU_CHROME = 4;
10
- /** Ink paddingLeft on every message row. */
11
- export const MESSAGE_PAD_LEFT = 1;
12
- /**
13
- * Cells reserved at the right of a message row. Filling the last terminal
14
- * column wraps the cursor; East-Asian-ambiguous glyphs (`→`, `▸`) may also
15
- * occupy one more cell than `displayWidth` reports.
16
- */
17
- export const COL_WRAP_GUARD = 2;
18
- /** Pinned chrome of ConfirmBar: borders + title + gap + [y]/[N] prompt. */
19
- export const CONFIRM_CHROME_ROWS = 5;
20
- /** Pinned chrome of QuestionBar: borders + gap + input + hint. */
21
- export const QUESTION_CHROME_ROWS = 5;
22
- /**
23
- * Ink's log-update writes the frame plus a trailing newline. A root box that
24
- * uses the full terminal height therefore places the input bar's bottom
25
- * border on the last row, which that extra newline clips.
26
- */
27
- export const LAST_ROW_GUARD = 1;
28
- export function frameRows(terminalRows) {
29
- if (terminalRows <= 0)
30
- return 0;
31
- return Math.max(1, terminalRows - LAST_ROW_GUARD);
32
- }
33
- export function innerTextWidth(columns) {
34
- return Math.max(1, columns - 5);
35
- }
36
- export function messageTextWidth(columns) {
37
- return Math.max(1, columns - MESSAGE_PAD_LEFT - COL_WRAP_GUARD);
38
- }
39
- export function inputTextWidth(columns) {
40
- return Math.max(8, columns - BOX_CHROME - GUTTER_WIDTH);
41
- }
42
- export function computeMessageMaxHeight(frameRowCount, footerRows, spinnerRows) {
43
- if (frameRowCount <= 0)
44
- return undefined;
45
- return Math.max(MIN_MESSAGE_ROWS, frameRowCount - footerRows - STATUS_BAR_ROWS - spinnerRows);
46
- }
47
- /**
48
- * Max rows a confirm/question footer may occupy while leaving the status bar
49
- * and a two-row peek of the conversation. `minChrome` is the pinned action
50
- * chrome (title + prompt) that must stay on screen.
51
- */
52
- export function footerMaxRows(frameRowCount, minChrome) {
53
- if (frameRowCount <= 0)
54
- return Number.POSITIVE_INFINITY;
55
- return Math.max(minChrome, frameRowCount - STATUS_BAR_ROWS - MIN_MESSAGE_ROWS);
56
- }
57
- export function inputBarBoxRows(contentRows, hintRows) {
58
- return Math.max(1, contentRows) + Math.max(0, hintRows) + 2;
59
- }
60
- export function inputBarPaintRows(contentRows, hintRows, menuShown, argShown) {
61
- const menu = menuShown > 0 ? menuShown + SLASH_COMMAND_MENU_CHROME : argShown > 0 ? argShown + SLASH_ARG_MENU_CHROME : 0;
62
- return inputBarBoxRows(contentRows, hintRows) + menu;
63
- }
64
- /** How many slash-menu rows fit without covering the status bar and a two-row message peek. */
65
- export function slashMenuMaxVisible(frameRowCount, contentRows, hintRows, menuChromeRows) {
66
- const cap = footerMaxRows(frameRowCount, INPUT_BAR_ROWS);
67
- if (!Number.isFinite(cap))
68
- return Number.POSITIVE_INFINITY;
69
- return Math.max(SLASH_MENU_MIN_ITEMS, cap - inputBarBoxRows(contentRows, hintRows) - menuChromeRows);
70
- }
71
- /** Rows a line window actually paints: content plus one indicator per hidden side. */
72
- export function lineWindowPaintRows(window) {
73
- return window.lines.length + (window.above > 0 ? 1 : 0) + (window.below > 0 ? 1 : 0);
74
- }
75
- /**
76
- * Visible slice of wrapped lines for a max-height body. Hidden sides take an
77
- * indicator row each, subtracted from the content budget so the painted
78
- * window never exceeds `maxHeight`.
79
- */
80
- export function sliceLineWindow(lines, maxHeight, top) {
81
- if (maxHeight <= 0) {
82
- return { start: 0, lines: [], above: 0, below: lines.length };
83
- }
84
- if (lines.length <= maxHeight) {
85
- return { start: 0, lines, above: 0, below: 0 };
86
- }
87
- let above = 0;
88
- let below = 0;
89
- let start = 0;
90
- let viewH = maxHeight;
91
- for (let pass = 0; pass < 3; pass++) {
92
- const chrome = (above > 0 ? 1 : 0) + (below > 0 ? 1 : 0);
93
- viewH = Math.max(1, maxHeight - chrome);
94
- const maxTop = Math.max(0, lines.length - viewH);
95
- start = Math.max(0, Math.min(top, maxTop));
96
- above = start;
97
- below = Math.max(0, lines.length - (start + viewH));
98
- }
99
- return {
100
- start,
101
- lines: lines.slice(start, start + viewH),
102
- above,
103
- below,
104
- };
105
- }
package/dist/tui/mouse.js DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * Enable button-event tracking (1000), drag motion while a button is held
3
- * (1002) with SGR coordinates (1006). 1002 reports press/release plus motion
4
- * events while dragging, which the message list uses for text selection.
5
- */
6
- export const MOUSE_ENABLE = "\x1b[?1000h\x1b[?1002h\x1b[?1006h";
7
- /** Disable button-event tracking. */
8
- export const MOUSE_DISABLE = "\x1b[?1000l\x1b[?1002l\x1b[?1006l";
9
- const SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
10
- export function parseSgrMouse(input) {
11
- const match = input.match(SGR_RE);
12
- if (!match)
13
- return null;
14
- return {
15
- button: parseInt(match[1], 10),
16
- col: parseInt(match[2], 10),
17
- row: parseInt(match[3], 10),
18
- press: match[4] === "M",
19
- };
20
- }
21
- /** Wheel-up / wheel-down button codes in xterm button-event tracking (1000/1006). */
22
- export const WHEEL_UP = 64;
23
- export const WHEEL_DOWN = 65;
24
- /** Motion events (drag) add this to the button code (SGR, mode 1002/1003). */
25
- export const MOTION = 32;
26
- /** Modifier flags share the button code's low bits; Shift=4, Meta=8, Ctrl=16. Keep Ctrl so drag isn't mis-classified as "plain". */
27
- export const MOD_MASK = 31;
28
- /**
29
- * Parse the first complete SGR mouse event in a raw stdin buffer, returning
30
- * the event and the buffer remainder so the caller can process a stream of
31
- * events without re-reading consumed bytes.
32
- */
33
- export function scanSgrMouse(buffer) {
34
- const match = buffer.match(SGR_RE);
35
- if (!match)
36
- return null;
37
- return {
38
- event: {
39
- button: parseInt(match[1], 10),
40
- col: parseInt(match[2], 10),
41
- row: parseInt(match[3], 10),
42
- press: match[4] === "M",
43
- },
44
- rest: buffer.slice((match.index ?? 0) + match[0].length),
45
- };
46
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Pickers replace the input bar on the same Enter that opened them. Ink may
3
- * still deliver that key (or a leftover LF after CR) to the newly mounted
4
- * handler, which would auto-confirm the first row.
5
- */
6
- export function shouldAcceptOverlayConfirm(armed, key, input) {
7
- if (!armed)
8
- return false;
9
- if (input === "\n" && !key.return)
10
- return false;
11
- return Boolean(key.return);
12
- }