@imenam/mcp-organizer 1.0.10 → 1.0.12

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 (53) hide show
  1. package/README.md +57 -19
  2. package/dist/shared/schemas/agent-api.schema.d.ts +40 -2
  3. package/dist/shared/schemas/agent-api.schema.js +12 -3
  4. package/dist/shared/schemas/agent-tools.schema.d.ts +373 -6
  5. package/dist/shared/schemas/agent-tools.schema.js +54 -3
  6. package/dist/shared/schemas/api.schema.d.ts +26 -0
  7. package/dist/shared/schemas/api.schema.js +9 -0
  8. package/dist/shared/schemas/entities.schema.d.ts +38 -4
  9. package/dist/shared/schemas/entities.schema.js +33 -5
  10. package/dist/shared/schemas/enums.schema.d.ts +4 -2
  11. package/dist/shared/schemas/enums.schema.js +2 -1
  12. package/dist/shared/schemas/notifications-api.schema.d.ts +29 -7
  13. package/dist/shared/schemas/notifications-api.schema.js +21 -5
  14. package/dist/shared/schemas/tasks-api.schema.d.ts +112 -0
  15. package/dist/shared/schemas/tasks-api.schema.js +43 -0
  16. package/dist/shared/schemas/views-api.schema.d.ts +8 -0
  17. package/dist/shared/schemas/views-api.schema.js +5 -1
  18. package/dist/src/agent-api/requests.d.ts +1 -1
  19. package/dist/src/agent-api/requests.js +56 -4
  20. package/dist/src/agent-api/router.js +2 -1
  21. package/dist/src/agent-api/views.d.ts +2 -0
  22. package/dist/src/agent-api/views.js +203 -0
  23. package/dist/src/core/agent.d.ts +5 -1
  24. package/dist/src/core/agent.js +61 -2
  25. package/dist/src/core/board-views.d.ts +11 -1
  26. package/dist/src/core/board-views.js +39 -15
  27. package/dist/src/core/follow-ups.d.ts +7 -0
  28. package/dist/src/core/follow-ups.js +15 -0
  29. package/dist/src/core/history.d.ts +2 -1
  30. package/dist/src/core/history.js +62 -3
  31. package/dist/src/core/migrations.js +482 -421
  32. package/dist/src/core/notifications.js +36 -9
  33. package/dist/src/core/requests.d.ts +10 -1
  34. package/dist/src/core/requests.js +41 -3
  35. package/dist/src/core/snapshots.d.ts +4 -4
  36. package/dist/src/core/snapshots.js +6 -2
  37. package/dist/src/core/spaces.d.ts +2 -2
  38. package/dist/src/core/spaces.js +12 -6
  39. package/dist/src/core/store.d.ts +45 -6
  40. package/dist/src/core/store.js +214 -75
  41. package/dist/src/core/tasks.d.ts +22 -2
  42. package/dist/src/core/tasks.js +121 -12
  43. package/dist/src/gui-api.js +14 -4
  44. package/dist/src/mcp/start.d.ts +1 -1
  45. package/dist/src/mcp/start.js +4 -3
  46. package/dist/src/mcp/tools.js +86 -2
  47. package/dist/src/server/runner.js +4 -18
  48. package/gui/dist/assets/index-CVwckTU6.css +1 -0
  49. package/gui/dist/assets/index-G5uiHeLf.js +99 -0
  50. package/gui/dist/index.html +3 -3
  51. package/package.json +1 -1
  52. package/gui/dist/assets/index-CsMeMdCn.css +0 -1
  53. package/gui/dist/assets/index-DAGRLFSo.js +0 -98
@@ -4,7 +4,7 @@ import { positionBetween } from "../../shared/logic/positions.js";
4
4
  import { newId } from "./ids.js";
5
5
  import { WatcherRegistry } from "./watchers.js";
6
6
  import { MAX_TASK_DEPTH, TASK_PRIORITIES, TASK_STATUSES, } from "../../shared/schemas/enums.schema.js";
7
- import { AccessLinkSchema, AgentActionSchema, AgentInstructionsSchema, AgentTokenSchema, AgentRequestSchema, AttachmentSchema, BoardViewSchema, ChangeSchema, ChecklistItemSchema, CommentSchema, EntityVersionSchema, IdeaSchema, IdeaSnapshotSchema, InvitationSchema, MembershipSchema, NotificationSchema, SessionSchema, SpaceSchema, TagSchema, TaskSchema, TaskSnapshotSchema, TestCheckpointSchema, TestResultSchema, TestReviewSchema, UserSchema, UserSettingsSchema, SpaceNotificationSettingsSchema, } from "../../shared/schemas/entities.schema.js";
7
+ import { AccessLinkSchema, AgentActionSchema, AgentInstructionsSchema, AgentTokenSchema, AgentRequestSchema, AttachmentSchema, BoardViewSchema, ChangeSchema, ChecklistItemSchema, CommentSchema, EntityVersionSchema, FollowUpSchema, IdeaSchema, IdeaSnapshotSchema, InvitationSchema, MembershipSchema, NotificationSchema, SessionSchema, SpaceSchema, TagSchema, TaskSchema, TaskSnapshotSchema, TestCheckpointSchema, TestResultSchema, TestReviewSchema, UserSchema, UserSettingsSchema, SpaceNotificationSettingsSchema, } from "../../shared/schemas/entities.schema.js";
8
8
  import { RunnerSessionRecordSchema, RunnerSettingsSchema } from "../../shared/schemas/admin-api.schema.js";
9
9
  /** Valide `value` avec `schema` ; une donnée invalide est une erreur métier qui liste les champs fautifs. */
10
10
  function validate(schema, value, what) {
@@ -37,6 +37,8 @@ function spaceNotificationSettingsFromRow(row) {
37
37
  notifyAssignEmail: bool(row.notify_assign_email),
38
38
  notifyCommentApp: bool(row.notify_comment_app),
39
39
  notifyCommentEmail: bool(row.notify_comment_email),
40
+ notifyFollowUpApp: bool(row.notify_follow_up_app),
41
+ notifyFollowUpEmail: bool(row.notify_follow_up_email),
40
42
  });
41
43
  }
42
44
  function agentInstructionsFromRow(row) {
@@ -59,10 +61,10 @@ function runnerSessionFromRow(row) {
59
61
  cacheCreationTokens: row.cache_creation_tokens,
60
62
  });
61
63
  }
