minicode-ai 0.27.0 → 0.30.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 (145) hide show
  1. package/README.md +1 -1
  2. package/cli/args.ts +184 -57
  3. package/cli/bootstrap/presentation-bridge.ts +383 -0
  4. package/cli/commands/acp.ts +45 -29
  5. package/cli/commands/auth.ts +17 -17
  6. package/cli/commands/config.ts +65 -66
  7. package/cli/commands/daemon.ts +44 -16
  8. package/cli/commands/doctor.ts +18 -15
  9. package/cli/commands/exec.ts +41 -89
  10. package/cli/commands/mcp.ts +25 -8
  11. package/cli/commands/memory.ts +16 -24
  12. package/cli/commands/openwork.ts +6 -2
  13. package/cli/commands/pricing.ts +14 -12
  14. package/cli/commands/providers.ts +36 -57
  15. package/cli/commands/sessions.ts +24 -18
  16. package/cli/commands/skills.ts +33 -18
  17. package/cli/commands/stats.ts +15 -30
  18. package/cli/commands.ts +73 -44
  19. package/cli/context-command-run.ts +30 -18
  20. package/cli/index.ts +51 -100
  21. package/cli/model-manager.ts +7 -2
  22. package/cli/provider-manager.ts +33 -18
  23. package/cli/router.ts +41 -12
  24. package/cli/setup.ts +241 -485
  25. package/cli/tui.ts +303 -100
  26. package/docs/TERMINAL_CONTRACT.md +258 -73
  27. package/docs/UI_RENDER_PIPELINE.md +9 -1
  28. package/docs/agents.md +2 -2
  29. package/docs/architecture.md +17 -32
  30. package/docs/choosing-mode.md +7 -9
  31. package/docs/cli.md +3 -5
  32. package/docs/environment.md +1 -2
  33. package/docs/policy-sandbox.md +3 -3
  34. package/docs/repl.md +2 -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 +144 -68
  40. package/src/app/tool-layer.ts +38 -16
  41. package/src/config.ts +64 -104
  42. package/src/constants.ts +4 -6
  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/atomic-write.ts +31 -59
  48. package/src/lib/db-path.ts +47 -0
  49. package/src/lib/process-tree.ts +62 -0
  50. package/src/lib/public-http.ts +88 -23
  51. package/src/lib/trusted-exec.ts +48 -1
  52. package/src/lsp/client.ts +62 -17
  53. package/src/mcp/client.ts +85 -38
  54. package/src/mcp/http-transport.ts +28 -16
  55. package/src/mcp/transport.ts +42 -6
  56. package/src/memory/files.ts +164 -134
  57. package/src/memory/vector.ts +371 -420
  58. package/src/policy/approval-binding.ts +122 -45
  59. package/src/policy/bash-guard.ts +18 -7
  60. package/src/policy/compaction.ts +51 -18
  61. package/src/policy/context-window.ts +31 -8
  62. package/src/policy/context.ts +62 -36
  63. package/src/policy/executor.ts +17 -7
  64. package/src/policy/jail.ts +6 -8
  65. package/src/policy/microcompact.ts +4 -3
  66. package/src/policy/no-progress.ts +103 -22
  67. package/src/policy/permission.ts +36 -12
  68. package/src/policy/tool-contract.ts +74 -416
  69. package/src/policy/usage.ts +24 -2
  70. package/src/policy/verifier.ts +50 -2
  71. package/src/policy/work-mode.ts +28 -54
  72. package/src/presentation/adapter.ts +24 -16
  73. package/src/providers/anthropic.ts +16 -5
  74. package/src/providers/provision.ts +6 -56
  75. package/src/providers/responses.ts +38 -7
  76. package/src/providers/sse-bounds.ts +6 -4
  77. package/src/runtime/execution-journal.ts +4 -29
  78. package/src/sandbox/docker.ts +58 -34
  79. package/src/sandbox/mask.ts +157 -0
  80. package/src/sandbox/os.ts +107 -73
  81. package/src/session/authority.ts +29 -10
  82. package/src/session/context-projection.ts +6 -5
  83. package/src/session/db/runs.ts +397 -0
  84. package/src/session/db/schema.ts +358 -0
  85. package/src/session/open-work.ts +26 -3
  86. package/src/session/persistence.ts +74 -998
  87. package/src/session/verification.ts +170 -20
  88. package/src/skills/loader.ts +31 -16
  89. package/src/task/db/schema.ts +325 -0
  90. package/src/task/db/types.ts +269 -0
  91. package/src/task/production-scheduler.ts +13 -1
  92. package/src/task/store.ts +92 -1021
  93. package/src/telemetry/trace.ts +27 -0
  94. package/src/tools/ask_user.ts +1 -13
  95. package/src/tools/bash.ts +27 -92
  96. package/src/tools/code_run.ts +1 -1
  97. package/src/tools/context.ts +133 -0
  98. package/src/tools/delete_file.ts +3 -2
  99. package/src/tools/edit.ts +37 -72
  100. package/src/tools/git.ts +86 -9
  101. package/src/tools/glob.ts +26 -51
  102. package/src/tools/grep.ts +67 -57
  103. package/src/tools/hashline.ts +4 -0
  104. package/src/tools/lsp.ts +11 -8
  105. package/src/tools/mcp_call.ts +9 -6
  106. package/src/tools/memory.ts +56 -33
  107. package/src/tools/move_file.ts +36 -10
  108. package/src/tools/patch.ts +13 -21
  109. package/src/tools/read_file.ts +18 -25
  110. package/src/tools/read_image.ts +35 -33
  111. package/src/tools/submit_result.ts +29 -8
  112. package/src/tools/task.ts +74 -17
  113. package/src/tools/todo.ts +181 -74
  114. package/src/tools/web_fetch.ts +42 -2
  115. package/src/tools/web_search.ts +47 -8
  116. package/src/ui/approval/prompt.ts +206 -47
  117. package/src/ui/assistant/turn-status.ts +14 -5
  118. package/src/ui/footer.ts +4 -4
  119. package/src/ui/i18n/en.ts +47 -23
  120. package/src/ui/i18n/id.ts +76 -51
  121. package/src/ui/input/input.ts +4 -3
  122. package/src/ui/input/prompt-engine.ts +35 -5
  123. package/src/ui/render/activity-panel.ts +4 -2
  124. package/src/ui/render/hint.ts +7 -4
  125. package/src/ui/render/list.ts +32 -0
  126. package/src/ui/render/markdown.ts +6 -3
  127. package/src/ui/render/notice.ts +19 -0
  128. package/src/ui/render/table-grid.ts +7 -8
  129. package/src/ui/render/theme.ts +113 -39
  130. package/src/ui/runtime/screen.ts +74 -10
  131. package/src/ui/runtime/spinner.ts +19 -6
  132. package/src/ui/screens/dialog.ts +19 -1
  133. package/src/ui/screens/form.ts +80 -35
  134. package/src/ui/screens/model-manager.ts +82 -61
  135. package/src/ui/screens/output-window.ts +263 -0
  136. package/src/ui/screens/picker.ts +94 -81
  137. package/src/ui/screens/provider-manager.ts +100 -69
  138. package/src/ui/screens/wizard.ts +117 -28
  139. package/src/ui/tui/app.ts +196 -33
  140. package/src/ui/tui/transcript.ts +158 -25
  141. package/vendor/minicore/src/core/executor.ts +2 -0
  142. package/vendor/minicore/src/core/loop.ts +17 -6
  143. package/vendor/minicore/src/core/session.ts +3 -0
  144. package/vendor/minicore/src/core/tool.ts +1 -0
  145. package/vendor/minicore/src/providers/openai-compat.ts +35 -19
