@everme/claude-code 0.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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "mcpServers": {
3
+ "everme": {
4
+ "command": "node",
5
+ "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/scripts/mcp-server.js"],
6
+ "env": {}
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "everme",
3
+ "owner": {
4
+ "name": "EverMind AI",
5
+ "email": "support@evermind.ai",
6
+ "url": "https://everme.evermind.ai"
7
+ },
8
+ "plugins": [
9
+ {
10
+ "name": "everme",
11
+ "source": "./",
12
+ "description": "Automatic memory recall for Claude Code through the EverMe gateway. Saves and recalls per-session context using your EverMe account credentials.",
13
+ "version": "0.1.0",
14
+ "homepage": "https://everme.evermind.ai",
15
+ "license": "Apache-2.0"
16
+ }
17
+ ]
18
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Evermind AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # EverMe — Claude Code plugin
2
+
3
+ Automatic memory recall + persistence for Claude Code, backed by the EverMe gateway.
4
+
5
+ ## What it does
6
+
7
+ - **SessionStart** → loads recent context (profile + episodes) from past sessions and injects it as `additionalContext` for the model + a one-line `🧠 EverMe loaded N memory items` system message for you.
8
+ - **UserPromptSubmit** → searches your memory for content relevant to the prompt you just typed and injects it BEFORE the model sees the prompt. Silent when no relevant hit (no nag).
9
+ - **Stop** → after each Claude reply, persists the just-finished raw turn (including tool calls/results) to `/mem/agent-memory`.
10
+ - **SessionEnd** → no persistence; Stop owns runtime writes so Claude Code does not create `/mem/sources`.
11
+
12
+ Plus:
13
+
14
+ - **MCP server** exposing `everme_search` + `everme_context` tools for explicit recall.
15
+ - **Slash commands** `/recall <q>` and `/everme-help`.
16
+ - **Skill** (`memory-tools`) that tells Claude when/how to use the search tool.
17
+
18
+ ## Architecture (vs. the standalone `@everme/memory-mcp`)
19
+
20
+ | | `@everme/memory-mcp` (existing) | `@everme/claude-code` (this plugin) |
21
+ |---|---|---|
22
+ | Format | Generic MCP server | Claude Code plugin (hooks + commands + skill + MCP) |
23
+ | Recall trigger | User must call MCP tool manually | Automatic on every UserPromptSubmit |
24
+ | Save trigger | Buffer flushes by turn-count or byte threshold | Every Stop event via realtime agent memory |
25
+ | Auth | `EVERME_AGENT_TOKEN` (evt) | Recall supports `EVERME_API_KEY` or `EVERME_AGENT_TOKEN`; realtime writes require `EVERME_AGENT_TOKEN` + `EVERME_AGENT_ID` |
26
+ | Backend | EverMe gateway (`/api/v1/mem/*`) | Same — runtime writes use `/mem/agent-memory`, not `/mem/sources` |
27
+
28
+ Both plugins share the gateway, so memory written by one is visible to the other.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ ./install.sh
34
+ ```
35
+
36
+ The installer:
37
+
38
+ 1. Verifies `claude` CLI and Node 18+ are present.
39
+ 2. Prompts for `EVERME_API_KEY` (an `emk_*`) if not in the environment, persists to your shell profile.
40
+ 3. Runs `claude plugin install <this-dir>` so Claude Code wires hooks + commands + MCP.
41
+
42
+ ## Manual install
43
+
44
+ ```bash
45
+ export EVERME_API_KEY="emk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # from EverMe Web UI
46
+ export EVERME_API_BASE="http://localhost:8080" # optional — defaults to everme.evermind.ai
47
+ claude plugin install /path/to/everme/plugins/claude-code
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ | Env var | Purpose |
53
+ |---|---|
54
+ | `EVERME_API_KEY` | Account-level emk. Supports recall-only mode. |
55
+ | `EVERME_AGENT_TOKEN` | Per-machine evt — written by `evercli plugin install claude-code`. Required for realtime writes and wins over emk when both are set. |
56
+ | `EVERME_AGENT_ID` | Required with `EVERME_AGENT_TOKEN` for realtime writes; also pins recall to a specific cloud agent. |
57
+ | `EVERME_API_BASE` | Gateway host. Defaults to `https://everme.evermind.ai`. Set to `http://localhost:8080` for local dev. |
58
+ | `EVERME_DEBUG` | `1` to print hook traces to stderr (with token redaction). |
59
+
60
+ ## Verifying the install
61
+
62
+ In a new Claude Code session:
63
+
64
+ ```
65
+ /everme-help
66
+ ```
67
+
68
+ …should print the cheatsheet. Then:
69
+
70
+ ```
71
+ /recall the postgres composite index decision
72
+ ```
73
+
74
+ …should call `everme_search`, summarise hits, and cite memory subjects.
75
+
76
+ ## Files
77
+
78
+ ```
79
+ plugin.json plugin metadata
80
+ .claude-plugin/.mcp.json MCP server registration
81
+ .claude-plugin/marketplace.json marketplace listing
82
+ hooks/hooks.json SessionStart / UserPromptSubmit / Stop / SessionEnd wiring
83
+ hooks/scripts/inject-memories.js UserPromptSubmit handler
84
+ hooks/scripts/store-memories.js Stop handler
85
+ hooks/scripts/session-start.js SessionStart handler
86
+ hooks/scripts/session-summary.js SessionEnd handler
87
+ hooks/scripts/mcp-server.js MCP server (everme_search / everme_context tools)
88
+ hooks/scripts/lib/api.js Gateway HTTP client (agent-memory, search, context)
89
+ hooks/scripts/lib/config.js Env-var resolution (emk vs evt)
90
+ hooks/scripts/lib/transcript.js Claude Code transcript JSONL reader
91
+ hooks/scripts/lib/redact.js evt/emk/X-Amz-Signature scrub for logs
92
+ commands/recall.md /recall slash command
93
+ commands/everme-help.md /everme-help slash command
94
+ skills/memory-tools.md always-injected skill — tells Claude how to use the tools
95
+ install.sh bash installer
96
+ ```
97
+
98
+ ## License
99
+
100
+ Apache-2.0
@@ -0,0 +1,31 @@
1
+ ---
2
+ description: Print a concise EverMe plugin status + reference card.
3
+ ---
4
+
5
+ # EverMe · help
6
+
7
+ Print the following block verbatim to the user:
8
+
9
+ ```
10
+ EverMe for Claude Code
11
+ ─────────────────────
12
+ Auth: EVERME_API_KEY (account emk_*) — recall-only mode
13
+ EVERME_AGENT_TOKEN + EVERME_AGENT_ID — required for realtime writes
14
+ Gateway: EVERME_API_BASE — defaults to https://everme.evermind.ai
15
+
16
+ Hooks:
17
+ SessionStart → loads recent context from past sessions
18
+ UserPromptSubmit → recalls relevant memories before each prompt
19
+ Stop → saves the last raw turn through /mem/agent-memory
20
+ SessionEnd → no persistence; Stop owns runtime writes
21
+
22
+ Slash:
23
+ /recall <query> — explicit search + summarize
24
+ /everme-help — this card
25
+
26
+ MCP tools:
27
+ everme_search — ranked search
28
+ everme_context — server-rendered context block
29
+
30
+ Tip: Set EVERME_DEBUG=1 to see hook traces on stderr.
31
+ ```
@@ -0,0 +1,26 @@
1
+ ---
2
+ description: Recall relevant EverMe memories from past sessions and use them as context for the current task.
3
+ arguments:
4
+ - name: query
5
+ description: What to look up — keywords, topic, or a question.
6
+ required: true
7
+ ---
8
+
9
+ # EverMe · recall
10
+
11
+ You have access to two MCP tools backed by the EverMe gateway:
12
+
13
+ - `everme_search` — ranked search with subject + summary + score.
14
+ - `everme_context` — server-rendered context block (profile + recent episodes).
15
+
16
+ ## Query
17
+
18
+ {{query}}
19
+
20
+ ## Instructions
21
+
22
+ 1. Call `everme_search` with the query. Start with `topK: 10`.
23
+ 2. If the top results are clearly relevant (score ≥ 0.3), summarize the matched memories briefly and use them to answer or guide the next action.
24
+ 3. If results are weak or empty, retry once with broader keywords. If still nothing useful, say so explicitly — do not fabricate context.
25
+ 4. When citing a memory, mention its subject (or session id) so the user can trace it back via `evercli` or the EverMe Web UI.
26
+ 5. NEVER paste the entire raw memory body verbatim if it's long; quote the salient parts only.
@@ -0,0 +1,52 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "*",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-start.js",
10
+ "timeout": 30
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "UserPromptSubmit": [
16
+ {
17
+ "matcher": "*",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/inject-memories.js",
22
+ "timeout": 10
23
+ }
24
+ ]
25
+ }
26
+ ],
27
+ "Stop": [
28
+ {
29
+ "matcher": "*",
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/store-memories.js",
34
+ "timeout": 30
35
+ }
36
+ ]
37
+ }
38
+ ],
39
+ "SessionEnd": [
40
+ {
41
+ "matcher": "*",
42
+ "hooks": [
43
+ {
44
+ "type": "command",
45
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/session-summary.js",
46
+ "timeout": 30
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+ }
52
+ }
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UserPromptSubmit hook — recall relevant memories and inject them
4
+ * into Claude's context BEFORE it sees the user's prompt.
5
+ *
6
+ * Hook contract (from Claude Code):
7
+ * stdin = JSON { prompt, transcript_path, cwd, ... }
8
+ * stdout = JSON {
9
+ * systemMessage: "...", // shown to user inline
10
+ * hookSpecificOutput: {
11
+ * hookEventName: "UserPromptSubmit",
12
+ * additionalContext: "..." // injected for the model only
13
+ * }
14
+ * }
15
+ *
16
+ * On any error or "no relevant memories" we exit 0 silently — never
17
+ * block the user's prompt on a memory backend hiccup.
18
+ */
19
+
20
+ process.on("uncaughtException", () => process.exit(0));
21
+ process.on("unhandledRejection", () => process.exit(0));
22
+
23
+ import { buildMemoryPrompt } from "@everme/agent-sdk";
24
+ import { isConfigured } from "./lib/config.js";
25
+ import { searchMemories } from "./lib/api.js";
26
+ import { redactError, debug } from "./lib/redact.js";
27
+
28
+ const MIN_PROMPT_WORDS = 3;
29
+ const TOP_K = 5;
30
+ const MIN_SCORE = 0.1;
31
+
32
+ async function main() {
33
+ const data = await readStdinJSON();
34
+ const prompt = String(data?.prompt || "");
35
+ if (!isConfigured()) {
36
+ debug("inject", "skip: not configured");
37
+ return process.exit(0);
38
+ }
39
+ if (countTokens(prompt) < MIN_PROMPT_WORDS) {
40
+ debug("inject", "skip: prompt too short");
41
+ return process.exit(0);
42
+ }
43
+
44
+ // /mem/search with the gateway's default memoryTypes returns episodes
45
+ // + profiles + raw_messages + agent_memory in a single call, ranked
46
+ // by query relevance. That's strictly more than /mem/context (a
47
+ // queryless full-profile snapshot) — context is kept for SessionStart
48
+ // where there is no prompt, but per-turn inject goes through search.
49
+ let block = "";
50
+ let count = 0;
51
+ try {
52
+ const res = await searchMemories(prompt, { topK: TOP_K });
53
+ // EverOS frequently returns score=null on episodic hits (decoded as
54
+ // 0 over the wire) — that's "unscored", not "score zero". Treat
55
+ // 0/null as unscored and keep the row; only drop rows with an
56
+ // explicit positive score below the threshold.
57
+ const filteredMemories = (res?.memories || []).filter((m) => {
58
+ const s = m?.score ?? m?.relevanceScore;
59
+ return s == null || s === 0 || s >= MIN_SCORE;
60
+ });
61
+ const bundle = {
62
+ memories: filteredMemories,
63
+ profiles: res?.profiles || [],
64
+ rawMessages: res?.rawMessages || [],
65
+ agentMemory: res?.agentMemory || { cases: [], skills: [] },
66
+ };
67
+ count =
68
+ filteredMemories.length +
69
+ bundle.profiles.length +
70
+ (bundle.agentMemory.cases?.length || 0) +
71
+ (bundle.agentMemory.skills?.length || 0) +
72
+ bundle.rawMessages.length;
73
+ // Reuse the SDK renderer so Claude Code and OpenClaw inject the
74
+ // same sectioned shape. wrapInCodeBlock=false because Claude Code
75
+ // wraps the body in an <everme_recall> envelope below — fenced
76
+ // markdown nested in XML reads worse than the bare section list.
77
+ const inner = buildMemoryPrompt(bundle, { wrapInCodeBlock: false });
78
+ if (inner) block = `<everme_recall>\n${inner}\n</everme_recall>`;
79
+ } catch (err) {
80
+ debug("inject", "search failed:", redactError(err?.message));
81
+ }
82
+
83
+ if (!block || count === 0) {
84
+ debug("inject", "no memories above threshold");
85
+ return process.exit(0);
86
+ }
87
+
88
+ const systemMessage = `🧠 Recalling ${count} relevant ${count === 1 ? "memory" : "memories"} from EverMe`;
89
+ const out = {
90
+ systemMessage,
91
+ hookSpecificOutput: {
92
+ hookEventName: "UserPromptSubmit",
93
+ additionalContext: block,
94
+ },
95
+ };
96
+ process.stdout.write(JSON.stringify(out));
97
+ process.exit(0);
98
+ }
99
+
100
+ // Multilingual rough word count (CJK characters count individually,
101
+ // other languages by whitespace tokens). Mirrors the reference
102
+ // plugin's heuristic so users get the same min-prompt feel.
103
+ function countTokens(text) {
104
+ if (!text) return 0;
105
+ const cjkRe = /[一-鿿㐀-䶿぀-ゟ゠-ヿ가-힯]/g;
106
+ const cjk = (text.match(cjkRe) || []).length;
107
+ const ascii = text
108
+ .replace(cjkRe, " ")
109
+ .split(/\s+/)
110
+ .filter(Boolean).length;
111
+ return cjk + ascii;
112
+ }
113
+
114
+ async function readStdinJSON() {
115
+ const chunks = [];
116
+ for await (const c of process.stdin) chunks.push(c);
117
+ const raw = Buffer.concat(chunks).toString("utf8");
118
+ if (!raw) return {};
119
+ try {
120
+ return JSON.parse(raw);
121
+ } catch {
122
+ return {};
123
+ }
124
+ }
125
+
126
+ main();
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Thin wrapper around `@everme/agent-sdk` for the Claude Code hooks.
3
+ *
4
+ * Why this file still exists:
5
+ * - The hooks call `searchMemories(query, { topK })` / `getContext` /
6
+ * `saveAgentMemory` against an SDK-managed client created from our config.
7
+ * Centralising the client construction here keeps each hook script short.
8
+ * - Re-exports keep the rest of the codebase (and tests) stable —
9
+ * a future SDK rename would only land here.
10
+ */
11
+
12
+ import {
13
+ createClient,
14
+ searchMemory as sdkSearchMemory,
15
+ saveAgentMemory as sdkSaveAgentMemory,
16
+ EvermeError,
17
+ } from "@everme/agent-sdk";
18
+ import { getConfig } from "./config.js";
19
+
20
+ let _client = null;
21
+
22
+ function getClient() {
23
+ if (_client) return _client;
24
+ _client = createClient(getConfig());
25
+ return _client;
26
+ }
27
+
28
+ export async function searchMemories(query, opts = {}) {
29
+ // agent is bound from the MemAuth token; no agentId in the body.
30
+ return sdkSearchMemory(getClient(), { query, ...opts });
31
+ }
32
+
33
+ /**
34
+ * Direct POST /mem/context that returns the gateway's raw shape
35
+ * {profile, cachedAt, generatedAt}. The hooks render `profile`
36
+ * themselves (see inject-memories.js / session-start.js's
37
+ * renderProfileBlock). The SDK's `getContext` is too opinionated for
38
+ * our needs (it extracts a server-rendered .context string the
39
+ * gateway doesn't currently produce), so we bypass it and call the
40
+ * client directly.
41
+ *
42
+ * Body is `{ forceRefresh: bool }` only — the agent is bound from
43
+ * the MemAuth token, so `query`/`topK` are no longer forwarded.
44
+ */
45
+ export async function getContext(_query, opts = {}) {
46
+ const body = opts.forceRefresh ? { forceRefresh: true } : {};
47
+ return getClient().request("POST", "/mem/context", body);
48
+ }
49
+
50
+ export async function saveAgentMemory(req, log) {
51
+ return sdkSaveAgentMemory(getClient(), req, log);
52
+ }
53
+
54
+ export { EvermeError };