@totalreclaw/mcp-server 2.7.0 → 3.0.1

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.
Files changed (58) hide show
  1. package/README.md +47 -7
  2. package/dist/claims-helper.d.ts +79 -31
  3. package/dist/claims-helper.d.ts.map +1 -1
  4. package/dist/claims-helper.js +125 -45
  5. package/dist/claims-helper.js.map +1 -1
  6. package/dist/index.js +177 -40
  7. package/dist/index.js.map +1 -1
  8. package/dist/prompts.d.ts +13 -13
  9. package/dist/prompts.d.ts.map +1 -1
  10. package/dist/prompts.js +111 -178
  11. package/dist/prompts.js.map +1 -1
  12. package/dist/subgraph/store.d.ts +25 -2
  13. package/dist/subgraph/store.d.ts.map +1 -1
  14. package/dist/subgraph/store.js +29 -5
  15. package/dist/subgraph/store.js.map +1 -1
  16. package/dist/tools/consolidate.js +12 -12
  17. package/dist/tools/consolidate.js.map +1 -1
  18. package/dist/tools/debrief.d.ts.map +1 -1
  19. package/dist/tools/debrief.js +11 -3
  20. package/dist/tools/debrief.js.map +1 -1
  21. package/dist/tools/export.d.ts.map +1 -1
  22. package/dist/tools/export.js +61 -12
  23. package/dist/tools/export.js.map +1 -1
  24. package/dist/tools/forget.d.ts +14 -0
  25. package/dist/tools/forget.d.ts.map +1 -1
  26. package/dist/tools/forget.js +8 -2
  27. package/dist/tools/forget.js.map +1 -1
  28. package/dist/tools/import-batch.d.ts.map +1 -1
  29. package/dist/tools/import-batch.js +10 -3
  30. package/dist/tools/import-batch.js.map +1 -1
  31. package/dist/tools/index.d.ts +2 -0
  32. package/dist/tools/index.d.ts.map +1 -1
  33. package/dist/tools/index.js +15 -1
  34. package/dist/tools/index.js.map +1 -1
  35. package/dist/tools/pin.d.ts +8 -0
  36. package/dist/tools/pin.d.ts.map +1 -1
  37. package/dist/tools/pin.js +44 -12
  38. package/dist/tools/pin.js.map +1 -1
  39. package/dist/tools/recall.d.ts.map +1 -1
  40. package/dist/tools/recall.js +63 -10
  41. package/dist/tools/recall.js.map +1 -1
  42. package/dist/tools/remember.d.ts +44 -3
  43. package/dist/tools/remember.d.ts.map +1 -1
  44. package/dist/tools/remember.js +97 -10
  45. package/dist/tools/remember.js.map +1 -1
  46. package/dist/tools/retype.d.ts +119 -0
  47. package/dist/tools/retype.d.ts.map +1 -0
  48. package/dist/tools/retype.js +360 -0
  49. package/dist/tools/retype.js.map +1 -0
  50. package/dist/tools/set-scope.d.ts +57 -0
  51. package/dist/tools/set-scope.d.ts.map +1 -0
  52. package/dist/tools/set-scope.js +118 -0
  53. package/dist/tools/set-scope.js.map +1 -0
  54. package/dist/v1-types.d.ts +79 -0
  55. package/dist/v1-types.d.ts.map +1 -0
  56. package/dist/v1-types.js +104 -0
  57. package/dist/v1-types.js.map +1 -0
  58. package/package.json +7 -2
