@skedulo/memory-hub-mcp 0.2.33 → 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/skills/project-knowledge/SKILL.md +6 -5
- package/assets/skills/project-knowledge/references/create-refresh.md +38 -4
- package/assets/skills/project-knowledge/references/page-format.md +6 -0
- package/assets/skills/project-knowledge/references/touch.md +4 -1
- package/dist/cli.js +17 -0
- package/dist/coverage.js +469 -0
- package/package.json +1 -1
|
@@ -20,8 +20,8 @@ and never skip one:
|
|
|
20
20
|
- `decision-rules.md`: before deciding which source wins, what becomes an entry, or a tier or status.
|
|
21
21
|
- `checker.md`: before anything is saved ("Check the work").
|
|
22
22
|
- `create-refresh.md`: create, resuming a create, refresh from sources and the sources-only refresh.
|
|
23
|
-
It also holds "Discover sources", "Discover features", "
|
|
24
|
-
catch-up reads too.
|
|
23
|
+
It also holds "Discover sources", "Discover features", "Coverage check", "Screen findings" and
|
|
24
|
+
"QA files", which a catch-up reads too.
|
|
25
25
|
- `targeted-update.md`: a change list handed over by another skill, or a change asked for by entry ID.
|
|
26
26
|
- `touch.md`: keeping the pages in step with the code from a commit range, used by fold-findings and
|
|
27
27
|
by refresh, or when the developer asks to catch up with the code.
|
|
@@ -29,7 +29,7 @@ and never skip one:
|
|
|
29
29
|
|
|
30
30
|
A section named in quotes is in: this file for "Before any mode", "Core changes" and "Summary";
|
|
31
31
|
`decision-rules.md` for "Decision rules"; `checker.md` for "Check the work"; `create-refresh.md`
|
|
32
|
-
for "Discover sources", "Discover features", "Create", "Refresh from sources",
|
|
32
|
+
for "Discover sources", "Discover features", "Coverage check", "Create", "Refresh from sources",
|
|
33
33
|
"Sources-only refresh", "Screen findings" and "QA files";
|
|
34
34
|
`targeted-update.md` for "Update" and "Targeted update"; `touch.md` for "Touch update"; `import.md` for "Import" and "Import step <n>".
|
|
35
35
|
|
|
@@ -161,8 +161,9 @@ Use these headings and leave out any that would be empty:
|
|
|
161
161
|
differs, not confirmed or could not be opened, and the final accuracy.
|
|
162
162
|
- **Worth a look**: `unverified` entries, rules not found in code, pending tickets, new feature keys,
|
|
163
163
|
suggested feature splits.
|
|
164
|
-
- **Coverage**: how many features, the
|
|
165
|
-
documents that fed no
|
|
164
|
+
- **Coverage**: how many features, the coverage check's numbers (code files, covered, the uncovered
|
|
165
|
+
folders left and why, features with no code, or why it did not run), and documents that fed no
|
|
166
|
+
entry.
|
|
166
167
|
- **Left out**: what the confidentiality rules removed, skipped Slack channels, and sources not read
|
|
167
168
|
and why.
|
|
168
169
|
- **Sources read**: one line per kind (code, tickets, technical docs, business docs, Slack, hub leads)
|
|
@@ -87,9 +87,43 @@ own code.
|
|
|
87
87
|
4. Write `<Project> › Reference › feature-map` (format in page-format.md): for each feature, a one-line
|
|
88
88
|
purpose and the code paths, document sections, ticket labels or epics, business processes and
|
|
89
89
|
Slack channels it covers.
|
|
90
|
-
5. Check coverage both ways
|
|
91
|
-
without code is either not built yet (list it under
|
|
92
|
-
belongs on a reference page. Report what does not fit
|
|
90
|
+
5. Check coverage both ways (the coverage check, next section, confirms it after the map is saved).
|
|
91
|
+
Every code area belongs to a feature. Every feature has code: a feature without code is either not built yet (list it under
|
|
92
|
+
"Worth a look") or a business concept that belongs on a reference page. Report what does not fit
|
|
93
|
+
under "Coverage" in the summary.
|
|
94
|
+
|
|
95
|
+
## Coverage check
|
|
96
|
+
|
|
97
|
+
The check matches every tracked code file against the saved feature map's `Code:` paths, reading
|
|
98
|
+
the map from the hub itself. Run it once after the feature map is saved. Run it once more only when
|
|
99
|
+
you changed `Code:` paths, to confirm.
|
|
100
|
+
|
|
101
|
+
1. Run, with a `--checkout` and a `--ref` for each repo the map names that you have a clone of,
|
|
102
|
+
delivery repo first. `<commit>` is the sha you read that repo at (in a touch update, `<B>`):
|
|
103
|
+
`npx -y @skedulo/memory-hub-mcp@latest coverage --project "<Project>" --checkout <owner/name>=<clone> --ref <owner/name>=<commit>`
|
|
104
|
+
2. Act on the JSON, editing only the feature map's `Code:` lines (`memory_update`):
|
|
105
|
+
- `repos[].uncovered.folders`: code no feature covers. Add each folder to the feature it
|
|
106
|
+
implements (a feature in `featuresWithoutCode` first). When a folder has `loose`, add those
|
|
107
|
+
files, never the whole folder. Name what fits no feature under "Coverage" with a reason (shared
|
|
108
|
+
plumbing, build tooling, dead code). Folders under `notListed` are too small to list: leave
|
|
109
|
+
them.
|
|
110
|
+
- `repos[].vendored`: already set aside as copied libraries. Name them under "Coverage"; never
|
|
111
|
+
put them in a `Code:` path.
|
|
112
|
+
- `featuresWithoutCode`: when no uncovered folder is its code, apply "Discover features", step 5.
|
|
113
|
+
- `pathsMatchingNothing`: replace the path with its `suggest` when there is one, otherwise delete
|
|
114
|
+
it.
|
|
115
|
+
- `unresolved`: write the entry as a full path (page-format.md, "Code paths").
|
|
116
|
+
- `overlaps` and `notCheckedOut`: name them under "Coverage". Change nothing.
|
|
117
|
+
3. Put the result in the summary's "Coverage" line, one line per repo:
|
|
118
|
+
`<repo>: <covered>/<codeFiles> code files covered`, then the folders left and why.
|
|
119
|
+
|
|
120
|
+
In a refresh, a catch-up or a targeted update with a commit range, the existing keys keep their code
|
|
121
|
+
paths ("Discover features", step 2). There, only add paths to existing features and fix or delete
|
|
122
|
+
paths that match nothing; a new feature goes under "Worth a look". In the weekly sweep, change
|
|
123
|
+
nothing: report the per-repo line in the digest.
|
|
124
|
+
|
|
125
|
+
When the check cannot run (no shell, no clone, not signed in, or `Unknown command "coverage"` from a
|
|
126
|
+
server older than 0.2.34), say so under "Coverage" and move on.
|
|
93
127
|
|
|
94
128
|
## Create
|
|
95
129
|
|
|
@@ -107,7 +141,7 @@ own code.
|
|
|
107
141
|
(page-format.md, "Page source"), with `tags=["ProjectRules"]` on rules and don't-build pages. Every page ends with a change-log line
|
|
108
142
|
(`<date> · <developer> via project-knowledge · Created · from <sources>`). Check each result
|
|
109
143
|
reports `visibility: "Team"`; if one does not, stop and tell the developer. Save the feature map
|
|
110
|
-
with them.
|
|
144
|
+
with them. Then run the coverage check and fix the map.
|
|
111
145
|
8. Save the Sources page last, then give the summary.
|
|
112
146
|
|
|
113
147
|
**Resuming a create that stopped partway** (pages but no Sources page): leave the saved pages and
|
|
@@ -46,6 +46,12 @@ Creates, times and allocates Ride jobs for appointments, and keeps them in step
|
|
|
46
46
|
Leave out a line that would be empty. Plan-ticket matches tickets to features with it, so keep the
|
|
47
47
|
code paths and labels precise.
|
|
48
48
|
|
|
49
|
+
**Code paths.** Write each `Code:` path relative to the repo root, starting a repo's group with
|
|
50
|
+
`owner/name` (it can be left off for the delivery repo). Short names are fine when the page defines
|
|
51
|
+
them before the first feature, as `T = Skedulo/<repo>` or `` `TA` = src/triggered-actions/ ``. A
|
|
52
|
+
remark goes in parentheses after its path. The coverage check (create-refresh.md, "Coverage check")
|
|
53
|
+
reads these lines and lists anything else as `unresolved`.
|
|
54
|
+
|
|
49
55
|
A page over about 20,000 characters is split into parts titled `<title> (1/3)`, `(2/3)`, `(3/3)`. Each
|
|
50
56
|
part keeps its own change log. When an edit pushes a page over the limit, move whole entries into a
|
|
51
57
|
new last part and renumber the titles.
|
|
@@ -55,7 +55,10 @@ unchanged code and never rebuilds the project. Callers:
|
|
|
55
55
|
7. New feature: draft it as in Create steps 3 to 5, for this feature only, giving the drafter the
|
|
56
56
|
project overview and one neighbouring Rules page as examples of tier and wording. Only a new
|
|
57
57
|
feature's entries get the full checker sample.
|
|
58
|
-
8.
|
|
58
|
+
8. Coverage, in a refresh, a catch-up or a targeted update with a commit range (not from
|
|
59
|
+
fold-findings): after the feature map is updated, run the coverage check (create-refresh.md,
|
|
60
|
+
"Coverage check") with `--ref <owner/name>=<B>` for each repo.
|
|
61
|
+
9. Finish:
|
|
59
62
|
- inside a targeted update or a refresh: hand the changes, including feature-map changes, to the
|
|
60
63
|
caller, which checks, applies, asks about core changes and gives the summary once for the run;
|
|
61
64
|
- a catch-up: run steps 1 to 7 for every repo on the Sources page first, then, once for all of
|
package/dist/cli.js
CHANGED
|
@@ -97,6 +97,16 @@ else if (command === 'watch') {
|
|
|
97
97
|
process.exitCode = 1;
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
else if (command === 'coverage') {
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
102
|
+
const { runCoverage } = require('./coverage');
|
|
103
|
+
runCoverage(process.argv.slice(3), { log: (line) => console.log(line) }).then((code) => {
|
|
104
|
+
process.exitCode = code;
|
|
105
|
+
}, (error) => {
|
|
106
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
100
110
|
else if (command === 'routine') {
|
|
101
111
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
102
112
|
const { runRoutine } = require('./routine');
|
|
@@ -167,6 +177,13 @@ else if (command === '--help' || command === '-h') {
|
|
|
167
177
|
in the checkout's code and in the memories, and print JSON. Checks
|
|
168
178
|
each one with a fast path where one fits, via git and gh.
|
|
169
179
|
--no-probe only lists them.
|
|
180
|
+
memory-hub-mcp coverage (--project <name> | --map <file>...) --checkout <owner/name>=<path> [--checkout ...]
|
|
181
|
+
[--ref [<owner/name>=]<ref>] [--exclude <glob>] [--full]
|
|
182
|
+
check a feature map's Code: paths against each checkout's tracked files
|
|
183
|
+
(at origin/HEAD unless --ref) and print brief JSON: code no feature covers,
|
|
184
|
+
vendored folders set aside, features without code, paths matching nothing
|
|
185
|
+
(with a suggestion), overlaps. --project reads the map from the hub.
|
|
186
|
+
--full lists every folder with samples. Never changes anything.
|
|
170
187
|
memory-hub-mcp routine --mode <dry-run|apply> --user <email> --environment <id> --repos <a/b,...> [--watch-repos <a/b,...>]
|
|
171
188
|
print the JSON body of the weekly sweep cloud routine for those repos
|
|
172
189
|
(only repos with hub items), to create at claude.ai/code/routines.
|
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/package.json
CHANGED