minicode-ai 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/AGENTS.md +45 -0
  2. package/CHANGELOG.md +59 -4
  3. package/PLAN.md +491 -0
  4. package/README.md +2 -2
  5. package/cli/commands/acp.ts +485 -0
  6. package/cli/commands/auth.ts +7 -4
  7. package/cli/commands/config.ts +41 -27
  8. package/cli/commands/exec.ts +33 -12
  9. package/cli/commands/mcp.ts +3 -2
  10. package/cli/commands/memory.ts +1 -1
  11. package/cli/commands/pricing.ts +6 -4
  12. package/cli/commands/providers.ts +18 -8
  13. package/cli/commands/sessions.ts +11 -4
  14. package/cli/commands/skills.ts +3 -3
  15. package/cli/commands/stats.ts +3 -1
  16. package/cli/commands.ts +6 -0
  17. package/cli/index.ts +82 -57
  18. package/cli/model-manager.ts +6 -1
  19. package/cli/router.ts +7 -0
  20. package/cli/setup.ts +341 -5
  21. package/cli/tui.ts +54 -18
  22. package/docs/ARCHITECTURE.html +29 -22
  23. package/docs/CONTROL-PLANE-MAP.md +139 -0
  24. package/docs/HARNESS.md +150 -0
  25. package/docs/PLAN_UIUX_V6.md +209 -0
  26. package/docs/README.md +1 -1
  27. package/docs/SUMMARY.md +52 -0
  28. package/docs/TERMINAL_CONTRACT.md +367 -0
  29. package/docs/UI_RENDER_PIPELINE.md +165 -0
  30. package/docs/USAGE.md +11 -0
  31. package/docs/agents.md +31 -0
  32. package/docs/architecture.md +3 -3
  33. package/docs/choosing-mode.md +34 -0
  34. package/docs/cli.md +130 -0
  35. package/docs/concepts.md +53 -0
  36. package/docs/config-providers.md +87 -0
  37. package/docs/config.md +63 -0
  38. package/docs/contributing.md +79 -0
  39. package/docs/environment.md +95 -0
  40. package/docs/exec.md +73 -0
  41. package/docs/getting-started.md +102 -0
  42. package/docs/glossary.md +37 -0
  43. package/docs/mcp-lsp.md +54 -0
  44. package/docs/memory-sessions.md +63 -0
  45. package/docs/policy-sandbox.md +72 -0
  46. package/docs/pricing-budget.md +49 -0
  47. package/docs/quickstart.md +60 -0
  48. package/docs/repl.md +67 -0
  49. package/docs/security-model.md +95 -0
  50. package/docs/security.md +91 -0
  51. package/docs/skills.md +48 -0
  52. package/docs/terminal.md +79 -0
  53. package/docs/tools.md +123 -0
  54. package/docs/troubleshooting.md +40 -0
  55. package/docs/verify-benchmark.md +58 -0
  56. package/package.json +8 -5
  57. package/src/app/provider-layer.ts +12 -4
  58. package/src/app/session.ts +6 -0
  59. package/src/app/tool-layer.ts +2 -1
  60. package/src/constants.ts +35 -0
  61. package/src/lib/net.ts +6 -1
  62. package/src/lsp/client.ts +41 -8
  63. package/src/mcp/http-transport.ts +52 -15
  64. package/src/mcp/transport.ts +32 -1
  65. package/src/memory/files.ts +6 -5
  66. package/src/policy/allowlist.ts +1 -1
  67. package/src/policy/bash-guard.ts +154 -14
  68. package/src/policy/compaction.ts +57 -3
  69. package/src/policy/context.ts +4 -0
  70. package/src/policy/jail.ts +49 -4
  71. package/src/policy/permission.ts +152 -12
  72. package/src/policy/pricing.ts +12 -9
  73. package/src/presentation/adapter.ts +721 -0
  74. package/src/presentation/events.ts +324 -0
  75. package/src/presentation/label.ts +140 -0
  76. package/src/presentation/model.ts +172 -0
  77. package/src/presentation/reducer.ts +486 -0
  78. package/src/presentation/store.ts +256 -0
  79. package/src/providers/anthropic.ts +22 -4
  80. package/src/providers/detect.ts +2 -1
  81. package/src/providers/router.ts +13 -0
  82. package/src/repo/repomap.ts +2 -29
  83. package/src/session/checkpoint.ts +27 -9
  84. package/src/session/journal.ts +27 -5
  85. package/src/skills/loader.ts +88 -5
  86. package/src/telemetry/trace.ts +36 -15
  87. package/src/tools/ask_user.ts +73 -4
  88. package/src/tools/bash.ts +15 -17
  89. package/src/tools/glob.ts +10 -11
  90. package/src/tools/lsp.ts +3 -56
  91. package/src/tools/memory.ts +13 -12
  92. package/src/tools/task.ts +1 -0
  93. package/src/ui/approval/prompt.ts +14 -6
  94. package/src/ui/assistant/simple.ts +137 -26
  95. package/src/ui/assistant/turn-status.ts +16 -3
  96. package/src/ui/contract.ts +119 -0
  97. package/src/ui/footer.ts +21 -2
  98. package/src/ui/i18n/en.ts +34 -6
  99. package/src/ui/i18n/id.ts +34 -6
  100. package/src/ui/i18n/locale.ts +3 -1
  101. package/src/ui/input/input.ts +51 -4
  102. package/src/ui/input/prompt-engine.ts +46 -4
  103. package/src/ui/render/collapse.ts +13 -13
  104. package/src/ui/render/diff.ts +7 -2
  105. package/src/ui/render/format.ts +16 -8
  106. package/src/ui/render/highlight.ts +7 -3
  107. package/src/ui/render/markdown.ts +5 -1
  108. package/src/ui/render/sanitize.ts +29 -2
  109. package/src/ui/render/table.ts +8 -5
  110. package/src/ui/render/theme.ts +18 -4
  111. package/src/ui/render/width.ts +89 -10
  112. package/src/ui/runtime/motion.ts +16 -0
  113. package/src/ui/runtime/screen.ts +45 -0
  114. package/src/ui/runtime/spinner.ts +50 -4
  115. package/src/ui/runtime/statusline.ts +50 -1
  116. package/src/ui/screens/form.ts +42 -15
  117. package/src/ui/screens/model-manager.ts +26 -18
  118. package/src/ui/screens/picker.ts +47 -23
  119. package/src/ui/screens/provider-manager.ts +18 -12
  120. package/src/ui/screens/wizard.ts +24 -8
  121. package/src/ui/tui/app.ts +233 -27
  122. package/src/ui/tui/transcript.ts +269 -65
  123. package/vendor/minicore/LICENSE +21 -0
  124. package/vendor/minicore/VENDOR.md +6 -3
  125. package/vendor/minicore/package.json +6 -3
  126. package/vendor/minicore/src/core/loop.ts +12 -2
  127. package/vendor/minicore/src/core/snapshot.ts +4 -0
  128. package/vendor/minicore/src/providers/openai-compat.ts +76 -25
