Skip to content

[plan-stable] Stable working build across supported IDEs and platforms #3137

Description

@thedotmack

Defect

Current main has many targeted fixes in flight, but the product can still install cleanly while core claude-mem behavior fails at runtime: packaged workers can miss runtime modules, hooks can block or emit host-invalid JSON, worker startup can split across cache/marketplace roots, stale Windows sockets can hold the configured port, Chroma/search can be unavailable after install, provider env sanitization can remove required auth/proxy variables, and settings/storage/project identity can corrupt or mis-key state.

This plan is for branch plan/stable-working-build. The goal is not a new architecture. It is a stable, working build from current main plus only low-risk patches/backports needed for the intended claude-mem feature set to work across supported IDEs/platforms.

Snapshot and Baseline

  • Snapshot: /tmp/claude-mem-three-track/backlog-full.json, captured 2026-07-05T04:56:22Z.
  • Backlog size: 116 open issues, 134 open PRs.
  • Baseline inspected locally: package claude-mem@13.10.1, HEAD e02494852, worktree branch freckle-nail.
  • Target branch: plan/stable-working-build.
  • Stable principle: prefer small backports, generated-artifact fixes, and contract tests over holistic rewrites.

Backlog Evidence

Release-quality signal

Distribution and runtime packaging

Symptoms:

Patch evidence:

Stable reading:

  • Current scripts/build-hooks.js builds the worker and checks generated hook outputs, but the inspected main build path does not emit the plugin/sqlite runtime modules required by the bundled worker.
  • This is a release-blocking stable fix because clean installs should not depend on source-tree-only modules.

Worker singleton, root resolution, and port lifecycle

Symptoms:

Patch evidence:

Stable reading:

  • src/build/hook-shell-template.ts is the canonical generated shell resolver for hooks/MCP, but src/shared/worker-utils.ts has its own worker script resolution path. The stable branch should make resolution deterministic without introducing a new service manager.
  • Windows port cleanup should not wait for a long cooldown when the port owner is stale, dead, or the previous version.

Hook and platform contracts

Symptoms:

Patch evidence:

Stable reading:

  • src/cli/adapters/index.ts declares supported adapters: claude-code, codex, cursor, windsurf, antigravity, antigravity-cli, and raw.
  • OpenCode support in current main is plugin/capture-oriented rather than a full CLI adapter; stable work should keep that supported path working without inventing a new adapter.
  • Generated hook files must be regenerated from src/build/hook-shell-template.ts and verified by scripts/build-hooks.js; do not hand-edit generated command strings.

Chroma, semantic search, MCP, and smart explore

Symptoms:

Patch evidence:

Stable reading:

  • Current src/services/sync/ChromaMcpManager.ts already uses direct uvx --from chroma-mcp==0.2.6 chroma-mcp and StdioClientTransport; preserve that patch shape.
  • Do not replace Chroma or MCP transport as part of the stable build.

Observer, provider env, and prompt safety

Symptoms:

Patch evidence:

Stable reading:

  • Current src/services/worker/agents/ResponseProcessor.ts already treats benign non-XML/no-op output as valid; verify and avoid reworking it.
  • Current src/supervisor/env-sanitizer.ts still appears to strip proxy variables and omits CLAUDE_CODE_SKIP_BEDROCK_AUTH / CLAUDE_CODE_SKIP_VERTEX_AUTH; this is a low-risk stable backport because it preserves caller-provided env rather than adding new behavior.

Settings, storage, migration, and project identity

Symptoms:

Patch evidence:

Stable reading:

  • SettingsDefaultsManager strips BOM in one reader but uses direct writes for defaults/migrations; stable should use the existing atomic JSON writer pattern where applicable.
  • src/utils/project-name.ts and src/utils/worktree.ts should get minimal identity fixes, not a new project model.

Explicitly Out Of Scope

Documentation Discovery / Allowed APIs

