minicode-ai 0.30.0 → 0.30.1

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.
@@ -349,13 +349,8 @@ export function padToWidth(s: string, width: number, align: "left" | "right" = "
349
349
  return align === "right" ? pad + s : s + pad
350
350
  }
351
351
 
352
- /**
353
- * Pecah string menjadi potongan yang masing-masing <= `width` kolom.
354
- * Dipakai untuk teks tanpa spasi (CJK, URL panjang, hash) yang tidak bisa
355
- * dipecah di batas kata.
356
- */
357
- export function chunkByWidth(s: string, width: number): string[] {
358
- if (width <= 0) return [""]
352
+ function chunkByWidthCore(s: string, firstWidth: number, contWidth: number): string[] {
353
+ if (firstWidth <= 0 || contWidth <= 0) return [""]
359
354
  const out: string[] = []
360
355
  let cur = ""
361
356
  let w = 0
@@ -389,7 +384,8 @@ export function chunkByWidth(s: string, width: number): string[] {
389
384
  cur += seq
390
385
  continue
391
386
  }
392
- if (w + token.width > width && cur !== "") {
387
+ const limit = out.length === 0 ? firstWidth : contWidth
388
+ if (w + token.width > limit && cur !== "") {
393
389
  pushChunk()
394
390
  }
395
391
  cur += token.text
@@ -399,6 +395,28 @@ export function chunkByWidth(s: string, width: number): string[] {
399
395
  return out.length ? out : [""]
400
396
  }
401
397
 
398
+ /**
399
+ * Pecah string menjadi potongan per-kolom, dengan anggaran baris pertama dan
400
+ * baris lanjutan terpisah (dipakai word-wrap ber-indentasi gantung).
401
+ */
402
+ export function chunkByWidthSplit(s: string, firstWidth: number, contWidth: number): string[] {
403
+ return chunkByWidthCore(s, firstWidth, contWidth)
404
+ }
405
+
406
+ /**
407
+ * Pecah string menjadi potongan yang masing-masing <= `width` kolom.
408
+ * Dipakai untuk teks tanpa spasi (CJK, URL panjang, hash) yang tidak bisa
409
+ * dipecah di batas kata.
410
+ */
411
+ export function chunkByWidth(s: string, width: number): string[] {
412
+ return chunkByWidthCore(s, width, width)
413
+ }
414
+
415
+ export interface WrapByWidthOptions {
416
+ /** Indentasi gantung (kolom spasi) yang disisipkan di awal setiap baris lanjutan. */
417
+ hangingIndent?: string
418
+ }
419
+
402
420
  /**
403
421
  * Pecah string ke potongan <= `width` kolom, TAPI word-aware: lebih suka
404
422
  * memutus di batas kata (spasi) daripada membelah kata di tengah. Token tanpa
@@ -409,12 +427,22 @@ export function chunkByWidth(s: string, width: number): string[] {
409
427
  * Spasi yang tepat TIDAK muat menjadi titik putus; spasi itu (dan spasi-trailing
410
428
  * yang tak terlihat) dibuang, bukan dipindah ke baris berikutnya.
411
429
  */
412
- export function wrapByWidth(s: string, width: number): string[] {
430
+ export function wrapByWidth(s: string, width: number, options?: WrapByWidthOptions): string[] {
413
431
  if (width <= 0) return [""]
432
+ const rawHang = options?.hangingIndent ?? ""
433
+ const rawHangWidth = rawHang ? displayWidth(rawHang) : 0
434
+ // Jangan biarkan indentasi gantung menutup seluruh lebar baris — minimal 1 kolom isi.
435
+ const effectiveHang = rawHangWidth > 0 && rawHangWidth < width ? rawHang : ""
436
+ const effectiveHangWidth = effectiveHang ? rawHangWidth : 0
437
+ const contBudget = Math.max(1, width - effectiveHangWidth)
438
+
414
439
  const out: string[] = []
415
440
  let line = ""
416
441
  let lineWidth = 0
442
+ let plainIndent = ""
443
+ let lineHasWord = false
417
444
  let openSgr: string[] = []
445
+ let openSgrBeforeWord: string[] = []
418
446
  let word = ""
419
447
  let wordWidth = 0
420
448
 
@@ -430,36 +458,56 @@ export function wrapByWidth(s: string, width: number): string[] {
430
458
 
431
459
  const flush = (): void => {
432
460
  if (line !== "") out.push(openSgr.length > 0 ? `${line}\x1b[0m` : line)
433
- line = openSgr.join("")
434
- lineWidth = 0
461
+ // Indentasi gantung diletakkan SEBELUM SGR terbuka agar spasi margin/indentasi
462
+ // tidak ikut mendapat gaya warna/latar teks di baris lanjutan.
463
+ line = effectiveHang + openSgr.join("")
464
+ lineWidth = effectiveHangWidth
465
+ plainIndent = effectiveHang
466
+ lineHasWord = false
435
467
  }
436
468
 
437
469
  const placeWord = (): void => {
438
470
  if (wordWidth === 0) {
471
+ if (word) line += word
439
472
  word = ""
473
+ openSgrBeforeWord = [...openSgr]
440
474
  return
441
475
  }
442
476
  if (lineWidth + wordWidth <= width) {
443
477
  line += word
444
478
  lineWidth += wordWidth
445
- } else if (wordWidth <= width) {
479
+ lineHasWord = true
480
+ } else if (wordWidth <= contBudget) {
446
481
  // Kata utuh pindah ke baris berikutnya (bukan dibelah di tengah).
447
482
  flush()
448
483
  line += word
449
484
  lineWidth += wordWidth
485
+ lineHasWord = true
450
486
  } else {
451
- // Token tanpa spasi > width: potong per kolom (chunkByWidth, sgr-safe).
452
- if (lineWidth > 0) flush()
453
- const pieces = chunkByWidth(word, width)
487
+ // Token tanpa spasi > sisa anggaran: potong per kolom (chunkByWidthCore, sgr-safe).
488
+ if (lineHasWord) flush()
489
+ const firstBudget = Math.max(1, width - lineWidth)
490
+ const pieces = chunkByWidthCore(openSgrBeforeWord.join("") + word, firstBudget, contBudget)
454
491
  for (let i = 0; i < pieces.length - 1; i++) {
492
+ const prefix = i === 0 ? plainIndent : effectiveHang
455
493
  const piece = pieces[i]!
456
- out.push(openSgr.length > 0 && !piece.endsWith("\x1b[0m") ? `${piece}\x1b[0m` : piece)
494
+ out.push(prefix + piece)
457
495
  }
458
- line = pieces[pieces.length - 1] ?? ""
496
+ let lastPiece = pieces[pieces.length - 1] ?? ""
497
+ // Jika masih ada SGR terbuka setelah kata ini, lepas `\x1b[0m` penutup
498
+ // sementara dari chunkByWidthCore agar kata berikutnya di baris yang sama
499
+ // tetap mewarisi gaya aslinya.
500
+ if (openSgr.length > 0 && lastPiece.endsWith("\x1b[0m")) {
501
+ lastPiece = lastPiece.slice(0, -4)
502
+ }
503
+ const lastPrefix = pieces.length === 1 ? plainIndent : effectiveHang
504
+ line = lastPrefix + lastPiece
459
505
  lineWidth = displayWidth(line)
506
+ lineHasWord = true
460
507
  }
461
508
  word = ""
462
509
  wordWidth = 0
510
+ openSgrBeforeWord = [...openSgr]
463
511
  }
464
512
 
465
513
  for (const token of displayTokens(s)) {
@@ -475,6 +523,7 @@ export function wrapByWidth(s: string, width: number): string[] {
475
523
  if (lineWidth + 1 <= width) {
476
524
  line += " "
477
525
  lineWidth += 1
526
+ if (!lineHasWord) plainIndent += " "
478
527
  }
479
528
  continue
480
529
  }
@@ -482,6 +531,10 @@ export function wrapByWidth(s: string, width: number): string[] {
482
531
  wordWidth += token.width
483
532
  }
484
533
  placeWord()
485
- if (line !== "" || out.length === 0) flush()
534
+ if (out.length === 0 || lineHasWord || lineWidth > effectiveHangWidth) {
535
+ if (line !== "" || out.length === 0) {
536
+ out.push(openSgr.length > 0 ? `${line}\x1b[0m` : line)
537
+ }
538
+ }
486
539
  return out.length ? out : [""]
487
540
  }
@@ -8,8 +8,9 @@
8
8
  // yang di sini tidak ikut diperbaiki saat pola ANSI diperluas untuk sekuens
9
9
  // private-mode (ESC[?25l dsb.).
10
10
 
11
+ import { computeHangingIndent } from "./markdown-layout.ts"
11
12
  import { stripAnsi } from "./theme.ts"
12
- import { chunkByWidth, displayWidth } from "./width.ts"
13
+ import { chunkByWidthSplit, displayWidth } from "./width.ts"
13
14
 
14
15
  export { stripAnsi }
15
16
 
@@ -34,13 +35,20 @@ export function wordWrap(text: string, width: number): string {
34
35
  out.push(line)
35
36
  continue
36
37
  }
38
+ const hang = computeHangingIndent(line, width)
39
+ const hangWidth = hang ? displayWidth(hang) : 0
37
40
  let current = ""
41
+ let lineIndex = 0
42
+ const emitLine = (textOut: string) => {
43
+ out.push(textOut)
44
+ lineIndex++
45
+ }
38
46
  const flush = () => {
39
- if (current !== "") {
47
+ if (current !== "" && (lineIndex === 0 || current.trim() !== "")) {
40
48
  // Spasi pemisah di ujung tidak ikut tampil.
41
- out.push(current.trimEnd())
42
- current = ""
49
+ emitLine(current.trimEnd())
43
50
  }
51
+ current = ""
44
52
  }
45
53
  // Pisah dengan pemisah tertangkap agar spasi ganda (ASCII art/tabel)
46
54
  // tetap utuh — run whitespace menempel ke kata berikut, wrap hanya putus
@@ -56,25 +64,35 @@ export function wordWrap(text: string, width: number): string {
56
64
  continue
57
65
  }
58
66
  const word = tok
59
- // Kata tunggal lebih lebar dari baris: pecah paksa per kolom.
60
- if (displayWidth(word) > width) {
67
+ const contBudget = Math.max(1, width - hangWidth)
68
+ // Kata tunggal lebih lebar dari sisa lebar baris lanjutan: pecah paksa per kolom.
69
+ if (
70
+ displayWidth(word) > contBudget &&
71
+ (displayWidth(word) > width || current.trim() !== "")
72
+ ) {
61
73
  // Indentasi (bila ada) menempel ke potongan PERTAMA dan menyusutkan
62
74
  // lebar potongan itu — tanpa ini indentasi hilang atau baris meluap.
63
75
  const lead = current.trim() === "" ? current : ""
64
76
  // Teks yang sudah terkumpul (bila ada) ditutup dulu; hanya indentasi
65
77
  // murni yang ikut menempel ke potongan pertama.
66
- if (current.trim() !== "") out.push(current.trimEnd())
78
+ if (current.trim() !== "") emitLine(current.trimEnd())
67
79
  current = ""
68
- const avail = Math.max(1, width - displayWidth(lead))
69
- const pieces = chunkByWidth(word, avail)
70
- if (lead && pieces.length > 0) {
71
- out.push(lead + (pieces[0] ?? ""))
72
- for (let i = 1; i < pieces.length - 1; i++) out.push(pieces[i]!)
73
- current = pieces[pieces.length - 1] ?? ""
74
- if (pieces.length === 1) current = ""
75
- } else {
76
- for (let i = 0; i < pieces.length - 1; i++) out.push(pieces[i]!)
77
- current = pieces[pieces.length - 1] ?? ""
80
+ const firstPrefix = lineIndex === 0 ? lead : hang
81
+ const firstPrefixWidth = displayWidth(firstPrefix)
82
+ const availFirst = Math.max(1, width - firstPrefixWidth)
83
+ if (displayWidth(word) <= availFirst) {
84
+ current = firstPrefix + word
85
+ continue
86
+ }
87
+ // Potong bagian pertama sepas `availFirst`, sisanya mengikuti `contBudget`
88
+ // (SGR-safe via chunkByWidthSplit agar warna tetap terbawa utuh).
89
+ const pieces = chunkByWidthSplit(word, availFirst, contBudget)
90
+ if (pieces.length > 0) {
91
+ emitLine(firstPrefix + (pieces[0] ?? ""))
92
+ for (let i = 1; i < pieces.length - 1; i++) {
93
+ emitLine(hang + pieces[i]!)
94
+ }
95
+ current = pieces.length > 1 ? hang + (pieces[pieces.length - 1] ?? "") : ""
78
96
  }
79
97
  continue
80
98
  }
@@ -82,12 +100,11 @@ export function wordWrap(text: string, width: number): string {
82
100
  // hanya bila tidak ada pemisah di antara dua kata.
83
101
  const glued = !current || /\s$/.test(current) ? `${current}${word}` : `${current} ${word}`
84
102
  if (displayWidth(glued) > width && current.trim() !== "") {
85
- out.push(current.trimEnd())
86
- current = word
103
+ emitLine(current.trimEnd())
104
+ current = hang && displayWidth(hang) + displayWidth(word) <= width ? hang + word : word
87
105
  } else if (displayWidth(glued) > width) {
88
- // Indentasi + kata tak muat bersama: indentasi dilepas untuk baris ini
89
- // (baris tetap <= width; lebih baik daripada meluap/memecah kata).
90
- current = word
106
+ // Indentasi + kata tak muat bersama: lepas indentasi berlebih atau pakai hang.
107
+ current = hang && displayWidth(hang) + displayWidth(word) <= width ? hang + word : word
91
108
  } else {
92
109
  current = glued
93
110
  }
@@ -72,10 +72,10 @@ export class UiSessionState {
72
72
  this.#minimizeAnswer = opts.minimizeAnswer ?? process.env.MINICODE_MINIMIZE_ANSWER === "1"
73
73
  this.#minimizeTool = opts.minimizeTool ?? process.env.MINICODE_MINIMIZE_TOOL === "1"
74
74
  this.#compact = opts.compact ?? process.env.MINICODE_COMPACT === "1"
75
- // Thinking/teks berpikir TERLIHAT secara default (expanded) — alasannya user
76
- // ingin membaca proses berpikir model tanpa flag. `MINICODE_SHOW_THINKING=0`
77
- // eksplisit mematikan (minimized); `=1` eksplisit menghidupkan.
78
- this.#reasoningVisible = opts.reasoningVisible ?? process.env.MINICODE_SHOW_THINKING !== "0"
75
+ // Thinking/teks berpikir TERSEMBUNYI secara default agar transkrip bersih;
76
+ // user tetap bisa membukanya lewat `/thinking`, `Ctrl+T`, `--verbose`, atau
77
+ // `MINICODE_SHOW_THINKING=1` (indikator dots di composer tetap hidup).
78
+ this.#reasoningVisible = opts.reasoningVisible ?? process.env.MINICODE_SHOW_THINKING === "1"
79
79
  // Lipat aktivitas tool per turn (opencode-like): baris ledger per-tool
80
80
  // ditahan, diganti satu ringkasan turn. Opt-in (`MINICODE_MINIMIZE_ACTIVITY=1`),
81
81
  // default transparan sesuai filosofi "agentic Unix shell".
package/src/ui/tui/app.ts CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  import { appendWrapped, shaveWrapped } from "../render/composer-wrap.ts"
27
27
  import { formatError } from "../render/errors.ts"
28
28
  import { listRow } from "../render/list.ts"
29
+ import { LOGO_WIDTH, renderLogoRows } from "../render/logo.ts"
29
30
  import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
30
31
  import { c, glyphs, scrimMode, scrimSgr } from "../render/theme.ts"
31
32
  import { chunkByWidth, displayWidth, escapeLength, truncateToWidth } from "../render/width.ts"
@@ -257,7 +258,7 @@ export class TuiApp {
257
258
  private lastAbortAt = 0
258
259
  /** Hint "tekan lagi untuk keluar" tampil sekali setelah abort pertama. */
259
260
  private abortHintOn = false
260
- /** Micro-toast 2 detik di slot footer saat mengganti mode/bahasa/salin. */
261
+ /** Micro-toast 2 detik di slot footer saat mengganti bahasa/salin. */
261
262
  private statusToast = ""
262
263
  private toastTimer: ReturnType<typeof setTimeout> | undefined
263
264
  private frames = 0
@@ -784,21 +785,15 @@ export class TuiApp {
784
785
  return
785
786
  }
786
787
  this.host.cycleWorkMode(1)
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
- }
788
+ // Pembaruan WorkMode langsung mengubah label di bar footer tanpa
789
+ // menutup footer dengan toast sementara.
790
+ this.paintCurrent()
794
791
  return
795
792
  }
796
793
  if (key.type === "shift-tab") {
797
794
  this.host.togglePermissionMode()
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()
795
+ // Pembaruan PermissionMode langsung mengubah label di bar footer.
796
+ this.paintCurrent()
802
797
  return
803
798
  }
804
799
  if (key.type === "ctrl-o") {
@@ -1919,30 +1914,14 @@ export class TuiApp {
1919
1914
  const selected = this.selectedRange(row)
1920
1915
  return selected ? highlightColumns(row.text, selected.start, selected.end) : row.text
1921
1916
  })
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]!}`
1917
+ // Zero-state boot: tampilkan hanya logo kecil minicode di pojok kiri atas
1918
+ // tanpa blok identitas/hint di atas prompt & footer agar tampilan awal clean.
1919
+ if (this.transcript.total() === 0 && !busy && menu.length === 0 && !this.state.line) {
1920
+ const logoRows = renderLogoRows()
1921
+ if (viewH >= logoRows.length && width >= LOGO_WIDTH + 2) {
1922
+ for (let wi = 0; wi < logoRows.length; wi++) {
1923
+ body[wi] = ` ${c.accent(logoRows[wi]!)}`
1924
+ }
1946
1925
  }
1947
1926
  }
1948
1927
 
@@ -19,6 +19,11 @@ import { t } from "../i18n/locale.ts"
19
19
  import { renderActivityPanel } from "../render/activity-panel.ts"
20
20
  import { paintLedger, runMarker, statusWord } from "../render/ledger.ts"
21
21
  import { parseFence, renderInline } from "../render/markdown.ts"
22
+ import {
23
+ computeAssistantLineLayout,
24
+ effectiveAssistantMargin,
25
+ formatAssistantSpacing,
26
+ } from "../render/markdown-layout.ts"
22
27
  import { type MarkdownTable, parseMarkdownBlocks } from "../render/markdown-table.ts"
23
28
  import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
24
29
  import { renderMarkdownTable } from "../render/table-grid.ts"
@@ -188,46 +193,26 @@ function renderAssistantLine(line: string, fenceState: FenceState): string | nul
188
193
  if (fenceState === "boundary") return null
189
194
  if (fenceState.startsWith("open:")) {
190
195
  const lang = fenceState.slice(5)
191
- return lang ? c.dim(` ${glyphs.dot} ${lang}`) : null
196
+ return lang ? c.dim(`${glyphs.dot} ${lang}`) : null
192
197
  }
193
198
  if (fenceState === "inside") return line
194
199
  if (!/(?:\*{1,2}|`|^#{1,6}\s|~~|\[[^\]]+\]\()/.test(line)) return line
195
200
  const heading = /^(#{1,6})\s+(.*)$/.exec(line)
196
201
  if (heading) return c.bold(renderInline(heading[2] ?? ""))
202
+ const listItem = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(line)
203
+ if (listItem) return `${listItem[1]}${listItem[2]} ${renderInline(listItem[3] ?? "")}`
204
+ const blockquote = /^(\s*(?:>\s*)+)(.*)$/.exec(line)
205
+ if (blockquote) return `${blockquote[1]}${renderInline(blockquote[2] ?? "")}`
197
206
  return renderInline(line)
198
207
  }
199
208
 
200
209
  /**
201
210
  * Rapikan hanya whitespace presentasi jawaban model: hapus baris kosong di
202
- * tepi dan batasi jeda berulang di luar fenced code. Isi code fence tetap
203
- * literal karena spasi dan baris kosong di dalamnya adalah bagian contoh.
211
+ * tepi, sisipkan jeda bersih antar-poin/heading/blok, dan batasi jeda berulang
212
+ * di luar fenced code. Isi code fence tetap literal.
204
213
  */
205
214
  function normalizeAssistantOutput(text: string): string {
206
- const lines = text.replace(/\r\n?/g, "\n").split("\n")
207
- const out: string[] = []
208
- let openFence: { char: string; len: number } | null = null
209
- for (const line of lines) {
210
- const fence = parseFence(line)
211
- if (openFence) {
212
- out.push(line)
213
- if (fence && fence.char === openFence.char && fence.len >= openFence.len) openFence = null
214
- continue
215
- }
216
- if (fence) {
217
- openFence = fence
218
- out.push(line)
219
- continue
220
- }
221
- if (!line.trim()) {
222
- if (out.length && out[out.length - 1] !== "") out.push("")
223
- continue
224
- }
225
- out.push(line)
226
- }
227
- // Jika fence belum ditutup, baris kosong di ekor masih bagian dari contoh
228
- // kode dan harus tetap literal. Hanya whitespace di luar fence yang dirapatkan.
229
- if (!openFence) while (out.length && out[out.length - 1] === "") out.pop()
230
- return out.join("\n")
215
+ return formatAssistantSpacing(text)
231
216
  }
232
217
 
233
218
  let selectionSegmenter: Intl.Segmenter | undefined
@@ -601,6 +586,15 @@ export class Transcript {
601
586
  }
602
587
  return
603
588
  }
589
+ if (!this.uiState.reasoningVisible) {
590
+ // Tetap simpan thinking tersembunyi ke buffer `/expand` sebelum reset
591
+ // agar user tetap bisa membuka proses berpikir jika diperlukan.
592
+ if (this.thinkingBuf) this.uiState.rememberCollapsedSection("thinking", this.thinkingBuf)
593
+ this.thinkingBuf = ""
594
+ this.thinkingTail = ""
595
+ this.thinkingArea = []
596
+ return
597
+ }
604
598
  if (this.thinkingTail) {
605
599
  this.append(c.thinking(` ${this.thinkingTail}`), { kind: "diagnostic" })
606
600
  this.thinkingTail = ""
@@ -710,6 +704,7 @@ export class Transcript {
710
704
  fenceState: FenceState = "outside",
711
705
  ): TranscriptRow[] {
712
706
  const w = Math.max(10, width)
707
+ const outerMargin = markdown ? effectiveAssistantMargin(w) : 0
713
708
  const renderedLines = text.split("\n")
714
709
  const sourceLines = sourceText.split("\n")
715
710
  const out: TranscriptRow[] = []
@@ -717,22 +712,43 @@ export class Transcript {
717
712
  for (let lineIndex = 0; lineIndex < renderedLines.length; lineIndex++) {
718
713
  const raw = renderedLines[lineIndex] ?? ""
719
714
  const source = sourceLines[lineIndex] ?? stripSgr(sanitizeAnsi(raw))
720
- let rendered: string | null
721
- if (!markdown) rendered = raw
715
+ let renderedBody: string | null
716
+ if (!markdown) renderedBody = raw
722
717
  else if (sourceId >= 0 && this.assistantDisplay.has(sourceId))
723
- rendered = this.assistantDisplay.get(sourceId)!
718
+ renderedBody = this.assistantDisplay.get(sourceId)!
724
719
  else {
725
- rendered = renderAssistantLine(raw, fenceState)
726
- if (sourceId >= 0) this.assistantDisplay.set(sourceId, rendered)
720
+ renderedBody = renderAssistantLine(raw, fenceState)
721
+ if (sourceId >= 0) this.assistantDisplay.set(sourceId, renderedBody)
727
722
  }
728
- if (rendered === null) {
723
+ if (renderedBody === null) {
729
724
  sourceBase += source.length + 1
730
725
  continue
731
726
  }
732
727
  const isBoundaryHeader = markdown && fenceState.startsWith("open:")
733
- const renderedRows = rendered === "" ? [""] : wrapByWidth(rendered, w)
728
+ let firstLead = ""
729
+ let hangingIndent = ""
730
+ if (markdown) {
731
+ if (isBoundaryHeader) {
732
+ firstLead = outerMargin > 0 ? " ".repeat(outerMargin) : ""
733
+ hangingIndent = firstLead
734
+ } else if (renderedBody !== "") {
735
+ const layout = computeAssistantLineLayout(raw, outerMargin, w, {
736
+ inFence: fenceState === "inside",
737
+ })
738
+ firstLead = layout.firstLead
739
+ hangingIndent = layout.hangingIndent
740
+ }
741
+ }
742
+ const rendered = renderedBody === "" ? "" : `${firstLead}${renderedBody}`
743
+ const renderedRows =
744
+ rendered === ""
745
+ ? [""]
746
+ : wrapByWidth(rendered, w, hangingIndent ? { hangingIndent } : undefined)
747
+ const effectiveHangCols = displayWidth(hangingIndent)
748
+ const effectiveHang = effectiveHangCols > 0 && effectiveHangCols < w ? hangingIndent : ""
734
749
  const plainRenderedFull = stripSgr(sanitizeAnsi(rendered))
735
- const expectedExact = `${sourcePrefix}${source}`
750
+ const linePrefix0 = `${firstLead}${sourcePrefix}`
751
+ const expectedExact = `${linePrefix0}${source}`
736
752
  const exactMatch = !isBoundaryHeader && (!markdown || plainRenderedFull === expectedExact)
737
753
  const prefixTrimmed = sourcePrefix.trimEnd()
738
754
  const rowBodies: Array<{
@@ -746,19 +762,25 @@ export class Transcript {
746
762
  const plainRendered = stripSgr(sanitizeAnsi(renderedRow))
747
763
  let rowDisplayStart = 0
748
764
  let plainBody = plainRendered
749
- if (sourcePrefix && rowIndex === 0) {
750
- if (plainRendered.startsWith(sourcePrefix)) {
751
- rowDisplayStart = displayWidth(sourcePrefix)
752
- plainBody = plainRendered.slice(sourcePrefix.length)
765
+ if (rowIndex === 0 && linePrefix0) {
766
+ if (plainRendered.startsWith(linePrefix0)) {
767
+ rowDisplayStart = displayWidth(linePrefix0)
768
+ plainBody = plainRendered.slice(linePrefix0.length)
753
769
  } else if (
770
+ sourcePrefix &&
754
771
  prefixTrimmed &&
755
- plainRendered.startsWith(prefixTrimmed) &&
756
- plainRendered.length <= sourcePrefix.length
772
+ plainRendered.startsWith(`${firstLead}${prefixTrimmed}`) &&
773
+ plainRendered.length <= linePrefix0.length
757
774
  ) {
758
775
  // Terminal sempit memecah tepat di ujung chrome prefix ("minicode ›").
759
776
  rowDisplayStart = displayWidth(plainRendered)
760
777
  plainBody = ""
761
778
  }
779
+ } else if (rowIndex > 0 && effectiveHang && plainRendered.startsWith(effectiveHang)) {
780
+ // Lewati spasi indentasi gantung sintetis di awal baris lanjutan agar
781
+ // highlight seleksi & clipboard /copy tetap bersih berisi teks asli.
782
+ rowDisplayStart = effectiveHangCols
783
+ plainBody = plainRendered.slice(effectiveHang.length)
762
784
  }
763
785
  rowBodies.push({
764
786
  text: renderedRow,
@@ -914,9 +936,10 @@ export class Transcript {
914
936
  if (this.thinkingTail) logical.push(this.thinkingTail)
915
937
  if (logical.length === 0) return []
916
938
  const visual: string[] = []
939
+ const contentWidth = Math.max(1, w - 2)
917
940
  for (const line of logical) {
918
941
  if (line === "") visual.push("")
919
- else visual.push(...wrapByWidth(line, w))
942
+ else visual.push(...wrapByWidth(line, contentWidth))
920
943
  }
921
944
  const shown = visual.slice(-MAX_THINKING_ROWS)
922
945
  const hidden = visual.length - shown.length
@@ -1135,9 +1158,33 @@ export class Transcript {
1135
1158
  const pending = normalizeAssistantOutput(sanitizeAnsi(this.pending))
1136
1159
  if (pending) {
1137
1160
  for (const block of parseMarkdownBlocks(pending)) {
1138
- if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
1139
- else
1140
- for (const line of block.text.split("\n")) {
1161
+ if (block.type === "table") {
1162
+ if (rows.length > 0 && rows[rows.length - 1]!.text !== "") {
1163
+ rows.push({
1164
+ text: "",
1165
+ sourceId: -1,
1166
+ sourceStart: 0,
1167
+ sourceEnd: 0,
1168
+ displayStart: 0,
1169
+ displayEnd: 0,
1170
+ selectable: false,
1171
+ })
1172
+ }
1173
+ rows.push(...this.projectTable(block.table, -1, w))
1174
+ } else {
1175
+ const lineList = block.text.split("\n")
1176
+ if (rows.length > 0 && lineList[0] !== "" && rows[rows.length - 1]!.text !== "") {
1177
+ rows.push({
1178
+ text: "",
1179
+ sourceId: -1,
1180
+ sourceStart: 0,
1181
+ sourceEnd: 0,
1182
+ displayStart: 0,
1183
+ displayEnd: 0,
1184
+ selectable: false,
1185
+ })
1186
+ }
1187
+ for (const line of lineList) {
1141
1188
  const fenceState = pendingFence(line)
1142
1189
  const memoKey =
1143
1190
  line.length <= PENDING_MEMO_LINE_MAX ? `${w}\u0000${fenceState}\u0000${line}` : null
@@ -1156,6 +1203,7 @@ export class Transcript {
1156
1203
  }
1157
1204
  rows.push(...produced)
1158
1205
  }
1206
+ }
1159
1207
  }
1160
1208
  }
1161
1209
  if (this.pendingTruncated) {
@@ -1342,10 +1390,19 @@ export class Transcript {
1342
1390
  // Pisahkan jawaban dari thinking/diagnostik tepat di atasnya dengan satu
1343
1391
  // baris kosong — supaya "berpikir" tidak nempel ke jawaban.
1344
1392
  if (this.lastKind() === "diagnostic") this.append("", { kind: "assistant" })
1345
- for (const block of parseMarkdownBlocks(sanitizeAnsi(text))) {
1346
- if (block.type === "table") this.appendTable(block.table, { kind: "assistant" })
1347
- else {
1348
- for (const row of block.text.split("\n")) this.append(row, { kind: "assistant" })
1393
+ const blocks = parseMarkdownBlocks(sanitizeAnsi(text))
1394
+ for (const block of blocks) {
1395
+ if (block.type === "table") {
1396
+ if (this.lines.length > 0 && this.lines[this.lines.length - 1] !== "") {
1397
+ this.append("", { kind: "assistant" })
1398
+ }
1399
+ this.appendTable(block.table, { kind: "assistant" })
1400
+ } else {
1401
+ const rows = block.text.split("\n")
1402
+ if (this.tables[this.tables.length - 1] && rows[0] !== "") {
1403
+ this.append("", { kind: "assistant" })
1404
+ }
1405
+ for (const row of rows) this.append(row, { kind: "assistant" })
1349
1406
  }
1350
1407
  }
1351
1408
  }