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.
@@ -1,5 +1,4 @@
1
- // Block logo minicode: mark wordmark pemilik, dikonversi dari SVG vektor
2
- // (CorelDRAW) menjadi grid 17 kolom × 9 baris sel.
1
+ // Block logo minicode: mark wordmark pemilik pada grid 14 kolom × 9 baris sel.
3
2
  //
4
3
  // ASPEK PER-SEL — inti modul ini. Satu karakter terminal TIDAK persegi:
5
4
  // tingginya ±2× lebarnya. Menggambar satu sel = satu karakter penuh membuat
@@ -13,34 +12,32 @@
13
12
  // atas█ bawah█ → '█' (kedua sel terisi)
14
13
  // atas█ bawah∅ → '▀' (hanya sel atas)
15
14
  // atas∅ bawah█ → '▄' (hanya sel bawah)
16
- // Hasil: 17 kolom × 5 baris karakter (baris terakhir hanya berisi sel ke-9,
17
- // karena tinggi logis 9 sel — ganjil). Rasio kotak fisik ≈ 17:9, sama dengan
18
- // SVG asli; tidak lagi "dipipihkan" seperti blok karakter penuh.
15
+ // Hasil: 14 kolom × 5 baris karakter (baris terakhir hanya berisi sel ke-9,
16
+ // karena tinggi logis 9 sel — ganjil). Rasio kotak fisik ≈ 14:9, sesuai grid
17
+ // piksel pemilik; tidak lagi "dipipihkan" seperti blok karakter penuh.
19
18
  //
20
19
  // Fallback: terminal tanpa UTF-8 (MINICODE_ASCII/mini console legacy) memakai
21
20
  // '#' 9 baris — aspek setengah-sel tidak tersedia di sana, jadi bentuk penuh
22
21
  // dipertahankan agar pola tidak terpotong.
23
22
  //
24
- // Dimensi DIVERIFIKASI terhadap SVG (viewBox 8418.09 × 4456.66): 8418.09 =
25
- // 495.18 × 17 kolom, 4456.66 = 495.18 × 9 baris (sel seragam 495.18²).
26
- // Setiap '#' = satu sel terisi (75 polygon → 75 sel).
23
+ // Grid referensi pemilik: 14 kolom × 9 baris sel seragam (62 sel '#' terisi).
27
24
 
28
25
  import { supportsUtf8 } from "./theme.ts"
29
26
 
30
27
  const ROWS = [
31
- " ##### ",
32
- " ### #######",
33
- "##### ## ##",
34
- "## ### ## ##",
35
- "## ## ##",
36
- "## ## ##",
37
- "## ## ### ##",
38
- "###### ### ###",
39
- " #### ##### ",
28
+ " ### ",
29
+ " ### ## ##",
30
+ "##### ## ##",
31
+ "## ## ## ##",
32
+ "## ## ##",
33
+ "## ## ##",
34
+ "## ## ## ##",
35
+ "## ## #####",
36
+ " ### ### ",
40
37
  ] as const
41
38
 
42
39
  /** Dimensi logis logo (sel), untuk pemanggil yang butuh geometri/centering. */
43
- export const LOGO_WIDTH = 17
40
+ export const LOGO_WIDTH = 14
44
41
  export const LOGO_HEIGHT = 9
45
42
 
46
43
  /** Glyph sel terisi (fallback ASCII). */
