Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ You can set an initial folder with an absolute path instead of choosing one in S
```

The folder chosen in Settings takes precedence over this option.

## Development

```sh
bun run check
bun run test:styles
bun run test:storage /path/to/opencode
```

`check` includes native Node filesystem-watcher tests and rebuilds the GUI bundle. `test:styles` runs that bundle's setup, wallpaper switching, stylesheet cleanup, and gallery-toggle checks in headless Chrome; set `CHROME_BIN` if Chrome is installed elsewhere. `test:storage` checks migration against an OpenCode checkout's actual persistence decoder. Pass the checkout path or set `OPENCODE_CHECKOUT`.
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 15 additions & 21 deletions dist/gui-experimental.cjs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
],
"scripts": {
"build:gui": "bun --bun vite build",
"check": "bun run test && bun run typecheck && bun run build:gui && bun run check:package",
"check": "bun run typecheck && bun run build:gui && bun run test && bun run test:node && bun run check:package",
"check:package": "bun script/check-package.ts",
"typecheck": "tsc --noEmit",
"test": "bun test --conditions=browser src"
"test": "bun test --conditions=browser src",
"test:styles": "bun script/check-styles.ts",
"test:node": "bun script/check-catalog-node.ts",
"test:storage": "bun script/check-preferences.ts"
},
"peerDependencies": {
"@opencode/plugin": "~2.2.6 || ~2.3.2 || ^0.0.0-dev",
Expand All @@ -44,6 +47,7 @@
"@types/bun": "1.4.3",
"@typescript/native": "npm:typescript@7.1.0-beta",
"effect": "4.1.0",
"playwright-core": "1.65.1",
"solid-js": "1.9.17",
"vite": "7.3.7",
"vite-plugin-solid": "2.11.10"
Expand Down
75 changes: 75 additions & 0 deletions script/check-catalog-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import assert from "node:assert/strict"
import { fileURLToPath } from "node:url"

const root = fileURLToPath(new URL("..", import.meta.url))
const bundle = await Bun.build({
entrypoints: [fileURLToPath(new URL("../src/catalog.ts", import.meta.url))],
target: "node",
packages: "external",
format: "esm",
})
assert(bundle.success, "Catalog test bundle failed to build")
const output = bundle.outputs[0]
assert(output, "Catalog test bundle is missing")
const scenario = `
{
const assert = (await import('node:assert/strict')).default
const fs = await import('node:fs/promises')
const path = (await import('node:path')).default
const os = await import('node:os')
const temporary = path.join(os.tmpdir(), 'opencode')
await fs.mkdir(temporary, { recursive: true })
const directory = await fs.mkdtemp(path.join(temporary, 'wallpaper-node-test-'))
const target = path.join(directory, 'target')
const aliases = path.join(directory, 'aliases')
const alias = path.join(aliases, 'alias')
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'
const pending = new Set()
const catalog = createCatalog(alias, () => { for (const notify of [...pending]) notify() })
const waitFor = (predicate) => new Promise((resolve, reject) => {
if (predicate()) { resolve(); return }
const notify = () => {
if (!predicate()) return
clearTimeout(timer)
pending.delete(notify)
resolve()
}
const timer = setTimeout(() => {
pending.delete(notify)
reject(new Error('Filesystem event did not update the catalog: ' + JSON.stringify(catalog.state())))
}, 5000)
pending.add(notify)
})
try {
await fs.mkdir(target)
await fs.mkdir(aliases)
await fs.symlink(target, alias, ${JSON.stringify(process.platform === "win32" ? "junction" : "dir")})
await fs.writeFile(path.join(target, 'before.svg'), svg)
assert.equal(await catalog.refresh(), true)
assert.equal(catalog.state().images.length, 1)
const removed = waitFor(() => catalog.state().images.length === 0 && catalog.state().error.includes('ENOENT'))
await fs.rm(target, { recursive: true })
await removed
const restored = waitFor(() => !catalog.state().error && catalog.state().images.some(image => image.title === 'restored'))
await fs.mkdir(target)
await fs.writeFile(path.join(target, 'restored.svg'), svg)
await restored
assert.ok((await catalog.read(catalog.state().images[0])).includes(Buffer.from(svg).toString('base64')))
const changed = waitFor(() => catalog.state().images.length === 2)
await fs.writeFile(path.join(target, 'another.svg'), svg)
await changed
catalog.dispose()
assert.equal(await catalog.refresh(), false)
console.log('Node catalog passed: symlink target removal, recreation, subsequent changes, reads, and disposal.')
} finally {
catalog.dispose()
await fs.rm(directory, { recursive: true, force: true })
}
}
`
const node = Bun.spawn([process.env.NODE_BIN ?? "node", "--input-type=module", "--eval", `${await output.text()}\n${scenario}`],
{ cwd: root, stdout: "pipe", stderr: "pipe" },
)
const [stdout, stderr, exit] = await Promise.all([new Response(node.stdout).text(), new Response(node.stderr).text(), node.exited])
assert.equal(exit, 0, stderr)
console.log(stdout.trim())
1 change: 0 additions & 1 deletion script/check-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ for (const [name, version] of [manifest.devDependencies, manifest.peerDependenci
assert(!/^(?:link:|file:|workspace:)/.test(version), `Local dependency cannot be published: ${name}`)
}

// Ignore lifecycle scripts during package inspection.
const result = Bun.spawn(["npm", "pack", "--dry-run", "--ignore-scripts", "--json"], {
cwd: fileURLToPath(new URL("..", import.meta.url)),
stdout: "pipe",
Expand Down
48 changes: 48 additions & 0 deletions script/check-preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import assert from "node:assert/strict"
import path from "node:path"
import { fileURLToPath } from "node:url"
import { build } from "vite"

const checkout = process.argv[2] ?? process.env.OPENCODE_CHECKOUT
assert(checkout, "Pass an OpenCode checkout path, or set OPENCODE_CHECKOUT, to test the real host persistence implementation.")
const host = path.resolve(checkout, "packages/app/src/runtime/persistence/schema.ts")
assert(await Bun.file(host).exists(), `OpenCode persistence source is missing: ${host}`)
const root = fileURLToPath(new URL("..", import.meta.url))
const effect = fileURLToPath(import.meta.resolve("effect"))
const entry = path.join(root, "script/virtual-preference-test.ts")
const source = `
import { Persistence } from ${JSON.stringify(host)}
import { Schema } from 'effect'
import { Preferences, StoredPreferences, initial } from ${JSON.stringify(path.join(root, "src/preferences.ts"))}
import assert from 'node:assert/strict'

