minicode-ai 0.26.0 → 0.28.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.
- package/cli/args.ts +120 -16
- package/cli/commands/acp.ts +38 -28
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +11 -12
- package/cli/commands/exec.ts +35 -73
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +96 -46
- package/cli/context-command-run.ts +171 -0
- package/cli/context-command.ts +87 -0
- package/cli/index.ts +96 -98
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +246 -123
- package/cli/tui.ts +311 -109
- package/docs/TERMINAL_CONTRACT.md +254 -69
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/config.md +16 -0
- package/docs/environment.md +3 -3
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +3 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +119 -66
- package/src/app/tool-layer.ts +12 -17
- package/src/config.ts +64 -104
- package/src/constants.ts +23 -9
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +109 -0
- package/src/policy/context.ts +78 -37
- package/src/policy/executor.ts +17 -7
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/guards.ts +41 -2
- package/src/providers/provision.ts +6 -60
- package/src/providers/responses.ts +1 -0
- package/src/repo/repomap.ts +180 -23
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +25 -58
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +20 -37
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +59 -23
- package/src/ui/i18n/id.ts +88 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +88 -62
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +154 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/cli/commands/config.ts
CHANGED
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
saveMcpServer,
|
|
7
7
|
} from "../../src/config.ts"
|
|
8
8
|
import { detectAndSave, removeProvider } from "../../src/providers/provision.ts"
|
|
9
|
+
import { formatError } from "../../src/ui/render/errors.ts"
|
|
9
10
|
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
10
11
|
import { renderTable } from "../../src/ui/render/table.ts"
|
|
11
12
|
import { c, glyphs } from "../../src/ui/render/theme.ts"
|
|
13
|
+
import { allowLocalSubcommand, positionalSubArg } from "../args.ts"
|
|
12
14
|
|
|
13
15
|
// Akhiran baris untuk tabel yang dicetak bersama judul. Konstanta bernama
|
|
14
16
|
// (bukan `"\n"` lepas) supaya tidak tertukar dengan escape di template literal.
|
|
@@ -78,19 +80,27 @@ function usageError(message: string): never {
|
|
|
78
80
|
const isHelpFlag = (s: string | undefined): boolean =>
|
|
79
81
|
s === undefined || s === "--help" || s === "-h"
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const allowLocalHere = (args: readonly string[]): boolean => allowLocalSubcommand(args)
|
|
84
|
+
|
|
85
|
+
const positionalArg = (args: readonly string[], i: number): string | undefined =>
|
|
86
|
+
positionalSubArg(args, i)
|
|
87
|
+
|
|
88
|
+
/** Parse daftar `K=V` dipisah koma (`--env` / `--header`) menjadi objek. */
|
|
89
|
+
function parseKvList(raw: string | undefined): Record<string, string> {
|
|
90
|
+
const out: Record<string, string> = {}
|
|
91
|
+
for (const kv of (raw ?? "").split(",")) {
|
|
92
|
+
const [k, ...rest] = kv.split("=")
|
|
93
|
+
if (k && rest.length) out[k.trim()] = rest.join("=").trim()
|
|
94
|
+
}
|
|
95
|
+
return out
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
/** Parse daftar nilai dipisah koma (`--args`) menjadi array string bersih. */
|
|
99
|
+
function parseCsvList(raw: string | undefined): string[] {
|
|
100
|
+
return (raw ?? "")
|
|
101
|
+
.split(",")
|
|
102
|
+
.map((s) => s.trim())
|
|
103
|
+
.filter(Boolean)
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export async function handleConfig(
|
|
@@ -114,7 +124,7 @@ export async function handleConfig(
|
|
|
114
124
|
cwd: getArg("--cwd"),
|
|
115
125
|
})
|
|
116
126
|
console.log(
|
|
117
|
-
`${c.green(
|
|
127
|
+
`${c.green("ok")} Saved provider "${c.bold(sanitizeAnsiLine(entry.id))}" (${sanitizeAnsiLine(entry.providerHint ?? "?")}) models: ${entry.models
|
|
118
128
|
.slice(0, 5)
|
|
119
129
|
.map((m) => sanitizeAnsiLine(m))
|
|
120
130
|
.join(", ")}${entry.models.length > 5 ? " ..." : ""} (${entry.models.length} total)`,
|
|
@@ -129,10 +139,10 @@ export async function handleConfig(
|
|
|
129
139
|
console.log(c.dim("(no providers yet - add one via `minicode config add` or the wizard)"))
|
|
130
140
|
else {
|
|
131
141
|
const tableData = cfg.providers.map((p) => ({
|
|
132
|
-
id: c.cyan(p.id),
|
|
133
|
-
url: p.baseUrl,
|
|
142
|
+
id: c.cyan(sanitizeAnsiLine(p.id)),
|
|
143
|
+
url: sanitizeAnsiLine(p.baseUrl),
|
|
134
144
|
models: String(p.models.length),
|
|
135
|
-
hint: c.dim(p.providerHint ?? "?"),
|
|
145
|
+
hint: c.dim(sanitizeAnsiLine(p.providerHint ?? "?")),
|
|
136
146
|
}))
|
|
137
147
|
console.log(
|
|
138
148
|
`\n${c.bold("Configured LLM Providers")}\n` +
|
|
@@ -156,7 +166,7 @@ export async function handleConfig(
|
|
|
156
166
|
}
|
|
157
167
|
await removeProvider(id, { global: !args.includes("--local"), cwd: getArg("--cwd") })
|
|
158
168
|
console.log(
|
|
159
|
-
`${c.green(
|
|
169
|
+
`${c.green("ok")} Removed provider ${sanitizeAnsiLine(id)} (${!args.includes("--local") ? "global" : "local"})`,
|
|
160
170
|
)
|
|
161
171
|
process.exit(0)
|
|
162
172
|
} else if (sub === "context-window") {
|
|
@@ -177,12 +187,13 @@ export async function handleConfig(
|
|
|
177
187
|
"../../src/policy/context-window-assign.ts"
|
|
178
188
|
)
|
|
179
189
|
const { describeContextWindow } = await import("../../src/policy/context-window-presets.ts")
|
|
180
|
-
const
|
|
190
|
+
const globalFlag = args.includes("--global")
|
|
191
|
+
const localFlag = args.includes("--local")
|
|
181
192
|
const cwdArg = getArg("--cwd")
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
const cfg = await loadConfig(cwdArg, { allowLocal:
|
|
193
|
+
// Bila --local diminta eksplisit, baca juga config lokal tanpa mengharuskan
|
|
194
|
+
// flag kedua --allow-local-config.
|
|
195
|
+
const canReadLocal = allowLocalHere(args) || localFlag
|
|
196
|
+
const cfg = await loadConfig(cwdArg, { allowLocal: canReadLocal })
|
|
186
197
|
|
|
187
198
|
if (!pid) {
|
|
188
199
|
// Daftar ringkas seluruh provider: model mana yang punya nilai eksplisit.
|
|
@@ -258,18 +269,24 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
258
269
|
|
|
259
270
|
const outcome = assignContextWindow(provider, model, value)
|
|
260
271
|
if (!outcome.ok) {
|
|
261
|
-
console.error(`${c.red(
|
|
272
|
+
console.error(`${c.red("failed")} ${formatError(outcome.error)}`)
|
|
262
273
|
process.exit(1)
|
|
263
274
|
}
|
|
264
275
|
const { saveProvider } = await import("../../src/providers/provision.ts")
|
|
276
|
+
// Pertahankan scope asli provider bila user tidak memaksa --global/--local:
|
|
277
|
+
// mencegah duplikasi provider lokal ke config global (paritas /context).
|
|
278
|
+
const inGlobal = (await loadConfig(undefined, { allowLocal: false })).providers.some(
|
|
279
|
+
(p) => p.id === pid,
|
|
280
|
+
)
|
|
281
|
+
const global = localFlag ? false : globalFlag ? true : inGlobal || !canReadLocal
|
|
265
282
|
await saveProvider(outcome.provider, { global, ...(cwdArg ? { cwd: cwdArg } : {}) })
|
|
266
283
|
const shown = sanitizeAnsiLine(model)
|
|
267
284
|
const where = global ? "global" : "local"
|
|
268
285
|
if (outcome.tokens === null) {
|
|
269
|
-
console.log(`${c.green(
|
|
286
|
+
console.log(`${c.green("ok")} ${shown}: back to automatic detection (${where})`)
|
|
270
287
|
} else {
|
|
271
288
|
console.log(
|
|
272
|
-
`${c.green(
|
|
289
|
+
`${c.green("ok")} ${shown}: ${describeContextWindow(outcome.tokens)} ` +
|
|
273
290
|
`(${outcome.tokens.toLocaleString("en-US")} tokens) — ${where}`,
|
|
274
291
|
)
|
|
275
292
|
}
|
|
@@ -296,7 +313,7 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
296
313
|
process.exit(1)
|
|
297
314
|
}
|
|
298
315
|
console.log(
|
|
299
|
-
`${c.green(
|
|
316
|
+
`${c.green("ok")} Removed stored key for ${c.bold(sanitizeAnsiLine(id))} — update config apiKey manually (provider stays disabled until re-set)`,
|
|
300
317
|
)
|
|
301
318
|
process.exit(0)
|
|
302
319
|
}
|
|
@@ -322,7 +339,9 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
322
339
|
const { loadConfig } = await import("../../src/config.ts")
|
|
323
340
|
const { saveProvider } = await import("../../src/providers/provision.ts")
|
|
324
341
|
const global = !args.includes("--local")
|
|
325
|
-
const cfg = await loadConfig(getArg("--cwd"), {
|
|
342
|
+
const cfg = await loadConfig(getArg("--cwd"), {
|
|
343
|
+
allowLocal: allowLocalHere(args) || !global,
|
|
344
|
+
})
|
|
326
345
|
const entry = cfg.providers.find((p) => p.id === id)
|
|
327
346
|
if (!entry) {
|
|
328
347
|
console.error(
|
|
@@ -332,7 +351,7 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
332
351
|
}
|
|
333
352
|
await saveProvider({ ...entry, apiKey: `keystore:${key}` }, { global, cwd: getArg("--cwd") })
|
|
334
353
|
console.log(
|
|
335
|
-
`${c.green(
|
|
354
|
+
`${c.green("ok")} Stored key for ${c.bold(sanitizeAnsiLine(id))} via ${backend} (${global ? "global" : "local"} config now references it)`,
|
|
336
355
|
)
|
|
337
356
|
process.exit(0)
|
|
338
357
|
} else if (sub === "detect") {
|
|
@@ -343,19 +362,17 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
343
362
|
const baseUrl = getArg("--baseUrl")
|
|
344
363
|
const apiKey = getArg("--apiKey")
|
|
345
364
|
if (!baseUrl || !apiKey) {
|
|
346
|
-
usageError("usage: minicode config detect --baseUrl <url> --apiKey <key
|
|
365
|
+
usageError("usage: minicode config detect --baseUrl <url> --apiKey <key>")
|
|
347
366
|
}
|
|
348
367
|
const { detectModels } = await import("../../src/providers/detect.ts")
|
|
349
368
|
const res = await detectModels(baseUrl, apiKey).catch((e) => {
|
|
350
369
|
// Host mati total (bukan sekadar tanpa /models) — katakan begitu,
|
|
351
370
|
// jangan "Detected 0 models" yang menyalahkan kredensial.
|
|
352
|
-
console.error(
|
|
353
|
-
`${c.red(glyphs.cross)} ${sanitizeAnsiLine((e as Error).message)} — check network and URL`,
|
|
354
|
-
)
|
|
371
|
+
console.error(`${c.red("failed")} ${formatError(e)} — check network and URL`)
|
|
355
372
|
process.exit(1)
|
|
356
373
|
})
|
|
357
374
|
console.log(
|
|
358
|
-
`${c.green(
|
|
375
|
+
`${c.green("ok")} Detected ${res.models.length} models (${sanitizeAnsiLine(res.providerHint)}):\n${res.models.map((m) => ` ${glyphs.dot} ${sanitizeAnsiLine(m)}`).join("\n")}`,
|
|
359
376
|
)
|
|
360
377
|
process.exit(0)
|
|
361
378
|
} else if (sub === "mcp") {
|
|
@@ -373,18 +390,10 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
373
390
|
" [--global|--local]",
|
|
374
391
|
)
|
|
375
392
|
}
|
|
376
|
-
const env
|
|
377
|
-
for (const kv of (getArg("--env") ?? "").split(",")) {
|
|
378
|
-
const [k, ...rest] = kv.split("=")
|
|
379
|
-
if (k && rest.length) env[k.trim()] = rest.join("=").trim()
|
|
380
|
-
}
|
|
393
|
+
const env = parseKvList(getArg("--env"))
|
|
381
394
|
|
|
382
395
|
if (url) {
|
|
383
|
-
const headers
|
|
384
|
-
for (const kv of (getArg("--header") ?? "").split(",")) {
|
|
385
|
-
const [k, ...rest] = kv.split("=")
|
|
386
|
-
if (k && rest.length) headers[k.trim()] = rest.join("=").trim()
|
|
387
|
-
}
|
|
396
|
+
const headers = parseKvList(getArg("--header"))
|
|
388
397
|
try {
|
|
389
398
|
const parsed = new URL(url)
|
|
390
399
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
@@ -407,21 +416,18 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
407
416
|
{ global: !args.includes("--local"), cwd: getArg("--cwd") },
|
|
408
417
|
)
|
|
409
418
|
console.log(
|
|
410
|
-
`${c.green(
|
|
419
|
+
`${c.green("ok")} Saved MCP server "${c.bold(sanitizeAnsiLine(id))}" (http): ${sanitizeAnsiLine(url)}`,
|
|
411
420
|
)
|
|
412
421
|
process.exit(0)
|
|
413
422
|
}
|
|
414
423
|
|
|
415
|
-
const cmdArgs = (cmdArgsRaw
|
|
416
|
-
.split(",")
|
|
417
|
-
.map((s) => s.trim())
|
|
418
|
-
.filter(Boolean)
|
|
424
|
+
const cmdArgs = parseCsvList(cmdArgsRaw)
|
|
419
425
|
await saveMcpServer(
|
|
420
426
|
{ id, command, args: cmdArgs, ...(Object.keys(env).length ? { env } : {}) },
|
|
421
427
|
{ global: !args.includes("--local"), cwd: getArg("--cwd") },
|
|
422
428
|
)
|
|
423
429
|
console.log(
|
|
424
|
-
`${c.green(
|
|
430
|
+
`${c.green("ok")} Saved MCP server "${c.bold(sanitizeAnsiLine(id))}": ${sanitizeAnsiLine(command ?? "")} ${cmdArgs.map((a) => sanitizeAnsiLine(a)).join(" ")}`,
|
|
425
431
|
)
|
|
426
432
|
process.exit(0)
|
|
427
433
|
} else if (mcpSub === "list") {
|
|
@@ -432,9 +438,9 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
432
438
|
// Server bisa stdio (command+args) atau HTTP (url). Tampilkan keduanya
|
|
433
439
|
// di kolom yang sama supaya tabel tetap ringkas.
|
|
434
440
|
const tableData = cfg.mcpServers.map((m) => ({
|
|
435
|
-
id: c.cyan(m.id),
|
|
436
|
-
command: m.url ? c.dim("(http)") : (m.command ?? ""),
|
|
437
|
-
args: c.dim(m.url ?? (m.args ?? []).join(" ")),
|
|
441
|
+
id: c.cyan(sanitizeAnsiLine(m.id)),
|
|
442
|
+
command: m.url ? c.dim("(http)") : sanitizeAnsiLine(m.command ?? ""),
|
|
443
|
+
args: c.dim(sanitizeAnsiLine(m.url ?? (m.args ?? []).join(" "))),
|
|
438
444
|
}))
|
|
439
445
|
console.log(
|
|
440
446
|
`\n${c.bold("Configured MCP Servers")}\n` +
|
|
@@ -457,7 +463,7 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
457
463
|
}
|
|
458
464
|
await removeMcpServer(id, { global: !args.includes("--local"), cwd: getArg("--cwd") })
|
|
459
465
|
console.log(
|
|
460
|
-
`${c.green(
|
|
466
|
+
`${c.green("ok")} Removed MCP server ${sanitizeAnsiLine(id)} (${!args.includes("--local") ? "global" : "local"})`,
|
|
461
467
|
)
|
|
462
468
|
process.exit(0)
|
|
463
469
|
} else {
|
|
@@ -474,21 +480,14 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
474
480
|
'usage: minicode config lsp add <ext> --command <cmd> [--args "<arg1,arg2>"] [--env K=V] [--global|--local]',
|
|
475
481
|
)
|
|
476
482
|
}
|
|
477
|
-
const cmdArgs = cmdArgsRaw
|
|
478
|
-
|
|
479
|
-
.map((s) => s.trim())
|
|
480
|
-
.filter(Boolean)
|
|
481
|
-
const env: Record<string, string> = {}
|
|
482
|
-
for (const kv of (getArg("--env") ?? "").split(",")) {
|
|
483
|
-
const [k, ...rest] = kv.split("=")
|
|
484
|
-
if (k && rest.length) env[k.trim()] = rest.join("=").trim()
|
|
485
|
-
}
|
|
483
|
+
const cmdArgs = parseCsvList(cmdArgsRaw)
|
|
484
|
+
const env = parseKvList(getArg("--env"))
|
|
486
485
|
await saveLspServer(
|
|
487
486
|
{ ext, command, args: cmdArgs, ...(Object.keys(env).length ? { env } : {}) },
|
|
488
487
|
{ global: !args.includes("--local"), cwd: getArg("--cwd") },
|
|
489
488
|
)
|
|
490
489
|
console.log(
|
|
491
|
-
`${c.green(
|
|
490
|
+
`${c.green("ok")} Saved LSP server for ${c.bold(sanitizeAnsiLine(ext))}: ${sanitizeAnsiLine(command)} ${cmdArgs.map((a) => sanitizeAnsiLine(a)).join(" ")}`,
|
|
492
491
|
)
|
|
493
492
|
process.exit(0)
|
|
494
493
|
} else if (lspSub === "list") {
|
|
@@ -497,9 +496,9 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
497
496
|
console.log(c.dim("(no LSP servers configured - add via minicode config lsp add)"))
|
|
498
497
|
else {
|
|
499
498
|
const tableData = cfg.lspServers.map((l) => ({
|
|
500
|
-
ext: c.cyan(l.ext),
|
|
501
|
-
command: l.command,
|
|
502
|
-
args: c.dim(l.args.join(" ")),
|
|
499
|
+
ext: c.cyan(sanitizeAnsiLine(l.ext)),
|
|
500
|
+
command: sanitizeAnsiLine(l.command),
|
|
501
|
+
args: c.dim(sanitizeAnsiLine(l.args.join(" "))),
|
|
503
502
|
}))
|
|
504
503
|
console.log(
|
|
505
504
|
`\n${c.bold("Configured LSP Language Servers")}\n` +
|
|
@@ -522,7 +521,7 @@ ${c.bold(`Context windows — ${sanitizeAnsiLine(provider.id)}`)}
|
|
|
522
521
|
}
|
|
523
522
|
await removeLspServer(ext, { global: !args.includes("--local"), cwd: getArg("--cwd") })
|
|
524
523
|
console.log(
|
|
525
|
-
`${c.green(
|
|
524
|
+
`${c.green("ok")} Removed LSP server for ${sanitizeAnsiLine(ext)} (${!args.includes("--local") ? "global" : "local"})`,
|
|
526
525
|
)
|
|
527
526
|
process.exit(0)
|
|
528
527
|
} else {
|
package/cli/commands/daemon.ts
CHANGED
|
@@ -25,7 +25,13 @@ import {
|
|
|
25
25
|
resolveRuntimeMode,
|
|
26
26
|
} from "../../src/runtime/production-execution.ts"
|
|
27
27
|
import { listSessionRuns } from "../../src/session/persistence.ts"
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
allowLocalSubcommand,
|
|
30
|
+
displayWorkMode,
|
|
31
|
+
flagNameOf,
|
|
32
|
+
resolveWorkModeFlag,
|
|
33
|
+
valueFlags,
|
|
34
|
+
} from "../args.ts"
|
|
29
35
|
import type { CliSession, CliSessionOptions } from "../setup.ts"
|
|
30
36
|
|
|
31
37
|
export async function handleDaemon(
|
|
@@ -157,13 +163,19 @@ function fail(json: unknown, human: string, code = 1): never {
|
|
|
157
163
|
process.exit(code)
|
|
158
164
|
}
|
|
159
165
|
|
|
166
|
+
function failUser(json: boolean, reason: string): never {
|
|
167
|
+
fail(json ? { ok: false, code: "USER_ERROR", reason } : null, reason, 2)
|
|
168
|
+
}
|
|
169
|
+
|
|
160
170
|
async function openClient(
|
|
161
171
|
cwd: string | undefined,
|
|
162
172
|
scopes: DaemonScope[],
|
|
163
173
|
who: string,
|
|
174
|
+
json = false,
|
|
164
175
|
): Promise<{ client: DaemonClient; ep: DaemonEndpoint }> {
|
|
165
176
|
const ep = readEndpoint(cwd)
|
|
166
|
-
|
|
177
|
+
const msg = "daemon: tidak ada endpoint — jalankan `minicode daemon start` dulu"
|
|
178
|
+
if (!ep) fail(json ? { ok: false, reason: "no-endpoint", message: msg } : null, msg, 3)
|
|
167
179
|
const cap = issueCapabilityFromEndpoint(ep, { scopes, who })
|
|
168
180
|
const client = await DaemonClient.connect({
|
|
169
181
|
target: { host: ep.host, port: ep.port },
|
|
@@ -332,7 +344,7 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
332
344
|
sid: () => sessionRef?.sessionId ?? "",
|
|
333
345
|
runId: () => null,
|
|
334
346
|
}),
|
|
335
|
-
|
|
347
|
+
allowLocalConfig: allowLocalSubcommand(sub),
|
|
336
348
|
allowlist: false,
|
|
337
349
|
verify: sub.includes("--verify"),
|
|
338
350
|
workMode: workModeResolved.workMode,
|
|
@@ -457,7 +469,7 @@ export interface DaemonHostedRuntime {
|
|
|
457
469
|
/** Tutup sesi yang di-host (idempoten). Dipakai daemon saat shutdown. */
|
|
458
470
|
readonly closeHostedSession: () => Promise<void>
|
|
459
471
|
/** P0.2 (Q5): WorkMode efektif daemon / sesi yang di-host. */
|
|
460
|
-
readonly workMode: "DISCUSS" | "
|
|
472
|
+
readonly workMode: "DISCUSS" | "BUILD"
|
|
461
473
|
/** P0.2 (Q5): Peringatan bila nilai `--work-mode` / env tidak valid. */
|
|
462
474
|
readonly workModeWarning?: string
|
|
463
475
|
}
|
|
@@ -468,13 +480,15 @@ async function startDaemon(
|
|
|
468
480
|
cwd: string | undefined,
|
|
469
481
|
json: boolean,
|
|
470
482
|
): Promise<void> {
|
|
483
|
+
const portRaw = getArg("--port")
|
|
484
|
+
if (portRaw !== undefined && (!/^\d+$/.test(portRaw) || Number(portRaw) > 65535)) {
|
|
485
|
+
failUser(json, `daemon start: --port harus bilangan bulat 0..65535, diterima "${portRaw}"`)
|
|
486
|
+
}
|
|
471
487
|
let started: DaemonHostedRuntime
|
|
472
488
|
try {
|
|
473
489
|
started = await startDaemonHostedRuntime({ sub, getArg, cwd, autoRunPrompt: true })
|
|
474
490
|
} catch (e) {
|
|
475
|
-
if (e instanceof VerifyWorkModeConflictError)
|
|
476
|
-
fail(json ? { ok: false, code: "USER_ERROR", reason: e.message } : null, e.message, 2)
|
|
477
|
-
}
|
|
491
|
+
if (e instanceof VerifyWorkModeConflictError) failUser(json, e.message)
|
|
478
492
|
throw e
|
|
479
493
|
}
|
|
480
494
|
const { host, session, workMode, workModeWarning } = started
|
|
@@ -542,7 +556,7 @@ async function stopDaemon(cwd: string | undefined, json: boolean): Promise<void>
|
|
|
542
556
|
// Objek mentah, bukan string: `fail()` yang meng-encode (lihat kontraknya).
|
|
543
557
|
fail(json ? { ok: false, reason: probe.reason } : null, `daemon: ${probe.reason}`, 3)
|
|
544
558
|
try {
|
|
545
|
-
const { client } = await openClient(cwd, ["admin"], "operator")
|
|
559
|
+
const { client } = await openClient(cwd, ["admin"], "operator", json)
|
|
546
560
|
const res = await client.control("daemon.shutdown", { reason: "cli" }, `stop-${Date.now()}`)
|
|
547
561
|
client.close()
|
|
548
562
|
emit(
|
|
@@ -551,7 +565,8 @@ async function stopDaemon(cwd: string | undefined, json: boolean): Promise<void>
|
|
|
551
565
|
res.ok ? 0 : 1,
|
|
552
566
|
)
|
|
553
567
|
} catch (e) {
|
|
554
|
-
|
|
568
|
+
const msg = `daemon: gagal menghubungi — ${String((e as Error).message ?? e)}`
|
|
569
|
+
fail(json ? { ok: false, error: msg } : null, msg, 1)
|
|
555
570
|
}
|
|
556
571
|
}
|
|
557
572
|
|
|
@@ -568,15 +583,27 @@ async function issueCapability(
|
|
|
568
583
|
.map((s) => s.trim())
|
|
569
584
|
.filter((s): s is DaemonScope => (DAEMON_SCOPES as readonly string[]).includes(s))
|
|
570
585
|
if (scopes.length === 0) {
|
|
571
|
-
|
|
572
|
-
|
|
586
|
+
failUser(
|
|
587
|
+
json,
|
|
573
588
|
`daemon issue: --scopes wajib berisi salah satu dari: ${DAEMON_SCOPES.join(", ")}`,
|
|
574
|
-
|
|
589
|
+
)
|
|
590
|
+
}
|
|
591
|
+
if (ttlRaw !== undefined && (!/^\d+$/.test(ttlRaw) || Number(ttlRaw) <= 0)) {
|
|
592
|
+
failUser(
|
|
593
|
+
json,
|
|
594
|
+
`daemon issue: --ttl harus bilangan bulat positif (milidetik), diterima "${ttlRaw}"`,
|
|
575
595
|
)
|
|
576
596
|
}
|
|
577
597
|
const ep = readEndpoint(cwd)
|
|
578
|
-
if (!ep)
|
|
579
|
-
|
|
598
|
+
if (!ep)
|
|
599
|
+
fail(
|
|
600
|
+
json
|
|
601
|
+
? { ok: false, reason: "no-endpoint", message: "daemon issue: tidak ada endpoint" }
|
|
602
|
+
: null,
|
|
603
|
+
"daemon issue: tidak ada endpoint",
|
|
604
|
+
3,
|
|
605
|
+
)
|
|
606
|
+
const ttl = ttlRaw !== undefined ? Number(ttlRaw) : undefined
|
|
580
607
|
const token = issueCapabilityFromEndpoint(ep, {
|
|
581
608
|
scopes,
|
|
582
609
|
who,
|
|
@@ -587,7 +614,7 @@ async function issueCapability(
|
|
|
587
614
|
|
|
588
615
|
async function listSessions(cwd: string | undefined, json: boolean): Promise<void> {
|
|
589
616
|
try {
|
|
590
|
-
const { client } = await openClient(cwd, ["read:session"], "operator")
|
|
617
|
+
const { client } = await openClient(cwd, ["read:session"], "operator", json)
|
|
591
618
|
const res = await client.control("session.list", {}, `list-${Date.now()}`)
|
|
592
619
|
client.close()
|
|
593
620
|
if (!res.ok)
|
|
@@ -604,6 +631,7 @@ async function listSessions(cwd: string | undefined, json: boolean): Promise<voi
|
|
|
604
631
|
: rows.map((r) => `${r.sid} head=${r.presentationHead} run=${r.runStatus ?? "-"}`)
|
|
605
632
|
emit(lines, json ? JSON.stringify({ ok: true, sessions: rows }) : null, 0)
|
|
606
633
|
} catch (e) {
|
|
607
|
-
|
|
634
|
+
const msg = `daemon: gagal menghubungi — ${String((e as Error).message ?? e)}`
|
|
635
|
+
fail(json ? { ok: false, error: msg } : null, msg, 1)
|
|
608
636
|
}
|
|
609
637
|
}
|
package/cli/commands/doctor.ts
CHANGED
|
@@ -9,10 +9,14 @@ import { scrubSecrets } from "../../src/policy/scrub.ts"
|
|
|
9
9
|
import { dockerAvailable } from "../../src/sandbox/docker.ts"
|
|
10
10
|
import { osSandboxAvailable, osSandboxTypeName } from "../../src/sandbox/os.ts"
|
|
11
11
|
import { c } from "../../src/ui/render/theme.ts"
|
|
12
|
+
import { allowLocalSubcommand, guardSubcommand } from "../args.ts"
|
|
12
13
|
|
|
13
14
|
const DOCTOR_HELP = `minicode doctor — diagnosis lingkungan lokal (tanpa jaringan)
|
|
14
15
|
|
|
15
|
-
minicode doctor [--json] [--cwd <dir>]`
|
|
16
|
+
minicode doctor [--json] [--allow-local-config] [--cwd <dir>]`
|
|
17
|
+
|
|
18
|
+
const out = (msg: string): void => console.log(msg)
|
|
19
|
+
const err = (msg: string): void => console.error(msg)
|
|
16
20
|
|
|
17
21
|
interface DoctorReport {
|
|
18
22
|
bun: string
|
|
@@ -32,8 +36,8 @@ interface DoctorReport {
|
|
|
32
36
|
// Agregasi status yang sebelumnya tersebar di providers/pricing/memory —
|
|
33
37
|
// pola `codex doctor`: satu perintah untuk "apakah mesin ini siap jalan".
|
|
34
38
|
// Murni baca lokal: tanpa request jaringan, tanpa LLM, tanpa tulis file.
|
|
35
|
-
export async function buildDoctorReport(cwd?: string): Promise<DoctorReport> {
|
|
36
|
-
const cfg = await loadConfig(cwd).catch(() => ({ providers: [] }))
|
|
39
|
+
export async function buildDoctorReport(cwd?: string, allowLocal?: boolean): Promise<DoctorReport> {
|
|
40
|
+
const cfg = await loadConfig(cwd, { allowLocal }).catch(() => ({ providers: [] }))
|
|
37
41
|
const providers = cfg.providers ?? []
|
|
38
42
|
await loadPricingOverlay().catch(() => {})
|
|
39
43
|
const meta = pricingOverlayMeta()
|
|
@@ -89,18 +93,13 @@ export async function handleDoctor(
|
|
|
89
93
|
args: string[],
|
|
90
94
|
getArg: (name: string) => string | undefined,
|
|
91
95
|
): Promise<never> {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
console.log(DOCTOR_HELP)
|
|
95
|
-
process.exit(0)
|
|
96
|
-
}
|
|
97
|
-
const r = await buildDoctorReport(getArg("--cwd"))
|
|
96
|
+
guardSubcommand(args, "doctor", DOCTOR_HELP, out, err)
|
|
97
|
+
const r = await buildDoctorReport(getArg("--cwd"), allowLocalSubcommand(args))
|
|
98
98
|
if (getArg("--json") !== undefined || args.includes("--json")) {
|
|
99
|
-
|
|
99
|
+
out(JSON.stringify(r))
|
|
100
100
|
process.exit(0)
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
console.log("")
|
|
102
|
+
out(`${renderDoctorText(r)}\n`)
|
|
104
103
|
process.exit(0)
|
|
105
104
|
}
|
|
106
105
|
|