Skip to content

Publish Adapter Interface - #601

Merged
abogartz merged 16 commits into
abogartz:mainfrom
WhollyMindless:feat/public-adapter-api
Dec 1, 2026
Merged

abogartz merged 16 commits into
abogartz:mainfrom
WhollyMindless:feat/public-adapter-api

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This is a preliminary experiment to understand how we could split adapters out of the codebase and whether the engine exposes the necessary contract. Pi, oh-my-pi and OpenCode now use public engine entry points, including OpenCode's commands and TUI. Same-revision extraction tests and an API version do not establish a complete installation, upgrade and release workflow for independently maintained external repositories.

Preliminary experiment; adapter dependencies have landed. #561 and #570 are merged, and this branch includes main 6e33179 (package version 0.41.1). GitHub's diff against main now isolates the public API, adapter migration and verification work. The external packaging model and compatibility policy remain subject to review.

Public boundary

  • opencode-self-improvement/host: shared setup and host contracts, configured store location, shipped command text, capture-lifetime verification and narrowly scoped capture diagnostics.
  • opencode-self-improvement/status: local status reads, repository-scoped blocked writes, change-notification paths, payload types and presentation helpers. Missing repository ownership does not default to administrative visibility.
  • All maintained adapters use these entry points for engine access, including type-only dependencies. Relative imports stay within each adapter. Boundary tests reject private paths, cross-adapter imports, aliases and computed dependency shortcuts.

Initial API versioning

Both entry points export ADAPTER_API_VERSION = "0.1.0" and assertAdapterApiVersion(required). This contract version is separate from the engine package's release version.

Every MemoryHost declares the adapter's expected apiVersion. Setup rejects missing or mismatched versions before touching other ports, probing lifetime, configuring the store, installing commands or registering tools/hooks. Native adapters also check before any earlier registration or engine services; OpenCode's TUI checks its status API before setup. Expectations are adapter-owned literals, never copied from the installed engine's version.

The initial policy is exact matching, with exact engine release pins still recommended. Engine-only changes can retain the API version; public contract changes require a deliberate experimental revision. This covers types and behavior, including lifecycle/disposal and status semantics. There is no compatibility-range or negotiation promise.

Fast AST guards inspect all maintained adapters, including OpenCode's TUI, for adapter-owned current literals and reject copying the engine's version. The normal unit suite also pins current-version claims in the API guide, adapter reference and host contract to the export. Source-policy checks complement the packed/native early-rejection tests; they do not prove runtime ordering. Documentation explains the deliberately broad string declaration and the trusted-code/filesystem boundary.

Status writers stamp snapshots with the API version. Public status reads return null for incompatible or unversioned snapshots, so an older snapshot is unavailable until a matching writer refreshes it. Internal legacy readers retain their existing behavior.

Extraction and compatibility experiments

The package test installs the packed engine outside the checkout, without source links or TypeScript aliases. The fixed api-0.1.0 consumer and its content digest provide an initial baseline for later engine changes. It checks version rejection, gated writes, restart recall/injection, ownership, status and idempotent disposal. Keeping this fixture unchanged prepares future compatibility testing; it does not demonstrate two independently released versions today.

The same test separately packs each production adapter's unchanged sources, removes the engine's bundled adapters, and typechecks all three—including OpenCode's TUI—against installed SDK types. A fresh-process fault-injection test changes only the fixture engine's advertised version to 0.2.0; all three adapters must reject it before accessing host ports or creating a store. The test replaces the installed file before mutation and verifies hardlinked copies remain unchanged.

Native Pi and oh-my-pi installation scenarios cover bundled and extracted packages: tools, restart recall/injection, configuration, commands, isolation, capture, uninstall and shared-store readback. OpenCode loads the extracted package, installs commands, writes/recalls across processes, injects context and excludes another project's memory; its TUI entry compiles with the expected JSX runtime.

Validation

Fast-guard follow-up at 428cb6a: 24 focused version/boundary tests, root typecheck, changed-file lint/format, comment policy and diff checks pass. Five deliberate working-tree mutations were rejected: Pi borrowing the engine version, stale current-version prose in each of three guides, and an engine version bump without matching consumer/documentation updates. This follow-up changes tests and documentation only. All nine CI checks passed at 428cb6a, including the required Linux/Windows tests and both Pi-family adapters on Linux and Windows.

Latest main merge at 18291be: includes upstream 6e33179 and preserves its capture-disabled and queued-drop reporting through the public API. Local validation passes 2,161 tests, 35 skips, zero failures, plus root typecheck, lint rules, comment policy, conflict-resolution formatting and the complete packed-consumer/extracted-adapter check. All nine CI checks passed for this head, including both Pi-family adapters on Linux and Windows.

Local Windows / Bun 1.4.4 / Node 24.15.0, at b9021795:

Fixes #623. Public /host and /status consumers now typecheck with NodeNext and types: ["node"], without Bun declarations. Shipped command reads use node:fs/promises; setup inspects an optional Bun runtime without requiring its global type. The package runner performs this check before installing native SDKs or Bun types, then runs the unchanged consumer in fresh Bun and plain Node processes through a scoped tsx import. CI pins Node 22.19.0 for this package check on Linux and Windows.