const image = 'data:image/png;base64,YWJj'
const upload = { id: 'upload:one', name: 'one.png', image }
const schema = Persistence.withInitial(StoredPreferences, initial)
for (const changed of [{ tint: 101 }, { fit: undefined }, { brightness: 'bad' }, { duration: 0 }, { strength: 'bad' }]) {
const saved = { enabled: true, preset: 'custom', image, imageName: 'old.png', images: [upload], strength: 20, fit: 'contain', ...changed }
const restored = Schema.decodeUnknownSync(schema)(saved)
assert.equal(restored.enabled, true)
assert.equal(restored.preset, 'custom')
assert.deepEqual(restored.images, [{ id: 'custom', name: 'old.png', image }, upload])
const written = Schema.encodeSync(schema)({ ...restored, brightness: 120 })
assert.ok(!Object.hasOwn(written, 'image'))
assert.ok(!Object.hasOwn(written, 'strength'))
assert.deepEqual(Schema.decodeUnknownSync(schema)(written).images, restored.images)
}
assert.throws(() => Schema.encodeUnknownSync(Preferences)({ ...initial, tint: 101, images: [upload] }))
assert.throws(() => Schema.encodeUnknownSync(schema)({ ...initial, tint: 101, images: [upload] }))
console.log('Host persistence passed: independent field recovery preserves saved uploads and selection; writes stay strict.')
`
const result = await build({
configFile: false,
logLevel: "error",
resolve: { alias: [{ find: /^effect$/, replacement: effect }] },
plugins: [{ name: "preference-test", resolveId: (id) => id === entry ? entry : undefined, load: (id) => id === entry ? source : undefined }],
build: { write: false, lib: { entry, formats: ["es"] }, rollupOptions: { external: [effect, "node:assert/strict"] } },
})
const bundle = Array.isArray(result) ? result[0] : result
assert(bundle && "output" in bundle)
const chunk = bundle.output.find((output) => output.type === "chunk")
assert(chunk?.type === "chunk")
await import(`data:text/javascript;base64,${Buffer.from(chunk.code).toString("base64")}`)
Loading