minicode-ai 0.15.0 → 0.20.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 +6 -4
- package/cli/commands/exec.ts +3 -2
- package/cli/commands/openwork.ts +1 -1
- package/cli/commands.ts +6 -6
- package/cli/index.ts +4 -4
- package/cli/model-manager.ts +1 -1
- package/cli/setup.ts +57 -30
- package/cli/tui.ts +106 -11
- package/docs/CONTROL-PLANE-MAP.md +6 -4
- package/docs/OUTPUT_EVENT_MODEL.md +4 -3
- package/docs/OUTPUT_PROTOCOL_SPEC.md +1 -1
- package/docs/OUTPUT_RENDERING_SPEC.md +16 -4
- package/docs/OUTPUT_UX_RULES.md +38 -32
- package/docs/P14_OPEN_WORK.md +290 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +36 -22
- package/docs/TERMINAL_CONTRACT.md +54 -7
- package/docs/UI_RENDER_PIPELINE.md +47 -8
- package/docs/agents.md +1 -1
- package/docs/architecture.md +9 -8
- package/docs/autonomous-scheduler.md +142 -0
- package/docs/choosing-mode.md +2 -2
- package/docs/cli.md +4 -4
- package/docs/concepts.md +5 -5
- package/docs/config-providers.md +3 -3
- package/docs/contributing.md +7 -9
- package/docs/environment.md +5 -4
- package/docs/getting-started.md +4 -4
- package/docs/mcp-lsp.md +2 -2
- package/docs/memory-sessions.md +1 -1
- package/docs/policy-sandbox.md +7 -4
- package/docs/pricing-budget.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/repl.md +5 -5
- package/docs/security-model.md +1 -1
- package/docs/security.md +9 -8
- package/docs/skills.md +2 -2
- package/docs/terminal.md +10 -2
- package/docs/tools.md +4 -4
- package/docs/troubleshooting.md +3 -3
- package/docs/verify-benchmark.md +0 -3
- package/package.json +9 -18
- package/src/app/session.ts +40 -7
- package/src/constants.ts +31 -0
- package/src/hooks/run.ts +5 -6
- package/src/mcp/http-transport.ts +1 -1
- package/src/policy/bash-guard.ts +26 -6
- package/src/policy/compaction.ts +107 -17
- package/src/policy/consequence-engine.ts +3 -3
- package/src/policy/context-window.ts +24 -1
- package/src/policy/context.ts +16 -4
- package/src/policy/permission.ts +219 -4
- package/src/presentation/adapter.ts +1 -1
- package/src/presentation/events.ts +2 -2
- package/src/presentation/label.ts +3 -3
- package/src/presentation/model.ts +4 -0
- package/src/presentation/store.ts +2 -2
- package/src/runtime/child-execution.ts +1 -1
- package/src/runtime/composition.ts +5 -5
- package/src/runtime/execution-registry.ts +1 -1
- package/src/runtime/production-execution.ts +3 -3
- package/src/runtime/production-runtime.ts +2 -2
- package/src/runtime/runtime-capabilities.ts +1 -1
- package/src/runtime/runtime-status-facts.ts +1 -1
- package/src/runtime/runtime-task-admission.ts +2 -2
- package/src/session/context-assembly.ts +8 -1
- package/src/session/context-identity.ts +2 -2
- package/src/session/context-projection.ts +36 -11
- package/src/session/persistence.ts +1 -1
- package/src/task/autonomous-context.ts +2 -2
- package/src/task/autonomous-policy.ts +3 -3
- package/src/task/model.ts +2 -2
- package/src/task/production-scheduler.ts +2 -2
- package/src/task/scheduler.ts +3 -2
- package/src/task/scheduling-policy.ts +2 -1
- package/src/task/trigger.ts +5 -5
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +1 -1
- package/src/ui/assistant/simple.ts +33 -30
- package/src/ui/footer.ts +48 -9
- package/src/ui/i18n/en.ts +1 -0
- package/src/ui/i18n/id.ts +1 -0
- package/src/ui/input/prompt-engine.ts +36 -10
- package/src/ui/render/cells.ts +320 -0
- package/src/ui/render/composer-wrap.ts +73 -0
- package/src/ui/render/detail.ts +2 -2
- package/src/ui/render/ledger.ts +47 -0
- package/src/ui/render/theme.ts +32 -4
- package/src/ui/render/width.ts +2 -2
- package/src/ui/render/wrap.ts +5 -3
- package/src/ui/runtime/screen.ts +84 -7
- package/src/ui/runtime/statusline.ts +26 -0
- package/src/ui/screens/model-manager.ts +1 -1
- package/src/ui/tui/app.ts +336 -65
- package/src/ui/tui/transcript.ts +247 -88
- package/vendor/minicore/VENDOR.md +15 -11
- package/vendor/minicore/src/core/events.ts +1 -0
- package/vendor/minicore/src/core/loop.ts +10 -0
- package/vendor/minicore/src/core/session.ts +39 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// Framebuffer sel untuk penulisan terminal inkremental.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa ada: diff per BARIS (CUP+EL lalu tulis ulang seluruh baris) masih
|
|
4
|
+
// membayar O(panjang baris) untuk setiap perubahan kecil. Mengetik satu huruf
|
|
5
|
+
// di prompt 1.000 karakter berarti menulis ulang ±1.000 karakter ke ConPTY.
|
|
6
|
+
// Modul ini memecah baris menjadi SEL (grapheme + gaya SGR) lalu menghasilkan
|
|
7
|
+
// hanya rentang kolom yang benar-benar berubah — mekanisme yang sama dengan
|
|
8
|
+
// framebuffer/diff-cell OpenTUI, tetapi murni TypeScript tanpa dependency.
|
|
9
|
+
//
|
|
10
|
+
// Kontrak penting:
|
|
11
|
+
// - Frame LOGIS tetap penuh (pemilik layar mengirim `rows` baris utuh); modul
|
|
12
|
+
// ini hanya memutuskan byte FISIK apa yang ditulis.
|
|
13
|
+
// - Glyph lebar (CJK/emoji) menempati beberapa kolom: sel pertama membawa
|
|
14
|
+
// glyph, kolom lanjutan ditandai `cont` agar diff tidak memotong glyph.
|
|
15
|
+
// - Gaya disimpan sebagai STATE SGR, bukan riwayat sekuens mentah: terminal
|
|
16
|
+
// memperlakukan SGR sebagai himpunan atribut aktif, jadi `\x1b[39m` harus
|
|
17
|
+
// membatalkan warna foreground sebelumnya — bukan menumpuk sebagai teks.
|
|
18
|
+
// Tanpa normalisasi ini setiap sel sesudah reset membawa string yang terus
|
|
19
|
+
// memanjang, diff menganggap sel identik "berubah", dan footer ditulis ulang
|
|
20
|
+
// tiap detik.
|
|
21
|
+
import { escapeLength, graphemeWidth, segmentGraphemes } from "./width.ts"
|
|
22
|
+
|
|
23
|
+
/** Satu kolom layar. `cont` = kolom lanjutan glyph lebar (tanpa glyph sendiri). */
|
|
24
|
+
export interface Cell {
|
|
25
|
+
glyph: string
|
|
26
|
+
/** Sekuens SGR aktif ("" = atribut default). */
|
|
27
|
+
style: string
|
|
28
|
+
cont?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const BLANK: Cell = { glyph: " ", style: "" }
|
|
32
|
+
|
|
33
|
+
/** SGR saja (`ESC[...m` dengan parameter angka/`;`/`:`) — sisanya diabaikan. */
|
|
34
|
+
function isSgr(seq: string): boolean {
|
|
35
|
+
if (!seq.startsWith("\x1b[") || !seq.endsWith("m")) return false
|
|
36
|
+
for (let i = 2; i < seq.length - 1; i++) {
|
|
37
|
+
const ch = seq[i]!
|
|
38
|
+
if (!((ch >= "0" && ch <= "9") || ch === ";" || ch === ":")) return false
|
|
39
|
+
}
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Urutan serialisasi kanonik — hasil sama apa pun urutan SGR masukannya. */
|
|
44
|
+
const SGR_ORDER = [
|
|
45
|
+
"bold",
|
|
46
|
+
"dim",
|
|
47
|
+
"italic",
|
|
48
|
+
"underline",
|
|
49
|
+
"blink",
|
|
50
|
+
"inverse",
|
|
51
|
+
"conceal",
|
|
52
|
+
"strike",
|
|
53
|
+
"fg",
|
|
54
|
+
"bg",
|
|
55
|
+
] as const
|
|
56
|
+
|
|
57
|
+
interface SgrState {
|
|
58
|
+
values: Map<string, string>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function setGroup(state: SgrState, group: string, value: string | null): void {
|
|
62
|
+
if (value === null) state.values.delete(group)
|
|
63
|
+
else state.values.set(group, value)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function serializeSgr(state: SgrState): string {
|
|
67
|
+
if (state.values.size === 0) return ""
|
|
68
|
+
const parts: string[] = []
|
|
69
|
+
for (const group of SGR_ORDER) {
|
|
70
|
+
const value = state.values.get(group)
|
|
71
|
+
if (value !== undefined) parts.push(value)
|
|
72
|
+
}
|
|
73
|
+
return `\x1b[${parts.join(";")}m`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Parameter warna lanjutan (`38;5;n` / `38;2;r;g;b`), atau null bila tak lengkap. */
|
|
77
|
+
function readExtended(
|
|
78
|
+
tokens: string[],
|
|
79
|
+
i: number,
|
|
80
|
+
code: number,
|
|
81
|
+
): { value: string; next: number } | null {
|
|
82
|
+
const mode = tokens[i + 1]
|
|
83
|
+
if (mode === "5") {
|
|
84
|
+
const slot = tokens[i + 2]
|
|
85
|
+
if (slot === undefined) return null
|
|
86
|
+
return { value: `${code};5;${slot}`, next: i + 2 }
|
|
87
|
+
}
|
|
88
|
+
if (mode === "2") {
|
|
89
|
+
const r = tokens[i + 2]
|
|
90
|
+
const g = tokens[i + 3]
|
|
91
|
+
const b = tokens[i + 4]
|
|
92
|
+
if (r === undefined || g === undefined || b === undefined) return null
|
|
93
|
+
return { value: `${code};2;${r};${g};${b}`, next: i + 4 }
|
|
94
|
+
}
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Terapkan satu sekuens SGR ke state. Reset penuh (kosong/0) membuang semua.
|
|
100
|
+
* Parameter tak dikenal disimpan apa adanya (grup `raw:<token>`) supaya tidak
|
|
101
|
+
* hilang dan tetap idempoten di paint ulang.
|
|
102
|
+
*/
|
|
103
|
+
function applySgrTo(state: SgrState, seq: string): void {
|
|
104
|
+
const body = seq.slice(2, -1)
|
|
105
|
+
const tokens = body === "" ? ["0"] : body.split(";")
|
|
106
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
107
|
+
const token = tokens[i]!
|
|
108
|
+
// Bentuk titik-dua (mis. `38:5:196`) dibiarkan utuh — satu nilai warna.
|
|
109
|
+
const colon = token.indexOf(":")
|
|
110
|
+
if (colon >= 0) {
|
|
111
|
+
const head = token.slice(0, colon)
|
|
112
|
+
if (head === "38" || head === "58") setGroup(state, "fg", token)
|
|
113
|
+
else if (head === "48") setGroup(state, "bg", token)
|
|
114
|
+
else setGroup(state, `raw:${head}`, token)
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
117
|
+
const n = token === "" ? 0 : Number(token)
|
|
118
|
+
if (Number.isNaN(n)) {
|
|
119
|
+
setGroup(state, `raw:${token}`, token)
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
if (n === 0) {
|
|
123
|
+
state.values.clear()
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
if (n === 38 || n === 48) {
|
|
127
|
+
const extended = readExtended(tokens, i, n)
|
|
128
|
+
if (!extended) {
|
|
129
|
+
setGroup(state, `raw:${n}`, token)
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
setGroup(state, n === 38 ? "fg" : "bg", extended.value)
|
|
133
|
+
i = extended.next
|
|
134
|
+
continue
|
|
135
|
+
}
|
|
136
|
+
switch (n) {
|
|
137
|
+
case 1:
|
|
138
|
+
setGroup(state, "bold", "1")
|
|
139
|
+
break
|
|
140
|
+
case 2:
|
|
141
|
+
setGroup(state, "dim", "2")
|
|
142
|
+
break
|
|
143
|
+
case 22:
|
|
144
|
+
setGroup(state, "bold", null)
|
|
145
|
+
setGroup(state, "dim", null)
|
|
146
|
+
break
|
|
147
|
+
case 3:
|
|
148
|
+
setGroup(state, "italic", "3")
|
|
149
|
+
break
|
|
150
|
+
case 23:
|
|
151
|
+
setGroup(state, "italic", null)
|
|
152
|
+
break
|
|
153
|
+
case 4:
|
|
154
|
+
setGroup(state, "underline", "4")
|
|
155
|
+
break
|
|
156
|
+
case 24:
|
|
157
|
+
setGroup(state, "underline", null)
|
|
158
|
+
break
|
|
159
|
+
case 5:
|
|
160
|
+
case 6:
|
|
161
|
+
setGroup(state, "blink", String(n))
|
|
162
|
+
break
|
|
163
|
+
case 25:
|
|
164
|
+
setGroup(state, "blink", null)
|
|
165
|
+
break
|
|
166
|
+
case 7:
|
|
167
|
+
setGroup(state, "inverse", "7")
|
|
168
|
+
break
|
|
169
|
+
case 27:
|
|
170
|
+
setGroup(state, "inverse", null)
|
|
171
|
+
break
|
|
172
|
+
case 8:
|
|
173
|
+
setGroup(state, "conceal", "8")
|
|
174
|
+
break
|
|
175
|
+
case 28:
|
|
176
|
+
setGroup(state, "conceal", null)
|
|
177
|
+
break
|
|
178
|
+
case 9:
|
|
179
|
+
setGroup(state, "strike", "9")
|
|
180
|
+
break
|
|
181
|
+
case 29:
|
|
182
|
+
setGroup(state, "strike", null)
|
|
183
|
+
break
|
|
184
|
+
case 39:
|
|
185
|
+
setGroup(state, "fg", null)
|
|
186
|
+
break
|
|
187
|
+
case 49:
|
|
188
|
+
setGroup(state, "bg", null)
|
|
189
|
+
break
|
|
190
|
+
default:
|
|
191
|
+
if ((n >= 30 && n <= 37) || (n >= 90 && n <= 97)) setGroup(state, "fg", String(n))
|
|
192
|
+
else if ((n >= 40 && n <= 47) || (n >= 100 && n <= 107)) setGroup(state, "bg", String(n))
|
|
193
|
+
else setGroup(state, `raw:${n}`, String(n))
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Pecah satu baris frame menjadi sel kolom. Escape non-SGR diabaikan (frame
|
|
200
|
+
* TUI hanya membawa SGR; sanitizer membuang kontrol lain). Tab diperlakukan
|
|
201
|
+
* selebar 8 kolom — kebijakan yang sama dengan `charWidth`/`displayWidth`.
|
|
202
|
+
*/
|
|
203
|
+
export function parseCells(line: string): Cell[] {
|
|
204
|
+
const cells: Cell[] = []
|
|
205
|
+
const sgr: SgrState = { values: new Map() }
|
|
206
|
+
let style = ""
|
|
207
|
+
let i = 0
|
|
208
|
+
while (i < line.length) {
|
|
209
|
+
if (line[i] === "\x1b") {
|
|
210
|
+
const len = escapeLength(line, i)
|
|
211
|
+
if (len > 0) {
|
|
212
|
+
const seq = line.slice(i, i + len)
|
|
213
|
+
if (isSgr(seq)) {
|
|
214
|
+
applySgrTo(sgr, seq)
|
|
215
|
+
style = serializeSgr(sgr)
|
|
216
|
+
}
|
|
217
|
+
i += len
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
let end = line.indexOf("\x1b", i)
|
|
222
|
+
if (end < 0) end = line.length
|
|
223
|
+
if (end === i) end++
|
|
224
|
+
const run = line.slice(i, end)
|
|
225
|
+
for (const g of segmentGraphemes(run)) {
|
|
226
|
+
// Baris frame tidak boleh memuat newline; kalau ada, itu artefak dan
|
|
227
|
+
// bukan sel yang sah (menuliskannya akan menggeser baris berikut).
|
|
228
|
+
if (g === "\n" || g === "\r" || g === "\x1b") continue
|
|
229
|
+
const width = g === "\t" ? 8 : graphemeWidth(g)
|
|
230
|
+
if (width <= 0) {
|
|
231
|
+
// Grapheme nol-lebar menempel ke sel sebelumnya (mis. combining mark
|
|
232
|
+
// yang lolos tanpa base). Tanpa base, simpan sebagai sel selebar 1
|
|
233
|
+
// supaya posisi kolom berikutnya tidak meleset.
|
|
234
|
+
const prev = cells[cells.length - 1]
|
|
235
|
+
if (prev && !prev.cont) prev.glyph += g
|
|
236
|
+
else cells.push({ glyph: g, style })
|
|
237
|
+
continue
|
|
238
|
+
}
|
|
239
|
+
cells.push({ glyph: g === "\t" ? " ".repeat(8) : g, style })
|
|
240
|
+
for (let k = 1; k < width; k++) cells.push({ glyph: "", style, cont: true })
|
|
241
|
+
}
|
|
242
|
+
i = end
|
|
243
|
+
}
|
|
244
|
+
return cells
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Sel hilang = blank default; terminal memang sudah punya blank di sana. */
|
|
248
|
+
function sameCell(a: Cell | undefined, b: Cell | undefined): boolean {
|
|
249
|
+
if (!a && !b) return true
|
|
250
|
+
if (!a || !b) {
|
|
251
|
+
const only = a ?? b!
|
|
252
|
+
return only.glyph === " " && only.style === "" && !only.cont
|
|
253
|
+
}
|
|
254
|
+
return a.glyph === b.glyph && a.style === b.style && Boolean(a.cont) === Boolean(b.cont)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Tulis ulang EKOR baris `next` mulai kolom `start` (0-based, sudah selaras
|
|
259
|
+
* glyph): CUP ke kolom itu, reset atribut, hapus sisa baris (EL `0K`), lalu
|
|
260
|
+
* render sel dari `start` sampai akhir.
|
|
261
|
+
*
|
|
262
|
+
* Kenapa hapus-lalu-tulis, bukan menulis rentang terpisah per perubahan:
|
|
263
|
+
* terminal (khususnya ConPTY Windows) memegang buffer sendiri. Byte yang tidak
|
|
264
|
+
* kita tulis TIDAK hilang dari layar — sisa glyph lebar, ekor baris lama, atau
|
|
265
|
+
* teks diagnostik asing (`[hooks] …` dari stderr) tetap menempel bila tidak
|
|
266
|
+
* dihapus. Diff per-rentang tanpa EL pernah membiarkan sampah itu bertahan
|
|
267
|
+
* (regresi PTY: baris emoji + prompt tertimpa fragmen asing). Menghapus dari
|
|
268
|
+
* kolom perubahan pertama ke akhir baris menutup celah itu sekaligus tetap
|
|
269
|
+
* melewati prefix yang identik — penghasilan byte fase-2 untuk prompt panjang.
|
|
270
|
+
*/
|
|
271
|
+
function emitTail(next: Cell[], start: number, row: number): string {
|
|
272
|
+
// Reset SEBELUM EL: EL mewarisi atribut aktif (BCE), jadi tanpa reset area
|
|
273
|
+
// terhapus bisa tetap berwarna.
|
|
274
|
+
let out = `\x1b[${row};${start + 1}H\x1b[0m\x1b[0K`
|
|
275
|
+
// Setelah reset, atribut awal = default ("").
|
|
276
|
+
let active = ""
|
|
277
|
+
for (let col = start; col < next.length; col++) {
|
|
278
|
+
const cell = next[col]
|
|
279
|
+
// Kolom lanjutan tidak ditulis: glyph lebar di sel sebelumnya sudah
|
|
280
|
+
// memajukan kursor melewatinya.
|
|
281
|
+
if (cell?.cont) continue
|
|
282
|
+
const glyph = cell?.glyph ?? " "
|
|
283
|
+
const style = cell?.style ?? ""
|
|
284
|
+
if (style !== active) {
|
|
285
|
+
// Reset dulu agar atribut dari run sebelumnya tidak bocor ke sel ini.
|
|
286
|
+
out += style ? `\x1b[0m${style}` : "\x1b[0m"
|
|
287
|
+
active = style
|
|
288
|
+
}
|
|
289
|
+
out += glyph
|
|
290
|
+
}
|
|
291
|
+
return out
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Hasilkan byte yang mengubah baris `prev` menjadi `next`.
|
|
296
|
+
*
|
|
297
|
+
* Prefix identik tidak ditulis (nol byte); dari kolom berbeda pertama sampai
|
|
298
|
+
* akhir baris ditulis ulang setelah EL. `prev`/`next` adalah keluaran
|
|
299
|
+
* `parseCells` untuk baris yang sama; pemanggil wajib menyimpan `prev` dari
|
|
300
|
+
* paint sebelumnya.
|
|
301
|
+
*/
|
|
302
|
+
export function diffCellLine(prev: Cell[], next: Cell[], row: number): string {
|
|
303
|
+
const max = Math.max(prev.length, next.length)
|
|
304
|
+
let start = 0
|
|
305
|
+
while (start < max && sameCell(prev[start], next[start])) start++
|
|
306
|
+
if (start >= max) return ""
|
|
307
|
+
// Jangan mulai di tengah glyph lebar: mundur ke sel pembawa glyph supaya EL
|
|
308
|
+
// tidak membelah glyph (meninggalkan separuh sel kosong di kolom sebelumnya).
|
|
309
|
+
while (start > 0 && (prev[start]?.cont || next[start]?.cont)) start--
|
|
310
|
+
return emitTail(next, start, row)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** True bila dua baris framebuffer identik secara tampilan (test/diagnostik). */
|
|
314
|
+
export function sameCells(a: Cell[], b: Cell[]): boolean {
|
|
315
|
+
if (a.length !== b.length) return false
|
|
316
|
+
for (let i = 0; i < a.length; i++) if (!sameCell(a[i], b[i])) return false
|
|
317
|
+
return true
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export const EMPTY_CELLS: readonly Cell[] = [BLANK]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Wrap composer INKREMENTAL.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa ada: `chunkByWidth` adalah O(panjang baris). Mengetik satu huruf di
|
|
4
|
+
// prompt 5.000 karakter berarti membungkus ulang 5.000 karakter tiap ketukan —
|
|
5
|
+
// biaya itulah yang membuat ketikan panjang terasa berat. Karena composer
|
|
6
|
+
// menambah/menghapus SELALU di ujung baris, wrap greedy (isi tiap baris
|
|
7
|
+
// maksimal) hanya berubah pada baris visual TERAKHIR; baris sebelumnya sudah
|
|
8
|
+
// jenuh dan tak terpengaruh.
|
|
9
|
+
//
|
|
10
|
+
// Kontrak: helper di sini mengembalikan `null` bila pola tak didukung supaya
|
|
11
|
+
// pemanggil jatuh balik ke `chunkByWidth` penuh (jawaban aman, bukan jawaban
|
|
12
|
+
// salah). Teks composer tak memuat SGR (engine membuang byte kontrol), jadi
|
|
13
|
+
// varian tanpa riwayat SGR cukup — SGR apa pun memicu fallback.
|
|
14
|
+
import { displayWidth, segmentGraphemes } from "./width.ts"
|
|
15
|
+
|
|
16
|
+
/** Tabel kelipatan lebar tab, sinkron dengan `chunkByWidth`. */
|
|
17
|
+
const TAB_WIDTH = 8
|
|
18
|
+
|
|
19
|
+
function graphemeColumns(g: string): number {
|
|
20
|
+
if (g === "\t") return TAB_WIDTH
|
|
21
|
+
// Kolom lanjutan grapheme lebar: dihitung per grapheme (bukan per sel).
|
|
22
|
+
return displayWidth(g)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Perluas `rows` (hasil `chunkByWidth` untuk teks sebelumnya) dengan `appended`
|
|
27
|
+
* di UJUNG, mempertahankan wrap greedy. `null` bila tak bisa (baris kosong,
|
|
28
|
+
* lebar ≤ 0, atau ada newline/SGR) — pemanggil membungkus ulang penuh.
|
|
29
|
+
*/
|
|
30
|
+
export function appendWrapped(rows: string[], appended: string, width: number): string[] | null {
|
|
31
|
+
if (!rows.length || width <= 0) return null
|
|
32
|
+
if (appended.includes("\n") || appended.includes("\r") || appended.includes("\x1b")) return null
|
|
33
|
+
const out = rows.slice(0, -1)
|
|
34
|
+
let buf = rows[rows.length - 1]!
|
|
35
|
+
for (const g of segmentGraphemes(appended)) {
|
|
36
|
+
const gw = graphemeColumns(g)
|
|
37
|
+
if (gw <= 0) {
|
|
38
|
+
// Grapheme nol-lebar menempel ke buf tanpa menghabiskan kolom.
|
|
39
|
+
buf += g
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
if (displayWidth(buf) + gw > width && buf !== "") {
|
|
43
|
+
out.push(buf)
|
|
44
|
+
buf = ""
|
|
45
|
+
}
|
|
46
|
+
buf += g
|
|
47
|
+
}
|
|
48
|
+
out.push(buf)
|
|
49
|
+
return out
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Buang `removed` (UTF-16, harus menjadi AKHIR baris visual terakhir) dari
|
|
54
|
+
* `rows`. `null` bila baris terakhir tak diakhiri `removed` (mis. batas
|
|
55
|
+
* grapheme berbeda) — pemanggil membungkus ulang penuh.
|
|
56
|
+
*/
|
|
57
|
+
export function shaveWrapped(rows: string[], removed: string, width: number): string[] | null {
|
|
58
|
+
if (!rows.length || width <= 0 || !removed) return null
|
|
59
|
+
if (removed.includes("\x1b")) return null
|
|
60
|
+
const last = rows[rows.length - 1]!
|
|
61
|
+
if (!last.endsWith(removed)) return null
|
|
62
|
+
const trimmed = last.slice(0, last.length - removed.length)
|
|
63
|
+
if (trimmed === "") {
|
|
64
|
+
// Baris terakhir habis. Baris sebelumnya jenuh, jadi cukup pop — tapi bila
|
|
65
|
+
// ini satu-satunya baris, serahkan ke pemanggil (prefix prompt bisa hilang
|
|
66
|
+
// saat baris jadi kosong dan special-case `!line` yang menanganinya).
|
|
67
|
+
if (rows.length === 1) return null
|
|
68
|
+
return rows.slice(0, -1)
|
|
69
|
+
}
|
|
70
|
+
const out = rows.slice(0, -1)
|
|
71
|
+
out.push(trimmed)
|
|
72
|
+
return out
|
|
73
|
+
}
|
package/src/ui/render/detail.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Satu sumber state "level detail tool call": expanded vs compact.
|
|
2
2
|
//
|
|
3
3
|
// Posisi Minicode = agentic Unix shell: tool call transparan di aliran output.
|
|
4
|
-
// Default tergantung konteks: one-shot/exec = expanded;
|
|
5
|
-
// mengaktifkan compact saat start (
|
|
4
|
+
// Default tergantung konteks: one-shot/exec = expanded; TUI interaktif
|
|
5
|
+
// mengaktifkan compact saat start (`cli/tui.ts`) kecuali env diset eksplisit.
|
|
6
6
|
// `MINICODE_COMPACT=1`/`0` atau `/compact` selalu menang.
|
|
7
7
|
//
|
|
8
8
|
// [F-ENV-1] State module-local di-bootstrap SATU KALI dari env saat import; setter
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Satu sumber marker/status/warna untuk baris ledger tool — dipakai TUI
|
|
2
|
+
// (transcript.ts) dan printer linier (simple.ts) supaya glyph, kata status,
|
|
3
|
+
// warna, dan label run sub-agent tidak divergen. Sebelumnya logika ini
|
|
4
|
+
// diduplikasi di kedua berkas (dan mudah drift — kelas OAP-001).
|
|
5
|
+
//
|
|
6
|
+
// Murni & tanpa IO: hanya memetakan status → kata/glyph/warna; sanitasi dan
|
|
7
|
+
// pemotongan lebar tetap di sisi pemanggil.
|
|
8
|
+
import type { UiToolStatus } from "../contract.ts"
|
|
9
|
+
import { t } from "../i18n/locale.ts"
|
|
10
|
+
import { c, glyphs } from "./theme.ts"
|
|
11
|
+
|
|
12
|
+
/** Kata status lokal ("completed"/"failed"/dst.) — fallback non-warna. */
|
|
13
|
+
export function statusWord(status: UiToolStatus): string {
|
|
14
|
+
if (status === "completed") return t("ts.statusCompleted")
|
|
15
|
+
if (status === "failed") return t("ts.statusFailed")
|
|
16
|
+
if (status === "denied") return t("ts.statusDenied")
|
|
17
|
+
if (status === "cancelled") return t("ts.statusCancelled")
|
|
18
|
+
if (status === "interrupted") return t("ts.statusInterrupted")
|
|
19
|
+
return t("ts.statusRunning")
|
|
20
|
+
}
|
|
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
|
+
/** Warna baris ledger berdasar status terminal (sukses/error/denied/lain). */
|
|
31
|
+
export function paintLedger(status: UiToolStatus, line: string): string {
|
|
32
|
+
if (status === "failed") return c.error(line)
|
|
33
|
+
if (status === "denied") return c.warning(line)
|
|
34
|
+
if (status === "completed") return c.success(line)
|
|
35
|
+
return c.muted(line)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Label run pendek stabil (`run_<8>` | `sub_<8>`) untuk identitas sub-agent. */
|
|
39
|
+
export function runMarker(
|
|
40
|
+
activity: { runId?: string; childSessionId?: string } | undefined,
|
|
41
|
+
): string {
|
|
42
|
+
const id = activity?.runId ?? activity?.childSessionId
|
|
43
|
+
if (!id) return ""
|
|
44
|
+
const prefix = id.startsWith("run_") ? "run_" : id.startsWith("sub_") ? "sub_" : ""
|
|
45
|
+
const bare = id.slice(prefix.length).replace(/-/g, "")
|
|
46
|
+
return prefix + bare.slice(0, 8)
|
|
47
|
+
}
|
package/src/ui/render/theme.ts
CHANGED
|
@@ -31,6 +31,11 @@ export function supportsUtf8(): boolean {
|
|
|
31
31
|
// Dievaluasi LAZY (bukan saat import) supaya perubahan NO_COLOR/COLORTERM di
|
|
32
32
|
// runtime dan pengujian tetap berpengaruh; hasilnya murah karena hanya baca env.
|
|
33
33
|
function noColorEnv(): boolean {
|
|
34
|
+
// NO_COLOR="0" SENGAJA dianggap "warna nyala" (kill-switch terbalik) — berbeda
|
|
35
|
+
// dari no-color.org yang menyatakan kehadiran apa pun = mati. Keputusan product:
|
|
36
|
+
// "0" adalah nilai eksplisit "jangan matikan" yang dipakai sebagian tooling;
|
|
37
|
+
// nilai lain (termasuk kosong) mematikan warna. Didokumentasikan juga di
|
|
38
|
+
// docs/environment.md. Jangan "perbaiki" jadi === null tanpa keputusan owner.
|
|
34
39
|
return process.env.NO_COLOR != null && process.env.NO_COLOR !== "0"
|
|
35
40
|
}
|
|
36
41
|
function hasTruecolorEnv(): boolean {
|
|
@@ -48,6 +53,18 @@ function colorLevel(): number {
|
|
|
48
53
|
return 1
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Kunci kapabilitas tampilan (level warna + glyph UTF-8) untuk cache render.
|
|
58
|
+
*
|
|
59
|
+
* Dievaluasi LAZY tiap panggilan: NO_COLOR/TERM/COLORTERM dan deteksi UTF-8
|
|
60
|
+
* bisa berubah di runtime (dan antar test). Konsumen yang meng-cache string
|
|
61
|
+
* berwarna WAJIB menyertakan kunci ini; tanpa itu output mono bisa tersaji ke
|
|
62
|
+
* terminal berwarna (atau sebaliknya) setelah env berubah.
|
|
63
|
+
*/
|
|
64
|
+
export function themeCapabilityKey(): string {
|
|
65
|
+
return `${colorLevel()}:${hasTruecolorEnv() ? 1 : 0}:${supportsUtf8() ? 1 : 0}`
|
|
66
|
+
}
|
|
67
|
+
|
|
51
68
|
type Paint = (s: string) => string
|
|
52
69
|
const identity: Paint = (s) => s
|
|
53
70
|
|
|
@@ -292,17 +309,20 @@ export const c = {
|
|
|
292
309
|
// `cli/commands.ts` pernah membekukannya (V8) sehingga fallback ASCII tidak
|
|
293
310
|
// pernah aktif. Dijaga oleh `test/no-frozen-runtime-value.test.ts`.
|
|
294
311
|
export const glyphs = {
|
|
312
|
+
// A2 — status disampaikan lewat WARNA + kata, bukan glyph. Ikon sukses/gagal/
|
|
313
|
+
// ditolak/dibatalkan (✓/✗/⊘/○) dihapus karena bising & tak konsisten antar
|
|
314
|
+
// terminal; getter tetap "" agar semua pemanggil tak perlu diubah satu-satu.
|
|
295
315
|
get check() {
|
|
296
|
-
return
|
|
316
|
+
return ""
|
|
297
317
|
},
|
|
298
318
|
get cross() {
|
|
299
|
-
return
|
|
319
|
+
return ""
|
|
300
320
|
},
|
|
301
321
|
get denied() {
|
|
302
|
-
return
|
|
322
|
+
return ""
|
|
303
323
|
},
|
|
304
324
|
get circle() {
|
|
305
|
-
return
|
|
325
|
+
return ""
|
|
306
326
|
},
|
|
307
327
|
get arrow() {
|
|
308
328
|
return supportsUtf8() ? "›" : ">"
|
|
@@ -331,6 +351,14 @@ export const glyphs = {
|
|
|
331
351
|
// Fallback * untuk terminal tanpa UTF-8.
|
|
332
352
|
return supportsUtf8() ? "✦" : "*"
|
|
333
353
|
},
|
|
354
|
+
// Gembok bash allow-list (footer): fallback teks agar status kapabilitas
|
|
355
|
+
// tetap terbaca di terminal tanpa emoji (MINICODE_ASCII/legacy Windows).
|
|
356
|
+
get lock() {
|
|
357
|
+
return supportsUtf8() ? "🔒" : "[LOCK]"
|
|
358
|
+
},
|
|
359
|
+
get unlock() {
|
|
360
|
+
return supportsUtf8() ? "🔓" : "[OPEN]"
|
|
361
|
+
},
|
|
334
362
|
}
|
|
335
363
|
|
|
336
364
|
// ── Section separator ──
|
package/src/ui/render/width.ts
CHANGED
|
@@ -63,7 +63,7 @@ const EMOJI_PRESENTATION = /\p{Emoji_Presentation}/u
|
|
|
63
63
|
const EXTENDED_PICTOGRAPHIC = /\p{Extended_Pictographic}/u
|
|
64
64
|
let widthSegmenter: Intl.Segmenter | undefined
|
|
65
65
|
|
|
66
|
-
function segmentGraphemes(text: string): string[] {
|
|
66
|
+
export function segmentGraphemes(text: string): string[] {
|
|
67
67
|
try {
|
|
68
68
|
widthSegmenter ??= new Intl.Segmenter("und", { granularity: "grapheme" })
|
|
69
69
|
return Array.from(widthSegmenter.segment(text), (part) => part.segment)
|
|
@@ -74,7 +74,7 @@ function segmentGraphemes(text: string): string[] {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
function graphemeWidth(grapheme: string): number {
|
|
77
|
+
export function graphemeWidth(grapheme: string): number {
|
|
78
78
|
const points = Array.from(grapheme, (part) => part.codePointAt(0)!)
|
|
79
79
|
const has = (from: number, to: number): boolean => points.some((cp) => cp >= from && cp <= to)
|
|
80
80
|
const containsEmoji = points.some((cp) => EMOJI.test(String.fromCodePoint(cp)))
|
package/src/ui/render/wrap.ts
CHANGED
|
@@ -99,10 +99,12 @@ export function justifyLine(line: string, width: number): string {
|
|
|
99
99
|
//
|
|
100
100
|
// Baris TERAKHIR paragraf tidak dijustify — menjustifikasinya menghasilkan
|
|
101
101
|
// "sungai" spasi seperti `dengan lebar tertentu`, kesalahan tipografi
|
|
102
|
-
// klasik.
|
|
103
|
-
|
|
102
|
+
// klasik. Justify kini OPT-IN (default OFF, temuan K.2): menjustifikasi
|
|
103
|
+
// menyuntik spasi yang mengubah teks asli model saat di-copy/–pipe, dan membuat
|
|
104
|
+
// output linear berbeda dari TUI (ragged). `MINICODE_JUSTIFY=1` mengaktifkan.
|
|
105
|
+
export function formatWrapped(text: string, width: number, justify = false): string {
|
|
104
106
|
const wrapped = wordWrap(text, width)
|
|
105
|
-
if (!justify || process.env.MINICODE_JUSTIFY === "
|
|
107
|
+
if (!(justify || process.env.MINICODE_JUSTIFY === "1")) return wrapped
|
|
106
108
|
const lines = wrapped.split("\n")
|
|
107
109
|
return lines
|
|
108
110
|
.map((line, i) => {
|