@prmichaelsen/remember-mcp 2.8.0 → 3.12.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.
Files changed (250) hide show
  1. package/AGENT.md +296 -250
  2. package/CHANGELOG.md +468 -0
  3. package/README.md +163 -46
  4. package/agent/commands/acp.clarification-create.md +382 -0
  5. package/agent/commands/acp.command-create.md +0 -1
  6. package/agent/commands/acp.design-create.md +0 -1
  7. package/agent/commands/acp.init.md +0 -1
  8. package/agent/commands/acp.package-create.md +0 -1
  9. package/agent/commands/acp.package-info.md +0 -1
  10. package/agent/commands/acp.package-install.md +0 -1
  11. package/agent/commands/acp.package-list.md +0 -1
  12. package/agent/commands/acp.package-publish.md +0 -1
  13. package/agent/commands/acp.package-remove.md +0 -1
  14. package/agent/commands/acp.package-search.md +0 -1
  15. package/agent/commands/acp.package-update.md +0 -1
  16. package/agent/commands/acp.package-validate.md +0 -1
  17. package/agent/commands/acp.pattern-create.md +0 -1
  18. package/agent/commands/acp.plan.md +0 -1
  19. package/agent/commands/acp.proceed.md +0 -1
  20. package/agent/commands/acp.project-create.md +0 -1
  21. package/agent/commands/acp.project-info.md +309 -0
  22. package/agent/commands/acp.project-list.md +0 -1
  23. package/agent/commands/acp.project-remove.md +379 -0
  24. package/agent/commands/acp.project-set.md +0 -1
  25. package/agent/commands/acp.project-update.md +296 -0
  26. package/agent/commands/acp.report.md +0 -1
  27. package/agent/commands/acp.resume.md +0 -1
  28. package/agent/commands/acp.status.md +0 -1
  29. package/agent/commands/acp.sync.md +0 -1
  30. package/agent/commands/acp.task-create.md +17 -10
  31. package/agent/commands/acp.update.md +0 -1
  32. package/agent/commands/acp.validate.md +0 -1
  33. package/agent/commands/acp.version-check-for-updates.md +0 -1
  34. package/agent/commands/acp.version-check.md +0 -1
  35. package/agent/commands/acp.version-update.md +0 -1
  36. package/agent/commands/command.template.md +0 -5
  37. package/agent/commands/git.commit.md +13 -2
  38. package/agent/commands/git.init.md +0 -1
  39. package/agent/design/comment-memory-type.md +2 -2
  40. package/agent/design/local.collaborative-memory-sync.md +265 -0
  41. package/agent/design/local.content-flags.md +210 -0
  42. package/agent/design/local.ghost-persona-system.md +273 -0
  43. package/agent/design/local.group-acl-integration.md +338 -0
  44. package/agent/design/local.memory-acl-schema.md +352 -0
  45. package/agent/design/local.memory-collection-pattern-v2.md +348 -0
  46. package/agent/design/local.moderation-and-space-config.md +257 -0
  47. package/agent/design/local.v2-api-reference.md +621 -0
  48. package/agent/design/local.v2-migration-guide.md +191 -0
  49. package/agent/design/local.v2-usage-examples.md +265 -0
  50. package/agent/design/permissions-storage-architecture.md +11 -3
  51. package/agent/design/soft-delete-system.md +291 -0
  52. package/agent/design/trust-escalation-prevention.md +9 -2
  53. package/agent/design/trust-system-implementation.md +12 -3
  54. package/agent/milestones/milestone-13-soft-delete-system.md +306 -0
  55. package/agent/milestones/milestone-14-memory-collection-v2.md +182 -0
  56. package/agent/milestones/milestone-15-moderation-space-config.md +126 -0
  57. package/agent/package.template.yaml +0 -17
  58. package/agent/progress.yaml +762 -49
  59. package/agent/scripts/acp.common.sh +2 -0
  60. package/agent/scripts/acp.install.sh +15 -85
  61. package/agent/scripts/acp.package-install-optimized.sh +454 -0
  62. package/agent/scripts/acp.package-install.sh +248 -380
  63. package/agent/scripts/acp.package-validate.sh +0 -99
  64. package/agent/scripts/acp.project-info.sh +218 -0
  65. package/agent/scripts/acp.project-remove.sh +302 -0
  66. package/agent/scripts/acp.project-update.sh +296 -0
  67. package/agent/scripts/acp.yaml-parser.sh +128 -10
  68. package/agent/tasks/milestone-14-memory-collection-v2/task-165-core-infrastructure-setup.md +171 -0
  69. package/agent/tasks/milestone-14-memory-collection-v2/task-166-update-remember-publish.md +191 -0
  70. package/agent/tasks/milestone-14-memory-collection-v2/task-167-update-remember-retract.md +186 -0
  71. package/agent/tasks/milestone-14-memory-collection-v2/task-168-implement-remember-revise.md +184 -0
  72. package/agent/tasks/milestone-14-memory-collection-v2/task-169-update-remember-search-space.md +179 -0
  73. package/agent/tasks/milestone-14-memory-collection-v2/task-170-update-remember-create-update.md +139 -0
  74. package/agent/tasks/milestone-14-memory-collection-v2/task-172-performance-testing-optimization.md +161 -0
  75. package/agent/tasks/milestone-14-memory-collection-v2/task-173-documentation-examples.md +258 -0
  76. package/agent/tasks/milestone-15-moderation-space-config/task-174-add-moderation-schema-fields.md +57 -0
  77. package/agent/tasks/milestone-15-moderation-space-config/task-175-create-space-config-service.md +64 -0
  78. package/agent/tasks/milestone-15-moderation-space-config/task-176-wire-moderation-publish-flow.md +45 -0
  79. package/agent/tasks/milestone-15-moderation-space-config/task-177-add-moderation-search-filters.md +70 -0
  80. package/agent/tasks/milestone-15-moderation-space-config/task-178-create-remember-moderate-tool.md +69 -0
  81. package/agent/tasks/milestone-15-moderation-space-config/task-179-documentation-integration-tests.md +58 -0
  82. package/agent/tasks/milestone-16-ghost-system/task-187-ghost-config-firestore.md +41 -0
  83. package/agent/tasks/milestone-16-ghost-system/task-188-trust-filter-integration.md +44 -0
  84. package/agent/tasks/milestone-16-ghost-system/task-189-ghost-memory-filtering.md +43 -0
  85. package/agent/tasks/milestone-16-ghost-system/task-190-ghost-config-tools.md +45 -0
  86. package/agent/tasks/milestone-16-ghost-system/task-191-escalation-firestore.md +38 -0
  87. package/agent/tasks/milestone-16-ghost-system/task-192-documentation-verification.md +39 -0
  88. package/agent/tasks/milestone-7-trust-permissions/task-180-access-result-permission-types.md +69 -0
  89. package/agent/tasks/milestone-7-trust-permissions/task-181-firestore-permissions-access-logs.md +56 -0
  90. package/agent/tasks/milestone-7-trust-permissions/task-182-trust-enforcement-service.md +68 -0
  91. package/agent/tasks/milestone-7-trust-permissions/task-183-access-control-service.md +70 -0
  92. package/agent/tasks/milestone-7-trust-permissions/task-184-permission-tools.md +79 -0
  93. package/agent/tasks/milestone-7-trust-permissions/task-185-wire-trust-into-search-query.md +55 -0
  94. package/agent/tasks/milestone-7-trust-permissions/task-186-documentation-verification.md +56 -0
  95. package/agent/tasks/task-70-add-soft-delete-schema-fields.md +165 -0
  96. package/agent/tasks/task-71-implement-delete-confirmation-flow.md +257 -0
  97. package/agent/tasks/task-72-add-deleted-filter-to-search-tools.md +18 -0
  98. package/agent/tasks/task-73-update-relationship-handling.md +18 -0
  99. package/agent/tasks/task-74-add-unit-tests-soft-delete.md +18 -0
  100. package/agent/tasks/task-75-update-documentation-changelog.md +26 -0
  101. package/agent/tasks/task-76-fix-indexnullstate-schema-bug.md +197 -0
  102. package/dist/collections/composite-ids.d.ts +106 -0
  103. package/dist/collections/core-infrastructure.spec.d.ts +11 -0
  104. package/dist/collections/dot-notation.d.ts +106 -0
  105. package/dist/collections/tracking-arrays.d.ts +176 -0
  106. package/dist/constants/content-types.d.ts +1 -0
  107. package/dist/schema/v2-collections-comments.spec.d.ts +8 -0
  108. package/dist/schema/v2-collections.d.ts +210 -0
  109. package/dist/server-factory.d.ts +15 -0
  110. package/dist/server-factory.js +3261 -1316
  111. package/dist/server.js +2926 -1236
  112. package/dist/services/access-control.d.ts +103 -0
  113. package/dist/services/access-control.spec.d.ts +2 -0
  114. package/dist/services/credentials-provider.d.ts +24 -0
  115. package/dist/services/credentials-provider.spec.d.ts +2 -0
  116. package/dist/services/escalation.service.d.ts +22 -0
  117. package/dist/services/escalation.service.spec.d.ts +2 -0
  118. package/dist/services/ghost-config.service.d.ts +55 -0
  119. package/dist/services/ghost-config.service.spec.d.ts +2 -0
  120. package/dist/services/space-config.service.d.ts +23 -0
  121. package/dist/services/space-config.service.spec.d.ts +2 -0
  122. package/dist/services/trust-enforcement.d.ts +83 -0
  123. package/dist/services/trust-enforcement.spec.d.ts +2 -0
  124. package/dist/services/trust-validator.d.ts +43 -0
  125. package/dist/services/trust-validator.spec.d.ts +2 -0
  126. package/dist/tools/confirm-publish-moderation.spec.d.ts +8 -0
  127. package/dist/tools/confirm.d.ts +8 -1
  128. package/dist/tools/create-memory.d.ts +2 -1
  129. package/dist/tools/create-memory.spec.d.ts +10 -0
  130. package/dist/tools/create-relationship.d.ts +2 -1
  131. package/dist/tools/delete-memory.d.ts +7 -31
  132. package/dist/tools/delete-relationship.d.ts +2 -1
  133. package/dist/tools/deny.d.ts +2 -1
  134. package/dist/tools/find-similar.d.ts +10 -2
  135. package/dist/tools/get-preferences.d.ts +2 -1
  136. package/dist/tools/ghost-config.d.ts +27 -0
  137. package/dist/tools/ghost-config.spec.d.ts +2 -0
  138. package/dist/tools/moderate.d.ts +20 -0
  139. package/dist/tools/moderate.spec.d.ts +5 -0
  140. package/dist/tools/publish.d.ts +11 -3
  141. package/dist/tools/query-memory.d.ts +11 -2
  142. package/dist/tools/query-space.d.ts +4 -1
  143. package/dist/tools/retract.d.ts +29 -0
  144. package/dist/tools/revise.d.ts +45 -0
  145. package/dist/tools/revise.spec.d.ts +8 -0
  146. package/dist/tools/search-memory.d.ts +8 -1
  147. package/dist/tools/search-relationship.d.ts +10 -2
  148. package/dist/tools/search-space.d.ts +25 -5
  149. package/dist/tools/search-space.spec.d.ts +9 -0
  150. package/dist/tools/set-preference.d.ts +2 -1
  151. package/dist/tools/update-memory.d.ts +2 -1
  152. package/dist/tools/update-relationship.d.ts +2 -1
  153. package/dist/types/access-result.d.ts +48 -0
  154. package/dist/types/access-result.spec.d.ts +2 -0
  155. package/dist/types/auth.d.ts +46 -0
  156. package/dist/types/ghost-config.d.ts +36 -0
  157. package/dist/types/memory.d.ts +11 -1
  158. package/dist/types/preferences.d.ts +1 -1
  159. package/dist/types/space-memory.d.ts +3 -0
  160. package/dist/utils/auth-helpers.d.ts +14 -0
  161. package/dist/utils/auth-helpers.spec.d.ts +2 -0
  162. package/dist/utils/test-data-generator.d.ts +124 -0
  163. package/dist/utils/test-data-generator.spec.d.ts +12 -0
  164. package/dist/utils/weaviate-filters.d.ts +19 -0
  165. package/dist/v2-performance.e2e.d.ts +17 -0
  166. package/dist/v2-smoke.e2e.d.ts +14 -0
  167. package/dist/weaviate/client.d.ts +5 -8
  168. package/dist/weaviate/space-schema.d.ts +2 -2
  169. package/docs/performance/v2-benchmarks.md +80 -0
  170. package/jest.e2e.config.js +14 -3
  171. package/package.json +1 -1
  172. package/scripts/.collection-recreation-state.yaml +16 -0
  173. package/scripts/.gitkeep +5 -0
  174. package/scripts/README-collection-recreation.md +224 -0
  175. package/scripts/README.md +51 -0
  176. package/scripts/backup-collections.ts +543 -0
  177. package/scripts/delete-collection.ts +137 -0
  178. package/scripts/migrate-recreate-collections.ts +578 -0
  179. package/scripts/migrate-v1-to-v2.ts +1094 -0
  180. package/scripts/package-lock.json +1113 -0
  181. package/scripts/package.json +27 -0
  182. package/src/collections/composite-ids.ts +193 -0
  183. package/src/collections/core-infrastructure.spec.ts +353 -0
  184. package/src/collections/dot-notation.ts +212 -0
  185. package/src/collections/tracking-arrays.ts +298 -0
  186. package/src/constants/content-types.ts +20 -0
  187. package/src/schema/v2-collections-comments.spec.ts +141 -0
  188. package/src/schema/v2-collections.ts +433 -0
  189. package/src/server-factory.ts +89 -20
  190. package/src/server.ts +45 -17
  191. package/src/services/access-control.spec.ts +383 -0
  192. package/src/services/access-control.ts +291 -0
  193. package/src/services/credentials-provider.spec.ts +22 -0
  194. package/src/services/credentials-provider.ts +34 -0
  195. package/src/services/escalation.service.spec.ts +183 -0
  196. package/src/services/escalation.service.ts +150 -0
  197. package/src/services/ghost-config.service.spec.ts +339 -0
  198. package/src/services/ghost-config.service.ts +219 -0
  199. package/src/services/space-config.service.spec.ts +102 -0
  200. package/src/services/space-config.service.ts +79 -0
  201. package/src/services/trust-enforcement.spec.ts +309 -0
  202. package/src/services/trust-enforcement.ts +197 -0
  203. package/src/services/trust-validator.spec.ts +108 -0
  204. package/src/services/trust-validator.ts +105 -0
  205. package/src/tools/confirm-publish-moderation.spec.ts +240 -0
  206. package/src/tools/confirm.ts +914 -116
  207. package/src/tools/create-memory.spec.ts +126 -0
  208. package/src/tools/create-memory.ts +20 -27
  209. package/src/tools/create-relationship.ts +30 -8
  210. package/src/tools/delete-memory.ts +99 -64
  211. package/src/tools/delete-relationship.ts +15 -6
  212. package/src/tools/deny.ts +8 -1
  213. package/src/tools/find-similar.ts +44 -6
  214. package/src/tools/get-preferences.ts +10 -1
  215. package/src/tools/ghost-config.spec.ts +180 -0
  216. package/src/tools/ghost-config.ts +230 -0
  217. package/src/tools/moderate.spec.ts +277 -0
  218. package/src/tools/moderate.ts +219 -0
  219. package/src/tools/publish.ts +99 -41
  220. package/src/tools/query-memory.ts +44 -9
  221. package/src/tools/query-space.ts +39 -4
  222. package/src/tools/retract.ts +292 -0
  223. package/src/tools/revise.spec.ts +146 -0
  224. package/src/tools/revise.ts +283 -0
  225. package/src/tools/search-memory.ts +46 -10
  226. package/src/tools/search-relationship.ts +30 -7
  227. package/src/tools/search-space.spec.ts +341 -0
  228. package/src/tools/search-space.ts +323 -99
  229. package/src/tools/set-preference.ts +10 -1
  230. package/src/tools/update-memory.ts +24 -5
  231. package/src/tools/update-relationship.ts +10 -1
  232. package/src/types/access-result.spec.ts +193 -0
  233. package/src/types/access-result.ts +62 -0
  234. package/src/types/auth.ts +52 -0
  235. package/src/types/ghost-config.ts +46 -0
  236. package/src/types/memory.ts +20 -1
  237. package/src/types/preferences.ts +2 -2
  238. package/src/types/space-memory.ts +5 -0
  239. package/src/utils/auth-helpers.spec.ts +75 -0
  240. package/src/utils/auth-helpers.ts +25 -0
  241. package/src/utils/test-data-generator.spec.ts +317 -0
  242. package/src/utils/test-data-generator.ts +292 -0
  243. package/src/utils/weaviate-filters.ts +32 -5
  244. package/src/v2-performance.e2e.ts +173 -0
  245. package/src/v2-smoke.e2e.ts +401 -0
  246. package/src/weaviate/client.spec.ts +5 -5
  247. package/src/weaviate/client.ts +55 -35
  248. package/src/weaviate/schema.ts +11 -239
  249. package/src/weaviate/space-schema.spec.ts +28 -25
  250. package/src/weaviate/space-schema.ts +35 -11
