minicode-ai 0.9.26
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/CHANGELOG.md +935 -0
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/cli/args.ts +195 -0
- package/cli/auto-update.ts +108 -0
- package/cli/commands/auth.ts +166 -0
- package/cli/commands/config.ts +382 -0
- package/cli/commands/doctor.ts +128 -0
- package/cli/commands/exec.ts +179 -0
- package/cli/commands/mcp.ts +35 -0
- package/cli/commands/memory.ts +107 -0
- package/cli/commands/pricing.ts +100 -0
- package/cli/commands/providers.ts +162 -0
- package/cli/commands/sessions.ts +128 -0
- package/cli/commands/skills.ts +61 -0
- package/cli/commands/stats.ts +82 -0
- package/cli/commands.ts +317 -0
- package/cli/index.ts +539 -0
- package/cli/model-manager.ts +112 -0
- package/cli/provider-manager.ts +111 -0
- package/cli/repl.ts +734 -0
- package/cli/router.ts +124 -0
- package/cli/setup.ts +780 -0
- package/cli/wizard.ts +21 -0
- package/docs/ARCHITECTURE.html +1222 -0
- package/docs/README.md +109 -0
- package/docs/architecture.md +44 -0
- package/docs/changelog.md +3 -0
- package/package.json +91 -0
- package/src/agents/pool.ts +43 -0
- package/src/app/mentions.ts +50 -0
- package/src/app/provider-layer.ts +118 -0
- package/src/app/rag-layer.ts +105 -0
- package/src/app/session.ts +154 -0
- package/src/app/tool-layer.ts +56 -0
- package/src/config.ts +372 -0
- package/src/constants.ts +119 -0
- package/src/hooks/run.ts +89 -0
- package/src/lib/atomic-write.ts +88 -0
- package/src/lib/db-path.ts +36 -0
- package/src/lib/git-hardening.ts +91 -0
- package/src/lib/ignore.ts +58 -0
- package/src/lib/keystore.ts +202 -0
- package/src/lib/net.ts +70 -0
- package/src/lib/safe-open.ts +138 -0
- package/src/lib/session-id.ts +23 -0
- package/src/lib/trash.ts +38 -0
- package/src/lib/trusted-exec.ts +81 -0
- package/src/lsp/client.ts +395 -0
- package/src/mcp/client.ts +400 -0
- package/src/mcp/http-transport.ts +344 -0
- package/src/mcp/server.ts +538 -0
- package/src/mcp/transport.ts +150 -0
- package/src/memory/files.ts +159 -0
- package/src/memory/vector.ts +775 -0
- package/src/policy/allowlist.ts +67 -0
- package/src/policy/bash-guard.ts +465 -0
- package/src/policy/compaction.ts +271 -0
- package/src/policy/context.ts +161 -0
- package/src/policy/executor.ts +199 -0
- package/src/policy/jail.ts +127 -0
- package/src/policy/permission.ts +517 -0
- package/src/policy/pricing.ts +336 -0
- package/src/policy/ratelimit.ts +54 -0
- package/src/policy/sandbox-policy.ts +157 -0
- package/src/policy/scrub.ts +138 -0
- package/src/policy/update-check.ts +200 -0
- package/src/policy/usage.ts +292 -0
- package/src/policy/verifier.ts +181 -0
- package/src/providers/anthropic.ts +401 -0
- package/src/providers/auth-store.ts +139 -0
- package/src/providers/build.ts +136 -0
- package/src/providers/detect.ts +126 -0
- package/src/providers/effort.ts +165 -0
- package/src/providers/guards.ts +107 -0
- package/src/providers/oauth.ts +326 -0
- package/src/providers/presets.ts +122 -0
- package/src/providers/provision.ts +298 -0
- package/src/providers/responses.ts +371 -0
- package/src/providers/router.ts +247 -0
- package/src/repo/repomap.ts +470 -0
- package/src/sandbox/docker.ts +129 -0
- package/src/sandbox/os.ts +193 -0
- package/src/session/checkpoint.ts +543 -0
- package/src/session/journal.ts +1347 -0
- package/src/session/persistence.ts +446 -0
- package/src/session/shadow-git.ts +351 -0
- package/src/session/turn-marker.ts +118 -0
- package/src/skills/loader.ts +117 -0
- package/src/telemetry/trace.ts +283 -0
- package/src/tools/ask_user.ts +54 -0
- package/src/tools/bash.ts +400 -0
- package/src/tools/code_run.ts +96 -0
- package/src/tools/delete_file.ts +31 -0
- package/src/tools/edit.ts +204 -0
- package/src/tools/git.ts +301 -0
- package/src/tools/glob.ts +90 -0
- package/src/tools/grep.ts +281 -0
- package/src/tools/hashline.ts +66 -0
- package/src/tools/index.ts +103 -0
- package/src/tools/lsp.ts +346 -0
- package/src/tools/mcp_call.ts +163 -0
- package/src/tools/memory.ts +144 -0
- package/src/tools/move_file.ts +47 -0
- package/src/tools/patch.ts +86 -0
- package/src/tools/read_file.ts +130 -0
- package/src/tools/read_image.ts +80 -0
- package/src/tools/submit_result.ts +49 -0
- package/src/tools/task.ts +346 -0
- package/src/tools/todo.ts +201 -0
- package/src/tools/web_fetch.ts +161 -0
- package/src/tools/web_search.ts +156 -0
- package/src/tools/write_file.ts +42 -0
- package/src/ui/approval/prompt.ts +76 -0
- package/src/ui/assistant/simple.ts +568 -0
- package/src/ui/assistant/turn-status.ts +303 -0
- package/src/ui/contract.ts +55 -0
- package/src/ui/footer.ts +105 -0
- package/src/ui/input/input.ts +805 -0
- package/src/ui/input/prompt-engine.ts +606 -0
- package/src/ui/render/collapse.ts +84 -0
- package/src/ui/render/detail.ts +24 -0
- package/src/ui/render/diff.ts +181 -0
- package/src/ui/render/errors.ts +239 -0
- package/src/ui/render/format.ts +54 -0
- package/src/ui/render/highlight.ts +294 -0
- package/src/ui/render/markdown.ts +120 -0
- package/src/ui/render/money.ts +12 -0
- package/src/ui/render/reasoning.ts +20 -0
- package/src/ui/render/sanitize.ts +80 -0
- package/src/ui/render/table.ts +88 -0
- package/src/ui/render/theme.ts +339 -0
- package/src/ui/render/width.ts +256 -0
- package/src/ui/render/wrap.ts +120 -0
- package/src/ui/runtime/bus-debug.ts +83 -0
- package/src/ui/runtime/chrome.ts +301 -0
- package/src/ui/runtime/spinner.ts +77 -0
- package/src/ui/runtime/statusline.ts +227 -0
- package/src/ui/screens/model-manager.ts +434 -0
- package/src/ui/screens/overlay.ts +61 -0
- package/src/ui/screens/picker.ts +307 -0
- package/src/ui/screens/provider-manager.ts +450 -0
- package/src/ui/screens/wizard.ts +132 -0
- package/vendor/minicore/VENDOR.md +29 -0
- package/vendor/minicore/package.json +21 -0
- package/vendor/minicore/src/core/budget.ts +26 -0
- package/vendor/minicore/src/core/compact.ts +76 -0
- package/vendor/minicore/src/core/errors.ts +60 -0
- package/vendor/minicore/src/core/events.ts +74 -0
- package/vendor/minicore/src/core/executor.ts +139 -0
- package/vendor/minicore/src/core/history.ts +32 -0
- package/vendor/minicore/src/core/index.ts +42 -0
- package/vendor/minicore/src/core/loop.ts +344 -0
- package/vendor/minicore/src/core/permission.ts +24 -0
- package/vendor/minicore/src/core/provider.ts +39 -0
- package/vendor/minicore/src/core/recovery.ts +34 -0
- package/vendor/minicore/src/core/session.ts +327 -0
- package/vendor/minicore/src/core/snapshot.ts +142 -0
- package/vendor/minicore/src/core/tokens.ts +111 -0
- package/vendor/minicore/src/core/tool.ts +118 -0
- package/vendor/minicore/src/core/types.ts +50 -0
- package/vendor/minicore/src/providers/openai-compat.ts +366 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process"
|
|
2
|
+
import { resolve } from "node:path"
|
|
3
|
+
import { LIMITS } from "../constants.ts"
|
|
4
|
+
import { resolveTrustedExecutable } from "../lib/trusted-exec.ts"
|
|
5
|
+
import { sanitizeSpawnEnv } from "../policy/scrub.ts"
|
|
6
|
+
|
|
7
|
+
let osSandboxOk: boolean | null = null
|
|
8
|
+
let osSandboxType: "seatbelt" | "bwrap" | "none" | null = null
|
|
9
|
+
|
|
10
|
+
function detectOsSandbox(): { available: boolean; type: "seatbelt" | "bwrap" | "none" } {
|
|
11
|
+
if (osSandboxOk !== null) return { available: osSandboxOk, type: osSandboxType! }
|
|
12
|
+
if (process.platform === "darwin") {
|
|
13
|
+
// seatbelt via sandbox-exec (macOS). Check availability
|
|
14
|
+
try {
|
|
15
|
+
// F-23: resolve absolut (lihat docker.ts) — berlaku di Windows untuk
|
|
16
|
+
// docker; di POSIX sebagai hygiene + determinisme PATH.
|
|
17
|
+
const r = spawnSync(resolveTrustedExecutable("sandbox-exec"), ["-h"], {
|
|
18
|
+
stdio: "ignore",
|
|
19
|
+
timeout: 2000,
|
|
20
|
+
})
|
|
21
|
+
// sandbox-exec returns 0 or 64 with usage, consider available if binary exists
|
|
22
|
+
const ok = r.error === undefined
|
|
23
|
+
osSandboxOk = ok
|
|
24
|
+
osSandboxType = ok ? "seatbelt" : "none"
|
|
25
|
+
return { available: ok, type: osSandboxType }
|
|
26
|
+
} catch {
|
|
27
|
+
osSandboxOk = false
|
|
28
|
+
osSandboxType = "none"
|
|
29
|
+
return { available: false, type: "none" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (process.platform === "linux") {
|
|
33
|
+
try {
|
|
34
|
+
const r = spawnSync(resolveTrustedExecutable("bwrap"), ["--version"], {
|
|
35
|
+
stdio: "ignore",
|
|
36
|
+
timeout: 2000,
|
|
37
|
+
})
|
|
38
|
+
const ok = r.status === 0
|
|
39
|
+
osSandboxOk = ok
|
|
40
|
+
osSandboxType = ok ? "bwrap" : "none"
|
|
41
|
+
return { available: ok, type: osSandboxType }
|
|
42
|
+
} catch {
|
|
43
|
+
osSandboxOk = false
|
|
44
|
+
osSandboxType = "none"
|
|
45
|
+
return { available: false, type: "none" }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
osSandboxOk = false
|
|
49
|
+
osSandboxType = "none"
|
|
50
|
+
return { available: false, type: "none" }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function osSandboxAvailable(): boolean {
|
|
54
|
+
return detectOsSandbox().available
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function osSandboxTypeName(): string {
|
|
58
|
+
return detectOsSandbox().type
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface OsSandboxOptions {
|
|
62
|
+
env?: Record<string, string>
|
|
63
|
+
timeoutMs?: number
|
|
64
|
+
network?: "none" | "bridge"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Seatbelt profile minimal (deny network, restrict writes outside cwd)
|
|
68
|
+
// bwrap: bubblewrap with --ro-bind / --bind cwd, --unshare-net, --die-with-parent
|
|
69
|
+
export function runInOsSandbox(
|
|
70
|
+
command: string,
|
|
71
|
+
cwd: string,
|
|
72
|
+
opts: OsSandboxOptions = {},
|
|
73
|
+
): Promise<{ code: number | null; output: string }> {
|
|
74
|
+
const { available, type } = detectOsSandbox()
|
|
75
|
+
if (!available) {
|
|
76
|
+
// Fail-closed seam: pemanggil (bash/code_run) wajib cek osSandboxAvailable
|
|
77
|
+
// dulu; siapa pun yang memanggil langsung tanpa cek mendapat throw, bukan
|
|
78
|
+
// output berbentuk-sukses yang terlihat seperti isolasi berjalan.
|
|
79
|
+
return Promise.reject(
|
|
80
|
+
new Error(
|
|
81
|
+
"[os-sandbox] not available on this platform — refusing to run (no isolation backend)",
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
const abs = resolve(cwd)
|
|
86
|
+
const sanitizedEnv = sanitizeSpawnEnv(process.env, opts.env) as Record<string, string>
|
|
87
|
+
const timeout = opts.timeoutMs ?? LIMITS.DOCKER_TIMEOUT_MS
|
|
88
|
+
|
|
89
|
+
if (type === "seatbelt") {
|
|
90
|
+
// macOS seatbelt - simple deny network profile
|
|
91
|
+
const profile = `(version 1)
|
|
92
|
+
(deny default)
|
|
93
|
+
(allow process-exec)
|
|
94
|
+
(allow file-read* file-write* (subpath "${abs}"))
|
|
95
|
+
(allow file-read* (subpath "/usr") (subpath "/bin") (subpath "/private/tmp"))
|
|
96
|
+
(allow sysctl-read)
|
|
97
|
+
(deny network*)
|
|
98
|
+
`
|
|
99
|
+
// Use sandbox-exec with inline profile via stdin? sandbox-exec needs file, write tmp
|
|
100
|
+
const args = ["-p", profile, "sh", "-c", command]
|
|
101
|
+
return runSpawn("sandbox-exec", args, abs, sanitizedEnv, timeout)
|
|
102
|
+
}
|
|
103
|
+
if (type === "bwrap") {
|
|
104
|
+
const args = [
|
|
105
|
+
"--ro-bind",
|
|
106
|
+
"/usr",
|
|
107
|
+
"/usr",
|
|
108
|
+
"--ro-bind",
|
|
109
|
+
"/bin",
|
|
110
|
+
"/bin",
|
|
111
|
+
"--ro-bind",
|
|
112
|
+
"/lib",
|
|
113
|
+
"/lib",
|
|
114
|
+
"--ro-bind",
|
|
115
|
+
"/lib64",
|
|
116
|
+
"/lib64",
|
|
117
|
+
"--proc",
|
|
118
|
+
"/proc",
|
|
119
|
+
"--dev",
|
|
120
|
+
"/dev",
|
|
121
|
+
"--tmpfs",
|
|
122
|
+
"/tmp",
|
|
123
|
+
"--bind",
|
|
124
|
+
abs,
|
|
125
|
+
abs,
|
|
126
|
+
"--chdir",
|
|
127
|
+
abs,
|
|
128
|
+
"--unshare-net",
|
|
129
|
+
"--die-with-parent",
|
|
130
|
+
"--cap-drop",
|
|
131
|
+
"ALL",
|
|
132
|
+
"sh",
|
|
133
|
+
"-c",
|
|
134
|
+
command,
|
|
135
|
+
]
|
|
136
|
+
// best-effort: if network bridge requested, omit --unshare-net
|
|
137
|
+
if (opts.network === "bridge") {
|
|
138
|
+
const idx = args.indexOf("--unshare-net")
|
|
139
|
+
if (idx !== -1) args.splice(idx, 1)
|
|
140
|
+
}
|
|
141
|
+
return runSpawn("bwrap", args, abs, sanitizedEnv, timeout)
|
|
142
|
+
}
|
|
143
|
+
return Promise.resolve({ code: null, output: "[os-sandbox] unknown type" })
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function runSpawn(
|
|
147
|
+
bin: string,
|
|
148
|
+
args: string[],
|
|
149
|
+
cwd: string,
|
|
150
|
+
env: Record<string, string>,
|
|
151
|
+
timeoutMs: number,
|
|
152
|
+
): Promise<{ code: number | null; output: string }> {
|
|
153
|
+
return new Promise((resolveResult) => {
|
|
154
|
+
// F-23: bin di-resolve absolut dari PATH terpercaya di sini (satu titik
|
|
155
|
+
// untuk seatbelt/bwrap) — spawn dengan cwd workspace di Windows bisa
|
|
156
|
+
// mengeksekusi <bin>.bat repo bila hanya nama telanjang.
|
|
157
|
+
const p = spawn(resolveTrustedExecutable(bin), args, {
|
|
158
|
+
cwd,
|
|
159
|
+
env,
|
|
160
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
161
|
+
})
|
|
162
|
+
const OUT_CAP = LIMITS.DOCKER_OUTPUT_MAX_CHARS
|
|
163
|
+
let out = ""
|
|
164
|
+
let err = ""
|
|
165
|
+
let truncated = false
|
|
166
|
+
const appendCapped = (target: "out" | "err", d: Buffer | string): void => {
|
|
167
|
+
const s = typeof d === "string" ? d : d.toString()
|
|
168
|
+
const cur = target === "out" ? out : err
|
|
169
|
+
if (cur.length >= OUT_CAP) {
|
|
170
|
+
truncated = true
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
const room = OUT_CAP - cur.length
|
|
174
|
+
if (s.length > room) truncated = true
|
|
175
|
+
const piece = s.slice(0, Math.max(0, room))
|
|
176
|
+
if (target === "out") out += piece
|
|
177
|
+
else err += piece
|
|
178
|
+
}
|
|
179
|
+
p.stdout.on("data", (d) => appendCapped("out", d))
|
|
180
|
+
p.stderr.on("data", (d) => appendCapped("err", d))
|
|
181
|
+
const t = setTimeout(() => p.kill("SIGKILL"), timeoutMs)
|
|
182
|
+
p.on("error", (e) => {
|
|
183
|
+
clearTimeout(t)
|
|
184
|
+
resolveResult({ code: null, output: `[os-sandbox] ${e.message}` })
|
|
185
|
+
})
|
|
186
|
+
p.on("close", (code) => {
|
|
187
|
+
clearTimeout(t)
|
|
188
|
+
const marker = truncated ? "\n… [output truncated]" : ""
|
|
189
|
+
const output = (out + (err ? `\n[stderr]\n${err}` : "")).trim() + marker
|
|
190
|
+
resolveResult({ code, output })
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
}
|