minicode-ai 0.26.0 → 0.28.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.
Files changed (139) hide show
  1. package/cli/args.ts +120 -16
  2. package/cli/commands/acp.ts +38 -28
  3. package/cli/commands/auth.ts +17 -17
  4. package/cli/commands/config.ts +65 -66
  5. package/cli/commands/daemon.ts +44 -16
  6. package/cli/commands/doctor.ts +11 -12
  7. package/cli/commands/exec.ts +35 -73
  8. package/cli/commands/mcp.ts +25 -8
  9. package/cli/commands/memory.ts +16 -24
  10. package/cli/commands/openwork.ts +6 -2
  11. package/cli/commands/pricing.ts +14 -12
  12. package/cli/commands/providers.ts +36 -57
  13. package/cli/commands/sessions.ts +24 -18
  14. package/cli/commands/skills.ts +33 -18
  15. package/cli/commands/stats.ts +15 -30
  16. package/cli/commands.ts +96 -46
  17. package/cli/context-command-run.ts +171 -0
  18. package/cli/context-command.ts +87 -0
  19. package/cli/index.ts +96 -98
  20. package/cli/model-manager.ts +7 -2
  21. package/cli/provider-manager.ts +33 -18
  22. package/cli/router.ts +41 -12
  23. package/cli/setup.ts +246 -123
  24. package/cli/tui.ts +311 -109
  25. package/docs/TERMINAL_CONTRACT.md +254 -69
  26. package/docs/UI_RENDER_PIPELINE.md +9 -1
  27. package/docs/agents.md +2 -2
  28. package/docs/architecture.md +3 -3
  29. package/docs/choosing-mode.md +7 -9
  30. package/docs/cli.md +3 -5
  31. package/docs/config.md +16 -0
  32. package/docs/environment.md +3 -3
  33. package/docs/policy-sandbox.md +3 -3
  34. package/docs/repl.md +3 -2
  35. package/docs/tools.md +1 -1
  36. package/package.json +1 -1
  37. package/src/app/mentions.ts +60 -13
  38. package/src/app/rag-layer.ts +17 -20
  39. package/src/app/session.ts +119 -66
  40. package/src/app/tool-layer.ts +12 -17
  41. package/src/config.ts +64 -104
  42. package/src/constants.ts +23 -9
  43. package/src/daemon/capability.ts +8 -1
  44. package/src/daemon/control.ts +3 -2
  45. package/src/daemon/server.ts +57 -0
  46. package/src/hooks/run.ts +73 -41
  47. package/src/lib/db-path.ts +47 -0
  48. package/src/lib/process-tree.ts +62 -0
  49. package/src/lib/public-http.ts +88 -23
  50. package/src/lib/trusted-exec.ts +48 -1
  51. package/src/lsp/client.ts +62 -17
  52. package/src/mcp/client.ts +85 -38
  53. package/src/mcp/http-transport.ts +28 -16
  54. package/src/mcp/transport.ts +42 -6
  55. package/src/memory/files.ts +164 -134
  56. package/src/memory/vector.ts +371 -420
  57. package/src/policy/approval-binding.ts +122 -45
  58. package/src/policy/bash-guard.ts +18 -7
  59. package/src/policy/compaction.ts +51 -18
  60. package/src/policy/context-window.ts +109 -0
  61. package/src/policy/context.ts +78 -37
  62. package/src/policy/executor.ts +17 -7
  63. package/src/policy/microcompact.ts +4 -3
  64. package/src/policy/no-progress.ts +103 -22
  65. package/src/policy/permission.ts +36 -12
  66. package/src/policy/tool-contract.ts +74 -416
  67. package/src/policy/usage.ts +24 -2
  68. package/src/policy/verifier.ts +50 -2
  69. package/src/policy/work-mode.ts +28 -54
  70. package/src/presentation/adapter.ts +24 -16
  71. package/src/providers/guards.ts +41 -2
  72. package/src/providers/provision.ts +6 -60
  73. package/src/providers/responses.ts +1 -0
  74. package/src/repo/repomap.ts +180 -23
  75. package/src/runtime/execution-journal.ts +4 -29
  76. package/src/sandbox/docker.ts +58 -34
  77. package/src/sandbox/mask.ts +157 -0
  78. package/src/sandbox/os.ts +107 -73
  79. package/src/session/authority.ts +29 -10
  80. package/src/session/context-projection.ts +6 -5
  81. package/src/session/open-work.ts +26 -3
  82. package/src/session/persistence.ts +25 -58
  83. package/src/session/verification.ts +170 -20
  84. package/src/skills/loader.ts +31 -16
  85. package/src/task/production-scheduler.ts +13 -1
  86. package/src/task/store.ts +20 -37
  87. package/src/telemetry/trace.ts +27 -0
  88. package/src/tools/ask_user.ts +1 -13
  89. package/src/tools/bash.ts +27 -92
  90. package/src/tools/code_run.ts +1 -1
  91. package/src/tools/context.ts +133 -0
  92. package/src/tools/delete_file.ts +3 -2
  93. package/src/tools/edit.ts +37 -72
  94. package/src/tools/git.ts +86 -9
  95. package/src/tools/glob.ts +26 -51
  96. package/src/tools/grep.ts +67 -57
  97. package/src/tools/hashline.ts +4 -0
  98. package/src/tools/lsp.ts +11 -8
  99. package/src/tools/mcp_call.ts +9 -6
  100. package/src/tools/memory.ts +56 -33
  101. package/src/tools/move_file.ts +36 -10
  102. package/src/tools/patch.ts +13 -21
  103. package/src/tools/read_file.ts +18 -25
  104. package/src/tools/read_image.ts +35 -33
  105. package/src/tools/submit_result.ts +29 -8
  106. package/src/tools/task.ts +74 -17
  107. package/src/tools/todo.ts +181 -74
  108. package/src/tools/web_fetch.ts +42 -2
  109. package/src/tools/web_search.ts +47 -8
  110. package/src/ui/approval/prompt.ts +206 -47
  111. package/src/ui/assistant/turn-status.ts +14 -5
  112. package/src/ui/footer.ts +4 -4
  113. package/src/ui/i18n/en.ts +59 -23
  114. package/src/ui/i18n/id.ts +88 -51
  115. package/src/ui/input/input.ts +4 -3
  116. package/src/ui/input/prompt-engine.ts +35 -5
  117. package/src/ui/render/activity-panel.ts +4 -2
  118. package/src/ui/render/hint.ts +7 -4
  119. package/src/ui/render/list.ts +32 -0
  120. package/src/ui/render/markdown.ts +6 -3
  121. package/src/ui/render/notice.ts +19 -0
  122. package/src/ui/render/table-grid.ts +7 -8
  123. package/src/ui/render/theme.ts +113 -39
  124. package/src/ui/runtime/screen.ts +74 -10
  125. package/src/ui/runtime/spinner.ts +19 -6
  126. package/src/ui/screens/dialog.ts +19 -1
  127. package/src/ui/screens/form.ts +80 -35
  128. package/src/ui/screens/model-manager.ts +88 -62
  129. package/src/ui/screens/output-window.ts +263 -0
  130. package/src/ui/screens/picker.ts +94 -81
  131. package/src/ui/screens/provider-manager.ts +100 -69
  132. package/src/ui/screens/wizard.ts +117 -28
  133. package/src/ui/tui/app.ts +196 -33
  134. package/src/ui/tui/transcript.ts +154 -25
  135. package/vendor/minicore/src/core/executor.ts +2 -0
  136. package/vendor/minicore/src/core/loop.ts +17 -6
  137. package/vendor/minicore/src/core/session.ts +3 -0
  138. package/vendor/minicore/src/core/tool.ts +1 -0
  139. package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/src/mcp/client.ts CHANGED
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
3
3
  import { dirname, resolve } from "node:path"
