@zakstam/codex-local-component
v1.6.1
Published
Integrate with one prompt: install this package, open `README.md` then follow mapped docs (`docs/CANONICAL_INTEGRATION.md`, `docs/API_REFERENCE.md`) and validate with `npx convex dev --once`, `pnpm run dev:convex:once`, `pnpm run typecheck`.
Downloads
2,672
Maintainers
Readme
Codex Local Convex Component
Convex component for Codex integrations where Codex runs locally while thread state, messages, approvals, and replay are persisted in Convex.
[!IMPORTANT]
@zakstam/codex-local-componentis in alpha and ready for active testing. It is still experimental and not ready for production use.
Canonical default: runtime-owned host integration.
Install
pnpm add @zakstam/codex-local-component convexReact hooks require react peer dependency (^18 or ^19).
Typecheck Default (TS7 Preview)
pnpm run typechecknow uses TypeScript 7 preview (tsgo) by default.pnpm run buildnow uses TypeScript 7 preview (tsgo) for emit.- Use
pnpm run typecheck:tscto run the legacy TypeScript compiler (tsc --noEmit) when needed.
Canonical Implementation
Use one source of truth for implementation steps:
./LLMS.md(LLM-only execution manifest)- This README (human onboarding and package integration checklist)
LLMS.md is intentionally LLM-targeted; humans should start with this file.
Quickstart Summary
- Mount component in
convex/convex.config.tswithapp.use(codexLocal). - Generate/sync
convex/chat.tshost shim (pnpm run sync:host-shim). - Define host endpoints with
defineCodexHostDefinitions(...)and explicitmutation/queryexports. - Start runtime in runtime-owned mode.
- Call
chat.validateHostWiringat startup. - Use
@zakstam/codex-local-component/reacthooks against canonical host endpoints. - Prefer safe-by-default thread read queries. Most thread reads return status payloads in place of strict throw-only variants, while
listPendingServerRequestsreturns an empty list ([]) when the thread is missing instead of throwing. - Run
pnpm --filter @zakstam/codex-local-component run doctor:integrationto fail fast on setup drift.
Package Import Paths
@zakstam/codex-local-component/react@zakstam/codex-local-component/host@zakstam/codex-local-component/host/convex@zakstam/codex-local-component/convex.config@zakstam/codex-local-component/_generated/component.js@zakstam/codex-local-component/test
Docs Map
- Human onboarding entrypoint:
./README.md(this file) - Agent execution manifest:
./LLMS.md - Canonical implementation guide:
docs/CANONICAL_INTEGRATION.md - API reference:
docs/API_REFERENCE.md - Example app runbook (setup/checks/env):
docs/EXAMPLE_APPS_RUNBOOK.md - Fallback governance policy:
docs/FALLBACK_POLICY.md
One-shot LLM handoff prompt for external users
Give this prompt to an LLM after installing the package to get setup and code changes started:
Integrate `@zakstam/codex-local-component` in this project using only this package's docs.
Use this file (`README.md`) first, then follow only the mapped docs for the task:
- Canonical integration: `docs/CANONICAL_INTEGRATION.md`
- API lookup: `docs/API_REFERENCE.md`
- Optional runbook/checks: `docs/EXAMPLE_APPS_RUNBOOK.md`
Keep changes minimal and stay in runtime-owned mode.
Validate with:
- `npx convex dev --once`
- `pnpm run dev:convex:once` (or app equivalent)
- `pnpm run check:host-shim`
- `pnpm run typecheck`
If a prerequisite is missing for an app, ask for package-specific assumptions before continuing.Human integration checklist
- Install package dependencies:
pnpm add @zakstam/codex-local-component convexMount the component in
convex/convex.config.ts.Generate Convex types before wiring:
npx convex dev --onceGenerate/sync
convex/chat.tsfrom host manifest (pnpm run sync:host-shim).Start runtime-owned host wiring through
@zakstam/codex-local-component/host.Call
chat.validateHostWiringduring startup.Prefer
resolveActorFromAuth(ctx, requestedActor?)for host actor binding from Convex auth identity.Run app checks:
pnpm run dev:convex:once
pnpm run check:host-shim
pnpm run lint
pnpm run typecheck- Run package doctor checks for canonical contract drift:
pnpm --filter @zakstam/codex-local-component run doctor:integrationIntegration Failure/Fix Matrix
Use these failure classes to unblock quickly:
E_DOCTOR_MISSING_FILE: required canonical docs are missing. Fix by restoring expected docs.E_DOCTOR_CANONICAL_MARKER: canonical marker drift in package docs. Fix by restoring canonical marker text.E_DOCTOR_LEGACY_ALIAS: legacy alias symbols leaked into public docs. Fix by replacing with canonicalthreadHandlenaming.E_DOCTOR_README_ROUTING: example README not routing to packageLLMS.md. Fix by restoring canonical routing section.
Data Lifecycle APIs
The component supports async cascade deletion with job polling:
threads.deleteCascadethreads.scheduleDeleteCascadeturns.deleteCascadeturns.scheduleDeleteCascadethreads.purgeActorDatathreads.schedulePurgeActorDatathreads.cancelScheduledDeletionthreads.forceRunScheduledDeletionthreads.getDeletionJobStatus
Runtime-owned host endpoints expose the same lifecycle operations as:
deleteThreadscheduleDeleteThreaddeleteTurnscheduleDeleteTurnpurgeActorDataschedulePurgeActorDatacancelDeletionforceRunDeletiongetDeletionStatus
Runtime Thread Control APIs
createCodexHostRuntime(...) exposes thread control helpers:
openThread(start|resume|fork)importLocalThreadToPersistenceresumeThreadforkThreadarchiveThreadsetThreadNameunarchiveThreadcompactThreadrollbackThreadreadThreadlistThreadslistLoadedThreads
importLocalThreadToPersistence is the canonical single-call API for importing a local runtime thread into Convex persistence and returning the persisted threadHandle for UI reads.
Runtime Bridge Lifecycle APIs
createCodexHostRuntime(...) exposes canonical lifecycle tracking as push + snapshot:
connect(args)subscribeLifecycle(listener)getLifecycleState()
The lifecycle state includes:
runningphase(idle|starting|running|stopping|stopped|error)source(runtime|bridge_event|protocol_error|process_exit)updatedAtMspersistedThreadId(Convex-owned thread identity)runtimeThreadId(Codex runtime thread identity)threadHandleturnId
Tauri bridge client send behavior:
- Default:
createTauriBridgeClient(...)keepsturns.send(...)fail-fast. - Canonical sequence:
lifecycle.start(...)(transport connect) ->lifecycle.openThread(...)(explicit thread intent) ->turns.send(...). - Opt-in:
createTauriBridgeClient(..., { lifecycleSafeSend: true })only auto-recovers transport startup from cachedlifecycle.start(...)config. It does not implicitly open/create threads. - Fail-closed error codes for opt-in send:
E_TAURI_SEND_START_CONFIG_MISSINGE_TAURI_SEND_AUTO_START_FAILEDE_TAURI_SEND_RETRY_EXHAUSTED
Runtime Sync Mapping APIs
Runtime-owned host definitions now expose explicit sync mapping mutations:
syncOpenThreadBindingmarkThreadSyncProgressforceRebindThreadSync
These endpoints are used to persist local-runtime-to-Convex thread mapping state (syncState, lastSyncedCursor, session watermark, and rebind metadata) during openThread and ingest progression.
Type Safety Checks
pnpm --filter @zakstam/codex-local-component run codegen:componentpnpm --filter @zakstam/codex-local-component run lintpnpm --filter @zakstam/codex-local-component run typecheckpnpm --filter @zakstam/codex-local-component run typecheck:tscpnpm --filter @zakstam/codex-local-component run schema:checkpnpm --filter @zakstam/codex-local-component run check:unsafe-typespnpm --filter @zakstam/codex-local-component run check:fallback-policypnpm --filter @zakstam/codex-local-component run check:component-function-validators
Protocol Schema Workflow (Maintainers)
The protocol artifacts under src/protocol/schemas/** are generated and committed.
Schema updates are manual and fail closed.
Expected source directory must contain:
codex_app_server_protocol.schemas.jsonindex.tsv2/index.ts
Sync from an upstream generated schema directory:
pnpm --filter @zakstam/codex-local-component run schema:sync -- --source /path/to/codex/generated/schemasOptional source metadata for auditability:
pnpm --filter @zakstam/codex-local-component run schema:sync -- --source /path/to/codex/generated/schemas --source-ref codex@<commit-or-tag>Drift and contract checks:
pnpm --filter @zakstam/codex-local-component run schema:check
pnpm --filter @zakstam/codex-local-component run schema:verifyschema:verify intentionally blocks merge until code/tests/docs are updated for any schema contract break.
Component Authoring Exports
@zakstam/codex-local-component/_generated/component.js: generatedComponentApitype entrypoint for app-side typing.@zakstam/codex-local-component/test: test helper export (register) plusschemafor component test registration.
