minicode-ai 0.9.29 → 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 (141) hide show
  1. package/AGENTS.md +45 -0
  2. package/CHANGELOG.md +79 -1
  3. package/PLAN.md +491 -0
  4. package/README.md +2 -2
  5. package/cli/args.ts +1 -0
  6. package/cli/commands/acp.ts +485 -0
  7. package/cli/commands/auth.ts +7 -4
  8. package/cli/commands/config.ts +41 -27
  9. package/cli/commands/exec.ts +33 -12
  10. package/cli/commands/mcp.ts +3 -2
  11. package/cli/commands/memory.ts +1 -1
  12. package/cli/commands/pricing.ts +6 -4
  13. package/cli/commands/providers.ts +18 -8
  14. package/cli/commands/sessions.ts +11 -4
  15. package/cli/commands/skills.ts +3 -3
  16. package/cli/commands/stats.ts +3 -1
  17. package/cli/commands.ts +225 -103
  18. package/cli/index.ts +89 -62
  19. package/cli/model-manager.ts +8 -8
  20. package/cli/provider-manager.ts +13 -13
  21. package/cli/router.ts +7 -0
  22. package/cli/setup.ts +349 -4
  23. package/cli/tui.ts +542 -0
  24. package/cli/wizard.ts +2 -1
  25. package/docs/ARCHITECTURE.html +62 -36
  26. package/docs/CONTROL-PLANE-MAP.md +139 -0
  27. package/docs/HARNESS.md +150 -0
  28. package/docs/PLAN_UIUX_V6.md +209 -0
  29. package/docs/README.md +1 -1
  30. package/docs/SUMMARY.md +52 -0
  31. package/docs/TERMINAL_CONTRACT.md +367 -0
  32. package/docs/UI_RENDER_PIPELINE.md +165 -0
  33. package/docs/USAGE.md +11 -0
  34. package/docs/agents.md +31 -0
  35. package/docs/architecture.md +3 -3
  36. package/docs/choosing-mode.md +34 -0
  37. package/docs/cli.md +130 -0
  38. package/docs/concepts.md +53 -0
  39. package/docs/config-providers.md +87 -0
  40. package/docs/config.md +63 -0
  41. package/docs/contributing.md +79 -0
  42. package/docs/environment.md +95 -0
  43. package/docs/exec.md +73 -0
  44. package/docs/getting-started.md +102 -0
  45. package/docs/glossary.md +37 -0
  46. package/docs/mcp-lsp.md +54 -0
  47. package/docs/memory-sessions.md +63 -0
  48. package/docs/policy-sandbox.md +72 -0
  49. package/docs/pricing-budget.md +49 -0
  50. package/docs/quickstart.md +60 -0
  51. package/docs/repl.md +67 -0
  52. package/docs/security-model.md +95 -0
  53. package/docs/security.md +91 -0
  54. package/docs/skills.md +48 -0
  55. package/docs/terminal.md +79 -0
  56. package/docs/tools.md +123 -0
  57. package/docs/troubleshooting.md +40 -0
  58. package/docs/verify-benchmark.md +58 -0
  59. package/package.json +8 -5
  60. package/src/app/provider-layer.ts +12 -4
  61. package/src/app/rag-layer.ts +7 -2
  62. package/src/app/session.ts +6 -0
  63. package/src/app/tool-layer.ts +2 -1
  64. package/src/config.ts +30 -1
  65. package/src/constants.ts +35 -0
  66. package/src/lib/net.ts +6 -1
  67. package/src/lsp/client.ts +41 -8
  68. package/src/mcp/http-transport.ts +52 -15
  69. package/src/mcp/transport.ts +32 -1
  70. package/src/memory/files.ts +6 -5
  71. package/src/policy/allowlist.ts +1 -1
  72. package/src/policy/bash-guard.ts +213 -17
  73. package/src/policy/compaction.ts +57 -3
  74. package/src/policy/context.ts +4 -0
  75. package/src/policy/jail.ts +49 -4
  76. package/src/policy/permission.ts +152 -12
  77. package/src/policy/pricing.ts +12 -9
  78. package/src/policy/update-check.ts +4 -1
  79. package/src/presentation/adapter.ts +721 -0
  80. package/src/presentation/events.ts +324 -0
  81. package/src/presentation/label.ts +140 -0
  82. package/src/presentation/model.ts +172 -0
  83. package/src/presentation/reducer.ts +486 -0
  84. package/src/presentation/store.ts +256 -0
  85. package/src/providers/anthropic.ts +22 -4
  86. package/src/providers/detect.ts +2 -1
  87. package/src/providers/router.ts +13 -0
  88. package/src/repo/repomap.ts +2 -29
  89. package/src/session/checkpoint.ts +27 -9
  90. package/src/session/journal.ts +27 -5
  91. package/src/skills/loader.ts +88 -5
  92. package/src/telemetry/trace.ts +36 -15
  93. package/src/tools/ask_user.ts +73 -4
  94. package/src/tools/bash.ts +23 -17
  95. package/src/tools/glob.ts +10 -11
  96. package/src/tools/lsp.ts +3 -56
  97. package/src/tools/memory.ts +13 -12
  98. package/src/tools/task.ts +7 -1
  99. package/src/tools/web_fetch.ts +11 -2
  100. package/src/tools/web_search.ts +4 -1
  101. package/src/ui/approval/prompt.ts +96 -22
  102. package/src/ui/assistant/simple.ts +188 -44
  103. package/src/ui/assistant/turn-status.ts +32 -10
  104. package/src/ui/contract.ts +119 -0
  105. package/src/ui/footer.ts +35 -14
  106. package/src/ui/i18n/en.ts +253 -0
  107. package/src/ui/i18n/id.ts +255 -0
  108. package/src/ui/i18n/locale.ts +68 -0
  109. package/src/ui/input/input.ts +189 -81
  110. package/src/ui/input/prompt-engine.ts +139 -4
  111. package/src/ui/render/collapse.ts +20 -13
  112. package/src/ui/render/diff.ts +7 -2
  113. package/src/ui/render/errors.ts +75 -50
  114. package/src/ui/render/format.ts +26 -8
  115. package/src/ui/render/highlight.ts +12 -5
  116. package/src/ui/render/markdown.ts +5 -1
  117. package/src/ui/render/sanitize.ts +29 -2
  118. package/src/ui/render/table.ts +12 -6
  119. package/src/ui/render/theme.ts +23 -4
  120. package/src/ui/render/width.ts +104 -17
  121. package/src/ui/runtime/motion.ts +16 -0
  122. package/src/ui/runtime/screen.ts +242 -0
  123. package/src/ui/runtime/spinner.ts +50 -4
  124. package/src/ui/runtime/statusline.ts +50 -1
  125. package/src/ui/screens/dialog.ts +174 -0
  126. package/src/ui/screens/form.ts +486 -0
  127. package/src/ui/screens/model-manager.ts +289 -134
  128. package/src/ui/screens/picker.ts +264 -109
  129. package/src/ui/screens/provider-manager.ts +385 -172
  130. package/src/ui/screens/wizard.ts +165 -102
  131. package/src/ui/tui/app.ts +951 -0
  132. package/src/ui/tui/transcript.ts +475 -0
  133. package/vendor/minicore/LICENSE +21 -0
  134. package/vendor/minicore/VENDOR.md +6 -3
  135. package/vendor/minicore/package.json +6 -3
  136. package/vendor/minicore/src/core/loop.ts +12 -2
  137. package/vendor/minicore/src/core/snapshot.ts +4 -0
  138. package/vendor/minicore/src/providers/openai-compat.ts +76 -25
  139. package/cli/repl.ts +0 -740
  140. package/src/ui/runtime/chrome.ts +0 -369
  141. package/src/ui/screens/overlay.ts +0 -61
