Skip to content

Commit 082b8fc

Browse files
committed
fix(cli): dynamic WASM discovery in oclite build and fix check_task polling (#59)
1 parent 83658c8 commit 082b8fc

2 files changed

Lines changed: 45 additions & 15 deletions

File tree

‎packages/opencode/script/build-lite.ts‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
#!/usr/bin/env bun
22
import path from "path"
3-
import fs from "fs"
43
import { $ } from "bun"
54

65
const ROOT = path.resolve(import.meta.dirname, "..")
76
const DIST = path.join(ROOT, "dist", "oclite-darwin-arm64")
87
const BIN = path.join(DIST, "bin")
9-
const HOME_BIN = path.join(process.env.HOME!, "bin")
8+
9+
const home = process.env.HOME
10+
if (!home) {
11+
console.error("Error: HOME environment variable not set")
12+
process.exit(1)
13+
}
14+
const HOME_BIN = path.join(home, "bin")
15+
16+
async function copyWasm(src: string, dest: string): Promise<boolean> {
17+
try {
18+
await Bun.write(dest, Bun.file(src))
19+
return true
20+
} catch {
21+
return false
22+
}
23+
}
1024

1125
async function build() {
1226
console.log("Building oclite...")
1327

14-
// Clean
15-
await fs.promises.rm(DIST, { recursive: true, force: true })
16-
await fs.promises.mkdir(BIN, { recursive: true })
28+
await $`rm -rf ${DIST}`
29+
await $`mkdir -p ${BIN}`
1730

18-
// Build
1931
const result = await Bun.build({
2032
entrypoints: [path.join(ROOT, "src/cli/lite/index.ts")],
2133
outdir: BIN,
@@ -33,23 +45,39 @@ async function build() {
3345
process.exit(1)
3446
}
3547

36-
// Make executable
3748
await $`chmod +x ${path.join(BIN, "oclite")}`
3849

39-
// Copy to ~/bin
40-
await fs.promises.mkdir(HOME_BIN, { recursive: true })
41-
await fs.promises.copyFile(path.join(BIN, "oclite"), path.join(HOME_BIN, "oclite"))
50+
// Discover WASM assets produced by bundler
51+
const wasmOutputs = result.outputs.filter((o) => o.path.endsWith(".wasm"))
52+
if (wasmOutputs.length === 0) {
53+
console.error("Error: No WASM files in build output. Tree-sitter requires WASM at runtime.")
54+
process.exit(1)
55+
}
56+
57+
// Install binary to ~/bin
58+
await $`mkdir -p ${HOME_BIN}`
59+
await Bun.write(path.join(HOME_BIN, "oclite"), Bun.file(path.join(BIN, "oclite")))
60+
await $`chmod +x ${path.join(HOME_BIN, "oclite")}`
61+
62+
// Copy WASM assets to ~/bin
63+
for (const wasm of wasmOutputs) {
64+
const name = path.basename(wasm.path)
65+
const success = await copyWasm(wasm.path, path.join(HOME_BIN, name))
66+
if (!success) {
67+
console.error(`Error: Failed to copy WASM file: ${name}`)
68+
process.exit(1)
69+
}
70+
}
4271

43-
// Sign for macOS
4472
await $`codesign --force --deep --sign - ${path.join(HOME_BIN, "oclite")}`.quiet().nothrow()
4573
await $`xattr -cr ${path.join(HOME_BIN, "oclite")}`.quiet().nothrow()
4674

47-
// Get size
48-
const stat = await fs.promises.stat(path.join(HOME_BIN, "oclite"))
49-
const sizeMB = (stat.size / 1024 / 1024).toFixed(2)
75+
const size = Bun.file(path.join(HOME_BIN, "oclite")).size
76+
const sizeMB = (size / 1024 / 1024).toFixed(2)
5077

5178
console.log(`✓ Built oclite (${sizeMB} MB)`)
5279
console.log(`✓ Installed to ~/bin/oclite`)
80+
console.log(`✓ Copied ${wasmOutputs.length} WASM files`)
5381
console.log("\nRun with: ~/bin/oclite")
5482
}
5583

‎packages/opencode/src/tool/check_task.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
- Tasks **automatically notify you** when they complete — do NOT poll
2+
- Use only for rare cases: uncertainty about task status, explicit user request, or verifying very long-running tasks
3+
- **Never call this tool in loops or repeatedly** — let auto-notification handle task completion
14
- Query the status of a background task by its ID
25
- Status returns: "running", "completed", "failed", or "not_found"
36
- For completed tasks, includes the result from the agent's final text output
47
- For failed tasks, includes error information
5-
- Use this tool to poll the status of tasks created by the task tool

0 commit comments

Comments
 (0)