@skedulo/memory-hub-mcp 0.2.31 → 0.2.33

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/dist/save.js CHANGED
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.performSave = exports.validateRepoArg = exports.TEAM_NEEDS_REPO = void 0;
3
+ exports.performSave = exports.validateRepoArg = exports.TEAM_NEEDS_REPO = exports.NearCopyRefusal = void 0;
4
4
  const source_1 = require("./source");
5
5
  const capture_1 = require("./capture");
6
6
  const list_repos_1 = require("./list-repos");
7
+ const near_copy_1 = require("./near-copy");
8
+ class NearCopyRefusal extends Error {
9
+ }
10
+ exports.NearCopyRefusal = NearCopyRefusal;
7
11
  const UID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
12
  const OWNER_NAME_PATTERN = /^[^/\s]+\/[^/\s]+$/;
9
13
  exports.TEAM_NEEDS_REPO = "Team needs the project's repo: pass repo as owner/name, or save Private and say why.";
@@ -86,15 +90,60 @@ async function withSupersedes(saved, client, type, supersedes) {
86
90
  const result = await saved;
87
91
  return supersedes ? { ...result, ...(await markSuperseded(client, type, supersedes)) } : result;
88
92
  }
93
+ function nearCopyOption(deps, input) {
94
+ if (!deps.refuseNearCopies || (0, near_copy_1.isExempt)(input)) {
95
+ return {};
96
+ }
97
+ const distinctFrom = (0, near_copy_1.distinctList)(input);
98
+ return { refuseNearCopy: distinctFrom.length ? { distinctFrom } : {} };
99
+ }
100
+ async function readExisting(client, type, uid) {
101
+ try {
102
+ if (type === 'Scenario') {
103
+ const item = await client.getScenario({ uid });
104
+ return { text: item.summary, lastModifiedDate: item.lastModifiedDate };
105
+ }
106
+ if (type === 'Skill') {
107
+ const item = await client.getSkill({ uid });
108
+ const text = typeof item.content === 'string' && item.title ? `Title: ${item.title}\n${item.content}` : item.content;
109
+ return { text, lastModifiedDate: item.lastModifiedDate };
110
+ }
111
+ const item = await client.getFact({ uid });
112
+ return { text: item.content, lastModifiedDate: item.lastModifiedDate };
113
+ }
114
+ catch {
115
+ return {};
116
+ }
117
+ }
118
+ async function refusalFor(client, type, match, input) {
119
+ const existing = await readExisting(client, type, match.uid);
120
+ const existingText = typeof existing.text === 'string' ? existing.text : undefined;
121
+ return (0, near_copy_1.refusalMessage)({
122
+ type,
123
+ match,
124
+ existingText,
125
+ existingLastModified: existingText === undefined ? undefined : existing.lastModifiedDate,
126
+ distinct: (0, near_copy_1.distinctList)(input),
127
+ hasFactIds: Boolean(input.factIds?.length),
128
+ });
129
+ }
130
+ async function unlessRefused(response, client, type, input) {
131
+ const result = await response;
132
+ if ('refused' in result) {
133
+ throw new NearCopyRefusal(await refusalFor(client, type, result.refused, input));
134
+ }
135
+ return result;
136
+ }
89
137
  // Extracted from four near-identical memory_saveX tool handlers so the per-type
90
138
  // dispatch logic — which fields are required, what gets embedded, which client
91
139
  // method is called — is unit-testable. index.ts's module-scope side effects
92
140
  // (throwing on a missing token, connecting a stdio transport) make the file
93
141
  // itself untestable, the same reason list-repos.ts was extracted earlier.
94
142
  async function performSave(deps, input) {
95
- const { client, embed, currentRepoUid, resolveTaskUid } = deps;
143
+ const { client, embed, currentRepoUid, resolveTaskUid, beforeFactSave } = deps;
96
144
  (0, source_1.assertSource)(input.source);
97
145
  const supersedes = (0, capture_1.isCaptureMode)() ? undefined : input.supersedes;
146
+ const imported = input.importedFrom ? { importedFrom: input.importedFrom } : {};
98
147
  if (supersedes && input.type === 'Scenario') {
99
148
  throw new Error('supersedes applies to a Fact, Skill or Wiki page; a Scenario has no tags to mark Superseded.');
100
149
  }
@@ -114,9 +163,15 @@ async function performSave(deps, input) {
114
163
  throw new Error("content is required when type is 'Fact'");
115
164
  }
116
165
  const repo = await resolveRepo();
166
+ const nearCopy = (await beforeFactSave?.(input, repo)) ?? {};
167
+ if (nearCopy.refusal) {
168
+ throw new NearCopyRefusal(nearCopy.refusal);
169
+ }
117
170
  const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
118
171
  const embedding = await embed(input.content).catch(() => undefined);
119
- return withSupersedes(client.saveFact({ content: input.content, tags: input.tags, devTaskId, repo, embedding, visibility: input.visibility, source: input.source }), client, 'Fact', supersedes);
172
+ const response = client.saveFact({ content: input.content, tags: input.tags, devTaskId, repo, embedding, visibility: input.visibility, source: input.source, ...imported, ...nearCopyOption(deps, input) });
173
+ const saved = await withSupersedes(unlessRefused(response, client, 'Fact', input), client, 'Fact', supersedes);
174
+ return nearCopy.notice ? { ...saved, nearCopyNotice: nearCopy.notice } : saved;
120
175
  }
