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
package/README.md CHANGED
@@ -9,10 +9,12 @@ Interactive sessions run as a fullscreen TUI; one-shot and automation runs flow
9
9
  Requires Bun >=1.1.13 for development, local execution, and the published CLI:
10
10
 
11
11
  ```bash
12
- npm install -g minicode-ai
12
+ bun add -g minicode-ai
13
13
  minicode
14
14
  ```
15
15
 
16
+ `npm install -g minicode-ai` installs the same binary if you prefer npm.
17
+
16
18
  To run from a clone:
17
19
 
18
20
  ```bash
@@ -39,9 +41,9 @@ WorkMode controls how the agent works (`DISCUSS`, `PLAN`, or `BUILD`); permissio
39
41
  The full manual lives in [`docs/`](docs/) and is rendered at [minilabs.id/projects/minicode/docs](https://minilabs.id/projects/minicode/docs/). Quick links:
40
42
 
41
43
  - [Documentation index](docs/README.md) and [full navigation](docs/SUMMARY.md)
42
- - [Installation](docs/getting-started.md) · [Quickstart](docs/quickstart.md) · [CLI](docs/cli.md) · [TUI](docs/repl.md)
44
+ - [Installation](docs/getting-started.md) · [Quickstart](docs/getting-started.md) · [CLI](docs/cli.md) · [TUI](docs/repl.md)
43
45
  - [Configuration and providers](docs/config.md) · [Environment variables](docs/environment.md) · [Tools](docs/tools.md)
44
- - [Security model](docs/security-model.md) · [Policy and sandbox](docs/policy-sandbox.md)
46
+ - [Security model](docs/security.md) · [Policy and sandbox](docs/policy-sandbox.md)
45
47
  - [Architecture and repository map](docs/architecture.md)
46
48
  - [Contributing](docs/contributing.md) · [Release history](https://github.com/minilabs-id/minicode/releases)
47
49
 
@@ -10,6 +10,10 @@ import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
10
10
  import { renderTable } from "../../src/ui/render/table.ts"
11
11
  import { c, glyphs } from "../../src/ui/render/theme.ts"
12
12
 
13
+ // Akhiran baris untuk tabel yang dicetak bersama judul. Konstanta bernama
14
+ // (bukan `"\n"` lepas) supaya tidak tertukar dengan escape di template literal.
15
+ const NEWLINE = "\n"
16
+
13
17
  // Help kontekstual per subcommand. Sebelumnya ketiga cabang ini mencetak HELP
14
18
  // global 45 baris dan exit 0 — user tidak tahu apa yang salah dan skrip tidak
15
19
  // bisa mendeteksi kegagalan.
@@ -19,6 +23,10 @@ const CONFIG_HELP = `minicode config — provider, MCP, and LSP
19
23
  minicode config list
20
24
  minicode config remove <id> [--global|--local]
21
25
  minicode config detect --baseUrl <url> --apiKey <key>
26
+ minicode config context-window list all explicit windows
27
+ minicode config context-window <provider> windows of one provider
28
+ minicode config context-window <provider> <model> <v> set (128k, 200k, 1m, 1024x1024)
29
+ minicode config context-window <provider> <model> auto back to auto-detection
22
30
  minicode config set-key <id> [--global|--local] move API key to OS store (DPAPI on Windows)
23
31
  minicode config delete-key <id> forget stored key (provider stays disabled)
24
32
 
@@ -151,6 +159,121 @@ export async function handleConfig(
151
159
  `${c.green(glyphs.check)} Removed provider ${sanitizeAnsiLine(id)} (${!args.includes("--local") ? "global" : "local"})`,
152
160
  )
153
161
  process.exit(0)
