minicode-ai 0.21.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/commands/exec.ts +44 -1
- package/cli/commands.ts +5 -2
- package/cli/setup.ts +24 -0
- package/docs/TERMINAL_CONTRACT.md +30 -7
- package/docs/architecture.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +2 -1
- package/docs/environment.md +1 -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/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/footer.ts +2 -2
- package/src/ui/i18n/en.ts +9 -1
- package/src/ui/i18n/id.ts +9 -1
- package/src/ui/input/prompt-engine.ts +6 -0
- package/src/ui/render/diff.ts +51 -2
- package/src/ui/render/highlight.ts +68 -37
- package/src/ui/render/sanitize.ts +5 -1
- package/src/ui/render/session-summary.ts +6 -4
- package/src/ui/render/table-grid.ts +123 -13
- package/src/ui/render/table.ts +4 -2
- package/src/ui/render/theme.ts +11 -3
- package/src/ui/render/width.ts +35 -6
- package/src/ui/render/wrap.ts +28 -6
- package/src/ui/runtime/loading-bar.ts +17 -5
- 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/tui/app.ts +57 -20
- package/src/ui/tui/transcript.ts +42 -7
- package/vendor/minicore/src/providers/openai-compat.ts +30 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MiniCode
|
|
2
2
|
|
|
3
|
-
MiniCode is an open-source terminal coding agent built on the
|
|
3
|
+
MiniCode is an open-source terminal coding agent built on the vendored MiniCore kernel (host-editable since v0.16.0). It is zero-dependency (Bun is the only runtime). It inspects and edits a workspace, runs local tools, and connects to the AI providers and MCP/LSP servers you configure.
|
|
4
4
|
|
|
5
5
|
Interactive sessions run as a fullscreen TUI; one-shot and automation runs flow to the shell scrollback or a machine-readable JSONL stream. Every tool action is visible in the ledger, file changes are jailed to the workspace, and sensitive actions are gated behind your permission. Prompts and relevant workspace context are sent to the provider you configure; MCP and LSP servers may receive data or perform external effects. MiniCode itself sends no telemetry — traces are local-only (`MINICODE_TELEMETRY=0` to disable).
|
|
6
6
|
|
package/cli/commands/exec.ts
CHANGED
|
@@ -34,6 +34,14 @@ function writeMachineLine(line: string): void {
|
|
|
34
34
|
process.stdout.write(`${cleanUntrusted(scrubSecrets(line), false)}\n`)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** Prompt lanjutan (Phase D auto-continue): minta model menyelesaikan sisa
|
|
38
|
+
* pekerjaan dari titik berhenti, memanfaatkan progres parsial yang sudah
|
|
39
|
+
* durable (safeTurnBoundary + persist). */
|
|
40
|
+
const CONTINUE_PROMPT =
|
|
41
|
+
"Continue from where you left off: an earlier turn hit the tool-step limit " +
|
|
42
|
+
"but its completed steps are preserved. Finish the remaining work now " +
|
|
43
|
+
"(re-read state if needed) and do not start over from scratch."
|
|
44
|
+
|
|
37
45
|
function machineSummary(ok: boolean, fields: Record<string, unknown>): Record<string, unknown> {
|
|
38
46
|
return { schema: MACHINE_SCHEMA, type: "summary", ok, ...fields }
|
|
39
47
|
}
|
|
@@ -186,6 +194,18 @@ export async function handleExec(
|
|
|
186
194
|
)
|
|
187
195
|
timeoutMs = 900_000
|
|
188
196
|
}
|
|
197
|
+
// Phase D — auto-continue (opt-in): pecah tugas panjang menjadi beberapa turn
|
|
198
|
+
// bounded. Saat turn berakhir dengan max_steps_exceeded, kernel SUDAH
|
|
199
|
+
// meng-commit progres parsial (safeTurnBoundary); run lanjutan melanjutkan dari
|
|
200
|
+
// situ alih-alih mati fatal. `--max-turns` menetapkan jumlah turn lanjutan
|
|
201
|
+
// (default 3) — hard cap mencegah loop belanja; --budget tetap mengikat per turn.
|
|
202
|
+
const autoContinue =
|
|
203
|
+
hasFlag(subArgs, "--auto-continue") || process.env.MINICODE_AUTO_CONTINUE === "1"
|
|
204
|
+
const maxTurnsRaw = getArg("--max-turns")
|
|
205
|
+
const autoContinueBudget =
|
|
206
|
+
maxTurnsRaw && Number.isFinite(Number(maxTurnsRaw)) && Number(maxTurnsRaw) > 0
|
|
207
|
+
? Math.min(20, Math.floor(Number(maxTurnsRaw)))
|
|
208
|
+
: 3
|
|
189
209
|
|
|
190
210
|
const ignoredFlags = flagsAfterPromptBoundary(subArgs)
|
|
191
211
|
if (ignoredFlags.length > 0) {
|
|
@@ -296,7 +316,30 @@ export async function handleExec(
|
|
|
296
316
|
)
|
|
297
317
|
})
|
|
298
318
|
try {
|
|
299
|
-
|
|
319
|
+
if (autoContinue) {
|
|
320
|
+
// Lanjutkan sampai selesai / cap tercapai. `isStepLimit` memisahkan
|
|
321
|
+
// "habis langkah" (layak dilanjut) dari error lain (auth/network/dll yang
|
|
322
|
+
// wajib gagal keras). Tiap iterasi = satu turn utuh pada sesi sama; kernel
|
|
323
|
+
// sudah commit progres parsial turn yang gagal (safeTurnBoundary).
|
|
324
|
+
const isStepLimit = (e: unknown): boolean =>
|
|
325
|
+
(e as { kind?: string } | undefined)?.kind === "max_steps_exceeded" ||
|
|
326
|
+
/max.?steps/i.test(String((e as { message?: string } | undefined)?.message ?? ""))
|
|
327
|
+
for (let i = 0; i <= autoContinueBudget; i++) {
|
|
328
|
+
let err: unknown = null
|
|
329
|
+
try {
|
|
330
|
+
await ctx.runPromptWithVerify(i === 0 ? effectivePrompt : CONTINUE_PROMPT)
|
|
331
|
+
} catch (e) {
|
|
332
|
+
err = e
|
|
333
|
+
}
|
|
334
|
+
if (err === null) break
|
|
335
|
+
if (!isStepLimit(err) || i >= autoContinueBudget) throw err
|
|
336
|
+
process.stderr.write(
|
|
337
|
+
`[auto-continue] batas langkah tercapai — melanjutkan (turn lanjutan ${i + 1}/${autoContinueBudget})\n`,
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
await ctx.runPromptWithVerify(effectivePrompt)
|
|
342
|
+
}
|
|
300
343
|
// Harness-P1: exec sebelumnya mengabaikan --budget total (flag diteruskan
|
|
301
344
|
// tapi tak pernah diperiksa). Samakan dengan one-shot: over → exit 1.
|
|
302
345
|
const ue = ctx.usage.getSession(ctx.modelRef.current)
|
package/cli/commands.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "../src/task/scheduler-observability.ts"
|
|
13
13
|
import { type MsgKey, t } from "../src/ui/i18n/locale.ts"
|
|
14
14
|
import { formatUsd } from "../src/ui/render/money.ts"
|
|
15
|
+
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
15
16
|
import { glyphs } from "../src/ui/render/theme.ts"
|
|
16
17
|
import { padToWidth } from "../src/ui/render/width.ts"
|
|
17
18
|
|
|
@@ -594,11 +595,13 @@ export async function handleBuiltinCommand(
|
|
|
594
595
|
if (cfg.providers.length === 0) console.log(t("cmd.noProviders"))
|
|
595
596
|
else console.log(t("cmd.noChanges"))
|
|
596
597
|
} else {
|
|
598
|
+
// id provider datang dari probe jaringan (tak-terpercaya): paritas
|
|
599
|
+
// dengan `minicode providers sync` yang sudah menyaring ANSI.
|
|
597
600
|
for (const r of updated) {
|
|
598
|
-
console.log(` ${glyphs.check} ${r.id}: ${r.from} → ${r.to}`)
|
|
601
|
+
console.log(` ${glyphs.check} ${sanitizeAnsiLine(r.id)}: ${r.from} → ${r.to}`)
|
|
599
602
|
}
|
|
600
603
|
for (const f of failed) {
|
|
601
|
-
console.log(` ${glyphs.cross} ${f.id}: ${f.reason}`)
|
|
604
|
+
console.log(` ${glyphs.cross} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`)
|
|
602
605
|
}
|
|
603
606
|
// "Restart" hanya jujur bila ADA model baru — tanpa updated, restart
|
|
604
607
|
// tak mengubah apa pun (sebelumnya selalu dicetak, menyesatkan saat
|
package/cli/setup.ts
CHANGED
|
@@ -2395,6 +2395,30 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2395
2395
|
})
|
|
2396
2396
|
} catch {}
|
|
2397
2397
|
})
|
|
2398
|
+
// ── Phase C: soft-cap warning (host-side) ──
|
|
2399
|
+
// Peringatkan SEKALI per turn saat langkah mendekati cap (~85%) supaya operator
|
|
2400
|
+
// tahu batas akan tercapai dan bisa memecah/mendelegasikan sebelum tabrakan
|
|
2401
|
+
// keras di "Batas langkah tool tercapai". Operator-facing (stderr); menembus
|
|
2402
|
+
// ke MODEL butuh seam system-prompt terpisah (di luar scope fase ini).
|
|
2403
|
+
let softStepWarned = false
|
|
2404
|
+
session.events.on("turn:started", () => {
|
|
2405
|
+
softStepWarned = false
|
|
2406
|
+
})
|
|
2407
|
+
session.events.on("step:completed", (e) => {
|
|
2408
|
+
try {
|
|
2409
|
+
if (softStepWarned) return
|
|
2410
|
+
const cap = maxSteps ?? LIMITS.DEFAULT_MAX_STEPS
|
|
2411
|
+
const idx = (e.step as { index?: unknown })?.index
|
|
2412
|
+
if (typeof idx !== "number") return
|
|
2413
|
+
const threshold = Math.max(1, Math.floor(cap * 0.85))
|
|
2414
|
+
if (idx >= threshold && idx < cap) {
|
|
2415
|
+
softStepWarned = true
|
|
2416
|
+
warnLine(
|
|
2417
|
+
`mendekati batas langkah (step ${idx}/${cap}) — bungkus hasil, delegasikan, atau siapkan /resume`,
|
|
2418
|
+
)
|
|
2419
|
+
}
|
|
2420
|
+
} catch {}
|
|
2421
|
+
})
|
|
2398
2422
|
// ── P2.11 observasi verifikasi (observation-only) ──
|
|
2399
2423
|
// Bukti kanonik hidup di jurnal mutasi; presentasi hanya mengamatinya.
|
|
2400
2424
|
// Setiap tool selesai (dan setiap turn selesai untuk verifikasi susulan),
|
|
@@ -187,14 +187,21 @@ Non-TTY (pipe/redirect/CI/file): **0 cursor control, 0 alternate screen,
|
|
|
187
187
|
hilang, id selamat).
|
|
188
188
|
- Form dalam popup (`form.ts`): field text/secret(mask `•`)/select/confirm,
|
|
189
189
|
Tab/↑↓ pindah, ←/→ pilih atau geser kursor, Enter validasi+submit, Esc
|
|
190
|
-
dua-tahap (tekan-1
|
|
191
|
-
hilang sekali tekan); error
|
|
192
|
-
diparkir di field aktif
|
|
193
|
-
|
|
190
|
+
dua-tahap (tekan-1 KEMBALIKAN nilai bawaan field aktif — text/secret/select/
|
|
191
|
+
confirm, tekan-2 batal — isi tidak pernah hilang sekali tekan); error
|
|
192
|
+
validasi merah dalam box; kursor terminal diparkir di field aktif dan field
|
|
193
|
+
aktif SELALU terlihat (jendela body digeser via `focusRow` bila kotak
|
|
194
|
+
terpotong). Add/edit provider, delete confirm, dan wizard input WAJIB lewat
|
|
195
|
+
ini (bukan askLine liar di luar kotak).
|
|
196
|
+
- Picker ber-filter: Esc-1 mengosongkan filter (= kembali ke nilai bawaan
|
|
197
|
+
pencarian, analogen revert-to-default I21), Esc-2 menutup. Ctrl+U juga
|
|
198
|
+
mengosongkan filter. Tidak ada draft yang hilang tanpa undo.
|
|
194
199
|
- Dropdown `/` tetap inline menempel prompt (harus mengikuti kursor ketik):
|
|
195
200
|
berbingkai, terhapus di SEMUA jalur keluar.
|
|
196
201
|
- **Kursor diparkir di SEMUA permukaan** (picker/manager/form/App): baris
|
|
197
|
-
item/field aktif — bukan ditinggal di posisi paint terakhir.
|
|
202
|
+
item/field aktif — bukan ditinggal di posisi paint terakhir. Kursor idle App
|
|
203
|
+
berada tepat setelah prompt `minicode ›` (prompt tidak lagi disembunyikan
|
|
204
|
+
setelah Esc/Enter kosong — I13).
|
|
198
205
|
- **i18n dwibahasa** (`src/ui/i18n/`): kamus statis `en.ts`/`id.ts` (id WAJIB
|
|
199
206
|
kunci = en — tsc mengawal), `t(key, params)` interpolasi `{nama}`, fallback
|
|
200
207
|
kunci hilang → en. Prioritas: `/lang` (sesi) > `MINICODE_LANG` >
|
|
@@ -563,7 +570,9 @@ panjang).
|
|
|
563
570
|
> [Gap proteksi](#peta-proteksi-dan-gap-tersisa) di bawah — jangan
|
|
564
571
|
> dipoles dengan mengganti kata-kata.
|
|
565
572
|
|
|
566
|
-
- `test/tui-app.test.ts` — I1/I13/I14/I17-I20 (
|
|
573
|
+
- `test/tui-app.test.ts` — I1/I13/I14/I17-I20 (baris indikator dipotong ke
|
|
574
|
+
lebar frame walau locale id 51 kolom; prompt idle bertahan setelah Esc;
|
|
575
|
+
`repaint()` tak melukis saat suspended; boot/exit pairing, transcript
|
|
567
576
|
viewport, mouse-wheel/drag-selection/PgUp/PgDn scroll + indikator, prompt
|
|
568
577
|
editing, dots/timer, status bar, Esc-only abort, quit, suspend/resume,
|
|
569
578
|
busy-freeze, live repaint; I14: Home/End jump + Shift+PgUp/PgDn + hint abort
|
|
@@ -619,7 +628,21 @@ panjang).
|
|
|
619
628
|
- `test/tui-popup.test.ts` — I16 (komposit di atas transkrip, anti-bocor,
|
|
620
629
|
anti-hantu).
|
|
621
630
|
- `test/form.test.ts` — I21 (field, validasi, secret, select, confirm, batal;
|
|
622
|
-
Esc-1 kembalikan prefill
|
|
631
|
+
Esc-1 kembalikan prefill untuk text/secret DAN pilihan bawaan untuk
|
|
632
|
+
select/confirm, Esc-2 batal; Tab+teks dalam satu chunk tidak menulis ke field
|
|
633
|
+
lama; field aktif di luar tinggi kotak tetap terlihat).
|
|
634
|
+
- `test/render-audit-2026-11.test.ts` — audit renderer 2026-11-12 (proyeksi
|
|
635
|
+
pending dimemo per baris → tidak O(n²); SGR majemuk diproses berurutan di
|
|
636
|
+
`truncateToWidth`; indentasi `wordWrap`; SGR opak di highlight; cap input &
|
|
637
|
+
guard LCS diff; lebar tabel untuk grapheme 2 kolom; kop sesi lewat i18n;
|
|
638
|
+
`dialogBox` menggeser jendela ke `focusRow`) **plus penutupan kebocoran**:
|
|
639
|
+
`U+2028/U+2029` jadi spasi di jalur satu-baris, dan paste composer tidak
|
|
640
|
+
bisa menyelundupkan CSI C1 (`U+009B`) — buffer composer dilukis apa adanya,
|
|
641
|
+
jadi gate-nya ada di `prompt-engine` sebelum buffer terbentuk. Jalur pesan
|
|
642
|
+
error layar (`picker`, `model-manager`/`provider-manager` fail-open) dan
|
|
643
|
+
hasil probe jaringan `cli/commands.ts` (`/sync`) memakai `cleanUntrusted` /
|
|
644
|
+
`sanitizeAnsiLine`; hook `?25h` loading-bar didaftarkan lazy agar modul yang
|
|
645
|
+
sekadar di-import tidak menulis byte ke alt-screen.
|
|
623
646
|
- `test/approval-tui.test.ts` — I23 (blok + keputusan tercatat, deny;
|
|
624
647
|
stdout-pipe tanpa sink = deny).
|
|
625
648
|
- `test/footer-render.test.ts` — I13 (label title case, Work Mode kiri dan Permission Mode cyan rata kanan dekat konteks, posisi kolom stabil, fallback terminal sempit, ikon gembok 🔒 terang/redup).
|
package/docs/architecture.md
CHANGED
|
@@ -9,15 +9,19 @@ Roadmap fase pemilik tidak tersedia di checkout ini; jangan simpulkan status fas
|
|
|
9
9
|
```
|
|
10
10
|
L1 cli/ + src/ui/ → controller tipis + presentation mandiri
|
|
11
11
|
L2 src/ non-ui → agen: tools, agents, hooks, policy, providers, mcp, lsp, session, skills
|
|
12
|
-
L3 vendor/minicore → kernel STATE/MODEL/ACTION/LOOP (
|
|
12
|
+
L3 vendor/minicore → kernel STATE/MODEL/ACTION/LOOP (vendored, host-editable, zero-dep, via #minicore)
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Kernel di-vendor dan **dapat diedit di host** sejak v0.16.0 (lihat
|
|
16
|
+
[catatan vendor MiniCore](https://github.com/minilabs-id/minicode/blob/main/vendor/minicore/VENDOR.md));
|
|
17
|
+
commit sumber `0d33571` hanya referensi historis provenance, bukan invarian
|
|
18
|
+
keras. Impor kernel aplikasi hanya melalui `#minicore`.
|
|
17
19
|
|
|
18
20
|
Patch host yang diperlukan runtime tersimpan di `scripts/vendor-overlays/` dan
|
|
19
|
-
diterapkan saat sinkronisasi vendor
|
|
20
|
-
|
|
21
|
+
diterapkan saat sinkronisasi vendor. `bun run vendor:check` masih bisa dipakai
|
|
22
|
+
sebagai alat diagnosa provenance, tetapi bukan gate: hash yang tercatat di
|
|
23
|
+
`VENDOR.md` adalah checkpoint historis dan tidak ikut berubah saat kernel
|
|
24
|
+
diedit di host.
|
|
21
25
|
|
|
22
26
|
- `cli/` boleh impor `src/ui/` + `src/`; `src/` non-ui dilarang impor `src/ui/`; `src/ui/` dilarang impor `cli/`, `src/` non-ui, `#minicore`. Dijaga `test/ui-boundary.test.ts`.
|
|
23
27
|
- Satu-satunya jendela UI↔luar: `src/ui/contract.ts` (`UiEvent/UiBus/UiStep/UiExecution`).
|
package/docs/concepts.md
CHANGED
|
@@ -6,7 +6,7 @@ Minicode itu apa, kenapa dibangun begitu, dan kenapa beberapa hal sengaja tidak
|
|
|
6
6
|
|
|
7
7
|
| Nama | Apa |
|
|
8
8
|
|---|---|
|
|
9
|
-
| **MiniCore** | Kernel runtime `STATE / MODEL / ACTION / LOOP`.
|
|
9
|
+
| **MiniCore** | Kernel runtime `STATE / MODEL / ACTION / LOOP`. Zero-dependency, di-vendor ke `vendor/minicore`; dapat diedit di host sejak v0.16.0 (angka provenance historis dicatat di `vendor/minicore/VENDOR.md`). Bukan dependency — di-resolve lewat subpath imports `#minicore` |
|
|
10
10
|
| **Minicode** | Layer agencode di atasnya: tools, sub-agents, skills, hooks, policy/sandbox, providers, MCP/LSP, memory, sessions, repo-map, verifier, dan CLI dengan TUI interaktif serta jalur non-interaktif shell-first |
|
|
11
11
|
|
|
12
12
|
|
package/docs/contributing.md
CHANGED
|
@@ -52,7 +52,8 @@ Batas 4.096 KiB disetujui pemilik pada 2026-11-11 untuk rilis v0.21.0. Jangan me
|
|
|
52
52
|
Gerbang lain:
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
bun run gate:bash #
|
|
55
|
+
bun run gate:bash # korpus pola serangan + perintah sah (auto & allowlist) → 0 bypass / 0 over-block
|
|
56
|
+
# hitungan tercetak oleh probe itu sendiri; jangan disalin ke dokumen
|
|
56
57
|
bun run bench:smoke # fake, CI-safe
|
|
57
58
|
bun run vendor:check # provenance MiniCore (soft; vendor host-editable sejak v0.16.0)
|
|
58
59
|
```
|
package/docs/environment.md
CHANGED
|
@@ -69,6 +69,7 @@ Variabel yang paling menentukan perilaku (sisanya referensi di bawah):
|
|
|
69
69
|
|---|---|
|
|
70
70
|
| `MINICODE_BUDGET_STRICT` | `1` → penegasan eksplisit fail-closed (cost tak dikenal + pemakaian = over; kini juga default `--budget`) |
|
|
71
71
|
| `MINICODE_MAX_TURNS` | Batas keras maksimum jumlah turn per sesi (termasuk carry-forward lintas `--resume`; bilangan ≥1) |
|
|
72
|
+
| `MINICODE_AUTO_CONTINUE` | `1` → pada `exec`, saat turn berakhir `max_steps_exceeded`, lanjutkan turn pada sesi yang sama (progres parsial sudah durable) alih-alih gagal; dibatasi `--max-turns` (default 3) |
|
|
72
73
|
| `MINICODE_ALLOW_LOCAL_CONFIG` | `1` → percayai config lokal workspace (default: diabaikan) |
|
|
73
74
|
|
|
74
75
|
## Terminal & aksesibilitas
|
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
|
}
|