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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Eksekusi `/context`: baca config, resolve jendela efektif, dan (bila diminta)
|
|
2
|
+
// tulis penugasan manual.
|
|
3
|
+
//
|
|
4
|
+
// Dipisah dari `cli/commands.ts` karena butuh `loadConfig` + picker + penulisan
|
|
5
|
+
// config — sementara `commands.ts` memanggilnya lewat `import()` dinamis supaya
|
|
6
|
+
// jalur satu-shot (yang tak pernah membuka `/context`) tidak membayar biaya
|
|
7
|
+
// modul ini. Alasan yang sama dipakai `/model` (`./model-manager.ts`).
|
|
8
|
+
|
|
9
|
+
import type { MinicodeConfig, ProviderEntry } from "../src/config.ts"
|
|
10
|
+
import { hasProviderInLocalConfig, loadConfig } from "../src/config.ts"
|
|
11
|
+
import { resolveContextWindow } from "../src/policy/context-window.ts"
|
|
12
|
+
import { assignContextWindow } from "../src/policy/context-window-assign.ts"
|
|
13
|
+
import {
|
|
14
|
+
CONTEXT_WINDOW_AUTO,
|
|
15
|
+
describeContextWindow,
|
|
16
|
+
parseContextWindowInput,
|
|
17
|
+
} from "../src/policy/context-window-presets.ts"
|
|
18
|
+
import { t } from "../src/ui/i18n/locale.ts"
|
|
19
|
+
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
20
|
+
import { renderTable } from "../src/ui/render/table.ts"
|
|
21
|
+
import { outputWindowWidth } from "../src/ui/screens/output-window.ts"
|
|
22
|
+
import type { CommandContext } from "./commands.ts"
|
|
23
|
+
import {
|
|
24
|
+
contextWindowRow,
|
|
25
|
+
contextWindowSavedNotice,
|
|
26
|
+
contextWindowTableHeader,
|
|
27
|
+
} from "./context-command.ts"
|
|
28
|
+
|
|
29
|
+
/** Baris `provider::model` aktif, diturunkan dari id yang dipakai sesi. */
|
|
30
|
+
function activeRef(
|
|
31
|
+
ctx: CommandContext,
|
|
32
|
+
cfg?: MinicodeConfig,
|
|
33
|
+
): { provider: string; model: string } | undefined {
|
|
34
|
+
const id = ctx.currentModel
|
|
35
|
+
if (!id) return undefined
|
|
36
|
+
if (id.includes("::")) {
|
|
37
|
+
const sep = id.indexOf("::")
|
|
38
|
+
return { provider: id.slice(0, sep), model: id.slice(sep + 2) }
|
|
39
|
+
}
|
|
40
|
+
const owner = cfg?.providers.find((p) => p.models.includes(id))
|
|
41
|
+
return owner ? { provider: owner.id, model: id } : undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Cetak tabel jendela efektif untuk SEMUA model yang dikonfigurasi.
|
|
46
|
+
*
|
|
47
|
+
* Kenapa semua model, bukan hanya yang aktif: pertanyaan "berapa konteks saya"
|
|
48
|
+
* hampir selalu muncul saat memilih model, dan tabel satu baris memaksa buka
|
|
49
|
+
* `/context` berkali-kali. Baris aktif ditandai supaya mata langsung menemukan
|
|
50
|
+
* yang relevan.
|
|
51
|
+
*/
|
|
52
|
+
async function rowsFor(ctx: CommandContext): Promise<string[]> {
|
|
53
|
+
const cfg = await loadConfig(ctx.cwd, { allowLocal: ctx.allowLocalConfig })
|
|
54
|
+
const active = activeRef(ctx, cfg)
|
|
55
|
+
const rows: { model: string; window: string; origin: string }[] = []
|
|
56
|
+
for (const p of cfg.providers) {
|
|
57
|
+
for (const model of p.models ?? []) {
|
|
58
|
+
const res = resolveContextWindow(cfg, `${p.id}::${model}`)
|
|
59
|
+
const row = contextWindowRow(model, res, describeContextWindow)
|
|
60
|
+
// Angka jendela = data operasional, nama model = input tak terpercaya
|
|
61
|
+
// (bisa datang dari /models jaringan): sanitasi keduanya sebelum tampil.
|
|
62
|
+
rows.push({
|
|
63
|
+
model: `${sanitizeAnsiLine(`${p.id}::${model}`)}${active && active.provider === p.id && active.model === model ? " *" : ""}`,
|
|
64
|
+
window: sanitizeAnsiLine(row.window),
|
|
65
|
+
origin: sanitizeAnsiLine(row.origin),
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!rows.length) return [t("ctx.empty")]
|
|
70
|
+
const head = contextWindowTableHeader()
|
|
71
|
+
// Lebar kolom mengikuti inner width jendela output command agar tabel tidak
|
|
72
|
+
// ter-wrap/terpotong (terminal 80 → inner 68; terminal 60 → inner 52).
|
|
73
|
+
const inner = Math.max(20, outputWindowWidth(process.stdout.columns || 80) - 4)
|
|
74
|
+
const windowW = 9
|
|
75
|
+
const originW = Math.min(14, Math.max(10, Math.floor(inner * 0.18)))
|
|
76
|
+
const modelW = Math.max(18, Math.min(40, inner - windowW - originW - 10))
|
|
77
|
+
return [
|
|
78
|
+
"",
|
|
79
|
+
renderTable(
|
|
80
|
+
[
|
|
81
|
+
{ header: head.model, key: "model", width: modelW },
|
|
82
|
+
{ header: head.window, key: "window", width: windowW, align: "right" },
|
|
83
|
+
{ header: head.origin, key: "origin", width: originW },
|
|
84
|
+
],
|
|
85
|
+
rows,
|
|
86
|
+
),
|
|
87
|
+
` ${t("ctx.usage")}`,
|
|
88
|
+
"",
|
|
89
|
+
].flatMap((line) => line.split("\n"))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Tulis nilai manual untuk model aktif. Mengembalikan baris untuk dicetak.
|
|
94
|
+
*
|
|
95
|
+
* Nilai `auto` MENGHAPUS kunci (lihat `assignContextWindow`), bukan menyimpan
|
|
96
|
+
* penanda — sehingga perilaku kembali persis ke rantai resolusi normal.
|
|
97
|
+
*/
|
|
98
|
+
async function save(ctx: CommandContext, input: string): Promise<string[]> {
|
|
99
|
+
const cfg = await loadConfig(ctx.cwd, { allowLocal: ctx.allowLocalConfig })
|
|
100
|
+
const active = activeRef(ctx, cfg)
|
|
101
|
+
if (!active) return [`${t("ctx.saveFailed", { msg: "no active model — pick one with /model" })}`]
|
|
102
|
+
const provider = cfg.providers.find((p) => p.id === active.provider)
|
|
103
|
+
if (!provider) return [`${t("ctx.saveFailed", { msg: `provider ${active.provider} not found` })}`]
|
|
104
|
+
|
|
105
|
+
const outcome = assignContextWindow(provider as ProviderEntry, active.model, input)
|
|
106
|
+
if (!outcome.ok) return [`${t("ctx.saveFailed", { msg: outcome.error })}`]
|
|
107
|
+
|
|
108
|
+
// Sesi ini menyimpan snapshot config saat start; tanpa mendaftarkan nilai
|
|
109
|
+
// baru ke registry live, "saved" di layar tidak mengubah apa pun sampai
|
|
110
|
+
// restart. Daftarkan sebelum/bersamaan dengan tulis disk.
|
|
111
|
+
const { setLiveContextWindow, clearLiveContextWindow } = await import(
|
|
112
|
+
"../src/policy/context-window.ts"
|
|
113
|
+
)
|
|
114
|
+
if (outcome.tokens === null) clearLiveContextWindow(active.provider, active.model)
|
|
115
|
+
else setLiveContextWindow(active.provider, active.model, outcome.tokens)
|
|
116
|
+
|
|
117
|
+
const { saveProvider } = await import("../src/providers/provision.ts")
|
|
118
|
+
// Scope tulis = scope tempat provider itu benar-benar didefinisikan, BUKAN
|
|
119
|
+
// hasil merge. Menyimpan entri merge ke file global menduplikat provider ke
|
|
120
|
+
// scope lain, lalu merge memprioritaskan salinan itu sehingga editan di scope
|
|
121
|
+
// asal terlihat "balik lagi" (kelas yang sama dengan `cli/model-manager.ts`).
|
|
122
|
+
// Provider lokal hanya terbaca bila sesi mengizinkannya (`--allow-local-config`)
|
|
123
|
+
// — tanpa opt-in kita tak boleh menyentuh berkas repo.
|
|
124
|
+
const inLocal =
|
|
125
|
+
!!ctx.allowLocalConfig && (await hasProviderInLocalConfig(active.provider, ctx.cwd))
|
|
126
|
+
try {
|
|
127
|
+
await saveProvider(outcome.provider, {
|
|
128
|
+
...(inLocal ? { global: false, cwd: ctx.cwd ?? process.cwd() } : { global: true }),
|
|
129
|
+
})
|
|
130
|
+
} catch (e) {
|
|
131
|
+
return [t("ctx.saveFailed", { msg: sanitizeAnsiLine(String((e as Error)?.message ?? e)) })]
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
sanitizeAnsiLine(
|
|
135
|
+
contextWindowSavedNotice(outcome.tokens, describeContextWindow).replace(
|
|
136
|
+
"{model}",
|
|
137
|
+
`${active.provider}::${active.model}`,
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Baris yang dicetak sebagai satu blok — dirakit di sini, bukan di
|
|
144
|
+
* `cli/commands.ts`, supaya berkas itu tetap satu penulis untuk perintah ini
|
|
145
|
+
* (inventaris writer OAP-008 menghitung pemanggilan tulis per berkas). */
|
|
146
|
+
export function formatContextOutput(lines: string[]): string {
|
|
147
|
+
return lines.join("\n")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Entri tunggal `/context`: tanpa argumen = tabel, dengan argumen = setel. */
|
|
151
|
+
export async function applyContextWindowArg(args: string, ctx: CommandContext): Promise<string[]> {
|
|
152
|
+
const raw = args.trim()
|
|
153
|
+
if (!raw) {
|
|
154
|
+
// Tanpa argumen = HANYA membaca. Sengaja tanpa picker: membuka picker di
|
|
155
|
+
// sini berarti perintah menahan turn sampai pengguna memilih, sehingga
|
|
156
|
+
// `/context` yang diniatkan sebagai "lihat angka" malah mengunci TUI —
|
|
157
|
+
// kelas keluhan "macet" yang justru sedang kita bereskan. Mengubah nilai
|
|
158
|
+
// selalu eksplisit: `/context 200k`.
|
|
159
|
+
return rowsFor(ctx)
|
|
160
|
+
}
|
|
161
|
+
// `auto` diterima apa adanya; selain itu WAJIB terbaca sebagai angka/preset.
|
|
162
|
+
// Menolak tebakan di sini penting: salah ketik yang diterima diam-diam akan
|
|
163
|
+
// memotong konteks model tanpa gejala sampai kompaksi prematur muncul.
|
|
164
|
+
if (raw.toLowerCase() !== CONTEXT_WINDOW_AUTO && parseContextWindowInput(raw) === undefined)
|
|
165
|
+
return [
|
|
166
|
+
t("ctx.saveFailed", {
|
|
167
|
+
msg: `cannot read "${sanitizeAnsiLine(raw)}" as a window (try 128k, 1m, 1024x1024, auto)`,
|
|
168
|
+
}),
|
|
169
|
+
]
|
|
170
|
+
return save(ctx, raw)
|
|
171
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// `/context` — jendela konteks: LIHAT kapasitas efektif, lalu UBAH bila perlu.
|
|
2
|
+
//
|
|
3
|
+
// ── Kenapa perintah ini ada ────────────────────────────────────────────────
|
|
4
|
+
// Fitur jendela konteks manual sebelumnya hanya hidup di `minicode config
|
|
5
|
+
// context-window <provider> <model> <nilai>`: subcommand CLI yang tak muncul di
|
|
6
|
+
// `/help`, tak punya tombol di `/model`, dan tak punya umpan balik di UI. Hasil
|
|
7
|
+
// audit pengguna: "fitur ini tidak ada". Mesinnya benar; penemuannya nol.
|
|
8
|
+
//
|
|
9
|
+
// `/context` menutup celah itu di tempat pengguna sudah melihat model: satu
|
|
10
|
+
// perintah yang (a) MENAMPILKAN angka efektif beserta asalnya, dan (b) membuka
|
|
11
|
+
// picker preset untuk menimpanya. Tabel tidak dikarang di sini — `resolveContextWindow`
|
|
12
|
+
// adalah rantai yang sama yang dipakai router/kernel, jadi angka yang tampil
|
|
13
|
+
// tidak bisa menyimpang dari angka yang benar-benar dipakai turn berikutnya.
|
|
14
|
+
|
|
15
|
+
import type { ContextWindowResolution } from "../src/policy/context-window.ts"
|
|
16
|
+
import { t } from "../src/ui/i18n/locale.ts"
|
|
17
|
+
|
|
18
|
+
/** Satu baris tabel: model, kapasitas efektif, dan dari mana angka itu datang. */
|
|
19
|
+
export interface ContextWindowRow {
|
|
20
|
+
model: string
|
|
21
|
+
window: string
|
|
22
|
+
/** Label asal yang jujur (bukan tebakan): lihat `originLabel`. */
|
|
23
|
+
origin: string
|
|
24
|
+
/** True bila angka ini berasal dari pilihan operator (boleh diubah/dihapus). */
|
|
25
|
+
manual: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Label asal resolusi. Sengaja dibedakan antara "manual" (operator memilih) dan
|
|
30
|
+
* "endpoint"/"catalog"/"models-dev" (temuan otomatis yang bisa berubah) karena
|
|
31
|
+
* satu-satunya pertanyaan yang berguna bagi pengguna adalah: apakah angka ini
|
|
32
|
+
* keputusan saya atau tebakan mesin?
|
|
33
|
+
*/
|
|
34
|
+
export function originLabel(res: ContextWindowResolution): string {
|
|
35
|
+
switch (res.source) {
|
|
36
|
+
case "override":
|
|
37
|
+
return "flag"
|
|
38
|
+
case "model":
|
|
39
|
+
case "provider-default":
|
|
40
|
+
// `origin` membedakan nilai `user` (dikunci operator) dari `endpoint`
|
|
41
|
+
// (ditemukan dari /models, boleh ditimpa sync berikutnya).
|
|
42
|
+
return res.origin === "user" ? "manual" : (res.origin ?? "config")
|
|
43
|
+
case "catalog":
|
|
44
|
+
return "katalog"
|
|
45
|
+
case "models-dev":
|
|
46
|
+
return "models.dev"
|
|
47
|
+
case "safe-default":
|
|
48
|
+
return "default aman"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Baris tabel untuk satu model. `describe` disuntik agar modul ini bebas dari
|
|
53
|
+
* format angka (dan mudah diuji tanpa tabel preset). */
|
|
54
|
+
export function contextWindowRow(
|
|
55
|
+
model: string,
|
|
56
|
+
res: ContextWindowResolution,
|
|
57
|
+
describe: (tokens: number) => string,
|
|
58
|
+
): ContextWindowRow {
|
|
59
|
+
return {
|
|
60
|
+
model,
|
|
61
|
+
window: describe(res.tokens),
|
|
62
|
+
origin: originLabel(res),
|
|
63
|
+
manual: res.source === "model" || res.source === "provider-default",
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Judul baris tabel — satu sumber untuk /context. */
|
|
68
|
+
export function contextWindowTableHeader(): { model: string; window: string; origin: string } {
|
|
69
|
+
return {
|
|
70
|
+
model: t("ctx.colModel"),
|
|
71
|
+
window: t("ctx.colWindow"),
|
|
72
|
+
origin: t("ctx.colOrigin"),
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Teks hasil setelah operator memilih nilai: menyebutkan ANGKA, bukan hanya
|
|
78
|
+
* label. `describe` memberi label pendek ("128K"); angka eksak disertakan
|
|
79
|
+
* karena satu-satunya sumber kebingungan adalah "128K" genap atau 128.000.
|
|
80
|
+
*/
|
|
81
|
+
export function contextWindowSavedNotice(
|
|
82
|
+
tokens: number | null,
|
|
83
|
+
describe: (tokens: number) => string,
|
|
84
|
+
): string {
|
|
85
|
+
if (tokens === null) return t("ctx.savedAuto")
|
|
86
|
+
return t("ctx.saved", { label: describe(tokens), tokens: tokens.toLocaleString("en-US") })
|
|
87
|
+
}
|
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,67 @@ 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"
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Jaring terakhir proses (audit freeze/ceket 2026-11-16).
|
|
44
|
+
*
|
|
45
|
+
* Tanpa handler ini, SATU rejection/throw yang lolos (dari hook async, timer,
|
|
46
|
+
* stream provider yang ditutup, atau fire-and-forget di UI) membunuh proses
|
|
47
|
+
* dengan exit 1 dan meninggalkan terminal dalam raw mode + alt-screen — gejala
|
|
48
|
+
* persis "ceket": layar rusak, tak ada pesan, sesi harus ditutup manual.
|
|
49
|
+
*
|
|
50
|
+
* Perilaku lama tidak dipertahankan sebagai default karena tak ada satu pun
|
|
51
|
+
* jalur yang memang menginginkan proses mati diam-diam: kegagalan yang perlu
|
|
52
|
+
* menghentikan sesi sudah lewat `App.quit()`/`AgentError`.
|
|
53
|
+
*
|
|
54
|
+
* Kontrak yang dipilih:
|
|
55
|
+
* - Cetak ringkas ke stderr (tanpa stack penuh kecuali MINICODE_DEBUG=1).
|
|
56
|
+
* - Kembalikan terminal (raw mode, alt-screen, kursor) SEBELUM keluar.
|
|
57
|
+
* - Exit code 1 agar CI/skrip tetap melihat kegagalan.
|
|
58
|
+
* - Idempoten: penanganan kedua (mis. error saat cleanup) tidak rekursi.
|
|
59
|
+
*/
|
|
60
|
+
let crashGuardArmed = false
|
|
61
|
+
function installCrashGuard(): void {
|
|
62
|
+
if (crashGuardArmed) return
|
|
63
|
+
crashGuardArmed = true
|
|
64
|
+
const restoreAndExit = (kind: string, error: unknown): void => {
|
|
65
|
+
try {
|
|
66
|
+
// Kembalikan terminal: tanpa ini shell pengguna tetap dalam raw mode.
|
|
67
|
+
const stdin = process.stdin as typeof process.stdin & { setRawMode?: (b: boolean) => void }
|
|
68
|
+
stdin.setRawMode?.(false)
|
|
69
|
+
} catch {}
|
|
70
|
+
try {
|
|
71
|
+
// 1049 = keluar alt-screen; 25h = tampilkan kursor; 0m = reset atribut.
|
|
72
|
+
process.stdout.write("\u001b[?1049l\u001b[?25h\u001b[0m")
|
|
73
|
+
} catch {}
|
|
74
|
+
try {
|
|
75
|
+
const debug = process.env.MINICODE_DEBUG === "1"
|
|
76
|
+
const msg = error instanceof Error ? error.message : String(error)
|
|
77
|
+
const detail = debug && error instanceof Error && error.stack ? `\n${error.stack}` : ""
|
|
78
|
+
process.stderr.write(`\n[minicode] ${kind}: ${msg}${detail}\n`)
|
|
79
|
+
} catch {}
|
|
80
|
+
// 1 = gagal. Dipakai CI dan skrip pemanggil untuk membedakan crash dari exit normal.
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
process.on("uncaughtException", (error) => restoreAndExit("internal error", error))
|
|
84
|
+
process.on("unhandledRejection", (reason) => restoreAndExit("unhandled rejection", reason))
|
|
85
|
+
}
|
|
38
86
|
|
|
39
87
|
/** Versi dibaca dari package.json — satu sumber, tidak di-hardcode dua tempat. */
|
|
40
88
|
function readVersion(): string {
|
|
@@ -71,7 +119,6 @@ Options:
|
|
|
71
119
|
--session <id> session id (default random)
|
|
72
120
|
--allow-all allow all tools (privileged access profile; hard jail/guard still apply)
|
|
73
121
|
--ask ask per tool (y/n/a) — human-supervised execution
|
|
74
|
-
--plan deprecated: alias for --work-mode PLAN (read-only planning)
|
|
75
122
|
--allowlist bash allowlist only (see MINICODE_BASH_ALLOWLIST)
|
|
76
123
|
--max-steps <n> max tool steps (default 50)
|
|
77
124
|
--context-window <n> context window tokens
|
|
@@ -83,8 +130,8 @@ Options:
|
|
|
83
130
|
--budget <usd> session cost limit
|
|
84
131
|
--budget-strict unknown cost + spend counts as over budget (fail-closed default)
|
|
85
132
|
--tool-scope <s> full (default) | explore (read-only subset)
|
|
86
|
-
--work-mode <m> DISCUSS |
|
|
87
|
-
read-only investigation,
|
|
133
|
+
--work-mode <m> DISCUSS | BUILD (default: DISCUSS). Operating mode: DISCUSS =
|
|
134
|
+
read-only investigation, discussion & planning, BUILD = implementation.
|
|
88
135
|
--tui deprecated no-op (interactive mode is always the fullscreen TUI)
|
|
89
136
|
--enable-scheduler EXPERIMENTAL: opt in to the autonomous scheduler (default: off).
|
|
90
137
|
Manual only - run /scheduler run. No timer; autonomous turns are
|
|
@@ -95,13 +142,16 @@ Options:
|
|
|
95
142
|
admitted through the runtime (kernel + durable journal); a rejected
|
|
96
143
|
admission runs nothing. Unknown value = off.
|
|
97
144
|
|
|
98
|
-
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
|
|
99
146
|
Keys: Enter submit · Tab work-mode · Shift+Tab permission · Up/Down history · Mouse wheel/PgUp/PgDn scroll (Shift = half page)
|
|
100
147
|
Home/End jump to transcript top/tail · Ctrl+R search · Esc abort turn (twice = quit) · Ctrl+D exit
|
|
101
148
|
Subcommand flags (config/mcp/sessions/skills/exec/...): see 'minicode <cmd> --help'.
|
|
102
149
|
`
|
|
103
150
|
|
|
104
151
|
const args = process.argv.slice(2)
|
|
152
|
+
// Dipasang SEBELUM dispatch: crash di jalur mana pun (termasuk config/mcp/exec)
|
|
153
|
+
// tetap memulihkan terminal, bukan meninggalkan sesi dalam raw mode.
|
|
154
|
+
installCrashGuard()
|
|
105
155
|
function getArg(name: string): string | undefined {
|
|
106
156
|
return rawGetArg(args, name)
|
|
107
157
|
}
|
|
@@ -154,13 +204,29 @@ setSubAgentSessionFactory(async (spec) => {
|
|
|
154
204
|
const { journal, ...coreSpec } = spec
|
|
155
205
|
const contextWindowTokensForModel = coreSpec.provider.contextWindowTokensForModel
|
|
156
206
|
const contextModelIdentity = coreSpec.provider.contextModelIdentity
|
|
207
|
+
const getContextModel = () => contextModelIdentity?.(coreSpec.model) ?? coreSpec.model
|
|
208
|
+
let childJournalHandle: ReturnType<typeof attachMutationJournal> | null = null
|
|
157
209
|
const session = await createMinicodeSession({
|
|
158
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
|
+
: {}),
|
|
159
225
|
...(contextWindowTokensForModel
|
|
160
226
|
? {
|
|
161
227
|
contextWindowTokens: contextWindowTokensForModel(coreSpec.model),
|
|
162
228
|
contextWindowTokensForModel,
|
|
163
|
-
getContextModel
|
|
229
|
+
getContextModel,
|
|
164
230
|
}
|
|
165
231
|
: {}),
|
|
166
232
|
})
|
|
@@ -178,7 +244,7 @@ setSubAgentSessionFactory(async (spec) => {
|
|
|
178
244
|
session.events.on("turn:completed", () => {
|
|
179
245
|
void childWrite.finally(() => childPresentation.dispose())
|
|
180
246
|
})
|
|
181
|
-
attachMutationJournal(session, {
|
|
247
|
+
childJournalHandle = attachMutationJournal(session, {
|
|
182
248
|
sessionId: journal.sessionId,
|
|
183
249
|
cwd: spec.cwd,
|
|
184
250
|
childOf: journal.parentSessionId,
|
|
@@ -260,7 +326,6 @@ if (args.includes("-h") || args.includes("--help")) {
|
|
|
260
326
|
},
|
|
261
327
|
{ flag: "--allow-all", desc: "allow all tools (privileged access profile)" },
|
|
262
328
|
{ flag: "--ask", desc: "ask per tool (human-supervised)" },
|
|
263
|
-
{ flag: "--plan", desc: "deprecated: alias for --work-mode PLAN" },
|
|
264
329
|
{ flag: "--allowlist", desc: "bash allowlist only" },
|
|
265
330
|
{ flag: "--interactive", desc: "interactive TUI" },
|
|
266
331
|
{ flag: "--verify", desc: "auto-verify + self-heal" },
|
|
@@ -270,8 +335,8 @@ if (args.includes("-h") || args.includes("--help")) {
|
|
|
270
335
|
{ flag: "--budget-strict", desc: "unknown cost + spend counts as over budget (default)" },
|
|
271
336
|
{ flag: "--tool-scope <full|explore>", desc: "tool subset (explore = read-only)" },
|
|
272
337
|
{
|
|
273
|
-
flag: "--work-mode <DISCUSS|
|
|
274
|
-
desc: "operating mode: DISCUSS (default, read-only),
|
|
338
|
+
flag: "--work-mode <DISCUSS|BUILD>",
|
|
339
|
+
desc: "operating mode: DISCUSS (default, read-only), BUILD",
|
|
275
340
|
},
|
|
276
341
|
{ flag: "--json", desc: "JSON output (help/exec)" },
|
|
277
342
|
{ flag: "--tui", desc: "deprecated no-op (interactive is always the fullscreen TUI)" },
|
|
@@ -289,7 +354,6 @@ const verbose = hasFlag(args, "--verbose")
|
|
|
289
354
|
const allowAll = hasFlag(args, "--allow-all")
|
|
290
355
|
const ask = hasFlag(args, "--ask")
|
|
291
356
|
const interactive = hasFlag(args, "--interactive")
|
|
292
|
-
const plan = hasFlag(args, "--plan") || process.env.MINICODE_PLAN === "1"
|
|
293
357
|
const allowlist = hasFlag(args, "--allowlist") || process.env.MINICODE_PERMISSION === "allowlist"
|
|
294
358
|
// [mode-architecture] Deprecation notice utk profil warisan — jangan dihapus
|
|
295
359
|
// diam-diam; peta kompatibilitas di MODE_ARCHITECTURE_MIGRATION_REPORT.
|
|
@@ -308,9 +372,8 @@ const cwd = cwdRaw ? resolvePath(cwdRaw) : undefined
|
|
|
308
372
|
// eksplisit per-invokasi (flag atau env). Tanpa ini repo clone-an bisa
|
|
309
373
|
// men-spawn MCP server dan menyedot prompt ke endpoint penyerang.
|
|
310
374
|
const allowLocal = allowLocalConfig(args)
|
|
311
|
-
// WorkMode (lapis intent di atas profil izin). Flag mengalahkan env;
|
|
375
|
+
// WorkMode (lapis intent 2-mode di atas profil izin). Flag mengalahkan env;
|
|
312
376
|
// keduanya tak ada atau nilainya tak dikenal = DISCUSS (fail-closed).
|
|
313
|
-
// `--plan` adalah alias legacy untuk WorkMode PLAN.
|
|
314
377
|
const workModeResolved = resolveWorkModeFlag(getArg)
|
|
315
378
|
const workMode = workModeResolved.workMode
|
|
316
379
|
// Sinyal WorkMode eksplisit (flag/env) ikut diteruskan agar resume dapat
|
|
@@ -365,30 +428,18 @@ const adoptTask = adoptTaskParsed ?? undefined
|
|
|
365
428
|
const bootId = mintSessionId()
|
|
366
429
|
const modelOverride = getArg("--model")
|
|
367
430
|
const providerOverride = getArg("--provider")
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
if (maxStepsRaw && (!Number.isFinite(maxSteps) || (maxSteps as number) <= 0)) {
|
|
371
|
-
process.stderr.write(`[warn] --max-steps requires a positive number, ignoring "${maxStepsRaw}"\n`)
|
|
372
|
-
maxSteps = undefined
|
|
431
|
+
const warnStderr = (msg: string): void => {
|
|
432
|
+
process.stderr.write(msg)
|
|
373
433
|
}
|
|
434
|
+
const { maxSteps, contextWindowTokens, timeoutMs, budget, ratelimitRpm } = parseRuntimeNumericFlags(
|
|
435
|
+
getArg,
|
|
436
|
+
warnStderr,
|
|
437
|
+
)
|
|
374
438
|
// `--tui` alias usang (TUI fullscreen kini satu-satunya tampilan interaktif):
|
|
375
439
|
// tetap diterima agar skrip lama tak pecah, tapi TIDAK diam — tanpa peringatan
|
|
376
440
|
// user mengira flag-nya masih mengubah perilaku.
|
|
377
441
|
if (args.includes("--tui")) {
|
|
378
|
-
|
|
379
|
-
"[deprecated] --tui is a no-op: interactive mode is always the fullscreen TUI\n",
|
|
380
|
-
)
|
|
381
|
-
}
|
|
382
|
-
const ctxWindowRaw = getArg("--context-window")
|
|
383
|
-
let contextWindowTokens = ctxWindowRaw ? Number(ctxWindowRaw) : undefined
|
|
384
|
-
if (
|
|
385
|
-
ctxWindowRaw &&
|
|
386
|
-
(!Number.isFinite(contextWindowTokens) || (contextWindowTokens as number) <= 0)
|
|
387
|
-
) {
|
|
388
|
-
process.stderr.write(
|
|
389
|
-
`[warn] --context-window requires a positive number, ignoring "${ctxWindowRaw}"\n`,
|
|
390
|
-
)
|
|
391
|
-
contextWindowTokens = undefined
|
|
442
|
+
warnStderr("[deprecated] --tui is a no-op: interactive mode is always the fullscreen TUI\n")
|
|
392
443
|
}
|
|
393
444
|
// F3.2: override keepRecentTurns kompaksi kernel via env (bukan flag: jarang
|
|
394
445
|
// diubah, dan permukaan flag CLI sengaja kecil). Selain bilangan >=1 =
|
|
@@ -396,23 +447,15 @@ if (
|
|
|
396
447
|
const keepTurnsRaw = (process.env.MINICODE_COMPACT_KEEP_TURNS ?? "").trim()
|
|
397
448
|
const keepRecentTurns = parseCompactKeepTurns(keepTurnsRaw || undefined)
|
|
398
449
|
if (keepTurnsRaw && keepRecentTurns === undefined)
|
|
399
|
-
|
|
450
|
+
warnStderr(
|
|
400
451
|
`[warn] MINICODE_COMPACT_KEEP_TURNS requires an integer >= 1, ignoring "${keepTurnsRaw}"\n`,
|
|
401
452
|
)
|
|
402
|
-
const timeoutRaw = getArg("--timeout")
|
|
403
|
-
let timeoutMs = timeoutRaw ? Number(timeoutRaw) : undefined
|
|
404
|
-
if (timeoutRaw && (!Number.isFinite(timeoutMs) || (timeoutMs as number) < 0)) {
|
|
405
|
-
process.stderr.write(
|
|
406
|
-
`[warn] --timeout requires a non-negative number, ignoring "${timeoutRaw}"\n`,
|
|
407
|
-
)
|
|
408
|
-
timeoutMs = undefined
|
|
409
|
-
}
|
|
410
453
|
|
|
411
454
|
// Sandbox: OS-native dipakai otomatis bila tersedia. Bila tidak ada isolasi
|
|
412
455
|
// nyata dan user belum memilih mode permission sendiri, default diturunkan ke
|
|
413
456
|
// `allowlist` — lebih baik membatasi perintah daripada menjalankan apa pun
|
|
414
457
|
// sambil menampilkan label aman. Lihat src/policy/sandbox-policy.ts.
|
|
415
|
-
const explicitPermission = allowAll || ask ||
|
|
458
|
+
const explicitPermission = allowAll || ask || allowlist
|
|
416
459
|
const requestedSandbox = getArg("--sandbox") ?? process.env.MINICODE_SANDBOX
|
|
417
460
|
// F-03: permintaan sandbox EKSPLISIT tanpa backend = tolak sebelum jalan
|
|
418
461
|
// (fail-closed). resolveSandbox di bawah tetap menghitung downgrade allowlist
|
|
@@ -429,29 +472,11 @@ else process.env.MINICODE_SANDBOX = sandbox.mode
|
|
|
429
472
|
// mode tak dikenal). Notice rutin disembunyikan: mode terlihat di prefiks.
|
|
430
473
|
// Cetaknya di setup, setelah provider layer lolos.
|
|
431
474
|
const effectiveAllowlist = allowlist || sandbox.fallbackPermission === "allowlist"
|
|
432
|
-
const budgetRaw = getArg("--budget")
|
|
433
|
-
let budget = budgetRaw ? Number(budgetRaw) : undefined
|
|
434
|
-
if (budgetRaw && (!Number.isFinite(budget) || (budget as number) < 0)) {
|
|
435
|
-
process.stderr.write(`[warn] --budget requires a USD number, ignoring "${budgetRaw}"\n`)
|
|
436
|
-
budget = undefined
|
|
437
|
-
}
|
|
438
475
|
// Harness-P1: strict lewat flag ATAU env (simetri dengan MINICODE_SANDBOX_STRICT).
|
|
439
476
|
const budgetStrict = hasFlag(args, "--budget-strict") || process.env.MINICODE_BUDGET_STRICT === "1"
|
|
440
477
|
// Harness-P2: scope tool sesi; nilai selain explore jatuh ke full (eksplisit di bawah).
|
|
441
|
-
const
|
|
442
|
-
const
|
|
443
|
-
const ratelimitRaw = getArg("--ratelimit")
|
|
444
|
-
let rateLimiter: ReturnType<typeof createRateLimiter> | undefined
|
|
445
|
-
if (ratelimitRaw) {
|
|
446
|
-
const rpm = Number(ratelimitRaw)
|
|
447
|
-
if (!Number.isFinite(rpm) || rpm <= 0) {
|
|
448
|
-
process.stderr.write(
|
|
449
|
-
`[warn] --ratelimit requires a positive number, ignoring "${ratelimitRaw}"\n`,
|
|
450
|
-
)
|
|
451
|
-
} else {
|
|
452
|
-
rateLimiter = createRateLimiter(rpm)
|
|
453
|
-
}
|
|
454
|
-
}
|
|
478
|
+
const toolScope = resolveToolScope(getArg)
|
|
479
|
+
const rateLimiter = ratelimitRpm !== undefined ? createRateLimiter(ratelimitRpm) : undefined
|
|
455
480
|
|
|
456
481
|
const prompt = promptFromArgs(args) || (await readPrompt())
|
|
457
482
|
// [Live Hardening 0.13.x §8.3] Flag dikenal yang muncul SETELAH prompt boundary
|
|
@@ -520,7 +545,7 @@ try {
|
|
|
520
545
|
const spaceIdx = prompt.indexOf(" ")
|
|
521
546
|
const skillName = spaceIdx === -1 ? prompt.slice(1) : prompt.slice(1, spaceIdx)
|
|
522
547
|
const skillArgs = spaceIdx === -1 ? "" : prompt.slice(spaceIdx + 1)
|
|
523
|
-
const skill = await findSkill(skillName, cwd)
|
|
548
|
+
const skill = await findSkill(skillName, cwd, { allowLocal })
|
|
524
549
|
if (skill) {
|
|
525
550
|
effectivePrompt = await renderSkill(skill, skillArgs)
|
|
526
551
|
console.error(c.dim(`[loaded skill /${skill.name}]`))
|
|
@@ -576,7 +601,6 @@ try {
|
|
|
576
601
|
verbose,
|
|
577
602
|
allowAll,
|
|
578
603
|
ask,
|
|
579
|
-
plan,
|
|
580
604
|
allowlist: effectiveAllowlist,
|
|
581
605
|
verify,
|
|
582
606
|
allowLocalConfig: allowLocal,
|
|
@@ -675,12 +699,7 @@ if (enterRepl) {
|
|
|
675
699
|
// efektif (termasuk hasil pulihan `--resume`).
|
|
676
700
|
if (ctx.workMode !== "EXECUTE" || workModeExplicit) {
|
|
677
701
|
const workModeLabel = displayWorkMode(ctx.workMode)
|
|
678
|
-
const modeNote =
|
|
679
|
-
ctx.workMode === "PLAN"
|
|
680
|
-
? " (read-only planning)"
|
|
681
|
-
: ctx.workMode === "DISCUSS"
|
|
682
|
-
? " (read-only)"
|
|
683
|
-
: ""
|
|
702
|
+
const modeNote = ctx.workMode === "DISCUSS" ? " (read-only)" : ""
|
|
684
703
|
process.stderr.write(`[work-mode] ${workModeLabel}${modeNote}\n`)
|
|
685
704
|
}
|
|
686
705
|
const {
|
|
@@ -697,7 +716,11 @@ if (enterRepl) {
|
|
|
697
716
|
} = ctx
|
|
698
717
|
const t0 = Date.now()
|
|
699
718
|
try {
|
|
700
|
-
|
|
719
|
+
let finalPrompt = effectivePrompt
|
|
720
|
+
if (finalPrompt.includes("@")) {
|
|
721
|
+
finalPrompt = (await expandMentions(finalPrompt, wcwd ?? process.cwd())).prompt
|
|
722
|
+
}
|
|
723
|
+
await runPromptWithVerify(finalPrompt)
|
|
701
724
|
// Total SESI, bukan turn: satu one-shot hanya punya satu turn, tapi
|
|
702
725
|
// --verify/self-heal bisa menjalankan beberapa dan reset() di antaranya.
|
|
703
726
|
const u = usage.getSession(modelRef.current)
|
|
@@ -763,7 +786,7 @@ if (enterRepl) {
|
|
|
763
786
|
// Error provider biasanya sudah dirender ramah oleh event handler
|
|
764
787
|
// (takePendingError) — cetak sekali saja, jangan dua blok error.
|
|
765
788
|
const shown = ctx.uiState.takePendingError()
|
|
766
|
-
process.stderr.write(`\n${c.red(
|
|
789
|
+
process.stderr.write(`\n${c.red("failed")} ${shown ?? formatError(e)}\n`)
|
|
767
790
|
// Audit #04 P1: sama seperti REPL — turn gagal setelah delegasi
|
|
768
791
|
// committed = efek anak tetap ada. One-shot tak punya retry loop, tapi
|
|
769
792
|
// user yang menjalankan ulang manual butuh peringatan yang sama.
|
|
@@ -800,29 +823,4 @@ if (enterRepl) {
|
|
|
800
823
|
}
|
|
801
824
|
await new Promise((r) => setTimeout(r, 200))
|
|
802
825
|
await close()
|
|
803
|
-
|
|
804
|
-
if (ctx.permissionMode === "plan" && process.stdin.isTTY) {
|
|
805
|
-
const { createInterface } = await import("node:readline")
|
|
806
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
807
|
-
const ans = await new Promise<string>((res) =>
|
|
808
|
-
rl.question(c.yellow("\nProceed to execute this plan? [y/N] "), res),
|
|
809
|
-
)
|
|
810
|
-
rl.close()
|
|
811
|
-
if (ans.trim().toLowerCase() === "y") {
|
|
812
|
-
const { spawn } = await import("node:child_process")
|
|
813
|
-
const { waitChildExit } = await import("./auto-update.ts")
|
|
814
|
-
const entry = process.argv[1] ?? resolvePath(import.meta.dir, "index.ts")
|
|
815
|
-
const filtered = args.filter((a) => a !== "--plan")
|
|
816
|
-
const child = spawn(process.execPath, [entry, ...filtered], {
|
|
817
|
-
stdio: "inherit",
|
|
818
|
-
env: { ...process.env, MINICODE_PLAN: "0" },
|
|
819
|
-
})
|
|
820
|
-
// Tunggu via mekanisme tunggal (exit+close+error): exit saja bisa tak
|
|
821
|
-
// datang bila anak menahan stdio = induk gantung tanpa prompt.
|
|
822
|
-
void waitChildExit(child).then((code) => process.exit(code ?? 0))
|
|
823
|
-
process.stdin.resume()
|
|
824
|
-
} else {
|
|
825
|
-
process.exit(0)
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
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
|
},
|