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/render/theme.ts
CHANGED
|
@@ -19,11 +19,16 @@ const isWindows = process.platform === "win32"
|
|
|
19
19
|
export function supportsUtf8(): boolean {
|
|
20
20
|
if (process.env.MINICODE_ASCII === "1") return false
|
|
21
21
|
if (!isWindows) return true
|
|
22
|
+
const term = (process.env.TERM ?? "").toLowerCase()
|
|
23
|
+
const locale = `${process.env.LC_ALL ?? ""} ${process.env.LANG ?? ""}`
|
|
22
24
|
return (
|
|
23
25
|
process.env.WT_SESSION != null ||
|
|
24
26
|
process.env.TERM_PROGRAM != null ||
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
process.env.ConEmuANSI === "ON" ||
|
|
28
|
+
process.env.ANSICON != null ||
|
|
29
|
+
process.env.MSYSTEM != null ||
|
|
30
|
+
/(?:xterm|screen|tmux|kitty|alacritty|wezterm|vt\d)/i.test(term) ||
|
|
31
|
+
/utf-?8/i.test(locale)
|
|
27
32
|
)
|
|
28
33
|
}
|
|
29
34
|
|
|
@@ -105,30 +110,74 @@ function wrap(open: number | string, close: number | string): Paint {
|
|
|
105
110
|
return (s: string) => `${o}${s}${cl}`
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
/** Warna
|
|
109
|
-
function
|
|
110
|
-
|
|
113
|
+
/** Warna token sesuai level terminal: 16 / 256 / truecolor. */
|
|
114
|
+
function paintToken(token: ColorToken): Paint {
|
|
115
|
+
const level = colorLevel()
|
|
116
|
+
if (level === 0) return identity
|
|
117
|
+
const code = level === 1 ? token.c16 : level === 2 ? token.c256 : token.rgb
|
|
111
118
|
return (s: string) => `\x1b[${code}m${s}\x1b[39m`
|
|
112
119
|
}
|
|
113
120
|
|
|
121
|
+
/** Token + bold (untuk accent judul/terpilih). */
|
|
122
|
+
function paintTokenBold(token: ColorToken): Paint {
|
|
123
|
+
const level = colorLevel()
|
|
124
|
+
if (level === 0) return identity
|
|
125
|
+
const code = level === 1 ? token.c16 : level === 2 ? token.c256 : token.rgb
|
|
126
|
+
return (s: string) => `\x1b[1;${code}m${s}\x1b[39m`
|
|
127
|
+
}
|
|
128
|
+
|
|
114
129
|
// ── Token palet tunggal (VS Code Dark+ inspired) ──
|
|
130
|
+
//
|
|
131
|
+
// Tiap token punya representasi 16-warna, 256-warna, dan truecolor. Sebelumnya
|
|
132
|
+
// semua token semantik selalu memancarkan `38;2;...` walau terminal hanya
|
|
133
|
+
// mengaku 16 warna — level deteksi jadi tidak bermakna dan warna status bisa
|
|
134
|
+
// hilang/diabaikan. `paintToken` memilih representasi sesuai `colorLevel()`.
|
|
135
|
+
interface ColorToken {
|
|
136
|
+
/** SGR 16-warna (mis. "32"). */
|
|
137
|
+
c16: string
|
|
138
|
+
/** SGR 256-warna (mis. "38;5;114"). */
|
|
139
|
+
c256: string
|
|
140
|
+
/** SGR truecolor (mis. "38;2;137;209;133"). */
|
|
141
|
+
rgb: string
|
|
142
|
+
}
|
|
143
|
+
|
|
115
144
|
const TOKENS = {
|
|
116
|
-
success: "38;2;137;209;133",
|
|
117
|
-
error: "38;2;244;135;113",
|
|
118
|
-
warning: "38;2;204;167;0",
|
|
119
|
-
info: "38;2;117;190;255",
|
|
120
|
-
accent: "38;2;74;144;226",
|
|
145
|
+
success: { c16: "32", c256: "38;5;114", rgb: "38;2;137;209;133" },
|
|
146
|
+
error: { c16: "31", c256: "38;5;210", rgb: "38;2;244;135;113" },
|
|
147
|
+
warning: { c16: "33", c256: "38;5;178", rgb: "38;2;204;167;0" },
|
|
148
|
+
info: { c16: "36", c256: "38;5;75", rgb: "38;2;117;190;255" },
|
|
149
|
+
accent: { c16: "94", c256: "38;5;69", rgb: "38;2;74;144;226" },
|
|
121
150
|
// String literal kode (VS Code Dark+ `string` #CE9178) — sengaja terpisah dari
|
|
122
151
|
// `success` (green): string harus tampak jingga-salm ala VS Code, sementara
|
|
123
152
|
// status sukses tetap hijau. Alias lama `green` tetap menyasar success.
|
|
124
|
-
string: "38;2;206;145;120",
|
|
153
|
+
string: { c16: "33", c256: "38;5;173", rgb: "38;2;206;145;120" },
|
|
125
154
|
// Thinking/reasoning: abu-kebiruan yang tetap terbaca nyaman (bukan `dim` yang
|
|
126
155
|
// meredupkan seluruh teks) — jelas sekunder dari jawaban model tapi tak silau.
|
|
127
|
-
thinking: "38;2;135;146;160",
|
|
156
|
+
thinking: { c16: "90", c256: "38;5;246", rgb: "38;2;135;146;160" },
|
|
128
157
|
// Faint: abu gelap untuk garis footer — lebih redup dari `gray` (bright-black)
|
|
129
158
|
// dan dari `muted` (dim). Dipakai elemen yang harus ada tapi hampir tak
|
|
130
159
|
// terlihat, seperti separator baris dasar.
|
|
131
|
-
faint: "38;2;72;72;72",
|
|
160
|
+
faint: { c16: "90", c256: "38;5;238", rgb: "38;2;72;72;72" },
|
|
161
|
+
} satisfies Record<string, ColorToken>
|
|
162
|
+
|
|
163
|
+
const GRAY_TOKEN: ColorToken = { c16: "90", c256: "38;5;245", rgb: "90" }
|
|
164
|
+
const ACCENT_ALT_TOKEN: ColorToken = { c16: "95", c256: "38;5;141", rgb: TOKENS.info.rgb }
|
|
165
|
+
const MAGENTA_TOKEN: ColorToken = { c16: "35", c256: "38;5;141", rgb: "35" }
|
|
166
|
+
const WHITE_TOKEN: ColorToken = { c16: "37", c256: "37", rgb: "37" }
|
|
167
|
+
const BRIGHT_YELLOW_TOKEN: ColorToken = {
|
|
168
|
+
c16: "93",
|
|
169
|
+
c256: "38;5;179",
|
|
170
|
+
rgb: "38;2;215;186;125",
|
|
171
|
+
}
|
|
172
|
+
const BRIGHT_MAGENTA_TOKEN: ColorToken = {
|
|
173
|
+
c16: "95",
|
|
174
|
+
c256: "38;5;176",
|
|
175
|
+
rgb: "38;2;197;134;192",
|
|
176
|
+
}
|
|
177
|
+
const BRIGHT_CYAN_TOKEN: ColorToken = {
|
|
178
|
+
c16: "96",
|
|
179
|
+
c256: "38;5;80",
|
|
180
|
+
rgb: "38;2;78;201;176",
|
|
132
181
|
}
|
|
133
182
|
|
|
134
183
|
// ── Slot warna ──
|
|
@@ -166,39 +215,36 @@ interface Palette {
|
|
|
166
215
|
const paletteCache = new Map<string, Palette>()
|
|
167
216
|
|
|
168
217
|
function buildPalette(): Palette {
|
|
169
|
-
const truecolor = hasTruecolorEnv()
|
|
170
218
|
const mono = colorLevel() === 0
|
|
171
|
-
// Aksen: 16-color fallback saat truecolor tak tersedia.
|
|
172
|
-
const accent = truecolor ? paintFrom(TOKENS.accent) : wrap(94, 39)
|
|
173
219
|
return {
|
|
174
|
-
success:
|
|
175
|
-
error:
|
|
176
|
-
warning:
|
|
177
|
-
info:
|
|
178
|
-
accent,
|
|
179
|
-
accentAlt:
|
|
180
|
-
accentBold:
|
|
220
|
+
success: paintToken(TOKENS.success),
|
|
221
|
+
error: paintToken(TOKENS.error),
|
|
222
|
+
warning: paintToken(TOKENS.warning),
|
|
223
|
+
info: paintToken(TOKENS.info),
|
|
224
|
+
accent: paintToken(TOKENS.accent),
|
|
225
|
+
accentAlt: paintToken(ACCENT_ALT_TOKEN),
|
|
226
|
+
accentBold: paintTokenBold(TOKENS.accent),
|
|
181
227
|
// Saat mono, `gray` memakai dim (SGR 2) alih-alih bright-black (SGR 90):
|
|
182
228
|
// 90 adalah warna, dan mono adalah jalur aksesibilitas yang seharusnya
|
|
183
229
|
// monokrom. Dim tetap memberi hierarki visual tanpa memakai kanal warna.
|
|
184
|
-
gray: mono ? attr(2, 22) :
|
|
230
|
+
gray: mono ? attr(2, 22) : paintToken(GRAY_TOKEN),
|
|
185
231
|
// Faint: garis footer hampir tak terlihat. Mono (aksesibilitas) jatuh ke
|
|
186
232
|
// dim agar tetap ada hierarki tanpa kanal warna.
|
|
187
|
-
faint: mono ? attr(2, 22) :
|
|
233
|
+
faint: mono ? attr(2, 22) : paintToken(TOKENS.faint),
|
|
188
234
|
// Alias legacy: dipetakan ke token, bukan hex hardcoded.
|
|
189
|
-
red:
|
|
190
|
-
green:
|
|
191
|
-
yellow:
|
|
192
|
-
cyan:
|
|
193
|
-
blue: accent,
|
|
194
|
-
magenta: mono ? identity :
|
|
195
|
-
white: mono ? identity :
|
|
235
|
+
red: paintToken(TOKENS.error),
|
|
236
|
+
green: paintToken(TOKENS.success),
|
|
237
|
+
yellow: paintToken(TOKENS.warning),
|
|
238
|
+
cyan: paintToken(TOKENS.info),
|
|
239
|
+
blue: paintToken(TOKENS.accent),
|
|
240
|
+
magenta: mono ? identity : paintToken(MAGENTA_TOKEN),
|
|
241
|
+
white: mono ? identity : paintToken(WHITE_TOKEN),
|
|
196
242
|
// Slot syntax highlight — saat mono semuanya jadi teks biasa.
|
|
197
|
-
brightYellow: mono ? identity :
|
|
198
|
-
brightMagenta: mono ? identity :
|
|
199
|
-
brightCyan: mono ? identity :
|
|
200
|
-
string:
|
|
201
|
-
thinking:
|
|
243
|
+
brightYellow: mono ? identity : paintToken(BRIGHT_YELLOW_TOKEN),
|
|
244
|
+
brightMagenta: mono ? identity : paintToken(BRIGHT_MAGENTA_TOKEN),
|
|
245
|
+
brightCyan: mono ? identity : paintToken(BRIGHT_CYAN_TOKEN),
|
|
246
|
+
string: paintToken(TOKENS.string),
|
|
247
|
+
thinking: paintToken(TOKENS.thinking),
|
|
202
248
|
}
|
|
203
249
|
}
|
|
204
250
|
|
|
@@ -355,6 +401,27 @@ export const glyphs = {
|
|
|
355
401
|
get prompt() {
|
|
356
402
|
return supportsUtf8() ? "❯" : ">"
|
|
357
403
|
},
|
|
404
|
+
/** Pasangan kunci panah untuk hint — ASCII fallback agar kill-switch tetap utuh. */
|
|
405
|
+
get upDown() {
|
|
406
|
+
return supportsUtf8() ? "↑↓" : "Up/Down"
|
|
407
|
+
},
|
|
408
|
+
get leftRight() {
|
|
409
|
+
return supportsUtf8() ? "←→" : "Left/Right"
|
|
410
|
+
},
|
|
411
|
+
/** Chevron pemilih nilai (form select) dengan fallback ASCII. */
|
|
412
|
+
get chevronLeft() {
|
|
413
|
+
return supportsUtf8() ? "‹" : "<"
|
|
414
|
+
},
|
|
415
|
+
get chevronRight() {
|
|
416
|
+
return supportsUtf8() ? "›" : ">"
|
|
417
|
+
},
|
|
418
|
+
/** Caret blok di baris pencarian. */
|
|
419
|
+
get caret() {
|
|
420
|
+
return supportsUtf8() ? "█" : "#"
|
|
421
|
+
},
|
|
422
|
+
get down() {
|
|
423
|
+
return supportsUtf8() ? "↓" : "v"
|
|
424
|
+
},
|
|
358
425
|
get dot() {
|
|
359
426
|
return supportsUtf8() ? "·" : "."
|
|
360
427
|
},
|
|
@@ -398,6 +465,13 @@ export const glyphs = {
|
|
|
398
465
|
get unlock() {
|
|
399
466
|
return supportsUtf8() ? "○" : "[OPEN]"
|
|
400
467
|
},
|
|
468
|
+
/** Garis horizontal & vertikal konsisten untuk divider dan penanda blok kode. */
|
|
469
|
+
get hLine() {
|
|
470
|
+
return supportsUtf8() ? "─" : "-"
|
|
471
|
+
},
|
|
472
|
+
get vLine() {
|
|
473
|
+
return supportsUtf8() ? "│" : "|"
|
|
474
|
+
},
|
|
401
475
|
}
|
|
402
476
|
|
|
403
477
|
// ── Section separator ──
|
|
@@ -410,12 +484,12 @@ export function section(title: string): string {
|
|
|
410
484
|
// per kolom — tanpa ini dashes jatuh ke 4 dan total label+4 tetap meluap.
|
|
411
485
|
const label =
|
|
412
486
|
displayWidth(` ${clean} `) > Math.max(4, width - 4)
|
|
413
|
-
? truncateToWidth(` ${clean} `, Math.max(4, width - 4),
|
|
487
|
+
? truncateToWidth(` ${clean} `, Math.max(4, width - 4), glyphs.ellipsis)
|
|
414
488
|
: ` ${clean} `
|
|
415
489
|
// Lebar pemisah dihitung per KOLOM terminal: CJK/emoji bisa 2 kolom.
|
|
416
490
|
// Clamp agar garis tak memicu wrap sendiri di terminal sempit.
|
|
417
491
|
const dashes = Math.min(Math.max(4, width - displayWidth(label)), Math.max(4, width - 4))
|
|
418
|
-
return c.dim(label +
|
|
492
|
+
return c.dim(label + glyphs.hLine.repeat(dashes))
|
|
419
493
|
}
|
|
420
494
|
|
|
421
495
|
export function getTerminalWidth(): number {
|
package/src/ui/runtime/screen.ts
CHANGED
|
@@ -26,6 +26,7 @@ const CLEAR_ALL = "\x1b[2J"
|
|
|
26
26
|
* tersembunyi yang membuat terminal "berantakan" setelah Ctrl+D). */
|
|
27
27
|
const RESET_ATTRS = "\x1b[0m"
|
|
28
28
|
const SHOW_CURSOR = "\x1b[?25h"
|
|
29
|
+
const HIDE_CURSOR = "\x1b[?25l"
|
|
29
30
|
// Reset scroll-region — unconditional + idempoten: region aktif peninggalan
|
|
30
31
|
// akan memotong paint fullscreen; tulis SEBELUM enter dan SESUDAH exit agar
|
|
31
32
|
// buffer utama kembali steril apa pun yang terjadi di dalam.
|
|
@@ -45,8 +46,36 @@ const EXIT_SEQUENCE = RESET_ATTRS + SHOW_CURSOR + SYNC_END + EXIT + RESET_REGION
|
|
|
45
46
|
export const SYNC_UPDATE_START = SYNC_START
|
|
46
47
|
export const SYNC_UPDATE_END = SYNC_END
|
|
47
48
|
|
|
49
|
+
export type ScreenBackdrop = (cols: number, rows: number) => readonly string[]
|
|
50
|
+
|
|
48
51
|
let depth = 0
|
|
49
52
|
let exitHookInstalled = false
|
|
53
|
+
// Penanda perubahan region (paintRegion/clearRegion) lintas handle: memastikan
|
|
54
|
+
// `paint()` berikutnya pada handle induk (mis. TuiApp.resume) melakukan diff
|
|
55
|
+
// ulang penuh dan tidak melewatkan sel yang ditimpa popup (krusial saat NO_COLOR=1).
|
|
56
|
+
let regionEpoch = 0
|
|
57
|
+
let backdropState: { fn: ScreenBackdrop; cols: number; rows: number } | null = null
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Daftarkan penyedia latar redup aktif selama popup komposit hidup: region
|
|
61
|
+
* yang menyusut/dibersihkan atau ter-resize mengisi ulang sel di luar kotak
|
|
62
|
+
* dengan backdrop redup tanpa memancarkan `ESC[2J` penuh.
|
|
63
|
+
*/
|
|
64
|
+
export function registerScreenBackdrop(
|
|
65
|
+
fn: ScreenBackdrop | null,
|
|
66
|
+
initialCols = 0,
|
|
67
|
+
initialRows = 0,
|
|
68
|
+
): () => void {
|
|
69
|
+
if (!fn) {
|
|
70
|
+
backdropState = null
|
|
71
|
+
return () => {}
|
|
72
|
+
}
|
|
73
|
+
const entry = { fn, cols: initialCols, rows: initialRows }
|
|
74
|
+
backdropState = entry
|
|
75
|
+
return () => {
|
|
76
|
+
if (backdropState === entry) backdropState = null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
50
79
|
|
|
51
80
|
function installExitHook(): void {
|
|
52
81
|
if (exitHookInstalled) return
|
|
@@ -81,6 +110,8 @@ export interface AltScreen {
|
|
|
81
110
|
* merakit ulang frame penuh hanya membuang kerja.
|
|
82
111
|
*/
|
|
83
112
|
moveCursor(row: number, col: number): void
|
|
113
|
+
/** Sembunyikan/tampilkan kursor secara atomik dalam blok sync. */
|
|
114
|
+
setCursorVisible(visible: boolean): void
|
|
84
115
|
/**
|
|
85
116
|
* Lukis REGION TANPA clear: popup di atas konten pemilik layar (App TUI).
|
|
86
117
|
* Tiap baris ditulis di `topRow+i` (1-based) setelah hapus-baris; baris di
|
|
@@ -110,6 +141,7 @@ function nullScreen(): AltScreen {
|
|
|
110
141
|
rows: process.stdout.rows || NULL_ROWS,
|
|
111
142
|
paint: () => {},
|
|
112
143
|
moveCursor: () => {},
|
|
144
|
+
setCursorVisible: () => {},
|
|
113
145
|
paintRegion: () => {},
|
|
114
146
|
clearRegion: () => {},
|
|
115
147
|
close: () => {},
|
|
@@ -162,6 +194,7 @@ export function openAltScreen(): AltScreen {
|
|
|
162
194
|
let lastFrame: string[] | null = null
|
|
163
195
|
let lastCells: Cell[][] | null = null
|
|
164
196
|
let lastCols = 0
|
|
197
|
+
let lastRegionEpoch = regionEpoch
|
|
165
198
|
return {
|
|
166
199
|
ok: true,
|
|
167
200
|
// Getter LIVE (bukan snapshot saat open) — resize di tengah modal wajib
|
|
@@ -187,6 +220,7 @@ export function openAltScreen(): AltScreen {
|
|
|
187
220
|
const drifted = consumeScreenDrift()
|
|
188
221
|
if (
|
|
189
222
|
!drifted &&
|
|
223
|
+
lastRegionEpoch === regionEpoch &&
|
|
190
224
|
lastFrame &&
|
|
191
225
|
lastCells &&
|
|
192
226
|
lastFrame.length === lines.length &&
|
|
@@ -208,6 +242,7 @@ export function openAltScreen(): AltScreen {
|
|
|
208
242
|
lastFrame = lines.slice()
|
|
209
243
|
lastCells = lines.map((line) => parseCells(line))
|
|
210
244
|
lastCols = cols
|
|
245
|
+
lastRegionEpoch = regionEpoch
|
|
211
246
|
}
|
|
212
247
|
// Reset atribut sebelum kursor: run diff bisa berakhir dengan warna
|
|
213
248
|
// aktif, dan kursor yang ditampilkan mewarisi atribut itu.
|
|
@@ -229,7 +264,15 @@ export function openAltScreen(): AltScreen {
|
|
|
229
264
|
// Sync block + reset atribut: kursor tak boleh mewarisi warna run
|
|
230
265
|
// sebelumnya, dan perpindahan kursor tak perlu menyentuh satu sel pun.
|
|
231
266
|
process.stdout.write(
|
|
232
|
-
`${SYNC_START}${RESET_ATTRS}\x1b[
|
|
267
|
+
`${SYNC_START}${RESET_ATTRS}${HIDE_CURSOR}\x1b[${r};${c}H\x1b[6 q${SHOW_CURSOR}${SYNC_END}`,
|
|
268
|
+
)
|
|
269
|
+
},
|
|
270
|
+
setCursorVisible(visible: boolean): void {
|
|
271
|
+
if (closed) return
|
|
272
|
+
process.stdout.write(
|
|
273
|
+
visible
|
|
274
|
+
? `${SYNC_START}${RESET_ATTRS}${SHOW_CURSOR}${SYNC_END}`
|
|
275
|
+
: `${SYNC_START}${HIDE_CURSOR}${SYNC_END}`,
|
|
233
276
|
)
|
|
234
277
|
},
|
|
235
278
|
paintRegion(lines: string[], topRow: number): void {
|
|
@@ -237,35 +280,48 @@ export function openAltScreen(): AltScreen {
|
|
|
237
280
|
// Melukis nol baris = no-op murni (bukan clear): pemanggil yang ingin
|
|
238
281
|
// menghapus memakai clearRegion() eksplisit.
|
|
239
282
|
if (!lines.length) return
|
|
283
|
+
const cols = this.cols
|
|
284
|
+
const rows = this.rows
|
|
240
285
|
const top = Math.max(1, Math.floor(topRow) || 1)
|
|
241
286
|
const h = lines.length
|
|
287
|
+
// Bila backdrop aktif dan ukuran layar berubah, reflow seluruh baris di
|
|
288
|
+
// luar kotak dalam SATU tulis sync agar tepi baru ikut redup (tanpa 2J).
|
|
289
|
+
const resizedBackdrop =
|
|
290
|
+
backdropState !== null && (backdropState.cols !== cols || backdropState.rows !== rows)
|
|
242
291
|
// Union region lama + baru: kotak yang menyusut/bergeser (filter,
|
|
243
292
|
// notice hilang) harus menghapus sisa bingkainya sendiri — pemilik
|
|
244
293
|
// layar tak tahu geometri popup.
|
|
245
|
-
let clearTop = top
|
|
246
|
-
let clearBottom = top + Math.max(0, h - 1)
|
|
294
|
+
let clearTop = resizedBackdrop ? 1 : top
|
|
295
|
+
let clearBottom = resizedBackdrop ? rows : top + Math.max(0, h - 1)
|
|
247
296
|
if (lastRegion) {
|
|
248
297
|
clearTop = Math.min(clearTop, lastRegion.top)
|
|
249
298
|
clearBottom = Math.max(clearBottom, lastRegion.top + lastRegion.height - 1)
|
|
250
299
|
}
|
|
300
|
+
const backdropRows = backdropState ? backdropState.fn(cols, rows) : null
|
|
301
|
+
if (backdropState && resizedBackdrop) {
|
|
302
|
+
backdropState.cols = cols
|
|
303
|
+
backdropState.rows = rows
|
|
304
|
+
}
|
|
251
305
|
let out = SYNC_START
|
|
252
306
|
for (let r = clearTop; r <= clearBottom; r++) {
|
|
253
307
|
const i = r - top
|
|
254
308
|
// Baris diasumsi satu-baris-tersanitasi dari dialogBox (tanpa \n —
|
|
255
309
|
// \n akan menggeser kursor dan merusak baris berikut; split defensif).
|
|
256
310
|
// Clamp ke lebar layar: baris lebih lebar memicu auto-wrap dan
|
|
257
|
-
// menggeser seluruh region (AUD-009).
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
)
|
|
311
|
+
// menggeser seluruh region (AUD-009). Baris di luar kotak memulihkan
|
|
312
|
+
// backdrop redup bila ada (bukan meninggalkan lubang hitam kosong).
|
|
313
|
+
const raw =
|
|
314
|
+
i >= 0 && i < h ? ((lines[i] ?? "").split("\n")[0] ?? "") : (backdropRows?.[r - 1] ?? "")
|
|
315
|
+
const row = truncateToWidth(raw, cols)
|
|
262
316
|
out += `\x1b[${r};1H\x1b[2K${row}`
|
|
263
317
|
}
|
|
264
318
|
out += SYNC_END
|
|
265
319
|
process.stdout.write(out)
|
|
266
320
|
lastRegion = h > 0 ? { top, height: h } : null
|
|
267
321
|
// Region menimpa isi frame di luar pelacakan diff; paksa paint berikutnya
|
|
268
|
-
//
|
|
322
|
+
// (termasuk handle induk via regionEpoch) clear penuh agar tak ada sel
|
|
323
|
+
// terlewat (termasuk saat NO_COLOR=1).
|
|
324
|
+
regionEpoch++
|
|
269
325
|
lastFrame = null
|
|
270
326
|
lastCells = null
|
|
271
327
|
lastCols = 0
|
|
@@ -274,14 +330,19 @@ export function openAltScreen(): AltScreen {
|
|
|
274
330
|
if (closed) return
|
|
275
331
|
if (!lastRegion) return
|
|
276
332
|
try {
|
|
333
|
+
const cols = this.cols
|
|
334
|
+
const rows = this.rows
|
|
335
|
+
const backdropRows = backdropState ? backdropState.fn(cols, rows) : null
|
|
277
336
|
let out = SYNC_START
|
|
278
337
|
for (let r = lastRegion.top; r < lastRegion.top + lastRegion.height; r++) {
|
|
279
|
-
|
|
338
|
+
const bg = backdropRows ? truncateToWidth(backdropRows[r - 1] ?? "", cols) : ""
|
|
339
|
+
out += `\x1b[${r};1H\x1b[2K${bg}`
|
|
280
340
|
}
|
|
281
341
|
out += SYNC_END
|
|
282
342
|
process.stdout.write(out)
|
|
283
343
|
} catch {}
|
|
284
344
|
lastRegion = null
|
|
345
|
+
regionEpoch++
|
|
285
346
|
// Area popup sudah dihapus, tetapi isi frame di bawahnya tidak lagi
|
|
286
347
|
// tercermin di `lastCells`; paint berikutnya harus penuh.
|
|
287
348
|
lastFrame = null
|
|
@@ -316,6 +377,7 @@ export function altScreenDepth(): number {
|
|
|
316
377
|
* Node TIDAK jalan pada sinyal fatal default.
|
|
317
378
|
*/
|
|
318
379
|
export function forceRestoreScreenForSignal(): void {
|
|
380
|
+
backdropState = null
|
|
319
381
|
if (depth > 0) {
|
|
320
382
|
try {
|
|
321
383
|
process.stdout.write(EXIT_SEQUENCE)
|
|
@@ -331,6 +393,8 @@ export function forceRestoreScreenForSignal(): void {
|
|
|
331
393
|
*/
|
|
332
394
|
export function resetAltScreenDepth(): void {
|
|
333
395
|
depth = 0
|
|
396
|
+
regionEpoch = 0
|
|
397
|
+
backdropState = null
|
|
334
398
|
resetInteractiveScreenHoldForTest()
|
|
335
399
|
}
|
|
336
400
|
|
|
@@ -2,10 +2,19 @@ import { sanitizeAnsiLine } from "../render/sanitize.ts"
|
|
|
2
2
|
import { c, glyphs } from "../render/theme.ts"
|
|
3
3
|
import { acquireTransientPaint, paintWrite } from "./statusline.ts"
|
|
4
4
|
|
|
5
|
-
// Jaga agar kursor terminal selalu ter-restore meski proses dihentikan
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
// Jaga agar kursor terminal selalu ter-restore meski proses dihentikan
|
|
6
|
+
// (SIGINT/dll). Didaftarkan LAZY saat spinner benar-benar menyembunyikan
|
|
7
|
+
// kursor (pola loading-bar.ts) agar import modul tak menulis ESC[?25h saat exit.
|
|
8
|
+
let exitHookInstalled = false
|
|
9
|
+
function installExitHook(): void {
|
|
10
|
+
if (exitHookInstalled) return
|
|
11
|
+
exitHookInstalled = true
|
|
12
|
+
process.on("exit", () => {
|
|
13
|
+
try {
|
|
14
|
+
if (process.stderr.isTTY) process.stderr.write("\x1b[?25h")
|
|
15
|
+
} catch {}
|
|
16
|
+
})
|
|
17
|
+
}
|
|
9
18
|
|
|
10
19
|
export interface Spinner {
|
|
11
20
|
update: (message: string) => void
|
|
@@ -68,10 +77,14 @@ export function createSpinner(initialMessage: string = "", opts: SpinnerOptions
|
|
|
68
77
|
return
|
|
69
78
|
}
|
|
70
79
|
// Hide cursor during spin
|
|
80
|
+
installExitHook()
|
|
71
81
|
paintWrite("\x1b[?25l")
|
|
72
82
|
owned = acquireTransientPaint("spinner", tick)
|
|
73
83
|
tick()
|
|
74
84
|
intervalId = setInterval(tick, intervalMs)
|
|
85
|
+
try {
|
|
86
|
+
;(intervalId as unknown as { unref?: () => void }).unref?.()
|
|
87
|
+
} catch {}
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
const stopTimer = () => {
|
|
@@ -111,13 +124,13 @@ export function createSpinner(initialMessage: string = "", opts: SpinnerOptions
|
|
|
111
124
|
if (stopped) return
|
|
112
125
|
stopped = true
|
|
113
126
|
stopTimer()
|
|
114
|
-
process.stderr.write(`${c.green(
|
|
127
|
+
process.stderr.write(`${c.green("ok")} ${sanitizeAnsiLine(msg)}\n`)
|
|
115
128
|
},
|
|
116
129
|
error(msg: string) {
|
|
117
130
|
if (stopped) return
|
|
118
131
|
stopped = true
|
|
119
132
|
stopTimer()
|
|
120
|
-
process.stderr.write(`${c.red(
|
|
133
|
+
process.stderr.write(`${c.red("failed")} ${sanitizeAnsiLine(msg)}\n`)
|
|
121
134
|
},
|
|
122
135
|
}
|
|
123
136
|
}
|
package/src/ui/screens/dialog.ts
CHANGED
|
@@ -34,6 +34,17 @@ interface BoxChars {
|
|
|
34
34
|
v: string
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export const MIN_MODAL_COLS = 20
|
|
38
|
+
export const MIN_MODAL_ROWS = 10
|
|
39
|
+
|
|
40
|
+
/** Syarat minimum dimensi terminal agar kotak Layer 2 muat bersih dan terbaca. */
|
|
41
|
+
export function canRenderModal(
|
|
42
|
+
cols: number = process.stdout.columns || 80,
|
|
43
|
+
rows: number = process.stdout.rows || 24,
|
|
44
|
+
): boolean {
|
|
45
|
+
return cols >= MIN_MODAL_COLS && rows >= MIN_MODAL_ROWS
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
/** Lebar kotak popup: skala dari layar; pemanggil membekukan saat mount. */
|
|
38
49
|
export function popupBoxWidth(cols: number): number {
|
|
39
50
|
const safeCols = Math.max(10, cols)
|
|
@@ -147,7 +158,14 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
|
|
|
147
158
|
boxed.push(
|
|
148
159
|
`${box.v} ${padToWidth(cut(t("dlg.more", { n: spec.body.length - shown })), innerW)} ${box.v}`,
|
|
149
160
|
)
|
|
150
|
-
if (footer != null)
|
|
161
|
+
if (footer != null) {
|
|
162
|
+
// Jangan bungkus footer ber-SGR (hintLine / status berwarna) dengan `c.dim`,
|
|
163
|
+
// karena `\x1b[2m` meredupkan tombol pertama lalu reset `\x1b[22m` mematikan
|
|
164
|
+
// dim di pertengahan baris (hint.ts).
|
|
165
|
+
const clippedFooter = cut(footer)
|
|
166
|
+
const styledFooter = clippedFooter.includes("\x1b[") ? clippedFooter : c.dim(clippedFooter)
|
|
167
|
+
boxed.push(`${box.v} ${padToWidth(styledFooter, innerW)} ${box.v}`)
|
|
168
|
+
}
|
|
151
169
|
boxed.push(row(box.bl, bar, box.br))
|
|
152
170
|
|
|
153
171
|
const topRow = Math.max(1, Math.floor((r0 - boxed.length) / 2) + 1)
|