@skedulo/memory-hub-mcp 0.2.39 → 0.2.41

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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skedulo/memory-hub-mcp",
3
- "version": "0.2.39",
3
+ "version": "0.2.41",
4
4
  "description": "MCP server for the Memory Hub: recall and save developer memory from Claude Code and Claude Desktop.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/skill-guide.md CHANGED
@@ -911,7 +911,9 @@ on one bad item.
911
911
  means no repo), `visibility`, `titlePrefix`, `tags` (not for Scenario),
912
912
  `mine`, `createdAfter` (ISO date), `sourceRepo` (`owner/name`, exact) and
913
913
  `verifiedBefore` (ISO date; items last verified earlier). Each item carries its
914
- `source` when it has one. It is not a search; use `memory_recall`
914
+ `source` when it has one. `fields` returns only the named fields of each item
915
+ (`["title"]`, `["uid","title"]`), which keeps a long list small; get an item
916
+ before relying on it. It is not a search; use `memory_recall`
915
917
  for that. It changes nothing.
916
918
  - **`memory_saveBatch`** — `items` (1-25), each exactly a `memory_save` input.
917
919
  Results come back by `index`; duplicates appear as a short `similarTo` list.