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
package/README.md CHANGED
@@ -39,9 +39,9 @@ WorkMode controls how the agent works (`DISCUSS`, `PLAN`, or `BUILD`); permissio
39
39
  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
40
 
41
41
  - [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)
42
+ - [Installation](docs/getting-started.md) · [Quickstart](docs/getting-started.md) · [CLI](docs/cli.md) · [TUI](docs/repl.md)
43
43
  - [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)
44
+ - [Security model](docs/security.md) · [Policy and sandbox](docs/policy-sandbox.md)
45
45
  - [Architecture and repository map](docs/architecture.md)
46
46
  - [Contributing](docs/contributing.md) · [Release history](https://github.com/minilabs-id/minicode/releases)
47
47
 
package/cli/commands.ts CHANGED
@@ -238,6 +238,16 @@ function statusLines(ctx: CommandContext): string[] {
238
238
  t("st.output", { v: u.outputTokens.toLocaleString() }),
239
239
  t("st.total", { v: u.totalTokens.toLocaleString() }),
240
240
  t("st.cost", { v: u.cost != null ? formatUsd(u.cost) : "N/A" }),
241
+ // Fase 7 (pengukuran cache): tampilkan hit/read hanya bila ada aktivitas cache —
242
+ // baris nol-byte untuk sesi tanpa caching (clean & minimal).
243
+ ...((u.cacheReadTokens ?? 0) > 0 || (u.cacheWriteTokens ?? 0) > 0
244
+ ? [
245
+ t("st.cache", {
246
+ read: (u.cacheReadTokens ?? 0).toLocaleString(),
247
+ write: (u.cacheWriteTokens ?? 0).toLocaleString(),
248
+ }),
249
+ ]
250
+ : []),
241
251
  t("st.budget", {
242
252
  v: ctx.budgetState(),
243
253
  extra: u.cost == null ? t("st.costUnknown") : "",
package/cli/index.ts CHANGED
@@ -543,6 +543,15 @@ let setupBar: LoadingBar | null = null
543
543
  const setupBarPhases: Record<string, { pct: number; label: MsgKey }> = {
544
544
  "provider-layer": { pct: 55, label: "loading.provider" },
545
545
  "rag-layer": { pct: 75, label: "loading.rag" },
546
+ // Load-histori resume (paling lambat saat repo berhistori banyak) — sekarang
547
+ // ter-instrumentasi via startupPhase di cli/setup.ts sehingga bar TIDAK mandeg
548
+ // diam di 75% selama loadSession/history/projection/select/workspace. Nilai pct
549
+ // hampiran berurutan; di-tune setelah MINICODE_DEBUG_STARTUP=1 diukur di repo besar.
550
+ "resume-session": { pct: 78, label: "loading.session" },
551
+ "resume-history": { pct: 82, label: "loading.session" },
552
+ "resume-projection": { pct: 84, label: "loading.session" },
553
+ "resume-select": { pct: 86, label: "loading.session" },
554
+ "resume-workspace": { pct: 88, label: "loading.session" },
546
555
  "tool-layer": { pct: 90, label: "loading.session" },
547
556
  "kernel-session": { pct: 98, label: "loading.session" },
548
557
  }
@@ -653,6 +662,8 @@ if (enterRepl) {
653
662
  sessionId: ctx.sessionId,
654
663
  model: ctx.modelRef.current ?? "default",
655
664
  totalTokens: u.totalTokens,
665
+ inputTokens: u.inputTokens,
666
+ cacheReadTokens: u.cacheReadTokens,
656
667
  ...(u.cost != null ? { cost: u.cost } : {}),
657
668
  durationMs: Date.now() - replStart,
658
669
  })
package/cli/setup.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  } from "../src/app/session.ts"
14
14
  import { setupToolLayer } from "../src/app/tool-layer.ts"
15
15
  import type { MinicodeConfig } from "../src/config.ts"
16
- import { loadLastModel, localConfigNotice } from "../src/config.ts"
16
+ import { loadLang, loadLastModel, localConfigNotice } from "../src/config.ts"
17
17
  import { LIMITS } from "../src/constants.ts"
18
18
  import { runRunHooks, shouldRunHooks } from "../src/hooks/run.ts"
19
19
  import { homeDir } from "../src/lib/db-path.ts"
@@ -115,10 +115,7 @@ import {
115
115
  runtimeMetadataFromSelection,
116
116
  } from "../src/session/context-adapter.ts"
117
117
  import { type ContextOnlyArtifact, stripContextOnly } from "../src/session/context-assembly.ts"
118
- import {
119
- countDurableCompactions,
120
- deriveFrontierFromDurable,
121
- } from "../src/session/context-identity.ts"
118
+ import { deriveFrontierFromDurable } from "../src/session/context-identity.ts"
122
119
  import {
123
120
  produceSummaryProjection,
124
121
  readConsumableSummaryProjection,
@@ -148,6 +145,7 @@ import {
148
145
  appendPresentationEvents,
149
146
  backfillHistoryEventIds,
150
147
  completeRun,
148
+ countDurableCompactionEvents,
151
149
  createRun,
152
150
  DEFAULT_THREAD_ID,
153
151
  ensureDefaultThread,
@@ -156,6 +154,7 @@ import {
156
154
  listPersistedTurns,
157
155
  loadPresentationEvents,
158
156
  loadSession,
157
+ loadSessionMeta,
159
158
  loadSessionUsageSummary,
160
159
  loadSessionWorkMode,
161
160
  loadThreadHistoryWithSeq,
@@ -963,7 +962,8 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
963
962
  })
964
963
  const sessionId = identity.sid
965
964
  const bootId = identity.bootId
966
- startupWrite(`${c.dim(formatSessionIdentityLine(identity))}\n`)
965
+ // Identitas internal (sid/boot) — hanya --verbose; "resumed session …" sudah human-friendly.
966
+ if (verbose) startupWrite(`${c.dim(formatSessionIdentityLine(identity))}\n`)
967
967
 
968
968
  // P2.2 — admission penulis tunggal. Lease = admission; pagar mutasi =
969
969
  // writer_epoch (CAS di transaksi tulis). Komposisi ini MEMEGANG lease
@@ -985,9 +985,11 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
985
985
  )
986
986
  }
987
987
  }
