minicode-ai 0.13.0 → 0.14.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 (83) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -21
  3. package/README.md +4 -0
  4. package/cli/args.ts +50 -2
  5. package/cli/commands/acp.ts +18 -3
  6. package/cli/commands/daemon.ts +114 -19
  7. package/cli/commands/exec.ts +95 -7
  8. package/cli/commands/mcp.ts +66 -5
  9. package/cli/commands/memory.ts +46 -14
  10. package/cli/commands.ts +5 -0
  11. package/cli/index.ts +30 -5
  12. package/cli/minicode.js +6 -0
  13. package/cli/setup.ts +365 -24
  14. package/cli/tui.ts +72 -27
  15. package/docs/TERMINAL_CONTRACT.md +91 -24
  16. package/docs/agents.md +2 -2
  17. package/docs/cli.md +1 -0
  18. package/docs/environment.md +1 -0
  19. package/docs/memory-sessions.md +5 -0
  20. package/package.json +3 -2
  21. package/src/app/session.ts +153 -35
  22. package/src/app/tool-layer.ts +67 -61
  23. package/src/daemon/approvals.ts +25 -1
  24. package/src/daemon/client.ts +51 -1
  25. package/src/daemon/control.ts +8 -0
  26. package/src/daemon/protocol.ts +47 -1
  27. package/src/daemon/server.ts +45 -9
  28. package/src/daemon/subscription.ts +25 -1
  29. package/src/daemon/telemetry.ts +4 -0
  30. package/src/hooks/run.ts +5 -1
  31. package/src/mcp/client.ts +349 -90
  32. package/src/mcp/http-transport.ts +7 -0
  33. package/src/mcp/transport.ts +5 -0
  34. package/src/memory/files.ts +69 -3
  35. package/src/memory/vector.ts +556 -160
  36. package/src/policy/approval-binding.ts +199 -0
  37. package/src/policy/context.ts +20 -1
  38. package/src/policy/executor.ts +44 -5
  39. package/src/policy/permission.ts +243 -26
  40. package/src/policy/tool-contract.ts +77 -0
  41. package/src/policy/usage.ts +3 -1
  42. package/src/policy/work-mode.ts +49 -1
  43. package/src/presentation/adapter.ts +157 -7
  44. package/src/presentation/events.ts +173 -1
  45. package/src/presentation/model.ts +37 -0
  46. package/src/presentation/projection.ts +107 -18
  47. package/src/presentation/reducer.ts +134 -10
  48. package/src/sandbox/os.ts +18 -1
  49. package/src/session/persistence.ts +153 -11
  50. package/src/task/store.ts +43 -3
  51. package/src/tools/memory.ts +70 -10
  52. package/src/tools/task.ts +7 -1
  53. package/src/tools/todo.ts +14 -4
  54. package/src/ui/approval/prompt.ts +52 -7
  55. package/src/ui/assistant/simple.ts +160 -57
  56. package/src/ui/contract.ts +46 -0
  57. package/src/ui/footer.ts +14 -5
  58. package/src/ui/i18n/en.ts +9 -0
  59. package/src/ui/i18n/id.ts +9 -0
  60. package/src/ui/render/collapse.ts +24 -52
  61. package/src/ui/render/detail.ts +14 -9
  62. package/src/ui/render/errors.ts +8 -0
  63. package/src/ui/render/reasoning.ts +13 -8
  64. package/src/ui/session-state.ts +243 -0
  65. package/src/ui/tui/app.ts +7 -3
  66. package/src/ui/tui/transcript.ts +271 -30
  67. package/vendor/minicore/src/core/budget.ts +25 -25
  68. package/vendor/minicore/src/core/compact.ts +75 -75
  69. package/vendor/minicore/src/core/errors.ts +59 -59
  70. package/vendor/minicore/src/core/events.ts +73 -73
  71. package/vendor/minicore/src/core/executor.ts +139 -139
  72. package/vendor/minicore/src/core/history.ts +31 -31
  73. package/vendor/minicore/src/core/index.ts +41 -41
  74. package/vendor/minicore/src/core/loop.ts +355 -355
  75. package/vendor/minicore/src/core/permission.ts +22 -22
  76. package/vendor/minicore/src/core/provider.ts +39 -39
  77. package/vendor/minicore/src/core/recovery.ts +35 -35
  78. package/vendor/minicore/src/core/session.ts +327 -327
  79. package/vendor/minicore/src/core/snapshot.ts +146 -146
  80. package/vendor/minicore/src/core/tokens.ts +107 -107
  81. package/vendor/minicore/src/core/tool.ts +115 -115
  82. package/vendor/minicore/src/core/types.ts +50 -50
  83. package/vendor/minicore/src/providers/openai-compat.ts +417 -417
@@ -12,19 +12,11 @@ import type {
12
12
  UiStep,
13
13
  } from "../contract.ts"
14
14
  import { t } from "../i18n/locale.ts"
