@imenam/mcp-organizer 1.0.11 → 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 (50) hide show
  1. package/README.md +728 -714
  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 +32 -2
  9. package/dist/shared/schemas/entities.schema.js +27 -3
  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 +82 -0
  15. package/dist/shared/schemas/tasks-api.schema.js +35 -0
  16. package/dist/src/agent-api/requests.d.ts +1 -1
  17. package/dist/src/agent-api/requests.js +56 -4
  18. package/dist/src/agent-api/router.js +2 -1
  19. package/dist/src/agent-api/views.d.ts +2 -0
  20. package/dist/src/agent-api/views.js +203 -0
  21. package/dist/src/core/agent.d.ts +5 -1
  22. package/dist/src/core/agent.js +61 -2
  23. package/dist/src/core/board-views.d.ts +11 -1
  24. package/dist/src/core/board-views.js +28 -11
  25. package/dist/src/core/follow-ups.d.ts +7 -0
  26. package/dist/src/core/follow-ups.js +15 -0
  27. package/dist/src/core/history.d.ts +2 -1
  28. package/dist/src/core/history.js +62 -3
  29. package/dist/src/core/migrations.js +479 -424
  30. package/dist/src/core/notifications.js +36 -9
  31. package/dist/src/core/requests.d.ts +10 -1
  32. package/dist/src/core/requests.js +41 -3
  33. package/dist/src/core/snapshots.d.ts +4 -4
  34. package/dist/src/core/snapshots.js +6 -2
  35. package/dist/src/core/spaces.d.ts +2 -2
  36. package/dist/src/core/spaces.js +12 -6
  37. package/dist/src/core/store.d.ts +43 -6
  38. package/dist/src/core/store.js +202 -71
  39. package/dist/src/core/tasks.d.ts +21 -1
  40. package/dist/src/core/tasks.js +100 -10
  41. package/dist/src/gui-api.js +14 -4
  42. package/dist/src/mcp/start.d.ts +1 -1
  43. package/dist/src/mcp/start.js +4 -3
  44. package/dist/src/mcp/tools.js +86 -2
  45. package/dist/src/server/runner.js +4 -18
  46. package/gui/dist/assets/{index-BLhlceSY.css → index-CVwckTU6.css} +1 -1
  47. package/gui/dist/assets/index-G5uiHeLf.js +99 -0
  48. package/gui/dist/index.html +2 -2
  49. package/package.json +1 -1
  50. package/gui/dist/assets/index-Em4IQgbR.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
  }
@@ -195,8 +199,9 @@ function requestFromRow(row) {
195
199
  text: row.text,
196
200
  status: row.status,
197
201
  reply: row.reply,
198
- followUps: JSON.parse(row.follow_ups),
199
202
  failureReason: row.failure_reason,
203
+ parentRequestId: row.parent_request_id,
204
+ commentId: row.comment_id,
200
205
  createdAt: row.created_at,
201
206
  updatedAt: row.updated_at,
202
207
  claimedAt: row.claimed_at,
@@ -207,6 +212,17 @@ function requestFromRow(row) {
207
212
  stoppedBy: row.stopped_by,
208
213
  });
209
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
+ }
210
226
  function versionFromRow(row) {
211
227
  const raw = row.snapshot === null ? null : JSON.parse(row.snapshot);
212
228
  const snapshot = raw === null ? null : row.entity_type === "task" ? TaskSnapshotSchema.parse(raw) : IdeaSnapshotSchema.parse(raw);
@@ -230,6 +246,7 @@ function changeFromRow(row) {
230
246
  entityType: row.entity_type,
231
247
  entityId: row.entity_id,
232
248
  taskId: row.task_id,
249
+ actorType: row.actor_type ?? null,
233
250
  at: row.at,
234
251
  });
235
252
  }
@@ -248,6 +265,7 @@ function commentFromRow(row) {
248
265
  createdAt: row.created_at,
249
266
  editedAt: row.edited_at,
250
267
  requestId: row.request_id,
268
+ replyToCommentId: row.reply_to_comment_id,
251
269
  });
252
270
  }
253
271
  function agentActionFromRow(row) {
@@ -318,6 +336,10 @@ function notificationFromRow(row) {
318
336
  emailError: row.email_error,
319
337
  });
