forge-openclaw-plugin 0.2.19 → 0.2.21

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 (82) hide show
  1. package/README.md +133 -2
  2. package/dist/assets/board-_C6oMy5w.js +6 -0
  3. package/dist/assets/{board-8L3uX7_O.js.map → board-_C6oMy5w.js.map} +1 -1
  4. package/dist/assets/index-B4A6TooJ.js +63 -0
  5. package/dist/assets/index-B4A6TooJ.js.map +1 -0
  6. package/dist/assets/index-D6Xs_2mo.css +1 -0
  7. package/dist/assets/{motion-1GAqqi8M.js → motion-D4sZgCHd.js} +2 -2
  8. package/dist/assets/{motion-1GAqqi8M.js.map → motion-D4sZgCHd.js.map} +1 -1
  9. package/dist/assets/{table-DBGlgRjk.js → table-BWzTaky1.js} +2 -2
  10. package/dist/assets/{table-DBGlgRjk.js.map → table-BWzTaky1.js.map} +1 -1
  11. package/dist/assets/{ui-iTluWjC4.js → ui-BzK4azQb.js} +7 -7
  12. package/dist/assets/{ui-iTluWjC4.js.map → ui-BzK4azQb.js.map} +1 -1
  13. package/dist/assets/vendor-DT3pnAKJ.css +1 -0
  14. package/dist/assets/vendor-De38P6YR.js +729 -0
  15. package/dist/assets/vendor-De38P6YR.js.map +1 -0
  16. package/dist/assets/viz-C6hfyqzu.js +34 -0
  17. package/dist/assets/viz-C6hfyqzu.js.map +1 -0
  18. package/dist/index.html +9 -9
  19. package/dist/openclaw/parity.d.ts +1 -1
  20. package/dist/openclaw/parity.js +29 -2
  21. package/dist/openclaw/routes.js +207 -24
  22. package/dist/openclaw/tools.js +324 -35
  23. package/dist/server/app.js +2080 -92
  24. package/dist/server/db.js +3 -0
  25. package/dist/server/health.js +1284 -0
  26. package/dist/server/managers/platform/background-job-manager.js +138 -2
  27. package/dist/server/managers/platform/llm-manager.js +126 -0
  28. package/dist/server/managers/platform/openai-responses-provider.js +773 -0
  29. package/dist/server/managers/runtime.js +6 -1
  30. package/dist/server/openapi.js +718 -0
  31. package/dist/server/preferences-seeds.js +409 -0
  32. package/dist/server/preferences-types.js +368 -0
  33. package/dist/server/psyche-types.js +42 -18
  34. package/dist/server/repositories/activity-events.js +53 -4
  35. package/dist/server/repositories/calendar.js +89 -15
  36. package/dist/server/repositories/collaboration.js +8 -3
  37. package/dist/server/repositories/diagnostic-logs.js +243 -0
  38. package/dist/server/repositories/entity-ownership.js +92 -0
  39. package/dist/server/repositories/goals.js +7 -2
  40. package/dist/server/repositories/habits.js +122 -16
  41. package/dist/server/repositories/notes.js +119 -41
  42. package/dist/server/repositories/preferences.js +1765 -0
  43. package/dist/server/repositories/projects.js +18 -7
  44. package/dist/server/repositories/psyche.js +84 -27
  45. package/dist/server/repositories/rewards.js +112 -4
  46. package/dist/server/repositories/strategies.js +450 -0
  47. package/dist/server/repositories/tags.js +11 -6
  48. package/dist/server/repositories/task-runs.js +10 -2
  49. package/dist/server/repositories/tasks.js +99 -17
  50. package/dist/server/repositories/users.js +417 -0
  51. package/dist/server/repositories/wiki-memory.js +3366 -0
  52. package/dist/server/services/context.js +20 -18
  53. package/dist/server/services/dashboard.js +29 -6
  54. package/dist/server/services/entity-crud.js +21 -3
  55. package/dist/server/services/insights.js +9 -7
  56. package/dist/server/services/projects.js +2 -1
  57. package/dist/server/services/psyche.js +10 -9
  58. package/dist/server/types.js +594 -30
  59. package/openclaw.plugin.json +1 -1
  60. package/package.json +1 -1
  61. package/server/migrations/015_multi_user_and_strategies.sql +244 -0
  62. package/server/migrations/016_health_companion.sql +158 -0
  63. package/server/migrations/016_strategy_contracts_and_user_graph.sql +22 -0
  64. package/server/migrations/017_preferences.sql +131 -0
  65. package/server/migrations/018_preference_catalogs.sql +31 -0
  66. package/server/migrations/019_wiki_memory.sql +255 -0
  67. package/server/migrations/020_wiki_page_hierarchy.sql +11 -0
  68. package/server/migrations/021_hide_evidence_from_wiki_index.sql +3 -0
  69. package/server/migrations/022_wiki_ingest_background.sql +85 -0
  70. package/server/migrations/023_diagnostic_logs.sql +28 -0
  71. package/skills/forge-openclaw/SKILL.md +126 -34
  72. package/skills/forge-openclaw/entity_conversation_playbooks.md +337 -0
  73. package/skills/forge-openclaw/psyche_entity_playbooks.md +404 -0
  74. package/dist/assets/board-8L3uX7_O.js +0 -6
  75. package/dist/assets/index-Cj1IBH_w.js +0 -36
  76. package/dist/assets/index-Cj1IBH_w.js.map +0 -1
  77. package/dist/assets/index-DQT6EbuS.css +0 -1
  78. package/dist/assets/vendor-BvM2F9Dp.js +0 -503
  79. package/dist/assets/vendor-BvM2F9Dp.js.map +0 -1
  80. package/dist/assets/vendor-CRS-psbw.css +0 -1
  81. package/dist/assets/viz-CNeunkfu.js +0 -34
  82. package/dist/assets/viz-CNeunkfu.js.map +0 -1
