xonecas.io
64875
Mc

mini-coder / commit f173e22

feat: headless mode one shot, no tools

xonecas2026-04-21 f173e224a630f5f64304278e6a03f12b0fc3cf49 parent 738bab5

5 files changed

src/args.ts+13−3
@@ -1,11 +1,21 @@
1-import { loginOAuth, readCreds } from "./oauth";
1+import { getModels, KnownProvider } from "@mariozechner/pi-ai";
2+import { loginOAuth } from "./oauth";
23 import type { CliOptions } from "./types.ts";
34
5+function getModelConfig(modelName: string, provider: KnownProvider) {
6+ const models = getModels(provider);
7+ if (models.length === 0) throw new Error("Provider has no models");
8+
9+ const model = models.find((m) => m.id === modelName);
10+ if (!model) throw new Error("Model not found");
11+
12+ return model;
13+}
14+
415 export async function handleArgv(argv: string[]): Promise<CliOptions> {
516 // TODO: Fetch defaults from settings file
617 let options: CliOptions = {
7- model: "gpt-5.4",
8- provider: "openai-codex",
18+ model: getModelConfig("gpt-5.4", "openai-codex"),
919 effort: "xhigh",
1020 };
1121
src/headless.ts+41−0
@@ -0,0 +1,41 @@
1+import { Context, stream } from "@mariozechner/pi-ai";
2+import { getApiKey } from "./oauth";
3+import type { CliOptions } from "./types";
4+
5+export async function streamHeadless(options: CliOptions) {
6+ const apiKey = await getApiKey(options);
7+ const context: Context = {
8+ // TODO: Centralize prompts
9+ systemPrompt:
10+ "You are friendly coding assistant, answer user questions and complete given tasks with accuracy.",
11+ messages: [
12+ { content: options.prompt ?? "", role: "user", timestamp: Date.now() },
13+ ],
14+ tools: [],
15+ };
16+
17+ const s = stream(options.model, context, { apiKey });
18+ for await (const ev of s) {
19+ switch (ev.type) {
20+ case "start":
21+ console.log("Starting headless mode");
22+ break;
23+ case "text_start":
24+ console.log("Answering...")
25+ break;
26+ case "thinking_start":
27+ console.log("Thinking... or trying to...")
28+ break;
29+ case "done":
30+ console.log("Done.")
31+ break;
32+ case "error":
33+ console.log(`Error ${ev.error}`)
34+ break;
35+ }
36+ }
37+
38+ const finalMessage = await s.result();
39+ context.messages.push(finalMessage)
40+ console.log(finalMessage.content)
41+}
src/index.ts+2−2
@@ -1,15 +1,15 @@
1-import { getOAuthApiKey } from "@mariozechner/pi-ai/oauth";
21 import { handleArgv } from "./args.ts";
2+import { streamHeadless } from "./headless.ts";
33 import { initTUI } from "./tui.ts";
44
55 export async function main(): Promise<void> {
66 const options = await handleArgv(process.argv.slice(2));
7- let apiKeys = {};
87
98 console.log(options);
109
1110 if (options.prompt) {
1211 // TODO: Headless mode/non-interactiv
12+ await streamHeadless(options);
1313 process.exit(0);
1414 }
1515
src/oauth.ts+3−2
@@ -43,11 +43,12 @@ export async function loginOAuth(provider: OAuthProviderId) {
4343 }
4444
4545 export async function getApiKey(options: CliOptions) {
46+ const provider = options.model.provider;
4647 const auth = await readCreds();
47- const result = await getOAuthApiKey(options.provider, auth);
48+ const result = await getOAuthApiKey(provider, auth);
4849 if (!result) throw new Error("Not logged in");
4950
50- auth[options.provider] = { type: "oauth", ...result.newCredentials };
51+ auth[provider] = { type: "oauth", ...result.newCredentials };
5152 await writeCreds(auth);
5253
5354 return result.apiKey;
src/types.ts+3−6
@@ -1,13 +1,10 @@
1-import type {
2- OAuthCredentials,
3- OAuthProviderId,
4-} from "@mariozechner/pi-ai/oauth";
1+import type { Model } from "@mariozechner/pi-ai";
2+import type { OAuthCredentials } from "@mariozechner/pi-ai/oauth";
53
64 export type CliOptions = {
75 prompt?: string;
8- model: string;
6+ model: Model<never>;
97 effort: string;
10- provider: OAuthProviderId;
118 };
129
1310 export type TUIOptions = {