320
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`;
321
343
  /** Libellé d'une tâche dans les messages : `ORG-41`. */
322
344
  function taskLabel(db, task) {
323
345
  return `${keyPrefixOf(db, task.spaceId)}-${task.number}`;
@@ -490,7 +512,7 @@ export class Store {
490
512
  /** Espaces dont l'utilisateur est membre : son espace personnel d'abord, puis les espaces communs par nom. */
491
513
  listSpacesOf(userId) {
492
514
  const rows = this.db
493
- .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
494
516
  WHERE m.user_id = ? ORDER BY s.kind = 'shared', s.name COLLATE NOCASE`)
495
517
  .all(userId);
496
518
  return rows.map(spaceFromRow);
@@ -540,6 +562,23 @@ export class Store {
540
562
  const rows = this.db.prepare("SELECT user_id FROM task_assignees WHERE task_id = ? ORDER BY user_id").all(taskId);
541
563
  return rows.map((row) => row.user_id);
542
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
+ }
543
582
  listTagIds(taskId) {
544
583
  const rows = this.db.prepare("SELECT tag_id FROM task_tags WHERE task_id = ? ORDER BY tag_id").all(taskId);
545
584
  return rows.map((row) => row.tag_id);
@@ -645,7 +684,7 @@ export class Store {
645
684
  /** Résultats saisis sur les points des tâches d'un espace. */
646
685
  listTestResultsInSpace(spaceId) {
647
686
  const rows = this.db
648
- .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
649
688
  JOIN test_checkpoints c ON c.id = r.checkpoint_id JOIN tasks t ON t.id = c.task_id WHERE t.space_id = ?`)
650
689
  .all(spaceId);
651
690
  return rows.map((row) => ({
@@ -690,7 +729,7 @@ export class Store {
690
729
  /** Pièces jointes d'une tâche et de toutes ses sous-tâches. */
691
730
  listAttachmentsInSubtree(taskId) {
692
731
  const rows = this.db
693
- .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)
694
733
  SELECT a.* FROM attachments a JOIN subtree s ON a.task_id = s.id`)
695
734
  .all(taskId);
696
735
  return rows.map(attachmentFromRow);
@@ -720,7 +759,7 @@ export class Store {
720
759
  /** Demandes de promotion (`idea_promotion`) en attente ou en cours sur les idées d'un espace. */
721
760
  listOpenPromotionRequests(spaceId) {
722
761
  const rows = this.db
723
- .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
724
763
  WHERE i.space_id = ? AND r.kind = 'idea_promotion' AND r.status IN ('pending', 'processing') ORDER BY r.created_at, r.id`)
725
764
  .all(spaceId);
726
765
  return rows.map(requestFromRow);
@@ -777,9 +816,9 @@ export class Store {
777
816
  if (limit === 0)
778
817
  return [];
779
818
  const rows = this.db
780
- .prepare(`SELECT * FROM agent_requests
781
- WHERE target_space_id = @spaceId AND author_id = @authorId AND status IN ('done', 'failed')
782
- 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))
783
822
  ORDER BY created_at DESC, id DESC LIMIT @limit`)
784
823
  .all({ spaceId, authorId, createdAt: before.createdAt, id: before.id, limit });
785
824
  return rows.map(requestFromRow).reverse();
@@ -791,6 +830,31 @@ export class Store {
791
830
  .all({ spaceId, limit });
792
831
  return rows.map(requestFromRow);
793
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
+ }
794
858
  /** Nombre de demandes en attente d'un espace. */
795
859
  countPendingRequestsOfSpace(spaceId) {
796
860
  const row = this.db.prepare("SELECT COUNT(*) AS n FROM agent_requests WHERE status = 'pending' AND target_space_id = ?").get(spaceId);
@@ -841,14 +905,13 @@ export class Store {
841
905
  }
842
906
  /**
843
907
  * Notifications affichées dans l'application d'un utilisateur, sur les
844
- * tâches des espaces dont il est encore membre : non lues d'abord, puis de
845
- * 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.
846
910
  */
847
911
  listNotifications(userId, limit, offset) {
848
912
  const rows = this.db
849
- .prepare(`SELECT n.* FROM notifications n JOIN tasks t ON t.id = n.task_id
850
- JOIN memberships m ON m.space_id = t.space_id AND m.user_id = n.user_id
851
- 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
852
915
  ORDER BY n.read_at IS NOT NULL, n.created_at DESC, n.id DESC LIMIT ? OFFSET ?`)
853
916
  .all(userId, limit, offset);
854
917
  return rows.map(notificationFromRow);
@@ -856,8 +919,7 @@ export class Store {
856
919
  /** Nombre de notifications non lues affichées dans l'application d'un utilisateur. */
857
920
  countUnreadNotifications(userId) {
858
921
  const row = this.db
859
- .prepare(`SELECT COUNT(*) AS n FROM notifications n JOIN tasks t ON t.id = n.task_id
860
- 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}
861
923
  WHERE n.user_id = ? AND n.in_app = 1 AND n.read_at IS NULL`)
862
924
  .get(userId);
863
925
  return row.n;
@@ -886,8 +948,8 @@ export class Store {
886
948
  */
887
949
  listChangesForUser(userId, since, limit) {
888
950
  const rows = this.db
889
- .prepare(`SELECT * FROM changes WHERE seq > ?
890
- 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 = ?))
891
953
  ORDER BY seq LIMIT ?`)
892
954
  .all(since, userId, userId, limit);
893
955
  return rows.map(changeFromRow);
@@ -1049,13 +1111,13 @@ export class Mutation {
1049
1111
  }
1050
1112
  this.agentWriteChecked = true;
1051
1113
  }
1052
- touch(entityType, entityId, spaceId, userId, taskId = null) {
1114
+ touch(entityType, entityId, spaceId, userId, taskId = null, scopeSpaceId = spaceId) {
1053
1115
  if (entityType !== "agent_request")
1054
1116
  this.assertAgentMayWrite();
1055
1117
  const key = `${entityType}:${entityId}`;
1056
1118
  const concernedTask = entityType === "task" ? entityId : taskId;
1057
1119
  if (!this.touched.has(key))
1058
- this.touched.set(key, { entityType, entityId, spaceId, userId, taskId: concernedTask });
1120
+ this.touched.set(key, { entityType, entityId, spaceId, userId, taskId: concernedTask, scopeSpaceId });
1059
1121
  }
1060
1122
  // --- Utilisateurs ---
1061
1123
  createUser(input) {
@@ -1169,7 +1231,7 @@ export class Mutation {
1169
1231
  if (!this.store.isMember(token.spaceId, token.userId))
1170
1232
  throw new ForbiddenError("An agent token can only cover a space its owner is a member of.");
1171
1233
  this.db
1172
- .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)
1173
1235
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1174
1236
  .run(token.id, token.userId, token.spaceId, token.name, token.prefix, token.tokenHash, token.createdAt, token.expiresAt, token.isRunner ? 1 : 0);
1175
1237
  this.touch("agent_token", token.id, null, token.userId);
@@ -1305,7 +1367,7 @@ export class Mutation {
1305
1367
  this.touch("membership", `${id}:${membership.userId}`, id, membership.userId);
1306
1368
  }
1307
1369
  this.db
1308
- .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 = ?))
1309
1371
  OR (entity_type = 'idea' AND entity_id IN (SELECT id FROM ideas WHERE space_id = ?))`)
