minicode-ai 0.30.0 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/tui.ts +3 -4
- package/docs/TERMINAL_CONTRACT.md +23 -16
- package/docs/UI_RENDER_PIPELINE.md +3 -3
- package/docs/environment.md +1 -1
- package/package.json +1 -1
- package/src/app/session.ts +176 -51
- package/src/ui/assistant/simple.ts +25 -19
- package/src/ui/i18n/en.ts +0 -3
- package/src/ui/i18n/id.ts +0 -3
- package/src/ui/render/logo.ts +15 -18
- package/src/ui/render/markdown-layout.ts +293 -0
- package/src/ui/render/markdown.ts +36 -44
- package/src/ui/render/session-summary.ts +1 -1
- package/src/ui/render/table-grid.ts +16 -7
- package/src/ui/render/width.ts +71 -18
- package/src/ui/render/wrap.ts +39 -22
- package/src/ui/session-state.ts +4 -4
- package/src/ui/tui/app.ts +15 -36
- package/src/ui/tui/transcript.ts +107 -50
package/cli/tui.ts
CHANGED
|
@@ -419,7 +419,7 @@ export async function runTui(ctx: CliSession): Promise<void> {
|
|
|
419
419
|
return all.filter((t) => t.startsWith(line))
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
// Tab: cycle WorkMode (DISCUSS
|
|
422
|
+
// Tab: cycle WorkMode (DISCUSS ↔ BUILD). Hanya command ini
|
|
423
423
|
// (beserta /work-mode) yang menggeser operating mode — TIDAK permission mode.
|
|
424
424
|
const cycleWorkMode = (dir: 1 | -1): void => {
|
|
425
425
|
if (!workModeControl) return // policy terinjeksi = tanpa kontrol (fail-closed)
|
|
@@ -710,9 +710,8 @@ export async function runTui(ctx: CliSession): Promise<void> {
|
|
|
710
710
|
} else {
|
|
711
711
|
togglePermissionMode()
|
|
712
712
|
}
|
|
713
|
-
|
|
713
|
+
app.repaint()
|
|
714
714
|
transcript.pushInfo([c.muted(t("tui.modeLine", { m: mode }))])
|
|
715
|
-
if (modeLabel) app.showToast(t("tui.modeLine", { m: modeLabel }))
|
|
716
715
|
return
|
|
717
716
|
}
|
|
718
717
|
// [mode-architecture] /work-mode = WorkMode (operating mode) SAJA.
|
|
@@ -739,8 +738,8 @@ export async function runTui(ctx: CliSession): Promise<void> {
|
|
|
739
738
|
}
|
|
740
739
|
workModeControl.setWorkMode(next)
|
|
741
740
|
const label = displayWorkMode(next)
|
|
741
|
+
app.repaint()
|
|
742
742
|
transcript.pushInfo([c.muted(t("tui.workModeLine", { m: label }))])
|
|
743
|
-
app.showToast(t("tui.workModeLine", { m: label }))
|
|
744
743
|
return
|
|
745
744
|
}
|
|
746
745
|
// /unrestric — full akses tanpa gerbang (jail + bash-guard + sandbox/allowlist).
|
|
@@ -18,9 +18,10 @@ Perubahan v7.19 (remediasi audit & ergonomi UX):
|
|
|
18
18
|
meski pesan notice membungkus; form men-stack label panjang di atas baris
|
|
19
19
|
input agar lebar field minimal tetap terjaga, dan menyaring byte kontrol C1
|
|
20
20
|
(`\u0080–\u009f`); wizard menjaga pesan error sampai user menekan Enter/Esc.
|
|
21
|
-
4. **Zero-state, ritme transkrip, seleksi akurat, & ASCII konsisten.**
|
|
22
|
-
Saat transkrip kosong dan idle,
|
|
23
|
-
|
|
21
|
+
4. **Zero-state clean (logo kecil pojok kiri atas), ritme transkrip, seleksi akurat, & ASCII konsisten.**
|
|
22
|
+
Saat transkrip kosong dan idle, hanya logo kecil minicode (`14×9` half-block)
|
|
23
|
+
tampil di pojok kiri atas tanpa teks identitas/hint di atas prompt & footer,
|
|
24
|
+
dan tanpa menambah baris frame atau mengubah baris spacer. Transkrip
|
|
24
25
|
menambahkan jeda antar-turn sebelum `pushUser`, header bahasa redup pada
|
|
25
26
|
pembuka code fence berbahasa, serta pemetaan `displayStart` dan teks inline
|
|
26
27
|
untuk akurasi `pointAt`/`columnAtOffset`. `Shift+Enter`/`Alt+Enter` modern
|
|
@@ -307,7 +308,7 @@ proteksi").
|
|
|
307
308
|
| Stream | Isi | Catatan |
|
|
308
309
|
|---|---|---|
|
|
309
310
|
| stdout | Permanent output pada non-interaktif; frame TUI saat sesi interaktif | `App` satu-satunya pemilik frame interaktif; machine output tetap murni |
|
|
310
|
-
| stderr | Human-facing progress/diagnostic: ledger tool (`› …` hijau/merah), reasoning (default
|
|
311
|
+
| stderr | Human-facing progress/diagnostic: ledger tool (`› …` hijau/merah), reasoning (default tersembunyi/minimized; `MINICODE_SHOW_THINKING=1` atau `/thinking` / `Ctrl+T` / `--verbose` menampilkan), warning, error | Boleh transient rendering bila stderr TTY |
|
|
311
312
|
| keduanya | Warna hanya bila stream TTY (`stdout.isTTY`); `NO_COLOR` menang; TERM/COLORTERM env TIDAK menyalakan warna pada pipe/redirect | Lihat `src/ui/render/theme.ts` `colorLevel()` |
|
|
312
313
|
|
|
313
314
|
Non-TTY (pipe/redirect/CI/file): **0 cursor control, 0 alternate screen,
|
|
@@ -588,16 +589,19 @@ Non-TTY (pipe/redirect/CI/file): **0 cursor control, 0 alternate screen,
|
|
|
588
589
|
di footer form ("batal dalam 10 dtk" — bukan countdown hidup), 10 dtk
|
|
589
590
|
berikutnya = auto-batal (cancel), total semantik 90 dtk lama; SATU
|
|
590
591
|
ketikan apa pun me-reset kedua timer.
|
|
591
|
-
22. Thinking
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
592
|
+
22. Thinking tersembunyi SECARA DEFAULT (hidden/minimized) agar transkrip
|
|
593
|
+
tetap bersih: composer tetap memakai dots clock saat thinking dan detail
|
|
594
|
+
penuh disimpan ke buffer `/expand`. User dapat membukanya kapan saja lewat
|
|
595
|
+
`/thinking`, `Ctrl+T`, `--verbose`, atau `MINICODE_SHOW_THINKING=1`: saat
|
|
596
|
+
dibuka dengan panel aktivitas ON (default TUI; `/fold`), transkrip
|
|
597
|
+
menampilkan AREA thinking = blok live maks 10 baris visual terakhir
|
|
598
|
+
(header `+ thinking`, penanda `… N baris lagi`), lalu saat fase berakhir
|
|
599
|
+
diringkas SATU baris (`+ thinking · N baris`); dengan panel OFF,
|
|
600
|
+
perilaku legacy = alir thinking ber-warna terbaca (`c.thinking`,
|
|
597
601
|
abu-kebiruan) dan ber-indentasi 2 kolom, dipisah SATU baris kosong dari
|
|
598
|
-
jawaban/ledger — bukan `dim`;
|
|
599
|
-
|
|
600
|
-
|
|
602
|
+
jawaban/ledger — bukan `dim`; saat tetap tersembunyi di TUI, transkrip
|
|
603
|
+
bersih tanpa marker (`… thinking`); fase berakhir = commit (tak ada
|
|
604
|
+
thinking yatim).
|
|
601
605
|
23. Approval & ask_user tercatat di transkrip (pertanyaan + keputusan) dan
|
|
602
606
|
terlihat sebelum menjawab; non-TTY = deny/null fail-closed; stdout
|
|
603
607
|
di-pipe tanpa sink TUI = deny/null (prompt tak terlihat + mencemari
|
|
@@ -761,7 +765,7 @@ Non-TTY (pipe/redirect/CI/file): **0 cursor control, 0 alternate screen,
|
|
|
761
765
|
|
|
762
766
|
prompt `minicode ›` tampil saat boot/idle dan hilang saat busy (dropdown `/`
|
|
763
767
|
berbingkai di atasnya; `Tab` melengkapi command terpilih saat terbuka, dan
|
|
764
|
-
memutar WorkMode saat tertutup) ·
|
|
768
|
+
memutar WorkMode saat tertutup) · logo kecil minicode di pojok kiri atas saat transkrip kosong/idle ·
|
|
765
769
|
status bar `✦ 00.00.00 Discuss model cwd … context Auto ●`
|
|
766
770
|
(timer redup idle; detik putih aktif, menit mulai terang di 60 dtk, jam di 1
|
|
767
771
|
jam; tanpa bullet separator; permission rata kanan dekat token konteks; label
|
|
@@ -781,7 +785,10 @@ command di atas chat (v7.18) ·
|
|
|
781
785
|
baris ledger per-tool dirangkum jadi SATU baris ringkas (`n tools · nama · x ok · y gagal`),
|
|
782
786
|
tidak hilang diam-diam; detail dibuka via `/expand` ·
|
|
783
787
|
tabel markdown dirender kotak ber-garis (opencode-like) ber-`wrap` (konten panjang
|
|
784
|
-
tidak kepotong) + margin kiri
|
|
788
|
+
tidak kepotong) + margin kiri 3 kolom (adaptif di lebar < 36); area teks jawaban
|
|
789
|
+
(paragraf, heading, daftar, blockquote, code block) ber-margin kiri 3 kolom
|
|
790
|
+
dengan hanging-indent wrap untuk daftar/paragraf multi-tingkat agar lanjutan teks
|
|
791
|
+
tidak melewati batas kiri tingkatnya serta jeda baris kosong antar-poin/heading/blok ·
|
|
785
792
|
Projection V2: `› name target … running`, ledger status ber-warna/kata,
|
|
786
793
|
retry/grup anak (anak ber-identitas run = baris `↳ run_<8>` sendiri; tanpa
|
|
787
794
|
identitas run = hitungan `n child tools`), ringkasan turn, dan marker evict
|
|
@@ -835,7 +842,7 @@ panjang).
|
|
|
835
842
|
counter posisi di judul, sembunyikan hint scroll bila pas 1 layar, salin isi
|
|
836
843
|
dengan `c` lewat `onCopy`, Esc menutup, non-TTY fallback false, lebar outputWindowWidth).
|
|
837
844
|
- `test/tui-app.test.ts` — I1/I13/I14/I17-I20 (baris indikator dipotong ke
|
|
838
|
-
lebar frame walau locale id 51 kolom;
|
|
845
|
+
lebar frame walau locale id 51 kolom; logo kecil pojok kiri atas saat boot kosong tanpa teks welcome;
|
|
839
846
|
`Tab` autolengkap dropdown `/` vs putar WorkMode saat menu tertutup; klik pada
|
|
840
847
|
baris composer kedua hasil wrap; prompt idle bertahan setelah Esc;
|
|
841
848
|
`repaint()` tak melukis saat suspended; boot/exit pairing, transcript
|
|
@@ -102,7 +102,7 @@ tanpa IO) digerakkan `cli/` (`tui.ts`, `commands.ts`, `wizard.ts`,
|
|
|
102
102
|
resize, counter judul, scroll wheel/`j`/`k`/`Space`, dan salin `c` opsional); jendela
|
|
103
103
|
interaktif command (`/model`, `/provider`, `/sessions`, picker) berbagi
|
|
104
104
|
`dialogBox`/`hintLine` (dan `listRow` untuk daftar) yang sama serta mendukung scroll mouse
|
|
105
|
-
wheel. TUI fullscreen menampilkan
|
|
105
|
+
wheel. TUI fullscreen menampilkan logo kecil minicode di pojok kiri atas saat transkrip kosong/idle (tanpa identitas/hint di atas prompt),
|
|
106
106
|
`Tab` pada dropdown `/` untuk autocomplete, jeda antar-turn dan label bahasa fence redup,
|
|
107
107
|
serta fallback glyph `MINICODE_ASCII=1` konsisten hingga garis tabel dan ellipsis.
|
|
108
108
|
|
|
@@ -113,10 +113,10 @@ I = bisa diinterupsi, L = bisa tiba setelah completion.
|
|
|
113
113
|
|
|
114
114
|
| Event | Producer | Representasi UI | S | D | O | I | L |
|
|
115
115
|
|---|---|---|---|---|---|---|---|
|
|
116
|
-
| assistant text | provider stream | stdout wrap + fence
|
|
116
|
+
| assistant text | provider stream | stdout/TUI wrap ber-indentasi gantung (margin kiri 3 kolom adaptif, jeda antar-poin/heading/blok) + code fence 3-spasi; pipe-table-aligned di TTY, source sanitized di non-TTY | ya | tidak (E1) | tidak | ya (abort) | tidak (detach flush 1x, E6) |
|
|
117
117
|
| tool call | model → kernel | `› nama target` muted (compact: diam) | tidak | tidak | tidak | ya | tidak |
|
|
118
118
|
| tool result | tool → executor | ledger hijau/merah; minimize → `+ label` + buffer; panel aktivitas ON → baris grup per keluarga tool (`+ explore · N tools · N ok`) | tidak | tidak | tidak | ya | tidak |
|
|
119
|
-
| reasoning | provider extension | TUI composer
|
|
119
|
+
| reasoning | provider extension | default tersembunyi (TUI composer tetap dots clock, isi disimpan ke `/expand`); bila dibuka (`/thinking` / `Ctrl+T` / `MINICODE_SHOW_THINKING=1` / `--verbose`), panel aktivitas ON → AREA thinking live maks 10 baris (`+ thinking`, ringkas 1 baris saat turn selesai); panel OFF → alir per baris | ya | tidak | tidak | ya | tidak |
|
|
120
120
|
| thinking effort | picker `/model` | badge + level per model | tidak | tidak | tidak | tidak | tidak |
|
|
121
121
|
| usage | provider extension | verbose saja; masuk budget watcher | ya | tidak | ya (tail pasca-finish) | ya | ya (diabaikan aman) |
|
|
122
122
|
| compaction | kernel loop | `── compacted: <reason>` kuning, reason verbatim | tidak | tidak | tidak | tidak | tidak |
|
package/docs/environment.md
CHANGED
|
@@ -90,7 +90,7 @@ Variabel yang paling menentukan perilaku (sisanya referensi di bawah):
|
|
|
90
90
|
| `MINICODE_BELL` | `0` → matikan bell `\x07` saat approval (aksesibilitas) |
|
|
91
91
|
| `MINICODE_STATUSLINE` | `rich` → statusline turn menampilkan token kumulatif + biaya sesi (default hemat) |
|
|
92
92
|
| `MINICODE_A11Y` | `1` → live-region approval untuk screen reader (baris polos tanpa ANSI) |
|
|
93
|
-
| `MINICODE_SHOW_THINKING` | reasoning model
|
|
93
|
+
| `MINICODE_SHOW_THINKING` | reasoning model tersembunyi SECARA DEFAULT (`false`); `1` → paksa terlihat (atau `/thinking` / `Ctrl+T` / `--verbose`), `0` → paksa tersembunyi |
|
|
94
94
|
| `MINICODE_MINIMIZE_ACTIVITY` | ON secara default di TUI; `0` → transparan (baris per-tool). Lipat aktivitas tool per turn jadi satu ringkasan (detail via `/expand`) |
|
|
95
95
|
| `MINICODE_ACTIVITY_PANEL` | `0` → matikan panel aktivitas (default AKTIF di TUI; `/fold` toggle); `1` → paksa aktif juga di jalur linear/one-shot |
|
|
96
96
|
| `MINICODE_AUTORESUME_BG` | `0` → nonaktifkan auto-resume turn TUI saat job background selesai (default aktif; sekali per job, hanya bila tidak ada turn berjalan) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minicode-ai",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Open-source terminal coding agent on a vendored zero-dependency MiniCore kernel — layered permissions, path jail, sandboxing, MCP/LSP, and durable shadow-git checkpoints",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
package/src/app/session.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
estimateTools,
|
|
18
18
|
safeStringify,
|
|
19
19
|
} from "#minicore/core/tokens.ts"
|
|
20
|
+
import type { Message, UserMessage } from "#minicore/core/types.ts"
|
|
20
21
|
import { LIMITS } from "../constants.ts"
|
|
21
22
|
// [Area B · PROMPT 06] Binding persetujuan ↔ operasi yang dieksekusi.
|
|
22
23
|
import { ApprovalBindingStore, verifyApprovalBinding } from "../policy/approval-binding.ts"
|
|
@@ -257,10 +258,9 @@ export type WorkModeControl = {
|
|
|
257
258
|
*
|
|
258
259
|
* DISCUSS = investigasi baca-saja yang berorientasi diskusi: model membaca,
|
|
259
260
|
* mencari, dan bernalar, lalu MENYAJIKAN temuan/opsi/trade-off untuk didiskusikan
|
|
260
|
-
* dengan user — bukan menulis atau mengeksekusi apa pun.
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* menambah apa pun (identitas).
|
|
261
|
+
* dengan user — bukan menulis atau mengeksekusi apa pun.
|
|
262
|
+
* BUILD (EXECUTE) = direktif aktif positif bahwa implementasi diizinkan dan
|
|
263
|
+
* mengabaikan pembatasan DISCUSS pada histori percakapan sebelumnya.
|
|
264
264
|
*
|
|
265
265
|
* Ini *guidance* (behavior), bukan enforcement — enforcement tetap milik ceiling
|
|
266
266
|
* handler `work-mode.ts`. Diekspor agar teruji langsung (pola repo pure/export).
|
|
@@ -268,13 +268,109 @@ export type WorkModeControl = {
|
|
|
268
268
|
export function workModeHint(workMode: WorkMode): string {
|
|
269
269
|
if (workMode === "DISCUSS") {
|
|
270
270
|
return (
|
|
271
|
-
"\n\nDISCUSS MODE: You are in read-only investigation, discussion, and planning mode. " +
|
|
271
|
+
"\n\nDISCUSS MODE (active): You are in read-only investigation, discussion, and planning mode. " +
|
|
272
272
|
"Do NOT modify files, run bash, or use write/edit tools. " +
|
|
273
273
|
"Read, search, and reason — investigate the question thoroughly, discuss findings, options, and trade-offs with the user, and produce a concrete implementation plan. " +
|
|
274
274
|
"Do not implement or execute any change."
|
|
275
275
|
)
|
|
276
276
|
}
|
|
277
|
-
return
|
|
277
|
+
return (
|
|
278
|
+
"\n\nBUILD MODE (active): Full implementation and execution tools are active. " +
|
|
279
|
+
"If earlier turns in the conversation occurred under read-only DISCUSS mode, ignore prior self-statements or plans about waiting/refusing edits — proceed directly to implement requested changes using write/edit/bash tools without asking for written confirmation unless genuine ambiguity remains."
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const PLAN_PM_HINT =
|
|
284
|
+
"\n\nPLAN MODE: You are in read-only planning mode. Do NOT modify files, run bash, or use write/edit tools. Only read, search, and reason — then output a concrete implementation plan."
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Penanda live `PermissionMode` (`Auto`, `Ask`, `Unrestricted`, dsb.) pada
|
|
288
|
+
* system prompt supaya model memahami perilaku gerbang izin & tidak meminta
|
|
289
|
+
* konfirmasi tertulis yang tidak perlu saat berganti mode.
|
|
290
|
+
*/
|
|
291
|
+
export function permissionModeHint(
|
|
292
|
+
permissionMode: PermissionMode | undefined,
|
|
293
|
+
workMode: WorkMode,
|
|
294
|
+
): string {
|
|
295
|
+
if (!permissionMode) return ""
|
|
296
|
+
switch (permissionMode) {
|
|
297
|
+
case "plan":
|
|
298
|
+
return PLAN_PM_HINT
|
|
299
|
+
case "unrestricted":
|
|
300
|
+
return workMode === "EXECUTE"
|
|
301
|
+
? "\n\nPERMISSION MODE: UNRESTRICTED (active this session). Interactive approval prompts, workspace path jail, bash-guard, and allowlist restrictions are lifted; execute tools directly without asking confirmation."
|
|
302
|
+
: "\n\nPERMISSION MODE: UNRESTRICTED (suspended in DISCUSS mode — read-only ceiling and workspace path jail stay enforced until switching to BUILD)."
|
|
303
|
+
case "ask":
|
|
304
|
+
return "\n\nPERMISSION MODE: ASK (supervised). Non-read-only mutating/execution tools require interactive approval in the UI; invoke tools directly when ready — do NOT ask the user for written confirmation in chat before calling them."
|
|
305
|
+
case "auto":
|
|
306
|
+
return "\n\nPERMISSION MODE: AUTO (autonomous within workspace safety guards). Authorized workspace tools execute without confirmation prompts (`ask_user` is unavailable); act directly."
|
|
307
|
+
case "allow-all":
|
|
308
|
+
return "\n\nPERMISSION MODE: ALLOW-ALL. Workspace tools run autonomously subject to path jail and hard security guards."
|
|
309
|
+
case "allowlist":
|
|
310
|
+
return "\n\nPERMISSION MODE: ALLOWLIST. Shell commands are restricted to the configured bash allowlist; workspace path jail and hard security guards stay active."
|
|
311
|
+
case "readonly":
|
|
312
|
+
return "\n\nPERMISSION MODE: READONLY. Only read-only workspace tools are permitted."
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface ModeSnapshot {
|
|
317
|
+
workMode: WorkMode
|
|
318
|
+
permissionMode?: PermissionMode
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const workModeLabel = (wm: WorkMode): "BUILD" | "DISCUSS" =>
|
|
322
|
+
wm === "EXECUTE" ? "BUILD" : "DISCUSS"
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Catatan transisi singkat ketika `WorkMode` atau `PermissionMode` berubah antar
|
|
326
|
+
* turn dalam sesi yang sama — disisipkan hanya di salinan wire request turn itu
|
|
327
|
+
* supaya model tidak terkecoh oleh histori turn sebelumnya saat bolak-balik mode.
|
|
328
|
+
*/
|
|
329
|
+
export function buildModeTransitionNote(prev: ModeSnapshot, curr: ModeSnapshot): string {
|
|
330
|
+
const parts: string[] = []
|
|
331
|
+
if (prev.workMode !== curr.workMode) {
|
|
332
|
+
parts.push(
|
|
333
|
+
curr.workMode === "EXECUTE"
|
|
334
|
+
? `WorkMode ${workModeLabel(prev.workMode)} -> BUILD (write/edit/bash tools NOW ENABLED; ignore prior read-only/planning statements in history and implement directly without asking written confirmation)`
|
|
335
|
+
: `WorkMode ${workModeLabel(prev.workMode)} -> DISCUSS (read-only mode NOW ACTIVE; do NOT modify files or run mutating commands)`,
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
if (prev.permissionMode !== curr.permissionMode && curr.permissionMode) {
|
|
339
|
+
const fromLabel = (prev.permissionMode ?? "auto").toUpperCase()
|
|
340
|
+
const toLabel = curr.permissionMode.toUpperCase()
|
|
341
|
+
if (curr.permissionMode === "unrestricted") {
|
|
342
|
+
parts.push(
|
|
343
|
+
curr.workMode === "EXECUTE"
|
|
344
|
+
? `PermissionMode ${fromLabel} -> UNRESTRICTED (full access active; approval prompts, jail, and bash-guard bypassed)`
|
|
345
|
+
: `PermissionMode ${fromLabel} -> UNRESTRICTED (read-only DISCUSS ceiling stays active until switching to BUILD)`,
|
|
346
|
+
)
|
|
347
|
+
} else if (curr.permissionMode === "ask") {
|
|
348
|
+
parts.push(
|
|
349
|
+
`PermissionMode ${fromLabel} -> ASK (supervised; call tools directly — approval prompt is automatic in UI)`,
|
|
350
|
+
)
|
|
351
|
+
} else {
|
|
352
|
+
parts.push(
|
|
353
|
+
`PermissionMode ${fromLabel} -> ${toLabel} (autonomous workspace execution active)`,
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return parts.length > 0 ? `[Runtime mode update: ${parts.join("; ")}]` : ""
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function annotateLastUserMessage(messages: readonly Message[], note: string): readonly Message[] {
|
|
361
|
+
if (!note) return messages
|
|
362
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
363
|
+
const msg = messages[i]
|
|
364
|
+
if (msg?.role !== "user") continue
|
|
365
|
+
const content: UserMessage["content"] =
|
|
366
|
+
typeof msg.content === "string"
|
|
367
|
+
? `${note}\n\n${msg.content}`
|
|
368
|
+
: [{ type: "text", text: `${note}\n` }, ...msg.content]
|
|
369
|
+
const next = messages.slice()
|
|
370
|
+
next[i] = { ...msg, content }
|
|
371
|
+
return next
|
|
372
|
+
}
|
|
373
|
+
return messages
|
|
278
374
|
}
|
|
279
375
|
|
|
280
376
|
export async function createMinicodeSession(
|
|
@@ -425,12 +521,10 @@ export async function createMinicodeSession(
|
|
|
425
521
|
`createMinicodeSession: workMode ${resolvedWorkMode} dengan permissionHandler terinjeksi belum didukung (fail-closed S2.1)`,
|
|
426
522
|
)
|
|
427
523
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
//
|
|
431
|
-
//
|
|
432
|
-
// pembungkus provider supaya transisi runtime `/work-mode` maupun `/mode`
|
|
433
|
-
// tercermin langsung di StreamRequest.system tanpa mengedit vendor/minicore.
|
|
524
|
+
// P0.2 (G-PROMPT-RT): rakit bagian dasar sekali, lalu tambahkan `workModeHint`
|
|
525
|
+
// + `permissionModeHint` secara LIVE per-turn lewat pembungkus provider supaya
|
|
526
|
+
// transisi runtime `/work-mode` maupun `/mode` & `/unrestric` tercermin
|
|
527
|
+
// langsung di StreamRequest.system tanpa mengedit vendor/minicore.
|
|
434
528
|
const baseSystem = await buildSystemPrompt({
|
|
435
529
|
cwd: defaultCwd,
|
|
436
530
|
extra: opts.systemExtra ?? "",
|
|
@@ -686,13 +780,19 @@ export async function createMinicodeSession(
|
|
|
686
780
|
// Teruskan mode live ke kernel agar ToolContext.permissionMode selalu
|
|
687
781
|
// mencerminkan Shift+Tab saat itu (bukan snapshot saat sesi dibuat).
|
|
688
782
|
const livePermissionMode = (): PermissionMode => (injected ? "readonly" : withMode.__getMode())
|
|
783
|
+
const liveWorkModeForSystem = (): WorkMode =>
|
|
784
|
+
injected ? resolvedWorkMode : (wmCtl.__getWorkMode?.() ?? resolvedWorkMode)
|
|
785
|
+
const livePermissionModeForSystem = (): PermissionMode | undefined =>
|
|
786
|
+
injected ? opts.permissionMode : withMode.__getMode()
|
|
787
|
+
let lastTurnMode: ModeSnapshot | null = null
|
|
788
|
+
let activeTurnTransitionNote = ""
|
|
789
|
+
let turnSentStream = false
|
|
689
790
|
const computeLiveSystem = (): string => {
|
|
690
|
-
const pm =
|
|
691
|
-
const wm =
|
|
692
|
-
const planHint = pm === "plan" ? PLAN_PM_HINT : ""
|
|
791
|
+
const pm = livePermissionModeForSystem()
|
|
792
|
+
const wm = liveWorkModeForSystem()
|
|
693
793
|
const contextWindow = contextWindowForModel(currentContextModel())
|
|
694
794
|
const capacityHint = `\n\n# Harness context capacity\nThe harness currently budgets ${contextWindow} tokens for the selected model. This is the configured/resolved session limit, not a guarantee from the provider. It is independent of the Windows operating system and shell. System instructions, tool schemas, history, and output share this budget; compaction starts before the full window is exhausted. Preserve durable task progress before compaction.`
|
|
695
|
-
return baseSystem +
|
|
795
|
+
return baseSystem + workModeHint(wm) + permissionModeHint(pm, wm) + capacityHint
|
|
696
796
|
}
|
|
697
797
|
// [CTX] Kalibrasi dipisahkan per identitas model agar berpindah ke model
|
|
698
798
|
// lain tidak membawa rasio tokenizer/provider dari sesi sebelumnya.
|
|
@@ -852,7 +952,11 @@ export async function createMinicodeSession(
|
|
|
852
952
|
return provider.models
|
|
853
953
|
},
|
|
854
954
|
async *stream(req, signal) {
|
|
955
|
+
turnSentStream = true
|
|
855
956
|
const system = computeLiveSystem()
|
|
957
|
+
const messages = activeTurnTransitionNote
|
|
958
|
+
? annotateLastUserMessage(req.messages, activeTurnTransitionNote)
|
|
959
|
+
: req.messages
|
|
856
960
|
const model = req.model ?? currentContextModel()
|
|
857
961
|
let limit = contextWindowForModel(model)
|
|
858
962
|
let maxOutputTokens = maxOutputTokensForModel(model)
|
|
@@ -866,21 +970,21 @@ export async function createMinicodeSession(
|
|
|
866
970
|
? rawTools.filter((t) => !hiddenWireTools.has(t.name))
|
|
867
971
|
: rawTools
|
|
868
972
|
const localInputTokens =
|
|
869
|
-
estimateMessages(
|
|
973
|
+
estimateMessages(messages, minicodeEstimator) +
|
|
870
974
|
estimateSystem(system, minicodeEstimator) +
|
|
871
975
|
estimateTools(tools, minicodeEstimator)
|
|
872
976
|
let inputTokens =
|
|
873
|
-
estimateMessages(
|
|
977
|
+
estimateMessages(messages, estimator) +
|
|
874
978
|
estimateSystem(system, estimator) +
|
|
875
979
|
estimateTools(tools, estimator)
|
|
876
980
|
// Anchor ukuran nyata: jangan biarkan estimasi (chars/4, bisa under-count
|
|
877
981
|
// 2–5× pada kode/JSON) jatuh di bawah input asli terakhir provider. Input
|
|
878
982
|
// hanya tumbuh antar-turn normal; bila jumlah pesan menyusut (kompaksi,
|
|
879
983
|
// rewind/checkpoint, atau clear), reset anchor agar tidak memicu overflow palsu.
|
|
880
|
-
if (
|
|
984
|
+
if (messages.length < lastRequestMessageCount) {
|
|
881
985
|
lastProviderInputTokens = undefined
|
|
882
986
|
}
|
|
883
|
-
lastRequestMessageCount =
|
|
987
|
+
lastRequestMessageCount = messages.length
|
|
884
988
|
if (lastProviderInputTokens !== undefined && lastProviderInputTokens > inputTokens) {
|
|
885
989
|
inputTokens = lastProviderInputTokens
|
|
886
990
|
}
|
|
@@ -911,7 +1015,7 @@ export async function createMinicodeSession(
|
|
|
911
1015
|
// cutoff ini palsu (inflasi kalibrasi) — bukan konteks benar-benar penuh.
|
|
912
1016
|
factor: calibration.snapshot().factor,
|
|
913
1017
|
localInputTokens: localInputTokens,
|
|
914
|
-
storeMessages:
|
|
1018
|
+
storeMessages: messages.length,
|
|
915
1019
|
},
|
|
916
1020
|
})
|
|
917
1021
|
let clientOverflowErr: ProviderError | undefined
|
|
@@ -945,6 +1049,7 @@ export async function createMinicodeSession(
|
|
|
945
1049
|
for await (const event of provider.stream(
|
|
946
1050
|
{
|
|
947
1051
|
...req,
|
|
1052
|
+
messages,
|
|
948
1053
|
system,
|
|
949
1054
|
...(hiddenWireTools && hiddenWireTools.size > 0 ? { tools } : {}),
|
|
950
1055
|
},
|
|
@@ -968,7 +1073,7 @@ export async function createMinicodeSession(
|
|
|
968
1073
|
admittedFactor = calibration.snapshot().factor
|
|
969
1074
|
inputTokens = Math.max(
|
|
970
1075
|
inputTokens,
|
|
971
|
-
estimateMessages(
|
|
1076
|
+
estimateMessages(messages, estimator) +
|
|
972
1077
|
estimateSystem(system, estimator) +
|
|
973
1078
|
estimateTools(tools, estimator),
|
|
974
1079
|
)
|
|
@@ -980,7 +1085,7 @@ export async function createMinicodeSession(
|
|
|
980
1085
|
if (currentFactor > admittedFactor) {
|
|
981
1086
|
inputTokens = Math.max(
|
|
982
1087
|
inputTokens,
|
|
983
|
-
estimateMessages(
|
|
1088
|
+
estimateMessages(messages, estimator) +
|
|
984
1089
|
estimateSystem(system, estimator) +
|
|
985
1090
|
estimateTools(tools, estimator),
|
|
986
1091
|
)
|
|
@@ -1200,35 +1305,55 @@ export async function createMinicodeSession(
|
|
|
1200
1305
|
run(input: string, runOpts?: { signal?: AbortSignal; model?: string }) {
|
|
1201
1306
|
activeContextModel = runOpts?.model ?? opts.model
|
|
1202
1307
|
const modelForRun = activeContextModel
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
escalateContextWindow(modelForRun, used, true)
|
|
1308
|
+
const startMode: ModeSnapshot = {
|
|
1309
|
+
workMode: liveWorkModeForSystem(),
|
|
1310
|
+
permissionMode: livePermissionModeForSystem(),
|
|
1311
|
+
}
|
|
1312
|
+
activeTurnTransitionNote = lastTurnMode
|
|
1313
|
+
? buildModeTransitionNote(lastTurnMode, startMode)
|
|
1314
|
+
: ""
|
|
1315
|
+
turnSentStream = false
|
|
1316
|
+
return core
|
|
1317
|
+
.run(input, runOpts)
|
|
1318
|
+
.finally(() => {
|
|
1319
|
+
if (turnSentStream) {
|
|
1320
|
+
lastTurnMode = {
|
|
1321
|
+
workMode: liveWorkModeForSystem(),
|
|
1322
|
+
permissionMode: livePermissionModeForSystem(),
|
|
1323
|
+
}
|
|
1220
1324
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1325
|
+
activeTurnTransitionNote = ""
|
|
1326
|
+
turnSentStream = false
|
|
1327
|
+
})
|
|
1328
|
+
.catch((error: unknown) => {
|
|
1329
|
+
// Kernel melaporkan kehabisan konteks sebagai `budget_exceeded` dengan
|
|
1330
|
+
// `details.reason` = `fixpoint` atau `critical`. Keduanya BUKTI
|
|
1331
|
+
// terverifikasi bahwa jendela yang dipakai terlalu kecil untuk sesi ini
|
|
1332
|
+
// — sama sahnya dengan penolakan provider. Tanpa eskalasi di sini,
|
|
1333
|
+
// sesi yang sudah di titik tetap langsung mati padahal endpoint mungkin
|
|
1334
|
+
// punya kapasitas jauh lebih besar.
|
|
1335
|
+
//
|
|
1336
|
+
// Bukan pemicu: `max_steps_exceeded`, `max_turns`, `aborted`, timeout,
|
|
1337
|
+
// dan error provider non-konteks — menaikkan jendela tak akan menolong.
|
|
1338
|
+
// (`max_steps_exceeded` punya jalurnya sendiri: eskalasi batas langkah.)
|
|
1339
|
+
if (error instanceof AgentError && error.kind === "budget_exceeded") {
|
|
1340
|
+
const reason = error.details?.reason
|
|
1341
|
+
if (reason === "fixpoint" || reason === "critical") {
|
|
1342
|
+
const used =
|
|
1343
|
+
typeof error.details?.fixedTokens === "number" ? error.details.fixedTokens : 0
|
|
1344
|
+
escalateContextWindow(modelForRun, used, true)
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
// [T-008] Turn mentok batas langkah: naik satu tangga untuk turn
|
|
1348
|
+
// berikutnya. Kerja turn ini tetap hilang (kernel sudah berhenti), tapi
|
|
1349
|
+
// turn lanjutan tidak akan menabrak dinding yang sama. Bounded: satu
|
|
1350
|
+
// langkah per kejadian, dibatasi STEP_LIMIT_CEILING.
|
|
1351
|
+
if (error instanceof AgentError && error.kind === "max_steps_exceeded") {
|
|
1352
|
+
const used = typeof error.details?.steps === "number" ? error.details.steps : 0
|
|
1353
|
+
escalateMaxSteps(used)
|
|
1354
|
+
}
|
|
1355
|
+
throw error
|
|
1356
|
+
})
|
|
1232
1357
|
},
|
|
1233
1358
|
abort() {
|
|
1234
1359
|
core.abort()
|
|
@@ -18,6 +18,7 @@ import { formatArgsPreview, formatProviderError, formatUsage } from "../render/f
|
|
|
18
18
|
import { highlightCode } from "../render/highlight.ts"
|
|
19
19
|
import { paintLedger, runMarker, statusWord } from "../render/ledger.ts"
|
|
20
20
|
import { decorateMarkdown, type FenceMatch, parseFence, renderInline } from "../render/markdown.ts"
|
|
21
|
+
import { effectiveAssistantMargin, MarkdownFlowStepper } from "../render/markdown-layout.ts"
|
|
21
22
|
import { MarkdownTableStream } from "../render/markdown-table.ts"
|
|
22
23
|
import {
|
|
23
24
|
cleanUntrusted,
|
|
@@ -236,9 +237,9 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
236
237
|
// /copy tak tersentuh (rememberTurn selalu jalan sebelum sink).
|
|
237
238
|
let answerBuf = ""
|
|
238
239
|
let answerTruncated = false
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
let
|
|
240
|
+
// State aliran markdown untuk memberi jeda bersih antar-poin, heading,
|
|
241
|
+
// blockquote, tabel, dan code fence (paritas penuh dengan TUI Transcript).
|
|
242
|
+
let answerFlow = new MarkdownFlowStepper()
|
|
242
243
|
let activeProviderAttempt: number | null = null
|
|
243
244
|
let attemptCopyText = ""
|
|
244
245
|
let attemptAnswerBuf = ""
|
|
@@ -247,6 +248,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
247
248
|
let attemptReasoningLine = ""
|
|
248
249
|
let attemptThinkState: "off" | "min" | "exp" = "off"
|
|
249
250
|
let attemptFence: FenceMatch | null = null
|
|
251
|
+
let attemptAnswerFlow = answerFlow.clone()
|
|
250
252
|
const ANSWER_BUF_MAX = 1_000_000
|
|
251
253
|
// Jawaban tak pernah disembunyikan di pipa/CI (output mesin harus utuh)
|
|
252
254
|
// dan --verbose selalu menampilkan semua.
|
|
@@ -356,28 +358,29 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
356
358
|
const flushLine = (line: string) => {
|
|
357
359
|
const w = process.stdout.columns || 80
|
|
358
360
|
const f = parseFence(line)
|
|
361
|
+
if (fence !== null) {
|
|
362
|
+
if (f && f.char === fence.char && f.len >= fence.len) {
|
|
363
|
+
fence = null
|
|
364
|
+
answerFlow.onFenceClose()
|
|
365
|
+
} else {
|
|
366
|
+
const margin = " ".repeat(effectiveAssistantMargin(w))
|
|
367
|
+
const content = fence.lang ? highlightCode(line, fence.lang) : line
|
|
368
|
+
emitAnswer(line.trim() === "" ? "\n" : `${margin}${content}\n`)
|
|
369
|
+
}
|
|
370
|
+
return
|
|
371
|
+
}
|
|
359
372
|
if (f) {
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
// Baris pembuka/penutup fence adalah delimiter — tidak dicetak.
|
|
373
|
+
if (answerFlow.onFenceOpen()) emitAnswer("\n")
|
|
374
|
+
fence = f
|
|
363
375
|
return
|
|
364
376
|
}
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
// bahasa. Tanpa bahasa, tetap apa adanya (perbaikan V8: fence tanpa
|
|
368
|
-
// bahasa tidak boleh kehilangan *value* karena dianggap italic).
|
|
369
|
-
const content = fence.lang ? highlightCode(line, fence.lang) : line
|
|
370
|
-
emitAnswer(` ${content}\n`)
|
|
371
|
-
answerHasLine = true
|
|
377
|
+
if (line.trim() === "") {
|
|
378
|
+
if (answerFlow.onBlank()) emitAnswer("\n")
|
|
372
379
|
return
|
|
373
380
|
}
|
|
374
|
-
|
|
375
|
-
// paritas dengan decorateMarkdown TUI (spasi vertikal sebelum heading).
|
|
376
|
-
const isHeading = /^#{1,3}\s/.test(line)
|
|
377
|
-
if (isHeading && answerHasLine) emitAnswer("\n")
|
|
381
|
+
if (answerFlow.onLine(line)) emitAnswer("\n")
|
|
378
382
|
emitAnswer(formatWrapped(decorateMarkdown(line), w))
|
|
379
383
|
emitAnswer("\n")
|
|
380
|
-
answerHasLine = answerHasLine || line.trim() !== ""
|
|
381
384
|
}
|
|
382
385
|
const consumePlainText = (text: string): void => {
|
|
383
386
|
const combined = plainLineBuffer + text
|
|
@@ -392,6 +395,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
392
395
|
continue
|
|
393
396
|
}
|
|
394
397
|
const width = process.stdout.columns || 80
|
|
398
|
+
if (answerFlow.onTable()) emitAnswer("\n")
|
|
395
399
|
const rendered = process.stdout.isTTY
|
|
396
400
|
? renderMarkdownTable(event.table, width, renderInline)
|
|
397
401
|
: event.raw
|
|
@@ -625,7 +629,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
625
629
|
reasoningLine = ""
|
|
626
630
|
answerBuf = ""
|
|
627
631
|
answerTruncated = false
|
|
628
|
-
|
|
632
|
+
answerFlow = new MarkdownFlowStepper()
|
|
629
633
|
activeProviderAttempt = null
|
|
630
634
|
attemptCopyText = ""
|
|
631
635
|
ui.clearCollapsedSections()
|
|
@@ -714,6 +718,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
714
718
|
attemptReasoningLine = reasoningLine
|
|
715
719
|
attemptThinkState = thinkState
|
|
716
720
|
attemptFence = fence ? { ...fence } : null
|
|
721
|
+
attemptAnswerFlow = answerFlow.clone()
|
|
717
722
|
textSan = createStreamSanitizer()
|
|
718
723
|
reasoningSan = createStreamSanitizer()
|
|
719
724
|
} else if (id === activeProviderAttempt && data?.phase === "completed") {
|
|
@@ -731,6 +736,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
|
|
|
731
736
|
reasoningLine = attemptReasoningLine
|
|
732
737
|
thinkState = attemptThinkState
|
|
733
738
|
fence = attemptFence ? { ...attemptFence } : null
|
|
739
|
+
answerFlow = attemptAnswerFlow.clone()
|
|
734
740
|
plainLineBuffer = ""
|
|
735
741
|
tableStream.reset()
|
|
736
742
|
textSan.flush()
|
package/src/ui/i18n/en.ts
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
export const en = {
|
|
5
5
|
"app.newBelow": "↓ {n} new lines below · PgDn to bottom",
|
|
6
6
|
"app.abortHint": "abort sent — press Esc again to quit",
|
|
7
|
-
"app.welcomeTitle": "minicode {dot} {model}",
|
|
8
|
-
"app.welcomeCwd": "{cwd}",
|
|
9
|
-
"app.welcomeHints": "Tab mode {dot} Shift+Tab permission {dot} / menu {dot} Ctrl+R history",
|
|
10
7
|
"tui.selectionCopied": "selection copied to clipboard",
|
|
11
8
|
"tui.selectionCopyFailed": "selection could not be copied (OSC 52 unavailable)",
|
|
12
9
|
"tui.selectionTooLarge": "selection too large to copy",
|
package/src/ui/i18n/id.ts
CHANGED
|
@@ -5,9 +5,6 @@ import type { MsgKey } from "./locale.ts"
|
|
|
5
5
|
export const id: Record<MsgKey, string> = {
|
|
6
6
|
"app.newBelow": "↓ {n} baris baru di bawah · PgDn ke ekor",
|
|
7
7
|
"app.abortHint": "abort terkirim — tekan Esc sekali lagi untuk keluar",
|
|
8
|
-
"app.welcomeTitle": "minicode {dot} {model}",
|
|
9
|
-
"app.welcomeCwd": "{cwd}",
|
|
10
|
-
"app.welcomeHints": "Tab mode {dot} Shift+Tab izin {dot} / menu {dot} Ctrl+R riwayat",
|
|
11
8
|
"tui.selectionCopied": "seleksi disalin ke clipboard",
|
|
12
9
|
"tui.selectionCopyFailed": "seleksi tidak bisa disalin (OSC 52 tidak tersedia)",
|
|
13
10
|
"tui.selectionTooLarge": "seleksi terlalu besar untuk disalin",
|