@@ -6,6 +6,7 @@ import {
6
6
  saveMcpServer,
7
7
  } from "../../src/config.ts"
8
8
  import { detectAndSave, removeProvider } from "../../src/providers/provision.ts"
9
+ import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
9
10
  import { renderTable } from "../../src/ui/render/table.ts"
10
11
  import { c, glyphs } from "../../src/ui/render/theme.ts"
11
12
 
@@ -43,11 +44,13 @@ const LSP_HELP = `minicode config lsp — language servers per file extension
43
44
 
44
45
  [--global|--local] save to ~/.minicode (default) or local .minicode/`
45
46
 
46
- /** Cetak help lalu keluar: 0 bila user memang meminta, 1 bila salah pakai. */
47
+ /** Cetak help lalu keluar: 0 bila user memang meminta, 2 bila salah pakai
48
+ * (aturan kontrak: gagal runtime = 1). */
47
49
  function showHelp(text: string, asked: boolean, unknown?: string): never {
48
- if (!asked) console.error(`unknown subcommand: ${unknown}\n`)
50
+ if (!asked)
51
+ console.error(`unknown subcommand: ${unknown === undefined ? "" : sanitizeAnsiLine(unknown)}\n`)
49
52
  console.log(text)
50
- process.exit(asked ? 0 : 1)
53
+ process.exit(asked ? 0 : 2)
51
54
  }
52
55
 
53
56
  const isHelpFlag = (s: string | undefined): boolean =>