@@ -1,8 +1,14 @@
1
1
  /**
2
2
  * remember_publish tool
3
3
  *
4
- * Generates a confirmation token for publishing a memory to a shared space.
4
+ * Generates a confirmation token for publishing a memory to shared spaces and/or groups.
5
5
  * This is the first phase of the two-phase publish workflow.
6
+ *
7
+ * Memory Collection Pattern v2:
8
+ * - Supports multi-space publication to Memory_spaces_public
9
+ * - Supports multi-group publication to Memory_groups_{groupId}
10
+ * - Uses composite IDs ({userId}.{memoryId}) for published memories
11
+ * - Maintains tracking arrays (space_ids, group_ids) on source memory
6
12
  */
7
13
 
8
14
  import type { Tool } from '@modelcontextprotocol/sdk/types.js';
@@ -13,13 +19,18 @@ import { handleToolError } from '../utils/error-handler.js';
13
19
  import { SUPPORTED_SPACES } from '../types/space-memory.js';
14
20
  import { logger } from '../utils/logger.js';
15
21
  import { createDebugLogger } from '../utils/debug.js';
22
+ import type { AuthContext } from '../types/auth.js';
16
23
 
17
24
  /**
18
25
  * Tool definition for remember_publish
19
26
  */
20
27
  export const publishTool: Tool = {
21
28
  name: 'remember_publish',
22
- description: `Publish a memory to one or more shared spaces (like "The Void"). The memory will be COPIED (not moved) from your personal collection. Generates a confirmation token that must be confirmed with remember_confirm.
29
+ description: `Publish a memory to one or more shared spaces and/or groups. The memory will be COPIED (not moved) from your personal collection. Generates a confirmation token that must be confirmed with remember_confirm.
30
+
31
+ Publication Destinations:
32
+ - Spaces: Public shared areas (e.g., "the_void", "dogs")
33
+ - Groups: Private group collections (provide group IDs)
23
34
 
24
35
  ⚠️ 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 publication.`,
25
36
  inputSchema: {
@@ -39,6 +50,13 @@ export const publishTool: Tool = {
39
50
  minItems: 1,
40
51
  default: ['the_void'],
41
52
  },
53
+ groups: {
54
+ type: 'array',
55
+ items: { type: 'string' },
56
+ description: 'Group IDs to publish to (e.g., ["group-123", "group-456"]). Can publish to multiple groups at once.',
57
+ minItems: 1,
58
+ default: [],
59
+ },
42
60
  additional_tags: {
43
61
  type: 'array',
44
62
  items: { type: 'string' },
@@ -46,13 +64,14 @@ export const publishTool: Tool = {
46
64
  default: [],
47
65
  },
48
66
  },
49
- required: ['memory_id', 'spaces'],
67
+ required: ['memory_id'],
50
68
  },
51
69
  };
52
70
 
53
71
  interface PublishArgs {
54
72
  memory_id: string;
55
- spaces: string[];
73
+ spaces?: string[];
74
+ groups?: string[];
56
75
  additional_tags?: string[];
57
76
  }
58
77
 
@@ -61,7 +80,8 @@ interface PublishArgs {
61
80
  */
62
81
  export async function handlePublish(
63
82
  args: PublishArgs,
64
- userId: string
83
+ userId: string,
84
+ authContext?: AuthContext
65
85
  ): Promise<string> {
66
86
  const debug = createDebugLogger({
67
87
  tool: 'remember_publish',
@@ -73,56 +93,91 @@ export async function handlePublish(
73
93
  debug.info('Tool invoked');
74
94
  debug.trace('Arguments', { args });
75
95
 
96
+ // Normalize arrays (handle undefined)
97
+ const spaces = args.spaces || [];
98
+ const groups = args.groups || [];
99
+
76
100
  logger.info('Starting publish request', {
77
101
  tool: 'remember_publish',
78
102
  userId,
79
103
  memoryId: args.memory_id,
80
- spaces: args.spaces,
81
- spaceCount: args.spaces.length,
104
+ spaces,
105
+ groups,
106
+ spaceCount: spaces.length,
107
+ groupCount: groups.length,
82
108
  additionalTags: args.additional_tags?.length || 0,
83
109
  });
84
110
 
85
- // Validate all space IDs
86
- debug.debug('Validating space IDs', { spaces: args.spaces });
87
- const invalidSpaces = args.spaces.filter(s => !isValidSpaceId(s));
88
- if (invalidSpaces.length > 0) {
89
- debug.warn('Invalid space IDs detected', { invalidSpaces });
90
- logger.warn('Invalid space IDs provided', {
111
+ // Validate that at least one destination is provided
112
+ if (spaces.length === 0 && groups.length === 0) {
113
+ logger.warn('No destinations provided', {
91
114
  tool: 'remember_publish',
92
- invalidSpaces,
93
- providedSpaces: args.spaces,
115
+ userId,
94
116
  });
95
117
  return JSON.stringify(
96
118
  {
97
119
  success: false,
98
- error: 'Invalid space IDs',
99
- message: `Invalid spaces: ${invalidSpaces.join(', ')}. Supported spaces: ${SUPPORTED_SPACES.join(', ')}`,
100
- context: {
101
- invalid_spaces: invalidSpaces,
102
- provided_spaces: args.spaces,
103
- supported_spaces: SUPPORTED_SPACES,
104
- },
120
+ error: 'No destinations provided',
121
+ message: 'Must specify at least one space or group to publish to',
105
122
  },
106
123
  null,
107
124
  2
108
125
  );
109
126
  }
110
127
 
111
- // Validate not empty
112
- if (args.spaces.length === 0) {
113
- logger.warn('Empty spaces array provided', {
114
- tool: 'remember_publish',
115
- userId,
116
- });
117
- return JSON.stringify(
118
- {
119
- success: false,
120
- error: 'Empty spaces array',
121
- message: 'Must specify at least one space to publish to',
122
- },
123
- null,
124
- 2
125
- );
128
+ // Validate all space IDs
129
+ if (spaces.length > 0) {
130
+ debug.debug('Validating space IDs', { spaces });
131
+ const invalidSpaces = spaces.filter(s => !isValidSpaceId(s));
132
+ if (invalidSpaces.length > 0) {
133
+ debug.warn('Invalid space IDs detected', { invalidSpaces });
134
+ logger.warn('Invalid space IDs provided', {
135
+ tool: 'remember_publish',
136
+ invalidSpaces,
137
+ providedSpaces: spaces,
138
+ });
139
+ return JSON.stringify(
140
+ {
141
+ success: false,
142
+ error: 'Invalid space IDs',
143
+ message: `Invalid spaces: ${invalidSpaces.join(', ')}. Supported spaces: ${SUPPORTED_SPACES.join(', ')}`,
144
+ context: {
145
+ invalid_spaces: invalidSpaces,
146
+ provided_spaces: spaces,
147
+ supported_spaces: SUPPORTED_SPACES,
148
+ },
149
+ },
150
+ null,
151
+ 2
152
+ );
153
+ }
154
+ }
155
+
156
+ // Validate group IDs format (basic validation - no dots allowed)
157
+ if (groups.length > 0) {
158
+ debug.debug('Validating group IDs', { groups });
159
+ const invalidGroups = groups.filter(g => !g || g.includes('.') || g.trim() === '');
160
+ if (invalidGroups.length > 0) {
161
+ debug.warn('Invalid group IDs detected', { invalidGroups });
162
+ logger.warn('Invalid group IDs provided', {
163
+ tool: 'remember_publish',
164
+ invalidGroups,
165
+ providedGroups: groups,
166
+ });
167
+ return JSON.stringify(
168
+ {
169
+ success: false,
170
+ error: 'Invalid group IDs',
171
+ message: 'Group IDs cannot be empty or contain dots',
172
+ context: {
173
+ invalid_groups: invalidGroups,
174
+ provided_groups: groups,
175
+ },
176
+ },
177
+ null,
178
+ 2
179
+ );
180
+ }
126
181
  }
127
182
 
128
183
  // Verify memory exists and user owns it
@@ -206,10 +261,11 @@ export async function handlePublish(
206
261
  );
207
262
  }
208
263
 
209
- // Create payload with memory_id and spaces array
264
+ // Create payload with memory_id, spaces, and groups arrays
210
265
  const payload = {
211
266
  memory_id: args.memory_id,
212
- spaces: args.spaces,
267
+ spaces: spaces,
268
+ groups: groups,
213
269
  additional_tags: args.additional_tags || [],
214
270
  };
215
271
 
@@ -217,7 +273,8 @@ export async function handlePublish(
217
273
  tool: 'remember_publish',
218
274
  userId,
219
275
  memoryId: args.memory_id,
220
- spaces: args.spaces,
276
+ spaces: spaces,
277
+ groups: groups,
221
278
  });
222
279
 
223
280
  // Generate confirmation token
@@ -233,7 +290,8 @@ export async function handlePublish(
233
290
  requestId,
234
291
  token,
235
292
  action: 'publish_memory',
236
- spaces: args.spaces,
293
+ spaces: spaces,
294
+ groups: groups,
237
295
  });
238
296
 
239
297
  // Return minimal response - agent already knows memory details
@@ -3,11 +3,14 @@
3
3
  * RAG (Retrieval-Augmented Generation) queries with natural language
4
4
  */
5
5
 
6
- import type { Memory, SearchFilters } from '../types/memory.js';
6
+ import type { Memory, SearchFilters, DeletedFilter } from '../types/memory.js';
7
7
  import { getMemoryCollection } from '../weaviate/schema.js';
8
8
  import { logger } from '../utils/logger.js';
9
9
  import { handleToolError } from '../utils/error-handler.js';
10
- import { buildCombinedSearchFilters } from '../utils/weaviate-filters.js';
10
+ import { buildCombinedSearchFilters, 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_query_memory
@@ -113,6 +116,12 @@ export const queryMemoryTool = {
113
116
  enum: ['detailed', 'compact'],
114
117
  default: 'detailed',
115
118
  },
119
+ deleted_filter: {
120
+ type: 'string',
121
+ enum: ['exclude', 'include', 'only'],
122
+ default: 'exclude',
123
+ description: 'Filter deleted memories: "exclude" (default, hide deleted), "include" (show all), "only" (show only deleted)',
124
+ },
116
125
  },
117
126
  required: ['query'],
118
127
  },
@@ -128,6 +137,7 @@ export interface QueryMemoryArgs {
128
137
  filters?: SearchFilters;
129
138
  include_context?: boolean;
130
139
  format?: 'detailed' | 'compact';
140
+ deleted_filter?: DeletedFilter;
131
141
  }
132
142
 
133
143
  /**
@@ -135,6 +145,7 @@ export interface QueryMemoryArgs {
135
145
  */
136
146
  export interface RelevantMemory extends Partial<Memory> {
137
147
  relevance: number; // 0-1 relevance score
148
+ content_type?: string; // v2 property name (v1: type)
138
149
  }
139
150
 
140
151
  /**
@@ -153,24 +164,47 @@ export interface QueryMemoryResult {
153
164
  */
154
165
  export async function handleQueryMemory(
155
166
  args: QueryMemoryArgs,
156
- userId: string
167
+ userId: string,
168
+ authContext?: AuthContext
157
169
  ): Promise<string> {
170
+ const ghostMode = authContext?.ghostMode;
171
+ const searchUserId = ghostMode?.owner_user_id ?? userId;
172
+ const debug = createDebugLogger({ tool: 'remember_query_memory', userId: searchUserId, operation: ghostMode ? 'ghost query' : 'query memory' });
158
173
  try {
174
+ debug.info('Tool invoked');
175
+ debug.trace('Arguments', { args, ghostMode: !!ghostMode });
159
176
  // Validate query is not empty
160
177
  if (!args.query || args.query.trim() === '') {
161
178
  throw new Error('Query cannot be empty');
162
179
  }
163
180
 
164
- logger.info('Querying memories', { userId, query: args.query });
181
+ logger.info('Querying memories', { userId: searchUserId, query: args.query, ghostMode: !!ghostMode });
165
182
 
166
- const collection = getMemoryCollection(userId);
183
+ const collection = getMemoryCollection(searchUserId);
167
184
  const limit = args.limit ?? 5;
168
185
  const minRelevance = args.min_relevance ?? 0.6;
169
186
  const includeContext = args.include_context ?? true;
170
187
  const format = args.format ?? 'detailed';
171
188
 
189
+ // Build deleted filter
190
+ const deletedFilter = buildDeletedFilter(collection, args.deleted_filter || 'exclude');
191
+
192
+ // Build trust filter for ghost mode (resolved server-side, never from tool args)
193
+ const trustFilter = ghostMode
194
+ ? buildTrustFilter(collection, ghostMode.accessor_trust_level)
195
+ : null;
196
+
172
197
  // Build filters using v3 API - search both memories and relationships
173
- const filters = buildCombinedSearchFilters(collection, args.filters);
198
+ const searchFilters = buildCombinedSearchFilters(collection, args.filters);
199
+
200
+ // Exclude ghost memories by default (unless explicitly searching for them)
201
+ const hasExplicitTypeFilter = args.filters?.types && args.filters.types.length > 0;
202
+ const ghostExclusionFilter = !hasExplicitTypeFilter
203
+ ? collection.filter.byProperty('content_type').notEqual('ghost')
204
+ : null;
205
+
206
+ // Combine deleted filter, trust filter, ghost exclusion, and search filters
207
+ const combinedFilters = combineFiltersWithAnd([deletedFilter, trustFilter, ghostExclusionFilter, searchFilters].filter(f => f !== null));
174
208
 
175
209
  // Build search options
176
210
  const searchOptions: any = {
@@ -180,8 +214,8 @@ export async function handleQueryMemory(
180
214
  };
181
215
 
182
216
  // Add filters if present
183
- if (filters) {
184
- searchOptions.filters = filters;
217
+ if (combinedFilters) {
218
+ searchOptions.filters = combinedFilters;
185
219
  }
186
220
 
187
221
  // Perform semantic search using nearText
@@ -222,7 +256,7 @@ export async function handleQueryMemory(
222
256
  // Compact format: text summary for easy LLM consumption
223
257
  const summaryParts = relevantMemories.map((mem, idx) => {
224
258
  const title = mem.title ? `"${mem.title}"` : `Memory ${idx + 1}`;
225
- const type = mem.type ? ` [${mem.type}]` : '';
259
+ const type = mem.content_type ? ` [${mem.content_type}]` : '';
226
260
  const relevancePercent = Math.round((mem.relevance ?? 0) * 100);
227
261
  const content = mem.content || '(no content)';
228
262
  const tags = mem.tags && mem.tags.length > 0 ? `\nTags: ${mem.tags.join(', ')}` : '';
@@ -250,6 +284,7 @@ export async function handleQueryMemory(
250
284
 
251
285
  return JSON.stringify(result, null, 2);
252
286
  } catch (error) {
287
+ debug.error('Tool failed', { error: error instanceof Error ? error.message : String(error) });
253
288
  handleToolError(error, {
254
289
  toolName: 'remember_query_memory',
255
290
  operation: 'query memories',
@@ -12,6 +12,10 @@ import { ensurePublicCollection, isValidSpaceId } from '../weaviate/space-schema
12
12
  import { SUPPORTED_SPACES } from '../types/space-memory.js';
13
13
  import { handleToolError } from '../utils/error-handler.js';
14
14
  import { createDebugLogger } from '../utils/debug.js';
15
+ import type { AuthContext } from '../types/auth.js';
16
+ import type { ModerationFilter } from './search-space.js';
17
+ import { buildModerationFilter } from './search-space.js';
18
+ import { canModerateAny } from '../utils/auth-helpers.js';
15
19
 
16
20
  /**
17
21
  * Tool definition for remember_query_space
@@ -66,6 +70,12 @@ Let the query algorithm find ALL relevant memories regardless of type unless exp
66
70
  type: 'string',
67
71
  description: 'Filter memories created before this date (ISO 8601)',
68
72
  },
73
+ moderation_filter: {
74
+ type: 'string',
75
+ enum: ['approved', 'pending', 'rejected', 'removed', 'all'],
76
+ description: 'Filter by moderation status. Default: "approved" (only shows approved/unmoderated). Non-approved filters require moderator permissions.',
77
+ default: 'approved',
78
+ },
69
79
  include_comments: {
70
80
  type: 'boolean',
71
81
  description: 'Include comments in query results (default: false)',
@@ -95,6 +105,7 @@ interface QuerySpaceArgs {
95
105
  min_weight?: number;
96
106
  date_from?: string;
97
107
  date_to?: string;
108
+ moderation_filter?: ModerationFilter;
98
109
  include_comments?: boolean;
99
110
  limit?: number;
100
111
  format?: 'detailed' | 'compact';
@@ -105,7 +116,8 @@ interface QuerySpaceArgs {
105
116
  */
106
117
  export async function handleQuerySpace(
107
118
  args: QuerySpaceArgs,
108
- userId: string // May be used for private spaces in future
119
+ userId: string,
120
+ authContext?: AuthContext
109
121
  ): Promise<string> {
110
122
  const debug = createDebugLogger({
111
123
  tool: 'remember_query_space',
@@ -145,6 +157,20 @@ export async function handleQuerySpace(
145
157
  );
146
158
  }
147
159
 
160
+ // Permission check: non-approved moderation filters require moderator access
161
+ const moderationFilterValue = args.moderation_filter || 'approved';
162
+ if (moderationFilterValue !== 'approved' && !canModerateAny(authContext)) {
163
+ return JSON.stringify(
164
+ {
165
+ success: false,
166
+ error: 'Permission denied',
167
+ message: `Moderator access required to view ${moderationFilterValue} memories in spaces`,
168
+ },
169
+ null,
170
+ 2
171
+ );
172
+ }
173
+
148
174
  const weaviateClient = getWeaviateClient();
149
175
  const publicCollection = await ensurePublicCollection(weaviateClient);
150
176
 
@@ -157,16 +183,25 @@ export async function handleQuerySpace(
157
183
  // Filter by doc_type (memory) - space_memory concept was removed
158
184
  filterList.push(publicCollection.filter.byProperty('doc_type').equal('memory'));
159
185
 
186
+ // Moderation status filter
187
+ const moderationFilter = buildModerationFilter(publicCollection, args.moderation_filter);
188
+ if (moderationFilter) {
189
+ filterList.push(moderationFilter);
190
+ }
191
+
160
192
  // Apply content type filter
161
193
  if (args.content_type) {
162
- filterList.push(publicCollection.filter.byProperty('type').equal(args.content_type));
194
+ filterList.push(publicCollection.filter.byProperty('content_type').equal(args.content_type));
163
195
  }
164
196
 
165
- // Exclude comments by default (unless explicitly included)
197
+ // Exclude comments and ghost memories by default (unless explicitly included)
166
198
  if (!args.include_comments && !args.content_type) {
167
199
  // Only exclude comments if not filtering by content_type
168
200
  // (if content_type is set, user has explicit control)
169
- filterList.push(publicCollection.filter.byProperty('type').notEqual('comment'));
201
+ filterList.push(publicCollection.filter.byProperty('content_type').notEqual('comment'));
202
+ }
203
+ if (!args.content_type) {
204
+ filterList.push(publicCollection.filter.byProperty('content_type').notEqual('ghost'));
170
205
  }
171
206
 
172
207
  // Apply tags filter