minicode-ai 0.9.29 → 0.10.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 (47) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/cli/args.ts +1 -0
  3. package/cli/commands.ts +219 -103
  4. package/cli/index.ts +8 -6
  5. package/cli/model-manager.ts +2 -7
  6. package/cli/provider-manager.ts +13 -13
  7. package/cli/setup.ts +10 -1
  8. package/cli/tui.ts +506 -0
  9. package/cli/wizard.ts +2 -1
  10. package/docs/ARCHITECTURE.html +41 -22
  11. package/package.json +1 -1
  12. package/src/app/rag-layer.ts +7 -2
  13. package/src/config.ts +30 -1
  14. package/src/policy/bash-guard.ts +64 -8
  15. package/src/policy/update-check.ts +4 -1
  16. package/src/tools/bash.ts +8 -0
  17. package/src/tools/task.ts +6 -1
  18. package/src/tools/web_fetch.ts +11 -2
  19. package/src/tools/web_search.ts +4 -1
  20. package/src/ui/approval/prompt.ts +84 -18
  21. package/src/ui/assistant/simple.ts +55 -22
  22. package/src/ui/assistant/turn-status.ts +16 -7
  23. package/src/ui/footer.ts +14 -12
  24. package/src/ui/i18n/en.ts +225 -0
  25. package/src/ui/i18n/id.ts +227 -0
  26. package/src/ui/i18n/locale.ts +66 -0
  27. package/src/ui/input/input.ts +138 -77
  28. package/src/ui/input/prompt-engine.ts +97 -4
  29. package/src/ui/render/collapse.ts +8 -1
  30. package/src/ui/render/errors.ts +75 -50
  31. package/src/ui/render/format.ts +15 -5
  32. package/src/ui/render/highlight.ts +5 -2
  33. package/src/ui/render/table.ts +7 -4
  34. package/src/ui/render/theme.ts +8 -3
  35. package/src/ui/render/width.ts +17 -9
  36. package/src/ui/runtime/screen.ts +197 -0
  37. package/src/ui/screens/dialog.ts +174 -0
  38. package/src/ui/screens/form.ts +459 -0
  39. package/src/ui/screens/model-manager.ts +274 -127
  40. package/src/ui/screens/picker.ts +229 -98
  41. package/src/ui/screens/provider-manager.ts +371 -164
  42. package/src/ui/screens/wizard.ts +149 -102
  43. package/src/ui/tui/app.ts +745 -0
  44. package/src/ui/tui/transcript.ts +271 -0
  45. package/cli/repl.ts +0 -740
  46. package/src/ui/runtime/chrome.ts +0 -369
  47. package/src/ui/screens/overlay.ts +0 -61
@@ -1,9 +1,19 @@
1
- // View persetujuan tool — readline + warna, murni presentasi.
1
+ // View persetujuan tool — murni presentasi.
2
2
  // Lapisan policy tidak mengimpor file ini; ia di-inject sebagai callback dari
3
3
  // composition root (cli/setup.ts -> createMinicodeSession -> permission).
4
+ //
5
+ // Warga TUI: bila approval sink terdaftar (cli/tui.ts saat App aktif), blok
6
+ // pertanyaan dicatat ke transkrip + layar di-repaint SEBELUM user menjawab
7
+ // (jejak keputusan permanen, terlihat saat menjawab). Tanpa sink = tulis
8
+ // langsung warisan (one-shot/exec). Input jawaban tetap askLine inline di
9
+ // baris kursor — aman dari App karena input App dibekukan saat busy (hanya
10
+ // abort yang lolos; Esc/Ctrl+C di sini = abort turn + deny, fail-closed).
11
+
12
+ import { t } from "../i18n/locale.ts"
4
13
  import { askLine } from "../input/input.ts"
5
14
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
6
15
  import { c } from "../render/theme.ts"
16
+ import { getApprovalSink } from "../tui/transcript.ts"
7
17
 
8
18
  /** Subset struktural tool call yang dibutuhkan view — tanpa tipe kernel. */
