minicode-ai 0.14.6 → 0.15.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/cli/args.ts +20 -8
- package/cli/commands/exec.ts +14 -12
- package/cli/commands.ts +33 -17
- package/cli/index.ts +25 -3
- package/cli/router.ts +22 -9
- package/cli/setup.ts +20 -5
- package/cli/tui.ts +73 -14
- package/docs/CONTROL-PLANE-MAP.md +1 -1
- package/docs/SUMMARY.md +1 -1
- package/docs/TERMINAL_CONTRACT.md +37 -12
- package/docs/architecture.md +1 -0
- package/docs/choosing-mode.md +3 -1
- package/docs/cli.md +7 -5
- package/docs/config.md +1 -1
- package/docs/environment.md +3 -1
- package/docs/getting-started.md +1 -1
- package/docs/memory-sessions.md +2 -2
- package/docs/repl.md +6 -3
- package/docs/security-model.md +3 -1
- package/package.json +1 -1
- package/scripts/vendor-overlays/minicode-context.patch +1 -1
- package/src/app/mentions.ts +1 -1
- package/src/app/rag-layer.ts +11 -2
- package/src/app/session.ts +92 -7
- package/src/constants.ts +1 -1
- package/src/daemon/client.ts +11 -6
- package/src/daemon/control.ts +2 -9
- package/src/daemon/resource.ts +5 -4
- package/src/lib/keystore.ts +11 -9
- package/src/lib/net.ts +8 -3
- package/src/lib/safe-open.ts +29 -5
- package/src/lib/trusted-exec.ts +4 -1
- package/src/lsp/client.ts +9 -10
- package/src/mcp/server.ts +17 -7
- package/src/memory/files.ts +2 -1
- package/src/memory/vector.ts +25 -16
- package/src/policy/bash-guard.ts +33 -11
- package/src/policy/bpe.ts +110 -0
- package/src/policy/compaction.ts +33 -6
- package/src/policy/context-window.ts +19 -0
- package/src/policy/context.ts +34 -8
- package/src/policy/jail.ts +48 -3
- package/src/policy/no-progress.ts +15 -8
- package/src/policy/permission.ts +24 -1
- package/src/policy/tokenizer-registry.ts +104 -0
- package/src/policy/usage.ts +20 -13
- package/src/policy/verifier.ts +7 -4
- package/src/policy/work-mode.ts +9 -5
- package/src/presentation/adapter.ts +7 -3
- package/src/presentation/projection.ts +10 -2
- package/src/providers/anthropic.ts +13 -3
- package/src/providers/responses.ts +16 -6
- package/src/runtime/capability.ts +22 -4
- package/src/runtime/execution-journal.ts +13 -7
- package/src/runtime/production-execution.ts +4 -3
- package/src/sandbox/os.ts +4 -3
- package/src/session/checkpoint.ts +29 -4
- package/src/session/persistence.ts +21 -10
- package/src/task/autonomous-context.ts +0 -1
- package/src/task/scheduler-observability.ts +1 -0
- package/src/tools/git.ts +22 -4
- package/src/tools/lsp.ts +10 -8
- package/src/tools/web_fetch.ts +6 -2
- package/src/tools/web_search.ts +2 -1
- package/src/ui/assistant/simple.ts +9 -3
- package/src/ui/contract.ts +4 -0
- package/src/ui/footer.ts +18 -6
- package/src/ui/i18n/en.ts +13 -2
- package/src/ui/i18n/id.ts +13 -2
- package/src/ui/render/diff.ts +14 -5
- package/src/ui/render/highlight.ts +4 -4
- package/src/ui/render/markdown.ts +12 -5
- package/src/ui/render/session-summary.ts +50 -0
- package/src/ui/render/table-grid.ts +134 -6
- package/src/ui/render/theme.ts +17 -0
- package/src/ui/render/width.ts +89 -2
- package/src/ui/runtime/screen.ts +16 -15
- package/src/ui/session-state.ts +27 -1
- package/src/ui/tui/transcript.ts +90 -18
- package/vendor/minicore/VENDOR.md +3 -3
- package/vendor/minicore/src/core/loop.ts +1 -1
|
@@ -129,17 +129,24 @@ export function decorateMarkdown(text: string): string {
|
|
|
129
129
|
// Headings (# ## ###) -> bold with vertical spacing
|
|
130
130
|
if (/^#{1,3}\s/.test(line)) {
|
|
131
131
|
if (out.length > 0 && out[out.length - 1] !== "") out.push("")
|
|
132
|
-
|
|
132
|
+
// Margin kiri 1 kolom — jangan menempel ke tepi terminal.
|
|
133
|
+
out.push(` ${c.bold(line)}`)
|
|
133
134
|
continue
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
// Daftar (bullet `-`/`*`/`+` atau bernomor `1.`/`2)`) — indentasi BERSARANG
|
|
138
|
+
// mengikuti lekukan sumber, bukan diratakan jadi satu level. Marker
|
|
139
|
+
// dipertahankan; isi didekorasi inline (bold/italic/code tetap jalan).
|
|
140
|
+
const listItem = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(line)
|
|
141
|
+
if (listItem) {
|
|
142
|
+
const depth = Math.min(8, Math.floor((listItem[1]!.length + 1) / 2))
|
|
143
|
+
const indent = " ".repeat(depth + 1)
|
|
144
|
+
out.push(`${indent}${listItem[2]} ${renderInline(listItem[3] ?? "")}`)
|
|
139
145
|
continue
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
// Margin kiri 1 kolom untuk paragraf (tidak menempel ke tepi terminal).
|
|
149
|
+
out.push(` ${renderInline(line)}`)
|
|
143
150
|
}
|
|
144
151
|
return out.join("\n")
|
|
145
152
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Kop ringkasan sesi — ditampilkan saat interactive exit (/exit atau Ctrl+D).
|
|
2
|
+
//
|
|
3
|
+
// Memakai wordmark teks "minicode" sebagai pengganti mark block-art: teks tetap
|
|
4
|
+
// rapi & legible di ukuran kecil, tidak hancur seperti block-element yang
|
|
5
|
+
// didownscale. Detail sesi di baris berikutnya, rata kiri.
|
|
6
|
+
//
|
|
7
|
+
// Wordmark tanpa warna custom: gradien truecolor (cyan→magenta) tidak didukung
|
|
8
|
+
// merata di semua terminal dan pernah membuat "minicode" tak tampil. Bold polos
|
|
9
|
+
// via `c` menjamin selalu terlihat + hormati NO_COLOR.
|
|
10
|
+
|
|
11
|
+
import { formatUsd } from "./money.ts"
|
|
12
|
+
import { c } from "./theme.ts"
|
|
13
|
+
|
|
14
|
+
const WORDMARK = "minicode"
|
|
15
|
+
|
|
16
|
+
/** "minicode" bold — selalu terlihat, hormat NO_COLOR/non-TTY. */
|
|
17
|
+
function paintWordmark(): string {
|
|
18
|
+
return c.bold(WORDMARK)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SessionSummary {
|
|
22
|
+
sessionId: string
|
|
23
|
+
model: string
|
|
24
|
+
totalTokens: number
|
|
25
|
+
cost?: number
|
|
26
|
+
durationMs: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** "3m 12s" / "1m 5s" / "45s" untuk durasi manusia. */
|
|
30
|
+
export function formatDuration(ms: number): string {
|
|
31
|
+
const total = Math.max(0, Math.round(ms / 1000))
|
|
32
|
+
if (total >= 60) return `${Math.floor(total / 60)}m ${total % 60}s`
|
|
33
|
+
return `${total}s`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render kop: wordmark + detail sesi (baris demi baris). */
|
|
37
|
+
export function renderSessionSummary(s: SessionSummary): string {
|
|
38
|
+
const label = (t: string): string => c.muted(t.padEnd(7))
|
|
39
|
+
const cost = s.cost != null ? formatUsd(s.cost) : null
|
|
40
|
+
return `${[
|
|
41
|
+
paintWordmark(),
|
|
42
|
+
`${label("Session")} ${c.gray(s.sessionId)}`,
|
|
43
|
+
`${label("Model")} ${c.gray(s.model)}`,
|
|
44
|
+
`${label("Usage")} ${s.totalTokens.toLocaleString()} tokens${
|
|
45
|
+
cost != null ? ` · ${cost}` : ""
|
|
46
|
+
} · ${formatDuration(s.durationMs)}`,
|
|
47
|
+
]
|
|
48
|
+
.join("\r\n")
|
|
49
|
+
.concat("\r\n")}`
|
|
50
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MarkdownTable, PipeTableAlignment } from "./markdown-table.ts"
|
|
2
2
|
import { cleanUntrusted, sanitizeAnsiLine } from "./sanitize.ts"
|
|
3
|
-
import { c, getTerminalWidth } from "./theme.ts"
|
|
4
|
-
import { displayWidth, padToWidth, truncateToWidth } from "./width.ts"
|
|
3
|
+
import { c, getTerminalWidth, supportsUtf8 } from "./theme.ts"
|
|
4
|
+
import { displayWidth, padToWidth, truncateToWidth, wrapByWidth } from "./width.ts"
|
|
5
5
|
|
|
6
6
|
export interface GridColumn {
|
|
7
7
|
header: string
|
|
@@ -23,11 +23,18 @@ export interface GridRenderOptions {
|
|
|
23
23
|
minCellWidth?: number
|
|
24
24
|
styleHeader?: boolean
|
|
25
25
|
formatCell?: (value: string) => string
|
|
26
|
+
/** Wrap isi sel ke baris berikutnya (untuk tabel markdown jawaban model)
|
|
27
|
+
* alih-alih truncate dengan ellipsis — info panjang TIDAK hilang. */
|
|
28
|
+
wrap?: boolean
|
|
29
|
+
/** Render sebagai kotak ber-garis (opencode-like) dengan padding dalam sel. */
|
|
30
|
+
box?: boolean
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
const DEFAULT_ELLIPSIS = "…"
|
|
29
34
|
const DEFAULT_MAX_CELL_WIDTH = 50
|
|
30
35
|
const MIN_CONTENT_WIDTH = 3
|
|
36
|
+
/** Margin kiri kotak tabel — biar tidak menempel ke tepi terminal. */
|
|
37
|
+
const BOX_MARGIN = 1
|
|
31
38
|
|
|
32
39
|
function cleanCell(value: unknown): string {
|
|
33
40
|
return cleanUntrusted(
|
|
@@ -113,6 +120,78 @@ function fitWidths(natural: readonly number[], budget: number, minimum: number):
|
|
|
113
120
|
return widths
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Render tabel sebagai kotak ber-garis (opencode-like) dengan padding 1 kolom
|
|
125
|
+
* di dalam tiap sel — teks tidak menempel ke garis `│`. Isi sel di-wrap
|
|
126
|
+
* (bukan truncate) agar info panjang tidak hilang; ANSI terjaga via
|
|
127
|
+
* chunkByWidth. Fallback ASCII (`+`,`-`,`|`) saat MINICODE_ASCII/terminal non-UTF.
|
|
128
|
+
*/
|
|
129
|
+
function renderBorderedGrid(
|
|
130
|
+
table: GridTable,
|
|
131
|
+
widths: number[],
|
|
132
|
+
aligns: readonly PipeTableAlignment[],
|
|
133
|
+
styleHeader: boolean,
|
|
134
|
+
options: GridRenderOptions,
|
|
135
|
+
): string {
|
|
136
|
+
const g = supportsUtf8()
|
|
137
|
+
? {
|
|
138
|
+
tl: "┌",
|
|
139
|
+
tm: "┬",
|
|
140
|
+
tr: "┐",
|
|
141
|
+
ml: "├",
|
|
142
|
+
mm: "┼",
|
|
143
|
+
mr: "┤",
|
|
144
|
+
bl: "└",
|
|
145
|
+
bm: "┴",
|
|
146
|
+
br: "┘",
|
|
147
|
+
h: "─",
|
|
148
|
+
v: "│",
|
|
149
|
+
}
|
|
150
|
+
: {
|
|
151
|
+
tl: "+",
|
|
152
|
+
tm: "+",
|
|
153
|
+
tr: "+",
|
|
154
|
+
ml: "+",
|
|
155
|
+
mm: "+",
|
|
156
|
+
mr: "+",
|
|
157
|
+
bl: "+",
|
|
158
|
+
bm: "+",
|
|
159
|
+
br: "+",
|
|
160
|
+
h: "-",
|
|
161
|
+
v: "|",
|
|
162
|
+
}
|
|
163
|
+
const cellLines = (value: unknown, col: number): string[] => {
|
|
164
|
+
const colWidth = widths[col]!
|
|
165
|
+
const align = aligns[col] ?? "left"
|
|
166
|
+
const raw = cleanCell(value)
|
|
167
|
+
const rendered = options.formatCell?.(raw) ?? raw
|
|
168
|
+
return wrapByWidth(rendered, colWidth).map((l) => alignCell(l, colWidth, align))
|
|
169
|
+
}
|
|
170
|
+
const headerCols = table.headers.map((v, i) => {
|
|
171
|
+
const rendered = options.formatCell?.(cleanCell(v)) ?? cleanCell(v)
|
|
172
|
+
const styled = styleHeader ? c.bold(c.accent(rendered)) : rendered
|
|
173
|
+
return wrapByWidth(styled, widths[i]!).map((l) => alignCell(l, widths[i]!, aligns[i] ?? "left"))
|
|
174
|
+
})
|
|
175
|
+
const rowLine = (cols: string[][], li: number): string =>
|
|
176
|
+
c.dim(g.v) +
|
|
177
|
+
cols.map((lines, i) => ` ${lines[li] ?? padToWidth("", widths[i]!)} `).join(c.dim(g.v)) +
|
|
178
|
+
c.dim(g.v)
|
|
179
|
+
const horiz = (l: string, m: string, r: string): string =>
|
|
180
|
+
c.dim(l + widths.map((w) => g.h.repeat(w + 2)).join(m) + r)
|
|
181
|
+
|
|
182
|
+
const out: string[] = [horiz(g.tl, g.tm, g.tr)]
|
|
183
|
+
const headerHeight = headerCols.reduce((m, lines) => Math.max(m, lines.length), 1)
|
|
184
|
+
for (let li = 0; li < headerHeight; li++) out.push(rowLine(headerCols, li))
|
|
185
|
+
out.push(horiz(g.ml, g.mm, g.mr))
|
|
186
|
+
for (const row of table.rows) {
|
|
187
|
+
const cols = row.map((_, i) => cellLines(row[i] ?? "", i))
|
|
188
|
+
const height = cols.reduce((m, lines) => Math.max(m, lines.length), 0)
|
|
189
|
+
for (let li = 0; li < height; li++) out.push(rowLine(cols, li))
|
|
190
|
+
}
|
|
191
|
+
out.push(horiz(g.bl, g.bm, g.br))
|
|
192
|
+
return out.map((line) => " ".repeat(BOX_MARGIN) + line).join("\n")
|
|
193
|
+
}
|
|
194
|
+
|
|
116
195
|
export function renderGridTable(table: GridTable, options: GridRenderOptions = {}): string {
|
|
117
196
|
if (table.headers.length === 0) return ""
|
|
118
197
|
if (table.rows.length === 0 && options.styleHeader === false) return ""
|
|
@@ -129,7 +208,12 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
|
|
|
129
208
|
const minCellWidth = Number.isFinite(requestedMinCellWidth)
|
|
130
209
|
? Math.max(1, Math.trunc(requestedMinCellWidth))
|
|
131
210
|
: MIN_CONTENT_WIDTH
|
|
132
|
-
|
|
211
|
+
// Overhead batas: format kotak `│ c │` memakan 2 kolom lebih banyak per baris
|
|
212
|
+
// (baris batas `│` + padding) daripada format separator lama ` c ` + spasi.
|
|
213
|
+
// `BOX_MARGIN` = margin kiri agar kotak tidak nempel ke tepi terminal.
|
|
214
|
+
const overhead = options.box
|
|
215
|
+
? table.headers.length * 3 + 1 + BOX_MARGIN
|
|
216
|
+
: table.headers.length * 3 - 1
|
|
133
217
|
const budget = width - overhead
|
|
134
218
|
const natural = naturalWidths(table, maxCellWidth)
|
|
135
219
|
const minimum = Math.max(1, Math.min(minCellWidth, ...natural.map((value) => Math.max(1, value))))
|
|
@@ -140,6 +224,51 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
|
|
|
140
224
|
if (!widths) return renderVertical(table, width, ellipsis).join("\n")
|
|
141
225
|
|
|
142
226
|
const aligns = table.aligns ?? table.headers.map(() => "left" as const)
|
|
227
|
+
const styleHeader = options.styleHeader !== false
|
|
228
|
+
|
|
229
|
+
if (options.box) return renderBorderedGrid(table, widths, aligns, styleHeader, options)
|
|
230
|
+
|
|
231
|
+
const separator = c.dim(widths.map((value) => "─".repeat(value + 2)).join(" "))
|
|
232
|
+
|
|
233
|
+
if (options.wrap) {
|
|
234
|
+
// Wrap isi sel di batas kolom (BUKAN truncate) agar info panjang tidak hilang
|
|
235
|
+
// — dilanjutkan ke baris berikutnya dalam sel. ANSI terjaga via chunkByWidth
|
|
236
|
+
// (mengembalikan SGR yang terbuka ke potongan berikutnya).
|
|
237
|
+
const cellWrapped = (value: unknown, column: number): string[] => {
|
|
238
|
+
const colWidth = widths[column]!
|
|
239
|
+
const align = aligns[column] ?? "left"
|
|
240
|
+
const raw = cleanCell(value)
|
|
241
|
+
const rendered = options.formatCell?.(raw) ?? raw
|
|
242
|
+
return wrapByWidth(rendered, colWidth).map((l) => alignCell(l, colWidth, align))
|
|
243
|
+
}
|
|
244
|
+
// Header bergaya bold+accent DITERAPKAN SEBELUM wrap agar baris lanjutan tetap
|
|
245
|
+
// bergaya; header jarang wrap tapi tetap ditangani.
|
|
246
|
+
const headerCols = table.headers.map((value, i) => {
|
|
247
|
+
const colWidth = widths[i]!
|
|
248
|
+
const align = aligns[i] ?? "left"
|
|
249
|
+
const raw = cleanCell(value)
|
|
250
|
+
const rendered = options.formatCell?.(raw) ?? raw
|
|
251
|
+
const styled = styleHeader ? c.bold(c.accent(rendered)) : rendered
|
|
252
|
+
return wrapByWidth(styled, colWidth).map((l) => alignCell(l, colWidth, align))
|
|
253
|
+
})
|
|
254
|
+
const lineOf = (cols: string[][], li: number): string =>
|
|
255
|
+
cols.map((lines, ci) => ` ${lines[li] ?? padToWidth("", widths[ci]!)} `).join(" ")
|
|
256
|
+
|
|
257
|
+
const headerHeight = headerCols.reduce((m, lines) => Math.max(m, lines.length), 1)
|
|
258
|
+
const headerLines: string[] = []
|
|
259
|
+
for (let li = 0; li < headerHeight; li++) headerLines.push(lineOf(headerCols, li))
|
|
260
|
+
|
|
261
|
+
const bodyLines: string[] = []
|
|
262
|
+
for (const row of table.rows) {
|
|
263
|
+
const cols = row.map((_, i) => cellWrapped(row[i] ?? "", i))
|
|
264
|
+
const height = cols.reduce((m, lines) => Math.max(m, lines.length), 0)
|
|
265
|
+
for (let li = 0; li < height; li++) bodyLines.push(lineOf(cols, li))
|
|
266
|
+
}
|
|
267
|
+
return [separator, ...headerLines, ...bodyLines].join("\n")
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Mode default (tabel UI: config/sessions/skills): kolom lebar-tetap, nilai
|
|
271
|
+
// kepanjangan dipotong dengan ellipsis — kolom TIDAK melebar / multi-baris.
|
|
143
272
|
const cell = (value: unknown, column: number): string => {
|
|
144
273
|
const colWidth = widths[column]!
|
|
145
274
|
const align = aligns[column] ?? "left"
|
|
@@ -149,10 +278,9 @@ export function renderGridTable(table: GridTable, options: GridRenderOptions = {
|
|
|
149
278
|
}
|
|
150
279
|
const header = table.headers.map((value, i) => {
|
|
151
280
|
const rendered = cell(value, i)
|
|
152
|
-
return
|
|
281
|
+
return styleHeader ? ` ${c.bold(c.accent(rendered))} ` : ` ${rendered} `
|
|
153
282
|
})
|
|
154
283
|
const rows = table.rows.map((row) => table.headers.map((_, i) => ` ${cell(row[i] ?? "", i)} `))
|
|
155
|
-
const separator = c.dim(widths.map((value) => "─".repeat(value + 2)).join(" "))
|
|
156
284
|
return [separator, header.join(" "), ...rows.map((row) => row.join(" "))].join("\n")
|
|
157
285
|
}
|
|
158
286
|
|
|
@@ -170,7 +298,7 @@ export function renderMarkdownTable(
|
|
|
170
298
|
rows: table.rows,
|
|
171
299
|
aligns: table.aligns,
|
|
172
300
|
},
|
|
173
|
-
{ width, styleHeader: true, formatCell },
|
|
301
|
+
{ width, styleHeader: true, formatCell, box: true },
|
|
174
302
|
)
|
|
175
303
|
}
|
|
176
304
|
|
package/src/ui/render/theme.ts
CHANGED
|
@@ -76,6 +76,13 @@ const TOKENS = {
|
|
|
76
76
|
warning: "38;2;204;167;0",
|
|
77
77
|
info: "38;2;117;190;255",
|
|
78
78
|
accent: "38;2;0;122;204",
|
|
79
|
+
// String literal kode (VS Code Dark+ `string` #CE9178) — sengaja terpisah dari
|
|
80
|
+
// `success` (green): string harus tampak jingga-salm ala VS Code, sementara
|
|
81
|
+
// status sukses tetap hijau. Alias lama `green` tetap menyasar success.
|
|
82
|
+
string: "38;2;206;145;120",
|
|
83
|
+
// Thinking/reasoning: abu-kebiruan yang tetap terbaca nyaman (bukan `dim` yang
|
|
84
|
+
// meredupkan seluruh teks) — jelas sekunder dari jawaban model tapi tak silau.
|
|
85
|
+
thinking: "38;2;135;146;160",
|
|
79
86
|
// Faint: abu gelap untuk garis footer — lebih redup dari `gray` (bright-black)
|
|
80
87
|
// dan dari `muted` (dim). Dipakai elemen yang harus ada tapi hampir tak
|
|
81
88
|
// terlihat, seperti separator baris dasar.
|
|
@@ -110,6 +117,8 @@ interface Palette {
|
|
|
110
117
|
brightYellow: Paint
|
|
111
118
|
brightMagenta: Paint
|
|
112
119
|
brightCyan: Paint
|
|
120
|
+
string: Paint
|
|
121
|
+
thinking: Paint
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
const paletteCache = new Map<string, Palette>()
|
|
@@ -146,6 +155,8 @@ function buildPalette(): Palette {
|
|
|
146
155
|
brightYellow: mono ? identity : truecolor ? wrap("38;2;215;186;125", 39) : wrap(93, 39),
|
|
147
156
|
brightMagenta: mono ? identity : truecolor ? wrap("38;2;197;134;192", 39) : wrap(95, 39),
|
|
148
157
|
brightCyan: mono ? identity : truecolor ? wrap("38;2;78;201;176", 39) : wrap(96, 39),
|
|
158
|
+
string: paintFrom(TOKENS.string),
|
|
159
|
+
thinking: paintFrom(TOKENS.thinking),
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
|
|
@@ -265,6 +276,12 @@ export const c = {
|
|
|
265
276
|
get brightCyan() {
|
|
266
277
|
return palette().brightCyan
|
|
267
278
|
},
|
|
279
|
+
get string() {
|
|
280
|
+
return palette().string
|
|
281
|
+
},
|
|
282
|
+
get thinking() {
|
|
283
|
+
return palette().thinking
|
|
284
|
+
},
|
|
268
285
|
}
|
|
269
286
|
|
|
270
287
|
// ── Glyphs - minimal, Ubuntu Server style ──
|
package/src/ui/render/width.ts
CHANGED
|
@@ -243,8 +243,8 @@ export function escapeLength(s: string, i: number): number {
|
|
|
243
243
|
if (st !== -1) return st - i + 2
|
|
244
244
|
return s.length - i
|
|
245
245
|
}
|
|
246
|
-
// ESC ( B, ESC ) 0, ESC # 8 — charset & DEC line size, 3 byte.
|
|
247
|
-
if (next === "(" || next === ")" || next === "#") return 3
|
|
246
|
+
// ESC ( B, ESC ) 0, ESC # 8 — charset & DEC line size, 3 byte (dibatasi sisa string).
|
|
247
|
+
if (next === "(" || next === ")" || next === "#") return Math.min(3, s.length - i)
|
|
248
248
|
// ESC diikuti byte final tunggal (ESC 7, ESC =, ESC M, …) = 2 byte.
|
|
249
249
|
// ESC di ujung string = 1 byte. Karakter setelahnya yang BUKAN bagian
|
|
250
250
|
// sekuens (mis. huruf biasa) tidak boleh ikut ditelan — itu membuat teks
|
|
@@ -369,3 +369,90 @@ export function chunkByWidth(s: string, width: number): string[] {
|
|
|
369
369
|
if (cur !== "") pushChunk()
|
|
370
370
|
return out.length ? out : [""]
|
|
371
371
|
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Pecah string ke potongan <= `width` kolom, TAPI word-aware: lebih suka
|
|
375
|
+
* memutus di batas kata (spasi) daripada membelah kata di tengah. Token tanpa
|
|
376
|
+
* spasi yang lebih panjang dari `width` (URL, hash, CJK panjang) jatuh-balik
|
|
377
|
+
* ke pemotongan per-kolom. ANSI-safe (SGR terbuka dibawa ke potongan berikut,
|
|
378
|
+
* non-SGR dibuang) — identik dengan `chunkByWidth`.
|
|
379
|
+
*
|
|
380
|
+
* Spasi yang tepat TIDAK muat menjadi titik putus; spasi itu (dan spasi-trailing
|
|
381
|
+
* yang tak terlihat) dibuang, bukan dipindah ke baris berikutnya.
|
|
382
|
+
*/
|
|
383
|
+
export function wrapByWidth(s: string, width: number): string[] {
|
|
384
|
+
if (width <= 0) return [""]
|
|
385
|
+
const out: string[] = []
|
|
386
|
+
let line = ""
|
|
387
|
+
let lineWidth = 0
|
|
388
|
+
let openSgr: string[] = []
|
|
389
|
+
let word = ""
|
|
390
|
+
let wordWidth = 0
|
|
391
|
+
|
|
392
|
+
const trackSgr = (seq: string): void => {
|
|
393
|
+
if (!seq.endsWith("m")) return
|
|
394
|
+
const params = seq.slice(2, -1).split(/[:;]/)
|
|
395
|
+
if (params.some((p) => SGR_OFF.has(p) || p === "")) openSgr = []
|
|
396
|
+
if (params.some((p) => p !== "" && !SGR_OFF.has(p))) {
|
|
397
|
+
openSgr.push(seq)
|
|
398
|
+
if (openSgr.length > 8) openSgr = openSgr.slice(-8)
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const flush = (): void => {
|
|
403
|
+
if (line !== "") out.push(openSgr.length > 0 ? `${line}\x1b[0m` : line)
|
|
404
|
+
line = openSgr.join("")
|
|
405
|
+
lineWidth = 0
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const placeWord = (): void => {
|
|
409
|
+
if (wordWidth === 0) {
|
|
410
|
+
word = ""
|
|
411
|
+
return
|
|
412
|
+
}
|
|
413
|
+
if (lineWidth + wordWidth <= width) {
|
|
414
|
+
line += word
|
|
415
|
+
lineWidth += wordWidth
|
|
416
|
+
} else if (wordWidth <= width) {
|
|
417
|
+
// Kata utuh pindah ke baris berikutnya (bukan dibelah di tengah).
|
|
418
|
+
flush()
|
|
419
|
+
line += word
|
|
420
|
+
lineWidth += wordWidth
|
|
421
|
+
} else {
|
|
422
|
+
// Token tanpa spasi > width: potong per kolom (chunkByWidth, sgr-safe).
|
|
423
|
+
if (lineWidth > 0) flush()
|
|
424
|
+
const pieces = chunkByWidth(word, width)
|
|
425
|
+
for (let i = 0; i < pieces.length - 1; i++) {
|
|
426
|
+
const piece = pieces[i]!
|
|
427
|
+
out.push(openSgr.length > 0 && !piece.endsWith("\x1b[0m") ? `${piece}\x1b[0m` : piece)
|
|
428
|
+
}
|
|
429
|
+
line = pieces[pieces.length - 1] ?? ""
|
|
430
|
+
lineWidth = displayWidth(line)
|
|
431
|
+
}
|
|
432
|
+
word = ""
|
|
433
|
+
wordWidth = 0
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
for (const token of displayTokens(s)) {
|
|
437
|
+
if (token.escape) {
|
|
438
|
+
const seq = token.text
|
|
439
|
+
if (!isSgrSeq(seq)) continue
|
|
440
|
+
word += seq
|
|
441
|
+
trackSgr(seq)
|
|
442
|
+
continue
|
|
443
|
+
}
|
|
444
|
+
if (token.text === " ") {
|
|
445
|
+
placeWord()
|
|
446
|
+
if (lineWidth + 1 <= width) {
|
|
447
|
+
line += " "
|
|
448
|
+
lineWidth += 1
|
|
449
|
+
}
|
|
450
|
+
continue
|
|
451
|
+
}
|
|
452
|
+
word += token.text
|
|
453
|
+
wordWidth += token.width
|
|
454
|
+
}
|
|
455
|
+
placeWord()
|
|
456
|
+
if (line !== "" || out.length === 0) flush()
|
|
457
|
+
return out.length ? out : [""]
|
|
458
|
+
}
|
package/src/ui/runtime/screen.ts
CHANGED
|
@@ -15,6 +15,11 @@ const ENTER = "\x1b[?1049h"
|
|
|
15
15
|
const EXIT = "\x1b[?1049l"
|
|
16
16
|
const HOME = "\x1b[H"
|
|
17
17
|
const CLEAR_ALL = "\x1b[2J"
|
|
18
|
+
/** Reset atribut (warna/efek) + tampilkan kursor — ditulis saat exit supaya
|
|
19
|
+
* prompt shell kembali bersih (tidak ada sisa warna frame terakhir / kursor
|
|
20
|
+
* tersembunyi yang membuat terminal "berantakan" setelah Ctrl+D). */
|
|
21
|
+
const RESET_ATTRS = "\x1b[0m"
|
|
22
|
+
const SHOW_CURSOR = "\x1b[?25h"
|
|
18
23
|
// Reset scroll-region — unconditional + idempoten: region aktif peninggalan
|
|
19
24
|
// akan memotong paint fullscreen; tulis SEBELUM enter dan SESUDAH exit agar
|
|
20
25
|
// buffer utama kembali steril apa pun yang terjadi di dalam.
|
|
@@ -23,6 +28,12 @@ const CLEAR_ALL = "\x1b[2J"
|
|
|
23
28
|
const RESET_REGION = "\x1b[r"
|
|
24
29
|
const SYNC_START = "\x1b[?2026h"
|
|
25
30
|
const SYNC_END = "\x1b[?2026l"
|
|
31
|
+
/** Satu sekuens exit atomik: reset atribut → tampilkan kursor → tutup sync
|
|
32
|
+
* update → keluar alt-screen → reset region. Ditulis SEBAGAI SATU tulis agar
|
|
33
|
+
* terminal tak pernah tertinggal setengah pulih, dan agar jumlah writer di
|
|
34
|
+
* berkas ini tidak melewati batas inventaris OAP-008 (writer-inventory.test.ts
|
|
35
|
+
* menolak penulis yang bertambah diam-diam). */
|
|
36
|
+
const EXIT_SEQUENCE = RESET_ATTRS + SHOW_CURSOR + SYNC_END + EXIT + RESET_REGION
|
|
26
37
|
/** Ekspor untuk pemanggil yang melukis kursor di luar paint() (app.ts) —
|
|
27
38
|
* kursor WAJIB di dalam blok sync yang sama dengan framenya (TUI-007). */
|
|
28
39
|
export const SYNC_UPDATE_START = SYNC_START
|
|
@@ -42,7 +53,9 @@ function installExitHook(): void {
|
|
|
42
53
|
process.on("exit", () => {
|
|
43
54
|
if (depth > 0) {
|
|
44
55
|
try {
|
|
45
|
-
|
|
56
|
+
// Sekuens exit lengkap (reset atribut + kursor + sync + alt-screen +
|
|
57
|
+
// region) — jaring terakhir `kill`/`exit` tak langsung.
|
|
58
|
+
process.stdout.write(EXIT_SEQUENCE)
|
|
46
59
|
} catch {}
|
|
47
60
|
depth = 0
|
|
48
61
|
}
|
|
@@ -200,13 +213,7 @@ export function openAltScreen(): AltScreen {
|
|
|
200
213
|
depth = Math.max(0, depth - 1)
|
|
201
214
|
if (depth === 0) {
|
|
202
215
|
try {
|
|
203
|
-
process.stdout.write(
|
|
204
|
-
} catch {}
|
|
205
|
-
try {
|
|
206
|
-
process.stdout.write(EXIT)
|
|
207
|
-
} catch {}
|
|
208
|
-
try {
|
|
209
|
-
process.stdout.write(RESET_REGION)
|
|
216
|
+
process.stdout.write(EXIT_SEQUENCE)
|
|
210
217
|
} catch {}
|
|
211
218
|
}
|
|
212
219
|
},
|
|
@@ -226,13 +233,7 @@ export function altScreenDepth(): number {
|
|
|
226
233
|
export function forceRestoreScreenForSignal(): void {
|
|
227
234
|
if (depth > 0) {
|
|
228
235
|
try {
|
|
229
|
-
process.stdout.write(
|
|
230
|
-
} catch {}
|
|
231
|
-
try {
|
|
232
|
-
process.stdout.write(EXIT)
|
|
233
|
-
} catch {}
|
|
234
|
-
try {
|
|
235
|
-
process.stdout.write(RESET_REGION)
|
|
236
|
+
process.stdout.write(EXIT_SEQUENCE)
|
|
236
237
|
} catch {}
|
|
237
238
|
depth = 0
|
|
238
239
|
}
|
package/src/ui/session-state.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface UiSessionStateOptions {
|
|
|
40
40
|
minimizeTool?: boolean
|
|
41
41
|
compact?: boolean
|
|
42
42
|
reasoningVisible?: boolean
|
|
43
|
+
minimizeActivity?: boolean
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -54,6 +55,7 @@ export class UiSessionState {
|
|
|
54
55
|
#minimizeTool: boolean
|
|
55
56
|
#compact: boolean
|
|
56
57
|
#reasoningVisible: boolean
|
|
58
|
+
#minimizeActivity: boolean
|
|
57
59
|
#views: CollapsedSectionView[] = []
|
|
58
60
|
|
|
59
61
|
// Buffer /copy + error tertunda (logger linier). Berlifecycle per sesi:
|
|
@@ -68,7 +70,14 @@ export class UiSessionState {
|
|
|
68
70
|
this.#minimizeAnswer = opts.minimizeAnswer ?? process.env.MINICODE_MINIMIZE_ANSWER === "1"
|
|
69
71
|
this.#minimizeTool = opts.minimizeTool ?? process.env.MINICODE_MINIMIZE_TOOL === "1"
|
|
70
72
|
this.#compact = opts.compact ?? process.env.MINICODE_COMPACT === "1"
|
|
71
|
-
|
|
73
|
+
// Thinking/teks berpikir TERLIHAT secara default (expanded) — alasannya user
|
|
74
|
+
// ingin membaca proses berpikir model tanpa flag. `MINICODE_SHOW_THINKING=0`
|
|
75
|
+
// eksplisit mematikan (minimized); `=1` eksplisit menghidupkan.
|
|
76
|
+
this.#reasoningVisible = opts.reasoningVisible ?? process.env.MINICODE_SHOW_THINKING !== "0"
|
|
77
|
+
// Lipat aktivitas tool per turn (opencode-like): baris ledger per-tool
|
|
78
|
+
// ditahan, diganti satu ringkasan turn. Opt-in (`MINICODE_MINIMIZE_ACTIVITY=1`),
|
|
79
|
+
// default transparan sesuai filosofi "agentic Unix shell".
|
|
80
|
+
this.#minimizeActivity = opts.minimizeActivity ?? process.env.MINICODE_MINIMIZE_ACTIVITY === "1"
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
// ── Collapse ────────────────────────────────────────────────────────────
|
|
@@ -171,6 +180,23 @@ export class UiSessionState {
|
|
|
171
180
|
return nextVal
|
|
172
181
|
}
|
|
173
182
|
|
|
183
|
+
// ── Lipat aktivitas tool (opencode-like) ────────────────────────────────
|
|
184
|
+
|
|
185
|
+
get minimizeActivity(): boolean {
|
|
186
|
+
return this.#minimizeActivity
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
set minimizeActivity(v: boolean) {
|
|
190
|
+
this.#minimizeActivity = v
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Set eksplisit (on/off) atau toggle bila `next` tidak diberikan. */
|
|
194
|
+
setMinimizeActivity(next?: boolean): boolean {
|
|
195
|
+
const nextVal = next ?? !this.#minimizeActivity
|
|
196
|
+
this.#minimizeActivity = nextVal
|
|
197
|
+
return nextVal
|
|
198
|
+
}
|
|
199
|
+
|
|
174
200
|
// ── Buffer /copy (logger linier) ────────────────────────────────────────
|
|
175
201
|
|
|
176
202
|
/** Isi output turn terakhir (teks model + hasil tool). */
|