minicode-ai 0.23.0 → 0.26.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 (104) hide show
  1. package/README.md +5 -3
  2. package/cli/commands/config.ts +123 -0
  3. package/cli/setup.ts +107 -8
  4. package/cli/tui.ts +28 -2
  5. package/docs/README.md +2 -2
  6. package/docs/SUMMARY.md +10 -19
  7. package/docs/TERMINAL_CONTRACT.md +113 -28
  8. package/docs/architecture.md +1 -1
  9. package/docs/autonomous-scheduler.md +283 -2
  10. package/docs/choosing-mode.md +4 -4
  11. package/docs/concepts.md +39 -3
  12. package/docs/config.md +103 -5
  13. package/docs/environment.md +4 -0
  14. package/docs/getting-started.md +69 -5
  15. package/docs/repl.md +1 -1
  16. package/docs/security.md +49 -2
  17. package/docs/tools.md +2 -1
  18. package/package.json +2 -36
  19. package/src/app/provider-layer.ts +1 -1
  20. package/src/app/session.ts +187 -17
  21. package/src/config.ts +21 -8
  22. package/src/constants.ts +17 -1
  23. package/src/lib/net.ts +6 -15
  24. package/src/lib/public-http.ts +128 -0
  25. package/src/lib/safe-open.ts +21 -12
  26. package/src/memory/vector.ts +0 -31
  27. package/src/policy/auto-resume.ts +63 -0
  28. package/src/policy/compaction.ts +354 -70
  29. package/src/policy/context-budget.ts +4 -6
  30. package/src/policy/context-window-assign.ts +114 -0
  31. package/src/policy/context-window-catalog.ts +4 -1
  32. package/src/policy/context-window-presets.ts +165 -0
  33. package/src/policy/context-window.ts +19 -37
  34. package/src/policy/context.ts +11 -9
  35. package/src/policy/executor.ts +69 -27
  36. package/src/policy/microcompact.ts +76 -15
  37. package/src/policy/no-progress.ts +1 -1
  38. package/src/policy/permission.ts +5 -0
  39. package/src/policy/recovery-budget.ts +281 -0
  40. package/src/policy/scrub.ts +15 -2
  41. package/src/policy/step-escalation.ts +82 -0
  42. package/src/policy/tokenizer-registry.ts +1 -0
  43. package/src/policy/tool-contract.ts +11 -9
  44. package/src/presentation/reducer.ts +1 -0
  45. package/src/providers/anthropic.ts +3 -3
  46. package/src/providers/detect.ts +40 -7
  47. package/src/providers/provision.ts +23 -1
  48. package/src/runtime/child-execution.ts +4 -2
  49. package/src/runtime/execution-backend.ts +3 -0
  50. package/src/sandbox/os.ts +53 -9
  51. package/src/session/context-assembly.ts +11 -7
  52. package/src/session/persistence.ts +19 -3
  53. package/src/task/autonomous-policy.ts +7 -0
  54. package/src/task/graph-validate.ts +1 -1
  55. package/src/task/session-authority.ts +0 -5
  56. package/src/task/store.ts +0 -4
  57. package/src/tools/ask_user.ts +14 -1
  58. package/src/tools/bash.ts +68 -17
  59. package/src/tools/code_run.ts +19 -20
  60. package/src/tools/context.ts +10 -0
  61. package/src/tools/delete_file.ts +3 -2
  62. package/src/tools/edit.ts +5 -4
  63. package/src/tools/git.ts +70 -12
  64. package/src/tools/glob.ts +13 -5
  65. package/src/tools/grep.ts +26 -10
  66. package/src/tools/index.ts +3 -2
  67. package/src/tools/lsp.ts +15 -9
  68. package/src/tools/move_file.ts +4 -3
  69. package/src/tools/patch.ts +5 -4
  70. package/src/tools/read_file.ts +3 -2
  71. package/src/tools/read_image.ts +3 -2
  72. package/src/tools/task.ts +5 -1
  73. package/src/tools/todo.ts +4 -8
  74. package/src/tools/web_fetch.ts +13 -19
  75. package/src/tools/write_file.ts +4 -3
  76. package/src/ui/approval/prompt.ts +226 -77
  77. package/src/ui/assistant/simple.ts +61 -10
  78. package/src/ui/footer.ts +41 -29
  79. package/src/ui/i18n/en.ts +7 -0
  80. package/src/ui/i18n/id.ts +7 -0
  81. package/src/ui/input/prompt-engine.ts +53 -21
  82. package/src/ui/render/activity-group.ts +9 -0
  83. package/src/ui/render/activity-panel.ts +20 -2
  84. package/src/ui/render/ledger.ts +1 -9
  85. package/src/ui/render/logo.ts +0 -5
  86. package/src/ui/render/markdown-table.ts +0 -3
  87. package/src/ui/render/table-grid.ts +0 -3
  88. package/src/ui/render/theme.ts +31 -5
  89. package/src/ui/runtime/screen.ts +7 -1
  90. package/src/ui/screens/dialog.ts +45 -81
  91. package/src/ui/screens/form.ts +10 -10
  92. package/src/ui/screens/model-manager.ts +7 -10
  93. package/src/ui/screens/picker.ts +8 -11
  94. package/src/ui/screens/provider-manager.ts +9 -13
  95. package/src/ui/tui/app.ts +118 -20
  96. package/src/ui/tui/transcript.ts +179 -29
  97. package/vendor/minicore/src/core/loop.ts +20 -1
  98. package/vendor/minicore/src/core/session.ts +6 -0
  99. package/docs/P14_OPEN_WORK.md +0 -290
  100. package/docs/config-providers.md +0 -87
  101. package/docs/glossary.md +0 -39
  102. package/docs/quickstart.md +0 -60
  103. package/docs/security-model.md +0 -96
  104. package/docs/terminal.md +0 -91