9
19
  export interface ApprovalRequest {
@@ -20,7 +30,7 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
20
30
  // Live-region untuk screen reader: baris polos tanpa ANSI agar terbaca
21
31
  // sebagai teks, bukan escape mentah. Bell saja mengganggu tanpa informasi.
22
32
  if (process.env.MINICODE_A11Y === "1")
23
- process.stderr.write(`[approval required: ${sanitizeAnsiLine(call.name)}]\n`)
33
+ process.stderr.write(`${t("appr.a11y", { name: sanitizeAnsiLine(call.name) })}\n`)
24
34
 
25
35
  // toolName/actionSummary berasal dari model/MCP (tidak terpercaya). Tanpa
26
36
  // sanitasi, `\x1b[2J\x1b[H` di dalam args.command akan membersihkan layar
@@ -43,17 +53,54 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
43
53
  }
44
54
  actionSummary = sanitizeAnsiLine(actionSummary)
45
55
 
46
- process.stdout.write(`\n${c.warning(c.bold("Approval required"))}\n`)
47
- process.stdout.write(` ${c.bold("Tool:")} ${c.info(toolName)}\n`)
48
- process.stdout.write(` ${actionSummary}\n`)
56
+ const block = [
57
+ ``,
58
+ `${c.warning(c.bold(t("appr.title")))}`,
59
+ ` ${c.bold(t("appr.tool"))} ${c.info(toolName)}`,
60
+ ` ${actionSummary}`,
61
+ ]
62
+ const sink = getApprovalSink()
63
+ if (sink) {
64
+ sink.pushBlock(block)
65
+ sink.repaint()
66
+ // Bekukan App selama menunggu jawaban (pola popup komposit): tanpa ini
67
+ // listener App + repaint live berlomba dengan askLine — prompt tak
68
+ // terlihat, user mengetik buta. Esc/Ctrl+C di sini = deny (batal hanya
69
+ // tool ini), BUKAN abort turn — turn lanjut dengan tool lain.
70
+ sink.suspend()
71
+ } else {
72
+ for (const l of block) process.stdout.write(`${l}\n`)
73
+ }
49
74
 
50
- const promptText = `${c.bold("[y]")} Allow once ${c.bold("[a]")} Always ${c.bold("[n]")} Deny: `
51
- const ans = (await askLine({ prompt: promptText })) ?? ""
75
+ const promptText = `${c.bold(t("appr.allowOnce"))} ${c.bold(t("appr.always"))} ${c.bold(t("appr.deny"))}: `
76
+ let ans: string | null
77
+ try {
78
+ ans = (await askLine({ prompt: promptText })) ?? ""
79
+ } finally {
80
+ if (sink) sink.resume()
81
+ }
52
82
 
83
+ // Terima jawaban dwibahasa (prompt tampil per locale): y/yes/ya,
84
+ // n/no/tidak/t, a/always/selalu/s. Selain itu = deny (fail-closed).
53
85
  const a = ans.trim().toLowerCase()
54
- if (a === "a" || a === "always") return "always"
55
- if (a === "y" || a === "yes") return "allow"
56
- return "deny"
86
+ const decisionKey =
87
+ a === "a" || a === "always" || a === "selalu" || a === "s"
88
+ ? ("appr.decAlways" as const)
89
+ : a === "y" || a === "yes" || a === "ya"
90
+ ? ("appr.decAllow" as const)
91
+ : ("appr.decDeny" as const)
92
+ const decision = t(decisionKey)
93
+ // Keputusan dicatat di transkrip (jejak audit); warisan mengandalkan
94
+ // scrollback askLine yang terhapus repaint.
95
+ if (sink) {
96
+ sink.pushBlock([c.muted(` → ${decision}`)])
97
+ sink.repaint()
98
+ }
99
+ return decisionKey === "appr.decAlways"
100
+ ? "always"
101
+ : decisionKey === "appr.decAllow"
102
+ ? "allow"
103
+ : "deny"
57
104
  }
58
105
 
