minicode-ai 0.27.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +1 -1
  2. package/cli/args.ts +184 -57
  3. package/cli/bootstrap/presentation-bridge.ts +383 -0
  4. package/cli/commands/acp.ts +45 -29
  5. package/cli/commands/auth.ts +17 -17
  6. package/cli/commands/config.ts +65 -66
  7. package/cli/commands/daemon.ts +44 -16
  8. package/cli/commands/doctor.ts +18 -15
  9. package/cli/commands/exec.ts +41 -89
  10. package/cli/commands/mcp.ts +25 -8
  11. package/cli/commands/memory.ts +16 -24
  12. package/cli/commands/openwork.ts +6 -2
  13. package/cli/commands/pricing.ts +14 -12
  14. package/cli/commands/providers.ts +36 -57
  15. package/cli/commands/sessions.ts +24 -18
  16. package/cli/commands/skills.ts +33 -18
  17. package/cli/commands/stats.ts +15 -30
  18. package/cli/commands.ts +73 -44
  19. package/cli/context-command-run.ts +30 -18
  20. package/cli/index.ts +51 -100
  21. package/cli/model-manager.ts +7 -2
  22. package/cli/provider-manager.ts +33 -18
  23. package/cli/router.ts +41 -12
  24. package/cli/setup.ts +241 -485
  25. package/cli/tui.ts +303 -100
  26. package/docs/TERMINAL_CONTRACT.md +258 -73
  27. package/docs/UI_RENDER_PIPELINE.md +9 -1
  28. package/docs/agents.md +2 -2
  29. package/docs/architecture.md +17 -32
  30. package/docs/choosing-mode.md +7 -9
  31. package/docs/cli.md +3 -5
  32. package/docs/environment.md +1 -2
  33. package/docs/policy-sandbox.md +3 -3
  34. package/docs/repl.md +2 -2
  35. package/docs/tools.md +1 -1
  36. package/package.json +1 -1
  37. package/src/app/mentions.ts +60 -13
  38. package/src/app/rag-layer.ts +17 -20
  39. package/src/app/session.ts +144 -68
  40. package/src/app/tool-layer.ts +38 -16
  41. package/src/config.ts +64 -104
  42. package/src/constants.ts +4 -6
  43. package/src/daemon/capability.ts +8 -1
  44. package/src/daemon/control.ts +3 -2
  45. package/src/daemon/server.ts +57 -0
  46. package/src/hooks/run.ts +73 -41
  47. package/src/lib/atomic-write.ts +31 -59
  48. package/src/lib/db-path.ts +47 -0
  49. package/src/lib/process-tree.ts +62 -0
  50. package/src/lib/public-http.ts +88 -23
  51. package/src/lib/trusted-exec.ts +48 -1
  52. package/src/lsp/client.ts +62 -17
  53. package/src/mcp/client.ts +85 -38
  54. package/src/mcp/http-transport.ts +28 -16
  55. package/src/mcp/transport.ts +42 -6
  56. package/src/memory/files.ts +164 -134
  57. package/src/memory/vector.ts +371 -420
  58. package/src/policy/approval-binding.ts +122 -45
  59. package/src/policy/bash-guard.ts +18 -7
  60. package/src/policy/compaction.ts +51 -18
  61. package/src/policy/context-window.ts +31 -8
  62. package/src/policy/context.ts +62 -36
  63. package/src/policy/executor.ts +17 -7
  64. package/src/policy/jail.ts +6 -8
  65. package/src/policy/microcompact.ts +4 -3
  66. package/src/policy/no-progress.ts +103 -22
  67. package/src/policy/permission.ts +36 -12
  68. package/src/policy/tool-contract.ts +74 -416
  69. package/src/policy/usage.ts +24 -2
  70. package/src/policy/verifier.ts +50 -2
  71. package/src/policy/work-mode.ts +28 -54
  72. package/src/presentation/adapter.ts +24 -16
  73. package/src/providers/anthropic.ts +16 -5
  74. package/src/providers/provision.ts +6 -56
  75. package/src/providers/responses.ts +38 -7
  76. package/src/providers/sse-bounds.ts +6 -4
  77. package/src/runtime/execution-journal.ts +4 -29
  78. package/src/sandbox/docker.ts +58 -34
  79. package/src/sandbox/mask.ts +157 -0
  80. package/src/sandbox/os.ts +107 -73
  81. package/src/session/authority.ts +29 -10
  82. package/src/session/context-projection.ts +6 -5
  83. package/src/session/db/runs.ts +397 -0
  84. package/src/session/db/schema.ts +358 -0
  85. package/src/session/open-work.ts +26 -3
  86. package/src/session/persistence.ts +74 -998
  87. package/src/session/verification.ts +170 -20
  88. package/src/skills/loader.ts +31 -16
  89. package/src/task/db/schema.ts +325 -0
  90. package/src/task/db/types.ts +269 -0
  91. package/src/task/production-scheduler.ts +13 -1
  92. package/src/task/store.ts +92 -1021
  93. package/src/telemetry/trace.ts +27 -0
  94. package/src/tools/ask_user.ts +1 -13
  95. package/src/tools/bash.ts +27 -92
  96. package/src/tools/code_run.ts +1 -1
  97. package/src/tools/context.ts +133 -0
  98. package/src/tools/delete_file.ts +3 -2
  99. package/src/tools/edit.ts +37 -72
  100. package/src/tools/git.ts +86 -9
  101. package/src/tools/glob.ts +26 -51
  102. package/src/tools/grep.ts +67 -57
  103. package/src/tools/hashline.ts +4 -0
  104. package/src/tools/lsp.ts +11 -8
  105. package/src/tools/mcp_call.ts +9 -6
  106. package/src/tools/memory.ts +56 -33
  107. package/src/tools/move_file.ts +36 -10
  108. package/src/tools/patch.ts +13 -21
  109. package/src/tools/read_file.ts +18 -25
  110. package/src/tools/read_image.ts +35 -33
  111. package/src/tools/submit_result.ts +29 -8
  112. package/src/tools/task.ts +74 -17
  113. package/src/tools/todo.ts +181 -74
  114. package/src/tools/web_fetch.ts +42 -2
  115. package/src/tools/web_search.ts +47 -8
  116. package/src/ui/approval/prompt.ts +206 -47
  117. package/src/ui/assistant/turn-status.ts +14 -5
  118. package/src/ui/footer.ts +4 -4
  119. package/src/ui/i18n/en.ts +47 -23
  120. package/src/ui/i18n/id.ts +76 -51
  121. package/src/ui/input/input.ts +4 -3
  122. package/src/ui/input/prompt-engine.ts +35 -5
  123. package/src/ui/render/activity-panel.ts +4 -2
  124. package/src/ui/render/hint.ts +7 -4
  125. package/src/ui/render/list.ts +32 -0
  126. package/src/ui/render/markdown.ts +6 -3
  127. package/src/ui/render/notice.ts +19 -0
  128. package/src/ui/render/table-grid.ts +7 -8
  129. package/src/ui/render/theme.ts +113 -39
  130. package/src/ui/runtime/screen.ts +74 -10
  131. package/src/ui/runtime/spinner.ts +19 -6
  132. package/src/ui/screens/dialog.ts +19 -1
  133. package/src/ui/screens/form.ts +80 -35
  134. package/src/ui/screens/model-manager.ts +82 -61
  135. package/src/ui/screens/output-window.ts +263 -0
  136. package/src/ui/screens/picker.ts +94 -81
  137. package/src/ui/screens/provider-manager.ts +100 -69
  138. package/src/ui/screens/wizard.ts +117 -28
  139. package/src/ui/tui/app.ts +196 -33
  140. package/src/ui/tui/transcript.ts +158 -25
  141. package/vendor/minicore/src/core/executor.ts +2 -0
  142. package/vendor/minicore/src/core/loop.ts +17 -6
  143. package/vendor/minicore/src/core/session.ts +3 -0
  144. package/vendor/minicore/src/core/tool.ts +1 -0
  145. package/vendor/minicore/src/providers/openai-compat.ts +35 -19