121
176
  case 'Skill': {
122
177
  if (!input.title || !input.content) {
@@ -124,7 +179,8 @@ async function performSave(deps, input) {
124
179
  }
125
180
  const repo = await resolveRepo();
126
181
  const embedding = await embed(`${input.title}\n\n${input.content}`).catch(() => undefined);
127
- return withSupersedes(client.saveSkill({ title: input.title, content: input.content, tags: input.tags, repo, embedding, visibility: input.visibility, source: input.source }), client, 'Skill', supersedes);
182
+ const response = client.saveSkill({ title: input.title, content: input.content, tags: input.tags, repo, embedding, visibility: input.visibility, source: input.source, ...imported, ...nearCopyOption(deps, input) });
183
+ return withSupersedes(unlessRefused(response, client, 'Skill', input), client, 'Skill', supersedes);
128
184
  }
129
185
  case 'Scenario': {
130
186
  if (!input.summary) {
@@ -133,7 +189,8 @@ async function performSave(deps, input) {
133
189
  const repo = await resolveRepo();
134
190
  const devTaskId = input.externalRef ? await resolveTaskUid(input.externalRef, repo ?? null) : undefined;
135
191
  const embedding = await embed(input.summary).catch(() => undefined);
136
- return client.saveScenario({ summary: input.summary, factIds: input.factIds, devTaskId, repo, embedding, visibility: input.visibility, source: input.source });
192
+ const response = client.saveScenario({ summary: input.summary, factIds: input.factIds, devTaskId, repo, embedding, visibility: input.visibility, source: input.source, ...imported, ...nearCopyOption(deps, input) });
193
+ return unlessRefused(response, client, 'Scenario', input);
137
194
  }
138
195
  case 'Wiki': {
139
196
  if (!input.title || !input.content) {
@@ -152,6 +209,7 @@ async function performSave(deps, input) {
152
209
  embedding,
153
210
  visibility: input.visibility,
154
211
  source: input.source,
212
+ ...imported,
155
213
  });
156
214
  return withSupersedes(saved, client, 'Wiki', supersedes);
157
215
  }
@@ -15,7 +15,7 @@ function soft(p, fallback, ms = CALL_TIMEOUT_MS) {
15
15
  }
16
16
  async function buildSessionContext(deps) {
17
17
  const { client, currentRepoUid, staleness } = deps;
18
- const [persona, factsSelf, factsTeam, skillsSelf, skillsTeam, repoUid] = await Promise.all([
18
+ const [persona, factsSelf, factsTeam, skillsSelf, skillsTeam, repoUid, checkSettings] = await Promise.all([
19
19
  // The one piece of context that does not depend on a repo, which makes it the most
20
20
  // valuable leg for a host with no project directory. `configured: false` is the cue
21
21
  // to offer setup once — without it Claude would have to nag every conversation.
@@ -25,6 +25,7 @@ async function buildSessionContext(deps) {
25
25
  soft(client.listSkills({ scope: 'self' }), { skills: [] }),
26
26
  soft(client.listSkills({ scope: 'team' }), { skills: [] }),
27
27
  soft(currentRepoUid(), undefined),
28
+ soft(Promise.resolve().then(() => client.checkSettings()), undefined),
28
29
  ]);
29
30
  // The team query matches "mine OR visibility=Team", so it re-returns everything self
30
31
  // already has; subtract it so the model isn't shown the same fact twice and weighing
@@ -65,6 +66,7 @@ async function buildSessionContext(deps) {
65
66
  skills: { self: skillsS, team: skillsT, repo: skillsR },
66
67
  wiki: wikiItems,
67
68
  repoScoped: Boolean(repoUid),
69
+ ...(checkSettings ? { checkSettings } : {}),
68
70
  };
69
71
  }
70
72
  exports.buildSessionContext = buildSessionContext;
@@ -75,7 +77,14 @@ function without(items, ...seen) {
75
77
  async function item(x, staleness) {
76
78
  const content = x.title ? `${x.title}: ${x.content}` : x.content;
77
79
  // Date only, no time: the model needs "is this stale", not an ordering key.
78
- const base = x.lastModifiedDate ? { content, updated: x.lastModifiedDate.slice(0, 10) } : { content };
80
+ const checked = x.check ? { uid: x.uid } : {};
81
+ const base = x.lastModifiedDate ? { ...checked, content, updated: x.lastModifiedDate.slice(0, 10) } : { ...checked, content };
79
82
  const { superseded, staleness: changed } = await (0, annotate_1.annotateItem)({ content: x.content, tags: x.tags, source: x.source }, staleness);
80
- return { ...base, ...(superseded ? { superseded } : {}), ...(changed ? { staleness: changed } : {}) };
83
+ return {
84
+ ...base,
85
+ ...(superseded ? { superseded } : {}),
86
+ ...(changed ? { staleness: changed } : {}),
87
+ ...(x.upstream?.length ? { upstream: x.upstream } : {}),
88
+ ...(x.check ? { check: x.check } : {}),
89
+ };
81
90
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.similarNotice = exports.batchClosingLine = exports.closingLine = exports.ownerLabel = exports.canEdit = void 0;
4
+ const near_copy_1 = require("./near-copy");
4
5
  const PREVIEW = 160;
5
6
  function canEdit(match) {
6
7
  return match.editable ?? match.mine !== false;
@@ -28,9 +29,22 @@ function citeAdvice(matches) {
28
29
  const uids = matches.map((match) => match.uid).join(', ');
29
30
  return `you cannot edit ${uids}, so cite ${matches.length === 1 ? 'it' : 'them'} in the new memory instead of repeating ${matches.length === 1 ? 'it' : 'them'}`;
30
31
  }
31
- function closingLine(type, newUid, matches) {
32
- const editable = matches.filter(canEdit);
33
- const locked = matches.filter((match) => !canEdit(match));
32
+ // Merging into your own item shared wider than this save would widen who reads the new text.
33
+ function sharedWider(match, saveVisibility) {
34
+ return Boolean(match.mine && match.visibility && saveVisibility && (0, near_copy_1.widerThan)(match.visibility, saveVisibility));
35
+ }
36
+ function sort(matches, saveVisibility) {
37
+ return {
38
+ editable: matches.filter((match) => canEdit(match) && !sharedWider(match, saveVisibility)),
39
+ wider: matches.filter((match) => canEdit(match) && sharedWider(match, saveVisibility)),
40
+ locked: matches.filter((match) => !canEdit(match)),
41
+ };
42
+ }
43
+ function widerAdvice(match) {
44
+ return `${match.uid} is yours but shared wider (${match.visibility}) than this save, so cite it instead of merging into it; keep the new one only if it adds something it doesn't say.`;
45
+ }
46
+ function closingLine(type, newUid, matches, saveVisibility) {
47
+ const { editable, wider, locked } = sort(matches, saveVisibility);
34
48
  const parts = [];
35
49
  if (editable.length > 0) {
36
50
  const target = editable.length === 1 ? editable[0].uid : '<that uid>';
@@ -38,22 +52,26 @@ function closingLine(type, newUid, matches) {
38
52
  const supersedes = type === 'Scenario' ? '' : ', or pass supersedes next time';
39
53
  parts.push(`To keep a single copy, update the existing one${which} with memory_update type=${type} uid=${target} ${UPDATE_GUARD} and the merged text, then memory_delete type=${type} uid=${newUid}${supersedes}.`);
40
54
  }
55
+ parts.push(...wider.map(widerAdvice));
41
56
  if (locked.length > 0) {
42
- parts.push(`${editable.length > 0 ? 'For the others' : 'Otherwise'}, ${citeAdvice(locked)}; keep the new one only if it adds something they don't say.`);
57
+ parts.push(`${parts.length > 0 ? 'For the others' : 'Otherwise'}, ${citeAdvice(locked)}; keep the new one only if it adds something they don't say.`);
43
58
  }
44
59
  return parts.join(' ');
45
60
  }
46
61
  exports.closingLine = closingLine;
47
- function batchClosingLine(matches) {
48
- const editable = matches.filter(canEdit);
49
- const locked = matches.filter((match) => !canEdit(match));
62
+ function batchClosingLine(items) {
63
+ const sorted = items.map((item) => sort(item.matches, item.visibility));
64
+ const editable = sorted.flatMap((item) => item.editable);
65
+ const wider = sorted.flatMap((item) => item.wider);
66
+ const locked = sorted.flatMap((item) => item.locked);
50
67
  const parts = [];
51
68
  if (editable.length > 0) {
52
69
  parts.push(`Where one you can edit already covers it (${editable.map((match) => match.uid).join(', ')}), memory_update that uid with the merged text and ${UPDATE_GUARD}, then memory_delete the new copy.`);
53
70
  }
71
+ parts.push(...wider.map(widerAdvice));
54
72
  if (locked.length > 0) {
55
73
  const advice = citeAdvice(locked);
56
- parts.push(editable.length > 0 ? `For the others, ${advice}.` : `${advice.charAt(0).toUpperCase()}${advice.slice(1)}.`);
74
+ parts.push(parts.length > 0 ? `For the others, ${advice}.` : `${advice.charAt(0).toUpperCase()}${advice.slice(1)}.`);
57
75
  }
58
76
  return parts.join(' ');
59
77
  }
@@ -68,7 +86,7 @@ function similarNotice(type, result) {
68
86
  `Saved as ${result.uid}, but it looks like ${matches.length === 1 ? 'a memory' : 'memories'} already saved:`,
69
87
  ...matches.map(describe),
70
88
  ];
71
- lines.push(closingLine(type, result.uid, matches));
89
+ lines.push(closingLine(type, result.uid, matches, result.visibility));
72
90
  return lines.join('\n');
73
91
  }
74
92
  exports.similarNotice = similarNotice;
package/dist/sweep.js CHANGED
@@ -5,6 +5,7 @@ const child_process_1 = require("child_process");
5
5
  const path_1 = require("path");
6
6
  const check_sources_1 = require("./check-sources");
7
7
  const client_1 = require("./client");
8
+ const item_targets_1 = require("./item-targets");
8
9
  const git_remote_1 = require("./git-remote");
9
10
  const staleness_1 = require("./staleness");
10
11
  exports.SWEEP_USAGE = 'memory-hub-mcp sweep --repo <owner/name> --checkout <path> [--stamp]';
@@ -13,24 +14,27 @@ exports.REPO_NAME = /^[A-Za-z0-9_-][A-Za-z0-9_.-]*\/[A-Za-z0-9_-][A-Za-z0-9_.-]*
13
14
  const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
14
15
  const GIT_TIMEOUT_MS = 60_000;
15
16
  const GIT_MAX_BUFFER = 64 * 1024 * 1024;
17
+ const CLAIM_BATCH = 50;
18
+ const schemeFree = (key) => key.slice(key.indexOf(':') + 1);
19
+ const PROJECT_PAGE_MARKER = ' › ';
16
20
  async function fetchItem(client, item) {
17
21
  const uid = item.uid;
18
22
  switch (item.type) {
19
23
  case 'Fact': {
20
24
  const got = await client.getFact({ uid });
21
- return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate };
25
+ return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate, upstream: got.upstream };
22
26
  }
23
27
  case 'Skill': {
24
28
  const got = await client.getSkill({ uid });
25
- return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate };
29
+ return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate, upstream: got.upstream };
26
30
  }
27
31
  case 'Scenario': {
28
32
  const got = await client.getScenario({ uid });
29
- return { text: got.summary, source: got.source, lastModifiedDate: got.lastModifiedDate };
33
+ return { text: got.summary, source: got.source, lastModifiedDate: got.lastModifiedDate, upstream: got.upstream };
30
34
  }
31
35
  case 'Wiki': {
32
36
  const got = await client.getWikiPage({ uid });
33
- return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate };
37
+ return { text: got.content, source: got.source, lastModifiedDate: got.lastModifiedDate, upstream: got.upstream };
34
38
  }
35
39
  }
36
40
  }
@@ -74,6 +78,7 @@ async function performSweep(deps, input) {
74
78
  }
75
79
  const result = { repo, target, unchanged: [], changed: [], nothingCited: [], unknownCommit: [], otherRepo: [], errors: [] };
76
80
  const toStamp = [];
81
+ const codeOnly = [];
77
82
  const now = deps.now().getTime();
78
83
  for (const item of await (0, check_sources_1.listBySourceRepo)(client, repo)) {
79
84
  try {
@@ -84,8 +89,12 @@ async function performSweep(deps, input) {
84
89
  switch (staleness.status) {
85
90
  case 'unchanged':
86
91
  result.unchanged.push(item.uid);
87
- if (source)
92
+ if (source) {
88
93
  toStamp.push({ item, source, lastModifiedDate });
94
+ const key = codeOnlyKey(repo, item, full, source);
95
+ if (key)
96
+ codeOnly.push({ item, source, key });
97
+ }
89
98
  break;
90
99
  case 'nothing-cited':
91
100
  result.nothingCited.push(item.uid);
@@ -145,9 +154,66 @@ async function performSweep(deps, input) {
145
154
  }
146
155
  }
147
156
  }
157
+ result.checkStamped = await stampCheckRows(deps, target, codeOnly, result);
148
158
  return result;
149
159
  }
150
160
  exports.performSweep = performSweep;
161
+ function codeOnlyKey(repo, item, full, source) {
162
+ if (item.type === 'Wiki' && item.title.includes(PROJECT_PAGE_MARKER))
163
+ return undefined;
164
+ const targets = (0, item_targets_1.itemTargets)({ type: item.type, title: item.title, text: full.text, source, upstream: full.upstream, createdDate: '', lastModifiedDate: full.lastModifiedDate ?? '' }, []);
165
+ const ours = repo.toLowerCase();
166
+ return targets.length > 0 && targets.every((target) => target.kind === 'repo' && target.identity === ours) ? targets[0].key : undefined;
167
+ }
168
+ async function stampCheckRows(deps, target, codeOnly, result) {
169
+ const { client, exec } = deps;
170
+ const ready = [];
171
+ for (const { item, source, key } of codeOnly) {
172
+ const old = source.commit.trim();
173
+ if (!HEX_SHA.test(old))
174
+ continue;
175
+ const reached = old.toLowerCase() === target.toLowerCase() || (await exec(['merge-base', '--is-ancestor', '--end-of-options', old, target]).then(() => true, () => false));
176
+ if (reached)
177
+ ready.push({ item, key });
178
+ }
179
+ const stamped = [];
180
+ for (let start = 0; start < ready.length; start += CLAIM_BATCH) {
181
+ const batch = ready.slice(start, start + CLAIM_BATCH);
182
+ let claimed;
183
+ try {
184
+ const { results } = await client.claimChecks({ items: batch.map(({ item }) => ({ type: item.type, uid: item.uid })), force: true });
185
+ claimed = new Map(results.filter((claim) => claim.outcome === 'claimed').map((claim) => [claim.uid, claim.required ?? []]));
186
+ }
187
+ catch (error) {
188
+ batch.forEach(({ item }) => result.errors.push({ uid: item.uid, error: `check not stamped: ${message(error)}` }));
189
+ continue;
190
+ }
191
+ for (const { item, key } of batch.filter(({ item }) => claimed.has(item.uid))) {
192
+ const ours = schemeFree(key);
193
+ const other = claimed.get(item.uid).filter((identity) => identity.toLowerCase() !== ours);
194
+ if (other.length > 0) {
195
+ await client.releaseCheck({ type: item.type, uid: item.uid, note: `needs-judgement: ${other.join(', ')}` }).catch(() => undefined);
196
+ result.checkNotStamped = [...(result.checkNotStamped ?? []), item.uid];
197
+ continue;
198
+ }
199
+ try {
200
+ await client.stampCheck({ type: item.type, uid: item.uid, checkedAgainst: `${key}@${target}` });
201
+ stamped.push(item.uid);
202
+ }
203
+ catch (error) {
204
+ const text = message(error);
205
+ if (!text.startsWith('Not held')) {
206
+ await client.releaseCheck({ type: item.type, uid: item.uid, note: `needs-judgement: ${text}` }).catch(() => undefined);
207
+ }
208
+ if (text.startsWith('Missing sources'))
209
+ result.checkNotStamped = [...(result.checkNotStamped ?? []), item.uid];
210
+ else
211
+ result.errors.push({ uid: item.uid, error: `check not stamped: ${text}` });
212
+ }
213
+ }
214
+ }
215
+ return stamped;
216
+ }
151
217
  function gitIn(checkout) {
152
218
  return (args) => new Promise((done, fail) => {
153
219
  (0, child_process_1.execFile)('git', ['-C', checkout, ...args], { encoding: 'utf8', timeout: GIT_TIMEOUT_MS, maxBuffer: GIT_MAX_BUFFER }, (err, stdout) => err ? fail(err) : done(stdout));
package/dist/tags.js CHANGED
@@ -37,4 +37,5 @@ exports.TAG_VALUES = [
37
37
  'Superseded',
38
38
  'SkillDrift',
39
39
  'ScreenFindings',
40
+ 'AppliesTo',
40
41
  ];