minicode-ai 0.13.0 → 0.14.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 (83) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -21
  3. package/README.md +4 -0
  4. package/cli/args.ts +50 -2
  5. package/cli/commands/acp.ts +18 -3
  6. package/cli/commands/daemon.ts +114 -19
  7. package/cli/commands/exec.ts +95 -7
  8. package/cli/commands/mcp.ts +66 -5
  9. package/cli/commands/memory.ts +46 -14
  10. package/cli/commands.ts +5 -0
  11. package/cli/index.ts +30 -5
  12. package/cli/minicode.js +6 -0
  13. package/cli/setup.ts +365 -24
  14. package/cli/tui.ts +72 -27
  15. package/docs/TERMINAL_CONTRACT.md +91 -24
  16. package/docs/agents.md +2 -2
  17. package/docs/cli.md +1 -0
  18. package/docs/environment.md +1 -0
  19. package/docs/memory-sessions.md +5 -0
  20. package/package.json +3 -2
  21. package/src/app/session.ts +153 -35
  22. package/src/app/tool-layer.ts +67 -61
  23. package/src/daemon/approvals.ts +25 -1
  24. package/src/daemon/client.ts +51 -1
  25. package/src/daemon/control.ts +8 -0
  26. package/src/daemon/protocol.ts +47 -1
  27. package/src/daemon/server.ts +45 -9
  28. package/src/daemon/subscription.ts +25 -1
  29. package/src/daemon/telemetry.ts +4 -0
  30. package/src/hooks/run.ts +5 -1
  31. package/src/mcp/client.ts +349 -90
  32. package/src/mcp/http-transport.ts +7 -0
  33. package/src/mcp/transport.ts +5 -0
  34. package/src/memory/files.ts +69 -3
  35. package/src/memory/vector.ts +556 -160
  36. package/src/policy/approval-binding.ts +199 -0
  37. package/src/policy/context.ts +20 -1
  38. package/src/policy/executor.ts +44 -5
  39. package/src/policy/permission.ts +243 -26
  40. package/src/policy/tool-contract.ts +77 -0
  41. package/src/policy/usage.ts +3 -1
  42. package/src/policy/work-mode.ts +49 -1
  43. package/src/presentation/adapter.ts +157 -7
  44. package/src/presentation/events.ts +173 -1
  45. package/src/presentation/model.ts +37 -0
  46. package/src/presentation/projection.ts +107 -18
  47. package/src/presentation/reducer.ts +134 -10
  48. package/src/sandbox/os.ts +18 -1
  49. package/src/session/persistence.ts +153 -11
  50. package/src/task/store.ts +43 -3
  51. package/src/tools/memory.ts +70 -10
  52. package/src/tools/task.ts +7 -1
  53. package/src/tools/todo.ts +14 -4
  54. package/src/ui/approval/prompt.ts +52 -7
  55. package/src/ui/assistant/simple.ts +160 -57
  56. package/src/ui/contract.ts +46 -0
  57. package/src/ui/footer.ts +14 -5
  58. package/src/ui/i18n/en.ts +9 -0
  59. package/src/ui/i18n/id.ts +9 -0
  60. package/src/ui/render/collapse.ts +24 -52
  61. package/src/ui/render/detail.ts +14 -9
  62. package/src/ui/render/errors.ts +8 -0
  63. package/src/ui/render/reasoning.ts +13 -8
  64. package/src/ui/session-state.ts +243 -0
  65. package/src/ui/tui/app.ts +7 -3
  66. package/src/ui/tui/transcript.ts +271 -30
  67. package/vendor/minicore/src/core/budget.ts +25 -25
  68. package/vendor/minicore/src/core/compact.ts +75 -75
  69. package/vendor/minicore/src/core/errors.ts +59 -59
  70. package/vendor/minicore/src/core/events.ts +73 -73
  71. package/vendor/minicore/src/core/executor.ts +139 -139
  72. package/vendor/minicore/src/core/history.ts +31 -31
  73. package/vendor/minicore/src/core/index.ts +41 -41
  74. package/vendor/minicore/src/core/loop.ts +355 -355
  75. package/vendor/minicore/src/core/permission.ts +22 -22
  76. package/vendor/minicore/src/core/provider.ts +39 -39
  77. package/vendor/minicore/src/core/recovery.ts +35 -35
  78. package/vendor/minicore/src/core/session.ts +327 -327
  79. package/vendor/minicore/src/core/snapshot.ts +146 -146
  80. package/vendor/minicore/src/core/tokens.ts +107 -107
  81. package/vendor/minicore/src/core/tool.ts +115 -115
  82. package/vendor/minicore/src/core/types.ts +50 -50
  83. package/vendor/minicore/src/providers/openai-compat.ts +417 -417
