minicode-ai 0.14.6 → 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.
Files changed (142) hide show
  1. package/README.md +6 -4
  2. package/cli/args.ts +20 -8
  3. package/cli/commands/exec.ts +17 -14
  4. package/cli/commands/openwork.ts +1 -1
  5. package/cli/commands.ts +39 -23
  6. package/cli/index.ts +29 -7
  7. package/cli/model-manager.ts +1 -1
  8. package/cli/router.ts +22 -9
  9. package/cli/setup.ts +77 -35
  10. package/cli/tui.ts +179 -25
  11. package/docs/CONTROL-PLANE-MAP.md +7 -5
  12. package/docs/OUTPUT_EVENT_MODEL.md +4 -3
  13. package/docs/OUTPUT_PROTOCOL_SPEC.md +1 -1
  14. package/docs/OUTPUT_RENDERING_SPEC.md +16 -4
  15. package/docs/OUTPUT_UX_RULES.md +38 -32
  16. package/docs/P14_OPEN_WORK.md +290 -0
  17. package/docs/README.md +1 -1
  18. package/docs/SUMMARY.md +36 -22
  19. package/docs/TERMINAL_CONTRACT.md +89 -17
  20. package/docs/UI_RENDER_PIPELINE.md +47 -8
  21. package/docs/agents.md +1 -1
  22. package/docs/architecture.md +10 -8
  23. package/docs/autonomous-scheduler.md +142 -0
  24. package/docs/choosing-mode.md +4 -2
  25. package/docs/cli.md +11 -9
  26. package/docs/concepts.md +5 -5
  27. package/docs/config-providers.md +3 -3
  28. package/docs/config.md +1 -1
  29. package/docs/contributing.md +7 -9
  30. package/docs/environment.md +8 -5
  31. package/docs/getting-started.md +5 -5
  32. package/docs/mcp-lsp.md +2 -2
  33. package/docs/memory-sessions.md +3 -3
  34. package/docs/policy-sandbox.md +7 -4
  35. package/docs/pricing-budget.md +3 -3
  36. package/docs/quickstart.md +1 -1
  37. package/docs/repl.md +11 -8
  38. package/docs/security-model.md +4 -2
  39. package/docs/security.md +9 -8
  40. package/docs/skills.md +2 -2
  41. package/docs/terminal.md +10 -2
  42. package/docs/tools.md +4 -4
  43. package/docs/troubleshooting.md +3 -3
  44. package/docs/verify-benchmark.md +0 -3
  45. package/package.json +9 -18
  46. package/scripts/vendor-overlays/minicode-context.patch +1 -1
  47. package/src/app/mentions.ts +1 -1
  48. package/src/app/rag-layer.ts +11 -2
  49. package/src/app/session.ts +128 -10
  50. package/src/constants.ts +32 -1
  51. package/src/daemon/client.ts +11 -6
  52. package/src/daemon/control.ts +2 -9
  53. package/src/daemon/resource.ts +5 -4
  54. package/src/hooks/run.ts +5 -6
  55. package/src/lib/keystore.ts +11 -9
  56. package/src/lib/net.ts +8 -3
  57. package/src/lib/safe-open.ts +29 -5
  58. package/src/lib/trusted-exec.ts +4 -1
  59. package/src/lsp/client.ts +9 -10
  60. package/src/mcp/http-transport.ts +1 -1
  61. package/src/mcp/server.ts +17 -7
  62. package/src/memory/files.ts +2 -1
  63. package/src/memory/vector.ts +25 -16
  64. package/src/policy/bash-guard.ts +58 -16
  65. package/src/policy/bpe.ts +110 -0
  66. package/src/policy/compaction.ts +139 -22
  67. package/src/policy/consequence-engine.ts +3 -3
  68. package/src/policy/context-window.ts +43 -1
  69. package/src/policy/context.ts +50 -12
  70. package/src/policy/jail.ts +48 -3
  71. package/src/policy/no-progress.ts +15 -8
  72. package/src/policy/permission.ts +243 -5
  73. package/src/policy/tokenizer-registry.ts +104 -0
  74. package/src/policy/usage.ts +20 -13
  75. package/src/policy/verifier.ts +7 -4
  76. package/src/policy/work-mode.ts +9 -5
  77. package/src/presentation/adapter.ts +8 -4
  78. package/src/presentation/events.ts +2 -2
  79. package/src/presentation/label.ts +3 -3
  80. package/src/presentation/model.ts +4 -0
  81. package/src/presentation/projection.ts +10 -2
  82. package/src/presentation/store.ts +2 -2
  83. package/src/providers/anthropic.ts +13 -3
  84. package/src/providers/responses.ts +16 -6
  85. package/src/runtime/capability.ts +22 -4
  86. package/src/runtime/child-execution.ts +1 -1
  87. package/src/runtime/composition.ts +5 -5
  88. package/src/runtime/execution-journal.ts +13 -7
  89. package/src/runtime/execution-registry.ts +1 -1
  90. package/src/runtime/production-execution.ts +7 -6
  91. package/src/runtime/production-runtime.ts +2 -2
  92. package/src/runtime/runtime-capabilities.ts +1 -1
  93. package/src/runtime/runtime-status-facts.ts +1 -1
  94. package/src/runtime/runtime-task-admission.ts +2 -2
  95. package/src/sandbox/os.ts +4 -3
  96. package/src/session/checkpoint.ts +29 -4
  97. package/src/session/context-assembly.ts +8 -1
  98. package/src/session/context-identity.ts +2 -2
  99. package/src/session/context-projection.ts +36 -11
  100. package/src/session/persistence.ts +22 -11
  101. package/src/task/autonomous-context.ts +2 -3
  102. package/src/task/autonomous-policy.ts +3 -3
  103. package/src/task/model.ts +2 -2
  104. package/src/task/production-scheduler.ts +2 -2
  105. package/src/task/scheduler-observability.ts +1 -0
  106. package/src/task/scheduler.ts +3 -2
  107. package/src/task/scheduling-policy.ts +2 -1
  108. package/src/task/trigger.ts +5 -5
  109. package/src/tools/git.ts +22 -4
  110. package/src/tools/lsp.ts +10 -8
  111. package/src/tools/read_image.ts +2 -1
  112. package/src/tools/task.ts +1 -1
  113. package/src/tools/web_fetch.ts +6 -2
  114. package/src/tools/web_search.ts +2 -1
  115. package/src/ui/assistant/simple.ts +42 -33
  116. package/src/ui/contract.ts +4 -0
  117. package/src/ui/footer.ts +63 -12
  118. package/src/ui/i18n/en.ts +14 -2
  119. package/src/ui/i18n/id.ts +14 -2
  120. package/src/ui/input/prompt-engine.ts +36 -10
  121. package/src/ui/render/cells.ts +320 -0
  122. package/src/ui/render/composer-wrap.ts +73 -0
  123. package/src/ui/render/detail.ts +2 -2
  124. package/src/ui/render/diff.ts +14 -5
  125. package/src/ui/render/highlight.ts +4 -4
  126. package/src/ui/render/ledger.ts +47 -0
  127. package/src/ui/render/markdown.ts +12 -5
  128. package/src/ui/render/session-summary.ts +50 -0
  129. package/src/ui/render/table-grid.ts +134 -6
  130. package/src/ui/render/theme.ts +49 -4
  131. package/src/ui/render/width.ts +91 -4
  132. package/src/ui/render/wrap.ts +5 -3
  133. package/src/ui/runtime/screen.ts +100 -22
  134. package/src/ui/runtime/statusline.ts +26 -0
  135. package/src/ui/screens/model-manager.ts +1 -1
  136. package/src/ui/session-state.ts +27 -1
  137. package/src/ui/tui/app.ts +336 -65
  138. package/src/ui/tui/transcript.ts +335 -104
  139. package/vendor/minicore/VENDOR.md +16 -12
  140. package/vendor/minicore/src/core/events.ts +1 -0
  141. package/vendor/minicore/src/core/loop.ts +11 -1
  142. package/vendor/minicore/src/core/session.ts +39 -0
