minicode-ai 0.27.0 → 0.28.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 (135) hide show
  1. package/cli/args.ts +120 -16
  2. package/cli/commands/acp.ts +38 -28
  3. package/cli/commands/auth.ts +17 -17
  4. package/cli/commands/config.ts +65 -66
  5. package/cli/commands/daemon.ts +44 -16
  6. package/cli/commands/doctor.ts +11 -12
  7. package/cli/commands/exec.ts +35 -73
  8. package/cli/commands/mcp.ts +25 -8
  9. package/cli/commands/memory.ts +16 -24
  10. package/cli/commands/openwork.ts +6 -2
  11. package/cli/commands/pricing.ts +14 -12
  12. package/cli/commands/providers.ts +36 -57
  13. package/cli/commands/sessions.ts +24 -18
  14. package/cli/commands/skills.ts +33 -18
  15. package/cli/commands/stats.ts +15 -30
  16. package/cli/commands.ts +73 -44
  17. package/cli/context-command-run.ts +30 -18
  18. package/cli/index.ts +48 -98
  19. package/cli/model-manager.ts +7 -2
  20. package/cli/provider-manager.ts +33 -18
  21. package/cli/router.ts +41 -12
  22. package/cli/setup.ts +246 -123
  23. package/cli/tui.ts +303 -100
  24. package/docs/TERMINAL_CONTRACT.md +254 -69
  25. package/docs/UI_RENDER_PIPELINE.md +9 -1
  26. package/docs/agents.md +2 -2
  27. package/docs/architecture.md +3 -3
  28. package/docs/choosing-mode.md +7 -9
  29. package/docs/cli.md +3 -5
  30. package/docs/environment.md +1 -2
  31. package/docs/policy-sandbox.md +3 -3
  32. package/docs/repl.md +2 -2
  33. package/docs/tools.md +1 -1
  34. package/package.json +1 -1
  35. package/src/app/mentions.ts +60 -13
  36. package/src/app/rag-layer.ts +17 -20
  37. package/src/app/session.ts +119 -66
  38. package/src/app/tool-layer.ts +12 -17
  39. package/src/config.ts +64 -104
  40. package/src/constants.ts +4 -6
  41. package/src/daemon/capability.ts +8 -1
  42. package/src/daemon/control.ts +3 -2
  43. package/src/daemon/server.ts +57 -0
  44. package/src/hooks/run.ts +73 -41
  45. package/src/lib/db-path.ts +47 -0
  46. package/src/lib/process-tree.ts +62 -0
  47. package/src/lib/public-http.ts +88 -23
  48. package/src/lib/trusted-exec.ts +48 -1
  49. package/src/lsp/client.ts +62 -17
  50. package/src/mcp/client.ts +85 -38
  51. package/src/mcp/http-transport.ts +28 -16
  52. package/src/mcp/transport.ts +42 -6
  53. package/src/memory/files.ts +164 -134
  54. package/src/memory/vector.ts +371 -420
  55. package/src/policy/approval-binding.ts +122 -45
  56. package/src/policy/bash-guard.ts +18 -7
  57. package/src/policy/compaction.ts +51 -18
  58. package/src/policy/context-window.ts +31 -8
  59. package/src/policy/context.ts +62 -36
  60. package/src/policy/executor.ts +17 -7
  61. package/src/policy/microcompact.ts +4 -3
  62. package/src/policy/no-progress.ts +103 -22
  63. package/src/policy/permission.ts +36 -12
  64. package/src/policy/tool-contract.ts +74 -416
  65. package/src/policy/usage.ts +24 -2
  66. package/src/policy/verifier.ts +50 -2
  67. package/src/policy/work-mode.ts +28 -54
  68. package/src/presentation/adapter.ts +24 -16
  69. package/src/providers/provision.ts +6 -56
  70. package/src/providers/responses.ts +1 -0
  71. package/src/runtime/execution-journal.ts +4 -29
  72. package/src/sandbox/docker.ts +58 -34
  73. package/src/sandbox/mask.ts +157 -0
  74. package/src/sandbox/os.ts +107 -73
  75. package/src/session/authority.ts +29 -10
  76. package/src/session/context-projection.ts +6 -5
  77. package/src/session/open-work.ts +26 -3
  78. package/src/session/persistence.ts +25 -58
  79. package/src/session/verification.ts +170 -20
  80. package/src/skills/loader.ts +31 -16
  81. package/src/task/production-scheduler.ts +13 -1
  82. package/src/task/store.ts +20 -37
  83. package/src/telemetry/trace.ts +27 -0
  84. package/src/tools/ask_user.ts +1 -13
  85. package/src/tools/bash.ts +27 -92
  86. package/src/tools/code_run.ts +1 -1
  87. package/src/tools/context.ts +133 -0
  88. package/src/tools/delete_file.ts +3 -2
  89. package/src/tools/edit.ts +37 -72
  90. package/src/tools/git.ts +86 -9
  91. package/src/tools/glob.ts +26 -51
  92. package/src/tools/grep.ts +67 -57
  93. package/src/tools/hashline.ts +4 -0
  94. package/src/tools/lsp.ts +11 -8
  95. package/src/tools/mcp_call.ts +9 -6
  96. package/src/tools/memory.ts +56 -33
  97. package/src/tools/move_file.ts +36 -10
  98. package/src/tools/patch.ts +13 -21
  99. package/src/tools/read_file.ts +18 -25
  100. package/src/tools/read_image.ts +35 -33
  101. package/src/tools/submit_result.ts +29 -8
  102. package/src/tools/task.ts +74 -17
  103. package/src/tools/todo.ts +181 -74
  104. package/src/tools/web_fetch.ts +42 -2
  105. package/src/tools/web_search.ts +47 -8
  106. package/src/ui/approval/prompt.ts +206 -47
  107. package/src/ui/assistant/turn-status.ts +14 -5
  108. package/src/ui/footer.ts +4 -4
  109. package/src/ui/i18n/en.ts +47 -23
  110. package/src/ui/i18n/id.ts +76 -51
  111. package/src/ui/input/input.ts +4 -3
  112. package/src/ui/input/prompt-engine.ts +35 -5
  113. package/src/ui/render/activity-panel.ts +4 -2
  114. package/src/ui/render/hint.ts +7 -4
  115. package/src/ui/render/list.ts +32 -0
  116. package/src/ui/render/markdown.ts +6 -3
  117. package/src/ui/render/notice.ts +19 -0
  118. package/src/ui/render/table-grid.ts +7 -8
  119. package/src/ui/render/theme.ts +113 -39
  120. package/src/ui/runtime/screen.ts +74 -10
  121. package/src/ui/runtime/spinner.ts +19 -6
  122. package/src/ui/screens/dialog.ts +19 -1
  123. package/src/ui/screens/form.ts +80 -35
  124. package/src/ui/screens/model-manager.ts +82 -61
  125. package/src/ui/screens/output-window.ts +263 -0
  126. package/src/ui/screens/picker.ts +94 -81
  127. package/src/ui/screens/provider-manager.ts +100 -69
  128. package/src/ui/screens/wizard.ts +117 -28
  129. package/src/ui/tui/app.ts +196 -33
  130. package/src/ui/tui/transcript.ts +154 -25
  131. package/vendor/minicore/src/core/executor.ts +2 -0
  132. package/vendor/minicore/src/core/loop.ts +17 -6
  133. package/vendor/minicore/src/core/session.ts +3 -0
  134. package/vendor/minicore/src/core/tool.ts +1 -0
  135. package/vendor/minicore/src/providers/openai-compat.ts +28 -19
