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
|
@@ -99,16 +99,29 @@ export function boundedSseBody(
|
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/** Body error dibaca secukupnya untuk kategori/pesan, lalu sisa stream dibuang.
|
|
103
|
-
|
|
102
|
+
/** Body error dibaca secukupnya untuk kategori/pesan, lalu sisa stream dibuang.
|
|
103
|
+
* `signal` membuat pembacaan abort-aware: server yang mengembalikan status error
|
|
104
|
+
* lalu menstall body-nya tidak boleh menggantung reader selamanya — cancel reader
|
|
105
|
+
* saat abort sehingga jalur error tetap terbatas waktu. */
|
|
106
|
+
export async function readProviderErrorBody(
|
|
107
|
+
response: Response,
|
|
108
|
+
signal?: AbortSignal,
|
|
109
|
+
): Promise<string> {
|
|
104
110
|
if (!response.body) return ""
|
|
111
|
+
if (signal?.aborted) return ""
|
|
105
112
|
const reader = response.body.getReader()
|
|
106
113
|
const chunks: Uint8Array[] = []
|
|
107
114
|
let size = 0
|
|
108
115
|
let reachedEof = false
|
|
116
|
+
const onAbort = () => {
|
|
117
|
+
void reader.cancel(signal?.reason).catch(() => {})
|
|
118
|
+
}
|
|
119
|
+
signal?.addEventListener("abort", onAbort, { once: true })
|
|
109
120
|
try {
|
|
110
121
|
while (size < LIMITS.PROVIDER_ERROR_BODY_MAX_BYTES) {
|
|
122
|
+
if (signal?.aborted) break
|
|
111
123
|
const { done, value } = await reader.read()
|
|
124
|
+
if (signal?.aborted) break
|
|
112
125
|
if (done) {
|
|
113
126
|
reachedEof = true
|
|
114
127
|
break
|
|
@@ -121,6 +134,7 @@ export async function readProviderErrorBody(response: Response): Promise<string>
|
|
|
121
134
|
}
|
|
122
135
|
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString("utf8")
|
|
123
136
|
} finally {
|
|
137
|
+
signal?.removeEventListener("abort", onAbort)
|
|
124
138
|
if (!reachedEof) await reader.cancel().catch(() => {})
|
|
125
139
|
reader.releaseLock()
|
|
126
140
|
}
|
|
@@ -13,6 +13,7 @@ import { t } from "../i18n/locale.ts"
|
|
|
13
13
|
import { askLine } from "../input/input.ts"
|
|
14
14
|
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
15
15
|
import { c } from "../render/theme.ts"
|
|
16
|
+
import { truncateToWidth } from "../render/width.ts"
|
|
16
17
|
import { getApprovalSink } from "../tui/transcript.ts"
|
|
17
18
|
|
|
18
19
|
/** Subset struktural tool call yang dibutuhkan view — tanpa tipe kernel. */
|
|
@@ -73,10 +74,16 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
|
|
|
73
74
|
const toolName = sanitizeAnsiLine(call.name)
|
|
74
75
|
const args = (call.args ?? {}) as Record<string, unknown>
|
|
75
76
|
|
|
77
|
+
// Sanitasi DULU, potong SESUDAH: `slice` mentah bisa membelah surrogate
|
|
78
|
+
// pair (byte U+FFFD di layar) dan memotong sekuens ANSI di tengah sehingga
|
|
79
|
+
// ekor `\x1b[` menggantung (terminal menelan output berikutnya sebagai
|
|
80
|
+
// parameter CSI) — audit 2026-11-12, MEDIUM-1.
|
|
81
|
+
const summarize = (value: unknown, max: number): string =>
|
|
82
|
+
truncateToWidth(sanitizeAnsiLine(String(value)), max, "…")
|
|
76
83
|
let actionSummary = ""
|
|
77
|
-
if (args.command) actionSummary = `${t("appr.cmdLabel")} ${
|
|
78
|
-
else if (args.path) actionSummary = `${t("appr.fileLabel")} ${
|
|
79
|
-
else if (args.query) actionSummary = `${t("appr.queryLabel")} ${
|
|
84
|
+
if (args.command) actionSummary = `${t("appr.cmdLabel")} ${summarize(args.command, 100)}`
|
|
85
|
+
else if (args.path) actionSummary = `${t("appr.fileLabel")} ${summarize(args.path, 100)}`
|
|
86
|
+
else if (args.query) actionSummary = `${t("appr.queryLabel")} ${summarize(args.query, 100)}`
|
|
80
87
|
else {
|
|
81
88
|
let json = ""
|
|
82
89
|
try {
|
|
@@ -84,7 +91,7 @@ export async function promptAsk(call: ApprovalRequest): Promise<"allow" | "deny"
|
|
|
84
91
|
} catch {
|
|
85
92
|
json = String(args)
|
|
86
93
|
}
|
|
87
|
-
actionSummary = `${t("appr.argsLabel")} ${json
|
|
94
|
+
actionSummary = `${t("appr.argsLabel")} ${summarize(json, 100)}`
|
|
88
95
|
}
|
|
89
96
|
actionSummary = sanitizeAnsiLine(actionSummary)
|
|
90
97
|
|
|
@@ -162,7 +169,9 @@ export async function promptAskText(question: string, options?: string[]): Promi
|
|
|
162
169
|
// Paritas promptAsk: tanpa sink + stdout pipe = jawab tak terlihat & pipe
|
|
163
170
|
// tercemar → batal fail-closed.
|
|
164
171
|
if (!textSink && !process.stdout.isTTY) return null
|
|
165
|
-
|
|
172
|
+
// Potong SESUDAH sanitasi lewat truncateToWidth (bukan `slice`): `slice`
|
|
173
|
+
// bisa menyisakan `\x1b[` menggantung di ekor potongan.
|
|
174
|
+
const q = truncateToWidth(sanitizeAnsiLine(question), 2000, "…")
|
|
166
175
|
const block = [
|
|
167
176
|
``,
|
|
168
177
|
`${c.warning(c.bold(t("appr.askTitle")))}`,
|
|
@@ -188,7 +197,9 @@ export async function promptAskText(question: string, options?: string[]): Promi
|
|
|
188
197
|
if (ans == null || !ans.trim()) return null
|
|
189
198
|
const out = ans.trim()
|
|
190
199
|
if (sink) {
|
|
191
|
-
|
|
200
|
+
// Gema jawaban juga dipotong lewat truncateToWidth: `slice` bisa membelah
|
|
201
|
+
// surrogate pair (emoji → U+FFFD) atau menyisakan escape menggantung.
|
|
202
|
+
sink.pushBlock([c.muted(` → ${truncateToWidth(sanitizeAnsiLine(out), 200, "…")}`)])
|
|
192
203
|
sink.repaint()
|
|
193
204
|
}
|
|
194
205
|
return out
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
UiStep,
|
|
13
13
|
} from "../contract.ts"
|
|
14
14
|
import { t } from "../i18n/locale.ts"
|
|
15
|
+
import { renderActivityPanel } from "../render/activity-panel.ts"
|
|
15
16
|
import { renderDiffCard } from "../render/diff.ts"
|
|
16
17
|
import { formatArgsPreview, formatProviderError, formatUsage } from "../render/format.ts"
|
|
17
18
|
import { highlightCode } from "../render/highlight.ts"
|
|
@@ -605,6 +606,19 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
605
606
|
bashSan.flush()
|
|
606
607
|
flushThinking()
|
|
607
608
|
finalizeAnswer()
|
|
609
|
+
// [Fase 2] Panel aktivitas di jalur linear: satu blok ringkas per
|
|
610
|
+
// keluarga tool saat turn selesai (append-only — detail per-tool tetap
|
|
611
|
+
// lewat /expand). Opt-in via MINICODE_ACTIVITY_PANEL=1 / ui.activityPanel.
|
|
612
|
+
if (ui.activityPanel && opts.getSnapshot) {
|
|
613
|
+
const snap = presentationSnapshot()
|
|
614
|
+
if (snap) {
|
|
615
|
+
const lines = renderActivityPanel(snap.activities, { maxRows: 10 })
|
|
616
|
+
if (lines.length > 0) {
|
|
617
|
+
wErr(c.muted(`${t("panel.header")}\n`))
|
|
618
|
+
for (const line of lines) wErr(c.muted(`${line}\n`))
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
608
622
|
if (opts.verbose) wErr(c.muted(t("one.done")))
|
|
609
623
|
}),
|
|
610
624
|
)
|
package/src/ui/footer.ts
CHANGED
|
@@ -108,7 +108,7 @@ export function paintPermissionMode(mode: string, style: ModeLabelStyle = "full"
|
|
|
108
108
|
* jadi dirender jelas (bukan redup). */
|
|
109
109
|
export function paintBashStrict(strictBash?: boolean, unrestricted = false): string {
|
|
110
110
|
if (unrestricted) return c.info(glyphs.unlock)
|
|
111
|
-
return strictBash ? c.yellow(glyphs.lock) : c.
|
|
111
|
+
return strictBash ? c.yellow(glyphs.lock) : c.gray(glyphs.lock)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/** Spark glyph: redup saat idle, pulse putih↔abu saat busy (frame genap/ganjil). */
|
|
@@ -119,7 +119,7 @@ function sparkGlyph(frame: number): string {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function paintTimer(text: string, active: boolean, highlight: TimerHighlight = "seconds"): string {
|
|
122
|
-
if (!active) return c.
|
|
122
|
+
if (!active) return c.gray(text)
|
|
123
123
|
const parts = text.split(".")
|
|
124
124
|
if (parts.length !== 3) return c.white(text)
|
|
125
125
|
const rank: Record<TimerHighlight, number> = { seconds: 1, minutes: 2, hours: 3 }
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -312,11 +312,39 @@ export const en = {
|
|
|
312
312
|
"err.timeout": "Run exceeded timeout",
|
|
313
313
|
"err.timeoutFix": "Increase --timeout or use a faster model.",
|
|
314
314
|
"err.steps": "Tool step limit reached",
|
|
315
|
-
"err.stepsFix": "
|
|
315
|
+
"err.stepsFix": "Progress is saved — run /resume to continue, or raise --max-steps.",
|
|
316
316
|
"err.budget": "Session budget exceeded",
|
|
317
317
|
"err.budgetFix": "Start a new session or increase --budget.",
|
|
318
318
|
"err.busy": "A run is still in progress",
|
|
319
319
|
"err.busyFix": "Wait for the current run to finish.",
|
|
320
320
|
"err.aborted": "Run was aborted",
|
|
321
321
|
"common.active": "active",
|
|
322
|
+
"panel.group.explore": "explore",
|
|
323
|
+
"panel.group.edit": "edit",
|
|
324
|
+
"panel.group.execute": "execute",
|
|
325
|
+
"panel.group.feed": "feed",
|
|
326
|
+
"panel.group.other": "other",
|
|
327
|
+
"panel.tools": "{n} tools",
|
|
328
|
+
"panel.ok": "{n} ok",
|
|
329
|
+
"panel.failed": "{n} failed",
|
|
330
|
+
"panel.running": "{n} running",
|
|
331
|
+
"panel.thinking": "thinking",
|
|
332
|
+
"panel.lines": "{n} lines",
|
|
333
|
+
"panel.moreLines": "… {n} more lines",
|
|
334
|
+
"panel.header": "activity",
|
|
335
|
+
"loading.checking": "checking for updates",
|
|
336
|
+
"loading.installing": "installing update",
|
|
337
|
+
"loading.restarting": "restarting",
|
|
338
|
+
"loading.provider": "configuring provider",
|
|
339
|
+
"loading.rag": "loading context",
|
|
340
|
+
"loading.session": "preparing session",
|
|
341
|
+
"loading.finalize": "finalizing",
|
|
342
|
+
"diff.noChanges": "(no changes)",
|
|
343
|
+
"diff.truncated": "… diff truncated — input too large",
|
|
344
|
+
"tbl.noColumns": "(no columns)",
|
|
345
|
+
"tbl.noEntries": "(no entries)",
|
|
346
|
+
"summary.session": "Session",
|
|
347
|
+
"summary.model": "Model",
|
|
348
|
+
"summary.usage": "Usage",
|
|
349
|
+
"summary.tokens": "tokens",
|
|
322
350
|
} as const
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -314,11 +314,39 @@ export const id: Record<MsgKey, string> = {
|
|
|
314
314
|
"err.timeout": "Run melewati batas waktu",
|
|
315
315
|
"err.timeoutFix": "Naikkan --timeout atau pakai model lebih cepat.",
|
|
316
316
|
"err.steps": "Batas langkah tool tercapai",
|
|
317
|
-
"err.stepsFix": "
|
|
317
|
+
"err.stepsFix": "Progres sudah tersimpan — lanjutkan via /resume, atau naikkan --max-steps.",
|
|
318
318
|
"err.budget": "Budget sesi terlampaui",
|
|
319
319
|
"err.budgetFix": "Mulai sesi baru atau naikkan --budget.",
|
|
320
320
|
"err.busy": "Run masih berjalan",
|
|
321
321
|
"err.busyFix": "Tunggu run berjalan selesai.",
|
|
322
322
|
"err.aborted": "Run dibatalkan",
|
|
323
323
|
"common.active": "aktif",
|
|
324
|
+
"panel.group.explore": "jelajah",
|
|
325
|
+
"panel.group.edit": "ubah",
|
|
326
|
+
"panel.group.execute": "jalankan",
|
|
327
|
+
"panel.group.feed": "sumber",
|
|
328
|
+
"panel.group.other": "lainnya",
|
|
329
|
+
"panel.tools": "{n} tool",
|
|
330
|
+
"panel.ok": "{n} sukses",
|
|
331
|
+
"panel.failed": "{n} gagal",
|
|
332
|
+
"panel.running": "{n} berjalan",
|
|
333
|
+
"panel.thinking": "berpikir",
|
|
334
|
+
"panel.lines": "{n} baris",
|
|
335
|
+
"panel.moreLines": "… {n} baris lagi",
|
|
336
|
+
"panel.header": "aktivitas",
|
|
337
|
+
"loading.checking": "memeriksa pembaruan",
|
|
338
|
+
"loading.installing": "memasang pembaruan",
|
|
339
|
+
"loading.restarting": "memulai ulang",
|
|
340
|
+
"loading.provider": "menyiapkan provider",
|
|
341
|
+
"loading.rag": "memuat konteks",
|
|
342
|
+
"loading.session": "menyiapkan sesi",
|
|
343
|
+
"loading.finalize": "menyelesaikan",
|
|
344
|
+
"diff.noChanges": "(tidak ada perubahan)",
|
|
345
|
+
"diff.truncated": "… diff dipotong — input terlalu besar",
|
|
346
|
+
"tbl.noColumns": "(tanpa kolom)",
|
|
347
|
+
"tbl.noEntries": "(tanpa entri)",
|
|
348
|
+
"summary.session": "Sesi",
|
|
349
|
+
"summary.model": "Model",
|
|
350
|
+
"summary.usage": "Pemakaian",
|
|
351
|
+
"summary.tokens": "token",
|
|
324
352
|
}
|
|
@@ -232,6 +232,12 @@ export function applyKey(
|
|
|
232
232
|
.replace(/\t/g, " ")
|
|
233
233
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: membuang byte kontrol dari paste
|
|
234
234
|
.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")
|
|
235
|
+
// C1 (0x80–0x9F) juga dibuang: U+009B bertindak sebagai CSI di banyak
|
|
236
|
+
// terminal, jadi paste bisa menyuntik escape TANPA byte ESC — melewati
|
|
237
|
+
// filter di atas dan gate sanitize (buffer composer dilukis apa adanya).
|
|
238
|
+
.replace(/[\u0080-\u009f]/g, "")
|
|
239
|
+
// Separator garis/paragraf Unicode = pindah baris di sebagian terminal.
|
|
240
|
+
.replace(/[\u2028\u2029]/g, "\n")
|
|
235
241
|
if (!ins) return { state, action: "none" }
|
|
236
242
|
const { line, cursor } = insertAt(state.line, state.cursor, ins)
|
|
237
243
|
return { state: withLine(line, cursor), action: "render" }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Klasifikasi tool → keluarga panel aktivitas (Fase 2). Murni & tanpa IO:
|
|
2
|
+
// hanya memetakan nama tool ke label keluarga (group) yang dipakai panel
|
|
3
|
+
// TUI (transcript.ts) dan blok ringkas linear (simple.ts). Satu sumber
|
|
4
|
+
// kebenaran supaya kedua renderer tidak divergen.
|
|
5
|
+
//
|
|
6
|
+
// Keluarga disandikan sebagai kunci i18n (`panel.group.*`) — modul ini tidak
|
|
7
|
+
// menyentuh teks render, hanya kunci. Fallback: tool yang tak dikenal tetap
|
|
8
|
+
// tampil dengan nama aslinya (tanpa dikelompokkan).
|
|
9
|
+
|
|
10
|
+
export type ActivityGroupKind = "explore" | "edit" | "execute" | "feed" | "other"
|
|
11
|
+
|
|
12
|
+
/** Peta nama tool → keluarga. Kunci nama tool (input tak-terpercaya) — renderer
|
|
13
|
+
* tetap wajib sanitasi sebelum tampil (aturan repo). */
|
|
14
|
+
const GROUP_BY_TOOL: Readonly<Record<string, ActivityGroupKind>> = {
|
|
15
|
+
// ── explore: membaca workspace / mencari informasi ──
|
|
16
|
+
read_file: "explore",
|
|
17
|
+
read_image: "explore",
|
|
18
|
+
glob: "explore",
|
|
19
|
+
grep: "explore",
|
|
20
|
+
lsp_diagnostics: "explore",
|
|
21
|
+
lsp_symbols: "explore",
|
|
22
|
+
lsp_workspace_symbols: "explore",
|
|
23
|
+
// ── edit: mengubah file / working tree ──
|
|
24
|
+
edit: "edit",
|
|
25
|
+
apply_patch: "edit",
|
|
26
|
+
write_file: "edit",
|
|
27
|
+
delete_file: "edit",
|
|
28
|
+
move_file: "edit",
|
|
29
|
+
// ── execute: menjalankan proses / perintah ──
|
|
30
|
+
bash: "execute",
|
|
31
|
+
code_run: "execute",
|
|
32
|
+
git_status: "execute",
|
|
33
|
+
git_diff: "execute",
|
|
34
|
+
git_log: "execute",
|
|
35
|
+
git_commit: "execute",
|
|
36
|
+
mcp_list: "execute",
|
|
37
|
+
mcp_call: "execute",
|
|
38
|
+
mcp_read: "execute",
|
|
39
|
+
mcp_prompt: "execute",
|
|
40
|
+
ask_user: "execute",
|
|
41
|
+
// ── feed: sumber informasi eksternal / memori ──
|
|
42
|
+
web_search: "feed",
|
|
43
|
+
web_fetch: "feed",
|
|
44
|
+
read_memory: "feed",
|
|
45
|
+
write_memory: "feed",
|
|
46
|
+
forget_memory: "feed",
|
|
47
|
+
delegate_task: "feed",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Keluarga tool (kunci i18n). Kunci `other` untuk yang tak dikenal. */
|
|
51
|
+
export function activityGroup(name: string): ActivityGroupKind {
|
|
52
|
+
return GROUP_BY_TOOL[name] ?? "other"
|
|
53
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Render panel aktivitas (Fase 2): satu baris per KELUARGA tool + state
|
|
2
|
+
// thinking. Murni (input → string[]), tanpa IO — pemanggil (transcript TUI /
|
|
3
|
+
// simple linear) yang memutuskan kapan & di mana mencetaknya.
|
|
4
|
+
//
|
|
5
|
+
// Semua teks yang datang dari model/tool (nama tool, target) adalah input
|
|
6
|
+
// tak-terpercaya: wajib sanitasi di sini sebelum dirender. Label keluarga
|
|
7
|
+
// berasal dari i18n (terpercaya).
|
|
8
|
+
|
|
9
|
+
import type { UiPresentationActivity } from "../contract.ts"
|
|
10
|
+
import { t } from "../i18n/locale.ts"
|
|
11
|
+
import { activityGroup } from "./activity-group.ts"
|
|
12
|
+
import { sanitizeAnsiLine, stripSgr } from "./sanitize.ts"
|
|
13
|
+
import { truncateToWidth } from "./width.ts"
|
|
14
|
+
/** Satu grup teragregasi (dipakai renderer + /expand buffer). */
|
|
15
|
+
export interface ActivityGroupView {
|
|
16
|
+
kind: string
|
|
17
|
+
/** Jumlah tool dalam grup. */
|
|
18
|
+
count: number
|
|
19
|
+
ok: number
|
|
20
|
+
failed: number
|
|
21
|
+
running: number
|
|
22
|
+
denied: number
|
|
23
|
+
/** Nama tool pertama (indikator; sudah tersanitasi & terpotong). */
|
|
24
|
+
names: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const MAX_PANEL_LABEL = 40
|
|
28
|
+
|
|
29
|
+
/** Agregasi activity → grup. Hanya activity yang statusnya terminal/running
|
|
30
|
+
* masuk; child (parentToolCallId) dihitung ke grup orang tuanya. */
|
|
31
|
+
export function groupActivities(
|
|
32
|
+
activities: readonly UiPresentationActivity[],
|
|
33
|
+
): Map<string, ActivityGroupView> {
|
|
34
|
+
const groups = new Map<string, ActivityGroupView>()
|
|
35
|
+
for (const a of activities) {
|
|
36
|
+
const kind = activityGroup(a.name)
|
|
37
|
+
let g = groups.get(kind)
|
|
38
|
+
if (!g) {
|
|
39
|
+
g = { kind, count: 0, ok: 0, failed: 0, running: 0, denied: 0, names: [] }
|
|
40
|
+
groups.set(kind, g)
|
|
41
|
+
}
|
|
42
|
+
g.count++
|
|
43
|
+
const status = a.status
|
|
44
|
+
if (status === "completed") g.ok++
|
|
45
|
+
else if (status === "failed") g.failed++
|
|
46
|
+
else if (status === "running") g.running++
|
|
47
|
+
else if (status === "denied") g.denied++
|
|
48
|
+
// Nama tool dari model/provider = input tak-terpercaya: buang SEMUA ANSI
|
|
49
|
+
// (termasuk SGR) saat masuk — styling ditambahkan renderer sendiri.
|
|
50
|
+
const cleanName = stripSgr(sanitizeAnsiLine(a.name))
|
|
51
|
+
if (g.names.length < 3 && !g.names.includes(cleanName)) g.names.push(cleanName)
|
|
52
|
+
}
|
|
53
|
+
return groups
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Satu baris grup (`+ explore · 3 tools · 2 ok · 1 failed`). */
|
|
57
|
+
export function groupLine(g: ActivityGroupView): string {
|
|
58
|
+
// Kunci i18n literal (bukan template) — MsgKey adalah union, bukan string.
|
|
59
|
+
const key:
|
|
60
|
+
| "panel.group.explore"
|
|
61
|
+
| "panel.group.edit"
|
|
62
|
+
| "panel.group.execute"
|
|
63
|
+
| "panel.group.feed"
|
|
64
|
+
| "panel.group.other" = `panel.group.${g.kind}` as never
|
|
65
|
+
const label = sanitizeAnsiLine(t(key))
|
|
66
|
+
const parts: string[] = [`+ ${truncateToWidth(label, MAX_PANEL_LABEL, "")}`]
|
|
67
|
+
parts.push(t("panel.tools", { n: g.count }))
|
|
68
|
+
if (g.ok > 0) parts.push(t("panel.ok", { n: g.ok }))
|
|
69
|
+
if (g.failed > 0) parts.push(t("panel.failed", { n: g.failed }))
|
|
70
|
+
if (g.running > 0) parts.push(t("panel.running", { n: g.running }))
|
|
71
|
+
const names = g.names.map((n) => sanitizeAnsiLine(n)).join(", ")
|
|
72
|
+
if (names) parts.push(`· ${truncateToWidth(names, MAX_PANEL_LABEL, "…")}`)
|
|
73
|
+
return parts.join(" ")
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Baris panel lengkap (header + satu baris per grup). Kosong bila tak ada
|
|
77
|
+
* activity — pemanggil boleh tak menampilkan apa pun. */
|
|
78
|
+
export function renderActivityPanel(
|
|
79
|
+
activities: readonly UiPresentationActivity[],
|
|
80
|
+
opts: { maxRows?: number } = {},
|
|
81
|
+
): string[] {
|
|
82
|
+
const max = Math.max(1, opts.maxRows ?? 10)
|
|
83
|
+
const groups = groupActivities(activities)
|
|
84
|
+
const out: string[] = []
|
|
85
|
+
if (groups.size === 0) return out
|
|
86
|
+
for (const g of groups.values()) {
|
|
87
|
+
if (out.length >= max) break
|
|
88
|
+
out.push(groupLine(g))
|
|
89
|
+
}
|
|
90
|
+
return out
|
|
91
|
+
}
|
package/src/ui/render/cells.ts
CHANGED
|
@@ -40,19 +40,25 @@ function isSgr(seq: string): boolean {
|
|
|
40
40
|
return true
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/** Urutan serialisasi kanonik — hasil sama apa pun urutan SGR masukannya.
|
|
44
|
-
|
|
43
|
+
/** Urutan serialisasi kanonik — hasil sama apa pun urutan SGR masukannya.
|
|
44
|
+
* Termasuk atribut yang jarang dipakai: 21 double-underline (u2), 53
|
|
45
|
+
* overline (ov), 58 underline-color (uc) — sebelumnya jatuh ke `raw:*` dan
|
|
46
|
+
* hilang saat serialisasi (audit render #1). */
|
|
47
|
+
const SGR_ORDER: readonly string[] = [
|
|
45
48
|
"bold",
|
|
46
49
|
"dim",
|
|
47
50
|
"italic",
|
|
48
51
|
"underline",
|
|
52
|
+
"u2",
|
|
53
|
+
"ov",
|
|
49
54
|
"blink",
|
|
50
55
|
"inverse",
|
|
51
56
|
"conceal",
|
|
52
57
|
"strike",
|
|
53
58
|
"fg",
|
|
54
59
|
"bg",
|
|
55
|
-
|
|
60
|
+
"uc",
|
|
61
|
+
]
|
|
56
62
|
|
|
57
63
|
interface SgrState {
|
|
58
64
|
values: Map<string, string>
|
|
@@ -70,6 +76,12 @@ function serializeSgr(state: SgrState): string {
|
|
|
70
76
|
const value = state.values.get(group)
|
|
71
77
|
if (value !== undefined) parts.push(value)
|
|
72
78
|
}
|
|
79
|
+
// Parameter tak dikenal (`raw:<token>`: 21, 53, 58, dst.) ikut
|
|
80
|
+
// diserialisasi — jangan dibuang (audit render #1). Urutan stabil
|
|
81
|
+
// (insertion order Map) supaya serialize idempoten.
|
|
82
|
+
for (const [group, value] of state.values) {
|
|
83
|
+
if (!SGR_ORDER.includes(group)) parts.push(value)
|
|
84
|
+
}
|
|
73
85
|
return `\x1b[${parts.join(";")}m`
|
|
74
86
|
}
|
|
75
87
|
|
|
@@ -109,8 +121,9 @@ function applySgrTo(state: SgrState, seq: string): void {
|
|
|
109
121
|
const colon = token.indexOf(":")
|
|
110
122
|
if (colon >= 0) {
|
|
111
123
|
const head = token.slice(0, colon)
|
|
112
|
-
if (head === "38"
|
|
124
|
+
if (head === "38") setGroup(state, "fg", token)
|
|
113
125
|
else if (head === "48") setGroup(state, "bg", token)
|
|
126
|
+
else if (head === "58") setGroup(state, "uc", token)
|
|
114
127
|
else setGroup(state, `raw:${head}`, token)
|
|
115
128
|
continue
|
|
116
129
|
}
|
|
@@ -123,13 +136,14 @@ function applySgrTo(state: SgrState, seq: string): void {
|
|
|
123
136
|
state.values.clear()
|
|
124
137
|
continue
|
|
125
138
|
}
|
|
126
|
-
if (n === 38 || n === 48) {
|
|
139
|
+
if (n === 38 || n === 48 || n === 58) {
|
|
127
140
|
const extended = readExtended(tokens, i, n)
|
|
128
141
|
if (!extended) {
|
|
129
142
|
setGroup(state, `raw:${n}`, token)
|
|
130
143
|
continue
|
|
131
144
|
}
|
|
132
|
-
|
|
145
|
+
if (n === 58) setGroup(state, "uc", extended.value)
|
|
146
|
+
else setGroup(state, n === 38 ? "fg" : "bg", extended.value)
|
|
133
147
|
i = extended.next
|
|
134
148
|
continue
|
|
135
149
|
}
|
|
@@ -153,8 +167,21 @@ function applySgrTo(state: SgrState, seq: string): void {
|
|
|
153
167
|
case 4:
|
|
154
168
|
setGroup(state, "underline", "4")
|
|
155
169
|
break
|
|
170
|
+
case 21:
|
|
171
|
+
setGroup(state, "u2", "21")
|
|
172
|
+
break
|
|
156
173
|
case 24:
|
|
157
174
|
setGroup(state, "underline", null)
|
|
175
|
+
setGroup(state, "u2", null)
|
|
176
|
+
break
|
|
177
|
+
case 53:
|
|
178
|
+
setGroup(state, "ov", "53")
|
|
179
|
+
break
|
|
180
|
+
case 54:
|
|
181
|
+
setGroup(state, "ov", null)
|
|
182
|
+
break
|
|
183
|
+
case 59:
|
|
184
|
+
setGroup(state, "uc", null)
|
|
158
185
|
break
|
|
159
186
|
case 5:
|
|
160
187
|
case 6:
|
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
|
|
@@ -24,6 +51,13 @@ export interface DiffLine {
|
|
|
24
51
|
export function computeLineDiff(oldText: string, newText: string): DiffLine[] {
|
|
25
52
|
const oldLines = oldText.split("\n")
|
|
26
53
|
const newLines = newText.split("\n")
|
|
54
|
+
// Pop SATU elemen kosong di ekor tiap sisi. Elemen itu artefak newline
|
|
55
|
+
// penutup (`"a\n".split("\n")` → `["a",""]`), bukan baris nyata — tanpa
|
|
56
|
+
// ini `computeLineDiff("", "baru")` dan `"a\n"` vs `"a"` memancarkan
|
|
57
|
+
// delete/context baris kosong spurious. Baris kosong nyata di tengah tetap
|
|
58
|
+
// dipertahankan; hanya ekor artifisial yang dibuang.
|
|
59
|
+
if (oldLines[oldLines.length - 1] === "") oldLines.pop()
|
|
60
|
+
if (newLines[newLines.length - 1] === "") newLines.pop()
|
|
27
61
|
const result: DiffLine[] = []
|
|
28
62
|
let i = 0,
|
|
29
63
|
j = 0,
|
|
@@ -73,6 +107,15 @@ export function markChangedWords(
|
|
|
73
107
|
const b = tokenizeWords(newLine)
|
|
74
108
|
const n = a.length
|
|
75
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
|
+
}
|
|
76
119
|
const dp: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0))
|
|
77
120
|
for (let i = n - 1; i >= 0; i--)
|
|
78
121
|
for (let j = m - 1; j >= 0; j--)
|
|
@@ -112,9 +155,17 @@ export function renderDiffCard(
|
|
|
112
155
|
// dirender. Tanpa ini `\n` di path menjadi baris diff palsu dan `ESC[2J`
|
|
113
156
|
// lolos via `cut` (truncate menyalin escape apa pun sebelum F-04).
|
|
114
157
|
const safePath = sanitizeAnsiLine(filePath)
|
|
115
|
-
const
|
|
158
|
+
const cappedOld = capDiffInput(oldText)
|
|
159
|
+
const cappedNew = capDiffInput(newText)
|
|
160
|
+
const diff = computeLineDiff(sanitizeAnsi(cappedOld.text), sanitizeAnsi(cappedNew.text))
|
|
116
161
|
const changes = diff.filter((d) => d.type !== "context")
|
|
117
|
-
|
|
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
|
+
}
|
|
118
169
|
// Pasangan del/add untuk sorot kata: kelompokkan run perubahan beruntun,
|
|
119
170
|
// pasangkan del ke-i dengan add ke-i (pola hunk unified).
|
|
120
171
|
const wordMask = new Map<number, boolean[]>()
|
|
@@ -191,5 +242,10 @@ export function renderDiffCard(
|
|
|
191
242
|
} else lines.push(...wrapDiffLine(" ", d.content, (s) => c.dim(s)))
|
|
192
243
|
count++
|
|
193
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
|
+
}
|
|
194
250
|
return lines.join("\n")
|
|
195
251
|
}
|