minicode-ai 0.14.0 → 0.14.2

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 (88) hide show
  1. package/README.md +1 -1
  2. package/cli/args.ts +16 -3
  3. package/cli/auto-update.ts +32 -2
  4. package/cli/commands/exec.ts +9 -0
  5. package/cli/index.ts +31 -13
  6. package/cli/setup.ts +31 -19
  7. package/cli/tui.ts +63 -40
  8. package/docs/OUTPUT_PROTOCOL_SPEC.md +6 -0
  9. package/docs/OUTPUT_RENDERING_SPEC.md +28 -4
  10. package/docs/README.md +2 -2
  11. package/docs/TERMINAL_CONTRACT.md +52 -26
  12. package/docs/agents.md +2 -2
  13. package/docs/choosing-mode.md +20 -13
  14. package/docs/cli.md +11 -11
  15. package/docs/environment.md +3 -3
  16. package/docs/getting-started.md +14 -12
  17. package/docs/glossary.md +1 -1
  18. package/docs/mcp-lsp.md +1 -1
  19. package/docs/policy-sandbox.md +7 -1
  20. package/docs/security-model.md +2 -2
  21. package/docs/security.md +7 -1
  22. package/docs/tools.md +4 -4
  23. package/docs/verify-benchmark.md +16 -0
  24. package/package.json +1 -3
  25. package/src/app/mentions.ts +4 -3
  26. package/src/app/session.ts +19 -9
  27. package/src/app/tool-layer.ts +10 -3
  28. package/src/constants.ts +17 -0
  29. package/src/lib/git-hardening.ts +27 -22
  30. package/src/lib/safe-open.ts +73 -19
  31. package/src/lib/trusted-exec.ts +7 -4
  32. package/src/mcp/client.ts +34 -9
  33. package/src/mcp/transport.ts +96 -42
  34. package/src/memory/files.ts +15 -4
  35. package/src/memory/vector.ts +5 -1
  36. package/src/policy/context.ts +21 -13
  37. package/src/policy/permission.ts +75 -16
  38. package/src/policy/tool-contract.ts +21 -10
  39. package/src/policy/update-check.ts +83 -6
  40. package/src/policy/usage.ts +17 -7
  41. package/src/policy/work-mode.ts +51 -17
  42. package/src/presentation/adapter.ts +64 -2
  43. package/src/presentation/events.ts +6 -0
  44. package/src/presentation/model.ts +1 -0
  45. package/src/presentation/projection.ts +2 -0
  46. package/src/presentation/reducer.ts +1 -0
  47. package/src/providers/anthropic.ts +52 -19
  48. package/src/providers/guards.ts +98 -13
  49. package/src/providers/responses.ts +61 -23
  50. package/src/providers/sse-bounds.ts +170 -0
  51. package/src/repo/repomap.ts +10 -11
  52. package/src/runtime/execution-backend.ts +7 -8
  53. package/src/sandbox/docker.ts +113 -9
  54. package/src/session/checkpoint.ts +9 -2
  55. package/src/session/persistence.ts +5 -2
  56. package/src/session/verification.ts +55 -16
  57. package/src/skills/loader.ts +16 -3
  58. package/src/tools/bash.ts +6 -3
  59. package/src/tools/code_run.ts +6 -5
  60. package/src/tools/context.ts +8 -0
  61. package/src/tools/delete_file.ts +2 -1
  62. package/src/tools/edit.ts +2 -1
  63. package/src/tools/git.ts +128 -54
  64. package/src/tools/glob.ts +2 -1
  65. package/src/tools/grep.ts +31 -6
  66. package/src/tools/lsp.ts +5 -4
  67. package/src/tools/mcp_call.ts +3 -1
  68. package/src/tools/memory.ts +175 -180
  69. package/src/tools/move_file.ts +2 -1
  70. package/src/tools/patch.ts +2 -1
  71. package/src/tools/read_file.ts +94 -1
  72. package/src/tools/read_image.ts +2 -1
  73. package/src/tools/task.ts +2 -1
  74. package/src/tools/todo.ts +4 -5
  75. package/src/tools/web_fetch.ts +28 -12
  76. package/src/tools/web_search.ts +28 -9
  77. package/src/tools/write_file.ts +2 -1
  78. package/src/ui/assistant/simple.ts +72 -3
  79. package/src/ui/footer.ts +17 -12
  80. package/src/ui/i18n/en.ts +6 -3
  81. package/src/ui/i18n/id.ts +6 -3
  82. package/src/ui/render/width.ts +107 -79
  83. package/src/ui/runtime/screen.ts +49 -37
  84. package/src/ui/tui/app.ts +261 -209
  85. package/src/ui/tui/transcript.ts +39 -0
  86. package/CHANGELOG.md +0 -1167
  87. package/docs/PLAN_UIUX_V6.md +0 -209
  88. package/docs/changelog.md +0 -3
