minicode-ai 0.9.27 → 0.9.29

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.29] - 2026-09-18 — Identitas publik: homepage npm → minicode.fun
6
+
7
+ ### Changed
8
+ - **Field `homepage` paket npm `minicode-ai` kini `https://minicode.fun`**
9
+ (dulu repo GitHub). Registry adalah halaman discoverability pertama
10
+ (`npm page` / `npm home`) — situs resmi harus jadi tujuannya. Situs sudah
11
+ live sejak 0.9.28, sitemap 40 halaman ter-deploy + IndexNow otomatis;
12
+ field `repository`/`bugs` tetap ke repo GitHub sesuai fungsinya.
13
+ - `CHANGELOG.md` ikut ke tarball (`files`), jadi catatan ini tampil di npm.
14
+ - Tanpa perubahan kode CLI/kernel; metadata + docs saja.
15
+
16
+ ## [0.9.28] - 2026-09-18 — Terminal rendering hardening: stream-aware ANSI + resize-safe footer
17
+
18
+ ### Fixed
19
+ - **Fragmentasi ANSI antar-chunk (F1, HIGH)**: `sanitizeAnsi()` berjalan per-chunk sehingga escape terpotong (`"ESC["` + `"32mHello"`) tampil literal. Kini `splitTrailingEscape()` menahan ekor tak-lengkap (CSI/SGR/OSC/malformed/unterminated) dan `createStreamSanitizer()` menyambungnya ke chunk berikut sebelum sanitasi — satu instans per aliran (model/reasoning/bash), ekor sisa dibuang deterministik saat completed/detach/abort. Terbukti setara whole-string di semua titik belah (properti test).
20
+ - **Kebocoran ANSI ke non-TTY (F2, MEDIUM)**: SGR model lolos mentah ke stdout pipe. Kini kebijakan eksplisit — TTY dipertahankan, non-TTY dibuang (`stripSgr` di `wOut`/`wErr` + `rememberTurn`, cerminan `colorLevel` → `stdout.isTTY`); cabang TTY terbukti tak over-strip, pipe anak nyata nol `ESC[`.
21
+ - **Korupsi layout saat resize (HIGH)**: repaint footer hanya melukis baris dasar baru tanpa menghapus frame lama (5 resize → 4 kopi di model VT) dan tanpa me-reset region yang bisa hilang diam-diam di ConPTY. Kini satu jalur `reconcile()`: reset-dulu → tegakkan region → hapus frame lama (bila teralamatkan) → lukis; dipakai present/refresh/setBusy/onResize. Badai 500 resize + stream: maks 1 footer hidup/iterasi.
22
+ - **Buffer thinking tanpa marker (F3, LOW)**: head-drop kini membawa `… (early thinking truncated)`; overlap listener approval/busy-key (O1) didokumentasikan tanpa refactor (fail-closed).
23
+
24
+ ### Changed
25
+ - Peta proteksi `docs/TERMINAL_CONTRACT.md` + `docs/ARCHITECTURE.html` (pill `v0.9.28`) diselaraskan; tanpa redesign renderer/EventBus/REPL.
26
+
5
27
  ## [0.9.27] - 2026-09-18 — Upstream sync: 10 seam kernel dihilirkan, vendor nol-divergensi
6
28
 
7
29
  ### Fixed
package/cli/repl.ts CHANGED
@@ -400,6 +400,12 @@ export async function runRepl(ctx: CliSession): Promise<void> {
400
400
  if (chunk.includes(0x03)) ctrl.abort()
401
401
  }
402
402
  process.stdin.resume()
403
+ // O1 (audit UI 2026-09): approval `askLine` di tengah turn menempelkan
404
+ // listener "data" KEDUA di atas onBusyKey ini — byte yang sama (mis.
405
+ // Ctrl+C) diterima keduanya. SENGAJA tidak di-refactor: onBusyKey abort
406
+ // turn, askLine membatalkan approval menjadi deny via raceAbort
407
+ // (permission.ts) — gabungannya fail-closed ke arah aman. Jangan
408
+ // "merapikan" dengan melepas salah satunya tanpa memikirkan ulang.
403
409
  process.stdin.on("data", onBusyKey)
