minicode-ai 0.10.0 → 0.11.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 (128) hide show
  1. package/AGENTS.md +45 -0
  2. package/CHANGELOG.md +59 -4
  3. package/PLAN.md +491 -0
  4. package/README.md +2 -2
  5. package/cli/commands/acp.ts +485 -0
  6. package/cli/commands/auth.ts +7 -4
  7. package/cli/commands/config.ts +41 -27
  8. package/cli/commands/exec.ts +33 -12
  9. package/cli/commands/mcp.ts +3 -2
  10. package/cli/commands/memory.ts +1 -1
  11. package/cli/commands/pricing.ts +6 -4
  12. package/cli/commands/providers.ts +18 -8
  13. package/cli/commands/sessions.ts +11 -4
  14. package/cli/commands/skills.ts +3 -3
  15. package/cli/commands/stats.ts +3 -1
  16. package/cli/commands.ts +6 -0
  17. package/cli/index.ts +82 -57
  18. package/cli/model-manager.ts +6 -1
  19. package/cli/router.ts +7 -0
  20. package/cli/setup.ts +341 -5
  21. package/cli/tui.ts +54 -18
  22. package/docs/ARCHITECTURE.html +29 -22
  23. package/docs/CONTROL-PLANE-MAP.md +139 -0
  24. package/docs/HARNESS.md +150 -0
  25. package/docs/PLAN_UIUX_V6.md +209 -0
  26. package/docs/README.md +1 -1
  27. package/docs/SUMMARY.md +52 -0
  28. package/docs/TERMINAL_CONTRACT.md +367 -0
  29. package/docs/UI_RENDER_PIPELINE.md +165 -0
  30. package/docs/USAGE.md +11 -0
  31. package/docs/agents.md +31 -0
  32. package/docs/architecture.md +3 -3
  33. package/docs/choosing-mode.md +34 -0
  34. package/docs/cli.md +130 -0
  35. package/docs/concepts.md +53 -0
  36. package/docs/config-providers.md +87 -0
  37. package/docs/config.md +63 -0
  38. package/docs/contributing.md +79 -0
  39. package/docs/environment.md +95 -0
  40. package/docs/exec.md +73 -0
  41. package/docs/getting-started.md +102 -0
  42. package/docs/glossary.md +37 -0
  43. package/docs/mcp-lsp.md +54 -0
  44. package/docs/memory-sessions.md +63 -0
  45. package/docs/policy-sandbox.md +72 -0
  46. package/docs/pricing-budget.md +49 -0
  47. package/docs/quickstart.md +60 -0
  48. package/docs/repl.md +67 -0
  49. package/docs/security-model.md +95 -0
  50. package/docs/security.md +91 -0
  51. package/docs/skills.md +48 -0
  52. package/docs/terminal.md +79 -0
  53. package/docs/tools.md +123 -0
  54. package/docs/troubleshooting.md +40 -0
  55. package/docs/verify-benchmark.md +58 -0
  56. package/package.json +8 -5
  57. package/src/app/provider-layer.ts +12 -4
  58. package/src/app/session.ts +6 -0
  59. package/src/app/tool-layer.ts +2 -1
  60. package/src/constants.ts +35 -0
  61. package/src/lib/net.ts +6 -1
  62. package/src/lsp/client.ts +41 -8
  63. package/src/mcp/http-transport.ts +52 -15
  64. package/src/mcp/transport.ts +32 -1
  65. package/src/memory/files.ts +6 -5
  66. package/src/policy/allowlist.ts +1 -1
  67. package/src/policy/bash-guard.ts +154 -14
  68. package/src/policy/compaction.ts +57 -3
  69. package/src/policy/context.ts +4 -0
  70. package/src/policy/jail.ts +49 -4
  71. package/src/policy/permission.ts +152 -12
  72. package/src/policy/pricing.ts +12 -9
  73. package/src/presentation/adapter.ts +721 -0
  74. package/src/presentation/events.ts +324 -0
  75. package/src/presentation/label.ts +140 -0
  76. package/src/presentation/model.ts +172 -0
  77. package/src/presentation/reducer.ts +486 -0
  78. package/src/presentation/store.ts +256 -0
  79. package/src/providers/anthropic.ts +22 -4
  80. package/src/providers/detect.ts +2 -1
  81. package/src/providers/router.ts +13 -0
  82. package/src/repo/repomap.ts +2 -29
  83. package/src/session/checkpoint.ts +27 -9
  84. package/src/session/journal.ts +27 -5
  85. package/src/skills/loader.ts +88 -5
  86. package/src/telemetry/trace.ts +36 -15
  87. package/src/tools/ask_user.ts +73 -4
  88. package/src/tools/bash.ts +15 -17
  89. package/src/tools/glob.ts +10 -11
  90. package/src/tools/lsp.ts +3 -56
  91. package/src/tools/memory.ts +13 -12
  92. package/src/tools/task.ts +1 -0
  93. package/src/ui/approval/prompt.ts +14 -6
  94. package/src/ui/assistant/simple.ts +137 -26
  95. package/src/ui/assistant/turn-status.ts +16 -3
  96. package/src/ui/contract.ts +119 -0
  97. package/src/ui/footer.ts +21 -2
  98. package/src/ui/i18n/en.ts +34 -6
  99. package/src/ui/i18n/id.ts +34 -6
  100. package/src/ui/i18n/locale.ts +3 -1
  101. package/src/ui/input/input.ts +51 -4
  102. package/src/ui/input/prompt-engine.ts +46 -4
  103. package/src/ui/render/collapse.ts +13 -13
  104. package/src/ui/render/diff.ts +7 -2
  105. package/src/ui/render/format.ts +16 -8
  106. package/src/ui/render/highlight.ts +7 -3
  107. package/src/ui/render/markdown.ts +5 -1
  108. package/src/ui/render/sanitize.ts +29 -2
  109. package/src/ui/render/table.ts +8 -5
  110. package/src/ui/render/theme.ts +18 -4
  111. package/src/ui/render/width.ts +89 -10
  112. package/src/ui/runtime/motion.ts +16 -0
  113. package/src/ui/runtime/screen.ts +45 -0
  114. package/src/ui/runtime/spinner.ts +50 -4
  115. package/src/ui/runtime/statusline.ts +50 -1
  116. package/src/ui/screens/form.ts +42 -15
  117. package/src/ui/screens/model-manager.ts +26 -18
  118. package/src/ui/screens/picker.ts +47 -23
  119. package/src/ui/screens/provider-manager.ts +18 -12
  120. package/src/ui/screens/wizard.ts +24 -8
  121. package/src/ui/tui/app.ts +233 -27
  122. package/src/ui/tui/transcript.ts +269 -65
  123. package/vendor/minicore/LICENSE +21 -0
  124. package/vendor/minicore/VENDOR.md +6 -3
  125. package/vendor/minicore/package.json +6 -3
  126. package/vendor/minicore/src/core/loop.ts +12 -2
  127. package/vendor/minicore/src/core/snapshot.ts +4 -0
  128. package/vendor/minicore/src/providers/openai-compat.ts +76 -25