59
106
  /** View pertanyaan ask_user — di-inject ke src/tools/ask_user.ts dari cli/setup.ts.
@@ -63,14 +110,33 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
63
110
  export async function promptAskText(question: string, options?: string[]): Promise<string | null> {
64
111
  if (!process.stdin.isTTY) return null
65
112
  const q = sanitizeAnsiLine(question).slice(0, 2000)
66
- process.stdout.write(`\n${c.warning(c.bold("Agent asks"))}\n`)
67
- process.stdout.write(` ${q}\n`)
68
- if (options?.length) {
69
- options.forEach((o, i) => {
70
- process.stdout.write(` ${c.dim(`${i + 1}.`)} ${sanitizeAnsiLine(o)}\n`)
71
- })
113
+ const block = [
114
+ ``,
115
+ `${c.warning(c.bold(t("appr.askTitle")))}`,
116
+ ` ${q}`,
117
+ ...(options?.length
118
+ ? options.map((o, i) => ` ${c.dim(`${i + 1}.`)} ${sanitizeAnsiLine(o)}`)
119
+ : []),
120
+ ]
121
+ const sink = getApprovalSink()
122
+ if (sink) {
123
+ sink.pushBlock(block)
124
+ sink.repaint()
125
+ sink.suspend()
126
+ } else {
127
+ for (const l of block) process.stdout.write(`${l}\n`)
128
+ }
129
+ let ans: string | null
130
+ try {
131
+ ans = await askLine({ prompt: `${c.bold(t("appr.answerPrompt"))}` })
132
+ } finally {
133
+ if (sink) sink.resume()
72
134
  }
73
- const ans = await askLine({ prompt: `${c.bold("Your answer")} (empty = cancel): ` })
74
135
  if (ans == null || !ans.trim()) return null
75
- return ans.trim()
136
+ const out = ans.trim()
137
+ if (sink) {
138
+ sink.pushBlock([c.muted(` → ${sanitizeAnsiLine(out).slice(0, 200)}`)])
139
+ sink.repaint()
140
+ }
141
+ return out
76
142
  }
@@ -4,6 +4,7 @@
4
4
  // MINICODE_COMPACT=1 atau setCompactMode (/compact).
5
5
  import { Buffer } from "node:buffer"
6
6
  import type { UiBus, UiStep } from "../contract.ts"
7
+ import { t } from "../i18n/locale.ts"
7
8
  import {
8
9
  bufferSection,
9
10
  collapse,
@@ -31,6 +32,13 @@ import { runWithoutStatus } from "../runtime/statusline.ts"
31
32
 
32
33
  export interface SimpleOptions {
33
34
  verbose?: boolean
35
+ /**
36
+ * Mode senyap untuk TUI fullscreen: semua tulis ke stdout/stderr DITEKAN,
37
+ * tapi state tetap jalan (rememberTurn untuk /copy, bufferSection untuk
38
+ * /expand, pendingError untuk driver). Tanpa ini printer linier mengotori
39
+ * alt-screen di sela repaint App — kontrak I3 (App penulis tunggal layar).
40
+ */
41
+ quiet?: boolean
34
42
  }
35
43
 
36
44
  // Buffer output turn terakhir untuk /copy: teks model (sudah sanitize, sama
@@ -67,9 +75,9 @@ export function writeClipboardOsc52(text: string): boolean {
67
75
  return true
68
76
  }
69
77
 
70
- const wOut = (s: string) =>
78
+ const wOutDirect = (s: string) =>
71
79
  runWithoutStatus(() => process.stdout.write(process.stdout.isTTY ? s : stripSgr(s)))
72
- const wErr = (s: string) =>
80
+ const wErrDirect = (s: string) =>
73
81
  runWithoutStatus(() => process.stderr.write(process.stdout.isTTY ? s : stripSgr(s)))
74
82
 
75
83
  // Error provider terakhir turn ini — diingat, BUKAN dicetak langsung.
@@ -111,6 +119,11 @@ function patchBlocks(patches: unknown): [string, string] {
111
119
  }
112
120
 
113
121
  export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () => void {
122
+ // Shadow module-level wOut/wErr: saat quiet, paint ditekan tapi SEMUA state
123
+ // (rememberTurn, bufferSection, pendingError, sanitizer) tetap jalan.
124
+ // Shadowing disengaja agar ~20 call-site tak perlu diubah satu per satu.
125
+ const wOut = opts.quiet ? (_: string) => {} : wOutDirect
126
+ const wErr = opts.quiet ? (_: string) => {} : wErrDirect
114
127
  let streamBuffer = ""
115
128
  // Sanitizer sadar-stream per aliran teks (temuan F1): ekor escape yang
116
129
  // terpotong di batas chunk ditahan dan disambung ke chunk berikut SEBELUM
@@ -159,7 +172,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
159
172
  return
160
173
  }
