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.
- package/cli/args.ts +120 -16
- package/cli/commands/acp.ts +38 -28
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +11 -12
- package/cli/commands/exec.ts +35 -73
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +96 -46
- package/cli/context-command-run.ts +171 -0
- package/cli/context-command.ts +87 -0
- package/cli/index.ts +96 -98
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +246 -123
- package/cli/tui.ts +311 -109
- package/docs/TERMINAL_CONTRACT.md +254 -69
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/config.md +16 -0
- package/docs/environment.md +3 -3
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +3 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +119 -66
- package/src/app/tool-layer.ts +12 -17
- package/src/config.ts +64 -104
- package/src/constants.ts +23 -9
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +109 -0
- package/src/policy/context.ts +78 -37
- package/src/policy/executor.ts +17 -7
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/guards.ts +41 -2
- package/src/providers/provision.ts +6 -60
- package/src/providers/responses.ts +1 -0
- package/src/repo/repomap.ts +180 -23
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +25 -58
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +20 -37
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +59 -23
- package/src/ui/i18n/id.ts +88 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +88 -62
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +154 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/src/tools/grep.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process"
|
|
2
|
-
import {
|
|
3
|
-
import { isAbsolute,
|
|
2
|
+
import { stat } from "node:fs/promises"
|
|
3
|
+
import { isAbsolute, resolve } from "node:path"
|
|
4
4
|
import type { Tool } from "#minicore"
|
|
5
5
|
import { LIMITS } from "../constants.ts"
|
|
6
|
-
import {
|
|
6
|
+
import { loadIgnoreMatchers } from "../lib/ignore.ts"
|
|
7
7
|
import { safeReadFile } from "../lib/safe-open.ts"
|
|
8
8
|
import { resolveTrustedExecutable } from "../lib/trusted-exec.ts"
|
|
9
9
|
import { isPathOutsideRoot, isSensitive } from "../policy/jail.ts"
|
|
10
10
|
import { sanitizeSpawnEnv, scrubSecrets } from "../policy/scrub.ts"
|
|
11
|
-
import {
|
|
11
|
+
import { resolveSearchRoot, walkWorkspaceFiles } from "./context.ts"
|
|
12
|
+
import { globToRegExp } from "./glob.ts"
|
|
12
13
|
|
|
13
14
|
async function walkGrep(
|
|
14
15
|
dir: string,
|
|
@@ -20,43 +21,30 @@ async function walkGrep(
|
|
|
20
21
|
includeRe?: RegExp | null,
|
|
21
22
|
ignoreMatchers: ((rel: string) => boolean)[] = [],
|
|
22
23
|
relaxed = false,
|
|
24
|
+
includeDotfiles = false,
|
|
23
25
|
) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
if (/\.(png|jpg|jpeg|gif|webp|pdf|zip|exe|dll|bin)$/i.test(e.name)) continue
|
|
38
|
-
// symlink file escape check — resolve realpath and jail
|
|
39
|
-
const real = await realpath(full).catch(() => full)
|
|
40
|
-
if (
|
|
41
|
-
(!relaxed && isPathOutsideRoot(real, resolve(root))) ||
|
|
42
|
-
isSensitive(real) ||
|
|
43
|
-
isSensitive(rel)
|
|
44
|
-
)
|
|
45
|
-
continue
|
|
46
|
-
// also skip if symlink points outside (already covered) or sensitive
|
|
26
|
+
await walkWorkspaceFiles(
|
|
27
|
+
{
|
|
28
|
+
dir,
|
|
29
|
+
root,
|
|
30
|
+
signal,
|
|
31
|
+
ignoreMatchers,
|
|
32
|
+
relaxed,
|
|
33
|
+
includeDotfiles,
|
|
34
|
+
shouldStop: () => out.length >= limit,
|
|
35
|
+
},
|
|
36
|
+
async ({ rel, name, real }) => {
|
|
37
|
+
if (includeRe && !includeRe.test(rel) && !includeRe.test(name)) return
|
|
38
|
+
if (/\.(png|jpg|jpeg|gif|webp|pdf|zip|exe|dll|bin)$/i.test(name)) return
|
|
47
39
|
const st = await stat(real).catch(() => null)
|
|
48
|
-
if (!st || st.size > LIMITS.GREP_FILE_MAX_BYTES)
|
|
49
|
-
// Baca via safeReadFile (O_NOFOLLOW + verifikasi ulang target saat
|
|
50
|
-
// open): swap symlink antara realpath di atas dan read di bawah tak
|
|
51
|
-
// lagi bisa menyelundupkan konten luar/sensitif. Gagal = lewati berkas.
|
|
40
|
+
if (!st || st.size > LIMITS.GREP_FILE_MAX_BYTES) return
|
|
52
41
|
const text = (await safeReadFile(real, root, relaxed).catch(() => null)) ?? ""
|
|
53
|
-
if (text.includes("\0"))
|
|
42
|
+
if (text.includes("\0")) return
|
|
54
43
|
const lines = text.split("\n")
|
|
55
44
|
for (let i = 0; i < lines.length; i++) {
|
|
56
45
|
re.lastIndex = 0
|
|
57
46
|
if (re.test(lines[i]!)) {
|
|
58
47
|
const body = lines[i]!
|
|
59
|
-
// Baris terpotong ditandai "…" agar tak tampak utuh (audit #02).
|
|
60
48
|
const cut = body.length > LIMITS.GREP_MATCH_MAX_CHARS
|
|
61
49
|
out.push(
|
|
62
50
|
`${rel}:${i + 1}: ${scrubSecrets(cut ? `${body.slice(0, LIMITS.GREP_MATCH_MAX_CHARS)}…` : body)}`,
|
|
@@ -64,18 +52,15 @@ async function walkGrep(
|
|
|
64
52
|
if (out.length >= limit) break
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
55
|
+
},
|
|
56
|
+
)
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
function includeToRegExp(include: string): RegExp | null {
|
|
72
60
|
if (!include) return null
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
esc = esc.replace(/§§/g, ".*")
|
|
77
|
-
esc = esc.replace(/\?/g, ".")
|
|
78
|
-
return new RegExp(`^${esc}$`)
|
|
61
|
+
// Pakai parser glob yang sama dengan glob.ts agar brace expansion `{ts,tsx}`
|
|
62
|
+
// konsisten antara mesin ripgrep (--glob) dan walker fallback JS.
|
|
63
|
+
return globToRegExp(include)
|
|
79
64
|
}
|
|
80
65
|
|
|
81
66
|
// ── ripgrep ──
|
|
@@ -139,6 +124,8 @@ function runRipgrep(
|
|
|
139
124
|
signal: AbortSignal,
|
|
140
125
|
include?: string,
|
|
141
126
|
relaxed = false,
|
|
127
|
+
ignoreCase = false,
|
|
128
|
+
includeDotfiles = false,
|
|
142
129
|
): Promise<string[]> {
|
|
143
130
|
const args = [
|
|
144
131
|
"--no-config", // config ripgrep dapat menjalankan --pre pada berkas workspace
|
|
@@ -155,9 +142,9 @@ function runRipgrep(
|
|
|
155
142
|
"!.git/**",
|
|
156
143
|
"--glob",
|
|
157
144
|
"!node_modules/**",
|
|
158
|
-
"--glob",
|
|
159
|
-
"!.*/**",
|
|
160
145
|
]
|
|
146
|
+
if (!includeDotfiles) args.push("--glob", "!.*/**")
|
|
147
|
+
if (ignoreCase) args.push("-i")
|
|
161
148
|
if (include) args.push("--glob", include)
|
|
162
149
|
args.push("--regexp", pattern, "--", ".")
|
|
163
150
|
|
|
@@ -238,41 +225,51 @@ function runRipgrep(
|
|
|
238
225
|
export const grepTool: Tool = {
|
|
239
226
|
name: "grep",
|
|
240
227
|
description:
|
|
241
|
-
"Search a regex across files. Returns file:line: content, capped (100/500 matches) with a refine hint. Skips .git, node_modules, and dotfiles; does not follow symlinks. Use for locating symbols or patterns before reading files.",
|
|
228
|
+
"Search a regex across files. Returns file:line: content, capped (100/500 matches) with a refine hint. Skips .git, node_modules, and dotfiles by default; does not follow symlinks. Use for locating symbols or patterns before reading files.",
|
|
242
229
|
parameters: {
|
|
243
230
|
type: "object",
|
|
244
231
|
properties: {
|
|
245
232
|
pattern: { type: "string", description: "regex pattern (e.g. log.*Error)" },
|
|
246
233
|
cwd: { type: "string", description: "root directory (default: workspace root)" },
|
|
247
|
-
include: { type: "string", description: "file glob filter (e.g. *.ts)" },
|
|
234
|
+
include: { type: "string", description: "file glob filter (e.g. *.ts or *.{ts,tsx})" },
|
|
248
235
|
limit: { type: "number" },
|
|
236
|
+
caseInsensitive: {
|
|
237
|
+
type: "boolean",
|
|
238
|
+
description: "ignore case when matching (default false)",
|
|
239
|
+
},
|
|
240
|
+
includeDotfiles: {
|
|
241
|
+
type: "boolean",
|
|
242
|
+
description: "include dotfiles/dotdirs like .github (default false)",
|
|
243
|
+
},
|
|
249
244
|
},
|
|
250
245
|
required: ["pattern"],
|
|
251
246
|
additionalProperties: false,
|
|
252
247
|
},
|
|
253
|
-
async execute({ pattern, cwd, include, limit }, ctx) {
|
|
254
|
-
const
|
|
255
|
-
const relaxed = contextUnrestricted(ctx)
|
|
256
|
-
const rawRoot = (cwd as string) ?? "."
|
|
257
|
-
const root = resolve(sessionRoot, rawRoot)
|
|
258
|
-
if (!relaxed && isPathOutsideRoot(root, sessionRoot))
|
|
259
|
-
throw new Error(`cwd outside workspace: ${rawRoot}`)
|
|
248
|
+
async execute({ pattern, cwd, include, limit, caseInsensitive, includeDotfiles }, ctx) {
|
|
249
|
+
const { root, rawRoot, relaxed } = resolveSearchRoot(cwd, ctx)
|
|
260
250
|
const rawLim = limit as number | undefined
|
|
261
251
|
const lim = Number.isFinite(rawLim)
|
|
262
252
|
? Math.min(Math.max(Math.floor(rawLim!), 1), LIMITS.SEARCH_MAX_LIMIT)
|
|
263
253
|
: LIMITS.SEARCH_DEFAULT_LIMIT
|
|
264
|
-
const
|
|
254
|
+
const rawPat = pattern as string
|
|
255
|
+
const inlineIgnoreCase = rawPat.startsWith("(?i)")
|
|
256
|
+
const pat = inlineIgnoreCase ? rawPat.slice(4) : rawPat
|
|
257
|
+
const ignoreCase = caseInsensitive === true || inlineIgnoreCase
|
|
265
258
|
// Validasi regex di JS lebih dulu: pesan errornya jelas dan berlaku untuk
|
|
266
|
-
// kedua jalur.
|
|
259
|
+
// kedua jalur. Prefix `(?i)` dikonversi ke flag `i` agar sintaks umum PCRE
|
|
260
|
+
// tidak ditolak oleh JS RegExp sebelum mencapai ripgrep.
|
|
267
261
|
let re: RegExp
|
|
268
262
|
try {
|
|
269
|
-
re = new RegExp(pat)
|
|
263
|
+
re = new RegExp(pat, ignoreCase ? "i" : "")
|
|
270
264
|
} catch (e) {
|
|
271
265
|
throw new Error(`invalid regex: ${(e as Error).message}`)
|
|
272
266
|
}
|
|
273
267
|
|
|
274
268
|
const noMatch = () =>
|
|
275
|
-
`no matches for /${
|
|
269
|
+
`no matches for /${rawPat}/ in ${rawRoot}${include ? ` (include ${include})` : ""}`
|
|
270
|
+
const st = await stat(root).catch(() => null)
|
|
271
|
+
if (!st?.isDirectory()) return noMatch()
|
|
272
|
+
const withDotfiles = includeDotfiles === true
|
|
276
273
|
|
|
277
274
|
// Minta satu lebih agar tahu pasti apakah hasil terpotong (temuan #02:
|
|
278
275
|
// limit-hit diam-diam tampak lengkap). Tampilkan tetap `lim`.
|
|
@@ -286,6 +283,8 @@ export const grepTool: Tool = {
|
|
|
286
283
|
ctx.signal,
|
|
287
284
|
include as string | undefined,
|
|
288
285
|
relaxed,
|
|
286
|
+
ignoreCase,
|
|
287
|
+
withDotfiles,
|
|
289
288
|
)
|
|
290
289
|
if (hits.length === 0) return noMatch()
|
|
291
290
|
// runRipgrep tandai timeout via suffix khusus di elemen terakhir (bila timedOut)
|
|
@@ -302,7 +301,18 @@ export const grepTool: Tool = {
|
|
|
302
301
|
const incRe = include ? includeToRegExp(include as string) : null
|
|
303
302
|
const ignoreMatchers = await loadIgnoreMatchers(root)
|
|
304
303
|
const out: string[] = []
|
|
305
|
-
await walkGrep(
|
|
304
|
+
await walkGrep(
|
|
305
|
+
root,
|
|
306
|
+
re,
|
|
307
|
+
out,
|
|
308
|
+
root,
|
|
309
|
+
want,
|
|
310
|
+
ctx.signal,
|
|
311
|
+
incRe,
|
|
312
|
+
ignoreMatchers,
|
|
313
|
+
relaxed,
|
|
314
|
+
withDotfiles,
|
|
315
|
+
)
|
|
306
316
|
return out.length === 0 ? noMatch() : withCapMark(out, lim)
|
|
307
317
|
},
|
|
308
318
|
}
|
package/src/tools/hashline.ts
CHANGED
|
@@ -48,6 +48,10 @@ export function findHashlineHunk(
|
|
|
48
48
|
for (let j = 0; j < searchLines.length; j++) {
|
|
49
49
|
if (trimmedContentHashes[i + j] !== trimmedSearchHashes[j]) continue outer2
|
|
50
50
|
}
|
|
51
|
+
// Verifikasi kesetaraan teks setelah trim untuk menutup potensi kolisi hash 32-bit.
|
|
52
|
+
for (let j = 0; j < searchLines.length; j++) {
|
|
53
|
+
if (contentLines[i + j]?.trim() !== searchLines[j]?.trim()) continue outer2
|
|
54
|
+
}
|
|
51
55
|
return { start: i, end: i + searchLines.length }
|
|
52
56
|
}
|
|
53
57
|
return null
|
package/src/tools/lsp.ts
CHANGED
|
@@ -125,10 +125,13 @@ function posTool(
|
|
|
125
125
|
parameters: {
|
|
126
126
|
type: "object",
|
|
127
127
|
properties: {
|
|
128
|
-
file: { type: "string", description: "path
|
|
129
|
-
symbol: {
|
|
128
|
+
file: { type: "string", description: "file path relative to cwd" },
|
|
129
|
+
symbol: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "symbol name in the file (alternative to line/character)",
|
|
132
|
+
},
|
|
130
133
|
line: { type: "number", description: "0-based line (optional)" },
|
|
131
|
-
character: { type: "number", description: "
|
|
134
|
+
character: { type: "number", description: "0-based column (optional)" },
|
|
132
135
|
},
|
|
133
136
|
required: ["file"],
|
|
134
137
|
additionalProperties: false,
|
|
@@ -171,7 +174,7 @@ export const lspDiagnosticsTool: Tool = {
|
|
|
171
174
|
"LSP diagnostics for one file (errors/warnings from the language server). Requires a registered LSP server for the file extension.",
|
|
172
175
|
parameters: {
|
|
173
176
|
type: "object",
|
|
174
|
-
properties: { file: { type: "string", description: "path
|
|
177
|
+
properties: { file: { type: "string", description: "file path relative to cwd" } },
|
|
175
178
|
required: ["file"],
|
|
176
179
|
additionalProperties: false,
|
|
177
180
|
},
|
|
@@ -220,15 +223,15 @@ export const lspReferencesTool = posTool(
|
|
|
220
223
|
export const lspHoverTool = posTool(
|
|
221
224
|
"lsp_hover",
|
|
222
225
|
"textDocument/hover",
|
|
223
|
-
"Hover info
|
|
226
|
+
"Hover info and type signature for a symbol. Params: file + symbol (or line/character).",
|
|
224
227
|
)
|
|
225
228
|
|
|
226
229
|
export const lspSymbolsTool: Tool = {
|
|
227
230
|
name: "lsp_symbols",
|
|
228
|
-
description: "
|
|
231
|
+
description: "Document symbol outline (functions/classes/variables) via LSP.",
|
|
229
232
|
parameters: {
|
|
230
233
|
type: "object",
|
|
231
|
-
properties: { file: { type: "string", description: "path
|
|
234
|
+
properties: { file: { type: "string", description: "file path relative to cwd" } },
|
|
232
235
|
required: ["file"],
|
|
233
236
|
additionalProperties: false,
|
|
234
237
|
},
|
|
@@ -279,10 +282,10 @@ export const lspWorkspaceSymbolsTool: Tool = {
|
|
|
279
282
|
},
|
|
280
283
|
async execute({ query }, ctx) {
|
|
281
284
|
ctx.signal.throwIfAborted()
|
|
285
|
+
const cwd = requireToolCwd(ctx)
|
|
282
286
|
if (getConfiguredExts().length === 0)
|
|
283
287
|
return "(no LSP servers configured — add via minicode config lsp add)"
|
|
284
288
|
try {
|
|
285
|
-
const cwd = requireToolCwd(ctx)
|
|
286
289
|
const symbols = await raceAbort(
|
|
287
290
|
workspaceSymbols((query as string) ?? "", 5000, cwd),
|
|
288
291
|
ctx.signal,
|
package/src/tools/mcp_call.ts
CHANGED
|
@@ -57,7 +57,7 @@ export const mcpCallTool: Tool = {
|
|
|
57
57
|
properties: {
|
|
58
58
|
server: {
|
|
59
59
|
type: "string",
|
|
60
|
-
description: "
|
|
60
|
+
description: "MCP server ID (see mcp_list)",
|
|
61
61
|
},
|
|
62
62
|
tool: {
|
|
63
63
|
type: "string",
|
|
@@ -93,6 +93,7 @@ export const mcpCallTool: Tool = {
|
|
|
93
93
|
: fenceUntrustedToolOutput(`mcp_call:${sid}.${tn}`, capped)
|
|
94
94
|
} catch (e) {
|
|
95
95
|
if (e instanceof McpCallOutcomeUnknownError) throw e
|
|
96
|
+
ctx.signal.throwIfAborted()
|
|
96
97
|
return `[mcp] error: ${scrubSecrets((e as Error).message)}`
|
|
97
98
|
}
|
|
98
99
|
},
|
|
@@ -107,11 +108,11 @@ function notConnected(sid: string): string {
|
|
|
107
108
|
export const mcpReadTool: Tool = {
|
|
108
109
|
name: "mcp_read",
|
|
109
110
|
description:
|
|
110
|
-
"
|
|
111
|
+
"Read a resource from a connected MCP server (resources/read). Get URIs from mcp_list. Read-only.",
|
|
111
112
|
parameters: {
|
|
112
113
|
type: "object",
|
|
113
114
|
properties: {
|
|
114
|
-
server: { type: "string", description: "
|
|
115
|
+
server: { type: "string", description: "MCP server ID" },
|
|
115
116
|
uri: { type: "string", description: "Resource URI, e.g. file:///x or db://table" },
|
|
116
117
|
},
|
|
117
118
|
required: ["server", "uri"],
|
|
@@ -129,6 +130,7 @@ export const mcpReadTool: Tool = {
|
|
|
129
130
|
const capped = capMcpText(text)
|
|
130
131
|
return isAlreadyFenced(capped) ? capped : fenceUntrustedToolOutput(`mcp_read:${sid}`, capped)
|
|
131
132
|
} catch (e) {
|
|
133
|
+
ctx.signal.throwIfAborted()
|
|
132
134
|
return `[mcp] error: ${scrubSecrets((e as Error).message)}`
|
|
133
135
|
}
|
|
134
136
|
},
|
|
@@ -141,11 +143,11 @@ export const mcpPromptTool: Tool = {
|
|
|
141
143
|
parameters: {
|
|
142
144
|
type: "object",
|
|
143
145
|
properties: {
|
|
144
|
-
server: { type: "string", description: "
|
|
145
|
-
name: { type: "string", description: "
|
|
146
|
+
server: { type: "string", description: "MCP server ID" },
|
|
147
|
+
name: { type: "string", description: "Prompt name (see mcp_list)" },
|
|
146
148
|
args: {
|
|
147
149
|
type: "object",
|
|
148
|
-
description: "
|
|
150
|
+
description: "Prompt arguments (key-value object)",
|
|
149
151
|
additionalProperties: true,
|
|
150
152
|
},
|
|
151
153
|
},
|
|
@@ -166,6 +168,7 @@ export const mcpPromptTool: Tool = {
|
|
|
166
168
|
? capped
|
|
167
169
|
: fenceUntrustedToolOutput(`mcp_prompt:${sid}`, capped)
|
|
168
170
|
} catch (e) {
|
|
171
|
+
ctx.signal.throwIfAborted()
|
|
169
172
|
return `[mcp] error: ${scrubSecrets((e as Error).message)}`
|
|
170
173
|
}
|
|
171
174
|
},
|
package/src/tools/memory.ts
CHANGED
|
@@ -10,10 +10,13 @@ import {
|
|
|
10
10
|
checkMemorySupersessionTarget,
|
|
11
11
|
deleteMemoryByQuery,
|
|
12
12
|
invokeMemoryWriteFaultForTest,
|
|
13
|
+
MemorySupersessionError,
|
|
13
14
|
memoryEntryText,
|
|
14
15
|
recordCandidateLesson,
|
|
16
|
+
resolveEnvEmbeddingAuth,
|
|
15
17
|
searchHybrid,
|
|
16
18
|
} from "../memory/vector.ts"
|
|
19
|
+
import { scrubSecrets } from "../policy/scrub.ts"
|
|
17
20
|
import { requireToolCwd } from "./context.ts"
|
|
18
21
|
import { subAgentWorkMode } from "./task.ts"
|
|
19
22
|
|
|
@@ -47,12 +50,7 @@ export const readMemoryTool: Tool = {
|
|
|
47
50
|
// hybrid search — use cwd + try embedding via env (consistent with cli RAG)
|
|
48
51
|
let hits: { text: string; score: number; createdAt: number; id?: string }[] = []
|
|
49
52
|
try {
|
|
50
|
-
const baseUrl
|
|
51
|
-
const apiKey =
|
|
52
|
-
process.env.OPENAI_API_KEY ??
|
|
53
|
-
process.env.DEEPSEEK_API_KEY ??
|
|
54
|
-
process.env.AGENT_API_KEY ??
|
|
55
|
-
""
|
|
53
|
+
const { baseUrl, apiKey } = resolveEnvEmbeddingAuth()
|
|
56
54
|
hits = await searchHybrid(q, {
|
|
57
55
|
topK: (topK as number) ?? 5,
|
|
58
56
|
cwd,
|
|
@@ -68,7 +66,10 @@ export const readMemoryTool: Tool = {
|
|
|
68
66
|
.split("\n")
|
|
69
67
|
.filter((l) => l.toLowerCase().includes(q.toLowerCase()))
|
|
70
68
|
.slice(0, 5)
|
|
71
|
-
.map((l) =>
|
|
69
|
+
.map((l) => {
|
|
70
|
+
const clean = scrubSecrets(l)
|
|
71
|
+
return clean.length > 300 ? `${clean.slice(0, 300)}…` : clean
|
|
72
|
+
})
|
|
72
73
|
.join("\n")
|
|
73
74
|
const fmtDate = (ts: number): string => {
|
|
74
75
|
try {
|
|
@@ -92,7 +93,8 @@ export const readMemoryTool: Tool = {
|
|
|
92
93
|
// [Live Hardening §7.5] ekspos id row agar write_memory.supersedes_id
|
|
93
94
|
// bisa menyasar id nyata (sebelumnya tak diekspos → model memakai teks).
|
|
94
95
|
const idTag = h.id ? ` [id:${h.id}] ` : ""
|
|
95
|
-
|
|
96
|
+
const cleanText = scrubSecrets(h.text)
|
|
97
|
+
return `- ${cleanText.slice(0, 300)}${cleanText.length > 300 ? "…" : ""} (${h.score.toFixed(2)}, ${fmtDate(h.createdAt)}) ${meta}${idTag}`
|
|
96
98
|
},
|
|
97
99
|
)
|
|
98
100
|
.join("\n")}\n`
|
|
@@ -150,16 +152,17 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
150
152
|
// itu dibaca mentah saat query kosong) dan hanya hidup di store vektor
|
|
151
153
|
// dengan status `provisional` sampai verifikasi mempromosikannya.
|
|
152
154
|
if (validation === "provisional") {
|
|
155
|
+
if (typeof supersedes_id === "string" && supersedes_id) {
|
|
156
|
+
throw new Error("supersedes_id cannot be combined with validation=provisional")
|
|
157
|
+
}
|
|
153
158
|
if (typeof sessionId !== "string" || !sessionId) {
|
|
154
159
|
throw new Error("validation=provisional requires sessionId for later promotion")
|
|
155
160
|
}
|
|
156
|
-
const baseUrl
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
""
|
|
162
|
-
const tagArr = Array.isArray(tags) ? (tags as string[]) : undefined
|
|
161
|
+
const { baseUrl, apiKey } = resolveEnvEmbeddingAuth()
|
|
162
|
+
const tagArr = Array.isArray(tags)
|
|
163
|
+
? (tags as string[]).map((tg) => scrubSecrets(String(tg)).replace(/[\r\n]+/g, " "))
|
|
164
|
+
: undefined
|
|
165
|
+
const cleanEcho = scrubSecrets(t.trim()).replace(/[\r\n]+/g, " ")
|
|
163
166
|
const id = await recordCandidateLesson(sessionId, t, {
|
|
164
167
|
cwd,
|
|
165
168
|
...(apiKey ? { baseUrl, apiKey } : {}),
|
|
@@ -168,7 +171,7 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
168
171
|
turnId: (turnId as string | undefined) ?? null,
|
|
169
172
|
sourceRef: (sourceRef as string | undefined) ?? null,
|
|
170
173
|
})
|
|
171
|
-
return `candidate lesson recorded (provisional) id=${id}: ${
|
|
174
|
+
return `candidate lesson recorded (provisional) id=${id}: ${cleanEcho.slice(0, 100)}`
|
|
172
175
|
}
|
|
173
176
|
// [Live Hardening §7.5] Validasi supersedes_id SEBELUM file/vector tersentuh.
|
|
174
177
|
// Id yang tak ada → error actionable, bukan tombstone no-op yang menyisakan
|
|
@@ -190,9 +193,12 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
190
193
|
// menulisnya hanya ke hasil tool, sehingga baris di MEMORY.md tak punya
|
|
191
194
|
// bukti provenance (tag yang dibangun di bawah terbuang percuma).
|
|
192
195
|
const cat = (category as string) ?? "fact"
|
|
193
|
-
const tagArr = Array.isArray(tags)
|
|
196
|
+
const tagArr = Array.isArray(tags)
|
|
197
|
+
? (tags as string[]).map((tg) => scrubSecrets(String(tg)).replace(/[\r\n]+/g, " "))
|
|
198
|
+
: undefined
|
|
194
199
|
// [Fase 12 / LF-4] id memori lama yang digantikan (supersession) dari argumen tool.
|
|
195
200
|
const supersedesId = typeof supersedes_id === "string" && supersedes_id ? supersedes_id : null
|
|
201
|
+
const scrubbedLineText = scrubSecrets(t.trim()).replace(/[\r\n]+/g, " ")
|
|
196
202
|
|
|
197
203
|
// MEM-01: add provenance tags to MEMORY.md (as metadata comment at end of line)
|
|
198
204
|
const memTags = tagArr ? [...tagArr] : []
|
|
@@ -207,13 +213,9 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
207
213
|
// persis di titik ini → menghasilkan entri file-only (split-brain arah 1).
|
|
208
214
|
invokeMemoryWriteFaultForTest("after_file_before_vector")
|
|
209
215
|
|
|
210
|
-
const baseUrl
|
|
211
|
-
const apiKey =
|
|
212
|
-
process.env.DEEPSEEK_API_KEY ??
|
|
213
|
-
process.env.OPENAI_API_KEY ??
|
|
214
|
-
process.env.AGENT_API_KEY ??
|
|
215
|
-
""
|
|
216
|
+
const { baseUrl, apiKey } = resolveEnvEmbeddingAuth()
|
|
216
217
|
let added = false
|
|
218
|
+
let supersessionErr: MemorySupersessionError | null = null
|
|
217
219
|
if (apiKey) {
|
|
218
220
|
try {
|
|
219
221
|
await addMemory(t, {
|
|
@@ -230,10 +232,12 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
230
232
|
})
|
|
231
233
|
added = true
|
|
232
234
|
} catch (e) {
|
|
233
|
-
|
|
235
|
+
if (e instanceof MemorySupersessionError) supersessionErr = e
|
|
236
|
+
else
|
|
237
|
+
process.stderr.write(`[warn] memory vector embedding failed: ${(e as Error).message}\n`)
|
|
234
238
|
}
|
|
235
239
|
}
|
|
236
|
-
if (!added) {
|
|
240
|
+
if (!added && !supersessionErr) {
|
|
237
241
|
try {
|
|
238
242
|
await addMemory(t, {
|
|
239
243
|
cwd,
|
|
@@ -247,11 +251,23 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
247
251
|
})
|
|
248
252
|
added = true
|
|
249
253
|
} catch (e2) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
254
|
+
if (e2 instanceof MemorySupersessionError) supersessionErr = e2
|
|
255
|
+
else {
|
|
256
|
+
process.stderr.write(
|
|
257
|
+
`[warn] memory keyword-only fallback failed: ${(e2 as Error).message}\n`,
|
|
258
|
+
)
|
|
259
|
+
}
|
|
253
260
|
}
|
|
254
261
|
}
|
|
262
|
+
// P1.3: error semantik supersession (mis. race conflict / self) harus
|
|
263
|
+
// ditolak tegas setelah rollback file — JANGAN ditelan sebagai
|
|
264
|
+
// "vector index unavailable".
|
|
265
|
+
if (supersessionErr) {
|
|
266
|
+
try {
|
|
267
|
+
await deleteMemoryEntry(scrubbedLineText, cwd)
|
|
268
|
+
} catch {}
|
|
269
|
+
throw supersessionErr
|
|
270
|
+
}
|
|
255
271
|
// [Area E / D6] Fakta lama yang digantikan harus hilang dari MEMORY.md —
|
|
256
272
|
// jalur retrieval file membaca berkas mentah, jadi menambah fakta baru
|
|
257
273
|
// saja membuat fakta lama tetap "benar". Hanya dilakukan bila store vektor
|
|
@@ -263,12 +279,12 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
263
279
|
if (oldText) await deleteMemoryEntry(oldText, cwd)
|
|
264
280
|
} catch {}
|
|
265
281
|
}
|
|
266
|
-
// P1.3: bila store menolak (mis.
|
|
282
|
+
// P1.3: bila store menolak (mis. DB terkunci/gagal dengan supersedesId), tarik
|
|
267
283
|
// kembali baris file yang sudah ditulis agar tidak ada fakta "file-only"
|
|
268
284
|
// yang tetap terbaca sementara relasi supersession gagal.
|
|
269
285
|
if (!added && supersedesId) {
|
|
270
286
|
try {
|
|
271
|
-
await deleteMemoryEntry(
|
|
287
|
+
await deleteMemoryEntry(scrubbedLineText, cwd)
|
|
272
288
|
} catch {}
|
|
273
289
|
}
|
|
274
290
|
// [Area E / D1] Jangan klaim sukses penuh bila indeks vektor gagal total:
|
|
@@ -278,7 +294,7 @@ export function createWriteMemoryTool(runtimeSessionId?: string): Tool {
|
|
|
278
294
|
const vectorNote = added
|
|
279
295
|
? ""
|
|
280
296
|
: " (vector index unavailable — saved to file only; run `minicode memory reconcile` to index)"
|
|
281
|
-
return `saved to ${path}: ${
|
|
297
|
+
return `saved to ${path}: ${scrubbedLineText.slice(0, 100)}${memTags.length ? ` [tags: ${JSON.stringify(memTags)}]` : ""}${vectorNote}`
|
|
282
298
|
},
|
|
283
299
|
}
|
|
284
300
|
}
|
|
@@ -315,13 +331,20 @@ export const forgetMemoryTool: Tool = {
|
|
|
315
331
|
|
|
316
332
|
let resultText = ""
|
|
317
333
|
|
|
318
|
-
// Use provenance-based deletion if specified
|
|
334
|
+
// Use provenance-based deletion if specified (memadukan query jika ikut diisi),
|
|
335
|
+
// otherwise fall back to query-based.
|
|
319
336
|
if (sessionId || turnId || sourceKind) {
|
|
320
337
|
const { revokeByProvenance } = await import("../memory/vector.ts")
|
|
321
|
-
const criteria: {
|
|
338
|
+
const criteria: {
|
|
339
|
+
sessionId?: string
|
|
340
|
+
turnId?: string
|
|
341
|
+
sourceKind?: string
|
|
342
|
+
query?: string
|
|
343
|
+
} = {}
|
|
322
344
|
if (sessionId as string) criteria.sessionId = sessionId as string
|
|
323
345
|
if (turnId as string) criteria.turnId = turnId as string
|
|
324
346
|
if (sourceKind as string) criteria.sourceKind = sourceKind as string
|
|
347
|
+
if (q.trim()) criteria.query = q.trim()
|
|
325
348
|
const { vectorRows, fileLines } = await revokeByProvenance(criteria, cwd)
|
|
326
349
|
resultText = `revoked ${vectorRows} vector entries + ${fileLines} file lines by provenance`
|
|
327
350
|
} else {
|
package/src/tools/move_file.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { mkdir, rename, stat } from "node:fs/promises"
|
|
2
|
-
import { dirname } from "node:path"
|
|
1
|
+
import { lstat, mkdir, rename, stat } from "node:fs/promises"
|
|
2
|
+
import { dirname, extname } from "node:path"
|
|
3
3
|
import type { Tool } from "#minicore"
|
|
4
|
-
import {
|
|
4
|
+
import { LIMITS } from "../constants.ts"
|
|
5
|
+
import { assertSafeWriteTarget, resolveSafePath, safeReadFile } from "../lib/safe-open.ts"
|
|
5
6
|
import { trashFile } from "../lib/trash.ts"
|
|
7
|
+
import { getConfiguredExts } from "../lsp/client.ts"
|
|
8
|
+
import { appendLspDiagnostics } from "../policy/verifier.ts"
|
|
6
9
|
import { contextUnrestricted, requireToolCwd } from "./context.ts"
|
|
7
10
|
|
|
8
11
|
export const moveFileTool: Tool = {
|
|
@@ -31,19 +34,42 @@ export const moveFileTool: Tool = {
|
|
|
31
34
|
const { abs: absFrom, real: realFrom } = await resolveSafePath(f, root, relaxed)
|
|
32
35
|
const st = await stat(realFrom).catch(() => null)
|
|
33
36
|
if (!st) throw new Error(`source not found: ${f}`)
|
|
34
|
-
const { abs: absTo } = await resolveSafePath(t, root, relaxed)
|
|
37
|
+
const { abs: absTo, real: realTo } = await resolveSafePath(t, root, relaxed)
|
|
38
|
+
await assertSafeWriteTarget(absTo, root, relaxed)
|
|
35
39
|
await mkdir(dirname(absTo), { recursive: true, mode: 0o700 }).catch(() => {})
|
|
40
|
+
|
|
41
|
+
// Deteksi rename case-only (mis. foo.ts → Foo.ts di Windows NTFS) atau
|
|
42
|
+
// alias path ke berkas fisik yang sama sebelum trashFile, agar sumber
|
|
43
|
+
// tidak dipindahkan ke .trash sebelum rename dijalankan.
|
|
44
|
+
const fromLstat = await lstat(absFrom, { bigint: true }).catch(() => null)
|
|
45
|
+
const destLstat = await lstat(absTo, { bigint: true }).catch(() => null)
|
|
46
|
+
const sameInode =
|
|
47
|
+
fromLstat !== null &&
|
|
48
|
+
destLstat !== null &&
|
|
49
|
+
fromLstat.ino !== 0n &&
|
|
50
|
+
fromLstat.dev === destLstat.dev &&
|
|
51
|
+
fromLstat.ino === destLstat.ino
|
|
52
|
+
const sameWinCasePath =
|
|
53
|
+
process.platform === "win32" &&
|
|
54
|
+
absFrom.toLowerCase() === absTo.toLowerCase() &&
|
|
55
|
+
!destLstat?.isSymbolicLink()
|
|
56
|
+
const sameFileRename = sameInode || sameWinCasePath
|
|
57
|
+
|
|
36
58
|
// S3 — dest yang sudah ada dibackup ke trash dulu (jangan timpa diam-diam).
|
|
37
|
-
//
|
|
38
|
-
// realpath ulang di sini.
|
|
59
|
+
// Pakai lstat agar symlink tujuan di-trash sebagai entry link, bukan targetnya.
|
|
39
60
|
let backup = ""
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (destStat.isDirectory()) throw new Error(`destination is a directory: ${t}`)
|
|
61
|
+
if (destLstat && !sameFileRename) {
|
|
62
|
+
if (destLstat.isDirectory()) throw new Error(`destination is a directory: ${t}`)
|
|
43
63
|
const trashed = await trashFile(root, absTo)
|
|
44
64
|
backup = ` (previous dest backed up to ${trashed})`
|
|
45
65
|
}
|
|
46
66
|
await rename(absFrom, absTo)
|
|
47
|
-
|
|
67
|
+
const base = `moved ${f} -> ${t}${backup}`
|
|
68
|
+
if (!st.isFile() || st.size > LIMITS.READ_FILE_MAX_BYTES) return base
|
|
69
|
+
const ext = extname(absTo).toLowerCase()
|
|
70
|
+
if (!getConfiguredExts().includes(ext)) return base
|
|
71
|
+
const text = await safeReadFile(absTo, root, relaxed).catch(() => null)
|
|
72
|
+
if (text === null) return base
|
|
73
|
+
return await appendLspDiagnostics(realTo, text, base, undefined, root)
|
|
48
74
|
},
|
|
49
75
|
}
|