Use only documented/local contracts below unless a failing test proves a narrower patch is required.

  • Worker HTTP base and env contract: docs/public/platform-integration.mdx:13, docs/public/platform-integration.mdx:23, docs/public/platform-integration.mdx:48.
  • Worker session/event/search/context APIs: docs/public/platform-integration.mdx:148, docs/public/platform-integration.mdx:354, docs/public/platform-integration.mdx:475.
  • Health and SSE APIs: docs/public/platform-integration.mdx:532.
  • Hook lifecycle and Claude Code hookSpecificOutput.additionalContext: docs/public/hooks-architecture.mdx:30, docs/public/hooks-architecture.mdx:117, docs/public/hooks-architecture.mdx:264.
  • Hook timing and fail-open design: docs/public/hooks-architecture.mdx:422, docs/public/hooks-architecture.mdx:521.
  • Cursor hook names, config, inputs, and outputs: docs/context/cursor-hooks-reference.md:16, docs/context/cursor-hooks-reference.md:239, docs/context/cursor-hooks-reference.md:328, docs/context/cursor-hooks-reference.md:356, docs/context/cursor-hooks-reference.md:425, docs/context/cursor-hooks-reference.md:494.
  • OpenClaw lifecycle and context/SSE integration: docs/public/openclaw-integration.mdx:21, docs/public/openclaw-integration.mdx:40, docs/public/openclaw-integration.mdx:64.
  • Adapter contracts: src/cli/types.ts:1, src/cli/adapters/index.ts:9, src/cli/adapters/claude-code.ts:8, src/cli/adapters/codex.ts:5, src/cli/adapters/cursor.ts:18, src/cli/adapters/windsurf.ts:4, src/cli/adapters/antigravity-cli.ts:4.
  • Canonical generated hook command resolver: src/build/hook-shell-template.ts:1, src/build/hook-shell-template.ts:61, src/build/hook-shell-template.ts:111, src/build/hook-shell-template.ts:163, src/build/hook-shell-template.ts:217.
  • Build/generation verification: scripts/build-hooks.js:57, scripts/build-hooks.js:138, scripts/build-hooks.js:287, scripts/build-hooks.js:606.
  • Worker lifecycle/root APIs: src/shared/worker-utils.ts:126, src/shared/worker-utils.ts:207, src/services/worker-spawner.ts:69, src/services/infrastructure/HealthMonitor.ts:8.
  • Runtime selector/server client API boundary: src/services/hooks/runtime-selector.ts:39, src/services/hooks/server-client.ts:57.
  • Chroma MCP API boundary: src/services/sync/ChromaMcpManager.ts:31, src/services/sync/ChromaMcpManager.ts:127, src/services/sync/ChromaMcpManager.ts:167, src/services/sync/ChromaMcpManager.ts:265, src/services/sync/ChromaMcpManager.ts:395.
  • Settings/storage/project APIs: src/shared/SettingsDefaultsManager.ts:197, src/utils/json-utils.ts:5, src/utils/project-name.ts:21, src/utils/worktree.ts:20.

Allowed API changes:

  • Add missing generated/package outputs needed by the existing worker.
  • Add env-preservation keys and tests to the existing sanitizer.
  • Add narrow project-key/worktree/submodule cases to existing utilities.
  • Add deterministic worker script override/root resolution using existing env/config hooks.
  • Add health/port stale-owner diagnostics and cleanup within existing worker-spawner/HealthMonitor.
  • Add generated hook command variants required by documented host shells.

Disallowed API changes:

  • Do not change documented worker HTTP endpoints.
  • Do not change adapter NormalizedHookInput, HookResult, or platform output schemas unless the host contract currently rejects the output.
  • Do not add server-only MCP tools to worker runtime.
  • Do not make hooks depend on network, Chroma, or observer success before returning control to the host.

Phased Fix Sequence