161
174
  if (answerBuf.length < ANSWER_BUF_MAX) {
162
- answerBuf += s.slice(0, ANSWER_BUF_MAX - answerBuf.length)
175
+ // Jangan belah surrogate pair di batas cap: slice mentah bisa
176
+ // menyisakan lead-surrogate yatim yang tampil sebagai U+FFFD di /expand.
177
+ let chunk = s.slice(0, ANSWER_BUF_MAX - answerBuf.length)
178
+ const last = chunk.charCodeAt(chunk.length - 1)
179
+ if (chunk.length > 0 && last >= 0xd800 && last <= 0xdbff) chunk = chunk.slice(0, -1)
180
+ answerBuf += chunk
163
181
  if (answerBuf.length >= ANSWER_BUF_MAX) answerTruncated = true
164
182
  } else {
165
183
  answerTruncated = true
@@ -217,11 +235,13 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
217
235
  // menghilangkan konten diam-diam (perilaku lama menampilkannya live).
218
236
  const finalizeAnswer = () => {
219
237
  if (answerBuf.length === 0) return
220
- const n = stripAnsi(answerBuf).length
221
- const cap = answerTruncated ? ", capped 1MB" : ""
238
+ // Hitung per code point (bukan UTF-16 unit): emoji surrogate dihitung 1,
239
+ // konsisten dengan label "chars" dan tak menggandakan di /expand.
240
+ const n = Array.from(stripAnsi(answerBuf)).length
241
+ const cap = answerTruncated ? t("one.answerCap") : ""
222
242
  // Petunjuk /expand WAJIB di baris ini: tanpa itu jawaban yang dikecilkan
223
243
  // terlihat "bisu" (tak ada cara membuka yang bisa ditemukan user).
224
- wErr(c.info(` + answer (${n} chars${cap}) — /expand to read\n`))
244
+ wErr(c.info(t("one.answerMin", { n, cap })))
225
245
  bufferSection("answer", answerBuf, "stdout")
226
246
  answerBuf = ""
227
247
  answerTruncated = false
@@ -278,7 +298,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
278
298
  collapse.setActiveSection(null)
279
299
  lastTurnText = ""
280
300
  pendingError = null
281
- if (opts.verbose) wErr(c.muted(`\n── Turn ${e.turn} ──\n`))
301
+ if (opts.verbose) wErr(c.muted(t("one.turnHead", { n: e.turn })))
282
302
  }),
283
303
  )
284
304
  offs.push(
@@ -295,7 +315,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
295
315
  bashSan.flush()
296
316
  flushThinking()
297
317
  finalizeAnswer()
298
- if (opts.verbose) wErr(c.muted(`\n done\n`))
318
+ if (opts.verbose) wErr(c.muted(t("one.done")))
299
319
  }),
300
320
  )