@@ -0,0 +1,119 @@
1
+ /**
2
+ * `totalreclaw_retype` — change the v1 type of an existing memory.
3
+ *
4
+ * Implementation pattern mirrors `tools/pin.ts`: fetch the original, decrypt,
5
+ * rebuild a new canonical claim with the type override, submit on-chain as a
6
+ * two-payload batch (tombstone old + write new with `superseded_by` link).
7
+ *
8
+ * Spec: `docs/specs/totalreclaw/memory-taxonomy-v1.md` §3-new-MCP-tools.
9
+ */
10
+ import type { SubgraphSearchFact } from '../subgraph/search.js';
11
+ import { type MemoryTypeV1, type MemorySource, type MemoryScope, type MemoryVolatility } from '../v1-types.js';
12
+ import { buildV1ClaimBlob } from '../claims-helper.js';
13
+ export declare const retypeToolDefinition: {
14
+ name: string;
15
+ description: string;
16
+ inputSchema: {
17
+ type: string;
18
+ properties: {
19
+ memory_id: {
20
+ type: string;
21
+ description: string;
22
+ };
23
+ new_type: {
24
+ type: string;
25
+ enum: ("claim" | "preference" | "directive" | "commitment" | "episode" | "summary")[];
26
+ description: string;
27
+ };
28
+ };
29
+ required: string[];
30
+ };
31
+ annotations: {
32
+ readOnlyHint: boolean;
33
+ destructiveHint: boolean;
34
+ idempotentHint: boolean;
35
+ };
36
+ };
37
+ interface ValidatedArgs {
38
+ ok: boolean;
39
+ memoryId: string;
40
+ newType: MemoryTypeV1;
41
+ error: string;
42
+ }
43
+ export declare function validateRetypeArgs(args: unknown): ValidatedArgs;
44
+ export interface MetadataOpDeps {
45
+ owner: string;
46
+ sourceAgent: string;
47
+ fetchFactById: (factId: string) => Promise<SubgraphSearchFact | null>;
48
+ decryptBlob: (hexEncryptedBlob: string) => string;
49
+ encryptBlob: (plaintext: string) => string;
50
+ submitBatch: (protobufPayloads: Buffer[]) => Promise<{
51
+ txHash: string;
52
+ success: boolean;
53
+ }>;
54
+ generateIndices: (text: string, entityNames: string[]) => Promise<{
55
+ blindIndices: string[];
56
+ encryptedEmbedding?: string;
57
+ }>;
58
+ }
59
+ export interface MetadataOpResult {
60
+ success: boolean;
61
+ memory_id: string;
62
+ new_memory_id?: string;
63
+ previous_value?: string;
64
+ new_value?: string;
65
+ idempotent?: boolean;
66
+ tx_hash?: string;
67
+ error?: string;
68
+ }
69
+ /**
70
+ * Parse a decrypted blob into a MemoryClaimV1-shaped object. Handles three
71
+ * input formats:
72
+ *
73
+ * 1. v1 canonical JSON (`{schema_version: "1.0", text, type, source, ...}`)
74
+ * 2. v0 short-key canonical JSON (`{t, c, i, sa, ea, ...}`) — legacy plugin
75
+ * 3. v0 plugin-legacy (`{text, metadata: {type, importance}}`)
76
+ *
77
+ * Returns a v1 shape that callers can mutate then pass to `buildV1ClaimBlob`.
78
+ * The caller is responsible for overriding the specific field being updated.
79
+ */
80
+ export declare function extractV1Fields(decrypted: string): {
81
+ text: string;
82
+ type: MemoryTypeV1;
83
+ source: MemorySource;
84
+ scope?: MemoryScope;
85
+ volatility?: MemoryVolatility;
86
+ reasoning?: string;
87
+ importance?: number;
88
+ confidence?: number;
89
+ createdAt?: string;
90
+ };
91
+ /**
92
+ * Generic supersede operation. Used by retype + set_scope. Builds a fresh v1
93
+ * blob with the caller's field override and submits a two-payload batch
94
+ * (tombstone old + new fact with `superseded_by: old_id`).
95
+ *
96
+ * `buildOverride` produces the v1 claim input given the extracted original.
97
+ * Returns `{ previousValue, newValue }` so the result can surface a readable
98
+ * diff to the tool response.
99
+ */
100
+ export declare function executeMetadataOp<T>(memoryId: string, deps: MetadataOpDeps, readCurrent: (extracted: ReturnType<typeof extractV1Fields>) => T, isNoop: (current: T, next: T) => boolean, buildOverride: (extracted: ReturnType<typeof extractV1Fields>, nextValue: T) => Parameters<typeof buildV1ClaimBlob>[0], nextValue: T, opName: string): Promise<MetadataOpResult>;
101
+ /**
102
+ * Execute the retype operation: build a new v1 claim with `new_type` and
103
+ * chain it over the original via `superseded_by`.
104
+ */
105
+ export declare function executeRetype(memoryId: string, newType: MemoryTypeV1, deps: MetadataOpDeps): Promise<MetadataOpResult>;
106
+ export declare function handleRetype(args: unknown): Promise<{
107
+ content: Array<{
108
+ type: string;
109
+ text: string;
110
+ }>;
111
+ }>;
112
+ export declare function handleRetypeWithDeps(args: unknown, deps: MetadataOpDeps): Promise<{
113
+ content: Array<{
114
+ type: string;
115
+ text: string;
116
+ }>;
117
+ }>;
118
+ export {};
119
+ //# sourceMappingURL=retype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retype.d.ts","sourceRoot":"","sources":["../../src/tools/retype.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAgBvD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;CAwBhC,CAAC;AAIF,UAAU,aAAa;IACrB,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;IACtB,KAAK,EAAE,MAA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D"}
@@ -0,0 +1,360 @@
1
+ "use strict";
2
+ /**
3
+ * `totalreclaw_retype` — change the v1 type of an existing memory.
4
+ *
5
+ * Implementation pattern mirrors `tools/pin.ts`: fetch the original, decrypt,
6
+ * rebuild a new canonical claim with the type override, submit on-chain as a
7
+ * two-payload batch (tombstone old + write new with `superseded_by` link).
8
+ *
9
+ * Spec: `docs/specs/totalreclaw/memory-taxonomy-v1.md` §3-new-MCP-tools.
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.retypeToolDefinition = void 0;
16
+ exports.validateRetypeArgs = validateRetypeArgs;
17
+ exports.extractV1Fields = extractV1Fields;
18
+ exports.executeMetadataOp = executeMetadataOp;
19
+ exports.executeRetype = executeRetype;
20
+ exports.handleRetype = handleRetype;
21
+ exports.handleRetypeWithDeps = handleRetypeWithDeps;
22
+ const node_crypto_1 = __importDefault(require("node:crypto"));
23
+ const store_js_1 = require("../subgraph/store.js");
24
+ const v1_types_js_1 = require("../v1-types.js");
25
+ const claims_helper_js_1 = require("../claims-helper.js");
26
+ // ── Tool definition ──────────────────────────────────────────────────────────
27
+ const RETYPE_DESCRIPTION = 'Reclassify memory to different v1 type.\n' +
28
+ '\nINVOKE WHEN USER SAYS:\n' +
29
+ '- "that was actually a directive, not a preference"\n' +
30
+ '- "more of a decision than a goal" / "retype as claim"\n' +
31
+ '- "file that under directives/commitments"\n' +
32
+ '\nDOES: builds v1 claim with new_type, links via superseded_by, tombstones original. Idempotent.\n' +
33
+ '\nWHEN NOT TO USE:\n' +
34
+ '- text wrong → totalreclaw_forget + totalreclaw_remember\n' +
35
+ '- unsure which memory → totalreclaw_recall first\n' +
36
+ '\nnew_type: claim|preference|directive|commitment|episode|summary.';
37
+ exports.retypeToolDefinition = {
38
+ name: 'totalreclaw_retype',
39
+ description: RETYPE_DESCRIPTION,
40
+ inputSchema: {
41
+ type: 'object',
42
+ properties: {
43
+ memory_id: {
44
+ type: 'string',
45
+ description: 'The ID of the memory to retype (from a prior totalreclaw_recall result).',
46
+ },
47
+ new_type: {
48
+ type: 'string',
49
+ enum: [...v1_types_js_1.VALID_MEMORY_TYPES_V1],
50
+ description: 'New Memory Taxonomy v1 type. One of: claim, preference, directive, commitment, episode, summary.',
51
+ },
52
+ },
53
+ required: ['memory_id', 'new_type'],
54
+ },
55
+ annotations: {
56
+ readOnlyHint: false,
57
+ destructiveHint: false,
58
+ idempotentHint: true,
59
+ },
60
+ };
61
+ function validateRetypeArgs(args) {
62
+ if (!args || typeof args !== 'object') {
63
+ return {
64
+ ok: false,
65
+ memoryId: '',
66
+ newType: 'claim',
67
+ error: 'Invalid input: memory_id and new_type are required',
68
+ };
69
+ }
70
+ const record = args;
71
+ const memoryId = record.memory_id;
72
+ if (typeof memoryId !== 'string' || memoryId.trim().length === 0) {
73
+ return {
74
+ ok: false,
75
+ memoryId: '',
76
+ newType: 'claim',
77
+ error: 'Invalid input: memory_id must be a non-empty string',
78
+ };
79
+ }
80
+ const newType = record.new_type;
81
+ if (typeof newType !== 'string' ||
82
+ !v1_types_js_1.VALID_MEMORY_TYPES_V1.includes(newType)) {
83
+ return {
84
+ ok: false,
85
+ memoryId: memoryId.trim(),
86
+ newType: 'claim',
87
+ error: `Invalid input: new_type must be one of ${v1_types_js_1.VALID_MEMORY_TYPES_V1.join(', ')}`,
88
+ };
89
+ }
90
+ return {
91
+ ok: true,
92
+ memoryId: memoryId.trim(),
93
+ newType: newType,
94
+ error: '',
95
+ };
96
+ }
97
+ /**
98
+ * Parse a decrypted blob into a MemoryClaimV1-shaped object. Handles three
99
+ * input formats:
100
+ *
101
+ * 1. v1 canonical JSON (`{schema_version: "1.0", text, type, source, ...}`)
102
+ * 2. v0 short-key canonical JSON (`{t, c, i, sa, ea, ...}`) — legacy plugin
103
+ * 3. v0 plugin-legacy (`{text, metadata: {type, importance}}`)
104
+ *
105
+ * Returns a v1 shape that callers can mutate then pass to `buildV1ClaimBlob`.
106
+ * The caller is responsible for overriding the specific field being updated.
107
+ */
108
+ function extractV1Fields(decrypted) {
109
+ try {
110
+ const obj = JSON.parse(decrypted);
111
+ // v1 canonical path — presence of top-level text+type (closed enum) is
112
+ // the signature; `schema_version` is omitted when equal to the default
113
+ // (Rust `skip_serializing_if`), so we don't require it.
114
+ if (typeof obj.text === 'string' &&
115
+ typeof obj.type === 'string' &&
116
+ v1_types_js_1.VALID_MEMORY_TYPES_V1.includes(String(obj.type)) &&
117
+ (typeof obj.schema_version !== 'string' ||
118
+ obj.schema_version === v1_types_js_1.MEMORY_CLAIM_V1_SCHEMA_VERSION)) {
119
+ return {
120
+ text: String(obj.text),
121
+ type: v1_types_js_1.VALID_MEMORY_TYPES_V1.includes(String(obj.type))
122
+ ? obj.type
123
+ : 'claim',
124
+ source: typeof obj.source === 'string' ? obj.source : 'user-inferred',
125
+ scope: typeof obj.scope === 'string' ? obj.scope : undefined,
126
+ volatility: typeof obj.volatility === 'string' ? obj.volatility : undefined,
127
+ reasoning: typeof obj.reasoning === 'string' ? obj.reasoning : undefined,
128
+ importance: typeof obj.importance === 'number' ? obj.importance : undefined,
129
+ confidence: typeof obj.confidence === 'number' ? obj.confidence : undefined,
130
+ createdAt: typeof obj.created_at === 'string' ? obj.created_at : undefined,
131
+ };
132
+ }
133
+ // v0 short-key canonical path — map `c` short-key to v1 type, default source user-inferred
134
+ if (typeof obj.t === 'string') {
135
+ const cMap = {
136
+ fact: 'claim',
137
+ claim: 'claim',
138
+ ctx: 'claim',
139
+ dec: 'claim',
140
+ pref: 'preference',
141
+ rule: 'directive',
142
+ goal: 'commitment',
143
+ epi: 'episode',
144
+ sum: 'summary',
145
+ };
146
+ return {
147
+ text: String(obj.t),
148
+ type: cMap[String(obj.c)] ?? 'claim',
149
+ source: 'user-inferred',
150
+ importance: typeof obj.i === 'number' ? Math.max(1, Math.min(10, Math.round(obj.i))) : undefined,
151
+ };
152
+ }
153
+ // v0 plugin-legacy path
154
+ if (typeof obj.text === 'string') {
155
+ const meta = obj.metadata ?? {};
156
+ const typeLegacyToV1 = {
157
+ fact: 'claim',
158
+ context: 'claim',
159
+ decision: 'claim',
160
+ preference: 'preference',
161
+ rule: 'directive',
162
+ goal: 'commitment',
163
+ episodic: 'episode',
164
+ summary: 'summary',
165
+ };
166
+ const legacyType = typeof meta.type === 'string' ? meta.type : 'fact';
167
+ const impFloat = typeof meta.importance === 'number' ? meta.importance : 0.5;
168
+ return {
169
+ text: String(obj.text),
170
+ type: typeLegacyToV1[legacyType] ?? 'claim',
171
+ source: 'user-inferred',
172
+ importance: Math.max(1, Math.min(10, Math.round(impFloat * 10))),
173
+ };
174
+ }
175
+ }
176
+ catch {
177
+ // fall through
178
+ }
179
+ // Raw-text fallback
180
+ return {
181
+ text: decrypted,
182
+ type: 'claim',
183
+ source: 'user-inferred',
184
+ };
185
+ }
186
+ /**
187
+ * Generic supersede operation. Used by retype + set_scope. Builds a fresh v1
188
+ * blob with the caller's field override and submits a two-payload batch
189
+ * (tombstone old + new fact with `superseded_by: old_id`).
190
+ *
191
+ * `buildOverride` produces the v1 claim input given the extracted original.
192
+ * Returns `{ previousValue, newValue }` so the result can surface a readable
193
+ * diff to the tool response.
194
+ */
195
+ async function executeMetadataOp(memoryId, deps, readCurrent, isNoop, buildOverride, nextValue, opName) {
196
+ // 1. Fetch the original fact
197
+ const existing = await deps.fetchFactById(memoryId);
198
+ if (!existing) {
199
+ return {
200
+ success: false,
201
+ memory_id: memoryId,
202
+ error: `Memory not found: ${memoryId}`,
203
+ };
204
+ }
205
+ // 2. Decrypt
206
+ const blobHex = existing.encryptedBlob.startsWith('0x')
207
+ ? existing.encryptedBlob.slice(2)
208
+ : existing.encryptedBlob;
209
+ let plaintext;
210
+ try {
211
+ plaintext = deps.decryptBlob(blobHex);
212
+ }
213
+ catch (err) {
214
+ return {
215
+ success: false,
216
+ memory_id: memoryId,
217
+ error: `Failed to decrypt memory: ${err instanceof Error ? err.message : String(err)}`,
218
+ };
219
+ }
220
+ const extracted = extractV1Fields(plaintext);
221
+ const current = readCurrent(extracted);
222
+ // 3. Idempotent early-exit
223
+ if (isNoop(current, nextValue)) {
224
+ return {
225
+ success: true,
226
+ memory_id: memoryId,
227
+ previous_value: String(current),
228
+ new_value: String(nextValue),
229
+ idempotent: true,
230
+ };
231
+ }
232
+ // 4. Build new v1 blob with the override
233
+ let newBlobPlain;
234
+ try {
235
+ const input = buildOverride(extracted, nextValue);
236
+ newBlobPlain = (0, claims_helper_js_1.buildV1ClaimBlob)(input);
237
+ }
238
+ catch (err) {
239
+ return {
240
+ success: false,
241
+ memory_id: memoryId,
242
+ error: `Failed to build updated claim: ${err instanceof Error ? err.message : String(err)}`,
243
+ };
244
+ }
245
+ // 5. Encrypt
246
+ let newBlobHex;
247
+ try {
248
+ newBlobHex = deps.encryptBlob(newBlobPlain);
249
+ }
250
+ catch (err) {
251
+ return {
252
+ success: false,
253
+ memory_id: memoryId,
254
+ error: `Failed to encrypt updated claim: ${err instanceof Error ? err.message : String(err)}`,
255
+ };
256
+ }
257
+ // 6. Regenerate trapdoors (text didn't change but we want fresh LSH for the
258
+ // new fact id so it's findable in recall).
259
+ let trapdoors;
260
+ try {
261
+ trapdoors = await deps.generateIndices(extracted.text, []);
262
+ }
263
+ catch {
264
+ trapdoors = { blindIndices: [] };
265
+ }
266
+ // 7. Build tombstone + new payloads
267
+ const tombstonePayload = {
268
+ id: memoryId,
269
+ timestamp: new Date().toISOString(),
270
+ owner: deps.owner,
271
+ encryptedBlob: Buffer.from('tombstone').toString('hex'),
272
+ blindIndices: [],
273
+ decayScore: 0,
274
+ source: `mcp_${opName}`,
275
+ contentFp: '',
276
+ agentId: deps.sourceAgent,
277
+ };
278
+ const newFactId = node_crypto_1.default.randomUUID();
279
+ const newPayload = {
280
+ id: newFactId,
281
+ timestamp: new Date().toISOString(),
282
+ owner: deps.owner,
283
+ encryptedBlob: newBlobHex,
284
+ blindIndices: trapdoors.blindIndices,
285
+ decayScore: 0.85, // Retype/scope updates land as active with healthy decay
286
+ source: `mcp_${opName}`,
287
+ contentFp: '',
288
+ agentId: deps.sourceAgent,
289
+ encryptedEmbedding: trapdoors.encryptedEmbedding,
290
+ };
291
+ const payloads = [(0, store_js_1.encodeFactProtobuf)(tombstonePayload), (0, store_js_1.encodeFactProtobuf)(newPayload)];
292
+ // 8. Submit
293
+ try {
294
+ const { txHash, success } = await deps.submitBatch(payloads);
295
+ if (!success) {
296
+ return {
297
+ success: false,
298
+ memory_id: memoryId,
299
+ previous_value: String(current),
300
+ error: 'On-chain batch submission failed',
301
+ tx_hash: txHash,
302
+ };
303
+ }
304
+ return {
305
+ success: true,
306
+ memory_id: memoryId,
307
+ new_memory_id: newFactId,
308
+ previous_value: String(current),
309
+ new_value: String(nextValue),
310
+ tx_hash: txHash,
311
+ };
312
+ }
313
+ catch (err) {
314
+ return {
315
+ success: false,
316
+ memory_id: memoryId,
317
+ previous_value: String(current),
318
+ error: `Failed to submit batch: ${err instanceof Error ? err.message : String(err)}`,
319
+ };
320
+ }
321
+ }
322
+ // ── Public entry point ───────────────────────────────────────────────────────
323
+ /**
324
+ * Execute the retype operation: build a new v1 claim with `new_type` and
325
+ * chain it over the original via `superseded_by`.
326
+ */
327
+ async function executeRetype(memoryId, newType, deps) {
328
+ return executeMetadataOp(memoryId, deps, (e) => e.type, (cur, next) => cur === next, (e, next) => ({
329
+ text: e.text,
330
+ type: next,
331
+ source: e.source,
332
+ scope: e.scope,
333
+ volatility: e.volatility,
334
+ reasoning: e.reasoning,
335
+ importance: e.importance,
336
+ confidence: e.confidence,
337
+ createdAt: e.createdAt,
338
+ supersededBy: memoryId,
339
+ }), newType, 'retype');
340
+ }
341
+ // ── Handler wrappers ─────────────────────────────────────────────────────────
342
+ async function handleRetype(args) {
343
+ const validation = validateRetypeArgs(args);
344
+ if (!validation.ok) {
345
+ return errorResponse(validation.error);
346
+ }
347
+ // HTTP (self-hosted) mode: not yet supported — same policy as pin/unpin.
348
+ return errorResponse('Retype is only supported with the managed service. Self-hosted mode does not yet implement v1 supersession.');
349
+ }
350
+ async function handleRetypeWithDeps(args, deps) {
351
+ const validation = validateRetypeArgs(args);
352
+ if (!validation.ok)
353
+ return errorResponse(validation.error);
354
+ const result = await executeRetype(validation.memoryId, validation.newType, deps);
355
+ return { content: [{ type: 'text', text: JSON.stringify(result) }] };
356
+ }
357
+ function errorResponse(error) {
358
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error }) }] };
359
+ }
360
+ //# sourceMappingURL=retype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retype.js","sourceRoot":"","sources":["../../src/tools/retype.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAgEH,gDAqCC;AAyCD,0CA8FC;AAWD,8CA8IC;AAqBD,sCAyBC;AAID,oCAWC;AAED,oDAQC;AA1cD,8DAAiC;AAEjC,mDAA0D;AAC1D,gDAOwB;AACxB,0DAAuD;AAEvD,gFAAgF;AAEhF,MAAM,kBAAkB,GACtB,2CAA2C;IAC3C,4BAA4B;IAC5B,uDAAuD;IACvD,0DAA0D;IAC1D,8CAA8C;IAC9C,oGAAoG;IACpG,sBAAsB;IACtB,4DAA4D;IAC5D,oDAAoD;IACpD,oEAAoE,CAAC;AAE1D,QAAA,oBAAoB,GAAG;IAClC,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,kBAAkB;IAC/B,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0EAA0E;aACxF;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,GAAG,mCAAqB,CAAC;gBAChC,WAAW,EACT,kGAAkG;aACrG;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;KACpC;IACD,WAAW,EAAE;QACX,YAAY,EAAE,KAA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I,CAAC,UAAU,CAAC,EAAE;QAAE,OAAO,aAAa,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AACvE,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `totalreclaw_set_scope` — set or change the v1 scope of an existing memory.
3
+ *
4
+ * Uses the same supersede pattern as `retype` and `pin`: rebuild the inner
5
+ * claim with the scope override, tombstone the old fact id, write the new
6
+ * one with `superseded_by` linking back.
7
+ *
8
+ * Spec: `docs/specs/totalreclaw/memory-taxonomy-v1.md` §3-new-MCP-tools.
9
+ */
10
+ import { type MemoryScope } from '../v1-types.js';
11
+ import { type MetadataOpDeps, type MetadataOpResult } from './retype.js';
12
+ export declare const setScopeToolDefinition: {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: {
16
+ type: string;
17
+ properties: {
18
+ memory_id: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ scope: {
23
+ type: string;
24
+ enum: ("work" | "personal" | "health" | "family" | "creative" | "finance" | "misc" | "unspecified")[];
25
+ description: string;
26
+ };
27
+ };
28
+ required: string[];
29
+ };
30
+ annotations: {
31
+ readOnlyHint: boolean;
32
+ destructiveHint: boolean;
33
+ idempotentHint: boolean;
34
+ };
35
+ };
36
+ interface ValidatedArgs {
37
+ ok: boolean;
38
+ memoryId: string;
39
+ scope: MemoryScope;
40
+ error: string;
41
+ }
42
+ export declare function validateSetScopeArgs(args: unknown): ValidatedArgs;
43
+ export declare function executeSetScope(memoryId: string, newScope: MemoryScope, deps: MetadataOpDeps): Promise<MetadataOpResult>;
44
+ export declare function handleSetScope(args: unknown): Promise<{
45
+ content: Array<{
46
+ type: string;
47
+ text: string;
48
+ }>;
49
+ }>;
50
+ export declare function handleSetScopeWithDeps(args: unknown, deps: MetadataOpDeps): Promise<{
51
+ content: Array<{
52
+ type: string;
53
+ text: string;
54
+ }>;
55
+ }>;
56
+ export {};
57
+ //# sourceMappingURL=set-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-scope.d.ts","sourceRoot":"","sources":["../../src/tools/set-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AAarB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;CAwBlC,CAAC;AAEF,UAAU,aAAa;IACrB,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,CAkCjE;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAQ7D;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAK7D"}