Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1c2c4c7
feat(opencli): add adapter discovery search
Astro-Han Jun 11, 2026
223648c
feat(opencli): run adapter commands
Astro-Han Jun 11, 2026
fff3e44
feat(opencli): guard adapter page capabilities
Astro-Han Jun 11, 2026
5892e41
build(opencli): package adapter runtime assets
Astro-Han Jun 11, 2026
5165bee
fix(opencli): keep desktop adapter runtime resolvable
Astro-Han Jun 11, 2026
f24e6fd
fix(opencli): align adapter tools with browser permission
Astro-Han Jun 11, 2026
2248cce
fix(opencli): copy adapter runtime into desktop build
Astro-Han Jun 11, 2026
2b854ae
ci(opencli): cover adapter tests on windows
Astro-Han Jun 11, 2026
a9eb255
build(opencli): prune non-runtime package files
Astro-Han Jun 11, 2026
fc09560
fix(opencli): reject blank numeric adapter args
Astro-Han Jun 11, 2026
bff3c3c
fix(opencli): index implicit browser commands
Astro-Han Jun 11, 2026
d4de5ae
fix(opencli): widen adapter browser permissions
Astro-Han Jun 11, 2026
85d2313
fix(opencli): describe adapter args in search
Astro-Han Jun 11, 2026
4d0a4fa
refactor(opencli): expose adapter namespaces
Astro-Han Jun 11, 2026
ccbab97
refactor(opencli): locate adapter package by manifest
Astro-Han Jun 11, 2026
2c44257
test(opencli): document accepted closeWindow gap
Astro-Han Jun 11, 2026
04591b4
test(opencli): use effect tool harness
Astro-Han Jun 11, 2026
5646222
fix(opencli): gate adapter side effects
Astro-Han Jun 11, 2026
f28128e
fix(opencli): tolerate failed adapter imports
Astro-Han Jun 11, 2026
2a2a673
fix(opencli): avoid permissive null permission fallback
Astro-Han Jun 11, 2026
756b6b6
fix(opencli): tighten adapter permission helper type
Astro-Han Jun 11, 2026
6102e71
test(opencli): normalize adapter import URL expectations
Astro-Han Jun 11, 2026
d54b3b6
fix(opencli): tighten adapter write guardrails
Astro-Han Jun 12, 2026
c8a3204
fix(opencli): surface adapter load failures
Astro-Han Jun 12, 2026
4e211eb
refactor(opencli): reuse browser action runner
Astro-Han Jun 12, 2026
44adda9
fix(opencli): gate adapter imports behind permissions
Astro-Han Jun 12, 2026
b8a16c3
refactor(desktop): share opencli runtime filters
Astro-Han Jun 12, 2026
9d87079
fix(opencli): format empty adapter output
Astro-Han Jun 12, 2026
9a2cc6d
fix(opencli): match persistent pre-nav origin
Astro-Han Jun 12, 2026
f69e743
fix(opencli): ask with final command args
Astro-Han Jun 12, 2026
b44a159
fix(opencli): clarify write adapter cancellation
Astro-Han Jun 12, 2026
8d575c8
test(opencli): type command summary fixtures
Astro-Han Jun 12, 2026
8d48226
docs: credit bundled OpenCLI runtime
Astro-Han Jun 12, 2026
de743a0
refactor(opencli): ask once for run permission
Astro-Han Jun 12, 2026
3c839ad
refactor(opencli): keep search manifest-only
Astro-Han Jun 12, 2026
19cb08f
refactor(opencli): remove adapter load diagnostics
Astro-Han Jun 12, 2026
9b87953
test(opencli): remove search warning legacy cast
Astro-Han Jun 12, 2026
ba93036
refactor(opencli): reuse command summary metadata
Astro-Han Jun 12, 2026
caba1b4
fix(opencli): tighten browser adapter boundaries
Astro-Han Jun 12, 2026
c5351a5
test(opencli): pin global registry contract
Astro-Han Jun 12, 2026
0c8edf1
fix(opencli): enforce adapter execution boundaries
Astro-Han Jun 12, 2026
8e8472c
docs(opencli): narrow adapter coverage claims
Astro-Han Jun 12, 2026
8ad3599
fix(opencli): recheck browser adapter landings
Astro-Han Jun 12, 2026
222f223
refactor(opencli): drop unreachable write interruption branch
Astro-Han Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/windows-advisory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ jobs:
test/worktree
test/file/
test/github
test/opencli
test/settings
test/settings.test.ts
report_path: packages/opencode/.artifacts/unit/junit-windows-config-project.xml
Expand Down
56 changes: 56 additions & 0 deletions packages/desktop-electron/electron-builder-app-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
getPublishConfig,
nativeWatcherFileSets,
nativeWatcherPackageNames,
openCliRuntimeFileSets,
openCliRuntimePackageNames,
} from "./electron-builder.config"
import { serializeAppUpdateConfig } from "./scripts/write-app-update-config"

