minicode-ai 0.9.29 → 0.11.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 (141) hide show
  1. package/AGENTS.md +45 -0
  2. package/CHANGELOG.md +79 -1
  3. package/PLAN.md +491 -0
  4. package/README.md +2 -2
  5. package/cli/args.ts +1 -0
  6. package/cli/commands/acp.ts +485 -0
  7. package/cli/commands/auth.ts +7 -4
  8. package/cli/commands/config.ts +41 -27
  9. package/cli/commands/exec.ts +33 -12
  10. package/cli/commands/mcp.ts +3 -2
  11. package/cli/commands/memory.ts +1 -1
  12. package/cli/commands/pricing.ts +6 -4
  13. package/cli/commands/providers.ts +18 -8
  14. package/cli/commands/sessions.ts +11 -4
  15. package/cli/commands/skills.ts +3 -3
  16. package/cli/commands/stats.ts +3 -1
  17. package/cli/commands.ts +225 -103
  18. package/cli/index.ts +89 -62
  19. package/cli/model-manager.ts +8 -8
  20. package/cli/provider-manager.ts +13 -13
  21. package/cli/router.ts +7 -0
  22. package/cli/setup.ts +349 -4
  23. package/cli/tui.ts +542 -0
  24. package/cli/wizard.ts +2 -1
  25. package/docs/ARCHITECTURE.html +62 -36
  26. package/docs/CONTROL-PLANE-MAP.md +139 -0
  27. package/docs/HARNESS.md +150 -0
  28. package/docs/PLAN_UIUX_V6.md +209 -0
  29. package/docs/README.md +1 -1
  30. package/docs/SUMMARY.md +52 -0
  31. package/docs/TERMINAL_CONTRACT.md +367 -0
  32. package/docs/UI_RENDER_PIPELINE.md +165 -0
  33. package/docs/USAGE.md +11 -0
  34. package/docs/agents.md +31 -0
  35. package/docs/architecture.md +3 -3
  36. package/docs/choosing-mode.md +34 -0
  37. package/docs/cli.md +130 -0
  38. package/docs/concepts.md +53 -0
  39. package/docs/config-providers.md +87 -0
  40. package/docs/config.md +63 -0
  41. package/docs/contributing.md +79 -0
  42. package/docs/environment.md +95 -0
  43. package/docs/exec.md +73 -0
  44. package/docs/getting-started.md +102 -0
  45. package/docs/glossary.md +37 -0
  46. package/docs/mcp-lsp.md +54 -0
  47. package/docs/memory-sessions.md +63 -0
  48. package/docs/policy-sandbox.md +72 -0
  49. package/docs/pricing-budget.md +49 -0
  50. package/docs/quickstart.md +60 -0
  51. package/docs/repl.md +67 -0
  52. package/docs/security-model.md +95 -0
  53. package/docs/security.md +91 -0
  54. package/docs/skills.md +48 -0
  55. package/docs/terminal.md +79 -0
  56. package/docs/tools.md +123 -0
  57. package/docs/troubleshooting.md +40 -0
  58. package/docs/verify-benchmark.md +58 -0
  59. package/package.json +8 -5
  60. package/src/app/provider-layer.ts +12 -4
  61. package/src/app/rag-layer.ts +7 -2
  62. package/src/app/session.ts +6 -0
  63. package/src/app/tool-layer.ts +2 -1
  64. package/src/config.ts +30 -1
  65. package/src/constants.ts +35 -0
  66. package/src/lib/net.ts +6 -1
  67. package/src/lsp/client.ts +41 -8
  68. package/src/mcp/http-transport.ts +52 -15
  69. package/src/mcp/transport.ts +32 -1
  70. package/src/memory/files.ts +6 -5
  71. package/src/policy/allowlist.ts +1 -1
  72. package/src/policy/bash-guard.ts +213 -17
  73. package/src/policy/compaction.ts +57 -3
  74. package/src/policy/context.ts +4 -0
  75. package/src/policy/jail.ts +49 -4
  76. package/src/policy/permission.ts +152 -12
  77. package/src/policy/pricing.ts +12 -9
  78. package/src/policy/update-check.ts +4 -1
  79. package/src/presentation/adapter.ts +721 -0
  80. package/src/presentation/events.ts +324 -0
  81. package/src/presentation/label.ts +140 -0
  82. package/src/presentation/model.ts +172 -0
  83. package/src/presentation/reducer.ts +486 -0
  84. package/src/presentation/store.ts +256 -0
  85. package/src/providers/anthropic.ts +22 -4
  86. package/src/providers/detect.ts +2 -1
  87. package/src/providers/router.ts +13 -0
  88. package/src/repo/repomap.ts +2 -29
  89. package/src/session/checkpoint.ts +27 -9
  90. package/src/session/journal.ts +27 -5
  91. package/src/skills/loader.ts +88 -5
  92. package/src/telemetry/trace.ts +36 -15
  93. package/src/tools/ask_user.ts +73 -4
  94. package/src/tools/bash.ts +23 -17
  95. package/src/tools/glob.ts +10 -11
  96. package/src/tools/lsp.ts +3 -56
  97. package/src/tools/memory.ts +13 -12
  98. package/src/tools/task.ts +7 -1
  99. package/src/tools/web_fetch.ts +11 -2
  100. package/src/tools/web_search.ts +4 -1
  101. package/src/ui/approval/prompt.ts +96 -22
  102. package/src/ui/assistant/simple.ts +188 -44
  103. package/src/ui/assistant/turn-status.ts +32 -10
  104. package/src/ui/contract.ts +119 -0
  105. package/src/ui/footer.ts +35 -14
  106. package/src/ui/i18n/en.ts +253 -0
  107. package/src/ui/i18n/id.ts +255 -0
  108. package/src/ui/i18n/locale.ts +68 -0
  109. package/src/ui/input/input.ts +189 -81
  110. package/src/ui/input/prompt-engine.ts +139 -4
  111. package/src/ui/render/collapse.ts +20 -13
  112. package/src/ui/render/diff.ts +7 -2
  113. package/src/ui/render/errors.ts +75 -50
  114. package/src/ui/render/format.ts +26 -8
  115. package/src/ui/render/highlight.ts +12 -5
  116. package/src/ui/render/markdown.ts +5 -1
  117. package/src/ui/render/sanitize.ts +29 -2
  118. package/src/ui/render/table.ts +12 -6
  119. package/src/ui/render/theme.ts +23 -4
  120. package/src/ui/render/width.ts +104 -17
  121. package/src/ui/runtime/motion.ts +16 -0
  122. package/src/ui/runtime/screen.ts +242 -0
  123. package/src/ui/runtime/spinner.ts +50 -4
  124. package/src/ui/runtime/statusline.ts +50 -1
  125. package/src/ui/screens/dialog.ts +174 -0
  126. package/src/ui/screens/form.ts +486 -0
  127. package/src/ui/screens/model-manager.ts +289 -134
  128. package/src/ui/screens/picker.ts +264 -109
  129. package/src/ui/screens/provider-manager.ts +385 -172
  130. package/src/ui/screens/wizard.ts +165 -102
  131. package/src/ui/tui/app.ts +951 -0
  132. package/src/ui/tui/transcript.ts +475 -0
  133. package/vendor/minicore/LICENSE +21 -0
  134. package/vendor/minicore/VENDOR.md +6 -3
  135. package/vendor/minicore/package.json +6 -3
  136. package/vendor/minicore/src/core/loop.ts +12 -2
  137. package/vendor/minicore/src/core/snapshot.ts +4 -0
  138. package/vendor/minicore/src/providers/openai-compat.ts +76 -25
  139. package/cli/repl.ts +0 -740
  140. package/src/ui/runtime/chrome.ts +0 -369
  141. package/src/ui/screens/overlay.ts +0 -61
