minicode-ai 0.9.28 → 0.10.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 (48) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/cli/args.ts +1 -0
  3. package/cli/commands.ts +219 -103
  4. package/cli/index.ts +8 -6
  5. package/cli/model-manager.ts +2 -7
  6. package/cli/provider-manager.ts +13 -13
  7. package/cli/setup.ts +10 -1
  8. package/cli/tui.ts +506 -0
  9. package/cli/wizard.ts +2 -1
  10. package/docs/ARCHITECTURE.html +41 -22
  11. package/docs/README.md +1 -0
  12. package/package.json +3 -3
  13. package/src/app/rag-layer.ts +7 -2
  14. package/src/config.ts +30 -1
  15. package/src/policy/bash-guard.ts +64 -8
  16. package/src/policy/update-check.ts +4 -1
  17. package/src/tools/bash.ts +8 -0
  18. package/src/tools/task.ts +6 -1
  19. package/src/tools/web_fetch.ts +11 -2
  20. package/src/tools/web_search.ts +4 -1
  21. package/src/ui/approval/prompt.ts +84 -18
  22. package/src/ui/assistant/simple.ts +55 -22
  23. package/src/ui/assistant/turn-status.ts +16 -7
  24. package/src/ui/footer.ts +14 -12
  25. package/src/ui/i18n/en.ts +225 -0
  26. package/src/ui/i18n/id.ts +227 -0
  27. package/src/ui/i18n/locale.ts +66 -0
  28. package/src/ui/input/input.ts +138 -77
  29. package/src/ui/input/prompt-engine.ts +97 -4
  30. package/src/ui/render/collapse.ts +8 -1
  31. package/src/ui/render/errors.ts +75 -50
  32. package/src/ui/render/format.ts +15 -5
  33. package/src/ui/render/highlight.ts +5 -2
  34. package/src/ui/render/table.ts +7 -4
  35. package/src/ui/render/theme.ts +8 -3
  36. package/src/ui/render/width.ts +17 -9
  37. package/src/ui/runtime/screen.ts +197 -0
  38. package/src/ui/screens/dialog.ts +174 -0
  39. package/src/ui/screens/form.ts +459 -0
  40. package/src/ui/screens/model-manager.ts +274 -127
  41. package/src/ui/screens/picker.ts +229 -98
  42. package/src/ui/screens/provider-manager.ts +371 -164
  43. package/src/ui/screens/wizard.ts +149 -102
  44. package/src/ui/tui/app.ts +745 -0
  45. package/src/ui/tui/transcript.ts +271 -0
  46. package/cli/repl.ts +0 -740
  47. package/src/ui/runtime/chrome.ts +0 -369
  48. package/src/ui/screens/overlay.ts +0 -61
@@ -1,11 +1,14 @@
1
- // View wizard setup pertama — murni presentasi: picker gateway, isian URL,
2
- // input API key, spinner. Penyimpanan provider dilakukan lewat callback
3
- // `onSubmit` yang di-inject controller (cli/wizard.ts).
1
+ // View wizard setup pertama — murni presentasi: picker gateway + form
2
+ // URL/key dalam popup. Penyimpanan provider lewat callback `onSubmit` yang
3
+ // di-inject controller (cli/wizard.ts). SEMUA langkah dalam kotak: tak ada
4
+ // ketikan di luar popup.
4
5
  import { formatError } from "../assistant/simple.ts"
5
- import { askLine, askSecret } from "../input/input.ts"
6
+ import { t } from "../i18n/locale.ts"
6
7
  import { sanitizeAnsiLine } from "../render/sanitize.ts"
7
8
  import { c, glyphs } from "../render/theme.ts"
8
- import { displayWidth } from "../render/width.ts"
9
+ import { openAltScreen } from "../runtime/screen.ts"
10
+ import { dialogBox } from "./dialog.ts"
11
+ import { runForm, validateUrl } from "./form.ts"
9
12
  import { runPicker } from "./picker.ts"
10
13
 