@@ -0,0 +1,263 @@
1
+ // Jendela hasil command read-only: SATU layer di atas transkrip, seragam
2
+ // dengan jendela command lain (dialogBox + judul + hint minimalis).
3
+ // Output command TIDAK dicetak ke transkrip — chat tetap utuh dan tidak
4
+ // bergeser. Mendukung scroll (↑↓/PgUp/PgDn/Home/End/wheel/j/k/Space) serta
5
+ // salin cepat (`c`) untuk /help full, /status, /context, /history, /expand, dll.
6
+ import { t } from "../i18n/locale.ts"
7
+ import { createDecoderState, createKeyStreamPump, type DecodedKey } from "../input/prompt-engine.ts"
8
+ import { hintLine } from "../render/hint.ts"
9
+ import { sanitizeAnsiLine } from "../render/sanitize.ts"
10
+ import { c, glyphs, stripAnsi } from "../render/theme.ts"
11
+ import { wrapByWidth } from "../render/width.ts"
12
+ import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
13
+ import { canRenderModal, dialogBox } from "./dialog.ts"
14
+ import { createIdleTimer } from "./lifecycle.ts"
15
+
16
+ export interface OutputWindowOptions {
17
+ title: string
18
+ /** Baris output command (boleh mengandung SGR dari formatter command). */
19
+ lines: readonly string[]
20
+ /** Callback opsional untuk menyalin teks polos isi jendela dengan tombol `c`. */
21
+ onCopy?: (text: string) => boolean
22
+ }
23
+
24
+ /**
25
+ * Bungkus baris output agar muat di `width` kolom sambil mempertahankan
26
+ * hanging indent pada baris berindentasi (/help, /status, daftar command).
27
+ */
28
+ function wrapCommandLines(source: readonly string[], width: number): string[] {
29
+ const out: string[] = []
30
+ for (const line of source) {
31
+ const safe = sanitizeAnsiLine(line)
32
+ if (!safe) {
33
+ out.push("")
34
+ continue
35
+ }
36
+ const direct = wrapByWidth(safe, width)
37
+ if (direct.length <= 1) {
38
+ out.push(...direct)
39
+ continue
40
+ }
41
+ const lead = /^(\s+)/.exec(stripAnsi(safe))?.[1]?.length ?? 0
42
+ const hang = Math.min(lead, Math.max(0, Math.floor(width / 3)))
43
+ if (hang <= 0) {
44
+ out.push(...direct)
45
+ continue
46
+ }
47
+ // Bungkus ulang dengan anggaran menyisakan `hang` kolom agar sambungan sejajar.
48
+ const pad = " ".repeat(hang)
49
+ const indented = wrapByWidth(safe, Math.max(8, width - hang))
50
+ out.push(indented[0]!)
51
+ for (let k = 1; k < indented.length; k++) out.push(`${pad}${indented[k]!}`)
52
+ }
53
+ return out
54
+ }
55
+
56
+ /** Lebar jendela output command: lega untuk tabel/help, tetap rapi di layar. */
57
+ export function outputWindowWidth(cols: number): number {
58
+ const safe = Math.max(10, Math.floor(cols) || 80)
59
+ // Lebar lega untuk tabel/help, tetapi selalu menyisakan margin 4 kolom
60
+ // (chrome border+padding dialogBox) — terminal sempit tak boleh overflow.
61
+ return Math.min(Math.max(56, safe - 8), 96, Math.max(14, safe - 4))
62
+ }
63
+
64
+ /**
65
+ * Tampilkan output command sebagai overlay. Return false bila layar tak mampu
66
+ * (non-TTY/terlalu kecil) — pemanggil WAJIB fallback ke transkrip agar output
67
+ * tidak hilang.
68
+ */
69
+ export async function runOutputWindow(opts: OutputWindowOptions): Promise<boolean> {
70
+ if (!process.stdin.isTTY || !process.stdout.isTTY) return false
71
+ const screen: AltScreen = openAltScreen()
72
+ const useModal =
73
+ screen.ok && canRenderModal(process.stdout.columns || 80, process.stdout.rows || 24)
74
+ if (!useModal) {
75
+ try {
76
+ screen.close()
77
+ } catch {}
78
+ return false
79
+ }
80
+ // Buang blank line tepi (printStatus/help menambahkan padding) agar isi
81
+ // jendela rapi; blank internal dipertahankan.
82
+ const source = [...opts.lines]
83
+ while (source.length && !source[0]?.trim()) source.shift()
84
+ while (source.length && !source[source.length - 1]?.trim()) source.pop()
85
+
86
+ let boxWidth = outputWindowWidth(process.stdout.columns || 80)
87
+ let lastCols = 0
88
+ let wrapped: string[] = []
89
+ let scroll = 0
90
+ let done = false
91
+ let copyNotice: string | null = null
92
+ let copyTimer: ReturnType<typeof setTimeout> | null = null
93
+ let onData!: (chunk: Buffer) => void
94
+ let onResize!: () => void
95
+
96
+ const clearCopyTimer = (): void => {
97
+ if (copyTimer) {
98
+ clearTimeout(copyTimer)
99
+ copyTimer = null
100
+ }
101
+ }
102
+
103
+ const ensureWrapped = (cols: number): void => {
104
+ if (cols === lastCols && (wrapped.length > 0 || source.length === 0)) return
105
+ const prevTotal = wrapped.length
106
+ lastCols = cols
107
+ boxWidth = outputWindowWidth(cols)
108
+ const innerW = Math.max(8, boxWidth - 4)
109
+ wrapped = wrapCommandLines(source, innerW)
110
+ if (prevTotal > 0 && wrapped.length !== prevTotal) {
111
+ // Pertahankan posisi scroll proporsional saat terminal diubah ukurannya.
112
+ const ratio = scroll / Math.max(1, prevTotal)
113
+ scroll = Math.round(ratio * wrapped.length)
114
+ }
115
+ }
116
+
117
+ const bodyBudget = (): number => Math.max(1, (process.stdout.rows || 24) - 4)
118
+ const maxScroll = (): number => Math.max(0, wrapped.length - bodyBudget())
119
+
120
+ const render = (): void => {
121
+ const cols = process.stdout.columns || 80
122
+ const rows = process.stdout.rows || 24
123
+ ensureWrapped(cols)
124
+ const budget = bodyBudget()
125
+ scroll = Math.max(0, Math.min(scroll, Math.max(0, wrapped.length - budget)))
126
+ const scrollable = wrapped.length > budget
127
+ const startIdx = scroll + 1
128
+ const endIdx = Math.min(wrapped.length, scroll + budget)
129
+ const titleText = scrollable
130
+ ? `${opts.title} (${startIdx}-${endIdx}/${wrapped.length})`
131
+ : opts.title
132
+ const hints = hintLine([
133
+ ...(scrollable ? [{ key: glyphs.upDown, label: t("hint.scroll") }] : []),
134
+ ...(opts.onCopy ? [{ key: "c", label: t("hint.copy") }] : []),
135
+ { key: "Esc", label: t("hint.cancel") },
136
+ ])
137
+ const footerLine = copyNotice
138
+ ? copyNotice === t("tui.selectionCopied")
139
+ ? c.success(copyNotice)
140
+ : c.warning(copyNotice)
141
+ : hints
142
+ const body = wrapped.slice(scroll, scroll + budget)
143
+ const box = dialogBox(
144
+ {
145
+ title: titleText,
146
+ body,
147
+ footer: footerLine,
148
+ minWidth: boxWidth,
149
+ maxWidth: boxWidth,
150
+ },
151
+ cols,
152
+ rows,
153
+ )
154
+ screen.paintRegion(box.lines, box.topRow)
155
+ screen.setCursorVisible(false)
156
+ }
157
+
158
+ const idle = createIdleTimer({
159
+ cancelMs: 90_000,
160
+ onCancel: () => finish(true),
161
+ })
162
+
163
+ const finish = (ok = true): void => {
164
+ if (done) return
165
+ done = true
166
+ clearCopyTimer()
167
+ try {
168
+ pump.dispose()
169
+ } catch {}
170
+ idle.dispose()
171
+ try {
172
+ process.stdin.removeListener("data", onData)
173
+ } catch {}
174
+ if (onResize) process.stdout.removeListener("resize", onResize)
175
+ try {
176
+ screen.clearRegion()
177
+ } catch {}
178
+ try {
179
+ screen.close()
180
+ } catch {}
181
+ try {
182
+ process.stdin.setRawMode(false)
183
+ } catch {}
184
+ resolve(ok)
185
+ }
186
+
187
+ let resolve!: (v: boolean) => void
188
+ const result = new Promise<boolean>((r) => (resolve = r))
189
+
190
+ const handleKeys = (keys: DecodedKey[]): boolean => {
191
+ ensureWrapped(process.stdout.columns || 80)
192
+ let dirty = false
193
+ for (const d of keys) {
194
+ dirty = true
195
+ const k = d.key
196
+ if (k.type === "esc" || k.type === "enter" || k.type === "ctrl-c" || k.type === "ctrl-d") {
197
+ finish(true)
198
+ return true
199
+ }
200
+ if (k.type === "char" && (k.ch === "c" || k.ch === "C") && opts.onCopy) {
201
+ const okCopy = opts.onCopy(source.map((l) => stripAnsi(l)).join("\n"))
202
+ copyNotice = okCopy ? t("tui.selectionCopied") : t("tui.selectionCopyFailed")
203
+ clearCopyTimer()
204
+ copyTimer = setTimeout(() => {
205
+ copyTimer = null
206
+ copyNotice = null
207
+ if (!done) render()
208
+ }, 2000)
209
+ if (typeof copyTimer === "object" && "unref" in copyTimer) copyTimer.unref()
210
+ continue
211
+ }
212
+ copyNotice = null
213
+ clearCopyTimer()
214
+ if (k.type === "up" || (k.type === "char" && k.ch === "k")) {
215
+ scroll = Math.max(0, scroll - 1)
216
+ } else if (k.type === "down" || (k.type === "char" && k.ch === "j")) {
217
+ scroll = Math.min(maxScroll(), scroll + 1)
218
+ } else if (k.type === "wheelup") {
219
+ scroll = Math.max(0, scroll - 3)
220
+ } else if (k.type === "wheeldown") {
221
+ scroll = Math.min(maxScroll(), scroll + 3)
222
+ } else if (k.type === "pageup") {
223
+ scroll = Math.max(0, scroll - Math.max(1, bodyBudget() - 1))
224
+ } else if (k.type === "pagedown" || (k.type === "char" && k.ch === " ")) {
225
+ scroll = Math.min(maxScroll(), scroll + Math.max(1, bodyBudget() - 1))
226
+ } else if (k.type === "home") {
227
+ scroll = 0
228
+ } else if (k.type === "end") {
229
+ scroll = maxScroll()
230
+ }
231
+ }
232
+ if (dirty) {
233
+ idle.reset()
234
+ render()
235
+ }
236
+ return false
237
+ }
238
+ const pump = createKeyStreamPump({ state: createDecoderState(), onKeys: handleKeys })
239
+
240
+ onData = (chunk: Buffer) => {
241
+ idle.reset()
242
+ try {
243
+ pump.push(chunk)
244
+ } catch {
245
+ finish(true)
246
+ }
247
+ }
248
+ onResize = () => render()
249
+
250
+ try {
251
+ process.stdin.setRawMode(true)
252
+ process.stdin.resume()
253
+ process.stdin.on("data", onData)
254
+ process.stdout.on("resize", onResize)
255
+ idle.reset()
256
+ render()
257
+ } catch {
258
+ // Setup gagal = jendela tak pernah tampil. Resolve false agar pemanggil
259
+ // fallback mencetak output ke transkrip (data tidak hilang).
260
+ finish(false)
261
+ }
262
+ return result
263
+ }
@@ -9,12 +9,12 @@ import {
9
9
  toGraphemes,
10
10
  } from "../input/prompt-engine.ts"
