@skedulo/memory-hub-mcp 0.2.40 → 0.2.42
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 +10 -0
- package/assets/session-start.sh +17 -6
- package/assets/session-stop.sh +2 -2
- package/assets/skills/setup/SKILL.md +1 -1
- package/assets/uninstall-memory-hub.sh +1 -1
- package/dist/asset-sync.js +2 -1
- package/dist/index.js +18 -0
- package/dist/login-tool.js +11 -2
- package/dist/migrate-plugin.js +49 -81
- package/dist/move-lock.js +55 -0
- package/dist/move-trigger.js +43 -0
- package/dist/plugin-move-util.js +77 -0
- package/dist/setup.js +82 -51
- package/dist/skedulo-move.js +323 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,8 @@ the plugin, `mcp__memory-hub__*` with `--no-plugin`), to `permissions.allow` in
|
|
|
71
71
|
so they stop asking for approval; pass `--no-allow` to skip that.
|
|
72
72
|
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`.
|
|
73
73
|
|
|
74
|
+
Once Memory Hub is listed in the Skedulo plugin marketplace and the move is turned on in a release, installs move to `memory-hub@skedulo-plugin-marketplace` by themselves at the end of a session. On a machine without Memory Hub, anyone who already has that marketplace can run `claude plugin install memory-hub@skedulo-plugin-marketplace`.
|
|
75
|
+
|
|
74
76
|
Plugin only, no `npm` or `sked`: install it with `claude plugin marketplace add Skedulo/se-ai-memory-hub`
|
|
75
77
|
and `claude plugin install memory-hub@memory-hub` (in the desktop app: + → Plugins), start a session,
|
|
76
78
|
and sign in in the browser tab that opens. The plugin needs Node from [nodejs.org](https://nodejs.org)
|
|
@@ -167,6 +169,14 @@ release has five steps:
|
|
|
167
169
|
|
|
168
170
|
A hook or skill fix on its own still ships as a patch release.
|
|
169
171
|
|
|
172
|
+
Every push to `main` also runs the `Plugin dist` workflow. It builds the plugin with the server and
|
|
173
|
+
its native packages inside (`scripts/build-plugin-dist.sh`: macOS arm64 and Intel, Linux x64 for the
|
|
174
|
+
cloud routine, about 43 MB compressed), checks it on all three with `scripts/smoke-plugin-dist.sh`,
|
|
175
|
+
and force-pushes it as one commit to the `plugin-dist` branch. A plugin installed from that branch
|
|
176
|
+
runs its own server with `node` instead of `npx` (`memory-hub-hook/mcp-server.sh` looks for
|
|
177
|
+
`memory-hub-mcp/.bundled`). No marketplace points at `plugin-dist` yet, so npm stays the release
|
|
178
|
+
path until one does.
|
|
179
|
+
|
|
170
180
|
Roll back by pointing `latest` at the previous version:
|
|
171
181
|
`npm dist-tag add @skedulo/memory-hub-mcp@<previous> latest`.
|
|
172
182
|
|
package/assets/session-start.sh
CHANGED
|
@@ -24,7 +24,7 @@ FUNCTION_URL="${MEMORY_HUB_FUNCTION_URL:-${FILE_API_BASE:-https://dev-api.test.s
|
|
|
24
24
|
# <<< token lookup
|
|
25
25
|
|
|
26
26
|
OLD_ID_ROOT=false
|
|
27
|
-
case "${CLAUDE_PLUGIN_ROOT:-}" in */se-ai-memory-hub/*) OLD_ID_ROOT=true ;; esac
|
|
27
|
+
case "${CLAUDE_PLUGIN_ROOT:-}" in */se-ai-memory-hub/* | */plugins/cache/memory-hub/*) OLD_ID_ROOT=true ;; esac
|
|
28
28
|
|
|
29
29
|
STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
|
|
30
30
|
HOOK_INPUT=""
|
|
@@ -56,16 +56,17 @@ emit_jq_missing() {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
npx_available() {
|
|
59
|
-
local dir
|
|
59
|
+
local dir tool=npx
|
|
60
|
+
[ -f "${CLAUDE_PLUGIN_ROOT:-}/memory-hub-mcp/.bundled" ] && tool=node
|
|
60
61
|
if [ -n "${MEMORY_HUB_NPX_SEARCH:-}" ]; then
|
|
61
62
|
for dir in $MEMORY_HUB_NPX_SEARCH; do
|
|
62
|
-
[ -x "$dir
|
|
63
|
+
[ -x "$dir/$tool" ] && return 0
|
|
63
64
|
done
|
|
64
65
|
return 1
|
|
65
66
|
fi
|
|
66
|
-
command -v
|
|
67
|
+
command -v "$tool" >/dev/null 2>&1 && return 0
|
|
67
68
|
for dir in /opt/homebrew/bin /usr/local/bin "$HOME/.volta/bin" $(ls -d "$HOME"/.nvm/versions/node/*/bin 2>/dev/null | sort -rV); do
|
|
68
|
-
[ -x "$dir
|
|
69
|
+
[ -x "$dir/$tool" ] && return 0
|
|
69
70
|
done
|
|
70
71
|
return 1
|
|
71
72
|
}
|
|
@@ -792,7 +793,15 @@ plugin_move_nudge() {
|
|
|
792
793
|
case "$last" in ''|*[!0-9]*) last=0 ;; esac
|
|
793
794
|
[ $((now - last)) -ge 604800 ] || return 0
|
|
794
795
|
printf '%s\n' "$now" > "$stamp" 2>/dev/null || return 0
|
|
795
|
-
printf '%s' '
|
|
796
|
+
printf '%s' 'Memory Hub uses a pasted token, so it can'"'"'t move to its new plugin home by itself. Tell the user they can run `npx -y @skedulo/memory-hub-mcp@latest setup --code` in a terminal, which signs them in so the pasted token is no longer needed; their current install keeps working.'
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
moved_notice() {
|
|
800
|
+
local file="$STATE_DIR/moved-to-skedulo" text='Memory Hub now installs from the Skedulo plugin marketplace.'
|
|
801
|
+
[ -f "$file" ] || return 0
|
|
802
|
+
[ "$(sed -n 2p "$file" 2>/dev/null)" = autoupdate ] && text="$text Auto-update is on for the Skedulo plugin marketplace, as it was for Memory Hub."
|
|
803
|
+
rm -f "$file" 2>/dev/null || return 0
|
|
804
|
+
printf '%s' "$text"
|
|
796
805
|
}
|
|
797
806
|
|
|
798
807
|
no_project_pages() {
|
|
@@ -841,6 +850,8 @@ SHARE_NUDGE=$(share_nudge 2>/dev/null || true)
|
|
|
841
850
|
[ -z "$SHARE_NUDGE" ] || NUDGE="${NUDGE}${SHARE_NUDGE}${NL}${NL}"
|
|
842
851
|
MOVE_NUDGE=$(plugin_move_nudge 2>/dev/null || true)
|
|
843
852
|
[ -z "$MOVE_NUDGE" ] || NUDGE="${NUDGE}${MOVE_NUDGE}${NL}${NL}"
|
|
853
|
+
MOVED_NOTICE=$(moved_notice 2>/dev/null || true)
|
|
854
|
+
[ -z "$MOVED_NOTICE" ] || NUDGE="${NUDGE}${MOVED_NOTICE}${NL}${NL}"
|
|
844
855
|
EMPTY_NUDGE=$(empty_project_nudge 2>/dev/null || true)
|
|
845
856
|
[ -z "$EMPTY_NUDGE" ] || NUDGE="${NUDGE}${EMPTY_NUDGE}${NL}${NL}"
|
|
846
857
|
|
package/assets/session-stop.sh
CHANGED
|
@@ -9,7 +9,7 @@ fi
|
|
|
9
9
|
|
|
10
10
|
start_plugin_move() {
|
|
11
11
|
[ "$EVENT" = SessionEnd ] || return 0
|
|
12
|
-
|
|
12
|
+
[ -n "${CLAUDE_PLUGIN_ROOT:-}" ] || return 0
|
|
13
13
|
local cli stamp="$STATE_DIR/plugin-move.stamp" lock="$STATE_DIR/plugin-move.lock" today
|
|
14
14
|
today=$(date +%F)
|
|
15
15
|
[ "$(cat "$stamp" 2>/dev/null)" != "$today" ] || return 0
|
|
@@ -40,7 +40,7 @@ start_plugin_move() {
|
|
|
40
40
|
set -- perl -e '$SIG{HUP} = "IGNORE"; setpgrp(0, 0); exec @ARGV' "$@"
|
|
41
41
|
fi
|
|
42
42
|
trap '' HUP
|
|
43
|
-
"$@" >/dev/null 2>&1 </dev/null &
|
|
43
|
+
(cd "$HOME" 2>/dev/null; "$@" >/dev/null 2>&1 </dev/null &)
|
|
44
44
|
trap - HUP
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -67,7 +67,7 @@ nothing, because only hooks see it; step 3's `memory_login` says whether the per
|
|
|
67
67
|
3. If the browser says they have no login, they need an invite: ask the Memory Hub admin.
|
|
68
68
|
4. If they would rather paste a token than use the browser, give them these two steps and leave the
|
|
69
69
|
pasting to them: copy a token from Pulse Web → their profile → Settings → Developer tools → API
|
|
70
|
-
tokens, then run `/plugin configure memory-hub@memory-hub`
|
|
70
|
+
tokens, then run `/plugin configure <id>` in a terminal, where `<id>` is the installed one (`memory-hub@memory-hub`, `memory-hub@se-ai-memory-hub` or `memory-hub@skedulo-plugin-marketplace`; `claude plugin list` shows it) and restart Claude.
|
|
71
71
|
|
|
72
72
|
## 4. Stop approval prompts (optional)
|
|
73
73
|
|
|
@@ -69,7 +69,7 @@ fi
|
|
|
69
69
|
|
|
70
70
|
say "Plugin:"
|
|
71
71
|
if command -v claude >/dev/null 2>&1; then
|
|
72
|
-
for id in memory-hub@memory-hub memory-hub@se-ai-memory-hub; do
|
|
72
|
+
for id in memory-hub@memory-hub memory-hub@se-ai-memory-hub memory-hub@skedulo-plugin-marketplace; do
|
|
73
73
|
if claude plugin list 2>/dev/null | grep -q "❯ $id\$"; then
|
|
74
74
|
if $DRY; then say " would uninstall $id"; else claude plugin uninstall "$id" >/dev/null 2>&1 && say " uninstalled $id"; fi
|
|
75
75
|
fi
|
package/dist/asset-sync.js
CHANGED
|
@@ -225,7 +225,8 @@ function syncInstalledAssets(options) {
|
|
|
225
225
|
exports.syncInstalledAssets = syncInstalledAssets;
|
|
226
226
|
function refreshInstalledAssets({ distDir = __dirname, home = (0, os_1.homedir)(), log = (line) => console.error(line) } = {}) {
|
|
227
227
|
// A repo checkout runs its hooks in place, so it has no installed copies to refresh.
|
|
228
|
-
|
|
228
|
+
const installed = distDir.split(path_1.sep).includes('node_modules') || (0, fs_1.existsSync)((0, path_1.join)(distDir, '..', '.bundled'));
|
|
229
|
+
if (!installed)
|
|
229
230
|
return undefined;
|
|
230
231
|
try {
|
|
231
232
|
const version = packageVersion(distDir);
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,8 @@ const session_context_1 = require("./session-context");
|
|
|
28
28
|
const version_1 = require("./version");
|
|
29
29
|
const extension_update_1 = require("./extension-update");
|
|
30
30
|
const asset_sync_1 = require("./asset-sync");
|
|
31
|
+
const move_trigger_1 = require("./move-trigger");
|
|
32
|
+
const setup_1 = require("./setup");
|
|
31
33
|
const tags_1 = require("./tags");
|
|
32
34
|
const ask_prompt_1 = require("./ask-prompt");
|
|
33
35
|
const change_tools_1 = require("./change-tools");
|
|
@@ -126,6 +128,7 @@ const login = (0, login_tool_1.createLoginTool)({
|
|
|
126
128
|
status: creds => (0, login_1.tokenStatus)((0, credentials_1.resolveFunctionUrl)(process.env, creds), creds.token),
|
|
127
129
|
extension: process.env.MEMORY_HUB_EXTENSION === '1',
|
|
128
130
|
viaPlugin: process.env.MEMORY_HUB_VIA_PLUGIN === '1',
|
|
131
|
+
marketplace: () => (0, setup_1.marketplaceFromRoot)(process.env.CLAUDE_PLUGIN_ROOT),
|
|
129
132
|
});
|
|
130
133
|
server.tool('memory_login', "Sign in to Memory Hub: opens a Skedulo sign-in in the user's browser and saves the token on this machine. Call it when another memory tool says it isn't signed in, or when the user asks to sign in. Call it again to check whether the sign-in finished.", {}, async () => ({ content: [{ type: 'text', text: await login() }] }));
|
|
131
134
|
server.tool('memory_getSkillGuide', 'Get the current Memory Hub usage guide — when to recall, what to save where, sharing rules, repo linking. Call this first when the memory-hub skill triggers. Pass section to read one part only (for example "Stale memories"), which costs far fewer tokens.', {
|
|
@@ -412,5 +415,20 @@ server.tool('memory_sessionContext', "Load this developer's saved memory-hub con
|
|
|
412
415
|
if (process.env.MEMORY_HUB_EXTENSION !== '1') {
|
|
413
416
|
(0, asset_sync_1.refreshInstalledAssets)();
|
|
414
417
|
}
|
|
418
|
+
const startedAt = Date.now();
|
|
419
|
+
let moveStarted = false;
|
|
420
|
+
const startMoveAtSessionEnd = () => {
|
|
421
|
+
if (moveStarted)
|
|
422
|
+
return;
|
|
423
|
+
moveStarted = true;
|
|
424
|
+
try {
|
|
425
|
+
if ((0, move_trigger_1.shouldStartMove)({ startedAt, now: Date.now(), installedIds: (0, setup_1.installedPluginIds)(), pluginRoot: process.env.CLAUDE_PLUGIN_ROOT })) {
|
|
426
|
+
(0, move_trigger_1.startMoveDetached)((0, path_1.join)(__dirname, 'cli.js'));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch { }
|
|
430
|
+
};
|
|
431
|
+
process.stdin.once('end', startMoveAtSessionEnd);
|
|
432
|
+
process.stdin.once('close', startMoveAtSessionEnd);
|
|
415
433
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
416
434
|
server.connect(transport);
|
package/dist/login-tool.js
CHANGED
|
@@ -7,7 +7,12 @@ const setup_1 = require("./setup");
|
|
|
7
7
|
const SIGNED_IN = 'Signed in. Memory Hub works now, no restart needed.';
|
|
8
8
|
const EXTENSION_ALLOW_NOTE = " If Claude asks before each Memory Hub tool, the user can choose Always allow, or change it later in the Claude app's settings for the Memory Hub extension.";
|
|
9
9
|
const allowOffer = (rule) => ` Then offer once to stop Memory Hub's approval prompts (this covers all its tools, including deleting and sharing memories): if the user agrees, add "${rule}" to permissions.allow in ~/.claude/settings.json (merge it, keep a backup), and say it applies from their next session.`;
|
|
10
|
-
const
|
|
10
|
+
const SKEDULO_EVERY_PLUGIN = ' This turns on auto-update for every plugin from the Skedulo plugin marketplace.';
|
|
11
|
+
const autoUpdateOffer = (name) => {
|
|
12
|
+
const { source, repo, ref } = (0, setup_1.marketplaceSource)(name);
|
|
13
|
+
const shown = JSON.stringify({ source, repo, ...(ref ? { ref } : {}) }).replace(/":"/g, '": "').replace(/","/g, '", "');
|
|
14
|
+
return ` Also offer once to turn on auto-update, so the Memory Hub plugin gets new versions by itself: if the user agrees, set extraKnownMarketplaces["${name}"].autoUpdate to true in ~/.claude/settings.json, adding the entry with source ${shown} if it is missing (merge it, keep a backup).${name === setup_1.SKEDULO_MARKETPLACE_NAME ? SKEDULO_EVERY_PLUGIN : ''}`;
|
|
15
|
+
};
|
|
11
16
|
const FIRST_CALL_WAIT_MS = 5000;
|
|
12
17
|
const POLL_MS = 25;
|
|
13
18
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -53,11 +58,15 @@ function createLoginTool(deps) {
|
|
|
53
58
|
: `The token in MEMORY_HUB_MCP_TOKEN (in ~/.claude/settings.json, or the plugin's token option) was rejected (HTTP ${status}). It wins over a browser sign-in, so remove it, restart Claude, then call memory_login again.`,
|
|
54
59
|
};
|
|
55
60
|
};
|
|
61
|
+
const offerMarketplace = () => {
|
|
62
|
+
const name = deps.marketplace?.();
|
|
63
|
+
return name === setup_1.SKEDULO_MARKETPLACE_NAME ? name : setup_1.MARKETPLACE_NAME;
|
|
64
|
+
};
|
|
56
65
|
const signedIn = () => {
|
|
57
66
|
if (deps.extension)
|
|
58
67
|
return `${SIGNED_IN}${EXTENSION_ALLOW_NOTE}`;
|
|
59
68
|
if (deps.viaPlugin)
|
|
60
|
-
return `${SIGNED_IN}${allowOffer(setup_1.PLUGIN_ALLOW_RULE)}${
|
|
69
|
+
return `${SIGNED_IN}${allowOffer(setup_1.PLUGIN_ALLOW_RULE)}${autoUpdateOffer(offerMarketplace())}`;
|
|
61
70
|
return `${SIGNED_IN}${allowOffer(setup_1.DIRECT_ALLOW_RULE)}`;
|
|
62
71
|
};
|
|
63
72
|
const call = async () => {
|
package/dist/migrate-plugin.js
CHANGED
|
@@ -1,61 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runMigratePlugin = exports.migratePlugin = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
3
|
+
exports.runMigratePlugin = exports.migratePlugin = exports.captureFlag = void 0;
|
|
5
4
|
const path_1 = require("path");
|
|
6
5
|
const setup_1 = require("./setup");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
}
|
|
6
|
+
const move_lock_1 = require("./move-lock");
|
|
7
|
+
const skedulo_move_1 = require("./skedulo-move");
|
|
8
|
+
const plugin_move_util_1 = require("./plugin-move-util");
|
|
9
|
+
Object.defineProperty(exports, "captureFlag", { enumerable: true, get: function () { return plugin_move_util_1.captureFlag; } });
|
|
55
10
|
function migratePlugin(deps) {
|
|
11
|
+
if ((0, setup_1.skeduloMoveEnabled)(deps.env ?? process.env))
|
|
12
|
+
return (0, skedulo_move_1.moveToSkedulo)(deps);
|
|
56
13
|
const { run, configDir } = deps;
|
|
57
14
|
const finish = (status, reason) => {
|
|
58
|
-
deps.log(logLine(status, reason));
|
|
15
|
+
deps.log((0, plugin_move_util_1.logLine)(status, reason));
|
|
59
16
|
return { status, reason };
|
|
60
17
|
};
|
|
61
18
|
const settingsPath = (0, path_1.join)(configDir, 'settings.json');
|
|
@@ -64,7 +21,7 @@ function migratePlugin(deps) {
|
|
|
64
21
|
const retireOld = (notes) => {
|
|
65
22
|
let left;
|
|
66
23
|
try {
|
|
67
|
-
if (readStrict(settingsPath)?.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true) {
|
|
24
|
+
if ((0, plugin_move_util_1.readStrict)(settingsPath)?.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true) {
|
|
68
25
|
const disabled = run(['plugin', 'disable', setup_1.LEGACY_PLUGIN_ID]);
|
|
69
26
|
if (disabled.status !== 0)
|
|
70
27
|
left = `disable failed (${(0, setup_1.lastLine)(disabled.output)})`;
|
|
@@ -76,13 +33,13 @@ function migratePlugin(deps) {
|
|
|
76
33
|
}
|
|
77
34
|
}
|
|
78
35
|
catch (error) {
|
|
79
|
-
left = message(error);
|
|
36
|
+
left = (0, plugin_move_util_1.message)(error);
|
|
80
37
|
}
|
|
81
38
|
if (left === undefined)
|
|
82
39
|
return;
|
|
83
40
|
notes.push(`old marketplace not removed: ${left}`);
|
|
84
41
|
try {
|
|
85
|
-
const turnedOff = updateSettings(settingsPath, (current) => {
|
|
42
|
+
const turnedOff = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
86
43
|
if (current.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true)
|
|
87
44
|
current.enabledPlugins[setup_1.LEGACY_PLUGIN_ID] = false;
|
|
88
45
|
});
|
|
@@ -90,26 +47,25 @@ function migratePlugin(deps) {
|
|
|
90
47
|
notes.push(`${setup_1.LEGACY_PLUGIN_ID} still enabled, settings unreadable`);
|
|
91
48
|
}
|
|
92
49
|
catch (error) {
|
|
93
|
-
notes.push(`${setup_1.LEGACY_PLUGIN_ID} still enabled (${message(error)})`);
|
|
50
|
+
notes.push(`${setup_1.LEGACY_PLUGIN_ID} still enabled (${(0, plugin_move_util_1.message)(error)})`);
|
|
94
51
|
}
|
|
95
52
|
};
|
|
96
|
-
const withNotes = (reason, notes) => (notes.length > 0 ? `${reason} (${notes.join('; ')})` : reason);
|
|
97
53
|
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);
|
|
54
|
+
if (!(0, plugin_move_util_1.has)(plugins, setup_1.LEGACY_PLUGIN_ID))
|
|
55
|
+
return finish('skipped', (0, plugin_move_util_1.has)(plugins, setup_1.PLUGIN_ID) ? 'already moved' : 'not installed');
|
|
56
|
+
const settings = (0, plugin_move_util_1.readStrict)(settingsPath);
|
|
101
57
|
if (!settings)
|
|
102
58
|
return finish('skipped', 'settings unreadable');
|
|
103
59
|
const records = Array.isArray(plugins[setup_1.LEGACY_PLUGIN_ID]) ? plugins[setup_1.LEGACY_PLUGIN_ID] : [];
|
|
104
60
|
const userScopeOnly = records.length > 0 && records.every((record) => record?.scope === 'user');
|
|
105
|
-
if (has(plugins, setup_1.PLUGIN_ID)) {
|
|
61
|
+
if ((0, plugin_move_util_1.has)(plugins, setup_1.PLUGIN_ID)) {
|
|
106
62
|
if (!userScopeOnly)
|
|
107
63
|
return finish('skipped', 'not user scope');
|
|
108
64
|
// A move cut off after the new install leaves both IDs loaded until the old marketplace goes.
|
|
109
|
-
const known = readStrict(knownPath);
|
|
65
|
+
const known = (0, plugin_move_util_1.readStrict)(knownPath);
|
|
110
66
|
if (!known)
|
|
111
67
|
return finish('skipped', 'marketplaces unreadable');
|
|
112
|
-
if (!has(known, setup_1.LEGACY_MARKETPLACE_NAME) || !(0, setup_1.isHubSource)(known[setup_1.MARKETPLACE_NAME]?.source))
|
|
68
|
+
if (!(0, plugin_move_util_1.has)(known, setup_1.LEGACY_MARKETPLACE_NAME) || !(0, setup_1.isHubSource)(known[setup_1.MARKETPLACE_NAME]?.source))
|
|
113
69
|
return finish('skipped', 'already moved');
|
|
114
70
|
const newRecords = Array.isArray(plugins[setup_1.PLUGIN_ID]) ? plugins[setup_1.PLUGIN_ID] : [];
|
|
115
71
|
const newActive = newRecords.some((record) => record?.scope === 'user') && settings.enabledPlugins?.[setup_1.PLUGIN_ID] === true;
|
|
@@ -117,7 +73,7 @@ function migratePlugin(deps) {
|
|
|
117
73
|
return finish('skipped', 'new install not active');
|
|
118
74
|
const notes = [];
|
|
119
75
|
retireOld(notes);
|
|
120
|
-
return finish('moved', withNotes('retired the old install', notes));
|
|
76
|
+
return finish('moved', (0, plugin_move_util_1.withNotes)('retired the old install', notes));
|
|
121
77
|
}
|
|
122
78
|
if (settings.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] !== true)
|
|
123
79
|
return finish('skipped', 'disabled');
|
|
@@ -130,7 +86,7 @@ function migratePlugin(deps) {
|
|
|
130
86
|
if (!(0, setup_1.isHubSource)(declared?.source))
|
|
131
87
|
return finish('skipped', 'old marketplace not in settings');
|
|
132
88
|
const configured = run(['plugin', 'configure', '--json', setup_1.LEGACY_PLUGIN_ID]);
|
|
133
|
-
const options = configured.status === 0 ? parseObject(configured.output) : undefined;
|
|
89
|
+
const options = configured.status === 0 ? (0, plugin_move_util_1.parseObject)(configured.output) : undefined;
|
|
134
90
|
if (!options || !Array.isArray(options.configured))
|
|
135
91
|
return finish('failed', 'could not read the plugin options, nothing changed');
|
|
136
92
|
const settingsToken = settings.env?.MEMORY_HUB_MCP_TOKEN;
|
|
@@ -139,14 +95,14 @@ function migratePlugin(deps) {
|
|
|
139
95
|
return finish('skipped', 'pasted token');
|
|
140
96
|
if (run(['plugin', 'marketplace', 'update', setup_1.LEGACY_MARKETPLACE_NAME]).status !== 0)
|
|
141
97
|
return finish('skipped', 'cannot reach the marketplace');
|
|
142
|
-
const knownAtStart = readStrict(knownPath);
|
|
143
|
-
if (!knownAtStart || !has(knownAtStart, setup_1.LEGACY_MARKETPLACE_NAME))
|
|
98
|
+
const knownAtStart = (0, plugin_move_util_1.readStrict)(knownPath);
|
|
99
|
+
if (!knownAtStart || !(0, plugin_move_util_1.has)(knownAtStart, setup_1.LEGACY_MARKETPLACE_NAME))
|
|
144
100
|
return finish('skipped', 'marketplaces unreadable');
|
|
145
|
-
const capture = options.inputs
|
|
101
|
+
const capture = (0, plugin_move_util_1.captureFlag)(options.inputs);
|
|
146
102
|
const ref = declared.source.ref || setup_1.MARKETPLACE_REF;
|
|
147
103
|
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]);
|
|
104
|
+
const marketplacesBefore = (0, plugin_move_util_1.pick)(settings.extraKnownMarketplaces, [setup_1.MARKETPLACE_NAME]);
|
|
105
|
+
const enabledBefore = (0, plugin_move_util_1.pick)(settings.enabledPlugins, [setup_1.PLUGIN_ID]);
|
|
150
106
|
const addAndInstall = () => {
|
|
151
107
|
const added = run(['plugin', 'marketplace', 'add', `${setup_1.MARKETPLACE_GIT_URL}#${ref}`]);
|
|
152
108
|
if (added.status !== 0)
|
|
@@ -156,7 +112,7 @@ function migratePlugin(deps) {
|
|
|
156
112
|
const installed = run(['plugin', 'install', setup_1.PLUGIN_ID, ...capture]);
|
|
157
113
|
if (installed.status !== 0)
|
|
158
114
|
return `install failed (${(0, setup_1.lastLine)(installed.output)})`;
|
|
159
|
-
if ((0, setup_1.
|
|
115
|
+
if (!(0, setup_1.installedPluginIds)(installedPath).includes(setup_1.PLUGIN_ID))
|
|
160
116
|
return `install failed (claude did not list ${setup_1.PLUGIN_ID})`;
|
|
161
117
|
return undefined;
|
|
162
118
|
};
|
|
@@ -166,9 +122,9 @@ function migratePlugin(deps) {
|
|
|
166
122
|
if (name !== setup_1.LEGACY_MARKETPLACE_NAME && !knownBefore.has(name) && (0, setup_1.isHubSource)(known[name]?.source))
|
|
167
123
|
run(['plugin', 'marketplace', 'remove', name]);
|
|
168
124
|
}
|
|
169
|
-
const restored = updateSettings(settingsPath, (current) => {
|
|
170
|
-
putBack(current, 'extraKnownMarketplaces', [setup_1.MARKETPLACE_NAME], marketplacesBefore);
|
|
171
|
-
putBack(current, 'enabledPlugins', [setup_1.PLUGIN_ID], enabledBefore);
|
|
125
|
+
const restored = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
126
|
+
(0, plugin_move_util_1.putBack)(current, 'extraKnownMarketplaces', [setup_1.MARKETPLACE_NAME], marketplacesBefore);
|
|
127
|
+
(0, plugin_move_util_1.putBack)(current, 'enabledPlugins', [setup_1.PLUGIN_ID], enabledBefore);
|
|
172
128
|
});
|
|
173
129
|
return restored ? `${setup_1.LEGACY_PLUGIN_ID} untouched` : `${setup_1.LEGACY_PLUGIN_ID} untouched, settings unreadable and left as they are`;
|
|
174
130
|
};
|
|
@@ -177,7 +133,7 @@ function migratePlugin(deps) {
|
|
|
177
133
|
failure = addAndInstall();
|
|
178
134
|
}
|
|
179
135
|
catch (error) {
|
|
180
|
-
failure = `add or install failed (${message(error)})`;
|
|
136
|
+
failure = `add or install failed (${(0, plugin_move_util_1.message)(error)})`;
|
|
181
137
|
}
|
|
182
138
|
if (failure !== undefined) {
|
|
183
139
|
let outcome;
|
|
@@ -185,7 +141,7 @@ function migratePlugin(deps) {
|
|
|
185
141
|
outcome = undoNew();
|
|
186
142
|
}
|
|
187
143
|
catch (error) {
|
|
188
|
-
outcome = `undoing the new marketplace failed (${message(error)})`;
|
|
144
|
+
outcome = `undoing the new marketplace failed (${(0, plugin_move_util_1.message)(error)})`;
|
|
189
145
|
}
|
|
190
146
|
return finish('failed', `${failure}; ${outcome}`);
|
|
191
147
|
}
|
|
@@ -193,7 +149,7 @@ function migratePlugin(deps) {
|
|
|
193
149
|
retireOld(notes);
|
|
194
150
|
if (declared.autoUpdate === true) {
|
|
195
151
|
try {
|
|
196
|
-
const set = updateSettings(settingsPath, (current) => {
|
|
152
|
+
const set = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
197
153
|
const known = (current.extraKnownMarketplaces ||= {});
|
|
198
154
|
known[setup_1.MARKETPLACE_NAME] = { source: { source: 'git', url: setup_1.MARKETPLACE_GIT_URL, ref }, ...known[setup_1.MARKETPLACE_NAME], autoUpdate: true };
|
|
199
155
|
});
|
|
@@ -201,19 +157,31 @@ function migratePlugin(deps) {
|
|
|
201
157
|
notes.push('auto-update not carried over, settings unreadable');
|
|
202
158
|
}
|
|
203
159
|
catch (error) {
|
|
204
|
-
notes.push(`auto-update not carried over (${message(error)})`);
|
|
160
|
+
notes.push(`auto-update not carried over (${(0, plugin_move_util_1.message)(error)})`);
|
|
205
161
|
}
|
|
206
162
|
}
|
|
207
|
-
return finish('moved', withNotes(`${setup_1.LEGACY_PLUGIN_ID} to ${setup_1.PLUGIN_ID}, loads at the next session`, notes));
|
|
163
|
+
return finish('moved', (0, plugin_move_util_1.withNotes)(`${setup_1.LEGACY_PLUGIN_ID} to ${setup_1.PLUGIN_ID}, loads at the next session`, notes));
|
|
208
164
|
}
|
|
209
165
|
exports.migratePlugin = migratePlugin;
|
|
210
|
-
async function runMigratePlugin(
|
|
166
|
+
async function runMigratePlugin(argv) {
|
|
211
167
|
const log = (line) => console.log(line);
|
|
212
168
|
const run = (0, setup_1.claudeRunner)();
|
|
213
169
|
if (!run) {
|
|
214
|
-
log(logLine('skipped', 'claude CLI not on PATH'));
|
|
170
|
+
log((0, plugin_move_util_1.logLine)('skipped', 'claude CLI not on PATH'));
|
|
215
171
|
return 0;
|
|
216
172
|
}
|
|
217
|
-
|
|
173
|
+
const move = () => migratePlugin({ run, configDir: (0, setup_1.claudeConfigDir)(), log }).status === 'failed' ? 1 : 0;
|
|
174
|
+
if (!argv.includes('--take-lock'))
|
|
175
|
+
return move();
|
|
176
|
+
let code = 0;
|
|
177
|
+
const outcome = (0, move_lock_1.withMoveLock)(() => {
|
|
178
|
+
code = move();
|
|
179
|
+
}, { stamp: true });
|
|
180
|
+
// Not a result word: the session-start nudge reads the last moved/skipped/failed line.
|
|
181
|
+
if (outcome === 'busy')
|
|
182
|
+
log(`${new Date().toISOString()} note busy`);
|
|
183
|
+
if (outcome === 'done-today')
|
|
184
|
+
log(`${new Date().toISOString()} note done today`);
|
|
185
|
+
return code;
|
|
218
186
|
}
|
|
219
187
|
exports.runMigratePlugin = runMigratePlugin;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withMoveLock = exports.today = exports.moveStateDir = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const os_1 = require("os");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const MOVE_LOCK_STALE_MS = 60 * 60 * 1000;
|
|
8
|
+
function moveStateDir(env = process.env) {
|
|
9
|
+
return env.MEMORY_HUB_STATE_DIR || (0, path_1.join)((0, os_1.homedir)(), '.claude', 'memory-hub-hook', 'state');
|
|
10
|
+
}
|
|
11
|
+
exports.moveStateDir = moveStateDir;
|
|
12
|
+
// Local date, like `date +%F` in the SessionEnd hook.
|
|
13
|
+
function today() {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
16
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
17
|
+
}
|
|
18
|
+
exports.today = today;
|
|
19
|
+
// The same lock the SessionEnd hook takes, so setup and a background move never overlap.
|
|
20
|
+
function withMoveLock(fn, opts, env = process.env) {
|
|
21
|
+
const stateDir = moveStateDir(env);
|
|
22
|
+
const lock = (0, path_1.join)(stateDir, 'plugin-move.lock');
|
|
23
|
+
try {
|
|
24
|
+
(0, fs_1.mkdirSync)(stateDir, { recursive: true });
|
|
25
|
+
if ((0, fs_1.existsSync)(lock) && Date.now() - (0, fs_1.statSync)(lock).mtimeMs > MOVE_LOCK_STALE_MS)
|
|
26
|
+
(0, fs_1.rmdirSync)(lock);
|
|
27
|
+
(0, fs_1.mkdirSync)(lock);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return 'busy';
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
if (opts.stamp) {
|
|
34
|
+
const stamp = (0, path_1.join)(stateDir, 'plugin-move.stamp');
|
|
35
|
+
const day = today();
|
|
36
|
+
let last = '';
|
|
37
|
+
try {
|
|
38
|
+
last = (0, fs_1.readFileSync)(stamp, 'utf8').trim();
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
if (last === day)
|
|
42
|
+
return 'done-today';
|
|
43
|
+
(0, fs_1.writeFileSync)(stamp, `${day}\n`);
|
|
44
|
+
}
|
|
45
|
+
fn();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
try {
|
|
49
|
+
(0, fs_1.rmdirSync)(lock);
|
|
50
|
+
}
|
|
51
|
+
catch { }
|
|
52
|
+
}
|
|
53
|
+
return 'ran';
|
|
54
|
+
}
|
|
55
|
+
exports.withMoveLock = withMoveLock;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startMoveDetached = exports.shouldStartMove = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const move_lock_1 = require("./move-lock");
|
|
9
|
+
const setup_1 = require("./setup");
|
|
10
|
+
const MIN_SESSION_MS = 600_000;
|
|
11
|
+
function shouldStartMove(opts) {
|
|
12
|
+
if (!opts.pluginRoot)
|
|
13
|
+
return false;
|
|
14
|
+
const oldListed = opts.installedIds.includes(setup_1.PLUGIN_ID) || opts.installedIds.includes(setup_1.LEGACY_PLUGIN_ID);
|
|
15
|
+
return oldListed && opts.now - opts.startedAt >= MIN_SESSION_MS;
|
|
16
|
+
}
|
|
17
|
+
exports.shouldStartMove = shouldStartMove;
|
|
18
|
+
function openMoveLog() {
|
|
19
|
+
try {
|
|
20
|
+
const dir = (0, move_lock_1.moveStateDir)();
|
|
21
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
22
|
+
return (0, fs_1.openSync)((0, path_1.join)(dir, 'plugin-move.log'), 'a');
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function startMoveDetached(cliPath, spawnFn = child_process_1.spawn, openLog = openMoveLog) {
|
|
29
|
+
const fd = openLog();
|
|
30
|
+
try {
|
|
31
|
+
const child = spawnFn(process.execPath, [cliPath, 'migrate-plugin', '--take-lock'], {
|
|
32
|
+
detached: true,
|
|
33
|
+
stdio: fd === undefined ? 'ignore' : ['ignore', fd, fd],
|
|
34
|
+
cwd: (0, os_1.homedir)(),
|
|
35
|
+
});
|
|
36
|
+
child.unref();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (fd !== undefined)
|
|
40
|
+
(0, fs_1.closeSync)(fd);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.startMoveDetached = startMoveDetached;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logLine = exports.withNotes = exports.captureFlag = exports.captureValue = exports.putBack = exports.pick = exports.updateSettings = exports.readStrict = exports.parseObject = exports.message = exports.has = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const setup_1 = require("./setup");
|
|
6
|
+
const has = (value, key) => typeof value === 'object' && value !== null && Object.prototype.hasOwnProperty.call(value, key);
|
|
7
|
+
exports.has = has;
|
|
8
|
+
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
9
|
+
exports.message = message;
|
|
10
|
+
function parseObject(output) {
|
|
11
|
+
const start = output.indexOf('{');
|
|
12
|
+
const end = output.lastIndexOf('}');
|
|
13
|
+
if (start < 0 || end < start)
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(output.slice(start, end + 1));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.parseObject = parseObject;
|
|
23
|
+
// readJson reads a torn or hand-broken file as {}, and writing that back would wipe the user's settings.
|
|
24
|
+
function readStrict(path) {
|
|
25
|
+
if (!(0, fs_1.existsSync)(path))
|
|
26
|
+
return {};
|
|
27
|
+
try {
|
|
28
|
+
const value = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
|
|
29
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.readStrict = readStrict;
|
|
36
|
+
function updateSettings(path, change) {
|
|
37
|
+
const settings = readStrict(path);
|
|
38
|
+
if (!settings)
|
|
39
|
+
return false;
|
|
40
|
+
change(settings);
|
|
41
|
+
(0, setup_1.writeJson)(path, settings);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
exports.updateSettings = updateSettings;
|
|
45
|
+
function pick(source, keys) {
|
|
46
|
+
return Object.fromEntries(keys.filter((key) => (0, exports.has)(source, key)).map((key) => [key, JSON.parse(JSON.stringify(source[key]))]));
|
|
47
|
+
}
|
|
48
|
+
exports.pick = pick;
|
|
49
|
+
function putBack(settings, field, keys, before) {
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if ((0, exports.has)(before, key))
|
|
52
|
+
(settings[field] ||= {})[key] = before[key];
|
|
53
|
+
else if ((0, exports.has)(settings[field], key))
|
|
54
|
+
delete settings[field][key];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.putBack = putBack;
|
|
58
|
+
function captureValue(inputs) {
|
|
59
|
+
const capture = inputs?.capture;
|
|
60
|
+
if (capture === true || capture === 'true')
|
|
61
|
+
return true;
|
|
62
|
+
if (capture === false || capture === 'false')
|
|
63
|
+
return false;
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
exports.captureValue = captureValue;
|
|
67
|
+
function captureFlag(inputs) {
|
|
68
|
+
const capture = captureValue(inputs);
|
|
69
|
+
return capture === undefined ? [] : ['--config', `capture=${capture}`];
|
|
70
|
+
}
|
|
71
|
+
exports.captureFlag = captureFlag;
|
|
72
|
+
const withNotes = (reason, notes) => (notes.length > 0 ? `${reason} (${notes.join('; ')})` : reason);
|
|
73
|
+
exports.withNotes = withNotes;
|
|
74
|
+
function logLine(status, reason) {
|
|
75
|
+
return `${new Date().toISOString()} ${status} ${reason.replace(/\s+/g, ' ')}`;
|
|
76
|
+
}
|
|
77
|
+
exports.logLine = logLine;
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.desktopRestartOffer = exports.insideClaudeDesktop = exports.chooseSetup = 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.allowMemoryHubTools = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.writeJson = exports.readJsonStrict = exports.readJson = exports.desktopConfigPath = exports.mcpLaunch = exports.lastLine = exports.isSkeduloSource = exports.isHubSource = exports.pluginInstalled = exports.installedPluginId = exports.installedPluginIds = exports.claudeConfigDir = exports.marketplaceSource = exports.marketplaceFromRoot = exports.skeduloMoveEnabled = exports.LEGACY_PLUGIN_ID = exports.SKEDULO_MARKETPLACE_MOVE = exports.SKEDULO_PLUGIN_ID = exports.SKEDULO_MARKETPLACE_REPO = exports.SKEDULO_MARKETPLACE_NAME = exports.PLUGIN_ID = exports.DIRECT_ALLOW_RULE = exports.PLUGIN_ALLOW_RULE = 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
|
+
exports.runSetup = exports.runCapture = exports.captureMessage = exports.processAncestors = exports.doneLine = void 0;
|
|
4
5
|
const child_process_1 = require("child_process");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const os_1 = require("os");
|
|
@@ -8,6 +9,8 @@ const path_1 = require("path");
|
|
|
8
9
|
const readline_1 = require("readline");
|
|
9
10
|
const asset_sync_1 = require("./asset-sync");
|
|
10
11
|
const migrate_plugin_1 = require("./migrate-plugin");
|
|
12
|
+
const skedulo_move_1 = require("./skedulo-move");
|
|
13
|
+
const move_lock_1 = require("./move-lock");
|
|
11
14
|
const DEFAULT_API_HOST = 'dev-api.test.skl.io';
|
|
12
15
|
const DEFAULT_TENANT = 'memory-hub';
|
|
13
16
|
const SKED_CONFIG = (0, path_1.join)((0, os_1.homedir)(), '.config', 'sked', 'config.json');
|
|
@@ -30,7 +33,28 @@ exports.MARKETPLACE_REF = 'main';
|
|
|
30
33
|
exports.PLUGIN_ALLOW_RULE = 'mcp__plugin_memory-hub_memory-hub__*';
|
|
31
34
|
exports.DIRECT_ALLOW_RULE = 'mcp__memory-hub__*';
|
|
32
35
|
exports.PLUGIN_ID = `memory-hub@${exports.MARKETPLACE_NAME}`;
|
|
36
|
+
exports.SKEDULO_MARKETPLACE_NAME = 'skedulo-plugin-marketplace';
|
|
37
|
+
exports.SKEDULO_MARKETPLACE_REPO = 'Skedulo/skedulo-plugin-marketplace';
|
|
38
|
+
exports.SKEDULO_PLUGIN_ID = `memory-hub@${exports.SKEDULO_MARKETPLACE_NAME}`;
|
|
39
|
+
exports.SKEDULO_MARKETPLACE_MOVE = false;
|
|
33
40
|
exports.LEGACY_PLUGIN_ID = `memory-hub@${exports.LEGACY_MARKETPLACE_NAME}`;
|
|
41
|
+
function skeduloMoveEnabled(env = process.env) {
|
|
42
|
+
return exports.SKEDULO_MARKETPLACE_MOVE || env.MEMORY_HUB_SKEDULO_MOVE === '1';
|
|
43
|
+
}
|
|
44
|
+
exports.skeduloMoveEnabled = skeduloMoveEnabled;
|
|
45
|
+
function marketplaceFromRoot(root) {
|
|
46
|
+
const path = (root || '').replace(/\\/g, '/');
|
|
47
|
+
const marker = 'plugins/cache/';
|
|
48
|
+
const at = path.indexOf(marker);
|
|
49
|
+
return at < 0 ? undefined : path.slice(at + marker.length).split('/')[0] || undefined;
|
|
50
|
+
}
|
|
51
|
+
exports.marketplaceFromRoot = marketplaceFromRoot;
|
|
52
|
+
function marketplaceSource(name) {
|
|
53
|
+
if (name === exports.SKEDULO_MARKETPLACE_NAME)
|
|
54
|
+
return { source: 'github', repo: exports.SKEDULO_MARKETPLACE_REPO };
|
|
55
|
+
return { source: 'github', repo: exports.MARKETPLACE_REPO, ref: exports.MARKETPLACE_REF };
|
|
56
|
+
}
|
|
57
|
+
exports.marketplaceSource = marketplaceSource;
|
|
34
58
|
// `||`, not `??`: Claude Code treats an empty CLAUDE_CONFIG_DIR as the current directory.
|
|
35
59
|
function claudeConfigDir(env = process.env, home = (0, os_1.homedir)()) {
|
|
36
60
|
return env.CLAUDE_CONFIG_DIR || (0, path_1.join)(home, '.claude');
|
|
@@ -38,7 +62,7 @@ function claudeConfigDir(env = process.env, home = (0, os_1.homedir)()) {
|
|
|
38
62
|
exports.claudeConfigDir = claudeConfigDir;
|
|
39
63
|
function installedPluginIds(path = (0, path_1.join)(claudeConfigDir(), 'plugins', 'installed_plugins.json')) {
|
|
40
64
|
const plugins = readJson(path).plugins || {};
|
|
41
|
-
return [exports.PLUGIN_ID, exports.LEGACY_PLUGIN_ID].filter((id) => Object.prototype.hasOwnProperty.call(plugins, id));
|
|
65
|
+
return [exports.SKEDULO_PLUGIN_ID, exports.PLUGIN_ID, exports.LEGACY_PLUGIN_ID].filter((id) => Object.prototype.hasOwnProperty.call(plugins, id));
|
|
42
66
|
}
|
|
43
67
|
exports.installedPluginIds = installedPluginIds;
|
|
44
68
|
function installedPluginId(path) {
|
|
@@ -49,9 +73,9 @@ function pluginInstalled(path) {
|
|
|
49
73
|
return installedPluginId(path) !== undefined;
|
|
50
74
|
}
|
|
51
75
|
exports.pluginInstalled = pluginInstalled;
|
|
52
|
-
function
|
|
76
|
+
function sourceIsRepo(source, repoName) {
|
|
53
77
|
const s = (source || {});
|
|
54
|
-
const repo =
|
|
78
|
+
const repo = repoName.toLowerCase();
|
|
55
79
|
if (typeof s.repo === 'string')
|
|
56
80
|
return s.repo.toLowerCase() === repo;
|
|
57
81
|
if (typeof s.url !== 'string')
|
|
@@ -59,7 +83,10 @@ function isHubSource(source) {
|
|
|
59
83
|
const url = s.url.toLowerCase().replace(/\.git$/, '');
|
|
60
84
|
return url.endsWith(`/${repo}`) || url.endsWith(`:${repo}`);
|
|
61
85
|
}
|
|
86
|
+
const isHubSource = (source) => sourceIsRepo(source, exports.MARKETPLACE_REPO);
|
|
62
87
|
exports.isHubSource = isHubSource;
|
|
88
|
+
const isSkeduloSource = (source) => sourceIsRepo(source, exports.SKEDULO_MARKETPLACE_REPO);
|
|
89
|
+
exports.isSkeduloSource = isSkeduloSource;
|
|
63
90
|
function lastLine(output) {
|
|
64
91
|
return output.trim().split('\n').pop() || 'no output';
|
|
65
92
|
}
|
|
@@ -289,10 +316,21 @@ exports.enableMarketplaceAutoUpdate = enableMarketplaceAutoUpdate;
|
|
|
289
316
|
// The repo's marketplace.json decides the name `marketplace add` registers, and main may still carry the old one.
|
|
290
317
|
function registeredMarketplace(knownPath) {
|
|
291
318
|
const known = readJson(knownPath);
|
|
292
|
-
const names = Object.keys(known).filter((name) => isHubSource(known[name]?.source));
|
|
319
|
+
const names = Object.keys(known).filter((name) => (0, exports.isHubSource)(known[name]?.source));
|
|
293
320
|
return names.includes(exports.MARKETPLACE_NAME) ? exports.MARKETPLACE_NAME : names[0] || exports.MARKETPLACE_NAME;
|
|
294
321
|
}
|
|
295
|
-
function
|
|
322
|
+
function installFromSkedulo(run, installedPath, knownPath) {
|
|
323
|
+
const known = readJson(knownPath);
|
|
324
|
+
const registered = Object.keys(known).includes(exports.SKEDULO_MARKETPLACE_NAME) && (0, exports.isSkeduloSource)(known[exports.SKEDULO_MARKETPLACE_NAME]?.source);
|
|
325
|
+
if (!registered && run(['plugin', 'marketplace', 'add', exports.SKEDULO_MARKETPLACE_REPO]).status !== 0)
|
|
326
|
+
return false;
|
|
327
|
+
if (run(['plugin', 'install', exports.SKEDULO_PLUGIN_ID, '--scope', 'user']).status !== 0)
|
|
328
|
+
return false;
|
|
329
|
+
return installedPluginIds(installedPath).includes(exports.SKEDULO_PLUGIN_ID);
|
|
330
|
+
}
|
|
331
|
+
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'), env = process.env) {
|
|
332
|
+
if (skeduloMoveEnabled(env) && installFromSkedulo(run, installedPath, knownPath))
|
|
333
|
+
return { ok: true };
|
|
296
334
|
const added = run(['plugin', 'marketplace', 'add', `${exports.MARKETPLACE_REPO}#${exports.MARKETPLACE_REF}`]);
|
|
297
335
|
if (added.status !== 0)
|
|
298
336
|
return { ok: false, reason: lastLine(added.output) };
|
|
@@ -302,15 +340,16 @@ function installPlugin(run, settingsPath, installedPath = (0, path_1.join)(claud
|
|
|
302
340
|
const installed = run(['plugin', 'install', id]);
|
|
303
341
|
if (installed.status !== 0)
|
|
304
342
|
return { ok: false, reason: lastLine(installed.output) };
|
|
305
|
-
return
|
|
343
|
+
return installedPluginIds(installedPath).includes(id) ? { ok: true } : { ok: false, reason: 'claude reported success but did not list the plugin' };
|
|
306
344
|
}
|
|
307
345
|
exports.installPlugin = installPlugin;
|
|
308
346
|
// Without repo access git would otherwise wait on a password prompt or an SSH host-key question.
|
|
309
347
|
function claudeRunner() {
|
|
310
|
-
|
|
348
|
+
const command = (0, child_process_1.spawnSync)('which', ['claude']).status === 0 ? 'claude' : process.env.CLAUDE_CODE_EXECPATH;
|
|
349
|
+
if (!command)
|
|
311
350
|
return undefined;
|
|
312
351
|
return (args) => {
|
|
313
|
-
const result = (0, child_process_1.spawnSync)(
|
|
352
|
+
const result = (0, child_process_1.spawnSync)(command, args, {
|
|
314
353
|
encoding: 'utf8',
|
|
315
354
|
timeout: 180000,
|
|
316
355
|
env: {
|
|
@@ -634,53 +673,38 @@ async function runCapture(argv = []) {
|
|
|
634
673
|
}
|
|
635
674
|
exports.runCapture = runCapture;
|
|
636
675
|
const QUIET_SKIPS = ['not installed', 'already moved', 'not released yet'];
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
(0,
|
|
647
|
-
|
|
648
|
-
catch {
|
|
649
|
-
return false;
|
|
650
|
-
}
|
|
651
|
-
try {
|
|
652
|
-
fn();
|
|
653
|
-
}
|
|
654
|
-
finally {
|
|
655
|
-
try {
|
|
656
|
-
(0, fs_1.rmdirSync)(lock);
|
|
657
|
-
}
|
|
658
|
-
catch { }
|
|
659
|
-
}
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
function moveLegacyPlugin() {
|
|
676
|
+
function hasOldPlugin() {
|
|
677
|
+
const ids = installedPluginIds();
|
|
678
|
+
return ids.includes(exports.LEGACY_PLUGIN_ID) || (skeduloMoveEnabled() && ids.includes(exports.PLUGIN_ID));
|
|
679
|
+
}
|
|
680
|
+
function moveOldPlugin() {
|
|
681
|
+
const skedulo = skeduloMoveEnabled();
|
|
682
|
+
const target = skedulo ? exports.SKEDULO_PLUGIN_ID : exports.PLUGIN_ID;
|
|
683
|
+
const configDir = claudeConfigDir();
|
|
684
|
+
const from = skedulo
|
|
685
|
+
? ((0, skedulo_move_1.pickOldId)(readJson((0, path_1.join)(configDir, 'plugins', 'installed_plugins.json')).plugins || {}, readJson((0, path_1.join)(configDir, 'settings.json')))?.old ?? exports.PLUGIN_ID)
|
|
686
|
+
: exports.LEGACY_PLUGIN_ID;
|
|
663
687
|
const run = claudeRunner();
|
|
664
688
|
if (!run) {
|
|
665
|
-
console.log(` kept ${
|
|
689
|
+
console.log(` kept ${from}: the claude CLI is not on PATH to move it to ${target}.`);
|
|
666
690
|
return;
|
|
667
691
|
}
|
|
668
692
|
let result;
|
|
669
|
-
const
|
|
670
|
-
result = (0, migrate_plugin_1.migratePlugin)({ run, configDir
|
|
671
|
-
});
|
|
672
|
-
if (
|
|
673
|
-
console.log(` a move of ${
|
|
693
|
+
const outcome = (0, move_lock_1.withMoveLock)(() => {
|
|
694
|
+
result = (0, migrate_plugin_1.migratePlugin)({ run, configDir, log: () => { } });
|
|
695
|
+
}, { stamp: false });
|
|
696
|
+
if (outcome !== 'ran' || !result) {
|
|
697
|
+
console.log(` a move of ${from} to ${target} is already running; re-run setup in a minute if it is still listed.`);
|
|
674
698
|
return;
|
|
675
699
|
}
|
|
676
700
|
if (result.status === 'moved' && result.reason.startsWith('retired'))
|
|
677
|
-
console.log(` removed the old ${
|
|
701
|
+
console.log(` removed the old ${from} install; ${target} stays.`);
|
|
678
702
|
else if (result.status === 'moved')
|
|
679
|
-
console.log(` moved ${
|
|
703
|
+
console.log(` moved ${from} to its new ID ${target}; it loads at the next session.`);
|
|
680
704
|
else if (result.status === 'failed')
|
|
681
|
-
console.log(` couldn't move ${
|
|
705
|
+
console.log(` couldn't move ${from} to ${target}: ${result.reason}.`);
|
|
682
706
|
else if (!QUIET_SKIPS.includes(result.reason))
|
|
683
|
-
console.log(` kept ${
|
|
707
|
+
console.log(` kept ${from} (${result.reason}).`);
|
|
684
708
|
}
|
|
685
709
|
async function runSetup(argv = []) {
|
|
686
710
|
console.log('==> Setting up the memory hub');
|
|
@@ -771,10 +795,10 @@ async function runSetup(argv = []) {
|
|
|
771
795
|
console.log(` Couldn't install the plugin (${result.reason}), so the MCP server, hooks and skills are installed directly.`);
|
|
772
796
|
}
|
|
773
797
|
}
|
|
774
|
-
if (plugin &&
|
|
798
|
+
if (plugin && hasOldPlugin()) {
|
|
775
799
|
// Before the move: a settings token is what lets an install with a pasted token move.
|
|
776
800
|
writeUserEnv(settingsPath, env);
|
|
777
|
-
|
|
801
|
+
moveOldPlugin();
|
|
778
802
|
plugin = pluginInstalled();
|
|
779
803
|
if (!plugin)
|
|
780
804
|
console.log(' No memory-hub plugin is installed now, so the MCP server, hooks and skills are installed directly.');
|
|
@@ -782,10 +806,17 @@ async function runSetup(argv = []) {
|
|
|
782
806
|
if (plugin) {
|
|
783
807
|
writeUserEnv(settingsPath, env);
|
|
784
808
|
const pluginId = installedPluginId() ?? exports.PLUGIN_ID;
|
|
785
|
-
console.log(installedNow
|
|
786
|
-
?
|
|
787
|
-
:
|
|
788
|
-
|
|
809
|
+
console.log(!installedNow
|
|
810
|
+
? ` The ${pluginId} plugin is already installed. Your token is saved for it.`
|
|
811
|
+
: pluginId === exports.SKEDULO_PLUGIN_ID
|
|
812
|
+
? ' Installed. Your token is saved for it.'
|
|
813
|
+
: ' Installed. It updates itself at each new session, and your token is saved for it.');
|
|
814
|
+
if (pluginId === exports.SKEDULO_PLUGIN_ID) {
|
|
815
|
+
console.log(` To get Memory Hub updates automatically, turn on auto-update for ${exports.SKEDULO_MARKETPLACE_NAME} in /plugin → Marketplaces (it covers every Skedulo plugin).`);
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
enableMarketplaceAutoUpdate(settingsPath, pluginId === exports.LEGACY_PLUGIN_ID ? exports.LEGACY_MARKETPLACE_NAME : exports.MARKETPLACE_NAME);
|
|
819
|
+
}
|
|
789
820
|
const hooks = unregisterHooks(settingsPath);
|
|
790
821
|
const server = removeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'));
|
|
791
822
|
const copies = removeCopiedAssets(settingsPath);
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveToSkedulo = exports.semverAtLeast = exports.loadsCleanly = exports.pickOldId = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const setup_1 = require("./setup");
|
|
7
|
+
const move_lock_1 = require("./move-lock");
|
|
8
|
+
const plugin_move_util_1 = require("./plugin-move-util");
|
|
9
|
+
const hasUserRecord = (installed, id) => Array.isArray(installed[id]) && installed[id].some((record) => record?.scope === 'user');
|
|
10
|
+
const isActive = (installed, settings, id) => hasUserRecord(installed, id) && settings.enabledPlugins?.[id] === true;
|
|
11
|
+
function pickOldId(installed, settings) {
|
|
12
|
+
const hub = (0, plugin_move_util_1.has)(installed, setup_1.PLUGIN_ID);
|
|
13
|
+
const legacy = (0, plugin_move_util_1.has)(installed, setup_1.LEGACY_PLUGIN_ID);
|
|
14
|
+
if (hub && legacy) {
|
|
15
|
+
const hubActive = isActive(installed, settings, setup_1.PLUGIN_ID);
|
|
16
|
+
return hubActive ? { old: setup_1.PLUGIN_ID, retireLegacyFirst: true } : { old: setup_1.LEGACY_PLUGIN_ID, retireLegacyFirst: false };
|
|
17
|
+
}
|
|
18
|
+
if (hub)
|
|
19
|
+
return { old: setup_1.PLUGIN_ID, retireLegacyFirst: false };
|
|
20
|
+
if (legacy)
|
|
21
|
+
return { old: setup_1.LEGACY_PLUGIN_ID, retireLegacyFirst: false };
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
exports.pickOldId = pickOldId;
|
|
25
|
+
function listedEntry(listJson, id) {
|
|
26
|
+
let parsed;
|
|
27
|
+
try {
|
|
28
|
+
parsed = JSON.parse(listJson);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const entries = Array.isArray(parsed) ? parsed : parsed?.plugins;
|
|
34
|
+
return Array.isArray(entries) ? entries.find((candidate) => candidate?.id === id) : undefined;
|
|
35
|
+
}
|
|
36
|
+
function loadsCleanly(listJson, id) {
|
|
37
|
+
const entry = listedEntry(listJson, id);
|
|
38
|
+
const bad = (value) => (Array.isArray(value) ? value.length > 0 : !!value);
|
|
39
|
+
return !!entry && entry.enabled === true && !bad(entry.errors) && !bad(entry.error) && !bad(entry.loadError);
|
|
40
|
+
}
|
|
41
|
+
exports.loadsCleanly = loadsCleanly;
|
|
42
|
+
function semverAtLeast(a, b) {
|
|
43
|
+
const parse = (value) => (/^\d+\.\d+\.\d+$/.test(value) ? value.split('.').map(Number) : undefined);
|
|
44
|
+
const left = parse(a);
|
|
45
|
+
const right = parse(b);
|
|
46
|
+
if (!left || !right)
|
|
47
|
+
return undefined;
|
|
48
|
+
for (let i = 0; i < 3; i++)
|
|
49
|
+
if (left[i] !== right[i])
|
|
50
|
+
return left[i] > right[i];
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
exports.semverAtLeast = semverAtLeast;
|
|
54
|
+
function moveToSkedulo(deps) {
|
|
55
|
+
const { run, configDir } = deps;
|
|
56
|
+
const finish = (status, reason) => {
|
|
57
|
+
deps.log((0, plugin_move_util_1.logLine)(status, reason));
|
|
58
|
+
return { status, reason };
|
|
59
|
+
};
|
|
60
|
+
const settings = (0, plugin_move_util_1.readStrict)((0, path_1.join)(configDir, 'settings.json'));
|
|
61
|
+
if (!settings)
|
|
62
|
+
return finish('skipped', 'settings unreadable');
|
|
63
|
+
const installed = (0, setup_1.readJson)((0, path_1.join)(configDir, 'plugins', 'installed_plugins.json')).plugins || {};
|
|
64
|
+
const picked = pickOldId(installed, settings);
|
|
65
|
+
if (!picked)
|
|
66
|
+
return finish('skipped', 'not installed');
|
|
67
|
+
const old = picked.old;
|
|
68
|
+
const records = Array.isArray(installed[old]) ? installed[old] : [];
|
|
69
|
+
if (records.length === 0 || !records.every((record) => record?.scope === 'user'))
|
|
70
|
+
return finish('skipped', 'not user scope');
|
|
71
|
+
const newInstalled = (0, plugin_move_util_1.has)(installed, setup_1.SKEDULO_PLUGIN_ID);
|
|
72
|
+
if (newInstalled) {
|
|
73
|
+
if (!isActive(installed, settings, setup_1.SKEDULO_PLUGIN_ID))
|
|
74
|
+
return finish('skipped', 'new install not active');
|
|
75
|
+
}
|
|
76
|
+
else if (settings.enabledPlugins?.[old] !== true)
|
|
77
|
+
return finish('skipped', 'disabled');
|
|
78
|
+
const marketplace = old === setup_1.LEGACY_PLUGIN_ID ? setup_1.LEGACY_MARKETPLACE_NAME : setup_1.MARKETPLACE_NAME;
|
|
79
|
+
const known = (0, setup_1.readJson)((0, path_1.join)(configDir, 'plugins', 'known_marketplaces.json'));
|
|
80
|
+
const source = (0, plugin_move_util_1.has)(known, marketplace) ? known[marketplace]?.source : settings.extraKnownMarketplaces?.[marketplace]?.source;
|
|
81
|
+
if (!(0, setup_1.isHubSource)(source))
|
|
82
|
+
return finish('skipped', 'not a hub source');
|
|
83
|
+
if (source.ref && source.ref !== 'main')
|
|
84
|
+
return finish('skipped', 'ref not main');
|
|
85
|
+
const configured = run(['plugin', 'configure', '--json', old]);
|
|
86
|
+
const options = configured.status === 0 ? (0, plugin_move_util_1.parseObject)(configured.output) : undefined;
|
|
87
|
+
if (!options || !Array.isArray(options.configured))
|
|
88
|
+
return finish('failed', 'could not read the plugin options, nothing changed');
|
|
89
|
+
const settingsToken = settings.env?.MEMORY_HUB_MCP_TOKEN;
|
|
90
|
+
const hasSettingsToken = typeof settingsToken === 'string' && settingsToken.trim() !== '';
|
|
91
|
+
if (options.configured.includes('token') && !hasSettingsToken)
|
|
92
|
+
return finish('skipped', 'pasted token');
|
|
93
|
+
const settingsPath = (0, path_1.join)(configDir, 'settings.json');
|
|
94
|
+
const installedPath = (0, path_1.join)(configDir, 'plugins', 'installed_plugins.json');
|
|
95
|
+
const knownPath = (0, path_1.join)(configDir, 'plugins', 'known_marketplaces.json');
|
|
96
|
+
const knownBefore = (0, plugin_move_util_1.readStrict)(knownPath);
|
|
97
|
+
if (!knownBefore)
|
|
98
|
+
return finish('skipped', 'marketplaces unreadable');
|
|
99
|
+
const skeduloCloned = (0, plugin_move_util_1.has)(knownBefore, setup_1.SKEDULO_MARKETPLACE_NAME);
|
|
100
|
+
const skeduloDeclared = (0, plugin_move_util_1.has)(settings.extraKnownMarketplaces, setup_1.SKEDULO_MARKETPLACE_NAME);
|
|
101
|
+
// Removing a marketplace drops every plugin and setting under it, so any trace of it counts as the user's.
|
|
102
|
+
const skeduloKnownBefore = skeduloCloned || skeduloDeclared || Object.keys(installed).some((id) => id.endsWith(`@${setup_1.SKEDULO_MARKETPLACE_NAME}`));
|
|
103
|
+
if (!newInstalled) {
|
|
104
|
+
const skeduloSource = skeduloCloned ? knownBefore[setup_1.SKEDULO_MARKETPLACE_NAME]?.source : settings.extraKnownMarketplaces?.[setup_1.SKEDULO_MARKETPLACE_NAME]?.source;
|
|
105
|
+
if ((skeduloCloned || skeduloDeclared) && !(0, setup_1.isSkeduloSource)(skeduloSource))
|
|
106
|
+
return finish('skipped', 'foreign skedulo marketplace');
|
|
107
|
+
if (skeduloCloned && run(['plugin', 'marketplace', 'update', setup_1.SKEDULO_MARKETPLACE_NAME]).status !== 0)
|
|
108
|
+
return finish('skipped', 'cannot reach the marketplace');
|
|
109
|
+
}
|
|
110
|
+
const marketplacesBefore = (0, plugin_move_util_1.pick)(settings.extraKnownMarketplaces, [setup_1.SKEDULO_MARKETPLACE_NAME]);
|
|
111
|
+
const enabledBefore = (0, plugin_move_util_1.pick)(settings.enabledPlugins, [setup_1.SKEDULO_PLUGIN_ID]);
|
|
112
|
+
const configsBefore = (0, plugin_move_util_1.pick)(settings.pluginConfigs, [setup_1.SKEDULO_PLUGIN_ID]);
|
|
113
|
+
const doesNotLoad = 'new install does not load';
|
|
114
|
+
const addAndInstall = () => {
|
|
115
|
+
if (!skeduloCloned) {
|
|
116
|
+
const added = run(['plugin', 'marketplace', 'add', setup_1.SKEDULO_MARKETPLACE_REPO]);
|
|
117
|
+
if (added.status !== 0)
|
|
118
|
+
return `add failed (${(0, setup_1.lastLine)(added.output)})`;
|
|
119
|
+
if (!(0, setup_1.isSkeduloSource)((0, setup_1.readJson)(knownPath)[setup_1.SKEDULO_MARKETPLACE_NAME]?.source))
|
|
120
|
+
return `add failed (the repo did not register as ${setup_1.SKEDULO_MARKETPLACE_NAME})`;
|
|
121
|
+
}
|
|
122
|
+
const install = run(['plugin', 'install', setup_1.SKEDULO_PLUGIN_ID, '--scope', 'user', ...(0, plugin_move_util_1.captureFlag)(options.inputs)]);
|
|
123
|
+
if (install.status !== 0)
|
|
124
|
+
return `install failed (${(0, setup_1.lastLine)(install.output)})`;
|
|
125
|
+
if (!(0, setup_1.installedPluginIds)(installedPath).includes(setup_1.SKEDULO_PLUGIN_ID))
|
|
126
|
+
return `install failed (claude did not list ${setup_1.SKEDULO_PLUGIN_ID})`;
|
|
127
|
+
return undefined;
|
|
128
|
+
};
|
|
129
|
+
const verify = () => {
|
|
130
|
+
const listed = run(['plugin', 'list', '--json']);
|
|
131
|
+
if (listed.status !== 0 || !loadsCleanly(listed.output, setup_1.SKEDULO_PLUGIN_ID)) {
|
|
132
|
+
if (newInstalled && listed.status === 0 && listedEntry(listed.output, setup_1.SKEDULO_PLUGIN_ID)?.enabled !== true)
|
|
133
|
+
return 'inactive';
|
|
134
|
+
return doesNotLoad;
|
|
135
|
+
}
|
|
136
|
+
// Until claude's list --json error field is confirmed, the text list is the second witness.
|
|
137
|
+
const text = run(['plugin', 'list']);
|
|
138
|
+
if (text.status !== 0 || text.output.split('\n').some((line) => line.includes(setup_1.SKEDULO_PLUGIN_ID) && line.includes('failed to load')))
|
|
139
|
+
return doesNotLoad;
|
|
140
|
+
const installedNow = (0, setup_1.readJson)(installedPath).plugins || {};
|
|
141
|
+
const settingsNow = (0, plugin_move_util_1.readStrict)(settingsPath);
|
|
142
|
+
if (!settingsNow || !isActive(installedNow, settingsNow, setup_1.SKEDULO_PLUGIN_ID))
|
|
143
|
+
return doesNotLoad;
|
|
144
|
+
const newer = semverAtLeast(userVersion(installedNow, setup_1.SKEDULO_PLUGIN_ID) ?? '', userVersion(installed, old) ?? '');
|
|
145
|
+
if (newer === undefined)
|
|
146
|
+
return 'version unknown';
|
|
147
|
+
if (!newer)
|
|
148
|
+
return 'new install is older';
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
const undo = () => {
|
|
152
|
+
const outcomes = [`${old} untouched`];
|
|
153
|
+
const attempt = (label, args) => {
|
|
154
|
+
try {
|
|
155
|
+
const result = run(args);
|
|
156
|
+
if (result.status === 0)
|
|
157
|
+
return true;
|
|
158
|
+
outcomes.push(`${label} failed (${(0, setup_1.lastLine)(result.output)})`);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
outcomes.push(`${label} failed (${(0, plugin_move_util_1.message)(error)})`);
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
165
|
+
const leftInstalled = !newInstalled && (0, plugin_move_util_1.has)((0, setup_1.readJson)(installedPath).plugins, setup_1.SKEDULO_PLUGIN_ID) && !attempt('uninstall', ['plugin', 'uninstall', setup_1.SKEDULO_PLUGIN_ID, '--scope', 'user']);
|
|
166
|
+
if (!skeduloKnownBefore && (0, plugin_move_util_1.has)((0, setup_1.readJson)(knownPath), setup_1.SKEDULO_MARKETPLACE_NAME)) {
|
|
167
|
+
attempt('marketplace remove', ['plugin', 'marketplace', 'remove', setup_1.SKEDULO_MARKETPLACE_NAME, '--scope', 'user']);
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const restored = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
171
|
+
(0, plugin_move_util_1.putBack)(current, 'extraKnownMarketplaces', [setup_1.SKEDULO_MARKETPLACE_NAME], marketplacesBefore);
|
|
172
|
+
(0, plugin_move_util_1.putBack)(current, 'enabledPlugins', [setup_1.SKEDULO_PLUGIN_ID], enabledBefore);
|
|
173
|
+
(0, plugin_move_util_1.putBack)(current, 'pluginConfigs', [setup_1.SKEDULO_PLUGIN_ID], configsBefore);
|
|
174
|
+
for (const field of ['extraKnownMarketplaces', 'enabledPlugins', 'pluginConfigs']) {
|
|
175
|
+
if (!(0, plugin_move_util_1.has)(settings, field) && Object.keys(current[field] ?? {}).length === 0)
|
|
176
|
+
delete current[field];
|
|
177
|
+
}
|
|
178
|
+
if (leftInstalled)
|
|
179
|
+
(current.enabledPlugins ||= {})[setup_1.SKEDULO_PLUGIN_ID] = false;
|
|
180
|
+
});
|
|
181
|
+
if (!restored)
|
|
182
|
+
outcomes.push('settings unreadable and left as they are');
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
outcomes.push(`settings not restored (${(0, plugin_move_util_1.message)(error)})`);
|
|
186
|
+
}
|
|
187
|
+
return outcomes.join('; ');
|
|
188
|
+
};
|
|
189
|
+
const carryCapture = () => {
|
|
190
|
+
const capture = (0, plugin_move_util_1.captureValue)(options.inputs);
|
|
191
|
+
if (capture === undefined || (0, plugin_move_util_1.has)(settings.pluginConfigs?.[setup_1.SKEDULO_PLUGIN_ID]?.options, 'capture'))
|
|
192
|
+
return undefined;
|
|
193
|
+
const written = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
194
|
+
const config = ((current.pluginConfigs ||= {})[setup_1.SKEDULO_PLUGIN_ID] ||= {});
|
|
195
|
+
(config.options ||= {}).capture = capture;
|
|
196
|
+
});
|
|
197
|
+
return written ? undefined : 'capture not carried over (settings unreadable)';
|
|
198
|
+
};
|
|
199
|
+
let failure;
|
|
200
|
+
try {
|
|
201
|
+
failure = (newInstalled ? undefined : addAndInstall()) ?? verify();
|
|
202
|
+
if (failure === 'inactive')
|
|
203
|
+
return finish('skipped', 'new install not active');
|
|
204
|
+
if (failure === undefined && newInstalled)
|
|
205
|
+
failure = carryCapture();
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
failure = `move failed (${(0, plugin_move_util_1.message)(error)})`;
|
|
209
|
+
}
|
|
210
|
+
if (failure !== undefined)
|
|
211
|
+
return finish('failed', `${failure}; ${undo()}`);
|
|
212
|
+
const notes = [];
|
|
213
|
+
const settingsBeforeRetire = (0, plugin_move_util_1.readStrict)(settingsPath);
|
|
214
|
+
const oldMarketplaces = picked.retireLegacyFirst ? [marketplace, setup_1.LEGACY_MARKETPLACE_NAME] : [marketplace];
|
|
215
|
+
const carryAutoUpdate = oldMarketplaces.some((name) => settingsBeforeRetire?.extraKnownMarketplaces?.[name]?.autoUpdate === true);
|
|
216
|
+
const oldWasEnabled = settingsBeforeRetire?.enabledPlugins?.[old] === true;
|
|
217
|
+
if (picked.retireLegacyFirst)
|
|
218
|
+
retireLegacy(deps, installed, legacySourceOnMain(known, settings), notes);
|
|
219
|
+
let disableFailure;
|
|
220
|
+
try {
|
|
221
|
+
if (oldWasEnabled) {
|
|
222
|
+
const disabled = run(['plugin', 'disable', old]);
|
|
223
|
+
if (disabled.status !== 0)
|
|
224
|
+
disableFailure = (0, setup_1.lastLine)(disabled.output);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
disableFailure = (0, plugin_move_util_1.message)(error);
|
|
229
|
+
}
|
|
230
|
+
if (disableFailure !== undefined)
|
|
231
|
+
return finish('failed', (0, plugin_move_util_1.withNotes)(`disable failed (${disableFailure})`, notes));
|
|
232
|
+
let removeFailure;
|
|
233
|
+
try {
|
|
234
|
+
const removed = run(['plugin', 'marketplace', 'remove', marketplace, '--scope', 'user']);
|
|
235
|
+
if (removed.status !== 0)
|
|
236
|
+
removeFailure = (0, setup_1.lastLine)(removed.output);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
removeFailure = (0, plugin_move_util_1.message)(error);
|
|
240
|
+
}
|
|
241
|
+
if (removeFailure !== undefined) {
|
|
242
|
+
notes.push(`old marketplace not removed: ${removeFailure}`);
|
|
243
|
+
turnOff(settingsPath, old, notes);
|
|
244
|
+
}
|
|
245
|
+
const reason = `${old} to ${setup_1.SKEDULO_PLUGIN_ID}, loads at the next session`;
|
|
246
|
+
// A remove that keeps failing would otherwise re-announce the move and re-force auto-update every day.
|
|
247
|
+
if (!oldWasEnabled && removeFailure !== undefined)
|
|
248
|
+
return finish('moved', (0, plugin_move_util_1.withNotes)(reason, notes));
|
|
249
|
+
let autoUpdate = false;
|
|
250
|
+
if (carryAutoUpdate) {
|
|
251
|
+
try {
|
|
252
|
+
autoUpdate = (0, plugin_move_util_1.updateSettings)(settingsPath, (current) => {
|
|
253
|
+
const marketplaces = (current.extraKnownMarketplaces ||= {});
|
|
254
|
+
marketplaces[setup_1.SKEDULO_MARKETPLACE_NAME] = { source: (0, setup_1.marketplaceSource)(setup_1.SKEDULO_MARKETPLACE_NAME), ...marketplaces[setup_1.SKEDULO_MARKETPLACE_NAME], autoUpdate: true };
|
|
255
|
+
});
|
|
256
|
+
if (!autoUpdate)
|
|
257
|
+
notes.push('auto-update not carried over, settings unreadable');
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
notes.push(`auto-update not carried over (${(0, plugin_move_util_1.message)(error)})`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const stateDir = (0, move_lock_1.moveStateDir)(deps.env);
|
|
265
|
+
(0, fs_1.mkdirSync)(stateDir, { recursive: true });
|
|
266
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(stateDir, 'moved-to-skedulo'), [(0, move_lock_1.today)(), ...(autoUpdate ? ['autoupdate'] : [])].join('\n') + '\n');
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
notes.push(`notice not written (${(0, plugin_move_util_1.message)(error)})`);
|
|
270
|
+
}
|
|
271
|
+
return finish('moved', (0, plugin_move_util_1.withNotes)(reason, notes));
|
|
272
|
+
}
|
|
273
|
+
exports.moveToSkedulo = moveToSkedulo;
|
|
274
|
+
function userVersion(installed, id) {
|
|
275
|
+
const records = Array.isArray(installed[id]) ? installed[id] : [];
|
|
276
|
+
const version = records.find((record) => record?.scope === 'user')?.version;
|
|
277
|
+
return typeof version === 'string' ? version : undefined;
|
|
278
|
+
}
|
|
279
|
+
function turnOff(settingsPath, id, notes) {
|
|
280
|
+
try {
|
|
281
|
+
if (!(0, plugin_move_util_1.updateSettings)(settingsPath, (current) => ((current.enabledPlugins ||= {})[id] = false)))
|
|
282
|
+
notes.push(`${id} still enabled, settings unreadable`);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
notes.push(`${id} still enabled (${(0, plugin_move_util_1.message)(error)})`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function legacySourceOnMain(known, settings) {
|
|
289
|
+
const source = (0, plugin_move_util_1.has)(known, setup_1.LEGACY_MARKETPLACE_NAME) ? known[setup_1.LEGACY_MARKETPLACE_NAME]?.source : settings.extraKnownMarketplaces?.[setup_1.LEGACY_MARKETPLACE_NAME]?.source;
|
|
290
|
+
return (0, setup_1.isHubSource)(source) && (!source.ref || source.ref === 'main');
|
|
291
|
+
}
|
|
292
|
+
function retireLegacy(deps, installed, onMain, notes) {
|
|
293
|
+
const settingsPath = (0, path_1.join)(deps.configDir, 'settings.json');
|
|
294
|
+
const records = Array.isArray(installed[setup_1.LEGACY_PLUGIN_ID]) ? installed[setup_1.LEGACY_PLUGIN_ID] : [];
|
|
295
|
+
if (records.length === 0 || !records.every((record) => record?.scope === 'user')) {
|
|
296
|
+
notes.push('legacy install kept (not user scope)');
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (!onMain) {
|
|
300
|
+
notes.push('legacy install kept (not a hub source on main)');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
let left;
|
|
304
|
+
try {
|
|
305
|
+
if ((0, plugin_move_util_1.readStrict)(settingsPath)?.enabledPlugins?.[setup_1.LEGACY_PLUGIN_ID] === true) {
|
|
306
|
+
const disabled = deps.run(['plugin', 'disable', setup_1.LEGACY_PLUGIN_ID]);
|
|
307
|
+
if (disabled.status !== 0)
|
|
308
|
+
left = `disable failed (${(0, setup_1.lastLine)(disabled.output)})`;
|
|
309
|
+
}
|
|
310
|
+
if (left === undefined) {
|
|
311
|
+
const removed = deps.run(['plugin', 'marketplace', 'remove', setup_1.LEGACY_MARKETPLACE_NAME, '--scope', 'user']);
|
|
312
|
+
if (removed.status !== 0)
|
|
313
|
+
left = (0, setup_1.lastLine)(removed.output);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
left = (0, plugin_move_util_1.message)(error);
|
|
318
|
+
}
|
|
319
|
+
if (left === undefined)
|
|
320
|
+
return;
|
|
321
|
+
notes.push(`legacy not retired: ${left}`);
|
|
322
|
+
turnOff(settingsPath, setup_1.LEGACY_PLUGIN_ID, notes);
|
|
323
|
+
}
|
package/package.json
CHANGED