11
14
  export interface WizardPreset {
@@ -19,114 +22,158 @@ export interface SetupWizardViewOptions {
19
22
  onSubmit(baseUrl: string, apiKey: string): Promise<string>
20
23
  }
21
24
 
25
+ /**
26
+ * Tunggu tanpa menahan process hidup (unref): jeda sukses/gagal wizard tak
27
+ * boleh menahan exit bila stdin sudah ditutup. Gagal-di-kode-lama: timer
28
+ * polos menahan event-loop 1.2/2.5 dtk.
29
+ */
30
+ function sleepUnref(ms: number): Promise<void> {
31
+ return new Promise((r) => {
32
+ const timer = setTimeout(r, ms)
33
+ try {
34
+ ;(timer as unknown as { unref?: () => void }).unref?.()
35
+ } catch {}
36
+ })
37
+ }
38
+
22
39
  /**
23
40
  * Wizard setup pertama — hal PERTAMA yang dilihat pengguna baru.
24
41
  *
25
- * Memakai `runPicker` (panah + filter), bukan "Choice [1-15]" lewat readline.
26
- * Dua alasan: (1) REPL sudah punya picker untuk tugas yang sama — memilih dari
27
- * daftar — jadi dua UX berbeda untuk satu konsep membingungkan; (2) nomor manual
28
- * membuat pilihan di luar rentang diam-diam jatuh ke item pertama, sehingga user
29
- * mengira memilih sesuatu yang lain.
30
- *
31
- * Fallback readline tetap ada untuk terminal tanpa raw mode.
42
+ * Memakai `runPicker` (panah + filter) untuk gateway, lalu form dalam popup
43
+ * untuk URL + API key. Esc di langkah mana pun = batal total.
32
44
  */
33
45
  export async function runSetupWizardView(opts: SetupWizardViewOptions): Promise<boolean> {
34
46
  if (!process.stdin.isTTY) return false
47
+ const screen = openAltScreen()
48
+ if (!screen.ok) return false
49
+ try {
50
+ const CUSTOM = "\u0000custom"
51
+ const items = [
52
+ ...opts.presets.map((p) => ({ name: p.label, provider: "", value: p.baseUrl })),
53
+ { name: t("prov.customUrl"), provider: "", value: CUSTOM },
54
+ ]
35
55
 
36
- // Sapaan: pada terminal sempit, petunjuk batal pindah ke baris sendiri
37
- // supaya tidak membungkus.
38
- const cols = process.stdout.columns || 80
39
- const sapaan = "Connect your first provider."
40
- const petunjuk = "(Ctrl+C to cancel)"
41
- process.stdout.write(`\n${c.bold("Minicode setup")}\n`)
42
- process.stdout.write(
43
- displayWidth(`${sapaan} ${petunjuk}`) <= cols
44
- ? `${sapaan} ${c.dim(petunjuk)}\n`
45
- : `${sapaan}\n${c.dim(petunjuk)}\n`,
46
- )
47
-
48
- const CUSTOM = "\u0000custom"
49
- const items = [
50
- ...opts.presets.map((p) => ({ name: p.label, provider: "", value: p.baseUrl })),
51
- { name: "Custom URL", provider: "", value: CUSTOM },
52
- ]
53
-
54
- let picked: string | null = null
55
- await runPicker({
56
- title: "Select gateway",
57
- items,
58
- filterable: true,
59
- placeholder: "Filter",
60
- onPick: (v) => {
61
- picked = v
62
- },
63
- onCancel: () => {
64
- picked = null
65
- },
66
- })
67
- if (picked === null) {
68
- process.stdout.write("Setup canceled.\n")
69
- return false
70
- }
71
-
72
- // Isian URL memakai askLine (bukan readline) — satu stack input: sanitasi
73
- // paste, editing UTF-16/grapheme, history, dan ukuran lebar kolom semuanya
74
- // sama dengan prompt REPL. Readline lama tidak lewat decodeKeys sehingga
75
- // paste/mouse bisa bocor sebagai teks.
76
- let targetUrl: string
77
- if (picked === CUSTOM) {
78
- targetUrl = (await askLine({ prompt: "Base URL: " })) ?? ""
79
- } else {
80
- const custom = await askLine({ prompt: `Base URL [${picked}]: ` })
81
- // Esc/Ctrl+C = batal total — dulu jatuh ke "pakai default" dan wizard
82
- // lanjut ke API key padahal sapaan bilang "(Ctrl+C to cancel)".
83
- if (custom == null) {
84
- process.stdout.write("Setup canceled.\n")
56
+ let picked: string | null = null
57
+ await runPicker({
58
+ title: t("wiz.gateway"),
59
+ items,
60
+ filterable: true,
61
+ placeholder: t("pick.placeholder"),
62
+ onPick: (v) => {
63
+ picked = v
64
+ },
65
+ onCancel: () => {
66
+ picked = null
67
+ },
68
+ })
69
+ if (picked === null) {
70
+ process.stdout.write(`${t("wiz.canceled")}\n`)
85
71
  return false
86
72
  }
87
- targetUrl = custom.trim() || (picked as string)
88
- }
89
73
 
90
- if (!targetUrl) {
91
- process.stdout.write("Setup canceled.\n")
92
- return false
93
- }
94
- // Validasi URL — umpan balik langsung, bukan gagal saat detect.
95
- try {
96
- const u = new URL(targetUrl)
97
- if (!["http:", "https:"].includes(u.protocol)) throw new Error("protocol")
98
- } catch {
99
- // URL = input user tak terpercaya — sanitasi sebelum echo ke terminal.
100
- process.stdout.write(`${c.red(glyphs.cross)} Invalid URL: ${sanitizeAnsiLine(targetUrl)}\n`)
101
- return false
102
- }
103
-
104
- // Endpoint lokal (Ollama/LM Studio) tidak butuh API key; kirim placeholder
105
- // agar header Authorization tetap terbentuk.
106
- const lokal = /^(https?:\/\/)(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(targetUrl)
107
- const apiKey = lokal ? "ollama" : await askSecret("API key: ")
74
+ // URL via form dalam popup (validasi inline, bukan gagal saat detect).
75
+ const urlForm = await runForm(
76
+ {
77
+ title: t("wiz.title"),
78
+ fields: [
79
+ {
80
+ id: "url",
81
+ label: picked === CUSTOM ? t("wiz.urlLabel") : `${t("wiz.urlLabel")} [${picked}]`,
82
+ kind: "text",
83
+ initial: picked === CUSTOM ? "" : (picked as string),
84
+ validate: (v) => {
85
+ const val = v.trim() || (picked === CUSTOM ? "" : (picked as string))
86
+ if (!val) return t("form.required")
87
+ return validateUrl(val)
88
+ },
89
+ },
90
+ ],
91
+ },
92
+ screen,
93
+ )
94
+ if (urlForm.cancelled || !urlForm.values) {
95
+ process.stdout.write(`${t("wiz.canceled")}\n`)
96
+ return false
97
+ }
98
+ const rawUrl = (urlForm.values.url ?? "").trim()
99
+ const targetUrl = rawUrl || (picked === CUSTOM ? "" : (picked as string))
100
+ if (!targetUrl) {
101
+ process.stdout.write(`${t("wiz.canceled")}\n`)
102
+ return false
103
+ }
108
104
 
109
- if (apiKey == null) {
110
- // Batal (Esc/Ctrl+C) — jangan sarankan OPENAI_API_KEY, itu untuk submit
111
- // kosong (user benar-benar menyerah tanpa key).
112
- process.stdout.write("Setup canceled.\n")
113
- return false
114
- }
115
- if (!apiKey) {
116
- process.stdout.write(`Setup canceled. Set OPENAI_API_KEY later to continue.\n`)
117
- return false
118
- }
105
+ // Endpoint lokal (Ollama/LM Studio) tidak butuh API key; kirim placeholder
106
+ // agar header Authorization tetap terbentuk.
107
+ const lokal = /^(https?:\/\/)(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(targetUrl)
108
+ let apiKey = "ollama"
109
+ if (!lokal) {
110
+ const keyForm = await runForm(
111
+ {
112
+ title: t("wiz.title"),
113
+ fields: [
114
+ {
115
+ id: "key",
116
+ label: t("wiz.keyLabel", { url: targetUrl }),
117
+ kind: "secret",
118
+ validate: (v) => (v.trim() ? null : t("form.required")),
119
+ },
120
+ ],
121
+ },
122
+ screen,
123
+ )
124
+ if (keyForm.cancelled || !keyForm.values) {
125
+ process.stdout.write(`${t("wiz.canceled")}\n`)
126
+ return false
127
+ }
128
+ apiKey = (keyForm.values.key ?? "").trim()
129
+ if (!apiKey) {
130
+ process.stdout.write(`${t("wiz.keyLater")}\n`)
131
+ return false
132
+ }
133
+ }
119
134
 
120
- const { createSpinner } = await import("../runtime/spinner.ts")
121
- const spin = createSpinner("Detecting models…")
122
- try {
123
- const message = await opts.onSubmit(targetUrl, apiKey)
124
- // Pesan dari jaringan (nama model/gateway) — sanitasi sebelum tampil.
125
- spin.success(sanitizeAnsiLine(message))
126
- process.stdout.write(`Setup complete.\n\n`)
127
- return true
128
- } catch (e) {
129
- spin.error(`Model detection failed: ${formatError(e)}`)
130
- return false
135
+ // Progres sebagai baris dalam kotak (bukan spinner liar di bawah popup).
136
+ const box = dialogBox(
137
+ { title: t("wiz.title"), body: [c.muted(t("wiz.detecting"))] },
138
+ screen.cols,
139
+ screen.rows,
140
+ )
141
+ screen.paintRegion(box.lines, box.topRow)
142
+ try {
143
+ const message = await opts.onSubmit(targetUrl, apiKey)
144
+ // Pesan dari jaringan (nama model/gateway) — sanitasi sebelum tampil.
145
+ screen.clearRegion()
146
+ const doneBox = dialogBox(
147
+ {
148
+ title: t("wiz.title"),
149
+ body: [`${glyphs.check} ${sanitizeAnsiLine(message)}`, "", t("wiz.done")],
150
+ },
151
+ screen.cols,
152
+ screen.rows,
153
+ )
154
+ screen.paintRegion(doneBox.lines, doneBox.topRow)
155
+ await sleepUnref(1200)
156
+ return true
157
+ } catch (e) {
158
+ screen.clearRegion()
159
+ const errBox = dialogBox(
160
+ {
161
+ title: t("wiz.title"),
162
+ body: [c.error(`${glyphs.cross} ${t("wiz.detectFail", { msg: formatError(e) })}`)],
163
+ },
164
+ screen.cols,
165
+ screen.rows,
166
+ )
167
+ screen.paintRegion(errBox.lines, errBox.topRow)
168
+ await sleepUnref(2500)
169
+ return false
170
+ }
171
+ } finally {
172
+ try {
173
+ screen.clearRegion()
174
+ } catch {}
175
+ try {
176
+ screen.close()
177
+ } catch {}
131
178
  }
132
179
  }