@@ -7,19 +7,20 @@
7
7
  //
8
8
  // Mode compact saja di Fase 1: teks model mengalir, ledger tool satu baris
9
9
  // ` › nama target` (grammar sama dengan REPL), error merah satu baris.
10
- import type { UiBus } from "../contract.ts"
10
+ import type {
11
+ UiBus,
12
+ UiPresentationEvent,
13
+ UiPresentationSnapshot,
14
+ UiToolStatus,
15
+ } from "../contract.ts"
11
16
  import { t } from "../i18n/locale.ts"
12
17
  import { reasoning } from "../render/reasoning.ts"
13
18
  import { sanitizeAnsi, sanitizeAnsiLine } from "../render/sanitize.ts"
14
- import { c } from "../render/theme.ts"
19
+ import { c, glyphs } from "../render/theme.ts"
15
20
  import { chunkByWidth, truncateToWidth } from "../render/width.ts"
16
21
 
17
22
  /** Cap memori: baris logis tertua dibuang diam-diam (kontrak I12). */
18
23
  export const TRANSCRIPT_CAP = 5000
19
- /** Isi tool per section untuk /expand: maks 10 section × 2000 char. */
20
- const EXPAND_MAX_SECTIONS = 10
21
- const EXPAND_MAX_CHARS = 2000
22
-
23
24
  /**
24
25
  * Sink approval TUI: pemilik layar (cli/tui.ts) mendaftarkan transkrip +
25
26
  * repaint + suspend/resume agar prompt persetujuan tercatat di transkrip dan
@@ -46,29 +47,58 @@ export function getApprovalSink(): ApprovalSink | null {
46
47
  return approvalSink
47
48
  }
48
49
 
49
- export interface BufferedSection {
50
- label: string
51
- text: string
50
+ export interface TranscriptMeta {
51
+ seq?: number
52
+ kind: "user" | "assistant" | "activity" | "approval" | "system" | "diagnostic"
53
+ turnId?: number
54
+ toolCallId?: string
55
+ approvalId?: string
56
+ status?: UiToolStatus
57
+ expandRef?: { toolCallId: string; idx: number }
58
+ }
59
+
60
+ export interface TranscriptOptions {
61
+ getSnapshot?: () => UiPresentationSnapshot | null
62
+ onPresentationEvent?: (handler: (event: UiPresentationEvent) => void) => () => void
52
63
  }
53
64
 
54
- function ledgerTarget(args: Record<string, unknown>): string | undefined {
65
+ function targetForFallback(args: Record<string, unknown>): string | undefined {
55
66
  if (typeof args.path === "string" && args.path) return args.path
56
67
  const cmd = args.cmd ?? args.command
57
68
  if (typeof cmd === "string" && cmd) return `$ ${cmd}`
58
69
  return undefined
59
70
  }
60
71
 
72
+ function formatElapsed(ms: number): string {
73
+ const seconds = Math.max(0, Math.floor(ms / 1000))
74
+ if (seconds < 60) return `${seconds}s`
75
+ const minutes = Math.floor(seconds / 60)
76
+ if (minutes < 60) return `${minutes}m${String(seconds % 60).padStart(2, "0")}s`
77
+ return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}m`
78
+ }
79
+
61
80
  export class Transcript {
62
81
  private lines: string[] = []
63
82
  private pending = ""
64
- private sections: BufferedSection[] = []
65
- /** Thinking terakumulasi (tersanitasi). Minimized: penanda hidup + buffer
66
- * /expand; expanded: mengalir redup seperti teks. */
83
+ /** Hitung monotonik baris yang pernah ditambah — basis indikator "baru"
84
+ * yang kebal evict cap 5000 (size() menyusut saat tertua dibuang). */
85
+ private totalAppended = 0
86
+ /** Thinking terakumulasi (tersanitasi). Minimized: penanda hidup;
87
+ * expanded: mengalir redup seperti teks. */
67
88
  private thinkingBuf = ""
