minicode-ai 0.23.0 → 0.26.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 (104) hide show
  1. package/README.md +5 -3
  2. package/cli/commands/config.ts +123 -0
  3. package/cli/setup.ts +107 -8
  4. package/cli/tui.ts +28 -2
  5. package/docs/README.md +2 -2
  6. package/docs/SUMMARY.md +10 -19
  7. package/docs/TERMINAL_CONTRACT.md +113 -28
  8. package/docs/architecture.md +1 -1
  9. package/docs/autonomous-scheduler.md +283 -2
  10. package/docs/choosing-mode.md +4 -4
  11. package/docs/concepts.md +39 -3
  12. package/docs/config.md +103 -5
  13. package/docs/environment.md +4 -0
  14. package/docs/getting-started.md +69 -5
  15. package/docs/repl.md +1 -1
  16. package/docs/security.md +49 -2
  17. package/docs/tools.md +2 -1
  18. package/package.json +2 -36
  19. package/src/app/provider-layer.ts +1 -1
  20. package/src/app/session.ts +187 -17
  21. package/src/config.ts +21 -8
  22. package/src/constants.ts +17 -1
  23. package/src/lib/net.ts +6 -15
  24. package/src/lib/public-http.ts +128 -0
  25. package/src/lib/safe-open.ts +21 -12
  26. package/src/memory/vector.ts +0 -31
  27. package/src/policy/auto-resume.ts +63 -0
  28. package/src/policy/compaction.ts +354 -70
  29. package/src/policy/context-budget.ts +4 -6
  30. package/src/policy/context-window-assign.ts +114 -0
  31. package/src/policy/context-window-catalog.ts +4 -1
  32. package/src/policy/context-window-presets.ts +165 -0
  33. package/src/policy/context-window.ts +19 -37
  34. package/src/policy/context.ts +11 -9
  35. package/src/policy/executor.ts +69 -27
  36. package/src/policy/microcompact.ts +76 -15
  37. package/src/policy/no-progress.ts +1 -1
  38. package/src/policy/permission.ts +5 -0
  39. package/src/policy/recovery-budget.ts +281 -0
  40. package/src/policy/scrub.ts +15 -2
  41. package/src/policy/step-escalation.ts +82 -0
  42. package/src/policy/tokenizer-registry.ts +1 -0
  43. package/src/policy/tool-contract.ts +11 -9
  44. package/src/presentation/reducer.ts +1 -0
  45. package/src/providers/anthropic.ts +3 -3
  46. package/src/providers/detect.ts +40 -7
  47. package/src/providers/provision.ts +23 -1
  48. package/src/runtime/child-execution.ts +4 -2
  49. package/src/runtime/execution-backend.ts +3 -0
  50. package/src/sandbox/os.ts +53 -9
  51. package/src/session/context-assembly.ts +11 -7
  52. package/src/session/persistence.ts +19 -3
  53. package/src/task/autonomous-policy.ts +7 -0
  54. package/src/task/graph-validate.ts +1 -1
  55. package/src/task/session-authority.ts +0 -5
  56. package/src/task/store.ts +0 -4
  57. package/src/tools/ask_user.ts +14 -1
  58. package/src/tools/bash.ts +68 -17
  59. package/src/tools/code_run.ts +19 -20
  60. package/src/tools/context.ts +10 -0
  61. package/src/tools/delete_file.ts +3 -2
  62. package/src/tools/edit.ts +5 -4
  63. package/src/tools/git.ts +70 -12
  64. package/src/tools/glob.ts +13 -5
  65. package/src/tools/grep.ts +26 -10
  66. package/src/tools/index.ts +3 -2
  67. package/src/tools/lsp.ts +15 -9
  68. package/src/tools/move_file.ts +4 -3
  69. package/src/tools/patch.ts +5 -4
  70. package/src/tools/read_file.ts +3 -2
  71. package/src/tools/read_image.ts +3 -2
  72. package/src/tools/task.ts +5 -1
  73. package/src/tools/todo.ts +4 -8
  74. package/src/tools/web_fetch.ts +13 -19
  75. package/src/tools/write_file.ts +4 -3
  76. package/src/ui/approval/prompt.ts +226 -77
  77. package/src/ui/assistant/simple.ts +61 -10
  78. package/src/ui/footer.ts +41 -29
  79. package/src/ui/i18n/en.ts +7 -0
  80. package/src/ui/i18n/id.ts +7 -0
  81. package/src/ui/input/prompt-engine.ts +53 -21
  82. package/src/ui/render/activity-group.ts +9 -0
  83. package/src/ui/render/activity-panel.ts +20 -2
  84. package/src/ui/render/ledger.ts +1 -9
  85. package/src/ui/render/logo.ts +0 -5
  86. package/src/ui/render/markdown-table.ts +0 -3
  87. package/src/ui/render/table-grid.ts +0 -3
  88. package/src/ui/render/theme.ts +31 -5
  89. package/src/ui/runtime/screen.ts +7 -1
  90. package/src/ui/screens/dialog.ts +45 -81
  91. package/src/ui/screens/form.ts +10 -10
  92. package/src/ui/screens/model-manager.ts +7 -10
  93. package/src/ui/screens/picker.ts +8 -11
  94. package/src/ui/screens/provider-manager.ts +9 -13
  95. package/src/ui/tui/app.ts +118 -20
  96. package/src/ui/tui/transcript.ts +179 -29
  97. package/vendor/minicore/src/core/loop.ts +20 -1
  98. package/vendor/minicore/src/core/session.ts +6 -0
  99. package/docs/P14_OPEN_WORK.md +0 -290
  100. package/docs/config-providers.md +0 -87
  101. package/docs/glossary.md +0 -39
  102. package/docs/quickstart.md +0 -60
  103. package/docs/security-model.md +0 -96
  104. package/docs/terminal.md +0 -91
