@skedulo/memory-hub-mcp 0.2.0 → 0.2.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/assets/session-start.sh +171 -41
- package/dist/client.js +14 -0
- package/dist/guide-check.js +24 -0
- package/dist/index.js +19 -1
- package/dist/recall.js +29 -6
- package/dist/setup.js +22 -8
- package/package.json +1 -1
- package/skill-guide.md +13 -5
package/assets/session-start.sh
CHANGED
|
@@ -25,6 +25,12 @@ call() {
|
|
|
25
25
|
# comfortable headroom even if both rounds hit the cap. Bumped from 2s/3s after live
|
|
26
26
|
# runs showed occasional silent drops (a call's own timeout, not a logic bug) under
|
|
27
27
|
# real tenant latency.
|
|
28
|
+
# Test seam: replay canned per-leg responses so budget and assembly logic test offline.
|
|
29
|
+
if [ -n "${MEMORY_HUB_FIXTURE_DIR:-}" ]; then
|
|
30
|
+
cp "$MEMORY_HUB_FIXTURE_DIR/$(basename "$out_file")" "$out_file" 2>/dev/null || true
|
|
31
|
+
return 0
|
|
32
|
+
fi
|
|
33
|
+
|
|
28
34
|
curl -sS --connect-timeout 3 --max-time 5 \
|
|
29
35
|
-X POST "${FUNCTION_URL}${path}" \
|
|
30
36
|
-H "Authorization: Bearer ${TOKEN}" \
|
|
@@ -115,10 +121,19 @@ if [ -z "$TEAM_NAME_HINT" ] && [ -n "$REPO_NAME" ]; then
|
|
|
115
121
|
TEAM_NAME_HINT=$(humanize_repo_slug "$REPO_NAME" 2>/dev/null || true)
|
|
116
122
|
fi
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
# Oversized means silently unread: past the inline cap the block is only previewed. 8000 is conservative, not measured.
|
|
125
|
+
BUDGET="${MEMORY_HUB_MAX_CHARS:-8000}"
|
|
126
|
+
|
|
127
|
+
# Legs oversubscribe BUDGET on purpose: the server drops past its cap silently, so the clip below must be the binding one.
|
|
128
|
+
FETCH_FACTS=$((BUDGET / 3))
|
|
129
|
+
FETCH_SKILLS=$((BUDGET / 4))
|
|
130
|
+
FETCH_REPO_FACTS=$((BUDGET / 2))
|
|
131
|
+
FETCH_REPO_REST=$((BUDGET / 3))
|
|
132
|
+
|
|
133
|
+
call "/memory/recall" "{\"scope\":\"self\",\"maxTotalChars\":$FETCH_FACTS}" "$TMP_DIR/facts_self.json" &
|
|
134
|
+
call "/memory/recall" "{\"scope\":\"team\",\"maxTotalChars\":$FETCH_FACTS}" "$TMP_DIR/facts_team.json" &
|
|
135
|
+
call "/memory/list-skills" "{\"scope\":\"self\",\"maxTotalChars\":$FETCH_SKILLS}" "$TMP_DIR/skills_self.json" &
|
|
136
|
+
call "/memory/list-skills" "{\"scope\":\"team\",\"maxTotalChars\":$FETCH_SKILLS}" "$TMP_DIR/skills_team.json" &
|
|
122
137
|
if [ -n "$REPO_NAME" ]; then
|
|
123
138
|
REPO_NAME_JSON=$(printf '%s' "$REPO_NAME" | jq -Rs . 2>/dev/null || true)
|
|
124
139
|
if [ -n "$REPO_NAME_JSON" ]; then
|
|
@@ -141,66 +156,152 @@ if [ -s "$TMP_DIR/repo.json" ]; then
|
|
|
141
156
|
fi
|
|
142
157
|
|
|
143
158
|
if [ -n "$REPO_UID" ]; then
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
call "/memory/
|
|
147
|
-
call "/memory/
|
|
159
|
+
# The repo legs get the larger share — they are first in priority order below.
|
|
160
|
+
REPO_UID_JSON=$(printf '%s' "$REPO_UID" | jq -Rs .)
|
|
161
|
+
call "/memory/recall" "$(printf '{"scope":"team","repo":%s,"maxTotalChars":%d}' "$REPO_UID_JSON" "$FETCH_REPO_FACTS")" "$TMP_DIR/facts_repo.json" &
|
|
162
|
+
call "/memory/list-skills" "$(printf '{"scope":"team","repo":%s,"maxTotalChars":%d}' "$REPO_UID_JSON" "$FETCH_REPO_REST")" "$TMP_DIR/skills_repo.json" &
|
|
163
|
+
call "/memory/recall-wiki" "$(printf '{"scope":"team","repo":%s,"maxTotalChars":%d}' "$REPO_UID_JSON" "$FETCH_REPO_REST")" "$TMP_DIR/wiki_repo.json" &
|
|
148
164
|
wait
|
|
149
165
|
fi
|
|
150
166
|
|
|
167
|
+
# -c, not -r: content is multi-line, and sort/comm dedup plus the budget clip below are
|
|
168
|
+
# all line-oriented — one JSON-escaped line per item is what keeps an item atomic through
|
|
169
|
+
# them, instead of its lines being alphabetised apart. add_section decodes at the end.
|
|
170
|
+
#
|
|
151
171
|
# Appends "(updated YYYY-MM-DD)" when lastModifiedDate is present, nothing otherwise —
|
|
152
172
|
# the panel shows the same signal as a relative "N days ago" label, but the raw date
|
|
153
173
|
# is cheaper to compute in jq and just as usable for the agent's own judgment (it can
|
|
154
174
|
# already see today's date in its own context).
|
|
175
|
+
STAMP='(if .lastModifiedDate then " (updated " + .lastModifiedDate[0:10] + ")" else "" end)'
|
|
176
|
+
|
|
177
|
+
# The function truncates each item at 500 chars (handlers/recallMemory.ts), which can cut
|
|
178
|
+
# inside a code fence and leave every later section rendering as one code block.
|
|
179
|
+
CLOSE_FENCE='if ([match("```"; "g")] | length) % 2 == 1 then . + "\n```" else . end'
|
|
180
|
+
|
|
181
|
+
# A cut at exactly the cap reads as complete, because the "(updated …)" stamp still follows it.
|
|
182
|
+
ITEM_CAP=500
|
|
183
|
+
ELIDE="if length >= $ITEM_CAP then . + \"…\" else . end"
|
|
184
|
+
|
|
185
|
+
# Without this a stored "## heading" renders at the level of the hook's own section headings.
|
|
186
|
+
INDENT='gsub("\n"; "\n ")'
|
|
187
|
+
|
|
188
|
+
# The function flags a cut item; an older one sends no flag and keeps just the "…" above.
|
|
189
|
+
cut_pointer() {
|
|
190
|
+
printf '(if .truncated then " [cut at \\(.content | length) of \\(.fullLength) — memory_get type=%s uid=\\(.uid)]" else "" end)' "$1"
|
|
191
|
+
}
|
|
192
|
+
|
|
155
193
|
extract_facts() {
|
|
156
|
-
jq -
|
|
194
|
+
jq -c ".facts[]? | (\"- \" + (.content | $ELIDE) + $(cut_pointer Fact) + $STAMP) | $CLOSE_FENCE | $INDENT" "$1" 2>/dev/null || true
|
|
157
195
|
}
|
|
158
196
|
|
|
159
197
|
extract_skills() {
|
|
160
|
-
jq -
|
|
198
|
+
jq -c ".skills[]? | (\"- \" + .title + \": \" + (.content | $ELIDE) + $(cut_pointer Skill) + $STAMP) | $CLOSE_FENCE | $INDENT" "$1" 2>/dev/null || true
|
|
161
199
|
}
|
|
162
200
|
|
|
163
201
|
extract_wiki() {
|
|
164
|
-
jq -
|
|
202
|
+
jq -c ".pages[]? | (\"- \" + .title + \": \" + (.content | $ELIDE) + $(cut_pointer Wiki) + $STAMP) | $CLOSE_FENCE | $INDENT" "$1" 2>/dev/null || true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
# Absent on functions deployed before the field existed; fall back to what arrived rather than inventing a number.
|
|
206
|
+
leg_total() {
|
|
207
|
+
local sent
|
|
208
|
+
sent=$(jq -r '.total // empty' "$1" 2>/dev/null || true)
|
|
209
|
+
case "$sent" in
|
|
210
|
+
'' | *[!0-9]*) printf '%s' "$2" ;;
|
|
211
|
+
*) printf '%s' "$sent" ;;
|
|
212
|
+
esac
|
|
165
213
|
}
|
|
166
214
|
|
|
167
215
|
# Counts non-empty "- "-prefixed lines in a var (0 for an empty string, never 1) —
|
|
168
216
|
# used only for the diagnostic summary line below, not for any content shown above.
|
|
169
217
|
count_items() {
|
|
170
218
|
[ -z "$1" ] && { printf '0'; return 0; }
|
|
171
|
-
printf '%s\n' "$1" | grep -c '
|
|
219
|
+
printf '%s\n' "$1" | grep -c '^"-' 2>/dev/null || printf '0'
|
|
172
220
|
}
|
|
173
221
|
|
|
174
222
|
NL=$'\n'
|
|
175
223
|
CONTEXT=""
|
|
176
224
|
|
|
225
|
+
# Reserved so the omission footer can never itself be the thing squeezed out.
|
|
226
|
+
FOOTER_RESERVE=120
|
|
227
|
+
REMAINING=$((BUDGET - FOOTER_RESERVE))
|
|
228
|
+
SKIPPED=""
|
|
229
|
+
|
|
230
|
+
# Even share per section, recomputed: huge facts/repo sections cannot starve skills, and unspent budget flows onward.
|
|
231
|
+
SECTIONS_LEFT=4
|
|
232
|
+
[ -n "$REPO_UID" ] && SECTIONS_LEFT=5
|
|
233
|
+
|
|
234
|
+
# Emits at most $1 chars of $2, whole items only. $3 is what the server holds — its cap has usually dropped items already.
|
|
235
|
+
clip_to_budget() {
|
|
236
|
+
local budget="$1" text="$2" avail="$3" out="" line used=0 shown=0 seen=0
|
|
237
|
+
while IFS= read -r line; do
|
|
238
|
+
[ -n "$line" ] || continue
|
|
239
|
+
seen=$((seen + 1))
|
|
240
|
+
if [ "$shown" -eq "$((seen - 1))" ] && [ $((used + ${#line} + 1)) -le "$budget" ]; then
|
|
241
|
+
out="${out}${line}${NL}"
|
|
242
|
+
used=$((used + ${#line} + 1))
|
|
243
|
+
shown=$((shown + 1))
|
|
244
|
+
fi
|
|
245
|
+
done <<< "$text"
|
|
246
|
+
printf '%s' "$out"
|
|
247
|
+
[ "$shown" -gt 0 ] || return 0
|
|
248
|
+
# Pre-dedup, so team counts can overstate by items also shown under self/repo.
|
|
249
|
+
[ "$avail" -ge "$seen" ] 2>/dev/null || avail="$seen"
|
|
250
|
+
if [ "$avail" -gt "$shown" ]; then
|
|
251
|
+
# A bare memory_recall returns newest-first — the same items already above.
|
|
252
|
+
printf '_showing %d of %d — ask memory_recall with a query for the rest._' "$shown" "$avail" | jq -R .
|
|
253
|
+
fi
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
add_section() {
|
|
257
|
+
local heading="$1" body="$2" avail="${3:-0}" clipped rendered room share
|
|
258
|
+
# Counted before the decrement, or the second-to-last section is handed the entire remainder.
|
|
259
|
+
local mine="$SECTIONS_LEFT"
|
|
260
|
+
[ "$SECTIONS_LEFT" -gt 1 ] && SECTIONS_LEFT=$((SECTIONS_LEFT - 1))
|
|
261
|
+
[ -n "$body" ] || return 0
|
|
262
|
+
# Heading plus the "## " and blank-line overhead, charged before clipping so a section
|
|
263
|
+
# can never push the total over by its own frame.
|
|
264
|
+
room=$((REMAINING - ${#heading} - 6))
|
|
265
|
+
share=$((room / mine))
|
|
266
|
+
[ "$share" -lt "$room" ] && room="$share"
|
|
267
|
+
# Below this a section is all frame and no content; recorded, not silent.
|
|
268
|
+
if [ "$room" -le 150 ]; then
|
|
269
|
+
SKIPPED="${SKIPPED}${SKIPPED:+, }${heading}"
|
|
270
|
+
return 0
|
|
271
|
+
fi
|
|
272
|
+
clipped=$(clip_to_budget "$room" "$body" "$avail")
|
|
273
|
+
# Room for the frame but not one item is the same omission as a skipped section.
|
|
274
|
+
if [ -z "$clipped" ]; then
|
|
275
|
+
SKIPPED="${SKIPPED}${SKIPPED:+, }${heading}"
|
|
276
|
+
return 0
|
|
277
|
+
fi
|
|
278
|
+
rendered=$(printf '%s\n' "$clipped" | jq -r . 2>/dev/null || true)
|
|
279
|
+
[ -n "$rendered" ] || return 0
|
|
280
|
+
CONTEXT="${CONTEXT}## ${heading}${NL}${rendered}${NL}${NL}"
|
|
281
|
+
# Charged on the escaped length, which is the larger one — the budget errs small.
|
|
282
|
+
REMAINING=$((REMAINING - ${#clipped} - ${#heading} - 6))
|
|
283
|
+
}
|
|
284
|
+
|
|
177
285
|
FACTS_SELF=$(extract_facts "$TMP_DIR/facts_self.json")
|
|
178
286
|
FACTS_TEAM=$(extract_facts "$TMP_DIR/facts_team.json")
|
|
179
287
|
SKILLS_SELF=$(extract_skills "$TMP_DIR/skills_self.json")
|
|
180
288
|
SKILLS_TEAM=$(extract_skills "$TMP_DIR/skills_team.json")
|
|
181
289
|
|
|
290
|
+
FACTS_SELF_N=$(leg_total "$TMP_DIR/facts_self.json" "$(count_items "$FACTS_SELF")")
|
|
291
|
+
FACTS_TEAM_N=$(leg_total "$TMP_DIR/facts_team.json" "$(count_items "$FACTS_TEAM")")
|
|
292
|
+
SKILLS_SELF_N=$(leg_total "$TMP_DIR/skills_self.json" "$(count_items "$SKILLS_SELF")")
|
|
293
|
+
SKILLS_TEAM_N=$(leg_total "$TMP_DIR/skills_team.json" "$(count_items "$SKILLS_TEAM")")
|
|
294
|
+
|
|
182
295
|
# The team-scope query matches DevAgentId == self OR Visibility == "Team", so
|
|
183
296
|
# self-owned items also come back in the team results. Drop anything already
|
|
184
297
|
# shown under "Your ..." so it isn't rendered twice.
|
|
185
298
|
FACTS_TEAM=$(comm -23 <(echo "$FACTS_TEAM" | sort) <(echo "$FACTS_SELF" | sort) 2>/dev/null || true)
|
|
186
299
|
SKILLS_TEAM=$(comm -23 <(echo "$SKILLS_TEAM" | sort) <(echo "$SKILLS_SELF" | sort) 2>/dev/null || true)
|
|
187
300
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
CONTEXT="${CONTEXT}## Team memory-hub facts${NL}${FACTS_TEAM}${NL}${NL}"
|
|
193
|
-
fi
|
|
194
|
-
if [ -n "$SKILLS_SELF" ]; then
|
|
195
|
-
CONTEXT="${CONTEXT}## Your memory-hub skills${NL}${SKILLS_SELF}${NL}${NL}"
|
|
196
|
-
fi
|
|
197
|
-
if [ -n "$SKILLS_TEAM" ]; then
|
|
198
|
-
CONTEXT="${CONTEXT}## Team memory-hub skills${NL}${SKILLS_TEAM}${NL}${NL}"
|
|
199
|
-
fi
|
|
200
|
-
|
|
201
|
-
# Additive, never narrowing: this is an extra section on top of the four above, not a
|
|
202
|
-
# filter applied to them. It surfaces what the whole team knows about this specific
|
|
203
|
-
# repo — including from members whose work this developer has never seen.
|
|
301
|
+
# Additive, never narrowing: a section alongside the self/team ones, not a filter applied
|
|
302
|
+
# to them — what the whole team knows about this repo, including from members this
|
|
303
|
+
# developer has never worked with.
|
|
304
|
+
REPO_SECTION=""
|
|
204
305
|
if [ -n "$REPO_UID" ]; then
|
|
205
306
|
FACTS_REPO=$(extract_facts "$TMP_DIR/facts_repo.json")
|
|
206
307
|
SKILLS_REPO=$(extract_skills "$TMP_DIR/skills_repo.json")
|
|
@@ -208,6 +309,11 @@ if [ -n "$REPO_UID" ]; then
|
|
|
208
309
|
# page is only ever fetched here, in this one repo-scoped round, so there's
|
|
209
310
|
# nothing to subtract it against.
|
|
210
311
|
WIKI_REPO=$(extract_wiki "$TMP_DIR/wiki_repo.json")
|
|
312
|
+
REPO_N=$((
|
|
313
|
+
$(leg_total "$TMP_DIR/facts_repo.json" "$(count_items "$FACTS_REPO")") +
|
|
314
|
+
$(leg_total "$TMP_DIR/skills_repo.json" "$(count_items "$SKILLS_REPO")") +
|
|
315
|
+
$(leg_total "$TMP_DIR/wiki_repo.json" "$(count_items "$WIKI_REPO")")
|
|
316
|
+
))
|
|
211
317
|
|
|
212
318
|
# The repo-scoped query ({"scope":"team","repo":...}) is a superset filter of what
|
|
213
319
|
# the team query already fetched, so dedup against both the self and team sections
|
|
@@ -217,7 +323,6 @@ if [ -n "$REPO_UID" ]; then
|
|
|
217
323
|
SKILLS_REPO=$(comm -23 <(echo "$SKILLS_REPO" | sort) <(echo "$SKILLS_TEAM" | sort) 2>/dev/null || true)
|
|
218
324
|
SKILLS_REPO=$(comm -23 <(echo "$SKILLS_REPO" | sort) <(echo "$SKILLS_SELF" | sort) 2>/dev/null || true)
|
|
219
325
|
|
|
220
|
-
REPO_SECTION=""
|
|
221
326
|
if [ -n "$FACTS_REPO" ]; then
|
|
222
327
|
REPO_SECTION="${REPO_SECTION}${FACTS_REPO}${NL}"
|
|
223
328
|
fi
|
|
@@ -227,10 +332,6 @@ if [ -n "$REPO_UID" ]; then
|
|
|
227
332
|
if [ -n "$WIKI_REPO" ]; then
|
|
228
333
|
REPO_SECTION="${REPO_SECTION}${WIKI_REPO}${NL}"
|
|
229
334
|
fi
|
|
230
|
-
|
|
231
|
-
if [ -n "$REPO_SECTION" ]; then
|
|
232
|
-
CONTEXT="${CONTEXT}## Team knowledge for ${REPO_NAME}${NL}${REPO_SECTION}${NL}"
|
|
233
|
-
fi
|
|
234
335
|
fi
|
|
235
336
|
|
|
236
337
|
# A completed-but-empty run and a timed-out/killed run both look identical from the
|
|
@@ -247,18 +348,47 @@ else
|
|
|
247
348
|
fi
|
|
248
349
|
DIAG="${DIAG}_"
|
|
249
350
|
|
|
250
|
-
# Recall
|
|
351
|
+
# Recall below is the hook's own automation — it never saves anything new, and an
|
|
251
352
|
# agent reading only the facts/skills sections has no reason to infer that a
|
|
252
353
|
# separate, non-automatic step exists for the other half (on-demand mid-session
|
|
253
354
|
# recall, and saving durable results once a task lands). State that explicitly and
|
|
254
355
|
# unconditionally (not gated behind having any facts to show) so an agent that
|
|
255
|
-
# finds nothing
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
356
|
+
# finds nothing below still knows to check back in before finishing a task.
|
|
357
|
+
#
|
|
358
|
+
# First, not last: it is the only part that asks for an action, so it has to survive the
|
|
359
|
+
# budget even when nothing else does.
|
|
360
|
+
# A stale build cannot warn about itself, so the hook, which a git pull does refresh, has to.
|
|
361
|
+
MCP_DIR="${MEMORY_HUB_MCP_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../memory-hub-mcp" 2>/dev/null && pwd)}"
|
|
362
|
+
STALE_MCP=""
|
|
363
|
+
if [ -n "$MCP_DIR" ] && [ -f "$MCP_DIR/dist/index.js" ] &&
|
|
364
|
+
[ -n "$(find "$MCP_DIR/src" "$MCP_DIR/skill-guide.md" -type f \( -name '*.ts' -o -name '*.md' \) ! -name '*.test.ts' -newer "$MCP_DIR/dist/index.js" 2>/dev/null | head -1)" ]; then
|
|
365
|
+
STALE_MCP="WARNING: the memory-hub MCP build in this checkout is older than its source, so tools the guide names (memory_get) may be missing and recalled items cut at 500 chars cannot be fetched whole. Tell the user to run ./scripts/setup-dev.sh (or cd memory-hub-mcp && yarn build) and restart the session.${NL}${NL}"
|
|
366
|
+
fi
|
|
367
|
+
|
|
368
|
+
REMINDER="## Reminder${NL}"
|
|
369
|
+
REMINDER="${REMINDER}What follows is an automatic recall only - it never saves anything new.${NL}"
|
|
370
|
+
REMINDER="${REMINDER}Invoke the se-ai-memory-hub skill during this session: memory_recall before${NL}"
|
|
371
|
+
REMINDER="${REMINDER}investigating something that smells like prior context, and memory_save${NL}"
|
|
372
|
+
REMINDER="${REMINDER}(type \"Fact\" or \"Scenario\") once a task produces a durable decision, root${NL}"
|
|
373
|
+
REMINDER="${REMINDER}cause, or fix worth keeping for next time.${NL}${NL}"
|
|
374
|
+
REMINDER="${REMINDER}${STALE_MCP}"
|
|
375
|
+
CONTEXT="$REMINDER"
|
|
376
|
+
REMAINING=$((REMAINING - ${#REMINDER} - ${#DIAG}))
|
|
377
|
+
|
|
378
|
+
# Priority order, most repo-specific first: whatever the budget cuts should be the
|
|
379
|
+
# content least likely to bear on the repo this session is actually in.
|
|
380
|
+
if [ -n "$REPO_UID" ]; then
|
|
381
|
+
add_section "Team knowledge for ${REPO_NAME}" "$REPO_SECTION" "${REPO_N:-0}"
|
|
382
|
+
fi
|
|
383
|
+
add_section "Your memory-hub facts" "$FACTS_SELF" "$FACTS_SELF_N"
|
|
384
|
+
add_section "Team memory-hub facts" "$FACTS_TEAM" "$FACTS_TEAM_N"
|
|
385
|
+
add_section "Your memory-hub skills" "$SKILLS_SELF" "$SKILLS_SELF_N"
|
|
386
|
+
add_section "Team memory-hub skills" "$SKILLS_TEAM" "$SKILLS_TEAM_N"
|
|
387
|
+
|
|
388
|
+
# A section that never fit is the omission most likely to be read as "there is nothing there".
|
|
389
|
+
if [ -n "$SKIPPED" ]; then
|
|
390
|
+
CONTEXT="${CONTEXT}_Omitted for space: ${SKIPPED}. Ask memory_recall with a query._${NL}${NL}"
|
|
391
|
+
fi
|
|
262
392
|
|
|
263
393
|
CONTEXT="${CONTEXT}${DIAG}${NL}"
|
|
264
394
|
|
package/dist/client.js
CHANGED
|
@@ -68,6 +68,20 @@ class MemoryHubClient {
|
|
|
68
68
|
linkRepoTeam(input) {
|
|
69
69
|
return this.post('/memory/link-repo-team', input);
|
|
70
70
|
}
|
|
71
|
+
// Full, uncapped content by uid — recall truncates every item to
|
|
72
|
+
// DEFAULT_MAX_CHARS_PER_ITEM, so anything longer is only readable through these.
|
|
73
|
+
getFact(input) {
|
|
74
|
+
return this.post('/memory/get-fact', input);
|
|
75
|
+
}
|
|
76
|
+
getSkill(input) {
|
|
77
|
+
return this.post('/memory/get-skill', input);
|
|
78
|
+
}
|
|
79
|
+
getScenario(input) {
|
|
80
|
+
return this.post('/memory/get-scenario', input);
|
|
81
|
+
}
|
|
82
|
+
getWikiPage(input) {
|
|
83
|
+
return this.post('/memory/get-wiki-page', input);
|
|
84
|
+
}
|
|
71
85
|
saveWikiPage(input) {
|
|
72
86
|
return this.post('/memory/save-wiki-page', input);
|
|
73
87
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.staleBuildNotice = exports.toolsMentioned = void 0;
|
|
4
|
+
// The guide is read from disk, so a pull without a rebuild pairs a new guide with an old build.
|
|
5
|
+
function toolsMentioned(guide) {
|
|
6
|
+
return [...new Set(guide.match(/\bmemory_[A-Za-z]+\b/g) ?? [])].sort();
|
|
7
|
+
}
|
|
8
|
+
exports.toolsMentioned = toolsMentioned;
|
|
9
|
+
function staleBuildNotice(guide, registered) {
|
|
10
|
+
// Fail open: with no registry to compare against, a warning would be noise.
|
|
11
|
+
if (registered.length === 0) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
const have = new Set(registered);
|
|
15
|
+
const missing = toolsMentioned(guide).filter((name) => !have.has(name));
|
|
16
|
+
if (missing.length === 0) {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
return (`WARNING: this memory-hub-mcp build is older than its guide. The guide below refers to ` +
|
|
20
|
+
`${missing.join(', ')}, which this build does not expose, so those steps will fail. ` +
|
|
21
|
+
`Tell the user to rebuild (\`cd memory-hub-mcp && yarn build\`, or rerun ./scripts/setup-dev.sh) ` +
|
|
22
|
+
`and restart the session.\n\n---\n\n`);
|
|
23
|
+
}
|
|
24
|
+
exports.staleBuildNotice = staleBuildNotice;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const git_remote_1 = require("./git-remote");
|
|
|
13
13
|
const embeddings_1 = require("./embeddings");
|
|
14
14
|
const save_1 = require("./save");
|
|
15
15
|
const recall_1 = require("./recall");
|
|
16
|
+
const guide_check_1 = require("./guide-check");
|
|
16
17
|
const session_context_1 = require("./session-context");
|
|
17
18
|
// Must match the AgentFacts/AgentSkills/AgentWikiPages Tags custom field's Picklist
|
|
18
19
|
// allowedValues (src/object-model/custom-fields/{AgentFacts,AgentSkills,AgentWikiPages}/*-Tags.custom-field.json)
|
|
@@ -106,7 +107,9 @@ server.tool('memory_getSkillGuide', 'Get the current SE AI Memory Hub usage guid
|
|
|
106
107
|
// itself and updates on every `yarn build`, not via a separate manual `cp` step.
|
|
107
108
|
const guidePath = (0, path_1.join)(__dirname, '..', 'skill-guide.md');
|
|
108
109
|
const guide = (0, fs_1.readFileSync)(guidePath, 'utf-8');
|
|
109
|
-
|
|
110
|
+
// The SDK has no public tool list; if this internal moves, the check just goes silent.
|
|
111
|
+
const registered = Object.keys(server._registeredTools ?? {});
|
|
112
|
+
return { content: [{ type: 'text', text: (0, guide_check_1.staleBuildNotice)(guide, registered) + guide }] };
|
|
110
113
|
});
|
|
111
114
|
server.tool('memory_recall', "Recall this developer's (or their team's) Facts, Skills, Scenarios, or Wiki pages. See memory_getSkillGuide for when to use each type.", {
|
|
112
115
|
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
@@ -114,10 +117,25 @@ server.tool('memory_recall', "Recall this developer's (or their team's) Facts, S
|
|
|
114
117
|
query: zod_1.z.string().optional(),
|
|
115
118
|
tags: zod_1.z.array(zod_1.z.enum(TAG_VALUES)).optional().describe('Fact only.'),
|
|
116
119
|
externalRef: zod_1.z.string().optional().describe("Fact, Scenario only — filter to items linked to this Linear/Jira ticket ref, e.g. 'SOL-1234'. Does not create a task if the ref doesn't resolve to one — returns no results instead."),
|
|
120
|
+
maxCharsPerItem: zod_1.z.number().int().positive().optional().describe('Per-item content cap, default 500. Raise it to read longer items inline; prefer memory_get for a single long one.'),
|
|
121
|
+
maxTotalChars: zod_1.z.number().int().positive().optional().describe('Cap across all items, default 6000.'),
|
|
117
122
|
}, async (input) => {
|
|
118
123
|
const result = await (0, recall_1.performRecall)({ client, embed: embeddings_1.embed }, input);
|
|
119
124
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
120
125
|
});
|
|
126
|
+
server.tool('memory_get', "Fetch one Fact/Skill/Scenario/Wiki page in full by its uid. memory_recall truncates every item it lists (500 chars by default), so use this to read anything longer than a paragraph — take the uid from a memory_recall result.", {
|
|
127
|
+
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
128
|
+
uid: zod_1.z.string().min(1).describe('The uid from a memory_recall result.'),
|
|
129
|
+
}, async (input) => {
|
|
130
|
+
const result = input.type === 'Fact'
|
|
131
|
+
? await client.getFact({ uid: input.uid })
|
|
132
|
+
: input.type === 'Skill'
|
|
133
|
+
? await client.getSkill({ uid: input.uid })
|
|
134
|
+
: input.type === 'Scenario'
|
|
135
|
+
? await client.getScenario({ uid: input.uid })
|
|
136
|
+
: await client.getWikiPage({ uid: input.uid });
|
|
137
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
138
|
+
});
|
|
121
139
|
server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the SE AI Memory Hub. Written Team visibility automatically if the attached repo is already linked to a team, otherwise Private. See memory_getSkillGuide for which type to use and which fields it needs. The current repo is detected automatically unless you pass an explicit repo (from memory_listRepos) to target a different one.', {
|
|
122
140
|
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
123
141
|
content: zod_1.z.string().optional().describe('Required for Fact, Skill, Wiki.'),
|
package/dist/recall.js
CHANGED
|
@@ -1,32 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.performRecall = void 0;
|
|
4
|
+
// In-band, not just a JSON field: an agent skimming the text must still see the cut and the uid.
|
|
5
|
+
function markCuts(type, listKey, textKey, result) {
|
|
6
|
+
const items = result?.[listKey];
|
|
7
|
+
if (!Array.isArray(items)) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
const marked = items.map((item) => {
|
|
11
|
+
if (!item.truncated) {
|
|
12
|
+
return item;
|
|
13
|
+
}
|
|
14
|
+
const { truncated: _truncated, fullLength, ...rest } = item;
|
|
15
|
+
const text = typeof rest[textKey] === 'string' ? rest[textKey] : '';
|
|
16
|
+
const of = typeof fullLength === 'number' ? ` of ${fullLength.toLocaleString('en-US')}` : '';
|
|
17
|
+
return {
|
|
18
|
+
...rest,
|
|
19
|
+
[textKey]: `${text}\n[cut at ${text.length}${of} chars — memory_get type=${type} uid=${rest.uid}]`,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return { ...result, [listKey]: marked };
|
|
23
|
+
}
|
|
4
24
|
// Extracted from four near-identical memory_recall/listSkills/recallScenarios/
|
|
5
25
|
// recallWiki tool handlers — see save.ts's comment for why (index.ts's module-scope
|
|
6
26
|
// side effects make it untestable directly).
|
|
7
27
|
async function performRecall(deps, input) {
|
|
8
28
|
const { client, embed } = deps;
|
|
9
29
|
const queryEmbedding = input.query ? await embed(input.query).catch(() => undefined) : undefined;
|
|
30
|
+
const caps = { maxCharsPerItem: input.maxCharsPerItem, maxTotalChars: input.maxTotalChars };
|
|
10
31
|
switch (input.type) {
|
|
11
32
|
case 'Fact':
|
|
12
|
-
return client.recall({
|
|
33
|
+
return markCuts('Fact', 'facts', 'content', await client.recall({
|
|
13
34
|
scope: input.scope,
|
|
14
35
|
query: input.query,
|
|
15
36
|
tags: input.tags,
|
|
16
37
|
externalRef: input.externalRef,
|
|
17
38
|
queryEmbedding,
|
|
18
|
-
|
|
39
|
+
...caps,
|
|
40
|
+
}));
|
|
19
41
|
case 'Skill':
|
|
20
|
-
return client.listSkills({ scope: input.scope, query: input.query, queryEmbedding });
|
|
42
|
+
return markCuts('Skill', 'skills', 'content', await client.listSkills({ scope: input.scope, query: input.query, queryEmbedding, ...caps }));
|
|
21
43
|
case 'Scenario':
|
|
22
|
-
return client.recallScenarios({
|
|
44
|
+
return markCuts('Scenario', 'scenarios', 'summary', await client.recallScenarios({
|
|
23
45
|
scope: input.scope,
|
|
24
46
|
query: input.query,
|
|
25
47
|
externalRef: input.externalRef,
|
|
26
48
|
queryEmbedding,
|
|
27
|
-
|
|
49
|
+
...caps,
|
|
50
|
+
}));
|
|
28
51
|
case 'Wiki':
|
|
29
|
-
return client.recallWiki({ scope: input.scope, query: input.query, queryEmbedding });
|
|
52
|
+
return markCuts('Wiki', 'pages', 'content', await client.recallWiki({ scope: input.scope, query: input.query, queryEmbedding, ...caps }));
|
|
30
53
|
}
|
|
31
54
|
}
|
|
32
55
|
exports.performRecall = performRecall;
|
package/dist/setup.js
CHANGED
|
@@ -131,17 +131,26 @@ function writeUserEnv(path, env) {
|
|
|
131
131
|
writeJson(path, settings);
|
|
132
132
|
}
|
|
133
133
|
exports.writeUserEnv = writeUserEnv;
|
|
134
|
-
//
|
|
135
|
-
//
|
|
134
|
+
// Only our own entries are touched — a developer may have their own SessionStart hooks.
|
|
135
|
+
// "Ours" is the script's identity, not its exact path: setup-dev.sh registers the repo
|
|
136
|
+
// checkout and this installer ~/.claude/memory-hub-hook, so matching the exact string
|
|
137
|
+
// lets both stack copies of the same script. Replaces, keeping any timeout it carried.
|
|
136
138
|
function registerSessionStartHook(path, hookPath) {
|
|
137
139
|
const settings = readJson(path);
|
|
138
140
|
const hooks = (settings.hooks ||= {});
|
|
139
141
|
const entries = (hooks.SessionStart ||= []);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const isOurs = (command) => typeof command === 'string' &&
|
|
143
|
+
(command.trim() === hookPath || command.trim().endsWith('memory-hub-hook/session-start.sh'));
|
|
144
|
+
const ours = entries.flatMap((entry) => (entry.hooks || []).filter((h) => isOurs(h.command)));
|
|
145
|
+
const already = ours.length === 1 && ours[0].command === hookPath;
|
|
146
|
+
const kept = { type: 'command', ...ours[0], command: hookPath };
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
entry.hooks = (entry.hooks || []).filter((h) => !isOurs(h.command));
|
|
149
|
+
}
|
|
150
|
+
hooks.SessionStart = entries.filter((entry) => entry.hooks.length > 0);
|
|
151
|
+
hooks.SessionStart.push({ hooks: [kept] });
|
|
143
152
|
writeJson(path, settings);
|
|
144
|
-
return already;
|
|
153
|
+
return { already, replaced: already ? 0 : ours.length };
|
|
145
154
|
}
|
|
146
155
|
exports.registerSessionStartHook = registerSessionStartHook;
|
|
147
156
|
function installAssets() {
|
|
@@ -260,8 +269,13 @@ async function runSetup(argv = []) {
|
|
|
260
269
|
// Code gives it, not from the MCP server's env block.
|
|
261
270
|
writeUserEnv((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), env);
|
|
262
271
|
const { hookPath } = installAssets();
|
|
263
|
-
const already = registerSessionStartHook((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), hookPath);
|
|
264
|
-
|
|
272
|
+
const { already, replaced } = registerSessionStartHook((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), hookPath);
|
|
273
|
+
const note = already
|
|
274
|
+
? ' (already registered)'
|
|
275
|
+
: replaced > 0
|
|
276
|
+
? ` (replaced ${replaced} earlier registration${replaced > 1 ? 's' : ''})`
|
|
277
|
+
: '';
|
|
278
|
+
console.log(` SessionStart hook -> ${hookPath}${note}`);
|
|
265
279
|
console.log(' skill -> ~/.claude/skills/se-ai-memory-hub/SKILL.md');
|
|
266
280
|
for (const tool of ['curl', 'jq']) {
|
|
267
281
|
if ((0, child_process_1.spawnSync)('which', [tool]).status !== 0) {
|
package/package.json
CHANGED
package/skill-guide.md
CHANGED
|
@@ -27,10 +27,16 @@ filters to facts/scenarios linked to that ticket, and returns nothing (not
|
|
|
27
27
|
everything) if the ref was never used before.
|
|
28
28
|
|
|
29
29
|
Recall truncates every item it lists — 500 characters each, 6000 across the
|
|
30
|
-
result — so a Skill long enough to be worth writing down is
|
|
31
|
-
readable from a recall.
|
|
32
|
-
`
|
|
33
|
-
|
|
30
|
+
result — so a Skill long enough to be worth writing down is rarely fully
|
|
31
|
+
readable from a recall. A cut item ends with a marker such as
|
|
32
|
+
`[cut at 500 of 3,412 chars — memory_get type=Skill uid=<uid>]`; call
|
|
33
|
+
`memory_get` with that `type` and `uid` for the whole thing. No marker means
|
|
34
|
+
the item is complete. A query that is exactly a Skill's or Wiki page's title
|
|
35
|
+
returns that item whole (up to the 6000 total), so use the exact title when you
|
|
36
|
+
know it. Raise `maxCharsPerItem` / `maxTotalChars` instead only when you need
|
|
37
|
+
several long items at once. If `memory_get` or those parameters are missing
|
|
38
|
+
from your tools, your memory-hub-mcp build is stale: tell the user to rerun
|
|
39
|
+
`./scripts/setup-dev.sh` (or `cd memory-hub-mcp && yarn build`) and restart.
|
|
34
40
|
|
|
35
41
|
## Save at the end of a task
|
|
36
42
|
|
|
@@ -51,7 +57,9 @@ Call `memory_save` with a `type` of `'Fact'`, `'Skill'`, `'Scenario'`, or
|
|
|
51
57
|
different repo explicitly" below).
|
|
52
58
|
- **`type: 'Skill'`** — a reusable procedure or fix you'd want to reach
|
|
53
59
|
for again. Pass `title` and `content` (the actual steps/code), and
|
|
54
|
-
optionally `tags`. The repo is attached automatically, as above.
|
|
60
|
+
optionally `tags`. The repo is attached automatically, as above. Recall
|
|
61
|
+
shows only the first 500 characters, so put the answer — the exact
|
|
62
|
+
endpoint, command, or rule — in the first ~400 and the background after it.
|
|
55
63
|
|
|
56
64
|
`tags` (on Fact/Skill/Wiki saves, and on `memory_recall`) is a fixed
|
|
57
65
|
picklist, not a free-form string — pick from `ConnectedFunction`,
|