68
89
  private thinkingTail = ""
90
+ private meta: TranscriptMeta[] = []
91
+ private evicted = 0
92
+ private hasEvictMarker = false
93
+ private getSnapshot: (() => UiPresentationSnapshot | null) | undefined
94
+ private presentationEvents = false
95
+ private presentationUnsub: (() => void) | null = null
96
+ private presentedTerminals = new Set<string>()
97
+ private summarizedTurns = new Set<number>()
69
98
  private unsubs: (() => void)[] = []
70
99
 
71
- constructor(bus: UiBus) {
100
+ constructor(bus: UiBus, opts: TranscriptOptions = {}) {
101
+ this.getSnapshot = opts.getSnapshot
72
102
  // Gagal subscribe = transcript mati total; biarkan throw (fail-closed).
73
103
  this.unsubs = [
74
104
  bus.on("provider:text", (e: { text: string }) => this.stream(e.text)),
@@ -84,12 +114,18 @@ export class Transcript {
84
114
  this.commit()
85
115
  this.commitThinking()
86
116
  }),
87
- bus.on("execution:completed", (e) => this.ledger(e)),
117
+ bus.on("execution:completed", (e) => {
118
+ if (!this.presentationEvents) this.ledger(e)
119
+ }),
88
120
  bus.on("provider:extension", (e: { kind: string; data: unknown }) => this.extension(e)),
89
121
  bus.on("context:compacted", (e: { reason: string }) =>
90
122
  this.push(c.muted(t("ts.compacted", { reason: sanitizeAnsiLine(e.reason ?? "") }))),
91
123
  ),
92
124
  ]
125
+ if (opts.onPresentationEvent) {
126
+ this.presentationEvents = true
127
+ this.presentationUnsub = opts.onPresentationEvent((event) => this.presentationEvent(event))
128
+ }
93
129
  }
94
130
 
95
131
  /** Teks model mengalir — ditahan sebagai ekor hidup sampai commit. */
@@ -111,46 +147,42 @@ export class Transcript {
111
147
  // Expanded: alir redup per baris (line-buffered, ekor hidup).
112
148
  this.thinkingTail += clean
113
149
  const parts = this.thinkingTail.split("\n")
114
- for (let i = 0; i < parts.length - 1; i++) this.append(c.muted(parts[i] ?? ""))
150
+ for (let i = 0; i < parts.length - 1; i++)
151
+ this.append(c.muted(parts[i] ?? ""), { kind: "diagnostic" })
152
+
115
153
  this.thinkingTail = parts[parts.length - 1] ?? ""
116
154
  } else {
117
- // Minimized: penanda hidup + buffer untuk /expand (cap 20k).
155
+ // Minimized: penanda hidup; isi disimpan di collapsed view linear.
118
156
  this.thinkingBuf = (this.thinkingBuf + clean).slice(-20000)
119
157
  }
