minicode-ai 0.22.0 → 0.25.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 (100) hide show
  1. package/README.md +2 -2
  2. package/cli/commands.ts +10 -0
  3. package/cli/index.ts +11 -0
  4. package/cli/setup.ts +64 -33
  5. package/cli/tui.ts +29 -3
  6. package/docs/README.md +2 -2
  7. package/docs/SUMMARY.md +10 -19
  8. package/docs/TERMINAL_CONTRACT.md +119 -32
  9. package/docs/architecture.md +1 -1
  10. package/docs/autonomous-scheduler.md +283 -2
  11. package/docs/choosing-mode.md +4 -4
  12. package/docs/concepts.md +39 -3
  13. package/docs/config.md +90 -4
  14. package/docs/environment.md +6 -0
  15. package/docs/getting-started.md +58 -2
  16. package/docs/repl.md +1 -1
  17. package/docs/security.md +49 -2
  18. package/docs/tools.md +2 -1
  19. package/package.json +2 -36
  20. package/src/app/provider-layer.ts +1 -1
  21. package/src/app/session.ts +129 -20
  22. package/src/config.ts +102 -2
  23. package/src/constants.ts +32 -4
  24. package/src/lib/safe-open.ts +21 -12
  25. package/src/memory/vector.ts +0 -31
  26. package/src/policy/compaction.ts +27 -0
  27. package/src/policy/context-budget.ts +132 -0
  28. package/src/policy/context-escalation.ts +140 -0
  29. package/src/policy/context-window.ts +14 -9
  30. package/src/policy/context.ts +10 -1
  31. package/src/policy/microcompact.ts +162 -0
  32. package/src/policy/no-progress.ts +1 -1
  33. package/src/policy/permission.ts +5 -0
  34. package/src/policy/scrub.ts +15 -2
  35. package/src/policy/tool-contract.ts +11 -9
  36. package/src/presentation/reducer.ts +1 -0
  37. package/src/providers/anthropic.ts +17 -3
  38. package/src/providers/detect.ts +155 -13
  39. package/src/providers/provision.ts +92 -1
  40. package/src/providers/responses.ts +13 -1
  41. package/src/session/persistence.ts +56 -0
  42. package/src/task/autonomous-policy.ts +7 -0
  43. package/src/task/graph-validate.ts +1 -1
  44. package/src/task/session-authority.ts +0 -5
  45. package/src/task/store.ts +0 -4
  46. package/src/tools/ask_user.ts +14 -1
  47. package/src/tools/bash.ts +57 -9
  48. package/src/tools/context.ts +10 -0
  49. package/src/tools/delete_file.ts +3 -2
  50. package/src/tools/edit.ts +5 -4
  51. package/src/tools/git.ts +70 -12
  52. package/src/tools/glob.ts +13 -5
  53. package/src/tools/grep.ts +26 -10
  54. package/src/tools/index.ts +3 -2
  55. package/src/tools/lsp.ts +15 -9
  56. package/src/tools/move_file.ts +4 -3
  57. package/src/tools/patch.ts +5 -4
  58. package/src/tools/read_file.ts +3 -2
  59. package/src/tools/read_image.ts +3 -2
  60. package/src/tools/task.ts +1 -0
  61. package/src/tools/todo.ts +4 -8
  62. package/src/tools/write_file.ts +4 -3
  63. package/src/ui/approval/prompt.ts +226 -77
  64. package/src/ui/assistant/simple.ts +1 -1
  65. package/src/ui/footer.ts +41 -29
  66. package/src/ui/i18n/en.ts +23 -4
  67. package/src/ui/i18n/id.ts +25 -4
  68. package/src/ui/input/input.ts +2 -2
  69. package/src/ui/render/activity-group.ts +1 -0
  70. package/src/ui/render/activity-panel.ts +21 -3
  71. package/src/ui/render/hint.ts +28 -0
  72. package/src/ui/render/ledger.ts +1 -9
  73. package/src/ui/render/logo.ts +86 -0
  74. package/src/ui/render/markdown-table.ts +0 -3
  75. package/src/ui/render/session-summary.ts +22 -1
  76. package/src/ui/render/table-grid.ts +0 -3
  77. package/src/ui/render/theme.ts +36 -5
  78. package/src/ui/runtime/screen.ts +11 -3
  79. package/src/ui/screens/dialog.ts +45 -81
  80. package/src/ui/screens/form.ts +29 -33
  81. package/src/ui/screens/lifecycle.ts +80 -0
  82. package/src/ui/screens/model-manager.ts +84 -91
  83. package/src/ui/screens/picker.ts +36 -33
  84. package/src/ui/screens/provider-manager.ts +50 -59
  85. package/src/ui/screens/watchdog.ts +27 -0
  86. package/src/ui/screens/wizard.ts +3 -20
  87. package/src/ui/tui/app.ts +97 -11
  88. package/src/ui/tui/transcript.ts +55 -16
  89. package/vendor/minicore/src/core/compact.ts +10 -0
  90. package/vendor/minicore/src/core/errors.ts +11 -1
  91. package/vendor/minicore/src/core/executor.ts +6 -1
  92. package/vendor/minicore/src/core/loop.ts +92 -2
  93. package/vendor/minicore/src/core/session.ts +8 -0
  94. package/vendor/minicore/src/providers/openai-compat.ts +15 -2
  95. package/docs/P14_OPEN_WORK.md +0 -290
  96. package/docs/config-providers.md +0 -87
  97. package/docs/glossary.md +0 -39
  98. package/docs/quickstart.md +0 -60
  99. package/docs/security-model.md +0 -96
  100. package/docs/terminal.md +0 -91
