minicode-ai 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/args.ts +120 -16
- package/cli/commands/acp.ts +38 -28
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +11 -12
- package/cli/commands/exec.ts +35 -73
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +73 -44
- package/cli/context-command-run.ts +30 -18
- package/cli/index.ts +48 -98
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +246 -123
- package/cli/tui.ts +303 -100
- package/docs/TERMINAL_CONTRACT.md +254 -69
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/environment.md +1 -2
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +2 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +119 -66
- package/src/app/tool-layer.ts +12 -17
- package/src/config.ts +64 -104
- package/src/constants.ts +4 -6
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +31 -8
- package/src/policy/context.ts +62 -36
- package/src/policy/executor.ts +17 -7
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/provision.ts +6 -56
- package/src/providers/responses.ts +1 -0
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +25 -58
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +20 -37
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +47 -23
- package/src/ui/i18n/id.ts +76 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +82 -61
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +154 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/cli/commands/sessions.ts
CHANGED
|
@@ -10,8 +10,10 @@ import {
|
|
|
10
10
|
loadSession,
|
|
11
11
|
purgeExpired,
|
|
12
12
|
} from "../../src/session/persistence.ts"
|
|
13
|
+
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
13
14
|
import { renderTable } from "../../src/ui/render/table.ts"
|
|
14
15
|
import { c } from "../../src/ui/render/theme.ts"
|
|
16
|
+
import { hasHelpFlag, positionalSubArg } from "../args.ts"
|
|
15
17
|
|
|
16
18
|
const SESSIONS_HELP = `minicode sessions — session history
|
|
17
19
|
|
|
@@ -19,11 +21,18 @@ const SESSIONS_HELP = `minicode sessions — session history
|
|
|
19
21
|
minicode sessions export <id> [--jsonl] export message history
|
|
20
22
|
minicode sessions purge remove expired sessions (TTL)`
|
|
21
23
|
|
|
24
|
+
const out = (msg: string): void => console.log(msg)
|
|
25
|
+
const err = (msg: string): void => console.error(msg)
|
|
26
|
+
|
|
22
27
|
export async function handleSessions(
|
|
23
28
|
args: string[],
|
|
24
29
|
getArg: (name: string) => string | undefined,
|
|
25
30
|
): Promise<never> {
|
|
26
31
|
const sub = args[1]
|
|
32
|
+
if (hasHelpFlag(args)) {
|
|
33
|
+
out(SESSIONS_HELP)
|
|
34
|
+
process.exit(0)
|
|
35
|
+
}
|
|
27
36
|
if (sub === "list" || !sub) {
|
|
28
37
|
const cwdArg = getArg("--cwd")
|
|
29
38
|
const rows = listSessions(cwdArg)
|
|
@@ -34,15 +43,15 @@ export async function handleSessions(
|
|
|
34
43
|
const usesLocal =
|
|
35
44
|
existsSync(resolve(base, ".minicode", "sessions.db")) ||
|
|
36
45
|
existsSync(resolve(base, ".minicode"))
|
|
37
|
-
if (!usesLocal)
|
|
38
|
-
if (rows.length === 0)
|
|
46
|
+
if (!usesLocal) out(c.dim(`(global scope — no local .minicode/sessions.db in ${base})`))
|
|
47
|
+
if (rows.length === 0) out(c.dim("(no recorded sessions yet)"))
|
|
39
48
|
else {
|
|
40
49
|
const tableData = rows.map((r) => ({
|
|
41
|
-
id: c.cyan(r.id),
|
|
50
|
+
id: c.cyan(sanitizeAnsiLine(r.id)),
|
|
42
51
|
date: new Date(r.created_at).toLocaleString(),
|
|
43
|
-
cwd: c.dim(r.cwd),
|
|
52
|
+
cwd: c.dim(sanitizeAnsiLine(r.cwd)),
|
|
44
53
|
}))
|
|
45
|
-
|
|
54
|
+
out(
|
|
46
55
|
`\n${c.bold("Recent Sessions")}\n` +
|
|
47
56
|
renderTable(
|
|
48
57
|
[
|
|
@@ -57,23 +66,21 @@ export async function handleSessions(
|
|
|
57
66
|
}
|
|
58
67
|
process.exit(0)
|
|
59
68
|
} else if (sub === "export") {
|
|
60
|
-
|
|
61
|
-
// memperlakukannya sebagai id menghasilkan pesan "sesi --cwd tidak ditemukan".
|
|
62
|
-
const id = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
|
|
69
|
+
const id = positionalSubArg(args, 2)
|
|
63
70
|
const asJsonl = args.includes("--jsonl")
|
|
64
71
|
if (!id) {
|
|
65
|
-
|
|
72
|
+
err("usage: minicode sessions export <id> [--jsonl]")
|
|
66
73
|
process.exit(2)
|
|
67
74
|
}
|
|
68
75
|
// P2.1 read-compat: alias eksak resolve ke kanonik; selain itu input
|
|
69
76
|
// apa adanya (lenien untuk baca; tulis tetap jalur kanonik tunggal).
|
|
70
77
|
const sess = loadSession(resolveSessionDisplayTarget(id, getArg("--cwd")), getArg("--cwd"))
|
|
71
78
|
if (!sess) {
|
|
72
|
-
|
|
79
|
+
err(`session "${sanitizeAnsiLine(id)}" not found - see: minicode sessions list`)
|
|
73
80
|
process.exit(1)
|
|
74
81
|
}
|
|
75
|
-
if (asJsonl) for (const m of sess.messages)
|
|
76
|
-
else
|
|
82
|
+
if (asJsonl) for (const m of sess.messages) out(JSON.stringify(m))
|
|
83
|
+
else out(JSON.stringify(sess, null, 2))
|
|
77
84
|
process.exit(0)
|
|
78
85
|
} else if (sub === "purge") {
|
|
79
86
|
const cwdArg = getArg("--cwd")
|
|
@@ -123,16 +130,15 @@ export async function handleSessions(
|
|
|
123
130
|
}
|
|
124
131
|
} catch {}
|
|
125
132
|
const ttl = getSessionTtlDays()
|
|
126
|
-
|
|
127
|
-
if (orphans > 0)
|
|
133
|
+
out(`[purge] removed ${removed} sessions (older than ${ttl} days)`)
|
|
134
|
+
if (orphans > 0) out(`[purge] removed ${orphans} orphan journals`)
|
|
128
135
|
} finally {
|
|
129
136
|
db.close()
|
|
130
137
|
}
|
|
131
138
|
process.exit(0)
|
|
132
139
|
} else {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
process.exit(asked ? 0 : 2)
|
|
140
|
+
err(`unknown sessions subcommand: ${sanitizeAnsiLine(sub)}\n`)
|
|
141
|
+
out(SESSIONS_HELP)
|
|
142
|
+
process.exit(2)
|
|
137
143
|
}
|
|
138
144
|
}
|
package/cli/commands/skills.ts
CHANGED
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
import { findSkill, loadSkills } from "../../src/skills/loader.ts"
|
|
2
|
+
import { sanitizeAnsi, sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
2
3
|
import { renderTable } from "../../src/ui/render/table.ts"
|
|
3
4
|
import { c } from "../../src/ui/render/theme.ts"
|
|
5
|
+
import { allowLocalSubcommand, hasHelpFlag, positionalSubArg } from "../args.ts"
|
|
4
6
|
|
|
5
7
|
const SKILLS_HELP = `minicode skills — markdown skills in .minicode/skills/*.md
|
|
6
8
|
|
|
7
|
-
minicode skills list list installed skills
|
|
8
|
-
minicode skills show <name> show one skill
|
|
9
|
+
minicode skills list [--allow-local-config] list installed skills
|
|
10
|
+
minicode skills show <name> [--allow-local-config] show one skill
|
|
9
11
|
|
|
10
12
|
In interactive mode, run a skill with /name [arguments].`
|
|
11
13
|
|
|
14
|
+
const out = (msg: string): void => console.log(msg)
|
|
15
|
+
const err = (msg: string): void => console.error(msg)
|
|
16
|
+
|
|
12
17
|
export async function handleSkills(
|
|
13
18
|
args: string[],
|
|
14
19
|
getArg: (name: string) => string | undefined,
|
|
15
20
|
): Promise<never> {
|
|
16
21
|
const cwdArg = getArg("--cwd")
|
|
22
|
+
const allowLocal = allowLocalSubcommand(args)
|
|
17
23
|
const sub = args[1]
|
|
24
|
+
if (hasHelpFlag(args)) {
|
|
25
|
+
out(SKILLS_HELP)
|
|
26
|
+
process.exit(0)
|
|
27
|
+
}
|
|
18
28
|
if (sub === "list" || sub === undefined) {
|
|
19
|
-
const all = await loadSkills(cwdArg)
|
|
29
|
+
const all = await loadSkills(cwdArg, { allowLocal })
|
|
20
30
|
if (all.length === 0) {
|
|
21
|
-
|
|
31
|
+
out(
|
|
32
|
+
c.dim(
|
|
33
|
+
allowLocal
|
|
34
|
+
? "(no skills yet - add markdown files in .minicode/skills/*.md)"
|
|
35
|
+
: "(no global skills - pass --allow-local-config to include project .minicode/skills)",
|
|
36
|
+
),
|
|
37
|
+
)
|
|
22
38
|
process.exit(0)
|
|
23
39
|
}
|
|
24
40
|
const tableData = all.map((s) => ({
|
|
25
|
-
skill: c.yellow(`/${s.name}`),
|
|
26
|
-
desc: s.description || "(no description)",
|
|
41
|
+
skill: c.yellow(`/${sanitizeAnsiLine(s.name)}`),
|
|
42
|
+
desc: sanitizeAnsiLine(s.description || "(no description)"),
|
|
27
43
|
}))
|
|
28
|
-
|
|
44
|
+
out(
|
|
29
45
|
`\n${c.bold("Installed Skills")}\n` +
|
|
30
46
|
renderTable(
|
|
31
47
|
[
|
|
@@ -39,23 +55,22 @@ export async function handleSkills(
|
|
|
39
55
|
process.exit(0)
|
|
40
56
|
}
|
|
41
57
|
if (sub === "show") {
|
|
42
|
-
|
|
43
|
-
// bukan permintaan skill bernama "--cwd".
|
|
44
|
-
const name = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
|
|
58
|
+
const name = positionalSubArg(args, 2)
|
|
45
59
|
if (!name) {
|
|
46
|
-
|
|
60
|
+
err("usage: minicode skills show <name>")
|
|
47
61
|
process.exit(2)
|
|
48
62
|
}
|
|
49
|
-
const s = await findSkill(name, cwdArg)
|
|
63
|
+
const s = await findSkill(name, cwdArg, { allowLocal })
|
|
50
64
|
if (!s) {
|
|
51
|
-
|
|
65
|
+
err(`skill "${sanitizeAnsiLine(name)}" not found - see: minicode skills list`)
|
|
52
66
|
process.exit(1)
|
|
53
67
|
}
|
|
54
|
-
|
|
68
|
+
out(
|
|
69
|
+
`${c.bold(c.cyan(`/${sanitizeAnsiLine(s.name)}`))} ${c.dim(`- ${sanitizeAnsiLine(s.description)}`)}\n\n${sanitizeAnsi(s.body)}`,
|
|
70
|
+
)
|
|
55
71
|
process.exit(0)
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
process.exit(asked ? 0 : 2)
|
|
73
|
+
err(`unknown skills subcommand: ${sanitizeAnsiLine(sub)}\n`)
|
|
74
|
+
out(SKILLS_HELP)
|
|
75
|
+
process.exit(2)
|
|
61
76
|
}
|
package/cli/commands/stats.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs"
|
|
2
1
|
import { resolve } from "node:path"
|
|
3
2
|
import type { RuntimeView } from "../../src/runtime/runtime-status.ts"
|
|
4
3
|
import { currentRuntimeView } from "../../src/runtime/runtime-status-provider.ts"
|
|
5
|
-
import { type StepTrace, summarizeStepTraces } from "../../src/telemetry/trace.ts"
|
|
4
|
+
import { readTraceRows, type StepTrace, summarizeStepTraces } from "../../src/telemetry/trace.ts"
|
|
6
5
|
import { c } from "../../src/ui/render/theme.ts"
|
|
6
|
+
import { guardSubcommand } from "../args.ts"
|
|
7
|
+
|
|
8
|
+
const STATS_HELP = `minicode stats — run & tool telemetry summary
|
|
9
|
+
|
|
10
|
+
minicode stats [--json] [--cwd <dir>]`
|
|
7
11
|
|
|
8
12
|
interface TraceRow {
|
|
9
13
|
ok?: boolean
|
|
@@ -30,23 +34,16 @@ function runtimeStatusSummary(view: RuntimeView): string {
|
|
|
30
34
|
return `phase=${view.phase} · admission=${view.admission} · health=${view.health} · termination=${view.termination} · bukti=${view.evidenceState} · kapabilitas=${caps} · anak-ter-supervisi=${view.supervisedChildren}${missing}${note}`
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export async function handleStats(
|
|
37
|
+
export async function handleStats(
|
|
38
|
+
getArg: (name: string) => string | undefined,
|
|
39
|
+
args: readonly string[] = [],
|
|
40
|
+
): Promise<never> {
|
|
41
|
+
guardSubcommand(args, "stats", STATS_HELP, console.log, console.error)
|
|
34
42
|
const cwdArg = getArg("--cwd")
|
|
35
|
-
const asJson =
|
|
43
|
+
const asJson =
|
|
44
|
+
getArg("--json") !== undefined || args.includes("--json") || process.argv.includes("--json")
|
|
36
45
|
const file = resolve(cwdArg ?? ".", ".minicode", "traces.jsonl")
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
traces = readFileSync(file, "utf8")
|
|
40
|
-
.split("\n")
|
|
41
|
-
.filter(Boolean)
|
|
42
|
-
.flatMap((l) => {
|
|
43
|
-
try {
|
|
44
|
-
return [JSON.parse(l) as TraceRow]
|
|
45
|
-
} catch {
|
|
46
|
-
return []
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
} catch {}
|
|
46
|
+
const traces = readTraceRows<TraceRow>(cwdArg, "traces.jsonl")
|
|
50
47
|
const total = traces.length
|
|
51
48
|
const ok = traces.filter((t) => t.ok).length
|
|
52
49
|
const inputTokens = traces.reduce((s, t) => s + (t.inputTokens ?? 0), 0)
|
|
@@ -56,19 +53,7 @@ export async function handleStats(getArg: (name: string) => string | undefined):
|
|
|
56
53
|
|
|
57
54
|
// Harness-P3: agregat step-trace (P1.2) — deny-rate, tool bermasalah,
|
|
58
55
|
// mode sandbox. Berkas tak ada/rusak = nol, bukan crash.
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
stepRows = readFileSync(resolve(cwdArg ?? ".", ".minicode", "step-traces.jsonl"), "utf8")
|
|
62
|
-
.split("\n")
|
|
63
|
-
.filter(Boolean)
|
|
64
|
-
.flatMap((l) => {
|
|
65
|
-
try {
|
|
66
|
-
return [JSON.parse(l) as StepTrace]
|
|
67
|
-
} catch {
|
|
68
|
-
return []
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
} catch {}
|
|
56
|
+
const stepRows = readTraceRows<StepTrace>(cwdArg, "step-traces.jsonl")
|
|
72
57
|
const steps = summarizeStepTraces(stepRows)
|
|
73
58
|
|
|
74
59
|
// [P13.1] Status runtime: dari model kanonik, bukan sumber status kedua.
|
package/cli/commands.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
1
2
|
import { basename, resolve as resolvePath } from "node:path"
|
|
2
3
|
import { loadConfig, saveLastModel } from "../src/config.ts"
|
|
3
4
|
import type { Usage } from "../src/policy/usage.ts"
|
|
4
5
|
import { refreshProviderModels } from "../src/providers/provision.ts"
|
|
5
6
|
import type { RuntimeProductionMode } from "../src/runtime/production-execution.ts"
|
|
7
|
+
import { resolveSessionDisplayTarget } from "../src/session/identity.ts"
|
|
6
8
|
import { listSessions, loadSession } from "../src/session/persistence.ts"
|
|
7
9
|
import type { Skill } from "../src/skills/loader.ts"
|
|
8
10
|
import type { ProductionSchedulerHandle } from "../src/task/production-scheduler.ts"
|
|
@@ -13,7 +15,7 @@ import {
|
|
|
13
15
|
import { type MsgKey, t } from "../src/ui/i18n/locale.ts"
|
|
14
16
|
import { formatUsd } from "../src/ui/render/money.ts"
|
|
15
17
|
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
16
|
-
import {
|
|
18
|
+
import { c } from "../src/ui/render/theme.ts"
|
|
17
19
|
import { padToWidth } from "../src/ui/render/width.ts"
|
|
18
20
|
|
|
19
21
|
// SEMUA output = PLAIN TEXT tanpa ANSI.
|
|
@@ -42,9 +44,9 @@ export interface CommandContext {
|
|
|
42
44
|
permissionMode?: string
|
|
43
45
|
setModelOverride: (model: string) => void
|
|
44
46
|
/** Dipanggil sebelum spawn anak stdio-inherit — composition root (cli/tui.ts)
|
|
45
|
-
* mengisinya untuk melepas terminal alt-screen + raw mode
|
|
46
|
-
* tetap jalan (no-op). */
|
|
47
|
-
onBeforeSpawn?: () => void
|
|
47
|
+
* mengisinya untuk melepas terminal alt-screen + raw mode dan menutup sesi induk.
|
|
48
|
+
* Tanpa injeksi tetap jalan (no-op). */
|
|
49
|
+
onBeforeSpawn?: () => void | Promise<void>
|
|
48
50
|
/** Kontrak control-plane (Phase 6): angka konteks SAAT INI dari sumber
|
|
49
51
|
* kebenaran kernel (estimateSessionContext) — bukan usage kumulatif.
|
|
50
52
|
* Dibedakan dari Input/Output/Total (provider usage) di /status. */
|
|
@@ -151,13 +153,20 @@ export const BUILTIN_COMMANDS: BuiltinCommand[] = [
|
|
|
151
153
|
* Opsi A audit UX: undo/redo/clear/copy/history tidak punya duplikat lain. */
|
|
152
154
|
export const DRIVER_HELP_COMMANDS: BuiltinCommand[] = [
|
|
153
155
|
{ name: "mode", args: "[name]", descKey: "help.desc.mode" },
|
|
154
|
-
{ name: "work-mode", args: "[DISCUSS|
|
|
156
|
+
{ name: "work-mode", args: "[DISCUSS|BUILD]", descKey: "help.desc.work-mode" },
|
|
155
157
|
{ name: "lang", args: "[en|id]", descKey: "help.desc.lang" },
|
|
156
158
|
{ name: "undo", descKey: "help.desc.undo" },
|
|
157
159
|
{ name: "redo", descKey: "help.desc.redo" },
|
|
158
160
|
{ name: "clear", descKey: "help.desc.clear" },
|
|
159
161
|
{ name: "copy", args: "[n]", descKey: "help.desc.copy" },
|
|
160
162
|
{ name: "history", descKey: "help.desc.history" },
|
|
163
|
+
// View commands ditangani driver TUI; terdaftar di sini agar `/help full`
|
|
164
|
+
// dan `/help` ringkas memakai permukaan yang SAMA (grup View tak kosong).
|
|
165
|
+
{ name: "compact", args: "[on|off]", descKey: "help.desc.compact" },
|
|
166
|
+
{ name: "thinking", args: "[on|off]", descKey: "help.desc.thinking" },
|
|
167
|
+
{ name: "expand", args: "[id]", descKey: "help.desc.expand" },
|
|
168
|
+
{ name: "minimize", args: "[on|off]", descKey: "help.desc.minimize" },
|
|
169
|
+
{ name: "fold", args: "[on|off]", descKey: "help.desc.fold" },
|
|
161
170
|
// [PHASE 6AB] Help-only, not in the dropdown: the scheduler is off in every
|
|
162
171
|
// default session, so advertising it in completion would put a command that
|
|
163
172
|
// always answers "not enabled" one keystroke away. It stays fully discoverable
|
|
@@ -230,13 +239,16 @@ function statusLines(ctx: CommandContext): string[] {
|
|
|
230
239
|
? ctx.currentModel.slice(0, ctx.currentModel.indexOf("::"))
|
|
231
240
|
: undefined
|
|
232
241
|
const provider = ctx.usage.modelUsed().provider ?? pinned ?? ctx.providerHint ?? "-"
|
|
242
|
+
// Nilai mode memakai bentuk produk yang sama dengan footer (title case):
|
|
243
|
+
// BUILD/AUTO di runtime, `Build`/`Auto` di layar.
|
|
244
|
+
const titleCase = (v: string): string => v.charAt(0).toUpperCase() + v.slice(1).toLowerCase()
|
|
233
245
|
return [
|
|
234
246
|
t("st.session", { id: ctx.sessionId }),
|
|
235
247
|
t("st.model", { v: ctx.currentModel ?? "default" }),
|
|
236
248
|
t("st.provider", { v: provider }),
|
|
237
249
|
t("st.tools", { v: ctx.toolsCount }),
|
|
238
|
-
t("st.workMode", { v: ctx.workMode ?? "DISCUSS" }),
|
|
239
|
-
t("st.permissionMode", { v: ctx.permissionMode ?? "auto" }),
|
|
250
|
+
t("st.workMode", { v: titleCase(ctx.workMode ?? "DISCUSS") }),
|
|
251
|
+
t("st.permissionMode", { v: titleCase(ctx.permissionMode ?? "auto") }),
|
|
240
252
|
t("st.context", { v: ctx.getContextTokens().toLocaleString() }),
|
|
241
253
|
t("st.turn", { v: last.totalTokens.toLocaleString() }),
|
|
242
254
|
t("st.input", { v: u.inputTokens.toLocaleString() }),
|
|
@@ -284,26 +296,33 @@ function printStatus(ctx: CommandContext): void {
|
|
|
284
296
|
* argumen langsung (`/sessions <id>`) dan pilihan picker popup.
|
|
285
297
|
* Return true bila anak di-spawn (false = sesi tak ditemukan, tanpa jejak). */
|
|
286
298
|
async function resumeById(target: string, ctx: CommandContext): Promise<boolean> {
|
|
287
|
-
const
|
|
299
|
+
const canonical = resolveSessionDisplayTarget(target, ctx.cwd)
|
|
300
|
+
const sess = loadSession(canonical, ctx.cwd)
|
|
288
301
|
if (!sess?.messages.length) {
|
|
289
|
-
console.log(t("sess.notFound", { id: target }))
|
|
302
|
+
console.log(t("sess.notFound", { id: sanitizeAnsiLine(target) }))
|
|
290
303
|
return false
|
|
291
304
|
}
|
|
292
|
-
// Anak stdio-inherit memakai terminal yang sama; App TUI sudah
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
ctx.onBeforeSpawn?.()
|
|
296
|
-
} catch {}
|
|
305
|
+
// Anak stdio-inherit memakai terminal yang sama; App TUI sudah melepas
|
|
306
|
+
// terminal + menutup lease sesi induk lewat onBeforeSpawn, dan fungsi ini
|
|
307
|
+
// menunggu anak selesai sebelum proses induk keluar (mencegah race app.resume).
|
|
297
308
|
const { spawn } = await import("node:child_process")
|
|
298
309
|
const { waitChildExit } = await import("./auto-update.ts")
|
|
310
|
+
try {
|
|
311
|
+
await ctx.onBeforeSpawn?.()
|
|
312
|
+
} catch {}
|
|
299
313
|
const entryPath = resolvePath(import.meta.dir, "index.ts")
|
|
300
314
|
const child = spawn(
|
|
301
315
|
process.execPath,
|
|
302
|
-
buildResumeSpawnArgs(entryPath,
|
|
316
|
+
buildResumeSpawnArgs(entryPath, canonical, ctx.cwd, ctx.runtimeMode, {
|
|
317
|
+
allowLocalConfig: ctx.allowLocalConfig,
|
|
318
|
+
ask: ctx.permissionMode?.toLowerCase() === "ask",
|
|
319
|
+
schedulerEnabled: ctx.scheduler?.handle.enabled === true,
|
|
320
|
+
}),
|
|
303
321
|
{ stdio: "inherit", env: { ...process.env, MINICODE_RESUME_NEW: "1" } },
|
|
304
322
|
)
|
|
305
|
-
void waitChildExit(child).then((code) => process.exit(code ?? 0))
|
|
306
323
|
process.stdin.pause()
|
|
324
|
+
const code = await waitChildExit(child)
|
|
325
|
+
process.exit(code ?? 0)
|
|
307
326
|
return true
|
|
308
327
|
}
|
|
309
328
|
|
|
@@ -320,12 +339,16 @@ export function buildResumeSpawnArgs(
|
|
|
320
339
|
target: string,
|
|
321
340
|
cwd: string | undefined,
|
|
322
341
|
runtimeMode: RuntimeProductionMode | undefined,
|
|
342
|
+
opts?: { allowLocalConfig?: boolean; ask?: boolean; schedulerEnabled?: boolean },
|
|
323
343
|
): string[] {
|
|
324
344
|
return [
|
|
325
345
|
entryPath,
|
|
326
346
|
`--resume=${target}`,
|
|
327
347
|
...(cwd ? [`--cwd=${cwd}`] : []),
|
|
328
348
|
...(runtimeMode ? ["--runtime", runtimeMode] : []),
|
|
349
|
+
...(opts?.allowLocalConfig ? ["--allow-local-config"] : []),
|
|
350
|
+
...(opts?.ask ? ["--ask"] : []),
|
|
351
|
+
...(opts?.schedulerEnabled ? ["--enable-scheduler"] : []),
|
|
329
352
|
]
|
|
330
353
|
}
|
|
331
354
|
|
|
@@ -522,8 +545,12 @@ export async function handleBuiltinCommand(
|
|
|
522
545
|
}
|
|
523
546
|
|
|
524
547
|
case "init": {
|
|
548
|
+
if (ctx.workMode === "DISCUSS") {
|
|
549
|
+
console.log(`\n${t("cmd.initInDiscuss")}\n`)
|
|
550
|
+
return { handled: true }
|
|
551
|
+
}
|
|
525
552
|
const target = resolvePath(ctx.cwd ?? process.cwd(), "AGENTS.md")
|
|
526
|
-
if (
|
|
553
|
+
if (existsSync(target)) {
|
|
527
554
|
console.log(`\n${t("cmd.initExists")}\n`)
|
|
528
555
|
return { handled: true }
|
|
529
556
|
}
|
|
@@ -532,16 +559,14 @@ export async function handleBuiltinCommand(
|
|
|
532
559
|
const body = [
|
|
533
560
|
"# AGENTS.md",
|
|
534
561
|
"",
|
|
535
|
-
"
|
|
562
|
+
t("cmd.initBodyDesc"),
|
|
536
563
|
"",
|
|
537
|
-
"
|
|
564
|
+
t("cmd.initBodyMap"),
|
|
538
565
|
"```",
|
|
539
|
-
map ?? "
|
|
566
|
+
map ?? t("cmd.initBodyEmpty"),
|
|
540
567
|
"```",
|
|
541
568
|
"",
|
|
542
|
-
"
|
|
543
|
-
"- Ikuti gaya kode existing.",
|
|
544
|
-
"- Jalankan typecheck/test sebelum selesai.",
|
|
569
|
+
t("cmd.initBodyConv"),
|
|
545
570
|
"",
|
|
546
571
|
].join("\n")
|
|
547
572
|
const { atomicWriteText } = await import("../src/lib/atomic-write.ts")
|
|
@@ -629,21 +654,32 @@ export async function handleBuiltinCommand(
|
|
|
629
654
|
// id provider datang dari probe jaringan (tak-terpercaya): paritas
|
|
630
655
|
// dengan `minicode providers sync` yang sudah menyaring ANSI.
|
|
631
656
|
for (const r of updated) {
|
|
632
|
-
|
|
657
|
+
// Status = kata + warna (bukan warna/glyph saja) agar terbaca juga
|
|
658
|
+
// saat NO_COLOR atau terminal tanpa UTF-8.
|
|
659
|
+
console.log(
|
|
660
|
+
` ${c.success(t("ts.statusCompleted"))} ${sanitizeAnsiLine(r.id)}: ${r.from} → ${r.to}`,
|
|
661
|
+
)
|
|
633
662
|
}
|
|
634
663
|
for (const f of failed) {
|
|
635
|
-
console.log(
|
|
664
|
+
console.log(
|
|
665
|
+
` ${c.error(t("ts.statusFailed"))} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`,
|
|
666
|
+
)
|
|
636
667
|
}
|
|
637
668
|
// "Restart" hanya jujur bila ADA model baru — tanpa updated, restart
|
|
638
669
|
// tak mengubah apa pun (sebelumnya selalu dicetak, menyesatkan saat
|
|
639
670
|
// semua provider gagal).
|
|
640
|
-
if (updated.length > 0)
|
|
641
|
-
|
|
671
|
+
if (updated.length > 0) {
|
|
672
|
+
const { reloadProviders } = await import("../src/app/provider-layer.ts")
|
|
673
|
+
await reloadProviders(ctx.cwd, { allowLocal: ctx.allowLocalConfig }).catch(() => {})
|
|
674
|
+
console.log(t("cmd.restart"))
|
|
675
|
+
} else console.log(t("cmd.nothingUpdated"))
|
|
642
676
|
}
|
|
643
677
|
return { handled: true }
|
|
644
678
|
}
|
|
645
679
|
|
|
680
|
+
case "resume":
|
|
646
681
|
case "sessions": {
|
|
682
|
+
if (cmd === "resume" && !args) return { handled: false }
|
|
647
683
|
const rows = listSessions(ctx.cwd).slice(0, 25)
|
|
648
684
|
if (rows.length === 0) {
|
|
649
685
|
console.log(`\n${t("cmd.noSessions")}`)
|
|
@@ -656,25 +692,31 @@ export async function handleBuiltinCommand(
|
|
|
656
692
|
// ID di DEPAN (truncasi memakan ekor — ekor berisi tanggal/cwd,
|
|
657
693
|
// id adalah info terpenting dan harus selamat).
|
|
658
694
|
const shortDir = (d: string): string => basename(d) || "(cwd)"
|
|
695
|
+
let pickedId: string | null = null
|
|
659
696
|
await runPicker({
|
|
660
697
|
title: t("sess.title"),
|
|
698
|
+
// Jendela command: judul konsisten dengan /model, /provider, dll.
|
|
699
|
+
showTitle: true,
|
|
661
700
|
items: rows.map((r) => ({
|
|
662
|
-
name: `${r.id} · ${new Date(r.created_at).toLocaleString()} · ${r.cwd ? shortDir(r.cwd) : "(cwd)"}`,
|
|
701
|
+
name: `${sanitizeAnsiLine(r.id)} · ${new Date(r.created_at).toLocaleString()} · ${r.cwd ? sanitizeAnsiLine(shortDir(r.cwd)) : "(cwd)"}`,
|
|
663
702
|
provider: "",
|
|
664
703
|
value: r.id,
|
|
665
704
|
})),
|
|
666
705
|
filterable: true,
|
|
667
706
|
onPick: (id) => {
|
|
668
|
-
|
|
707
|
+
pickedId = id
|
|
669
708
|
},
|
|
670
709
|
onCancel: () => {},
|
|
671
710
|
})
|
|
711
|
+
if (pickedId) await resumeById(pickedId, ctx)
|
|
672
712
|
return { handled: true }
|
|
673
713
|
}
|
|
674
714
|
console.log(`\n${t("sess.listHead")}`)
|
|
675
|
-
|
|
715
|
+
// Tanpa indeks: pemilihan selalu lewat id (`/sessions <id>`), jadi
|
|
716
|
+
// angka `[i]` hanya menawarkan affordance yang tidak bisa dipakai.
|
|
717
|
+
rows.forEach((r) => {
|
|
676
718
|
console.log(
|
|
677
|
-
`
|
|
719
|
+
` - ${sanitizeAnsiLine(r.id).padEnd(14)} ${new Date(r.created_at).toLocaleString().padEnd(24)} ${sanitizeAnsiLine(r.cwd || "(cwd)")}`,
|
|
678
720
|
)
|
|
679
721
|
})
|
|
680
722
|
console.log(t("sess.listHint"))
|
|
@@ -687,19 +729,6 @@ export async function handleBuiltinCommand(
|
|
|
687
729
|
return { handled: true }
|
|
688
730
|
}
|
|
689
731
|
|
|
690
|
-
case "resume": {
|
|
691
|
-
// Alias /sessions <id> (repl.md). Gagal-di-kode-lama: jatuh ke default
|
|
692
|
-
// → handled:false → sunyi total di TUI (tidak tercatat, tidak spawn).
|
|
693
|
-
if (!args) return { handled: false }
|
|
694
|
-
const rows = listSessions(ctx.cwd).slice(0, 25)
|
|
695
|
-
if (rows.length > 0) {
|
|
696
|
-
if (await resumeById(args, ctx)) console.log("")
|
|
697
|
-
return { handled: true }
|
|
698
|
-
}
|
|
699
|
-
console.log("")
|
|
700
|
-
return { handled: true }
|
|
701
|
-
}
|
|
702
|
-
|
|
703
732
|
default:
|
|
704
733
|
return { handled: false }
|
|
705
734
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// jalur satu-shot (yang tak pernah membuka `/context`) tidak membayar biaya
|
|
7
7
|
// modul ini. Alasan yang sama dipakai `/model` (`./model-manager.ts`).
|
|
8
8
|
|
|
9
|
-
import type { ProviderEntry } from "../src/config.ts"
|
|
10
|
-
import { loadConfig } from "../src/config.ts"
|
|
9
|
+
import type { MinicodeConfig, ProviderEntry } from "../src/config.ts"
|
|
10
|
+
import { hasProviderInLocalConfig, loadConfig } from "../src/config.ts"
|
|
11
11
|
import { resolveContextWindow } from "../src/policy/context-window.ts"
|
|
12
12
|
import { assignContextWindow } from "../src/policy/context-window-assign.ts"
|
|
13
13
|
import {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { t } from "../src/ui/i18n/locale.ts"
|
|
19
19
|
import { sanitizeAnsiLine } from "../src/ui/render/sanitize.ts"
|
|
20
20
|
import { renderTable } from "../src/ui/render/table.ts"
|
|
21
|
+
import { outputWindowWidth } from "../src/ui/screens/output-window.ts"
|
|
21
22
|
import type { CommandContext } from "./commands.ts"
|
|
22
23
|
import {
|
|
23
24
|
contextWindowRow,
|
|
@@ -26,11 +27,18 @@ import {
|
|
|
26
27
|
} from "./context-command.ts"
|
|
27
28
|
|
|
28
29
|
/** Baris `provider::model` aktif, diturunkan dari id yang dipakai sesi. */
|
|
29
|
-
function activeRef(
|
|
30
|
+
function activeRef(
|
|
31
|
+
ctx: CommandContext,
|
|
32
|
+
cfg?: MinicodeConfig,
|
|
33
|
+
): { provider: string; model: string } | undefined {
|
|
30
34
|
const id = ctx.currentModel
|
|
31
|
-
if (!id
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
/**
|
|
@@ -43,29 +51,36 @@ function activeRef(ctx: CommandContext): { provider: string; model: string } | u
|
|
|
43
51
|
*/
|
|
44
52
|
async function rowsFor(ctx: CommandContext): Promise<string[]> {
|
|
45
53
|
const cfg = await loadConfig(ctx.cwd, { allowLocal: ctx.allowLocalConfig })
|
|
46
|
-
const active = activeRef(ctx)
|
|
54
|
+
const active = activeRef(ctx, cfg)
|
|
47
55
|
const rows: { model: string; window: string; origin: string }[] = []
|
|
48
56
|
for (const p of cfg.providers) {
|
|
49
57
|
for (const model of p.models ?? []) {
|
|
50
58
|
const res = resolveContextWindow(cfg, `${p.id}::${model}`)
|
|
59
|
+
const row = contextWindowRow(model, res, describeContextWindow)
|
|
51
60
|
// Angka jendela = data operasional, nama model = input tak terpercaya
|
|
52
61
|
// (bisa datang dari /models jaringan): sanitasi keduanya sebelum tampil.
|
|
53
62
|
rows.push({
|
|
54
63
|
model: `${sanitizeAnsiLine(`${p.id}::${model}`)}${active && active.provider === p.id && active.model === model ? " *" : ""}`,
|
|
55
|
-
window: sanitizeAnsiLine(
|
|
56
|
-
origin: sanitizeAnsiLine(
|
|
64
|
+
window: sanitizeAnsiLine(row.window),
|
|
65
|
+
origin: sanitizeAnsiLine(row.origin),
|
|
57
66
|
})
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
if (!rows.length) return [t("ctx.empty")]
|
|
61
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))
|
|
62
77
|
return [
|
|
63
78
|
"",
|
|
64
79
|
renderTable(
|
|
65
80
|
[
|
|
66
|
-
{ header: head.model, key: "model", width:
|
|
67
|
-
{ header: head.window, key: "window", width:
|
|
68
|
-
{ header: head.origin, key: "origin", width:
|
|
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 },
|
|
69
84
|
],
|
|
70
85
|
rows,
|
|
71
86
|
),
|
|
@@ -81,9 +96,9 @@ async function rowsFor(ctx: CommandContext): Promise<string[]> {
|
|
|
81
96
|
* penanda — sehingga perilaku kembali persis ke rantai resolusi normal.
|
|
82
97
|
*/
|
|
83
98
|
async function save(ctx: CommandContext, input: string): Promise<string[]> {
|
|
84
|
-
const active = activeRef(ctx)
|
|
85
|
-
if (!active) return [`${t("ctx.saveFailed", { msg: "no active model — pick one with /model" })}`]
|
|
86
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" })}`]
|
|
87
102
|
const provider = cfg.providers.find((p) => p.id === active.provider)
|
|
88
103
|
if (!provider) return [`${t("ctx.saveFailed", { msg: `provider ${active.provider} not found` })}`]
|
|
89
104
|
|
|
@@ -107,10 +122,7 @@ async function save(ctx: CommandContext, input: string): Promise<string[]> {
|
|
|
107
122
|
// Provider lokal hanya terbaca bila sesi mengizinkannya (`--allow-local-config`)
|
|
108
123
|
// — tanpa opt-in kita tak boleh menyentuh berkas repo.
|
|
109
124
|
const inLocal =
|
|
110
|
-
!!ctx.allowLocalConfig &&
|
|
111
|
-
(await loadConfig(ctx.cwd, { allowLocal: true })).providers.some(
|
|
112
|
-
(p) => p.id === active.provider,
|
|
113
|
-
)
|
|
125
|
+
!!ctx.allowLocalConfig && (await hasProviderInLocalConfig(active.provider, ctx.cwd))
|
|
114
126
|
try {
|
|
115
127
|
await saveProvider(outcome.provider, {
|
|
116
128
|
...(inLocal ? { global: false, cwd: ctx.cwd ?? process.cwd() } : { global: true }),
|