@scitrera/memorylayer-cc-plugin 0.0.5 → 0.2.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.
- package/LICENSE +177 -0
- package/README.md +11 -4
- package/dist/bin/memorylayer-hook.js +27 -9
- package/dist/bin/memorylayer-hook.js.map +1 -1
- package/dist/src/hooks/client.d.ts +21 -0
- package/dist/src/hooks/client.d.ts.map +1 -0
- package/dist/src/hooks/client.js +57 -0
- package/dist/src/hooks/client.js.map +1 -0
- package/dist/src/hooks/formatters.d.ts +33 -0
- package/dist/src/hooks/formatters.d.ts.map +1 -0
- package/dist/src/hooks/formatters.js +187 -0
- package/dist/src/hooks/formatters.js.map +1 -0
- package/dist/src/hooks/handlers/post-tool.d.ts +10 -0
- package/dist/src/hooks/handlers/post-tool.d.ts.map +1 -0
- package/dist/src/hooks/handlers/post-tool.js +98 -0
- package/dist/src/hooks/handlers/post-tool.js.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts +5 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.js +117 -0
- package/dist/src/hooks/handlers/pre-compact.js.map +1 -0
- package/dist/src/hooks/handlers/pre-tool.d.ts +10 -0
- package/dist/src/hooks/handlers/pre-tool.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-tool.js +114 -0
- package/dist/src/hooks/handlers/pre-tool.js.map +1 -0
- package/dist/src/hooks/handlers/session-start.d.ts +10 -0
- package/dist/src/hooks/handlers/session-start.d.ts.map +1 -0
- package/dist/src/hooks/handlers/session-start.js +111 -0
- package/dist/src/hooks/handlers/session-start.js.map +1 -0
- package/dist/src/hooks/handlers/stop.d.ts +14 -0
- package/dist/src/hooks/handlers/stop.d.ts.map +1 -0
- package/dist/src/hooks/handlers/stop.js +49 -0
- package/dist/src/hooks/handlers/stop.js.map +1 -0
- package/dist/src/hooks/handlers/user-prompt.d.ts +10 -0
- package/dist/src/hooks/handlers/user-prompt.d.ts.map +1 -0
- package/dist/src/hooks/handlers/user-prompt.js +128 -0
- package/dist/src/hooks/handlers/user-prompt.js.map +1 -0
- package/dist/src/hooks/index.d.ts +18 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +23 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/observation.d.ts +59 -0
- package/dist/src/hooks/observation.d.ts.map +1 -0
- package/dist/src/hooks/observation.js +421 -0
- package/dist/src/hooks/observation.js.map +1 -0
- package/dist/src/hooks/state.d.ts +73 -0
- package/dist/src/hooks/state.d.ts.map +1 -0
- package/dist/src/hooks/state.js +168 -0
- package/dist/src/hooks/state.js.map +1 -0
- package/dist/src/hooks/types.d.ts +86 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +14 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/package.json +15 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -57,6 +57,9 @@ Set environment variables to customize:
|
|
|
57
57
|
# Custom server URL
|
|
58
58
|
export MEMORYLAYER_URL="http://your-server:61001"
|
|
59
59
|
|
|
60
|
+
# Optional API key for secured MemoryLayer deployments
|
|
61
|
+
export MEMORYLAYER_API_KEY="ml_..."
|
|
62
|
+
|
|
60
63
|
# Custom workspace (default: auto-detected from git repo)
|
|
61
64
|
export MEMORYLAYER_WORKSPACE_ID="my-project"
|
|
62
65
|
|
|
@@ -68,7 +71,7 @@ export MEMORYLAYER_SESSION_MODE="false"
|
|
|
68
71
|
|
|
69
72
|
### MCP Server
|
|
70
73
|
|
|
71
|
-
The plugin configures the `@scitrera/memorylayer-mcp-server`
|
|
74
|
+
The plugin configures the `@scitrera/memorylayer-mcp-server` through `.mcp.json`. It forwards `MEMORYLAYER_URL`, `MEMORYLAYER_API_KEY`, and `MEMORYLAYER_WORKSPACE_ID` from the environment when present. The MCP server provides these tools:
|
|
72
75
|
|
|
73
76
|
#### Core Memory Tools
|
|
74
77
|
|
|
@@ -123,8 +126,8 @@ Working memory persists within a session and survives context compaction. At ses
|
|
|
123
126
|
|
|
124
127
|
| Hook | Trigger | Behavior |
|
|
125
128
|
|------|---------|----------|
|
|
126
|
-
| `PreCompact` | Before context compaction |
|
|
127
|
-
| `SessionStart` | Session begins |
|
|
129
|
+
| `PreCompact` | Before context compaction | Durably uploads only new raw transcript bytes, then commits working memory and checkpoints sandbox state; failures are reported but do not block compaction |
|
|
130
|
+
| `SessionStart` | Session begins | Starts the server session and loads one bounded context pack; older servers use the briefing/recall compatibility path |
|
|
128
131
|
| `Stop` | Session ends | Commits working memory to long-term storage and ends the server session |
|
|
129
132
|
| `PreToolUse` | Before Task/Edit/Write | Injects recalled context relevant to the operation (query-aware dedup) |
|
|
130
133
|
| `PostToolUse` | After Bash/Edit/Write/Task | Captures outcomes (commit summaries, file changes, new file creation, agent results) |
|
|
@@ -149,7 +152,7 @@ With MemoryLayer:
|
|
|
149
152
|
↓ context window full
|
|
150
153
|
[PreCompact hook fires]
|
|
151
154
|
↓
|
|
152
|
-
[
|
|
155
|
+
[Command hook stores the exact new transcript segment before derived indexing]
|
|
153
156
|
↓
|
|
154
157
|
[COMPACTION - history truncated]
|
|
155
158
|
↓
|
|
@@ -189,6 +192,10 @@ You can always ask Claude directly:
|
|
|
189
192
|
- **0.5-0.6** - General knowledge, minor features
|
|
190
193
|
- **0.3-0.4** - Temporary notes
|
|
191
194
|
|
|
195
|
+
## Codex
|
|
196
|
+
|
|
197
|
+
A matching Codex plugin now lives at `../memorylayer-codex-plugin`. It reuses the same `memorylayer-mcp` command and environment variables, with Codex-specific guidance delivered as a skill instead of Claude Code hooks.
|
|
198
|
+
|
|
192
199
|
## Troubleshooting
|
|
193
200
|
|
|
194
201
|
### MCP Server Not Connecting
|
|
@@ -25,6 +25,7 @@ import { handleUserPromptSubmit } from "../src/hooks/handlers/user-prompt.js";
|
|
|
25
25
|
import { handlePreToolUse } from "../src/hooks/handlers/pre-tool.js";
|
|
26
26
|
import { handlePostToolUse } from "../src/hooks/handlers/post-tool.js";
|
|
27
27
|
import { handleStop } from "../src/hooks/handlers/stop.js";
|
|
28
|
+
import { handlePreCompact } from "../src/hooks/handlers/pre-compact.js";
|
|
28
29
|
import { resetRecallStatus, updateSessionInfo } from "../src/hooks/state.js";
|
|
29
30
|
import { getClient } from "../src/hooks/client.js";
|
|
30
31
|
/**
|
|
@@ -88,8 +89,8 @@ function buildOutput(hookType, additionalContext, block = false, reason) {
|
|
|
88
89
|
output.decision = "block";
|
|
89
90
|
output.reason = reason || "Blocked by MemoryLayer hook";
|
|
90
91
|
}
|
|
91
|
-
// Only add hookSpecificOutput for hooks that support it
|
|
92
|
-
// SessionStart
|
|
92
|
+
// Only add hookSpecificOutput for hooks that support it.
|
|
93
|
+
// SessionStart works empirically for context injection; Stop and PreCompact do not.
|
|
93
94
|
if (additionalContext && HOOKS_WITH_ADDITIONAL_CONTEXT.has(hookType)) {
|
|
94
95
|
output.hookSpecificOutput = {
|
|
95
96
|
hookEventName: hookType,
|
|
@@ -109,6 +110,24 @@ function buildErrorOutput(hookType, error) {
|
|
|
109
110
|
},
|
|
110
111
|
};
|
|
111
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Quote a value for a POSIX shell env file without permitting expansion.
|
|
115
|
+
*/
|
|
116
|
+
function shellQuote(value) {
|
|
117
|
+
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Redact IDs before diagnostic logging.
|
|
121
|
+
*/
|
|
122
|
+
function redactId(value) {
|
|
123
|
+
if (!value) {
|
|
124
|
+
return "(none)";
|
|
125
|
+
}
|
|
126
|
+
if (value.length <= 8) {
|
|
127
|
+
return `${value.slice(0, 2)}...`;
|
|
128
|
+
}
|
|
129
|
+
return `${value.slice(0, 4)}...${value.slice(-4)}`;
|
|
130
|
+
}
|
|
112
131
|
/**
|
|
113
132
|
* Convert legacy HookOutput to HandlerResult
|
|
114
133
|
*/
|
|
@@ -162,7 +181,7 @@ async function dispatch(hookType, input) {
|
|
|
162
181
|
workspaceId = client.getWorkspaceId();
|
|
163
182
|
const sessionResult = await client.startSession({ ttl_seconds: 3600 });
|
|
164
183
|
sessionId = sessionResult.session_id;
|
|
165
|
-
console.error(`[session-start] created hook session=${sessionId} workspace=${workspaceId} (direct, no handoff)`);
|
|
184
|
+
console.error(`[session-start] created hook session=${redactId(sessionId)} workspace=${redactId(workspaceId)} (direct, no handoff)`);
|
|
166
185
|
}
|
|
167
186
|
catch {
|
|
168
187
|
// Ignore - memory features will still work via MCP tools
|
|
@@ -170,19 +189,19 @@ async function dispatch(hookType, input) {
|
|
|
170
189
|
}
|
|
171
190
|
}
|
|
172
191
|
else {
|
|
173
|
-
console.error(`[session-start] got hook session=${sessionId} workspace=${workspaceId} (from handoff file)`);
|
|
192
|
+
console.error(`[session-start] got hook session=${redactId(sessionId)} workspace=${redactId(workspaceId)} (from handoff file)`);
|
|
174
193
|
}
|
|
175
194
|
// Write to CLAUDE_ENV_FILE so subsequent hook processes get the session.
|
|
176
195
|
// Each Claude Code session has its own env file, providing session isolation.
|
|
177
196
|
if (envFile) {
|
|
178
197
|
try {
|
|
179
198
|
if (workspaceId) {
|
|
180
|
-
appendFileSync(envFile, `export MEMORYLAYER_WORKSPACE_ID
|
|
199
|
+
appendFileSync(envFile, `export MEMORYLAYER_WORKSPACE_ID=${shellQuote(workspaceId)}\n`);
|
|
181
200
|
}
|
|
182
201
|
if (sessionId) {
|
|
183
|
-
appendFileSync(envFile, `export MEMORYLAYER_SESSION_ID
|
|
202
|
+
appendFileSync(envFile, `export MEMORYLAYER_SESSION_ID=${shellQuote(sessionId)}\n`);
|
|
184
203
|
}
|
|
185
|
-
console.error(`[session-start] wrote to CLAUDE_ENV_FILE=${envFile} sessionId=${sessionId
|
|
204
|
+
console.error(`[session-start] wrote to CLAUDE_ENV_FILE=${envFile} sessionId=${redactId(sessionId)} workspaceId=${redactId(workspaceId)}`);
|
|
186
205
|
}
|
|
187
206
|
catch (err) {
|
|
188
207
|
console.error(`[session-start] failed to write CLAUDE_ENV_FILE=${envFile}:`, err);
|
|
@@ -206,8 +225,7 @@ async function dispatch(hookType, input) {
|
|
|
206
225
|
case HookEvent.PostToolUse:
|
|
207
226
|
return legacyToResult(await handlePostToolUse(input));
|
|
208
227
|
case HookEvent.PreCompact:
|
|
209
|
-
|
|
210
|
-
return {};
|
|
228
|
+
return legacyToResult(await handlePreCompact(input));
|
|
211
229
|
case HookEvent.Stop:
|
|
212
230
|
// Stop: commit working memory and end session (side effects only, no context injection)
|
|
213
231
|
return legacyToResult(await handleStop());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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G,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAExC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,MAAM;AACN,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook client - provides access to the MemoryLayerClient for hook operations.
|
|
3
|
+
*
|
|
4
|
+
* Hooks use the exact same MemoryLayerClient as MCP tools, just with a shorter
|
|
5
|
+
* timeout since hooks need to respond quickly.
|
|
6
|
+
*/
|
|
7
|
+
import { MemoryLayerClient } from "@scitrera/memorylayer-mcp-server";
|
|
8
|
+
/**
|
|
9
|
+
* Get or create the singleton MemoryLayerClient instance.
|
|
10
|
+
* This is the same client class used by MCP tools.
|
|
11
|
+
*
|
|
12
|
+
* On each call, syncs the session ID via resolveSessionId() so that
|
|
13
|
+
* hooks running after SessionStart send the X-Session-ID header for
|
|
14
|
+
* correct workspace resolution on the server.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getClient(): MemoryLayerClient;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the MemoryLayer server is reachable
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkHealth(): Promise<boolean>;
|
|
21
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/hooks/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAqB,MAAM,kCAAkC,CAAC;AAMxF;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI,iBAAiB,CA2B7C;AAED;;GAEG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAOpD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook client - provides access to the MemoryLayerClient for hook operations.
|
|
3
|
+
*
|
|
4
|
+
* Hooks use the exact same MemoryLayerClient as MCP tools, just with a shorter
|
|
5
|
+
* timeout since hooks need to respond quickly.
|
|
6
|
+
*/
|
|
7
|
+
import { MemoryLayerClient, detectWorkspaceId } from "@scitrera/memorylayer-mcp-server";
|
|
8
|
+
import { resolveSessionId } from "./state.js";
|
|
9
|
+
/** Singleton client instance for hooks */
|
|
10
|
+
let clientInstance = null;
|
|
11
|
+
/**
|
|
12
|
+
* Get or create the singleton MemoryLayerClient instance.
|
|
13
|
+
* This is the same client class used by MCP tools.
|
|
14
|
+
*
|
|
15
|
+
* On each call, syncs the session ID via resolveSessionId() so that
|
|
16
|
+
* hooks running after SessionStart send the X-Session-ID header for
|
|
17
|
+
* correct workspace resolution on the server.
|
|
18
|
+
*/
|
|
19
|
+
export function getClient() {
|
|
20
|
+
if (!clientInstance) {
|
|
21
|
+
let workspaceId = process.env.MEMORYLAYER_WORKSPACE_ID;
|
|
22
|
+
if (!workspaceId) {
|
|
23
|
+
try {
|
|
24
|
+
workspaceId = detectWorkspaceId();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
workspaceId = "_default";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
clientInstance = new MemoryLayerClient({
|
|
31
|
+
baseUrl: process.env.MEMORYLAYER_URL,
|
|
32
|
+
apiKey: process.env.MEMORYLAYER_API_KEY,
|
|
33
|
+
workspaceId,
|
|
34
|
+
timeout: 5000, // Shorter timeout for hooks
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Sync session ID on every call — resolveSessionId prefers env (cheap)
|
|
38
|
+
// and only falls back to hook-state.json disk read if env is unset.
|
|
39
|
+
const sessionId = resolveSessionId("client");
|
|
40
|
+
if (sessionId && clientInstance.getSessionId() !== sessionId) {
|
|
41
|
+
clientInstance.setSessionId(sessionId);
|
|
42
|
+
}
|
|
43
|
+
return clientInstance;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if the MemoryLayer server is reachable
|
|
47
|
+
*/
|
|
48
|
+
export async function checkHealth() {
|
|
49
|
+
try {
|
|
50
|
+
await getClient().getBriefing({ limit: 1, includeMemories: false });
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/hooks/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,0CAA0C;AAC1C,IAAI,cAAc,GAA6B,IAAI,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,IAAI,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;QACvD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,IAAI,CAAC;gBACH,WAAW,GAAG,iBAAiB,EAAE,CAAC;YACpC,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW,GAAG,UAAU,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,cAAc,GAAG,IAAI,iBAAiB,CAAC;YACrC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;YACpC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;YACvC,WAAW;YACX,OAAO,EAAE,IAAI,EAAE,4BAA4B;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,uEAAuE;IACvE,oEAAoE;IACpE,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,SAAS,IAAI,cAAc,CAAC,YAAY,EAAE,KAAK,SAAS,EAAE,CAAC;QAC7D,cAAc,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,SAAS,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format API responses for injection into Claude's context.
|
|
3
|
+
*
|
|
4
|
+
* Uses the same types returned by MemoryLayerClient (the MCP adapter),
|
|
5
|
+
* so hooks and MCP tools share the same data contracts.
|
|
6
|
+
*/
|
|
7
|
+
import type { Memory, RecallResult, ToolResponse } from "@scitrera/memorylayer-mcp-server";
|
|
8
|
+
/**
|
|
9
|
+
* Format recall results for context injection
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatRecallResult(result: RecallResult, query: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format briefing for context injection.
|
|
14
|
+
* Accepts the ToolResponse from MemoryLayerClient.getBriefing().
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatBriefing(briefing: ToolResponse): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format directive memories specially (high importance user instructions)
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatDirectives(memories: Memory[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* Format sandbox state for context injection (post-compaction recovery)
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatSandboxState(inspectResult: Record<string, unknown>): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format combined SessionStart output
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatSessionStart(briefing: ToolResponse | null, directives: Memory[], topicRecall: RecallResult | null, topic?: string, sandboxState?: Record<string, unknown> | null): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format guidance for storing memories after tool use
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatStorageGuidance(toolName: string, isSignificant: boolean): string;
|
|
33
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../src/hooks/formatters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AA0B3F;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAmB9E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CA6C7D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAmB3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAoBjF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM,EAAE,EACpB,WAAW,EAAE,YAAY,GAAG,IAAI,EAChC,KAAK,CAAC,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAC5C,MAAM,CAoDR;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,MAAM,CAatF"}
|