@skedulo/memory-hub-mcp 0.2.20 → 0.2.21
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/assets/skills/sweep-knowledge/SKILL.md +61 -10
- package/dist/cli.js +21 -0
- package/dist/routine.js +136 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
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 ...]"
|
|
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. It can also schedule itself as a weekly cloud routine.
|
|
4
|
+
argument-hint: "[dry-run|apply|schedule [dry-run|apply]] [repo owner/name ...]"
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Weekly knowledge sweep
|
|
@@ -15,7 +15,7 @@ ones, within fixed caps.
|
|
|
15
15
|
would do. `apply` stamps, updates and refreshes. Start with dry runs; switch to `apply` once the
|
|
16
16
|
digests look right.
|
|
17
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
|
|
18
|
+
- **Unattended.** Never ask a question (schedule mode asks for one environment id, once). Anything that would need an answer is skipped and listed in
|
|
19
19
|
the digest as waiting, with why. A problem that stops the whole run still ends with the digest.
|
|
20
20
|
- **Never draft new knowledge.** The sweep saves no new memories, SkillDrift Facts included; it only
|
|
21
21
|
stamps, updates, flags and reports.
|
|
@@ -39,9 +39,50 @@ The `sweep` command needs `MEMORY_HUB_MCP_TOKEN` in the environment. If it is mi
|
|
|
39
39
|
in the digest how to provide it, as step 3 of the project-knowledge skill's `references/import.md`
|
|
40
40
|
explains (`memory-hub:project-knowledge` when installed as a plugin).
|
|
41
41
|
|
|
42
|
+
## Schedule mode
|
|
43
|
+
|
|
44
|
+
`schedule` sets up the weekly cloud routine `Memory hub weekly sweep` and stops. The rest of this
|
|
45
|
+
skill does not run. In order:
|
|
46
|
+
|
|
47
|
+
1. If `MEMORY_HUB_MCP_TOKEN` is unset, stop and say how to provide it, as in the check above. Never
|
|
48
|
+
print the token.
|
|
49
|
+
2. **Environment.** The token, the network access and the plugin live on a claude.ai cloud
|
|
50
|
+
environment, not on the routine. `RemoteTrigger list`, and if the existing routine has a
|
|
51
|
+
`job_config.ccr.environment_id`, reuse it. Otherwise ask for the id (`env_...`) of an environment
|
|
52
|
+
named `Memory hub`, giving these settings to create in claude.ai (Claude Code, environments).
|
|
53
|
+
This is the only question schedule mode asks.
|
|
54
|
+
- Network access: custom, keep the defaults, and add `*.skl.io`.
|
|
55
|
+
- Environment variable: `MEMORY_HUB_MCP_TOKEN=<your token>`. They paste it themselves from Pulse
|
|
56
|
+
Web or their local settings.
|
|
57
|
+
- If your local `MEMORY_HUB_FUNCTION_URL` differs from the default, set it on the environment too.
|
|
58
|
+
- Setup script:
|
|
59
|
+
```
|
|
60
|
+
claude plugin marketplace add Skedulo/se-ai-memory-hub
|
|
61
|
+
claude plugin install memory-hub@memory-hub
|
|
62
|
+
```
|
|
63
|
+
3. **Repos.** `memory_listRepos`; keep every name matching the repo pattern in step 2 below. The
|
|
64
|
+
command drops repos without hub items.
|
|
65
|
+
4. **Connectors.** From the `RemoteTrigger list` result, take the first `mcp_connections` entry named
|
|
66
|
+
`Linear`, `Atlassian`, `Google_Drive` or `Slack` across the developer's routines, and write them as
|
|
67
|
+
a JSON array to a temp file. If there are none, pass no file, and say the non-code refresh will
|
|
68
|
+
list sources as not refreshed until they add connectors on the routine page.
|
|
69
|
+
5. **User.** `git config user.email`, else the email in the memory-hub persona
|
|
70
|
+
(`memory_sessionContext`). If neither exists, stop and say why.
|
|
71
|
+
6. **Mode.** The argument after `schedule`, else the mode in the existing routine's prompt, else
|
|
72
|
+
`dry-run`.
|
|
73
|
+
7. Run `npx -y @skedulo/memory-hub-mcp@latest routine --mode <mode> --user <email> --environment
|
|
74
|
+
<env id> --repos <owner/name,...> [--connections-file <file>]`. It prints the routine JSON. Exit
|
|
75
|
+
code 2: relay the command's message and stop (bad arguments, unreadable connections file, or no
|
|
76
|
+
repo with hub items). Exit code 1: the token is missing. Remove the temp connections file on
|
|
77
|
+
every stop.
|
|
78
|
+
8. `RemoteTrigger create` with that JSON, or `update` the existing routine with the full body so
|
|
79
|
+
removed repos drop out. Remove the temp file.
|
|
80
|
+
9. Reply with the routine link, the next run time, the mode and the repo count only. Never echo the
|
|
81
|
+
token or the body.
|
|
82
|
+
|
|
42
83
|
## 1. Settle the mode and the date
|
|
43
84
|
|
|
44
|
-
Take the mode from the arguments (`dry-run` when none is given) and today's date, used as the reason
|
|
85
|
+
Take the mode from the arguments (`dry-run` when none is given; `schedule` goes to the section above) and today's date, used as the reason
|
|
45
86
|
"weekly sweep <date>" in every change-log line this run writes.
|
|
46
87
|
|
|
47
88
|
## 2. Find the repos
|
|
@@ -61,7 +102,15 @@ Take the mode from the arguments (`dry-run` when none is given) and today's date
|
|
|
61
102
|
|
|
62
103
|
For each swept repo, in turn:
|
|
63
104
|
|
|
64
|
-
1.
|
|
105
|
+
1. In a cloud routine the sources are already checked out, shallow, at `/home/user/<name>` (the
|
|
106
|
+
working directory or its parent). If one of them is `<owner/name>` (match `git remote get-url
|
|
107
|
+
origin`), use it as the clone; if `git rev-parse --is-shallow-repository` says `true`, run
|
|
108
|
+
`git fetch --unshallow`, and if that fails, list the repo as not swept, with the error. Then run
|
|
109
|
+
`git remote set-head origin --auto` (ignore a failure) and `git rev-parse --verify -q
|
|
110
|
+
origin/HEAD`; in `apply` mode, if that prints nothing, list the repo as not swept: no
|
|
111
|
+
`origin/HEAD` to stamp against. A repo with hub items that is not checked out in a cloud run is
|
|
112
|
+
not swept: list it as "not a source; re-run `schedule` to add it", not as a clone failure.
|
|
113
|
+
Otherwise clone it fresh, without blobs, so only the files a diff needs are fetched:
|
|
65
114
|
`rm -rf "${TMPDIR:-/tmp}/memory-hub-sweep/<owner>/<name>"`, then
|
|
66
115
|
`gh repo clone <owner/name> "${TMPDIR:-/tmp}/memory-hub-sweep/<owner>/<name>" -- --filter=blob:none`
|
|
67
116
|
(or `git clone --filter=blob:none` with the repo URL when `gh` is not available). If the clone
|
|
@@ -92,7 +141,7 @@ Take the items in order. Before reading anything, skip and list:
|
|
|
92
141
|
- `diffLines` over 300: flag it as too big to check here. For a project page, suggest "catch up the
|
|
93
142
|
<Project> knowledge with the code".
|
|
94
143
|
- `diffLines` of -1: the diff failed; flag it as not checked.
|
|
95
|
-
- `editedByOtherWithin7Days`: someone else is working on it;
|
|
144
|
+
- `editedByOtherWithin7Days`: someone else is working on it; never rewrite it. Count it as "already swept by a teammate" in the digest, not as waiting.
|
|
96
145
|
- `editable: false`: flag it (the "Stale memories" rule on edits you cannot make).
|
|
97
146
|
- tagged `Superseded`: a newer memory replaced it; report it, do not update it.
|
|
98
147
|
|
|
@@ -137,7 +186,7 @@ In `apply` mode, for each project that has `<Project> › Sources` on a swept re
|
|
|
137
186
|
(`memory_list type=Wiki repo=<repo uid> titlePrefix="<Project> › Sources"`), run the
|
|
138
187
|
project-knowledge skill as "the weekly sweep runs this skill", so it picks the sources-only refresh:
|
|
139
188
|
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
|
|
189
|
+
as waiting. A source whose connector tools are missing is listed as not refreshed, not as an error. Each refresh counts as one update against the cap; once the cap is reached, list the
|
|
141
190
|
remaining projects as not reached. In `dry-run` mode, list the projects it would refresh, counted
|
|
142
191
|
the same way.
|
|
143
192
|
|
|
@@ -156,8 +205,9 @@ One digest for the whole run, headed with the mode and the date:
|
|
|
156
205
|
1. Per repo: `target`, and the counts of unchanged, stamped, changed, updated, flagged, skipped,
|
|
157
206
|
not reached, nothing cited, unknown commit, other repo and errors. Repos not swept, with why.
|
|
158
207
|
2. Each update with its reason, by title (uid only when Private).
|
|
159
|
-
3. Flagged and skipped items with why: too big, diff failed,
|
|
160
|
-
|
|
208
|
+
3. Flagged and skipped items with why: too big, diff failed, not editable,
|
|
209
|
+
superseded, unclear after verifying, not reached. Items edited by someone else in the last 7
|
|
210
|
+
days are counted as already swept by a teammate.
|
|
161
211
|
4. Per project: what the targeted updates and sources-only refreshes changed, by page title and
|
|
162
212
|
entry ID, the core changes waiting ("run project-knowledge on <Project> to decide them"), and
|
|
163
213
|
anything "Worth a look", such as new modules.
|
|
@@ -167,4 +217,5 @@ One digest for the whole run, headed with the mode and the date:
|
|
|
167
217
|
|
|
168
218
|
## 8. Clean up
|
|
169
219
|
|
|
170
|
-
Remove the clones, even after a failure: `rm -rf "${TMPDIR:-/tmp}/memory-hub-sweep"`.
|
|
220
|
+
Remove the clones, even after a failure: `rm -rf "${TMPDIR:-/tmp}/memory-hub-sweep"`. Never remove
|
|
221
|
+
a repo that was already checked out.
|
package/dist/cli.js
CHANGED
|
@@ -72,6 +72,23 @@ else if (command === 'sweep') {
|
|
|
72
72
|
process.exitCode = 1;
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
else if (command === 'routine') {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
77
|
+
const { runRoutine } = require('./routine');
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
79
|
+
const { functionUrl } = require('./setup');
|
|
80
|
+
runRoutine(process.argv.slice(3), {
|
|
81
|
+
env: process.env,
|
|
82
|
+
log: (line) => console.log(line),
|
|
83
|
+
functionUrl,
|
|
84
|
+
timeZone: () => Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
85
|
+
}).then((code) => {
|
|
86
|
+
process.exitCode = code;
|
|
87
|
+
}, (error) => {
|
|
88
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
75
92
|
else if (command === 'migrate-plugin') {
|
|
76
93
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
77
94
|
const { runMigratePlugin } = require('./migrate-plugin');
|
|
@@ -110,6 +127,10 @@ else if (command === '--help' || command === '-h') {
|
|
|
110
127
|
they cite changed since their source commit, and print JSON.
|
|
111
128
|
Compares against the checkout's origin/HEAD and never fetches.
|
|
112
129
|
--stamp moves the source commit of unchanged items forward.
|
|
130
|
+
memory-hub-mcp routine --mode <dry-run|apply> --user <email> --environment <id> --repos <a/b,...>
|
|
131
|
+
print the JSON body of the weekly sweep cloud routine for those repos
|
|
132
|
+
(only repos with hub items), to create at claude.ai/code/routines.
|
|
133
|
+
[--connections-file <path>] adds connector entries.
|
|
113
134
|
memory-hub-mcp embed print the embedding of the text on stdin (or the arguments) as JSON;
|
|
114
135
|
used by the UserPromptSubmit hook. Exits non-zero if it cannot.
|
|
115
136
|
memory-hub-mcp run the MCP server on stdio (how a host launches it)
|
package/dist/routine.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runRoutine = exports.reposWithItems = exports.buildSweepRoutine = exports.sweepPrompt = exports.staggerMinute = exports.ROUTINE_USAGE = exports.ROUTINE_NAME = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
const sweep_1 = require("./sweep");
|
|
8
|
+
exports.ROUTINE_NAME = 'Memory hub weekly sweep';
|
|
9
|
+
exports.ROUTINE_USAGE = 'memory-hub-mcp routine --mode <dry-run|apply> --user <email> --environment <id> --repos <owner/name,...> [--connections-file <path>]';
|
|
10
|
+
const HUB_REPO = 'Skedulo/se-ai-memory-hub';
|
|
11
|
+
const TYPES = ['Fact', 'Skill', 'Scenario', 'Wiki'];
|
|
12
|
+
const ALLOWED_TOOLS = ['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep', 'Skill'];
|
|
13
|
+
function staggerMinute(user) {
|
|
14
|
+
const digest = (0, crypto_1.createHash)('sha256').update(user.trim().toLowerCase()).digest();
|
|
15
|
+
return digest.readUInt32BE(0) % 60;
|
|
16
|
+
}
|
|
17
|
+
exports.staggerMinute = staggerMinute;
|
|
18
|
+
function sweepPrompt(mode, repos) {
|
|
19
|
+
const args = [mode, ...repos.map((repo) => repo.trim())].join(' ');
|
|
20
|
+
return `Run \`/memory-hub:sweep-knowledge ${args}\`. The repos to sweep are already checked out in the working directory. There is nobody to ask: never ask a question, and report anything that needs an answer in the digest.`;
|
|
21
|
+
}
|
|
22
|
+
exports.sweepPrompt = sweepPrompt;
|
|
23
|
+
function buildSweepRoutine(input) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
const sources = [];
|
|
26
|
+
for (const repo of [HUB_REPO, ...input.repos]) {
|
|
27
|
+
const key = repo.trim().toLowerCase();
|
|
28
|
+
if (seen.has(key))
|
|
29
|
+
continue;
|
|
30
|
+
seen.add(key);
|
|
31
|
+
sources.push({ git_repository: { url: `https://github.com/${repo.trim()}` } });
|
|
32
|
+
}
|
|
33
|
+
const swept = input.repos.filter((repo, i) => input.repos.findIndex((r) => r.trim().toLowerCase() === repo.trim().toLowerCase()) === i);
|
|
34
|
+
return {
|
|
35
|
+
name: exports.ROUTINE_NAME,
|
|
36
|
+
cron_expression: `CRON_TZ=${input.timeZone} ${staggerMinute(input.user)} 7 * * 1`,
|
|
37
|
+
enabled: true,
|
|
38
|
+
mcp_connections: input.connections ?? [],
|
|
39
|
+
job_config: {
|
|
40
|
+
ccr: {
|
|
41
|
+
environment_id: input.environmentId,
|
|
42
|
+
session_context: { allowed_tools: ALLOWED_TOOLS, sources },
|
|
43
|
+
events: [
|
|
44
|
+
{
|
|
45
|
+
data: {
|
|
46
|
+
type: 'user',
|
|
47
|
+
uuid: (0, crypto_1.randomUUID)(),
|
|
48
|
+
session_id: '',
|
|
49
|
+
parent_tool_use_id: null,
|
|
50
|
+
message: { role: 'user', content: sweepPrompt(input.mode, swept) },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.buildSweepRoutine = buildSweepRoutine;
|
|
59
|
+
async function reposWithItems(client, repos) {
|
|
60
|
+
const kept = [];
|
|
61
|
+
for (const repo of repos) {
|
|
62
|
+
for (const type of TYPES) {
|
|
63
|
+
const page = await client.listResources({ type, sourceRepo: repo, offset: 0, limit: 1 });
|
|
64
|
+
if (page.total > 0) {
|
|
65
|
+
kept.push(repo);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return kept;
|
|
71
|
+
}
|
|
72
|
+
exports.reposWithItems = reposWithItems;
|
|
73
|
+
function option(argv, name) {
|
|
74
|
+
const index = argv.indexOf(`--${name}`);
|
|
75
|
+
const value = index >= 0 ? argv[index + 1] : undefined;
|
|
76
|
+
return value && !value.startsWith('--') ? value : undefined;
|
|
77
|
+
}
|
|
78
|
+
async function runRoutine(argv, deps) {
|
|
79
|
+
const mode = option(argv, 'mode');
|
|
80
|
+
const user = option(argv, 'user');
|
|
81
|
+
const environmentId = option(argv, 'environment');
|
|
82
|
+
const reposIndex = argv.indexOf('--repos');
|
|
83
|
+
const reposArg = reposIndex >= 0 ? (argv[reposIndex + 1] ?? '') : undefined;
|
|
84
|
+
if (mode !== 'dry-run' && mode !== 'apply') {
|
|
85
|
+
deps.log(`--mode must be dry-run or apply.\n${exports.ROUTINE_USAGE}`);
|
|
86
|
+
return 2;
|
|
87
|
+
}
|
|
88
|
+
if (!user || !environmentId || reposArg === undefined) {
|
|
89
|
+
deps.log(`--user, --environment and --repos are required.\n${exports.ROUTINE_USAGE}`);
|
|
90
|
+
return 2;
|
|
91
|
+
}
|
|
92
|
+
const repos = reposArg
|
|
93
|
+
.split(',')
|
|
94
|
+
.map((repo) => repo.trim())
|
|
95
|
+
.filter(Boolean);
|
|
96
|
+
if (repos.length === 0) {
|
|
97
|
+
deps.log(`--repos needs at least one owner/name.\n${exports.ROUTINE_USAGE}`);
|
|
98
|
+
return 2;
|
|
99
|
+
}
|
|
100
|
+
const bad = repos.find((repo) => !sweep_1.REPO_NAME.test(repo));
|
|
101
|
+
if (bad) {
|
|
102
|
+
deps.log(`--repos must be owner/name entries, got "${bad}".\n${exports.ROUTINE_USAGE}`);
|
|
103
|
+
return 2;
|
|
104
|
+
}
|
|
105
|
+
let connections;
|
|
106
|
+
const connectionsFile = option(argv, 'connections-file');
|
|
107
|
+
if (connectionsFile) {
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse((0, fs_1.readFileSync)(connectionsFile, 'utf8'));
|
|
110
|
+
if (!Array.isArray(parsed))
|
|
111
|
+
throw new Error('not a JSON array');
|
|
112
|
+
connections = parsed;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
deps.log(`Cannot read --connections-file ${connectionsFile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
return 2;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const apiToken = deps.env.MEMORY_HUB_MCP_TOKEN;
|
|
120
|
+
if (!apiToken) {
|
|
121
|
+
deps.log('MEMORY_HUB_MCP_TOKEN is not set. Run `npx -y @skedulo/memory-hub-mcp setup` first.');
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
const baseUrl = deps.env.MEMORY_HUB_FUNCTION_URL || deps.functionUrl();
|
|
125
|
+
const client = (deps.makeClient ?? ((config) => new client_1.MemoryHubClient(config)))({ baseUrl, apiToken });
|
|
126
|
+
const candidates = repos.filter((repo) => repo.toLowerCase() !== HUB_REPO.toLowerCase());
|
|
127
|
+
const withItems = await reposWithItems(client, candidates);
|
|
128
|
+
if (withItems.length === 0) {
|
|
129
|
+
deps.log('None of the repos has items in the hub, so there is nothing to sweep.');
|
|
130
|
+
return 2;
|
|
131
|
+
}
|
|
132
|
+
const body = buildSweepRoutine({ mode, timeZone: deps.timeZone() || 'UTC', user, repos: withItems, environmentId, connections });
|
|
133
|
+
deps.log(JSON.stringify(body, null, 2));
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
exports.runRoutine = runRoutine;
|
package/package.json
CHANGED