@imenam/mcp-organizer 1.0.38 → 1.0.40

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 (35) hide show
  1. package/README.md +6 -5
  2. package/dist/shared/logic/checkboxes.d.ts +32 -0
  3. package/dist/shared/logic/checkboxes.js +58 -0
  4. package/dist/shared/schemas/agent-tools.schema.d.ts +21 -0
  5. package/dist/shared/schemas/agent-tools.schema.js +12 -2
  6. package/dist/shared/schemas/entities.schema.d.ts +2 -2
  7. package/dist/shared/schemas/entities.schema.js +2 -2
  8. package/dist/shared/schemas/tasks-api.schema.d.ts +12 -2
  9. package/dist/shared/schemas/tasks-api.schema.js +13 -5
  10. package/dist/src/agent-api/checklist.d.ts +5 -1
  11. package/dist/src/agent-api/checklist.js +17 -13
  12. package/dist/src/agent-api/questions.js +4 -2
  13. package/dist/src/agent-api/tasks.js +6 -11
  14. package/dist/src/core/agent.d.ts +2 -0
  15. package/dist/src/core/agent.js +8 -2
  16. package/dist/src/core/history.d.ts +14 -1
  17. package/dist/src/core/history.js +123 -1
  18. package/dist/src/core/notes.d.ts +3 -0
  19. package/dist/src/core/notes.js +13 -1
  20. package/dist/src/core/requests.d.ts +14 -4
  21. package/dist/src/core/requests.js +43 -18
  22. package/dist/src/core/store.d.ts +21 -9
  23. package/dist/src/core/store.js +83 -28
  24. package/dist/src/core/tasks.d.ts +5 -0
  25. package/dist/src/core/tasks.js +25 -2
  26. package/dist/src/core/test-tasks.js +7 -14
  27. package/dist/src/gui-api.js +17 -6
  28. package/dist/src/mcp/start.d.ts +1 -1
  29. package/dist/src/mcp/start.js +6 -5
  30. package/dist/src/mcp/tools.js +15 -10
  31. package/gui/dist/assets/{index-CB0X_FZW.css → index-CAbA-qhx.css} +1 -1
  32. package/gui/dist/assets/index-Da_vH9jg.js +144 -0
  33. package/gui/dist/index.html +2 -2
  34. package/package.json +1 -1
  35. package/gui/dist/assets/index-xC5hAFk-.js +0 -122
@@ -3,7 +3,8 @@ import { type AgentAction, type TaskSnapshot } from "../../shared/schemas/entiti
3
3
  /**
4
4
  * Retour à un état antérieur : annulation d'une action de l'agent, après
5
5
  * comparaison de l'état courant de l'entité avec celui que l'action a
6
- * laissé, et restauration des champs d'une version de tâche.
6
+ * laissé, rétablissement d'une action annulée, après comparaison avec l'état
7
+ * que l'annulation a laissé, et restauration des champs d'une version de tâche.
7
8
  */
8
9
  /** Champs d'une tâche comparés et restaurés par l'historique. */
9
10
  declare const TASK_FIELDS: readonly ["title", "description", "status", "priority", "type", "parentId", "testedTaskId"];