Validation: 2,150 unit tests passed, 35 skipped, zero failures on the full rerun. The first full run hit an intermittent store-lock/teardown failure in lock-narrowing.test.ts; that file passed alone and the full rerun passed. Root typecheck, lint rules, comment policy and formatting in an LF-normalized snapshot pass. The package check passes Node-only typechecking, command loading, gated writes, restart recall/injection, project isolation, status, disposal, all detached adapter typechecks and incompatible-engine rejection. Before the production fix, the new Node-only check failed on all three reported Bun references. All nine CI checks passed for this commit, including the Node-only packed-consumer check on Linux and Windows.

That validation used main d7521e6f and experimental adapter API 0.1.0. This correction does not publish the entry points to npm or resolve the separate version-policy and release-workflow questions.

Earlier validation:

The test-only follow-up from #570 d98a5d52 is merged as f3f1de21: queued-capture shutdown completion and independent oh-my-pi empty-receipt accounting coverage. All 24 selected regression, import-boundary and API-version tests pass through the public API, along with root typecheck and comment policy. The full-suite measurements below predate this five-test addition; production sources are unchanged by the merge.

  • Shared/unit suite: 2,114 passed, 34 skipped, 0 failed.
  • Pi native suite: 41 passed, 0 failed.
  • oh-my-pi native suite: 40 passed, 0 failed.
  • Packed consumer, all detached adapter typechecks and incompatible-engine checks: passed.
  • OpenCode load/extraction suite: 4 passed, 0 failed.
  • OpenCode full suite: 62 passed, 1 failed. The standalone capture-teardown persistence test on local OpenCode 2.4.2 also failed on pre-migration commit 997f098d; cooperative-server capture passes.
  • Typecheck, lint rules, boundary/version/status tests, documentation links, comment policy and diff checks pass. Formatting passes in an LF-normalized snapshot; the Windows checkout has existing CRLF differences.

The adapters remain bundled for distribution. No separate adapter packages or engine release are published here. The reusable conformance suite remains repository-local, and new hosts still need their own native lifecycle tests.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Note

🤖 gpt-6-astra responding on behalf of WhollyMindless

This PR is an experiment to understand how we might split the adapters out of the codebase and identify what the engine would need to expose.

The separate-package tests exercise the current adapter sources against the same engine revision. That is useful evidence about the boundary, but it is not proof of a complete workflow for independently maintained and released external adapter repositories. This work was a necessary step toward determining whether we are ready to attempt that.

A possible next pass is to give the adapter API an explicit version and compatibility policy. We want to discuss that design before making further implementation changes. Please treat this PR as exploratory groundwork, not a commitment that the external-adapter model or interface is settled.

@WhollyMindless
WhollyMindless marked this pull request as ready for review November 29, 2026 04:40

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Architecture seat — proposal gate

Reviewing this as a design proposal, not a diff: the PR's own ask is a decision on
the version and compatibility policy before more code. No merge verdict here.
All measurements below were run by this seat in a scratch copy at head 9a90973f
(which contains current main); nothing in the main checkout was modified.

The direction is right and one part of it is genuinely good: the extraction
runner packs the revision, deletes the engine's bundled adapters, asserts the
native SDKs are absent, and typechecks the unchanged adapter sources — that is a
boundary proof rather than a boundary claim. The rest of this message is the part
that has to be answered before 0.1.0 becomes something an outsider depends on.

1. What this seat measured

# Input Surface Result
M1 ADAPTER_API_VERSION → 0.2.0, then run the retained api-0.1.0 fixture integration/adapter/fixtures/api-0.1.0/consumer.ts dies at consumer.ts:27 (ERR_ASSERTION), before any behavior is exercised
M2 same bump test/host/api-version.test.ts 3 fail / 8 pass
M3 src/adapters/pi/runtime.ts: const REQUIRED_API_VERSION = ADAPTER_API_VERSION (the "DRY up the literal" refactor the doc forbids) test/host/import-boundary.test.ts + test/host/api-version.test.ts survives — 15 pass / 0 fail
M4 enumerate any test/script pinning adapter expectations rg -ln 'REQUIRED_API_VERSION' test/ integration/ scripts/ empty
M5 enumerate anything checking the doc's version prose rg -ln 'adapter-api\.md' test/ scripts/ .github/ empty
M6 call memoryDirectory() and readMemoryCommand("repo-init") with no version check anywhere fresh Bun process against opencode-self-improvement/host both succeed; store path returned, command text returned (735 bytes)
M7 status snapshot stamped 0.2.0 on disk (writer stamped 0.1.0, then rewritten) public readStatus("probeB") and readStatus() null both ways, no throw, no diagnostic; memoryStatusPaths() still points at the same directory
M8 proposed guard (see A3) — AST check that each adapter expectation is a string literal clean head PASS
M9 same guard M3's mutant tree FAIL (non-literal:Identifier, plus "imports ADAPTER_API_VERSION from the engine")
M10 reject-version.ts behavior under M3 test:adapter-package unexecuted (needs pack + three SDK installs). Its regex pins adapter requires "0.1.0" (integration/adapter/reject-version.ts:20), so it should fail; this seat did not run it

CI at this head: 8/8 green (lint, test, test-windows, smoke, smoke-stable,
pi ×2, oh-my-pi ×2), mergeStateStatus: BLOCKED on review.

2. Design space, before the implementation

