Skip to content

Latest commit

 

History

History
192 lines (149 loc) · 37.4 KB

CLAUDE.md

File metadata and controls

192 lines (149 loc) · 37.4 KB

MarketMirror (MiroFish engine) — operating guide for Claude

MarketMirror is a marketing and sales simulation and prediction tool. You give it a brief, ads, messages, prices, a launch plan or a pitch; it builds diverse simulated buyers (interview-grounded personas with communities), lets them scroll realistic feeds, post and argue on simulated social platforms, answers a buyer survey, rehearses a sales pitch, and writes a plain-language report with a go / iterate / no-go decision. The installable skill is plugin/skills/market-mirror/SKILL.md; the MCP server is plugin/skills/market-mirror/scripts/mcp_server.py.

Under the hood it is the MiroFish engine (knowledge graph -> LLM agents -> OASIS social simulation) running headless on Claude. Drive the Flask backend (port 5001) with backend/claude_cli/mirofish.py and show the user the self-contained HTML dashboard it exports.

0. Fastest path

backend/claude_cli/start_server.sh
python backend/claude_cli/mirofish.py quickstart            # asks 9 plain questions, also sets up .env / the API key
python backend/claude_cli/mirofish.py quickstart --answers @answers.json   # for agents (keys: brand, product, buyers, platforms, tests, budget, size, past_ads, docs)

quickstart writes scenarios/<brand>/ (brief, question, personas spec, two template captions per platform, messages, launch calendar, pitch and rebuttals, past-ads import) plus market_test.json, creates the simulated people and stops before any paid step. Edit the template files, then run the printed market-test command with "approve_spend": true.

1. Setup (once)

cp .env.example .env        # if .env does not exist yet

Set these in MiroFish/.env (it is loaded by backend/app/config.py):

LLM_PROVIDER=claude          # Anthropic OpenAI-compatible endpoint (default)
LLM_API_KEY=<Anthropic API key>   # or export ANTHROPIC_API_KEY
LLM_MODEL_NAME=claude-haiku-4-5   # cheap and fast; use a Sonnet model for better reports
MEMORY_BACKEND=local         # local SQLite graph + local embeddings, so no Zep key is needed

