supermemory-local-server (decompiled reconstruction)

Readable, annotated reconstruction of supermemory-server 0.0.8 ("lite", linux-x64) — the self-hostable memory server released at github.com/supermemoryai/supermemory — produced by extracting the embedded JavaScript bundle from the official Bun-compiled release binary and refactoring it for readability only (renames + comments; logic untouched).

Read first: docs/RE-REPORT.md (method + findings + legal note) and docs/CONFIG-GUIDE.md (every env var, storage layout, LLM config incl. the zai-CLI → supermemory mapping).

Layout

supermemory-local-server/
├── bin/supermemory-server.mjs        launcher shim (forwards argv to dist/)
├── dist/supermemory-server.bundle.mjs  byte-exact extracted program (208 MB,
│                                       self-contained: PGlite+pgvector+ONNX+
│                                       embedding worker+Rivet engine inlined)
├── src/readable/
│   ├── supermemory-server.readable.mjs  annotated study copy (416 renamed
│   │                                    symbols, 64 section banners,
│   │                                    blobs → __VENDOR_BLOB_NN__ tokens)
│   ├── MODULES.md                    functional map: subsystem → line range
│   ├── NAMES.md                      mangled → readable symbol dictionary
│   └── rename-report.json            machine-readable rename evidence
├── vendor/                           the 13 decoded embedded payloads + README
├── docs/
│   ├── RE-REPORT.md                  reverse-engineering report
│   └── CONFIG-GUIDE.md               configuration & LLM provider guide
├── tools/                            extraction toolkit (reusable on new releases)
└── package.json                      scripts: start / doctor / migrate / version

Run it

Requires Bun ≥ 1.3.4.

bun run start                 # serves http://0.0.0.0:6767 (data dir ./.supermemory)
bun run start:config          # same, driven by config.json (llm base url / model /
                              #   api key / custom headers — see config.example.json)
SUPERMEMORY_DATA_DIR=~/.supermemory PORT=6767 bun run start
bun run doctor                # 7-point health check
bun run migrate               # apply embedded migrations and exit

On first boot the server extracts its runtime assets into the data dir, asks (interactively) for an LLM provider key or embedding setup, and prints a "supermemory ready" box with the auto-generated local API key (also written to <dataDir>/api-key). Localhost requests are auto-authenticated as a local owner; other hosts use Authorization: Bearer sm_….

Using the zai CLI endpoint as the LLM provider (tested)

The zai internal endpoint requires X-Z-AI-From / X-Token headers that the OpenAI protocol cannot carry, so run the bundled auth-injection proxy first — see docs/CONFIG-GUIDE.md §6.1 for the verified header matrix and API test results:

node tools/zai-auth-proxy.mjs 8787            # reads /etc/.z-ai-config or ~/.z-ai-config
OPENAI_API_KEY=Z.ai \
OPENAI_BASE_URL=http://127.0.0.1:8787/v1 \
OPENAI_MODEL=glm-4.6 \
WORKFLOW_ENGINE=direct \
bun run start

# end-to-end API battery (boot, ingest, search, LLM paths, teardown)
tools/tests/test-supermemory-zai.sh

The readable copy is not runnable by itself (its blob literals are placeholders) — that is what dist/ is for. Dist is the byte-exact program from the binary; the two correspond 1:1 except for identifier names.

Readability passes

  • v1 — top-level symbol recovery: 416 scope-aware renames, 64 section banners (NAMES.md documents every mapping).
  • v2 (tools/readable-rewrite-v2.mjs) — AST pass rooted at the entry point: 4,727 contextual local renames (catch → error, Hono handlers → c/next, collection callbacks → item, loops → i/entry/key, this.X = $ constructors → the field name) applied at 12,730+4,727 reference/declaration sites; 710 statically-unreachable top-level declarations flagged with // [v2] dead code markers; entry call-flow in src/readable/CODE-FLOW.md; banner index with current line numbers at the end of MODULES.md. Renames are text-spliced (formatting untouched) and verified semantically: tools/verify-renames.mjs proves the unresolved reference set is byte-identical before/after.

Reading the code

Start with src/readable/MODULES.md (subsystem → line ranges), then open src/readable/supermemory-server.readable.mjs and jump between the ═══ SECTION ═══ banners. Any symbol you don't recognize is either still mangled (look it up by context) or listed in NAMES.md with its original mangled name and usage count.

Highlights, in reading order:

  1. Entry point + boot sequence — banner ENTRY POINT (~line 212,954)
  2. API surface — banners V3 ROUTER, V4 ROUTER, HONO APP ASSEMBLY
  3. Auth — banners API-KEY AUTH MIDDLEWARE, LOCAL AUTH, scope enforcement
  4. Storage — banners encrypted PGlite store, EMBEDDED MIGRATIONS, VECTORDB SERVICE
  5. AI pipeline — banners CHUNKING, PROMPTS, INGESTION WORKFLOW STEPS, DREAMING JOBS, V4 SEARCH EXECUTOR
  6. Ops — banners DOCTOR, RIVET ENGINE SPAWNER, telemetry/heartbeat