@kolivri/memoreal-mcp 0.0.0-stage → 1.0.2
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.
- package/.actor/Dockerfile +6 -0
- package/.actor/actor.json +15 -0
- package/.actor/input_schema.json +92 -0
- package/.cursor-plugin/plugin.json +26 -0
- package/.mcp.json +11 -0
- package/CLAUDE.md +54 -0
- package/Dockerfile +5 -0
- package/LICENSE +21 -0
- package/README.md +125 -2
- package/agents/memoreal.md +123 -0
- package/agents/memoria.md +125 -0
- package/assets/logo.svg +9 -0
- package/bin/memoreal-ns +11 -0
- package/bin/memoria-ns +16 -0
- package/glama.json +8 -0
- package/hooks/hooks.json +119 -0
- package/install.sh +346 -0
- package/manifest.json +18 -0
- package/mcp.json +11 -0
- package/opencode/memoreal-hooks.js +609 -0
- package/opencode/memoria-hooks.js +38 -0
- package/package.json +37 -4
- package/prd/001-rebrand-memoreal-mcp.md +132 -0
- package/prd/002-connect-oauth-wizard.md +259 -0
- package/rules/memoreal.mdc +11 -0
- package/rules/memoria.mdc +11 -0
- package/server.json +50 -0
- package/skills/memoreal-connect/SKILL.md +71 -0
- package/skills/memoreal-doctor/SKILL.md +58 -0
- package/skills/memoreal-sync/SKILL.md +37 -0
- package/skills/memoreal-sync-code/SKILL.md +39 -0
- package/skills/memoreal-wrap-up/SKILL.md +32 -0
- package/skills/memoria-connect/SKILL.md +71 -0
- package/skills/memoria-doctor/SKILL.md +60 -0
- package/skills/memoria-sync/SKILL.md +18 -0
- package/skills/memoria-sync-code/SKILL.md +20 -0
- package/skills/memoria-wrap-up/SKILL.md +24 -0
- package/smithery.yaml +61 -0
- package/src/apify-main.mjs +346 -0
- package/src/config-store.mjs +486 -0
- package/src/schemas.mjs +583 -0
- package/src/server.mjs +563 -0
- package/src/wizard.mjs +921 -0
- package/test/apify-actor.test.mjs +429 -0
- package/test/config-store.test.mjs +680 -0
- package/test/connect-wizard.test.mjs +936 -0
- package/test/hooks-onboarding.test.mjs +1039 -0
- package/test/memoria-mcp.test.mjs +376 -0
- package/test/wizard-unit.test.mjs +1272 -0
package/bin/memoria-ns
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Backward-compatible alias for memoreal-ns.
|
|
3
|
+
# Derive Memoreal namespace from the current working directory.
|
|
4
|
+
# Strips a /.claude/worktrees/... suffix so worktrees (and submodule worktrees
|
|
5
|
+
# nested under them) share the parent project's namespace.
|
|
6
|
+
# Usage: NS=$(memoria-ns)
|
|
7
|
+
DIR="$(dirname "$0")"
|
|
8
|
+
if [ -x "$DIR/memoreal-ns" ]; then
|
|
9
|
+
exec "$DIR/memoreal-ns" "$@"
|
|
10
|
+
fi
|
|
11
|
+
P="${1:-$PWD}"
|
|
12
|
+
case "$P" in
|
|
13
|
+
*/.claude/worktrees/*) P="${P%%/.claude/worktrees/*}" ;;
|
|
14
|
+
*/.opencode/worktrees/*) P="${P%%/.opencode/worktrees/*}" ;;
|
|
15
|
+
esac
|
|
16
|
+
printf '%s' "$P" | tr '/' '-'
|
package/glama.json
ADDED
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_URL=''; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_URL\" ] && CFG_URL=$(grep -E '^(MEMOREAL_API_URL|MEMORIA_API_URL)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_URL=\"${MEMOREAL_API_URL:-${MEMORIA_API_URL:-${CFG_URL:-https://memoria.kolivri.com}}}\"; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then echo \"[memoreal-session-start] Memoreal Cloud is not yet connected.\\nDrive the 3-Click Interactive In-Chat Wizard using AskUserQuestion (Claude Code) or question (OpenCode & Cursor):\\n- Step 1: Present choice card \\\"Connect in 1 Click via Google / Browser (Recommended)\\\" vs \\\"Skip for this session\\\".\\n- Step 2: Call connect_account({ action: \\\"start\\\" }) and present clickable https://memoreal.kolivri.com/connect?code=XXXX-YYYY link with \\\"I clicked Authorize — Verify\\\" card (calling connect_account({ action: \\\"status\\\" })).\\n- Step 3: Once connected, present choice card \\\"Yes — Index repo now (Recommended)\\\" vs \\\"Later\\\".\\nNever ask the user to paste a raw API key into chat.\"; exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; case \"$API_URL\" in https://*) TLS_ARGS=\"--proto =https --tlsv1.2\" ;; http://localhost*|http://127.0.0.1*) TLS_ARGS=\"\" ;; *) API_URL=\"https://memoria.kolivri.com\"; TLS_ARGS=\"--proto =https --tlsv1.2\" ;; esac; CURL_CFG=''; if [ -n \"$API_KEY\" ]; then CURL_CFG=$(printf 'header = \"Authorization: Bearer %s\"\\n' \"$API_KEY\"); fi; BRANCH=$(git branch --show-current 2>/dev/null || echo ''); RECENT=$(git log --oneline -3 2>/dev/null | tr '\\n' '; ' || echo ''); CHANGED=$(git diff --name-only HEAD 2>/dev/null | tr '\\n' ', ' || echo ''); GIT_CTX=''; if [ -n \"$BRANCH\" ]; then GIT_CTX=\"branch: $BRANCH\"; fi; if [ -n \"$RECENT\" ]; then GIT_CTX=\"$GIT_CTX, recent commits: $RECENT\"; fi; if [ -n \"$CHANGED\" ]; then GIT_CTX=\"$GIT_CTX, changed files: $CHANGED\"; fi; QUERY=\"previous tasks, plans, pending work, key decisions, progress, corrections, lessons learned\"; if [ -n \"$GIT_CTX\" ]; then QUERY=\"$QUERY, context for $GIT_CTX\"; fi; HEALTH=$(printf '%s' \"$CURL_CFG\" | curl -sf $TLS_ARGS -K - \"$API_URL/v1/health\" 2>&1) || { echo \"[memoreal-session-start] namespace=$NS. Call build_context MCP tool with namespace \\\"$NS\\\" and query \\\"$QUERY\\\" and token_budget 4096 to load prior session context.\"; exit 0; }; PAYLOAD=$(jq -n --arg ns \"$NS\" --arg q \"$QUERY\" '{namespace: $ns, query: $q, token_budget: 4096}' 2>/dev/null || printf '{\"namespace\":\"%s\",\"query\":\"%s\",\"token_budget\":4096}' \"$NS\" \"$QUERY\"); CONTEXT=$(printf '%s' \"$CURL_CFG\" | curl -sf $TLS_ARGS -K - -X POST \"$API_URL/v1/memories/context\" -H 'Content-Type: application/json' -d \"$PAYLOAD\" 2>&1) || { echo \"[memoreal-session-start] namespace=$NS. Health: $HEALTH. Call build_context MCP tool with namespace \\\"$NS\\\" and query \\\"$QUERY\\\" to load prior context.\"; exit 0; }; echo \"$HEALTH\"; echo \"---\"; echo \"$CONTEXT\"",
|
|
10
|
+
"timeout": 15,
|
|
11
|
+
"statusMessage": "Loading memory context from Memoreal Cloud..."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"PreCompact": [
|
|
17
|
+
{
|
|
18
|
+
"matcher": "",
|
|
19
|
+
"hooks": [
|
|
20
|
+
{
|
|
21
|
+
"type": "command",
|
|
22
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-pre-compact] Context is about to be compressed. BEFORE compression happens, encode the following into Memoreal (namespace: $NS) so nothing is lost:\\n1. (type: episodic) Current task state: what you were working on, what is done, what remains\\n2. (type: episodic) Key findings so far: bugs found, root causes identified, decisions made\\n3. (type: episodic) Open questions and blockers\\n4. (type: semantic) Any code patterns, architecture insights, or facts learned this session\\nThis is critical — after compaction, detailed context is lost. Encode it NOW before responding.\"",
|
|
23
|
+
"timeout": 5
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"PostCompact": [
|
|
29
|
+
{
|
|
30
|
+
"matcher": "",
|
|
31
|
+
"hooks": [
|
|
32
|
+
{
|
|
33
|
+
"type": "command",
|
|
34
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-post-compact] Context was just compressed. Call build_context with namespace \\\"$NS\\\" and query \\\"current task, recent progress, findings, decisions, open questions, what was I working on\\\" and token_budget 2048 to restore critical context that may have been lost during compression.\"",
|
|
35
|
+
"timeout": 3
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"UserPromptSubmit": [
|
|
41
|
+
{
|
|
42
|
+
"matcher": "",
|
|
43
|
+
"hooks": [
|
|
44
|
+
{
|
|
45
|
+
"type": "command",
|
|
46
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; MSG=$(cat /dev/stdin 2>/dev/null | jq -r '.prompt // empty' 2>/dev/null | tr '[:upper:]' '[:lower:]'); case \"$MSG\" in *\"don't\"*|*\"do not\"*|*\"stop\"*|*\"never\"*|*\"wrong\"*|*\"no,\"*|*\"no \"*|*\"actually\"*|*\"instead\"*|*\"not like that\"*|*\"that's wrong\"*|*\"incorrect\"*) if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-correction] The user appears to be correcting your approach. After addressing the correction, encode the lesson into Memoreal (namespace: $NS, type: semantic, salience: 0.9) as a rule: what was wrong, what the correct approach is, and why. This ensures the mistake is never repeated in future sessions.\" ;; esac",
|
|
47
|
+
"timeout": 2
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"PostToolUse": [
|
|
53
|
+
{
|
|
54
|
+
"matcher": "TaskCreate",
|
|
55
|
+
"hooks": [
|
|
56
|
+
{
|
|
57
|
+
"type": "command",
|
|
58
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-encode-task] A task was just created. Encode it into Memoreal via encode_memory with type \\\"episodic\\\" and namespace \\\"$NS\\\". Include the task description, status, and which plan file it relates to (if any).\"",
|
|
59
|
+
"timeout": 3
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"matcher": "Write",
|
|
65
|
+
"hooks": [
|
|
66
|
+
{
|
|
67
|
+
"type": "command",
|
|
68
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; FILE=$(jq -r '.tool_input.file_path // empty' 2>/dev/null); case \"$FILE\" in *.claude/plans/*|*.opencode/plans/*|*design-log/*|*docs/*plan*|*docs/*roadmap*) echo \"[memoreal-encode-plan] Plan file written: $FILE\\nEncode this plan into Memoreal (namespace: $NS). Create MULTIPLE memories:\\n1. (type: semantic) Plan overview: title, goals, phase structure, and current status\\n2. (type: semantic) Key decisions and their rationale from this plan\\n3. (type: episodic) Progress snapshot: what phases are done, what is next, what is blocked\\n4. (type: semantic) Relationships: other files, systems, or plans referenced in this document\\n5. (type: semantic) Knowledge: patterns, techniques, or lessons relevant to executing this plan\\n6. (type: episodic) Ideas and open questions found in the plan\\n7. (type: semantic) Reflection: what is working well, what is not, what should change in approach\\n8. (type: semantic) Dream: replay and consolidate — what patterns emerge across related memories, what connections between ideas were missed, what should be strengthened or let go\\n9. (type: semantic) Workflow: how we are working on this plan — tools, processes, patterns that help or hinder\\nInclude the file path in context metadata for every memory.\" ;; *.md|*.markdown) echo \"[memoreal-encode-doc] Markdown document written: $FILE\\nEncode into Memoreal (namespace: $NS). Create memories for:\\n1. (type: semantic) Document purpose, structure, and key content\\n2. (type: semantic) Decisions, patterns, or knowledge worth remembering\\n3. (type: episodic) Relationships to other project work and plans\\nInclude the file path in context metadata.\" ;; *.lock|*.sum|*.toml|*.cfg|*.ini|*.env*) ;; *.rs|*.py|*.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.go|*.java|*.kt|*.kts|*.c|*.h|*.cc|*.cpp|*.hpp|*.cxx|*.cs|*.rb|*.php|*.swift|*.scala|*.sh|*.bash|*.zsh|*.sql|*.proto) echo \"[memoreal-encode-code] Code file written: $FILE. Re-encode this code into Memoreal (namespace: $NS) so search_code, explain_code, and find_references stay current: encode the key definitions (functions, types, classes) with their signatures, purpose, and notable logic as type semantic memories, salience 0.6, with the file path in context. Search before encoding so dedup can merge near-duplicates. For a full structural re-index of the project, run the memoreal-sync-code skill.\" ;; *) echo \"[memoreal-encode-file] File written: $FILE. Apply write gate: only encode if this file contains a key definition, decision, or pattern worth remembering across sessions. Skip boilerplate. If encoding, use namespace $NS, type semantic, salience 0.5. Include file path in context.\" ;; esac",
|
|
69
|
+
"timeout": 3
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"matcher": "Edit",
|
|
75
|
+
"hooks": [
|
|
76
|
+
{
|
|
77
|
+
"type": "command",
|
|
78
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; FILE=$(jq -r '.tool_input.file_path // empty' 2>/dev/null); case \"$FILE\" in *.claude/plans/*|*.opencode/plans/*|*design-log/*|*docs/*plan*|*docs/*roadmap*) echo \"[memoreal-encode-plan] Plan file updated: $FILE\\nEncode this change into Memoreal (namespace: $NS). Create memories for:\\n1. (type: episodic) What specifically changed in the plan and why\\n2. (type: episodic) Progress update: mark completed items, note new items or phase transitions\\n3. (type: semantic) Any new decisions, ideas, or insights from this edit\\n4. (type: semantic) New relationships or dependencies added\\n5. (type: semantic) Reflection: does this change reveal something about the approach — what is working, what needs rethinking\\n6. (type: semantic) Workflow ideas: better ways to work on this plan based on what just happened\\nInclude the file path in context metadata.\" ;; *.md|*.markdown) echo \"[memoreal-encode-doc] Markdown document edited: $FILE\\nEncode the change into Memoreal (namespace: $NS):\\n1. (type: episodic) What changed and why\\n2. (type: semantic) Any new knowledge, decisions, or patterns\\nInclude the file path in context metadata.\" ;; *.lock|*.sum|*.toml|*.cfg|*.ini|*.env*) ;; *.rs|*.py|*.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs|*.go|*.java|*.kt|*.kts|*.c|*.h|*.cc|*.cpp|*.hpp|*.cxx|*.cs|*.rb|*.php|*.swift|*.scala|*.sh|*.bash|*.zsh|*.sql|*.proto) echo \"[memoreal-encode-code] Code file edited: $FILE. Re-encode the changed code into Memoreal (namespace: $NS): encode the updated definitions and logic (what changed and the new behavior) as type semantic, salience 0.6, with the file path in context, so search_code, explain_code, and find_references reflect the current code. Search before encoding to avoid duplicates. For a full structural re-index, run the memoreal-sync-code skill.\" ;; *) echo \"[memoreal-encode-file] File edited: $FILE. Apply write gate: only encode if this edit represents a meaningful decision, pattern, or lesson. Skip routine changes. If encoding, use namespace $NS, type semantic, salience 0.5. Include file path and what changed.\" ;; esac",
|
|
79
|
+
"timeout": 3
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"matcher": "Read",
|
|
85
|
+
"hooks": [
|
|
86
|
+
{
|
|
87
|
+
"type": "command",
|
|
88
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; FILE=$(jq -r '.tool_input.file_path // empty' 2>/dev/null); case \"$FILE\" in *.claude/plans/*|*.opencode/plans/*|*design-log/*|*docs/*plan*|*docs/*roadmap*|*.md) if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-recall-doc] Reading: $FILE\\nRecall related memories from Memoreal (namespace: $NS) about this file: prior edits, progress updates, decisions, related plans, ideas, reflections, workflow patterns, consolidated patterns, and context from previous sessions. Show the user what Memoreal knows about this file before proceeding.\" ;; esac",
|
|
89
|
+
"timeout": 3
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"TaskCompleted": [
|
|
95
|
+
{
|
|
96
|
+
"matcher": "",
|
|
97
|
+
"hooks": [
|
|
98
|
+
{
|
|
99
|
+
"type": "command",
|
|
100
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-update-task] A task was just completed. Encode into Memoreal (namespace: $NS). Create memories for:\\n1. (type: episodic) What was accomplished and which plan file it relates to\\n2. (type: semantic) Lessons learned and knowledge gained from this task\\n3. (type: semantic) Reflection: what went well, what was harder than expected, what to do differently next time\\n4. (type: semantic) Workflow ideas: any process improvements or tool usage patterns discovered while doing this task\"",
|
|
101
|
+
"timeout": 3
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"Stop": [
|
|
107
|
+
{
|
|
108
|
+
"matcher": "",
|
|
109
|
+
"hooks": [
|
|
110
|
+
{
|
|
111
|
+
"type": "command",
|
|
112
|
+
"command": "BASE_HOME=\"${MEMOREAL_HOME:-$HOME}\"; CFG_KEY=''; if [ -n \"${MEMOREAL_HOME:-}\" ] || [ -z \"${MEMOREAL_API_KEY+x}\" ] || [ -n \"$MEMOREAL_API_KEY\" ]; then for f in \"$BASE_HOME/.memoreal/config.env\" \"$BASE_HOME/.memoria/config.env\"; do if [ -f \"$f\" ]; then [ -z \"$CFG_KEY\" ] && CFG_KEY=$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' \"$f\" 2>/dev/null | tail -n 1 | cut -d= -f2- | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); fi; done; fi; API_KEY=''; for _k in \"${MEMOREAL_API_KEY:-}\" \"${MEMORIA_API_KEY:-}\" \"${MEMOREAL_KEY:-}\" \"${MEMORIA_KEY:-}\" \"$CFG_KEY\"; do _ck=$(printf '%s' \"$_k\" | tr -d ' \\t\\r\\n\"' | tr -d \"'\"); [ -z \"$_ck\" ] && continue; _kl=$(printf '%s' \"$_ck\" | tr '[:upper:]' '[:lower:]'); case \"$_kl\" in *...*|'<'*'>'|'${'*'}'|mem_dev_your_key_here|*your_key_here*|*your_api_key*|*your-api-key*|*your-memoreal-api-key*|*your_memoreal_api_key*|placeholder) continue ;; *) API_KEY=\"$_ck\"; break ;; esac; done; if [ -z \"$API_KEY\" ]; then exit 0; fi; if [ -x \"$BASE_HOME/.memoreal/bin/memoreal-ns\" ]; then NS=$(\"$BASE_HOME/.memoreal/bin/memoreal-ns\"); elif [ -x \"$BASE_HOME/.memoria/bin/memoria-ns\" ]; then NS=$(\"$BASE_HOME/.memoria/bin/memoria-ns\"); else _P=\"$PWD\"; _P=\"${_P%%/.worktrees/*}\"; _P=\"${_P%%/.claude/worktrees/*}\"; _P=\"${_P%%/.opencode/worktrees/*}\"; NS=$(printf \"%s\" \"$_P\" | tr \"/\" \"-\"); fi; echo \"[memoreal-session-end] Session is ending. Encode a session summary into Memoreal (namespace: $NS) with the following write gate — ONLY encode if the item would change future behavior, represents a commitment, or is a decision worth preserving. Skip transient details.\\n1. (type: episodic, salience: 0.7) Session summary: what was the goal, what was accomplished, what remains unfinished\\n2. (type: semantic, salience: 0.8) Key decisions made and their rationale — only decisions that affect future work\\n3. (type: semantic, salience: 0.8) Lessons learned: mistakes made, corrections received, patterns discovered\\n4. (type: semantic, salience: 0.6) Code patterns or architecture insights worth remembering\\n5. (type: episodic, salience: 0.5) Open questions and next steps for the next session\\nInclude [[\\\"source\\\", \\\"session-end\\\"]] in context metadata for each. Then run consolidate on namespace \\\"$NS\\\".\"",
|
|
113
|
+
"timeout": 5
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
package/install.sh
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
MEMOREAL_DIR="${MEMOREAL_DIR:-$HOME/.memoreal}"
|
|
5
|
+
MEMORIA_DIR="${MEMORIA_DIR:-$HOME/.memoria}"
|
|
6
|
+
BIN_DIR="$MEMOREAL_DIR/bin"
|
|
7
|
+
CONFIG_ENV="$MEMOREAL_DIR/config.env"
|
|
8
|
+
LEGACY_CONFIG_ENV="$MEMORIA_DIR/config.env"
|
|
9
|
+
SETTINGS_JSON="$HOME/.claude/settings.json"
|
|
10
|
+
COMMANDS_DIR="$HOME/.claude/commands"
|
|
11
|
+
OPENCODE_DIR="$HOME/.config/opencode"
|
|
12
|
+
OPENCODE_JSON="$OPENCODE_DIR/opencode.json"
|
|
13
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
+
|
|
15
|
+
# Preserve existing API key from ~/.memoreal/config.env or ~/.memoria/config.env
|
|
16
|
+
EXISTING_API_KEY=""
|
|
17
|
+
EXISTING_API_URL=""
|
|
18
|
+
for cfg in "$CONFIG_ENV" "$LEGACY_CONFIG_ENV"; do
|
|
19
|
+
if [ -f "$cfg" ]; then
|
|
20
|
+
if [ -z "$EXISTING_API_KEY" ]; then
|
|
21
|
+
EXISTING_API_KEY="$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' "$cfg" 2>/dev/null | tail -n 1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" || true)"
|
|
22
|
+
fi
|
|
23
|
+
if [ -z "$EXISTING_API_URL" ]; then
|
|
24
|
+
EXISTING_API_URL="$(grep -E '^(MEMOREAL_API_URL|MEMORIA_API_URL|MEMOREAL_URL|MEMORIA_URL)=' "$cfg" 2>/dev/null | tail -n 1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" || true)"
|
|
25
|
+
fi
|
|
26
|
+
fi
|
|
27
|
+
done
|
|
28
|
+
|
|
29
|
+
# Memoreal Cloud MCP and HTTP API endpoints (defaulting to https://memoria.kolivri.com until DNS transition):
|
|
30
|
+
MEMOREAL_URL="${MEMOREAL_URL:-${MEMORIA_URL:-https://memoria.kolivri.com/v1/mcp}}"
|
|
31
|
+
DEFAULT_API_URL="${MEMOREAL_URL%/v1/mcp}"
|
|
32
|
+
DEFAULT_API_URL="${DEFAULT_API_URL%/}"
|
|
33
|
+
MEMOREAL_API_URL="${MEMOREAL_API_URL:-${MEMORIA_API_URL:-${EXISTING_API_URL:-$DEFAULT_API_URL}}}"
|
|
34
|
+
MEMOREAL_API_KEY="${MEMOREAL_API_KEY:-${MEMORIA_API_KEY:-${MEMOREAL_KEY:-${MEMORIA_KEY:-$EXISTING_API_KEY}}}}"
|
|
35
|
+
MEMORIA_URL="$MEMOREAL_URL"
|
|
36
|
+
MEMORIA_API_URL="$MEMOREAL_API_URL"
|
|
37
|
+
MEMORIA_API_KEY="$MEMOREAL_API_KEY"
|
|
38
|
+
|
|
39
|
+
# Validate URLs (require HTTPS for all remote hosts; allow HTTP only on local loopback for tests)
|
|
40
|
+
validate_url() {
|
|
41
|
+
case "$1" in
|
|
42
|
+
https://*[!A-Za-z0-9._:/-]*) return 1 ;;
|
|
43
|
+
https://?*) return 0 ;;
|
|
44
|
+
http://localhost*|http://127.0.0.1*) return 0 ;;
|
|
45
|
+
*) return 1 ;;
|
|
46
|
+
esac
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ! validate_url "$MEMOREAL_URL" || ! validate_url "$MEMOREAL_API_URL"; then
|
|
50
|
+
echo "Error: MEMOREAL_URL and MEMOREAL_API_URL must use https:// (or http://localhost for local tests)." >&2
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
if [ -n "$MEMOREAL_API_KEY" ] && ! printf '%s' "$MEMOREAL_API_KEY" | grep -Eq '^[A-Za-z0-9_.-]+$'; then
|
|
55
|
+
echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
|
|
56
|
+
exit 1
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
echo "Memoreal - Claude Code & OpenCode Cloud Plugin"
|
|
60
|
+
echo "=============================================="
|
|
61
|
+
echo ""
|
|
62
|
+
echo "Cloud API: $MEMOREAL_API_URL"
|
|
63
|
+
echo "Cloud MCP: $MEMOREAL_URL"
|
|
64
|
+
if [ -n "$MEMOREAL_API_KEY" ]; then
|
|
65
|
+
echo "API Key: ${MEMOREAL_API_KEY:0:12}..."
|
|
66
|
+
else
|
|
67
|
+
echo "API Key: (not set — pass MEMOREAL_KEY=mem_dev_... to authenticate)"
|
|
68
|
+
fi
|
|
69
|
+
echo ""
|
|
70
|
+
|
|
71
|
+
umask 077
|
|
72
|
+
mkdir -p "$MEMOREAL_DIR" "$BIN_DIR"
|
|
73
|
+
chmod 700 "$MEMOREAL_DIR" "$BIN_DIR" 2>/dev/null || true
|
|
74
|
+
|
|
75
|
+
# Maintain ~/.memoria symlink / directory for backward compatibility
|
|
76
|
+
if [ ! -e "$MEMORIA_DIR" ]; then
|
|
77
|
+
ln -s "$MEMOREAL_DIR" "$MEMORIA_DIR" 2>/dev/null || mkdir -p "$MEMORIA_DIR"
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
# --- Persist cloud configuration for SessionStart hooks and slash commands ---
|
|
81
|
+
printf 'MEMOREAL_URL="%s"\nMEMOREAL_API_URL="%s"\nMEMOREAL_API_KEY="%s"\nMEMORIA_URL="%s"\nMEMORIA_API_URL="%s"\nMEMORIA_API_KEY="%s"\n' \
|
|
82
|
+
"$MEMOREAL_URL" "$MEMOREAL_API_URL" "$MEMOREAL_API_KEY" \
|
|
83
|
+
"$MEMOREAL_URL" "$MEMOREAL_API_URL" "$MEMOREAL_API_KEY" > "$CONFIG_ENV"
|
|
84
|
+
chmod 600 "$CONFIG_ENV" 2>/dev/null || true
|
|
85
|
+
if [ ! -L "$MEMORIA_DIR" ] && [ -d "$MEMORIA_DIR" ] && [ "$MEMORIA_DIR" != "$MEMOREAL_DIR" ]; then
|
|
86
|
+
cp "$CONFIG_ENV" "$LEGACY_CONFIG_ENV" 2>/dev/null || true
|
|
87
|
+
chmod 600 "$LEGACY_CONFIG_ENV" 2>/dev/null || true
|
|
88
|
+
fi
|
|
89
|
+
echo "Saved cloud config to $CONFIG_ENV (mode 0600)"
|
|
90
|
+
|
|
91
|
+
# Clean up deprecated binary
|
|
92
|
+
if [ -f "$BIN_DIR/memoria-mcp" ]; then
|
|
93
|
+
rm -f "$BIN_DIR/memoria-mcp"
|
|
94
|
+
echo " Removed deprecated memoria-mcp"
|
|
95
|
+
fi
|
|
96
|
+
if [ -f "$BIN_DIR/memoreal-mcp" ]; then
|
|
97
|
+
rm -f "$BIN_DIR/memoreal-mcp"
|
|
98
|
+
fi
|
|
99
|
+
|
|
100
|
+
# --- Install memoreal-ns and memoria-ns helpers ---
|
|
101
|
+
if [ -f "$SCRIPT_DIR/bin/memoreal-ns" ]; then
|
|
102
|
+
cp "$SCRIPT_DIR/bin/memoreal-ns" "$BIN_DIR/memoreal-ns"
|
|
103
|
+
chmod +x "$BIN_DIR/memoreal-ns"
|
|
104
|
+
fi
|
|
105
|
+
if [ -f "$SCRIPT_DIR/bin/memoria-ns" ]; then
|
|
106
|
+
cp "$SCRIPT_DIR/bin/memoria-ns" "$BIN_DIR/memoria-ns"
|
|
107
|
+
chmod +x "$BIN_DIR/memoria-ns"
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
# --- Register MCP server (HTTP transport, shared across all Claude Code sessions) ---
|
|
111
|
+
echo ""
|
|
112
|
+
echo "Registering Cloud MCP server..."
|
|
113
|
+
|
|
114
|
+
if [ "${MEMOREAL_SKIP_CLAUDE_CLI:-${MEMORIA_SKIP_CLAUDE_CLI:-0}}" != "1" ] && command -v claude >/dev/null 2>&1; then
|
|
115
|
+
claude mcp remove -s user memoria 2>/dev/null || true
|
|
116
|
+
claude mcp remove -s user memoreal 2>/dev/null || true
|
|
117
|
+
if [ -n "$MEMOREAL_API_KEY" ]; then
|
|
118
|
+
claude mcp add -s user --transport http memoreal "$MEMOREAL_URL" --header "Authorization: Bearer $MEMOREAL_API_KEY"
|
|
119
|
+
else
|
|
120
|
+
claude mcp add -s user --transport http memoreal "$MEMOREAL_URL"
|
|
121
|
+
fi
|
|
122
|
+
echo " MCP registered (user scope, transport=http, url=$MEMOREAL_URL)"
|
|
123
|
+
else
|
|
124
|
+
echo " 'claude' CLI skipped or not found. Register manually:"
|
|
125
|
+
if [ -n "$MEMOREAL_API_KEY" ]; then
|
|
126
|
+
echo " claude mcp add -s user --transport http memoreal $MEMOREAL_URL --header \"Authorization: Bearer $MEMOREAL_API_KEY\""
|
|
127
|
+
else
|
|
128
|
+
echo " claude mcp add -s user --transport http memoreal $MEMOREAL_URL"
|
|
129
|
+
fi
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
# --- Install slash commands ---
|
|
133
|
+
echo ""
|
|
134
|
+
echo "Installing slash commands..."
|
|
135
|
+
mkdir -p "$COMMANDS_DIR" "$OPENCODE_DIR/commands"
|
|
136
|
+
|
|
137
|
+
for SKILL_DIR in "$SCRIPT_DIR/skills"/*/; do
|
|
138
|
+
SKILL_NAME="$(basename "$SKILL_DIR")"
|
|
139
|
+
if [ -f "$SKILL_DIR/SKILL.md" ]; then
|
|
140
|
+
cp "$SKILL_DIR/SKILL.md" "$COMMANDS_DIR/$SKILL_NAME.md"
|
|
141
|
+
cp "$SKILL_DIR/SKILL.md" "$OPENCODE_DIR/commands/$SKILL_NAME.md"
|
|
142
|
+
echo " /$SKILL_NAME (Claude Code & OpenCode)"
|
|
143
|
+
fi
|
|
144
|
+
done
|
|
145
|
+
|
|
146
|
+
# --- Install hooks ---
|
|
147
|
+
echo ""
|
|
148
|
+
echo "Installing hooks..."
|
|
149
|
+
HOOKS_JSON="$SCRIPT_DIR/hooks/hooks.json"
|
|
150
|
+
|
|
151
|
+
if command -v jq >/dev/null 2>&1 && [ -f "$HOOKS_JSON" ]; then
|
|
152
|
+
if [ -f "$SETTINGS_JSON" ]; then
|
|
153
|
+
cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
|
|
154
|
+
jq --slurpfile plugin_hooks "$HOOKS_JSON" '
|
|
155
|
+
.hooks //= {} |
|
|
156
|
+
reduce ($plugin_hooks[0].hooks | to_entries[]) as $entry (
|
|
157
|
+
.;
|
|
158
|
+
.hooks[$entry.key] = (
|
|
159
|
+
[(.hooks[$entry.key] // [])[] | select(
|
|
160
|
+
(.hooks | tostring | test("\\[(memoreal|memoria)[\\]-]")) | not
|
|
161
|
+
)] + $entry.value
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
|
|
165
|
+
echo " Hooks merged into $SETTINGS_JSON"
|
|
166
|
+
else
|
|
167
|
+
mkdir -p "$(dirname "$SETTINGS_JSON")"
|
|
168
|
+
jq --slurpfile plugin_hooks "$HOOKS_JSON" -n '{ hooks: $plugin_hooks[0].hooks }' > "$SETTINGS_JSON"
|
|
169
|
+
echo " Created $SETTINGS_JSON with hooks"
|
|
170
|
+
fi
|
|
171
|
+
else
|
|
172
|
+
echo " Warning: jq not found, skipping hook installation"
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# --- Install CLAUDE.md and OpenCode AGENTS.md instructions ---
|
|
176
|
+
echo ""
|
|
177
|
+
echo "Installing memory instructions..."
|
|
178
|
+
GLOBAL_CLAUDE_MD="$HOME/.claude/CLAUDE.md"
|
|
179
|
+
OPENCODE_AGENTS_MD="$OPENCODE_DIR/AGENTS.md"
|
|
180
|
+
MEMOREAL_CLAUDE_MD="$SCRIPT_DIR/CLAUDE.md"
|
|
181
|
+
|
|
182
|
+
upsert_memoreal_instructions() {
|
|
183
|
+
local TARGET_MD="$1"
|
|
184
|
+
if [ -f "$TARGET_MD" ]; then
|
|
185
|
+
cp "$TARGET_MD" "$TARGET_MD.bak"
|
|
186
|
+
if grep -q '<!-- memoreal:start -->' "$TARGET_MD"; then
|
|
187
|
+
sed '/<!-- memoreal:start -->/,/<!-- memoreal:end -->/d' "$TARGET_MD.bak" > "$TARGET_MD"
|
|
188
|
+
elif grep -q '<!-- memoria:start -->' "$TARGET_MD"; then
|
|
189
|
+
sed '/<!-- memoria:start -->/,/<!-- memoria:end -->/d' "$TARGET_MD.bak" > "$TARGET_MD"
|
|
190
|
+
fi
|
|
191
|
+
echo "" >> "$TARGET_MD"
|
|
192
|
+
cat "$MEMOREAL_CLAUDE_MD" >> "$TARGET_MD"
|
|
193
|
+
echo " Updated $TARGET_MD"
|
|
194
|
+
else
|
|
195
|
+
mkdir -p "$(dirname "$TARGET_MD")"
|
|
196
|
+
cp "$MEMOREAL_CLAUDE_MD" "$TARGET_MD"
|
|
197
|
+
echo " Created $TARGET_MD"
|
|
198
|
+
fi
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if [ -f "$MEMOREAL_CLAUDE_MD" ]; then
|
|
202
|
+
upsert_memoreal_instructions "$GLOBAL_CLAUDE_MD"
|
|
203
|
+
upsert_memoreal_instructions "$OPENCODE_AGENTS_MD"
|
|
204
|
+
upsert_memoreal_instructions "$HOME/.codex/AGENTS.md"
|
|
205
|
+
fi
|
|
206
|
+
|
|
207
|
+
# --- Install OpenCode plugin & MCP config ---
|
|
208
|
+
echo ""
|
|
209
|
+
echo "Installing OpenCode plugin & MCP configuration..."
|
|
210
|
+
mkdir -p "$OPENCODE_DIR/plugins"
|
|
211
|
+
if [ -f "$SCRIPT_DIR/opencode/memoreal-hooks.js" ]; then
|
|
212
|
+
cp "$SCRIPT_DIR/opencode/memoreal-hooks.js" "$OPENCODE_DIR/plugins/memoreal-hooks.js"
|
|
213
|
+
echo " Installed $OPENCODE_DIR/plugins/memoreal-hooks.js"
|
|
214
|
+
fi
|
|
215
|
+
if [ -f "$SCRIPT_DIR/opencode/memoria-hooks.js" ]; then
|
|
216
|
+
cp "$SCRIPT_DIR/opencode/memoria-hooks.js" "$OPENCODE_DIR/plugins/memoria-hooks.js"
|
|
217
|
+
echo " Installed $OPENCODE_DIR/plugins/memoria-hooks.js"
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
if command -v jq >/dev/null 2>&1; then
|
|
221
|
+
if [ -f "$OPENCODE_JSON" ]; then
|
|
222
|
+
cp "$OPENCODE_JSON" "$OPENCODE_JSON.bak"
|
|
223
|
+
jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
|
|
224
|
+
.mcp //= {} |
|
|
225
|
+
.mcp.memoreal = ((.mcp.memoreal // {}) + { "type": "remote", "url": $url, "enabled": true } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
226
|
+
' "$OPENCODE_JSON.bak" > "$OPENCODE_JSON"
|
|
227
|
+
chmod 600 "$OPENCODE_JSON" 2>/dev/null || true
|
|
228
|
+
echo " Updated MCP server in $OPENCODE_JSON"
|
|
229
|
+
else
|
|
230
|
+
jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
|
|
231
|
+
"$schema": "https://opencode.ai/config.json",
|
|
232
|
+
"mcp": {
|
|
233
|
+
"memoreal": ({
|
|
234
|
+
"type": "remote",
|
|
235
|
+
"url": $url,
|
|
236
|
+
"enabled": true
|
|
237
|
+
} + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
238
|
+
}
|
|
239
|
+
}' > "$OPENCODE_JSON"
|
|
240
|
+
chmod 600 "$OPENCODE_JSON" 2>/dev/null || true
|
|
241
|
+
echo " Created $OPENCODE_JSON with Memoreal Cloud MCP"
|
|
242
|
+
fi
|
|
243
|
+
|
|
244
|
+
upsert_mcp_servers_json() {
|
|
245
|
+
local TARGET_JSON="$1"
|
|
246
|
+
local LABEL="$2"
|
|
247
|
+
mkdir -p "$(dirname "$TARGET_JSON")"
|
|
248
|
+
if [ -f "$TARGET_JSON" ]; then
|
|
249
|
+
cp "$TARGET_JSON" "$TARGET_JSON.bak"
|
|
250
|
+
jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
|
|
251
|
+
.mcpServers //= {} |
|
|
252
|
+
.mcpServers.memoreal = ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
253
|
+
' "$TARGET_JSON.bak" > "$TARGET_JSON"
|
|
254
|
+
chmod 600 "$TARGET_JSON" 2>/dev/null || true
|
|
255
|
+
echo " Updated $LABEL MCP config in $TARGET_JSON"
|
|
256
|
+
else
|
|
257
|
+
jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
|
|
258
|
+
"mcpServers": {
|
|
259
|
+
"memoreal": ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
260
|
+
}
|
|
261
|
+
}' > "$TARGET_JSON"
|
|
262
|
+
chmod 600 "$TARGET_JSON" 2>/dev/null || true
|
|
263
|
+
echo " Configured $LABEL MCP in $TARGET_JSON"
|
|
264
|
+
fi
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
upsert_mcp_servers_json "$HOME/.cursor/mcp.json" "Cursor"
|
|
268
|
+
upsert_mcp_servers_json "$HOME/.codeium/windsurf/mcp_config.json" "Windsurf"
|
|
269
|
+
upsert_mcp_servers_json "$HOME/.codex/mcp.json" "OpenAI Codex CLI"
|
|
270
|
+
upsert_mcp_servers_json "$HOME/.gemini/settings.json" "Gemini CLI"
|
|
271
|
+
upsert_mcp_servers_json "$HOME/.vscode/mcp.json" "VS Code / GitHub Copilot"
|
|
272
|
+
upsert_mcp_servers_json "$HOME/.cline/mcp_settings.json" "Cline"
|
|
273
|
+
upsert_mcp_servers_json "$HOME/.roo/mcp.json" "Roo Code"
|
|
274
|
+
upsert_mcp_servers_json "$HOME/.kilocode/mcp.json" "Kilo Code"
|
|
275
|
+
upsert_mcp_servers_json "$HOME/.continue/mcpServers/memoreal.json" "Continue.dev"
|
|
276
|
+
upsert_mcp_servers_json "$HOME/.config/goose/mcp.json" "Goose"
|
|
277
|
+
upsert_mcp_servers_json "$HOME/.config/amp/settings.json" "Amp"
|
|
278
|
+
|
|
279
|
+
# Zed uses .context_servers.memoreal
|
|
280
|
+
ZED_SETTINGS="$HOME/.config/zed/settings.json"
|
|
281
|
+
mkdir -p "$(dirname "$ZED_SETTINGS")"
|
|
282
|
+
if [ -f "$ZED_SETTINGS" ]; then
|
|
283
|
+
cp "$ZED_SETTINGS" "$ZED_SETTINGS.bak"
|
|
284
|
+
jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
|
|
285
|
+
.context_servers //= {} |
|
|
286
|
+
.context_servers.memoreal = ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
287
|
+
' "$ZED_SETTINGS.bak" > "$ZED_SETTINGS" 2>/dev/null || cp "$ZED_SETTINGS.bak" "$ZED_SETTINGS"
|
|
288
|
+
chmod 600 "$ZED_SETTINGS" 2>/dev/null || true
|
|
289
|
+
echo " Updated Zed MCP config in $ZED_SETTINGS"
|
|
290
|
+
else
|
|
291
|
+
jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
|
|
292
|
+
"context_servers": {
|
|
293
|
+
"memoreal": ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
|
|
294
|
+
}
|
|
295
|
+
}' > "$ZED_SETTINGS"
|
|
296
|
+
chmod 600 "$ZED_SETTINGS" 2>/dev/null || true
|
|
297
|
+
echo " Configured Zed MCP in $ZED_SETTINGS"
|
|
298
|
+
fi
|
|
299
|
+
|
|
300
|
+
if [ "$(uname -s 2>/dev/null || echo '')" = "Darwin" ]; then
|
|
301
|
+
upsert_mcp_servers_json "$HOME/Library/Application Support/Claude/claude_desktop_config.json" "Claude Desktop"
|
|
302
|
+
else
|
|
303
|
+
upsert_mcp_servers_json "$HOME/.config/Claude/claude_desktop_config.json" "Claude Desktop"
|
|
304
|
+
fi
|
|
305
|
+
fi
|
|
306
|
+
|
|
307
|
+
# --- Clean up stale config from old installs ---
|
|
308
|
+
STALE_MCP="$HOME/.claude/.mcp.json"
|
|
309
|
+
if [ -f "$STALE_MCP" ] && command -v jq >/dev/null 2>&1; then
|
|
310
|
+
if jq -e '.mcpServers.memoria // .mcpServers.memoreal' "$STALE_MCP" >/dev/null 2>&1; then
|
|
311
|
+
jq 'del(.mcpServers.memoria) | del(.mcpServers.memoreal) | if .mcpServers == {} then del(.mcpServers) else . end' "$STALE_MCP" > "$STALE_MCP.tmp"
|
|
312
|
+
if [ "$(jq 'length' "$STALE_MCP.tmp" 2>/dev/null)" = "0" ]; then
|
|
313
|
+
rm -f "$STALE_MCP" "$STALE_MCP.tmp"
|
|
314
|
+
else
|
|
315
|
+
mv "$STALE_MCP.tmp" "$STALE_MCP"
|
|
316
|
+
fi
|
|
317
|
+
echo " Cleaned stale .mcp.json"
|
|
318
|
+
fi
|
|
319
|
+
fi
|
|
320
|
+
|
|
321
|
+
if [ -f "$SETTINGS_JSON" ] && command -v jq >/dev/null 2>&1; then
|
|
322
|
+
if jq -e '.mcpServers.memoria' "$SETTINGS_JSON" >/dev/null 2>&1; then
|
|
323
|
+
cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
|
|
324
|
+
jq 'del(.mcpServers.memoria)' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
|
|
325
|
+
echo " Cleaned stale mcpServers from settings"
|
|
326
|
+
fi
|
|
327
|
+
if jq -e '.enabledPlugins["memoria@local-plugins"]' "$SETTINGS_JSON" >/dev/null 2>&1; then
|
|
328
|
+
jq 'del(.enabledPlugins["memoria@local-plugins"])' "$SETTINGS_JSON" > "$SETTINGS_JSON.tmp" \
|
|
329
|
+
&& mv "$SETTINGS_JSON.tmp" "$SETTINGS_JSON"
|
|
330
|
+
fi
|
|
331
|
+
fi
|
|
332
|
+
|
|
333
|
+
# --- Done ---
|
|
334
|
+
echo ""
|
|
335
|
+
echo "============================="
|
|
336
|
+
echo "Plugin installed (Cloud API)."
|
|
337
|
+
echo ""
|
|
338
|
+
echo " Cloud API: $MEMOREAL_API_URL"
|
|
339
|
+
echo " Cloud MCP: $MEMOREAL_URL"
|
|
340
|
+
echo " Clients: Claude Code, Cursor, Windsurf, OpenCode, Claude Desktop, Codex CLI, Gemini CLI, VS Code, Zed, Cline, Roo Code, Kilo Code, Continue, Goose, Amp"
|
|
341
|
+
echo " Config: $CONFIG_ENV (fallback: $LEGACY_CONFIG_ENV)"
|
|
342
|
+
echo " Hooks: $SETTINGS_JSON & $OPENCODE_DIR/plugins/memoreal-hooks.js"
|
|
343
|
+
echo " Commands: /memoreal-sync, /memoreal-sync-code, /memoreal-wrap-up, /memoreal-doctor (aliases: /memoria-*)"
|
|
344
|
+
echo ""
|
|
345
|
+
echo "Restart your AI coding client to activate."
|
|
346
|
+
echo ""
|
package/manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": "0.1",
|
|
3
|
+
"name": "memoreal-mcp",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "Official Node.js MCP connector for Memoreal Cloud (https://memoreal.kolivri.com).",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Kolivri",
|
|
8
|
+
"url": "https://memoreal.kolivri.com"
|
|
9
|
+
},
|
|
10
|
+
"server": {
|
|
11
|
+
"type": "node",
|
|
12
|
+
"entry_point": "src/server.mjs",
|
|
13
|
+
"mcp_config": {
|
|
14
|
+
"command": "node",
|
|
15
|
+
"args": ["${__dirname}/src/server.mjs"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|