@@ -6,3 +6,13 @@ export function requireToolCwd(context: unknown): string {
6
6
  }
7
7
  return cwd
8
8
  }
9
+
10
+ /**
11
+ * True hanya di mode `unrestricted`. Sumber: `ToolContext.permissionMode`,
12
+ * di-resolve LIVE per-turn oleh kernel — `/unrestric` saat runtime langsung
13
+ * tercermin tanpa patch vendor. Fail-closed: selain string "unrestricted"
14
+ * (termasuk undefined pada pemanggil library/test) = false.
15
+ */
16
+ export function contextUnrestricted(context: unknown): boolean {
17
+ return (context as { permissionMode?: unknown } | null)?.permissionMode === "unrestricted"
18
+ }
@@ -2,7 +2,7 @@ import { stat } from "node:fs/promises"
2
2
  import type { Tool } from "#minicore"
3
3
  import { resolveSafePath } from "../lib/safe-open.ts"
4
4
  import { trashFile } from "../lib/trash.ts"
5
- import { requireToolCwd } from "./context.ts"
5
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
6
6
 
7
7
  export const deleteFileTool: Tool = {
8
8
  name: "delete_file",
@@ -20,8 +20,9 @@ export const deleteFileTool: Tool = {
20
20
  ctx.signal.throwIfAborted()
21
21
  const p = path as string
22
22
  const root = requireToolCwd(ctx)
23
+ const relaxed = contextUnrestricted(ctx)
23
24
  // Verifikasi path terpusat (logis + target nyata) — detail di safe-open.ts.
24
- const { abs, real } = await resolveSafePath(p, root)
25
+ const { abs, real } = await resolveSafePath(p, root, relaxed)
25
26
  const st = await stat(real).catch(() => null)
26
27
  if (!st) throw new Error(`file not found: ${p}`)
27
28
  if (st.isDirectory()) throw new Error(`path is directory, use bash rm -r: ${p}`)
package/src/tools/edit.ts CHANGED
@@ -3,7 +3,7 @@ import { LIMITS } from "../constants.ts"
3
3
  import { atomicWriteText } from "../lib/atomic-write.ts"
4
4
  import { assertSafeWriteTarget, resolveSafePath, safeReadFile } from "../lib/safe-open.ts"
5
5
  import { appendLspDiagnostics } from "../policy/verifier.ts"
6
- import { requireToolCwd } from "./context.ts"
6
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
7
7
  import { applyHashline } from "./hashline.ts"
8
8
 
9
9
  function normalizeLf(s: string): string {
@@ -147,11 +147,12 @@ export const editTool: Tool = {
147
147
  ctx.signal.throwIfAborted()
148
148
  const p = path as string
149
149
  const root = requireToolCwd(ctx)
150
+ const relaxed = contextUnrestricted(ctx)
150
151
  // Verifikasi path terpusat (logis + target nyata, induk symlink ikut
151
152
  // ter-resolusi) — symlink internal tetap bisa diedit, targetnya yang dicek.
152
- const { abs, real: realAbs } = await resolveSafePath(p, root)
153
+ const { abs, real: realAbs } = await resolveSafePath(p, root, relaxed)
153
154
  // Tolak menimpa symlink final (swap antara cek dan tulis gagal tutup).
154
- await assertSafeWriteTarget(abs, root)
155
+ await assertSafeWriteTarget(abs, root, relaxed)
155
156
  // Cek ukuran sebelum baca penuh — hindari OOM 1GB via safeReadFile.
156
157
  // Pakai byte length via stat pada realAbs (handle belum ada), fallback ke content length.
157
158
  const { stat } = await import("node:fs/promises")
@@ -159,7 +160,7 @@ export const editTool: Tool = {
159
160
  if (!st) throw new Error(`file not found: ${p}`)
160
161
  if (st.size > LIMITS.READ_FILE_MAX_BYTES) throw new Error(`file too large: ${p} (${st.size})`)
161
162
  // Baca via safeReadFile (O_NOFOLLOW) agar TOCTOU swap gagal ELOOP, bukan baca luar.
162
- const content = await safeReadFile(abs, root).catch(() => {
163
+ const content = await safeReadFile(abs, root, relaxed).catch(() => {
163
164
  throw new Error(`file not found: ${p}`)
164
165
  })
165
166
  const oldS = oldString as string
package/src/tools/git.ts CHANGED
@@ -20,13 +20,14 @@ import {
20
20
  isSensitive,
21
21
  } from "../policy/jail.ts"
22
22
  import { sanitizeSpawnEnv, scrubSecrets } from "../policy/scrub.ts"
23
- import { requireToolCwd } from "./context.ts"
23
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
24
24
 
25
25
  function runGit(
26
26
  args: string[],
27
27
  cwd: string | undefined,
28
28
  signal: AbortSignal,
29
29
  envPatch?: Record<string, string>,
30
+ relaxed = false,
30
31
  ): Promise<string> {
31
32
  return new Promise((resolve, reject) => {
32
33
  // Audit #10 P0: SEMUA pemanggilan git lewat sini membawa netralisasi
@@ -36,10 +37,12 @@ function runGit(
36
37
  const p = spawn(resolveTrustedExecutable("git"), [...GIT_SAFE_BASE, ...args], {
37
38
  cwd,
38
39
  // Repo hooks (pre-commit/commit-msg/...) berjalan sebagai child dengan
39
- // env ini — kredensial (API_KEY/TOKEN/...) di-strip agar hook nakal tak
40
+ // Secara default kredensial (API_KEY/TOKEN/...) di-strip agar hook nakal tak
40
41
  // bisa memanen secret dari env. Auth tetap via credential helper / agen
41
42
  // SSH (SSH_AUTH_SOCK bukan pola secret) — lihat policy/scrub.ts.
42
- env: sanitizeSpawnEnv(process.env, envPatch),
43
+ // Unrestricted: kredensial git SEMPIT (GH_TOKEN/GITHUB_TOKEN/SSH_AUTH_SOCK)
44
+ // dilewatkan untuk `git push`/remote.
45
+ env: sanitizeSpawnEnv(process.env, envPatch, relaxed),
43
46
  // Timeout dari LIMITS, bukan hardcode: `git_commit` menjalankan beberapa
44
47
  // operasi berurutan (rev-parse → add → commit → log), dan di mesin yang
45
48
  // sibuk (mis. CI menjalankan test dengan coverage) spawn git bisa jauh
@@ -102,8 +105,8 @@ async function withGitCommitLock<T>(cwd: string, operation: () => Promise<T>): P
102
105
  }
103
106
 
104
107
  /** cwd tool harus di dalam workspace — sama seperti bash/glob/grep. */
105
- function assertCwd(cwd: string | undefined, sessionRoot: string): void {
106
- if (!cwd) return
108
+ function assertCwd(cwd: string | undefined, sessionRoot: string, relaxed = false): void {
109
+ if (!cwd || relaxed) return
107
110
  const abs = resolve(sessionRoot, cwd)
108
111
  if (isCwdOutsideRoot(abs, sessionRoot) || isPathOutsideRoot(abs, sessionRoot)) {
109
112
  throw new Error(`cwd outside workspace: ${cwd}`)
@@ -132,7 +135,7 @@ export const gitStatusTool: Tool = {
132
135
  async execute({ cwd }, ctx) {
133
136
  const c = cwd as string | undefined
134
137
  const sessionRoot = requireToolCwd(ctx)
135
- assertCwd(c, sessionRoot)
138
+ assertCwd(c, sessionRoot, contextUnrestricted(ctx))
136
139
  const resolvedCwd = c ? resolve(sessionRoot, c) : sessionRoot
137
140
  if (!(await isGitRepo(resolvedCwd, ctx.signal))) return "not a git repository"
138
141
  // Audit #10 P0: `git diff` menjalankan clean filter pada berkas dirty
@@ -171,7 +174,7 @@ export const gitDiffTool: Tool = {
171
174
  },
172
175
  async execute({ cwd, staged }, ctx) {
173
176
  const sessionRoot = requireToolCwd(ctx)
174
- assertCwd(cwd as string | undefined, sessionRoot)
177
+ assertCwd(cwd as string | undefined, sessionRoot, contextUnrestricted(ctx))
175
178
  const resolvedCwd = (cwd as string | undefined)
176
179
  ? resolve(sessionRoot, cwd as string)
177
180
  : sessionRoot
@@ -200,7 +203,7 @@ export const gitLogTool: Tool = {
200
203
  },
201
204
  async execute({ cwd, limit }, ctx) {
202
205
  const sessionRoot = requireToolCwd(ctx)
203
- assertCwd(cwd as string | undefined, sessionRoot)
206
+ assertCwd(cwd as string | undefined, sessionRoot, contextUnrestricted(ctx))
204
207
  const resolvedCwd = (cwd as string | undefined)
205
208
  ? resolve(sessionRoot, cwd as string)
206
209
  : sessionRoot
@@ -223,14 +226,19 @@ export const gitLogTool: Tool = {
223
226
  // yang tidak bisa menilai konteksnya.
224
227
 
225
228
  /** Nama file di argumen `paths` harus di dalam workspace. */
226
- function assertPaths(paths: unknown, cwd: string | undefined, sessionRoot: string): string[] {
229
+ function assertPaths(
230
+ paths: unknown,
231
+ cwd: string | undefined,
232
+ sessionRoot: string,
233
+ relaxed = false,
234
+ ): string[] {
227
235
  if (paths == null) return []
228
236
  if (!Array.isArray(paths)) throw new Error("paths must be an array of strings")
229
237
  const root = cwd ? resolve(sessionRoot, cwd) : sessionRoot
230
238
  const out: string[] = []
231
239
  for (const p of paths) {
232
240
  if (typeof p !== "string" || !p.trim()) continue
233
- if (isPathOutsideRoot(p, root) || isRealPathOutsideRoot(p, root))
241
+ if (!relaxed && (isPathOutsideRoot(p, root) || isRealPathOutsideRoot(p, root)))
234
242
  throw new Error(`path outside workspace: ${p}`)
235
243
  const abs = resolve(root, p)
236
244
  if (isSensitive(p) || isSensitive(abs)) throw new Error(`blocked sensitive file: ${p}`)
@@ -267,13 +275,14 @@ export const gitCommitTool: Tool = {
267
275
  ctx.signal.throwIfAborted()
268
276
  const c = cwd as string | undefined
269
277
  const sessionRoot = requireToolCwd(ctx)
270
- assertCwd(c, sessionRoot)
278
+ const relaxed = contextUnrestricted(ctx)
279
+ assertCwd(c, sessionRoot, relaxed)
271
280
  const resolvedCwd = c ? resolve(sessionRoot, c) : sessionRoot
272
281
  const msg = String(message ?? "").trim()
273
282
  if (!msg) throw new Error("message is required")
274
283
  if (msg.length > 4000) throw new Error("message terlalu panjang (max 4000 char)")
275
284
 
276
- const files = assertPaths(paths, c, sessionRoot)
285
+ const files = assertPaths(paths, c, sessionRoot, relaxed)
277
286
  if (files.length === 0 && all !== true) {
278
287
  throw new Error(
279
288
  "provide `paths` (specific files) or `all: true` — an empty commit is useless",
@@ -391,3 +400,52 @@ export const gitCommitTool: Tool = {
391
400
  })
392
401
  },
393
402
  }
403
+
404
+ export const gitPushTool: Tool = {
405
+ name: "git_push",
406
+ description:
407
+ "Push a local branch to a remote (git push; hardened: repo hooks/filters neutralized). Gated like git_commit. In unrestricted mode git credentials (GH_TOKEN/GITHUB_TOKEN/SSH agent) are passed through.",
408
+ parameters: {
409
+ type: "object",
410
+ properties: {
411
+ remote: { type: "string", description: "remote name (default: git config)" },
412
+ branch: { type: "string", description: "branch to push (default: current upstream)" },
413
+ setUpstream: {
414
+ type: "boolean",
415
+ description: "set the pushed branch as the upstream tracking branch (-u)",
416
+ },
417
+ cwd: { type: "string" },
418
+ },
419
+ required: [],
420
+ additionalProperties: false,
421
+ },
422
+ async execute({ remote, branch, setUpstream, cwd }, ctx) {
423
+ ctx.signal.throwIfAborted()
424
+ const c = cwd as string | undefined
425
+ const sessionRoot = requireToolCwd(ctx)
426
+ const relaxed = contextUnrestricted(ctx)
427
+ assertCwd(c, sessionRoot, relaxed)
428
+ const resolvedCwd = c ? resolve(sessionRoot, c) : sessionRoot
429
+ // Tolak nilai berawalan "-" (mis. `--receive-pack=...`): argv diteruskan
430
+ // apa adanya ke git, jadi opsi dari argumen model = eksekusi di remote.
431
+ const refArg = (v: unknown, field: string): string | undefined => {
432
+ const s = typeof v === "string" ? v.trim() : ""
433
+ if (!s) return undefined
434
+ if (s.startsWith("-") || s.includes("\0")) throw new Error(`${field} must not start with '-'`)
435
+ return s
436
+ }
437
+ const remoteName = refArg(remote, "remote")
438
+ const branchName = refArg(branch, "branch")
439
+ if (!(await isGitRepo(resolvedCwd, ctx.signal))) return "not a git repository"
440
+ // Netralisasi hook: pre-push repo tak boleh dieksekusi. Kredensial hanya
441
+ // lewat saat unrestricted (relaxed).
442
+ const neutral = await gitFilterNeutralizers(resolvedCwd)
443
+ const args: string[] = [...neutral, "push"]
444
+ if (remoteName) args.push(remoteName)
445
+ if (branchName) args.push(branchName)
446
+ else if (setUpstream === true) throw new Error("branch is required when setUpstream:true")
447
+ if (setUpstream === true) args.push("--set-upstream")
448
+ const out = await runGit(args, resolvedCwd, ctx.signal, undefined, relaxed)
449
+ return out.trim() || "(push finished)"
450
+ },
451
+ }
package/src/tools/glob.ts CHANGED
@@ -4,7 +4,7 @@ import type { Tool } from "#minicore"
4
4
  import { LIMITS } from "../constants.ts"
5
5
  import { isIgnored, loadIgnoreMatchers } from "../lib/ignore.ts"
6
6
  import { isPathOutsideRoot, isSensitive } from "../policy/jail.ts"
7
- import { requireToolCwd } from "./context.ts"
7
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
8
8
 
9
9
  async function walk(
10
10
  dir: string,
@@ -14,6 +14,7 @@ async function walk(
14
14
  limit: number,
15
15
  signal: AbortSignal,
16
16
  ignoreMatchers: ((rel: string) => boolean)[],
17
+ relaxed = false,
17
18
  ) {
18
19
  if (signal.aborted) throw new Error("aborted")
19
20
  if (out.length >= limit) return
@@ -26,10 +27,15 @@ async function walk(
26
27
  // Hormati .gitignore subset (bukan hard-coded saja).
27
28
  if (isIgnored(rel, ignoreMatchers)) continue
28
29
  if (e.isDirectory()) {
29
- await walk(full, pattern, out, root, limit, signal, ignoreMatchers)
30
+ await walk(full, pattern, out, root, limit, signal, ignoreMatchers, relaxed)
30
31
  } else if (pattern.test(rel) || pattern.test(e.name)) {
31
32
  const real = await realpath(full).catch(() => full)
32
- if (isPathOutsideRoot(real, resolve(root)) || isSensitive(real) || isSensitive(rel)) continue
33
+ if (
34
+ (!relaxed && isPathOutsideRoot(real, resolve(root))) ||
35
+ isSensitive(real) ||
36
+ isSensitive(rel)
37
+ )
38
+ continue
33
39
  out.push(rel)
34
40
  }
35
41
  }
@@ -80,9 +86,11 @@ export const globTool: Tool = {
80
86
  },
81
87
  async execute({ pattern, cwd, limit }, ctx) {
82
88
  const sessionRoot = requireToolCwd(ctx)
89
+ const relaxed = contextUnrestricted(ctx)
83
90
  const rawRoot = (cwd as string) ?? "."
84
91
  const root = resolve(sessionRoot, rawRoot)
85
- if (isPathOutsideRoot(root, sessionRoot)) throw new Error(`cwd outside workspace: ${rawRoot}`)
92
+ if (!relaxed && isPathOutsideRoot(root, sessionRoot))
93
+ throw new Error(`cwd outside workspace: ${rawRoot}`)
86
94
  const rawLim = limit as number | undefined
87
95
  const lim = Number.isFinite(rawLim)
88
96
  ? Math.min(Math.max(Math.floor(rawLim!), 1), LIMITS.SEARCH_MAX_LIMIT)
@@ -90,7 +98,7 @@ export const globTool: Tool = {
90
98
  const re = globToRegExp(pattern as string)
91
99
  const ignoreMatchers = await loadIgnoreMatchers(root)
92
100
  const out: string[] = []
93
- await walk(root, re, out, root, lim, ctx.signal, ignoreMatchers)
101
+ await walk(root, re, out, root, lim, ctx.signal, ignoreMatchers, relaxed)
94
102
  const st = await stat(root).catch(() => null)
95
103
  if (!st) return `cwd not found: ${rawRoot}`
96
104
  if (out.length === 0) return `no files match ${pattern} in ${rawRoot}`
package/src/tools/grep.ts CHANGED
@@ -8,7 +8,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 { requireToolCwd } from "./context.ts"
11
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
12
12
 
13
13
  async function walkGrep(
14
14
  dir: string,
@@ -19,6 +19,7 @@ async function walkGrep(
19
19
  signal: AbortSignal,
20
20
  includeRe?: RegExp | null,
21
21
  ignoreMatchers: ((rel: string) => boolean)[] = [],
22
+ relaxed = false,
22
23
  ) {
23
24
  if (signal.aborted) throw new Error("aborted")
24
25
  if (out.length >= limit) return
@@ -30,20 +31,25 @@ async function walkGrep(
30
31
  const rel = relative(root, full).replace(/\\/g, "/")
31
32
  if (isIgnored(rel, ignoreMatchers)) continue
32
33
  if (e.isDirectory()) {
33
- await walkGrep(full, re, out, root, limit, signal, includeRe, ignoreMatchers)
34
+ await walkGrep(full, re, out, root, limit, signal, includeRe, ignoreMatchers, relaxed)
34
35
  } else {
35
36
  if (includeRe && !includeRe.test(rel) && !includeRe.test(e.name)) continue
36
37
  if (/\.(png|jpg|jpeg|gif|webp|pdf|zip|exe|dll|bin)$/i.test(e.name)) continue
37
38
  // symlink file escape check — resolve realpath and jail
38
39
  const real = await realpath(full).catch(() => full)
39
- if (isPathOutsideRoot(real, resolve(root)) || isSensitive(real) || isSensitive(rel)) continue
40
+ if (
41
+ (!relaxed && isPathOutsideRoot(real, resolve(root))) ||
42
+ isSensitive(real) ||
43
+ isSensitive(rel)
44
+ )
45
+ continue
40
46
  // also skip if symlink points outside (already covered) or sensitive
41
47
  const st = await stat(real).catch(() => null)
42
48
  if (!st || st.size > LIMITS.GREP_FILE_MAX_BYTES) continue
43
49
  // Baca via safeReadFile (O_NOFOLLOW + verifikasi ulang target saat
44
50
  // open): swap symlink antara realpath di atas dan read di bawah tak
45
51
  // lagi bisa menyelundupkan konten luar/sensitif. Gagal = lewati berkas.
46
- const text = (await safeReadFile(real, root).catch(() => null)) ?? ""
52
+ const text = (await safeReadFile(real, root, relaxed).catch(() => null)) ?? ""
47
53
  if (text.includes("\0")) continue
48
54
  const lines = text.split("\n")
49
55
  for (let i = 0; i < lines.length; i++) {
@@ -110,7 +116,7 @@ export function ripgrepAvailable(): boolean {
110
116
  * cap panjang. Return null bila baris harus dibuang (sensitif / tak terparse).
111
117
  * Diekspor untuk test.
112
118
  */
113
- export function normalizeRgLine(line: string, root: string): string | null {
119
+ export function normalizeRgLine(line: string, root: string, relaxed = false): string | null {
114
120
  // path bisa memuat ':' di Windows (C:\...), jadi cari dua ':' terakhir yang
115
121
  // diikuti angka — bukan split(':') naif.
116
122
  const m = /^(.*?):(\d+):(\d+):([\s\S]*)$/.exec(line)
@@ -120,7 +126,7 @@ export function normalizeRgLine(line: string, root: string): string | null {
120
126
  if (!rel) return null
121
127
  // Defense-in-depth: rg sudah dibatasi ke cwd, tapi jail tetap diterapkan
122
128
  // supaya hasil identik dengan fallback (symlink/sensitive tetap dibuang).
123
- if (isPathOutsideRoot(rel, resolve(root)) || isSensitive(rel)) return null
129
+ if ((!relaxed && isPathOutsideRoot(rel, resolve(root))) || isSensitive(rel)) return null
124
130
  const body = text ?? ""
125
131
  const cut = body.length > LIMITS.GREP_MATCH_MAX_CHARS
126
132
  return `${rel}:${lineNo}: ${scrubSecrets(cut ? `${body.slice(0, LIMITS.GREP_MATCH_MAX_CHARS)}…` : body)}`
@@ -132,6 +138,7 @@ function runRipgrep(
132
138
  limit: number,
133
139
  signal: AbortSignal,
134
140
  include?: string,
141
+ relaxed = false,
135
142
  ): Promise<string[]> {
136
143
  const args = [
137
144
  "--no-config", // config ripgrep dapat menjalankan --pre pada berkas workspace
@@ -198,7 +205,7 @@ function runRipgrep(
198
205
  while (idx >= 0) {
199
206
  const line = buf.slice(0, idx).replace(/\r$/, "")
200
207
  buf = buf.slice(idx + 1)
201
- const norm = normalizeRgLine(line, root)
208
+ const norm = normalizeRgLine(line, root, relaxed)
202
209
  if (norm) out.push(norm)
203
210
  if (out.length >= limit) {
204
211
  p.kill("SIGTERM")
@@ -245,9 +252,11 @@ export const grepTool: Tool = {
245
252
  },
246
253
  async execute({ pattern, cwd, include, limit }, ctx) {
247
254
  const sessionRoot = requireToolCwd(ctx)
255
+ const relaxed = contextUnrestricted(ctx)
248
256
  const rawRoot = (cwd as string) ?? "."
249
257
  const root = resolve(sessionRoot, rawRoot)
250
- if (isPathOutsideRoot(root, sessionRoot)) throw new Error(`cwd outside workspace: ${rawRoot}`)
258
+ if (!relaxed && isPathOutsideRoot(root, sessionRoot))
259
+ throw new Error(`cwd outside workspace: ${rawRoot}`)
251
260
  const rawLim = limit as number | undefined
252
261
  const lim = Number.isFinite(rawLim)
253
262
  ? Math.min(Math.max(Math.floor(rawLim!), 1), LIMITS.SEARCH_MAX_LIMIT)
@@ -270,7 +279,14 @@ export const grepTool: Tool = {
270
279
  const want = lim + 1
271
280
  if (process.env.MINICODE_GREP_ENGINE !== "js" && ripgrepAvailable()) {
272
281
  try {
273
- const hits = await runRipgrep(pat, root, want, ctx.signal, include as string | undefined)
282
+ const hits = await runRipgrep(
283
+ pat,
284
+ root,
285
+ want,
286
+ ctx.signal,
287
+ include as string | undefined,
288
+ relaxed,
289
+ )
274
290
  if (hits.length === 0) return noMatch()
275
291
  // runRipgrep tandai timeout via suffix khusus di elemen terakhir (bila timedOut)
276
292
  return withCapMark(hits, lim)
@@ -286,7 +302,7 @@ export const grepTool: Tool = {
286
302
  const incRe = include ? includeToRegExp(include as string) : null
287
303
  const ignoreMatchers = await loadIgnoreMatchers(root)
288
304
  const out: string[] = []
289
- await walkGrep(root, re, out, root, want, ctx.signal, incRe, ignoreMatchers)
305
+ await walkGrep(root, re, out, root, want, ctx.signal, incRe, ignoreMatchers, relaxed)
290
306
  return out.length === 0 ? noMatch() : withCapMark(out, lim)
291
307
  },
292
308
  }
@@ -3,7 +3,7 @@ export { bashKillTool, bashOutputTool, bashTool } from "./bash.ts"
3
3
  export { codeRunTool } from "./code_run.ts"
4
4
  export { deleteFileTool } from "./delete_file.ts"
5
5
  export { editTool } from "./edit.ts"
6
- export { gitCommitTool, gitDiffTool, gitLogTool, gitStatusTool } from "./git.ts"
6
+ export { gitCommitTool, gitDiffTool, gitLogTool, gitPushTool, gitStatusTool } from "./git.ts"
7
7
  export { globTool } from "./glob.ts"
8
8
  export { grepTool } from "./grep.ts"
9
9
  export {
@@ -32,7 +32,7 @@ import { bashKillTool, bashOutputTool, bashTool } from "./bash.ts"
32
32
  import { codeRunTool } from "./code_run.ts"
33
33
  import { deleteFileTool } from "./delete_file.ts"
34
34
  import { editTool } from "./edit.ts"
35
- import { gitCommitTool, gitDiffTool, gitLogTool, gitStatusTool } from "./git.ts"
35
+ import { gitCommitTool, gitDiffTool, gitLogTool, gitPushTool, gitStatusTool } from "./git.ts"
36
36
  import { globTool } from "./glob.ts"
37
37
  import { grepTool } from "./grep.ts"
38
38
  import {
@@ -70,6 +70,7 @@ export const allTools: Tool[] = [
70
70
  gitDiffTool,
71
71
  gitLogTool,
72
72
  gitCommitTool,
73
+ gitPushTool,
73
74
  webFetchTool,
74
75
  webSearchTool,
75
76
  readMemoryTool,
package/src/tools/lsp.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from "../lsp/client.ts"
13
13
  import { isPathOutsideRoot, isRealPathOutsideRoot, isSensitive } from "../policy/jail.ts"
14
14
  import { scrubSecrets } from "../policy/scrub.ts"
15
- import { requireToolCwd } from "./context.ts"
15
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
16
16
 
17
17
  const SEVERITY = ["Error", "Warn", "Info", "Hint"]
18
18
 
@@ -37,16 +37,21 @@ function toUri(abs: string): string {
37
37
  return pathToFileURL(abs).href
38
38
  }
39
39
 
40
- async function readTarget(file: string, cwd: string): Promise<{ abs: string; text: string }> {
41
- if (isPathOutsideRoot(file, cwd)) throw new Error(`path outside workspace: ${file}`)
40
+ async function readTarget(
41
+ file: string,
42
+ cwd: string,
43
+ relaxed = false,
44
+ ): Promise<{ abs: string; text: string }> {
45
+ if (!relaxed && isPathOutsideRoot(file, cwd)) throw new Error(`path outside workspace: ${file}`)
42
46
  if (isSensitive(file)) throw new Error(`blocked sensitive file: ${file}`)
43
47
  const abs = isAbsolute(file) ? resolvePath(file) : resolvePath(cwd, file)
44
- if (isRealPathOutsideRoot(abs, cwd)) throw new Error(`path outside workspace: ${file}`)
48
+ if (!relaxed && isRealPathOutsideRoot(abs, cwd))
49
+ throw new Error(`path outside workspace: ${file}`)
45
50
  // Baca via safeReadFile (O_NOFOLLOW + verifikasi ulang target saat open):
46
51
  // readFile biasa membuka hasil realpath LAMA sehingga swap symlink di
47
52
  // antara cek dan baca lolos + membaca target sensitif. relevan ganda di
48
53
  // jalur MCP yang permission handler-nya minim (tanpa pre-check jail).
49
- const text = await safeReadFile(abs, cwd)
54
+ const text = await safeReadFile(abs, cwd, relaxed)
50
55
  return { abs, text }
51
56
  }
52
57
 
@@ -74,10 +79,11 @@ interface PosArgs {
74
79
  async function resolvePosition(
75
80
  args: PosArgs,
76
81
  cwd: string,
82
+ relaxed = false,
77
83
  ): Promise<{ abs: string; text: string; position: { line: number; character: number } } | string> {
78
84
  if (getConfiguredExts().length === 0)
79
85
  return "(no LSP servers configured — add via minicode config lsp add)"
80
- const { abs, text } = await readTarget(args.file, cwd)
86
+ const { abs, text } = await readTarget(args.file, cwd, relaxed)
81
87
  let position: { line: number; character: number } | null = null
82
88
  if (args.line != null) position = { line: args.line, character: args.character ?? 0 }
83
89
  else if (args.symbol) position = findSymbolPosition(text, args.symbol)
@@ -131,7 +137,7 @@ function posTool(
131
137
  ctx.signal.throwIfAborted()
132
138
  const cwd = requireToolCwd(ctx)
133
139
  try {
134
- const resolved = await resolvePosition(args as PosArgs, cwd)
140
+ const resolved = await resolvePosition(args as PosArgs, cwd, contextUnrestricted(ctx))
135
141
  if (typeof resolved === "string") return resolved
136
142
  const { abs, text, position } = resolved
137
143
  const result = await raceAbort(
@@ -173,7 +179,7 @@ export const lspDiagnosticsTool: Tool = {
173
179
  ctx.signal.throwIfAborted()
174
180
  const cwd = requireToolCwd(ctx)
175
181
  try {
176
- const { abs, text } = await readTarget(String(file), cwd)
182
+ const { abs, text } = await readTarget(String(file), cwd, contextUnrestricted(ctx))
177
183
  const { items } = await raceAbort(lspDiagnostics(abs, text, undefined, cwd), ctx.signal)
178
184
  if (!items.length) return "(no diagnostics)"
179
185
  return scrubSecrets(
@@ -230,7 +236,7 @@ export const lspSymbolsTool: Tool = {
230
236
  ctx.signal.throwIfAborted()
231
237
  const cwd = requireToolCwd(ctx)
232
238
  try {
233
- const { abs, text } = await readTarget(String(file), cwd)
239
+ const { abs, text } = await readTarget(String(file), cwd, contextUnrestricted(ctx))
234
240
  const result = await raceAbort(
235
241
  lspCall(
236
242
  abs,
@@ -3,7 +3,7 @@ import { dirname } from "node:path"
3
3
  import type { Tool } from "#minicore"
4
4
  import { resolveSafePath } from "../lib/safe-open.ts"
5
5
  import { trashFile } from "../lib/trash.ts"
6
- import { requireToolCwd } from "./context.ts"
6
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
7
7
 
8
8
  export const moveFileTool: Tool = {
9
9
  name: "move_file",
@@ -21,16 +21,17 @@ export const moveFileTool: Tool = {
21
21
  async execute({ from, to }, ctx) {
22
22
  ctx.signal.throwIfAborted()
23
23
  const root = requireToolCwd(ctx)
24
+ const relaxed = contextUnrestricted(ctx)
24
25
  const f = from as string
25
26
  const t = to as string
26
27
  // Verifikasi kedua ujung via pemilik tunggal (logis + target nyata) —
27
28
  // detail di safe-open.ts. Beda dengan tool satu-berkas hanya karena
28
29
  // move punya dua ujung; substring pesan ("outside workspace",
29
30
  // "blocked sensitive file") dipertahankan agar test regex tetap hijau.
30
- const { abs: absFrom, real: realFrom } = await resolveSafePath(f, root)
31
+ const { abs: absFrom, real: realFrom } = await resolveSafePath(f, root, relaxed)
31
32
  const st = await stat(realFrom).catch(() => null)
32
33
  if (!st) throw new Error(`source not found: ${f}`)
33
- const { abs: absTo } = await resolveSafePath(t, root)
34
+ const { abs: absTo } = await resolveSafePath(t, root, relaxed)
34
35
  await mkdir(dirname(absTo), { recursive: true, mode: 0o700 }).catch(() => {})
35
36
  // S3 — dest yang sudah ada dibackup ke trash dulu (jangan timpa diam-diam).
36
37
  // absTo sudah terverifikasi nyata oleh resolveSafePath, jadi tak perlu
@@ -3,7 +3,7 @@ import type { Tool } from "#minicore"
3
3
  import { LIMITS } from "../constants.ts"
4
4
  import { atomicWriteText } from "../lib/atomic-write.ts"
5
5
  import { assertSafeWriteTarget, resolveSafePath, safeReadFile } from "../lib/safe-open.ts"
6
- import { requireToolCwd } from "./context.ts"
6
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
7
7
  import { flexibleMatch } from "./edit.ts"
8
8
 
9
9
  // Apply SEARCH/REPLACE block (a la Aider) ke file. Search block harus match
@@ -40,16 +40,17 @@ export const applyPatchTool: Tool = {
40
40
  ctx.signal.throwIfAborted()
41
41
  const p = path as string
42
42
  const root = requireToolCwd(ctx)
43
+ const relaxed = contextUnrestricted(ctx)
43
44
  // Verifikasi path terpusat (logis + target nyata) — detail di safe-open.ts.
44
- const { abs, real: realAbs } = await resolveSafePath(p, root)
45
+ const { abs, real: realAbs } = await resolveSafePath(p, root, relaxed)
45
46
  // Tolak menimpa symlink final (swap antara cek dan tulis gagal tutup).
46
- await assertSafeWriteTarget(abs, root)
47
+ await assertSafeWriteTarget(abs, root, relaxed)
47
48
  const st = await stat(realAbs).catch(() => null)
48
49
  if (!st) throw new Error(`file not found: ${p}`)
49
50
  if (st.size > LIMITS.READ_FILE_MAX_BYTES) throw new Error(`file too large: ${p} (${st.size})`)
50
51
 
51
52
  // Pakai safeReadFile (O_NOFOLLOW) agar swap symlink di antara cek dan baca gagal ELOOP.
52
- let content = await safeReadFile(abs, root)
53
+ let content = await safeReadFile(abs, root, relaxed)
53
54
  const patchList = patches as { search: string; replace: string }[]
54
55
  if (patchList.length > 50) throw new Error(`too many patches: ${patchList.length} (max 50)`)
55
56
  const applied: string[] = []
@@ -4,7 +4,7 @@ import type { Tool } from "#minicore"
4
4
  import { LIMITS } from "../constants.ts"
5
5
  import { safeOpenRead } from "../lib/safe-open.ts"
6
6
  import { scrubSecrets } from "../policy/scrub.ts"
7
- import { requireToolCwd } from "./context.ts"
7
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
8
8
 
9
9
  // defense-in-depth: also jail inside tool (permission layer is primary)
10
10
 
@@ -168,13 +168,14 @@ export const readFileTool: Tool = {
168
168
  ctx.signal.throwIfAborted()
169
169
  const p = path as string
170
170
  const root = requireToolCwd(ctx)
171
+ const relaxed = contextUnrestricted(ctx)
171
172
  const abs = isAbsolute(p) ? resolve(p) : resolve(root, p)
172
173
  // Semua verifikasi path (jail + sensitif + O_NOFOLLOW) terjadi di SATU
173
174
  // titik saat open — detail di safe-open.ts. Tidak ada resolve/stat
174
175
  // terpisah: handle dipakai untuk stat (cap ukuran) lalu baca.
175
176
  let handle: Awaited<ReturnType<typeof safeOpenRead>>["handle"]
176
177
  try {
177
- ;({ handle } = await safeOpenRead(abs, root))
178
+ ;({ handle } = await safeOpenRead(abs, root, relaxed))
178
179
  } catch (e) {
179
180
  // ENOENT → pesan seragam; sisanya (jail/sensitif/ELOOP/raw IO) apa adanya
180
181
  const msg = (e as Error).message ?? ""
@@ -3,7 +3,7 @@ import type { Tool } from "#minicore"
3
3
  import { LIMITS } from "../constants.ts"
4
4
  import { safeOpenRead } from "../lib/safe-open.ts"
5
5
  import { estimateImageTokens } from "../policy/context.ts"
6
- import { requireToolCwd } from "./context.ts"
6
+ import { contextUnrestricted, requireToolCwd } from "./context.ts"
7
7
 
8
8
  // Batas b64 = batas truncate kernel yang sebenarnya: toolResultMaxTokens
9
9
  // (default 4096) × DEFAULT_CHARS_PER_TOKEN (4) = 16.384 chars, dengan margin
@@ -27,13 +27,14 @@ export const readImageTool: Tool = {
27
27
  ctx.signal.throwIfAborted()
28
28
  const p = path as string
29
29
  const root = requireToolCwd(ctx)
30
+ const relaxed = contextUnrestricted(ctx)
30
31
  const abs = isAbsolute(p) ? resolve(p) : resolve(root, p)
31
32
  // TOCTOU-safe: safeOpenRead = realpath(abs) → cek jail+sensitif di dalam
32
33
  // root → open(preReal, O_NOFOLLOW). Bukan open(abs) yang bisa di-swap jadi
33
34
  // symlink luar di antara cek dan open — semua verifikasi ada di titik ini.
34
35
  let handle: Awaited<ReturnType<typeof safeOpenRead>>["handle"]
35
36
  try {
36
- ;({ handle } = await safeOpenRead(abs, root))
37
+ ;({ handle } = await safeOpenRead(abs, root, relaxed))
37
38
  } catch (e) {
38
39
  // ENOENT → pesan seragam; sisanya (jail/sensitif/ELOOP/raw IO) apa adanya
39
40
  const msg = (e as Error).message ?? ""
package/src/tools/task.ts CHANGED
@@ -316,6 +316,7 @@ export const delegateTaskTool: Tool = {
316
316
  "bash_output",
317
317
  "bash_kill",
318
318
  "git_commit",
319
+ "git_push",
319
320
  "submit_result",
320
321
  ].includes(t.name),
321
322
  )