@@ -1,12 +1,8 @@
1
- // Lebar tampil karakter di terminal.
1
+ // Lebar tampil teks dalam kolom terminal.
2
2
  //
3
- // Semua kode UI sebelumnya menganggap 1 karakter = 1 kolom. Itu salah untuk CJK,
4
- // Hangul, kana, emoji, dan simbol lebar-penuh — semuanya memakan DUA kolom.
5
- // Akibatnya nyata: 38 code point CJK menempati 73 kolom di terminal 40 kolom,
6
- // baris membungkus sendiri, dan frame TUI (yang dihitung per baris) rusak.
7
- //
8
- // Karakter penggabung (combining marks, variation selector, ZWJ) sebaliknya
9
- // memakan NOL kolom — "é" sebagai e+U+0301 adalah satu kolom, bukan dua.
3
+ // Ukur per grapheme, bukan per code point: satu emoji keluarga atau flag
4
+ // tersusun dari beberapa scalar tetapi tampil sebagai satu glyph dua kolom.
5
+ // Combining marks melekat pada base dan tidak menambah lebar sendiri.
10
6
  //
11
7
  // Referensi: EastAsianWidth (UAX #11) kategori W dan F. Rentang di bawah adalah
12
8
  // blok utama yang relevan untuk keluaran terminal; tidak perlu tabel lengkap
@@ -58,8 +54,77 @@ const ZERO: [number, number][] = [
58
54
  [0xfe20, 0xfe2f], // Combining Half Marks
59
55
  [0xfeff, 0xfeff], // BOM / ZWNBSP
60
56
  [0xe0100, 0xe01ef], // Variation Selectors Supplement
57
+ [0xe0020, 0xe007f], // Tag characters used by emoji flag sequences
61
58
  ]
62
59
 
