minicode-ai 0.11.0 → 0.13.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 (221) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/LICENSE +21 -21
  3. package/README.md +4 -4
  4. package/cli/args.ts +46 -0
  5. package/cli/commands/acp.ts +163 -10
  6. package/cli/commands/config.ts +33 -18
  7. package/cli/commands/daemon.ts +515 -0
  8. package/cli/commands/exec.ts +145 -53
  9. package/cli/commands/openwork.ts +986 -0
  10. package/cli/commands/sessions.ts +4 -1
  11. package/cli/commands/stats.ts +34 -4
  12. package/cli/commands.ts +217 -2
  13. package/cli/index.ts +146 -14
  14. package/cli/recovery-warning.ts +115 -0
  15. package/cli/router.ts +32 -1
  16. package/cli/setup.ts +2332 -171
  17. package/cli/tui.ts +113 -7
  18. package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +489 -0
  19. package/docs/OUTPUT_EVENT_MODEL.md +289 -0
  20. package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +391 -0
  21. package/docs/OUTPUT_PROTOCOL_SPEC.md +285 -0
  22. package/docs/OUTPUT_RENDERING_SPEC.md +248 -0
  23. package/docs/OUTPUT_UX_RULES.md +449 -0
  24. package/docs/PLAN_UIUX_V6.md +2 -2
  25. package/docs/README.md +4 -3
  26. package/docs/TERMINAL_CONTRACT.md +278 -66
  27. package/docs/architecture.md +89 -7
  28. package/docs/changelog.md +1 -1
  29. package/docs/choosing-mode.md +2 -2
  30. package/docs/cli.md +9 -5
  31. package/docs/concepts.md +1 -1
  32. package/docs/contributing.md +9 -2
  33. package/docs/environment.md +6 -2
  34. package/docs/exec.md +46 -5
  35. package/docs/memory-sessions.md +2 -0
  36. package/docs/policy-sandbox.md +1 -1
  37. package/docs/pricing-budget.md +1 -1
  38. package/docs/quickstart.md +2 -2
  39. package/docs/repl.md +6 -2
  40. package/docs/security-model.md +1 -1
  41. package/docs/security.md +1 -1
  42. package/docs/skills.md +2 -2
  43. package/docs/terminal.md +9 -5
  44. package/docs/tools.md +1 -1
  45. package/package.json +35 -5
  46. package/src/app/session.ts +261 -15
  47. package/src/app/tool-layer.ts +94 -7
  48. package/src/daemon/approvals.ts +361 -0
  49. package/src/daemon/capability.ts +145 -0
  50. package/src/daemon/children.ts +142 -0
  51. package/src/daemon/client.ts +267 -0
  52. package/src/daemon/control.ts +350 -0
  53. package/src/daemon/discovery.ts +234 -0
  54. package/src/daemon/feed.ts +155 -0
  55. package/src/daemon/framing.ts +94 -0
  56. package/src/daemon/host.ts +316 -0
  57. package/src/daemon/protocol.ts +217 -0
  58. package/src/daemon/resource.ts +170 -0
  59. package/src/daemon/sanitize.ts +57 -0
  60. package/src/daemon/server.ts +627 -0
  61. package/src/daemon/store.ts +317 -0
  62. package/src/daemon/subscription.ts +270 -0
  63. package/src/daemon/telemetry.ts +81 -0
  64. package/src/hooks/run.ts +12 -1
  65. package/src/lib/atomic-write.ts +29 -3
  66. package/src/lib/db-path.ts +26 -0
  67. package/src/lib/keystore.ts +544 -42
  68. package/src/lib/net.ts +43 -1
  69. package/src/lib/safe-open.ts +116 -1
  70. package/src/lib/session-id.ts +15 -0
  71. package/src/lsp/client.ts +123 -5
  72. package/src/mcp/client.ts +139 -17
  73. package/src/mcp/server.ts +177 -50
  74. package/src/mcp/transport.ts +16 -19
  75. package/src/memory/vector.ts +770 -55
  76. package/src/policy/allowlist.ts +14 -2
  77. package/src/policy/bash-guard.ts +105 -10
  78. package/src/policy/compaction.ts +82 -5
  79. package/src/policy/consequence-engine.ts +220 -0
  80. package/src/policy/context.ts +132 -0
  81. package/src/policy/executor.ts +187 -121
  82. package/src/policy/no-progress.ts +559 -0
  83. package/src/policy/permission.ts +4 -8
  84. package/src/policy/pricing.ts +17 -3
  85. package/src/policy/scrub.ts +69 -2
  86. package/src/policy/tool-contract.ts +515 -0
  87. package/src/policy/usage.ts +310 -24
  88. package/src/policy/verifier.ts +6 -3
  89. package/src/policy/work-mode.ts +182 -0
  90. package/src/presentation/adapter.ts +533 -26
  91. package/src/presentation/events.ts +151 -0
  92. package/src/presentation/model.ts +180 -27
  93. package/src/presentation/projection.ts +858 -0
  94. package/src/presentation/reducer.ts +645 -310
  95. package/src/presentation/store.ts +12 -7
  96. package/src/providers/anthropic.ts +18 -10
  97. package/src/providers/responses.ts +17 -7
  98. package/src/runtime/capability.ts +409 -0
  99. package/src/runtime/child-execution.ts +274 -0
  100. package/src/runtime/composition.ts +958 -0
  101. package/src/runtime/dispatch.ts +591 -0
  102. package/src/runtime/execution-backend.ts +632 -0
  103. package/src/runtime/execution-events.ts +272 -0
  104. package/src/runtime/execution-id.ts +230 -0
  105. package/src/runtime/execution-journal.ts +926 -0
  106. package/src/runtime/execution-kernel.ts +456 -0
  107. package/src/runtime/execution-registry.ts +379 -0
  108. package/src/runtime/process-supervision.ts +276 -0
  109. package/src/runtime/production-execution.ts +551 -0
  110. package/src/runtime/production-runtime.ts +217 -0
  111. package/src/runtime/recovery-safety.ts +70 -0
  112. package/src/runtime/recovery.ts +477 -0
  113. package/src/runtime/runtime-capabilities.ts +179 -0
  114. package/src/runtime/runtime-diagnostics.ts +141 -0
  115. package/src/runtime/runtime-host.ts +365 -0
  116. package/src/runtime/runtime-status-facts.ts +222 -0
  117. package/src/runtime/runtime-status-provider.ts +74 -0
  118. package/src/runtime/runtime-status.ts +459 -0
  119. package/src/runtime/runtime-task-admission.ts +101 -0
  120. package/src/runtime/supervisor.ts +444 -0
  121. package/src/session/authority.ts +168 -0
  122. package/src/session/checkpoint.ts +88 -1
  123. package/src/session/context-adapter.ts +251 -0
  124. package/src/session/context-assembly.ts +242 -0
  125. package/src/session/context-identity.ts +389 -0
  126. package/src/session/context-projection.ts +248 -0
  127. package/src/session/context-selector.ts +500 -0
  128. package/src/session/cross-session-adoption.ts +249 -0
  129. package/src/session/full-history-fold.ts +171 -0
  130. package/src/session/identity.ts +192 -0
  131. package/src/session/journal.ts +805 -102
  132. package/src/session/open-work-intent.ts +732 -0
  133. package/src/session/open-work.ts +767 -0
  134. package/src/session/pending-tools.ts +94 -0
  135. package/src/session/persistence.ts +3569 -127
  136. package/src/session/runtime-header.ts +208 -0
  137. package/src/session/shadow-git.ts +13 -5
  138. package/src/session/verification.ts +1623 -0
  139. package/src/task/assignment.ts +136 -0
  140. package/src/task/autonomous-adapter.ts +168 -0
  141. package/src/task/autonomous-context.ts +630 -0
  142. package/src/task/autonomous-policy.ts +490 -0
  143. package/src/task/continuity.ts +179 -0
  144. package/src/task/execution-cancellation.ts +165 -0
  145. package/src/task/graph-validate.ts +379 -0
  146. package/src/task/graph.ts +305 -0
  147. package/src/task/identity.ts +230 -0
  148. package/src/task/model.ts +417 -0
  149. package/src/task/production-scheduler.ts +293 -0
  150. package/src/task/readiness.ts +229 -0
  151. package/src/task/scheduler-observability.ts +387 -0
  152. package/src/task/scheduler.ts +1197 -0
  153. package/src/task/scheduling-policy.ts +165 -0
  154. package/src/task/session-authority.ts +148 -0
  155. package/src/task/session-ownership.ts +211 -0
  156. package/src/task/store.ts +2887 -0
  157. package/src/task/sync.ts +343 -0
  158. package/src/task/trigger.ts +260 -0
  159. package/src/tools/bash.ts +377 -211
  160. package/src/tools/code_run.ts +1 -1
  161. package/src/tools/delete_file.ts +1 -1
  162. package/src/tools/edit.ts +33 -6
  163. package/src/tools/evidence.ts +30 -0
  164. package/src/tools/git.ts +4 -4
  165. package/src/tools/glob.ts +12 -3
  166. package/src/tools/grep.ts +1 -1
  167. package/src/tools/lsp.ts +4 -4
  168. package/src/tools/mcp_call.ts +11 -4
  169. package/src/tools/memory.ts +153 -18
  170. package/src/tools/move_file.ts +1 -1
  171. package/src/tools/patch.ts +1 -1
  172. package/src/tools/read_file.ts +1 -1
  173. package/src/tools/read_image.ts +1 -1
  174. package/src/tools/submit_result.ts +1 -1
  175. package/src/tools/task.ts +437 -41
  176. package/src/tools/todo.ts +662 -35
  177. package/src/tools/web_fetch.ts +4 -2
  178. package/src/tools/web_search.ts +9 -3
  179. package/src/tools/write_file.ts +1 -1
  180. package/src/ui/assistant/simple.ts +123 -50
  181. package/src/ui/assistant/turn-status.ts +17 -3
  182. package/src/ui/contract.ts +184 -0
  183. package/src/ui/footer.ts +54 -18
  184. package/src/ui/i18n/en.ts +62 -6
  185. package/src/ui/i18n/id.ts +62 -6
  186. package/src/ui/input/prompt-engine.ts +120 -25
  187. package/src/ui/render/errors.ts +39 -1
  188. package/src/ui/render/markdown-table.ts +455 -0
  189. package/src/ui/render/markdown.ts +22 -1
  190. package/src/ui/render/table-grid.ts +184 -0
  191. package/src/ui/render/table.ts +15 -76
  192. package/src/ui/runtime/screen.ts +7 -2
  193. package/src/ui/runtime/statusline.ts +25 -6
  194. package/src/ui/tui/app.ts +598 -133
  195. package/src/ui/tui/transcript.ts +531 -89
  196. package/vendor/minicore/VENDOR.md +1 -1
  197. package/vendor/minicore/src/core/budget.ts +25 -25
  198. package/vendor/minicore/src/core/compact.ts +75 -75
  199. package/vendor/minicore/src/core/errors.ts +59 -59
  200. package/vendor/minicore/src/core/events.ts +73 -73
  201. package/vendor/minicore/src/core/executor.ts +139 -139
  202. package/vendor/minicore/src/core/history.ts +31 -31
  203. package/vendor/minicore/src/core/index.ts +41 -41
  204. package/vendor/minicore/src/core/loop.ts +355 -355
  205. package/vendor/minicore/src/core/permission.ts +22 -22
  206. package/vendor/minicore/src/core/provider.ts +39 -39
  207. package/vendor/minicore/src/core/recovery.ts +35 -35
  208. package/vendor/minicore/src/core/session.ts +327 -327
  209. package/vendor/minicore/src/core/snapshot.ts +146 -146
  210. package/vendor/minicore/src/core/tokens.ts +107 -107
  211. package/vendor/minicore/src/core/tool.ts +115 -115
  212. package/vendor/minicore/src/core/types.ts +50 -50
  213. package/vendor/minicore/src/providers/openai-compat.ts +417 -417
  214. package/AGENTS.md +0 -45
  215. package/PLAN.md +0 -491
  216. package/docs/ARCHITECTURE.html +0 -1248
  217. package/docs/CONTROL-PLANE-MAP.md +0 -139
  218. package/docs/HARNESS.md +0 -150
  219. package/docs/SUMMARY.md +0 -52
  220. package/docs/UI_RENDER_PIPELINE.md +0 -165
  221. package/docs/USAGE.md +0 -11