@@ -3,11 +3,18 @@
3
3
  // inline dan EXPANDED by default (transparansi shell); mode compact via
4
4
  // MINICODE_COMPACT=1 atau setCompactMode (/compact).
5
5
  import { Buffer } from "node:buffer"
6
- import type { UiBus, UiStep } from "../contract.ts"
6
+ import type {
7
+ UiBus,
8
+ UiPresentationActivity,
9
+ UiPresentationEvent,
10
+ UiPresentationSnapshot,
11
+ UiStep,
12
+ } from "../contract.ts"
13
+ import { t } from "../i18n/locale.ts"
7
14
  import {
8
- bufferSection,
15
+ clearCollapsedSections,
9
16
  collapse,
10
- resetBufferedSections,
17
+ rememberCollapsedSection,
11
18
  sectionMinimized,
12
19
  } from "../render/collapse.ts"
13
20
  import { detail } from "../render/detail.ts"
@@ -31,6 +38,15 @@ import { runWithoutStatus } from "../runtime/statusline.ts"
31
38
 
32
39
  export interface SimpleOptions {
33
40
  verbose?: boolean
41
+ /**
42
+ * Mode senyap untuk TUI fullscreen: semua tulis ke stdout/stderr DITEKAN,
43
+ * tapi state tetap jalan (rememberTurn untuk /copy, rememberCollapsedSection untuk
44
+ * /expand, pendingError untuk driver). Tanpa ini printer linier mengotori
45
+ * alt-screen di sela repaint App — kontrak I3 (App penulis tunggal layar).
46
+ */
47
+ quiet?: boolean
48
+ getSnapshot?: () => UiPresentationSnapshot | null
49
+ onPresentationEvent?: (handler: (event: UiPresentationEvent) => void) => () => void
34
50
  }
35
51
 
36
52
  // Buffer output turn terakhir untuk /copy: teks model (sudah sanitize, sama
@@ -67,9 +83,9 @@ export function writeClipboardOsc52(text: string): boolean {
67
83
  return true
68
84
  }
69
85
 
70
- const wOut = (s: string) =>
86
+ const wOutDirect = (s: string) =>
71
87
  runWithoutStatus(() => process.stdout.write(process.stdout.isTTY ? s : stripSgr(s)))
72
- const wErr = (s: string) =>
88
+ const wErrDirect = (s: string) =>
73
89
  runWithoutStatus(() => process.stderr.write(process.stdout.isTTY ? s : stripSgr(s)))
74
90
 
75
91
  // Error provider terakhir turn ini — diingat, BUKAN dicetak langsung.
@@ -111,6 +127,11 @@ function patchBlocks(patches: unknown): [string, string] {
111
127
  }
112
128
 