404
410
  const turnStart = Date.now()
405
411
  try {
@@ -464,7 +464,7 @@ footer.site .spacer { flex: 1; }
464
464
  <span class="mi">search</span><span>Cari modul, simbol, env…</span><kbd>Ctrl K</kbd>
465
465
  </div>
466
466
  <div class="top-actions">
467
- <span class="vpill hide-m">v0.9.27 · Bun-only · 0 deps</span>
467
+ <span class="vpill hide-m">v0.9.28 · Bun-only · 0 deps</span>
468
468
  <button class="iconbtn" id="themeBtn" aria-label="Ganti tema terang/gelap" title="Ganti tema"><span class="mi">dark_mode</span></button>
469
469
  </div>
470
470
  </header>
@@ -1039,7 +1039,7 @@ bun run bench # benchmark loop agen</pre></div>
1039
1039
  <footer class="site">
1040
1040
  <span>Minicode · Peta struktur hidup — terminal contract FROZEN (<a href="TERMINAL_CONTRACT.md">docs/TERMINAL_CONTRACT.md</a>)</span>
1041
1041
  <span class="spacer"></span>
1042
- <span>v0.9.27 · diperbarui 2026-09-18</span>
1042
+ <span>v0.9.28 · diperbarui 2026-09-18</span>
1043
1043
  </footer>
1044
1044
 
1045
1045
  </div>
package/docs/README.md CHANGED
@@ -97,6 +97,7 @@ Habis itu, baca sesuai kebutuhan lewat tabel Navigasi di bawah — tak perlu ber
97
97
  | Error umum + `doctor` | [Troubleshooting](troubleshooting.md) |
98
98
  | Peta lapisan, alur satu prompt | [Arsitektur](architecture.md) |
99
99
  | Kontrak stdout/stderr FROZEN, 14 invariant | [Kontrak Terminal](terminal.md) |
100
+ | Kontrak internal kontributor: terminal FROZEN, control-plane, pipeline render | [Internal & Arsitektur](TERMINAL_CONTRACT.md) (grup di sidebar) |
100
101
  | Ikut kontribusi, gate, batas lapisan | [Contributing](contributing.md) |
101
102
  | Perubahan per versi | [Changelog](changelog.md) |
102
103
  | Arsip panduan monolit lama (baca hanya bila perlu) | `USAGE.md` (file pendamping, status legacy) |
package/docs/changelog.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Changelog
2
2
 
3
- Riwayat rilis dan status eksekusi kini digenerate otomatis dari [`PLAN.md`](../PLAN.md) saat build website — lihat [changelog di website](https://startupmini.github.io/minicode/docs/changelog.html).
3
+ Riwayat rilis dan status eksekusi kini digenerate otomatis dari [`PLAN.md`](../PLAN.md) saat build website — lihat [changelog di website](https://minicode.fun/docs/changelog.html).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minicode-ai",
3
- "version": "0.9.27",
3
+ "version": "0.9.29",
4
4
  "description": "Coding agent CLI built on the frozen MiniCore runtime — tools, MCP, LSP, sandbox, shadow-git checkpoints",
5
5
  "type": "module",
6
6
  "private": false,
@@ -24,7 +24,7 @@
24
24
  "anthropic",
25
25
  "ollama"
26
26
  ],
27
- "homepage": "https://github.com/startupmini/minicode#readme",
27
+ "homepage": "https://minicode.fun",
28
28
  "repository": {
29
29
  "type": "git",
30
30
  "url": "git+https://github.com/startupmini/minicode.git"
@@ -81,7 +81,7 @@
81
81
  "audit:harness": "bun bench/harness-audit.ts",
82
82
  "bench:runs": "bun bench/runner.ts --runs 2",
83
83
  "web:css": "bun scripts/build-web-css.ts",
84
- "web:build": "bun scripts/build-web.ts",
84
+ "web:build": "bun scripts/build-web-css.ts && bun scripts/build-web.ts",
85
85
  "web:serve": "bun --hot scripts/web-serve.ts",
86
86
  "web:check": "bun scripts/web-check.ts",
87
87
  "web:indexnow": "bun scripts/web-indexnow.ts",
@@ -17,7 +17,13 @@ import { formatArgsPreview, formatProviderError, formatUsage } from "../render/f
17
17
  import { highlightCode } from "../render/highlight.ts"
18
18
  import { decorateMarkdown, type FenceMatch, parseFence } from "../render/markdown.ts"
19
19
  import { reasoning } from "../render/reasoning.ts"
20
- import { sanitizeAnsi, sanitizeAnsiLine } from "../render/sanitize.ts"
20
+ import {
21
+ cleanUntrusted,
22
+ createStreamSanitizer,
23
+ sanitizeAnsi,
24
+ sanitizeAnsiLine,
25
+ stripSgr,
26
+ } from "../render/sanitize.ts"
21
27
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
22
28
  import { displayWidth, truncateToWidth } from "../render/width.ts"
23
29
  import { formatWrapped } from "../render/wrap.ts"
@@ -39,7 +45,8 @@ export function getLastTurnText(): string {
39
45
  }
40
46
  const rememberTurn = (s: string) => {
41
47
  if (!s) return
42
- lastTurnText += s
48
+ // Samakan dengan yang terlihat: kebijakan pipa (F2) berlaku juga untuk /copy.
49
+ lastTurnText += process.stdout.isTTY ? s : stripSgr(s)
43
50
  if (lastTurnText.length > LAST_TURN_MAX_CHARS)
44
51
  lastTurnText = lastTurnText.slice(-LAST_TURN_MAX_CHARS)
45
52
  }
@@ -60,8 +67,10 @@ export function writeClipboardOsc52(text: string): boolean {
60
67
  return true
61
68
  }
62
69
 
63
- const wOut = (s: string) => runWithoutStatus(() => process.stdout.write(s))
64
- const wErr = (s: string) => runWithoutStatus(() => process.stderr.write(s))
70
+ const wOut = (s: string) =>
71
+ runWithoutStatus(() => process.stdout.write(process.stdout.isTTY ? s : stripSgr(s)))
72
+ const wErr = (s: string) =>
73
+ runWithoutStatus(() => process.stderr.write(process.stdout.isTTY ? s : stripSgr(s)))
65
74
 
66
75
  // Error provider terakhir turn ini — diingat, BUKAN dicetak langsung.
67
76
  // Alasan: error tengah-turn sering pulih via fallback router; mencetak tiap
@@ -103,6 +112,15 @@ function patchBlocks(patches: unknown): [string, string] {
103
112
 
104
113
  export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () => void {
105
114
  let streamBuffer = ""
115
+ // Sanitizer sadar-stream per aliran teks (temuan F1): ekor escape yang
116
+ // terpotong di batas chunk ditahan dan disambung ke chunk berikut SEBELUM
117
+ // sanitasi — tanpa ini "ESC[" + "32m" tampil literal. Satu instans per
118
+ // aliran (model/reasoning/bash) agar state ekor tak tercampur. Ekor yang
119
+ // tersisa saat turn selesai/detach DIBUANG (flush di bawah): escape tanpa
120
+ // teks lanjutan tak punya efek tampak kecuali mutasi state terminal.
121
+ const textSan = createStreamSanitizer()
122
+ const reasoningSan = createStreamSanitizer()
123
+ const bashSan = createStreamSanitizer()
106
124
  // State fence dipegang DI SINI, bukan di decorateMarkdown: baris datang per
107
125
  // event streaming, sedangkan decorateMarkdown memproses satu teks utuh.
108
126
  // Sebelumnya `line.includes("```")` toggle naif → fence ~~~ tidak dikenal,
@@ -115,6 +133,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
115
133
  // menambah baris header baru sebagai ganti menimpa yang lama.
116
134
  let thinkState: "off" | "min" | "exp" = "off"
117
135
  let thinkingBuf = ""
136
+ // Batas buffer thinking + marker head-drop (F3): bila kepala dibuang,
137
+ // operator wajib tahu dari /expand bahwa isi tak lengkap — jangan biarkan
138
+ // ia percaya seluruh thinking tersedia. Terminologi mengikuti marker
139
+ // truncasi lain ("… (N more…)", ", capped 1MB").
140
+ const THINKING_BUF_MAX = 200_000
141
+ const THINKING_TRUNCATED_MARKER = "… (earlier thinking truncated)\n"
118
142
  // Sisa baris reasoning yang belum ber-newline (mode expanded): di-flush
119
143
  // per baris utuh agar tampilan rapi, bukan salad fragmen per chunk.
120
144
  let reasoningLine = ""
@@ -264,6 +288,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
264
288
  flushLine(streamBuffer)
265
289
  streamBuffer = ""
266
290
  }
291
+ // Ekor escape yang tertahan (F1) dibuang di sini — deterministik, tak
292
+ // pernah bocor mentah; begitu pula saat detach/abort di bawah.
293
+ textSan.flush()
294
+ reasoningSan.flush()
295
+ bashSan.flush()
267
296
  flushThinking()
268
297
  finalizeAnswer()
269
298
  if (opts.verbose) wErr(c.muted(`\n done\n`))
@@ -284,7 +313,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
284
313
  answerBuf = ""
285
314
  answerTruncated = false
286
315
  }
287
- const clean = sanitizeAnsi(e.text)
316
+ const clean = cleanUntrusted(textSan.push(e.text), !!process.stdout.isTTY)
288
317
  streamBuffer += clean
289
318
  rememberTurn(clean)
290
319
  flushBuf()
@@ -316,7 +345,8 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
316
345
  if (text) {
317
346
  // Teks reasoning TAK TERPERCAYA seperti provider:text — sanitasi
318
347
  // saat masuk (bukan saat flush) agar tak ada jalur cetak yang lupa.
319
- reasoningLine += sanitizeAnsi(text)
348
+ // Sadar-stream (F1) + kebijakan pipa (F2) seperti teks model.
349
+ reasoningLine += cleanUntrusted(reasoningSan.push(text), !!process.stdout.isTTY)
320
350
  const parts = reasoningLine.split("\n")
321
351
  for (let i = 0; i < parts.length - 1; i++) wErr(c.muted(`${parts[i]}\n`))
322
352
  reasoningLine = parts[parts.length - 1] ?? ""
@@ -331,9 +361,19 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
331
361
  }
332
362
  if (text) {
333
363
  // Sama: buffer thinking ikut tercemar bila mentah (flush expanded
334
- // mencetaknya verbatim + /expand menampilkannya lagi).
335
- thinkingBuf += sanitizeAnsi(text)
336
- if (thinkingBuf.length > 200_000) thinkingBuf = thinkingBuf.slice(-200_000)
364
+ // mencetaknya verbatim + /expand menampilkannya lagi). Sadar-stream
365
+ // (F1) + kebijakan pipa (F2); marker truncasi di bawah (F3).
366
+ thinkingBuf += cleanUntrusted(reasoningSan.push(text), !!process.stdout.isTTY)
367
+ if (thinkingBuf.length > THINKING_BUF_MAX) {
368
+ // Total ber-marker dibatasi THINKING_BUF_MAX (= cap per-entry
369
+ // bufferSection) agar tak ada pemotongan diam-diam kedua di hilir.
370
+ const body = thinkingBuf.startsWith(THINKING_TRUNCATED_MARKER)
371
+ ? thinkingBuf.slice(THINKING_TRUNCATED_MARKER.length)
372
+ : thinkingBuf
373
+ thinkingBuf =
374
+ THINKING_TRUNCATED_MARKER +
375
+ body.slice(-(THINKING_BUF_MAX - THINKING_TRUNCATED_MARKER.length))
376
+ }
337
377
  }
338
378
  }
339
379
  } else if (e.kind === "usage") {
@@ -343,9 +383,10 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
343
383
  } else if (e.kind === "bash-output") {
344
384
  // Progres bash inkremental — hanya di --verbose supaya output default
345
385
  // tidak dibanjiri log build. Ringkasan tetap muncul di execution:completed.
386
+ // Sadar-stream (F1): progres datang per event seperti teks model.
346
387
  if (opts.verbose) {
347
388
  const d = e.data as { text?: string }
348
- if (d.text) wErr(c.muted(sanitizeAnsi(d.text)))
389
+ if (d.text) wErr(c.muted(cleanUntrusted(bashSan.push(d.text), !!process.stdout.isTTY)))
349
390
  }
350
391
  } else if (e.kind === "error") {
351
392
  const d = e.data as { message?: string; category?: string }
@@ -540,6 +581,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
540
581
  flushLine(streamBuffer)
541
582
  streamBuffer = ""
542
583
  }
584
+ // Ekor escape tertahan (F1) dibuang di sini juga: abort/error/budget
585
+ // tanpa turn:completed tak boleh meninggalkan ANSI tail.
586
+ textSan.flush()
587
+ reasoningSan.flush()
588
+ bashSan.flush()
543
589
  flushReasoningTail()
544
590
  flushThinking()
545
591
  finalizeAnswer()
@@ -78,3 +78,106 @@ export function sanitizeAnsi(s: string): string {
78
78
  export function sanitizeAnsiLine(s: string): string {
79
79
  return sanitizeAnsi(s).replace(/\n/g, " ")
80
80
  }
81
+
82
+ // ── Sanitasi sadar-stream (temuan F1) ──
83
+ //
84
+ // sanitizeAnsi() bekerja pada string utuh, sedangkan teks model datang
85
+ // per-chunk: escape yang terpotong tepat di batas ("ESC[" + "32mHello")
86
+ // tampil literal "32mHello". Strateginya: tahan ekor yang MUNGKIN sekuens
87
+ // tak-lengkap, sambung ke chunk berikut SEBELUM sanitasi. Hanya ekor
88
+ // tak-lengkap yang ditahan — sekuens lengkap langsung disanitasi seperti
89
+ // dulu (perilaku lama utuh, tanpa duplikasi logika grammar: aturan
90
+ // "lengkap vs terpotong" mencerminkan escapeLength di width.ts).
91
+
92
+ /** Batas ekor tahan: OSC tanpa terminator tak boleh tumbuh tanpa batas. */
93
+ const MAX_ESC_TAIL = 4096
94
+
95
+ function isCsiParamOrInter(code: number): boolean {
96
+ // Sama seperti csiByteKind di width.ts: parameter 0x30–0x3F, intermediate
97
+ // 0x21–0x2F. SPASI bukan intermediate (komentar di width.ts).
98
+ return (code >= 0x30 && code <= 0x3f) || (code >= 0x21 && code <= 0x2f)
99
+ }
100
+
101
+ /**
102
+ * Pisahkan kemungkinan ekor escape tak-lengkap di ujung string.
103
+ * Kembalikan {head, tail}: head aman disanitasi SEKARANG, tail wajib
104
+ * disambung ke chunk berikut (atau dibuang saat stream selesai — tak pernah
105
+ * render mentah). Sekuens lengkap tidak pernah ditahan.
106
+ */
107
+ export function splitTrailingEscape(s: string): { head: string; tail: string } {
108
+ const idx = s.lastIndexOf("\x1b")
109
+ if (idx === -1) return { head: s, tail: "" }
110
+ const next = s[idx + 1]
111
+ // ESC tunggal di ujung: bisa menjadi awal apa pun → tahan.
112
+ if (next === undefined) return { head: s.slice(0, idx), tail: s.slice(idx) }
113
+ if (next === "[") {
114
+ // CSI: lengkap bila ada byte final sebelum string habis.
115
+ let j = idx + 2
116
+ while (j < s.length && isCsiParamOrInter(s.charCodeAt(j)!)) j++
117
+ if (j >= s.length) return { head: s.slice(0, idx), tail: s.slice(idx) }
118
+ return { head: s, tail: "" }
119
+ }
120
+ if (next === "]" || next === "P" || next === "_" || next === "^" || next === "X") {
121
+ // OSC/DCS/APC/PM/SOS: lengkap bila ada terminator BEL atau ESC \.
122
+ const rest = s.slice(idx + 2)
123
+ if (!rest.includes("\u0007") && !rest.includes("\x1b\\")) {
124
+ return { head: s.slice(0, idx), tail: s.slice(idx) }
125
+ }
126
+ return { head: s, tail: "" }
127
+ }
128
+ if (next === "(" || next === ")" || next === "#") {
129
+ // Charset 3-byte: tahan bila terpotong.
130
+ if (s.length - idx < 3) return { head: s.slice(0, idx), tail: s.slice(idx) }
131
+ return { head: s, tail: "" }
132
+ }
133
+ // Fe 2-byte (ESC 7, ESC M, …): lengkap.
134
+ return { head: s, tail: "" }
135
+ }
136
+
137
+ /**
138
+ * Sanitizer stateful untuk satu stream teks: push() per chunk, flush() saat
139
+ * stream selesai. Ekor tak-lengkap yang tersisa di flush() DIBUANG (bukan
140
+ * dirender) — escape tanpa teks lanjutan tak punya efek tampak kecuali
141
+ * mutasi state terminal, yang tak pernah diinginkan dari teks tak-terpercaya.
142
+ */
143
+ export interface StreamSanitizer {
144
+ push(chunk: string): string
145
+ flush(): string
146
+ }
147
+
148
+ export function createStreamSanitizer(): StreamSanitizer {
149
+ let tail = ""
150
+ return {
151
+ push(chunk: string): string {
152
+ const combined = tail + chunk
153
+ const part = splitTrailingEscape(combined)
154
+ tail = part.tail.length > MAX_ESC_TAIL ? "" : part.tail
155
+ return sanitizeAnsi(part.head)
156
+ },
157
+ flush(): string {
158
+ tail = ""
159
+ return ""
160
+ },
161
+ }
162
+ }
163
+
164
+ // ── Kebijakan ANSI non-TTY (temuan F2) ──
165
+
166
+ const ESC_CH = String.fromCharCode(27)
167
+
168
+ /** Buang SGR (sesudah sanitizeAnsi, hanya ini yang tersisa) untuk pipa. */
169
+ export function stripSgr(s: string): string {
170
+ // Pola dibangun tanpa literal kontrol (aturan lint noControlCharactersInRegex).
171
+ return s.replace(new RegExp(`${ESC_CH}\\[[0-9;:]*m`, "g"), "")
172
+ }
173
+
174
+ /**
175
+ * Satu pintu kebijakan ANSI teks tak-terpercaya: TTY → SGR dipertahankan
176
+ * (renderer mewarnai); non-TTY → semua ANSI dibuang agar pipe/CI
177
+ * deterministik. Cerminan colorLevel() di theme.ts yang mengacu
178
+ * stdout.isTTY — satu aturan untuk semua stream.
179
+ */
180
+ export function cleanUntrusted(s: string, stdoutTty: boolean): string {
181
+ const clean = sanitizeAnsi(s)
182
+ return stdoutTty ? clean : stripSgr(clean)
183
+ }
@@ -121,6 +121,13 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
121
121
  let regionOn = false
122
122
  let detached = false
123
123
  let resizeBound: (() => void) | null = null
124
+ // Geometri frame footer yang TERAKHIR dilukis (jumlah baris saat itu).
125
+ // Invarian: repaint SELALU menghapus frame lama dulu bila geometri berubah
126
+ // dan baris lama masih teralamatkan — tanpa ini setiap resize meninggalkan
127
+ // satu kopi footer yatim di scrollback (duplikat menumpuk tiap siklus
128
+ // besar-kecil, terbukti oleh model VT: 5 resize → 4 kopi). null = tidak ada
129
+ // frame hidup (belum pernah / sudah dilepas / geometri tak teralamatkan).
130
+ let paintedRows: number | null = null
124
131
  // Pulse spark: frame naik saat busy. Timer HANYA hidup selama turn; idle =
125
132
  // frame 0 (spark redup). Fail-safe: callback timer dibungkus try/catch dan
126
133
  // tak pernah menyentuh jalur turn — animasi mati, turn tetap jalan.
@@ -157,22 +164,76 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
157
164
  regionOn = true
158
165
  }
159
166
 
160
- const onResize = (): void => {
161
- try {
162
- if (!regionOn || detached) return
163
- const r = rows()
164
- if (r < 10) {
165
- // Terlalu pendek: lepas region agar tidak aneh; present berikutnya
166
- // akan me-reset ulang bila sudah muat. DECSTBM reset juga bisa
167
- // memindahkan kursor → save/restore seperti enableRegion.
167
+ // Hapus frame footer yang sedang hidup (bila teralamatkan). Dipakai saat
168
+ // geometri berubah (eraseOldFrame) dan saat detach (frame lengket tak boleh
169
+ // tertinggal sebagai duplikat salinan scrollback).
170
+ const erasePaintedFrame = (): void => {
171
+ if (paintedRows === null) return
172
+ const r = rows()
173
+ if (paintedRows - 1 >= 1 && paintedRows <= r) {
174
+ process.stdout.write(SAVE_CURSOR)
175
+ process.stdout.write(`\x1b[${paintedRows - 1};1H${CLEAR}`)
176
+ process.stdout.write(`\x1b[${paintedRows};1H${CLEAR}`)
177
+ process.stdout.write(RESTORE_CURSOR)
178
+ }
179
+ paintedRows = null
180
+ }
181
+
182
+ // Hapus frame footer LAMA bila geometri berubah dan barisnya masih
183
+ // teralamatkan di layar saat ini. Bila layar menyusut di bawah frame lama
184
+ // (paintedRows > r), frame lama sudah menjadi scrollback dan tak bisa
185
+ // dihapus via pengalamatan — catat null (jujur: yatim, bukan hidup) agar
186
+ // repaint berikut tidak salah mengira ada frame yang dijaga.
187
+ const eraseOldFrame = (r: number): void => {
188
+ if (paintedRows === null || paintedRows === r) return
189
+ erasePaintedFrame()
190
+ }
191
+
192
+ // Satu-satunya jalur yang menyentuh region/frame (present, refresh,
193
+ // setBusy, onResize SEMUA lewat sini): reset dulu (rekonsiliasi — region
194
+ // bisa hilang diam-diam saat resize ConPTY atau program anak me-reset;
195
+ // keyakinan lokal `regionOn` tak pernah dipercaya), lalu tegakkan region
196
+ // baru + hapus frame lama + lukis frame baru (kecuali pemanggil melukis
197
+ // sendiri dalam bingkai SYNC-nya, mis. present). Tiap pemanggilan sinkron
198
+ // penuh — tak ada interleaving antar-repaint (JS single thread), jadi
199
+ // state selalu konsisten antar-repaint tanpa lock.
200
+ const reconcile = (r: number, paint = true): void => {
201
+ if (detached) return
202
+ process.stdout.write(SAVE_CURSOR)
203
+ process.stdout.write(RESET_REGION)
204
+ process.stdout.write(RESTORE_CURSOR)
205
+ regionOn = false
206
+ if (r < 10) {
207
+ // Terlalu pendek: jangan tegakkan apa pun. Frame hidup (bila ada)
208
+ // kemungkinan besar terdorong reflow ke 2 baris dasar layar kecil —
209
+ // bersihkan keduanya agar tak menjadi duplikat permanen saat tumbuh
210
+ // kembali (bukti model VT: susut-ke-8 lalu tumbuh → 2 footer hidup).
211
+ // Bila reflow justru memotong bawah, ini hanya mengosongkan 2 baris
212
+ // viewport (scrollback utuh, pulih oleh output berikut) — tak pernah
213
+ // menyentuh baris di luar 2 dasar. Tanpa frame hidup: diam total.
214
+ if (paintedRows !== null && r >= 2) {
168
215
  process.stdout.write(SAVE_CURSOR)
169
- process.stdout.write(RESET_REGION)
216
+ process.stdout.write(`\x1b[${r - 1};1H${CLEAR}`)
217
+ process.stdout.write(`\x1b[${r};1H${CLEAR}`)
170
218
  process.stdout.write(RESTORE_CURSOR)
171
- regionOn = false
172
- return
173
219
  }
174
- enableRegion(r)
220
+ paintedRows = null
221
+ return
222
+ }
223
+ enableRegion(r)
224
+ eraseOldFrame(r)
225
+ if (paint) {
175
226
  paintFooter(r)
227
+ paintedRows = r
228
+ }
229
+ }
230
+
231
+ const onResize = (): void => {
232
+ try {
233
+ if (detached) return
234
+ // Resize = invalidasi total: geometri lama mati, rekonsiliasi penuh.
235
+ // Sengaja TANPA early-return regionOn — keyakinan lokal bisa basi.
236
+ reconcile(rows())
176
237
  } catch {}
177
238
  }
178
239
 
@@ -185,9 +246,8 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
185
246
  refresh() {
186
247
  if (detached) return
187
248
  try {
188
- const r = rows()
189
- if (r < 10 || !regionOn) return
190
- paintFooter(r)
249
+ // Sama seperti present tapi tanpa memindahkan kursor (prompt aktif).
250
+ reconcile(rows())
191
251
  } catch {}
192
252
  },
193
253
  setBusy(busy: boolean) {
@@ -199,8 +259,10 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
199
259
  pulseTimer = setInterval(() => {
200
260
  try {
201
261
  frame += 1
202
- const r = rows()
203
- if (regionOn && r >= 10) paintFooter(r)
262
+ // Lewat reconcile (bukan paint langsung): resize di tengah turn
263
+ // ikut menyembuhkan region + menghapus frame lama, bukan
264
+ // menumpuk frame baru di atasnya.
265
+ reconcile(rows())
204
266
  } catch {
205
267
  // Runtime rewel: matikan animasi, jangan pernah gagalkan turn.
206
268
  stopPulse()
@@ -209,8 +271,7 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
209
271
  } else {
210
272
  stopPulse()
211
273
  frame = 0
212
- const r = rows()
213
- if (regionOn && r >= 10) paintFooter(r) // kembali redup seketika
274
+ reconcile(rows()) // kembali redup seketika
214
275
  }
215
276
  } catch {}
216
277
  },
@@ -220,7 +281,6 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
220
281
  const r = rows()
221
282
  if (r < 10) return // terminal terlalu pendek — jangan sentuh apa pun
222
283
  if (!regionOn) {
223
- enableRegion(r)
224
284
  if (!resizeBound) {
225
285
  resizeBound = onResize
226
286
  try {
@@ -228,9 +288,13 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
228
288
  } catch {}
229
289
  }
230
290
  }
291
+ // Rekonsiliasi TANPA lukis (paint=false): lukisan dilakukan sekali di
292
+ // bawah dalam bingkai SYNC agar tak ada frame ganda per present.
293
+ reconcile(r, false)
231
294
  // Satu frame sinkron agar repaint footer tidak robek.
232
295
  process.stdout.write(SYNC_START)
233
296
  paintFooter(r)
297
+ paintedRows = r
234
298
  // Kursor ke baris input (tepat di atas blank footer — kini 2 baris total).
235
299
  process.stdout.write(`\x1b[${r - 2};1H`)
236
300
  process.stdout.write(SYNC_END)
@@ -247,6 +311,10 @@ export function createFooterChrome(opts: FooterChromeOptions): FooterChrome {
247
311
  } catch {}
248
312
  resizeBound = null
249
313
  }
314
+ // Hapus frame lengket dulu agar salinan scrollback di bawah bukan
315
+ // duplikatnya (sebelumnya: reset lalu cetak → dua baris status
316
+ // terlihat bersamaan sesaat).
317
+ erasePaintedFrame()
250
318
  if (regionOn) {
251
319
  process.stdout.write(RESET_REGION)
252
320
  regionOn = false