minicode-ai 0.14.6 → 0.20.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 +6 -4
- package/cli/args.ts +20 -8
- package/cli/commands/exec.ts +17 -14
- package/cli/commands/openwork.ts +1 -1
- package/cli/commands.ts +39 -23
- package/cli/index.ts +29 -7
- package/cli/model-manager.ts +1 -1
- package/cli/router.ts +22 -9
- package/cli/setup.ts +77 -35
- package/cli/tui.ts +179 -25
- package/docs/CONTROL-PLANE-MAP.md +7 -5
- package/docs/OUTPUT_EVENT_MODEL.md +4 -3
- package/docs/OUTPUT_PROTOCOL_SPEC.md +1 -1
- package/docs/OUTPUT_RENDERING_SPEC.md +16 -4
- package/docs/OUTPUT_UX_RULES.md +38 -32
- package/docs/P14_OPEN_WORK.md +290 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +36 -22
- package/docs/TERMINAL_CONTRACT.md +89 -17
- package/docs/UI_RENDER_PIPELINE.md +47 -8
- package/docs/agents.md +1 -1
- package/docs/architecture.md +10 -8
- package/docs/autonomous-scheduler.md +142 -0
- package/docs/choosing-mode.md +4 -2
- package/docs/cli.md +11 -9
- package/docs/concepts.md +5 -5
- package/docs/config-providers.md +3 -3
- package/docs/config.md +1 -1
- package/docs/contributing.md +7 -9
- package/docs/environment.md +8 -5
- package/docs/getting-started.md +5 -5
- package/docs/mcp-lsp.md +2 -2
- package/docs/memory-sessions.md +3 -3
- package/docs/policy-sandbox.md +7 -4
- package/docs/pricing-budget.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/repl.md +11 -8
- package/docs/security-model.md +4 -2
- package/docs/security.md +9 -8
- package/docs/skills.md +2 -2
- package/docs/terminal.md +10 -2
- package/docs/tools.md +4 -4
- package/docs/troubleshooting.md +3 -3
- package/docs/verify-benchmark.md +0 -3
- package/package.json +9 -18
- package/scripts/vendor-overlays/minicode-context.patch +1 -1
- package/src/app/mentions.ts +1 -1
- package/src/app/rag-layer.ts +11 -2
- package/src/app/session.ts +128 -10
- package/src/constants.ts +32 -1
- package/src/daemon/client.ts +11 -6
- package/src/daemon/control.ts +2 -9
- package/src/daemon/resource.ts +5 -4
- package/src/hooks/run.ts +5 -6
- package/src/lib/keystore.ts +11 -9
- package/src/lib/net.ts +8 -3
- package/src/lib/safe-open.ts +29 -5
- package/src/lib/trusted-exec.ts +4 -1
- package/src/lsp/client.ts +9 -10
- package/src/mcp/http-transport.ts +1 -1
- package/src/mcp/server.ts +17 -7
- package/src/memory/files.ts +2 -1
- package/src/memory/vector.ts +25 -16
- package/src/policy/bash-guard.ts +58 -16
- package/src/policy/bpe.ts +110 -0
- package/src/policy/compaction.ts +139 -22
- package/src/policy/consequence-engine.ts +3 -3
- package/src/policy/context-window.ts +43 -1
- package/src/policy/context.ts +50 -12
- package/src/policy/jail.ts +48 -3
- package/src/policy/no-progress.ts +15 -8
- package/src/policy/permission.ts +243 -5
- package/src/policy/tokenizer-registry.ts +104 -0
- package/src/policy/usage.ts +20 -13
- package/src/policy/verifier.ts +7 -4
- package/src/policy/work-mode.ts +9 -5
- package/src/presentation/adapter.ts +8 -4
- package/src/presentation/events.ts +2 -2
- package/src/presentation/label.ts +3 -3
- package/src/presentation/model.ts +4 -0
- package/src/presentation/projection.ts +10 -2
- package/src/presentation/store.ts +2 -2
- package/src/providers/anthropic.ts +13 -3
- package/src/providers/responses.ts +16 -6
- package/src/runtime/capability.ts +22 -4
- package/src/runtime/child-execution.ts +1 -1
- package/src/runtime/composition.ts +5 -5
- package/src/runtime/execution-journal.ts +13 -7
- package/src/runtime/execution-registry.ts +1 -1
- package/src/runtime/production-execution.ts +7 -6
- package/src/runtime/production-runtime.ts +2 -2
- package/src/runtime/runtime-capabilities.ts +1 -1
- package/src/runtime/runtime-status-facts.ts +1 -1
- package/src/runtime/runtime-task-admission.ts +2 -2
- package/src/sandbox/os.ts +4 -3
- package/src/session/checkpoint.ts +29 -4
- package/src/session/context-assembly.ts +8 -1
- package/src/session/context-identity.ts +2 -2
- package/src/session/context-projection.ts +36 -11
- package/src/session/persistence.ts +22 -11
- package/src/task/autonomous-context.ts +2 -3
- package/src/task/autonomous-policy.ts +3 -3
- package/src/task/model.ts +2 -2
- package/src/task/production-scheduler.ts +2 -2
- package/src/task/scheduler-observability.ts +1 -0
- package/src/task/scheduler.ts +3 -2
- package/src/task/scheduling-policy.ts +2 -1
- package/src/task/trigger.ts +5 -5
- package/src/tools/git.ts +22 -4
- package/src/tools/lsp.ts +10 -8
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +1 -1
- package/src/tools/web_fetch.ts +6 -2
- package/src/tools/web_search.ts +2 -1
- package/src/ui/assistant/simple.ts +42 -33
- package/src/ui/contract.ts +4 -0
- package/src/ui/footer.ts +63 -12
- package/src/ui/i18n/en.ts +14 -2
- package/src/ui/i18n/id.ts +14 -2
- package/src/ui/input/prompt-engine.ts +36 -10
- package/src/ui/render/cells.ts +320 -0
- package/src/ui/render/composer-wrap.ts +73 -0
- package/src/ui/render/detail.ts +2 -2
- package/src/ui/render/diff.ts +14 -5
- package/src/ui/render/highlight.ts +4 -4
- package/src/ui/render/ledger.ts +47 -0
- package/src/ui/render/markdown.ts +12 -5
- package/src/ui/render/session-summary.ts +50 -0
- package/src/ui/render/table-grid.ts +134 -6
- package/src/ui/render/theme.ts +49 -4
- package/src/ui/render/width.ts +91 -4
- package/src/ui/render/wrap.ts +5 -3
- package/src/ui/runtime/screen.ts +100 -22
- package/src/ui/runtime/statusline.ts +26 -0
- package/src/ui/screens/model-manager.ts +1 -1
- package/src/ui/session-state.ts +27 -1
- package/src/ui/tui/app.ts +336 -65
- package/src/ui/tui/transcript.ts +335 -104
- package/vendor/minicore/VENDOR.md +16 -12
- package/vendor/minicore/src/core/events.ts +1 -0
- package/vendor/minicore/src/core/loop.ts +11 -1
- package/vendor/minicore/src/core/session.ts +39 -0
package/src/lib/safe-open.ts
CHANGED
|
@@ -23,6 +23,32 @@ const O_RDONLY = constants.O_RDONLY
|
|
|
23
23
|
* "blocked sensitive file", "symlink points outside workspace") agar test
|
|
24
24
|
* regex tetap hijau.
|
|
25
25
|
*/
|
|
26
|
+
/**
|
|
27
|
+
* Resolusi path nyata atau ancestor terdekat bila target/induk langsung belum
|
|
28
|
+
* ada (ENOENT), sehingga symlink pada leluhur bertingkat (`symlink_dir/sub/new.txt`)
|
|
29
|
+
* tidak lolos ke path logis saat membuat subdirektori baru.
|
|
30
|
+
*/
|
|
31
|
+
async function resolveRealOrAncestor(abs: string): Promise<string> {
|
|
32
|
+
try {
|
|
33
|
+
return await realpath(abs)
|
|
34
|
+
} catch {
|
|
35
|
+
let probe = dirname(abs)
|
|
36
|
+
let tail = basename(abs)
|
|
37
|
+
for (let i = 0; i < 64; i++) {
|
|
38
|
+
try {
|
|
39
|
+
const realAncestor = await realpath(probe)
|
|
40
|
+
return resolve(realAncestor, tail)
|
|
41
|
+
} catch {
|
|
42
|
+
const parent = dirname(probe)
|
|
43
|
+
if (parent === probe) break
|
|
44
|
+
tail = join(basename(probe), tail)
|
|
45
|
+
probe = parent
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return abs
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
26
52
|
export async function resolveSafePath(
|
|
27
53
|
p: string,
|
|
28
54
|
root: string,
|
|
@@ -31,9 +57,7 @@ export async function resolveSafePath(
|
|
|
31
57
|
if (isSensitive(p)) throw new Error(`blocked sensitive file: ${p}`)
|
|
32
58
|
const abs = isAbsolute(p) ? resolve(p) : resolve(root, p)
|
|
33
59
|
const realRoot = await realpath(root).catch(() => root)
|
|
34
|
-
const
|
|
35
|
-
const fileReal = await realpath(abs).catch(() => null)
|
|
36
|
-
const real = fileReal ?? resolve(realDir, basename(abs))
|
|
60
|
+
const real = await resolveRealOrAncestor(abs)
|
|
37
61
|
if (isPathOutsideRoot(real, realRoot)) throw new Error(`symlink points outside workspace: ${p}`)
|
|
38
62
|
if (isSensitive(real)) throw new Error(`blocked sensitive file: ${p}`)
|
|
39
63
|
return { abs, real }
|
|
@@ -180,14 +204,14 @@ export async function safeStat(abs: string, root: string) {
|
|
|
180
204
|
export async function assertSafeWriteTarget(abs: string, root: string): Promise<string> {
|
|
181
205
|
const realRoot = await realpath(root).catch(() => root)
|
|
182
206
|
const dir = dirname(abs)
|
|
183
|
-
const realDir = await
|
|
207
|
+
const realDir = await resolveRealOrAncestor(dir)
|
|
184
208
|
if (isPathOutsideRoot(realDir, realRoot)) throw new Error(`parent outside workspace: ${abs}`)
|
|
185
209
|
const fileReal = await realpath(abs).catch(() => null)
|
|
186
210
|
// basename (bukan split "/"): path Windows memakai backslash — split "/"
|
|
187
211
|
// mengembalikan seluruh path absolut sehingga resolve() mengabaikan realDir
|
|
188
212
|
// dan verifikasi parent symlink gugur diam-diam di Windows.
|
|
189
213
|
const realAbs = fileReal ?? resolve(realDir, basename(abs))
|
|
190
|
-
if (
|
|
214
|
+
if (isPathOutsideRoot(realAbs, realRoot))
|
|
191
215
|
throw new Error(`symlink points outside workspace: ${abs}`)
|
|
192
216
|
return realAbs
|
|
193
217
|
}
|
package/src/lib/trusted-exec.ts
CHANGED
|
@@ -72,7 +72,10 @@ function resolveUncached(name: string): string {
|
|
|
72
72
|
for (const dir of validPathEntries()) {
|
|
73
73
|
if (windows) {
|
|
74
74
|
for (const ext of exts) {
|
|
75
|
-
const candidate = join(
|
|
75
|
+
const candidate = join(
|
|
76
|
+
dir,
|
|
77
|
+
name.toLowerCase().endsWith(ext.toLowerCase()) ? name : name + ext,
|
|
78
|
+
)
|
|
76
79
|
if (isExecutableFile(candidate)) return candidate
|
|
77
80
|
}
|
|
78
81
|
} else {
|
package/src/lsp/client.ts
CHANGED
|
@@ -109,6 +109,7 @@ class LspConnection {
|
|
|
109
109
|
private async doStart(rootPath: string): Promise<void> {
|
|
110
110
|
this.rootPath = rootPath
|
|
111
111
|
this.stopping = false
|
|
112
|
+
this.killSignal = new AbortController()
|
|
112
113
|
this.proc = spawn(this.entry.command, this.entry.args, {
|
|
113
114
|
stdio: ["pipe", "pipe", "pipe"],
|
|
114
115
|
// env kredensial di-strip; env eksplisit config server menang setelahnya
|
|
@@ -123,10 +124,9 @@ class LspConnection {
|
|
|
123
124
|
this.proc.stdin?.on("error", () => {})
|
|
124
125
|
this.proc.stdout?.on("error", () => {})
|
|
125
126
|
this.proc.on("exit", (code) => {
|
|
126
|
-
const wasStarted = this.started
|
|
127
127
|
this.started = false
|
|
128
128
|
this.starting = undefined
|
|
129
|
-
|
|
129
|
+
this.failAll(new Error(`LSP server ${this.entry.ext} exited (${code})`))
|
|
130
130
|
// [P13.2] Keluar saat kita TIDAK minta = anak hilang: serahkan ke jalur
|
|
131
131
|
// proses (bounded restart / eskalasi jujur). Keluar karena stop() kita
|
|
132
132
|
// sendiri bukan kegagalan.
|
|
@@ -312,16 +312,9 @@ class LspConnection {
|
|
|
312
312
|
|
|
313
313
|
async stop(): Promise<void> {
|
|
314
314
|
if (!this.proc) return
|
|
315
|
-
// [P13.2] Tandai stop yang kita minta → keluarannya tak dilaporkan sebagai
|
|
316
315
|
// [P13.2] Tandai stop yang kita minta: keluarannya tak dilaporkan sebagai
|
|
316
|
+
// crash tak terduga. Kirim didClose SEBELUM shutdown/exit selagi sesi LSP aktif.
|
|
317
317
|
this.stopping = true
|
|
318
|
-
try {
|
|
319
|
-
await this.request("shutdown", {}, 2_000)
|
|
320
|
-
} catch {}
|
|
321
|
-
try {
|
|
322
|
-
this.notify("exit")
|
|
323
|
-
} catch {}
|
|
324
|
-
// send didClose for all opened docs
|
|
325
318
|
for (const uri of this.opened.keys()) {
|
|
326
319
|
try {
|
|
327
320
|
this.notify("textDocument/didClose", { textDocument: { uri } })
|
|
@@ -329,6 +322,12 @@ class LspConnection {
|
|
|
329
322
|
}
|
|
330
323
|
this.opened.clear()
|
|
331
324
|
this.diagnostics.clear()
|
|
325
|
+
try {
|
|
326
|
+
await this.request("shutdown", {}, 2_000)
|
|
327
|
+
} catch {}
|
|
328
|
+
try {
|
|
329
|
+
this.notify("exit")
|
|
330
|
+
} catch {}
|
|
332
331
|
try {
|
|
333
332
|
this.proc.stdin?.end()
|
|
334
333
|
} catch {}
|
|
@@ -255,7 +255,7 @@ export class McpHttpTransport implements McpTransportLike {
|
|
|
255
255
|
* notifikasi tanpa id) berarti request kita **tidak** terjawab. Tanpa cek ini,
|
|
256
256
|
* balasan untuk request orang lain — atau notifikasi kosong — akan diterima
|
|
257
257
|
* sebagai hasil, dan `result: undefined` menjalar ke pemanggil sebagai
|
|
258
|
-
* "sukses". Ditemukan oleh
|
|
258
|
+
* "sukses". Ditemukan oleh harness MCP adversarial (server jahat).
|
|
259
259
|
*
|
|
260
260
|
* `expectId` opsional agar helper tetap bisa diuji tanpa konteks request.
|
|
261
261
|
* Diekspor untuk test.
|
package/src/mcp/server.ts
CHANGED
|
@@ -648,15 +648,25 @@ export async function serveMcp(opts: McpServeOptions = {}): Promise<void> {
|
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
|
|
651
|
-
// stdin close → shutdown bersih
|
|
651
|
+
// stdin close → shutdown bersih (bersihkan listener sinyal agar tidak bocor)
|
|
652
652
|
await new Promise<void>((resolve) => {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
653
|
+
const onSig = () => {
|
|
654
|
+
shutdown.abort()
|
|
655
|
+
cleanup()
|
|
656
|
+
resolve()
|
|
657
|
+
}
|
|
658
|
+
const onClose = () => {
|
|
659
|
+
cleanup()
|
|
660
|
+
resolve()
|
|
661
|
+
}
|
|
662
|
+
const cleanup = () => {
|
|
663
|
+
rl.off("close", onClose)
|
|
664
|
+
process.off("SIGINT", onSig)
|
|
665
|
+
process.off("SIGTERM", onSig)
|
|
659
666
|
}
|
|
667
|
+
rl.on("close", onClose)
|
|
668
|
+
process.once("SIGINT", onSig)
|
|
669
|
+
process.once("SIGTERM", onSig)
|
|
660
670
|
})
|
|
661
671
|
rl.close()
|
|
662
672
|
todoSession.id = prevTodo
|
package/src/memory/files.ts
CHANGED
|
@@ -136,7 +136,8 @@ export async function appendMemory(
|
|
|
136
136
|
const entryBoundary = rawKeep.indexOf("\n- ")
|
|
137
137
|
const cut = entryBoundary >= 0 ? entryBoundary + 1 : rawKeep.indexOf("\n")
|
|
138
138
|
const trimmed = cut >= 0 ? rawKeep.slice(cut + (entryBoundary >= 0 ? 0 : 1)) : rawKeep
|
|
139
|
-
await import("
|
|
139
|
+
const { atomicWriteText } = await import("../lib/atomic-write.ts")
|
|
140
|
+
await atomicWriteText(path, trimmed)
|
|
140
141
|
}
|
|
141
142
|
} catch {}
|
|
142
143
|
return path
|
package/src/memory/vector.ts
CHANGED
|
@@ -1472,20 +1472,28 @@ export async function revokeByProvenance(
|
|
|
1472
1472
|
if (conditions.length > 0) {
|
|
1473
1473
|
const db = open(cwd)
|
|
1474
1474
|
try {
|
|
1475
|
-
const
|
|
1476
|
-
|
|
1477
|
-
.
|
|
1478
|
-
|
|
1479
|
-
if (
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1475
|
+
const whereClause = conditions.join(" AND ")
|
|
1476
|
+
const matched = db
|
|
1477
|
+
.prepare(`SELECT id, parent FROM memory WHERE ${whereClause}`)
|
|
1478
|
+
.all(...(values as [string | null])) as { id: string; parent: string | null }[]
|
|
1479
|
+
if (matched.length > 0) {
|
|
1480
|
+
const heads = Array.from(new Set(matched.map((r) => r.parent ?? r.id)))
|
|
1481
|
+
const ph = heads.map(() => "?").join(",")
|
|
1482
|
+
const before = db
|
|
1483
|
+
.prepare(`SELECT count(*) as c FROM memory WHERE id IN (${ph}) OR parent IN (${ph})`)
|
|
1484
|
+
.get(...heads, ...heads) as { c: number } | null
|
|
1485
|
+
const n = before?.c ?? 0
|
|
1486
|
+
if (n > 0) {
|
|
1487
|
+
await withBusyRetry(() =>
|
|
1488
|
+
db
|
|
1489
|
+
.prepare(`DELETE FROM memory WHERE id IN (${ph}) OR parent IN (${ph})`)
|
|
1490
|
+
.run(...heads, ...heads),
|
|
1491
|
+
)
|
|
1492
|
+
// `changes` DELETE ikut terhitung tulis trigger FTS (bisa jauh lebih
|
|
1493
|
+
// besar dari baris memory yang benar-benar cocok) — jumlah baris yang
|
|
1494
|
+
// dihapus berasal dari penghitungannya SEBELUM delete.
|
|
1495
|
+
vectorDeleted = n
|
|
1496
|
+
}
|
|
1489
1497
|
}
|
|
1490
1498
|
} finally {
|
|
1491
1499
|
db.close()
|
|
@@ -1496,8 +1504,9 @@ export async function revokeByProvenance(
|
|
|
1496
1504
|
// FILE_STORE: tags JSON dalam baris → parse dan match terhadap criteria
|
|
1497
1505
|
let fileDeleted = 0
|
|
1498
1506
|
try {
|
|
1499
|
-
const { readFile
|
|
1507
|
+
const { readFile } = await import("node:fs/promises")
|
|
1500
1508
|
const { resolve } = await import("node:path")
|
|
1509
|
+
const { atomicWriteText } = await import("../lib/atomic-write.ts")
|
|
1501
1510
|
const LOCAL_MEM = ".minicode/MEMORY.md"
|
|
1502
1511
|
const path = resolve(cwd ?? process.cwd(), LOCAL_MEM)
|
|
1503
1512
|
|
|
@@ -1556,7 +1565,7 @@ export async function revokeByProvenance(
|
|
|
1556
1565
|
}
|
|
1557
1566
|
|
|
1558
1567
|
if (del > 0) {
|
|
1559
|
-
await
|
|
1568
|
+
await atomicWriteText(path, kept.join("\n"))
|
|
1560
1569
|
fileDeleted = del
|
|
1561
1570
|
}
|
|
1562
1571
|
} catch {}
|
package/src/policy/bash-guard.ts
CHANGED
|
@@ -71,10 +71,24 @@ export function stripQuotes(cmd: string): string {
|
|
|
71
71
|
export function stripCaretEscapes(cmd: string): string {
|
|
72
72
|
let out = ""
|
|
73
73
|
let inDouble = false
|
|
74
|
+
let inSingle = false
|
|
74
75
|
for (let i = 0; i < cmd.length; i++) {
|
|
75
76
|
const ch = cmd[i]!
|
|
76
|
-
if (ch ===
|
|
77
|
-
|
|
77
|
+
if (ch === "\\" && !inSingle && i + 1 < cmd.length) {
|
|
78
|
+
out += ch + cmd[++i]!
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
if (ch === "'" && !inDouble) {
|
|
82
|
+
inSingle = !inSingle
|
|
83
|
+
out += ch
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
if (ch === '"' && !inSingle) {
|
|
87
|
+
inDouble = !inDouble
|
|
88
|
+
out += ch
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
if (ch === "^" && !inDouble && !inSingle && i + 1 < cmd.length) {
|
|
78
92
|
out += cmd[++i]!
|
|
79
93
|
continue
|
|
80
94
|
}
|
|
@@ -110,7 +124,7 @@ export function inlineSimpleVars(cmd: string): string {
|
|
|
110
124
|
let changed = false
|
|
111
125
|
for (const [name, value] of vars) {
|
|
112
126
|
const ref = new RegExp(`\\$\\{${name}\\}|\\$${name}\\b`, "g")
|
|
113
|
-
const next = out.replace(ref, value)
|
|
127
|
+
const next = out.replace(ref, () => value)
|
|
114
128
|
if (next !== out) {
|
|
115
129
|
out = next
|
|
116
130
|
changed = true
|
|
@@ -126,8 +140,8 @@ export function inlineSimpleVars(cmd: string): string {
|
|
|
126
140
|
*
|
|
127
141
|
* `command env`, `nice env`, `time env`, `exec env` semuanya menjalankan `env`,
|
|
128
142
|
* tapi wrapper-nya menggeser posisi kata sehingga pola yang ter-anchor ke awal
|
|
129
|
-
* perintah (mis. deteksi env-dump) tidak lagi cocok. Ditemukan oleh
|
|
130
|
-
*
|
|
143
|
+
* perintah (mis. deteksi env-dump) tidak lagi cocok. Ditemukan oleh fuzz
|
|
144
|
+
* bash-guard: `command env` lolos sementara `env` ditolak.
|
|
131
145
|
*
|
|
132
146
|
* Wrapper dibuang berulang karena bisa berlapis (`time nice env`).
|
|
133
147
|
* Diekspor untuk test.
|
|
@@ -280,15 +294,22 @@ const GIT_DANGEROUS_CONFIG =
|
|
|
280
294
|
* repo/pohon lain (baca objek repo korban = jail-bypass READ, validasi e2e
|
|
281
295
|
* bug-hunt 2026-09-19 F2: `--git-dir=victim/.git log -p` bocor isi repo lain).
|
|
282
296
|
* Nilai dicek di bawah terhadap cwd (resolve+outside/sensitive/owned). */
|
|
283
|
-
const GIT_DIR_OVERRIDE = /(?:^|\s)(?:-C|--git-dir
|
|
297
|
+
const GIT_DIR_OVERRIDE = /(?:^|\s)(?:-C\s*(\S+)|--(?:git-dir|work-tree)(?:=|\s+)(\S+))/gi
|
|
284
298
|
|
|
285
299
|
/** Env git eksekusi (`GIT_PAGER=id ...`, `GIT_SSH=...`): efek sama dengan
|
|
286
300
|
* `-c` di atas, lewat assignment env. */
|
|
287
301
|
const GIT_EXEC_ENV = /(?:^|[;&|\n]\s*)GIT_(?:PAGER|SSH|ASKPASS|EDITOR|DIR|WORK_TREE)\s*=/i
|
|
288
302
|
|
|
289
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* Interpreter dijalankan dengan kode inline (semua bentuk flag).
|
|
305
|
+
*
|
|
306
|
+
* Interpreter diperluas mengikuti allowlist developer (python/node/bun/…
|
|
307
|
+
* sudah lama; tambah lua/julia/elixir/groovy/scala/tcl/dotnet/swift/dart/java)
|
|
308
|
+
* supaya `lua -e`, `julia -e`, `elixir -e`, dst tetap ditolak — tanpa ini,
|
|
309
|
+
* memperluas allowlist ke bahasa baru membuka jalur kode-inline pada bahasa itu.
|
|
310
|
+
*/
|
|
290
311
|
const INLINE_INTERPRETER =
|
|
291
|
-
/\b(?:pyw?|python[\d.]*|pypy[\d.]*|sh|bash|dash|zsh|ksh|node|deno|bun|perl|ruby|php|Rscript)(?:\.exe)?\b\s+(?:-\w*\s+)*(?:-c|-e|-E|--eval|--print|-p|--command|-r|--execute)\b/i
|
|
312
|
+
/\b(?:pyw?|python[\d.]*|pypy[\d.]*|sh|bash|dash|zsh|ksh|node|deno|bun|perl|ruby|php|Rscript|lua|luajit|julia|elixir|escript|erl|groovy|scala|tclsh|dotnet|swift|swiftc|dart|java|raku)(?:\.exe)?\b\s+(?:-\w*\s+)*(?:-c|-e|-E|--eval|-eval|--print|-p|--command|-r|--execute|--require|--import|--loader)\b/i
|
|
292
313
|
// Residual jujur (audit 2026-09-16 B3): eksekusi via stdin/redirect TANPA
|
|
293
314
|
// flag inline (`bash -s < skrip`, `python3 < prog`, `... | python3 -`) tidak
|
|
294
315
|
// ditahan — menahan `| python3 -` mematahkan pipeline sah, dan `bash berkas`
|
|
@@ -299,9 +320,10 @@ const INLINE_INTERPRETER =
|
|
|
299
320
|
/** Process substitution / here-string yang memasukkan output perintah lain. */
|
|
300
321
|
const PROCESS_SUB = /<\s*\(|>\s*\(|<<<|\bsource\s+<|\.\s+<\(/
|
|
301
322
|
|
|
302
|
-
/** Pipe ke shell/interpreter — bentuk apa pun sumbernya
|
|
323
|
+
/** Pipe ke shell/interpreter — bentuk apa pun sumbernya (interpreter baru
|
|
324
|
+
* mengikuti perluasan allowlist developer). */
|
|
303
325
|
const PIPE_TO_SHELL =
|
|
304
|
-
/\|\s*(?:sudo\s+)?(?:sh|bash|dash|zsh|ksh|python|python2|python3|pyw?|node|deno|bun|perl|ruby|php|iex|Invoke-Expression|powershell|pwsh)(?:\.exe)?\b/i
|
|
326
|
+
/\|\s*(?:sudo\s+)?(?:sh|bash|dash|zsh|ksh|python|python2|python3|pyw?|node|deno|bun|perl|ruby|php|iex|Invoke-Expression|powershell|pwsh|lua|luajit|julia|elixir|escript|erl|groovy|scala|tclsh|dotnet|swift|swiftc|dart|java|raku)(?:\.exe)?\b/i
|
|
305
327
|
|
|
306
328
|
/** Unduh ke berkas lalu jalankan berkas itu dalam satu baris. Catatan pola:
|
|
307
329
|
* - `certutil -urlcache` ikut (downloader Windows di luar curl/wget/iwr).
|
|
@@ -473,7 +495,14 @@ const STATIC_DENY: [RegExp, string][] = [
|
|
|
473
495
|
// `git -c k=v <sub>` sebelum subcommand sudah gugur di allowlist (tak cocok
|
|
474
496
|
// pola ^git <sub>), tapi mode auto hanya dijaga guard ini. Alur sah agen
|
|
475
497
|
// (status/diff/log/branch/show dalam repo) tak memakai flag ini.
|
|
476
|
-
[
|
|
498
|
+
[
|
|
499
|
+
/\bgit\b[^\n]*?--(?:no-index|exec-path|upload-pack|receive-pack|output(?:=|\s+))/,
|
|
500
|
+
"git dangerous flag",
|
|
501
|
+
],
|
|
502
|
+
[
|
|
503
|
+
/\bfind\b[^\n]*\s-(?:exec|execdir|ok|okdir|delete|fprint0?|fls)\b/i,
|
|
504
|
+
"find exec/delete/write flag",
|
|
505
|
+
],
|
|
477
506
|
[/\bext::/, "git ext transport"],
|
|
478
507
|
// Injeksi konfigurasi git via environment (`GIT_EXTERNAL_DIFF=x git diff`
|
|
479
508
|
// setara diff.external repo — repo-side adalah residual terdokumentasi, tapi
|
|
@@ -499,6 +528,18 @@ const STATIC_DENY: [RegExp, string][] = [
|
|
|
499
528
|
// arbitrer dari argumen single-command. `wscript`/`cscript` (Windows Script
|
|
500
529
|
// Host), `mshta` (HTML app), `rundll32`/`regsvr32` (load arbitrary DLL).
|
|
501
530
|
[/\b(?:mshta|wscript|cscript|rundll32|regsvr32)(?:\.exe)?\b/i, "dangerous windows launcher"],
|
|
531
|
+
// Verba rilis/kredensial registry — aksi IREVERSIBEL yang butuh kredensial,
|
|
532
|
+
// bukan bagian alur membangun aplikasi: `npm publish`, `cargo publish`/
|
|
533
|
+
// `login`, `gem push`, `dotnet nuget push`, `poetry publish`,
|
|
534
|
+
// `docker push`/`login`, `mvn deploy`, `gradle publish`, `dart pub publish`,
|
|
535
|
+
// `twine upload`, `cargo owner`/`yank`. Ditahan di SEMUA mode (armor) agar
|
|
536
|
+
// allowlist developer boleh LUAS tanpa membuka jalur terbit diam-diam.
|
|
537
|
+
// Over-block dijaga ketat: verba rilis HARUS tepat setelah manager (+ satu
|
|
538
|
+
// subcommand opsional), jadi `npm run deploy` TIDAK kena ("run" bukan verba).
|
|
539
|
+
[
|
|
540
|
+
/\b(?:npm|cargo|gem|poetry|twine|dotnet|docker|podman|mvn|gradle|bun|yarn|pnpm|dart|flutter|pub|nuget)\b(?:\s+(?:nuget|pub|compose|token))?\s+(?:publish|unpublish|push|deploy|login|logout|adduser|upload|yank|owner|signout)\b/i,
|
|
541
|
+
"registry publish/credential verb",
|
|
542
|
+
],
|
|
502
543
|
]
|
|
503
544
|
|
|
504
545
|
/**
|
|
@@ -530,12 +571,13 @@ export function inspectBashCommand(rawCmd: string, cwd?: string): BashVerdict {
|
|
|
530
571
|
if (both(VAR_UPLOAD)) return { denied: true, reason: "variable data upload to network" }
|
|
531
572
|
if (both(GIT_DANGEROUS_CONFIG)) return { denied: true, reason: "git exec config override" }
|
|
532
573
|
if (both(GIT_EXEC_ENV)) return { denied: true, reason: "git exec env override" }
|
|
533
|
-
// -C/--git-dir/--work-tree: resolve nilai terhadap cwd seperti redirect —
|
|
574
|
+
// -C/--git-dir/--work-tree: resolve SEMUA nilai terhadap cwd seperti redirect —
|
|
534
575
|
// di luar workspace/sensitif/owned = deny (baca repo lain = jail-bypass).
|
|
535
|
-
{
|
|
536
|
-
const m
|
|
537
|
-
|
|
538
|
-
|
|
576
|
+
for (const src of [norm, raw]) {
|
|
577
|
+
for (const m of src.matchAll(GIT_DIR_OVERRIDE)) {
|
|
578
|
+
const rawTarget = m[1] ?? m[2]
|
|
579
|
+
if (!rawTarget) continue
|
|
580
|
+
const t = rawTarget.replace(/^["']|["']$/g, "")
|
|
539
581
|
if (cwd != null) {
|
|
540
582
|
const abs = isAbsolute(t) ? resolve(t) : resolve(cwd, t)
|
|
541
583
|
if (
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Byte-level BPE tokenizer murni TS (tanpa dependensi) — kompatibel dengan
|
|
2
|
+
// `tokenizer.json` HuggingFace (keluarga GPT-2/llama/deepseek/qwen/mistral).
|
|
3
|
+
//
|
|
4
|
+
// Ini replikasi algoritma tiktoken/HF `tokenizers`: byte-to-unicode mapping,
|
|
5
|
+
// regex pre-tokenizer, dan greedy pair merge. Dipakai sebagai pengukur token
|
|
6
|
+
// AKURAT (bukan chars/4) untuk model open yang mempublikasikan vocab-nya —
|
|
7
|
+
// menutup celah under-count yang membuat konteks meledak tanpa disadari.
|
|
8
|
+
|
|
9
|
+
export interface BpeData {
|
|
10
|
+
vocab: Record<string, number>
|
|
11
|
+
merges: Array<string | [string, string]>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Map byte -> unicode (sama dengan tiktoken/HF): printable = dirinya, non-
|
|
15
|
+
* printable -> ␀..ÿ (256+n). Byte 32 (spasi) -> Ġ, byte 10 -> Ċ, dst. */
|
|
16
|
+
function byteEncoder(): Map<number, string> {
|
|
17
|
+
const bs: number[] = []
|
|
18
|
+
for (let i = 33; i <= 126; i++) bs.push(i) // !..~
|
|
19
|
+
for (let i = 161; i <= 172; i++) bs.push(i) // ¡..¬
|
|
20
|
+
for (let i = 174; i <= 255; i++) bs.push(i) // ®..ÿ
|
|
21
|
+
const cs: number[] = bs.slice()
|
|
22
|
+
let n = 0
|
|
23
|
+
for (let b = 0; b < 256; b++) {
|
|
24
|
+
if (!bs.includes(b)) {
|
|
25
|
+
bs.push(b)
|
|
26
|
+
cs.push(256 + n)
|
|
27
|
+
n++
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const map = new Map<number, string>()
|
|
31
|
+
for (let i = 0; i < bs.length; i++) map.set(bs[i]!, String.fromCodePoint(cs[i]!))
|
|
32
|
+
return map
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const BYTE_TO_UNICODE = byteEncoder()
|
|
36
|
+
|
|
37
|
+
// Regex pre-tokenizer persis tiktoken (keluarga GPT-2 BPE).
|
|
38
|
+
const PAT =
|
|
39
|
+
/(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+/gu
|
|
40
|
+
|
|
41
|
+
function byteEncode(text: string): string[] {
|
|
42
|
+
const bytes = new TextEncoder().encode(text)
|
|
43
|
+
return [...bytes].map((b) => BYTE_TO_UNICODE.get(b) ?? "")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Terapkan BPE merge pada satu "kata" (string unicode) memakai rank merge. */
|
|
47
|
+
function bpeMerge(token: string[], mergeRanks: Map<string, number>): string[] {
|
|
48
|
+
let parts = token.slice()
|
|
49
|
+
// Greedy: gabungkan pasangan ber-rank terendah (tertinggi) selama ada.
|
|
50
|
+
for (;;) {
|
|
51
|
+
let bestIdx = -1
|
|
52
|
+
let bestRank = Infinity
|
|
53
|
+
for (let i = 0; i + 1 < parts.length; i++) {
|
|
54
|
+
const rank = mergeRanks.get(`${parts[i]!} ${parts[i + 1]!}`)
|
|
55
|
+
if (rank !== undefined && rank < bestRank) {
|
|
56
|
+
bestRank = rank
|
|
57
|
+
bestIdx = i
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (bestIdx < 0) break
|
|
61
|
+
parts = [
|
|
62
|
+
...parts.slice(0, bestIdx),
|
|
63
|
+
parts[bestIdx]! + parts[bestIdx + 1]!,
|
|
64
|
+
...parts.slice(bestIdx + 2),
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
return parts
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class BpeTokenizer {
|
|
71
|
+
private mergeRanks: Map<string, number>
|
|
72
|
+
|
|
73
|
+
constructor(data: BpeData) {
|
|
74
|
+
// merges = urutan rank (indeks pertama = prioritas tertinggi).
|
|
75
|
+
// Gunakan kunci berpemisah spasi ("a b") agar pasangan berbeda seperti
|
|
76
|
+
// ("ab","c") vs ("a","bc") tidak bertabrakan; dukung juga format tuple HF v2.
|
|
77
|
+
this.mergeRanks = new Map()
|
|
78
|
+
data.merges.forEach((pair, index) => {
|
|
79
|
+
if (Array.isArray(pair)) {
|
|
80
|
+
if (typeof pair[0] === "string" && typeof pair[1] === "string") {
|
|
81
|
+
this.mergeRanks.set(`${pair[0]} ${pair[1]}`, index)
|
|
82
|
+
}
|
|
83
|
+
} else if (typeof pair === "string") {
|
|
84
|
+
this.mergeRanks.set(pair, index)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Jumlah token (ID unik) dalam teks. */
|
|
90
|
+
countTokens(text: string): number {
|
|
91
|
+
if (!text) return 0
|
|
92
|
+
let total = 0
|
|
93
|
+
for (const piece of text.match(PAT) ?? []) {
|
|
94
|
+
if (!piece) continue
|
|
95
|
+
const token = byteEncode(piece)
|
|
96
|
+
const parts = bpeMerge(token, this.mergeRanks)
|
|
97
|
+
// Setiap bagian jadi satu token; vocab lookup (>0 selalu ada di BPE terlatih).
|
|
98
|
+
total += parts.length
|
|
99
|
+
}
|
|
100
|
+
return total
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Bangun tokenizer dari objek tokenizer.json (model.vocab + model.merges). */
|
|
105
|
+
export function loadBpeTokenizer(model: {
|
|
106
|
+
vocab: Record<string, number>
|
|
107
|
+
merges: Array<string | [string, string]>
|
|
108
|
+
}): BpeTokenizer {
|
|
109
|
+
return new BpeTokenizer({ vocab: model.vocab, merges: model.merges })
|
|
110
|
+
}
|