minicode-ai 0.10.0 → 0.11.1
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.
- package/AGENTS.md +45 -0
- package/CHANGELOG.md +68 -4
- package/PLAN.md +491 -0
- package/README.md +2 -2
- package/cli/commands/acp.ts +485 -0
- package/cli/commands/auth.ts +7 -4
- package/cli/commands/config.ts +41 -27
- package/cli/commands/exec.ts +33 -12
- package/cli/commands/mcp.ts +3 -2
- package/cli/commands/memory.ts +1 -1
- package/cli/commands/pricing.ts +6 -4
- package/cli/commands/providers.ts +18 -8
- package/cli/commands/sessions.ts +11 -4
- package/cli/commands/skills.ts +3 -3
- package/cli/commands/stats.ts +3 -1
- package/cli/commands.ts +6 -0
- package/cli/index.ts +82 -57
- package/cli/model-manager.ts +6 -1
- package/cli/router.ts +7 -0
- package/cli/setup.ts +341 -5
- package/cli/tui.ts +54 -18
- package/docs/ARCHITECTURE.html +32 -25
- package/docs/CONTROL-PLANE-MAP.md +139 -0
- package/docs/HARNESS.md +150 -0
- package/docs/PLAN_UIUX_V6.md +209 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +52 -0
- package/docs/TERMINAL_CONTRACT.md +372 -0
- package/docs/UI_RENDER_PIPELINE.md +169 -0
- package/docs/USAGE.md +11 -0
- package/docs/agents.md +31 -0
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +34 -0
- package/docs/cli.md +130 -0
- package/docs/concepts.md +53 -0
- package/docs/config-providers.md +87 -0
- package/docs/config.md +63 -0
- package/docs/contributing.md +79 -0
- package/docs/environment.md +95 -0
- package/docs/exec.md +73 -0
- package/docs/getting-started.md +102 -0
- package/docs/glossary.md +37 -0
- package/docs/mcp-lsp.md +54 -0
- package/docs/memory-sessions.md +63 -0
- package/docs/policy-sandbox.md +72 -0
- package/docs/pricing-budget.md +49 -0
- package/docs/quickstart.md +60 -0
- package/docs/repl.md +67 -0
- package/docs/security-model.md +95 -0
- package/docs/security.md +91 -0
- package/docs/skills.md +48 -0
- package/docs/terminal.md +79 -0
- package/docs/tools.md +123 -0
- package/docs/troubleshooting.md +40 -0
- package/docs/verify-benchmark.md +58 -0
- package/package.json +8 -5
- package/src/app/provider-layer.ts +12 -4
- package/src/app/session.ts +6 -0
- package/src/app/tool-layer.ts +2 -1
- package/src/constants.ts +35 -0
- package/src/lib/net.ts +6 -1
- package/src/lsp/client.ts +41 -8
- package/src/mcp/http-transport.ts +52 -15
- package/src/mcp/transport.ts +32 -1
- package/src/memory/files.ts +6 -5
- package/src/policy/allowlist.ts +1 -1
- package/src/policy/bash-guard.ts +154 -14
- package/src/policy/compaction.ts +57 -3
- package/src/policy/context.ts +4 -0
- package/src/policy/jail.ts +49 -4
- package/src/policy/permission.ts +152 -12
- package/src/policy/pricing.ts +12 -9
- package/src/presentation/adapter.ts +721 -0
- package/src/presentation/events.ts +324 -0
- package/src/presentation/label.ts +140 -0
- package/src/presentation/model.ts +172 -0
- package/src/presentation/reducer.ts +486 -0
- package/src/presentation/store.ts +256 -0
- package/src/providers/anthropic.ts +22 -4
- package/src/providers/detect.ts +2 -1
- package/src/providers/responses.ts +15 -5
- package/src/providers/router.ts +13 -0
- package/src/repo/repomap.ts +2 -29
- package/src/session/checkpoint.ts +27 -9
- package/src/session/journal.ts +27 -5
- package/src/skills/loader.ts +88 -5
- package/src/telemetry/trace.ts +36 -15
- package/src/tools/ask_user.ts +73 -4
- package/src/tools/bash.ts +15 -17
- package/src/tools/glob.ts +10 -11
- package/src/tools/lsp.ts +3 -56
- package/src/tools/memory.ts +13 -12
- package/src/tools/task.ts +1 -0
- package/src/ui/approval/prompt.ts +14 -6
- package/src/ui/assistant/simple.ts +137 -26
- package/src/ui/assistant/turn-status.ts +16 -3
- package/src/ui/contract.ts +119 -0
- package/src/ui/footer.ts +27 -5
- package/src/ui/i18n/en.ts +38 -6
- package/src/ui/i18n/id.ts +38 -6
- package/src/ui/i18n/locale.ts +3 -1
- package/src/ui/input/input.ts +51 -4
- package/src/ui/input/prompt-engine.ts +46 -4
- package/src/ui/render/collapse.ts +13 -13
- package/src/ui/render/diff.ts +7 -2
- package/src/ui/render/format.ts +16 -8
- package/src/ui/render/highlight.ts +7 -3
- package/src/ui/render/markdown.ts +5 -1
- package/src/ui/render/sanitize.ts +29 -2
- package/src/ui/render/table.ts +8 -5
- package/src/ui/render/theme.ts +18 -4
- package/src/ui/render/width.ts +89 -10
- package/src/ui/runtime/motion.ts +16 -0
- package/src/ui/runtime/screen.ts +45 -0
- package/src/ui/runtime/spinner.ts +50 -4
- package/src/ui/runtime/statusline.ts +50 -1
- package/src/ui/screens/form.ts +42 -15
- package/src/ui/screens/model-manager.ts +26 -18
- package/src/ui/screens/picker.ts +47 -23
- package/src/ui/screens/provider-manager.ts +18 -12
- package/src/ui/screens/wizard.ts +24 -8
- package/src/ui/tui/app.ts +376 -43
- package/src/ui/tui/transcript.ts +269 -65
- package/vendor/minicore/LICENSE +21 -0
- package/vendor/minicore/VENDOR.md +6 -3
- package/vendor/minicore/package.json +6 -3
- package/vendor/minicore/src/core/loop.ts +12 -2
- package/vendor/minicore/src/core/snapshot.ts +4 -0
- package/vendor/minicore/src/providers/openai-compat.ts +76 -25
package/cli/commands/config.ts
CHANGED
|
@@ -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,
|
|
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)
|
|
50
|
+
if (!asked)
|
|
51
|
+
console.error(`unknown subcommand: ${unknown === undefined ? "" : sanitizeAnsiLine(unknown)}\n`)
|
|
49
52
|
console.log(text)
|
|
50
|
-
process.exit(asked ? 0 :
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
251
|
+
process.exit(2)
|
|
240
252
|
}
|
|
241
253
|
} catch {
|
|
242
|
-
console.error(`Invalid URL: ${url}`)
|
|
243
|
-
process.exit(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 {
|
package/cli/commands/exec.ts
CHANGED
|
@@ -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
|
-
//
|
|
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
|
-
|
|
26
|
-
|
|
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(
|
|
36
|
-
const ask = hasFlag(
|
|
37
|
-
const plan = hasFlag(
|
|
38
|
-
const allowlistFlag = hasFlag(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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[] = []
|
package/cli/commands/mcp.ts
CHANGED
|
@@ -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 =
|
|
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 :
|
|
35
|
+
process.exit(asking ? 0 : 2)
|
|
35
36
|
}
|
package/cli/commands/memory.ts
CHANGED
|
@@ -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(
|
|
61
|
+
process.exit(2)
|
|
62
62
|
}
|
|
63
63
|
const cwdArg = getArg("--cwd")
|
|
64
64
|
const asJson = getArg("--json") !== undefined || args.includes("--json")
|
package/cli/commands/pricing.ts
CHANGED
|
@@ -60,10 +60,11 @@ export async function handlePricing(args: string[]): Promise<never> {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (sub === "show") {
|
|
63
|
-
|
|
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(
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
152
|
-
|
|
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)
|
package/cli/commands/sessions.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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 :
|
|
133
|
+
process.exit(asked ? 0 : 2)
|
|
127
134
|
}
|
|
128
135
|
}
|
package/cli/commands/skills.ts
CHANGED
|
@@ -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
|
|
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(
|
|
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 :
|
|
60
|
+
process.exit(asked ? 0 : 2)
|
|
61
61
|
}
|
package/cli/commands/stats.ts
CHANGED
|
@@ -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() }),
|