@skedulo/memory-hub-mcp 0.2.17 → 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 +4 -3
- package/assets/session-start.sh +102 -10
- package/assets/session-stop.sh +47 -6
- package/assets/skills/ask/SKILL.md +163 -0
- package/assets/skills/{se-ai-memory-hub → memory-hub}/SKILL.md +5 -3
- package/assets/skills/project-knowledge/SKILL.md +18 -5
- package/assets/skills/project-knowledge/references/create-refresh.md +21 -2
- package/assets/skills/project-knowledge/references/targeted-update.md +30 -5
- package/assets/skills/project-knowledge/references/touch.md +4 -3
- package/assets/skills/sweep-knowledge/SKILL.md +170 -0
- package/assets/user-prompt-submit.sh +4 -2
- package/dist/annotate.js +55 -0
- package/dist/ask-prompt.js +41 -0
- package/dist/bulk.js +5 -3
- package/dist/capture.js +34 -4
- package/dist/check-sources.js +4 -2
- package/dist/cli.js +34 -2
- package/dist/git-remote.js +14 -9
- package/dist/guide-check.js +33 -1
- package/dist/index.js +53 -23
- package/dist/list-repos.js +10 -4
- package/dist/migrate-plugin.js +219 -0
- package/dist/recall.js +8 -7
- package/dist/repo-context.js +7 -1
- package/dist/save.js +90 -13
- package/dist/session-context.js +19 -15
- package/dist/setup.js +130 -23
- package/dist/similar-notice.js +52 -7
- package/dist/soft.js +16 -0
- package/dist/staleness.js +156 -0
- package/dist/sweep.js +191 -0
- package/dist/tags.js +2 -0
- package/dist/version.js +15 -0
- package/package.json +2 -2
- package/skill-guide.md +164 -43
package/dist/save.js
CHANGED
|
@@ -1,23 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.performSave = exports.validateRepoArg = void 0;
|
|
3
|
+
exports.performSave = exports.validateRepoArg = exports.TEAM_NEEDS_REPO = void 0;
|
|
4
4
|
const source_1 = require("./source");
|
|
5
|
+
const capture_1 = require("./capture");
|
|
6
|
+
const list_repos_1 = require("./list-repos");
|
|
5
7
|
const UID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
8
|
const OWNER_NAME_PATTERN = /^[^/\s]+\/[^/\s]+$/;
|
|
9
|
+
exports.TEAM_NEEDS_REPO = "Team needs the project's repo: pass repo as owner/name, or save Private and say why.";
|
|
10
|
+
const REPO_LIST_FAILED = 'Could not check your repos right now; save Private without the repo and say why, or try again.';
|
|
11
|
+
// resolveRepo joins the caller to the repo's team, so a name is matched against the caller's own list instead.
|
|
7
12
|
async function validateRepoArg(client, repo) {
|
|
8
13
|
if (UID_PATTERN.test(repo)) {
|
|
9
14
|
return repo;
|
|
10
15
|
}
|
|
11
16
|
if (OWNER_NAME_PATTERN.test(repo)) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
const wanted = repo.toLowerCase();
|
|
18
|
+
let found;
|
|
19
|
+
try {
|
|
20
|
+
found = await (0, list_repos_1.collectRepos)(client, undefined, true);
|
|
15
21
|
}
|
|
16
|
-
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error(REPO_LIST_FAILED);
|
|
24
|
+
}
|
|
25
|
+
const listed = found.repos.find((candidate) => candidate.name.toLowerCase() === wanted);
|
|
26
|
+
if (listed) {
|
|
27
|
+
return listed.uid;
|
|
28
|
+
}
|
|
29
|
+
if (!found.complete) {
|
|
30
|
+
throw new Error(REPO_LIST_FAILED);
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`No repo named ${repo} is registered in the hub, or you are not on its team. Check the name; if it is right, ask the person whether to join that team, or save Private without the repo and say why.`);
|
|
17
33
|
}
|
|
18
34
|
throw new Error(`repo must be a uid from memory_listRepos, got "${repo}"`);
|
|
19
35
|
}
|
|
20
36
|
exports.validateRepoArg = validateRepoArg;
|
|
37
|
+
function assertTeamHasRepo(visibility, repo) {
|
|
38
|
+
if (visibility === 'Team' && !repo) {
|
|
39
|
+
throw new Error(exports.TEAM_NEEDS_REPO);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const SUPERSEDED = 'Superseded';
|
|
43
|
+
function errorMessage(err) {
|
|
44
|
+
return err instanceof Error ? err.message : String(err);
|
|
45
|
+
}
|
|
46
|
+
async function readTags(client, type, uid) {
|
|
47
|
+
const current = type === 'Fact' ? await client.getFact({ uid }) : type === 'Skill' ? await client.getSkill({ uid }) : await client.getWikiPage({ uid });
|
|
48
|
+
return { tags: current.tags ?? [], lastModifiedDate: current.lastModifiedDate };
|
|
49
|
+
}
|
|
50
|
+
function writeTags(client, type, body) {
|
|
51
|
+
return type === 'Fact' ? client.updateFact(body) : type === 'Skill' ? client.updateSkill(body) : client.updateWikiPage(body);
|
|
52
|
+
}
|
|
53
|
+
async function markSuperseded(client, type, uid) {
|
|
54
|
+
try {
|
|
55
|
+
for (let attempt = 0;; attempt++) {
|
|
56
|
+
const { tags, lastModifiedDate } = await readTags(client, type, uid);
|
|
57
|
+
if (tags.includes(SUPERSEDED)) {
|
|
58
|
+
return { supersededMarked: true };
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
await writeTags(client, type, { uid, tags: [...tags, SUPERSEDED], expectedLastModified: lastModifiedDate });
|
|
62
|
+
return { supersededMarked: true };
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (attempt === 0 && errorMessage(err).startsWith('Conflict')) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const reason = errorMessage(err);
|
|
74
|
+
const why = reason.startsWith('Not found')
|
|
75
|
+
? `you cannot edit ${type} ${uid}, or it no longer exists`
|
|
76
|
+
: reason.startsWith('Conflict')
|
|
77
|
+
? `${type} ${uid} kept changing while it was being marked`
|
|
78
|
+
: reason;
|
|
79
|
+
return {
|
|
80
|
+
supersededMarked: false,
|
|
81
|
+
supersededNote: `The new memory is saved, but ${type} ${uid} was not marked Superseded: ${why}. Ask its owner to tag it Superseded, or cite it in the new memory.`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function withSupersedes(saved, client, type, supersedes) {
|
|
86
|
+
const result = await saved;
|
|
87
|
+
return supersedes ? { ...result, ...(await markSuperseded(client, type, supersedes)) } : result;
|
|
88
|
+
}
|
|
21
89
|
// Extracted from four near-identical memory_saveX tool handlers so the per-type
|
|
22
90
|
// dispatch logic — which fields are required, what gets embedded, which client
|
|
23
91
|
// method is called — is unit-testable. index.ts's module-scope side effects
|
|
@@ -26,7 +94,15 @@ exports.validateRepoArg = validateRepoArg;
|
|
|
26
94
|
async function performSave(deps, input) {
|
|
27
95
|
const { client, embed, currentRepoUid, resolveTaskUid } = deps;
|
|
28
96
|
(0, source_1.assertSource)(input.source);
|
|
29
|
-
const
|
|
97
|
+
const supersedes = (0, capture_1.isCaptureMode)() ? undefined : input.supersedes;
|
|
98
|
+
if (supersedes && input.type === 'Scenario') {
|
|
99
|
+
throw new Error('supersedes applies to a Fact, Skill or Wiki page; a Scenario has no tags to mark Superseded.');
|
|
100
|
+
}
|
|
101
|
+
const resolveRepo = async () => {
|
|
102
|
+
const repo = (input.repo === undefined ? undefined : await validateRepoArg(client, input.repo)) ?? (await currentRepoUid());
|
|
103
|
+
assertTeamHasRepo(input.visibility, repo);
|
|
104
|
+
return repo;
|
|
105
|
+
};
|
|
30
106
|
// Required-field checks run BEFORE any repo resolution/network call — the old
|
|
31
107
|
// per-type tools got this for free from Zod (`content: z.string()`, not
|
|
32
108
|
// `.optional()`), which the consolidated schema can't do since requiredness is
|
|
@@ -37,24 +113,24 @@ async function performSave(deps, input) {
|
|
|
37
113
|
if (!input.content) {
|
|
38
114
|
throw new Error("content is required when type is 'Fact'");
|
|
39
115
|
}
|
|
40
|
-
const repo =
|
|
116
|
+
const repo = await resolveRepo();
|
|
41
117
|
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
42
118
|
const embedding = await embed(input.content).catch(() => undefined);
|
|
43
|
-
return client.saveFact({ content: input.content, tags: input.tags, devTaskId, repo, embedding, visibility: input.visibility, source: input.source });
|
|
119
|
+
return withSupersedes(client.saveFact({ content: input.content, tags: input.tags, devTaskId, repo, embedding, visibility: input.visibility, source: input.source }), client, 'Fact', supersedes);
|
|
44
120
|
}
|
|
45
121
|
case 'Skill': {
|
|
46
122
|
if (!input.title || !input.content) {
|
|
47
123
|
throw new Error("title and content are required when type is 'Skill'");
|
|
48
124
|
}
|
|
49
|
-
const repo =
|
|
125
|
+
const repo = await resolveRepo();
|
|
50
126
|
const embedding = await embed(`${input.title}\n\n${input.content}`).catch(() => undefined);
|
|
51
|
-
return client.saveSkill({ title: input.title, content: input.content, tags: input.tags, repo, embedding, visibility: input.visibility, source: input.source });
|
|
127
|
+
return withSupersedes(client.saveSkill({ title: input.title, content: input.content, tags: input.tags, repo, embedding, visibility: input.visibility, source: input.source }), client, 'Skill', supersedes);
|
|
52
128
|
}
|
|
53
129
|
case 'Scenario': {
|
|
54
130
|
if (!input.summary) {
|
|
55
131
|
throw new Error("summary is required when type is 'Scenario'");
|
|
56
132
|
}
|
|
57
|
-
const repo =
|
|
133
|
+
const repo = await resolveRepo();
|
|
58
134
|
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
59
135
|
const embedding = await embed(input.summary).catch(() => undefined);
|
|
60
136
|
return client.saveScenario({ summary: input.summary, factIds: input.factIds, devTaskId, repo, embedding, visibility: input.visibility, source: input.source });
|
|
@@ -63,10 +139,10 @@ async function performSave(deps, input) {
|
|
|
63
139
|
if (!input.title || !input.content) {
|
|
64
140
|
throw new Error("title and content are required when type is 'Wiki'");
|
|
65
141
|
}
|
|
66
|
-
const repo =
|
|
142
|
+
const repo = await resolveRepo();
|
|
67
143
|
const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
|
|
68
144
|
const embedding = await embed(`${input.title}\n\n${input.content}`).catch(() => undefined);
|
|
69
|
-
|
|
145
|
+
const saved = client.saveWikiPage({
|
|
70
146
|
title: input.title,
|
|
71
147
|
content: input.content,
|
|
72
148
|
tags: input.tags,
|
|
@@ -77,6 +153,7 @@ async function performSave(deps, input) {
|
|
|
77
153
|
visibility: input.visibility,
|
|
78
154
|
source: input.source,
|
|
79
155
|
});
|
|
156
|
+
return withSupersedes(saved, client, 'Wiki', supersedes);
|
|
80
157
|
}
|
|
81
158
|
}
|
|
82
159
|
}
|
package/dist/session-context.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildSessionContext = void 0;
|
|
4
|
+
const annotate_1 = require("./annotate");
|
|
5
|
+
const soft_1 = require("./soft");
|
|
4
6
|
// Matches session-start.sh's --max-time 5 per call. Promise.race does not cancel the
|
|
5
7
|
// losing fetch, so a hung backend still holds its socket — but the tool answers instead
|
|
6
8
|
// of hanging the conversation, which is the property that matters here.
|
|
@@ -8,18 +10,11 @@ const CALL_TIMEOUT_MS = 5000;
|
|
|
8
10
|
// Every leg degrades to empty rather than rejecting: this is startup context, and a
|
|
9
11
|
// half-populated recall is worth more to the model than a failed tool call. Mirrors
|
|
10
12
|
// session-start.sh, which tolerates any individual endpoint failing behind its cap.
|
|
11
|
-
function soft(p, fallback) {
|
|
12
|
-
|
|
13
|
-
// already won would otherwise surface as an unhandled rejection and kill the process.
|
|
14
|
-
const handled = p.catch(() => fallback);
|
|
15
|
-
let timer;
|
|
16
|
-
const capped = new Promise((resolve) => {
|
|
17
|
-
timer = setTimeout(() => resolve(fallback), CALL_TIMEOUT_MS);
|
|
18
|
-
});
|
|
19
|
-
return Promise.race([handled, capped]).finally(() => clearTimeout(timer));
|
|
13
|
+
function soft(p, fallback, ms = CALL_TIMEOUT_MS) {
|
|
14
|
+
return (0, soft_1.soft)(p, fallback, ms);
|
|
20
15
|
}
|
|
21
16
|
async function buildSessionContext(deps) {
|
|
22
|
-
const { client, currentRepoUid } = deps;
|
|
17
|
+
const { client, currentRepoUid, staleness } = deps;
|
|
23
18
|
const [persona, factsSelf, factsTeam, skillsSelf, skillsTeam, repoUid] = await Promise.all([
|
|
24
19
|
// The one piece of context that does not depend on a repo, which makes it the most
|
|
25
20
|
// valuable leg for a host with no project directory. `configured: false` is the cue
|
|
@@ -57,11 +52,18 @@ async function buildSessionContext(deps) {
|
|
|
57
52
|
repoSkills = without(s.skills, selfSkills, teamSkills);
|
|
58
53
|
wiki = w.pages;
|
|
59
54
|
}
|
|
55
|
+
const toItems = (raws, check) => Promise.all(raws.map((raw) => item(raw, check)));
|
|
56
|
+
const groups = [selfFacts, teamFacts, repoFacts, selfSkills, teamSkills, repoSkills, wiki];
|
|
57
|
+
const plain = await Promise.all(groups.map((raws) => toItems(raws, undefined)));
|
|
58
|
+
const [factsS, factsT, factsR, skillsS, skillsT, skillsR, wikiItems] = staleness
|
|
59
|
+
? await soft(Promise.all(groups.map((raws) => toItems(raws, staleness))), plain, soft_1.STALENESS_TIMEOUT_MS)
|
|
60
|
+
: plain;
|
|
60
61
|
return {
|
|
62
|
+
serverVersion: deps.serverVersion,
|
|
61
63
|
persona,
|
|
62
|
-
facts: { self:
|
|
63
|
-
skills: { self:
|
|
64
|
-
wiki:
|
|
64
|
+
facts: { self: factsS, team: factsT, repo: factsR },
|
|
65
|
+
skills: { self: skillsS, team: skillsT, repo: skillsR },
|
|
66
|
+
wiki: wikiItems,
|
|
65
67
|
repoScoped: Boolean(repoUid),
|
|
66
68
|
};
|
|
67
69
|
}
|
|
@@ -70,8 +72,10 @@ function without(items, ...seen) {
|
|
|
70
72
|
const taken = new Set(seen.flat().map((x) => x.uid));
|
|
71
73
|
return items.filter((x) => !taken.has(x.uid));
|
|
72
74
|
}
|
|
73
|
-
function item(x) {
|
|
75
|
+
async function item(x, staleness) {
|
|
74
76
|
const content = x.title ? `${x.title}: ${x.content}` : x.content;
|
|
75
77
|
// Date only, no time: the model needs "is this stale", not an ordering key.
|
|
76
|
-
|
|
78
|
+
const base = x.lastModifiedDate ? { content, updated: x.lastModifiedDate.slice(0, 10) } : { content };
|
|
79
|
+
const { superseded, staleness: changed } = await (0, annotate_1.annotateItem)({ content: x.content, tags: x.tags, source: x.source }, staleness);
|
|
80
|
+
return { ...base, ...(superseded ? { superseded } : {}), ...(changed ? { staleness: changed } : {}) };
|
|
77
81
|
}
|
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/similar-notice.js
CHANGED
|
@@ -1,15 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.similarNotice = void 0;
|
|
3
|
+
exports.similarNotice = exports.batchClosingLine = exports.closingLine = exports.ownerLabel = exports.canEdit = void 0;
|
|
4
4
|
const PREVIEW = 160;
|
|
5
|
+
function canEdit(match) {
|
|
6
|
+
return match.editable ?? match.mine !== false;
|
|
7
|
+
}
|
|
8
|
+
exports.canEdit = canEdit;
|
|
9
|
+
function ownerLabel(match) {
|
|
10
|
+
if (match.mine === undefined) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
if (match.mine) {
|
|
14
|
+
return ', yours';
|
|
15
|
+
}
|
|
16
|
+
return canEdit(match) ? ", a teammate's, editable" : ", a teammate's";
|
|
17
|
+
}
|
|
18
|
+
exports.ownerLabel = ownerLabel;
|
|
19
|
+
const UPDATE_GUARD = "expectedLastModified=<its lastModifiedDate from memory_get>";
|
|
5
20
|
function describe(match) {
|
|
6
|
-
const owner = match.mine === undefined ? '' : match.mine ? ', yours' : ", a teammate's";
|
|
7
21
|
const when = match.lastModifiedDate ? `, updated ${match.lastModifiedDate.slice(0, 10)}` : '';
|
|
8
22
|
const label = match.title ? `${match.title}: ` : '';
|
|
9
23
|
const body = match.content.replace(/\s+/g, ' ').trim();
|
|
10
24
|
const preview = body.length > PREVIEW ? `${body.slice(0, PREVIEW)}…` : body;
|
|
11
|
-
return `- ${match.uid} (${match.similarity.toFixed(2)}${
|
|
25
|
+
return `- ${match.uid} (${match.similarity.toFixed(2)}${ownerLabel(match)}${when}) ${label}"${preview}"`;
|
|
26
|
+
}
|
|
27
|
+
function citeAdvice(matches) {
|
|
28
|
+
const uids = matches.map((match) => match.uid).join(', ');
|
|
29
|
+
return `you cannot edit ${uids}, so cite ${matches.length === 1 ? 'it' : 'them'} in the new memory instead of repeating ${matches.length === 1 ? 'it' : 'them'}`;
|
|
30
|
+
}
|
|
31
|
+
function closingLine(type, newUid, matches) {
|
|
32
|
+
const editable = matches.filter(canEdit);
|
|
33
|
+
const locked = matches.filter((match) => !canEdit(match));
|
|
34
|
+
const parts = [];
|
|
35
|
+
if (editable.length > 0) {
|
|
36
|
+
const target = editable.length === 1 ? editable[0].uid : '<that uid>';
|
|
37
|
+
const which = editable.length === 1 ? '' : ` (one of ${editable.map((match) => match.uid).join(', ')})`;
|
|
38
|
+
const supersedes = type === 'Scenario' ? '' : ', or pass supersedes next time';
|
|
39
|
+
parts.push(`To keep a single copy, update the existing one${which} with memory_update type=${type} uid=${target} ${UPDATE_GUARD} and the merged text, then memory_delete type=${type} uid=${newUid}${supersedes}.`);
|
|
40
|
+
}
|
|
41
|
+
if (locked.length > 0) {
|
|
42
|
+
parts.push(`${editable.length > 0 ? 'For the others' : 'Otherwise'}, ${citeAdvice(locked)}; keep the new one only if it adds something they don't say.`);
|
|
43
|
+
}
|
|
44
|
+
return parts.join(' ');
|
|
45
|
+
}
|
|
46
|
+
exports.closingLine = closingLine;
|
|
47
|
+
function batchClosingLine(matches) {
|
|
48
|
+
const editable = matches.filter(canEdit);
|
|
49
|
+
const locked = matches.filter((match) => !canEdit(match));
|
|
50
|
+
const parts = [];
|
|
51
|
+
if (editable.length > 0) {
|
|
52
|
+
parts.push(`Where one you can edit already covers it (${editable.map((match) => match.uid).join(', ')}), memory_update that uid with the merged text and ${UPDATE_GUARD}, then memory_delete the new copy.`);
|
|
53
|
+
}
|
|
54
|
+
if (locked.length > 0) {
|
|
55
|
+
const advice = citeAdvice(locked);
|
|
56
|
+
parts.push(editable.length > 0 ? `For the others, ${advice}.` : `${advice.charAt(0).toUpperCase()}${advice.slice(1)}.`);
|
|
57
|
+
}
|
|
58
|
+
return parts.join(' ');
|
|
12
59
|
}
|
|
60
|
+
exports.batchClosingLine = batchClosingLine;
|
|
13
61
|
// The save has already happened when this runs; the point is to let the agent keep one copy instead of two.
|
|
14
62
|
function similarNotice(type, result) {
|
|
15
63
|
const matches = result.similar?.length ? result.similar : result.possibleDuplicate ? [result.possibleDuplicate] : [];
|
|
@@ -20,10 +68,7 @@ function similarNotice(type, result) {
|
|
|
20
68
|
`Saved as ${result.uid}, but it looks like ${matches.length === 1 ? 'a memory' : 'memories'} already saved:`,
|
|
21
69
|
...matches.map(describe),
|
|
22
70
|
];
|
|
23
|
-
|
|
24
|
-
lines.push(editable
|
|
25
|
-
? `If one of yours already covers this, keep a single copy: memory_update type=${type} uid=<that uid> with the merged text, then memory_delete type=${type} uid=${result.uid}.`
|
|
26
|
-
: "Those belong to teammates and cannot be edited, so keep the new one only if it adds something they don't say.");
|
|
71
|
+
lines.push(closingLine(type, result.uid, matches));
|
|
27
72
|
return lines.join('\n');
|
|
28
73
|
}
|
|
29
74
|
exports.similarNotice = similarNotice;
|
package/dist/soft.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.soft = exports.STALENESS_TIMEOUT_MS = void 0;
|
|
4
|
+
// Annotation is a bonus on top of a result already in hand, so it gets less time than a fetch.
|
|
5
|
+
exports.STALENESS_TIMEOUT_MS = 2000;
|
|
6
|
+
function soft(p, fallback, ms) {
|
|
7
|
+
// Attached before the race, not after: a rejection arriving once the timeout has
|
|
8
|
+
// already won would otherwise surface as an unhandled rejection and kill the process.
|
|
9
|
+
const handled = p.catch(() => fallback);
|
|
10
|
+
let timer;
|
|
11
|
+
const capped = new Promise((resolve) => {
|
|
12
|
+
timer = setTimeout(() => resolve(fallback), ms);
|
|
13
|
+
});
|
|
14
|
+
return Promise.race([handled, capped]).finally(() => clearTimeout(timer));
|
|
15
|
+
}
|
|
16
|
+
exports.soft = soft;
|