minicode-ai 0.27.0 → 0.30.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/README.md +1 -1
- package/cli/args.ts +184 -57
- package/cli/bootstrap/presentation-bridge.ts +383 -0
- package/cli/commands/acp.ts +45 -29
- 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 +18 -15
- package/cli/commands/exec.ts +41 -89
- 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 +51 -100
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +241 -485
- package/cli/tui.ts +303 -100
- package/docs/TERMINAL_CONTRACT.md +258 -73
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +17 -32
- 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 +144 -68
- package/src/app/tool-layer.ts +38 -16
- 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/atomic-write.ts +31 -59
- 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/jail.ts +6 -8
- 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/anthropic.ts +16 -5
- package/src/providers/provision.ts +6 -56
- package/src/providers/responses.ts +38 -7
- package/src/providers/sse-bounds.ts +6 -4
- 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/db/runs.ts +397 -0
- package/src/session/db/schema.ts +358 -0
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +74 -998
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/db/schema.ts +325 -0
- package/src/task/db/types.ts +269 -0
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +92 -1021
- 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 +158 -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 +35 -19
package/cli/commands/exec.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path"
|
|
2
|
+
import { expandMentions } from "../../src/app/mentions.ts"
|
|
2
3
|
import { NoProviderError } from "../../src/app/provider-layer.ts"
|
|
3
4
|
// F3.2 parity: exec ikut menghormati MINICODE_COMPACT_KEEP_TURNS, sama seperti
|
|
4
5
|
// jalur one-shot (cli/index.ts) — sebelumnya env ini hanya berlaku di REPL.
|
|
@@ -23,8 +24,10 @@ import {
|
|
|
23
24
|
displayWorkMode,
|
|
24
25
|
flagsAfterPromptBoundary,
|
|
25
26
|
hasFlag,
|
|
27
|
+
parseRuntimeNumericFlags,
|
|
26
28
|
promptFromArgs,
|
|
27
29
|
getArg as rawGetArg,
|
|
30
|
+
resolveToolScope,
|
|
28
31
|
resolveWorkModeFlag,
|
|
29
32
|
} from "../args.ts"
|
|
30
33
|
import { createCliSession } from "../setup.ts"
|
|
@@ -34,6 +37,14 @@ function writeMachineLine(line: string): void {
|
|
|
34
37
|
process.stdout.write(`${cleanUntrusted(scrubSecrets(line), false)}\n`)
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
const warnStderr = (msg: string): void => {
|
|
41
|
+
process.stderr.write(msg)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const EXEC_HELP = `minicode exec — headless one-shot execution (JSONL/linear)
|
|
45
|
+
|
|
46
|
+
minicode exec [--json] [--work-mode DISCUSS|BUILD] [--cwd <dir>] [--model <m>] [--sandbox docker|os] "prompt"`
|
|
47
|
+
|
|
37
48
|
/** Prompt lanjutan (Phase D auto-continue): minta model menyelesaikan sisa
|
|
38
49
|
* pekerjaan dari titik berhenti, memanfaatkan progres parsial yang sudah
|
|
39
50
|
* durable (safeTurnBoundary + persist). */
|
|
@@ -51,24 +62,18 @@ function machineFailure(prompt: string, e: unknown): Record<string, unknown> {
|
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
export async function handleExec(
|
|
54
|
-
// P11.2 —
|
|
55
|
-
// flag global yang dikenal (sebelum subcommand) + semua token sesudahnya.
|
|
56
|
-
// Irisan lokal `args[0] === "exec"` lama hanya benar bila exec token
|
|
57
|
-
// pertama; dengan flag global mendahului ("--json exec ..."), token
|
|
58
|
-
// routing bocor ke prompt + summary mesin. Handler mempercayai argv yang
|
|
59
|
-
// sudah scoped — jangan iris lagi di sini.
|
|
65
|
+
// P11.2 — argv scoped tanpa token subcommand ("exec").
|
|
60
66
|
subArgs: string[],
|
|
61
67
|
getArg: (name: string) => string | undefined,
|
|
62
68
|
): Promise<never> {
|
|
69
|
+
if (hasFlag(subArgs, "--help") || hasFlag(subArgs, "-h")) {
|
|
70
|
+
console.log(EXEC_HELP)
|
|
71
|
+
process.exit(0)
|
|
72
|
+
}
|
|
63
73
|
// Bersihkan state submit_result dari run sebelumnya — tanpa ini, exec
|
|
64
74
|
// berturut-turut dalam proses sama bisa membaca hasil run lama.
|
|
65
75
|
clearSubmittedResult()
|
|
66
|
-
// Prompt diambil lewat promptFromArgs() —
|
|
67
|
-
// jalur non-exec. Versi sebelumnya menyaring dengan `a !== getArg("--model")`,
|
|
68
|
-
// yang hanya membuang NILAI dari dua flag (`--model`, `--cwd`); nilai flag lain
|
|
69
|
-
// ikut masuk ke prompt. `exec "tes" --provider gorouter --timeout 60000` benar-
|
|
70
|
-
// benar mengirim "tes gorouter 60000" ke model, dan model membalas dengan
|
|
71
|
-
// menebak-nebak soal "gorouter" dan "60000".
|
|
76
|
+
// Prompt diambil lewat promptFromArgs() — selaras dengan jalur non-exec.
|
|
72
77
|
const prompt = promptFromArgs(subArgs) || (rawGetArg(subArgs, "--prompt") ?? "")
|
|
73
78
|
const jsonMode = hasFlag(subArgs, "--json") || rawGetArg(subArgs, "--output-format") === "json"
|
|
74
79
|
const cwdRaw = getArg("--cwd")
|
|
@@ -77,9 +82,8 @@ export async function handleExec(
|
|
|
77
82
|
const providerOverride = getArg("--provider")
|
|
78
83
|
// P2.1: flag mentah; identitas kanonik diputus di resolver (satu sanitizer).
|
|
79
84
|
const sessionFlag = getArg("--session") ?? ""
|
|
80
|
-
const allowAll = hasFlag(subArgs, "--allow-all")
|
|
85
|
+
const allowAll = hasFlag(subArgs, "--allow-all") || hasFlag(subArgs, "-y")
|
|
81
86
|
const ask = hasFlag(subArgs, "--ask")
|
|
82
|
-
const plan = hasFlag(subArgs, "--plan")
|
|
83
87
|
const allowlistFlag = hasFlag(subArgs, "--allowlist")
|
|
84
88
|
// Sama seperti jalur interaktif: OS sandbox otomatis, dan tanpa isolasi nyata
|
|
85
89
|
// permission default turun ke allowlist. Headless CI justru paling butuh ini —
|
|
@@ -94,7 +98,7 @@ export async function handleExec(
|
|
|
94
98
|
writeMachineLine(JSON.stringify(machineFailure(prompt.trim(), new Error(sandboxRefusal))))
|
|
95
99
|
process.exit(1)
|
|
96
100
|
}
|
|
97
|
-
const sandbox = resolveSandbox(requestedSandbox, allowAll || ask ||
|
|
101
|
+
const sandbox = resolveSandbox(requestedSandbox, allowAll || ask || allowlistFlag)
|
|
98
102
|
if (sandbox.mode === "none") delete process.env.MINICODE_SANDBOX
|
|
99
103
|
else process.env.MINICODE_SANDBOX = sandbox.mode
|
|
100
104
|
const allowlist = allowlistFlag || sandbox.fallbackPermission === "allowlist"
|
|
@@ -103,30 +107,17 @@ export async function handleExec(
|
|
|
103
107
|
console.error(
|
|
104
108
|
`[deprecated] --allow-all is a privileged access profile (hard jail/guard still apply); treat it as an explicit override, not ordinary AUTO`,
|
|
105
109
|
)
|
|
106
|
-
if (
|
|
110
|
+
if (allowlistFlag)
|
|
107
111
|
console.error(
|
|
108
112
|
`[deprecated] --allowlist is a bash/tool access policy; persistent grants remain in ~/.minicode/allowlist.json`,
|
|
109
113
|
)
|
|
110
114
|
// Audit #07 P0: local config repo tak dipercaya kecuali operator opt-in.
|
|
111
115
|
const allowLocal = allowLocalConfig(subArgs)
|
|
112
|
-
const budgetRaw = getArg("--budget")
|
|
113
|
-
let budget = budgetRaw ? Number(budgetRaw) : undefined
|
|
114
|
-
// [Audit #2 A.1/B.4] Selaras dengan cli/index.ts: --budget non-angka/negatif
|
|
115
|
-
// diingatkan eksplisit, bukan dibiarkan berubah jadi undefined secara diam.
|
|
116
|
-
if (budgetRaw && (!Number.isFinite(budget) || (budget as number) < 0)) {
|
|
117
|
-
process.stderr.write(`[warn] --budget requires a USD number, ignoring "${budgetRaw}"\n`)
|
|
118
|
-
budget = undefined
|
|
119
|
-
}
|
|
120
116
|
// Harness-P1: sama seperti one-shot — strict fail-closed bila cost tak dikenal.
|
|
121
117
|
const budgetStrict =
|
|
122
118
|
hasFlag(subArgs, "--budget-strict") || process.env.MINICODE_BUDGET_STRICT === "1"
|
|
123
119
|
// Harness-P2: scope tool sesi.
|
|
124
|
-
const
|
|
125
|
-
getArg("--tool-scope") ??
|
|
126
|
-
process.env.MINICODE_TOOL_SCOPE ??
|
|
127
|
-
""
|
|
128
|
-
).toLowerCase()
|
|
129
|
-
const toolScope = toolScopeRaw === "explore" ? ("explore" as const) : ("full" as const)
|
|
120
|
+
const toolScope = resolveToolScope(getArg)
|
|
130
121
|
// WorkMode (flag > env, default DISCUSS; invalid → DISCUSS + warning).
|
|
131
122
|
const workModeResolved = resolveWorkModeFlag(getArg)
|
|
132
123
|
const workMode = workModeResolved.workMode
|
|
@@ -137,63 +128,21 @@ export async function handleExec(
|
|
|
137
128
|
// (summary.workMode) — bukan teks dekoratif. BUILD = mode yang mengizinkan tulis.
|
|
138
129
|
if (!jsonMode && (workMode !== "EXECUTE" || workModeResolved.explicit)) {
|
|
139
130
|
const modeLabel = displayWorkMode(workMode)
|
|
140
|
-
const modeNote =
|
|
141
|
-
|
|
142
|
-
process.stderr.write(`[work-mode] ${modeLabel}${modeNote}\n`)
|
|
143
|
-
}
|
|
144
|
-
const ratelimitRaw = getArg("--ratelimit")
|
|
145
|
-
let rateLimiter: ReturnType<typeof createRateLimiter> | undefined
|
|
146
|
-
if (ratelimitRaw) {
|
|
147
|
-
const rpm = Number(ratelimitRaw)
|
|
148
|
-
if (!Number.isFinite(rpm) || rpm <= 0) {
|
|
149
|
-
process.stderr.write(
|
|
150
|
-
`[warn] --ratelimit requires a positive number, ignoring "${ratelimitRaw}"\n`,
|
|
151
|
-
)
|
|
152
|
-
} else {
|
|
153
|
-
rateLimiter = createRateLimiter(rpm)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Live Hardening 0.13.x — parity flag runtime dengan jalur one-shot
|
|
158
|
-
// (cli/index.ts): --max-steps, --context-window, --timeout, dan env
|
|
159
|
-
// MINICODE_COMPACT_KEEP_TURNS kini diteruskan ke sesi. Sebelumnya exec
|
|
160
|
-
// menyaring nilai flag ini dari prompt tetapi tidak pernah menerapkannya —
|
|
161
|
-
// operator mengira batas aktif padahal sesi berjalan dengan default kernel
|
|
162
|
-
// (silently ignored). Parsing + warn tiruan persis jalur one-shot.
|
|
163
|
-
const maxStepsRaw = getArg("--max-steps")
|
|
164
|
-
let maxSteps = maxStepsRaw ? Number(maxStepsRaw) : undefined
|
|
165
|
-
if (maxStepsRaw && (!Number.isFinite(maxSteps) || (maxSteps as number) <= 0)) {
|
|
166
|
-
process.stderr.write(
|
|
167
|
-
`[warn] --max-steps requires a positive number, ignoring "${maxStepsRaw}"\n`,
|
|
168
|
-
)
|
|
169
|
-
maxSteps = undefined
|
|
170
|
-
}
|
|
171
|
-
const ctxWindowRaw = getArg("--context-window")
|
|
172
|
-
let contextWindowTokens = ctxWindowRaw ? Number(ctxWindowRaw) : undefined
|
|
173
|
-
if (
|
|
174
|
-
ctxWindowRaw &&
|
|
175
|
-
(!Number.isFinite(contextWindowTokens) || (contextWindowTokens as number) <= 0)
|
|
176
|
-
) {
|
|
177
|
-
process.stderr.write(
|
|
178
|
-
`[warn] --context-window requires a positive number, ignoring "${ctxWindowRaw}"\n`,
|
|
179
|
-
)
|
|
180
|
-
contextWindowTokens = undefined
|
|
131
|
+
const modeNote = workMode === "DISCUSS" ? " (read-only)" : ""
|
|
132
|
+
warnStderr(`[work-mode] ${modeLabel}${modeNote}\n`)
|
|
181
133
|
}
|
|
134
|
+
const parsedNums = parseRuntimeNumericFlags(getArg, warnStderr)
|
|
135
|
+
const { maxSteps, contextWindowTokens, budget } = parsedNums
|
|
136
|
+
const rateLimiter =
|
|
137
|
+
parsedNums.ratelimitRpm !== undefined ? createRateLimiter(parsedNums.ratelimitRpm) : undefined
|
|
182
138
|
const keepTurnsRaw = (process.env.MINICODE_COMPACT_KEEP_TURNS ?? "").trim()
|
|
183
139
|
const keepRecentTurns = parseCompactKeepTurns(keepTurnsRaw || undefined)
|
|
184
140
|
if (keepTurnsRaw && keepRecentTurns === undefined)
|
|
185
|
-
|
|
141
|
+
warnStderr(
|
|
186
142
|
`[warn] MINICODE_COMPACT_KEEP_TURNS requires an integer >= 1, ignoring "${keepTurnsRaw}"\n`,
|
|
187
143
|
)
|
|
188
|
-
const timeoutRaw = getArg("--timeout")
|
|
189
144
|
// exec (one-shot/CI) default 15 menit — lebih konservatif dari interaktif (1 jam).
|
|
190
|
-
|
|
191
|
-
if (timeoutRaw && (!Number.isFinite(timeoutMs) || (timeoutMs as number) < 0)) {
|
|
192
|
-
process.stderr.write(
|
|
193
|
-
`[warn] --timeout requires a non-negative number, ignoring "${timeoutRaw}"\n`,
|
|
194
|
-
)
|
|
195
|
-
timeoutMs = 900_000
|
|
196
|
-
}
|
|
145
|
+
const timeoutMs = parsedNums.timeoutMs ?? 900_000
|
|
197
146
|
// Phase D — auto-continue (opt-in): pecah tugas panjang menjadi beberapa turn
|
|
198
147
|
// bounded. Saat turn berakhir dengan max_steps_exceeded, kernel SUDAH
|
|
199
148
|
// meng-commit progres parsial (safeTurnBoundary); run lanjutan melanjutkan dari
|
|
@@ -209,7 +158,7 @@ export async function handleExec(
|
|
|
209
158
|
|
|
210
159
|
const ignoredFlags = flagsAfterPromptBoundary(subArgs)
|
|
211
160
|
if (ignoredFlags.length > 0) {
|
|
212
|
-
|
|
161
|
+
warnStderr(
|
|
213
162
|
`[warn] ignored flag(s) after the prompt: ${ignoredFlags.join(", ")} — put flags before the prompt (e.g. minicode exec ${ignoredFlags.join(" ")} "your prompt")\n`,
|
|
214
163
|
)
|
|
215
164
|
}
|
|
@@ -217,7 +166,7 @@ export async function handleExec(
|
|
|
217
166
|
const effectivePrompt = prompt.trim()
|
|
218
167
|
if (!effectivePrompt) {
|
|
219
168
|
console.error(
|
|
220
|
-
'usage: minicode exec [--json] [--work-mode DISCUSS|
|
|
169
|
+
'usage: minicode exec [--json] [--work-mode DISCUSS|BUILD] [--cwd <dir>] [--model <m>] [--sandbox docker|os] "prompt"',
|
|
221
170
|
)
|
|
222
171
|
if (jsonMode)
|
|
223
172
|
writeMachineLine(
|
|
@@ -241,7 +190,6 @@ export async function handleExec(
|
|
|
241
190
|
verbose: false,
|
|
242
191
|
allowAll,
|
|
243
192
|
ask,
|
|
244
|
-
plan,
|
|
245
193
|
allowlist,
|
|
246
194
|
verify: hasFlag(subArgs, "--verify"),
|
|
247
195
|
// [P1 M15] Mode runtime produksi, deterministik per invokasi (sama seperti
|
|
@@ -316,6 +264,9 @@ export async function handleExec(
|
|
|
316
264
|
)
|
|
317
265
|
})
|
|
318
266
|
try {
|
|
267
|
+
const runPrompt = effectivePrompt.includes("@")
|
|
268
|
+
? (await expandMentions(effectivePrompt, cwd ?? process.cwd())).prompt
|
|
269
|
+
: effectivePrompt
|
|
319
270
|
if (autoContinue) {
|
|
320
271
|
// Lanjutkan sampai selesai / cap tercapai. `isStepLimit` memisahkan
|
|
321
272
|
// "habis langkah" (layak dilanjut) dari error lain (auth/network/dll yang
|
|
@@ -327,7 +278,7 @@ export async function handleExec(
|
|
|
327
278
|
for (let i = 0; i <= autoContinueBudget; i++) {
|
|
328
279
|
let err: unknown = null
|
|
329
280
|
try {
|
|
330
|
-
await ctx.runPromptWithVerify(i === 0 ?
|
|
281
|
+
await ctx.runPromptWithVerify(i === 0 ? runPrompt : CONTINUE_PROMPT)
|
|
331
282
|
} catch (e) {
|
|
332
283
|
err = e
|
|
333
284
|
}
|
|
@@ -338,7 +289,7 @@ export async function handleExec(
|
|
|
338
289
|
)
|
|
339
290
|
}
|
|
340
291
|
} else {
|
|
341
|
-
await ctx.runPromptWithVerify(
|
|
292
|
+
await ctx.runPromptWithVerify(runPrompt)
|
|
342
293
|
}
|
|
343
294
|
// Harness-P1: exec sebelumnya mengabaikan --budget total (flag diteruskan
|
|
344
295
|
// tapi tak pernah diperiksa). Samakan dengan one-shot: over → exit 1.
|
|
@@ -351,7 +302,7 @@ export async function handleExec(
|
|
|
351
302
|
: `[budget] cost unknown (model without pricing) with ${ue.totalTokens} tokens spent - over budget, stopping.`
|
|
352
303
|
unsubMachine()
|
|
353
304
|
unsubText()
|
|
354
|
-
await ctx.persistCurrent(ctx.usage.
|
|
305
|
+
await ctx.persistCurrent(ctx.usage.get(ctx.modelRef.current))
|
|
355
306
|
await ctx.close()
|
|
356
307
|
if (jsonMode)
|
|
357
308
|
writeMachineLine(JSON.stringify(machineFailure(effectivePrompt, new Error(msg))))
|
|
@@ -360,7 +311,7 @@ export async function handleExec(
|
|
|
360
311
|
}
|
|
361
312
|
unsubMachine()
|
|
362
313
|
unsubText()
|
|
363
|
-
await ctx.persistCurrent(
|
|
314
|
+
await ctx.persistCurrent(ctx.usage.get(ctx.modelRef.current))
|
|
364
315
|
// P2.2: histori yang tak durable = kegagalan jujur (bukan exit 0). Diperiksa
|
|
365
316
|
// SEBELUM menulis machineSummary(true) agar stdout JSONL tidak pernah
|
|
366
317
|
// memancarkan dua summary terminal yang saling bertentangan (ok:true lalu ok:false).
|
|
@@ -377,7 +328,8 @@ export async function handleExec(
|
|
|
377
328
|
if (jsonMode) {
|
|
378
329
|
// submit_result dari model (bila dipanggil) ikut verbatim — pipeline CI
|
|
379
330
|
// tak perlu menebak batas JSON dari prosa turn terakhir.
|
|
380
|
-
const submitted = getSubmittedResult()
|
|
331
|
+
const submitted = getSubmittedResult(ctx.sessionId)
|
|
332
|
+
clearSubmittedResult(ctx.sessionId)
|
|
381
333
|
// P11.1 — hasil verify TERAKHIR (final pasca-self-heal) untuk summary.
|
|
382
334
|
// Aditif & absen bila verify tak jalan: cermin lastVerify sesi, bukan
|
|
383
335
|
// otoritas baru. ok top-level dan exit code SENGAJA tak berubah.
|
|
@@ -429,7 +381,7 @@ export async function handleExec(
|
|
|
429
381
|
unsubMachine()
|
|
430
382
|
unsubText()
|
|
431
383
|
try {
|
|
432
|
-
await ctx.persistCurrent(ctx.usage.
|
|
384
|
+
await ctx.persistCurrent(ctx.usage.get(ctx.modelRef.current))
|
|
433
385
|
} catch {}
|
|
434
386
|
await ctx.close()
|
|
435
387
|
process.exit(1)
|
package/cli/commands/mcp.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path"
|
|
2
2
|
import { configureMcpSchemaPins, mcpSchemaPinRegistry } from "../../src/mcp/client.ts"
|
|
3
|
+
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
4
|
+
import { guardSubcommand, positionalSubArg } from "../args.ts"
|
|
3
5
|
|
|
4
6
|
const MCP_HELP = `minicode mcp — run minicode as an MCP server / inspect schema pins
|
|
5
7
|
|
|
@@ -27,8 +29,14 @@ export async function handleMcp(
|
|
|
27
29
|
getArg: (name: string) => string | undefined,
|
|
28
30
|
_help: string,
|
|
29
31
|
): Promise<never> {
|
|
30
|
-
|
|
32
|
+
guardSubcommand(args, "mcp", MCP_HELP, out, err, -1)
|
|
33
|
+
const sub = positionalSubArg(args, 1)
|
|
31
34
|
const cwdArg = getArg("--cwd")
|
|
35
|
+
const extra = positionalSubArg(args, 2)
|
|
36
|
+
if (extra && (sub === "serve" || sub === "pins" || sub === "capabilities")) {
|
|
37
|
+
err(`unknown mcp ${sub} argument: ${sanitizeAnsiLine(extra)}\n${MCP_HELP}`)
|
|
38
|
+
process.exit(2)
|
|
39
|
+
}
|
|
32
40
|
if (sub === "serve") {
|
|
33
41
|
const { serveMcp } = await import("../../src/mcp/server.ts")
|
|
34
42
|
await serveMcp({
|
|
@@ -47,7 +55,9 @@ export async function handleMcp(
|
|
|
47
55
|
} else if (pins.length === 0) {
|
|
48
56
|
out("no MCP schema pins recorded for this workspace")
|
|
49
57
|
} else {
|
|
50
|
-
for (const p of pins)
|
|
58
|
+
for (const p of pins) {
|
|
59
|
+
out(`${sanitizeAnsiLine(p.serverId)}.${sanitizeAnsiLine(p.toolName)} ${p.hash}`)
|
|
60
|
+
}
|
|
51
61
|
}
|
|
52
62
|
process.exit(0)
|
|
53
63
|
}
|
|
@@ -73,9 +83,14 @@ export async function handleMcp(
|
|
|
73
83
|
process.exit(0)
|
|
74
84
|
}
|
|
75
85
|
if (sub === "approve") {
|
|
76
|
-
const target =
|
|
77
|
-
const hash = args
|
|
78
|
-
if (
|
|
86
|
+
const target = extra
|
|
87
|
+
const hash = positionalSubArg(args, 3) ?? getArg("--hash")
|
|
88
|
+
if (
|
|
89
|
+
!target?.includes(".") ||
|
|
90
|
+
!hash ||
|
|
91
|
+
!/^[0-9a-f]{64}$/i.test(hash) ||
|
|
92
|
+
positionalSubArg(args, 4)
|
|
93
|
+
) {
|
|
79
94
|
err("usage: minicode mcp approve <server>.<tool> <64-hex-sha256> [--cwd <dir>]")
|
|
80
95
|
process.exit(2)
|
|
81
96
|
}
|
|
@@ -85,13 +100,15 @@ export async function handleMcp(
|
|
|
85
100
|
const cwd = cwdArg ? resolvePath(cwdArg) : undefined
|
|
86
101
|
configureMcpSchemaPins(cwd)
|
|
87
102
|
mcpSchemaPinRegistry.approveMcpSchemaUpdate(serverId, toolName, hash.toLowerCase())
|
|
88
|
-
out(
|
|
103
|
+
out(
|
|
104
|
+
`approved ${sanitizeAnsiLine(serverId)}.${sanitizeAnsiLine(toolName)} -> ${hash.toLowerCase()}`,
|
|
105
|
+
)
|
|
89
106
|
process.exit(0)
|
|
90
107
|
}
|
|
91
108
|
// Help kontekstual, bukan HELP global 45 baris. Subcommand asing = salah
|
|
92
109
|
// pakai (exit 2), bukan gagal runtime (exit 1).
|
|
93
|
-
const asking = sub === undefined
|
|
94
|
-
if (
|
|
110
|
+
const asking = sub === undefined
|
|
111
|
+
if (sub !== undefined) err(`unknown mcp subcommand: ${sanitizeAnsiLine(sub)}\n`)
|
|
95
112
|
out(MCP_HELP)
|
|
96
113
|
process.exit(asking ? 0 : 2)
|
|
97
114
|
}
|
package/cli/commands/memory.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs"
|
|
2
|
-
import { resolve } from "node:path"
|
|
3
1
|
import { getMemoryStats, reconcileMemoryStores } from "../../src/memory/vector.ts"
|
|
2
|
+
import { readTraceRows } from "../../src/telemetry/trace.ts"
|
|
3
|
+
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
4
4
|
import { c } from "../../src/ui/render/theme.ts"
|
|
5
|
+
import { guardSubcommand, positionalSubArg } from "../args.ts"
|
|
5
6
|
|
|
6
7
|
const MEMORY_HELP = `minicode memory — vector RAG store stats
|
|
7
8
|
|
|
@@ -31,20 +32,12 @@ function fmtDate(ts: number | null): string {
|
|
|
31
32
|
function readHitRate(cwd?: string): { runs: number; avgHits: number } {
|
|
32
33
|
let runs = 0
|
|
33
34
|
let total = 0
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
for (const l of lines) {
|
|
39
|
-
try {
|
|
40
|
-
const t = JSON.parse(l) as MemoryTraceRow
|
|
41
|
-
if (typeof t.memoryHits === "number") {
|
|
42
|
-
runs++
|
|
43
|
-
total += t.memoryHits
|
|
44
|
-
}
|
|
45
|
-
} catch {}
|
|
35
|
+
for (const t of readTraceRows<MemoryTraceRow>(cwd, "traces.jsonl")) {
|
|
36
|
+
if (typeof t.memoryHits === "number") {
|
|
37
|
+
runs++
|
|
38
|
+
total += t.memoryHits
|
|
46
39
|
}
|
|
47
|
-
}
|
|
40
|
+
}
|
|
48
41
|
return { runs, avgHits: runs ? total / runs : 0 }
|
|
49
42
|
}
|
|
50
43
|
|
|
@@ -54,11 +47,8 @@ export async function handleMemory(
|
|
|
54
47
|
): Promise<never> {
|
|
55
48
|
// Satu saluran stderr bersama (dihitung inventaris writer sebagai satu site).
|
|
56
49
|
const err = (msg: string): void => console.error(msg)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.log(MEMORY_HELP)
|
|
60
|
-
process.exit(0)
|
|
61
|
-
}
|
|
50
|
+
guardSubcommand(args, "memory", MEMORY_HELP, console.log, err, -1)
|
|
51
|
+
const sub = positionalSubArg(args, 1)
|
|
62
52
|
// [PROMPT 06 · Area E / D4] `reconcileMemoryStores` sebelumnya TIDAK punya
|
|
63
53
|
// call site produksi sama sekali: pesan `write_memory` menyuruh user
|
|
64
54
|
// menjalankan `minicode memory reconcile` padahal subcommand itu tak ada —
|
|
@@ -83,8 +73,8 @@ export async function handleMemory(
|
|
|
83
73
|
process.exit(1)
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
|
-
if (sub && sub !== "status"
|
|
87
|
-
err(`unknown memory subcommand "${sub}" — see: minicode memory status`)
|
|
76
|
+
if (sub && sub !== "status") {
|
|
77
|
+
err(`unknown memory subcommand "${sanitizeAnsiLine(sub)}" — see: minicode memory status`)
|
|
88
78
|
process.exit(2)
|
|
89
79
|
}
|
|
90
80
|
const cwdArg = getArg("--cwd")
|
|
@@ -120,12 +110,14 @@ export async function handleMemory(
|
|
|
120
110
|
`(db ${fmtBytes(s.dbBytes)} ${dot} wal ${fmtBytes(s.walBytes)} ${dot} shm ${fmtBytes(s.shmBytes)})`,
|
|
121
111
|
]
|
|
122
112
|
if (s.models.length)
|
|
123
|
-
lines.push(
|
|
113
|
+
lines.push(
|
|
114
|
+
` models: ${s.models.map((m) => `${sanitizeAnsiLine(m.model)}×${m.count}`).join(", ")}`,
|
|
115
|
+
)
|
|
124
116
|
if (s.dims.length)
|
|
125
117
|
lines.push(` dims: ${s.dims.map((d) => `${d.dim || "none"}×${d.count}`).join(", ")}`)
|
|
126
118
|
if (s.categories.length)
|
|
127
119
|
lines.push(
|
|
128
|
-
` categories: ${s.categories.map((m) => `${m.category}×${m.count}`).join(", ")} (scope: ${scope})`,
|
|
120
|
+
` categories: ${s.categories.map((m) => `${sanitizeAnsiLine(m.category)}×${m.count}`).join(", ")} (scope: ${sanitizeAnsiLine(scope)})`,
|
|
129
121
|
)
|
|
130
122
|
lines.push(` range: ${fmtDate(s.oldest)} → ${fmtDate(s.newest)}`)
|
|
131
123
|
lines.push(
|
package/cli/commands/openwork.ts
CHANGED
|
@@ -423,7 +423,7 @@ function handleList(getArg: (name: string) => string | undefined): never {
|
|
|
423
423
|
process.exit(0)
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
function handleMerge(getArg: (name: string) => string | undefined): never {
|
|
426
|
+
async function handleMerge(getArg: (name: string) => string | undefined): Promise<never> {
|
|
427
427
|
const cwd = getArg("--cwd") ?? process.cwd()
|
|
428
428
|
const asJson = getArg("--json") !== undefined || process.argv.includes("--json")
|
|
429
429
|
const sessionId = getArg("--session")
|
|
@@ -473,6 +473,10 @@ function handleMerge(getArg: (name: string) => string | undefined): never {
|
|
|
473
473
|
exit1(sanitizeAnsi(`[openwork] merge refused: ${result.outcome} — ${result.detail}`))
|
|
474
474
|
}
|
|
475
475
|
|
|
476
|
+
// Sinkronkan view turunan todos/*.json & plans/*.md pasca merge/cancel duplikat.
|
|
477
|
+
const { syncTodoViewsFromTaskStore } = await import("../../src/tools/todo.ts")
|
|
478
|
+
await syncTodoViewsFromTaskStore(sessionId, cwd).catch(() => undefined)
|
|
479
|
+
|
|
476
480
|
if (asJson) {
|
|
477
481
|
emitJson(result)
|
|
478
482
|
process.exit(0)
|
|
@@ -968,7 +972,7 @@ export async function handleOpenwork(
|
|
|
968
972
|
}
|
|
969
973
|
const sub = actionAfter(args)
|
|
970
974
|
if (sub === "merge") {
|
|
971
|
-
handleMerge(getArg)
|
|
975
|
+
return await handleMerge(getArg)
|
|
972
976
|
}
|
|
973
977
|
if (sub === "inventory") {
|
|
974
978
|
handleInventory(getArg)
|
package/cli/commands/pricing.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
pricingOverlayMeta,
|
|
8
8
|
syncPricing,
|
|
9
9
|
} from "../../src/policy/pricing.ts"
|
|
10
|
-
import {
|
|
10
|
+
import { formatError } from "../../src/ui/render/errors.ts"
|
|
11
|
+
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
12
|
+
import { c } from "../../src/ui/render/theme.ts"
|
|
13
|
+
import { hasHelpFlag, positionalSubArg } from "../args.ts"
|
|
11
14
|
|
|
12
15
|
const PRICING_HELP = `minicode pricing — price table for cost estimation
|
|
13
16
|
|
|
@@ -17,23 +20,22 @@ const PRICING_HELP = `minicode pricing — price table for cost estimation
|
|
|
17
20
|
minicode pricing clear clear cache and use built-in data`
|
|
18
21
|
|
|
19
22
|
export async function handlePricing(args: string[]): Promise<never> {
|
|
20
|
-
|
|
21
|
-
if (raw === "--help" || raw === "-h") {
|
|
23
|
+
if (hasHelpFlag(args)) {
|
|
22
24
|
console.log(PRICING_HELP)
|
|
23
25
|
process.exit(0)
|
|
24
26
|
}
|
|
25
|
-
const sub = (
|
|
27
|
+
const sub = (positionalSubArg(args, 1) ?? "status").toLowerCase()
|
|
26
28
|
|
|
27
29
|
if (sub === "sync") {
|
|
28
30
|
process.stderr.write("fetching prices from models.dev…\n")
|
|
29
31
|
try {
|
|
30
32
|
const res = await syncPricing()
|
|
31
33
|
console.log(
|
|
32
|
-
`${c.green(
|
|
34
|
+
`${c.green("ok")} saved ${res.count} models (${Math.round(res.bytes / 1024)} KB)\n ${c.dim(res.path)}`,
|
|
33
35
|
)
|
|
34
36
|
process.exit(0)
|
|
35
37
|
} catch (e) {
|
|
36
|
-
console.error(
|
|
38
|
+
console.error(c.red(`failed: ${formatError(e)}`))
|
|
37
39
|
console.error(c.dim(" built-in price table is still used — nothing is broken"))
|
|
38
40
|
process.exit(1)
|
|
39
41
|
}
|
|
@@ -60,20 +62,20 @@ export async function handlePricing(args: string[]): Promise<never> {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
if (sub === "show") {
|
|
63
|
-
|
|
64
|
-
const model = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
|
|
65
|
+
const model = positionalSubArg(args, 2)
|
|
65
66
|
if (!model) {
|
|
66
67
|
console.error("usage: minicode pricing show <model>")
|
|
67
68
|
process.exit(2)
|
|
68
69
|
}
|
|
69
70
|
const overlay = await loadPricingOverlay()
|
|
70
71
|
const p = findPrice(model, overlay)
|
|
72
|
+
const safeModel = sanitizeAnsiLine(model)
|
|
71
73
|
if (!p) {
|
|
72
|
-
console.log(`(price for "${
|
|
74
|
+
console.log(`(price for "${safeModel}" is unknown — cost will show N/A)`)
|
|
73
75
|
process.exit(0)
|
|
74
76
|
}
|
|
75
77
|
const src = findPrice(model, {}) === p ? "built-in" : "models.dev"
|
|
76
|
-
console.log(`\n${c.bold(
|
|
78
|
+
console.log(`\n${c.bold(safeModel)} ${c.dim(`(${src})`)}`)
|
|
77
79
|
console.log(` input $${p.input}/M token`)
|
|
78
80
|
console.log(` output $${p.output}/M token`)
|
|
79
81
|
if (p.cacheRead != null) console.log(` cache read $${p.cacheRead}/M`)
|
|
@@ -87,7 +89,7 @@ export async function handlePricing(args: string[]): Promise<never> {
|
|
|
87
89
|
await readFile(pricingCachePath(), "utf8")
|
|
88
90
|
const { rm } = await import("node:fs/promises")
|
|
89
91
|
await rm(pricingCachePath(), { force: true })
|
|
90
|
-
console.log(`${c.green(
|
|
92
|
+
console.log(`${c.green("ok")} pricing cache cleared`)
|
|
91
93
|
} catch {
|
|
92
94
|
console.log("(no pricing cache)")
|
|
93
95
|
}
|
|
@@ -96,7 +98,7 @@ export async function handlePricing(args: string[]): Promise<never> {
|
|
|
96
98
|
|
|
97
99
|
// Subcommand asing = salah pakai: exit 2 supaya skrip bisa mendeteksinya
|
|
98
100
|
// dan membedakannya dari gagal runtime (exit 1).
|
|
99
|
-
console.error(`unknown pricing subcommand: ${sub}\n`)
|
|
101
|
+
console.error(`unknown pricing subcommand: ${sanitizeAnsiLine(sub)}\n`)
|
|
100
102
|
console.log(PRICING_HELP)
|
|
101
103
|
process.exit(2)
|
|
102
104
|
}
|