@skedulo/memory-hub-mcp 0.2.37 → 0.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiReference = exports.parseReadInput = exports.READ_FUNCTIONS = exports.READ_NAMES = void 0;
4
+ const zod_1 = require("zod");
5
+ const annotate_1 = require("./annotate");
6
+ const change_tools_1 = require("./change-tools");
7
+ const check_sources_1 = require("./check-sources");
8
+ const list_repos_1 = require("./list-repos");
9
+ const recall_1 = require("./recall");
10
+ const source_1 = require("./source");
11
+ const tags_1 = require("./tags");
12
+ const teams_1 = require("./teams");
13
+ exports.READ_NAMES = ['recall', 'get', 'list', 'related', 'checkSources', 'listRepos', 'listTeams', 'listTeamMembers', 'whoCanRead', 'listChanges'];
14
+ const recallShape = {
15
+ type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
16
+ scope: zod_1.z.enum(['self', 'team', 'all']),
17
+ query: zod_1.z.string().optional(),
18
+ tags: zod_1.z.array(zod_1.z.enum(tags_1.TAG_VALUES)).optional().describe('Fact only.'),
19
+ externalRef: zod_1.z.string().optional().describe("Fact, Scenario only — filter to items linked to this Linear/Jira ticket ref, e.g. 'SOL-1234'. Does not create a task if the ref doesn't resolve to one — returns no results instead."),
20
+ maxCharsPerItem: zod_1.z.number().int().positive().optional().describe('Per-item content cap, default 500. Raise it to read longer items inline; prefer memory_get for a single long one.'),
21
+ maxTotalChars: zod_1.z.number().int().positive().optional().describe('Cap across all items, default 6000.'),
22
+ };
23
+ const getShape = {
24
+ type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
25
+ uid: zod_1.z.string().min(1).describe('The uid from a memory_recall result.'),
26
+ };
27
+ const relatedShape = {
28
+ type: zod_1.z.enum(['Fact', 'Skill', 'Scenario', 'Wiki']),
29
+ uid: zod_1.z.string().min(1).describe('The uid from a memory_recall or memory_get result.'),
30
+ };
31
+ const listShape = {
32
+ type: zod_1.z.enum(['Fact', 'Scenario', 'Skill', 'Wiki']),
33
+ scope: zod_1.z.enum(['team', 'all']).optional().describe("team (default): yours plus what your teams share. all: also every other team's Team and Org items."),
34
+ repo: zod_1.z.string().min(1).nullable().optional().describe('A DevRepos uid from memory_listRepos. null lists only items with no repo; omit for any repo.'),
35
+ visibility: zod_1.z.enum(['Private', 'Team', 'Restricted', 'Org']).optional(),
36
+ titlePrefix: zod_1.z.string().min(1).optional().describe('Case-insensitive start of the title (Fact: content, Scenario: summary).'),
37
+ tags: zod_1.z.array(zod_1.z.enum(tags_1.TAG_VALUES)).optional().describe('Items carrying any of these tags. Not supported for Scenario.'),
38
+ mine: zod_1.z.boolean().optional().describe('true: only items you saved.'),
39
+ createdAfter: zod_1.z.string().min(1).optional().describe('ISO date or datetime. Skills filter on last modified instead of created.'),
40
+ sourceRepo: zod_1.z.string().min(1).optional().describe('owner/name, exact: only items whose source.repo is this.'),
41
+ verifiedBefore: zod_1.z.string().min(1).refine(source_1.isIsoDate, 'verifiedBefore must be an ISO date or datetime').optional().describe('Only items last verified before this ISO date or datetime.'),
42
+ offset: zod_1.z.number().int().min(0).optional(),
43
+ limit: zod_1.z.number().int().min(1).max(200).optional().describe('Default 50, max 200.'),
44
+ };
45
+ const checkSourcesShape = {
46
+ repo: zod_1.z.string().min(1).optional().describe("owner/name. Defaults to the current directory's repo."),
47
+ };
48
+ const listReposShape = {
49
+ query: zod_1.z.string().optional().describe('Case-insensitive substring filter on repo name.'),
50
+ includeUnlinked: zod_1.z.boolean().optional().describe('true: also return repos with no team, with teamName null.'),
51
+ };
52
+ const listTeamsShape = {
53
+ query: zod_1.z.string().optional(),
54
+ };
55
+ const listTeamMembersShape = {
56
+ teamName: zod_1.z.string().min(1),
57
+ };
58
+ const whoCanReadShape = {
59
+ type: zod_1.z.enum(['Fact', 'Scenario', 'Skill', 'Wiki']),
60
+ uid: zod_1.z.string().min(1),
61
+ };
62
+ async function getItem(client, { type, uid }) {
63
+ return type === 'Fact'
64
+ ? client.getFact({ uid })
65
+ : type === 'Skill'
66
+ ? client.getSkill({ uid })
67
+ : type === 'Scenario'
68
+ ? client.getScenario({ uid })
69
+ : client.getWikiPage({ uid });
70
+ }
71
+ exports.READ_FUNCTIONS = {
72
+ recall: {
73
+ name: 'recall',
74
+ tool: 'memory_recall',
75
+ summary: 'Search Facts, Skills, Scenarios or Wiki pages by meaning; items come back truncated.',
76
+ flags: '`check`, `staleness`, `superseded`, `upstream`',
77
+ shape: recallShape,
78
+ run: ({ client, embed, staleness }, input) => (0, recall_1.performRecall)({ client, embed, staleness }, input),
79
+ },
80
+ get: {
81
+ name: 'get',
82
+ tool: 'memory_get',
83
+ summary: 'Fetch one item in full by uid, with its lastModifiedDate.',
84
+ flags: '`check`, `staleness`, `superseded`, `upstream`',
85
+ shape: getShape,
86
+ run: async ({ client, staleness }, input) => {
87
+ const { type } = input;
88
+ const result = await getItem(client, input);
89
+ return (0, annotate_1.annotateItemCapped)(result, staleness, { entries: type === 'Wiki' });
90
+ },
91
+ },
92
+ list: {
93
+ name: 'list',
94
+ tool: 'memory_list',
95
+ summary: 'List one type of items you can see, newest first, one page at a time.',
96
+ flags: '`check`, `upstream`; not annotated, so no `staleness` or `superseded`',
97
+ shape: listShape,
98
+ run: ({ client }, input) => client.listResources(input),
99
+ },
100
+ related: {
101
+ name: 'related',
102
+ tool: 'memory_related',
103
+ summary: "List one item's neighbours as pointers, without their content.",
104
+ flags: 'none; pointers only',
105
+ shape: relatedShape,
106
+ run: ({ client }, input) => {
107
+ const { uid, type } = input;
108
+ return client.related({ uid, type });
109
+ },
110
+ },
111
+ checkSources: {
112
+ name: 'checkSources',
113
+ tool: 'memory_checkSources',
114
+ summary: "Report how far HEAD is ahead of each item's source commit for a repo checkout.",
115
+ flags: '`commitsBehind`/`unknownCommit`/`notAncestor`; no `check` or `upstream`',
116
+ shape: checkSourcesShape,
117
+ run: ({ client, detectRepoName, execGit }, input) => (0, check_sources_1.performCheckSources)({ client, detectRepoName, exec: execGit }, input),
118
+ },
119
+ listRepos: {
120
+ name: 'listRepos',
121
+ tool: 'memory_listRepos',
122
+ summary: "List repos across the developer's teams, optionally filtered by name.",
123
+ flags: 'not items',
124
+ shape: listReposShape,
125
+ run: async ({ client }, input) => ({
126
+ repos: await (0, list_repos_1.listReposForTools)(client, input.query, input.includeUnlinked === true),
127
+ }),
128
+ },
129
+ listTeams: {
130
+ name: 'listTeams',
131
+ tool: 'memory_listTeams',
132
+ summary: 'List the memory teams the developer belongs to, or search every team by name.',
133
+ flags: 'not items',
134
+ shape: listTeamsShape,
135
+ run: async ({ client }, input) => {
136
+ const { teams } = await (0, teams_1.performListTeams)({ client }, input);
137
+ return { teams };
138
+ },
139
+ },
140
+ listTeamMembers: {
141
+ name: 'listTeamMembers',
142
+ tool: 'memory_listTeamMembers',
143
+ summary: 'List the members of a memory team by name.',
144
+ flags: 'not items',
145
+ shape: listTeamMembersShape,
146
+ run: ({ client }, input) => (0, teams_1.performListTeamMembers)({ client }, input),
147
+ },
148
+ whoCanRead: {
149
+ name: 'whoCanRead',
150
+ tool: 'memory_whoCanRead',
151
+ summary: 'Preview who can read one item, from its actual visibility.',
152
+ flags: 'not items',
153
+ shape: whoCanReadShape,
154
+ run: ({ client }, input) => (0, teams_1.performWhoCanRead)({ client }, input),
155
+ },
156
+ listChanges: {
157
+ name: 'listChanges',
158
+ tool: 'memory_listChanges',
159
+ summary: 'List the change signals the hub has heard, by repo, key or uid.',
160
+ flags: 'change signals (upstream text)',
161
+ shape: change_tools_1.listChangesSchema,
162
+ run: ({ client }, input) => (0, change_tools_1.performListChanges)({ client }, input),
163
+ },
164
+ };
165
+ function parseReadInput(name, raw) {
166
+ const parsed = zod_1.z.object(exports.READ_FUNCTIONS[name].shape).safeParse(raw);
167
+ return parsed.success ? { ok: true, value: parsed.data } : { ok: false, issues: parsed.error.issues };
168
+ }
169
+ exports.parseReadInput = parseReadInput;
170
+ function apiReference() {
171
+ const functions = exports.READ_NAMES.map((name) => `- \`hub.${name}(input)\`: ${exports.READ_FUNCTIONS[name].summary}`);
172
+ const table = [
173
+ '| Function | Same as tool | Flags its results carry |',
174
+ '|---|---|---|',
175
+ ...exports.READ_NAMES.map((name) => `| \`hub.${name}(input)\` | \`${exports.READ_FUNCTIONS[name].tool}\` | ${exports.READ_FUNCTIONS[name].flags} |`),
176
+ ];
177
+ return [...functions, '', ...table].join('\n');
178
+ }
179
+ exports.apiReference = apiReference;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCli = void 0;
4
+ const check_sources_1 = require("./check-sources");
5
+ const client_1 = require("./client");
6
+ const code_mode_1 = require("./code-mode");
7
+ const credentials_1 = require("./credentials");
8
+ const embeddings_1 = require("./embeddings");
9
+ const git_remote_1 = require("./git-remote");
10
+ const read_api_1 = require("./read-api");
11
+ const SIGN_IN_HINT = 'Not signed in. Run: memory-hub-mcp login';
12
+ const USAGE = `Usage: memory-hub-mcp run <file|->
13
+
14
+ Runs a short read-only JavaScript script against the hub. The script gets \`hub\` and returns its result.
15
+ Use - to read the script from stdin. Exit codes: 0 ok, 1 script or usage error, 3 not signed in.
16
+ Run memory-hub-mcp login to sign in.
17
+
18
+ Functions:
19
+ ${(0, read_api_1.apiReference)()}`;
20
+ async function runCli(args, io) {
21
+ if (args[0] === '--help' || args[0] === '-h') {
22
+ io.write(USAGE);
23
+ return 0;
24
+ }
25
+ if (args.length !== 1) {
26
+ io.write(USAGE);
27
+ return 1;
28
+ }
29
+ let script;
30
+ try {
31
+ script = args[0] === '-' ? await io.readStdin() : await io.readFile(args[0]);
32
+ }
33
+ catch (error) {
34
+ io.write(error instanceof Error ? error.message : String(error));
35
+ return 1;
36
+ }
37
+ const runEnded = new AbortController();
38
+ const client = new client_1.MemoryHubClient({
39
+ credentials: () => {
40
+ const creds = (0, credentials_1.resolveCredentials)();
41
+ return creds && { baseUrl: (0, credentials_1.resolveFunctionUrl)(io.env, creds), apiToken: creds.token };
42
+ },
43
+ signal: runEnded.signal,
44
+ });
45
+ const outcome = await (0, code_mode_1.runHubScript)({ client, embed: embeddings_1.embed, detectRepoName: () => (0, git_remote_1.detectRepoName)(io.cwd), execGit: check_sources_1.execGit, mode: 'cli' }, script);
46
+ // A hub request the run left open would keep the process alive past the deadline.
47
+ runEnded.abort();
48
+ io.write(`${outcome.blocks[0]}\n\n${outcome.blocks[1]}`);
49
+ if (outcome.status === 'not-signed-in')
50
+ io.writeError(SIGN_IN_HINT);
51
+ return outcome.status === 'ok' ? 0 : outcome.status === 'not-signed-in' ? 3 : 1;
52
+ }
53
+ exports.runCli = runCli;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRunReport = exports.MODE_LINES = void 0;
4
+ const INTERACTIVE_BASE = 'Before relying on any item under attention: call memory_get on it to see the flag in full, then: ' +
5
+ 'due → memory_checkStart with its uid; stale or upstream → the rules in memory_getSkillGuide ' +
6
+ 'section="Stale memories"; superseded → prefer the newer memory, found with memory_recall or as a ' +
7
+ '"superseded by" candidate from memory_related. Items under notJudged were only listed: memory_get ' +
8
+ 'each before relying on it.';
9
+ exports.MODE_LINES = {
10
+ interactive: INTERACTIVE_BASE +
11
+ ' forBackgroundCheck is read by the session-end hook, not by you; an item in it is still unchecked now.',
12
+ extension: INTERACTIVE_BASE,
13
+ capture: 'Capture run: these flags do not stop a correction the person stated or a merge a save refusal asks ' +
14
+ 'for. If the memory you would update is superseded, use the newer one instead (find it with ' +
15
+ 'memory_recall) and update it only if it is also wrong. Do not check, fix code drift, pass source or ' +
16
+ 'mark anything stale. Nothing from this run reaches the background check.',
17
+ cli: 'The background check does not see CLI runs. Before relying on an item under attention or ' +
18
+ 'notJudged, read it with memory_get in an MCP session and follow what that result says; with no MCP ' +
19
+ 'session, name it to the person as not checked.'
20
+ };
21
+ const ATTENTION_CAP = 20;
22
+ const NOT_JUDGED_CAP = 20;
23
+ const BACKGROUND_CHECK_CAP = 10;
24
+ const UID_PATTERN = /^[A-Za-z0-9_-]+$/;
25
+ const ITEM_TYPES = ['Fact', 'Skill', 'Scenario', 'Wiki'];
26
+ const RECALL_GROUPS = [
27
+ ['facts', 'Fact'],
28
+ ['skills', 'Skill'],
29
+ ['scenarios', 'Scenario'],
30
+ ['pages', 'Wiki']
31
+ ];
32
+ function asRecord(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
34
+ ? value
35
+ : null;
36
+ }
37
+ function asItemType(value) {
38
+ return typeof value === 'string' && ITEM_TYPES.includes(value) ? value : null;
39
+ }
40
+ function entriesOf(value) {
41
+ if (!Array.isArray(value))
42
+ return [];
43
+ const entries = [];
44
+ for (const entry of value) {
45
+ const record = asRecord(entry);
46
+ if (record)
47
+ entries.push(record);
48
+ }
49
+ return entries;
50
+ }
51
+ function flagsOf(entry) {
52
+ const check = asRecord(entry.check);
53
+ return {
54
+ due: check !== null && (check.due === true || check.unknown === true),
55
+ stale: asRecord(entry.staleness) !== null,
56
+ superseded: entry.superseded === true,
57
+ upstream: Array.isArray(entry.upstream) && entry.upstream.length > 0
58
+ };
59
+ }
60
+ function returnedStrings(returned) {
61
+ const strings = new Set();
62
+ const visited = new Set();
63
+ const pending = [returned];
64
+ while (pending.length > 0) {
65
+ const value = pending.pop();
66
+ if (typeof value === 'string') {
67
+ strings.add(value);
68
+ }
69
+ else if (typeof value === 'object' && value !== null && !visited.has(value)) {
70
+ visited.add(value);
71
+ for (const child of Object.values(value))
72
+ pending.push(child);
73
+ }
74
+ }
75
+ return strings;
76
+ }
77
+ function sortItems(items, returned) {
78
+ const way = (item) => (item.viaGet ? 0 : item.viaRecall ? 1 : 2);
79
+ const isReturned = (item) => (returned.has(item.uid) ? 0 : 1);
80
+ return [...items].sort((a, b) => isReturned(a) - isReturned(b) || way(a) - way(b) || a.firstRead - b.firstRead);
81
+ }
82
+ function statusSentence(report, judgedCount, repoName, leftOut) {
83
+ if (report.reads.finished === 0)
84
+ return 'No hub read finished. Nothing was checked; do not rely on this run.';
85
+ if (report.reads.failed > 0)
86
+ return `${report.reads.failed} hub reads failed; the result may be incomplete.`;
87
+ if (report.attentionMore > 0 || report.notJudgedMore > 0) {
88
+ return `${leftOut} more items are flagged but not listed: memory_get any item you rely on that is not listed here.`;
89
+ }
90
+ if (report.attention.length === 0 && report.notJudged.length === 0) {
91
+ return (`No flag was found on the ${judgedCount} items read with get or recall. ` +
92
+ 'This is not a verification: an item that cites no file is never marked stale, and staleness ' +
93
+ `covers only ${repoName ?? 'no repo here'}.`);
94
+ }
95
+ return '';
96
+ }
97
+ function buildRunReport(input) {
98
+ const items = new Map();
99
+ const observe = (readIndex, via, type, entry) => {
100
+ const uid = entry.uid;
101
+ if (!type || typeof uid !== 'string' || !UID_PATTERN.test(uid))
102
+ return;
103
+ const key = `${type}${uid}`;
104
+ let item = items.get(key);
105
+ if (!item) {
106
+ item = {
107
+ type,
108
+ uid,
109
+ firstRead: readIndex,
110
+ viaGet: false,
111
+ viaRecall: false,
112
+ flags: { due: false, stale: false, superseded: false, upstream: false }
113
+ };
114
+ items.set(key, item);
115
+ }
116
+ if (via === 'get')
117
+ item.viaGet = true;
118
+ else if (via === 'recall')
119
+ item.viaRecall = true;
120
+ else
121
+ item.listedVia ??= via;
122
+ const flags = flagsOf(entry);
123
+ for (const reason of Object.keys(flags))
124
+ item.flags[reason] ||= flags[reason];
125
+ };
126
+ input.reads.forEach((read, index) => {
127
+ if (!read.ok)
128
+ return;
129
+ const result = asRecord(read.result);
130
+ if (!result)
131
+ return;
132
+ const inputType = asItemType(read.input?.type);
133
+ switch (read.fn) {
134
+ case 'get':
135
+ observe(index, 'get', inputType, result);
136
+ break;
137
+ case 'recall':
138
+ for (const [group, groupType] of RECALL_GROUPS) {
139
+ for (const entry of entriesOf(result[group]))
140
+ observe(index, 'recall', inputType ?? groupType, entry);
141
+ }
142
+ break;
143
+ case 'list':
144
+ for (const entry of entriesOf(result.items)) {
145
+ observe(index, 'list', inputType, entry);
146
+ }
147
+ break;
148
+ case 'related':
149
+ for (const entry of entriesOf(result.related))
150
+ observe(index, 'related', asItemType(entry.type), entry);
151
+ break;
152
+ case 'checkSources':
153
+ for (const entry of entriesOf(result.items)) {
154
+ observe(index, 'checkSources', asItemType(entry.type), entry);
155
+ }
156
+ break;
157
+ }
158
+ });
159
+ const returned = returnedStrings(input.returned);
160
+ const all = [...items.values()];
161
+ const reasonsOf = (item) => ['due', 'stale', 'superseded', 'upstream'].filter(reason => item.flags[reason]);
162
+ const flagged = sortItems(all.filter(item => reasonsOf(item).length > 0), returned);
163
+ const notJudged = sortItems(all.filter(item => !item.viaGet && !item.viaRecall && item.listedVia), returned);
164
+ const background = input.mode === 'interactive'
165
+ ? sortItems(all.filter(item => (item.viaGet || item.viaRecall) && item.flags.due), returned)
166
+ : [];
167
+ const report = {
168
+ reads: {
169
+ finished: input.reads.filter(read => read.ok).length,
170
+ failed: input.reads.filter(read => !read.ok).length
171
+ },
172
+ attention: flagged
173
+ .slice(0, ATTENTION_CAP)
174
+ .map(item => ({ type: item.type, uid: item.uid, reasons: reasonsOf(item) })),
175
+ attentionMore: Math.max(0, flagged.length - ATTENTION_CAP),
176
+ notJudged: notJudged.slice(0, NOT_JUDGED_CAP).map(item => ({
177
+ type: item.type,
178
+ uid: item.uid,
179
+ seenVia: item.listedVia
180
+ })),
181
+ notJudgedMore: Math.max(0, notJudged.length - NOT_JUDGED_CAP),
182
+ forBackgroundCheck: background.slice(0, BACKGROUND_CHECK_CAP).map(item => ({
183
+ type: item.type,
184
+ uid: item.uid,
185
+ via: item.viaGet ? 'get' : 'recall'
186
+ })),
187
+ forBackgroundCheckMore: Math.max(0, background.length - BACKGROUND_CHECK_CAP),
188
+ notices: [...new Set(input.notices)]
189
+ };
190
+ const judgedCount = all.filter(item => item.viaGet || item.viaRecall).length;
191
+ const leftOut = new Set([...flagged.slice(ATTENTION_CAP), ...notJudged.slice(NOT_JUDGED_CAP)]).size;
192
+ const status = statusSentence(report, judgedCount, input.repoName, leftOut);
193
+ return { ...report, next: exports.MODE_LINES[input.mode] + (status ? ` ${status}` : '') };
194
+ }
195
+ exports.buildRunReport = buildRunReport;