301
321
  offs.push(
@@ -308,7 +328,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
308
328
  flushThinking()
309
329
  collapse.setActiveSection("answer")
310
330
  if (!answerHidden() && answerBuf.length > 0) {
311
- wErr(c.muted(" − answer\n"))
331
+ wErr(c.muted(t("one.answerOpen")))
312
332
  wOut(answerBuf)
313
333
  answerBuf = ""
314
334
  answerTruncated = false
@@ -334,7 +354,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
334
354
  if (expanded) {
335
355
  if (thinkState !== "exp") {
336
356
  thinkState = "exp"
337
- wErr(c.muted(` − thinking\n`))
357
+ wErr(c.muted(t("one.thinkOpen")))
338
358
  if (thinkingBuf) {
339
359
  wErr(c.muted(thinkingBuf))
340
360
  thinkingBuf = ""
@@ -357,7 +377,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
357
377
  // Sisa baris expanded yang belum selesai dicetak dulu (terlihat),
358
378
  // baru header minimize — konten tak hilang, tak menempel.
359
379
  flushReasoningTail()
360
- wErr(c.info(` + thinking\n`))
380
+ wErr(c.info(t("one.thinkMin")))
361
381
  }
362
382
  if (text) {
363
383
  // Sama: buffer thinking ikut tercemar bila mentah (flush expanded
@@ -367,12 +387,15 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
367
387
  if (thinkingBuf.length > THINKING_BUF_MAX) {
368
388
  // Total ber-marker dibatasi THINKING_BUF_MAX (= cap per-entry
369
389
  // bufferSection) agar tak ada pemotongan diam-diam kedua di hilir.
390
+ // Tail-slice jangan mulai di tengah surrogate pair: trail
391
+ // yatim di awal tampil sebagai U+FFFD saat /expand.
370
392
  const body = thinkingBuf.startsWith(THINKING_TRUNCATED_MARKER)
371
393
  ? thinkingBuf.slice(THINKING_TRUNCATED_MARKER.length)
372
394
  : thinkingBuf
373
- thinkingBuf =
374
- THINKING_TRUNCATED_MARKER +
375
- body.slice(-(THINKING_BUF_MAX - THINKING_TRUNCATED_MARKER.length))
395
+ let tail = body.slice(-(THINKING_BUF_MAX - THINKING_TRUNCATED_MARKER.length))
396
+ const first = tail.charCodeAt(0)
397
+ if (tail.length > 0 && first >= 0xdc00 && first <= 0xdfff) tail = tail.slice(1)
398
+ thinkingBuf = THINKING_TRUNCATED_MARKER + tail
376
399
  }
377
400
  }
378
401
  }
@@ -392,7 +415,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
392
415
  const d = e.data as { message?: string; category?: string }
393
416
  pendingError = formatProviderError(d)
394
417
  } else if (e.kind === "content_filter") {
395
- wErr(c.warning(`\n! Content filter blocked\n`))
418
+ wErr(c.warning(t("one.contentBlocked")))
396
419
  }
397
420
  }),
398
421
  )
@@ -406,7 +429,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
406
429
  `${c.info(sanitizeAnsiLine(tc.name))}(${c.muted(sanitizeAnsiLine(formatArgsPreview(tc.args)))})`,
407
430
  )
408
431
  .join(", ")
409
- wErr(c.muted(` Step ${e.step.index}: ${calls}\n`))
432
+ wErr(c.muted(t("one.step", { i: e.step.index, calls })))
410
433
  }),
411
434
  )
412
435
  offs.push(
@@ -443,11 +466,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
443
466
  if (!r.isError && typeof r.content === "string")
444
467
  rememberTurn(truncateToWidth(sanitizeAnsi(r.content), 20000, ""))
445
468
  if (r.isError) {
446
- // Error tool SELALU tampil penuh — tidak pernah dikecilkan.
469
+ // Error tool ditampilkan ringkas per baris (cap 200 kolom + marker) —
470
+ // tanpa marker user tak bisa bedakan "pesan 200 kolom" vs "terpotong".
447
471
  collapse.setActiveSection(null)
448
472
  wErr(
449
473
  c.error(
450
- ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}: ${truncateToWidth(sanitizeAnsi(String(r.content)), 200, "")}\n`,
474
+ ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}: ${truncateToWidth(sanitizeAnsi(String(r.content)), 200, "…")}\n`,
451
475
  ),
452
476
  )
453
477
  return
@@ -495,8 +519,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
495
519
  }
496
520
  // todo_write: tampilkan daftarnya utuh — ini rencana kerja, bukan noise.
497
521
  if (name === "todo_write" || name === "todo_read") {
522
+ // Nama tool dari event model (tak terpercaya): sanitasi seperti cabang
523
+ // lain agar ESC[2J/OSC tak lolos via label.
524
+ const cleanName = sanitizeAnsiLine(name)
498
525
  wErr(
499
- c.success(` ${glyphs.arrow} ${name}\n`) +
526
+ c.success(` ${glyphs.arrow} ${cleanName}\n`) +
500
527
  c.muted(`${sanitizeAnsi(String(r.content))}\n`),
501
528
  )
502
529
  return
@@ -511,7 +538,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
511
538
  if (detail.compact) {
512
539
  const preview =
513
540
  lines.length > 3
514
- ? lines.slice(0, 3).join("\n ") + c.muted(`\n ... (${lines.length - 3} more)`)
541
+ ? lines.slice(0, 3).join("\n ") + c.muted(t("one.more3", { n: lines.length - 3 }))
515
542
  : lines.join("\n ")
516
543
  wErr(c.success(` ${glyphs.arrow} $ ${cmdLabel}\n`) + c.muted(` ${preview}\n`))
517
544
  return
@@ -519,7 +546,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
519
546
  const maxLines = TOOL_OUT_MAX_LINES()
520
547
  const shown = lines.slice(0, maxLines).map((l) => ` ${sanitizeAnsi(l)}`)
521
548
  const more =
522
- lines.length > maxLines ? c.muted(`\n … (${lines.length - maxLines} more lines)`) : ""
549
+ lines.length > maxLines ? c.muted(t("one.moreLines", { n: lines.length - maxLines })) : ""
523
550
  wErr(
524
551
  c.success(` ${glyphs.arrow} $ ${cmdLabel}\n`) +
525
552
  (shown.length ? `${c.muted(shown.join("\n")) + more}\n` : ""),
@@ -571,7 +598,13 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
571
598
  wErr(c.success(` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""}\n`))
572
599
  }),
573
600
  )
