summaryrefslogtreecommitdiffhomepage
path: root/js/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/index.ts')
-rw-r--r--js/src/index.ts43
1 files changed, 40 insertions, 3 deletions
diff --git a/js/src/index.ts b/js/src/index.ts
index b2a7c5f21..609abf14b 100644
--- a/js/src/index.ts
+++ b/js/src/index.ts
@@ -1,9 +1,10 @@
import { App } from "./app";
import { Server } from "./server/server";
-import { Cli, Command, runExit } from "clipanion";
+import { Cli, Command, Option, runExit } from "clipanion";
import fs from "fs/promises";
import path from "path";
import { Bus } from "./bus";
+import { Session } from "./session/session";
const cli = new Cli({
binaryLabel: `opencode`,
@@ -12,7 +13,7 @@ const cli = new Cli({
});
cli.register(
- class Run extends Command {
+ class extends Command {
async execute() {
const app = await App.create({
directory: process.cwd(),
@@ -25,7 +26,7 @@ cli.register(
},
);
cli.register(
- class Generate extends Command {
+ class extends Command {
static paths = [["generate"]];
async execute() {
const specs = await Server.openapi();
@@ -43,5 +44,41 @@ cli.register(
}
},
);
+
+cli.register(
+ class extends Command {
+ static paths = [["run"]];
+ message = Option.Rest();
+
+ async execute() {
+ const app = await App.create({
+ directory: process.cwd(),
+ });
+
+ await App.provide(app, async () => {
+ console.log("Thinking...");
+ const session = await Session.create();
+ const result = await Session.chat(session.id, {
+ type: "text",
+ text: this.message.join(" "),
+ });
+ for (const part of result.parts) {
+ if (part.type === "text") {
+ console.log("opencode:", part.text);
+ }
+ if (part.type === "tool-invocation") {
+ console.log(
+ "tool:",
+ part.toolInvocation.toolName,
+ part.toolInvocation.args,
+ );
+ }
+ }
+ });
+
+ process.exit(0);
+ }
+ },
+);
const [_bun, _app, ...args] = process.argv;
cli.runExit(args);