@kolivri/memoreal-mcp 1.0.2 → 1.1.0

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.
@@ -1,132 +0,0 @@
1
- # 001 — PRD: Rebrand `memoria-mcp` to `Memoreal` (`@kolivri/memoreal-mcp`)
2
-
3
- Today: 2026-11-21
4
- **Status**: Approved Architecture & Workstream Manifest
5
- **Repository**: `memoria-mcp`
6
- **Worktree**: `/Users/stasarshanski/Projects/Kolivri/memoria-mcp/.worktrees/feat-rebrand-memoreal`
7
- **Branch**: `feat/rebrand-memoreal`
8
-
9
- ---
10
-
11
- ## Pre-Design Checkpoint
12
-
13
- 1. **Package & schema fields verified**: `package.json:1-37` defines `name`, `version`, `mcpName`, `bin`, `repository`, `homepage`; `.actor/actor.json` defines `actorSpecification: 1`, `name`, `title`, `environmentVariables`; `.cursor-plugin/plugin.json` defines `name`, `displayName`, `homepage`, `repository`.
14
- 2. **States & protocol enums verified**: `src/apify-main.mjs#VALID_ACTIONS` (`recall`, `context`, `encode`, `search_code`, `health`, `standby_mcp`) and `src/schemas.mjs#MCP_TOOLS` (14 tools with `annotations` and `outputSchema`) remain 100% preserved for Glama TDQS `4.7/5.0` Grade A parity.
15
- 3. **Functions verified**: `src/server.mjs#createMemoriaMcpService` (`lines 25-260`) and `src/apify-main.mjs#executeMemoriaActorAction` (`lines 157-240`) verified in full; exporting `createMemorealMcpService` + `executeMemorealActorAction` alongside backward-compatible named aliases preserves all callers.
16
- 4. **Concrete `file#symbol` references**: Every module and test file (`test/memoria-mcp.test.mjs`, `test/apify-actor.test.mjs`) verified by reading full contents.
17
- 5. **Lifecycle traced end-to-end**: Stdio & Apify callers pass `MEMOREAL_API_KEY` (or legacy `MEMORIA_API_KEY`) -> `server.mjs` resolves endpoint -> forwards JSON-RPC 2.0 to `/v1/mcp`.
18
- 6. **Callers checked**: Checked `test/memoria-mcp.test.mjs`, `test/apify-actor.test.mjs`, `hooks/hooks.json`, and `install.sh`.
19
-
20
- ---
21
-
22
- ### Problem Solver Decision Record
23
-
24
- - **Broken Assumption & Escape Altitude $L^*$**: Rebranding an active MCP connector must update both isolated `"Memoria"` display strings and compound identifiers (`createMemorealMcpService`, `memoreal-session-start`, `memorealApiKey`, `memoreal-ns`, `memoreal-workflow`, `/memoreal-*`) without breaking existing `MEMORIA_*` env vars (`L11` Wire Protocol).
25
- - **Concept-Tree Occam Prune**: Pruned splitting into two separate git repositories; dual `"bin": { "memoreal-mcp": "src/server.mjs", "memoria-mcp": "src/server.mjs" }` and dual env/prompt resolution handle both canonical and legacy callers in one zero-dependency codebase.
26
- - **Unified Concept Set (Speed & Reliability)**: Disjoint 2-worker Wave 0 (`WS-0` code/actor/tests + `WS-1` manifests/hooks/skills/docs) with dual `MEMOREAL_* ?? MEMORIA_*` resolution.
27
- - **Rejected Epicycle & Solution Occam Delta**: Zero external dependencies added (`dependencies: undefined`).
28
- - **Chosen Mechanism**: Rung 1/3 static schema & dual-alias exports.
29
- - **Codebase Consolidation**: Reuses `src/server.mjs`, `src/schemas.mjs`, and `src/apify-main.mjs` in-place.
30
- - **Verification Proof Contract**:
31
- - Repro Command: `npm test`
32
- - Invariant Assertion: `serverInfo.name === '@kolivri/memoreal-mcp'`, all 14 tools retain `annotations` + `outputSchema`, both `MEMOREAL_API_KEY` and `MEMORIA_API_KEY` authenticate, both `memoreal-session-start` and `memoria-session-start` prompts resolve, and Apify `.actor/actor.json` validates as `memoreal-mcp`.
33
- - Regression Suite: `npm test` (`19+` passing, `0` failures).
34
-
35
- ---
36
-
37
- ## Questions & Answers
38
-
39
- - **Q1: What default endpoint URL should `src/server.mjs` use when neither `MEMOREAL_API_URL` nor `MEMORIA_API_URL` is set?**
40
- - **A1**: Default runtime `apiUrl` to `'https://memoria.kolivri.com'` (which is live with valid TLS today and serves `/v1/mcp` `200 OK` permanently per Design Log `014` even after `memoreal.kolivri.com` DNS is added), while honoring `process.env.MEMOREAL_API_URL || process.env.MEMORIA_API_URL`.
41
-
42
- ---
43
-
44
- ## Workstream Manifest
45
- ```json
46
- {
47
- "prdId": "001-rebrand-memoreal-mcp",
48
- "worktreePath": "/Users/stasarshanski/Projects/Kolivri/memoria-mcp/.worktrees/feat-rebrand-memoreal",
49
- "openQuestions": 0,
50
- "integrationVerifyCmd": "npm test",
51
- "workstreams": [
52
- {
53
- "id": "WS-0",
54
- "wave": 0,
55
- "layer": "providers_parallel",
56
- "title": "Rebrand MCP Server, Schemas, Apify Actor, Package & Unit/Integration Tests",
57
- "description": "Update package.json (@kolivri/memoreal-mcp, mcpName io.github.kolivritech/memoreal-mcp, dual bin memoreal-mcp & memoria-mcp), src/server.mjs (createMemorealMcpService + createMemoriaMcpService alias, MEMOREAL_* || MEMORIA_* env vars, serverInfo.name '@kolivri/memoreal-mcp', dual memoreal-*/memoria-* prompt handlers), src/schemas.mjs (Memoreal Cloud instructions, tool titles/descriptions, /memoreal-sync-code, MEMOREAL_*, memoreal-* prompts), src/apify-main.mjs (executeMemorealActorAction + executeMemoriaActorAction alias, MEMOREAL_* || MEMORIA_*), .actor/actor.json (name 'memoreal-mcp'), .actor/input_schema.json, test/memoria-mcp.test.mjs, and test/apify-actor.test.mjs.",
58
- "ownedFiles": [
59
- "package.json",
60
- "src/server.mjs",
61
- "src/schemas.mjs",
62
- "src/apify-main.mjs",
63
- ".actor/actor.json",
64
- ".actor/input_schema.json",
65
- "test/memoria-mcp.test.mjs",
66
- "test/apify-actor.test.mjs"
67
- ],
68
- "readOnlyContext": [
69
- "prd/001-rebrand-memoreal-mcp.md"
70
- ],
71
- "verifyCmd": "npm test"
72
- },
73
- {
74
- "id": "WS-1",
75
- "wave": 0,
76
- "layer": "providers_parallel",
77
- "title": "Rebrand README, CLAUDE.md, Manifests, Cursor Plugin, Hooks, Rules, Agents & Skills",
78
- "description": "Rebrand README.md, CLAUDE.md (<!-- memoreal:start -->), server.json (io.github.kolivritech/memoreal-mcp), smithery.yaml (memorealApiKey), manifest.json, mcp.json, .mcp.json, .cursor-plugin/plugin.json (name 'memoreal'), install.sh (~/.memoreal with ~/.memoria symlink & dual MEMOREAL_*/MEMORIA_*), hooks/hooks.json (~/.memoreal/bin/memoreal-ns falling back to ~/.memoria/bin/memoria-ns), and create/update bin/memoreal-ns, bin/memoria-ns, rules/memoreal.mdc, rules/memoria.mdc, agents/memoreal.md, agents/memoria.md, opencode/memoreal-hooks.js, opencode/memoria-hooks.js, skills/memoreal-{doctor,sync,sync-code,wrap-up}/SKILL.md, and skills/memoria-{doctor,sync,sync-code,wrap-up}/SKILL.md.",
79
- "ownedFiles": [
80
- "README.md",
81
- "CLAUDE.md",
82
- "server.json",
83
- "smithery.yaml",
84
- "manifest.json",
85
- "mcp.json",
86
- ".mcp.json",
87
- ".cursor-plugin/plugin.json",
88
- "install.sh",
89
- "hooks/hooks.json",
90
- "bin/memoreal-ns",
91
- "bin/memoria-ns",
92
- "rules/memoreal.mdc",
93
- "rules/memoria.mdc",
94
- "agents/memoreal.md",
95
- "agents/memoria.md",
96
- "opencode/memoreal-hooks.js",
97
- "opencode/memoria-hooks.js",
98
- "skills/memoreal-doctor/SKILL.md",
99
- "skills/memoreal-sync/SKILL.md",
100
- "skills/memoreal-sync-code/SKILL.md",
101
- "skills/memoreal-wrap-up/SKILL.md",
102
- "skills/memoria-doctor/SKILL.md",
103
- "skills/memoria-sync/SKILL.md",
104
- "skills/memoria-sync-code/SKILL.md",
105
- "skills/memoria-wrap-up/SKILL.md"
106
- ],
107
- "readOnlyContext": [
108
- "prd/001-rebrand-memoreal-mcp.md"
109
- ],
110
- "verifyCmd": "node -e \"const fs=require('fs');['server.json','manifest.json','mcp.json','.mcp.json','.cursor-plugin/plugin.json','hooks/hooks.json'].forEach(f=>JSON.parse(fs.readFileSync(f,'utf8')));console.log('JSON_OK');\""
111
- }
112
- ]
113
- }
114
- ```
115
-
116
- ---
117
-
118
- ## Verification Criteria
119
-
120
- 1. `npm test` passes 100% of stdio MCP and Apify Actor tests (`19+` passing, `0` failures).
121
- 2. All JSON manifests (`package.json`, `server.json`, `manifest.json`, `mcp.json`, `.mcp.json`, `.cursor-plugin/plugin.json`, `.actor/actor.json`, `.actor/input_schema.json`, `hooks/hooks.json`) parse cleanly and reflect `Memoreal` / `memoreal`.
122
- 3. Both `MEMOREAL_*` and legacy `MEMORIA_*` environment variables and prompt names (`memoreal-*` and `memoria-*`) execute without error.
123
-
124
- ---
125
-
126
- ## Implementation Results
127
-
128
- - **Wave 0 (`WS-0` & `WS-1` in parallel)**:
129
- - `WS-0`: Rebranded `package.json` (`@kolivri/memoreal-mcp`, `mcpName: io.github.kolivritech/memoreal-mcp`, dual `bin` `memoreal-mcp` & `memoria-mcp`), `src/server.mjs` (`createMemorealMcpService` + `createMemoriaMcpService` alias, dual `MEMOREAL_*/MEMORIA_*` env vars, dual `memoreal-*/memoria-*` prompts), `src/schemas.mjs`, `src/apify-main.mjs` (`executeMemorealActorAction` + alias), `.actor/actor.json` (`memoreal-mcp`), `.actor/input_schema.json`, and expanded test suites (`24/24` passing).
130
- - `WS-1`: Rebranded `README.md`, `CLAUDE.md` (`<!-- memoreal:start -->`), `server.json`, `smithery.yaml` (`memorealApiKey`), `manifest.json`, `mcp.json`, `.mcp.json`, `.cursor-plugin/plugin.json` (`memoreal`), `install.sh`, `hooks/hooks.json`, and added `bin/memoreal-ns`, `rules/memoreal.mdc`, `agents/memoreal.md`, `opencode/memoreal-hooks.js`, and `skills/memoreal-{doctor,sync,sync-code,wrap-up}/SKILL.md` with backward-compatible legacy delegates (`JSON_OK`).
131
- - **Full Integration Verification (`npm test`)**: **`24 / 24` tests passing** (`0` failures). Zero deviations from the approved design.
132
-
@@ -1,259 +0,0 @@
1
- # 002 — PRD: Memoreal Chrome OAuth Device-Pairing & IDE Setup Wizard (`@kolivri/memoreal-mcp`)
2
-
3
- Today: 2026-11-26
4
- **Status**: Approved Architecture & Workstream Manifest
5
- **Repository**: `memoria-mcp` (`@kolivri/memoreal-mcp`)
6
- **Worktree**: `/Users/stasarshanski/Projects/Kolivri/memoria-mcp/.worktrees/feat-connect-wizard`
7
- **Branch**: `feat/connect-wizard`
8
-
9
- ---
10
-
11
- ## Pre-Design Checkpoint
12
-
13
- 1. **Fields & config schemas verified**:
14
- - `src/schemas.mjs#MCP_TOOLS` (`lines 41-456`) defines 14 frozen tool descriptors, each carrying `name`, `title`, `description`, `annotations` (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`), `inputSchema`, and `outputSchema`.
15
- - `install.sh` (`lines 81-83`) defines the canonical 6-key `config.env` format (`MEMOREAL_URL`, `MEMOREAL_API_URL`, `MEMOREAL_API_KEY`, `MEMORIA_URL`, `MEMORIA_API_URL`, `MEMORIA_API_KEY`) and IDE JSON shapes (`lines 223-305`: `.mcp.memoreal` in `~/.config/opencode/opencode.json`; `.mcpServers.memoreal` in `~/.cursor/mcp.json`, `~/.codeium/windsurf/mcp_config.json`, `~/.vscode/mcp.json`, Claude Desktop `claude_desktop_config.json`, and existing `~/.claude.json`).
16
- - `package.json` (`lines 7-10`) maps both `memoreal-mcp` and `memoria-mcp` binaries to `src/server.mjs`.
17
- 2. **States & enum constraints verified**:
18
- - `connect_account` input `action` enum is `['start', 'status']` (`required: []`).
19
- - `connect_account` output `status` enum is `['already_connected', 'waiting_for_browser', 'connected', 'not_started', 'denied', 'expired']`.
20
- - Device poll statuses from `POST /v1/auth/device/poll` (`pending` / `authorization_pending`, `approved`, `denied` / `access_denied`, `expired` / `expired_token`) transition deterministically.
21
- - Glama TDQS invariants in `test/memoria-mcp.test.mjs` (`lines 146-153`) require every tool in `MCP_TOOLS` to publish boolean `annotations.readOnlyHint`, `outputSchema.type === 'object'`, and a `description` matching `/Use (when|at|to|after|before)/i`.
22
- 3. **Referenced functions verified**:
23
- - `src/server.mjs#createMemorealMcpService` (`lines 25-419`), `requireApiKey` (`lines 52-60`), `forwardCloudRpc` (`lines 62-103`), `callTool` (`lines 105-145`), `startMcpStdioServer` (`lines 423-471`), and `isDirectExecution` (`lines 473-485`) verified by reading full source.
24
- - `src/apify-main.mjs#normalizeInput` (`lines 17-48`) and `executeMemorealActorAction` (`lines 157-244`) verified to confirm how `apiKey: ''` in `test/apify-actor.test.mjs` (`lines 166-199`) interacts with `createMemorealMcpService`.
25
- - `opencode/memoreal-hooks.js#resolveCloudConfig` (`lines 45-90`), `fetchSessionStartContext` (`lines 92-135`), `MemorealHooksPlugin` (`lines 236-339`), and `setup` (`lines 350-463`), plus `opencode/memoria-hooks.js` (`lines 1-26`) and `hooks/hooks.json` (`lines 1-119`), verified in full.
26
- 4. **Concrete `file#symbol` references**: Every architectural claim above cites exact file paths and symbol/line ranges with zero unverified assumptions.
27
- 5. **End-to-end lifecycle traced**:
28
- - **Unconfigured start**: `SessionStart` hook (`hooks/hooks.json` / `opencode/memoreal-hooks.js`) or `src/server.mjs#requireApiKey` detects missing or placeholder key (`mem_dev_your_key_here`, `mem_dev_...`, `YOUR_API_KEY`, `<MEMOREAL_API_KEY>`) and instructs the AI assistant to drive the 3-Click Interactive In-Chat Wizard via `AskUserQuestion` / `question` while keeping `Read`/`Edit`/`Write` hooks silent.
29
- - **Device pairing**: Calling `connect_account({ action: 'start' })` posts to `${apiUrl}/v1/auth/device/start`, opens Chrome non-blockingly (`open` / `xdg-open` / `cmd /c start ""`), starts an `.unref()`ed background poller against `${apiUrl}/v1/auth/device/poll`, and immediately returns `waiting_for_browser` with `user_code`, `verification_uri`, and `verification_uri_complete`.
30
- - **Approval & zero-restart hot-reload**: When `/v1/auth/device/poll` returns `approved`, the poller writes `0600` `~/.memoreal/config.env` and `~/.memoria/config.env` (`0700` dirs, honoring `MEMOREAL_HOME`), merges `memoreal` into existing IDE config directories with `.bak` backups (skipping malformed JSON), sets `runtimePairedApiKey` in memory inside `createMemorealMcpService`, and caches `{ status: 'connected', workspace }` with all secret fields stripped so subsequent `encode_memory` / `build_context` calls succeed immediately without restarting the IDE.
31
- 6. **Callers & consumers checked**:
32
- - `test/memoria-mcp.test.mjs:190-208` passes `{ MEMOREAL_API_KEY: '', MEMORIA_API_KEY: '' }` expecting `Missing Memoreal API key: set MEMOREAL_API_KEY`; `resolveEffectiveApiKey` honors explicit empty `MEMOREAL_API_KEY === ''` in ambient `HOME` while still allowing `runtimePairedApiKey` and isolated `MEMOREAL_HOME` / `MEMOREAL_CONFIG_DIR` hot-reload.
33
- - `test/apify-actor.test.mjs:166-199` deletes `MEMOREAL_API_KEY` and passes `{ apiKey: '' }`; `src/apify-main.mjs#executeMemorealActorAction` passes `disableConfigFileFallback: true` when `rawInput.apiKey` is explicitly empty so developer `~/.memoria/config.env` files never pollute actor unit tests.
34
-
35
- ---
36
-
37
- ### Problem Solver Decision Record
38
-
39
- - **Broken Assumption & Escape Altitude $L^*$**: Shatters the assumption that stdio MCP connectors have static startup-only credentials requiring users to copy-paste raw API keys into chat or restart their IDE; ascends to `L11` (Wire / IPC Protocol) and `L14` (Bootstrap / Initialization) via Alien-Domain Isomorphism `L28` (RFC 8628 OAuth 2.0 Device Authorization Grant + copy-on-write `.bak` config persistence).
40
- - **Concept-Tree Occam Prune**: Pruned spawning an ephemeral localhost OAuth HTTP callback listener inside stdio MCP processes (eliminating port collisions across multi-window IDEs and OS firewall popups) and pruned third-party npm packages (`open`, `dotenv`, `inquirer`) in favor of zero-dependency Node.js `>= 18` built-ins (`fetch`, `readline`, `child_process.spawn`, `fs`).
41
- - **Unified Concept Set (Speed & Reliability)**: Fuses *Canonical Entry Normalization* (`sanitizeApiKey` rejecting placeholder tokens across env vars, `config.env`, and hooks) with *Dual In-Memory + On-Disk Hot-Reload* (`runtimePairedApiKey` + per-request `readSavedMemorealConfig`), collapsing 4 credential sources and 2 onboarding entrypoints (`connect_account` MCP tool + `setup`/`login`/`init` CLI) into 1 shared `src/config-store.mjs` + `src/wizard.mjs` primitive ($K \to 1$).
42
- - **Rejected Epicycle & Solution Occam Delta**: Rejects Rung 6 LLM chat copy-paste of raw secrets (preventing secret exposure in LLM context windows) and Rung 5 local port locks; uses Rung 1/3 deterministic FSM and `0600` file persistence with $\Delta\text{dependencies} = 0$ and $\Delta\text{src modules} = +2$ (`src/config-store.mjs`, `src/wizard.mjs`).
43
- - **Chosen Mechanism**: Rung 1 static MCP schema (`connect_account` with strict secret-redaction invariant) + Rung 3 deterministic device-code poller, placeholder-aware `resolveEffectiveApiKey`, `.bak`-guarded IDE JSON merger, and unregistered-silent hook gate.
44
- - **Codebase Consolidation**: Extends `src/server.mjs#createMemorealMcpService`, `src/schemas.mjs#MCP_TOOLS`, `opencode/memoreal-hooks.js#resolveCloudConfig`, and `install.sh`'s exact 6-variable `config.env` layout.
45
- - **Verification Proof Contract**:
46
- - Repro Command: `node --test ./test/connect-wizard.test.mjs`
47
- - Invariant Assertion: `MCP_TOOLS.length === 15` with 100% Glama TDQS compliance, `connect_account` transitions `waiting_for_browser` -> `connected` and hot-reloads `encode_memory` in-process without restart, `config.env` mode is `0600` (`0700` dir) under isolated `MEMOREAL_HOME`, `.bak` backups are created before IDE JSON merges while malformed JSON is preserved untouched, hooks produce zero output on `Read`/`Edit`/`Write` when unregistered, and raw `api_key` never appears in any MCP output or CLI stdout.
48
- - Regression Suite: `npm test`
49
-
50
- ---
51
-
52
- ## Questions & Answers
53
-
54
- - **Q1: How does `resolveEffectiveApiKey` support zero-restart `config.env` hot-reload without breaking `test/memoria-mcp.test.mjs:190` (`MEMOREAL_API_KEY: ''`) on developer machines that already have `~/.memoreal/config.env` or `~/.memoria/config.env`?**
55
- - **A1**: `resolveEffectiveApiKey` checks `overrideKey`, `runtimePairedApiKey`, `options.apiKey`, and `MEMOREAL_API_KEY` / `MEMOREAL_KEY` / `MEMORIA_API_KEY` / `MEMORIA_KEY` (filtering placeholders via `sanitizeApiKey`). When all are empty, it skips `$HOME` config-file fallback if `options.disableConfigFileFallback === true` or if `'MEMOREAL_API_KEY' in env && env.MEMOREAL_API_KEY === ''` without an explicit `MEMOREAL_HOME` / `MEMOREAL_CONFIG_DIR` test directory override. Placeholder strings such as `mem_dev_your_key_here` are non-empty in `env`, so they fall through to `config.env` hot-reload once paired.
56
- - **Q2: How should the AI assistant guide unregistered users in chat across Claude Code, OpenCode, and Cursor?**
57
- - **A2**: `MCP_SERVER_INSTRUCTIONS`, `requireApiKey` / `401` errors, `connect_account` messages, `hooks/hooks.json`, `opencode/memoria-hooks.js` (`opencode/memoreal-hooks.js`), and `skills/memoreal-connect/SKILL.md` instruct the assistant to drive the **3-Click Interactive In-Chat Wizard** via `AskUserQuestion` (Claude Code) or `question` (OpenCode & Cursor): Step 1 `"Connect in 1 Click via Google / Browser (Recommended)"` vs `"Skip for this session"`, Step 2 `connect_account({ action: "start" })` + clickable `/connect?code=XXXX-YYYY` link + `"I clicked Authorize — Verify"` (`connect_account({ action: "status" })`), and Step 3 `"Yes — Index repo now (Recommended)"` vs `"Later"`, never asking users to paste raw API keys into chat.
58
-
59
- ---
60
-
61
- ## Workstream Manifest
62
- ```json
63
- {
64
- "prdId": "002-connect-oauth-wizard",
65
- "worktreePath": "/Users/stasarshanski/Projects/Kolivri/memoria-mcp/.worktrees/feat-connect-wizard",
66
- "openQuestions": 0,
67
- "integrationVerifyCmd": "npm test",
68
- "workstreams": [
69
- {
70
- "id": "WS-0",
71
- "wave": 0,
72
- "layer": "architecture_base",
73
- "title": "Placeholder Detection, Dynamic Config Store, IDE Config Merger & Unit Tests",
74
- "description": "Create .gitignore ignoring .worktrees/, implement src/config-store.mjs for placeholder filtering, dynamic config.env resolution, 0600 persistence, and .bak IDE merging under MEMOREAL_HOME, and build unit tests in test/config-store.test.mjs.",
75
- "atomicChanges": [
76
- ".gitignore: create ignore rules for `.worktrees/`, `node_modules/`, `.DS_Store`, and `*.bak`.",
77
- "src/config-store.mjs: implement `isPlaceholderApiKey(raw)`, `sanitizeApiKey(raw)` (enforcing `/^[A-Za-z0-9_.-]+$/`), `normalizeApiUrl(raw)` (rejecting quotes/whitespace/shell metacharacters and non-HTTPS non-loopback URLs), and `POLITE_ONBOARDING_ACTION`.",
78
- "src/config-store.mjs: implement `resolveHomeDir(options)`, `readSavedMemorealConfig(options)`, `resolveEffectiveApiKey(overrideKey, options)`, and `resolveEffectiveApiUrl(overrideUrl, options)` honoring `runtimePairedApiKey`, explicit blank `MEMOREAL_API_KEY === ''` isolation, and `MEMOREAL_HOME`.",
79
- "src/config-store.mjs: implement `saveMemorealConfig({ apiKey, apiUrl, homeDir, env })` (`0700` dir, `0600` `config.env` + `.bak`) and `configureDetectedIdes({ apiKey, apiUrl, homeDir, env, preferredTool })` merging `memoreal` into `.config/opencode/opencode.json` (using OpenCode native `.mcp.memoreal = { type: 'remote', url, enabled: true, headers }`, never `.mcpServers`, and creating it when `preferredTool === 'opencode'`), `.cursor/mcp.json`, `.codeium/windsurf/mcp_config.json`, `.vscode/mcp.json`, Claude Desktop `claude_desktop_config.json`, and existing `.claude.json` with `.bak` backups while skipping malformed JSON.",
80
- "test/config-store.test.mjs: build unit tests verifying placeholder key filtering, `resolveEffectiveApiKey` test isolation, `0600` `config.env` persistence, and `.bak` IDE config merging (leaving malformed JSON untouched) strictly inside `MEMOREAL_HOME`."
81
- ],
82
- "ownedFiles": [
83
- ".gitignore",
84
- "src/config-store.mjs",
85
- "test/config-store.test.mjs"
86
- ],
87
- "readOnlyContext": [
88
- "prd/002-connect-oauth-wizard.md",
89
- "src/server.mjs",
90
- "install.sh",
91
- "test/memoria-mcp.test.mjs"
92
- ],
93
- "verifyCmd": "node --test ./test/config-store.test.mjs"
94
- },
95
- {
96
- "id": "WS-1",
97
- "wave": 0,
98
- "layer": "interfaces_first",
99
- "title": "connect_account Schema, Connect Skills & Schema Unit Tests",
100
- "description": "Update src/schemas.mjs with 3-Click Wizard instructions and connect_account (supporting string or object workspace), author skills/memoreal-connect/SKILL.md and skills/memoria-connect/SKILL.md, sync skills/memoria-doctor/SKILL.md, and update test/memoria-mcp.test.mjs.",
101
- "atomicChanges": [
102
- "src/schemas.mjs: update `MCP_SERVER_INSTRUCTIONS` (preserving `Memoreal Cloud`) to instruct assistants to run the 3-Click Interactive In-Chat Wizard via `AskUserQuestion` or `question` when unauthenticated and never ask users to paste raw API keys.",
103
- "src/schemas.mjs: append `connect_account` to `MCP_TOOLS` (15 tools total) with `annotations`, `inputSchema`, `outputSchema` (`workspace` using `anyOf: [{ type: 'string' }, { type: 'object' }]`), and `Use when` disambiguation text.",
104
- "skills/memoreal-connect/SKILL.md: create `/memoreal-connect` and mirror `skills/memoria-connect/SKILL.md` driving the 3-Click Interactive In-Chat Wizard (`AskUserQuestion` / `question` Steps 1-3).",
105
- "skills/memoria-doctor/SKILL.md: align legacy doctor alias with 3-Click Wizard onboarding and ensure zero `brain.kolivri.com` references across `skills/`.",
106
- "test/memoria-mcp.test.mjs: update unit tests for 15 tools (`MCP_TOOLS.length === 15`), asserting `connect_account` satisfies Glama TDQS `annotations`, `outputSchema` (`workspace` `anyOf` string/object), `/Use (when|at|to|after|before)/i`, and `required: []`."
107
- ],
108
- "ownedFiles": [
109
- "src/schemas.mjs",
110
- "skills/memoreal-connect/SKILL.md",
111
- "skills/memoria-connect/SKILL.md",
112
- "skills/memoria-doctor/SKILL.md",
113
- "test/memoria-mcp.test.mjs"
114
- ],
115
- "readOnlyContext": [
116
- "prd/002-connect-oauth-wizard.md",
117
- "src/server.mjs"
118
- ],
119
- "verifyCmd": "node --test ./test/memoria-mcp.test.mjs"
120
- },
121
- {
122
- "id": "WS-2",
123
- "wave": 1,
124
- "layer": "providers_parallel",
125
- "dependsOn": ["WS-0"],
126
- "title": "Device-Pairing Wizard Controller, Terminal CLI Setup & Unit Tests",
127
- "description": "Implement src/wizard.mjs providing non-blocking OS browser launch, background /v1/auth/device/poll state machine supporting string or object workspace with strict api_key redaction, and runCliSetupWizard(), plus unit tests in test/wizard-unit.test.mjs.",
128
- "atomicChanges": [
129
- "src/wizard.mjs: implement `openUrlInBrowser(url, options)` spawning `open` (`darwin`), `xdg-open` (`linux`), or `cmd /c start \"\"` (`win32`) detached with `.unref()` and silent error handling while respecting `MEMOREAL_NO_BROWSER=1`.",
130
- "src/wizard.mjs: implement `sanitizeWorkspaceMetadata(workspace)` supporting both trimmed non-secret string workspace slugs (such as `'acme'`) and sanitized plain objects while stripping secret properties/values, plus `normalizeClientToolSlug(rawName)`.",
131
- "src/wizard.mjs: implement `createConnectWizardController(options)` verifying existing keys via `POST /v1/mcp` `ping` (with `404` `/v1/health` fallback), guarding `executePoll` with per-poll timeout + `state.device_code === deviceCode` + controller identity checks, and handling `start`/`status`.",
132
- "src/wizard.mjs: implement `runCliSetupWizard(options)` supporting `--browser` and TTY choices `[1]` / `[2]` (calling `input.pause()` and ignoring ANSI escape sequences in `promptHidden`), verifying keys via `POST /v1/mcp` `ping` (rejecting `401`), and printing a secret-free summary.",
133
- "test/wizard-unit.test.mjs: build unit tests verifying `sanitizeWorkspaceMetadata` (string `'acme'` + objects), `promptHidden` TTY `input.pause()` + ANSI escape filtering, `POST /v1/mcp` `ping` `401` rejection vs `404` health fallback, and stale-`deviceCode` poll safety."
134
- ],
135
- "ownedFiles": [
136
- "src/wizard.mjs",
137
- "test/wizard-unit.test.mjs"
138
- ],
139
- "readOnlyContext": [
140
- "prd/002-connect-oauth-wizard.md",
141
- "src/config-store.mjs",
142
- "src/schemas.mjs"
143
- ],
144
- "verifyCmd": "node --test ./test/wizard-unit.test.mjs"
145
- },
146
- {
147
- "id": "WS-3",
148
- "wave": 1,
149
- "layer": "providers_parallel",
150
- "dependsOn": ["WS-0"],
151
- "title": "Silent-When-Unregistered Hooks, isChildSession Guard, ?tool=opencode & Unit Tests",
152
- "description": "Sync hooks/hooks.json, opencode/memoreal-hooks.js, opencode/memoria-hooks.js, and skills/memoreal-doctor/SKILL.md with isChildSession/isChildSubagentSession child suppression, ?tool=opencode fallback URL, and unregistered silence, tested in test/hooks-onboarding.test.mjs.",
153
- "atomicChanges": [
154
- "hooks/hooks.json: filter placeholder keys, move `NS=` after unregistered `exit 0` in `SessionStart`, provide inline POSIX `PWD` namespace fallback across all 10 hooks so `stderr` is empty without `install.sh`, and stay silent when unregistered.",
155
- "opencode/memoreal-hooks.js: implement and export `isChildSession` and `isChildSubagentSession` guarding `setup` and `MemorealHooksPlugin` hooks, include `https://memoreal.kolivri.com/connect?tool=opencode` (`tool: \"opencode\"`, `client_name: \"OpenCode\"`) in `ONBOARDING_WIZARD_PROMPT`, and suppress non-SessionStart hooks when unregistered.",
156
- "opencode/memoria-hooks.js: re-export `isChildSession`, `isChildSubagentSession`, `isPlaceholderApiKey`, and `ONBOARDING_WIZARD_PROMPT` alongside `MemorealHooksPlugin` and `setup` (both named and default exports).",
157
- "skills/memoreal-doctor/SKILL.md: ensure zero `brain.kolivri.com` references, detect placeholder keys in `~/.memoreal/config.env`, and direct unconfigured users to the 3-Click Wizard (`connect_account` or `npx -y @kolivri/memoreal-mcp setup`) without pasting raw keys.",
158
- "test/hooks-onboarding.test.mjs: build unit tests covering registered OpenCode v2 `setup` (`MEMOREAL_API_KEY: 'mem_dev_valid123'`) across `read`/`write`/`edit`/`compaction`/`session.execution.succeeded` in root vs child sessions (proving zero `ReferenceError`), `?tool=opencode` prompt URL, and unregistered silence."
159
- ],
160
- "ownedFiles": [
161
- "hooks/hooks.json",
162
- "opencode/memoreal-hooks.js",
163
- "opencode/memoria-hooks.js",
164
- "skills/memoreal-doctor/SKILL.md",
165
- "test/hooks-onboarding.test.mjs"
166
- ],
167
- "readOnlyContext": [
168
- "prd/002-connect-oauth-wizard.md",
169
- "src/config-store.mjs"
170
- ],
171
- "verifyCmd": "node --test ./test/hooks-onboarding.test.mjs"
172
- },
173
- {
174
- "id": "WS-4",
175
- "wave": 2,
176
- "layer": "consumers_after",
177
- "dependsOn": ["WS-0", "WS-1", "WS-2"],
178
- "title": "Wire Dynamic Hot-Reload, connect_account & CLI Entrypoint in server.mjs",
179
- "description": "Integrate config-store.mjs and wizard.mjs into src/server.mjs and src/apify-main.mjs for zero-restart key hot-reload, polite 3-Click Wizard 401/missing-key errors, connect_account dispatch, and CLI setup/login/init subcommands, updating unit tests in test/apify-actor.test.mjs.",
180
- "atomicChanges": [
181
- "src/server.mjs: update `createMemorealMcpService` to track `runtimePairedApiKey`, resolve keys and URLs dynamically via `resolveEffectiveApiKey` and `resolveEffectiveApiUrl`, and append `POLITE_ONBOARDING_ACTION` (keeping `'Missing Memoreal API key: set MEMOREAL_API_KEY'`) in `requireApiKey` and HTTP `401` errors in `forwardCloudRpc`.",
182
- "src/server.mjs: capture sanitized `params?.clientInfo?.name` into `connectedClientName` on `initialize`, instantiate `createConnectWizardController` with `getConnectedClientName`, route `callTool('connect_account', args)` locally without requiring an existing API key, and invoke `wizard.close()` when `startMcpStdioServer` closes.",
183
- "src/server.mjs: update the `isDirectExecution` entrypoint to dispatch `runCliSetupWizard({ argv: process.argv.slice(2) })` when `process.argv[2]` is `'setup'`, `'login'`, or `'init'` instead of starting the JSON-RPC stdio server.",
184
- "src/apify-main.mjs: sanitize placeholder keys in `normalizeInput` via `sanitizeApiKey` and pass `disableConfigFileFallback: ('apiKey' in rawInput && !sanitizeApiKey(rawInput.apiKey))` to `createMemorealMcpService` in `executeMemorealActorAction`.",
185
- "test/apify-actor.test.mjs: update unit tests to assert placeholder keys (`mem_dev_your_key_here`) and explicit empty `apiKey: ''` fail with `Missing Memoreal API key` and `Polite Onboarding Action` without leaking ambient `config.env`."
186
- ],
187
- "ownedFiles": [
188
- "src/server.mjs",
189
- "src/apify-main.mjs",
190
- "test/apify-actor.test.mjs"
191
- ],
192
- "readOnlyContext": [
193
- "prd/002-connect-oauth-wizard.md",
194
- "src/config-store.mjs",
195
- "src/schemas.mjs",
196
- "src/wizard.mjs",
197
- "test/memoria-mcp.test.mjs"
198
- ],
199
- "verifyCmd": "node --test ./test/apify-actor.test.mjs ./test/memoria-mcp.test.mjs"
200
- },
201
- {
202
- "id": "WS-5",
203
- "wave": 3,
204
- "layer": "consumers_after",
205
- "dependsOn": ["WS-2", "WS-3", "WS-4"],
206
- "title": "End-to-End Connect Wizard, Hot-Reload, CLI & Quiet-Hooks E2E Suite",
207
- "description": "Create end-to-end integration test suite test/connect-wizard.test.mjs verifying connect_account OAuth device pairing over stdio MCP, zero-restart hot-reload, 0600 permissions, .bak IDE config merging, placeholder/401 guidance, and node src/server.mjs setup --browser.",
208
- "atomicChanges": [
209
- "test/connect-wizard.test.mjs: add end-to-end stdio MCP test verifying `initialize` `clientInfo.name` forwards `client_name` and normalized `tool` slug to `POST /v1/auth/device/start`, handles both string (`workspace: 'acme'`) and object `workspace` from `POST /v1/auth/device/poll`, hot-reloads `encode_memory` without restart, writes `0600` `config.env` under `MEMOREAL_HOME`, and never exposes raw `api_key`.",
210
- "test/connect-wizard.test.mjs: add end-to-end IDE config merge test strictly within `MEMOREAL_HOME` verifying `.bak` backups, OpenCode native `.mcp.memoreal` (`type: 'remote'`, never `.mcpServers`), and `.mcpServers.memoreal` across `.cursor/mcp.json`, `.codeium/windsurf/mcp_config.json`, `.vscode/mcp.json`, Claude Desktop `claude_desktop_config.json`, and existing `.claude.json` while leaving malformed JSON untouched.",
211
- "test/connect-wizard.test.mjs: add end-to-end stdio MCP and CLI tests for placeholder key rejection, cross-process `config.env` hot-reload via `node src/server.mjs setup --browser`, HTTP `401` guidance, `?tool=opencode` in OpenCode `SessionStart` prompt, `skills/memoria-connect/SKILL.md` + `skills/memoreal-connect/SKILL.md` existence, and zero `brain.kolivri.com` across every file in `skills/`."
212
- ],
213
- "ownedFiles": [
214
- "test/connect-wizard.test.mjs"
215
- ],
216
- "readOnlyContext": [
217
- "prd/002-connect-oauth-wizard.md",
218
- "src/config-store.mjs",
219
- "src/schemas.mjs",
220
- "src/wizard.mjs",
221
- "src/server.mjs",
222
- "hooks/hooks.json",
223
- "opencode/memoreal-hooks.js",
224
- "opencode/memoria-hooks.js",
225
- "skills/memoreal-doctor/SKILL.md",
226
- "skills/memoreal-connect/SKILL.md"
227
- ],
228
- "verifyCmd": "npm test"
229
- }
230
- ]
231
- }
232
- ```
233
-
234
- ---
235
-
236
- ## Verification Criteria
237
-
238
- 1. `npm test` passes 100% across `test/memoria-mcp.test.mjs`, `test/apify-actor.test.mjs`, and `test/connect-wizard.test.mjs` with zero skipped or stubbed assertions.
239
- 2. `MCP_TOOLS` exports 15 tools (`connect_account` + 14 memory/code tools), all satisfying Glama TDQS `annotations`, `outputSchema`, and `/Use (when|at|to|after|before)/i` description checks.
240
- 3. Placeholder keys (`mem_dev_your_key_here`, `mem_dev_...`, `YOUR_API_KEY`, `<MEMOREAL_API_KEY>`) are treated as unconfigured, `test/memoria-mcp.test.mjs:190` passes on machines with or without `~/.memoreal/config.env`, and `requireApiKey` / `401` errors include `'Missing Memoreal API key: set MEMOREAL_API_KEY'`, `'Polite Onboarding Action'`, and 3-Click Interactive In-Chat Wizard guidance.
241
- 4. `connect_account` and `node src/server.mjs setup --browser` persist `0600` `config.env` inside `0700` directories under `MEMOREAL_HOME`, back up existing IDE configs to `.bak` without corrupting malformed JSON, hot-reload `encode_memory` immediately without restart, and never expose raw `api_key` values in MCP responses or CLI output.
242
- 5. `hooks/hooks.json` and `opencode/memoria-hooks.js` (`opencode/memoreal-hooks.js`) emit zero output on `Read`/`Edit`/`Write` when unregistered and emit a polite one-time 3-Click Wizard prompt on `SessionStart`.
243
-
244
- ---
245
-
246
- ## Implementation Results
247
-
248
- - **Wave 0 (`WS-0` & `WS-1`)**:
249
- - `WS-0`: Created `.gitignore`, `src/config-store.mjs` (`isPlaceholderApiKey`, `sanitizeApiKey`, `resolveEffectiveApiKey`, `resolveEffectiveApiUrl`, `saveMemorealConfig` with `0700`/`0600` permissions + `.bak`, `configureDetectedIdes` with OpenCode native `.mcp.memoreal` vs `.mcpServers.memoreal` across Cursor/Windsurf/VS Code/Claude Desktop/existing `.claude.json` while skipping malformed JSON, and `POLITE_ONBOARDING_ACTION`), and `test/config-store.test.mjs` (`22/22` passing).
250
- - `WS-1`: Updated `src/schemas.mjs` (`MCP_SERVER_INSTRUCTIONS` + 15th `connect_account` tool descriptor with Glama TDQS compliance), created `skills/memoreal-connect/SKILL.md`, and updated `test/memoria-mcp.test.mjs` (`8/8` passing).
251
- - **Wave 1 (`WS-2` & `WS-3`)**:
252
- - `WS-2`: Created `src/wizard.mjs` (`normalizeClientToolSlug`, `sanitizeClientName`, `sanitizeWorkspaceMetadata`, `openUrlInBrowser`, `createConnectWizardController`, `runCliSetupWizard`) and `test/wizard-unit.test.mjs` (`18/18` passing).
253
- - `WS-3`: Updated `hooks/hooks.json`, `opencode/memoreal-hooks.js`, `opencode/memoria-hooks.js`, and `skills/memoreal-doctor/SKILL.md`, and added `test/hooks-onboarding.test.mjs` (`16/16` passing).
254
- - **Wave 2 (`WS-4`)**:
255
- - `WS-4`: Wired dynamic hot-reload (`runtimePairedApiKey` + `config.env`), `initialize` `clientInfo.name` capture, `connect_account` routing, `401` / missing-key 3-Click Wizard guidance, and `setup`/`login`/`init` CLI dispatch into `src/server.mjs`, `src/apify-main.mjs`, and `test/apify-actor.test.mjs` (`24/24` passing).
256
- - **Wave 3 (`WS-5`) & Critic Hardening Passes**:
257
- - `WS-5` & Critic Remediation: Added `isChildSession` / `isChildSubagentSession` root-vs-child OpenCode hook guards and `?tool=opencode` (`client_name: "OpenCode"`) fallback URL in `opencode/memoreal-hooks.js` & `opencode/memoria-hooks.js`; added string `workspace` (`"acme"`) support in `src/wizard.mjs#sanitizeWorkspaceMetadata` and `src/schemas.mjs`; added `skills/memoria-connect/SKILL.md` and verified zero `brain.kolivri.com` across all `skills/*/SKILL.md`; hardened `promptHidden` (`input.pause()` + ANSI escape stripping), `executePoll` (timeout + `state.device_code` + controller guards), `verifyApiKeyAuth` (`POST /v1/mcp` `ping` rejecting `401` with `404` `/v1/health` fallback), `hooks/hooks.json` (inline POSIX `PWD` namespace fallback with empty `stderr`), and `src/config-store.mjs` (`/^[A-Za-z0-9_.-]+$/` key validation + HTTPS/loopback URL injection guards).
258
- - **Full Integration Verification (`npm test`)**: **`115 / 115` tests passing** across **`29` suites** (`0` failures, `0` skipped). Zero deviations from the approved design.
259
-