minicode-ai 0.10.0 → 0.11.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/AGENTS.md +45 -0
- package/CHANGELOG.md +59 -4
- package/PLAN.md +491 -0
- package/README.md +2 -2
- package/cli/commands/acp.ts +485 -0
- package/cli/commands/auth.ts +7 -4
- package/cli/commands/config.ts +41 -27
- package/cli/commands/exec.ts +33 -12
- package/cli/commands/mcp.ts +3 -2
- package/cli/commands/memory.ts +1 -1
- package/cli/commands/pricing.ts +6 -4
- package/cli/commands/providers.ts +18 -8
- package/cli/commands/sessions.ts +11 -4
- package/cli/commands/skills.ts +3 -3
- package/cli/commands/stats.ts +3 -1
- package/cli/commands.ts +6 -0
- package/cli/index.ts +82 -57
- package/cli/model-manager.ts +6 -1
- package/cli/router.ts +7 -0
- package/cli/setup.ts +341 -5
- package/cli/tui.ts +54 -18
- package/docs/ARCHITECTURE.html +29 -22
- package/docs/CONTROL-PLANE-MAP.md +139 -0
- package/docs/HARNESS.md +150 -0
- package/docs/PLAN_UIUX_V6.md +209 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +52 -0
- package/docs/TERMINAL_CONTRACT.md +367 -0
- package/docs/UI_RENDER_PIPELINE.md +165 -0
- package/docs/USAGE.md +11 -0
- package/docs/agents.md +31 -0
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +34 -0
- package/docs/cli.md +130 -0
- package/docs/concepts.md +53 -0
- package/docs/config-providers.md +87 -0
- package/docs/config.md +63 -0
- package/docs/contributing.md +79 -0
- package/docs/environment.md +95 -0
- package/docs/exec.md +73 -0
- package/docs/getting-started.md +102 -0
- package/docs/glossary.md +37 -0
- package/docs/mcp-lsp.md +54 -0
- package/docs/memory-sessions.md +63 -0
- package/docs/policy-sandbox.md +72 -0
- package/docs/pricing-budget.md +49 -0
- package/docs/quickstart.md +60 -0
- package/docs/repl.md +67 -0
- package/docs/security-model.md +95 -0
- package/docs/security.md +91 -0
- package/docs/skills.md +48 -0
- package/docs/terminal.md +79 -0
- package/docs/tools.md +123 -0
- package/docs/troubleshooting.md +40 -0
- package/docs/verify-benchmark.md +58 -0
- package/package.json +8 -5
- package/src/app/provider-layer.ts +12 -4
- package/src/app/session.ts +6 -0
- package/src/app/tool-layer.ts +2 -1
- package/src/constants.ts +35 -0
- package/src/lib/net.ts +6 -1
- package/src/lsp/client.ts +41 -8
- package/src/mcp/http-transport.ts +52 -15
- package/src/mcp/transport.ts +32 -1
- package/src/memory/files.ts +6 -5
- package/src/policy/allowlist.ts +1 -1
- package/src/policy/bash-guard.ts +154 -14
- package/src/policy/compaction.ts +57 -3
- package/src/policy/context.ts +4 -0
- package/src/policy/jail.ts +49 -4
- package/src/policy/permission.ts +152 -12
- package/src/policy/pricing.ts +12 -9
- package/src/presentation/adapter.ts +721 -0
- package/src/presentation/events.ts +324 -0
- package/src/presentation/label.ts +140 -0
- package/src/presentation/model.ts +172 -0
- package/src/presentation/reducer.ts +486 -0
- package/src/presentation/store.ts +256 -0
- package/src/providers/anthropic.ts +22 -4
- package/src/providers/detect.ts +2 -1
- package/src/providers/router.ts +13 -0
- package/src/repo/repomap.ts +2 -29
- package/src/session/checkpoint.ts +27 -9
- package/src/session/journal.ts +27 -5
- package/src/skills/loader.ts +88 -5
- package/src/telemetry/trace.ts +36 -15
- package/src/tools/ask_user.ts +73 -4
- package/src/tools/bash.ts +15 -17
- package/src/tools/glob.ts +10 -11
- package/src/tools/lsp.ts +3 -56
- package/src/tools/memory.ts +13 -12
- package/src/tools/task.ts +1 -0
- package/src/ui/approval/prompt.ts +14 -6
- package/src/ui/assistant/simple.ts +137 -26
- package/src/ui/assistant/turn-status.ts +16 -3
- package/src/ui/contract.ts +119 -0
- package/src/ui/footer.ts +21 -2
- package/src/ui/i18n/en.ts +34 -6
- package/src/ui/i18n/id.ts +34 -6
- package/src/ui/i18n/locale.ts +3 -1
- package/src/ui/input/input.ts +51 -4
- package/src/ui/input/prompt-engine.ts +46 -4
- package/src/ui/render/collapse.ts +13 -13
- package/src/ui/render/diff.ts +7 -2
- package/src/ui/render/format.ts +16 -8
- package/src/ui/render/highlight.ts +7 -3
- package/src/ui/render/markdown.ts +5 -1
- package/src/ui/render/sanitize.ts +29 -2
- package/src/ui/render/table.ts +8 -5
- package/src/ui/render/theme.ts +18 -4
- package/src/ui/render/width.ts +89 -10
- package/src/ui/runtime/motion.ts +16 -0
- package/src/ui/runtime/screen.ts +45 -0
- package/src/ui/runtime/spinner.ts +50 -4
- package/src/ui/runtime/statusline.ts +50 -1
- package/src/ui/screens/form.ts +42 -15
- package/src/ui/screens/model-manager.ts +26 -18
- package/src/ui/screens/picker.ts +47 -23
- package/src/ui/screens/provider-manager.ts +18 -12
- package/src/ui/screens/wizard.ts +24 -8
- package/src/ui/tui/app.ts +233 -27
- package/src/ui/tui/transcript.ts +269 -65
- package/vendor/minicore/LICENSE +21 -0
- package/vendor/minicore/VENDOR.md +6 -3
- package/vendor/minicore/package.json +6 -3
- package/vendor/minicore/src/core/loop.ts +12 -2
- package/vendor/minicore/src/core/snapshot.ts +4 -0
- package/vendor/minicore/src/providers/openai-compat.ts +76 -25
package/src/ui/render/width.ts
CHANGED
|
@@ -73,9 +73,14 @@ function inRanges(cp: number, ranges: [number, number][]): boolean {
|
|
|
73
73
|
return false
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/** Lebar kolom satu code point: 0, 1, atau
|
|
76
|
+
/** Lebar kolom satu code point: 0, 1, 2, atau 8 (tab). */
|
|
77
77
|
export function charWidth(cp: number): number {
|
|
78
78
|
if (cp === 0) return 0
|
|
79
|
+
// Tab dirender terminal sebagai lompatan ke stop berikutnya (kelipatan 8).
|
|
80
|
+
// Tanpa posisi kolom, hitung 8 = batas atas: tak pernah undercount (arah
|
|
81
|
+
// aman — overcount hanya wrap lebih awal, undercount merusak frame/popup).
|
|
82
|
+
// sanitizeAnsi SENGAJA mempertahankan tab agar isi (indentasi kode) utuh.
|
|
83
|
+
if (cp === 0x09) return 8
|
|
79
84
|
// C0/C1 control: tidak menempati kolom (dan seharusnya tidak sampai ke layar).
|
|
80
85
|
if (cp < 0x20 || (cp >= 0x7f && cp < 0xa0)) return 0
|
|
81
86
|
if (inRanges(cp, ZERO)) return 0
|
|
@@ -117,6 +122,40 @@ function csiByteKind(b: number): "param" | "inter" | "final" | "other" {
|
|
|
117
122
|
return "other"
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
/** Parameter SGR yang menutup gaya (reset/off) — arah aman saat pecah chunk. */
|
|
126
|
+
const SGR_OFF = new Set(["0", "22", "23", "24", "25", "27", "28", "29", "39", "49"])
|
|
127
|
+
|
|
128
|
+
/** True bila sekuens escape utuh adalah SGR pewarnaan (satu-satunya yang boleh lewat). */
|
|
129
|
+
function isSgrSeq(seq: string): boolean {
|
|
130
|
+
if (!seq.startsWith("\x1b[") || !seq.endsWith("m")) return false
|
|
131
|
+
const params = seq.slice(2, -1)
|
|
132
|
+
if (params === "") return true
|
|
133
|
+
return params.split(/[:;]/).every((p) => p === "" || /^[0-9]+$/.test(p))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** True bila string berakhir dengan gaya SGR masih terbuka (butuh reset). */
|
|
137
|
+
function sgrLeftOpen(s: string): boolean {
|
|
138
|
+
let open = false
|
|
139
|
+
let i = 0
|
|
140
|
+
while (i < s.length) {
|
|
141
|
+
if (s[i] === "\x1b") {
|
|
142
|
+
const len = escapeLength(s, i)
|
|
143
|
+
if (len > 0) {
|
|
144
|
+
const seq = s.slice(i, i + len)
|
|
145
|
+
if (isSgrSeq(seq)) {
|
|
146
|
+
const params = seq.slice(2, -1).split(/[:;]/)
|
|
147
|
+
if (params.some((p) => SGR_OFF.has(p) || p === "")) open = false
|
|
148
|
+
else if (params.some((p) => p !== "")) open = true
|
|
149
|
+
}
|
|
150
|
+
i += len
|
|
151
|
+
continue
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const cp = s.codePointAt(i)!
|
|
155
|
+
i += cp > 0xffff ? 2 : 1
|
|
156
|
+
}
|
|
157
|
+
return open
|
|
158
|
+
}
|
|
120
159
|
/** Panjang sekuens escape yang mulai di `i`, atau 0 bila bukan escape. */
|
|
121
160
|
export function escapeLength(s: string, i: number): number {
|
|
122
161
|
if (s[i] !== "\x1b") return 0
|
|
@@ -162,6 +201,21 @@ export function escapeLength(s: string, i: number): number {
|
|
|
162
201
|
return code >= 0x30 && code <= 0x7e ? 2 : 1
|
|
163
202
|
}
|
|
164
203
|
|
|
204
|
+
/** True bila string memuat escape non-SGR (atau ESC liar) yang wajib dibuang. */
|
|
205
|
+
function hasNonSgrEscape(s: string): boolean {
|
|
206
|
+
let i = 0
|
|
207
|
+
while (i < s.length) {
|
|
208
|
+
if (s[i] === "\x1b") {
|
|
209
|
+
const len = escapeLength(s, i)
|
|
210
|
+
if (len <= 0 || !isSgrSeq(s.slice(i, i + len))) return true
|
|
211
|
+
i += len
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
const cp = s.codePointAt(i)!
|
|
215
|
+
i += cp > 0xffff ? 2 : 1
|
|
216
|
+
}
|
|
217
|
+
return false
|
|
218
|
+
}
|
|
165
219
|
/**
|
|
166
220
|
* Potong string ke `width` KOLOM (bukan jumlah karakter), pertahankan sekuens
|
|
167
221
|
* ANSI utuh, dan tutup atribut yang masih terbuka. Tidak pernah membelah
|
|
@@ -169,19 +223,34 @@ export function escapeLength(s: string, i: number): number {
|
|
|
169
223
|
*/
|
|
170
224
|
export function truncateToWidth(s: string, width: number, ellipsis = "..."): string {
|
|
171
225
|
if (width <= 0) return ""
|
|
172
|
-
|
|
226
|
+
// Muat tanpa potong DAN tanpa escape asing: tetap tutup SGR yang terbuka
|
|
227
|
+
// agar tak bleed ke chrome berikut (dulu early-return membocorkan warna).
|
|
228
|
+
// Bila ada non-SGR, jatuh ke loop filter di bawah (tanpa ellipsis bila
|
|
229
|
+
// akhirnya tak ada yang dipotong).
|
|
230
|
+
if (displayWidth(s) <= width && !hasNonSgrEscape(s)) {
|
|
231
|
+
return sgrLeftOpen(s) ? `${s}\x1b[0m` : s
|
|
232
|
+
}
|
|
173
233
|
|
|
174
234
|
const ellW = displayWidth(ellipsis)
|
|
175
235
|
const budget = width > ellW ? width - ellW : width
|
|
176
236
|
let out = ""
|
|
177
237
|
let w = 0
|
|
178
238
|
let sawSgr = false
|
|
239
|
+
let cut = false
|
|
179
240
|
let i = 0
|
|
180
241
|
while (i < s.length) {
|
|
181
242
|
if (s[i] === "\x1b") {
|
|
182
243
|
const len = escapeLength(s, i)
|
|
183
244
|
if (len > 0) {
|
|
184
245
|
const seq = s.slice(i, i + len)
|
|
246
|
+
// Hanya SGR yang disalin — sekuens kontrol lain (clear, alternate
|
|
247
|
+
// screen, OSC) DIBUANG di sini agar satu pemanggil yang lupa sanitasi
|
|
248
|
+
// tidak menjadi injeksi terminal (defense-in-depth, bukan pengganti
|
|
249
|
+
// sanitizeAnsi di batas input tak-terpercaya).
|
|
250
|
+
if (!isSgrSeq(seq)) {
|
|
251
|
+
i += len
|
|
252
|
+
continue
|
|
253
|
+
}
|
|
185
254
|
if (seq.endsWith("m")) sawSgr = true
|
|
186
255
|
out += seq
|
|
187
256
|
i += len
|
|
@@ -190,13 +259,16 @@ export function truncateToWidth(s: string, width: number, ellipsis = "..."): str
|
|
|
190
259
|
}
|
|
191
260
|
const cp = s.codePointAt(i)!
|
|
192
261
|
const cw = charWidth(cp)
|
|
193
|
-
if (w + cw > budget)
|
|
262
|
+
if (w + cw > budget) {
|
|
263
|
+
cut = true
|
|
264
|
+
break
|
|
265
|
+
}
|
|
194
266
|
const size = cp > 0xffff ? 2 : 1
|
|
195
267
|
out += s.slice(i, i + size)
|
|
196
268
|
w += cw
|
|
197
269
|
i += size
|
|
198
270
|
}
|
|
199
|
-
const tail = width > ellW ? ellipsis : ""
|
|
271
|
+
const tail = cut && width > ellW ? ellipsis : ""
|
|
200
272
|
return sawSgr ? `${out}\x1b[0m${tail}` : out + tail
|
|
201
273
|
}
|
|
202
274
|
|
|
@@ -214,7 +286,7 @@ export function padToWidth(s: string, width: number, align: "left" | "right" = "
|
|
|
214
286
|
* dipecah di batas kata.
|
|
215
287
|
*/
|
|
216
288
|
export function chunkByWidth(s: string, width: number): string[] {
|
|
217
|
-
if (width <= 0) return [
|
|
289
|
+
if (width <= 0) return [""]
|
|
218
290
|
const out: string[] = []
|
|
219
291
|
let cur = ""
|
|
220
292
|
let w = 0
|
|
@@ -225,13 +297,22 @@ export function chunkByWidth(s: string, width: number): string[] {
|
|
|
225
297
|
// DAN merah ke potongan berikut. Reset/off (0, 22–29, 39, 49) mengosongkan
|
|
226
298
|
// tumpukan — arah aman: potongan berikut mulai tanpa gaya daripada dengan
|
|
227
299
|
// gaya basi yang salah.
|
|
228
|
-
|
|
300
|
+
// Non-SGR DIBUANG seperti truncateToWidth (defense-in-depth yang sama).
|
|
229
301
|
let openSgr: string[] = []
|
|
302
|
+
const pushChunk = (): void => {
|
|
303
|
+
out.push(openSgr.length > 0 ? `${cur}\x1b[0m` : cur)
|
|
304
|
+
cur = openSgr.join("") // lanjutkan warna ke potongan berikutnya
|
|
305
|
+
w = 0
|
|
306
|
+
}
|
|
230
307
|
while (i < s.length) {
|
|
231
308
|
if (s[i] === "\x1b") {
|
|
232
309
|
const len = escapeLength(s, i)
|
|
233
310
|
if (len > 0) {
|
|
234
311
|
const seq = s.slice(i, i + len)
|
|
312
|
+
if (!isSgrSeq(seq)) {
|
|
313
|
+
i += len
|
|
314
|
+
continue
|
|
315
|
+
}
|
|
235
316
|
if (seq.endsWith("m")) {
|
|
236
317
|
const params = seq.slice(2, -1).split(/[:;]/)
|
|
237
318
|
if (params.some((p) => SGR_OFF.has(p) || p === "")) openSgr = []
|
|
@@ -251,14 +332,12 @@ export function chunkByWidth(s: string, width: number): string[] {
|
|
|
251
332
|
const cw = charWidth(cp)
|
|
252
333
|
const size = cp > 0xffff ? 2 : 1
|
|
253
334
|
if (w + cw > width && cur !== "") {
|
|
254
|
-
|
|
255
|
-
cur = openSgr.join("") // lanjutkan warna ke potongan berikutnya
|
|
256
|
-
w = 0
|
|
335
|
+
pushChunk()
|
|
257
336
|
}
|
|
258
337
|
cur += s.slice(i, i + size)
|
|
259
338
|
w += cw
|
|
260
339
|
i += size
|
|
261
340
|
}
|
|
262
|
-
if (cur !== "")
|
|
341
|
+
if (cur !== "") pushChunk()
|
|
263
342
|
return out.length ? out : [""]
|
|
264
343
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Preferensi gerak (temuan audit TUI-006): status busy tidak boleh bergantung
|
|
2
|
+
// pada animasi. MINICODE_MOTION=0 mematikan pulse spark dsb. — pola lazy env
|
|
3
|
+
// yang sama dengan theme.ts (dibaca saat DIPAKAI, bukan dibekukan saat import,
|
|
4
|
+
// agar env runtime & test tetap berpengaruh).
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* True bila animasi/transisi visual harus dimatikan.
|
|
8
|
+
*
|
|
9
|
+
* Semantik nilai eksplisit (audit minor 2026-09-23): "0"/"false"/"off"/"no" = matikan;
|
|
10
|
+
* kosong/undefined/"1" = animasi hidup. Nilai tak dikenal (mis. "banana")
|
|
11
|
+
* TIDAK diam-diam mengubah perilaku (fail-closed ke default hidup).
|
|
12
|
+
*/
|
|
13
|
+
export function motionReduced(): boolean {
|
|
14
|
+
const v = (process.env.MINICODE_MOTION ?? "").trim().toLowerCase()
|
|
15
|
+
return v === "0" || v === "false" || v === "off" || v === "no"
|
|
16
|
+
}
|
package/src/ui/runtime/screen.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// try { ... screen.paint(frame) ... } finally { screen.close() }
|
|
10
10
|
// Refcount menutup modal nested (effort-picker di dalam manager): tulis
|
|
11
11
|
// enter/exit fisik hanya di lapis terluar; handle dalam = no-op paint-through.
|
|
12
|
+
import { __resetTransientForTest, beginInteractiveScreen } from "./statusline.ts"
|
|
13
|
+
|
|
12
14
|
const ENTER = "\x1b[?1049h"
|
|
13
15
|
const EXIT = "\x1b[?1049l"
|
|
14
16
|
const HOME = "\x1b[H"
|
|
@@ -21,6 +23,10 @@ const CLEAR_ALL = "\x1b[2J"
|
|
|
21
23
|
const RESET_REGION = "\x1b[r"
|
|
22
24
|
const SYNC_START = "\x1b[?2026h"
|
|
23
25
|
const SYNC_END = "\x1b[?2026l"
|
|
26
|
+
/** Ekspor untuk pemanggil yang melukis kursor di luar paint() (app.ts) —
|
|
27
|
+
* kursor WAJIB di dalam blok sync yang sama dengan framenya (TUI-007). */
|
|
28
|
+
export const SYNC_UPDATE_START = SYNC_START
|
|
29
|
+
export const SYNC_UPDATE_END = SYNC_END
|
|
24
30
|
|
|
25
31
|
let depth = 0
|
|
26
32
|
let exitHookInstalled = false
|
|
@@ -30,6 +36,9 @@ function installExitHook(): void {
|
|
|
30
36
|
exitHookInstalled = true
|
|
31
37
|
// Jaring terakhir (best-effort, sinkron): modal yatim mengunci layar di
|
|
32
38
|
// buffer alt. `kill -9` tak tercakup — ketik `reset` (residual kontrak).
|
|
39
|
+
// CATATAN TUI-001: handler `exit` Node TIDAK jalan pada SIGTERM/SIGHUP
|
|
40
|
+
// default — restore pada sinyal fatal adalah tanggung jawab pemilik sesi
|
|
41
|
+
// interaktif (TuiApp) yang memasang handler sinyalnya sendiri per-run.
|
|
33
42
|
process.on("exit", () => {
|
|
34
43
|
if (depth > 0) {
|
|
35
44
|
try {
|
|
@@ -97,6 +106,13 @@ export function openAltScreen(): AltScreen {
|
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
108
|
depth++
|
|
109
|
+
// Layar memegang terminal: tahan SEMUA painter transient stderr (spinner
|
|
110
|
+
// "Menyiapkan sesi…", garis status turn) selama alt-screen hidup — satu tick
|
|
111
|
+
// `\r\x1b[2K` dari stderr menghapus baris prompt wizard sehingga user baru
|
|
112
|
+
// melihat CLI "macet". Release idempoten per handle (nested dihitung);
|
|
113
|
+
// ditahan juga untuk lapisan nested supaya close dalam tak membocorkan
|
|
114
|
+
// painter ke tengah dialog luar.
|
|
115
|
+
const releaseHold = beginInteractiveScreen()
|
|
100
116
|
// Region terakhir handle ini (siklus hidup popup komposit) — per-handle
|
|
101
117
|
// (closure), bukan global: popup nested (effort di dalam manager) melacak
|
|
102
118
|
// areanya masing-masing.
|
|
@@ -169,6 +185,9 @@ export function openAltScreen(): AltScreen {
|
|
|
169
185
|
if (closed) return
|
|
170
186
|
closed = true
|
|
171
187
|
lastRegion = null
|
|
188
|
+
try {
|
|
189
|
+
releaseHold()
|
|
190
|
+
} catch {}
|
|
172
191
|
depth = Math.max(0, depth - 1)
|
|
173
192
|
if (depth === 0) {
|
|
174
193
|
try {
|
|
@@ -187,6 +206,21 @@ export function altScreenDepth(): number {
|
|
|
187
206
|
return depth
|
|
188
207
|
}
|
|
189
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Tulis exit-sequence alt-screen SEKARANG (dipanggil handler sinyal TuiApp
|
|
211
|
+
* sebelum process.exit): jaring restore saat SIGTERM/SIGHUP — handler `exit`
|
|
212
|
+
* Node TIDAK jalan pada sinyal fatal default.
|
|
213
|
+
*/
|
|
214
|
+
export function forceRestoreScreenForSignal(): void {
|
|
215
|
+
if (depth > 0) {
|
|
216
|
+
try {
|
|
217
|
+
process.stdout.write(EXIT)
|
|
218
|
+
process.stdout.write(RESET_REGION)
|
|
219
|
+
} catch {}
|
|
220
|
+
depth = 0
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
190
224
|
/**
|
|
191
225
|
* Reset kedalaman (HANYA untuk isolasi test antar-file): view yang gagal
|
|
192
226
|
* di tengah test bisa meninggalkan depth > 0 sehingga file test berikutnya
|
|
@@ -194,4 +228,15 @@ export function altScreenDepth(): number {
|
|
|
194
228
|
*/
|
|
195
229
|
export function resetAltScreenDepth(): void {
|
|
196
230
|
depth = 0
|
|
231
|
+
resetInteractiveScreenHoldForTest()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Reset hold transient alternatif (HANYA untuk isolasi test antar-file):
|
|
236
|
+
* view yang gagal sebelum `close()` bisa meninggalkan
|
|
237
|
+
* `beginInteractiveScreen` > 0 sehingga painter file test berikutnya tetap
|
|
238
|
+
* dibisukan.
|
|
239
|
+
*/
|
|
240
|
+
function resetInteractiveScreenHoldForTest(): void {
|
|
241
|
+
__resetTransientForTest()
|
|
197
242
|
}
|
|
@@ -14,34 +14,71 @@ export interface Spinner {
|
|
|
14
14
|
error: (message: string) => void
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export interface SpinnerOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Tunda frame pertama (ms). Dipakai fase startup yang sering selesai <200ms
|
|
20
|
+
* (cek update) — tanpa delay, spinner berkedip lalu hilang. 0 = langsung.
|
|
21
|
+
*/
|
|
22
|
+
delayMs?: number
|
|
23
|
+
/** Interval antar frame (default 120ms). */
|
|
24
|
+
intervalMs?: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createSpinner(initialMessage: string = "", opts: SpinnerOptions = {}): Spinner {
|
|
18
28
|
const isTTY = process.stderr.isTTY
|
|
29
|
+
const intervalMs = opts.intervalMs ?? 120
|
|
30
|
+
const delayMs = opts.delayMs ?? 0
|
|
19
31
|
// Pesan spinner bisa datang dari hasil tool yang tidak terpercaya — SGR boleh
|
|
20
32
|
// lewat, sekuens lain (mis. \x1b[2J) dibuang agar tidak merusak layar.
|
|
21
33
|
let message = sanitizeAnsiLine(initialMessage)
|
|
22
34
|
let frameIdx = 0
|
|
23
35
|
let intervalId: ReturnType<typeof setInterval> | undefined
|
|
36
|
+
let delayTimer: ReturnType<typeof setTimeout> | undefined
|
|
24
37
|
// Kepemilikan transient stderr selama animasi — mutual exclusion dengan
|
|
25
38
|
// garis status turn di-enforce statusline.ts (warning overlap, bukan crash).
|
|
26
39
|
let owned: { release(): void } | null = null
|
|
40
|
+
// Sudah pernah menulis frame? Determinan apakah stop() boleh menulis
|
|
41
|
+
// pembersih `\r\x1b[K` — spinner yang belum sempat melukis (masih dalam
|
|
42
|
+
// delay) tidak boleh menghapus baris milik penulis lain.
|
|
43
|
+
let painted = false
|
|
44
|
+
let stopped = false
|
|
27
45
|
|
|
28
46
|
const frames = glyphs.spinnerFrames
|
|
29
47
|
|
|
30
48
|
const tick = () => {
|
|
31
49
|
const frame = c.info(frames[frameIdx % frames.length]!)
|
|
32
50
|
frameIdx++
|
|
51
|
+
painted = true
|
|
33
52
|
paintWrite(`\r${frame} ${message}\x1b[K`)
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
|
|
55
|
+
// `withDelay` hanya untuk frame PERTAMA (delay gagal-berkedip fase startup);
|
|
56
|
+
// frame lanjutan/delay kedua akan membuat spinner tak pernah muncul.
|
|
57
|
+
const startPaint = (withDelay = false) => {
|
|
58
|
+
if (!isTTY || stopped || intervalId || delayTimer) return
|
|
59
|
+
if (withDelay && delayMs > 0) {
|
|
60
|
+
delayTimer = setTimeout(() => {
|
|
61
|
+
delayTimer = undefined
|
|
62
|
+
startPaint()
|
|
63
|
+
}, delayMs)
|
|
64
|
+
// Jangan tahan process hidup hanya karena delay tampil.
|
|
65
|
+
try {
|
|
66
|
+
;(delayTimer as unknown as { unref?: () => void }).unref?.()
|
|
67
|
+
} catch {}
|
|
68
|
+
return
|
|
69
|
+
}
|
|
37
70
|
// Hide cursor during spin
|
|
38
71
|
paintWrite("\x1b[?25l")
|
|
39
72
|
owned = acquireTransientPaint("spinner", tick)
|
|
40
73
|
tick()
|
|
41
|
-
intervalId = setInterval(tick,
|
|
74
|
+
intervalId = setInterval(tick, intervalMs)
|
|
42
75
|
}
|
|
43
76
|
|
|
44
77
|
const stopTimer = () => {
|
|
78
|
+
if (delayTimer) {
|
|
79
|
+
clearTimeout(delayTimer)
|
|
80
|
+
delayTimer = undefined
|
|
81
|
+
}
|
|
45
82
|
if (owned) {
|
|
46
83
|
owned.release()
|
|
47
84
|
owned = null
|
|
@@ -50,26 +87,35 @@ export function createSpinner(initialMessage: string = ""): Spinner {
|
|
|
50
87
|
clearInterval(intervalId)
|
|
51
88
|
intervalId = undefined
|
|
52
89
|
}
|
|
53
|
-
if (isTTY) {
|
|
90
|
+
if (isTTY && painted) {
|
|
54
91
|
paintWrite("\r\x1b[K\x1b[?25h")
|
|
55
92
|
}
|
|
93
|
+
painted = false
|
|
56
94
|
}
|
|
57
95
|
|
|
96
|
+
startPaint(delayMs > 0)
|
|
97
|
+
|
|
58
98
|
return {
|
|
59
99
|
update(newMessage: string) {
|
|
60
100
|
message = sanitizeAnsiLine(newMessage)
|
|
61
101
|
},
|
|
62
102
|
stop(finalMessage?: string) {
|
|
103
|
+
if (stopped) return
|
|
104
|
+
stopped = true
|
|
63
105
|
stopTimer()
|
|
64
106
|
if (finalMessage) {
|
|
65
107
|
process.stderr.write(`${sanitizeAnsiLine(finalMessage)}\n`)
|
|
66
108
|
}
|
|
67
109
|
},
|
|
68
110
|
success(msg: string) {
|
|
111
|
+
if (stopped) return
|
|
112
|
+
stopped = true
|
|
69
113
|
stopTimer()
|
|
70
114
|
process.stderr.write(`${c.green(glyphs.check)} ${sanitizeAnsiLine(msg)}\n`)
|
|
71
115
|
},
|
|
72
116
|
error(msg: string) {
|
|
117
|
+
if (stopped) return
|
|
118
|
+
stopped = true
|
|
73
119
|
stopTimer()
|
|
74
120
|
process.stderr.write(`${c.red(glyphs.cross)} ${sanitizeAnsiLine(msg)}\n`)
|
|
75
121
|
},
|
|
@@ -71,6 +71,8 @@ export function __resetTransientForTest(): void {
|
|
|
71
71
|
ourWrite = null
|
|
72
72
|
origWrite = null
|
|
73
73
|
transientBroken = false
|
|
74
|
+
warnedOverlap.clear()
|
|
75
|
+
screenDepth = 0
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
// Pasang wrapper stderr HANYA bila owner transient pertama muncul. Wrapper
|
|
@@ -129,9 +131,56 @@ function ensureWrap(): void {
|
|
|
129
131
|
process.stderr.write = ourWrite
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
// ── Kepemilikan layar interaktif (raw-mode) ──
|
|
135
|
+
// Picker/askLine/askSecret memegang raw mode DAN melukis overlay-nya di stdout
|
|
136
|
+
// dengan cursor addressing. Selama itu painter transient stderr (garis status
|
|
137
|
+
// turn, spinner setup) TIDAK boleh menulis satu byte pun: satu tick
|
|
138
|
+
// `\r\x1b[2K` dari stderr menghapus baris tempat layar baru menulis prompt —
|
|
139
|
+
// di Windows bahkan menghapus sebagian overlay. Tanpa aturan ini wizard setup
|
|
140
|
+
// pertama (picker gateway + prompt API key) tak terlihat, dan CLI tampak macet
|
|
141
|
+
// di `Menyiapkan sesi…` padahal sedang menunggu input user.
|
|
142
|
+
//
|
|
143
|
+
// Ditegakkan di SATU tempat (paintWrite) supaya SETIAP painter patuh tanpa
|
|
144
|
+
// harus tahu soal layar — termasuk painter baru di masa depan.
|
|
145
|
+
let screenDepth = 0
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Tandai layar raw-mode mengambil alih terminal. Kembalikan fungsi release
|
|
149
|
+
* IDEMPOTEN — panggil di cleanup SEMUA jalur (sukses, batal, error, timeout).
|
|
150
|
+
*
|
|
151
|
+
* Nesting aman (depth dihitung): picker yang dibuka dari dalam manager hanya
|
|
152
|
+
* melepas kepemilikannya sendiri saat selesai.
|
|
153
|
+
*
|
|
154
|
+
* CATATAN mode TUI: tidak ada auto-suspend di sini — alur interaktif mode
|
|
155
|
+
* TUI (approval/select/ask) diimplementasi in-flow di dalam alt-screen
|
|
156
|
+
* (lihat src/ui/tui/), dan alur cetak lewat capture driver. Layar linier
|
|
157
|
+
* (askLine/picker) hanya berjalan di buffer utama: setup wizard,
|
|
158
|
+
* subcommand TTY, dan suspend yang sudah dihapus bersama driver linier.
|
|
159
|
+
*/
|
|
160
|
+
export function beginInteractiveScreen(): () => void {
|
|
161
|
+
// Baris painter terakhir dibersihkan SEKARANG (kursor masih persis di sana),
|
|
162
|
+
// sebelum layar menulis byte pertamanya — dan SEBELUM depth naik, karena
|
|
163
|
+
// paintWrite menolak menulis saat layar sudah aktif. Tanpa ini teks spinner
|
|
164
|
+
// basi tertinggal tepat di atas overlay layar. Kursor juga dikembalikan:
|
|
165
|
+
// painter menyembunyikannya selama melukis, sedangkan prompt butuh kursor
|
|
166
|
+
// terlihat saat user mengetik.
|
|
167
|
+
if (screenDepth === 0 && owner) {
|
|
168
|
+
try {
|
|
169
|
+
paintWrite("\r\x1b[2K\x1b[?25h")
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
172
|
+
screenDepth++
|
|
173
|
+
let released = false
|
|
174
|
+
return () => {
|
|
175
|
+
if (released) return
|
|
176
|
+
released = true
|
|
177
|
+
screenDepth = Math.max(0, screenDepth - 1)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
132
181
|
/** Tulis internal milik painter aktif (tanpa aturan "asing" di atas). */
|
|
133
182
|
export function paintWrite(s: string): void {
|
|
134
|
-
if (transientBroken) return
|
|
183
|
+
if (transientBroken || screenDepth > 0) return
|
|
135
184
|
ownerWriting = true
|
|
136
185
|
try {
|
|
137
186
|
// Pakai sink yang MASIH terpasang: bila wrapper sudah diganti/di-restore
|
package/src/ui/screens/form.ts
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
22
22
|
import { c, stripAnsi } from "../render/theme.ts"
|
|
23
23
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
24
|
-
import type
|
|
24
|
+
import { type AltScreen, SYNC_UPDATE_END, SYNC_UPDATE_START } from "../runtime/screen.ts"
|
|
25
25
|
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
26
26
|
|
|
27
27
|
export interface FormField {
|
|
@@ -76,8 +76,7 @@ interface FieldState {
|
|
|
76
76
|
viewStart: number
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const
|
|
80
|
-
const RESTORE = "\x1b[22m"
|
|
79
|
+
const dim = (s: string): string => c.dim(s)
|
|
81
80
|
|
|
82
81
|
/** Lebar kotak form TETAP (keputusan rasa: geometri stabil). */
|
|
83
82
|
const FORM_BOX_W = 64
|
|
@@ -140,6 +139,14 @@ function sliceByWidth(pts: string[], start: number, maxV: number): string[] {
|
|
|
140
139
|
return out
|
|
141
140
|
}
|
|
142
141
|
|
|
142
|
+
// Jeda sebelum peringatan idle & jeda peringatan → batal (temuan audit
|
|
143
|
+
// TUI-004): raw-mode digenggam tanpa input rawan macet saat ConPTY mati,
|
|
144
|
+
// tapi batal diam-diam membuang draft yang sudah diketik. Dua-tahap: 80 dtk
|
|
145
|
+
// diam → peringatan di footer kotak; 10 dtk lagi tanpa keypress → batal.
|
|
146
|
+
// TOTAL tetap 90 dtk (semantik anti-hang dipertahankan).
|
|
147
|
+
export const IDLE_WARN_MS = 80_000
|
|
148
|
+
export const IDLE_CANCEL_MS = 10_000
|
|
149
|
+
|
|
143
150
|
export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormResult> {
|
|
144
151
|
if (!spec.fields.length) return { cancelled: true }
|
|
145
152
|
return new Promise<FormResult>((resolve) => {
|
|
@@ -147,6 +154,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
147
154
|
let idx = 0
|
|
148
155
|
let done = false
|
|
149
156
|
let idleTimer: ReturnType<typeof setTimeout> | undefined
|
|
157
|
+
let idleWarned = false
|
|
150
158
|
const clearIdle = () => {
|
|
151
159
|
if (idleTimer) clearTimeout(idleTimer)
|
|
152
160
|
idleTimer = undefined
|
|
@@ -154,7 +162,17 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
154
162
|
const resetIdle = () => {
|
|
155
163
|
if (done) return
|
|
156
164
|
clearIdle()
|
|
157
|
-
|
|
165
|
+
idleWarned = false
|
|
166
|
+
idleTimer = setTimeout(() => {
|
|
167
|
+
// Tahap 1: peringatan (draft TIDAK dibuang — render footer merah).
|
|
168
|
+
idleWarned = true
|
|
169
|
+
render()
|
|
170
|
+
// Tahap 2: batal — hanya bila tetap hening.
|
|
171
|
+
idleTimer = setTimeout(() => finish(true), IDLE_CANCEL_MS)
|
|
172
|
+
try {
|
|
173
|
+
;(idleTimer as unknown as { unref?: () => void }).unref?.()
|
|
174
|
+
} catch {}
|
|
175
|
+
}, IDLE_WARN_MS)
|
|
158
176
|
try {
|
|
159
177
|
;(idleTimer as unknown as { unref?: () => void }).unref?.()
|
|
160
178
|
} catch {}
|
|
@@ -204,9 +222,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
204
222
|
const marker = active ? c.accent("›") : " "
|
|
205
223
|
if (active) activeCol = -1 // select tanpa kursor ketik
|
|
206
224
|
body.push(
|
|
207
|
-
cut(
|
|
208
|
-
`${marker} ${sanitizeAnsiLine(st.def.label)}: ${DIM}‹${RESTORE} ${cur} ${DIM}›${RESTORE}`,
|
|
209
|
-
),
|
|
225
|
+
cut(`${marker} ${sanitizeAnsiLine(st.def.label)}: ${dim("‹")} ${cur} ${dim("›")}`),
|
|
210
226
|
)
|
|
211
227
|
activeRow = active ? body.length - 1 : activeRow
|
|
212
228
|
} else {
|
|
@@ -223,7 +239,12 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
223
239
|
{
|
|
224
240
|
title: spec.title,
|
|
225
241
|
body,
|
|
226
|
-
|
|
242
|
+
// Peringatan idle (TUI-004): footer berubah merah 10 dtk sebelum
|
|
243
|
+
// batal sendiri — user tahu kenapa dan bisa mencegah (tekan apa
|
|
244
|
+
// saja), draft tidak hilang tanpa jejak.
|
|
245
|
+
footer: idleWarned
|
|
246
|
+
? c.error(t("form.idleWarning", { s: Math.ceil(IDLE_CANCEL_MS / 1000) }))
|
|
247
|
+
: (spec.footer ?? t("form.footerDefault")),
|
|
227
248
|
// Lebar TETAP (paritas picker/manager — geometri stabil, tak
|
|
228
249
|
// bernapas saat error muncul/hilang).
|
|
229
250
|
minWidth: FORM_BOX_W,
|
|
@@ -246,7 +267,10 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
246
267
|
const contentW = displayWidth(stripped) - leftPad
|
|
247
268
|
const raw = activeCol >= 0 ? leftPad + activeCol + 2 : leftPad + contentW + 1
|
|
248
269
|
const col = Math.max(1, Math.min(screen.cols || 80, raw))
|
|
249
|
-
|
|
270
|
+
// Di dalam blok sync-update yang SAMA dengan paintRegion di atas
|
|
271
|
+
// (temuan audit TUI-007): kursor yang muncul di luar sync berpotensi
|
|
272
|
+
// tearing di emulator tanpa ?2026.
|
|
273
|
+
process.stdout.write(`${SYNC_UPDATE_START}\x1b[${row};${col}H\x1b[?25h${SYNC_UPDATE_END}`)
|
|
250
274
|
}
|
|
251
275
|
} catch {}
|
|
252
276
|
return { activeRow, activeCol }
|
|
@@ -334,14 +358,17 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
334
358
|
const st = fields[idx]!
|
|
335
359
|
for (const d of keys) {
|
|
336
360
|
const k = d.key
|
|
337
|
-
// Esc/Ctrl+C dua-tahap (anti-hilang draft): field
|
|
338
|
-
//
|
|
339
|
-
//
|
|
361
|
+
// Esc/Ctrl+C dua-tahap (anti-hilang draft): field kotor → kembalikan
|
|
362
|
+
// ke nilai bawaan (prefill edit tak hilang sekali tekan — dulu
|
|
363
|
+
// langsung dikosongkan tanpa undo); sudah bawaan/kosong → batal
|
|
364
|
+
// total. Ctrl+D = batal langsung (konvensi EOF, tidak dipakai
|
|
365
|
+
// menghapus).
|
|
340
366
|
if (k.type === "esc" || k.type === "ctrl-c") {
|
|
341
367
|
const cur = fields[idx]!
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
cur.
|
|
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
|
|
345
372
|
cur.viewStart = 0
|
|
346
373
|
cur.error = null
|
|
347
374
|
render()
|