Phase 0 - Reproduce and pin stable gates

  1. Create branch plan/stable-working-build from current main.
  2. Capture a failing baseline for the smallest representative cases:
  3. Add or update regression tests first when a small test can capture the stable contract.

Exit criteria:

  • Every later patch maps to a failing test, a clean-install package assertion, or a documented host contract.

Phase 1 - Fix package completeness before runtime behavior

Apply the minimal patch shape from #3108 first. Ensure package/build outputs include the plugin/sqlite runtime modules required by the worker and that generated package contents are verified in CI.

Then apply only the necessary runtime dependency packaging from #2887, #2710, #2531, #3095, #3113, #3006, and #3061.

Verification:

Do not proceed to hook/lifecycle fixes until a clean package can load the worker.

Phase 2 - Make hook IO host-valid and fail-open

Patch generated hook command/output contracts with the smallest host-specific changes:

Patch sources:

Verification:

  • scripts/build-hooks.js generated-file verification passes.
  • Codex hook JSON validates against allowed event keys from scripts/build-hooks.js.
  • Unit tests cover adapter output for Claude Code, Codex, Cursor, Windsurf, and Antigravity.
  • Windows command tests prove hooks do not require POSIX shell under Codex App/PowerShell.
  • Hook watchdog tests prove no observer/worker timeout blocks normal prompt submission.

Phase 3 - Unify worker root, singleton, health, and stale-port recovery

Patch existing worker resolution/lifecycle code rather than adding a new process manager:

Verification:

  • Worker launch from marketplace and cache paths produces one healthy daemon, not two.
  • Concurrent SessionStart hooks race to one worker.
  • Windows stale-socket fixture recovers without waiting for an arbitrary cooldown.
  • Worker restart/version-recycle tests prove child processes do not keep the listening socket alive after shutdown.
  • Existing worker-spawner, process-registry, supervisor, and health-monitor tests pass.

Phase 4 - Restore Chroma, search, MCP, and smart-explore under the stable package

After packaging and worker lifecycle are stable, verify current Chroma patches and backport only missing deltas:

Verification:

  • MCP tool schema/list tests prove worker runtime does not expose server-only tools.
  • Chroma MCP manager tests cover singleton, uvx args, Windows shell avoidance, SSL/env, prewarm cleanup.
  • Semantic search smoke:
    • record observation
    • summarize/store
    • search same project
    • search after worker restart
  • smart-explore smoke runs from a clean package with no global tree-sitter install.

Phase 5 - Harden observer/provider env without transcript side effects

Patch only stable correctness defects:

Verification:

  • Env sanitizer tests show proxy vars, Bedrock skip-auth, and Vertex skip-auth survive; unrelated CLAUDE_CODE_* control vars remain stripped.
  • Observer tests prove no synthetic assistant/user messages are persisted.
  • Response processor tests include empty/no-op/prose, malformed XML, and valid memory XML.
  • Provider tests include large image/base64 transcript inputs and bounded history.
  • Security/tool-enforcement tests include Skill, Workflow, SlashCommand, and ExitPlanMode.

Phase 6 - Make settings, storage, migrations, and project identity safe

Patch narrowly:

Verification:

  • Settings tests simulate interrupted write/read and prove existing valid settings are not reset to defaults.
  • JSON utility tests cover BOM with objects/arrays.
  • Migration tests run from historical fixture DBs through current schema.
  • SQLite tests cover busy timeout configuration without changing retention policy.
  • Project-name/worktree tests distinguish:
    • main repo
    • git worktree
    • nested monorepo package
    • git submodule

Phase 7 - Cross-platform smoke and release gate

Run final matrix before marking the stable branch ready:

  • Clean install from package/tarball, not repo source.
  • First launch, second launch, worker restart, and package-version recycle.
  • SessionStart context injection, UserPromptSubmit observation, PostToolUse observation, Stop summarization.
  • MCP search and Chroma semantic retrieval.
  • smart-explore invocation.
  • Settings read/write and old-DB migration.
  • Provider env passthrough for proxy, Bedrock, and Vertex.