62
- /** Les quatre préférences de notification d'un objet qui les porte. */
64
+ /** Les préférences de notification d'un objet qui les porte. */
63
65
  function preferencesOf(source) {
64
- const { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail } = source;
65
- return { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail };
66
+ const { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail, notifyFollowUpApp, notifyFollowUpEmail } = source;
67
+ return { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail, notifyFollowUpApp, notifyFollowUpEmail };
66
68
  }
67
69
  function settingsFromRow(row) {
68
70
  return UserSettingsSchema.parse({
@@ -71,6 +73,8 @@ function settingsFromRow(row) {
71
73
  notifyAssignEmail: bool(row.notify_assign_email),
72
74
  notifyCommentApp: bool(row.notify_comment_app),
73
75
  notifyCommentEmail: bool(row.notify_comment_email),
76
+ notifyFollowUpApp: bool(row.notify_follow_up_app),
77
+ notifyFollowUpEmail: bool(row.notify_follow_up_email),
74
78
  assistantHistory: row.assistant_history,
75
79
  });
76
80
  }
@@ -177,6 +181,8 @@ function boardViewFromRow(row) {
177
181
  showEmptyGroups: bool(row.show_empty_groups),
178
182
  statuses: JSON.parse(row.statuses),
179
183
  priorities: JSON.parse(row.priorities),
184
+ assigneeIds: JSON.parse(row.assignee_ids),
185
+ unassigned: bool(row.unassigned),
180
186
  position: row.position,
181
187
  createdAt: row.created_at,
182
188
  updatedAt: row.updated_at,
@@ -193,8 +199,9 @@ function requestFromRow(row) {
193
199
  text: row.text,
194
200
  status: row.status,
195
201
  reply: row.reply,
196
- followUps: JSON.parse(row.follow_ups),
197
202
  failureReason: row.failure_reason,
203
+ parentRequestId: row.parent_request_id,
204
+ commentId: row.comment_id,
198
205
  createdAt: row.created_at,
199
206
  updatedAt: row.updated_at,
200
207
  claimedAt: row.claimed_at,
@@ -205,6 +212,17 @@ function requestFromRow(row) {
205
212
  stoppedBy: row.stopped_by,
206
213
  });
207
214
  }
215
+ function followUpFromRow(row) {
216
+ return FollowUpSchema.parse({
217
+ id: row.id,
218
+ requestId: row.request_id,
219
+ position: row.position,
220
+ text: row.text,
221
+ doneAt: row.done_at,
222
+ doneBy: row.done_by,
223
+ doneByRequestId: row.done_by_request_id,
224
+ });
225
+ }
208
226
  function versionFromRow(row) {
209
227
  const raw = row.snapshot === null ? null : JSON.parse(row.snapshot);
210
228
  const snapshot = raw === null ? null : row.entity_type === "task" ? TaskSnapshotSchema.parse(raw) : IdeaSnapshotSchema.parse(raw);
@@ -228,6 +246,7 @@ function changeFromRow(row) {
228
246
  entityType: row.entity_type,
229
247
  entityId: row.entity_id,
230
248
  taskId: row.task_id,
249
+ actorType: row.actor_type ?? null,
231
250
  at: row.at,
232
251
  });
233
252
  }
@@ -246,6 +265,7 @@ function commentFromRow(row) {
246
265
  createdAt: row.created_at,
247
266
  editedAt: row.edited_at,
248
267
  requestId: row.request_id,
268
+ replyToCommentId: row.reply_to_comment_id,
249
269
  });
250
270
  }
251
271
  function agentActionFromRow(row) {
@@ -316,6 +336,10 @@ function notificationFromRow(row) {
316
336
  emailError: row.email_error,
317
337
  });
318
338
  }
339
+ /** Jointure qui garde les notifications dont la tâche ou la demande appartient à un espace dont le destinataire est membre. */
340
+ const VISIBLE_NOTIFICATION_JOIN = `LEFT JOIN tasks t ON t.id = n.task_id
341
+ LEFT JOIN agent_requests r ON n.task_id IS NULL AND r.id = n.request_id
342
+ JOIN memberships m ON m.space_id = COALESCE(t.space_id, r.target_space_id) AND m.user_id = n.user_id`;
319
343
  /** Libellé d'une tâche dans les messages : `ORG-41`. */
