minicode-ai 0.27.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cli/args.ts +184 -57
- package/cli/bootstrap/presentation-bridge.ts +383 -0
- package/cli/commands/acp.ts +45 -29
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +18 -15
- package/cli/commands/exec.ts +41 -89
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +73 -44
- package/cli/context-command-run.ts +30 -18
- package/cli/index.ts +51 -100
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +241 -485
- package/cli/tui.ts +303 -100
- package/docs/TERMINAL_CONTRACT.md +258 -73
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +17 -32
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/environment.md +1 -2
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +2 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +144 -68
- package/src/app/tool-layer.ts +38 -16
- package/src/config.ts +64 -104
- package/src/constants.ts +4 -6
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/atomic-write.ts +31 -59
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +31 -8
- package/src/policy/context.ts +62 -36
- package/src/policy/executor.ts +17 -7
- package/src/policy/jail.ts +6 -8
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/anthropic.ts +16 -5
- package/src/providers/provision.ts +6 -56
- package/src/providers/responses.ts +38 -7
- package/src/providers/sse-bounds.ts +6 -4
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/db/runs.ts +397 -0
- package/src/session/db/schema.ts +358 -0
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +74 -998
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/db/schema.ts +325 -0
- package/src/task/db/types.ts +269 -0
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +92 -1021
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +47 -23
- package/src/ui/i18n/id.ts +76 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +82 -61
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +158 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +35 -19
package/src/ui/screens/form.ts
CHANGED
|
@@ -18,10 +18,11 @@ import {
|
|
|
18
18
|
type DecoderState,
|
|
19
19
|
toGraphemes,
|
|
20
20
|
} from "../input/prompt-engine.ts"
|
|
21
|
+
import { type HintItem, hintLine } from "../render/hint.ts"
|
|
21
22
|
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
22
23
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
23
|
-
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
24
|
-
import {
|
|
24
|
+
import { displayWidth, truncateToWidth, wrapByWidth } from "../render/width.ts"
|
|
25
|
+
import type { AltScreen } from "../runtime/screen.ts"
|
|
25
26
|
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
26
27
|
import { createIdleTimer } from "./lifecycle.ts"
|
|
27
28
|
|
|
@@ -40,7 +41,8 @@ export interface FormField {
|
|
|
40
41
|
export interface FormSpec {
|
|
41
42
|
title: string
|
|
42
43
|
fields: FormField[]
|
|
43
|
-
|
|
44
|
+
/** Override hint (mis. Enter = hapus pada dialog konfirmasi). */
|
|
45
|
+
footerHints?: readonly HintItem[]
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export interface FormResult {
|
|
@@ -82,6 +84,31 @@ const dim = (s: string): string => c.dim(s)
|
|
|
82
84
|
/** Lebar kotak form: `popupBoxWidth` — paritas picker/model/provider (AUD-006). */
|
|
83
85
|
const formBoxWidth = (cols: number): number => popupBoxWidth(cols)
|
|
84
86
|
|
|
87
|
+
/** Hint default mengikuti jenis field aktif: select/confirm butuh panah. */
|
|
88
|
+
function defaultFooterHints(st: FieldState | undefined): HintItem[] {
|
|
89
|
+
// Select/confirm: panah adalah aksi utama; Tab tetap berlaku tetapi tidak
|
|
90
|
+
// diumumkan agar hint tetap satu baris di popup 48 kolom (80-col terminal).
|
|
91
|
+
if (st?.def.kind === "select") {
|
|
92
|
+
return [
|
|
93
|
+
{ key: glyphs.leftRight, label: t("hint.select") },
|
|
94
|
+
{ key: "Enter", label: t("hint.save") },
|
|
95
|
+
{ key: "Esc", label: t("hint.cancel") },
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
if (st?.def.kind === "confirm") {
|
|
99
|
+
return [
|
|
100
|
+
{ key: `${glyphs.leftRight}/y/n`, label: t("hint.select") },
|
|
101
|
+
{ key: "Enter", label: t("hint.save") },
|
|
102
|
+
{ key: "Esc", label: t("hint.cancel") },
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
return [
|
|
106
|
+
{ key: "Tab", label: t("hint.move") },
|
|
107
|
+
{ key: "Enter", label: t("hint.save") },
|
|
108
|
+
{ key: "Esc", label: t("hint.cancel") },
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
|
|
85
112
|
function toState(def: FormField): FieldState {
|
|
86
113
|
if (def.kind === "select") {
|
|
87
114
|
const n = Math.max(1, def.options?.length ?? 1)
|
|
@@ -176,9 +203,8 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
176
203
|
idle.reset()
|
|
177
204
|
}
|
|
178
205
|
|
|
179
|
-
// Lebar
|
|
180
|
-
const
|
|
181
|
-
const width = () => boxW
|
|
206
|
+
// Lebar dinamis mengikuti terminal saat resize (tetap stabil saat error muncul/hilang).
|
|
207
|
+
const width = () => formBoxWidth(screen.cols || 80)
|
|
182
208
|
const innerW = () => Math.max(8, width() - 4)
|
|
183
209
|
|
|
184
210
|
// Baris nilai field aktif (indeks dalam body) untuk parkir kursor.
|
|
@@ -190,13 +216,17 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
190
216
|
let activeCol = -1
|
|
191
217
|
fields.forEach((st, fi) => {
|
|
192
218
|
const active = fi === idx
|
|
219
|
+
const marker = active ? c.accent(glyphs.arrow) : " "
|
|
220
|
+
const cleanLabel = sanitizeAnsiLine(st.def.label)
|
|
193
221
|
if (st.def.kind === "text" || st.def.kind === "secret") {
|
|
194
222
|
const shown =
|
|
195
223
|
st.def.kind === "secret" ? glyphs.mask.repeat(toGraphemes(st.text).length) : st.text
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
//
|
|
199
|
-
|
|
224
|
+
const inlinePrefix = `${marker} ${cleanLabel}: `
|
|
225
|
+
const inlineRoom = w - displayWidth(stripAnsi(inlinePrefix))
|
|
226
|
+
// Tata letak bertumpuk saat label panjang menyisakan ruang < 20 kolom
|
|
227
|
+
// (mis. Base URL preset di wizard); pertahankan inline untuk label pendek.
|
|
228
|
+
const stacked = inlineRoom < 20
|
|
229
|
+
const maxV = stacked ? Math.max(8, w - 2) : Math.max(8, inlineRoom)
|
|
200
230
|
const pts = toGraphemes(shown)
|
|
201
231
|
let start = Math.max(0, Math.min(st.viewStart, st.cursor))
|
|
202
232
|
if (st.cursor < start) start = st.cursor
|
|
@@ -204,32 +234,47 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
204
234
|
start++
|
|
205
235
|
st.viewStart = start
|
|
206
236
|
const vis = sliceByWidth(pts, start, maxV).join("")
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
237
|
+
if (stacked) {
|
|
238
|
+
for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
|
|
239
|
+
if (active) {
|
|
240
|
+
activeCol = 2 + displayWidth(pts.slice(start, st.cursor).join("")) + 1
|
|
241
|
+
}
|
|
242
|
+
body.push(cut(` ${vis}`))
|
|
243
|
+
} else {
|
|
244
|
+
if (active) {
|
|
245
|
+
activeCol =
|
|
246
|
+
displayWidth(stripAnsi(inlinePrefix)) +
|
|
247
|
+
displayWidth(pts.slice(start, st.cursor).join("")) +
|
|
248
|
+
1
|
|
249
|
+
}
|
|
250
|
+
body.push(cut(`${inlinePrefix}${vis}`))
|
|
215
251
|
}
|
|
216
|
-
body.push(cut(`${prefix}${vis}`))
|
|
217
252
|
activeRow = active ? body.length - 1 : activeRow
|
|
218
253
|
} else if (st.def.kind === "select") {
|
|
219
254
|
const opts = st.def.options ?? []
|
|
220
255
|
const cur = sanitizeAnsiLine(opts[st.selectIdx] ?? "")
|
|
221
|
-
const
|
|
256
|
+
const ctrl = `${dim(glyphs.chevronLeft)} ${cur} ${dim(glyphs.chevronRight)}`
|
|
257
|
+
const inline = `${marker} ${cleanLabel}: ${ctrl}`
|
|
222
258
|
if (active) activeCol = -1 // select tanpa kursor ketik
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
259
|
+
if (displayWidth(stripAnsi(inline)) > w) {
|
|
260
|
+
for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
|
|
261
|
+
body.push(cut(` ${ctrl}`))
|
|
262
|
+
} else {
|
|
263
|
+
body.push(cut(inline))
|
|
264
|
+
}
|
|
226
265
|
activeRow = active ? body.length - 1 : activeRow
|
|
227
266
|
} else {
|
|
228
|
-
// Confirm: Ya/Tidak toggle.
|
|
229
|
-
const marker = active ? c.accent("›") : " "
|
|
267
|
+
// Confirm: Ya/Tidak toggle (panah/y-n — sama seperti select).
|
|
230
268
|
const val = st.confirmed ? c.accent(t("form.yes")) : t("form.no")
|
|
269
|
+
const ctrl = `${dim(glyphs.chevronLeft)} ${val} ${dim(glyphs.chevronRight)}`
|
|
270
|
+
const inline = `${marker} ${cleanLabel}: ${ctrl}`
|
|
231
271
|
if (active) activeCol = -1
|
|
232
|
-
|
|
272
|
+
if (displayWidth(stripAnsi(inline)) > w) {
|
|
273
|
+
for (const hl of wrapByWidth(`${marker} ${cleanLabel}`, w)) body.push(cut(hl))
|
|
274
|
+
body.push(cut(` ${ctrl}`))
|
|
275
|
+
} else {
|
|
276
|
+
body.push(cut(inline))
|
|
277
|
+
}
|
|
233
278
|
activeRow = active ? body.length - 1 : activeRow
|
|
234
279
|
}
|
|
235
280
|
if (st.error) body.push(cut(c.error(` ${sanitizeAnsiLine(st.error)}`)))
|
|
@@ -243,7 +288,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
243
288
|
// saja), draft tidak hilang tanpa jejak.
|
|
244
289
|
footer: idleWarned
|
|
245
290
|
? c.error(t("form.idleWarning", { s: Math.ceil(IDLE_CANCEL_MS / 1000) }))
|
|
246
|
-
: (spec.
|
|
291
|
+
: hintLine(spec.footerHints ?? defaultFooterHints(fields[idx])),
|
|
247
292
|
// Lebar beku (paritas picker/manager — tak bernapas saat error
|
|
248
293
|
// muncul/hilang).
|
|
249
294
|
minWidth: width(),
|
|
@@ -272,12 +317,12 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
272
317
|
const stripped = stripAnsi(box.lines[li] ?? "")
|
|
273
318
|
const leftPad = boxLeftPad(stripped)
|
|
274
319
|
const contentW = displayWidth(stripped) - leftPad
|
|
275
|
-
const
|
|
320
|
+
const maxCol = leftPad + 2 + w + 1
|
|
321
|
+
const raw =
|
|
322
|
+
activeCol >= 0 ? Math.min(maxCol, leftPad + activeCol + 2) : leftPad + contentW + 1
|
|
276
323
|
const col = Math.max(1, Math.min(screen.cols || 80, raw))
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
// tearing di emulator tanpa ?2026.
|
|
280
|
-
process.stdout.write(`${SYNC_UPDATE_START}\x1b[${row};${col}H\x1b[?25h${SYNC_UPDATE_END}`)
|
|
324
|
+
// Lewat screen.moveCursor agar RESET_ATTRS + `\x1b[6 q` + blok sync konsisten.
|
|
325
|
+
screen.moveCursor(row, col)
|
|
281
326
|
}
|
|
282
327
|
} catch {}
|
|
283
328
|
return { activeRow, activeCol }
|
|
@@ -335,9 +380,9 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
335
380
|
const clean = ins
|
|
336
381
|
.replace(/\r\n|\r/g, " ")
|
|
337
382
|
.replace(/\t/g, " ")
|
|
338
|
-
// Kontrol dibuang (kecuali newline yang sudah jadi spasi).
|
|
383
|
+
// Kontrol C0 + C1 dibuang (kecuali newline yang sudah jadi spasi).
|
|
339
384
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: sanitasi input form
|
|
340
|
-
.replace(/[\u0000-\u001f\u007f]/g, "")
|
|
385
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
|
|
341
386
|
if (!clean) return
|
|
342
387
|
const pts = toGraphemes(st.text)
|
|
343
388
|
const at = Math.max(0, Math.min(st.cursor, pts.length))
|
|
@@ -384,7 +429,7 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
384
429
|
cur.error = null
|
|
385
430
|
return true
|
|
386
431
|
}
|
|
387
|
-
const initial = typeof cur.def.initial === "string" ? cur.def.initial : ""
|
|
432
|
+
const initial = typeof cur.def.initial === "string" ? sanitizeAnsiLine(cur.def.initial) : ""
|
|
388
433
|
if (cur.text === initial) return false
|
|
389
434
|
cur.text = initial
|
|
390
435
|
cur.cursor = toGraphemes(initial).length
|
|
@@ -8,12 +8,15 @@ import {
|
|
|
8
8
|
type DecoderState,
|
|
9
9
|
toGraphemes,
|
|
10
10
|
} from "../input/prompt-engine.ts"
|
|
11
|
+
import { formatError } from "../render/errors.ts"
|
|
11
12
|
import { hintLine } from "../render/hint.ts"
|
|
13
|
+
import { listRow, tailFilterWindow } from "../render/list.ts"
|
|
14
|
+
import { type NoticeKind, paintNoticeLines } from "../render/notice.ts"
|
|
12
15
|
import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
13
16
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
14
|
-
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
17
|
+
import { displayWidth, truncateToWidth, wrapByWidth } from "../render/width.ts"
|
|
15
18
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
16
|
-
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
19
|
+
import { boxLeftPad, canRenderModal, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
17
20
|
import { runForm } from "./form.ts"
|
|
18
21
|
import { createIdleTimer } from "./lifecycle.ts"
|
|
19
22
|
import { runPicker } from "./picker.ts"
|
|
@@ -61,6 +64,7 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
|
|
|
61
64
|
|
|
62
65
|
/** Lebar kotak /model: `popupBoxWidth` (AUD-006, satu sumber width+maxWidth). */
|
|
63
66
|
const modalBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
|
|
67
|
+
const MODAL_MAX_HEIGHT = 15
|
|
64
68
|
|
|
65
69
|
export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
|
|
66
70
|
let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
|
|
@@ -82,26 +86,23 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
82
86
|
// redup DALAM popup, bukan console.log ke scrollback. Dibersihkan tiap
|
|
83
87
|
// keypress baru — terlihat sampai tombol berikut ditekan.
|
|
84
88
|
let notice: string | null = null
|
|
89
|
+
let noticeKind: NoticeKind = "info"
|
|
85
90
|
|
|
86
91
|
return new Promise<void>((resolve) => {
|
|
92
|
+
const width = () => Math.max(8, modalBoxWidth() - 4)
|
|
93
|
+
const renderedNoticeLines = (): string[] =>
|
|
94
|
+
notice ? paintNoticeLines(noticeKind, notice).flatMap((l) => wrapByWidth(l, width())) : []
|
|
87
95
|
const visibleRows = () => {
|
|
88
|
-
const rows = process.stdout.rows || 24
|
|
89
|
-
// Chrome tetap: 2 border + 1
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
// dari atas). Semua angka pas dengan `room = rows − 2` di dialogBox.
|
|
93
|
-
const fixed = 4 + (notice ? 1 : 0)
|
|
96
|
+
const rows = Math.min(process.stdout.rows || 24, MODAL_MAX_HEIGHT)
|
|
97
|
+
// Chrome tetap: 2 border + 1 judul + 1 pencarian + 1 footer (dipin `dialogBox`);
|
|
98
|
+
// notice menyusutkan daftar agar kotak tetap ringkas dan hint tak hilang.
|
|
99
|
+
const fixed = 5 + renderedNoticeLines().length
|
|
94
100
|
return Math.max(1, Math.min(rows - fixed, 8))
|
|
95
101
|
}
|
|
96
|
-
// Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
|
|
97
|
-
// tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
|
|
98
|
-
// dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
|
|
99
|
-
// = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
|
|
100
|
-
const width = () => Math.max(8, modalBoxWidth() - 4)
|
|
101
102
|
|
|
102
|
-
// Isi MINIMAL dialog /model
|
|
103
|
-
//
|
|
104
|
-
const bodyLinesModal = (): string[] => {
|
|
103
|
+
// Isi MINIMAL dialog /model; footer dipin lewat `spec.footer` agar aman
|
|
104
|
+
// dari pemotongan saat notice error panjang membungkus banyak baris.
|
|
105
|
+
const bodyLinesModal = (): { lines: string[]; footer: string; filterShown: string } => {
|
|
105
106
|
const list = viewRows()
|
|
106
107
|
const v = visibleRows()
|
|
107
108
|
if (sel < scroll) scroll = sel
|
|
@@ -110,7 +111,9 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
110
111
|
const cut = (s: string) => truncateToWidth(s, w)
|
|
111
112
|
const view = list.slice(scroll, scroll + v)
|
|
112
113
|
const lines: string[] = []
|
|
113
|
-
|
|
114
|
+
const filterBudget = Math.max(4, w - 3 - displayWidth(glyphs.caret))
|
|
115
|
+
const filterShown = tailFilterWindow(filter ?? "", filterBudget)
|
|
116
|
+
lines.push(cut(`${dim(">")} ${c.brightCyan(filterShown)}${c.accent(glyphs.caret)}`))
|
|
114
117
|
if (!list.length) {
|
|
115
118
|
lines.push(cut(dim(` ${filter == null ? t("model.empty") : t("model.noMatch")}`)))
|
|
116
119
|
} else {
|
|
@@ -122,67 +125,64 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
122
125
|
// nama yang dipotong, status yang selamat.
|
|
123
126
|
const active = row.active ? ` (${t("common.active")})` : ""
|
|
124
127
|
const nameBudget = Math.max(8, w - 4 - displayWidth(active))
|
|
125
|
-
const label = `${truncateToWidth(`${sanitizeAnsiLine(row.id)}${badge}`, nameBudget,
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
else lines.push(` ${dim(label)}`)
|
|
128
|
+
const label = `${truncateToWidth(`${sanitizeAnsiLine(row.id)}${badge}`, nameBudget, glyphs.ellipsis)}${active}`
|
|
129
|
+
// Kolom marker dipakai bersama (listRow): label tak bergeser saat
|
|
130
|
+
// seleksi berpindah dan marker `›` tidak hilang tanpa warna.
|
|
131
|
+
lines.push(listRow(label, picked))
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
|
-
|
|
133
|
-
// Hint
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
]),
|
|
145
|
-
),
|
|
146
|
-
)
|
|
147
|
-
return lines
|
|
134
|
+
for (const line of renderedNoticeLines()) lines.push(cut(line))
|
|
135
|
+
// Hint akurat per mode: saat filter aktif, Esc keluar dari pencarian
|
|
136
|
+
// (bukan menutup) dan Del mengedit query (jangan iklankan Del delete).
|
|
137
|
+
const escLabel = filter == null ? t("hint.cancel") : t("hint.back")
|
|
138
|
+
const footer = hintLine([
|
|
139
|
+
{ key: glyphs.upDown, label: t("hint.move") },
|
|
140
|
+
{ key: "Enter", label: t("hint.select") },
|
|
141
|
+
{ key: "Tab", label: t("hint.effort") },
|
|
142
|
+
...(filter == null ? [{ key: "Del", label: t("hint.delete") }] : []),
|
|
143
|
+
{ key: "Esc", label: escLabel },
|
|
144
|
+
])
|
|
145
|
+
return { lines, footer, filterShown }
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
const render = () => {
|
|
151
|
-
|
|
149
|
+
const { lines, footer, filterShown } = bodyLinesModal()
|
|
150
|
+
// Region kotak di atas transkrip; lebar mengikuti terminal saat resize.
|
|
152
151
|
const box = dialogBox(
|
|
153
152
|
{
|
|
154
|
-
title: "",
|
|
155
|
-
body:
|
|
153
|
+
title: t("out.titleModels"),
|
|
154
|
+
body: lines,
|
|
155
|
+
footer,
|
|
156
156
|
minWidth: modalBoxWidth(),
|
|
157
157
|
maxWidth: modalBoxWidth(),
|
|
158
|
-
maxHeight:
|
|
158
|
+
maxHeight: MODAL_MAX_HEIGHT,
|
|
159
159
|
},
|
|
160
160
|
screen.cols,
|
|
161
161
|
screen.rows,
|
|
162
162
|
)
|
|
163
163
|
screen.paintRegion(box.lines, box.topRow)
|
|
164
|
-
// Parkir kursor
|
|
165
|
-
// baris search body[0]): kolom = padding + border + spasi + "> " +
|
|
166
|
-
// lebar filter + 1. Parkir di ujung baris (padding void) terlihat
|
|
167
|
-
// rusak — kursor melayang jauh dari █.
|
|
164
|
+
// Parkir kursor tepat sebelum caret di dalam kotak dan blok sync-update.
|
|
168
165
|
try {
|
|
169
166
|
const li = Math.min(box.lines.length - 1, box.bodyTop)
|
|
170
167
|
const row = box.topRow + li
|
|
171
168
|
const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
|
|
169
|
+
const maxCol = leftPad + 2 + width() + 1
|
|
172
170
|
const col = Math.max(
|
|
173
171
|
1,
|
|
174
172
|
Math.min(
|
|
175
173
|
screen.cols || 80,
|
|
176
|
-
|
|
174
|
+
maxCol,
|
|
175
|
+
leftPad + 4 + displayWidth(stripAnsi(filterShown)) + 1,
|
|
177
176
|
),
|
|
178
177
|
)
|
|
179
|
-
|
|
178
|
+
screen.moveCursor(row, col)
|
|
180
179
|
} catch {}
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
// Popup butuh layar mampu; selain itu tolak BERSUARA + batal.
|
|
184
183
|
const screen: AltScreen = openAltScreen()
|
|
185
|
-
const useModal =
|
|
184
|
+
const useModal =
|
|
185
|
+
screen.ok && canRenderModal(process.stdout.columns || 80, process.stdout.rows || 24)
|
|
186
186
|
if (!useModal) {
|
|
187
187
|
try {
|
|
188
188
|
console.log(`⚠ ${t("gate.tuiModel")}`)
|
|
@@ -215,7 +215,14 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
215
215
|
const suspend = () => {
|
|
216
216
|
idle.clear()
|
|
217
217
|
attached = false
|
|
218
|
-
|
|
218
|
+
// Hapus kotak induk sebelum sub-modal (effort picker / form konfirmasi)
|
|
219
|
+
// tampil agar bingkai tidak tumpang-tindih; saat finish `done` sudah true.
|
|
220
|
+
if (!done) {
|
|
221
|
+
try {
|
|
222
|
+
screen.clearRegion()
|
|
223
|
+
} catch {}
|
|
224
|
+
screen.setCursorVisible(false)
|
|
225
|
+
}
|
|
219
226
|
// TANPA pause — stdin mengalir seumur proses (lihat cleanup askLine).
|
|
220
227
|
try {
|
|
221
228
|
process.stdin.setRawMode(false)
|
|
@@ -290,9 +297,10 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
290
297
|
try {
|
|
291
298
|
await fn()
|
|
292
299
|
} catch (e) {
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
notice =
|
|
300
|
+
// Formatter kanonik: redaksi credential + saran tindakan. Notice
|
|
301
|
+
// error dirender merah oleh paintNoticeLines (bukan teks redup).
|
|
302
|
+
notice = formatError(e)
|
|
303
|
+
noticeKind = "error"
|
|
296
304
|
} finally {
|
|
297
305
|
busy = false
|
|
298
306
|
await loadRowsSafe()
|
|
@@ -335,15 +343,21 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
335
343
|
kind: "confirm",
|
|
336
344
|
},
|
|
337
345
|
],
|
|
338
|
-
|
|
346
|
+
footerHints: [
|
|
347
|
+
{ key: `${glyphs.leftRight}/y/n`, label: t("hint.select") },
|
|
348
|
+
{ key: "Enter", label: t("hint.delete") },
|
|
349
|
+
{ key: "Esc", label: t("hint.cancel") },
|
|
350
|
+
],
|
|
339
351
|
},
|
|
340
352
|
screen,
|
|
341
353
|
)
|
|
342
354
|
if (!form.cancelled && form.values?.ok === "y") {
|
|
343
355
|
rows = await withWatchdog(() => opts.onDelete(row.id))
|
|
344
|
-
notice =
|
|
356
|
+
notice = t("ntc.deleted", { id: row.id })
|
|
357
|
+
noticeKind = "success"
|
|
345
358
|
} else {
|
|
346
359
|
notice = t("common.canceled")
|
|
360
|
+
noticeKind = "info"
|
|
347
361
|
rows = await withWatchdog(() => opts.loadRows())
|
|
348
362
|
}
|
|
349
363
|
clampSel()
|
|
@@ -366,6 +380,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
366
380
|
try {
|
|
367
381
|
void runPicker({
|
|
368
382
|
title: t("effort.title"),
|
|
383
|
+
showTitle: true,
|
|
384
|
+
screen,
|
|
369
385
|
items: options.map((name) => ({ name, provider: "", value: name })),
|
|
370
386
|
onPick: (v) => resolvePick(v),
|
|
371
387
|
onCancel: () => resolvePick(null),
|
|
@@ -389,9 +405,11 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
389
405
|
typeof process.stdin.getMaxListeners === "function" ? process.stdin.getMaxListeners() : 10
|
|
390
406
|
const handleManagerKeys = (keys: DecodedKey[]): boolean => {
|
|
391
407
|
if (busy || done) return true
|
|
408
|
+
if (!keys.length) return false
|
|
392
409
|
try {
|
|
393
410
|
// Struk lama dibersihkan tiap keypress baru (transient, bukan arsip).
|
|
394
411
|
notice = null
|
|
412
|
+
noticeKind = "info"
|
|
395
413
|
for (const item of keys) {
|
|
396
414
|
// Mode cari: semua ketikan masuk ke query, Esc keluar dari mode
|
|
397
415
|
// cari — bukan tutup manager.
|
|
@@ -441,8 +459,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
441
459
|
finish()
|
|
442
460
|
return true
|
|
443
461
|
}
|
|
444
|
-
if (item.key.type === "up") sel = Math.max(0, sel - 1)
|
|
445
|
-
else if (item.key.type === "down") {
|
|
462
|
+
if (item.key.type === "up" || item.key.type === "wheelup") sel = Math.max(0, sel - 1)
|
|
463
|
+
else if (item.key.type === "down" || item.key.type === "wheeldown") {
|
|
446
464
|
const n = viewRows().length
|
|
447
465
|
sel = n ? Math.min(n - 1, sel + 1) : 0
|
|
448
466
|
} else if (item.key.type === "home") {
|
|
@@ -484,8 +502,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
484
502
|
// Pilih model yang gagal HARUS terlihat dan kembali ke daftar
|
|
485
503
|
// untuk retry (pola resume() seperti a/d/e provider-manager),
|
|
486
504
|
// bukan menutup manager dan kehilangan konteks daftar.
|
|
487
|
-
|
|
488
|
-
|
|
505
|
+
notice = formatError(e)
|
|
506
|
+
noticeKind = "error"
|
|
489
507
|
busy = false
|
|
490
508
|
await loadRowsSafe()
|
|
491
509
|
resume()
|
|
@@ -508,17 +526,20 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
508
526
|
// user menekan Tab, layar tak berubah, dan itu terbaca sebagai
|
|
509
527
|
// "minicode macet". Nyatakan alasannya, tetap di daftar.
|
|
510
528
|
notice = t("effort.noThinking")
|
|
529
|
+
noticeKind = "info"
|
|
511
530
|
} else if (picked) {
|
|
512
531
|
await withWatchdog(() => opts.onSetEffort!(row.id, picked))
|
|
513
532
|
// Notice terlihat di daftar (manager tetap terbuka) —
|
|
514
533
|
// inilah kehidupan baru `effort.saved` setelah A5.
|
|
515
534
|
notice = t("effort.saved", { effort: picked })
|
|
535
|
+
noticeKind = "success"
|
|
516
536
|
}
|
|
517
537
|
busy = false
|
|
518
538
|
await loadRowsSafe()
|
|
519
539
|
resume()
|
|
520
540
|
} catch (e) {
|
|
521
|
-
notice =
|
|
541
|
+
notice = formatError(e)
|
|
542
|
+
noticeKind = "error"
|
|
522
543
|
busy = false
|
|
523
544
|
await loadRowsSafe()
|
|
524
545
|
resume()
|
|
@@ -556,7 +577,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
556
577
|
|
|
557
578
|
const onResize = () => render()
|
|
558
579
|
|
|
559
|
-
|
|
580
|
+
screen.setCursorVisible(false)
|
|
560
581
|
try {
|
|
561
582
|
process.stdin.setRawMode(true)
|
|
562
583
|
process.stdin.resume()
|