113
129
  export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () => void {
130
+ // Shadow module-level wOut/wErr: saat quiet, paint ditekan tapi SEMUA state
131
+ // (rememberTurn, rememberCollapsedSection, pendingError, sanitizer) tetap jalan.
132
+ // Shadowing disengaja agar ~20 call-site tak perlu diubah satu per satu.
133
+ const wOut = opts.quiet ? (_: string) => {} : wOutDirect
134
+ const wErr = opts.quiet ? (_: string) => {} : wErrDirect
114
135
  let streamBuffer = ""
115
136
  // Sanitizer sadar-stream per aliran teks (temuan F1): ekor escape yang
116
137
  // terpotong di batas chunk ditahan dan disambung ke chunk berikut SEBELUM
@@ -159,7 +180,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
159
180
  return
160
181
  }
161
182
  if (answerBuf.length < ANSWER_BUF_MAX) {
162
- answerBuf += s.slice(0, ANSWER_BUF_MAX - answerBuf.length)
183
+ // Jangan belah surrogate pair di batas cap: slice mentah bisa
184
+ // menyisakan lead-surrogate yatim yang tampil sebagai U+FFFD di /expand.
185
+ let chunk = s.slice(0, ANSWER_BUF_MAX - answerBuf.length)
186
+ const last = chunk.charCodeAt(chunk.length - 1)
187
+ if (chunk.length > 0 && last >= 0xd800 && last <= 0xdbff) chunk = chunk.slice(0, -1)
188
+ answerBuf += chunk
163
189
  if (answerBuf.length >= ANSWER_BUF_MAX) answerTruncated = true
164
190
  } else {
165
191
  answerTruncated = true
@@ -185,7 +211,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
185
211
  }
186
212
 
187
213
  /** Label satu-baris ringkas per tool (bukan dump JSON argumen). */
