minicode-ai 0.10.0 → 0.11.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 (128) hide show
  1. package/AGENTS.md +45 -0
  2. package/CHANGELOG.md +59 -4
  3. package/PLAN.md +491 -0
  4. package/README.md +2 -2
  5. package/cli/commands/acp.ts +485 -0
  6. package/cli/commands/auth.ts +7 -4
  7. package/cli/commands/config.ts +41 -27
  8. package/cli/commands/exec.ts +33 -12
  9. package/cli/commands/mcp.ts +3 -2
  10. package/cli/commands/memory.ts +1 -1
  11. package/cli/commands/pricing.ts +6 -4
  12. package/cli/commands/providers.ts +18 -8
  13. package/cli/commands/sessions.ts +11 -4
  14. package/cli/commands/skills.ts +3 -3
  15. package/cli/commands/stats.ts +3 -1
  16. package/cli/commands.ts +6 -0
  17. package/cli/index.ts +82 -57
  18. package/cli/model-manager.ts +6 -1
  19. package/cli/router.ts +7 -0
  20. package/cli/setup.ts +341 -5
  21. package/cli/tui.ts +54 -18
  22. package/docs/ARCHITECTURE.html +29 -22
  23. package/docs/CONTROL-PLANE-MAP.md +139 -0
  24. package/docs/HARNESS.md +150 -0
  25. package/docs/PLAN_UIUX_V6.md +209 -0
  26. package/docs/README.md +1 -1
  27. package/docs/SUMMARY.md +52 -0
  28. package/docs/TERMINAL_CONTRACT.md +367 -0
  29. package/docs/UI_RENDER_PIPELINE.md +165 -0
  30. package/docs/USAGE.md +11 -0
  31. package/docs/agents.md +31 -0
  32. package/docs/architecture.md +3 -3
  33. package/docs/choosing-mode.md +34 -0
  34. package/docs/cli.md +130 -0
  35. package/docs/concepts.md +53 -0
  36. package/docs/config-providers.md +87 -0
  37. package/docs/config.md +63 -0
  38. package/docs/contributing.md +79 -0
  39. package/docs/environment.md +95 -0
  40. package/docs/exec.md +73 -0
  41. package/docs/getting-started.md +102 -0
  42. package/docs/glossary.md +37 -0
  43. package/docs/mcp-lsp.md +54 -0
  44. package/docs/memory-sessions.md +63 -0
  45. package/docs/policy-sandbox.md +72 -0
  46. package/docs/pricing-budget.md +49 -0
  47. package/docs/quickstart.md +60 -0
  48. package/docs/repl.md +67 -0
  49. package/docs/security-model.md +95 -0
  50. package/docs/security.md +91 -0
  51. package/docs/skills.md +48 -0
  52. package/docs/terminal.md +79 -0
  53. package/docs/tools.md +123 -0
  54. package/docs/troubleshooting.md +40 -0
  55. package/docs/verify-benchmark.md +58 -0
  56. package/package.json +8 -5
  57. package/src/app/provider-layer.ts +12 -4
  58. package/src/app/session.ts +6 -0
  59. package/src/app/tool-layer.ts +2 -1
  60. package/src/constants.ts +35 -0
  61. package/src/lib/net.ts +6 -1
  62. package/src/lsp/client.ts +41 -8
  63. package/src/mcp/http-transport.ts +52 -15
  64. package/src/mcp/transport.ts +32 -1
  65. package/src/memory/files.ts +6 -5
  66. package/src/policy/allowlist.ts +1 -1
  67. package/src/policy/bash-guard.ts +154 -14
  68. package/src/policy/compaction.ts +57 -3
  69. package/src/policy/context.ts +4 -0
  70. package/src/policy/jail.ts +49 -4
  71. package/src/policy/permission.ts +152 -12
  72. package/src/policy/pricing.ts +12 -9
  73. package/src/presentation/adapter.ts +721 -0
  74. package/src/presentation/events.ts +324 -0
  75. package/src/presentation/label.ts +140 -0
  76. package/src/presentation/model.ts +172 -0
  77. package/src/presentation/reducer.ts +486 -0
  78. package/src/presentation/store.ts +256 -0
  79. package/src/providers/anthropic.ts +22 -4
  80. package/src/providers/detect.ts +2 -1
  81. package/src/providers/router.ts +13 -0
  82. package/src/repo/repomap.ts +2 -29
  83. package/src/session/checkpoint.ts +27 -9
  84. package/src/session/journal.ts +27 -5
  85. package/src/skills/loader.ts +88 -5
  86. package/src/telemetry/trace.ts +36 -15
  87. package/src/tools/ask_user.ts +73 -4
  88. package/src/tools/bash.ts +15 -17
  89. package/src/tools/glob.ts +10 -11
  90. package/src/tools/lsp.ts +3 -56
  91. package/src/tools/memory.ts +13 -12
  92. package/src/tools/task.ts +1 -0
  93. package/src/ui/approval/prompt.ts +14 -6
  94. package/src/ui/assistant/simple.ts +137 -26
  95. package/src/ui/assistant/turn-status.ts +16 -3
  96. package/src/ui/contract.ts +119 -0
  97. package/src/ui/footer.ts +21 -2
  98. package/src/ui/i18n/en.ts +34 -6
  99. package/src/ui/i18n/id.ts +34 -6
  100. package/src/ui/i18n/locale.ts +3 -1
  101. package/src/ui/input/input.ts +51 -4
  102. package/src/ui/input/prompt-engine.ts +46 -4
  103. package/src/ui/render/collapse.ts +13 -13
  104. package/src/ui/render/diff.ts +7 -2
  105. package/src/ui/render/format.ts +16 -8
  106. package/src/ui/render/highlight.ts +7 -3
  107. package/src/ui/render/markdown.ts +5 -1
  108. package/src/ui/render/sanitize.ts +29 -2
  109. package/src/ui/render/table.ts +8 -5
  110. package/src/ui/render/theme.ts +18 -4
  111. package/src/ui/render/width.ts +89 -10
  112. package/src/ui/runtime/motion.ts +16 -0
  113. package/src/ui/runtime/screen.ts +45 -0
  114. package/src/ui/runtime/spinner.ts +50 -4
  115. package/src/ui/runtime/statusline.ts +50 -1
  116. package/src/ui/screens/form.ts +42 -15
  117. package/src/ui/screens/model-manager.ts +26 -18
  118. package/src/ui/screens/picker.ts +47 -23
  119. package/src/ui/screens/provider-manager.ts +18 -12
  120. package/src/ui/screens/wizard.ts +24 -8
  121. package/src/ui/tui/app.ts +233 -27
  122. package/src/ui/tui/transcript.ts +269 -65
  123. package/vendor/minicore/LICENSE +21 -0
  124. package/vendor/minicore/VENDOR.md +6 -3
  125. package/vendor/minicore/package.json +6 -3
  126. package/vendor/minicore/src/core/loop.ts +12 -2
  127. package/vendor/minicore/src/core/snapshot.ts +4 -0
  128. package/vendor/minicore/src/providers/openai-compat.ts +76 -25