1310
1372
  .run(id, id);
1311
1373
  this.db.prepare("DELETE FROM spaces WHERE id = ?").run(id);
@@ -1326,10 +1388,17 @@ export class Mutation {
1326
1388
  this.touch("membership", `${spaceId}:${userId}`, spaceId, userId);
1327
1389
  return { ...membership, role };
1328
1390
  }
1329
- /** Retire un membre d'un espace, le retire du filtre des assignés des vues de l'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
+ */
1330
1396
  removeMember(spaceId, userId) {
1331
1397
  if (!this.store.findMembership(spaceId, userId))
1332
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
+ }
1333
1402
  this.db.prepare("DELETE FROM memberships WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
1334
1403
  this.db.prepare("DELETE FROM space_notification_settings WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
1335
1404
  this.db.prepare("DELETE FROM board_views WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
@@ -1374,8 +1443,8 @@ export class Mutation {
1374
1443
  version: 1,
1375
1444
  }, "task");
1376
1445
  this.db
1377
- .prepare(`INSERT INTO tasks (id, space_id, number, parent_id, depth, type, title, description, status, priority, position,
1378
- 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)
1379
1448
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1380
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);
1381
1450
  this.db.prepare("UPDATE spaces SET next_task_number = next_task_number + 1 WHERE id = ?").run(space.id);
@@ -1409,7 +1478,7 @@ export class Mutation {
1409
1478
  const testedTaskId = fields.testedTaskId !== undefined ? fields.testedTaskId : type === "standard" ? null : current.testedTaskId;
1410
1479
  const task = validate(TaskSchema, { ...current, ...fields, parentId, depth, status, position, testedTaskId, updatedAt: this.now }, "task");
1411
1480
  this.db
1412
- .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 = ?,
1413
1482
  position = ?, tested_task_id = ?, updated_at = ? WHERE id = ?`)
1414
1483
  .run(task.parentId, task.depth, task.type, task.title, task.description, task.status, task.priority, task.position, task.testedTaskId, task.updatedAt, id);
1415
1484
  this.touch("task", id, task.spaceId, null);
@@ -1668,7 +1737,7 @@ export class Mutation {
1668
1737
  updatedAt: this.now,
1669
1738
  }, "test result");
1670
1739
  this.db
1671
- .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 (?, ?, ?, ?, ?)
1672
1741
  ON CONFLICT (checkpoint_id, tester_id) DO UPDATE SET result = excluded.result, comment = excluded.comment, updated_at = excluded.updated_at`)
1673
1742
  .run(result.checkpointId, result.testerId, result.result, result.comment, result.updatedAt);
1674
1743
  this.touch("test_result", `${checkpointId}:${testerId}`, task.spaceId, null, task.id);
@@ -1710,13 +1779,13 @@ export class Mutation {
1710
1779
  return { review: { ...draft, submittedAt: this.now, requestId: request.id }, request };
1711
1780
  }
1712
1781
  // --- Commentaires ---
1713
- /** Commentaire de l'utilisateur acteur sur une tâche. */
1714
- 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) {
1715
1784
  const task = this.store.getTask(taskId);
1716
- 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");
1717
1786
  this.db
1718
- .prepare("INSERT INTO comments (id, task_id, author_id, body, created_at, edited_at, request_id) VALUES (?, ?, ?, ?, ?, ?, ?)")
1719
- .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);
1720
1789
  this.touch("comment", comment.id, task.spaceId, null, taskId);
1721
1790
  const commenters = this.store.listComments(taskId).filter((other) => other.id !== comment.id).map((other) => other.authorId);
1722
1791
  const recipients = [...new Set([...this.store.listAssigneeIds(taskId), ...commenters])].sort();
@@ -1831,7 +1900,7 @@ export class Mutation {
1831
1900
  createdAt: this.now,
1832
1901
  }, "idea");
1833
1902
  this.db
1834
- .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)
1835
1904
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1836
1905
  .run(idea.id, idea.spaceId, idea.authorId, idea.text, idea.origin, idea.requestId, idea.promotedTaskId, idea.archivedAt, idea.createdAt);
1837
1906
  this.touch("idea", idea.id, idea.spaceId, null);
@@ -1878,27 +1947,38 @@ export class Mutation {
1878
1947
  createdAt: this.now,
1879
1948
  updatedAt: this.now,
1880
1949
  }, "board view");
1950
+ this.insertBoardView(view);
1951
+ return view;
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) {
1881
1962
  this.db
1882
- .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)
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)
1883
1964
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1884
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);
1885
- this.touch("board_view", view.id, null, userId);
1886
- return view;
1966
+ this.touch("board_view", view.id, null, view.userId, null, view.spaceId);
1887
1967
  }
1888
1968
  updateBoardView(id, patch) {
1889
1969
  const current = this.store.getBoardView(id);
1890
1970
  const view = validate(BoardViewSchema, { ...current, ...normalizedSettings({ ...current, ...definedFields(patch) }), updatedAt: this.now }, "board view");
1891
1971
  this.db
1892
- .prepare(`UPDATE board_views SET name = ?, layout = ?, group_by = ?, then_by = ?, show_empty_groups = ?, statuses = ?, priorities = ?, assignee_ids = ?, unassigned = ?, updated_at = ?
1972
+ .prepare(`UPDATE board_views SET name = ?, layout = ?, group_by = ?, then_by = ?, show_empty_groups = ?, statuses = ?, priorities = ?, assignee_ids = ?, unassigned = ?, updated_at = ?
1893
1973
  WHERE id = ?`)
1894
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);
1895
- this.touch("board_view", id, null, view.userId);
1975
+ this.touch("board_view", id, null, view.userId, null, view.spaceId);
1896
1976
  return view;