@@ -0,0 +1,368 @@
1
+ import { z } from "zod";
2
+ import { crudEntityTypeSchema, userSummarySchema } from "./types.js";
3
+ const trimmedString = z.string().trim();
4
+ const nonEmptyTrimmedString = trimmedString.min(1);
5
+ export const preferenceDomainSchema = z.enum([
6
+ "projects",
7
+ "tasks",
8
+ "strategies",
9
+ "habits",
10
+ "calendar",
11
+ "sleep",
12
+ "sports",
13
+ "activities",
14
+ "food",
15
+ "places",
16
+ "countries",
17
+ "fashion",
18
+ "people",
19
+ "media",
20
+ "tools",
21
+ "custom"
22
+ ]);
23
+ export const preferenceCatalogSourceSchema = z.enum(["seeded", "custom"]);
24
+ export const preferenceContextShareModeSchema = z.enum([
25
+ "shared",
26
+ "isolated",
27
+ "blended"
28
+ ]);
29
+ export const preferenceJudgmentOutcomeSchema = z.enum([
30
+ "left",
31
+ "right",
32
+ "tie",
33
+ "skip"
34
+ ]);
35
+ export const preferenceSignalTypeSchema = z.enum([
36
+ "favorite",
37
+ "veto",
38
+ "must_have",
39
+ "bookmark",
40
+ "neutral",
41
+ "compare_later"
42
+ ]);
43
+ export const preferenceDimensionIdSchema = z.enum([
44
+ "novelty",
45
+ "simplicity",
46
+ "rigor",
47
+ "aesthetics",
48
+ "depth",
49
+ "structure",
50
+ "familiarity",
51
+ "surprise"
52
+ ]);
53
+ export const preferenceItemStatusSchema = z.enum([
54
+ "liked",
55
+ "disliked",
56
+ "uncertain",
57
+ "vetoed",
58
+ "bookmarked",
59
+ "favorite",
60
+ "must_have",
61
+ "neutral"
62
+ ]);
63
+ export const preferenceDimensionVectorSchema = z.object({
64
+ novelty: z.number().min(-1).max(1).default(0),
65
+ simplicity: z.number().min(-1).max(1).default(0),
66
+ rigor: z.number().min(-1).max(1).default(0),
67
+ aesthetics: z.number().min(-1).max(1).default(0),
68
+ depth: z.number().min(-1).max(1).default(0),
69
+ structure: z.number().min(-1).max(1).default(0),
70
+ familiarity: z.number().min(-1).max(1).default(0),
71
+ surprise: z.number().min(-1).max(1).default(0)
72
+ });
73
+ export const preferenceLinkedEntitySchema = z.object({
74
+ entityType: crudEntityTypeSchema,
75
+ entityId: nonEmptyTrimmedString
76
+ });
77
+ export const preferenceProfileSchema = z.object({
78
+ id: z.string(),
79
+ userId: nonEmptyTrimmedString,
80
+ domain: preferenceDomainSchema,
81
+ defaultContextId: z.string().nullable(),
82
+ modelVersion: nonEmptyTrimmedString,
83
+ createdAt: z.string(),
84
+ updatedAt: z.string(),
85
+ user: userSummarySchema.nullable().optional()
86
+ });
87
+ export const preferenceContextSchema = z.object({
88
+ id: z.string(),
89
+ profileId: nonEmptyTrimmedString,
90
+ name: nonEmptyTrimmedString,
91
+ description: trimmedString.default(""),
92
+ shareMode: preferenceContextShareModeSchema,
93
+ active: z.boolean(),
94
+ isDefault: z.boolean(),
95
+ decayDays: z.number().int().min(7).max(365),
96
+ createdAt: z.string(),
97
+ updatedAt: z.string()
98
+ });
99
+ export const preferenceItemSchema = z.object({
100
+ id: z.string(),
101
+ profileId: nonEmptyTrimmedString,
102
+ label: nonEmptyTrimmedString,
103
+ description: trimmedString.default(""),
104
+ tags: z.array(nonEmptyTrimmedString).default([]),
105
+ featureWeights: preferenceDimensionVectorSchema,
106
+ sourceEntityType: crudEntityTypeSchema.nullable().optional(),
107
+ sourceEntityId: z.string().nullable().optional(),
108
+ linkedEntity: preferenceLinkedEntitySchema.nullable().optional(),
109
+ metadata: z.record(z.string(), z.unknown()).default({}),
110
+ createdAt: z.string(),
111
+ updatedAt: z.string()
112
+ });
113
+ export const preferenceCatalogItemSchema = z.object({
114
+ id: z.string(),
115
+ catalogId: nonEmptyTrimmedString,
116
+ label: nonEmptyTrimmedString,
117
+ description: trimmedString.default(""),
118
+ tags: z.array(nonEmptyTrimmedString).default([]),
119
+ featureWeights: preferenceDimensionVectorSchema,
120
+ position: z.number().int().min(0),
121
+ createdAt: z.string(),
122
+ updatedAt: z.string()
123
+ });
124
+ export const preferenceCatalogSchema = z.object({
125
+ id: z.string(),
126
+ profileId: nonEmptyTrimmedString,
127
+ domain: preferenceDomainSchema,
128
+ slug: nonEmptyTrimmedString,
129
+ title: nonEmptyTrimmedString,
130
+ description: trimmedString.default(""),
131
+ source: preferenceCatalogSourceSchema,
132
+ createdAt: z.string(),
133
+ updatedAt: z.string(),
134
+ items: z.array(preferenceCatalogItemSchema).default([])
135
+ });
136
+ export const pairwiseJudgmentSchema = z.object({
137
+ id: z.string(),
138
+ profileId: nonEmptyTrimmedString,
139
+ contextId: nonEmptyTrimmedString,
140
+ userId: nonEmptyTrimmedString,
141
+ leftItemId: nonEmptyTrimmedString,
142
+ rightItemId: nonEmptyTrimmedString,
143
+ outcome: preferenceJudgmentOutcomeSchema,
144
+ strength: z.number().min(0.5).max(2),
145
+ responseTimeMs: z.number().int().nullable(),
146
+ source: nonEmptyTrimmedString,
147
+ reasonTags: z.array(nonEmptyTrimmedString).default([]),
148
+ createdAt: z.string()
149
+ });
150
+ export const absoluteSignalSchema = z.object({
151
+ id: z.string(),
152
+ profileId: nonEmptyTrimmedString,
153
+ contextId: nonEmptyTrimmedString,
154
+ userId: nonEmptyTrimmedString,
155
+ itemId: nonEmptyTrimmedString,
156
+ signalType: preferenceSignalTypeSchema,
157
+ strength: z.number().min(0.5).max(2),
158
+ source: nonEmptyTrimmedString,
159
+ createdAt: z.string()
160
+ });
161
+ export const preferenceItemScoreSchema = z.object({
162
+ id: z.string(),
163
+ profileId: nonEmptyTrimmedString,
164
+ contextId: nonEmptyTrimmedString,
165
+ itemId: nonEmptyTrimmedString,
166
+ latentScore: z.number(),
167
+ confidence: z.number().min(0).max(1),
168
+ uncertainty: z.number().min(0).max(1),
169
+ evidenceCount: z.number().int().min(0),
170
+ pairwiseWins: z.number().int().min(0),
171
+ pairwiseLosses: z.number().int().min(0),
172
+ pairwiseTies: z.number().int().min(0),
173
+ signalCount: z.number().int().min(0),
174
+ conflictCount: z.number().int().min(0),
175
+ status: preferenceItemStatusSchema,
176
+ dominantDimensions: z.array(preferenceDimensionIdSchema).default([]),
177
+ explanation: z.array(trimmedString).default([]),
178
+ manualStatus: preferenceItemStatusSchema.nullable().optional(),
179
+ manualScore: z.number().nullable().optional(),
180
+ confidenceLock: z.number().min(0).max(1).nullable().optional(),
181
+ bookmarked: z.boolean(),
182
+ compareLater: z.boolean(),
183
+ frozen: z.boolean(),
184
+ lastInferredAt: z.string(),
185
+ lastJudgmentAt: z.string().nullable(),
186
+ updatedAt: z.string(),
187
+ item: preferenceItemSchema.optional()
188
+ });
189
+ export const preferenceDimensionSummarySchema = z.object({
190
+ id: z.string(),
191
+ profileId: nonEmptyTrimmedString,
192
+ contextId: nonEmptyTrimmedString,
193
+ dimensionId: preferenceDimensionIdSchema,
194
+ leaning: z.number().min(-1).max(1),
195
+ confidence: z.number().min(0).max(1),
196
+ movement: z.number().min(-1).max(1),
197
+ contextSensitivity: z.number().min(0).max(1),
198
+ evidenceCount: z.number().int().min(0),
199
+ updatedAt: z.string()
200
+ });
201
+ export const preferenceSnapshotSchema = z.object({
202
+ id: z.string(),
203
+ profileId: nonEmptyTrimmedString,
204
+ contextId: nonEmptyTrimmedString,
205
+ summaryMetrics: z.record(z.string(), z.unknown()),
206
+ serializedModelState: z.record(z.string(), z.unknown()),
207
+ createdAt: z.string()
208
+ });
209
+ export const preferenceMapPointSchema = z.object({
210
+ itemId: nonEmptyTrimmedString,
211
+ label: nonEmptyTrimmedString,
212
+ x: z.number(),
213
+ y: z.number(),
214
+ score: z.number(),
215
+ confidence: z.number().min(0).max(1),
216
+ uncertainty: z.number().min(0).max(1),
217
+ status: preferenceItemStatusSchema,
218
+ clusterKey: trimmedString,
219
+ tags: z.array(nonEmptyTrimmedString).default([]),
220
+ sourceEntityType: crudEntityTypeSchema.nullable().optional(),
221
+ sourceEntityId: z.string().nullable().optional()
222
+ });
223
+ export const preferenceComparePairSchema = z.object({
224
+ left: preferenceItemSchema,
225
+ right: preferenceItemSchema,
226
+ rationale: z.array(trimmedString).default([]),
227
+ score: z.number()
228
+ });
229
+ export const preferenceWorkspacePayloadSchema = z.object({
230
+ profile: preferenceProfileSchema,
231
+ selectedContext: preferenceContextSchema,
232
+ contexts: z.array(preferenceContextSchema),
233
+ catalogs: z.array(preferenceCatalogSchema),
234
+ dimensions: z.array(preferenceDimensionSummarySchema),
235
+ scores: z.array(preferenceItemScoreSchema),
236
+ map: z.array(preferenceMapPointSchema),
237
+ history: z.object({
238
+ judgments: z.array(pairwiseJudgmentSchema),
239
+ signals: z.array(absoluteSignalSchema),
240
+ snapshots: z.array(preferenceSnapshotSchema),
241
+ staleItemIds: z.array(nonEmptyTrimmedString).default([]),
242
+ flippedItemIds: z.array(nonEmptyTrimmedString).default([])
243
+ }),
244
+ compare: z.object({
245
+ nextPair: preferenceComparePairSchema.nullable(),
246
+ pendingCount: z.number().int().min(0),
247
+ candidateCount: z.number().int().min(0)
248
+ }),
249
+ summary: z.object({
250
+ totalItems: z.number().int().min(0),
251
+ likedCount: z.number().int().min(0),
252
+ dislikedCount: z.number().int().min(0),
253
+ uncertainCount: z.number().int().min(0),
254
+ bookmarkedCount: z.number().int().min(0),
255
+ vetoedCount: z.number().int().min(0),
256
+ averageConfidence: z.number().min(0).max(1),
257
+ pendingComparisons: z.number().int().min(0)
258
+ }),
259
+ libraries: z.object({
260
+ totalCatalogs: z.number().int().min(0),
261
+ totalCatalogItems: z.number().int().min(0),
262
+ seededCatalogCount: z.number().int().min(0),
263
+ customCatalogCount: z.number().int().min(0)
264
+ })
265
+ });
266
+ export const preferenceWorkspaceQuerySchema = z.object({
267
+ userId: nonEmptyTrimmedString.optional(),
268
+ domain: preferenceDomainSchema.optional(),
269
+ contextId: nonEmptyTrimmedString.optional()
270
+ });
271
+ export const createPreferenceContextSchema = z.object({
272
+ userId: nonEmptyTrimmedString,
273
+ domain: preferenceDomainSchema,
274
+ name: nonEmptyTrimmedString,
275
+ description: trimmedString.default(""),
276
+ shareMode: preferenceContextShareModeSchema.default("blended"),
277
+ active: z.boolean().default(true),
278
+ isDefault: z.boolean().default(false),
279
+ decayDays: z.number().int().min(7).max(365).default(90)
280
+ });
281
+ export const updatePreferenceContextSchema = createPreferenceContextSchema
282
+ .omit({ userId: true, domain: true })
283
+ .partial();
284
+ export const mergePreferenceContextsSchema = z.object({
285
+ sourceContextId: nonEmptyTrimmedString,
286
+ targetContextId: nonEmptyTrimmedString
287
+ });
288
+ export const createPreferenceItemSchema = z.object({
289
+ userId: nonEmptyTrimmedString,
290
+ domain: preferenceDomainSchema,
291
+ label: nonEmptyTrimmedString,
292
+ description: trimmedString.default(""),
293
+ tags: z.array(nonEmptyTrimmedString).default([]),
294
+ featureWeights: preferenceDimensionVectorSchema.default({}),
295
+ sourceEntityType: crudEntityTypeSchema.nullable().optional(),
296
+ sourceEntityId: z.string().nullable().optional(),
297
+ metadata: z.record(z.string(), z.unknown()).default({}),
298
+ queueForCompare: z.boolean().default(true)
299
+ });
300
+ export const updatePreferenceItemSchema = createPreferenceItemSchema
301
+ .omit({ userId: true, domain: true })
302
+ .partial();
303
+ export const createPreferenceCatalogSchema = z.object({
304
+ userId: nonEmptyTrimmedString,
305
+ domain: preferenceDomainSchema,
306
+ title: nonEmptyTrimmedString,
307
+ description: trimmedString.default(""),
308
+ slug: trimmedString.optional()
309
+ });
310
+ export const updatePreferenceCatalogSchema = createPreferenceCatalogSchema
311
+ .omit({ userId: true, domain: true })
312
+ .partial();
313
+ export const createPreferenceCatalogItemSchema = z.object({
314
+ catalogId: nonEmptyTrimmedString,
315
+ label: nonEmptyTrimmedString,
316
+ description: trimmedString.default(""),
317
+ tags: z.array(nonEmptyTrimmedString).default([]),
318
+ featureWeights: preferenceDimensionVectorSchema.default({}),
319
+ position: z.number().int().min(0).optional()
320
+ });
321
+ export const updatePreferenceCatalogItemSchema = createPreferenceCatalogItemSchema
322
+ .omit({ catalogId: true })
323
+ .partial();
324
+ export const enqueueEntityPreferenceItemSchema = z.object({
325
+ userId: nonEmptyTrimmedString,
326
+ domain: preferenceDomainSchema,
327
+ entityType: crudEntityTypeSchema,
328
+ entityId: nonEmptyTrimmedString,
329
+ label: trimmedString.optional(),
330
+ description: trimmedString.optional(),
331
+ tags: z.array(nonEmptyTrimmedString).default([])
332
+ });
333
+ export const submitPairwiseJudgmentSchema = z.object({
334
+ userId: nonEmptyTrimmedString,
335
+ domain: preferenceDomainSchema,
336
+ contextId: nonEmptyTrimmedString,
337
+ leftItemId: nonEmptyTrimmedString,
338
+ rightItemId: nonEmptyTrimmedString,
339
+ outcome: preferenceJudgmentOutcomeSchema,
340
+ strength: z.number().min(0.5).max(2).default(1),
341
+ responseTimeMs: z.number().int().nullable().optional(),
342
+ reasonTags: z.array(nonEmptyTrimmedString).default([])
343
+ });
344
+ export const submitAbsoluteSignalSchema = z.object({
345
+ userId: nonEmptyTrimmedString,
346
+ domain: preferenceDomainSchema,
347
+ contextId: nonEmptyTrimmedString,
348
+ itemId: nonEmptyTrimmedString,
349
+ signalType: preferenceSignalTypeSchema,
350
+ strength: z.number().min(0.5).max(2).default(1)
351
+ });
352
+ export const updatePreferenceScoreSchema = z.object({
353
+ userId: nonEmptyTrimmedString,
354
+ domain: preferenceDomainSchema,
355
+ contextId: nonEmptyTrimmedString,
356
+ manualStatus: preferenceItemStatusSchema.nullable().optional(),
357
+ manualScore: z.number().nullable().optional(),
358
+ confidenceLock: z.number().min(0).max(1).nullable().optional(),
359
+ bookmarked: z.boolean().optional(),
360
+ compareLater: z.boolean().optional(),
361
+ frozen: z.boolean().optional()
362
+ });
363
+ export const startPreferenceGameSchema = z.object({
364
+ userId: nonEmptyTrimmedString,
365
+ domain: preferenceDomainSchema,
366
+ contextId: nonEmptyTrimmedString.optional(),
367
+ catalogId: nonEmptyTrimmedString.optional()
368
+ });
@@ -1,7 +1,13 @@
1
1
  import { z } from "zod";