@@ -1,9 +1,7 @@
1
- // Bingkai dialog modal: backdrop + kotak terpusat (border, judul, bayangan).
2
- //
3
- // View membangun KONTEN (state + tombol, seperti sekarang); dialog.ts hanya
4
- // menata konten menjadi frame SELAYAR (`rows` baris tepat) untuk `screen.paint`.
5
- // Teks disanitasi satu-baris + potong per kolom di sini (defense-in-depth di
6
- // atas sanitasi view — idempoten, murah). Fallback ASCII bila MINICODE_ASCII=1.
1
+ // Kotak dialog: border, judul, footer, terpusat. View membangun KONTEN; di
2
+ // sini konten ditata jadi baris kotak (paintRegion melukis region-nya saja).
3
+ // Teks disanitasi + dipotong per kolom (defense-in-depth, idempoten). ASCII
4
+ // bila MINICODE_ASCII=1.
7
5
 
8
6
  import { t } from "../i18n/locale.ts"
9
7
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
@@ -13,27 +11,17 @@ import { displayWidth, padToWidth, truncateToWidth } from "../render/width.ts"
13
11
  export interface DialogSpec {
14
12
  /** Judul baris atas. String kosong = tanpa baris judul (chrome menyesuaikan). */
15
13
  title: string
16
- /** Baris konten polos (sudah di-clamp view; di sini dipotong defensif). */
14
+ /** Baris konten polos. */
17
15
  body: string[]
18
16
  /** Baris hint bawah (tombol). Kosong = tanpa footer. */
19
17
  footer?: string
20
- /** Lebar kotak maksimum (inklusif border+padding). Default: selebar layar. */
18
+ /** Lebar maksimum (inklusif border+padding). Default: popup terhitung. */
21
19
  maxWidth?: number
22
- /**
23
- * Lebar kotak MINIMUM (inklusif border+padding): kotak tak pernah lebih
24
- * sempit dari ini walau konten pendek — geometri stabil, tak melompat
25
- * mengikuti data (keputusan rasa: presisi). Samakan dengan maxWidth untuk
26
- * lebar TETAP.
27
- */
20
+ /** Lebar MINIMUM (inklusif border+padding). Default: skala dari `cols`. */
28
21
  minWidth?: number
29
- /** Tinggi kotak maksimum (inklusif border). Default: setinggi layar. */
22
+ /** Tinggi maksimum (inklusif border). Default: setinggi layar. */
30
23
  maxHeight?: number
31
- /**
32
- * Indeks body (0-based) yang WAJIB terlihat, mis. field aktif form. Bila
33
- * body melebihi tinggi kotak, jendela digeser agar baris ini ikut tampil —
34
- * tanpa ini user mengetik ke field yang tidak ada di layar (audit
35
- * 2026-11-12, HIGH-2).
36
- */
24
+ /** Indeks body yang WAJIB terlihat; jendela digeser agar tak mengetik buta (HIGH-2). */
37
25
  focusRow?: number
38
26
  }
39
27
 
@@ -46,14 +34,24 @@ interface BoxChars {
46
34
  v: string
47
35
  }
48
36
 