package/src/ui/tui/app.ts CHANGED
@@ -25,11 +25,17 @@ import {
25
25
  } from "../input/prompt-engine.ts"
26
26
  import { appendWrapped, shaveWrapped } from "../render/composer-wrap.ts"
27
27
  import { formatError } from "../render/errors.ts"
28
+ import { listRow } from "../render/list.ts"
28
29
  import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
29
- import { c, scrimMode, scrimSgr } from "../render/theme.ts"
30
+ import { c, glyphs, scrimMode, scrimSgr } from "../render/theme.ts"
30
31
  import { chunkByWidth, displayWidth, escapeLength, truncateToWidth } from "../render/width.ts"
31
32
  import { motionReduced } from "../runtime/motion.ts"
32
- import { type AltScreen, forceRestoreScreenForSignal, openAltScreen } from "../runtime/screen.ts"
33
+ import {
34
+ type AltScreen,
35
+ forceRestoreScreenForSignal,
36
+ openAltScreen,
37
+ registerScreenBackdrop,
38
+ } from "../runtime/screen.ts"
33
39
  import type { Transcript, TranscriptPoint, TranscriptRow } from "./transcript.ts"
34
40
 
35
41
  export interface TuiStatusSnapshot {
@@ -75,8 +81,8 @@ const MAX_DROPDOWN_ROWS = 8
75
81
  const MIN_ROWS = 10
76
82
  const MIN_COLS = 20
77
83
 
78
- const PROMPT_FIRST = "minicode › "
79
- const PROMPT_CONT = " · "
84
+ const promptFirst = (): string => `minicode ${glyphs.arrow} `
85
+ const promptCont = (): string => ` ${glyphs.dot} `
80
86
  const TIMER_TEXT = "00.00.00"
81
87
  const DOT_INTERVAL_MS = 200
82
88
  /** Badge job background berputar lebih pelan dari dots (tidak berkedip). */
@@ -251,6 +257,9 @@ export class TuiApp {
251
257
  private lastAbortAt = 0
252
258
  /** Hint "tekan lagi untuk keluar" tampil sekali setelah abort pertama. */
253
259
  private abortHintOn = false
260
+ /** Micro-toast 2 detik di slot footer saat mengganti mode/bahasa/salin. */
261
+ private statusToast = ""
262
+ private toastTimer: ReturnType<typeof setTimeout> | undefined
254
263
  private frames = 0
255
264
  /**
256
265
  * Kedalaman batch input. Selama >0 paint ditunda lalu digabung jadi SATU
@@ -287,6 +296,7 @@ export class TuiApp {
287
296
  /** True setelah releaseTerminal (spawn anak): paint/repaint ditahan. */
288
297
  private released = false
289
298
  private mouseMode: MouseMode = "off"
299
+ private releaseBackdrop: (() => void) | null = null
290
300
  private selection: SelectionState | null = null
291
301
  private lastLayout: FrameLayout | null = null
292
302
  /**
@@ -300,6 +310,7 @@ export class TuiApp {
300
310
  cursor: number
301
311
  cols: number
302
312
  editing: boolean
313
+ prompt: string
303
314
  layout: ComposerLayout
304
315
  } | null = null
305
316
  private onExit: (() => void) | null = null
@@ -532,9 +543,15 @@ export class TuiApp {
532
543
  clearTimeout(this.repaintTimer)
533
544
  this.repaintTimer = undefined
534
545
  }
546
+ if (this.toastTimer !== undefined) {
547
+ clearTimeout(this.toastTimer)
548
+ this.toastTimer = undefined
549
+ }
550
+ this.statusToast = ""
535
551
  this.stopActivityClock()
536
552
  this.stopWaitingClock()
537
553
  this.stopAutoScroll()
554
+ this.clearBackdrop()
538
555
  for (const unsubscribe of this.busUnsubs.splice(0)) {
539
556
  try {
540
557
  unsubscribe()
@@ -649,6 +666,17 @@ export class TuiApp {
649
666
  return
650
667
  }
651
668
  if (key.type === "wheelup" || key.type === "wheeldown") {
669
+ if (
670
+ !this.tooSmall() &&
671
+ !this.isBusy() &&
672
+ this.editing &&
673
+ this.state.menuOpen &&
674
+ this.state.line.startsWith("/") &&
675
+ this.host.listCommands(this.state.line).length > 0
676
+ ) {
677
+ this.applyEngine({ type: key.type === "wheelup" ? "up" : "down" })
678
+ return
679
+ }
652
680
  this.scrollBy(key.type === "wheelup" ? 0.5 : -0.5)
653
681
  return
654
682
  }
@@ -744,13 +772,33 @@ export class TuiApp {
744
772
  return
745
773
  }
746
774
  if (key.type === "tab") {
775
+ // Saat dropdown `/` sedang terbuka dan punya kandidat, Tab melengkapi
776
+ // command ke composer tanpa langsung submit; selain itu putar WorkMode.
777
+ const hasMenu =
778
+ this.editing &&
779
+ this.state.menuOpen &&
780
+ this.state.line.startsWith("/") &&
781
+ this.host.listCommands(this.state.line).length > 0
782
+ if (hasMenu) {
783
+ this.applyEngine(key)
784
+ return
785
+ }
747
786
  this.host.cycleWorkMode(1)
748
- this.paintCurrent()
787
+ const wm = this.host.getStatus().footer.workMode
788
+ if (wm) {
789
+ const label = wm === "EXECUTE" ? "Build" : "Discuss"
790
+ this.showToast(t("tui.workModeLine", { m: label }))
791
+ } else {
792
+ this.paintCurrent()
793
+ }
749
794
  return
750
795
  }
751
796
  if (key.type === "shift-tab") {
752
797
  this.host.togglePermissionMode()
753
- this.paintCurrent()
798
+ const pm = this.host.getStatus().footer.mode
799
+ const label = pm ? `${pm[0]!.toUpperCase()}${pm.slice(1)}` : ""
800
+ if (label) this.showToast(t("tui.modeLine", { m: label }))
801
+ else this.paintCurrent()
754
802
  return
755
803
  }
756
804
  if (key.type === "ctrl-o") {
@@ -973,6 +1021,7 @@ export class TuiApp {
973
1021
  resume(): void {
974
1022
  if (this.released || this.suspended <= 0) return
975
1023
  if (--this.suspended > 0) return
1024
+ this.clearBackdrop()
976
1025
  try {
977
1026
  this.stdin?.setRawMode(true)
978
1027
  } catch {}
@@ -993,6 +1042,7 @@ export class TuiApp {
993
1042
  */
994
1043
  releaseTerminal(): void {
995
1044
  this.stopActivityClock()
1045
+ this.clearBackdrop()
996
1046
  try {
997
1047
  if (this.onData) this.stdin?.removeListener("data", this.onData)
998
1048
  } catch {}
@@ -1054,18 +1104,34 @@ export class TuiApp {
1054
1104
  return `${scrim}${s}${esc}[22m${esc}[0m`
1055
1105
  }
1056
1106
 
1107
+ private clearBackdrop(): void {
1108
+ try {
1109
+ this.releaseBackdrop?.()
1110
+ } catch {}
1111
+ this.releaseBackdrop = null
1112
+ }
1113
+
1057
1114
  /** Layar redup sebagai backdrop popup: frame normal dibungkus faint. */
1058
1115
  private paintDimmed(): void {
1059
1116
  const screen = this.currentScreen
1060
1117
  if (!screen) return
1061
1118
  const cols = screen.cols
1062
1119
  const rows = screen.rows
1063
- const snap = this.host.getStatus()
1064
- const layout = this.buildLayout(rows, cols, snap)
1065
- this.lastLayout = layout
1066
- const dimmed = layout.frame.map((ln) => TuiApp.applyBackdropDim(ln))
1067
- screen.paint(dimmed)
1120
+ const buildDimmed = (c: number, r: number): readonly string[] => {
1121
+ const snap = this.host.getStatus()
1122
+ const layout = this.buildLayout(r, c, snap)
1123
+ if (c === cols && r === rows) this.lastLayout = layout
1124
+ return layout.frame.map((ln) => TuiApp.applyBackdropDim(ln))
1125
+ }
1126
+ const dimmed = buildDimmed(cols, rows)
1127
+ screen.paint([...dimmed])
1068
1128
  this.frames++
1129
+ this.clearBackdrop()
1130
+ this.releaseBackdrop = registerScreenBackdrop(
1131
+ (c, r) => (c === cols && r === rows ? dimmed : buildDimmed(c, r)),
1132
+ cols,
1133
+ rows,
1134
+ )
1069
1135
  }
1070
1136
 
1071
1137
  private isBusy(): boolean {
@@ -1084,6 +1150,11 @@ export class TuiApp {
1084
1150
  if (this.history.length > 200) this.history.splice(0, this.history.length - 200)
1085
1151
  }
1086
1152
 
1153
+ /** Salinan histori prompt sesi ini (untuk perintah `/history` di TUI). */
1154
+ getHistory(): readonly string[] {
1155
+ return [...this.history]
1156
+ }
1157
+
1087
1158
  private historyNav(dir: -1 | 1): void {
1088
1159
  if (!this.history.length) return
1089
1160
  if (this.histIdx === -1) {
@@ -1301,10 +1372,27 @@ export class TuiApp {
1301
1372
  // Idle: prompt tetap tampil. Dulu baris kosong menggantikannya sehingga
1302
1373
  // setelah Esc/Enter-kosong layar terlihat mati (I13: prompt tampil saat
1303
1374
  // boot/idle) — audit 2026-11-12, MEDIUM-4.
1304
- if (!this.editing) return [chunkByWidth(PROMPT_FIRST, Math.max(10, cols))[0] ?? ""]
1375
+ if (!this.editing) return [chunkByWidth(promptFirst(), Math.max(10, cols))[0] ?? ""]
1305
1376
  return this.composerLayout(cols).rows
1306
1377
  }
1307
1378
 
1379
+ /** Tampilkan pesan status singkat (micro-toast) di slot footer selama `ms` ms. */
1380
+ showToast(text: string, ms = 2000): void {
1381
+ const clean = sanitizeAnsiLine(text).trim()
1382
+ if (!clean) return
1383
+ this.statusToast = clean
1384
+ if (this.toastTimer !== undefined) clearTimeout(this.toastTimer)
1385
+ this.toastTimer = setTimeout(() => {
1386
+ this.toastTimer = undefined
1387
+ this.statusToast = ""
1388
+ if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
1389
+ }, ms)
1390
+ try {
1391
+ ;(this.toastTimer as unknown as { unref?: () => void }).unref?.()
1392
+ } catch {}
1393
+ if (!this.quitRequested && this.suspended === 0 && !this.released) this.paintCurrent()
1394
+ }
1395
+
1308
1396
  private composerHeight(cols: number, busy = this.busy): number {
1309
1397
  if (busy || !this.editing) return 1
1310
1398
  return Math.min(MAX_INPUT_ROWS, Math.max(1, this.composerLayout(cols).rows.length))
@@ -1362,6 +1450,26 @@ export class TuiApp {
1362
1450
  }
1363
1451
  }
1364
1452
 
1453
+ /** Parkir kursor untuk pemilik region modal (approval/ask_user). */
1454
+ moveCursor(row: number, col: number): void {
1455
+ if (!this.currentScreen || this.quitRequested) return
1456
+ try {
1457
+ this.currentScreen.moveCursor(row, col)
1458
+ } catch (error) {
1459
+ this.stopAfterRuntimeError(error)
1460
+ }
1461
+ }
1462
+
1463
+ /** Atur visibilitas kursor untuk pemilik region modal (read-only/progress). */
1464
+ setCursorVisible(visible: boolean): void {
1465
+ if (!this.currentScreen || this.quitRequested) return
1466
+ try {
1467
+ this.currentScreen.setCursorVisible(visible)
1468
+ } catch (error) {
1469
+ this.stopAfterRuntimeError(error)
1470
+ }
1471
+ }
1472
+
1365
1473
  /** Hapus region popup (pasangan paintRegion); App akan repaint penuh saat resume. */
1366
1474
  clearRegion(): void {
1367
1475
  if (!this.currentScreen) return
@@ -1384,14 +1492,21 @@ export class TuiApp {
1384
1492
  const w = Math.max(10, cols)
1385
1493
  const line = this.state.line
1386
1494
  const cursor = this.state.cursor
1495
+ const pf = promptFirst()
1387
1496
  const cached = this.composerCache
1388
- if (cached?.editing && cached.cols === w && cached.cursor === cursor && cached.line === line) {
1497
+ if (
1498
+ cached?.editing &&
1499
+ cached.cols === w &&
1500
+ cached.cursor === cursor &&
1501
+ cached.line === line &&
1502
+ cached.prompt === pf
1503
+ ) {
1389
1504
  return cached.layout
1390
1505
  }
1391
1506
  const layout =
1392
- this.incrementalComposerLayout(cached, line, cursor, w) ??
1507
+ (cached?.prompt === pf ? this.incrementalComposerLayout(cached, line, cursor, w) : null) ??
1393
1508
  this.layoutComposer(line, cursor, w)
1394
- this.composerCache = { line, cursor, cols: w, editing: true, layout }
1509
+ this.composerCache = { line, cursor, cols: w, editing: true, prompt: pf, layout }
1395
1510
  return layout
1396
1511
  }
1397
1512
 
@@ -1440,11 +1555,13 @@ export class TuiApp {
1440
1555
  * potong per kolom, kursor di baris visual yang memuat targetWidth.
1441
1556
  */
1442
1557
  private layoutComposer(line: string, cursor: number, w: number): ComposerLayout {
1558
+ const pf = promptFirst()
1559
+ const pc = promptCont()
1443
1560
  // Prompt kosong SELALU satu baris utuh — sama dengan jalur lama. Tanpa
1444
1561
  // special-case, terminal sempit (w < lebar prefix) memecah prefix jadi dua
1445
1562
  // baris dan menggeser kursor; MIN_COLS membuatnya tak terjangkau di app,
1446
1563
  // tapi helper ini juga dipakai layout lain/test.
1447
- if (!line) return { rows: [PROMPT_FIRST], visIdx: 0, col: displayWidth(PROMPT_FIRST) + 1 }
1564
+ if (!line) return { rows: [pf], visIdx: 0, col: displayWidth(pf) + 1 }
1448
1565
  // Kursor dinormalisasi ke batas grapheme supaya emoji tak terbelah saat
1449
1566
  // dihitung (targetWidth memakai teks sebelum kursor).
1450
1567
  const units = toGraphemes(line)
@@ -1453,8 +1570,7 @@ export class TuiApp {
1453
1570
  const beforeLines = before.split("\n")
1454
1571
  const logicalIdx = beforeLines.length - 1
1455
1572
  const lastLine = beforeLines[logicalIdx] ?? ""
1456
- const targetWidth =
1457
- displayWidth(logicalIdx === 0 ? PROMPT_FIRST : PROMPT_CONT) + displayWidth(lastLine)
1573
+ const targetWidth = displayWidth(logicalIdx === 0 ? pf : pc) + displayWidth(lastLine)
1458
1574
 
1459
1575
  const rows: string[] = []
1460
1576
  const logical = line.split("\n")
@@ -1462,7 +1578,7 @@ export class TuiApp {
1462
1578
  let col = 1
1463
1579
  let cursorRowFound = false
1464
1580
  for (let li = 0; li < logical.length; li++) {
1465
- const prefix = li === 0 ? PROMPT_FIRST : PROMPT_CONT
1581
+ const prefix = li === 0 ? pf : pc
1466
1582
  const full = `${prefix}${logical[li] ?? ""}`
1467
1583
  const wrapped = chunkByWidth(full, w)
1468
1584
  for (const row of wrapped) rows.push(row)
@@ -1507,7 +1623,9 @@ export class TuiApp {
1507
1623
  shown.forEach((h, i) => {
1508
1624
  const picked = start + i === this.state.sel
1509
1625
  const text = sanitizeAnsiLine(h).replace(/^\/+/, "")
1510
- out.push(picked ? c.accent(c.bold(text)) : text)
1626
+ // Marker `›` + kolom marker tetap: seleksi terbaca tanpa warna dan
1627
+ // label tak bergeser saat panah berpindah.
1628
+ out.push(listRow(text, picked))
1511
1629
  })
1512
1630
  return out.map((l) => chunkByWidth(l, w)[0] ?? "")
1513
1631
  }
@@ -1558,22 +1676,32 @@ export class TuiApp {
1558
1676
  const targetRow = layout.composerOffset + relativeRow
1559
1677
  if (relativeRow < 0 || targetRow < 0) return false
1560
1678
  const w = Math.max(10, process.stdout.columns || 80)
1679
+ const pf = promptFirst()
1680
+ const pc = promptCont()
1561
1681
  const logical = this.state.line.split("\n")
1562
1682
  let rowIndex = 0
1563
1683
  let baseCodeUnits = 0
1564
1684
  for (let lineIndex = 0; lineIndex < logical.length; lineIndex++) {
1565
1685
  const line = logical[lineIndex] ?? ""
1566
- const prefix = lineIndex === 0 ? PROMPT_FIRST : PROMPT_CONT
1686
+ const prefix = lineIndex === 0 ? pf : pc
1567
1687
  const rows = chunkByWidth(`${prefix}${line}`, w)
1568
1688
  if (targetRow < rowIndex + rows.length) {
1569
- const row = rows[targetRow - rowIndex] ?? ""
1689
+ const localRow = targetRow - rowIndex
1690
+ // Baris ter-wrap: jumlahkan panjang grapheme baris visual sebelumnya
1691
+ // di baris logis yang sama supaya klik di baris lanjutan akurat.
1692
+ let precedingGraphemes = 0
1693
+ for (let ri = 0; ri < localRow; ri++) {
1694
+ const prevPlain = stripSgr(sanitizeAnsi(rows[ri] ?? ""))
1695
+ const prevBody =
1696
+ ri === 0 && prevPlain.startsWith(prefix) ? prevPlain.slice(prefix.length) : prevPlain
1697
+ precedingGraphemes += toGraphemes(prevBody).length
1698
+ }
1699
+ const row = rows[localRow] ?? ""
1570
1700
  const plain = stripSgr(sanitizeAnsi(row))
1571
- const body = plain.startsWith(prefix) ? plain.slice(prefix.length) : plain
1572
- const targetColumn = Math.max(
1573
- 0,
1574
- key.x - 1 - (plain.startsWith(prefix) ? displayWidth(prefix) : 0),
1575
- )
1576
- const local = graphemeOffsetAtColumn(body, targetColumn)
1701
+ const hasPrefix = localRow === 0 && plain.startsWith(prefix)
1702
+ const body = hasPrefix ? plain.slice(prefix.length) : plain
1703
+ const targetColumn = Math.max(0, key.x - 1 - (hasPrefix ? displayWidth(prefix) : 0))
1704
+ const local = precedingGraphemes + graphemeOffsetAtColumn(body, targetColumn)
1577
1705
  const base = toGraphemes(this.state.line.slice(0, baseCodeUnits)).length
1578
1706
  this.state = { ...this.state, cursor: base + local }
1579
1707
  this.histIdx = -1
@@ -1710,9 +1838,9 @@ export class TuiApp {
1710
1838
  try {
1711
1839
  copied = this.host.copySelection(text)
1712
1840
  } catch {}
1713
- if (copied) this.transcript.pushInfo([c.muted(t("tui.selectionCopied"))])
1714
- else this.transcript.pushInfo([c.muted(t("tui.selectionCopyFailed"))])
1715
- this.paintCurrent()
1841
+ const msg = t(copied ? "tui.selectionCopied" : "tui.selectionCopyFailed")
1842
+ this.transcript.pushInfo([c.muted(msg)])
1843
+ this.showToast(msg)
1716
1844
  }
1717
1845
 
1718
1846
  private buildLayout(rows: number, cols: number, snap: TuiStatusSnapshot): FrameLayout {
@@ -1750,7 +1878,9 @@ export class TuiApp {
1750
1878
  ? c.warning(truncateToWidth(t("app.abortHint"), width))
1751
1879
  : newCount > 0
1752
1880
  ? c.muted(truncateToWidth(t("app.newBelow", { n: newCount }), width))
1753
- : ""
1881
+ : this.statusToast
1882
+ ? c.accent(truncateToWidth(this.statusToast, width))
1883
+ : ""
1754
1884
 
1755
1885
  const allMenu = this.menuRows(height, width, busy)
1756
1886
  const allComposer = this.composerRows(width, snap, busy, now)
@@ -1789,7 +1919,34 @@ export class TuiApp {
1789
1919
  const selected = this.selectedRange(row)
1790
1920
  return selected ? highlightColumns(row.text, selected.start, selected.end) : row.text
1791
1921
  })
1922
+ // Zero-state welcome ringkas saat sesi masih kosong & idle: langsung memberi
1923
+ // orientasi model/workspace/pintasan tanpa menyisipkan riwayat scrollback.
1924
+ if (
1925
+ this.transcript.total() === 0 &&
1926
+ !busy &&
1927
+ menu.length === 0 &&
1928
+ !this.state.line &&
1929
+ viewH >= 5 &&
1930
+ width >= 24
1931
+ ) {
1932
+ const dot = glyphs.dot
1933
+ const innerMax = Math.max(8, width - 4)
1934
+ const model = sanitizeAnsiLine(snap.footer.model || t("tui.noModel"))
1935
+ const cwdText = sanitizeAnsiLine(snap.footer.cwd || "")
1936
+ const welcome = [
1937
+ c.bold(c.accent(truncateToWidth(t("app.welcomeTitle", { dot, model }), innerMax))),
1938
+ ...(cwdText
1939
+ ? [c.dim(truncateToWidth(t("app.welcomeCwd", { cwd: cwdText }), innerMax))]
1940
+ : []),
1941
+ c.muted(truncateToWidth(t("app.welcomeHints", { dot }), innerMax)),
1942
+ ]
1943
+ const startRow = Math.max(0, Math.floor((body.length - welcome.length) / 2))
1944
+ for (let wi = 0; wi < welcome.length && startRow + wi < body.length; wi++) {
1945
+ body[startRow + wi] = ` ${welcome[wi]!}`
1946
+ }
1947
+ }
1792
1948
 
1949
+ const pf = promptFirst()
1793
1950
  let shownComposer: string[]
1794
1951
  let cursorRow: number
1795
1952
  let cursorCol = 1
@@ -1806,7 +1963,13 @@ export class TuiApp {
1806
1963
  cursorRow = viewH + menu.length + 1
1807
1964
  // Kursor parkir tepat setelah prompt saat idle (bukan kolom 1) supaya
1808
1965
  // caret terlihat di tempat user akan mengetik.
1809
- if (!busy) cursorCol = displayWidth(PROMPT_FIRST) + 1
1966
+ if (!busy) cursorCol = displayWidth(pf) + 1
1967
+ }
1968
+ if (!busy && composerOffset === 0 && shownComposer[0]?.startsWith(pf)) {
1969
+ shownComposer = [
1970
+ `${c.accent(pf)}${shownComposer[0]!.slice(pf.length)}`,
1971
+ ...shownComposer.slice(1),
1972
+ ]
1810
1973
  }
1811
1974
 
1812
1975
  const started = this.turnStartedAt || now