162
+ } else if (sub === "context-window") {
163
+ // Jendela konteks MANUAL untuk model yang providernya tidak melaporkan
164
+ // kapasitas. Tanpa ini satu-satunya jalan adalah mengedit JSON dan menebak
165
+ // angka; salah tebak ke atas = request ditolak 400 di tengah turn, ke bawah
166
+ // = kompaksi prematur.
167
+ //
168
+ // Bentuk:
169
+ // minicode config context-window → daftar semua nilai
170
+ // minicode config context-window <provider> → nilai provider itu
171
+ // minicode config context-window <provider> <model> <nilai>
172
+ // minicode config context-window <provider> <model> auto → kembali deteksi
173
+ const pid = positionalArg(args, 2)
174
+ const model = positionalArg(args, 3)
175
+ const value = positionalArg(args, 4)
176
+ const { assignContextWindow, summarizeContextWindows } = await import(
177
+ "../../src/policy/context-window-assign.ts"
178
+ )
179
+ const { describeContextWindow } = await import("../../src/policy/context-window-presets.ts")
180
+ const global = !args.includes("--local")
181
+ const cwdArg = getArg("--cwd")
182
+ // Config dimuat lokal untuk cabang ini: daftar/nilai harus mencerminkan
183
+ // berkas yang benar-benar akan ditulis (global vs lokal), sama seperti
184
+ // cabang `add`/`remove`.
185
+ const cfg = await loadConfig(cwdArg, { allowLocal: allowLocalHere(args) })
186
+
187
+ if (!pid) {
188
+ // Daftar ringkas seluruh provider: model mana yang punya nilai eksplisit.
189
+ const rows = cfg.providers.flatMap((p) =>
190
+ summarizeContextWindows(p).map((w) => ({
191
+ provider: p.id,
192
+ model: w.model === "*" ? c.dim("* (default)") : w.model,
193
+ window: describeContextWindow(w.tokens),
194
+ source: w.source === "user" ? c.cyan("manual") : c.dim(w.source),
195
+ })),
196
+ )
197
+ if (rows.length === 0) {
198
+ console.log(
199
+ `${c.dim("no explicit context windows — all models use automatic detection")}\n` +
200
+ ` ${c.dim("set one: minicode config context-window <provider> <model> 128k")}`,
201
+ )
202
+ process.exit(0)
203
+ }
204
+ console.log(
205
+ `
206
+ ${c.bold("Context windows")}
207
+ ` +
208
+ renderTable(
209
+ [
210
+ { header: "Provider", key: "provider", width: 18 },
211
+ { header: "Model", key: "model", width: 30 },
212
+ { header: "Window", key: "window", width: 10, align: "right" },
213
+ { header: "Origin", key: "source", width: 10 },
214
+ ],
215
+ rows,
216
+ ) +
217
+ NEWLINE,
218
+ )
219
+ process.exit(0)
220
+ }
221
+
222
+ const provider = cfg.providers.find((p) => p.id === pid)
223
+ if (!provider) {
224
+ console.error(`provider ${c.bold(sanitizeAnsiLine(pid))} not found — see: minicode providers`)
225
+ process.exit(1)
226
+ }
227
+
228
+ if (!model || !value) {
229
+ const rows = summarizeContextWindows(provider).map((w) => ({
230
+ model: w.model === "*" ? c.dim("* (default)") : sanitizeAnsiLine(w.model),
231
+ window: describeContextWindow(w.tokens),
232
+ source: w.source === "user" ? c.cyan("manual") : c.dim(w.source),
233
+ }))
234
+ if (rows.length === 0)
235
+ console.log(`${c.dim(`${provider.id}: no explicit windows (automatic detection)`)}`)
236
+ else
237
+ console.log(
238
+ `
239
+ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
240
+ ` +
241
+ renderTable(
242
+ [
243
+ { header: "Model", key: "model", width: 34 },
244
+ { header: "Window", key: "window", width: 10, align: "right" },
245
+ { header: "Origin", key: "source", width: 10 },
246
+ ],
247
+ rows,
248
+ ) +
249
+ NEWLINE,
250
+ )
251
+ console.log(
252
+ ` ${c.dim(
253
+ `set: minicode config context-window ${sanitizeAnsiLine(provider.id)} <model> <128k|1m|1024x1024|auto>`,
254
+ )}`,
255
+ )
256
+ process.exit(0)
257
+ }
258
+
259
+ const outcome = assignContextWindow(provider, model, value)
260
+ if (!outcome.ok) {
261
+ console.error(`${c.red(glyphs.cross ?? "x")} ${outcome.error}`)
262
+ process.exit(1)
263
+ }
264
+ const { saveProvider } = await import("../../src/providers/provision.ts")
265
+ await saveProvider(outcome.provider, { global, ...(cwdArg ? { cwd: cwdArg } : {}) })
266
+ const shown = sanitizeAnsiLine(model)
267
+ const where = global ? "global" : "local"
268
+ if (outcome.tokens === null) {
269
+ console.log(`${c.green(glyphs.check)} ${shown}: back to automatic detection (${where})`)
270
+ } else {
271
+ console.log(
272
+ `${c.green(glyphs.check)} ${shown}: ${describeContextWindow(outcome.tokens)} ` +
273
+ `(${outcome.tokens.toLocaleString("en-US")} tokens) — ${where}`,
274
+ )
275
+ }
276
+ process.exit(0)
154
277
  } else if (sub === "set-key" || sub === "delete-key") {
155
278
  // Pindahkan API key provider dari config plaintext ke penyimpanan OS
156
279
  // (Windows: DPAPI user-scope; selain itu: berkas chmod 600 + peringatan
package/cli/setup.ts CHANGED
@@ -8,7 +8,9 @@ import { createProviderLayer } from "../src/app/provider-layer.ts"
8
8
  import { createRagLayer } from "../src/app/rag-layer.ts"
9
9
  import {
10
10
  createMinicodeSession,
11
+ createRecoveryLedger,
11
12
  type PermissionControl,
13
+ type RecoveryLedger,
12
14
  type WorkModeControl,
13
15
  } from "../src/app/session.ts"
14
16
  import { setupToolLayer } from "../src/app/tool-layer.ts"
@@ -32,6 +34,11 @@ import { loadContextWindowOverlay, resolveContextWindow } from "../src/policy/co
32
34
  import type { NoProgressDetector } from "../src/policy/no-progress.ts"
33
35
  import type { PermissionAsk } from "../src/policy/permission.ts"
34
36
  import type { RateLimiter } from "../src/policy/ratelimit.ts"
37
+ import {
38
+ type FailureSignal,
39
+ planRecovery,
40
+ type RecoveryDecision,
41
+ } from "../src/policy/recovery-budget.ts"
35
42
  import {
36
43
  budgetExceededError,
37
44
  createUsageCollector,
@@ -1261,7 +1268,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1261
1268
  if (!warnedContextModels.has(key)) {
1262
1269
  warnedContextModels.add(key)
1263
1270
  startupWrite(
1264
- `${c.yellow(`[context] no configured window for ${sanitizeAnsi(key)}; using fallback ${resolved.tokens} tokens. Set provider.contextWindows or --context-window for the exact limit.\n`)}`,
1271
+ `${c.yellow(`[context] no configured window for ${sanitizeAnsi(key)}; using fallback ${resolved.tokens} tokens. Set it with: minicode config context-window ${resolved.providerId ?? "<provider>"} ${resolved.model ?? "<model>"} 128k\n`)}`,
1265
1272
  )
1266
1273
  }
1267
1274
  }
@@ -1274,7 +1281,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1274
1281
  if (!warnedCatalogDrift.has(key)) {
1275
1282
  warnedCatalogDrift.add(key)
1276
1283
  startupWrite(
1277
- `${c.yellow(`[context] catalog window ${resolved.drift.catalogTokens} for ${sanitizeAnsi(key)} differs >2x from models.dev (${resolved.drift.overlayTokens}); catalog may be stale — run \`minicode pricing sync\` or set provider.contextWindows.\n`)}`,
1284
+ `${c.yellow(`[context] catalog window ${resolved.drift.catalogTokens} for ${sanitizeAnsi(key)} differs >2x from models.dev (${resolved.drift.overlayTokens}); using ${resolved.tokens} tokens (${resolved.source}). Set provider.contextWindows for an endpoint-specific limit.\n`)}`,
1278
1285
  )
1279
1286
  }
1280
1287
  }
@@ -1968,17 +1975,14 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1968
1975
  const v = opts.writeConcurrency
1969
1976
  return typeof v === "number" && Number.isFinite(v) && v > 0 ? Math.floor(v) : undefined
1970
1977
  })()
1971
- // Muat state.json.lang LEBIH AWAL (tui.ts memuatnya setelah sesi terbangun) agar
1972
- // direktif chat di system prompt ikut pilihan user; resolusi tetap currentLocale().
1973
- const { currentLocale, setConfigLocale } = await import("../src/ui/i18n/locale.ts")
1978
+ // Muat bahasa label UI lebih awal; bahasa balasan mengikuti percakapan pengguna.
1979
+ const { setConfigLocale } = await import("../src/ui/i18n/locale.ts")
1974
1980
  setConfigLocale((await loadLang().catch(() => undefined)) ?? null)
1975
- const sessionLang = currentLocale()
1976
1981
  const session = await startupPhase("kernel-session", () =>
1977
1982
  createMinicodeSession({
1978
1983
  provider: router,
1979
1984
  tools: sessionTools,
1980
1985
  cwd,
1981
- lang: sessionLang,
1982
1986
  permissionMode,
1983
1987
  restrictBash,
1984
1988
  allowLocalConfig,
@@ -2768,13 +2772,108 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
2768
2772
  : deadline.signal
2769
2773
  : signal
2770
2774
  try {
2771
- return await runPromptWithVerifyImpl(p, runSignal)
2775
+ // [T-009 OBSERVATION.md] Resume otomatis untuk kegagalan TRANSIEN.
2776
+ //
2777
+ // KENAPA memakai LEDGER BERSAMA: retry provider (lapisan recovery) dan
2778
+ // resume turn (di sini) adalah dua lapisan. Memberi masing-masing anggaran
2779
+ // sendiri membuat biayanya BERKALI — pola *retry amplification* yang
2780
+ // menahan user ~82 dtk untuk provider yang mati. Satu ledger per prompt
2781
+ // berarti satu anggaran waktu dan satu kuota percobaan dipakai bersama,
2782
+ // sehingga biaya total konstan berapa pun lapisannya.
2783
+ const ledger = createRecoveryLedger()
2784
+ for (;;) {
2785
+ try {
2786
+ return await runPromptWithVerifyImpl(p, runSignal)
2787
+ } catch (error) {
2788
+ const failure = classifyFailure(error, {
2789
+ userAborted: signal?.aborted === true && deadline.signal?.aborted !== true,
2790
+ })
2791
+ const decision = decideTurnResume(failure, ledger, p.trim().length > 0)
2792
+ if (decision.action !== "retry") throw error
2793
+ const secs = (decision.delayMs / 1000).toFixed(1)
2794
+ const left = Math.max(0, Math.round(decision.remainingMs / 1000))
2795
+ process.stderr.write(
2796
+ `[recovery] gangguan penyedia — melanjutkan turn otomatis ` +
2797
+ `(percobaan ${decision.attempt}, jeda ${secs} dtk, sisa anggaran ${left} dtk)
2798
+ `,
2799
+ )
2800
+ await Bun.sleep(decision.delayMs)
2801
+ // Pengguna menekan Ctrl+C saat menunggu: berhenti, jangan lanjut.
2802
+ if (runSignal?.aborted) throw error
2803
+ }
2804
+ }
2772
2805
  } finally {
2773
2806
  deadline.cancel()
2774
2807
  if (activeAgentSessionId === sessionId) activeAgentSessionId = previous ?? null
2775
2808
  }
2776
2809
  }
2777
2810
 
2811
+ /**
2812
+ * Terjemahkan error nyata menjadi `FailureSignal` murni untuk kebijakan.
2813
+ * Kategori provider bisa berada di `cause` (adapter membungkusnya), jadi
2814
+ * rantai cause ditelusuri berbatas — bukan while(true) pada objek asing.
2815
+ */
2816
+ function classifyFailure(error: unknown, opts: { userAborted: boolean }): FailureSignal {
2817
+ let category: string | undefined
2818
+ let kind: string | undefined
2819
+ let retryAfterMs: number | undefined
2820
+ let node: unknown = error
2821
+ for (let depth = 0; depth < 5 && node !== null && node !== undefined; depth++) {
2822
+ if (typeof node !== "object") break
2823
+ const rec = node as {
2824
+ category?: unknown
2825
+ kind?: unknown
2826
+ retryAfterMs?: unknown
2827
+ cause?: unknown
2828
+ }
2829
+ if (typeof rec.category === "string" && category === undefined) category = rec.category
2830
+ if (typeof rec.kind === "string" && kind === undefined) kind = rec.kind
2831
+ if (typeof rec.retryAfterMs === "number" && retryAfterMs === undefined)
2832
+ retryAfterMs = rec.retryAfterMs
2833
+ node = rec.cause
2834
+ }
2835
+ return {
2836
+ ...(category !== undefined ? { category } : {}),
2837
+ ...(kind !== undefined ? { kind } : {}),
2838
+ ...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
2839
+ abortedByUser: opts.userAborted,
2840
+ }
2841
+ }
2842
+
2843
+ /**
2844
+ * Keputusan resume turn, memakai anggaran bersama.
2845
+ *
2846
+ * Saklar `MINICODE_TURN_AUTO_RESUME=0` dipakai tes yang memang menguji jalur
2847
+ * gagal cepat (provider lokal tak terjangkau) dan operator yang ingin
2848
+ * kegagalan provider langsung terlihat tanpa jeda. Default tetap menyala.
2849
+ */
2850
+ function decideTurnResume(
2851
+ failure: FailureSignal,
2852
+ ledger: RecoveryLedger,
2853
+ hasPrompt: boolean,
2854
+ ): RecoveryDecision {
2855
+ if (process.env.MINICODE_TURN_AUTO_RESUME === "0")
2856
+ return { action: "stop", reason: "not-transient" }
2857
+ const next = ledger.nextDelay(failure)
2858
+ if (next !== null)
2859
+ return {
2860
+ action: "retry",
2861
+ attempt: next.attempt,
2862
+ delayMs: next.delayMs,
2863
+ remainingMs: ledger.remainingMs(),
2864
+ }
2865
+ // Kuota/anggaran yang menahan: laporkan alasannya, bukan "not-transient".
2866
+ return planRecovery(
2867
+ failure,
2868
+ {
2869
+ startedAtMs: ledger.startedAtMs,
2870
+ nowMs: Date.now(),
2871
+ attemptsUsed: ledger.attemptsUsed(),
2872
+ },
2873
+ { hasPrompt },
2874
+ )
2875
+ }
2876
+
2778
2877
  async function runPromptWithVerifyImpl(p: string, signal?: AbortSignal): Promise<void> {
2779
2878
  if (signal?.aborted) {
2780
2879
  const reason = signal.reason
package/cli/tui.ts CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  } from "../src/presentation/projection.ts"
27
27
  import { redoLastCheckpoint, undoLastCheckpoint } from "../src/session/checkpoint.ts"
28
28
  import { renderSkill } from "../src/skills/loader.ts"
29
+ import { listBackgroundJobs, onBackgroundJobFinished } from "../src/tools/bash.ts"
29
30
  import {
30
31
  clipboardByteLength,
31
32
  MAX_CLIPBOARD_BYTES,
@@ -193,6 +194,9 @@ export async function runTui(ctx: CliSession): Promise<void> {
193
194
  ui.setMinimizeActivity(true)
194
195
  let warned80 = false
195
196
  let abort: AbortController | null = null
197
+ /** Job background hidup (badge footer). Dihitung dari registry tool bash. */
198
+ const countLiveBackgroundJobs = (): number =>
199
+ listBackgroundJobs().reduce((n, j) => (j.done ? n : n + 1), 0)
196
200
 
197
201
  // Fase 1 perf (butir 2b): `session.contextTokens` adalah getter O(history)
198
202
  // (estimateMessages mengiterasi SELURUH store + estimator per pesan). Footer
@@ -629,7 +633,7 @@ export async function runTui(ctx: CliSession): Promise<void> {
629
633
  // WorkMode EXECUTE (BUILD) agar ceiling DISCUSS/PLAN tak menahan tulis.
630
634
  workModeControl?.setWorkMode("EXECUTE")
631
635
  app.repaint()
632
- transcript.pushInfo([c.warning(`${glyphs.unlock} ${t("tui.unrestrictedOn")}`)])
636
+ transcript.pushInfo([c.warning(`${c.red(glyphs.unlock)} ${t("tui.unrestrictedOn")}`)])
633
637
  return
634
638
  }
635
639
  mode = modeBeforeUnrestricted ?? "auto"
@@ -643,7 +647,7 @@ export async function runTui(ctx: CliSession): Promise<void> {
643
647
  modeBeforeUnrestricted = null
644
648
  workModeBeforeUnrestricted = null
645
649
  app.repaint()
646
- transcript.pushInfo([c.muted(`${glyphs.unlock} ${t("tui.unrestrictedOff", { m: mode })}`)])
650
+ transcript.pushInfo([c.muted(`${glyphs.lock} ${t("tui.unrestrictedOff", { m: mode })}`)])
647
651
  return
648
652
  }
649
653
  if (name === "lang") {
@@ -812,6 +816,9 @@ export async function runTui(ctx: CliSession): Promise<void> {
812
816
  cwd: cwd ?? process.cwd(),
813
817
  context: fmtCtx(getContextTokens()),
814
818
  metrics: fmtUsageMetrics(ctx, getContextTokens()),
819
+ // Jumlah job background hidup — dihitung di sini karena badge footer
820
+ // adalah view murni (src/ui dilarang impor src/ non-UI).
821
+ backgroundJobs: countLiveBackgroundJobs(),
815
822
  },
816
823
  busy,
817
824
  }
@@ -853,12 +860,30 @@ export async function runTui(ctx: CliSession): Promise<void> {
853
860
  // Approval sebagai warga TUI: blok pertanyaan + keputusan tercatat di
854
861
  // transkrip dan terlihat sebelum menjawab (tanpa sink = tulis langsung).
855
862
  const { setApprovalSink } = await import("../src/ui/tui/transcript.ts")
863
+ // Auto-resume sekali per job background (scope "lanjutkan tanpa saya"),
864
+ // bounded: satu resume per id, tak menumpuk walau banyak job selesai.
865
+ const resumedJobs = new Set<string>()
866
+ const autoResumeEnabled = process.env.MINICODE_AUTORESUME_BG !== "0"
867
+ const unsubscribeJobFinished = onBackgroundJobFinished((id, code) => {
868
+ try {
869
+ if (resumedJobs.has(id)) return
870
+ resumedJobs.add(id)
871
+ app.repaint()
872
+ if (!autoResumeEnabled) return
873
+ // Abort-aware: jangan menyela turn berjalan atau memulai saat quitting.
874
+ transcript.pushInfo([c.muted(t("tui.bgFinished", { id, code: code ?? "?" }))])
875
+ if (abort !== null) return
876
+ void runTurn(t("tui.bgFinishedAuto", { id, code: code ?? "?" })).catch(() => {})
877
+ } catch {}
878
+ })
856
879
  try {
857
880
  setApprovalSink({
858
881
  pushBlock: (lines) => transcript.pushInfo(lines),
859
882
  repaint: () => app.repaint(),
860
883
  suspend: () => app.suspend(),
861
884
  resume: () => app.resume(),
885
+ paintRegion: (lines, topRow) => app.paintRegion(lines, topRow),
886
+ clearRegion: () => app.clearRegion(),
862
887
  })
863
888
  const res = await app.run()
864
889
  if (!res.started) {
@@ -874,6 +899,7 @@ export async function runTui(ctx: CliSession): Promise<void> {
874
899
  }
875
900
  } finally {
876
901
  setApprovalSink(null)
902
+ unsubscribeJobFinished()
877
903
  for (const unsub of liveContextUnsubs.splice(0)) {
878
904
  try {
879
905
  unsub()
package/docs/README.md CHANGED
@@ -5,7 +5,7 @@ MiniCode adalah coding agent terminal yang dibangun di atas kernel MiniCore. Jal
5
5
  ## Mulai
6
6
 
7
7
  1. Ikuti [instalasi](getting-started.md). Metadata paket dan batas runtime Bun tersedia di `package.json` pada root repository.
8
- 2. Gunakan [quickstart](quickstart.md) untuk menyiapkan provider dan menjalankan prompt pertama.
8
+ 2. Gunakan [quickstart](getting-started.md) untuk menyiapkan provider dan menjalankan prompt pertama.
9
9
  3. Baca [memilih mode](choosing-mode.md) sebelum memberi agent akses tulis atau eksekusi.
10
10
 
11
11
  ## Batas yang perlu diketahui
@@ -16,7 +16,7 @@ MiniCode adalah coding agent terminal yang dibangun di atas kernel MiniCore. Jal
16
16
 
17
17
  ## Peta dokumentasi
18
18
 
19
- `SUMMARY.md` adalah daftar navigasi; dibaca build minilabs untuk membangun indeks halaman. Versi terbit tersedia di [minilabs.id/projects/minicode/docs](https://minilabs.id/projects/minicode/docs/). [Arsitektur](architecture.md) memuat peta struktur dan alur runtime.
19
+ `SUMMARY.md` adalah daftar navigasi; dibaca build minilabs untuk membangun indeks halaman. Jumlah halaman dijaga kecil dan bebas duplikasi — satu topik, satu halaman. Versi terbit tersedia di [minilabs.id/projects/minicode/docs](https://minilabs.id/projects/minicode/docs/). [Arsitektur](architecture.md) memuat peta struktur dan alur runtime.
20
20
 
21
21
  ## Pengembangan
22
22
 
package/docs/SUMMARY.md CHANGED
@@ -4,11 +4,9 @@
4
4
 
5
5
  ## Memulai
6
6
 
7
- * [Instalasi](getting-started.md)
8
- * [Quickstart 5 menit](quickstart.md)
9
- * [Konsep & Desain](concepts.md)
7
+ * [Instalasi & Quickstart](getting-started.md)
8
+ * [Konsep, Desain & Glosarium](concepts.md)
10
9
  * [Memilih Mode](choosing-mode.md)
11
- * [Glosarium](glossary.md)
12
10
 
13
11
  ## Menggunakan
14
12
 
@@ -18,7 +16,7 @@
18
16
  * [Skills & Hooks](skills.md)
19
17
  * [Pricing & Budget](pricing-budget.md)
20
18
 
21
- ## Kemampuan (tools & integrasi)
19
+ ## Kemampuan
22
20
 
23
21
  * [Tools](tools.md)
24
22
  * [Sub-Agents & Tasks](agents.md)
@@ -26,8 +24,7 @@
26
24
 
27
25
  ## Konfigurasi
28
26
 
29
- * [Config — File & Lokasi Data](config.md)
30
- * [Config & Provider](config-providers.md)
27
+ * [Config & Provider](config.md)
31
28
  * [Environment Variables](environment.md)
32
29
 
33
30
  ## State & Memori
@@ -37,31 +34,25 @@
37
34
 
38
35
  ## Keamanan
39
36
 
40
- * [Security Model](security-model.md) — ancaman & trust boundary
41
- * [Policy & Sandbox](policy-sandbox.md) — mode, guard, sandbox
42
- * [Keamanan](security.md) — mekanisme & bukti pengukuran
43
-
44
- ## Bantuan
45
-
46
- * [Troubleshooting](troubleshooting.md)
37
+ * [Keamanan — mode ancaman & bukti](security.md)
38
+ * [Policy & Sandbox](policy-sandbox.md)
47
39
 
48
40
  ## Eksperimental
49
41
 
50
- * [Autonomous Scheduler](autonomous-scheduler.md)
51
- * [Open Work — Lintas Sesi](P14_OPEN_WORK.md)
42
+ * [Autonomous Scheduler & Open Work](autonomous-scheduler.md)
52
43
 
53
44
  ## Kontributor & Arsitektur
54
45
 
55
46
  * [Arsitektur & Peta Repository](architecture.md)
56
- * [Kontrak Terminal (ringkas)](terminal.md)
57
47
  * [Contributing](contributing.md)
48
+ * [Troubleshooting](troubleshooting.md)
58
49
 
59
50
  ## Spesifikasi internal (FROZEN — untuk kontributor)
60
51
 
61
- * [Terminal Contract - 35 invariant, v7.12](TERMINAL_CONTRACT.md)
52
+ * [Terminal Contract](TERMINAL_CONTRACT.md)
62
53
  * [Output Event Model](OUTPUT_EVENT_MODEL.md)
63
54
  * [Output Protocol Spec](OUTPUT_PROTOCOL_SPEC.md)
64
55
  * [Output Rendering Spec](OUTPUT_RENDERING_SPEC.md)
65
56
  * [Output UX Rules](OUTPUT_UX_RULES.md)
66
57
  * [Control Plane Map](CONTROL-PLANE-MAP.md)
67
- * [UI Render Pipeline](UI_RENDER_PIPELINE.md)
58
+ * [UI Render Pipeline](UI_RENDER_PIPELINE.md)