minicode-ai 0.23.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/tui.ts +28 -2
- package/docs/README.md +2 -2
- package/docs/SUMMARY.md +10 -19
- package/docs/TERMINAL_CONTRACT.md +82 -28
- 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 +3 -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/config.ts +2 -0
- package/src/constants.ts +3 -0
- package/src/lib/safe-open.ts +21 -12
- package/src/memory/vector.ts +0 -31
- package/src/policy/context-window.ts +0 -33
- 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 +3 -3
- package/src/providers/detect.ts +27 -0
- package/src/providers/provision.ts +15 -1
- 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/footer.ts +41 -29
- package/src/ui/i18n/en.ts +4 -0
- package/src/ui/i18n/id.ts +4 -0
- package/src/ui/render/activity-group.ts +1 -0
- package/src/ui/render/ledger.ts +1 -9
- package/src/ui/render/logo.ts +0 -5
- package/src/ui/render/markdown-table.ts +0 -3
- package/src/ui/render/table-grid.ts +0 -3
- package/src/ui/render/theme.ts +31 -5
- package/src/ui/runtime/screen.ts +7 -1
- package/src/ui/screens/dialog.ts +45 -81
- package/src/ui/screens/form.ts +10 -10
- package/src/ui/screens/model-manager.ts +7 -10
- package/src/ui/screens/picker.ts +8 -11
- package/src/ui/screens/provider-manager.ts +9 -13
- package/src/ui/tui/app.ts +92 -9
- package/src/ui/tui/transcript.ts +4 -0
- 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
package/src/ui/footer.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// dengan spasi dan warna, tanpa bullet separator. Work Mode ada di kiri;
|
|
9
9
|
// Permission Mode berwarna cyan di sisi kanan, dekat penggunaan konteks.
|
|
10
10
|
import { sanitizeAnsiLine } from "./render/sanitize.ts"
|
|
11
|
-
import { c, glyphs, themeCapabilityKey } from "./render/theme.ts"
|
|
11
|
+
import { c, glyphs, supportsUtf8, themeCapabilityKey } from "./render/theme.ts"
|
|
12
12
|
import { displayWidth, truncateToWidth } from "./render/width.ts"
|
|
13
13
|
|
|
14
14
|
export type TimerHighlight = "seconds" | "minutes" | "hours"
|
|
@@ -36,6 +36,11 @@ export interface FooterStatus {
|
|
|
36
36
|
* memetakan frame → glyph berwarna.
|
|
37
37
|
*/
|
|
38
38
|
sparkFrame?: number
|
|
39
|
+
/** Jumlah job bash background hidup (dihitung di cli — batas lapisan).
|
|
40
|
+
* >= 1 = badge `◷ N` berputar; 0/undefined = tanpa badge. */
|
|
41
|
+
backgroundJobs?: number
|
|
42
|
+
/** Frame animasi badge job (dinaikkan clock idle di app.ts, bukan turn). */
|
|
43
|
+
backgroundFrame?: number
|
|
39
44
|
activity?: string
|
|
40
45
|
timer?: string
|
|
41
46
|
timerActive?: boolean
|
|
@@ -43,8 +48,6 @@ export interface FooterStatus {
|
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/** Lebar tetap kolom agar perubahan WorkMode tidak menggeser model/CWD. */
|
|
46
|
-
const WORK_MODE_WIDTH = 18
|
|
47
|
-
const WORK_MODE_COMPACT_WIDTH = 13
|
|
48
51
|
const WORK_MODE_VALUE_WIDTH = 7
|
|
49
52
|
|
|
50
53
|
/** Buang prefix provider (`acme::deepseek-v4` → `deepseek-v4`). */
|
|
@@ -73,41 +76,30 @@ function workModeValue(workMode?: string): string {
|
|
|
73
76
|
|
|
74
77
|
type ModeLabelStyle = "full" | "compact" | "value"
|
|
75
78
|
|
|
76
|
-
/** Work Mode memakai warna semantik;
|
|
77
|
-
|
|
79
|
+
/** Work Mode memakai warna semantik; nilai title case tanpa label (v0.24:
|
|
80
|
+
* footer lebih lega — nilai saja, pembeda sumbu = warna). */
|
|
81
|
+
export function paintWorkMode(workMode?: string, _style: ModeLabelStyle = "full"): string {
|
|
78
82
|
const value = workModeValue(workMode)
|
|
79
83
|
const normalized = sanitizeAnsiLine(workMode || "DISCUSS").toUpperCase()
|
|
80
|
-
const
|
|
81
|
-
const width =
|
|
82
|
-
style === "full"
|
|
83
|
-
? WORK_MODE_WIDTH
|
|
84
|
-
: style === "compact"
|
|
85
|
-
? WORK_MODE_COMPACT_WIDTH
|
|
86
|
-
: WORK_MODE_VALUE_WIDTH
|
|
87
|
-
const labelWidth = displayWidth(sanitizeAnsiLine(`${prefix}${value}`))
|
|
84
|
+
const labelWidth = displayWidth(sanitizeAnsiLine(value))
|
|
88
85
|
const colorValue = normalized === "DISCUSS" || normalized === "PLAN" ? c.warning : c.success
|
|
89
|
-
return `${
|
|
90
|
-
Math.max(0, width - labelWidth),
|
|
91
|
-
)}`
|
|
86
|
+
return `${colorValue(value)}${" ".repeat(Math.max(0, WORK_MODE_VALUE_WIDTH - labelWidth))}`
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
/** Permission Mode selalu cyan agar terpisah
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
export function paintPermissionMode(mode: string, style: ModeLabelStyle = "full"): string {
|
|
89
|
+
/** Permission Mode selalu cyan agar terpisah dari Work Mode. `unrestricted`:
|
|
90
|
+
* label disembunyikan — cukup titik terbuka ○ (lihat paintBashStrict). */
|
|
91
|
+
export function paintPermissionMode(mode: string, _style: ModeLabelStyle = "full"): string {
|
|
98
92
|
if (mode === "unrestricted") return ""
|
|
99
93
|
const value = titleCaseMode(mode, "Auto")
|
|
100
|
-
|
|
101
|
-
const prefix = style === "full" ? "Permission Mode: " : "Permission: "
|
|
102
|
-
return `${c.gray(prefix)}${c.info(value)}`
|
|
94
|
+
return c.info(value)
|
|
103
95
|
}
|
|
104
96
|
|
|
105
|
-
/** Badge pembatas bash allow-list:
|
|
106
|
-
* redup saat nonaktif (lapis kapabilitas, terpisah dari mode
|
|
107
|
-
* Saat `unrestricted` aktif,
|
|
108
|
-
* jadi dirender jelas (bukan redup). */
|
|
97
|
+
/** Badge pembatas bash allow-list: titik selalu tampil — terang/kuning saat
|
|
98
|
+
* aktif, redup/abu saat nonaktif (lapis kapabilitas, terpisah dari mode
|
|
99
|
+
* persetujuan). Saat `unrestricted` aktif, titik jadi ○ MERAH — satu-satunya
|
|
100
|
+
* penanda mode itu, jadi dirender jelas (bukan redup). */
|
|
109
101
|
export function paintBashStrict(strictBash?: boolean, unrestricted = false): string {
|
|
110
|
-
if (unrestricted) return c.
|
|
102
|
+
if (unrestricted) return c.red(glyphs.unlock)
|
|
111
103
|
return strictBash ? c.yellow(glyphs.lock) : c.gray(glyphs.lock)
|
|
112
104
|
}
|
|
113
105
|
|
|
@@ -118,6 +110,20 @@ function sparkGlyph(frame: number): string {
|
|
|
118
110
|
return frame % 2 === 0 ? c.white(g) : c.gray(g)
|
|
119
111
|
}
|
|
120
112
|
|
|
113
|
+
// Badge job background: jam flat berputar PELAN (fase beda dari spark),
|
|
114
|
+
// monokrom; fallback ASCII `[BG:n]`.
|
|
115
|
+
const WAITING_GLYPHS = ["◷", "◶", "◵", "◴"] as const
|
|
116
|
+
const WAITING_ASCII = ["[BG:", "|", "/", "-"] as const
|
|
117
|
+
|
|
118
|
+
/** Frame -> glyph badge tunggu. `count` = jumlah job hidup; 0 = string kosong. */
|
|
119
|
+
export function waitingGlyph(count: number, frame = 0): string {
|
|
120
|
+
if (count <= 0) return ""
|
|
121
|
+
const n = Math.max(1, Math.floor(count))
|
|
122
|
+
if (!supportsUtf8()) return `${WAITING_ASCII[0]}${n}]`
|
|
123
|
+
const phase = Math.abs(Math.floor(frame)) % WAITING_GLYPHS.length
|
|
124
|
+
return `${WAITING_GLYPHS[phase]} ${n}`
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
function paintTimer(text: string, active: boolean, highlight: TimerHighlight = "seconds"): string {
|
|
122
128
|
if (!active) return c.gray(text)
|
|
123
129
|
const parts = text.split(".")
|
|
@@ -168,6 +174,8 @@ function footerCacheKey(s: FooterStatus, cols: number): string {
|
|
|
168
174
|
s.context ?? "",
|
|
169
175
|
s.metrics ?? "",
|
|
170
176
|
s.sparkFrame ?? 0,
|
|
177
|
+
s.backgroundJobs ?? 0,
|
|
178
|
+
s.backgroundFrame ?? 0,
|
|
171
179
|
s.activity ?? "",
|
|
172
180
|
s.timer ?? "",
|
|
173
181
|
s.timerActive === true,
|
|
@@ -194,11 +202,15 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
|
|
|
194
202
|
|
|
195
203
|
function buildFooterLine(s: FooterStatus, cols: number): string {
|
|
196
204
|
const spark = sparkGlyph(s.sparkFrame ?? 0)
|
|
205
|
+
const badge =
|
|
206
|
+
s.backgroundJobs != null && s.backgroundJobs >= 1
|
|
207
|
+
? `${c.muted(waitingGlyph(s.backgroundJobs, s.backgroundFrame ?? 0))} `
|
|
208
|
+
: ""
|
|
197
209
|
const timerText = s.timer ? sanitizeAnsiLine(s.timer) : ""
|
|
198
210
|
const timer = timerText
|
|
199
211
|
? `${paintTimer(timerText, s.timerActive === true, s.timerHighlight)} `
|
|
200
212
|
: ""
|
|
201
|
-
const lead = `${spark} ${timer}`
|
|
213
|
+
const lead = `${spark} ${badge}${timer}`
|
|
202
214
|
const fieldGap = " "
|
|
203
215
|
// Satu-baris: cwd/model bisa berisi newline (nama dir) — sanitizeAnsiLine
|
|
204
216
|
// agar \n tak memecah frame lengket ke scrollback (displayWidth menghitung
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -25,6 +25,7 @@ export const en = {
|
|
|
25
25
|
"appr.decAllow": "allow",
|
|
26
26
|
"appr.decAlways": "always",
|
|
27
27
|
"appr.decDeny": "deny",
|
|
28
|
+
"appr.keyHint": "↑↓ move · Enter pick · Esc cancel",
|
|
28
29
|
"appr.askTitle": "Agent asks",
|
|
29
30
|
"appr.a11y": "[approval required: {name}]",
|
|
30
31
|
"appr.answerPrompt": "Your answer (empty = cancel): ",
|
|
@@ -256,6 +257,9 @@ export const en = {
|
|
|
256
257
|
"tui.workModeUnavailable": "work mode is not available in this session",
|
|
257
258
|
"tui.unrestrictedOn": "unrestricted mode enabled - full access",
|
|
258
259
|
"tui.unrestrictedOff": "unrestricted disabled — permission mode restored to {m}",
|
|
260
|
+
"tui.bgFinished": "background job {id} finished (exit {code})",
|
|
261
|
+
"tui.bgFinishedAuto":
|
|
262
|
+
"background job {id} finished with exit code {code}. Continue the work you were doing before without waiting for me: collect the job output with bash_output if relevant, verify the result, then finish the remaining tasks.",
|
|
259
263
|
"tui.langLine": "lang: {v}",
|
|
260
264
|
"tui.toolCall": "tool call: {v}",
|
|
261
265
|
"tui.modelSet": "model: {v}",
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -26,6 +26,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
26
26
|
"appr.decAllow": "izinkan",
|
|
27
27
|
"appr.decAlways": "selalu",
|
|
28
28
|
"appr.decDeny": "tolak",
|
|
29
|
+
"appr.keyHint": "↑↓ pindah · Enter pilih · Esc batal",
|
|
29
30
|
"appr.askTitle": "Agen bertanya",
|
|
30
31
|
"appr.a11y": "[butuh persetujuan: {name}]",
|
|
31
32
|
"appr.answerPrompt": "Jawaban (kosong = batal): ",
|
|
@@ -259,6 +260,9 @@ export const id: Record<MsgKey, string> = {
|
|
|
259
260
|
"tui.workModeUnavailable": "work mode tidak tersedia di sesi ini",
|
|
260
261
|
"tui.unrestrictedOn": "mode unrestricted aktif - akses penuh",
|
|
261
262
|
"tui.unrestrictedOff": "unrestricted nonaktif — mode izin kembali ke {m}",
|
|
263
|
+
"tui.bgFinished": "job background {id} selesai (exit {code})",
|
|
264
|
+
"tui.bgFinishedAuto":
|
|
265
|
+
"job background {id} selesai dengan exit code {code}. Lanjutkan pekerjaan yang tadi tanpa menunggu saya: ambil output job lewat bash_output bila relevan, verifikasi hasilnya, lalu selesaikan tugas yang tersisa.",
|
|
262
266
|
"tui.langLine": "lang: {v}",
|
|
263
267
|
"tui.toolCall": "pemanggilan tool: {v}",
|
|
264
268
|
"tui.modelSet": "model: {v}",
|
package/src/ui/render/ledger.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// pemotongan lebar tetap di sisi pemanggil.
|
|
8
8
|
import type { UiToolStatus } from "../contract.ts"
|
|
9
9
|
import { t } from "../i18n/locale.ts"
|
|
10
|
-
import { c
|
|
10
|
+
import { c } from "./theme.ts"
|
|
11
11
|
|
|
12
12
|
/** Kata status lokal ("completed"/"failed"/dst.) — fallback non-warna. */
|
|
13
13
|
export function statusWord(status: UiToolStatus): string {
|
|
@@ -19,14 +19,6 @@ export function statusWord(status: UiToolStatus): string {
|
|
|
19
19
|
return t("ts.statusRunning")
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** Glyph status (ASCII-aman via `glyphs`). */
|
|
23
|
-
export function statusGlyph(status: UiToolStatus): string {
|
|
24
|
-
if (status === "completed") return glyphs.check
|
|
25
|
-
if (status === "failed") return glyphs.cross
|
|
26
|
-
if (status === "denied") return glyphs.denied
|
|
27
|
-
return glyphs.circle
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
/** Warna baris ledger berdasar status terminal (sukses/error/denied/lain). */
|
|
31
23
|
export function paintLedger(status: UiToolStatus, line: string): string {
|
|
32
24
|
if (status === "failed") return c.error(line)
|
package/src/ui/render/logo.ts
CHANGED
|
@@ -294,9 +294,6 @@ export function parseMarkdownTable(
|
|
|
294
294
|
return parseMarkdownBlocks(source).find((block) => block.type === "table")?.table ?? null
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
export const parsePipeTable = parseMarkdownTable
|
|
298
|
-
export const parseMarkdownPipeTable = parseMarkdownTable
|
|
299
|
-
|
|
300
297
|
export function parseMarkdownTables(input: string): MarkdownTable[] {
|
|
301
298
|
return parseMarkdownBlocks(input)
|
|
302
299
|
.filter((block): block is Extract<MarkdownBlock, { type: "table" }> => block.type === "table")
|
|
@@ -394,9 +394,6 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
|
|
|
394
394
|
return [separator, header.join(" "), ...rows.map((row) => row.join(" "))].join("\n")
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
export const renderTableGrid = renderGridTable
|
|
398
|
-
export const renderGrid = renderGridTable
|
|
399
|
-
|
|
400
397
|
export function renderMarkdownTable(
|
|
401
398
|
table: MarkdownTable,
|
|
402
399
|
width = getTerminalWidth(),
|
package/src/ui/render/theme.ts
CHANGED
|
@@ -47,12 +47,37 @@ function colorLevel(): number {
|
|
|
47
47
|
// Determinisme Unix: output ke pipe/redirect/file tidak boleh memuat ANSI,
|
|
48
48
|
// apa pun TERM/COLORTERM di env (env sesi interaktif sering bocor ke proses
|
|
49
49
|
// yang di-pipe). Warna hanya untuk stdout yang benar-benar terminal.
|
|
50
|
-
if (!process.stdout.isTTY) return 0
|
|
50
|
+
if (!process.stdout.isTTY || process.env.TERM?.toLowerCase() === "dumb") return 0
|
|
51
51
|
if (hasTruecolorEnv()) return 3
|
|
52
52
|
if (process.env.TERM?.includes("256color")) return 2
|
|
53
|
+
// Terminal/ConPTY sering tak mengisi TERM; env eksplisit di atas tetap menang.
|
|
54
|
+
try {
|
|
55
|
+
const depth = (
|
|
56
|
+
process.stdout as NodeJS.WriteStream & { getColorDepth?: () => number }
|
|
57
|
+
).getColorDepth?.()
|
|
58
|
+
if (depth != null && depth >= 24) return 3
|
|
59
|
+
if (depth != null && depth >= 8) return 2
|
|
60
|
+
} catch {}
|
|
53
61
|
return 1
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
export type ScrimMode = "bg" | "faint" | "none"
|
|
65
|
+
|
|
66
|
+
/** Mode scrim (lazy); tak menambah byte di pipe. */
|
|
67
|
+
export function scrimMode(): ScrimMode {
|
|
68
|
+
if (noColorEnv() || !process.stdout.isTTY || process.env.TERM?.toLowerCase() === "dumb")
|
|
69
|
+
return "none"
|
|
70
|
+
if (process.env.MINICODE_SCRIM === "none") return "faint"
|
|
71
|
+
return colorLevel() >= 2 ? "bg" : colorLevel() === 1 ? "faint" : "none"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** SGR pembuka scrim; pemanggil menjaga efek tetap hidup melewati reset konten. */
|
|
75
|
+
export function scrimSgr(mode: ScrimMode): string {
|
|
76
|
+
if (mode === "bg") return "\x1b[2;48;5;236m"
|
|
77
|
+
if (mode === "faint") return "\x1b[2m"
|
|
78
|
+
return ""
|
|
79
|
+
}
|
|
80
|
+
|
|
56
81
|
/**
|
|
57
82
|
* Kunci kapabilitas tampilan (level warna + glyph UTF-8) untuk cache render.
|
|
58
83
|
*
|
|
@@ -364,13 +389,14 @@ export const glyphs = {
|
|
|
364
389
|
// Fallback * untuk terminal tanpa UTF-8.
|
|
365
390
|
return supportsUtf8() ? "✦" : "*"
|
|
366
391
|
},
|
|
367
|
-
//
|
|
368
|
-
//
|
|
392
|
+
// Badge bash allow-list (footer): titik monokrom, bukan emoji gembok —
|
|
393
|
+
// emoji berwarna dan lebarnya beda antar-font (kolom footer bergeser).
|
|
394
|
+
// ●/○ satu kolom dan tetap terbaca saat diwarnai; fallback teks ASCII.
|
|
369
395
|
get lock() {
|
|
370
|
-
return supportsUtf8() ? "
|
|
396
|
+
return supportsUtf8() ? "●" : "[LOCK]"
|
|
371
397
|
},
|
|
372
398
|
get unlock() {
|
|
373
|
-
return supportsUtf8() ? "
|
|
399
|
+
return supportsUtf8() ? "○" : "[OPEN]"
|
|
374
400
|
},
|
|
375
401
|
}
|
|
376
402
|
|
package/src/ui/runtime/screen.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// Refcount menutup modal nested (effort-picker di dalam manager): tulis
|
|
11
11
|
// enter/exit fisik hanya di lapis terluar; handle dalam = no-op paint-through.
|
|
12
12
|
import { type Cell, diffCellLine, parseCells } from "../render/cells.ts"
|
|
13
|
+
import { truncateToWidth } from "../render/width.ts"
|
|
13
14
|
import {
|
|
14
15
|
__resetTransientForTest,
|
|
15
16
|
beginInteractiveScreen,
|
|
@@ -252,7 +253,12 @@ export function openAltScreen(): AltScreen {
|
|
|
252
253
|
const i = r - top
|
|
253
254
|
// Baris diasumsi satu-baris-tersanitasi dari dialogBox (tanpa \n —
|
|
254
255
|
// \n akan menggeser kursor dan merusak baris berikut; split defensif).
|
|
255
|
-
|
|
256
|
+
// Clamp ke lebar layar: baris lebih lebar memicu auto-wrap dan
|
|
257
|
+
// menggeser seluruh region (AUD-009).
|
|
258
|
+
const row = truncateToWidth(
|
|
259
|
+
i >= 0 && i < h ? ((lines[i] ?? "").split("\n")[0] ?? "") : "",
|
|
260
|
+
this.cols,
|
|
261
|
+
)
|
|
256
262
|
out += `\x1b[${r};1H\x1b[2K${row}`
|
|
257
263
|
}
|
|
258
264
|
out += SYNC_END
|
package/src/ui/screens/dialog.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Teks disanitasi satu-baris + potong per kolom di sini (defense-in-depth di
|
|
6
|
-
// atas sanitasi view — idempoten, murah). Fallback ASCII bila MINICODE_ASCII=1.
|
|
1
|
+
// Kotak dialog: border, judul, footer, terpusat. View membangun KONTEN; di
|
|
2
|
+
// sini konten ditata jadi baris kotak (paintRegion melukis region-nya saja).
|
|
3
|
+
// Teks disanitasi + dipotong per kolom (defense-in-depth, idempoten). ASCII
|
|
4
|
+
// bila MINICODE_ASCII=1.
|
|
7
5
|
|
|
8
6
|
import { t } from "../i18n/locale.ts"
|
|
9
7
|
import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
@@ -13,27 +11,17 @@ import { displayWidth, padToWidth, truncateToWidth } from "../render/width.ts"
|
|
|
13
11
|
export interface DialogSpec {
|
|
14
12
|
/** Judul baris atas. String kosong = tanpa baris judul (chrome menyesuaikan). */
|
|
15
13
|
title: string
|
|
16
|
-
/** Baris konten polos
|
|
14
|
+
/** Baris konten polos. */
|
|
17
15
|
body: string[]
|
|
18
16
|
/** Baris hint bawah (tombol). Kosong = tanpa footer. */
|
|
19
17
|
footer?: string
|
|
20
|
-
/** Lebar
|
|
18
|
+
/** Lebar maksimum (inklusif border+padding). Default: popup terhitung. */
|
|
21
19
|
maxWidth?: number
|
|
22
|
-
/**
|
|
23
|
-
* Lebar kotak MINIMUM (inklusif border+padding): kotak tak pernah lebih
|
|
24
|
-
* sempit dari ini walau konten pendek — geometri stabil, tak melompat
|
|
25
|
-
* mengikuti data (keputusan rasa: presisi). Samakan dengan maxWidth untuk
|
|
26
|
-
* lebar TETAP.
|
|
27
|
-
*/
|
|
20
|
+
/** Lebar MINIMUM (inklusif border+padding). Default: skala dari `cols`. */
|
|
28
21
|
minWidth?: number
|
|
29
|
-
/** Tinggi
|
|
22
|
+
/** Tinggi maksimum (inklusif border). Default: setinggi layar. */
|
|
30
23
|
maxHeight?: number
|
|
31
|
-
/**
|
|
32
|
-
* Indeks body (0-based) yang WAJIB terlihat, mis. field aktif form. Bila
|
|
33
|
-
* body melebihi tinggi kotak, jendela digeser agar baris ini ikut tampil —
|
|
34
|
-
* tanpa ini user mengetik ke field yang tidak ada di layar (audit
|
|
35
|
-
* 2026-11-12, HIGH-2).
|
|
36
|
-
*/
|
|
24
|
+
/** Indeks body yang WAJIB terlihat; jendela digeser agar tak mengetik buta (HIGH-2). */
|
|
37
25
|
focusRow?: number
|
|
38
26
|
}
|
|
39
27
|
|
|
@@ -46,14 +34,24 @@ interface BoxChars {
|
|
|
46
34
|
v: string
|
|
47
35
|
}
|
|
48
36
|
|
|
37
|
+
/** Lebar kotak popup: skala dari layar; pemanggil membekukan saat mount. */
|
|
38
|
+
export function popupBoxWidth(cols: number): number {
|
|
39
|
+
const safeCols = Math.max(10, cols)
|
|
40
|
+
const scaled = Math.floor(safeCols * 0.6)
|
|
41
|
+
// Margin 4 kolom menang atas lantai 40 (AUD-011: `max(40,…)` dulu
|
|
42
|
+
// membungkus clamp sehingga terminal sempit overflow).
|
|
43
|
+
const room = safeCols - 4
|
|
44
|
+
return Math.min(Math.max(40, Math.min(88, scaled)), room)
|
|
45
|
+
}
|
|
46
|
+
|
|
49
47
|
function boxChars(): BoxChars {
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
return { tl: "
|
|
48
|
+
// Kapabilitas dan kill-switch dibaca tiap render agar perubahan env runtime
|
|
49
|
+
// (terutama test/aksesibilitas) langsung berlaku, bukan membeku saat import.
|
|
50
|
+
const style = process.env.MINICODE_BOX?.toLowerCase()
|
|
51
|
+
if (process.env.MINICODE_ASCII === "1" || style === "ascii" || !supportsUtf8())
|
|
52
|
+
return { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
|
|
53
|
+
if (style === "square") return { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│" }
|
|
54
|
+
return { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" }
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
/** Kotak popup tanpa backdrop: untuk paintRegion di atas konten pemilik layar. */
|
|
@@ -87,11 +85,7 @@ export function boxLeftPad(strippedLine: string): number {
|
|
|
87
85
|
return m ? m[0].length : 0
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
/**
|
|
91
|
-
* Bangun KOTAK saja (tanpa backdrop): dipakai popup komposit App TUI lewat
|
|
92
|
-
* paintRegion — transkrip di belakang tetap tampil. Lebar mengikuti konten
|
|
93
|
-
* (clamp maxWidth); tinggi mengikuti body (clamp maxHeight).
|
|
94
|
-
*/
|
|
88
|
+
/** Bangun KOTAK saja (tanpa backdrop); minWidth==maxWidth = lebar beku. */
|
|
95
89
|
export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogBox {
|
|
96
90
|
const c0 = Math.max(20, Math.floor(cols) || 80)
|
|
97
91
|
const r0 = Math.max(5, Math.floor(rows) || 24)
|
|
@@ -99,19 +93,22 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
99
93
|
const title = sanitizeAnsiLine(spec.title)
|
|
100
94
|
const footer = spec.footer != null && spec.footer !== "" ? sanitizeAnsiLine(spec.footer) : null
|
|
101
95
|
|
|
102
|
-
// Lebar dalam = konten terlebar, clamp ke layar. Chrome total per baris:
|
|
103
|
-
// v(1) + sp(1) + innerW + sp(1) + v(1) = innerW + 4. View membangun baris
|
|
104
|
-
// selebar itu (width() modal-aware) sehingga tak ada potong ulang di sini.
|
|
105
|
-
// maxWidth opsional mengecilkan kotak (dialog mungil) — kurangi SEBELUM
|
|
106
|
-
// hitung isi. Judul kosong = tanpa baris judul (chrome vertikal menyesuaikan).
|
|
107
96
|
const hasTitle = title !== ""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
const maxInner = Math.max(10, c0 - 6)
|
|
98
|
+
const def = Math.max(10, popupBoxWidth(c0) - 4)
|
|
99
|
+
const capInner = Math.min(
|
|
100
|
+
spec.maxWidth != null && Number.isFinite(spec.maxWidth)
|
|
101
|
+
? Math.max(10, Math.floor(spec.maxWidth) - 4)
|
|
102
|
+
: def,
|
|
103
|
+
maxInner,
|
|
104
|
+
)
|
|
105
|
+
const floorInner = Math.min(
|
|
106
|
+
spec.minWidth != null && Number.isFinite(spec.minWidth)
|
|
107
|
+
? Math.max(10, Math.floor(spec.minWidth) - 4)
|
|
108
|
+
: def,
|
|
109
|
+
capInner,
|
|
110
|
+
)
|
|
111
|
+
|
|
115
112
|
let contentW = displayWidth(title)
|
|
116
113
|
for (const ln of spec.body) {
|
|
117
114
|
const w = displayWidth(sanitizeAnsiLine(ln))
|
|
@@ -121,21 +118,16 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
121
118
|
const w = displayWidth(footer)
|
|
122
119
|
if (w > contentW) contentW = w
|
|
123
120
|
}
|
|
124
|
-
const innerW = Math.min(Math.max(
|
|
121
|
+
const innerW = Math.max(10, Math.min(Math.max(contentW, floorInner), capInner, maxInner))
|
|
125
122
|
const cut = (s: string) => truncateToWidth(sanitizeAnsiLine(s), innerW)
|
|
126
|
-
// +2 border, +2 padding: "│ text │".
|
|
127
123
|
const boxW = innerW + 4
|
|
128
|
-
const row = (
|
|
124
|
+
const row = (l: string, m: string, r: string) => l + m + r
|
|
129
125
|
|
|
130
126
|
const bar = box.h.repeat(Math.max(0, boxW - 2))
|
|
131
127
|
const boxed: string[] = []
|
|
132
128
|
boxed.push(row(box.tl, bar, box.tr))
|
|
133
|
-
// Judul aksen (paritas visual dengan overlay inline); footer redup.
|
|
134
|
-
// Judul kosong = baris judul dilewati seluruhnya (bukan baris kosong).
|
|
135
129
|
if (hasTitle) boxed.push(`${box.v} ${padToWidth(c.accent(c.bold(cut(title))), innerW)} ${box.v}`)
|
|
136
|
-
|
|
137
|
-
// marker ("… N more") ikut dihitung BILA terpotong. maxHeight opsional
|
|
138
|
-
// membatasi tinggi KOTAK (bukan frame — padding backdrop menyerap sisa).
|
|
130
|
+
|
|
139
131
|
const chromeFixed = 2 + (hasTitle ? 1 : 0) + (footer != null ? 1 : 0)
|
|
140
132
|
const boxBudget =
|
|
141
133
|
spec.maxHeight != null && Number.isFinite(spec.maxHeight)
|
|
@@ -144,10 +136,6 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
144
136
|
const room = Math.max(0, boxBudget - chromeFixed)
|
|
145
137
|
const clipped = spec.body.length > room
|
|
146
138
|
const shown = clipped ? Math.max(0, room - 1) : spec.body.length
|
|
147
|
-
// Jendela body: default dari atas, tapi bila pemanggil menandai baris fokus
|
|
148
|
-
// (form: field aktif) jendela digeser agar baris itu terlihat. Tanpa ini
|
|
149
|
-
// `activeRow` menunjuk baris di luar yang dirender sehingga kursor parkir di
|
|
150
|
-
// marker/border dan ketikan user tak terlihat (audit 2026-11-12, HIGH-2).
|
|
151
139
|
const focus = spec.focusRow
|
|
152
140
|
const bodyStart =
|
|
153
141
|
clipped && focus != null && shown > 0 && Number.isFinite(focus)
|
|
@@ -162,8 +150,6 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
162
150
|
if (footer != null) boxed.push(`${box.v} ${padToWidth(c.dim(cut(footer)), innerW)} ${box.v}`)
|
|
163
151
|
boxed.push(row(box.bl, bar, box.br))
|
|
164
152
|
|
|
165
|
-
// Pusatkan horizontal; vertikal via topRow (1-based) untuk paintRegion.
|
|
166
|
-
// displayWidth mengabaikan SGR (nol kolom) sehingga ANSI tak merusak hitungan.
|
|
167
153
|
const topRow = Math.max(1, Math.floor((r0 - boxed.length) / 2) + 1)
|
|
168
154
|
const lines = boxed.map((ln) => {
|
|
169
155
|
const left = Math.max(0, Math.floor((c0 - displayWidth(ln)) / 2))
|
|
@@ -171,25 +157,3 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
171
157
|
})
|
|
172
158
|
return { lines, topRow, height: boxed.length, bodyTop: 1 + (hasTitle ? 1 : 0), bodyStart }
|
|
173
159
|
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Bangun frame SELAYAR: tepat `rows` string (backdrop redup + kotak terpusat).
|
|
177
|
-
* Tak pernah melempar; tak menulis IO (view yang paint via screen).
|
|
178
|
-
* Dipakai layar yang memiliki buffer sendiri (wizard first-run); popup di
|
|
179
|
-
* atas konten App memakai dialogBox + paintRegion (tanpa clear).
|
|
180
|
-
*/
|
|
181
|
-
export function dialogFrame(spec: DialogSpec, cols: number, rows: number): string[] {
|
|
182
|
-
const c0 = Math.max(20, Math.floor(cols) || 80)
|
|
183
|
-
const r0 = Math.max(5, Math.floor(rows) || 24)
|
|
184
|
-
const box = dialogBox(spec, c0, r0)
|
|
185
|
-
// Backdrop REDUP (bukan hitam polos): pola ░ faint memenuhi layar sehingga
|
|
186
|
-
// kotak terbaca sebagai jendela di depan, bukan screen baru. Fallback ASCII
|
|
187
|
-
// "." bila glyph shade tak didukung.
|
|
188
|
-
const shade = supportsUtf8() ? "░".repeat(c0) : ".".repeat(c0)
|
|
189
|
-
const dim = c.faint(shade)
|
|
190
|
-
const out: string[] = []
|
|
191
|
-
for (let i = 1; i < box.topRow; i++) out.push(dim)
|
|
192
|
-
for (const ln of box.lines) out.push(ln)
|
|
193
|
-
while (out.length < r0) out.push(dim)
|
|
194
|
-
return out.slice(0, r0)
|
|
195
|
-
}
|
package/src/ui/screens/form.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
|
22
22
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
23
23
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
24
24
|
import { type AltScreen, SYNC_UPDATE_END, SYNC_UPDATE_START } from "../runtime/screen.ts"
|
|
25
|
-
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
25
|
+
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
26
26
|
import { createIdleTimer } from "./lifecycle.ts"
|
|
27
27
|
|
|
28
28
|
export interface FormField {
|
|
@@ -79,8 +79,8 @@ interface FieldState {
|
|
|
79
79
|
|
|
80
80
|
const dim = (s: string): string => c.dim(s)
|
|
81
81
|
|
|
82
|
-
/** Lebar kotak form
|
|
83
|
-
const
|
|
82
|
+
/** Lebar kotak form: `popupBoxWidth` — paritas picker/model/provider (AUD-006). */
|
|
83
|
+
const formBoxWidth = (cols: number): number => popupBoxWidth(cols)
|
|
84
84
|
|
|
85
85
|
function toState(def: FormField): FieldState {
|
|
86
86
|
if (def.kind === "select") {
|
|
@@ -176,9 +176,9 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
176
176
|
idle.reset()
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// Lebar konten = lebar kotak
|
|
180
|
-
|
|
181
|
-
const width = () =>
|
|
179
|
+
// Lebar konten = lebar kotak minus chrome border+padding (4).
|
|
180
|
+
const boxW = formBoxWidth(screen.cols || 80)
|
|
181
|
+
const width = () => boxW
|
|
182
182
|
const innerW = () => Math.max(8, width() - 4)
|
|
183
183
|
|
|
184
184
|
// Baris nilai field aktif (indeks dalam body) untuk parkir kursor.
|
|
@@ -244,10 +244,10 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
|
|
|
244
244
|
footer: idleWarned
|
|
245
245
|
? c.error(t("form.idleWarning", { s: Math.ceil(IDLE_CANCEL_MS / 1000) }))
|
|
246
246
|
: (spec.footer ?? t("form.footerDefault")),
|
|
247
|
-
// Lebar
|
|
248
|
-
//
|
|
249
|
-
minWidth:
|
|
250
|
-
maxWidth:
|
|
247
|
+
// Lebar beku (paritas picker/manager — tak bernapas saat error
|
|
248
|
+
// muncul/hilang).
|
|
249
|
+
minWidth: width(),
|
|
250
|
+
maxWidth: width(),
|
|
251
251
|
// Field aktif WAJIB terlihat: dialog menggeser jendela body bila
|
|
252
252
|
// muat-tidaknya terpaksa memotong (audit 2026-11-12, HIGH-2).
|
|
253
253
|
focusRow: activeRow >= 0 ? activeRow : undefined,
|
|
@@ -13,7 +13,7 @@ import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
|
13
13
|
import { c, glyphs, stripAnsi } from "../render/theme.ts"
|
|
14
14
|
import { displayWidth, truncateToWidth } from "../render/width.ts"
|
|
15
15
|
import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
|
|
16
|
-
import { boxLeftPad, dialogBox } from "./dialog.ts"
|
|
16
|
+
import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
|
|
17
17
|
import { runForm } from "./form.ts"
|
|
18
18
|
import { createIdleTimer } from "./lifecycle.ts"
|
|
19
19
|
import { runPicker } from "./picker.ts"
|
|
@@ -59,10 +59,8 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
|
|
|
59
59
|
return rows.filter((r) => r.id.toLowerCase().includes(needle))
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** Lebar kotak
|
|
63
|
-
|
|
64
|
-
* maxWidth dialogBox — keduanya HARUS sepakat agar label tak terpotong ulang. */
|
|
65
|
-
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)
|
|
66
64
|
|
|
67
65
|
export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
|
|
68
66
|
let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
|
|
@@ -99,7 +97,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
99
97
|
// tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
|
|
100
98
|
// dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
|
|
101
99
|
// = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
|
|
102
|
-
const width = () => Math.max(8,
|
|
100
|
+
const width = () => Math.max(8, modalBoxWidth() - 4)
|
|
103
101
|
|
|
104
102
|
// Isi MINIMAL dialog /model (tanpa judul/footer/hitungan/penanda —
|
|
105
103
|
// seleksi murni warna). Search selalu tampil, daftar tanpa `›`.
|
|
@@ -150,14 +148,13 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
const render = () => {
|
|
153
|
-
//
|
|
154
|
-
// App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
|
|
151
|
+
// Region kotak di atas transkrip; lebar beku (min=max).
|
|
155
152
|
const box = dialogBox(
|
|
156
153
|
{
|
|
157
154
|
title: "",
|
|
158
155
|
body: bodyLinesModal(),
|
|
159
|
-
minWidth:
|
|
160
|
-
maxWidth:
|
|
156
|
+
minWidth: modalBoxWidth(),
|
|
157
|
+
maxWidth: modalBoxWidth(),
|
|
161
158
|
maxHeight: 14,
|
|
162
159
|
},
|
|
163
160
|
screen.cols,
|