574
- offs.push(bus.on("context:compacted", (e) => wErr(c.warning(` ── compacted: ${e.reason}\n`))))
601
+ offs.push(
602
+ bus.on("context:compacted", (e) =>
603
+ wErr(
604
+ c.warning(`${t("ts.compacted", { reason: sanitizeAnsiLine(String(e.reason ?? "")) })}\n`),
605
+ ),
606
+ ),
607
+ )
575
608
 
576
609
  return () => {
577
610
  // Sisa parsal di-flush dulu (jangan hilang diam-diam), baru lepas.
@@ -117,7 +117,10 @@ export function attachTurnStatus(
117
117
  const dots = Array(1 + (tickGroup % 3))
118
118
  .fill(glyphs.dot)
119
119
  .join(" ")
120
- const cols = process.stdout.columns || 80
120
+ // Garis dilukis ke stderr via paintWrite — ukur dari stderr (jatuh ke
121
+ // stdout bila tak ada). stdout|pipe + stderr TTY memakai fallback 80 yang
122
+ // salah: terminal 120 terpotong berlebih, terminal 40 wrap sendiri.
123
+ const cols = process.stderr.columns ?? process.stdout.columns ?? 80
121
124
  // Sinyal "alive" (spark pulse) kini MILIK FOOTER, bukan thinking line:
122
125
  // satu sumber agar tak ada dua denyut. Thinking = titik saja; tool line
123
126
  // tetap pakai spinner braille (itu progres, bukan spark).
@@ -217,15 +220,21 @@ export function attachTurnStatus(
217
220
  let target = ""
218
221
  if (typeof args.path === "string") target = args.path
219
222
  else if (typeof args.file === "string") target = args.file
220
- else if (typeof args.cmd === "string") target = args.cmd.slice(0, 80)
221
- else if (typeof args.command === "string") target = args.command.slice(0, 80)
222
- // Potong panjang (bukan lebar) di sini; pemotongan LEBAR terjadi per-paint
223
- // agar resize langsung berefek.
223
+ else if (typeof args.cmd === "string") target = args.cmd
224
+ else if (typeof args.command === "string") target = args.command
225
+ // Potong panjang di sini (batas 80/200), potong LEBAR per-paint agar resize
226
+ // langsung berefek. truncateToWidth: tak belah SGR/surrogate — slice mentah
227
+ // bisa mendarat di tengah `\x1b[31m` dan menyisakan escape gantung yang
228
+ // lolos paintWrite.
224
229
  // Nama + argumen datang dari model (tak terpercaya): sanitasi sebelum
225
230
  // masuk paintWrite — truncateToWidth memotong lebar, bukan sekuens kontrol.
226
231
  const cleanName = sanitizeAnsiLine(name)
227
- const label2 = target ? `${cleanName} ${sanitizeAnsiLine(target)}` : cleanName
228
- return label2.length > 200 ? label2.slice(0, 200) : label2
232
+ const cleanTarget =
233
+ target.length > 80
234
+ ? truncateToWidth(sanitizeAnsiLine(target), 80, "")
235
+ : sanitizeAnsiLine(target)
236
+ const label2 = cleanTarget ? `${cleanName} ${cleanTarget}` : cleanName
237
+ return label2.length > 200 ? truncateToWidth(label2, 200, "") : label2
229
238
  }
230
239
 
231
240
  const detach = [
package/src/ui/footer.ts CHANGED
@@ -1,11 +1,8 @@
1
- // Footer status REPL: 1 baris status (tanpa garis — keputusan clean).
1
+ // Status bar TUI: 1 baris status (tanpa garis — keputusan clean).
2
2
  //
3
- // Dipakai dua mekanisme dengan KONTEN yang sama: mode cetak (idle, dicetak di
4
- // atas prompt sebagai scrollback biasa) dan mode lengket (chrome DECSTBM,
5
- // dilukis di 2 baris dasar terminal: blank + status). Modul ini murni render
6
- // tanpa IO, tanpa timer, tanpa tahu mekanisme mana yang memakainya. Frame
7
- // animasi spark dan angka konteks DIKIRIM pemanggil lewat FooterStatus, jadi
8
- // render tetap deterministik dan bisa diuji tanpa menunggu waktu.
3
+ // Modul murni render tanpa IO/timer: dipakai App TUI sebagai baris dasar.
4
+ // Frame animasi spark dan angka konteks DIKIRIM pemanggil lewat FooterStatus,
5
+ // jadi render tetap deterministik dan bisa diuji tanpa menunggu waktu.
9
6
  //
10
7
  // Gaya (keputusan produk): footer hampir tak terlihat — garis + teks status
11
8
  // abu-abu gelap; SATU-SATUNYA yang berwarna adalah token mode (mapping sama
@@ -14,7 +11,7 @@
14
11
  // Tata letak: `✦ mode • model • cwd ……… 14.2k` — konteks rata kanan. Mode
15
12
  // di-pad ke lebar tetap agar teks di kanannya TIDAK bergeser saat mode berganti
16
13
  // (Shift+Tab): tanpa padding, `auto`→`allowlist` menggeser seluruh baris.
17
- import { sanitizeAnsi } from "./render/sanitize.ts"
14
+ import { sanitizeAnsiLine } from "./render/sanitize.ts"
18
15
  import { c, glyphs } from "./render/theme.ts"
19
16
  import { displayWidth, padToWidth, truncateToWidth } from "./render/width.ts"
20
17
 
@@ -49,7 +46,9 @@ export function shortModel(id: string): string {
49
46
  export function paintFooterMode(mode: string): string {
50
47
  // Padding per KOLOM (bukan padEnd karakter): CJK/emoji = 2 kolom, dan
51
48
  // displayWidth sudah dipakai di bawah — konsisten satu penggaris.
52
- const padded = padToWidth(sanitizeAnsi(mode), MODE_WIDTH)
49
+ // Mode satu-baris: newline dari input tak terpercaya wajib dibuang agar tak
50
+ // memecah frame lengket 2-baris chrome.ts.
51
+ const padded = padToWidth(sanitizeAnsiLine(mode), MODE_WIDTH)
53
52
  return mode === "plan" ? c.warning(padded) : mode === "ask" ? c.info(padded) : c.success(padded)
54
53
  }
55
54
 
@@ -72,15 +71,18 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
72
71
  const mode = paintFooterMode(s.mode)
73
72
  const dot = c.gray("•")
74
73
  const sep = ` ${dot} `
75
- const model = c.gray(sanitizeAnsi(shortModel(s.model)))
76
- const cwdTxt = c.gray(sanitizeAnsi(s.cwd))
74
+ // Satu-baris: cwd/model bisa berisi newline (nama dir) — sanitizeAnsiLine
75
+ // agar \n tak memecah frame lengket ke scrollback (displayWidth menghitung
76
+ // \n = 0 sehingga align mengira muat).
77
+ const model = c.gray(sanitizeAnsiLine(shortModel(s.model)))
78
+ const cwdTxt = c.gray(sanitizeAnsiLine(s.cwd))
77
79
 
78
80
  const full = `${spark} ${mode}${sep}${model}${sep}${cwdTxt}`
79
81
  const mid = `${spark} ${mode}${sep}${model}`
80
82
  const lean = `${spark} ${mode}`
81
83
 
82
84
  const target = Math.max(4, cols - 1)
83
- const ctx = s.context ? sanitizeAnsi(s.context) : ""
85
+ const ctx = s.context ? sanitizeAnsiLine(s.context) : ""
84
86
  const ctxW = ctx ? displayWidth(ctx) : 0
85
87
 
86
88
  // Rata kanan: konteks didorong ke kolom `target` dengan gap ideal ≥6