120
158
  }
121
159
 
122
- /** Selesaikan fase thinking: minimized → buffer /expand (tanpa baris
123
- * transkrip, tetap bersih); expanded → flush ekor redup. */
160
+ /** Selesaikan fase thinking: minimized → penanda hilang; expanded → flush
161
+ * ekor redup. */
124
162
  private commitThinking(): void {
125
163
  if (this.thinkingTail) {
126
- this.append(c.muted(this.thinkingTail))
164
+ this.append(c.muted(this.thinkingTail), { kind: "diagnostic" })
127
165
  this.thinkingTail = ""
128
166
  }
129
- if (this.thinkingBuf.trim()) {
130
- this.sections.push({ label: "thinking", text: this.thinkingBuf.trim() })
131
- if (this.sections.length > EXPAND_MAX_SECTIONS) {
132
- this.sections.splice(0, this.sections.length - EXPAND_MAX_SECTIONS)
133
- }
134
- }
135
167
  this.thinkingBuf = ""
136
168
  }
137
169
 
138
170
  /** Dorong baris logis (sudah final, mis. gema prompt user). */
139
- push(line: string): void {
171
+ push(line: string, meta: TranscriptMeta = { kind: "system" }): void {
140
172
  this.commit()
141
- this.append(line)
173
+ this.append(line, meta)
142
174
  }
143
175
 
144
176
  /** Gema prompt user ala shell: `minicode › baris-1`, lanjutan menjorok. */
145
177
  pushUser(prompt: string): void {
146
178
  const rows = sanitizeAnsi(prompt).split("\n")
147
179
  const [first, ...rest] = rows
148
- this.push(`${c.accent("minicode")} ${c.muted("›")} ${first ?? ""}`)
149
- for (const r of rest) this.append(` ${r}`)
180
+ this.push(`${c.accent("minicode")} ${c.muted("›")} ${first ?? ""}`, { kind: "user" })
181
+ for (const r of rest) this.append(` ${r}`, { kind: "user" })
150
182
  }
151
183
 
152
184
  pushError(message: string): void {
153
- this.push(c.error(`✗ ${sanitizeAnsiLine(message)}`))
185
+ this.push(c.error(`✗ ${sanitizeAnsiLine(message)}`), { kind: "diagnostic" })
154
186
  }
155
187
 
156
188
  pushInfo(lines: string[]): void {
@@ -161,20 +193,14 @@ export class Transcript {
161
193
  /** Kosongkan transkrip (`/clear`): viewport kembali ke layar kosong. */
162
194
  clear(): void {
163
195
  this.lines = []
196
+ this.meta = []
164
197
  this.pending = ""
165
- this.sections = []
166
198
  this.thinkingBuf = ""
167
199
  this.thinkingTail = ""
168
- }
169
-
170
- /**
171
- * Ambil isi tool yang dibuffer untuk `/expand` (sekali ambil = habis,
172
- * seperti membuka arsip). Kosong = tak ada yang disembunyikan.
173
- */
174
- takeBufferedSections(): BufferedSection[] {
175
- const out = this.sections
176
- this.sections = []
177
- return out
200
+ this.evicted = 0
201
+ this.hasEvictMarker = false
202
+ this.presentedTerminals.clear()
203
+ this.summarizedTurns.clear()
178
204
  }
179
205
 
180
206
  /** Jumlah baris logis (untuk test; bukan API paint). */
@@ -182,12 +208,13 @@ export class Transcript {
182
208
  return this.lines.length + (this.pending ? 1 : 0)
183
209
  }
184
210
 
185
- /**
186
- * Baris tampil untuk viewport: wrap ke `width`, ambil `height` baris
187
- * terakhir dikurangi `scrollBack` (0 = ikut ekor). Selalu kembalikan
188
- * TEPAT `height` string (padding "" bila kurang) supaya frame penuh.
189
- */
190
- view(width: number, height: number, scrollBack: number): string[] {
211
+ /** Total baris logis yang pernah ditambah (monotonik, kebal evict cap). */
212
+ total(): number {
213
+ return this.totalAppended + (this.pending ? 1 : 0)
214
+ }
215
+
216
+ /** Baris visual (ter-wrap) untuk lebar kolom — dipakai view + kunci scroll. */
217
+ private wrapAll(width: number): string[] {
191
218
  const w = Math.max(10, width)
192
219
  const wrapped: string[] = []
193
220
  for (const logical of this.lines) {
@@ -201,7 +228,7 @@ export class Transcript {
201
228
  }
202
229
  }
203
230
  // Ekor hidup thinking: expanded = sisa baris redup; minimized = satu
204
- // penanda redup (transkrip tetap bersih, isi di /expand).
231
+ // penanda redup (isi tidak membanjiri transkrip).
205
232
  if (this.thinkingTail) {
206
233
  for (const chunk of this.thinkingTail.split("\n")) {
207
234
  const rows = chunk === "" ? [""] : chunkByWidth(chunk, w)
@@ -210,6 +237,22 @@ export class Transcript {
210
237
  } else if (this.thinkingBuf.trim()) {
211
238
  wrapped.push(c.muted(t("ts.thinking")))
212
239
  }
240
+ wrapped.push(...this.runningRows())
241
+ return wrapped
242
+ }
243
+
244
+ /** Panjang visual viewport (untuk kunci posisi baca App saat stream masuk). */
245
+ wrappedLength(width: number): number {
246
+ return this.wrapAll(width).length
247
+ }
248
+
249
+ /**
250
+ * Baris tampil untuk viewport: wrap ke `width`, ambil `height` baris
251
+ * terakhir dikurangi `scrollBack` (0 = ikut ekor). Selalu kembalikan
252
+ * TEPAT `height` string (padding "" bila kurang) supaya frame penuh.
253
+ */
254
+ view(width: number, height: number, scrollBack: number): string[] {
255
+ const wrapped = this.wrapAll(width)
213
256
  const back = Math.max(0, Math.min(scrollBack, Math.max(0, wrapped.length - height)))
214
257
  const tail = wrapped.slice(0, wrapped.length - back)
215
258
  const shown = tail.slice(Math.max(0, tail.length - height))
@@ -220,13 +263,168 @@ export class Transcript {
220
263
  dispose(): void {
221
264
  for (const u of this.unsubs) u()
222
265
  this.unsubs = []
266
+ try {
267
+ this.presentationUnsub?.()
268
+ } catch {}
269
+ this.presentationUnsub = null
223
270
  }
224
271
 
225
272
  private commit(): void {
226
273
  if (!this.pending) return
227
274
  const text = this.pending
228
275
  this.pending = ""
229
- for (const row of sanitizeAnsi(text).split("\n")) this.append(row)
276
+ for (const row of sanitizeAnsi(text).split("\n")) this.append(row, { kind: "assistant" })
277
+ }
278
+
279
+ private presentationSnapshot(): UiPresentationSnapshot | null {
280
+ if (!this.getSnapshot) return null
281
+ try {
282
+ return this.getSnapshot()
283
+ } catch {
284
+ return null
285
+ }
286
+ }
287
+
288
+ private presentationEvent(event: UiPresentationEvent): void {
289
+ if (event.type === "turn.completed") {
290
+ this.commit()
291
+ this.commitThinking()
292
+ this.turnSummary(event.summary, event)
293
+ return
294
+ }
295
+ if (!event.type.startsWith("tool.")) return
296
+ if (event.type === "tool.started") {
297
+ this.commit()
298
+ this.commitThinking()
299
+ return
300
+ }
301
+ this.presentationLedger(event)
302
+ }
303
+
304
+ private snapshotActivity(toolCallId: string | undefined) {
305
+ if (!toolCallId) return undefined
306
+ return this.presentationSnapshot()?.activities.find((a) => a.toolCallId === toolCallId)
307
+ }
308
+
309
+ private statusWord(status: UiToolStatus): string {
310
+ if (status === "completed") return t("ts.statusCompleted")
311
+ if (status === "failed") return t("ts.statusFailed")
312
+ if (status === "denied") return t("ts.statusDenied")
313
+ if (status === "cancelled") return t("ts.statusCancelled")
314
+ if (status === "interrupted") return t("ts.statusInterrupted")
315
+ return t("ts.statusRunning")
316
+ }
317
+
318
+ private statusGlyph(status: UiToolStatus): string {
319
+ if (status === "completed") return glyphs.check
320
+ if (status === "failed") return glyphs.cross
321
+ if (status === "denied") return glyphs.denied
322
+ return glyphs.circle
323
+ }
324
+
325
+ private statusPaint(status: UiToolStatus, line: string): string {
326
+ if (status === "completed") return c.success(line)
327
+ if (status === "failed") return c.error(line)
328
+ if (status === "denied") return c.warning(line)
329
+ return c.muted(line)
330
+ }
331
+
332
+ private presentationLedger(event: UiPresentationEvent): void {
333
+ if (event.toolCallId) {
334
+ if (this.presentedTerminals.has(event.toolCallId)) return
335
+ this.presentedTerminals.add(event.toolCallId)
336
+ }
337
+ const activity = this.snapshotActivity(event.toolCallId)
338
+ if (activity?.parentToolCallId) return
339
+ this.commit()
340
+ const name = sanitizeAnsiLine(activity?.name ?? event.name ?? "tool")
341
+ const target = activity?.target ?? event.target
342
+ const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
343
+ const status = activity?.status ?? event.status ?? "completed"
344
+ const snapshot = this.presentationSnapshot()
345
+ const children = activity
346
+ ? (snapshot?.activities ?? []).filter((a) => a.parentToolCallId === activity.toolCallId)
347
+ .length
348
+ : 0
349
+ const retry = activity?.supersedes ? ` ${t("ts.retry")}` : ""
350
+ const child = children > 0 ? ` ${t("ts.childGroup", { n: children })}` : ""
351
+ const message =
352
+ status === "failed" && event.message
353
+ ? `: ${truncateToWidth(sanitizeAnsi(String(event.message)), 200, "…").split("\n")[0] ?? ""}`
354
+ : ""
355
+ const line = ` ${this.statusGlyph(status)} ${name}${targetText} ${this.statusWord(status)}${retry}${child}${message}`
356
+ this.append(this.statusPaint(status, line), {
357
+ kind: "activity",
358
+ ...(event.seq !== undefined ? { seq: event.seq } : {}),
359
+ ...(event.turnId !== undefined ? { turnId: event.turnId } : {}),
360
+ ...(event.toolCallId ? { toolCallId: event.toolCallId } : {}),
361
+ status,
362
+ ...(activity?.expandRef ? { expandRef: activity.expandRef } : {}),
363
+ })
364
+ }
365
+
366
+ private turnSummary(summary: UiPresentationEvent["summary"], event: UiPresentationEvent): void {
367
+ if (!summary) return
368
+ const snapshot = this.presentationSnapshot()
369
+ const turn = snapshot?.turns.find((candidate) => {
370
+ const value = candidate.summary
371
+ return (
372
+ value?.toolsOk === summary.toolsOk &&
373
+ value?.toolsFailed === summary.toolsFailed &&
374
+ value?.toolsDenied === summary.toolsDenied &&
375
+ value?.filesChanged === summary.filesChanged
376
+ )
377
+ })
378
+ const turnId = turn?.turnId ?? snapshot?.turns[snapshot.turns.length - 1]?.turnId ?? 0
379
+ if (event.turnId !== undefined) {
380
+ if (this.summarizedTurns.has(event.turnId)) return
381
+ this.summarizedTurns.add(event.turnId)
382
+ }
383
+ const line = t("ts.turnSummary", {
384
+ turn: turnId,
385
+ ok: summary.toolsOk,
386
+ failed: summary.toolsFailed,
387
+ denied: summary.toolsDenied,
388
+ cancelled: summary.toolsCancelled,
389
+ interrupted: summary.toolsInterrupted,
390
+ files: summary.filesChanged,
391
+ ckpt: summary.checkpointId ?? "—",
392
+ secs: formatElapsed(summary.durationMs),
393
+ })
394
+ this.append(c.muted(line), {
395
+ kind: "system",
396
+ ...(event.seq !== undefined ? { seq: event.seq } : {}),
397
+ ...(event.turnId !== undefined ? { turnId: event.turnId } : {}),
398
+ })
399
+ }
400
+
401
+ private runningRows(): string[] {
402
+ const snapshot = this.presentationSnapshot()
403
+ if (!snapshot) return []
404
+ const running = snapshot.activities.filter((a) => a.status === "running")
405
+ const roots = running.filter((a) => !a.parentToolCallId)
406
+ const rootIds = new Set(roots.map((a) => a.toolCallId))
407
+ const row = (activity: (typeof running)[number], child: boolean): string => {
408
+ const name = sanitizeAnsiLine(activity.name)
409
+ const target = activity.target
410
+ ? ` ${truncateToWidth(sanitizeAnsiLine(activity.target), 120, "")}`
411
+ : ""
412
+ const elapsed = Date.now() - activity.tsStart
413
+ const elapsedText = elapsed >= 2000 ? ` (${formatElapsed(elapsed)})` : ""
414
+ const retry = activity.supersedes ? ` ${t("ts.retry")}` : ""
415
+ const prefix = child ? " ↳ " : ` ${glyphs.arrow} `
416
+ return c.info(`${prefix}${name}${target} … ${t("ts.statusRunning")}${elapsedText}${retry}`)
417
+ }
418
+ const out = roots.map((activity) => {
419
+ const childCount = running.filter((a) => a.parentToolCallId === activity.toolCallId).length
420
+ const suffix = childCount > 0 ? ` ${t("ts.childGroup", { n: childCount })}` : ""
421
+ return `${row(activity, false)}${suffix}`
422
+ })
423
+ for (const activity of running) {
424
+ if (!activity.parentToolCallId || rootIds.has(activity.parentToolCallId)) continue
425
+ out.push(row(activity, true))
426
+ }
427
+ return out
230
428
  }
231
429
 
232
430
  private ledger(e: {
@@ -243,29 +441,35 @@ export class Transcript {
243
441
  if (r?.isError) {
244
442
  const msg =
245
443
  truncateToWidth(sanitizeAnsi(String(r.content ?? "")), 200, "…").split("\n")[0] ?? ""
246
- this.append(c.error(` › ${name}: ${msg}`))
444
+ this.append(c.error(` › ${name}: ${msg}`), { kind: "activity" })
247
445
  return
248
446
  }
249
- const target = ledgerTarget(args)
447
+ const target = targetForFallback(args)
250
448
  const label = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
251
449
  // Glyph ledger memakai arrow tema (› di UTF-8, > di ASCII) — konsisten
252
450
  // dengan grammar REPL walau bentuknya disusun manual di sini.
253
- this.append(c.success(` ›${name ? ` ${name}` : ""}${label}`))
254
- // Isi tool sukses dibuffer untuk /expand (compact default: isi milik
255
- // model untuk dibaca, bukan untuk membanjiri viewport).
256
- if (typeof r?.content === "string" && r.content.trim()) {
257
- const text = sanitizeAnsi(r.content.trim()).slice(0, EXPAND_MAX_CHARS)
258
- this.sections.push({ label: `${name}${label}`, text })
259
- if (this.sections.length > EXPAND_MAX_SECTIONS) {
260
- this.sections.splice(0, this.sections.length - EXPAND_MAX_SECTIONS)
261
- }
262
- }
451
+ this.append(c.success(` ›${name ? ` ${name}` : ""}${label}`), { kind: "activity" })
263
452
  }
264
453
 
265
- private append(line: string): void {
454
+ private append(line: string, meta: TranscriptMeta = { kind: "system" }): void {
266
455
  this.lines.push(line)
267
- if (this.lines.length > TRANSCRIPT_CAP) {
268
- this.lines.splice(0, this.lines.length - TRANSCRIPT_CAP)
456
+ this.meta.push(meta)
457
+ this.totalAppended++
458
+ if (!this.hasEvictMarker && this.lines.length > TRANSCRIPT_CAP) {
459
+ const overflow = this.lines.length - TRANSCRIPT_CAP
460
+ this.lines.splice(0, overflow)
461
+ this.meta.splice(0, overflow)
462
+ this.evicted += overflow
463
+ this.lines.unshift(c.muted(t("ts.evictMarker", { n: this.evicted })))
464
+ this.meta.unshift({ kind: "system" })
465
+ this.hasEvictMarker = true
466
+ }
467
+ if (this.hasEvictMarker && this.lines.length > TRANSCRIPT_CAP + 1) {
468
+ const overflow = this.lines.length - (TRANSCRIPT_CAP + 1)
469
+ this.lines.splice(1, overflow)
470
+ this.meta.splice(1, overflow)
471
+ this.evicted += overflow
472
+ this.lines[0] = c.muted(t("ts.evictMarker", { n: this.evicted }))
269
473
  }
270
474
  }
271
475
  }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MiniCore contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -3,9 +3,12 @@
3
3
  Salinan kernel MiniCore agar `bun install` tidak membutuhkan clone sibling
4
4
  `../minicore`. Sumber kebenaran tetap repo minicore.
5
5
 
6
- - source commit: `ae9d1be362d24b685f83858f65ee12cbfa3ca75a`
7
- - files: 19
8
- - hash: `96bcd6f7b8b62a4e`
6
+ - source commit: `0d33571047c0ed3778986108fd42e4bde6828bb0`
7
+ - files: 20
8
+ - hash: `840aa2e9cd70a401`
9
+ - shipped hash: `78768e71a45254c3` (18 file) — fingerprint file vendor yang ikut paket npm
10
+ (hash di atas mencakup test/fakes.ts yang sengaja tidak ikut paket;
11
+ verifikasi dari paket terbit: hitung hash vendor/minicore di dalam tarball)
9
12
 
10
13
  Perbarui dengan `bun run vendor:minicore` (butuh `../minicore`).
11
14
  CI memverifikasi kesinkronan lewat `bun run vendor:check`.
@@ -4,6 +4,7 @@
4
4
  "description": "MiniCore: a minimal, reductionist AI Agent Runtime — provider/tool-agnostic model → tool → observation loop.",
5
5
  "type": "module",
6
6
  "private": true,
7
+ "license": "MIT",
7
8
  "engines": {
8
9
  "bun": ">=1.0.0"
9
10
  },
@@ -12,10 +13,12 @@
12
13
  },
13
14
  "scripts": {
14
15
  "test": "bun test",
15
- "typecheck": "bunx tsc --noEmit"
16
+ "typecheck": "bunx tsc --noEmit",
17
+ "coverage": "bun test --coverage"
16
18
  },
17
19
  "devDependencies": {
18
20
  "@types/bun": "^1.3.14",
19
- "@types/node": "^26.2.0"
21
+ "@types/node": "^26.2.0",
22
+ "typescript": "^7.0.2"
20
23
  }
21
- }
24
+ }
@@ -88,6 +88,10 @@ export async function executeTurn(
88
88
  let text = "";
89
89
  let reasoning = ""; // DeepSeek-style thinking content
90
90
  let attempt = 0;
91
+ // The original ProviderError behind the current attempt (if any), kept so a
92
+ // terminal throw can carry it as `cause` — callers/CLI can then reach the
93
+ // provider category (auth, rate_limit, …) instead of only the message.
94
+ let providerError: ProviderError | undefined;
91
95
 
92
96
  while (true) {
93
97
  attempt++;
@@ -96,6 +100,7 @@ export async function executeTurn(
96
100
  text = "";
97
101
  reasoning = "";
98
102
  toolCalls.length = 0;
103
+ providerError = undefined;
99
104
  let action: RecoveryAction | null = null;
100
105
  let errorMessage: string | undefined;
101
106
  let completed: FinishReason | undefined;
@@ -151,6 +156,7 @@ export async function executeTurn(
151
156
  }
152
157
  } catch (error) {
153
158
  const cause = toProviderError(error, signal);
159
+ providerError = cause;
154
160
  s.events.emit({
155
161
  type: "provider:extension",
156
162
  kind: "error",
@@ -163,10 +169,14 @@ export async function executeTurn(
163
169
  if (action === null) break;
164
170
  switch (action.type) {
165
171
  case "throw":
166
- throw new AgentError("provider", errorMessage ?? "provider error", { cause: action });
172
+ // `cause` is the original ProviderError when the throw came from a
173
+ // provider failure (category reachable by callers); it falls back to
174
+ // the recovery action for finish-reason throws (length/error/abort),
175
+ // which have no underlying ProviderError.
176
+ throw new AgentError("provider", errorMessage ?? "provider error", { cause: providerError ?? action });
167
177
  case "force_compact_and_retry": {
168
178
  if (compactedForRecovery)
169
- throw new AgentError("budget_exceeded", errorMessage ?? "context too large", { cause: action });
179
+ throw new AgentError("budget_exceeded", errorMessage ?? "context too large", { cause: providerError ?? action });
170
180
  await compactStore(s, signal);
171
181
  // The recovery flag is ALWAYS set (even on no-op):
172
182
  // force_compact_and_retry is exempt from maxProviderRetries, so a
@@ -127,6 +127,10 @@ function clonePlainValue(value: unknown, seen = new WeakMap<object, unknown>()):
127
127
  return out;
128
128
  }
129
129
  const proto = Object.getPrototypeOf(value);
130
+ // Known limitation (documented): non-plain objects (Date, RegExp, class
131
+ // instances, …) are returned AS-IS — the same reference crosses the
132
+ // boundary. Plain objects/arrays/binary are deep-copied; exotic types are
133
+ // kept so cloning never corrupts them, at the cost of shared identity.
130
134
  if (proto !== Object.prototype && proto !== null) return value;
131
135
  const out = Object.create(proto) as Record<string, unknown>;
132
136
  seen.set(value, out);