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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Bar loading startup — baris tunggal blok progres (`▓░`) + persen + label
|
|
2
|
+
// di stderr, menggantikan teks proses verbose saat REPL dibuka. Fase startup
|
|
3
|
+
// memanggil `update(label, percent)`; bar melukis via `paintWrite` sehingga
|
|
4
|
+
// otomatis tunduk pada arbitrase statusline.ts (wizard interaktif menahannya,
|
|
5
|
+
// tulis asing di-commit sebagai baris permanen, non-TTY = nol byte).
|
|
6
|
+
//
|
|
7
|
+
// Fase hanyalah sinyal, bukan animasi loop: frame digambar ulang TIDAK pada
|
|
8
|
+
// interval, melainkan saat `update()` dipanggil. Dengan begitu bar tidak
|
|
9
|
+
// berkedip pada startup yang sangat cepat (delay pertama 120ms) dan tidak
|
|
10
|
+
// melukis apa pun bila tidak ada fase yang melaporkan progres.
|
|
11
|
+
|
|
12
|
+
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
13
|
+
import { c, glyphs } from "../render/theme.ts"
|
|
14
|
+
import { truncateToWidth } from "../render/width.ts"
|
|
15
|
+
import { motionReduced } from "./motion.ts"
|
|
16
|
+
import { acquireTransientPaint, paintWrite } from "./statusline.ts"
|
|
17
|
+
|
|
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
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LoadingBar {
|
|
33
|
+
/** Ganti label + persen (0..100). Tak pernah melampaui target yang diberikan. */
|
|
34
|
+
update: (label: string, percent: number) => void
|
|
35
|
+
/** Hapus baris + restore kursor. Idempoten. */
|
|
36
|
+
stop: () => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface LoadingBarOptions {
|
|
40
|
+
/** Tunda frame pertama (ms). Default 120 — fase cepat tak berkedip. */
|
|
41
|
+
delayMs?: number
|
|
42
|
+
/** Lebar maks kolom bar (default 40). */
|
|
43
|
+
barWidth?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createLoadingBar(
|
|
47
|
+
initialLabel = "",
|
|
48
|
+
opts: LoadingBarOptions = {},
|
|
49
|
+
): LoadingBar | null {
|
|
50
|
+
// Non-TTY/pipe/CI: tanpa animasi/ANSI (kontrak terminal) — bar jadi no-op.
|
|
51
|
+
if (!process.stderr.isTTY) return null
|
|
52
|
+
// Preferensi gerak dikurangi: tetap tampilkan progres (informatif), tapi
|
|
53
|
+
// tanpa menyembunyikan kursor dan tanpa delay (tak ada sensasi animasi).
|
|
54
|
+
const reduced = motionReduced()
|
|
55
|
+
const delayMs = reduced ? 0 : (opts.delayMs ?? 120)
|
|
56
|
+
const barWidthMax = Math.max(8, Math.min(40, opts.barWidth ?? 40))
|
|
57
|
+
let label = sanitizeAnsiLine(initialLabel)
|
|
58
|
+
let percent = 0
|
|
59
|
+
let owned: { release(): void } | null = null
|
|
60
|
+
let delayTimer: ReturnType<typeof setTimeout> | undefined
|
|
61
|
+
let started = false
|
|
62
|
+
let stopped = false
|
|
63
|
+
|
|
64
|
+
const frame = (): string => {
|
|
65
|
+
// Lebar terminal = kolom (bukan karakter). Bar dihitung dari `columns`;
|
|
66
|
+
// sisa kolom untuk label (displayWidth-aware via truncateToWidth).
|
|
67
|
+
const cols = process.stderr.columns ?? process.stdout.columns ?? 80
|
|
68
|
+
const w = Math.min(barWidthMax, Math.max(8, cols - 20))
|
|
69
|
+
const filled = Math.round((percent / 100) * w)
|
|
70
|
+
const blocks = glyphs.blockFilled.repeat(filled) + glyphs.blockEmpty.repeat(w - filled)
|
|
71
|
+
const pct = `${Math.round(percent)}%`.padStart(4)
|
|
72
|
+
const labelPart = truncateToWidth(label, Math.max(4, cols - w - 14))
|
|
73
|
+
return `\r${c.dim(blocks)} ${pct} ${labelPart}\x1b[K`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const paint = (): void => {
|
|
77
|
+
paintWrite(frame())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const start = (): void => {
|
|
81
|
+
if (stopped || started) return
|
|
82
|
+
started = true
|
|
83
|
+
// Sembunyikan kursor hanya saat animasi normal; mode gerak-dikurangi
|
|
84
|
+
// cukup melukis baris tanpa mengubah visibilitas kursor.
|
|
85
|
+
if (!reduced) {
|
|
86
|
+
installExitHook()
|
|
87
|
+
paintWrite("\x1b[?25l")
|
|
88
|
+
}
|
|
89
|
+
owned = acquireTransientPaint("loading-bar", paint)
|
|
90
|
+
paint()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const scheduleStart = (): void => {
|
|
94
|
+
if (delayMs > 0) {
|
|
95
|
+
delayTimer = setTimeout(() => {
|
|
96
|
+
delayTimer = undefined
|
|
97
|
+
start()
|
|
98
|
+
}, delayMs)
|
|
99
|
+
// Jangan tahan process hidup hanya karena delay tampil.
|
|
100
|
+
try {
|
|
101
|
+
;(delayTimer as unknown as { unref?: () => void }).unref?.()
|
|
102
|
+
} catch {}
|
|
103
|
+
} else {
|
|
104
|
+
start()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
scheduleStart()
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
update(newLabel: string, newPercent: number) {
|
|
112
|
+
if (stopped) return
|
|
113
|
+
label = sanitizeAnsiLine(newLabel)
|
|
114
|
+
percent = Math.max(0, Math.min(100, newPercent))
|
|
115
|
+
// Sebelum delay habis, bar belum melukis apa pun — cukup simpan label/
|
|
116
|
+
// percent terbaru. `start()` (dari timer delay) memakai nilai ini, jadi
|
|
117
|
+
// fase yang cepat selesai sebelum delay tidak menampilkan frame kosong.
|
|
118
|
+
if (started) paint()
|
|
119
|
+
},
|
|
120
|
+
stop() {
|
|
121
|
+
if (stopped) return
|
|
122
|
+
stopped = true
|
|
123
|
+
if (delayTimer) {
|
|
124
|
+
clearTimeout(delayTimer)
|
|
125
|
+
delayTimer = undefined
|
|
126
|
+
}
|
|
127
|
+
if (owned) {
|
|
128
|
+
owned.release()
|
|
129
|
+
owned = null
|
|
130
|
+
}
|
|
131
|
+
if (started) {
|
|
132
|
+
paintWrite(reduced ? "\r\x1b[K" : "\r\x1b[K\x1b[?25h")
|
|
133
|
+
}
|
|
134
|
+
started = false
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
}
|
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()
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type DecodedKey,
|
|
10
10
|
type DecoderState,
|
|
11
11
|
} from "../input/prompt-engine.ts"
|
|
12
|
-
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
|
+
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
13
13
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
14
14
|
import { truncateToWidth } from "../render/width.ts"
|
|
15
15
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
@@ -400,7 +400,10 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
400
400
|
if (res.ok) notice = `${glyphs.check} ${sanitizeAnsiLine(res.ok)}`
|
|
401
401
|
else if (res.err) notice = `${glyphs.cross} ${sanitizeAnsiLine(res.err)}`
|
|
402
402
|
} catch (e) {
|
|
403
|
-
|
|
403
|
+
// Pesan error jaringan/controller = input tak-terpercaya: tanpa
|
|
404
|
+
// sanitasi, body provider bisa menyuntik `ESC[2J` ke popup dan
|
|
405
|
+
// menghapus layar TUI (audit 2026-11-12, MEDIUM-2).
|
|
406
|
+
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
404
407
|
} finally {
|
|
405
408
|
busy = false
|
|
406
409
|
await reload().catch(() => {})
|
|
@@ -632,7 +635,12 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
632
635
|
cleanup()
|
|
633
636
|
} catch {}
|
|
634
637
|
try {
|
|
635
|
-
|
|
638
|
+
// Pesan setup gagal (bisa memuat body jaringan) = teks tak-terpercaya.
|
|
639
|
+
console.log(
|
|
640
|
+
`⚠ ${t("prov.failOpen", {
|
|
641
|
+
msg: cleanUntrusted(String((e as Error)?.message ?? e), !!process.stdout.isTTY),
|
|
642
|
+
})}`,
|
|
643
|
+
)
|
|
636
644
|
} catch {}
|
|
637
645
|
try {
|
|
638
646
|
resolve()
|
package/src/ui/screens/wizard.ts
CHANGED
|
@@ -11,6 +11,34 @@ import { dialogBox } from "./dialog.ts"
|
|
|
11
11
|
import { runForm, validateUrl } from "./form.ts"
|
|
12
12
|
import { runPicker } from "./picker.ts"
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Batas tunggu simpan-provider (audit 2026-11-12, MEDIUM-7).
|
|
16
|
+
*
|
|
17
|
+
* `detect()` sendiri punya timeout, tapi callback controller juga melakukan
|
|
18
|
+
* I/O config (kunci, tulis disk) yang bisa lambat; tanpa batas, kotak
|
|
19
|
+
* "mendeteksi…" bertahan selama proses menggantung dan user tak punya jalan
|
|
20
|
+
* keluar (tak ada Esc di kotak progres). Timeout = pesan jujur, UI pulih.
|
|
21
|
+
*/
|
|
22
|
+
async function withWatchdog<T>(fn: () => Promise<T>, ms = 60_000): Promise<T> {
|
|
23
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
24
|
+
const pending = Promise.resolve().then(fn)
|
|
25
|
+
// Rejection telat tanpa handler = unhandledRejection (Bun: crash).
|
|
26
|
+
pending.catch(() => {})
|
|
27
|
+
try {
|
|
28
|
+
return await Promise.race([
|
|
29
|
+
pending,
|
|
30
|
+
new Promise<never>((_, reject) => {
|
|
31
|
+
timer = setTimeout(() => reject(new Error(t("ntc.timeout"))), ms)
|
|
32
|
+
try {
|
|
33
|
+
;(timer as unknown as { unref?: () => void }).unref?.()
|
|
34
|
+
} catch {}
|
|
35
|
+
}),
|
|
36
|
+
])
|
|
37
|
+
} finally {
|
|
38
|
+
if (timer) clearTimeout(timer)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
14
42
|
export interface WizardPreset {
|
|
15
43
|
label: string
|
|
16
44
|
baseUrl: string
|
|
@@ -148,7 +176,7 @@ export async function runSetupWizardView(opts: SetupWizardViewOptions): Promise<
|
|
|
148
176
|
)
|
|
149
177
|
screen.paintRegion(box.lines, box.topRow)
|
|
150
178
|
try {
|
|
151
|
-
const message = await opts.onSubmit(targetUrl, apiKey)
|
|
179
|
+
const message = await withWatchdog(() => opts.onSubmit(targetUrl, apiKey))
|
|
152
180
|
// Pesan dari jaringan (nama model/gateway) — sanitasi sebelum tampil.
|
|
153
181
|
screen.clearRegion()
|
|
154
182
|
const doneBox = dialogBox(
|
package/src/ui/session-state.ts
CHANGED
|
@@ -41,6 +41,7 @@ export interface UiSessionStateOptions {
|
|
|
41
41
|
compact?: boolean
|
|
42
42
|
reasoningVisible?: boolean
|
|
43
43
|
minimizeActivity?: boolean
|
|
44
|
+
activityPanel?: boolean
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/**
|
|
@@ -56,6 +57,7 @@ export class UiSessionState {
|
|
|
56
57
|
#compact: boolean
|
|
57
58
|
#reasoningVisible: boolean
|
|
58
59
|
#minimizeActivity: boolean
|
|
60
|
+
#activityPanel: boolean
|
|
59
61
|
#views: CollapsedSectionView[] = []
|
|
60
62
|
|
|
61
63
|
// Buffer /copy + error tertunda (logger linier). Berlifecycle per sesi:
|
|
@@ -78,6 +80,9 @@ export class UiSessionState {
|
|
|
78
80
|
// ditahan, diganti satu ringkasan turn. Opt-in (`MINICODE_MINIMIZE_ACTIVITY=1`),
|
|
79
81
|
// default transparan sesuai filosofi "agentic Unix shell".
|
|
80
82
|
this.#minimizeActivity = opts.minimizeActivity ?? process.env.MINICODE_MINIMIZE_ACTIVITY === "1"
|
|
83
|
+
// Panel aktivitas (Fase 2): default OFF — opt-in. TUI (cli/tui.ts)
|
|
84
|
+
// menyalakannya secara eksplisit; env bisa meng-override bootstrap.
|
|
85
|
+
this.#activityPanel = opts.activityPanel ?? process.env.MINICODE_ACTIVITY_PANEL === "1"
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
// ── Collapse ────────────────────────────────────────────────────────────
|
|
@@ -197,6 +202,23 @@ export class UiSessionState {
|
|
|
197
202
|
return nextVal
|
|
198
203
|
}
|
|
199
204
|
|
|
205
|
+
// ── Panel aktivitas (Fase 2: thinking + grup tool) ──────────────────────
|
|
206
|
+
|
|
207
|
+
get activityPanel(): boolean {
|
|
208
|
+
return this.#activityPanel
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
set activityPanel(v: boolean) {
|
|
212
|
+
this.#activityPanel = v
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Set eksplisit (on/off) atau toggle bila `next` tidak diberikan. */
|
|
216
|
+
setActivityPanel(next?: boolean): boolean {
|
|
217
|
+
const nextVal = next ?? !this.#activityPanel
|
|
218
|
+
this.#activityPanel = nextVal
|
|
219
|
+
return nextVal
|
|
220
|
+
}
|
|
221
|
+
|
|
200
222
|
// ── Buffer /copy (logger linier) ────────────────────────────────────────
|
|
201
223
|
|
|
202
224
|
/** Isi output turn terakhir (teks model + hasil tool). */
|
package/src/ui/tui/app.ts
CHANGED
|
@@ -131,6 +131,19 @@ export function timerHighlight(ms: number): TimerHighlight {
|
|
|
131
131
|
return "seconds"
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Indeks awal jendela dropdown yang menjaga item terpilih (`sel`) selalu tampil.
|
|
136
|
+
* Sebelum A1, jendela selalu `slice(0, visible)` sehingga `sel >= visible` tak
|
|
137
|
+
* pernah tersorot tetapi Enter tetap mengirim `hints[sel]` — perintah destruktif
|
|
138
|
+
* yang tak terlihat. Kontrak: untuk `0 <= sel < total` berlaku
|
|
139
|
+
* `start <= sel < start + min(visible, total)`.
|
|
140
|
+
*/
|
|
141
|
+
export function dropdownWindowStart(sel: number, visible: number, total: number): number {
|
|
142
|
+
const v = Math.max(1, Math.floor(visible))
|
|
143
|
+
if (total <= v) return 0
|
|
144
|
+
return Math.max(0, Math.min(sel - v + 1, total - v))
|
|
145
|
+
}
|
|
146
|
+
|
|
134
147
|
interface FrameLayout {
|
|
135
148
|
frame: string[]
|
|
136
149
|
cursor: { row: number; col: number }
|
|
@@ -292,8 +305,6 @@ export class TuiApp {
|
|
|
292
305
|
*/
|
|
293
306
|
private busUnsubs: (() => void)[] = []
|
|
294
307
|
private repaintTimer: ReturnType<typeof setTimeout> | undefined
|
|
295
|
-
/** Ukuran transkrip saat terakhir ikut ekor (basis indikator "baru"). */
|
|
296
|
-
private tailSize = 0
|
|
297
308
|
/** Ukuran transkrip saat mulai scroll ke atas (basis hitung baris baru). */
|
|
298
309
|
private scrollBase = 0
|
|
299
310
|
/** Panjang visual terakhir (kunci posisi baca agar stream tak merampasnya). */
|
|
@@ -486,8 +497,7 @@ export class TuiApp {
|
|
|
486
497
|
this.thinkingActive = false
|
|
487
498
|
})
|
|
488
499
|
sub("context:compacted")
|
|
489
|
-
this.
|
|
490
|
-
this.scrollBase = this.tailSize
|
|
500
|
+
this.scrollBase = this.transcript.total()
|
|
491
501
|
this.setMouseMode(mouseSelectionEnabled() ? "drag" : "off")
|
|
492
502
|
this.paint(screen)
|
|
493
503
|
await done
|
|
@@ -694,7 +704,10 @@ export class TuiApp {
|
|
|
694
704
|
if (this.state.line || this.editing) {
|
|
695
705
|
this.state = createState()
|
|
696
706
|
this.histIdx = -1
|
|
697
|
-
|
|
707
|
+
// Prompt TETAP tampil setelah Esc: kontrak I13 mensyaratkan prompt
|
|
708
|
+
// ada saat idle, dan menyembunyikannya membuat layar terlihat mati
|
|
709
|
+
// sampai user menekan tombol berikutnya (audit 2026-11-12, MEDIUM-4).
|
|
710
|
+
this.editing = true
|
|
698
711
|
this.paintCurrent()
|
|
699
712
|
}
|
|
700
713
|
return
|
|
@@ -869,6 +882,9 @@ export class TuiApp {
|
|
|
869
882
|
this.followTail()
|
|
870
883
|
this.abortHintOn = false
|
|
871
884
|
if (!line) {
|
|
885
|
+
// Enter pada baris kosong tetap idle: prompt harus langsung kembali
|
|
886
|
+
// (I13), bukan menghilang sampai ketikan berikutnya.
|
|
887
|
+
this.editing = true
|
|
872
888
|
this.paintCurrent()
|
|
873
889
|
return
|
|
874
890
|
}
|
|
@@ -1120,8 +1136,7 @@ export class TuiApp {
|
|
|
1120
1136
|
if (this.scrollBack === 0 && pages > 0) this.scrollBase = this.transcript.total()
|
|
1121
1137
|
this.scrollBack = Math.max(0, Math.round(this.scrollBack + pages * page))
|
|
1122
1138
|
if (this.scrollBack === 0) {
|
|
1123
|
-
this.
|
|
1124
|
-
this.scrollBase = this.tailSize
|
|
1139
|
+
this.scrollBase = this.transcript.total()
|
|
1125
1140
|
}
|
|
1126
1141
|
this.paintCurrent()
|
|
1127
1142
|
}
|
|
@@ -1130,7 +1145,7 @@ export class TuiApp {
|
|
|
1130
1145
|
* Scroll per BARIS (bukan per halaman) — dipakai auto-scroll seleksi agar
|
|
1131
1146
|
* gulirnya halus & presisi. `n` = baris terbungkus (+ = ke atas/lama,
|
|
1132
1147
|
* - = ke bawah/baru); di-clamp ke [0, wrapped - viewH]. Menjaga basis
|
|
1133
|
-
* `
|
|
1148
|
+
* `scrollBase` sama seperti `scrollBy`.
|
|
1134
1149
|
*/
|
|
1135
1150
|
private scrollRows(n: number): void {
|
|
1136
1151
|
const cols = process.stdout.columns || 80
|
|
@@ -1141,8 +1156,7 @@ export class TuiApp {
|
|
|
1141
1156
|
if (this.scrollBack === 0 && n > 0) this.scrollBase = this.transcript.total()
|
|
1142
1157
|
this.scrollBack = Math.max(0, Math.min(this.scrollBack + n, maxBack))
|
|
1143
1158
|
if (this.scrollBack === 0) {
|
|
1144
|
-
this.
|
|
1145
|
-
this.scrollBase = this.tailSize
|
|
1159
|
+
this.scrollBase = this.transcript.total()
|
|
1146
1160
|
}
|
|
1147
1161
|
this.paintCurrent()
|
|
1148
1162
|
}
|
|
@@ -1165,8 +1179,7 @@ export class TuiApp {
|
|
|
1165
1179
|
this.scrollBack = Math.max(0, curWrapped - viewH)
|
|
1166
1180
|
} else {
|
|
1167
1181
|
this.scrollBack = 0
|
|
1168
|
-
this.
|
|
1169
|
-
this.scrollBase = this.tailSize
|
|
1182
|
+
this.scrollBase = this.transcript.total()
|
|
1170
1183
|
}
|
|
1171
1184
|
this.paintCurrent()
|
|
1172
1185
|
}
|
|
@@ -1174,8 +1187,7 @@ export class TuiApp {
|
|
|
1174
1187
|
/** Kembali ke ekor: dipakai tiap ketikan/submit baru (I18). */
|
|
1175
1188
|
private followTail(): void {
|
|
1176
1189
|
this.scrollBack = 0
|
|
1177
|
-
this.
|
|
1178
|
-
this.scrollBase = this.tailSize
|
|
1190
|
+
this.scrollBase = this.transcript.total()
|
|
1179
1191
|
}
|
|
1180
1192
|
|
|
1181
1193
|
/** Kosongkan transkrip (/clear): viewport + basis scroll ikut di-reset agar
|
|
@@ -1234,7 +1246,10 @@ export class TuiApp {
|
|
|
1234
1246
|
const content = this.thinkingActive ? thinkingDots(now, start) : status
|
|
1235
1247
|
return [this.activityRow(content, cols)]
|
|
1236
1248
|
}
|
|
1237
|
-
|
|
1249
|
+
// Idle: prompt tetap tampil. Dulu baris kosong menggantikannya sehingga
|
|
1250
|
+
// setelah Esc/Enter-kosong layar terlihat mati (I13: prompt tampil saat
|
|
1251
|
+
// boot/idle) — audit 2026-11-12, MEDIUM-4.
|
|
1252
|
+
if (!this.editing) return [chunkByWidth(PROMPT_FIRST, Math.max(10, cols))[0] ?? ""]
|
|
1238
1253
|
return this.composerLayout(cols).rows
|
|
1239
1254
|
}
|
|
1240
1255
|
|
|
@@ -1277,7 +1292,11 @@ export class TuiApp {
|
|
|
1277
1292
|
* jalan atau sudah quit.
|
|
1278
1293
|
*/
|
|
1279
1294
|
repaint(): void {
|
|
1280
|
-
|
|
1295
|
+
// Suspend = pemilik layar lain (popup/approval) sedang melukis region
|
|
1296
|
+
// sendiri; melukis frame penuh di sini akan menimpanya. Sebelumnya guard
|
|
1297
|
+
// ini hanya ada di `requestPaint`, jadi API publik tak konsisten (audit
|
|
1298
|
+
// 2026-11-12, MEDIUM-9).
|
|
1299
|
+
if (!this.quitRequested && this.suspended === 0) this.paintCurrent()
|
|
1281
1300
|
}
|
|
1282
1301
|
|
|
1283
1302
|
private viewportHeight(rows: number, cols: number): number {
|
|
@@ -1401,11 +1420,19 @@ export class TuiApp {
|
|
|
1401
1420
|
const hints = this.host.listCommands(this.state.line)
|
|
1402
1421
|
if (!hints.length) return []
|
|
1403
1422
|
const room = Math.max(0, rows - 2 - this.composerHeight(cols, busy) - 3)
|
|
1404
|
-
const
|
|
1423
|
+
const visible = Math.max(1, Math.min(MAX_DROPDOWN_ROWS, room))
|
|
1424
|
+
const total = hints.length
|
|
1425
|
+
// A1: jendela MENGIKUTI `sel`, bukan selalu slice dari index 0. `sel` bisa
|
|
1426
|
+
// wrap melewati jumlah baris terlihat (mis. 24 perintah → sel 9..23), dan
|
|
1427
|
+
// bila jendela tetap index 0, tak ada baris tersorot tetapi Enter tetap
|
|
1428
|
+
// mengirim hints[sel] — perintah yang tak pernah terlihat (destruktif untuk
|
|
1429
|
+
// /clear, /undo). `start` menjaga item terpilih selalu tampil.
|
|
1430
|
+
const start = dropdownWindowStart(this.state.sel, visible, total)
|
|
1431
|
+
const shown = hints.slice(start, start + visible)
|
|
1405
1432
|
const w = Math.max(10, cols)
|
|
1406
1433
|
const out: string[] = []
|
|
1407
1434
|
shown.forEach((h, i) => {
|
|
1408
|
-
const picked = i === this.state.sel
|
|
1435
|
+
const picked = start + i === this.state.sel
|
|
1409
1436
|
const text = sanitizeAnsiLine(h).replace(/^\/+/, "")
|
|
1410
1437
|
out.push(picked ? c.accent(c.bold(text)) : text)
|
|
1411
1438
|
})
|
|
@@ -1625,9 +1652,16 @@ export class TuiApp {
|
|
|
1625
1652
|
this.turnStartedAt = 0
|
|
1626
1653
|
}
|
|
1627
1654
|
const newCount = this.scrollBack > 0 ? this.transcript.total() - this.scrollBase : 0
|
|
1655
|
+
// Baris indikator WAJIB dipotong ke lebar frame seperti baris lain: teks
|
|
1656
|
+
// locale id lebih panjang dari terminal sempit (51 kolom untuk abort hint),
|
|
1657
|
+
// dan baris lebih lebar dari `cols` membungkus sendiri → frame jadi
|
|
1658
|
+
// `rows+1`, alt-screen scroll, seluruh diff CUP meleset (audit 2026-11-12,
|
|
1659
|
+
// HIGH-3).
|
|
1628
1660
|
const indicator: string[] = []
|
|
1629
|
-
if (busy && this.abortHintOn)
|
|
1630
|
-
|
|
1661
|
+
if (busy && this.abortHintOn)
|
|
1662
|
+
indicator.push(c.warning(truncateToWidth(t("app.abortHint"), width)))
|
|
1663
|
+
else if (newCount > 0)
|
|
1664
|
+
indicator.push(c.muted(truncateToWidth(t("app.newBelow", { n: newCount }), width)))
|
|
1631
1665
|
|
|
1632
1666
|
const allMenu = this.menuRows(height, width, busy)
|
|
1633
1667
|
const allComposer = this.composerRows(width, snap, busy, now)
|
|
@@ -1681,6 +1715,9 @@ export class TuiApp {
|
|
|
1681
1715
|
} else {
|
|
1682
1716
|
shownComposer = allComposer.slice(0, composerH)
|
|
1683
1717
|
cursorRow = viewH + menu.length + indicator.length + 1
|
|
1718
|
+
// Kursor parkir tepat setelah prompt saat idle (bukan kolom 1) supaya
|
|
1719
|
+
// caret terlihat di tempat user akan mengetik.
|
|
1720
|
+
if (!busy) cursorCol = displayWidth(PROMPT_FIRST) + 1
|
|
1684
1721
|
}
|
|
1685
1722
|
|
|
1686
1723
|
const started = this.turnStartedAt || now
|