fix: speed up opening OpenCode in the terminal

Every 'Open in terminal' launch for OpenCode copied the bundled plugin dependency tree (about 3,600 files, 52 MB) into a temporary directory, adding 2.2-2.4 s on Windows before the TUI started. The tree is now copied once into terminal/opencode-config under user data and reused until its bundled version marker changes. Skills, Ask-mode plugins and model configuration are still generated per launch and cleaned up on close. OpenCode's own TUI startup (about 3 s) is unchanged; the remote Agent path is unaffected.

Release note: 在终端中打开 OpenCode 时不再每次复制插件依赖,第二次及以后的打开速度明显加快。
This commit is contained in:
mesalogo
2026-09-30 16:59:13 +08:00
parent 925d410247
commit 7fb23d9b6b
3 changed files with 63 additions and 7 deletions
+21 -1
View File
@@ -1,5 +1,5 @@
// @vitest-environment node
import { mkdtemp, readFile, readdir, rm } from 'node:fs/promises'
import { mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
@@ -82,6 +82,26 @@ describe('native terminal client', () => {
await expect(client.open(1, input)).resolves.toMatchObject({ state: 'running' })
})
it('copies the bundled OpenCode config once and reuses it for later launches', async () => {
const { root, create, fetcher, input } = await fixture()
const bundled = join(root, 'bundled-config')
await mkdir(join(bundled, 'node_modules', 'plugin'), { recursive: true })
await writeFile(join(bundled, '.goodbuddy-ready.json'), '{"version":"1"}')
await writeFile(join(bundled, 'node_modules', 'plugin', 'index.js'), 'export {}')
const client = new NativeTerminalClient({
terminalManager: { create }, rootDirectory: root, fetcher,
bundledRuntimePaths: { opencode: process.execPath, opencodeConfig: bundled, continue: process.execPath, ripgrep: '', deepseekHarness: '' }
})
await client.open(1, input)
const configDirectory = launches[0]!.spawnSpec.env.OPENCODE_CONFIG_DIR!
expect(configDirectory).toBe(join(root, 'opencode-config'))
const copied = (await stat(join(configDirectory, 'node_modules', 'plugin', 'index.js'))).mtimeMs
await launches[0]!.dispose()
await client.open(1, { ...input, workMode: 'execute' })
expect(launches[1]!.spawnSpec.env.OPENCODE_CONFIG_DIR).toBe(configDirectory)
expect((await stat(join(configDirectory, 'node_modules', 'plugin', 'index.js'))).mtimeMs).toBe(copied)
})
it('uses Execute permissions and explicit session MCP endpoints', async () => {
const { client, input } = await fixture()
await client.open(1, { ...input, workMode: 'execute', mcpServers: [{ name: 'tools', url: 'http://127.0.0.1:12345/mcp', headers: { Authorization: 'Bearer local-token' } }] })