@skedulo/memory-hub-mcp 0.2.32 → 0.2.34
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/session-start.sh +140 -3
- package/assets/session-stop.sh +206 -17
- package/assets/skills/ask/SKILL.md +32 -6
- package/assets/skills/ask/references/qa.md +1 -0
- package/assets/skills/delegate-ticket/SKILL.md +5 -0
- package/assets/skills/fold-findings/SKILL.md +36 -5
- package/assets/skills/memory-hub/SKILL.md +2 -2
- package/assets/skills/plan-ticket/SKILL.md +36 -13
- package/assets/skills/project-knowledge/SKILL.md +6 -5
- package/assets/skills/project-knowledge/references/create-refresh.md +52 -5
- package/assets/skills/project-knowledge/references/page-format.md +6 -0
- package/assets/skills/project-knowledge/references/touch.md +4 -1
- package/assets/skills/sweep-knowledge/SKILL.md +253 -23
- package/assets/skills/test-scripts/SKILL.md +309 -0
- package/assets/skills/{plan-ticket/references/test-scripts.md → test-scripts/references/format.md} +63 -28
- package/assets/uninstall-memory-hub.sh +1 -1
- package/assets/user-prompt-submit.sh +53 -8
- package/dist/bulk.js +25 -8
- package/dist/change-tools.js +71 -0
- package/dist/check-tools.js +348 -0
- package/dist/cli.js +37 -1
- package/dist/client.js +27 -0
- package/dist/coverage.js +469 -0
- package/dist/git-remote.js +2 -0
- package/dist/import-apply.js +3 -2
- package/dist/index.js +42 -4
- package/dist/item-targets.js +304 -0
- package/dist/near-copy.js +85 -21
- package/dist/pack-import.js +1 -0
- package/dist/routine.js +15 -3
- package/dist/save.js +53 -3
- package/dist/session-context.js +12 -3
- package/dist/similar-notice.js +27 -9
- package/dist/sweep.js +71 -5
- package/dist/watch.js +570 -0
- package/package.json +1 -1
- package/skill-guide.md +157 -31
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCoverage = exports.buildReport = exports.groupUncovered = exports.mapPathRegex = exports.parseFeatureMap = exports.parseAliases = exports.isCodeFile = exports.pathMatches = exports.globRegex = exports.COVERAGE_USAGE = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const client_1 = require("./client");
|
|
7
|
+
const credentials_1 = require("./credentials");
|
|
8
|
+
exports.COVERAGE_USAGE = 'memory-hub-mcp coverage (--project <name> | --map <file>...) --checkout <owner/name>=<path> [--checkout ...] [--ref [<owner/name>=]<ref>] [--exclude <glob>] [--full]';
|
|
9
|
+
const MAX_FOLDERS = 40;
|
|
10
|
+
const MAX_SAMPLE = 3;
|
|
11
|
+
const MAX_LOOSE = 10;
|
|
12
|
+
const MAX_LIST = 60;
|
|
13
|
+
const BRIEF_MIN_FILES = 3;
|
|
14
|
+
const BRIEF_UNRESOLVED = 20;
|
|
15
|
+
const BRIEF_OVERLAPS = 5;
|
|
16
|
+
const REF_CANDIDATES = ['origin/HEAD', 'origin/main', 'origin/master', 'HEAD'];
|
|
17
|
+
const FEATURE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
18
|
+
const REPO_TOKEN = /^([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)(?:@([0-9a-f]{7,40}))?$/i;
|
|
19
|
+
const CODE_EXTENSIONS = new Set([
|
|
20
|
+
'ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'vue', 'py', 'cls', 'trigger', 'apex', 'json', 'njk', 'html',
|
|
21
|
+
'gql', 'graphql', 'page', 'component', 'cmp', 'xml',
|
|
22
|
+
]);
|
|
23
|
+
const EXCLUDED_DIRS = new Set([
|
|
24
|
+
'node_modules', 'dist', 'build', 'out', 'coverage', '.next', '.sfdx', '.sf', '.git', '.github', '.husky',
|
|
25
|
+
'.vscode', '.changeset', '__tests__', '__mocks__', '__generated__', 'generated', '__graphql', 'vendor',
|
|
26
|
+
'third_party', 'profiles', 'permissionsets', 'layouts', 'reports', 'reportTypes', 'dashboards',
|
|
27
|
+
'translations', 'objectTranslations', 'staticresources', 'settings',
|
|
28
|
+
]);
|
|
29
|
+
const EXCLUDED_FILES = [
|
|
30
|
+
'*.test.*', '*.spec.*', '*.d.ts', '*.min.js', '*.map', '*.lock', 'package.json', 'package-lock.json',
|
|
31
|
+
'tsconfig*.json', 'jest.config.*', 'babel.config.*', 'eslint.config.*', '.eslintrc*', '.prettierrc*',
|
|
32
|
+
'vite.config.*', 'webpack.config.*', 'rollup.config.*', '*.cls-meta.xml', '*.trigger-meta.xml',
|
|
33
|
+
].map((glob) => globRegex(glob));
|
|
34
|
+
function escapeRegex(text) {
|
|
35
|
+
return text.replace(/[.+^$()|[\]\\]/g, '\\$&');
|
|
36
|
+
}
|
|
37
|
+
function globBody(glob) {
|
|
38
|
+
let out = '';
|
|
39
|
+
for (let i = 0; i < glob.length; i++) {
|
|
40
|
+
const ch = glob[i];
|
|
41
|
+
if (ch === '*' && glob[i + 1] === '*') {
|
|
42
|
+
if (glob[i + 2] === '/') {
|
|
43
|
+
out += '(?:.*/)?';
|
|
44
|
+
i += 2;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
out += '.*';
|
|
48
|
+
i += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (ch === '*') {
|
|
52
|
+
out += '[^/]*';
|
|
53
|
+
}
|
|
54
|
+
else if (ch === '?') {
|
|
55
|
+
out += '[^/]';
|
|
56
|
+
}
|
|
57
|
+
else if (ch === '{') {
|
|
58
|
+
const end = glob.indexOf('}', i);
|
|
59
|
+
if (end < 0) {
|
|
60
|
+
out += '\\{';
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
out += `(?:${glob.slice(i + 1, end).split(',').map(globBody).join('|')})`;
|
|
64
|
+
i = end;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
out += escapeRegex(ch);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function globRegex(glob) {
|
|
73
|
+
return new RegExp(`^${globBody(glob.replace(/^\.\//, '').replace(/\/+$/, ''))}$`);
|
|
74
|
+
}
|
|
75
|
+
exports.globRegex = globRegex;
|
|
76
|
+
function ancestorsAndSelf(path) {
|
|
77
|
+
const parts = path.split('/');
|
|
78
|
+
return parts.map((_, i) => parts.slice(0, i + 1).join('/'));
|
|
79
|
+
}
|
|
80
|
+
function pathMatches(pattern, file) {
|
|
81
|
+
return ancestorsAndSelf(file).some((candidate) => pattern.test(candidate));
|
|
82
|
+
}
|
|
83
|
+
exports.pathMatches = pathMatches;
|
|
84
|
+
function isCodeFile(file, extraExcludes = []) {
|
|
85
|
+
const parts = file.split('/');
|
|
86
|
+
const name = parts[parts.length - 1];
|
|
87
|
+
const dot = name.lastIndexOf('.');
|
|
88
|
+
if (dot < 0 || !CODE_EXTENSIONS.has(name.slice(dot + 1).toLowerCase()))
|
|
89
|
+
return false;
|
|
90
|
+
if (parts.slice(0, -1).some((dir) => EXCLUDED_DIRS.has(dir)))
|
|
91
|
+
return false;
|
|
92
|
+
if (EXCLUDED_FILES.some((re) => re.test(name)))
|
|
93
|
+
return false;
|
|
94
|
+
return !extraExcludes.some((re) => pathMatches(re, file));
|
|
95
|
+
}
|
|
96
|
+
exports.isCodeFile = isCodeFile;
|
|
97
|
+
function stripRemarks(text) {
|
|
98
|
+
let out = '';
|
|
99
|
+
let depth = 0;
|
|
100
|
+
for (const ch of text.replace(/`/g, '')) {
|
|
101
|
+
if (ch === '(')
|
|
102
|
+
depth++;
|
|
103
|
+
else if (ch === ')' && depth > 0)
|
|
104
|
+
depth--;
|
|
105
|
+
else if (depth === 0)
|
|
106
|
+
out += ch;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function splitOutsideBraces(text, separators) {
|
|
111
|
+
const parts = [];
|
|
112
|
+
let depth = 0;
|
|
113
|
+
let current = '';
|
|
114
|
+
for (const ch of text) {
|
|
115
|
+
if (ch === '{')
|
|
116
|
+
depth++;
|
|
117
|
+
if (ch === '}' && depth > 0)
|
|
118
|
+
depth--;
|
|
119
|
+
if (depth === 0 && separators.includes(ch)) {
|
|
120
|
+
parts.push(current);
|
|
121
|
+
current = '';
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
current += ch;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
parts.push(current);
|
|
128
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
129
|
+
}
|
|
130
|
+
const looksLikePath = (word) => /[/*.]/.test(word);
|
|
131
|
+
function joinPath(prefix, rest) {
|
|
132
|
+
if (!prefix)
|
|
133
|
+
return rest;
|
|
134
|
+
if (!rest)
|
|
135
|
+
return prefix.replace(/\/+$/, '');
|
|
136
|
+
return `${prefix.replace(/\/+$/, '')}/${rest.replace(/^\/+/, '')}`;
|
|
137
|
+
}
|
|
138
|
+
function parseAliases(line, aliases) {
|
|
139
|
+
for (const part of stripRemarks(line).split(/[,;]|\.\s/)) {
|
|
140
|
+
const def = /^\s*([A-Za-z][\w-]*)\s*=\s*(.+?)\s*\.?\s*$/.exec(part);
|
|
141
|
+
if (!def)
|
|
142
|
+
continue;
|
|
143
|
+
const [first, second = ''] = def[2].split(/\s+/);
|
|
144
|
+
const repo = REPO_TOKEN.exec(first);
|
|
145
|
+
const base = aliases.get(first);
|
|
146
|
+
if (repo)
|
|
147
|
+
aliases.set(def[1], { repo: repo[1], prefix: looksLikePath(second) ? second : '' });
|
|
148
|
+
else if (base && second)
|
|
149
|
+
aliases.set(def[1], { repo: base.repo, prefix: joinPath(base.prefix, second) });
|
|
150
|
+
else if (first.includes('/'))
|
|
151
|
+
aliases.set(def[1], { prefix: first });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.parseAliases = parseAliases;
|
|
155
|
+
function parseFeatureMap(texts, checkedOut, defaultRepo) {
|
|
156
|
+
const known = new Map(checkedOut.map((repo) => [repo.toLowerCase(), repo]));
|
|
157
|
+
const parsed = { features: [], withCodeLine: new Set(), paths: [], unresolved: [], notCheckedOut: [] };
|
|
158
|
+
const aliases = new Map();
|
|
159
|
+
let feature;
|
|
160
|
+
const resolveRepo = (name, at) => {
|
|
161
|
+
const named = known.get(name.toLowerCase());
|
|
162
|
+
if (!named)
|
|
163
|
+
parsed.notCheckedOut.push({ feature: at, repo: name });
|
|
164
|
+
return named;
|
|
165
|
+
};
|
|
166
|
+
for (const text of texts) {
|
|
167
|
+
let beforeFirstHeading = true;
|
|
168
|
+
for (const line of text.split('\n')) {
|
|
169
|
+
const heading = /^##\s+(.+?)\s*$/.exec(line);
|
|
170
|
+
if (heading) {
|
|
171
|
+
beforeFirstHeading = false;
|
|
172
|
+
const key = heading[1].replace(/\s+\(continued\)$/i, '');
|
|
173
|
+
feature = FEATURE_KEY.test(key) ? key : undefined;
|
|
174
|
+
if (feature && !parsed.features.includes(feature))
|
|
175
|
+
parsed.features.push(feature);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const code = /^\s*-\s*Code:\s*(.*)$/.exec(line);
|
|
179
|
+
if (!code) {
|
|
180
|
+
if (beforeFirstHeading)
|
|
181
|
+
parseAliases(line.replace(/`/g, ''), aliases);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!feature)
|
|
185
|
+
continue;
|
|
186
|
+
const at = feature;
|
|
187
|
+
parsed.withCodeLine.add(at);
|
|
188
|
+
for (const segment of splitOutsideBraces(stripRemarks(code[1]), '·')) {
|
|
189
|
+
let repo = defaultRepo;
|
|
190
|
+
let entries = splitOutsideBraces(segment, ',;');
|
|
191
|
+
const firstWords = (entries[0] ?? '').split(/\s+/);
|
|
192
|
+
const repoMatch = REPO_TOKEN.exec(firstWords[0]);
|
|
193
|
+
if (repoMatch && (known.has(repoMatch[1].toLowerCase()) || repoMatch[2] || firstWords.length > 1)) {
|
|
194
|
+
repo = resolveRepo(repoMatch[1], at);
|
|
195
|
+
if (!repo)
|
|
196
|
+
continue;
|
|
197
|
+
entries = [firstWords.slice(1).join(' '), ...entries.slice(1)].filter(Boolean);
|
|
198
|
+
}
|
|
199
|
+
for (const entry of entries) {
|
|
200
|
+
const words = entry.split(/\s+/);
|
|
201
|
+
const alias = aliases.get(words[0]);
|
|
202
|
+
if (alias) {
|
|
203
|
+
const aliasRepo = alias.repo ? resolveRepo(alias.repo, at) : repo;
|
|
204
|
+
if (aliasRepo)
|
|
205
|
+
parsed.paths.push({ feature: at, repo: aliasRepo, path: joinPath(alias.prefix, words[1] ?? '') || '**' });
|
|
206
|
+
}
|
|
207
|
+
else if (words.length === 1 || looksLikePath(words[0])) {
|
|
208
|
+
parsed.paths.push({ feature: at, repo, path: words[0] });
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
parsed.unresolved.push({ feature: at, text: entry });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return parsed;
|
|
218
|
+
}
|
|
219
|
+
exports.parseFeatureMap = parseFeatureMap;
|
|
220
|
+
function mapPathRegex(path) {
|
|
221
|
+
const clean = path.replace(/^\.\//, '').replace(/\/+$/, '');
|
|
222
|
+
const last = clean.split('/').pop() ?? '';
|
|
223
|
+
return new RegExp(`^${globBody(clean)}${last.includes('.') ? '' : '(?:\\.[^/]+)?'}$`);
|
|
224
|
+
}
|
|
225
|
+
exports.mapPathRegex = mapPathRegex;
|
|
226
|
+
const VENDOR_FOLDER = /^(vendors?|third[-_]party|externals?|bower_components)$/i;
|
|
227
|
+
const LIB_FOLDER = /^libs?$/i;
|
|
228
|
+
function suggestFor(path, files) {
|
|
229
|
+
const last = path.split('/').pop() ?? '';
|
|
230
|
+
if (/[*{?]/.test(last) || !/\.[A-Za-z0-9]+$/.test(last))
|
|
231
|
+
return [];
|
|
232
|
+
return files.filter((file) => file.endsWith(`/${last}`) || file === last).slice(0, 3);
|
|
233
|
+
}
|
|
234
|
+
function groupUncovered(uncovered, covered, tracked = [], full = false) {
|
|
235
|
+
const coveredDirs = new Set();
|
|
236
|
+
for (const file of covered)
|
|
237
|
+
ancestorsAndSelf(file).slice(0, -1).forEach((dir) => coveredDirs.add(dir));
|
|
238
|
+
const groups = new Map();
|
|
239
|
+
for (const file of uncovered) {
|
|
240
|
+
const dirs = ancestorsAndSelf(file).slice(0, -1);
|
|
241
|
+
const top = dirs.find((dir) => !coveredDirs.has(dir));
|
|
242
|
+
const folder = top ?? (dirs.length ? dirs[dirs.length - 1] : '.');
|
|
243
|
+
const group = groups.get(folder) ?? { files: [], whole: top !== undefined };
|
|
244
|
+
group.files.push(file);
|
|
245
|
+
groups.set(folder, group);
|
|
246
|
+
}
|
|
247
|
+
const vendored = [];
|
|
248
|
+
for (const [folder, g] of groups) {
|
|
249
|
+
if (g.whole && isVendored(folder, tracked)) {
|
|
250
|
+
vendored.push({ folder, files: g.files.length });
|
|
251
|
+
groups.delete(folder);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const minFiles = full ? 1 : BRIEF_MIN_FILES;
|
|
255
|
+
const sorted = [...groups.entries()].sort((a, b) => b[1].files.length - a[1].files.length || a[0].localeCompare(b[0]));
|
|
256
|
+
const shown = sorted.filter(([, g]) => g.files.length >= minFiles).slice(0, MAX_FOLDERS);
|
|
257
|
+
const hidden = sorted.filter((entry) => !shown.includes(entry));
|
|
258
|
+
return {
|
|
259
|
+
count: sorted.reduce((n, [, g]) => n + g.files.length, 0),
|
|
260
|
+
folders: shown.map(([folder, g]) => {
|
|
261
|
+
const out = { folder, files: g.files.length };
|
|
262
|
+
if (!g.whole) {
|
|
263
|
+
out.whole = false;
|
|
264
|
+
out.loose = g.files.slice(0, MAX_LOOSE);
|
|
265
|
+
}
|
|
266
|
+
if (full && g.whole)
|
|
267
|
+
out.sample = g.files.slice(0, MAX_SAMPLE);
|
|
268
|
+
return out;
|
|
269
|
+
}),
|
|
270
|
+
notListed: { folders: hidden.length, files: hidden.reduce((n, [, g]) => n + g.files.length, 0) },
|
|
271
|
+
vendored,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
exports.groupUncovered = groupUncovered;
|
|
275
|
+
function isVendored(folder, tracked) {
|
|
276
|
+
const parts = folder.split('/');
|
|
277
|
+
if (parts.some((part) => VENDOR_FOLDER.test(part)))
|
|
278
|
+
return true;
|
|
279
|
+
const prefix = `${folder}/`;
|
|
280
|
+
const inside = tracked.filter((file) => file.startsWith(prefix));
|
|
281
|
+
if (inside.some((file) => /\.min\.js$/.test(file)))
|
|
282
|
+
return true;
|
|
283
|
+
return LIB_FOLDER.test(parts[parts.length - 1]) && inside.some((file) => file.endsWith('/package.json'));
|
|
284
|
+
}
|
|
285
|
+
function buildReport(parsed, repos, options = {}) {
|
|
286
|
+
const { full = false, extraExcludes = [] } = options;
|
|
287
|
+
const compiled = parsed.paths.map((p, index) => ({ ...p, index, re: mapPathRegex(p.path) }));
|
|
288
|
+
const matchedAny = new Set();
|
|
289
|
+
const featureHasFiles = new Set();
|
|
290
|
+
const overlapCount = new Map();
|
|
291
|
+
const reports = [];
|
|
292
|
+
for (const { repo, ref, commit, files } of repos) {
|
|
293
|
+
const patterns = compiled.filter((p) => p.repo === repo);
|
|
294
|
+
const covered = [];
|
|
295
|
+
const uncovered = [];
|
|
296
|
+
let codeFiles = 0;
|
|
297
|
+
for (const file of files) {
|
|
298
|
+
const owners = new Set();
|
|
299
|
+
for (const p of patterns) {
|
|
300
|
+
if (pathMatches(p.re, file)) {
|
|
301
|
+
owners.add(p.feature);
|
|
302
|
+
matchedAny.add(p.index);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (!isCodeFile(file, extraExcludes))
|
|
306
|
+
continue;
|
|
307
|
+
codeFiles++;
|
|
308
|
+
owners.forEach((f) => featureHasFiles.add(f));
|
|
309
|
+
if (owners.size === 0) {
|
|
310
|
+
uncovered.push(file);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
covered.push(file);
|
|
314
|
+
const list = [...owners].sort();
|
|
315
|
+
for (let i = 0; i < list.length; i++) {
|
|
316
|
+
for (let j = i + 1; j < list.length; j++) {
|
|
317
|
+
const key = `${repo}\u0000${list[i]}\u0000${list[j]}`;
|
|
318
|
+
const entry = overlapCount.get(key) ?? { files: [], repo, features: [list[i], list[j]] };
|
|
319
|
+
entry.files.push(file);
|
|
320
|
+
overlapCount.set(key, entry);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const { vendored, ...rest } = groupUncovered(uncovered, covered, files, full);
|
|
325
|
+
const vendoredFiles = vendored.reduce((n, v) => n + v.files, 0);
|
|
326
|
+
const report = { repo, ref, commit, codeFiles: codeFiles - vendoredFiles, covered: covered.length, uncovered: rest };
|
|
327
|
+
if (vendored.length)
|
|
328
|
+
report.vendored = vendored;
|
|
329
|
+
reports.push(report);
|
|
330
|
+
}
|
|
331
|
+
const checked = new Set(repos.map((r) => r.repo));
|
|
332
|
+
const filesOf = new Map(repos.map((r) => [r.repo, r.files]));
|
|
333
|
+
const overlaps = [...overlapCount.values()].sort((a, b) => b.files.length - a.files.length);
|
|
334
|
+
const notCheckedOut = new Map();
|
|
335
|
+
for (const { repo, feature } of parsed.notCheckedOut)
|
|
336
|
+
notCheckedOut.set(repo, (notCheckedOut.get(repo) ?? new Set()).add(feature));
|
|
337
|
+
return {
|
|
338
|
+
repos: reports,
|
|
339
|
+
featuresWithoutCode: parsed.features
|
|
340
|
+
.filter((f) => !featureHasFiles.has(f))
|
|
341
|
+
.filter((f) => !parsed.withCodeLine.has(f) || parsed.paths.some((p) => p.feature === f && checked.has(p.repo)))
|
|
342
|
+
.map((feature) => ({ feature, reason: parsed.withCodeLine.has(feature) ? 'paths match nothing' : 'no Code line' })),
|
|
343
|
+
pathsMatchingNothing: parsed.paths
|
|
344
|
+
.filter((p, index) => checked.has(p.repo) && !matchedAny.has(index))
|
|
345
|
+
.slice(0, MAX_LIST)
|
|
346
|
+
.map((p) => {
|
|
347
|
+
const suggest = suggestFor(p.path, filesOf.get(p.repo) ?? []);
|
|
348
|
+
return suggest.length ? { ...p, suggest } : p;
|
|
349
|
+
}),
|
|
350
|
+
unresolved: { total: parsed.unresolved.length, items: parsed.unresolved.slice(0, full ? MAX_LIST : BRIEF_UNRESOLVED) },
|
|
351
|
+
notCheckedOut: [...notCheckedOut.entries()].map(([repo, features]) => ({ repo, features: features.size })),
|
|
352
|
+
overlaps: {
|
|
353
|
+
total: overlaps.length,
|
|
354
|
+
items: overlaps.slice(0, full ? MAX_LIST : BRIEF_OVERLAPS).map((o) => {
|
|
355
|
+
const item = { features: o.features, repo: o.repo, files: o.files.length };
|
|
356
|
+
if (full)
|
|
357
|
+
item.sample = o.files.slice(0, MAX_SAMPLE);
|
|
358
|
+
return item;
|
|
359
|
+
}),
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
exports.buildReport = buildReport;
|
|
364
|
+
const execRepoGit = (checkout, args) => new Promise((resolve, reject) => {
|
|
365
|
+
(0, child_process_1.execFile)('git', ['-C', checkout, ...args], { encoding: 'utf8', timeout: 60_000, maxBuffer: 256 * 1024 * 1024 }, (err, stdout) => err ? reject(err) : resolve(stdout));
|
|
366
|
+
});
|
|
367
|
+
async function resolveRef(git, checkout, ref) {
|
|
368
|
+
for (const candidate of ref ? [ref] : REF_CANDIDATES) {
|
|
369
|
+
try {
|
|
370
|
+
const commit = (await git(checkout, ['rev-parse', '--verify', '--quiet', `${candidate}^{commit}`])).trim();
|
|
371
|
+
if (commit)
|
|
372
|
+
return { ref: candidate, commit };
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
throw new Error(`no ${ref ?? 'default branch'} found in ${checkout}`);
|
|
379
|
+
}
|
|
380
|
+
class UsageError extends Error {
|
|
381
|
+
}
|
|
382
|
+
const VALUE_FLAGS = ['--map', '--project', '--checkout', '--ref', '--exclude'];
|
|
383
|
+
function parseArgs(argv) {
|
|
384
|
+
const args = { maps: [], checkouts: [], refs: new Map(), excludes: [], full: false };
|
|
385
|
+
for (let i = 0; i < argv.length; i++) {
|
|
386
|
+
const flag = argv[i];
|
|
387
|
+
if (flag === '--full') {
|
|
388
|
+
args.full = true;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const value = argv[i + 1];
|
|
392
|
+
if (!VALUE_FLAGS.includes(flag))
|
|
393
|
+
throw new UsageError(`Unknown argument "${flag}".`);
|
|
394
|
+
if (value === undefined || value.startsWith('--'))
|
|
395
|
+
throw new UsageError(`${flag} needs a value.`);
|
|
396
|
+
i++;
|
|
397
|
+
if (flag === '--map')
|
|
398
|
+
args.maps.push(value);
|
|
399
|
+
if (flag === '--project')
|
|
400
|
+
args.project = value;
|
|
401
|
+
if (flag === '--exclude')
|
|
402
|
+
args.excludes.push(value);
|
|
403
|
+
if (flag === '--checkout') {
|
|
404
|
+
const eq = value.indexOf('=');
|
|
405
|
+
if (eq < 0 || !REPO_TOKEN.test(value.slice(0, eq)))
|
|
406
|
+
throw new UsageError(`--checkout takes <owner/name>=<path>, got "${value}".`);
|
|
407
|
+
args.checkouts.push({ repo: value.slice(0, eq), path: value.slice(eq + 1) });
|
|
408
|
+
}
|
|
409
|
+
if (flag === '--ref') {
|
|
410
|
+
const eq = value.indexOf('=');
|
|
411
|
+
if (eq > 0 && REPO_TOKEN.test(value.slice(0, eq)))
|
|
412
|
+
args.refs.set(value.slice(0, eq).toLowerCase(), value.slice(eq + 1));
|
|
413
|
+
else
|
|
414
|
+
args.defaultRef = value;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if ((!args.maps.length && !args.project) || !args.checkouts.length)
|
|
418
|
+
throw new UsageError('--map or --project, and --checkout, are required.');
|
|
419
|
+
return args;
|
|
420
|
+
}
|
|
421
|
+
async function loadProjectMaps(project, deps) {
|
|
422
|
+
const client = deps.makeClient ? deps.makeClient() : defaultClient();
|
|
423
|
+
const titlePrefix = `${project} › Reference › feature-map`;
|
|
424
|
+
const listed = await client.listResources({ type: 'Wiki', scope: 'all', titlePrefix, limit: 50 });
|
|
425
|
+
const pages = listed.items.filter((item) => item.title === titlePrefix || item.title.startsWith(`${titlePrefix} (`)).sort((a, b) => a.title.localeCompare(b.title));
|
|
426
|
+
if (!pages.length)
|
|
427
|
+
throw new Error(`no "${titlePrefix}" page in the hub`);
|
|
428
|
+
const texts = [];
|
|
429
|
+
for (const page of pages)
|
|
430
|
+
texts.push((await client.getWikiPage({ uid: page.uid })).content);
|
|
431
|
+
return texts;
|
|
432
|
+
}
|
|
433
|
+
function defaultClient() {
|
|
434
|
+
const creds = (0, credentials_1.resolveCredentials)(process.env);
|
|
435
|
+
if (!creds)
|
|
436
|
+
throw new Error('not signed in to Memory Hub; run `npx -y @skedulo/memory-hub-mcp@latest login`');
|
|
437
|
+
return new client_1.MemoryHubClient({ baseUrl: (0, credentials_1.resolveFunctionUrl)(process.env, creds), apiToken: creds.token });
|
|
438
|
+
}
|
|
439
|
+
async function runCoverage(argv, deps) {
|
|
440
|
+
let args;
|
|
441
|
+
try {
|
|
442
|
+
args = parseArgs(argv);
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
if (!(error instanceof UsageError))
|
|
446
|
+
throw error;
|
|
447
|
+
deps.log(`${error.message}\nUsage: ${exports.COVERAGE_USAGE}`);
|
|
448
|
+
return 2;
|
|
449
|
+
}
|
|
450
|
+
const git = deps.git ?? execRepoGit;
|
|
451
|
+
const readFile = deps.readFile ?? ((path) => (0, fs_1.readFileSync)(path, 'utf8'));
|
|
452
|
+
try {
|
|
453
|
+
const texts = [...(args.project ? await loadProjectMaps(args.project, deps) : []), ...args.maps.map((m) => readFile(m))];
|
|
454
|
+
const parsed = parseFeatureMap(texts, args.checkouts.map((c) => c.repo), args.checkouts[0].repo);
|
|
455
|
+
const repos = [];
|
|
456
|
+
for (const { repo, path } of args.checkouts) {
|
|
457
|
+
const { ref, commit } = await resolveRef(git, path, args.refs.get(repo.toLowerCase()) ?? args.defaultRef);
|
|
458
|
+
const files = (await git(path, ['ls-tree', '-r', '--name-only', commit])).split('\n').filter(Boolean);
|
|
459
|
+
repos.push({ repo, ref, commit, files });
|
|
460
|
+
}
|
|
461
|
+
deps.log(JSON.stringify(buildReport(parsed, repos, { full: args.full, extraExcludes: args.excludes.map(globRegex) })));
|
|
462
|
+
return 0;
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
deps.log(`coverage failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
466
|
+
return 1;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
exports.runCoverage = runCoverage;
|
package/dist/git-remote.js
CHANGED
|
@@ -71,6 +71,7 @@ function packCheckout(dir) {
|
|
|
71
71
|
const root = runGit(['rev-parse', '--show-toplevel'], dir, CLI_GIT_TIMEOUT_MS);
|
|
72
72
|
const commit = runGit(['rev-parse', 'HEAD'], dir, CLI_GIT_TIMEOUT_MS);
|
|
73
73
|
const repo = detectRepoName(dir, CLI_GIT_TIMEOUT_MS);
|
|
74
|
+
const committedAt = runGit(['show', '-s', '--format=%cI', 'HEAD'], dir, CLI_GIT_TIMEOUT_MS)?.trim();
|
|
74
75
|
if (!root || !commit || !repo) {
|
|
75
76
|
return null;
|
|
76
77
|
}
|
|
@@ -80,6 +81,7 @@ function packCheckout(dir) {
|
|
|
80
81
|
// git prints the real path, so a symlinked temp or home folder must be resolved before comparing.
|
|
81
82
|
pathInRepo: (0, path_1.relative)((0, fs_1.realpathSync)(root), (0, fs_1.realpathSync)(dir)).split(path_1.sep).join('/'),
|
|
82
83
|
dirty: runGit(['status', '--porcelain', '--', '.'], dir, CLI_GIT_TIMEOUT_MS) !== null,
|
|
84
|
+
...(committedAt ? { committedAt } : {}),
|
|
83
85
|
};
|
|
84
86
|
}
|
|
85
87
|
exports.packCheckout = packCheckout;
|
package/dist/import-apply.js
CHANGED
|
@@ -59,6 +59,7 @@ async function applyPlan(deps, plan, repoName) {
|
|
|
59
59
|
deps.log(` ${result.uid} resembles ${similar.map((match) => match.uid).join(', ')}; check for a duplicate`);
|
|
60
60
|
return result;
|
|
61
61
|
};
|
|
62
|
+
const importedFrom = { basisAt: plan.sourceCommittedAt ?? null };
|
|
62
63
|
let saved = 0;
|
|
63
64
|
let skipped = 0;
|
|
64
65
|
for (const page of plan.pages) {
|
|
@@ -66,7 +67,7 @@ async function applyPlan(deps, plan, repoName) {
|
|
|
66
67
|
skipped++;
|
|
67
68
|
continue;
|
|
68
69
|
}
|
|
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
|
+
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, importedFrom });
|
|
70
71
|
page.savedUid = result.uid;
|
|
71
72
|
deps.savePlan(plan);
|
|
72
73
|
deps.log(`saved ${page.title} -> ${result.uid}`);
|
|
@@ -77,7 +78,7 @@ async function applyPlan(deps, plan, repoName) {
|
|
|
77
78
|
skipped++;
|
|
78
79
|
continue;
|
|
79
80
|
}
|
|
80
|
-
const result = await save(fact.id, fact.content, { type: 'Fact', content: fact.content, repo: repoUid, visibility: 'Team', source: plan.source });
|
|
81
|
+
const result = await save(fact.id, fact.content, { type: 'Fact', content: fact.content, repo: repoUid, visibility: 'Team', source: plan.source, importedFrom });
|
|
81
82
|
fact.savedUid = result.uid;
|
|
82
83
|
deps.savePlan(plan);
|
|
83
84
|
deps.log(`saved fact ${fact.id} -> ${result.uid}`);
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,9 @@ const extension_update_1 = require("./extension-update");
|
|
|
30
30
|
const asset_sync_1 = require("./asset-sync");
|
|
31
31
|
const tags_1 = require("./tags");
|
|
32
32
|
const ask_prompt_1 = require("./ask-prompt");
|
|
33
|
+
const change_tools_1 = require("./change-tools");
|
|
34
|
+
const check_tools_1 = require("./check-tools");
|
|
35
|
+
const watch_1 = require("./watch");
|
|
33
36
|
const client = new client_1.MemoryHubClient({
|
|
34
37
|
credentials: () => {
|
|
35
38
|
const creds = (0, credentials_1.resolveCredentials)();
|
|
@@ -52,7 +55,7 @@ const INSTRUCTIONS = [
|
|
|
52
55
|
'memory_list type=Wiki scope=all titlePrefix="<Project> ›", and when the hub has nothing, list the projects it holds and ask',
|
|
53
56
|
'which was meant, then only if none fits ask for sources and say reading them costs tokens.',
|
|
54
57
|
'Progress questions (how a project, WO/CR, release or ticket is going): follow "Progress reports" in memory_getSkillGuide;',
|
|
55
|
-
"reuse a WO or CR status snapshot
|
|
58
|
+
"reuse a WO or CR status snapshot within the limit `check.reuseUntil` gives, else pull live through the user's own connections.",
|
|
56
59
|
'Tenant questions (what a customer\'s tenant runs): follow "Tenant snapshots" in memory_getSkillGuide; answer from the saved tenant snapshot first and refresh it only with admin console access.',
|
|
57
60
|
'Every save gets a deliberate visibility (see "What to share" in memory_getSkillGuide):',
|
|
58
61
|
'Team for work knowledge about a project or customer, saved with repo: "<owner/name>"',
|
|
@@ -65,6 +68,7 @@ const INSTRUCTIONS = [
|
|
|
65
68
|
].join(' ');
|
|
66
69
|
const server = new mcp_js_1.McpServer({ name: 'memory-hub-mcp', version: (0, version_1.packageVersion)() }, { instructions: INSTRUCTIONS });
|
|
67
70
|
(0, login_tool_1.guardTools)(server, { signedIn: () => (0, credentials_1.resolveCredentials)() !== undefined, exempt: ['memory_login', 'memory_getSkillGuide'] });
|
|
71
|
+
(0, check_tools_1.guardCheckRun)(server, process.env);
|
|
68
72
|
// Detected from this process's own working directory, not from anything the model
|
|
69
73
|
// types. Resolved lazily on the first save so startup never blocks on git or the
|
|
70
74
|
// network, and degrades to undefined (an unscoped save) on any failure.
|
|
@@ -174,7 +178,7 @@ const saveShape = {
|
|
|
174
178
|
visibility: zod_1.z.enum(['Private', 'Team', 'Org']).optional().describe('Choose it on every save ("What to share" in memory_getSkillGuide). Team: work knowledge about a project or customer (decisions, fixes, root causes, how-tos, gotchas, conventions), on that project\'s repo; every agent can find it with scope all, so keep customer specifics to what the lesson needs. Org (everyone in the tenant): knowledge about Skedulo\'s own platform, products, tools or practices with no customer names or data, project detail, commercial terms, credentials, unpatched security detail or anything about a person. Private only with a stated reason: personal, an unverified guess, about a person, or barred by the confidentiality rules. Unsure between Org and Team: Team. Team is refused on a repo no team owns yet. Omit it in capture mode, which saves Private.'),
|
|
175
179
|
source: source_1.sourceSchema.optional().describe(source_1.SOURCE_DESCRIPTION),
|
|
176
180
|
supersedes: zod_1.z.string().min(1).optional().describe('Fact, Skill, Wiki only — the uid of a memory of the same type that this one replaces. After saving, that memory is tagged Superseded if you may edit it (yours, or a Team item on your repo); otherwise the result says why it was not marked.'),
|
|
177
|
-
distinctFrom: zod_1.z.string().min(1).optional().describe('Fact only —
|
|
181
|
+
distinctFrom: zod_1.z.union([zod_1.z.string().min(1), zod_1.z.array(zod_1.z.string().min(1)).min(1)]).optional().describe('Fact, Skill and Scenario only — a uid, or a list of uids, that "Not saved: … says nearly the same" replies named, when this note is about something else. Skips the check for those uids only. Ignored for a Wiki page.'),
|
|
178
182
|
};
|
|
179
183
|
const saveDeps = {
|
|
180
184
|
client,
|
|
@@ -182,7 +186,7 @@ const saveDeps = {
|
|
|
182
186
|
currentRepoUid: () => repoContext.currentRepoUid(),
|
|
183
187
|
resolveTaskUid: (ref, repoUid) => taskContext.resolveTaskUid(ref, repoUid),
|
|
184
188
|
};
|
|
185
|
-
server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the Memory Hub. Decide its visibility on every save by the "What to share" rule (see visibility) and state the choice and the reason in your reply. For work knowledge about a project, pass repo as "<owner/name>" of that project\'s repo, even from Claude Desktop or another folder. Never guess a repo name, and pass only a repo that memory_listRepos lists: a repo you pass by name on a team you are not on is refused, never joined (only the current folder\'s repo auto-joins). When memory_listRepos does not show the project\'s repo, or shows several candidates, ask which repo, or save Private and say why. Team with no repo, given or detected, is refused. Without visibility it is Team when the attached repo is linked to a team, otherwise Private. A Fact that says nearly the same as one
|
|
189
|
+
server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the Memory Hub. Decide its visibility on every save by the "What to share" rule (see visibility) and state the choice and the reason in your reply. For work knowledge about a project, pass repo as "<owner/name>" of that project\'s repo, even from Claude Desktop or another folder. Never guess a repo name, and pass only a repo that memory_listRepos lists: a repo you pass by name on a team you are not on is refused, never joined (only the current folder\'s repo auto-joins). When memory_listRepos does not show the project\'s repo, or shows several candidates, ask which repo, or save Private and say why. Team with no repo, given or detected, is refused. Without visibility it is Team when the attached repo is linked to a team, otherwise Private. A Fact, Skill or Scenario that says nearly the same as one you can edit on the same repo is not saved: the reply gives its text to merge with memory_update, or distinctFrom to save it as its own note. The result reports the saved visibility, repoId, repoName and teamName. See memory_getSkillGuide for which type to use and which fields it needs. The current repo is detected automatically unless you pass an explicit repo (from memory_listRepos) to target a different one.', saveShape, async (input) => {
|
|
186
190
|
const outcome = await (0, bulk_1.performSaveItem)(saveDeps, input);
|
|
187
191
|
if ('refused' in outcome) {
|
|
188
192
|
return { content: [{ type: 'text', text: outcome.refused }] };
|
|
@@ -196,7 +200,7 @@ server.tool('memory_save', 'Save a Fact, Skill, Scenario, or Wiki page to the Me
|
|
|
196
200
|
],
|
|
197
201
|
};
|
|
198
202
|
});
|
|
199
|
-
server.tool('memory_saveBatch', 'Save up to 25 Facts/Skills/Scenarios/Wiki pages in one call, each item shaped exactly like a memory_save call (same required fields, repo and visibility rules). Items are saved in order; each reports its own result, error or refused (a Fact that nearly repeats one
|
|
203
|
+
server.tool('memory_saveBatch', 'Save up to 25 Facts/Skills/Scenarios/Wiki pages in one call, each item shaped exactly like a memory_save call (same required fields, repo and visibility rules). Items are saved in order; each reports its own result, error or refused (a Fact, Skill or Scenario that nearly repeats one you can edit on the same repo, with the text to merge), so one bad item does not stop the rest. Possible duplicates are listed compactly per item. Decide each item\'s visibility by the "What to share" rule, as for memory_save, and state the choices and reasons in your reply.', { items: zod_1.z.array(zod_1.z.object(saveShape)).min(1).max(25) }, async (input) => {
|
|
200
204
|
const { results, similarNotices, similarClosing } = await (0, bulk_1.performSaveBatch)(saveDeps, input.items);
|
|
201
205
|
const similarBlock = similarNotices.length
|
|
202
206
|
? [
|
|
@@ -304,6 +308,40 @@ server.tool('memory_whoCanRead', "Preview who can read one Fact/Scenario/Skill/W
|
|
|
304
308
|
const result = await (0, teams_1.performWhoCanRead)({ client }, input);
|
|
305
309
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
306
310
|
});
|
|
311
|
+
server.tool('memory_reportChange', change_tools_1.REPORT_CHANGE_DESCRIPTION, change_tools_1.reportChangeSchema, async (input) => {
|
|
312
|
+
const result = await (0, change_tools_1.performReportChange)({ client }, input);
|
|
313
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
314
|
+
});
|
|
315
|
+
server.tool('memory_listChanges', change_tools_1.LIST_CHANGES_DESCRIPTION, change_tools_1.listChangesSchema, async (input) => {
|
|
316
|
+
const result = await (0, change_tools_1.performListChanges)({ client }, input);
|
|
317
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
318
|
+
});
|
|
319
|
+
server.tool('memory_ackChange', change_tools_1.ACK_CHANGE_DESCRIPTION, change_tools_1.ackChangeSchema, async (input) => {
|
|
320
|
+
const result = await (0, change_tools_1.performAckChange)({ client }, input);
|
|
321
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
322
|
+
});
|
|
323
|
+
server.tool('memory_retractChange', change_tools_1.RETRACT_CHANGE_DESCRIPTION, change_tools_1.retractChangeSchema, async (input) => {
|
|
324
|
+
const result = await (0, change_tools_1.performRetractChange)({ client }, input);
|
|
325
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
326
|
+
});
|
|
327
|
+
const checkStore = (0, check_tools_1.createCheckStore)();
|
|
328
|
+
const checkDeps = () => ({
|
|
329
|
+
client,
|
|
330
|
+
exec: check_sources_1.execGit,
|
|
331
|
+
gh: (args) => (0, watch_1.runCommand)('gh', args),
|
|
332
|
+
localRepo: repoContext.repoName,
|
|
333
|
+
background: (0, check_tools_1.isCheckRun)(process.env),
|
|
334
|
+
now: Date.now,
|
|
335
|
+
store: checkStore,
|
|
336
|
+
});
|
|
337
|
+
server.tool('memory_checkStart', check_tools_1.CHECK_START_DESCRIPTION, check_tools_1.checkStartSchema, async (input) => {
|
|
338
|
+
const result = await (0, check_tools_1.performCheckStart)(checkDeps(), input);
|
|
339
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
340
|
+
});
|
|
341
|
+
server.tool('memory_checkFinish', check_tools_1.CHECK_FINISH_DESCRIPTION, check_tools_1.checkFinishSchema, async (input) => {
|
|
342
|
+
const result = await (0, check_tools_1.performCheckFinish)(checkDeps(), input);
|
|
343
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
344
|
+
});
|
|
307
345
|
server.tool('memory_update', "Revise a memory (yours, or a Team item on your team's repo) in place, instead of saving a second copy. Pass the uid (from memory_recall, memory_get or a memory_save notice) and only the fields to change: content and tags for a Fact; title, content and tags for a Skill or Wiki page; summary for a Scenario; links for a Wiki page; factIds for a Scenario; repo (a uid from memory_listRepos, or null for not project-specific) and source (or null to clear it) for any. The author can update any of their items; any member of the team that owns the item's repo can update a Team-visible item, but only the author can change its repo, links or factIds. expectedLastModified (the lastModifiedDate from memory_get) is required when you are not the author: without it the update is treated as author-only and fails with Not found, so Not found on an item you can read usually means it was left out. If the item changed since you read it, the update fails with a Conflict error instead of overwriting it. When this repeats or corrects something you already saved, use this, not memory_save.", {
|
|
308
346
|
type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
|
|
309
347
|
uid: zod_1.z.string().min(1),
|