188
- const toolSummary = (name: string, args: Record<string, unknown>, target?: string): string => {
214
+ const fallbackToolLabel = (
215
+ name: string,
216
+ args: Record<string, unknown>,
217
+ target?: string,
218
+ ): string => {
189
219
  if (name === "todo_write" || name === "todo_read") {
190
220
  const list = args.todos
191
221
  const n = Array.isArray(list) ? list.length : 0
@@ -217,12 +247,14 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
217
247
  // menghilangkan konten diam-diam (perilaku lama menampilkannya live).
218
248
  const finalizeAnswer = () => {
219
249
  if (answerBuf.length === 0) return
220
- const n = stripAnsi(answerBuf).length
221
- const cap = answerTruncated ? ", capped 1MB" : ""
250
+ // Hitung per code point (bukan UTF-16 unit): emoji surrogate dihitung 1,
251
+ // konsisten dengan label "chars" dan tak menggandakan di /expand.
252
+ const n = Array.from(stripAnsi(answerBuf)).length
253
+ const cap = answerTruncated ? t("one.answerCap") : ""
222
254
  // Petunjuk /expand WAJIB di baris ini: tanpa itu jawaban yang dikecilkan
223
255
  // terlihat "bisu" (tak ada cara membuka yang bisa ditemukan user).
224
- wErr(c.info(` + answer (${n} chars${cap}) — /expand to read\n`))
225
- bufferSection("answer", answerBuf, "stdout")
256
+ wErr(c.info(t("one.answerMin", { n, cap })))
257
+ rememberCollapsedSection("answer", answerBuf, "stdout")
226
258
  answerBuf = ""
227
259
  answerTruncated = false
228
260
  }
@@ -230,7 +262,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
230
262
  const flushThinking = () => {
231
263
  flushReasoningTail()
232
264
  if (thinkState === "min" && thinkingBuf) {
233
- bufferSection("thinking", thinkingBuf)
265
+ rememberCollapsedSection("thinking", thinkingBuf)
234
266
  thinkingBuf = ""
235
267
  }
236
268
  thinkState = "off"
@@ -264,7 +296,80 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
264
296
  streamBuffer = parts[parts.length - 1] ?? ""
265
297
  }
266
298
 
299
+ const presentationEnabled = !!opts.getSnapshot
300
+ const presentedTerminals = new Set<string>()
301
+ const presentationSnapshot = (): UiPresentationSnapshot | null => {
302
+ if (!presentationEnabled || !opts.getSnapshot) return null
303
+ try {
304
+ return opts.getSnapshot()
305
+ } catch {
306
+ return null
307
+ }
308
+ }
309
+ const presentationActivity = (toolCallId: string | undefined) => {
310
+ if (!toolCallId) return undefined
311
+ return presentationSnapshot()?.activities.find((activity) => activity.toolCallId === toolCallId)
312
+ }
313
+ const statusWord = (status: UiPresentationActivity["status"]): string => {
314
+ if (status === "completed") return t("ts.statusCompleted")
315
+ if (status === "failed") return t("ts.statusFailed")
316
+ if (status === "denied") return t("ts.statusDenied")
317
+ if (status === "cancelled") return t("ts.statusCancelled")
318
+ if (status === "interrupted") return t("ts.statusInterrupted")
319
+ return t("ts.statusRunning")
320
+ }
321
+ const linearSuffix = (activity: UiPresentationActivity | undefined): string => {
322
+ if (!activity) return ""
323
+ const parts: string[] = [statusWord(activity.status)]
324
+ if (activity.durationMs !== undefined)
325
+ parts.push(t("one.duration", { v: Math.max(0, Math.round(activity.durationMs)) }))
326
+ if (activity.denyReason)
327
+ parts.push(t("one.denyReason", { reason: sanitizeAnsiLine(activity.denyReason) }))
328
+ const paths = activity.receipt?.paths ?? []
329
+ if (paths.length > 0) {
330
+ const cleanPaths = paths
331
+ .map((path) => truncateToWidth(sanitizeAnsiLine(path), 80, ""))
332
+ .join(", ")
333
+ parts.push(t("one.receipt", { paths: cleanPaths }))
334
+ }
335
+ if (activity.supersedes) parts.push(t("ts.retry"))
336
+ return parts.length > 0 ? ` ${c.muted(`[${parts.join(" · ")}]`)}` : ""
337
+ }
338
+ const paintTerminal = (status: UiPresentationActivity["status"], line: string): string => {
339
+ if (status === "failed") return c.error(line)
340
+ if (status === "denied") return c.warning(line)
341
+ if (status === "completed") return c.success(line)
342
+ return c.muted(line)
343
+ }
344
+ const writePresentationTerminal = (event: UiPresentationEvent): void => {
345
+ if (!presentationEnabled) return
346
+ if (
347
+ event.type !== "tool.failed" &&
348
+ event.type !== "tool.denied" &&
349
+ event.type !== "tool.cancelled"
350
+ ) {
351
+ return
352
+ }
353
+ if (!event.toolCallId) return
354
+ if (presentedTerminals.has(event.toolCallId)) return
355
+ presentedTerminals.add(event.toolCallId)
356
+ const activity = presentationActivity(event.toolCallId)
357
+ const name = sanitizeAnsiLine(activity?.name ?? event.name ?? "tool")
358
+ const target = activity?.target ?? event.target
359
+ const targetText = target ? ` ${truncateToWidth(sanitizeAnsiLine(target), 120, "")}` : ""
360
+ const status = activity?.status ?? event.status ?? "failed"
361
+ const message = event.message ?? activity?.error?.message
362
+ const detail = message
363
+ ? `: ${truncateToWidth(sanitizeAnsi(String(message)), 200, "…").split("\n")[0] ?? ""}`
364
+ : ""
365
+ const line = ` ${glyphs.arrow} ${name}${targetText}${linearSuffix(activity)}${detail}`
366
+ wErr(paintTerminal(status, `${line}\n`))
367
+ }
368
+
267
369
  const offs: (() => void)[] = []
370
+ if (opts.onPresentationEvent) {
371
+ offs.push(opts.onPresentationEvent((event) => writePresentationTerminal(event)))
372
+ }
268
373
  offs.push(
269
374
  bus.on("turn:started", (e) => {
270
375
  // Turn baru: buffer turn sebelumnya dibuang (lihat /copy yang juga
@@ -274,11 +379,13 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
274
379
  reasoningLine = ""
275
380
  answerBuf = ""
276
381
  answerTruncated = false
277
- resetBufferedSections()
382
+ clearCollapsedSections()
278
383
  collapse.setActiveSection(null)
279
384
  lastTurnText = ""
280
385
  pendingError = null
281
- if (opts.verbose) wErr(c.muted(`\n── Turn ${e.turn} ──\n`))
386
+ presentedTerminals.clear()
387
+
388
+ if (opts.verbose) wErr(c.muted(t("one.turnHead", { n: e.turn })))
282
389
  }),
283
390
  )
284
391
  offs.push(
@@ -295,7 +402,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
295
402
  bashSan.flush()
296
403
  flushThinking()
297
404
  finalizeAnswer()
298
- if (opts.verbose) wErr(c.muted(`\n done\n`))
405
+ if (opts.verbose) wErr(c.muted(t("one.done")))
299
406
  }),
300
407
  )
301
408
  offs.push(
@@ -308,7 +415,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
308
415
  flushThinking()
309
416
  collapse.setActiveSection("answer")
310
417
  if (!answerHidden() && answerBuf.length > 0) {
311
- wErr(c.muted(" − answer\n"))
418
+ wErr(c.muted(t("one.answerOpen")))
312
419
  wOut(answerBuf)
313
420
  answerBuf = ""
314
421
  answerTruncated = false
@@ -334,7 +441,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
334
441
  if (expanded) {
335
442
  if (thinkState !== "exp") {
336
443
  thinkState = "exp"
337
- wErr(c.muted(` − thinking\n`))
444
+ wErr(c.muted(t("one.thinkOpen")))
338
445
  if (thinkingBuf) {
339
446
  wErr(c.muted(thinkingBuf))
340
447
  thinkingBuf = ""
@@ -357,7 +464,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
357
464
  // Sisa baris expanded yang belum selesai dicetak dulu (terlihat),
358
465
  // baru header minimize — konten tak hilang, tak menempel.
359
466
  flushReasoningTail()
360
- wErr(c.info(` + thinking\n`))
467
+ wErr(c.info(t("one.thinkMin")))
361
468
  }
362
469
  if (text) {
363
470
  // Sama: buffer thinking ikut tercemar bila mentah (flush expanded
@@ -366,13 +473,16 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
366
473
  thinkingBuf += cleanUntrusted(reasoningSan.push(text), !!process.stdout.isTTY)
367
474
  if (thinkingBuf.length > THINKING_BUF_MAX) {
368
475
  // Total ber-marker dibatasi THINKING_BUF_MAX (= cap per-entry
369
- // bufferSection) agar tak ada pemotongan diam-diam kedua di hilir.
476
+ // rememberCollapsedSection) agar tak ada pemotongan diam-diam kedua di hilir.
477
+ // Tail-slice jangan mulai di tengah surrogate pair: trail
478
+ // yatim di awal tampil sebagai U+FFFD saat /expand.
370
479
  const body = thinkingBuf.startsWith(THINKING_TRUNCATED_MARKER)
371
480
  ? thinkingBuf.slice(THINKING_TRUNCATED_MARKER.length)
372
481
  : thinkingBuf
373
- thinkingBuf =
374
- THINKING_TRUNCATED_MARKER +
375
- body.slice(-(THINKING_BUF_MAX - THINKING_TRUNCATED_MARKER.length))
482
+ let tail = body.slice(-(THINKING_BUF_MAX - THINKING_TRUNCATED_MARKER.length))
483
+ const first = tail.charCodeAt(0)
484
+ if (tail.length > 0 && first >= 0xdc00 && first <= 0xdfff) tail = tail.slice(1)
485
+ thinkingBuf = THINKING_TRUNCATED_MARKER + tail
376
486
  }
377
487
  }
378
488
  }
@@ -392,7 +502,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
392
502
  const d = e.data as { message?: string; category?: string }
393
503
  pendingError = formatProviderError(d)
394
504
  } else if (e.kind === "content_filter") {
395
- wErr(c.warning(`\n! Content filter blocked\n`))
505
+ wErr(c.warning(t("one.contentBlocked")))
396
506
  }
397
507
  }),
398
508
  )
