minicode-ai 0.22.0 → 0.25.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 +2 -2
- package/cli/commands.ts +10 -0
- package/cli/index.ts +11 -0
- package/cli/setup.ts +64 -33
- package/cli/tui.ts +29 -3
- package/docs/README.md +2 -2
- package/docs/SUMMARY.md +10 -19
- package/docs/TERMINAL_CONTRACT.md +119 -32
- package/docs/architecture.md +1 -1
- package/docs/autonomous-scheduler.md +283 -2
- package/docs/choosing-mode.md +4 -4
- package/docs/concepts.md +39 -3
- package/docs/config.md +90 -4
- package/docs/environment.md +6 -0
- package/docs/getting-started.md +58 -2
- package/docs/repl.md +1 -1
- package/docs/security.md +49 -2
- package/docs/tools.md +2 -1
- package/package.json +2 -36
- package/src/app/provider-layer.ts +1 -1
- package/src/app/session.ts +129 -20
- package/src/config.ts +102 -2
- package/src/constants.ts +32 -4
- package/src/lib/safe-open.ts +21 -12
- package/src/memory/vector.ts +0 -31
- package/src/policy/compaction.ts +27 -0
- package/src/policy/context-budget.ts +132 -0
- package/src/policy/context-escalation.ts +140 -0
- package/src/policy/context-window.ts +14 -9
- package/src/policy/context.ts +10 -1
- package/src/policy/microcompact.ts +162 -0
- package/src/policy/no-progress.ts +1 -1
- package/src/policy/permission.ts +5 -0
- package/src/policy/scrub.ts +15 -2
- package/src/policy/tool-contract.ts +11 -9
- package/src/presentation/reducer.ts +1 -0
- package/src/providers/anthropic.ts +17 -3
- package/src/providers/detect.ts +155 -13
- package/src/providers/provision.ts +92 -1
- package/src/providers/responses.ts +13 -1
- package/src/session/persistence.ts +56 -0
- package/src/task/autonomous-policy.ts +7 -0
- package/src/task/graph-validate.ts +1 -1
- package/src/task/session-authority.ts +0 -5
- package/src/task/store.ts +0 -4
- package/src/tools/ask_user.ts +14 -1
- package/src/tools/bash.ts +57 -9
- package/src/tools/context.ts +10 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +5 -4
- package/src/tools/git.ts +70 -12
- package/src/tools/glob.ts +13 -5
- package/src/tools/grep.ts +26 -10
- package/src/tools/index.ts +3 -2
- package/src/tools/lsp.ts +15 -9
- package/src/tools/move_file.ts +4 -3
- package/src/tools/patch.ts +5 -4
- package/src/tools/read_file.ts +3 -2
- package/src/tools/read_image.ts +3 -2
- package/src/tools/task.ts +1 -0
- package/src/tools/todo.ts +4 -8
- package/src/tools/write_file.ts +4 -3
- package/src/ui/approval/prompt.ts +226 -77
- package/src/ui/assistant/simple.ts +1 -1
- package/src/ui/footer.ts +41 -29
- package/src/ui/i18n/en.ts +23 -4
- package/src/ui/i18n/id.ts +25 -4
- package/src/ui/input/input.ts +2 -2
- package/src/ui/render/activity-group.ts +1 -0
- package/src/ui/render/activity-panel.ts +21 -3
- package/src/ui/render/hint.ts +28 -0
- package/src/ui/render/ledger.ts +1 -9
- package/src/ui/render/logo.ts +86 -0
- package/src/ui/render/markdown-table.ts +0 -3
- package/src/ui/render/session-summary.ts +22 -1
- package/src/ui/render/table-grid.ts +0 -3
- package/src/ui/render/theme.ts +36 -5
- package/src/ui/runtime/screen.ts +11 -3
- package/src/ui/screens/dialog.ts +45 -81
- package/src/ui/screens/form.ts +29 -33
- package/src/ui/screens/lifecycle.ts +80 -0
- package/src/ui/screens/model-manager.ts +84 -91
- package/src/ui/screens/picker.ts +36 -33
- package/src/ui/screens/provider-manager.ts +50 -59
- package/src/ui/screens/watchdog.ts +27 -0
- package/src/ui/screens/wizard.ts +3 -20
- package/src/ui/tui/app.ts +97 -11
- package/src/ui/tui/transcript.ts +55 -16
- package/vendor/minicore/src/core/compact.ts +10 -0
- package/vendor/minicore/src/core/errors.ts +11 -1
- package/vendor/minicore/src/core/executor.ts +6 -1
- package/vendor/minicore/src/core/loop.ts +92 -2
- package/vendor/minicore/src/core/session.ts +8 -0
- package/vendor/minicore/src/providers/openai-compat.ts +15 -2
- package/docs/P14_OPEN_WORK.md +0 -290
- package/docs/config-providers.md +0 -87
- package/docs/glossary.md +0 -39
- package/docs/quickstart.md +0 -60
- package/docs/security-model.md +0 -96
- package/docs/terminal.md +0 -91
|
@@ -8,13 +8,16 @@ import {
|
|
|
8
8
|
type DecoderState,
|
|
9
9
|
toGraphemes,
|
|
10
10
|
} from "../input/prompt-engine.ts"
|
|
11
|
+
import { hintLine } from "../render/hint.ts"
|
|
11
12
|
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
13
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
13
14
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
14
15
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
15
|
-
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
16
|
+
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
16
17
|
import { runForm } from "./form.ts"
|
|
18
|
+
import { createIdleTimer } from "./lifecycle.ts"
|
|
17
19
|
import { runPicker } from "./picker.ts"
|
|
20
|
+
import { withTimeout } from "./watchdog.ts"
|
|
18
21
|
|
|
19
22
|
const dim = (s: string): string => c.dim(s)
|
|
20
23
|
|
|
@@ -56,10 +59,8 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
|
|
|
56
59
|
return rows.filter((r) => r.id.toLowerCase().includes(needle))
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
/** Lebar kotak
|
|
60
|
-
|
|
61
|
-
* maxWidth dialogBox — keduanya HARUS sepakat agar label tak terpotong ulang. */
|
|
62
|
-
const MODAL_BOX_W = 64
|
|
62
|
+
/** Lebar kotak /model: `popupBoxWidth` (AUD-006, satu sumber width+maxWidth). */
|
|
63
|
+
const modalBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
|
|
63
64
|
|
|
64
65
|
export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
|
|
65
66
|
let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
|
|
@@ -85,14 +86,18 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
85
86
|
return new Promise<void>((resolve) => {
|
|
86
87
|
const visibleRows = () => {
|
|
87
88
|
const rows = process.stdout.rows || 24
|
|
88
|
-
//
|
|
89
|
-
|
|
89
|
+
// Chrome tetap: 2 border + 1 baris pencarian + 1 baris hint aksi;
|
|
90
|
+
// struk notice (transient) menyusutkan daftar satu baris agar tak
|
|
91
|
+
// pernah menyingkirkan hint/marker "… more" (dialogBox memotong body
|
|
92
|
+
// dari atas). Semua angka pas dengan `room = rows − 2` di dialogBox.
|
|
93
|
+
const fixed = 4 + (notice ? 1 : 0)
|
|
94
|
+
return Math.max(1, Math.min(rows - fixed, 8))
|
|
90
95
|
}
|
|
91
96
|
// Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
|
|
92
97
|
// tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
|
|
93
98
|
// dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
|
|
94
99
|
// = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
|
|
95
|
-
const width = () => Math.max(8,
|
|
100
|
+
const width = () => Math.max(8, modalBoxWidth() - 4)
|
|
96
101
|
|
|
97
102
|
// Isi MINIMAL dialog /model (tanpa judul/footer/hitungan/penanda —
|
|
98
103
|
// seleksi murni warna). Search selalu tampil, daftar tanpa `›`.
|
|
@@ -125,18 +130,31 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
if (notice) lines.push(cut(dim(sanitizeAnsiLine(notice))))
|
|
133
|
+
// Hint aksi minimalis (kunci terang, label redup) — satu sumber dengan
|
|
134
|
+
// picker/form agar seluruh jendela /model konsisten. Sengaja TANPA
|
|
135
|
+
// judul/footer dekoratif (kontrak v7.8); ini baris body terakhir.
|
|
136
|
+
lines.push(
|
|
137
|
+
cut(
|
|
138
|
+
hintLine([
|
|
139
|
+
{ key: "↑↓", label: t("hint.move") },
|
|
140
|
+
{ key: "Enter", label: t("hint.select") },
|
|
141
|
+
{ key: "Tab", label: t("hint.effort") },
|
|
142
|
+
{ key: "Del", label: t("hint.delete") },
|
|
143
|
+
{ key: "Esc", label: t("hint.close") },
|
|
144
|
+
]),
|
|
145
|
+
),
|
|
146
|
+
)
|
|
128
147
|
return lines
|
|
129
148
|
}
|
|
130
149
|
|
|
131
150
|
const render = () => {
|
|
132
|
-
//
|
|
133
|
-
// App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
|
|
151
|
+
// Region kotak di atas transkrip; lebar beku (min=max).
|
|
134
152
|
const box = dialogBox(
|
|
135
153
|
{
|
|
136
154
|
title: "",
|
|
137
155
|
body: bodyLinesModal(),
|
|
138
|
-
minWidth:
|
|
139
|
-
maxWidth:
|
|
156
|
+
minWidth: modalBoxWidth(),
|
|
157
|
+
maxWidth: modalBoxWidth(),
|
|
140
158
|
maxHeight: 14,
|
|
141
159
|
},
|
|
142
160
|
screen.cols,
|
|
@@ -187,17 +205,15 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
187
205
|
// Manager ini sebelumnya TANPA idleTimer: bila stdin 'data' tak pernah
|
|
188
206
|
// datang (ConPTY macet/fokus hilang/busy bocor), Promise tak pernah settle
|
|
189
207
|
// dan raw-mode dipegang selamanya = "masuk list model macet". Samakan
|
|
190
|
-
// dengan picker: idle 90 dtk = batal otomatis.
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
// Didefinisikan di bawah (function hoisting via let) — dipanggil finish.
|
|
197
|
-
let resetIdle: () => void = () => {}
|
|
208
|
+
// dengan picker: idle 90 dtk = batal otomatis (helper bersama, audit D1).
|
|
209
|
+
// `finish` dirujuk sebagai closure — dievaluasi saat timer fire.
|
|
210
|
+
const idle = createIdleTimer({
|
|
211
|
+
cancelMs: 90_000,
|
|
212
|
+
onCancel: () => finish(),
|
|
213
|
+
})
|
|
198
214
|
|
|
199
215
|
const suspend = () => {
|
|
200
|
-
|
|
216
|
+
idle.clear()
|
|
201
217
|
attached = false
|
|
202
218
|
process.stdout.write("\x1b[0m\x1b[?25h")
|
|
203
219
|
// TANPA pause — stdin mengalir seumur proses (lihat cleanup askLine).
|
|
@@ -233,13 +249,13 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
233
249
|
attached = true
|
|
234
250
|
}
|
|
235
251
|
render()
|
|
236
|
-
|
|
252
|
+
idle.reset()
|
|
237
253
|
}
|
|
238
254
|
|
|
239
255
|
const finish = () => {
|
|
240
256
|
if (done) return
|
|
241
257
|
done = true
|
|
242
|
-
|
|
258
|
+
idle.dispose()
|
|
243
259
|
// Kembalikan batas listener warisan (lihat prevMaxListeners): warning
|
|
244
260
|
// MaxListenersExceeded kembali berguna setelah sesi ini selesai.
|
|
245
261
|
try {
|
|
@@ -266,18 +282,6 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
266
282
|
}
|
|
267
283
|
}
|
|
268
284
|
|
|
269
|
-
resetIdle = () => {
|
|
270
|
-
if (done) return
|
|
271
|
-
clearIdle()
|
|
272
|
-
idleTimer = setTimeout(() => {
|
|
273
|
-
finish()
|
|
274
|
-
}, 90_000)
|
|
275
|
-
// Jangan tahan process hidup hanya karena timer ini.
|
|
276
|
-
try {
|
|
277
|
-
;(idleTimer as unknown as { unref?: () => void }).unref?.()
|
|
278
|
-
} catch {}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
285
|
const runAction = (fn: () => Promise<void>) =>
|
|
282
286
|
(async () => {
|
|
283
287
|
if (busy) return
|
|
@@ -303,26 +307,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
303
307
|
* akhirnya selesai diabaikan hasilnya (tanpa resolve ganda — resolve
|
|
304
308
|
* hanya lewat finish alur normal). Bisa dioverride test via opts.
|
|
305
309
|
*/
|
|
306
|
-
const withWatchdog =
|
|
307
|
-
|
|
308
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
309
|
-
const p = Promise.resolve().then(fn)
|
|
310
|
-
// Rejection telat TANPA handler = unhandledRejection (bun: crash).
|
|
311
|
-
p.catch(() => {})
|
|
312
|
-
try {
|
|
313
|
-
return await Promise.race([
|
|
314
|
-
p,
|
|
315
|
-
new Promise<never>((_, reject) => {
|
|
316
|
-
timer = setTimeout(() => reject(new Error(t("ntc.timeout"))), ms)
|
|
317
|
-
try {
|
|
318
|
-
;(timer as unknown as { unref?: () => void }).unref?.()
|
|
319
|
-
} catch {}
|
|
320
|
-
}),
|
|
321
|
-
])
|
|
322
|
-
} finally {
|
|
323
|
-
if (timer) clearTimeout(timer)
|
|
324
|
-
}
|
|
325
|
-
}
|
|
310
|
+
const withWatchdog = <T>(fn: () => Promise<T> | T): Promise<T> =>
|
|
311
|
+
withTimeout(fn, opts.actionTimeoutMs ?? 60_000)
|
|
326
312
|
|
|
327
313
|
const loadRowsSafe = async () => {
|
|
328
314
|
try {
|
|
@@ -486,44 +472,51 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
486
472
|
if (busy) return true
|
|
487
473
|
busy = true
|
|
488
474
|
suspend()
|
|
489
|
-
//
|
|
490
|
-
//
|
|
491
|
-
// Esc = batal total,
|
|
475
|
+
// B4 (audit UI/UX): Enter = SATU langkah — pilih & simpan model
|
|
476
|
+
// langsung. Picker effort tidak lagi langkah wajib tiap Enter
|
|
477
|
+
// (dulu: Esc di effort = batal total, dua tekan untuk ganti model).
|
|
478
|
+
// Effort kini aksi terpisah lewat Tab (lihat cabang `tab` di bawah).
|
|
479
|
+
;(async () => {
|
|
480
|
+
try {
|
|
481
|
+
await withWatchdog(() => opts.onSelect(row.id))
|
|
482
|
+
finish()
|
|
483
|
+
} catch (e) {
|
|
484
|
+
// Pilih model yang gagal HARUS terlihat dan kembali ke daftar
|
|
485
|
+
// untuk retry (pola resume() seperti a/d/e provider-manager),
|
|
486
|
+
// bukan menutup manager dan kehilangan konteks daftar.
|
|
487
|
+
// Pesan controller = input tak terpercaya: sanitasi.
|
|
488
|
+
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
489
|
+
busy = false
|
|
490
|
+
await loadRowsSafe()
|
|
491
|
+
resume()
|
|
492
|
+
}
|
|
493
|
+
})()
|
|
494
|
+
return true
|
|
495
|
+
} else if (item.key.type === "tab") {
|
|
496
|
+
// B4: ubah thinking effort TANPA mengganti model. Tab = aksi
|
|
497
|
+
// eksplisit (bukan langkah wajib), Esc pada picker = batal dan
|
|
498
|
+
// kembali ke daftar — manajer tidak pernah menutup diri di sini.
|
|
499
|
+
const row = viewRows()[sel]
|
|
500
|
+
if (!row || busy || !opts.onSetEffort) return true
|
|
501
|
+
busy = true
|
|
502
|
+
suspend()
|
|
492
503
|
;(async () => {
|
|
493
504
|
try {
|
|
494
505
|
const picked = await pickEffort(row.id)
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
506
|
+
if (picked && picked !== "skip") {
|
|
507
|
+
await withWatchdog(() => opts.onSetEffort!(row.id, picked))
|
|
508
|
+
// Notice terlihat di daftar (manager tetap terbuka) —
|
|
509
|
+
// inilah kehidupan baru `effort.saved` setelah A5.
|
|
510
|
+
notice = t("effort.saved", { effort: picked })
|
|
500
511
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
// manager langsung tutup sesudahnya, jadi baris ini hanya
|
|
510
|
-
// terlihat bila alur berubah me-resume — badge effort di
|
|
511
|
-
// daftar tetap sumber kebenaran yang bisa dibuka ulang.
|
|
512
|
-
notice = t("effort.saved", { effort: picked })
|
|
513
|
-
}
|
|
514
|
-
finish()
|
|
515
|
-
} catch (e) {
|
|
516
|
-
// Pilih model yang gagal HARUS terlihat dan kembali ke daftar
|
|
517
|
-
// untuk retry (pola resume() seperti a/d/e provider-manager),
|
|
518
|
-
// bukan menutup manager dan kehilangan konteks daftar.
|
|
519
|
-
// Pesan controller = input tak terpercaya: sanitasi.
|
|
520
|
-
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
521
|
-
busy = false
|
|
522
|
-
await loadRowsSafe()
|
|
523
|
-
resume()
|
|
524
|
-
}
|
|
525
|
-
} catch {
|
|
526
|
-
finish()
|
|
512
|
+
busy = false
|
|
513
|
+
await loadRowsSafe()
|
|
514
|
+
resume()
|
|
515
|
+
} catch (e) {
|
|
516
|
+
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
517
|
+
busy = false
|
|
518
|
+
await loadRowsSafe()
|
|
519
|
+
resume()
|
|
527
520
|
}
|
|
528
521
|
})()
|
|
529
522
|
return true
|
|
@@ -548,7 +541,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
548
541
|
}
|
|
549
542
|
const managerPump = createKeyStreamPump({ state: decoder, onKeys: handleManagerKeys })
|
|
550
543
|
const onData = (chunk: Buffer) => {
|
|
551
|
-
|
|
544
|
+
idle.reset()
|
|
552
545
|
try {
|
|
553
546
|
managerPump.push(chunk)
|
|
554
547
|
} catch {
|
|
@@ -566,7 +559,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
566
559
|
process.stdin.on("data", onData)
|
|
567
560
|
process.stdout.on("resize", onResize)
|
|
568
561
|
attached = true
|
|
569
|
-
|
|
562
|
+
idle.reset()
|
|
570
563
|
render()
|
|
571
564
|
} catch (e) {
|
|
572
565
|
// Setup gagal = tutup + BERSUARA (Fase D): jendela kosong bisu adalah
|
package/src/ui/screens/picker.ts
CHANGED
|
@@ -8,12 +8,14 @@ import {
|
|
|
8
8
|
type DecoderState,
|
|
9
9
|
toGraphemes,
|
|
10
10
|
} from "../input/prompt-engine.ts"
|
|
11
|
+
import { hintLine } from "../render/hint.ts"
|
|
11
12
|
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
13
|
import { c, stripAnsi } from "../render/theme.ts"
|
|
13
14
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
14
15
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
15
16
|
import { beginInteractiveScreen } from "../runtime/statusline.ts"
|
|
16
|
-
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
17
|
+
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
18
|
+
import { createIdleTimer } from "./lifecycle.ts"
|
|
17
19
|
|
|
18
20
|
export interface PickerItem {
|
|
19
21
|
name: string
|
|
@@ -31,9 +33,6 @@ export interface PickerOptions {
|
|
|
31
33
|
|
|
32
34
|
const dim = (s: string): string => c.dim(s)
|
|
33
35
|
|
|
34
|
-
/** Lebar kotak popup picker TETAP (keputusan rasa: geometri stabil). */
|
|
35
|
-
const PICKER_BOX_W = 64
|
|
36
|
-
|
|
37
36
|
// Tandai substring query di label agar user tahu KENAPA item cocok.
|
|
38
37
|
// Operasi pada teks plain (sebelum truncate) — SGR bold nol kolom.
|
|
39
38
|
function highlightMatch(label: string, query: string): string {
|
|
@@ -70,6 +69,8 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
70
69
|
let scroll = 0
|
|
71
70
|
let filter = ""
|
|
72
71
|
const isFilterable = opts.filterable ?? false
|
|
72
|
+
// Lebar dibekukan saat mount (AUD-006).
|
|
73
|
+
const boxWidth = popupBoxWidth(process.stdout.columns || 80)
|
|
73
74
|
|
|
74
75
|
const filteredItems = (): PickerItem[] => {
|
|
75
76
|
if (!isFilterable || !filter) return opts.items
|
|
@@ -87,21 +88,28 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
87
88
|
// dicetak — keduanya membungkus dan merusak tampilan.
|
|
88
89
|
const visibleRows = () => {
|
|
89
90
|
const rows = process.stdout.rows || 24
|
|
90
|
-
// Modal tanpa judul/footer; sisakan border
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Modal tanpa judul/footer dekoratif; sisakan border, baris pencarian
|
|
92
|
+
// (bila ada), DAN satu baris hint aksi di dasar.
|
|
93
|
+
if (useModal) return Math.max(1, Math.min(rows - (isFilterable ? 4 : 3), 12))
|
|
94
|
+
const chrome = isFilterable ? 4 : 3
|
|
93
95
|
return Math.max(1, Math.min(rows - chrome, 12))
|
|
94
96
|
}
|
|
95
|
-
// Lebar konten = lebar kotak
|
|
96
|
-
// stabil, tak bernapas saat filter) dikurangi chrome dialog
|
|
97
|
+
// Lebar konten = lebar kotak (dibekukan saat mount) dikurangi chrome dialog
|
|
97
98
|
// (border+padding = 4 kolom) agar dialogBox tak memotong ulang label.
|
|
98
|
-
const width = () =>
|
|
99
|
-
Math.max(8, Math.min((process.stdout.columns || 80) - 2 - 4, PICKER_BOX_W - 4))
|
|
99
|
+
const width = () => Math.max(8, boxWidth - 4)
|
|
100
100
|
|
|
101
|
-
// Isi untuk dialog popup (tanpa judul
|
|
101
|
+
// Isi untuk dialog popup (tanpa judul; hint aksi satu baris di dasar).
|
|
102
102
|
const bodyLines = (): string[] => {
|
|
103
103
|
const items = filteredItems()
|
|
104
104
|
const v = visibleRows()
|
|
105
|
+
// Hint minimalis: kunci terang, label redup (satu sumber `hintLine`).
|
|
106
|
+
// Selalu tampil agar navigasi tak perlu ditebak; tidak memakan tinggi
|
|
107
|
+
// daftar karena `visibleRows` sudah menyisihkan satu baris untuknya.
|
|
108
|
+
const hint = hintLine([
|
|
109
|
+
{ key: "↑↓", label: t("hint.move") },
|
|
110
|
+
{ key: "Enter", label: t("hint.select") },
|
|
111
|
+
{ key: "Esc", label: t("hint.close") },
|
|
112
|
+
])
|
|
105
113
|
if (sel >= items.length) sel = Math.max(0, items.length - 1)
|
|
106
114
|
if (sel < 0) sel = 0
|
|
107
115
|
if (sel < scroll) scroll = sel
|
|
@@ -118,6 +126,7 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
118
126
|
}
|
|
119
127
|
if (items.length === 0) {
|
|
120
128
|
lines.push(cut(dim(` ${t("pick.noMatch", { q: sanitizeAnsiLine(filter) })}`)))
|
|
129
|
+
lines.push(cut(hint))
|
|
121
130
|
return lines
|
|
122
131
|
}
|
|
123
132
|
for (let i = 0; i < rows.length; i++) {
|
|
@@ -133,19 +142,20 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
133
142
|
if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
|
|
134
143
|
else lines.push(` ${dim(label)}`)
|
|
135
144
|
}
|
|
136
|
-
|
|
145
|
+
lines.push(cut(hint))
|
|
146
|
+
return lines
|
|
137
147
|
}
|
|
138
148
|
|
|
139
149
|
const render = () => {
|
|
140
150
|
// Popup komposit: HANYA region kotak yang dilukis (tanpa clear) di atas
|
|
141
151
|
// konten pemilik layar (transkrip App / alt-buffer wizard). Pemilik
|
|
142
|
-
//
|
|
152
|
+
// Lebar beku (min=max): geometri tak bernapas saat filter berubah.
|
|
143
153
|
const box = dialogBox(
|
|
144
154
|
{
|
|
145
155
|
title: "",
|
|
146
156
|
body: bodyLines(),
|
|
147
|
-
minWidth:
|
|
148
|
-
maxWidth:
|
|
157
|
+
minWidth: boxWidth,
|
|
158
|
+
maxWidth: boxWidth,
|
|
149
159
|
},
|
|
150
160
|
screen.cols,
|
|
151
161
|
screen.rows,
|
|
@@ -180,23 +190,16 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
180
190
|
// 133 dtk idle di picker). Timer idle 90 dtk auto-batal agar raw-mode
|
|
181
191
|
// tidak digenggam selamanya — tanpa ini picker bisa crash Bun sebelum
|
|
182
192
|
// user menekan apa pun. Bukan perubahan perilaku: idle sepanjang itu
|
|
183
|
-
// memang harusnya batal.
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
// memang harusnya batal. Satu sumber idle via helper bersama (audit D1).
|
|
194
|
+
// `cleanup`/`resolve` dirujuk sebagai closure (dievaluasi saat timer fire).
|
|
195
|
+
const idle = createIdleTimer({
|
|
196
|
+
cancelMs: 90_000,
|
|
197
|
+
onCancel: () => {
|
|
188
198
|
cleanup()
|
|
189
199
|
opts.onCancel()
|
|
190
200
|
resolve()
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
idleTimer &&
|
|
195
|
-
typeof (idleTimer as unknown as { unref?: () => void }).unref === "function"
|
|
196
|
-
) {
|
|
197
|
-
;(idleTimer as unknown as { unref: () => void }).unref!()
|
|
198
|
-
}
|
|
199
|
-
}
|
|
201
|
+
},
|
|
202
|
+
})
|
|
200
203
|
const decoder: DecoderState = createDecoderState()
|
|
201
204
|
// Seperti manager: simpan batas listener warisan (guard: stdin stub test
|
|
202
205
|
// tak punya getMaxListeners), kembalikan di cleanup agar warning Node
|
|
@@ -240,7 +243,7 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
240
243
|
try {
|
|
241
244
|
process.stdin.setMaxListeners(prevMaxListeners)
|
|
242
245
|
} catch {}
|
|
243
|
-
|
|
246
|
+
idle.dispose()
|
|
244
247
|
// Lepas kepemilikan layar: painter boleh melukis lagi setelah ini
|
|
245
248
|
// (kursor sudah kembali ke anchor, overlay sudah dibersihkan).
|
|
246
249
|
endScreen()
|
|
@@ -394,7 +397,7 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
394
397
|
const pickerPump = createKeyStreamPump({ state: decoder, onKeys: handlePickerKeys })
|
|
395
398
|
|
|
396
399
|
onData = (chunk: Buffer) => {
|
|
397
|
-
|
|
400
|
+
idle.reset()
|
|
398
401
|
try {
|
|
399
402
|
pickerPump.push(chunk)
|
|
400
403
|
} catch (e) {
|
|
@@ -428,7 +431,7 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
428
431
|
process.stdin.setMaxListeners(0)
|
|
429
432
|
process.stdin.on("data", onData)
|
|
430
433
|
process.stdout.on("resize", onResize)
|
|
431
|
-
|
|
434
|
+
idle.reset()
|
|
432
435
|
render()
|
|
433
436
|
} catch (e) {
|
|
434
437
|
// Sama seperti di atas: setup gagal (raw-mode ConPTY rusak) harus
|
|
@@ -9,18 +9,22 @@ import {
|
|
|
9
9
|
type DecodedKey,
|
|
10
10
|
type DecoderState,
|
|
11
11
|
} from "../input/prompt-engine.ts"
|
|
12
|
+
import { hintLine } from "../render/hint.ts"
|
|
12
13
|
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
13
14
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
14
15
|
import { truncateToWidth } from "../render/width.ts"
|
|
15
16
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
16
|
-
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
17
|
+
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
17
18
|
import { runForm, validateRequired, validateUrl } from "./form.ts"
|
|
19
|
+
import { createIdleTimer } from "./lifecycle.ts"
|
|
18
20
|
import { runPicker } from "./picker.ts"
|
|
21
|
+
import { withTimeout } from "./watchdog.ts"
|
|
19
22
|
|
|
20
23
|
const dim = (s: string): string => c.dim(s)
|
|
21
24
|
|
|
22
25
|
/** Lebar tetap popup provider setelah daftar diringkas ke nama provider. */
|
|
23
|
-
|
|
26
|
+
/** Lebar kotak /providers: `popupBoxWidth` — paritas picker/model/form (AUD-006). */
|
|
27
|
+
const providerBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
|
|
24
28
|
|
|
25
29
|
export interface ProviderRow {
|
|
26
30
|
id: string
|
|
@@ -90,12 +94,15 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
90
94
|
// kemungkinan notice tetap masuk ke perhitungan tinggi.
|
|
91
95
|
const visibleRows = () => {
|
|
92
96
|
const rows = process.stdout.rows || 24
|
|
93
|
-
|
|
97
|
+
// Chrome tetap: 2 border + 1 baris hint aksi; notice (transient)
|
|
98
|
+
// menyusutkan daftar satu baris — paritas model-manager, agar hint
|
|
99
|
+
// tak pernah jadi korban potong atas dialogBox.
|
|
100
|
+
const fixed = 3 + (notice ? 1 : 0)
|
|
101
|
+
return Math.max(1, Math.min(rows - fixed, 14))
|
|
94
102
|
}
|
|
95
|
-
// Lebar konten = lebar kotak
|
|
96
|
-
//
|
|
97
|
-
const width = () =>
|
|
98
|
-
Math.max(8, Math.min((process.stdout.columns || 80) - 2 - 4, PROVIDER_BOX_W - 4))
|
|
103
|
+
// Lebar konten = lebar kotak (dibekukan saat mount) dikurangi chrome
|
|
104
|
+
// dialog (lihat picker.ts).
|
|
105
|
+
const width = () => Math.max(8, providerBoxWidth() - 4)
|
|
99
106
|
|
|
100
107
|
// Isi popup ringkas: nama provider dan hasil aksi sementara.
|
|
101
108
|
const bodyLines = (): string[] => {
|
|
@@ -124,18 +131,30 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
124
131
|
}
|
|
125
132
|
// Struk transient (jalur legacy maupun modal).
|
|
126
133
|
if (notice) lines.push(cut(dim(sanitizeAnsiLine(notice))))
|
|
134
|
+
// Hint aksi minimalis (kunci terang, label redup) — paritas /model.
|
|
135
|
+
lines.push(
|
|
136
|
+
cut(
|
|
137
|
+
hintLine([
|
|
138
|
+
{ key: "Enter", label: t("hint.select") },
|
|
139
|
+
{ key: "a", label: t("hint.add") },
|
|
140
|
+
{ key: "e", label: t("hint.edit") },
|
|
141
|
+
{ key: "d", label: t("hint.delete") },
|
|
142
|
+
{ key: "Esc", label: t("hint.close") },
|
|
143
|
+
]),
|
|
144
|
+
),
|
|
145
|
+
)
|
|
127
146
|
return lines
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
const render = () => {
|
|
131
150
|
// Popup komposit: HANYA region kotak (tanpa clear) di atas konten
|
|
132
|
-
//
|
|
151
|
+
// Lebar beku (min=max, paritas picker/model).
|
|
133
152
|
const box = dialogBox(
|
|
134
153
|
{
|
|
135
154
|
title: "",
|
|
136
155
|
body: bodyLines(),
|
|
137
|
-
minWidth:
|
|
138
|
-
maxWidth:
|
|
156
|
+
minWidth: providerBoxWidth(),
|
|
157
|
+
maxWidth: providerBoxWidth(),
|
|
139
158
|
},
|
|
140
159
|
screen.cols,
|
|
141
160
|
screen.rows,
|
|
@@ -172,13 +191,20 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
172
191
|
let busy = false
|
|
173
192
|
// Idle-timeout 90 dtk seperti picker/model-manager: tanpa ini raw-mode
|
|
174
193
|
// digenggam selamanya bila stdin 'data' tak pernah datang di Windows
|
|
175
|
-
// (ConPTY macet) = "masuk list macet". Timer di-unref agar tak menahan
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
// (ConPTY macet) = "masuk list macet". Timer di-unref agar tak menahan
|
|
195
|
+
// exit — satu sumber idle via helper bersama (audit D1). `cleanup`
|
|
196
|
+
// dirujuk sebagai closure (dievaluasi saat timer fire).
|
|
197
|
+
const idle = createIdleTimer({
|
|
198
|
+
cancelMs: 90_000,
|
|
199
|
+
onCancel: () => {
|
|
200
|
+
try {
|
|
201
|
+
cleanup()
|
|
202
|
+
} catch {}
|
|
203
|
+
try {
|
|
204
|
+
resolve()
|
|
205
|
+
} catch {}
|
|
206
|
+
},
|
|
207
|
+
})
|
|
182
208
|
/** Listener stdin terpasang? Menjaga resume() idempoten (anti-ganda). */
|
|
183
209
|
let attached = false
|
|
184
210
|
|
|
@@ -186,7 +212,7 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
186
212
|
// di a/d/e). Tidak menyentuh `done` - manager tetap hidup; resume()
|
|
187
213
|
// menggambar ulang region popup.
|
|
188
214
|
const suspend = () => {
|
|
189
|
-
|
|
215
|
+
idle.clear()
|
|
190
216
|
attached = false
|
|
191
217
|
process.stdout.write("\x1b[0m\x1b[?25h")
|
|
192
218
|
// setRawMode dibungkus try/catch: di Windows handle bisa rusak dan
|
|
@@ -223,14 +249,14 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
223
249
|
attached = true
|
|
224
250
|
}
|
|
225
251
|
render()
|
|
226
|
-
|
|
252
|
+
idle.reset()
|
|
227
253
|
}
|
|
228
254
|
// Close final: suspend + tandai selesai (manager tidak bisa dibuka lagi).
|
|
229
255
|
// Selalu resolve walau suspend melempar — tanpa try/finally Promise gantung.
|
|
230
256
|
const cleanup = () => {
|
|
231
257
|
if (done) return
|
|
232
258
|
done = true
|
|
233
|
-
|
|
259
|
+
idle.dispose()
|
|
234
260
|
try {
|
|
235
261
|
providerPump.dispose()
|
|
236
262
|
} catch {}
|
|
@@ -249,23 +275,6 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
249
275
|
} catch {}
|
|
250
276
|
}
|
|
251
277
|
|
|
252
|
-
resetIdle = () => {
|
|
253
|
-
if (done) return
|
|
254
|
-
clearIdle()
|
|
255
|
-
idleTimer = setTimeout(() => {
|
|
256
|
-
// Idle 90 dtk tanpa input = batal otomatis (samakan picker).
|
|
257
|
-
try {
|
|
258
|
-
cleanup()
|
|
259
|
-
} catch {}
|
|
260
|
-
try {
|
|
261
|
-
resolve()
|
|
262
|
-
} catch {}
|
|
263
|
-
}, 90_000)
|
|
264
|
-
try {
|
|
265
|
-
;(idleTimer as unknown as { unref?: () => void }).unref?.()
|
|
266
|
-
} catch {}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
278
|
// SEMUA aksi a/d/e lewat sini: busy guard + suspend, lalu SELALU resume di
|
|
270
279
|
// finally. Tanpa finally, exception di onAdd/askLine (atau loadRows) membuat
|
|
271
280
|
// busy tetap true → onData menolak semua input → manager terkunci selamanya.
|
|
@@ -292,26 +301,8 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
292
301
|
* pulih; aksi telat yang akhirnya selesai diabaikan hasilnya. Tunggu
|
|
293
302
|
* interaksi user (form/picker) TIDAK dibatasi — hanya await jaringan.
|
|
294
303
|
*/
|
|
295
|
-
const withWatchdog =
|
|
296
|
-
|
|
297
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
298
|
-
const p = Promise.resolve().then(fn)
|
|
299
|
-
// Rejection telat TANPA handler = unhandledRejection (bun: crash).
|
|
300
|
-
p.catch(() => {})
|
|
301
|
-
try {
|
|
302
|
-
return await Promise.race([
|
|
303
|
-
p,
|
|
304
|
-
new Promise<never>((_, reject) => {
|
|
305
|
-
timer = setTimeout(() => reject(new Error(t("ntc.timeout"))), ms)
|
|
306
|
-
try {
|
|
307
|
-
;(timer as unknown as { unref?: () => void }).unref?.()
|
|
308
|
-
} catch {}
|
|
309
|
-
}),
|
|
310
|
-
])
|
|
311
|
-
} finally {
|
|
312
|
-
if (timer) clearTimeout(timer)
|
|
313
|
-
}
|
|
314
|
-
}
|
|
304
|
+
const withWatchdog = <T>(fn: () => Promise<T> | T): Promise<T> =>
|
|
305
|
+
withTimeout(fn, opts.actionTimeoutMs ?? 60_000)
|
|
315
306
|
|
|
316
307
|
const doAdd = () => {
|
|
317
308
|
if (busy) return
|
|
@@ -603,7 +594,7 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
603
594
|
}
|
|
604
595
|
const providerPump = createKeyStreamPump({ state: decoder, onKeys: handleProviderKeys })
|
|
605
596
|
const onData = (chunk: Buffer) => {
|
|
606
|
-
|
|
597
|
+
idle.reset()
|
|
607
598
|
try {
|
|
608
599
|
providerPump.push(chunk)
|
|
609
600
|
} catch {
|
|
@@ -626,7 +617,7 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
|
|
|
626
617
|
process.stdin.on("data", onData)
|
|
627
618
|
process.stdout.on("resize", onResize)
|
|
628
619
|
attached = true
|
|
629
|
-
|
|
620
|
+
idle.reset()
|
|
630
621
|
render()
|
|
631
622
|
} catch (e) {
|
|
632
623
|
// Setup gagal = tutup + BERSUARA (Fase D): jendela kosong bisu adalah
|