4
4
  import type { Tool, ToolContext } from "#minicore"
5
5
  import { LIMITS } from "../constants.ts"
6
- import { scrubSecrets } from "../policy/scrub.ts"
6
+ import { fenceUntrustedToolOutput, isAlreadyFenced, scrubSecrets } from "../policy/scrub.ts"
7
7
  import { McpHttpTransport, type McpTransportLike } from "./http-transport.ts"
8
8
  import { McpTransport } from "./transport.ts"
9
9
 
@@ -67,6 +67,28 @@ function sortObjectKeys(obj: Record<string, unknown>): Record<string, unknown> {
67
67
  return out
68
68
  }
69
69
 
70
+ /**
71
+ * Normalisasi `inputSchema` dari server MCP agar provider LLM yang ketat
72
+ * (OpenAI/Gemini) tidak menolak tool saat server mengirim skema kosong atau
73
+ * tanpa `type: "object"`/`properties`. Tidak menyentuh objek asli agar pin SHA-256 utuh.
74
+ */
75
+ export function normalizeMcpInputSchema(schema: unknown): Tool["parameters"] {
76
+ if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
77
+ return { type: "object", properties: {}, additionalProperties: true }
78
+ }
79
+ const obj = schema as Record<string, unknown>
80
+ const typeVal = typeof obj.type === "string" && obj.type ? obj.type : "object"
81
+ if (typeVal === "object" && (!obj.properties || typeof obj.properties !== "object")) {
82
+ return {
83
+ ...obj,
84
+ type: "object",
85
+ properties: {},
86
+ ...(obj.additionalProperties === undefined ? { additionalProperties: true } : {}),
87
+ } as Tool["parameters"]
88
+ }
89
+ return { ...obj, type: typeVal } as Tool["parameters"]
90
+ }
91
+
70
92
  /** P2.3: sleep yang dapat dibatalkan oleh signal sesi/koneksi. */