@@ -12,20 +12,19 @@ import type { Content, Message } from "../core/types.ts";
12
12
  // `args` — the executor rejects unknown properties (all schemas are
13
13
  // additionalProperties:false), so smuggling it there fails validation.
14
14
  // Side-map keeps args clean; consume-once + cap so long sessions can't leak.
15
- const providerMetaByCallId = new Map<string, unknown>()
16
- function stashProviderMeta(id: string, meta: unknown): void {
17
- if (!id || meta == null) return
18
- providerMetaByCallId.set(id, meta)
19
- // Cap: drop the oldest entry when a very long session piles up.
20
- if (providerMetaByCallId.size > 500) {
21
- const first = providerMetaByCallId.keys().next()
22
- if (!first.done) providerMetaByCallId.delete(first.value)
23
- }
24
- }
25
- function takeProviderMeta(id: string): unknown {
26
- const v = providerMetaByCallId.get(id)
27
- if (v != null) providerMetaByCallId.delete(id)
28
- return v
15
+ // The map lives per provider INSTANCE (inside createOpenAICompatProvider):
16
+ // a module-level map would be shared across concurrent sessions, and
17
+ // index-based fallback ids (`call_0`) could then echo one session's metadata
18
+ // into another session's history replay.
19
+
20
+ /** Sniff a well-known image format from magic bytes; undefined when unknown. */
21
+ function sniffImageMime(bytes: Uint8Array): string | undefined {
22
+ if (bytes.length >= 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) return "image/png";
23
+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) return "image/jpeg";
24
+ if (bytes.length >= 4 && bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x38) return "image/gif";
25
+ if (bytes.length >= 12 && bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x46 && bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50) return "image/webp";
26
+ if (bytes.length >= 2 && bytes[0] === 0x42 && bytes[1] === 0x4d) return "image/bmp";
27
+ return undefined;
29
28
  }