@@ -1,10 +1,16 @@
1
- import { readFileSync } from "node:fs"
2
- import { resolve } from "node:path"
3
1
  import { loadConfig, type MinicodeConfig } from "../../src/config.ts"
4
2
  import { refreshProviderModels } from "../../src/providers/provision.ts"
3
+ import { readTraceRows } from "../../src/telemetry/trace.ts"
5
4
  import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
6
5
  import { renderTable } from "../../src/ui/render/table.ts"
7
- import { c, glyphs } from "../../src/ui/render/theme.ts"
6
+ import { c } from "../../src/ui/render/theme.ts"
7
+ import { allowLocalSubcommand, guardSubcommand, positionalSubArg } from "../args.ts"
8
+
9
+ const PROVIDERS_HELP = `minicode providers | models | sync — inspect & refresh configured LLM providers
10
+
11
+ minicode providers [--allow-local-config] [--cwd <dir>]
12
+ minicode models [provider] [--match <q>] [--allow-local-config] [--cwd <dir>]
13
+ minicode sync [--allow-local-config] [--cwd <dir>]`
8
14
 
9
15
  interface TraceRow {
10
16
  model?: string
@@ -13,23 +19,8 @@ interface TraceRow {
13
19
  timestamp?: string
14
20
  }
15
21
 
16
- // 6.3 — health tanpa jaringan: ambil dari traces.jsonl (last run per provider)
17
- function readTraces(cwd?: string): TraceRow[] {
18
- try {
19
- return readFileSync(resolve(cwd ?? ".", ".minicode", "traces.jsonl"), "utf8")
20
- .split("\n")
21
- .filter(Boolean)
22
- .flatMap((l) => {
23
- try {
24
- return [JSON.parse(l) as TraceRow]
25
- } catch {
26
- return []
27
- }
28
- })
29
- } catch {
30
- return []
31
- }
32
- }
22
+ const out = (msg: string): void => console.log(msg)
23
+ const err = (msg: string): void => console.error(msg)
33
24
 
34
25
  export function providerOfTrace(cfg: MinicodeConfig, t: TraceRow): string | undefined {
35
26
  const m = t.model ?? ""
@@ -64,23 +55,20 @@ export async function handleProviders(
64
55
  if (firstArg !== "providers" && firstArg !== "models" && firstArg !== "sync") {
65
56
  process.exit(0)
66
57
  }
58
+ guardSubcommand(args, firstArg, PROVIDERS_HELP, out, err, firstArg === "models" ? -1 : 1)
67
59
  const cwdArg = getArg("--cwd")
68
60
  // Audit #07: local hanya bila operator opt-in (aturan universal — sync
69
- // tanpa flag tak boleh menghubungi endpoint repo tak dikenal). argv
70
- // subcommand diawali positional sehingga pakai includes + env (gaya --local).
71
- const allowLocal =
72
- args.includes("--allow-local-config") || process.env.MINICODE_ALLOW_LOCAL_CONFIG === "1"
61
+ // tanpa flag tak boleh menghubungi endpoint repo tak dikenal).
62
+ const allowLocal = allowLocalSubcommand(args)
73
63
  const cfg = await loadConfig(cwdArg, { allowLocal })
74
64
  if (firstArg === "providers") {
75
65
  if (cfg.providers.length === 0) {
76
- console.log(
66
+ out(
77
67
  "(no providers yet - run `minicode` for the wizard, `minicode auth login` (free, no API key),\nor `minicode config add --baseUrl <url> --apiKey <key>`)",
78
68
  )
79
69
  process.exit(0)
80
70
  }
81
- // renderTable menjaga kolom tetap berbaris untuk id sepanjang apa pun;
82
- // padEnd(16) manual sebelumnya rusak begitu id lebih dari 16 karakter.
83
- const health = healthMap(cfg, readTraces(cwdArg))
71
+ const health = healthMap(cfg, readTraceRows<TraceRow>(cwdArg, "traces.jsonl"))
84
72
  const rows = cfg.providers.map((p) => {
85
73
  const h = health.get(p.id)
86
74
  const status = !h
@@ -89,13 +77,13 @@ export async function handleProviders(
89
77
  h.ts ? new Date(h.ts).toISOString().slice(0, 10) : "-",
90
78
  )}`
91
79
  return {
92
- id: c.cyan(p.id),
80
+ id: c.cyan(sanitizeAnsiLine(p.id)),
93
81
  models: String(p.models.length),
94
- url: p.baseUrl,
82
+ url: sanitizeAnsiLine(p.baseUrl),
95
83
  status,
96
84
  }
97
85
  })
98
- console.log(
86
+ out(
99
87
  `\n${c.bold("LLM Providers")}\n` +
100
88
  renderTable(
101
89
  [
@@ -108,63 +96,54 @@ export async function handleProviders(
108
96
  ) +
109
97
  "\n",
110
98
  )
111
- console.log(
99
+ out(
112
100
  ` ${c.dim("next: minicode models | minicode sync | minicode config add --baseUrl <url> --apiKey <key>")}\n`,
113
101
  )
114
102
  process.exit(0)
115
103
  }
116
104
  if (firstArg === "models") {
117
- const pid = args[1] && !args[1]!.startsWith("--") ? args[1] : undefined
118
- const matchIdx = args.indexOf("--match")
119
- const filter = (matchIdx >= 0 && args[matchIdx + 1] ? args[matchIdx + 1]! : "").toLowerCase()
105
+ const pid = positionalSubArg(args, 1)
106
+ const filter = (getArg("--match") ?? "").toLowerCase()
120
107
  const match = (s: string) => (filter ? s.toLowerCase().includes(filter) : true)
121
108
  if (pid) {
122
109
  const p = cfg.providers.find((x) => x.id === pid)
123
110
  if (!p) {
124
- console.error(`provider "${sanitizeAnsiLine(pid)}" not found - see: minicode providers`)
111
+ err(`provider "${sanitizeAnsiLine(pid)}" not found - see: minicode providers`)
125
112
  process.exit(1)
126
113
  }
127
114
  const list = p.models.filter(match)
128
- if (!list.length) console.log(` (no matches for "${sanitizeAnsiLine(filter)}")`)
129
- for (const [i, m] of list.entries()) console.log(` [${i}] ${sanitizeAnsiLine(m)}`)
115
+ if (!list.length) out(` (no matches for "${sanitizeAnsiLine(filter)}")`)
116
+ for (const [i, m] of list.entries()) out(` [${i}] ${sanitizeAnsiLine(m)}`)
130
117
  } else {
131
- if (cfg.providers.length === 0) console.log("(no providers yet)")
118
+ if (cfg.providers.length === 0) out("(no providers yet)")
132
119
  let shown = 0
133
120
  for (const p of cfg.providers) {
134
121
  const list = p.models.filter(match)
135
122
  if (!list.length) continue
136
- // id/baseUrl dari config (lokal = input repo tak terpercaya); model dari
137
- // hasil probe jaringan — sanitasi sebelum masuk scrollback.
138
- console.log(
123
+ out(
139
124
  `${sanitizeAnsiLine(p.id)} (${sanitizeAnsiLine(p.baseUrl)})${filter ? ` - matches "${sanitizeAnsiLine(filter)}"` : ""}`,
140
125
  )
141
126
  shown += list.length
142
- for (const m of list.slice(0, 10)) console.log(` ${sanitizeAnsiLine(m)}`)
143
- if (filter && list.length > 10) console.log(` … +${list.length - 10} more`)
144
- if (!filter && p.models.length > 10) console.log(` … +${p.models.length - 10} more`)
127
+ for (const m of list.slice(0, 10)) out(` ${sanitizeAnsiLine(m)}`)
128
+ if (filter && list.length > 10) out(` … +${list.length - 10} more`)
129
+ if (!filter && p.models.length > 10) out(` … +${p.models.length - 10} more`)
145
130
  }
146
- // Header provider hanya bila ada yang cocok — tanpa ini filter kosong
147
- // mencetak judul lalu "(no matches)", dua baris untuk nol informasi.
148
- if (filter && shown === 0) console.log(` (no matches for "${sanitizeAnsiLine(filter)}")`)
131
+ if (filter && shown === 0) out(` (no matches for "${sanitizeAnsiLine(filter)}")`)
149
132
  }
150
133
  process.exit(0)
151
134
  }
152
135
  if (firstArg === "sync") {
153
- console.log("Syncing model list from providers…")
136
+ out("Syncing model list from providers…")
154
137
  const { updated, failed } = await refreshProviderModels({ cwd: cwdArg, allowLocal })
155
138
  for (const r of updated)
156
- console.log(
157
- ` ${c.green(glyphs.check)} ${sanitizeAnsiLine(r.id)}: ${r.from} -> ${r.to} model`,
158
- )
139
+ out(` ${c.green("ok")} ${sanitizeAnsiLine(r.id)}: ${r.from} -> ${r.to} model`)
159
140
  for (const f of failed)
160
- console.log(
161
- ` ${c.red(glyphs.cross)} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`,
162
- )
141
+ out(` ${c.red("failed")} ${sanitizeAnsiLine(f.id)}: ${sanitizeAnsiLine(f.reason)}`)
163
142
  if (!updated.length && !failed.length) {
164
143
  const cfgHere = await loadConfig(cwdArg, { allowLocal })
165
144
  if (cfgHere.providers.length === 0)
166
- console.log(" (no providers yet - run `minicode config add` first)")
167
- else console.log(" (no changes — check API key and network, then retry)")
145
+ out(" (no providers yet - run `minicode config add` first)")
146
+ else out(" (no changes — check API key and network, then retry)")
168
147
  }
169
148
  process.exit(0)
170
149
  }
@@ -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) console.log(c.dim(`(global scope — no local .minicode/sessions.db in ${base})`))
38
- if (rows.length === 0) console.log(c.dim("(no recorded sessions yet)"))
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
- console.log(
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
- // args[2] bisa berupa flag bila user lupa id (`sessions export --cwd x`);
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
- console.error("usage: minicode sessions export <id> [--jsonl]")
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
- console.error(`session "${id}" not found - see: minicode sessions list`)
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) console.log(JSON.stringify(m))
76
- else console.log(JSON.stringify(sess, null, 2))
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
- console.log(`[purge] removed ${removed} sessions (older than ${ttl} days)`)
127
- if (orphans > 0) console.log(`[purge] removed ${orphans} orphan journals`)
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
- const asked = sub === "--help" || sub === "-h"
134
- if (!asked) console.error(`unknown sessions subcommand: ${sub}\n`)
135
- console.log(SESSIONS_HELP)
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
  }
@@ -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
- console.log(c.dim("(no skills yet - add markdown files in .minicode/skills/*.md)"))
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
- console.log(
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
- // Tolak flag sebagai nama: `skills show --cwd x` adalah lupa argumen,
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
- console.error("usage: minicode skills show <name>")
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
- console.error(`skill "${name}" not found - see: minicode skills list`)
65
+ err(`skill "${sanitizeAnsiLine(name)}" not found - see: minicode skills list`)
52
66
  process.exit(1)
53
67
  }
54
- console.log(`${c.bold(c.cyan(`/${s.name}`))} ${c.dim(`- ${s.description}`)}\n\n${s.body}`)
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
- const asked = sub === "--help" || sub === "-h"
58
- if (!asked) console.error(`unknown skills subcommand: ${sub}\n`)
59
- console.log(SKILLS_HELP)
60
- process.exit(asked ? 0 : 2)
73
+ err(`unknown skills subcommand: ${sanitizeAnsiLine(sub)}\n`)
74
+ out(SKILLS_HELP)
75
+ process.exit(2)
61
76
  }
@@ -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(getArg: (name: string) => string | undefined): Promise<never> {
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 = getArg("--json") !== undefined || process.argv.includes("--json")
43
+ const asJson =
44
+ getArg("--json") !== undefined || args.includes("--json") || process.argv.includes("--json")
36
45
  const file = resolve(cwdArg ?? ".", ".minicode", "traces.jsonl")
37
- let traces: TraceRow[] = []
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
- let stepRows: StepTrace[] = []
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.