minicode-ai 0.11.1 → 0.13.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/CHANGELOG.md +89 -0
- package/LICENSE +21 -21
- package/README.md +4 -4
- package/cli/args.ts +46 -0
- package/cli/commands/acp.ts +163 -10
- package/cli/commands/config.ts +33 -18
- package/cli/commands/daemon.ts +515 -0
- package/cli/commands/exec.ts +145 -53
- package/cli/commands/openwork.ts +986 -0
- package/cli/commands/sessions.ts +4 -1
- package/cli/commands/stats.ts +34 -4
- package/cli/commands.ts +217 -2
- package/cli/index.ts +146 -14
- package/cli/recovery-warning.ts +115 -0
- package/cli/router.ts +32 -1
- package/cli/setup.ts +2332 -171
- package/cli/tui.ts +113 -7
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +489 -0
- package/docs/OUTPUT_EVENT_MODEL.md +289 -0
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +391 -0
- package/docs/OUTPUT_PROTOCOL_SPEC.md +285 -0
- package/docs/OUTPUT_RENDERING_SPEC.md +248 -0
- package/docs/OUTPUT_UX_RULES.md +449 -0
- package/docs/PLAN_UIUX_V6.md +2 -2
- package/docs/README.md +4 -3
- package/docs/TERMINAL_CONTRACT.md +278 -71
- package/docs/architecture.md +89 -7
- package/docs/changelog.md +1 -1
- package/docs/choosing-mode.md +2 -2
- package/docs/cli.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +9 -2
- package/docs/environment.md +6 -2
- package/docs/exec.md +46 -5
- package/docs/memory-sessions.md +2 -0
- package/docs/policy-sandbox.md +1 -1
- package/docs/pricing-budget.md +1 -1
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +6 -2
- package/docs/security-model.md +1 -1
- package/docs/security.md +1 -1
- package/docs/skills.md +2 -2
- package/docs/terminal.md +9 -5
- package/docs/tools.md +1 -1
- package/package.json +35 -5
- package/src/app/session.ts +261 -15
- package/src/app/tool-layer.ts +94 -7
- package/src/daemon/approvals.ts +361 -0
- package/src/daemon/capability.ts +145 -0
- package/src/daemon/children.ts +142 -0
- package/src/daemon/client.ts +267 -0
- package/src/daemon/control.ts +350 -0
- package/src/daemon/discovery.ts +234 -0
- package/src/daemon/feed.ts +155 -0
- package/src/daemon/framing.ts +94 -0
- package/src/daemon/host.ts +316 -0
- package/src/daemon/protocol.ts +217 -0
- package/src/daemon/resource.ts +170 -0
- package/src/daemon/sanitize.ts +57 -0
- package/src/daemon/server.ts +627 -0
- package/src/daemon/store.ts +317 -0
- package/src/daemon/subscription.ts +270 -0
- package/src/daemon/telemetry.ts +81 -0
- package/src/hooks/run.ts +12 -1
- package/src/lib/atomic-write.ts +29 -3
- package/src/lib/db-path.ts +26 -0
- package/src/lib/keystore.ts +544 -42
- package/src/lib/net.ts +43 -1
- package/src/lib/safe-open.ts +116 -1
- package/src/lib/session-id.ts +15 -0
- package/src/lsp/client.ts +123 -5
- package/src/mcp/client.ts +139 -17
- package/src/mcp/server.ts +177 -50
- package/src/mcp/transport.ts +16 -19
- package/src/memory/vector.ts +770 -55
- package/src/policy/allowlist.ts +14 -2
- package/src/policy/bash-guard.ts +105 -10
- package/src/policy/compaction.ts +82 -5
- package/src/policy/consequence-engine.ts +220 -0
- package/src/policy/context.ts +132 -0
- package/src/policy/executor.ts +187 -121
- package/src/policy/no-progress.ts +559 -0
- package/src/policy/permission.ts +4 -8
- package/src/policy/pricing.ts +17 -3
- package/src/policy/scrub.ts +69 -2
- package/src/policy/tool-contract.ts +515 -0
- package/src/policy/usage.ts +310 -24
- package/src/policy/verifier.ts +6 -3
- package/src/policy/work-mode.ts +182 -0
- package/src/presentation/adapter.ts +533 -26
- package/src/presentation/events.ts +151 -0
- package/src/presentation/model.ts +180 -27
- package/src/presentation/projection.ts +858 -0
- package/src/presentation/reducer.ts +645 -310
- package/src/presentation/store.ts +12 -7
- package/src/providers/anthropic.ts +18 -10
- package/src/providers/responses.ts +2 -2
- package/src/runtime/capability.ts +409 -0
- package/src/runtime/child-execution.ts +274 -0
- package/src/runtime/composition.ts +958 -0
- package/src/runtime/dispatch.ts +591 -0
- package/src/runtime/execution-backend.ts +632 -0
- package/src/runtime/execution-events.ts +272 -0
- package/src/runtime/execution-id.ts +230 -0
- package/src/runtime/execution-journal.ts +926 -0
- package/src/runtime/execution-kernel.ts +456 -0
- package/src/runtime/execution-registry.ts +379 -0
- package/src/runtime/process-supervision.ts +276 -0
- package/src/runtime/production-execution.ts +551 -0
- package/src/runtime/production-runtime.ts +217 -0
- package/src/runtime/recovery-safety.ts +70 -0
- package/src/runtime/recovery.ts +477 -0
- package/src/runtime/runtime-capabilities.ts +179 -0
- package/src/runtime/runtime-diagnostics.ts +141 -0
- package/src/runtime/runtime-host.ts +365 -0
- package/src/runtime/runtime-status-facts.ts +222 -0
- package/src/runtime/runtime-status-provider.ts +74 -0
- package/src/runtime/runtime-status.ts +459 -0
- package/src/runtime/runtime-task-admission.ts +101 -0
- package/src/runtime/supervisor.ts +444 -0
- package/src/session/authority.ts +168 -0
- package/src/session/checkpoint.ts +88 -1
- package/src/session/context-adapter.ts +251 -0
- package/src/session/context-assembly.ts +242 -0
- package/src/session/context-identity.ts +389 -0
- package/src/session/context-projection.ts +248 -0
- package/src/session/context-selector.ts +500 -0
- package/src/session/cross-session-adoption.ts +249 -0
- package/src/session/full-history-fold.ts +171 -0
- package/src/session/identity.ts +192 -0
- package/src/session/journal.ts +805 -102
- package/src/session/open-work-intent.ts +732 -0
- package/src/session/open-work.ts +767 -0
- package/src/session/pending-tools.ts +94 -0
- package/src/session/persistence.ts +3569 -127
- package/src/session/runtime-header.ts +208 -0
- package/src/session/shadow-git.ts +13 -5
- package/src/session/verification.ts +1623 -0
- package/src/task/assignment.ts +136 -0
- package/src/task/autonomous-adapter.ts +168 -0
- package/src/task/autonomous-context.ts +630 -0
- package/src/task/autonomous-policy.ts +490 -0
- package/src/task/continuity.ts +179 -0
- package/src/task/execution-cancellation.ts +165 -0
- package/src/task/graph-validate.ts +379 -0
- package/src/task/graph.ts +305 -0
- package/src/task/identity.ts +230 -0
- package/src/task/model.ts +417 -0
- package/src/task/production-scheduler.ts +293 -0
- package/src/task/readiness.ts +229 -0
- package/src/task/scheduler-observability.ts +387 -0
- package/src/task/scheduler.ts +1197 -0
- package/src/task/scheduling-policy.ts +165 -0
- package/src/task/session-authority.ts +148 -0
- package/src/task/session-ownership.ts +211 -0
- package/src/task/store.ts +2887 -0
- package/src/task/sync.ts +343 -0
- package/src/task/trigger.ts +260 -0
- package/src/tools/bash.ts +377 -211
- package/src/tools/code_run.ts +1 -1
- package/src/tools/delete_file.ts +1 -1
- package/src/tools/edit.ts +33 -6
- package/src/tools/evidence.ts +30 -0
- package/src/tools/git.ts +4 -4
- package/src/tools/glob.ts +12 -3
- package/src/tools/grep.ts +1 -1
- package/src/tools/lsp.ts +4 -4
- package/src/tools/mcp_call.ts +11 -4
- package/src/tools/memory.ts +153 -18
- package/src/tools/move_file.ts +1 -1
- package/src/tools/patch.ts +1 -1
- package/src/tools/read_file.ts +1 -1
- package/src/tools/read_image.ts +1 -1
- package/src/tools/submit_result.ts +1 -1
- package/src/tools/task.ts +437 -41
- package/src/tools/todo.ts +662 -35
- package/src/tools/web_fetch.ts +4 -2
- package/src/tools/web_search.ts +9 -3
- package/src/tools/write_file.ts +1 -1
- package/src/ui/assistant/simple.ts +123 -50
- package/src/ui/assistant/turn-status.ts +17 -3
- package/src/ui/contract.ts +184 -0
- package/src/ui/footer.ts +52 -19
- package/src/ui/i18n/en.ts +58 -6
- package/src/ui/i18n/id.ts +58 -6
- package/src/ui/input/prompt-engine.ts +120 -25
- package/src/ui/render/errors.ts +39 -1
- package/src/ui/render/markdown-table.ts +455 -0
- package/src/ui/render/markdown.ts +22 -1
- package/src/ui/render/table-grid.ts +184 -0
- package/src/ui/render/table.ts +15 -76
- package/src/ui/runtime/screen.ts +7 -2
- package/src/ui/runtime/statusline.ts +25 -6
- package/src/ui/tui/app.ts +507 -169
- package/src/ui/tui/transcript.ts +531 -89
- package/vendor/minicore/VENDOR.md +1 -1
- package/vendor/minicore/src/core/budget.ts +25 -25
- package/vendor/minicore/src/core/compact.ts +75 -75
- package/vendor/minicore/src/core/errors.ts +59 -59
- package/vendor/minicore/src/core/events.ts +73 -73
- package/vendor/minicore/src/core/executor.ts +139 -139
- package/vendor/minicore/src/core/history.ts +31 -31
- package/vendor/minicore/src/core/index.ts +41 -41
- package/vendor/minicore/src/core/loop.ts +355 -355
- package/vendor/minicore/src/core/permission.ts +22 -22
- package/vendor/minicore/src/core/provider.ts +39 -39
- package/vendor/minicore/src/core/recovery.ts +35 -35
- package/vendor/minicore/src/core/session.ts +327 -327
- package/vendor/minicore/src/core/snapshot.ts +146 -146
- package/vendor/minicore/src/core/tokens.ts +107 -107
- package/vendor/minicore/src/core/tool.ts +115 -115
- package/vendor/minicore/src/core/types.ts +50 -50
- package/vendor/minicore/src/providers/openai-compat.ts +417 -417
- package/AGENTS.md +0 -45
- package/PLAN.md +0 -491
- package/docs/ARCHITECTURE.html +0 -1248
- package/docs/CONTROL-PLANE-MAP.md +0 -139
- package/docs/HARNESS.md +0 -150
- package/docs/SUMMARY.md +0 -52
- package/docs/UI_RENDER_PIPELINE.md +0 -169
- package/docs/USAGE.md +0 -11
package/src/tools/bash.ts
CHANGED
|
@@ -76,10 +76,34 @@ interface BackgroundJob {
|
|
|
76
76
|
chunks: string[]
|
|
77
77
|
exitCode: number | null
|
|
78
78
|
done: boolean
|
|
79
|
+
/**
|
|
80
|
+
* F-03 (P5 §C2): sid kanonik pemilik job — diikat saat start dari instans
|
|
81
|
+
* tool yang sudah di-composition (createBashJobTools), BUKAN dari argumen
|
|
82
|
+
* tool. null = instans default tanpa sid (library/test legacy); jalur
|
|
83
|
+
* produksi selalu terikat sid lewat composition root.
|
|
84
|
+
*/
|
|
85
|
+
ownerSid: string | null
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
const jobs = new Map<string, BackgroundJob>()
|
|
82
89
|
|
|
90
|
+
// F-03 (P5 §C2): gerbang akses job. Hanya pemilik (sid sama, null==null untuk
|
|
91
|
+
// jalur legacy) yang boleh inspect/cancel. Kegagalan karena kepemilikan
|
|
92
|
+
// menghasilkan TIDAK ADA — pemanggil tak bisa membedakan "job milik sesi lain"
|
|
93
|
+
// dari "id tak dikenal" (non-disclosing).
|
|
94
|
+
function ownedJob(id: string, callerSid: string | null): BackgroundJob | undefined {
|
|
95
|
+
const j = jobs.get(id)
|
|
96
|
+
if (!j || j.ownerSid !== callerSid) return undefined
|
|
97
|
+
return j
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Daftar job hidup yang boleh disebut dalam pesan not-found: HANYA milik
|
|
101
|
+
// pemanggil. Daftar proses-wide (lama) membocorkan id sesi lain — itulah
|
|
102
|
+
// kebocoran yang ditutup C2.
|
|
103
|
+
function liveOwnedIds(callerSid: string | null): string[] {
|
|
104
|
+
return [...jobs.values()].filter((j) => !j.done && j.ownerSid === callerSid).map((j) => j.id)
|
|
105
|
+
}
|
|
106
|
+
|
|
83
107
|
function reapFinishedJobs(): void {
|
|
84
108
|
const now = Date.now()
|
|
85
109
|
for (const [id, j] of jobs) {
|
|
@@ -87,6 +111,60 @@ function reapFinishedJobs(): void {
|
|
|
87
111
|
}
|
|
88
112
|
}
|
|
89
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Sinyal ke SELURUH grup proses (POSIX). Butuh spawn `detached:true` agar
|
|
116
|
+
* shell jadi group leader — tanpa itu `-pid` bukan grup yang valid dan
|
|
117
|
+
* group-kill jadi tak mungkin (cucu selamat). true = sinyal sampai ke grup.
|
|
118
|
+
*/
|
|
119
|
+
function signalProcessGroup(p: ReturnType<typeof spawn>, signal: NodeJS.Signals): boolean {
|
|
120
|
+
if (process.platform === "win32" || p.pid === undefined) return false
|
|
121
|
+
try {
|
|
122
|
+
process.kill(-p.pid, signal)
|
|
123
|
+
return true
|
|
124
|
+
} catch {
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* [Fase 2 / LOOP-INV-10] Eskalasi AWAL yang sopan: SIGTERM ke seluruh process
|
|
131
|
+
* group, bukan hanya shell induk.
|
|
132
|
+
*
|
|
133
|
+
* Kenapa penting: `p.kill("SIGTERM")` hanya menyentuh shell wrapper. Cucu
|
|
134
|
+
* (`node -e`, dev server) tetap hidup, menahan pipe, dan baru mati 2 detik
|
|
135
|
+
* kemudian oleh SIGKILL grup — padahal banyak proses menangani SIGTERM dengan
|
|
136
|
+
* flush/cleanup yang benar bila sinyalnya sampai. Helper ini dipakai sebelum
|
|
137
|
+
* timer eskalasi `killTree` (SIGKILL), di jalur timeout DAN abort.
|
|
138
|
+
*
|
|
139
|
+
* `opts` adalah seam deterministik untuk test: perilaku POSIX dapat diuji di
|
|
140
|
+
* Windows tanpa benar-benar mengirim sinyal ke proses nyata.
|
|
141
|
+
*/
|
|
142
|
+
export function signalProcessGroupGraceful(
|
|
143
|
+
pid: number | undefined,
|
|
144
|
+
fallback: { kill: (signal?: NodeJS.Signals | number) => boolean },
|
|
145
|
+
opts: {
|
|
146
|
+
platform?: NodeJS.Platform
|
|
147
|
+
killGroup?: (pid: number, signal: NodeJS.Signals) => boolean
|
|
148
|
+
} = {},
|
|
149
|
+
): "group" | "fallback" {
|
|
150
|
+
const platform = opts.platform ?? process.platform
|
|
151
|
+
if (platform !== "win32" && typeof pid === "number" && pid > 0) {
|
|
152
|
+
const killGroup =
|
|
153
|
+
opts.killGroup ??
|
|
154
|
+
((target: number, signal: NodeJS.Signals): boolean => process.kill(target, signal))
|
|
155
|
+
try {
|
|
156
|
+
// Negatif = process group id (shell adalah group leader karena detached).
|
|
157
|
+
if (killGroup(-pid, "SIGTERM")) return "group"
|
|
158
|
+
} catch {
|
|
159
|
+
// Grup sudah hilang / ESRCH: jatuh ke sinyal proses tunggal di bawah.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
fallback.kill("SIGTERM")
|
|
164
|
+
} catch {}
|
|
165
|
+
return "fallback"
|
|
166
|
+
}
|
|
167
|
+
|
|
90
168
|
/**
|
|
91
169
|
* Bunuh proses + seluruh subtree-nya. Di Windows `p.kill()` hanya membunuh
|
|
92
170
|
* wrapper `cmd.exe` — cucu seperti `node -e "while(true){}"` tetap hidup,
|
|
@@ -108,14 +186,10 @@ function killTree(p: ReturnType<typeof spawn>): void {
|
|
|
108
186
|
},
|
|
109
187
|
)
|
|
110
188
|
if (r.status === 0) return
|
|
111
|
-
} else if (p
|
|
189
|
+
} else if (signalProcessGroup(p, "SIGKILL")) {
|
|
112
190
|
// POSIX: bunuh seluruh grup proses (shell wrapper + cucu seperti
|
|
113
|
-
// `node -e`). Spawn
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
process.kill(-p.pid, "SIGKILL")
|
|
117
|
-
return
|
|
118
|
-
} catch {}
|
|
191
|
+
// `node -e`). Spawn memakai detached:true agar shell jadi group leader.
|
|
192
|
+
return
|
|
119
193
|
}
|
|
120
194
|
} catch {}
|
|
121
195
|
try {
|
|
@@ -123,11 +197,20 @@ function killTree(p: ReturnType<typeof spawn>): void {
|
|
|
123
197
|
} catch {}
|
|
124
198
|
}
|
|
125
199
|
|
|
126
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Hentikan semua job — dipanggil saat CLI keluar agar tidak ada proses yatim.
|
|
202
|
+
*
|
|
203
|
+
* WAJIB tree-kill, bukan `proc.kill()`: yang dibunuh cuma wrapper shell,
|
|
204
|
+
* sedangkan cucu (dev server, watcher, `node -e`) tetap hidup, menahan pipe
|
|
205
|
+
* stdio, dan jadi proses yatim yang tak pernah dibersihkan. Modul ini sudah
|
|
206
|
+
* punya killTree() untuk itu — jalur shutdown sebelumnya tak memakainya.
|
|
207
|
+
*/
|
|
127
208
|
export function killAllBackgroundJobs(): void {
|
|
128
209
|
for (const [id, j] of jobs) {
|
|
129
210
|
try {
|
|
130
|
-
|
|
211
|
+
// `!j.done` = jangan sentuh pid yang sudah mati (risiko pid dipakai
|
|
212
|
+
// ulang proses lain → taskkill /pid membunuh proses tak berkaitan).
|
|
213
|
+
if (!j.done) killTree(j.proc)
|
|
131
214
|
} catch {}
|
|
132
215
|
jobs.delete(id)
|
|
133
216
|
}
|
|
@@ -137,7 +220,7 @@ export function listBackgroundJobs(): { id: string; cmd: string; done: boolean }
|
|
|
137
220
|
return [...jobs.values()].map((j) => ({ id: j.id, cmd: j.cmd, done: j.done }))
|
|
138
221
|
}
|
|
139
222
|
|
|
140
|
-
function startBackground(cmd: string, cwd: string | undefined): string {
|
|
223
|
+
function startBackground(cmd: string, cwd: string | undefined, ownerSid: string | null): string {
|
|
141
224
|
reapFinishedJobs()
|
|
142
225
|
const live = [...jobs.values()].filter((j) => !j.done).length
|
|
143
226
|
if (live >= LIMITS.BASH_BACKGROUND_MAX_JOBS) {
|
|
@@ -151,6 +234,10 @@ function startBackground(cmd: string, cwd: string | undefined): string {
|
|
|
151
234
|
cwd,
|
|
152
235
|
env: sanitizeSpawnEnv(process.env),
|
|
153
236
|
stdio: ["ignore", "pipe", "pipe"],
|
|
237
|
+
// detached agar shell jadi group leader → killTree bisa menutup SELURUH
|
|
238
|
+
// grup (POSIX kill(-pid)). Tanpa ini yang bisa dibunuh cuma wrapper shell
|
|
239
|
+
// dan cucu (dev server, watcher) jadi yatim saat bash_kill/shutdown.
|
|
240
|
+
detached: process.platform !== "win32",
|
|
154
241
|
})
|
|
155
242
|
const job: BackgroundJob = {
|
|
156
243
|
id,
|
|
@@ -162,6 +249,7 @@ function startBackground(cmd: string, cwd: string | undefined): string {
|
|
|
162
249
|
chunks: [],
|
|
163
250
|
exitCode: null,
|
|
164
251
|
done: false,
|
|
252
|
+
ownerSid,
|
|
165
253
|
}
|
|
166
254
|
proc.stdout?.on("data", (d: Buffer) => {
|
|
167
255
|
const piece = job.buffer.append("out", d)
|
|
@@ -183,224 +271,302 @@ function startBackground(cmd: string, cwd: string | undefined): string {
|
|
|
183
271
|
return id
|
|
184
272
|
}
|
|
185
273
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
274
|
+
// F-03: instans tool bash terikat satu sid pemilik. Instans default (export
|
|
275
|
+
// di bawah) memakai null — jalur library/test tanpa komposisi sid; sesi
|
|
276
|
+
// produksi memakai createBashJobTools(sid) lewat composition root.
|
|
277
|
+
function makeBashTool(ownerSid: string | null): Tool {
|
|
278
|
+
return {
|
|
279
|
+
name: "bash",
|
|
280
|
+
description:
|
|
281
|
+
"Run a shell command (default timeout 30s, max output 20k chars, exit code prefixed). Set background:true for long-running processes (dev server, watcher), then collect output via bash_output and stop with bash_kill. Prefer git_status/git_diff/git_log tools over raw `git` commands: raw git executes repository-configured hooks, filters and diff drivers. Destructive, network-exfiltrating, env-dumping, and inline-interpreter commands are blocked. If the shell allowlist denies a command: do NOT retry blindly — file reads/writes belong to read_file/write_file/edit, and a full shell needs the operator to rerun with --allow-all or --sandbox docker. On Windows the shell is cmd.exe (use dir, echo %VAR%, type).",
|
|
282
|
+
parameters: {
|
|
283
|
+
type: "object",
|
|
284
|
+
properties: {
|
|
285
|
+
cmd: { type: "string", description: "command to run (shell: cmd.exe on Windows)" },
|
|
286
|
+
cwd: {
|
|
287
|
+
type: "string",
|
|
288
|
+
description: "working directory relative to the workspace (default: workspace root)",
|
|
289
|
+
},
|
|
290
|
+
timeoutMs: { type: "number", description: "timeout in ms (default 30000)" },
|
|
291
|
+
background: {
|
|
292
|
+
type: "boolean",
|
|
293
|
+
description:
|
|
294
|
+
"run without waiting for completion; returns a job id for bash_output/bash_kill",
|
|
295
|
+
},
|
|
203
296
|
},
|
|
297
|
+
required: ["cmd"],
|
|
298
|
+
additionalProperties: false,
|
|
204
299
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// design; safe-open O_NOFOLLOW hanya untuk tool file). Mitigasi: --sandbox
|
|
222
|
-
// untuk isolasi penuh; lihat permission.ts jail + safe-open.ts.
|
|
223
|
-
const timeout = timeoutMs ?? LIMITS.BASH_DEFAULT_TIMEOUT_MS
|
|
300
|
+
async execute({ cmd, cwd, timeoutMs, background }, ctx) {
|
|
301
|
+
const sessionRoot = ctx.cwd ?? process.cwd()
|
|
302
|
+
const c = cwd as string | undefined
|
|
303
|
+
if (c && (isCwdOutsideRoot(c, sessionRoot) || isPathOutsideRoot(c, sessionRoot)))
|
|
304
|
+
throw new Error(`cwd outside workspace: ${c}`)
|
|
305
|
+
const resolvedCwd = c ? resolvePath(sessionRoot, c) : undefined
|
|
306
|
+
const effectiveCwd = resolvedCwd ?? sessionRoot
|
|
307
|
+
// Catatan TOCTOU (bug-hunt 2026-09-19, tervalidasi e2e): cek-cwd di atas
|
|
308
|
+
// (isCwdOutsideRoot = realpath) menutup varian cwd-form — swap setelah
|
|
309
|
+
// titik ini masih menang SEBELUM spawn (jendela mikrodetik pada alur
|
|
310
|
+
// executor normal; butuh penulis konkuren jahat). Varian redirect-form
|
|
311
|
+
// (`> sub/f` tanpa arg cwd) tak punya recheck saat spawn: shell me-resolve
|
|
312
|
+
// symlink — tak bisa ditutup murah dari sini (shell mengikuti symlink by
|
|
313
|
+
// design; safe-open O_NOFOLLOW hanya untuk tool file). Mitigasi: --sandbox
|
|
314
|
+
// untuk isolasi penuh; lihat permission.ts jail + safe-open.ts.
|
|
315
|
+
const timeout = timeoutMs ?? LIMITS.BASH_DEFAULT_TIMEOUT_MS
|
|
224
316
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
317
|
+
if (background === true) {
|
|
318
|
+
// Sandbox tidak diterapkan di jalur background: container/namespace
|
|
319
|
+
// ephemeral mati bersama call-nya, jadi menjanjikan isolasi di sini
|
|
320
|
+
// akan menyesatkan. Tolak eksplisit daripada diam-diam tanpa sandbox.
|
|
321
|
+
if (process.env.MINICODE_SANDBOX) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
"background:true is not supported while --sandbox is active (the process must outlive the turn)",
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
const id = startBackground(cmd as string, resolvedCwd, ownerSid)
|
|
327
|
+
// F-07: echo perintah di-scrub seperti output foreground — command line
|
|
328
|
+
// bisa membawa secret (`curl -H "Authorization: Bearer …"`), dan versi
|
|
329
|
+
// lama menaruhnya mentah ke konteks model.
|
|
330
|
+
return `background job started: ${id}\ncmd: ${scrubSecrets(String(cmd)).slice(0, 200)}\ncollect output: bash_output({ id: "${id}" })`
|
|
233
331
|
}
|
|
234
|
-
const id = startBackground(cmd as string, resolvedCwd)
|
|
235
|
-
// F-07: echo perintah di-scrub seperti output foreground — command line
|
|
236
|
-
// bisa membawa secret (`curl -H "Authorization: Bearer …"`), dan versi
|
|
237
|
-
// lama menaruhnya mentah ke konteks model.
|
|
238
|
-
return `background job started: ${id}\ncmd: ${scrubSecrets(String(cmd)).slice(0, 200)}\ncollect output: bash_output({ id: "${id}" })`
|
|
239
|
-
}
|
|
240
332
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
333
|
+
// Docker sandbox mode — run in ephemeral isolated container
|
|
334
|
+
if (process.env.MINICODE_SANDBOX === "docker") {
|
|
335
|
+
if (dockerAvailable()) {
|
|
336
|
+
const res = await runInDocker(cmd as string, effectiveCwd, {
|
|
337
|
+
timeoutMs: timeout,
|
|
338
|
+
env: sanitizeSpawnEnv(process.env) as Record<string, string>,
|
|
339
|
+
})
|
|
340
|
+
const text = scrubSecrets(res.output)
|
|
341
|
+
if (res.code !== 0 && res.code !== null)
|
|
342
|
+
return `exit ${res.code}\n${capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)}`
|
|
343
|
+
return capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
344
|
+
}
|
|
345
|
+
if (sandboxStrict() || !sandboxExplicitFallbackAllowed()) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
"[sandbox] MINICODE_SANDBOX=docker but docker unavailable — refusing direct execution (explicit sandbox request must not silently downgrade; set MINICODE_SANDBOX_ALLOW_FALLBACK=1 to allow host fallback explicitly)",
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
process.stderr.write(
|
|
351
|
+
"[warn] MINICODE_SANDBOX=docker but docker unavailable — falling back to direct execution (explicit MINICODE_SANDBOX_ALLOW_FALLBACK=1)\n",
|
|
352
|
+
)
|
|
252
353
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
354
|
+
// OS-native sandbox (Seatbelt macOS / bubblewrap Linux) — Codex/Gemini-like without Docker
|
|
355
|
+
if (
|
|
356
|
+
process.env.MINICODE_SANDBOX === "os" ||
|
|
357
|
+
process.env.MINICODE_SANDBOX === "seatbelt" ||
|
|
358
|
+
process.env.MINICODE_SANDBOX === "bwrap"
|
|
359
|
+
) {
|
|
360
|
+
if (osSandboxAvailable()) {
|
|
361
|
+
const res = await runInOsSandbox(cmd as string, effectiveCwd, {
|
|
362
|
+
timeoutMs: timeout,
|
|
363
|
+
env: sanitizeSpawnEnv(process.env) as Record<string, string>,
|
|
364
|
+
})
|
|
365
|
+
const text = scrubSecrets(res.output)
|
|
366
|
+
if (res.code !== 0 && res.code !== null)
|
|
367
|
+
return `exit ${res.code}\n${capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)}`
|
|
368
|
+
return capMarked(text, LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
369
|
+
}
|
|
370
|
+
if (sandboxStrict() || !sandboxExplicitFallbackAllowed()) {
|
|
371
|
+
throw new Error(
|
|
372
|
+
"[sandbox] OS sandbox unavailable — refusing direct execution (explicit sandbox request must not silently downgrade; set MINICODE_SANDBOX_ALLOW_FALLBACK=1 to allow host fallback explicitly)",
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
process.stderr.write(
|
|
376
|
+
"[warn] MINICODE_SANDBOX=os but OS sandbox unavailable — falling back to direct execution (explicit MINICODE_SANDBOX_ALLOW_FALLBACK=1)\n",
|
|
256
377
|
)
|
|
257
378
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
379
|
+
|
|
380
|
+
return await new Promise((resolveOut, reject) => {
|
|
381
|
+
const startedAt = Date.now()
|
|
382
|
+
// [Fase 2 / LOOP-INV-07] Dua sebab penghentian yang HARUS dibedakan:
|
|
383
|
+
// timeout internal (efek samping = UNKNOWN) vs abort turn (dibatalkan
|
|
384
|
+
// pemanggil). Sebelumnya keduanya hanya terlihat sebagai `exit null`
|
|
385
|
+
// sehingga model tak punya sinyal untuk berhenti mengulang perintah
|
|
386
|
+
// destruktif yang mungkin sudah setengah berjalan.
|
|
387
|
+
let timedOut = false
|
|
388
|
+
const p = spawn(cmd as string, {
|
|
389
|
+
shell: true,
|
|
390
|
+
// F-24: selalu effectiveCwd (sessionRoot bila arg cwd absen), bukan
|
|
391
|
+
// undefined (= inherit process.cwd()). Jail/permission dievaluasi
|
|
392
|
+
// terhadap sessionRoot — eksekusi harus di direktori yang sama.
|
|
393
|
+
cwd: effectiveCwd,
|
|
394
|
+
env: sanitizeSpawnEnv(process.env),
|
|
395
|
+
signal: ctx.signal,
|
|
396
|
+
// detached agar shell jadi group leader → killTree bisa bunuh
|
|
397
|
+
// seluruh grup (POSIX kill(-pid)). Tanpa ini cucu yatim menahan pipe.
|
|
398
|
+
detached: process.platform !== "win32",
|
|
272
399
|
})
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
400
|
+
const buf = new CappedBuffer(LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
401
|
+
// Progres inkremental: command panjang (bun test, build) tidak lagi
|
|
402
|
+
// membisu sampai selesai. Event ini opsional bagi UI.
|
|
403
|
+
const emitChunk = (piece: string) => {
|
|
404
|
+
if (!piece) return
|
|
405
|
+
try {
|
|
406
|
+
ctx.emit?.({
|
|
407
|
+
type: "provider:extension",
|
|
408
|
+
kind: "bash-output",
|
|
409
|
+
data: { text: scrubSecrets(piece) },
|
|
410
|
+
})
|
|
411
|
+
} catch {}
|
|
412
|
+
}
|
|
413
|
+
p.stdout.on("data", (d: Buffer) => emitChunk(buf.append("out", d)))
|
|
414
|
+
p.stderr.on("data", (d: Buffer) => emitChunk(buf.append("err", d)))
|
|
415
|
+
p.on("error", reject)
|
|
416
|
+
p.on("close", (code) => {
|
|
417
|
+
const text = buf.text()
|
|
418
|
+
if (timedOut) {
|
|
419
|
+
// Prefix deterministik (parsing oleh jurnal/recovery) + instruksi
|
|
420
|
+
// eksplisit. `isError: true` dicapai dengan reject: kernel
|
|
421
|
+
// mengubah message menjadi ToolResult{isError:true}.
|
|
422
|
+
const elapsed = Date.now() - startedAt
|
|
423
|
+
const partial = text.length > 4000 ? `…${text.slice(-4000)}` : text
|
|
424
|
+
reject(
|
|
425
|
+
new Error(
|
|
426
|
+
`[TOOL_OUTCOME state=UNKNOWN reason=TIMEOUT side_effect_tier=LOCAL_ENV_MUTATION ` +
|
|
427
|
+
`duration_ms=${elapsed} timeout_ms=${timeout}]\n` +
|
|
428
|
+
`Command was cut off by the ${timeout} ms timeout. Its side effects are UNKNOWN ` +
|
|
429
|
+
`(the command may have partially run). Do NOT re-run a side-effecting command ` +
|
|
430
|
+
`before inspecting workspace/process state.\n` +
|
|
431
|
+
(partial
|
|
432
|
+
? `--- partial output ---\n${partial}`
|
|
433
|
+
: "--- partial output ---\n(none)"),
|
|
434
|
+
),
|
|
435
|
+
)
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
if (code !== 0) resolveOut(`exit ${code}\n${text}`)
|
|
439
|
+
else resolveOut(text)
|
|
440
|
+
})
|
|
441
|
+
let killTimer: ReturnType<typeof setTimeout> | undefined
|
|
442
|
+
const t = setTimeout(() => {
|
|
443
|
+
timedOut = true
|
|
444
|
+
// Windows: SIGTERM hanya membunuh cmd.exe wrapper — cucu (node -e)
|
|
445
|
+
// bisa belum lahir (spawn lambat) atau yatim sambil menahan pipe.
|
|
446
|
+
// Eskalasi taskkill /pid-shell-yang-sudah-mati lalu gagal total.
|
|
447
|
+
// Jadi di win32 langsung tree-kill saat timeout, tanpa jeda.
|
|
448
|
+
// POSIX: SIGTERM ke SELURUH grup dulu (LOOP-INV-10) supaya cucu
|
|
449
|
+
// sempat cleanup; SIGKILL grup menyusul bila 2 detik tak cukup.
|
|
450
|
+
if (process.platform === "win32") killTree(p)
|
|
451
|
+
else signalProcessGroupGraceful(p.pid, p)
|
|
452
|
+
killTimer = setTimeout(() => {
|
|
453
|
+
killTree(p)
|
|
454
|
+
}, 2000)
|
|
455
|
+
}, timeout)
|
|
456
|
+
const onAbort = () => {
|
|
457
|
+
clearTimeout(t)
|
|
458
|
+
if (killTimer) clearTimeout(killTimer)
|
|
459
|
+
if (process.platform === "win32") killTree(p)
|
|
460
|
+
else signalProcessGroupGraceful(p.pid, p)
|
|
461
|
+
killTimer = setTimeout(() => {
|
|
462
|
+
killTree(p)
|
|
463
|
+
}, 1000)
|
|
464
|
+
}
|
|
465
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true })
|
|
466
|
+
p.on("close", () => {
|
|
467
|
+
ctx.signal.removeEventListener("abort", onAbort)
|
|
468
|
+
clearTimeout(t)
|
|
469
|
+
if (killTimer) clearTimeout(killTimer)
|
|
470
|
+
})
|
|
471
|
+
})
|
|
472
|
+
},
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function makeBashOutputTool(ownerSid: string | null): Tool {
|
|
477
|
+
return {
|
|
478
|
+
name: "bash_output",
|
|
479
|
+
description:
|
|
480
|
+
"Get NEW output from a background job (since the last read). Includes the exit status once it has finished.",
|
|
481
|
+
parameters: {
|
|
482
|
+
type: "object",
|
|
483
|
+
properties: {
|
|
484
|
+
id: { type: "string", description: "job id dari bash background:true" },
|
|
485
|
+
},
|
|
486
|
+
required: ["id"],
|
|
487
|
+
additionalProperties: false,
|
|
488
|
+
},
|
|
489
|
+
async execute({ id }, ctx: ToolContext) {
|
|
490
|
+
ctx.signal.throwIfAborted()
|
|
491
|
+
// F-03: kepemilikan diperiksa SEBELUM output/status apa pun dibocorkan;
|
|
492
|
+
// pesan untuk job sesi lain = persis "tidak dikenal", tanpa daftar id asing.
|
|
493
|
+
const job = ownedJob(String(id), ownerSid)
|
|
494
|
+
if (!job) {
|
|
495
|
+
const live = liveOwnedIds(ownerSid)
|
|
279
496
|
throw new Error(
|
|
280
|
-
"
|
|
497
|
+
`job "${id}" not found${live.length ? ` — active: ${live.join(", ")}` : ""}`,
|
|
281
498
|
)
|
|
282
499
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
)
|
|
286
|
-
|
|
500
|
+
const fresh = job.chunks.slice(job.cursor)
|
|
501
|
+
job.cursor = job.chunks.length
|
|
502
|
+
const status = job.done ? `finished (exit ${job.exitCode ?? "?"})` : "running"
|
|
503
|
+
if (fresh.length === 0) return `[${job.id}] ${status} — no new output yet`
|
|
504
|
+
return capMarked(`[${job.id}] ${status}\n${fresh.join("")}`, LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
505
|
+
},
|
|
506
|
+
}
|
|
507
|
+
}
|
|
287
508
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
509
|
+
function makeBashKillTool(ownerSid: string | null): Tool {
|
|
510
|
+
return {
|
|
511
|
+
name: "bash_kill",
|
|
512
|
+
description: "Stop a background job (SIGTERM then SIGKILL).",
|
|
513
|
+
parameters: {
|
|
514
|
+
type: "object",
|
|
515
|
+
properties: { id: { type: "string", description: "job id" } },
|
|
516
|
+
required: ["id"],
|
|
517
|
+
additionalProperties: false,
|
|
518
|
+
},
|
|
519
|
+
async execute({ id }, ctx: ToolContext) {
|
|
520
|
+
ctx.signal.throwIfAborted()
|
|
521
|
+
// F-03: sama seperti bash_output — penolakan identik dengan id tak dikenal,
|
|
522
|
+
// tanpa mengungkap status (hidup/selesai) milik sesi lain.
|
|
523
|
+
const job = ownedJob(String(id), ownerSid)
|
|
524
|
+
if (!job) throw new Error(`job "${id}" not found`)
|
|
525
|
+
if (job.done) return `[${job.id}] already finished (exit ${job.exitCode ?? "?"})`
|
|
526
|
+
// Bunuh TREE, bukan cuma wrapper shell: `proc.kill()` di Windows hanya
|
|
527
|
+
// menebas cmd.exe — cucu (watcher, `node -e`) tetap hidup, menahan pipe
|
|
528
|
+
// stdio sehingga job tak pernah selesai dan prosesnya yatim.
|
|
529
|
+
// POSIX diberi jeda SIGTERM ke grup dulu (graceful); Windows langsung
|
|
530
|
+
// tree-kill, karena proc.kill hanya menebas cmd.exe sedangkan
|
|
531
|
+
// taskkill /T butuh akar yang masih hidup.
|
|
532
|
+
if (process.platform === "win32") killTree(job.proc)
|
|
533
|
+
else if (!signalProcessGroup(job.proc, "SIGTERM")) {
|
|
306
534
|
try {
|
|
307
|
-
|
|
308
|
-
type: "provider:extension",
|
|
309
|
-
kind: "bash-output",
|
|
310
|
-
data: { text: scrubSecrets(piece) },
|
|
311
|
-
})
|
|
535
|
+
job.proc.kill("SIGTERM")
|
|
312
536
|
} catch {}
|
|
313
537
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
else resolveOut(text)
|
|
321
|
-
})
|
|
322
|
-
let killTimer: ReturnType<typeof setTimeout> | undefined
|
|
323
|
-
const t = setTimeout(() => {
|
|
324
|
-
// Windows: SIGTERM hanya membunuh cmd.exe wrapper — cucu (node -e)
|
|
325
|
-
// bisa belum lahir (spawn lambat) atau yatim sambil menahan pipe.
|
|
326
|
-
// Eskalasi taskkill /pid-shell-yang-sudah-mati lalu gagal total.
|
|
327
|
-
// Jadi di win32 langsung tree-kill saat timeout, tanpa jeda.
|
|
328
|
-
if (process.platform === "win32") killTree(p)
|
|
329
|
-
else p.kill("SIGTERM")
|
|
330
|
-
killTimer = setTimeout(() => {
|
|
331
|
-
killTree(p)
|
|
332
|
-
}, 2000)
|
|
333
|
-
}, timeout)
|
|
334
|
-
const onAbort = () => {
|
|
335
|
-
clearTimeout(t)
|
|
336
|
-
if (killTimer) clearTimeout(killTimer)
|
|
337
|
-
if (process.platform === "win32") killTree(p)
|
|
338
|
-
else p.kill("SIGTERM")
|
|
339
|
-
killTimer = setTimeout(() => {
|
|
340
|
-
killTree(p)
|
|
341
|
-
}, 1000)
|
|
342
|
-
}
|
|
343
|
-
ctx.signal.addEventListener("abort", onAbort, { once: true })
|
|
344
|
-
p.on("close", () => {
|
|
345
|
-
ctx.signal.removeEventListener("abort", onAbort)
|
|
346
|
-
clearTimeout(t)
|
|
347
|
-
if (killTimer) clearTimeout(killTimer)
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
},
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
export const bashOutputTool: Tool = {
|
|
354
|
-
name: "bash_output",
|
|
355
|
-
description:
|
|
356
|
-
"Get NEW output from a background job (since the last read). Includes the exit status once it has finished.",
|
|
357
|
-
parameters: {
|
|
358
|
-
type: "object",
|
|
359
|
-
properties: {
|
|
360
|
-
id: { type: "string", description: "job id dari bash background:true" },
|
|
538
|
+
setTimeout(() => {
|
|
539
|
+
try {
|
|
540
|
+
if (!job.done) killTree(job.proc)
|
|
541
|
+
} catch {}
|
|
542
|
+
}, 1000)
|
|
543
|
+
return `[${job.id}] stopped`
|
|
361
544
|
},
|
|
362
|
-
|
|
363
|
-
additionalProperties: false,
|
|
364
|
-
},
|
|
365
|
-
async execute({ id }, ctx: ToolContext) {
|
|
366
|
-
ctx.signal.throwIfAborted()
|
|
367
|
-
const job = jobs.get(String(id))
|
|
368
|
-
if (!job) {
|
|
369
|
-
const live = listBackgroundJobs()
|
|
370
|
-
throw new Error(
|
|
371
|
-
`job "${id}" not found${live.length ? ` — active: ${live.map((j) => j.id).join(", ")}` : ""}`,
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
const fresh = job.chunks.slice(job.cursor)
|
|
375
|
-
job.cursor = job.chunks.length
|
|
376
|
-
const status = job.done ? `finished (exit ${job.exitCode ?? "?"})` : "running"
|
|
377
|
-
if (fresh.length === 0) return `[${job.id}] ${status} — no new output yet`
|
|
378
|
-
return capMarked(`[${job.id}] ${status}\n${fresh.join("")}`, LIMITS.BASH_OUTPUT_MAX_CHARS)
|
|
379
|
-
},
|
|
545
|
+
}
|
|
380
546
|
}
|
|
381
547
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
548
|
+
// Instans default TANPA sid: jalur library/test lama tetap berfungsi (caller
|
|
549
|
+
// null mengakses job null). Sesi produksi WAJIB memakai createBashJobTools.
|
|
550
|
+
export const bashTool: Tool = makeBashTool(null)
|
|
551
|
+
export const bashOutputTool: Tool = makeBashOutputTool(null)
|
|
552
|
+
export const bashKillTool: Tool = makeBashKillTool(null)
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* F-03 (P5 §C2): instans bash/bash_output/bash_kill yang menyandang satu sid
|
|
556
|
+
* pemilik kanonik. Dipanggil composition root (tool-layer untuk sesi CLI,
|
|
557
|
+
* serveMcp dengan contextId per-instance) — sid DIJAHIT sebagai closure saat
|
|
558
|
+
* perakitan, bukan dari argumen tool yang bisa dipalsukan pemanggil.
|
|
559
|
+
*/
|
|
560
|
+
export function createBashJobTools(ownerSid: string): {
|
|
561
|
+
bash: Tool
|
|
562
|
+
bashOutput: Tool
|
|
563
|
+
bashKill: Tool
|
|
564
|
+
} {
|
|
565
|
+
if (typeof ownerSid !== "string" || !ownerSid)
|
|
566
|
+
throw new Error("createBashJobTools: ownerSid must be a non-empty canonical session id")
|
|
567
|
+
return {
|
|
568
|
+
bash: makeBashTool(ownerSid),
|
|
569
|
+
bashOutput: makeBashOutputTool(ownerSid),
|
|
570
|
+
bashKill: makeBashKillTool(ownerSid),
|
|
571
|
+
}
|
|
406
572
|
}
|