30
29
 
31
30
  /** Configuration for an OpenAI-compatible chat completions endpoint. */
@@ -68,6 +67,23 @@ export function createOpenAICompatProvider(config: OpenAICompatConfig): ModelPro
68
67
  ...config.headers,
69
68
  };
70
69
 
70
+ // Per-instance provider-metadata side-map (see comment at top of file).
71
+ const providerMetaByCallId = new Map<string, unknown>();
72
+ function stashProviderMeta(id: string, meta: unknown): void {
73
+ if (!id || meta == null) return;
74
+ providerMetaByCallId.set(id, meta);
75
+ // Cap: drop the oldest entry when a very long session piles up.
76
+ if (providerMetaByCallId.size > 500) {
77
+ const first = providerMetaByCallId.keys().next();
78
+ if (!first.done) providerMetaByCallId.delete(first.value);
79
+ }
80
+ }
81
+ function takeProviderMeta(id: string): unknown {
82
+ const v = providerMetaByCallId.get(id);
83
+ if (v != null) providerMetaByCallId.delete(id);
84
+ return v;
85
+ }
86
+
71
87
  return {
72
88
  id: config.id ?? "openai-compat",
73
89
  models: config.models,
@@ -76,14 +92,16 @@ export function createOpenAICompatProvider(config: OpenAICompatConfig): ModelPro
76
92
  const buildBody = (withUsage: boolean): string =>
77
93
  JSON.stringify({
78
94
  model: request.model ?? config.defaultModel,
79
- messages: toMessages(request.messages),
95
+ messages: toMessages(request.messages, takeProviderMeta),
80
96
  tools: request.tools?.length ? toTools(request.tools) : undefined,
81
97
  stream: true,
82
98
  // JSON.stringify drops undefined keys, so the field is omitted entirely.
83
99
  stream_options: withUsage ? { include_usage: true } : undefined,
84
100
  // DeepSeek-style thinking: provider seperti b.ai butuh reasoning_content
85
101
  // di history saat thinking aktif. OFF via env agar multi-turn aman.
86
- ...(process.env.MINICODE_THINKING === "off" ? { enable_thinking: false } : {}),
102
+ // MINICORE_THINKING adalah nama resmi; MINICODE_THINKING (brand lama)
103
+ // dipertahankan sebagai fallback kompatibilitas.
104
+ ...((process.env.MINICORE_THINKING ?? process.env.MINICODE_THINKING) === "off" ? { enable_thinking: false } : {}),
87
105
  ...(config.reasoningEffort ? { reasoning_effort: config.reasoningEffort } : {}),
88
106
  });
89
107
  let body = buildBody(includeUsage);
@@ -223,7 +241,7 @@ export function createOpenAICompatProvider(config: OpenAICompatConfig): ModelPro
223
241
  };
224
242
  }
225
243
 
