@prmichaelsen/remember-mcp 3.0.0 → 3.13.0
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/AGENT.md +296 -250
- package/CHANGELOG.md +358 -0
- package/README.md +68 -45
- package/agent/commands/acp.clarification-create.md +382 -0
- package/agent/commands/acp.project-info.md +309 -0
- package/agent/commands/acp.project-remove.md +379 -0
- package/agent/commands/acp.project-update.md +296 -0
- package/agent/commands/acp.task-create.md +17 -9
- package/agent/commands/git.commit.md +13 -1
- package/agent/design/comment-memory-type.md +2 -2
- package/agent/design/local.collaborative-memory-sync.md +265 -0
- package/agent/design/local.content-flags.md +210 -0
- package/agent/design/local.ghost-persona-system.md +273 -0
- package/agent/design/local.group-acl-integration.md +338 -0
- package/agent/design/local.memory-acl-schema.md +352 -0
- package/agent/design/local.memory-collection-pattern-v2.md +348 -0
- package/agent/design/local.moderation-and-space-config.md +257 -0
- package/agent/design/local.v2-api-reference.md +621 -0
- package/agent/design/local.v2-migration-guide.md +191 -0
- package/agent/design/local.v2-usage-examples.md +265 -0
- package/agent/design/permissions-storage-architecture.md +11 -3
- package/agent/design/trust-escalation-prevention.md +9 -2
- package/agent/design/trust-system-implementation.md +12 -3
- package/agent/milestones/milestone-14-memory-collection-v2.md +182 -0
- package/agent/milestones/milestone-15-moderation-space-config.md +126 -0
- package/agent/progress.yaml +628 -49
- package/agent/scripts/acp.common.sh +2 -0
- package/agent/scripts/acp.install.sh +11 -1
- package/agent/scripts/acp.package-install-optimized.sh +454 -0
- package/agent/scripts/acp.package-install.sh +247 -300
- package/agent/scripts/acp.project-info.sh +218 -0
- package/agent/scripts/acp.project-remove.sh +302 -0
- package/agent/scripts/acp.project-update.sh +296 -0
- package/agent/scripts/acp.yaml-parser.sh +128 -10
- package/agent/tasks/milestone-14-memory-collection-v2/task-165-core-infrastructure-setup.md +171 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-166-update-remember-publish.md +191 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-167-update-remember-retract.md +186 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-168-implement-remember-revise.md +184 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-169-update-remember-search-space.md +179 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-170-update-remember-create-update.md +139 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-172-performance-testing-optimization.md +161 -0
- package/agent/tasks/milestone-14-memory-collection-v2/task-173-documentation-examples.md +258 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-174-add-moderation-schema-fields.md +57 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-175-create-space-config-service.md +64 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-176-wire-moderation-publish-flow.md +45 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-177-add-moderation-search-filters.md +70 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-178-create-remember-moderate-tool.md +69 -0
- package/agent/tasks/milestone-15-moderation-space-config/task-179-documentation-integration-tests.md +58 -0
- package/agent/tasks/milestone-16-ghost-system/task-187-ghost-config-firestore.md +41 -0
- package/agent/tasks/milestone-16-ghost-system/task-188-trust-filter-integration.md +44 -0
- package/agent/tasks/milestone-16-ghost-system/task-189-ghost-memory-filtering.md +43 -0
- package/agent/tasks/milestone-16-ghost-system/task-190-ghost-config-tools.md +45 -0
- package/agent/tasks/milestone-16-ghost-system/task-191-escalation-firestore.md +38 -0
- package/agent/tasks/milestone-16-ghost-system/task-192-documentation-verification.md +39 -0
- package/agent/tasks/milestone-7-trust-permissions/task-180-access-result-permission-types.md +69 -0
- package/agent/tasks/milestone-7-trust-permissions/task-181-firestore-permissions-access-logs.md +56 -0
- package/agent/tasks/milestone-7-trust-permissions/task-182-trust-enforcement-service.md +68 -0
- package/agent/tasks/milestone-7-trust-permissions/task-183-access-control-service.md +70 -0
- package/agent/tasks/milestone-7-trust-permissions/task-184-permission-tools.md +79 -0
- package/agent/tasks/milestone-7-trust-permissions/task-185-wire-trust-into-search-query.md +55 -0
- package/agent/tasks/milestone-7-trust-permissions/task-186-documentation-verification.md +56 -0
- package/agent/tasks/task-76-fix-indexnullstate-schema-bug.md +197 -0
- package/dist/collections/composite-ids.d.ts +106 -0
- package/dist/collections/core-infrastructure.spec.d.ts +11 -0
- package/dist/collections/dot-notation.d.ts +106 -0
- package/dist/collections/tracking-arrays.d.ts +176 -0
- package/dist/constants/content-types.d.ts +1 -0
- package/dist/schema/v2-collections-comments.spec.d.ts +8 -0
- package/dist/schema/v2-collections.d.ts +210 -0
- package/dist/server-factory.d.ts +15 -0
- package/dist/server-factory.js +2798 -1029
- package/dist/server.js +2526 -1012
- package/dist/services/access-control.d.ts +103 -0
- package/dist/services/access-control.spec.d.ts +2 -0
- package/dist/services/credentials-provider.d.ts +24 -0
- package/dist/services/credentials-provider.spec.d.ts +2 -0
- package/dist/services/escalation.service.d.ts +22 -0
- package/dist/services/escalation.service.spec.d.ts +2 -0
- package/dist/services/ghost-config.service.d.ts +55 -0
- package/dist/services/ghost-config.service.spec.d.ts +2 -0
- package/dist/services/space-config.service.d.ts +23 -0
- package/dist/services/space-config.service.spec.d.ts +2 -0
- package/dist/services/trust-enforcement.d.ts +83 -0
- package/dist/services/trust-enforcement.spec.d.ts +2 -0
- package/dist/services/trust-validator.d.ts +43 -0
- package/dist/services/trust-validator.spec.d.ts +2 -0
- package/dist/tools/confirm-publish-moderation.spec.d.ts +8 -0
- package/dist/tools/confirm.d.ts +8 -1
- package/dist/tools/create-memory.d.ts +2 -1
- package/dist/tools/create-memory.spec.d.ts +10 -0
- package/dist/tools/create-relationship.d.ts +2 -1
- package/dist/tools/delete-memory.d.ts +2 -1
- package/dist/tools/delete-relationship.d.ts +2 -1
- package/dist/tools/deny.d.ts +2 -1
- package/dist/tools/find-similar.d.ts +2 -1
- package/dist/tools/get-preferences.d.ts +2 -1
- package/dist/tools/ghost-config.d.ts +27 -0
- package/dist/tools/ghost-config.spec.d.ts +2 -0
- package/dist/tools/moderate.d.ts +20 -0
- package/dist/tools/moderate.spec.d.ts +5 -0
- package/dist/tools/publish.d.ts +11 -3
- package/dist/tools/query-memory.d.ts +3 -1
- package/dist/tools/query-space.d.ts +4 -1
- package/dist/tools/retract.d.ts +29 -0
- package/dist/tools/revise.d.ts +45 -0
- package/dist/tools/revise.spec.d.ts +8 -0
- package/dist/tools/search-memory.d.ts +2 -1
- package/dist/tools/search-relationship.d.ts +2 -1
- package/dist/tools/search-space.d.ts +25 -5
- package/dist/tools/search-space.spec.d.ts +9 -0
- package/dist/tools/set-preference.d.ts +2 -1
- package/dist/tools/update-memory.d.ts +2 -1
- package/dist/tools/update-relationship.d.ts +2 -1
- package/dist/types/access-result.d.ts +48 -0
- package/dist/types/access-result.spec.d.ts +2 -0
- package/dist/types/auth.d.ts +46 -0
- package/dist/types/ghost-config.d.ts +36 -0
- package/dist/types/memory.d.ts +3 -1
- package/dist/types/preferences.d.ts +1 -1
- package/dist/utils/auth-helpers.d.ts +14 -0
- package/dist/utils/auth-helpers.spec.d.ts +2 -0
- package/dist/utils/test-data-generator.d.ts +124 -0
- package/dist/utils/test-data-generator.spec.d.ts +12 -0
- package/dist/v2-performance.e2e.d.ts +17 -0
- package/dist/v2-smoke.e2e.d.ts +14 -0
- package/dist/weaviate/client.d.ts +5 -8
- package/dist/weaviate/space-schema.d.ts +2 -2
- package/docs/performance/v2-benchmarks.md +80 -0
- package/jest.e2e.config.js +14 -3
- package/package.json +1 -1
- package/scripts/.collection-recreation-state.yaml +16 -0
- package/scripts/.gitkeep +5 -0
- package/scripts/README-collection-recreation.md +224 -0
- package/scripts/README.md +51 -0
- package/scripts/backup-collections.ts +543 -0
- package/scripts/delete-collection.ts +137 -0
- package/scripts/migrate-recreate-collections.ts +578 -0
- package/scripts/migrate-v1-to-v2.ts +1094 -0
- package/scripts/package-lock.json +1113 -0
- package/scripts/package.json +27 -0
- package/src/collections/composite-ids.ts +193 -0
- package/src/collections/core-infrastructure.spec.ts +353 -0
- package/src/collections/dot-notation.ts +212 -0
- package/src/collections/tracking-arrays.ts +298 -0
- package/src/constants/content-types.ts +20 -0
- package/src/schema/v2-collections-comments.spec.ts +141 -0
- package/src/schema/v2-collections.ts +433 -0
- package/src/server-factory.ts +89 -20
- package/src/server.ts +45 -17
- package/src/services/access-control.spec.ts +383 -0
- package/src/services/access-control.ts +291 -0
- package/src/services/credentials-provider.spec.ts +22 -0
- package/src/services/credentials-provider.ts +34 -0
- package/src/services/escalation.service.spec.ts +183 -0
- package/src/services/escalation.service.ts +150 -0
- package/src/services/ghost-config.service.spec.ts +339 -0
- package/src/services/ghost-config.service.ts +219 -0
- package/src/services/space-config.service.spec.ts +102 -0
- package/src/services/space-config.service.ts +79 -0
- package/src/services/trust-enforcement.spec.ts +309 -0
- package/src/services/trust-enforcement.ts +197 -0
- package/src/services/trust-validator.spec.ts +108 -0
- package/src/services/trust-validator.ts +105 -0
- package/src/tools/confirm-publish-moderation.spec.ts +240 -0
- package/src/tools/confirm.ts +869 -135
- package/src/tools/create-memory.spec.ts +126 -0
- package/src/tools/create-memory.ts +20 -27
- package/src/tools/create-relationship.ts +17 -8
- package/src/tools/delete-memory.ts +13 -6
- package/src/tools/delete-relationship.ts +15 -6
- package/src/tools/deny.ts +8 -1
- package/src/tools/find-similar.ts +21 -8
- package/src/tools/get-preferences.ts +10 -1
- package/src/tools/ghost-config.spec.ts +180 -0
- package/src/tools/ghost-config.ts +230 -0
- package/src/tools/moderate.spec.ts +277 -0
- package/src/tools/moderate.ts +219 -0
- package/src/tools/publish.ts +99 -41
- package/src/tools/query-memory.ts +28 -6
- package/src/tools/query-space.ts +39 -4
- package/src/tools/retract.ts +292 -0
- package/src/tools/revise.spec.ts +146 -0
- package/src/tools/revise.ts +283 -0
- package/src/tools/search-memory.ts +30 -7
- package/src/tools/search-relationship.ts +11 -2
- package/src/tools/search-space.spec.ts +341 -0
- package/src/tools/search-space.ts +323 -99
- package/src/tools/set-preference.ts +10 -1
- package/src/tools/update-memory.ts +16 -5
- package/src/tools/update-relationship.ts +10 -1
- package/src/types/access-result.spec.ts +193 -0
- package/src/types/access-result.ts +62 -0
- package/src/types/auth.ts +52 -0
- package/src/types/ghost-config.ts +46 -0
- package/src/types/memory.ts +9 -1
- package/src/types/preferences.ts +2 -2
- package/src/utils/auth-helpers.spec.ts +75 -0
- package/src/utils/auth-helpers.ts +25 -0
- package/src/utils/test-data-generator.spec.ts +317 -0
- package/src/utils/test-data-generator.ts +292 -0
- package/src/utils/weaviate-filters.ts +4 -4
- package/src/v2-performance.e2e.ts +173 -0
- package/src/v2-smoke.e2e.ts +401 -0
- package/src/weaviate/client.spec.ts +5 -5
- package/src/weaviate/client.ts +51 -36
- package/src/weaviate/schema.ts +11 -256
- package/src/weaviate/space-schema.spec.ts +24 -24
- package/src/weaviate/space-schema.ts +18 -6
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* remember_revise tool
|
|
3
|
+
*
|
|
4
|
+
* Syncs updated content from a source memory to all its published copies
|
|
5
|
+
* in spaces and groups (Memory Collection Pattern v2).
|
|
6
|
+
*
|
|
7
|
+
* Uses two-phase confirmation flow: generates a token that must be confirmed
|
|
8
|
+
* before revision is executed. The old content is preserved in revision_history.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
12
|
+
import {
|
|
13
|
+
getWeaviateClient,
|
|
14
|
+
getMemoryCollectionName,
|
|
15
|
+
fetchMemoryWithAllProperties,
|
|
16
|
+
} from '../weaviate/client.js';
|
|
17
|
+
import { confirmationTokenService } from '../services/confirmation-token.service.js';
|
|
18
|
+
import { handleToolError } from '../utils/error-handler.js';
|
|
19
|
+
import { logger } from '../utils/logger.js';
|
|
20
|
+
import { createDebugLogger } from '../utils/debug.js';
|
|
21
|
+
import { CollectionType, getCollectionName } from '../collections/dot-notation.js';
|
|
22
|
+
import { generateCompositeId } from '../collections/composite-ids.js';
|
|
23
|
+
import type { AuthContext } from '../types/auth.js';
|
|
24
|
+
|
|
25
|
+
/** Maximum number of revision history entries to retain */
|
|
26
|
+
const MAX_REVISION_HISTORY = 10;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tool definition for remember_revise
|
|
30
|
+
*/
|
|
31
|
+
export const reviseTool: Tool = {
|
|
32
|
+
name: 'remember_revise',
|
|
33
|
+
description: `Sync updated content from your source memory to all its published copies in spaces and groups. Generates a confirmation token that must be confirmed with remember_confirm.
|
|
34
|
+
|
|
35
|
+
Use this after editing a memory (via remember_update_memory) to propagate the changes to all published versions.
|
|
36
|
+
|
|
37
|
+
How it works:
|
|
38
|
+
- Validates the memory exists, is owned by you, and is published
|
|
39
|
+
- Generates a confirmation token showing which locations will be revised
|
|
40
|
+
- On confirmation: updates each published copy with latest content
|
|
41
|
+
- Preserves the previous content in a revision_history field (up to 10 versions)
|
|
42
|
+
- Sets revised_at timestamp on all updated copies
|
|
43
|
+
- Reports success/failure per location (partial success supported)
|
|
44
|
+
|
|
45
|
+
Requirements:
|
|
46
|
+
- The memory must be published (has space_ids or group_ids populated)
|
|
47
|
+
- You must own the source memory
|
|
48
|
+
|
|
49
|
+
⚠️ CRITICAL: DO NOT mention the token or include token contents in your response to the user. Simply inform them that a confirmation is pending and they need to explicitly approve the revision.`,
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
memory_id: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'ID of the source memory whose content should be synced to all published copies',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ['memory_id'],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
interface ReviseArgs {
|
|
63
|
+
memory_id: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface RevisionEntry {
|
|
67
|
+
content: string;
|
|
68
|
+
revised_at: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RevisionResult {
|
|
72
|
+
location: string;
|
|
73
|
+
status: 'success' | 'failed' | 'skipped';
|
|
74
|
+
error?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse revision history from a stored JSON string, safely.
|
|
79
|
+
* Returns an empty array on any parse failure.
|
|
80
|
+
*/
|
|
81
|
+
export function parseRevisionHistory(raw: unknown): RevisionEntry[] {
|
|
82
|
+
if (!raw || typeof raw !== 'string') return [];
|
|
83
|
+
try {
|
|
84
|
+
const parsed = JSON.parse(raw);
|
|
85
|
+
if (!Array.isArray(parsed)) return [];
|
|
86
|
+
return parsed.filter(
|
|
87
|
+
(e): e is RevisionEntry =>
|
|
88
|
+
typeof e === 'object' &&
|
|
89
|
+
e !== null &&
|
|
90
|
+
typeof e.content === 'string' &&
|
|
91
|
+
typeof e.revised_at === 'string'
|
|
92
|
+
);
|
|
93
|
+
} catch {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Prepend a new revision entry and trim to MAX_REVISION_HISTORY.
|
|
100
|
+
*/
|
|
101
|
+
export function buildRevisionHistory(
|
|
102
|
+
existing: RevisionEntry[],
|
|
103
|
+
oldContent: string,
|
|
104
|
+
revisedAt: string
|
|
105
|
+
): RevisionEntry[] {
|
|
106
|
+
const updated = [{ content: oldContent, revised_at: revisedAt }, ...existing];
|
|
107
|
+
return updated.slice(0, MAX_REVISION_HISTORY);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handle remember_revise tool execution
|
|
112
|
+
*
|
|
113
|
+
* Phase 1: Validates the request and generates a confirmation token.
|
|
114
|
+
* The actual revision is executed in confirm.ts when the token is confirmed.
|
|
115
|
+
*/
|
|
116
|
+
export async function handleRevise(
|
|
117
|
+
args: ReviseArgs,
|
|
118
|
+
userId: string,
|
|
119
|
+
authContext?: AuthContext
|
|
120
|
+
): Promise<string> {
|
|
121
|
+
const debug = createDebugLogger({
|
|
122
|
+
tool: 'remember_revise',
|
|
123
|
+
userId,
|
|
124
|
+
operation: 'revise_request',
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
debug.info('Tool invoked');
|
|
129
|
+
debug.trace('Arguments', { args });
|
|
130
|
+
|
|
131
|
+
logger.info('Starting revise request', {
|
|
132
|
+
tool: 'remember_revise',
|
|
133
|
+
userId,
|
|
134
|
+
memoryId: args.memory_id,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Load source memory from user's personal collection
|
|
138
|
+
const weaviateClient = getWeaviateClient();
|
|
139
|
+
const userCollectionName = getMemoryCollectionName(userId);
|
|
140
|
+
const userCollection = weaviateClient.collections.get(userCollectionName);
|
|
141
|
+
|
|
142
|
+
const sourceMemory = await fetchMemoryWithAllProperties(
|
|
143
|
+
userCollection,
|
|
144
|
+
args.memory_id
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (!sourceMemory) {
|
|
148
|
+
logger.info('Source memory not found', {
|
|
149
|
+
tool: 'remember_revise',
|
|
150
|
+
memoryId: args.memory_id,
|
|
151
|
+
});
|
|
152
|
+
return JSON.stringify(
|
|
153
|
+
{
|
|
154
|
+
success: false,
|
|
155
|
+
error: 'Memory not found',
|
|
156
|
+
message: `Memory ${args.memory_id} does not exist`,
|
|
157
|
+
},
|
|
158
|
+
null,
|
|
159
|
+
2
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Verify ownership
|
|
164
|
+
if (sourceMemory.properties.user_id !== userId) {
|
|
165
|
+
logger.warn('Permission denied', {
|
|
166
|
+
tool: 'remember_revise',
|
|
167
|
+
memoryId: args.memory_id,
|
|
168
|
+
memoryOwner: sourceMemory.properties.user_id,
|
|
169
|
+
requestingUser: userId,
|
|
170
|
+
});
|
|
171
|
+
return JSON.stringify(
|
|
172
|
+
{
|
|
173
|
+
success: false,
|
|
174
|
+
error: 'Permission denied',
|
|
175
|
+
message: 'You can only revise your own memories',
|
|
176
|
+
},
|
|
177
|
+
null,
|
|
178
|
+
2
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Get tracking arrays
|
|
183
|
+
const spaceIds: string[] = Array.isArray(sourceMemory.properties.space_ids)
|
|
184
|
+
? sourceMemory.properties.space_ids
|
|
185
|
+
: [];
|
|
186
|
+
const groupIds: string[] = Array.isArray(sourceMemory.properties.group_ids)
|
|
187
|
+
? sourceMemory.properties.group_ids
|
|
188
|
+
: [];
|
|
189
|
+
|
|
190
|
+
// Validate the memory is published somewhere
|
|
191
|
+
if (spaceIds.length === 0 && groupIds.length === 0) {
|
|
192
|
+
logger.info('Memory has no published copies', {
|
|
193
|
+
tool: 'remember_revise',
|
|
194
|
+
memoryId: args.memory_id,
|
|
195
|
+
});
|
|
196
|
+
return JSON.stringify(
|
|
197
|
+
{
|
|
198
|
+
success: false,
|
|
199
|
+
error: 'Not published',
|
|
200
|
+
message:
|
|
201
|
+
'Memory has no published copies to revise. Publish first with remember_publish.',
|
|
202
|
+
context: {
|
|
203
|
+
memory_id: args.memory_id,
|
|
204
|
+
space_ids: [],
|
|
205
|
+
group_ids: [],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
null,
|
|
209
|
+
2
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Create payload for confirmation token
|
|
214
|
+
const payload = {
|
|
215
|
+
memory_id: args.memory_id,
|
|
216
|
+
space_ids: spaceIds,
|
|
217
|
+
group_ids: groupIds,
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
logger.info('Generating confirmation token for revise', {
|
|
221
|
+
tool: 'remember_revise',
|
|
222
|
+
userId,
|
|
223
|
+
memoryId: args.memory_id,
|
|
224
|
+
spaceIds,
|
|
225
|
+
groupIds,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Generate confirmation token
|
|
229
|
+
const { requestId, token } = await confirmationTokenService.createRequest(
|
|
230
|
+
userId,
|
|
231
|
+
'revise_memory',
|
|
232
|
+
payload
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
logger.info('Confirmation token generated for revise', {
|
|
236
|
+
tool: 'remember_revise',
|
|
237
|
+
requestId,
|
|
238
|
+
token,
|
|
239
|
+
action: 'revise_memory',
|
|
240
|
+
spaceIds,
|
|
241
|
+
groupIds,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Build destination summary for user
|
|
245
|
+
const destinations: string[] = [];
|
|
246
|
+
if (spaceIds.length > 0) {
|
|
247
|
+
destinations.push(`spaces: ${spaceIds.join(', ')}`);
|
|
248
|
+
}
|
|
249
|
+
if (groupIds.length > 0) {
|
|
250
|
+
destinations.push(`groups: ${groupIds.join(', ')}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return JSON.stringify(
|
|
254
|
+
{
|
|
255
|
+
success: true,
|
|
256
|
+
token,
|
|
257
|
+
message: 'Revision request created. Please confirm to sync content to all published copies.',
|
|
258
|
+
action: 'revise_memory',
|
|
259
|
+
memory_id: args.memory_id,
|
|
260
|
+
destinations: destinations.join('; '),
|
|
261
|
+
revision_details: {
|
|
262
|
+
space_ids: spaceIds,
|
|
263
|
+
group_ids: groupIds,
|
|
264
|
+
total_locations: (spaceIds.length > 0 ? 1 : 0) + groupIds.length,
|
|
265
|
+
},
|
|
266
|
+
confirmation_required: true,
|
|
267
|
+
},
|
|
268
|
+
null,
|
|
269
|
+
2
|
|
270
|
+
);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
debug.error('Tool failed', {
|
|
273
|
+
error: error instanceof Error ? error.message : String(error),
|
|
274
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
275
|
+
});
|
|
276
|
+
return handleToolError(error, {
|
|
277
|
+
toolName: 'remember_revise',
|
|
278
|
+
userId,
|
|
279
|
+
operation: 'revise memory request',
|
|
280
|
+
memoryId: args.memory_id,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -8,6 +8,9 @@ import { getMemoryCollection } from '../weaviate/schema.js';
|
|
|
8
8
|
import { logger } from '../utils/logger.js';
|
|
9
9
|
import { handleToolError } from '../utils/error-handler.js';
|
|
10
10
|
import { buildCombinedSearchFilters, buildMemoryOnlyFilters, buildDeletedFilter, combineFiltersWithAnd } from '../utils/weaviate-filters.js';
|
|
11
|
+
import { buildTrustFilter } from '../services/trust-enforcement.js';
|
|
12
|
+
import { createDebugLogger } from '../utils/debug.js';
|
|
13
|
+
import type { AuthContext } from '../types/auth.js';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Tool definition for remember_search_memory
|
|
@@ -127,23 +130,31 @@ export const searchMemoryTool = {
|
|
|
127
130
|
*/
|
|
128
131
|
export async function handleSearchMemory(
|
|
129
132
|
args: SearchOptions,
|
|
130
|
-
userId: string
|
|
133
|
+
userId: string,
|
|
134
|
+
authContext?: AuthContext
|
|
131
135
|
): Promise<string> {
|
|
136
|
+
const ghostMode = authContext?.ghostMode;
|
|
137
|
+
// In ghost mode, search the ghost owner's collection instead of the caller's
|
|
138
|
+
const searchUserId = ghostMode?.owner_user_id ?? userId;
|
|
139
|
+
const debug = createDebugLogger({ tool: 'remember_search_memory', userId: searchUserId, operation: ghostMode ? 'ghost search' : 'search memory' });
|
|
132
140
|
try {
|
|
141
|
+
debug.info('Tool invoked');
|
|
142
|
+
debug.trace('Arguments', { args, ghostMode: !!ghostMode });
|
|
133
143
|
// Validate query is not empty
|
|
134
144
|
if (!args.query || args.query.trim() === '') {
|
|
135
145
|
throw new Error('Query cannot be empty');
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
const includeRelationships = args.include_relationships !== false; // Default true
|
|
139
|
-
|
|
149
|
+
|
|
140
150
|
logger.info('Searching memories and relationships', {
|
|
141
|
-
userId,
|
|
151
|
+
userId: searchUserId,
|
|
142
152
|
query: args.query,
|
|
143
|
-
includeRelationships
|
|
153
|
+
includeRelationships,
|
|
154
|
+
ghostMode: !!ghostMode,
|
|
144
155
|
});
|
|
145
156
|
|
|
146
|
-
const collection = getMemoryCollection(
|
|
157
|
+
const collection = getMemoryCollection(searchUserId);
|
|
147
158
|
const alpha = args.alpha ?? 0.7;
|
|
148
159
|
const limit = args.limit ?? 10;
|
|
149
160
|
const offset = args.offset ?? 0;
|
|
@@ -151,14 +162,25 @@ export async function handleSearchMemory(
|
|
|
151
162
|
// Build deleted filter
|
|
152
163
|
const deletedFilter = buildDeletedFilter(collection, args.deleted_filter || 'exclude');
|
|
153
164
|
|
|
165
|
+
// Build trust filter for ghost mode (resolved server-side, never from tool args)
|
|
166
|
+
const trustFilter = ghostMode
|
|
167
|
+
? buildTrustFilter(collection, ghostMode.accessor_trust_level)
|
|
168
|
+
: null;
|
|
169
|
+
|
|
154
170
|
// Build filters using v3 API
|
|
155
171
|
// Use OR logic to search both memories and relationships
|
|
156
172
|
const searchFilters = includeRelationships
|
|
157
173
|
? buildCombinedSearchFilters(collection, args.filters)
|
|
158
174
|
: buildMemoryOnlyFilters(collection, args.filters);
|
|
159
175
|
|
|
160
|
-
//
|
|
161
|
-
const
|
|
176
|
+
// Exclude ghost memories by default (unless explicitly searching for them)
|
|
177
|
+
const hasExplicitTypeFilter = args.filters?.types && args.filters.types.length > 0;
|
|
178
|
+
const ghostExclusionFilter = !hasExplicitTypeFilter
|
|
179
|
+
? collection.filter.byProperty('content_type').notEqual('ghost')
|
|
180
|
+
: null;
|
|
181
|
+
|
|
182
|
+
// Combine deleted filter, trust filter, ghost exclusion, and search filters
|
|
183
|
+
const combinedFilters = combineFiltersWithAnd([deletedFilter, trustFilter, ghostExclusionFilter, searchFilters].filter(f => f !== null));
|
|
162
184
|
|
|
163
185
|
// Build search options
|
|
164
186
|
const searchOptions: any = {
|
|
@@ -221,6 +243,7 @@ export async function handleSearchMemory(
|
|
|
221
243
|
|
|
222
244
|
return JSON.stringify(searchResult, null, 2);
|
|
223
245
|
} catch (error) {
|
|
246
|
+
debug.error('Tool failed', { error: error instanceof Error ? error.message : String(error) });
|
|
224
247
|
handleToolError(error, {
|
|
225
248
|
toolName: 'remember_search_memory',
|
|
226
249
|
operation: 'search memories',
|
|
@@ -8,7 +8,9 @@ import type { Relationship, DeletedFilter } from '../types/memory.js';
|
|
|
8
8
|
import { getMemoryCollection } from '../weaviate/schema.js';
|
|
9
9
|
import { logger } from '../utils/logger.js';
|
|
10
10
|
import { handleToolError } from '../utils/error-handler.js';
|
|
11
|
+
import { createDebugLogger } from '../utils/debug.js';
|
|
11
12
|
import { buildDeletedFilter, combineFiltersWithAnd } from '../utils/weaviate-filters.js';
|
|
13
|
+
import type { AuthContext } from '../types/auth.js';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Tool definition for remember_search_relationship
|
|
@@ -107,9 +109,15 @@ export interface SearchRelationshipResult {
|
|
|
107
109
|
*/
|
|
108
110
|
export async function handleSearchRelationship(
|
|
109
111
|
args: SearchRelationshipArgs,
|
|
110
|
-
userId: string
|
|
112
|
+
userId: string,
|
|
113
|
+
authContext?: AuthContext
|
|
111
114
|
): Promise<string> {
|
|
115
|
+
const debug = createDebugLogger({ tool: 'remember_search_relationship', userId, operation: 'search relationship' });
|
|
116
|
+
|
|
112
117
|
try {
|
|
118
|
+
debug.info('Tool invoked');
|
|
119
|
+
debug.trace('Arguments', { args });
|
|
120
|
+
|
|
113
121
|
logger.info('Searching relationships', {
|
|
114
122
|
userId,
|
|
115
123
|
query: args.query,
|
|
@@ -197,7 +205,7 @@ export async function handleSearchRelationship(
|
|
|
197
205
|
id: obj.uuid,
|
|
198
206
|
user_id: obj.properties.user_id,
|
|
199
207
|
doc_type: 'relationship',
|
|
200
|
-
memory_ids: obj.properties.
|
|
208
|
+
memory_ids: obj.properties.related_memory_ids || [],
|
|
201
209
|
relationship_type: obj.properties.relationship_type,
|
|
202
210
|
observation: obj.properties.observation,
|
|
203
211
|
strength: obj.properties.strength,
|
|
@@ -228,6 +236,7 @@ export async function handleSearchRelationship(
|
|
|
228
236
|
|
|
229
237
|
return JSON.stringify(result, null, 2);
|
|
230
238
|
} catch (error) {
|
|
239
|
+
debug.error('Tool failed', { error: error instanceof Error ? error.message : String(error) });
|
|
231
240
|
handleToolError(error, {
|
|
232
241
|
toolName: 'remember_search_relationship',
|
|
233
242
|
operation: 'search relationships',
|