summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-06 23:58:09 -0400
committerDax Raad <[email protected]>2025-06-06 23:58:09 -0400
commitf22c93ba1b20df15d7e4f9d3f22e2b6cd28cc464 (patch)
tree6a51434c878317f926a0cddcd3af18e142b9b9f6
parentb34d5c959bd273a39530af398e8dd91f78886e53 (diff)
downloadopencode-f22c93ba1b20df15d7e4f9d3f22e2b6cd28cc464.tar.gz
opencode-f22c93ba1b20df15d7e4f9d3f22e2b6cd28cc464.zip
logs
-rwxr-xr-xpackages/opencode/script/release.ts2
-rw-r--r--packages/opencode/src/cli/cmd/run.ts153
-rw-r--r--packages/opencode/src/index.ts75
3 files changed, 125 insertions, 105 deletions
diff --git a/packages/opencode/script/release.ts b/packages/opencode/script/release.ts
index d4aea8bcc..39a9acf43 100755
--- a/packages/opencode/script/release.ts
+++ b/packages/opencode/script/release.ts
@@ -6,7 +6,7 @@ import pkg from "../package.json"
const dry = process.argv.includes("--dry")
-const version = `0.0.0-${Date.now()}`
+const version = `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
const GOARCH: Record<string, string> = {
arm64: "arm64",
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts
index 7016c250d..b358f629f 100644
--- a/packages/opencode/src/cli/cmd/run.ts
+++ b/packages/opencode/src/cli/cmd/run.ts
@@ -24,85 +24,98 @@ export const RunCommand = {
type: "string",
})
},
- handler: async (args: { message: string[]; session?: string }) => {
+ handler: async (args: {
+ message: string[]
+ session?: string
+ printLogs?: boolean
+ }) => {
const message = args.message.join(" ")
- await App.provide({ cwd: process.cwd(), version: "0.0.0" }, async () => {
- await Share.init()
- const session = args.session
- ? await Session.get(args.session)
- : await Session.create()
+ await App.provide(
+ {
+ cwd: process.cwd(),
+ version: "0.0.0",
+ printLogs: args.printLogs,
+ },
+ async () => {
+ await Share.init()
+ const session = args.session
+ ? await Session.get(args.session)
+ : await Session.create()
- UI.print(UI.Style.TEXT_HIGHLIGHT_BOLD + "◍ OpenCode", VERSION)
- UI.empty()
- UI.print(UI.Style.TEXT_NORMAL_BOLD + "> ", message)
- UI.empty()
- UI.print(
- UI.Style.TEXT_INFO_BOLD +
- "~ https://dev.opencode.ai/s?id=" +
- session.id.slice(-8),
- )
- UI.empty()
-
- function printEvent(color: string, type: string, title: string) {
+ UI.print(UI.Style.TEXT_HIGHLIGHT_BOLD + "◍ OpenCode", VERSION)
+ UI.empty()
+ UI.print(UI.Style.TEXT_NORMAL_BOLD + "> ", message)
+ UI.empty()
UI.print(
- color + `|`,
- UI.Style.TEXT_NORMAL + UI.Style.TEXT_DIM + ` ${type.padEnd(7, " ")}`,
- "",
- UI.Style.TEXT_NORMAL + title,
+ UI.Style.TEXT_INFO_BOLD +
+ "~ https://dev.opencode.ai/s?id=" +
+ session.id.slice(-8),
)
- }
+ UI.empty()
- Bus.subscribe(Message.Event.PartUpdated, async (message) => {
- const part = message.properties.part
- if (
- part.type === "tool-invocation" &&
- part.toolInvocation.state === "result"
- ) {
- if (part.toolInvocation.toolName === "opencode_todowrite") return
+ function printEvent(color: string, type: string, title: string) {
+ UI.print(
+ color + `|`,
+ UI.Style.TEXT_NORMAL +
+ UI.Style.TEXT_DIM +
+ ` ${type.padEnd(7, " ")}`,
+ "",
+ UI.Style.TEXT_NORMAL + title,
+ )
+ }
- const args = part.toolInvocation.args as any
- const tool = part.toolInvocation.toolName
+ Bus.subscribe(Message.Event.PartUpdated, async (message) => {
+ const part = message.properties.part
+ if (
+ part.type === "tool-invocation" &&
+ part.toolInvocation.state === "result"
+ ) {
+ if (part.toolInvocation.toolName === "opencode_todowrite") return
- if (tool === "opencode_edit")
- printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Edit", args.filePath)
- if (tool === "opencode_bash")
- printEvent(UI.Style.TEXT_WARNING_BOLD, "Execute", args.command)
- if (tool === "opencode_read")
- printEvent(UI.Style.TEXT_INFO_BOLD, "Read", args.filePath)
- if (tool === "opencode_write")
- printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Create", args.filePath)
- if (tool === "opencode_glob")
- printEvent(
- UI.Style.TEXT_INFO_BOLD,
- "Glob",
- args.pattern + (args.path ? " in " + args.path : ""),
- )
- }
+ const args = part.toolInvocation.args as any
+ const tool = part.toolInvocation.toolName
- if (part.type === "text") {
- if (part.text.includes("\n")) {
- UI.empty()
- UI.print(part.text)
- UI.empty()
- return
+ if (tool === "opencode_edit")
+ printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Edit", args.filePath)
+ if (tool === "opencode_bash")
+ printEvent(UI.Style.TEXT_WARNING_BOLD, "Execute", args.command)
+ if (tool === "opencode_read")
+ printEvent(UI.Style.TEXT_INFO_BOLD, "Read", args.filePath)
+ if (tool === "opencode_write")
+ printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Create", args.filePath)
+ if (tool === "opencode_glob")
+ printEvent(
+ UI.Style.TEXT_INFO_BOLD,
+ "Glob",
+ args.pattern + (args.path ? " in " + args.path : ""),
+ )
}
- printEvent(UI.Style.TEXT_NORMAL_BOLD, "Text", part.text)
- }
- })
- const { providerID, modelID } = await Provider.defaultModel()
- await Session.chat({
- sessionID: session.id,
- providerID,
- modelID,
- parts: [
- {
- type: "text",
- text: message,
- },
- ],
- })
- UI.empty()
- })
+ if (part.type === "text") {
+ if (part.text.includes("\n")) {
+ UI.empty()
+ UI.print(part.text)
+ UI.empty()
+ return
+ }
+ printEvent(UI.Style.TEXT_NORMAL_BOLD, "Text", part.text)
+ }
+ })
+
+ const { providerID, modelID } = await Provider.defaultModel()
+ await Session.chat({
+ sessionID: session.id,
+ providerID,
+ modelID,
+ parts: [
+ {
+ type: "text",
+ text: message,
+ },
+ ],
+ })
+ UI.empty()
+ },
+ )
},
}
diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts
index e7b6369a1..f96b9e870 100644
--- a/packages/opencode/src/index.ts
+++ b/packages/opencode/src/index.ts
@@ -22,42 +22,49 @@ yargs(hideBin(process.argv))
.command({
command: "$0",
describe: "Start OpenCode TUI",
- handler: async () => {
- await App.provide({ cwd: process.cwd(), version: VERSION }, async () => {
- await Share.init()
- const server = Server.listen()
+ builder: (yargs) =>
+ yargs.option("print-logs", {
+ type: "boolean",
+ }),
+ handler: async (args) => {
+ await App.provide(
+ { cwd: process.cwd(), version: VERSION, printLogs: args.printLogs },
+ async () => {
+ await Share.init()
+ const server = Server.listen()
- let cmd = ["go", "run", "./main.go"]
- let cwd = new URL("../../tui/cmd/opencode", import.meta.url).pathname
- if (Bun.embeddedFiles.length > 0) {
- const blob = Bun.embeddedFiles[0] as File
- const binary = path.join(Global.Path.cache, "tui", blob.name)
- const file = Bun.file(binary)
- if (!(await file.exists())) {
- console.log("installing tui binary...")
- await Bun.write(file, blob, { mode: 0o755 })
- await fs.chmod(binary, 0o755)
+ let cmd = ["go", "run", "./main.go"]
+ let cwd = new URL("../../tui/cmd/opencode", import.meta.url).pathname
+ if (Bun.embeddedFiles.length > 0) {
+ const blob = Bun.embeddedFiles[0] as File
+ const binary = path.join(Global.Path.cache, "tui", blob.name)
+ const file = Bun.file(binary)
+ if (!(await file.exists())) {
+ console.log("installing tui binary...")
+ await Bun.write(file, blob, { mode: 0o755 })
+ await fs.chmod(binary, 0o755)
+ }
+ cwd = process.cwd()
+ cmd = [binary]
}
- cwd = process.cwd()
- cmd = [binary]
- }
- const proc = Bun.spawn({
- cmd,
- cwd,
- stdout: "inherit",
- stderr: "inherit",
- stdin: "inherit",
- env: {
- ...process.env,
- OPENCODE_SERVER: server.url.toString(),
- },
- onExit: () => {
- server.stop()
- },
- })
- await proc.exited
- await server.stop()
- })
+ const proc = Bun.spawn({
+ cmd,
+ cwd,
+ stdout: "inherit",
+ stderr: "inherit",
+ stdin: "inherit",
+ env: {
+ ...process.env,
+ OPENCODE_SERVER: server.url.toString(),
+ },
+ onExit: () => {
+ server.stop()
+ },
+ })
+ await proc.exited
+ await server.stop()
+ },
+ )
},
})
.command(RunCommand)