Expand Down Expand Up @@ -136,6 +138,60 @@ describe("electron builder app-update config", () => {
)
})

test("packages OpenCLI adapters and runtime dependencies for the embedded server", () => {
const config = createConfig("prod")
const resources = openCliRuntimeFileSets()

expect(openCliRuntimePackageNames()).toEqual([
"@jackwener/opencli",
"@mixmark-io/domino",
"@mozilla/readability",
"ansi-regex",
"argparse",
"cli-table3",
"commander",
"emoji-regex",
"is-fullwidth-code-point",
"js-yaml",
"string-width",
"strip-ansi",
"turndown",
"turndown-plugin-gfm",
"undici",
"ws",
])
expect(config.extraResources).toEqual(
expect.arrayContaining(
resources.map((resource) =>
expect.objectContaining({
from: resource.from,
to: resource.to,
}),
),
),
)
expect(resources.map((resource) => resource.to)).toEqual(
openCliRuntimePackageNames().map((packageName) => join("node_modules", ...packageName.split("/"))),
)
})

test("packages only OpenCLI runtime files", () => {
const resources = openCliRuntimeFileSets()

for (const resource of resources) {
expect(resource.filter).toEqual(
expect.arrayContaining([
"!**/.yarn/**",
"!**/{test,tests,__tests__,coverage}/**",
"!**/*.{test,spec}.{js,mjs,cjs,ts,tsx}",
]),
)
}
expect(resources.find((resource) => resource.to.endsWith(join("@jackwener", "opencli")))?.filter).toContain(
"!clis/test-utils.js",
)
})