988
- startupWrite(
989
- `${c.dim(`[writer] admitted sid=${sessionId} boot=${bootId} epoch=${expectedEpoch}${admission.admission.tookOver ? " (takeover)" : ""}${admission.admission.fresh ? " (fresh)" : ""}\n`)}`,
990
- )
988
+ // Lease sukses = internal; hanya --verbose (STALE/lease-lost tetap tampil).
989
+ if (verbose)
990
+ startupWrite(
991
+ `${c.dim(`[writer] admitted sid=${sessionId} boot=${bootId} epoch=${expectedEpoch}${admission.admission.tookOver ? " (takeover)" : ""}${admission.admission.fresh ? " (fresh)" : ""}\n`)}`,
992
+ )
991
993
  // [P14] Adopsi eksplisit berjalan SETELAH admission target (token target
992
994
  // sudah sah) dan SEBELUM turn pertama. Gagal = lepas lease target lalu
993
995
  // lempar error terklasifikasi; jangan pernah meninggalkan target terkunci
@@ -1360,11 +1362,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1360
1362
  `${c.dim(`[thread sid=${sessionId} tid=${defaultThread.thread_id} head=${defaultThread.head_seq}${backfilled > 0 ? ` backfilled=${backfilled}` : ""}]\n`)}`,
1361
1363
  )
