minicode-ai 0.20.0 → 0.22.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/auto-update.ts +24 -15
- package/cli/commands/exec.ts +44 -1
- package/cli/commands.ts +5 -2
- package/cli/index.ts +57 -18
- package/cli/setup.ts +88 -34
- package/cli/tui.ts +22 -2
- package/docs/TERMINAL_CONTRACT.md +50 -11
- package/docs/UI_RENDER_PIPELINE.md +6 -3
- package/docs/architecture.md +10 -6
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +4 -3
- package/docs/environment.md +2 -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/config.ts +8 -6
- package/src/daemon/discovery.ts +24 -0
- package/src/policy/bash-guard.ts +170 -6
- package/src/policy/compaction.ts +34 -7
- package/src/policy/jail.ts +10 -22
- package/src/policy/permission.ts +9 -6
- package/src/policy/update-check.ts +6 -4
- package/src/presentation/projection.ts +1 -1
- package/src/providers/anthropic.ts +14 -4
- package/src/providers/responses.ts +1 -1
- package/src/providers/sse-bounds.ts +16 -2
- package/src/ui/approval/prompt.ts +17 -6
- package/src/ui/assistant/simple.ts +14 -0
- package/src/ui/footer.ts +2 -2
- package/src/ui/i18n/en.ts +29 -1
- package/src/ui/i18n/id.ts +29 -1
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/activity-group.ts +53 -0
- package/src/ui/render/activity-panel.ts +91 -0
- package/src/ui/render/cells.ts +33 -6
- package/src/ui/render/diff.ts +58 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/markdown.ts +6 -1
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +11 -4
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +19 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +137 -0
- package/src/ui/screens/dialog.ts +23 -2
- package/src/ui/screens/form.ts +52 -10
- package/src/ui/screens/model-manager.ts +8 -2
- package/src/ui/screens/picker.ts +11 -3
- package/src/ui/screens/provider-manager.ts +11 -3
- package/src/ui/screens/wizard.ts +29 -1
- package/src/ui/session-state.ts +22 -0
- package/src/ui/tui/app.ts +57 -20
- package/src/ui/tui/transcript.ts +204 -27
- package/vendor/minicore/src/providers/openai-compat.ts +30 -1
|
@@ -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
|
|
|
@@ -25,7 +25,12 @@ export interface FenceMatch {
|
|
|
25
25
|
* sehingga fence berbahasa kehilangan highlight dan state desync.
|
|
26
26
|
*/
|
|
27
27
|
export function parseFence(line: string): FenceMatch | null {
|
|
28
|
-
|
|
28
|
+
// Info-string setelah bahasa diperbolehkan (````ts title="demo"` atau
|
|
29
|
+
// ` ```js #tag `). Hanya token pertama (non-spasi) yang dibaca sebagai
|
|
30
|
+
// bahasa — sisanya adalah metadata yang tak memengaruhi highlight. Regex
|
|
31
|
+
// lama menolak seluruh baris ber-info-string sehingga kode jatuh ke dekorasi
|
|
32
|
+
// inline (`const x = *a*` jadi `const x = a`).
|
|
33
|
+
const m = /^\s*(```+|~~~+)([A-Za-z0-9_+.-]*)(?:\s+[^\r\n]*)?\s*$/.exec(line)
|
|
29
34
|
if (!m) return null
|
|
30
35
|
return { char: m[1]![0]!, len: m[1]!.length, lang: m[2] ?? "" }
|
|
31
36
|
}
|
|
@@ -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,7 +8,9 @@
|
|
|
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"
|
|
11
12
|
import { formatUsd } from "./money.ts"
|
|
13
|
+
import { sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
12
14
|
import { c } from "./theme.ts"
|
|
13
15
|
|
|
14
16
|
const WORDMARK = "minicode"
|
|
@@ -35,13 +37,18 @@ export function formatDuration(ms: number): string {
|
|
|
35
37
|
|
|
36
38
|
/** Render kop: wordmark + detail sesi (baris demi baris). */
|
|
37
39
|
export function renderSessionSummary(s: SessionSummary): string {
|
|
38
|
-
|
|
40
|
+
// Parameter dinamai `text`, bukan `t`: `t` sudah dipakai untuk i18n.
|
|
41
|
+
const label = (text: string): string => c.muted(text.padEnd(7))
|
|
39
42
|
const cost = s.cost != null ? formatUsd(s.cost) : null
|
|
43
|
+
// sessionId/model = input tak-terpercaya (config/network): buang SEMUA ANSI
|
|
44
|
+
// (termasuk SGR) sebelum dibungkus style — nilai mentah hanya boleh muncul
|
|
45
|
+
// sebagai teks polos, styling ditambahkan pemanggil (aturan repo).
|
|
46
|
+
const clean = (v: string): string => stripSgr(sanitizeAnsiLine(v))
|
|
40
47
|
return `${[
|
|
41
48
|
paintWordmark(),
|
|
42
|
-
`${label("
|
|
43
|
-
`${label("
|
|
44
|
-
`${label("
|
|
49
|
+
`${label(t("summary.session"))} ${c.gray(clean(s.sessionId))}`,
|
|
50
|
+
`${label(t("summary.model"))} ${c.gray(clean(s.model))}`,
|
|
51
|
+
`${label(t("summary.usage"))} ${s.totalTokens.toLocaleString()} ${t("summary.tokens")}${
|
|
45
52
|
cost != null ? ` · ${cost}` : ""
|
|
46
53
|
} · ${formatDuration(s.durationMs)}`,
|
|
47
54
|
]
|
|
@@ -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
|
{
|
package/src/ui/render/theme.ts
CHANGED
|
@@ -92,7 +92,7 @@ const TOKENS = {
|
|
|
92
92
|
error: "38;2;244;135;113",
|
|
93
93
|
warning: "38;2;204;167;0",
|
|
94
94
|
info: "38;2;117;190;255",
|
|
95
|
-
accent: "38;2;
|
|
95
|
+
accent: "38;2;74;144;226",
|
|
96
96
|
// String literal kode (VS Code Dark+ `string` #CE9178) — sengaja terpisah dari
|
|
97
97
|
// `success` (green): string harus tampak jingga-salm ala VS Code, sementara
|
|
98
98
|
// status sukses tetap hijau. Alias lama `green` tetap menyasar success.
|
|
@@ -345,6 +345,14 @@ export const glyphs = {
|
|
|
345
345
|
get spinnerFrames() {
|
|
346
346
|
return supportsUtf8() ? ["·", "··", "···"] : [".", "..", "..."]
|
|
347
347
|
},
|
|
348
|
+
// Blok progress bar loading (baris tunggal). Fallback ASCII untuk terminal
|
|
349
|
+
// tanpa UTF-8 (MINICODE_ASCII / konsol Windows legacy).
|
|
350
|
+
get blockFilled() {
|
|
351
|
+
return supportsUtf8() ? "▓" : "#"
|
|
352
|
+
},
|
|
353
|
+
get blockEmpty() {
|
|
354
|
+
return supportsUtf8() ? "░" : "-"
|
|
355
|
+
},
|
|
348
356
|
get thinkingIcon() {
|
|
349
357
|
// Sparkle ✦ (bintang) — indikator thinking yang "kelip-kelip": glyph
|
|
350
358
|
// monokrom, jadi warna ANSI (putih ↔ abu di turn-status) terlihat.
|
|
@@ -397,7 +405,15 @@ export const ESC = String.fromCharCode(27)
|
|
|
397
405
|
// hanya cocok untuk `ESC[P`/`ESC[_` dst. sehingga payload DCS bocor.
|
|
398
406
|
export const ANSI_PATTERN = `${ESC}(?:\\[[0-9;?<=>]*[@-~]|\\[[0-9;?<=>]*|\\][^${ESC}\\u0007]*(?:\\u0007|${ESC}\\\\)|(?:P|_|\\^|X)[^${ESC}\\u0007]*(?:\\u0007|${ESC}\\\\)|[()#][0-~]|[0-~])`
|
|
399
407
|
|
|
408
|
+
/** Regex bersama untuk stripAnsi.
|
|
409
|
+
*
|
|
410
|
+
* Dulu `new RegExp(...)` dibuat tiap panggilan — meski hasilnya benar (lastIndex
|
|
411
|
+
* `replace` selalu di-reset), ini hot path yang dipanggil per baris. Regex
|
|
412
|
+
* global dicomile sekali; `String.replace` dengan flag `g` mereset `lastIndex`
|
|
413
|
+
* sendiri sehingga aman dipakai bersama antar pemanggil (audit 2026-11-12).
|
|
414
|
+
*/
|
|
415
|
+
const ANSI_STRIP = new RegExp(ANSI_PATTERN, "g")
|
|
416
|
+
|
|
400
417
|
export function stripAnsi(str: string): string {
|
|
401
|
-
|
|
402
|
-
return str.replace(new RegExp(ANSI_PATTERN, "g"), "")
|
|
418
|
+
return str.replace(ANSI_STRIP, "")
|
|
403
419
|
}
|
package/src/ui/render/width.ts
CHANGED
|
@@ -186,7 +186,16 @@ function isSgrSeq(seq: string): boolean {
|
|
|
186
186
|
return params.split(/[:;]/).every((p) => p === "" || /^[0-9]+$/.test(p))
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* True bila string berakhir dengan gaya SGR masih terbuka (butuh reset).
|
|
191
|
+
*
|
|
192
|
+
* Parameter diproses BERURUTAN, bukan "ada OFF di mana pun": `\x1b[0;31m`
|
|
193
|
+
* berarti reset lalu merah (= masih terbuka), sedangkan `some(SGR_OFF)` lama
|
|
194
|
+
* menyimpulkan tertutup dan tak menambahkan reset → warna bocor ke sisa baris
|
|
195
|
+
* (audit 2026-11-12, HIGH-7). Parameter extended color (`38;2;r;g;b`,
|
|
196
|
+
* `38;5;n`) juga dikonsumsi sebagai satu atribut: komponen warnanya bisa
|
|
197
|
+
* bernilai 0 dan tidak boleh disalahartikan sebagai reset.
|
|
198
|
+
*/
|
|
190
199
|
function sgrLeftOpen(s: string): boolean {
|
|
191
200
|
let open = false
|
|
192
201
|
let i = 0
|
|
@@ -195,11 +204,7 @@ function sgrLeftOpen(s: string): boolean {
|
|
|
195
204
|
const len = escapeLength(s, i)
|
|
196
205
|
if (len > 0) {
|
|
197
206
|
const seq = s.slice(i, i + len)
|
|
198
|
-
if (isSgrSeq(seq))
|
|
199
|
-
const params = seq.slice(2, -1).split(/[:;]/)
|
|
200
|
-
if (params.some((p) => SGR_OFF.has(p) || p === "")) open = false
|
|
201
|
-
else if (params.some((p) => p !== "")) open = true
|
|
202
|
-
}
|
|
207
|
+
if (isSgrSeq(seq)) open = sgrParamsEndOpen(seq.slice(2, -1).split(/[:;]/), open)
|
|
203
208
|
i += len
|
|
204
209
|
continue
|
|
205
210
|
}
|
|
@@ -209,6 +214,30 @@ function sgrLeftOpen(s: string): boolean {
|
|
|
209
214
|
}
|
|
210
215
|
return open
|
|
211
216
|
}
|
|
217
|
+
|
|
218
|
+
/** State "masih terbuka" setelah satu sekuens SGR, mengikuti urutan parameter. */
|
|
219
|
+
function sgrParamsEndOpen(params: string[], open: boolean): boolean {
|
|
220
|
+
let state = open
|
|
221
|
+
for (let i = 0; i < params.length; i++) {
|
|
222
|
+
const p = params[i]!
|
|
223
|
+
if (p === "" || p === "0") {
|
|
224
|
+
state = false
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
// Extended color: 38/48/58 diikuti 5;n atau 2;r;g;b — satu atribut utuh.
|
|
228
|
+
if (p === "38" || p === "48" || p === "58") {
|
|
229
|
+
const mode = params[i + 1]
|
|
230
|
+
i += mode === "5" ? 2 : mode === "2" ? 4 : 1
|
|
231
|
+
state = true
|
|
232
|
+
continue
|
|
233
|
+
}
|
|
234
|
+
// OFF hanya menutup satu atribut; atribut lain bisa tetap aktif, jadi
|
|
235
|
+
// status dibiarkan (arah aman: reset ekstra tak berbahaya).
|
|
236
|
+
if (SGR_OFF.has(p)) continue
|
|
237
|
+
state = true
|
|
238
|
+
}
|
|
239
|
+
return state
|
|
240
|
+
}
|
|
212
241
|
/** Panjang sekuens escape yang mulai di `i`, atau 0 bila bukan escape. */
|
|
213
242
|
export function escapeLength(s: string, i: number): number {
|
|
214
243
|
if (s[i] !== "\x1b") return 0
|
package/src/ui/render/wrap.ts
CHANGED
|
@@ -48,24 +48,46 @@ export function wordWrap(text: string, width: number): string {
|
|
|
48
48
|
for (const tok of line.split(/(\s+)/)) {
|
|
49
49
|
if (tok === "") continue
|
|
50
50
|
if (/^\s+$/.test(tok)) {
|
|
51
|
-
|
|
51
|
+
// Run whitespace di AWAL baris = indentasi, bukan pemisah: ia harus
|
|
52
|
+
// ikut baris pertama. Dulu run ini dibuang saat `current` masih kosong
|
|
53
|
+
// sehingga indentasi & marker list panjang hilang di jalur linear
|
|
54
|
+
// (audit 2026-11-12, HIGH-6).
|
|
55
|
+
current += tok
|
|
52
56
|
continue
|
|
53
57
|
}
|
|
54
58
|
const word = tok
|
|
55
59
|
// Kata tunggal lebih lebar dari baris: pecah paksa per kolom.
|
|
56
60
|
if (displayWidth(word) > width) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
// Indentasi (bila ada) menempel ke potongan PERTAMA dan menyusutkan
|
|
62
|
+
// lebar potongan itu — tanpa ini indentasi hilang atau baris meluap.
|
|
63
|
+
const lead = current.trim() === "" ? current : ""
|
|
64
|
+
// Teks yang sudah terkumpul (bila ada) ditutup dulu; hanya indentasi
|
|
65
|
+
// murni yang ikut menempel ke potongan pertama.
|
|
66
|
+
if (current.trim() !== "") out.push(current.trimEnd())
|
|
67
|
+
current = ""
|
|
68
|
+
const avail = Math.max(1, width - displayWidth(lead))
|
|
69
|
+
const pieces = chunkByWidth(word, avail)
|
|
70
|
+
if (lead && pieces.length > 0) {
|
|
71
|
+
out.push(lead + (pieces[0] ?? ""))
|
|
72
|
+
for (let i = 1; i < pieces.length - 1; i++) out.push(pieces[i]!)
|
|
73
|
+
current = pieces[pieces.length - 1] ?? ""
|
|
74
|
+
if (pieces.length === 1) current = ""
|
|
75
|
+
} else {
|
|
76
|
+
for (let i = 0; i < pieces.length - 1; i++) out.push(pieces[i]!)
|
|
77
|
+
current = pieces[pieces.length - 1] ?? ""
|
|
78
|
+
}
|
|
61
79
|
continue
|
|
62
80
|
}
|
|
63
81
|
// `current` sudah memuat run whitespace aslinya; tambah satu spasi
|
|
64
82
|
// hanya bila tidak ada pemisah di antara dua kata.
|
|
65
83
|
const glued = !current || /\s$/.test(current) ? `${current}${word}` : `${current} ${word}`
|
|
66
|
-
if (displayWidth(glued) > width && current) {
|
|
84
|
+
if (displayWidth(glued) > width && current.trim() !== "") {
|
|
67
85
|
out.push(current.trimEnd())
|
|
68
86
|
current = word
|
|
87
|
+
} else if (displayWidth(glued) > width) {
|
|
88
|
+
// Indentasi + kata tak muat bersama: indentasi dilepas untuk baris ini
|
|
89
|
+
// (baris tetap <= width; lebih baik daripada meluap/memecah kata).
|
|
90
|
+
current = word
|
|
69
91
|
} else {
|
|
70
92
|
current = glued
|
|
71
93
|
}
|