71
93
  function abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {
72
94
  return new Promise((resolve, reject) => {
@@ -316,7 +338,9 @@ class McpConnection {
316
338
  this.stdio = null
317
339
  return this.http
318
340
  }
319
- this.stdio = new McpTransport()
341
+ // Beri ruang frame stdio 8 MiB agar screenshot/snapshot browser MCP tidak
342
+ // memicu SIGKILL pada server (uji unit McpTransport() tetap pakai default 1 MiB).
343
+ this.stdio = new McpTransport({ maxFrameBytes: LIMITS.MCP_HTTP_BODY_MAX_BYTES })
320
344
  this.http = null
321
345
  return this.stdio
322
346
  }
@@ -380,27 +404,10 @@ class McpConnection {
380
404
  }
381
405
 
382
406
  let handshakeOk = false
383
- // `server/discover` adalah ekstensi non-standar; hanya masuk akal untuk
384
- // stdio lokal. Server HTTP mengikuti spec → langsung `initialize`.
385
- if (this.kind === "stdio") {
386
- try {
387
- const disc = (await this.transport.request(
388
- "server/discover",
389
- {
390
- _meta: {
391
- "io.modelcontextprotocol/protocolVersion": "2026-07-28",
392
- "io.modelcontextprotocol/clientInfo": { name: "minicode", version: "0.1.0" },
393
- "io.modelcontextprotocol/clientCapabilities": { tools: {} },
394
- },
395
- },
396
- 2_000,
397
- )) as Record<string, unknown>
398
- if (disc?.capabilities) handshakeOk = true
399
- } catch {
400
- // jatuh ke initialize di bawah
401
- }
402
- }
403
- if (!handshakeOk) {
407
+ // Standar MCP mewajibkan `initialize` sebagai pesan pertama; mengirim
408
+ // `server/discover` lebih dulu membuang 2 dtk timeout dan membuat server
409
+ // ketat (Playwright/Puppeteer/SDK resmi) menutup koneksi.
410
+ try {
404
411
  await this.transport.request(
405
412
  "initialize",
406
413
  {
@@ -417,6 +424,32 @@ class McpConnection {
417
424
  // wajib per spec: notification initialized setelah initialize
418
425
  this.transport.notify("notifications/initialized", {})
419
426
  handshakeOk = true
427
+ } catch (initErr) {
428
+ const msg = (initErr as Error)?.message ?? ""
429
+ if (
430
+ this.kind === "stdio" &&
431
+ !this.transport.isClosed &&
432
+ /method not found|-32601/i.test(msg)
433
+ ) {
434
+ try {
435
+ const disc = (await this.transport.request(
436
+ "server/discover",
437
+ {
438
+ _meta: {
439
+ "io.modelcontextprotocol/protocolVersion": "2026-07-28",
440
+ "io.modelcontextprotocol/clientInfo": { name: "minicode", version: "0.1.0" },
441
+ "io.modelcontextprotocol/clientCapabilities": { tools: {} },
442
+ },
443
+ },
444
+ 2_000,
445
+ )) as Record<string, unknown>
446
+ if (disc?.capabilities) handshakeOk = true
447
+ } catch {
448
+ throw initErr
449
+ }
450
+ } else {
451
+ throw initErr
452
+ }
420
453
  }
421
454
  if (!handshakeOk) throw new Error("handshake failed")
422
455
 
@@ -579,11 +612,7 @@ class McpConnection {
579
612
  return {
580
613
  name: `${serverId}.${t.name}`,
581
614
  description: t.description ?? `MCP tool from ${serverId}`,
582
- parameters: (t.inputSchema ?? {
583
- type: "object",
584
- properties: {},
585
- additionalProperties: true,
586
- }) as Tool["parameters"],
615
+ parameters: normalizeMcpInputSchema(t.inputSchema),
587
616
  async execute(input: Record<string, unknown>, _ctx: ToolContext): Promise<string> {
588
617
  // P2.3: pastikan koneksi hidup; reconnect bounded bila transport
589
618
  // mati. Discovery dijalankan ulang, jadi verifikasi memakai definisi
@@ -603,7 +632,10 @@ class McpConnection {
603
632
  _ctx.signal.throwIfAborted()
604
633
  const result = await conn.callTool(t.name, input ?? {}, _ctx.signal)
605
634
  const content = extractMcpText(result)
606
- return capMcpText(content)
635
+ const capped = capMcpText(content)
636
+ return isAlreadyFenced(capped)
637
+ ? capped
638
+ : fenceUntrustedToolOutput(`${serverId}.${t.name}`, capped)
607
639
  },
608
640
  }
609
641
  })
@@ -629,7 +661,7 @@ async function ensureConnection(serverId: string, signal?: AbortSignal): Promise
629
661
  return conn
630
662
  }
631
663
 
632
- /** Normalisasi konten tool MCP (string | blok {text} campuran) → teks. */
664
+ /** Normalisasi konten tool MCP (string | blok {text} | image | resource) → teks. */
633
665
  export function extractMcpText(result: unknown): string {
634
666
  if (result == null) return ""
635
667
  const r = result as { content?: unknown }
@@ -637,8 +669,26 @@ export function extractMcpText(result: unknown): string {
637
669
  return r.content
638
670
  .map((c) => {
639
671
  if (typeof c === "string") return c
640
- if (c && typeof c === "object" && typeof (c as { text?: unknown }).text === "string") {
641
- return (c as { text: string }).text
672
+ if (c && typeof c === "object") {
673
+ const obj = c as {
674
+ type?: unknown
675
+ text?: unknown
676
+ data?: unknown
677
+ mimeType?: unknown
678
+ resource?: { text?: unknown; blob?: unknown; mimeType?: unknown; uri?: unknown }
679
+ }
680
+ if (typeof obj.text === "string") return obj.text
681
+ // Blok image/audio (mis. screenshot Playwright MCP): jangan serialize base64
682
+ // raksasa menjadi JSON teks yang lalu dipotong tengah di 16 KB.
683
+ if ((obj.type === "image" || obj.type === "audio") && typeof obj.data === "string") {
684
+ return `[${obj.type} ${String(obj.mimeType ?? "application/octet-stream")}, ${obj.data.length} base64 chars — binary skipped]`
685
+ }
686
+ if (obj.type === "resource" && obj.resource) {
687
+ if (typeof obj.resource.text === "string") return obj.resource.text
688
+ if (typeof obj.resource.blob === "string") {
689
+ return `[binary ${String(obj.resource.mimeType ?? "application/octet-stream")}, ${obj.resource.blob.length} base64 chars — skipped]`
690
+ }
691
+ }
642
692
  }
643
693
  return JSON.stringify(c)
644
694
  })
@@ -717,8 +767,7 @@ export async function callMcpTool(
717
767
  args: Record<string, unknown>,
718
768
  signal?: AbortSignal,
719
769
  ): Promise<unknown> {
720
- const conn = activeConnections.get(serverId)
721
- if (!conn) throw new Error(`MCP server ${serverId} not connected`)
770
+ const conn = await ensureConnection(serverId, signal)
722
771
  // F8.2: verify skema ulang saat pemanggilan. Tool yang skemanya berubah
723
772
  // tanpa persetujuan ditolak fail-closed sebelum request dikirim ke server.
724
773
  const tool = conn.tools.find((t) => t.name === toolName)
@@ -735,8 +784,7 @@ export async function readMcpResource(
735
784
  uri: string,
736
785
  signal?: AbortSignal,
737
786
  ): Promise<string> {
738
- const conn = activeConnections.get(serverId)
739
- if (!conn) throw new Error(`MCP server ${serverId} not connected`)
787
+ const conn = await ensureConnection(serverId, signal)
740
788
  return conn.readResource(uri, signal)
741
789
  }
742
790
 
@@ -746,8 +794,7 @@ export async function getMcpPrompt(
746
794
  args: Record<string, unknown>,
747
795
  signal?: AbortSignal,
748
796
  ): Promise<string> {
749
- const conn = activeConnections.get(serverId)
750
- if (!conn) throw new Error(`MCP server ${serverId} not connected`)
797
+ const conn = await ensureConnection(serverId, signal)
751
798
  return conn.getPrompt(name, args, signal)
752
799
  }
753
800
 
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { LIMITS } from "../constants.ts"
22
22
  import { isPrivateHostWithDns } from "../lib/net.ts"
23
+ import { publicHttp } from "../lib/public-http.ts"
23
24
 
24
25
  /**
25
26
  * Kemampuan transport yang dipakai `McpConnection` setelah koneksi terbuka.
@@ -160,17 +161,21 @@ export class McpHttpTransport implements McpTransportLike {
160
161
  else signal?.addEventListener("abort", onAbort, { once: true })
161
162
  let res: Response
162
163
  try {
163
- res = await fetch(this.url.toString(), {
164
+ res = await publicHttp.request(this.url, {
164
165
  method: "POST",
165
166
  headers: this.headers("application/json, text/event-stream"),
166
167
  body,
167
168
  signal: controller.signal,
168
- redirect: "manual", // redirect ke host lain = permukaan SSRF
169
+ allowPrivateHost: this.allowPrivate,
169
170
  })
170
171
  } catch (e) {
171
172
  clearTimeout(timer)
172
173
  signal?.removeEventListener("abort", onAbort)
173
174
  const msg = (e as Error).message
175
+ if (msg.startsWith("blocked private host:")) {
176
+ this.blockedPrivate = true
177
+ throw new Error(`MCP http: private host rejected: ${this.url.hostname}`)
178
+ }
174
179
  throw new Error(
175
180
  `MCP http: ${method} failed: ${msg === "timeout" ? `timeout ${timeoutMs}ms` : msg}`,
176
181
  )
@@ -222,13 +227,16 @@ export class McpHttpTransport implements McpTransportLike {
222
227
  // request()/connect()) alih-alih mengirim lalu diam.
223
228
  void (async () => {
224
229
  if (!(await this.checkHost())) return
225
- await fetch(this.url.toString(), {
226
- method: "POST",
227
- headers: this.headers("application/json, text/event-stream"),
228
- body: JSON.stringify({ jsonrpc: "2.0", method, params }),
229
- redirect: "manual",
230
- signal: AbortSignal.timeout(LIMITS.MCP_HANDSHAKE_TIMEOUT_MS),
231
- }).catch(() => {})
230
+ await publicHttp
231
+ .request(this.url, {
232
+ method: "POST",
233
+ headers: this.headers("application/json, text/event-stream"),
234
+ body: JSON.stringify({ jsonrpc: "2.0", method, params }),
235
+ allowPrivateHost: this.allowPrivate,
236
+ signal: AbortSignal.timeout(Math.min(LIMITS.MCP_HANDSHAKE_TIMEOUT_MS, 3_000)),
237
+ })
238
+ .then((r) => r.body?.cancel())
239
+ .catch(() => {})
232
240
  })()
233
241
  }
234
242
 
@@ -239,11 +247,15 @@ export class McpHttpTransport implements McpTransportLike {
239
247
  // itu bukan kegagalan bagi kita. Audit F7: cleanup TIDAK boleh jadi jalur
240
248
  // egress tanpa validasi host (blockedPrivate = host terbukti privat).
241
249
  if (this.sessionId && !this.blockedPrivate && (await this.checkHost())) {
242
- await fetch(this.url.toString(), {
243
- method: "DELETE",
244
- headers: this.headers("application/json"),
245
- signal: AbortSignal.timeout(LIMITS.MCP_HANDSHAKE_TIMEOUT_MS),
246
- }).catch(() => {})
250
+ await publicHttp
251
+ .request(this.url, {
252
+ method: "DELETE",
253
+ headers: this.headers("application/json"),
254
+ allowPrivateHost: this.allowPrivate,
255
+ signal: AbortSignal.timeout(Math.min(LIMITS.MCP_HANDSHAKE_TIMEOUT_MS, 3_000)),
256
+ })
257
+ .then((r) => r.body?.cancel())
258
+ .catch(() => {})
247
259
  }
248
260
  }
249
261
  }
@@ -299,7 +311,7 @@ export async function readSseResponse(
299
311
  const { done, value } = await reader.read()
300
312
  if (done) break
301
313
  total += value.byteLength
302
- if (total > LIMITS.MCP_OUTPUT_MAX_CHARS) {
314
+ if (total > LIMITS.MCP_HTTP_BODY_MAX_BYTES) {
303
315
  throw new Error("MCP http: aliran SSE melewati batas ukuran")
304
316
  }
305
317
  buffer += decoder.decode(value, { stream: true })
@@ -377,7 +389,7 @@ async function readCapped(res: Response): Promise<string> {
377
389
  const { done, value } = await reader.read()
378
390
  if (done) break
379
391
  out += decoder.decode(value, { stream: true })
380
- if (out.length > LIMITS.MCP_OUTPUT_MAX_CHARS) {
392
+ if (out.length > LIMITS.MCP_HTTP_BODY_MAX_BYTES) {
381
393
  throw new Error("MCP http: balasan melewati batas ukuran")
382
394
  }
383
395
  }
@@ -1,9 +1,15 @@
1
- import { type ChildProcess, spawn } from "node:child_process"
1
+ import { type ChildProcess, spawn, spawnSync } from "node:child_process"
2
2
  import { LIMITS } from "../constants.ts"
3
+ import { resolveSpawnTarget, resolveTrustedExecutable } from "../lib/trusted-exec.ts"
3
4
  import { sanitizeSpawnEnv } from "../policy/scrub.ts"
4
5
 
5
6
  export class McpTransport {
7
+ private readonly maxFrameBytes: number
8
+ constructor(opts: { maxFrameBytes?: number } = {}) {
9
+ this.maxFrameBytes = opts.maxFrameBytes ?? LIMITS.MCP_STDIO_FRAME_MAX_BYTES
10
+ }
6
11
  private proc: ChildProcess | null = null
12
+ private winCmdTree = false
7
13
  private stdoutFrame = Buffer.alloc(0)
8
14
  private pending = new Map<
9
15
  string | number,
@@ -28,11 +34,14 @@ export class McpTransport {
28
34
  async connect(command: string, args: string[], env: Record<string, string> = {}): Promise<void> {
29
35
  if (this.proc) throw new Error("transport already connected")
30
36
 
31
- this.proc = spawn(command, args, {
37
+ const target = resolveSpawnTarget(command, args)
38
+ this.winCmdTree = target.windowsVerbatimArguments === true
39
+ this.proc = spawn(target.command, target.args, {
32
40
  stdio: ["pipe", "pipe", "pipe"],
33
41
  // env kredensial di-strip; env eksplisit config server menang setelahnya
34
42
  env: sanitizeSpawnEnv(process.env, env),
35
43
  signal: this.killSignal.signal,
44
+ ...(target.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
36
45
  })
37
46
 
38
47
  this.proc.on("error", (err) => this.failAll(err))
@@ -101,6 +110,22 @@ export class McpTransport {
101
110
  try {
102
111
  this.proc?.stdin?.end()
103
112
  } catch {}
113
+ // Untuk shim .cmd/.bat di Windows, bunuh seluruh subtree SEBELUM killSignal.abort()
114
+ // karena abort() hanya menghentikan wrapper cmd.exe dan meninggalkan anak (node/Chromium).
115
+ if (
116
+ this.winCmdTree &&
117
+ process.platform === "win32" &&
118
+ this.proc?.pid !== undefined &&
119
+ this.proc.exitCode === null
120
+ ) {
121
+ try {
122
+ spawnSync(
123
+ resolveTrustedExecutable("taskkill"),
124
+ ["/pid", String(this.proc.pid), "/T", "/F"],
125
+ { stdio: "ignore", env: sanitizeSpawnEnv(process.env) },
126
+ )
127
+ } catch {}
128
+ }
104
129
  this.killSignal.abort()
105
130
  if (this.proc) {
106
131
  const p = this.proc
@@ -108,7 +133,18 @@ export class McpTransport {
108
133
  await new Promise<void>((r) => {
109
134
  const t = setTimeout(() => {
110
135
  try {
111
- p.kill("SIGKILL")
136
+ if (process.platform === "win32" && p.pid !== undefined) {
137
+ spawnSync(
138
+ resolveTrustedExecutable("taskkill"),
139
+ ["/pid", String(p.pid), "/T", "/F"],
140
+ {
141
+ stdio: "ignore",
142
+ env: sanitizeSpawnEnv(process.env),
143
+ },
144
+ )
145
+ } else {
146
+ p.kill("SIGKILL")
147
+ }
112
148
  } catch {}
113
149
  r()
114
150
  }, 2_000)
@@ -172,7 +208,7 @@ export class McpTransport {
172
208
  for (let i = 0; i < chunk.length; i++) {
173
209
  if (chunk[i] !== 0x0a) continue
174
210
  const part = chunk.subarray(start, i)
175
- if (this.stdoutFrame.length + part.length > LIMITS.MCP_STDIO_FRAME_MAX_BYTES) {
211
+ if (this.stdoutFrame.length + part.length > this.maxFrameBytes) {
176
212
  this.rejectOversizedFrame(this.stdoutFrame.length + part.length)
177
213
  return
178
214
  }
@@ -184,7 +220,7 @@ export class McpTransport {
184
220
  }
185
221
  if (start < chunk.length) {
186
222
  const remainder = chunk.subarray(start)
187
- if (this.stdoutFrame.length + remainder.length > LIMITS.MCP_STDIO_FRAME_MAX_BYTES) {
223
+ if (this.stdoutFrame.length + remainder.length > this.maxFrameBytes) {
188
224
  this.rejectOversizedFrame(this.stdoutFrame.length + remainder.length)
189
225
  return
190
226
  }
@@ -214,7 +250,7 @@ export class McpTransport {
214
250
 
215
251
  private rejectOversizedFrame(size: number): void {
216
252
  const error = new Error(
217
- `MCP stdio frame exceeds ${LIMITS.MCP_STDIO_FRAME_MAX_BYTES} bytes (at least ${size})`,
253
+ `MCP stdio frame exceeds ${this.maxFrameBytes} bytes (at least ${size})`,
218
254
  )
219
255
  this.closed = true
220
256
  this.stdoutFrame = Buffer.alloc(0)