@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sweep-knowledge
|
|
3
|
+
description: Use for the weekly knowledge sweep, run by hand or as a scheduled routine, e.g. "sweep the hub knowledge", "dry-run the knowledge sweep", "apply the weekly sweep for Skedulo/acme-delivery". It checks every hub memory sourced from your teams' repos against the latest code, stamps the ones still current, updates a capped number of changed ones, refreshes each project's non-code sources, and reports one digest. It never asks questions.
|
|
4
|
+
argument-hint: "[dry-run|apply] [repo owner/name ...]"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Weekly knowledge sweep
|
|
8
|
+
|
|
9
|
+
Keeping knowledge current is one of the hub's core principles: it corrects itself without anyone
|
|
10
|
+
rereading whole projects. This sweep is the weekly backstop. A deterministic `sweep` command sorts
|
|
11
|
+
each repo's memories by whether the files they cite changed; you spend tokens only on the changed
|
|
12
|
+
ones, within fixed caps.
|
|
13
|
+
|
|
14
|
+
- **Mode.** `dry-run` (the default when no mode is given) writes nothing: it reports what `apply`
|
|
15
|
+
would do. `apply` stamps, updates and refreshes. Start with dry runs; switch to `apply` once the
|
|
16
|
+
digests look right.
|
|
17
|
+
- **Repos.** The `owner/name` arguments, or else every repo found in step 2.
|
|
18
|
+
- **Unattended.** Never ask a question. Anything that would need an answer is skipped and listed in
|
|
19
|
+
the digest as waiting, with why. A problem that stops the whole run still ends with the digest.
|
|
20
|
+
- **Never draft new knowledge.** The sweep saves no new memories, SkillDrift Facts included; it only
|
|
21
|
+
stamps, updates, flags and reports.
|
|
22
|
+
- **Never show Private content.** In the digest, a Private item is named by its uid only: no title,
|
|
23
|
+
no content, no detail of what changed.
|
|
24
|
+
|
|
25
|
+
## First, check the server version
|
|
26
|
+
|
|
27
|
+
Look at the parameters of the `memory_update`, `memory_save` and `memory_list` tools; if only their
|
|
28
|
+
names are listed, load their schemas first. If any of them is missing, the memory-hub server is not
|
|
29
|
+
connected: say so in the digest and stop. If `memory_update` has no `expectedLastModified`
|
|
30
|
+
parameter, or `memory_save`'s `tags` values do not include `ProjectRules`, `Superseded` and
|
|
31
|
+
`SkillDrift`, or `memory_list` has no `sourceRepo` parameter, the memory-hub server is older than
|
|
32
|
+
this release. Stop, do nothing else, and say in the digest that it must be updated:
|
|
33
|
+
|
|
34
|
+
- plugin installs, and `setup` installs with auto-update: restart Claude Code;
|
|
35
|
+
- pinned installs: re-run `npx -y @skedulo/memory-hub-mcp@latest setup --no-auto-update`;
|
|
36
|
+
- a checkout of the se-ai-memory-hub repo: pull and re-run `scripts/setup-dev.sh`.
|
|
37
|
+
|
|
38
|
+
The `sweep` command needs `MEMORY_HUB_MCP_TOKEN` in the environment. If it is missing, stop and say
|
|
39
|
+
in the digest how to provide it, as step 3 of the project-knowledge skill's `references/import.md`
|
|
40
|
+
explains (`memory-hub:project-knowledge` when installed as a plugin).
|
|
41
|
+
|
|
42
|
+
## 1. Settle the mode and the date
|
|
43
|
+
|
|
44
|
+
Take the mode from the arguments (`dry-run` when none is given) and today's date, used as the reason
|
|
45
|
+
"weekly sweep <date>" in every change-log line this run writes.
|
|
46
|
+
|
|
47
|
+
## 2. Find the repos
|
|
48
|
+
|
|
49
|
+
1. `memory_listRepos` lists the repos on your teams, with each one's `uid`, `name` and `teamName`.
|
|
50
|
+
2. For each repo (or each repo named in the arguments), list the items sourced from it:
|
|
51
|
+
`memory_list type=<T> sourceRepo=<owner/name> limit=200` for each of `Fact`, `Skill`, `Scenario`
|
|
52
|
+
and `Wiki`. `memory_list` returns `total` and one page of items; call it again with `offset`
|
|
53
|
+
until you have all of them. Keep each item's uid, title, visibility, `repo` uid and tags: the
|
|
54
|
+
`sweep` output has no visibility, and the digest needs it.
|
|
55
|
+
3. A repo with items is swept. A repo on your teams with none is a new repo: report it only, never
|
|
56
|
+
draft knowledge for it.
|
|
57
|
+
4. Skip, and list as not swept, any repo whose name does not match
|
|
58
|
+
`^[A-Za-z0-9_-][A-Za-z0-9_.-]*/[A-Za-z0-9_-][A-Za-z0-9_.-]*$`: it goes into shell commands below.
|
|
59
|
+
|
|
60
|
+
## 3. Sweep each repo
|
|
61
|
+
|
|
62
|
+
For each swept repo, in turn:
|
|
63
|
+
|
|
64
|
+
1. Clone it fresh, without blobs, so only the files a diff needs are fetched:
|
|
65
|
+
`rm -rf "${TMPDIR:-/tmp}/memory-hub-sweep/<owner>/<name>"`, then
|
|
66
|
+
`gh repo clone <owner/name> "${TMPDIR:-/tmp}/memory-hub-sweep/<owner>/<name>" -- --filter=blob:none`
|
|
67
|
+
(or `git clone --filter=blob:none` with the repo URL when `gh` is not available). If the clone
|
|
68
|
+
fails, list the repo in the digest as not swept, with the error, and go to the next repo.
|
|
69
|
+
2. Run `npx -y @skedulo/memory-hub-mcp@latest sweep --repo <owner/name> --checkout <clone>`, adding
|
|
70
|
+
`--stamp` in `apply` mode only. If it fails, list the repo as not swept, with the error, and go
|
|
71
|
+
to the next repo. It prints JSON:
|
|
72
|
+
- `target`: the commit everything was compared with (the clone's `origin/HEAD`);
|
|
73
|
+
- `unchanged`: items whose cited files did not change; with `--stamp`, `stamped` lists those whose
|
|
74
|
+
source commit moved forward to `target`, and `notEditable` those you may not edit;
|
|
75
|
+
- `changed`: items with `uid`, `type`, `title`, `changed` (the cited paths that changed),
|
|
76
|
+
`diffLines`, `editable` and `editedByOtherWithin7Days`;
|
|
77
|
+
- `nothingCited`, `unknownCommit`, `otherRepo`: items it could not check; `errors`: items it
|
|
78
|
+
failed on.
|
|
79
|
+
3. Keep the counts for the digest. Collect `changed` across all repos, in the order the sweep lists
|
|
80
|
+
them, for step 4.
|
|
81
|
+
|
|
82
|
+
## 4. Handle the changed items
|
|
83
|
+
|
|
84
|
+
At most 30 model updates per run, across all repos, steps 4 and 5 together. One update is one
|
|
85
|
+
`memory_update` on a changed item (moving only its `source` counts too), one project page a targeted
|
|
86
|
+
update reports as changed, or one sources-only refresh. This cap replaces the skill guide's "at most
|
|
87
|
+
three fixes per task" for the sweep. Items and projects left when the cap is reached are listed as
|
|
88
|
+
not reached; the next sweep picks them up.
|
|
89
|
+
|
|
90
|
+
Take the items in order. Before reading anything, skip and list:
|
|
91
|
+
|
|
92
|
+
- `diffLines` over 300: flag it as too big to check here. For a project page, suggest "catch up the
|
|
93
|
+
<Project> knowledge with the code".
|
|
94
|
+
- `diffLines` of -1: the diff failed; flag it as not checked.
|
|
95
|
+
- `editedByOtherWithin7Days`: someone else is working on it; report it, never rewrite it.
|
|
96
|
+
- `editable: false`: flag it (the "Stale memories" rule on edits you cannot make).
|
|
97
|
+
- tagged `Superseded`: a newer memory replaced it; report it, do not update it.
|
|
98
|
+
|
|
99
|
+
In `dry-run` mode, read nothing more. Count as `apply` would, with each project handed over counted
|
|
100
|
+
as its number of changed pages (the most it can report as changed), and list what `apply` would
|
|
101
|
+
take before the cap is reached: the items, the projects handed over and the projects flagged.
|
|
102
|
+
|
|
103
|
+
In `apply` mode:
|
|
104
|
+
|
|
105
|
+
1. **Project pages** (Wiki pages titled `<Project> › …`). Never `memory_update` them directly. Group
|
|
106
|
+
them by project and delivery repo (the page's `repo` uid), taking projects in the order of their
|
|
107
|
+
first changed page. A targeted update with a commit range touches every page and file in that
|
|
108
|
+
range, so it would also reach pages skipped above. Hand a project over only when none of its
|
|
109
|
+
pages was skipped for a diff over 300 lines or a failed diff, a recent edit by someone else or not being
|
|
110
|
+
editable; otherwise flag the project with "catch up the <Project> knowledge with the code" and
|
|
111
|
+
leave all its pages. Stop handing projects over once the cap is reached.
|
|
112
|
+
|
|
113
|
+
For a project handed over, read each grouped page with `memory_get` for its `source.commit`, take
|
|
114
|
+
the oldest one that is an ancestor of `target` (`git -C <clone> merge-base --is-ancestor
|
|
115
|
+
<commit> <target>`), and run the project-knowledge skill's targeted update
|
|
116
|
+
(`memory-hub:project-knowledge` when installed as a plugin) as the weekly sweep, with the
|
|
117
|
+
delivery repo uid, the project, the commit range `<oldest>..<target>` on `<owner/name>` and no
|
|
118
|
+
change list, and the reason "weekly sweep <date>". Tell it not to ask: it applies only changes
|
|
119
|
+
that do not touch a `core` entry and lists the core changes as waiting. Count each page it
|
|
120
|
+
reports as changed against the cap.
|
|
121
|
+
2. **Other items.** Follow the guide's "Stale memories" section
|
|
122
|
+
(`memory_getSkillGuide section="Stale memories"`, loaded once per run), running its git commands
|
|
123
|
+
as `git -C <clone>` with `target` as the target commit:
|
|
124
|
+
1. `memory_get` the item for its text, `source` and `lastModifiedDate`.
|
|
125
|
+
2. Verify: read each path in `changed` at `target`, and its change with
|
|
126
|
+
`git -C <clone> diff <source.commit> <target> -- <paths>`.
|
|
127
|
+
3. Apply the section's "still true", "clearly wrong" or "unclear" step, with
|
|
128
|
+
`source: {repo: "<owner/name>", commit: "<target>"}` and `expectedLastModified` on every
|
|
129
|
+
`memory_update`, keeping the item's visibility.
|
|
130
|
+
|
|
131
|
+
Record each update with its reason in one line (for example "R12 still true: moved source", "fixed:
|
|
132
|
+
the retry limit is now 5, `code: <owner/name>@<sha> <path>`").
|
|
133
|
+
|
|
134
|
+
## 5. Refresh each project's other sources
|
|
135
|
+
|
|
136
|
+
In `apply` mode, for each project that has `<Project> › Sources` on a swept repo
|
|
137
|
+
(`memory_list type=Wiki repo=<repo uid> titlePrefix="<Project> › Sources"`), run the
|
|
138
|
+
project-knowledge skill as "the weekly sweep runs this skill", so it picks the sources-only refresh:
|
|
139
|
+
it reads the non-code sources, never repos, applies only non-core changes, and lists the core ones
|
|
140
|
+
as waiting. Each refresh counts as one update against the cap; once the cap is reached, list the
|
|
141
|
+
remaining projects as not reached. In `dry-run` mode, list the projects it would refresh, counted
|
|
142
|
+
the same way.
|
|
143
|
+
|
|
144
|
+
## 6. Group the skill drift
|
|
145
|
+
|
|
146
|
+
`memory_list type=Fact tags=["SkillDrift"]`, paginated with `offset`, lists the SkillDrift Facts you
|
|
147
|
+
can read across authors; the guide's "Skill drift" section (`memory_getSkillGuide section="Skill drift"`)
|
|
148
|
+
says what each one holds. Read each one cut short with `memory_get`. Group them by the skill they name
|
|
149
|
+
(`plugin:<name>@<version>`), and under each skill list the contradicted instructions with their
|
|
150
|
+
evidence and the number of Facts reporting each. Leave out Private Facts. Change nothing.
|
|
151
|
+
|
|
152
|
+
## 7. Report the digest
|
|
153
|
+
|
|
154
|
+
One digest for the whole run, headed with the mode and the date:
|
|
155
|
+
|
|
156
|
+
1. Per repo: `target`, and the counts of unchanged, stamped, changed, updated, flagged, skipped,
|
|
157
|
+
not reached, nothing cited, unknown commit, other repo and errors. Repos not swept, with why.
|
|
158
|
+
2. Each update with its reason, by title (uid only when Private).
|
|
159
|
+
3. Flagged and skipped items with why: too big, diff failed, edited by someone else in the last 7 days, not
|
|
160
|
+
editable, superseded, unclear after verifying, not reached.
|
|
161
|
+
4. Per project: what the targeted updates and sources-only refreshes changed, by page title and
|
|
162
|
+
entry ID, the core changes waiting ("run project-knowledge on <Project> to decide them"), and
|
|
163
|
+
anything "Worth a look", such as new modules.
|
|
164
|
+
5. New repos found (report only).
|
|
165
|
+
6. Skill drift, grouped by skill.
|
|
166
|
+
7. In `dry-run` mode: what `apply` would do, and that nothing was written.
|
|
167
|
+
|
|
168
|
+
## 8. Clean up
|
|
169
|
+
|
|
170
|
+
Remove the clones, even after a failure: `rm -rf "${TMPDIR:-/tmp}/memory-hub-sweep"`.
|
|
@@ -88,8 +88,10 @@ cut_pointer() {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
EXTRAS_DEF='def extras($under; $text):
|
|
91
|
-
(if (.
|
|
92
|
-
+ ((
|
|
91
|
+
(if (.source | type) == "object" and (.source.verifiedAt | type) == "string" and .source.verifiedAt != "" then " · verified " + .source.verifiedAt[0:10] else "" end)
|
|
92
|
+
+ (if (.externalRef | type) == "string" and .externalRef != "" and .externalRef != $under then " · " + (.externalRef | gsub("[[:cntrl:]]"; " ")) else "" end)
|
|
93
|
+
+ ((first(($text // "") | gsub("[A-Za-z][A-Za-z0-9+.-]*://[^\\s)]*"; " ") | scan("[A-Za-z0-9_./-]+\\.(?:tsx|ts|jsx|js|mjs|sh|py|json|md|yml|yaml|cls|java|kt|swift|go|rb)\\b") | select(startswith("http") | not)) // null) | if . then " · cites " + . else "" end)
|
|
94
|
+
+ (if ((.tags // []) | index("Superseded")) then " · superseded, prefer the newer memory" else "" end);'
|
|
93
95
|
|
|
94
96
|
TICKET_DENYLIST=" UTF ISO SHA RFC HTTP HTTPS TLS SSL MD AES RSA X Y Z UTC GMT CVE COVID PR "
|
|
95
97
|
REFS_FILE="$STATE_DIR/$SESSION_ID.refs"
|
package/dist/annotate.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.annotateListCapped = exports.annotateItemCapped = exports.annotateList = exports.annotateItem = exports.stalenessFor = void 0;
|
|
4
|
+
const staleness_1 = require("./staleness");
|
|
5
|
+
const soft_1 = require("./soft");
|
|
6
|
+
// A new checker per call: it memoizes git results, and a long-lived server must see new fetches.
|
|
7
|
+
function stalenessFor(exec, detectRepo) {
|
|
8
|
+
const repo = detectRepo()?.trim();
|
|
9
|
+
if (!repo)
|
|
10
|
+
return undefined;
|
|
11
|
+
return { check: (0, staleness_1.createStalenessChecker)({ exec, repo }).check, repo };
|
|
12
|
+
}
|
|
13
|
+
exports.stalenessFor = stalenessFor;
|
|
14
|
+
async function changedFor(item, deps) {
|
|
15
|
+
const here = deps?.repo?.trim().toLowerCase();
|
|
16
|
+
const there = item.source?.repo?.trim().toLowerCase();
|
|
17
|
+
if (!deps || !here || here !== there)
|
|
18
|
+
return undefined;
|
|
19
|
+
const text = typeof item.content === 'string' ? item.content : typeof item.summary === 'string' ? item.summary : '';
|
|
20
|
+
const result = await deps.check({ source: item.source, text }).catch(() => undefined);
|
|
21
|
+
return result?.status === 'changed' ? result : undefined;
|
|
22
|
+
}
|
|
23
|
+
async function annotateItem(item, deps, options = {}) {
|
|
24
|
+
const changed = await changedFor(item, deps);
|
|
25
|
+
const staleness = changed && (options.entries ? changed : omitEntries(changed));
|
|
26
|
+
if (!staleness && !item.tags?.includes('Superseded'))
|
|
27
|
+
return item;
|
|
28
|
+
return {
|
|
29
|
+
...item,
|
|
30
|
+
...(item.tags?.includes('Superseded') ? { superseded: true } : {}),
|
|
31
|
+
...(staleness ? { staleness } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.annotateItem = annotateItem;
|
|
35
|
+
function omitEntries({ entries: _entries, ...rest }) {
|
|
36
|
+
return rest;
|
|
37
|
+
}
|
|
38
|
+
async function annotateList(result, listKey, deps) {
|
|
39
|
+
const items = result?.[listKey];
|
|
40
|
+
if (!Array.isArray(items))
|
|
41
|
+
return result;
|
|
42
|
+
const annotated = await Promise.all(items.map((item) => annotateItem(item, deps)));
|
|
43
|
+
return { ...result, [listKey]: annotated };
|
|
44
|
+
}
|
|
45
|
+
exports.annotateList = annotateList;
|
|
46
|
+
async function annotateItemCapped(item, deps, options = {}, ms = soft_1.STALENESS_TIMEOUT_MS) {
|
|
47
|
+
const plain = await annotateItem(item, undefined);
|
|
48
|
+
return deps ? (0, soft_1.soft)(annotateItem(item, deps, options), plain, ms) : plain;
|
|
49
|
+
}
|
|
50
|
+
exports.annotateItemCapped = annotateItemCapped;
|
|
51
|
+
async function annotateListCapped(result, listKey, deps, ms = soft_1.STALENESS_TIMEOUT_MS) {
|
|
52
|
+
const plain = await annotateList(result, listKey, undefined);
|
|
53
|
+
return deps ? (0, soft_1.soft)(annotateList(result, listKey, deps), plain, ms) : plain;
|
|
54
|
+
}
|
|
55
|
+
exports.annotateListCapped = annotateListCapped;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.askPromptText = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const FALLBACK = [
|
|
7
|
+
'# Ask the hub',
|
|
8
|
+
'',
|
|
9
|
+
'Answer the question below from what the memory hub already knows, in plain language.',
|
|
10
|
+
'',
|
|
11
|
+
'1. Search with `memory_recall` scope=team, which includes your own items, for Facts, Skills, Scenarios and Wiki pages.',
|
|
12
|
+
'2. When a project is named, list its pages with `memory_list type=Wiki titlePrefix="<Project> ›"`.',
|
|
13
|
+
'3. Read anything cut short with `memory_get`, and back each claim with the uid it came from.',
|
|
14
|
+
"4. When the hub has nothing, say so and ask which sources to read; reading sources costs tokens. Searching everything for a project needs Claude Code in the project's repo.",
|
|
15
|
+
'5. Never paste SOW or Slack text, and never save prices, rates, budgets, customer personal data or credentials.',
|
|
16
|
+
'6. End with one line of what you updated and saved, or "Nothing changed."',
|
|
17
|
+
].join('\n');
|
|
18
|
+
// A repo checkout first: its packed assets copy is only refreshed by `npm pack`.
|
|
19
|
+
function skillPaths(assetsDir) {
|
|
20
|
+
if (assetsDir) {
|
|
21
|
+
return [(0, path_1.join)(assetsDir, 'skills', 'ask', 'SKILL.md')];
|
|
22
|
+
}
|
|
23
|
+
const pkgDir = (0, path_1.join)(__dirname, '..');
|
|
24
|
+
return [(0, path_1.join)(pkgDir, '..', 'skills', 'ask', 'SKILL.md'), (0, path_1.join)(pkgDir, 'assets', 'skills', 'ask', 'SKILL.md')];
|
|
25
|
+
}
|
|
26
|
+
function readSkillBody(assetsDir) {
|
|
27
|
+
for (const path of skillPaths(assetsDir)) {
|
|
28
|
+
try {
|
|
29
|
+
return (0, fs_1.readFileSync)(path, 'utf-8').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '').trim();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function askPromptText(question, assetsDir) {
|
|
38
|
+
const body = readSkillBody(assetsDir) || FALLBACK;
|
|
39
|
+
return `${body}\n\n## The question\n\n${question.trim()}\n`;
|
|
40
|
+
}
|
|
41
|
+
exports.askPromptText = askPromptText;
|
package/dist/bulk.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.performLinkRepoTeam = exports.performMoveResourceRepo = exports.performSaveBatch = exports.performSaveItem = exports.MAX_LINK_BATCH = exports.MAX_MOVE_BATCH = exports.MAX_SAVE_BATCH = void 0;
|
|
4
4
|
const capture_1 = require("./capture");
|
|
5
|
+
const similar_notice_1 = require("./similar-notice");
|
|
5
6
|
const save_1 = require("./save");
|
|
6
7
|
exports.MAX_SAVE_BATCH = 25;
|
|
7
8
|
exports.MAX_MOVE_BATCH = 100;
|
|
@@ -20,8 +21,7 @@ async function performSaveItem(deps, input) {
|
|
|
20
21
|
}
|
|
21
22
|
exports.performSaveItem = performSaveItem;
|
|
22
23
|
function describeMatch(match) {
|
|
23
|
-
|
|
24
|
-
return `${match.uid} (${match.similarity.toFixed(2)}${owner})`;
|
|
24
|
+
return `${match.uid} (${match.similarity.toFixed(2)}${(0, similar_notice_1.ownerLabel)(match)})`;
|
|
25
25
|
}
|
|
26
26
|
async function performSaveBatch(deps, items) {
|
|
27
27
|
if (items.length === 0) {
|
|
@@ -32,6 +32,7 @@ async function performSaveBatch(deps, items) {
|
|
|
32
32
|
}
|
|
33
33
|
const results = [];
|
|
34
34
|
const similarNotices = [];
|
|
35
|
+
const allMatches = [];
|
|
35
36
|
for (const [index, input] of items.entries()) {
|
|
36
37
|
try {
|
|
37
38
|
const outcome = await performSaveItem(deps, input);
|
|
@@ -42,6 +43,7 @@ async function performSaveBatch(deps, items) {
|
|
|
42
43
|
const { possibleDuplicate, similar, ...saved } = outcome.result;
|
|
43
44
|
const matches = similar?.length ? similar : possibleDuplicate ? [possibleDuplicate] : [];
|
|
44
45
|
const similarTo = matches.map(describeMatch);
|
|
46
|
+
allMatches.push(...matches);
|
|
45
47
|
results.push({ index, ...saved, ...(similarTo.length ? { similarTo } : {}) });
|
|
46
48
|
if (similarTo.length) {
|
|
47
49
|
similarNotices.push(`- item ${index} (${saved.uid}) resembles ${similarTo.join(', ')}`);
|
|
@@ -51,7 +53,7 @@ async function performSaveBatch(deps, items) {
|
|
|
51
53
|
results.push({ index, error: message(err) });
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
return { results, similarNotices };
|
|
56
|
+
return { results, similarNotices, ...(allMatches.length ? { similarClosing: (0, similar_notice_1.batchClosingLine)(allMatches) } : {}) };
|
|
55
57
|
}
|
|
56
58
|
exports.performSaveBatch = performSaveBatch;
|
|
57
59
|
function performMoveResourceRepo(deps, input) {
|
package/dist/capture.js
CHANGED
|
@@ -7,12 +7,15 @@ function isCaptureMode(env = process.env) {
|
|
|
7
7
|
return env.MEMORY_HUB_CAPTURE === '1';
|
|
8
8
|
}
|
|
9
9
|
exports.isCaptureMode = isCaptureMode;
|
|
10
|
+
// Same pick as the session-stop hook's jq max_by: newest by lastModifiedDate, the later one on a tie, else the first returned.
|
|
11
|
+
function pickNewest(items) {
|
|
12
|
+
const newest = items.reduce((best, item) => (item.lastModifiedDate && (!best || item.lastModifiedDate >= best.lastModifiedDate) ? item : best), undefined);
|
|
13
|
+
return newest ?? items[0];
|
|
14
|
+
}
|
|
10
15
|
async function findOwnFactUid(deps, content, externalRef) {
|
|
11
16
|
if (externalRef) {
|
|
12
17
|
const { facts } = await deps.client.recall({ scope: 'self', externalRef, maxCharsPerItem: 1, maxTotalChars: 10000 });
|
|
13
|
-
|
|
14
|
-
const newest = facts.reduce((best, fact) => (fact.lastModifiedDate && (!best || fact.lastModifiedDate >= best.lastModifiedDate) ? fact : best), undefined);
|
|
15
|
-
return (newest ?? facts[0])?.uid;
|
|
18
|
+
return pickNewest(facts)?.uid;
|
|
16
19
|
}
|
|
17
20
|
const queryEmbedding = await deps.embed(content);
|
|
18
21
|
const { facts } = await deps.client.recall({
|
|
@@ -25,6 +28,27 @@ async function findOwnFactUid(deps, content, externalRef) {
|
|
|
25
28
|
const similar = facts.filter((fact) => (fact.similarity ?? 0) >= SIMILAR_OWN_FACT_FLOOR);
|
|
26
29
|
return similar.sort((a, b) => (b.similarity ?? 0) - (a.similarity ?? 0))[0]?.uid;
|
|
27
30
|
}
|
|
31
|
+
async function refuseDuplicateScenario(deps, externalRef) {
|
|
32
|
+
if (!externalRef) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const { scenarios } = await deps.client
|
|
36
|
+
.recallScenarios({ scope: 'self', externalRef, maxCharsPerItem: 1, maxTotalChars: 10000 })
|
|
37
|
+
.catch(() => ({ scenarios: [] }));
|
|
38
|
+
const uid = pickNewest(scenarios)?.uid;
|
|
39
|
+
if (!uid) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const existing = await deps.client.getScenario({ uid }).catch(() => undefined);
|
|
43
|
+
if (!existing || typeof existing.summary !== 'string') {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
message: `Not saved: Scenario ${uid} already covers ${externalRef}. ` +
|
|
48
|
+
`Merge what is new into the text below and call memory_update type=Scenario uid=${uid} with the complete merged text. ` +
|
|
49
|
+
`Keep everything below that is still true.\n\n${existing.summary}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
28
52
|
async function captureUpsert(deps, input, env = process.env) {
|
|
29
53
|
if (isCaptureMode(env) && input.visibility !== undefined) {
|
|
30
54
|
return {
|
|
@@ -32,7 +56,13 @@ async function captureUpsert(deps, input, env = process.env) {
|
|
|
32
56
|
'Save again without visibility; a human can share the item afterwards.',
|
|
33
57
|
};
|
|
34
58
|
}
|
|
35
|
-
if (!isCaptureMode(env)
|
|
59
|
+
if (!isCaptureMode(env)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
if (input.type === 'Scenario') {
|
|
63
|
+
return refuseDuplicateScenario(deps, input.externalRef);
|
|
64
|
+
}
|
|
65
|
+
if (input.type !== 'Fact' || !input.content) {
|
|
36
66
|
return undefined;
|
|
37
67
|
}
|
|
38
68
|
const uid = await findOwnFactUid(deps, input.content, input.externalRef).catch(() => undefined);
|
package/dist/check-sources.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.performCheckSources = exports.execGit = void 0;
|
|
3
|
+
exports.performCheckSources = exports.listBySourceRepo = exports.execGit = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const TYPES = ['Fact', 'Skill', 'Scenario', 'Wiki'];
|
|
6
6
|
const PAGE_SIZE = 200;
|
|
7
7
|
const HEX_SHA = /^[0-9a-f]{7,64}$/i;
|
|
8
|
+
const GIT_TIMEOUT_MS = 3000;
|
|
8
9
|
const execGit = (args) => new Promise((resolve, reject) => {
|
|
9
|
-
(0, child_process_1.execFile)('git', args, { cwd: process.cwd(), encoding: 'utf8' }, (err, stdout) => (err ? reject(err) : resolve(stdout)));
|
|
10
|
+
(0, child_process_1.execFile)('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: GIT_TIMEOUT_MS }, (err, stdout) => (err ? reject(err) : resolve(stdout)));
|
|
10
11
|
});
|
|
11
12
|
exports.execGit = execGit;
|
|
12
13
|
async function listBySourceRepo(client, sourceRepo) {
|
|
@@ -24,6 +25,7 @@ async function listBySourceRepo(client, sourceRepo) {
|
|
|
24
25
|
}
|
|
25
26
|
return items;
|
|
26
27
|
}
|
|
28
|
+
exports.listBySourceRepo = listBySourceRepo;
|
|
27
29
|
async function compareToHead(exec, sha) {
|
|
28
30
|
if (!HEX_SHA.test(sha)) {
|
|
29
31
|
return {};
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
// load when MEMORY_HUB_MCP_TOKEN is unset — which is exactly the state `setup` exists
|
|
5
5
|
// to fix, so it can never be reached from there.
|
|
6
6
|
const command = process.argv[2];
|
|
7
|
-
if (command === '
|
|
7
|
+
if (command === '--version' || command === '-v') {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
+
const { packageVersion } = require('./version');
|
|
10
|
+
console.log(packageVersion());
|
|
11
|
+
}
|
|
12
|
+
else if (command === 'setup') {
|
|
8
13
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
14
|
const { runSetup } = require('./setup');
|
|
10
15
|
runSetup(process.argv.slice(3)).catch((error) => {
|
|
@@ -55,8 +60,30 @@ else if (command === 'import') {
|
|
|
55
60
|
process.exitCode = 1;
|
|
56
61
|
});
|
|
57
62
|
}
|
|
63
|
+
else if (command === 'sweep') {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
65
|
+
const { runSweep } = require('./sweep');
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
67
|
+
const { functionUrl } = require('./setup');
|
|
68
|
+
runSweep(process.argv.slice(3), { env: process.env, log: (line) => console.log(line), functionUrl }).then((code) => {
|
|
69
|
+
process.exitCode = code;
|
|
70
|
+
}, (error) => {
|
|
71
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else if (command === 'migrate-plugin') {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
77
|
+
const { runMigratePlugin } = require('./migrate-plugin');
|
|
78
|
+
runMigratePlugin(process.argv.slice(3)).then((code) => {
|
|
79
|
+
process.exitCode = code;
|
|
80
|
+
}, (error) => {
|
|
81
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
58
85
|
else if (command === '--help' || command === '-h') {
|
|
59
|
-
console.log(`memory-hub-mcp — MCP server for the
|
|
86
|
+
console.log(`memory-hub-mcp — MCP server for the Memory Hub
|
|
60
87
|
|
|
61
88
|
memory-hub-mcp setup log in, then wire up Claude Code and/or Claude Desktop, and verify
|
|
62
89
|
the token. Pass --code, --desktop or --both to skip the prompt.
|
|
@@ -78,6 +105,11 @@ else if (command === '--help' || command === '-h') {
|
|
|
78
105
|
memory-hub-mcp import apply <plan.json> --repo <owner/name>
|
|
79
106
|
save a reviewed plan to the hub as Team items on that repo, with
|
|
80
107
|
embeddings. Re-running resumes where it stopped.
|
|
108
|
+
memory-hub-mcp sweep --repo <owner/name> --checkout <path> [--stamp]
|
|
109
|
+
sort the hub's memories sourced from that repo by whether the files
|
|
110
|
+
they cite changed since their source commit, and print JSON.
|
|
111
|
+
Compares against the checkout's origin/HEAD and never fetches.
|
|
112
|
+
--stamp moves the source commit of unchanged items forward.
|
|
81
113
|
memory-hub-mcp embed print the embedding of the text on stdin (or the arguments) as JSON;
|
|
82
114
|
used by the UserPromptSubmit hook. Exits non-zero if it cannot.
|
|
83
115
|
memory-hub-mcp run the MCP server on stdio (how a host launches it)
|
package/dist/git-remote.js
CHANGED
|
@@ -33,11 +33,16 @@ function canonicalizeRemoteUrl(remoteUrl) {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
exports.canonicalizeRemoteUrl = canonicalizeRemoteUrl;
|
|
36
|
-
|
|
36
|
+
// execFileSync blocks the event loop, so a hung git would freeze every tool call.
|
|
37
|
+
const GIT_TIMEOUT_MS = 5000;
|
|
38
|
+
// The pack-import CLI is not the server; a timed-out status there would read as a clean checkout.
|
|
39
|
+
const CLI_GIT_TIMEOUT_MS = 120_000;
|
|
40
|
+
function runGit(args, cwd, timeout = GIT_TIMEOUT_MS) {
|
|
37
41
|
try {
|
|
38
42
|
const stdout = (0, child_process_1.execFileSync)('git', args, {
|
|
39
43
|
cwd,
|
|
40
44
|
encoding: 'utf8',
|
|
45
|
+
timeout,
|
|
41
46
|
// stderr is swallowed: "not a git repository" is an expected, silent outcome.
|
|
42
47
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
43
48
|
});
|
|
@@ -51,21 +56,21 @@ function runGit(args, cwd) {
|
|
|
51
56
|
* The canonical `owner/name` of the repo this process is running in, or null if
|
|
52
57
|
* it isn't in a git checkout, has no remotes, or the remote isn't a recognized form.
|
|
53
58
|
*/
|
|
54
|
-
function detectRepoName(cwd = process.cwd()) {
|
|
55
|
-
let remoteUrl = runGit(['remote', 'get-url', 'origin'], cwd);
|
|
59
|
+
function detectRepoName(cwd = process.cwd(), timeout = GIT_TIMEOUT_MS) {
|
|
60
|
+
let remoteUrl = runGit(['remote', 'get-url', 'origin'], cwd, timeout);
|
|
56
61
|
if (!remoteUrl) {
|
|
57
|
-
const firstRemote = runGit(['remote'], cwd)?.split('\n')[0]?.trim();
|
|
62
|
+
const firstRemote = runGit(['remote'], cwd, timeout)?.split('\n')[0]?.trim();
|
|
58
63
|
if (firstRemote) {
|
|
59
|
-
remoteUrl = runGit(['remote', 'get-url', firstRemote], cwd);
|
|
64
|
+
remoteUrl = runGit(['remote', 'get-url', firstRemote], cwd, timeout);
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
return remoteUrl ? canonicalizeRemoteUrl(remoteUrl) : null;
|
|
63
68
|
}
|
|
64
69
|
exports.detectRepoName = detectRepoName;
|
|
65
70
|
function packCheckout(dir) {
|
|
66
|
-
const root = runGit(['rev-parse', '--show-toplevel'], dir);
|
|
67
|
-
const commit = runGit(['rev-parse', 'HEAD'], dir);
|
|
68
|
-
const repo = detectRepoName(dir);
|
|
71
|
+
const root = runGit(['rev-parse', '--show-toplevel'], dir, CLI_GIT_TIMEOUT_MS);
|
|
72
|
+
const commit = runGit(['rev-parse', 'HEAD'], dir, CLI_GIT_TIMEOUT_MS);
|
|
73
|
+
const repo = detectRepoName(dir, CLI_GIT_TIMEOUT_MS);
|
|
69
74
|
if (!root || !commit || !repo) {
|
|
70
75
|
return null;
|
|
71
76
|
}
|
|
@@ -74,7 +79,7 @@ function packCheckout(dir) {
|
|
|
74
79
|
commit,
|
|
75
80
|
// git prints the real path, so a symlinked temp or home folder must be resolved before comparing.
|
|
76
81
|
pathInRepo: (0, path_1.relative)((0, fs_1.realpathSync)(root), (0, fs_1.realpathSync)(dir)).split(path_1.sep).join('/'),
|
|
77
|
-
dirty: runGit(['status', '--porcelain', '--', '.'], dir) !== null,
|
|
82
|
+
dirty: runGit(['status', '--porcelain', '--', '.'], dir, CLI_GIT_TIMEOUT_MS) !== null,
|
|
78
83
|
};
|
|
79
84
|
}
|
|
80
85
|
exports.packCheckout = packCheckout;
|
package/dist/guide-check.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.staleBuildNotice = exports.toolsMentioned = void 0;
|
|
3
|
+
exports.guideSection = exports.guideSectionNames = exports.staleBuildNotice = exports.toolsMentioned = void 0;
|
|
4
4
|
// The guide is read from disk, so a pull without a rebuild pairs a new guide with an old build.
|
|
5
5
|
function toolsMentioned(guide) {
|
|
6
6
|
return [...new Set(guide.match(/\bmemory_[A-Za-z]+\b/g) ?? [])].sort();
|
|
@@ -22,3 +22,35 @@ function staleBuildNotice(guide, registered) {
|
|
|
22
22
|
`and restart the session.\n\n---\n\n`);
|
|
23
23
|
}
|
|
24
24
|
exports.staleBuildNotice = staleBuildNotice;
|
|
25
|
+
function guideBlocks(guide) {
|
|
26
|
+
const blocks = [];
|
|
27
|
+
let fence;
|
|
28
|
+
for (const line of guide.split('\n')) {
|
|
29
|
+
const marker = /^(`{3,}|~{3,})/.exec(line)?.[1];
|
|
30
|
+
if (marker && (!fence || (marker[0] === fence[0] && marker.length >= fence.length))) {
|
|
31
|
+
fence = fence ? undefined : marker;
|
|
32
|
+
}
|
|
33
|
+
const heading = !fence && !marker ? /^## (.+?)\s*$/.exec(line) : null;
|
|
34
|
+
if (heading) {
|
|
35
|
+
blocks.push({ name: heading[1], lines: [line] });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
blocks[blocks.length - 1]?.lines.push(line);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return blocks;
|
|
42
|
+
}
|
|
43
|
+
function guideSectionNames(guide) {
|
|
44
|
+
return guideBlocks(guide).map((block) => block.name);
|
|
45
|
+
}
|
|
46
|
+
exports.guideSectionNames = guideSectionNames;
|
|
47
|
+
function guideSection(guide, section) {
|
|
48
|
+
const wanted = section.trim().toLowerCase();
|
|
49
|
+
const blocks = guideBlocks(guide);
|
|
50
|
+
const found = blocks.find((block) => block.name.toLowerCase() === wanted);
|
|
51
|
+
if (!found) {
|
|
52
|
+
throw new Error(`No section "${section.trim()}" in the skill guide. Sections: ${blocks.map((block) => block.name).join('; ')}.`);
|
|
53
|
+
}
|
|
54
|
+
return found.lines.join('\n').trimEnd();
|
|
55
|
+
}
|
|
56
|
+
exports.guideSection = guideSection;
|