@@ -406,7 +516,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
406
516
  `${c.info(sanitizeAnsiLine(tc.name))}(${c.muted(sanitizeAnsiLine(formatArgsPreview(tc.args)))})`,
407
517
  )
408
518
  .join(", ")
409
- wErr(c.muted(` Step ${e.step.index}: ${calls}\n`))
519
+ wErr(c.muted(t("one.step", { i: e.step.index, calls })))
410
520
  }),
411
521
  )
412
522
  offs.push(
@@ -435,19 +545,27 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
435
545
  )
436
546
  offs.push(
437
547
  bus.on("execution:completed", (e) => {
548
+ const callId = e.execution.call.id
549
+ const activity = presentationActivity(callId)
550
+ if (activity && activity.status !== "completed" && callId && presentedTerminals.has(callId)) {
551
+ return
552
+ }
438
553
  const r = e.execution.result
439
554
  const name = e.execution.call.name
440
555
  const args = (e.execution.call.args ?? {}) as Record<string, unknown>
556
+ const suffix = linearSuffix(activity)
557
+ const isError = activity ? activity.status !== "completed" : r.isError === true
441
558
  // Hasil string ikut ke buffer /copy (versi sanitize, cap per-add agar
442
559
  // satu read_file raksasa tak langsung memenuhi buffer sendirian).
443
- if (!r.isError && typeof r.content === "string")
560
+ if (!isError && typeof r.content === "string")
444
561
  rememberTurn(truncateToWidth(sanitizeAnsi(r.content), 20000, ""))
445
- if (r.isError) {
446
- // Error tool SELALU tampil penuh — tidak pernah dikecilkan.
562
+ if (isError) {
563
+ // Error tool ditampilkan ringkas per baris (cap 200 kolom + marker) —
564
+ // tanpa marker user tak bisa bedakan "pesan 200 kolom" vs "terpotong".
447
565
  collapse.setActiveSection(null)
448
566
  wErr(
449
567
  c.error(
450
- ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}: ${truncateToWidth(sanitizeAnsi(String(r.content)), 200, "")}\n`,
568
+ ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}${suffix}: ${truncateToWidth(sanitizeAnsi(String(r.content)), 200, "…")}\n`,
451
569
  ),
452
570
  )
453
571
  return
@@ -458,9 +576,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
458
576
  // pencetakan isi (bash/edit/diff/content tool), bukan marker.
459
577
  if (sectionMinimized("tool")) {
460
578
  collapse.setActiveSection(null)
461
- const label = toolSummary(name, args, target)
462
- wErr(c.info(` + ${label}\n`))
463
- bufferSection(label, sanitizeAnsi(String(r.content ?? "")).trim())
579
+ const label = activity?.summary
580
+ ? sanitizeAnsiLine(activity.summary)
581
+ : fallbackToolLabel(name, args, target)
582
+ wErr(c.info(` + ${label}${suffix}\n`))
583
+ rememberCollapsedSection(label, sanitizeAnsi(String(r.content ?? "")).trim())
464
584
  return
465
585
  }
466
586
  if (name === "write_file" && target) {
@@ -470,7 +590,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
470
590
  const cleanTarget = sanitizeAnsiLine(target)
471
591
  wOut(
472
592
  c.success(
473
- ` ${glyphs.arrow} write_file ${cleanTarget}${size ? c.muted(` (${size})`) : ""}\n`,
593
+ ` ${glyphs.arrow} write_file ${cleanTarget}${size ? c.muted(` (${size})`) : ""}${suffix}\n`,
474
594
  ),
475
595
  )
476
596
  return
@@ -490,13 +610,20 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
490
610
  )
491
611
  return
492
612
  }
493
- wOut(c.success(` ${glyphs.arrow} ${sanitizeAnsiLine(name)} ${sanitizeAnsiLine(target)}\n`))
613
+ wOut(
614
+ c.success(
615
+ ` ${glyphs.arrow} ${sanitizeAnsiLine(name)} ${sanitizeAnsiLine(target)}${suffix}\n`,
616
+ ),
617
+ )
494
618
  return
495
619
  }
496
620
  // todo_write: tampilkan daftarnya utuh — ini rencana kerja, bukan noise.
497
621
  if (name === "todo_write" || name === "todo_read") {
622
+ // Nama tool dari event model (tak terpercaya): sanitasi seperti cabang
623
+ // lain agar ESC[2J/OSC tak lolos via label.
624
+ const cleanName = sanitizeAnsiLine(name)
498
625
  wErr(
499
- c.success(` ${glyphs.arrow} ${name}\n`) +
626
+ c.success(` ${glyphs.arrow} ${cleanName}${suffix}\n`) +
500
627
  c.muted(`${sanitizeAnsi(String(r.content))}\n`),
501
628
  )
502
629
  return
@@ -511,17 +638,19 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
511
638
  if (detail.compact) {
512
639
  const preview =
513
640
  lines.length > 3
514
- ? lines.slice(0, 3).join("\n ") + c.muted(`\n ... (${lines.length - 3} more)`)
641
+ ? lines.slice(0, 3).join("\n ") + c.muted(t("one.more3", { n: lines.length - 3 }))
515
642
  : lines.join("\n ")
516
- wErr(c.success(` ${glyphs.arrow} $ ${cmdLabel}\n`) + c.muted(` ${preview}\n`))
643
+ wErr(
644
+ c.success(` ${glyphs.arrow} $ ${cmdLabel}${suffix}\n`) + c.muted(` ${preview}\n`),
645
+ )
517
646
  return
518
647
  }
519
648
  const maxLines = TOOL_OUT_MAX_LINES()
520
649
  const shown = lines.slice(0, maxLines).map((l) => ` ${sanitizeAnsi(l)}`)
521
650
  const more =
522
- lines.length > maxLines ? c.muted(`\n … (${lines.length - maxLines} more lines)`) : ""
651
+ lines.length > maxLines ? c.muted(t("one.moreLines", { n: lines.length - maxLines })) : ""
523
652
  wErr(
524
- c.success(` ${glyphs.arrow} $ ${cmdLabel}\n`) +
653
+ c.success(` ${glyphs.arrow} $ ${cmdLabel}${suffix}\n`) +
525
654
  (shown.length ? `${c.muted(shown.join("\n")) + more}\n` : ""),
526
655
  )
527
656
  return
@@ -530,8 +659,15 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
530
659
  // satu baris › + target — isinya milik model untuk dibaca, bukan untuk
531
660
  // membanjiri scrollback pengguna. Konten tetap bisa dilihat via expanded.
532
661
  if (detail.compact && CONTENT_TOOLS.has(name)) {
533
- const label = truncateWords(sanitizeAnsiLine(target ?? formatArgsPreview(args)), 120)
534
- wErr(c.success(` ${glyphs.arrow} ${sanitizeAnsiLine(name)}${label ? ` ${label}` : ""}\n`))
662
+ const label = activity?.summary
663
+ ? sanitizeAnsiLine(activity.summary)
664
+ : truncateWords(sanitizeAnsiLine(target ?? formatArgsPreview(args)), 120)
665
+
666
+ wErr(
667
+ c.success(
668
+ ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}${label ? ` ${label}` : ""}${suffix}\n`,
669
+ ),
670
+ )
535
671
  return
536
672
  }
537
673
  if (!detail.compact && CONTENT_TOOLS.has(name)) {
@@ -556,22 +692,30 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
556
692
  }
557
693
  // Sisa tool (compact & expanded): satu baris › + label. WAJIB diakhiri
558
694
  // newline — tanpa itu baris berikutnya menempel (overlap di stderr log).
559
- const label = truncateWords(sanitizeAnsiLine(target ?? formatArgsPreview(args)), 120)
695
+ const label = activity?.summary
696
+ ? sanitizeAnsiLine(activity.summary)
697
+ : truncateWords(sanitizeAnsiLine(target ?? formatArgsPreview(args)), 120)
560
698
  const first = sanitizeAnsi(String(r.content)).trim().split("\n")[0] ?? ""
561
699
  const preview = truncateToWidth(first, 80, "")
562
700
  const cleanName = sanitizeAnsiLine(name)
563
701
  if (!detail.compact && preview) {
564
702
  wErr(
565
703
  c.success(
566
- ` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""} ${c.muted(preview)}\n`,
704
+ ` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""}${suffix} ${c.muted(preview)}\n`,
567
705
  ),
568
706
  )
569
707
  return
570
708
  }
571
- wErr(c.success(` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""}\n`))
709
+ wErr(c.success(` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""}${suffix}\n`))
572
710
  }),
573
711
  )
574
- offs.push(bus.on("context:compacted", (e) => wErr(c.warning(` ── compacted: ${e.reason}\n`))))
712
+ offs.push(
713
+ bus.on("context:compacted", (e) =>
714
+ wErr(
715
+ c.warning(`${t("ts.compacted", { reason: sanitizeAnsiLine(String(e.reason ?? "")) })}\n`),
716
+ ),
717
+ ),
718
+ )
575
719
 
576
720
  return () => {
577
721
  // Sisa parsal di-flush dulu (jangan hilang diam-diam), baru lepas.
@@ -95,6 +95,7 @@ export function attachTurnStatus(
95
95
  // Interval animasi mengikuti — cepat bila model berpikir cepat.
96
96
  let intervalMs = 150
97
97
  let lastReasoningMs: number | null = null
98
+ let toolStartMs: number | null = null
98
99
  const recentDeltas: number[] = []
99
100
  // Kepemilikan transient stderr selama interval hidup — lihat statusline.ts.
100
101
  let owned: { release(): void } | null = null
@@ -117,14 +118,24 @@ export function attachTurnStatus(
117
118
  const dots = Array(1 + (tickGroup % 3))
118
119
  .fill(glyphs.dot)
119
120
  .join(" ")
120
- const cols = process.stdout.columns || 80
121
+ // Garis dilukis ke stderr via paintWrite — ukur dari stderr (jatuh ke
122
+ // stdout bila tak ada). stdout|pipe + stderr TTY memakai fallback 80 yang
123
+ // salah: terminal 120 terpotong berlebih, terminal 40 wrap sendiri.
124
+ const cols = process.stderr.columns ?? process.stdout.columns ?? 80
121
125
  // Sinyal "alive" (spark pulse) kini MILIK FOOTER, bukan thinking line:
122
126
  // satu sumber agar tak ada dua denyut. Thinking = titik saja; tool line
123
127
  // tetap pakai spinner braille (itu progres, bukan spark).
128
+ let elapsedText = ""
129
+ if (label !== "Thinking" && toolStartMs !== null) {
130
+ const elapsed = Date.now() - toolStartMs
131
+ if (elapsed >= 2000) {
132
+ elapsedText = ` ${c.faint(`(${formatElapsed(elapsed)})`)}`
133
+ }
134
+ }
124
135
  const body =
125
136
  label === "Thinking"
126
137
  ? `${dots}`
127
- : `${c.info(glyphs.spinnerFrames[fi % glyphs.spinnerFrames.length]!)} ${label} ${dots}`
138
+ : `${c.info(glyphs.spinnerFrames[fi % glyphs.spinnerFrames.length]!)} ${label} ${dots}${elapsedText}`
128
139
  const full = body + extra
129
140
  // Terminal sangat sempit: potongan label bisa tinggal 1 huruf ("t") —
130
141
  // dalam kasus itu tampilkan titiknya saja daripada label rusak.
@@ -186,6 +197,7 @@ export function attachTurnStatus(
186
197
  turnOn = false
187
198
  textOn = false
188
199
  textSeen = false
200
+ toolStartMs = null
189
201
  label = "Thinking"
190
202
  intervalMs = 150
191
203
  lastReasoningMs = null
@@ -211,21 +223,29 @@ export function attachTurnStatus(
211
223
  }
212
224
  registerStatusLine(handle)
213
225
 
214
- const toolLabel = (e: { execution: { call: { name: string; args?: unknown } } }): string => {
226
+ const statusToolLabel = (e: {
227
+ execution: { call: { name: string; args?: unknown } }
228
+ }): string => {
215
229
  const name = e.execution.call.name
216
230
  const args = (e.execution.call.args ?? {}) as Record<string, unknown>
217
231
  let target = ""
218
232
  if (typeof args.path === "string") target = args.path
219
233
  else if (typeof args.file === "string") target = args.file
220
- else if (typeof args.cmd === "string") target = args.cmd.slice(0, 80)
221
- else if (typeof args.command === "string") target = args.command.slice(0, 80)
222
- // Potong panjang (bukan lebar) di sini; pemotongan LEBAR terjadi per-paint
223
- // agar resize langsung berefek.
234
+ else if (typeof args.cmd === "string") target = args.cmd
235
+ else if (typeof args.command === "string") target = args.command
236
+ // Potong panjang di sini (batas 80/200), potong LEBAR per-paint agar resize
237
+ // langsung berefek. truncateToWidth: tak belah SGR/surrogate — slice mentah
238
+ // bisa mendarat di tengah `\x1b[31m` dan menyisakan escape gantung yang
239
+ // lolos paintWrite.
224
240
  // Nama + argumen datang dari model (tak terpercaya): sanitasi sebelum
225
241
  // masuk paintWrite — truncateToWidth memotong lebar, bukan sekuens kontrol.
226
242
  const cleanName = sanitizeAnsiLine(name)
227
- const label2 = target ? `${cleanName} ${sanitizeAnsiLine(target)}` : cleanName
228
- return label2.length > 200 ? label2.slice(0, 200) : label2
243
+ const cleanTarget =
244
+ target.length > 80
245
+ ? truncateToWidth(sanitizeAnsiLine(target), 80, "")
246
+ : sanitizeAnsiLine(target)
247
+ const label2 = cleanTarget ? `${cleanName} ${cleanTarget}` : cleanName
248
+ return label2.length > 200 ? truncateToWidth(label2, 200, "") : label2
229
249
  }
230
250
 
231
251
  const detach = [
@@ -282,10 +302,12 @@ export function attachTurnStatus(
282
302
  // Fase kerja baru: latch teks dibuka lagi (thinking antar-tool tampil).
283
303
  textOn = false
284
304
  textSeen = false
285
- startPaint(toolLabel(e))
305
+ toolStartMs = Date.now()
306
+ startPaint(statusToolLabel(e))
286
307
  }),
287
308
  bus.on("execution:completed", () => {
288
309
  // Tool selesai: kembali ke "Thinking" selama model belum mengeluarkan teks.
310
+ toolStartMs = null
289
311
  textSeen = false
290
312
  if (shouldPaint()) startPaint("Thinking")
291
313
  }),
@@ -11,13 +11,29 @@
11
11
  // menyerahkan bus kernel apa adanya tanpa adapter runtime.
12
12
 
13
13
  export interface UiToolCallRef {
14
+ /**
15
+ * toolCallId dari provider (ToolCall.id) — diaditif Fase 2 Presentasi V2.1.
16
+ * Opsional agar subscriber lama yang hanya butuh name/args tidak rusak;
17
+ * kernel selalu mengisi ini (snapshotToolCall), cast `as unknown` di
18
+ * cli/tui.ts tidak lagi buta terhadap identitas.
19
+ */
20
+ id?: string
14
21
  name: string
15
22
  args?: unknown
16
23
  }
17
24
 
25
+ /** Hasil tool ringkas di step (Fase 2) — bukan payload penuh ToolResult. */
26
+ export interface UiStepResultRef {
27
+ toolCallId?: string
28
+ isError?: boolean
29
+ content?: unknown
30
+ }
31
+
18
32
  export interface UiStep {
19
33
  index: number
20
34
  toolCalls: readonly UiToolCallRef[]
35
+ /** Opsional: ringkas results (kernel step:completed membawa ini penuh). */
36
+ results?: readonly UiStepResultRef[]
21
37
  }
22
38
 
23
39
  export interface UiExecution {
@@ -53,3 +69,106 @@ export type UiEventType = UiEvent["type"]
53
69
  export interface UiBus {
54
70
  on(type: UiEventType, handler: (event: any) => void): () => void
55
71
  }
72
+
73
+ export type UiToolStatus =
74
+ | "running"
75
+ | "completed"
76
+ | "failed"
77
+ | "denied"
78
+ | "cancelled"
79
+ | "interrupted"
80
+
81
+ export interface UiTurnSummary {
82
+ toolsOk: number
83
+ toolsFailed: number
84
+ toolsDenied: number
85
+ toolsCancelled: number
86
+ toolsInterrupted: number
87
+ filesChanged: number
88
+ checkpointId?: string
89
+ durationMs: number
90
+ }
91
+
92
+ export interface UiPresentationError {
93
+ cause?: string
94
+ message: string
95
+ hint?: string
96
+ }
97
+
98
+ export interface UiPresentationReceipt {
99
+ paths?: string[]
100
+ checkpointId?: string
101
+ stats?: { added?: number; removed?: number }
102
+ test?: { passed: number; failed: number; summary: string }
103
+ cmd?: { exit?: number }
104
+ }
105
+
106
+ export interface UiPresentationActivity {
107
+ seq?: number
108
+ turnId?: number
109
+ sessionId?: string
110
+ toolCallId: string
111
+ name: string
112
+ qualified?: string
113
+ target?: string
114
+ status: UiToolStatus
115
+ tsStart: number
116
+ tsEnd?: number
117
+ durationMs?: number
118
+ summary?: string
119
+ error?: UiPresentationError
120
+ denyReason?: string
121
+ receipt?: UiPresentationReceipt
122
+ parentToolCallId?: string
123
+ supersedes?: string
124
+ expandRef?: { toolCallId: string; idx: number }
125
+ }
126
+
127
+ export interface UiPresentationTurn {
128
+ turnId: number
129
+ status: "running" | "completed" | "failed" | "cancelled" | "interrupted"
130
+ summary?: UiTurnSummary
131
+ }
132
+
133
+ export interface UiPresentationSnapshot {
134
+ activities: UiPresentationActivity[]
135
+ turns: UiPresentationTurn[]
136
+ }
137
+
138
+ export interface UiApprovalOutcome {
139
+ decision: "allow" | "allow-always" | "deny" | "cancelled"
140
+ by: "user" | "system"
141
+ reason?: string
142
+ }
143
+
144
+ export interface UiPresentationEvent {
145
+ type:
146
+ | "turn.started"
147
+ | "turn.completed"
148
+ | "turn.failed"
149
+ | "turn.cancelled"
150
+ | "tool.started"
151
+ | "tool.completed"
152
+ | "tool.failed"
153
+ | "tool.denied"
154
+ | "tool.cancelled"
155
+ | "approval.requested"
156
+ | "approval.settled"
157
+ seq?: number
158
+ turnId?: number
159
+ toolCallId?: string
160
+ approvalId?: string
161
+ name?: string
162
+ qualified?: string
163
+ target?: string
164
+ status?: UiToolStatus
165
+ tsStart?: number
166
+ durationMs?: number
167
+ message?: string
168
+ cause?: string
169
+ reason?: string
170
+ error?: string
171
+ outcome?: UiApprovalOutcome
172
+ via?: "prompt" | "system"
173
+ summary?: UiTurnSummary
174
+ }