@skedulo/memory-hub-mcp 0.2.2 → 0.2.4
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 +44 -21
- package/assets/session-stop.sh +5 -3
- package/assets/user-prompt-submit.sh +124 -0
- package/dist/cli.js +7 -0
- package/dist/client.js +27 -0
- package/dist/embed-cli.js +41 -0
- package/dist/embeddings.js +6 -1
- package/dist/index.js +33 -17
- package/dist/revise.js +85 -0
- package/dist/setup.js +20 -10
- package/dist/similar-notice.js +29 -0
- package/package.json +2 -2
- package/skill-guide.md +30 -0
package/assets/session-start.sh
CHANGED
|
@@ -222,8 +222,14 @@ count_items() {
|
|
|
222
222
|
NL=$'\n'
|
|
223
223
|
CONTEXT=""
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
omission_footer() {
|
|
226
|
+
printf '_Omitted for space: %s. Ask memory_recall with a query._' "$1"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
# Sized for every section being skipped, so the footer can never itself be the thing squeezed out.
|
|
230
|
+
FOOTER_NAMES="Your memory-hub facts, Team memory-hub facts, Your memory-hub skills, Team memory-hub skills"
|
|
231
|
+
[ -n "$REPO_UID" ] && FOOTER_NAMES="Team knowledge for ${REPO_NAME}, ${FOOTER_NAMES}"
|
|
232
|
+
FOOTER_RESERVE=$(($(omission_footer "$FOOTER_NAMES" | wc -m) + 2))
|
|
227
233
|
REMAINING=$((BUDGET - FOOTER_RESERVE))
|
|
228
234
|
SKIPPED=""
|
|
229
235
|
|
|
@@ -233,24 +239,31 @@ SECTIONS_LEFT=4
|
|
|
233
239
|
|
|
234
240
|
# Emits at most $1 chars of $2, whole items only. $3 is what the server holds — its cap has usually dropped items already.
|
|
235
241
|
clip_to_budget() {
|
|
236
|
-
local budget="$1" text="$2" avail="$3" out="" line used
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
seen
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
shown
|
|
242
|
+
local budget="$1" text="$2" avail="$3" out="" line used shown seen marker attempt
|
|
243
|
+
# The "showing N of M" marker is part of what the section costs, so a second pass leaves room for it.
|
|
244
|
+
for attempt in 1 2; do
|
|
245
|
+
out="" used=0 shown=0 seen=0 marker=""
|
|
246
|
+
while IFS= read -r line; do
|
|
247
|
+
[ -n "$line" ] || continue
|
|
248
|
+
seen=$((seen + 1))
|
|
249
|
+
if [ "$shown" -eq "$((seen - 1))" ] && [ $((used + ${#line} + 1)) -le "$budget" ]; then
|
|
250
|
+
out="${out}${line}${NL}"
|
|
251
|
+
used=$((used + ${#line} + 1))
|
|
252
|
+
shown=$((shown + 1))
|
|
253
|
+
fi
|
|
254
|
+
done <<< "$text"
|
|
255
|
+
[ "$shown" -gt 0 ] || return 0
|
|
256
|
+
# Pre-dedup, so team counts can overstate by items also shown under self/repo.
|
|
257
|
+
[ "$avail" -ge "$seen" ] 2>/dev/null || avail="$seen"
|
|
258
|
+
# A bare memory_recall returns newest-first — the same items already above.
|
|
259
|
+
[ "$avail" -gt "$shown" ] && marker=$(printf '_showing %d of %d — ask memory_recall with a query for the rest._' "$shown" "$avail" | jq -R .)
|
|
260
|
+
if [ -z "$marker" ] || [ $((used + ${#marker} + 1)) -le "$budget" ]; then
|
|
261
|
+
break
|
|
244
262
|
fi
|
|
245
|
-
|
|
263
|
+
budget=$((budget - ${#marker} - 1))
|
|
264
|
+
done
|
|
246
265
|
printf '%s' "$out"
|
|
247
|
-
[ "$
|
|
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
|
|
266
|
+
[ -z "$marker" ] || printf '%s\n' "$marker"
|
|
254
267
|
}
|
|
255
268
|
|
|
256
269
|
add_section() {
|
|
@@ -359,9 +372,19 @@ DIAG="${DIAG}_"
|
|
|
359
372
|
# budget even when nothing else does.
|
|
360
373
|
# A stale build cannot warn about itself, so the hook, which a git pull does refresh, has to.
|
|
361
374
|
MCP_DIR="${MEMORY_HUB_MCP_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../memory-hub-mcp" 2>/dev/null && pwd)}"
|
|
375
|
+
# Content, not mtimes: a branch switch or pull rewrites files without changing what they say.
|
|
376
|
+
mcp_build_is_stale() {
|
|
377
|
+
local dir="$1" current
|
|
378
|
+
[ -f "$dir/dist/index.js" ] || return 1
|
|
379
|
+
if [ -f "$dir/dist/.source-hash" ] && [ -f "$dir/scripts/source-hash.sh" ]; then
|
|
380
|
+
current=$(bash "$dir/scripts/source-hash.sh" 2>/dev/null)
|
|
381
|
+
[ -z "$current" ] || { [ "$current" != "$(cat "$dir/dist/.source-hash" 2>/dev/null)" ]; return; }
|
|
382
|
+
fi
|
|
383
|
+
[ -n "$(find "$dir/src" "$dir/skill-guide.md" -type f \( -name '*.ts' -o -name '*.md' \) ! -name '*.test.ts' -newer "$dir/dist/index.js" 2>/dev/null | head -1)" ]
|
|
384
|
+
}
|
|
385
|
+
|
|
362
386
|
STALE_MCP=""
|
|
363
|
-
if [ -n "$MCP_DIR" ] &&
|
|
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
|
|
387
|
+
if [ -n "$MCP_DIR" ] && mcp_build_is_stale "$MCP_DIR"; then
|
|
365
388
|
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
389
|
fi
|
|
367
390
|
|
|
@@ -387,7 +410,7 @@ add_section "Team memory-hub skills" "$SKILLS_TEAM" "$SKILLS_TEAM_N"
|
|
|
387
410
|
|
|
388
411
|
# A section that never fit is the omission most likely to be read as "there is nothing there".
|
|
389
412
|
if [ -n "$SKIPPED" ]; then
|
|
390
|
-
CONTEXT="${CONTEXT}
|
|
413
|
+
CONTEXT="${CONTEXT}$(omission_footer "$SKIPPED")${NL}${NL}"
|
|
391
414
|
fi
|
|
392
415
|
|
|
393
416
|
CONTEXT="${CONTEXT}${DIAG}${NL}"
|
package/assets/session-stop.sh
CHANGED
|
@@ -41,14 +41,16 @@ would be worth knowing next time, in this repo or across the team — not
|
|
|
41
41
|
narration or exploration. If you already called memory_save with type
|
|
42
42
|
"Fact" or "Scenario" for it earlier in this same session, do not save it
|
|
43
43
|
again. If nothing in this session qualifies, do nothing and finish.
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
For each item that qualifies, first call memory_recall with a query for it.
|
|
45
|
+
If one of your own memories already covers it, call memory_update on that
|
|
46
|
+
memory with the revised full text instead of saving a copy. Otherwise call
|
|
47
|
+
memory_save (type "Fact" or "Scenario"). Never delete anything.'
|
|
46
48
|
|
|
47
49
|
LOG_FILE="${TMPDIR:-/tmp}/memory-hub-stop-hook.log"
|
|
48
50
|
{
|
|
49
51
|
echo "---- $(date -u +%FT%TZ) session=$SESSION_ID ----"
|
|
50
52
|
MEMORY_HUB_STOP_HOOK_ACTIVE=1 claude -p --resume "$SESSION_ID" \
|
|
51
|
-
--allowedTools "mcp__memory-hub__memory_recall,mcp__memory-hub__memory_save" \
|
|
53
|
+
--allowedTools "mcp__memory-hub__memory_recall,mcp__memory-hub__memory_save,mcp__memory-hub__memory_update" \
|
|
52
54
|
--permission-prompts none \
|
|
53
55
|
--model haiku \
|
|
54
56
|
--no-session-persistence \
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# UserPromptSubmit hook: on the first substantive prompt of a session, recalls the memories most
|
|
3
|
+
# relevant to that prompt and injects them. Must never block or crash a prompt — every failure
|
|
4
|
+
# degrades to injecting nothing.
|
|
5
|
+
set -u
|
|
6
|
+
|
|
7
|
+
TOKEN="${MEMORY_HUB_MCP_TOKEN:-}"
|
|
8
|
+
[ -n "$TOKEN" ] || exit 0
|
|
9
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
10
|
+
|
|
11
|
+
# Same default as session-start.sh; change both together.
|
|
12
|
+
FUNCTION_URL="${MEMORY_HUB_FUNCTION_URL:-https://dev-api.test.skl.io/function/memory-hub/memory-hub}"
|
|
13
|
+
BUDGET="${MEMORY_HUB_PROMPT_MAX_CHARS:-6000}"
|
|
14
|
+
[ "$BUDGET" -gt 9000 ] && BUDGET=9000
|
|
15
|
+
FACTS_N="${MEMORY_HUB_PROMPT_FACTS:-5}"
|
|
16
|
+
# Scores in this corpus are compressed: relevant items land near 0.4-0.7, unrelated ones near 0.3-0.4,
|
|
17
|
+
# so an item must clear a floor and stay close to the best match across both lists.
|
|
18
|
+
MIN_SIMILARITY="${MEMORY_HUB_PROMPT_MIN_SIMILARITY:-0.35}"
|
|
19
|
+
SIMILARITY_BAND="${MEMORY_HUB_PROMPT_SIMILARITY_BAND:-0.25}"
|
|
20
|
+
SKILLS_N="${MEMORY_HUB_PROMPT_SKILLS:-3}"
|
|
21
|
+
ITEM_CAP=500
|
|
22
|
+
NL=$'\n'
|
|
23
|
+
|
|
24
|
+
INPUT=$(cat)
|
|
25
|
+
SESSION_ID=$(printf '%s' "$INPUT" | jq -r '.session_id // empty' 2>/dev/null | tr -cd 'A-Za-z0-9_-')
|
|
26
|
+
PROMPT=$(printf '%s' "$INPUT" | jq -r '.prompt // empty' 2>/dev/null)
|
|
27
|
+
[ -n "$SESSION_ID" ] && [ -n "$PROMPT" ] || exit 0
|
|
28
|
+
|
|
29
|
+
# A slash command or a one-line reply has nothing to match on, and must not use up the session's one shot.
|
|
30
|
+
case "$PROMPT" in /*) exit 0 ;; esac
|
|
31
|
+
[ "$(printf '%s' "$PROMPT" | wc -w)" -ge "${MEMORY_HUB_MIN_PROMPT_WORDS:-4}" ] || exit 0
|
|
32
|
+
|
|
33
|
+
STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
|
|
34
|
+
mkdir -p "$STATE_DIR" 2>/dev/null || exit 0
|
|
35
|
+
find "$STATE_DIR" -type f -mtime +7 -delete 2>/dev/null || true
|
|
36
|
+
MARKER="$STATE_DIR/$SESSION_ID"
|
|
37
|
+
[ -e "$MARKER" ] && exit 0
|
|
38
|
+
# Marked before any work, so a slow or failing function costs one prompt, not every prompt.
|
|
39
|
+
: > "$MARKER" 2>/dev/null || exit 0
|
|
40
|
+
|
|
41
|
+
TMP_DIR=$(mktemp -d)
|
|
42
|
+
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
43
|
+
|
|
44
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
|
45
|
+
EMBED=()
|
|
46
|
+
if [ -n "${MEMORY_HUB_EMBED_CMD:-}" ]; then
|
|
47
|
+
EMBED=("$MEMORY_HUB_EMBED_CMD")
|
|
48
|
+
elif [ -f "$HOOK_DIR/../memory-hub-mcp/dist/cli.js" ] && command -v node >/dev/null 2>&1; then
|
|
49
|
+
EMBED=(node "$HOOK_DIR/../memory-hub-mcp/dist/cli.js" embed)
|
|
50
|
+
elif command -v memory-hub-mcp >/dev/null 2>&1; then
|
|
51
|
+
EMBED=(memory-hub-mcp embed)
|
|
52
|
+
else
|
|
53
|
+
SERVER_CMD=$(jq -r '.mcpServers["memory-hub"].command // empty' "$HOME/.claude.json" 2>/dev/null)
|
|
54
|
+
[ -n "$SERVER_CMD" ] && [ -x "$SERVER_CMD" ] && EMBED=("$SERVER_CMD" embed)
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
VECTOR=""
|
|
58
|
+
if [ "${#EMBED[@]}" -gt 0 ]; then
|
|
59
|
+
VECTOR=$(printf '%s' "$PROMPT" | MEMORY_HUB_EMBED_TIMEOUT_MS=4000 "${EMBED[@]}" 2>/dev/null) || VECTOR=""
|
|
60
|
+
printf '%s' "$VECTOR" | jq -e 'type == "array" and length > 0' >/dev/null 2>&1 || VECTOR=""
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
QUERY=$(printf '%s' "$PROMPT" | head -c 300)
|
|
64
|
+
body() {
|
|
65
|
+
jq -nc --arg q "$QUERY" --arg v "${VECTOR:-null}" --argjson cap "$((BUDGET / 2))" \
|
|
66
|
+
--argjson min "$MIN_SIMILARITY" '
|
|
67
|
+
{scope: "team", query: $q, diverse: true, maxCharsPerItem: 500, maxTotalChars: $cap}
|
|
68
|
+
+ (if $v == "null" then {} else {queryEmbedding: ($v | fromjson), minSimilarity: $min} end)'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
call() {
|
|
72
|
+
local path="$1" out_file="$2"
|
|
73
|
+
if [ -n "${MEMORY_HUB_FIXTURE_DIR:-}" ]; then
|
|
74
|
+
mkdir -p "$MEMORY_HUB_FIXTURE_DIR/requests"
|
|
75
|
+
body > "$MEMORY_HUB_FIXTURE_DIR/requests/$(basename "$out_file")" 2>/dev/null
|
|
76
|
+
cp "$MEMORY_HUB_FIXTURE_DIR/$(basename "$out_file")" "$out_file" 2>/dev/null || true
|
|
77
|
+
return 0
|
|
78
|
+
fi
|
|
79
|
+
curl -sS --connect-timeout 3 --max-time 7 \
|
|
80
|
+
-X POST "${FUNCTION_URL}${path}" \
|
|
81
|
+
-H "Authorization: Bearer ${TOKEN}" \
|
|
82
|
+
-H "Content-Type: application/json" \
|
|
83
|
+
-d "$(body)" \
|
|
84
|
+
-o "$out_file" 2>/dev/null || true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
call "/memory/recall" "$TMP_DIR/facts.json" &
|
|
88
|
+
call "/memory/list-skills" "$TMP_DIR/skills.json" &
|
|
89
|
+
wait
|
|
90
|
+
|
|
91
|
+
CLOSE_FENCE='if ([match("```"; "g")] | length) % 2 == 1 then . + "\n```" else . end'
|
|
92
|
+
INDENT='gsub("\n"; "\n ")'
|
|
93
|
+
STAMP='(if .lastModifiedDate then " (updated " + .lastModifiedDate[0:10] + ")" else "" end)'
|
|
94
|
+
ELIDE="if length >= $ITEM_CAP then . + \"…\" else . end"
|
|
95
|
+
cut_pointer() {
|
|
96
|
+
printf '(if .truncated then " [cut at \\(.content | length) of \\(.fullLength) — memory_get type=%s uid=\\(.uid)]" else "" end)' "$1"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Judged across both lists: one list alone may have no strong match, and would keep its weak ones.
|
|
100
|
+
BEST=$(jq -rs '[.[] | ((.facts // []) + (.skills // []))[] | .similarity // empty] | max // empty' "$TMP_DIR/facts.json" "$TMP_DIR/skills.json" 2>/dev/null)
|
|
101
|
+
FLOOR=-1
|
|
102
|
+
[ -n "$BEST" ] && FLOOR=$(jq -n --argjson best "$BEST" --argjson band "$SIMILARITY_BAND" '$best - $band')
|
|
103
|
+
KEEP='select(.similarity == null or .similarity >= $floor)'
|
|
104
|
+
|
|
105
|
+
HEADING="## Memory relevant to this prompt"
|
|
106
|
+
FOOTER="_Matched to your prompt, not newest-first. memory_recall with a query finds more; memory_get fetches a cut item._"
|
|
107
|
+
room=$((BUDGET - ${#HEADING} - ${#FOOTER} - 4))
|
|
108
|
+
BODY=""
|
|
109
|
+
used=0
|
|
110
|
+
# Whole items only: each item is one logical record, so it is shown entirely or not at all.
|
|
111
|
+
while IFS= read -r -d $'\x1e' item; do
|
|
112
|
+
[ -n "$item" ] || continue
|
|
113
|
+
if [ $((used + ${#item} + 1)) -le "$room" ]; then
|
|
114
|
+
BODY="${BODY}${item}${NL}"
|
|
115
|
+
used=$((used + ${#item} + 1))
|
|
116
|
+
fi
|
|
117
|
+
done < <(
|
|
118
|
+
jq -j --argjson floor "$FLOOR" "[.facts[]? | $KEEP][:$FACTS_N][] | ((\"- \" + (.content | $ELIDE) + $(cut_pointer Fact) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/facts.json" 2>/dev/null
|
|
119
|
+
jq -j --argjson floor "$FLOOR" "[.skills[]? | $KEEP][:$SKILLS_N][] | ((\"- \" + .title + \": \" + (.content | $ELIDE) + $(cut_pointer Skill) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/skills.json" 2>/dev/null
|
|
120
|
+
)
|
|
121
|
+
[ -n "$BODY" ] || exit 0
|
|
122
|
+
|
|
123
|
+
CONTEXT="${HEADING}${NL}${BODY}${NL}${FOOTER}${NL}"
|
|
124
|
+
jq -nc --arg c "$CONTEXT" '{hookSpecificOutput: {hookEventName: "UserPromptSubmit", additionalContext: $c}}'
|
package/dist/cli.js
CHANGED
|
@@ -12,12 +12,19 @@ if (command === 'setup') {
|
|
|
12
12
|
process.exit(1);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
else if (command === 'embed') {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
+
const { runEmbed, readProcessStdin } = require('./embed-cli');
|
|
18
|
+
runEmbed(process.argv.slice(3), { readStdin: readProcessStdin, write: (line) => console.log(line) }).then((code) => process.exit(code));
|
|
19
|
+
}
|
|
15
20
|
else if (command === '--help' || command === '-h') {
|
|
16
21
|
console.log(`memory-hub-mcp — MCP server for the SE AI Memory Hub
|
|
17
22
|
|
|
18
23
|
memory-hub-mcp setup log in, then wire up Claude Code (MCP server + SessionStart
|
|
19
24
|
hook + skill) and/or Claude Desktop (MCP server), and verify
|
|
20
25
|
the token. Pass --code, --desktop or --both to skip the prompt.
|
|
26
|
+
memory-hub-mcp embed print the embedding of the text on stdin (or the arguments) as JSON;
|
|
27
|
+
used by the UserPromptSubmit hook. Exits non-zero if it cannot.
|
|
21
28
|
memory-hub-mcp run the MCP server on stdio (how a host launches it)
|
|
22
29
|
`);
|
|
23
30
|
}
|
package/dist/client.js
CHANGED
|
@@ -20,6 +20,33 @@ class MemoryHubClient {
|
|
|
20
20
|
recall(input) {
|
|
21
21
|
return this.post('/memory/recall', input);
|
|
22
22
|
}
|
|
23
|
+
updateFact(input) {
|
|
24
|
+
return this.post('/memory/update-fact', input);
|
|
25
|
+
}
|
|
26
|
+
updateSkill(input) {
|
|
27
|
+
return this.post('/memory/update-skill', input);
|
|
28
|
+
}
|
|
29
|
+
updateScenario(input) {
|
|
30
|
+
return this.post('/memory/update-scenario', input);
|
|
31
|
+
}
|
|
32
|
+
updateWikiPage(input) {
|
|
33
|
+
return this.post('/memory/update-wiki-page', input);
|
|
34
|
+
}
|
|
35
|
+
deleteFact(input) {
|
|
36
|
+
return this.post('/memory/delete-fact', input);
|
|
37
|
+
}
|
|
38
|
+
deleteSkill(input) {
|
|
39
|
+
return this.post('/memory/delete-skill', input);
|
|
40
|
+
}
|
|
41
|
+
deleteScenario(input) {
|
|
42
|
+
return this.post('/memory/delete-scenario', input);
|
|
43
|
+
}
|
|
44
|
+
deleteWikiPage(input) {
|
|
45
|
+
return this.post('/memory/delete-wiki-page', input);
|
|
46
|
+
}
|
|
47
|
+
updateTask(input) {
|
|
48
|
+
return this.post('/memory/update-task', input);
|
|
49
|
+
}
|
|
23
50
|
saveFact(input) {
|
|
24
51
|
return this.post('/memory/save-fact', input);
|
|
25
52
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readProcessStdin = exports.runEmbed = void 0;
|
|
4
|
+
const embeddings_1 = require("./embeddings");
|
|
5
|
+
const MAX_TEXT_CHARS = 2000;
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 8000;
|
|
7
|
+
// Exit code, not process.exit, so a hook can treat any non-zero as "no embedding" and carry on.
|
|
8
|
+
async function runEmbed(args, deps) {
|
|
9
|
+
const text = (args.length > 0 ? args.join(' ') : await deps.readStdin()).trim().slice(0, MAX_TEXT_CHARS);
|
|
10
|
+
if (!text) {
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
let timer;
|
|
14
|
+
const timeout = new Promise((_, reject) => {
|
|
15
|
+
timer = setTimeout(() => reject(new Error('embed timed out')), deps.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
const vector = await Promise.race([(deps.embedText ?? embeddings_1.embed)(text), timeout]);
|
|
19
|
+
deps.write(JSON.stringify(vector));
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return 2;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.runEmbed = runEmbed;
|
|
30
|
+
function readProcessStdin() {
|
|
31
|
+
if (process.stdin.isTTY) {
|
|
32
|
+
return Promise.resolve('');
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
let data = '';
|
|
36
|
+
process.stdin.setEncoding('utf8');
|
|
37
|
+
process.stdin.on('data', (chunk) => (data += chunk));
|
|
38
|
+
process.stdin.on('end', () => resolve(data));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.readProcessStdin = readProcessStdin;
|
package/dist/embeddings.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.embed = void 0;
|
|
3
|
+
exports.embed = exports.MODEL_CACHE_DIR = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
4
6
|
const transformers_1 = require("@xenova/transformers");
|
|
7
|
+
// Not under node_modules: a global `npm i -g` update wipes that, and a slow network can then miss the load timeout.
|
|
8
|
+
exports.MODEL_CACHE_DIR = process.env.MEMORY_HUB_MODEL_CACHE || (0, path_1.join)((0, os_1.homedir)(), '.cache', 'memory-hub', 'models');
|
|
9
|
+
transformers_1.env.cacheDir = exports.MODEL_CACHE_DIR;
|
|
5
10
|
// Loaded lazily, once per process, on the first embed() call — a session that
|
|
6
11
|
// never saves or recalls anything pays zero cost, and every call after the
|
|
7
12
|
// first reuses the same loaded model instead of reloading it. The model's
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ const embeddings_1 = require("./embeddings");
|
|
|
14
14
|
const save_1 = require("./save");
|
|
15
15
|
const recall_1 = require("./recall");
|
|
16
16
|
const guide_check_1 = require("./guide-check");
|
|
17
|
+
const revise_1 = require("./revise");
|
|
18
|
+
const similar_notice_1 = require("./similar-notice");
|
|
17
19
|
const session_context_1 = require("./session-context");
|
|
18
20
|
// Must match the AgentFacts/AgentSkills/AgentWikiPages Tags custom field's Picklist
|
|
19
21
|
// allowedValues (src/object-model/custom-fields/{AgentFacts,AgentSkills,AgentWikiPages}/*-Tags.custom-field.json)
|
|
@@ -83,22 +85,10 @@ async function joinNoticeBlocks() {
|
|
|
83
85
|
},
|
|
84
86
|
];
|
|
85
87
|
}
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function duplicateNoticeBlocks(result) {
|
|
91
|
-
const match = result.possibleDuplicate;
|
|
92
|
-
if (!match) {
|
|
93
|
-
return [];
|
|
94
|
-
}
|
|
95
|
-
const when = match.lastModifiedDate ? ` on ${match.lastModifiedDate.slice(0, 10)}` : '';
|
|
96
|
-
return [
|
|
97
|
-
{
|
|
98
|
-
type: 'text',
|
|
99
|
-
text: `Note: this looks similar to something already saved${when}: "${match.content}". Saved as new anyway — consider recalling and updating that one instead next time.`,
|
|
100
|
-
},
|
|
101
|
-
];
|
|
88
|
+
// The save has already happened (dedup only warns), so this just makes the match visible to the agent.
|
|
89
|
+
function similarNoticeBlocks(type, result) {
|
|
90
|
+
const text = (0, similar_notice_1.similarNotice)(type, result);
|
|
91
|
+
return text ? [{ type: 'text', text }] : [];
|
|
102
92
|
}
|
|
103
93
|
server.tool('memory_getSkillGuide', 'Get the current SE AI Memory Hub usage guide — when to recall, what to save where, sharing rules, repo linking. Call this first when the se-ai-memory-hub skill triggers.', {}, async () => {
|
|
104
94
|
// Read from disk on every call, not cached at module load — this is the whole point:
|
|
@@ -156,7 +146,7 @@ server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the SE
|
|
|
156
146
|
return {
|
|
157
147
|
content: [
|
|
158
148
|
...(await joinNoticeBlocks()),
|
|
159
|
-
...
|
|
149
|
+
...similarNoticeBlocks(input.type, result),
|
|
160
150
|
{ type: 'text', text: JSON.stringify(result) },
|
|
161
151
|
],
|
|
162
152
|
};
|
|
@@ -205,6 +195,32 @@ server.tool('memory_listTeams', "List the memory teams this developer belongs to
|
|
|
205
195
|
const { teams } = await client.listTeams();
|
|
206
196
|
return { content: [{ type: 'text', text: JSON.stringify({ teams }) }] };
|
|
207
197
|
});
|
|
198
|
+
server.tool('memory_update', "Revise a memory you saved, in place, instead of saving a second copy. Pass the uid (from memory_recall, memory_get or a memory_save notice) and only the fields to change: content and tags for a Fact; title, content and tags for a Skill or Wiki page; summary for a Scenario; repo (a uid from memory_listRepos, or null for not project-specific) for any. Only the author can update. When this repeats or corrects something you already saved, use this, not memory_save.", {
|
|
199
|
+
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
200
|
+
uid: zod_1.z.string().min(1),
|
|
201
|
+
content: zod_1.z.string().min(1).optional().describe('Fact, Skill, Wiki: the full new text, not a patch.'),
|
|
202
|
+
title: zod_1.z.string().min(1).optional().describe('Skill, Wiki only.'),
|
|
203
|
+
summary: zod_1.z.string().min(1).optional().describe('Scenario only: the full new summary.'),
|
|
204
|
+
tags: zod_1.z.array(zod_1.z.enum(TAG_VALUES)).optional().describe('Fact, Skill, Wiki only. Replaces the existing tags.'),
|
|
205
|
+
repo: zod_1.z.string().min(1).nullable().optional().describe('A DevRepos uid, or null to clear it.'),
|
|
206
|
+
}, async (input) => {
|
|
207
|
+
const result = await (0, revise_1.performUpdate)({ client, embed: embeddings_1.embed }, input);
|
|
208
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
209
|
+
});
|
|
210
|
+
server.tool('memory_delete', "Permanently delete one memory you saved. Use it to remove a copy you have just merged into another, or a memory that is wrong or obsolete. It cannot be undone and only the author can delete. Prefer memory_update when the memory is still partly right.", {
|
|
211
|
+
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
212
|
+
uid: zod_1.z.string().min(1),
|
|
213
|
+
}, async (input) => {
|
|
214
|
+
const result = await (0, revise_1.performDelete)({ client }, input);
|
|
215
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
216
|
+
});
|
|
217
|
+
server.tool('memory_setTaskStatus', "Mark a ticket's task Done when its work is finished, or Open to reopen it. Takes the ticket ref used with memory_save externalRef, e.g. 'SOL-1234'. Anyone on the task's team can do this.", {
|
|
218
|
+
externalRef: zod_1.z.string().min(1),
|
|
219
|
+
status: zod_1.z.enum(['Open', 'Done']),
|
|
220
|
+
}, async (input) => {
|
|
221
|
+
const result = await (0, revise_1.performSetTaskStatus)({ client }, input);
|
|
222
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
223
|
+
});
|
|
208
224
|
server.tool('memory_listRepos', "List repos across this developer's teams, with an optional substring query filter, for targeting memory_save or memory_moveResourceRepo at a repo other than the current directory.", {
|
|
209
225
|
query: zod_1.z.string().optional().describe('Case-insensitive substring filter on repo name.'),
|
|
210
226
|
}, async (input) => {
|
package/dist/revise.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performSetTaskStatus = exports.performDelete = exports.performUpdate = void 0;
|
|
4
|
+
// Which fields each type accepts. Anything else is refused, not dropped, so a typo cannot look like a successful edit.
|
|
5
|
+
const ALLOWED = {
|
|
6
|
+
Fact: ['content', 'tags', 'repo'],
|
|
7
|
+
Skill: ['title', 'content', 'tags', 'repo'],
|
|
8
|
+
Scenario: ['summary', 'repo'],
|
|
9
|
+
Wiki: ['title', 'content', 'tags', 'repo'],
|
|
10
|
+
};
|
|
11
|
+
const FIELDS = ['content', 'title', 'summary', 'tags', 'repo'];
|
|
12
|
+
// The text an item is embedded from, matching save.ts, so a revised item stays comparable to the rest.
|
|
13
|
+
function embeddedText(type, current) {
|
|
14
|
+
if (type === 'Fact')
|
|
15
|
+
return current.content ?? '';
|
|
16
|
+
if (type === 'Scenario')
|
|
17
|
+
return current.summary ?? '';
|
|
18
|
+
return `${current.title ?? ''}\n\n${current.content ?? ''}`;
|
|
19
|
+
}
|
|
20
|
+
async function fetchCurrent(client, type, uid) {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case 'Fact':
|
|
23
|
+
return client.getFact({ uid });
|
|
24
|
+
case 'Skill':
|
|
25
|
+
return client.getSkill({ uid });
|
|
26
|
+
case 'Scenario':
|
|
27
|
+
return client.getScenario({ uid });
|
|
28
|
+
case 'Wiki':
|
|
29
|
+
return client.getWikiPage({ uid });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function performUpdate(deps, input) {
|
|
33
|
+
const { client, embed } = deps;
|
|
34
|
+
const given = FIELDS.filter((field) => input[field] !== undefined);
|
|
35
|
+
if (given.length === 0) {
|
|
36
|
+
throw new Error('Nothing to update: pass at least one of content, title, summary, tags or repo.');
|
|
37
|
+
}
|
|
38
|
+
const refused = given.filter((field) => !ALLOWED[input.type].includes(field));
|
|
39
|
+
if (refused.length > 0) {
|
|
40
|
+
throw new Error(`A ${input.type} has no ${refused.join(', ')}. It accepts: ${ALLOWED[input.type].join(', ')}.`);
|
|
41
|
+
}
|
|
42
|
+
const textChanged = input.content !== undefined || input.title !== undefined || input.summary !== undefined;
|
|
43
|
+
let embedding;
|
|
44
|
+
if (textChanged) {
|
|
45
|
+
const current = await fetchCurrent(client, input.type, input.uid);
|
|
46
|
+
const merged = {
|
|
47
|
+
title: input.title ?? current.title,
|
|
48
|
+
content: input.content ?? current.content,
|
|
49
|
+
summary: input.summary ?? current.summary,
|
|
50
|
+
};
|
|
51
|
+
// No embedding is better than a stale one: the function clears the old vector when the text changes.
|
|
52
|
+
embedding = await embed(embeddedText(input.type, merged)).catch(() => undefined);
|
|
53
|
+
}
|
|
54
|
+
const { type, uid, ...changes } = input;
|
|
55
|
+
const body = { uid, ...changes, ...(embedding ? { embedding } : {}) };
|
|
56
|
+
switch (type) {
|
|
57
|
+
case 'Fact':
|
|
58
|
+
return client.updateFact(body);
|
|
59
|
+
case 'Skill':
|
|
60
|
+
return client.updateSkill(body);
|
|
61
|
+
case 'Scenario':
|
|
62
|
+
return client.updateScenario(body);
|
|
63
|
+
case 'Wiki':
|
|
64
|
+
return client.updateWikiPage(body);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.performUpdate = performUpdate;
|
|
68
|
+
async function performDelete(deps, input) {
|
|
69
|
+
const { client } = deps;
|
|
70
|
+
switch (input.type) {
|
|
71
|
+
case 'Fact':
|
|
72
|
+
return client.deleteFact({ uid: input.uid });
|
|
73
|
+
case 'Skill':
|
|
74
|
+
return client.deleteSkill({ uid: input.uid });
|
|
75
|
+
case 'Scenario':
|
|
76
|
+
return client.deleteScenario({ uid: input.uid });
|
|
77
|
+
case 'Wiki':
|
|
78
|
+
return client.deleteWikiPage({ uid: input.uid });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.performDelete = performDelete;
|
|
82
|
+
function performSetTaskStatus(deps, input) {
|
|
83
|
+
return deps.client.updateTask(input);
|
|
84
|
+
}
|
|
85
|
+
exports.performSetTaskStatus = performSetTaskStatus;
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runSetup = exports.registerSessionStartHook = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.desktopConfigPath = void 0;
|
|
3
|
+
exports.runSetup = exports.registerPromptHook = exports.registerSessionStartHook = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.desktopConfigPath = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const os_1 = require("os");
|
|
@@ -135,36 +135,44 @@ exports.writeUserEnv = writeUserEnv;
|
|
|
135
135
|
// "Ours" is the script's identity, not its exact path: setup-dev.sh registers the repo
|
|
136
136
|
// checkout and this installer ~/.claude/memory-hub-hook, so matching the exact string
|
|
137
137
|
// lets both stack copies of the same script. Replaces, keeping any timeout it carried.
|
|
138
|
-
function
|
|
138
|
+
function registerHook(path, event, hookPath, script, timeout) {
|
|
139
139
|
const settings = readJson(path);
|
|
140
140
|
const hooks = (settings.hooks ||= {});
|
|
141
|
-
const entries = (hooks
|
|
141
|
+
const entries = (hooks[event] ||= []);
|
|
142
142
|
const isOurs = (command) => typeof command === 'string' &&
|
|
143
|
-
(command.trim() === hookPath || command.trim().endsWith(
|
|
143
|
+
(command.trim() === hookPath || command.trim().endsWith(`memory-hub-hook/${script}`));
|
|
144
144
|
const ours = entries.flatMap((entry) => (entry.hooks || []).filter((h) => isOurs(h.command)));
|
|
145
145
|
const already = ours.length === 1 && ours[0].command === hookPath;
|
|
146
|
-
const kept = { type: 'command', ...ours[0], command: hookPath };
|
|
146
|
+
const kept = { type: 'command', ...(timeout ? { timeout } : {}), ...ours[0], command: hookPath };
|
|
147
147
|
for (const entry of entries) {
|
|
148
148
|
entry.hooks = (entry.hooks || []).filter((h) => !isOurs(h.command));
|
|
149
149
|
}
|
|
150
|
-
hooks
|
|
151
|
-
hooks.
|
|
150
|
+
hooks[event] = entries.filter((entry) => entry.hooks.length > 0);
|
|
151
|
+
hooks[event].push({ hooks: [kept] });
|
|
152
152
|
writeJson(path, settings);
|
|
153
153
|
return { already, replaced: already ? 0 : ours.length };
|
|
154
154
|
}
|
|
155
|
+
function registerSessionStartHook(path, hookPath) {
|
|
156
|
+
return registerHook(path, 'SessionStart', hookPath, 'session-start.sh');
|
|
157
|
+
}
|
|
155
158
|
exports.registerSessionStartHook = registerSessionStartHook;
|
|
159
|
+
// This one is on the critical path of every prompt, so it carries an explicit timeout.
|
|
160
|
+
function registerPromptHook(path, hookPath) {
|
|
161
|
+
return registerHook(path, 'UserPromptSubmit', hookPath, 'user-prompt-submit.sh', 15);
|
|
162
|
+
}
|
|
163
|
+
exports.registerPromptHook = registerPromptHook;
|
|
156
164
|
function installAssets() {
|
|
157
165
|
const hookDir = (0, path_1.join)((0, os_1.homedir)(), '.claude', 'memory-hub-hook');
|
|
158
166
|
const skillDir = (0, path_1.join)((0, os_1.homedir)(), '.claude', 'skills', 'se-ai-memory-hub');
|
|
159
167
|
(0, fs_1.mkdirSync)(hookDir, { recursive: true });
|
|
160
168
|
(0, fs_1.mkdirSync)(skillDir, { recursive: true });
|
|
161
|
-
for (const name of ['session-start.sh', 'session-stop.sh']) {
|
|
169
|
+
for (const name of ['session-start.sh', 'session-stop.sh', 'user-prompt-submit.sh']) {
|
|
162
170
|
const dest = (0, path_1.join)(hookDir, name);
|
|
163
171
|
(0, fs_1.copyFileSync)((0, path_1.join)(ASSETS, name), dest);
|
|
164
172
|
(0, fs_1.chmodSync)(dest, 0o755);
|
|
165
173
|
}
|
|
166
174
|
(0, fs_1.copyFileSync)((0, path_1.join)(ASSETS, 'SKILL.md'), (0, path_1.join)(skillDir, 'SKILL.md'));
|
|
167
|
-
return { hookPath: (0, path_1.join)(hookDir, 'session-start.sh') };
|
|
175
|
+
return { hookPath: (0, path_1.join)(hookDir, 'session-start.sh'), promptHookPath: (0, path_1.join)(hookDir, 'user-prompt-submit.sh') };
|
|
168
176
|
}
|
|
169
177
|
// A wrong token does not make the server fail loudly — every recall degrades to
|
|
170
178
|
// empty — so the only honest confirmation is one real call before declaring done.
|
|
@@ -268,7 +276,7 @@ async function runSetup(argv = []) {
|
|
|
268
276
|
// The hook is a shell script, so it reads the token from the environment Claude
|
|
269
277
|
// Code gives it, not from the MCP server's env block.
|
|
270
278
|
writeUserEnv((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), env);
|
|
271
|
-
const { hookPath } = installAssets();
|
|
279
|
+
const { hookPath, promptHookPath } = installAssets();
|
|
272
280
|
const { already, replaced } = registerSessionStartHook((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), hookPath);
|
|
273
281
|
const note = already
|
|
274
282
|
? ' (already registered)'
|
|
@@ -276,6 +284,8 @@ async function runSetup(argv = []) {
|
|
|
276
284
|
? ` (replaced ${replaced} earlier registration${replaced > 1 ? 's' : ''})`
|
|
277
285
|
: '';
|
|
278
286
|
console.log(` SessionStart hook -> ${hookPath}${note}`);
|
|
287
|
+
const prompt = registerPromptHook((0, path_1.join)((0, os_1.homedir)(), '.claude', 'settings.json'), promptHookPath);
|
|
288
|
+
console.log(` UserPromptSubmit hook -> ${promptHookPath}${prompt.already ? ' (already registered)' : ''}`);
|
|
279
289
|
console.log(' skill -> ~/.claude/skills/se-ai-memory-hub/SKILL.md');
|
|
280
290
|
for (const tool of ['curl', 'jq']) {
|
|
281
291
|
if ((0, child_process_1.spawnSync)('which', [tool]).status !== 0) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.similarNotice = void 0;
|
|
4
|
+
const PREVIEW = 160;
|
|
5
|
+
function describe(match) {
|
|
6
|
+
const owner = match.mine === undefined ? '' : match.mine ? ', yours' : ", a teammate's";
|
|
7
|
+
const when = match.lastModifiedDate ? `, updated ${match.lastModifiedDate.slice(0, 10)}` : '';
|
|
8
|
+
const label = match.title ? `${match.title}: ` : '';
|
|
9
|
+
const body = match.content.replace(/\s+/g, ' ').trim();
|
|
10
|
+
const preview = body.length > PREVIEW ? `${body.slice(0, PREVIEW)}…` : body;
|
|
11
|
+
return `- ${match.uid} (${match.similarity.toFixed(2)}${owner}${when}) ${label}"${preview}"`;
|
|
12
|
+
}
|
|
13
|
+
// The save has already happened when this runs; the point is to let the agent keep one copy instead of two.
|
|
14
|
+
function similarNotice(type, result) {
|
|
15
|
+
const matches = result.similar?.length ? result.similar : result.possibleDuplicate ? [result.possibleDuplicate] : [];
|
|
16
|
+
if (matches.length === 0) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const lines = [
|
|
20
|
+
`Saved as ${result.uid}, but it looks like ${matches.length === 1 ? 'a memory' : 'memories'} already saved:`,
|
|
21
|
+
...matches.map(describe),
|
|
22
|
+
];
|
|
23
|
+
const editable = matches.some((match) => match.mine !== false);
|
|
24
|
+
lines.push(editable
|
|
25
|
+
? `If one of yours already covers this, keep a single copy: memory_update type=${type} uid=<that uid> with the merged text, then memory_delete type=${type} uid=${result.uid}.`
|
|
26
|
+
: "Those belong to teammates and cannot be edited, so keep the new one only if it adds something they don't say.");
|
|
27
|
+
return lines.join('\n');
|
|
28
|
+
}
|
|
29
|
+
exports.similarNotice = similarNotice;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skedulo/memory-hub-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "MCP server for the SE AI Memory Hub: recall and save developer memory from Claude Code and Claude Desktop.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "tsc",
|
|
28
|
+
"build": "tsc && ./scripts/source-hash.sh > dist/.source-hash",
|
|
29
29
|
"start": "node dist/index.js",
|
|
30
30
|
"test": "jest",
|
|
31
31
|
"prepack": "./scripts/copy-assets.sh"
|
package/skill-guide.md
CHANGED
|
@@ -147,6 +147,36 @@ stopping point, save what's already distilled now — compaction summarizes
|
|
|
147
147
|
lossily, and a fact that only exists in your reasoning does not survive
|
|
148
148
|
it. A save that happens is worth more than a better-timed one that doesn't.
|
|
149
149
|
|
|
150
|
+
## Revise, don't re-save
|
|
151
|
+
|
|
152
|
+
A memory is not frozen. When you learn something that corrects, completes or
|
|
153
|
+
repeats a memory of yours, change that memory instead of saving another one:
|
|
154
|
+
|
|
155
|
+
- **`memory_update`** with `type`, `uid` and only the fields that change
|
|
156
|
+
(`content`/`tags` for a Fact; `title`/`content`/`tags` for a Skill or Wiki
|
|
157
|
+
page; `summary` for a Scenario; `repo`, or `null`, for any). Pass the full
|
|
158
|
+
new text, not a patch. It re-embeds the text, so search keeps working. Only
|
|
159
|
+
the author can update.
|
|
160
|
+
- **`memory_delete`** removes one of your memories for good. Use it for a copy
|
|
161
|
+
you have just merged into another, or a memory that is wrong or obsolete.
|
|
162
|
+
Prefer `memory_update` while the memory is still partly right.
|
|
163
|
+
- **`memory_setTaskStatus`** with the ticket `externalRef` marks that ticket's
|
|
164
|
+
task `Done` when its work is finished, or `Open` to reopen it. Any member of
|
|
165
|
+
the task's team can do this.
|
|
166
|
+
|
|
167
|
+
`memory_save` checks what you are saving against everything you can see. If it
|
|
168
|
+
looks like an existing memory, the reply starts with `Saved as <uid>, but it
|
|
169
|
+
looks like …` and lists each match with its uid, a similarity score and whether
|
|
170
|
+
it is yours. When a match is yours and already covers the point, keep one copy:
|
|
171
|
+
`memory_update` the old one with the merged text, then `memory_delete` the one
|
|
172
|
+
you just saved. A teammate's memory cannot be edited; keep your new one only if
|
|
173
|
+
it adds something theirs does not say. The check only warns, so a distinct
|
|
174
|
+
memory that shares vocabulary with another is saved either way.
|
|
175
|
+
|
|
176
|
+
Before saving a decision or root cause that you suspect was recorded before,
|
|
177
|
+
run `memory_recall` with a query for it first. A status that has changed (a PR
|
|
178
|
+
merged, a rollout finished) is an update to the old memory, not a new fact.
|
|
179
|
+
|
|
150
180
|
## Mapping an unfamiliar codebase
|
|
151
181
|
|
|
152
182
|
When asked to get oriented in a repo or subsystem you haven't worked in
|