minicode-ai 0.9.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +935 -0
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/cli/args.ts +195 -0
- package/cli/auto-update.ts +108 -0
- package/cli/commands/auth.ts +166 -0
- package/cli/commands/config.ts +382 -0
- package/cli/commands/doctor.ts +128 -0
- package/cli/commands/exec.ts +179 -0
- package/cli/commands/mcp.ts +35 -0
- package/cli/commands/memory.ts +107 -0
- package/cli/commands/pricing.ts +100 -0
- package/cli/commands/providers.ts +162 -0
- package/cli/commands/sessions.ts +128 -0
- package/cli/commands/skills.ts +61 -0
- package/cli/commands/stats.ts +82 -0
- package/cli/commands.ts +317 -0
- package/cli/index.ts +539 -0
- package/cli/model-manager.ts +112 -0
- package/cli/provider-manager.ts +111 -0
- package/cli/repl.ts +734 -0
- package/cli/router.ts +124 -0
- package/cli/setup.ts +780 -0
- package/cli/wizard.ts +21 -0
- package/docs/ARCHITECTURE.html +1222 -0
- package/docs/README.md +109 -0
- package/docs/architecture.md +44 -0
- package/docs/changelog.md +3 -0
- package/package.json +91 -0
- package/src/agents/pool.ts +43 -0
- package/src/app/mentions.ts +50 -0
- package/src/app/provider-layer.ts +118 -0
- package/src/app/rag-layer.ts +105 -0
- package/src/app/session.ts +154 -0
- package/src/app/tool-layer.ts +56 -0
- package/src/config.ts +372 -0
- package/src/constants.ts +119 -0
- package/src/hooks/run.ts +89 -0
- package/src/lib/atomic-write.ts +88 -0
- package/src/lib/db-path.ts +36 -0
- package/src/lib/git-hardening.ts +91 -0
- package/src/lib/ignore.ts +58 -0
- package/src/lib/keystore.ts +202 -0
- package/src/lib/net.ts +70 -0
- package/src/lib/safe-open.ts +138 -0
- package/src/lib/session-id.ts +23 -0
- package/src/lib/trash.ts +38 -0
- package/src/lib/trusted-exec.ts +81 -0
- package/src/lsp/client.ts +395 -0
- package/src/mcp/client.ts +400 -0
- package/src/mcp/http-transport.ts +344 -0
- package/src/mcp/server.ts +538 -0
- package/src/mcp/transport.ts +150 -0
- package/src/memory/files.ts +159 -0
- package/src/memory/vector.ts +775 -0
- package/src/policy/allowlist.ts +67 -0
- package/src/policy/bash-guard.ts +465 -0
- package/src/policy/compaction.ts +271 -0
- package/src/policy/context.ts +161 -0
- package/src/policy/executor.ts +199 -0
- package/src/policy/jail.ts +127 -0
- package/src/policy/permission.ts +517 -0
- package/src/policy/pricing.ts +336 -0
- package/src/policy/ratelimit.ts +54 -0
- package/src/policy/sandbox-policy.ts +157 -0
- package/src/policy/scrub.ts +138 -0
- package/src/policy/update-check.ts +200 -0
- package/src/policy/usage.ts +292 -0
- package/src/policy/verifier.ts +181 -0
- package/src/providers/anthropic.ts +401 -0
- package/src/providers/auth-store.ts +139 -0
- package/src/providers/build.ts +136 -0
- package/src/providers/detect.ts +126 -0
- package/src/providers/effort.ts +165 -0
- package/src/providers/guards.ts +107 -0
- package/src/providers/oauth.ts +326 -0
- package/src/providers/presets.ts +122 -0
- package/src/providers/provision.ts +298 -0
- package/src/providers/responses.ts +371 -0
- package/src/providers/router.ts +247 -0
- package/src/repo/repomap.ts +470 -0
- package/src/sandbox/docker.ts +129 -0
- package/src/sandbox/os.ts +193 -0
- package/src/session/checkpoint.ts +543 -0
- package/src/session/journal.ts +1347 -0
- package/src/session/persistence.ts +446 -0
- package/src/session/shadow-git.ts +351 -0
- package/src/session/turn-marker.ts +118 -0
- package/src/skills/loader.ts +117 -0
- package/src/telemetry/trace.ts +283 -0
- package/src/tools/ask_user.ts +54 -0
- package/src/tools/bash.ts +400 -0
- package/src/tools/code_run.ts +96 -0
- package/src/tools/delete_file.ts +31 -0
- package/src/tools/edit.ts +204 -0
- package/src/tools/git.ts +301 -0
- package/src/tools/glob.ts +90 -0
- package/src/tools/grep.ts +281 -0
- package/src/tools/hashline.ts +66 -0
- package/src/tools/index.ts +103 -0
- package/src/tools/lsp.ts +346 -0
- package/src/tools/mcp_call.ts +163 -0
- package/src/tools/memory.ts +144 -0
- package/src/tools/move_file.ts +47 -0
- package/src/tools/patch.ts +86 -0
- package/src/tools/read_file.ts +130 -0
- package/src/tools/read_image.ts +80 -0
- package/src/tools/submit_result.ts +49 -0
- package/src/tools/task.ts +346 -0
- package/src/tools/todo.ts +201 -0
- package/src/tools/web_fetch.ts +161 -0
- package/src/tools/web_search.ts +156 -0
- package/src/tools/write_file.ts +42 -0
- package/src/ui/approval/prompt.ts +76 -0
- package/src/ui/assistant/simple.ts +568 -0
- package/src/ui/assistant/turn-status.ts +303 -0
- package/src/ui/contract.ts +55 -0
- package/src/ui/footer.ts +105 -0
- package/src/ui/input/input.ts +805 -0
- package/src/ui/input/prompt-engine.ts +606 -0
- package/src/ui/render/collapse.ts +84 -0
- package/src/ui/render/detail.ts +24 -0
- package/src/ui/render/diff.ts +181 -0
- package/src/ui/render/errors.ts +239 -0
- package/src/ui/render/format.ts +54 -0
- package/src/ui/render/highlight.ts +294 -0
- package/src/ui/render/markdown.ts +120 -0
- package/src/ui/render/money.ts +12 -0
- package/src/ui/render/reasoning.ts +20 -0
- package/src/ui/render/sanitize.ts +80 -0
- package/src/ui/render/table.ts +88 -0
- package/src/ui/render/theme.ts +339 -0
- package/src/ui/render/width.ts +256 -0
- package/src/ui/render/wrap.ts +120 -0
- package/src/ui/runtime/bus-debug.ts +83 -0
- package/src/ui/runtime/chrome.ts +301 -0
- package/src/ui/runtime/spinner.ts +77 -0
- package/src/ui/runtime/statusline.ts +227 -0
- package/src/ui/screens/model-manager.ts +434 -0
- package/src/ui/screens/overlay.ts +61 -0
- package/src/ui/screens/picker.ts +307 -0
- package/src/ui/screens/provider-manager.ts +450 -0
- package/src/ui/screens/wizard.ts +132 -0
- package/vendor/minicore/VENDOR.md +29 -0
- package/vendor/minicore/package.json +21 -0
- package/vendor/minicore/src/core/budget.ts +26 -0
- package/vendor/minicore/src/core/compact.ts +76 -0
- package/vendor/minicore/src/core/errors.ts +60 -0
- package/vendor/minicore/src/core/events.ts +74 -0
- package/vendor/minicore/src/core/executor.ts +139 -0
- package/vendor/minicore/src/core/history.ts +32 -0
- package/vendor/minicore/src/core/index.ts +42 -0
- package/vendor/minicore/src/core/loop.ts +344 -0
- package/vendor/minicore/src/core/permission.ts +24 -0
- package/vendor/minicore/src/core/provider.ts +39 -0
- package/vendor/minicore/src/core/recovery.ts +34 -0
- package/vendor/minicore/src/core/session.ts +327 -0
- package/vendor/minicore/src/core/snapshot.ts +142 -0
- package/vendor/minicore/src/core/tokens.ts +111 -0
- package/vendor/minicore/src/core/tool.ts +118 -0
- package/vendor/minicore/src/core/types.ts +50 -0
- package/vendor/minicore/src/providers/openai-compat.ts +366 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { appendFile, mkdir, readFile, stat } from "node:fs/promises"
|
|
2
|
+
import { homedir } from "node:os"
|
|
3
|
+
import { dirname, join, resolve } from "node:path"
|
|
4
|
+
import { LIMITS } from "../constants.ts"
|
|
5
|
+
import { homeDir } from "../lib/db-path.ts"
|
|
6
|
+
import { isRealPathOutsideRoot } from "../policy/jail.ts"
|
|
7
|
+
import { scrubSecrets } from "../policy/scrub.ts"
|
|
8
|
+
|
|
9
|
+
function tildePath(p: string): string {
|
|
10
|
+
const home = homedir()
|
|
11
|
+
return p.startsWith(home) ? `~${p.slice(home.length)}` : p
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Jalur global DIHITUNG per panggil (bukan const modul): homeDir() hormat
|
|
15
|
+
// MINICODE_HOME saat runtime (hermetic test + XDG-ish, sama seperti DB).
|
|
16
|
+
// Const modul akan membekukan home saat import pertama (audit 2026-09-16 M4).
|
|
17
|
+
const globalMemPath = (): string => join(homeDir(), ".minicode", "MEMORY.md")
|
|
18
|
+
const LOCAL_MEM = ".minicode/MEMORY.md"
|
|
19
|
+
const ROOT_MEM = "MEMORY.md"
|
|
20
|
+
// Claude-like hierarchy extensions
|
|
21
|
+
const CLAUDE_MEM = "CLAUDE.md"
|
|
22
|
+
|
|
23
|
+
export async function loadMemoryFiles(cwd = process.cwd()): Promise<string> {
|
|
24
|
+
const parts: string[] = []
|
|
25
|
+
const globalMem = globalMemPath()
|
|
26
|
+
// Hierarchy: global → local → root → CLAUDE compat → rules/
|
|
27
|
+
const candidates = [
|
|
28
|
+
globalMem,
|
|
29
|
+
resolve(cwd, LOCAL_MEM),
|
|
30
|
+
resolve(cwd, ROOT_MEM),
|
|
31
|
+
resolve(cwd, CLAUDE_MEM),
|
|
32
|
+
]
|
|
33
|
+
for (const p of candidates) {
|
|
34
|
+
try {
|
|
35
|
+
// Symlink escape (temuan audit #06): kandidat fixed-name bisa berupa
|
|
36
|
+
// symlink keluar workspace. globalMem (home) sengaja dikecualikan —
|
|
37
|
+
// di luar cwd by design. Samakan rules/ di bawah ke realpath.
|
|
38
|
+
if (p !== globalMem && isRealPathOutsideRoot(p, cwd)) continue
|
|
39
|
+
const txt = await readFile(p, "utf8")
|
|
40
|
+
if (txt.trim()) parts.push(`# ${tildePath(p)}\n${scrubSecrets(txt.slice(0, 6000))}`)
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
// Load .minicode/rules/*.md (Kiro steering style)
|
|
44
|
+
try {
|
|
45
|
+
const { readdir } = await import("node:fs/promises")
|
|
46
|
+
const rulesDir = resolve(cwd, ".minicode/rules")
|
|
47
|
+
const entries = await readdir(rulesDir).catch(() => [] as string[])
|
|
48
|
+
// entries may be string[] or Dirent — handle both
|
|
49
|
+
const files: string[] =
|
|
50
|
+
Array.isArray(entries) && typeof entries[0] === "string"
|
|
51
|
+
? (entries as string[]).filter((f) => f.endsWith(".md")).slice(0, 10)
|
|
52
|
+
: (entries as unknown as import("node:fs").Dirent[])
|
|
53
|
+
.filter((e) => e.isFile() && e.name.endsWith(".md"))
|
|
54
|
+
.map((e) => e.name)
|
|
55
|
+
.slice(0, 10)
|
|
56
|
+
for (const f of files) {
|
|
57
|
+
try {
|
|
58
|
+
const full = join(rulesDir, f as string)
|
|
59
|
+
if (isRealPathOutsideRoot(full, cwd)) continue
|
|
60
|
+
const txt = await readFile(full, "utf8")
|
|
61
|
+
if (txt.trim()) parts.push(`# rules/${f}\n${scrubSecrets(txt.slice(0, 3000))}`)
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
} catch {}
|
|
65
|
+
return parts.join("\n\n")
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const MAX_MEMORY_FILE_BYTES = LIMITS.MEMORY_FILE_MAX_BYTES
|
|
69
|
+
|
|
70
|
+
// Kunci in-process per berkas (audit #09 P1): appendMemory (append +
|
|
71
|
+
// truncate-guard read-modify-write) dan deleteMemoryLines (read-filter-write)
|
|
72
|
+
// tanpa ini saling menelan — reproducer: forget vs 20 append konkuren →
|
|
73
|
+
// 0/20 selamat. Baca (loadMemoryFiles) sengaja tanpa lock: append O_APPEND
|
|
74
|
+
// atomik sehingga baca basi/robek sesaat tak berbahaya untuk retrieval.
|
|
75
|
+
const memLocks = new Map<string, Promise<void>>()
|
|
76
|
+
|
|
77
|
+
async function withMemLock<T>(path: string, fn: () => Promise<T>): Promise<T> {
|
|
78
|
+
const prev = memLocks.get(path) ?? Promise.resolve()
|
|
79
|
+
let release!: () => void
|
|
80
|
+
const next = new Promise<void>((res) => (release = res))
|
|
81
|
+
memLocks.set(
|
|
82
|
+
path,
|
|
83
|
+
prev.then(() => next),
|
|
84
|
+
)
|
|
85
|
+
await prev
|
|
86
|
+
try {
|
|
87
|
+
return await fn()
|
|
88
|
+
} finally {
|
|
89
|
+
release()
|
|
90
|
+
if (memLocks.get(path) === next) memLocks.delete(path)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function appendMemory(text: string, cwd = process.cwd()): Promise<string> {
|
|
95
|
+
const path = resolve(cwd, LOCAL_MEM)
|
|
96
|
+
return withMemLock(path, async () => {
|
|
97
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 }).catch(() => {})
|
|
98
|
+
const clean = scrubSecrets(text.trim().slice(0, 1000))
|
|
99
|
+
const entry = `- ${new Date().toISOString().slice(0, 10)} ${clean}\n`
|
|
100
|
+
// atomic append — no read+write race
|
|
101
|
+
await appendFile(path, entry, "utf8").catch(async () => {
|
|
102
|
+
// fallback if file not exists
|
|
103
|
+
await mkdir(dirname(path), { recursive: true })
|
|
104
|
+
await appendFile(path, entry, "utf8")
|
|
105
|
+
})
|
|
106
|
+
// size guard: truncate oldest if too large (keep last 150k)
|
|
107
|
+
try {
|
|
108
|
+
const st = await stat(path)
|
|
109
|
+
if (st.size > MAX_MEMORY_FILE_BYTES) {
|
|
110
|
+
const txt = await readFile(path, "utf8")
|
|
111
|
+
const keep = txt.slice(-LIMITS.MEMORY_TRUNCATE_KEEP_BYTES)
|
|
112
|
+
const cut = keep.indexOf("\n")
|
|
113
|
+
await import("node:fs/promises").then((m) =>
|
|
114
|
+
m.writeFile(path, cut >= 0 ? keep.slice(cut + 1) : keep, "utf8"),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
} catch {}
|
|
118
|
+
return path
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function readMemoryFile(cwd = process.cwd()): Promise<string> {
|
|
123
|
+
return await loadMemoryFiles(cwd)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Hapus baris MEMORY.md lokal + global yang cocok query (temuan audit #06,
|
|
128
|
+
* diperluas audit 2026-09-16 M4).
|
|
129
|
+
*
|
|
130
|
+
* forget_memory sebelumnya hanya menghapus baris vector — entri file
|
|
131
|
+
* (sumber `file hits:` di read_memory) bertahan selamanya sehingga "lupa"
|
|
132
|
+
* tidak pernah benar-benar terjadi di jalur file. Perluasan M4: read_memory
|
|
133
|
+
* membaca hierarki lokal DAN global (loadMemoryFiles), jadi hapus lokal saja
|
|
134
|
+
* tak tuntas — baris global yang cocok ikut dihapus. Pencocokan sama persis
|
|
135
|
+
* dengan jalur baca (substring case-insensitive) agar hapus-menemukan apa
|
|
136
|
+
* yang baca-temukan.
|
|
137
|
+
*/
|
|
138
|
+
export async function deleteMemoryLines(query: string, cwd = process.cwd()): Promise<number> {
|
|
139
|
+
const q = query.trim().toLowerCase()
|
|
140
|
+
if (!q) return 0
|
|
141
|
+
let total = 0
|
|
142
|
+
for (const path of [resolve(cwd, LOCAL_MEM), globalMemPath()]) {
|
|
143
|
+
total += await withMemLock(path, async () => {
|
|
144
|
+
let txt: string
|
|
145
|
+
try {
|
|
146
|
+
txt = await readFile(path, "utf8")
|
|
147
|
+
} catch {
|
|
148
|
+
return 0
|
|
149
|
+
}
|
|
150
|
+
const kept = txt.split("\n").filter((l) => !l.toLowerCase().includes(q))
|
|
151
|
+
const deleted = txt.split("\n").length - kept.length
|
|
152
|
+
if (deleted === 0) return 0
|
|
153
|
+
const { atomicWriteText } = await import("../lib/atomic-write.ts")
|
|
154
|
+
await atomicWriteText(path, kept.join("\n"))
|
|
155
|
+
return deleted
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
return total
|
|
159
|
+
}
|