minicode-ai 0.27.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 +73 -44
- package/cli/context-command-run.ts +30 -18
- package/cli/index.ts +48 -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 +303 -100
- 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/environment.md +1 -2
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +2 -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 +4 -6
- 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 +31 -8
- package/src/policy/context.ts +62 -36
- 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/provision.ts +6 -56
- package/src/providers/responses.ts +1 -0
- 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 +47 -23
- package/src/ui/i18n/id.ts +76 -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 +82 -61
- 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/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { readFileSync } from "node:fs"
|
|
3
3
|
import { resolve as resolvePath } from "node:path"
|
|
4
|
+
import { expandMentions } from "../src/app/mentions.ts"
|
|
4
5
|
import { NoProviderError } from "../src/app/provider-layer.ts"
|
|
5
6
|
import { createMinicodeSession } from "../src/app/session.ts"
|
|
6
7
|
import { parseCompactKeepTurns } from "../src/policy/compaction.ts"
|
|
@@ -21,20 +22,22 @@ import { setSubAgentSessionFactory } from "../src/tools/task.ts"
|
|
|
21
22
|
import { formatError } from "../src/ui/assistant/simple.ts"
|
|
22
23
|
import { type MsgKey, t } from "../src/ui/i18n/locale.ts"
|
|
23
24
|
import { formatUsd } from "../src/ui/render/money.ts"
|
|
24
|
-
import { c
|
|
25
|
+
import { c } from "../src/ui/render/theme.ts"
|
|
25
26
|
import { motionReduced } from "../src/ui/runtime/motion.ts"
|
|
26
27
|
import {
|
|
27
28
|
allowLocalConfig,
|
|
28
29
|
displayWorkMode,
|
|
29
30
|
flagsAfterPromptBoundary,
|
|
30
31
|
hasFlag,
|
|
32
|
+
parseRuntimeNumericFlags,
|
|
31
33
|
promptFromArgs,
|
|
32
34
|
getArg as rawGetArg,
|
|
33
35
|
readPrompt,
|
|
36
|
+
resolveToolScope,
|
|
34
37
|
resolveWorkModeFlag,
|
|
35
38
|
} from "./args.ts"
|
|
36
39
|
import { dispatch } from "./router.ts"
|
|
37
|
-
import { createCliSession } from "./setup.ts"
|
|
40
|
+
import { createChildCompaction, createCliSession } from "./setup.ts"
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* Jaring terakhir proses (audit freeze/ceket 2026-11-16).
|
|
@@ -116,7 +119,6 @@ Options:
|
|
|
116
119
|
--session <id> session id (default random)
|
|
117
120
|
--allow-all allow all tools (privileged access profile; hard jail/guard still apply)
|
|
118
121
|
--ask ask per tool (y/n/a) — human-supervised execution
|
|
119
|
-
--plan deprecated: alias for --work-mode PLAN (read-only planning)
|
|
120
122
|
--allowlist bash allowlist only (see MINICODE_BASH_ALLOWLIST)
|
|
121
123
|
--max-steps <n> max tool steps (default 50)
|
|
122
124
|
--context-window <n> context window tokens
|
|
@@ -128,8 +130,8 @@ Options:
|
|
|
128
130
|
--budget <usd> session cost limit
|
|
129
131
|
--budget-strict unknown cost + spend counts as over budget (fail-closed default)
|
|
130
132
|
--tool-scope <s> full (default) | explore (read-only subset)
|
|
131
|
-
--work-mode <m> DISCUSS |
|
|
132
|
-
read-only investigation,
|
|
133
|
+
--work-mode <m> DISCUSS | BUILD (default: DISCUSS). Operating mode: DISCUSS =
|
|
134
|
+
read-only investigation, discussion & planning, BUILD = implementation.
|
|
133
135
|
--tui deprecated no-op (interactive mode is always the fullscreen TUI)
|
|
134
136
|
--enable-scheduler EXPERIMENTAL: opt in to the autonomous scheduler (default: off).
|
|
135
137
|
Manual only - run /scheduler run. No timer; autonomous turns are
|
|
@@ -140,7 +142,7 @@ Options:
|
|
|
140
142
|
admitted through the runtime (kernel + durable journal); a rejected
|
|
141
143
|
admission runs nothing. Unknown value = off.
|
|
142
144
|
|
|
143
|
-
TUI: /help /provider /model /sync /status /sessions /init /exit /mode /work-mode /undo /redo /clear /copy /history /compact /thinking /minimize
|
|
145
|
+
TUI: /help /provider /model /context /sync /status /sessions /init /exit /mode /work-mode /undo /redo /clear /copy /history /compact /thinking /expand /minimize /fold /lang /scheduler
|
|
144
146
|
Keys: Enter submit · Tab work-mode · Shift+Tab permission · Up/Down history · Mouse wheel/PgUp/PgDn scroll (Shift = half page)
|
|
145
147
|
Home/End jump to transcript top/tail · Ctrl+R search · Esc abort turn (twice = quit) · Ctrl+D exit
|
|
146
148
|
Subcommand flags (config/mcp/sessions/skills/exec/...): see 'minicode <cmd> --help'.
|
|
@@ -202,13 +204,29 @@ setSubAgentSessionFactory(async (spec) => {
|
|
|
202
204
|
const { journal, ...coreSpec } = spec
|
|
203
205
|
const contextWindowTokensForModel = coreSpec.provider.contextWindowTokensForModel
|
|
204
206
|
const contextModelIdentity = coreSpec.provider.contextModelIdentity
|
|
207
|
+
const getContextModel = () => contextModelIdentity?.(coreSpec.model) ?? coreSpec.model
|
|
208
|
+
let childJournalHandle: ReturnType<typeof attachMutationJournal> | null = null
|
|
205
209
|
const session = await createMinicodeSession({
|
|
206
210
|
...coreSpec,
|
|
211
|
+
compaction: createChildCompaction({
|
|
212
|
+
provider: coreSpec.provider,
|
|
213
|
+
model: coreSpec.model,
|
|
214
|
+
cwd: coreSpec.cwd,
|
|
215
|
+
contextWindowTokensForModel,
|
|
216
|
+
getContextModel,
|
|
217
|
+
}),
|
|
218
|
+
...(journal
|
|
219
|
+
? {
|
|
220
|
+
beforeToolEffect: async (call) => {
|
|
221
|
+
if (childJournalHandle !== null) await childJournalHandle.preflightIntent(call)
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
: {}),
|
|
207
225
|
...(contextWindowTokensForModel
|
|
208
226
|
? {
|
|
209
227
|
contextWindowTokens: contextWindowTokensForModel(coreSpec.model),
|
|
210
228
|
contextWindowTokensForModel,
|
|
211
|
-
getContextModel
|
|
229
|
+
getContextModel,
|
|
212
230
|
}
|
|
213
231
|
: {}),
|
|
214
232
|
})
|
|
@@ -226,7 +244,7 @@ setSubAgentSessionFactory(async (spec) => {
|
|
|
226
244
|
session.events.on("turn:completed", () => {
|
|
227
245
|
void childWrite.finally(() => childPresentation.dispose())
|
|
228
246
|
})
|
|
229
|
-
attachMutationJournal(session, {
|
|
247
|
+
childJournalHandle = attachMutationJournal(session, {
|
|
230
248
|
sessionId: journal.sessionId,
|
|
231
249
|
cwd: spec.cwd,
|
|
232
250
|
childOf: journal.parentSessionId,
|
|
@@ -308,7 +326,6 @@ if (args.includes("-h") || args.includes("--help")) {
|
|
|
308
326
|
},
|
|
309
327
|
{ flag: "--allow-all", desc: "allow all tools (privileged access profile)" },
|
|
310
328
|
{ flag: "--ask", desc: "ask per tool (human-supervised)" },
|
|
311
|
-
{ flag: "--plan", desc: "deprecated: alias for --work-mode PLAN" },
|
|
312
329
|
{ flag: "--allowlist", desc: "bash allowlist only" },
|
|
313
330
|
{ flag: "--interactive", desc: "interactive TUI" },
|
|
314
331
|
{ flag: "--verify", desc: "auto-verify + self-heal" },
|
|
@@ -318,8 +335,8 @@ if (args.includes("-h") || args.includes("--help")) {
|
|
|
318
335
|
{ flag: "--budget-strict", desc: "unknown cost + spend counts as over budget (default)" },
|
|
319
336
|
{ flag: "--tool-scope <full|explore>", desc: "tool subset (explore = read-only)" },
|
|
320
337
|
{
|
|
321
|
-
flag: "--work-mode <DISCUSS|
|
|
322
|
-
desc: "operating mode: DISCUSS (default, read-only),
|
|
338
|
+
flag: "--work-mode <DISCUSS|BUILD>",
|
|
339
|
+
desc: "operating mode: DISCUSS (default, read-only), BUILD",
|
|
323
340
|
},
|
|
324
341
|
{ flag: "--json", desc: "JSON output (help/exec)" },
|
|
325
342
|
{ flag: "--tui", desc: "deprecated no-op (interactive is always the fullscreen TUI)" },
|
|
@@ -337,7 +354,6 @@ const verbose = hasFlag(args, "--verbose")
|
|
|
337
354
|
const allowAll = hasFlag(args, "--allow-all")
|
|
338
355
|
const ask = hasFlag(args, "--ask")
|
|
339
356
|
const interactive = hasFlag(args, "--interactive")
|
|
340
|
-
const plan = hasFlag(args, "--plan") || process.env.MINICODE_PLAN === "1"
|
|
341
357
|
const allowlist = hasFlag(args, "--allowlist") || process.env.MINICODE_PERMISSION === "allowlist"
|
|
342
358
|
// [mode-architecture] Deprecation notice utk profil warisan — jangan dihapus
|
|
343
359
|
// diam-diam; peta kompatibilitas di MODE_ARCHITECTURE_MIGRATION_REPORT.
|
|
@@ -356,9 +372,8 @@ const cwd = cwdRaw ? resolvePath(cwdRaw) : undefined
|
|
|
356
372
|
// eksplisit per-invokasi (flag atau env). Tanpa ini repo clone-an bisa
|
|
357
373
|
// men-spawn MCP server dan menyedot prompt ke endpoint penyerang.
|
|
358
374
|
const allowLocal = allowLocalConfig(args)
|
|
359
|
-
// WorkMode (lapis intent di atas profil izin). Flag mengalahkan env;
|
|
375
|
+
// WorkMode (lapis intent 2-mode di atas profil izin). Flag mengalahkan env;
|
|
360
376
|
// keduanya tak ada atau nilainya tak dikenal = DISCUSS (fail-closed).
|
|
361
|
-
// `--plan` adalah alias legacy untuk WorkMode PLAN.
|
|
362
377
|
const workModeResolved = resolveWorkModeFlag(getArg)
|
|
363
378
|
const workMode = workModeResolved.workMode
|
|
364
379
|
// Sinyal WorkMode eksplisit (flag/env) ikut diteruskan agar resume dapat
|
|
@@ -413,30 +428,18 @@ const adoptTask = adoptTaskParsed ?? undefined
|
|
|
413
428
|
const bootId = mintSessionId()
|
|
414
429
|
const modelOverride = getArg("--model")
|
|
415
430
|
const providerOverride = getArg("--provider")
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
if (maxStepsRaw && (!Number.isFinite(maxSteps) || (maxSteps as number) <= 0)) {
|
|
419
|
-
process.stderr.write(`[warn] --max-steps requires a positive number, ignoring "${maxStepsRaw}"\n`)
|
|
420
|
-
maxSteps = undefined
|
|
431
|
+
const warnStderr = (msg: string): void => {
|
|
432
|
+
process.stderr.write(msg)
|
|
421
433
|
}
|
|
434
|
+
const { maxSteps, contextWindowTokens, timeoutMs, budget, ratelimitRpm } = parseRuntimeNumericFlags(
|
|
435
|
+
getArg,
|
|
436
|
+
warnStderr,
|
|
437
|
+
)
|
|
422
438
|
// `--tui` alias usang (TUI fullscreen kini satu-satunya tampilan interaktif):
|
|
423
439
|
// tetap diterima agar skrip lama tak pecah, tapi TIDAK diam — tanpa peringatan
|
|
424
440
|
// user mengira flag-nya masih mengubah perilaku.
|
|
425
441
|
if (args.includes("--tui")) {
|
|
426
|
-
|
|
427
|
-
"[deprecated] --tui is a no-op: interactive mode is always the fullscreen TUI\n",
|
|
428
|
-
)
|
|
429
|
-
}
|
|
430
|
-
const ctxWindowRaw = getArg("--context-window")
|
|
431
|
-
let contextWindowTokens = ctxWindowRaw ? Number(ctxWindowRaw) : undefined
|
|
432
|
-
if (
|
|
433
|
-
ctxWindowRaw &&
|
|
434
|
-
(!Number.isFinite(contextWindowTokens) || (contextWindowTokens as number) <= 0)
|
|
435
|
-
) {
|
|
436
|
-
process.stderr.write(
|
|
437
|
-
`[warn] --context-window requires a positive number, ignoring "${ctxWindowRaw}"\n`,
|
|
438
|
-
)
|
|
439
|
-
contextWindowTokens = undefined
|
|
442
|
+
warnStderr("[deprecated] --tui is a no-op: interactive mode is always the fullscreen TUI\n")
|
|
440
443
|
}
|
|
441
444
|
// F3.2: override keepRecentTurns kompaksi kernel via env (bukan flag: jarang
|
|
442
445
|
// diubah, dan permukaan flag CLI sengaja kecil). Selain bilangan >=1 =
|
|
@@ -444,23 +447,15 @@ if (
|
|
|
444
447
|
const keepTurnsRaw = (process.env.MINICODE_COMPACT_KEEP_TURNS ?? "").trim()
|
|
445
448
|
const keepRecentTurns = parseCompactKeepTurns(keepTurnsRaw || undefined)
|
|
446
449
|
if (keepTurnsRaw && keepRecentTurns === undefined)
|
|
447
|
-
|
|
450
|
+
warnStderr(
|
|
448
451
|
`[warn] MINICODE_COMPACT_KEEP_TURNS requires an integer >= 1, ignoring "${keepTurnsRaw}"\n`,
|
|
449
452
|
)
|
|
450
|
-
const timeoutRaw = getArg("--timeout")
|
|
451
|
-
let timeoutMs = timeoutRaw ? Number(timeoutRaw) : undefined
|
|
452
|
-
if (timeoutRaw && (!Number.isFinite(timeoutMs) || (timeoutMs as number) < 0)) {
|
|
453
|
-
process.stderr.write(
|
|
454
|
-
`[warn] --timeout requires a non-negative number, ignoring "${timeoutRaw}"\n`,
|
|
455
|
-
)
|
|
456
|
-
timeoutMs = undefined
|
|
457
|
-
}
|
|
458
453
|
|
|
459
454
|
// Sandbox: OS-native dipakai otomatis bila tersedia. Bila tidak ada isolasi
|
|
460
455
|
// nyata dan user belum memilih mode permission sendiri, default diturunkan ke
|
|
461
456
|
// `allowlist` — lebih baik membatasi perintah daripada menjalankan apa pun
|
|
462
457
|
// sambil menampilkan label aman. Lihat src/policy/sandbox-policy.ts.
|
|
463
|
-
const explicitPermission = allowAll || ask ||
|
|
458
|
+
const explicitPermission = allowAll || ask || allowlist
|
|
464
459
|
const requestedSandbox = getArg("--sandbox") ?? process.env.MINICODE_SANDBOX
|
|
465
460
|
// F-03: permintaan sandbox EKSPLISIT tanpa backend = tolak sebelum jalan
|
|
466
461
|
// (fail-closed). resolveSandbox di bawah tetap menghitung downgrade allowlist
|
|
@@ -477,29 +472,11 @@ else process.env.MINICODE_SANDBOX = sandbox.mode
|
|
|
477
472
|
// mode tak dikenal). Notice rutin disembunyikan: mode terlihat di prefiks.
|
|
478
473
|
// Cetaknya di setup, setelah provider layer lolos.
|
|
479
474
|
const effectiveAllowlist = allowlist || sandbox.fallbackPermission === "allowlist"
|
|
480
|
-
const budgetRaw = getArg("--budget")
|
|
481
|
-
let budget = budgetRaw ? Number(budgetRaw) : undefined
|
|
482
|
-
if (budgetRaw && (!Number.isFinite(budget) || (budget as number) < 0)) {
|
|
483
|
-
process.stderr.write(`[warn] --budget requires a USD number, ignoring "${budgetRaw}"\n`)
|
|
484
|
-
budget = undefined
|
|
485
|
-
}
|
|
486
475
|
// Harness-P1: strict lewat flag ATAU env (simetri dengan MINICODE_SANDBOX_STRICT).
|
|
487
476
|
const budgetStrict = hasFlag(args, "--budget-strict") || process.env.MINICODE_BUDGET_STRICT === "1"
|
|
488
477
|
// Harness-P2: scope tool sesi; nilai selain explore jatuh ke full (eksplisit di bawah).
|
|
489
|
-
const
|
|
490
|
-
const
|
|
491
|
-
const ratelimitRaw = getArg("--ratelimit")
|
|
492
|
-
let rateLimiter: ReturnType<typeof createRateLimiter> | undefined
|
|
493
|
-
if (ratelimitRaw) {
|
|
494
|
-
const rpm = Number(ratelimitRaw)
|
|
495
|
-
if (!Number.isFinite(rpm) || rpm <= 0) {
|
|
496
|
-
process.stderr.write(
|
|
497
|
-
`[warn] --ratelimit requires a positive number, ignoring "${ratelimitRaw}"\n`,
|
|
498
|
-
)
|
|
499
|
-
} else {
|
|
500
|
-
rateLimiter = createRateLimiter(rpm)
|
|
501
|
-
}
|
|
502
|
-
}
|
|
478
|
+
const toolScope = resolveToolScope(getArg)
|
|
479
|
+
const rateLimiter = ratelimitRpm !== undefined ? createRateLimiter(ratelimitRpm) : undefined
|
|
503
480
|
|
|
504
481
|
const prompt = promptFromArgs(args) || (await readPrompt())
|
|
505
482
|
// [Live Hardening 0.13.x §8.3] Flag dikenal yang muncul SETELAH prompt boundary
|
|
@@ -568,7 +545,7 @@ try {
|
|
|
568
545
|
const spaceIdx = prompt.indexOf(" ")
|
|
569
546
|
const skillName = spaceIdx === -1 ? prompt.slice(1) : prompt.slice(1, spaceIdx)
|
|
570
547
|
const skillArgs = spaceIdx === -1 ? "" : prompt.slice(spaceIdx + 1)
|
|
571
|
-
const skill = await findSkill(skillName, cwd)
|
|
548
|
+
const skill = await findSkill(skillName, cwd, { allowLocal })
|
|
572
549
|
if (skill) {
|
|
573
550
|
effectivePrompt = await renderSkill(skill, skillArgs)
|
|
574
551
|
console.error(c.dim(`[loaded skill /${skill.name}]`))
|
|
@@ -624,7 +601,6 @@ try {
|
|
|
624
601
|
verbose,
|
|
625
602
|
allowAll,
|
|
626
603
|
ask,
|
|
627
|
-
plan,
|
|
628
604
|
allowlist: effectiveAllowlist,
|
|
629
605
|
verify,
|
|
630
606
|
allowLocalConfig: allowLocal,
|
|
@@ -723,12 +699,7 @@ if (enterRepl) {
|
|
|
723
699
|
// efektif (termasuk hasil pulihan `--resume`).
|
|
724
700
|
if (ctx.workMode !== "EXECUTE" || workModeExplicit) {
|
|
725
701
|
const workModeLabel = displayWorkMode(ctx.workMode)
|
|
726
|
-
const modeNote =
|
|
727
|
-
ctx.workMode === "PLAN"
|
|
728
|
-
? " (read-only planning)"
|
|
729
|
-
: ctx.workMode === "DISCUSS"
|
|
730
|
-
? " (read-only)"
|
|
731
|
-
: ""
|
|
702
|
+
const modeNote = ctx.workMode === "DISCUSS" ? " (read-only)" : ""
|
|
732
703
|
process.stderr.write(`[work-mode] ${workModeLabel}${modeNote}\n`)
|
|
733
704
|
}
|
|
734
705
|
const {
|
|
@@ -745,7 +716,11 @@ if (enterRepl) {
|
|
|
745
716
|
} = ctx
|
|
746
717
|
const t0 = Date.now()
|
|
747
718
|
try {
|
|
748
|
-
|
|
719
|
+
let finalPrompt = effectivePrompt
|
|
720
|
+
if (finalPrompt.includes("@")) {
|
|
721
|
+
finalPrompt = (await expandMentions(finalPrompt, wcwd ?? process.cwd())).prompt
|
|
722
|
+
}
|
|
723
|
+
await runPromptWithVerify(finalPrompt)
|
|
749
724
|
// Total SESI, bukan turn: satu one-shot hanya punya satu turn, tapi
|
|
750
725
|
// --verify/self-heal bisa menjalankan beberapa dan reset() di antaranya.
|
|
751
726
|
const u = usage.getSession(modelRef.current)
|
|
@@ -811,7 +786,7 @@ if (enterRepl) {
|
|
|
811
786
|
// Error provider biasanya sudah dirender ramah oleh event handler
|
|
812
787
|
// (takePendingError) — cetak sekali saja, jangan dua blok error.
|
|
813
788
|
const shown = ctx.uiState.takePendingError()
|
|
814
|
-
process.stderr.write(`\n${c.red(
|
|
789
|
+
process.stderr.write(`\n${c.red("failed")} ${shown ?? formatError(e)}\n`)
|
|
815
790
|
// Audit #04 P1: sama seperti REPL — turn gagal setelah delegasi
|
|
816
791
|
// committed = efek anak tetap ada. One-shot tak punya retry loop, tapi
|
|
817
792
|
// user yang menjalankan ulang manual butuh peringatan yang sama.
|
|
@@ -848,29 +823,4 @@ if (enterRepl) {
|
|
|
848
823
|
}
|
|
849
824
|
await new Promise((r) => setTimeout(r, 200))
|
|
850
825
|
await close()
|
|
851
|
-
|
|
852
|
-
if (ctx.permissionMode === "plan" && process.stdin.isTTY) {
|
|
853
|
-
const { createInterface } = await import("node:readline")
|
|
854
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
855
|
-
const ans = await new Promise<string>((res) =>
|
|
856
|
-
rl.question(c.yellow("\nProceed to execute this plan? [y/N] "), res),
|
|
857
|
-
)
|
|
858
|
-
rl.close()
|
|
859
|
-
if (ans.trim().toLowerCase() === "y") {
|
|
860
|
-
const { spawn } = await import("node:child_process")
|
|
861
|
-
const { waitChildExit } = await import("./auto-update.ts")
|
|
862
|
-
const entry = process.argv[1] ?? resolvePath(import.meta.dir, "index.ts")
|
|
863
|
-
const filtered = args.filter((a) => a !== "--plan")
|
|
864
|
-
const child = spawn(process.execPath, [entry, ...filtered], {
|
|
865
|
-
stdio: "inherit",
|
|
866
|
-
env: { ...process.env, MINICODE_PLAN: "0" },
|
|
867
|
-
})
|
|
868
|
-
// Tunggu via mekanisme tunggal (exit+close+error): exit saja bisa tak
|
|
869
|
-
// datang bila anak menahan stdio = induk gantung tanpa prompt.
|
|
870
|
-
void waitChildExit(child).then((code) => process.exit(code ?? 0))
|
|
871
|
-
process.stdin.resume()
|
|
872
|
-
} else {
|
|
873
|
-
process.exit(0)
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
826
|
}
|
package/cli/model-manager.ts
CHANGED
|
@@ -56,7 +56,10 @@ export async function runModelManager(opts: {
|
|
|
56
56
|
id: string,
|
|
57
57
|
mutate: (p: ProviderEntry) => void,
|
|
58
58
|
): Promise<void> => {
|
|
59
|
-
const paths =
|
|
59
|
+
const paths =
|
|
60
|
+
opts.cwd && opts.allowLocalConfig
|
|
61
|
+
? [resolve(opts.cwd, LOCAL), globalConfigPath()]
|
|
62
|
+
: [globalConfigPath()]
|
|
60
63
|
let touched = false
|
|
61
64
|
for (const path of paths) {
|
|
62
65
|
let cfg: MinicodeConfig
|
|
@@ -86,8 +89,10 @@ export async function runModelManager(opts: {
|
|
|
86
89
|
onSelect: async (id) => {
|
|
87
90
|
// Reload providers agar router langsung kenal provider baru tanpa restart
|
|
88
91
|
const { reloadProviders } = await import("../src/app/provider-layer.ts")
|
|
92
|
+
// Jangan tulis mentah ke stderr saat alt-screen masih aktif; tulis lewat
|
|
93
|
+
// log standar ditangkap captureConsole → mendarat bersih sesudah popup.
|
|
89
94
|
await reloadProviders(opts.cwd, { allowLocal: opts.allowLocalConfig }).catch(() =>
|
|
90
|
-
|
|
95
|
+
console.error(`[warn] ${t("prov.reloadFail")}`),
|
|
91
96
|
)
|
|
92
97
|
opts.setModelOverride?.(id)
|
|
93
98
|
},
|
package/cli/provider-manager.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { loadConfig, type MinicodeConfig } from "../src/config.ts"
|
|
|
6
6
|
import { GATEWAY_PRESETS } from "../src/providers/presets.ts"
|
|
7
7
|
import { detectAndSave, removeProvider } from "../src/providers/provision.ts"
|
|
8
8
|
import { t } from "../src/ui/i18n/locale.ts"
|
|
9
|
+
import { formatError } from "../src/ui/render/errors.ts"
|
|
10
|
+
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
9
11
|
import {
|
|
10
12
|
type ProviderActionResult,
|
|
11
13
|
type ProviderRow,
|
|
@@ -30,13 +32,20 @@ export async function runProviderManager(opts: {
|
|
|
30
32
|
}): Promise<void> {
|
|
31
33
|
if (!process.stdin.isTTY) {
|
|
32
34
|
const cfg = await loadConfig(opts.cwd, { allowLocal: opts.allowLocalConfig })
|
|
33
|
-
for (const p of cfg.providers) console.log(p.id)
|
|
35
|
+
for (const p of cfg.providers) console.log(sanitizeAnsiLine(p.id))
|
|
34
36
|
return
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
const
|
|
39
|
+
// Simpan kegagalan muat-ulang agar ditampilkan sebagai notice di dalam kotak
|
|
40
|
+
// Layer 2 (bukan menulis mentah ke stderr saat popup masih terbuka).
|
|
41
|
+
const reloadSuffix = async (): Promise<string> => {
|
|
42
|
+
try {
|
|
43
|
+
await reloadProviders(opts.cwd, { allowLocal: opts.allowLocalConfig })
|
|
44
|
+
return ""
|
|
45
|
+
} catch {
|
|
46
|
+
return ` (${t("prov.reloadFail")})`
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
|
|
41
50
|
await runProviderManagerView({
|
|
42
51
|
initialRows: rowsFrom(await loadConfig(opts.cwd, { allowLocal: opts.allowLocalConfig })),
|
|
@@ -60,19 +69,20 @@ export async function runProviderManager(opts: {
|
|
|
60
69
|
fallbackModels,
|
|
61
70
|
allowLocal: opts.allowLocalConfig,
|
|
62
71
|
})
|
|
63
|
-
|
|
72
|
+
const warn = await reloadSuffix()
|
|
64
73
|
return {
|
|
65
|
-
ok: t("ntc.saved", { id: entry.id, n: entry.models.length, scope })
|
|
74
|
+
ok: `${t("ntc.saved", { id: entry.id, n: entry.models.length, scope })}${warn}`,
|
|
66
75
|
}
|
|
67
76
|
} catch (e) {
|
|
68
|
-
return { err: t("prov.detectFail", { msg: (e
|
|
77
|
+
return { err: t("prov.detectFail", { msg: formatError(e) }) }
|
|
69
78
|
}
|
|
70
79
|
},
|
|
71
80
|
onDelete: async (row): Promise<ProviderActionResult> => {
|
|
72
81
|
await removeProvider(row.id, { global: true })
|
|
73
|
-
if (opts.cwd
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
if (opts.cwd && opts.allowLocalConfig)
|
|
83
|
+
await removeProvider(row.id, { global: false, cwd: opts.cwd })
|
|
84
|
+
const warn = await reloadSuffix()
|
|
85
|
+
return { ok: `${t("prov.deleted", { id: row.id })}${warn}` }
|
|
76
86
|
},
|
|
77
87
|
onEditDefaults: async (row) => {
|
|
78
88
|
const cfg = await loadConfig(opts.cwd, { allowLocal: opts.allowLocalConfig })
|
|
@@ -84,25 +94,30 @@ export async function runProviderManager(opts: {
|
|
|
84
94
|
const cfg = await loadConfig(opts.cwd, { allowLocal: opts.allowLocalConfig })
|
|
85
95
|
const cur = cfg.providers.find((p) => p.id === row.id)
|
|
86
96
|
if (!cur) return { err: t("ntc.notFound") }
|
|
97
|
+
const inGlobal = (await loadConfig(undefined, { allowLocal: false })).providers.some(
|
|
98
|
+
(p) => p.id === row.id,
|
|
99
|
+
)
|
|
100
|
+
const saveGlobal = inGlobal || !opts.allowLocalConfig || !opts.cwd
|
|
87
101
|
try {
|
|
88
|
-
await removeProvider(row.id, { global: true })
|
|
89
|
-
if (opts.cwd
|
|
102
|
+
if (inGlobal) await removeProvider(row.id, { global: true })
|
|
103
|
+
if (opts.cwd && opts.allowLocalConfig)
|
|
104
|
+
await removeProvider(row.id, { global: false, cwd: opts.cwd })
|
|
90
105
|
const entry = await detectAndSave(baseUrl, apiKey, row.id, {
|
|
91
|
-
global:
|
|
106
|
+
global: saveGlobal,
|
|
92
107
|
cwd: opts.cwd,
|
|
93
108
|
fallbackModels: cur.models,
|
|
94
109
|
allowLocal: opts.allowLocalConfig,
|
|
95
110
|
})
|
|
96
|
-
|
|
97
|
-
return { ok: t("ntc.updated", { id: entry.id, n: entry.models.length }) }
|
|
111
|
+
const warn = await reloadSuffix()
|
|
112
|
+
return { ok: `${t("ntc.updated", { id: entry.id, n: entry.models.length })}${warn}` }
|
|
98
113
|
} catch (e) {
|
|
99
114
|
await detectAndSave(cur.baseUrl, cur.apiKey, cur.id, {
|
|
100
|
-
global:
|
|
115
|
+
global: saveGlobal,
|
|
101
116
|
cwd: opts.cwd,
|
|
102
117
|
fallbackModels: cur.models,
|
|
103
118
|
}).catch(() => {})
|
|
104
|
-
|
|
105
|
-
return { err: t("prov.updateFail", { msg: (e
|
|
119
|
+
const warn = await reloadSuffix()
|
|
120
|
+
return { err: `${t("prov.updateFail", { msg: formatError(e) })}${warn}` }
|
|
106
121
|
}
|
|
107
122
|
},
|
|
108
123
|
})
|
package/cli/router.ts
CHANGED
|
@@ -60,6 +60,10 @@ export async function dispatch(
|
|
|
60
60
|
if (a === undefined) continue
|
|
61
61
|
if (a === "--") break
|
|
62
62
|
if (a === name) {
|
|
63
|
+
if (!valueFlags.has(name)) {
|
|
64
|
+
found = "1"
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
63
67
|
const v = subArgv[i + 1]
|
|
64
68
|
if (v !== undefined && (v === "-" || !v.startsWith("-") || /^-?\d+(\.\d+)?$/.test(v)))
|
|
65
69
|
found = v
|
|
@@ -71,19 +75,44 @@ export async function dispatch(
|
|
|
71
75
|
return found
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
// P11.x
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
// P11.x + CMD-03: pisahkan positional pasca-subcommand ke indeks 1..N sebelum
|
|
79
|
+
// flag global & pasca-subcommand agar flag mendahului subcommand tetap terbaca.
|
|
80
|
+
const postPositionals: string[] = []
|
|
81
|
+
const postFlags: string[] = []
|
|
82
|
+
for (let i = cmdIndex + 1; i < args.length; i++) {
|
|
83
|
+
const t = args[i]
|
|
84
|
+
if (t === undefined) continue
|
|
85
|
+
if (t === "--") {
|
|
86
|
+
postPositionals.push(...args.slice(i + 1))
|
|
87
|
+
break
|
|
88
|
+
}
|
|
89
|
+
const flag = flagNameOf(t)
|
|
90
|
+
if (flag) {
|
|
91
|
+
postFlags.push(t)
|
|
92
|
+
if (valueFlags.has(flag) && !t.includes("=") && i + 1 < args.length) {
|
|
93
|
+
const v = args[i + 1]
|
|
94
|
+
if (v !== undefined) {
|
|
95
|
+
postFlags.push(v)
|
|
96
|
+
i++
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
if (t.startsWith("-")) {
|
|
102
|
+
postFlags.push(t)
|
|
103
|
+
continue
|
|
104
|
+
}
|
|
105
|
+
postPositionals.push(t)
|
|
106
|
+
}
|
|
107
|
+
const scoped = [
|
|
108
|
+
args[cmdIndex]!,
|
|
109
|
+
...postPositionals,
|
|
110
|
+
...subArgv.slice(0, cmdTokenPos),
|
|
111
|
+
...postFlags,
|
|
112
|
+
]
|
|
84
113
|
if (cmd === "stats") {
|
|
85
114
|
const { handleStats } = await import("./commands/stats.ts")
|
|
86
|
-
await handleStats(subGetArg)
|
|
115
|
+
await handleStats(subGetArg, scoped)
|
|
87
116
|
return true
|
|
88
117
|
}
|
|
89
118
|
if (cmd === "sessions") {
|
|
@@ -145,7 +174,7 @@ export async function dispatch(
|
|
|
145
174
|
// Fase 5: server JSON-RPC stdio minimal untuk IDE (subset, bukan ACP penuh).
|
|
146
175
|
// Handler memblokir sampai stdin EOF/shutdown; tak ada sesi CLI yang dibuat.
|
|
147
176
|
const { handleAcp } = await import("./commands/acp.ts")
|
|
148
|
-
await handleAcp()
|
|
177
|
+
await handleAcp(scoped)
|
|
149
178
|
return true
|
|
150
179
|
}
|
|
151
180
|
if (cmd === "daemon") {
|