minicode-ai 0.14.1 → 0.14.4
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 +34 -178
- package/cli/args.ts +10 -18
- package/cli/auto-update.ts +32 -2
- package/cli/commands/acp.ts +20 -27
- package/cli/commands/daemon.ts +6 -7
- package/cli/commands/exec.ts +12 -10
- package/cli/commands.ts +6 -9
- package/cli/index.ts +40 -17
- package/cli/provider-manager.ts +1 -3
- package/cli/setup.ts +174 -145
- package/cli/tui.ts +33 -38
- package/docs/CONTROL-PLANE-MAP.md +145 -0
- package/docs/OUTPUT_EVENT_MODEL.md +1 -1
- package/docs/OUTPUT_PROTOCOL_SPEC.md +8 -2
- package/docs/OUTPUT_RENDERING_SPEC.md +35 -6
- package/docs/OUTPUT_UX_RULES.md +1 -1
- package/docs/README.md +14 -102
- package/docs/SUMMARY.md +53 -0
- package/docs/TERMINAL_CONTRACT.md +136 -77
- package/docs/UI_RENDER_PIPELINE.md +204 -0
- package/docs/agents.md +5 -5
- package/docs/architecture.md +23 -12
- package/docs/choosing-mode.md +7 -7
- package/docs/cli.md +22 -29
- package/docs/concepts.md +1 -1
- package/docs/config.md +10 -5
- package/docs/contributing.md +6 -6
- package/docs/environment.md +3 -1
- package/docs/exec.md +5 -5
- package/docs/getting-started.md +14 -12
- package/docs/glossary.md +9 -7
- package/docs/mcp-lsp.md +1 -1
- package/docs/memory-sessions.md +7 -5
- package/docs/policy-sandbox.md +23 -15
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +4 -3
- package/docs/security-model.md +16 -17
- package/docs/security.md +15 -30
- package/docs/skills.md +1 -1
- package/docs/tools.md +6 -6
- package/docs/verify-benchmark.md +16 -0
- package/package.json +5 -5
- package/scripts/vendor-overlays/minicode-context.patch +109 -0
- package/src/app/mentions.ts +4 -3
- package/src/app/provider-layer.ts +13 -1
- package/src/app/session.ts +229 -22
- package/src/app/tool-layer.ts +6 -0
- package/src/config.ts +30 -3
- package/src/constants.ts +19 -0
- package/src/daemon/control.ts +1 -1
- package/src/lib/git-hardening.ts +27 -22
- package/src/lib/safe-open.ts +73 -19
- package/src/lib/trusted-exec.ts +7 -4
- package/src/mcp/client.ts +34 -9
- package/src/mcp/server.ts +2 -3
- package/src/mcp/transport.ts +96 -42
- package/src/memory/files.ts +15 -4
- package/src/memory/vector.ts +5 -1
- package/src/policy/compaction.ts +272 -16
- package/src/policy/context-window.ts +73 -0
- package/src/policy/context.ts +76 -16
- package/src/policy/ratelimit.ts +47 -18
- package/src/policy/tool-contract.ts +4 -10
- package/src/policy/update-check.ts +83 -6
- package/src/policy/usage.ts +31 -14
- package/src/policy/work-mode.ts +1 -1
- package/src/presentation/adapter.ts +64 -2
- package/src/presentation/events.ts +6 -0
- package/src/presentation/model.ts +1 -0
- package/src/presentation/projection.ts +2 -0
- package/src/presentation/reducer.ts +1 -0
- package/src/providers/anthropic.ts +52 -19
- package/src/providers/guards.ts +158 -16
- package/src/providers/provision.ts +12 -3
- package/src/providers/responses.ts +61 -23
- package/src/providers/router.ts +56 -23
- package/src/providers/sse-bounds.ts +170 -0
- package/src/repo/repomap.ts +10 -11
- package/src/runtime/execution-backend.ts +7 -8
- package/src/sandbox/docker.ts +113 -9
- package/src/session/checkpoint.ts +9 -2
- package/src/session/context-projection.ts +14 -0
- package/src/session/context-selector.ts +58 -20
- package/src/session/persistence.ts +6 -3
- package/src/session/verification.ts +55 -16
- package/src/skills/loader.ts +16 -3
- package/src/task/model.ts +21 -70
- package/src/tools/bash.ts +6 -3
- package/src/tools/code_run.ts +6 -5
- package/src/tools/context.ts +8 -0
- package/src/tools/delete_file.ts +2 -1
- package/src/tools/edit.ts +2 -1
- package/src/tools/git.ts +128 -54
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +31 -6
- package/src/tools/lsp.ts +5 -4
- package/src/tools/mcp_call.ts +3 -1
- package/src/tools/memory.ts +175 -180
- package/src/tools/move_file.ts +2 -1
- package/src/tools/patch.ts +2 -1
- package/src/tools/read_file.ts +94 -1
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +9 -1
- package/src/tools/todo.ts +4 -5
- package/src/tools/web_fetch.ts +28 -12
- package/src/tools/web_search.ts +28 -9
- package/src/tools/write_file.ts +2 -1
- package/src/ui/assistant/simple.ts +72 -3
- package/src/ui/footer.ts +131 -66
- package/src/ui/i18n/en.ts +3 -11
- package/src/ui/i18n/id.ts +3 -11
- package/src/ui/input/input.ts +2 -3
- package/src/ui/input/prompt-engine.ts +2 -5
- package/src/ui/render/width.ts +107 -79
- package/src/ui/runtime/screen.ts +49 -37
- package/src/ui/screens/model-manager.ts +3 -10
- package/src/ui/screens/picker.ts +23 -40
- package/src/ui/screens/provider-manager.ts +12 -33
- package/src/ui/screens/wizard.ts +0 -1
- package/src/ui/tui/app.ts +265 -211
- package/src/ui/tui/transcript.ts +87 -8
- package/vendor/minicore/VENDOR.md +9 -5
- package/vendor/minicore/src/core/loop.ts +47 -12
- package/vendor/minicore/src/core/provider.ts +4 -0
- package/vendor/minicore/src/core/session.ts +14 -1
- package/CHANGELOG.md +0 -1185
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +0 -489
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +0 -391
- package/docs/PLAN_UIUX_V6.md +0 -209
- package/docs/changelog.md +0 -3
package/src/ui/i18n/id.ts
CHANGED
|
@@ -4,8 +4,6 @@ import type { MsgKey } from "./locale.ts"
|
|
|
4
4
|
|
|
5
5
|
export const id: Record<MsgKey, string> = {
|
|
6
6
|
"app.placeholder": "tanya sesuatu, / untuk perintah… (Ctrl+D keluar)",
|
|
7
|
-
"app.menuHeader": "─ perintah ─",
|
|
8
|
-
"app.moreLines": " … {n} lagi",
|
|
9
7
|
"app.newBelow": "↓ {n} baris baru di bawah · PgDn ke ekor",
|
|
10
8
|
"app.abortHint": "abort terkirim — tekan Esc sekali lagi untuk keluar",
|
|
11
9
|
"app.working": "Bekerja",
|
|
@@ -40,6 +38,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
40
38
|
"appr.tier.unknown": "efek tidak diketahui",
|
|
41
39
|
"dlg.more": "… {n} lagi",
|
|
42
40
|
"ts.compacted": "… dipadatkan: {reason}",
|
|
41
|
+
"ts.providerAttemptDiscarded": "percobaan provider {attempt} gagal; output parsial dibuang",
|
|
43
42
|
"ts.thinking": "… berpikir",
|
|
44
43
|
"ts.evictMarker": "… {n} baris awal di luar viewport — riwayat penuh di model",
|
|
45
44
|
"ts.statusRunning": "berjalan",
|
|
@@ -63,17 +62,11 @@ export const id: Record<MsgKey, string> = {
|
|
|
63
62
|
"verb.delete": "hapus",
|
|
64
63
|
"verb.edit": "ubah",
|
|
65
64
|
"verb.close": "tutup",
|
|
66
|
-
"pick.filter": "Filter:",
|
|
67
|
-
"pick.placeholder": "ketik untuk saring",
|
|
68
65
|
"pick.noMatch": 'Tidak cocok untuk "{q}"',
|
|
69
|
-
"pick.matches": "{n}/{total} cocok",
|
|
70
|
-
"pick.hint": "↑↓:{select} · Enter:{confirm} · Esc:{back}",
|
|
71
66
|
"pick.fail": "picker gagal: {msg}",
|
|
72
67
|
"pick.failOpen": "picker gagal dibuka: {msg}",
|
|
73
68
|
"model.empty": "Belum ada model",
|
|
74
69
|
"model.noMatch": "Tidak ada model yang cocok",
|
|
75
|
-
"model.title": "Model",
|
|
76
|
-
"model.typeFilter": "ketik untuk saring",
|
|
77
70
|
"model.deleteTitle": "Hapus model",
|
|
78
71
|
"model.deleteFooter": "←/→/y/n pilih · Enter hapus · Esc batal",
|
|
79
72
|
"model.delActive": 'Hapus model AKTIF "{id}"?',
|
|
@@ -81,9 +74,7 @@ export const id: Record<MsgKey, string> = {
|
|
|
81
74
|
"model.failOpen": "model manager gagal dibuka: {msg}",
|
|
82
75
|
"effort.title": "Upaya berpikir",
|
|
83
76
|
"effort.saved": "Thinking: {effort} (sesi berikut)",
|
|
84
|
-
"prov.title": "Penyedia",
|
|
85
77
|
"prov.empty": "Belum ada penyedia",
|
|
86
|
-
"prov.hint": "Enter:{select} · a:{add} · d:{delete} · e:{edit} · Esc:{close}",
|
|
87
78
|
"prov.addTitle": "Tambah penyedia",
|
|
88
79
|
"prov.customUrl": "URL kustom",
|
|
89
80
|
"prov.editTitle": 'Ubah "{id}"',
|
|
@@ -98,7 +89,6 @@ export const id: Record<MsgKey, string> = {
|
|
|
98
89
|
"prov.deleteAsk": " — hapus?",
|
|
99
90
|
"prov.deleteFooter": "←/→/y/n pilih · Enter hapus · Esc batal",
|
|
100
91
|
"prov.failOpen": "provider manager gagal dibuka: {msg}",
|
|
101
|
-
"prov.models": "{n} model",
|
|
102
92
|
"prov.reloadFail": "reload provider gagal — restart untuk menerapkan",
|
|
103
93
|
"prov.detectFail": "Deteksi model gagal: {msg}",
|
|
104
94
|
"prov.updateFail": "Pembaruan gagal: {msg}",
|
|
@@ -279,6 +269,8 @@ export const id: Record<MsgKey, string> = {
|
|
|
279
269
|
"one.answerOpen": " − jawaban\n",
|
|
280
270
|
"one.answerMin": " + jawaban ({n} karakter{cap}) — /expand untuk baca\n",
|
|
281
271
|
"one.answerCap": ", dibatasi 1MB",
|
|
272
|
+
"one.providerAttemptDiscarded":
|
|
273
|
+
"\n[percobaan provider {attempt} gagal; output parsial di atas tidak termasuk jawaban akhir]\n",
|
|
282
274
|
"one.thinkOpen": " − berpikir\n",
|
|
283
275
|
"one.thinkMin": " + berpikir\n",
|
|
284
276
|
"one.more3": "\n ... ({n} lagi)",
|
package/src/ui/input/input.ts
CHANGED
|
@@ -112,9 +112,8 @@ export interface AskLineOptions {
|
|
|
112
112
|
/**
|
|
113
113
|
* Dipanggil untuk setiap keypress SEBELUM logika bawaan (history, applyKey).
|
|
114
114
|
* Return truthy = key sudah ditangani pemanggil; askLine melewatkan handling
|
|
115
|
-
* default dan tetap me-render ulang. Dipakai
|
|
116
|
-
*
|
|
117
|
-
* `line` = isi baris saat ini (untuk Tab kosong).
|
|
115
|
+
* default dan tetap me-render ulang. Dipakai pemanggil untuk kontrol yang
|
|
116
|
+
* khusus pada permukaan input, seperti navigasi mode atau tampilan.
|
|
118
117
|
*/
|
|
119
118
|
onKey?: (key: PromptKey, line: string) => boolean
|
|
120
119
|
}
|
|
@@ -261,11 +261,8 @@ export function applyKey(
|
|
|
261
261
|
return { state: { ...state, sel: (state.sel + 1) % n }, action: "render" }
|
|
262
262
|
}
|
|
263
263
|
case "tab": {
|
|
264
|
-
// Tab
|
|
265
|
-
//
|
|
266
|
-
// Completion dropdown tidak lagi pakai Tab — user pilih via ↑/↓ lalu
|
|
267
|
-
// Enter (lengkapi + kirim). Tanpa ini Tab saat mengetik tidak bisa
|
|
268
|
-
// ganti mode (keluhan nyata) dan menabrak completion.
|
|
264
|
+
// TUI menangani Tab sebagai siklus Work Mode sebelum editor generik.
|
|
265
|
+
// Picker command memilih item dengan ↑/↓ lalu Enter.
|
|
269
266
|
return { state, action: "none" }
|
|
270
267
|
}
|
|
271
268
|
case "enter": {
|
package/src/ui/render/width.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// Lebar tampil
|
|
1
|
+
// Lebar tampil teks dalam kolom terminal.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// baris membungkus sendiri, dan frame TUI (yang dihitung per baris) rusak.
|
|
7
|
-
//
|
|
8
|
-
// Karakter penggabung (combining marks, variation selector, ZWJ) sebaliknya
|
|
9
|
-
// memakan NOL kolom — "é" sebagai e+U+0301 adalah satu kolom, bukan dua.
|
|
3
|
+
// Ukur per grapheme, bukan per code point: satu emoji keluarga atau flag
|
|
4
|
+
// tersusun dari beberapa scalar tetapi tampil sebagai satu glyph dua kolom.
|
|
5
|
+
// Combining marks melekat pada base dan tidak menambah lebar sendiri.
|
|
10
6
|
//
|
|
11
7
|
// Referensi: EastAsianWidth (UAX #11) kategori W dan F. Rentang di bawah adalah
|
|
12
8
|
// blok utama yang relevan untuk keluaran terminal; tidak perlu tabel lengkap
|
|
@@ -58,8 +54,77 @@ const ZERO: [number, number][] = [
|
|
|
58
54
|
[0xfe20, 0xfe2f], // Combining Half Marks
|
|
59
55
|
[0xfeff, 0xfeff], // BOM / ZWNBSP
|
|
60
56
|
[0xe0100, 0xe01ef], // Variation Selectors Supplement
|
|
57
|
+
[0xe0020, 0xe007f], // Tag characters used by emoji flag sequences
|
|
61
58
|
]
|
|
62
59
|
|
|
60
|
+
const UNICODE_MARK = /\p{Mark}/u
|
|
61
|
+
const EMOJI = /\p{Emoji}/u
|
|
62
|
+
const EMOJI_PRESENTATION = /\p{Emoji_Presentation}/u
|
|
63
|
+
const EXTENDED_PICTOGRAPHIC = /\p{Extended_Pictographic}/u
|
|
64
|
+
let widthSegmenter: Intl.Segmenter | undefined
|
|
65
|
+
|
|
66
|
+
function segmentGraphemes(text: string): string[] {
|
|
67
|
+
try {
|
|
68
|
+
widthSegmenter ??= new Intl.Segmenter("und", { granularity: "grapheme" })
|
|
69
|
+
return Array.from(widthSegmenter.segment(text), (part) => part.segment)
|
|
70
|
+
} catch {
|
|
71
|
+
// Bun yang didukung MiniCode menyediakan Intl.Segmenter; fallback ini
|
|
72
|
+
// menjaga module tetap bisa dipakai di runtime tertanam yang lebih tua.
|
|
73
|
+
return Array.from(text)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function graphemeWidth(grapheme: string): number {
|
|
78
|
+
const points = Array.from(grapheme, (part) => part.codePointAt(0)!)
|
|
79
|
+
const has = (from: number, to: number): boolean => points.some((cp) => cp >= from && cp <= to)
|
|
80
|
+
const containsEmoji = points.some((cp) => EMOJI.test(String.fromCodePoint(cp)))
|
|
81
|
+
const containsPictograph = points.some((cp) =>
|
|
82
|
+
EXTENDED_PICTOGRAPHIC.test(String.fromCodePoint(cp)),
|
|
83
|
+
)
|
|
84
|
+
if (
|
|
85
|
+
has(0x20e3, 0x20e3) || // keycap
|
|
86
|
+
has(0x1f1e6, 0x1f1ff) || // regional-indicator flag (including a lone RI, conservatively)
|
|
87
|
+
has(0x1f3fb, 0x1f3ff) || // skin-tone modifier
|
|
88
|
+
(has(0x200d, 0x200d) && containsPictograph) || // emoji ZWJ sequence
|
|
89
|
+
(has(0xfe0f, 0xfe0f) && containsEmoji) || // explicit emoji presentation
|
|
90
|
+
points.some((cp) => EMOJI_PRESENTATION.test(String.fromCodePoint(cp)))
|
|
91
|
+
) {
|
|
92
|
+
return 2
|
|
93
|
+
}
|
|
94
|
+
let width = 0
|
|
95
|
+
for (const cp of points) width += charWidth(cp)
|
|
96
|
+
return width
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface DisplayToken {
|
|
100
|
+
text: string
|
|
101
|
+
width: number
|
|
102
|
+
escape: boolean
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Token terminal: escape utuh atau grapheme utuh dengan lebar display yang sama. */
|
|
106
|
+
function* displayTokens(s: string): Generator<DisplayToken> {
|
|
107
|
+
let i = 0
|
|
108
|
+
while (i < s.length) {
|
|
109
|
+
if (s[i] === "\x1b") {
|
|
110
|
+
const length = escapeLength(s, i)
|
|
111
|
+
if (length > 0) {
|
|
112
|
+
yield { text: s.slice(i, i + length), width: 0, escape: true }
|
|
113
|
+
i += length
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let end = s.indexOf("\x1b", i)
|
|
118
|
+
if (end < 0) end = s.length
|
|
119
|
+
if (end === i) end = i + 1
|
|
120
|
+
const run = s.slice(i, end)
|
|
121
|
+
for (const text of segmentGraphemes(run)) {
|
|
122
|
+
yield { text, width: graphemeWidth(text), escape: false }
|
|
123
|
+
}
|
|
124
|
+
i = end
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
63
128
|
function inRanges(cp: number, ranges: [number, number][]): boolean {
|
|
64
129
|
let lo = 0
|
|
65
130
|
let hi = ranges.length - 1
|
|
@@ -83,31 +148,19 @@ export function charWidth(cp: number): number {
|
|
|
83
148
|
if (cp === 0x09) return 8
|
|
84
149
|
// C0/C1 control: tidak menempati kolom (dan seharusnya tidak sampai ke layar).
|
|
85
150
|
if (cp < 0x20 || (cp >= 0x7f && cp < 0xa0)) return 0
|
|
86
|
-
if (inRanges(cp, ZERO)) return 0
|
|
151
|
+
if (inRanges(cp, ZERO) || UNICODE_MARK.test(String.fromCodePoint(cp))) return 0
|
|
87
152
|
if (inRanges(cp, WIDE)) return 2
|
|
88
153
|
return 1
|
|
89
154
|
}
|
|
90
155
|
|
|
91
156
|
/**
|
|
92
157
|
* Lebar tampil string dalam kolom terminal. Sekuens ANSI dan karakter
|
|
93
|
-
* penggabung tidak dihitung; CJK/emoji dihitung
|
|
158
|
+
* penggabung tidak dihitung; CJK/fullwidth dan emoji presentation dihitung
|
|
159
|
+
* dua kolom per grapheme. Lebar glyph spesifik terminal tidak diprobe.
|
|
94
160
|
*/
|
|
95
161
|
export function displayWidth(s: string): number {
|
|
96
162
|
let w = 0
|
|
97
|
-
|
|
98
|
-
while (i < s.length) {
|
|
99
|
-
// Lewati sekuens escape — tidak menempati kolom.
|
|
100
|
-
if (s[i] === "\x1b") {
|
|
101
|
-
const len = escapeLength(s, i)
|
|
102
|
-
if (len > 0) {
|
|
103
|
-
i += len
|
|
104
|
-
continue
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const cp = s.codePointAt(i)!
|
|
108
|
-
w += charWidth(cp)
|
|
109
|
-
i += cp > 0xffff ? 2 : 1
|
|
110
|
-
}
|
|
163
|
+
for (const token of displayTokens(s)) if (!token.escape) w += token.width
|
|
111
164
|
return w
|
|
112
165
|
}
|
|
113
166
|
|
|
@@ -237,36 +290,23 @@ export function truncateToWidth(s: string, width: number, ellipsis = "..."): str
|
|
|
237
290
|
let w = 0
|
|
238
291
|
let sawSgr = false
|
|
239
292
|
let cut = false
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (!isSgrSeq(seq)) {
|
|
251
|
-
i += len
|
|
252
|
-
continue
|
|
253
|
-
}
|
|
254
|
-
if (seq.endsWith("m")) sawSgr = true
|
|
255
|
-
out += seq
|
|
256
|
-
i += len
|
|
257
|
-
continue
|
|
258
|
-
}
|
|
293
|
+
for (const token of displayTokens(s)) {
|
|
294
|
+
if (token.escape) {
|
|
295
|
+
// Hanya SGR yang disalin — sekuens kontrol lain (clear, alternate
|
|
296
|
+
// screen, OSC) DIBUANG di sini agar satu pemanggil yang lupa sanitasi
|
|
297
|
+
// tidak menjadi injeksi terminal (defense-in-depth, bukan pengganti
|
|
298
|
+
// sanitizeAnsi di batas input tak-terpercaya).
|
|
299
|
+
if (!isSgrSeq(token.text)) continue
|
|
300
|
+
if (token.text.endsWith("m")) sawSgr = true
|
|
301
|
+
out += token.text
|
|
302
|
+
continue
|
|
259
303
|
}
|
|
260
|
-
|
|
261
|
-
const cw = charWidth(cp)
|
|
262
|
-
if (w + cw > budget) {
|
|
304
|
+
if (w + token.width > budget) {
|
|
263
305
|
cut = true
|
|
264
306
|
break
|
|
265
307
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
w += cw
|
|
269
|
-
i += size
|
|
308
|
+
out += token.text
|
|
309
|
+
w += token.width
|
|
270
310
|
}
|
|
271
311
|
const tail = cut && width > ellW ? ellipsis : ""
|
|
272
312
|
return sawSgr ? `${out}\x1b[0m${tail}` : out + tail
|
|
@@ -290,7 +330,6 @@ export function chunkByWidth(s: string, width: number): string[] {
|
|
|
290
330
|
const out: string[] = []
|
|
291
331
|
let cur = ""
|
|
292
332
|
let w = 0
|
|
293
|
-
let i = 0
|
|
294
333
|
// Sekuens SGR yang masih "terbuka" — disuntikkan ke potongan berikutnya
|
|
295
334
|
// agar warna tidak hilang saat kata berwarna panjang dipecah. SEMUA pembuka
|
|
296
335
|
// diingat (bukan satu): `\x1b[1m\x1b[31m…` yang terbelah harus membawa bold
|
|
@@ -304,39 +343,28 @@ export function chunkByWidth(s: string, width: number): string[] {
|
|
|
304
343
|
cur = openSgr.join("") // lanjutkan warna ke potongan berikutnya
|
|
305
344
|
w = 0
|
|
306
345
|
}
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (
|
|
319
|
-
if (params.some((p) => p !== "" && !SGR_OFF.has(p))) {
|
|
320
|
-
openSgr.push(seq)
|
|
321
|
-
// Batas tumpukan: input patologis (ganti warna tiap karakter tanpa
|
|
322
|
-
// reset) tak boleh membuat tiap potongan membawa ratusan sekuens.
|
|
323
|
-
if (openSgr.length > 8) openSgr = openSgr.slice(-8)
|
|
324
|
-
}
|
|
346
|
+
for (const token of displayTokens(s)) {
|
|
347
|
+
if (token.escape) {
|
|
348
|
+
const seq = token.text
|
|
349
|
+
if (!isSgrSeq(seq)) continue
|
|
350
|
+
if (seq.endsWith("m")) {
|
|
351
|
+
const params = seq.slice(2, -1).split(/[:;]/)
|
|
352
|
+
if (params.some((p) => SGR_OFF.has(p) || p === "")) openSgr = []
|
|
353
|
+
if (params.some((p) => p !== "" && !SGR_OFF.has(p))) {
|
|
354
|
+
openSgr.push(seq)
|
|
355
|
+
// Batas tumpukan: input patologis (ganti warna tiap karakter tanpa
|
|
356
|
+
// reset) tak boleh membuat tiap potongan membawa ratusan sekuens.
|
|
357
|
+
if (openSgr.length > 8) openSgr = openSgr.slice(-8)
|
|
325
358
|
}
|
|
326
|
-
cur += seq
|
|
327
|
-
i += len
|
|
328
|
-
continue
|
|
329
359
|
}
|
|
360
|
+
cur += seq
|
|
361
|
+
continue
|
|
330
362
|
}
|
|
331
|
-
|
|
332
|
-
const cw = charWidth(cp)
|
|
333
|
-
const size = cp > 0xffff ? 2 : 1
|
|
334
|
-
if (w + cw > width && cur !== "") {
|
|
363
|
+
if (w + token.width > width && cur !== "") {
|
|
335
364
|
pushChunk()
|
|
336
365
|
}
|
|
337
|
-
cur +=
|
|
338
|
-
w +=
|
|
339
|
-
i += size
|
|
366
|
+
cur += token.text
|
|
367
|
+
w += token.width
|
|
340
368
|
}
|
|
341
369
|
if (cur !== "") pushChunk()
|
|
342
370
|
return out.length ? out : [""]
|
package/src/ui/runtime/screen.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface AltScreen {
|
|
|
54
54
|
readonly ok: boolean
|
|
55
55
|
readonly cols: number
|
|
56
56
|
readonly rows: number
|
|
57
|
-
/** Lukis
|
|
57
|
+
/** Lukis frame penuh; exception writer dipropagasikan agar owner menutup sesi. */
|
|
58
58
|
paint(lines: string[], cursor?: { row: number; col: number }): void
|
|
59
59
|
/**
|
|
60
60
|
* Lukis REGION TANPA clear: popup di atas konten pemilik layar (App TUI).
|
|
@@ -102,6 +102,14 @@ export function openAltScreen(): AltScreen {
|
|
|
102
102
|
process.stdout.write(RESET_REGION)
|
|
103
103
|
process.stdout.write(ENTER)
|
|
104
104
|
} catch {
|
|
105
|
+
// ENTER mungkin sudah terkirim sebelum writer melempar; pulihkan
|
|
106
|
+
// buffer utama sebelum menyatakan terminal tidak mampu.
|
|
107
|
+
try {
|
|
108
|
+
process.stdout.write(EXIT)
|
|
109
|
+
} catch {}
|
|
110
|
+
try {
|
|
111
|
+
process.stdout.write(RESET_REGION)
|
|
112
|
+
} catch {}
|
|
105
113
|
return nullScreen()
|
|
106
114
|
}
|
|
107
115
|
}
|
|
@@ -130,48 +138,44 @@ export function openAltScreen(): AltScreen {
|
|
|
130
138
|
},
|
|
131
139
|
paint(lines: string[], cursor?: { row: number; col: number }): void {
|
|
132
140
|
if (closed) return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
process.stdout.write(SYNC_END)
|
|
144
|
-
} catch {}
|
|
141
|
+
process.stdout.write(SYNC_START)
|
|
142
|
+
process.stdout.write(HOME)
|
|
143
|
+
process.stdout.write(CLEAR_ALL)
|
|
144
|
+
process.stdout.write(lines.join("\r\n"))
|
|
145
|
+
if (cursor) {
|
|
146
|
+
const row = Math.max(1, Math.floor(cursor.row))
|
|
147
|
+
const col = Math.max(1, Math.floor(cursor.col))
|
|
148
|
+
process.stdout.write(`\x1b[?25l\x1b[${row};${col}H\x1b[?25h`)
|
|
149
|
+
}
|
|
150
|
+
process.stdout.write(SYNC_END)
|
|
145
151
|
},
|
|
146
152
|
paintRegion(lines: string[], topRow: number): void {
|
|
147
153
|
if (closed) return
|
|
148
154
|
// Melukis nol baris = no-op murni (bukan clear): pemanggil yang ingin
|
|
149
155
|
// menghapus memakai clearRegion() eksplisit.
|
|
150
156
|
if (!lines.length) return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
lastRegion = h > 0 ? { top, height: h } : null
|
|
174
|
-
} catch {}
|
|
157
|
+
const top = Math.max(1, Math.floor(topRow) || 1)
|
|
158
|
+
const h = lines.length
|
|
159
|
+
// Union region lama + baru: kotak yang menyusut/bergeser (filter,
|
|
160
|
+
// notice hilang) harus menghapus sisa bingkainya sendiri — pemilik
|
|
161
|
+
// layar tak tahu geometri popup.
|
|
162
|
+
let clearTop = top
|
|
163
|
+
let clearBottom = top + Math.max(0, h - 1)
|
|
164
|
+
if (lastRegion) {
|
|
165
|
+
clearTop = Math.min(clearTop, lastRegion.top)
|
|
166
|
+
clearBottom = Math.max(clearBottom, lastRegion.top + lastRegion.height - 1)
|
|
167
|
+
}
|
|
168
|
+
let out = SYNC_START
|
|
169
|
+
for (let r = clearTop; r <= clearBottom; r++) {
|
|
170
|
+
const i = r - top
|
|
171
|
+
// Baris diasumsi satu-baris-tersanitasi dari dialogBox (tanpa \n —
|
|
172
|
+
// \n akan menggeser kursor dan merusak baris berikut; split defensif).
|
|
173
|
+
const row = i >= 0 && i < h ? ((lines[i] ?? "").split("\n")[0] ?? "") : ""
|
|
174
|
+
out += `\x1b[${r};1H\x1b[2K${row}`
|
|
175
|
+
}
|
|
176
|
+
out += SYNC_END
|
|
177
|
+
process.stdout.write(out)
|
|
178
|
+
lastRegion = h > 0 ? { top, height: h } : null
|
|
175
179
|
},
|
|
176
180
|
clearRegion(): void {
|
|
177
181
|
if (closed) return
|
|
@@ -195,6 +199,9 @@ export function openAltScreen(): AltScreen {
|
|
|
195
199
|
} catch {}
|
|
196
200
|
depth = Math.max(0, depth - 1)
|
|
197
201
|
if (depth === 0) {
|
|
202
|
+
try {
|
|
203
|
+
process.stdout.write(SYNC_END)
|
|
204
|
+
} catch {}
|
|
198
205
|
try {
|
|
199
206
|
process.stdout.write(EXIT)
|
|
200
207
|
} catch {}
|
|
@@ -218,8 +225,13 @@ export function altScreenDepth(): number {
|
|
|
218
225
|
*/
|
|
219
226
|
export function forceRestoreScreenForSignal(): void {
|
|
220
227
|
if (depth > 0) {
|
|
228
|
+
try {
|
|
229
|
+
process.stdout.write(SYNC_END)
|
|
230
|
+
} catch {}
|
|
221
231
|
try {
|
|
222
232
|
process.stdout.write(EXIT)
|
|
233
|
+
} catch {}
|
|
234
|
+
try {
|
|
223
235
|
process.stdout.write(RESET_REGION)
|
|
224
236
|
} catch {}
|
|
225
237
|
depth = 0
|
|
@@ -85,9 +85,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
85
85
|
return new Promise<void>((resolve) => {
|
|
86
86
|
const visibleRows = () => {
|
|
87
87
|
const rows = process.stdout.rows || 24
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
return Math.max(1, Math.min(rows - 5, 8))
|
|
88
|
+
// Dialog tanpa judul/footer; satu baris dipakai untuk pencarian.
|
|
89
|
+
return Math.max(1, Math.min(rows - 3, 8))
|
|
91
90
|
}
|
|
92
91
|
// Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
|
|
93
92
|
// tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
|
|
@@ -134,9 +133,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
134
133
|
// App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
|
|
135
134
|
const box = dialogBox(
|
|
136
135
|
{
|
|
137
|
-
title:
|
|
136
|
+
title: "",
|
|
138
137
|
body: bodyLinesModal(),
|
|
139
|
-
footer: modelHint(),
|
|
140
138
|
minWidth: MODAL_BOX_W,
|
|
141
139
|
maxWidth: MODAL_BOX_W,
|
|
142
140
|
maxHeight: 14,
|
|
@@ -164,11 +162,6 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
|
|
|
164
162
|
} catch {}
|
|
165
163
|
}
|
|
166
164
|
|
|
167
|
-
/** Hint footer /model: Del/type-to-filter jadi discoverable (dulu tanpa
|
|
168
|
-
* footer — user baru tak tahu cara hapus/saring). */
|
|
169
|
-
const modelHint = (): string =>
|
|
170
|
-
`${c.accent(t("model.typeFilter"))} · Del:${c.accent(t("verb.delete"))} · Enter:${c.accent(t("verb.select"))} · Esc:${c.accent(t("verb.close"))}`
|
|
171
|
-
|
|
172
165
|
// Popup butuh layar mampu; selain itu tolak BERSUARA + batal.
|
|
173
166
|
const screen: AltScreen = openAltScreen()
|
|
174
167
|
const useModal = screen.ok && (process.stdout.rows || 24) >= 10
|
package/src/ui/screens/picker.ts
CHANGED
|
@@ -26,12 +26,10 @@ export interface PickerOptions {
|
|
|
26
26
|
items: PickerItem[]
|
|
27
27
|
onPick: (value: string) => void
|
|
28
28
|
onCancel: () => void
|
|
29
|
-
placeholder?: string
|
|
30
29
|
filterable?: boolean
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
const dim = (s: string): string => c.dim(s)
|
|
34
|
-
ACC_DIM = (s: string) => c.accent(s)
|
|
32
|
+
const dim = (s: string): string => c.dim(s)
|
|
35
33
|
|
|
36
34
|
/** Lebar kotak popup picker TETAP (keputusan rasa: geometri stabil). */
|
|
37
35
|
const PICKER_BOX_W = 64
|
|
@@ -53,10 +51,11 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
53
51
|
if (!process.stdin.isTTY) {
|
|
54
52
|
// Pipe/redirect: item dari config (tak-terpercaya) disanitasi agar ANSI
|
|
55
53
|
// mentah tak mencemari output program (kontrak stdout non-TTY).
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
for (const it of opts.items) {
|
|
55
|
+
const provider = sanitizeAnsiLine(it.provider)
|
|
56
|
+
const name = sanitizeAnsiLine(it.name)
|
|
57
|
+
console.log(provider ? `${provider}::${name}` : name)
|
|
58
|
+
}
|
|
60
59
|
// Fail-closed: pemanggil nested (mis. pickEffort di /model) menunggu
|
|
61
60
|
// onPick/onCancel — tanpa ini await-nya gantung selamanya (busy=true)
|
|
62
61
|
// saat isTTY flip di tengah. Non-TTY = tak ada pilihan = batal.
|
|
@@ -88,11 +87,9 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
88
87
|
// dicetak — keduanya membungkus dan merusak tampilan.
|
|
89
88
|
const visibleRows = () => {
|
|
90
89
|
const rows = process.stdout.rows || 24
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// 1 baris untuk baris counter ("… N more") agar End selalu sampai dasar.
|
|
95
|
-
if (useModal) return Math.max(1, Math.min(rows - 5, 12))
|
|
90
|
+
// Modal tanpa judul/footer; sisakan border dan baris pencarian bila ada.
|
|
91
|
+
if (useModal) return Math.max(1, Math.min(rows - (isFilterable ? 3 : 2), 12))
|
|
92
|
+
const chrome = isFilterable ? 3 : 2
|
|
96
93
|
return Math.max(1, Math.min(rows - chrome, 12))
|
|
97
94
|
}
|
|
98
95
|
// Lebar konten = lebar kotak TETAP (min=max, keputusan rasa: geometri
|
|
@@ -115,11 +112,9 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
115
112
|
const cut = (s: string) => truncateToWidth(s, w)
|
|
116
113
|
const lines: string[] = []
|
|
117
114
|
if (isFilterable) {
|
|
118
|
-
const placeholderText = opts.placeholder ?? t("pick.placeholder")
|
|
119
115
|
// Filter = input user tak terpercaya — sanitasi sebelum tampil.
|
|
120
|
-
const display = filter ? c.brightCyan(sanitizeAnsiLine(filter)) :
|
|
121
|
-
|
|
122
|
-
lines.push(cut(`${label} ${display}`))
|
|
116
|
+
const display = filter ? c.brightCyan(sanitizeAnsiLine(filter)) : ""
|
|
117
|
+
lines.push(cut(`${dim(">")} ${display}${c.accent("█")}`))
|
|
123
118
|
}
|
|
124
119
|
if (items.length === 0) {
|
|
125
120
|
lines.push(cut(dim(` ${t("pick.noMatch", { q: sanitizeAnsiLine(filter) })}`)))
|
|
@@ -128,38 +123,27 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
128
123
|
for (let i = 0; i < rows.length; i++) {
|
|
129
124
|
const it = rows[i]!
|
|
130
125
|
const picked = i === sel - scroll
|
|
131
|
-
//
|
|
132
|
-
// Highlight query
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const rawLabel = `${sanitizeAnsiLine(it.name)}${it.provider ? ` — ${sanitizeAnsiLine(it.provider)}` : ""}`
|
|
126
|
+
// Label provider::model ringkas; teks tetap disanitasi sebelum truncate.
|
|
127
|
+
// Highlight query diterapkan sebelum truncate agar posisi kolom tepat.
|
|
128
|
+
const safeProvider = sanitizeAnsiLine(it.provider)
|
|
129
|
+
const rawLabel = safeProvider
|
|
130
|
+
? `${safeProvider}::${sanitizeAnsiLine(it.name)}`
|
|
131
|
+
: sanitizeAnsiLine(it.name)
|
|
138
132
|
const label = highlightMatch(truncateToWidth(rawLabel, w - 4), filter)
|
|
139
133
|
if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
|
|
140
134
|
else lines.push(` ${dim(label)}`)
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
lines.push(cut(dim(t("dlg.more", { n: items.length - scroll - v }))))
|
|
144
|
-
} else if (isFilterable && filter) {
|
|
145
|
-
lines.push(
|
|
146
|
-
cut(dim(` ${t("pick.matches", { n: items.length, total: opts.items.length })}`)),
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
return lines
|
|
136
|
+
return lines.slice(0, v + (isFilterable ? 1 : 0))
|
|
150
137
|
}
|
|
151
138
|
|
|
152
|
-
const hintText = (): string => t("pick.hint")
|
|
153
|
-
|
|
154
139
|
const render = () => {
|
|
155
140
|
// Popup komposit: HANYA region kotak yang dilukis (tanpa clear) di atas
|
|
156
141
|
// konten pemilik layar (transkrip App / alt-buffer wizard). Pemilik
|
|
157
142
|
// me-repaint penuh saat popup tutup. Lebar TETAP 64 (min=max).
|
|
158
143
|
const box = dialogBox(
|
|
159
144
|
{
|
|
160
|
-
title:
|
|
145
|
+
title: "",
|
|
161
146
|
body: bodyLines(),
|
|
162
|
-
footer: hintText(),
|
|
163
147
|
minWidth: PICKER_BOX_W,
|
|
164
148
|
maxWidth: PICKER_BOX_W,
|
|
165
149
|
},
|
|
@@ -167,16 +151,15 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
|
|
|
167
151
|
screen.rows,
|
|
168
152
|
)
|
|
169
153
|
screen.paintRegion(box.lines, box.topRow)
|
|
170
|
-
// Parkir kursor
|
|
171
|
-
//
|
|
172
|
-
// filter kosong, parkir di baris item aktif (navigasi ↑↓).
|
|
154
|
+
// Parkir kursor pada input filter meski kosong agar teks pertama langsung
|
|
155
|
+
// masuk ke pencarian; navigasi item tetap memakai tombol panah.
|
|
173
156
|
// Kolom = padding kiri + border + spasi + lebar label+filter + 1.
|
|
174
157
|
try {
|
|
175
|
-
if (isFilterable
|
|
158
|
+
if (isFilterable) {
|
|
176
159
|
const li = Math.min(box.lines.length - 1, box.bodyTop)
|
|
177
160
|
const row = box.topRow + li
|
|
178
161
|
const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
|
|
179
|
-
const col = leftPad + 2 + displayWidth(stripAnsi(
|
|
162
|
+
const col = leftPad + 2 + 2 + displayWidth(stripAnsi(filter)) + 1
|
|
180
163
|
process.stdout.write(`\x1b[${row};${Math.max(1, col)}H\x1b[?25h`)
|
|
181
164
|
} else {
|
|
182
165
|
const itemRow = Math.min(Math.max(0, sel - scroll), Math.max(0, visibleRows() - 1))
|