@skedulo/memory-hub-mcp 0.2.13 → 0.2.15

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,150 @@
1
+ ---
2
+ name: product-knowledge
3
+ description: Use when building, refreshing or importing a customer product's knowledge in the memory hub (rules with IDs and tiers, work not to build, reference pages, sources), e.g. "create the product knowledge for Lindamood-Bell from the TDD", "refresh the LMB knowledge", "import the knowledge pack for this customer", or when fold-findings hands over confirmed changes.
4
+ ---
5
+
6
+ # Product knowledge
7
+
8
+ Product knowledge is a set of Team wiki pages in the memory hub, one set per product (a hub team), on
9
+ the product's delivery repo. Read `references/page-format.md` in this skill's folder before reading or
10
+ writing any page: it defines the titles, the entry line format, IDs, tiers, the change log, the
11
+ Sources page, the team-safe editing steps and the confidentiality rules. Follow it exactly.
12
+
13
+ Pick the mode from what the developer asks: **create** (no pages yet), **update** (refresh from
14
+ sources, or apply changes another skill hands over), or **import** (from a knowledge pack in the
15
+ shared memory repo).
16
+
17
+ ## First, check the server version
18
+
19
+ Look at the parameters of the `memory_update` tool; if only its name is listed, load its schema first.
20
+ If there is no `memory_update` tool at all, the memory-hub server is not connected: say so and stop.
21
+ If it has no `expectedLastModified` parameter, the memory-hub server is older than this release and
22
+ cannot edit safely. Stop, do nothing else, and tell the developer to update it:
23
+
24
+ - plugin installs, and `setup` installs with auto-update: restart Claude Code;
25
+ - pinned installs: re-run `npx -y @skedulo/memory-hub-mcp@latest setup --no-auto-update`;
26
+ - a checkout of the se-ai-memory-hub repo: pull and re-run `scripts/setup-dev.sh`.
27
+
28
+ ## Before any mode
29
+
30
+ 1. Find the product and its delivery repo. In the delivery repo's checkout, `memory_checkRepoStatus`
31
+ shows the linked team; otherwise ask, and confirm with `memory_listRepos`. If the repo is not
32
+ linked to the product's team, stop and ask the developer to link it; call `memory_linkRepoTeam`
33
+ only when they say so.
34
+ 2. List the existing pages: `memory_list type=Wiki repo=<repo uid> titlePrefix="<Product> ›"` (page
35
+ through with `offset` when `total` is larger). Read the ID prefix from existing entries.
36
+ 3. Nothing is saved or changed until the developer confirms it in this conversation.
37
+
38
+ ## Create
39
+
40
+ 1. If pages already exist for the product, switch to update.
41
+ 2. Ask which sources to build from: TDD, SOW and change requests, Confluence pages (Atlassian
42
+ connector), Linear issues or projects (Linear connector), Google Drive documents (Drive connector),
43
+ the delivery repo. If a connector a source needs is not connected, say so and ask for the document
44
+ another way; do not skip it silently.
45
+ 3. Read each source and note its version as the Sources page records it.
46
+ 4. Draft, per feature: rules (`R`) and constraints (`C`) with proposed IDs and tiers; the don't-build
47
+ list (`D`) with the reason and source of each item; the reference topics worth a page (data model,
48
+ APIs, workflows, glossary, troubleshooting, overview). Agree feature keys with the developer first.
49
+ 5. Show the draft feature by feature: each entry's ID, tier, status and text, and its source. Ask the
50
+ developer to confirm, change or drop entries, and to confirm every `core` entry by ID. Entries they
51
+ confirm from documents are `verified`; entries taken from code stay `unverified`.
52
+ 6. Apply the confidentiality rules to the confirmed draft. Remove anything they forbid and say what
53
+ you removed.
54
+ 7. Save each page with `memory_save type=Wiki repo=<delivery repo uid> title=... content=...`, with
55
+ `tags=["ProductRules"]` on rules and don't-build pages. Every page ends with a change-log line
56
+ (`<date> · <developer> · Created · from <sources>`). Check each result reports `visibility: "Team"`; if one does not, stop
57
+ and tell the developer.
58
+ 8. Save the Sources page last. Report every page title with its uid.
59
+
60
+ ## Update
61
+
62
+ Use update to refresh from sources, to add sources, or to apply a confirmed change list handed over by
63
+ fold-findings or plan-ticket.
64
+
65
+ A change list handed over by another skill skips steps 1 and 2 and runs steps 3 to 5; its non-core
66
+ changes are already confirmed. Then report what changed.
67
+
68
+ A core change is a new `core` entry, a change to or from `core`, or any edit, `Conflict:` note or
69
+ retirement of a `core` entry. Each one needs the developer to confirm that entry by ID. Approving a
70
+ plan or a change list as a whole is not that confirmation, so ask about each core change in a
71
+ handed-over list too, unless the developer already confirmed that exact change by ID in this
72
+ conversation.
73
+
74
+ 1. Read the Sources page. For each source, read its current version (page-format.md lists how) and
75
+ compare it with the recorded one. A source you cannot reach is reported as unchecked, not as
76
+ unchanged.
77
+ 2. For each changed source, re-read it and compare with the pages it feeds. Propose, per feature:
78
+ new entries (next free IDs), changed text, tier changes, entries a newer decision overrides (a
79
+ `Conflict:` note plus a new entry), and entries to retire.
80
+
81
+ A `pack` source has moved when its recorded commit differs from the checkout's HEAD or
82
+ `memory_checkSources` reports its pages behind. Re-read it by running `import convert` again with
83
+ the same `--product` and `--prefix` and `--out "$TMPDIR/memory-hub-import/<PREFIX>-refresh.json"`
84
+ (it saves nothing, and nothing is written in the checkout). Compare that plan's pages with the hub
85
+ pages entry by entry, matched by ID, on rule text and source only: a fresh convert marks every
86
+ entry `standard` and `unverified`, so never propose reverting a hub entry's tier, status,
87
+ `Conflict:` note or retirement, and never propose removing an entry the pack does not have. If a
88
+ pack entry's ID is already used by a different hub entry, ask. Propose the differences as above,
89
+ and use the new review file's flags in step 4. Never run `import apply` for a product that
90
+ already has pages; the CLI refuses it. In step 6, also set each page the pack feeds to the new
91
+ commit (`memory_update ... source={repo: "<owner/name>", commit: "<sha>"}` with
92
+ `expectedLastModified`), so `memory_checkSources` stops reporting it. When you are done, offer to
93
+ delete the new plan and review files: they may hold flagged values.
94
+ 3. Show the proposals with each entry's exact current line and exact new line, and ask about each
95
+ core change by ID. Apply only what the developer confirms.
96
+ 4. Apply the confidentiality rules to the confirmed changes. Remove anything they forbid and say what
97
+ you removed.
98
+ 5. Apply each confirmed change with the team-safe editing steps in page-format.md: `memory_get`, edit
99
+ the full text, add the change-log line, `memory_update` with `expectedLastModified`, and retry on
100
+ `Conflict:`.
101
+ 6. Update the Sources page with the versions you read, through the same steps.
102
+
103
+ ## Import
104
+
105
+ Imports a knowledge pack, `domains/<name>/` in a checkout of the shared memory repo, through the
106
+ `memory-hub-mcp import` CLI, which saves through the same path as `memory_save`, so every page is
107
+ embedded. Each imported page records the pack's repo and commit as its source. Never edit the shared
108
+ memory repo from this skill: it changes only through its own publish tool.
109
+
110
+ 1. If pages already exist for the product, do not import: importing again would duplicate titles or
111
+ start a second ID prefix, and `import apply` refuses it. To pick up a pack that has moved, use
112
+ update mode.
113
+ 2. Ask for the path of the shared memory repo checkout and the pack name (`domains/<name>`), the
114
+ product name, the ID prefix, and the delivery repo as `owner/name` (linked to the product's team).
115
+ 3. The CLI needs `MEMORY_HUB_MCP_TOKEN` in the environment. `memory-hub-mcp setup` stores it in
116
+ `~/.claude/settings.json`, which Claude Code passes to commands. If it is missing, ask the developer
117
+ to run `npx -y @skedulo/memory-hub-mcp@latest setup --code`, or to export the token in this shell.
118
+ 4. Convert. This saves nothing:
119
+
120
+ ```bash
121
+ npx -y @skedulo/memory-hub-mcp@latest import convert "<checkout>/domains/<name>" --product "<Product>" --prefix <PREFIX> --by "<developer name>"
122
+ ```
123
+
124
+ It prints the plan file (JSON) and the review file (Markdown) beside it.
125
+ 5. Read the review file and go through its flags with the developer, the likely names first. For each
126
+ flagged value, the developer chooses: remove it (edit the content of every item the flag lists in
127
+ the plan JSON), skip a whole item (`"skip": true`), or keep it (`"resolved": true` on the flag,
128
+ only for Skedulo staff names and values that are not customer data). Show the "Probably product
129
+ terms" list and let the developer resolve it in one go. Apply the confidentiality rules to the rest
130
+ of the plan as you go.
131
+ 6. Every imported entry is `standard` and `unverified`. Ask whether any should be `core` now; edit
132
+ those lines in the plan JSON. Constraints with category `scope` are don't-build candidates: note
133
+ them for an update after the import.
134
+ 7. Before saving, tell the developer what apply will write: the number of pages and facts, the page
135
+ titles, and that each is a Team item on `<owner/name>`, visible to the product team. Run apply
136
+ only when they say go ahead.
137
+ 8. Save:
138
+
139
+ ```bash
140
+ npx -y @skedulo/memory-hub-mcp@latest import apply "<plan.json>" --repo <owner/name>
141
+ ```
142
+
143
+ It refuses while a flagged value is unresolved, when the repo has no team, or when the embedding
144
+ model does not load. It writes each saved uid into the plan file, so if it stops partway, run the
145
+ same command again and it resumes.
146
+ 9. The plan and review files still hold the flagged values. Once apply has finished without errors,
147
+ tell the developer where they are (the `Plan:` and `Review:` paths convert printed) and offer to
148
+ delete them. Keep them while an apply is unfinished: the plan file is what it resumes from.
149
+ 10. Ask the developer to check the pages in the hub. When they are happy, offer a don't-build page
150
+ from the `scope` constraints (update mode).
@@ -0,0 +1,133 @@
1
+ # Product knowledge pages
2
+
3
+ Every skill that reads or writes product knowledge follows this file.
4
+
5
+ ## Where it lives
6
+
7
+ A product is a memory-hub team (for example "Lindamood Bell"). Its knowledge is Team-visible wiki pages
8
+ on the product's delivery repo, the repo linked to that team. A product with several repos links them
9
+ all to the same team; the pages attach to the delivery repo only.
10
+
11
+ - Visibility is always Team: never Org, never Private. A repo-scoped save on a team-linked repo is
12
+ Team by default, so do not pass `visibility`; check that each save reports `visibility: "Team"`.
13
+ - `<Product>` is the product's display name, written the same way in every title.
14
+ - `<PREFIX>` is the product's ID prefix, upper-case letters and digits (`LMB`). Read it from the
15
+ existing rule IDs; never start a second prefix for the same product.
16
+
17
+ ## Page kinds
18
+
19
+ - `<Product> › Rules › <feature>`: the rules and constraints for one feature. Tag `ProductRules`.
20
+ - `<Product> › Don't build`: work that is out of scope, with the reason and source. Tag `ProductRules`.
21
+ - `<Product> › Reference › <topic>`: APIs, workflows, data model, glossary, troubleshooting,
22
+ overview. No tag.
23
+ - `<Product> › Sources`: every source the knowledge was built from, with its version or hash. No tag.
24
+
25
+ `<feature>` is a stable kebab-case key (`group-sessions`, `schedule-plans`). It becomes a Knowledge Hub
26
+ area name later, so never derive it from a ticket key or a date, and never rename one. Add a new
27
+ feature key only with the developer's agreement.
28
+
29
+ A page over about 20,000 characters is split into parts titled `<title> (1/3)`, `(2/3)`, `(3/3)`. Each
30
+ part keeps its own change log. When an edit pushes a page over the limit, move whole entries into a
31
+ new last part and renumber the titles.
32
+
33
+ Find pages with `memory_list type=Wiki repo=<delivery repo uid> titlePrefix="<Product> ›"`, or
34
+ `tags=["ProductRules"]` for the rules and don't-build pages only; it returns `total` and one page of
35
+ items, so call it again with `offset` until you have them all. Read a page in full with
36
+ `memory_get type=Wiki uid=<uid>`, which also returns its `lastModifiedDate`.
37
+
38
+ ## Entry lines
39
+
40
+ One entry per bullet, so a skill can copy it verbatim into a sub-issue:
41
+
42
+ ```
43
+ - **LMB-R13** · core · verified — The Skedulo Optimizer is out of scope for both divisions. _Source: TDD For Schools §4.2_
44
+ ```
45
+
46
+ - ID: `<PREFIX>-R<n>` for a rule, `<PREFIX>-C<n>` for a constraint, `<PREFIX>-D<n>` for a don't-build
47
+ item. IDs are unique within the product and never reused. The next ID is one more than the highest
48
+ existing number of that kind across all the product's pages. Imported entries keep their number.
49
+ - Tier: `core` (never change without the developer's explicit confirmation of that entry),
50
+ `standard`, or `detail` (a tunable default).
51
+ - Status: `verified` or `unverified`. Anything taken from code, an import or old files is
52
+ `unverified` until a developer reviews it. An entry the developer confirmed from a TDD, SOW,
53
+ Confluence page or Linear decision is `verified`.
54
+ - Source: the document and section, the Linear issue, or `code: <owner/name>@<short sha> <path>`.
55
+ - When a later decision overrides an entry, do not rewrite it silently. Keep the line and add
56
+ `Conflict: overridden by SOL-1234 (<one-line reason>)` after the source, then add the new entry with
57
+ its own ID.
58
+ - A retired entry moves to a `## Retired` section at the end of its page, before the change log, with
59
+ `Retired <date>: <reason>` after the source. Its ID is not reused.
60
+
61
+ Rules pages have `## Rules` and `## Constraints` sections. The don't-build page has one list:
62
+
63
+ ```
64
+ - **LMB-D3** · core · verified — Do not build an automatic waitlist. Reason: the customer keeps waitlists in Salesforce. _Source: SOW §2.1 (scope as function)_
65
+ ```
66
+
67
+ ## Change log
68
+
69
+ Every page ends with:
70
+
71
+ ```
72
+ ## Change log
73
+
74
+ - 2026-10-21 · Sam Developer · Added LMB-R74, changed LMB-R13 to core · TDD v1.4 §3 changed the session rules
75
+ ```
76
+
77
+ Date, who (the developer, by name), what changed (entry IDs), why (the source or decision). Newest
78
+ last. The skills write it; it stands in for the history git would otherwise give.
79
+
80
+ ## Sources page
81
+
82
+ One line per source:
83
+
84
+ ```
85
+ - `local` · docs/TDD For Schools.pdf · sha256 `9f2c…` · read 2026-10-21
86
+ - `confluence` · page 123456789 "LC Technical Design" · version 14 · read 2026-10-21
87
+ - `linear` · SOL-1234 · updatedAt 2026-10-20T03:00:00.000Z · read 2026-10-21
88
+ - `gdrive` · file 1AbCdEf "LC Statement of Work" · modifiedTime 2026-10-19T22:10:00.000Z · read 2026-10-21
89
+ - `repo` · Skedulo/cx-lindamood-bell@main · commit 4be1c0d · read 2026-10-21
90
+ - `pack` · <owner/name of the shared memory repo> domains/cx-lindamood-bell · commit 7a3e9b1 · read 2026-10-21
91
+ ```
92
+
93
+ How to read each version now:
94
+
95
+ - `local`: `shasum -a 256 "<path>"`.
96
+ - `confluence`: the Atlassian connector's get-page call; use the page's `version.number`.
97
+ - `linear`: the Linear connector's get-issue (or get-project/get-document) call; use `updatedAt`.
98
+ - `gdrive`: the Google Drive connector's file-metadata call; use `modifiedTime` (or `version`).
99
+ - `repo`: `git -C <checkout> rev-parse HEAD`, or `gh api repos/<owner>/<name>/commits/<branch> --jq .sha`.
100
+ - `pack`: `git -C <checkout> rev-parse HEAD` in an up-to-date checkout of the shared memory repo, or
101
+ `memory_checkSources` run in that checkout, which lists imported pages whose commit is behind.
102
+
103
+ ## Editing a page (team-safe)
104
+
105
+ Any member of the product team can edit these pages; two developers must not overwrite each other.
106
+
107
+ 1. `memory_get type=Wiki uid=<uid>`; keep its `content` and `lastModifiedDate`.
108
+ 2. Apply the change to the full text. Keep every other line exactly as it was.
109
+ 3. Append the change-log line.
110
+ 4. `memory_update type=Wiki uid=<uid> content=<full new text> expectedLastModified=<lastModifiedDate>`.
111
+ 5. If it fails with `Conflict:`, someone else changed the page. Go back to step 1, re-apply the change
112
+ to the new text, show the developer what the other person changed if it touches the same entries,
113
+ and retry.
114
+
115
+ Teammates can change a page's title, content and tags. Only the page's author can move it to another
116
+ repo or change its links; ask them if that is needed. Deleting a page is author-only too; prefer
117
+ retiring entries over deleting pages.
118
+
119
+ ## Confidentiality
120
+
121
+ Read documents in the session and store only distilled knowledge. The hub may hold: the customer's
122
+ organisation name, features and rules, scope stated as function, decisions attributed by role ("the
123
+ customer's operations lead"), schema and field API names, and Skedulo staff names.
124
+
125
+ Never store, on any page or fact:
126
+
127
+ - commercial terms: prices, rates, budgets, contract values, payment terms;
128
+ - customer personal data: names, emails or phone numbers of customer staff or end users;
129
+ - credentials, tokens or secrets;
130
+ - customer data rows or production record IDs (UUIDs, Salesforce record IDs);
131
+ - verbatim contract text: never quote a SOW or change request; restate scope as function.
132
+
133
+ When unsure, leave it out and tell the developer what you left out.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refreshInstalledAssets = exports.syncInstalledAssets = exports.recordInstall = exports.recordCliPath = exports.compareVersions = exports.packageVersion = exports.installDirs = exports.CLI_PATH_FILE = exports.VERSION_FILE = exports.HOOK_SCRIPTS = void 0;
3
+ exports.refreshInstalledAssets = exports.syncInstalledAssets = exports.recordInstall = exports.recordCliPath = exports.compareVersions = exports.packageVersion = exports.copySkills = exports.ownsSkillDir = exports.removeSkill = exports.markedSkills = exports.listedSkillFiles = exports.packagedSkills = exports.filesUnder = exports.installDirs = exports.LEGACY_SKILL = exports.SKILL_MARKER = exports.CLI_PATH_FILE = exports.VERSION_FILE = exports.HOOK_SCRIPTS = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const os_1 = require("os");
6
6
  const path_1 = require("path");
@@ -8,13 +8,162 @@ exports.HOOK_SCRIPTS = ['session-start.sh', 'session-stop.sh', 'user-prompt-subm
8
8
  exports.VERSION_FILE = '.installed-version';
9
9
  // The prompt hook runs `embed` from this path, i.e. the build the host last launched.
10
10
  exports.CLI_PATH_FILE = 'cli-path';
11
+ exports.SKILL_MARKER = '.memory-hub';
12
+ // Copied by setup before the marker existed, so it is ours without one.
13
+ exports.LEGACY_SKILL = 'se-ai-memory-hub';
11
14
  function installDirs(home = (0, os_1.homedir)()) {
12
15
  return {
13
16
  hookDir: (0, path_1.join)(home, '.claude', 'memory-hub-hook'),
14
- skillFile: (0, path_1.join)(home, '.claude', 'skills', 'se-ai-memory-hub', 'SKILL.md'),
17
+ skillsDir: (0, path_1.join)(home, '.claude', 'skills'),
15
18
  };
16
19
  }
17
20
  exports.installDirs = installDirs;
21
+ function filesUnder(dir) {
22
+ return (0, fs_1.readdirSync)(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? filesUnder((0, path_1.join)(dir, entry.name)) : [(0, path_1.join)(dir, entry.name)]);
23
+ }
24
+ exports.filesUnder = filesUnder;
25
+ function packagedSkills(assetsDir) {
26
+ const root = (0, path_1.join)(assetsDir, 'skills');
27
+ if (!(0, fs_1.existsSync)(root))
28
+ return [];
29
+ return (0, fs_1.readdirSync)(root, { withFileTypes: true })
30
+ .filter((entry) => entry.isDirectory())
31
+ .map((entry) => entry.name)
32
+ .sort();
33
+ }
34
+ exports.packagedSkills = packagedSkills;
35
+ function entryAt(path) {
36
+ try {
37
+ return (0, fs_1.lstatSync)(path);
38
+ }
39
+ catch {
40
+ return undefined;
41
+ }
42
+ }
43
+ // A symlinked folder or marker is never ours, so nothing is copied into or deleted through it.
44
+ function isMarked(dir) {
45
+ return !!entryAt(dir)?.isDirectory() && !!entryAt((0, path_1.join)(dir, exports.SKILL_MARKER))?.isFile();
46
+ }
47
+ function isLegacyCopy(dir) {
48
+ return (0, path_1.basename)(dir) === exports.LEGACY_SKILL && !!entryAt(dir)?.isDirectory() && !entryAt((0, path_1.join)(dir, exports.SKILL_MARKER));
49
+ }
50
+ // The marker lists the files setup copied, so a later release can delete the ones it no longer ships.
51
+ function listedSkillFiles(dir) {
52
+ if (!isMarked(dir))
53
+ return [];
54
+ return (0, fs_1.readFileSync)((0, path_1.join)(dir, exports.SKILL_MARKER), 'utf8')
55
+ .split('\n')
56
+ .map((line) => line.trim())
57
+ .filter((line) => line && line !== exports.SKILL_MARKER && !(0, path_1.isAbsolute)(line) && !line.split(/[\\/]/).includes('..'));
58
+ }
59
+ exports.listedSkillFiles = listedSkillFiles;
60
+ function writeSkillMarker(dir, files) {
61
+ (0, fs_1.writeFileSync)((0, path_1.join)(dir, exports.SKILL_MARKER), [...new Set(files)].sort().map((file) => `${file}\n`).join(''));
62
+ }
63
+ function skillFiles(srcRoot) {
64
+ return filesUnder(srcRoot).map((src) => (0, path_1.relative)(srcRoot, src).split(path_1.sep).join('/')).sort();
65
+ }
66
+ function markedSkills(skillsDir) {
67
+ if (!(0, fs_1.existsSync)(skillsDir))
68
+ return [];
69
+ return (0, fs_1.readdirSync)(skillsDir, { withFileTypes: true })
70
+ .filter((entry) => entry.isDirectory() && isMarked((0, path_1.join)(skillsDir, entry.name)))
71
+ .map((entry) => entry.name)
72
+ .sort();
73
+ }
74
+ exports.markedSkills = markedSkills;
75
+ // A symlinked subfolder would resolve elsewhere, so the file's folder must resolve to where its path reads.
76
+ function isOwnFile(dir, realDir, path) {
77
+ const folder = (0, path_1.relative)(dir, (0, path_1.dirname)(path));
78
+ if (folder === '..' || folder.startsWith(`..${path_1.sep}`) || (0, path_1.isAbsolute)(folder) || !entryAt(path)?.isFile())
79
+ return false;
80
+ try {
81
+ return (0, fs_1.realpathSync)((0, path_1.dirname)(path)) === (0, path_1.join)(realDir, folder);
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
87
+ // Only the folders a removed file leaves empty, so an empty folder the developer made stays.
88
+ function removeEmptyParents(dir, path) {
89
+ for (let parent = (0, path_1.dirname)(path); parent !== dir && (0, fs_1.readdirSync)(parent).length === 0; parent = (0, path_1.dirname)(parent)) {
90
+ (0, fs_1.rmdirSync)(parent);
91
+ }
92
+ }
93
+ function removeFiles(dir, files) {
94
+ const realDir = (0, fs_1.realpathSync)(dir);
95
+ const removed = [];
96
+ for (const file of files) {
97
+ const path = (0, path_1.join)(dir, file);
98
+ if (!isOwnFile(dir, realDir, path))
99
+ continue;
100
+ (0, fs_1.unlinkSync)(path);
101
+ removed.push(path);
102
+ removeEmptyParents(dir, path);
103
+ }
104
+ return removed;
105
+ }
106
+ // Deletes only what the marker lists (plus `extra`), so a file the developer added keeps the folder.
107
+ function removeSkill(skillsDir, name, extra = []) {
108
+ const dir = (0, path_1.join)(skillsDir, name);
109
+ const legacy = isLegacyCopy(dir);
110
+ if (!legacy && !isMarked(dir))
111
+ return [];
112
+ const files = legacy ? ['SKILL.md'] : [...listedSkillFiles(dir), ...extra, exports.SKILL_MARKER];
113
+ const removed = removeFiles(dir, [...new Set(files)]);
114
+ if ((0, fs_1.readdirSync)(dir).length === 0)
115
+ (0, fs_1.rmdirSync)(dir);
116
+ return removed;
117
+ }
118
+ exports.removeSkill = removeSkill;
119
+ function ownsSkillDir(skillsDir, name) {
120
+ const dir = (0, path_1.join)(skillsDir, name);
121
+ return !entryAt(dir) || isMarked(dir) || isLegacyCopy(dir);
122
+ }
123
+ exports.ownsSkillDir = ownsSkillDir;
124
+ function copySkills(assetsDir, skillsDir, log = () => { }) {
125
+ const changed = [];
126
+ const packaged = packagedSkills(assetsDir);
127
+ for (const name of packaged) {
128
+ const srcRoot = (0, path_1.join)(assetsDir, 'skills', name);
129
+ const destRoot = (0, path_1.join)(skillsDir, name);
130
+ if (!ownsSkillDir(skillsDir, name)) {
131
+ log(`memory-hub-mcp: left ${destRoot} alone: memory-hub did not install it`);
132
+ continue;
133
+ }
134
+ const files = skillFiles(srcRoot);
135
+ const listed = listedSkillFiles(destRoot);
136
+ // Marked first, listing old and new files, so an interrupted copy is finished and pruned by the next run.
137
+ (0, fs_1.mkdirSync)(destRoot, { recursive: true });
138
+ writeSkillMarker(destRoot, [...listed, ...files]);
139
+ // Before copying: on a case-insensitive disk, Foo.md renamed to foo.md is one file and would be deleted.
140
+ changed.push(...removeFiles(destRoot, listed.filter((file) => !files.includes(file))));
141
+ for (const file of files) {
142
+ const src = (0, path_1.join)(srcRoot, file);
143
+ const dest = (0, path_1.join)(destRoot, file);
144
+ if ((0, fs_1.existsSync)(dest) && (0, fs_1.readFileSync)(src).equals((0, fs_1.readFileSync)(dest)))
145
+ continue;
146
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(dest), { recursive: true });
147
+ (0, fs_1.copyFileSync)(src, dest);
148
+ changed.push(dest);
149
+ }
150
+ writeSkillMarker(destRoot, files);
151
+ }
152
+ for (const name of new Set([exports.LEGACY_SKILL, ...markedSkills(skillsDir)])) {
153
+ if (packaged.includes(name))
154
+ continue;
155
+ const removed = removeSkill(skillsDir, name);
156
+ if (removed.length > 0)
157
+ log(`memory-hub-mcp: removed ${(0, path_1.join)(skillsDir, name)}: the package no longer ships it`);
158
+ changed.push(...removed);
159
+ }
160
+ return changed;
161
+ }
162
+ exports.copySkills = copySkills;
163
+ // setup --plugin removes the copied skills but can keep a hook script, so hooks alone do not mean skills are wanted.
164
+ function hasCopiedSkills(skillsDir) {
165
+ return ((0, fs_1.existsSync)((0, path_1.join)(skillsDir, exports.LEGACY_SKILL, 'SKILL.md')) || markedSkills(skillsDir).length > 0);
166
+ }
18
167
  function packageVersion(distDir = __dirname) {
19
168
  return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(distDir, '..', 'package.json'), 'utf8')).version;
20
169
  }
@@ -55,9 +204,8 @@ function syncInstalledAssets(options) {
55
204
  const previous = (0, fs_1.existsSync)(marker) ? (0, fs_1.readFileSync)(marker, 'utf8').trim() : '';
56
205
  if (previous && compareVersions(options.version, previous) < 0)
57
206
  return { updated: [], skipped: 'newer-installed' };
58
- const files = [...hooks, { src: (0, path_1.join)(options.assetsDir, 'SKILL.md'), dest: options.skillFile, executable: false }];
59
207
  const updated = [];
60
- for (const file of files) {
208
+ for (const file of hooks) {
61
209
  if (!(0, fs_1.existsSync)(file.src) || !(0, fs_1.existsSync)(file.dest))
62
210
  continue;
63
211
  if ((0, fs_1.readFileSync)(file.src).equals((0, fs_1.readFileSync)(file.dest)))
@@ -67,6 +215,10 @@ function syncInstalledAssets(options) {
67
215
  (0, fs_1.chmodSync)(file.dest, 0o755);
68
216
  updated.push(file.dest);
69
217
  }
218
+ // Unlike a hook script, a skill the package added since setup is installed: it needs no registration to work.
219
+ if (hasCopiedSkills(options.skillsDir)) {
220
+ updated.push(...copySkills(options.assetsDir, options.skillsDir, options.log));
221
+ }
70
222
  recordInstall(options.hookDir, options.version, options.cliPath);
71
223
  return { updated };
72
224
  }
@@ -77,9 +229,9 @@ function refreshInstalledAssets({ distDir = __dirname, home = (0, os_1.homedir)(
77
229
  return undefined;
78
230
  try {
79
231
  const version = packageVersion(distDir);
80
- const { hookDir, skillFile } = installDirs(home);
232
+ const { hookDir, skillsDir } = installDirs(home);
81
233
  const cliPath = (0, path_1.join)(distDir, 'cli.js');
82
- const result = syncInstalledAssets({ assetsDir: (0, path_1.join)(distDir, '..', 'assets'), hookDir, skillFile, version, cliPath });
234
+ const result = syncInstalledAssets({ assetsDir: (0, path_1.join)(distDir, '..', 'assets'), hookDir, skillsDir, version, cliPath, log });
83
235
  // A plugin install has no copied hooks, but its prompt hook still needs this to embed.
84
236
  if (result.skipped === 'not-installed')
85
237
  recordCliPath(hookDir, cliPath);
package/dist/cli.js CHANGED
@@ -33,6 +33,28 @@ else if (command === 'embed') {
33
33
  }
34
34
  });
35
35
  }
36
+ else if (command === 'import') {
37
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
38
+ const { runImport } = require('./import-cli');
39
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
40
+ const { embed } = require('./embeddings');
41
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
42
+ const { functionUrl } = require('./setup');
43
+ runImport(process.argv.slice(3), {
44
+ env: process.env,
45
+ log: (line) => console.log(line),
46
+ today: () => new Date().toISOString().slice(0, 10),
47
+ embed,
48
+ functionUrl,
49
+ }).then(
50
+ // Exit code, not process.exit: onnxruntime aborts if the process exits with its model session open.
51
+ (code) => {
52
+ process.exitCode = code;
53
+ }, (error) => {
54
+ console.error(error instanceof Error ? error.message : String(error));
55
+ process.exitCode = 1;
56
+ });
57
+ }
36
58
  else if (command === '--help' || command === '-h') {
37
59
  console.log(`memory-hub-mcp — MCP server for the SE AI Memory Hub
38
60
 
@@ -49,6 +71,13 @@ else if (command === '--help' || command === '-h') {
49
71
  end, a background Claude run, using your Claude usage, saves what
50
72
  the session learned (new memories Private, updates keep their
51
73
  visibility). setup also asks.
74
+ memory-hub-mcp import convert <packDir> --product <name> --prefix <PREFIX> [--by <name>] [--out <plan.json>] [--force]
75
+ turn a knowledge pack folder (domains/<name> in the shared memory
76
+ repo) into a plan of product knowledge pages, plus a review file
77
+ listing values that look like customer data. Saves nothing.
78
+ memory-hub-mcp import apply <plan.json> --repo <owner/name>
79
+ save a reviewed plan to the hub as Team items on that repo, with
80
+ embeddings. Re-running resumes where it stopped.
52
81
  memory-hub-mcp embed print the embedding of the text on stdin (or the arguments) as JSON;
53
82
  used by the UserPromptSubmit hook. Exits non-zero if it cannot.
54
83
  memory-hub-mcp run the MCP server on stdio (how a host launches it)
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectRepoName = exports.canonicalizeRemoteUrl = void 0;
3
+ exports.packCheckout = exports.detectRepoName = exports.canonicalizeRemoteUrl = void 0;
4
4
  // memory-hub-mcp/src/git-remote.ts
5
5
  const child_process_1 = require("child_process");
6
+ const fs_1 = require("fs");
7
+ const path_1 = require("path");
6
8
  /**
7
9
  * Normalize a git remote URL to the canonical `owner/name` form, per the
8
10
  * repo/team grouping spec §3. The host is deliberately dropped — this project
@@ -60,3 +62,19 @@ function detectRepoName(cwd = process.cwd()) {
60
62
  return remoteUrl ? canonicalizeRemoteUrl(remoteUrl) : null;
61
63
  }
62
64
  exports.detectRepoName = detectRepoName;
65
+ 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);
69
+ if (!root || !commit || !repo) {
70
+ return null;
71
+ }
72
+ return {
73
+ repo,
74
+ commit,
75
+ // git prints the real path, so a symlinked temp or home folder must be resolved before comparing.
76
+ 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,
78
+ };
79
+ }
80
+ exports.packCheckout = packCheckout;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyPlan = exports.unresolvedFlags = void 0;
4
+ const pack_import_1 = require("./pack-import");
5
+ const save_1 = require("./save");
6
+ function unresolvedFlags(plan) {
7
+ const kept = new Set(plan.flags.filter((flag) => flag.resolved).map((flag) => `${flag.kind}|${flag.match}`));
8
+ const items = [
9
+ ...plan.pages.map((page) => ({ ...page, text: `${page.title}\n${page.content}` })),
10
+ ...plan.facts.map((fact) => ({ ...fact, text: fact.content })),
11
+ ];
12
+ return items
13
+ .filter((item) => !item.skip && !item.savedUid)
14
+ .flatMap((item) => (0, pack_import_1.flagText)(item.text)
15
+ .filter((flag) => !kept.has(`${flag.kind}|${flag.match}`))
16
+ .map((flag) => ({ target: item.id, ...flag })));
17
+ }
18
+ exports.unresolvedFlags = unresolvedFlags;
19
+ async function listWikiPages(client, repo, titlePrefix) {
20
+ const items = [];
21
+ for (;;) {
22
+ const page = await client.listResources({ type: 'Wiki', repo, titlePrefix, offset: items.length, limit: 200 });
23
+ items.push(...page.items);
24
+ if (page.items.length === 0 || items.length >= page.total)
25
+ return items;
26
+ }
27
+ }
28
+ // One item per request, in sequence: the function allows 5 concurrent invocations of 12 s each.
29
+ async function applyPlan(deps, plan, repoName) {
30
+ const open = unresolvedFlags(plan);
31
+ if (open.length) {
32
+ const places = [...new Set(open.map((flag) => `${flag.target} ${flag.kind}`))];
33
+ throw new Error(`Nothing saved: ${open.length} flagged value(s) are unresolved: ${places.slice(0, 10).join('; ')}${places.length > 10 ? '; …' : ''}. ` +
34
+ `${deps.reviewPath} lists each value; resolve them in the plan file first.`);
35
+ }
36
+ const repo = await deps.client.resolveRepo({ name: repoName });
37
+ if (!repo.uid || !('devTeamId' in repo) || !repo.devTeamId) {
38
+ throw new Error(`Nothing saved: ${repoName} is not linked to a team. Link it to the product's team (memory_linkRepoTeam) first.`);
39
+ }
40
+ const repoUid = repo.uid;
41
+ const titlePrefix = `${plan.product} ›`;
42
+ const savedByPlan = new Set(plan.pages.map((page) => page.savedUid));
43
+ const foreign = (await listWikiPages(deps.client, repoUid, titlePrefix)).filter((page) => !savedByPlan.has(page.uid));
44
+ if (foreign.length) {
45
+ const sample = foreign.slice(0, 3).map((page) => `${page.title} (${page.uid})`);
46
+ throw new Error(`Nothing saved: ${repoName} already has ${foreign.length} Wiki page(s) titled "${titlePrefix}" that this plan did not save, e.g. ${sample.join('; ')}. ` +
47
+ 'Resume an earlier import with its own plan file. If that plan is lost, delete those pages or use another --product before importing again.');
48
+ }
49
+ // resolve-task does not say whether it created the task, so an import links none rather than open one per historic ticket.
50
+ const resolveTaskUid = () => Promise.reject(new Error('An import never links a task; the ticket IDs stay in the fact text.'));
51
+ // performSave saves without an embedding when embedding fails; an imported page must stay searchable, so stop instead.
52
+ const save = async (id, embedText, input) => {
53
+ const embedding = await deps.embed(embedText).catch((err) => {
54
+ throw new Error(`Stopped before ${id}: the embedding model did not load (${err instanceof Error ? err.message : String(err)}), and imported pages must be searchable. Items already saved are recorded in the plan; re-run to resume.`);
55
+ });
56
+ const result = await (0, save_1.performSave)({ client: deps.client, embed: async () => embedding, currentRepoUid: async () => repoUid, resolveTaskUid }, input);
57
+ const similar = result.similar?.length ? result.similar : result.possibleDuplicate ? [result.possibleDuplicate] : [];
58
+ if (similar.length)
59
+ deps.log(` ${result.uid} resembles ${similar.map((match) => match.uid).join(', ')}; check for a duplicate`);
60
+ return result;
61
+ };
62
+ let saved = 0;
63
+ let skipped = 0;
64
+ for (const page of plan.pages) {
65
+ if (page.skip || page.savedUid) {
66
+ skipped++;
67
+ continue;
68
+ }
69
+ const result = await save(page.id, `${page.title}\n\n${page.content}`, { type: 'Wiki', title: page.title, content: page.content, tags: page.tags, repo: repoUid, visibility: 'Team', source: plan.source });
70
+ page.savedUid = result.uid;
71
+ deps.savePlan(plan);
72
+ deps.log(`saved ${page.title} -> ${result.uid}`);
73
+ saved++;
74
+ }
75
+ for (const fact of plan.facts) {
76
+ if (fact.skip || fact.savedUid) {
77
+ skipped++;
78
+ continue;
79
+ }
80
+ const result = await save(fact.id, fact.content, { type: 'Fact', content: fact.content, repo: repoUid, visibility: 'Team', source: plan.source });
81
+ fact.savedUid = result.uid;
82
+ deps.savePlan(plan);
83
+ deps.log(`saved fact ${fact.id} -> ${result.uid}`);
84
+ saved++;
85
+ }
86
+ return { saved, skipped };
87
+ }
88
+ exports.applyPlan = applyPlan;