@@ -188,7 +188,7 @@ function highlightTsTokens(text: string): string {
188
188
  /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|\b\d+(?:\.\d+)?\b|\b[A-Za-z_$][A-Za-z0-9_$]*\b|[{}()[\];:,.<>=+\-*/%!&|^~?]+|\s+)/g
189
189
  return text.replace(tokenRe, (token) => {
190
190
  if (token.startsWith('"') || token.startsWith("'") || token.startsWith("`")) {
191
- return c.green(token)
191
+ return c.string(token)
192
192
  }
193
193
  if (/^\d+(?:\.\d+)?$/.test(token)) {
194
194
  return c.brightYellow(token)
@@ -223,7 +223,7 @@ function highlightPythonTokens(text: string): string {
223
223
  /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\b\d+(?:\.\d+)?\b|\b[A-Za-z_][A-Za-z0-9_]*\b|[{}()[\];:,.<>=+\-*/%!&|^~?]+|\s+)/g
224
224
  return text.replace(tokenRe, (token) => {
225
225
  if (token.startsWith('"') || token.startsWith("'")) {
226
- return c.green(token)
226
+ return c.string(token)
227
227
  }
228
228
  if (/^\d+/.test(token)) return c.brightYellow(token)
229
229
  if (PY_KEYWORDS.has(token)) return c.brightMagenta(c.bold(token))
@@ -239,7 +239,7 @@ function highlightJsonLine(line: string): string {
239
239
  (match, str, colon, bool, num) => {
240
240
  if (str) {
241
241
  if (colon) return c.brightCyan(str) + colon
242
- return c.green(str)
242
+ return c.string(str)
243
243
  }
244
244
  if (bool) return c.yellow(bool)
245
245
  if (num) return c.brightYellow(num)
@@ -264,7 +264,7 @@ function highlightShellTokens(text: string): string {
264
264
  return text.replace(
265
265
  /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\$[A-Za-z0-9_]+|-{1,2}[A-Za-z0-9][A-Za-z0-9_-]*|\b[A-Za-z_][A-Za-z0-9_-]*\b|\s+)/g,
266
266
  (token) => {
267
- if (token.startsWith('"') || token.startsWith("'")) return c.green(token)
267
+ if (token.startsWith('"') || token.startsWith("'")) return c.string(token)
268
268
  if (token.startsWith("$")) return c.brightCyan(token)
269
269
  if (SH_KEYWORDS.has(token)) return c.brightMagenta(c.bold(token))
270
270
  if (token.startsWith("-")) return c.yellow(token)
@@ -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
+ }
@@ -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
- out.push(c.bold(line))
132
+ // Margin kiri 1 kolom — jangan menempel ke tepi terminal.
133
+ out.push(` ${c.bold(line)}`)
133
134
  continue
134
135
  }
135
136
 
136
- // Bullet list -> indentasi
137
- if (/^\s*[-*]\s/.test(line)) {
138
- out.push(` ${renderInline(line.trimStart())}`)
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
- out.push(renderInline(line))
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
- const overhead = table.headers.length * 3 - 1
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 options.styleHeader === false ? ` ${rendered} ` : ` ${c.bold(c.accent(rendered))} `
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
 
@@ -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
 
@@ -76,6 +93,13 @@ const TOKENS = {
76
93
  warning: "38;2;204;167;0",
77
94
  info: "38;2;117;190;255",
78
95
  accent: "38;2;0;122;204",
96
+ // String literal kode (VS Code Dark+ `string` #CE9178) — sengaja terpisah dari
97
+ // `success` (green): string harus tampak jingga-salm ala VS Code, sementara
98
+ // status sukses tetap hijau. Alias lama `green` tetap menyasar success.
99
+ string: "38;2;206;145;120",
100
+ // Thinking/reasoning: abu-kebiruan yang tetap terbaca nyaman (bukan `dim` yang
101
+ // meredupkan seluruh teks) — jelas sekunder dari jawaban model tapi tak silau.
102
+ thinking: "38;2;135;146;160",
79
103
  // Faint: abu gelap untuk garis footer — lebih redup dari `gray` (bright-black)
80
104
  // dan dari `muted` (dim). Dipakai elemen yang harus ada tapi hampir tak
81
105
  // terlihat, seperti separator baris dasar.
@@ -110,6 +134,8 @@ interface Palette {
110
134
  brightYellow: Paint
111
135
  brightMagenta: Paint
112
136
  brightCyan: Paint
137
+ string: Paint
138
+ thinking: Paint
113
139
  }
114
140
 
115
141
  const paletteCache = new Map<string, Palette>()
@@ -146,6 +172,8 @@ function buildPalette(): Palette {
146
172
  brightYellow: mono ? identity : truecolor ? wrap("38;2;215;186;125", 39) : wrap(93, 39),
147
173
  brightMagenta: mono ? identity : truecolor ? wrap("38;2;197;134;192", 39) : wrap(95, 39),
148
174
  brightCyan: mono ? identity : truecolor ? wrap("38;2;78;201;176", 39) : wrap(96, 39),
175
+ string: paintFrom(TOKENS.string),
176
+ thinking: paintFrom(TOKENS.thinking),
149
177
  }
150
178
  }
151
179
 
@@ -265,6 +293,12 @@ export const c = {
265
293
  get brightCyan() {
266
294
  return palette().brightCyan
267
295
  },
296
+ get string() {
297
+ return palette().string
298
+ },
299
+ get thinking() {
300
+ return palette().thinking
301
+ },
268
302
  }
269
303
 
270
304
  // ── Glyphs - minimal, Ubuntu Server style ──
@@ -275,17 +309,20 @@ export const c = {
275
309
  // `cli/commands.ts` pernah membekukannya (V8) sehingga fallback ASCII tidak
276
310
  // pernah aktif. Dijaga oleh `test/no-frozen-runtime-value.test.ts`.
277
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.
278
315
  get check() {
279
- return supportsUtf8() ? "✓" : "[OK]"
316
+ return ""
280
317
  },
281
318
  get cross() {
282
- return supportsUtf8() ? "✗" : "[FAIL]"
319
+ return ""
283
320
  },
284
321
  get denied() {
285
- return supportsUtf8() ? "⊘" : "[DENY]"
322
+ return ""
286
323
  },
287
324
  get circle() {
288
- return supportsUtf8() ? "○" : "[CANCEL]"
325
+ return ""
289
326
  },
290
327
  get arrow() {
291
328
  return supportsUtf8() ? "›" : ">"
@@ -314,6 +351,14 @@ export const glyphs = {
314
351
  // Fallback * untuk terminal tanpa UTF-8.
315
352
  return supportsUtf8() ? "✦" : "*"
316
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
+ },
317
362
  }
318
363
 
319
364
  // ── Section separator ──
@@ -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)))
@@ -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
+ }
@@ -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. MINICODE_JUSTIFY=0 mematikan justify sepenuhnya.
103
- export function formatWrapped(text: string, width: number, justify = true): string {
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 === "0") return wrapped
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) => {