minicode-ai 0.21.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/commands/exec.ts +44 -1
- package/cli/commands.ts +5 -2
- package/cli/setup.ts +24 -0
- package/docs/TERMINAL_CONTRACT.md +30 -7
- package/docs/architecture.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +2 -1
- package/docs/environment.md +1 -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/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/footer.ts +2 -2
- package/src/ui/i18n/en.ts +9 -1
- package/src/ui/i18n/id.ts +9 -1
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/diff.ts +51 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +6 -4
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +11 -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/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/tui/app.ts +57 -20
- package/src/ui/tui/transcript.ts +42 -7
- package/vendor/minicore/src/providers/openai-compat.ts +30 -1
|
@@ -8,6 +8,7 @@
|
|
|
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"
|
|
12
13
|
import { sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
13
14
|
import { c } from "./theme.ts"
|
|
@@ -36,7 +37,8 @@ export function formatDuration(ms: number): string {
|
|
|
36
37
|
|
|
37
38
|
/** Render kop: wordmark + detail sesi (baris demi baris). */
|
|
38
39
|
export function renderSessionSummary(s: SessionSummary): string {
|
|
39
|
-
|
|
40
|
+
// Parameter dinamai `text`, bukan `t`: `t` sudah dipakai untuk i18n.
|
|
41
|
+
const label = (text: string): string => c.muted(text.padEnd(7))
|
|
40
42
|
const cost = s.cost != null ? formatUsd(s.cost) : null
|
|
41
43
|
// sessionId/model = input tak-terpercaya (config/network): buang SEMUA ANSI
|
|
42
44
|
// (termasuk SGR) sebelum dibungkus style — nilai mentah hanya boleh muncul
|
|
@@ -44,9 +46,9 @@ export function renderSessionSummary(s: SessionSummary): string {
|
|
|
44
46
|
const clean = (v: string): string => stripSgr(sanitizeAnsiLine(v))
|
|
45
47
|
return `${[
|
|
46
48
|
paintWordmark(),
|
|
47
|
-
`${label("
|
|
48
|
-
`${label("
|
|
49
|
-
`${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")}${
|
|
50
52
|
cost != null ? ` · ${cost}` : ""
|
|
51
53
|
} · ${formatDuration(s.durationMs)}`,
|
|
52
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.
|
|
@@ -405,7 +405,15 @@ export const ESC = String.fromCharCode(27)
|
|
|
405
405
|
// hanya cocok untuk `ESC[P`/`ESC[_` dst. sehingga payload DCS bocor.
|
|
406
406
|
export const ANSI_PATTERN = `${ESC}(?:\\[[0-9;?<=>]*[@-~]|\\[[0-9;?<=>]*|\\][^${ESC}\\u0007]*(?:\\u0007|${ESC}\\\\)|(?:P|_|\\^|X)[^${ESC}\\u0007]*(?:\\u0007|${ESC}\\\\)|[()#][0-~]|[0-~])`
|
|
407
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
|
+
|
|
408
417
|
export function stripAnsi(str: string): string {
|
|
409
|
-
|
|
410
|
-
return str.replace(new RegExp(ANSI_PATTERN, "g"), "")
|
|
418
|
+
return str.replace(ANSI_STRIP, "")
|
|
411
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
|
}
|
|
@@ -15,10 +15,19 @@ import { truncateToWidth } from "../render/width.ts"
|
|
|
15
15
|
import { motionReduced } from "./motion.ts"
|
|
16
16
|
import { acquireTransientPaint, paintWrite } from "./statusline.ts"
|
|
17
17
|
|
|
18
|
-
// Jaga agar kursor terminal selalu ter-restore meski proses dihentikan
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
// Jaga agar kursor terminal selalu ter-restore meski proses dihentikan
|
|
19
|
+
// (SIGINT/dll). Hook didaftarkan LAZY saat bar benar-benar menyembunyikan
|
|
20
|
+
// kursor: hook di scope modul menulis `ESC[?25h` ke stderr pada SETIAP proses
|
|
21
|
+
// yang sekadar meng-import modul ini — byte asing yang mendarat di alt-screen
|
|
22
|
+
// TUI walau bar tak pernah dibuat (audit 2026-11-12).
|
|
23
|
+
let exitHookInstalled = false
|
|
24
|
+
function installExitHook(): void {
|
|
25
|
+
if (exitHookInstalled) return
|
|
26
|
+
exitHookInstalled = true
|
|
27
|
+
process.on("exit", () => {
|
|
28
|
+
if (process.stderr.isTTY) process.stderr.write("\x1b[?25h")
|
|
29
|
+
})
|
|
30
|
+
}
|
|
22
31
|
|
|
23
32
|
export interface LoadingBar {
|
|
24
33
|
/** Ganti label + persen (0..100). Tak pernah melampaui target yang diberikan. */
|
|
@@ -73,7 +82,10 @@ export function createLoadingBar(
|
|
|
73
82
|
started = true
|
|
74
83
|
// Sembunyikan kursor hanya saat animasi normal; mode gerak-dikurangi
|
|
75
84
|
// cukup melukis baris tanpa mengubah visibilitas kursor.
|
|
76
|
-
if (!reduced)
|
|
85
|
+
if (!reduced) {
|
|
86
|
+
installExitHook()
|
|
87
|
+
paintWrite("\x1b[?25l")
|
|
88
|
+
}
|
|
77
89
|
owned = acquireTransientPaint("loading-bar", paint)
|
|
78
90
|
paint()
|
|
79
91
|
}
|
package/src/ui/screens/dialog.ts
CHANGED
|
@@ -28,6 +28,13 @@ export interface DialogSpec {
|
|
|
28
28
|
minWidth?: number
|
|
29
29
|
/** Tinggi kotak maksimum (inklusif border). Default: setinggi layar. */
|
|
30
30
|
maxHeight?: number
|
|
31
|
+
/**
|
|
32
|
+
* Indeks body (0-based) yang WAJIB terlihat, mis. field aktif form. Bila
|
|
33
|
+
* body melebihi tinggi kotak, jendela digeser agar baris ini ikut tampil —
|
|
34
|
+
* tanpa ini user mengetik ke field yang tidak ada di layar (audit
|
|
35
|
+
* 2026-11-12, HIGH-2).
|
|
36
|
+
*/
|
|
37
|
+
focusRow?: number
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
interface BoxChars {
|
|
@@ -63,6 +70,11 @@ export interface DialogBox {
|
|
|
63
70
|
* (bug nyata di 4 view).
|
|
64
71
|
*/
|
|
65
72
|
bodyTop: number
|
|
73
|
+
/**
|
|
74
|
+
* Indeks body pertama yang benar-benar dirender (0 kecuali body digeser
|
|
75
|
+
* karena `focusRow`). Kursor = `bodyTop + (activeRow - bodyStart)`.
|
|
76
|
+
*/
|
|
77
|
+
bodyStart: number
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
/**
|
|
@@ -132,7 +144,16 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
132
144
|
const room = Math.max(0, boxBudget - chromeFixed)
|
|
133
145
|
const clipped = spec.body.length > room
|
|
134
146
|
const shown = clipped ? Math.max(0, room - 1) : spec.body.length
|
|
135
|
-
|
|
147
|
+
// Jendela body: default dari atas, tapi bila pemanggil menandai baris fokus
|
|
148
|
+
// (form: field aktif) jendela digeser agar baris itu terlihat. Tanpa ini
|
|
149
|
+
// `activeRow` menunjuk baris di luar yang dirender sehingga kursor parkir di
|
|
150
|
+
// marker/border dan ketikan user tak terlihat (audit 2026-11-12, HIGH-2).
|
|
151
|
+
const focus = spec.focusRow
|
|
152
|
+
const bodyStart =
|
|
153
|
+
clipped && focus != null && shown > 0 && Number.isFinite(focus)
|
|
154
|
+
? Math.max(0, Math.min(Math.floor(focus) - shown + 1, spec.body.length - shown))
|
|
155
|
+
: 0
|
|
156
|
+
const body = spec.body.slice(bodyStart, bodyStart + shown)
|
|
136
157
|
for (const ln of body) boxed.push(`${box.v} ${padToWidth(cut(ln), innerW)} ${box.v}`)
|
|
137
158
|
if (clipped)
|
|
138
159
|
boxed.push(
|
|
@@ -148,7 +169,7 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
148
169
|
const left = Math.max(0, Math.floor((c0 - displayWidth(ln)) / 2))
|
|
149
170
|
return `${" ".repeat(left)}${ln}`
|
|
150
171
|
})
|
|
151
|
-
return { lines, topRow, height: boxed.length, bodyTop: 1 + (hasTitle ? 1 : 0) }
|
|
172
|
+
return { lines, topRow, height: boxed.length, bodyTop: 1 + (hasTitle ? 1 : 0), bodyStart }
|
|
152
173
|
}
|
|
153
174
|
|
|
154
175
|
/**
|
package/src/ui/screens/form.ts
CHANGED
|
@@ -108,7 +108,10 @@ function toState(def: FormField): FieldState {
|
|
|
108
108
|
}
|
|
109
109
|
return {
|
|
110
110
|
def,
|
|
111
|
-
|
|
111
|
+
// Prefill berasal dari config/berkas (teks tak-terpercaya). Disanitasi di
|
|
112
|
+
// STATE, bukan saat render: kursor & viewStart dihitung dari `text`, jadi
|
|
113
|
+
// escape di dalamnya akan menggeser kolom kursor dari yang terlihat.
|
|
114
|
+
text: typeof def.initial === "string" ? sanitizeAnsiLine(def.initial) : "",
|
|
112
115
|
cursor: 0,
|
|
113
116
|
selectIdx: 0,
|
|
114
117
|
confirmed: false,
|
|
@@ -249,6 +252,9 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
249
252
|
// bernapas saat error muncul/hilang).
|
|
250
253
|
minWidth: FORM_BOX_W,
|
|
251
254
|
maxWidth: FORM_BOX_W,
|
|
255
|
+
// Field aktif WAJIB terlihat: dialog menggeser jendela body bila
|
|
256
|
+
// muat-tidaknya terpaksa memotong (audit 2026-11-12, HIGH-2).
|
|
257
|
+
focusRow: activeRow >= 0 ? activeRow : undefined,
|
|
252
258
|
},
|
|
253
259
|
screen.cols,
|
|
254
260
|
screen.rows,
|
|
@@ -260,7 +266,12 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
260
266
|
// dari lebar baris (yang sudah termasuk padding) terbukti off-by-N.
|
|
261
267
|
try {
|
|
262
268
|
if (activeRow >= 0) {
|
|
263
|
-
|
|
269
|
+
// bodyStart = offset jendela body yang benar-benar dirender; tanpa
|
|
270
|
+
// dikurangi, kursor mendarat di baris marker/border saat body dipotong.
|
|
271
|
+
const li = Math.max(
|
|
272
|
+
0,
|
|
273
|
+
Math.min(box.lines.length - 1, box.bodyTop + (activeRow - box.bodyStart)),
|
|
274
|
+
)
|
|
264
275
|
const row = box.topRow + li
|
|
265
276
|
const stripped = stripAnsi(box.lines[li] ?? "")
|
|
266
277
|
const leftPad = boxLeftPad(stripped)
|
|
@@ -352,25 +363,56 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
352
363
|
st.error = null
|
|
353
364
|
}
|
|
354
365
|
|
|
366
|
+
/**
|
|
367
|
+
* Esc tahap-1: kembalikan nilai bawaan field AKTIF, apa pun jenisnya.
|
|
368
|
+
*
|
|
369
|
+
* Kontrak I21 menyebut "semua input teks/pilihan", tapi dulu hanya
|
|
370
|
+
* text/secret yang di-revert — pada select/confirm Esc langsung menutup
|
|
371
|
+
* seluruh form dan perubahan field lain ikut hilang (audit 2026-11-12,
|
|
372
|
+
* MEDIUM-6). `false` = sudah di nilai bawaan → lanjut ke tahap-2 (batal).
|
|
373
|
+
*/
|
|
374
|
+
const revertField = (cur: FieldState): boolean => {
|
|
375
|
+
if (cur.def.kind === "select") {
|
|
376
|
+
const n = Math.max(1, cur.def.options?.length ?? 1)
|
|
377
|
+
const init = typeof cur.def.initial === "number" ? cur.def.initial : 0
|
|
378
|
+
const target = Math.min(Math.max(0, init), n - 1)
|
|
379
|
+
if (cur.selectIdx === target) return false
|
|
380
|
+
cur.selectIdx = target
|
|
381
|
+
cur.error = null
|
|
382
|
+
return true
|
|
383
|
+
}
|
|
384
|
+
if (cur.def.kind === "confirm") {
|
|
385
|
+
const target = typeof cur.def.initial === "boolean" ? cur.def.initial : false
|
|
386
|
+
if (cur.confirmed === target) return false
|
|
387
|
+
cur.confirmed = target
|
|
388
|
+
cur.error = null
|
|
389
|
+
return true
|
|
390
|
+
}
|
|
391
|
+
const initial = typeof cur.def.initial === "string" ? cur.def.initial : ""
|
|
392
|
+
if (cur.text === initial) return false
|
|
393
|
+
cur.text = initial
|
|
394
|
+
cur.cursor = toGraphemes(initial).length
|
|
395
|
+
cur.viewStart = 0
|
|
396
|
+
cur.error = null
|
|
397
|
+
return true
|
|
398
|
+
}
|
|
399
|
+
|
|
355
400
|
const handleKeys = (keys: DecodedKey[]): boolean => {
|
|
356
401
|
if (done) return true
|
|
357
402
|
resetIdle()
|
|
358
|
-
const st = fields[idx]!
|
|
359
403
|
for (const d of keys) {
|
|
360
404
|
const k = d.key
|
|
405
|
+
// Field STATE dibaca ulang tiap iterasi: Tab/↑/↓ di dalam chunk yang
|
|
406
|
+
// sama memindahkan `idx`, dan pointer yang dicapture sebelum loop
|
|
407
|
+
// membuat ketikan masuk ke field SEBELUMNYA (audit 2026-11-12, HIGH-1).
|
|
408
|
+
const st = fields[idx]!
|
|
361
409
|
// Esc/Ctrl+C dua-tahap (anti-hilang draft): field kotor → kembalikan
|
|
362
410
|
// ke nilai bawaan (prefill edit tak hilang sekali tekan — dulu
|
|
363
411
|
// langsung dikosongkan tanpa undo); sudah bawaan/kosong → batal
|
|
364
412
|
// total. Ctrl+D = batal langsung (konvensi EOF, tidak dipakai
|
|
365
413
|
// menghapus).
|
|
366
414
|
if (k.type === "esc" || k.type === "ctrl-c") {
|
|
367
|
-
|
|
368
|
-
const initial = typeof cur.def.initial === "string" ? cur.def.initial : ""
|
|
369
|
-
if ((cur.def.kind === "text" || cur.def.kind === "secret") && cur.text !== initial) {
|
|
370
|
-
cur.text = initial
|
|
371
|
-
cur.cursor = toGraphemes(initial).length
|
|
372
|
-
cur.viewStart = 0
|
|
373
|
-
cur.error = null
|
|
415
|
+
if (revertField(fields[idx]!)) {
|
|
374
416
|
render()
|
|
375
417
|
continue
|
|
376
418
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type DecoderState,
|
|
9
9
|
toGraphemes,
|
|
10
10
|
} from "../input/prompt-engine.ts"
|
|
11
|
-
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
11
|
+
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
12
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
13
13
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
14
14
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
@@ -575,7 +575,13 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
575
575
|
finish()
|
|
576
576
|
} catch {}
|
|
577
577
|
try {
|
|
578
|
-
|
|
578
|
+
// Pesan error bisa memuat body jaringan (tak-terpercaya): sanitasi
|
|
579
|
+
// sebelum ditulis ke stdout agar escape tak membersihkan layar.
|
|
580
|
+
console.log(
|
|
581
|
+
`⚠ ${t("model.failOpen", {
|
|
582
|
+
msg: cleanUntrusted(String((e as Error)?.message ?? e), !!process.stdout.isTTY),
|
|
583
|
+
})}`,
|
|
584
|
+
)
|
|
579
585
|
} catch {}
|
|
580
586
|
}
|
|
581
587
|
})
|
package/src/ui/screens/picker.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type DecoderState,
|
|
9
9
|
toGraphemes,
|
|
10
10
|
} from "../input/prompt-engine.ts"
|
|
11
|
-
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
11
|
+
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
12
|
import { c, stripAnsi } from "../render/theme.ts"
|
|
13
13
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
14
14
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
@@ -406,7 +406,11 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
406
406
|
cleanup()
|
|
407
407
|
} catch {}
|
|
408
408
|
try {
|
|
409
|
-
console.log(
|
|
409
|
+
console.log(
|
|
410
|
+
`⚠ ${t("pick.fail", {
|
|
411
|
+
msg: cleanUntrusted(String((e as Error)?.message ?? e), !!process.stdout.isTTY),
|
|
412
|
+
})}`,
|
|
413
|
+
)
|
|
410
414
|
} catch {}
|
|
411
415
|
try {
|
|
412
416
|
opts.onCancel()
|
|
@@ -434,7 +438,11 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
434
438
|
cleanup()
|
|
435
439
|
} catch {}
|
|
436
440
|
try {
|
|
437
|
-
console.log(
|
|
441
|
+
console.log(
|
|
442
|
+
`⚠ ${t("pick.failOpen", {
|
|
443
|
+
msg: cleanUntrusted(String((e as Error)?.message ?? e), !!process.stdout.isTTY),
|
|
444
|
+
})}`,
|
|
445
|
+
)
|
|
438
446
|
} catch {}
|
|
439
447
|
try {
|
|
440
448
|
opts.onCancel()
|