minicode-ai 0.14.1 → 0.14.4
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/README.md +34 -178
- package/cli/args.ts +10 -18
- package/cli/auto-update.ts +32 -2
- package/cli/commands/acp.ts +20 -27
- package/cli/commands/daemon.ts +6 -7
- package/cli/commands/exec.ts +12 -10
- package/cli/commands.ts +6 -9
- package/cli/index.ts +40 -17
- package/cli/provider-manager.ts +1 -3
- package/cli/setup.ts +174 -145
- package/cli/tui.ts +33 -38
- package/docs/CONTROL-PLANE-MAP.md +145 -0
- package/docs/OUTPUT_EVENT_MODEL.md +1 -1
- package/docs/OUTPUT_PROTOCOL_SPEC.md +8 -2
- package/docs/OUTPUT_RENDERING_SPEC.md +35 -6
- package/docs/OUTPUT_UX_RULES.md +1 -1
- package/docs/README.md +14 -102
- package/docs/SUMMARY.md +53 -0
- package/docs/TERMINAL_CONTRACT.md +136 -77
- package/docs/UI_RENDER_PIPELINE.md +204 -0
- package/docs/agents.md +5 -5
- package/docs/architecture.md +23 -12
- package/docs/choosing-mode.md +7 -7
- package/docs/cli.md +22 -29
- package/docs/concepts.md +1 -1
- package/docs/config.md +10 -5
- package/docs/contributing.md +6 -6
- package/docs/environment.md +3 -1
- package/docs/exec.md +5 -5
- package/docs/getting-started.md +14 -12
- package/docs/glossary.md +9 -7
- package/docs/mcp-lsp.md +1 -1
- package/docs/memory-sessions.md +7 -5
- package/docs/policy-sandbox.md +23 -15
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +4 -3
- package/docs/security-model.md +16 -17
- package/docs/security.md +15 -30
- package/docs/skills.md +1 -1
- package/docs/tools.md +6 -6
- package/docs/verify-benchmark.md +16 -0
- package/package.json +5 -5
- package/scripts/vendor-overlays/minicode-context.patch +109 -0
- package/src/app/mentions.ts +4 -3
- package/src/app/provider-layer.ts +13 -1
- package/src/app/session.ts +229 -22
- package/src/app/tool-layer.ts +6 -0
- package/src/config.ts +30 -3
- package/src/constants.ts +19 -0
- package/src/daemon/control.ts +1 -1
- package/src/lib/git-hardening.ts +27 -22
- package/src/lib/safe-open.ts +73 -19
- package/src/lib/trusted-exec.ts +7 -4
- package/src/mcp/client.ts +34 -9
- package/src/mcp/server.ts +2 -3
- package/src/mcp/transport.ts +96 -42
- package/src/memory/files.ts +15 -4
- package/src/memory/vector.ts +5 -1
- package/src/policy/compaction.ts +272 -16
- package/src/policy/context-window.ts +73 -0
- package/src/policy/context.ts +76 -16
- package/src/policy/ratelimit.ts +47 -18
- package/src/policy/tool-contract.ts +4 -10
- package/src/policy/update-check.ts +83 -6
- package/src/policy/usage.ts +31 -14
- package/src/policy/work-mode.ts +1 -1
- package/src/presentation/adapter.ts +64 -2
- package/src/presentation/events.ts +6 -0
- package/src/presentation/model.ts +1 -0
- package/src/presentation/projection.ts +2 -0
- package/src/presentation/reducer.ts +1 -0
- package/src/providers/anthropic.ts +52 -19
- package/src/providers/guards.ts +158 -16
- package/src/providers/provision.ts +12 -3
- package/src/providers/responses.ts +61 -23
- package/src/providers/router.ts +56 -23
- package/src/providers/sse-bounds.ts +170 -0
- package/src/repo/repomap.ts +10 -11
- package/src/runtime/execution-backend.ts +7 -8
- package/src/sandbox/docker.ts +113 -9
- package/src/session/checkpoint.ts +9 -2
- package/src/session/context-projection.ts +14 -0
- package/src/session/context-selector.ts +58 -20
- package/src/session/persistence.ts +6 -3
- package/src/session/verification.ts +55 -16
- package/src/skills/loader.ts +16 -3
- package/src/task/model.ts +21 -70
- package/src/tools/bash.ts +6 -3
- package/src/tools/code_run.ts +6 -5
- package/src/tools/context.ts +8 -0
- package/src/tools/delete_file.ts +2 -1
- package/src/tools/edit.ts +2 -1
- package/src/tools/git.ts +128 -54
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +31 -6
- package/src/tools/lsp.ts +5 -4
- package/src/tools/mcp_call.ts +3 -1
- package/src/tools/memory.ts +175 -180
- package/src/tools/move_file.ts +2 -1
- package/src/tools/patch.ts +2 -1
- package/src/tools/read_file.ts +94 -1
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +9 -1
- package/src/tools/todo.ts +4 -5
- package/src/tools/web_fetch.ts +28 -12
- package/src/tools/web_search.ts +28 -9
- package/src/tools/write_file.ts +2 -1
- package/src/ui/assistant/simple.ts +72 -3
- package/src/ui/footer.ts +131 -66
- package/src/ui/i18n/en.ts +3 -11
- package/src/ui/i18n/id.ts +3 -11
- package/src/ui/input/input.ts +2 -3
- package/src/ui/input/prompt-engine.ts +2 -5
- package/src/ui/render/width.ts +107 -79
- package/src/ui/runtime/screen.ts +49 -37
- package/src/ui/screens/model-manager.ts +3 -10
- package/src/ui/screens/picker.ts +23 -40
- package/src/ui/screens/provider-manager.ts +12 -33
- package/src/ui/screens/wizard.ts +0 -1
- package/src/ui/tui/app.ts +265 -211
- package/src/ui/tui/transcript.ts +87 -8
- package/vendor/minicore/VENDOR.md +9 -5
- package/vendor/minicore/src/core/loop.ts +47 -12
- package/vendor/minicore/src/core/provider.ts +4 -0
- package/vendor/minicore/src/core/session.ts +14 -1
- package/CHANGELOG.md +0 -1185
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +0 -489
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +0 -391
- package/docs/PLAN_UIUX_V6.md +0 -209
- package/docs/changelog.md +0 -3
package/docs/quickstart.md
CHANGED
|
@@ -20,7 +20,7 @@ minicode auth status # lihat kredensial + kapan kedaluwarsa
|
|
|
20
20
|
## 2. Prompt pertama (2 menit)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
minicode "buat http server hello world di server.ts" --verbose
|
|
23
|
+
minicode --work-mode BUILD "buat http server hello world di server.ts" --verbose
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
Yang terjadi: model menerima system prompt berisi `# Environment` (cwd + platform) + repo-map ringkas, lalu loop ReAct `Thought → Action → Observation` sampai jawaban final atau batas (`--max-steps` default 50, `--timeout` default 15 menit).
|
|
@@ -38,7 +38,7 @@ minicode --interactive
|
|
|
38
38
|
## 3. Verify otomatis (2 menit)
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
minicode --verify "fix bugs lalu typecheck"
|
|
41
|
+
minicode --work-mode BUILD --verify "fix bugs lalu typecheck"
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Sebelum agen jalan, baseline diuji dulu. Bila baseline sudah merah, catatan Health-Check ditempel ke prompt awal agar agen memperbaiki dulu. Setelah run, verify dijalankan; bila gagal, agen self-heal maks 3 siklus. Output error dibungkus fence agar tidak jadi prompt injection. Custom command via `MINICODE_VERIFY_CMD` atau `verifyCommand` di config.
|
package/docs/repl.md
CHANGED
|
@@ -22,8 +22,8 @@ en. `/lang` tanpa argumen = tampilkan aktif. Semua string lewat kamus i18n
|
|
|
22
22
|
| `/redo` | Terapkan ulang yang dibatalkan |
|
|
23
23
|
| `/sessions` | Tanpa argumen = popup picker resume; `/sessions <id>` = langsung resume |
|
|
24
24
|
| `/status` | Runtime + pemakaian & biaya **kumulatif sesi** |
|
|
25
|
-
| `/mode [
|
|
26
|
-
| `/work-mode [DISCUSS\|PLAN\|
|
|
25
|
+
| `/mode [AUTO\|ASK]` | Ganti pengawasan persetujuan; tanpa argumen = toggle AUTO/ASK |
|
|
26
|
+
| `/work-mode [DISCUSS\|PLAN\|BUILD]` | WorkMode membatasi cara agent bekerja. `DISCUSS` read-only, `PLAN` memakai ceiling rencana, `BUILD` tidak menambah ceiling (identitas internal `EXECUTE`). Tanpa argumen = tampilkan mode aktif + usage; nilai invalid ditolak dan mode aktif tidak berubah. Tab dan `/work-mode` mengubah WorkMode; Shift+Tab dan `/mode` mengubah PermissionMode. |
|
|
27
27
|
| `/lang [en|id]` | Bahasa UI; tanpa argumen = tampilkan aktif |
|
|
28
28
|
| `/init` | Buat `AGENTS.md` proyek ini |
|
|
29
29
|
| `/copy [n]` | Salin `n` turn terakhir (default `1`, maksimal `10`) via OSC 52 |
|
|
@@ -42,7 +42,8 @@ Did-you-mean: typo `/sessoons` → `Did you mean /sessions?` (jarak ≤ 2).
|
|
|
42
42
|
| Tombol | Fungsi |
|
|
43
43
|
|---|---|
|
|
44
44
|
| `enter` | Kirim prompt (di picker/form: pilih/simpan; kosong = batal di picker) |
|
|
45
|
-
| `tab`
|
|
45
|
+
| `tab` | Putar WorkMode (`DISCUSS` → `PLAN` → `BUILD`) |
|
|
46
|
+
| `shift+tab` | Toggle PermissionMode (`AUTO` ↔ `ASK`) |
|
|
46
47
|
| `↑` / `↓` | Riwayat prompt, atau navigasi item di picker/manager/form |
|
|
47
48
|
| `pgup` / `pgdn` | Gulir transkrip satu halaman; dengan `shift`: setengah halaman (di picker/manager: gulir daftar) |
|
|
48
49
|
| `mouse drag` | Select teks transkrip; `Ctrl+C` menyalin selection app-level |
|
package/docs/security-model.md
CHANGED
|
@@ -21,20 +21,19 @@ Permission → Jail → Bash Guard → Argument Validation → Executor → Jour
|
|
|
21
21
|
| **Bash Guard** | Perintah shell dinormalisasi dulu (buang quote/wrapper/variabel sederhana), baru diperiksa polanya. Menolak env-dump, exfiltrasi upload, interpreter inline, destruksi luas. |
|
|
22
22
|
| **Argument Validation** | Skema argumen divalidasi kernel sebelum eksekusi; argumen invalid ditolak tanpa efek. |
|
|
23
23
|
| **Executor** | Menjalankan yang lolos: read paralel, write dibatasi konkurensinya, abort-aware, output dipotong dengan penanda (tak pernah diam-diam). |
|
|
24
|
-
| **Journal / Recovery** | Tiap mutasi dicatat `pending`
|
|
24
|
+
| **Journal / Recovery** | Tiap mutasi dicatat sebagai `pending` lalu `committed`/`failed`/`unknown`; finalisasi menandai cakupan turn durable. Resume tak pernah mengulang buta (lihat [Recovery](#recovery)). |
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Mode dan akses
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|---|---|---|---|
|
|
30
|
-
| `auto` (default) | Baca + tulis file terjail + bash aman + memori/todo | Gated tools tanpa persetujuan | Sekali per tool gated (TTY); non-TTY = tolak |
|
|
31
|
-
| `ask` | Sama seperti `auto` | Tanpa jawaban allow | Tiap tool non-sepele |
|
|
32
|
-
| `readonly` | 18 tool baca di gerbang izin (model melihat 12) | Mutasi apa pun, bash, commit, delegasi | Tidak perlu (tak ada efek) |
|
|
33
|
-
| `plan` | Baca + `todo_write` + `delegate_task` (anak dipaksa read-only) + `submit_result` | Tulis file, bash, git, memori | Tidak perlu |
|
|
34
|
-
| `allowlist` | Bash pola aman + tulis terjail | Shell di luar pola, tool gated | Tidak perlu |
|
|
35
|
-
| `allow-all` | Semua tool | Bash berbahaya, path di luar jail | Tidak perlu |
|
|
28
|
+
Pilihan yang terlihat oleh operator dipisah menjadi tiga sumbu:
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
| Sumbu | Nilai | Dampak |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| **WorkMode** | `DISCUSS`, `PLAN`, `BUILD` (`EXECUTE` internal) | Membatasi ruang kerja agent. `DISCUSS` read-only; `PLAN` dapat menulis artefak rencana; `BUILD` tidak menambahkan ceiling. WorkMode hanya mempersempit akses. |
|
|
33
|
+
| **PermissionMode** | `AUTO`, `ASK` | `AUTO` menjalankan capability yang sudah diotorisasi tanpa persetujuan rutin; `ASK` meminta persetujuan untuk pemanggilan yang digate. `ask_user` ditolak di `AUTO`. |
|
|
34
|
+
| **Tool Access Policy** | kebijakan capability dan profil akses warisan | Menentukan tools yang tersedia. `readonly`, `plan`, `allowlist`, dan `allow-all` tetap menjadi identitas internal/kompatibilitas untuk batas akses, bukan mode persetujuan tambahan. |
|
|
35
|
+
|
|
36
|
+
**Profil `allow-all` tetap terbatas.** Path jail, penolakan state milik runtime, bash-guard, dan validasi argumen tetap berlaku; profil ini tidak memberi akses host tanpa batas. Detail implementasi dan opsi CLI ada di [Policy & Sandbox](policy-sandbox.md).
|
|
38
37
|
|
|
39
38
|
## Trust Boundaries
|
|
40
39
|
|
|
@@ -44,9 +43,9 @@ PENTING: **`allow-all` bukan akses host tanpa batas.** Jail path dan bash-guard
|
|
|
44
43
|
| Output model | Tak dipercaya untuk klaim | Teks/keputusan model bisa salah; bukti (hasil tool, test, HEAD) yang menentukan |
|
|
45
44
|
| Hasil tool | Data | Dibaca model sebagai fakta observasi, bukan instruksi baru |
|
|
46
45
|
| Data repository (kode, AGENTS.md, MEMORY, skill) | Data | Bisa berisi instruksi injeksi; system prompt menandainya tak-terpercaya |
|
|
47
|
-
| Server MCP | External capability | Efek di sisi server arbitrer dan tak terlihat;
|
|
46
|
+
| Server MCP | External capability | Efek di sisi server arbitrer dan tak terlihat; persetujuan mengikuti mode dan authorization; pembatalan tak membatalkan efek yang sudah terjadi |
|
|
48
47
|
| Provider / network | External | Prompt dan hasil melewati provider yang Anda pilih; tak ada telemetri/analitik dari Minicode sendiri |
|
|
49
|
-
| Child agent | Terisolasi | Memori, sinyal, budget, dan jurnal sendiri;
|
|
48
|
+
| Child agent | Terisolasi | Memori, sinyal, budget, dan jurnal sendiri; tool scope mengikuti kebijakan delegasi dan WorkMode parent (lihat [Sub-Agents & Tasks](agents.md)) |
|
|
50
49
|
| Local config (`.minicode/config.json`) | Tak dipercaya default | Diabaikan kecuali `--allow-local-config`; repo clone-an tak bisa men-spawn server |
|
|
51
50
|
| Skills / memory tersimpan | Data | Dibaca sebagai konteks, bukan kebijakan |
|
|
52
51
|
|
|
@@ -58,25 +57,25 @@ Minicode **tidak menyediakan tool** untuk (terverifikasi di `src/tools/`):
|
|
|
58
57
|
- `git reset`, `amend`, `rebase`, `checkout`, `branch -D`, `stash drop`
|
|
59
58
|
- Eksekusi remote / deploy bawaan
|
|
60
59
|
|
|
61
|
-
Catatan jujur: operasi itu tetap BISA diketik lewat `bash` (tunduk pada bash-guard + jail, BUKAN larangan).
|
|
60
|
+
Catatan jujur: operasi itu tetap BISA diketik lewat `bash` (tunduk pada bash-guard + jail, BUKAN larangan). `git` via bash menjalankan konfigurasi repo apa adanya (hook/filter/driver milik repo). Tool baca `git_*` dinetralkan; `git_commit` menolak sebelum staging bila filter Git terkonfigurasi. Di repo tak-terpercaya, utamakan tool baca dan tinjau konfigurasi sebelum memakai Git manual.
|
|
62
61
|
|
|
63
62
|
## Recovery
|
|
64
63
|
|
|
65
64
|
Setiap mutasi meninggalkan bukti, bukan janji (disebut *mutation journal* di kode: `src/session/journal.ts`):
|
|
66
65
|
|
|
67
66
|
```
|
|
68
|
-
intent
|
|
67
|
+
intent pending → committed/failed/unknown → finalisasi cakupan turn durable
|
|
69
68
|
```
|
|
70
69
|
|
|
71
70
|
- `committed` yang turn-nya hilang → **tidak diulang**; model diberi catatan narasi.
|
|
72
|
-
- `pending`/`failed` → direktif verifikasi; **dilarang redo buta**.
|
|
71
|
+
- `pending`/`failed`/`unknown` → direktif verifikasi; **dilarang redo buta**.
|
|
73
72
|
- Klaim sukses pihak ketiga (MCP) diperlakukan sebagai "kata server", wajib baca-balik bila penting.
|
|
74
73
|
|
|
75
74
|
Kejujuran yang disengaja: crash ambiguity TETAP MUNGKIN (filesystem dan database tak bisa commit atomik bersama). Yang dijamin adalah: ambiguitas selalu diperlakukan sebagai ambigu — diverifikasi dulu, tidak diasumsikan sukses maupun gagal.
|
|
76
75
|
|
|
77
76
|
## Limitations
|
|
78
77
|
|
|
79
|
-
- **Repo hooks/filter/driver:** `git` via bash mengeksekusinya (semantik stock-git); tool `git_*`
|
|
78
|
+
- **Repo hooks/filter/driver:** `git` via bash mengeksekusinya (semantik stock-git); tool baca `git_*` menetralkan filter, sedangkan `git_commit` menolak bila menemukan filter terkonfigurasi.
|
|
80
79
|
- **Bash arbitrer:** guard adalah analisis statis; substitusi dinamis (`$(curl …)`) butuh sandbox OS/docker untuk isolasi nyata.
|
|
81
80
|
- **Efek eksternal MCP:** setelah terjadi, tak bisa dibatalkan dari sini.
|
|
82
81
|
- **Provider/network:** data melewati provider pilihan Anda; Minicode tak menambahkan transmisi sendiri.
|
package/docs/security.md
CHANGED
|
@@ -5,47 +5,32 @@
|
|
|
5
5
|
1. **Fail-closed di jalur tak pasti**: tool tanpa backend tersedia menolak (`code_run`), sandbox yang diminta tapi tidak tersedia tidak pura-pura aman (warn + `allowlist`), provider OAuth yang belum login dibuang dari daftar, auth non-TTY fail-fast.
|
|
6
6
|
2. **Ukur, bukan klaim**: bash-guard divalidasi korpus manual pola serangan + perintah sah dan fuzz kombinatorial ber-seed — jalankan `bun run gate:bash` dan `bun run extreme:fuzz` untuk angka terkini (exit 0 = 0 bypass / 0 over-block).
|
|
7
7
|
3. **Teks eksternal = tidak terpercaya**: output tool, MCP, web, bahkan output verify dibungkus fence; `sanitizeAnsi` menyaring escape ANSI dari teks model/tool sebelum render.
|
|
8
|
-
4. **Permission mengontrol pemanggilan, bukan capability**: satu approval
|
|
8
|
+
4. **Permission mengontrol pemanggilan, bukan capability**: di ASK, satu approval hanya mencakup pasangan server+tool+args (MCP); capability di balik server tak bisa diketahui statis.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Mode dan akses
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Kontrol mode punya tiga sumbu: **WorkMode** (`DISCUSS`/`PLAN`/`BUILD`) membatasi cara kerja agent; **PermissionMode** (`AUTO`/`ASK`) menentukan kapan dibutuhkan persetujuan manusia; **Tool Access Policy** menentukan capability yang tersedia. Nilai internal `readonly`, `plan`, `allowlist`, dan `allow-all` masih ada untuk batas akses dan kompatibilitas, tetapi bukan empat mode pengawasan tambahan. Hard deny path jail, owned-state, dan bash-guard tetap berlaku. Detail kombinasi dan interface ada di [Memilih Mode](choosing-mode.md) dan [Policy & Sandbox](policy-sandbox.md).
|
|
13
13
|
|
|
14
14
|
## Lapisan perlindungan bash
|
|
15
15
|
|
|
16
|
-
1. **Bash-guard ternormalisasi** (`src/policy/bash-guard.ts`)
|
|
17
|
-
|
|
18
|
-
| Dulu lolos | Kenapa | Sekarang |
|
|
19
|
-
|---|---|---|
|
|
20
|
-
| `cat .e""nv` | regex melihat `.e""nv`, shell membaca `.env` | ditolak |
|
|
21
|
-
| `X=.env; cat $X` | regex tak pernah melihat `.env` | ditolak |
|
|
22
|
-
| `p=python3; $p -c 1` | regex tak melihat `python3 -c` | ditolak |
|
|
23
|
-
| `node --eval "1"` | hanya `-e` yang di-regex | ditolak |
|
|
24
|
-
| `env`, `set`, `export -p` | hanya `printenv` yang diblok | ditolak |
|
|
25
|
-
| `curl -F file=@~/.ssh/id_rsa` | tak ada aturan upload | ditolak |
|
|
26
|
-
| `bash <(curl x)` | tak ada aturan process substitution | ditolak |
|
|
27
|
-
| `rm -rf ..`, `rm --recursive --force /`, `rm -rf /; :` | pola lama hanya kenal `/` dan `~` | ditolak |
|
|
28
|
-
| `command env`, `nice env`, dkk. (wrapper) | deteksi env-dump ter-anchor ke awal | ditolak via `stripCommandWrappers` (buang wrapper berlapis) |
|
|
29
|
-
| `echo x > ..\evil` (redirect keluar workspace) | allowlist `echo *` + guard tanpa aturan redirect | ditolak via `findRedirectTargets` (target di-resolve ke cwd; heredoc/fd/`/dev/null` dikecualikan) |
|
|
30
|
-
| `echo x > "%TEMP%\evil"` (redirect + ekspansi env) | cek statis melihat literal `%TEMP%\…` di dalam cwd; cmd.exe mengekspansi SETELAH cek | ditolak: target berpola `%NAMA%` tak bisa dipastikan aman (red-team eksternal). `%` tunggal (`100%.txt`) tetap lolos |
|
|
31
|
-
| `py -c …`, `python3.14 -c …` (launcher/versi) | regex hanya kenal `python|python2|python3|pypy` | ditolak via `pyw?|python[\d.]*|pypy[\d.]*` |
|
|
32
|
-
| `type ..\..\..\windows\system32\config\sam` (baca hive SAM) | pola kredensial POSIX-sentris (`/etc/shadow` dkk, tanpa padanan Windows) | ditolak: `system32\config\(sam|system|security|software|default)` + `ntds.dit` (anchor segmen, case-insensitive); `reg save|export` hive + `vssadmin create|delete shadow` + `ntdsutil` ditolak eksplisit (`reg query`, `vssadmin list`, `system.txt` biasa tetap lolos) |
|
|
33
|
-
| `write_file .minicode/test-write.txt` (state via nama tak terdaftar) | jail `.minicode/` berbasis daftar-nama | ditolak: kunci penuh segmen `.minicode/` untuk tool tulis (satu-satunya pengecualian: restore `.minicode/.trash/` → workspace) |
|
|
34
|
-
| baca via hardlink ke luar workspace | `realpath` tak melihat hardlink (semua nama setara) | ditolak bila `nlink > 1` pada handle yang dibuka (fstat, bebas race). Tulis aman by-design (atomic replace memutus hardlink) |
|
|
35
|
-
| `type .e^nv`, `ty^pe .env` (escape caret cmd.exe) | guard mencocokkan nama LITERAL, sementara cmd.exe melepas `^` di luar kutip ganda sebelum eksekusi — satu caret memindahkan perintah dari "ditahan" ke "lolos" | ditolak: `stripCaretEscapes` berjalan sebelum semua aturan nama/jail (audit 2026-09-20, temuan F1); caret di dalam kutip ganda tidak disentuh (`echo "a^b"` tetap sah). Trade-off jujur: di POSIX caret bukan escape, jadi `cat .e^nv` ikut ditolak (fail-closed; berkas bernama `.e^nv` praktis tidak ada) |
|
|
36
|
-
| `type %USERPROFILE%\notes.txt` (argumen PEMBACA + ekspansi env) | hanya target redirect yang dianggap "tak bisa dipastikan"; argumen pembaca di-`resolve()` sebagai jalur relatif DI DALAM cwd | ditolak: aturan `%NAMA%` kini simetris untuk argumen pembaca (temuan F2). `%` tunggal (`100%.txt`) tetap lolos |
|
|
37
|
-
| `for /f %i in (.env) do @echo %i` (pembaca bawaan cmd.exe) | `for` adalah loop, bukan utilitas → tidak ada di `READERS`, sehingga target berkasnya tak diperiksa sama sekali | ditolak: set berkas `for /f … in (…)` diekstrak (`forFileSets`) dan diperiksa seperti argumen pembaca (temuan F3) |
|
|
16
|
+
1. **Bash-guard ternormalisasi** (`src/policy/bash-guard.ts`) menormalisasi command sebelum aturan diterapkan. Tabel bypass termasuk redirect, ekspansi env Windows, hardlink, escape caret, dan pembaca `for /f` ada di [Policy & Sandbox](policy-sandbox.md), satu sumber contoh. `bun run gate:bash` dan `bun run extreme:fuzz` mengukur regresi.
|
|
38
17
|
|
|
39
18
|
2. **Allowlist** (`--allowlist`, dan default bila tanpa sandbox OS): hanya bentuk read/build — `git status/diff/log/branch/show`, `bun test/run/x tsc`, `npm run/exec`, `npx`, `ls dir cat type head tail wc grep rg find which echo pwd`. Tulis via shell ditahan; pakai `write_file`/`edit` yang ter-jail. `npm exec`/`npx`/`bun run`/`bun x` tak boleh ekspansi shell/redirection. `git --no-index/--exec-path/--upload-pack/--receive-pack`, transport `ext::`, dan `GIT_EXTERNAL_DIFF`/`GIT_CONFIG_*` inline ditolak guard (git sebagai pelarian jail).
|
|
40
|
-
3. **Path jail** realpath-based + symlink check
|
|
19
|
+
3. **Path jail** realpath-based + symlink check; pembaca membuka target canonical, memakai `O_NOFOLLOW` pada POSIX, lalu mencocokkan `dev+ino` antara stat sebelum open dan handle setelah open (termasuk Windows). `.env`/`.git/config`/`node_modules`/hive Windows (`system32\config\sam|system|security|software`, `ntds.dit`) deny; berlaku bahkan `--allow-all`.
|
|
41
20
|
4. **Env scrub** `sanitizeSpawnEnv`: strip kata-kunci kredensial dari merge final. `GITHUB_WORKSPACE`/`GITHUB_REF`/`GOOGLE_CHROME_PATH`/`REDIS_HOST`/`AWS_REGION` **tetap ada** (pernah terhapus dan memecahkan build CI), sementara `GITHUB_TOKEN`/`AWS_SECRET_ACCESS_KEY`/`DATABASE_URL` di-strip. Bila non-rahasia ikut hilang, itu bug — laporkan nama variabelnya.
|
|
42
21
|
5. **web_fetch/web_search**: redirect manual ≤5 hop + DNS pinning 30 dtk + body cap 2 MB. Host privat ditolak (sama untuk MCP HTTP).
|
|
43
22
|
|
|
23
|
+
`grep` memakai ripgrep bila tersedia. Biner di-resolve dari PATH absolut yang
|
|
24
|
+
tepercaya, environment child disanitasi, dan config eksternal dinonaktifkan
|
|
25
|
+
(`--no-config`, tanpa `RIPGREP_CONFIG_PATH`). Config ripgrep mendukung
|
|
26
|
+
preprocessor yang mengeksekusi program per berkas; karena itu tool pencarian
|
|
27
|
+
tidak mewarisi konfigurasi tersebut.
|
|
28
|
+
|
|
44
29
|
## Prompt injection
|
|
45
30
|
|
|
46
31
|
- Output verify dibungkus fence agar instruksi di error build tidak diikuti model.
|
|
47
32
|
- `mcp_read`/`mcp_prompt` di-gate meski read-only — konten pihak ketiga langsung ke konteks = jalur injection; "read-only ≠ aman".
|
|
48
|
-
- Secret scrubber meredaksi `sk-`, `
|
|
33
|
+
- Secret scrubber meredaksi `sk-`, `ghp_`, `AKIA`, PEM, JWT, Bearer, `api_key=...` sebelum teks ke LLM (read_file/bash/grep), tanpa whitelist kata.
|
|
49
34
|
- Bypass korpus + fuzz: `bun run gate:bash`, `bun run extreme:fuzz` (`--seed` untuk reproduksi). Batas jujur: analisis statis atas bahasa Turing-complete; `$(curl …)` dinamis perlu sandbox OS/docker.
|
|
50
35
|
|
|
51
36
|
## Batas kepercayaan file lokal (trust model)
|
|
@@ -75,17 +60,17 @@ provider model pihak ketiga.
|
|
|
75
60
|
## Config lokal & supply chain
|
|
76
61
|
|
|
77
62
|
- Config lokal `.minicode/config.json` + allowlist **diabaikan secara default** — repo clone-an tidak bisa men-spawn MCP, menyedot prompt, atau memasang hook. Percayai dengan `--allow-local-config`.
|
|
78
|
-
- Server MCP terdaftar tidak mendapat wildcard auto-allow
|
|
63
|
+
- Server MCP terdaftar tidak mendapat wildcard auto-allow. Capability tetap harus diotorisasi; di ASK pemanggilan yang digate meminta persetujuan per pasangan server+tool+args, sedangkan AUTO menjalankan capability authorized tanpa prompt rutin. `[a] Always` menyimpan cakupan yang disetujui ke allowlist.
|
|
79
64
|
- Config/allowlist/auth ditulis atomik + chmod 600; token OAuth terpisah di `~/.minicode/auth.json` (bukan config yang rawan ter-commit).
|
|
80
65
|
- `mcp serve` stdio-only (tanpa mode HTTP → tanpa permukaan jaringan), curated tools, permission aktif; `--all-tools` opt-in operator.
|
|
81
66
|
|
|
82
67
|
## Checkpoint & recovery
|
|
83
68
|
|
|
84
|
-
Setiap turn checkpoint shadow-git + recovery journal `.minicode/journal-<sesi>.jsonl` (`pending` → `committed
|
|
69
|
+
Setiap turn checkpoint shadow-git + recovery journal `.minicode/journal-<sesi>.jsonl` (`pending` → `committed`/`failed`/`unknown`; finalisasi menandai cakupan turn durable). Saat resume: `committed` yang turn-nya hilang tidak diulang; `pending`/`failed`/`unknown` → direktif verifikasi, dilarang redo buta; `committed` MCP = external-acknowledged wajib baca-balik. Detail di [Memory & Sessions](memory-sessions.md).
|
|
85
70
|
|
|
86
71
|
## Lanjut
|
|
87
72
|
|
|
88
73
|
- [Security Model](security-model.md) — rantai eksekusi, trust boundary, dan limitasi dalam satu halaman.
|
|
89
|
-
- [Policy & Sandbox](policy-sandbox.md) —
|
|
74
|
+
- [Policy & Sandbox](policy-sandbox.md) — mode, tool access policy, dan detail guard.
|
|
90
75
|
- [Kontrak Terminal](terminal.md) — kenapa warna di-gate TTY.
|
|
91
76
|
- [Otomasi & CI](exec.md) — batasan agent di CI (fail-closed non-TTY).
|
package/docs/skills.md
CHANGED
|
@@ -45,4 +45,4 @@ Hooks global + lokal di-merge dari allowlist secara atomik (chmod 600). Karena h
|
|
|
45
45
|
|
|
46
46
|
- [TUI](repl.md) - dropdown + slash command.
|
|
47
47
|
- [Config](config.md) — lokasi file & skema config.
|
|
48
|
-
- [Tools](tools.md) —
|
|
48
|
+
- [Tools](tools.md) — capability yang tersedia untuk skill.
|
package/docs/tools.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Tools
|
|
1
|
+
# Tools
|
|
2
2
|
|
|
3
3
|
Referensi lengkap tool Minicode: filesystem, search, exec, git, web, memory, plan, agents, MCP, LSP.
|
|
4
4
|
|
|
5
|
-
Pilih tool ini ketika: **file** untuk baca/tulis presisi (bukan `cat` via bash); **search** untuk menemukan kode (bukan `grep` via bash); **bash** untuk perintah yang memang butuh shell; **git tool** untuk status/diff/log/commit (bukan `git` mentah —
|
|
5
|
+
Pilih tool ini ketika: **file** untuk baca/tulis presisi (bukan `cat` via bash); **search** untuk menemukan kode (bukan `grep` via bash); **bash** untuk perintah yang memang butuh shell; **git tool** untuk status/diff/log/commit (bukan `git` mentah — operasi baca dinetralkan dan commit menolak custom filter repo); **web** untuk sumber publik; **memory** untuk fakta lintas sesi (bukan tempelan prompt); **delegate** untuk penelahan paralel yang hasilnya diverifikasi parent.
|
|
6
6
|
|
|
7
7
|
Daftar pasti kapan pun:
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ bun -e "import {allTools} from './src/tools/index.ts'; console.log(allTools.map(
|
|
|
23
23
|
| `apply_patch` | Blok SEARCH/REPLACE multi-hunk ala Aider | Satu call banyak patch |
|
|
24
24
|
| `move_file` | Pindah/rename atomik | Dest yang ada dibackup ke trash dulu (catat path). Dijail di permission layer juga |
|
|
25
25
|
| `delete_file` | Soft-delete ke `.minicode/.trash/` | Undo via `move_file`. Cap 100 terbaru, gitignored. Shared helper `src/lib/trash.ts` |
|
|
26
|
-
| `read_image` | Gambar → konteks model | Base64 utuh + lapor `(bytes mime, tokens)` via `estimateImageTokens`. Cap file-size 2 MB.
|
|
26
|
+
| `read_image` | Gambar → konteks model | Base64 utuh + lapor `(bytes mime, tokens)` via `estimateImageTokens`. Cap file-size 2 MB. Pembukaan memeriksa target canonical, boundary ulang, identitas handle `dev+ino`, dan hardlink (`safeOpenRead`) |
|
|
27
27
|
|
|
28
28
|
Contoh paging:
|
|
29
29
|
|
|
@@ -66,7 +66,7 @@ Batas `BASH_BACKGROUND_MAX_JOBS`; semua job mati saat CLI keluar.
|
|
|
66
66
|
| `git_status` | `status --porcelain + diff --stat + log -10` | cwd jail |
|
|
67
67
|
| `git_diff` | `diff` unstaged atau `--staged` | — |
|
|
68
68
|
| `git_log` | `log --oneline -n` | — |
|
|
69
|
-
| `git_commit` | Commit saja | **Di-gate** seperti `delegate_task` (TTY = minta sekali, non-TTY = tolak; `readonly/plan/allowlist` = tolak). Sub-agent tidak mendapatkannya. Yang sengaja tidak ada: push/amend/reset/rebase/checkout/branch -D/stash drop. Pesan via `-m` tunggal agar `$()`/backtick tidak dieksekusi; `git add -- <paths>` agar file `-weird.txt` tidak jadi flag |
|
|
69
|
+
| `git_commit` | Commit saja | **Di-gate** seperti `delegate_task` (TTY = minta sekali, non-TTY = tolak; `readonly/plan/allowlist` = tolak). Menolak sebelum staging jika config Git efektif memuat custom filter; tinjau filter terpercaya lalu lakukan commit manual. Sub-agent tidak mendapatkannya. Yang sengaja tidak ada: push/amend/reset/rebase/checkout/branch -D/stash drop. Pesan via `-m` tunggal agar `$()`/backtick tidak dieksekusi; `git add -- <paths>` agar file `-weird.txt` tidak jadi flag |
|
|
70
70
|
|
|
71
71
|
## Web
|
|
72
72
|
|
|
@@ -90,14 +90,14 @@ Batas `BASH_BACKGROUND_MAX_JOBS`; semua job mati saat CLI keluar.
|
|
|
90
90
|
|
|
91
91
|
| Tool | Fungsi | Catatan |
|
|
92
92
|
|---|---|---|
|
|
93
|
-
| `delegate_task` | Sub-agen isolasi `explore`/`plan` | Pool 3,
|
|
93
|
+
| `delegate_task` | Sub-agen isolasi `explore`/`plan` | Pool 3, context/memory/signal/budget terpisah, abort-aware. Di ASK, TTY meminta persetujuan dan non-TTY menolak; AUTO berjalan tanpa prompt bila authorized. Parent PermissionMode `ASK`/`plan`/`readonly` memaksa `explore`; WorkMode `DISCUSS`/`PLAN` membatasi tool anak ke subset eksplorasi. Anak tidak mendapat MCP, commit, memory/todo writes, nesting, atau job background. Satu approval mencakup satu delegasi; turn gagal setelah anak committed → warning `[recovery]` |
|
|
94
94
|
|
|
95
95
|
## MCP
|
|
96
96
|
|
|
97
97
|
| Tool | Spec | Catatan |
|
|
98
98
|
|---|---|---|
|
|
99
99
|
| `mcp_list` | `tools/list` + `resources/list` + `prompts/list` | Read-only, tidak di-gate. Panggil dulu |
|
|
100
|
-
| `mcp_call` | `tools/call` | Di-gate. 1 approval = 1 call. Jalan di luar policy minicode |
|
|
100
|
+
| `mcp_call` | `tools/call` | Di-gate. 1 approval = 1 call. Jalan di luar policy minicode. Abort/timeout setelah request dikirim dilaporkan sebagai `outcome unknown`; periksa state server sebelum retry |
|
|
101
101
|
| `mcp_read` | `resources/read` | Di-gate **meski read-only** (konten pihak ketiga = jalur prompt-injection). Biner diganti penanda ukuran |
|
|
102
102
|
| `mcp_prompt` | `prompts/get` | Di-gate, server merender argumen |
|
|
103
103
|
|
package/docs/verify-benchmark.md
CHANGED
|
@@ -29,6 +29,22 @@ bun run gate:eval --results bench/live.json --min-rate 0.8 --max-median-tokens 8
|
|
|
29
29
|
bun bench/eval-gate.ts --results bench/results.json --min-rate 1 --max-median-tokens 5000 --observe-tokens # observasi: token tak menggagalkan (2–3 run pertama sebelum ambang dikunci)
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
CI menjalankan `test/eval-gate.test.ts` untuk menguji evaluator secara
|
|
33
|
+
deterministik tanpa provider, lalu menjalankan CLI `gate:eval` terhadap output
|
|
34
|
+
`bench:smoke` dan memastikan hasil palsu ditolak. `bench:smoke` hanya menguji
|
|
35
|
+
wiring harness; hanya hasil yang secara eksplisit berlabel `fake: false` dapat
|
|
36
|
+
dinilai, sehingga hasil fake atau artefak lama tanpa asal provider dinyatakan
|
|
37
|
+
bukan bukti kualitas. Evaluasi
|
|
38
|
+
kualitas live tetap harus memakai hasil provider nyata yang tersimpan, serta
|
|
39
|
+
anggaran/provider yang dipilih operator. CI PR dan publish tidak menjalankan
|
|
40
|
+
provider berbayar atau memakai rahasia model; evaluasi live tetap manual karena
|
|
41
|
+
hasil, model, dan anggaran harus dipilih operator secara eksplisit.
|
|
42
|
+
|
|
43
|
+
Skor deterministik menggunakan total langkah aktual seluruh run dibanding
|
|
44
|
+
total batas langkah yang disediakan. Nilai ini berasal dari `usage.steps` saat
|
|
45
|
+
run selesai, atau event `step:started` jika run berakhir dengan error; batas
|
|
46
|
+
konfigurasi tidak lagi dipakai sebagai pengganti langkah aktual.
|
|
47
|
+
|
|
32
48
|
Metrik: resolve rate, steps, token, cost, durasi, memoryHits + delta vs run sebelumnya. Hasil `bench/results.json` (`--out` untuk path lain). Tiap run gagal membawa kelas (`VERIFY_FAIL`/`MAX_STEPS`/`NO_PROGRESS`/`ABORT`) + distribusi global di akhir run; kartu metodologi + log observasi di `bench/HARNESS-CARD.md`.
|
|
33
49
|
|
|
34
50
|
Setiap run memakai `MINICODE_HOME` hermetic sendiri (DB/memory/sesi global tak bocor antar run dan tak menyentuh `~/.minicode` operator). Task boleh membawa `seedMemory`: fakta yang di-seed ke memory run itu — task `follow-convention` hanya lolos bila agen membaca fakta tersebut, sehingga `bun bench/runner.ts --memory on` vs `--memory off` mengukur nilai memory secara diferensial (bukan klaim).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minicode-ai",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"description": "Coding agent CLI built on the frozen MiniCore runtime — tools, MCP, LSP, sandbox, shadow-git checkpoints",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -48,22 +48,22 @@
|
|
|
48
48
|
"vendor/minicore/src",
|
|
49
49
|
"vendor/minicore/package.json",
|
|
50
50
|
"vendor/minicore/VENDOR.md",
|
|
51
|
+
"scripts/vendor-overlays/minicode-context.patch",
|
|
51
52
|
"README.md",
|
|
52
|
-
"CHANGELOG.md",
|
|
53
53
|
"LICENSE",
|
|
54
|
-
"docs/OUTPUT_ARCHITECTURE_AUDIT.md",
|
|
55
54
|
"docs/OUTPUT_EVENT_MODEL.md",
|
|
56
|
-
"docs/OUTPUT_IMPLEMENTATION_PLAN.md",
|
|
57
55
|
"docs/OUTPUT_PROTOCOL_SPEC.md",
|
|
58
56
|
"docs/OUTPUT_RENDERING_SPEC.md",
|
|
59
57
|
"docs/OUTPUT_UX_RULES.md",
|
|
60
|
-
"docs/
|
|
58
|
+
"docs/SUMMARY.md",
|
|
61
59
|
"docs/TERMINAL_CONTRACT.md",
|
|
60
|
+
"docs/UI_RENDER_PIPELINE.md",
|
|
62
61
|
"docs/agents.md",
|
|
63
62
|
"docs/architecture.md",
|
|
64
63
|
"docs/choosing-mode.md",
|
|
65
64
|
"docs/cli.md",
|
|
66
65
|
"docs/concepts.md",
|
|
66
|
+
"docs/CONTROL-PLANE-MAP.md",
|
|
67
67
|
"docs/config-providers.md",
|
|
68
68
|
"docs/config.md",
|
|
69
69
|
"docs/contributing.md",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
diff --git a/vendor/minicore/src/core/loop.ts b/vendor/minicore/src/core/loop.ts
|
|
2
|
+
index 11ea5eb..56e4f54 100644
|
|
3
|
+
--- a/vendor/minicore/src/core/loop.ts
|
|
4
|
+
+++ b/vendor/minicore/src/core/loop.ts
|
|
5
|
+
@@ -48,3 +48,6 @@ export async function executeTurn(
|
|
6
|
+
- // maxProviderRetries); the policy flag is set when a policy compaction
|
|
7
|
+
- // is attempted (once per turn, guarding against per-step O(n) repeats).
|
|
8
|
+
- let compactedForBudget = false;
|
|
9
|
+
+ // maxProviderRetries); policy compaction has a small per-turn hard cap,
|
|
10
|
+
+ // guarding against repeated no-progress work after tool output grows.
|
|
11
|
+
+ // Permit one follow-up policy compaction after tool results grow the current
|
|
12
|
+
+ // turn. The hard cap prevents a no-progress compactor from looping forever.
|
|
13
|
+
+ let budgetCompactions = 0;
|
|
14
|
+
+ const maxBudgetCompactions = 2;
|
|
15
|
+
@@ -52,0 +56,13 @@ export async function executeTurn(
|
|
16
|
+
+ // Resolve once for the turn: model switching is a between-turn operation,
|
|
17
|
+
+ // so budget admission and output accounting must use the same model window.
|
|
18
|
+
+ let contextWindowTokens = s.contextWindowTokens;
|
|
19
|
+
+ try {
|
|
20
|
+
+ const resolved = s.contextWindowTokensForModel?.(s.state.model);
|
|
21
|
+
+ if (typeof resolved === "number" && Number.isSafeInteger(resolved) && resolved > 0) {
|
|
22
|
+
+ contextWindowTokens = resolved;
|
|
23
|
+
+ }
|
|
24
|
+
+ } catch {
|
|
25
|
+
+ // Keep the validated numeric fallback; a metadata lookup must not bypass
|
|
26
|
+
+ // the kernel's context guard.
|
|
27
|
+
+ }
|
|
28
|
+
+
|
|
29
|
+
@@ -62 +78 @@ export async function executeTurn(
|
|
30
|
+
- limitTokens: s.contextWindowTokens,
|
|
31
|
+
+ limitTokens: contextWindowTokens,
|
|
32
|
+
@@ -64 +80,2 @@ export async function executeTurn(
|
|
33
|
+
- if (s.budget.shouldCompact(pressure) && !compactedForBudget) {
|
|
34
|
+
+ let reduced = false;
|
|
35
|
+
+ if (s.budget.shouldCompact(pressure) && budgetCompactions < maxBudgetCompactions) {
|
|
36
|
+
@@ -67 +84 @@ export async function executeTurn(
|
|
37
|
+
- compactedForBudget = true;
|
|
38
|
+
+ budgetCompactions++;
|
|
39
|
+
@@ -72 +89 @@ export async function executeTurn(
|
|
40
|
+
- const reduced = s.store.messages.length < before;
|
|
41
|
+
+ reduced = s.store.messages.length < before;
|
|
42
|
+
@@ -79 +96 @@ export async function executeTurn(
|
|
43
|
+
- limitTokens: s.contextWindowTokens,
|
|
44
|
+
+ limitTokens: contextWindowTokens,
|
|
45
|
+
@@ -82,2 +99,9 @@ export async function executeTurn(
|
|
46
|
+
- if (pressure === "critical" && compactedForBudget) {
|
|
47
|
+
- throw new AgentError("budget_exceeded", "context window exceeded after compaction");
|
|
48
|
+
+ if (s.budget.shouldCompact(pressure) && reduced && budgetCompactions < maxBudgetCompactions) {
|
|
49
|
+
+ continue;
|
|
50
|
+
+ }
|
|
51
|
+
+ if (pressure === "critical") {
|
|
52
|
+
+ const used = contextTokens(s);
|
|
53
|
+
+ throw new AgentError(
|
|
54
|
+
+ "budget_exceeded",
|
|
55
|
+
+ `context window exceeded after compaction (${used} > ${contextWindowTokens}); reduce the prompt, tool output, or fixed instructions, or select a model with a larger context window`,
|
|
56
|
+
+ );
|
|
57
|
+
@@ -179 +203,5 @@ export async function executeTurn(
|
|
58
|
+
- throw new AgentError("budget_exceeded", errorMessage ?? "context too large", { cause: providerError ?? action });
|
|
59
|
+
+ throw new AgentError(
|
|
60
|
+
+ "budget_exceeded",
|
|
61
|
+
+ `context window exceeded after recovery compaction: ${errorMessage ?? "context too large"}`,
|
|
62
|
+
+ { cause: providerError ?? action },
|
|
63
|
+
+ );
|
|
64
|
+
@@ -303,0 +332,3 @@ function toProviderError(error: unknown, signal: AbortSignal): ProviderError {
|
|
65
|
+
+ // Host-side admission guards (context budget, shutdown, etc.) preserve their
|
|
66
|
+
+ // deterministic AgentError identity instead of entering provider retry.
|
|
67
|
+
+ if (error instanceof AgentError) throw error;
|
|
68
|
+
@@ -336 +367,5 @@ function contextTokens(s: SessionInternal): number {
|
|
69
|
+
- return estimateSessionContext(s.store, s.system, s.registry.list(), s.estimator);
|
|
70
|
+
+ let system = s.system;
|
|
71
|
+
+ try {
|
|
72
|
+
+ system = s.systemForContext?.() ?? system;
|
|
73
|
+
+ } catch {}
|
|
74
|
+
+ return estimateSessionContext(s.store, system, s.registry.list(), s.estimator);
|
|
75
|
+
diff --git a/vendor/minicore/src/core/provider.ts b/vendor/minicore/src/core/provider.ts
|
|
76
|
+
index 489e244..63afbbc 100644
|
|
77
|
+
--- a/vendor/minicore/src/core/provider.ts
|
|
78
|
+
+++ b/vendor/minicore/src/core/provider.ts
|
|
79
|
+
@@ -37,0 +38,4 @@ export interface ModelProvider {
|
|
80
|
+
+ /** Optional host metadata for per-model admission budgets. */
|
|
81
|
+
+ contextWindowTokensForModel?(model?: string): number;
|
|
82
|
+
+ /** Canonical provider/model key for per-model estimator state. */
|
|
83
|
+
+ contextModelIdentity?(model?: string): string | undefined;
|
|
84
|
+
diff --git a/vendor/minicore/src/core/session.ts b/vendor/minicore/src/core/session.ts
|
|
85
|
+
index 6e183d7..df80273 100644
|
|
86
|
+
--- a/vendor/minicore/src/core/session.ts
|
|
87
|
+
+++ b/vendor/minicore/src/core/session.ts
|
|
88
|
+
@@ -37,0 +38,2 @@ export interface SessionConfig {
|
|
89
|
+
+ /** Dynamic system prompt for host-controlled per-turn mode hints. */
|
|
90
|
+
+ systemForContext?: () => string;
|
|
91
|
+
@@ -61,0 +64,3 @@ export interface SessionConfig {
|
|
92
|
+
+ /** Resolve a model-specific context limit for each run. Additive app seam;
|
|
93
|
+
+ * the numeric option remains the fallback for existing library callers. */
|
|
94
|
+
+ contextWindowTokensForModel?: (model?: string) => number;
|
|
95
|
+
@@ -140,0 +146 @@ export interface SessionInternal {
|
|
96
|
+
+ readonly systemForContext?: () => string;
|
|
97
|
+
@@ -149,0 +156 @@ export interface SessionInternal {
|
|
98
|
+
+ readonly contextWindowTokensForModel?: (model?: string) => number;
|
|
99
|
+
@@ -180,0 +188 @@ export function createSession(config: SessionConfig): Session {
|
|
100
|
+
+ systemForContext: config.systemForContext,
|
|
101
|
+
@@ -189,0 +198 @@ export function createSession(config: SessionConfig): Session {
|
|
102
|
+
+ contextWindowTokensForModel: config.contextWindowTokensForModel,
|
|
103
|
+
@@ -213 +222,5 @@ export function createSession(config: SessionConfig): Session {
|
|
104
|
+
- return estimateSessionContext(store, config.system, impl.registry.list(), impl.estimator);
|
|
105
|
+
+ let system = config.system
|
|
106
|
+
+ try {
|
|
107
|
+
+ system = config.systemForContext?.() ?? system
|
|
108
|
+
+ } catch {}
|
|
109
|
+
+ return estimateSessionContext(store, system, impl.registry.list(), impl.estimator);
|
package/src/app/mentions.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { realpath } from "node:fs/promises"
|
|
2
2
|
import { isAbsolute, relative, resolve } from "node:path"
|
|
3
|
+
import { safeReadFileCapped } from "../lib/safe-open.ts"
|
|
3
4
|
import { isPathOutsideRoot, isSensitive } from "../policy/jail.ts"
|
|
4
5
|
|
|
5
6
|
const MAX_INJECT = 2_000
|
|
@@ -26,9 +27,9 @@ export async function resolveMentionContent(
|
|
|
26
27
|
const [real, realRoot] = await Promise.all([realpath(abs), realpath(cwd)])
|
|
27
28
|
if (isPathOutsideRoot(real, realRoot) || isSensitive(real))
|
|
28
29
|
return { ok: false, reason: "rejected (jail)" }
|
|
29
|
-
const txt = await
|
|
30
|
+
const { text: txt, truncated } = await safeReadFileCapped(real, realRoot, MAX_INJECT)
|
|
30
31
|
const rel = relative(realRoot, real).replace(/\\/g, "/")
|
|
31
|
-
const body =
|
|
32
|
+
const body = truncated ? `${txt}\n… (truncated: first ${MAX_INJECT} bytes)` : txt
|
|
32
33
|
return { ok: true, content: `\n[file: ${rel}]\n${body}\n[/file]\n` }
|
|
33
34
|
} catch {
|
|
34
35
|
return { ok: false, reason: "file not found" }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createOpenAICompatProvider } from "#minicore/providers/openai-compat.ts"
|
|
2
2
|
import { loadConfig, type MinicodeConfig } from "../config.ts"
|
|
3
|
+
import { resolveContextWindow } from "../policy/context-window.ts"
|
|
3
4
|
import type { RateLimiter } from "../policy/ratelimit.ts"
|
|
4
5
|
import { createAnthropicProvider } from "../providers/anthropic.ts"
|
|
5
6
|
import { buildProviderListAsync } from "../providers/build.ts"
|
|
@@ -7,6 +8,7 @@ import { withStreamGuards } from "../providers/guards.ts"
|
|
|
7
8
|
import { createRouterProvider } from "../providers/router.ts"
|
|
8
9
|
|
|
9
10
|
let currentRouter: ReturnType<typeof createRouterProvider> | null = null
|
|
11
|
+
let currentConfig: MinicodeConfig | null = null
|
|
10
12
|
|
|
11
13
|
/** Setup tanpa provider apa pun. Dilempar (bukan exit di sini) agar
|
|
12
14
|
* composition root bisa memilih presentasi: REPL/one-shot mencetak pesan
|
|
@@ -24,9 +26,17 @@ export async function reloadProviders(
|
|
|
24
26
|
): Promise<void> {
|
|
25
27
|
if (!currentRouter) return
|
|
26
28
|
const cfg = await loadConfig(cwd, { allowLocal: opts.allowLocal })
|
|
29
|
+
if (currentConfig)
|
|
30
|
+
currentConfig.providers.splice(0, currentConfig.providers.length, ...cfg.providers)
|
|
31
|
+
else currentConfig = cfg
|
|
27
32
|
const providers = await buildProviderListAsync(cfg)
|
|
28
|
-
const r = currentRouter as unknown as {
|
|
33
|
+
const r = currentRouter as unknown as {
|
|
34
|
+
updateProviders: (list: unknown[]) => void
|
|
35
|
+
}
|
|
29
36
|
if (typeof r.updateProviders === "function") r.updateProviders(providers)
|
|
37
|
+
// Keep the router's live context resolver. The composition root may have
|
|
38
|
+
// wrapped it with a session override and warning policy; replacing it here
|
|
39
|
+
// would make /sync silently reset child sessions to config-only limits.
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
export async function createProviderLayer(opts: {
|
|
@@ -43,6 +53,7 @@ export async function createProviderLayer(opts: {
|
|
|
43
53
|
setupWhenEmpty?: () => Promise<boolean>
|
|
44
54
|
}): Promise<{ cfg: MinicodeConfig; router: ReturnType<typeof createRouterProvider> }> {
|
|
45
55
|
const cfg = await loadConfig(opts.cwd, { allowLocal: opts.allowLocalConfig })
|
|
56
|
+
currentConfig = cfg
|
|
46
57
|
type Provider = ReturnType<typeof createOpenAICompatProvider>
|
|
47
58
|
let providers = await buildProviderListAsync(cfg)
|
|
48
59
|
|
|
@@ -119,6 +130,7 @@ export async function createProviderLayer(opts: {
|
|
|
119
130
|
}
|
|
120
131
|
const router = createRouterProvider({
|
|
121
132
|
providers,
|
|
133
|
+
contextWindowTokensForModel: (model) => resolveContextWindow(cfg, model).tokens,
|
|
122
134
|
...(opts.rateLimiter ? { limiter: opts.rateLimiter } : {}),
|
|
123
135
|
})
|
|
124
136
|
currentRouter = router
|