@@ -80,7 +83,7 @@ export async function handleConfig(
80
83
  const id = getArg("--id")
81
84
  if (!baseUrl || !apiKey) {
82
85
  console.error("usage: minicode config add --baseUrl <url> --apiKey <key> [--id <id>]")
83
- process.exit(1)
86
+ process.exit(2)
84
87
  }
85
88
  const entry = await detectAndSave(baseUrl, apiKey, id, {
86
89
  // Default GLOBAL seperti remove/set-key: menulis provider+key ke
@@ -90,7 +93,10 @@ export async function handleConfig(
90
93
  cwd: getArg("--cwd"),
91
94
  })
92
95
  console.log(
93
- `${c.green(glyphs.check)} Saved provider "${c.bold(entry.id)}" (${entry.providerHint}) models: ${entry.models.slice(0, 5).join(", ")}${entry.models.length > 5 ? " ..." : ""} (${entry.models.length} total)`,
96
+ `${c.green(glyphs.check)} Saved provider "${c.bold(sanitizeAnsiLine(entry.id))}" (${sanitizeAnsiLine(entry.providerHint ?? "?")}) models: ${entry.models
97
+ .slice(0, 5)
98
+ .map((m) => sanitizeAnsiLine(m))
99
+ .join(", ")}${entry.models.length > 5 ? " ..." : ""} (${entry.models.length} total)`,
94
100
  )
95
101
  process.exit(0)
96
102
  } else if (sub === "list") {
@@ -126,11 +132,11 @@ export async function handleConfig(
126
132
  const id = positionalArg(args, 2)
127
133
  if (!id) {
128
134
  console.error("usage: minicode config remove <id> [--global|--local] [--cwd <dir>]")
129
- process.exit(1)
135
+ process.exit(2)
130
136
  }
131
137
  await removeProvider(id, { global: !args.includes("--local"), cwd: getArg("--cwd") })
132
138
  console.log(
133
- `${c.green(glyphs.check)} Removed provider ${id} (${!args.includes("--local") ? "global" : "local"})`,
139
+ `${c.green(glyphs.check)} Removed provider ${sanitizeAnsiLine(id)} (${!args.includes("--local") ? "global" : "local"})`,
134
140
  )
135
141
  process.exit(0)
136
142
  } else if (sub === "set-key" || sub === "delete-key") {
@@ -140,14 +146,14 @@ export async function handleConfig(
140
146
  const id = positionalArg(args, 2)
141
147
  if (!id) {
142
148
  console.error("usage: minicode config set-key <id> [--global|--local] [--cwd <dir>]")
143
- process.exit(1)
149
+ process.exit(2)
144
150
  }
145
151
  const { deleteSecret, setSecret } = await import("../../src/lib/keystore.ts")
146
152
  const key = `provider:${id}`
147
153
  if (sub === "delete-key") {
148
154
  await deleteSecret(key)
149
155
  console.log(
150
- `${c.green(glyphs.check)} Removed stored key for ${c.bold(id)} — update config apiKey manually (provider stays disabled until re-set)`,
156
+ `${c.green(glyphs.check)} Removed stored key for ${c.bold(sanitizeAnsiLine(id))} — update config apiKey manually (provider stays disabled until re-set)`,
151
157
  )
152
158
  process.exit(0)
153
159
  }
@@ -158,7 +164,9 @@ export async function handleConfig(
158
164
  process.exit(1)
159
165
  }
160
166
  const { askSecret } = await import("../../src/ui/input/input.ts")
161
- const secret = await askSecret(`API key for ${id} (hidden, empty = cancel) > `)
167
+ const secret = await askSecret(
168
+ `API key for ${sanitizeAnsiLine(id)} (hidden, empty = cancel) > `,
169
+ )
162
170
  if (!secret) {
163
171
  console.log(c.yellow("canceled"))
164
172
  process.exit(1)
@@ -174,12 +182,14 @@ export async function handleConfig(
174
182
  const cfg = await loadConfig(getArg("--cwd"), { allowLocal: allowLocalHere(args) })
175
183
  const entry = cfg.providers.find((p) => p.id === id)
176
184
  if (!entry) {
177
- console.error(`provider "${id}" not found - secret stored, but no provider points at it yet`)
185
+ console.error(
186
+ `provider "${sanitizeAnsiLine(id)}" not found - secret stored, but no provider points at it yet`,
187
+ )
178
188
  process.exit(1)
179
189
  }
180
190
  await saveProvider({ ...entry, apiKey: `keystore:${key}` }, { global, cwd: getArg("--cwd") })
181
191
  console.log(
182
- `${c.green(glyphs.check)} Stored key for ${c.bold(id)} via ${backend} (${global ? "global" : "local"} config now references it)`,
192
+ `${c.green(glyphs.check)} Stored key for ${c.bold(sanitizeAnsiLine(id))} via ${backend} (${global ? "global" : "local"} config now references it)`,
183
193
  )
184
194
  process.exit(0)
185
195
  } else if (sub === "detect") {
@@ -191,17 +201,19 @@ export async function handleConfig(
191
201
  const apiKey = getArg("--apiKey")
192
202
  if (!baseUrl || !apiKey) {
193
203
  console.error("usage: minicode config detect --baseUrl <url> --apiKey <key>")
194
- process.exit(1)
204
+ process.exit(2)
195
205
  }
196
206
  const { detectModels } = await import("../../src/providers/detect.ts")
197
207
  const res = await detectModels(baseUrl, apiKey).catch((e) => {
198
208
  // Host mati total (bukan sekadar tanpa /models) — katakan begitu,
199
209
  // jangan "Detected 0 models" yang menyalahkan kredensial.
200
- console.error(`${c.red(glyphs.cross)} ${(e as Error).message} — check network and URL`)
210
+ console.error(
211
+ `${c.red(glyphs.cross)} ${sanitizeAnsiLine((e as Error).message)} — check network and URL`,
212
+ )
201
213
  process.exit(1)
202
214
  })
203
215
  console.log(
204
- `${c.green(glyphs.check)} Detected ${res.models.length} models (${res.providerHint}):\n${res.models.map((m) => ` ${glyphs.dot} ${m}`).join("\n")}`,
216
+ `${c.green(glyphs.check)} Detected ${res.models.length} models (${sanitizeAnsiLine(res.providerHint)}):\n${res.models.map((m) => ` ${glyphs.dot} ${sanitizeAnsiLine(m)}`).join("\n")}`,
205
217
  )
206
218
  process.exit(0)
207
219
  } else if (sub === "mcp") {
@@ -218,7 +230,7 @@ export async function handleConfig(
218
230
  " minicode config mcp add <id> --url <https://…> [--header K=V] [--allow-private]\n" +
219
231
  " [--global|--local]",
220
232
  )
221
- process.exit(1)
233
+ process.exit(2)
222
234
  }
223
235
  const env: Record<string, string> = {}
224
236
  for (const kv of (getArg("--env") ?? "").split(",")) {
@@ -236,11 +248,11 @@ export async function handleConfig(
236
248
  const parsed = new URL(url)
237
249
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
238
250
  console.error(`URL must use http/https, not ${parsed.protocol}`)
239
- process.exit(1)
251
+ process.exit(2)
240
252
  }
241
253
  } catch {
242
- console.error(`Invalid URL: ${url}`)
243
- process.exit(1)
254
+ console.error(`Invalid URL: ${sanitizeAnsiLine(url)}`)
255
+ process.exit(2)
244
256
  }
245
257
  // P10: add branch WAJIB menghormati --cwd seperti remove —
246
258
  // sebelumnya menulis ke process.cwd() diam-diam (salah direktori).
@@ -253,7 +265,9 @@ export async function handleConfig(
253
265
  },
254
266
  { global: !args.includes("--local"), cwd: getArg("--cwd") },
255
267
  )
256
- console.log(`${c.green(glyphs.check)} Saved MCP server "${c.bold(id)}" (http): ${url}`)
268
+ console.log(
269
+ `${c.green(glyphs.check)} Saved MCP server "${c.bold(sanitizeAnsiLine(id))}" (http): ${sanitizeAnsiLine(url)}`,
270
+ )
257
271
  process.exit(0)
258
272
  }
259
273
 
@@ -266,7 +280,7 @@ export async function handleConfig(
266
280
  { global: !args.includes("--local"), cwd: getArg("--cwd") },
267
281
  )
268
282
  console.log(
269
- `${c.green(glyphs.check)} Saved MCP server "${c.bold(id)}": ${command} ${cmdArgs.join(" ")}`,
283
+ `${c.green(glyphs.check)} Saved MCP server "${c.bold(sanitizeAnsiLine(id))}": ${sanitizeAnsiLine(command ?? "")} ${cmdArgs.map((a) => sanitizeAnsiLine(a)).join(" ")}`,
270
284
  )
271
285
  process.exit(0)
272
286
  } else if (mcpSub === "list") {
@@ -299,11 +313,11 @@ export async function handleConfig(
299
313
  const id = positionalArg(args, 3)
300
314
  if (!id) {
301
315
  console.error("usage: minicode config mcp remove <id> [--global|--local]")
302
- process.exit(1)
316
+ process.exit(2)
303
317
  }
304
318
  await removeMcpServer(id, { global: !args.includes("--local"), cwd: getArg("--cwd") })
305
319
  console.log(
306
- `${c.green(glyphs.check)} Removed MCP server ${id} (${!args.includes("--local") ? "global" : "local"})`,
320
+ `${c.green(glyphs.check)} Removed MCP server ${sanitizeAnsiLine(id)} (${!args.includes("--local") ? "global" : "local"})`,
307
321
  )
308
322
  process.exit(0)
309
323
  } else {
@@ -319,7 +333,7 @@ export async function handleConfig(
319
333
  console.error(
320
334
  'usage: minicode config lsp add <ext> --command <cmd> [--args "<arg1,arg2>"] [--env K=V] [--global|--local]',
321
335
  )
322
- process.exit(1)
336
+ process.exit(2)
323
337
  }
324
338
  const cmdArgs = cmdArgsRaw
325
339
  .split(",")
@@ -335,7 +349,7 @@ export async function handleConfig(
335
349
  { global: !args.includes("--local"), cwd: getArg("--cwd") },
336
350
  )
337
351
  console.log(
338
- `${c.green(glyphs.check)} Saved LSP server for ${c.bold(ext)}: ${command} ${cmdArgs.join(" ")}`,
352
+ `${c.green(glyphs.check)} Saved LSP server for ${c.bold(sanitizeAnsiLine(ext))}: ${sanitizeAnsiLine(command)} ${cmdArgs.map((a) => sanitizeAnsiLine(a)).join(" ")}`,
339
353
  )
340
354
  process.exit(0)
341
355
  } else if (lspSub === "list") {
@@ -366,11 +380,11 @@ export async function handleConfig(
366
380
  const ext = positionalArg(args, 3)
367
381
  if (!ext) {
368
382
  console.error("usage: minicode config lsp remove <ext> [--global|--local]")
369
- process.exit(1)
383
+ process.exit(2)
370
384
  }
371
385
  await removeLspServer(ext, { global: !args.includes("--local"), cwd: getArg("--cwd") })
372
386
  console.log(
373
- `${c.green(glyphs.check)} Removed LSP server for ${ext} (${!args.includes("--local") ? "global" : "local"})`,
387
+ `${c.green(glyphs.check)} Removed LSP server for ${sanitizeAnsiLine(ext)} (${!args.includes("--local") ? "global" : "local"})`,
374
388
  )
375
389
  process.exit(0)
376
390
  } else {
@@ -1,10 +1,11 @@
1
1
  import { randomUUID } from "node:crypto"
2
2
  import { resolve as resolvePath } from "node:path"
3
+ import { NoProviderError } from "../../src/app/provider-layer.ts"
3
4
  import { createRateLimiter } from "../../src/policy/ratelimit.ts"
4
5
  import { resolveSandbox, sandboxRefusalReason } from "../../src/policy/sandbox-policy.ts"
5
6
  import { scrubSecrets } from "../../src/policy/scrub.ts"
6
7
  import { budgetStatus } from "../../src/policy/usage.ts"
7
- import { getSubmittedResult } from "../../src/tools/submit_result.ts"
8
+ import { clearSubmittedResult, getSubmittedResult } from "../../src/tools/submit_result.ts"
8
9
  import { formatError } from "../../src/ui/assistant/simple.ts"
9
10
  import { formatUsd } from "../../src/ui/render/money.ts"
10
11
  import { allowLocalConfig, hasFlag, promptFromArgs, getArg as rawGetArg } from "../args.ts"
@@ -14,7 +15,9 @@ export async function handleExec(
14
15
  args: string[],
15
16
  getArg: (name: string) => string | undefined,
16
17
  ): Promise<never> {
17
- // minicode exec "prompt" [--json] [--cwd <dir>] [--model <m>] [--sandbox docker|os] ...
18
+ // Bersihkan state submit_result dari run sebelumnya — tanpa ini, exec
19
+ // berturut-turut dalam proses sama bisa membaca hasil run lama.
20
+ clearSubmittedResult()
18
21
  //
19
22
  // Prompt diambil lewat promptFromArgs() — satu implementasi yang sama dengan
20
23
  // jalur non-exec. Versi sebelumnya menyaring dengan `a !== getArg("--model")`,
@@ -22,8 +25,13 @@ export async function handleExec(
22
25
  // ikut masuk ke prompt. `exec "tes" --provider gorouter --timeout 60000` benar-
23
26
  // benar mengirim "tes gorouter 60000" ke model, dan model membalas dengan
24
27
  // menebak-nebak soal "gorouter" dan "60000".
25
- const prompt = promptFromArgs(args.slice(1)) || (rawGetArg(args, "--prompt") ?? "")
26
- const jsonMode = hasFlag(args, "--json") || rawGetArg(args, "--output-format") === "json"
28
+ // Router memanggil dengan argv penuh (["exec", ...]) sementara hasFlag/
29
+ // getArg berhenti di token subcommand (boundary anti-injeksi) — tanpa
30
+ // slice, SEMUA flag boolean exec (--json/--verify/--ask/...) mati diam-diam
31
+ // di CLI nyata. Pola yang sama dengan promptFromArgs di bawah.
32
+ const subArgs = args[0] === "exec" ? args.slice(1) : args
33
+ const prompt = promptFromArgs(subArgs) || (rawGetArg(subArgs, "--prompt") ?? "")
34
+ const jsonMode = hasFlag(subArgs, "--json") || rawGetArg(subArgs, "--output-format") === "json"
27
35
  const cwdRaw = getArg("--cwd")
28
36
  const cwd = cwdRaw ? resolvePath(cwdRaw) : undefined
29
37
  const modelOverride = getArg("--model")
@@ -32,10 +40,10 @@ export async function handleExec(
32
40
  getArg("--session")
33
41
  ?.replace(/[^A-Za-z0-9._-]/g, "-")
34
42
  .slice(0, 64) || randomUUID().slice(0, 8)
35
- const allowAll = hasFlag(args, "--allow-all")
36
- const ask = hasFlag(args, "--ask")
37
- const plan = hasFlag(args, "--plan")
38
- const allowlistFlag = hasFlag(args, "--allowlist")
43
+ const allowAll = hasFlag(subArgs, "--allow-all")
44
+ const ask = hasFlag(subArgs, "--ask")
45
+ const plan = hasFlag(subArgs, "--plan")
46
+ const allowlistFlag = hasFlag(subArgs, "--allowlist")
39
47
  // Sama seperti jalur interaktif: OS sandbox otomatis, dan tanpa isolasi nyata
40
48
  // permission default turun ke allowlist. Headless CI justru paling butuh ini —
41
49
  // di sana tak ada manusia yang bisa menyetujui prompt.
@@ -52,7 +60,7 @@ export async function handleExec(
52
60
  else process.env.MINICODE_SANDBOX = sandbox.mode
53
61
  const allowlist = allowlistFlag || sandbox.fallbackPermission === "allowlist"
54
62
  // Audit #07 P0: local config repo tak dipercaya kecuali operator opt-in.
55
- const allowLocal = allowLocalConfig(args)
63
+ const allowLocal = allowLocalConfig(subArgs)
56
64
  const budgetRaw = getArg("--budget")
57
65
  const parsedBudget = budgetRaw ? Number(budgetRaw) : undefined
58
66
  const budget =
@@ -61,7 +69,7 @@ export async function handleExec(
61
69
  : undefined
62
70
  // Harness-P1: sama seperti one-shot — strict fail-closed bila cost tak dikenal.
63
71
  const budgetStrict =
64
- hasFlag(args, "--budget-strict") || process.env.MINICODE_BUDGET_STRICT === "1"
72
+ hasFlag(subArgs, "--budget-strict") || process.env.MINICODE_BUDGET_STRICT === "1"
65
73
  // Harness-P2: scope tool sesi.
66
74
  const toolScopeRaw = (
67
75
  getArg("--tool-scope") ??
@@ -77,7 +85,7 @@ export async function handleExec(
77
85
  console.error(
78
86
  'usage: minicode exec "prompt" [--json] [--cwd <dir>] [--model <m>] [--sandbox docker|os]',
79
87
  )
80
- process.exit(1)
88
+ process.exit(2)
81
89
  }
82
90
 
83
91
  const ctx = await createCliSession({
@@ -92,7 +100,7 @@ export async function handleExec(
92
100
  ask,
93
101
  plan,
94
102
  allowlist,
95
- verify: hasFlag(args, "--verify"),
103
+ verify: hasFlag(subArgs, "--verify"),
96
104
  allowLocalConfig: allowLocal,
97
105
  budget,
98
106
  budgetStrict,
@@ -100,6 +108,19 @@ export async function handleExec(
100
108
  rateLimiter,
101
109
  // Notice hanya bila user eksplisit meminta mode (daemon mati / tak dikenal).
102
110
  sandboxNotice: requestedSandbox ? sandbox.notice : undefined,
111
+ }).catch((e) => {
112
+ // Setup gagal SEBELUM envelope JSON dipasang (tanpa provider): mode
113
+ // mesin tetap pulang membawa satu baris summary agar pipeline CI tak
114
+ // menerima stream kosong — stderr manusia + exit 1 tidak berubah.
115
+ if (e instanceof NoProviderError) {
116
+ if (jsonMode)
117
+ process.stdout.write(
118
+ `${scrubSecrets(JSON.stringify({ type: "summary", ok: false, error: formatError(e), prompt: effectivePrompt }))}\n`,
119
+ )
120
+ console.error(e.message)
121
+ process.exit(1)
122
+ }
123
+ throw e
103
124
  })
104
125
  const t0 = Date.now()
105
126
  const events: unknown[] = []
@@ -27,9 +27,10 @@ export async function handleMcp(
27
27
  })
28
28
  process.exit(0)
29
29
  }
30
- // Help kontekstual, bukan HELP global 45 baris. Subcommand asing = exit 1.
30
+ // Help kontekstual, bukan HELP global 45 baris. Subcommand asing = salah
31
+ // pakai (exit 2), bukan gagal runtime (exit 1).
31
32
  const asking = sub === undefined || sub === "--help" || sub === "-h"
32
33
  if (!asking) console.error(`unknown mcp subcommand: ${sub}\n`)
33
34
  console.log(MCP_HELP)
34
- process.exit(asking ? 0 : 1)
35
+ process.exit(asking ? 0 : 2)
35
36
  }
@@ -58,7 +58,7 @@ export async function handleMemory(
58
58
  }
59
59
  if (sub && sub !== "status" && !sub.startsWith("-")) {
60
60
  console.error(`unknown memory subcommand "${sub}" — see: minicode memory status`)
61
- process.exit(1)
61
+ process.exit(2)
62
62
  }
63
63
  const cwdArg = getArg("--cwd")
64
64
  const asJson = getArg("--json") !== undefined || args.includes("--json")
@@ -60,10 +60,11 @@ export async function handlePricing(args: string[]): Promise<never> {
60
60
  }
61
61
 
62
62
  if (sub === "show") {
63
- const model = args[2]
63
+ // Flag bukan nama model (`pricing show --json` = lupa argumen).
64
+ const model = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
64
65
  if (!model) {
65
66
  console.error("usage: minicode pricing show <model>")
66
- process.exit(1)
67
+ process.exit(2)
67
68
  }
68
69
  const overlay = await loadPricingOverlay()
69
70
  const p = findPrice(model, overlay)
@@ -93,8 +94,9 @@ export async function handlePricing(args: string[]): Promise<never> {
93
94
  process.exit(0)
94
95
  }
95
96
 
96
- // Subcommand asing = salah pakai: exit 1 supaya skrip bisa mendeteksinya.
97
+ // Subcommand asing = salah pakai: exit 2 supaya skrip bisa mendeteksinya
98
+ // dan membedakannya dari gagal runtime (exit 1).
97
99
  console.error(`unknown pricing subcommand: ${sub}\n`)
98
100
  console.log(PRICING_HELP)
99
- process.exit(1)
101
+ process.exit(2)
100
102
  }
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs"
2
2
  import { resolve } from "node:path"
3
3
  import { loadConfig, type MinicodeConfig } from "../../src/config.ts"
4
4
  import { refreshProviderModels } from "../../src/providers/provision.ts"
5
+ import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
5
6
  import { renderTable } from "../../src/ui/render/table.ts"
6
7
  import { c, glyphs } from "../../src/ui/render/theme.ts"
7
8
 
@@ -120,27 +121,31 @@ export async function handleProviders(
120
121
  if (pid) {
121
122
  const p = cfg.providers.find((x) => x.id === pid)
122
123
  if (!p) {
123
- console.error(`provider "${pid}" not found - see: minicode providers`)
124
+ console.error(`provider "${sanitizeAnsiLine(pid)}" not found - see: minicode providers`)
124
125
  process.exit(1)
125
126
  }
126
127
  const list = p.models.filter(match)
127
- if (!list.length) console.log(` (no matches for "${filter}")`)
128
- for (const [i, m] of list.entries()) console.log(` [${i}] ${m}`)
128
+ if (!list.length) console.log(` (no matches for "${sanitizeAnsiLine(filter)}")`)
129
+ for (const [i, m] of list.entries()) console.log(` [${i}] ${sanitizeAnsiLine(m)}`)
129
130
  } else {
130
131
  if (cfg.providers.length === 0) console.log("(no providers yet)")
131
132
  let shown = 0
132
133
  for (const p of cfg.providers) {
133
134
  const list = p.models.filter(match)
134
135
  if (!list.length) continue
135
- console.log(`${p.id} (${p.baseUrl})${filter ? ` - matches "${filter}"` : ""}`)
136
+ // id/baseUrl dari config (lokal = input repo tak terpercaya); model dari
137
+ // hasil probe jaringan — sanitasi sebelum masuk scrollback.
138
+ console.log(
139
+ `${sanitizeAnsiLine(p.id)} (${sanitizeAnsiLine(p.baseUrl)})${filter ? ` - matches "${sanitizeAnsiLine(filter)}"` : ""}`,
140
+ )
136
141
  shown += list.length
137
- for (const m of list.slice(0, 10)) console.log(` ${m}`)
142
+ for (const m of list.slice(0, 10)) console.log(` ${sanitizeAnsiLine(m)}`)
138
143
  if (filter && list.length > 10) console.log(` … +${list.length - 10} more`)
139
144
  if (!filter && p.models.length > 10) console.log(` … +${p.models.length - 10} more`)
140
145
  }
141
146
  // Header provider hanya bila ada yang cocok — tanpa ini filter kosong
142
147
  // mencetak judul lalu "(no matches)", dua baris untuk nol informasi.
143
- if (filter && shown === 0) console.log(` (no matches for "${filter}")`)
148
+ if (filter && shown === 0) console.log(` (no matches for "${sanitizeAnsiLine(filter)}")`)
144
149
  }
145
150
  process.exit(0)
146
151
  }
@@ -148,8 +153,13 @@ export async function handleProviders(
148
153
  console.log("Syncing model list from providers…")
149
154
  const { updated, failed } = await refreshProviderModels({ cwd: cwdArg, allowLocal })
150
155
  for (const r of updated)
151
- console.log(` ${c.green(glyphs.check)} ${r.id}: ${r.from} -> ${r.to} model`)
152
- for (const f of failed) console.log(` ${c.red(glyphs.cross)} ${f.id}: ${f.reason}`)
156
+ console.log(
157
+ ` ${c.green(glyphs.check)} ${sanitizeAnsiLine(r.id)}: ${r.from} -> ${r.to} model`,
158
+ )
159
+ for (const f of failed)
160
+ console.log(
161
+ ` ${c.red(glyphs.cross)} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`,
162
+ )
153
163
  if (!updated.length && !failed.length) {
154
164
  const cfgHere = await loadConfig(cwdArg, { allowLocal })
155
165
  if (cfgHere.providers.length === 0)
@@ -1,6 +1,5 @@
1
1
  import { Database } from "bun:sqlite"
2
2
  import { existsSync, mkdirSync } from "node:fs"
3
- import { homedir } from "node:os"
4
3
  import { dirname, join, resolve } from "node:path"
5
4
  import { homeDir } from "../../src/lib/db-path.ts"
6
5
  import { deleteJournalFile, findOrphanJournals } from "../../src/session/journal.ts"
@@ -27,6 +26,14 @@ export async function handleSessions(
27
26
  if (sub === "list" || !sub) {
28
27
  const cwdArg = getArg("--cwd")
29
28
  const rows = listSessions(cwdArg)
29
+ // resolveDbPath jatuh ke global ~/.minicode bila workspace tanpa
30
+ // .minicode/ — umumkan scope agar daftar lintas-workspace tak dibaca
31
+ // sebagai isi workspace ini (temuan F-C audit terminal UI/UX).
32
+ const base = cwdArg ?? process.cwd()
33
+ const usesLocal =
34
+ existsSync(resolve(base, ".minicode", "sessions.db")) ||
35
+ existsSync(resolve(base, ".minicode"))
36
+ if (!usesLocal) console.log(c.dim(`(global scope — no local .minicode/sessions.db in ${base})`))
30
37
  if (rows.length === 0) console.log(c.dim("(no recorded sessions yet)"))
31
38
  else {
32
39
  const tableData = rows.map((r) => ({
@@ -55,7 +62,7 @@ export async function handleSessions(
55
62
  const asJsonl = args.includes("--jsonl")
56
63
  if (!id) {
57
64
  console.error("usage: minicode sessions export <id> [--jsonl]")
58
- process.exit(1)
65
+ process.exit(2)
59
66
  }
60
67
  const sess = loadSession(id, getArg("--cwd"))
61
68
  if (!sess) {
@@ -71,7 +78,7 @@ export async function handleSessions(
71
78
  const dbPath = existsSync(localPath)
72
79
  ? localPath
73
80
  : (() => {
74
- const g = join(homedir(), ".minicode")
81
+ const g = join(homeDir(), ".minicode")
75
82
  mkdirSync(g, { recursive: true })
76
83
  return join(g, "sessions.db")
77
84
  })()
@@ -123,6 +130,6 @@ export async function handleSessions(
123
130
  const asked = sub === "--help" || sub === "-h"
124
131
  if (!asked) console.error(`unknown sessions subcommand: ${sub}\n`)
125
132
  console.log(SESSIONS_HELP)
126
- process.exit(asked ? 0 : 1)
133
+ process.exit(asked ? 0 : 2)
127
134
  }
128
135
  }
@@ -7,7 +7,7 @@ const SKILLS_HELP = `minicode skills — markdown skills in .minicode/skills/*.m
7
7
  minicode skills list list installed skills
8
8
  minicode skills show <name> show one skill
9
9
 
10
- In REPL, run a skill with /name [arguments].`
10
+ In interactive mode, run a skill with /name [arguments].`
11
11
 
12
12
  export async function handleSkills(
13
13
  args: string[],
@@ -44,7 +44,7 @@ export async function handleSkills(
44
44
  const name = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
45
45
  if (!name) {
46
46
  console.error("usage: minicode skills show <name>")
47
- process.exit(1)
47
+ process.exit(2)
48
48
  }
49
49
  const s = await findSkill(name, cwdArg)
50
50
  if (!s) {
@@ -57,5 +57,5 @@ export async function handleSkills(
57
57
  const asked = sub === "--help" || sub === "-h"
58
58
  if (!asked) console.error(`unknown skills subcommand: ${sub}\n`)
59
59
  console.log(SKILLS_HELP)
60
- process.exit(asked ? 0 : 1)
60
+ process.exit(asked ? 0 : 2)
61
61
  }
@@ -74,8 +74,10 @@ export async function handleStats(getArg: (name: string) => string | undefined):
74
74
  if (steps.tools > 0) {
75
75
  const topDeny = steps.topDenied.map((t) => `${t.tool}×${t.n}`).join(", ")
76
76
  const topReason = steps.topDenyReasons.map((r) => `${r.reason}×${r.n}`).join(", ")
77
+ // F1.2: peak token kumulatif antar step — satu angka "seboros apa sesi ini".
78
+ const peak = steps.peakTotalTokens > 0 ? ` · Peak tok: ${steps.peakTotalTokens}` : ""
77
79
  console.log(
78
- `Tools: ${steps.tools} · Denied: ${steps.denied} (${(steps.denyRate * 100).toFixed(1)}%) · Errors: ${steps.errors}${topDeny ? ` · Top denied: ${topDeny}` : ""}${topReason ? ` · Reason: ${topReason}` : ""}${steps.sandboxes.length ? ` · Sandbox: ${steps.sandboxes.join(",")}` : ""}`,
80
+ `Tools: ${steps.tools} · Denied: ${steps.denied} (${(steps.denyRate * 100).toFixed(1)}%) · Errors: ${steps.errors}${topDeny ? ` · Top denied: ${topDeny}` : ""}${topReason ? ` · Reason: ${topReason}` : ""}${steps.sandboxes.length ? ` · Sandbox: ${steps.sandboxes.join(",")}` : ""}${peak}`,
79
81
  )
80
82
  }
81
83
  process.exit(0)
package/cli/commands.ts CHANGED
@@ -131,6 +131,7 @@ const KEYBOARD_HELP: [string, MsgKey][] = [
131
131
  ["tab / shift+tab", "help.k.cycleMode"],
132
132
  ["up / down", "help.k.history"],
133
133
  ["pgup / pgdn", "help.k.scroll"],
134
+ ["home / end (prompt)", "help.k.jumpTop"],
134
135
  ["left / right", "help.k.move"],
135
136
  ["home / end", "help.k.jump"],
136
137
  ["delete", "help.k.delChar"],
@@ -157,6 +158,10 @@ function pad(text: string, width: number): string {
157
158
  function statusLines(ctx: CommandContext): string[] {
158
159
  // Kumulatif sesi, bukan turn terakhir — judulnya menjanjikan "biaya sesi".
159
160
  const u = ctx.usage.getSession(ctx.currentModel)
161
+ // F1.1: turn terakhir tampil terpisah — tanpa ini user tak bisa membedakan
162
+ // "turn ini boros" dari "sesi ini boros". get() = akumulator turn yang
163
+ // di-reset tiap persistCurrent, bukan recompute.
164
+ const last = ctx.usage.get(ctx.currentModel)
160
165
  // Kontrak control-plane (Phase 6): DUA angka berbeda, dua konsep —
161
166
  // Context = ukuran jendela saat ini (kernel, estimateSessionContext);
162
167
  // Total = pemakaian kumulatif provider (usage event). Dulu hanya Total
@@ -172,6 +177,7 @@ function statusLines(ctx: CommandContext): string[] {
172
177
  t("st.provider", { v: provider }),
173
178
  t("st.tools", { v: ctx.toolsCount }),
174
179
  t("st.context", { v: ctx.getContextTokens().toLocaleString() }),
180
+ t("st.turn", { v: last.totalTokens.toLocaleString() }),
175
181
  t("st.input", { v: u.inputTokens.toLocaleString() }),
176
182
  t("st.output", { v: u.outputTokens.toLocaleString() }),
177
183
  t("st.total", { v: u.totalTokens.toLocaleString() }),