minicode-ai 0.14.2 → 0.14.5

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 (78) hide show
  1. package/README.md +34 -178
  2. package/cli/args.ts +10 -18
  3. package/cli/commands/acp.ts +20 -27
  4. package/cli/commands/daemon.ts +6 -7
  5. package/cli/commands/exec.ts +12 -10
  6. package/cli/commands.ts +6 -9
  7. package/cli/index.ts +30 -15
  8. package/cli/provider-manager.ts +1 -3
  9. package/cli/setup.ts +188 -143
  10. package/cli/tui.ts +15 -23
  11. package/docs/CONTROL-PLANE-MAP.md +145 -0
  12. package/docs/OUTPUT_EVENT_MODEL.md +1 -1
  13. package/docs/OUTPUT_PROTOCOL_SPEC.md +2 -2
  14. package/docs/OUTPUT_RENDERING_SPEC.md +7 -2
  15. package/docs/OUTPUT_UX_RULES.md +1 -1
  16. package/docs/README.md +14 -102
  17. package/docs/SUMMARY.md +53 -0
  18. package/docs/TERMINAL_CONTRACT.md +84 -51
  19. package/docs/UI_RENDER_PIPELINE.md +204 -0
  20. package/docs/agents.md +5 -5
  21. package/docs/architecture.md +23 -12
  22. package/docs/choosing-mode.md +7 -7
  23. package/docs/cli.md +22 -29
  24. package/docs/concepts.md +1 -1
  25. package/docs/config.md +10 -5
  26. package/docs/contributing.md +6 -6
  27. package/docs/environment.md +3 -1
  28. package/docs/exec.md +5 -5
  29. package/docs/glossary.md +8 -6
  30. package/docs/memory-sessions.md +7 -5
  31. package/docs/policy-sandbox.md +16 -14
  32. package/docs/quickstart.md +2 -2
  33. package/docs/repl.md +4 -3
  34. package/docs/security-model.md +14 -15
  35. package/docs/security.md +8 -29
  36. package/docs/skills.md +1 -1
  37. package/docs/tools.md +2 -2
  38. package/package.json +5 -3
  39. package/scripts/vendor-overlays/minicode-context.patch +109 -0
  40. package/src/app/provider-layer.ts +13 -1
  41. package/src/app/session.ts +231 -13
  42. package/src/config.ts +30 -3
  43. package/src/constants.ts +2 -0
  44. package/src/daemon/control.ts +1 -1
  45. package/src/mcp/server.ts +2 -3
  46. package/src/policy/compaction.ts +272 -16
  47. package/src/policy/context-window-catalog.ts +64 -0
  48. package/src/policy/context-window.ts +173 -0
  49. package/src/policy/context.ts +55 -3
  50. package/src/policy/pricing.ts +52 -0
  51. package/src/policy/ratelimit.ts +47 -18
  52. package/src/policy/usage.ts +15 -8
  53. package/src/policy/work-mode.ts +1 -1
  54. package/src/providers/guards.ts +61 -4
  55. package/src/providers/provision.ts +12 -3
  56. package/src/providers/router.ts +56 -23
  57. package/src/session/context-projection.ts +14 -0
  58. package/src/session/context-selector.ts +58 -20
  59. package/src/session/persistence.ts +1 -1
  60. package/src/task/model.ts +21 -70
  61. package/src/tools/task.ts +7 -0
  62. package/src/ui/footer.ts +131 -66
  63. package/src/ui/i18n/en.ts +0 -11
  64. package/src/ui/i18n/id.ts +0 -11
  65. package/src/ui/input/input.ts +2 -3
  66. package/src/ui/input/prompt-engine.ts +2 -5
  67. package/src/ui/screens/model-manager.ts +3 -10
  68. package/src/ui/screens/picker.ts +23 -40
  69. package/src/ui/screens/provider-manager.ts +12 -33
  70. package/src/ui/screens/wizard.ts +0 -1
  71. package/src/ui/tui/app.ts +10 -6
  72. package/src/ui/tui/transcript.ts +48 -8
  73. package/vendor/minicore/VENDOR.md +9 -5
  74. package/vendor/minicore/src/core/loop.ts +47 -12
  75. package/vendor/minicore/src/core/provider.ts +4 -0
  76. package/vendor/minicore/src/core/session.ts +14 -1
  77. package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +0 -489
  78. package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +0 -391
package/src/ui/i18n/id.ts CHANGED
@@ -4,8 +4,6 @@ import type { MsgKey } from "./locale.ts"
4
4
 
