minicode-ai 0.20.0 → 0.22.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.
- package/README.md +1 -1
- package/cli/auto-update.ts +24 -15
- package/cli/commands/exec.ts +44 -1
- package/cli/commands.ts +5 -2
- package/cli/index.ts +57 -18
- package/cli/setup.ts +88 -34
- package/cli/tui.ts +22 -2
- package/docs/TERMINAL_CONTRACT.md +50 -11
- package/docs/UI_RENDER_PIPELINE.md +6 -3
- package/docs/architecture.md +10 -6
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +4 -3
- package/docs/environment.md +2 -0
- package/docs/policy-sandbox.md +6 -1
- package/docs/security.md +12 -4
- package/docs/skills.md +1 -1
- package/package.json +2 -2
- package/src/config.ts +8 -6
- package/src/daemon/discovery.ts +24 -0
- package/src/policy/bash-guard.ts +170 -6
- package/src/policy/compaction.ts +34 -7
- package/src/policy/jail.ts +10 -22
- package/src/policy/permission.ts +9 -6
- package/src/policy/update-check.ts +6 -4
- package/src/presentation/projection.ts +1 -1
- package/src/providers/anthropic.ts +14 -4
- package/src/providers/responses.ts +1 -1
- package/src/providers/sse-bounds.ts +16 -2
- package/src/ui/approval/prompt.ts +17 -6
- package/src/ui/assistant/simple.ts +14 -0
- package/src/ui/footer.ts +2 -2
- package/src/ui/i18n/en.ts +29 -1
- package/src/ui/i18n/id.ts +29 -1
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/activity-group.ts +53 -0
- package/src/ui/render/activity-panel.ts +91 -0
- package/src/ui/render/cells.ts +33 -6
- package/src/ui/render/diff.ts +58 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/markdown.ts +6 -1
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +11 -4
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +19 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +137 -0
- package/src/ui/screens/dialog.ts +23 -2
- package/src/ui/screens/form.ts +52 -10
- package/src/ui/screens/model-manager.ts +8 -2
- package/src/ui/screens/picker.ts +11 -3
- package/src/ui/screens/provider-manager.ts +11 -3
- package/src/ui/screens/wizard.ts +29 -1
- package/src/ui/session-state.ts +22 -0
- package/src/ui/tui/app.ts +57 -20
- package/src/ui/tui/transcript.ts +204 -27
- package/vendor/minicore/src/providers/openai-compat.ts +30 -1
package/docs/policy-sandbox.md
CHANGED
|
@@ -30,7 +30,7 @@ Set terkait: `INTERNAL_WRITE_TOOLS`, `FILE_WRITE_TOOLS`, `GATED_TOOLS` (+ `*.*`
|
|
|
30
30
|
| `echo x > "%TEMP%\evil"` | ditolak; target berisi ekspansi `%NAMA%` tak bisa dipastikan aman secara statis |
|
|
31
31
|
| `py -c …`, `python3.14 -c …` | ditolak bersama varian launcher dan versi Python |
|
|
32
32
|
| `type ..\..\windows\system32\config\sam`, `Get-Content .../ntds.dit` | ditolak (hive Windows + `reg save|export` hive + `vssadmin create|delete shadow` + `ntdsutil`; `reg query`, `vssadmin list`, `system.txt` biasa tetap lolos) |
|
|
33
|
-
| `write_file .minicode/<apa-pun>` | ditolak fail-closed (kunci penuh segmen `.minicode/`;
|
|
33
|
+
| `write_file .minicode/<apa-pun>` | ditolak fail-closed (kunci penuh segmen `.minicode/`; satu-satunya pengecualian restore `.trash/` → workspace; skrip `.minicode/hooks/` kini ikut terkunci — lihat [Keamanan](security.md)) |
|
|
34
34
|
| `bash <(curl x)` | ditolak |
|
|
35
35
|
| `rm -rf ..`, `rm --recursive --force /`, `rm -rf /; :` | ditolak |
|
|
36
36
|
| `command env`, `nice env`, dkk. (wrapper) | deteksi env-dump ter-anchor ke awal | ditolak via `stripCommandWrappers` (buang wrapper berlapis) |
|
|
@@ -38,6 +38,11 @@ Set terkait: `INTERNAL_WRITE_TOOLS`, `FILE_WRITE_TOOLS`, `GATED_TOOLS` (+ `*.*`
|
|
|
38
38
|
| `type .e^nv`, `ty^pe .env` (escape caret cmd.exe) | ditolak setelah caret dinormalisasi sebelum aturan nama/jail |
|
|
39
39
|
| `type %USERPROFILE%\notes.txt` | ditolak; argumen pembaca berpola `%NAMA%` tak bisa dipastikan aman |
|
|
40
40
|
| `for /f %i in (.env) do @echo %i` | ditolak; file set pada loop `for /f` ikut diperiksa |
|
|
41
|
+
| `cat${IFS}.env`, `cat$IFS.env`, `cat${IFS:0:1}.env` (audit 2026-11-12) | ditolak; `$IFS` adalah pemisah kata, dinormalisasi jadi spasi sebelum aturan nama |
|
|
42
|
+
| `cat .?nv`, `cat .[e]nv` | ditolak; glob `?`/`[]` mengembang ke nama lain sama seperti `*` |
|
|
43
|
+
| `cat .{env,}`, `cat {.env,x}` | ditolak; brace expansion diekspansi sebelum pemeriksaan |
|
|
44
|
+
| `cat$(printf ' ').env` | ditolak; argumen pembaca berupa substitusi perintah tak bisa dipastikan statis |
|
|
45
|
+
| `echo "rm -rf /"`, `git commit -m "docs: sudo rm"` | lolos (arah over-block); isi kutip milik echo/printf/grep/`-m` git adalah DATA, bukan perintah — kecuali memuat `$(`, backtick, atau `$VAR` yang tetap dieksekusi |
|
|
41
46
|
|
|
42
47
|
Allowlist (bentuk perintah yang boleh; diperiksa SETELAH bash-guard). Dua daftar:
|
|
43
48
|
- **Narrow** (`--allowlist`, task tak-terpercaya): `git status/diff/log/branch/show`, `bun test/run/x tsc`, `npm/bun/pnpm/yarn install|add`, `npm run/exec/install/ci/test/start`, `node`, `npx`, `ls dir cat type head tail wc grep rg find which echo pwd`. Tulis via shell (`mkdir cp mv rm touch`) ditahan — pakai `write_file`/`edit` yang ter-jail.
|
package/docs/security.md
CHANGED
|
@@ -52,17 +52,25 @@ provider model pihak ketiga.
|
|
|
52
52
|
yang belum bermutasi (by-design, bukan korupsi).
|
|
53
53
|
- State milik runtime (`.minicode/` — DB, todos, plans, checkpoints, jurnal,
|
|
54
54
|
traces, allowlist, config, + file APAPUN lain di bawahnya): tulis via file
|
|
55
|
-
tools ditolak fail-closed (pengecualian: restore
|
|
56
|
-
|
|
57
|
-
luar permission system, aktif hanya via opt-in `MINICODE_HOOKS=1` dan
|
|
58
|
-
dilarang di WorkMode non-`EXECUTE`); baca tetap boleh (observability). Tulis
|
|
55
|
+
tools ditolak fail-closed (satu-satunya pengecualian: restore
|
|
56
|
+
`.minicode/.trash/` → workspace); baca tetap boleh (observability). Tulis
|
|
59
57
|
catatan sendiri ke workspace, bukan ke `.minicode/`.
|
|
58
|
+
- Skrip hooks `.minicode/hooks/` ikut terkunci untuk penulisan (audit
|
|
59
|
+
2026-11-12). Hook adalah kode arbitrer di luar permission system yang
|
|
60
|
+
dieksekusi OTOMATIS lewat scan direktori saat opt-in `MINICODE_HOOKS=1`
|
|
61
|
+
(hanya WorkMode `EXECUTE`, timeout 5 dtk, env disanitasi). Kalau file tool
|
|
62
|
+
boleh menulis ke sana, model/prompt-injection bisa menanam hook lalu
|
|
63
|
+
menjalankannya di sesi yang sama — jadi skrip hook dibuat operator di luar
|
|
64
|
+
sesi. Repo clone-an yang sudah memuat `.minicode/hooks/*.js` tetap harus
|
|
65
|
+
diperlakukan sebagai config lokal tak tepercaya: periksa isinya sebelum
|
|
66
|
+
menyalakan `MINICODE_HOOKS=1`.
|
|
60
67
|
|
|
61
68
|
## Config lokal & supply chain
|
|
62
69
|
|
|
63
70
|
- 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`.
|
|
64
71
|
- 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.
|
|
65
72
|
- Config/allowlist/auth ditulis atomik + chmod 600; token OAuth terpisah di `~/.minicode/auth.json` (bukan config yang rawan ter-commit).
|
|
73
|
+
- Daemon menaruh `bootstrap` secret di `<cwd>/.minicode/daemon-endpoint.json` (`0600`). Di Windows mode POSIX diabaikan, jadi ACL berkas itu dicabut dari warisan dan dibatasi ke user pemilik via `icacls` (best-effort). Residual: pada mesin multi-user Windows di mana `icacls` gagal, user lain yang bisa membaca folder repo masih bisa membaca secret dan menerbitkan capability daemon (loopback, bukan remote).
|
|
66
74
|
- `mcp serve` stdio-only (tanpa mode HTTP → tanpa permukaan jaringan), curated tools, permission aktif; `--all-tools` opt-in operator.
|
|
67
75
|
|
|
68
76
|
## Checkpoint & recovery
|
package/docs/skills.md
CHANGED
|
@@ -39,7 +39,7 @@ Hooks mati secara default; nyalakan dengan `MINICODE_HOOKS=1`.
|
|
|
39
39
|
| Konteks | Env `MINICODE_HOOK_CTX` (JSON run) |
|
|
40
40
|
| Sanitasi | Env hook disanitasi tanpa secret; hook dilewati bila sesi dibatalkan |
|
|
41
41
|
|
|
42
|
-
Hooks global + lokal di-merge (bukan lewat allowlist). Karena hook adalah kode arbitrer di luar permission system, ia hanya jalan bila `MINICODE_HOOKS=1` dan WorkMode `EXECUTE` (tidak di `DISCUSS`/`PLAN`); setiap hook dikenai timeout 5 dtk dan env-nya disanitasi. Repo clone-an
|
|
42
|
+
Hooks global + lokal di-merge (bukan lewat allowlist). Karena hook adalah kode arbitrer di luar permission system, ia hanya jalan bila `MINICODE_HOOKS=1` dan WorkMode `EXECUTE` (tidak di `DISCUSS`/`PLAN`); setiap hook dikenai timeout 5 dtk dan env-nya disanitasi. File tool **tidak** boleh menulis ke `.minicode/hooks/` (audit 2026-11-12) — skrip hook dibuat operator di luar sesi, sehingga model tidak bisa menanam hook yang langsung dieksekusi. Repo clone-an yang sudah memuat `.minicode/hooks/*.js` tetap tak tepercaya: periksa isinya sebelum menyalakan `MINICODE_HOOKS=1` (lihat [Keamanan](security.md)).
|
|
43
43
|
|
|
44
44
|
## Lanjut
|
|
45
45
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minicode-ai",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Open-source terminal coding agent on a
|
|
3
|
+
"version": "0.22.0",
|
|
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,
|
|
7
7
|
"publishConfig": {
|
package/src/config.ts
CHANGED
|
@@ -17,17 +17,19 @@ const configLocks = new Map<string, Promise<void>>()
|
|
|
17
17
|
export async function withConfigLock<T>(path: string, fn: () => Promise<T>): Promise<T> {
|
|
18
18
|
const prev = configLocks.get(path) ?? Promise.resolve()
|
|
19
19
|
let release!: () => void
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const gate = new Promise<void>((res) => (release = res))
|
|
21
|
+
// Yang DISIMPAN harus rantai yang sama dengan yang dibandingkan di finally.
|
|
22
|
+
// Dulu map menyimpan `prev.then(() => next)` sementara finally membandingkan
|
|
23
|
+
// dengan `next` — tak pernah sama, sehingga entri map tidak pernah dihapus
|
|
24
|
+
// dan rantai promise tumbuh per penulisan config.
|
|
25
|
+
const tail = prev.then(() => gate)
|
|
26
|
+
configLocks.set(path, tail)
|
|
25
27
|
await prev
|
|
26
28
|
try {
|
|
27
29
|
return await fn()
|
|
28
30
|
} finally {
|
|
29
31
|
release()
|
|
30
|
-
if (configLocks.get(path) ===
|
|
32
|
+
if (configLocks.get(path) === tail) configLocks.delete(path)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
package/src/daemon/discovery.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// koneksi yang berhasil; lease segar hanya menghasilkan "suspect" —
|
|
15
15
|
// ada kandidat, belum terbukti.
|
|
16
16
|
|
|
17
|
+
import { execFileSync } from "node:child_process"
|
|
17
18
|
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs"
|
|
18
19
|
import { resolve } from "node:path"
|
|
19
20
|
import { resolveLocalDbPath } from "../lib/db-path.ts"
|
|
@@ -77,11 +78,34 @@ function leasePath(cwd?: string): string {
|
|
|
77
78
|
return resolveLocalDbPath(LEASE_FILE, cwd)
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Win32 mengabaikan mode POSIX, jadi `0600` pada berkas endpoint (yang memuat
|
|
83
|
+
* bootstrap secret) TIDAK membatasi siapa pun. Satu-satunya kontrol nyata
|
|
84
|
+
* adalah ACL: cabut warisan lalu beri hak penuh hanya ke user pemilik.
|
|
85
|
+
*
|
|
86
|
+
* Best-effort dan senyap: kegagalan icacls (kebijakan domain, PATH aneh)
|
|
87
|
+
* tidak boleh menggagalkan daemon — tapi juga tidak boleh dianggap aman.
|
|
88
|
+
* Residual yang tersisa (mesin multi-user Windows tanpa izin mengubah ACL)
|
|
89
|
+
* didokumentasikan di docs/security.md.
|
|
90
|
+
*/
|
|
91
|
+
function hardenAcl(path: string): void {
|
|
92
|
+
if (process.platform !== "win32") return
|
|
93
|
+
const user = process.env.USERNAME
|
|
94
|
+
if (!user) return
|
|
95
|
+
try {
|
|
96
|
+
execFileSync("icacls", [path, "/inheritance:r", "/grant:r", `${user}:F`], {
|
|
97
|
+
stdio: "ignore",
|
|
98
|
+
windowsHide: true,
|
|
99
|
+
})
|
|
100
|
+
} catch {}
|
|
101
|
+
}
|
|
102
|
+
|
|
80
103
|
/** Tulis atomik (tmp + rename) supaya pembaca tak pernah melihat file separuh. */
|
|
81
104
|
function writeAtomic(path: string, value: unknown, mode = 0o600): void {
|
|
82
105
|
const tmp = `${path}.${process.pid}.tmp`
|
|
83
106
|
writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`, { mode })
|
|
84
107
|
renameSync(tmp, path)
|
|
108
|
+
if (mode <= 0o600) hardenAcl(path)
|
|
85
109
|
}
|
|
86
110
|
|
|
87
111
|
export function writeEndpoint(ep: DaemonEndpoint, cwd?: string): string {
|
package/src/policy/bash-guard.ts
CHANGED
|
@@ -97,6 +97,70 @@ export function stripCaretEscapes(cmd: string): string {
|
|
|
97
97
|
return out
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Ekspansi `$IFS` / `${IFS...}` menjadi pemisah kata.
|
|
102
|
+
*
|
|
103
|
+
* Bash memecah kata pada karakter di `$IFS` (default: spasi/tab/newline),
|
|
104
|
+
* sehingga `cat${IFS}.env` dieksekusi PERSIS seperti `cat .env` — tapi tanpa
|
|
105
|
+
* normalisasi guard hanya melihat satu kata `cat${IFS}.env` dan tak pernah
|
|
106
|
+
* mencocokkan READERS/SENSITIVE_TARGET. Bentuk `$IFS`, `${IFS}` dan
|
|
107
|
+
* `${IFS:0:1}` semuanya menghasilkan pemisah, jadi semuanya dipetakan ke
|
|
108
|
+
* spasi. Diterapkan dua kali dalam pipeline (sebelum dan sesudah quote
|
|
109
|
+
* dibuang) karena `${I"F"S}` juga sah di bash.
|
|
110
|
+
*
|
|
111
|
+
* Diekspor untuk test.
|
|
112
|
+
*/
|
|
113
|
+
export function expandIfsRefs(cmd: string): string {
|
|
114
|
+
return cmd.replace(/\$\{\s*IFS\b[^}]*\}/g, " ").replace(/\$IFS\b/g, " ")
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Ekspansi brace `{a,b}` → semua alternatifnya, sebagai kata-kata terpisah.
|
|
119
|
+
*
|
|
120
|
+
* Brace expansion terjadi SEBELUM perintah dijalankan: `cat .{env,}` dan
|
|
121
|
+
* `cat {.env,x}` membaca `.env`. Karena hasilnya beberapa kata, untuk
|
|
122
|
+
* pemeriksaan alternatif digabung sebagai kata terpisah sehingga aturan
|
|
123
|
+
* berbasis nama (`SENSITIVE_TARGET`) melihat setiap kandidat nyata.
|
|
124
|
+
*
|
|
125
|
+
* Hanya grup yang MENGANDUNG koma yang dianggap ekspansi: `awk '{print $1}'`
|
|
126
|
+
* (tanpa koma) adalah argumen biasa dan tidak boleh ikut dipecah — itu
|
|
127
|
+
* mencegah over-block pada pola awk/sed yang lazim. Kedalaman dan jumlah
|
|
128
|
+
* alternatif dibatasi karena ini heuristik deteksi, bukan evaluator shell.
|
|
129
|
+
*/
|
|
130
|
+
function expandWordBraces(w: string, depth = 0): string[] {
|
|
131
|
+
if (depth > 4 || w.length > 512) return [w]
|
|
132
|
+
const m = /\{([^{}]*)\}/.exec(w)
|
|
133
|
+
if (!m) return [w]
|
|
134
|
+
const body = m[1]!
|
|
135
|
+
if (!body.includes(",")) return [w]
|
|
136
|
+
const pre = w.slice(0, m.index)
|
|
137
|
+
const post = w.slice(m.index + m[0].length)
|
|
138
|
+
const out: string[] = []
|
|
139
|
+
for (const alt of body.split(",")) {
|
|
140
|
+
for (const r of expandWordBraces(pre + alt + post, depth + 1)) {
|
|
141
|
+
out.push(r)
|
|
142
|
+
if (out.length >= 64) return out
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return out
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Diekspor untuk test.
|
|
150
|
+
*
|
|
151
|
+
* Tanpa grup berkoma, perintah dikembalikan APA ADANYA: pemecahan kata di
|
|
152
|
+
* sini mengganti tab/newline dengan spasi, dan kontrak normalisasi menuntut
|
|
153
|
+
* makna (termasuk "perintah ini mencari dari cwd") tetap terbaca —
|
|
154
|
+
* `C=find\t/; ${C} -name x` harus tetap terlihat sebagai tab, bukan `find /`.
|
|
155
|
+
*/
|
|
156
|
+
export function expandBraceAlternatives(cmd: string): string {
|
|
157
|
+
if (!/\{[^{}]*,[^{}]*\}/.test(cmd)) return cmd
|
|
158
|
+
return cmd
|
|
159
|
+
.split(/\s+/)
|
|
160
|
+
.flatMap((w) => (w.includes("{") ? expandWordBraces(w) : [w]))
|
|
161
|
+
.join(" ")
|
|
162
|
+
}
|
|
163
|
+
|
|
100
164
|
/**
|
|
101
165
|
* Substitusi assignment variabel sederhana dalam satu perintah.
|
|
102
166
|
* `X=.env; cat $X` → `X=.env; cat .env`
|
|
@@ -205,16 +269,89 @@ export function normalizeCommand(cmd: string): string {
|
|
|
205
269
|
// [SEC-1] Gabungkan backslash line-continuation dulu agar perintah multi-baris
|
|
206
270
|
// (`curl ... \\\n -d $KEY`) tidak membuat regex satu-baris `[^\n]*` meleset.
|
|
207
271
|
let c = cmd.replace(/\\\r?\n/g, " ")
|
|
272
|
+
// [SEC-3] `$IFS`/`${IFS…}` adalah PEMISAH KATA bagi shell: tanpa ini
|
|
273
|
+
// `cat${IFS}.env` lolos seluruh aturan berbasis nama perintah.
|
|
274
|
+
c = expandIfsRefs(c)
|
|
208
275
|
// [SEC-2] Dekode ANSI-C quoting sebelum quote dibuang.
|
|
209
276
|
c = decodeAnsiCQuotes(c)
|
|
210
|
-
|
|
277
|
+
// IFS dan brace diekspansi sekali lagi setelah quote dibuang: `${I"F"S}`
|
|
278
|
+
// dan `".{env,}"` sama-sama sah di bash.
|
|
279
|
+
return stripCommandWrappers(
|
|
280
|
+
inlineSimpleVars(expandBraceAlternatives(expandIfsRefs(stripQuotes(stripCaretEscapes(c))))),
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Kosongkan isi kutip yang merupakan DATA untuk perintah pencetak/pencari.
|
|
286
|
+
*
|
|
287
|
+
* `echo "rm -rf /"` dan `git commit -m "docs: sudo rm"` tidak mengeksekusi
|
|
288
|
+
* apa pun, tetapi karena normalisasi membuang kutip keduanya terlihat persis
|
|
289
|
+
* seperti perintah berbahaya dan diblokir (over-block yang mengganggu alur
|
|
290
|
+
* dokumentasi/commit). Argumen kutip milik echo/printf/grep/rg dan
|
|
291
|
+
* `-m`/`--message` git adalah teks, jadi isinya dijadikan spasi SEBELUM aturan
|
|
292
|
+
* statis dievaluasi.
|
|
293
|
+
*
|
|
294
|
+
* Pengaman penting: kutip yang memuat substitusi/ekspansi (`$(`, backtick,
|
|
295
|
+
* `${`, `$VAR`) TIDAK dikosongkan — `git commit -m "$(rm -rf /)"` benar-benar
|
|
296
|
+
* mengeksekusi perintah di dalamnya, jadi teks itu bukan data inert.
|
|
297
|
+
*
|
|
298
|
+
* Blanking HANYA dipakai untuk aturan statis (STATIC_DENY/RM_*); pemeriksaan
|
|
299
|
+
* target berkas (SENSITIVE_TARGET, READERS, redirect, jail) tetap memakai
|
|
300
|
+
* bentuk ternormalisasi penuh.
|
|
301
|
+
*
|
|
302
|
+
* Diekspor untuk test.
|
|
303
|
+
*/
|
|
304
|
+
export function blankQuotedDataArgs(cmd: string): string {
|
|
305
|
+
const INERT_HEADS = /^(?:echo|printf|grep|egrep|fgrep|rg|ag)$/i
|
|
306
|
+
const out = cmd.split("")
|
|
307
|
+
let i = 0
|
|
308
|
+
// Awal segmen perintah terakhir: head ditentukan dari sini, bukan dari awal
|
|
309
|
+
// seluruh baris (`git status && echo "x"` → head segmen kedua = echo).
|
|
310
|
+
let segStart = 0
|
|
311
|
+
while (i < cmd.length) {
|
|
312
|
+
const ch = cmd[i]!
|
|
313
|
+
if (ch === "\\" && i + 1 < cmd.length) {
|
|
314
|
+
i += 2
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
if (ch === ";" || ch === "&" || ch === "|" || ch === "\n") {
|
|
318
|
+
segStart = i + 1
|
|
319
|
+
i++
|
|
320
|
+
continue
|
|
321
|
+
}
|
|
322
|
+
if (ch === "'" || ch === '"') {
|
|
323
|
+
const closer = ch
|
|
324
|
+
let j = i + 1
|
|
325
|
+
while (j < cmd.length && cmd[j] !== closer) {
|
|
326
|
+
if (closer === '"' && cmd[j] === "\\" && j + 1 < cmd.length) j++
|
|
327
|
+
if (cmd[j] === "\n") break
|
|
328
|
+
j++
|
|
329
|
+
}
|
|
330
|
+
const closed = j < cmd.length && cmd[j] === closer
|
|
331
|
+
const body = cmd.slice(i + 1, j)
|
|
332
|
+
if (closed && body !== "") {
|
|
333
|
+
const words = cmd.slice(segStart, i).trim().split(/\s+/).filter(Boolean)
|
|
334
|
+
const head = words[0] ?? ""
|
|
335
|
+
const prev = words[words.length - 1] ?? ""
|
|
336
|
+
const inertTarget =
|
|
337
|
+
prev !== head && (/^--message$/i.test(prev) || /^-[a-zA-Z]{0,2}m$/.test(prev))
|
|
338
|
+
const isData =
|
|
339
|
+
(INERT_HEADS.test(head) || inertTarget) && !/\$\(|`|\$\{|\$[A-Za-z_]/.test(body)
|
|
340
|
+
if (isData) for (let k = i + 1; k < j; k++) out[k] = " "
|
|
341
|
+
}
|
|
342
|
+
i = closed ? j + 1 : j
|
|
343
|
+
continue
|
|
344
|
+
}
|
|
345
|
+
i++
|
|
346
|
+
}
|
|
347
|
+
return out.join("")
|
|
211
348
|
}
|
|
212
349
|
|
|
213
350
|
// ── Aturan ──
|
|
214
351
|
|
|
215
352
|
/** Path/berkas kredensial, dicek pada bentuk ternormalisasi. */
|
|
216
353
|
const SENSITIVE_TARGET =
|
|
217
|
-
/(?:^|[\s/\\=@"'([:<>])(?:\.env(?:\.[\w.-]+)?|\.git-credentials|\.npmrc|\.netrc|id_(?:rsa|dsa|ecdsa|ed25519)|credentials(?:\.json)?|\.pem|\.p12|\.pfx|shadow|master\.key|config[/\\](?:sam|system|security|software|default)(?=[/\\]|$|[\s;"'&|])|ntds\.dit\b|hklm[/\\](?:sam|system|security)(?=[/\\]|$|[\s;"'&|]))\b/i
|
|
354
|
+
/(?:^|[\s/\\=@"'([:<>{,])(?:\.env(?:\.[\w.-]+)?|\.git-credentials|\.npmrc|\.netrc|id_(?:rsa|dsa|ecdsa|ed25519)|credentials(?:\.json)?|\.pem|\.p12|\.pfx|shadow|master\.key|config[/\\](?:sam|system|security|software|default)(?=[/\\]|$|[\s;"'&|])|ntds\.dit\b|hklm[/\\](?:sam|system|security)(?=[/\\]|$|[\s;"'&|]))\b/i
|
|
218
355
|
|
|
219
356
|
/** Direktori kredensial: ~/.ssh, $HOME/.aws, /etc/shadow, dst. */
|
|
220
357
|
const SENSITIVE_DIR = /(?:~|\$HOME|\$\{HOME\}|\/etc|\/root|\/proc\/self)[/\\](?:\.?[\w.-]+)/i
|
|
@@ -452,8 +589,11 @@ const ROOT_SCAN = /\b(?:find|fd|ls|dir|du|tree|grep|rg)\b[^\n]*\s\/(?:\s|$)/i
|
|
|
452
589
|
* -r menghapus isi dotfile root.
|
|
453
590
|
*/
|
|
454
591
|
const RM_RECURSIVE = /\brm\b[^\n]*(?:\s-[a-z]*[rR]|\s--recursive\b|\s--dir\b)/i
|
|
592
|
+
// Terminator target root ikut mencakup `)`, `,` dan backtick: bentuk
|
|
593
|
+
// bersubstitusi (`rm -rf $(pwd)`) berakhir dengan `)` sehingga `\s\/(?:\s|…)`
|
|
594
|
+
// dulu meleset dan seluruh perintah lolos.
|
|
455
595
|
const RM_DANGEROUS_TARGET =
|
|
456
|
-
/(?:\s\/(?:\s
|
|
596
|
+
/(?:\s\/(?:\s|$|\*|;|&|\/|\.|\)|,|`)|\s~(?:[/\\]\s*)?(?:\s|$|;|&|\))|\$\{?HOME\}?|\.\.(?:[/\\]|\s|$|;|&)|\s\*\s*(?:$|;|&)|--no-preserve-root)/
|
|
457
597
|
|
|
458
598
|
const STATIC_DENY: [RegExp, string][] = [
|
|
459
599
|
// Fork bomb: definisi fungsi rekursif yang memanggil dirinya lewat pipe.
|
|
@@ -553,11 +693,17 @@ export function inspectBashCommand(rawCmd: string, cwd?: string): BashVerdict {
|
|
|
553
693
|
const raw = rawCmd
|
|
554
694
|
const norm = normalizeCommand(rawCmd)
|
|
555
695
|
const both = (re: RegExp): boolean => re.test(norm) || re.test(raw)
|
|
696
|
+
// Aturan statis dievaluasi pada bentuk yang teks-kutip-inert-nya sudah
|
|
697
|
+
// dikosongkan (blankQuotedDataArgs), sehingga `echo "rm -rf /"` tidak lagi
|
|
698
|
+
// diblokir sementara `rm -rf /` dan `bash -c "rm -rf /"` tetap.
|
|
699
|
+
const inert = blankQuotedDataArgs(raw)
|
|
700
|
+
const inertNorm = normalizeCommand(inert)
|
|
701
|
+
const staticHit = (re: RegExp): boolean => re.test(inertNorm) || re.test(inert)
|
|
556
702
|
|
|
557
703
|
for (const [re, reason] of STATIC_DENY) {
|
|
558
|
-
if (
|
|
704
|
+
if (staticHit(re)) return { denied: true, reason }
|
|
559
705
|
}
|
|
560
|
-
if (
|
|
706
|
+
if (staticHit(RM_RECURSIVE) && staticHit(RM_DANGEROUS_TARGET)) {
|
|
561
707
|
return { denied: true, reason: "destructive rm" }
|
|
562
708
|
}
|
|
563
709
|
if (both(PROCESS_SUB)) return { denied: true, reason: "process substitution" }
|
|
@@ -721,6 +867,16 @@ export function inspectBashCommand(rawCmd: string, cwd?: string): BashVerdict {
|
|
|
721
867
|
|
|
722
868
|
// Berkas sensitif: berbahaya bila dibaca/disalin ATAU dijadikan argumen
|
|
723
869
|
// perintah jaringan. Menyebut `.env` dalam `echo` saja tidak diblokir.
|
|
870
|
+
// Pembaca yang argumennya langsung substitusi perintah (`cat$(printf ' ')`)
|
|
871
|
+
// menyembunyikan nama berkas sepenuhnya dari analisis statis.
|
|
872
|
+
if (
|
|
873
|
+
/\b(?:cat|bat|less|more|head|tail|nl|od|xxd|strings|type|Get-Content|gc|cp|copy|mv|move|tar|base64|openssl|awk|sed|grep|egrep|fgrep|rg|findstr)\b\s*(?:\$\(|`)/i.test(
|
|
874
|
+
inertNorm,
|
|
875
|
+
)
|
|
876
|
+
) {
|
|
877
|
+
return { denied: true, reason: "reader command substitution" }
|
|
878
|
+
}
|
|
879
|
+
|
|
724
880
|
const touchesSensitive = both(SENSITIVE_TARGET) || both(SENSITIVE_DIR)
|
|
725
881
|
if (touchesSensitive && (both(READERS) || /\b(?:curl|wget|nc|ncat|socat|scp)\b/i.test(norm))) {
|
|
726
882
|
return { denied: true, reason: "sensitive file access" }
|
|
@@ -773,12 +929,20 @@ export function inspectBashCommand(rawCmd: string, cwd?: string): BashVerdict {
|
|
|
773
929
|
// `%` tunggal (`100%.txt`) tetap lolos karena bukan pola ekspansi.
|
|
774
930
|
if (/%[^%\s]+%/.test(t))
|
|
775
931
|
return { denied: true, reason: "reader target with env expansion (%VAR%)" }
|
|
776
|
-
|
|
932
|
+
// Glob `?` dan `[abc]` sama-sama mengembang ke nama lain: `cat .?nv`
|
|
933
|
+
// membaca `.env` walau tak ada `*`. Hanya diperiksa untuk token yang
|
|
934
|
+
// berbentuk path (berawalan `.`/`~`/`/`, drive letter, atau memuat
|
|
935
|
+
// pemisah path) supaya pola grep/awk seperti `a[0-9]` tidak terblokir.
|
|
936
|
+
const pathLike = /^[.~/]|^[A-Za-z]:[\\/]|[/\\]/.test(t)
|
|
937
|
+
if (t.includes("*") || (pathLike && /[*?[]/.test(t))) {
|
|
777
938
|
// Wildcard di READER bisa mengembang ke .env/.minicode — tolak bila
|
|
778
939
|
// cwd tersedia (butuh path eksplisit). Tanpa cwd, heuristik sensitif.
|
|
779
940
|
if (cwd != null) return { denied: true, reason: "reader wildcard" }
|
|
780
941
|
if (isSensitive(t) || isOwnedState(t)) return { denied: true, reason: "reader wildcard" }
|
|
781
942
|
}
|
|
943
|
+
// Nama target yang dihitung shell tak bisa dipastikan statis:
|
|
944
|
+
// `cat$(printf ' ')` membaca `.env` tanpa pernah menampakkan nama itu.
|
|
945
|
+
if (/^\$\(|^`/.test(t)) return { denied: true, reason: "reader command substitution" }
|
|
782
946
|
if (isSensitive(t) || isSensitive(resolve(cwd ?? ".", t))) {
|
|
783
947
|
return { denied: true, reason: "sensitive file access" }
|
|
784
948
|
}
|
package/src/policy/compaction.ts
CHANGED
|
@@ -280,9 +280,14 @@ function boundCompactionResult(
|
|
|
280
280
|
store: ContextStore,
|
|
281
281
|
result: readonly import("#minicore/core/types.ts").Message[],
|
|
282
282
|
keepRecentTurns: number,
|
|
283
|
-
targetTokens
|
|
283
|
+
targetTokens: number | undefined,
|
|
284
|
+
maxSummaryChars: number,
|
|
284
285
|
): readonly import("#minicore/core/types.ts").Message[] {
|
|
285
|
-
|
|
286
|
+
// R9 — pagu ringkasan mengikuti jendela (summaryCharBudgetForWindow), bukan
|
|
287
|
+
// 4k konstan. Tanpa ini ringkasan LLM untuk model berjendela raksasa
|
|
288
|
+
// (1M token) yang SUDAH diproduksi dengan budget skala 32k dipangkas ulang
|
|
289
|
+
// ke COMPACTION_SUMMARY_MAX_CHARS, sehingga fakta lama over-discard.
|
|
290
|
+
let bounded = boundSummary(result, maxSummaryChars)
|
|
286
291
|
if (targetTokens !== undefined && estimateMessages(bounded, minicodeEstimator) > targetTokens) {
|
|
287
292
|
bounded = boundedMechanical(store, Math.min(1, keepRecentTurns), targetTokens)
|
|
288
293
|
}
|
|
@@ -307,6 +312,9 @@ export function createLlmCompaction(opts: LlmCompactionOptions = {}): Compaction
|
|
|
307
312
|
? Math.floor((limit as number) * LIMITS.COMPACTION_SUMMARY_TARGET_RATIO)
|
|
308
313
|
: undefined
|
|
309
314
|
}
|
|
315
|
+
// R9 — pagu karakter ringkasan mengikuti jendela (satu sumber, dipakai juga
|
|
316
|
+
// oleh boundCompactionResult agar ringkasan LLM tidak di-clamp balik ke 4k).
|
|
317
|
+
const summaryChars = () => summaryCharBudgetForWindow(opts.getContextWindowTokens?.())
|
|
310
318
|
// F3.1 anti-thrash (state per strategi = per sesi, karena strategy dibuat
|
|
311
319
|
// sekali di setup): kernel memicu kompaksi budget sekali PER TURN, jadi
|
|
312
320
|
// turn panjang dengan jendela penuh-kembali langsung (= satu output raksasa)
|
|
@@ -384,6 +392,7 @@ export function createLlmCompaction(opts: LlmCompactionOptions = {}): Compaction
|
|
|
384
392
|
fallback.compact(store, { keepRecentTurns: 1 }),
|
|
385
393
|
1,
|
|
386
394
|
targetTokens(),
|
|
395
|
+
summaryChars(),
|
|
387
396
|
)
|
|
388
397
|
}
|
|
389
398
|
const progress = before > 0 ? (before - out.length) / before : 1
|
|
@@ -399,7 +408,13 @@ export function createLlmCompaction(opts: LlmCompactionOptions = {}): Compaction
|
|
|
399
408
|
)
|
|
400
409
|
}
|
|
401
410
|
}
|
|
402
|
-
return boundCompactionResult(
|
|
411
|
+
return boundCompactionResult(
|
|
412
|
+
store,
|
|
413
|
+
out,
|
|
414
|
+
cOpts.keepRecentTurns,
|
|
415
|
+
targetTokens(),
|
|
416
|
+
summaryChars(),
|
|
417
|
+
)
|
|
403
418
|
} finally {
|
|
404
419
|
clearTimeout(timer)
|
|
405
420
|
signal.removeEventListener("abort", onAbort)
|
|
@@ -646,11 +661,23 @@ export async function compactWithLlm(
|
|
|
646
661
|
: ""
|
|
647
662
|
return `- tool(${m.name}): ${head(raw, toolHeadLen(m.name, 250))}`
|
|
648
663
|
}
|
|
664
|
+
// F6 — pertahankan instruksi terkini verbatim saat active-turn fold. Jalur
|
|
665
|
+
// mekanikal (compactActiveTurn) menyimpan "Current task/request" mentah; jalur
|
|
666
|
+
// LLM merangkum seluruh prefix lewat summarizer sehingga request persis bisa
|
|
667
|
+
// terparafrase atau hilang — terutama saat satu turn didominasi output tool
|
|
668
|
+
// raksasa. Sertakan request terakhir verbatim (dengan pagu) di awal input
|
|
669
|
+
// summarizer supaya apa yang sebenarnya diminta user tidak menyusut.
|
|
670
|
+
const currentRequest = (() => {
|
|
671
|
+
if (!activeTurn) return ""
|
|
672
|
+
const lastUser = [...prefix].reverse().find((m) => m.role === "user")
|
|
673
|
+
const text = lastUser ? contentToText(lastUser.content).trim() : ""
|
|
674
|
+
return text ? `Current request (verbatim):\n${head(text, 1200)}\n\n` : ""
|
|
675
|
+
})()
|
|
649
676
|
const scrubbedPrefix = scrubSecrets(
|
|
650
|
-
prefix
|
|
651
|
-
|
|
652
|
-
.
|
|
653
|
-
|
|
677
|
+
(currentRequest + prefix.map(lineFor).join("\n")).slice(
|
|
678
|
+
0,
|
|
679
|
+
opts.maxInputChars ?? LIMITS.COMPACTION_LLM_INPUT_MIN_CHARS,
|
|
680
|
+
),
|
|
654
681
|
)
|
|
655
682
|
// Guard anti-injeksi (temuan audit #02): prefix berisi output tool/web/repo
|
|
656
683
|
// tak-terpercaya yang bisa memuat "abaikan instruksi". Tanpa pagar, payload
|
package/src/policy/jail.ts
CHANGED
|
@@ -47,29 +47,20 @@ export function isSensitive(p: string): boolean {
|
|
|
47
47
|
// ("always" palsu!), config (server MCP jahat!), atau membutakan recovery.
|
|
48
48
|
// BACA tetap boleh (observability/debug). Pola di-anchor ke segmen
|
|
49
49
|
// `.minicode/` agar file user bernama mirip di tempat lain tak kena.
|
|
50
|
-
// Pengecualian:
|
|
51
|
-
//
|
|
52
|
-
//
|
|
50
|
+
// Pengecualian: restore dari `.minicode/.trash/` (ditangani di permission.ts,
|
|
51
|
+
// bukan di sini, agar arahnya eksplisit).
|
|
52
|
+
//
|
|
53
|
+
// `.minicode/hooks/` TIDAK lagi dikecualikan (audit 2026-11-12): hook
|
|
54
|
+
// dieksekusi otomatis lewat scan direktori begitu `MINICODE_HOOKS=1`, jadi
|
|
55
|
+
// carve-out tulis = model/prompt-injection bisa menanam kode lalu menjalankannya
|
|
56
|
+
// di sesi yang sama, di luar permission/jail/sandbox. Skrip hook sekarang
|
|
57
|
+
// dibuat operator di luar sesi (shell manual), bukan lewat file tool.
|
|
53
58
|
const OWNED_STATE_RE = /(?:^|[/\\])\.minicode(?:[/\\]|$)/i
|
|
54
59
|
|
|
55
|
-
// Skrip hooks milik user (.minicode/hooks/): BUKAN state runtime — alur
|
|
56
|
-
// legit "buatkan hook" menulis lewat tool (dikunci test delegate-audit).
|
|
57
|
-
// Registrasi eksekusi tetap dikunci (allowlist.json owned), jadi file
|
|
58
|
-
// titipan tak jalan sendiri. skills//steering/MEMORY tetap terkunci:
|
|
59
|
-
// isinya ikut ke konteks (persistensi prompt-injection), user kelola via shell.
|
|
60
|
-
const HOOKS_RE = /(?:^|[/\\])\.minicode[/\\]hooks(?:[/\\]|$)/i
|
|
61
|
-
|
|
62
|
-
/** true bila jalurargumen tool menunjuk skrip hooks user (carve-out tulis). */
|
|
63
|
-
export function isHookScript(p: string): boolean {
|
|
64
|
-
if (!p || DOTDOT_SEG_RE.test(p)) return false
|
|
65
|
-
return HOOKS_RE.test(p)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
60
|
export function isOwnedState(p: string): boolean {
|
|
69
61
|
if (!p) return false
|
|
70
62
|
const cleaned = cleanPathForMatch(p)
|
|
71
|
-
|
|
72
|
-
return matchesOwned && !isHookScript(p) && !isHookScript(cleaned)
|
|
63
|
+
return OWNED_STATE_RE.test(p) || OWNED_STATE_RE.test(cleaned)
|
|
73
64
|
}
|
|
74
65
|
/**
|
|
75
66
|
* Kunci realpath untuk owned-state (temuan audit 2026-09-22 F-CRIT): cek
|
|
@@ -90,10 +81,7 @@ export function isOwnedStateReal(p: string, root: string): boolean {
|
|
|
90
81
|
let tail = ""
|
|
91
82
|
for (let i = 0; i < 64; i++) {
|
|
92
83
|
try {
|
|
93
|
-
|
|
94
|
-
// Carve-out hooks: skrip hooks sah tetap lewat kunci ini (registrasi
|
|
95
|
-
// eksekusinya terkunci di allowlist.json yang owned).
|
|
96
|
-
return isOwnedState(real) && !isHookScript(real)
|
|
84
|
+
return isOwnedState(resolve(realpathSync(probe), tail))
|
|
97
85
|
} catch {
|
|
98
86
|
const parent = dirname(probe)
|
|
99
87
|
if (parent === probe) break
|
package/src/policy/permission.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
import { inspectBashCommand } from "./bash-guard.ts"
|
|
19
19
|
import {
|
|
20
20
|
isCwdOutsideRoot,
|
|
21
|
-
isHookScript,
|
|
22
21
|
isOwnedState,
|
|
23
22
|
isOwnedStateReal,
|
|
24
23
|
isRealPathOutsideRoot,
|
|
@@ -649,7 +648,10 @@ export function createPermissionHandler(
|
|
|
649
648
|
const v = inspectBashCommand(cmd, root)
|
|
650
649
|
return v.denied ? (v.reason ?? "blocked command") : null
|
|
651
650
|
} catch {
|
|
652
|
-
|
|
651
|
+
// Fail-closed: guard yang melempar exception bukan bukti perintah aman.
|
|
652
|
+
// Sebelumnya `return null` membuat setiap error internal menjadi ALLOW —
|
|
653
|
+
// satu bug di guard cukup untuk membuka seluruh permukaan eksekusi.
|
|
654
|
+
return "bash-guard internal error — command refused (fail-closed)"
|
|
653
655
|
}
|
|
654
656
|
}
|
|
655
657
|
|
|
@@ -908,9 +910,10 @@ export function createPermissionHandler(
|
|
|
908
910
|
? ([(earlyArgs?.from as string) ?? "", (earlyArgs?.to as string) ?? ""] as const)
|
|
909
911
|
: ([(earlyArgs?.path as string) ?? ""] as const)
|
|
910
912
|
// Carve-out sah (string mentah): restore `.minicode/.trash/` →
|
|
911
|
-
// workspace
|
|
912
|
-
//
|
|
913
|
-
//
|
|
913
|
+
// workspace — satu-satunya gerak sah yang menyentuh state. Cek string
|
|
914
|
+
// dulu supaya jalur sah (yang target nyatanya justru `.minicode/`)
|
|
915
|
+
// tidak ikut ditahan kunci realpath. Skrip hooks TIDAK lagi punya
|
|
916
|
+
// carve-out (lihat jail.ts): hook auto-dieksekusi saat opt-in.
|
|
914
917
|
if (call.name === "move_file") {
|
|
915
918
|
const f = rawTargets[0] ?? ""
|
|
916
919
|
const t = rawTargets[1] ?? ""
|
|
@@ -925,7 +928,7 @@ export function createPermissionHandler(
|
|
|
925
928
|
}
|
|
926
929
|
} else {
|
|
927
930
|
const p = rawTargets[0] ?? ""
|
|
928
|
-
if (p !== "" && (isOwnedState(p) ||
|
|
931
|
+
if (p !== "" && (isOwnedState(p) || isOwnedStateReal(p, root))) {
|
|
929
932
|
return deny(call, "jail: owned state")
|
|
930
933
|
}
|
|
931
934
|
}
|
|
@@ -208,14 +208,16 @@ export function installUpdate(version: string, runner?: InstallRunner): boolean
|
|
|
208
208
|
const run: InstallRunner =
|
|
209
209
|
runner ??
|
|
210
210
|
((cmd, args, opts) => {
|
|
211
|
-
// Windows: npm adalah .cmd → butuh shell
|
|
212
|
-
//
|
|
211
|
+
// Windows: npm adalah .cmd → butuh shell. Output npm dipipe dan
|
|
212
|
+
// dibuang — auto-update kini berjalan di belakang bar loading, jadi
|
|
213
|
+
// progres raw npm malah mengotori baris bar (sebelumnya stdio
|
|
214
|
+
// inherit menimpa spinner).
|
|
213
215
|
// Timeout 120 dtk: tanpa ini spawnSync memblokir event-loop selamanya
|
|
214
216
|
// saat npm lambat (AV/UAC di Windows 15–60 dtk) — timer abort 1.8 dtk
|
|
215
|
-
// dan
|
|
217
|
+
// dan bar ikut beku sehingga terlihat hang. Timeout = gagal jujur
|
|
216
218
|
// lalu lanjut versi lama, bukan gantung.
|
|
217
219
|
const r = spawnSync(cmd, args, {
|
|
218
|
-
stdio: "
|
|
220
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
219
221
|
shell: process.platform === "win32",
|
|
220
222
|
...(opts?.cwd ? { cwd: opts.cwd } : {}),
|
|
221
223
|
timeout: 120_000,
|
|
@@ -947,7 +947,7 @@ export function machineError(e: unknown): MachineError {
|
|
|
947
947
|
if (kind === "timeout" || (/timeout|timed out/i.test(message) && kind !== "aborted"))
|
|
948
948
|
return { category: "AGENT_ERROR", message, action: "retry with a higher --timeout" }
|
|
949
949
|
if (kind === "max_steps_exceeded" || /max.?steps/i.test(message))
|
|
950
|
-
return { category: "AGENT_ERROR", message, action: "raise --max-steps" }
|
|
950
|
+
return { category: "AGENT_ERROR", message, action: "continue via /resume or raise --max-steps" }
|
|
951
951
|
if (kind === "aborted" || /^(run cancelled|turn aborted|aborted)/i.test(message))
|
|
952
952
|
return { category: "USER_ERROR", message }
|
|
953
953
|
if (/refusing|denied|not allowed|not permitted/i.test(message))
|
|
@@ -134,7 +134,7 @@ export function createAnthropicProvider(config: AnthropicConfig): ModelProvider
|
|
|
134
134
|
throw new ProviderError("network", e instanceof Error ? e.message : String(e))
|
|
135
135
|
}
|
|
136
136
|
if (!response.ok) {
|
|
137
|
-
const txt = await readProviderErrorBody(response).catch(() => "")
|
|
137
|
+
const txt = await readProviderErrorBody(response, signal).catch(() => "")
|
|
138
138
|
throw toAnthropicError(response.status, txt, response.headers)
|
|
139
139
|
}
|
|
140
140
|
if (!response.body) throw new ProviderError("network", "empty response body")
|
|
@@ -413,9 +413,19 @@ function toAnthropicError(status: number, body: string, headers: Headers): Provi
|
|
|
413
413
|
if (status === 401 || status === 403)
|
|
414
414
|
return new ProviderError("auth", `auth failed (${status}): ${detail}`)
|
|
415
415
|
if (status === 400 || status === 422) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
// Samakan frasa deteksi overflow dengan adapter lain (openai-compat /
|
|
417
|
+
// responses): gateway kompatibel-Anthropic bisa memfrasakan jendela konteks
|
|
418
|
+
// sebagai "context window"/"input is too long" — tanpa frasa itu, kasus
|
|
419
|
+
// compact-and-retry jatuh jadi invalid_request terminal.
|
|
420
|
+
const lower = body.toLowerCase()
|
|
421
|
+
const isCtx = [
|
|
422
|
+
"context_length",
|
|
423
|
+
"context length",
|
|
424
|
+
"maximum context",
|
|
425
|
+
"prompt is too long",
|
|
426
|
+
"input is too long",
|
|
427
|
+
"context window",
|
|
428
|
+
].some((phrase) => lower.includes(phrase))
|
|
419
429
|
return new ProviderError(
|
|
420
430
|
isCtx ? "context_length_exceeded" : "invalid_request",
|
|
421
431
|
`${status}: ${detail}`,
|
|
@@ -140,7 +140,7 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
140
140
|
// Bila request gagal saat membawa previous_response_id, hapus ID tersebut
|
|
141
141
|
// agar turn berikutnya tidak macet permanen pada ID yang kedaluwarsa/ditolak.
|
|
142
142
|
if (prev) lastResponseByModel.delete(modelKey)
|
|
143
|
-
const txt = await readProviderErrorBody(res).catch(() => "")
|
|
143
|
+
const txt = await readProviderErrorBody(res, signal).catch(() => "")
|
|
144
144
|
const retryAfter = res.headers.get("retry-after")
|
|
145
145
|
if (res.status === 429) {
|
|
146
146
|
const ms = retryAfter ? Number(retryAfter) * 1000 : undefined
|