mini-coder 0.5.14 → 0.6.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 (70) hide show
  1. package/README.md +25 -109
  2. package/bin/mc.ts +8 -11
  3. package/bun.lock +79 -269
  4. package/package.json +17 -22
  5. package/src/agent.ts +237 -1403
  6. package/src/args.ts +289 -0
  7. package/src/headless.ts +43 -358
  8. package/src/index.ts +29 -1016
  9. package/src/oauth.ts +117 -0
  10. package/src/prompt.ts +227 -284
  11. package/src/session.ts +55 -1306
  12. package/src/shared.ts +117 -38
  13. package/src/tool-bash.ts +110 -0
  14. package/src/tool-edit.ts +133 -0
  15. package/src/tool-task.ts +114 -0
  16. package/src/tui-components.ts +150 -0
  17. package/src/tui-conversation.ts +262 -0
  18. package/src/tui-editor.ts +29 -0
  19. package/src/tui-overlay.ts +403 -0
  20. package/src/tui.ts +236 -0
  21. package/src/types.ts +160 -0
  22. package/tsconfig.json +17 -0
  23. package/BENCHMARK.md +0 -107
  24. package/LICENSE +0 -9
  25. package/PROGRESS.md +0 -5
  26. package/assets/icon-1-minimal.svg +0 -31
  27. package/assets/icon-2-dark-terminal.svg +0 -48
  28. package/assets/icon-3-gradient-modern.svg +0 -45
  29. package/assets/icon-4-filled-bold.svg +0 -54
  30. package/assets/icon-5-community-badge.svg +0 -63
  31. package/assets/mc-claude-smart.png +0 -0
  32. package/assets/mc-gpt-smart.png +0 -0
  33. package/assets/preview-0-5-0.png +0 -0
  34. package/assets/preview.gif +0 -0
  35. package/benchmark-baseline.sh +0 -15
  36. package/benchmark-loop.sh +0 -19
  37. package/skills-lock.json +0 -15
  38. package/src/assistant-output.ts +0 -73
  39. package/src/cli.ts +0 -134
  40. package/src/delegation.ts +0 -238
  41. package/src/errors.ts +0 -15
  42. package/src/git.ts +0 -247
  43. package/src/input.ts +0 -168
  44. package/src/mcp.ts +0 -609
  45. package/src/paths.ts +0 -37
  46. package/src/session-message.ts +0 -385
  47. package/src/settings.ts +0 -449
  48. package/src/skills.ts +0 -271
  49. package/src/submit.ts +0 -376
  50. package/src/text.ts +0 -71
  51. package/src/theme.ts +0 -330
  52. package/src/tool-common.ts +0 -93
  53. package/src/tool-delegate.ts +0 -125
  54. package/src/tool-grep.ts +0 -606
  55. package/src/tool-read.ts +0 -313
  56. package/src/tool-shell.ts +0 -1051
  57. package/src/tools.ts +0 -1179
  58. package/src/ui/agent.ts +0 -320
  59. package/src/ui/commands.test.ts +0 -957
  60. package/src/ui/commands.ts +0 -848
  61. package/src/ui/conversation.test.ts +0 -585
  62. package/src/ui/conversation.ts +0 -1836
  63. package/src/ui/help.ts +0 -158
  64. package/src/ui/input.test.ts +0 -64
  65. package/src/ui/input.ts +0 -138
  66. package/src/ui/overlay.ts +0 -59
  67. package/src/ui/runtime.ts +0 -69
  68. package/src/ui/status.ts +0 -220
  69. package/src/ui.ts +0 -1190
  70. package/src/version.ts +0 -48