package/src/ui/tui/app.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  //
8
8
  // Batas lapisan: semua yang berbau sesi/model/turn datang via TuiHost yang
9
9
  // di-inject dari cli/ (composition root). src/ui TAK BOLEH impor cli/.
10
- import type { UiBus } from "../contract.ts"
10
+ import type { UiBus, UiPresentationActivity } from "../contract.ts"
11
11
  import { type FooterStatus, renderFooter } from "../footer.ts"
12
12
  import { t } from "../i18n/locale.ts"
13
13
  import {
@@ -15,6 +15,7 @@ import {
15
15
  createDecoderState,
16
16
  createKeyStreamPump,
17
17
  createState,
18
+ cursorLineIndex,
18
19
  type DecoderState,
19
20
  type KeyStreamPump,
20
21
  type PromptKey,
@@ -24,12 +25,20 @@ import {
24
25
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
25
26
  import { c } from "../render/theme.ts"
26
27
  import { chunkByWidth, displayWidth, truncateToWidth } from "../render/width.ts"
27
- import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
28
+ import { motionReduced } from "../runtime/motion.ts"
29
+ import {
30
+ type AltScreen,
31
+ forceRestoreScreenForSignal,
32
+ openAltScreen,
33
+ SYNC_UPDATE_END,
34
+ SYNC_UPDATE_START,
35
+ } from "../runtime/screen.ts"
28
36
  import type { Transcript } from "./transcript.ts"
29
37
 
30
38
  export interface TuiStatusSnapshot {
31
39
  footer: FooterStatus
32
40
  busy: boolean
41
+ pinnedActivity?: UiPresentationActivity
33
42
  }
34
43
 
35
44
  export interface TuiHost {
@@ -67,7 +76,7 @@ const MIN_ROWS = 10
67
76
  const MIN_COLS = 20
68
77
 
69
78
  const PROMPT_FIRST = "minicode › "
70
- const PROMPT_CONT = " "
79
+ const PROMPT_CONT = " · "
71
80
 
72
81
  interface RawStdin {
73
82
  setRawMode(v: boolean): void
@@ -88,6 +97,8 @@ export class TuiApp {
88
97
  private tick = 0
89
98
  /** Timestamp abort terakhir (ms) — deteksi double-tap Esc/Ctrl+C = quit. */
90
99
  private lastAbortAt = 0
100
+ /** Hint "tekan lagi untuk keluar" tampil sekali setelah abort pertama. */
101
+ private abortHintOn = false
91
102
  private frames = 0
92
103
  private quitRequested = false
93
104
  private finish: (() => void) | null = null
@@ -95,6 +106,14 @@ export class TuiApp {
95
106
  private pump: KeyStreamPump | null = null
96
107
  private onData: ((chunk: Buffer) => void) | null = null
97
108
  private onResize: (() => void) | null = null
109
+ /**
110
+ * Dua wrapper sinyal terpisah — Bun tidak menyampaikan nama sinyal ke
111
+ * handler (argumen undefined, beda dengan Node), jadi pemetaan sinyal →
112
+ * exit code dilakukan lewat pemasangan per-sinyal ke core di bawah.
113
+ */
114
+ private onSignalTerm: (() => void) | null = null
115
+ private onSignalHup: (() => void) | null = null
116
+
98
117
  private wasRaw = false
99
118
  /**
100
119
  * Kedalaman suspend (popup komposit memegang fokus). >0 = listener stdin
@@ -116,6 +135,8 @@ export class TuiApp {
116
135
  private tailSize = 0
117
136
  /** Ukuran transkrip saat mulai scroll ke atas (basis hitung baris baru). */
118
137
  private scrollBase = 0
138
+ /** Panjang visual terakhir (kunci posisi baca agar stream tak merampasnya). */
139
+ private lastWrapped = 0
119
140
 
120
141
  constructor(
121
142
  private readonly transcript: Transcript,
@@ -156,7 +177,10 @@ export class TuiApp {
156
177
  // Saat popup fokus, view popup yang melukis ulang regionnya sendiri;
157
178
  // repaint penuh App akan menghapus popup dari layar.
158
179
  if (this.suspended > 0) return
159
- this.paint(screen)
180
+ // Lukis layar AKTIF (bukan handle `screen` run() yang basi setelah
181
+ // release+reacquire gagal — dulu repaint/resize melukis ke handle
182
+ // tertutup sekaligus menimpa currentScreen baru dengannya).
183
+ this.paintCurrent()
160
184
  }
161
185
  try {
162
186
  stdin.setRawMode(true)
@@ -170,6 +194,42 @@ export class TuiApp {
170
194
  removeListener(e: string, fn: () => void): void
171
195
  }
172
196
  stdout.on("resize", this.onResize)
197
+ // Sinyal fatal (temuan audit TUI-001): default kernel-kill TIDAK
198
+ // menjalankan handler "exit" Node — terminal bisa tertinggal alt-screen
199
+ // + raw mode. Dipasang per-run, dilepas di cleanup (pasangan ketat).
200
+ // Handler TERPISAH per sinyal: Bun TIDAK menyampaikan nama sinyal ke
201
+ // handler (argumen undefined — beda dengan Node), jadi satu handler
202
+ // bersama tak bisa membedakan TERM vs HUP dari parameternya.
203
+ // WAJIB tetap di blok sinkron yang sama dengan openAltScreen() di atas
204
+ // (tanpa await di antaranya): sinyal hanya disampaikan antar-tick event
205
+ // loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
206
+ // membuka race SIGTERM sebelum handler terpasang.
207
+ const restoreAndExit = (code: number) => {
208
+ try {
209
+ stdin.setRawMode(false)
210
+ } catch {}
211
+ try {
212
+ stdin.pause()
213
+ } catch {}
214
+ try {
215
+ stdin.removeListener("data", this.onData!)
216
+ } catch {}
217
+ forceRestoreScreenForSignal()
218
+ // exit() eksplisit memicu handler "exit" yang tersisa (spinner,
219
+ // turn-status) — best-effort sinkron. 128+n = konvensi "mati oleh
220
+ // sinyal n" (SIGTERM=15 → 143, SIGHUP=1 → 129) agar automation
221
+ // tetap bisa membedakan sebab.
222
+ process.exit(code)
223
+ }
224
+ this.onSignalTerm = () => restoreAndExit(143)
225
+ this.onSignalHup = () => restoreAndExit(129)
226
+ try {
227
+ process.on("SIGTERM", this.onSignalTerm)
228
+ process.on("SIGHUP", this.onSignalHup)
229
+ } catch {
230
+ this.onSignalTerm = null
231
+ this.onSignalHup = null
232
+ }
173
233
  // Repaint live mengikuti event bus (stream teks, ledger, thinking).
174
234
  // Suspend menahan repaint (popup melukis sendiri); quit menahan semua.
175
235
  const requestPaint = () => {
@@ -177,7 +237,7 @@ export class TuiApp {
177
237
  if (this.repaintTimer !== undefined) return
178
238
  this.repaintTimer = setTimeout(() => {
179
239
  this.repaintTimer = undefined
180
- if (!this.quitRequested && this.suspended === 0 && !this.released) this.paint(screen)
240
+ if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
181
241
  }, 30)
182
242
  try {
183
243
  ;(this.repaintTimer as unknown as { unref?: () => void }).unref?.()
@@ -195,7 +255,7 @@ export class TuiApp {
195
255
  sub("turn:started")
196
256
  sub("turn:completed")
197
257
  sub("context:compacted")
198
- this.tailSize = this.transcript.size()
258
+ this.tailSize = this.transcript.total()
199
259
  this.scrollBase = this.tailSize
200
260
  this.paint(screen)
201
261
  await done
@@ -215,6 +275,18 @@ export class TuiApp {
215
275
  this.busUnsubs = []
216
276
  this.suspended = 0
217
277
  this.released = false
278
+ if (this.onSignalTerm) {
279
+ try {
280
+ process.off("SIGTERM", this.onSignalTerm)
281
+ } catch {}
282
+ this.onSignalTerm = null
283
+ }
284
+ if (this.onSignalHup) {
285
+ try {
286
+ process.off("SIGHUP", this.onSignalHup)
287
+ } catch {}
288
+ this.onSignalHup = null
289
+ }
218
290
  this.stdin = null
219
291
  this.pump.dispose()
220
292
  this.pump = null
@@ -250,20 +322,40 @@ export class TuiApp {
250
322
  }
251
323
 
252
324
  private handleKey(key: PromptKey): void {
253
- // Terminal menciut di bawah minimum: abaikan SEMUA kecuali keluar.
254
- // Tanpa ini layout rusak (kolom negatif, kursor melompat) dan user
255
- // terkunci tanpa jalan keluar yang terlihat.
256
- if (this.tooSmall()) {
257
- if (key.type === "ctrl-d") this.quit()
258
- return
259
- }
260
- // Scroll SELALU tersedia (menu buka/tutup, busy/idle) — di-intercept
261
- // sebelum engine supaya tak jadi histori maupun teks.
325
+ // Scroll SELALU tersedia (menu buka/tutup, busy/idle, layar menciut) —
326
+ // di-intercept sebelum engine supaya tak jadi histori maupun teks.
327
+ // Dulu di bawah gate tooSmall: terminal menciut + turn busy = tak bisa
328
+ // scroll maupun abort (harus kill -9).
329
+ // Shift+PgUp/PgDn (ESC[5;2~/6;2~, didekode modifier 2 = shift) = setengah
330
+ // halaman (temuan audit TUI-002): halaman penuh terlalu kasar untuk
331
+ // transkrip panjang; Home/End = lompat top/tail (di bawah).
262
332
  if (key.type === "pageup" || key.type === "pagedown") {
333
+ const mod = key.modifier ?? 0
334
+ if (mod === 2) {
335
+ this.scrollBy(key.type === "pageup" ? 0.5 : -0.5)
336
+ return
337
+ }
263
338
  this.scrollBy(key.type === "pageup" ? 1 : -1)
264
339
  return
265
340
  }
266
- // Abort/batal: Esc & Ctrl+C. Saat busy = abort turn; idle = bersih baris.
341
+ // Home/End LOMPAT transkrip HANYA saat prompt kosong & tanpa dropdown
342
+ // (temuan audit TUI-002): transkrip cap 5000 baris ≈ 125 halaman —
343
+ // menekan PgUp 125× bukan navigasi. Home = baris teratas, End = kembali
344
+ // ke ekor. Baris BERISI = tombol editing (awal/akhir baris, kontrak lama);
345
+ // dropdown terbuka = navigasi menu (jalur engine).
346
+ if ((key.type === "home" || key.type === "end") && !this.state.menuOpen && !this.state.line) {
347
+ const logical = key.type === "home"
348
+ if (logical || this.scrollBack !== 0) {
349
+ this.jumpEdge(logical)
350
+ return
351
+ }
352
+ // End saat sudah di ekor: biarkan ke engine (kebiasaan editing —
353
+ // tidak ada yang berubah, action "none").
354
+ this.applyEngine(key)
355
+ return
356
+ }
357
+ // Abort/batal: Esc & Ctrl+C — berlaku juga saat layar menciut (jalan
358
+ // keluar saat terminal mengecil di tengah turn busy).
267
359
  // Jalan keluar saat abort macet (provider/tool non-kooperatif abaikan
268
360
  // sinyal): Esc/Ctrl+C KEDUA dalam 1.5 dtk, atau Ctrl+D baris-kosong,
269
361
  // = abort + quit. Tanpa ini sesi hanya bisa dibunuh kill -9 (kontrak I14).
@@ -274,10 +366,17 @@ export class TuiApp {
274
366
  } catch {}
275
367
  const now = Date.now()
276
368
  const doubleTap = now - this.lastAbortAt < 1500
369
+ // Hint "tekan lagi untuk keluar" SEKALI setelah abort pertama (temuan
370
+ // audit TUI-005): tanpa ini user yang menekan Esc dua kali untuk
371
+ // "memastikan" justru keluar sesi tanpa sengaja — transkrip TUI hilang.
372
+ // Hanya saat TIDAK double-tap; saat menciut indikator tak dilukis.
373
+ if (!doubleTap) this.abortHintOn = true
277
374
  this.lastAbortAt = now
278
375
  if (doubleTap) this.quit()
376
+ else this.paintCurrent()
279
377
  return
280
378
  }
379
+ if (this.tooSmall()) return
281
380
  if (key.type === "esc" && this.state.menuOpen) {
282
381
  this.applyEngine(key)
283
382
  return
@@ -289,6 +388,13 @@ export class TuiApp {
289
388
  }
290
389
  return
291
390
  }
391
+ // Terminal menciut di bawah minimum: abaikan SEMUA kecuali keluar.
392
+ // Tanpa ini layout rusak (kolom negatif, kursor melompat) dan user
393
+ // terkunci tanpa jalan keluar yang terlihat.
394
+ if (this.tooSmall()) {
395
+ if (key.type === "ctrl-d") this.quit()
396
+ return
397
+ }
292
398
  // Saat turn berjalan SEMUA input dibekukan kecuali abort (Esc/Ctrl+C),
293
399
  // scroll (PgUp/PgDn di atas), dan Ctrl+D baris-kosong (= abort + quit,
294
400
  // jalan keluar saat abort macet — kontrak I14).
@@ -330,8 +436,33 @@ export class TuiApp {
330
436
  this.historySearch()
331
437
  return
332
438
  }
333
- // Up/Down di luar menu = histori (bukan scroll — scroll milik PgUp/PgDn).
439
+ // Up/Down di luar menu: jika teks multi-line, navigasi baris dalam teks dulu.
440
+ // Hanya picu navigasi histori bila Up di baris pertama atau Down di baris terakhir.
334
441
  if ((key.type === "up" || key.type === "down") && !this.state.menuOpen) {
442
+ if (this.state.line.includes("\n")) {
443
+ const { lineIdx, colIdx } = cursorLineIndex(this.state.line, this.state.cursor)
444
+ const lines = this.state.line.split("\n")
445
+ if (key.type === "up" && lineIdx > 0) {
446
+ const targetLine = lineIdx - 1
447
+ const targetCol = Math.min(colIdx, toGraphemes(lines[targetLine] ?? "").length)
448
+ let newCursor = 0
449
+ for (let i = 0; i < targetLine; i++) newCursor += toGraphemes(lines[i] ?? "").length + 1
450
+ newCursor += targetCol
451
+ this.state = { ...this.state, cursor: newCursor }
452
+ this.paintCurrent()
453
+ return
454
+ }
455
+ if (key.type === "down" && lineIdx < lines.length - 1) {
456
+ const targetLine = lineIdx + 1
457
+ const targetCol = Math.min(colIdx, toGraphemes(lines[targetLine] ?? "").length)
458
+ let newCursor = 0
459
+ for (let i = 0; i < targetLine; i++) newCursor += toGraphemes(lines[i] ?? "").length + 1
460
+ newCursor += targetCol
461
+ this.state = { ...this.state, cursor: newCursor }
462
+ this.paintCurrent()
463
+ return
464
+ }
465
+ }
335
466
  this.historyNav(key.type === "up" ? -1 : 1)
336
467
  return
337
468
  }
@@ -361,6 +492,7 @@ export class TuiApp {
361
492
  this.state = createState()
362
493
  this.histIdx = -1
363
494
  this.followTail()
495
+ this.abortHintOn = false
364
496
  if (!line) {
365
497
  this.paintCurrent()
366
498
  return
@@ -473,6 +605,21 @@ export class TuiApp {
473
605
  return this.suspended > 0
474
606
  }
475
607
 
608
+ /**
609
+ * Bungkus baris dengan mode redup (\x1b[2m) untuk backdrop popup.
610
+ * Reset (\x1b[0m atau \x1b[22m) dan bold (\x1b[1m) di dalam teks dinetralkan
611
+ * agar peredupan tidak bocor di tengah baris yang diwarnai.
612
+ */
613
+ static applyBackdropDim(ln: string): string {
614
+ if (!ln) return ""
615
+ const esc = String.fromCharCode(27)
616
+ let s = ln.replaceAll(`${esc}[1m`, "")
617
+ s = s.replaceAll(`${esc}[22m`, `${esc}[2m`)
618
+ s = s.replaceAll(`${esc}[0m`, `${esc}[0m${esc}[2m`)
619
+ s = s.replaceAll(`${esc}[m`, `${esc}[0m${esc}[2m`)
620
+ return `${esc}[2m${s}${esc}[22m${esc}[0m`
621
+ }
622
+
476
623
  /** Layar redup sebagai backdrop popup: frame normal dibungkus faint. */
477
624
  private paintDimmed(): void {
478
625
  const screen = this.currentScreen
@@ -488,7 +635,7 @@ export class TuiApp {
488
635
  const body = this.transcript.view(cols, viewH, this.scrollBack)
489
636
  const frame: string[] = [...body, ...menu, ...inputAll.slice(-inputH), statusLine]
490
637
  while (frame.length < rows) frame.unshift("")
491
- const dimmed = frame.slice(-rows).map((ln) => `\x1b[2m${ln}\x1b[22m`)
638
+ const dimmed = frame.slice(-rows).map((ln) => TuiApp.applyBackdropDim(ln))
492
639
  try {
493
640
  screen.paint(dimmed)
494
641
  } catch {}
@@ -553,11 +700,37 @@ export class TuiApp {
553
700
  const rows = process.stdout.rows || 24
554
701
  const page = Math.max(1, this.viewportHeight(rows, process.stdout.columns || 80) - 1)
555
702
  // scrollBack dihitung dalam BARIS agar presisi di terminal pendek. Basis
556
- // hitung "baris baru" dicatat saat mulai meninggalkan ekor.
557
- if (this.scrollBack === 0 && pages > 0) this.scrollBase = this.transcript.size()
558
- this.scrollBack = Math.max(0, this.scrollBack + pages * page)
703
+ // hitung "baris baru" dicatat saat mulai meninggalkan ekor. total()
704
+ // (monotonik) dipakai agar evict cap 5000 tak merusak hitungan.
705
+ // pages pecahan (±0.5) = setengah halaman (temuan audit TUI-002).
706
+ if (this.scrollBack === 0 && pages > 0) this.scrollBase = this.transcript.total()
707
+ this.scrollBack = Math.max(0, Math.round(this.scrollBack + pages * page))
559
708
  if (this.scrollBack === 0) {
560
- this.tailSize = this.transcript.size()
709
+ this.tailSize = this.transcript.total()
710
+ this.scrollBase = this.tailSize
711
+ }
712
+ this.paintCurrent()
713
+ }
714
+
715
+ /**
716
+ * Lompat ke ujung transkrip (temuan audit TUI-002): Home = baris teratas
717
+ * (scrollBack maksimum), End = ekor. `lastWrapped` dinetralkan SEBELUM
718
+ * perhitungan kunci-posisi-baca berikutnya: jendela yang sengaja dipindah
719
+ * user bukan drift stream, tanpa ini paint pertama post-jump menarik
720
+ * viewport kembali ke ekor (lompatan tak terlihat).
721
+ */
722
+ private jumpEdge(top: boolean): void {
723
+ const rows = process.stdout.rows || 24
724
+ const cols = process.stdout.columns || 80
725
+ const curWrapped = this.transcript.wrappedLength(cols)
726
+ this.lastWrapped = curWrapped
727
+ if (top) {
728
+ const viewH = Math.max(1, this.viewportHeight(rows, cols) - 1)
729
+ if (this.scrollBack === 0) this.scrollBase = this.transcript.total()
730
+ this.scrollBack = Math.max(0, curWrapped - viewH)
731
+ } else {
732
+ this.scrollBack = 0
733
+ this.tailSize = this.transcript.total()
561
734
  this.scrollBase = this.tailSize
562
735
  }
563
736
  this.paintCurrent()
@@ -566,10 +739,19 @@ export class TuiApp {
566
739
  /** Kembali ke ekor: dipakai tiap ketikan/submit baru (I18). */
567
740
  private followTail(): void {
568
741
  this.scrollBack = 0
569
- this.tailSize = this.transcript.size()
742
+ this.tailSize = this.transcript.total()
570
743
  this.scrollBase = this.tailSize
571
744
  }
572
745
 
746
+ /** Kosongkan transkrip (/clear): viewport + basis scroll ikut di-reset agar
747
+ * tak tertinggal scrollBack basi (layar kosong + user harus PgDn manual). */
748
+ clearView(): void {
749
+ this.transcript.clear()
750
+ this.followTail()
751
+ this.lastWrapped = 0
752
+ this.paintCurrent()
753
+ }
754
+
573
755
  // ── Paint ──
574
756
 
575
757
  private currentScreen: AltScreen | null = null
@@ -666,17 +848,38 @@ export class TuiApp {
666
848
  return
667
849
  }
668
850
  const snap = this.host.getStatus()
851
+ // MINICODE_MOTION=0 (temuan audit TUI-006): spark statis redup — status
852
+ // busy tak boleh bergantung pada animasi (aksesibilitas / rec / SSH lambat).
669
853
  this.tick = snap.busy ? this.tick + 1 : 0
670
854
  const statusLine =
671
- renderFooter({ ...snap.footer, sparkFrame: snap.busy ? this.tick : 0 }, cols)[0] ?? ""
855
+ renderFooter(
856
+ { ...snap.footer, sparkFrame: snap.busy && !motionReduced() ? this.tick : 0 },
857
+ cols,
858
+ )[0] ?? ""
672
859
  const menu = this.menuRows(rows, cols)
673
860
  const inputAll = this.inputRows(cols)
674
861
  const inputH = Math.min(MAX_INPUT_ROWS, Math.max(1, inputAll.length))
675
862
  // Indikator "output baru di bawah": user membaca ke atas saat stream
676
863
  // masuk — tanpa ini output baru lewat diam-diam. Makan 1 baris viewport.
677
- const newCount = this.scrollBack > 0 ? this.transcript.size() - this.scrollBase : 0
678
- const indicator = newCount > 0 ? [c.muted(t("app.newBelow", { n: newCount }))] : []
864
+ // total() monotonik: evict cap tak membuat hitungan negatif/hilang.
865
+ const newCount = this.scrollBack > 0 ? this.transcript.total() - this.scrollBase : 0
866
+ // Indikator + hint abort saling eksklusif (satu slot): scroll memakai slot
867
+ // untuk "baris baru"; abort memakainya untuk petunjuk keluar.
868
+ const indicator: string[] = []
869
+ if (newCount > 0) indicator.push(c.muted(t("app.newBelow", { n: newCount })))
870
+ else if (this.busy && this.abortHintOn) indicator.push(c.warning(t("app.abortHint")))
679
871
  const viewH = Math.max(1, rows - 1 - inputH - menu.length - indicator.length)
872
+ // Kunci posisi baca: stream yang menambah baris saat user scroll ke atas
873
+ // ikut menggeser scrollBack agar jendela menunjuk baris absolut yang sama
874
+ // (dulu viewport merayap mengikuti ekor — kontrak I17).
875
+ const curWrapped = this.transcript.wrappedLength(cols)
876
+ if (this.scrollBack > 0 && this.lastWrapped > 0) {
877
+ this.scrollBack = Math.max(
878
+ 0,
879
+ Math.min(this.scrollBack + (curWrapped - this.lastWrapped), Math.max(0, curWrapped - 1)),
880
+ )
881
+ }
882
+ this.lastWrapped = curWrapped
680
883
  const body = this.transcript.view(cols, viewH, this.scrollBack)
681
884
  // Jendela input mengikuti kursor: bila kursor di atas jendela ekor
682
885
  // (mis. paste 10 baris lalu Home), gulir ke atas agar kursor terlihat.
@@ -692,10 +895,13 @@ export class TuiApp {
692
895
  screen.paint(out)
693
896
  } catch {}
694
897
  // Parkir kursor di posisi ketik (kolom terminal, bukan karakter).
898
+ // Di dalam blok sync-update yang SAMA dengan frame (temuan audit TUI-007):
899
+ // kursor yang ditulis setelah SYNC_END berpotensi tearing di emulator
900
+ // tanpa ?2026 (frame tampil, kursor satu posisi lama).
695
901
  const cursorRow = viewH + menu.length + indicator.length + (cursor.visIdx - winStart) + 1
696
902
  try {
697
903
  process.stdout.write(
698
- `\x1b[?25l\x1b[${Math.max(1, cursorRow)};${Math.max(1, cursor.col)}H\x1b[?25h`,
904
+ `${SYNC_UPDATE_START}\x1b[?25l\x1b[${Math.max(1, cursorRow)};${Math.max(1, cursor.col)}H\x1b[?25h${SYNC_UPDATE_END}`,
699
905
  )
700
906
  } catch {}
701
907
  this.frames++