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/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. */
|
|
@@ -134,6 +136,7 @@ export const BUILTIN_COMMANDS: BuiltinCommand[] = [
|
|
|
134
136
|
{ name: "help", descKey: "help.desc.help" },
|
|
135
137
|
{ name: "provider", descKey: "help.desc.provider" },
|
|
136
138
|
{ name: "model", descKey: "help.desc.model" },
|
|
139
|
+
{ name: "context", descKey: "help.desc.context" },
|
|
137
140
|
{ name: "sync", descKey: "help.desc.sync" },
|
|
138
141
|
{ name: "status", descKey: "help.desc.status" },
|
|
139
142
|
{ name: "sessions", descKey: "help.desc.sessions" },
|
|
@@ -150,13 +153,20 @@ export const BUILTIN_COMMANDS: BuiltinCommand[] = [
|
|
|
150
153
|
* Opsi A audit UX: undo/redo/clear/copy/history tidak punya duplikat lain. */
|
|
151
154
|
export const DRIVER_HELP_COMMANDS: BuiltinCommand[] = [
|
|
152
155
|
{ name: "mode", args: "[name]", descKey: "help.desc.mode" },
|
|
153
|
-
{ name: "work-mode", args: "[DISCUSS|
|
|
156
|
+
{ name: "work-mode", args: "[DISCUSS|BUILD]", descKey: "help.desc.work-mode" },
|
|
154
157
|
{ name: "lang", args: "[en|id]", descKey: "help.desc.lang" },
|
|
155
158
|
{ name: "undo", descKey: "help.desc.undo" },
|
|
156
159
|
{ name: "redo", descKey: "help.desc.redo" },
|
|
157
160
|
{ name: "clear", descKey: "help.desc.clear" },
|
|
158
161
|
{ name: "copy", args: "[n]", descKey: "help.desc.copy" },
|
|
159
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" },
|
|
160
170
|
// [PHASE 6AB] Help-only, not in the dropdown: the scheduler is off in every
|
|
161
171
|
// default session, so advertising it in completion would put a command that
|
|
162
172
|
// always answers "not enabled" one keystroke away. It stays fully discoverable
|
|
@@ -167,13 +177,17 @@ export const DRIVER_HELP_COMMANDS: BuiltinCommand[] = [
|
|
|
167
177
|
/** Grup kurasi untuk /help: kategori semantik (bukan urutan registrasi). Dipakai
|
|
168
178
|
* render full help supaya mudah dipindai; nama di sini harus 1:1 dengan isi
|
|
169
179
|
* BUILTIN_COMMANDS + DRIVER_HELP_COMMANDS. */
|
|
170
|
-
const HELP_GROUPS: readonly { key: MsgKey; names: readonly string[] }[] = [
|
|
180
|
+
export const HELP_GROUPS: readonly { key: MsgKey; names: readonly string[] }[] = [
|
|
171
181
|
{
|
|
172
182
|
key: "help.gGeneral",
|
|
173
183
|
names: ["help", "status", "sessions", "history", "clear", "copy", "init", "exit"],
|
|
174
184
|
},
|
|
175
|
-
{ key: "help.gModel", names: ["model", "provider", "sync"] },
|
|
185
|
+
{ key: "help.gModel", names: ["model", "context", "provider", "sync"] },
|
|
176
186
|
{ key: "help.gMode", names: ["mode", "work-mode", "undo", "redo", "lang"] },
|
|
187
|
+
{
|
|
188
|
+
key: "help.gView",
|
|
189
|
+
names: ["compact", "thinking", "expand", "minimize", "fold"],
|
|
190
|
+
},
|
|
177
191
|
{ key: "help.gTask", names: ["scheduler"] },
|
|
178
192
|
]
|
|
179
193
|
|
|
@@ -225,13 +239,16 @@ function statusLines(ctx: CommandContext): string[] {
|
|
|
225
239
|
? ctx.currentModel.slice(0, ctx.currentModel.indexOf("::"))
|
|
226
240
|
: undefined
|
|
227
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()
|
|
228
245
|
return [
|
|
229
246
|
t("st.session", { id: ctx.sessionId }),
|
|
230
247
|
t("st.model", { v: ctx.currentModel ?? "default" }),
|
|
231
248
|
t("st.provider", { v: provider }),
|
|
232
249
|
t("st.tools", { v: ctx.toolsCount }),
|
|
233
|
-
t("st.workMode", { v: ctx.workMode ?? "DISCUSS" }),
|
|
234
|
-
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") }),
|
|
235
252
|
t("st.context", { v: ctx.getContextTokens().toLocaleString() }),
|
|
236
253
|
t("st.turn", { v: last.totalTokens.toLocaleString() }),
|
|
237
254
|
t("st.input", { v: u.inputTokens.toLocaleString() }),
|
|
@@ -279,26 +296,33 @@ function printStatus(ctx: CommandContext): void {
|
|
|
279
296
|
* argumen langsung (`/sessions <id>`) dan pilihan picker popup.
|
|
280
297
|
* Return true bila anak di-spawn (false = sesi tak ditemukan, tanpa jejak). */
|
|
281
298
|
async function resumeById(target: string, ctx: CommandContext): Promise<boolean> {
|
|
282
|
-
const
|
|
299
|
+
const canonical = resolveSessionDisplayTarget(target, ctx.cwd)
|
|
300
|
+
const sess = loadSession(canonical, ctx.cwd)
|
|
283
301
|
if (!sess?.messages.length) {
|
|
284
|
-
console.log(t("sess.notFound", { id: target }))
|
|
302
|
+
console.log(t("sess.notFound", { id: sanitizeAnsiLine(target) }))
|
|
285
303
|
return false
|
|
286
304
|
}
|
|
287
|
-
// Anak stdio-inherit memakai terminal yang sama; App TUI sudah
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
ctx.onBeforeSpawn?.()
|
|
291
|
-
} 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).
|
|
292
308
|
const { spawn } = await import("node:child_process")
|
|
293
309
|
const { waitChildExit } = await import("./auto-update.ts")
|
|
310
|
+
try {
|
|
311
|
+
await ctx.onBeforeSpawn?.()
|
|
312
|
+
} catch {}
|
|
294
313
|
const entryPath = resolvePath(import.meta.dir, "index.ts")
|
|
295
314
|
const child = spawn(
|
|
296
315
|
process.execPath,
|
|
297
|
-
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
|
+
}),
|
|
298
321
|
{ stdio: "inherit", env: { ...process.env, MINICODE_RESUME_NEW: "1" } },
|
|
299
322
|
)
|
|
300
|
-
void waitChildExit(child).then((code) => process.exit(code ?? 0))
|
|
301
323
|
process.stdin.pause()
|
|
324
|
+
const code = await waitChildExit(child)
|
|
325
|
+
process.exit(code ?? 0)
|
|
302
326
|
return true
|
|
303
327
|
}
|
|
304
328
|
|
|
@@ -315,12 +339,16 @@ export function buildResumeSpawnArgs(
|
|
|
315
339
|
target: string,
|
|
316
340
|
cwd: string | undefined,
|
|
317
341
|
runtimeMode: RuntimeProductionMode | undefined,
|
|
342
|
+
opts?: { allowLocalConfig?: boolean; ask?: boolean; schedulerEnabled?: boolean },
|
|
318
343
|
): string[] {
|
|
319
344
|
return [
|
|
320
345
|
entryPath,
|
|
321
346
|
`--resume=${target}`,
|
|
322
347
|
...(cwd ? [`--cwd=${cwd}`] : []),
|
|
323
348
|
...(runtimeMode ? ["--runtime", runtimeMode] : []),
|
|
349
|
+
...(opts?.allowLocalConfig ? ["--allow-local-config"] : []),
|
|
350
|
+
...(opts?.ask ? ["--ask"] : []),
|
|
351
|
+
...(opts?.schedulerEnabled ? ["--enable-scheduler"] : []),
|
|
324
352
|
]
|
|
325
353
|
}
|
|
326
354
|
|
|
@@ -517,8 +545,12 @@ export async function handleBuiltinCommand(
|
|
|
517
545
|
}
|
|
518
546
|
|
|
519
547
|
case "init": {
|
|
548
|
+
if (ctx.workMode === "DISCUSS") {
|
|
549
|
+
console.log(`\n${t("cmd.initInDiscuss")}\n`)
|
|
550
|
+
return { handled: true }
|
|
551
|
+
}
|
|
520
552
|
const target = resolvePath(ctx.cwd ?? process.cwd(), "AGENTS.md")
|
|
521
|
-
if (
|
|
553
|
+
if (existsSync(target)) {
|
|
522
554
|
console.log(`\n${t("cmd.initExists")}\n`)
|
|
523
555
|
return { handled: true }
|
|
524
556
|
}
|
|
@@ -527,16 +559,14 @@ export async function handleBuiltinCommand(
|
|
|
527
559
|
const body = [
|
|
528
560
|
"# AGENTS.md",
|
|
529
561
|
"",
|
|
530
|
-
"
|
|
562
|
+
t("cmd.initBodyDesc"),
|
|
531
563
|
"",
|
|
532
|
-
"
|
|
564
|
+
t("cmd.initBodyMap"),
|
|
533
565
|
"```",
|
|
534
|
-
map ?? "
|
|
566
|
+
map ?? t("cmd.initBodyEmpty"),
|
|
535
567
|
"```",
|
|
536
568
|
"",
|
|
537
|
-
"
|
|
538
|
-
"- Ikuti gaya kode existing.",
|
|
539
|
-
"- Jalankan typecheck/test sebelum selesai.",
|
|
569
|
+
t("cmd.initBodyConv"),
|
|
540
570
|
"",
|
|
541
571
|
].join("\n")
|
|
542
572
|
const { atomicWriteText } = await import("../src/lib/atomic-write.ts")
|
|
@@ -589,6 +619,22 @@ export async function handleBuiltinCommand(
|
|
|
589
619
|
return { handled: true }
|
|
590
620
|
}
|
|
591
621
|
|
|
622
|
+
case "context": {
|
|
623
|
+
// `/context` = bagian "temukan" dari fitur jendela konteks manual. Tanpa
|
|
624
|
+
// entri di /help dan dropdown, fitur ini praktis tidak ada (temuan audit:
|
|
625
|
+
// pengguna tidak menemukannya sama sekali). Tanpa argumen = tabel angka
|
|
626
|
+
// EFEKTIF (rantai resolusi yang sama dengan router, bukan hitungan ulang);
|
|
627
|
+
// dengan argumen = setel untuk model aktif.
|
|
628
|
+
const { applyContextWindowArg, formatContextOutput } = await import(
|
|
629
|
+
"./context-command-run.ts"
|
|
630
|
+
)
|
|
631
|
+
// Satu penulis untuk seluruh blok: inventaris writer (OAP-008) menghitung
|
|
632
|
+
// pemanggilan tulis per berkas, jadi perakitan string dilakukan di modul
|
|
633
|
+
// perintah, bukan di sini.
|
|
634
|
+
console.log(formatContextOutput(await applyContextWindowArg(args, ctx)))
|
|
635
|
+
return { handled: true }
|
|
636
|
+
}
|
|
637
|
+
|
|
592
638
|
case "sync": {
|
|
593
639
|
// Re-detect model dari semua provider -> config diperbarui otomatis.
|
|
594
640
|
// Meneruskan flag local sesi: tanpa opt-in /sync tak boleh menghubungi
|
|
@@ -608,21 +654,32 @@ export async function handleBuiltinCommand(
|
|
|
608
654
|
// id provider datang dari probe jaringan (tak-terpercaya): paritas
|
|
609
655
|
// dengan `minicode providers sync` yang sudah menyaring ANSI.
|
|
610
656
|
for (const r of updated) {
|
|
611
|
-
|
|
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
|
+
)
|
|
612
662
|
}
|
|
613
663
|
for (const f of failed) {
|
|
614
|
-
console.log(
|
|
664
|
+
console.log(
|
|
665
|
+
` ${c.error(t("ts.statusFailed"))} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`,
|
|
666
|
+
)
|
|
615
667
|
}
|
|
616
668
|
// "Restart" hanya jujur bila ADA model baru — tanpa updated, restart
|
|
617
669
|
// tak mengubah apa pun (sebelumnya selalu dicetak, menyesatkan saat
|
|
618
670
|
// semua provider gagal).
|
|
619
|
-
if (updated.length > 0)
|
|
620
|
-
|
|
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"))
|
|
621
676
|
}
|
|
622
677
|
return { handled: true }
|
|
623
678
|
}
|
|
624
679
|
|
|
680
|
+
case "resume":
|
|
625
681
|
case "sessions": {
|
|
682
|
+
if (cmd === "resume" && !args) return { handled: false }
|
|
626
683
|
const rows = listSessions(ctx.cwd).slice(0, 25)
|
|
627
684
|
if (rows.length === 0) {
|
|
628
685
|
console.log(`\n${t("cmd.noSessions")}`)
|
|
@@ -635,25 +692,31 @@ export async function handleBuiltinCommand(
|
|
|
635
692
|
// ID di DEPAN (truncasi memakan ekor — ekor berisi tanggal/cwd,
|
|
636
693
|
// id adalah info terpenting dan harus selamat).
|
|
637
694
|
const shortDir = (d: string): string => basename(d) || "(cwd)"
|
|
695
|
+
let pickedId: string | null = null
|
|
638
696
|
await runPicker({
|
|
639
697
|
title: t("sess.title"),
|
|
698
|
+
// Jendela command: judul konsisten dengan /model, /provider, dll.
|
|
699
|
+
showTitle: true,
|
|
640
700
|
items: rows.map((r) => ({
|
|
641
|
-
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)"}`,
|
|
642
702
|
provider: "",
|
|
643
703
|
value: r.id,
|
|
644
704
|
})),
|
|
645
705
|
filterable: true,
|
|
646
706
|
onPick: (id) => {
|
|
647
|
-
|
|
707
|
+
pickedId = id
|
|
648
708
|
},
|
|
649
709
|
onCancel: () => {},
|
|
650
710
|
})
|
|
711
|
+
if (pickedId) await resumeById(pickedId, ctx)
|
|
651
712
|
return { handled: true }
|
|
652
713
|
}
|
|
653
714
|
console.log(`\n${t("sess.listHead")}`)
|
|
654
|
-
|
|
715
|
+
// Tanpa indeks: pemilihan selalu lewat id (`/sessions <id>`), jadi
|
|
716
|
+
// angka `[i]` hanya menawarkan affordance yang tidak bisa dipakai.
|
|
717
|
+
rows.forEach((r) => {
|
|
655
718
|
console.log(
|
|
656
|
-
`
|
|
719
|
+
` - ${sanitizeAnsiLine(r.id).padEnd(14)} ${new Date(r.created_at).toLocaleString().padEnd(24)} ${sanitizeAnsiLine(r.cwd || "(cwd)")}`,
|
|
657
720
|
)
|
|
658
721
|
})
|
|
659
722
|
console.log(t("sess.listHint"))
|
|
@@ -666,19 +729,6 @@ export async function handleBuiltinCommand(
|
|
|
666
729
|
return { handled: true }
|
|
667
730
|
}
|
|
668
731
|
|
|
669
|
-
case "resume": {
|
|
670
|
-
// Alias /sessions <id> (repl.md). Gagal-di-kode-lama: jatuh ke default
|
|
671
|
-
// → handled:false → sunyi total di TUI (tidak tercatat, tidak spawn).
|
|
672
|
-
if (!args) return { handled: false }
|
|
673
|
-
const rows = listSessions(ctx.cwd).slice(0, 25)
|
|
674
|
-
if (rows.length > 0) {
|
|
675
|
-
if (await resumeById(args, ctx)) console.log("")
|
|
676
|
-
return { handled: true }
|
|
677
|
-
}
|
|
678
|
-
console.log("")
|
|
679
|
-
return { handled: true }
|
|
680
|
-
}
|
|
681
|
-
|
|
682
732
|
default:
|
|
683
733
|
return { handled: false }
|
|
684
734
|
}
|