package/src/oauth.ts ADDED
@@ -0,0 +1,117 @@
1
+ import readline from "node:readline";
2
+
3
+ import { getEnvApiKey, getProviders } from "@mariozechner/pi-ai";
4
+ import {
5
+ getOAuthApiKey,
6
+ getOAuthProvider,
7
+ getOAuthProviders,
8
+ type OAuthProviderId,
9
+ } from "@mariozechner/pi-ai/oauth";
10
+ import { AUTH_PATH as AUTH_FILE } from "./shared";
11
+ import type { CliOptions, SavedOAuthCreds } from "./types";
12
+
13
+ export function isOAuthProvider(provider: string): boolean {
14
+ return getOAuthProviders().some(
15
+ (oauthProvider) => oauthProvider.id === provider,
16
+ );
17
+ }
18
+
19
+ export async function getAvailableProviders(): Promise<string[]> {
20
+ const auth = await readCreds();
21
+ const loggedInOAuthProviders = getOAuthProviders()
22
+ .map((provider) => provider.id)
23
+ .filter((provider) => auth[provider]);
24
+ const envKeyProviders = getProviders().filter(
25
+ (provider) => !!getEnvApiKey(provider),
26
+ );
27
+ const providers: string[] = [];
28
+ const providerIds = new Set<string>();
29
+
30
+ for (const provider of [...loggedInOAuthProviders, ...envKeyProviders]) {
31
+ if (providerIds.has(provider)) continue;
32
+
33
+ providers.push(provider);
34
+ providerIds.add(provider);
35
+ }
36
+
37
+ return providers;
38
+ }
39
+
40
+ export async function loginOAuth(provider: OAuthProviderId) {
41
+ const oauthProvider = getOAuthProvider(provider);
42
+ if (!oauthProvider) throw new Error(`Unknown OAuth provider: ${provider}`);
43
+
44
+ const rl = readline.createInterface({
45
+ input: process.stdin,
46
+ output: process.stdout,
47
+ });
48
+
49
+ try {
50
+ const creds = await oauthProvider.login({
51
+ onAuth: ({ url, instructions }) => {
52
+ console.log(`Open: ${url}`);
53
+ if (instructions) console.log(instructions);
54
+ },
55
+ onPrompt: async (prompt) => {
56
+ let answer: string = "";
57
+ await rl.question(prompt.message, (a) => (answer = a));
58
+ return answer;
59
+ },
60
+ onProgress: (message) => console.log(message),
61
+ });
62
+
63
+ await writeCreds({ [provider]: { type: "oauth", ...creds } });
64
+ } finally {
65
+ rl.close();
66
+ }
67
+
68
+ return await readCreds();
69
+ }
70
+
71
+ export async function getApiKey(options: CliOptions) {
72
+ const provider = options.model.provider;
73
+ const auth = await readCreds();
74
+
75
+ if (isOAuthProvider(provider)) {
76
+ const result = await getOAuthApiKey(provider, auth);
77
+ if (result) {
78
+ auth[provider] = { type: "oauth", ...result.newCredentials };
79
+ await writeCreds(auth);
80
+
81
+ return result.apiKey;
82
+ }
83
+ }
84
+
85
+ const envApiKey = getEnvApiKey(provider);
86
+ if (envApiKey) return envApiKey;
87
+
88
+ const knownProviders = getProviders() as string[];
89
+ if (!knownProviders.includes(provider)) {
90
+ if (options.model.api === "openai-completions") {
91
+ // pi-ai requires a truthy apiKey for OpenAI-compatible local providers like Ollama.
92
+ return "dummy";
93
+ }
94
+
95
+ return undefined;
96
+ }
97
+
98
+ throw new Error("Not logged in");
99
+ }
100
+
101
+ export async function readCreds(): Promise<SavedOAuthCreds> {
102
+ const file = Bun.file(AUTH_FILE);
103
+ if (await file.exists()) {
104
+ return JSON.parse(await file.text());
105
+ }
106
+
107
+ return {};
108
+ }
109
+
110
+ async function writeCreds(creds: SavedOAuthCreds) {
111
+ await Bun.write(AUTH_FILE, JSON.stringify(await mergeCreds(creds)));
112
+ }
113
+
114
+ async function mergeCreds(newCreds: SavedOAuthCreds) {
115
+ const oldCreds = await readCreds();
116
+ return { ...oldCreds, ...newCreds };
117
+ }