minicode-ai 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/args.ts +120 -16
- package/cli/commands/acp.ts +38 -28
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +11 -12
- package/cli/commands/exec.ts +35 -73
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +96 -46
- package/cli/context-command-run.ts +171 -0
- package/cli/context-command.ts +87 -0
- package/cli/index.ts +96 -98
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +246 -123
- package/cli/tui.ts +311 -109
- package/docs/TERMINAL_CONTRACT.md +254 -69
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/config.md +16 -0
- package/docs/environment.md +3 -3
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +3 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +119 -66
- package/src/app/tool-layer.ts +12 -17
- package/src/config.ts +64 -104
- package/src/constants.ts +23 -9
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +109 -0
- package/src/policy/context.ts +78 -37
- package/src/policy/executor.ts +17 -7
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/guards.ts +41 -2
- package/src/providers/provision.ts +6 -60
- package/src/providers/responses.ts +1 -0
- package/src/repo/repomap.ts +180 -23
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +25 -58
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +20 -37
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +59 -23
- package/src/ui/i18n/id.ts +88 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +88 -62
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +154 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/cli/args.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Pure arg-parsing helpers - dipisah dari cli/index.ts agar mudah diuji.
|
|
2
|
+
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
3
|
+
|
|
2
4
|
const BOOLEAN_FLAGS = new Set([
|
|
3
5
|
"--verbose",
|
|
4
6
|
"--allow-all",
|
|
5
7
|
"--ask",
|
|
6
|
-
"--plan",
|
|
7
8
|
"--interactive",
|
|
8
9
|
"--tui", // alias usang: TUI fullscreen kini satu-satunya tampilan interaktif
|
|
9
10
|
"--verify",
|
|
@@ -11,6 +12,16 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
11
12
|
"--json", // dipakai `exec --json` dan `--help --json`
|
|
12
13
|
"--budget-strict", // penegasan eksplisit fail-closed (kini juga default --budget)
|
|
13
14
|
"--allow-local-config", // opt-in: baca .minicode/config.json + allowlist lokal (default mati)
|
|
15
|
+
// flag boolean subcommand — harus di sini agar router tidak memakan token berikutnya sebagai nilai
|
|
16
|
+
"--allow-private",
|
|
17
|
+
"--jsonl",
|
|
18
|
+
"--all-tools",
|
|
19
|
+
"--global",
|
|
20
|
+
"--local",
|
|
21
|
+
"--auto-continue",
|
|
22
|
+
"--blocked",
|
|
23
|
+
"--closed",
|
|
24
|
+
"--force",
|
|
14
25
|
// [PHASE 6U] Experimental. Opt-in gate for autonomous Scheduler execution.
|
|
15
26
|
// DEFAULT OFF. A CLI flag and not a config key or env var on purpose: env is
|
|
16
27
|
// inherited by sub-agents and MCP servers, and config is inherited globally or
|
|
@@ -31,7 +42,7 @@ const VALUE_FLAGS = new Set([
|
|
|
31
42
|
"--ratelimit",
|
|
32
43
|
"--budget",
|
|
33
44
|
"--tool-scope", // full | explore (read-only) — tanpa ini jadi kata prompt!
|
|
34
|
-
"--work-mode", // DISCUSS |
|
|
45
|
+
"--work-mode", // DISCUSS | BUILD — HARUS dikenal agar tak bocor ke prompt.
|
|
35
46
|
// [P1 M15] Mode runtime produksi (off | constructed | owned). HARUS terdaftar:
|
|
36
47
|
// flag tak dikenal menghentikan scan `hasFlag`/`getArg` (dianggap prompt
|
|
37
48
|
// boundary), sehingga flag yang diletakkan SETELAH `--runtime` akan hilang
|
|
@@ -47,13 +58,27 @@ const VALUE_FLAGS = new Set([
|
|
|
47
58
|
"--args",
|
|
48
59
|
"--env",
|
|
49
60
|
"--header",
|
|
50
|
-
"--allow-private",
|
|
51
61
|
"--url",
|
|
52
62
|
"--match",
|
|
53
|
-
"--
|
|
54
|
-
"--
|
|
55
|
-
"--
|
|
56
|
-
"--
|
|
63
|
+
"--adopt-task",
|
|
64
|
+
"--max-turns",
|
|
65
|
+
"--port",
|
|
66
|
+
"--who",
|
|
67
|
+
"--scopes",
|
|
68
|
+
"--ttl",
|
|
69
|
+
"--hash",
|
|
70
|
+
"--status",
|
|
71
|
+
"--state",
|
|
72
|
+
"--priority",
|
|
73
|
+
"--min-age-days",
|
|
74
|
+
"--depends-on",
|
|
75
|
+
"--stale-days",
|
|
76
|
+
"--keep",
|
|
77
|
+
"--drop",
|
|
78
|
+
"--evidence",
|
|
79
|
+
"--task",
|
|
80
|
+
"--format",
|
|
81
|
+
"--out",
|
|
57
82
|
])
|
|
58
83
|
export const valueFlags = VALUE_FLAGS
|
|
59
84
|
const KNOWN_FLAGS = new Set([...BOOLEAN_FLAGS, ...VALUE_FLAGS, "-h", "--help", "-v", "--version"])
|
|
@@ -95,21 +120,100 @@ export function hasFlag(argv: string[], name: string): boolean {
|
|
|
95
120
|
|
|
96
121
|
/** Opt-in config lokal untuk alur sesi utama (index/exec): flag eksplisit
|
|
97
122
|
* operator ATAU env (keduanya default mati). Memakai hasFlag yang
|
|
98
|
-
* boundary-aware: flag di DALAM teks prompt tidak dihitung (anti-injeksi).
|
|
99
|
-
* Handler subcommand (config/providers/…) memakai args.includes langsung
|
|
100
|
-
* karena argv-nya selalu diawali positional subcommand. */
|
|
123
|
+
* boundary-aware: flag di DALAM teks prompt tidak dihitung (anti-injeksi). */
|
|
101
124
|
export function allowLocalConfig(argv: string[]): boolean {
|
|
102
125
|
return hasFlag(argv, "--allow-local-config") || process.env.MINICODE_ALLOW_LOCAL_CONFIG === "1"
|
|
103
126
|
}
|
|
104
127
|
|
|
105
|
-
|
|
128
|
+
/** Cek --allow-local-config / env pada argv subcommand. */
|
|
129
|
+
export function allowLocalSubcommand(argv: readonly string[]): boolean {
|
|
130
|
+
return argv.includes("--allow-local-config") || process.env.MINICODE_ALLOW_LOCAL_CONFIG === "1"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Ambil positional ke-`index` dari argv subcommand (tolak `-*`). */
|
|
134
|
+
export function positionalSubArg(argv: readonly string[], index: number): string | undefined {
|
|
135
|
+
const v = argv[index]
|
|
136
|
+
return v && !v.startsWith("-") ? v : undefined
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Cek apakah argv subcommand meminta `--help` / `-h`. */
|
|
140
|
+
export function hasHelpFlag(argv: readonly string[]): boolean {
|
|
141
|
+
return argv.includes("--help") || argv.includes("-h")
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Tangani `--help`/`-h` (exit 0) dan positional tak terduga (exit 2) secara seragam. */
|
|
145
|
+
export function guardSubcommand(
|
|
146
|
+
args: readonly string[],
|
|
147
|
+
cmd: string,
|
|
148
|
+
help: string,
|
|
149
|
+
out: (s: string) => void,
|
|
150
|
+
err: (s: string) => void,
|
|
151
|
+
extraIndex = 1,
|
|
152
|
+
): void {
|
|
153
|
+
if (hasHelpFlag(args)) {
|
|
154
|
+
out(help)
|
|
155
|
+
process.exit(0)
|
|
156
|
+
}
|
|
157
|
+
if (extraIndex >= 0) {
|
|
158
|
+
const extra = positionalSubArg(args, extraIndex)
|
|
159
|
+
if (extra) {
|
|
160
|
+
err(`unknown ${cmd} subcommand: ${sanitizeAnsiLine(extra)}\n${help}`)
|
|
161
|
+
process.exit(2)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Parse argumen toggle (`/compact`, `/thinking`, `/fold`, `/minimize`, `/unrestric`). */
|
|
167
|
+
export function parseToggleArg(raw: string): boolean | undefined | "invalid" {
|
|
168
|
+
const norm = raw.trim().toLowerCase()
|
|
169
|
+
if (norm === "") return undefined
|
|
170
|
+
if (norm === "on" || norm === "1") return true
|
|
171
|
+
if (norm === "off" || norm === "0") return false
|
|
172
|
+
return "invalid"
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Parse flag numerik runtime + peringatan seragam untuk CLI utama & `exec`. */
|
|
176
|
+
export function parseNumericFlag(
|
|
177
|
+
getArg: (name: string) => string | undefined,
|
|
178
|
+
flag: string,
|
|
179
|
+
kind: "positive" | "non-negative" | "usd",
|
|
180
|
+
warn: (msg: string) => void,
|
|
181
|
+
): number | undefined {
|
|
182
|
+
const raw = getArg(flag)
|
|
183
|
+
if (!raw) return undefined
|
|
184
|
+
const n = Number(raw)
|
|
185
|
+
if (Number.isFinite(n) && (kind === "positive" ? n > 0 : n >= 0)) return n
|
|
186
|
+
const label = kind === "usd" ? "USD number" : `${kind} number`
|
|
187
|
+
warn(`[warn] ${flag} requires a ${label}, ignoring "${raw}"\n`)
|
|
188
|
+
return undefined
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function parseRuntimeNumericFlags(
|
|
192
|
+
getArg: (name: string) => string | undefined,
|
|
193
|
+
warn: (msg: string) => void,
|
|
194
|
+
) {
|
|
195
|
+
return {
|
|
196
|
+
maxSteps: parseNumericFlag(getArg, "--max-steps", "positive", warn),
|
|
197
|
+
contextWindowTokens: parseNumericFlag(getArg, "--context-window", "positive", warn),
|
|
198
|
+
timeoutMs: parseNumericFlag(getArg, "--timeout", "non-negative", warn),
|
|
199
|
+
budget: parseNumericFlag(getArg, "--budget", "usd", warn),
|
|
200
|
+
ratelimitRpm: parseNumericFlag(getArg, "--ratelimit", "positive", warn),
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function resolveToolScope(getArg: (name: string) => string | undefined): "explore" | "full" {
|
|
205
|
+
const raw = (getArg("--tool-scope") ?? process.env.MINICODE_TOOL_SCOPE ?? "").toLowerCase()
|
|
206
|
+
return raw === "explore" ? "explore" : "full"
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type CliWorkMode = "DISCUSS" | "EXECUTE"
|
|
106
210
|
|
|
107
|
-
/** Parse
|
|
211
|
+
/** Parse dua nilai Work Mode yang ditampilkan ke operator (DISCUSS | BUILD). */
|
|
108
212
|
export function parseWorkModeValue(raw: string): CliWorkMode | undefined {
|
|
109
213
|
const norm = raw.trim().toUpperCase()
|
|
110
214
|
// BUILD adalah nama produk untuk identitas runtime EXECUTE.
|
|
111
215
|
if (norm === "BUILD") return "EXECUTE"
|
|
112
|
-
if (norm === "DISCUSS"
|
|
216
|
+
if (norm === "DISCUSS") return norm
|
|
113
217
|
return undefined
|
|
114
218
|
}
|
|
115
219
|
|
|
@@ -118,7 +222,7 @@ export function parseWorkModeValue(raw: string): CliWorkMode | undefined {
|
|
|
118
222
|
* ditampilkan sebagai `BUILD`. Dipakai footer, /status, help, dan i18n agar
|
|
119
223
|
* semua permukaan konsisten, tanpa mengubah identitas runtime/persistence.
|
|
120
224
|
*/
|
|
121
|
-
export function displayWorkMode(workMode: CliWorkMode): "DISCUSS" | "
|
|
225
|
+
export function displayWorkMode(workMode: CliWorkMode): "DISCUSS" | "BUILD" {
|
|
122
226
|
return workMode === "EXECUTE" ? "BUILD" : workMode
|
|
123
227
|
}
|
|
124
228
|
|
|
@@ -143,7 +247,7 @@ export function resolveWorkModeFlag(getArg: (n: string) => string | undefined):
|
|
|
143
247
|
return {
|
|
144
248
|
workMode: "DISCUSS",
|
|
145
249
|
explicit: true,
|
|
146
|
-
warning: `--work-mode requires DISCUSS|
|
|
250
|
+
warning: `--work-mode requires DISCUSS|BUILD, ignoring "${raw}" (using DISCUSS)`,
|
|
147
251
|
}
|
|
148
252
|
}
|
|
149
253
|
|
|
@@ -217,7 +321,7 @@ export function promptFromArgs(argv: string[]): string {
|
|
|
217
321
|
}
|
|
218
322
|
continue
|
|
219
323
|
}
|
|
220
|
-
if (
|
|
324
|
+
if (!VALUE_FLAGS.has(fname)) continue
|
|
221
325
|
// value flag sebelum prompt: lewati flag + nilainya
|
|
222
326
|
if (!a.includes("=")) i++
|
|
223
327
|
}
|
package/cli/commands/acp.ts
CHANGED
|
@@ -15,9 +15,28 @@ import { formatError } from "../../src/ui/assistant/simple.ts"
|
|
|
15
15
|
import type { UiPresentationEvent, UiPresentationSnapshot } from "../../src/ui/contract.ts"
|
|
16
16
|
import { formatUsd } from "../../src/ui/render/money.ts"
|
|
17
17
|
import { cleanUntrusted } from "../../src/ui/render/sanitize.ts"
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
allowLocalSubcommand,
|
|
20
|
+
displayWorkMode,
|
|
21
|
+
guardSubcommand,
|
|
22
|
+
parseWorkModeValue,
|
|
23
|
+
resolveWorkModeFlag,
|
|
24
|
+
} from "../args.ts"
|
|
19
25
|
import { createCliSession } from "../setup.ts"
|
|
20
26
|
|
|
27
|
+
const ACP_HELP = `minicode acp — minimal JSON-RPC stdio server for IDEs
|
|
28
|
+
|
|
29
|
+
minicode acp [--allow-local-config]`
|
|
30
|
+
|
|
31
|
+
const writeStdoutLine = (line: string): void => {
|
|
32
|
+
try {
|
|
33
|
+
process.stdout.write(`${line}\n`)
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
const writeStderrLine = (line: string): void => {
|
|
37
|
+
process.stderr.write(`${line}\n`)
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
// minicode acp — server JSON-RPC via stdio untuk IDE (Fase 5, subset minimal).
|
|
22
41
|
//
|
|
23
42
|
// BUKAN klaim kompatibel ACP penuh (Zed/JetBrains): hanya tiga method yang
|
|
@@ -27,7 +46,7 @@ import { createCliSession } from "../setup.ts"
|
|
|
27
46
|
//
|
|
28
47
|
// -> {"id":1,"method":"initialize","params":{"client":"zed"}}
|
|
29
48
|
// <- {"id":1,"result":{"server":"minicode-acp","capabilities":{...}}}
|
|
30
|
-
// -> {"id":2,"method":"run","params":{"prompt":"...","cwd":"...","model":"...","maxSteps":50,"timeoutMs":600000,"budget":0.5,"mode":"auto"|"ask","workMode":"DISCUSS"|"
|
|
49
|
+
// -> {"id":2,"method":"run","params":{"prompt":"...","cwd":"...","model":"...","maxSteps":50,"timeoutMs":600000,"budget":0.5,"mode":"auto"|"ask","workMode":"DISCUSS"|"BUILD"}}
|
|
31
50
|
// <- {"type":"text","delta":"..."} ... (notifikasi, tanpa id)
|
|
32
51
|
// <- {"type":"tool","name":"read_file"} ... (notifikasi legacy, tanpa id)
|
|
33
52
|
// <- {"type":"tool.started","toolCallId":"...","name":"read_file"} ...
|
|
@@ -95,7 +114,7 @@ export interface AcpRunParams {
|
|
|
95
114
|
budget?: number
|
|
96
115
|
mode?: "auto" | "ask"
|
|
97
116
|
/** WorkMode terpisah dari mode persetujuan; input BUILD dipetakan internal. */
|
|
98
|
-
workMode?: "DISCUSS" | "
|
|
117
|
+
workMode?: "DISCUSS" | "EXECUTE"
|
|
99
118
|
}
|
|
100
119
|
|
|
101
120
|
/** Validasi params `run`: prompt wajib non-kosong; angka harus hingga-positif;
|
|
@@ -125,7 +144,7 @@ export function parseRunParams(
|
|
|
125
144
|
? resolveWorkModeFlag(() => undefined).workMode
|
|
126
145
|
: parseWorkModeValue(String(p.workMode))
|
|
127
146
|
if (workMode === undefined)
|
|
128
|
-
return { ok: false, error: 'params.workMode must be "DISCUSS" | "
|
|
147
|
+
return { ok: false, error: 'params.workMode must be "DISCUSS" | "BUILD"' }
|
|
129
148
|
const out: AcpRunParams = { prompt, mode, workMode }
|
|
130
149
|
if (typeof p.cwd === "string" && p.cwd) out.cwd = p.cwd
|
|
131
150
|
if (typeof p.model === "string" && p.model) out.model = p.model
|
|
@@ -354,6 +373,7 @@ export interface AcpSessionDeps {
|
|
|
354
373
|
shouldExit: () => boolean
|
|
355
374
|
exit: (code: number) => void
|
|
356
375
|
createSession?: typeof createCliSession
|
|
376
|
+
allowLocalConfig?: boolean
|
|
357
377
|
}
|
|
358
378
|
|
|
359
379
|
/** Satu `run`: validasi → sesi headless → stream notifikasi → hasil/error
|
|
@@ -392,9 +412,9 @@ export async function runAcpSession(
|
|
|
392
412
|
verbose: false,
|
|
393
413
|
allowAll: false,
|
|
394
414
|
ask: rp.mode === "ask",
|
|
395
|
-
plan: false,
|
|
396
415
|
allowlist: false,
|
|
397
416
|
verify: false,
|
|
417
|
+
...(deps.allowLocalConfig ? { allowLocalConfig: true } : {}),
|
|
398
418
|
// WorkMode terpisah dari mode persetujuan; default DISCUSS.
|
|
399
419
|
workMode: rp.workMode,
|
|
400
420
|
budget: rp.budget,
|
|
@@ -452,7 +472,8 @@ export async function runAcpSession(
|
|
|
452
472
|
: `[budget] cost unknown (model without pricing) with ${ue.totalTokens} tokens spent - over budget, stopping.`
|
|
453
473
|
write(acpErr(id, msg, machineError(new Error(msg))))
|
|
454
474
|
} else {
|
|
455
|
-
const submitted = getSubmittedResult()
|
|
475
|
+
const submitted = getSubmittedResult(sessionId)
|
|
476
|
+
clearSubmittedResult(sessionId)
|
|
456
477
|
// submitted verbatim seperti exec --json (pipeline tak menebak
|
|
457
478
|
// batas); teks dis-scrub + di-cap (bisa megabyte).
|
|
458
479
|
write(
|
|
@@ -461,9 +482,9 @@ export async function runAcpSession(
|
|
|
461
482
|
sessionId: ctx.sessionId,
|
|
462
483
|
model: ctx.modelRef.current,
|
|
463
484
|
workMode: displayWorkMode(
|
|
464
|
-
((ctx as { workMode?: "DISCUSS" | "
|
|
485
|
+
((ctx as { workMode?: "DISCUSS" | "EXECUTE" }).workMode ??
|
|
465
486
|
rp.workMode ??
|
|
466
|
-
"DISCUSS") as "DISCUSS" | "
|
|
487
|
+
"DISCUSS") as "DISCUSS" | "EXECUTE",
|
|
467
488
|
),
|
|
468
489
|
tokens: ue.totalTokens,
|
|
469
490
|
inputTokens: ue.inputTokens,
|
|
@@ -490,8 +511,8 @@ export async function runAcpSession(
|
|
|
490
511
|
// histori yang tak durable dilaporkan via stderr diagnostik, bukan
|
|
491
512
|
// pesan protokol kedua.
|
|
492
513
|
if (ctx.isWriterStale()) {
|
|
493
|
-
|
|
494
|
-
`[writer] stale writer sid=${ctx.sessionId}, history NOT durable: ${ctx.writerStaleNote()}
|
|
514
|
+
writeStderrLine(
|
|
515
|
+
`[writer] stale writer sid=${ctx.sessionId}, history NOT durable: ${ctx.writerStaleNote()}`,
|
|
495
516
|
)
|
|
496
517
|
}
|
|
497
518
|
} catch {}
|
|
@@ -568,14 +589,10 @@ export async function dispatchAcpLine(line: string, loop: AcpLoop): Promise<void
|
|
|
568
589
|
}
|
|
569
590
|
}
|
|
570
591
|
|
|
571
|
-
export async function handleAcp(): Promise<void> {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
try {
|
|
576
|
-
process.stdout.write(`${line}\n`)
|
|
577
|
-
} catch {}
|
|
578
|
-
}
|
|
592
|
+
export async function handleAcp(args: readonly string[] = []): Promise<void> {
|
|
593
|
+
guardSubcommand(args, "acp", ACP_HELP, writeStdoutLine, writeStderrLine)
|
|
594
|
+
const allowLocalConfig = allowLocalSubcommand(args)
|
|
595
|
+
const write = writeStdoutLine
|
|
579
596
|
const flight = createFlight()
|
|
580
597
|
let shuttingDown = false
|
|
581
598
|
// Run sedang berjalan (termasuk antrean setup): flight.active() saja TIDAK
|
|
@@ -591,6 +608,7 @@ export async function handleAcp(): Promise<void> {
|
|
|
591
608
|
startFlight: (abort) => flight.start(abort),
|
|
592
609
|
shouldExit: () => shuttingDown,
|
|
593
610
|
exit: (code) => process.exit(code),
|
|
611
|
+
allowLocalConfig,
|
|
594
612
|
})
|
|
595
613
|
} finally {
|
|
596
614
|
busy = false
|
|
@@ -606,22 +624,14 @@ export async function handleAcp(): Promise<void> {
|
|
|
606
624
|
shuttingDown = true
|
|
607
625
|
},
|
|
608
626
|
exit: (code) => process.exit(code),
|
|
609
|
-
warnMalformed: () =>
|
|
627
|
+
warnMalformed: () => writeStderrLine("[acp] ignoring malformed line"),
|
|
610
628
|
}
|
|
611
629
|
|
|
612
630
|
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity })
|
|
613
|
-
// Event-driven, BUKAN for-await sekuensial: `cancel`/`shutdown` harus bisa
|
|
614
|
-
// menyela run yang berjalan. for-await menahan baris berikutnya sampai run
|
|
615
|
-
// selesai — cancel di stdin tak pernah terbaca (fitur mati di produksi).
|
|
616
|
-
// Tiap baris didispatch tanpa await; prefik sinkron dispatch (parse →
|
|
617
|
-
// runOne → startFlight) tetap berurutan per event, jadi run kedua melihat
|
|
618
|
-
// flight aktif dan ditolak jujur.
|
|
619
631
|
let inflight: Promise<void> | null = null
|
|
620
632
|
rl.on("line", (line: string) => {
|
|
621
633
|
const p = dispatchAcpLine(line, loop).catch((e: unknown) => {
|
|
622
|
-
|
|
623
|
-
// jangan biarkan satu baris jahat membunuh server diam-diam.
|
|
624
|
-
process.stderr.write(`[acp] dispatch failed: ${(e as Error)?.message ?? e}\n`)
|
|
634
|
+
writeStderrLine(`[acp] dispatch failed: ${(e as Error)?.message ?? e}`)
|
|
625
635
|
})
|
|
626
636
|
inflight = p
|
|
627
637
|
void p.finally(() => {
|
package/cli/commands/auth.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
OAUTH_PROVIDERS,
|
|
8
8
|
} from "../../src/providers/oauth.ts"
|
|
9
9
|
import { saveProvider } from "../../src/providers/provision.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
|
function usage(code = 0): never {
|
|
13
16
|
console.log(`minicode auth — OAuth login (no API key)
|
|
@@ -24,7 +27,7 @@ Tokens are stored at ${authFilePath()} (chmod 600), NOT in config.json.`)
|
|
|
24
27
|
export async function handleAuth(args: string[]): Promise<never> {
|
|
25
28
|
const sub = (args[1] ?? "").toLowerCase()
|
|
26
29
|
|
|
27
|
-
if (!sub || sub === "help" ||
|
|
30
|
+
if (!sub || sub === "help" || hasHelpFlag(args)) usage()
|
|
28
31
|
|
|
29
32
|
if (sub === "list") {
|
|
30
33
|
console.log(`\n${c.bold("Providers with OAuth support")}`)
|
|
@@ -50,44 +53,41 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
50
53
|
? c.yellow("expired (auto-refresh)")
|
|
51
54
|
: c.red("expired (re-login required)")
|
|
52
55
|
: c.green("active")
|
|
53
|
-
console.log(
|
|
56
|
+
console.log(
|
|
57
|
+
` ${c.cyan(sanitizeAnsiLine(r.providerId).padEnd(12))} ${state} ${c.dim(`exp ${exp}`)}`,
|
|
58
|
+
)
|
|
54
59
|
}
|
|
55
60
|
console.log("")
|
|
56
61
|
process.exit(0)
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
if (sub === "logout") {
|
|
60
|
-
|
|
61
|
-
// --cwd X` adalah lupa argumen, bukan kredensial bernama "--cwd".
|
|
62
|
-
const id = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
|
|
65
|
+
const id = positionalSubArg(args, 2)
|
|
63
66
|
if (!id) {
|
|
64
67
|
console.error("usage: minicode auth logout <provider>")
|
|
65
68
|
process.exit(2)
|
|
66
69
|
}
|
|
67
70
|
const ok = await removeAuth(id)
|
|
71
|
+
const safeId = sanitizeAnsiLine(id)
|
|
68
72
|
console.log(
|
|
69
|
-
ok ? `${c.green(
|
|
73
|
+
ok ? `${c.green("ok")} credentials "${safeId}" removed` : `(no credentials for "${safeId}")`,
|
|
70
74
|
)
|
|
71
75
|
process.exit(0)
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
if (sub !== "login") {
|
|
75
|
-
|
|
76
|
-
// dan bukan gagal runtime (exit 1).
|
|
77
|
-
console.error(`unknown auth subcommand: ${sub}`)
|
|
79
|
+
console.error(`unknown auth subcommand: ${sanitizeAnsiLine(sub)}`)
|
|
78
80
|
usage(2)
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
// ── login ──
|
|
82
|
-
// Device flow butuh browser + persetujuan manusia — di non-TTY (CI/pipe)
|
|
83
|
-
// gagalkan cepat dengan pesan jelas, bukan menembak jaringan lalu gagal 400.
|
|
84
84
|
if (!process.stdin.isTTY) {
|
|
85
85
|
console.error(
|
|
86
86
|
"auth login needs an interactive terminal (device-code approval happens in a browser)",
|
|
87
87
|
)
|
|
88
88
|
process.exit(1)
|
|
89
89
|
}
|
|
90
|
-
const requested = args
|
|
90
|
+
const requested = positionalSubArg(args, 2) ?? OAUTH_PROVIDERS[0]?.id
|
|
91
91
|
if (!requested) {
|
|
92
92
|
console.error("no OAuth providers registered")
|
|
93
93
|
process.exit(1)
|
|
@@ -95,7 +95,7 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
95
95
|
const spec = findOAuthProvider(requested)
|
|
96
96
|
if (!spec) {
|
|
97
97
|
console.error(
|
|
98
|
-
`provider "${requested}" does not support OAuth. Available: ${OAUTH_PROVIDERS.map((p) => p.id).join(", ")}`,
|
|
98
|
+
`provider "${sanitizeAnsiLine(requested)}" does not support OAuth. Available: ${OAUTH_PROVIDERS.map((p) => p.id).join(", ")}`,
|
|
99
99
|
)
|
|
100
100
|
process.exit(1)
|
|
101
101
|
}
|
|
@@ -127,7 +127,7 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
127
127
|
},
|
|
128
128
|
})
|
|
129
129
|
process.stderr.write("\r \r")
|
|
130
|
-
console.log(`${c.green(
|
|
130
|
+
console.log(`${c.green("ok")} login successful`)
|
|
131
131
|
|
|
132
132
|
// Daftarkan provider bila belum ada. apiKey dibiarkan kosong: tokennya
|
|
133
133
|
// hidup di auth.json dan diambil saat runtime oleh buildProviderListAsync.
|
|
@@ -155,13 +155,13 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
155
155
|
{ global: true },
|
|
156
156
|
)
|
|
157
157
|
console.log(
|
|
158
|
-
`${c.green(
|
|
158
|
+
`${c.green("ok")} provider "${c.bold(spec.id)}" ready (${models.length} models)\n` +
|
|
159
159
|
` ${c.dim(`try: minicode --provider ${spec.id} "hello"`)}\n`,
|
|
160
160
|
)
|
|
161
161
|
process.exit(0)
|
|
162
162
|
} catch (e) {
|
|
163
163
|
process.stderr.write("\r \r")
|
|
164
|
-
console.error(
|
|
164
|
+
console.error(c.red(formatError(e)))
|
|
165
165
|
process.exit(1)
|
|
166
166
|
} finally {
|
|
167
167
|
process.off("SIGINT", onSigint)
|