No API key? backend/gateway/local_gateway.py --backend claude|codex serves an OpenAI-compatible endpoint on :5055 over your Claude Code or ChatGPT login (LLM_PROVIDER=openai, LLM_BASE_URL=http://127.0.0.1:5055/v1, LLM_API_KEY=gateway); slower and rate-limited, personal use. Install the Python deps with cd backend && uv sync (this includes fastembed; the ~220 MB multilingual embedding model is downloaded on first use into backend/uploads/models). See section 6 for the memory backends. The CLI itself needs only the stdlib and requests. Offline export --run-dir needs only the stdlib.

2. Start / stop the backend

backend/claude_cli/start_server.sh     # background start, waits for /health, prints JSON
backend/claude_cli/stop_server.sh      # stops it, including simulation subprocesses

The log is written to backend/logs/server.out. The CLI reads MIROFISH_URL (default http://localhost:5001) or takes --base-url.

Long steps run as jobs in a durable SQLite queue (backend/app/jobs/, docs/JOBS.md): limits per provider (MM_JOB_LIMIT_PROVIDER, default 4) and per workspace (X-MM-Workspace, MM_JOB_LIMIT_WORKSPACE, default 2, no cap for the local workspace), cancellation and approval-gated retries via /api/jobs, recovery after a restart (a job that already made model calls is never retried without POST /api/jobs/<id>/retry {"approve_spend": true}). More throughput: MM_JOB_EXTERNAL_WORKERS=1 plus cd backend && uv run --no-sync python -m app.jobs.worker. OASIS starts beyond MM_OASIS_MAX_RUNS (default 2) return runner_status: "queued" and start when a run finishes. Load test with a fake LLM: backend/scripts/load_test_jobs.py.

3. Run a simulation end to end

C="python backend/claude_cli/mirofish.py"   # from the repo root; or: cd backend && uv run --no-sync python claude_cli/mirofish.py
$C health
$C run --seed brief.md data.pdf \
       --requirement "If X happens, how will the public react over the next 3 days?" \
       --platform parallel --max-rounds 5 --out mirofish_runs/x_test

run performs these steps: upload, ontology, graph build, create simulation, prepare (profiles and config), start (polls until the run is completed), report, collect, and export. Progress lines go to stderr, and the final JSON (ids and paths) goes to stdout. Every intermediate file is saved in --out: ontology.json, project.json, graph.json, simulation.json, config.json, profiles_*.json, run_status.json, timeline.json, actions.json, posts_*.json, comments_*.json, report.json, run_manifest.json, dashboard.html, report.md and summary.json. If a step fails, the CLI exports whatever exists, records run_manifest.json.error and exits 1.

--requirement @file.txt reads the question from a file. Use --stop-after prepare to check the agents before spending money on rounds.

Individual steps (all print JSON)

Step Command
upload + ontology $C upload --seed a.md --requirement "..." [--name N] gives project_id
graph build $C build-graph --project proj_x (waits), gives graph_id
simulation $C create-sim --project proj_x --platform parallel gives simulation_id
agents/config $C prepare --simulation sim_x [--entity-types Student Media]
run $C start --simulation sim_x --max-rounds 5 (waits; --no-wait + $C wait)
status $C status --simulation sim_x / --project proj_x / --task task_x
report $C report --simulation sim_x [--force] [--out report.md]
ask ReportAgent $C chat --simulation sim_x --message "Why did sentiment flip?" [--history chat.json]
interview agents $C profiles --simulation sim_x --brief, then $C interview --simulation sim_x --agent 3 --prompt "..." (or --agent 1 2 5, or --all)
MCP resources and prompts the MCP server also lists run files as resources (`marketmirror://runs//dashboard.html
MCP tasks and spend approval clients that negotiate tasks (2025-11-25 capabilities.tasks, or the 2026-07-28 Tasks extension io.modelcontextprotocol/tasks per request) get long tools (market_test, study, run_test, pitch, email_test, website_test, ad_patterns, quickstart, setup, cli) as tasks over the same job(); others keep job_status. A market_test without approve_spend asks the user through elicitation (server request on stdio/HTTP, or an InputRequiredResult on 2026-07-28) with the planned people and a rough cost (MARKET_MIRROR_USD_PER_CALL, default 0.005); run continues with approved spend, people_first keeps the guard, decline/cancel starts nothing. Clients without elicitation keep today's flow
MCP resources and prompts the MCP server also lists run files as resources (`marketmirror://runs//dashboard.html
housekeeping `$C list [projects

Interviews work only while the simulation environment is still alive (status shows env.env_alive). It stays alive after a run finishes until close-env, stop or a server restart.

3b. MarketMirror commands

Goal Command
personas: what the planner does balanced slots -> persona call (5 per call) -> stereotype guard -> life interview (12 questions) -> second call per 4 people: 2 adaptive probes + 3 product questions + the BDE card (background / decision procedure / evaluation) stored in persona_index[].bde; personas.json keys probes, population (raked weight), personas_lite (no interviews)
concrete personas + communities $C run ... --personas scenarios/x/personas.json (or --auto-personas 30), --stop-after prepare first
ads in realistic feeds `$C feedtest --simulation sim_x --creatives @scenarios/x/creatives.json [--exposures 2] [--seeds 3] [--landing @..] [--benchmarks @past_ads.json] [--vision describe
predicted brain response (opt-in research view) $C brain-response --run-dir mirofish_runs/x [--creatives @creatives.json] or market_test.json key brain_response: true (after the feed test), POST /api/simulation/brain-response, MCP brain_response: sends each ad's video, audio or caption to the owner's own Meta TRIBE v2 sidecar (backend/brain_sidecar/: `brain_sidecar.sh setup
pre-flight look at real ad images / videos $C creative-check --creatives @creatives.json [--out creative_check.json] -> what each shows, words on it, brand / CTA visibility, platform checks, measured aspect ratio (no simulation needed; a model reading, not an attention score); ad-patterns --vision labels real ads from their pictures
buyer survey / split test / price $C survey --simulation sim_x --offer ".." --goal ".." --messages @msgs.txt --split --pricing USD (needs a started simulation; free-text answers are mapped to 1-5 distributions by POST /api/simulation/ssr, --no-ssr to skip). Each person gets one of three wordings and one verdict order (seeded by agent id; the retest gets another); a second estimate per segment (POST /api/simulation/survey-estimate, two calls per segment, both orders averaged, --no-estimate to skip) sits next to SSR as "Two ways of asking" with a margin and a no-better-than-uniform flag; split-test arms also show a lift shrunk toward the average (prior 0.55); price arms state what is held fixed (held_fixed in the spec)
talk to the buyers after the run $C ask --simulation sim_x --person 12 "Would you pay $9?" [--history @chat.json] (one saved persona with its decision card and memories; no live environment needed) and $C focus-group --simulation sim_x --guide @guide.md [--people 6] [--segment ..] [--rounds 2] -> focus_group.json + dashboard section: private verdict, moderated discussion, private verdict again, the shift and a conformity flag, themes with transcript-checked quotes; MCP ask_buyers; market_test key focus_group {guide, people, segment}
trust pack (every run) segment gaps are shrunk toward the overall rate by 0.4 when no real data exists (segment_shrink in the survey analysis: simulated segment gaps run 2-4x larger than real ones, Chen, Zhu & Zheng 2026), with a "Close call" note on the Audiences card when the shrunk lead is under 3 points or a top segment has fewer than 10 people (survey.shrink.segment_factor overrides); run_manifest.json.provenance records models, engine commit (and local changes), a hash of the prompt code in app/services, seeds and spend approval (GET /api/simulation/provenance); the dashboard section How this was made and disclosure.md give the AI-use disclosure (who answered, real people compared, model, dates, memory, human review, how to repeat, known limits; AAPOR 2026, ESOMAR 20 questions)
pre-registered forecasts $C forecast lock --run-dir mirofish_runs/x [--due 2026-12-15] [--note ..] [--ledger L] writes forecast_lock.json (decision, overall rate, segment / message / creative order from summary.json and the feed test) hashed with SHA-256 and appended to the append-only ledger (default mirofish_runs/forecast_ledger.jsonl); once only per run. $C forecast score --run-dir .. --actual @real.json ({rate, segment_rates, message_rates, creative_rates, decision_held}) refuses a lock whose hash no longer matches, then records error in points, ratio, winner hit and Spearman per order; $C forecast table writes the ledger as Markdown with misses kept. Commit the ledger somewhere public for an outside timestamp. Offline, no model calls (claude_cli/forecast_ledger.py)
when not to use (fit check) after the people are prepared (persona preparation itself makes model calls) and before the guarded test steps, market-test checks the test against the known weak spots of simulated panels (claude_cli/fit_check.py): segments under 10 people, half or more of the people in less-covered markets, sensitive or identity topics in the brief, a product new to the world, and targets / forecasts / budgets in the config (people come from persona_index, the brief is read from the requirement file; unreadable people are reported as audience_unavailable, not as a pass). It runs again on every pass. Each warning says what to do instead; fit_check lands in run_manifest.json and the personas_ready reply; it never blocks a run. Answers to ESOMAR's 20 questions for buyers of AI services are in docs/ESOMAR-20.md
your own questionnaire `$C questionnaire --simulation sim_x --questions @questions.md
rank claims, trade-offs, demand at each price `$C choice-test --simulation sim_x --kind maxdiff
analyst panel $C panel --simulation sim_x --analysts 5 --brief ".."
test-retest reliability $C survey ... --retest 20 (or "retest": 20 in the market-test survey block): agreement a simulated week later
real-people check kit every exported run writes real_check.md and real_check.csv next to dashboard.html (download "Check with real people"): the 3-5 questions that decided the verdict, who to ask, how many (+-10 points, or the earlier calibration plan) and the calibrate --real real_check.csv command; claude_cli/real_check.py
calibrate against real answers $C calibrate --run-dir mirofish_runs/x --real answers.csv [--map y=Converted segment=Audience] [--field would_convert] [--by segment] [--halfwidth 0.05] [--budget N] -> calibration.json (overlap, per-audience trust/correct/walk-away, AIPW-corrected rate, and ppi: a PPI++ interval for the audience rate that stays valid however good the panel is, lambda, effective sample size ("the panel is worth N more real answers"), per-segment intervals, and how many more real answers a +-halfwidth interval needs with and without the panel; spread: whether the simulated answers and the gaps between audiences are as varied as the real ones, as simulated/real SD ratios with 90% bootstrap intervals and a verdict too alike / similar / too spread out / unclear (simulated panels tend to answer too alike; 'too alike' or 'too spread out' costs a point of evidence grade); ppi.allocation: where to collect the next --budget real answers (default: what the +-halfwidth target needs), greedy on the stratified PPI++ variance so more go where the panel predicts least, thin segments topped up to 10 first, next to a split by audience share; real_check.md uses it as quotas); dashboard section "Real-sample check"
split real answers between personas and the check `$C real-split --real answers.csv [--share auto
past ads to seed + benchmarks $C ads-import export.csv --out scenarios/x/past_ads.md
backtest vs real ads $C backtest --run-dir mirofish_runs/x --actuals scenarios/x/past_ads.json
understand the product first $C understand --project proj_x or --docs a.md b.md --url https://... (product_profile.json; market-test does it after upload; every later prompt reads it)
platform-native captions $C captions --brief @brief.md --platform instagram --n 6 [--run-dir X] (objections from the run are folded in; output usable as posts, creatives or messages)
brand posts + launch calendar inside the rounds $C run ... --posts @posts.json --events @events.json or market_test.json keys posts / events ([{round, agent, platform, content}]; PUT /api/simulation/<sid>/events)
sales rehearsal (pitch + rebuttals) $C pitch --simulation sim_x --script @pitch.md --rebuttals @rebuttals.md [--channel call] [--segment ..] (needs a live environment, like the survey)
your own customers as grounded personas `$C intake --files reviews.csv calls/*.txt [--segment-field plan] [--base personas.json] --out scenarios/x/personas.json [--engine llm
audience from your web analytics `$C analytics-audience --files ga4.csv posthog.json [--rows @rows.json] [--segment-by country
creative patterns in real ads (yours or competitors') `$C ad-patterns --ads library.json [--run-dir mirofish_runs/x] [--engine auto
next test ideas from real ads + the run $C ideas --ads export.csv --run-dir mirofish_runs/x --brand X (or --rows @rows.json with rows pulled from a connected ads tool)
email campaign test $C emailtest --simulation sim_x --emails @emails.json [--list-size N] (emails.json: {emails:[{id, from_name, subject, preheader, body, cta, send_time, segments, sequence:[{delay_days, subject, body}]}], list_size, benchmarks}; market-test key emails)
test anything from one spec $C test --simulation sim_x --spec @experiment.json [--brand X] ({type, name, variants, audience, metric, budget, rounds}; types ad, message, price, offer, positioning, naming, landing, launch, pitch, email, creator_post, channel_mix, maxdiff, conjoint, gabor_granger) -> experiment_result.json
what real people say $C research --query ".." --country in [--subreddit fitness] [--url ...] -> scenarios/<q>/research/{research.md, research.json, voices.json}; market-test key research (folder) attaches the voices to the project (PUT /api/graph/project/<pid>/voices) and copies research.json into the run
live context into the rounds $C context --simulation sim_x --text ".." [--round N] [--source ..] (PUT /api/simulation/<sid>/context; the runner re-reads simulation_config.json every round)
study: scenarios x seeds $C study --spec study.json ({name, base, simulation_id, scenarios:[{name, overrides}], seeds, steps}) -> mirofish_runs/<name>/{study_summary.json, study_report.md, study.html}; finished cells are reused
predictions + forecast $C predict --run-dir mirofish_runs/x --brand X [--target ctr=2 cpl=10] [--spend 500] -> predictions.json, forecast.json; backtest --brand X and calibrate feed the store backend/uploads/calibration_store.json
accuracy against open human data $C bench --suite upworthy --data packages.csv [--run-dir mirofish_runs/x] [--n 50] or `$C bench --suite twin2k --fetch [--n 20] [--blocks pricing
simulated feelings (emotion layer) --emotions observe (default) asks every feed, landing, email, survey and pitch answer for a short appraisal (feel); app/services/emotion.py maps it to one feeling, keeps a mood that fades back to each person's baseline over simulated hours (behavior_state.json v2, state.affect), and the dashboard shows How people felt. --emotions on also adds a mild mood line to prompts, lets walk-aways skip the rebuttal and applies emotion.COUPLING: small bounded multipliers on ad notice and wear-out, landing patience, the wallet threshold, the polite back-out, email opens and OASIS action budgets (no new random draws; each moved row carries emotion_effects; MM_EMOTION_WEIGHT=0.5,notice=0). OASIS rounds read emotions from simulation_config.json or MM_EMOTIONS on the server. Every test checks stated pleasantness against the person's own words (emotion.words_check, POST /api/simulation/affect-ssr, local embeddings), and focus groups compare private vs in-the-room feelings (focus_group.json.affect: masking / over-convergence flags). off leaves prompts unchanged. Env MM_EMOTIONS, config key emotions. Simulated, not validated
Jev as an outside labeller with a Jev key set (TYPESAFE_API_KEY, or JEV_VIA=openrouter + OPENROUTER_API_KEY), app/services/jev_labels.py labels after the run, never what a person says or hears: reply and post sentiment in feed_story.json (word list kept as the fallback; sentiment_method), research voices, landing-page drop reasons grouped into ranked causes (feed_test.json.drop_causes, per ad under landing.drop_causes), ad comments for the battlecard, and the pitch's objection tags checked against an independent label (pitch.json.objection_check). Labels are cached per text in jev_labels.json next to the run. MM_JEV_LABELS=auto|on|off (default auto). Tests never call the real Jev
market coverage the evidence grade (app/services/evidence.py) drops one step when half or more of the people are outside the markets plain persona prompts track best (US, GB/UK, CA, AU, NZ, IE; full country names, including United States of America, also work) and no real answers checked the run; market_coverage names the markets and the report and dashboard show the note
plain-language report $C report --simulation sim_x --run-dir mirofish_runs/x (default engine market; --engine upstream for the old narrative report)
real post view GET /api/simulation/<sid>/feed-story -> feed_story.json, rendered as the dashboard's Social feed. Each post carries votes_by_round; feed_story.json.herding checks whether reactions followed a post's visible score (likes and positive replies up, dislikes and negative replies down) more than the post's own mix explains: a permutation null shuffles each post's reactions across its rounds, reported after a net-negative and a net-positive score; negative pile-on (the LLM failure OASIS found replicating Muchnik et al.) is flagged on the dashboard and in the report. Observational: who is online when can also cluster reactions
randomized herding probe (measures pile-ons) $C run ... --herding-probe [SHARE] [--herding-probe-seed N], the same flags on start, market_test.json key herding_probe {share, seed} (absent = off) or simulation_config.json key herding_probe (POST /api/simulation/start takes herding_probe: true, a share, {share, seed}, or false). Off by default because it changes the run: scripts/herding_probe.py appends one neutral account that no model drives to the copy of the profiles the runner loads (never in the profile files, persona_index or agent_configs, so it is no persona, community, brand, interviewee or respondent, and any action other than its votes is dropped). After each round a seeded share (default 0.5) of that round's organic persona posts (no reposts, quotes, brand, scheduled or community posts; none from the last round) get one vote from it first thing in the next round that runs: up = like, down = dislike (Reddit only), the rest are controls; <sim>/herding_probe.json logs the arms, the database high-water marks and whether each vote landed; the probe's own votes stay out of actions.jsonl and every count. feed_story.json.herding.probe compares each arm with its platform's controls on other people's final net score and on their share of later negative reactions, 95% bootstrap intervals over posts (5+ posts per arm and control); down-voted posts ending lower with the interval below 0 is negative pile-on (flagged in the Social feed note, the insight line and the report)

market-test runs all of this from one config (keys: posts, events, creatives, rounds, herding_probe, survey, pitch {script, rebuttals, channel}, panel, report, analytics). Results land in the run folder (feed_test.json, survey.json, pitch.json, analyst_panel.json, backtest.json, feed_story.json, market_report.json/.md, ideas.json/.md) and in the dashboard, which also writes CSV/JSON/Markdown downloads next to dashboard.html. API: backend/app/api/market.py. Persona spec, creatives and benchmark formats are documented in README.md and the skill. Report simulated numbers as directions with their margins, never as measurements: the feed-test range across --seeds and the survey's SSR mean ± spread.

4. Export and show the dashboard

$C export --simulation sim_x --out mirofish_runs/x/dashboard.html   # fetches everything from the API
$C export --run-dir mirofish_runs/x                                  # offline re-render from saved JSON

The output is one HTML file with inline CSS, inline SVG/ECharts and no external requests. Order: Decision -> Report (plain language; the download buttons sit in its header: this page, print/PDF, report MD, action plan JSON, survey answers CSV, feed sessions CSV, lead scores CSV, pitch JSON, test ideas, all numbers JSON) -> Results -> Playbook -> Sales rehearsal -> Ad patterns -> Test ideas -> Feed test -> Social feed (every post by platform, round, segment and country, with likes, quotes and comments; brand posts strip with reply sentiment) -> Funnel -> Audiences -> Objections -> Messages -> Pricing -> Voices -> Analysts -> Backtest, then the people cards (interview summary, phone, groups, lead score), activity, the market map (knowledge graph) and run details. It adapts to light and dark mode and to phone width. Publish dashboard.html with the Artifact tool, or send it as a file, so the user can view it. report.md and summary.json (key numbers) are written next to it. Use summary.json for your own written summary.

Live view (watch a run while it happens)

$C live                                   # follows the newest run under mirofish_runs/
$C live --run-dir mirofish_runs/x         # or a specific run; --simulation sim_x also works

live serves the same dashboard at http://127.0.0.1:5050/ (--port or MIROFISH_LIVE_PORT to change it). Every --interval seconds (default 10) it re-collects the run from the backend and re-renders the page; the open page reloads itself only when something changed, keeps its scroll position, and shows the current stage in a corner badge (graph build, preparing agents, round N/M, report, done). In the Claude desktop app, open it in the browser pane with preview_start and the .claude/launch.json entry market-mirror-live. --offline re-renders saved JSON without calling the backend.

Scenario inputs

Keep private inputs (seed documents, questions, campaign data) in scenarios/<name>/, which is gitignored. The repo itself stays a generic base.

5. Cost tips

  • Hard cap: "max_spend_usd": 5 in market_test.json (or the MCP market_test config) stops new model calls once the estimated spend reaches it; calls in flight finish, so it can overshoot slightly; one capped run per server, spend-cap --clear lifts a cap left by a killed run (app/utils/spend_cap.py, list prices, MM_USD_PER_MTOK to override; GET|POST|DELETE /api/simulation/spend-cap; spend_cap.json in the run folder). MM_MAX_SPEND_USD caps each server process.
  • Start small: --max-rounds 3-5, one platform (--platform reddit), and a short seed document.
  • Agent count equals the number of graph entities. Use --entity-types (on run or prepare) to limit which types become agents.
  • claude-haiku-4-5 is fine for exploration. Switch LLM_MODEL_NAME only for the final run.
  • Reports are cached per simulation, so report reuses the existing one unless you pass --force.
  • --no-graph-memory skips writing agent activity back into the graph. With MEMORY_BACKEND=local or cognee that write is cheap anyway, because activity is stored and searchable without LLM extraction unless MEMORY_EXTRACT_ACTIVITY=true.
  • The local backend makes one Claude call per unique chunk. Re-building a graph from the same document with the same ontology and model reuses the cached extractions for free.

6. Memory backends (knowledge graph)

All three backends expose the same zep_cloud-shaped client (get_zep_client() in backend/app/utils/zep.py), so graph building, entity reading, ReportAgent tools and simulation memory work the same on each.

  • local (default): backend/app/utils/local_graph.py, a SQLite file at backend/uploads/local_graph.db. The configured LLM (Claude) extracts entities and relationships per chunk with a compact prompt, 4 workers in parallel. Identical chunks reuse a cached extraction, and chunks are capped at LOCAL_GRAPH_MAX_EPISODE_CHARS. Search is hybrid: BM25 fused with cosine similarity over local fastembed embeddings (reciprocal rank fusion). The default model is paraphrase-multilingual-MiniLM-L12-v2 (multilingual, 384 dims, CPU only), and vectors are cached in the same SQLite file. Entity resolution merges exact names, declared aliases, safe variants (Acme Inc. = Acme, WHO = World Health Organization, an unambiguous Alice = Alice Smith) and same-type names with embedding cosine >= MEMORY_ENTITY_SIMILARITY (0.9). If fastembed or the model is unavailable, search falls back to BM25 with no error. Set MEMORY_EMBEDDINGS=false to skip embeddings entirely.
  • cognee (optional): backend/app/utils/cognee_graph.py plus a sidecar. Cognee cannot share backend/.venv: every Cognee release needs tiktoken>=0.8 and openai>=2, while camel-ai==0.2.78 (required by camel-oasis) pins tiktoken<0.8 and openai<2. So Cognee runs in backend/memory_sidecar/.venv (about 1.3 GB) behind a small localhost JSON API:
    backend/memory_sidecar/cognee_sidecar.sh setup    # once
    backend/memory_sidecar/cognee_sidecar.sh start    # before start_server.sh; also: status | stop
    # .env: MEMORY_BACKEND=cognee
    Cognee uses the same Claude key and model (its anthropic provider), fastembed embeddings and local stores (SQLite, LanceDB, Ladybug/Kuzu) under backend/uploads/cognee. The ontology is passed as Cognee's custom_prompt. After each cognify run, the Cognee graph is read back and mirrored as EntityNode/EntityEdge rows. Search fuses Cognee's vector hits with the local hybrid ranking, and falls back to the local ranking if the sidecar is down.
  • zep (legacy): hosted Zep Cloud, requires ZEP_API_KEY.
Option License / cost Runs where Fit for MiroFish Decision
local hybrid (this repo) AGPL (repo), free in-process SQLite + ONNX Typed ontology, episodes/batches and the Zep shapes the services expect; one Claude call per unique chunk Default
Cognee Apache-2.0, free sidecar venv, local stores Mature extraction/cognify pipeline and vector retrieval; dependency conflict with camel-ai Optional (cognee)
Zep Cloud hosted, paid tiers SaaS Original upstream backend Legacy (zep)
Graphiti (Zep OSS) Apache-2.0 needs a graph DB (Neo4j/FalkorDB/Kuzu) + embedding provider Strong temporal graph, but several LLM calls per episode and extra infrastructure Not used
Mem0 Apache-2.0 vector store (+ optional graph) Built for user/agent conversational memory, not ontology-typed document graphs Not used
LightRAG MIT file/DB storage + embedding function Good graph-RAG question answering, but no episode/batch model or typed ontology contract Not used

Choice: the local backend keeps the "no extra service, no extra key" path and the exact Zep data model, so it is the default. Cognee is the drop-in upgrade for richer extraction when you can run a second process. Every backend uses Claude for extraction, and embeddings are always local and free (Anthropic has no embeddings API).

6b. Accounts and the workspace database

Chats, projects, pins, the run index, preferences and onboarding live in backend/app/db/ (SQLite by default, Postgres with MM_DATABASE_URL; numbered SQL migrations in app/db/migrations/, run on start or with python -m app.db.cli migrate). Local mode (default) keeps the loopback + setup-token check. MM_ACCOUNTS=on adds sign-in (argon2id), workspaces, owner/editor/viewer roles and invitation links; app/auth.py resolves the caller and scopes saved runs to the workspace's run index. Design note, roles and security: docs/ACCOUNTS.md.

7. Code map / rules

  • backend/app/api/{graph,simulation,report}.py contains the REST endpoints, and backend/app/services/ the logic (graph builder, OASIS runner, ReportAgent). Runtime data is under backend/uploads/ (projects, simulations, reports).
  • Memory: backend/app/utils/{local_graph,embeddings,cognee_graph,zep}.py and backend/memory_sidecar/ (Cognee sidecar). Backend tests: cd backend && uv run --no-sync python -m pytest tests claude_cli/tests -q.
  • backend/claude_cli/ holds the CLI (mirofish.py), the dashboard exporter (exporter.py, stdlib only), the server scripts and the tests (python -m unittest discover -s backend/claude_cli/tests).
  • Never commit .env or anything under backend/uploads/ or mirofish_runs/.