@cerefox/memory 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,275 @@
1
+ # Upgrading Cerefox
2
+
3
+ This guide covers upgrading an existing Cerefox installation to the latest version. All steps are idempotent and safe to re-run.
4
+
5
+ ## Standard Upgrade Checklist
6
+
7
+ Run these steps every time you pull a new version:
8
+
9
+ ```bash
10
+ # 1. Pull the latest code
11
+ git pull origin main
12
+
13
+ # 2. Install/update Python dependencies
14
+ uv sync
15
+
16
+ # 3. Apply database migrations (skips already-applied ones)
17
+ uv run python scripts/db_migrate.py
18
+
19
+ # 4. Redeploy RPC functions (safe to re-run)
20
+ uv run python scripts/db_deploy.py
21
+
22
+ # 5. Build the web UI
23
+ cd frontend && npm install && npm run build && cd ..
24
+
25
+ # 6. Deploy Edge Functions (if using Supabase-hosted)
26
+ # Run from the project root (where supabase/ directory is)
27
+ npx supabase functions deploy cerefox-search
28
+ npx supabase functions deploy cerefox-ingest
29
+ npx supabase functions deploy cerefox-metadata
30
+ npx supabase functions deploy cerefox-get-document
31
+ npx supabase functions deploy cerefox-list-versions
32
+ npx supabase functions deploy cerefox-get-audit-log
33
+ npx supabase functions deploy cerefox-metadata-search
34
+ npx supabase functions deploy cerefox-mcp
35
+
36
+ # 7. Restart the application
37
+ uv run uvicorn cerefox.api.app:create_app --factory --reload
38
+
39
+ # 8. (Optional) Sync project docs to Cerefox knowledge base
40
+ uv run python scripts/sync_docs.py
41
+ ```
42
+
43
+ Steps 3-4 require `CEREFOX_DATABASE_URL` in your `.env` file (direct Postgres connection). Steps 6 require the Supabase CLI and a linked project.
44
+
45
+ ## Verifying the Upgrade
46
+
47
+ After upgrading, verify the key components:
48
+
49
+ ```bash
50
+ # Check migration status
51
+ uv run python scripts/db_migrate.py --status
52
+
53
+ # Run unit tests (optional but recommended)
54
+ uv run pytest -q
55
+
56
+ # Visit the web UI
57
+ open http://localhost:8000/app/
58
+ ```
59
+
60
+ ## Version-Specific Notes
61
+
62
+ Most upgrades require no special steps beyond the standard checklist above. Notes below only apply when upgrading across specific version boundaries.
63
+
64
+ ### Upgrading to v0.1.20 (from v0.1.19) -- Multi-Project Preservation Fix
65
+
66
+ **Edge Function redeploy is required.** v0.1.20 fixes
67
+ [issue #38](https://github.com/fstamatelopoulos/cerefox/issues/38): `cerefox_ingest`
68
+ no longer destructively replaces multi-project memberships when an agent updates
69
+ content with a single `project_name`. It also adds a new `project_names: string[]`
70
+ parameter for explicit full-set semantics and a new MCP tool
71
+ `cerefox_set_document_projects` for first-class agent control over project
72
+ membership independent of content updates.
73
+
74
+ The fix touches two Edge Functions in `supabase/functions/`. Pulling the new
75
+ code does **not** apply the TS changes to your live Supabase. After `git pull`,
76
+ step 6 of the standard checklist (Edge Function redeploy) is **mandatory for
77
+ this release**:
78
+
79
+ ```bash
80
+ npx supabase functions deploy cerefox-ingest
81
+ npx supabase functions deploy cerefox-mcp
82
+ ```
83
+
84
+ **If you skip this step**: the Python pipeline fix still applies on next local
85
+ MCP server restart, so the destructive bug is fixed for the local Python MCP
86
+ path. But the **remote MCP** (Claude.ai, ChatGPT Custom GPT via OpenAPI, any
87
+ HTTP MCP client pointed at `cerefox-mcp` Edge Function) and the **direct
88
+ `cerefox-ingest` Edge Function** path will still silently ignore `project_name`
89
+ on update — non-destructive, but agents can't add a membership via that path.
90
+ And the new `cerefox_set_document_projects` MCP tool won't appear in the remote
91
+ MCP tool list until `cerefox-mcp` is redeployed.
92
+
93
+ **No schema migration, no RPC redeploy, no chunk reindex** needed. The fix is
94
+ purely application-layer; the underlying junction table (`cerefox_document_projects`)
95
+ and its many-to-many semantics were always correct. Only the write surface had bugs.
96
+
97
+ **New behaviour to be aware of (no breaking changes)**:
98
+ - `cerefox_ingest` with `project_name="X"` on update → ensures membership in X,
99
+ preserves all others (was: destructive replace in local MCP / silent ignore in TS).
100
+ - `cerefox_ingest` with `project_names=["X","Y","Z"]` (new) on update → sets
101
+ full project set to exactly {X, Y, Z}; opt-in to destructive replace.
102
+ - `cerefox_ingest` with neither → no membership changes.
103
+ - `cerefox_set_document_projects(document_id, project_names=["X","Y"])` (new tool)
104
+ → explicit metadata-only write of the full project set. Logged as
105
+ `update-metadata` in the audit log.
106
+
107
+ Architectural rationale: see the cerefox#38 PR commit message and
108
+ [`docs/solution-design.md`](../solution-design.md).
109
+
110
+ ### Upgrading to v0.1.19 (from v0.1.18) -- FTS Query Parser
111
+
112
+ **RPC redeploy is required.** v0.1.19 changes the FTS query parser used by
113
+ `cerefox_hybrid_search` and `cerefox_fts_search` from `websearch_to_tsquery`
114
+ to `plainto_tsquery`. The change lives in `src/cerefox/db/rpcs.sql` — pulling
115
+ the new code does **not** apply it. After `git pull`, step 4 of the standard
116
+ checklist (redeploy RPCs) is mandatory, not optional:
117
+
118
+ ```bash
119
+ uv run python scripts/db_deploy.py
120
+ ```
121
+
122
+ `db_deploy.py` is idempotent (`CREATE OR REPLACE FUNCTION`) and safe to
123
+ re-run. **If you skip this step, searches for any title containing `-`
124
+ (e.g. "Job Hunting - Opportunity Index", `setup-supabase`) will continue
125
+ to return zero results until the RPCs are redeployed.** This is the
126
+ single most common upgrade mistake for v0.1.19.
127
+
128
+ **No schema migration**, **no Edge Function redeploy**, **no chunk reindex**
129
+ needed for this change — the corpus side (`to_tsvector` in chunk `fts`
130
+ column) is unchanged; only the query parser changed. The link-resolver web
131
+ UI feature (the other half of v0.1.19) requires step 5 of the standard
132
+ checklist (rebuild the frontend); no backend changes are needed for that
133
+ half.
134
+
135
+ **Behaviour change to be aware of**: the new parser treats every query
136
+ token as a literal word and ANDs them together. It does **not** interpret
137
+ phrase quotes (`"…"`), `OR`, or `-` as operators. If you or any scripts
138
+ relied on Google-style search operators in `cerefox_search` queries, those
139
+ queries now treat the operator characters as literal tokens. The architectural
140
+ rationale lives in [`docs/solution-design.md` §5.2](../solution-design.md#52-title-boosting-search-quality).
141
+
142
+ ### Upgrading to v0.1.14+ (from v0.1.13) -- Title Boosting
143
+
144
+ **One new migration**: `0011_title_boosting.sql`
145
+
146
+ - Drops the `GENERATED ALWAYS AS` expression on `cerefox_chunks.fts` (it can't cross-reference `cerefox_documents.title`)
147
+ - Adds `cerefox_update_chunk_fts(p_document_id, p_new_title)` RPC for title-change FTS refresh
148
+
149
+ Both are applied automatically by `db_migrate.py` (step 3). After the migration, also run `db_deploy.py` (step 4) to update the RPC definitions.
150
+
151
+ **Redeploy Edge Functions**: `cerefox-ingest` and `cerefox-mcp` now prepend the document title to chunk embedding inputs. Redeploy both:
152
+
153
+ ```bash
154
+ npx supabase functions deploy cerefox-ingest
155
+ npx supabase functions deploy cerefox-mcp
156
+ ```
157
+
158
+ **Optional reindex** (recommended for better search quality):
159
+
160
+ Existing chunks were embedded without the document title prefix and their FTS vectors don't include the document title at weight A. New documents ingested after this upgrade are automatically correct.
161
+
162
+ To upgrade existing chunks:
163
+
164
+ ```bash
165
+ # Preview what would be reindexed (no changes made)
166
+ uv run python scripts/reindex_all.py --dry-run
167
+
168
+ # Reindex all chunks (re-embeds with title prefix, updates FTS)
169
+ # Uses 50 chunks per API call by default; lower --batch if you hit rate limits
170
+ uv run python scripts/reindex_all.py
171
+
172
+ # Or run directly via the CLI (same effect)
173
+ uv run cerefox reindex --all
174
+ ```
175
+
176
+ The reindex is **resumable**: if interrupted, re-running it skips chunks already embedded with the current model. Archived chunks (historical versions) are not reindexed -- they are not searched.
177
+
178
+ Cost estimate: ~$0.01-0.05 for a typical personal knowledge base (a few thousand chunks at `text-embedding-3-small` rates).
179
+
180
+ ### Upgrading to v0.1.11+ (from v0.1.10)
181
+
182
+ **Two new migrations**:
183
+ - `0006_usage_log.sql` -- adds `cerefox_config` and `cerefox_usage_log` tables with 5 new RPCs
184
+ - `0007_usage_log_requestor.sql` -- renames `reader` column to `requestor` in `cerefox_usage_log`
185
+ and updates all 3 usage RPCs. Non-destructive (existing data preserved).
186
+
187
+ Both are applied automatically by `db_migrate.py` (step 3 above). After migrations, also
188
+ redeploy RPCs via `db_deploy.py` (step 4) to update the canonical function definitions.
189
+
190
+ **New REST API endpoints**: `/api/v1/usage-log`, `/api/v1/usage-log/export.csv`,
191
+ `/api/v1/usage-log/summary`, `/api/v1/config/{key}`.
192
+
193
+ **Analytics page**: new page at `/app/analytics` with 7 interactive visualizations
194
+ (Nivo charts), date/project/path filters, usage tracking toggle, and CSV export.
195
+
196
+ **Usage tracking is opt-in**: disabled by default. Enable via CLI:
197
+ ```bash
198
+ cerefox config-set usage_tracking_enabled true
199
+ ```
200
+ Or via the toggle on the Analytics page. When enabled, **all operations** (both reads
201
+ and writes) are logged with operation type, access path, requestor identity, query text,
202
+ and result count.
203
+
204
+ **Requestor attribution**: each usage log entry records who made the call:
205
+ - MCP tools: `"mcp-agent"` for reads, the `author` parameter value for writes (ingest)
206
+ - Web UI: `"user"`
207
+ - CLI: `"user"`
208
+ - Primitive Edge Functions: not attributed (access_path identifies the caller type)
209
+
210
+ **Edge Functions updated**: all primitive Edge Functions and `cerefox-mcp` now include
211
+ fire-and-forget usage logging calls for both reads and writes. Redeploy all Edge
212
+ Functions (step 6 above).
213
+
214
+ ### Upgrading to v0.1.10+ (from any earlier version)
215
+
216
+ **New Edge Function**: `cerefox-metadata-search` must be deployed (included in step 6 above).
217
+
218
+ **Breaking change -- MCP tool `project_id` input removed**: The `cerefox_search`,
219
+ `cerefox_ingest`, and `cerefox_metadata_search` tools in `cerefox-mcp` now accept
220
+ `project_name` (human-readable string) instead of `project_id` (UUID). If you have
221
+ any AI agents that pass `project_id` in their MCP tool calls, update them to pass
222
+ `project_name` with the project's display name instead.
223
+
224
+ This change **only affects the MCP path** (`cerefox-mcp` Edge Function and local MCP
225
+ server). The primitive Edge Functions (`cerefox-search`, `cerefox-ingest`, etc.) still
226
+ accept `project_id UUID` and are unchanged.
227
+
228
+ **New data in search results**: All search and retrieval results now include a
229
+ `project_names` field (array of strings) alongside the existing `project_ids` field.
230
+ Existing callers that ignore unknown fields are unaffected.
231
+
232
+ **New MCP tools**: `cerefox_list_projects` (no parameters; returns all projects with
233
+ names and IDs) and `cerefox_metadata_search` are now available on all MCP paths.
234
+ MCP clients pick up new tools automatically on the next connection.
235
+
236
+ ### Upgrading to v0.1.7+ (from any earlier version)
237
+
238
+ **Web UI replaced**: The Jinja2 + HTMX frontend was replaced with a React SPA. The web UI is now at `/app/` instead of `/`. The old root URL (`/`) shows a redirect page.
239
+
240
+ **New frontend build step**: Step 5 (`npm install && npm run build`) is required starting from v0.1.7. Earlier versions had no frontend build step.
241
+
242
+ **New dependency**: Node.js 18+ is required for building the frontend.
243
+
244
+ ### Upgrading to v0.1.4+ (from v0.1.0-v0.1.3)
245
+
246
+ **Versioning schema**: Migration `0003_add_document_versions.sql` adds the `cerefox_document_versions` table and `version_id` column on `cerefox_chunks`. This is applied automatically by `db_migrate.py`.
247
+
248
+ ### Upgrading to v0.1.1+ (from v0.1.0)
249
+
250
+ **Cloud-only embeddings**: Local embedders (mpnet, Ollama) were removed. If you were using a local embedder, switch to OpenAI or Fireworks AI and run `uv run cerefox reindex` to re-embed all chunks.
251
+
252
+ ## AI Agent Integration After Upgrade
253
+
254
+ After deploying new Edge Functions (step 6), AI agent integrations may need reconfiguration.
255
+
256
+ ### MCP clients (Claude Code, Cursor, Claude Desktop)
257
+
258
+ If you are using the **remote MCP server** (Streamable HTTP via `cerefox-mcp` Edge Function), MCP clients will pick up new tools and updated tool signatures in **new sessions** started after the deploy. No reconfiguration needed -- just start a new conversation.
259
+
260
+ **Important**: MCP tool schemas are cached for the lifetime of a session. An existing session that already loaded the old tool definitions will not see changes even if you "restart" the AI client within the same session context. The schema is fetched once at session initialization and held in memory. Starting a completely new session (new conversation/window) is the only way to pick up schema changes.
261
+
262
+ This matters when you add a new parameter to an existing tool (e.g., adding `project_name` to `cerefox_search`): agents in open sessions will not know the parameter exists until they start a fresh session.
263
+
264
+ If you are still using the **local MCP server** (`cerefox mcp` via stdio), consider switching to the remote MCP server. The remote path is now the recommended default -- it supports all tools, runs server-side embedding, and works across machines. See `docs/guides/connect-agents.md` for setup instructions.
265
+
266
+ ### ChatGPT Custom GPT (GPT Actions)
267
+
268
+ If you use GPT Actions pointing at the Cerefox Edge Functions, **check the OpenAPI schema version** in `docs/guides/connect-agents.md` after every upgrade. If the version has changed (e.g., from 1.4.0 to 1.5.0), you need to update the schema in the ChatGPT Custom GPT editor:
269
+
270
+ 1. Open the Custom GPT editor and go to **Actions**
271
+ 2. Replace the OpenAPI schema with the latest version from `docs/guides/connect-agents.md`
272
+ 3. Save the schema
273
+ 4. **Re-enter the API key**: go to **Authentication** settings and re-enter your Supabase **legacy anon JWT** (Project Settings → API Keys → Legacy → anon) as the Bearer token. The new `sb_publishable_…` key does not work for GPT Actions — see [`setup-supabase.md` → Supabase API keys (2026)](setup-supabase.md#supabase-api-keys-2026).
274
+
275
+ **Known issue**: the ChatGPT editor clears the Bearer token (legacy anon JWT) every time the OpenAPI schema is saved. This happens even if you only change whitespace. There is no workaround -- you must re-enter the key after every schema save.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerefox/memory",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "Cerefox — user-owned shared memory for AI agents. The local TypeScript runtime: stdio MCP server in v0.4; CLI binary added in v0.5; in-process web server in v0.6; ingestion pipeline in v0.7.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/fstamatelopoulos/cerefox",
@@ -27,10 +27,13 @@
27
27
  "bun": ">=1.0.0"
28
28
  },
29
29
  "bin": {
30
- "cerefox-mcp": "dist/bin/cerefox-mcp.js"
30
+ "cerefox": "dist/bin/cerefox.js"
31
31
  },
32
32
  "files": [
33
33
  "dist",
34
+ "docs",
35
+ "AGENT_GUIDE.md",
36
+ "AGENT_QUICK_REFERENCE.md",
34
37
  "README.md",
35
38
  "LICENSE",
36
39
  "CHANGELOG.md"
@@ -38,18 +41,25 @@
38
41
  "dependencies": {
39
42
  "@modelcontextprotocol/sdk": "^1.0.0",
40
43
  "@supabase/supabase-js": "^2.45.0",
44
+ "cli-progress": "^3.12.0",
45
+ "commander": "^12.1.0",
46
+ "picocolors": "^1.0.0",
47
+ "prompts": "^2.4.2",
41
48
  "zod": "^3.23.0"
42
49
  },
43
50
  "devDependencies": {
44
51
  "@types/bun": "^1.3.14",
52
+ "@types/cli-progress": "^3.11.5",
45
53
  "@types/node": "^20.0.0",
54
+ "@types/prompts": "^2.4.9",
46
55
  "typescript": "^6.0.3"
47
56
  },
48
57
  "scripts": {
49
- "build": "bun build src/bin/cerefox-mcp.ts --outdir dist/bin --target node --format esm",
50
- "clean": "rm -rf dist",
51
- "prepublishOnly": "bun run clean && bun run build",
52
- "smoke": "node dist/bin/cerefox-mcp.js --help"
58
+ "build": "bun build src/bin/cerefox.ts --outdir dist/bin --target node --format esm",
59
+ "clean": "rm -rf dist docs AGENT_GUIDE.md AGENT_QUICK_REFERENCE.md",
60
+ "bundle-docs": "bun run ../../scripts/bundle_package_docs.ts",
61
+ "prepublishOnly": "bun run clean && bun run bundle-docs && bun run build",
62
+ "smoke": "node dist/bin/cerefox.js --help && node dist/bin/cerefox.js mcp --help"
53
63
  },
54
64
  "publishConfig": {
55
65
  "access": "public",