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.
- package/README.md +133 -2
- package/dist/assets/board-_C6oMy5w.js +6 -0
- package/dist/assets/{board-8L3uX7_O.js.map → board-_C6oMy5w.js.map} +1 -1
- package/dist/assets/index-B4A6TooJ.js +63 -0
- package/dist/assets/index-B4A6TooJ.js.map +1 -0
- package/dist/assets/index-D6Xs_2mo.css +1 -0
- package/dist/assets/{motion-1GAqqi8M.js → motion-D4sZgCHd.js} +2 -2
- package/dist/assets/{motion-1GAqqi8M.js.map → motion-D4sZgCHd.js.map} +1 -1
- package/dist/assets/{table-DBGlgRjk.js → table-BWzTaky1.js} +2 -2
- package/dist/assets/{table-DBGlgRjk.js.map → table-BWzTaky1.js.map} +1 -1
- package/dist/assets/{ui-iTluWjC4.js → ui-BzK4azQb.js} +7 -7
- package/dist/assets/{ui-iTluWjC4.js.map → ui-BzK4azQb.js.map} +1 -1
- package/dist/assets/vendor-DT3pnAKJ.css +1 -0
- package/dist/assets/vendor-De38P6YR.js +729 -0
- package/dist/assets/vendor-De38P6YR.js.map +1 -0
- package/dist/assets/viz-C6hfyqzu.js +34 -0
- package/dist/assets/viz-C6hfyqzu.js.map +1 -0
- package/dist/index.html +9 -9
- package/dist/openclaw/parity.d.ts +1 -1
- package/dist/openclaw/parity.js +29 -2
- package/dist/openclaw/routes.js +207 -24
- package/dist/openclaw/tools.js +324 -35
- package/dist/server/app.js +2080 -92
- package/dist/server/db.js +3 -0
- package/dist/server/health.js +1284 -0
- package/dist/server/managers/platform/background-job-manager.js +138 -2
- package/dist/server/managers/platform/llm-manager.js +126 -0
- package/dist/server/managers/platform/openai-responses-provider.js +773 -0
- package/dist/server/managers/runtime.js +6 -1
- package/dist/server/openapi.js +718 -0
- package/dist/server/preferences-seeds.js +409 -0
- package/dist/server/preferences-types.js +368 -0
- package/dist/server/psyche-types.js +42 -18
- package/dist/server/repositories/activity-events.js +53 -4
- package/dist/server/repositories/calendar.js +89 -15
- package/dist/server/repositories/collaboration.js +8 -3
- package/dist/server/repositories/diagnostic-logs.js +243 -0
- package/dist/server/repositories/entity-ownership.js +92 -0
- package/dist/server/repositories/goals.js +7 -2
- package/dist/server/repositories/habits.js +122 -16
- package/dist/server/repositories/notes.js +119 -41
- package/dist/server/repositories/preferences.js +1765 -0
- package/dist/server/repositories/projects.js +18 -7
- package/dist/server/repositories/psyche.js +84 -27
- package/dist/server/repositories/rewards.js +112 -4
- package/dist/server/repositories/strategies.js +450 -0
- package/dist/server/repositories/tags.js +11 -6
- package/dist/server/repositories/task-runs.js +10 -2
- package/dist/server/repositories/tasks.js +99 -17
- package/dist/server/repositories/users.js +417 -0
- package/dist/server/repositories/wiki-memory.js +3366 -0
- package/dist/server/services/context.js +20 -18
- package/dist/server/services/dashboard.js +29 -6
- package/dist/server/services/entity-crud.js +21 -3
- package/dist/server/services/insights.js +9 -7
- package/dist/server/services/projects.js +2 -1
- package/dist/server/services/psyche.js +10 -9
- package/dist/server/types.js +594 -30
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server/migrations/015_multi_user_and_strategies.sql +244 -0
- package/server/migrations/016_health_companion.sql +158 -0
- package/server/migrations/016_strategy_contracts_and_user_graph.sql +22 -0
- package/server/migrations/017_preferences.sql +131 -0
- package/server/migrations/018_preference_catalogs.sql +31 -0
- package/server/migrations/019_wiki_memory.sql +255 -0
- package/server/migrations/020_wiki_page_hierarchy.sql +11 -0
- package/server/migrations/021_hide_evidence_from_wiki_index.sql +3 -0
- package/server/migrations/022_wiki_ingest_background.sql +85 -0
- package/server/migrations/023_diagnostic_logs.sql +28 -0
- package/skills/forge-openclaw/SKILL.md +126 -34
- package/skills/forge-openclaw/entity_conversation_playbooks.md +337 -0
- package/skills/forge-openclaw/psyche_entity_playbooks.md +404 -0
- package/dist/assets/board-8L3uX7_O.js +0 -6
- package/dist/assets/index-Cj1IBH_w.js +0 -36
- package/dist/assets/index-Cj1IBH_w.js.map +0 -1
- package/dist/assets/index-DQT6EbuS.css +0 -1
- package/dist/assets/vendor-BvM2F9Dp.js +0 -503
- package/dist/assets/vendor-BvM2F9Dp.js.map +0 -1
- package/dist/assets/vendor-CRS-psbw.css +0 -1
- package/dist/assets/viz-CNeunkfu.js +0 -34
- package/dist/assets/viz-CNeunkfu.js.map +0 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { listActivityEvents } from "../repositories/activity-events.js";
|
|
2
|
-
import { listGoals } from "../repositories/goals.js";
|
|
3
|
-
import { listHabits } from "../repositories/habits.js";
|
|
4
2
|
import { listRewardLedger } from "../repositories/rewards.js";
|
|
5
3
|
import { listTags, listTagsByIds } from "../repositories/tags.js";
|
|
6
|
-
import { listTasks } from "../repositories/tasks.js";
|
|
7
4
|
import { getDashboard } from "./dashboard.js";
|
|
8
5
|
import { buildAchievementSignals, buildGamificationProfile, buildMilestoneRewards } from "./gamification.js";
|
|
9
6
|
import { overviewContextSchema, riskContextSchema, todayContextSchema } from "../types.js";
|
|
@@ -107,11 +104,14 @@ function buildDomainBalance(goals, tasks) {
|
|
|
107
104
|
}
|
|
108
105
|
return [...domainRows.values()].sort((left, right) => right.completedPoints - left.completedPoints);
|
|
109
106
|
}
|
|
110
|
-
export function getOverviewContext(now = new Date()) {
|
|
111
|
-
const dashboard = getDashboard();
|
|
107
|
+
export function getOverviewContext(now = new Date(), options = {}) {
|
|
108
|
+
const dashboard = getDashboard(options);
|
|
112
109
|
const focusTasks = dashboard.tasks.filter((task) => task.status === "focus" || task.status === "in_progress").length;
|
|
113
110
|
const overdueTasks = dashboard.tasks.filter((task) => task.status !== "done" && task.dueDate !== null && task.dueDate < now.toISOString().slice(0, 10)).length;
|
|
114
111
|
const dueHabits = dashboard.habits.filter((habit) => habit.dueToday).slice(0, 6);
|
|
112
|
+
const goals = dashboard.goals;
|
|
113
|
+
const tasks = dashboard.tasks;
|
|
114
|
+
const habits = dashboard.habits;
|
|
115
115
|
return overviewContextSchema.parse({
|
|
116
116
|
generatedAt: now.toISOString(),
|
|
117
117
|
strategicHeader: {
|
|
@@ -125,19 +125,20 @@ export function getOverviewContext(now = new Date()) {
|
|
|
125
125
|
overdueTasks
|
|
126
126
|
},
|
|
127
127
|
projects: dashboard.projects.slice(0, 5),
|
|
128
|
-
activeGoals:
|
|
129
|
-
topTasks: sortStrategicTasks(
|
|
128
|
+
activeGoals: goals.filter((goal) => goal.status === "active").slice(0, 6),
|
|
129
|
+
topTasks: sortStrategicTasks(tasks.filter((task) => task.status !== "done")).slice(0, 6),
|
|
130
130
|
dueHabits,
|
|
131
|
-
recentEvidence: listActivityEvents({ limit: 12 }),
|
|
132
|
-
achievements: buildAchievementSignals(
|
|
133
|
-
domainBalance: buildDomainBalance(
|
|
134
|
-
neglectedGoals: buildNeglectedGoals(
|
|
131
|
+
recentEvidence: listActivityEvents({ limit: 12, userIds: options.userIds }),
|
|
132
|
+
achievements: buildAchievementSignals(goals, tasks, habits, now),
|
|
133
|
+
domainBalance: buildDomainBalance(goals, tasks),
|
|
134
|
+
neglectedGoals: buildNeglectedGoals(goals, tasks, now)
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
export function getTodayContext(now = new Date()) {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
137
|
+
export function getTodayContext(now = new Date(), options = {}) {
|
|
138
|
+
const dashboard = getDashboard(options);
|
|
139
|
+
const goals = dashboard.goals;
|
|
140
|
+
const tasks = dashboard.tasks;
|
|
141
|
+
const habits = dashboard.habits;
|
|
141
142
|
const gamification = buildGamificationProfile(goals, tasks, habits, now);
|
|
142
143
|
const inProgressTasks = sortStrategicTasks(tasks.filter((task) => task.status === "in_progress")).slice(0, 4);
|
|
143
144
|
const readyTasks = sortStrategicTasks(tasks.filter((task) => task.status === "focus" || task.status === "backlog")).slice(0, 4);
|
|
@@ -205,9 +206,10 @@ export function getTodayContext(now = new Date()) {
|
|
|
205
206
|
}
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
|
-
export function getRiskContext(now = new Date()) {
|
|
209
|
-
const
|
|
210
|
-
const
|
|
209
|
+
export function getRiskContext(now = new Date(), options = {}) {
|
|
210
|
+
const dashboard = getDashboard(options);
|
|
211
|
+
const tasks = dashboard.tasks;
|
|
212
|
+
const goals = dashboard.goals;
|
|
211
213
|
const overdueTasks = sortStrategicTasks(tasks.filter((task) => task.status !== "done" && task.dueDate !== null && task.dueDate < now.toISOString().slice(0, 10))).slice(0, 8);
|
|
212
214
|
const blockedTasks = sortStrategicTasks(tasks.filter((task) => task.status === "blocked")).slice(0, 8);
|
|
213
215
|
const neglectedGoals = buildNeglectedGoals(goals, tasks, now);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { listGoals } from "../repositories/goals.js";
|
|
2
2
|
import { listActivityEvents } from "../repositories/activity-events.js";
|
|
3
|
+
import { filterOwnedEntities } from "../repositories/entity-ownership.js";
|
|
3
4
|
import { listHabits } from "../repositories/habits.js";
|
|
4
5
|
import { buildNotesSummaryByEntity } from "../repositories/notes.js";
|
|
5
6
|
import { listTagsByIds, listTags } from "../repositories/tags.js";
|
|
@@ -114,10 +115,10 @@ function buildGoalSummary(tasks, goalId) {
|
|
|
114
115
|
const momentumLabel = completedTasks === 0 ? "Needs ignition" : completedTasks >= Math.ceil(totalTasks / 2) ? "Strong momentum" : "Building pace";
|
|
115
116
|
return { progress, totalTasks, completedTasks, earnedPoints, momentumLabel };
|
|
116
117
|
}
|
|
117
|
-
export function getDashboard() {
|
|
118
|
-
const goals = listGoals();
|
|
119
|
-
const tasks = listTasks();
|
|
120
|
-
const habits = listHabits();
|
|
118
|
+
export function getDashboard(options = {}) {
|
|
119
|
+
const goals = filterOwnedEntities("goal", listGoals(), options.userIds);
|
|
120
|
+
const tasks = filterOwnedEntities("task", listTasks(), options.userIds);
|
|
121
|
+
const habits = filterOwnedEntities("habit", listHabits(), options.userIds);
|
|
121
122
|
const tags = listTags();
|
|
122
123
|
const now = new Date();
|
|
123
124
|
const weekStart = startOfWeek(now).toISOString();
|
|
@@ -148,14 +149,36 @@ export function getDashboard() {
|
|
|
148
149
|
tags: listTagsByIds(goal.tagIds)
|
|
149
150
|
};
|
|
150
151
|
});
|
|
151
|
-
const projects = listProjectSummaries();
|
|
152
|
+
const projects = listProjectSummaries({ userIds: options.userIds });
|
|
152
153
|
const suggestedTags = tags.filter((tag) => ["value", "execution"].includes(tag.kind)).slice(0, 6);
|
|
153
154
|
const owners = [...new Set(tasks.map((task) => task.owner).filter(Boolean))].sort((left, right) => left.localeCompare(right));
|
|
154
155
|
const executionBuckets = buildExecutionBuckets(tasks, todayIso, weekEndIso);
|
|
155
156
|
const gamification = buildGamificationProfile(goals, tasks, habits, now);
|
|
156
157
|
const achievements = buildAchievementSignals(goals, tasks, habits, now);
|
|
157
158
|
const milestoneRewards = buildMilestoneRewards(goals, tasks, habits, now);
|
|
158
|
-
const
|
|
159
|
+
const visibleIds = {
|
|
160
|
+
goal: new Set(goals.map((goal) => goal.id)),
|
|
161
|
+
project: new Set(projects.map((project) => project.id)),
|
|
162
|
+
task: new Set(tasks.map((task) => task.id)),
|
|
163
|
+
habit: new Set(habits.map((habit) => habit.id))
|
|
164
|
+
};
|
|
165
|
+
const recentActivity = listActivityEvents({ limit: 36, userIds: options.userIds })
|
|
166
|
+
.filter((event) => {
|
|
167
|
+
if (event.entityType === "goal") {
|
|
168
|
+
return visibleIds.goal.has(event.entityId);
|
|
169
|
+
}
|
|
170
|
+
if (event.entityType === "project") {
|
|
171
|
+
return visibleIds.project.has(event.entityId);
|
|
172
|
+
}
|
|
173
|
+
if (event.entityType === "task") {
|
|
174
|
+
return visibleIds.task.has(event.entityId);
|
|
175
|
+
}
|
|
176
|
+
if (event.entityType === "habit") {
|
|
177
|
+
return visibleIds.habit.has(event.entityId);
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
})
|
|
181
|
+
.slice(0, 12);
|
|
159
182
|
const notesSummaryByEntity = buildNotesSummaryByEntity();
|
|
160
183
|
return dashboardPayloadSchema.parse({
|
|
161
184
|
stats,
|
|
@@ -2,15 +2,17 @@ import { getDatabase, runInTransaction } from "../db.js";
|
|
|
2
2
|
import { createInsight, deleteInsight, getInsightById, listInsights, updateInsight } from "../repositories/collaboration.js";
|
|
3
3
|
import { createCalendarEvent, createTaskTimebox, createWorkBlockTemplate, deleteCalendarEvent, deleteTaskTimebox, deleteWorkBlockTemplate, getCalendarEventById, getTaskTimeboxById, getWorkBlockTemplateById, listCalendarEvents, listTaskTimeboxes, listWorkBlockTemplates, updateCalendarEvent, updateTaskTimebox, updateWorkBlockTemplate } from "../repositories/calendar.js";
|
|
4
4
|
import { createNote, deleteNote, getNoteById, listNotes, unlinkNotesForEntity, updateNote } from "../repositories/notes.js";
|
|
5
|
+
import { clearEntityOwner, filterOwnedEntities } from "../repositories/entity-ownership.js";
|
|
5
6
|
import { createBehaviorPatternSchema, createBehaviorSchema, createBeliefEntrySchema, createEmotionDefinitionSchema, createEventTypeSchema, createModeGuideSessionSchema, createModeProfileSchema, createPsycheValueSchema, createTriggerReportSchema, updateBehaviorPatternSchema, updateBehaviorSchema, updateBeliefEntrySchema, updateEmotionDefinitionSchema, updateEventTypeSchema, updateModeGuideSessionSchema, updateModeProfileSchema, updatePsycheValueSchema, updateTriggerReportSchema } from "../psyche-types.js";
|
|
6
7
|
import { buildSettingsBinPayload, cascadeSoftDeleteAnchoredCollaboration, clearDeletedEntityRecord, getDeletedEntityRecord, listDeletedEntities, restoreAnchoredCollaboration, restoreDeletedEntityRecord, upsertDeletedEntityRecord } from "../repositories/deleted-entities.js";
|
|
7
8
|
import { createGoal, deleteGoal, getGoalById, listGoals, updateGoal } from "../repositories/goals.js";
|
|
8
9
|
import { createHabit, deleteHabit, getHabitById, listHabits, updateHabit } from "../repositories/habits.js";
|
|
9
10
|
import { createBehavior, createBehaviorPattern, createBeliefEntry, createEmotionDefinition, createEventType, createModeGuideSession, createModeProfile, createPsycheValue, createTriggerReport, deleteBehavior, deleteBehaviorPattern, deleteBeliefEntry, deleteEmotionDefinition, deleteEventType, deleteModeGuideSession, deleteModeProfile, deletePsycheValue, deleteTriggerReport, getBehaviorById, getBehaviorPatternById, getBeliefEntryById, getEmotionDefinitionById, getEventTypeById, getModeGuideSessionById, getModeProfileById, getPsycheValueById, getTriggerReportById, listBehaviors, listBehaviorPatterns, listBeliefEntries, listEmotionDefinitions, listEventTypes, listModeGuideSessions, listModeProfiles, listPsycheValues, listTriggerReports, updateBehavior, updateBehaviorPattern, updateBeliefEntry, updateEmotionDefinition, updateEventType, updateModeGuideSession, updateModeProfile, updatePsycheValue, updateTriggerReport } from "../repositories/psyche.js";
|
|
10
11
|
import { createProject, deleteProject, getProjectById, listProjects, updateProject } from "../repositories/projects.js";
|
|
12
|
+
import { createStrategy, deleteStrategy, getStrategyById, listStrategies, updateStrategy } from "../repositories/strategies.js";
|
|
11
13
|
import { createTag, deleteTag, getTagById, listTags, updateTag } from "../repositories/tags.js";
|
|
12
14
|
import { createTask, deleteTask, getTaskById, listTasks, updateTask } from "../repositories/tasks.js";
|
|
13
|
-
import { createCalendarEventSchema, createGoalSchema, createHabitSchema, createInsightSchema, createNoteSchema, createProjectSchema, createTaskTimeboxSchema, createTagSchema, createTaskSchema, createWorkBlockTemplateSchema, updateCalendarEventSchema, updateGoalSchema, updateHabitSchema, updateInsightSchema, updateNoteSchema, updateProjectSchema, updateTaskTimeboxSchema, updateTagSchema, updateTaskSchema, updateWorkBlockTemplateSchema } from "../types.js";
|
|
15
|
+
import { createCalendarEventSchema, createGoalSchema, createHabitSchema, createInsightSchema, createNoteSchema, createProjectSchema, createStrategySchema, createTaskTimeboxSchema, createTagSchema, createTaskSchema, createWorkBlockTemplateSchema, updateCalendarEventSchema, updateGoalSchema, updateHabitSchema, updateInsightSchema, updateNoteSchema, updateProjectSchema, updateStrategySchema, updateTaskTimeboxSchema, updateTagSchema, updateTaskSchema, updateWorkBlockTemplateSchema } from "../types.js";
|
|
14
16
|
const ENTITY_CALENDAR_LIST_RANGE = {
|
|
15
17
|
from: "1970-01-01T00:00:00.000Z",
|
|
16
18
|
to: "2100-01-01T00:00:00.000Z"
|
|
@@ -61,6 +63,17 @@ const CRUD_ENTITY_CAPABILITIES = {
|
|
|
61
63
|
update: (id, patch, context) => updateTask(id, patch, context),
|
|
62
64
|
hardDelete: (id, context) => deleteTask(id, context)
|
|
63
65
|
},
|
|
66
|
+
strategy: {
|
|
67
|
+
entityType: "strategy",
|
|
68
|
+
routeBase: "/api/v1/strategies",
|
|
69
|
+
deleteMode: "soft_default",
|
|
70
|
+
inBin: true,
|
|
71
|
+
list: () => listStrategies(),
|
|
72
|
+
get: (id) => getStrategyById(id),
|
|
73
|
+
create: (data) => createStrategy(data),
|
|
74
|
+
update: (id, patch) => updateStrategy(id, patch),
|
|
75
|
+
hardDelete: (id) => deleteStrategy(id)
|
|
76
|
+
},
|
|
64
77
|
habit: {
|
|
65
78
|
entityType: "habit",
|
|
66
79
|
routeBase: "/api/v1/habits",
|
|
@@ -254,6 +267,7 @@ const CREATE_ENTITY_SCHEMAS = {
|
|
|
254
267
|
goal: createGoalSchema,
|
|
255
268
|
project: createProjectSchema,
|
|
256
269
|
task: createTaskSchema,
|
|
270
|
+
strategy: createStrategySchema,
|
|
257
271
|
habit: createHabitSchema,
|
|
258
272
|
tag: createTagSchema,
|
|
259
273
|
note: createNoteSchema,
|
|
@@ -275,6 +289,7 @@ const UPDATE_ENTITY_SCHEMAS = {
|
|
|
275
289
|
goal: updateGoalSchema,
|
|
276
290
|
project: updateProjectSchema,
|
|
277
291
|
task: updateTaskSchema,
|
|
292
|
+
strategy: updateStrategySchema,
|
|
278
293
|
habit: updateHabitSchema,
|
|
279
294
|
tag: updateTagSchema,
|
|
280
295
|
note: updateNoteSchema,
|
|
@@ -536,6 +551,7 @@ export function deleteEntity(entityType, id, options, context) {
|
|
|
536
551
|
purgeAnchoredCollaboration(entityType, id);
|
|
537
552
|
}
|
|
538
553
|
const deleted = capability.hardDelete(id, context);
|
|
554
|
+
clearEntityOwner(entityType, id);
|
|
539
555
|
clearDeletedEntityRecord(entityType, id);
|
|
540
556
|
return deleted;
|
|
541
557
|
});
|
|
@@ -652,8 +668,7 @@ export function searchEntities(input) {
|
|
|
652
668
|
return {
|
|
653
669
|
results: input.searches.map((search) => {
|
|
654
670
|
const entityTypes = search.entityTypes && search.entityTypes.length > 0 ? search.entityTypes : defaultEntityTypes;
|
|
655
|
-
const liveMatches = entityTypes.flatMap((entityType) => getCapability(entityType)
|
|
656
|
-
.list()
|
|
671
|
+
const liveMatches = entityTypes.flatMap((entityType) => filterOwnedEntities(entityType, getCapability(entityType).list(), search.userIds)
|
|
657
672
|
.filter((entity) => (search.ids && search.ids.length > 0 ? search.ids.includes(String(entity.id ?? "")) : true))
|
|
658
673
|
.filter((entity) => matchesQuery(entity, search.query))
|
|
659
674
|
.filter((entity) => matchesStatus(entity, search.status))
|
|
@@ -664,6 +679,9 @@ export function searchEntities(input) {
|
|
|
664
679
|
? deleted
|
|
665
680
|
.filter((item) => entityTypes.includes(item.entityType))
|
|
666
681
|
.filter((item) => (search.ids && search.ids.length > 0 ? search.ids.includes(item.entityId) : true))
|
|
682
|
+
.filter((item) => !search.userIds || search.userIds.length === 0
|
|
683
|
+
? true
|
|
684
|
+
: search.userIds.includes(String(item.snapshot.userId ?? "")))
|
|
667
685
|
.filter((item) => matchesQuery(item.snapshot, search.query) || matchesQuery(item, search.query))
|
|
668
686
|
.filter((item) => matchesStatus(item.snapshot, search.status))
|
|
669
687
|
.filter((item) => (search.linkedTo ? matchesLinkedTo(item.entityType, item.snapshot, search.linkedTo) : true))
|
|
@@ -3,6 +3,7 @@ import { listInsights } from "../repositories/collaboration.js";
|
|
|
3
3
|
import { listGoals } from "../repositories/goals.js";
|
|
4
4
|
import { listHabits } from "../repositories/habits.js";
|
|
5
5
|
import { listTasks } from "../repositories/tasks.js";
|
|
6
|
+
import { filterOwnedEntities } from "../repositories/entity-ownership.js";
|
|
6
7
|
import { getOverviewContext } from "./context.js";
|
|
7
8
|
import { buildGamificationProfile } from "./gamification.js";
|
|
8
9
|
import { insightsPayloadSchema } from "../types.js";
|
|
@@ -31,12 +32,13 @@ function buildHeatmap(tasks, now) {
|
|
|
31
32
|
}
|
|
32
33
|
return cells;
|
|
33
34
|
}
|
|
34
|
-
export function getInsightsPayload(now = new Date()) {
|
|
35
|
-
const goals = listGoals();
|
|
36
|
-
const tasks = listTasks();
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
35
|
+
export function getInsightsPayload(now = new Date(), options = {}) {
|
|
36
|
+
const goals = filterOwnedEntities("goal", listGoals(), options.userIds);
|
|
37
|
+
const tasks = filterOwnedEntities("task", listTasks(), options.userIds);
|
|
38
|
+
const habits = filterOwnedEntities("habit", listHabits(), options.userIds);
|
|
39
|
+
const gamification = buildGamificationProfile(goals, tasks, habits, now);
|
|
40
|
+
const overview = getOverviewContext(now, { userIds: options.userIds });
|
|
41
|
+
const activity = listActivityEvents({ limit: 60, userIds: options.userIds });
|
|
40
42
|
const trends = Array.from({ length: 6 }, (_, offset) => {
|
|
41
43
|
const bucketStart = addDays(now, -(5 - offset) * 5);
|
|
42
44
|
const bucketEnd = addDays(bucketStart, 4);
|
|
@@ -60,7 +62,7 @@ export function getInsightsPayload(now = new Date()) {
|
|
|
60
62
|
const hottestGoal = overview.activeGoals[0] ?? null;
|
|
61
63
|
const blockedTasks = tasks.filter((task) => task.status === "blocked").length;
|
|
62
64
|
const overdueTasks = tasks.filter((task) => task.status !== "done" && task.dueDate !== null && task.dueDate < dayKey(now)).length;
|
|
63
|
-
const feed = listInsights({ limit: 8 });
|
|
65
|
+
const feed = listInsights({ limit: 8, userIds: options.userIds });
|
|
64
66
|
return insightsPayloadSchema.parse({
|
|
65
67
|
generatedAt: now.toISOString(),
|
|
66
68
|
status: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { listActivityEvents } from "../repositories/activity-events.js";
|
|
2
|
+
import { filterOwnedEntities } from "../repositories/entity-ownership.js";
|
|
2
3
|
import { getGoalById, listGoals } from "../repositories/goals.js";
|
|
3
4
|
import { buildNotesSummaryByEntity } from "../repositories/notes.js";
|
|
4
5
|
import { listProjects } from "../repositories/projects.js";
|
|
@@ -55,7 +56,7 @@ export function listProjectSummaries(filters = {}) {
|
|
|
55
56
|
const goals = new Map(listGoals().map((goal) => [goal.id, goal]));
|
|
56
57
|
const tasks = listTasks();
|
|
57
58
|
const projectAdjustmentSeconds = listProjectWorkAdjustmentSecondsMap();
|
|
58
|
-
return listProjects(filters).map((project) => {
|
|
59
|
+
return filterOwnedEntities("project", listProjects(filters), filters.userIds).map((project) => {
|
|
59
60
|
const goal = goals.get(project.goalId);
|
|
60
61
|
const projectTasks = tasks.filter((task) => task.projectId === project.id);
|
|
61
62
|
const taskSummary = projectTaskSummary(projectTasks);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDomainBySlug } from "../repositories/domains.js";
|
|
2
2
|
import { listInsights } from "../repositories/collaboration.js";
|
|
3
3
|
import { listNotes } from "../repositories/notes.js";
|
|
4
|
+
import { filterOwnedEntities } from "../repositories/entity-ownership.js";
|
|
4
5
|
import { listBehaviorPatterns, listBehaviors, listBeliefEntries, listModeProfiles, listPsycheValues, listSchemaCatalog, listTriggerReports } from "../repositories/psyche.js";
|
|
5
6
|
import { psycheOverviewPayloadSchema } from "../psyche-types.js";
|
|
6
7
|
const PSYCHE_ENTITY_TYPE_SET = new Set([
|
|
@@ -11,20 +12,20 @@ const PSYCHE_ENTITY_TYPE_SET = new Set([
|
|
|
11
12
|
"mode_profile",
|
|
12
13
|
"trigger_report"
|
|
13
14
|
]);
|
|
14
|
-
export function getPsycheOverview() {
|
|
15
|
+
export function getPsycheOverview(userIds) {
|
|
15
16
|
const domain = getDomainBySlug("psyche");
|
|
16
17
|
if (!domain) {
|
|
17
18
|
throw new Error("Psyche domain is not available");
|
|
18
19
|
}
|
|
19
|
-
const values = listPsycheValues();
|
|
20
|
-
const patterns = listBehaviorPatterns();
|
|
21
|
-
const behaviors = listBehaviors();
|
|
22
|
-
const beliefs = listBeliefEntries();
|
|
23
|
-
const modes = listModeProfiles();
|
|
24
|
-
const reports = listTriggerReports(5);
|
|
20
|
+
const values = filterOwnedEntities("psyche_value", listPsycheValues(), userIds);
|
|
21
|
+
const patterns = filterOwnedEntities("behavior_pattern", listBehaviorPatterns(), userIds);
|
|
22
|
+
const behaviors = filterOwnedEntities("behavior", listBehaviors(), userIds);
|
|
23
|
+
const beliefs = filterOwnedEntities("belief_entry", listBeliefEntries(), userIds);
|
|
24
|
+
const modes = filterOwnedEntities("mode_profile", listModeProfiles(), userIds);
|
|
25
|
+
const reports = filterOwnedEntities("trigger_report", listTriggerReports(5), userIds);
|
|
25
26
|
const schemaCatalog = listSchemaCatalog();
|
|
26
|
-
const notes = listNotes({ limit: 200 });
|
|
27
|
-
const openInsights = listInsights({ limit: 100 }).filter((insight) => insight.entityType && PSYCHE_ENTITY_TYPE_SET.has(insight.entityType)).length;
|
|
27
|
+
const notes = filterOwnedEntities("note", listNotes({ limit: 200 }), userIds);
|
|
28
|
+
const openInsights = filterOwnedEntities("insight", listInsights({ limit: 100 }), userIds).filter((insight) => insight.entityType && PSYCHE_ENTITY_TYPE_SET.has(insight.entityType)).length;
|
|
28
29
|
const openNotes = notes.filter((note) => note.links.some((link) => PSYCHE_ENTITY_TYPE_SET.has(link.entityType))).length;
|
|
29
30
|
const committedActions = [
|
|
30
31
|
...values.flatMap((value) => value.committedActions),
|