11
11
  import { hintLine } from "../render/hint.ts"
12
+ import { listRow, tailFilterWindow } from "../render/list.ts"
12
13
  import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
13
- import { c, stripAnsi } from "../render/theme.ts"
14
+ import { c, glyphs, stripAnsi } from "../render/theme.ts"
14
15
  import { displayWidth, truncateToWidth } from "../render/width.ts"
15
16
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
16
- import { beginInteractiveScreen } from "../runtime/statusline.ts"
17
- import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
17
+ import { boxLeftPad, canRenderModal, dialogBox, popupBoxWidth } from "./dialog.ts"
18
18
  import { createIdleTimer } from "./lifecycle.ts"
19
19
 
20
20
  export interface PickerItem {
@@ -29,21 +29,27 @@ export interface PickerOptions {
29
29
  onPick: (value: string) => void
30
30
  onCancel: () => void
31
31
  filterable?: boolean
32
+ /** Tampilkan judul di kotak (khusus wizard yang butuh indikator step). */
33
+ showTitle?: boolean
34
+ /** Screen induk (nested popup memakai handle yang sama — anti-tearing). */
35
+ screen?: AltScreen
32
36
  }
33
37
 
34
38
  const dim = (s: string): string => c.dim(s)
35
39
 
36
40
  // Tandai substring query di label agar user tahu KENAPA item cocok.
37
- // Operasi pada teks plain (sebelum truncate) — SGR bold nol kolom.
38
- function highlightMatch(label: string, query: string): string {
39
- if (!query) return label
40
- const idx = label.toLowerCase().indexOf(query.toLowerCase())
41
- if (idx < 0) return label
42
- return (
43
- label.slice(0, idx) +
44
- c.bold(label.slice(idx, idx + query.length)) +
45
- label.slice(idx + query.length)
46
- )
41
+ // Pakai warna foreground saja (bukan bold \x1b[22m) agar atribut bold/dim dari
42
+ // pemanggil tidak padam untuk sisa teks setelah bagian yang cocok.
43
+ function highlightMatch(label: string, query: string, selected: boolean): string {
44
+ const paintBase = (s: string): string => (selected ? c.accent(c.bold(s)) : c.dim(s))
45
+ const paintHit = (s: string): string => (selected ? c.brightCyan(c.bold(s)) : c.dim(c.info(s)))
46
+ const idx = query ? label.toLowerCase().indexOf(query.toLowerCase()) : -1
47
+ const prefix = selected ? ` ${c.accent(glyphs.arrow)} ` : " "
48
+ if (idx < 0) return `${prefix}${paintBase(label)}`
49
+ const before = label.slice(0, idx)
50
+ const hit = label.slice(idx, idx + query.length)
51
+ const after = label.slice(idx + query.length)
52
+ return `${prefix}${before ? paintBase(before) : ""}${paintHit(hit)}${after ? paintBase(after) : ""}`
47
53
  }
48
54
 
49
55
  export async function runPicker(opts: PickerOptions): Promise<void> {
@@ -69,8 +75,11 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
69
75
  let scroll = 0
70
76
  let filter = ""
71
77
  const isFilterable = opts.filterable ?? false
72
- // Lebar dibekukan saat mount (AUD-006).
73
- const boxWidth = popupBoxWidth(process.stdout.columns || 80)
78
+ const showTitle = opts.showTitle === true
79
+ const ownScreen = !opts.screen
80
+ const screen: AltScreen = opts.screen ?? openAltScreen()
81
+ // Lebar dinamis terhadap terminal saat render/resize (tetap stabil saat filter).
82
+ const boxWidth = () => popupBoxWidth(screen.cols || 80)
74
83
 
75
84
  const filteredItems = (): PickerItem[] => {
76
85
  if (!isFilterable || !filter) return opts.items
@@ -88,27 +97,33 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
88
97
  // dicetak — keduanya membungkus dan merusak tampilan.
89
98
  const visibleRows = () => {
90
99
  const rows = process.stdout.rows || 24
91
- // Modal tanpa judul/footer dekoratif; sisakan border, baris pencarian
92
- // (bila ada), DAN satu baris hint aksi di dasar.
93
- if (useModal) return Math.max(1, Math.min(rows - (isFilterable ? 4 : 3), 12))
94
- const chrome = isFilterable ? 4 : 3
100
+ // Modal: border + (judul bila diminta) + baris pencarian (bila ada) +
101
+ // satu baris hint aksi di dasar.
102
+ const titleRows = showTitle ? 1 : 0
103
+ if (useModal) {
104
+ const chrome = (isFilterable ? 4 : 3) + titleRows
105
+ return Math.max(1, Math.min(rows - chrome, 12))
106
+ }
107
+ const chrome = (isFilterable ? 4 : 3) + titleRows
95
108
  return Math.max(1, Math.min(rows - chrome, 12))
96
109
  }
97
110
  // Lebar konten = lebar kotak (dibekukan saat mount) dikurangi chrome dialog
98
111
  // (border+padding = 4 kolom) agar dialogBox tak memotong ulang label.
99
- const width = () => Math.max(8, boxWidth - 4)
112
+ const width = () => Math.max(8, boxWidth() - 4)
100
113
 
101
- // Isi untuk dialog popup (tanpa judul; hint aksi satu baris di dasar).
102
- const bodyLines = (): string[] => {
114
+ // Isi untuk dialog popup (hint dipasung di `spec.footer` agar tak pernah
115
+ // ikut terpotong clipping dialogBox saat terminal menyusut).
116
+ const bodyLines = (): { lines: string[]; footer: string; filterShown: string } => {
103
117
  const items = filteredItems()
104
118
  const v = visibleRows()
105
- // Hint minimalis: kunci terang, label redup (satu sumber `hintLine`).
106
- // Selalu tampil agar navigasi tak perlu ditebak; tidak memakan tinggi
107
- // daftar karena `visibleRows` sudah menyisihkan satu baris untuknya.
108
- const hint = hintLine([
109
- { key: "↑↓", label: t("hint.move") },
119
+ // Hint akurat per mode: Esc pertama mengosongkan filter (bukan menutup).
120
+ const footer = hintLine([
121
+ { key: glyphs.upDown, label: t("hint.move") },
110
122
  { key: "Enter", label: t("hint.select") },
111
- { key: "Esc", label: t("hint.close") },
123
+ {
124
+ key: "Esc",
125
+ label: filter ? t("hint.clear") : t("hint.cancel"),
126
+ },
112
127
  ])
113
128
  if (sel >= items.length) sel = Math.max(0, items.length - 1)
114
129
  if (sel < 0) sel = 0
@@ -119,65 +134,68 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
119
134
  const w = width()
120
135
  const cut = (s: string) => truncateToWidth(s, w)
121
136
  const lines: string[] = []
137
+ let filterShown = ""
122
138
  if (isFilterable) {
123
- // Filter = input user tak terpercaya — sanitasi sebelum tampil.
124
- const display = filter ? c.brightCyan(sanitizeAnsiLine(filter)) : ""
125
- lines.push(cut(`${dim(">")} ${display}${c.accent("█")}`))
139
+ // Filter = input user tak terpercaya — sanitasi + windowing agar muat.
140
+ const budget = Math.max(4, w - 3 - displayWidth(glyphs.caret))
141
+ filterShown = filter ? tailFilterWindow(filter, budget) : ""
142
+ const display = filterShown ? c.brightCyan(filterShown) : ""
143
+ lines.push(cut(`${dim(">")} ${display}${c.accent(glyphs.caret)}`))
126
144
  }
127
145
  if (items.length === 0) {
128
146
  lines.push(cut(dim(` ${t("pick.noMatch", { q: sanitizeAnsiLine(filter) })}`)))
129
- lines.push(cut(hint))
130
- return lines
147
+ return { lines, footer, filterShown }
131
148
  }
132
149
  for (let i = 0; i < rows.length; i++) {
133
150
  const it = rows[i]!
134
151
  const picked = i === sel - scroll
135
152
  // Label provider::model ringkas; teks tetap disanitasi sebelum truncate.
136
- // Highlight query diterapkan sebelum truncate agar posisi kolom tepat.
137
153
  const safeProvider = sanitizeAnsiLine(it.provider)
138
154
  const rawLabel = safeProvider
139
155
  ? `${safeProvider}::${sanitizeAnsiLine(it.name)}`
140
156
  : sanitizeAnsiLine(it.name)
141
- const label = highlightMatch(truncateToWidth(rawLabel, w - 4), filter)
142
- if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
143
- else lines.push(` ${dim(label)}`)
157
+ // Marker `…` agar pemotongan tidak diam-diam (kontrak OUTPUT_UX §10).
158
+ const truncated = truncateToWidth(rawLabel, Math.max(4, w - 4), glyphs.ellipsis)
159
+ lines.push(filter ? highlightMatch(truncated, filter, picked) : listRow(truncated, picked))
144
160
  }
145
- lines.push(cut(hint))
146
- return lines
161
+ return { lines, footer, filterShown }
147
162
  }
148
163
 
149
164
  const render = () => {
165
+ const { lines, footer, filterShown } = bodyLines()
166
+ const w = boxWidth()
150
167
  // Popup komposit: HANYA region kotak yang dilukis (tanpa clear) di atas
151
- // konten pemilik layar (transkrip App / alt-buffer wizard). Pemilik
152
- // Lebar beku (min=max): geometri tak bernapas saat filter berubah.
168
+ // konten pemilik layar (transkrip App / alt-buffer wizard).
153
169
  const box = dialogBox(
154
170
  {
155
- title: "",
156
- body: bodyLines(),
157
- minWidth: boxWidth,
158
- maxWidth: boxWidth,
171
+ title: showTitle ? opts.title : "",
172
+ body: lines,
173
+ footer,
174
+ minWidth: w,
175
+ maxWidth: w,
159
176
  },
160
177
  screen.cols,
161
178
  screen.rows,
162
179
  )
163
180
  screen.paintRegion(box.lines, box.topRow)
164
- // Parkir kursor pada input filter meski kosong agar teks pertama langsung
165
- // masuk ke pencarian; navigasi item tetap memakai tombol panah.
166
- // Kolom = padding kiri + border + spasi + lebar label+filter + 1.
181
+ // Parkir kursor pada input filter; picker tanpa ketikan sembunyikan kursor.
167
182
  try {
168
183
  if (isFilterable) {
169
184
  const li = Math.min(box.lines.length - 1, box.bodyTop)
170
185
  const row = box.topRow + li
171
186
  const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
172
- const col = leftPad + 2 + 2 + displayWidth(stripAnsi(filter)) + 1
173
- process.stdout.write(`\x1b[${row};${Math.max(1, col)}H\x1b[?25h`)
187
+ const maxCol = leftPad + 2 + width() + 1
188
+ const col = Math.max(
189
+ 1,
190
+ Math.min(
191
+ screen.cols || 80,
192
+ maxCol,
193
+ leftPad + 4 + displayWidth(stripAnsi(filterShown)) + 1,
194
+ ),
195
+ )
196
+ screen.moveCursor(row, col)
174
197
  } else {
175
- const itemRow = Math.min(Math.max(0, sel - scroll), Math.max(0, visibleRows() - 1))
176
- const bodyOffset = isFilterable ? 1 : 0
177
- const li = Math.min(box.lines.length - 1, box.bodyTop + bodyOffset + itemRow)
178
- const row = box.topRow + li
179
- const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
180
- process.stdout.write(`\x1b[${row};${Math.max(1, leftPad + 1)}H\x1b[?25h`)
198
+ screen.setCursorVisible(false)
181
199
  }
182
200
  } catch {}
183
201
  }
@@ -210,8 +228,8 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
210
228
  // itu tak ada permukaan popup — tolak BERSUARA + batal (fail-closed).
211
229
  // Jalur overlay inline dihapus: satu-satunya tampilan interaktif adalah
212
230
  // TUI fullscreen (atau alt-buffer wizard first-run).
213
- const screen: AltScreen = openAltScreen()
214
- const useModal = screen.ok && (process.stdout.rows || 24) >= 10
231
+ const useModal =
232
+ screen.ok && canRenderModal(process.stdout.columns || 80, process.stdout.rows || 24)
215
233
  if (!useModal) {
216
234
  try {
217
235
  console.log(`⚠ ${t("gate.tuiPicker", { title: opts.title })}`)
@@ -219,21 +237,16 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
219
237
  try {
220
238
  opts.onCancel()
221
239
  } catch {}
222
- // Tutup layar sebelum batal: openAltScreen sudah menulis ENTER fisik
223
- // (?1049h) — bail tanpa close membocorkan alt-screen (terminal tertinggal
224
- // di buffer alternatif) dan hold painter-nya (I27) tidak pernah lepas.
225
- try {
226
- screen.close()
227
- } catch {}
240
+ // Tutup layar sebelum batal hanya bila picker membukanya sendiri:
241
+ // screen milik pemanggil tetap menjadi tanggung jawab pemanggil.
242
+ if (ownScreen) {
243
+ try {
244
+ screen.close()
245
+ } catch {}
246
+ }
228
247
  resolve()
229
248
  return
230
249
  }
231
- // Raw mode (sama seperti askLine/askSecret): picker juga menghalangi
232
- // painter transient stderr melukis di baris yang sama. Jalur ini aktif
233
- // bahkan saat runPicker dipanggil langsung (bukan lewat wizard), misalnya
234
- // di bawah alt-screen App yang painter-nya sudah ditahan — hold nested dan
235
- // release-nya idempoten.
236
- const endScreen = beginInteractiveScreen()
237
250
  const cleanup = () => {
238
251
  if (done) return
239
252
  done = true
@@ -244,18 +257,16 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
244
257
  process.stdin.setMaxListeners(prevMaxListeners)
245
258
  } catch {}
246
259
  idle.dispose()
247
- // Lepas kepemilikan layar: painter boleh melukis lagi setelah ini
248
- // (kursor sudah kembali ke anchor, overlay sudah dibersihkan).
249
- endScreen()
250
260
  // Hapus region popup sendiri; pemilik layar (App.resume) repaint penuh,
251
- // standalone (wizard) membuang alt-buffer utuh via close.
261
+ // standalone membuang alt-buffer + memulihkan kursor via close().
252
262
  try {
253
263
  screen.clearRegion()
254
264
  } catch {}
255
- try {
256
- screen.close()
257
- } catch {}
258
- process.stdout.write("\x1b[0m\x1b[?25h")
265
+ if (ownScreen) {
266
+ try {
267
+ screen.close()
268
+ } catch {}
269
+ }
259
270
  // TIDAK menulis \r\n di sini: \r\n membuat baris kosong permanen tiap
260
271
  // picker dipakai — terlihat sebagai gap saat picker nested di dalam
261
272
  // manager (mis. Enter → Thinking effort di /model).
@@ -274,10 +285,12 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
274
285
  const items = filteredItems()
275
286
  switch (d.key.type) {
276
287
  case "up":
288
+ case "wheelup":
277
289
  sel = Math.max(0, sel - 1)
278
290
  render()
279
291
  break
280
292
  case "down":
293
+ case "wheeldown":
281
294
  // Daftar kosong: jangan biarkan sel=-1 (Enter setelah Down lalu
282
295
  // filter menghadirkan 1 item akan menunjuk items[-1]=undefined →
283
296
  // onCancel padahal ada hasil ter-highlight).
@@ -341,8 +354,8 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
341
354
  }
342
355
  case "pageup":
343
356
  case "pagedown": {
344
- // Scroll daftar panjang (… N more) per halaman — paritas App.
345
- const vis = Math.max(1, Math.min((process.stdout.rows || 24) - 5, 12))
357
+ // Scroll daftar (… N more) per halaman memakai visibleRows() konsisten.
358
+ const vis = visibleRows()
346
359
  if (items.length > vis) {
347
360
  const page = Math.max(1, vis - 1)
348
361
  const maxScroll = Math.max(0, items.length - vis)
@@ -424,7 +437,7 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
424
437
 
425
438
  onResize = () => render()
426
439
 
427
- process.stdout.write("\x1b[?25l")
440
+ screen.setCursorVisible(false)
428
441
  try {
429
442
  process.stdin.setRawMode(true)
430
443
  process.stdin.resume()