320
344
  function taskLabel(db, task) {
321
345
  return `${keyPrefixOf(db, task.spaceId)}-${task.number}`;
@@ -488,7 +512,7 @@ export class Store {
488
512
  /** Espaces dont l'utilisateur est membre : son espace personnel d'abord, puis les espaces communs par nom. */
489
513
  listSpacesOf(userId) {
490
514
  const rows = this.db
491
- .prepare(`SELECT s.* FROM spaces s JOIN memberships m ON m.space_id = s.id
515
+ .prepare(`SELECT s.* FROM spaces s JOIN memberships m ON m.space_id = s.id
492
516
  WHERE m.user_id = ? ORDER BY s.kind = 'shared', s.name COLLATE NOCASE`)
493
517
  .all(userId);
494
518
  return rows.map(spaceFromRow);
@@ -538,6 +562,23 @@ export class Store {
538
562
  const rows = this.db.prepare("SELECT user_id FROM task_assignees WHERE task_id = ? ORDER BY user_id").all(taskId);
539
563
  return rows.map((row) => row.user_id);
540
564
  }
565
+ /** Tâches d'un espace auxquelles un utilisateur est assigné. */
566
+ listAssignedTaskIds(spaceId, userId) {
567
+ return this.db
568
+ .prepare("SELECT x.task_id FROM task_assignees x JOIN tasks t ON t.id = x.task_id WHERE t.space_id = ? AND x.user_id = ? ORDER BY t.number")
569
+ .pluck()
570
+ .all(spaceId, userId);
571
+ }
572
+ /** Nombre de tâches d'un espace assignées à un utilisateur, par statut. */
573
+ countAssignedTasks(spaceId, userId) {
574
+ const rows = this.db
575
+ .prepare("SELECT t.status AS status, COUNT(*) AS n FROM task_assignees x JOIN tasks t ON t.id = x.task_id WHERE t.space_id = ? AND x.user_id = ? GROUP BY t.status")
576
+ .all(spaceId, userId);
577
+ const counts = { todo: 0, doing: 0, review: 0, done: 0 };
578
+ for (const row of rows)
579
+ counts[row.status] = row.n;
580
+ return counts;
581
+ }
541
582
  listTagIds(taskId) {
542
583
  const rows = this.db.prepare("SELECT tag_id FROM task_tags WHERE task_id = ? ORDER BY tag_id").all(taskId);
543
584
  return rows.map((row) => row.tag_id);
@@ -643,7 +684,7 @@ export class Store {
643
684
  /** Résultats saisis sur les points des tâches d'un espace. */
644
685
  listTestResultsInSpace(spaceId) {
645
686
  const rows = this.db
646
- .prepare(`SELECT c.task_id, r.checkpoint_id, r.tester_id, r.result FROM test_results r
687
+ .prepare(`SELECT c.task_id, r.checkpoint_id, r.tester_id, r.result FROM test_results r
647
688
  JOIN test_checkpoints c ON c.id = r.checkpoint_id JOIN tasks t ON t.id = c.task_id WHERE t.space_id = ?`)
648
689
  .all(spaceId);
649
690
  return rows.map((row) => ({
@@ -688,7 +729,7 @@ export class Store {
688
729
  /** Pièces jointes d'une tâche et de toutes ses sous-tâches. */
689
730
  listAttachmentsInSubtree(taskId) {
690
731
  const rows = this.db
691
- .prepare(`WITH RECURSIVE subtree(id) AS (SELECT ? UNION ALL SELECT t.id FROM tasks t JOIN subtree s ON t.parent_id = s.id)
732
+ .prepare(`WITH RECURSIVE subtree(id) AS (SELECT ? UNION ALL SELECT t.id FROM tasks t JOIN subtree s ON t.parent_id = s.id)
692
733
  SELECT a.* FROM attachments a JOIN subtree s ON a.task_id = s.id`)
693
734
  .all(taskId);
694
735
  return rows.map(attachmentFromRow);
@@ -718,7 +759,7 @@ export class Store {
718
759
  /** Demandes de promotion (`idea_promotion`) en attente ou en cours sur les idées d'un espace. */
719
760
  listOpenPromotionRequests(spaceId) {
720
761
  const rows = this.db
721
- .prepare(`SELECT r.* FROM agent_requests r JOIN ideas i ON i.id = r.context_idea_id
762
+ .prepare(`SELECT r.* FROM agent_requests r JOIN ideas i ON i.id = r.context_idea_id
722
763
  WHERE i.space_id = ? AND r.kind = 'idea_promotion' AND r.status IN ('pending', 'processing') ORDER BY r.created_at, r.id`)
723
764
  .all(spaceId);
724
765
  return rows.map(requestFromRow);
@@ -775,9 +816,9 @@ export class Store {
775
816
  if (limit === 0)
776
817
  return [];
777
818
  const rows = this.db
778
- .prepare(`SELECT * FROM agent_requests
779
- WHERE target_space_id = @spaceId AND author_id = @authorId AND status IN ('done', 'failed')
780
- AND (created_at < @createdAt OR (created_at = @createdAt AND id < @id))
819
+ .prepare(`SELECT * FROM agent_requests
820
+ WHERE target_space_id = @spaceId AND author_id = @authorId AND status IN ('done', 'failed')
821
+ AND (created_at < @createdAt OR (created_at = @createdAt AND id < @id))
781
822
  ORDER BY created_at DESC, id DESC LIMIT @limit`)
782
823
  .all({ spaceId, authorId, createdAt: before.createdAt, id: before.id, limit });
783
824
  return rows.map(requestFromRow).reverse();
@@ -789,6 +830,31 @@ export class Store {
789
830
  .all({ spaceId, limit });
790
831
  return rows.map(requestFromRow);
791
832
  }
833
+ /** Demande confiée à l'agent par un commentaire, ou null. */
834
+ findRequestOfComment(commentId) {
835
+ const row = this.db.prepare("SELECT * FROM agent_requests WHERE comment_id = ? ORDER BY created_at LIMIT 1").get(commentId);
836
+ return row ? requestFromRow(row) : null;
837
+ }
838
+ /** Suites d'une demande d'origine, de la plus ancienne à la plus récente. */
839
+ listSuitesOf(requestId) {
840
+ const rows = this.db.prepare("SELECT * FROM agent_requests WHERE parent_request_id = ? ORDER BY created_at, id").all(requestId);
841
+ return rows.map(requestFromRow);
842
+ }
843
+ /** Points à régler d'une demande, dans l'ordre où l'agent les a laissés. */
844
+ listFollowUps(requestId) {
845
+ const rows = this.db.prepare("SELECT * FROM follow_ups WHERE request_id = ? ORDER BY position").all(requestId);
846
+ return rows.map(followUpFromRow);
847
+ }
848
+ findFollowUp(id) {
849
+ const row = this.db.prepare("SELECT * FROM follow_ups WHERE id = ?").get(id);
850
+ return row ? followUpFromRow(row) : null;
851
+ }
852
+ getFollowUp(id) {
853
+ const followUp = this.findFollowUp(id);
854
+ if (!followUp)
855
+ throw new NotFoundError(`Follow-up ${id} not found.`);
856
+ return followUp;
857
+ }
792
858
  /** Nombre de demandes en attente d'un espace. */
793
859
  countPendingRequestsOfSpace(spaceId) {
794
860
  const row = this.db.prepare("SELECT COUNT(*) AS n FROM agent_requests WHERE status = 'pending' AND target_space_id = ?").get(spaceId);
@@ -839,14 +905,13 @@ export class Store {
839
905
  }
840
906
  /**
841
907
  * Notifications affichées dans l'application d'un utilisateur, sur les
842
- * tâches des espaces dont il est encore membre : non lues d'abord, puis de
843
- * la plus récente à la plus ancienne.
908
+ * tâches ou les demandes des espaces dont il est encore membre : non lues
909
+ * d'abord, puis de la plus récente à la plus ancienne.
844
910
  */
845
911
  listNotifications(userId, limit, offset) {
846
912
  const rows = this.db
847
- .prepare(`SELECT n.* FROM notifications n JOIN tasks t ON t.id = n.task_id
848
- JOIN memberships m ON m.space_id = t.space_id AND m.user_id = n.user_id
849
- WHERE n.user_id = ? AND n.in_app = 1
913
+ .prepare(`SELECT n.* FROM notifications n ${VISIBLE_NOTIFICATION_JOIN}
914
+ WHERE n.user_id = ? AND n.in_app = 1
850
915
  ORDER BY n.read_at IS NOT NULL, n.created_at DESC, n.id DESC LIMIT ? OFFSET ?`)
851
916
  .all(userId, limit, offset);
852
917
  return rows.map(notificationFromRow);
@@ -854,8 +919,7 @@ export class Store {
854
919
  /** Nombre de notifications non lues affichées dans l'application d'un utilisateur. */
855
920
  countUnreadNotifications(userId) {
856
921
  const row = this.db
857
- .prepare(`SELECT COUNT(*) AS n FROM notifications n JOIN tasks t ON t.id = n.task_id
858
- JOIN memberships m ON m.space_id = t.space_id AND m.user_id = n.user_id
922
+ .prepare(`SELECT COUNT(*) AS n FROM notifications n ${VISIBLE_NOTIFICATION_JOIN}
859
923
  WHERE n.user_id = ? AND n.in_app = 1 AND n.read_at IS NULL`)
860
924
  .get(userId);
861
925
  return row.n;
@@ -884,8 +948,8 @@ export class Store {
884
948
  */
885
949
  listChangesForUser(userId, since, limit) {
886
950
  const rows = this.db
887
- .prepare(`SELECT * FROM changes WHERE seq > ?
888
- AND (user_id = ? OR space_id IN (SELECT space_id FROM memberships WHERE user_id = ?))
951
+ .prepare(`SELECT * FROM changes WHERE seq > ?
952
+ AND (user_id = ? OR space_id IN (SELECT space_id FROM memberships WHERE user_id = ?))
889
953
  ORDER BY seq LIMIT ?`)
890
954
  .all(since, userId, userId, limit);
891
955
  return rows.map(changeFromRow);
@@ -1047,13 +1111,13 @@ export class Mutation {
1047
1111
  }
1048
1112
  this.agentWriteChecked = true;
1049
1113
  }
1050
- touch(entityType, entityId, spaceId, userId, taskId = null) {
1114
+ touch(entityType, entityId, spaceId, userId, taskId = null, scopeSpaceId = spaceId) {
1051
1115
  if (entityType !== "agent_request")
1052
1116
  this.assertAgentMayWrite();
1053
1117
  const key = `${entityType}:${entityId}`;
1054
1118
  const concernedTask = entityType === "task" ? entityId : taskId;
1055
1119
  if (!this.touched.has(key))
1056
- this.touched.set(key, { entityType, entityId, spaceId, userId, taskId: concernedTask });
1120
+ this.touched.set(key, { entityType, entityId, spaceId, userId, taskId: concernedTask, scopeSpaceId });
1057
1121
  }
1058
1122
  // --- Utilisateurs ---
1059
1123
  createUser(input) {
@@ -1167,7 +1231,7 @@ export class Mutation {
1167
1231
  if (!this.store.isMember(token.spaceId, token.userId))
1168
1232
  throw new ForbiddenError("An agent token can only cover a space its owner is a member of.");
1169
1233
  this.db
1170
- .prepare(`INSERT INTO agent_tokens (id, user_id, space_id, name, prefix, token_hash, created_at, expires_at, is_runner)
1234
+ .prepare(`INSERT INTO agent_tokens (id, user_id, space_id, name, prefix, token_hash, created_at, expires_at, is_runner)
1171
1235
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1172
1236
  .run(token.id, token.userId, token.spaceId, token.name, token.prefix, token.tokenHash, token.createdAt, token.expiresAt, token.isRunner ? 1 : 0);
1173
1237
  this.touch("agent_token", token.id, null, token.userId);
@@ -1303,7 +1367,7 @@ export class Mutation {
1303
1367
  this.touch("membership", `${id}:${membership.userId}`, id, membership.userId);
1304
1368
  }
1305
1369
  this.db
1306
- .prepare(`DELETE FROM entity_versions WHERE (entity_type = 'task' AND entity_id IN (SELECT id FROM tasks WHERE space_id = ?))
1370
+ .prepare(`DELETE FROM entity_versions WHERE (entity_type = 'task' AND entity_id IN (SELECT id FROM tasks WHERE space_id = ?))
1307
1371
  OR (entity_type = 'idea' AND entity_id IN (SELECT id FROM ideas WHERE space_id = ?))`)
1308
1372
  .run(id, id);
1309
1373
  this.db.prepare("DELETE FROM spaces WHERE id = ?").run(id);
@@ -1324,13 +1388,24 @@ export class Mutation {
1324
1388
  this.touch("membership", `${spaceId}:${userId}`, spaceId, userId);
1325
1389
  return { ...membership, role };
1326
1390
  }
1327
- /** Retire un membre d'un espace et révoque ses jetons d'agent sur cet espace. */
1391
+ /**
1392
+ * Retire un membre d'un espace : le désassigne des tâches de l'espace, le
1393
+ * retire du filtre des assignés des vues de l'espace et révoque ses jetons
1394
+ * d'agent sur cet espace. Ses résultats de test restent.
1395
+ */
1328
1396
  removeMember(spaceId, userId) {
1329
1397
  if (!this.store.findMembership(spaceId, userId))
1330
1398
  throw new NotFoundError(`User ${userId} is not a member of space ${spaceId}.`);
1399
+ for (const taskId of this.store.listAssignedTaskIds(spaceId, userId)) {
1400
+ this.setAssignees(taskId, this.store.listAssigneeIds(taskId).filter((id) => id !== userId));
1401
+ }
1331
1402
  this.db.prepare("DELETE FROM memberships WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
1332
1403
  this.db.prepare("DELETE FROM space_notification_settings WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
1333
1404
  this.db.prepare("DELETE FROM board_views WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
1405
+ const filtering = this.db.prepare("SELECT * FROM board_views WHERE space_id = ?").all(spaceId);
1406
+ for (const view of filtering.map(boardViewFromRow).filter((view) => view.assigneeIds.includes(userId))) {
1407
+ this.updateBoardView(view.id, { assigneeIds: view.assigneeIds.filter((id) => id !== userId) });
1408
+ }
1334
1409
  this.touch("membership", `${spaceId}:${userId}`, spaceId, userId);
1335
1410
  const tokenIds = this.db.prepare("SELECT id FROM agent_tokens WHERE space_id = ? AND user_id = ? AND revoked_at IS NULL").pluck().all(spaceId, userId);
1336
1411
  this.db.prepare("UPDATE agent_tokens SET revoked_at = ? WHERE space_id = ? AND user_id = ? AND revoked_at IS NULL").run(this.now, spaceId, userId);
@@ -1368,8 +1443,8 @@ export class Mutation {
1368
1443
  version: 1,
1369
1444
  }, "task");
1370
1445
  this.db
1371
- .prepare(`INSERT INTO tasks (id, space_id, number, parent_id, depth, type, title, description, status, priority, position,
1372
- created_by, created_at, updated_at, version)
1446
+ .prepare(`INSERT INTO tasks (id, space_id, number, parent_id, depth, type, title, description, status, priority, position,
1447
+ created_by, created_at, updated_at, version)
1373
1448
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1374
1449
  .run(task.id, task.spaceId, task.number, task.parentId, task.depth, task.type, task.title, task.description, task.status, task.priority, task.position, task.createdBy, task.createdAt, task.updatedAt, task.version);
1375
1450
  this.db.prepare("UPDATE spaces SET next_task_number = next_task_number + 1 WHERE id = ?").run(space.id);
@@ -1403,7 +1478,7 @@ export class Mutation {
1403
1478
  const testedTaskId = fields.testedTaskId !== undefined ? fields.testedTaskId : type === "standard" ? null : current.testedTaskId;
1404
1479
  const task = validate(TaskSchema, { ...current, ...fields, parentId, depth, status, position, testedTaskId, updatedAt: this.now }, "task");
1405
1480
  this.db
1406
- .prepare(`UPDATE tasks SET parent_id = ?, depth = ?, type = ?, title = ?, description = ?, status = ?, priority = ?,
1481
+ .prepare(`UPDATE tasks SET parent_id = ?, depth = ?, type = ?, title = ?, description = ?, status = ?, priority = ?,
1407
1482
  position = ?, tested_task_id = ?, updated_at = ? WHERE id = ?`)
1408
1483
  .run(task.parentId, task.depth, task.type, task.title, task.description, task.status, task.priority, task.position, task.testedTaskId, task.updatedAt, id);
1409
1484
  this.touch("task", id, task.spaceId, null);
@@ -1662,7 +1737,7 @@ export class Mutation {
1662
1737
  updatedAt: this.now,
1663
1738
  }, "test result");
1664
1739
  this.db
1665
- .prepare(`INSERT INTO test_results (checkpoint_id, tester_id, result, comment, updated_at) VALUES (?, ?, ?, ?, ?)
1740
+ .prepare(`INSERT INTO test_results (checkpoint_id, tester_id, result, comment, updated_at) VALUES (?, ?, ?, ?, ?)
1666
1741
  ON CONFLICT (checkpoint_id, tester_id) DO UPDATE SET result = excluded.result, comment = excluded.comment, updated_at = excluded.updated_at`)
1667
1742
  .run(result.checkpointId, result.testerId, result.result, result.comment, result.updatedAt);
1668
1743
  this.touch("test_result", `${checkpointId}:${testerId}`, task.spaceId, null, task.id);
@@ -1704,13 +1779,13 @@ export class Mutation {
1704
1779
  return { review: { ...draft, submittedAt: this.now, requestId: request.id }, request };
1705
1780
  }
1706
1781
  // --- Commentaires ---
1707
- /** Commentaire de l'utilisateur acteur sur une tâche. */
1708
- addComment(taskId, body) {
1782
+ /** Commentaire de l'utilisateur acteur sur une tâche ; `replyToCommentId` : commentaire auquel l'agent répond. */
1783
+ addComment(taskId, body, replyToCommentId = null) {
1709
1784
  const task = this.store.getTask(taskId);
1710
- const comment = validate(CommentSchema, { id: newId(), taskId, authorId: this.actingUserId, body, createdAt: this.now, editedAt: null, requestId: this.request?.id ?? null }, "comment");
1785
+ const comment = validate(CommentSchema, { id: newId(), taskId, authorId: this.actingUserId, body, createdAt: this.now, editedAt: null, requestId: this.request?.id ?? null, replyToCommentId }, "comment");
1711
1786
  this.db
1712
- .prepare("INSERT INTO comments (id, task_id, author_id, body, created_at, edited_at, request_id) VALUES (?, ?, ?, ?, ?, ?, ?)")
1713
- .run(comment.id, comment.taskId, comment.authorId, comment.body, comment.createdAt, comment.editedAt, comment.requestId);
1787
+ .prepare("INSERT INTO comments (id, task_id, author_id, body, created_at, edited_at, request_id, reply_to_comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
1788
+ .run(comment.id, comment.taskId, comment.authorId, comment.body, comment.createdAt, comment.editedAt, comment.requestId, comment.replyToCommentId);
1714
1789
  this.touch("comment", comment.id, task.spaceId, null, taskId);
1715
1790
  const commenters = this.store.listComments(taskId).filter((other) => other.id !== comment.id).map((other) => other.authorId);
1716
1791
  const recipients = [...new Set([...this.store.listAssigneeIds(taskId), ...commenters])].sort();
@@ -1825,7 +1900,7 @@ export class Mutation {
1825
1900
  createdAt: this.now,
1826
1901
  }, "idea");
1827
1902
  this.db
1828
- .prepare(`INSERT INTO ideas (id, space_id, author_id, text, origin, request_id, promoted_task_id, archived_at, created_at)
1903
+ .prepare(`INSERT INTO ideas (id, space_id, author_id, text, origin, request_id, promoted_task_id, archived_at, created_at)
1829
1904
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1830
1905
  .run(idea.id, idea.spaceId, idea.authorId, idea.text, idea.origin, idea.requestId, idea.promotedTaskId, idea.archivedAt, idea.createdAt);
1831
1906
  this.touch("idea", idea.id, idea.spaceId, null);
@@ -1872,27 +1947,38 @@ export class Mutation {
1872
1947
  createdAt: this.now,
1873
1948
  updatedAt: this.now,
1874
1949
  }, "board view");
1875
- this.db
1876
- .prepare(`INSERT INTO board_views (id, space_id, user_id, name, layout, group_by, then_by, show_empty_groups, statuses, priorities, position, created_at, updated_at)
1877
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1878
- .run(view.id, view.spaceId, view.userId, view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), view.position, view.createdAt, view.updatedAt);
1879
- this.touch("board_view", view.id, null, userId);
1950
+ this.insertBoardView(view);
1880
1951
  return view;
1881
1952
  }
1953
+ /** Recrée une vue supprimée, avec son identifiant et sa position d'alors. */
1954
+ restoreBoardView(view) {
1955
+ if (!this.store.findMembership(view.spaceId, view.userId))
1956
+ throw new NotFoundError(`User ${view.userId} is not a member of space ${view.spaceId}.`);
1957
+ const restored = validate(BoardViewSchema, { ...view, updatedAt: this.now }, "board view");
1958
+ this.insertBoardView(restored);
1959
+ return restored;
1960
+ }
1961
+ insertBoardView(view) {
1962
+ this.db
1963
+ .prepare(`INSERT INTO board_views (id, space_id, user_id, name, layout, group_by, then_by, show_empty_groups, statuses, priorities, assignee_ids, unassigned, position, created_at, updated_at)
1964
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1965
+ .run(view.id, view.spaceId, view.userId, view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), JSON.stringify(view.assigneeIds), view.unassigned ? 1 : 0, view.position, view.createdAt, view.updatedAt);
1966
+ this.touch("board_view", view.id, null, view.userId, null, view.spaceId);
1967
+ }
1882
1968
  updateBoardView(id, patch) {
1883
1969
  const current = this.store.getBoardView(id);
1884
1970
  const view = validate(BoardViewSchema, { ...current, ...normalizedSettings({ ...current, ...definedFields(patch) }), updatedAt: this.now }, "board view");
1885
1971
  this.db
1886
- .prepare(`UPDATE board_views SET name = ?, layout = ?, group_by = ?, then_by = ?, show_empty_groups = ?, statuses = ?, priorities = ?, updated_at = ?
1972
+ .prepare(`UPDATE board_views SET name = ?, layout = ?, group_by = ?, then_by = ?, show_empty_groups = ?, statuses = ?, priorities = ?, assignee_ids = ?, unassigned = ?, updated_at = ?
1887
1973
  WHERE id = ?`)
1888
- .run(view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), view.updatedAt, id);
1889
- this.touch("board_view", id, null, view.userId);
1974
+ .run(view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), JSON.stringify(view.assigneeIds), view.unassigned ? 1 : 0, view.updatedAt, id);
1975
+ this.touch("board_view", id, null, view.userId, null, view.spaceId);
1890
1976
  return view;
1891
1977
  }
1892
1978
  deleteBoardView(id) {
1893
1979
  const view = this.store.getBoardView(id);
1894
1980
  this.db.prepare("DELETE FROM board_views WHERE id = ?").run(id);
1895
- this.touch("board_view", id, null, view.userId);
1981
+ this.touch("board_view", id, null, view.userId, null, view.spaceId);
1896
1982
  }
1897
1983
  // --- Demandes ---
1898
1984
  /** Dépose une demande `pending` de l'utilisateur acteur. */
@@ -1909,8 +1995,9 @@ export class Mutation {
1909
1995
  text: input.text,
1910
1996
  status: "pending",
1911
1997
  reply: null,
1912
- followUps: [],
1913
1998
  failureReason: null,
1999
+ parentRequestId: input.parentRequestId ?? null,
2000
+ commentId: input.commentId ?? null,
1914
2001
  createdAt: this.now,
1915
2002
  updatedAt: this.now,
1916
2003
  claimedAt: null,
@@ -1922,10 +2009,10 @@ export class Mutation {
1922
2009
  }, "request");
1923
2010
  this.store.getSpace(request.targetSpaceId);
1924
2011
  this.db
1925
- .prepare(`INSERT INTO agent_requests (id, author_id, target_space_id, kind, context_task_id, context_idea_id,
1926
- text, status, created_at, updated_at)
1927
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1928
- .run(request.id, request.authorId, request.targetSpaceId, request.kind, request.contextTaskId, request.contextIdeaId, request.text, request.status, request.createdAt, request.updatedAt);
2012
+ .prepare(`INSERT INTO agent_requests (id, author_id, target_space_id, kind, context_task_id, context_idea_id,
2013
+ text, status, parent_request_id, comment_id, created_at, updated_at)
2014
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2015
+ .run(request.id, request.authorId, request.targetSpaceId, request.kind, request.contextTaskId, request.contextIdeaId, request.text, request.status, request.parentRequestId, request.commentId, request.createdAt, request.updatedAt);
1929
2016
  this.createdRequestIds.add(request.id);
1930
2017
  this.pendingRequestIds.push(request.id);
1931
2018
  this.touchRequest(request);
@@ -1991,9 +2078,10 @@ export class Mutation {
1991
2078
  if (current.status !== "failed" || current.stoppedAt === null)
1992
2079
  throw new InvariantError(`Request ${id} is ${current.status}: only a stopped request can be relaunched.`);
1993
2080
  this.db
1994
- .prepare(`UPDATE agent_requests SET status = 'pending', claimed_at = NULL, claimed_by_token_id = NULL, completed_at = NULL, failure_reason = NULL,
1995
- follow_ups = '[]', stopped_at = NULL, stopped_by = NULL, updated_at = ? WHERE id = ?`)
2081
+ .prepare(`UPDATE agent_requests SET status = 'pending', claimed_at = NULL, claimed_by_token_id = NULL, completed_at = NULL, failure_reason = NULL,
2082
+ stopped_at = NULL, stopped_by = NULL, updated_at = ? WHERE id = ?`)
1996
2083
  .run(this.now, id);
2084
+ this.db.prepare("DELETE FROM follow_ups WHERE request_id = ?").run(id);
1997
2085
  const relaunched = this.store.getAgentRequest(id);
1998
2086
  this.pendingRequestIds.push(id);
1999
2087
  this.touchRequest(relaunched);
@@ -2056,12 +2144,51 @@ export class Mutation {
2056
2144
  const column = status === "done" ? "reply" : "failure_reason";
2057
2145
  const points = followUps.map((point) => point.trim()).filter((point) => point !== "");
2058
2146
  this.db
2059
- .prepare(`UPDATE agent_requests SET status = ?, ${column} = ?, follow_ups = ?, completed_at = ?, updated_at = ? WHERE id = ?`)
2060
- .run(status, text, JSON.stringify(points), this.now, this.now, request.id);
2147
+ .prepare(`UPDATE agent_requests SET status = ?, ${column} = ?, completed_at = ?, updated_at = ? WHERE id = ?`)
2148
+ .run(status, text, this.now, this.now, request.id);
2149
+ const insert = this.db.prepare("INSERT INTO follow_ups (id, request_id, position, text) VALUES (?, ?, ?, ?)");
2150
+ points.forEach((point, index) => insert.run(newId(), request.id, index + 1, point));
2061
2151
  const finished = this.store.getAgentRequest(request.id);
2062
2152
  this.touchRequest(finished);
2153
+ if (points.length > 0)
2154
+ this.notifyFollowUps(finished);
2155
+ const source = status === "done" && finished.commentId !== null ? this.store.findComment(finished.commentId) : null;
2156
+ if (source)
2157
+ this.addComment(source.taskId, text, source.id);
2063
2158
  return finished;
2064
2159
  }
2160
+ // --- Points à régler ---
2161
+ /**
2162
+ * Coche ou décoche un point. Coché par un utilisateur, il retient son nom ;
2163
+ * par l'agent, la demande pour laquelle il agit. Un point déjà dans l'état
2164
+ * demandé garde son auteur et sa date.
2165
+ */
2166
+ setFollowUpDone(id, done) {
2167
+ const current = this.store.getFollowUp(id);
2168
+ if ((current.doneAt !== null) === done)
2169
+ return current;
2170
+ if (!done)
2171
+ return this.writeFollowUpState(current, { doneAt: null, doneBy: null, doneByRequestId: null });
2172
+ return this.writeFollowUpState(current, {
2173
+ doneAt: this.now,
2174
+ doneBy: this.actor.type === "user" ? this.actor.userId : null,
2175
+ doneByRequestId: this.actor.type === "agent" ? this.agentRequest().request.id : null,
2176
+ });
2177
+ }
2178
+ /** Ramène un point à un état antérieur : coché (par qui, quand) ou non. */
2179
+ restoreFollowUpState(id, state) {
2180
+ return this.writeFollowUpState(this.store.getFollowUp(id), state);
2181
+ }
2182
+ writeFollowUpState(current, state) {
2183
+ const followUp = validate(FollowUpSchema, { ...current, ...state }, "follow-up");
2184
+ this.db
2185
+ .prepare("UPDATE follow_ups SET done_at = ?, done_by = ?, done_by_request_id = ? WHERE id = ?")
2186
+ .run(followUp.doneAt, followUp.doneBy, followUp.doneByRequestId, followUp.id);
2187
+ const request = this.store.getAgentRequest(followUp.requestId);
2188
+ this.touch("follow_up", followUp.id, request.targetSpaceId, request.authorId);
2189
+ this.touchRequest(request);
2190
+ return followUp;
2191
+ }
2065
2192
  // --- Actions de l'agent ---
2066
2193
  /** Enregistre une action de l'agent dans le lot de sa demande, avec le rang suivant. */
2067
2194
  recordAgentAction(input) {
@@ -2083,7 +2210,7 @@ export class Mutation {
2083
2210
  tokenId: token.id,
2084
2211
  }, "agent action");
2085
2212
  this.db
2086
- .prepare(`INSERT INTO agent_actions (id, request_id, seq, entity_type, entity_id, operation, before, after, summary, created_at, token_id)
2213
+ .prepare(`INSERT INTO agent_actions (id, request_id, seq, entity_type, entity_id, operation, before, after, summary, created_at, token_id)
2087
2214
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2088
2215
  .run(action.id, action.requestId, action.seq, action.entityType, action.entityId, action.operation, action.before === null ? null : JSON.stringify(action.before), action.after === null ? null : JSON.stringify(action.after), action.summary, action.createdAt, action.tokenId);
2089
2216
  this.touch("agent_action", action.id, request.targetSpaceId, null, input.taskId);
@@ -2113,11 +2240,19 @@ export class Mutation {
2113
2240
  * deux sont désactivés.
2114
2241
  */
2115
2242
  notify(type, userId, taskId, commentId) {
2116
- const settings = this.store.notificationPreferences(userId, this.store.getTask(taskId).spaceId);
2117
- const inApp = type === "assigned" ? settings.notifyAssignApp : settings.notifyCommentApp;
2118
- const email = type === "assigned" ? settings.notifyAssignEmail : settings.notifyCommentEmail;
2243
+ this.insertNotification(type, userId, this.store.getTask(taskId).spaceId, { taskId, requestId: this.request?.id ?? null, commentId });
2244
+ }
2245
+ /** Notifie l'auteur d'une demande que l'agent l'a traitée en lui laissant des points à régler. */
2246
+ notifyFollowUps(request) {
2247
+ this.insertNotification("follow_ups", request.authorId, request.targetSpaceId, { taskId: null, requestId: request.id, commentId: null });
2248
+ }
2249
+ insertNotification(type, userId, spaceId, about) {
2250
+ const settings = this.store.notificationPreferences(userId, spaceId);
2251
+ const inApp = { assigned: settings.notifyAssignApp, comment: settings.notifyCommentApp, follow_ups: settings.notifyFollowUpApp }[type];
2252
+ const email = { assigned: settings.notifyAssignEmail, comment: settings.notifyCommentEmail, follow_ups: settings.notifyFollowUpEmail }[type];
2119
2253
  if (!inApp && !email)
2120
2254
  return;
2255
+ const { taskId, requestId, commentId } = about;
2121
2256
  const notification = validate(NotificationSchema, {
2122
2257
  id: newId(),
2123
2258
  userId,
@@ -2125,7 +2260,7 @@ export class Mutation {
2125
2260
  taskId,
2126
2261
  actorType: this.actor.type,
2127
2262
  actorId: this.actor.type === "user" ? this.actor.userId : null,
2128
- requestId: this.request?.id ?? null,
2263
+ requestId,
2129
2264
  commentId,
2130
2265
  inApp,
2131
2266
  createdAt: this.now,
@@ -2134,7 +2269,7 @@ export class Mutation {
2134
2269
  emailError: null,
2135
2270
  }, "notification");
2136
2271
  this.db
2137
- .prepare(`INSERT INTO notifications (id, user_id, type, task_id, actor_type, actor_id, request_id, comment_id, in_app, created_at)
2272
+ .prepare(`INSERT INTO notifications (id, user_id, type, task_id, actor_type, actor_id, request_id, comment_id, in_app, created_at)
2138
2273
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2139
2274
  .run(notification.id, notification.userId, notification.type, notification.taskId, notification.actorType, notification.actorId, notification.requestId, notification.commentId, inApp ? 1 : 0, notification.createdAt);
2140
2275
  if (inApp)
@@ -2176,9 +2311,9 @@ export class Mutation {
2176
2311
  updateUserSettings(userId, patch) {
2177
2312
  const settings = validate(UserSettingsSchema, { ...this.store.getUserSettings(userId), ...definedFields(patch) }, "settings");
2178
2313
  this.db
2179
- .prepare(`UPDATE user_settings SET notify_assign_app = ?, notify_assign_email = ?, notify_comment_app = ?, notify_comment_email = ?,
2180
- assistant_history = ? WHERE user_id = ?`)
2181
- .run(settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0, settings.assistantHistory, userId);
2314
+ .prepare(`UPDATE user_settings SET notify_assign_app = ?, notify_assign_email = ?, notify_comment_app = ?, notify_comment_email = ?,
2315
+ notify_follow_up_app = ?, notify_follow_up_email = ?, assistant_history = ? WHERE user_id = ?`)
2316
+ .run(settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0, settings.notifyFollowUpApp ? 1 : 0, settings.notifyFollowUpEmail ? 1 : 0, settings.assistantHistory, userId);
2182
2317
  this.touch("user_settings", userId, null, userId);
2183
2318
  return settings;
2184
2319
  }
@@ -2196,11 +2331,13 @@ export class Mutation {
2196
2331
  }
2197
2332
  const settings = validate(SpaceNotificationSettingsSchema, { userId, spaceId, ...preferences }, "space notification settings");
2198
2333
  this.db
2199
- .prepare(`INSERT INTO space_notification_settings (user_id, space_id, notify_assign_app, notify_assign_email, notify_comment_app, notify_comment_email)
2200
- VALUES (?, ?, ?, ?, ?, ?)
2201
- ON CONFLICT (user_id, space_id) DO UPDATE SET notify_assign_app = excluded.notify_assign_app, notify_assign_email = excluded.notify_assign_email,
2202
- notify_comment_app = excluded.notify_comment_app, notify_comment_email = excluded.notify_comment_email`)
2203
- .run(userId, spaceId, settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0);
2334
+ .prepare(`INSERT INTO space_notification_settings (user_id, space_id, notify_assign_app, notify_assign_email, notify_comment_app, notify_comment_email,
2335
+ notify_follow_up_app, notify_follow_up_email)
2336
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
2337
+ ON CONFLICT (user_id, space_id) DO UPDATE SET notify_assign_app = excluded.notify_assign_app, notify_assign_email = excluded.notify_assign_email,
2338
+ notify_comment_app = excluded.notify_comment_app, notify_comment_email = excluded.notify_comment_email,
2339
+ notify_follow_up_app = excluded.notify_follow_up_app, notify_follow_up_email = excluded.notify_follow_up_email`)
2340
+ .run(userId, spaceId, settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0, settings.notifyFollowUpApp ? 1 : 0, settings.notifyFollowUpEmail ? 1 : 0);
2204
2341
  return settings;
2205
2342
  }
2206
2343
  /**
@@ -2236,7 +2373,7 @@ export class Mutation {
2236
2373
  recordRunnerSession(record) {
2237
2374
  const valid = validate(RunnerSessionRecordSchema, record, "runner session");
2238
2375
  this.db
2239
- .prepare(`INSERT INTO runner_sessions (id, space_id, space_name, started_at, ended_at, outcome, model, turns, cost_usd, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens)
2376
+ .prepare(`INSERT INTO runner_sessions (id, space_id, space_name, started_at, ended_at, outcome, model, turns, cost_usd, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens)
2240
2377
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2241
2378
  .run(valid.id, valid.spaceId, valid.spaceName, valid.startedAt, valid.endedAt, valid.outcome, valid.model, valid.turns, valid.costUsd, valid.inputTokens, valid.outputTokens, valid.cacheReadTokens, valid.cacheCreationTokens);
2242
2379
  }
@@ -2285,7 +2422,7 @@ export class Mutation {
2285
2422
  continue;
2286
2423
  if (entry.entityType === "agent_request" && entry.entityId === request.id)
2287
2424
  continue;
2288
- if (entry.spaceId !== request.targetSpaceId) {
2425
+ if (entry.scopeSpaceId !== request.targetSpaceId) {
2289
2426
  throw new InvariantError(`Request ${request.id} targets space ${request.targetSpaceId}; the agent cannot modify ${entry.entityType} ${entry.entityId} outside of it.`);
2290
2427
  }
2291
2428
  }
@@ -2316,8 +2453,8 @@ export class Mutation {
2316
2453
  }
2317
2454
  }
2318
2455
  const outsiders = this.db
2319
- .prepare(`SELECT t.number AS number, x.user_id AS user_id FROM task_assignees x JOIN tasks t ON t.id = x.task_id
2320
- WHERE t.space_id = ? AND NOT EXISTS (SELECT 1 FROM memberships m WHERE m.space_id = t.space_id AND m.user_id = x.user_id)
2456
+ .prepare(`SELECT t.number AS number, x.user_id AS user_id FROM task_assignees x JOIN tasks t ON t.id = x.task_id
2457
+ WHERE t.space_id = ? AND NOT EXISTS (SELECT 1 FROM memberships m WHERE m.space_id = t.space_id AND m.user_id = x.user_id)
2321
2458
  ORDER BY t.number LIMIT 1`)
2322
2459
  .get(space.id);
2323
2460
  if (outsiders) {
@@ -2389,7 +2526,7 @@ export class Mutation {
2389
2526
  const actorId = this.actingUserId;
2390
2527
  const requestId = this.request?.id ?? null;
2391
2528
  const tokenId = this.token?.id ?? null;
2392
- const insert = this.db.prepare(`INSERT INTO entity_versions (entity_type, entity_id, version, snapshot, actor_type, actor_id, request_id, created_at, token_id)
2529
+ const insert = this.db.prepare(`INSERT INTO entity_versions (entity_type, entity_id, version, snapshot, actor_type, actor_id, request_id, created_at, token_id)
2393
2530
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`);
2394
2531
  for (const entry of this.touched.values()) {
2395
2532
  if (!VERSIONED.has(entry.entityType))
@@ -2411,7 +2548,7 @@ export class Mutation {
2411
2548
  }
2412
2549
  /** Une ligne du journal par entité modifiée, avec l'auteur de la mutation. */
2413
2550
  writeChanges() {
2414
- const insert = this.db.prepare(`INSERT INTO changes (space_id, user_id, entity_type, entity_id, task_id, at, actor_type, actor_id, request_id)
2551
+ const insert = this.db.prepare(`INSERT INTO changes (space_id, user_id, entity_type, entity_id, task_id, at, actor_type, actor_id, request_id)
2415
2552
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`);
2416
2553
  const actorId = this.actingUserId;
2417
2554
  const requestId = this.request?.id ?? null;
@@ -2422,7 +2559,7 @@ export class Mutation {
2422
2559
  }
2423
2560
  /** Réglages d'une vue avec des filtres sans doublon, dans l'ordre des statuts et des priorités. */
2424
2561
  function normalizedSettings(settings) {
2425
- const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities } = settings;
2562
+ const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned } = settings;
2426
2563
  return {
2427
2564
  name,
2428
2565
  layout,
@@ -2431,6 +2568,8 @@ function normalizedSettings(settings) {
2431
2568
  showEmptyGroups,
2432
2569
  statuses: TASK_STATUSES.filter((status) => statuses.includes(status)),
2433
2570
  priorities: TASK_PRIORITIES.filter((priority) => priorities.includes(priority)),
2571
+ assigneeIds: [...new Set(assigneeIds)],
2572
+ unassigned,
2434
2573
  };
2435
2574
  }
2436
2575
  /** Champs de `patch` dont la valeur n'est pas `undefined`. */