226
- function toMessages(messages: readonly Message[]): unknown[] {
244
+ function toMessages(messages: readonly Message[], takeMeta: (id: string) => unknown): unknown[] {
227
245
  return messages.map((message) => {
228
246
  switch (message.role) {
229
247
  case "user":
@@ -239,7 +257,7 @@ function toMessages(messages: readonly Message[]): unknown[] {
239
257
  ? message.toolCalls.map((call) => {
240
258
  // Echo provider metadata from the side-map (consume-once);
241
259
  // args are sent exactly as received, with no hidden keys.
242
- const extra = takeProviderMeta(call.id)
260
+ const extra = takeMeta(call.id)
243
261
  return {
244
262
  id: call.id,
245
263
  type: "function",
@@ -249,12 +267,24 @@ function toMessages(messages: readonly Message[]): unknown[] {
249
267
  })
250
268
  : undefined,
251
269
  };
252
- case "tool":
270
+ case "tool": {
271
+ const content = message.content;
272
+ // Binary tool results must never reach the wire as a JSON index map
273
+ // ({"0":1,...}): sniffed images travel as an image_url data-URL part;
274
+ // any other binary becomes an explicit placeholder string.
275
+ if (content instanceof Uint8Array) {
276
+ const mime = sniffImageMime(content);
277
+ const wire = mime
278
+ ? [{ type: "image_url", image_url: { url: `data:${mime};base64,${bytesToBase64(content)}` } }]
279
+ : `[binary: ${content.byteLength} bytes]`;
280
+ return { role: "tool", tool_call_id: message.toolCallId, content: wire };
281
+ }
253
282
  return {
254
283
  role: "tool",
255
284
  tool_call_id: message.toolCallId,
256
- content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
285
+ content: typeof content === "string" ? content : JSON.stringify(content),
257
286
  };
287
+ }
258
288
  }
259
289
  });
260
290
  }
@@ -351,16 +381,37 @@ async function* sse(body: ReadableStream<Uint8Array>, signal: AbortSignal): Asyn
351
381
 
352
382
  function toProviderError(status: number, body: string, headers: Headers): ProviderError {
353
383
  const detail = body.slice(0, 500);
354
- const retryAfter = headers.get("retry-after");
384
+ const retryAfterMs = parseRetryAfter(headers.get("retry-after"));
355
385
  if (status === 429) {
356
- const ms = retryAfter ? Number(retryAfter) * 1_000 : undefined;
357
- return new ProviderError("rate_limit", `rate limited (${status}): ${detail}`, Number.isFinite(ms) ? ms : undefined);
386
+ return new ProviderError("rate_limit", `rate limited (${status}): ${detail}`, retryAfterMs);
358
387
  }
359
388
  if (status === 401 || status === 403) return new ProviderError("auth", `auth failed (${status}): ${detail}`);
360
389
  if (status === 400 || status === 404 || status === 422) {
361
- const isContext = body.toLowerCase().includes("context_length") || body.toLowerCase().includes("maximum context");
390
+ // Providers phrase context overflow differently: OpenAI "maximum context
391
+ // length", OpenRouter-style "context_length_exceeded", Anthropic "prompt
392
+ // is too long", Gemini-style "input is too long". Missing a phrase turns
393
+ // a compact-and-retry case into a terminal invalid_request throw.
394
+ const lower = body.toLowerCase();
395
+ const isContext = ["context_length", "context length", "maximum context", "prompt is too long", "input is too long"].some((phrase) =>
396
+ lower.includes(phrase),
397
+ );
362
398
  return new ProviderError(isContext ? "context_length_exceeded" : "invalid_request", `${status}: ${detail}`);
363
399
  }
364
400
  if (status >= 500) return new ProviderError("server", `server error (${status}): ${detail}`);
365
401
  return new ProviderError("unknown", `${status}: ${detail}`);
366
- }
402
+ }
403
+
404
+ /**
405
+ * Parse a `Retry-After` header in either RFC form — delta-seconds ("120")
406
+ * or HTTP-date ("Wed, 21 Oct 2026 07:28:00 GMT") — into milliseconds from
407
+ * now. Returns undefined when absent or unparsable; a past date yields 0.
408
+ */
409
+ function parseRetryAfter(value: string | null): number | undefined {
410
+ if (!value) return undefined;
411
+ const trimmed = value.trim();
412
+ if (trimmed === "") return undefined;
413
+ if (/^\d+(\.\d+)?$/.test(trimmed)) return Math.round(Number(trimmed) * 1_000);
414
+ const date = Date.parse(trimmed);
415
+ if (Number.isNaN(date)) return undefined;
416
+ return Math.max(0, date - Date.now());
417
+ }