1897
1977
  }
1898
1978
  deleteBoardView(id) {
1899
1979
  const view = this.store.getBoardView(id);
1900
1980
  this.db.prepare("DELETE FROM board_views WHERE id = ?").run(id);
1901
- this.touch("board_view", id, null, view.userId);
1981
+ this.touch("board_view", id, null, view.userId, null, view.spaceId);
1902
1982
  }
1903
1983
  // --- Demandes ---
1904
1984
  /** Dépose une demande `pending` de l'utilisateur acteur. */
@@ -1915,8 +1995,9 @@ export class Mutation {
1915
1995
  text: input.text,
1916
1996
  status: "pending",
1917
1997
  reply: null,
1918
- followUps: [],
1919
1998
  failureReason: null,
1999
+ parentRequestId: input.parentRequestId ?? null,
2000
+ commentId: input.commentId ?? null,
1920
2001
  createdAt: this.now,
1921
2002
  updatedAt: this.now,
1922
2003
  claimedAt: null,
@@ -1928,10 +2009,10 @@ export class Mutation {
1928
2009
  }, "request");
1929
2010
  this.store.getSpace(request.targetSpaceId);
1930
2011
  this.db
1931
- .prepare(`INSERT INTO agent_requests (id, author_id, target_space_id, kind, context_task_id, context_idea_id,
1932
- text, status, created_at, updated_at)
1933
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
1934
- .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);
1935
2016
  this.createdRequestIds.add(request.id);
1936
2017
  this.pendingRequestIds.push(request.id);
1937
2018
  this.touchRequest(request);
@@ -1997,9 +2078,10 @@ export class Mutation {
1997
2078
  if (current.status !== "failed" || current.stoppedAt === null)
1998
2079
  throw new InvariantError(`Request ${id} is ${current.status}: only a stopped request can be relaunched.`);
1999
2080
  this.db
2000
- .prepare(`UPDATE agent_requests SET status = 'pending', claimed_at = NULL, claimed_by_token_id = NULL, completed_at = NULL, failure_reason = NULL,
2001
- 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 = ?`)
2002
2083
  .run(this.now, id);
2084
+ this.db.prepare("DELETE FROM follow_ups WHERE request_id = ?").run(id);
2003
2085
  const relaunched = this.store.getAgentRequest(id);
2004
2086
  this.pendingRequestIds.push(id);
2005
2087
  this.touchRequest(relaunched);
@@ -2062,12 +2144,51 @@ export class Mutation {
2062
2144
  const column = status === "done" ? "reply" : "failure_reason";
2063
2145
  const points = followUps.map((point) => point.trim()).filter((point) => point !== "");
2064
2146
  this.db
2065
- .prepare(`UPDATE agent_requests SET status = ?, ${column} = ?, follow_ups = ?, completed_at = ?, updated_at = ? WHERE id = ?`)
2066
- .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));
2067
2151
  const finished = this.store.getAgentRequest(request.id);
2068
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);
2069
2158
  return finished;
2070
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
+ }
2071
2192
  // --- Actions de l'agent ---
2072
2193
  /** Enregistre une action de l'agent dans le lot de sa demande, avec le rang suivant. */
2073
2194
  recordAgentAction(input) {
@@ -2089,7 +2210,7 @@ export class Mutation {
2089
2210
  tokenId: token.id,
2090
2211
  }, "agent action");
2091
2212
  this.db
2092
- .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)
2093
2214
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2094
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);
2095
2216
  this.touch("agent_action", action.id, request.targetSpaceId, null, input.taskId);
@@ -2119,11 +2240,19 @@ export class Mutation {
2119
2240
  * deux sont désactivés.
2120
2241
  */
2121
2242
  notify(type, userId, taskId, commentId) {
2122
- const settings = this.store.notificationPreferences(userId, this.store.getTask(taskId).spaceId);
2123
- const inApp = type === "assigned" ? settings.notifyAssignApp : settings.notifyCommentApp;
2124
- 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];
2125
2253
  if (!inApp && !email)
2126
2254
  return;
2255
+ const { taskId, requestId, commentId } = about;
2127
2256
  const notification = validate(NotificationSchema, {
2128
2257
  id: newId(),
2129
2258
  userId,
@@ -2131,7 +2260,7 @@ export class Mutation {
2131
2260
  taskId,
2132
2261
  actorType: this.actor.type,
2133
2262
  actorId: this.actor.type === "user" ? this.actor.userId : null,
2134
- requestId: this.request?.id ?? null,
2263
+ requestId,
2135
2264
  commentId,
2136
2265
  inApp,
2137
2266
  createdAt: this.now,
@@ -2140,7 +2269,7 @@ export class Mutation {
2140
2269
  emailError: null,
2141
2270
  }, "notification");
2142
2271
  this.db
2143
- .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)
2144
2273
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2145
2274
  .run(notification.id, notification.userId, notification.type, notification.taskId, notification.actorType, notification.actorId, notification.requestId, notification.commentId, inApp ? 1 : 0, notification.createdAt);
2146
2275
  if (inApp)
@@ -2182,9 +2311,9 @@ export class Mutation {
2182
2311
  updateUserSettings(userId, patch) {
2183
2312
  const settings = validate(UserSettingsSchema, { ...this.store.getUserSettings(userId), ...definedFields(patch) }, "settings");
2184
2313
  this.db
2185
- .prepare(`UPDATE user_settings SET notify_assign_app = ?, notify_assign_email = ?, notify_comment_app = ?, notify_comment_email = ?,
2186
- assistant_history = ? WHERE user_id = ?`)
2187
- .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);
2188
2317
  this.touch("user_settings", userId, null, userId);
2189
2318
  return settings;
2190
2319
  }
@@ -2202,11 +2331,13 @@ export class Mutation {
2202
2331
  }
2203
2332
  const settings = validate(SpaceNotificationSettingsSchema, { userId, spaceId, ...preferences }, "space notification settings");
2204
2333
  this.db
2205
- .prepare(`INSERT INTO space_notification_settings (user_id, space_id, notify_assign_app, notify_assign_email, notify_comment_app, notify_comment_email)
2206
- VALUES (?, ?, ?, ?, ?, ?)
2207
- ON CONFLICT (user_id, space_id) DO UPDATE SET notify_assign_app = excluded.notify_assign_app, notify_assign_email = excluded.notify_assign_email,
2208
- notify_comment_app = excluded.notify_comment_app, notify_comment_email = excluded.notify_comment_email`)
2209
- .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);
2210
2341
  return settings;
2211
2342
  }
2212
2343
  /**
@@ -2242,7 +2373,7 @@ export class Mutation {
2242
2373
  recordRunnerSession(record) {
2243
2374
  const valid = validate(RunnerSessionRecordSchema, record, "runner session");
2244
2375
  this.db
2245
- .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)
2246
2377
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2247
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);
2248
2379
  }
@@ -2291,7 +2422,7 @@ export class Mutation {
2291
2422
  continue;
2292
2423
  if (entry.entityType === "agent_request" && entry.entityId === request.id)
2293
2424
  continue;
2294
- if (entry.spaceId !== request.targetSpaceId) {
2425
+ if (entry.scopeSpaceId !== request.targetSpaceId) {
2295
2426
  throw new InvariantError(`Request ${request.id} targets space ${request.targetSpaceId}; the agent cannot modify ${entry.entityType} ${entry.entityId} outside of it.`);
2296
2427
  }
2297
2428
  }
@@ -2322,8 +2453,8 @@ export class Mutation {
2322
2453
  }
2323
2454
  }
2324
2455
  const outsiders = this.db
2325
- .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
2326
- 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)
2327
2458
  ORDER BY t.number LIMIT 1`)
2328
2459
  .get(space.id);
2329
2460
  if (outsiders) {
@@ -2395,7 +2526,7 @@ export class Mutation {
2395
2526
  const actorId = this.actingUserId;
2396
2527
  const requestId = this.request?.id ?? null;
2397
2528
  const tokenId = this.token?.id ?? null;
2398
- 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)
2399
2530
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`);
2400
2531
  for (const entry of this.touched.values()) {
2401
2532
  if (!VERSIONED.has(entry.entityType))
@@ -2417,7 +2548,7 @@ export class Mutation {
2417
2548
  }
2418
2549
  /** Une ligne du journal par entité modifiée, avec l'auteur de la mutation. */
2419
2550
  writeChanges() {
2420
- 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)
2421
2552
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`);
2422
2553
  const actorId = this.actingUserId;
2423
2554
  const requestId = this.request?.id ?? null;