@@ -0,0 +1,293 @@
1
+ // Layout teks & spasi presentasi asisten (dibagi bersama TUI Transcript dan
2
+ // printer linier agar margin kiri, hanging indent multi-tingkat, dan jeda antar
3
+ // poin paragraf selalu konsisten).
4
+
5
+ import { stripSgr } from "./sanitize.ts"
6
+ import { displayWidth } from "./width.ts"
7
+
8
+ export interface FenceMatch {
9
+ char: string
10
+ len: number
11
+ lang: string
12
+ }
13
+
14
+ /**
15
+ * Parse satu baris fence markdown (``` atau ~~~) → info pembuka, atau null.
16
+ */
17
+ export function parseFence(line: string): FenceMatch | null {
18
+ const m = /^\s*(```+|~~~+)([A-Za-z0-9_+.-]*)(?:\s+[^\r\n]*)?\s*$/.exec(line)
19
+ if (!m) return null
20
+ return { char: m[1]![0]!, len: m[1]!.length, lang: m[2] ?? "" }
21
+ }
22
+
23
+ /** Margin kiri standar area teks asisten agar lega dari tepi kiri terminal. */
24
+ export const ASSISTANT_LEFT_MARGIN = 3
25
+
26
+ /** Margin kiri adaptif: lega (3 kolom) di terminal normal, menyusut di layar sempit. */
27
+ export function effectiveAssistantMargin(width: number): number {
28
+ if (width >= 36) return ASSISTANT_LEFT_MARGIN
29
+ if (width >= 20) return 2
30
+ if (width >= 14) return 1
31
+ return 0
32
+ }
33
+
34
+ /**
35
+ * Lebar isi minimum yang wajib disisakan saat mengitung hanging indent agar
36
+ * list/paragraf bersarang dalam di terminal sempit tak memeras teks menjadi 1–2 huruf.
37
+ */
38
+ function minReadableContentCols(width: number): number {
39
+ return Math.min(16, Math.max(6, Math.floor(width / 3)))
40
+ }
41
+
42
+ /**
43
+ * Hitung indentasi gantung (kolom spasi pada baris lanjutan wrap) untuk baris
44
+ * teks yang SUDAH memuat margin luarnya.
45
+ *
46
+ * Contoh (margin = 3):
47
+ * - `- item panjang` -> continuation 5 spasi (sejajar tepat di bawah huruf i)
48
+ * - `1. item panjang` -> continuation 6 spasi
49
+ * - ` - sub-poin panjang` -> continuation 8 spasi (tak bablas ke level induk/kolom 0)
50
+ * - ` Paragraf berindentasi` -> continuation 6 spasi (tetap di tingkat paragraf)
51
+ * - `> kutipan panjang` -> continuation 5 spasi (tetap di dalam kutipan)
52
+ */
53
+ export function computeHangingIndent(line: string, width: number): string {
54
+ if (width <= 0) return ""
55
+ const plain = stripSgr(line)
56
+ if (plain.trim() === "") return ""
57
+
58
+ const maxHangCols = Math.max(0, width - minReadableContentCols(width))
59
+ let desiredCols = 0
60
+
61
+ // Heading: tetap sejajar di indentasi awalan barisnya.
62
+ const heading = /^(\s*)#{1,6}\s+/.exec(plain)
63
+ if (heading) {
64
+ desiredCols = displayWidth(heading[1]!)
65
+ } else {
66
+ // Daftar (bullet / bernomor) beserta checkbox opsional `- [x] `:
67
+ // lanjutan teks sejajar di kolom isi, bukan di bawah marker/angka.
68
+ const listItem = /^(\s*)([-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?(.*)$/.exec(plain)
69
+ if (listItem) {
70
+ desiredCols =
71
+ displayWidth(listItem[1]!) +
72
+ displayWidth(listItem[2]!) +
73
+ 1 +
74
+ displayWidth(listItem[3] ?? "")
75
+ } else {
76
+ // Kutipan bersarang (`> `, `> > `, ` > `): teks lanjutan sejajar di dalam kutipan.
77
+ const blockquote = /^(\s*(?:>\s*)+)/.exec(plain)
78
+ if (blockquote) {
79
+ desiredCols = displayWidth(blockquote[1]!)
80
+ } else {
81
+ // Paragraf biasa atau paragraf berindentasi multi-tingkat:
82
+ // pertahankan seluruh spasi awal sebagai batas kiri tingkatnya.
83
+ const leading = /^(\s+)/.exec(plain)
84
+ if (leading) desiredCols = displayWidth(leading[1]!)
85
+ }
86
+ }
87
+ }
88
+
89
+ const clampedCols = Math.min(desiredCols, maxHangCols)
90
+ return clampedCols > 0 ? " ".repeat(clampedCols) : ""
91
+ }
92
+
93
+ export interface AssistantLineLayout {
94
+ firstLead: string
95
+ hangingIndent: string
96
+ }
97
+
98
+ /** Hitung prefix margin baris-1 & hanging indent wrap untuk satu baris logis asisten. */
99
+ export function computeAssistantLineLayout(
100
+ rawLine: string,
101
+ outerMargin: number,
102
+ width: number,
103
+ opts: { inFence?: boolean } = {},
104
+ ): AssistantLineLayout {
105
+ if (rawLine.trim() === "" || outerMargin <= 0) {
106
+ const hangingIndent = opts.inFence ? "" : computeHangingIndent(rawLine, width)
107
+ return { firstLead: "", hangingIndent }
108
+ }
109
+ const firstLead = " ".repeat(outerMargin)
110
+ if (opts.inFence) {
111
+ // Di dalam code fence, pertahankan margin area teks + opsional indentasi
112
+ // kode secukupnya agar potongan kode panjang tak menempel kembali ke tepi kiri.
113
+ return { firstLead, hangingIndent: firstLead }
114
+ }
115
+ const hangingIndent = computeHangingIndent(`${firstLead}${rawLine}`, width)
116
+ return { firstLead, hangingIndent }
117
+ }
118
+
119
+ export type FlowLineKind = "none" | "heading" | "list" | "blockquote" | "fenceClose" | "prose"
120
+
121
+ export interface MarkdownFlowState {
122
+ prevKind: FlowLineKind
123
+ topListIndent: number | null
124
+ prevWasBlank: boolean
125
+ hasContent: boolean
126
+ }
127
+
128
+ function classifyNonFenceLine(line: string): {
129
+ kind: "heading" | "list" | "blockquote" | "prose"
130
+ indentCols: number
131
+ } {
132
+ if (/^#{1,6}\s/.test(line)) return { kind: "heading", indentCols: 0 }
133
+ const listItem = /^(\s*)([-*+]|\d+[.)])\s+/.exec(line)
134
+ if (listItem) return { kind: "list", indentCols: displayWidth(listItem[1]!) }
135
+ if (/^\s*>/.test(line)) return { kind: "blockquote", indentCols: 0 }
136
+ const leading = /^(\s*)/.exec(line)
137
+ return { kind: "prose", indentCols: displayWidth(leading?.[1] ?? "") }
138
+ }
139
+
140
+ /**
141
+ * Mesin status transisi jeda vertikal antar-blok markdown.
142
+ *
143
+ * Menambahkan 1 baris kosong (bila belum ada) agar setiap poin utama daftar,
144
+ * paragraf pengantar/penutup, heading, blockquote, dan code fence punya ruang
145
+ * napas yang nyaman dibaca tanpa menumpuk jadi dinding teks atau menghasilkan
146
+ * baris kosong ganda berlebihan.
147
+ */
148
+ export class MarkdownFlowStepper {
149
+ private state: MarkdownFlowState = {
150
+ prevKind: "none",
151
+ topListIndent: null,
152
+ prevWasBlank: false,
153
+ hasContent: false,
154
+ }
155
+
156
+ get hasEmitted(): boolean {
157
+ return this.state.hasContent
158
+ }
159
+
160
+ clone(): MarkdownFlowStepper {
161
+ const copy = new MarkdownFlowStepper()
162
+ copy.state = { ...this.state }
163
+ return copy
164
+ }
165
+
166
+ /** Catat baris kosong; return true bila boleh dicetak (mencegah blank berulang/awal). */
167
+ onBlank(): boolean {
168
+ if (!this.state.hasContent || this.state.prevWasBlank) return false
169
+ this.state.prevWasBlank = true
170
+ return true
171
+ }
172
+
173
+ /** Transisi ke pembuka code fence; return true bila perlu baris kosong pemisah sebelumnya. */
174
+ onFenceOpen(): boolean {
175
+ const needSpacer = this.state.hasContent && !this.state.prevWasBlank
176
+ this.state.hasContent = true
177
+ this.state.prevWasBlank = false
178
+ this.state.prevKind = "fenceClose"
179
+ this.state.topListIndent = null
180
+ return needSpacer
181
+ }
182
+
183
+ /** Tutup code fence agar baris sesudahnya diberi jeda bersih. */
184
+ onFenceClose(): void {
185
+ this.state.hasContent = true
186
+ this.state.prevWasBlank = false
187
+ this.state.prevKind = "fenceClose"
188
+ this.state.topListIndent = null
189
+ }
190
+
191
+ /** Catat tabel blok terpisah (paritas pemisah terhadap paragraf di sekitarnya). */
192
+ onTable(): boolean {
193
+ const needSpacer = this.state.hasContent && !this.state.prevWasBlank
194
+ this.state.hasContent = true
195
+ this.state.prevWasBlank = false
196
+ this.state.prevKind = "fenceClose"
197
+ this.state.topListIndent = null
198
+ return needSpacer
199
+ }
200
+
201
+ /** Catat satu baris teks markdown non-kosong di luar fence; return true bila perlu jeda sebelumnya. */
202
+ onLine(line: string): boolean {
203
+ const curr = classifyNonFenceLine(line)
204
+ let needSpacer = false
205
+
206
+ if (this.state.hasContent && !this.state.prevWasBlank) {
207
+ if (curr.kind === "heading") {
208
+ needSpacer = true
209
+ } else if (this.state.prevKind === "heading" || this.state.prevKind === "fenceClose") {
210
+ needSpacer = true
211
+ } else if (curr.kind === "blockquote") {
212
+ needSpacer = this.state.prevKind !== "blockquote"
213
+ } else if (this.state.prevKind === "blockquote") {
214
+ needSpacer = true
215
+ } else if (curr.kind === "list") {
216
+ if (this.state.topListIndent === null) {
217
+ // Masuk ke blok daftar dari paragraf/elemen lain → pisahkan dengan 1 jeda.
218
+ needSpacer = true
219
+ } else if (curr.indentCols <= this.state.topListIndent) {
220
+ // Poin utama / level terluar berikutnya dalam daftar (atau keluar dari
221
+ // sub-poin kembali ke poin utama) → pisahkan antar-poin. Sub-item bersarang
222
+ // (`indentCols > topListIndent`) tetap merapat di bawah induknya.
223
+ needSpacer = true
224
+ }
225
+ } else {
226
+ // `curr.kind === "prose"`: bila baru keluar dari daftar ke paragraf level
227
+ // terluar (bukan paragraf lanjutan berindentasi di dalam poin), beri jeda.
228
+ if (this.state.topListIndent !== null && curr.indentCols <= this.state.topListIndent) {
229
+ needSpacer = true
230
+ }
231
+ }
232
+ }
233
+
234
+ if (curr.kind === "list") {
235
+ this.state.topListIndent =
236
+ this.state.topListIndent === null
237
+ ? curr.indentCols
238
+ : Math.min(this.state.topListIndent, curr.indentCols)
239
+ } else if (
240
+ curr.kind === "heading" ||
241
+ this.state.topListIndent === null ||
242
+ curr.indentCols <= this.state.topListIndent
243
+ ) {
244
+ this.state.topListIndent = null
245
+ }
246
+
247
+ this.state.hasContent = true
248
+ this.state.prevWasBlank = false
249
+ this.state.prevKind = curr.kind
250
+ return needSpacer
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Rapikan spasi presentasi jawaban model: hapus baris kosong di tepi, batasi
256
+ * jeda berulang di luar fence, dan sisipkan jeda 1 baris antar-poin utama /
257
+ * paragraf / heading / blok kode. Isi code fence tetap literal 100%.
258
+ */
259
+ export function formatAssistantSpacing(text: string): string {
260
+ const lines = text.replace(/\r\n?/g, "\n").split("\n")
261
+ const out: string[] = []
262
+ const flow = new MarkdownFlowStepper()
263
+ let openFence: { char: string; len: number } | null = null
264
+
265
+ for (const line of lines) {
266
+ const fence = parseFence(line)
267
+ if (openFence) {
268
+ out.push(line)
269
+ if (fence && fence.char === openFence.char && fence.len >= openFence.len) {
270
+ openFence = null
271
+ flow.onFenceClose()
272
+ }
273
+ continue
274
+ }
275
+ if (fence) {
276
+ if (flow.onFenceOpen()) out.push("")
277
+ openFence = fence
278
+ out.push(line)
279
+ continue
280
+ }
281
+ if (!line.trim()) {
282
+ if (flow.onBlank()) out.push("")
283
+ continue
284
+ }
285
+ if (flow.onLine(line)) out.push("")
286
+ out.push(line)
287
+ }
288
+
289
+ // Jika fence belum ditutup, baris kosong di ekor masih bagian dari contoh
290
+ // kode dan harus tetap literal. Hanya whitespace di luar fence yang dirapatkan.
291
+ if (!openFence) while (out.length && out[out.length - 1] === "") out.pop()
292
+ return out.join("\n")
293
+ }
@@ -3,38 +3,15 @@
3
3
  // Inline: **bold**, *italic*, `code`, ~~strike~~, [text](url) -> teks accent (no underline).
4
4
 
5
5
  import { highlightCode } from "./highlight.ts"
6
+ import { effectiveAssistantMargin, formatAssistantSpacing, parseFence } from "./markdown-layout.ts"
6
7
  import { type MarkdownTable, parseMarkdownBlocks } from "./markdown-table.ts"
7
8
  import { sanitizeAnsi } from "./sanitize.ts"
8
9
  import { renderMarkdownTable } from "./table-grid.ts"
9
10
  import { c, glyphs } from "./theme.ts"
10
11
 
12
+ export { type FenceMatch, parseFence } from "./markdown-layout.ts"
11
13
  export { renderMarkdownTable, renderMarkdownTableLines } from "./table-grid.ts"
12
14
 
13
- export interface FenceMatch {
14
- char: string
15
- len: number
16
- lang: string
17
- }
18
-
19
- /**
20
- * Parse satu baris fence markdown (``` atau ~~~) → info pembuka, atau null.
21
- *
22
- * Diekspor agar simple.ts (printer linier streaming) memakai parser yang SAMA
23
- * dengan decorateMarkdown — sebelumnya ia men-toggle `inFence` naif per baris
24
- * (`line.includes("```")`) yang tidak kenal ~~~ dan tidak cek char/panjang,
25
- * sehingga fence berbahasa kehilangan highlight dan state desync.
26
- */
27
- export function parseFence(line: string): FenceMatch | null {
28
- // Info-string setelah bahasa diperbolehkan (````ts title="demo"` atau
29
- // ` ```js #tag `). Hanya token pertama (non-spasi) yang dibaca sebagai
30
- // bahasa — sisanya adalah metadata yang tak memengaruhi highlight. Regex
31
- // lama menolak seluruh baris ber-info-string sehingga kode jatuh ke dekorasi
32
- // inline (`const x = *a*` jadi `const x = a`).
33
- const m = /^\s*(```+|~~~+)([A-Za-z0-9_+.-]*)(?:\s+[^\r\n]*)?\s*$/.exec(line)
34
- if (!m) return null
35
- return { char: m[1]![0]!, len: m[1]!.length, lang: m[2] ?? "" }
36
- }
37
-
38
15
  // ── Inline markdown -> ANSI ──
39
16
  // Urutan replace lama: `code` diganti dulu jadi `c.brightCyan(...)`, lalu
40
17
  // regex **bold** masih menemukan `**` DI DALAM hasil cyan → `` `**a**` ``
@@ -72,7 +49,11 @@ export function decorateMarkdown(text: string): string {
72
49
  // Teks model tak-terpercaya: sanitasi SEKALI di hulu agar fence-content,
73
50
  // renderInline, dan highlight tak pernah melihat escape mentah. Urutan ini
74
51
  // juga melindungi placeholder `\u0000` (sanitize membuang null model).
75
- const lines = sanitizeAnsi(text).split("\n")
52
+ const sanitized = sanitizeAnsi(text)
53
+ const spaced = sanitized.includes("\n") ? formatAssistantSpacing(sanitized) : sanitized
54
+ const lines = spaced.split("\n")
55
+ const cols = process.stdout.columns || 80
56
+ const margin = " ".repeat(effectiveAssistantMargin(cols))
76
57
  const tableStarts = new Map<number, MarkdownTable>()
77
58
  for (const block of parseMarkdownBlocks(lines.join("\n"))) {
78
59
  if (block.type === "table") tableStarts.set(block.startLine, block.table)
@@ -87,9 +68,7 @@ export function decorateMarkdown(text: string): string {
87
68
  const table = tableStarts.get(lineIndex)
88
69
  if (table) {
89
70
  if (process.stdout.isTTY)
90
- out.push(
91
- ...renderMarkdownTable(table, process.stdout.columns || 80, renderInline).split("\n"),
92
- )
71
+ out.push(...renderMarkdownTable(table, cols, renderInline).split("\n"))
93
72
  else
94
73
  for (let tableLine = lineIndex; tableLine <= table.endLine; tableLine++)
95
74
  out.push(lines[tableLine]!)
@@ -105,7 +84,7 @@ export function decorateMarkdown(text: string): string {
105
84
  fenceChar = fence.char
106
85
  fenceLen = fence.len
107
86
  fenceLang = fence.lang
108
- if (fenceLang) out.push(c.dim(` ${glyphs.dot} ${fenceLang}`))
87
+ if (fenceLang) out.push(`${margin}${c.dim(`${glyphs.dot} ${fenceLang}`)}`)
109
88
  } else {
110
89
  if (fence.char === fenceChar && fence.len >= fenceLen) {
111
90
  inFence = false
@@ -115,7 +94,7 @@ export function decorateMarkdown(text: string): string {
115
94
  } else {
116
95
  // fence di dalam fence dengan char/len berbeda → anggap konten
117
96
  const bar = fenceLang ? c.dim(glyphs.vLine) : glyphs.vLine
118
- out.push(` ${bar} ${fenceLang ? highlightCode(line, fenceLang) : line}`)
97
+ out.push(`${margin}${bar} ${fenceLang ? highlightCode(line, fenceLang) : line}`)
119
98
  continue
120
99
  }
121
100
  }
@@ -129,32 +108,45 @@ export function decorateMarkdown(text: string): string {
129
108
  // `npm run build -- --flag=*value*` kehilangan bintangnya karena dianggap
130
109
  // italic. Fence tanpa bahasa justru bentuk paling umum untuk perintah shell.
131
110
  if (inFence) {
111
+ if (line.trim() === "") {
112
+ out.push("")
113
+ continue
114
+ }
132
115
  const bar = fenceLang ? c.dim(glyphs.vLine) : glyphs.vLine
133
- out.push(` ${bar} ${fenceLang ? highlightCode(line, fenceLang) : line}`)
116
+ out.push(`${margin}${bar} ${fenceLang ? highlightCode(line, fenceLang) : line}`)
134
117
  continue
135
118
  }
136
119
 
137
- // Headings (# ## ###) -> bold with vertical spacing
138
- if (/^#{1,3}\s/.test(line)) {
120
+ if (line.trim() === "") {
121
+ out.push("")
122
+ continue
123
+ }
124
+
125
+ // Headings (# .. ######) -> bold dengan margin area teks.
126
+ if (/^#{1,6}\s/.test(line)) {
139
127
  if (out.length > 0 && out[out.length - 1] !== "") out.push("")
140
- // Margin kiri 1 kolom — jangan menempel ke tepi terminal.
141
- out.push(` ${c.bold(line)}`)
128
+ out.push(`${margin}${c.bold(line)}`)
142
129
  continue
143
130
  }
144
131
 
145
- // Daftar (bullet `-`/`*`/`+` atau bernomor `1.`/`2)`) — indentasi BERSARANG
146
- // mengikuti lekukan sumber, bukan diratakan jadi satu level. Marker
147
- // dipertahankan; isi didekorasi inline (bold/italic/code tetap jalan).
132
+ // Daftar (bullet `-`/`*`/`+` atau bernomor `1.`/`2)`) — pertahankan indentasi
133
+ // sumber bersarang relatif di atas margin terluar agar sub-item tetap sejajar
134
+ // tepat di bawah teks induknya saat di-wrap.
148
135
  const listItem = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(line)
149
136
  if (listItem) {
150
- const depth = Math.min(8, Math.floor((listItem[1]!.length + 1) / 2))
151
- const indent = " ".repeat(depth + 1)
152
- out.push(`${indent}${listItem[2]} ${renderInline(listItem[3] ?? "")}`)
137
+ const sourceIndent = listItem[1]!.slice(0, 16)
138
+ out.push(`${margin}${sourceIndent}${listItem[2]} ${renderInline(listItem[3] ?? "")}`)
139
+ continue
140
+ }
141
+
142
+ // Kutipan (`> `) atau paragraf biasa / berindentasi multi-tingkat.
143
+ const blockquote = /^(\s*(?:>\s*)+)(.*)$/.exec(line)
144
+ if (blockquote) {
145
+ out.push(`${margin}${blockquote[1]}${renderInline(blockquote[2] ?? "")}`)
153
146
  continue
154
147
  }
155
148
 
156
- // Margin kiri 1 kolom untuk paragraf (tidak menempel ke tepi terminal).
157
- out.push(` ${renderInline(line)}`)
149
+ out.push(`${margin}${renderInline(line)}`)
158
150
  }
159
151
  return out.join("\n")
160
152
  }
@@ -21,7 +21,7 @@ function paintWordmark(): string {
21
21
  return c.bold(WORDMARK)
22
22
  }
23
23
 
24
- /** Block logo pemilik (9×19) dicat dengan aksen brand — jatuh ke plain saat
24
+ /** Block logo pemilik (14×9) dicat dengan aksen brand — jatuh ke plain saat
25
25
  * NO_COLOR, dan ke '#' saat terminal tanpa UTF-8 (fallback di logo.ts). */
26
26
  function paintLogo(): string[] {
27
27
  return renderLogoRows().map((row) => c.accent(row))
@@ -1,3 +1,4 @@
1
+ import { effectiveAssistantMargin } from "./markdown-layout.ts"
1
2
  import type { MarkdownTable, PipeTableAlignment } from "./markdown-table.ts"
2
3
  import { cleanUntrusted, sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
3
4
  import { c, getTerminalWidth, glyphs, supportsUtf8 } from "./theme.ts"
@@ -42,8 +43,6 @@ export interface GridRenderOptions {
42
43
 
43
44
  const DEFAULT_MAX_CELL_WIDTH = 50
44
45
  const MIN_CONTENT_WIDTH = 3
45
- /** Margin kiri kotak tabel — biar tidak menempel ke tepi terminal. */
46
- const BOX_MARGIN = 1
47
46
 
48
47
  function cleanCell(value: unknown): string {
49
48
  return cleanUntrusted(
@@ -212,6 +211,7 @@ function renderBorderedGrid(
212
211
  aligns: readonly PipeTableAlignment[],
213
212
  styleHeader: boolean,
214
213
  options: GridRenderOptions,
214
+ margin: number,
215
215
  ): string {
216
216
  const g = supportsUtf8()
217
217
  ? {
@@ -290,7 +290,8 @@ function renderBorderedGrid(
290
290
  for (let li = 0; li < height; li++) out.push(rowLine(cols, li))
291
291
  }
292
292
  out.push(horiz(g.bl, g.bm, g.br))
293
- return out.map((line) => " ".repeat(BOX_MARGIN) + line).join("\n")
293
+ const pad = margin > 0 ? " ".repeat(margin) : ""
294
+ return pad ? out.map((line) => pad + line).join("\n") : out.join("\n")
294
295
  }
295
296
 
296
297
  export function renderGridTable(table: GridTable, options: GridRenderOptions = {}): string {
@@ -311,9 +312,10 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
311
312
  : MIN_CONTENT_WIDTH
312
313
  // Overhead batas: format kotak `│ c │` memakan 2 kolom lebih banyak per baris
313
314
  // (baris batas `│` + padding) daripada format separator lama ` c ` + spasi.
314
- // `BOX_MARGIN` = margin kiri agar kotak tidak nempel ke tepi terminal.
315
+ // Margin kiri kotak tabel diselaraskan dengan margin area teks asisten.
316
+ const boxMargin = options.box ? effectiveAssistantMargin(width) : 0
315
317
  const overhead = options.box
316
- ? table.headers.length * 3 + 1 + BOX_MARGIN
318
+ ? table.headers.length * 3 + 1 + boxMargin
317
319
  : table.headers.length * 3 - 1
318
320
  const budget = width - overhead
319
321
  const natural = naturalWidths(table, maxCellWidth)
@@ -330,12 +332,19 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
330
332
  budget < minimums.reduce((sum, value) => sum + value, 0)
331
333
  ? null
332
334
  : fitWidths(natural, budget, minimums)
333
- if (!widths) return renderVertical(table, width, ellipsis).join("\n")
335
+ if (!widths) {
336
+ const vMargin = options.box ? effectiveAssistantMargin(width) : 0
337
+ const lines = renderVertical(table, Math.max(1, width - vMargin), ellipsis)
338
+ .join("\n")
339
+ .split("\n")
340
+ const pad = vMargin > 0 ? " ".repeat(vMargin) : ""
341
+ return (pad ? lines.map((l) => (l ? pad + l : l)) : lines).join("\n")
342
+ }
334
343
 
335
344
  const aligns = table.aligns ?? table.headers.map(() => "left" as const)
336
345
  const styleHeader = options.styleHeader !== false
337
346
 
338
- if (options.box) return renderBorderedGrid(table, widths, aligns, styleHeader, options)
347
+ if (options.box) return renderBorderedGrid(table, widths, aligns, styleHeader, options, boxMargin)
339
348
 
340
349
  const separator = c.dim(widths.map((value) => glyphs.hLine.repeat(value + 2)).join(" "))
341
350