@@ -1,23 +1,23 @@
1
- // Permission boundary. The kernel commits to consulting this handler before
2
- // every tool execution; it never enforces its own policy.
3
-
4
- import type { ToolCall } from "./types.ts";
5
- import type { ExecutorDeps } from "./executor.ts";
6
-
7
- /**
8
- * Only "deny" blocks execution. A handler that needs interactive approval
9
- * (e.g. a CLI prompt) is expected to block until it resolves the decision
10
- * internally and then return "allow" or "deny".
11
- */
12
- export type Decision = "allow" | "deny";
13
-
14
- export interface PermissionHandler {
15
- check(call: ToolCall, deps: ExecutorDeps): Promise<Decision>;
16
- /**
17
- * Optional diagnostic for the most recent denial of `call`, so the model
18
- * can steer instead of retrying blindly until max steps. Invoked right
19
- * after `check` returns "deny"; returning undefined/"" keeps the plain
20
- * denial message. Optional — handlers without it behave as before.
21
- */
22
- describeDenial?(call: ToolCall): Promise<string | undefined> | string | undefined;
1
+ // Permission boundary. The kernel commits to consulting this handler before
2
+ // every tool execution; it never enforces its own policy.
3
+
4
+ import type { ToolCall } from "./types.ts";
5
+ import type { ExecutorDeps } from "./executor.ts";
6
+
7
+ /**
8
+ * Only "deny" blocks execution. A handler that needs interactive approval
9
+ * (e.g. a CLI prompt) is expected to block until it resolves the decision
10
+ * internally and then return "allow" or "deny".
11
+ */
12
+ export type Decision = "allow" | "deny";
13
+
14
+ export interface PermissionHandler {
15
+ check(call: ToolCall, deps: ExecutorDeps): Promise<Decision>;
16
+ /**
17
+ * Optional diagnostic for the most recent denial of `call`, so the model
18
+ * can steer instead of retrying blindly until max steps. Invoked right
19
+ * after `check` returns "deny"; returning undefined/"" keeps the plain
20
+ * denial message. Optional — handlers without it behave as before.
21
+ */
22
+ describeDenial?(call: ToolCall): Promise<string | undefined> | string | undefined;
23
23
  }
@@ -1,39 +1,39 @@
1
- // The model contract. The kernel only knows these normalized events; every
2
- // provider adapter (OpenAI-compatible, Anthropic, Gemini, local…) implements
3
- // this one interface. Reasoning/thinking is an optional "extension" event and
4
- // is never required.
5
-
6
- import type { Message } from "./types.ts";
7
- import type { ToolSchema } from "./tool.ts";
8
-
9
- /**
10
- * Why a provider stream ended. The kernel consults this to decide recovery:
11
- * `length` may trigger compaction+retry, `error`/`abort` never retry.
12
- */
13
- export type FinishReason = "stop" | "tool_calls" | "length" | "abort" | "error";
14
-
15
- /**
16
- * The normalized provider stream. Adapters translate their wire format into
17
- * exactly these events; the kernel never sees provider-specific shapes. A
18
- * well-formed stream always ends with a `finish` event.
19
- */
20
- export type ProviderEvent =
21
- | { type: "text"; text: string }
22
- | { type: "tool_call"; id: string; name: string; args: unknown }
23
- | { type: "finish"; reason: FinishReason }
24
- | { type: "extension"; kind: string; data: unknown };
25
-
26
- /** The per-request payload the kernel hands to a provider. */
27
- export interface StreamRequest {
28
- readonly messages: readonly Message[];
29
- readonly tools?: readonly ToolSchema[];
30
- readonly system?: string;
31
- readonly model?: string;
32
- }
33
-
34
- /** A model provider: normalized, stateless, and swappable. */
35
- export interface ModelProvider {
36
- readonly id: string;
37
- readonly models: readonly string[];
38
- stream(request: StreamRequest, signal: AbortSignal): AsyncIterable<ProviderEvent>;
39
- }
1
+ // The model contract. The kernel only knows these normalized events; every
2
+ // provider adapter (OpenAI-compatible, Anthropic, Gemini, local…) implements
3
+ // this one interface. Reasoning/thinking is an optional "extension" event and
4
+ // is never required.
5
+
6
+ import type { Message } from "./types.ts";
7
+ import type { ToolSchema } from "./tool.ts";
8
+
9
+ /**
10
+ * Why a provider stream ended. The kernel consults this to decide recovery:
11
+ * `length` may trigger compaction+retry, `error`/`abort` never retry.
12
+ */
13
+ export type FinishReason = "stop" | "tool_calls" | "length" | "abort" | "error";
14
+
15
+ /**
16
+ * The normalized provider stream. Adapters translate their wire format into
17
+ * exactly these events; the kernel never sees provider-specific shapes. A
18
+ * well-formed stream always ends with a `finish` event.
19
+ */
20
+ export type ProviderEvent =
21
+ | { type: "text"; text: string }
22
+ | { type: "tool_call"; id: string; name: string; args: unknown }
23
+ | { type: "finish"; reason: FinishReason }
24
+ | { type: "extension"; kind: string; data: unknown };
25
+
26
+ /** The per-request payload the kernel hands to a provider. */
27
+ export interface StreamRequest {
28
+ readonly messages: readonly Message[];
29
+ readonly tools?: readonly ToolSchema[];
30
+ readonly system?: string;
31
+ readonly model?: string;
32
+ }
33
+
34
+ /** A model provider: normalized, stateless, and swappable. */
35
+ export interface ModelProvider {
36
+ readonly id: string;
37
+ readonly models: readonly string[];
38
+ stream(request: StreamRequest, signal: AbortSignal): AsyncIterable<ProviderEvent>;
39
+ }
@@ -1,36 +1,36 @@
1
- // Provider-agnostic recovery. Adapters normalize provider-specific errors into
2
- // ProviderError categories; this policy decides what the kernel does about them.
3
-
4
- import type { ProviderError, RecoveryAction } from "./errors.ts";
5
-
6
- export interface RecoveryPolicy {
7
- onError(error: ProviderError, attempt: number): RecoveryAction;
8
- onLength(compacted: boolean): RecoveryAction;
9
- }
10
-
11
- export const maxProviderRetries = 3;
12
-
13
- export const defaultRecoveryPolicy: RecoveryPolicy = {
14
- onError(error, attempt) {
15
- switch (error.category) {
16
- case "auth":
17
- case "invalid_request":
18
- return { type: "throw" };
19
- case "context_length_exceeded":
20
- return { type: "force_compact_and_retry" };
21
- default:
22
- if (attempt > maxProviderRetries) return { type: "throw" };
23
- return { type: "retry", delayMs: backoffDelay(attempt, error.retryAfterMs) };
24
- }
25
- },
26
- onLength(compacted) {
27
- return compacted ? { type: "throw" } : { type: "force_compact_and_retry" };
28
- },
29
- };
30
-
31
- const RETRY_AFTER_MAX_MS = 30_000;
32
-
33
- function backoffDelay(attempt: number, retryAfter?: number): number {
34
- if (retryAfter != null) return Math.min(retryAfter, RETRY_AFTER_MAX_MS);
35
- return Math.min(1_000 * 2 ** (attempt - 1), 8_000);
1
+ // Provider-agnostic recovery. Adapters normalize provider-specific errors into
2
+ // ProviderError categories; this policy decides what the kernel does about them.
3
+
4
+ import type { ProviderError, RecoveryAction } from "./errors.ts";
5
+
6
+ export interface RecoveryPolicy {
7
+ onError(error: ProviderError, attempt: number): RecoveryAction;
8
+ onLength(compacted: boolean): RecoveryAction;
9
+ }
10
+
11
+ export const maxProviderRetries = 3;
12
+
13
+ export const defaultRecoveryPolicy: RecoveryPolicy = {
14
+ onError(error, attempt) {
15
+ switch (error.category) {
16
+ case "auth":
17
+ case "invalid_request":
18
+ return { type: "throw" };
19
+ case "context_length_exceeded":
20
+ return { type: "force_compact_and_retry" };
21
+ default:
22
+ if (attempt > maxProviderRetries) return { type: "throw" };
23
+ return { type: "retry", delayMs: backoffDelay(attempt, error.retryAfterMs) };
24
+ }
25
+ },
26
+ onLength(compacted) {
27
+ return compacted ? { type: "throw" } : { type: "force_compact_and_retry" };
28
+ },
29
+ };
30
+
31
+ const RETRY_AFTER_MAX_MS = 30_000;
32
+
33
+ function backoffDelay(attempt: number, retryAfter?: number): number {
34
+ if (retryAfter != null) return Math.min(retryAfter, RETRY_AFTER_MAX_MS);
35
+ return Math.min(1_000 * 2 ** (attempt - 1), 8_000);
36
36
  }