|
@@ -9,7 +9,6 @@ import yargs from "yargs"
|
|
|
import { hideBin } from "yargs/helpers"
|
|
import { hideBin } from "yargs/helpers"
|
|
|
import { RunCommand } from "./cli/cmd/run"
|
|
import { RunCommand } from "./cli/cmd/run"
|
|
|
import { GenerateCommand } from "./cli/cmd/generate"
|
|
import { GenerateCommand } from "./cli/cmd/generate"
|
|
|
-import { VERSION } from "./cli/version"
|
|
|
|
|
import { ScrapCommand } from "./cli/cmd/scrap"
|
|
import { ScrapCommand } from "./cli/cmd/scrap"
|
|
|
import { Log } from "./util/log"
|
|
import { Log } from "./util/log"
|
|
|
import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth"
|
|
import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth"
|
|
@@ -18,21 +17,11 @@ import { Provider } from "./provider/provider"
|
|
|
import { UI } from "./cli/ui"
|
|
import { UI } from "./cli/ui"
|
|
|
import { GlobalConfig } from "./global/config"
|
|
import { GlobalConfig } from "./global/config"
|
|
|
import { Installation } from "./installation"
|
|
import { Installation } from "./installation"
|
|
|
-;(async () => {
|
|
|
|
|
- if (Installation.VERSION === "dev") return
|
|
|
|
|
- if (Installation.isSnapshot()) return
|
|
|
|
|
- const config = await GlobalConfig.get()
|
|
|
|
|
- if (config.autoupdate === false) return
|
|
|
|
|
- const latest = await Installation.latest()
|
|
|
|
|
- if (Installation.VERSION === latest) return
|
|
|
|
|
- const method = await Installation.method()
|
|
|
|
|
- if (method === "unknown") return
|
|
|
|
|
- await Installation.upgrade(method, latest).catch(() => {})
|
|
|
|
|
-})()
|
|
|
|
|
|
|
+import { Bus } from "./bus"
|
|
|
|
|
|
|
|
const cli = yargs(hideBin(process.argv))
|
|
const cli = yargs(hideBin(process.argv))
|
|
|
.scriptName("opencode")
|
|
.scriptName("opencode")
|
|
|
- .version(VERSION)
|
|
|
|
|
|
|
+ .version(Installation.VERSION)
|
|
|
.option("print-logs", {
|
|
.option("print-logs", {
|
|
|
describe: "Print logs to stderr",
|
|
describe: "Print logs to stderr",
|
|
|
type: "boolean",
|
|
type: "boolean",
|
|
@@ -40,7 +29,7 @@ const cli = yargs(hideBin(process.argv))
|
|
|
.middleware(async () => {
|
|
.middleware(async () => {
|
|
|
await Log.init({ print: process.argv.includes("--print-logs") })
|
|
await Log.init({ print: process.argv.includes("--print-logs") })
|
|
|
Log.Default.info("opencode", {
|
|
Log.Default.info("opencode", {
|
|
|
- version: VERSION,
|
|
|
|
|
|
|
+ version: Installation.VERSION,
|
|
|
args: process.argv.slice(2),
|
|
args: process.argv.slice(2),
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -57,52 +46,62 @@ const cli = yargs(hideBin(process.argv))
|
|
|
while (true) {
|
|
while (true) {
|
|
|
const cwd = args.project ? path.resolve(args.project) : process.cwd()
|
|
const cwd = args.project ? path.resolve(args.project) : process.cwd()
|
|
|
process.chdir(cwd)
|
|
process.chdir(cwd)
|
|
|
- const result = await App.provide(
|
|
|
|
|
- { cwd, version: VERSION },
|
|
|
|
|
- async (app) => {
|
|
|
|
|
- const providers = await Provider.list()
|
|
|
|
|
- if (Object.keys(providers).length === 0) {
|
|
|
|
|
- return "needs_provider"
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const result = await App.provide({ cwd }, async (app) => {
|
|
|
|
|
+ const providers = await Provider.list()
|
|
|
|
|
+ if (Object.keys(providers).length === 0) {
|
|
|
|
|
+ return "needs_provider"
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- await Share.init()
|
|
|
|
|
- const server = Server.listen()
|
|
|
|
|
|
|
+ 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())) {
|
|
|
|
|
- await Bun.write(file, blob, { mode: 0o755 })
|
|
|
|
|
- await fs.chmod(binary, 0o755)
|
|
|
|
|
- }
|
|
|
|
|
- cwd = process.cwd()
|
|
|
|
|
- cmd = [binary]
|
|
|
|
|
|
|
+ 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())) {
|
|
|
|
|
+ await Bun.write(file, blob, { mode: 0o755 })
|
|
|
|
|
+ await fs.chmod(binary, 0o755)
|
|
|
}
|
|
}
|
|
|
- const proc = Bun.spawn({
|
|
|
|
|
- cmd: [...cmd, ...process.argv.slice(2)],
|
|
|
|
|
- cwd,
|
|
|
|
|
- stdout: "inherit",
|
|
|
|
|
- stderr: "inherit",
|
|
|
|
|
- stdin: "inherit",
|
|
|
|
|
- env: {
|
|
|
|
|
- ...process.env,
|
|
|
|
|
- OPENCODE_SERVER: server.url.toString(),
|
|
|
|
|
- OPENCODE_APP_INFO: JSON.stringify(app),
|
|
|
|
|
- },
|
|
|
|
|
- onExit: () => {
|
|
|
|
|
- server.stop()
|
|
|
|
|
- },
|
|
|
|
|
- })
|
|
|
|
|
- await proc.exited
|
|
|
|
|
- await server.stop()
|
|
|
|
|
|
|
+ cwd = process.cwd()
|
|
|
|
|
+ cmd = [binary]
|
|
|
|
|
+ }
|
|
|
|
|
+ const proc = Bun.spawn({
|
|
|
|
|
+ cmd: [...cmd, ...process.argv.slice(2)],
|
|
|
|
|
+ cwd,
|
|
|
|
|
+ stdout: "inherit",
|
|
|
|
|
+ stderr: "inherit",
|
|
|
|
|
+ stdin: "inherit",
|
|
|
|
|
+ env: {
|
|
|
|
|
+ ...process.env,
|
|
|
|
|
+ OPENCODE_SERVER: server.url.toString(),
|
|
|
|
|
+ OPENCODE_APP_INFO: JSON.stringify(app),
|
|
|
|
|
+ },
|
|
|
|
|
+ onExit: () => {
|
|
|
|
|
+ server.stop()
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ ;(async () => {
|
|
|
|
|
+ if (Installation.VERSION === "dev") return
|
|
|
|
|
+ if (Installation.isSnapshot()) return
|
|
|
|
|
+ const config = await GlobalConfig.get()
|
|
|
|
|
+ if (config.autoupdate === false) return
|
|
|
|
|
+ const latest = await Installation.latest()
|
|
|
|
|
+ if (Installation.VERSION === latest) return
|
|
|
|
|
+ const method = await Installation.method()
|
|
|
|
|
+ if (method === "unknown") return
|
|
|
|
|
+ await Installation.upgrade(method, latest).catch(() => {})
|
|
|
|
|
+ Bus.publish(Installation.Event.Updated, { version: latest })
|
|
|
|
|
+ })()
|
|
|
|
|
+
|
|
|
|
|
+ await proc.exited
|
|
|
|
|
+ await server.stop()
|
|
|
|
|
|
|
|
- return "done"
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return "done"
|
|
|
|
|
+ })
|
|
|
if (result === "done") break
|
|
if (result === "done") break
|
|
|
if (result === "needs_provider") {
|
|
if (result === "needs_provider") {
|
|
|
UI.empty()
|
|
UI.empty()
|