package/src/ui/footer.ts CHANGED
@@ -4,19 +4,28 @@
4
4
  // Frame animasi spark dan angka konteks DIKIRIM pemanggil lewat FooterStatus,
5
5
  // jadi render tetap deterministik dan bisa diuji tanpa menunggu waktu.
6
6
  //
7
- // Gaya (keputusan produk): footer hampir tak terlihat — garis + teks status
8
- // abu-abu gelap; SATU-SATUNYA yang berwarna adalah token mode (mapping sama
9
- // dengan prompt lama: plan kuning, ask biru, sisanya hijau).
7
+ // Gaya (keputusan produk): footer hampir tak terlihat; field dipisahkan
8
+ // dengan spasi dan warna, tanpa bullet separator. Mode memakai mapping warna
9
+ // yang sama dengan prompt lama: plan kuning, ask biru, sisanya hijau.
10
10
  //
11
- // Tata letak: `✦ mode • model • cwd ……… 14.2k` — konteks rata kanan. Mode
12
- // di-pad ke lebar tetap agar teks di kanannya TIDAK bergeser saat mode berganti
13
- // (Shift+Tab): tanpa padding, `auto`→`allowlist` menggeser seluruh baris.
11
+ // Tata letak: `✦ 00.00.00 mode model cwd ……… 14.2k` — konteks rata kanan.
12
+ // Mode di-pad ke lebar tetap agar teks di kanannya TIDAK bergeser saat mode
13
+ // berganti (Shift+Tab): tanpa padding, `auto`→`allowlist` menggeser seluruh baris.
14
14
  import { sanitizeAnsiLine } from "./render/sanitize.ts"
