minicode-ai 0.21.0 → 0.23.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.
- package/README.md +1 -1
- package/cli/commands/exec.ts +44 -1
- package/cli/commands.ts +15 -2
- package/cli/index.ts +11 -0
- package/cli/setup.ts +88 -33
- package/cli/tui.ts +3 -3
- package/docs/TERMINAL_CONTRACT.md +69 -13
- package/docs/architecture.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +2 -1
- package/docs/environment.md +4 -0
- package/docs/policy-sandbox.md +6 -1
- package/docs/security.md +12 -4
- package/docs/skills.md +1 -1
- package/package.json +2 -2
- package/src/app/session.ts +129 -20
- package/src/config.ts +108 -8
- package/src/constants.ts +29 -4
- package/src/daemon/discovery.ts +24 -0
- package/src/policy/bash-guard.ts +170 -6
- package/src/policy/compaction.ts +61 -7
- package/src/policy/context-budget.ts +132 -0
- package/src/policy/context-escalation.ts +140 -0
- package/src/policy/context-window.ts +47 -9
- package/src/policy/context.ts +10 -1
- package/src/policy/jail.ts +10 -22
- package/src/policy/microcompact.ts +162 -0
- package/src/policy/permission.ts +9 -6
- package/src/presentation/projection.ts +1 -1
- package/src/providers/anthropic.ts +31 -7
- package/src/providers/detect.ts +128 -13
- package/src/providers/provision.ts +78 -1
- package/src/providers/responses.ts +14 -2
- package/src/providers/sse-bounds.ts +16 -2
- package/src/session/persistence.ts +56 -0
- package/src/ui/approval/prompt.ts +17 -6
- package/src/ui/assistant/simple.ts +1 -1
- package/src/ui/footer.ts +2 -2
- package/src/ui/i18n/en.ts +28 -5
- package/src/ui/i18n/id.ts +30 -5
- package/src/ui/input/input.ts +2 -2
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/activity-panel.ts +21 -3
- package/src/ui/render/diff.ts +51 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/hint.ts +28 -0
- package/src/ui/render/logo.ts +91 -0
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +28 -5
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +16 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +17 -5
- package/src/ui/runtime/screen.ts +4 -2
- package/src/ui/screens/dialog.ts +23 -2
- package/src/ui/screens/form.ts +71 -33
- package/src/ui/screens/lifecycle.ts +80 -0
- package/src/ui/screens/model-manager.ts +85 -83
- package/src/ui/screens/picker.ts +39 -25
- package/src/ui/screens/provider-manager.ts +58 -55
- package/src/ui/screens/watchdog.ts +27 -0
- package/src/ui/screens/wizard.ts +12 -1
- package/src/ui/tui/app.ts +62 -22
- package/src/ui/tui/transcript.ts +93 -23
- package/vendor/minicore/src/core/compact.ts +10 -0
- package/vendor/minicore/src/core/errors.ts +11 -1
- package/vendor/minicore/src/core/executor.ts +6 -1
- package/vendor/minicore/src/core/loop.ts +92 -2
- package/vendor/minicore/src/core/session.ts +8 -0
- package/vendor/minicore/src/providers/openai-compat.ts +45 -3
package/src/ui/render/diff.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
// Diff renderer - Ubuntu Server style: indentasi + warna, tanpa border.
|
|
2
|
+
import { t } from "../i18n/locale.ts"
|
|
2
3
|
import { sanitizeAnsi, sanitizeAnsiLine } from "./sanitize.ts"
|
|
3
4
|
import { c } from "./theme.ts"
|
|
4
5
|
import { truncateToWidth, wrapByWidth } from "./width.ts"
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Batas input diff (audit 2026-11-12, HIGH-5).
|
|
9
|
+
*
|
|
10
|
+
* LCS kata adalah O(n·m) waktu DAN memori (matriks dp penuh). Argumen
|
|
11
|
+
* `edit` datang mentah dari model dan skemanya tak membatasi panjang: satu
|
|
12
|
+
* baris 8k kata butuh ~2 dtk + ratusan MB, dan 20k kata berujung OOM — cukup
|
|
13
|
+
* untuk membekukan CLI linear sebelum satu byte pun dicetak. Dipotong di sini
|
|
14
|
+
* (bukan di schema tool) supaya renderer aman untuk pemanggil mana pun.
|
|
15
|
+
*/
|
|
16
|
+
const DIFF_MAX_CHARS = 64 * 1024
|
|
17
|
+
const DIFF_MAX_LINES = 2000
|
|
18
|
+
/** Sel matriks LCS kata maksimum; di atas ini sorotan-per-kata dilepas. */
|
|
19
|
+
const WORD_LCS_MAX_CELLS = 250_000
|
|
20
|
+
|
|
21
|
+
/** Potong input diff pada batas baris terdekat agar tak ada baris separuh. */
|
|
22
|
+
function capDiffInput(text: string): { text: string; truncated: boolean } {
|
|
23
|
+
const lines = text.split("\n")
|
|
24
|
+
if (lines.length > DIFF_MAX_LINES) {
|
|
25
|
+
return { text: lines.slice(0, DIFF_MAX_LINES).join("\n"), truncated: true }
|
|
26
|
+
}
|
|
27
|
+
if (text.length <= DIFF_MAX_CHARS) return { text, truncated: false }
|
|
28
|
+
const head = text.slice(0, DIFF_MAX_CHARS)
|
|
29
|
+
const nl = head.lastIndexOf("\n")
|
|
30
|
+
return { text: nl > 0 ? head.slice(0, nl) : head, truncated: true }
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
export interface DiffLine {
|
|
7
34
|
type: "add" | "delete" | "context"
|
|
8
35
|
oldLine?: number
|
|
@@ -80,6 +107,15 @@ export function markChangedWords(
|
|
|
80
107
|
const b = tokenizeWords(newLine)
|
|
81
108
|
const n = a.length
|
|
82
109
|
const m = b.length
|
|
110
|
+
// Baris raksasa (minified JSON, satu baris hasil generate): LCS penuh =
|
|
111
|
+
// ratusan MB. Semua token ditandai berubah → paintWords menampilkan polos
|
|
112
|
+
// (rasio > 0.6), jadi tak ada info hilang, hanya tanpa sorotan kata.
|
|
113
|
+
if (n * m > WORD_LCS_MAX_CELLS) {
|
|
114
|
+
return {
|
|
115
|
+
oldMask: new Array<boolean>(n).fill(true),
|
|
116
|
+
newMask: new Array<boolean>(m).fill(true),
|
|
117
|
+
}
|
|
118
|
+
}
|
|
83
119
|
const dp: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0))
|
|
84
120
|
for (let i = n - 1; i >= 0; i--)
|
|
85
121
|
for (let j = m - 1; j >= 0; j--)
|
|
@@ -119,9 +155,17 @@ export function renderDiffCard(
|
|
|
119
155
|
// dirender. Tanpa ini `\n` di path menjadi baris diff palsu dan `ESC[2J`
|
|
120
156
|
// lolos via `cut` (truncate menyalin escape apa pun sebelum F-04).
|
|
121
157
|
const safePath = sanitizeAnsiLine(filePath)
|
|
122
|
-
const
|
|
158
|
+
const cappedOld = capDiffInput(oldText)
|
|
159
|
+
const cappedNew = capDiffInput(newText)
|
|
160
|
+
const diff = computeLineDiff(sanitizeAnsi(cappedOld.text), sanitizeAnsi(cappedNew.text))
|
|
123
161
|
const changes = diff.filter((d) => d.type !== "context")
|
|
124
|
-
|
|
162
|
+
// Tanpa perubahan pada PREFIKS yang dipotong, jangan klaim "no changes":
|
|
163
|
+
// perbedaan bisa berada di bagian yang dibuang. Marker truncasi menang.
|
|
164
|
+
if (changes.length === 0) {
|
|
165
|
+
return c.muted(
|
|
166
|
+
` ${t(cappedOld.truncated || cappedNew.truncated ? "diff.truncated" : "diff.noChanges")}`,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
125
169
|
// Pasangan del/add untuk sorot kata: kelompokkan run perubahan beruntun,
|
|
126
170
|
// pasangkan del ke-i dengan add ke-i (pola hunk unified).
|
|
127
171
|
const wordMask = new Map<number, boolean[]>()
|
|
@@ -198,5 +242,10 @@ export function renderDiffCard(
|
|
|
198
242
|
} else lines.push(...wrapDiffLine(" ", d.content, (s) => c.dim(s)))
|
|
199
243
|
count++
|
|
200
244
|
}
|
|
245
|
+
// Pemotongan input WAJIB terlihat: user harus tahu diff yang tampil bukan
|
|
246
|
+
// keseluruhan perubahan (OUTPUT_UX_RULES: truncate selalu dengan marker).
|
|
247
|
+
if (cappedOld.truncated || cappedNew.truncated) {
|
|
248
|
+
lines.push(c.muted(` ${t("diff.truncated")}`))
|
|
249
|
+
}
|
|
201
250
|
return lines.join("\n")
|
|
202
251
|
}
|
|
@@ -182,30 +182,58 @@ function highlightTsLine(line: string): string {
|
|
|
182
182
|
return highlightTsTokens(line)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Jalankan `fn` hanya pada bagian DI LUAR sekuens SGR.
|
|
187
|
+
*
|
|
188
|
+
* Sekuens SGR yang dipertahankan sanitizeAnsi adalah byte opak. Dulu tokenizer
|
|
189
|
+
* melihat isinya dan mewarnai `1`/`31` sebagai angka, memecah escape sehingga
|
|
190
|
+
* user melihat literal `1;31m` di dalam code fence (audit 2026-11-12, HIGH-4).
|
|
191
|
+
* Regex di-reuse dengan `lastIndex` direset tiap panggilan.
|
|
192
|
+
*/
|
|
193
|
+
// Dibangun tanpa literal kontrol (aturan lint noControlCharactersInRegex).
|
|
194
|
+
const SGR_SEQ = new RegExp(`${String.fromCharCode(27)}\\[[0-9;:]*m`, "g")
|
|
195
|
+
|
|
196
|
+
function mapOutsideSgr(line: string, fn: (chunk: string) => string): string {
|
|
197
|
+
SGR_SEQ.lastIndex = 0
|
|
198
|
+
let out = ""
|
|
199
|
+
let last = 0
|
|
200
|
+
let m = SGR_SEQ.exec(line)
|
|
201
|
+
while (m) {
|
|
202
|
+
if (m.index > last) out += fn(line.slice(last, m.index))
|
|
203
|
+
out += m[0]
|
|
204
|
+
last = m.index + m[0].length
|
|
205
|
+
m = SGR_SEQ.exec(line)
|
|
206
|
+
}
|
|
207
|
+
if (last < line.length) out += fn(line.slice(last))
|
|
208
|
+
return out
|
|
209
|
+
}
|
|
210
|
+
|
|
185
211
|
function highlightTsTokens(text: string): string {
|
|
186
212
|
// Regex to match string literals, numbers, identifiers, operators
|
|
187
213
|
const tokenRe =
|
|
188
214
|
/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|\b\d+(?:\.\d+)?\b|\b[A-Za-z_$][A-Za-z0-9_$]*\b|[{}()[\];:,.<>=+\-*/%!&|^~?]+|\s+)/g
|
|
189
|
-
return text
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
return mapOutsideSgr(text, (chunk) =>
|
|
216
|
+
chunk.replace(tokenRe, (token) => {
|
|
217
|
+
if (token.startsWith('"') || token.startsWith("'") || token.startsWith("`")) {
|
|
218
|
+
return c.string(token)
|
|
219
|
+
}
|
|
220
|
+
if (/^\d+(?:\.\d+)?$/.test(token)) {
|
|
221
|
+
return c.brightYellow(token)
|
|
222
|
+
}
|
|
223
|
+
if (TS_KEYWORDS.has(token)) {
|
|
224
|
+
return c.brightMagenta(c.bold(token))
|
|
225
|
+
}
|
|
226
|
+
if (/^[A-Z][A-Za-z0-9_$]*$/.test(token)) {
|
|
227
|
+
// Type / Class name
|
|
228
|
+
return c.brightCyan(token)
|
|
229
|
+
}
|
|
230
|
+
// Tidak ada cabang khusus untuk true/false/null/undefined: keempatnya sudah
|
|
231
|
+
// ada di TS_KEYWORDS, jadi cabang di atas selalu menang. Cabang terpisah
|
|
232
|
+
// yang pernah ada di sini tak pernah terjangkau (terlihat saat coverage
|
|
233
|
+
// highlight.ts dinaikkan: satu baris mustahil dicapai test apa pun).
|
|
234
|
+
return token
|
|
235
|
+
}),
|
|
236
|
+
)
|
|
209
237
|
}
|
|
210
238
|
|
|
211
239
|
function highlightPythonLine(line: string): string {
|
|
@@ -221,22 +249,24 @@ function highlightPythonLine(line: string): string {
|
|
|
221
249
|
function highlightPythonTokens(text: string): string {
|
|
222
250
|
const tokenRe =
|
|
223
251
|
/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\b\d+(?:\.\d+)?\b|\b[A-Za-z_][A-Za-z0-9_]*\b|[{}()[\];:,.<>=+\-*/%!&|^~?]+|\s+)/g
|
|
224
|
-
return text
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
252
|
+
return mapOutsideSgr(text, (chunk) =>
|
|
253
|
+
chunk.replace(tokenRe, (token) => {
|
|
254
|
+
if (token.startsWith('"') || token.startsWith("'")) {
|
|
255
|
+
return c.string(token)
|
|
256
|
+
}
|
|
257
|
+
if (/^\d+/.test(token)) return c.brightYellow(token)
|
|
258
|
+
if (PY_KEYWORDS.has(token)) return c.brightMagenta(c.bold(token))
|
|
259
|
+
if (/^[A-Z][A-Za-z0-9_]*$/.test(token)) return c.brightCyan(token)
|
|
260
|
+
return token
|
|
261
|
+
}),
|
|
262
|
+
)
|
|
233
263
|
}
|
|
234
264
|
|
|
235
265
|
function highlightJsonLine(line: string): string {
|
|
236
266
|
// Key vs string value vs number/bool
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
(match, str, colon, bool, num) => {
|
|
267
|
+
const tokenRe = /("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|\b(-?\d+(?:\.\d+)?)\b/g
|
|
268
|
+
return mapOutsideSgr(line, (chunk) =>
|
|
269
|
+
chunk.replace(tokenRe, (match, str, colon, bool, num) => {
|
|
240
270
|
if (str) {
|
|
241
271
|
if (colon) return c.brightCyan(str) + colon
|
|
242
272
|
return c.string(str)
|
|
@@ -244,7 +274,7 @@ function highlightJsonLine(line: string): string {
|
|
|
244
274
|
if (bool) return c.yellow(bool)
|
|
245
275
|
if (num) return c.brightYellow(num)
|
|
246
276
|
return match
|
|
247
|
-
},
|
|
277
|
+
}),
|
|
248
278
|
)
|
|
249
279
|
}
|
|
250
280
|
|
|
@@ -261,15 +291,16 @@ function highlightShellLine(line: string): string {
|
|
|
261
291
|
function highlightShellTokens(text: string): string {
|
|
262
292
|
// Alternatif flag (`-x`/`--long`) WAJIB sebelum kata: tanpa itu `-` tak pernah
|
|
263
293
|
// jadi awal token (cabang yellow di bawah mati — dulu flag tampil polos).
|
|
264
|
-
|
|
265
|
-
/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\$[A-Za-z0-9_]+|-{1,2}[A-Za-z0-9][A-Za-z0-9_-]*|\b[A-Za-z_][A-Za-z0-9_-]*\b|\s+)/g
|
|
266
|
-
|
|
294
|
+
const tokenRe =
|
|
295
|
+
/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\$[A-Za-z0-9_]+|-{1,2}[A-Za-z0-9][A-Za-z0-9_-]*|\b[A-Za-z_][A-Za-z0-9_-]*\b|\s+)/g
|
|
296
|
+
return mapOutsideSgr(text, (chunk) =>
|
|
297
|
+
chunk.replace(tokenRe, (token) => {
|
|
267
298
|
if (token.startsWith('"') || token.startsWith("'")) return c.string(token)
|
|
268
299
|
if (token.startsWith("$")) return c.brightCyan(token)
|
|
269
300
|
if (SH_KEYWORDS.has(token)) return c.brightMagenta(c.bold(token))
|
|
270
301
|
if (token.startsWith("-")) return c.yellow(token)
|
|
271
302
|
return token
|
|
272
|
-
},
|
|
303
|
+
}),
|
|
273
304
|
)
|
|
274
305
|
}
|
|
275
306
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Petunjuk aksi minimalis untuk jendela pilihan / manager / form.
|
|
2
|
+
//
|
|
3
|
+
// Bentuk sengaja "a add" (bukan "a: add"): kunci pendek, pemisah satu SPASI,
|
|
4
|
+
// label redup — kunci yang bisa ditekan lebih terang. Ini menyeragamkan seluruh
|
|
5
|
+
// jendela MiniCode yang sebelumnya menulis hint dengan gaya berbeda-beda
|
|
6
|
+
// ("a add · d delete" vs footer form vs tanpa hint sama sekali), dan tetap
|
|
7
|
+
// mematuhi kontrak v7.8 (tanpa judul, tanpa footer dekoratif di dalam kotak):
|
|
8
|
+
// hint ditaruh sebagai baris body paling bawah, bukan chrome kotak.
|
|
9
|
+
import { c } from "../render/theme.ts"
|
|
10
|
+
|
|
11
|
+
export interface HintItem {
|
|
12
|
+
/** Tombol yang benar-benar berlaku di permukaan ini. */
|
|
13
|
+
key: string
|
|
14
|
+
/** Label pendek, title case/lowercase mengikuti bahasa. */
|
|
15
|
+
label: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Warna kunci (lebih terang) vs label (redup) — aksesibel tanpa warna. */
|
|
19
|
+
export function paintHint(item: HintItem): string {
|
|
20
|
+
return `${c.accent(item.key)} ${c.dim(item.label)}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Satu baris hint: `a add · d hapus · Esc tutup` (tanpa awalan/akhiran).
|
|
24
|
+
* Tanpa pembungkus faint di seluruh baris: itu akan meredupkan KUNCI juga
|
|
25
|
+
* (SGR 2 tak dibatalkan warna). Kunci = accent (lebih terang), label = dim. */
|
|
26
|
+
export function hintLine(items: readonly HintItem[]): string {
|
|
27
|
+
return items.map(paintHint).join(` ${c.faint("·")} `)
|
|
28
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Block logo minicode: mark wordmark pemilik, dikonversi dari SVG vektor
|
|
2
|
+
// (CorelDRAW) menjadi grid 17 kolom × 9 baris sel.
|
|
3
|
+
//
|
|
4
|
+
// ASPEK PER-SEL — inti modul ini. Satu karakter terminal TIDAK persegi:
|
|
5
|
+
// tingginya ±2× lebarnya. Menggambar satu sel = satu karakter penuh membuat
|
|
6
|
+
// setiap "kotak" logo tampak persegi panjang (tinggi > lebar). Solusi: setiap
|
|
7
|
+
// sel logis dipetakan ke SETENGAH sel karakter (upper/lower half block), yang
|
|
8
|
+
// kotak tintanya persegi di terminal tipikal (lebar 1 kolom, tinggi ½ baris).
|
|
9
|
+
//
|
|
10
|
+
// Komposisi 2 sel logis bertumpuk → 1 baris karakter, memakai glyph set yang
|
|
11
|
+
// sudah ada (U+2580–U+2584):
|
|
12
|
+
// atas∅ bawah∅ → ' '
|
|
13
|
+
// atas█ bawah█ → '█' (kedua sel terisi)
|
|
14
|
+
// atas█ bawah∅ → '▀' (hanya sel atas)
|
|
15
|
+
// 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.
|
|
19
|
+
//
|
|
20
|
+
// Fallback: terminal tanpa UTF-8 (MINICODE_ASCII/mini console legacy) memakai
|
|
21
|
+
// '#' 9 baris — aspek setengah-sel tidak tersedia di sana, jadi bentuk penuh
|
|
22
|
+
// dipertahankan agar pola tidak terpotong.
|
|
23
|
+
//
|
|
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).
|
|
27
|
+
|
|
28
|
+
import { supportsUtf8 } from "./theme.ts"
|
|
29
|
+
|
|
30
|
+
const ROWS = [
|
|
31
|
+
" ##### ",
|
|
32
|
+
" ### #######",
|
|
33
|
+
"##### ## ##",
|
|
34
|
+
"## ### ## ##",
|
|
35
|
+
"## ## ##",
|
|
36
|
+
"## ## ##",
|
|
37
|
+
"## ## ### ##",
|
|
38
|
+
"###### ### ###",
|
|
39
|
+
" #### ##### ",
|
|
40
|
+
] as const
|
|
41
|
+
|
|
42
|
+
/** Dimensi logis logo (sel), untuk pemanggil yang butuh geometri/centering. */
|
|
43
|
+
export const LOGO_WIDTH = 17
|
|
44
|
+
export const LOGO_HEIGHT = 9
|
|
45
|
+
|
|
46
|
+
/** Glyph sel terisi (fallback ASCII). */
|
|
47
|
+
export function logoBlock(): string {
|
|
48
|
+
return supportsUtf8() ? "█" : "#"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Apakah terminal mampu glyph half-block (U+2580/U+2584/U+2588)? */
|
|
52
|
+
export function supportsHalfBlocks(): boolean {
|
|
53
|
+
return supportsUtf8()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function halfLine(top: string, bottom: string): string {
|
|
57
|
+
let out = ""
|
|
58
|
+
for (let x = 0; x < LOGO_WIDTH; x++) {
|
|
59
|
+
const up = top[x] === "#"
|
|
60
|
+
const down = bottom[x] === "#"
|
|
61
|
+
if (up && down) out += "█"
|
|
62
|
+
else if (up) out += "▀"
|
|
63
|
+
else if (down) out += "▄"
|
|
64
|
+
else out += " "
|
|
65
|
+
}
|
|
66
|
+
return out
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Baris logo, kotak-per-sel:
|
|
71
|
+
* - UTF-8: gabungkan 2 sel logis per baris dengan glyph half-block (5 baris).
|
|
72
|
+
* - ASCII/legacy: tetap 1 sel per karakter (9 baris) supaya pola tidak hilang.
|
|
73
|
+
*/
|
|
74
|
+
export function renderLogoRows(): string[] {
|
|
75
|
+
if (!supportsUtf8()) {
|
|
76
|
+
const block = logoBlock()
|
|
77
|
+
return ROWS.map((row) => row.replace(/#/g, block))
|
|
78
|
+
}
|
|
79
|
+
const out: string[] = []
|
|
80
|
+
for (let y = 0; y < ROWS.length; y += 2) {
|
|
81
|
+
const top = ROWS[y] ?? " ".repeat(LOGO_WIDTH)
|
|
82
|
+
const bottom = ROWS[y + 1] ?? " ".repeat(LOGO_WIDTH)
|
|
83
|
+
out.push(halfLine(top, bottom))
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Jumlah baris hasil render (bukan tinggi grid logis). */
|
|
89
|
+
export function renderLogoLineCount(): number {
|
|
90
|
+
return supportsUtf8() ? Math.ceil(LOGO_HEIGHT / 2) : LOGO_HEIGHT
|
|
91
|
+
}
|
|
@@ -98,9 +98,13 @@ export function sanitizeAnsi(s: string): string {
|
|
|
98
98
|
/**
|
|
99
99
|
* Versi satu-baris: newline juga dibuang (jadi spasi).
|
|
100
100
|
* Untuk tempat yang menggambar tepat satu baris — judul, label, sel tabel.
|
|
101
|
+
*
|
|
102
|
+
* U+2028/U+2029 (LINE/PARAGRAPH SEPARATOR) ikut jadi spasi: sebagian terminal
|
|
103
|
+
* memperlakukannya sebagai pindah baris, dan satu label yang memecah baris
|
|
104
|
+
* menggeser seluruh geometri frame (audit 2026-11-12).
|
|
101
105
|
*/
|
|
102
106
|
export function sanitizeAnsiLine(s: string): string {
|
|
103
|
-
return sanitizeAnsi(s).replace(
|
|
107
|
+
return sanitizeAnsi(s).replace(/[\n\u2028\u2029]/g, " ")
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
// ── Sanitasi sadar-stream (temuan F1) ──
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// merata di semua terminal dan pernah membuat "minicode" tak tampil. Bold polos
|
|
9
9
|
// via `c` menjamin selalu terlihat + hormati NO_COLOR.
|
|
10
10
|
|
|
11
|
+
import { t } from "../i18n/locale.ts"
|
|
12
|
+
import { renderLogoRows } from "./logo.ts"
|
|
11
13
|
import { formatUsd } from "./money.ts"
|
|
12
14
|
import { sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
13
15
|
import { c } from "./theme.ts"
|
|
@@ -19,12 +21,22 @@ function paintWordmark(): string {
|
|
|
19
21
|
return c.bold(WORDMARK)
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
/** Block logo pemilik (9×19) dicat dengan aksen brand — jatuh ke plain saat
|
|
25
|
+
* NO_COLOR, dan ke '#' saat terminal tanpa UTF-8 (fallback di logo.ts). */
|
|
26
|
+
function paintLogo(): string[] {
|
|
27
|
+
return renderLogoRows().map((row) => c.accent(row))
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export interface SessionSummary {
|
|
23
31
|
sessionId: string
|
|
24
32
|
model: string
|
|
25
33
|
totalTokens: number
|
|
26
34
|
cost?: number
|
|
27
35
|
durationMs: number
|
|
36
|
+
/** Input token (Fase 7 ukur): penyebut hit-rate cache. */
|
|
37
|
+
inputTokens?: number
|
|
38
|
+
/** Token yang dibaca dari prompt cache (Fase 7 ukur). 0/undefined = nol. */
|
|
39
|
+
cacheReadTokens?: number
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
/** "3m 12s" / "1m 5s" / "45s" untuk durasi manusia. */
|
|
@@ -36,19 +48,30 @@ export function formatDuration(ms: number): string {
|
|
|
36
48
|
|
|
37
49
|
/** Render kop: wordmark + detail sesi (baris demi baris). */
|
|
38
50
|
export function renderSessionSummary(s: SessionSummary): string {
|
|
39
|
-
|
|
51
|
+
// Parameter dinamai `text`, bukan `t`: `t` sudah dipakai untuk i18n.
|
|
52
|
+
const label = (text: string): string => c.muted(text.padEnd(7))
|
|
40
53
|
const cost = s.cost != null ? formatUsd(s.cost) : null
|
|
54
|
+
// Fase 7 ukur: fraksi input dari cache; tampil hanya bila cache read > 0.
|
|
55
|
+
const cacheRead = s.cacheReadTokens ?? 0
|
|
56
|
+
const input = s.inputTokens ?? 0
|
|
57
|
+
const cachePart =
|
|
58
|
+
cacheRead > 0 && input > 0
|
|
59
|
+
? ` · cache ${cacheRead.toLocaleString()} (${Math.round((cacheRead / input) * 100)}%)`
|
|
60
|
+
: ""
|
|
41
61
|
// sessionId/model = input tak-terpercaya (config/network): buang SEMUA ANSI
|
|
42
62
|
// (termasuk SGR) sebelum dibungkus style — nilai mentah hanya boleh muncul
|
|
43
63
|
// sebagai teks polos, styling ditambahkan pemanggil (aturan repo).
|
|
44
64
|
const clean = (v: string): string => stripSgr(sanitizeAnsiLine(v))
|
|
45
65
|
return `${[
|
|
66
|
+
"",
|
|
67
|
+
...paintLogo(),
|
|
68
|
+
"",
|
|
46
69
|
paintWordmark(),
|
|
47
|
-
`${label("
|
|
48
|
-
`${label("
|
|
49
|
-
`${label("
|
|
70
|
+
`${label(t("summary.session"))} ${c.gray(clean(s.sessionId))}`,
|
|
71
|
+
`${label(t("summary.model"))} ${c.gray(clean(s.model))}`,
|
|
72
|
+
`${label(t("summary.usage"))} ${s.totalTokens.toLocaleString()} ${t("summary.tokens")}${
|
|
50
73
|
cost != null ? ` · ${cost}` : ""
|
|
51
|
-
} · ${formatDuration(s.durationMs)}`,
|
|
74
|
+
}${cachePart} · ${formatDuration(s.durationMs)}`,
|
|
52
75
|
]
|
|
53
76
|
.join("\r\n")
|
|
54
77
|
.concat("\r\n")}`
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { MarkdownTable, PipeTableAlignment } from "./markdown-table.ts"
|
|
2
|
-
import { cleanUntrusted, sanitizeAnsiLine } from "./sanitize.ts"
|
|
2
|
+
import { cleanUntrusted, sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
3
3
|
import { c, getTerminalWidth, supportsUtf8 } from "./theme.ts"
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
displayWidth,
|
|
6
|
+
graphemeWidth,
|
|
7
|
+
padToWidth,
|
|
8
|
+
segmentGraphemes,
|
|
9
|
+
truncateToWidth,
|
|
10
|
+
wrapByWidth,
|
|
11
|
+
} from "./width.ts"
|
|
5
12
|
|
|
6
13
|
export interface GridColumn {
|
|
7
14
|
header: string
|
|
@@ -28,6 +35,9 @@ export interface GridRenderOptions {
|
|
|
28
35
|
wrap?: boolean
|
|
29
36
|
/** Render sebagai kotak ber-garis (opencode-like) dengan padding dalam sel. */
|
|
30
37
|
box?: boolean
|
|
38
|
+
/** Minimum kolom proporsional (tabel markdown jawaban model) alih-alih
|
|
39
|
+
* minimum atomik 1–3 kolom. Lihat `fairMinimums`. */
|
|
40
|
+
fairMinimums?: boolean
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
const DEFAULT_ELLIPSIS = "…"
|
|
@@ -100,13 +110,84 @@ function naturalWidths(table: GridTable, maxCellWidth: number): number[] {
|
|
|
100
110
|
})
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Minimum per kolom berdasarkan ATOMIC WIDTH isinya.
|
|
115
|
+
*
|
|
116
|
+
* Lebar kolom 1 memotong grapheme 2 kolom (CJK/emoji) sehingga baris data
|
|
117
|
+
* menjadi lebih lebar dari border — terminal membungkusnya sendiri dan tinggi
|
|
118
|
+
* frame meleset (audit 2026-11-12, MEDIUM-8). Kolom yang isinya memuat
|
|
119
|
+
* grapheme 2 kolom minimal 2 (dibatasi lebar naturalnya).
|
|
120
|
+
*/
|
|
121
|
+
function atomicMinimums(table: GridTable, natural: readonly number[]): number[] {
|
|
122
|
+
return table.headers.map((_, col) => {
|
|
123
|
+
const naturalW = natural[col] ?? 1
|
|
124
|
+
if (naturalW >= 2) return 1
|
|
125
|
+
const cells = [table.headers[col] ?? "", ...table.rows.map((row) => row[col] ?? "")]
|
|
126
|
+
for (const cell of cells) {
|
|
127
|
+
for (const g of segmentGraphemes(cleanCell(cell))) {
|
|
128
|
+
if (graphemeWidth(g) >= 2) return 2
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return 1
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Lebar minimum KONTEN per kolom untuk render markdown (jawaban model).
|
|
137
|
+
*
|
|
138
|
+
* Minimum 1 kolom membuat kolom identifier (mis. `read_file`, path, hash)
|
|
139
|
+
* terbelah di tengah token saat terminal sempit — `read_fi` / `le`. Untuk
|
|
140
|
+
* tabel jawaban model lebih baik kolom pendek dikorbankan sedikit agar kolom
|
|
141
|
+
* panjang punya ruang: `MIN_MD_CONTENT_WIDTH` kolom, ditambah bagian
|
|
142
|
+
* proporsional (maks `min(natural, MAX)`), supaya kolom lebar tidak menyusut
|
|
143
|
+
* jadi satu potongan grapheme. Ini tetap deterministik (fungsi murni nilai).
|
|
144
|
+
*/
|
|
145
|
+
const MIN_MD_CONTENT_WIDTH = 6
|
|
146
|
+
const MAX_MD_FAIR_MINIMUM = 14
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Minimum "pintar" untuk tabel jawaban model: lebar TOKEN terpanjang di kolom.
|
|
150
|
+
*
|
|
151
|
+
* `read_file` cukup 9 kolom — memberi kolom itu 9 (bukan 1, bukan 50) berarti
|
|
152
|
+
* kolom identifier tak terbelah di tengah kata sementara kolom prosa tetap
|
|
153
|
+
* mendapat sisa ruang. Ditutup `MAX_MD_FAIR_MINIMUM` supaya satu path panjang
|
|
154
|
+
* di satu baris tidak memborong seluruh lebar terminal, dan tak pernah
|
|
155
|
+
* melebihi lebar natural kolom itu sendiri.
|
|
156
|
+
*/
|
|
157
|
+
function fairMinimums(table: GridTable, natural: readonly number[]): number[] {
|
|
158
|
+
return natural.map((value, col) => {
|
|
159
|
+
let longestToken = Math.min(value, MIN_MD_CONTENT_WIDTH)
|
|
160
|
+
const cells = [table.headers[col] ?? "", ...table.rows.map((row) => row[col] ?? "")]
|
|
161
|
+
for (const cell of cells) {
|
|
162
|
+
for (const token of cleanCell(cell).split(/\s+/)) {
|
|
163
|
+
longestToken = Math.max(longestToken, displayWidth(token))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return Math.max(1, Math.min(value || 1, Math.min(longestToken, MAX_MD_FAIR_MINIMUM)))
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function fitWidths(
|
|
171
|
+
natural: readonly number[],
|
|
172
|
+
budget: number,
|
|
173
|
+
minimums: number[],
|
|
174
|
+
): number[] | null {
|
|
175
|
+
const widths = natural.map((value, i) => Math.max(minimums[i]!, value))
|
|
105
176
|
const naturalTotal = widths.reduce((sum, value) => sum + value, 0)
|
|
106
177
|
if (naturalTotal <= budget) return widths
|
|
107
|
-
const
|
|
178
|
+
const floor = minimums.reduce((sum, value) => sum + value, 0)
|
|
179
|
+
// Minimum bersama lebih besar dari ruang tersedia: susutkan SEMUA minimum
|
|
180
|
+
// secara proporsional (bukan menyerah ke render vertical) — geometri tabel
|
|
181
|
+
// dipertahankan dan tiap kolom tetap dapat bagian sebanding lebar isinya.
|
|
182
|
+
const scale = floor > budget && floor > 0 ? budget / floor : 1
|
|
183
|
+
const applied =
|
|
184
|
+
scale >= 1
|
|
185
|
+
? minimums
|
|
186
|
+
: minimums.map((m, i) => Math.max(1, Math.min(natural[i] || 1, Math.floor(m * scale))))
|
|
187
|
+
const appliedFloor = applied.reduce((sum, value) => sum + value, 0)
|
|
188
|
+
const room = budget - appliedFloor
|
|
108
189
|
if (room < 0) return null
|
|
109
|
-
const extras = widths.map((value) => value -
|
|
190
|
+
const extras = widths.map((value, i) => value - applied[i]!)
|
|
110
191
|
const extraTotal = extras.reduce((sum, value) => sum + value, 0)
|
|
111
192
|
if (extraTotal <= 0) return null
|
|
112
193
|
let assigned = 0
|
|
@@ -114,7 +195,7 @@ function fitWidths(natural: readonly number[], budget: number, minimum: number):
|
|
|
114
195
|
const share =
|
|
115
196
|
i === widths.length - 1 ? room - assigned : Math.floor((extras[i]! * room) / extraTotal)
|
|
116
197
|
const amount = Math.min(extras[i]!, Math.max(0, share))
|
|
117
|
-
widths[i] =
|
|
198
|
+
widths[i] = applied[i]! + amount
|
|
118
199
|
assigned += amount
|
|
119
200
|
}
|
|
120
201
|
return widths
|
|
@@ -160,17 +241,38 @@ function renderBorderedGrid(
|
|
|
160
241
|
h: "-",
|
|
161
242
|
v: "|",
|
|
162
243
|
}
|
|
244
|
+
// Guard terakhir: baris sel TIDAK BOLEH lebih lebar dari kolomnya. Dengan
|
|
245
|
+
// minimum wide-aware ini seharusnya tak terjadi, tapi invariant geometri
|
|
246
|
+
// (I1) terlalu mahal untuk ditebak — potong defensif tanpa ellipsis.
|
|
247
|
+
const fitCellLine = (line: string, colWidth: number): string =>
|
|
248
|
+
displayWidth(line) > colWidth ? truncateToWidth(line, colWidth, "") : line
|
|
249
|
+
// Sel yang seluruhnya satu token tanpa spasi (identifier, path, hash, URL
|
|
250
|
+
// pendek) tidak punya titik patah yang wajar untuk dibaca user.
|
|
251
|
+
const hasNoBreakOpportunity = (plain: string): boolean => !/[\s\-_/.]/.test(plain.trim())
|
|
163
252
|
const cellLines = (value: unknown, col: number): string[] => {
|
|
164
253
|
const colWidth = widths[col]!
|
|
165
254
|
const align = aligns[col] ?? "left"
|
|
166
255
|
const raw = cleanCell(value)
|
|
167
256
|
const rendered = options.formatCell?.(raw) ?? raw
|
|
168
|
-
|
|
257
|
+
// Token tanpa spasi (identifier/path/angka) TIDAK dipecah: bila ia tak
|
|
258
|
+
// muat, ia melimpah keluar kolom dengan `…` alih-alih pecah jadi
|
|
259
|
+
// `read_fi`/`le`. Bir-patah token bahkan lebih sulit dibaca daripada
|
|
260
|
+
// ellipsis, dan memilih minimum lebih besar per kolom tak menyelesaikan
|
|
261
|
+
// kasus ekstrem (lebar terminal tetap terbatas).
|
|
262
|
+
const chunks = wrapByWidth(rendered, colWidth)
|
|
263
|
+
const atomicOverflow =
|
|
264
|
+
chunks.length > 1 &&
|
|
265
|
+
hasNoBreakOpportunity(stripSgr(rendered)) &&
|
|
266
|
+
displayWidth(stripSgr(rendered)) > colWidth
|
|
267
|
+
const lines = atomicOverflow ? [rendered] : chunks
|
|
268
|
+
return lines.map((l) => alignCell(fitCellLine(l, colWidth), colWidth, align))
|
|
169
269
|
}
|
|
170
270
|
const headerCols = table.headers.map((v, i) => {
|
|
171
271
|
const rendered = options.formatCell?.(cleanCell(v)) ?? cleanCell(v)
|
|
172
272
|
const styled = styleHeader ? c.bold(c.accent(rendered)) : rendered
|
|
173
|
-
return wrapByWidth(styled, widths[i]!).map((l) =>
|
|
273
|
+
return wrapByWidth(styled, widths[i]!).map((l) =>
|
|
274
|
+
alignCell(fitCellLine(l, widths[i]!), widths[i]!, aligns[i] ?? "left"),
|
|
275
|
+
)
|
|
174
276
|
})
|
|
175
277
|
const rowLine = (cols: string[][], li: number): string =>
|
|
176
278
|
c.dim(g.v) +
|
|
@@ -216,11 +318,19 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
|
|
|
216
318
|
: table.headers.length * 3 - 1
|
|
217
319
|
const budget = width - overhead
|
|
218
320
|
const natural = naturalWidths(table, maxCellWidth)
|
|
219
|
-
const
|
|
321
|
+
const atomic = atomicMinimums(table, natural).map((m) =>
|
|
322
|
+
Math.max(m, Math.min(minCellWidth, ...natural.map((value) => Math.max(1, value)))),
|
|
323
|
+
)
|
|
324
|
+
// Tabel jawaban model boleh lebih "pintar" memilih minimum: kolom identifier
|
|
325
|
+
// tak boleh terbelah di tengah token hanya untuk memberi kolom prosa kolam
|
|
326
|
+
// yang sama. Tabel UI internal (config/sessions/skills) tetap memakai minimum
|
|
327
|
+
// atomik sempit — kolom pendeknya memang pendek.
|
|
328
|
+
const minimums = options.fairMinimums ? fairMinimums(table, natural) : atomic
|
|
220
329
|
const widths =
|
|
221
|
-
(width < 40 && table.headers.length > 3) ||
|
|
330
|
+
(width < 40 && table.headers.length > 3) ||
|
|
331
|
+
budget < minimums.reduce((sum, value) => sum + value, 0)
|
|
222
332
|
? null
|
|
223
|
-
: fitWidths(natural, budget,
|
|
333
|
+
: fitWidths(natural, budget, minimums)
|
|
224
334
|
if (!widths) return renderVertical(table, width, ellipsis).join("\n")
|
|
225
335
|
|
|
226
336
|
const aligns = table.aligns ?? table.headers.map(() => "left" as const)
|
|
@@ -298,7 +408,7 @@ export function renderMarkdownTable(
|
|
|
298
408
|
rows: table.rows,
|
|
299
409
|
aligns: table.aligns,
|
|
300
410
|
},
|
|
301
|
-
{ width, styleHeader: true, formatCell, box: true },
|
|
411
|
+
{ width, styleHeader: true, formatCell, box: true, fairMinimums: true },
|
|
302
412
|
)
|
|
303
413
|
}
|
|
304
414
|
|
package/src/ui/render/table.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from "../i18n/locale.ts"
|
|
1
2
|
import { sanitizeAnsiLine } from "./sanitize.ts"
|
|
2
3
|
import { renderGridTable } from "./table-grid.ts"
|
|
3
4
|
import { c, getTerminalWidth } from "./theme.ts"
|
|
@@ -18,8 +19,9 @@ function cleanCell(value: unknown): string {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export function renderTable(columns: ColumnDef[], data: Record<string, unknown>[]): string {
|
|
21
|
-
|
|
22
|
-
if (
|
|
22
|
+
// Status kosong juga user-visible → lewat t() (I26).
|
|
23
|
+
if (columns.length === 0) return c.muted(t("tbl.noColumns"))
|
|
24
|
+
if (data.length === 0) return c.muted(t("tbl.noEntries"))
|
|
23
25
|
const rows = data.map((row) => columns.map((column) => cleanCell(row[column.key])))
|
|
24
26
|
return renderGridTable(
|
|
25
27
|
{
|