@@ -52,13 +52,15 @@ async function resolveRealOrAncestor(abs: string): Promise<string> {
52
52
  export async function resolveSafePath(
53
53
  p: string,
54
54
  root: string,
55
+ relaxed = false,
55
56
  ): Promise<{ abs: string; real: string }> {
56
- if (isPathOutsideRoot(p, root)) throw new Error(`path outside workspace: ${p}`)
57
+ if (!relaxed && isPathOutsideRoot(p, root)) throw new Error(`path outside workspace: ${p}`)
57
58
  if (isSensitive(p)) throw new Error(`blocked sensitive file: ${p}`)
58
59
  const abs = isAbsolute(p) ? resolve(p) : resolve(root, p)
59
60
  const realRoot = await realpath(root).catch(() => root)
60
61
  const real = await resolveRealOrAncestor(abs)
61
- if (isPathOutsideRoot(real, realRoot)) throw new Error(`symlink points outside workspace: ${p}`)
62
+ if (!relaxed && isPathOutsideRoot(real, realRoot))
63
+ throw new Error(`symlink points outside workspace: ${p}`)
62
64
  if (isSensitive(real)) throw new Error(`blocked sensitive file: ${p}`)
63
65
  return { abs, real }
64
66
  }
@@ -81,11 +83,12 @@ export async function resolveSafePath(
81
83
  export async function safeOpenRead(
82
84
  abs: string,
83
85
  root: string,
86
+ relaxed = false,
84
87
  ): Promise<{ handle: FileHandle; realPath: string }> {
85
88
  const realRoot = await realpath(root).catch(() => root)
86
89
  // Pre-check cepat (fail-fast tanpa open)
87
90
  const preReal = await realpath(abs).catch(() => abs)
88
- if (isPathOutsideRoot(preReal, realRoot))
91
+ if (!relaxed && isPathOutsideRoot(preReal, realRoot))
89
92
  throw new Error(`symlink points outside workspace: ${abs}`)
90
93
  // Sensitif pada target nyata — symlink bernama jinak bisa menunjuk .env;
91
94
  // di sini agar semua pembaca via open (read_file/read_image/stat) mewarisinya.
@@ -96,7 +99,7 @@ export async function safeOpenRead(
96
99
  // keluar sesudah realpath pertama tetapi sebelum open.
97
100
  const expected = await statPath(preReal, { bigint: true })
98
101
  const checkedReal = await realpath(preReal)
99
- if (isPathOutsideRoot(checkedReal, realRoot))
102
+ if (!relaxed && isPathOutsideRoot(checkedReal, realRoot))
100
103
  throw new Error(`symlink points outside workspace: ${abs}`)
101
104
  if (isSensitive(checkedReal)) throw new Error(`blocked sensitive file: ${abs}`)
102
105
  if (expected.ino === 0n)
@@ -137,8 +140,8 @@ export async function safeOpenRead(
137
140
  return { handle, realPath: checkedReal }
138
141
  }
139
142
 
140
- export async function safeReadFile(abs: string, root: string): Promise<string> {
141
- const { handle } = await safeOpenRead(abs, root)
143
+ export async function safeReadFile(abs: string, root: string, relaxed = false): Promise<string> {
144
+ const { handle } = await safeOpenRead(abs, root, relaxed)
142
145
  try {
143
146
  return await handle.readFile("utf8")
144
147
  } finally {
@@ -154,10 +157,11 @@ export async function safeReadFileCapped(
154
157
  abs: string,
155
158
  root: string,
156
159
  maxBytes: number,
160
+ relaxed = false,
157
161
  ): Promise<{ text: string; truncated: boolean }> {
158
162
  if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
159
163
  throw new RangeError("maxBytes must be a positive safe integer")
160
- const { handle } = await safeOpenRead(abs, root)
164
+ const { handle } = await safeOpenRead(abs, root, relaxed)
161
165
  try {
162
166
  const st = await handle.stat()
163
167
  if (!st.isFile()) throw new Error(`refusing to read non-regular file: ${abs}`)
@@ -178,8 +182,8 @@ export async function safeReadFileCapped(
178
182
  }
179
183
  }
180
184
 
181
- export async function safeStat(abs: string, root: string) {
182
- const { handle } = await safeOpenRead(abs, root)
185
+ export async function safeStat(abs: string, root: string, relaxed = false) {
186
+ const { handle } = await safeOpenRead(abs, root, relaxed)
183
187
  try {
184
188
  return await handle.stat()
185
189
  } finally {
@@ -201,17 +205,22 @@ export async function safeStat(abs: string, root: string) {
201
205
  * via isPathOutsideRoot(real) + isSensitive(real), dan cek realpath di
202
206
  * bawah menjaga parent-dir yang di-swap jadi symlink keluar.
203
207
  */
204
- export async function assertSafeWriteTarget(abs: string, root: string): Promise<string> {
208
+ export async function assertSafeWriteTarget(
209
+ abs: string,
210
+ root: string,
211
+ relaxed = false,
212
+ ): Promise<string> {
205
213
  const realRoot = await realpath(root).catch(() => root)
206
214
  const dir = dirname(abs)
207
215
  const realDir = await resolveRealOrAncestor(dir)
208
- if (isPathOutsideRoot(realDir, realRoot)) throw new Error(`parent outside workspace: ${abs}`)
216
+ if (!relaxed && isPathOutsideRoot(realDir, realRoot))
217
+ throw new Error(`parent outside workspace: ${abs}`)
209
218
  const fileReal = await realpath(abs).catch(() => null)
210
219
  // basename (bukan split "/"): path Windows memakai backslash — split "/"
211
220
  // mengembalikan seluruh path absolut sehingga resolve() mengabaikan realDir
212
221
  // dan verifikasi parent symlink gugur diam-diam di Windows.
213
222
  const realAbs = fileReal ?? resolve(realDir, basename(abs))
214
- if (isPathOutsideRoot(realAbs, realRoot))
223
+ if (!relaxed && isPathOutsideRoot(realAbs, realRoot))
215
224
  throw new Error(`symlink points outside workspace: ${abs}`)
216
225
  return realAbs
217
226
  }
@@ -959,37 +959,6 @@ async function syncMemoryFileToSupersession(
959
959
  await files.appendMemory(`[supersession] fact ${oldId} → ${newId} (superseded)`, cwd)
960
960
  }
961
961
 
962
- export async function supersedeMemoryByIds(
963
- oldIds: string[],
964
- newId: string,
965
- cwd?: string,
966
- ): Promise<number> {
967
- let n = 0
968
- const db = open(cwd)
969
- try {
970
- await withBusyRetry(() => {
971
- for (const oldId of oldIds) {
972
- const oldRow = memoryEntryHeadId(db, oldId)
973
- if (oldRow) {
974
- // Tombstone SELURUH entri lama (semua chunk berbagi kepala), bukan
975
- // hanya id chunk yang diberikan (D8: entri bisa diberikan lewat
976
- // chunk mana pun).
977
- db.prepare(`UPDATE memory SET superseded_by = ? WHERE id = ? OR parent = ?`).run(
978
- newId,
979
- oldRow.headId,
980
- oldRow.headId,
981
- )
982
- n++
983
- }
984
- }
985
- db.prepare(`UPDATE memory SET supersedes = ? WHERE id = ?`).run(oldIds.join(","), newId)
986
- })
987
- } finally {
988
- db.close()
989
- }
990
- return n
991
- }
992
-
993
962
  /**
994
963
  * [Fase 8 / 8.1] Rekam pelajaran KANDIDAT (belum terverifikasi).
995
964
  * Pelajaran disimpan `provisional` sehingga retrieval default tidak akan
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Resume turn otomatis setelah turn gagal karena penyedia.
3
+ *
4
+ * ── Kenapa dulu dipisah, sekarang tidak ─────────────────────────────────────
5
+ * Versi pertama modul ini punya angka sendiri (`MAX_AUTO_RESUMES = 2`, jeda
6
+ * 3 dtk + 10 dtk) dan angka itu TERPISAH dari anggaran retry provider. Hasilnya
7
+ * biaya BERKALI: 5 percobaan retry × 3 percobaan turn ≈ 82 detik penundaan untuk
8
+ * provider yang mati permanen, karena tiap resume mengulang seluruh retry dari
9
+ * nol. Itulah *retry amplification* — anti-pattern yang sama yang membuat
10
+ * insiden awal terasa seperti "provider rusak".
11
+ *
12
+ * Karena itu keputusan di sini TIDAK lagi punya angka sendiri: seluruhnya
13
+ * didelegasikan ke {@link planRecovery} di `recovery-budget.ts`, yang memegang
14
+ * SATU anggaran waktu dan SATU kuota percobaan untuk retry provider maupun
15
+ * resume turn. Satu panggilan logis, satu anggaran.
16
+ *
17
+ * Yang tetap milik modul ini hanyalah makna: resume hanya masuk akal bila turn
18
+ * punya prompt untuk dilanjutkan, dan bila kegagalannya memang datang dari
19
+ * penyedia (bukan pagar lokal seperti anggaran biaya atau batas langkah).
20
+ */
21
+
22
+ export {
23
+ type FailureSignal,
24
+ isRecoverable,
25
+ planRecovery,
26
+ RECOVERY_ATTEMPT_QUOTA,
27
+ RECOVERY_BUDGET_MS,
28
+ type RecoveryDecision,
29
+ type RecoveryState,
30
+ type RecoveryStopReason,
31
+ } from "./recovery-budget.ts"
32
+
33
+ import { type FailureSignal, planRecovery, type RecoveryDecision } from "./recovery-budget.ts"
34
+
35
+ /**
36
+ * Putuskan apakah turn yang gagal boleh dicoba ulang otomatis.
37
+ *
38
+ * Kompatibilitas bentuk: `attempt` (jumlah resume yang sudah dilakukan) dipakai
39
+ * menurunkan `attemptsUsed`. Pemanggil yang memegang anggaran lengkap sebaiknya
40
+ * memanggil {@link planRecovery} langsung agar percobaan retry provider ikut
41
+ * terhitung dalam kuota yang sama — itulah inti perbaikannya.
42
+ *
43
+ * @param failure sinyal kegagalan (kategori/kind/abort/Retry-After)
44
+ * @param attempt resume yang sudah dilakukan untuk prompt ini (0 pada kegagalan pertama)
45
+ * @param opts.hasPrompt turn hanya bisa dilanjutkan bila ada prompt
46
+ * @param opts.budgetExhausted anggaran BIAYA model sudah habis (bukan gangguan)
47
+ */
48
+ export function decideAutoResume(
49
+ failure: FailureSignal,
50
+ attempt: number,
51
+ opts: { hasPrompt: boolean; budgetExhausted?: boolean } = { hasPrompt: true },
52
+ ): RecoveryDecision {
53
+ return planRecovery(
54
+ failure,
55
+ // Tanpa konteks waktu, resume dipandang sebagai percobaan tambahan dari nol;
56
+ // pagar waktu tetap berlaku di pemanggil yang memegang jam sebenarnya.
57
+ { startedAtMs: 0, nowMs: 0, attemptsUsed: attempt },
58
+ {
59
+ hasPrompt: opts.hasPrompt,
60
+ costBudgetExhausted: opts.budgetExhausted === true,
61
+ },
62
+ )
63
+ }