minicode-ai 0.9.29 → 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 +79 -1
- package/PLAN.md +491 -0
- package/README.md +2 -2
- package/cli/args.ts +1 -0
- 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 +225 -103
- package/cli/index.ts +89 -62
- package/cli/model-manager.ts +8 -8
- package/cli/provider-manager.ts +13 -13
- package/cli/router.ts +7 -0
- package/cli/setup.ts +349 -4
- package/cli/tui.ts +542 -0
- package/cli/wizard.ts +2 -1
- package/docs/ARCHITECTURE.html +62 -36
- 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/rag-layer.ts +7 -2
- package/src/app/session.ts +6 -0
- package/src/app/tool-layer.ts +2 -1
- package/src/config.ts +30 -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 +213 -17
- 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/policy/update-check.ts +4 -1
- 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 +23 -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 +7 -1
- package/src/tools/web_fetch.ts +11 -2
- package/src/tools/web_search.ts +4 -1
- package/src/ui/approval/prompt.ts +96 -22
- package/src/ui/assistant/simple.ts +188 -44
- package/src/ui/assistant/turn-status.ts +32 -10
- package/src/ui/contract.ts +119 -0
- package/src/ui/footer.ts +35 -14
- package/src/ui/i18n/en.ts +253 -0
- package/src/ui/i18n/id.ts +255 -0
- package/src/ui/i18n/locale.ts +68 -0
- package/src/ui/input/input.ts +189 -81
- package/src/ui/input/prompt-engine.ts +139 -4
- package/src/ui/render/collapse.ts +20 -13
- package/src/ui/render/diff.ts +7 -2
- package/src/ui/render/errors.ts +75 -50
- package/src/ui/render/format.ts +26 -8
- package/src/ui/render/highlight.ts +12 -5
- package/src/ui/render/markdown.ts +5 -1
- package/src/ui/render/sanitize.ts +29 -2
- package/src/ui/render/table.ts +12 -6
- package/src/ui/render/theme.ts +23 -4
- package/src/ui/render/width.ts +104 -17
- package/src/ui/runtime/motion.ts +16 -0
- package/src/ui/runtime/screen.ts +242 -0
- package/src/ui/runtime/spinner.ts +50 -4
- package/src/ui/runtime/statusline.ts +50 -1
- package/src/ui/screens/dialog.ts +174 -0
- package/src/ui/screens/form.ts +486 -0
- package/src/ui/screens/model-manager.ts +289 -134
- package/src/ui/screens/picker.ts +264 -109
- package/src/ui/screens/provider-manager.ts +385 -172
- package/src/ui/screens/wizard.ts +165 -102
- package/src/ui/tui/app.ts +951 -0
- package/src/ui/tui/transcript.ts +475 -0
- 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/cli/repl.ts +0 -740
- package/src/ui/runtime/chrome.ts +0 -369
- package/src/ui/screens/overlay.ts +0 -61
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
// View model registry — pola
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// View model registry — pola popup komposit yang konsisten dengan picker/// provider-manager. Tetap shell-like: overlay sementara, hasil aksi tetap inline.
|
|
2
|
+
|
|
3
|
+
import { t } from "../i18n/locale.ts"
|
|
4
|
+
import {
|
|
5
|
+
createDecoderState,
|
|
6
|
+
createKeyStreamPump,
|
|
7
|
+
type DecodedKey,
|
|
8
|
+
type DecoderState,
|
|
9
|
+
toGraphemes,
|
|
10
|
+
} from "../input/prompt-engine.ts"
|
|
11
|
+
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
12
|
+
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
13
|
+
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
14
|
+
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
15
|
+
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
16
|
+
import { runForm } from "./form.ts"
|
|
8
17
|
import { runPicker } from "./picker.ts"
|
|
9
18
|
|
|
10
|
-
const
|
|
11
|
-
RESTORE = "\x1b[22m"
|
|
19
|
+
const dim = (s: string): string => c.dim(s)
|
|
12
20
|
|
|
13
21
|
export interface ModelRow {
|
|
14
22
|
/** Format "providerId::model". */
|
|
@@ -23,9 +31,8 @@ export interface ModelManagerViewOptions {
|
|
|
23
31
|
/** Filter awal (dari `/model <cari>`) — null/"" = tanpa filter. */
|
|
24
32
|
initialFilter?: string
|
|
25
33
|
onSelect(id: string): void | Promise<void>
|
|
26
|
-
/** Ambil baris terbaru setelah mutasi
|
|
34
|
+
/** Ambil baris terbaru setelah mutasi. */
|
|
27
35
|
loadRows(): Promise<ModelRow[]>
|
|
28
|
-
onAdd(providerId: string, model: string): Promise<ModelRow[]>
|
|
29
36
|
onDelete(id: string): Promise<ModelRow[]>
|
|
30
37
|
onSetEffort?(id: string, effort: "default" | "low" | "medium" | "high"): Promise<ModelRow[]>
|
|
31
38
|
/**
|
|
@@ -35,6 +42,11 @@ export interface ModelManagerViewOptions {
|
|
|
35
42
|
* injeksi): semua opsi, perilaku lama.
|
|
36
43
|
*/
|
|
37
44
|
getEfforts?: (id: string) => ("default" | "low" | "medium" | "high")[]
|
|
45
|
+
/**
|
|
46
|
+
* Batas waktu aksi jaringan (ms) — DI untuk test (default 60 dtk).
|
|
47
|
+
* Tanpa ini test watchdog menunggu semenit.
|
|
48
|
+
*/
|
|
49
|
+
actionTimeoutMs?: number
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
/** Saring baris berdasarkan substring id, case-insensitive. Murni agar bisa diuji. */
|
|
@@ -44,12 +56,14 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
|
|
|
44
56
|
return rows.filter((r) => r.id.toLowerCase().includes(needle))
|
|
45
57
|
}
|
|
46
58
|
|
|
59
|
+
/** Lebar kotak dialog /model: TETAP 64 kolom (keputusan rasa: geometri stabil,
|
|
60
|
+
* tak pernah melompat mengikuti konten). Satu sumber untuk width() dan
|
|
61
|
+
* maxWidth dialogBox — keduanya HARUS sepakat agar label tak terpotong ulang. */
|
|
62
|
+
const MODAL_BOX_W = 64
|
|
63
|
+
|
|
47
64
|
export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
|
|
48
|
-
let rows = opts.initialRows
|
|
49
|
-
//
|
|
50
|
-
// lagi shortcut huruf agar mengetik selalu menyaring di semua OS). Tambah =
|
|
51
|
-
// Ctrl+N, hapus = tombol Del. Esc keluar dari mode cari, bukan tutup
|
|
52
|
-
// manager. null = tak memfilter.
|
|
65
|
+
let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
|
|
66
|
+
// Esc keluar dari mode cari, bukan tutup manager. null = tak memfilter.
|
|
53
67
|
let filter: string | null = null
|
|
54
68
|
const initial = opts.initialFilter?.trim()
|
|
55
69
|
if (initial) filter = initial
|
|
@@ -63,15 +77,27 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
63
77
|
)
|
|
64
78
|
clampSel()
|
|
65
79
|
let scroll = 0
|
|
66
|
-
|
|
80
|
+
// Struk aksi transient: hasil delete/Canceled/error tampil sebagai baris
|
|
81
|
+
// redup DALAM popup, bukan console.log ke scrollback. Dibersihkan tiap
|
|
82
|
+
// keypress baru — terlihat sampai tombol berikut ditekan.
|
|
83
|
+
let notice: string | null = null
|
|
67
84
|
|
|
68
85
|
return new Promise<void>((resolve) => {
|
|
69
|
-
const visibleRows = () =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
const visibleRows = () => {
|
|
87
|
+
const rows = process.stdout.rows || 24
|
|
88
|
+
// Popup: jatah dialog rows−4 sudah termasuk baris counter/notice, jadi
|
|
89
|
+
// item dibatasi rows−5 (lihat picker.ts). Dialog mungil /model: maks 8.
|
|
90
|
+
return Math.max(1, Math.min(rows - 5, 8))
|
|
91
|
+
}
|
|
92
|
+
// Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
|
|
93
|
+
// tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
|
|
94
|
+
// dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
|
|
95
|
+
// = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
|
|
96
|
+
const width = () => Math.max(8, Math.min((process.stdout.columns || 80) - 6, MODAL_BOX_W - 4))
|
|
73
97
|
|
|
74
|
-
|
|
98
|
+
// Isi MINIMAL dialog /model (tanpa judul/footer/hitungan/penanda —
|
|
99
|
+
// seleksi murni warna). Search selalu tampil, daftar tanpa `›`.
|
|
100
|
+
const bodyLinesModal = (): string[] => {
|
|
75
101
|
const list = viewRows()
|
|
76
102
|
const v = visibleRows()
|
|
77
103
|
if (sel < scroll) scroll = sel
|
|
@@ -80,55 +106,89 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
80
106
|
const cut = (s: string) => truncateToWidth(s, w)
|
|
81
107
|
const view = list.slice(scroll, scroll + v)
|
|
82
108
|
const lines: string[] = []
|
|
83
|
-
lines.push(
|
|
84
|
-
cut(
|
|
85
|
-
`${DIM}─ ${c.accent(c.bold("Models"))}${rows.length ? ` ${DIM}(${rows.length})${RESTORE}` : ""} ${DIM}─${RESTORE}`,
|
|
86
|
-
),
|
|
87
|
-
)
|
|
88
|
-
if (filter != null) {
|
|
89
|
-
lines.push(
|
|
90
|
-
cut(
|
|
91
|
-
`${DIM} Filter:${RESTORE} ${filter}█ ${DIM}(${list.length}/${rows.length})${RESTORE}`,
|
|
92
|
-
),
|
|
93
|
-
)
|
|
94
|
-
}
|
|
109
|
+
lines.push(cut(`${dim(">")} ${c.brightCyan(sanitizeAnsiLine(filter ?? ""))}█`))
|
|
95
110
|
if (!list.length) {
|
|
96
|
-
lines.push(
|
|
97
|
-
cut(`${DIM} ${filter == null ? "No models configured" : "No models match"}${RESTORE}`),
|
|
98
|
-
)
|
|
111
|
+
lines.push(cut(dim(` ${filter == null ? t("model.empty") : t("model.noMatch")}`)))
|
|
99
112
|
} else {
|
|
100
113
|
for (let i = 0; i < view.length; i++) {
|
|
101
114
|
const row = view[i]!
|
|
102
115
|
const picked = i === sel - scroll
|
|
103
|
-
// Badge effort hanya bila non-default — default adalah kondisi normal
|
|
104
|
-
// yang tak perlu diumumkan tiap baris (minimalis).
|
|
105
116
|
const badge = row.effort && row.effort !== "default" ? ` [${row.effort}]` : ""
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
lines.push(
|
|
117
|
+
// Penanda aktif di luar budget truncasi (paritas provider-manager):
|
|
118
|
+
// nama yang dipotong, status yang selamat.
|
|
119
|
+
const active = row.active ? ` (${t("common.active")})` : ""
|
|
120
|
+
const nameBudget = Math.max(8, w - 4 - displayWidth(active))
|
|
121
|
+
const label = `${truncateToWidth(`${sanitizeAnsiLine(row.id)}${badge}`, nameBudget, "…")}${active}`
|
|
122
|
+
// Penanda › paritas picker/provider-manager — aksesibilitas visual
|
|
123
|
+
// (warna saja tak cukup untuk sebagian pengguna).
|
|
124
|
+
if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
|
|
125
|
+
else lines.push(` ${dim(label)}`)
|
|
115
126
|
}
|
|
116
127
|
}
|
|
117
|
-
lines.push(
|
|
118
|
-
lines.push(
|
|
119
|
-
cut(
|
|
120
|
-
`${DIM}Enter:${RESTORE}${c.accent("select+thinking")} ${DIM}Ctrl+N:${RESTORE}${c.accent("add")} ${DIM}Del:${RESTORE}${c.accent("delete")} ${DIM}ketik:${RESTORE}${c.accent("cari")} ${DIM}Esc:${RESTORE}${c.accent(filter == null ? "close" : "clear filter")}${RESTORE}`,
|
|
121
|
-
),
|
|
122
|
-
)
|
|
128
|
+
if (notice) lines.push(cut(dim(sanitizeAnsiLine(notice))))
|
|
123
129
|
return lines
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
const render = () => {
|
|
127
|
-
|
|
133
|
+
// Popup komposit: HANYA region kotak (tanpa clear) di atas transkrip
|
|
134
|
+
// App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
|
|
135
|
+
const box = dialogBox(
|
|
136
|
+
{
|
|
137
|
+
title: t("model.title"),
|
|
138
|
+
body: bodyLinesModal(),
|
|
139
|
+
footer: modelHint(),
|
|
140
|
+
minWidth: MODAL_BOX_W,
|
|
141
|
+
maxWidth: MODAL_BOX_W,
|
|
142
|
+
maxHeight: 14,
|
|
143
|
+
},
|
|
144
|
+
screen.cols,
|
|
145
|
+
screen.rows,
|
|
146
|
+
)
|
|
147
|
+
screen.paintRegion(box.lines, box.topRow)
|
|
148
|
+
// Parkir kursor di posisi ketik query (tepat sebelum penanda █ di
|
|
149
|
+
// baris search body[0]): kolom = padding + border + spasi + "> " +
|
|
150
|
+
// lebar filter + 1. Parkir di ujung baris (padding void) terlihat
|
|
151
|
+
// rusak — kursor melayang jauh dari █.
|
|
152
|
+
try {
|
|
153
|
+
const li = Math.min(box.lines.length - 1, box.bodyTop)
|
|
154
|
+
const row = box.topRow + li
|
|
155
|
+
const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
|
|
156
|
+
const col = Math.max(
|
|
157
|
+
1,
|
|
158
|
+
Math.min(
|
|
159
|
+
screen.cols || 80,
|
|
160
|
+
leftPad + 2 + 2 + displayWidth(sanitizeAnsiLine(filter ?? "")) + 1,
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
process.stdout.write(`\x1b[${row};${col}H\x1b[?25h`)
|
|
164
|
+
} catch {}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Hint footer /model: Del/type-to-filter jadi discoverable (dulu tanpa
|
|
168
|
+
* footer — user baru tak tahu cara hapus/saring). */
|
|
169
|
+
const modelHint = (): string =>
|
|
170
|
+
`${c.accent(t("model.typeFilter"))} · Del:${c.accent(t("verb.delete"))} · Enter:${c.accent(t("verb.select"))} · Esc:${c.accent(t("verb.close"))}`
|
|
171
|
+
|
|
172
|
+
// Popup butuh layar mampu; selain itu tolak BERSUARA + batal.
|
|
173
|
+
const screen: AltScreen = openAltScreen()
|
|
174
|
+
const useModal = screen.ok && (process.stdout.rows || 24) >= 10
|
|
175
|
+
if (!useModal) {
|
|
176
|
+
try {
|
|
177
|
+
console.log(`⚠ ${t("gate.tuiModel")}`)
|
|
178
|
+
} catch {}
|
|
179
|
+
// Tutup layar sebelum batal: openAltScreen sudah menulis ENTER fisik —
|
|
180
|
+
// bail tanpa close membocorkan alt-screen + hold painter (I27).
|
|
181
|
+
try {
|
|
182
|
+
screen.close()
|
|
183
|
+
} catch {}
|
|
184
|
+
resolve()
|
|
185
|
+
return
|
|
128
186
|
}
|
|
129
187
|
|
|
130
188
|
let busy = false
|
|
131
189
|
let done = false
|
|
190
|
+
/** Listener stdin terpasang? Menjaga resume() idempoten (anti-ganda). */
|
|
191
|
+
let attached = false
|
|
132
192
|
// Bun Windows: raw-mode yang ditahan tanpa input rawan digenggam selamanya
|
|
133
193
|
// (lihat idleTimer 90 dtk di picker.ts — segfault setelah 133 dtk idle).
|
|
134
194
|
// Manager ini sebelumnya TANPA idleTimer: bila stdin 'data' tak pernah
|
|
@@ -145,9 +205,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
145
205
|
|
|
146
206
|
const suspend = () => {
|
|
147
207
|
clearIdle()
|
|
148
|
-
|
|
208
|
+
attached = false
|
|
149
209
|
process.stdout.write("\x1b[0m\x1b[?25h")
|
|
150
|
-
// TIDAK menulis \r\n — clearTransientOverlay sudah kembali ke anchor.
|
|
151
210
|
// TANPA pause — stdin mengalir seumur proses (lihat cleanup askLine).
|
|
152
211
|
try {
|
|
153
212
|
process.stdin.setRawMode(false)
|
|
@@ -162,18 +221,24 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
162
221
|
|
|
163
222
|
const resume = () => {
|
|
164
223
|
if (done) return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
224
|
+
// Idempoten: tanpa garda, resume ganda (mis. watchdog timeout lalu
|
|
225
|
+
// aksi telat selesai) memasang listener stdin DUA kali → tiap tombol
|
|
226
|
+
// diproses ganda. Gagal-di-kode-lama.
|
|
227
|
+
if (!attached) {
|
|
228
|
+
process.stdin.setMaxListeners(0)
|
|
229
|
+
try {
|
|
230
|
+
process.stdin.setRawMode(true)
|
|
231
|
+
} catch {
|
|
232
|
+
// Raw-mode gagal (ConPTY Windows) = tak bisa baca tombol; lebih baik
|
|
233
|
+
// tutup jujur daripada gantung dengan layar mati.
|
|
234
|
+
finish()
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
process.stdin.resume()
|
|
238
|
+
process.stdin.on("data", onData)
|
|
239
|
+
process.stdout.on("resize", onResize)
|
|
240
|
+
attached = true
|
|
173
241
|
}
|
|
174
|
-
process.stdin.resume()
|
|
175
|
-
process.stdin.on("data", onData)
|
|
176
|
-
process.stdout.on("resize", onResize)
|
|
177
242
|
render()
|
|
178
243
|
resetIdle()
|
|
179
244
|
}
|
|
@@ -182,6 +247,21 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
182
247
|
if (done) return
|
|
183
248
|
done = true
|
|
184
249
|
clearIdle()
|
|
250
|
+
// Kembalikan batas listener warisan (lihat prevMaxListeners): warning
|
|
251
|
+
// MaxListenersExceeded kembali berguna setelah sesi ini selesai.
|
|
252
|
+
try {
|
|
253
|
+
managerPump.dispose()
|
|
254
|
+
} catch {}
|
|
255
|
+
try {
|
|
256
|
+
process.stdin.setMaxListeners(prevMaxListeners)
|
|
257
|
+
} catch {}
|
|
258
|
+
// Hapus region popup sendiri sebelum pemilik me-repaint (App.resume).
|
|
259
|
+
try {
|
|
260
|
+
screen.clearRegion()
|
|
261
|
+
} catch {}
|
|
262
|
+
try {
|
|
263
|
+
screen.close()
|
|
264
|
+
} catch {}
|
|
185
265
|
// suspend() tak boleh menggagalkan resolve: setRawMode bisa melempar
|
|
186
266
|
// di Windows bila handle sudah rusak — tanpa try/finally Promise gantung
|
|
187
267
|
// selamanya (resolve tak tercapai).
|
|
@@ -213,7 +293,9 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
213
293
|
try {
|
|
214
294
|
await fn()
|
|
215
295
|
} catch (e) {
|
|
216
|
-
|
|
296
|
+
// Pesan error dari controller/jaringan = input tak terpercaya:
|
|
297
|
+
// sanitasi (tanpa ini ESC[2J dari pesan merusak layar).
|
|
298
|
+
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
217
299
|
} finally {
|
|
218
300
|
busy = false
|
|
219
301
|
await loadRowsSafe()
|
|
@@ -221,6 +303,34 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
221
303
|
}
|
|
222
304
|
})()
|
|
223
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Batas waktu aksi jaringan (onDelete/onSelect/onSetEffort): provider/tool
|
|
308
|
+
* non-kooperatif yang gantung selamanya membuat popup mati (suspend tanpa
|
|
309
|
+
* listener/timer). Timeout = notice jujur + UI pulih; aksi telat yang
|
|
310
|
+
* akhirnya selesai diabaikan hasilnya (tanpa resolve ganda — resolve
|
|
311
|
+
* hanya lewat finish alur normal). Bisa dioverride test via opts.
|
|
312
|
+
*/
|
|
313
|
+
const withWatchdog = async <T>(fn: () => Promise<T> | T): Promise<T> => {
|
|
314
|
+
const ms = opts.actionTimeoutMs ?? 60_000
|
|
315
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
316
|
+
const p = Promise.resolve().then(fn)
|
|
317
|
+
// Rejection telat TANPA handler = unhandledRejection (bun: crash).
|
|
318
|
+
p.catch(() => {})
|
|
319
|
+
try {
|
|
320
|
+
return await Promise.race([
|
|
321
|
+
p,
|
|
322
|
+
new Promise<never>((_, reject) => {
|
|
323
|
+
timer = setTimeout(() => reject(new Error(t("ntc.timeout"))), ms)
|
|
324
|
+
try {
|
|
325
|
+
;(timer as unknown as { unref?: () => void }).unref?.()
|
|
326
|
+
} catch {}
|
|
327
|
+
}),
|
|
328
|
+
])
|
|
329
|
+
} finally {
|
|
330
|
+
if (timer) clearTimeout(timer)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
224
334
|
const loadRowsSafe = async () => {
|
|
225
335
|
try {
|
|
226
336
|
rows = await opts.loadRows()
|
|
@@ -228,50 +338,34 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
228
338
|
clampSel()
|
|
229
339
|
}
|
|
230
340
|
|
|
231
|
-
const addModel = () =>
|
|
232
|
-
runAction(async () => {
|
|
233
|
-
const providerId = await askLine({ prompt: "Provider > " })
|
|
234
|
-
// Batal (Esc/Ctrl+C di baris kosong = null) harus berhenti DI SINI —
|
|
235
|
-
// kalau lanjut ke prompt berikutnya, batal di prompt pertama terasa
|
|
236
|
-
// seperti pindah pertanyaan.
|
|
237
|
-
if (providerId == null) {
|
|
238
|
-
console.log("Canceled")
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
const model = await askLine({ prompt: "Model > " })
|
|
242
|
-
if (model == null) {
|
|
243
|
-
console.log("Canceled")
|
|
244
|
-
return
|
|
245
|
-
}
|
|
246
|
-
if (!providerId.trim() || !model.trim()) {
|
|
247
|
-
// Isian kosong (Enter tanpa teks) — beri tahu, jangan diam.
|
|
248
|
-
console.log("Canceled")
|
|
249
|
-
return
|
|
250
|
-
}
|
|
251
|
-
const prevCount = rows.length
|
|
252
|
-
rows = await opts.onAdd(providerId.trim(), model.trim())
|
|
253
|
-
// Panjang tak berubah = model sudah ada (bukan error — provider
|
|
254
|
-
// ditemukan, onAdd tak lempar). Laporkan jujur, bukan "added".
|
|
255
|
-
if (rows.length === prevCount)
|
|
256
|
-
console.log(`${glyphs.dot} ${providerId.trim()}::${model.trim()} already exists`)
|
|
257
|
-
else console.log(`${glyphs.check} added ${providerId.trim()}::${model.trim()}`)
|
|
258
|
-
clampSel()
|
|
259
|
-
})
|
|
260
|
-
|
|
261
341
|
const deleteModel = () => {
|
|
262
342
|
const row = viewRows()[sel]
|
|
263
343
|
if (!row) return
|
|
264
344
|
return runAction(async () => {
|
|
265
345
|
// Model AKTIF yang dihapus membuat prompt berikutnya kehilangan model
|
|
266
|
-
// tanpa sebab yang terlihat — sebutkan
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
346
|
+
// tanpa sebab yang terlihat — sebutkan. Konfirmasi dalam popup.
|
|
347
|
+
const form = await runForm(
|
|
348
|
+
{
|
|
349
|
+
title: t("model.deleteTitle"),
|
|
350
|
+
fields: [
|
|
351
|
+
{
|
|
352
|
+
id: "ok",
|
|
353
|
+
label: row.active
|
|
354
|
+
? t("model.delActive", { id: row.id })
|
|
355
|
+
: t("model.del", { id: row.id }),
|
|
356
|
+
kind: "confirm",
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
footer: t("model.deleteFooter"),
|
|
360
|
+
},
|
|
361
|
+
screen,
|
|
362
|
+
)
|
|
363
|
+
if (!form.cancelled && form.values?.ok === "y") {
|
|
364
|
+
rows = await withWatchdog(() => opts.onDelete(row.id))
|
|
365
|
+
notice = `${glyphs.check} ${t("ntc.deleted", { id: row.id })}`
|
|
272
366
|
} else {
|
|
273
|
-
|
|
274
|
-
rows = await opts.loadRows()
|
|
367
|
+
notice = t("common.canceled")
|
|
368
|
+
rows = await withWatchdog(() => opts.loadRows())
|
|
275
369
|
}
|
|
276
370
|
clampSel()
|
|
277
371
|
})
|
|
@@ -292,7 +386,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
292
386
|
// bocor true selamanya (= manager terkunci, terlihat hang).
|
|
293
387
|
try {
|
|
294
388
|
void runPicker({
|
|
295
|
-
title: "
|
|
389
|
+
title: t("effort.title"),
|
|
296
390
|
items: options.map((name) => ({ name, provider: "", value: name })),
|
|
297
391
|
onPick: (v) => resolvePick(v),
|
|
298
392
|
onCancel: () => resolvePick(null),
|
|
@@ -308,12 +402,18 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
308
402
|
}
|
|
309
403
|
|
|
310
404
|
const decoder: DecoderState = createDecoderState()
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
405
|
+
// Batas listener warisan SEBELUM dimatikan: setMaxListeners(0) menutupi
|
|
406
|
+
// kebocoran listener masa depan secara global — simpan & kembalikan di
|
|
407
|
+
// finish agar warning Node kembali berguna setelah sesi ini.
|
|
408
|
+
// Guard typeof: stdin bisa stub (test) tanpa API ini — anggap default 10.
|
|
409
|
+
const prevMaxListeners =
|
|
410
|
+
typeof process.stdin.getMaxListeners === "function" ? process.stdin.getMaxListeners() : 10
|
|
411
|
+
const handleManagerKeys = (keys: DecodedKey[]): boolean => {
|
|
412
|
+
if (busy || done) return true
|
|
315
413
|
try {
|
|
316
|
-
|
|
414
|
+
// Struk lama dibersihkan tiap keypress baru (transient, bukan arsip).
|
|
415
|
+
notice = null
|
|
416
|
+
for (const item of keys) {
|
|
317
417
|
// Mode cari: semua ketikan masuk ke query, Esc keluar dari mode
|
|
318
418
|
// cari — bukan tutup manager.
|
|
319
419
|
if (filter != null) {
|
|
@@ -333,10 +433,22 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
333
433
|
scroll = 0
|
|
334
434
|
continue
|
|
335
435
|
}
|
|
436
|
+
if (item.key.type === "ctrl-u") {
|
|
437
|
+
// Ctrl+U = kosongkan query tapi TETAP di mode saring (paritas
|
|
438
|
+
// readline kill-line + picker). Dulu null (keluar mode) — beda
|
|
439
|
+
// dari picker yang tetap di mode filter setelah Ctrl+U.
|
|
440
|
+
filter = ""
|
|
441
|
+
sel = 0
|
|
442
|
+
scroll = 0
|
|
443
|
+
continue
|
|
444
|
+
}
|
|
336
445
|
// Backspace & Del sama-sama memangkas query (tanpa kursor,
|
|
337
446
|
// Del maju = grapheme terakhir juga). Query habis = keluar mode.
|
|
447
|
+
// toGraphemes: emoji/flag utuh (paritas picker/form/askLine).
|
|
338
448
|
if (item.key.type === "backspace" || item.key.type === "delete") {
|
|
339
|
-
|
|
449
|
+
const g = toGraphemes(filter)
|
|
450
|
+
g.pop()
|
|
451
|
+
filter = g.join("")
|
|
340
452
|
if (!filter) filter = null
|
|
341
453
|
sel = 0
|
|
342
454
|
scroll = 0
|
|
@@ -348,16 +460,37 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
348
460
|
item.key.type === "ctrl-d"
|
|
349
461
|
) {
|
|
350
462
|
finish()
|
|
351
|
-
return
|
|
463
|
+
return true
|
|
352
464
|
}
|
|
353
465
|
if (item.key.type === "up") sel = Math.max(0, sel - 1)
|
|
354
466
|
else if (item.key.type === "down") {
|
|
355
467
|
const n = viewRows().length
|
|
356
468
|
sel = n ? Math.min(n - 1, sel + 1) : 0
|
|
469
|
+
} else if (item.key.type === "home") {
|
|
470
|
+
// Home/End = lompat atas/bawah daftar (paritas picker/App).
|
|
471
|
+
sel = 0
|
|
472
|
+
scroll = 0
|
|
473
|
+
} else if (item.key.type === "end") {
|
|
474
|
+
const n = viewRows().length
|
|
475
|
+
sel = n ? Math.max(0, n - 1) : 0
|
|
476
|
+
} else if (item.key.type === "pageup" || item.key.type === "pagedown") {
|
|
477
|
+
// Scroll daftar per halaman (paritas picker/App). Gagal-di-kode-lama:
|
|
478
|
+
// memakai panjang LIST sebagai jatah visible → kondisi tak pernah
|
|
479
|
+
// benar → PgUp/PgDn mati total.
|
|
480
|
+
const list = viewRows()
|
|
481
|
+
const v = visibleRows()
|
|
482
|
+
if (list.length > v) {
|
|
483
|
+
const page = Math.max(1, v - 1)
|
|
484
|
+
const dir = item.key.type === "pageup" ? -page : page
|
|
485
|
+
scroll = Math.max(0, Math.min(Math.max(0, list.length - v), scroll + dir))
|
|
486
|
+
sel = Math.max(0, Math.min(list.length - 1, sel))
|
|
487
|
+
if (sel < scroll) sel = scroll
|
|
488
|
+
if (sel >= scroll + v) sel = scroll + v - 1
|
|
489
|
+
}
|
|
357
490
|
} else if (item.key.type === "enter") {
|
|
358
491
|
const row = viewRows()[sel]
|
|
359
|
-
if (!row) return // daftar kosong: jangan tutup (footer bilang select)
|
|
360
|
-
if (busy) return
|
|
492
|
+
if (!row) return true // daftar kosong: jangan tutup (footer bilang select)
|
|
493
|
+
if (busy) return true
|
|
361
494
|
busy = true
|
|
362
495
|
suspend()
|
|
363
496
|
// Alur: picker effort DULU, baru select+simpan. Dibalik (select
|
|
@@ -373,36 +506,39 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
373
506
|
return
|
|
374
507
|
}
|
|
375
508
|
try {
|
|
376
|
-
await opts.onSelect(row.id)
|
|
509
|
+
await withWatchdog(() => opts.onSelect(row.id))
|
|
377
510
|
// "skip" = model tanpa thinking: select langsung, effort
|
|
378
511
|
// tersimpan tak disentuh (aman — pengiriman effort juga
|
|
379
512
|
// di-gate per keluarga, jadi nilai basi tak pernah terkirim).
|
|
380
513
|
if (picked !== "skip" && opts.onSetEffort) {
|
|
381
|
-
await opts.onSetEffort(row.id, picked)
|
|
382
|
-
|
|
514
|
+
await withWatchdog(() => opts.onSetEffort!(row.id, picked))
|
|
515
|
+
// Struk via notice (rute yang sama dengan receipts lain);
|
|
516
|
+
// manager langsung tutup sesudahnya, jadi baris ini hanya
|
|
517
|
+
// terlihat bila alur berubah me-resume — badge effort di
|
|
518
|
+
// daftar tetap sumber kebenaran yang bisa dibuka ulang.
|
|
519
|
+
notice = t("effort.saved", { effort: picked })
|
|
383
520
|
}
|
|
384
|
-
} catch (e) {
|
|
385
|
-
// Jangan tutup diam-diam: pilih model yang gagal harus
|
|
386
|
-
// terlihat, bukan dianggap sukses (manager lalu hilang).
|
|
387
|
-
console.log(`${glyphs.cross} ${(e as Error).message}`)
|
|
388
|
-
} finally {
|
|
389
521
|
finish()
|
|
522
|
+
} catch (e) {
|
|
523
|
+
// Pilih model yang gagal HARUS terlihat dan kembali ke daftar
|
|
524
|
+
// untuk retry (pola resume() seperti a/d/e provider-manager),
|
|
525
|
+
// bukan menutup manager dan kehilangan konteks daftar.
|
|
526
|
+
// Pesan controller = input tak terpercaya: sanitasi.
|
|
527
|
+
notice = `${glyphs.cross} ${sanitizeAnsiLine((e as Error).message)}`
|
|
528
|
+
busy = false
|
|
529
|
+
await loadRowsSafe()
|
|
530
|
+
resume()
|
|
390
531
|
}
|
|
391
532
|
} catch {
|
|
392
533
|
finish()
|
|
393
534
|
}
|
|
394
535
|
})()
|
|
395
|
-
return
|
|
396
|
-
} else if (item.key.type === "ctrl-n") {
|
|
397
|
-
// Tambah model — shortcut non-ketik agar ketikan huruf apa pun
|
|
398
|
-
// (termasuk a/d) selalu jadi query cari, di Windows & Linux.
|
|
399
|
-
void addModel()
|
|
400
|
-
return
|
|
536
|
+
return true
|
|
401
537
|
} else if (item.key.type === "delete") {
|
|
402
538
|
// Di sini filter selalu null (mode cari ditangani di atas):
|
|
403
539
|
// hapus model ter-highlight (dengan konfirmasi di deleteModel).
|
|
404
540
|
void deleteModel()
|
|
405
|
-
return
|
|
541
|
+
return true
|
|
406
542
|
} else if (item.key.type === "char") {
|
|
407
543
|
// Ketik langsung menyaring — tanpa awalan apa pun.
|
|
408
544
|
filter = item.key.ch
|
|
@@ -411,6 +547,17 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
411
547
|
}
|
|
412
548
|
}
|
|
413
549
|
render()
|
|
550
|
+
return false
|
|
551
|
+
} catch {
|
|
552
|
+
finish()
|
|
553
|
+
return true
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const managerPump = createKeyStreamPump({ state: decoder, onKeys: handleManagerKeys })
|
|
557
|
+
const onData = (chunk: Buffer) => {
|
|
558
|
+
resetIdle()
|
|
559
|
+
try {
|
|
560
|
+
managerPump.push(chunk)
|
|
414
561
|
} catch {
|
|
415
562
|
finish()
|
|
416
563
|
}
|
|
@@ -425,10 +572,18 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
425
572
|
process.stdin.setMaxListeners(0)
|
|
426
573
|
process.stdin.on("data", onData)
|
|
427
574
|
process.stdout.on("resize", onResize)
|
|
575
|
+
attached = true
|
|
428
576
|
resetIdle()
|
|
429
577
|
render()
|
|
430
|
-
} catch {
|
|
431
|
-
|
|
578
|
+
} catch (e) {
|
|
579
|
+
// Setup gagal = tutup + BERSUARA (Fase D): jendela kosong bisu adalah
|
|
580
|
+
// kelas bug yang hanya bisa diburu bila terlihat.
|
|
581
|
+
try {
|
|
582
|
+
finish()
|
|
583
|
+
} catch {}
|
|
584
|
+
try {
|
|
585
|
+
console.log(`⚠ ${t("model.failOpen", { msg: String((e as Error)?.message ?? e) })}`)
|
|
586
|
+
} catch {}
|
|
432
587
|
}
|
|
433
588
|
})
|
|
434
589
|
}
|