5
5
  export const id: Record<MsgKey, string> = {
6
6
  "app.placeholder": "tanya sesuatu, / untuk perintah… (Ctrl+D keluar)",
7
- "app.menuHeader": "─ perintah ─",
8
- "app.moreLines": " … {n} lagi",
9
7
  "app.newBelow": "↓ {n} baris baru di bawah · PgDn ke ekor",
10
8
  "app.abortHint": "abort terkirim — tekan Esc sekali lagi untuk keluar",
11
9
  "app.working": "Bekerja",
@@ -64,17 +62,11 @@ export const id: Record<MsgKey, string> = {
64
62
  "verb.delete": "hapus",
65
63
  "verb.edit": "ubah",
66
64
  "verb.close": "tutup",
67
- "pick.filter": "Filter:",
68
- "pick.placeholder": "ketik untuk saring",
69
65
  "pick.noMatch": 'Tidak cocok untuk "{q}"',
70
- "pick.matches": "{n}/{total} cocok",
71
- "pick.hint": "↑↓:{select} · Enter:{confirm} · Esc:{back}",
72
66
  "pick.fail": "picker gagal: {msg}",
73
67
  "pick.failOpen": "picker gagal dibuka: {msg}",
74
68
  "model.empty": "Belum ada model",
75
69
  "model.noMatch": "Tidak ada model yang cocok",
76
- "model.title": "Model",
77
- "model.typeFilter": "ketik untuk saring",
78
70
  "model.deleteTitle": "Hapus model",
79
71
  "model.deleteFooter": "←/→/y/n pilih · Enter hapus · Esc batal",
80
72
  "model.delActive": 'Hapus model AKTIF "{id}"?',
@@ -82,9 +74,7 @@ export const id: Record<MsgKey, string> = {
82
74
  "model.failOpen": "model manager gagal dibuka: {msg}",
83
75
  "effort.title": "Upaya berpikir",
84
76
  "effort.saved": "Thinking: {effort} (sesi berikut)",
85
- "prov.title": "Penyedia",
86
77
  "prov.empty": "Belum ada penyedia",
87
- "prov.hint": "Enter:{select} · a:{add} · d:{delete} · e:{edit} · Esc:{close}",
88
78
  "prov.addTitle": "Tambah penyedia",
89
79
  "prov.customUrl": "URL kustom",
90
80
  "prov.editTitle": 'Ubah "{id}"',
@@ -99,7 +89,6 @@ export const id: Record<MsgKey, string> = {
99
89
  "prov.deleteAsk": " — hapus?",
100
90
  "prov.deleteFooter": "←/→/y/n pilih · Enter hapus · Esc batal",
101
91
  "prov.failOpen": "provider manager gagal dibuka: {msg}",
102
- "prov.models": "{n} model",
103
92
  "prov.reloadFail": "reload provider gagal — restart untuk menerapkan",
104
93
  "prov.detectFail": "Deteksi model gagal: {msg}",
105
94
  "prov.updateFail": "Pembaruan gagal: {msg}",
@@ -112,9 +112,8 @@ export interface AskLineOptions {
112
112
  /**
113
113
  * Dipanggil untuk setiap keypress SEBELUM logika bawaan (history, applyKey).
114
114
  * Return truthy = key sudah ditangani pemanggil; askLine melewatkan handling
115
- * default dan tetap me-render ulang. Dipakai REPL linier untuk Shift+Tab
116
- * (cycle mode), Tab kosong (toggle plan/build), dan Ctrl+O (toggle compact).
117
- * `line` = isi baris saat ini (untuk Tab kosong).
115
+ * default dan tetap me-render ulang. Dipakai pemanggil untuk kontrol yang
116
+ * khusus pada permukaan input, seperti navigasi mode atau tampilan.
118
117
  */
119
118
  onKey?: (key: PromptKey, line: string) => boolean
120
119
  }
@@ -261,11 +261,8 @@ export function applyKey(
261
261
  return { state: { ...state, sel: (state.sel + 1) % n }, action: "render" }
262
262
  }
263
263
  case "tab": {
264
- // Tab sekarang HANYA putar mode (cycle `auto→ask→plan→allowlist`),
265
- // ditangani di REPL via `onKey` agar selalu jalan bahkan saat mengetik.
266
- // Completion dropdown tidak lagi pakai Tab — user pilih via ↑/↓ lalu
267
- // Enter (lengkapi + kirim). Tanpa ini Tab saat mengetik tidak bisa
268
- // ganti mode (keluhan nyata) dan menabrak completion.
264
+ // TUI menangani Tab sebagai siklus Work Mode sebelum editor generik.
265
+ // Picker command memilih item dengan ↑/↓ lalu Enter.
269
266
  return { state, action: "none" }
270
267
  }
271
268
  case "enter": {
@@ -85,9 +85,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
85
85
  return new Promise<void>((resolve) => {
86
86
  const visibleRows = () => {
87
87
  const rows = process.stdout.rows || 24
88
- // Popup: jatah dialog rows−4 sudah termasuk baris counter/notice, jadi
89
- // item dibatasi rows−5 (lihat picker.ts). Dialog mungil /model: maks 8.
90
- return Math.max(1, Math.min(rows - 5, 8))
88
+ // Dialog tanpa judul/footer; satu baris dipakai untuk pencarian.
89
+ return Math.max(1, Math.min(rows - 3, 8))
91
90
  }
92
91
  // Lantai lebar tak boleh melebihi terminal. Lebar konten = lebar kotak
93
92
  // tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
@@ -134,9 +133,8 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
134
133
  // App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
135
134
  const box = dialogBox(
136
135
  {
137
- title: t("model.title"),
136
+ title: "",
138
137
  body: bodyLinesModal(),
139
- footer: modelHint(),
140
138
  minWidth: MODAL_BOX_W,
141
139
  maxWidth: MODAL_BOX_W,
142
140
  maxHeight: 14,
@@ -164,11 +162,6 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
164
162
  } catch {}
165
163
  }
166
164
 
167
- /** Hint footer /model: Del/type-to-filter jadi discoverable (dulu tanpa
168
- * footer — user baru tak tahu cara hapus/saring). */
169
- const modelHint = (): string =>
170
- `${c.accent(t("model.typeFilter"))} · Del:${c.accent(t("verb.delete"))} · Enter:${c.accent(t("verb.select"))} · Esc:${c.accent(t("verb.close"))}`
171
-
172
165
  // Popup butuh layar mampu; selain itu tolak BERSUARA + batal.
173
166
  const screen: AltScreen = openAltScreen()
174
167
  const useModal = screen.ok && (process.stdout.rows || 24) >= 10
@@ -26,12 +26,10 @@ export interface PickerOptions {
26
26
  items: PickerItem[]
27
27
  onPick: (value: string) => void
28
28
  onCancel: () => void
29
- placeholder?: string
30
29
  filterable?: boolean
31
30
  }
32
31
 
33
- const dim = (s: string): string => c.dim(s),
34
- ACC_DIM = (s: string) => c.accent(s)
32
+ const dim = (s: string): string => c.dim(s)
35
33
 
36
34
  /** Lebar kotak popup picker TETAP (keputusan rasa: geometri stabil). */
37
35
  const PICKER_BOX_W = 64
@@ -53,10 +51,11 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
53
51
  if (!process.stdin.isTTY) {
54
52
  // Pipe/redirect: item dari config (tak-terpercaya) disanitasi agar ANSI
55
53
  // mentah tak mencemari output program (kontrak stdout non-TTY).
56
- console.log(`\n${opts.title}`)
57
- for (const [i, it] of opts.items.entries())
58
- console.log(` [${i}] ${sanitizeAnsiLine(it.provider)}::${sanitizeAnsiLine(it.name)}`)
59
- console.log("")
54
+ for (const it of opts.items) {
55
+ const provider = sanitizeAnsiLine(it.provider)
56
+ const name = sanitizeAnsiLine(it.name)
57
+ console.log(provider ? `${provider}::${name}` : name)
58
+ }
60
59
  // Fail-closed: pemanggil nested (mis. pickEffort di /model) menunggu
61
60
  // onPick/onCancel — tanpa ini await-nya gantung selamanya (busy=true)
62
61
  // saat isTTY flip di tengah. Non-TTY = tak ada pilihan = batal.
@@ -88,11 +87,9 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
88
87
  // dicetak — keduanya membungkus dan merusak tampilan.
89
88
  const visibleRows = () => {
90
89
  const rows = process.stdout.rows || 24
91
- // Sisakan ruang untuk judul, baris filter, baris footer, dan baris sisa.
92
- const chrome = isFilterable ? 4 : 3
93
- // Modal: dialog menambah border/judul/footer di luar jatah view + sisakan
94
- // 1 baris untuk baris counter ("… N more") agar End selalu sampai dasar.
95
- if (useModal) return Math.max(1, Math.min(rows - 5, 12))
90
+ // Modal tanpa judul/footer; sisakan border dan baris pencarian bila ada.
91
+ if (useModal) return Math.max(1, Math.min(rows - (isFilterable ? 3 : 2), 12))
92
+ const chrome = isFilterable ? 3 : 2
96
93
  return Math.max(1, Math.min(rows - chrome, 12))
97
94
  }
98
95
  // Lebar konten = lebar kotak TETAP (min=max, keputusan rasa: geometri
@@ -115,11 +112,9 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
115
112
  const cut = (s: string) => truncateToWidth(s, w)
116
113
  const lines: string[] = []
117
114
  if (isFilterable) {
118
- const placeholderText = opts.placeholder ?? t("pick.placeholder")
119
115
  // Filter = input user tak terpercaya — sanitasi sebelum tampil.
120
- const display = filter ? c.brightCyan(sanitizeAnsiLine(filter)) : dim(placeholderText)
121
- const label = filter ? ACC_DIM(t("pick.filter")) : dim(t("pick.filter"))
122
- lines.push(cut(`${label} ${display}`))
116
+ const display = filter ? c.brightCyan(sanitizeAnsiLine(filter)) : ""
117
+ lines.push(cut(`${dim(">")} ${display}${c.accent("█")}`))
123
118
  }
124
119
  if (items.length === 0) {
125
120
  lines.push(cut(dim(` ${t("pick.noMatch", { q: sanitizeAnsiLine(filter) })}`)))
@@ -128,38 +123,27 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
128
123
  for (let i = 0; i < rows.length; i++) {
129
124
  const it = rows[i]!
130
125
  const picked = i === sel - scroll
131
- // Potong label ke KOLOM (CJK 2 kolom), sisakan ruang untuk penanda "› ".
132
- // Highlight query DITERAPKAN sebelum truncate agar posisi kolom tepat.
133
- // Nama di DEPAN (truncasi memakan ekor — id/nama adalah info
134
- // terpenting dan harus selamat); provider/tanggal sebagai konteks
135
- // ekor yang boleh terpotong. Sanitasi DULU karena truncateToWidth
136
- // menyalin semua escape (juga 2J).
137
- const rawLabel = `${sanitizeAnsiLine(it.name)}${it.provider ? ` — ${sanitizeAnsiLine(it.provider)}` : ""}`
126
+ // Label provider::model ringkas; teks tetap disanitasi sebelum truncate.
127
+ // Highlight query diterapkan sebelum truncate agar posisi kolom tepat.
128
+ const safeProvider = sanitizeAnsiLine(it.provider)
129
+ const rawLabel = safeProvider
130
+ ? `${safeProvider}::${sanitizeAnsiLine(it.name)}`
131
+ : sanitizeAnsiLine(it.name)
138
132
  const label = highlightMatch(truncateToWidth(rawLabel, w - 4), filter)
139
133
  if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
140
134
  else lines.push(` ${dim(label)}`)
141
135
  }
142
- if (items.length > scroll + v) {
143
- lines.push(cut(dim(t("dlg.more", { n: items.length - scroll - v }))))
144
- } else if (isFilterable && filter) {
145
- lines.push(
146
- cut(dim(` ${t("pick.matches", { n: items.length, total: opts.items.length })}`)),
147
- )
148
- }
149
- return lines
136
+ return lines.slice(0, v + (isFilterable ? 1 : 0))
150
137
  }
151
138
 
152
- const hintText = (): string => t("pick.hint")
153
-
154
139
  const render = () => {
155
140
  // Popup komposit: HANYA region kotak yang dilukis (tanpa clear) di atas
156
141
  // konten pemilik layar (transkrip App / alt-buffer wizard). Pemilik
157
142
  // me-repaint penuh saat popup tutup. Lebar TETAP 64 (min=max).
158
143
  const box = dialogBox(
159
144
  {
160
- title: opts.title,
145
+ title: "",
161
146
  body: bodyLines(),
162
- footer: hintText(),
163
147
  minWidth: PICKER_BOX_W,
164
148
  maxWidth: PICKER_BOX_W,
165
149
  },
@@ -167,16 +151,15 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
167
151
  screen.rows,
168
152
  )
169
153
  screen.paintRegion(box.lines, box.topRow)
170
- // Parkir kursor: saat filter terisi, user sedang mengetik → kursor di
171
- // ujung teks filter (dulu selalu di baris item = ketik buta). Saat
172
- // filter kosong, parkir di baris item aktif (navigasi ↑↓).
154
+ // Parkir kursor pada input filter meski kosong agar teks pertama langsung
155
+ // masuk ke pencarian; navigasi item tetap memakai tombol panah.
173
156
  // Kolom = padding kiri + border + spasi + lebar label+filter + 1.
174
157
  try {
175
- if (isFilterable && filter !== "") {
158
+ if (isFilterable) {
176
159
  const li = Math.min(box.lines.length - 1, box.bodyTop)
177
160
  const row = box.topRow + li
178
161
  const leftPad = boxLeftPad(stripAnsi(box.lines[li] ?? ""))
179
- const col = leftPad + 2 + displayWidth(stripAnsi(`${t("pick.filter")} ${filter}`)) + 1
162
+ const col = leftPad + 2 + 2 + displayWidth(stripAnsi(filter)) + 1
180
163
  process.stdout.write(`\x1b[${row};${Math.max(1, col)}H\x1b[?25h`)
181
164
  } else {
182
165
  const itemRow = Math.min(Math.max(0, sel - scroll), Math.max(0, visibleRows() - 1))
@@ -11,7 +11,7 @@ import {
11
11
  } from "../input/prompt-engine.ts"
12
12
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
13
13
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
14
- import { displayWidth, padToWidth, truncateToWidth } from "../render/width.ts"
14
+ import { truncateToWidth } from "../render/width.ts"
15
15
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
16
16
  import { boxLeftPad, dialogBox } from "./dialog.ts"
17
17
  import { runForm, validateRequired, validateUrl } from "./form.ts"
@@ -19,8 +19,8 @@ import { runPicker } from "./picker.ts"
19
19
 
20
20
  const dim = (s: string): string => c.dim(s)
21
21
 
22
- /** Lebar kotak popup provider TETAP (lebih lebar: kolom URL panjang). */
23
- const PROVIDER_BOX_W = 76
22
+ /** Lebar tetap popup provider setelah daftar diringkas ke nama provider. */
23
+ const PROVIDER_BOX_W = 52
24
24
 
25
25
  export interface ProviderRow {
26
26
  id: string
@@ -86,19 +86,18 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
86
86
  }
87
87
 
88
88
  return new Promise<void>((resolve) => {
89
- // Ukuran mengikuti terminal SUNGGUHAN (lihat picker.ts untuk alasan sama).
90
- // Popup: jatah dialog rows−4 sudah termasuk baris counter/notice, jadi
91
- // item dibatasi rows−5 (lihat picker.ts).
89
+ // Ukuran mengikuti terminal sungguhan; satu baris border atas/bawah dan
90
+ // kemungkinan notice tetap masuk ke perhitungan tinggi.
92
91
  const visibleRows = () => {
93
92
  const rows = process.stdout.rows || 24
94
- return Math.max(1, Math.min(rows - 5, 14))
93
+ return Math.max(1, Math.min(rows - 3, 14))
95
94
  }
96
95
  // Lebar konten = lebar kotak TETAP (min=max, paritas picker/model) —
97
96
  // dikurangi chrome dialog (lihat picker.ts).
98
97
  const width = () =>
99
98
  Math.max(8, Math.min((process.stdout.columns || 80) - 2 - 4, PROVIDER_BOX_W - 4))
100
99
 
101
- // Isi popup (judul + hint dibingkai dialog).
100
+ // Isi popup ringkas: nama provider dan hasil aksi sementara.
102
101
  const bodyLines = (): string[] => {
103
102
  const v = visibleRows()
104
103
  if (sel < scroll) scroll = sel
@@ -113,47 +112,28 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
113
112
  for (let i = 0; i < rows.length; i++) {
114
113
  const it = rows[i]!
115
114
  const picked = i === sel - scroll
116
- // Tandai provider yang sedang aktif supaya user tahu apa yang akan
117
- // hilang bila ia menekan d. ID/URL dari config (data kotor mungkin)
118
- // disanitasi seperti label picker.
115
+ // Nama provider dan status aktif cukup untuk memilih tanpa memenuhi
116
+ // daftar dengan URL dan jumlah model.
119
117
  const aktif = opts.currentModel?.startsWith(`${it.id}::`)
120
118
  ? ` (${t("common.active")})`
121
119
  : ""
122
- // Status aktif TAK BOLEH ikut terpotong: URL dipotong dari budget
123
- // sisa SETELAH head+aktif (dulu truncate menelan "(aktif)" dulu
124
- // saat URL panjang — user tak tahu mana yang aktif).
125
- const head = `${padToWidth(sanitizeAnsiLine(it.id), 18)} ${t("prov.models", { n: it.models })} `
126
- const urlBudget = Math.max(8, w - 4 - displayWidth(head) - displayWidth(aktif))
127
- const label = `${head}${truncateToWidth(sanitizeAnsiLine(it.baseUrl), urlBudget, "…")}${aktif}`
120
+ const label = `${truncateToWidth(sanitizeAnsiLine(it.id), Math.max(8, w - 4 - aktif.length), "…")}${aktif}`
128
121
  if (picked) lines.push(` ${c.accent("›")} ${c.accent(c.bold(label))}`)
129
122
  else lines.push(` ${dim(label)}`)
130
123
  }
131
- if (providers.length > scroll + v) {
132
- lines.push(cut(dim(t("dlg.more", { n: providers.length - scroll - v }))))
133
- }
134
124
  }
135
125
  // Struk transient (jalur legacy maupun modal).
136
126
  if (notice) lines.push(cut(dim(sanitizeAnsiLine(notice))))
137
127
  return lines
138
128
  }
139
129
 
140
- const hintText = (): string =>
141
- t("prov.hint", {
142
- select: c.accent(t("verb.select")),
143
- add: c.accent(t("verb.add")),
144
- delete: c.accent(t("verb.delete")),
145
- edit: c.accent(t("verb.edit")),
146
- close: c.accent(t("verb.close")),
147
- })
148
-
149
130
  const render = () => {
150
131
  // Popup komposit: HANYA region kotak (tanpa clear) di atas konten
151
- // pemilik layar. Lebar TETAP 76 (min=max) — tak bernapas.
132
+ // pemilik layar. Lebar tetap 52 agar daftar tidak kosong terlalu lebar.
152
133
  const box = dialogBox(
153
134
  {
154
- title: t("prov.title"),
135
+ title: "",
155
136
  body: bodyLines(),
156
- footer: hintText(),
157
137
  minWidth: PROVIDER_BOX_W,
158
138
  maxWidth: PROVIDER_BOX_W,
159
139
  },
@@ -350,7 +330,6 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
350
330
  { name: t("prov.customUrl"), provider: "", value: CUSTOM },
351
331
  ],
352
332
  filterable: true,
353
- placeholder: t("pick.placeholder"),
354
333
  onPick: (v) => resolvePick(v),
355
334
  onCancel: () => resolvePick(null),
356
335
  }).catch(() => resolvePick(null))
@@ -62,7 +62,6 @@ export async function runSetupWizardView(opts: SetupWizardViewOptions): Promise<
62
62
  title: t("wiz.gateway"),
63
63
  items,
64
64
  filterable: true,
65
- placeholder: t("pick.placeholder"),
66
65
  onPick: (v) => {
67
66
  picked = v
68
67
  },
package/src/ui/tui/app.ts CHANGED
@@ -219,6 +219,7 @@ export class TuiApp {
219
219
  private onSignalTerm: (() => void) | null = null
220
220
  private onSignalHup: (() => void) | null = null
221
221
  private onSignalInt: (() => void) | null = null
222
+ private signalExitHandled = false
222
223
 
223
224
  private wasRaw = false
224
225
  /**
@@ -328,6 +329,8 @@ export class TuiApp {
328
329
  // loop, jadi tak ada jendela nyata; sisipkan await di antara keduanya =
329
330
  // membuka race SIGTERM sebelum handler terpasang.
330
331
  const restoreAndExit = (code: number) => {
332
+ if (this.signalExitHandled) return
333
+ this.signalExitHandled = true
331
334
  // Selesaikan loop lebih dulu: cleanup melepas referensi resolver.
332
335
  // Ini juga penting saat process.exit di-stub oleh test atau host.
333
336
  this.quitRequested = true
@@ -737,7 +740,10 @@ export class TuiApp {
737
740
  return
738
741
  }
739
742
  this.rememberHistory(line)
740
- this.transcript.pushUser(rawLine)
743
+ // Built-in commands and shortcuts belong to the composer history, not the
744
+ // conversation transcript. The command result remains independently
745
+ // visible when it carries useful user-facing information.
746
+ if (!line.startsWith("/")) this.transcript.pushUser(rawLine)
741
747
  this.busy = true
742
748
  this.thinkingActive = false
743
749
  this.turnStartedAt = Date.now()
@@ -1143,14 +1149,12 @@ export class TuiApp {
1143
1149
  const room = Math.max(0, rows - 2 - this.composerHeight(cols, busy) - 3)
1144
1150
  const shown = hints.slice(0, Math.min(MAX_DROPDOWN_ROWS, room))
1145
1151
  const w = Math.max(10, cols)
1146
- const out: string[] = [c.muted(t("app.menuHeader"))]
1152
+ const out: string[] = []
1147
1153
  shown.forEach((h, i) => {
1148
1154
  const picked = i === this.state.sel
1149
- const text = sanitizeAnsiLine(h)
1150
- out.push(picked ? c.accent(`› ${text}`) : ` ${text}`)
1155
+ const text = sanitizeAnsiLine(h).replace(/^\/+/, "")
1156
+ out.push(picked ? c.accent(c.bold(text)) : text)
1151
1157
  })
1152
- if (hints.length > shown.length)
1153
- out.push(c.muted(t("app.moreLines", { n: hints.length - shown.length })))
1154
1158
  return out.map((l) => chunkByWidth(l, w)[0] ?? "")
1155
1159
  }
1156
1160
 
@@ -132,6 +132,39 @@ function renderAssistantLine(line: string, fenceState: FenceState): string | nul
132
132
  return renderInline(line)
133
133
  }
134
134
 
135
+ /**
136
+ * Rapikan hanya whitespace presentasi jawaban model: hapus baris kosong di
137
+ * tepi dan batasi jeda berulang di luar fenced code. Isi code fence tetap
138
+ * literal karena spasi dan baris kosong di dalamnya adalah bagian contoh.
139
+ */
140
+ function normalizeAssistantOutput(text: string): string {
141
+ const lines = text.replace(/\r\n?/g, "\n").split("\n")
142
+ const out: string[] = []
143
+ let openFence: { char: string; len: number } | null = null
144
+ for (const line of lines) {
145
+ const fence = parseFence(line)
146
+ if (openFence) {
147
+ out.push(line)
148
+ if (fence && fence.char === openFence.char && fence.len >= openFence.len) openFence = null
149
+ continue
150
+ }
151
+ if (fence) {
152
+ openFence = fence
153
+ out.push(line)
154
+ continue
155
+ }
156
+ if (!line.trim()) {
157
+ if (out.length && out[out.length - 1] !== "") out.push("")
158
+ continue
159
+ }
160
+ out.push(line)
161
+ }
162
+ // Jika fence belum ditutup, baris kosong di ekor masih bagian dari contoh
163
+ // kode dan harus tetap literal. Hanya whitespace di luar fence yang dirapatkan.
164
+ if (!openFence) while (out.length && out[out.length - 1] === "") out.pop()
165
+ return out.join("\n")
166
+ }
167
+
135
168
  let selectionSegmenter: Intl.Segmenter | undefined
136
169
 
137
170
  function offsetAtColumn(text: string, start: number, end: number, column: number): number {
@@ -556,13 +589,18 @@ export class Transcript {
556
589
  }
557
590
  if (this.pending) {
558
591
  const pendingFence = this.fenceTracker()
559
- for (const block of parseMarkdownBlocks(sanitizeAnsi(this.pending))) {
560
- if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
561
- else
562
- for (const line of block.text.split("\n")) {
563
- const clean = stripSgr(sanitizeAnsi(line))
564
- rows.push(...this.projectText(line, clean, -1, w, false, "", true, pendingFence(line)))
565
- }
592
+ const pending = normalizeAssistantOutput(sanitizeAnsi(this.pending))
593
+ if (pending) {
594
+ for (const block of parseMarkdownBlocks(pending)) {
595
+ if (block.type === "table") rows.push(...this.projectTable(block.table, -1, w))
596
+ else
597
+ for (const line of block.text.split("\n")) {
598
+ const clean = stripSgr(sanitizeAnsi(line))
599
+ rows.push(
600
+ ...this.projectText(line, clean, -1, w, false, "", true, pendingFence(line)),
601
+ )
602
+ }
603
+ }
566
604
  }
567
605
  }
568
606
  if (this.pendingTruncated) {
@@ -707,11 +745,13 @@ export class Transcript {
707
745
 
708
746
  private commit(): void {
709
747
  if (!this.pending) return
710
- const text = this.pendingTruncated
748
+ const rawText = this.pendingTruncated
711
749
  ? `${this.pending}\n${TRANSCRIPT_TRUNCATION_MARKER}`
712
750
  : this.pending
713
751
  this.pending = ""
714
752
  this.pendingTruncated = false
753
+ const text = normalizeAssistantOutput(rawText)
754
+ if (!text) return
715
755
  for (const block of parseMarkdownBlocks(sanitizeAnsi(text))) {
716
756
  if (block.type === "table") this.appendTable(block.table, { kind: "assistant" })
717
757
  else {
@@ -1,14 +1,18 @@
1
1
  # vendor/minicore — JANGAN EDIT MANUAL
2
2
 
3
- Salinan kernel MiniCore agar `bun install` tidak membutuhkan clone sibling
4
- `../minicore`. Sumber kebenaran tetap repo minicore.
3
+ Salinan MiniCore dari source commit yang dipin, ditambah overlay host yang
4
+ diperiksa dari patch di `scripts/vendor-overlays/minicode-context.patch`.
5
+ Overlay memberi admission context per model dan system prompt dinamis;
6
+ simpan seam ini saat menyinkronkan source upstream.
5
7
 
6
8
  - source commit: `0d33571047c0ed3778986108fd42e4bde6828bb0`
9
+ - source hash: `c8d214bb8d5eea86`
10
+ - overlay sha256: `7545ff914e4f83745634ee106c9a2e774dfea3bf4541e58ea98eba216902d432`
7
11
  - files: 20
8
- - hash: `c8d214bb8d5eea86`
9
- - shipped hash: `78768e71a45254c3` (18 file) — fingerprint file vendor yang ikut paket npm
12
+ - hash: `b5e27f72d08afb98`
13
+ - shipped hash: `4998979304b3c6e2` (18 file) — fingerprint file vendor yang ikut paket npm
10
14
  (hash di atas mencakup test/fakes.ts yang sengaja tidak ikut paket;
11
15
  verifikasi dari paket terbit: hitung hash vendor/minicore di dalam tarball)
12
16
 
13
17
  Perbarui dengan `bun run vendor:minicore` (butuh `../minicore`).
14
- CI memverifikasi kesinkronan lewat `bun run vendor:check`.
18
+ `bun run vendor:check` memverifikasi source, overlay, dan fingerprint final.
@@ -45,11 +45,27 @@ export async function executeTurn(
45
45
  // compaction burned the one recovery retry (though recovery was never
46
46
  // tried), and vice versa. The recovery flag is ALWAYS set (a guard
47
47
  // against an infinite loop: force_compact_and_retry is exempt from
48
- // maxProviderRetries); the policy flag is set when a policy compaction
49
- // is attempted (once per turn, guarding against per-step O(n) repeats).
50
- let compactedForBudget = false;
48
+ // maxProviderRetries); policy compaction has a small per-turn hard cap,
49
+ // guarding against repeated no-progress work after tool output grows.
50
+ // Permit one follow-up policy compaction after tool results grow the current
51
+ // turn. The hard cap prevents a no-progress compactor from looping forever.
52
+ let budgetCompactions = 0;
53
+ const maxBudgetCompactions = 2;
51
54
  let compactedForRecovery = false;
52
55
 
56
+ // Resolve once for the turn: model switching is a between-turn operation,
57
+ // so budget admission and output accounting must use the same model window.
58
+ let contextWindowTokens = s.contextWindowTokens;
59
+ try {
60
+ const resolved = s.contextWindowTokensForModel?.(s.state.model);
61
+ if (typeof resolved === "number" && Number.isSafeInteger(resolved) && resolved > 0) {
62
+ contextWindowTokens = resolved;
63
+ }
64
+ } catch {
65
+ // Keep the validated numeric fallback; a metadata lookup must not bypass
66
+ // the kernel's context guard.
67
+ }
68
+
53
69
  while (true) {
54
70
  if (signal.aborted) throw abortError(signal);
55
71
  if (stepIndex >= s.maxSteps) throw new AgentError("max_steps_exceeded", `exceeded ${s.maxSteps} steps`);
@@ -59,28 +75,36 @@ export async function executeTurn(
59
75
  // prompt and tool schemas, which are sent on every request.
60
76
  let pressure = s.budget.evaluate({
61
77
  usedTokens: contextTokens(s),
62
- limitTokens: s.contextWindowTokens,
78
+ limitTokens: contextWindowTokens,
63
79
  });
64
- if (s.budget.shouldCompact(pressure) && !compactedForBudget) {
80
+ let reduced = false;
81
+ if (s.budget.shouldCompact(pressure) && budgetCompactions < maxBudgetCompactions) {
65
82
  const before = s.store.messages.length;
66
83
  await compactStore(s, signal);
67
- compactedForBudget = true;
84
+ budgetCompactions++;
68
85
  // The reason distinguishes the trigger and whether compaction
69
86
  // actually shrank the store (no-op = nothing evictable in messages;
70
87
  // reporters must tell that apart from fixed system+schema overhead,
71
88
  // which compaction never touches).
72
- const reduced = s.store.messages.length < before;
89
+ reduced = s.store.messages.length < before;
73
90
  s.events.emit({
74
91
  type: "context:compacted",
75
92
  reason: reduced ? `pressure:${pressure}` : `pressure:${pressure}:no-op`,
76
93
  });
77
94
  pressure = s.budget.evaluate({
78
95
  usedTokens: contextTokens(s),
79
- limitTokens: s.contextWindowTokens,
96
+ limitTokens: contextWindowTokens,
80
97
  });
81
98
  }
82
- if (pressure === "critical" && compactedForBudget) {
83
- throw new AgentError("budget_exceeded", "context window exceeded after compaction");
99
+ if (s.budget.shouldCompact(pressure) && reduced && budgetCompactions < maxBudgetCompactions) {
100
+ continue;
101
+ }
102
+ if (pressure === "critical") {
103
+ const used = contextTokens(s);
104
+ throw new AgentError(
105
+ "budget_exceeded",
106
+ `context window exceeded after compaction (${used} > ${contextWindowTokens}); reduce the prompt, tool output, or fixed instructions, or select a model with a larger context window`,
107
+ );
84
108
  }
85
109
 
86
110
  // Sample from the provider with deterministic recovery.
@@ -176,7 +200,11 @@ export async function executeTurn(
176
200
  throw new AgentError("provider", errorMessage ?? "provider error", { cause: providerError ?? action });
177
201
  case "force_compact_and_retry": {
178
202
  if (compactedForRecovery)
179
- throw new AgentError("budget_exceeded", errorMessage ?? "context too large", { cause: providerError ?? action });
203
+ throw new AgentError(
204
+ "budget_exceeded",
205
+ `context window exceeded after recovery compaction: ${errorMessage ?? "context too large"}`,
206
+ { cause: providerError ?? action },
207
+ );
180
208
  await compactStore(s, signal);
181
209
  // The recovery flag is ALWAYS set (even on no-op):
182
210
  // force_compact_and_retry is exempt from maxProviderRetries, so a
@@ -301,6 +329,9 @@ function toolErrorResult(call: ToolCall, message: string): ToolResult {
301
329
 
302
330
  function toProviderError(error: unknown, signal: AbortSignal): ProviderError {
303
331
  if (signal.aborted) throw abortError(signal);
332
+ // Host-side admission guards (context budget, shutdown, etc.) preserve their
333
+ // deterministic AgentError identity instead of entering provider retry.
334
+ if (error instanceof AgentError) throw error;
304
335
  if (error instanceof ProviderError) return error;
305
336
  if (error instanceof Error && error.name === "AbortError") {
306
337
  throw abortError(signal);
@@ -333,7 +364,11 @@ function delay(ms: number, signal: AbortSignal): Promise<void> {
333
364
  function contextTokens(s: SessionInternal): number {
334
365
  // Single source in tokens.ts `estimateSessionContext` — shared by the
335
366
  // loop and the Session getter so no duplicate estimator can drift.
336
- return estimateSessionContext(s.store, s.system, s.registry.list(), s.estimator);
367
+ let system = s.system;
368
+ try {
369
+ system = s.systemForContext?.() ?? system;
370
+ } catch {}
371
+ return estimateSessionContext(s.store, system, s.registry.list(), s.estimator);
337
372
  }
338
373
 
339
374
  // The single compaction seam. Prefers the strategy's optional async method
@@ -35,5 +35,9 @@ export interface StreamRequest {
35
35
  export interface ModelProvider {
36
36
  readonly id: string;
37
37
  readonly models: readonly string[];
38
+ /** Optional host metadata for per-model admission budgets. */
39
+ contextWindowTokensForModel?(model?: string): number;
40
+ /** Canonical provider/model key for per-model estimator state. */
41
+ contextModelIdentity?(model?: string): string | undefined;
38
42
  stream(request: StreamRequest, signal: AbortSignal): AsyncIterable<ProviderEvent>;
39
43
  }