You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Status: rev 6, 2026-10-23. Supersedes TODO.11 (kept as history). Architecture unchanged — domain-agnostic substrate in SpaceGraphJS (@spacegraphjs/kernel), OpenCode a thin host — but the path is reordered so a complete usable base lands in ~6.5 days with zero regressions, and everything peripheral stacks after. Adds 10 design refinements and 7 development-path improvements.
1. Definition: what "usable base" means
Base = the kernel-backed system with no capability loss. Concretely, after Slice 3:
OpenCode's graph runs entirely on @spacegraphjs/kernel; buildGraph signature unchanged; both goldens byte-identical; all 179 session-ui + 104 session-graph tests pass untouched.
A dependent can: build a kernel, serialize it, diff two kernels, run derivers, query it, and render through the existing adapter/renderer contract (unchanged).
Everything else — navigation UI, profiles, clusters, continuous layout, spatial, a11y, review — is additive capability, each in its own shippable slice.
Base is not a demo. It is a library other projects can adopt, and the version of OpenCode with no behavior change.
2. Design refinements (deltas from TODO.11)
#
Refinement
Why
D1
Kernels preserve insertion order for nodes and edges; declared invariant.
Goldens and layout stability depend on order.
D2
SessionKernel state is the fold of its append log; checkout(v)/fork(v) replay entries to v. No per-version snapshots.
History without memory blow-up; time-travel becomes entry replay, not snapshot storage.
D3
deriveScope(keep: (node) => boolean) and deriveZoom({ levelOf, rank, level, expansion }) take host functions.
Kernel must not know domain, minLevel, or provenance — those are host metadata. Keeps the substrate genuinely domain-agnostic.
D4
provenance/confidence contracts are enforced by the host conformance run, not kernel core.
Kernel stays vocabulary-free; the host declares its own invariants.
D5
GraphQuery is topology-only. Spatial queries take an index explicitly: q.near(spatial, point, radius).
Query can ship in Slice 1, long before SpatialIndex2D. No API churn later.
D6
GraphModel becomes a view: toGraphModel(kernel). Kernel is the source of truth; existing selectors/tests read the view unchanged.
283 existing tests keep working; migration is internal.
D7
Groups are bands. The adapter already emits bands as RenderNodes; clusters reuse that mechanism with a data.group convention. No renderer-contract change in base or clusters. Native shape:'group' deferred (V66).
Zero contract churn; maximal alignment with ModelAdapter.
D8
Registry.actions is host-owned; kernel core leaves the slot empty.
Action vocabulary is OpenCode's, not the substrate's.
D9
Codec header carries format version + contract version; old files fail with a clear message.
Files outlive code; fail loudly, never silently.
D10
Kernel tests stay dependency-free: small seeded LCG generator in test utils, no fast-check.
Property tests without a dependency; same discipline as the package.
Dual-path compare during the port: SESSION_GRAPH_KERNEL=compare builds the model by both old builder and kernel, throws on divergence. Dev-only; deleted at the end of Slice 3.
Catches real-session divergence the fixtures miss, while both paths exist.
P3
Kernel JSON fixtures: once the codec exists, commit session.kernel.json / workspace.kernel.json; deriver tests become kernel in → kernel out.
Faster, clearer tests; derivers testable without message fixtures.
P4
Slice 1 ends publishable: version the package, add README + exports map.
Dependents can adopt immediately; API pressure surfaces early.
P5
No contract bump in base. Groups via bands (D7), so renderer v3 stays valid through Slice 6.
Removes a whole class of adapter/conformance churn from the critical path.
P6
Per-kind parity report: during the port, compare node/edge id sets per kind, not just the whole golden.
Makes a partial port debuggable ("directories match, symbols 3 off") instead of one opaque diff.
P7
Every slice ends shippable: named gate, green tests, no half-migrated surfaces.
No integration hell; any slice can be the last one for a while.
4. Revised slices — base first (6.5 days), then capability
Every kind announced/reachable; export round-trips
10. Real-time
post
kernel
T62 WorkspaceKernel.merge(delta) + deriver re-run
Converges; no full rebuild
Base = Slices 1–3 (6.5 days). Full capability = Slices 1–9 (~19.5 days). Slice 10 and the universal features (T63–T68) are post-plan.
5. Testing discipline (carried from TODO.11, tightened)
Laws, not snapshots, for substrate: round-trip, composition, monotonicity, order preservation, no dangling edges.
Contracts, not values, for hosts: every derived node has provenance; lenses never drop pinned kinds; no edge references a missing node. Enforced by the host's conformance run (D4).
Two goldens, one command: UPDATE_GOLDEN=1 bun test src/graph/workspace.test.ts. Byte-identical is the migration gate (Slices 1–3), then goldens document intent.
No exact-count/format assertions outside goldens and the codec format test.
Dual-path compare (P2) is temporary by design — deleted at parity; it must never become a permanent test.
Seed generators, not randomness. Fixed seeds in test utils; fixtures have no clock, no network.
Budgets warn, then hard-fail at 2×. Never flake on a near-miss.
Conformance is opt-in; core development is never blocked by host expectations.
Fail-useful: every failure names the invariant and the offending node/edge id.
A test that pins a value a developer would reasonably change is a bug in the test. If a test costs more to update than the change it guards, replace it with a law or a contract.
We will not: per-deriver snapshots; render-tree snapshots; pixel diffs; tests duplicating implementation logic; cross-file test ordering.
6. Codebase alignment (unchanged, now load-bearing)
Base-first ordering; base = zero-regression kernel-backed system
Value at day 6.5; every later slice is additive
77
Kernel functions take host predicates/config (D3)
Keeps the substrate vocabulary-free
78
Session state is a log fold (D2)
Time-travel without snapshot storage
79
Groups reuse adapter bands (D7)
No renderer contract churn in base; aligns with existing pipeline
80
Query ships topology-only (D5)
Unblocks navigation before spatial exists
81
Dual-path compare is temporary (P2)
Safety during the port, deleted at parity so it cannot calcify
82
No slice ships half-migrated
Prevents the long tail of two systems
10. Immediate next action
Slice 1, day 1: scaffold spacegraphjs/packages/kernel/ — package.json (zero deps, exports map, like @spacegraphjs/renderer), src/kernel.ts, src/codec.ts, seeded test generator, property tests for ordering + append-only + round-trip.
Slice 3 gate (the proof of the whole plan): both goldens byte-identical, dual-path compare clean on a live session, all existing tests green, scopeModel deleted.