minicode-ai 0.26.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 (139) 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 +96 -46
  17. package/cli/context-command-run.ts +171 -0
  18. package/cli/context-command.ts +87 -0
  19. package/cli/index.ts +96 -98
  20. package/cli/model-manager.ts +7 -2
  21. package/cli/provider-manager.ts +33 -18
  22. package/cli/router.ts +41 -12
  23. package/cli/setup.ts +246 -123
  24. package/cli/tui.ts +311 -109
  25. package/docs/TERMINAL_CONTRACT.md +254 -69
  26. package/docs/UI_RENDER_PIPELINE.md +9 -1
  27. package/docs/agents.md +2 -2
  28. package/docs/architecture.md +3 -3
  29. package/docs/choosing-mode.md +7 -9
  30. package/docs/cli.md +3 -5
  31. package/docs/config.md +16 -0
  32. package/docs/environment.md +3 -3
  33. package/docs/policy-sandbox.md +3 -3
  34. package/docs/repl.md +3 -2
  35. package/docs/tools.md +1 -1
  36. package/package.json +1 -1
  37. package/src/app/mentions.ts +60 -13
  38. package/src/app/rag-layer.ts +17 -20
  39. package/src/app/session.ts +119 -66
  40. package/src/app/tool-layer.ts +12 -17
  41. package/src/config.ts +64 -104
  42. package/src/constants.ts +23 -9
  43. package/src/daemon/capability.ts +8 -1
  44. package/src/daemon/control.ts +3 -2
  45. package/src/daemon/server.ts +57 -0
  46. package/src/hooks/run.ts +73 -41
  47. package/src/lib/db-path.ts +47 -0
  48. package/src/lib/process-tree.ts +62 -0
  49. package/src/lib/public-http.ts +88 -23
  50. package/src/lib/trusted-exec.ts +48 -1
  51. package/src/lsp/client.ts +62 -17
  52. package/src/mcp/client.ts +85 -38
  53. package/src/mcp/http-transport.ts +28 -16
  54. package/src/mcp/transport.ts +42 -6
  55. package/src/memory/files.ts +164 -134
  56. package/src/memory/vector.ts +371 -420
  57. package/src/policy/approval-binding.ts +122 -45
  58. package/src/policy/bash-guard.ts +18 -7
  59. package/src/policy/compaction.ts +51 -18
  60. package/src/policy/context-window.ts +109 -0
  61. package/src/policy/context.ts +78 -37
  62. package/src/policy/executor.ts +17 -7
  63. package/src/policy/microcompact.ts +4 -3
  64. package/src/policy/no-progress.ts +103 -22
  65. package/src/policy/permission.ts +36 -12
  66. package/src/policy/tool-contract.ts +74 -416
  67. package/src/policy/usage.ts +24 -2
  68. package/src/policy/verifier.ts +50 -2
  69. package/src/policy/work-mode.ts +28 -54
  70. package/src/presentation/adapter.ts +24 -16
  71. package/src/providers/guards.ts +41 -2
  72. package/src/providers/provision.ts +6 -60
  73. package/src/providers/responses.ts +1 -0
  74. package/src/repo/repomap.ts +180 -23
  75. package/src/runtime/execution-journal.ts +4 -29
  76. package/src/sandbox/docker.ts +58 -34
  77. package/src/sandbox/mask.ts +157 -0
  78. package/src/sandbox/os.ts +107 -73
  79. package/src/session/authority.ts +29 -10
  80. package/src/session/context-projection.ts +6 -5
  81. package/src/session/open-work.ts +26 -3
  82. package/src/session/persistence.ts +25 -58
  83. package/src/session/verification.ts +170 -20
  84. package/src/skills/loader.ts +31 -16
  85. package/src/task/production-scheduler.ts +13 -1
  86. package/src/task/store.ts +20 -37
  87. package/src/telemetry/trace.ts +27 -0
  88. package/src/tools/ask_user.ts +1 -13
  89. package/src/tools/bash.ts +27 -92
  90. package/src/tools/code_run.ts +1 -1
  91. package/src/tools/context.ts +133 -0
  92. package/src/tools/delete_file.ts +3 -2
  93. package/src/tools/edit.ts +37 -72
  94. package/src/tools/git.ts +86 -9
  95. package/src/tools/glob.ts +26 -51
  96. package/src/tools/grep.ts +67 -57
  97. package/src/tools/hashline.ts +4 -0
  98. package/src/tools/lsp.ts +11 -8
  99. package/src/tools/mcp_call.ts +9 -6
  100. package/src/tools/memory.ts +56 -33
  101. package/src/tools/move_file.ts +36 -10
  102. package/src/tools/patch.ts +13 -21
  103. package/src/tools/read_file.ts +18 -25
  104. package/src/tools/read_image.ts +35 -33
  105. package/src/tools/submit_result.ts +29 -8
  106. package/src/tools/task.ts +74 -17
  107. package/src/tools/todo.ts +181 -74
  108. package/src/tools/web_fetch.ts +42 -2
  109. package/src/tools/web_search.ts +47 -8
  110. package/src/ui/approval/prompt.ts +206 -47
  111. package/src/ui/assistant/turn-status.ts +14 -5
  112. package/src/ui/footer.ts +4 -4
  113. package/src/ui/i18n/en.ts +59 -23
  114. package/src/ui/i18n/id.ts +88 -51
  115. package/src/ui/input/input.ts +4 -3
  116. package/src/ui/input/prompt-engine.ts +35 -5
  117. package/src/ui/render/activity-panel.ts +4 -2
  118. package/src/ui/render/hint.ts +7 -4
  119. package/src/ui/render/list.ts +32 -0
  120. package/src/ui/render/markdown.ts +6 -3
  121. package/src/ui/render/notice.ts +19 -0
  122. package/src/ui/render/table-grid.ts +7 -8
  123. package/src/ui/render/theme.ts +113 -39
  124. package/src/ui/runtime/screen.ts +74 -10
  125. package/src/ui/runtime/spinner.ts +19 -6
  126. package/src/ui/screens/dialog.ts +19 -1
  127. package/src/ui/screens/form.ts +80 -35
  128. package/src/ui/screens/model-manager.ts +88 -62
  129. package/src/ui/screens/output-window.ts +263 -0
  130. package/src/ui/screens/picker.ts +94 -81
  131. package/src/ui/screens/provider-manager.ts +100 -69
  132. package/src/ui/screens/wizard.ts +117 -28
  133. package/src/ui/tui/app.ts +196 -33
  134. package/src/ui/tui/transcript.ts +154 -25
  135. package/vendor/minicore/src/core/executor.ts +2 -0
  136. package/vendor/minicore/src/core/loop.ts +17 -6
  137. package/vendor/minicore/src/core/session.ts +3 -0
  138. package/vendor/minicore/src/core/tool.ts +1 -0
  139. package/vendor/minicore/src/providers/openai-compat.ts +28 -19