test("afterPack writes app-update.yml to the packager-reported macOS resources path", async () => {
const root = mkdtempSync(join(tmpdir(), "pawwork-builder-config-"))
roots.push(root)
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop-electron/electron-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { promisify } from "node:util"

import type { Configuration } from "electron-builder"
import { writeAppUpdateConfig, type GitHubPublishConfig } from "./scripts/write-app-update-config"
import { openCliRuntimeFileSets, openCliRuntimePackageNames } from "./opencli-runtime"

export { openCliRuntimeFileSets, openCliRuntimePackageNames } from "./opencli-runtime"

const execFileAsync = promisify(execFile)
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..")
Expand Down Expand Up @@ -118,6 +121,7 @@ const getBase = (channel: Channel): Configuration => ({
},
extraResources: [
...nativeWatcherFileSets(),
...openCliRuntimeFileSets(),
{
from: path.join(rootDir, "skills"),
to: "skills",
Expand Down
9 changes: 8 additions & 1 deletion packages/desktop-electron/electron-vite.config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "bun:test"
import { realpathSync } from "node:fs"
import { readFileSync, realpathSync } from "node:fs"
import path from "node:path"
import { createRendererWorkspaceConfig } from "./renderer-workspace-config"

Expand All @@ -15,3 +15,10 @@ test("renderer dedupes the ui workspace package", () => {

expect(dedupe).toContain("@opencode-ai/ui")
})

test("main build does not externalize OpenCLI from the desktop bundle", () => {
const source = readFileSync(path.join(import.meta.dir, "electron.vite.config.ts"), "utf8")

expect(source).toContain("externalizeDeps: { include: [nodePtyPkg] }")
expect(source).not.toContain("OPENCLI_EXTERNALS")
})
33 changes: 33 additions & 0 deletions packages/desktop-electron/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
embeddedServerMissingArtifactsMessage,
} from "./src/main/embedded-server-contract"
import { createRendererWorkspaceConfig } from "./renderer-workspace-config"
import { includeOpenCliRuntimeDirectory, includeOpenCliRuntimeFile, openCliRuntimePackages } from "./opencli-runtime"

const channel = (() => {
const raw = process.env.OPENCODE_CHANNEL
Expand All @@ -29,6 +30,28 @@ if (missingArtifacts.length > 0) {
const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
const rendererWorkspaceConfig = createRendererWorkspaceConfig(process.cwd(), realpathSync)

async function copyOpenCliRuntimePackage(pkg: ReturnType<typeof openCliRuntimePackages>[number], target: string) {
const stack = [{ source: pkg.dir, destination: target, relativePath: "" }]
while (stack.length > 0) {
const current = stack.pop()!
await fs.mkdir(current.destination, { recursive: true })
for (const entry of await fs.readdir(current.source, { withFileTypes: true })) {
const source = path.join(current.source, entry.name)
const destination = path.join(current.destination, entry.name)
const relativePath = current.relativePath ? path.join(current.relativePath, entry.name) : entry.name
if (entry.isDirectory()) {
if (includeOpenCliRuntimeDirectory(pkg.name, relativePath)) {
stack.push({ source, destination, relativePath })
}
continue
}
if (entry.isFile() && includeOpenCliRuntimeFile(pkg.name, relativePath)) {
await fs.copyFile(source, destination)
}
}
}
}

export default defineConfig({
main: {
define: {
Expand Down Expand Up @@ -66,6 +89,16 @@ export default defineConfig({
}
},
},
{
name: "opencode:copy-opencli-runtime",
async writeBundle() {
for (const pkg of openCliRuntimePackages()) {
const target = path.join("./out/main/chunks/node_modules", ...pkg.name.split("/"))
await fs.rm(target, { recursive: true, force: true })
await copyOpenCliRuntimePackage(pkg, target)
}
},
},
],
},
preload: {
Expand Down
136 changes: 136 additions & 0 deletions packages/desktop-electron/opencli-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { existsSync, readFileSync } from "node:fs"
import { createRequire } from "node:module"
import path from "node:path"
import { fileURLToPath } from "node:url"

type PackageJson = {
name?: string
dependencies?: Record<string, string>
}

const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..")

function readPackageJson(packageDir: string): PackageJson {
return JSON.parse(readFileSync(path.join(packageDir, "package.json"), "utf8")) as PackageJson
}

function packageRootFromResolvedEntry(packageName: string, resolvedEntry: string) {
let dir = path.dirname(resolvedEntry)
while (true) {
const packageJsonPath = path.join(dir, "package.json")
if (existsSync(packageJsonPath)) {
const json = JSON.parse(readFileSync(packageJsonPath, "utf8")) as PackageJson
if (json.name === packageName) return dir
}

const parent = path.dirname(dir)
if (parent === dir) {
throw new Error(`Could not find package root for ${packageName} from ${resolvedEntry}`)
}
dir = parent
}
}

function resolvePackageRoot(packageName: string, issuerPackageDir: string) {
const resolver = createRequire(path.join(issuerPackageDir, "package.json"))
const resolvedEntry = resolver.resolve(packageName)
if (path.isAbsolute(resolvedEntry)) return packageRootFromResolvedEntry(packageName, resolvedEntry)
// Bun resolves its built-in `undici` compatibility entry to the bare
// specifier. The installed package still exposes package.json in this layout,
// so use it only as a narrow fallback for non-path results.
return path.dirname(resolver.resolve(`${packageName}/package.json`))
}

export function openCliRuntimePackages() {
const packages: Array<{ name: string; dir: string; json: PackageJson }> = []
const seen = new Map<string, string>()

function visit(packageName: string, issuerPackageDir: string) {
const dir = resolvePackageRoot(packageName, issuerPackageDir)
const previous = seen.get(packageName)
if (previous) {
if (previous !== dir) throw new Error(`Multiple runtime copies found for ${packageName}: ${previous}, ${dir}`)
return
}

const json = readPackageJson(dir)
seen.set(packageName, dir)
packages.push({ name: packageName, dir, json })
for (const dependency of Object.keys(json.dependencies ?? {}).sort()) {
visit(dependency, dir)
}
}

visit("@jackwener/opencli", path.join(rootDir, "packages", "opencode"))
return packages.sort((a, b) => a.name.localeCompare(b.name))
}

export function openCliRuntimePackageNames() {
return openCliRuntimePackages().map((pkg) => pkg.name)
}

const runtimeOnlyExcludes = [
"!**/.yarn/**",
"!**/{test,tests,__tests__,coverage}/**",
"!**/*.{test,spec}.{js,mjs,cjs,ts,tsx}",
]

function normalizeRelativePath(relativePath: string) {
return relativePath.split(path.sep).join("/")
}

function isNonRuntimePath(relativePath: string) {
const normalized = normalizeRelativePath(relativePath)
const parts = normalized.split("/")
if (parts.some((part) => part === ".yarn" || part === "test" || part === "tests" || part === "__tests__" || part === "coverage")) {
return true
}
const basename = parts.at(-1) ?? ""
return /\.(test|spec)\.(js|mjs|cjs|ts|tsx)$/.test(basename)
}

export function includeOpenCliRuntimeFile(packageName: string, relativePath: string) {
const normalized = normalizeRelativePath(relativePath)
if (isNonRuntimePath(normalized)) return false
if (packageName !== "@jackwener/opencli") return true
if (normalized === "clis/test-utils.js") return false
return (
normalized === "package.json" ||
normalized === "README.md" ||
normalized === "LICENSE" ||
normalized === "cli-manifest.json" ||
normalized.startsWith("clis/") ||
normalized.startsWith("dist/src/")
)
}

export function includeOpenCliRuntimeDirectory(packageName: string, relativePath: string) {
const normalized = normalizeRelativePath(relativePath)
if (normalized === "") return true
if (isNonRuntimePath(normalized)) return false
if (packageName !== "@jackwener/opencli") return true
return (
normalized === "clis" ||
normalized.startsWith("clis/") ||
normalized === "dist" ||
normalized === "dist/src" ||
normalized.startsWith("dist/src/")
)
}

function openCliRuntimeFilter(packageName: string) {
const includes =
packageName === "@jackwener/opencli"
? ["package.json", "README.md", "LICENSE", "cli-manifest.json", "clis/**/*", "dist/src/**/*"]
: ["**/*"]
const packageExcludes = packageName === "@jackwener/opencli" ? ["!clis/test-utils.js"] : []
return [...includes, ...runtimeOnlyExcludes, ...packageExcludes]
}

export function openCliRuntimeFileSets() {
return openCliRuntimePackages().map((pkg) => ({
from: pkg.dir,
to: path.join("node_modules", ...pkg.name.split("/")),
filter: openCliRuntimeFilter(pkg.name),
}))
}
14 changes: 14 additions & 0 deletions packages/desktop-electron/src/main/embedded-server-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ test("electron-vite build copies required embedded server wasm sidecars into out
for (const matches of requiredWasmMatchers) {
expect(files.some((file) => matches(file))).toBe(true)
}
expect(fs.existsSync(path.join(outChunksDir, "node_modules", "@jackwener", "opencli", "cli-manifest.json"))).toBe(
true,
)
expect(
fs.existsSync(path.join(outChunksDir, "node_modules", "@jackwener", "opencli", "clis", "twitter", "like.js")),
).toBe(true)
expect(
fs.existsSync(path.join(outChunksDir, "node_modules", "@jackwener", "opencli", "clis", "twitter", "like.test.js")),
).toBe(false)
expect(fs.existsSync(path.join(outChunksDir, "node_modules", "@mixmark-io", "domino", "package.json"))).toBe(true)
expect(fs.existsSync(path.join(outChunksDir, "node_modules", "@mixmark-io", "domino", "lib", "index.js"))).toBe(
true,
)
expect(fs.existsSync(path.join(outChunksDir, "node_modules", "@mixmark-io", "domino", "test"))).toBe(false)

expectModelsSnapshotUnchanged(modelsFixture)
})
Expand Down
20 changes: 19 additions & 1 deletion packages/opencode/script/build-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const dir = path.resolve(__dirname, "..")

const OPENCLI_EXTERNALS = [
"@jackwener/opencli",
"@jackwener/opencli/browser/cdp",
"@jackwener/opencli/browser/page",
"@jackwener/opencli/browser/utils",
"@jackwener/opencli/download",
"@jackwener/opencli/download/article-download",
"@jackwener/opencli/download/media-download",
"@jackwener/opencli/download/progress",
"@jackwener/opencli/errors",
"@jackwener/opencli/launcher",
"@jackwener/opencli/logger",
"@jackwener/opencli/pipeline",
"@jackwener/opencli/registry",
"@jackwener/opencli/types",
"@jackwener/opencli/utils",
]

process.chdir(dir)

await import("./generate.ts")
Expand Down Expand Up @@ -55,7 +73,7 @@ await Bun.build({
outdir: "./dist/node",
format: "esm",
sourcemap: "linked",
external: ["jsonc-parser", "@lydell/node-pty"],
external: ["jsonc-parser", "@lydell/node-pty", ...OPENCLI_EXTERNALS],
define: {
OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_PLUGIN_VERSION: `'${pluginPkg.version}'`,
Expand Down
Loading
Loading