15
- import {
16
- clearCollapsedSections,
17
- collapse,
18
- rememberCollapsedSection,
19
- sectionMinimized,
20
- } from "../render/collapse.ts"
21
- import { detail } from "../render/detail.ts"
22
15
  import { renderDiffCard } from "../render/diff.ts"
23
16
  import { formatArgsPreview, formatProviderError, formatUsage } from "../render/format.ts"
24
17
  import { highlightCode } from "../render/highlight.ts"
25
18
  import { decorateMarkdown, type FenceMatch, parseFence, renderInline } from "../render/markdown.ts"
26
19
  import { MarkdownTableStream } from "../render/markdown-table.ts"
27
- import { reasoning } from "../render/reasoning.ts"
28
20
  import {
29
21
  cleanUntrusted,
30
22
  createStreamSanitizer,
@@ -37,6 +29,15 @@ import { c, glyphs, stripAnsi } from "../render/theme.ts"
37
29
  import { displayWidth, truncateToWidth } from "../render/width.ts"
38
30
  import { formatWrapped } from "../render/wrap.ts"
39
31
  import { runWithoutStatus } from "../runtime/statusline.ts"
32
+ // [Area A · PROMPT 06] State UI per-sesi. Printer linier memakai state SESI
33
+ // miliknya (diteruskan composition root), bukan singleton modul — dua sesi di
34
+ // satu proses tak lagi saling menimpa minimize/compact/reasoning.
35
+ import {
36
+ defaultUiState,
37
+ LAST_TURN_MAX_CHARS,
38
+ MAX_COPY_TURNS,
39
+ type UiSessionState,
40
+ } from "../session-state.ts"
40
41
 
41
42
  export interface SimpleOptions {
42
43
  verbose?: boolean
@@ -51,41 +52,50 @@ export interface SimpleOptions {
51
52
  onPresentationEvent?: (handler: (event: UiPresentationEvent) => void) => () => void
52
53
  /** Kebijakan kanonik dari composition root; absen = logika inline legacy. */
53
54
  policy?: PresentationPolicy
55
+ /**
56
+ * [Area A · PROMPT 06] State UI milik SESI ini. Absen = instance default
57
+ * modul (dipakai one-shot/test) — jalur produksi WAJIB mengoper instance
58
+ * sesinya supaya dua sesi dalam satu proses tak saling menimpa.
59
+ */
60
+ uiState?: UiSessionState
54
61
  }
55
62
 
56
63
  // Buffer output turn terakhir untuk /copy: teks model (sudah sanitize, sama
57
64
  // seperti yang terlihat) + isi hasil tool string. BUKAN transcript penuh —
58
65
  // scrollback milik terminal; ini konten yang berguna ditempel ulang. Cap agar
59
66
  // sesi panjang tak membengkakkan memori.
60
- const LAST_TURN_MAX_CHARS = 200_000
61
- export const MAX_COPY_TURNS = 10
62
- let lastTurnText = ""
63
- let previousTurnTexts: string[] = []
67
+ //
68
+ // [Area A · PROMPT 06] Buffer ini kini milik `UiSessionState` (per sesi),
69
+ // bukan variabel modul. Fungsi modul di bawah tetap eksport demi kompatibilitas
70
+ // dan mendelegasikan ke instance default.
71
+ export { MAX_COPY_TURNS }
64
72
 
65
73
  /** Isi output turn terakhir (teks model + hasil tool). */
66
74
  export function getLastTurnText(): string {
67
- return lastTurnText
75
+ return defaultUiState.getLastTurnText()
68
76
  }
69
77
 
70
78
  export function getLastTurnTexts(count = 1): string[] {
71
- const all = lastTurnText ? [...previousTurnTexts, lastTurnText] : [...previousTurnTexts]
72
- const n = Number.isFinite(count) ? Math.max(1, Math.floor(count)) : 1
73
- return all.slice(-n)
79
+ return defaultUiState.getLastTurnTexts(count)
74
80
  }
75
81
 
76
- const archiveTurn = (): void => {
77
- if (!lastTurnText) return
78
- previousTurnTexts.push(lastTurnText)
79
- if (previousTurnTexts.length > MAX_COPY_TURNS) previousTurnTexts.shift()
80
- lastTurnText = ""
82
+ /**
83
+ * [Area A] Reset eksplisit buffer /copy + error tertunda milik instance
84
+ * default modul. Dipakai oleh sesi/uji yang butuh kekaburan; attach logger
85
+ * TIDAK lagi wipe buffer (itu yang merusak `/copy [n]` untuk n>1).
86
+ */
87
+ export function resetCopyBuffer(): void {
88
+ defaultUiState.resetCopyBuffer()
89
+ }
90
+
91
+ const archiveTurn = (ui: UiSessionState): void => {
92
+ ui.archiveTurn()
81
93
  }
82
94
 
83
- const rememberTurn = (s: string) => {
95
+ const rememberTurn = (ui: UiSessionState, s: string) => {
84
96
  if (!s) return
85
97
  // Samakan dengan yang terlihat: kebijakan pipa (F2) berlaku juga untuk /copy.
86
- lastTurnText += process.stdout.isTTY ? s : stripSgr(s)
87
- if (lastTurnText.length > LAST_TURN_MAX_CHARS)
88
- lastTurnText = lastTurnText.slice(-LAST_TURN_MAX_CHARS)
98
+ ui.appendTurnText(process.stdout.isTTY ? s : stripSgr(s))
89
99
  }
90
100
 
91
101
  /**
@@ -113,12 +123,14 @@ const wErrDirect = (s: string) =>
113
123
  // Alasan: error tengah-turn sering pulih via fallback router; mencetak tiap
114
124
  // event + sekali lagi di catch driver = dua blok ✗ untuk satu kegagalan.
115
125
  // Driver (index.ts/repl.ts) mencetak sekali via takePendingError().
116
- let pendingError: string | null = null
126
+ //
127
+ // [Area A · PROMPT 06] Error tertunda milik SESI (state per-sesi), bukan
128
+ // variabel modul — dua sesi dalam satu proses tak lagi saling menimpa
129
+ // pesan error. Fungsi modul delegate ke instance default.
130
+ export { LAST_TURN_MAX_CHARS }
117
131
  /** Ambil + kosongkan error tertunda (consume-once per turn). */
118
132
  export function takePendingError(): string | null {
119
- const e = pendingError
120
- pendingError = null
121
- return e
133
+ return defaultUiState.takePendingError()
122
134
  }
123
135
 
124
136
  // Batas tampilan expanded — ADAPTIF terhadap tinggi terminal, bukan konstanta
@@ -153,8 +165,9 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
153
165
  // Shadowing disengaja agar ~20 call-site tak perlu diubah satu per satu.
154
166
  const wOut = opts.quiet ? (_: string) => {} : wOutDirect
155
167
  const wErr = opts.quiet ? (_: string) => {} : wErrDirect
156
- previousTurnTexts = []
157
- lastTurnText = ""
168
+ // [Area A · PROMPT 06] State UI milik instance ini. Composition root mengoper
169
+ // state SESI; tanpa itu (one-shot/test) jatuh ke instance default modul.
170
+ const ui: UiSessionState = opts.uiState ?? defaultUiState
158
171
  const tableStream = new MarkdownTableStream()
159
172
  let plainLineBuffer = ""
160
173
  // Sanitizer sadar-stream per aliran teks (temuan F1): ekor escape yang
@@ -197,7 +210,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
197
210
  // Jawaban tak pernah disembunyikan di pipa/CI (output mesin harus utuh)
198
211
  // dan --verbose selalu menampilkan semua.
199
212
  const answerHidden = (): boolean =>
200
- sectionMinimized("answer") && !!process.stdout.isTTY && !opts.verbose
213
+ ui.sectionMinimized("answer") && !!process.stdout.isTTY && !opts.verbose
201
214
  const emitAnswer = (s: string) => {
202
215
  if (!answerHidden()) {
203
216
  wOut(s)
@@ -278,7 +291,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
278
291
  // Petunjuk /expand WAJIB di baris ini: tanpa itu jawaban yang dikecilkan
279
292
  // terlihat "bisu" (tak ada cara membuka yang bisa ditemukan user).
280
293
  wErr(c.info(t("one.answerMin", { n, cap })))
281
- rememberCollapsedSection("answer", answerBuf, "stdout")
294
+ ui.rememberCollapsedSection("answer", answerBuf, "stdout")
282
295
  answerBuf = ""
283
296
  answerTruncated = false
284
297
  }
@@ -286,11 +299,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
286
299
  const flushThinking = () => {
287
300
  flushReasoningTail()
288
301
  if (thinkState === "min" && thinkingBuf) {
289
- rememberCollapsedSection("thinking", thinkingBuf)
302
+ ui.rememberCollapsedSection("thinking", thinkingBuf)
290
303
  thinkingBuf = ""
291
304
  }
292
305
  thinkState = "off"
293
- collapse.setActiveSection(null)
306
+ ui.setActiveSection(null)
294
307
  }
295
308
 
296
309
  const flushLine = (line: string) => {
@@ -343,6 +356,9 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
343
356
  const presentationEnabled = !!opts.getSnapshot
344
357
  const presentedTerminals = new Set<string>()
345
358
  const presentedVerifications = new Set<string>()
359
+ // F-TASK-1: dedup baris ledger status task (id+status+revisi) — event yang
360
+ // sama tak boleh muncul dua kali bila konsumen memutar ulang sebagian stream.
361
+ const presentedTaskStatuses = new Set<string>()
346
362
  const presentationSnapshot = (): UiPresentationSnapshot | null => {
347
363
  if (!presentationEnabled || !opts.getSnapshot) return null
348
364
  try {
@@ -400,9 +416,52 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
400
416
  if (status === "completed") return c.success(line)
401
417
  return c.muted(line)
402
418
  }
419
+ // F-AGENT-1: label run pendek stabil (`run_<8>` | `sub_<8>`) — identitas anak,
420
+ // sama dengan TUI, supaya failure tool anak paralel tak saling tertukar.
421
+ const runMarker = (activity: UiPresentationActivity | undefined): string => {
422
+ const id = activity?.runId ?? activity?.childSessionId
423
+ if (!id) return ""
424
+ const prefix = id.startsWith("run_") ? "run_" : id.startsWith("sub_") ? "sub_" : ""
425
+ const bare = id.slice(prefix.length).replace(/-/g, "")
426
+ return prefix + bare.slice(0, 8)
427
+ }
403
428
  const writePresentationTerminal = (event: UiPresentationEvent): void => {
404
429
  if (!presentationEnabled) return
405
430
  flushTableStream()
431
+ // F-TASK-1: status task kanonik juga punya baris ledger di jalur linear
432
+ // (scrollback non-TTY). Sebelum ini event hanya hidup di TUI + machine
433
+ // envelope — pengguna `minicode exec`/pipe tak pernah melihatnya.
434
+ if (event.type === "task.status") {
435
+ const id = event.taskId
436
+ const raw = event.taskStatus
437
+ if (id === undefined || raw === undefined) return
438
+ const key = `${id}:${raw}:${event.revision ?? ""}`
439
+ if (presentedTaskStatuses.has(key)) return
440
+ presentedTaskStatuses.add(key)
441
+ const status = sanitizeAnsiLine(String(raw).toLowerCase())
442
+ const parent = event.parentId ? ` parent=${sanitizeAnsiLine(event.parentId)}` : ""
443
+ const deps = event.dependsOn?.length
444
+ ? ` dependsOn=[${event.dependsOn.map((d) => sanitizeAnsiLine(d)).join(",")}]`
445
+ : ""
446
+ const rev = event.revision !== undefined ? ` r${event.revision}` : ""
447
+ const verify =
448
+ raw === "COMPLETED"
449
+ ? event.taskVerification?.verdict === "passed"
450
+ ? " [verified]"
451
+ : ` [${event.taskVerification?.verdict ?? "unverified"}]`
452
+ : ""
453
+ const line = ` ${glyphs.bullet} ${sanitizeAnsiLine(id)} ${status}${parent}${deps}${rev}${verify}`
454
+ const paint =
455
+ raw === "FAILED"
456
+ ? c.error(line)
457
+ : raw === "BLOCKED"
458
+ ? c.warning(line)
459
+ : raw === "COMPLETED"
460
+ ? c.success(line)
461
+ : c.muted(line)
462
+ wErr(`${paint}\n`)
463
+ return
464
+ }
406
465
  // Observasi verifikasi punya baris sendiri (dedup per invocation):
407
466
  // terminal tool sudah tampil duluan dan baris linear append-only.
408
467
  // Baris ini tak pernah mengklaim status tool.
@@ -423,6 +482,42 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
423
482
  wErr(`${verification.verdict === "present" ? c.success(line) : c.muted(line)}\n`)
424
483
  return
425
484
  }
485
+ // P1.5: consequence/context diagnostics juga tampil di scrollback linear.
486
+ // Sebelumnya hanya TUI/machine yang melihatnya.
487
+ if (event.type === "consequence.decided") {
488
+ const verdict = String(event.verdict ?? "UNKNOWN")
489
+ const cls = event.failureClass ? ` class=${sanitizeAnsiLine(String(event.failureClass))}` : ""
490
+ const next = event.nextAction ? ` next=${sanitizeAnsiLine(String(event.nextAction))}` : ""
491
+ const why = event.message ?? event.reason
492
+ const detail = why
493
+ ? `: ${truncateToWidth(sanitizeAnsi(String(why)), 200, "…").split("\n")[0] ?? ""}`
494
+ : ""
495
+ const line = ` ${glyphs.bullet} consequence ${sanitizeAnsiLine(verdict)}${cls}${next}${detail}`
496
+ const paint =
497
+ verdict === "FAIL" || verdict === "BLOCKED"
498
+ ? c.error(line)
499
+ : verdict === "PASS"
500
+ ? c.success(line)
501
+ : c.warning(line)
502
+ wErr(`${paint}\n`)
503
+ return
504
+ }
505
+ if (event.type === "context.cutoff") {
506
+ const reason = event.reason ? `: ${sanitizeAnsiLine(String(event.reason))}` : ""
507
+ wErr(`${c.warning(` ${glyphs.bullet} context cutoff${reason}`)}\n`)
508
+ return
509
+ }
510
+ if (event.type === "context.window") {
511
+ const used = event.usedTokens
512
+ const window = event.windowTokens
513
+ const pct = event.percent != null ? ` ${Math.round(event.percent)}%` : ""
514
+ const tokens =
515
+ used != null
516
+ ? ` ${used.toLocaleString()}${window ? `/${window.toLocaleString()}` : ""} tokens`
517
+ : ""
518
+ wErr(`${c.muted(` ${glyphs.bullet} context window${tokens}${pct}`)}\n`)
519
+ return
520
+ }
426
521
  if (
427
522
  event.type !== "tool.failed" &&
428
523
  event.type !== "tool.denied" &&
@@ -443,7 +538,14 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
443
538
  const detail = message
444
539
  ? `: ${truncateToWidth(sanitizeAnsi(String(message)), 200, "…").split("\n")[0] ?? ""}`
445
540
  : ""
446
- const line = ` ${glyphs.arrow} ${name}${targetText}${linearSuffix(activity)}${detail}`
541
+ // F-AGENT-1: tool anak dirender sebagai baris run sendiri (`↳ <marker>`),
542
+ // bukan dicampur ke baris root — identitas childSessionId/runId tiap run.
543
+ // Child tanpa identitas run tetap tampil (kegagalan tak boleh hilang),
544
+ // hanya tanpa marker.
545
+ const isChild = activity?.parentToolCallId !== undefined
546
+ const marker = runMarker(activity)
547
+ const prefix = isChild ? ` ↳ ${marker ? `${marker} ` : ""}` : ` ${glyphs.arrow} `
548
+ const line = `${prefix}${name}${targetText}${linearSuffix(activity)}${detail}`
447
549
  wErr(paintTerminal(status, `${line}\n`))
448
550
  }
449
551
 
@@ -463,12 +565,13 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
463
565
  reasoningLine = ""
464
566
  answerBuf = ""
465
567
  answerTruncated = false
466
- clearCollapsedSections()
467
- collapse.setActiveSection(null)
468
- archiveTurn()
469
- pendingError = null
568
+ ui.clearCollapsedSections()
569
+ ui.setActiveSection(null)
570
+ archiveTurn(ui)
571
+ ui.setPendingError(null)
470
572
  presentedTerminals.clear()
471
573
  presentedVerifications.clear()
574
+ presentedTaskStatuses.clear()
472
575
 
473
576
  if (opts.verbose) wErr(c.muted(t("one.turnHead", { n: e.turn })))
474
577
  }),
@@ -494,7 +597,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
494
597
  // Teks = jawaban; section-nya ikut collapse (minimize → buffer + expand
495
598
  // via + / /expand), kecuali pipa/CI/verbose yang selalu stream.
496
599
  flushThinking()
497
- collapse.setActiveSection("answer")
600
+ ui.setActiveSection("answer")
498
601
  if (!answerHidden() && answerBuf.length > 0) {
499
602
  wErr(c.muted(t("one.answerOpen")))
500
603
  wOut(answerBuf)
@@ -502,7 +605,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
502
605
  answerTruncated = false
503
606
  }
504
607
  const clean = cleanUntrusted(textSan.push(e.text), !!process.stdout.isTTY)
505
- rememberTurn(clean)
608
+ rememberTurn(ui, clean)
506
609
  consumeTableEvents(tableStream.push(clean))
507
610
  }),
508
611
  )
@@ -512,12 +615,12 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
512
615
  // Section thinking: reasoning.visible = expanded (stream), else
513
616
  // minimized (satu baris ` + thinking`, isi di-buffer untuk /expand).
514
617
  // Toggle runtime /thinking, Ctrl+T, atau tombol + / - saat busy.
515
- collapse.setActiveSection("thinking")
618
+ ui.setActiveSection("thinking")
516
619
  const d = e.data as { text?: string }
517
620
  const text = d.text ?? ""
518
621
  // --verbose = semua terlihat (expanded). Kalau tidak, reasoning.visible
519
622
  // menentukan: true = stream live, false = ` + thinking` + buffer.
520
- const expanded = opts.verbose || reasoning.visible
623
+ const expanded = opts.verbose || ui.reasoningVisible
521
624
  if (expanded) {
522
625
  if (thinkState !== "exp") {
523
626
  thinkState = "exp"
@@ -580,7 +683,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
580
683
  }
581
684
  } else if (e.kind === "error") {
582
685
  const d = e.data as { message?: string; category?: string }
583
- pendingError = formatProviderError(d)
686
+ ui.setPendingError(formatProviderError(d))
584
687
  } else if (e.kind === "content_filter") {
585
688
  wErr(c.warning(t("one.contentBlocked")))
586
689
  }
@@ -604,11 +707,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
604
707
  bus.on("execution:started", (e) => {
605
708
  flushTableStream()
606
709
  // Section aktif = tool yang sedang jalan — target tombol + / - saat busy.
607
- collapse.setActiveSection("tool")
710
+ ui.setActiveSection("tool")
608
711
  // Ganti fase: sisa baris thinking yang belum ber-newline dicetak dulu
609
712
  // agar tak menempel ke baris tool.
610
713
  flushReasoningTail()
611
- if (detail.compact) {
714
+ if (ui.compact) {
612
715
  // Mode compact: TIDAK ada baris start. Aktivitas ditampilkan oleh
613
716
  // garis status "Thinking"/nama tool (TTY) atau diam (non-TTY) — baris
614
717
  // `running x... ` lama tanpa newline menempel ke baris ✓ berikutnya
@@ -644,11 +747,11 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
644
747
  // Hasil string ikut ke buffer /copy (versi sanitize, cap per-add agar
645
748
  // satu read_file raksasa tak langsung memenuhi buffer sendirian).
646
749
  if (!isError && typeof r.content === "string")
647
- rememberTurn(truncateToWidth(sanitizeAnsi(r.content), 20000, ""))
750
+ rememberTurn(ui, truncateToWidth(sanitizeAnsi(r.content), 20000, ""))
648
751
  if (isError) {
649
752
  // Error tool ditampilkan ringkas per baris (cap 200 kolom + marker) —
650
753
  // tanpa marker user tak bisa bedakan "pesan 200 kolom" vs "terpotong".
651
- collapse.setActiveSection(null)
754
+ ui.setActiveSection(null)
652
755
  wErr(
653
756
  c.error(
654
757
  ` ${glyphs.arrow} ${sanitizeAnsiLine(name)}${suffix}: ${truncateToWidth(sanitizeAnsi(String(r.content)), 200, "…")}\n`,
@@ -660,13 +763,13 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
660
763
  // Section tool dikecilkan: satu baris ` + label`, isi di-buffer untuk
661
764
  // /expand. Ledger lain (chevron) tetap satu baris — ini menggantikan
662
765
  // pencetakan isi (bash/edit/diff/content tool), bukan marker.
663
- if (sectionMinimized("tool")) {
664
- collapse.setActiveSection(null)
766
+ if (ui.sectionMinimized("tool")) {
767
+ ui.setActiveSection(null)
665
768
  const label = activity?.summary
666
769
  ? sanitizeAnsiLine(activity.summary)
667
770
  : fallbackToolLabel(name, args, target)
668
771
  wErr(c.info(` + ${label}${suffix}\n`))
669
- rememberCollapsedSection(label, sanitizeAnsi(String(r.content ?? "")).trim())
772
+ ui.rememberCollapsedSection(label, sanitizeAnsi(String(r.content ?? "")).trim())
670
773
  return
671
774
  }
672
775
  if (name === "write_file" && target) {
@@ -688,7 +791,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
688
791
  : patchBlocks(args.patches)
689
792
  // Expanded: diff adalah inti perubahan — tampilkan inline. Compact
690
793
  // jatuh ke baris ringkasan seperti sebelumnya.
691
- if (!detail.compact && (oldT || newT)) {
794
+ if (!ui.compact && (oldT || newT)) {
692
795
  wOut(
693
796
  `${renderDiffCard(sanitizeAnsiLine(target), sanitizeAnsi(oldT), sanitizeAnsi(newT), {
694
797
  maxLines: DIFF_MAX_LINES,
@@ -721,7 +824,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
721
824
  // di sini — cabang compact di bawah dan expanded map di-sanitize lagi
722
825
  // (idempoten) sehingga tak ada cabang yang mentah.
723
826
  const lines = sanitizeAnsi(String(r.content)).trim().split("\n").filter(Boolean)
724
- if (detail.compact) {
827
+ if (ui.compact) {
725
828
  const preview =
726
829
  lines.length > 3
727
830
  ? lines.slice(0, 3).join("\n ") + c.muted(t("one.more3", { n: lines.length - 3 }))
@@ -744,7 +847,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
744
847
  // Tool penghasil KONTEN (isi berkas, hasil cari) di mode compact cukup
745
848
  // satu baris › + target — isinya milik model untuk dibaca, bukan untuk
746
849
  // membanjiri scrollback pengguna. Konten tetap bisa dilihat via expanded.
747
- if (detail.compact && CONTENT_TOOLS.has(name)) {
850
+ if (ui.compact && CONTENT_TOOLS.has(name)) {
748
851
  const label = activity?.summary
749
852
  ? sanitizeAnsiLine(activity.summary)
750
853
  : truncateWords(sanitizeAnsiLine(target ?? formatArgsPreview(args)), 120)
@@ -756,7 +859,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
756
859
  )
757
860
  return
758
861
  }
759
- if (!detail.compact && CONTENT_TOOLS.has(name)) {
862
+ if (!ui.compact && CONTENT_TOOLS.has(name)) {
760
863
  // Expanded: hasil berupa KONTEN (isi berkas, hasil cari) ikut mengalir.
761
864
  const raw = sanitizeAnsi(String(r.content ?? "")).trim()
762
865
  const lines = raw ? raw.split("\n") : []
@@ -784,7 +887,7 @@ export function attachSimpleLogger(bus: UiBus, opts: SimpleOptions = {}): () =>
784
887
  const first = sanitizeAnsi(String(r.content)).trim().split("\n")[0] ?? ""
785
888
  const preview = truncateToWidth(first, 80, "")
786
889
  const cleanName = sanitizeAnsiLine(name)
787
- if (!detail.compact && preview) {
890
+ if (!ui.compact && preview) {
788
891
  wErr(
789
892
  c.success(
790
893
  ` ${glyphs.arrow} ${cleanName}${label ? ` ${label}` : ""}${suffix} ${c.muted(preview)}\n`,
@@ -142,6 +142,9 @@ export interface UiPresentationActivity {
142
142
  denyReason?: string
143
143
  receipt?: UiPresentationReceipt
144
144
  parentToolCallId?: string
145
+ /** F-AGENT-1: identitas sub-agent (session anak + run kanonik). */
146
+ childSessionId?: string
147
+ runId?: string
145
148
  supersedes?: string
146
149
  expandRef?: { toolCallId: string; idx: number }
147
150
  verification?: UiVerificationDisplay
@@ -181,6 +184,12 @@ export interface UiPresentationSystem {
181
184
  text: string
182
185
  reason?: string
183
186
  severity: "info" | "warning" | "error" | "critical"
187
+ /** F-TASK-1: field terstruktur status task (absen untuk notice lain). */
188
+ taskId?: string
189
+ taskStatus?: string
190
+ parentId?: string
191
+ dependsOn?: string[]
192
+ revision?: number
184
193
  }
185
194
 
186
195
  export interface UiPresentationPlan {
@@ -192,6 +201,10 @@ export interface UiPresentationPlan {
192
201
  stepId: string
193
202
  title?: string
194
203
  status: "pending" | "active" | "completed" | "cancelled" | "blocked"
204
+ /** F-TASK-1: identitas task kanonik (`t<n>`) bila resolusi total. */
205
+ taskId?: string
206
+ /** F-TASK-1: posisi tampil (bukan identitas). */
207
+ ordinal?: number
195
208
  }>
196
209
  }
197
210
 
@@ -308,9 +321,18 @@ export interface UiPresentationEvent {
308
321
  | "diagnostic.raised"
309
322
  | "checkpoint.created"
310
323
  | "verification.observed"
324
+ | "consequence.decided"
325
+ | "context.window"
326
+ | "context.cutoff"
327
+ | "task.status"
311
328
  seq?: number
312
329
  turnId?: number
313
330
  stepId?: number
331
+ /** P1.6: session pemilik event (anak untuk event forward), bukan selalu induk. */
332
+ sessionId?: string
333
+ /** P1.6: identitas sub-agent yang membedakan session vs run vs taut pemanggil. */
334
+ childSessionId?: string
335
+ runId?: string
314
336
  toolCallId?: string
315
337
  approvalId?: string
316
338
  name?: string
@@ -353,6 +375,30 @@ export interface UiPresentationEvent {
353
375
  stepId: string
354
376
  title?: string
355
377
  status: "pending" | "active" | "completed" | "cancelled" | "blocked"
378
+ /** F-TASK-1: identitas task kanonik (`t<n>`). */
379
+ taskId?: string
380
+ /** F-TASK-1: posisi tampil (bukan identitas). */
381
+ ordinal?: number
356
382
  }>
357
383
  evidence?: string[]
384
+ // ── P1 Observability & Interaction (aditif) ──
385
+ verdict?: string
386
+ failureClass?: string
387
+ nextAction?: string
388
+ newEvidenceSinceLastAttempt?: boolean
389
+ riskTier?: string
390
+ diffPreview?: string
391
+ schemaDrift?: { serverId: string; toolName: string }
392
+ taskId?: string
393
+ taskStatus?: string
394
+ parentId?: string
395
+ dependsOn?: string[]
396
+ revision?: number
397
+ /** P1.5: COMPLETED + bukan `passed` = unverified (bukan PASS). */
398
+ taskVerification?: { verdict: "passed" | "failed" | "unverified"; checkedAt?: string }
399
+ usedTokens?: number
400
+ windowTokens?: number
401
+ percent?: number
402
+ costUsd?: number
403
+ providerModel?: string
358
404
  }
package/src/ui/footer.ts CHANGED
@@ -30,6 +30,12 @@ export interface FooterStatus {
30
30
  cwd: string
31
31
  /** Jumlah konteks polos (mis. "14.2k"). Kosong = tak ditampilkan. */
32
32
  context?: string
33
+ /**
34
+ * F-CTX-1: metrik usage (biaya + window %), sudah diformat pemanggil
35
+ * (mis. "$0.0601 42%"). Kosong = tak ditampilkan. Render hanya meletakkan;
36
+ * angka dihitung di lapisan cli (bukan di sini) agar tak ada estimasi.
37
+ */
38
+ metrics?: string
33
39
  /**
34
40
  * Frame animasi spark: 0 = idle (spark redup statis), >0 = busy (pulse
35
41
  * putih↔abu). Chrome yang menaikkan frame saat turn berjalan; render hanya
@@ -136,7 +142,10 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
136
142
 
137
143
  const target = Math.max(4, cols - 1)
138
144
  const ctx = s.context ? sanitizeAnsiLine(s.context) : ""
139
- const ctxW = ctx ? displayWidth(ctx) : 0
145
+ const metrics = s.metrics ? sanitizeAnsiLine(s.metrics) : ""
146
+ // F-CTX-1: metrik usage menempel di kiri blok konteks (satu blok rata kanan).
147
+ const rightTxt = [ctx, metrics].filter(Boolean).join(" ")
148
+ const rightW = displayWidth(rightTxt)
140
149
 
141
150
  // Rata kanan: konteks didorong ke kolom `target` dengan gap ideal ≥6
142
151
  // agar rapi dan tidak mepet (keluhan: terlalu rapat → 1→2→4→6).
@@ -144,10 +153,10 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
144
153
  // tangga di bawah, bukan konteks yang dilepas.
145
154
  const align = (left: string): string => {
146
155
  const lw = displayWidth(left)
147
- if (!ctx) return left
148
- if (lw + ctxW + 2 > target) return left
149
- const gap = Math.max(6, target - lw - ctxW)
150
- return `${left}${" ".repeat(gap)}${c.gray(ctx)}`
156
+ if (!rightTxt) return left
157
+ if (lw + rightW + 2 > target) return left
158
+ const gap = Math.max(6, target - lw - rightW)
159
+ return `${left}${" ".repeat(gap)}${c.gray(rightTxt)}`
151
160
  }
152
161
 
153
162
  // Tangga prioritas buang saat sempit: cwd penuh → cwd diperpendek → model
package/src/ui/i18n/en.ts CHANGED
@@ -30,6 +30,13 @@ export const en = {
30
30
  "appr.askTitle": "Agent asks",
31
31
  "appr.a11y": "[approval required: {name}]",
32
32
  "appr.answerPrompt": "Your answer (empty = cancel): ",
33
+ "appr.risk": "Risk:",
34
+ "appr.diff": "Diff:",
35
+ "appr.tier.pure": "read-only",
36
+ "appr.tier.workspace": "workspace edit",
37
+ "appr.tier.localenv": "local env change",
38
+ "appr.tier.external": "irreversible external effect",
39
+ "appr.tier.unknown": "unknown effect",
33
40
  "dlg.more": "… {n} more",
34
41
  "ts.compacted": "… compacted: {reason}",
35
42
  "ts.thinking": "… thinking",
@@ -124,6 +131,8 @@ export const en = {
124
131
  "st.model": " Model: {v}",
125
132
  "st.provider": " Provider: {v}",
126
133
  "st.tools": " Tools: {v}",
134
+ "st.workMode": " WorkMode: {v} (intent layer)",
135
+ "st.permissionMode": " Permission: {v} (allow/deny authority)",
127
136
  "st.context": " Context: ~{v} tok (window estimate)",
128
137
  "st.turn": " Turn: {v} (last turn only)",
129
138
  "st.input": " Input: {v} (provider usage)",
package/src/ui/i18n/id.ts CHANGED
@@ -31,6 +31,13 @@ export const id: Record<MsgKey, string> = {
31
31
  "appr.askTitle": "Agen bertanya",
32
32
  "appr.a11y": "[butuh persetujuan: {name}]",
33
33
  "appr.answerPrompt": "Jawaban (kosong = batal): ",
34
+ "appr.risk": "Risiko:",
35
+ "appr.diff": "Perubahan:",
36
+ "appr.tier.pure": "hanya-baca",
37
+ "appr.tier.workspace": "ubah berkas workspace",
38
+ "appr.tier.localenv": "ubah lingkungan lokal",
39
+ "appr.tier.external": "efek eksternal ireversibel",
40
+ "appr.tier.unknown": "efek tidak diketahui",
34
41
  "dlg.more": "… {n} lagi",
35
42
  "ts.compacted": "… dipadatkan: {reason}",
36
43
  "ts.thinking": "… berpikir",
@@ -125,6 +132,8 @@ export const id: Record<MsgKey, string> = {
125
132
  "st.model": " Model: {v}",
126
133
  "st.provider": " Penyedia: {v}",
127
134
  "st.tools": " Perkakas: {v}",
135
+ "st.workMode": " WorkMode: {v} (lapis intent)",
136
+ "st.permissionMode": " Izin: {v} (otoritas allow/deny)",
128
137
  "st.context": " Konteks: ~{v} tok (estimasi jendela)",
129
138
  "st.turn": " Turn: {v} (turn terakhir saja)",
130
139
  "st.input": " Masukan: {v} (pemakaian provider)",