Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Draft
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
2 changes: 1 addition & 1 deletion bun.lock

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

89 changes: 89 additions & 0 deletions packages/app/FORGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Forge embedding on v2.0.32

This fork's stable baseline is upstream `843a6c514e606b436a7fe713422ace0a93ad3d61`
(v2.0.32). The lower integration commit has exactly that tree; the upper layer
contains the Forge UI ports. Do not replay the old fork's test timing changes or
overwrite stable's generated clients.

## Host contract

- Import `AppBaseProviders`, `AppInterface`, `PlatformProvider`, `Platform`, and
`ServerConnection` from `@opencode/app`. The package scope changed from
`@opencode-ai/*` to `@opencode/*`.
- Mount `PlatformProvider` outside `AppBaseProviders`, then render
`AppInterface embedded servers={[connection]} router={HostRouter}` inside it.
`AppBaseProviders` includes the stable `ExtensionRoot`; keep it mounted.
- `AppInterface` no longer accepts `defaultServer`. `Platform` no longer has
`getDefaultServer` or `setDefaultServer`. The route selects the server.
- An HTTP connection is `{ type: "http", http: { url, password? } }`. Its key is
`ServerConnection.key(connection)`. Use the full absolute task proxy URL,
such as `https://forge.owner.sh/api/v2/opencode-host/<task-id>`.
- A session route is
`/server/${base64Encode(ServerConnection.key(connection))}/session/${sessionID}`;
import `base64Encode` from `@opencode/util/encode`. A host-owned
`createMemoryHistory()` can select it with
`history.set({ value: route, replace: true, scroll: false })`. Pass a stable
router component rendering `<MemoryRouter {...props} history={history} />`.
- Mount and load the app bundle inside the iframe's own window/document. Give
its root a bounded full height and dispose the Solid render root on teardown.
Styles, theme/font writes, keyboard handlers, workers, and platform callbacks
then belong to that iframe. Namespace host-provided storage for the stable UI
when running it beside the legacy UI.
- The web platform must supply `platform: "web"`, `openExternal`, `restart`,
and `notify`. `storage`, `draftStore`, and `fetch` remain optional host hooks.
No desktop extension bridge is required for web rendering.

Embedded mode hides the titlebar, vertical tab sidebar, session identity header,
mobile view tabs, and floating review toggle. Mobile stays on the conversation.
The timeline retains a 16px headerless inset at both viewport sizes. Standalone
mode keeps upstream layout and extension behavior.

Server controllers are disposed on provider teardown through the same disposer
used for credential changes and server removal, including the credentials map.
The timeline waits for document adoption before attaching and recovers silent
scroll resets without taking over native touch momentum or size compensation.

`time.released === 0` becomes an empty `release_date`, allowing undated custom
models to remain visible. `charon_execute` and `executor_execute` display
expandable JavaScript and output; native `execute` retains its console label and
plain code. Highlighting uses the existing Markdown worker and falls back to raw
code if unavailable.

## Dependencies and build

Install the complete stable workspace with its lockfile:

```sh
mise x bun@1.4.2 -- bun install --frozen-lockfile
mise x bun@1.4.2 -- bun run check
mise x bun@1.4.2 -- bun run --cwd packages/app build
```

For focused iteration, run `bun typecheck` in `packages/app` and
`packages/session-ui`. The build emits `packages/app/dist`.

The stable app directly needs the local `@opencode/client`, `schema`,
`gui-extensions`, `session-ui`, `ui`, and `util` packages. Preserve their
transitive workspace dependencies, including `protocol`, `plugin-browser`, and
`plugin`; adding only the old app/ui aliases is insufficient. Stable also moves
to Effect 4.0.1, Solid 1.9.15, Vite 8.2.2, and Tailwind 4.3.3 for the app.
Keep the lockfile patches, especially Solid, TanStack virtual-core, and the
stable Vite/worker configuration. `@opencode/app/vite` exports the app's Vite
plugins and configures its source alias, workers, Tailwind, and Solid compiler.

