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.
Files changed (162) hide show
  1. package/CHANGELOG.md +935 -0
  2. package/LICENSE +21 -0
  3. package/README.md +200 -0
  4. package/cli/args.ts +195 -0
  5. package/cli/auto-update.ts +108 -0
  6. package/cli/commands/auth.ts +166 -0
  7. package/cli/commands/config.ts +382 -0
  8. package/cli/commands/doctor.ts +128 -0
  9. package/cli/commands/exec.ts +179 -0
  10. package/cli/commands/mcp.ts +35 -0
  11. package/cli/commands/memory.ts +107 -0
  12. package/cli/commands/pricing.ts +100 -0
  13. package/cli/commands/providers.ts +162 -0
  14. package/cli/commands/sessions.ts +128 -0
  15. package/cli/commands/skills.ts +61 -0
  16. package/cli/commands/stats.ts +82 -0
  17. package/cli/commands.ts +317 -0
  18. package/cli/index.ts +539 -0
  19. package/cli/model-manager.ts +112 -0
  20. package/cli/provider-manager.ts +111 -0
  21. package/cli/repl.ts +734 -0
  22. package/cli/router.ts +124 -0
  23. package/cli/setup.ts +780 -0
  24. package/cli/wizard.ts +21 -0
  25. package/docs/ARCHITECTURE.html +1222 -0
  26. package/docs/README.md +109 -0
  27. package/docs/architecture.md +44 -0
  28. package/docs/changelog.md +3 -0
  29. package/package.json +91 -0
  30. package/src/agents/pool.ts +43 -0
  31. package/src/app/mentions.ts +50 -0
  32. package/src/app/provider-layer.ts +118 -0
  33. package/src/app/rag-layer.ts +105 -0
  34. package/src/app/session.ts +154 -0
  35. package/src/app/tool-layer.ts +56 -0
  36. package/src/config.ts +372 -0
  37. package/src/constants.ts +119 -0
  38. package/src/hooks/run.ts +89 -0
  39. package/src/lib/atomic-write.ts +88 -0
  40. package/src/lib/db-path.ts +36 -0
  41. package/src/lib/git-hardening.ts +91 -0
  42. package/src/lib/ignore.ts +58 -0
  43. package/src/lib/keystore.ts +202 -0
  44. package/src/lib/net.ts +70 -0
  45. package/src/lib/safe-open.ts +138 -0
  46. package/src/lib/session-id.ts +23 -0
  47. package/src/lib/trash.ts +38 -0
  48. package/src/lib/trusted-exec.ts +81 -0
  49. package/src/lsp/client.ts +395 -0
  50. package/src/mcp/client.ts +400 -0
  51. package/src/mcp/http-transport.ts +344 -0
  52. package/src/mcp/server.ts +538 -0
  53. package/src/mcp/transport.ts +150 -0
  54. package/src/memory/files.ts +159 -0
  55. package/src/memory/vector.ts +775 -0
  56. package/src/policy/allowlist.ts +67 -0
  57. package/src/policy/bash-guard.ts +465 -0
  58. package/src/policy/compaction.ts +271 -0
  59. package/src/policy/context.ts +161 -0
  60. package/src/policy/executor.ts +199 -0
  61. package/src/policy/jail.ts +127 -0
  62. package/src/policy/permission.ts +517 -0
  63. package/src/policy/pricing.ts +336 -0
  64. package/src/policy/ratelimit.ts +54 -0
  65. package/src/policy/sandbox-policy.ts +157 -0
  66. package/src/policy/scrub.ts +138 -0
  67. package/src/policy/update-check.ts +200 -0
  68. package/src/policy/usage.ts +292 -0
  69. package/src/policy/verifier.ts +181 -0
  70. package/src/providers/anthropic.ts +401 -0
  71. package/src/providers/auth-store.ts +139 -0
  72. package/src/providers/build.ts +136 -0
  73. package/src/providers/detect.ts +126 -0
  74. package/src/providers/effort.ts +165 -0
  75. package/src/providers/guards.ts +107 -0
  76. package/src/providers/oauth.ts +326 -0
  77. package/src/providers/presets.ts +122 -0
  78. package/src/providers/provision.ts +298 -0
  79. package/src/providers/responses.ts +371 -0
  80. package/src/providers/router.ts +247 -0
  81. package/src/repo/repomap.ts +470 -0
  82. package/src/sandbox/docker.ts +129 -0
  83. package/src/sandbox/os.ts +193 -0
  84. package/src/session/checkpoint.ts +543 -0
  85. package/src/session/journal.ts +1347 -0
  86. package/src/session/persistence.ts +446 -0
  87. package/src/session/shadow-git.ts +351 -0
  88. package/src/session/turn-marker.ts +118 -0
  89. package/src/skills/loader.ts +117 -0
  90. package/src/telemetry/trace.ts +283 -0
  91. package/src/tools/ask_user.ts +54 -0
  92. package/src/tools/bash.ts +400 -0
  93. package/src/tools/code_run.ts +96 -0
  94. package/src/tools/delete_file.ts +31 -0
  95. package/src/tools/edit.ts +204 -0
  96. package/src/tools/git.ts +301 -0
  97. package/src/tools/glob.ts +90 -0
  98. package/src/tools/grep.ts +281 -0
  99. package/src/tools/hashline.ts +66 -0
  100. package/src/tools/index.ts +103 -0
  101. package/src/tools/lsp.ts +346 -0
  102. package/src/tools/mcp_call.ts +163 -0
  103. package/src/tools/memory.ts +144 -0
  104. package/src/tools/move_file.ts +47 -0
  105. package/src/tools/patch.ts +86 -0
  106. package/src/tools/read_file.ts +130 -0
  107. package/src/tools/read_image.ts +80 -0
  108. package/src/tools/submit_result.ts +49 -0
  109. package/src/tools/task.ts +346 -0
  110. package/src/tools/todo.ts +201 -0
  111. package/src/tools/web_fetch.ts +161 -0
  112. package/src/tools/web_search.ts +156 -0
  113. package/src/tools/write_file.ts +42 -0
  114. package/src/ui/approval/prompt.ts +76 -0
  115. package/src/ui/assistant/simple.ts +568 -0
  116. package/src/ui/assistant/turn-status.ts +303 -0
  117. package/src/ui/contract.ts +55 -0
  118. package/src/ui/footer.ts +105 -0
  119. package/src/ui/input/input.ts +805 -0
  120. package/src/ui/input/prompt-engine.ts +606 -0
  121. package/src/ui/render/collapse.ts +84 -0
  122. package/src/ui/render/detail.ts +24 -0
  123. package/src/ui/render/diff.ts +181 -0
  124. package/src/ui/render/errors.ts +239 -0
  125. package/src/ui/render/format.ts +54 -0
  126. package/src/ui/render/highlight.ts +294 -0
  127. package/src/ui/render/markdown.ts +120 -0
  128. package/src/ui/render/money.ts +12 -0
  129. package/src/ui/render/reasoning.ts +20 -0
  130. package/src/ui/render/sanitize.ts +80 -0
  131. package/src/ui/render/table.ts +88 -0
  132. package/src/ui/render/theme.ts +339 -0
  133. package/src/ui/render/width.ts +256 -0
  134. package/src/ui/render/wrap.ts +120 -0
  135. package/src/ui/runtime/bus-debug.ts +83 -0
  136. package/src/ui/runtime/chrome.ts +301 -0
  137. package/src/ui/runtime/spinner.ts +77 -0
  138. package/src/ui/runtime/statusline.ts +227 -0
  139. package/src/ui/screens/model-manager.ts +434 -0
  140. package/src/ui/screens/overlay.ts +61 -0
  141. package/src/ui/screens/picker.ts +307 -0
  142. package/src/ui/screens/provider-manager.ts +450 -0
  143. package/src/ui/screens/wizard.ts +132 -0
  144. package/vendor/minicore/VENDOR.md +29 -0
  145. package/vendor/minicore/package.json +21 -0
  146. package/vendor/minicore/src/core/budget.ts +26 -0
  147. package/vendor/minicore/src/core/compact.ts +76 -0
  148. package/vendor/minicore/src/core/errors.ts +60 -0
  149. package/vendor/minicore/src/core/events.ts +74 -0
  150. package/vendor/minicore/src/core/executor.ts +139 -0
  151. package/vendor/minicore/src/core/history.ts +32 -0
  152. package/vendor/minicore/src/core/index.ts +42 -0
  153. package/vendor/minicore/src/core/loop.ts +344 -0
  154. package/vendor/minicore/src/core/permission.ts +24 -0
  155. package/vendor/minicore/src/core/provider.ts +39 -0
  156. package/vendor/minicore/src/core/recovery.ts +34 -0
  157. package/vendor/minicore/src/core/session.ts +327 -0
  158. package/vendor/minicore/src/core/snapshot.ts +142 -0
  159. package/vendor/minicore/src/core/tokens.ts +111 -0
  160. package/vendor/minicore/src/core/tool.ts +118 -0
  161. package/vendor/minicore/src/core/types.ts +50 -0
  162. 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
+ }