minicode-ai 0.10.0 → 0.11.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/AGENTS.md +45 -0
- package/CHANGELOG.md +59 -4
- package/PLAN.md +491 -0
- package/README.md +2 -2
- package/cli/commands/acp.ts +485 -0
- package/cli/commands/auth.ts +7 -4
- package/cli/commands/config.ts +41 -27
- package/cli/commands/exec.ts +33 -12
- package/cli/commands/mcp.ts +3 -2
- package/cli/commands/memory.ts +1 -1
- package/cli/commands/pricing.ts +6 -4
- package/cli/commands/providers.ts +18 -8
- package/cli/commands/sessions.ts +11 -4
- package/cli/commands/skills.ts +3 -3
- package/cli/commands/stats.ts +3 -1
- package/cli/commands.ts +6 -0
- package/cli/index.ts +82 -57
- package/cli/model-manager.ts +6 -1
- package/cli/router.ts +7 -0
- package/cli/setup.ts +341 -5
- package/cli/tui.ts +54 -18
- package/docs/ARCHITECTURE.html +29 -22
- package/docs/CONTROL-PLANE-MAP.md +139 -0
- package/docs/HARNESS.md +150 -0
- package/docs/PLAN_UIUX_V6.md +209 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +52 -0
- package/docs/TERMINAL_CONTRACT.md +367 -0
- package/docs/UI_RENDER_PIPELINE.md +165 -0
- package/docs/USAGE.md +11 -0
- package/docs/agents.md +31 -0
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +34 -0
- package/docs/cli.md +130 -0
- package/docs/concepts.md +53 -0
- package/docs/config-providers.md +87 -0
- package/docs/config.md +63 -0
- package/docs/contributing.md +79 -0
- package/docs/environment.md +95 -0
- package/docs/exec.md +73 -0
- package/docs/getting-started.md +102 -0
- package/docs/glossary.md +37 -0
- package/docs/mcp-lsp.md +54 -0
- package/docs/memory-sessions.md +63 -0
- package/docs/policy-sandbox.md +72 -0
- package/docs/pricing-budget.md +49 -0
- package/docs/quickstart.md +60 -0
- package/docs/repl.md +67 -0
- package/docs/security-model.md +95 -0
- package/docs/security.md +91 -0
- package/docs/skills.md +48 -0
- package/docs/terminal.md +79 -0
- package/docs/tools.md +123 -0
- package/docs/troubleshooting.md +40 -0
- package/docs/verify-benchmark.md +58 -0
- package/package.json +8 -5
- package/src/app/provider-layer.ts +12 -4
- package/src/app/session.ts +6 -0
- package/src/app/tool-layer.ts +2 -1
- package/src/constants.ts +35 -0
- package/src/lib/net.ts +6 -1
- package/src/lsp/client.ts +41 -8
- package/src/mcp/http-transport.ts +52 -15
- package/src/mcp/transport.ts +32 -1
- package/src/memory/files.ts +6 -5
- package/src/policy/allowlist.ts +1 -1
- package/src/policy/bash-guard.ts +154 -14
- package/src/policy/compaction.ts +57 -3
- package/src/policy/context.ts +4 -0
- package/src/policy/jail.ts +49 -4
- package/src/policy/permission.ts +152 -12
- package/src/policy/pricing.ts +12 -9
- package/src/presentation/adapter.ts +721 -0
- package/src/presentation/events.ts +324 -0
- package/src/presentation/label.ts +140 -0
- package/src/presentation/model.ts +172 -0
- package/src/presentation/reducer.ts +486 -0
- package/src/presentation/store.ts +256 -0
- package/src/providers/anthropic.ts +22 -4
- package/src/providers/detect.ts +2 -1
- package/src/providers/router.ts +13 -0
- package/src/repo/repomap.ts +2 -29
- package/src/session/checkpoint.ts +27 -9
- package/src/session/journal.ts +27 -5
- package/src/skills/loader.ts +88 -5
- package/src/telemetry/trace.ts +36 -15
- package/src/tools/ask_user.ts +73 -4
- package/src/tools/bash.ts +15 -17
- package/src/tools/glob.ts +10 -11
- package/src/tools/lsp.ts +3 -56
- package/src/tools/memory.ts +13 -12
- package/src/tools/task.ts +1 -0
- package/src/ui/approval/prompt.ts +14 -6
- package/src/ui/assistant/simple.ts +137 -26
- package/src/ui/assistant/turn-status.ts +16 -3
- package/src/ui/contract.ts +119 -0
- package/src/ui/footer.ts +21 -2
- package/src/ui/i18n/en.ts +34 -6
- package/src/ui/i18n/id.ts +34 -6
- package/src/ui/i18n/locale.ts +3 -1
- package/src/ui/input/input.ts +51 -4
- package/src/ui/input/prompt-engine.ts +46 -4
- package/src/ui/render/collapse.ts +13 -13
- package/src/ui/render/diff.ts +7 -2
- package/src/ui/render/format.ts +16 -8
- package/src/ui/render/highlight.ts +7 -3
- package/src/ui/render/markdown.ts +5 -1
- package/src/ui/render/sanitize.ts +29 -2
- package/src/ui/render/table.ts +8 -5
- package/src/ui/render/theme.ts +18 -4
- package/src/ui/render/width.ts +89 -10
- package/src/ui/runtime/motion.ts +16 -0
- package/src/ui/runtime/screen.ts +45 -0
- package/src/ui/runtime/spinner.ts +50 -4
- package/src/ui/runtime/statusline.ts +50 -1
- package/src/ui/screens/form.ts +42 -15
- package/src/ui/screens/model-manager.ts +26 -18
- package/src/ui/screens/picker.ts +47 -23
- package/src/ui/screens/provider-manager.ts +18 -12
- package/src/ui/screens/wizard.ts +24 -8
- package/src/ui/tui/app.ts +233 -27
- package/src/ui/tui/transcript.ts +269 -65
- package/vendor/minicore/LICENSE +21 -0
- package/vendor/minicore/VENDOR.md +6 -3
- package/vendor/minicore/package.json +6 -3
- package/vendor/minicore/src/core/loop.ts +12 -2
- package/vendor/minicore/src/core/snapshot.ts +4 -0
- package/vendor/minicore/src/providers/openai-compat.ts +76 -25
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Verify & Benchmark
|
|
2
|
+
|
|
3
|
+
## Auto-verify & self-heal
|
|
4
|
+
|
|
5
|
+
`--verify` auto-detect perintah (`typecheck` → `test` → `tsconfig`) atau `MINICODE_VERIFY_CMD` / `verifyCommand` di config.
|
|
6
|
+
|
|
7
|
+
Alur: baseline diuji dulu (bila merah, Health-Check ditempel ke prompt awal) → run utama → verify → bila gagal, agen perbaiki (maks 3 siklus). Output error dibungkus fence agar tidak jadi prompt injection.
|
|
8
|
+
|
|
9
|
+
Checkpoint shadow-git: snapshot per turn sebagai SHA tree (O(delta), tanpa cap file, `HEAD`/index tak tersentuh, ref menunjuk *tree* sehingga tak muncul di `git log`). `.gitignore` dihormati. Non-repo fallback snapshot file.
|
|
10
|
+
|
|
11
|
+
Repo-map: simbol per file (regex, 9 bahasa) di-cache `.minicode/repomap.json`, disuntik ke system prompt. Tree-sitter tidak dipakai — alasan terukur di `extractSymbolsAsync` (`src/repo/repomap.ts`).
|
|
12
|
+
|
|
13
|
+
Secret scrubber meredaksi `sk-`, `ghp_`, `AKIA`, PEM, JWT, Bearer, `api_key=...` sebelum ke LLM.
|
|
14
|
+
|
|
15
|
+
## Benchmark
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun run bench # butuh provider (resolve rate nyata)
|
|
19
|
+
bun run bench:smoke # --fake, untuk CI
|
|
20
|
+
bun run bench --tasks path/to/tasks.json # external tasks (SWE-bench-format)
|
|
21
|
+
bun run audit:harness # 60 cek deterministik, tanpa API key
|
|
22
|
+
bun run bench --runs 2 # median 2 runs
|
|
23
|
+
bun bench/runner.ts --fake --memory off # tanpa RAG/auto-memory
|
|
24
|
+
bun bench/runner.ts --fake --memory on # dengan RAG + seed memory
|
|
25
|
+
bun bench/runner.ts --provider vyceai-com --model 'vyceai-com::deepseek-v4-flash' --max-steps 6 --timeout 90000 # live berbiaya: pin provider+model+rem
|
|
26
|
+
bun bench/runner.ts --judge-model 'vyceai-com::deepseek-v4-flash-lr' # nilai penjelasan (model HARUS beda dari aktor)
|
|
27
|
+
bun run gate:eval # kunci ambang baterai (min resolve-rate, max median token)
|
|
28
|
+
bun run gate:eval --results bench/live.json --min-rate 0.8 --max-median-tokens 8000 --allow-partial
|
|
29
|
+
bun bench/eval-gate.ts --results bench/results.json --min-rate 1 --max-median-tokens 5000 --observe-tokens # observasi: token tak menggagalkan (2–3 run pertama sebelum ambang dikunci)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Metrik: resolve rate, steps, token, cost, durasi, memoryHits + delta vs run sebelumnya. Hasil `bench/results.json` (`--out` untuk path lain). Tiap run gagal membawa kelas (`VERIFY_FAIL`/`MAX_STEPS`/`NO_PROGRESS`/`ABORT`) + distribusi global di akhir run; kartu metodologi + log observasi di `bench/HARNESS-CARD.md`.
|
|
33
|
+
|
|
34
|
+
Setiap run memakai `MINICODE_HOME` hermetic sendiri (DB/memory/sesi global tak bocor antar run dan tak menyentuh `~/.minicode` operator). Task boleh membawa `seedMemory`: fakta yang di-seed ke memory run itu — task `follow-convention` hanya lolos bila agen membaca fakta tersebut, sehingga `bun bench/runner.ts --memory on` vs `--memory off` mengukur nilai memory secara diferensial (bukan klaim).
|
|
35
|
+
|
|
36
|
+
Format `tasks.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
[
|
|
40
|
+
{
|
|
41
|
+
"id": "fix-issue-1",
|
|
42
|
+
"prompt": "Fix the bug in buggy.ts",
|
|
43
|
+
"files": [{ "path": "buggy.ts", "content": "export function f(){ return 1 }" }],
|
|
44
|
+
"verify": ["export function f()", "!return 1"]
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
SWE-bench Lite: `bench/swebench.ts` + `bench/swebench_lite_20.jsonl` (20 instance nyata, 12 repo, base_commit spot-check) + `bench/docker/` (5 image Python 3.6–3.10 + `manifest.json` + `--docker`). Harness apply `test_patch` dulu (tanpanya skor fiksi). Run nyata tercatat 0/20 (`nemotron-3.5-lightning-free`, 25 steps) dengan catatan validitas lingkungan (Python 3.14 vs era 2022) — skor comparable butuh Docker per-instance.
|
|
50
|
+
|
|
51
|
+
Eksperimen adversarial (terpisah dari gate default):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
bun run extreme:fuzz # fuzz bash-guard (--seed N reproduksi)
|
|
55
|
+
bun run extreme:git # stress shadow-git (--files N --sessions N)
|
|
56
|
+
bun run extreme:mcp # server MCP jahat (hang, flood, redirect, SSRF)
|
|
57
|
+
bun experiments/bash-bypass-probe.ts # postur denylist (0 bypass = lulus)
|
|
58
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minicode-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Coding agent CLI built on the frozen MiniCore runtime — tools, MCP, LSP, sandbox, shadow-git checkpoints",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"#minicore/*": "./vendor/minicore/src/*"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
|
-
"bun": ">=1.
|
|
43
|
+
"bun": ">=1.1.13"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"cli",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"vendor/minicore/src",
|
|
49
49
|
"vendor/minicore/package.json",
|
|
50
50
|
"vendor/minicore/VENDOR.md",
|
|
51
|
-
"docs
|
|
52
|
-
"
|
|
53
|
-
"
|
|
51
|
+
"docs",
|
|
52
|
+
"PLAN.md",
|
|
53
|
+
"AGENTS.md",
|
|
54
54
|
"README.md",
|
|
55
55
|
"CHANGELOG.md",
|
|
56
56
|
"LICENSE"
|
|
@@ -60,6 +60,8 @@
|
|
|
60
60
|
"test:live": "bun scripts/test-live.ts",
|
|
61
61
|
"test:qa": "bun scripts/live-qa.ts",
|
|
62
62
|
"test:coverage": "bun test --coverage",
|
|
63
|
+
"gate:fast": "bun x tsc --noEmit && bun run lint && bun test && bun run gate:coverage && bun run gate:pack && bun run gate:bash && bun run bench:smoke && bun run audit:harness",
|
|
64
|
+
"gate:slow": "bun experiments/extreme-bash-fuzz.ts --rounds 12 && bun experiments/extreme-shadow-git.ts && bun experiments/extreme-mcp-adversarial.ts",
|
|
63
65
|
"gate:coverage": "bun scripts/coverage-gate.ts",
|
|
64
66
|
"gate:bash": "bun experiments/bash-bypass-probe.ts && bun experiments/bash-bypass-probe.ts --mode allowlist",
|
|
65
67
|
"gate:pack": "bun scripts/pack-check.ts",
|
|
@@ -90,6 +92,7 @@
|
|
|
90
92
|
"dependencies": {},
|
|
91
93
|
"devDependencies": {
|
|
92
94
|
"@biomejs/biome": "2.5.10",
|
|
95
|
+
"@lydell/node-pty": "1.2.0-beta.15",
|
|
93
96
|
"@resvg/resvg-js": "^2.6.2",
|
|
94
97
|
"@types/bun": "^1.3.14",
|
|
95
98
|
"@types/node": "^26.2.0",
|
|
@@ -7,6 +7,17 @@ import { withStreamGuards } from "../providers/guards.ts"
|
|
|
7
7
|
import { createRouterProvider } from "../providers/router.ts"
|
|
8
8
|
|
|
9
9
|
let currentRouter: ReturnType<typeof createRouterProvider> | null = null
|
|
10
|
+
|
|
11
|
+
/** Setup tanpa provider apa pun. Dilempar (bukan exit di sini) agar
|
|
12
|
+
* composition root bisa memilih presentasi: REPL/one-shot mencetak pesan
|
|
13
|
+
* manusia ke stderr, `exec --json` menambah envelope mesin ke stdout.
|
|
14
|
+
* Pesan = teks yang dulu dicetak langsung sebelum exit(1) — byte-identik. */
|
|
15
|
+
export class NoProviderError extends Error {
|
|
16
|
+
readonly name = "NoProviderError"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const NO_PROVIDER_MESSAGE =
|
|
20
|
+
"no provider configured — run `minicode` for setup wizard,\nor: minicode auth login (free, no API key), minicode config add --baseUrl <url> --apiKey <key>, or set OPENAI_API_KEY"
|
|
10
21
|
export async function reloadProviders(
|
|
11
22
|
cwd?: string,
|
|
12
23
|
opts: { allowLocal?: boolean } = {},
|
|
@@ -104,10 +115,7 @@ export async function createProviderLayer(opts: {
|
|
|
104
115
|
}
|
|
105
116
|
}
|
|
106
117
|
if (providers.length === 0) {
|
|
107
|
-
|
|
108
|
-
"no provider configured — run `minicode` for setup wizard,\nor: minicode auth login (free, no API key), minicode config add --baseUrl <url> --apiKey <key>, or set OPENAI_API_KEY",
|
|
109
|
-
)
|
|
110
|
-
process.exit(1)
|
|
118
|
+
throw new NoProviderError(NO_PROVIDER_MESSAGE)
|
|
111
119
|
}
|
|
112
120
|
const router = createRouterProvider({
|
|
113
121
|
providers,
|
package/src/app/session.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type PermissionAsk,
|
|
12
12
|
type PermissionMode,
|
|
13
13
|
} from "../policy/permission.ts"
|
|
14
|
+
import type { ApprovalEventHook } from "../presentation/events.ts"
|
|
14
15
|
|
|
15
16
|
// P2 cap wrapper: limit retryAfter to 30s without mutating original error.
|
|
16
17
|
// F-12: sanitasi PENUH di satu titik sentral (mencakup adapter vendor yang
|
|
@@ -65,6 +66,9 @@ export async function createMinicodeSession(
|
|
|
65
66
|
/** View persetujuan tool (di-inject dari cli/; tanpa ini mode interaktif
|
|
66
67
|
* menolak semua prompt — aman untuk headless/library). */
|
|
67
68
|
ask?: PermissionAsk
|
|
69
|
+
/** Hook observability persetujuan Fase 1 (diteruskan ke permission
|
|
70
|
+
* handler; tanpa ini gate identik seperti dulu). */
|
|
71
|
+
onApprovalEvent?: ApprovalEventHook
|
|
68
72
|
},
|
|
69
73
|
): Promise<Session> {
|
|
70
74
|
const planHint =
|
|
@@ -86,6 +90,7 @@ export async function createMinicodeSession(
|
|
|
86
90
|
provider,
|
|
87
91
|
onPermissions,
|
|
88
92
|
ask,
|
|
93
|
+
onApprovalEvent,
|
|
89
94
|
turnCount,
|
|
90
95
|
stepCount,
|
|
91
96
|
...rest
|
|
@@ -121,6 +126,7 @@ export async function createMinicodeSession(
|
|
|
121
126
|
root: cwd,
|
|
122
127
|
ask,
|
|
123
128
|
allowLocalConfig,
|
|
129
|
+
onApprovalEvent,
|
|
124
130
|
})
|
|
125
131
|
const withMode = permissions as typeof permissions & {
|
|
126
132
|
__setMode(m: PermissionMode): void
|
package/src/app/tool-layer.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Tool } from "#minicore"
|
|
|
2
2
|
import type { MinicodeConfig } from "../config.ts"
|
|
3
3
|
import { configureServers as lspConfigure } from "../lsp/client.ts"
|
|
4
4
|
import { connectAll as mcpConnectAll } from "../mcp/client.ts"
|
|
5
|
+
import { isMcpToolName } from "../presentation/label.ts"
|
|
5
6
|
import { allTools, withMcpTools } from "../tools/index.ts"
|
|
6
7
|
import { EXPLORE_TOOL_NAMES } from "../tools/task.ts"
|
|
7
8
|
|
|
@@ -39,7 +40,7 @@ export async function setupToolLayer(
|
|
|
39
40
|
sessionTools = withMcpTools(sessionTools, mcpTools)
|
|
40
41
|
if (permissionMode === "plan" || permissionMode === "readonly") {
|
|
41
42
|
sessionTools = sessionTools.filter(
|
|
42
|
-
(t) => !t.name
|
|
43
|
+
(t) => !isMcpToolName(t.name) || EXPLORE_TOOL_NAMES.includes(t.name),
|
|
43
44
|
)
|
|
44
45
|
}
|
|
45
46
|
}
|
package/src/constants.ts
CHANGED
|
@@ -25,6 +25,11 @@ export const LIMITS = {
|
|
|
25
25
|
AGENTS_MD_MAX_CHARS: 3_000,
|
|
26
26
|
COMPACTION_SUMMARY_MAX_CHARS: 1_500,
|
|
27
27
|
COMPACTION_LLM_TIMEOUT_MS: 10_000,
|
|
28
|
+
/** F3.1 anti-thrash: kompaksi LLM yang mengurangi <10% dihitung tak
|
|
29
|
+
* berprogres (satu output tool raksasa mendominasi jendela); 2× beruntun
|
|
30
|
+
* = thrash → jalur LLM dimatikan sesi-ini (mekanikal saja). */
|
|
31
|
+
COMPACTION_THRASH_MIN_PROGRESS: 0.1,
|
|
32
|
+
COMPACTION_THRASH_MAX_STREAK: 2,
|
|
28
33
|
EMBEDDING_TIMEOUT_MS: 3_500,
|
|
29
34
|
/** Budget TOTAL semua attempt embedding (3 header × 2 URL sekuensial):
|
|
30
35
|
* tanpa ini endpoint lambat-menjawab menahan RAG setup ~21 dtk (6×3,5 dtk
|
|
@@ -117,3 +122,33 @@ export const LIMITS = {
|
|
|
117
122
|
REPOMAP_MAX_CHARS: 2_500,
|
|
118
123
|
REPOMAP_MAX_SYMBOLS_PER_FILE: 40,
|
|
119
124
|
} as const
|
|
125
|
+
|
|
126
|
+
/** LSP SymbolKind string mapping (1-indexed, LSP specification) */
|
|
127
|
+
export const LSP_SYMBOL_KINDS = [
|
|
128
|
+
"File",
|
|
129
|
+
"Module",
|
|
130
|
+
"Namespace",
|
|
131
|
+
"Package",
|
|
132
|
+
"Class",
|
|
133
|
+
"Method",
|
|
134
|
+
"Property",
|
|
135
|
+
"Field",
|
|
136
|
+
"Constructor",
|
|
137
|
+
"Enum",
|
|
138
|
+
"Interface",
|
|
139
|
+
"Function",
|
|
140
|
+
"Variable",
|
|
141
|
+
"Constant",
|
|
142
|
+
"String",
|
|
143
|
+
"Number",
|
|
144
|
+
"Boolean",
|
|
145
|
+
"Array",
|
|
146
|
+
"Object",
|
|
147
|
+
"Key",
|
|
148
|
+
"Null",
|
|
149
|
+
"EnumMember",
|
|
150
|
+
"Struct",
|
|
151
|
+
"Event",
|
|
152
|
+
"Operator",
|
|
153
|
+
"TypeParameter",
|
|
154
|
+
] as const
|
package/src/lib/net.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
// Penjaga jaringan bersama: validasi host anti-SSRF + DNS
|
|
1
|
+
// Penjaga jaringan bersama: validasi host anti-SSRF + re-resolve DNS per cek.
|
|
2
2
|
// Dipakai web_fetch (tool), web_search, dan transport HTTP MCP — server MCP
|
|
3
3
|
// remote yang menunjuk ke metadata endpoint adalah jalur SSRF yang identik,
|
|
4
4
|
// jadi semuanya memakai satu penjaga yang sama.
|
|
5
|
+
// CATATAN audit F7: istilah "DNS pinning" DILARANG di sini — yang dilakukan
|
|
6
|
+
// fungsi ini adalah resolve-lalu-cek (check-then-connect), BUKAN menanam IP ke
|
|
7
|
+
// socket. Residualnya jujur didokumentasikan di web_fetch (cek dan connect
|
|
8
|
+
// bisa melihat IP berbeda); yang ditutup di sini adalah cache basi (noCache)
|
|
9
|
+
// dan kegagalan DNS (strict) — pilih per jalur sesuai risikonya.
|
|
5
10
|
import { lookup } from "node:dns/promises"
|
|
6
11
|
|
|
7
12
|
// Host validasi untuk anti-SSRF. Catatan: WHATWG URL sudah menormalisasi host
|
package/src/lsp/client.ts
CHANGED
|
@@ -63,6 +63,7 @@ class LspConnection {
|
|
|
63
63
|
private killSignal = new AbortController()
|
|
64
64
|
private opened = new Map<string, number>()
|
|
65
65
|
readonly diagnostics = new Map<string, Record<string, unknown>[]>()
|
|
66
|
+
private diagnosticWaiters = new Map<string, Set<() => void>>()
|
|
66
67
|
|
|
67
68
|
constructor(public entry: LspServerEntry) {}
|
|
68
69
|
|
|
@@ -161,14 +162,36 @@ class LspConnection {
|
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
async waitForDiagnostics(uri: string, timeoutMs = 5_000): Promise<Record<string, unknown>[]> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
await sleep(400) // settle window for follow-up pushes
|
|
168
|
-
return this.diagnostics.get(uri) ?? []
|
|
169
|
-
}
|
|
170
|
-
await sleep(100)
|
|
165
|
+
if (this.diagnostics.has(uri)) {
|
|
166
|
+
await sleep(100) // settle window for follow-up pushes
|
|
167
|
+
return this.diagnostics.get(uri) ?? []
|
|
171
168
|
}
|
|
169
|
+
await new Promise<void>((resolve) => {
|
|
170
|
+
let timer: ReturnType<typeof setTimeout>
|
|
171
|
+
const onDiag = () => {
|
|
172
|
+
clearTimeout(timer)
|
|
173
|
+
cleanup()
|
|
174
|
+
setTimeout(resolve, 50)
|
|
175
|
+
}
|
|
176
|
+
const cleanup = () => {
|
|
177
|
+
const s = this.diagnosticWaiters.get(uri)
|
|
178
|
+
if (s) {
|
|
179
|
+
s.delete(onDiag)
|
|
180
|
+
if (s.size === 0) this.diagnosticWaiters.delete(uri)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
timer = setTimeout(() => {
|
|
184
|
+
cleanup()
|
|
185
|
+
resolve()
|
|
186
|
+
}, timeoutMs)
|
|
187
|
+
|
|
188
|
+
let s = this.diagnosticWaiters.get(uri)
|
|
189
|
+
if (!s) {
|
|
190
|
+
s = new Set()
|
|
191
|
+
this.diagnosticWaiters.set(uri, s)
|
|
192
|
+
}
|
|
193
|
+
s.add(onDiag)
|
|
194
|
+
})
|
|
172
195
|
return this.diagnostics.get(uri) ?? []
|
|
173
196
|
}
|
|
174
197
|
|
|
@@ -252,11 +275,21 @@ class LspConnection {
|
|
|
252
275
|
const params = msg.params as
|
|
253
276
|
| { uri?: string; diagnostics?: Record<string, unknown>[] }
|
|
254
277
|
| undefined
|
|
255
|
-
if (params?.uri)
|
|
278
|
+
if (params?.uri) {
|
|
279
|
+
this.diagnostics.set(params.uri, params.diagnostics ?? [])
|
|
280
|
+
const waiters = this.diagnosticWaiters.get(params.uri)
|
|
281
|
+
if (waiters) {
|
|
282
|
+
for (const cb of waiters) cb()
|
|
283
|
+
}
|
|
284
|
+
}
|
|
256
285
|
}
|
|
257
286
|
}
|
|
258
287
|
|
|
259
288
|
private failAll(err: Error) {
|
|
289
|
+
for (const s of this.diagnosticWaiters.values()) {
|
|
290
|
+
for (const cb of s) cb()
|
|
291
|
+
}
|
|
292
|
+
this.diagnosticWaiters.clear()
|
|
260
293
|
for (const p of this.pending.values()) {
|
|
261
294
|
clearTimeout(p.timer)
|
|
262
295
|
p.reject(err)
|
|
@@ -55,6 +55,13 @@ export class McpHttpTransport implements McpTransportLike {
|
|
|
55
55
|
private seq = 0
|
|
56
56
|
private sessionId: string | null = null
|
|
57
57
|
private closed = false
|
|
58
|
+
/**
|
|
59
|
+
* Set bila host TERBUKTI privat (audit F7): egress fire-and-forget
|
|
60
|
+
* (notify/close) mengikuti keputusan ini supaya tak ada jalur yang
|
|
61
|
+
* melewati validasi host. request()/connect() tetap THROW eksplisit agar
|
|
62
|
+
* pemanggil melihat penolakannya.
|
|
63
|
+
*/
|
|
64
|
+
private blockedPrivate = false
|
|
58
65
|
private readonly url: URL
|
|
59
66
|
private readonly extraHeaders: Record<string, string>
|
|
60
67
|
private readonly allowPrivate: boolean
|
|
@@ -76,9 +83,29 @@ export class McpHttpTransport implements McpTransportLike {
|
|
|
76
83
|
this.allowPrivate = opts.allowPrivateHost === true
|
|
77
84
|
}
|
|
78
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Validasi host satu tempat (audit F7): strict + noCache seperti jalur
|
|
88
|
+
* embedding (`vector.ts`) — MCP HTTP adalah URL konfigurasi pihak ketiga
|
|
89
|
+
* seumur panjang, jadi fail-open 400 ms + cache 30 dtk (default
|
|
90
|
+
* `isPrivateHostWithDns`) adalah postur yang salah untuknya. Mengembalikan
|
|
91
|
+
* true bila egress BOLEH jalan; false + tandai `blockedPrivate` bila host
|
|
92
|
+
* terbukti privat.
|
|
93
|
+
*/
|
|
94
|
+
private async checkHost(): Promise<boolean> {
|
|
95
|
+
if (this.allowPrivate) return true
|
|
96
|
+
// noCache: tiap pengecekan resolve ulang (DNS bisa berubah setelah
|
|
97
|
+
// connect — klaim F-21). strict: kegagalan/timeout DNS = BLOKIR
|
|
98
|
+
// (fail-closed), karena config server MCP bebas menunjuk ke mana pun.
|
|
99
|
+
if (await isPrivateHostWithDns(this.url.hostname, { strict: true, noCache: true })) {
|
|
100
|
+
this.blockedPrivate = true
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
|
|
79
106
|
async connect(): Promise<void> {
|
|
80
107
|
// Validasi host sebelum request PERTAMA, bukan setelahnya.
|
|
81
|
-
if (!
|
|
108
|
+
if (!(await this.checkHost())) {
|
|
82
109
|
throw new Error(
|
|
83
110
|
`MCP http: private host rejected: ${this.url.hostname} (set allowPrivateHost for local servers)`,
|
|
84
111
|
)
|
|
@@ -104,12 +131,15 @@ export class McpHttpTransport implements McpTransportLike {
|
|
|
104
131
|
signal?: AbortSignal,
|
|
105
132
|
): Promise<unknown> {
|
|
106
133
|
if (this.closed) throw new Error("MCP http: transport already closed")
|
|
134
|
+
if (this.blockedPrivate)
|
|
135
|
+
throw new Error(`MCP http: private host rejected: ${this.url.hostname}`)
|
|
107
136
|
signal?.throwIfAborted()
|
|
108
137
|
// F-21: validasi ulang tiap request (bukan hanya saat connect): sesi MCP
|
|
109
|
-
// berumur panjang dan DNS bisa berubah setelah connect.
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
138
|
+
// berumur panjang dan DNS bisa berubah setelah connect. noCache membuat
|
|
139
|
+
// cek ini resolve ulang (bukan penutup TOCTOU check-then-connect yang
|
|
140
|
+
// fundamental — lihat web_fetch — melainkan penutup drift sesi); strict
|
|
141
|
+
// = kegagalan DNS memblokir, bukan mengizinkan.
|
|
142
|
+
if (!(await this.checkHost())) {
|
|
113
143
|
throw new Error(`MCP http: private host rejected: ${this.url.hostname}`)
|
|
114
144
|
}
|
|
115
145
|
const id = ++this.seq
|
|
@@ -178,23 +208,30 @@ export class McpHttpTransport implements McpTransportLike {
|
|
|
178
208
|
}
|
|
179
209
|
|
|
180
210
|
notify(method: string, params: Record<string, unknown> = {}): void {
|
|
181
|
-
if (this.closed) return
|
|
211
|
+
if (this.closed || this.blockedPrivate) return
|
|
182
212
|
// Notifikasi tak punya id dan tak menunggu balasan; kegagalan tidak fatal.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
213
|
+
// Audit F7: fire-and-forget BUKAN berarti tanpa validasi — host dicek
|
|
214
|
+
// sebelum mengirim; bila privat, blokir transport ini selamanya (sesuai
|
|
215
|
+
// request()/connect()) alih-alih mengirim lalu diam.
|
|
216
|
+
void (async () => {
|
|
217
|
+
if (!(await this.checkHost())) return
|
|
218
|
+
await fetch(this.url.toString(), {
|
|
219
|
+
method: "POST",
|
|
220
|
+
headers: this.headers("application/json, text/event-stream"),
|
|
221
|
+
body: JSON.stringify({ jsonrpc: "2.0", method, params }),
|
|
222
|
+
redirect: "manual",
|
|
223
|
+
signal: AbortSignal.timeout(LIMITS.MCP_HANDSHAKE_TIMEOUT_MS),
|
|
224
|
+
}).catch(() => {})
|
|
225
|
+
})()
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
async close(): Promise<void> {
|
|
193
229
|
if (this.closed) return
|
|
194
230
|
this.closed = true
|
|
195
231
|
// Spec: DELETE mengakhiri sesi. Server yang tak mendukung akan menolak —
|
|
196
|
-
// itu bukan kegagalan bagi kita.
|
|
197
|
-
|
|
232
|
+
// itu bukan kegagalan bagi kita. Audit F7: cleanup TIDAK boleh jadi jalur
|
|
233
|
+
// egress tanpa validasi host (blockedPrivate = host terbukti privat).
|
|
234
|
+
if (this.sessionId && !this.blockedPrivate && (await this.checkHost())) {
|
|
198
235
|
await fetch(this.url.toString(), {
|
|
199
236
|
method: "DELETE",
|
|
200
237
|
headers: this.headers("application/json"),
|
package/src/mcp/transport.ts
CHANGED
|
@@ -97,6 +97,9 @@ export class McpTransport {
|
|
|
97
97
|
})
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
private writeQueue: string[] = []
|
|
101
|
+
private draining = false
|
|
102
|
+
|
|
100
103
|
notify(method: string, params: Record<string, unknown> = {}) {
|
|
101
104
|
this.write({ jsonrpc: "2.0", method, params })
|
|
102
105
|
}
|
|
@@ -104,6 +107,8 @@ export class McpTransport {
|
|
|
104
107
|
async close(): Promise<void> {
|
|
105
108
|
if (this.closed) return
|
|
106
109
|
this.closed = true
|
|
110
|
+
this.writeQueue = []
|
|
111
|
+
this.draining = false
|
|
107
112
|
this.failAll(new Error("transport closed"))
|
|
108
113
|
if (this.rl) this.rl.close()
|
|
109
114
|
try {
|
|
@@ -136,8 +141,34 @@ export class McpTransport {
|
|
|
136
141
|
} catch {
|
|
137
142
|
throw new Error("circular JSON in MCP message")
|
|
138
143
|
}
|
|
144
|
+
if (this.draining) {
|
|
145
|
+
this.writeQueue.push(line)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
139
148
|
const ok = this.proc.stdin.write(line)
|
|
140
|
-
if (!ok)
|
|
149
|
+
if (!ok) {
|
|
150
|
+
this.draining = true
|
|
151
|
+
this.proc.stdin.once("drain", () => {
|
|
152
|
+
this.draining = false
|
|
153
|
+
this.flushQueue()
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private flushQueue() {
|
|
159
|
+
if (!this.proc?.stdin || this.draining) return
|
|
160
|
+
while (this.writeQueue.length > 0) {
|
|
161
|
+
const next = this.writeQueue.shift()!
|
|
162
|
+
const ok = this.proc.stdin.write(next)
|
|
163
|
+
if (!ok) {
|
|
164
|
+
this.draining = true
|
|
165
|
+
this.proc.stdin.once("drain", () => {
|
|
166
|
+
this.draining = false
|
|
167
|
+
this.flushQueue()
|
|
168
|
+
})
|
|
169
|
+
break
|
|
170
|
+
}
|
|
171
|
+
}
|
|
141
172
|
}
|
|
142
173
|
|
|
143
174
|
private failAll(err: Error) {
|
package/src/memory/files.ts
CHANGED
|
@@ -108,11 +108,12 @@ export async function appendMemory(text: string, cwd = process.cwd()): Promise<s
|
|
|
108
108
|
const st = await stat(path)
|
|
109
109
|
if (st.size > MAX_MEMORY_FILE_BYTES) {
|
|
110
110
|
const txt = await readFile(path, "utf8")
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
111
|
+
const rawKeep = txt.slice(-LIMITS.MEMORY_TRUNCATE_KEEP_BYTES)
|
|
112
|
+
// Cari batas entri utuh berikutnya (diawali \n- ) agar entri pertama tak terpotong buntung
|
|
113
|
+
const entryBoundary = rawKeep.indexOf("\n- ")
|
|
114
|
+
const cut = entryBoundary >= 0 ? entryBoundary + 1 : rawKeep.indexOf("\n")
|
|
115
|
+
const trimmed = cut >= 0 ? rawKeep.slice(cut + (entryBoundary >= 0 ? 0 : 1)) : rawKeep
|
|
116
|
+
await import("node:fs/promises").then((m) => m.writeFile(path, trimmed, "utf8"))
|
|
116
117
|
}
|
|
117
118
|
} catch {}
|
|
118
119
|
return path
|
package/src/policy/allowlist.ts
CHANGED
|
@@ -59,7 +59,7 @@ export function matchAllowlist(call: ToolCall, allowlist: string[]): boolean {
|
|
|
59
59
|
// prefix 'A'x195 + tail jinak vs tail jahat → kunci terpotong identik).
|
|
60
60
|
const key = `${call.name}:${JSON.stringify(call.args)}`
|
|
61
61
|
return allowlist.some((pat) => {
|
|
62
|
-
const safe = pat.replace(/[.+^${}()|[\]
|
|
62
|
+
const safe = pat.replace(/[.+^${}()|[\]\\?]/g, "\\$&").replace(/\*/g, ".*")
|
|
63
63
|
const re = new RegExp(`^${safe}$`)
|
|
64
64
|
if (pat.includes(":")) return re.test(key)
|
|
65
65
|
return re.test(call.name) || re.test(key)
|