"Keep an adapter maintainable by someone who does not own the engine" has more
than one solution point, and they fail differently:

  1. In-tree boundary only — an import-policy lint, no packaging change. Cheapest;
    protects nothing once the adapter actually leaves the repo.
  2. Published subpath + exact contract version marker — what this PR ships. Solves
    one engine ↔ one adapter contract drift, loudly, at setup. Says nothing about
    shared on-disk state.
  3. peerDependencies / single-instance engine — wins the moment two adapters and
    a host coexist in one process, where duplicated engine copies are the failure.
  4. Compiled SDK package (.js + .d.ts, no source graph published) — wins when
    consumers are Node-loaded or when shipping the whole src/ graph is unacceptable.
  5. Protocol boundary (engine behind a versioned wire/IPC contract) — wins exactly
    where an in-process version marker structurally cannot reach: two engine versions
    alive at once against one store. Costs an IPC layer and the whole in-process port
    model.
  6. Store-format versioning + open-time migration — governs the artifact adapters
    actually share, and makes 2 a necessary-but-not-sufficient check rather than the
    only one.

This PR sits squarely on 2 and explicitly excludes 6
(docs/reference/adapter-api.md: the version is "separate from native host SDK
versions and durable memory-store formats"), while OPENCODE_MEMORY_DIR makes one
store shared across harnesses. The PR's closing paragraph names the unresolved
problem — install/upgrade/release for independently maintained repos — and 5 and 6
are where that problem lives. That is fine for an experiment; it is not fine to
merge a policy doc that reads as if the compatibility question were settled.

3. The grill

A. The version marker's own mechanics

A1 — The retained fixture cannot survive the bump it exists to police. What is the green path?
scripts/test-adapter-package.ts:86-93 digests fixtures/api-0.1.0/consumer.ts and
fails with "The API baseline fixture changed; retain old fixtures when evolving the
contract"
— then copies that fixture into the consumer, installs the current
revision's tarball
, and runs write/read/foreign. The fixture's first two
assertions are assert.equal(ADAPTER_API_VERSION, "0.1.0")
(consumer.ts:27-28). M1: bumping the constant kills it on line 27. CI runs this
runner in both test and test-windows (.github/workflows/ci.yml:58,73). So the
first deliberate 0.1.0 → 0.2.0 lands as a red CI whose only fast resolution is
editing the fixture and regenerating its digest — the exact act the message forbids.
Which is it: (a) fixtures become version-selected and each runs against an engine
whose advertised version matches, (b) the fixture stops running against the working
tree and only ever runs against published engines in a dedicated compatibility
job, or (c) it is one-shot and gets replaced, in which case the "retain old fixtures"
sentence is false and the digest is churn with a scary message? Answer in the doc,
not in a comment — the sentence is the interface.

A2 — Nothing keeps the prose true. M5: no test, script, or workflow references
docs/reference/adapter-api.md. 0.1.0 is asserted in five places in that file,
plus docs/internals/host-contract.md:21 and docs/reference/adapters.md:24. M2
shows the constant can move while every one of those keeps saying 0.1.0. Who owns
that truth — a check that reads the declared version out of the doc and compares it
to ADAPTER_API_VERSION, or a human memory? Model-facing docs get repeated to users
as fact; an unversioned doc beside a versioned API is the one place the version
policy silently rots.

A3 — The invariant the doc calls defeat-the-check is unenforced in the fast lane.
MemoryHost.apiVersion is readonly apiVersion: string (src/host/runtime.ts:9), so
apiVersion: ADAPTER_API_VERSION typechecks — the precise thing
docs/reference/adapter-api.md says must not happen ("Assigning the engine's
ADAPTER_API_VERSION to host.apiVersion would silently accept whatever engine is
installed and defeat the check"). M3/M4: the refactor passes typecheck, lint and
the unit lane; rg finds no pin on adapter expectations anywhere in test/. The
only guard is a message regex inside the packing job (M10, unexecuted). This seat
executed a candidate guard: an AST check that each adapter's expectation resolves to
a StringLiteral and that ADAPTER_API_VERSION never appears in an adapter's import
list from the engine — PASS at clean head, FAIL on the mutant (M8/M9). Which do you
want: the AST pin in test/host/import-boundary.test.ts, or apiVersion typed so
the copy is a type error? If string is deliberate so an old adapter can reject a
new engine at runtime, say so in the doc — that reasoning is currently invisible,
and it is the only defense the field has.

A4 — The gate guards setup only; the rest of the surface is prose-governed. M6:
with no version check anywhere, memoryDirectory() and readMemoryCommand()
succeed, and they are the two functions that hand an adapter the store path and the
engine's own command text. Same shape for verifyCaptureLifetime,
reportCaptureSkipped, reportCaptureDisabled, readBlockedWrites.
docs/reference/adapter-api.md pushes the duty onto the adapter ("must call
assertAdapterApiVersion first"). An external-adapter API whose safety depends on an
unenforced instruction in a doc is a convention, not a contract. Name the
call-safe-before-check set exactly — which of the exported runtime values in
src/host/index.ts and src/status/index.ts may be called before the check, and
which must not — or make every exported operation assert. Which one, and why?

A5 — memoryDirectory() plus the filesystem is a policy bypass, and the doc recommends living there.
The engine's whole ownership model (repo scoping, session privacy, quarantine) is
enforced in code above the store directory. memoryDirectory() returns that directory
and the doc suggests adapter settings "can live beneath this directory". A third-party
adapter — one that has not passed any review — can readdir and read every repo's
memory rows with plain node:fs, no private import involved, and exports cannot
stop it. What is the intended isolation story for a third-party adapter reading the
shared store: documented trust ("adapters are trusted code, like a plugin"), a
per-adapter subdirectory convention with a name-derivation rule, or is store access
out of the contract and the getter should go? "Trusted code" is a legitimate answer;
silence about it is not, because the store holds other repositories' rows.

B. The upgrade story the marker creates

B1 — Mismatch is invisible on the only surface that shows status. M7: a snapshot
stamped 0.2.0 yields null from both readStatus(sessionID) and readStatus(),
no throw, no distinguishing signal, while memoryStatusPaths() keeps pointing at the
same directory — so a watcher still sees activity that every read refuses. The sole
consumer is OpenCode's TUI (src/adapters/opencode/tui/panel.tsx:90), which renders
nothing. The PR's stated goal is independent release cadence, which makes
"engine bumped, adapter not yet" the normal operating state, not an edge case. Why
null rather than a typed { unavailable: "api-mismatch", found, expected } on the
one surface where a human would read it? If "blank forever until the adapter ships" is
the accepted UX, put that sentence in adapter-api.md where users will find it.

B2 — Whose digits are they? Exact equality on a semver-shaped string with "no
compatibility-range promise" is a defensible start, but the doc does not say who may
change which digit or what each means. Concretely, name the verdict for each: adding
a field to StatusPayload; adding an optional method to MemoryHost; removing a
member from CaptureSkipReason (src/host/services.ts:20-24 — an external adapter
switches on that union, and the allowlist throws for unknown values, so a removal is
a runtime break in the adapter, not a type error); rewording a shipped command. Which
of those is a new 0.x.0, and is that decision recorded in a file a bump PR must
touch?

B3 — Is shipped prompt/command text under the version? readMemoryCommand() returns
engine-owned repo-init.md / memory-report.md text that changes adapter behavior. A
wording change is invisible to ADAPTER_API_VERSION. The doc says the version covers
"exported types and operations … and the status payload and presentation contract" —
does command text fall inside that, and if not, what tells an adapter pinned to
0.1.0 that its users' /memory-report instructions changed?

C. What extraction actually breaks (the excluded points, 5 and 6)

C1 — Two engine versions, one store. The version policy explicitly excludes the
durable store format, and the store is shared by configuration. Post-extraction, a
user can run engine A (adapter pinned 0.1.0) and engine B (0.2.0) against the same
OPENCODE_MEMORY_DIR. Today's file-level lock serializes writes; nothing versioning-wise
stops a newer-format row from being misread by the older engine. What is the artifact
that decides this, and is it in scope before the first adapter leaves the repo? If the
answer is "store format is separately versioned", where does it say so — because
adapter-api.md currently disclaims the topic without pointing anywhere.

C2 — dependencies invites N engine copies in one process. The install section tells
adapter packages to declare the engine in runtime dependencies; the engine's own
peerDependencies carries only @opentui/* and solid-js. Install engine + two
external adapters and the resolver may hand you multiple engine instances. In-process
state is per-copy (src/core/state.ts:104,155, src/telemetry/ledger.ts:541
ledgerCache, src/runtime/setup.ts:31) while the store, evidence log and status
files are shared paths — so counters, epoch accounting and harness attribution split
across instances writing one store. Was peerDependencies considered and rejected? If
dependencies stands, which of those module-level singletons is safe to duplicate, and
what is the observable symptom when two copies coexist?

C3 — The package still publishes the adapters it is trying to evict. package.json
exports still list ./tui, ./oh-my-pi, ./pi and files still ships all of src.
So the engine offers both a public boundary and the bundled adapters as public entries.
After extraction, do those entries stay (two copies of every adapter behind one contract
version) or go (a breaking removal that 0.1.0 has to describe)? Which release carries
the removal, and does the fixture story in A1 have room for it?

C4 — The public surface is TypeScript source, and every extraction test runs under Bun.
The exports map targets ./src/host/index.ts with no types condition, and the runner
writes a consumer tsconfig.json requiring allowImportingTsExtensions: true
(scripts/test-adapter-package.ts:66-81). The same doc advertises Node.js 22.19+ support.
How does a Node-loaded external adapter import a .ts entry — does the host compile it,
does the adapter ship its own build, or is a d.ts/JS build a precondition for
extraction (point 4 above)? Which test in this PR runs the public boundary under Node
rather than Bun? If none, say so plainly in the body: "the boundary is proven under Bun
only".

4. Prose that currently outruns the measurement

Claim-surface pass on the added text; each row names the surface that can see it.

Shipped claim Surface that can see it Status
"Assigning the engine's ADAPTER_API_VERSION … would defeat the check" (adapter-api.md) unit lane + packing job true as advice, but unenforced in the fast lane (M3, M4); the check exists only as a message regex in reject-version.ts
"retain old fixtures when evolving the contract" (scripts/test-adapter-package.ts:92, surfaced as a CI failure) CI test / test-windows contradicted by the runner's own design (M1): the retained fixture cannot pass a bumped engine
"readStatus returns null for … differently versioned snapshots … it is not silently interpreted" OpenCode TUI measured true (M7), and null is indistinguishable from "no data" on the only consumer — B1
"Status writers stamp snapshots with apiVersion" store on disk measured true (M7: 0.1.0 on disk)
"Its contract version is 0.1.0" ×5, host-contract.md:21, adapters.md:24 docs, repeated by the model nothing checks them (M5)

5. Verdict against the blocking standard

Not DRASTIC — the pattern (public subpaths, adapter-owned expectations, real
extraction proof) is the right shape, and this seat would build on it.

Answer before this becomes the API's first public contract: A1, A2, A3, B1, C1, C4.
A1 and A2 are policy contradictions with measured consequences; A3 has an executed fix
ready (M8/M9); B1 and C1 are the two failure modes that independent release cadence
makes routine; C4 decides whether "external adapter" means Bun-only.

Mergeable-now reading: this is sound groundwork if the version-policy section is
trimmed to what is measured — exact match at setup, Bun-only extraction proof, status
unavailability on mismatch, store format explicitly unversioned with a pointer to the
issue that will decide it — and the unmeasured promises ("retain old fixtures", any
implication of an upgrade path) are removed rather than qualified. The engine-side
boundary work (adapters through /host and /status, the AST import policy, the
extraction harness) stands on its own and does not need the version story resolved.

No review from this seat blocks the boundary code. It does block publishing 0.1.0
as a promise to strangers.

@abogartz

Copy link
Copy Markdown
Owner

First outside consumer: dsh-self-improvement — what the boundary held and what it did not

An external adapter for DeepSeek Harness now exists at
WhollyMindless/dsh-self-improvement (tracking: #621). It consumes /host from this PR's
head as a separate package. I ran it locally against the pinned engine. This is the first
evidence for the readiness questions raised above, and it resolves three of them while
adding one defect on our side.

Our side: the public entry point is not type-checkable without Bun typings (defect, small fix)

A minimal consumer —

import { readMemoryCommand, type MemoryHost } from 'opencode-self-improvement/host';
export const h: Pick<MemoryHost, 'apiVersion'> = { apiVersion: '0.1.0' };
export const cmd = readMemoryCommand('repo-init');

with moduleResolution: NodeNext, strict, types: ["node"], skipLibCheck — fails:

node_modules/opencode-self-improvement/src/host/services.ts(16,10): error TS2868: Cannot find name 'Bun' …
node_modules/opencode-self-improvement/src/runtime/setup.ts(97,14): error TS2868: Cannot find name 'Bun' …
node_modules/opencode-self-improvement/src/runtime/setup.ts(97,43): error TS2868: Cannot find name 'Bun' …

Adding @types/bun clears it. The adapter's own tsconfig.json carries
"types": ["node", "bun"] and its README says the same thing independently, so this is
reproduced from two directions. skipLibCheck does not save a consumer because we ship
.ts, not declaration files.

Two lines close it: readMemoryCommand reads via node:fs/promises, and the
Bun.version probe reads Bun off a typed globalThis cast. Until then every external
TypeScript adapter installs Bun typings to consume a Bun-optional engine — a promise our
own doc contradicts ("Node hosts do not need a Bun process bridge").

C4 answered: it works under plain Node, at a price we have not costed

The adapter loads the entry point through tsx's tsImport, scoped to that one import
(src/index.ts:26), and bundles with --packages=external. Its suite passes under plain
Node with no global TS loader (test/package.test.ts, 7/7 for me on Node 22.23.4, and
green in its own CI on Linux and Windows with Node 24.15.0). So the boundary is reachable
off Bun — but the cost is a runtime tsx dependency plus esbuild in every external
adapter, purely because exports maps ./host to ./src/host/index.ts. That trade
belongs in adapter-api.md next to the Node support claim, or in front of a compiled-JS
build.

C2 answered: peer-dependency placement is the shape that works

The adapter declares opencode-self-improvement as an exact peer, with the dsh SDK
packages also peers, and its own runtime dependencies are tsx and zod only. That is
the single-instance answer. Worth stating as policy in the doc — engine as
dependencies invites N engine copies per process, with per-copy module state against one
shared store.

C1 partially answered: the cross-process shared-store proof exists, and not in our CI

test/package.test.ts plus its reference-consumer scenario runs a separate public-API
host that reads dsh's project memory, writes a global preference, has it injected by a
restarted dsh process, and confirms a foreign project cannot read the project memory. That
is the store-sharing check asked for above, built by an outsider. It should not live only
in their repository.

A1/B2 got a concrete victim: the pin cannot resolve

peerDependencies["opencode-self-improvement"] is "0.41.1" while the working install is
devDependencies → codeload.github.com/WhollyMindless/opencode-self-improvement/tar.gz/9a90973f…,
and their test asserts the peer value (package.test.ts:24-26). Verified: npm view [email protected] exports returns ., ./pi, ./tui, ./oh-my-pi — no
./host, no ./status. Their README states it honestly ("Do not replace the dependency
with [email protected]"), which is exactly the problem: the manifest now
requires prose to explain why the manifest is wrong, and adapter-api.md forbids shipping
a checkout link. This is the version-policy question landing on a real consumer rather
than on a hypothetical.

New, and not in my earlier list: pnpm blocks the transitive install

pnpm's default security policy rejects a source archive as a transitive dependency, so the
engine cannot arrive as the adapter's dependency at all. A user must install engine and
adapter separately, with --ignore-scripts to avoid an unapproved transitive esbuild
build hook. That is their documented install path today. It means "install an adapter, get
memory" does not exist, and it will not be fixed by the version marker — it is a
distribution-format consequence of publishing TypeScript source. Strongest argument yet
that the release workflow is the unsolved half of this PR, not the TypeScript boundary.

Also true, worth recording

The adapter never touches /status and declares usageReceipts: false, so the status
payload's behavior for a host that reports no usage has zero external coverage — one
consumer remains, OpenCode's TUI.

None of this changes the verdict above: the boundary is the right shape and now has an
outside implementation that passes its own native suite against it. The additions to the
answer-before-publishing list are the Bun typings defect (ours, two lines) and the pnpm
distribution fact (ours, structural).

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note

🤖 gpt-6.2-sol responding on behalf of WhollyMindless

I propose keeping the experimental adapter API at 0.1.0 and addressing the engine-side review findings before the first registry release that includes /host and /status. The dsh adapter fixes are being handled separately. Its trial gives us an external consumer to validate against.

Changes in #601

  • Make version bumps testable. Select the packed-consumer fixture by the engine’s advertised API version. Preserve the 0.1.0 fixture, and add a check that an adapter pinned to 0.1.0 rejects a newer engine before setup touches the host or store. Add fast checks that adapter expectations are adapter-owned literals and that the documented current version matches the export.
  • Make status mismatches visible. Give the OpenCode TUI a typed way to distinguish an incompatible snapshot from missing status. Preserve the current readStatus() return behavior so existing consumers keep working.
  • Verify the Node consumer path. Remove the Bun globals that force an external TypeScript consumer to install Bun typings. Add a clean NodeNext typecheck with Node-only types against the packed engine, and exercise the documented Node loading path in a separate process.
  • Document the compatibility limits. Keep exact API matching and recommend an exact engine peer dependency for external adapters. Require the version check before engine operations and document that in-process adapters run as trusted code. State that shared-store behavior has been exercised with the same engine build. Mixed-version store compatibility needs its own policy and upgrade tests. Keep the bundled adapter exports available.

Version and release

Keep 0.1.0 for changes that preserve the existing contract. If we deliberately break an exported type or a behavior an adapter relies on, advance the experimental API version and add the matching fixture in the same PR. The engine’s npm version is separate. The published 0.41.1 package lacks the new entry points.

Once we agree on the package format, publish a new engine prerelease and validate it from the registry. Install it with npm and pnpm in clean environments, resolve the adapter’s exact engine peer, and start an external consumer under Node through the documented loader. If that path uses tsx, document it as a runtime dependency for source consumers. Treat loader-free Node imports as a separate packaging decision with their own test.

Does this scope match what you want in #601? The release criterion would be a clean install and startup from the published prerelease.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Note

🤖 gpt-6-astra responding on behalf of WhollyMindless

428cb6a adds the fast guards requested in A2/A3. test/host/version-policy.test.ts inspects all maintained adapters, including OpenCode's TUI, for adapter-owned current literals in version checks and host declarations. It rejects borrowed versions, stale literals, and missing checks/declarations at the maintained entry points. Current-version claims in the API guide, adapter reference and host contract are checked against the export.

The guide now explains why MemoryHost.apiVersion remains string and states the A5 trust boundary explicitly: in-process adapters have the host's filesystem access; the version check is not a sandbox.

Validation: 24 focused tests pass, along with root typecheck, changed-file lint/format and comment policy. Five actual source/document mutations failed the guard as intended: Pi copying the engine version, each guide advertising a stale version, and an engine bump without consumer/doc updates. CI is pending for this head. Production behavior and API version are unchanged.

The retained-fixture selection, typed status-mismatch diagnostic, and remaining compatibility/release-policy proposals are still separate work. This does not mark those review items resolved.

ocsi-reviewer[bot]
ocsi-reviewer Bot previously requested changes Dec 1, 2026

@ocsi-reviewer ocsi-reviewer 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.

PR Reviewer

Review — PR #601 "Publish Adapter Interface" @ 428cb6ab7ee359fd43a1d20e639a7588c0187fa3

Method disclosure first. This review ran a shape pass before reading the diff, PR body, or comments: problem statement, replacing alternatives, and invariants were written from the base tree (6e33179, extracted via git archive) with only PR metadata, a title-search for the originating issue, and issue #623's body (found through a capture() of the Closes line — no body prose printed). Full pre-diff write-up: .dev/601-shape.md. After that the diff was read with nothing held blind. Reviewer environment: macOS, bun 1.4.4, default Node 20.20.2 with v22.23.4 used where Node 22 is required — the known environmental baseline; nothing below leans on it.

Did the design fall inside the space drawn before the diff?

Yes. The space written before the diff named four replacing shapes: publish the live seam through a new entry (S1), a generated declaration surface from one source of truth (S2), the conformance kit as the contract (S3), and publish-nothing (S4). The contribution is S1 done with the enforcement the invariants demanded — and it beat S2 to S2's own goal a better way: the sha-pinned api-0.1.0 consumer fixture, reinstalled from the packed tarball and typechecked on every run, is a frozen old consumer, which is a better drift artifact than a generated .d.ts in a tree that deliberately ships TS sources. That is where one of my assumptions was wrong: I had assumed golden API visibility required emitted declarations; a frozen consumer gives the same diff-ability with no build step. Two scope choices fell outside the predicted surface but inside the shape family: the second /status entry, and making the OpenCode TUI a version-checked /status client. The predicted redundancy did not materialize at any of the four sites named in the shape pass: ensureCommand now delegates to readMemoryCommand instead of duplicating the read; MemoryHost is re-exported, not forked; setupMemory is the published function itself, not a wrapper; ADAPTER_API_VERSION has one definition, and the AST guard makes copying it into an adapter a test failure — the exact-match policy with adapter-owned literals is the correct answer to the decorative-version-number risk. S3 (publishing the conformance kit) is not adopted and is declared, which per the blocking standard does not block; the same goes for the release workflow and npm publication.

Verified claims (measurements, with commands)

All runs in a fresh /tmp clone verified at 428cb6a; every store-touching command ran with OPENCODE_MEMORY_DIR set to a fresh directory.

  • The surface is real and consumer-reachable. Not just exported internally: bun pm pack, install from the tarball in a clean project, my own probe file (reviewer-chosen symbols, not the fixture's) with NodeNext, strict, types: ["node"]: typecheck clean; a MemoryHost literal without apiVersion is a compile error (the @ts-expect-error fires); opencode-self-improvement/src/runtime/setup.ts and …/status/write.ts are TS2307 — private paths unreachable. Bun runtime smoke: memoryDirectory() honors config, readMemoryCommand returns the shipped text, assertAdapterApiVersion("9.9.9") throws, readStatus is null. Loose-copy probe (tarball contents, no node_modules): the self-referencing import "opencode-self-improvement/host" resolves under bun and command install works — the degraded plugin path the root shim documents still holds.
  • #623 is genuinely fixed at the boundary. bun run test:adapter-package — 12/12, including "Typecheck public API with Node-only types" before @types/bun exists in the consumer, then fresh Bun and plain Node (22.23.4) processes through write/read/foreign, extracted-adapter typechecks including the TUI, and the fault-injected 0.2.0 engine rejected by all three adapters. My independent probe above is the same claim from a different file. The runner's consumer tsconfig declares types: ["node"] — the guard #623 asked for, present.
  • Implementers: three production adapters + an out-of-package fourth. createOpenCodeMemoryHost, the Pi runtime host, the oh-my-pi extension host (each declaring its own apiVersion literal), the test simulator, and the fixed consumer fixture, which constructs its own minimal MemoryHost from the installed package rather than instantiating an in-tree adapter — so the contract test does not collapse into testing one implementation. The one genuinely external adopter (dsh, #621) has not adopted yet; #623's acceptance item about its README is external follow-through, and the PR's "preliminary experiment" framing says so out loud. That keeps the abstraction honest rather than a guess.
  • Backward compatibility is additive. Exports map gains ./host and ./status; ././tui/./pi/./oh-my-pi untouched; root index.ts and tui.ts not in the diff. StatusPayload.apiVersion is optional on disk; internal status readers unchanged. The real behavior change is intended and ordered: setupMemory rejects a mismatched apiVersion before touching any port (Proxy test proves ["apiVersion"] is the only property read), and a mismatched adapter creates no store (reject-version.ts asserts the store dir does not exist).
  • Tests exercise the contract. api-version.test.ts rejects nine bad version shapes before port access; public-services.test.ts imports through the public specifiers and enforces the reason allowlist; the version-policy AST guard rejects renamed/computed engine-version reads and pins the guide's version prose. The break I would invent — a consumer upgrading the engine under a pinned adapter — is already a shipped fresh-process test with zero port touches and no store creation.
  • Their suite at this head (my numbers, not the body's): bun run test → 2,182 pass / 23 skip / 0 fail. bun run typecheck exit 0. bun run lint exit 0. bun run lint:comments clean. CI at 428cb6a: nine checks, all success, per gh api …/commits/428cb6a/check-runs.
  • Coverage matrix. Uncovered by execution here, reasoned statically instead: Windows (CI green; the finding below is symlinked-tmp-specific and cannot occur there); npm-registry channel (file: tarball tested; same artifact class); real second external repo adoption (none exists yet — declared); cross-version upgrade replay (no pre-0.1.0 fixture — declared by the PR itself). Full native pi/oh-my-pi suites were run; see the finding for the one affected scenario each.

The one change requested

The new extracted-adapter installer cannot pass on a symlinked temp dir, which is every macOS machine. installExtractedAdapter ends with assert.equal(realpathSync(installed), installed) (integration/adapter/package.ts:81). macOS tmpdir() yields /var/folders/… under the /var → /private/var symlink, so that identity can never hold, and it takes the three new scenarios with it — measured, not inferred:

  • bun test e2e/load.test.ts → "Scenario: external OpenCode adapter loads without bundled adapter sources" fails at package.ts:81.
  • bun test ./integration/pi/ → "external adapter installs into a fresh pi home and shares memory after process restart" fails.
  • bun test ./integration/oh-my-pi/ → the analogous scenario fails.

Same three files with TMPDIR=/private/… (canonical path, nothing else changed): e2e/load 4/4, pi installation 2/2, oh-my-pi installation 2/2. Linux and Windows temp paths are already canonical, which is why the PR's own checks and CI never see it — but the maintainer develops on macOS, so these scenarios are broken on the platform the repo is written on. Fix at the boundary so all call sites are covered: canonicalize at installer entry, e.g. consumer = realpathSync(consumer) as the first statement of installExtractedAdapter (all three callers pass an existing directory), the same treatment scripts/test-adapter-package.ts already gives tmpdir() at its entry. Nothing else about the extraction machinery is implicated — the real-host loads themselves pass once the path is canonical.

Two small asks (not blocking on their own)

  1. docs/reference/adapters.md:5 says "The published 0.40.1 package does not contain these entry points." The substance is right, the version is stale: npm view opencode-self-improvement version → 0.41.1, which is also this branch's own manifest version. The version-policy guard pins prose to ADAPTER_API_VERSION but not to the registry, so this sentence drifted through CI. Make it 0.41.1 or word it version-free ("no npm release to date contains them").
  2. Type-closure gap: MemoryCaptureHost.captureDisabledReason is typed CaptureDisabledReason, but that union is not re-exported from /host — a consumer importing it by name gets TS2305 (measured). The structural literal "unverified_host_lifetime" still compiles, so adapters aren't stuck; add it to the src/host/index.ts export list for closure completeness (it is one of the two enumerations the human report keys off, so external adapters will want to name it).

Notes, not findings

  • The branch is currently 5 commits behind main (a8f8c39); head reviewed and signed: 428cb6ab7ee359fd43a1d20e639a7588c0187fa3. Updater business, not a review issue.
  • integration/pi/node-launcher.test.ts passes under PI_TEST_NODE (v22.23.4) here; nothing in this review uses the environment baseline to excuse anything.
  • The declared remainders — conformance suite stays repo-local, no separate adapter packages, no release-workflow claim, exact-match-only versioning — are stated as plainly as the capability docs do it. That framing is the PR's strength; keep it in whatever supersedes this.

WhollyMindless — the substance here is strong and independently reproduced end to end: the packed-consumer story, the ordered version rejection, the loose-copy self-reference, all hold up under measurements that did not reuse your fixture. The request list is short precisely because of that: one canonicalization at the installer boundary, plus the version citation and the one missing type export. Fix the realpath assert and this is approve on my side.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Note

🤖 gpt-6-astra responding on behalf of WhollyMindless

Addressed all three requests from the review at 428cb6a in c1bf161, after merging main through 3495b73:

  • Canonicalize consumer at installExtractedAdapter entry. The packed-package check now installs all three extracted adapters through a directory alias (junction on Windows, symlink elsewhere) and checks the returned canonical paths. On Windows, this reproduced the reported assertion failure before the fix and passed afterward.
  • Export CaptureDisabledReason from /host. A separate packed-consumer type probe imports it by name, assigns it to MemoryCaptureHost.captureDisabledReason, and checks that an unknown reason is rejected. It runs in the Node-only typecheck; the frozen api-0.1.0 fixture is unchanged.
  • Correct the published-package reference in docs/reference/adapters.md to 0.41.1.

Validation on Windows: test:adapter-package passed all 12 stages; the affected OpenCode/Pi/oh-my-pi installation files passed 8/8; the full test suite passed 2,178 with 35 skipped and zero failures. Typecheck, Biome lint, comment lint, and formatting of all 500 checked files in an LF export of the staged tree passed. The ordinary working-tree format check hit existing CRLF differences. A native macOS rerun remains for CI/re-review.

One factual correction to the external-adoption note: the dsh trial already adopted Node-only typings in 972e611, using the experimental engine pinned at b902179. It remains an experimental source-pinned trial.

Ready for re-review of these fixes; fresh CI is pending.

@abogartz

abogartz commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@WhollyMindless CI failed

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Note

🤖 gpt-6-astra responding on behalf of WhollyMindless

The Windows oh-my-pi job at c1bf161 finished with 39 passing scenarios and one failure: capture follows actual SDK boundaries: compact-override. It logged that shutdown-lifetime verification had failed and capture was disabled; the fixture subsequently hit its 45-second watchdog (exit 143). Both bundled and extracted-adapter installation scenarios passed.

On Windows at the same head, the failing scenario passed alone, then all nine scenarios in capture-boundaries.test.ts passed in sequence (27 assertions). The lifetime verifier and boundary fixtures are unchanged from the previous head. This suggests an intermittent verification failure, but does not yet establish its cause.

I attempted to rerun only the failed Windows job; GitHub rejected the request with “Must have admin rights to Repository.” @abogartz, could you rerun that job? The verification checks and timeouts remain unchanged.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Note

🤖 gpt-6-astra responding on behalf of WhollyMindless

Merged current main (c8ff1e2, package 0.41.3) into this branch without conflicts and pushed merge commit 60028ade0a6367e25dd08434d970ef80230fc11e.

Validation on that merge, on Windows with Bun 1.4.4, Node 24.15.0 and pinned OpenCode 2.0.26:

  • Unit suite: 2,226 passed, 35 skipped, 0 failed.
  • Packed external-adapter consumer: all 12 stages passed, including Node-only public types, fresh Bun/Node consumers, extracted adapters and incompatible-version rejection.
  • Pi integration: 42 passed; oh-my-pi integration: 40 passed, including installed adapters and shutdown/capture scenarios.
  • Typecheck, Biome lint and comment-policy checks passed. Formatting passed against an LF export of the committed files; the Windows working copy retains its existing CRLF conversions. git diff --check is clean.
  • OpenCode E2E: 62 passed, 1 failed. The failure is the documented Windows standalone-shutdown assertion in e2e/capture.test.ts: capture answered but no memory row persisted. It also fails in isolation on the previous head c1bf161, so this merge did not introduce it. The standalone probe observed no cleanup callback; both cooperative server-shutdown controls passed. The failing assertion remains enabled; this is not an all-green Windows E2E claim.

The branch now includes current main. Fresh CI and maintainer re-review are still pending.

@abogartz
abogartz merged commit 6802b96 into abogartz:main Dec 1, 2026
10 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.42.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public /host and /status cannot be typechecked by a consumer without Bun typings

2 participants