refactor(tui): centralize application exit
This commit is contained in:
parent
7c1e61af1e
commit
ffd38aade4
19 changed files with 150 additions and 332 deletions
24
.github/workflows/test.yml
vendored
24
.github/workflows/test.yml
vendored
|
|
@ -65,7 +65,7 @@ jobs:
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
run: bun turbo test:ci --log-order=stream --log-prefix=task
|
run: bun turbo test --output-logs=errors-only --log-order=grouped --log-prefix=task
|
||||||
env:
|
env:
|
||||||
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }}
|
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }}
|
||||||
|
|
||||||
|
|
@ -74,26 +74,6 @@ jobs:
|
||||||
working-directory: packages/opencode
|
working-directory: packages/opencode
|
||||||
run: bun run test:httpapi
|
run: bun run test:httpapi
|
||||||
|
|
||||||
- name: Publish unit reports
|
|
||||||
if: always()
|
|
||||||
uses: mikepenz/action-junit-report@bccf2e31636835cf0874589931c4116687171386 # v6.4.0
|
|
||||||
with:
|
|
||||||
report_paths: packages/*/.artifacts/unit/junit.xml
|
|
||||||
check_name: "unit results (${{ matrix.settings.name }})"
|
|
||||||
detailed_summary: true
|
|
||||||
include_time_in_summary: true
|
|
||||||
fail_on_failure: false
|
|
||||||
|
|
||||||
- name: Upload unit artifacts
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
||||||
with:
|
|
||||||
name: unit-${{ matrix.settings.name }}-${{ github.run_attempt }}
|
|
||||||
include-hidden-files: true
|
|
||||||
if-no-files-found: ignore
|
|
||||||
retention-days: 7
|
|
||||||
path: packages/*/.artifacts/unit/junit.xml
|
|
||||||
|
|
||||||
e2e:
|
e2e:
|
||||||
name: e2e (${{ matrix.settings.name }})
|
name: e2e (${{ matrix.settings.name }})
|
||||||
strategy:
|
strategy:
|
||||||
|
|
@ -151,7 +131,6 @@ jobs:
|
||||||
run: bun --cwd packages/app test:e2e:local
|
run: bun --cwd packages/app test:e2e:local
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
PLAYWRIGHT_JUNIT_OUTPUT: e2e/junit-${{ matrix.settings.name }}.xml
|
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
|
||||||
- name: Upload Playwright artifacts
|
- name: Upload Playwright artifacts
|
||||||
|
|
@ -162,6 +141,5 @@ jobs:
|
||||||
if-no-files-found: ignore
|
if-no-files-found: ignore
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
packages/app/e2e/junit-*.xml
|
|
||||||
packages/app/e2e/test-results
|
packages/app/e2e/test-results
|
||||||
packages/app/e2e/playwright-report
|
packages/app/e2e/playwright-report
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"serve": "vite preview",
|
"serve": "vite preview",
|
||||||
"test": "bun run test:unit",
|
"test": "bun run test:unit",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test --preload ./happydom.ts ./src --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
"test:unit": "bun test --only-failures --preload ./happydom.ts ./src",
|
||||||
"test:unit": "bun test --preload ./happydom.ts ./src",
|
|
||||||
"test:unit:watch": "bun test --watch --preload ./happydom.ts ./src",
|
"test:unit:watch": "bun test --watch --preload ./happydom.ts ./src",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"test:e2e:local": "playwright test",
|
"test:e2e:local": "playwright test",
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
|
||||||
const command = `bun run dev -- --host 0.0.0.0 --port ${port}`
|
const command = `bun run dev -- --host 0.0.0.0 --port ${port}`
|
||||||
const reuse = !process.env.CI
|
const reuse = !process.env.CI
|
||||||
const workers = Number(process.env.PLAYWRIGHT_WORKERS ?? (process.env.CI ? 5 : 0)) || undefined
|
const workers = Number(process.env.PLAYWRIGHT_WORKERS ?? (process.env.CI ? 5 : 0)) || undefined
|
||||||
const reporter = [["html", { outputFolder: "e2e/playwright-report", open: "never" }], ["line"]] as const
|
|
||||||
|
|
||||||
if (process.env.PLAYWRIGHT_JUNIT_OUTPUT) {
|
|
||||||
reporter.push(["junit", { outputFile: process.env.PLAYWRIGHT_JUNIT_OUTPUT }])
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: "./e2e",
|
testDir: "./e2e",
|
||||||
outputDir: "./e2e/test-results",
|
outputDir: "./e2e/test-results",
|
||||||
|
|
@ -24,7 +18,7 @@ export default defineConfig({
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
retries: process.env.CI ? 2 : 0,
|
retries: process.env.CI ? 2 : 0,
|
||||||
workers,
|
workers,
|
||||||
reporter,
|
reporter: [["html", { outputFolder: "e2e/playwright-report", open: "never" }], ["line"]],
|
||||||
webServer: {
|
webServer: {
|
||||||
command,
|
command,
|
||||||
url: baseURL,
|
url: baseURL,
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
"db": "bun drizzle-kit",
|
"db": "bun drizzle-kit",
|
||||||
"migration": "bun run script/migration.ts",
|
"migration": "bun run script/migration.ts",
|
||||||
"fix-node-pty": "bun run script/fix-node-pty.ts",
|
"fix-node-pty": "bun run script/fix-node-pty.ts",
|
||||||
"test": "bun test",
|
"test": "bun test --only-failures",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test --timeout 30000 --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
|
||||||
"typecheck": "tsgo --noEmit"
|
"typecheck": "tsgo --noEmit"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test --timeout 30000",
|
"test": "bun test --timeout 30000 --only-failures",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test --timeout 30000 --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
|
||||||
"typecheck": "tsgo --noEmit"
|
"typecheck": "tsgo --noEmit"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test --timeout 30000",
|
"test": "bun test --timeout 30000 --only-failures",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test --timeout 30000 --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
|
||||||
"typecheck": "tsgo --noEmit",
|
"typecheck": "tsgo --noEmit",
|
||||||
"build": "bun ./script/build.ts",
|
"build": "bun ./script/build.ts",
|
||||||
"verify:package": "bun ./script/verify-package.ts"
|
"verify:package": "bun ./script/verify-package.ts"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup:recording-env": "bun run script/setup-recording-env.ts",
|
"setup:recording-env": "bun run script/setup-recording-env.ts",
|
||||||
"test": "bun test --timeout 30000",
|
"test": "bun test --timeout 30000 --only-failures",
|
||||||
"typecheck": "tsgo --noEmit"
|
"typecheck": "tsgo --noEmit"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typecheck": "tsgo --noEmit",
|
"typecheck": "tsgo --noEmit",
|
||||||
"test": "bun test --timeout 30000",
|
"test": "bun test --timeout 30000 --only-failures",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test --timeout 30000 --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
|
||||||
"test:httpapi": "bun run script/httpapi-exercise.ts --mode coverage --fail-on-missing --fail-on-skip && bun run script/httpapi-exercise.ts --mode auth --fail-on-missing --fail-on-skip && bun run script/httpapi-exercise.ts --mode effect --fail-on-missing --fail-on-skip",
|
"test:httpapi": "bun run script/httpapi-exercise.ts --mode coverage --fail-on-missing --fail-on-skip && bun run script/httpapi-exercise.ts --mode auth --fail-on-missing --fail-on-skip && bun run script/httpapi-exercise.ts --mode effect --fail-on-missing --fail-on-skip",
|
||||||
"bench:test": "bun run script/bench-test-suite.ts",
|
"bench:test": "bun run script/bench-test-suite.ts",
|
||||||
"profile:test": "bun run script/profile-test-files.ts",
|
"profile:test": "bun run script/profile-test-files.ts",
|
||||||
|
|
|
||||||
|
|
@ -213,12 +213,12 @@ export const TuiThreadCommand = cmd({
|
||||||
} finally {
|
} finally {
|
||||||
await stop()
|
await stop()
|
||||||
}
|
}
|
||||||
process.exit(0)
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
unguard?.()
|
unguard?.()
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
process.exit(0)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// scratch
|
// scratch
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test --timeout 30000",
|
"test": "bun test --timeout 30000 --only-failures",
|
||||||
"typecheck": "tsgo --noEmit"
|
"typecheck": "tsgo --noEmit"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
"./config": "./src/config/index.tsx",
|
"./config": "./src/config/index.tsx",
|
||||||
"./context/args": "./src/context/args.tsx",
|
"./context/args": "./src/context/args.tsx",
|
||||||
"./context/epilogue": "./src/context/epilogue.tsx",
|
"./context/epilogue": "./src/context/epilogue.tsx",
|
||||||
|
"./context/exit": "./src/context/exit.tsx",
|
||||||
"./context/kv": "./src/context/kv.tsx",
|
"./context/kv": "./src/context/kv.tsx",
|
||||||
"./context/project": "./src/context/project.tsx",
|
"./context/project": "./src/context/project.tsx",
|
||||||
"./context/runtime": "./src/context/runtime.tsx",
|
"./context/runtime": "./src/context/runtime.tsx",
|
||||||
|
|
@ -26,7 +27,6 @@
|
||||||
"./attention": "./src/attention.ts",
|
"./attention": "./src/attention.ts",
|
||||||
"./editor": "./src/editor.ts",
|
"./editor": "./src/editor.ts",
|
||||||
"./editor-zed": "./src/editor-zed.ts",
|
"./editor-zed": "./src/editor-zed.ts",
|
||||||
"./context/aggregate-failures": "./src/context/aggregate-failures.ts",
|
|
||||||
"./runtime": "./src/runtime.tsx",
|
"./runtime": "./src/runtime.tsx",
|
||||||
"./terminal-win32": "./src/terminal-win32.ts",
|
"./terminal-win32": "./src/terminal-win32.ts",
|
||||||
"./config/keybind": "./src/config/keybind.ts",
|
"./config/keybind": "./src/config/keybind.ts",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { Global } from "@opencode-ai/core/global"
|
||||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
||||||
import { ClipboardProvider, useClipboard } from "./context/clipboard"
|
import { ClipboardProvider, useClipboard } from "./context/clipboard"
|
||||||
|
import { ExitProvider, useExit } from "./context/exit"
|
||||||
import { EpilogueProvider } from "./context/epilogue"
|
import { EpilogueProvider } from "./context/epilogue"
|
||||||
import * as Selection from "./util/selection"
|
import * as Selection from "./util/selection"
|
||||||
import { createCliRenderer, MouseButton, type CliRenderer } from "@opentui/core"
|
import { createCliRenderer, MouseButton, type CliRenderer } from "@opentui/core"
|
||||||
|
|
@ -80,6 +81,7 @@ import { createTuiAttention } from "./attention"
|
||||||
import * as TuiAudio from "./audio"
|
import * as TuiAudio from "./audio"
|
||||||
import { win32DisableProcessedInput, win32FlushInputBuffer } from "./terminal-win32"
|
import { win32DisableProcessedInput, win32FlushInputBuffer } from "./terminal-win32"
|
||||||
import { destroyRenderer } from "./util/renderer"
|
import { destroyRenderer } from "./util/renderer"
|
||||||
|
import { cliErrorMessage, errorFormat } from "./util/error"
|
||||||
|
|
||||||
const appGlobalBindingCommands = [
|
const appGlobalBindingCommands = [
|
||||||
"session.list",
|
"session.list",
|
||||||
|
|
@ -175,8 +177,8 @@ function isVersionGreater(left: string, right: string) {
|
||||||
|
|
||||||
export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
const global = yield* Global.Service
|
const global = yield* Global.Service
|
||||||
const epilogue = { value: undefined as string | undefined }
|
const exit = { epilogue: undefined as string | undefined, reason: undefined as unknown }
|
||||||
const output = yield* Effect.scoped(
|
yield* Effect.scoped(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const renderer = yield* Effect.acquireRelease(
|
const renderer = yield* Effect.acquireRelease(
|
||||||
Effect.tryPromise(() =>
|
Effect.tryPromise(() =>
|
||||||
|
|
@ -194,7 +196,10 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
(renderer) => Effect.sync(() => destroyRenderer(renderer)),
|
(renderer) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
destroyRenderer(renderer)
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
win32DisableProcessedInput()
|
win32DisableProcessedInput()
|
||||||
const keymap = createDefaultOpenTuiKeymap(renderer)
|
const keymap = createDefaultOpenTuiKeymap(renderer)
|
||||||
|
|
@ -212,7 +217,7 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
yield* Effect.addFinalizer(() => Effect.sync(TuiAudio.dispose))
|
yield* Effect.addFinalizer(() => Effect.sync(TuiAudio.dispose))
|
||||||
const shutdown = yield* Deferred.make<void>()
|
const shutdown = yield* Deferred.make<unknown>()
|
||||||
const onSighup = () => destroyRenderer(renderer)
|
const onSighup = () => destroyRenderer(renderer)
|
||||||
yield* Effect.acquireRelease(
|
yield* Effect.acquireRelease(
|
||||||
Effect.sync(() => process.on("SIGHUP", onSighup)),
|
Effect.sync(() => process.on("SIGHUP", onSighup)),
|
||||||
|
|
@ -229,103 +234,116 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
|
|
||||||
await render(() => {
|
await render(() => {
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary fallback={(error, reset) => <ErrorComponent error={error} reset={reset} mode={mode} />}>
|
<ExitProvider
|
||||||
<TuiPathsProvider
|
exit={(reason) => {
|
||||||
value={{
|
if (renderer.isDestroyed) return
|
||||||
cwd: process.cwd(),
|
exit.reason = reason
|
||||||
home: global.home,
|
destroyRenderer(renderer)
|
||||||
state: global.state,
|
}}
|
||||||
worktree: global.data + "/worktree",
|
>
|
||||||
}}
|
<EpilogueProvider set={(value) => (exit.epilogue = value)}>
|
||||||
>
|
<ErrorBoundary fallback={(error, reset) => <ErrorComponent error={error} reset={reset} mode={mode} />}>
|
||||||
<TuiTerminalEnvironmentProvider
|
<TuiPathsProvider
|
||||||
value={{
|
|
||||||
platform: process.platform,
|
|
||||||
multiplexer: process.env.TMUX ? "tmux" : process.env.STY ? "screen" : undefined,
|
|
||||||
displayServer: process.env.WAYLAND_DISPLAY ? "wayland" : process.env.DISPLAY ? "x11" : undefined,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TuiStartupProvider
|
|
||||||
value={{
|
value={{
|
||||||
initialRoute: process.env.OPENCODE_ROUTE ? JSON.parse(process.env.OPENCODE_ROUTE) : undefined,
|
cwd: process.cwd(),
|
||||||
skipInitialLoading: Boolean(process.env.OPENCODE_FAST_BOOT),
|
home: global.home,
|
||||||
|
state: global.state,
|
||||||
|
worktree: global.data + "/worktree",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ClipboardProvider>
|
<TuiTerminalEnvironmentProvider
|
||||||
<EpilogueProvider set={(value) => (epilogue.value = value)}>
|
value={{
|
||||||
<OpencodeKeymapProvider keymap={keymap}>
|
platform: process.platform,
|
||||||
<ArgsProvider {...input.args}>
|
multiplexer: process.env.TMUX ? "tmux" : process.env.STY ? "screen" : undefined,
|
||||||
<KVProvider>
|
displayServer: process.env.WAYLAND_DISPLAY
|
||||||
<ToastProvider>
|
? "wayland"
|
||||||
<RouteProvider
|
: process.env.DISPLAY
|
||||||
initialRoute={
|
? "x11"
|
||||||
input.args.continue
|
: undefined,
|
||||||
? {
|
}}
|
||||||
type: "session",
|
>
|
||||||
sessionID: "dummy",
|
<TuiStartupProvider
|
||||||
}
|
value={{
|
||||||
: undefined
|
initialRoute: process.env.OPENCODE_ROUTE ? JSON.parse(process.env.OPENCODE_ROUTE) : undefined,
|
||||||
}
|
skipInitialLoading: Boolean(process.env.OPENCODE_FAST_BOOT),
|
||||||
>
|
}}
|
||||||
<TuiConfigProvider config={input.config}>
|
>
|
||||||
<PluginRuntimeProvider value={pluginRuntime}>
|
<ClipboardProvider>
|
||||||
<SDKProvider
|
<OpencodeKeymapProvider keymap={keymap}>
|
||||||
url={input.url}
|
<ArgsProvider {...input.args}>
|
||||||
directory={input.directory}
|
<KVProvider>
|
||||||
fetch={input.fetch}
|
<ToastProvider>
|
||||||
headers={input.headers}
|
<RouteProvider
|
||||||
events={input.events}
|
initialRoute={
|
||||||
>
|
input.args.continue
|
||||||
<ProjectProvider>
|
? {
|
||||||
<SyncProvider>
|
type: "session",
|
||||||
<SyncProviderV2>
|
sessionID: "dummy",
|
||||||
<ThemeProvider mode={mode}>
|
}
|
||||||
<LocalProvider>
|
: undefined
|
||||||
<PromptStashProvider>
|
}
|
||||||
<DialogProvider>
|
>
|
||||||
<FrecencyProvider>
|
<TuiConfigProvider config={input.config}>
|
||||||
<PromptHistoryProvider>
|
<PluginRuntimeProvider value={pluginRuntime}>
|
||||||
<PromptRefProvider>
|
<SDKProvider
|
||||||
<EditorContextProvider>
|
url={input.url}
|
||||||
<App
|
directory={input.directory}
|
||||||
onSnapshot={input.onSnapshot}
|
fetch={input.fetch}
|
||||||
pluginHost={input.pluginHost}
|
headers={input.headers}
|
||||||
/>
|
events={input.events}
|
||||||
</EditorContextProvider>
|
>
|
||||||
</PromptRefProvider>
|
<ProjectProvider>
|
||||||
</PromptHistoryProvider>
|
<SyncProvider>
|
||||||
</FrecencyProvider>
|
<SyncProviderV2>
|
||||||
</DialogProvider>
|
<ThemeProvider mode={mode}>
|
||||||
</PromptStashProvider>
|
<LocalProvider>
|
||||||
</LocalProvider>
|
<PromptStashProvider>
|
||||||
</ThemeProvider>
|
<DialogProvider>
|
||||||
</SyncProviderV2>
|
<FrecencyProvider>
|
||||||
</SyncProvider>
|
<PromptHistoryProvider>
|
||||||
</ProjectProvider>
|
<PromptRefProvider>
|
||||||
</SDKProvider>
|
<EditorContextProvider>
|
||||||
</PluginRuntimeProvider>
|
<App
|
||||||
</TuiConfigProvider>
|
onSnapshot={input.onSnapshot}
|
||||||
</RouteProvider>
|
pluginHost={input.pluginHost}
|
||||||
</ToastProvider>
|
/>
|
||||||
</KVProvider>
|
</EditorContextProvider>
|
||||||
</ArgsProvider>
|
</PromptRefProvider>
|
||||||
</OpencodeKeymapProvider>
|
</PromptHistoryProvider>
|
||||||
</EpilogueProvider>
|
</FrecencyProvider>
|
||||||
</ClipboardProvider>
|
</DialogProvider>
|
||||||
</TuiStartupProvider>
|
</PromptStashProvider>
|
||||||
</TuiTerminalEnvironmentProvider>
|
</LocalProvider>
|
||||||
</TuiPathsProvider>
|
</ThemeProvider>
|
||||||
</ErrorBoundary>
|
</SyncProviderV2>
|
||||||
|
</SyncProvider>
|
||||||
|
</ProjectProvider>
|
||||||
|
</SDKProvider>
|
||||||
|
</PluginRuntimeProvider>
|
||||||
|
</TuiConfigProvider>
|
||||||
|
</RouteProvider>
|
||||||
|
</ToastProvider>
|
||||||
|
</KVProvider>
|
||||||
|
</ArgsProvider>
|
||||||
|
</OpencodeKeymapProvider>
|
||||||
|
</ClipboardProvider>
|
||||||
|
</TuiStartupProvider>
|
||||||
|
</TuiTerminalEnvironmentProvider>
|
||||||
|
</TuiPathsProvider>
|
||||||
|
</ErrorBoundary>
|
||||||
|
</EpilogueProvider>
|
||||||
|
</ExitProvider>
|
||||||
)
|
)
|
||||||
}, renderer)
|
}, renderer)
|
||||||
})
|
})
|
||||||
yield* Deferred.await(shutdown)
|
yield* Deferred.await(shutdown)
|
||||||
return epilogue.value
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
yield* Effect.sync(() => {
|
yield* Effect.sync(() => {
|
||||||
win32FlushInputBuffer()
|
win32FlushInputBuffer()
|
||||||
if (output) process.stdout.write(output + "\n")
|
if (exit.reason !== undefined)
|
||||||
|
process.stderr.write((cliErrorMessage(exit.reason) ?? errorFormat(exit.reason)) + "\n")
|
||||||
|
if (exit.epilogue) process.stdout.write(exit.epilogue + "\n")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -346,6 +364,7 @@ function App(props: { onSnapshot?: () => Promise<string[]>; pluginHost: TuiPlugi
|
||||||
const { theme, mode, setMode, locked, lock, unlock } = themeState
|
const { theme, mode, setMode, locked, lock, unlock } = themeState
|
||||||
const sync = useSync()
|
const sync = useSync()
|
||||||
const project = useProject()
|
const project = useProject()
|
||||||
|
const exit = useExit()
|
||||||
const promptRef = usePromptRef()
|
const promptRef = usePromptRef()
|
||||||
const pluginRuntime = usePluginRuntime()
|
const pluginRuntime = usePluginRuntime()
|
||||||
const attention = createTuiAttention({ renderer, config: tuiConfig, kv })
|
const attention = createTuiAttention({ renderer, config: tuiConfig, kv })
|
||||||
|
|
@ -786,7 +805,7 @@ function App(props: { onSnapshot?: () => Promise<string[]>; pluginHost: TuiPlugi
|
||||||
title: "Exit the app",
|
title: "Exit the app",
|
||||||
slashName: "exit",
|
slashName: "exit",
|
||||||
slashAliases: ["quit", "q"],
|
slashAliases: ["quit", "q"],
|
||||||
run: () => destroyRenderer(renderer),
|
run: () => exit(),
|
||||||
category: "System",
|
category: "System",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -1020,7 +1039,7 @@ function App(props: { onSnapshot?: () => Promise<string[]>; pluginHost: TuiPlugi
|
||||||
`Successfully updated to OpenCode v${result.data.version}. Please restart the application.`,
|
`Successfully updated to OpenCode v${result.data.version}. Please restart the application.`,
|
||||||
)
|
)
|
||||||
|
|
||||||
destroyRenderer(renderer)
|
void exit()
|
||||||
})
|
})
|
||||||
|
|
||||||
const plugin = createMemo(() => {
|
const plugin = createMemo(() => {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
import { TextAttributes } from "@opentui/core"
|
import { TextAttributes } from "@opentui/core"
|
||||||
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
|
import { useKeyboard, useTerminalDimensions } from "@opentui/solid"
|
||||||
import { createSignal } from "solid-js"
|
import { createSignal } from "solid-js"
|
||||||
import { getScrollAcceleration } from "../util/scroll"
|
import { getScrollAcceleration } from "../util/scroll"
|
||||||
import { useClipboard } from "../context/clipboard"
|
import { useClipboard } from "../context/clipboard"
|
||||||
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
||||||
import { destroyRenderer } from "../util/renderer"
|
import { useExit } from "../context/exit"
|
||||||
|
|
||||||
export function ErrorComponent(props: { error: Error; reset: () => void; mode?: "dark" | "light" }) {
|
export function ErrorComponent(props: { error: Error; reset: () => void; mode?: "dark" | "light" }) {
|
||||||
const term = useTerminalDimensions()
|
const term = useTerminalDimensions()
|
||||||
const renderer = useRenderer()
|
const exit = useExit()
|
||||||
const clipboard = useClipboard()
|
const clipboard = useClipboard()
|
||||||
|
|
||||||
useKeyboard((evt) => {
|
useKeyboard((evt) => {
|
||||||
if (evt.ctrl && evt.name === "c") {
|
if (evt.ctrl && evt.name === "c") {
|
||||||
destroyRenderer(renderer)
|
void exit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const [copied, setCopied] = createSignal(false)
|
const [copied, setCopied] = createSignal(false)
|
||||||
|
|
@ -66,7 +66,7 @@ export function ErrorComponent(props: { error: Error; reset: () => void; mode?:
|
||||||
<box onMouseUp={props.reset} backgroundColor={colors.primary} padding={1}>
|
<box onMouseUp={props.reset} backgroundColor={colors.primary} padding={1}>
|
||||||
<text fg={colors.bg}>Reset TUI</text>
|
<text fg={colors.bg}>Reset TUI</text>
|
||||||
</box>
|
</box>
|
||||||
<box onMouseUp={() => destroyRenderer(renderer)} backgroundColor={colors.primary} padding={1}>
|
<box onMouseUp={() => void exit()} backgroundColor={colors.primary} padding={1}>
|
||||||
<text fg={colors.bg}>Exit</text>
|
<text fg={colors.bg}>Exit</text>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import { useSync } from "../../context/sync"
|
||||||
import { useEvent } from "../../context/event"
|
import { useEvent } from "../../context/event"
|
||||||
import { editorSelectionKey, useEditorContext, type EditorSelection } from "../../context/editor"
|
import { editorSelectionKey, useEditorContext, type EditorSelection } from "../../context/editor"
|
||||||
import { normalizePromptContent, openEditor } from "../../editor"
|
import { normalizePromptContent, openEditor } from "../../editor"
|
||||||
import { destroyRenderer } from "../../util/renderer"
|
import { useExit } from "../../context/exit"
|
||||||
import { promptOffsetWidth } from "../../prompt/display"
|
import { promptOffsetWidth } from "../../prompt/display"
|
||||||
import { createStore, produce, unwrap } from "solid-js/store"
|
import { createStore, produce, unwrap } from "solid-js/store"
|
||||||
import { usePromptHistory, type PromptInfo } from "../../prompt/history"
|
import { usePromptHistory, type PromptInfo } from "../../prompt/history"
|
||||||
|
|
@ -163,6 +163,7 @@ export function Prompt(props: PromptProps) {
|
||||||
const agentShortcut = useCommandShortcut("agent.cycle")
|
const agentShortcut = useCommandShortcut("agent.cycle")
|
||||||
const paletteShortcut = useCommandShortcut("command.palette.show")
|
const paletteShortcut = useCommandShortcut("command.palette.show")
|
||||||
const renderer = useRenderer()
|
const renderer = useRenderer()
|
||||||
|
const exit = useExit()
|
||||||
const dimensions = useTerminalDimensions()
|
const dimensions = useTerminalDimensions()
|
||||||
const { theme, syntax } = useTheme()
|
const { theme, syntax } = useTheme()
|
||||||
const kv = useKV()
|
const kv = useKV()
|
||||||
|
|
@ -955,7 +956,7 @@ export function Prompt(props: PromptProps) {
|
||||||
if (!agent) return false
|
if (!agent) return false
|
||||||
const trimmed = store.prompt.input.trim()
|
const trimmed = store.prompt.input.trim()
|
||||||
if (trimmed === "exit" || trimmed === "quit" || trimmed === ":q") {
|
if (trimmed === "exit" || trimmed === "quit" || trimmed === ":q") {
|
||||||
destroyRenderer(renderer)
|
void exit()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
const selectedModel = local.model.current()
|
const selectedModel = local.model.current()
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
import { cliErrorMessage } from "../util/error"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aggregate Promise.allSettled results into a single Error that names every
|
|
||||||
* failed endpoint, or return null when all fulfilled. Used at TUI bootstrap
|
|
||||||
* boundaries so a single 4xx doesn't drown its parallel siblings as
|
|
||||||
* unhandled rejections — every failure surfaces in one labeled message.
|
|
||||||
*/
|
|
||||||
export type LabeledSettled = {
|
|
||||||
name: string
|
|
||||||
result: PromiseSettledResult<unknown>
|
|
||||||
}
|
|
||||||
|
|
||||||
export function aggregateFailures(labeled: LabeledSettled[]): Error | null {
|
|
||||||
const failed = labeled.filter(
|
|
||||||
(x): x is { name: string; result: PromiseRejectedResult } => x.result.status === "rejected",
|
|
||||||
)
|
|
||||||
if (failed.length === 0) return null
|
|
||||||
|
|
||||||
const reasons = Array.from(
|
|
||||||
failed
|
|
||||||
.map((f) => ({ name: f.name, message: reasonMessage(f.result.reason) }))
|
|
||||||
.reduce((grouped, failure) => {
|
|
||||||
grouped.set(failure.message, [...(grouped.get(failure.message) ?? []), failure.name])
|
|
||||||
return grouped
|
|
||||||
}, new Map<string, string[]>())
|
|
||||||
.entries(),
|
|
||||||
)
|
|
||||||
.map(([message, names]) =>
|
|
||||||
names.length === 1 ? `${names[0]}: ${message}` : `${message}\nAffected startup requests: ${names.join(", ")}`,
|
|
||||||
)
|
|
||||||
.join("; ")
|
|
||||||
const summary = `${failed.length} of ${labeled.length} requests failed: ${reasons}`
|
|
||||||
const err = new Error(summary)
|
|
||||||
err.cause = { failures: failed.map((f) => ({ name: f.name, reason: f.result.reason })) }
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
function reasonMessage(reason: unknown): string {
|
|
||||||
const formatted = cliErrorMessage(reason)
|
|
||||||
if (formatted) return formatted
|
|
||||||
|
|
||||||
if (reason instanceof Error) return reason.message
|
|
||||||
if (typeof reason === "string") return reason
|
|
||||||
if (reason && typeof reason === "object") {
|
|
||||||
const obj = reason as { message?: unknown; name?: unknown }
|
|
||||||
if (typeof obj.message === "string") return obj.message
|
|
||||||
if (typeof obj.name === "string") return obj.name
|
|
||||||
}
|
|
||||||
return String(reason)
|
|
||||||
}
|
|
||||||
8
packages/tui/src/context/exit.tsx
Normal file
8
packages/tui/src/context/exit.tsx
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { createSimpleContext } from "./helper"
|
||||||
|
|
||||||
|
export type Exit = (reason?: unknown) => void
|
||||||
|
|
||||||
|
export const { use: useExit, provider: ExitProvider } = createSimpleContext({
|
||||||
|
name: "Exit",
|
||||||
|
init: (input: { exit: Exit }) => input.exit,
|
||||||
|
})
|
||||||
|
|
@ -26,13 +26,11 @@ import { useEvent } from "./event"
|
||||||
import { useSDK } from "./sdk"
|
import { useSDK } from "./sdk"
|
||||||
import { useTuiStartup } from "./runtime"
|
import { useTuiStartup } from "./runtime"
|
||||||
import { createSimpleContext } from "./helper"
|
import { createSimpleContext } from "./helper"
|
||||||
import { useRenderer } from "@opentui/solid"
|
import { useExit } from "./exit"
|
||||||
import { useArgs } from "./args"
|
import { useArgs } from "./args"
|
||||||
import { batch, onMount } from "solid-js"
|
import { batch, onMount } from "solid-js"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { aggregateFailures } from "./aggregate-failures"
|
|
||||||
import { useKV } from "./kv"
|
import { useKV } from "./kv"
|
||||||
import { destroyRenderer } from "../util/renderer"
|
|
||||||
|
|
||||||
const emptyConsoleState: ConsoleState = {
|
const emptyConsoleState: ConsoleState = {
|
||||||
consoleManagedProviders: [],
|
consoleManagedProviders: [],
|
||||||
|
|
@ -424,7 +422,7 @@ export const {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const renderer = useRenderer()
|
const exit = useExit()
|
||||||
const args = useArgs()
|
const args = useArgs()
|
||||||
|
|
||||||
async function bootstrap(input: { fatal?: boolean } = {}) {
|
async function bootstrap(input: { fatal?: boolean } = {}) {
|
||||||
|
|
@ -442,23 +440,14 @@ export const {
|
||||||
.catch(() => emptyConsoleState)
|
.catch(() => emptyConsoleState)
|
||||||
const agentsPromise = sdk.client.app.agents({ workspace }, { throwOnError: true })
|
const agentsPromise = sdk.client.app.agents({ workspace }, { throwOnError: true })
|
||||||
const configPromise = sdk.client.config.get({ workspace }, { throwOnError: true })
|
const configPromise = sdk.client.config.get({ workspace }, { throwOnError: true })
|
||||||
const blockingRequests: { name: string; promise: Promise<unknown> }[] = [
|
await Promise.all([
|
||||||
{ name: "config.providers", promise: providersPromise },
|
providersPromise,
|
||||||
{ name: "provider.list", promise: providerListPromise },
|
providerListPromise,
|
||||||
{ name: "app.agents", promise: agentsPromise },
|
agentsPromise,
|
||||||
{ name: "config.get", promise: configPromise },
|
configPromise,
|
||||||
{ name: "project.sync", promise: projectPromise },
|
projectPromise,
|
||||||
...(args.continue ? [{ name: "session.list", promise: sessionListPromise }] : []),
|
...(args.continue ? [sessionListPromise] : []),
|
||||||
]
|
])
|
||||||
|
|
||||||
await Promise.allSettled(blockingRequests.map((r) => r.promise))
|
|
||||||
.then((settled) => {
|
|
||||||
// Surface every failed endpoint in one labeled message instead of
|
|
||||||
// letting the first rejection drown its siblings as unhandled
|
|
||||||
// rejections.
|
|
||||||
const failure = aggregateFailures(blockingRequests.map((r, i) => ({ name: r.name, result: settled[i] })))
|
|
||||||
if (failure) throw failure
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const providersResponse = providersPromise.then((x) => x.data!)
|
const providersResponse = providersPromise.then((x) => x.data!)
|
||||||
const providerListResponse = providerListPromise.then((x) => x.data!)
|
const providerListResponse = providerListPromise.then((x) => x.data!)
|
||||||
|
|
@ -523,7 +512,7 @@ export const {
|
||||||
stack: e instanceof Error ? e.stack : undefined,
|
stack: e instanceof Error ? e.stack : undefined,
|
||||||
})
|
})
|
||||||
if (fatal) {
|
if (fatal) {
|
||||||
destroyRenderer(renderer)
|
exit(e)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
/**
|
|
||||||
* Regression test for the TUI bootstrap aggregation helper. Replaces the
|
|
||||||
* pre-fix Promise.all behavior where the first rejection drowned every
|
|
||||||
* sibling endpoint's failure as an unhandled rejection.
|
|
||||||
*/
|
|
||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
import { aggregateFailures } from "@opencode-ai/tui/context/aggregate-failures"
|
|
||||||
|
|
||||||
describe("aggregateFailures", () => {
|
|
||||||
test("returns null when every result is fulfilled", () => {
|
|
||||||
expect(
|
|
||||||
aggregateFailures([
|
|
||||||
{ name: "config", result: { status: "fulfilled", value: 1 } },
|
|
||||||
{ name: "providers", result: { status: "fulfilled", value: 2 } },
|
|
||||||
]),
|
|
||||||
).toBeNull()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("names the failed endpoint when one rejects", () => {
|
|
||||||
const err = aggregateFailures([
|
|
||||||
{ name: "config", result: { status: "fulfilled", value: 1 } },
|
|
||||||
{
|
|
||||||
name: "providers",
|
|
||||||
result: { status: "rejected", reason: new Error("Service unavailable") },
|
|
||||||
},
|
|
||||||
])
|
|
||||||
expect(err).toBeInstanceOf(Error)
|
|
||||||
expect(err!.message).toContain("1 of 2")
|
|
||||||
expect(err!.message).toContain("providers: Service unavailable")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("names every failed endpoint when multiple reject", () => {
|
|
||||||
const err = aggregateFailures([
|
|
||||||
{ name: "config", result: { status: "rejected", reason: new Error("400 Bad Request") } },
|
|
||||||
{ name: "providers", result: { status: "fulfilled", value: 1 } },
|
|
||||||
{ name: "agents", result: { status: "rejected", reason: { message: "boom" } } },
|
|
||||||
])
|
|
||||||
expect(err).toBeInstanceOf(Error)
|
|
||||||
expect(err!.message).toContain("2 of 3")
|
|
||||||
expect(err!.message).toContain("config: 400 Bad Request")
|
|
||||||
expect(err!.message).toContain("agents: boom")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("formats structured config errors hidden inside SDK error causes", () => {
|
|
||||||
const configError = {
|
|
||||||
name: "ConfigInvalidError",
|
|
||||||
data: {
|
|
||||||
path: "/tmp/opencode.json",
|
|
||||||
issues: [{ message: "Expected object", path: ["provider", "anthropic", "options"] }],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const err = aggregateFailures([
|
|
||||||
{
|
|
||||||
name: "config.get",
|
|
||||||
result: {
|
|
||||||
status: "rejected",
|
|
||||||
reason: new Error("ConfigInvalidError", {
|
|
||||||
cause: {
|
|
||||||
body: configError,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
expect(err!.message).toContain("config.get: Configuration is invalid at /tmp/opencode.json")
|
|
||||||
expect(err!.message).toContain("Expected object provider.anthropic.options")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("deduplicates identical failure messages across startup requests", () => {
|
|
||||||
const reason = new Error("same config problem")
|
|
||||||
const err = aggregateFailures([
|
|
||||||
{ name: "config.providers", result: { status: "rejected", reason } },
|
|
||||||
{ name: "provider.list", result: { status: "rejected", reason } },
|
|
||||||
{ name: "app.agents", result: { status: "rejected", reason } },
|
|
||||||
{ name: "config.get", result: { status: "rejected", reason } },
|
|
||||||
{ name: "project.sync", result: { status: "fulfilled", value: undefined } },
|
|
||||||
])
|
|
||||||
|
|
||||||
expect(err!.message).toContain("4 of 5 requests failed: same config problem")
|
|
||||||
expect(err!.message).toContain("Affected startup requests: config.providers, provider.list, app.agents, config.get")
|
|
||||||
expect(err!.message.match(/same config problem/g)?.length).toBe(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("attaches structured failure list under .cause", () => {
|
|
||||||
const reason = new Error("nope")
|
|
||||||
const err = aggregateFailures([{ name: "providers", result: { status: "rejected", reason } }])
|
|
||||||
expect(err!.cause).toEqual({ failures: [{ name: "providers", reason }] })
|
|
||||||
})
|
|
||||||
|
|
||||||
test("falls back to String() for opaque reasons", () => {
|
|
||||||
const err = aggregateFailures([{ name: "x", result: { status: "rejected", reason: 42 } }])
|
|
||||||
expect(err!.message).toContain("x: 42")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
@ -29,8 +29,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typecheck": "tsgo --noEmit",
|
"typecheck": "tsgo --noEmit",
|
||||||
"test": "bun test src",
|
"test": "bun test src --only-failures",
|
||||||
"test:ci": "mkdir -p .artifacts/unit && bun test src --reporter=junit --reporter-outfile=.artifacts/unit/junit.xml",
|
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"generate:tailwind": "bun run script/tailwind.ts",
|
"generate:tailwind": "bun run script/tailwind.ts",
|
||||||
"generate:v2-oc2": "bun run script/build-oc2-v2-overrides.ts"
|
"generate:v2-oc2": "bun run script/build-oc2-v2-overrides.ts"
|
||||||
|
|
|
||||||
19
turbo.json
19
turbo.json
|
|
@ -13,32 +13,13 @@
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"passThroughEnv": ["*"]
|
"passThroughEnv": ["*"]
|
||||||
},
|
},
|
||||||
"test:ci": {
|
|
||||||
"outputs": [".artifacts/unit/junit.xml"],
|
|
||||||
"passThroughEnv": ["*"]
|
|
||||||
},
|
|
||||||
"opencode#test:ci": {
|
|
||||||
"dependsOn": ["^build"],
|
|
||||||
"outputs": [".artifacts/unit/junit.xml"],
|
|
||||||
"passThroughEnv": ["*"]
|
|
||||||
},
|
|
||||||
"@opencode-ai/app#test": {
|
"@opencode-ai/app#test": {
|
||||||
"dependsOn": ["^build"],
|
"dependsOn": ["^build"],
|
||||||
"outputs": []
|
"outputs": []
|
||||||
},
|
},
|
||||||
"@opencode-ai/app#test:ci": {
|
|
||||||
"dependsOn": ["^build"],
|
|
||||||
"outputs": [".artifacts/unit/junit.xml"],
|
|
||||||
"passThroughEnv": ["*"]
|
|
||||||
},
|
|
||||||
"@opencode-ai/ui#test": {
|
"@opencode-ai/ui#test": {
|
||||||
"dependsOn": ["^build"],
|
"dependsOn": ["^build"],
|
||||||
"outputs": []
|
"outputs": []
|
||||||
},
|
|
||||||
"@opencode-ai/ui#test:ci": {
|
|
||||||
"dependsOn": ["^build"],
|
|
||||||
"outputs": [".artifacts/unit/junit.xml"],
|
|
||||||
"passThroughEnv": ["*"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue