mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-30 22:24:19 +01:00
feat: nix support for the nix folks (#3924)
Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
This commit is contained in:
@@ -57,11 +57,16 @@ export const TuiThreadCommand = cmd({
|
||||
// Resolve relative paths against PWD to preserve behavior when using --cwd flag
|
||||
const baseCwd = process.env.PWD ?? process.cwd()
|
||||
const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
|
||||
let workerPath: string | URL = new URL("./worker.ts", import.meta.url)
|
||||
|
||||
if (typeof OPENCODE_WORKER_PATH !== "undefined") {
|
||||
workerPath = OPENCODE_WORKER_PATH
|
||||
}
|
||||
const defaultWorker = new URL("./worker.ts", import.meta.url)
|
||||
// Nix build creates a bundled worker next to the binary; prefer it when present.
|
||||
const execDir = path.dirname(process.execPath)
|
||||
const bundledWorker = path.join(execDir, "opencode-worker.js")
|
||||
const hasBundledWorker = await Bun.file(bundledWorker).exists()
|
||||
const workerPath = (() => {
|
||||
if (typeof OPENCODE_WORKER_PATH !== "undefined") return OPENCODE_WORKER_PATH
|
||||
if (hasBundledWorker) return bundledWorker
|
||||
return defaultWorker
|
||||
})()
|
||||
try {
|
||||
process.chdir(cwd)
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
export async function data() {
|
||||
const path = Bun.env.MODELS_DEV_API_JSON
|
||||
if (path) {
|
||||
const file = Bun.file(path)
|
||||
if (await file.exists()) {
|
||||
return await file.text()
|
||||
}
|
||||
}
|
||||
const json = await fetch("https://models.dev/api.json").then((x) => x.text())
|
||||
return json
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { $ } from "bun"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { Wildcard } from "@/util/wildcard"
|
||||
import { Permission } from "@/permission"
|
||||
import { fileURLToPath } from "url"
|
||||
|
||||
const MAX_OUTPUT_LENGTH = 30_000
|
||||
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
||||
@@ -19,20 +20,29 @@ const SIGKILL_TIMEOUT_MS = 200
|
||||
|
||||
export const log = Log.create({ service: "bash-tool" })
|
||||
|
||||
const resolveWasm = (asset: string) => {
|
||||
if (asset.startsWith("file://")) return fileURLToPath(asset)
|
||||
if (asset.startsWith("/")) return asset
|
||||
const url = new URL(asset, import.meta.url)
|
||||
return fileURLToPath(url)
|
||||
}
|
||||
|
||||
const parser = lazy(async () => {
|
||||
const { Parser } = await import("web-tree-sitter")
|
||||
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, {
|
||||
with: { type: "wasm" },
|
||||
})
|
||||
const treePath = resolveWasm(treeWasm)
|
||||
await Parser.init({
|
||||
locateFile() {
|
||||
return treeWasm
|
||||
return treePath
|
||||
},
|
||||
})
|
||||
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
|
||||
with: { type: "wasm" },
|
||||
})
|
||||
const bashLanguage = await Language.load(bashWasm)
|
||||
const bashPath = resolveWasm(bashWasm)
|
||||
const bashLanguage = await Language.load(bashPath)
|
||||
const p = new Parser()
|
||||
p.setLanguage(bashLanguage)
|
||||
return p
|
||||
|
||||
Reference in New Issue
Block a user