Keep the stable entry's dependency resolution separate from legacy package
aliases when building both UIs. Compile the stable sources and load their CSS
inside the iframe. Do not alias stable packages back to the legacy vendored tree.

Stable already preserves path prefixes for generated HTTP calls, PTY sockets,
and persistent PTY sockets. HTTP and socket routes append `/api/...` to the
connection URL. The app request queue classifies paths relative to the current
server URL so prefixed SSE bypasses the queue, filesystem/git reads use the slow
slots, and worktree creation keeps its ten-minute response-header budget. The
host proxy still needs to support both HTTP and WebSocket requests and streaming
responses.

Before rollout, verify the parent wrapper against a v2.0.32 sandbox: session
load and streaming, task switches/remounts, mobile scrolling, tool expansion,
undated model visibility, and HTTP plus both PTY paths. A fork build alone does
not establish those host/runtime contracts.
25 changes: 15 additions & 10 deletions packages/app/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TabsProvider } from "@/shell/tabs/tabs"
import { ErrorPage } from "@/shell/errors/error"
import { AppRoutes, File, preloadRoute } from "@/shell/routes/routes"
import { ExtensionRoot } from "@/runtime/extension/root"
import { EmbeddedProvider } from "@/runtime/embed"

export { preloadRoute }

Expand Down Expand Up @@ -89,21 +90,25 @@ export function AppInterface(props: {
canonicalLocalServer?: ServerConnection.Key
servers?: Array<ServerConnection.Any>
router?: Component<BaseRouterProps>
/** Hide application navigation when the host owns the surrounding chrome. */
embedded?: boolean
}) {
// The visual layout lives in the router root so it remains mounted across
// route changes. Draft and session routes override only their server-bound data
// providers beneath it.
const Root = (rootProps: ParentProps) => (
<TabsProvider>
<GlobalProvider>
<BodyTypography />
<CommandProvider>
<DesktopCommands />
{props.children}
{rootProps.children}
</CommandProvider>
</GlobalProvider>
</TabsProvider>
<EmbeddedProvider embedded={props.embedded}>
<TabsProvider>
<GlobalProvider>
<BodyTypography />
<CommandProvider>
<DesktopCommands />
{props.children}
{rootProps.children}
</CommandProvider>
</GlobalProvider>
</TabsProvider>
</EmbeddedProvider>
)

return (
Expand Down
17 changes: 17 additions & 0 deletions packages/app/src/runtime/embed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createContext, useContext, type ParentProps } from "solid-js"

const EmbeddedContext = createContext({ embedded: false })

export function EmbeddedProvider(props: ParentProps<{ embedded?: boolean }>) {
const value = {
get embedded() {
return props.embedded ?? false
},
}

return <EmbeddedContext.Provider value={value}>{props.children}</EmbeddedContext.Provider>
}

export function useEmbedded() {
return useContext(EmbeddedContext)
}
5 changes: 4 additions & 1 deletion packages/app/src/runtime/server/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export function createServerTransport(input: { http: ServerConnection.HttpBase;
readonly api: ServerApi
readonly pty: ReturnType<typeof createPtyClient>
} {
const queue = createRequestQueue({ fetch: input.fetch ?? globalThis.fetch })
const queue = createRequestQueue({
fetch: input.fetch ?? globalThis.fetch,
baseUrl: (): string => state.current.http.url,
})

const build = (http: ServerConnection.HttpBase) => {
const api = createApiForServer({ server: http, fetch: queue.fetch })
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/runtime/server/global-sync/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function normalizeProviderList(
status: model.status,
options: model.settings ?? {},
headers: model.headers ?? {},
release_date: new Date(model.time.released).toISOString().slice(0, 10),
release_date: model.time.released ? new Date(model.time.released).toISOString().slice(0, 10) : "",
variants: Object.fromEntries(model.variants.map((variant) => [variant.id, variant.settings ?? {}])),
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/app/src/runtime/server/request-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function isSetupRequest(method: string, pathname: string) {

export function createRequestQueue(input: {
fetch: typeof globalThis.fetch
/** The current server URL, including a reverse proxy's path prefix. */
baseUrl?: () => string
limit?: number
slowLimit?: number
stallMs?: number
Expand Down Expand Up @@ -119,7 +121,15 @@ export function createRequestQueue(input: {
const fetch: typeof globalThis.fetch = Object.assign(
async (resource: RequestInfo | URL, init?: RequestInit) => {
const request = new Request(resource, init)
const pathname = new URL(request.url).pathname
const url = new URL(request.url)
const baseUrl = input.baseUrl?.()
const server = baseUrl ? new URL(baseUrl) : undefined
const prefix = server?.pathname.replace(/\/+$/, "") ?? ""

const pathname =
server?.origin === url.origin && prefix && url.pathname.startsWith(`${prefix}/`)
? url.pathname.slice(prefix.length)
: url.pathname

// The event stream is long-lived; never count it against the request budget.
if (pathname === "/api/event") return base(request)
Expand Down
17 changes: 16 additions & 1 deletion packages/app/src/runtime/server/runtime.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { createSimpleContext } from "@opencode/ui/context"
import { Accessor, batch, createEffect, createMemo, createResource, createRoot, getOwner, untrack } from "solid-js"
import {
Accessor,
batch,
createEffect,
createMemo,
createResource,
createRoot,
getOwner,
onCleanup,
untrack,
} from "solid-js"
import { createServerProjects, RECENTLY_CLOSED_DISPLAY_LIMIT, ServerConnection, useServers } from "./registry"
import { pathKey } from "@/workspaces/path-key"
import { useServerHealth } from "@/runtime/server/health"
Expand Down Expand Up @@ -91,6 +101,11 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
}
})

// Detached roots otherwise keep reconnecting their event streams after the host unmounts the app.
onCleanup(() => {
for (const key of serverCtxDisposers.keys()) disposeServerCtx(key)
})

return {
servers: {
list: () => server.list,
Expand Down
14 changes: 10 additions & 4 deletions packages/app/src/session/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { SessionReviewToggle } from "./header/session-header-actions"
import { SessionRunningMenu } from "./header/session-running-menu"
import { createAnimatedPresence } from "@/runtime/animated-presence"
import { createTimelineCache } from "./timeline/cache"
import { useEmbedded } from "@/runtime/embed"

export function SessionScreenView(props: { session: SessionModel }) {
// The timeline cache captures its owner when created, so link handling must be provided above it.
Expand Down Expand Up @@ -66,6 +67,7 @@ function SessionScreenContent(props: {
const host = useExtensionHost()
const attachment = useExtensionAttachment()
const settings = useSettings()
const embedded = useEmbedded()
const isDesktop = session.isDesktop
const bottomMobileTabs = () => settings.general.mobileTitlebarPosition() === "bottom"
const sidebar = createPanelSidebar()
Expand Down Expand Up @@ -191,7 +193,7 @@ function SessionScreenContent(props: {
const dockView = createMemo(() => mobile.entries().find((entry) => entry.provider.region === "dock"))

const mobileView = createMemo(() =>
screen.dock.open() ? (dockView()?.key ?? "session") : attachment.mobile.current(),
embedded.embedded ? "session" : screen.dock.open() ? (dockView()?.key ?? "session") : attachment.mobile.current(),
)

const mobileEntry = createMemo(() => {
Expand Down Expand Up @@ -304,7 +306,9 @@ function SessionScreenContent(props: {
input={composer.drop.input()}
identity={session.layout.tabKey}
/>
<Show when={!isDesktop() && !!session.identity.params.id && !bottomMobileTabs()}>{mobileTabs()}</Show>
<Show when={!embedded.embedded && !isDesktop() && !!session.identity.params.id && !bottomMobileTabs()}>
{mobileTabs()}
</Show>
{/* Surface query errors without suspending session metadata while messages load. */}
<Show when={timeline.resource.error}>
{(error) => {
Expand Down Expand Up @@ -363,7 +367,9 @@ function SessionScreenContent(props: {
<ActiveSessionComposerRegion session={session} model={model} suggestionBoundary={timeline.scroller} />
)}
</Show>
<Show when={!isDesktop() && !!session.identity.params.id && bottomMobileTabs()}>{mobileTabs()}</Show>
<Show when={!embedded.embedded && !isDesktop() && !!session.identity.params.id && bottomMobileTabs()}>
{mobileTabs()}
</Show>
</>
)

Expand All @@ -372,7 +378,7 @@ function SessionScreenContent(props: {
<div class="flex-1 min-h-0 flex flex-col gap-2 px-[var(--shell-inline-inset,8px)] pb-[var(--shell-bottom-inset,8px)] pt-[var(--shell-top-inset,8px)]">
<div ref={screen.panel.ref} class="relative flex-1 min-h-0 flex flex-col md:flex-row gap-2">
{/* Keep the control outside panel animations. */}
<Show when={isDesktop() && messagesReady() && session.identity.params.id}>
<Show when={!embedded.embedded && isDesktop() && messagesReady() && session.identity.params.id}>
<div
class="absolute end-3 top-0 z-30 h-12 flex items-center"
data-slot="session-review-toggle"
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/session/session-identity-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useServer } from "@/runtime/server/current"
import { ServerConnection } from "@/runtime/server/registry"
import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { useEmbedded } from "@/runtime/embed"
import { errorMessage } from "@/shell/layout/helpers"
import { useLayout, type LocalProject } from "@/shell/state/layout"
import { tabKey, useTabs } from "@/shell/tabs/tabs"
Expand Down Expand Up @@ -307,6 +308,7 @@ export function useOpenSessionRoute() {
}

export function SessionIdentityHeader(props: ParentProps<{ sessionID: string; session?: SessionInfo }>) {
const embedded = useEmbedded()
const server = useServer()
const tabs = useTabs()
const language = useLanguage()
Expand Down Expand Up @@ -379,7 +381,7 @@ export function SessionIdentityHeader(props: ParentProps<{ sessionID: string; se
const workspaceSession = createMemo(() => !!pending() || isWorkspaceDirectory(project(), directory() ?? ""))

return (
<Show when={title() || parentTitle()}>
<Show when={!embedded.embedded && (title() || parentTitle())}>
<SessionTitleHeader>
<div class="flex h-12 w-full items-center justify-between gap-2">
<div class="flex min-w-0 flex-1 items-center gap-1">
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/session/timeline/message-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { parseVoiceDelegation } from "./voice-delegation"
import { useCommand } from "@/shell/commands/command"
import { SessionAncestorTrail, SessionProjectMenu, SessionTitleHeader } from "../session-identity-header"
import { SessionHeaderSpacer } from "@/session/header/session-header"
import { useEmbedded } from "@/runtime/embed"
import { SessionRunningMenu } from "@/session/header/session-running-menu"

type BlockingTask = { type: "shell" | "subagent"; partID: string; id?: string; label?: string }
Expand Down Expand Up @@ -123,6 +124,7 @@ function MessageTimelineView(
pending: TimelineController["pending"]
},
) {
const embedded = useEmbedded()
const language = useLanguage()
const server = useServer()
const data = server.ctx.data
Expand Down Expand Up @@ -162,7 +164,11 @@ function MessageTimelineView(
void data.location.vcs.sync({ directory }).catch(() => undefined)
})
const turnPadding = () => "px-4 md:px-6"
const showHeader = createMemo(() => !props.hideHeader && (props.data.showHeader() || workspaceSession()))

const showHeader = createMemo(
() => !embedded.embedded && !props.hideHeader && (props.data.showHeader() || workspaceSession()),
)

const pinned = createMemo(() => props.pinned)
const messageByID = projection.messageByID

Expand Down Expand Up @@ -461,7 +467,7 @@ function MessageTimelineView(
</Show>
)}
header={
<Show when={!props.hideHeader}>
<Show when={!embedded.embedded && !props.hideHeader}>
<SessionTitleHeader>
<div class="h-12 w-full flex items-center justify-between gap-2">
<div class="flex items-center gap-1 min-w-0 flex-1">
Expand Down
Loading
Loading