@@ -18,10 +18,11 @@ import {
18
18
  type DecoderState,
19
19
  toGraphemes,
20
20
  } from "../input/prompt-engine.ts"
21
+ import { type HintItem, hintLine } from "../render/hint.ts"
21
22
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
22
23
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
23
- import { displayWidth, truncateToWidth } from "../render/width.ts"
24
- import { type AltScreen, SYNC_UPDATE_END, SYNC_UPDATE_START } from "../runtime/screen.ts"
24
+ import { displayWidth, truncateToWidth, wrapByWidth } from "../render/width.ts"
25
+ import type { AltScreen } from "../runtime/screen.ts"
25
26
  import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
26
27
  import { createIdleTimer } from "./lifecycle.ts"
27
28
 
@@ -40,7 +41,8 @@ export interface FormField {
40
41
  export interface FormSpec {
41
42
  title: string
42
43
  fields: FormField[]
43
- footer?: string
44
+ /** Override hint (mis. Enter = hapus pada dialog konfirmasi). */
45
+ footerHints?: readonly HintItem[]
44
46
  }
45
47
 
46
48
  export interface FormResult {
@@ -82,6 +84,31 @@ const dim = (s: string): string => c.dim(s)
82
84
  /** Lebar kotak form: `popupBoxWidth` — paritas picker/model/provider (AUD-006). */
83
85
  const formBoxWidth = (cols: number): number => popupBoxWidth(cols)
84
86
 
87
+ /** Hint default mengikuti jenis field aktif: select/confirm butuh panah. */
88
+ function defaultFooterHints(st: FieldState | undefined): HintItem[] {
89
+ // Select/confirm: panah adalah aksi utama; Tab tetap berlaku tetapi tidak
90
+ // diumumkan agar hint tetap satu baris di popup 48 kolom (80-col terminal).
91
+ if (st?.def.kind === "select") {
92
+ return [
93
+ { key: glyphs.leftRight, label: t("hint.select") },
94
+ { key: "Enter", label: t("hint.save") },
95
+ { key: "Esc", label: t("hint.cancel") },
96
+ ]
97
+ }
98
+ if (st?.def.kind === "confirm") {
99
+ return [
100
+ { key: `${glyphs.leftRight}/y/n`, label: t("hint.select") },
101
+ { key: "Enter", label: t("hint.save") },
102
+ { key: "Esc", label: t("hint.cancel") },
103
+ ]
104
+ }
105
+ return [
106
+ { key: "Tab", label: t("hint.move") },
107
+ { key: "Enter", label: t("hint.save") },
108
+ { key: "Esc", label: t("hint.cancel") },
109
+ ]
110
+ }
111
+
85
112
  function toState(def: FormField): FieldState {
86
113
  if (def.kind === "select") {
87
114
  const n = Math.max(1, def.options?.length ?? 1)
@@ -176,9 +203,8 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
176
203
  idle.reset()
177
204
  }
178
205
 
179
- // Lebar konten = lebar kotak minus chrome border+padding (4).
180
- const boxW = formBoxWidth(screen.cols || 80)
181
- const width = () => boxW
206
+ // Lebar dinamis mengikuti terminal saat resize (tetap stabil saat error muncul/hilang).
207
+ const width = () => formBoxWidth(screen.cols || 80)
182
208
  const innerW = () => Math.max(8, width() - 4)
183
209
 
184
210
  // Baris nilai field aktif (indeks dalam body) untuk parkir kursor.
@@ -190,13 +216,17 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
190
216
  let activeCol = -1
191
217
  fields.forEach((st, fi) => {
192
218
  const active = fi === idx
219
+ const marker = active ? c.accent(glyphs.arrow) : " "
220
+ const cleanLabel = sanitizeAnsiLine(st.def.label)
193
221
  if (st.def.kind === "text" || st.def.kind === "secret") {
194
222
  const shown =
195
223
  st.def.kind === "secret" ? glyphs.mask.repeat(toGraphemes(st.text).length) : st.text
196
- // Scroll horizontal dalam KOLOM (bukan grapheme): CJK/emoji 2 kolom,
197
- // jadi hitung lebar tampil, bukan jumlah unit. Gagal-di-kode-lama:
198
- // kursor meleset 1 per glyph lebar + scroll prematur/terlambat.
199
- const maxV = Math.max(8, w - displayWidth(sanitizeAnsiLine(st.def.label)) - 4)
224
+ const inlinePrefix = `${marker} ${cleanLabel}: `
225
+ const inlineRoom = w - displayWidth(stripAnsi(inlinePrefix))
226
+ // Tata letak bertumpuk saat label panjang menyisakan ruang < 20 kolom
227
+ // (mis. Base URL preset di wizard); pertahankan inline untuk label pendek.
228
+ const stacked = inlineRoom < 20
229
+ const maxV = stacked ? Math.max(8, w - 2) : Math.max(8, inlineRoom)
200
230
  const pts = toGraphemes(shown)
201
231
  let start = Math.max(0, Math.min(st.viewStart, st.cursor))
202
232
  if (st.cursor < start) start = st.cursor
@@ -204,32 +234,47 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
204
234
  start++
205
235
  st.viewStart = start
206
236
  const vis = sliceByWidth(pts, start, maxV).join("")
207
- const prefix = `${active ? c.accent("›") : " "} ${sanitizeAnsiLine(st.def.label)}: `
208
- // Kolom kursor terminal = lebar tampil prefix + lebar tampil nilai
209
- // sebelum kursor (BUKAN jumlah grapheme).
210
- if (active) {
211
- activeCol =
212
- displayWidth(stripAnsi(prefix)) +
213
- displayWidth(pts.slice(start, st.cursor).join("")) +
214
- 1
237
+ if (stacked) {
238
+ for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
239
+ if (active) {
240
+ activeCol = 2 + displayWidth(pts.slice(start, st.cursor).join("")) + 1
241
+ }
242
+ body.push(cut(` ${vis}`))
243
+ } else {
244
+ if (active) {
245
+ activeCol =
246
+ displayWidth(stripAnsi(inlinePrefix)) +
247
+ displayWidth(pts.slice(start, st.cursor).join("")) +
248
+ 1
249
+ }
250
+ body.push(cut(`${inlinePrefix}${vis}`))
215
251
  }
216
- body.push(cut(`${prefix}${vis}`))
217
252
  activeRow = active ? body.length - 1 : activeRow
218
253
  } else if (st.def.kind === "select") {
219
254
  const opts = st.def.options ?? []
220
255
  const cur = sanitizeAnsiLine(opts[st.selectIdx] ?? "")
221
- const marker = active ? c.accent("›") : " "
256
+ const ctrl = `${dim(glyphs.chevronLeft)} ${cur} ${dim(glyphs.chevronRight)}`
257
+ const inline = `${marker} ${cleanLabel}: ${ctrl}`
222
258
  if (active) activeCol = -1 // select tanpa kursor ketik
223
- body.push(
224
- cut(`${marker} ${sanitizeAnsiLine(st.def.label)}: ${dim("‹")} ${cur} ${dim("›")}`),
225
- )
259
+ if (displayWidth(stripAnsi(inline)) > w) {
260
+ for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
261
+ body.push(cut(` ${ctrl}`))
262
+ } else {
263
+ body.push(cut(inline))
264
+ }
226
265
  activeRow = active ? body.length - 1 : activeRow
227
266
  } else {
228
- // Confirm: Ya/Tidak toggle.
229
- const marker = active ? c.accent("›") : " "
267
+ // Confirm: Ya/Tidak toggle (panah/y-n — sama seperti select).
230
268
  const val = st.confirmed ? c.accent(t("form.yes")) : t("form.no")
269
+ const ctrl = `${dim(glyphs.chevronLeft)} ${val} ${dim(glyphs.chevronRight)}`
270
+ const inline = `${marker} ${cleanLabel}: ${ctrl}`
231
271
  if (active) activeCol = -1
232
- body.push(cut(`${marker} ${sanitizeAnsiLine(st.def.label)}: ${val}`))
272
+ if (displayWidth(stripAnsi(inline)) > w) {
273
+ for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
274
+ body.push(cut(` ${ctrl}`))
275
+ } else {
276
+ body.push(cut(inline))
277
+ }
233
278
  activeRow = active ? body.length - 1 : activeRow
234
279
  }
235
280
  if (st.error) body.push(cut(c.error(` ${sanitizeAnsiLine(st.error)}`)))
@@ -243,7 +288,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
243
288
  // saja), draft tidak hilang tanpa jejak.
244
289
  footer: idleWarned
245
290
  ? c.error(t("form.idleWarning", { s: Math.ceil(IDLE_CANCEL_MS / 1000) }))
246
- : (spec.footer ?? t("form.footerDefault")),
291
+ : hintLine(spec.footerHints ?? defaultFooterHints(fields[idx])),
247
292
  // Lebar beku (paritas picker/manager — tak bernapas saat error
248
293
  // muncul/hilang).
249
294
  minWidth: width(),
@@ -272,12 +317,12 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
272
317
  const stripped = stripAnsi(box.lines[li] ?? "")
273
318
  const leftPad = boxLeftPad(stripped)
274
319
  const contentW = displayWidth(stripped) - leftPad
275
- const raw = activeCol >= 0 ? leftPad + activeCol + 2 : leftPad + contentW + 1
320
+ const maxCol = leftPad + 2 + w + 1
321
+ const raw =
322
+ activeCol >= 0 ? Math.min(maxCol, leftPad + activeCol + 2) : leftPad + contentW + 1
276
323
  const col = Math.max(1, Math.min(screen.cols || 80, raw))
277
- // Di dalam blok sync-update yang SAMA dengan paintRegion di atas
278
- // (temuan audit TUI-007): kursor yang muncul di luar sync berpotensi
279
- // tearing di emulator tanpa ?2026.
280
- process.stdout.write(`${SYNC_UPDATE_START}\x1b[${row};${col}H\x1b[?25h${SYNC_UPDATE_END}`)
324
+ // Lewat screen.moveCursor agar RESET_ATTRS + `\x1b[6 q` + blok sync konsisten.
325
+ screen.moveCursor(row, col)
281
326
  }
282
327
  } catch {}
283
328
  return { activeRow, activeCol }
@@ -335,9 +380,9 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
335
380
  const clean = ins
336
381
  .replace(/\r\n|\r/g, " ")
337
382
  .replace(/\t/g, " ")
338
- // Kontrol dibuang (kecuali newline yang sudah jadi spasi).
383
+ // Kontrol C0 + C1 dibuang (kecuali newline yang sudah jadi spasi).
339
384
  // biome-ignore lint/suspicious/noControlCharactersInRegex: sanitasi input form
340
- .replace(/[\u0000-\u001f\u007f]/g, "")
385
+ .replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
341
386
  if (!clean) return
342
387
  const pts = toGraphemes(st.text)
343
388
  const at = Math.max(0, Math.min(st.cursor, pts.length))
@@ -384,7 +429,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
384
429
  cur.error = null
385
430
  return true
386
431
  }
387
- const initial = typeof cur.def.initial === "string" ? cur.def.initial : ""
432
+ const initial = typeof cur.def.initial === "string" ? sanitizeAnsiLine(cur.def.initial) : ""
388
433
  if (cur.text === initial) return false
389
434
  cur.text = initial
390
435
  cur.cursor = toGraphemes(initial).length
@@ -8,12 +8,15 @@ import {
8
8
  type DecoderState,
9
9
  toGraphemes,
10
10
  } from "../input/prompt-engine.ts"
11
+ import { formatError } from "../render/errors.ts"
11
12
  import { hintLine } from "../render/hint.ts"
13
+ import { listRow, tailFilterWindow } from "../render/list.ts"
14
+ import { type NoticeKind, paintNoticeLines } from "../render/notice.ts"
12
15
  import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
13
16
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
14
- import { displayWidth, truncateToWidth } from "../render/width.ts"
17
+ import { displayWidth, truncateToWidth, wrapByWidth } from "../render/width.ts"
15
18
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
16
- import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
19
+ import { boxLeftPad, canRenderModal, dialogBox, popupBoxWidth } from "./dialog.ts"
17
20
  import { runForm } from "./form.ts"
18
21
  import { createIdleTimer } from "./lifecycle.ts"
19
22
  import { runPicker } from "./picker.ts"
@@ -61,6 +64,7 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
61
64
 
62
65
  /** Lebar kotak /model: `popupBoxWidth` (AUD-006, satu sumber width+maxWidth). */
63
66
  const modalBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
67
+ const MODAL_MAX_HEIGHT = 15
64
68
 
65
69
  export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
66
70
  let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
@@ -82,26 +86,23 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
82
86
  // redup DALAM popup, bukan console.log ke scrollback. Dibersihkan tiap
83
87
  // keypress baru — terlihat sampai tombol berikut ditekan.
84
88
  let notice: string | null = null
89
+ let noticeKind: NoticeKind = "info"
85
90
 
86
91
  return new Promise<void>((resolve) => {
92
+ const width = () => Math.max(8, modalBoxWidth() - 4)
93
+ const renderedNoticeLines = (): string[] =>
94
+ notice ? paintNoticeLines(noticeKind, notice).flatMap((l) => wrapByWidth(l, width())) : []
87
95
  const visibleRows = () => {
88
- const rows = process.stdout.rows || 24
89
- // Chrome tetap: 2 border + 1 baris pencarian + 1 baris hint aksi;
90
- // struk notice (transient) menyusutkan daftar satu baris agar tak
91
- // pernah menyingkirkan hint/marker "… more" (dialogBox memotong body
92
- // dari atas). Semua angka pas dengan `room = rows − 2` di dialogBox.
93
- const fixed = 4 + (notice ? 1 : 0)
96
+ const rows = Math.min(process.stdout.rows || 24, MODAL_MAX_HEIGHT)
97
+ // Chrome tetap: 2 border + 1 judul + 1 pencarian + 1 footer (dipin `dialogBox`);
98
+ // notice menyusutkan daftar agar kotak tetap ringkas dan hint tak hilang.
99
+ const fixed = 5 + renderedNoticeLines().length
94
100
  return Math.max(1, Math.min(rows - fixed, 8))
95
101
  }
96
- // Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
97
- // tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
98
- // dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
99
- // = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
100
- const width = () => Math.max(8, modalBoxWidth() - 4)
101
102
 
102
- // Isi MINIMAL dialog /model (tanpa judul/footer/hitungan/penanda —
103
- // seleksi murni warna). Search selalu tampil, daftar tanpa `›`.
104
- const bodyLinesModal = (): string[] => {
103
+ // Isi MINIMAL dialog /model; footer dipin lewat `spec.footer` agar aman
104
+ // dari pemotongan saat notice error panjang membungkus banyak baris.
105
+ const bodyLinesModal = (): { lines: string[]; footer: string; filterShown: string } => {
105
106
  const list = viewRows()
106
107
  const v = visibleRows()
107
108
  if (sel < scroll) scroll = sel
@@ -110,7 +111,9 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
110
111
  const cut = (s: string) => truncateToWidth(s, w)
111
112
  const view = list.slice(scroll, scroll + v)
112
113
  const lines: string[] = []
113
- lines.push(cut(`${dim(">")} ${c.brightCyan(sanitizeAnsiLine(filter ?? ""))}█`))
114
+ const filterBudget = Math.max(4, w - 3 - displayWidth(glyphs.caret))
115
+ const filterShown = tailFilterWindow(filter ?? "", filterBudget)
116
+ lines.push(cut(`${dim(">")} ${c.brightCyan(filterShown)}${c.accent(glyphs.caret)}`))
114
117
  if (!list.length) {
115
118
  lines.push(cut(dim(` ${filter == null ? t("model.empty") : t("model.noMatch")}`)))
116
119
  } else {
@@ -122,67 +125,64 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
122
125
  // nama yang dipotong, status yang selamat.
123
126
  const active = row.active ? ` (${t("common.active")})` : ""
124
127
  const nameBudget = Math.max(8, w - 4 - displayWidth(active))
125
- const label = `${truncateToWidth(`${sanitizeAnsiLine(row.id)}${badge}`, nameBudget, "…")}${active}`
126
- // Penanda › paritas picker/provider-manager — aksesibilitas visual
127
- // (warna saja tak cukup untuk sebagian pengguna).
128
- if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
129
- else lines.push(` ${dim(label)}`)
128
+ const label = `${truncateToWidth(`${sanitizeAnsiLine(row.id)}${badge}`, nameBudget, glyphs.ellipsis)}${active}`
129
+ // Kolom marker dipakai bersama (listRow): label tak bergeser saat
130
+ // seleksi berpindah dan marker `›` tidak hilang tanpa warna.
131
+ lines.push(listRow(label, picked))
130
132
  }
131
133
  }
132
- if (notice) lines.push(cut(dim(sanitizeAnsiLine(notice))))
133
- // Hint aksi minimalis (kunci terang, label redup) — satu sumber dengan
134
- // picker/form agar seluruh jendela /model konsisten. Sengaja TANPA
135
- // judul/footer dekoratif (kontrak v7.8); ini baris body terakhir.
136
- lines.push(
137
- cut(
138
- hintLine([
139
- { key: "↑↓", label: t("hint.move") },
140
- { key: "Enter", label: t("hint.select") },
141
- { key: "Tab", label: t("hint.effort") },
142
- { key: "Del", label: t("hint.delete") },
143
- { key: "Esc", label: t("hint.close") },
144
- ]),
145
- ),
146
- )
147
- return lines
134
+ for (const line of renderedNoticeLines()) lines.push(cut(line))
135
+ // Hint akurat per mode: saat filter aktif, Esc keluar dari pencarian
136
+ // (bukan menutup) dan Del mengedit query (jangan iklankan Del delete).
137
+ const escLabel = filter == null ? t("hint.cancel") : t("hint.back")
138
+ const footer = hintLine([
139
+ { key: glyphs.upDown, label: t("hint.move") },
140
+ { key: "Enter", label: t("hint.select") },
141
+ { key: "Tab", label: t("hint.effort") },
142
+ ...(filter == null ? [{ key: "Del", label: t("hint.delete") }] : []),
143
+ { key: "Esc", label: escLabel },
144
+ ])
145
+ return { lines, footer, filterShown }
148
146
  }
149
147
 
150
148
  const render = () => {
151
- // Region kotak di atas transkrip; lebar beku (min=max).
149
+ const { lines, footer, filterShown } = bodyLinesModal()
150
+ // Region kotak di atas transkrip; lebar mengikuti terminal saat resize.
152
151
  const box = dialogBox(
153
152
  {
154
- title: "",
155
- body: bodyLinesModal(),
153
+ title: t("out.titleModels"),
154
+ body: lines,
155
+ footer,
156
156
  minWidth: modalBoxWidth(),
157
157
  maxWidth: modalBoxWidth(),
158
- maxHeight: 14,
158
+ maxHeight: MODAL_MAX_HEIGHT,
159
159
  },
160
160
  screen.cols,
161
161
  screen.rows,
162
162
  )
163
163
  screen.paintRegion(box.lines, box.topRow)
164
- // Parkir kursor di posisi ketik query (tepat sebelum penanda █ di
165
- // baris search body[0]): kolom = padding + border + spasi + "> " +
166
- // lebar filter + 1. Parkir di ujung baris (padding void) terlihat
167
- // rusak — kursor melayang jauh dari █.
164
+ // Parkir kursor tepat sebelum caret di dalam kotak dan blok sync-update.
168
165
  try {
169
166
  const li = Math.min(box.lines.length - 1, box.bodyTop)
170
167
  const row = box.topRow + li
171
168
  const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
169
+ const maxCol = leftPad + 2 + width() + 1
172
170
  const col = Math.max(
173
171
  1,
174
172
  Math.min(
175
173
  screen.cols || 80,
176
- leftPad + 2 + 2 + displayWidth(sanitizeAnsiLine(filter ?? "")) + 1,
174
+ maxCol,
175
+ leftPad + 4 + displayWidth(stripAnsi(filterShown)) + 1,
177
176
  ),
178
177
  )
179
- process.stdout.write(`\x1b[${row};${col}H\x1b[?25h`)
178
+ screen.moveCursor(row, col)
180
179
  } catch {}
181
180
  }
182
181
 
183
182
  // Popup butuh layar mampu; selain itu tolak BERSUARA + batal.
184
183
  const screen: AltScreen = openAltScreen()
185
- const useModal = screen.ok && (process.stdout.rows || 24) >= 10
184
+ const useModal =
185
+ screen.ok && canRenderModal(process.stdout.columns || 80, process.stdout.rows || 24)
186
186
  if (!useModal) {
187
187
  try {
188
188
  console.log(`⚠ ${t("gate.tuiModel")}`)
@@ -215,7 +215,14 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
215
215
  const suspend = () => {
216
216
  idle.clear()
217
217
  attached = false
218
- process.stdout.write("\x1b[0m\x1b[?25h")
218
+ // Hapus kotak induk sebelum sub-modal (effort picker / form konfirmasi)
219
+ // tampil agar bingkai tidak tumpang-tindih; saat finish `done` sudah true.
220
+ if (!done) {
221
+ try {
222
+ screen.clearRegion()
223
+ } catch {}
224
+ screen.setCursorVisible(false)
225
+ }
219
226
  // TANPA pause — stdin mengalir seumur proses (lihat cleanup askLine).
220
227
  try {
221
228
  process.stdin.setRawMode(false)
@@ -290,9 +297,10 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
290
297
  try {
291
298
  await fn()
292
299
  } catch (e) {
293
- // Pesan error dari controller/jaringan = input tak terpercaya:
294
- // sanitasi (tanpa ini ESC[2J dari pesan merusak layar).
295
- notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
300
+ // Formatter kanonik: redaksi credential + saran tindakan. Notice
301
+ // error dirender merah oleh paintNoticeLines (bukan teks redup).
302
+ notice = formatError(e)
303
+ noticeKind = "error"
296
304
  } finally {
297
305
  busy = false
298
306
  await loadRowsSafe()
@@ -335,15 +343,21 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
335
343
  kind: "confirm",
336
344
  },
337
345
  ],
338
- footer: t("model.deleteFooter"),
346
+ footerHints: [
347
+ { key: `${glyphs.leftRight}/y/n`, label: t("hint.select") },
348
+ { key: "Enter", label: t("hint.delete") },
349
+ { key: "Esc", label: t("hint.cancel") },
350
+ ],
339
351
  },
340
352
  screen,
341
353
  )
342
354
  if (!form.cancelled && form.values?.ok === "y") {
343
355
  rows = await withWatchdog(() => opts.onDelete(row.id))
344
- notice = `${glyphs.check} ${t("ntc.deleted", { id: row.id })}`
356
+ notice = t("ntc.deleted", { id: row.id })
357
+ noticeKind = "success"
345
358
  } else {
346
359
  notice = t("common.canceled")
360
+ noticeKind = "info"
347
361
  rows = await withWatchdog(() => opts.loadRows())
348
362
  }
349
363
  clampSel()
@@ -366,6 +380,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
366
380
  try {
367
381
  void runPicker({
368
382
  title: t("effort.title"),
383
+ showTitle: true,
384
+ screen,
369
385
  items: options.map((name) => ({ name, provider: "", value: name })),
370
386
  onPick: (v) => resolvePick(v),
371
387
  onCancel: () => resolvePick(null),
@@ -389,9 +405,11 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
389
405
  typeof process.stdin.getMaxListeners === "function" ? process.stdin.getMaxListeners() : 10
390
406
  const handleManagerKeys = (keys: DecodedKey[]): boolean => {
391
407
  if (busy || done) return true
408
+ if (!keys.length) return false
392
409
  try {
393
410
  // Struk lama dibersihkan tiap keypress baru (transient, bukan arsip).
394
411
  notice = null
412
+ noticeKind = "info"
395
413
  for (const item of keys) {
396
414
  // Mode cari: semua ketikan masuk ke query, Esc keluar dari mode
397
415
  // cari — bukan tutup manager.
@@ -441,8 +459,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
441
459
  finish()
442
460
  return true
443
461
  }
444
- if (item.key.type === "up") sel = Math.max(0, sel - 1)
445
- else if (item.key.type === "down") {
462
+ if (item.key.type === "up" || item.key.type === "wheelup") sel = Math.max(0, sel - 1)
463
+ else if (item.key.type === "down" || item.key.type === "wheeldown") {
446
464
  const n = viewRows().length
447
465
  sel = n ? Math.min(n - 1, sel + 1) : 0
448
466
  } else if (item.key.type === "home") {
@@ -484,8 +502,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
484
502
  // Pilih model yang gagal HARUS terlihat dan kembali ke daftar
485
503
  // untuk retry (pola resume() seperti a/d/e provider-manager),
486
504
  // bukan menutup manager dan kehilangan konteks daftar.
487
- // Pesan controller = input tak terpercaya: sanitasi.
488
- notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
505
+ notice = formatError(e)
506
+ noticeKind = "error"
489
507
  busy = false
490
508
  await loadRowsSafe()
491
509
  resume()
@@ -503,17 +521,25 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
503
521
  ;(async () => {
504
522
  try {
505
523
  const picked = await pickEffort(row.id)
506
- if (picked && picked !== "skip") {
524
+ if (picked === "skip") {
525
+ // Keluarga tanpa thinking: sebelumnya cabang ini diam total —
526
+ // user menekan Tab, layar tak berubah, dan itu terbaca sebagai
527
+ // "minicode macet". Nyatakan alasannya, tetap di daftar.
528
+ notice = t("effort.noThinking")
529
+ noticeKind = "info"
530
+ } else if (picked) {
507
531
  await withWatchdog(() => opts.onSetEffort!(row.id, picked))
508
532
  // Notice terlihat di daftar (manager tetap terbuka) —
509
533
  // inilah kehidupan baru `effort.saved` setelah A5.
510
534
  notice = t("effort.saved", { effort: picked })
535
+ noticeKind = "success"
511
536
  }
512
537
  busy = false
513
538
  await loadRowsSafe()
514
539
  resume()
515
540
  } catch (e) {
516
- notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
541
+ notice = formatError(e)
542
+ noticeKind = "error"
517
543
  busy = false
518
544
  await loadRowsSafe()
519
545
  resume()
@@ -551,7 +577,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
551
577
 
552
578
  const onResize = () => render()
553
579
 
554
- process.stdout.write("\x1b[?25l")
580
+ screen.setCursorVisible(false)
555
581
  try {
556
582
  process.stdin.setRawMode(true)
557
583
  process.stdin.resume()