Exit criteria:

  • All stable issues named in this plan either have a direct closing patch or are explicitly marked "covered by stable verification" in the PR description.
  • No feature-roadmap issue/PR from the out-of-scope list is merged as part of the branch.

Verification Matrix

Area macOS arm64 Linux x64 Windows 10/11 PowerShell Windows Git Bash / Claude Desktop WSL2
Clean package install tarball install, no source tree tarball install, no source tree npm/bun path with spaces Claude Desktop extension path install from Linux filesystem
Worker lifecycle first launch, restart, duplicate root marketplace/cache root convergence stale port, version recycle, hidden windows no POSIX dependency where host shell is PowerShell host/port env consistency
Claude Code SessionStart, UserPromptSubmit, PostToolUse, Stop same hook output JSON and fail-open desktop extension hook path same
Codex CLI/App SessionStart context, PostToolUse same PowerShell-safe command, no suppressOutput Git Bash fallback if present same
Cursor Agent/Tab beforeSubmitPrompt, afterFileEdit same path escaping and transcript handling n/a same
Windsurf prompt/write/command/MCP/cascade events same path escaping n/a same
Antigravity CLI env/cwd/session mapping same env/cwd/session mapping n/a same
OpenCode capture supported capture/plugin path only supported capture/plugin path only supported capture/plugin path only n/a same
OpenClaw documented event endpoints/SSE documented event endpoints/SSE documented event endpoints/SSE n/a same
Chroma/search uvx direct, restart search uvx direct, restart search uvx without cmd shell, cleanup same same
smart-explore packaged tree-sitter runtime packaged tree-sitter runtime packaged tree-sitter runtime same same
Settings/storage atomic write, BOM, migration atomic write, BOM, migration atomic write, BOM, migration same same

Minimum command/test gate:

  • npm run build
  • generated hook verification from scripts/build-hooks.js
  • package/tarball content check
  • clean-room install smoke
  • adapter/hook contract tests
  • worker-spawner/health/process-registry tests
  • Chroma/MCP/smart-explore tests
  • env-sanitizer/provider/observer tests
  • settings/json/storage/project identity tests

Anti-pattern Guards

  • No second-system rewrite: do not introduce a new daemon architecture, queue system, storage engine, RPC protocol, or provider abstraction to fix these issues.
  • No hand-edited generated hooks: update templates/build inputs, then regenerate and verify.
  • No shell: true plus args for subprocess fixes unless a platform contract requires it and a test proves the exact behavior.
  • No cmd.exe workaround for uvx/Chroma if direct executable resolution works.
  • No hook may block the host because memory/search/observer/Chroma is unavailable.
  • No source-tree-only fixes: package/tarball verification must prove clean installs work.
  • No server-only MCP tools in worker runtime.
  • No settings reset on parse/write errors; preserve user data and fail with a recoverable diagnostic.
  • No deletion of user memory to address DB bloat; limit stable scope to busy timeout and safe migration unless a narrow retention patch is separately verified.
  • No broad platform additions or provider integrations in this branch.
  • No behavior changes that require users to reconfigure existing Claude Code, Codex, Cursor, Windsurf, Antigravity, OpenCode, or OpenClaw setups.

PR Handling

Done

The branch is ready when:

  • Clean package installs exercise the full intended claude-mem path without source-tree dependencies.
  • Supported IDE/platform hooks return host-valid output and fail open on optional memory failures.
  • One worker owns the configured host/port and stale owner recovery is deterministic.
  • Chroma, MCP search, semantic search, and smart-explore work after clean install and worker restart.
  • Observer/provider paths preserve required env, bound prompt payloads, and do not mutate transcripts with synthetic messages.
  • Settings/storage/migration/project identity tests pass without data loss.
  • The verification matrix above is complete or each skipped cell has an explicit, documented reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions