Skip to content

refactor: architecture foundation — cycle-free imports, enforced layering, shared wire contract, CI-gated tests - #2199

Merged
benjaminshafii merged 10 commits into
devfrom
goal/architecture-refactor
Jun 12, 2026
Merged

benjaminshafii merged 10 commits into
devfrom
goal/architecture-refactor

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

What

Foundation refactor: 8 commits, net -397 lines, each individually tested and revertable.

Commit Change
1f5d2cc7e Delete dead packages/app/ orphan (diverged deep-link-bridge copy, zero refs)
51bdff909 Break runtime import cycles: LANGUAGE_PREF_KEY → i18n (kills genuine i18n↔constants runtime cycle); isDesktopRuntime → leaf lib/runtime-env.ts so low-level clients stop importing the 1,199-line utils barrel
18d199c12 Restore layering: app-inspector (zero-import instrumentation) → app/lib; provider-list-query → react-app/infra; BrowserPanelTab → desktop-types. Invariant: zero react-app/ imports in src/app/
efeff3d37 packages/types gains shared WorkspaceWire contract — the app↔server WorkspaceInfo shapes had already drifted (client-only token fields vs server-only opencode block, 3 sandboxBackend vocabularies). App type is now an alias; server gets zero-runtime compile-time tripwires so future drift fails producer typecheck
2de1a80c0 Repair 2 test files that rotted after #2016 (imports of removed exports); graceful sqlite skip for bun env; CI now runs the app+server unit suites for the first time (setup-bun + test steps before the e2e gate)
0bbf704a1 Remove unused Solid flavor of @openwork/ui (zero consumers) + 5 vestigial build hooks — dist/ was orphaned since all export conditions resolve to src/. pnpm typecheck is pure tsc now
5cc673c4b Dissolve last type-only cycles: Den wire types → leaf den-types.ts; ReloadReason ownership → extension manifest contract. madge --circular: 0 (was 7)
69175ec0a Rewrite stale ARCHITECTURE.md (claimed Solid still ships, src/react shims, Tauri) — now documents the real layout and the new enforced dependency rules

Tests (ran locally, evidence per step in commit messages)

pnpm --filter @openwork/app test       # 58 pass, 0 fail
cd apps/server && bun test             # 215 pass, 6 skip, 0 fail
pnpm typecheck                         # clean (app)
cd apps/server && npx tsc --noEmit     # clean (server)
pnpm --filter @openwork/app build      # vite production build clean
pnpm --filter @openwork/app test:e2e   # CI gate: 23/23 assertions ok
npx madge --circular src/app src/i18n  # 0 cycles

Live checks per step: vite dev server boots and serves the changed module graphs (200s); openwork-server boots with the new types import, registers a workspace, serves /capabilities with auth enforced.

No video: refactor-only PR with no user-visible UI change — the e2e suite + live boot checks above are the end-to-end evidence. Reviewer repro: the commands in the block above, plus pnpm dev for a manual smoke.

Follow-ups queued (tracked, each its own branch)

session-route/settings-route god-component decomposition · typed Electron IPC command map · server.ts route-registry split · extend contract pattern to the remaining 60 mirrored server types

Review in cubic

packages/app/ had no package.json (not a workspace) and contained a single
stale, diverged copy of deep-link-bridge.ts resurrected at the pre-restructure
path. The live file is apps/app/src/app/lib/deep-link-bridge.ts. Zero
references to the orphan anywhere in apps/, packages/, ee/, scripts/.

Tested: pnpm typecheck (clean).
Two runtime cycle edges cut:

- i18n/index.ts <-> app/constants.ts: LANGUAGE_PREF_KEY now lives in i18n
  (where it's used); constants re-exports it. Kills the genuine runtime
  cycle i18n -> constants -> i18n.
- lib/{openwork-server,opencode,den,den-telemetry}.ts no longer import the
  1,199-line utils barrel (which drags in i18n + constants) just for
  isDesktopRuntime: moved isElectronRuntime/isDesktopRuntime to new leaf
  module lib/runtime-env.ts; utils re-exports for the 7 react-app callers.

madge --circular: 7 cycles -> 2, and both remaining close via import-type
edges only (extensions->types, den-session-events->den), i.e. zero runtime
cycles. Those type edges dissolve in the upcoming shared-contract step.

Tested:
- pnpm typecheck (clean)
- bun test tests/ — 51 pass, 2 fail: verified identical failures on base
  via git stash (stale tests referencing removed exports, pre-existing)
- pnpm build (vite production build clean)
- live: vite dev server boots, / -> 200, transformed i18n/constants modules
  serve with the new export graph
…react-app

Fixes the three documented layering violations:

- app-inspector.ts (zero-import window-global instrumentation) moves from
  react-app/shell to app/lib where analytics.ts can legally use it; the 8
  react-app consumers now import from app/lib.
- provider-list-query.ts moves from domains/connections to react-app/infra
  (it is shared query infrastructure used by kernel, shell, components, and
  connections — and infra already hosts query-client.ts). Kills the
  kernel -> domains edge in global-sync-provider.
- BrowserPanelTab type moves to app/lib/desktop-types.ts (it describes
  desktop IPC bridge payloads); panel-tab-store re-exports it, so desktop.ts
  no longer reaches into the session domain.

Invariant restored: grep 'react-app/' in src/app -> zero hits.

Tested:
- pnpm typecheck (clean)
- bun test tests/ — 51 pass, 2 pre-existing failures (unchanged vs base)
- pnpm build (vite production build clean)
- live: vite dev server 200, analytics module serves with new import graph
packages/types gains src/workspace.ts: the canonical wire shape for
workspace records, unioned across what openwork-server emits (plain
optionals + opencode engine block) and what the desktop IPC bridge emits
(explicit nulls + openworkClientToken/openworkHostToken). This is the drift
that motivated the contract: each side had fields the other's type didn't
know existed, plus three different sandboxBackend vocabularies.

- apps/app: desktop-types.WorkspaceInfo is now an alias of WorkspaceWire;
  openwork-server.ts drops its OpenworkWorkspaceInfo opencode{} patch type
  (kept as plain alias for existing imports).
- apps/server: keeps its stricter internal interface but gains zero-runtime
  compile-time tripwires asserting (1) every field fits the wire contract
  and (2) no fields exist the contract doesn't know about. Future drift now
  fails typecheck on the producer.
- @openwork/types added as devDependency of openwork-server (type-only,
  erased at build; published artifact is bin/dist so npm consumers are
  unaffected).

Tested:
- pnpm typecheck (app, clean) + tsc --noEmit in apps/server (clean)
- bun test apps/app tests/ — 51 pass (2 pre-existing fails unchanged)
- bun test apps/server — 215 pass (2 pre-existing better-sqlite3-under-bun
  env failures, verified identical via git stash)
- pnpm build (vite production build clean)
- live: booted openwork-server (bun src/cli.ts), workspace registered,
  /capabilities serves and enforces auth — new types import resolves at
  runtime
The repo's strongest test suites never ran in CI (no bun setup, no test
scripts), which let two app test files rot when #2016 removed the legacy
message list:

- session-sync-tool-parts.test.ts: drop the removed shouldDeferInProgressTool
  import; deferral behavior stays pinned via parseDynamicToolUIPart nulls and
  the end-to-end session-sync test. Unlocks 5 previously-crashed tests.
- reasoning-display.test.ts: delete the markup test for the deleted
  SessionTranscript component (data-reasoning no longer exists in src);
  keep the DEFAULT_SHOW_THINKING product-default pin.
- opencode-db.test.ts (server): probe better-sqlite3 by constructing an
  in-memory DB and describe.skipIf when the native binding cannot load under
  bun (oven-sh/bun#4290) — env failures become explicit skips that
  self-re-enable when bun gains support.
- apps/app gains a 'test' script (bun test tests/); ci-tests.yml gains
  setup-bun + app and server unit-test steps before the e2e gate.

Tested:
- apps/app: bun test tests/ — 58 pass, 0 fail (was 51 pass / 2 crashed files)
- apps/server: bun test — 215 pass, 6 skip, 0 fail (was 2 env fails)
- tsc --noEmit in apps/server clean
The Solid entrypoint of @openwork/ui had zero import consumers (apps/app is
fully React since the migration; the only reference was a cosmetic string in
ui-demo). Removed src/solid/, its tsup/tsconfig, the ./solid export, and the
solid-js peer dependency.

Bigger win: every @openwork/ui export condition resolves to src/, so the
dist/ output was referenced by nothing — yet apps/app prebuild/prebuild:web/
pretypecheck and all three ui-demo scripts rebuilt it (twice, react+solid)
on every dev/build/typecheck. All five hooks removed; pnpm typecheck is now
pure tsc and pnpm build skips the double tsup entirely.

Tested:
- pnpm install + root pnpm typecheck (clean, no tsup in the path anymore)
- apps/app pnpm build (vite bundles @openwork/ui/react imports fine)
- apps/ui-demo pnpm typecheck (clean)
…-free

- den.ts no longer doubles as the Den type registry: the 14 wire types
  consumed across module boundaries (DenSettings, DenUser, DenOrg*,
  DenPluginConfig*, DenResourceSnapshot*) move to new leaf den-types.ts;
  den.ts re-exports them so its many importers are untouched.
  den-session-events and openwork-server now import the leaf instead of the
  2k-line client implementation.
- ReloadReason ownership flips from types.ts to extensions.ts (it is part of
  the extension manifest contract); types.ts re-exports. extensions.ts is
  now a leaf module.
- types.ts imports OpencodeConfigFile/WorkspaceInfo from desktop-types
  (leaf) instead of the desktop bridge implementation.

madge --circular on src/app + src/i18n: 0 cycles (7 when this branch
started; the graph is now a DAG).

Tested:
- pnpm typecheck (clean)
- bun test tests/ — 58 pass, 0 fail
- pnpm build (vite production build clean)
- live: vite dev server 200, den-types module serves
The doc still described the Solid-to-React migration: 'The Solid runtime
still ships by default', src/react/** shims, Tauri-vs-web platform, and a
porting pattern for a migration that finished long ago. src/react/ does not
exist and there are zero solid-js references in src/.

Rewritten around what is now true and enforced:
- layer map including src/app (agnostic) + leaf modules (runtime-env,
  desktop-types, den-types, extensions) from this branch's refactors
- dependency rules: app/i18n never import react-app, kernel/infra below
  domains, leaves import nothing, wire contracts in packages/types,
  madge --circular = 0
- current domain list (cloud, onboarding, sidebar, terminal, voice, ...)
- kept the still-accurate route/state-ownership rules verbatim
- testing section pointing at the now-CI-gated suites
@vercel

vercel Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Jun 12, 2026 7:22pm
openwork-den Ready Ready Preview, Comment Jun 12, 2026 7:22pm
openwork-den-worker-proxy Ready Ready Preview, Comment Jun 12, 2026 7:22pm
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 12, 2026 7:22pm

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 51 files

Re-trigger cubic

A triggerless directory-level fs event arriving inside the debounce window
overwrote the pending named file trigger with undefined, so the emitted
reload event lost its trigger {name, path}. Event ordering is platform
dependent — this surfaced immediately as a macOS-only failure in
reload-events.e2e.test.ts once CI started running the server suite (this
branch), while passing on Linux and fast local runs.

Coalescing now keeps the existing named trigger unless the newer event
carries its own.

Tested: bun test src/reload-events.e2e.test.ts src/reload-watcher.test.ts
5x consecutive green; full server suite 215 pass / 6 skip / 0 fail;
tsc --noEmit clean.
On macOS, fs.watch can deliver directory events with no filename. The
workspace-root watcher then scheduled the config check without a trigger,
producing reload events missing trigger {name, path} — the remaining cause
of the macos-14 CI failure in reload-events.e2e.test.ts (Linux always
provides filenames, so ubuntu stayed green).

Mirror the inference ensureOpencodeRootWatcher already uses: resolve the
existing opencode.json(c) (and AGENTS.md for the agents reason) and
synthesize the trigger. checkReason only emits when the content fingerprint
actually changed, so inferred triggers cannot create spurious events.

Tested: reload suites + full server suite green locally (215 pass / 6 skip);
tsc --noEmit clean. Real validation is the macos-14 CI job on this PR.

This branch was successfully deployed

4 active deployments
Preview – openwork-den-worker-proxy — 50b906c8 Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-landing — 50b906c8 Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-den — 50b906c8 Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-app — 50b906c8 Deployed Jun 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant