@skedulo/memory-hub-mcp 0.2.18 → 0.2.19
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/README.md +1 -0
- package/assets/session-start.sh +24 -1
- package/assets/session-stop.sh +46 -5
- package/dist/cli.js +16 -1
- package/dist/index.js +8 -2
- package/dist/migrate-plugin.js +219 -0
- package/dist/session-context.js +1 -0
- package/dist/setup.js +130 -23
- package/dist/version.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ have no equivalent there, and nothing is saved unless Claude calls `memory_save`
|
|
|
60
60
|
For Claude Code, `setup` installs the `memory-hub` plugin from the repo's marketplace when the
|
|
61
61
|
`claude` CLI and your GitHub access allow it, and turns its auto-update on; otherwise, or with
|
|
62
62
|
`--no-plugin`, it installs the hooks and skill directly as described below.
|
|
63
|
+
Older installs (`memory-hub@se-ai-memory-hub`) move to the `memory-hub@memory-hub` ID by themselves at the end of a session, except ones with a pasted token, which keep working and move when you run `setup`.
|
|
63
64
|
|
|
64
65
|
Two commands, no config file to edit. No GitHub access, no git clone, no build step, no npm
|
|
65
66
|
account:
|
package/assets/session-start.sh
CHANGED
|
@@ -11,10 +11,14 @@ set -u
|
|
|
11
11
|
FUNCTION_URL="${MEMORY_HUB_FUNCTION_URL:-https://dev-api.test.skl.io/function/memory-hub/memory-hub}"
|
|
12
12
|
TOKEN="${MEMORY_HUB_MCP_TOKEN:-${CLAUDE_PLUGIN_OPTION_TOKEN:-}}"
|
|
13
13
|
|
|
14
|
+
PLUGIN_ID=memory-hub@memory-hub
|
|
15
|
+
OLD_ID_ROOT=false
|
|
16
|
+
case "${CLAUDE_PLUGIN_ROOT:-}" in */se-ai-memory-hub/*) PLUGIN_ID=memory-hub@se-ai-memory-hub; OLD_ID_ROOT=true ;; esac
|
|
17
|
+
|
|
14
18
|
if [ -z "$TOKEN" ]; then
|
|
15
19
|
# A plugin install has no setup step of its own, so it says how to add the token.
|
|
16
20
|
if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
|
|
17
|
-
printf '
|
|
21
|
+
printf '{"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "memory-hub plugin: MEMORY_HUB_MCP_TOKEN is not set, so memory is off this session. Tell the user to run `npx -y @skedulo/memory-hub-mcp setup --code` in a terminal (it logs in with sked and stores a token), or to paste a Skedulo API token with /plugin configure %s. Then restart Claude Code."}}\n' "$PLUGIN_ID"
|
|
18
22
|
fi
|
|
19
23
|
exit 0
|
|
20
24
|
fi
|
|
@@ -410,6 +414,10 @@ if [ -n "$REPO_UID" ]; then
|
|
|
410
414
|
else
|
|
411
415
|
DIAG="${DIAG} · repo: not linked"
|
|
412
416
|
fi
|
|
417
|
+
if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
|
|
418
|
+
PLUGIN_VERSION=$(jq -r '.version // empty' "$CLAUDE_PLUGIN_ROOT/.claude-plugin/plugin.json" 2>/dev/null || true)
|
|
419
|
+
[ -n "$PLUGIN_VERSION" ] && DIAG="${DIAG} · plugin ${PLUGIN_VERSION}"
|
|
420
|
+
fi
|
|
413
421
|
DIAG="${DIAG}_"
|
|
414
422
|
|
|
415
423
|
# Unconditional, not gated behind having any facts to show, so an agent that finds nothing below still knows to check back in before finishing a task.
|
|
@@ -568,10 +576,25 @@ share_nudge() {
|
|
|
568
576
|
printf '%d of your private notes on team repos look shareable; say "share them" to review and share.' "$n"
|
|
569
577
|
}
|
|
570
578
|
|
|
579
|
+
plugin_move_nudge() {
|
|
580
|
+
$OLD_ID_ROOT || return 0
|
|
581
|
+
local stamp="$STATE_DIR/plugin-move-nudge.stamp" now last
|
|
582
|
+
# The log also holds stderr, so the result is the last line shaped like one.
|
|
583
|
+
grep -E '^[0-9T:.Z-]+ (moved|skipped|failed) ' "$STATE_DIR/plugin-move.log" 2>/dev/null | tail -n1 | grep -qF 'pasted token' || return 0
|
|
584
|
+
now=$(date +%s)
|
|
585
|
+
last=$(cat "$stamp" 2>/dev/null)
|
|
586
|
+
case "$last" in ''|*[!0-9]*) last=0 ;; esac
|
|
587
|
+
[ $((now - last)) -ge 604800 ] || return 0
|
|
588
|
+
printf '%s\n' "$now" > "$stamp" 2>/dev/null || return 0
|
|
589
|
+
printf '%s' 'memory-hub has a new plugin name. Tell the user they can move to it by running `npx -y @skedulo/memory-hub-mcp@latest setup` in a terminal; their current install keeps working.'
|
|
590
|
+
}
|
|
591
|
+
|
|
571
592
|
NUDGE=$(catch_up_nudge 2>/dev/null || true)
|
|
572
593
|
[ -z "$NUDGE" ] || NUDGE="${NUDGE}${NL}${NL}"
|
|
573
594
|
SHARE_NUDGE=$(share_nudge 2>/dev/null || true)
|
|
574
595
|
[ -z "$SHARE_NUDGE" ] || NUDGE="${NUDGE}${SHARE_NUDGE}${NL}${NL}"
|
|
596
|
+
MOVE_NUDGE=$(plugin_move_nudge 2>/dev/null || true)
|
|
597
|
+
[ -z "$MOVE_NUDGE" ] || NUDGE="${NUDGE}${MOVE_NUDGE}${NL}${NL}"
|
|
575
598
|
|
|
576
599
|
REMINDER="## Reminder${NL}"
|
|
577
600
|
REMINDER="${REMINDER}${SAVE_LINE}${NL}"
|
package/assets/session-stop.sh
CHANGED
|
@@ -7,11 +7,57 @@ if [ -n "${MEMORY_HUB_STOP_HOOK_ACTIVE:-}" ]; then
|
|
|
7
7
|
exit 0
|
|
8
8
|
fi
|
|
9
9
|
|
|
10
|
+
start_plugin_move() {
|
|
11
|
+
[ "$EVENT" = SessionEnd ] || return 0
|
|
12
|
+
case "${CLAUDE_PLUGIN_ROOT:-}" in */se-ai-memory-hub/*) ;; *) return 0 ;; esac
|
|
13
|
+
local cli stamp="$STATE_DIR/plugin-move.stamp" lock="$STATE_DIR/plugin-move.lock" today
|
|
14
|
+
today=$(date +%F)
|
|
15
|
+
[ "$(cat "$stamp" 2>/dev/null)" != "$today" ] || return 0
|
|
16
|
+
cli=$(head -n1 "$HOME/.claude/memory-hub-hook/cli-path" 2>/dev/null)
|
|
17
|
+
# An older npm build would start the MCP server instead of failing on the unknown command.
|
|
18
|
+
[ -n "$cli" ] && grep -qF migrate-plugin "$cli" 2>/dev/null || return 0
|
|
19
|
+
if [ -n "${MEMORY_HUB_MIGRATE_CMD:-}" ]; then
|
|
20
|
+
set -- sh -c "$MEMORY_HUB_MIGRATE_CMD"
|
|
21
|
+
else
|
|
22
|
+
command -v node >/dev/null 2>&1 || return 0
|
|
23
|
+
set -- node "$cli" migrate-plugin
|
|
24
|
+
fi
|
|
25
|
+
mkdir -p "$STATE_DIR" 2>/dev/null || return 0
|
|
26
|
+
[ -z "$(find "$lock" -maxdepth 0 -mmin +60 2>/dev/null)" ] || rmdir "$lock" 2>/dev/null
|
|
27
|
+
mkdir "$lock" 2>/dev/null || return 0
|
|
28
|
+
# A session that ended just before may have finished and released the lock after our stamp check.
|
|
29
|
+
if [ "$(cat "$stamp" 2>/dev/null)" = "$today" ]; then
|
|
30
|
+
rmdir "$lock" 2>/dev/null
|
|
31
|
+
return 0
|
|
32
|
+
fi
|
|
33
|
+
if ! printf '%s\n' "$today" > "$stamp" 2>/dev/null; then
|
|
34
|
+
rmdir "$lock" 2>/dev/null
|
|
35
|
+
return 0
|
|
36
|
+
fi
|
|
37
|
+
# HUP is ignored from the fork on and the wrapper leaves the session's process group, so the lock release survives a signal to that group.
|
|
38
|
+
set -- sh -c 'lock=$1 log=$2; shift 2; trap "" HUP; "$@" >>"$log" 2>&1 </dev/null; rmdir "$lock" 2>/dev/null' sh "$lock" "$STATE_DIR/plugin-move.log" "$@"
|
|
39
|
+
if command -v perl >/dev/null 2>&1; then
|
|
40
|
+
set -- perl -e '$SIG{HUP} = "IGNORE"; setpgrp(0, 0); exec @ARGV' "$@"
|
|
41
|
+
fi
|
|
42
|
+
trap '' HUP
|
|
43
|
+
"$@" >/dev/null 2>&1 </dev/null &
|
|
44
|
+
trap - HUP
|
|
45
|
+
}
|
|
46
|
+
|
|
10
47
|
opted_in() {
|
|
11
48
|
case "$(printf '%s' "${MEMORY_HUB_AUTO_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in 1|true|yes|on) return 0 ;; esac
|
|
12
49
|
[ "${CLAUDE_PLUGIN_OPTION_CAPTURE:-}" = true ]
|
|
13
50
|
}
|
|
14
51
|
|
|
52
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
53
|
+
|
|
54
|
+
INPUT=$(cat)
|
|
55
|
+
EVENT=$(printf '%s' "$INPUT" | jq -r '.hook_event_name // empty' 2>/dev/null)
|
|
56
|
+
|
|
57
|
+
umask 077
|
|
58
|
+
STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
|
|
59
|
+
start_plugin_move
|
|
60
|
+
|
|
15
61
|
# The plugin registers this hook for everyone, so there it waits for an opt-in; a hand registration is the opt-in.
|
|
16
62
|
if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && ! opted_in; then
|
|
17
63
|
exit 0
|
|
@@ -19,7 +65,6 @@ fi
|
|
|
19
65
|
|
|
20
66
|
TOKEN="${MEMORY_HUB_MCP_TOKEN:-${CLAUDE_PLUGIN_OPTION_TOKEN:-}}"
|
|
21
67
|
[ -n "$TOKEN" ] || exit 0
|
|
22
|
-
command -v jq >/dev/null 2>&1 || exit 0
|
|
23
68
|
|
|
24
69
|
# Same default as session-start.sh; change both together.
|
|
25
70
|
FUNCTION_URL="${MEMORY_HUB_FUNCTION_URL:-https://dev-api.test.skl.io/function/memory-hub/memory-hub}"
|
|
@@ -30,16 +75,12 @@ SESSION_END_MIN_LINES=8
|
|
|
30
75
|
case "$INTERVAL_MIN" in ''|*[!0-9]*) INTERVAL_MIN=30 ;; esac
|
|
31
76
|
case "$MIN_NEW_LINES" in ''|*[!0-9]*) MIN_NEW_LINES=40 ;; esac
|
|
32
77
|
|
|
33
|
-
INPUT=$(cat)
|
|
34
|
-
EVENT=$(printf '%s' "$INPUT" | jq -r '.hook_event_name // empty' 2>/dev/null)
|
|
35
78
|
case "$EVENT" in Stop|SessionEnd) ;; *) exit 0 ;; esac
|
|
36
79
|
SESSION_ID=$(printf '%s' "$INPUT" | jq -r '.session_id // empty' 2>/dev/null | tr -cd 'A-Za-z0-9_-')
|
|
37
80
|
[ -n "$SESSION_ID" ] || exit 0
|
|
38
81
|
TRANSCRIPT_PATH=$(printf '%s' "$INPUT" | jq -r '.transcript_path // empty' 2>/dev/null)
|
|
39
82
|
INPUT_CWD=$(printf '%s' "$INPUT" | jq -r '.cwd // empty' 2>/dev/null)
|
|
40
83
|
|
|
41
|
-
umask 077
|
|
42
|
-
STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
|
|
43
84
|
mkdir -p "$STATE_DIR/logs" 2>/dev/null || exit 0
|
|
44
85
|
STATE_FILE="$STATE_DIR/capture-$SESSION_ID.json"
|
|
45
86
|
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
// load when MEMORY_HUB_MCP_TOKEN is unset — which is exactly the state `setup` exists
|
|
5
5
|
// to fix, so it can never be reached from there.
|
|
6
6
|
const command = process.argv[2];
|
|
7
|
-
if (command === '
|
|
7
|
+
if (command === '--version' || command === '-v') {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
+
const { packageVersion } = require('./version');
|
|
10
|
+
console.log(packageVersion());
|
|
11
|
+
}
|
|
12
|
+
else if (command === 'setup') {
|
|
8
13
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
14
|
const { runSetup } = require('./setup');
|
|
10
15
|
runSetup(process.argv.slice(3)).catch((error) => {
|
|
@@ -67,6 +72,16 @@ else if (command === 'sweep') {
|
|
|
67
72
|
process.exitCode = 1;
|
|
68
73
|
});
|
|
69
74
|
}
|
|
75
|
+
else if (command === 'migrate-plugin') {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
77
|
+
const { runMigratePlugin } = require('./migrate-plugin');
|
|
78
|
+
runMigratePlugin(process.argv.slice(3)).then((code) => {
|
|
79
|
+
process.exitCode = code;
|
|
80
|
+
}, (error) => {
|
|
81
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
70
85
|
else if (command === '--help' || command === '-h') {
|
|
71
86
|
console.log(`memory-hub-mcp — MCP server for the Memory Hub
|
|
72
87
|
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const guide_check_1 = require("./guide-check");
|
|
|
22
22
|
const revise_1 = require("./revise");
|
|
23
23
|
const similar_notice_1 = require("./similar-notice");
|
|
24
24
|
const session_context_1 = require("./session-context");
|
|
25
|
+
const version_1 = require("./version");
|
|
25
26
|
const asset_sync_1 = require("./asset-sync");
|
|
26
27
|
const tags_1 = require("./tags");
|
|
27
28
|
const ask_prompt_1 = require("./ask-prompt");
|
|
@@ -55,7 +56,7 @@ const INSTRUCTIONS = [
|
|
|
55
56
|
'knowledge about Skedulo\'s platform, products, tools or practices; Private only with a',
|
|
56
57
|
'stated reason. Unsure between Org and Team: Team. Say the choice and the reason.',
|
|
57
58
|
].join(' ');
|
|
58
|
-
const server = new mcp_js_1.McpServer({ name: 'memory-hub-mcp', version:
|
|
59
|
+
const server = new mcp_js_1.McpServer({ name: 'memory-hub-mcp', version: (0, version_1.packageVersion)() }, { instructions: INSTRUCTIONS });
|
|
59
60
|
// Detected from this process's own working directory, not from anything the model
|
|
60
61
|
// types. Resolved lazily on the first save so startup never blocks on git or the
|
|
61
62
|
// network, and degrades to undefined (an unscoped save) on any failure.
|
|
@@ -340,7 +341,12 @@ server.tool('memory_checkSources', "Find memories that may be stale against a re
|
|
|
340
341
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
341
342
|
});
|
|
342
343
|
server.tool('memory_sessionContext', "Load this developer's saved memory-hub context: their persona profile, facts, skills, and — when the session has a repo — its wiki pages. Call once at the start of a conversation. If the result has persona.configured false, offer once to set up their persona with memory_upsertPersona, then drop it for the rest of the conversation. On Claude Code the SessionStart hook already covers facts and skills; call this there for the persona, or if that context is missing.", {}, async () => {
|
|
343
|
-
const context = await (0, session_context_1.buildSessionContext)({
|
|
344
|
+
const context = await (0, session_context_1.buildSessionContext)({
|
|
345
|
+
client,
|
|
346
|
+
currentRepoUid: repoContext.currentRepoUid,
|
|
347
|
+
staleness: currentStaleness(),
|
|
348
|
+
serverVersion: (0, version_1.packageVersion)(),
|
|
349
|
+
});
|
|
344
350
|
return { content: [...embeddingNoticeBlocks(), { type: 'text', text: JSON.stringify(context) }] };
|
|
345
351
|
});
|
|
346
352
|
(0, asset_sync_1.refreshInstalledAssets)();
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runMigratePlugin = exports.migratePlugin = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const setup_1 = require("./setup");
|
|
7
|
+
const has = (value, key) => typeof value === 'object' && value !== null && Object.prototype.hasOwnProperty.call(value, key);
|
|
8
|
+
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
9
|
+
function parseObject(output) {
|
|
10
|
+
const start = output.indexOf('{');
|
|
11
|
+
const end = output.lastIndexOf('}');
|
|
12
|
+
if (start < 0 || end < start)
|
|
13
|
+
return undefined;
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(output.slice(start, end + 1));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// readJson reads a torn or hand-broken file as {}, and writing that back would wipe the user's settings.
|
|
22
|
+
function readStrict(path) {
|
|
23
|
+
if (!(0, fs_1.existsSync)(path))
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
|
|
27
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function updateSettings(path, change) {
|
|
34
|
+
const settings = readStrict(path);
|
|
35
|
+
if (!settings)
|
|
36
|
+
return false;
|
|
37
|
+
change(settings);
|
|
38
|
+
(0, setup_1.writeJson)(path, settings);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
function pick(source, keys) {
|
|
42
|
+
return Object.fromEntries(keys.filter((key) => has(source, key)).map((key) => [key, JSON.parse(JSON.stringify(source[key]))]));
|
|
43
|
+
}
|
|
44
|
+
function putBack(settings, field, keys, before) {
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
if (has(before, key))
|
|
47
|
+
(settings[field] ||= {})[key] = before[key];
|
|
48
|
+
else if (has(settings[field], key))
|
|
49
|
+
delete settings[field][key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function logLine(status, reason) {
|
|
53
|
+
return `${new Date().toISOString()} ${status} ${reason.replace(/\s+/g, ' ')}`;
|
|
54
|
+
}
|
|
55
|
+
function migratePlugin(deps) {
|
|
56
|
+
const { run, configDir } = deps;
|
|
57
|
+
const finish = (status, reason) => {
|
|
58
|
+
deps.log(logLine(status, reason));
|
|
59
|
+
return { status, reason };
|
|
60
|
+
};
|
|
61
|
+
const settingsPath = (0, path_1.join)(configDir, 'settings.json');
|
|
62
|
+
const installedPath = (0, path_1.join)(configDir, 'plugins', 'installed_plugins.json');
|
|
63
|
+
const knownPath = (0, path_1.join)(configDir, 'plugins', 'known_marketplaces.json');
|
|
64
|
+
const retireOld = (notes) => {
|
|
65
|
+
let left;
|
|
66
|
+
try {
|
|
67
|
+
if (readStrict(settingsPath)?.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true) {
|
|
68
|
+
const disabled = run(['plugin', 'disable', setup_1.LEGACY_PLUGIN_ID]);
|
|
69
|
+
if (disabled.status !== 0)
|
|
70
|
+
left = `disable failed (${(0, setup_1.lastLine)(disabled.output)})`;
|
|
71
|
+
}
|
|
72
|
+
if (left === undefined) {
|
|
73
|
+
const removed = run(['plugin', 'marketplace', 'remove', setup_1.LEGACY_MARKETPLACE_NAME]);
|
|
74
|
+
if (removed.status !== 0)
|
|
75
|
+
left = (0, setup_1.lastLine)(removed.output);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
left = message(error);
|
|
80
|
+
}
|
|
81
|
+
if (left === undefined)
|
|
82
|
+
return;
|
|
83
|
+
notes.push(`old marketplace not removed: ${left}`);
|
|
84
|
+
try {
|
|
85
|
+
const turnedOff = updateSettings(settingsPath, (current) => {
|
|
86
|
+
if (current.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true)
|
|
87
|
+
current.enabledPlugins[setup_1.LEGACY_PLUGIN_ID] = false;
|
|
88
|
+
});
|
|
89
|
+
if (!turnedOff)
|
|
90
|
+
notes.push(`${setup_1.LEGACY_PLUGIN_ID} still enabled, settings unreadable`);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
notes.push(`${setup_1.LEGACY_PLUGIN_ID} still enabled (${message(error)})`);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const withNotes = (reason, notes) => (notes.length > 0 ? `${reason} (${notes.join('; ')})` : reason);
|
|
97
|
+
const plugins = (0, setup_1.readJson)(installedPath).plugins || {};
|
|
98
|
+
if (!has(plugins, setup_1.LEGACY_PLUGIN_ID))
|
|
99
|
+
return finish('skipped', has(plugins, setup_1.PLUGIN_ID) ? 'already moved' : 'not installed');
|
|
100
|
+
const settings = readStrict(settingsPath);
|
|
101
|
+
if (!settings)
|
|
102
|
+
return finish('skipped', 'settings unreadable');
|
|
103
|
+
const records = Array.isArray(plugins[setup_1.LEGACY_PLUGIN_ID]) ? plugins[setup_1.LEGACY_PLUGIN_ID] : [];
|
|
104
|
+
const userScopeOnly = records.length > 0 && records.every((record) => record?.scope === 'user');
|
|
105
|
+
if (has(plugins, setup_1.PLUGIN_ID)) {
|
|
106
|
+
if (!userScopeOnly)
|
|
107
|
+
return finish('skipped', 'not user scope');
|
|
108
|
+
// A move cut off after the new install leaves both IDs loaded until the old marketplace goes.
|
|
109
|
+
const known = readStrict(knownPath);
|
|
110
|
+
if (!known)
|
|
111
|
+
return finish('skipped', 'marketplaces unreadable');
|
|
112
|
+
if (!has(known, setup_1.LEGACY_MARKETPLACE_NAME) || !(0, setup_1.isHubSource)(known[setup_1.MARKETPLACE_NAME]?.source))
|
|
113
|
+
return finish('skipped', 'already moved');
|
|
114
|
+
const newRecords = Array.isArray(plugins[setup_1.PLUGIN_ID]) ? plugins[setup_1.PLUGIN_ID] : [];
|
|
115
|
+
const newActive = newRecords.some((record) => record?.scope === 'user') && settings.enabledPlugins?.[setup_1.PLUGIN_ID] === true;
|
|
116
|
+
if (!newActive)
|
|
117
|
+
return finish('skipped', 'new install not active');
|
|
118
|
+
const notes = [];
|
|
119
|
+
retireOld(notes);
|
|
120
|
+
return finish('moved', withNotes('retired the old install', notes));
|
|
121
|
+
}
|
|
122
|
+
if (settings.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] !== true)
|
|
123
|
+
return finish('skipped', 'disabled');
|
|
124
|
+
if (!userScopeOnly)
|
|
125
|
+
return finish('skipped', 'not user scope');
|
|
126
|
+
const repoCopy = (0, path_1.join)(configDir, 'plugins', 'marketplaces', setup_1.LEGACY_MARKETPLACE_NAME, '.claude-plugin', 'marketplace.json');
|
|
127
|
+
if ((0, setup_1.readJson)(repoCopy).name !== setup_1.MARKETPLACE_NAME)
|
|
128
|
+
return finish('skipped', 'not released yet');
|
|
129
|
+
const declared = settings.extraKnownMarketplaces?.[setup_1.LEGACY_MARKETPLACE_NAME];
|
|
130
|
+
if (!(0, setup_1.isHubSource)(declared?.source))
|
|
131
|
+
return finish('skipped', 'old marketplace not in settings');
|
|
132
|
+
const configured = run(['plugin', 'configure', '--json', setup_1.LEGACY_PLUGIN_ID]);
|
|
133
|
+
const options = configured.status === 0 ? parseObject(configured.output) : undefined;
|
|
134
|
+
if (!options || !Array.isArray(options.configured))
|
|
135
|
+
return finish('failed', 'could not read the plugin options, nothing changed');
|
|
136
|
+
const settingsToken = settings.env?.MEMORY_HUB_MCP_TOKEN;
|
|
137
|
+
const hasSettingsToken = typeof settingsToken === 'string' && settingsToken.trim() !== '';
|
|
138
|
+
if (options.configured.includes('token') && !hasSettingsToken)
|
|
139
|
+
return finish('skipped', 'pasted token');
|
|
140
|
+
if (run(['plugin', 'marketplace', 'update', setup_1.LEGACY_MARKETPLACE_NAME]).status !== 0)
|
|
141
|
+
return finish('skipped', 'cannot reach the marketplace');
|
|
142
|
+
const knownAtStart = readStrict(knownPath);
|
|
143
|
+
if (!knownAtStart || !has(knownAtStart, setup_1.LEGACY_MARKETPLACE_NAME))
|
|
144
|
+
return finish('skipped', 'marketplaces unreadable');
|
|
145
|
+
const capture = options.inputs?.capture === true ? ['--config', 'capture=true'] : [];
|
|
146
|
+
const ref = declared.source.ref || setup_1.MARKETPLACE_REF;
|
|
147
|
+
const knownBefore = new Set(Object.keys(knownAtStart));
|
|
148
|
+
const marketplacesBefore = pick(settings.extraKnownMarketplaces, [setup_1.MARKETPLACE_NAME]);
|
|
149
|
+
const enabledBefore = pick(settings.enabledPlugins, [setup_1.PLUGIN_ID]);
|
|
150
|
+
const addAndInstall = () => {
|
|
151
|
+
const added = run(['plugin', 'marketplace', 'add', `${setup_1.MARKETPLACE_GIT_URL}#${ref}`]);
|
|
152
|
+
if (added.status !== 0)
|
|
153
|
+
return `add failed (${(0, setup_1.lastLine)(added.output)})`;
|
|
154
|
+
if (!(0, setup_1.isHubSource)((0, setup_1.readJson)(knownPath)[setup_1.MARKETPLACE_NAME]?.source))
|
|
155
|
+
return `add failed (the repo did not register as ${setup_1.MARKETPLACE_NAME})`;
|
|
156
|
+
const installed = run(['plugin', 'install', setup_1.PLUGIN_ID, ...capture]);
|
|
157
|
+
if (installed.status !== 0)
|
|
158
|
+
return `install failed (${(0, setup_1.lastLine)(installed.output)})`;
|
|
159
|
+
if ((0, setup_1.installedPluginId)(installedPath) !== setup_1.PLUGIN_ID)
|
|
160
|
+
return `install failed (claude did not list ${setup_1.PLUGIN_ID})`;
|
|
161
|
+
return undefined;
|
|
162
|
+
};
|
|
163
|
+
const undoNew = () => {
|
|
164
|
+
const known = (0, setup_1.readJson)(knownPath);
|
|
165
|
+
for (const name of Object.keys(known)) {
|
|
166
|
+
if (name !== setup_1.LEGACY_MARKETPLACE_NAME && !knownBefore.has(name) && (0, setup_1.isHubSource)(known[name]?.source))
|
|
167
|
+
run(['plugin', 'marketplace', 'remove', name]);
|
|
168
|
+
}
|
|
169
|
+
const restored = updateSettings(settingsPath, (current) => {
|
|
170
|
+
putBack(current, 'extraKnownMarketplaces', [setup_1.MARKETPLACE_NAME], marketplacesBefore);
|
|
171
|
+
putBack(current, 'enabledPlugins', [setup_1.PLUGIN_ID], enabledBefore);
|
|
172
|
+
});
|
|
173
|
+
return restored ? `${setup_1.LEGACY_PLUGIN_ID} untouched` : `${setup_1.LEGACY_PLUGIN_ID} untouched, settings unreadable and left as they are`;
|
|
174
|
+
};
|
|
175
|
+
let failure;
|
|
176
|
+
try {
|
|
177
|
+
failure = addAndInstall();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
failure = `add or install failed (${message(error)})`;
|
|
181
|
+
}
|
|
182
|
+
if (failure !== undefined) {
|
|
183
|
+
let outcome;
|
|
184
|
+
try {
|
|
185
|
+
outcome = undoNew();
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
outcome = `undoing the new marketplace failed (${message(error)})`;
|
|
189
|
+
}
|
|
190
|
+
return finish('failed', `${failure}; ${outcome}`);
|
|
191
|
+
}
|
|
192
|
+
const notes = [];
|
|
193
|
+
retireOld(notes);
|
|
194
|
+
if (declared.autoUpdate === true) {
|
|
195
|
+
try {
|
|
196
|
+
const set = updateSettings(settingsPath, (current) => {
|
|
197
|
+
const known = (current.extraKnownMarketplaces ||= {});
|
|
198
|
+
known[setup_1.MARKETPLACE_NAME] = { source: { source: 'git', url: setup_1.MARKETPLACE_GIT_URL, ref }, ...known[setup_1.MARKETPLACE_NAME], autoUpdate: true };
|
|
199
|
+
});
|
|
200
|
+
if (!set)
|
|
201
|
+
notes.push('auto-update not carried over, settings unreadable');
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
notes.push(`auto-update not carried over (${message(error)})`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return finish('moved', withNotes(`${setup_1.LEGACY_PLUGIN_ID} to ${setup_1.PLUGIN_ID}, loads at the next session`, notes));
|
|
208
|
+
}
|
|
209
|
+
exports.migratePlugin = migratePlugin;
|
|
210
|
+
async function runMigratePlugin(_argv) {
|
|
211
|
+
const log = (line) => console.log(line);
|
|
212
|
+
const run = (0, setup_1.claudeRunner)();
|
|
213
|
+
if (!run) {
|
|
214
|
+
log(logLine('skipped', 'claude CLI not on PATH'));
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
return migratePlugin({ run, configDir: (0, setup_1.claudeConfigDir)(), log }).status === 'failed' ? 1 : 0;
|
|
218
|
+
}
|
|
219
|
+
exports.runMigratePlugin = runMigratePlugin;
|
package/dist/session-context.js
CHANGED
|
@@ -59,6 +59,7 @@ async function buildSessionContext(deps) {
|
|
|
59
59
|
? await soft(Promise.all(groups.map((raws) => toItems(raws, staleness))), plain, soft_1.STALENESS_TIMEOUT_MS)
|
|
60
60
|
: plain;
|
|
61
61
|
return {
|
|
62
|
+
serverVersion: deps.serverVersion,
|
|
62
63
|
persona,
|
|
63
64
|
facts: { self: factsS, team: factsT, repo: factsR },
|
|
64
65
|
skills: { self: skillsS, team: skillsT, repo: skillsR },
|
package/dist/setup.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runSetup = exports.runCapture = exports.registerPromptHook = exports.registerSessionStartHook = exports.removeMcpServer = exports.removeCopiedAssets = exports.setCapture = exports.captureOn = exports.CAPTURE_FLAG = exports.unregisterHooks = exports.installPlugin = exports.enableMarketplaceAutoUpdate = exports.removeUserEnv = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.desktopConfigPath = exports.mcpLaunch = exports.pluginInstalled = exports.PLUGIN_ID = exports.MARKETPLACE_REF = exports.MARKETPLACE_REPO = exports.MARKETPLACE_NAME = exports.launchPath = exports.PACKAGE_SPEC = void 0;
|
|
3
|
+
exports.runSetup = exports.runCapture = exports.registerPromptHook = exports.registerSessionStartHook = exports.removeMcpServer = exports.removeCopiedAssets = exports.setCapture = exports.captureOn = exports.CAPTURE_FLAG = exports.unregisterHooks = exports.claudeRunner = exports.installPlugin = exports.enableMarketplaceAutoUpdate = exports.removeUserEnv = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.writeJson = exports.readJson = exports.desktopConfigPath = exports.mcpLaunch = exports.lastLine = exports.isHubSource = exports.pluginInstalled = exports.installedPluginId = exports.installedPluginIds = exports.claudeConfigDir = exports.LEGACY_PLUGIN_ID = exports.PLUGIN_ID = exports.MARKETPLACE_REF = exports.MARKETPLACE_GIT_URL = exports.MARKETPLACE_REPO = exports.LEGACY_MARKETPLACE_NAME = exports.MARKETPLACE_NAME = exports.launchPath = exports.PACKAGE_SPEC = 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");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const readline_1 = require("readline");
|
|
9
9
|
const asset_sync_1 = require("./asset-sync");
|
|
10
|
+
const migrate_plugin_1 = require("./migrate-plugin");
|
|
10
11
|
const DEFAULT_API_HOST = 'dev-api.test.skl.io';
|
|
11
12
|
const DEFAULT_TENANT = 'memory-hub';
|
|
12
13
|
const SKED_CONFIG = (0, path_1.join)((0, os_1.homedir)(), '.config', 'sked', 'config.json');
|
|
@@ -19,15 +20,48 @@ function launchPath(execPath, currentPath = process.env.PATH || '', sep = path_1
|
|
|
19
20
|
return [...new Set([(0, path_1.dirname)(execPath), ...currentPath.split(sep).filter(Boolean)])].join(sep);
|
|
20
21
|
}
|
|
21
22
|
exports.launchPath = launchPath;
|
|
22
|
-
exports.MARKETPLACE_NAME = '
|
|
23
|
+
exports.MARKETPLACE_NAME = 'memory-hub';
|
|
24
|
+
exports.LEGACY_MARKETPLACE_NAME = 'se-ai-memory-hub';
|
|
23
25
|
exports.MARKETPLACE_REPO = 'Skedulo/se-ai-memory-hub';
|
|
26
|
+
// While the old entry holds the repo by its github shorthand, adding the shorthand again is a no-op; the git URL registers alongside it.
|
|
27
|
+
exports.MARKETPLACE_GIT_URL = `https://github.com/${exports.MARKETPLACE_REPO}.git`;
|
|
24
28
|
// main only moves when a release is merged into it, so installs and updates both get released hooks.
|
|
25
29
|
exports.MARKETPLACE_REF = 'main';
|
|
26
30
|
exports.PLUGIN_ID = `memory-hub@${exports.MARKETPLACE_NAME}`;
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
exports.LEGACY_PLUGIN_ID = `memory-hub@${exports.LEGACY_MARKETPLACE_NAME}`;
|
|
32
|
+
// `||`, not `??`: Claude Code treats an empty CLAUDE_CONFIG_DIR as the current directory.
|
|
33
|
+
function claudeConfigDir(env = process.env, home = (0, os_1.homedir)()) {
|
|
34
|
+
return env.CLAUDE_CONFIG_DIR || (0, path_1.join)(home, '.claude');
|
|
35
|
+
}
|
|
36
|
+
exports.claudeConfigDir = claudeConfigDir;
|
|
37
|
+
function installedPluginIds(path = (0, path_1.join)(claudeConfigDir(), 'plugins', 'installed_plugins.json')) {
|
|
38
|
+
const plugins = readJson(path).plugins || {};
|
|
39
|
+
return [exports.PLUGIN_ID, exports.LEGACY_PLUGIN_ID].filter((id) => Object.prototype.hasOwnProperty.call(plugins, id));
|
|
40
|
+
}
|
|
41
|
+
exports.installedPluginIds = installedPluginIds;
|
|
42
|
+
function installedPluginId(path) {
|
|
43
|
+
return installedPluginIds(path)[0];
|
|
44
|
+
}
|
|
45
|
+
exports.installedPluginId = installedPluginId;
|
|
46
|
+
function pluginInstalled(path) {
|
|
47
|
+
return installedPluginId(path) !== undefined;
|
|
29
48
|
}
|
|
30
49
|
exports.pluginInstalled = pluginInstalled;
|
|
50
|
+
function isHubSource(source) {
|
|
51
|
+
const s = (source || {});
|
|
52
|
+
const repo = exports.MARKETPLACE_REPO.toLowerCase();
|
|
53
|
+
if (typeof s.repo === 'string')
|
|
54
|
+
return s.repo.toLowerCase() === repo;
|
|
55
|
+
if (typeof s.url !== 'string')
|
|
56
|
+
return false;
|
|
57
|
+
const url = s.url.toLowerCase().replace(/\.git$/, '');
|
|
58
|
+
return url.endsWith(`/${repo}`) || url.endsWith(`:${repo}`);
|
|
59
|
+
}
|
|
60
|
+
exports.isHubSource = isHubSource;
|
|
61
|
+
function lastLine(output) {
|
|
62
|
+
return output.trim().split('\n').pop() || 'no output';
|
|
63
|
+
}
|
|
64
|
+
exports.lastLine = lastLine;
|
|
31
65
|
// Hosts don't launch MCP servers from a login shell, so the command must be an absolute path.
|
|
32
66
|
function mcpLaunch(options) {
|
|
33
67
|
if (!options.autoUpdate)
|
|
@@ -58,12 +92,14 @@ function readJson(path) {
|
|
|
58
92
|
return {};
|
|
59
93
|
}
|
|
60
94
|
}
|
|
95
|
+
exports.readJson = readJson;
|
|
61
96
|
function writeJson(path, value) {
|
|
62
97
|
(0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
|
|
63
98
|
if ((0, fs_1.existsSync)(path))
|
|
64
99
|
(0, fs_1.writeFileSync)(`${path}.bak`, (0, fs_1.readFileSync)(path));
|
|
65
100
|
(0, fs_1.writeFileSync)(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
66
101
|
}
|
|
102
|
+
exports.writeJson = writeJson;
|
|
67
103
|
function ask(question) {
|
|
68
104
|
const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
|
|
69
105
|
return new Promise((done) => rl.question(question, (answer) => { rl.close(); done(answer.trim()); }));
|
|
@@ -186,11 +222,11 @@ function registerHook(path, event, hookPath, script, timeout, extra = {}) {
|
|
|
186
222
|
return { already, replaced: already ? 0 : ours.length };
|
|
187
223
|
}
|
|
188
224
|
// Third-party marketplaces don't auto-update unless this documented settings key says so.
|
|
189
|
-
function enableMarketplaceAutoUpdate(path) {
|
|
225
|
+
function enableMarketplaceAutoUpdate(path, name = exports.MARKETPLACE_NAME) {
|
|
190
226
|
const settings = readJson(path);
|
|
191
227
|
const known = (settings.extraKnownMarketplaces ||= {});
|
|
192
|
-
const entry = known[
|
|
193
|
-
known[
|
|
228
|
+
const entry = known[name] || {};
|
|
229
|
+
known[name] = {
|
|
194
230
|
...entry,
|
|
195
231
|
source: entry.source || { source: 'github', repo: exports.MARKETPLACE_REPO, ref: exports.MARKETPLACE_REF },
|
|
196
232
|
autoUpdate: true,
|
|
@@ -198,16 +234,23 @@ function enableMarketplaceAutoUpdate(path) {
|
|
|
198
234
|
writeJson(path, settings);
|
|
199
235
|
}
|
|
200
236
|
exports.enableMarketplaceAutoUpdate = enableMarketplaceAutoUpdate;
|
|
201
|
-
|
|
202
|
-
|
|
237
|
+
// The repo's marketplace.json decides the name `marketplace add` registers, and main may still carry the old one.
|
|
238
|
+
function registeredMarketplace(knownPath) {
|
|
239
|
+
const known = readJson(knownPath);
|
|
240
|
+
const names = Object.keys(known).filter((name) => isHubSource(known[name]?.source));
|
|
241
|
+
return names.includes(exports.MARKETPLACE_NAME) ? exports.MARKETPLACE_NAME : names[0] || exports.MARKETPLACE_NAME;
|
|
242
|
+
}
|
|
243
|
+
function installPlugin(run, settingsPath, installedPath = (0, path_1.join)(claudeConfigDir(), 'plugins', 'installed_plugins.json'), knownPath = (0, path_1.join)((0, path_1.dirname)(installedPath), 'known_marketplaces.json')) {
|
|
203
244
|
const added = run(['plugin', 'marketplace', 'add', `${exports.MARKETPLACE_REPO}#${exports.MARKETPLACE_REF}`]);
|
|
204
245
|
if (added.status !== 0)
|
|
205
246
|
return { ok: false, reason: lastLine(added.output) };
|
|
206
|
-
|
|
207
|
-
|
|
247
|
+
const name = registeredMarketplace(knownPath);
|
|
248
|
+
enableMarketplaceAutoUpdate(settingsPath, name);
|
|
249
|
+
const id = `memory-hub@${name}`;
|
|
250
|
+
const installed = run(['plugin', 'install', id]);
|
|
208
251
|
if (installed.status !== 0)
|
|
209
252
|
return { ok: false, reason: lastLine(installed.output) };
|
|
210
|
-
return
|
|
253
|
+
return installedPluginId(installedPath) === id ? { ok: true } : { ok: false, reason: 'claude reported success but did not list the plugin' };
|
|
211
254
|
}
|
|
212
255
|
exports.installPlugin = installPlugin;
|
|
213
256
|
// Without repo access git would otherwise wait on a password prompt or an SSH host-key question.
|
|
@@ -227,6 +270,7 @@ function claudeRunner() {
|
|
|
227
270
|
return { status: result.status, output: `${result.stdout || ''}${result.stderr || ''}` };
|
|
228
271
|
};
|
|
229
272
|
}
|
|
273
|
+
exports.claudeRunner = claudeRunner;
|
|
230
274
|
// The plugin brings its own hooks, so setup's copies would run every hook twice.
|
|
231
275
|
// Empty event lists are dropped too: left behind, they read as "the hooks are missing".
|
|
232
276
|
function removeHookCommands(settings, event, matches) {
|
|
@@ -394,7 +438,7 @@ async function chooseHosts() {
|
|
|
394
438
|
}
|
|
395
439
|
function existingToken(hosts) {
|
|
396
440
|
if (hosts.includes('code')) {
|
|
397
|
-
const settings = readJson((0, path_1.join)((
|
|
441
|
+
const settings = readJson((0, path_1.join)(claudeConfigDir(), 'settings.json'));
|
|
398
442
|
const token = settings.env?.MEMORY_HUB_MCP_TOKEN;
|
|
399
443
|
const url = readJson((0, path_1.join)((0, os_1.homedir)(), '.claude.json')).mcpServers?.['memory-hub']?.env?.MEMORY_HUB_FUNCTION_URL;
|
|
400
444
|
if (token)
|
|
@@ -425,13 +469,13 @@ async function askCapture(current) {
|
|
|
425
469
|
return answer.startsWith('y');
|
|
426
470
|
}
|
|
427
471
|
async function runCapture(argv = []) {
|
|
428
|
-
const settingsPath = (0, path_1.join)((
|
|
472
|
+
const settingsPath = (0, path_1.join)(claudeConfigDir(), 'settings.json');
|
|
429
473
|
const plugin = pluginInstalled();
|
|
430
474
|
const hookPath = (0, path_1.join)((0, asset_sync_1.installDirs)().hookDir, 'session-stop.sh');
|
|
431
475
|
const choice = argv[0];
|
|
432
476
|
const pluginNote = "If you turned on the plugin's Auto-capture option in /plugin configure, that keeps it on too.";
|
|
433
477
|
if (choice !== 'on' && choice !== 'off') {
|
|
434
|
-
console.log(`auto-capture is ${captureOn(settingsPath) ? 'on' : 'off'} in
|
|
478
|
+
console.log(`auto-capture is ${captureOn(settingsPath) ? 'on' : 'off'} in ${settingsPath}.`);
|
|
435
479
|
if (plugin)
|
|
436
480
|
console.log(pluginNote);
|
|
437
481
|
console.log('Usage: memory-hub-mcp capture on|off');
|
|
@@ -447,7 +491,7 @@ async function runCapture(argv = []) {
|
|
|
447
491
|
console.log('auto-capture is on: after long stretches and at session end, a background Claude run, using your Claude usage, saves what the session learned. New memories are Private; updates keep their visibility.');
|
|
448
492
|
}
|
|
449
493
|
else if (captureOn(settingsPath)) {
|
|
450
|
-
console.log(
|
|
494
|
+
console.log(`auto-capture is still on: a session-stop.sh entry under Stop or SessionEnd in ${settingsPath} keeps it running. Remove that entry by hand to stop it.`);
|
|
451
495
|
}
|
|
452
496
|
else {
|
|
453
497
|
console.log('auto-capture is off.');
|
|
@@ -457,6 +501,60 @@ async function runCapture(argv = []) {
|
|
|
457
501
|
console.log('Restart Claude Code to pick this up.');
|
|
458
502
|
}
|
|
459
503
|
exports.runCapture = runCapture;
|
|
504
|
+
const QUIET_SKIPS = ['not installed', 'already moved', 'not released yet'];
|
|
505
|
+
const MOVE_LOCK_STALE_MS = 60 * 60 * 1000;
|
|
506
|
+
// The same lock the SessionEnd hook takes, so setup and a background move never overlap.
|
|
507
|
+
function withMoveLock(fn) {
|
|
508
|
+
const stateDir = process.env.MEMORY_HUB_STATE_DIR || (0, path_1.join)((0, os_1.homedir)(), '.claude', 'memory-hub-hook', 'state');
|
|
509
|
+
const lock = (0, path_1.join)(stateDir, 'plugin-move.lock');
|
|
510
|
+
try {
|
|
511
|
+
(0, fs_1.mkdirSync)(stateDir, { recursive: true });
|
|
512
|
+
if ((0, fs_1.existsSync)(lock) && Date.now() - (0, fs_1.statSync)(lock).mtimeMs > MOVE_LOCK_STALE_MS)
|
|
513
|
+
(0, fs_1.rmdirSync)(lock);
|
|
514
|
+
(0, fs_1.mkdirSync)(lock);
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
try {
|
|
520
|
+
fn();
|
|
521
|
+
}
|
|
522
|
+
finally {
|
|
523
|
+
try {
|
|
524
|
+
(0, fs_1.rmdirSync)(lock);
|
|
525
|
+
}
|
|
526
|
+
catch { }
|
|
527
|
+
}
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
function moveLegacyPlugin() {
|
|
531
|
+
const say = (line) => {
|
|
532
|
+
console.log();
|
|
533
|
+
console.log('==> Claude Code plugin');
|
|
534
|
+
console.log(line);
|
|
535
|
+
};
|
|
536
|
+
const run = claudeRunner();
|
|
537
|
+
if (!run) {
|
|
538
|
+
say(` kept ${exports.LEGACY_PLUGIN_ID}: the claude CLI is not on PATH to move it to ${exports.PLUGIN_ID}.`);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
let result;
|
|
542
|
+
const locked = withMoveLock(() => {
|
|
543
|
+
result = (0, migrate_plugin_1.migratePlugin)({ run, configDir: claudeConfigDir(), log: () => { } });
|
|
544
|
+
});
|
|
545
|
+
if (!locked || !result) {
|
|
546
|
+
say(` a move of ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID} is already running; re-run setup in a minute if it is still listed.`);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (result.status === 'moved' && result.reason.startsWith('retired'))
|
|
550
|
+
say(` removed the old ${exports.LEGACY_PLUGIN_ID} install; ${exports.PLUGIN_ID} stays.`);
|
|
551
|
+
else if (result.status === 'moved')
|
|
552
|
+
say(` moved ${exports.LEGACY_PLUGIN_ID} to its new ID ${exports.PLUGIN_ID}; it loads at the next session.`);
|
|
553
|
+
else if (result.status === 'failed')
|
|
554
|
+
say(` couldn't move ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID}: ${result.reason}.`);
|
|
555
|
+
else if (!QUIET_SKIPS.includes(result.reason))
|
|
556
|
+
say(` kept ${exports.LEGACY_PLUGIN_ID} (${result.reason}).`);
|
|
557
|
+
}
|
|
460
558
|
async function runSetup(argv = []) {
|
|
461
559
|
console.log('==> Setting up the memory hub');
|
|
462
560
|
let hosts;
|
|
@@ -522,7 +620,7 @@ async function runSetup(argv = []) {
|
|
|
522
620
|
else {
|
|
523
621
|
console.log(' pinned to this install. Update with `npm i -g @skedulo/memory-hub-mcp` and re-run setup.');
|
|
524
622
|
}
|
|
525
|
-
const settingsPath = (0, path_1.join)((
|
|
623
|
+
const settingsPath = (0, path_1.join)(claudeConfigDir(), 'settings.json');
|
|
526
624
|
let plugin = hosts.includes('code') && pluginInstalled();
|
|
527
625
|
if (hosts.includes('code') && !plugin && !argv.includes('--no-plugin')) {
|
|
528
626
|
console.log();
|
|
@@ -540,13 +638,22 @@ async function runSetup(argv = []) {
|
|
|
540
638
|
: ` couldn't install it (${result.reason}), so the hooks and skill are installed directly instead.`);
|
|
541
639
|
}
|
|
542
640
|
}
|
|
641
|
+
if (plugin && installedPluginIds().includes(exports.LEGACY_PLUGIN_ID)) {
|
|
642
|
+
// Before the move: a settings token is what lets an install with a pasted token move.
|
|
643
|
+
writeUserEnv(settingsPath, env);
|
|
644
|
+
moveLegacyPlugin();
|
|
645
|
+
plugin = pluginInstalled();
|
|
646
|
+
if (!plugin)
|
|
647
|
+
console.log(' no memory-hub plugin is installed now, so the hooks and skill are installed directly instead.');
|
|
648
|
+
}
|
|
543
649
|
if (plugin) {
|
|
544
650
|
console.log();
|
|
545
651
|
console.log('==> Claude Code');
|
|
546
|
-
console.log(` the ${exports.PLUGIN_ID} plugin brings the MCP server, hooks and skill, so setup only`);
|
|
547
|
-
console.log(' stores your token for them, and keeps the plugin on auto-update.');
|
|
548
|
-
enableMarketplaceAutoUpdate(settingsPath);
|
|
549
652
|
writeUserEnv(settingsPath, env);
|
|
653
|
+
const pluginId = installedPluginId() ?? exports.PLUGIN_ID;
|
|
654
|
+
console.log(` the ${pluginId} plugin brings the MCP server, hooks and skill, so setup only`);
|
|
655
|
+
console.log(' stores your token for them, and keeps the plugin on auto-update.');
|
|
656
|
+
enableMarketplaceAutoUpdate(settingsPath, pluginId === exports.LEGACY_PLUGIN_ID ? exports.LEGACY_MARKETPLACE_NAME : exports.MARKETPLACE_NAME);
|
|
550
657
|
const hooks = unregisterHooks(settingsPath);
|
|
551
658
|
const server = removeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'));
|
|
552
659
|
const copies = removeCopiedAssets(settingsPath);
|
|
@@ -565,16 +672,16 @@ async function runSetup(argv = []) {
|
|
|
565
672
|
console.log(` MCP server -> ${shown}`);
|
|
566
673
|
// The hook is a shell script, so it reads the token from the environment Claude
|
|
567
674
|
// Code gives it, not from the MCP server's env block.
|
|
568
|
-
writeUserEnv(
|
|
675
|
+
writeUserEnv(settingsPath, env);
|
|
569
676
|
const { hookPath, promptHookPath } = installAssets();
|
|
570
|
-
const { already, replaced } = registerSessionStartHook(
|
|
677
|
+
const { already, replaced } = registerSessionStartHook(settingsPath, hookPath);
|
|
571
678
|
const note = already
|
|
572
679
|
? ' (already registered)'
|
|
573
680
|
: replaced > 0
|
|
574
681
|
? ` (replaced ${replaced} earlier registration${replaced > 1 ? 's' : ''})`
|
|
575
682
|
: '';
|
|
576
683
|
console.log(` SessionStart hook -> ${hookPath}${note}`);
|
|
577
|
-
const prompt = registerPromptHook(
|
|
684
|
+
const prompt = registerPromptHook(settingsPath, promptHookPath);
|
|
578
685
|
console.log(` UserPromptSubmit hook -> ${promptHookPath}${prompt.already ? ' (already registered)' : ''}`);
|
|
579
686
|
console.log(` skills -> ~/.claude/skills/ (${(0, asset_sync_1.packagedSkills)(ASSETS).join(', ')})`);
|
|
580
687
|
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packageVersion = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
// Same relative path from src (ts-jest) and from dist.
|
|
7
|
+
function packageVersion(dir = __dirname) {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(dir, '..', 'package.json'), 'utf8')).version ?? 'unknown';
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return 'unknown';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.packageVersion = packageVersion;
|
package/package.json
CHANGED