37
+ /** Lebar kotak popup: skala dari layar; pemanggil membekukan saat mount. */
38
+ export function popupBoxWidth(cols: number): number {
39
+ const safeCols = Math.max(10, cols)
40
+ const scaled = Math.floor(safeCols * 0.6)
41
+ // Margin 4 kolom menang atas lantai 40 (AUD-011: `max(40,…)` dulu
42
+ // membungkus clamp sehingga terminal sempit overflow).
43
+ const room = safeCols - 4
44
+ return Math.min(Math.max(40, Math.min(88, scaled)), room)
45
+ }
46
+
49
47
  function boxChars(): BoxChars {
50
- // supportsUtf8() dibaca TIAP paint (getter runtime, bukan cache module) —
51
- // aturan yang sama dengan c/glyphs (theme.ts).
52
- // Tanpa bayangan: kolom `▓` redup terlihat seperti strip berpasir di
53
- // Windows Terminal (keluhan visual nyata) — kedalaman diganti backdrop
54
- // redup + kotak terpusat saja.
55
- if (!supportsUtf8()) return { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
56
- return { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│" }
48
+ // Kapabilitas dan kill-switch dibaca tiap render agar perubahan env runtime
49
+ // (terutama test/aksesibilitas) langsung berlaku, bukan membeku saat import.
50
+ const style = process.env.MINICODE_BOX?.toLowerCase()
51
+ if (process.env.MINICODE_ASCII === "1" || style === "ascii" || !supportsUtf8())
52
+ return { tl: "+", tr: "+", bl: "+", br: "+", h: "-", v: "|" }
53
+ if (style === "square") return { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│" }
54
+ return { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" }
57
55
  }
58
56
 
59
57
  /** Kotak popup tanpa backdrop: untuk paintRegion di atas konten pemilik layar. */
@@ -87,11 +85,7 @@ export function boxLeftPad(strippedLine: string): number {
87
85
  return m ? m[0].length : 0
88
86
  }
89
87
 
90
- /**
91
- * Bangun KOTAK saja (tanpa backdrop): dipakai popup komposit App TUI lewat
92
- * paintRegion — transkrip di belakang tetap tampil. Lebar mengikuti konten
93
- * (clamp maxWidth); tinggi mengikuti body (clamp maxHeight).
94
- */
88
+ /** Bangun KOTAK saja (tanpa backdrop); minWidth==maxWidth = lebar beku. */
95
89
  export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogBox {
96
90
  const c0 = Math.max(20, Math.floor(cols) || 80)
97
91
  const r0 = Math.max(5, Math.floor(rows) || 24)
@@ -99,19 +93,22 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
99
93
  const title = sanitizeAnsiLine(spec.title)
100
94
  const footer = spec.footer != null && spec.footer !== "" ? sanitizeAnsiLine(spec.footer) : null
101
95
 
102
- // Lebar dalam = konten terlebar, clamp ke layar. Chrome total per baris:
103
- // v(1) + sp(1) + innerW + sp(1) + v(1) = innerW + 4. View membangun baris
104
- // selebar itu (width() modal-aware) sehingga tak ada potong ulang di sini.
105
- // maxWidth opsional mengecilkan kotak (dialog mungil) — kurangi SEBELUM
106
- // hitung isi. Judul kosong = tanpa baris judul (chrome vertikal menyesuaikan).
107
96
  const hasTitle = title !== ""
108
- let innerMax = c0 - 2 - 4
109
- if (spec.maxWidth != null && Number.isFinite(spec.maxWidth))
110
- innerMax = Math.min(innerMax, Math.max(8, Math.floor(spec.maxWidth) - 4))
111
- if (innerMax < 8) innerMax = 8
112
- let innerMin = 8
113
- if (spec.minWidth != null && Number.isFinite(spec.minWidth))
114
- innerMin = Math.min(innerMax, Math.max(8, Math.floor(spec.minWidth) - 4))
97
+ const maxInner = Math.max(10, c0 - 6)
98
+ const def = Math.max(10, popupBoxWidth(c0) - 4)
99
+ const capInner = Math.min(
100
+ spec.maxWidth != null && Number.isFinite(spec.maxWidth)
101
+ ? Math.max(10, Math.floor(spec.maxWidth) - 4)
102
+ : def,
103
+ maxInner,
104
+ )
105
+ const floorInner = Math.min(
106
+ spec.minWidth != null && Number.isFinite(spec.minWidth)
107
+ ? Math.max(10, Math.floor(spec.minWidth) - 4)
108
+ : def,
109
+ capInner,
110
+ )
111
+
115
112
  let contentW = displayWidth(title)
116
113
  for (const ln of spec.body) {
117
114
  const w = displayWidth(sanitizeAnsiLine(ln))
@@ -121,21 +118,16 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
121
118
  const w = displayWidth(footer)
122
119
  if (w > contentW) contentW = w
123
120
  }
124
- const innerW = Math.min(Math.max(innerMin, contentW), innerMax)
121
+ const innerW = Math.max(10, Math.min(Math.max(contentW, floorInner), capInner, maxInner))
125
122
  const cut = (s: string) => truncateToWidth(sanitizeAnsiLine(s), innerW)
126
- // +2 border, +2 padding: "│ text │".
127
123
  const boxW = innerW + 4
128
- const row = (left: string, mid: string, right: string) => left + mid + right
124
+ const row = (l: string, m: string, r: string) => l + m + r
129
125
 
130
126
  const bar = box.h.repeat(Math.max(0, boxW - 2))
131
127
  const boxed: string[] = []
132
128
  boxed.push(row(box.tl, bar, box.tr))
133
- // Judul aksen (paritas visual dengan overlay inline); footer redup.
134
- // Judul kosong = baris judul dilewati seluruhnya (bukan baris kosong).
135
129
  if (hasTitle) boxed.push(`${box.v} ${padToWidth(c.accent(c.bold(cut(title))), innerW)} ${box.v}`)
136
- // Isi: chrome tetap = 2 border + (judul ? 1 : 0) + (footer ? 1 : 0); baris
137
- // marker ("… N more") ikut dihitung BILA terpotong. maxHeight opsional
138
- // membatasi tinggi KOTAK (bukan frame — padding backdrop menyerap sisa).
130
+
139
131
  const chromeFixed = 2 + (hasTitle ? 1 : 0) + (footer != null ? 1 : 0)
140
132
  const boxBudget =
141
133
  spec.maxHeight != null && Number.isFinite(spec.maxHeight)
@@ -144,10 +136,6 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
144
136
  const room = Math.max(0, boxBudget - chromeFixed)
145
137
  const clipped = spec.body.length > room
146
138
  const shown = clipped ? Math.max(0, room - 1) : spec.body.length
147
- // Jendela body: default dari atas, tapi bila pemanggil menandai baris fokus
148
- // (form: field aktif) jendela digeser agar baris itu terlihat. Tanpa ini
149
- // `activeRow` menunjuk baris di luar yang dirender sehingga kursor parkir di
150
- // marker/border dan ketikan user tak terlihat (audit 2026-11-12, HIGH-2).
151
139
  const focus = spec.focusRow
152
140
  const bodyStart =
153
141
  clipped && focus != null && shown > 0 && Number.isFinite(focus)
@@ -162,8 +150,6 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
162
150
  if (footer != null) boxed.push(`${box.v} ${padToWidth(c.dim(cut(footer)), innerW)} ${box.v}`)
163
151
  boxed.push(row(box.bl, bar, box.br))
164
152
 
165
- // Pusatkan horizontal; vertikal via topRow (1-based) untuk paintRegion.
166
- // displayWidth mengabaikan SGR (nol kolom) sehingga ANSI tak merusak hitungan.
167
153
  const topRow = Math.max(1, Math.floor((r0 - boxed.length) / 2) + 1)
168
154
  const lines = boxed.map((ln) => {
169
155
  const left = Math.max(0, Math.floor((c0 - displayWidth(ln)) / 2))
@@ -171,25 +157,3 @@ export function dialogBox(spec: DialogSpec, cols: number, rows: number): DialogB
171
157
  })
172
158
  return { lines, topRow, height: boxed.length, bodyTop: 1 + (hasTitle ? 1 : 0), bodyStart }
173
159
  }
174
-
175
- /**
176
- * Bangun frame SELAYAR: tepat `rows` string (backdrop redup + kotak terpusat).
177
- * Tak pernah melempar; tak menulis IO (view yang paint via screen).
178
- * Dipakai layar yang memiliki buffer sendiri (wizard first-run); popup di
179
- * atas konten App memakai dialogBox + paintRegion (tanpa clear).
180
- */
181
- export function dialogFrame(spec: DialogSpec, cols: number, rows: number): string[] {
182
- const c0 = Math.max(20, Math.floor(cols) || 80)
183
- const r0 = Math.max(5, Math.floor(rows) || 24)
184
- const box = dialogBox(spec, c0, r0)
185
- // Backdrop REDUP (bukan hitam polos): pola ░ faint memenuhi layar sehingga
186
- // kotak terbaca sebagai jendela di depan, bukan screen baru. Fallback ASCII
187
- // "." bila glyph shade tak didukung.
188
- const shade = supportsUtf8() ? "░".repeat(c0) : ".".repeat(c0)
189
- const dim = c.faint(shade)
190
- const out: string[] = []
191
- for (let i = 1; i < box.topRow; i++) out.push(dim)
192
- for (const ln of box.lines) out.push(ln)
193
- while (out.length < r0) out.push(dim)
194
- return out.slice(0, r0)
195
- }
@@ -22,7 +22,7 @@ import { sanitizeAnsiLine } from "../render/sanitize.ts"
22
22
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
23
23
  import { displayWidth, truncateToWidth } from "../render/width.ts"
24
24
  import { type AltScreen, SYNC_UPDATE_END, SYNC_UPDATE_START } from "../runtime/screen.ts"
25
- import { boxLeftPad, dialogBox } from "./dialog.ts"
25
+ import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
26
26
  import { createIdleTimer } from "./lifecycle.ts"
27
27
 
28
28
  export interface FormField {
@@ -79,8 +79,8 @@ interface FieldState {
79
79
 
80
80
  const dim = (s: string): string => c.dim(s)
81
81
 
82
- /** Lebar kotak form TETAP (keputusan rasa: geometri stabil). */
83
- const FORM_BOX_W = 64
82
+ /** Lebar kotak form: `popupBoxWidth` — paritas picker/model/provider (AUD-006). */
83
+ const formBoxWidth = (cols: number): number => popupBoxWidth(cols)
84
84
 
85
85
  function toState(def: FormField): FieldState {
86
86
  if (def.kind === "select") {
@@ -176,9 +176,9 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
176
176
  idle.reset()
177
177
  }
178
178
 
179
- // Lebar konten = lebar kotak TETAP (64) dikurangi chrome (border+padding
180
- // = 4) — sepakat dengan dialogBox min=max 64 (tanpa potong-ganda).
181
- const width = () => Math.max(20, Math.min((screen.cols || 80) - 6, FORM_BOX_W))
179
+ // Lebar konten = lebar kotak minus chrome border+padding (4).
180
+ const boxW = formBoxWidth(screen.cols || 80)
181
+ const width = () => boxW
182
182
  const innerW = () => Math.max(8, width() - 4)
183
183
 
184
184
  // Baris nilai field aktif (indeks dalam body) untuk parkir kursor.
@@ -244,10 +244,10 @@ export async function runForm(spec: FormSpec, screen: AltScreen): Promise<FormRe
244
244
  footer: idleWarned
245
245
  ? c.error(t("form.idleWarning", { s: Math.ceil(IDLE_CANCEL_MS / 1000) }))
246
246
  : (spec.footer ?? t("form.footerDefault")),
247
- // Lebar TETAP (paritas picker/manager — geometri stabil, tak
248
- // bernapas saat error muncul/hilang).
249
- minWidth: FORM_BOX_W,
250
- maxWidth: FORM_BOX_W,
247
+ // Lebar beku (paritas picker/manager — tak bernapas saat error
248
+ // muncul/hilang).
249
+ minWidth: width(),
250
+ maxWidth: width(),
251
251
  // Field aktif WAJIB terlihat: dialog menggeser jendela body bila
252
252
  // muat-tidaknya terpaksa memotong (audit 2026-11-12, HIGH-2).
253
253
  focusRow: activeRow >= 0 ? activeRow : undefined,
@@ -13,7 +13,7 @@ import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
13
13
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
14
14
  import { displayWidth, truncateToWidth } from "../render/width.ts"
15
15
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
16
- import { boxLeftPad, dialogBox } from "./dialog.ts"
16
+ import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
17
17
  import { runForm } from "./form.ts"
18
18
  import { createIdleTimer } from "./lifecycle.ts"
19
19
  import { runPicker } from "./picker.ts"
@@ -59,10 +59,8 @@ export function filterModelRows(rows: ModelRow[], q: string): ModelRow[] {
59
59
  return rows.filter((r) => r.id.toLowerCase().includes(needle))
60
60
  }
61
61
 
62
- /** Lebar kotak dialog /model: TETAP 64 kolom (keputusan rasa: geometri stabil,
63
- * tak pernah melompat mengikuti konten). Satu sumber untuk width() dan
64
- * maxWidth dialogBox — keduanya HARUS sepakat agar label tak terpotong ulang. */
65
- const MODAL_BOX_W = 64
62
+ /** Lebar kotak /model: `popupBoxWidth` (AUD-006, satu sumber width+maxWidth). */
63
+ const modalBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
66
64
 
67
65
  export async function runModelManagerView(opts: ModelManagerViewOptions): Promise<void> {
68
66
  let rows = opts.initialRows // Mode cari: ketikan apa pun langsung jadi query. Hapus = tombol Del.
@@ -99,7 +97,7 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
99
97
  // tetap dikurangi chrome dialog (border+padding = 4) agar sepakat dengan
100
98
  // dialogBox (tanpa potong ulang). innerMax dialog = cols−6, jadi konten
101
99
  // = cols−6 juga (dulu cols−4 → potong-ganda 2 kolom di terminal sempit).
102
- const width = () => Math.max(8, Math.min((process.stdout.columns || 80) - 6, MODAL_BOX_W - 4))
100
+ const width = () => Math.max(8, modalBoxWidth() - 4)
103
101
 
104
102
  // Isi MINIMAL dialog /model (tanpa judul/footer/hitungan/penanda —
105
103
  // seleksi murni warna). Search selalu tampil, daftar tanpa `›`.
@@ -150,14 +148,13 @@ export async function runModelManagerView(opts: ModelManagerViewOptions): Promis
150
148
  }
151
149
 
152
150
  const render = () => {
153
- // Popup komposit: HANYA region kotak (tanpa clear) di atas transkrip
154
- // App. Lebar TETAP 64 (min=max) — tak pernah melompat mengikuti konten.
151
+ // Region kotak di atas transkrip; lebar beku (min=max).
155
152
  const box = dialogBox(
156
153
  {
157
154
  title: "",
158
155
  body: bodyLinesModal(),
159
- minWidth: MODAL_BOX_W,
160
- maxWidth: MODAL_BOX_W,
156
+ minWidth: modalBoxWidth(),
157
+ maxWidth: modalBoxWidth(),
161
158
  maxHeight: 14,
162
159
  },
163
160
  screen.cols,
@@ -14,7 +14,7 @@ import { c, stripAnsi } from "../render/theme.ts"
14
14
  import { displayWidth, truncateToWidth } from "../render/width.ts"
15
15
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
16
16
  import { beginInteractiveScreen } from "../runtime/statusline.ts"
17
- import { boxLeftPad, dialogBox } from "./dialog.ts"
17
+ import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
18
18
  import { createIdleTimer } from "./lifecycle.ts"
19
19
 
20
20
  export interface PickerItem {
@@ -33,9 +33,6 @@ export interface PickerOptions {
33
33
 
34
34
  const dim = (s: string): string => c.dim(s)
35
35
 
36
- /** Lebar kotak popup picker TETAP (keputusan rasa: geometri stabil). */
37
- const PICKER_BOX_W = 64
38
-
39
36
  // Tandai substring query di label agar user tahu KENAPA item cocok.
40
37
  // Operasi pada teks plain (sebelum truncate) — SGR bold nol kolom.
41
38
  function highlightMatch(label: string, query: string): string {
@@ -72,6 +69,8 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
72
69
  let scroll = 0
73
70
  let filter = ""
74
71
  const isFilterable = opts.filterable ?? false
72
+ // Lebar dibekukan saat mount (AUD-006).
73
+ const boxWidth = popupBoxWidth(process.stdout.columns || 80)
75
74
 
76
75
  const filteredItems = (): PickerItem[] => {
77
76
  if (!isFilterable || !filter) return opts.items
@@ -95,11 +94,9 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
95
94
  const chrome = isFilterable ? 4 : 3
96
95
  return Math.max(1, Math.min(rows - chrome, 12))
97
96
  }
98
- // Lebar konten = lebar kotak TETAP (min=max, keputusan rasa: geometri
99
- // stabil, tak bernapas saat filter) dikurangi chrome dialog
97
+ // Lebar konten = lebar kotak (dibekukan saat mount) dikurangi chrome dialog
100
98
  // (border+padding = 4 kolom) agar dialogBox tak memotong ulang label.
101
- const width = () =>
102
- Math.max(8, Math.min((process.stdout.columns || 80) - 2 - 4, PICKER_BOX_W - 4))
99
+ const width = () => Math.max(8, boxWidth - 4)
103
100
 
104
101
  // Isi untuk dialog popup (tanpa judul; hint aksi satu baris di dasar).
105
102
  const bodyLines = (): string[] => {
@@ -152,13 +149,13 @@ export async function runPicker(opts: PickerOptions): Promise<void> {
152
149
  const render = () => {
153
150
  // Popup komposit: HANYA region kotak yang dilukis (tanpa clear) di atas
154
151
  // konten pemilik layar (transkrip App / alt-buffer wizard). Pemilik
155
- // me-repaint penuh saat popup tutup. Lebar TETAP 64 (min=max).
152
+ // Lebar beku (min=max): geometri tak bernapas saat filter berubah.
156
153
  const box = dialogBox(
157
154
  {
158
155
  title: "",
159
156
  body: bodyLines(),
160
- minWidth: PICKER_BOX_W,
161
- maxWidth: PICKER_BOX_W,
157
+ minWidth: boxWidth,
158
+ maxWidth: boxWidth,
162
159
  },
163
160
  screen.cols,
164
161
  screen.rows,
@@ -14,7 +14,7 @@ import { cleanUntrusted, sanitizeAnsiLine } from "../render/sanitize.ts"
14
14
  import { c, glyphs, stripAnsi } from "../render/theme.ts"
15
15
  import { truncateToWidth } from "../render/width.ts"
16
16
  import { type AltScreen, openAltScreen } from "../runtime/screen.ts"
17
- import { boxLeftPad, dialogBox } from "./dialog.ts"
17
+ import { boxLeftPad, dialogBox, popupBoxWidth } from "./dialog.ts"
18
18
  import { runForm, validateRequired, validateUrl } from "./form.ts"
19
19
  import { createIdleTimer } from "./lifecycle.ts"
20
20
  import { runPicker } from "./picker.ts"
@@ -23,10 +23,8 @@ import { withTimeout } from "./watchdog.ts"
23
23
  const dim = (s: string): string => c.dim(s)
24
24
 
25
25
  /** Lebar tetap popup provider setelah daftar diringkas ke nama provider. */
26
- /** Lebar kotak dialog /providers: TETAP 64 kolom — paritas picker/model/wizard
27
- * (audit B3: 52 terlalu sempit; nama provider/ID panjang + baris hint aksi
28
- * terpotong). Geometri tetap (min=max), tak pernah melompat mengikuti konten. */
29
- const PROVIDER_BOX_W = 64
26
+ /** Lebar kotak /providers: `popupBoxWidth` — paritas picker/model/form (AUD-006). */
27
+ const providerBoxWidth = (): number => popupBoxWidth(process.stdout.columns || 80)
30
28
 
31
29
  export interface ProviderRow {
32
30
  id: string
@@ -102,10 +100,9 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
102
100
  const fixed = 3 + (notice ? 1 : 0)
103
101
  return Math.max(1, Math.min(rows - fixed, 14))
104
102
  }
105
- // Lebar konten = lebar kotak TETAP (min=max, paritas picker/model) —
106
- // dikurangi chrome dialog (lihat picker.ts).
107
- const width = () =>
108
- Math.max(8, Math.min((process.stdout.columns || 80) - 2 - 4, PROVIDER_BOX_W - 4))
103
+ // Lebar konten = lebar kotak (dibekukan saat mount) dikurangi chrome
104
+ // dialog (lihat picker.ts).
105
+ const width = () => Math.max(8, providerBoxWidth() - 4)
109
106
 
110
107
  // Isi popup ringkas: nama provider dan hasil aksi sementara.
111
108
  const bodyLines = (): string[] => {
@@ -151,14 +148,13 @@ export async function runProviderManagerView(opts: ProviderManagerViewOptions):
151
148
 
152
149
  const render = () => {
153
150
  // Popup komposit: HANYA region kotak (tanpa clear) di atas konten
154
- // pemilik layar. Lebar TETAP 64 (min=max, paritas picker/model) —
155
- // tak pernah melompat mengikuti konten.
151
+ // Lebar beku (min=max, paritas picker/model).
156
152
  const box = dialogBox(
157
153
  {
158
154
  title: "",
159
155
  body: bodyLines(),
160
- minWidth: PROVIDER_BOX_W,
161
- maxWidth: PROVIDER_BOX_W,
156
+ minWidth: providerBoxWidth(),
157
+ maxWidth: providerBoxWidth(),
162
158
  },
163
159
  screen.cols,
164
160
  screen.rows,
package/src/ui/tui/app.ts CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  import { appendWrapped, shaveWrapped } from "../render/composer-wrap.ts"
27
27
  import { formatError } from "../render/errors.ts"
28
28
  import { sanitizeAnsi, sanitizeAnsiLine, stripSgr } from "../render/sanitize.ts"
29
- import { c } from "../render/theme.ts"
29
+ import { c, scrimMode, scrimSgr } from "../render/theme.ts"
30
30
  import { chunkByWidth, displayWidth, escapeLength, truncateToWidth } from "../render/width.ts"
31
31
  import { motionReduced } from "../runtime/motion.ts"
32
32
  import { type AltScreen, forceRestoreScreenForSignal, openAltScreen } from "../runtime/screen.ts"
@@ -79,6 +79,8 @@ const PROMPT_FIRST = "minicode › "
79
79
  const PROMPT_CONT = " · "
80
80
  const TIMER_TEXT = "00.00.00"
81
81
  const DOT_INTERVAL_MS = 200
82
+ /** Badge job background berputar lebih pelan dari dots (tidak berkedip). */
83
+ const WAITING_INTERVAL_MS = 400
82
84
  const DOT_PHASES = ["...", "..", ".", ".."] as const
83
85
  const MOUSE_DRAG_ON = "\x1b[?1002h\x1b[?1006h"
84
86
  const MOUSE_WHEEL_ON = "\x1b[?1000h\x1b[?1006h"
@@ -241,6 +243,10 @@ export class TuiApp {
241
243
  private thinkingActive = false
242
244
  private turnStartedAt = 0
243
245
  private activityTimer: ReturnType<typeof setTimeout> | undefined
246
+ // Clock badge job background: TERPISAH dari activityTimer karena job hidup
247
+ // justru saat turn IDLE (activityTimer hanya jalan saat busy).
248
+ private waitingTimer: ReturnType<typeof setTimeout> | undefined
249
+ private waitingStartedAt = 0
244
250
  /** Timestamp abort terakhir (ms) — deteksi double-tap Esc = quit. */
245
251
  private lastAbortAt = 0
246
252
  /** Hint "tekan lagi untuk keluar" tampil sekali setelah abort pertama. */
@@ -527,6 +533,7 @@ export class TuiApp {
527
533
  this.repaintTimer = undefined
528
534
  }
529
535
  this.stopActivityClock()
536
+ this.stopWaitingClock()
530
537
  this.stopAutoScroll()
531
538
  for (const unsubscribe of this.busUnsubs.splice(0)) {
532
539
  try {
@@ -923,6 +930,7 @@ export class TuiApp {
923
930
  this.host.abort()
924
931
  } catch {}
925
932
  this.stopActivityClock()
933
+ this.stopWaitingClock()
926
934
  this.quitRequested = true
927
935
  this.finish?.()
928
936
  }
@@ -1028,18 +1036,22 @@ export class TuiApp {
1028
1036
  }
1029
1037
 
1030
1038
  /**
1031
- * Bungkus baris dengan mode redup (\x1b[2m) untuk backdrop popup.
1032
- * Reset (\x1b[0m atau \x1b[22m) dan bold (\x1b[1m) di dalam teks dinetralkan
1033
- * agar peredupan tidak bocor di tengah baris yang diwarnai.
1039
+ * Bungkus baris dengan scrim latar netral bila tersedia. Reset SGR dalam
1040
+ * konten dipulihkan ke keadaan scrim agar warna teks tak mematikan backdrop.
1034
1041
  */
1035
1042
  static applyBackdropDim(ln: string): string {
1036
1043
  if (!ln) return ""
1044
+ const mode = scrimMode()
1045
+ if (mode === "none") return ln
1037
1046
  const esc = String.fromCharCode(27)
1038
- let s = ln.replaceAll(`${esc}[1m`, "")
1039
- s = s.replaceAll(`${esc}[22m`, `${esc}[2m`)
1040
- s = s.replaceAll(`${esc}[0m`, `${esc}[0m${esc}[2m`)
1041
- s = s.replaceAll(`${esc}[m`, `${esc}[0m${esc}[2m`)
1042
- return `${esc}[2m${s}${esc}[22m${esc}[0m`
1047
+ const scrim = scrimSgr(mode)
1048
+ // Bold DIPETAKAN ke scrim (bukan dibuang) dan `[22m` memulihkan scrim,
1049
+ // bukan meninggalkan teks normal (AUD-003).
1050
+ let s = ln.replaceAll(`${esc}[1m`, scrim)
1051
+ s = s.replaceAll(`${esc}[22m`, `${esc}[22m${scrim}`)
1052
+ s = s.replaceAll(`${esc}[0m`, `${esc}[0m${scrim}`)
1053
+ s = s.replaceAll(`${esc}[m`, `${esc}[0m${scrim}`)
1054
+ return `${scrim}${s}${esc}[22m${esc}[0m`
1043
1055
  }
1044
1056
 
1045
1057
  /** Layar redup sebagai backdrop popup: frame normal dibungkus faint. */
@@ -1221,6 +1233,46 @@ export class TuiApp {
1221
1233
  }
1222
1234
  }
1223
1235
 
1236
+ // Clock badge job background: berjalan selama ada job hidup, termasuk saat
1237
+ // turn idle (justru saat itulah job biasanya selesai).
1238
+ private startWaitingClock(): void {
1239
+ if (this.waitingTimer !== undefined || this.quitRequested) return
1240
+ if (!this.waitingStartedAt) this.waitingStartedAt = Date.now()
1241
+ const tick = () => {
1242
+ this.waitingTimer = undefined
1243
+ if (this.quitRequested) return
1244
+ if (!this.hasBackgroundJobs()) {
1245
+ this.waitingStartedAt = 0
1246
+ return
1247
+ }
1248
+ if (this.suspended === 0 && !this.released) this.paintCurrent()
1249
+ if (this.quitRequested) return
1250
+ this.startWaitingClock()
1251
+ }
1252
+ this.waitingTimer = setTimeout(tick, WAITING_INTERVAL_MS)
1253
+ try {
1254
+ ;(this.waitingTimer as unknown as { unref?: () => void }).unref?.()
1255
+ } catch {}
1256
+ }
1257
+
1258
+ private stopWaitingClock(): void {
1259
+ if (this.waitingTimer !== undefined) {
1260
+ clearTimeout(this.waitingTimer)
1261
+ this.waitingTimer = undefined
1262
+ }
1263
+ this.waitingStartedAt = 0
1264
+ }
1265
+
1266
+ /** Jumlah job hidup dari snapshot host (0 bila host tak melaporkan). */
1267
+ private hasBackgroundJobs(): boolean {
1268
+ try {
1269
+ const jobs = this.host.getStatus().footer.backgroundJobs ?? 0
1270
+ return jobs >= 1
1271
+ } catch {
1272
+ return false
1273
+ }
1274
+ }
1275
+
1224
1276
  private activityStatus(snap: TuiStatusSnapshot): string {
1225
1277
  const activity = snap.pinnedActivity
1226
1278
  if (!activity) return ""
@@ -1299,6 +1351,27 @@ export class TuiApp {
1299
1351
  if (!this.quitRequested && this.suspended === 0) this.paintCurrent()
1300
1352
  }
1301
1353
 
1354
+ // Titik masuk popup komposit (approval/ask_user): lukis kotak di atas
1355
+ // transkrip yang sudah redup. Geometri milik currentScreen.
1356
+ paintRegion(lines: string[], topRow: number): void {
1357
+ if (!this.currentScreen || this.quitRequested) return
1358
+ try {
1359
+ this.currentScreen.paintRegion(lines, topRow)
1360
+ } catch (error) {
1361
+ this.stopAfterRuntimeError(error)
1362
+ }
1363
+ }
1364
+
1365
+ /** Hapus region popup (pasangan paintRegion); App akan repaint penuh saat resume. */
1366
+ clearRegion(): void {
1367
+ if (!this.currentScreen) return
1368
+ try {
1369
+ this.currentScreen.clearRegion()
1370
+ } catch (error) {
1371
+ this.stopAfterRuntimeError(error)
1372
+ }
1373
+ }
1374
+
1302
1375
  private viewportHeight(rows: number, cols: number): number {
1303
1376
  const busy = this.isBusy()
1304
1377
  const inputH = this.composerHeight(cols, busy)
@@ -1654,28 +1727,41 @@ export class TuiApp {
1654
1727
  this.thinkingActive = false
1655
1728
  this.turnStartedAt = 0
1656
1729
  }
1730
+ // Badge hidup saat busy DAN idle; clock-nya terpisah dari activity.
1731
+ const backgroundJobs = snap.footer.backgroundJobs ?? 0
1732
+ if (backgroundJobs >= 1) this.startWaitingClock()
1733
+ else this.stopWaitingClock()
1657
1734
  const newCount = this.scrollBack > 0 ? this.transcript.total() - this.scrollBase : 0
1658
1735
  // Baris indikator WAJIB dipotong ke lebar frame seperti baris lain: teks
1659
1736
  // locale id lebih panjang dari terminal sempit (51 kolom untuk abort hint),
1660
1737
  // dan baris lebih lebar dari `cols` membungkus sendiri → frame jadi
1661
1738
  // `rows+1`, alt-screen scroll, seluruh diff CUP meleset (audit 2026-11-12,
1662
1739
  // HIGH-3).
1663
- const indicator: string[] = []
1664
- if (busy && this.abortHintOn)
1665
- indicator.push(c.warning(truncateToWidth(t("app.abortHint"), width)))
1666
- else if (newCount > 0)
1667
- indicator.push(c.muted(truncateToWidth(t("app.newBelow", { n: newCount }), width)))
1740
+ // Indikator status (abort hint / "N baris di bawah") TIDAK memakai baris
1741
+ // frame sendiri: ia MENGGANTIKAN isi baris footer selama aktif (lihat
1742
+ // `frame` di bawah). Dua alasan:
1743
+ // (a) tinggi frame tidak bergantung status. Dulu baris indikator
1744
+ // menambah/mengurangi satu baris, dan karena `viewH` memilih jendela
1745
+ // transkrip, seluruh isi layar bergeser di antara frame — gejala
1746
+ // "teks naik-turun";
1747
+ // (b) tidak memakan satu baris transkrip permanen demi pesan sementara.
1748
+ const indicatorLine =
1749
+ busy && this.abortHintOn
1750
+ ? c.warning(truncateToWidth(t("app.abortHint"), width))
1751
+ : newCount > 0
1752
+ ? c.muted(truncateToWidth(t("app.newBelow", { n: newCount }), width))
1753
+ : ""
1668
1754
 
1669
1755
  const allMenu = this.menuRows(height, width, busy)
1670
1756
  const allComposer = this.composerRows(width, snap, busy, now)
1671
- const contentBudget = Math.max(1, height - 3 - indicator.length)
1757
+ const contentBudget = Math.max(1, height - 3)
1672
1758
  let menu = allMenu
1673
1759
  let composerH = Math.min(MAX_INPUT_ROWS, Math.max(1, allComposer.length))
1674
1760
  if (menu.length + composerH > contentBudget) {
1675
1761
  menu = menu.slice(0, Math.max(0, contentBudget - 1))
1676
1762
  composerH = Math.max(1, contentBudget - menu.length)
1677
1763
  }
1678
- const viewH = Math.max(1, height - 2 - composerH - menu.length - indicator.length)
1764
+ const viewH = Math.max(1, height - 2 - composerH - menu.length)
1679
1765
  let viewport = this.transcript.viewport(width, viewH, this.scrollBack)
1680
1766
  const curWrapped = viewport.totalRows
1681
1767
  if (this.scrollBack > 0 && this.lastWrapped > 0) {
@@ -1713,11 +1799,11 @@ export class TuiApp {
1713
1799
  const winStart = Math.max(0, Math.min(allComposer.length - composerH, cursor.visIdx))
1714
1800
  composerOffset = winStart
1715
1801
  shownComposer = allComposer.slice(winStart, winStart + composerH)
1716
- cursorRow = viewH + menu.length + indicator.length + (cursor.visIdx - winStart) + 1
1802
+ cursorRow = viewH + menu.length + (cursor.visIdx - winStart) + 1
1717
1803
  cursorCol = cursor.col
1718
1804
  } else {
1719
1805
  shownComposer = allComposer.slice(0, composerH)
1720
- cursorRow = viewH + menu.length + indicator.length + 1
1806
+ cursorRow = viewH + menu.length + 1
1721
1807
  // Kursor parkir tepat setelah prompt saat idle (bukan kolom 1) supaya
1722
1808
  // caret terlihat di tempat user akan mengetik.
1723
1809
  if (!busy) cursorCol = displayWidth(PROMPT_FIRST) + 1
@@ -1736,10 +1822,22 @@ export class TuiApp {
1736
1822
  timer,
1737
1823
  timerActive: busy,
1738
1824
  timerHighlight: timerHighlight(elapsed),
1825
+ // Frame badge dihitung dari clock badge sendiri (waitingStartedAt),
1826
+ // bukan dari turn: job background berputar juga saat idle.
1827
+ backgroundFrame:
1828
+ backgroundJobs >= 1 && !motionReduced()
1829
+ ? Math.floor((now - (this.waitingStartedAt || now)) / WAITING_INTERVAL_MS)
1830
+ : 0,
1739
1831
  },
1740
1832
  width,
1741
1833
  )[0] ?? ""
1742
- const frame = [...body, ...menu, ...indicator, ...shownComposer, "", footer]
1834
+ const frame = [
1835
+ ...body,
1836
+ ...menu,
1837
+ ...shownComposer,
1838
+ "",
1839
+ indicatorLine ? truncateToWidth(indicatorLine, width) : footer,
1840
+ ]
1743
1841
  const rawLength = frame.length
1744
1842
  const crop = Math.max(0, rawLength - height)
1745
1843
  const topPad = Math.max(0, height - rawLength)
@@ -1753,7 +1851,7 @@ export class TuiApp {
1753
1851
  },
1754
1852
  transcriptRows: bodyRows,
1755
1853
  transcriptTop: topPad - crop,
1756
- composerTop: topPad - crop + body.length + menu.length + indicator.length,
1854
+ composerTop: topPad - crop + body.length + menu.length,
1757
1855
  composerLines: allComposer,
1758
1856
  composerOffset,
1759
1857
  }