@@ -17,6 +18,18 @@ declare const TASK_FIELDS: readonly ["title", "description", "status", "priority
17
18
  * efface une fois la mutation validée ; null sinon.
18
19
  */
19
20
  export declare function undoAgentAction(tx: Mutation, action: AgentAction): string | null;
21
+ /**
22
+ * Rétablit une action de l'agent annulée, dans la mutation `tx` (acteur
23
+ * utilisateur) : refait à l'identique ce que l'action avait fait. L'état
24
+ * courant de l'entité doit être celui que l'annulation a laissé ; sinon le
25
+ * refus nomme l'auteur de la modification. Ce que l'annulation a supprimé
26
+ * est recréé avec ses identifiants (une pièce jointe seulement si son
27
+ * fichier existe encore, selon `hasFile`), ce qu'elle a recréé est supprimé,
28
+ * ce qu'elle a ramené à l'état d'avant reprend l'état laissé par l'action.
29
+ * Renvoie le chemin du fichier d'une pièce jointe supprimée, que l'appelant
30
+ * efface une fois la mutation validée ; null sinon.
31
+ */
32
+ export declare function redoAgentAction(tx: Mutation, action: AgentAction, hasFile: (storagePath: string) => boolean): string | null;
20
33
  /** Libellés français des champs restaurables d'une tâche ; « position » est le rang dans une même colonne. */
21
34
  export declare const TASK_FIELD_LABELS: Record<(typeof TASK_FIELDS)[number] | "position" | "assigneeIds" | "tagIds", string>;
22
35
  /**
@@ -4,7 +4,8 @@ import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotS
4
4
  /**
5
5
  * Retour à un état antérieur : annulation d'une action de l'agent, après
6
6
  * comparaison de l'état courant de l'entité avec celui que l'action a
7
- * laissé, et restauration des champs d'une version de tâche.
7
+ * laissé, rétablissement d'une action annulée, après comparaison avec l'état
8
+ * que l'annulation a laissé, et restauration des champs d'une version de tâche.
8
9
  */
9
10
  /** Champs d'une tâche comparés et restaurés par l'historique. */
10
11
  const TASK_FIELDS = ["title", "description", "status", "priority", "type", "parentId", "testedTaskId"];
@@ -161,6 +162,127 @@ export function undoAgentAction(tx, action) {
161
162
  tx.markAgentActionUndone(action.id, taskIdOfAction(action));
162
163
  return removedFile;
163
164
  }
165
+ /**
166
+ * Rétablit une action de l'agent annulée, dans la mutation `tx` (acteur
167
+ * utilisateur) : refait à l'identique ce que l'action avait fait. L'état
168
+ * courant de l'entité doit être celui que l'annulation a laissé ; sinon le
169
+ * refus nomme l'auteur de la modification. Ce que l'annulation a supprimé
170
+ * est recréé avec ses identifiants (une pièce jointe seulement si son
171
+ * fichier existe encore, selon `hasFile`), ce qu'elle a recréé est supprimé,
172
+ * ce qu'elle a ramené à l'état d'avant reprend l'état laissé par l'action.
173
+ * Renvoie le chemin du fichier d'une pièce jointe supprimée, que l'appelant
174
+ * efface une fois la mutation validée ; null sinon.
175
+ */
176
+ export function redoAgentAction(tx, action, hasFile) {
177
+ if (action.undoneAt === null)
178
+ throw new InvariantError("Cette action n'est pas annulée.");
179
+ if (!isTracked(action.entityType))
180
+ throw new InvariantError(`Une action sur ${action.entityType} ne se rétablit pas.`);
181
+ const entityType = action.entityType;
182
+ const store = tx.store;
183
+ if (entityType === "board_view")
184
+ requireViewOwner(tx, BoardViewSchema.parse(action.after ?? action.before));
185
+ if (entityType === "time_session")
186
+ requireTimerOwner(tx, TimeSessionSchema.parse(action.after ?? action.before));
187
+ const current = snapshotOf(store, entityType, action.entityId);
188
+ let removedFile = null;
189
+ if (action.before === null) {
190
+ const { label } = describe(store, entityType, action.after);
191
+ if (current !== null)
192
+ throw new InvariantError(`${label} existe de nouveau : rien à rétablir.`);
193
+ recreateCreated(tx, entityType, action.after, label, hasFile);
194
+ }
195
+ else {
196
+ const { label, feminine } = describe(store, entityType, current ?? action.before);
197
+ const agreement = feminine ? "e" : "";
198
+ if (current === null) {
199
+ throw new InvariantError(`${label} a été supprimé${agreement} depuis par ${lastModifier(store, entityType, action.entityId, action)} : rétablissement impossible.`);
200
+ }
201
+ if (!sameState(entityType, current, action.before, action.after)) {
202
+ throw new InvariantError(`${label} a été modifié${agreement} depuis par ${lastModifier(store, entityType, action.entityId, action)} : le rétablissement écraserait cette modification.`);
203
+ }
204
+ if (action.after === null)
205
+ removedFile = remove(tx, entityType, current, label);
206
+ else
207
+ restore(tx, entityType, action.entityId, action.after);
208
+ }
209
+ tx.markAgentActionRedone(action.id, taskIdOfAction(action));
210
+ return removedFile;
211
+ }
212
+ /** Recrée, avec ses identifiants, une entité que l'agent avait créée et que l'annulation a supprimée. */
213
+ function recreateCreated(tx, entityType, after, label, hasFile) {
214
+ const store = tx.store;
215
+ const requireTask = (taskId) => {
216
+ if (!store.findTask(taskId))
217
+ throw new InvariantError(`${label} appartenait à une tâche qui n'existe plus : rétablissement impossible.`);
218
+ };
219
+ switch (entityType) {
220
+ case "task": {
221
+ const task = TaskSnapshotSchema.parse(after);
222
+ if (task.parentId !== null && !store.findTask(task.parentId))
223
+ throw new InvariantError(`La tâche parente de ${label.toLowerCase()} n'existe plus : rétablissement impossible.`);
224
+ tx.restoreTask(task);
225
+ const assignees = task.assigneeIds.filter((userId) => store.isMember(task.spaceId, userId));
226
+ if (assignees.length > 0)
227
+ tx.setAssignees(task.id, assignees, false);
228
+ const tags = task.tagIds.flatMap((tagId) => store.findTag(tagId)?.name ?? []);
229
+ if (tags.length > 0)
230
+ tx.setTags(task.id, tags);
231
+ return;
232
+ }
233
+ case "checklist_item": {
234
+ const item = ChecklistItemSchema.parse(after);
235
+ requireTask(item.taskId);
236
+ tx.restoreChecklistItem(item);
237
+ return;
238
+ }
239
+ case "task_question": {
240
+ const question = QuestionSnapshotSchema.parse(after);
241
+ requireTask(question.taskId);
242
+ tx.restoreQuestion(question);
243
+ return;
244
+ }
245
+ case "test_checkpoint": {
246
+ const { results, ...fields } = CheckpointSnapshotSchema.parse(after);
247
+ requireTask(fields.taskId);
248
+ tx.restoreCheckpoint(fields, results);
249
+ return;
250
+ }
251
+ case "comment": {
252
+ const comment = CommentSchema.parse(after);
253
+ requireTask(comment.taskId);
254
+ tx.restoreComment(comment);
255
+ return;
256
+ }
257
+ case "attachment": {
258
+ const attachment = AttachmentSchema.parse(after);
259
+ requireTask(attachment.taskId);
260
+ if (!hasFile(attachment.storagePath))
261
+ throw new InvariantError(`Le fichier de ${label.toLowerCase()} a été effacé : rétablissement impossible.`);
262
+ tx.restoreAttachment(attachment);
263
+ return;
264
+ }
265
+ case "idea":
266
+ tx.restoreIdea(IdeaSchema.parse(after));
267
+ return;
268
+ case "board_view": {
269
+ const view = BoardViewSchema.parse(after);
270
+ if (!store.isMember(view.spaceId, view.userId))
271
+ throw new InvariantError(`Le propriétaire de la vue « ${view.name} » n'est plus membre de l'espace : rétablissement impossible.`);
272
+ requireViewAssignees(tx, view);
273
+ tx.restoreBoardView(view);
274
+ return;
275
+ }
276
+ case "time_session": {
277
+ const session = TimeSessionSchema.parse(after);
278
+ requireTask(session.taskId);
279
+ tx.restoreTimeSession(session);
280
+ return;
281
+ }
282
+ case "follow_up":
283
+ throw new InvariantError(`${label} ne se recrée pas : rétablissement impossible.`);
284
+ }
285
+ }
164
286
  /** Seul le membre à qui appartient une vue annule les changements que l'agent y a faits. */
165
287
  function requireViewOwner(tx, view) {
166
288
  if (tx.actor.type === "user" && tx.actor.userId === view.userId)
@@ -1,3 +1,4 @@
1
+ import { type CheckboxTarget } from "../../shared/logic/checkboxes.js";
1
2
  import type { Store } from "./store.js";
2
3
  import type { CreateNoteRequest, NoteListResponse, NoteView, SendNoteResponse, UpdateNoteRequest } from "../../shared/schemas/notes-api.schema.js";
3
4
  /**
@@ -14,6 +15,8 @@ export declare function listNotes(store: Store, userId: string, spaceId: string)
14
15
  export declare function getNote(store: Store, userId: string, noteId: string): NoteView;
15
16
  export declare function createNote(store: Store, userId: string, spaceId: string, input: CreateNoteRequest): NoteView;
16
17
  export declare function updateNote(store: Store, userId: string, noteId: string, patch: UpdateNoteRequest): NoteView;
18
+ /** Coche ou décoche une case du contenu d'une note. */
19
+ export declare function toggleNoteCheckbox(store: Store, userId: string, noteId: string, target: CheckboxTarget): NoteView;
17
20
  export declare function deleteNote(store: Store, userId: string, noteId: string): void;
18
21
  /**
19
22
  * Confie une note à l'agent : un message dans la file de l'espace de la note,
@@ -1,4 +1,5 @@
1
- import { NotFoundError } from "./errors.js";
1
+ import { InvariantError, NotFoundError } from "./errors.js";
2
+ import { CHECKBOX_CONFLICT, toggleCheckbox } from "../../shared/logic/checkboxes.js";
2
3
  import { requireMember } from "./spaces.js";
3
4
  import { noteLinkMarkdown } from "../../shared/logic/notes.js";
4
5
  /**
@@ -57,6 +58,17 @@ export function updateNote(store, userId, noteId, patch) {
57
58
  });
58
59
  return noteView(store, note);
59
60
  }
61
+ /** Coche ou décoche une case du contenu d'une note. */
62
+ export function toggleNoteCheckbox(store, userId, noteId, target) {
63
+ const note = store.mutate(asUser(userId), (tx) => {
64
+ const current = requireNote(tx.store, noteId, userId);
65
+ const body = toggleCheckbox(current.body, target);
66
+ if (body === null)
67
+ throw new InvariantError(CHECKBOX_CONFLICT);
68
+ return body === current.body ? current : tx.updateNote(noteId, { body });
69
+ });
70
+ return noteView(store, note);
71
+ }
60
72
  export function deleteNote(store, userId, noteId) {
61
73
  store.mutate(asUser(userId), (tx) => {
62
74
  requireNote(tx.store, noteId, userId);
@@ -78,11 +78,21 @@ export declare function listRequests(store: Store, userId: string, spaceId: stri
78
78
  startedAt: string;
79
79
  } | null;
80
80
  }, now?: Date): RequestListResponse;
81
- /** Annule une action de l'agent ; le fichier d'une pièce jointe ainsi supprimée est effacé. */
82
- export declare function undoAction(store: Store, storage: AttachmentStorage, userId: string, actionId: string): RequestView;
81
+ /**
82
+ * Annule une action de l'agent. Le fichier d'une pièce jointe ainsi
83
+ * supprimée est gardé, pour qu'un rétablissement la remette.
84
+ */
85
+ export declare function undoAction(store: Store, userId: string, actionId: string): RequestView;
83
86
  /**
84
87
  * Annule toutes les actions non annulées d'un lot, de la plus récente à la
85
88
  * plus ancienne : tout le lot ou rien. Les fichiers des pièces jointes
86
- * supprimées sont effacés.
89
+ * supprimées sont gardés, pour qu'un rétablissement les remette.
90
+ */
91
+ export declare function undoRequest(store: Store, userId: string, requestId: string): RequestView;
92
+ /** Rétablit une action de l'agent annulée ; les mêmes membres que pour l'annuler le peuvent. */
93
+ export declare function redoAction(store: Store, storage: AttachmentStorage, userId: string, actionId: string): RequestView;
94
+ /**
95
+ * Rétablit toutes les actions annulées d'un lot, de la plus ancienne à la
96
+ * plus récente : tout le lot ou rien.
87
97
  */
88
- export declare function undoRequest(store: Store, storage: AttachmentStorage, userId: string, requestId: string): RequestView;
98
+ export declare function redoRequest(store: Store, storage: AttachmentStorage, userId: string, requestId: string): RequestView;
@@ -2,7 +2,7 @@ import { ForbiddenError, InvariantError, NotFoundError, OrganizerError } from ".
2
2
  import { stoppedByReason } from "./admin.js";
3
3
  import { requireMember } from "./spaces.js";
4
4
  import { requireTask } from "./tasks.js";
5
- import { undoAgentAction } from "./history.js";
5
+ import { redoAgentAction, undoAgentAction } from "./history.js";
6
6
  import { actionTaskKey } from "./agent.js";
7
7
  import { taskIdOfAction } from "./snapshots.js";
8
8
  import { tokenState } from "./agent-tokens.js";
@@ -324,40 +324,65 @@ function requireUndoableRequest(request) {
324
324
  if (request.status === "processing")
325
325
  throw new InvariantError("L'agent traite encore cette demande : attendez qu'il ait terminé pour annuler ses actions.");
326
326
  }
327
- /** Annule une action de l'agent ; le fichier d'une pièce jointe ainsi supprimée est effacé. */
328
- export function undoAction(store, storage, userId, actionId) {
329
- const { requestId, removedFile } = store.mutate(asUser(userId), (tx) => {
327
+ /**
328
+ * Annule une action de l'agent. Le fichier d'une pièce jointe ainsi
329
+ * supprimée est gardé, pour qu'un rétablissement la remette.
330
+ */
331
+ export function undoAction(store, userId, actionId) {
332
+ const requestId = store.mutate(asUser(userId), (tx) => {
330
333
  const action = tx.store.findAgentAction(actionId);
331
334
  if (!action)
332
335
  throw new NotFoundError("Action introuvable.");
333
336
  const request = requireVisibleRequest(tx.store, userId, action.requestId);
334
337
  requireUndoableRequest(request);
335
- return { requestId: request.id, removedFile: undoAgentAction(tx, action) };
338
+ undoAgentAction(tx, action);
339
+ return request.id;
336
340
  });
337
- if (removedFile !== null)
338
- storage.remove([removedFile]);
339
341
  return requestView(store, userId, store.getAgentRequest(requestId));
340
342
  }
341
343
  /**
342
344
  * Annule toutes les actions non annulées d'un lot, de la plus récente à la
343
345
  * plus ancienne : tout le lot ou rien. Les fichiers des pièces jointes
344
- * supprimées sont effacés.
346
+ * supprimées sont gardés, pour qu'un rétablissement les remette.
345
347
  */
346
- export function undoRequest(store, storage, userId, requestId) {
347
- const removedFiles = store.mutate(asUser(userId), (tx) => {
348
+ export function undoRequest(store, userId, requestId) {
349
+ store.mutate(asUser(userId), (tx) => {
348
350
  const request = requireVisibleRequest(tx.store, userId, requestId);
349
351
  requireUndoableRequest(request);
350
352
  const remaining = tx.store.listAgentActions(requestId).filter((action) => action.undoneAt === null);
351
353
  if (remaining.length === 0)
352
354
  throw new InvariantError("Toutes les actions de ce lot sont déjà annulées.");
353
- const files = [];
354
- for (const action of remaining.reverse()) {
355
- const removed = undoAgentAction(tx, tx.store.getAgentAction(action.id));
356
- if (removed !== null)
357
- files.push(removed);
358
- }
359
- return files;
355
+ for (const action of remaining.reverse())
356
+ undoAgentAction(tx, tx.store.getAgentAction(action.id));
357
+ });
358
+ return requestView(store, userId, store.getAgentRequest(requestId));
359
+ }
360
+ /** Rétablit une action de l'agent annulée ; les mêmes membres que pour l'annuler le peuvent. */
361
+ export function redoAction(store, storage, userId, actionId) {
362
+ const requestId = store.mutate(asUser(userId), (tx) => {
363
+ const action = tx.store.findAgentAction(actionId);
364
+ if (!action)
365
+ throw new NotFoundError("Action introuvable.");
366
+ const request = requireVisibleRequest(tx.store, userId, action.requestId);
367
+ requireUndoableRequest(request);
368
+ redoAgentAction(tx, action, (path) => storage.exists(path));
369
+ return request.id;
370
+ });
371
+ return requestView(store, userId, store.getAgentRequest(requestId));
372
+ }
373
+ /**
374
+ * Rétablit toutes les actions annulées d'un lot, de la plus ancienne à la
375
+ * plus récente : tout le lot ou rien.
376
+ */
377
+ export function redoRequest(store, storage, userId, requestId) {
378
+ store.mutate(asUser(userId), (tx) => {
379
+ const request = requireVisibleRequest(tx.store, userId, requestId);
380
+ requireUndoableRequest(request);
381
+ const undone = tx.store.listAgentActions(requestId).filter((action) => action.undoneAt !== null);
382
+ if (undone.length === 0)
383
+ throw new InvariantError("Aucune action de ce lot n'est annulée : rien à rétablir.");
384
+ for (const action of undone)
385
+ redoAgentAction(tx, tx.store.getAgentAction(action.id), (path) => storage.exists(path));
360
386
  });
361
- storage.remove(removedFiles);
362
387
  return requestView(store, userId, store.getAgentRequest(requestId));
363
388
  }
@@ -149,7 +149,7 @@ export declare class Store {
149
149
  questionSnapshot(id: string): QuestionSnapshot;
150
150
  findCheckpoint(id: string): TestCheckpoint | null;
151
151
  getCheckpoint(id: string): TestCheckpoint;
152
- /** Points de vérification d'une tâche de test, dans l'ordre. */
152
+ /** Points de vérification d'une tâche, dans l'ordre. */
153
153
  listCheckpoints(taskId: string): TestCheckpoint[];
154
154
  /** Résultats saisis sur les points d'une tâche, tous testeurs confondus. */
155
155
  listTestResults(taskId: string): TestResult[];
@@ -644,7 +644,7 @@ export declare class Mutation {
644
644
  multiple: boolean;
645
645
  options: readonly QuestionOptionInput[];
646
646
  }): QuestionSnapshot;
647
- /** Change le texte d'une question ou son type de choix ; un choix unique n'accepte qu'une réponse. */
647
+ /** Change le texte d'une question ou son type de choix ; un choix unique n'accepte qu'une proposition. */
648
648
  updateQuestion(id: string, patch: {
649
649
  text?: string;
650
650
  multiple?: boolean;
@@ -672,12 +672,12 @@ export declare class Mutation {
672
672
  replaceQuestion(snapshot: QuestionSnapshot): void;
673
673
  private insertQuestion;
674
674
  private insertQuestionOption;
675
- /** Un choix unique a pour réponse une seule proposition ou la réponse libre. */
675
+ /** Un choix unique retient au plus une proposition ; la réponse libre peut l'accompagner. */
676
676
  private requireSingleAnswer;
677
677
  private touchQuestion;
678
678
  /**
679
- * Ajoute un élément à la checklist d'une tâche standard : juste après
680
- * `afterId` (null : en tête), en fin de liste sans `afterId`.
679
+ * Ajoute un élément à la checklist d'une tâche : juste après `afterId`
680
+ * (null : en tête), en fin de liste sans `afterId`.
681
681
  */
682
682
  addChecklistItem(taskId: string, text: string, afterId?: string | null): ChecklistItem;
683
683
  updateChecklistItem(id: string, patch: {
@@ -698,12 +698,10 @@ export declare class Mutation {
698
698
  * reçoit les identifiants dans l'ordre et leur donne les rangs 1, 2, 3…
699
699
  */
700
700
  private slotAfter;
701
- /** Tâche de test qui porte des points de vérification. */
702
- private testTask;
703
- /** Tâche de test dont l'utilisateur acteur est testeur (assigné). */
701
+ /** Tâche dont l'utilisateur acteur est testeur (assigné). */
704
702
  private testedTask;
705
703
  /**
706
- * Ajoute un point de vérification à une tâche de test : juste après
704
+ * Ajoute un point de vérification à une tâche : juste après
707
705
  * `afterId` (null : en tête), en fin de liste sans `afterId`.
708
706
  */
709
707
  addCheckpoint(taskId: string, text: string, afterId?: string | null): TestCheckpoint;
@@ -744,6 +742,8 @@ export declare class Mutation {
744
742
  deleteComment(id: string): void;
745
743
  /** Supprime un commentaire écrit par l'agent, quel que soit l'utilisateur acteur : annulation de l'action qui l'a créé. */
746
744
  deleteAgentComment(id: string): void;
745
+ /** Recrée un commentaire de l'agent supprimé, avec son identifiant ; sa réponse à un commentaire disparu depuis est oubliée. */
746
+ restoreComment(snapshot: Comment): Comment;
747
747
  private authoredComment;
748
748
  /** Enregistre une pièce jointe dont le fichier est déjà écrit sous `storagePath`. */
749
749
  createAttachment(input: {
@@ -756,6 +756,8 @@ export declare class Mutation {
756
756
  }): Attachment;
757
757
  /** Supprime l'enregistrement d'une pièce jointe et le renvoie ; son fichier reste à effacer. */
758
758
  deleteAttachment(id: string): Attachment;
759
+ /** Recrée l'enregistrement d'une pièce jointe supprimée, avec son identifiant ; son fichier doit encore exister sous `storagePath`. */
760
+ restoreAttachment(snapshot: Attachment): Attachment;
759
761
  /** Enregistre une image de demande, encore rattachée à aucune demande, dont le fichier est déjà écrit sous `storagePath`. */
760
762
  createRequestAttachment(input: {
761
763
  id: string;
@@ -785,6 +787,8 @@ export declare class Mutation {
785
787
  createIdea(input: CreateIdeaInput): Idea;
786
788
  updateIdea(id: string, patch: UpdateIdeaInput): Idea;
787
789
  /** Supprime une idée ; sa version de suppression a un instantané nul. */
790
+ /** Recrée une idée supprimée, avec son identifiant ; sa tâche issue de l'idée est oubliée si elle n'existe plus. */
791
+ restoreIdea(snapshot: Idea): Idea;
788
792
  deleteIdea(id: string): void;
789
793
  createNote(input: CreateNoteInput): Note;
790
794
  updateNote(id: string, patch: UpdateNoteInput): Note;
@@ -874,6 +878,8 @@ export declare class Mutation {
874
878
  recordAgentAction(input: AgentActionInput): AgentAction;
875
879
  /** Marque annulée une action de l'agent, par l'utilisateur acteur. */
876
880
  markAgentActionUndone(id: string, taskId: string | null): AgentAction;
881
+ /** Marque rétablie une action de l'agent annulée, par l'utilisateur acteur : elle redevient active. */
882
+ markAgentActionRedone(id: string, taskId: string | null): AgentAction;
877
883
  /**
878
884
  * Démarre une session de chrono d'un membre sur une tâche, en marche dès
879
885
  * `at`. Le membre n'a qu'une session active par tâche, et une seule en
@@ -898,6 +904,12 @@ export declare class Mutation {
898
904
  * tâche, ou tourne alors que l'état visé est en marche.
899
905
  */
900
906
  restoreTimeSessionState(id: string, state: Pick<TimeSession, "runningSince" | "elapsedMs" | "endedAt">): TimeSession;
907
+ /**
908
+ * Recrée une session de chrono supprimée, avec son identifiant ; refusé
909
+ * quand une autre session du membre occupe désormais la tâche, ou tourne
910
+ * alors que la session recréée est en marche.
911
+ */
912
+ restoreTimeSession(snapshot: TimeSession): TimeSession;
901
913
  deleteTimeSession(id: string): void;
902
914
  private insertTimeSession;
903
915
  private writeTimeSessionState;
@@ -850,7 +850,7 @@ export class Store {
850
850
  throw new NotFoundError(`Checkpoint ${id} not found.`);
851
851
  return checkpoint;
852
852
  }
853
- /** Points de vérification d'une tâche de test, dans l'ordre. */
853
+ /** Points de vérification d'une tâche, dans l'ordre. */
854
854
  listCheckpoints(taskId) {
855
855
  const rows = this.db.prepare("SELECT * FROM test_checkpoints WHERE task_id = ? ORDER BY position").all(taskId);
856
856
  return rows.map(checkpointFromRow);
@@ -2026,7 +2026,7 @@ export class Mutation {
2026
2026
  this.touch("task_question", question.id, task.spaceId, null, taskId);
2027
2027
  return this.store.questionSnapshot(question.id);
2028
2028
  }
2029
- /** Change le texte d'une question ou son type de choix ; un choix unique n'accepte qu'une réponse. */
2029
+ /** Change le texte d'une question ou son type de choix ; un choix unique n'accepte qu'une proposition. */
2030
2030
  updateQuestion(id, patch) {
2031
2031
  const current = this.store.getQuestion(id);
2032
2032
  const question = validate(TaskQuestionSchema, { ...current, ...definedFields(patch) }, "question");
@@ -2147,25 +2147,22 @@ export class Mutation {
2147
2147
  .prepare("INSERT INTO question_options (id, question_id, label, detail, recommended, selected, position) VALUES (?, ?, ?, ?, ?, ?, ?)")
2148
2148
  .run(option.id, option.questionId, option.label, option.detail, option.recommended ? 1 : 0, option.selected ? 1 : 0, option.position);
2149
2149
  }
2150
- /** Un choix unique a pour réponse une seule proposition ou la réponse libre. */
2150
+ /** Un choix unique retient au plus une proposition ; la réponse libre peut l'accompagner. */
2151
2151
  requireSingleAnswer(question, options) {
2152
- const answers = options.filter((option) => option.selected).length + (question.otherAnswer === null ? 0 : 1);
2153
- if (answers > 1)
2154
- throw new InvariantError(`"${question.text}" is a single-choice question: it takes one option or a free answer, not ${answers}.`);
2152
+ const selected = options.filter((option) => option.selected).length;
2153
+ if (selected > 1)
2154
+ throw new InvariantError(`"${question.text}" is a single-choice question: it takes one option, not ${selected}.`);
2155
2155
  }
2156
2156
  touchQuestion(question) {
2157
2157
  this.touch("task_question", question.id, this.store.getTask(question.taskId).spaceId, null, question.taskId);
2158
2158
  }
2159
2159
  // --- Checklist ---
2160
2160
  /**
2161
- * Ajoute un élément à la checklist d'une tâche standard : juste après
2162
- * `afterId` (null : en tête), en fin de liste sans `afterId`.
2161
+ * Ajoute un élément à la checklist d'une tâche : juste après `afterId`
2162
+ * (null : en tête), en fin de liste sans `afterId`.
2163
2163
  */
2164
2164
  addChecklistItem(taskId, text, afterId) {
2165
2165
  const task = this.store.getTask(taskId);
2166
- if (task.type !== "standard") {
2167
- throw new InvariantError(`Task ${taskLabel(this.db, task)} is a test: it has checkpoints, not a checklist.`);
2168
- }
2169
2166
  const items = this.store.listChecklist(taskId);
2170
2167
  const position = this.slotAfter(items, afterId === undefined ? (items.at(-1)?.id ?? null) : afterId, `Checklist item ${afterId} is not in this checklist`, (ids) => {
2171
2168
  const update = this.db.prepare("UPDATE checklist_items SET position = ? WHERE id = ?");
@@ -2197,8 +2194,6 @@ export class Mutation {
2197
2194
  restoreChecklistItem(snapshot) {
2198
2195
  const item = validate(ChecklistItemSchema, snapshot, "checklist item");
2199
2196
  const task = this.store.getTask(item.taskId);
2200
- if (task.type !== "standard")
2201
- throw new InvariantError(`Task ${taskLabel(this.db, task)} is a test: it has checkpoints, not a checklist.`);
2202
2197
  this.db
2203
2198
  .prepare("INSERT INTO checklist_items (id, task_id, text, done, position) VALUES (?, ?, ?, ?, ?)")
2204
2199
  .run(item.id, item.taskId, item.text, item.done ? 1 : 0, item.position);
@@ -2251,31 +2246,23 @@ export class Mutation {
2251
2246
  renumber(items.map((item) => item.id));
2252
2247
  return positionBetween(index > 0 ? index : null, index < items.length ? index + 1 : null);
2253
2248
  }
2254
- // --- Tâches de test ---
2255
- /** Tâche de test qui porte des points de vérification. */
2256
- testTask(taskId) {
2257
- const task = this.store.getTask(taskId);
2258
- if (task.type !== "test") {
2259
- throw new InvariantError(`Task ${taskLabel(this.db, task)} is a standard task: it has a checklist, not test checkpoints.`);
2260
- }
2261
- return task;
2262
- }
2263
- /** Tâche de test dont l'utilisateur acteur est testeur (assigné). */
2249
+ // --- Tests ---
2250
+ /** Tâche dont l'utilisateur acteur est testeur (assigné). */
2264
2251
  testedTask(taskId) {
2265
- const task = this.testTask(taskId);
2252
+ const task = this.store.getTask(taskId);
2266
2253
  if (!this.store.listAssigneeIds(taskId).includes(this.actingUserId)) {
2267
2254
  throw new ForbiddenError(`Only the testers (assignees) of task ${taskLabel(this.db, task)} can record results and reviews; assign the user first.`);
2268
2255
  }
2269
2256
  return task;
2270
2257
  }
2271
2258
  /**
2272
- * Ajoute un point de vérification à une tâche de test : juste après
2259
+ * Ajoute un point de vérification à une tâche : juste après
2273
2260
  * `afterId` (null : en tête), en fin de liste sans `afterId`.
2274
2261
  */
2275
2262
  addCheckpoint(taskId, text, afterId) {
2276
- const task = this.testTask(taskId);
2263
+ const task = this.store.getTask(taskId);
2277
2264
  const checkpoints = this.store.listCheckpoints(taskId);
2278
- const position = this.slotAfter(checkpoints, afterId === undefined ? (checkpoints.at(-1)?.id ?? null) : afterId, `Checkpoint ${afterId} is not in this test`, (ids) => {
2265
+ const position = this.slotAfter(checkpoints, afterId === undefined ? (checkpoints.at(-1)?.id ?? null) : afterId, `Checkpoint ${afterId} is not in the checkpoints of this task`, (ids) => {
2279
2266
  const update = this.db.prepare("UPDATE test_checkpoints SET position = ? WHERE id = ?");
2280
2267
  ids.forEach((checkpointId, index) => {
2281
2268
  update.run(index + 1, checkpointId);
@@ -2305,7 +2292,7 @@ export class Mutation {
2305
2292
  /** Recrée un point de vérification supprimé, avec son identifiant, sa position et les résultats saisis dessus. */
2306
2293
  restoreCheckpoint(snapshot, results) {
2307
2294
  const checkpoint = validate(TestCheckpointSchema, snapshot, "checkpoint");
2308
- const task = this.testTask(checkpoint.taskId);
2295
+ const task = this.store.getTask(checkpoint.taskId);
2309
2296
  this.db
2310
2297
  .prepare("INSERT INTO test_checkpoints (id, task_id, text, position) VALUES (?, ?, ?, ?)")
2311
2298
  .run(checkpoint.id, checkpoint.taskId, checkpoint.text, checkpoint.position);
@@ -2445,6 +2432,19 @@ export class Mutation {
2445
2432
  this.db.prepare("DELETE FROM comments WHERE id = ?").run(id);
2446
2433
  this.touch("comment", id, this.store.getTask(comment.taskId).spaceId, null, comment.taskId);
2447
2434
  }
2435
+ /** Recrée un commentaire de l'agent supprimé, avec son identifiant ; sa réponse à un commentaire disparu depuis est oubliée. */
2436
+ restoreComment(snapshot) {
2437
+ const task = this.store.getTask(snapshot.taskId);
2438
+ if (this.store.findComment(snapshot.id))
2439
+ throw new InvariantError(`Comment ${snapshot.id} already exists.`);
2440
+ const replyToCommentId = snapshot.replyToCommentId !== null && this.store.findComment(snapshot.replyToCommentId) ? snapshot.replyToCommentId : null;
2441
+ const comment = validate(CommentSchema, { ...snapshot, replyToCommentId }, "comment");
2442
+ this.db
2443
+ .prepare("INSERT INTO comments (id, task_id, author_id, body, created_at, edited_at, request_id, reply_to_comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
2444
+ .run(comment.id, comment.taskId, comment.authorId, comment.body, comment.createdAt, comment.editedAt, comment.requestId, comment.replyToCommentId);
2445
+ this.touch("comment", comment.id, task.spaceId, null, task.id);
2446
+ return comment;
2447
+ }
2448
2448
  authoredComment(id, action) {
2449
2449
  const comment = this.store.getComment(id);
2450
2450
  if (comment.authorId !== this.actingUserId)
@@ -2469,6 +2469,18 @@ export class Mutation {
2469
2469
  this.touch("attachment", id, this.store.getTask(attachment.taskId).spaceId, null, attachment.taskId);
2470
2470
  return attachment;
2471
2471
  }
2472
+ /** Recrée l'enregistrement d'une pièce jointe supprimée, avec son identifiant ; son fichier doit encore exister sous `storagePath`. */
2473
+ restoreAttachment(snapshot) {
2474
+ const task = this.store.getTask(snapshot.taskId);
2475
+ if (this.store.findAttachment(snapshot.id))
2476
+ throw new InvariantError(`Attachment ${snapshot.id} already exists.`);
2477
+ const attachment = validate(AttachmentSchema, snapshot, "attachment");
2478
+ this.db
2479
+ .prepare("INSERT INTO attachments (id, task_id, uploader_id, filename, mime, size, storage_path, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
2480
+ .run(attachment.id, attachment.taskId, attachment.uploaderId, attachment.filename, attachment.mime, attachment.size, attachment.storagePath, attachment.createdAt);
2481
+ this.touch("attachment", attachment.id, task.spaceId, null, task.id);
2482
+ return attachment;
2483
+ }
2472
2484
  /** Enregistre une image de demande, encore rattachée à aucune demande, dont le fichier est déjà écrit sous `storagePath`. */
2473
2485
  createRequestAttachment(input) {
2474
2486
  this.store.getSpace(input.spaceId);
@@ -2582,6 +2594,20 @@ export class Mutation {
2582
2594
  return idea;
2583
2595
  }
2584
2596
  /** Supprime une idée ; sa version de suppression a un instantané nul. */
2597
+ /** Recrée une idée supprimée, avec son identifiant ; sa tâche issue de l'idée est oubliée si elle n'existe plus. */
2598
+ restoreIdea(snapshot) {
2599
+ this.store.getSpace(snapshot.spaceId);
2600
+ if (this.store.findIdea(snapshot.id))
2601
+ throw new InvariantError(`Idea ${snapshot.id} already exists.`);
2602
+ const promotedTaskId = snapshot.promotedTaskId !== null && this.store.findTask(snapshot.promotedTaskId) ? snapshot.promotedTaskId : null;
2603
+ const idea = validate(IdeaSchema, { ...snapshot, promotedTaskId }, "idea");
2604
+ this.db
2605
+ .prepare(`INSERT INTO ideas (id, space_id, author_id, text, origin, request_id, promoted_task_id, archived_at, created_at)
2606
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2607
+ .run(idea.id, idea.spaceId, idea.authorId, idea.text, idea.origin, idea.requestId, idea.promotedTaskId, idea.archivedAt, idea.createdAt);
2608
+ this.touch("idea", idea.id, idea.spaceId, null);
2609
+ return idea;
2610
+ }
2585
2611
  deleteIdea(id) {
2586
2612
  const idea = this.store.getIdea(id);
2587
2613
  this.db.prepare("DELETE FROM ideas WHERE id = ?").run(id);
@@ -3065,6 +3091,17 @@ export class Mutation {
3065
3091
  this.touch("agent_action", id, this.store.getAgentRequest(action.requestId).targetSpaceId, null, taskId);
3066
3092
  return { ...action, undoneAt: this.now, undoneBy: this.actor.userId };
3067
3093
  }
3094
+ /** Marque rétablie une action de l'agent annulée, par l'utilisateur acteur : elle redevient active. */
3095
+ markAgentActionRedone(id, taskId) {
3096
+ if (this.actor.type !== "user")
3097
+ throw new InvariantError("Only a user can redo an agent action.");
3098
+ const action = this.store.getAgentAction(id);
3099
+ if (action.undoneAt === null)
3100
+ throw new InvariantError(`Agent action ${id} is not undone.`);
3101
+ this.db.prepare("UPDATE agent_actions SET undone_at = NULL, undone_by = NULL WHERE id = ?").run(id);
3102
+ this.touch("agent_action", id, this.store.getAgentRequest(action.requestId).targetSpaceId, null, taskId);
3103
+ return { ...action, undoneAt: null, undoneBy: null };
3104
+ }
3068
3105
  // --- Chrono ---
3069
3106
  /**
3070
3107
  * Démarre une session de chrono d'un membre sur une tâche, en marche dès
@@ -3139,6 +3176,24 @@ export class Mutation {
3139
3176
  }
3140
3177
  return this.writeTimeSessionState(current, state);
3141
3178
  }
3179
+ /**
3180
+ * Recrée une session de chrono supprimée, avec son identifiant ; refusé
3181
+ * quand une autre session du membre occupe désormais la tâche, ou tourne
3182
+ * alors que la session recréée est en marche.
3183
+ */
3184
+ restoreTimeSession(snapshot) {
3185
+ this.store.getTask(snapshot.taskId);
3186
+ if (this.store.findTimeSession(snapshot.id))
3187
+ throw new InvariantError(`Time session ${snapshot.id} already exists.`);
3188
+ const session = validate(TimeSessionSchema, snapshot, "time session");
3189
+ if (session.endedAt === null && this.store.findActiveTimeSession(session.taskId, session.userId))
3190
+ throw new InvariantError("Un autre chrono a été démarré depuis sur cette tâche : rétablissement impossible.");
3191
+ if (session.runningSince !== null && this.store.findRunningTimeSessionOf(session.userId))
3192
+ throw new InvariantError("Un autre chrono tourne désormais : mettez-le en pause avant de rétablir.");
3193
+ this.insertTimeSession(session);
3194
+ this.touchTimeSession(session);
3195
+ return session;
3196
+ }
3142
3197
  deleteTimeSession(id) {
3143
3198
  const session = this.store.getTimeSession(id);
3144
3199
  this.db.prepare("DELETE FROM time_sessions WHERE id = ?").run(id);