1362
1364
  try {
1363
- const prev = loadSession(sessionId, cwd)
1364
- if (prev) {
1365
+ const meta = await startupPhase("resume-session", async () => loadSessionMeta(sessionId, cwd))
1366
+ if (meta) {
1365
1367
  resumeUsageSnapshot = loadSessionUsageSummary(sessionId, cwd)
1366
1368
  }
1367
- if (prev?.messages.length) {
1369
+ // BACA histori SEKALI (dengan seq). loadSessionMeta tidak decode messages,
1370
+ // jadi decode penuh tinggal SATU kali (dulu `loadSession` + `loadThreadHistoryWithSeq`
1371
+ // decode dua kali — akar lemot resume berhistori banyak, lihat audit perf).
1372
+ const rowsForSelector = await startupPhase("resume-history", async () =>
1373
+ loadThreadHistoryWithSeq(sessionId, defaultThread.thread_id, cwd),
1374
+ )
1375
+ if (meta && rowsForSelector.length) {
1368
1376
  // [Fase 4 / LOOP-13, LOOP-INV-16] Kumpulkan snapshot state operasional
1369
1377
  // deterministik dari sumber durable (TaskStore + usage historis) agar
1370
1378
  // header [RUNTIME_STATE_HEADER] ikut ke konteks resume — tak hilang
@@ -1381,7 +1389,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1381
1389
  totalTokens: resumeUsageSnapshot?.totalTokens ?? 0,
1382
1390
  cost: resumeUsageSnapshot?.totalCostUsd,
1383
1391
  }),
1384
- getTurnCount: () => prev.turnCount ?? 0,
1392
+ getTurnCount: () => meta.turnCount ?? 0,
1385
1393
  }
1386
1394
  operationalState = collectOperationalState(
1387
1395
  sessionId,
@@ -1400,16 +1408,15 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1400
1408
  // Batasi histori resume ke batas model, tanpa mengarang overhead.
1401
1409
  // Kernel menghitung system+tools aktual dan memadatkan sebelum request;
1402
1410
  // selector hanya membuang ke budget-tail bila pesan sendiri tak muat.
1403
- const durableEvents = loadPresentationEvents(sessionId, cwd)
1404
- const revision = countDurableCompactions(durableEvents as readonly { type: string }[])
1405
- const rowsForSelector = loadThreadHistoryWithSeq(sessionId, defaultThread.thread_id, cwd)
1411
+ // Hitung revisi kompaksi langsung dari kolom `type` — tanpa memuat +
1412
+ // decode seluruh presentation_events (dulu tarik ratusan ribu baris
1413
+ // hanya untuk menghitung revisi; kini COUNT(*) SQL, lihat audit perf).
1414
+ const revision = countDurableCompactionEvents(sessionId, cwd)
1406
1415
  // P3.4: proyeksi kanonik durable adalah sumber UTAMA untuk selector
1407
1416
  // (cakupan-valid: CURRENT atau STALE berjangkar utuh, P3.0 §8 D6),
1408
1417
  // sehingga `summary-plus-tail` menjadi perilaku produksi nyata.
1409
- const durableProjection = readConsumableSummaryProjection(
1410
- sessionId,
1411
- cwd,
1412
- defaultThread.thread_id,
1418
+ const durableProjection = await startupPhase("resume-projection", async () =>
1419
+ readConsumableSummaryProjection(sessionId, cwd, defaultThread.thread_id),
1413
1420
  )
1414
1421
  const projectionSummary = durableProjection
1415
1422
  const selectedWindow = getContextWindowTokens()
@@ -1425,15 +1432,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1425
1432
  rows: rowsToCanonicalRefs(selectorRows),
1426
1433
  revision,
1427
1434
  })
1428
- const selection = selectContext({
1429
- sessionId,
1430
- threadId: defaultThread.thread_id,
1431
- rows: selectorRows,
1432
- revision,
1433
- ...(projectionSummary ? { projection: projectionSummary } : {}),
1434
- policy: { budgetTokens: messageBudget, estimator: minicodeEstimator },
1435
- canonicalFrontier,
1436
- })
1435
+ const selection = await startupPhase("resume-select", async () =>
1436
+ selectContext({
1437
+ sessionId,
1438
+ threadId: defaultThread.thread_id,
1439
+ rows: selectorRows,
1440
+ revision,
1441
+ ...(projectionSummary ? { projection: projectionSummary } : {}),
1442
+ policy: { budgetTokens: messageBudget, estimator: minicodeEstimator },
1443
+ canonicalFrontier,
1444
+ }),
1445
+ )
1437
1446
  initialMessages = selection.messages as readonly Message[]
1438
1447
  // [Fase 4 / LOOP-13, LOOP-INV-16] Simpan snapshot state operasional
1439
1448
  // deterministik untuk dijadikan header di SYSTEM prompt (buffer kedua):
@@ -1452,14 +1461,14 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1452
1461
  runtimeContextMetadata = runtimeMetadataFromSelection(selection, revision)
1453
1462
  if (selection.contextOnly) {
1454
1463
  contextOnlyArtifact = selection.contextOnly
1455
- contextCanonicalBaseline = prev.messages
1464
+ contextCanonicalBaseline = rowsForSelector.map((r) => r.message)
1456
1465
  }
1457
- resumeTurnCount = prev.turnCount
1466
+ resumeTurnCount = meta.turnCount
1458
1467
  startupConsoleError(
1459
1468
  c.dim(
1460
1469
  // "(N messages)" dipertahankan VERBATIM (kontrak diagnostik yang
1461
1470
  // sudah dipakai test/CLI).
1462
- `[resumed session ${sessionId} (${prev.messages.length} messages)]\n`,
1471
+ `[resumed session ${sessionId} (${rowsForSelector.length} messages)]\n`,
1463
1472
  ),
1464
1473
  )
1465
1474
  // P3.3 — jejak provenance seleksi (baca-saja; tak mengubah perilaku).
@@ -1471,7 +1480,9 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1471
1480
  // P3 — validasi resume: bukan replay buta. Bila workspace berubah
1472
1481
  // sejak checkpoint terakhir (edit manual / run lain), beri tahu —
1473
1482
  // /undo tersedia bila perlu kembali. Best-effort, tak menggagalkan resume.
1474
- const div = await validateResumeWorkspace(cwd ?? ".", sessionId).catch(() => null)
1483
+ const div = await startupPhase("resume-workspace", async () =>
1484
+ validateResumeWorkspace(cwd ?? ".", sessionId).catch(() => null),
1485
+ )
1475
1486
  if (div && div.diverged > 0) {
1476
1487
  startupConsoleError(
1477
1488
  c.yellow(
@@ -1941,6 +1952,9 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1941
1952
 
1942
1953
  let permissions: PermissionControl | undefined
1943
1954
  let noProgressDetector: NoProgressDetector | null = null
1955
+ // Jendela konteks hasil eskalasi adaptif (0 = belum ada). Dipakai /status
1956
+ // untuk menampilkan angka efektif, bukan tebakan awal.
1957
+ const escalatedWindowRef = { current: 0 }
1944
1958
  const effectiveMaxTurns = (() => {
1945
1959
  const raw = (opts as { maxTurns?: number }).maxTurns ?? Number(process.env.MINICODE_MAX_TURNS)
1946
1960
  return typeof raw === "number" && Number.isFinite(raw) && raw >= 1 ? Math.floor(raw) : undefined
@@ -1954,11 +1968,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
1954
1968
  const v = opts.writeConcurrency
1955
1969
  return typeof v === "number" && Number.isFinite(v) && v > 0 ? Math.floor(v) : undefined
1956
1970
  })()
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")
1974
+ setConfigLocale((await loadLang().catch(() => undefined)) ?? null)
1975
+ const sessionLang = currentLocale()
1957
1976
  const session = await startupPhase("kernel-session", () =>
1958
1977
  createMinicodeSession({
1959
1978
  provider: router,
1960
1979
  tools: sessionTools,
1961
1980
  cwd,
1981
+ lang: sessionLang,
1962
1982
  permissionMode,
1963
1983
  restrictBash,
1964
1984
  allowLocalConfig,
@@ -2020,6 +2040,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
2020
2040
  onNoProgress: (detector) => {
2021
2041
  noProgressDetector = detector
2022
2042
  },
2043
+ // Eskalasi jendela konteks: beritahu user secara eksplisit. Tanpa ini,
2044
+ // jendela yang naik otomatis terasa seperti angka ajaib — user perlu tahu
2045
+ // bahwa ada BUKTI overflow dan berapa nilai barunya, agar bisa memutuskan
2046
+ // menyetel `contextWindows` permanen bila perlu.
2047
+ onContextWindowEscalated: (info) => {
2048
+ startupWrite(
2049
+ `${c.yellow(`[context] window raised ${info.fromTokens} → ${info.toTokens} tokens for ${sanitizeAnsi(info.model)} after a verified context overflow (observed ${info.observedTokens}). Set provider.contextWindows to make it permanent.
2050
+ `)}`,
2051
+ )
2052
+ escalatedWindowRef.current = info.toTokens
2053
+ },
2023
2054
  ...(maxSteps ? { maxSteps } : {}),
2024
2055
  ...(keepRecentTurns ? { keepRecentTurns } : {}),
2025
2056
  ...(safeConcurrency ? { concurrency: safeConcurrency } : {}),
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,
@@ -36,7 +37,7 @@ import type { UiBus } from "../src/ui/contract.ts"
36
37
  import { t } from "../src/ui/i18n/locale.ts"
37
38
  import { loadHistory } from "../src/ui/input/input.ts"
38
39
  import { formatUsd } from "../src/ui/render/money.ts"
39
- import { c } from "../src/ui/render/theme.ts"
40
+ import { c, glyphs } from "../src/ui/render/theme.ts"
40
41
  // [Area A · PROMPT 06] State UI milik SESI ini. TUI + printer linier sesi yang
41
42
  // sama berbagi state (satu instance), sesi lain di proses yang sama tak
42
43
  // tersentuh. Absen = instance default (fixture tes partial).
@@ -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(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(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)