2
+ import { userSummarySchema } from "./types.js";
2
3
  const trimmedString = z.string().trim();
3
4
  const nonEmptyTrimmedString = trimmedString.min(1);
4
5
  const uniqueStringArraySchema = z.array(nonEmptyTrimmedString);
6
+ const optionalOwnedUserIdSchema = z.string().trim().min(1).nullable().optional();
7
+ const ownedEntityFieldsSchema = {
8
+ userId: optionalOwnedUserIdSchema,
9
+ user: userSummarySchema.nullable().optional()
10
+ };
5
11
  export const triggerReportStatusSchema = z.enum(["draft", "reviewed", "integrated"]);
6
12
  export const behaviorKindSchema = z.enum(["away", "committed", "recovery"]);
7
13
  export const beliefTypeSchema = z.enum(["absolute", "conditional"]);
@@ -42,7 +48,8 @@ export const eventTypeSchema = z.object({
42
48
  description: trimmedString,
43
49
  system: z.boolean(),
44
50
  createdAt: z.string(),
45
- updatedAt: z.string()
51
+ updatedAt: z.string(),
52
+ ...ownedEntityFieldsSchema
46
53
  });
47
54
  export const emotionDefinitionSchema = z.object({
48
55
  id: z.string(),
@@ -52,7 +59,8 @@ export const emotionDefinitionSchema = z.object({
52
59
  category: trimmedString,
53
60
  system: z.boolean(),
54
61
  createdAt: z.string(),
55
- updatedAt: z.string()
62
+ updatedAt: z.string(),
63
+ ...ownedEntityFieldsSchema
56
64
  });
57
65
  export const psycheValueSchema = z.object({
58
66
  id: z.string(),
@@ -66,7 +74,8 @@ export const psycheValueSchema = z.object({
66
74
  linkedTaskIds: uniqueStringArraySchema.default([]),
67
75
  committedActions: z.array(trimmedString).default([]),
68
76
  createdAt: z.string(),
69
- updatedAt: z.string()
77
+ updatedAt: z.string(),
78
+ ...ownedEntityFieldsSchema
70
79
  });
71
80
  export const behaviorPatternSchema = z.object({
72
81
  id: z.string(),
@@ -84,7 +93,8 @@ export const behaviorPatternSchema = z.object({
84
93
  linkedModeIds: uniqueStringArraySchema.default([]),
85
94
  linkedBeliefIds: uniqueStringArraySchema.default([]),
86
95
  createdAt: z.string(),
87
- updatedAt: z.string()
96
+ updatedAt: z.string(),
97
+ ...ownedEntityFieldsSchema
88
98
  });
89
99
  export const behaviorSchema = z.object({
90
100
  id: z.string(),
@@ -103,7 +113,8 @@ export const behaviorSchema = z.object({
103
113
  linkedSchemaIds: uniqueStringArraySchema.default([]),
104
114
  linkedModeIds: uniqueStringArraySchema.default([]),
105
115
  createdAt: z.string(),
106
- updatedAt: z.string()
116
+ updatedAt: z.string(),
117
+ ...ownedEntityFieldsSchema
107
118
  });
108
119
  export const beliefEntrySchema = z.object({
109
120
  id: z.string(),
@@ -121,7 +132,8 @@ export const beliefEntrySchema = z.object({
121
132
  linkedModeIds: uniqueStringArraySchema.default([]),
122
133
  linkedReportIds: uniqueStringArraySchema.default([]),
123
134
  createdAt: z.string(),
124
- updatedAt: z.string()
135
+ updatedAt: z.string(),
136
+ ...ownedEntityFieldsSchema
125
137
  });
126
138
  export const modeProfileSchema = z.object({
127
139
  id: z.string(),
@@ -142,7 +154,8 @@ export const modeProfileSchema = z.object({
142
154
  linkedBehaviorIds: uniqueStringArraySchema.default([]),
143
155
  linkedValueIds: uniqueStringArraySchema.default([]),
144
156
  createdAt: z.string(),
145
- updatedAt: z.string()
157
+ updatedAt: z.string(),
158
+ ...ownedEntityFieldsSchema
146
159
  });
147
160
  export const modeTimelineEntrySchema = z.object({
148
161
  id: z.string(),
@@ -168,7 +181,8 @@ export const modeGuideSessionSchema = z.object({
168
181
  answers: z.array(modeGuideAnswerSchema),
169
182
  results: z.array(modeGuideResultSchema),
170
183
  createdAt: z.string(),
171
- updatedAt: z.string()
184
+ updatedAt: z.string(),
185
+ ...ownedEntityFieldsSchema
172
186
  });
173
187
  export const triggerEmotionSchema = z.object({
174
188
  id: z.string(),
@@ -222,7 +236,8 @@ export const triggerReportSchema = z.object({
222
236
  modeTimeline: z.array(modeTimelineEntrySchema).default([]),
223
237
  nextMoves: z.array(trimmedString).default([]),
224
238
  createdAt: z.string(),
225
- updatedAt: z.string()
239
+ updatedAt: z.string(),
240
+ ...ownedEntityFieldsSchema
226
241
  });
227
242
  export const schemaPressureEntrySchema = z.object({
228
243
  schemaId: z.string(),
@@ -251,7 +266,8 @@ export const createPsycheValueSchema = z.object({
251
266
  linkedGoalIds: uniqueStringArraySchema.default([]),
252
267
  linkedProjectIds: uniqueStringArraySchema.default([]),
253
268
  linkedTaskIds: uniqueStringArraySchema.default([]),
254
- committedActions: z.array(trimmedString).default([])
269
+ committedActions: z.array(trimmedString).default([]),
270
+ userId: optionalOwnedUserIdSchema
255
271
  });
256
272
  export const updatePsycheValueSchema = createPsycheValueSchema.partial();
257
273
  export const createBehaviorPatternSchema = z.object({
@@ -266,7 +282,8 @@ export const createBehaviorPatternSchema = z.object({
266
282
  linkedSchemaLabels: z.array(trimmedString).default([]),
267
283
  linkedModeLabels: z.array(trimmedString).default([]),
268
284
  linkedModeIds: uniqueStringArraySchema.default([]),
269
- linkedBeliefIds: uniqueStringArraySchema.default([])
285
+ linkedBeliefIds: uniqueStringArraySchema.default([]),
286
+ userId: optionalOwnedUserIdSchema
270
287
  });
271
288
  export const updateBehaviorPatternSchema = createBehaviorPatternSchema.partial();
272
289
  export const createBehaviorSchema = z.object({
@@ -282,7 +299,8 @@ export const createBehaviorSchema = z.object({
282
299
  linkedPatternIds: uniqueStringArraySchema.default([]),
283
300
  linkedValueIds: uniqueStringArraySchema.default([]),
284
301
  linkedSchemaIds: uniqueStringArraySchema.default([]),
285
- linkedModeIds: uniqueStringArraySchema.default([])
302
+ linkedModeIds: uniqueStringArraySchema.default([]),
303
+ userId: optionalOwnedUserIdSchema
286
304
  });
287
305
  export const updateBehaviorSchema = createBehaviorSchema.partial();
288
306
  export const createBeliefEntrySchema = z.object({
@@ -297,7 +315,8 @@ export const createBeliefEntrySchema = z.object({
297
315
  linkedValueIds: uniqueStringArraySchema.default([]),
298
316
  linkedBehaviorIds: uniqueStringArraySchema.default([]),
299
317
  linkedModeIds: uniqueStringArraySchema.default([]),
300
- linkedReportIds: uniqueStringArraySchema.default([])
318
+ linkedReportIds: uniqueStringArraySchema.default([]),
319
+ userId: optionalOwnedUserIdSchema
301
320
  });
302
321
  export const updateBeliefEntrySchema = createBeliefEntrySchema.partial();
303
322
  export const createModeProfileSchema = z.object({
@@ -315,23 +334,27 @@ export const createModeProfileSchema = z.object({
315
334
  firstAppearanceAt: trimmedString.nullable().default(null),
316
335
  linkedPatternIds: uniqueStringArraySchema.default([]),
317
336
  linkedBehaviorIds: uniqueStringArraySchema.default([]),
318
- linkedValueIds: uniqueStringArraySchema.default([])
337
+ linkedValueIds: uniqueStringArraySchema.default([]),
338
+ userId: optionalOwnedUserIdSchema
319
339
  });
320
340
  export const updateModeProfileSchema = createModeProfileSchema.partial();
321
341
  export const createModeGuideSessionSchema = z.object({
322
342
  summary: nonEmptyTrimmedString,
323
- answers: z.array(modeGuideAnswerSchema).min(1)
343
+ answers: z.array(modeGuideAnswerSchema).min(1),
344
+ userId: optionalOwnedUserIdSchema
324
345
  });
325
346
  export const updateModeGuideSessionSchema = createModeGuideSessionSchema.partial();
326
347
  export const createEventTypeSchema = z.object({
327
348
  label: nonEmptyTrimmedString,
328
- description: trimmedString.default("")
349
+ description: trimmedString.default(""),
350
+ userId: optionalOwnedUserIdSchema
329
351
  });
330
352
  export const updateEventTypeSchema = createEventTypeSchema.partial();
331
353
  export const createEmotionDefinitionSchema = z.object({
332
354
  label: nonEmptyTrimmedString,
333
355
  description: trimmedString.default(""),
334
- category: trimmedString.default("")
356
+ category: trimmedString.default(""),
357
+ userId: optionalOwnedUserIdSchema
335
358
  });
336
359
  export const updateEmotionDefinitionSchema = createEmotionDefinitionSchema.partial();
337
360
  export const createTriggerReportSchema = z.object({
@@ -361,6 +384,7 @@ export const createTriggerReportSchema = z.object({
361
384
  modeOverlays: z.array(trimmedString).default([]),
362
385
  schemaLinks: z.array(trimmedString).default([]),
363
386
  modeTimeline: z.array(modeTimelineEntrySchema.omit({ id: true }).extend({ id: z.string().optional() })).default([]),
364
- nextMoves: z.array(trimmedString).default([])
387
+ nextMoves: z.array(trimmedString).default([]),
388
+ userId: optionalOwnedUserIdSchema
365
389
  });
366
390
  export const updateTriggerReportSchema = createTriggerReportSchema.partial();
@@ -1,8 +1,45 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { getDatabase, runInTransaction } from "../db.js";
3
+ import { getEntityOwner } from "./entity-ownership.js";
3
4
  import { recordEventLog } from "./event-log.js";
4
5
  import { activityEventSchema } from "../types.js";
6
+ function resolveActivityOwner(row) {
7
+ if (row.entity_type === "task_run") {
8
+ const taskRunRow = getDatabase()
9
+ .prepare(`SELECT task_id FROM task_runs WHERE id = ?`)
10
+ .get(row.entity_id);
11
+ if (taskRunRow) {
12
+ const user = getEntityOwner("task", taskRunRow.task_id);
13
+ return { userId: user?.id ?? null, user };
14
+ }
15
+ }
16
+ if (row.entity_type === "work_block") {
17
+ const user = getEntityOwner("work_block_template", row.entity_id);
18
+ return { userId: user?.id ?? null, user };
19
+ }
20
+ if (row.entity_type === "system") {
21
+ const metadata = JSON.parse(row.metadata_json);
22
+ const correctedEntityType = typeof metadata.correctedEntityType === "string"
23
+ ? metadata.correctedEntityType
24
+ : null;
25
+ const correctedEntityId = typeof metadata.correctedEntityId === "string"
26
+ ? metadata.correctedEntityId
27
+ : null;
28
+ if (correctedEntityType && correctedEntityId) {
29
+ const mappedEntityType = correctedEntityType === "work_block"
30
+ ? "work_block_template"
31
+ : correctedEntityType;
32
+ const user = getEntityOwner(mappedEntityType, correctedEntityId);
33
+ return { userId: user?.id ?? null, user };
34
+ }
35
+ }
36
+ const rawEntityType = row.entity_type;
37
+ const mappedEntityType = rawEntityType === "work_block" ? "work_block_template" : rawEntityType;
38
+ const user = getEntityOwner(mappedEntityType, row.entity_id);
39
+ return { userId: user?.id ?? null, user };
40
+ }
5
41
  function mapActivityEvent(row) {
42
+ const owner = resolveActivityOwner(row);
6
43
  return activityEventSchema.parse({
7
44
  id: row.id,
8
45
  entityType: row.entity_type,
@@ -13,7 +50,9 @@ function mapActivityEvent(row) {
13
50
  actor: row.actor,
14
51
  source: row.source,
15
52
  metadata: JSON.parse(row.metadata_json),
16
- createdAt: row.created_at
53
+ createdAt: row.created_at,
54
+ userId: owner.userId,
55
+ user: owner.user
17
56
  });
18
57
  }
19
58
  export function recordActivityEvent(input, now = new Date()) {
@@ -80,9 +119,14 @@ export function listActivityEvents(filters = {}) {
80
119
  ORDER BY created_at DESC
81
120
  ${limitSql}`)
82
121
  .all(...params);
83
- return rows.map(mapActivityEvent);
122
+ const events = rows.map(mapActivityEvent);
123
+ if (!filters.userIds || filters.userIds.length === 0) {
124
+ return events;
125
+ }
126
+ const allowed = new Set(filters.userIds);
127
+ return events.filter((event) => event.userId !== null && allowed.has(event.userId));
84
128
  }
85
- export function listActivityEventsForTask(taskId, limit = 25) {
129
+ export function listActivityEventsForTask(taskId, limit = 25, userIds) {
86
130
  const rows = getDatabase()
87
131
  .prepare(`SELECT
88
132
  activity_events.id,
@@ -112,7 +156,12 @@ export function listActivityEventsForTask(taskId, limit = 25) {
112
156
  ORDER BY activity_events.created_at DESC
113
157
  LIMIT ?`)
114
158
  .all(taskId, taskId, limit);
115
- return rows.map(mapActivityEvent);
159
+ const events = rows.map(mapActivityEvent);
160
+ if (!userIds || userIds.length === 0) {
161
+ return events;
162
+ }
163
+ const allowed = new Set(userIds);
164
+ return events.filter((event) => event.userId !== null && allowed.has(event.userId));
116
165
  }
117
166
  export function getActivityEventById(eventId) {
118
167
  const row = getDatabase()