60
+ const UNICODE_MARK = /\p{Mark}/u
61
+ const EMOJI = /\p{Emoji}/u
62
+ const EMOJI_PRESENTATION = /\p{Emoji_Presentation}/u
63
+ const EXTENDED_PICTOGRAPHIC = /\p{Extended_Pictographic}/u
64
+ let widthSegmenter: Intl.Segmenter | undefined
65
+
66
+ function segmentGraphemes(text: string): string[] {
67
+ try {
68
+ widthSegmenter ??= new Intl.Segmenter("und", { granularity: "grapheme" })
69
+ return Array.from(widthSegmenter.segment(text), (part) => part.segment)
70
+ } catch {
71
+ // Bun yang didukung MiniCode menyediakan Intl.Segmenter; fallback ini
72
+ // menjaga module tetap bisa dipakai di runtime tertanam yang lebih tua.
73
+ return Array.from(text)
74
+ }
75
+ }
76
+
77
+ function graphemeWidth(grapheme: string): number {
78
+ const points = Array.from(grapheme, (part) => part.codePointAt(0)!)
79
+ const has = (from: number, to: number): boolean => points.some((cp) => cp >= from && cp <= to)
80
+ const containsEmoji = points.some((cp) => EMOJI.test(String.fromCodePoint(cp)))
81
+ const containsPictograph = points.some((cp) =>
82
+ EXTENDED_PICTOGRAPHIC.test(String.fromCodePoint(cp)),
83
+ )
84
+ if (
85
+ has(0x20e3, 0x20e3) || // keycap
86
+ has(0x1f1e6, 0x1f1ff) || // regional-indicator flag (including a lone RI, conservatively)
87
+ has(0x1f3fb, 0x1f3ff) || // skin-tone modifier
88
+ (has(0x200d, 0x200d) && containsPictograph) || // emoji ZWJ sequence
89
+ (has(0xfe0f, 0xfe0f) && containsEmoji) || // explicit emoji presentation
90
+ points.some((cp) => EMOJI_PRESENTATION.test(String.fromCodePoint(cp)))
91
+ ) {
92
+ return 2
93
+ }
94
+ let width = 0
95
+ for (const cp of points) width += charWidth(cp)
96
+ return width
97
+ }
98
+
99
+ interface DisplayToken {
100
+ text: string
101
+ width: number
102
+ escape: boolean
103
+ }
104
+
105
+ /** Token terminal: escape utuh atau grapheme utuh dengan lebar display yang sama. */
106
+ function* displayTokens(s: string): Generator<DisplayToken> {
107
+ let i = 0
108
+ while (i < s.length) {
109
+ if (s[i] === "\x1b") {
110
+ const length = escapeLength(s, i)
111
+ if (length > 0) {
112
+ yield { text: s.slice(i, i + length), width: 0, escape: true }
113
+ i += length
114
+ continue
115
+ }
116
+ }
117
+ let end = s.indexOf("\x1b", i)
118
+ if (end < 0) end = s.length
119
+ if (end === i) end = i + 1
120
+ const run = s.slice(i, end)
121
+ for (const text of segmentGraphemes(run)) {
122
+ yield { text, width: graphemeWidth(text), escape: false }
123
+ }
124
+ i = end
125
+ }
126
+ }
127
+
63
128
  function inRanges(cp: number, ranges: [number, number][]): boolean {
64
129
  let lo = 0
65
130
  let hi = ranges.length - 1
@@ -83,31 +148,19 @@ export function charWidth(cp: number): number {
83
148
  if (cp === 0x09) return 8
84
149
  // C0/C1 control: tidak menempati kolom (dan seharusnya tidak sampai ke layar).
85
150
  if (cp < 0x20 || (cp >= 0x7f && cp < 0xa0)) return 0
86
- if (inRanges(cp, ZERO)) return 0
151
+ if (inRanges(cp, ZERO) || UNICODE_MARK.test(String.fromCodePoint(cp))) return 0
87
152
  if (inRanges(cp, WIDE)) return 2
88
153
  return 1
89
154
  }
90
155
 
91
156
  /**
92
157
  * Lebar tampil string dalam kolom terminal. Sekuens ANSI dan karakter
93
- * penggabung tidak dihitung; CJK/emoji dihitung dua.
158
+ * penggabung tidak dihitung; CJK/fullwidth dan emoji presentation dihitung
159
+ * dua kolom per grapheme. Lebar glyph spesifik terminal tidak diprobe.
94
160
  */
95
161
  export function displayWidth(s: string): number {
96
162
  let w = 0
97
- let i = 0
98
- while (i < s.length) {
99
- // Lewati sekuens escape — tidak menempati kolom.
100
- if (s[i] === "\x1b") {
101
- const len = escapeLength(s, i)
102
- if (len > 0) {
103
- i += len
104
- continue
105
- }
106
- }
107
- const cp = s.codePointAt(i)!
108
- w += charWidth(cp)
109
- i += cp > 0xffff ? 2 : 1
110
- }
163
+ for (const token of displayTokens(s)) if (!token.escape) w += token.width
111
164
  return w
112
165
  }
113
166
 
@@ -237,36 +290,23 @@ export function truncateToWidth(s: string, width: number, ellipsis = "..."): str
237
290
  let w = 0
238
291
  let sawSgr = false
239
292
  let cut = false
240
- let i = 0
241
- while (i < s.length) {
242
- if (s[i] === "\x1b") {
243
- const len = escapeLength(s, i)
244
- if (len > 0) {
245
- const seq = s.slice(i, i + len)
246
- // Hanya SGR yang disalin — sekuens kontrol lain (clear, alternate
247
- // screen, OSC) DIBUANG di sini agar satu pemanggil yang lupa sanitasi
248
- // tidak menjadi injeksi terminal (defense-in-depth, bukan pengganti
249
- // sanitizeAnsi di batas input tak-terpercaya).
250
- if (!isSgrSeq(seq)) {
251
- i += len
252
- continue
253
- }
254
- if (seq.endsWith("m")) sawSgr = true
255
- out += seq
256
- i += len
257
- continue
258
- }
293
+ for (const token of displayTokens(s)) {
294
+ if (token.escape) {
295
+ // Hanya SGR yang disalin — sekuens kontrol lain (clear, alternate
296
+ // screen, OSC) DIBUANG di sini agar satu pemanggil yang lupa sanitasi
297
+ // tidak menjadi injeksi terminal (defense-in-depth, bukan pengganti
298
+ // sanitizeAnsi di batas input tak-terpercaya).
299
+ if (!isSgrSeq(token.text)) continue
300
+ if (token.text.endsWith("m")) sawSgr = true
301
+ out += token.text
302
+ continue
259
303
  }
260
- const cp = s.codePointAt(i)!
261
- const cw = charWidth(cp)
262
- if (w + cw > budget) {
304
+ if (w + token.width > budget) {
263
305
  cut = true
264
306
  break
265
307
  }
266
- const size = cp > 0xffff ? 2 : 1
267
- out += s.slice(i, i + size)
268
- w += cw
269
- i += size
308
+ out += token.text
309
+ w += token.width
270
310
  }
271
311
  const tail = cut && width > ellW ? ellipsis : ""
272
312
  return sawSgr ? `${out}\x1b[0m${tail}` : out + tail
@@ -290,7 +330,6 @@ export function chunkByWidth(s: string, width: number): string[] {
290
330
  const out: string[] = []
291
331
  let cur = ""
292
332
  let w = 0
293
- let i = 0
294
333
  // Sekuens SGR yang masih "terbuka" — disuntikkan ke potongan berikutnya
295
334
  // agar warna tidak hilang saat kata berwarna panjang dipecah. SEMUA pembuka
296
335
  // diingat (bukan satu): `\x1b[1m\x1b[31m…` yang terbelah harus membawa bold
@@ -304,39 +343,28 @@ export function chunkByWidth(s: string, width: number): string[] {
304
343
  cur = openSgr.join("") // lanjutkan warna ke potongan berikutnya
305
344
  w = 0
306
345
  }
307
- while (i < s.length) {
308
- if (s[i] === "\x1b") {
309
- const len = escapeLength(s, i)
310
- if (len > 0) {
311
- const seq = s.slice(i, i + len)
312
- if (!isSgrSeq(seq)) {
313
- i += len
314
- continue
315
- }
316
- if (seq.endsWith("m")) {
317
- const params = seq.slice(2, -1).split(/[:;]/)
318
- if (params.some((p) => SGR_OFF.has(p) || p === "")) openSgr = []
319
- if (params.some((p) => p !== "" && !SGR_OFF.has(p))) {
320
- openSgr.push(seq)
321
- // Batas tumpukan: input patologis (ganti warna tiap karakter tanpa
322
- // reset) tak boleh membuat tiap potongan membawa ratusan sekuens.
323
- if (openSgr.length > 8) openSgr = openSgr.slice(-8)
324
- }
346
+ for (const token of displayTokens(s)) {
347
+ if (token.escape) {
348
+ const seq = token.text
349
+ if (!isSgrSeq(seq)) continue
350
+ if (seq.endsWith("m")) {
351
+ const params = seq.slice(2, -1).split(/[:;]/)
352
+ if (params.some((p) => SGR_OFF.has(p) || p === "")) openSgr = []
353
+ if (params.some((p) => p !== "" && !SGR_OFF.has(p))) {
354
+ openSgr.push(seq)
355
+ // Batas tumpukan: input patologis (ganti warna tiap karakter tanpa
356
+ // reset) tak boleh membuat tiap potongan membawa ratusan sekuens.
357
+ if (openSgr.length > 8) openSgr = openSgr.slice(-8)
325
358
  }
326
- cur += seq
327
- i += len
328
- continue
329
359
  }
360
+ cur += seq
361
+ continue
330
362
  }
331
- const cp = s.codePointAt(i)!
332
- const cw = charWidth(cp)
333
- const size = cp > 0xffff ? 2 : 1
334
- if (w + cw > width && cur !== "") {
363
+ if (w + token.width > width && cur !== "") {
335
364
  pushChunk()
336
365
  }
337
- cur += s.slice(i, i + size)
338
- w += cw
339
- i += size
366
+ cur += token.text
367
+ w += token.width
340
368
  }
341
369
  if (cur !== "") pushChunk()
342
370
  return out.length ? out : [""]
@@ -54,7 +54,7 @@ export interface AltScreen {
54
54
  readonly ok: boolean
55
55
  readonly cols: number
56
56
  readonly rows: number
57
- /** Lukis satu frame penuh (tepat `rows` baris dari dialog.ts). */
57
+ /** Lukis frame penuh; exception writer dipropagasikan agar owner menutup sesi. */
58
58
  paint(lines: string[], cursor?: { row: number; col: number }): void
59
59
  /**
60
60
  * Lukis REGION TANPA clear: popup di atas konten pemilik layar (App TUI).
@@ -102,6 +102,14 @@ export function openAltScreen(): AltScreen {
102
102
  process.stdout.write(RESET_REGION)
103
103
  process.stdout.write(ENTER)
104
104
  } catch {
105
+ // ENTER mungkin sudah terkirim sebelum writer melempar; pulihkan
106
+ // buffer utama sebelum menyatakan terminal tidak mampu.
107
+ try {
108
+ process.stdout.write(EXIT)
109
+ } catch {}
110
+ try {
111
+ process.stdout.write(RESET_REGION)
112
+ } catch {}
105
113
  return nullScreen()
106
114
  }
107
115
  }
@@ -130,48 +138,44 @@ export function openAltScreen(): AltScreen {
130
138
  },
131
139
  paint(lines: string[], cursor?: { row: number; col: number }): void {
132
140
  if (closed) return
133
- try {
134
- process.stdout.write(SYNC_START)
135
- process.stdout.write(HOME)
136
- process.stdout.write(CLEAR_ALL)
137
- process.stdout.write(lines.join("\r\n"))
138
- if (cursor) {
139
- const row = Math.max(1, Math.floor(cursor.row))
140
- const col = Math.max(1, Math.floor(cursor.col))
141
- process.stdout.write(`\x1b[?25l\x1b[${row};${col}H\x1b[?25h`)
142
- }
143
- process.stdout.write(SYNC_END)
144
- } catch {}
141
+ process.stdout.write(SYNC_START)
142
+ process.stdout.write(HOME)
143
+ process.stdout.write(CLEAR_ALL)
144
+ process.stdout.write(lines.join("\r\n"))
145
+ if (cursor) {
146
+ const row = Math.max(1, Math.floor(cursor.row))
147
+ const col = Math.max(1, Math.floor(cursor.col))
148
+ process.stdout.write(`\x1b[?25l\x1b[${row};${col}H\x1b[?25h`)
149
+ }
150
+ process.stdout.write(SYNC_END)
145
151
  },
146
152
  paintRegion(lines: string[], topRow: number): void {
147
153
  if (closed) return
148
154
  // Melukis nol baris = no-op murni (bukan clear): pemanggil yang ingin
149
155
  // menghapus memakai clearRegion() eksplisit.
150
156
  if (!lines.length) return
151
- try {
152
- const top = Math.max(1, Math.floor(topRow) || 1)
153
- const h = lines.length
154
- // Union region lama + baru: kotak yang menyusut/bergeser (filter,
155
- // notice hilang) harus menghapus sisa bingkainya sendiri — pemilik
156
- // layar tak tahu geometri popup.
157
- let clearTop = top
158
- let clearBottom = top + Math.max(0, h - 1)
159
- if (lastRegion) {
160
- clearTop = Math.min(clearTop, lastRegion.top)
161
- clearBottom = Math.max(clearBottom, lastRegion.top + lastRegion.height - 1)
162
- }
163
- let out = SYNC_START
164
- for (let r = clearTop; r <= clearBottom; r++) {
165
- const i = r - top
166
- // Baris diasumsi satu-baris-tersanitasi dari dialogBox (tanpa \n —
167
- // \n akan menggeser kursor dan merusak baris berikut; split defensif).
168
- const row = i >= 0 && i < h ? ((lines[i] ?? "").split("\n")[0] ?? "") : ""
169
- out += `\x1b[${r};1H\x1b[2K${row}`
170
- }
171
- out += SYNC_END
172
- process.stdout.write(out)
173
- lastRegion = h > 0 ? { top, height: h } : null
174
- } catch {}
157
+ const top = Math.max(1, Math.floor(topRow) || 1)
158
+ const h = lines.length
159
+ // Union region lama + baru: kotak yang menyusut/bergeser (filter,
160
+ // notice hilang) harus menghapus sisa bingkainya sendiri — pemilik
161
+ // layar tak tahu geometri popup.
162
+ let clearTop = top
163
+ let clearBottom = top + Math.max(0, h - 1)
164
+ if (lastRegion) {
165
+ clearTop = Math.min(clearTop, lastRegion.top)
166
+ clearBottom = Math.max(clearBottom, lastRegion.top + lastRegion.height - 1)
167
+ }
168
+ let out = SYNC_START
169
+ for (let r = clearTop; r <= clearBottom; r++) {
170
+ const i = r - top
171
+ // Baris diasumsi satu-baris-tersanitasi dari dialogBox (tanpa \n —
172
+ // \n akan menggeser kursor dan merusak baris berikut; split defensif).
173
+ const row = i >= 0 && i < h ? ((lines[i] ?? "").split("\n")[0] ?? "") : ""
174
+ out += `\x1b[${r};1H\x1b[2K${row}`
175
+ }
176
+ out += SYNC_END
177
+ process.stdout.write(out)
178
+ lastRegion = h > 0 ? { top, height: h } : null
175
179
  },
176
180
  clearRegion(): void {
177
181
  if (closed) return
@@ -195,6 +199,9 @@ export function openAltScreen(): AltScreen {
195
199
  } catch {}
196
200
  depth = Math.max(0, depth - 1)
197
201
  if (depth === 0) {
202
+ try {
203
+ process.stdout.write(SYNC_END)
204
+ } catch {}
198
205
  try {
199
206
  process.stdout.write(EXIT)
200
207
  } catch {}
@@ -218,8 +225,13 @@ export function altScreenDepth(): number {
218
225
  */
219
226
  export function forceRestoreScreenForSignal(): void {
220
227
  if (depth > 0) {
228
+ try {
229
+ process.stdout.write(SYNC_END)
230
+ } catch {}
221
231
  try {
222
232
  process.stdout.write(EXIT)
233
+ } catch {}
234
+ try {
223
235
  process.stdout.write(RESET_REGION)
224
236
  } catch {}
225
237
  depth = 0