15
15
  import { c, glyphs } from "./render/theme.ts"
16
16
  import { displayWidth, padToWidth, truncateToWidth } from "./render/width.ts"
17
17
 
18
+ export type TimerHighlight = "seconds" | "minutes" | "hours"
19
+
18
20
  export interface FooterStatus {
19
21
  mode: string
22
+ /**
23
+ * P12 S2.2 Slice 5 — WorkMode aktif sesi (DISCUSS|PLAN|EXECUTE). Hanya
24
+ * ditampilkan bila bukan EXECUTE: label jadi `<WorkMode>·<permission mode>`
25
+ * (mis. `PLAN·auto`, `DISCUSS·auto`) agar dua lapis intent/permission bisa
26
+ * dibedakan. EXECUTE (default) = perilaku lama, label permission mode saja.
27
+ */
28
+ workMode?: string
20
29
  model: string
21
30
  cwd: string
22
31
  /** Jumlah konteks polos (mis. "14.2k"). Kosong = tak ditampilkan. */
@@ -27,6 +36,10 @@ export interface FooterStatus {
27
36
  * memetakan frame → glyph berwarna.
28
37
  */
29
38
  sparkFrame?: number
39
+ activity?: string
40
+ timer?: string
41
+ timerActive?: boolean
42
+ timerHighlight?: TimerHighlight
30
43
  }
31
44
 
32
45
  /** Lebar tetap kolom mode — `allowlist`/`allow-all` (9) adalah yang terpanjang. */
@@ -42,13 +55,20 @@ export function shortModel(id: string): string {
42
55
  * Warna + PAD token mode. Padding dilakukan sebelum pewarnaan supaya lebar
43
56
  * kolom mode tetap sama untuk semua mode (anti-geser), sementara warna tetap
44
57
  * dipilih dari nama mode asli.
58
+ *
59
+ * P12 S2.2 Slice 5 - WorkMode non-EXECUTE digabung ke label (`PLAN·auto`):
60
+ * dua lapis intent/permission dibedakan dalam satu token. Warna mengikuti
61
+ * lapis yang lebih ketat (WorkMode DISCUSS/PLAN -> warning seperti plan PM).
45
62
  */
46
- export function paintFooterMode(mode: string): string {
63
+ export function paintFooterMode(mode: string, workMode?: string): string {
64
+ const restrictive = workMode === "DISCUSS" || workMode === "PLAN"
65
+ const label = restrictive ? `${workMode}·${mode}` : mode
47
66
  // Padding per KOLOM (bukan padEnd karakter): CJK/emoji = 2 kolom, dan
48
67
  // displayWidth sudah dipakai di bawah — konsisten satu penggaris.
49
68
  // Mode satu-baris: newline dari input tak terpercaya wajib dibuang agar tak
50
69
  // memecah frame lengket 2-baris chrome.ts.
51
- const padded = padToWidth(sanitizeAnsiLine(mode), MODE_WIDTH)
70
+ const padded = padToWidth(sanitizeAnsiLine(label), MODE_WIDTH)
71
+ if (restrictive) return c.warning(padded)
52
72
  return mode === "plan" ? c.warning(padded) : mode === "ask" ? c.info(padded) : c.success(padded)
53
73
  }
54
74
 
@@ -59,6 +79,17 @@ function sparkGlyph(frame: number): string {
59
79
  return frame % 2 === 0 ? c.white(g) : c.gray(g)
60
80
  }
61
81
 
82
+ function paintTimer(text: string, active: boolean, highlight: TimerHighlight = "seconds"): string {
83
+ if (!active) return c.faint(text)
84
+ const parts = text.split(".")
85
+ if (parts.length !== 3) return c.white(text)
86
+ const rank: Record<TimerHighlight, number> = { seconds: 1, minutes: 2, hours: 3 }
87
+ const level = rank[highlight]
88
+ const part = (value: string, required: number): string =>
89
+ level >= required ? c.white(value) : c.faint(value)
90
+ return `${part(parts[0]!, 3)}${c.faint(".")}${part(parts[1]!, 2)}${c.faint(".")}${part(parts[2]!, 1)}`
91
+ }
92
+
62
93
  /**
63
94
  * Perpendek path agar muat di terminal sedang tanpa membuang CWD sepenuhnya.
64
95
  * Mis. "D:\git\minicode\src\ui" -> "...\src\ui"
@@ -84,20 +115,24 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
84
115
  const cols = Math.max(10, Math.floor(columns) || 80)
85
116
 
86
117
  const spark = sparkGlyph(s.sparkFrame ?? 0)
87
- const mode = paintFooterMode(s.mode)
88
- const dot = c.gray("•")
89
- const sep = ` ${dot} `
118
+ const timerText = s.timer ? sanitizeAnsiLine(s.timer) : ""
119
+ const timer = timerText
120
+ ? `${paintTimer(timerText, s.timerActive === true, s.timerHighlight)} `
121
+ : ""
122
+ const lead = `${spark} ${timer}`
123
+ const mode = paintFooterMode(s.mode, s.workMode)
124
+ const fieldGap = " "
90
125
  // Satu-baris: cwd/model bisa berisi newline (nama dir) — sanitizeAnsiLine
91
126
  // agar \n tak memecah frame lengket ke scrollback (displayWidth menghitung
92
127
  // \n = 0 sehingga align mengira muat).
93
128
  const model = c.gray(sanitizeAnsiLine(shortModel(s.model)))
94
- const cwdTxt = c.gray(sanitizeAnsiLine(s.cwd))
95
- const shortCwdTxt = c.gray(sanitizeAnsiLine(shortenPath(s.cwd)))
129
+ const cwdTxt = c.muted(sanitizeAnsiLine(s.cwd))
130
+ const shortCwdTxt = c.muted(sanitizeAnsiLine(shortenPath(s.cwd)))
96
131
 
97
- const full = `${spark} ${mode}${sep}${model}${sep}${cwdTxt}`
98
- const shortened = `${spark} ${mode}${sep}${model}${sep}${shortCwdTxt}`
99
- const mid = `${spark} ${mode}${sep}${model}`
100
- const lean = `${spark} ${mode}`
132
+ const full = `${lead}${mode}${fieldGap}${model}${fieldGap}${cwdTxt}`
133
+ const shortened = `${lead}${mode}${fieldGap}${model}${fieldGap}${shortCwdTxt}`
134
+ const mid = `${lead}${mode}${fieldGap}${model}`
135
+ const lean = `${lead}${mode}`
101
136
 
102
137
  const target = Math.max(4, cols - 1)
103
138
  const ctx = s.context ? sanitizeAnsiLine(s.context) : ""
@@ -115,7 +150,8 @@ export function renderFooter(s: FooterStatus, columns: number): string[] {
115
150
  return `${left}${" ".repeat(gap)}${c.gray(ctx)}`
116
151
  }
117
152
 
118
- // Tangga prioritas buang saat sempit: cwd penuh → cwd diperpendek → model (spark+mode+context kekal).
153
+ // Tangga prioritas buang saat sempit: cwd penuh → cwd diperpendek → model
154
+ // (spark + timer + mode + context tetap punya ruang).
119
155
  const candidates = shortCwdTxt !== cwdTxt ? [full, shortened, mid, lean] : [full, mid, lean]
120
156
  for (const left of candidates) {
121
157
  const line = align(left)
package/src/ui/i18n/en.ts CHANGED
@@ -6,7 +6,14 @@ export const en = {
6
6
  "app.menuHeader": "─ commands ─",
7
7
  "app.moreLines": " … {n} more",
8
8
  "app.newBelow": "↓ {n} new lines below · PgDn to bottom",
9
- "app.abortHint": "abort sent — press Esc/Ctrl+C again to quit",
9
+ "app.abortHint": "abort sent — press Esc again to quit",
10
+ "app.working": "Working",
11
+ "app.thinking": "Thinking",
12
+ "app.running": "Running",
13
+ "app.stopping": "Stopping",
14
+ "tui.selectionCopied": "selection copied to clipboard",
15
+ "tui.selectionCopyFailed": "selection could not be copied (OSC 52 unavailable)",
16
+ "tui.selectionTooLarge": "selection too large to copy",
10
17
  "form.idleWarning": "idle — canceling in {s}s (press any key to keep editing)",
11
18
  "appr.title": "Approval required",
12
19
  "appr.tool": "Tool:",
@@ -126,15 +133,17 @@ export const en = {
126
133
  "st.budget": " Budget: {v}{extra}",
127
134
  "st.costUnknown": " (cost unknown — model without pricing)",
128
135
  "help.head": "Commands:",
129
- "help.keysLine": "PgUp/PgDn scroll (Shift = half) · /help keys = all shortcuts",
136
+ "help.keysLine": "Mouse wheel/PgUp/PgDn scroll (Shift = half) · /help keys = all shortcuts",
130
137
  "help.cHead": "Commands:",
131
- "help.cKeys": "Keys: Tab mode · ↑↓ history · PgUp/PgDn scroll · Ctrl+R search · Ctrl+D exit",
138
+ "help.cKeys":
139
+ "Keys: Tab mode · ↑↓ history · Mouse wheel/PgUp/PgDn scroll · Ctrl+R search · Ctrl+D exit",
132
140
  "help.cMore": " /help keys = all shortcuts",
133
141
  "help.kHead": "Keyboard:",
134
142
  "help.k.submit": "submit",
135
143
  "help.k.cycleMode": "cycle permission mode",
136
144
  "help.k.history": "prompt history (in picker: navigate)",
137
- "help.k.scroll": "scroll transcript (Shift+ = half page)",
145
+ "help.k.mouse": "scroll transcript with mouse wheel",
146
+ "help.k.scroll": "scroll transcript with PgUp/PgDn (Shift+ = half page)",
138
147
  "help.k.jumpTop": "jump to transcript top / back to tail (empty prompt only)",
139
148
  "help.k.move": "move cursor",
140
149
  "help.k.jump": "jump to line start / end",
@@ -147,7 +156,7 @@ export const en = {
147
156
  "help.k.compact": "toggle compact/expanded tool output",
148
157
  "help.k.thinking": "toggle expand/minimize thinking output",
149
158
  "help.k.esc": "close dropdown / picker / clear line (busy: abort turn)",
150
- "help.k.ctrlC": "clear line (busy: abort turn)",
159
+ "help.k.ctrlC": "clear line / cancel prompt (TUI turn: use Esc)",
151
160
  "help.k.ctrlD": "exit on empty line",
152
161
  "help.desc.help": "Show commands",
153
162
  "help.desc.provider": "Manage providers",
@@ -158,12 +167,52 @@ export const en = {
158
167
  "help.desc.init": "Create AGENTS.md",
159
168
  "help.desc.exit": "Exit",
160
169
  "help.desc.mode": "Show or set permission mode",
170
+ "help.desc.work-mode": "Show or set work mode (intent layer)",
161
171
  "help.desc.lang": "Show or set UI language",
162
172
  "help.desc.undo": "Revert file changes from the last turn",
163
173
  "help.desc.redo": "Re-apply reverted changes",
164
174
  "help.desc.clear": "Clear transcript",
165
- "help.desc.copy": "Copy last turn to clipboard (OSC 52)",
175
+ "help.desc.copy": "Copy the last 1–10 turns to clipboard (OSC 52)",
166
176
  "help.desc.history": "Show recent prompt history",
177
+ "help.desc.scheduler": "Inspect, trigger, or stop the autonomous scheduler",
178
+
179
+ // [PHASE 6AB] Operator strings for `/scheduler`. The STATE line itself is
180
+ // deliberately not localised - see `describeOperatorState`, which the
181
+ // production-path tests assert verbatim. Everything around it is.
182
+ "sched.usage": "usage: /scheduler [status|run|stop]",
183
+ "sched.title": "Autonomous scheduler",
184
+ "sched.state": "state",
185
+ "sched.session": "session",
186
+ "sched.authority": "authority",
187
+ "sched.held": "held (lease acquired)",
188
+ "sched.none": "not held",
189
+ "sched.counts": "counters",
190
+ "sched.cEvaluated": "evaluated",
191
+ "sched.cCoalesced": "coalesced",
192
+ "sched.cRefused": "refused",
193
+ "sched.cExec": "executions",
194
+ "sched.cFail": "failures",
195
+ "sched.lastTask": "last task",
196
+ "sched.lastStop": "last cycle stop",
197
+ "sched.lastError": "last error",
198
+ "sched.recent": "recent activity",
199
+ "sched.unavailable":
200
+ "scheduler control is unavailable in this invocation — the scheduler exists only in the interactive session.",
201
+ "sched.notEnabled":
202
+ "scheduler is OFF for this process. Start it with --enable-scheduler to enable it.",
203
+ "sched.notActive":
204
+ "scheduler is not active (stopped, shut down, or its session authority was lost). It cannot be triggered; restart the process to re-enable.",
205
+ "sched.running": "evaluating the task graph…",
206
+ "sched.ranDone": "scheduling cycle completed.",
207
+ "sched.ranNothing": "scheduling cycle completed: no task was ready to run.",
208
+ "sched.coalesced": "a cycle was already running; this request was folded into it.",
209
+ "sched.refusedNotRunning":
210
+ "trigger refused: the scheduler is not running. Nothing was scheduled.",
211
+ "sched.refusedPending": "trigger refused: a re-run is already pending. Nothing changed.",
212
+ "sched.refusedUnknown": "trigger refused for an unknown reason. Nothing was scheduled.",
213
+ "sched.stopped":
214
+ "scheduler stopped: no further triggers, no new claims, and session authority released.",
215
+ "sched.alreadyStopped": "scheduler was already stopped; nothing to do.",
167
216
  "tui.budgetOver":
168
217
  "[budget] {spent} > {budget} — over budget, new prompts rejected. /exit to quit.",
169
218
  "tui.budgetUnknown":
@@ -172,9 +221,16 @@ export const en = {
172
221
  "tui.budget80": "[budget] {spent} / {budget} (80% used)",
173
222
  "tui.copyNone": "(nothing to copy yet — run a prompt first)",
174
223
  "tui.copyOk": "copied {n} chars (OSC 52 — allow clipboard access in terminal if empty)",
224
+ "tui.copyOkMany":
225
+ "copied {turns} turns ({n} chars · OSC 52 — allow clipboard access in terminal if empty)",
226
+ "tui.copyInvalid": "invalid turn count: {n} (use 1–{max})",
175
227
  "tui.copyNeedTty": "(clipboard needs a TTY terminal)",
176
228
  "tui.unknownMode": "unknown mode: {a} — choices: {modes}",
177
229
  "tui.modeLine": "mode: {m}",
230
+ "tui.workModeUnknown": "unknown work mode: {a} — choices: {modes}",
231
+ "tui.workModeLine": "work mode: {m}",
232
+ "tui.workModeUsage": "usage: /work-mode <DISCUSS|PLAN|EXECUTE> — current: {m}",
233
+ "tui.workModeUnavailable": "work mode is not available in this session",
178
234
  "tui.langLine": "lang: {v}",
179
235
  "tui.toolCall": "tool call: {v}",
180
236
  "tui.modelSet": "model: {v}",
package/src/ui/i18n/id.ts CHANGED
@@ -7,7 +7,14 @@ export const id: Record<MsgKey, string> = {
7
7
  "app.menuHeader": "─ perintah ─",
8
8
  "app.moreLines": " … {n} lagi",
9
9
  "app.newBelow": "↓ {n} baris baru di bawah · PgDn ke ekor",
10
- "app.abortHint": "abort terkirim — tekan Esc/Ctrl+C sekali lagi untuk keluar",
10
+ "app.abortHint": "abort terkirim — tekan Esc sekali lagi untuk keluar",
11
+ "app.working": "Bekerja",
12
+ "app.thinking": "Berpikir",
13
+ "app.running": "Menjalankan",
14
+ "app.stopping": "Menghentikan",
15
+ "tui.selectionCopied": "selection disalin ke clipboard",
16
+ "tui.selectionCopyFailed": "selection tidak bisa disalin (OSC 52 tidak tersedia)",
17
+ "tui.selectionTooLarge": "selection terlalu besar untuk disalin",
11
18
  "form.idleWarning": "diam — dibatalkan dalam {s} dtk (tekan sembarang tombol untuk lanjut)",
12
19
  "appr.title": "Perlu persetujuan",
13
20
  "appr.tool": "Alat:",
@@ -127,15 +134,17 @@ export const id: Record<MsgKey, string> = {
127
134
  "st.budget": " Budget: {v}{extra}",
128
135
  "st.costUnknown": " (biaya tak diketahui — model tanpa harga)",
129
136
  "help.head": "Perintah:",
130
- "help.keysLine": "PgUp/PgDn gulir (Shift = ½) · /help tombol = semua pintasan",
137
+ "help.keysLine": "Mouse wheel/PgUp/PgDn gulir (Shift = ½) · /help tombol = semua pintasan",
131
138
  "help.cHead": "Perintah:",
132
- "help.cKeys": "Tombol: Tab mode · ↑↓ riwayat · PgUp/PgDn gulir · Ctrl+R cari · Ctrl+D keluar",
139
+ "help.cKeys":
140
+ "Tombol: Tab mode · ↑↓ riwayat · Mouse wheel/PgUp/PgDn gulir · Ctrl+R cari · Ctrl+D keluar",
133
141
  "help.cMore": " /help tombol = semua pintasan",
134
142
  "help.kHead": "Papan tombol:",
135
143
  "help.k.submit": "kirim",
136
144
  "help.k.cycleMode": "putar mode izin",
137
145
  "help.k.history": "riwayat prompt (di picker: navigasi)",
138
- "help.k.scroll": "gulir transkrip (Shift+ = setengah halaman)",
146
+ "help.k.mouse": "gulir transkrip dengan mouse wheel",
147
+ "help.k.scroll": "gulir transkrip dengan PgUp/PgDn (Shift+ = setengah halaman)",
139
148
  "help.k.jumpTop": "lompat ke atas transkrip / kembali ke ekor (hanya prompt kosong)",
140
149
  "help.k.move": "geser kursor",
141
150
  "help.k.jump": "lompat ke awal/akhir baris",
@@ -148,7 +157,7 @@ export const id: Record<MsgKey, string> = {
148
157
  "help.k.compact": "alihkan output tool ringkas/penuh",
149
158
  "help.k.thinking": "alihkan thinking bentang/ringkas",
150
159
  "help.k.esc": "tutup dropdown/picker/hapus baris (busy: batalkan turn)",
151
- "help.k.ctrlC": "hapus baris (busy: batalkan turn)",
160
+ "help.k.ctrlC": "hapus baris / batalkan prompt (turn TUI: pakai Esc)",
152
161
  "help.k.ctrlD": "keluar saat baris kosong",
153
162
  "help.desc.help": "Tampilkan perintah",
154
163
  "help.desc.provider": "Kelola penyedia",
@@ -159,12 +168,52 @@ export const id: Record<MsgKey, string> = {
159
168
  "help.desc.init": "Buat AGENTS.md",
160
169
  "help.desc.exit": "Keluar",
161
170
  "help.desc.mode": "Tampilkan atau set mode izin",
171
+ "help.desc.work-mode": "Tampilkan atau set work mode (lapis intent)",
162
172
  "help.desc.lang": "Tampilkan atau set bahasa UI",
163
173
  "help.desc.undo": "Urungkan perubahan berkas dari turn terakhir",
164
174
  "help.desc.redo": "Terapkan ulang yang diurungkan",
165
175
  "help.desc.clear": "Bersihkan transkrip",
166
- "help.desc.copy": "Salin turn terakhir ke clipboard (OSC 52)",
176
+ "help.desc.copy": "Salin 1–10 turn terakhir ke clipboard (OSC 52)",
167
177
  "help.desc.history": "Tampilkan riwayat prompt",
178
+ "help.desc.scheduler": "Periksa, picu, atau hentikan scheduler otonom",
179
+
180
+ // [PHASE 6AB] Operator strings for `/scheduler`.
181
+ "sched.usage": "pakai: /scheduler [status|run|stop]",
182
+ "sched.title": "Scheduler otonom",
183
+ "sched.state": "keadaan",
184
+ "sched.session": "sesi",
185
+ "sched.authority": "otoritas",
186
+ "sched.held": "dimiliki (lease diambil)",
187
+ "sched.none": "tidak dimiliki",
188
+ "sched.counts": "penghitung",
189
+ "sched.cEvaluated": "dievaluasi",
190
+ "sched.cCoalesced": "digabung",
191
+ "sched.cRefused": "ditolak",
192
+ "sched.cExec": "eksekusi",
193
+ "sched.cFail": "kegagalan",
194
+ "sched.lastTask": "tugas terakhir",
195
+ "sched.lastStop": "henti siklus terakhir",
196
+ "sched.lastError": "galat terakhir",
197
+ "sched.recent": "aktivitas terbaru",
198
+ "sched.unavailable":
199
+ "kendali scheduler tidak tersedia pada pemanggilan ini — scheduler hanya ada di sesi interaktif.",
200
+ "sched.notEnabled":
201
+ "scheduler MATI untuk proses ini. Jalankan dengan --enable-scheduler untuk menyalakannya.",
202
+ "sched.notActive":
203
+ "scheduler tidak aktif (dihentikan, ditutup, atau otoritas sesinya hilang). Tidak dapat dipicu; jalankan ulang proses untuk menyalakan lagi.",
204
+ "sched.running": "mengevaluasi grafik tugas…",
205
+ "sched.ranDone": "siklus penjadwalan selesai.",
206
+ "sched.ranNothing": "siklus penjadwalan selesai: tidak ada tugas yang siap dijalankan.",
207
+ "sched.coalesced": "siklus sedang berjalan; permintaan ini digabung ke dalamnya.",
208
+ "sched.refusedNotRunning":
209
+ "pemicuan ditolak: scheduler tidak berjalan. Tidak ada yang dijadwalkan.",
210
+ "sched.refusedPending":
211
+ "pemicuan ditolak: sudah ada pengulangan yang tertunda. Tidak ada yang berubah.",
212
+ "sched.refusedUnknown":
213
+ "pemicuan ditolak karena alasan tidak diketahui. Tidak ada yang dijadwalkan.",
214
+ "sched.stopped":
215
+ "scheduler dihentikan: tidak ada pemicu lanjutan, tidak ada klaim baru, dan otoritas sesi dilepaskan.",
216
+ "sched.alreadyStopped": "scheduler sudah dihentikan; tidak ada yang perlu dilakukan.",
168
217
  "tui.budgetOver":
169
218
  "[budget] {spent} > {budget} — melebihi budget, prompt baru ditolak. /exit untuk keluar.",
170
219
  "tui.budgetUnknown":
@@ -173,9 +222,16 @@ export const id: Record<MsgKey, string> = {
173
222
  "tui.budget80": "[budget] {spent} / {budget} (80% terpakai)",
174
223
  "tui.copyNone": "(belum ada yang disalin — jalankan prompt dulu)",
175
224
  "tui.copyOk": "tersalin {n} chars (OSC 52 — izinkan akses clipboard di terminal bila kosong)",
225
+ "tui.copyOkMany":
226
+ "tersalin {turns} turn ({n} chars · OSC 52 — izinkan akses clipboard di terminal bila kosong)",
227
+ "tui.copyInvalid": "jumlah turn tidak valid: {n} (gunakan 1–{max})",
176
228
  "tui.copyNeedTty": "(clipboard butuh terminal TTY)",
177
229
  "tui.unknownMode": "mode tidak dikenal: {a} — pilihan: {modes}",
178
230
  "tui.modeLine": "mode: {m}",
231
+ "tui.workModeUnknown": "work mode tidak dikenal: {a} — pilihan: {modes}",
232
+ "tui.workModeLine": "mode kerja: {m}",
233
+ "tui.workModeUsage": "pemakaian: /work-mode <DISCUSS|PLAN|EXECUTE> — aktif: {m}",
234
+ "tui.workModeUnavailable": "work mode tidak tersedia di sesi ini",
179
235
  "tui.langLine": "lang: {v}",
180
236
  "tui.toolCall": "pemanggilan tool: {v}",
181
237
  "tui.modelSet": "model: {v}",
@@ -43,11 +43,18 @@ export type PromptKey =
43
43
  | { type: "end" }
44
44
  | { type: "up" }
45
45
  | { type: "down" }
46
- // PgUp/PgDn (ESC[5~/[6~) — di TUI scroll viewport transkrip, bukan histori.
47
- // modifier (kode xterm, 0 = polos): 2 = shift — Shift+PgUp/PgDn = setengah
48
- // halaman (temuan audit TUI-002).
49
46
  | { type: "pageup"; modifier?: number }
50
47
  | { type: "pagedown"; modifier?: number }
48
+ | { type: "wheelup" }
49
+ | { type: "wheeldown" }
50
+ | {
51
+ type: "mouse"
52
+ action: "press" | "release" | "drag" | "move"
53
+ button: 0 | 1 | 2 | null
54
+ x: number
55
+ y: number
56
+ modifiers: number
57
+ }
51
58
  | { type: "tab" }
52
59
  | { type: "enter" }
53
60
  | { type: "esc" }
@@ -278,7 +285,7 @@ export function applyKey(
278
285
  case "ctrl-t": // toggle expand/minimize reasoning di REPL (onKey)
279
286
  case "ctrl-n": // tambah model — ditangani view yang membutuhkan (model-manager); di prompt teks diabaikan
280
287
  case "shift-tab": // cycle mode — ditangani REPL lewat onKey askLine
281
- case "ignore": // byte mouse dsb: dibuang, tidak boleh jadi teks
288
+ case "ignore":
282
289
  return { state, action: "none" }
283
290
  case "ctrl-u": {
284
291
  if (!state.line.length) return { state, action: "none" }
@@ -288,8 +295,9 @@ export function applyKey(
288
295
  // applyKey; engine netral (tanpa ini switch tak exhaustive → tsc merah).
289
296
  case "pageup":
290
297
  case "pagedown":
291
- // Scroll ditangani App TUI SEBELUM applyKey (I18); engine netral
292
- // (tanpa ini switch tak exhaustive → tsc merah).
298
+ case "wheelup":
299
+ case "wheeldown":
300
+ case "mouse":
293
301
  return { state, action: "none" }
294
302
  case "ctrl-w": {
295
303
  if (state.cursor === 0) return { state, action: "none" }
@@ -345,15 +353,10 @@ export function buildRenderSpec(
345
353
  // ── Binari dari chunk stdin -> keystroke stream ──
346
354
  // Rust-style manual parsing: ESC [ A/B/C/D = arrows, ESC = esc, dsb.
347
355
  export function decodeKeys(buf: Uint8Array): DecodedKey[] {
348
- const out: DecodedKey[] = []
349
- const s = new TextDecoder("utf-8").decode(buf)
350
- let i = 0
351
- while (i < s.length) {
352
- const d = decodeKey(s, i)
353
- d && out.push(d)
354
- i += d?.width ?? 1
355
- }
356
- return out
356
+ return decodeKeysStream(buf, createDecoderState()).map((decoded) => ({
357
+ ...decoded,
358
+ width: Math.max(1, decoded.width),
359
+ }))
357
360
  }
358
361
 
359
362
  export interface DecodedKey {
@@ -486,17 +489,41 @@ export function decodeKeysStream(chunk: Uint8Array, state: DecoderState): Decode
486
489
  }
487
490
  // Mouse X10: ESC[M + 3 byte koordinat MENTAH (bukan UTF-8).
488
491
  if (n1 === 0x5b && buf[i + 2] === 0x4d) {
489
- if (i + 6 > buf.length) break // byte koordinat terpotong — tahan
490
- out.push({ key: { type: "ignore" }, width: 0 })
492
+ if (i + 6 > buf.length) break
493
+ const button = buf[i + 3]! - 0x20
494
+ const x = buf[i + 4]! - 31
495
+ const y = buf[i + 5]! - 31
496
+ out.push({
497
+ key: mouseKeyForReport(button, mouseActionForButton(button), x, y),
498
+ width: 6,
499
+ })
491
500
  i += 6
492
501
  continue
493
502
  }
494
- // Mouse SGR: ESC[< … M|m
495
503
  if (n1 === 0x5b && buf[i + 2] === 0x3c) {
496
504
  let j = i + 3
497
505
  while (j < buf.length && buf[j] !== 0x4d && buf[j] !== 0x6d) j++
498
- if (j >= buf.length) break // terminator belum tiba — tahan
499
- out.push({ key: { type: "ignore" }, width: 0 })
506
+ if (j >= buf.length) {
507
+ if (buf.length - i <= MAX_MOUSE_REPORT_BYTES) break
508
+ out.push({ key: { type: "ignore" }, width: MAX_MOUSE_REPORT_BYTES })
509
+ i += MAX_MOUSE_REPORT_BYTES
510
+ continue
511
+ }
512
+ const first = buf.indexOf(0x3b, i + 3)
513
+ const second = first >= 0 ? buf.indexOf(0x3b, first + 1) : -1
514
+ const valid =
515
+ first > i + 3 &&
516
+ second > first + 1 &&
517
+ second < j &&
518
+ !buf.slice(second + 1, j).includes(0x3b)
519
+ const button = valid ? parseDecimalBytes(buf, i + 3, first) : null
520
+ const x = valid ? parseDecimalBytes(buf, first + 1, second) : null
521
+ const y = valid ? parseDecimalBytes(buf, second + 1, j) : null
522
+ const key =
523
+ button === null || x === null || y === null
524
+ ? ({ type: "ignore" } as const)
525
+ : mouseKeyForReport(button, mouseActionForButton(button, buf[j] === 0x6d), x, y)
526
+ out.push({ key, width: j - i + 1 })
500
527
  i = j + 1
501
528
  continue
502
529
  }
@@ -628,6 +655,58 @@ export function createKeyStreamPump(opts: {
628
655
  }
629
656
  }
630
657
 
658
+ type MouseAction = Extract<PromptKey, { type: "mouse" }>["action"]
659
+
660
+ function mouseActionForButton(button: number, release = false): MouseAction {
661
+ if (release) return "release"
662
+ if ((button & 0x20) !== 0) return (button & 0x03) <= 2 ? "drag" : "move"
663
+ return (button & 0x03) <= 2 ? "press" : "move"
664
+ }
665
+
666
+ function mouseKeyForReport(button: number, action: MouseAction, x: number, y: number): PromptKey {
667
+ if (
668
+ !Number.isSafeInteger(button) ||
669
+ button < 0 ||
670
+ !Number.isSafeInteger(x) ||
671
+ !Number.isSafeInteger(y) ||
672
+ x < 1 ||
673
+ y < 1
674
+ ) {
675
+ return { type: "ignore" }
676
+ }
677
+ const modifiers = button & 0x1c
678
+ if ((button & 0xc0) === 0x40) {
679
+ const vertical = button & 0x1f
680
+ if (vertical === 0) return { type: "wheelup" }
681
+ if (vertical === 1) return { type: "wheeldown" }
682
+ return { type: "ignore" }
683
+ }
684
+ const rawButton = button & 0x03
685
+ const normalizedButton = rawButton <= 2 ? (rawButton as 0 | 1 | 2) : null
686
+ if (action === "release") {
687
+ return { type: "mouse", action, button: normalizedButton, x, y, modifiers }
688
+ }
689
+ if (action === "drag" || action === "move") {
690
+ return { type: "mouse", action, button: normalizedButton, x, y, modifiers }
691
+ }
692
+ if (normalizedButton === null) return { type: "ignore" }
693
+ return { type: "mouse", action: "press", button: normalizedButton, x, y, modifiers }
694
+ }
695
+
696
+ function parseDecimalBytes(bytes: number[], from: number, to: number): number | null {
697
+ if (from >= to) return null
698
+ let value = 0
699
+ for (let i = from; i < to; i++) {
700
+ const digit = bytes[i]! - 0x30
701
+ if (digit < 0 || digit > 9) return null
702
+ value = value * 10 + digit
703
+ if (!Number.isSafeInteger(value)) return null
704
+ }
705
+ return value
706
+ }
707
+
708
+ const MAX_MOUSE_REPORT_BYTES = 64
709
+
631
710
  export function decodeKey(s: string, i: number): DecodedKey | null {
632
711
  const c = s[i]!
633
712
  const code = c.charCodeAt(0)
@@ -645,14 +724,30 @@ export function decodeKey(s: string, i: number): DecodedKey | null {
645
724
  return { key: { type: "char", ch: s.slice(i + 6, endIdx) }, width: endIdx + 6 - i }
646
725
  }
647
726
  }
648
- // Laporan mouse. X10: ESC [ M + 3 byte mentah (yang BUKAN huruf final, jadi
649
- // scanCsi tidak bisa mengukurnya). SGR: ESC [ < … M/m. Keduanya dibuang —
650
- // tanpa ini byte koordinat masuk sebagai teks ("teks" jadi "teks 00").
651
- if (s[i + 1] === "[" && s[i + 2] === "M") return { key: { type: "ignore" }, width: 6 }
727
+ if (s[i + 1] === "[" && s[i + 2] === "M") {
728
+ const button = s.charCodeAt(i + 3) - 0x20
729
+ const x = s.charCodeAt(i + 4) - 31
730
+ const y = s.charCodeAt(i + 5) - 31
731
+ return {
732
+ key: mouseKeyForReport(button, mouseActionForButton(button), x, y),
733
+ width: 6,
734
+ }
735
+ }
652
736
  if (s[i + 1] === "[" && s[i + 2] === "<") {
653
737
  let j = i + 3
654
738
  while (j < s.length && s[j] !== "M" && s[j] !== "m") j++
655
- return { key: { type: "ignore" }, width: j - i + 1 }
739
+ const first = s.indexOf(";", i + 3)
740
+ const second = first >= 0 ? s.indexOf(";", first + 1) : -1
741
+ const valid =
742
+ first > i + 3 && second > first + 1 && second < j && !s.slice(second + 1, j).includes(";")
743
+ const button = valid ? Number.parseInt(s.slice(i + 3, first), 10) : Number.NaN
744
+ const x = valid ? Number.parseInt(s.slice(first + 1, second), 10) : Number.NaN
745
+ const y = valid ? Number.parseInt(s.slice(second + 1, j), 10) : Number.NaN
746
+ const release = s[j] === "m"
747
+ return {
748
+ key: mouseKeyForReport(button, mouseActionForButton(button, release), x, y),
749
+ width: j - i + 1,
750
+ }
656
751
  }
657
752
  if (s[i + 1] === "[" || s[i + 1] === "O") {
658
753
  const kind = s[i + 2]
@@ -250,7 +250,7 @@ export function friendlyError(raw: string): FriendlyError {
250
250
  if (lower.includes("budget")) return { message: t("err.budget"), fix: t("err.budgetFix") }
251
251
  if (lower.includes("busy")) return { message: t("err.busy"), fix: t("err.busyFix") }
252
252
  if (lower.includes("aborted")) return { message: t("err.aborted") }
253
- const { detail } = extractProviderDetail(raw)
253
+ const { detail } = extractProviderDetail(redactSecrets(raw))
254
254
  // detail sudah sanitize via firstSentence; redact tak menambah ANSI, tapi
255
255
  // bungkus lagi agar idempoten bila pemanggil mengirim mentah di masa depan.
256
256
  if (detail) return { message: sanitizeAnsiLine(redactSecrets(detail)) }
@@ -262,3 +262,41 @@ export function friendlyError(raw: string): FriendlyError {
262
262
  export function formatFriendly(e: FriendlyError): string {
263
263
  return e.fix ? `${e.message}\n → ${e.fix}` : e.message
264
264
  }
265
+
266
+ /**
267
+ * Error apa pun → satu pesan siap tampil. KANONIK untuk seluruh UI
268
+ * (TUI fullscreen, wizard, one-shot).
269
+ *
270
+ * Semua permukaan harus lewat sini: pesan error adalah TEKS TAK
271
+ * DIPERCAYA (body provider, proxy, header Authorization) — `e.message` mentah
272
+ * pernah menampilkan bearer token dan dump JSON mentah ke layar.
273
+ *
274
+ * Bentuk yang dikenali:
275
+ * - ProviderError → punya `category` (peta formal → pesan actionable).
276
+ * - AgentError → punya `kind` (timeout/aborted/budget/dst).
277
+ * - Error biasa → pesannya (meredaksi + mensanitasi + memotong).
278
+ * - Non-Error → tetap LEWAT jalur redaksi; `String(e)` mentah bisa
279
+ * memuat credential. Informasi yang aman tetap dipertahankan — error tak
280
+ * diganti jadi teks generik.
281
+ */
282
+ export function formatError(e: unknown): string {
283
+ const obj = e as { kind?: string; category?: string; message?: string } | undefined
284
+ // ProviderError punya `category`; AgentError punya `kind`.
285
+ if (obj?.category) return formatFriendly(friendlyFromCategory(obj.category, obj.message ?? ""))
286
+ if (obj?.kind) {
287
+ const friendly = friendlyError(`${obj.kind}: ${obj.message ?? ""}`)
288
+ return formatFriendly(friendly)
289
+ }
290
+ if (e instanceof Error) {
291
+ // Error tanpa pesan → pakai nama kelasnya ("Error"/"TypeError") supaya
292
+ // tetap ada jejak di layar, bukan baris kosong tanpa konteks.
293
+ return formatFriendly(friendlyError(e.message.trim() ? e.message : String(e)))
294
+ }
295
+ // Objek non-Error yang tetap punya `message` (bentuk yang dipakai sebagian
296
+ // lib pihak ketiga): pakai pesannya, bukan "[object Object]".
297
+ if (typeof obj?.message === "string" && obj.message.trim()) {
298
+ return formatFriendly(friendlyError(obj.message))
299
+ }
300
+ // Sisanya (string yang dilempar, objek tanpa message): TETAP lewat redaksi.
301
+ return formatFriendly(friendlyError(String(e)))
302
+ }