@imenam/mcp-organizer 1.0.42 → 1.0.44

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 (33) hide show
  1. package/README.md +6 -4
  2. package/dist/shared/logic/feedback.d.ts +12 -0
  3. package/dist/shared/logic/feedback.js +37 -0
  4. package/dist/shared/schemas/agent-api.schema.d.ts +42 -0
  5. package/dist/shared/schemas/agent-api.schema.js +5 -1
  6. package/dist/shared/schemas/agent-tools.schema.d.ts +19 -0
  7. package/dist/shared/schemas/agent-tools.schema.js +3 -0
  8. package/dist/shared/schemas/entities.schema.d.ts +29 -0
  9. package/dist/shared/schemas/entities.schema.js +19 -1
  10. package/dist/shared/schemas/enums.schema.d.ts +33 -2
  11. package/dist/shared/schemas/enums.schema.js +16 -2
  12. package/dist/shared/schemas/tasks-api.schema.d.ts +115 -0
  13. package/dist/shared/schemas/tasks-api.schema.js +41 -2
  14. package/dist/src/agent-api/tasks.js +9 -3
  15. package/dist/src/core/agent.js +41 -0
  16. package/dist/src/core/feedback.d.ts +26 -0
  17. package/dist/src/core/feedback.js +120 -0
  18. package/dist/src/core/migrations.js +50 -0
  19. package/dist/src/core/requests.js +7 -0
  20. package/dist/src/core/store.d.ts +10 -1
  21. package/dist/src/core/store.js +34 -1
  22. package/dist/src/core/tasks.js +7 -2
  23. package/dist/src/core/text-edits.d.ts +12 -0
  24. package/dist/src/core/text-edits.js +29 -0
  25. package/dist/src/gui-api.js +6 -1
  26. package/dist/src/mcp/start.d.ts +1 -1
  27. package/dist/src/mcp/start.js +1 -0
  28. package/dist/src/mcp/tools.js +16 -2
  29. package/gui/dist/assets/{index-pP-Dvqvt.css → index-CwE72p7-.css} +1 -1
  30. package/gui/dist/assets/index-DKATg-vt.js +144 -0
  31. package/gui/dist/index.html +2 -2
  32. package/package.json +1 -1
  33. package/gui/dist/assets/index-DRRMjg-Q.js +0 -144
@@ -324,6 +324,28 @@ export declare const CommentViewSchema: z.ZodObject<{
324
324
  authorName: z.ZodString;
325
325
  excerpt: z.ZodString;
326
326
  }, z.core.$strip>>;
327
+ answersFeedback: z.ZodNullable<z.ZodObject<{
328
+ targetKind: z.ZodEnum<{
329
+ checklist_item: "checklist_item";
330
+ checkpoint: "checkpoint";
331
+ comment: "comment";
332
+ description: "description";
333
+ option: "option";
334
+ passage: "passage";
335
+ question: "question";
336
+ section: "section";
337
+ }>;
338
+ targetId: z.ZodNullable<z.ZodString>;
339
+ excerpt: z.ZodString;
340
+ authorName: z.ZodString;
341
+ shortcut: z.ZodNullable<z.ZodEnum<{
342
+ details: "details";
343
+ rephrase: "rephrase";
344
+ simplify: "simplify";
345
+ wrong: "wrong";
346
+ }>>;
347
+ text: z.ZodString;
348
+ }, z.core.$strip>>;
327
349
  reply: z.ZodNullable<z.ZodObject<{
328
350
  requestId: z.ZodString;
329
351
  followUps: z.ZodArray<z.ZodObject<{
@@ -479,6 +501,29 @@ export declare const TestDetailSchema: z.ZodObject<{
479
501
  }, z.core.$strip>>;
480
502
  }, z.core.$strip>;
481
503
  export type TestDetail = z.infer<typeof TestDetailSchema>;
504
+ /** Retour ciblé en attente ou en cours sur un élément de la tâche. */
505
+ export declare const TaskFeedbackViewSchema: z.ZodObject<{
506
+ requestId: z.ZodString;
507
+ targetKind: z.ZodEnum<{
508
+ checklist_item: "checklist_item";
509
+ checkpoint: "checkpoint";
510
+ comment: "comment";
511
+ description: "description";
512
+ option: "option";
513
+ passage: "passage";
514
+ question: "question";
515
+ section: "section";
516
+ }>;
517
+ targetId: z.ZodNullable<z.ZodString>;
518
+ excerpt: z.ZodString;
519
+ status: z.ZodEnum<{
520
+ pending: "pending";
521
+ processing: "processing";
522
+ }>;
523
+ authorName: z.ZodString;
524
+ canCancel: z.ZodBoolean;
525
+ }, z.core.$strip>;
526
+ export type TaskFeedbackView = z.infer<typeof TaskFeedbackViewSchema>;
482
527
  export declare const TaskDetailResponseSchema: z.ZodObject<{
483
528
  task: z.ZodObject<{
484
529
  id: z.ZodString;
@@ -679,6 +724,28 @@ export declare const TaskDetailResponseSchema: z.ZodObject<{
679
724
  authorName: z.ZodString;
680
725
  excerpt: z.ZodString;
681
726
  }, z.core.$strip>>;
727
+ answersFeedback: z.ZodNullable<z.ZodObject<{
728
+ targetKind: z.ZodEnum<{
729
+ checklist_item: "checklist_item";
730
+ checkpoint: "checkpoint";
731
+ comment: "comment";
732
+ description: "description";
733
+ option: "option";
734
+ passage: "passage";
735
+ question: "question";
736
+ section: "section";
737
+ }>;
738
+ targetId: z.ZodNullable<z.ZodString>;
739
+ excerpt: z.ZodString;
740
+ authorName: z.ZodString;
741
+ shortcut: z.ZodNullable<z.ZodEnum<{
742
+ details: "details";
743
+ rephrase: "rephrase";
744
+ simplify: "simplify";
745
+ wrong: "wrong";
746
+ }>>;
747
+ text: z.ZodString;
748
+ }, z.core.$strip>>;
682
749
  reply: z.ZodNullable<z.ZodObject<{
683
750
  requestId: z.ZodString;
684
751
  followUps: z.ZodArray<z.ZodObject<{
@@ -738,6 +805,27 @@ export declare const TaskDetailResponseSchema: z.ZodObject<{
738
805
  elapsedMs: z.ZodNumber;
739
806
  }, z.core.$strip>>;
740
807
  }, z.core.$strip>;
808
+ feedbacks: z.ZodArray<z.ZodObject<{
809
+ requestId: z.ZodString;
810
+ targetKind: z.ZodEnum<{
811
+ checklist_item: "checklist_item";
812
+ checkpoint: "checkpoint";
813
+ comment: "comment";
814
+ description: "description";
815
+ option: "option";
816
+ passage: "passage";
817
+ question: "question";
818
+ section: "section";
819
+ }>;
820
+ targetId: z.ZodNullable<z.ZodString>;
821
+ excerpt: z.ZodString;
822
+ status: z.ZodEnum<{
823
+ pending: "pending";
824
+ processing: "processing";
825
+ }>;
826
+ authorName: z.ZodString;
827
+ canCancel: z.ZodBoolean;
828
+ }, z.core.$strip>>;
741
829
  }, z.core.$strip>;
742
830
  export type TaskDetailResponse = z.infer<typeof TaskDetailResponseSchema>;
743
831
  export declare const CreateTaskRequestSchema: z.ZodObject<{
@@ -870,6 +958,33 @@ export declare const CommentRequestSchema: z.ZodObject<{
870
958
  body: z.ZodString;
871
959
  }, z.core.$strip>;
872
960
  export type CommentRequest = z.infer<typeof CommentRequestSchema>;
961
+ export declare const MAX_FEEDBACK_PRECISION_LENGTH = 4000;
962
+ /**
963
+ * Retour ciblé envoyé à l'agent sur un élément de la tâche : l'élément, son
964
+ * texte tel que le membre le voit, un raccourci et/ou une précision libre.
965
+ */
966
+ export declare const SendFeedbackRequestSchema: z.ZodObject<{
967
+ targetKind: z.ZodEnum<{
968
+ checklist_item: "checklist_item";
969
+ checkpoint: "checkpoint";
970
+ comment: "comment";
971
+ description: "description";
972
+ option: "option";
973
+ passage: "passage";
974
+ question: "question";
975
+ section: "section";
976
+ }>;
977
+ targetId: z.ZodNullable<z.ZodString>;
978
+ excerpt: z.ZodString;
979
+ shortcut: z.ZodNullable<z.ZodEnum<{
980
+ details: "details";
981
+ rephrase: "rephrase";
982
+ simplify: "simplify";
983
+ wrong: "wrong";
984
+ }>>;
985
+ precision: z.ZodString;
986
+ }, z.core.$strip>;
987
+ export type SendFeedbackRequest = z.infer<typeof SendFeedbackRequestSchema>;
873
988
  /** Type MIME `type/sous-type`, sans paramètres. */
874
989
  export declare const MimeTypeSchema: z.ZodString;
875
990
  /** Pièce jointe transmise par le serveur web, qui lit le formulaire multipart du navigateur. */
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { RequestStatusSchema, TaskPrioritySchema, TaskStatusSchema, TaskTypeSchema, TestResultValueSchema } from "./enums.schema.js";
2
+ import { FeedbackShortcutSchema, FeedbackTargetKindSchema, RequestStatusSchema, TaskPrioritySchema, TaskStatusSchema, TaskTypeSchema, TestResultValueSchema } from "./enums.schema.js";
3
3
  import { TaskTimeSchema } from "./timers-api.schema.js";
4
- import { ChangeSchema, EmailSchema, IdSchema, MAX_OTHER_ANSWER_LENGTH, PositionSchema, TimestampSchema } from "./entities.schema.js";
4
+ import { ChangeSchema, EmailSchema, IdSchema, MAX_FEEDBACK_EXCERPT_LENGTH, MAX_OTHER_ANSWER_LENGTH, PositionSchema, TimestampSchema } from "./entities.schema.js";
5
5
  /** Corps des requêtes et des réponses de l'API des tâches de la GUI. */
6
6
  /** Taille maximale d'une pièce jointe : 20 Mo. */
7
7
  export const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
@@ -150,6 +150,18 @@ export const CommentViewSchema = z.object({
150
150
  .nullable(),
151
151
  /** Pour la réponse de l'agent : le commentaire auquel elle répond, son auteur et son début. */
152
152
  replyTo: z.object({ commentId: IdSchema, authorName: z.string(), excerpt: z.string() }).nullable(),
153
+ /** Pour la réponse de l'agent à un retour ciblé : l'élément visé, son texte au moment du retour, et le retour de son auteur. */
154
+ answersFeedback: z
155
+ .object({
156
+ targetKind: FeedbackTargetKindSchema,
157
+ targetId: IdSchema.nullable(),
158
+ excerpt: z.string(),
159
+ authorName: z.string(),
160
+ shortcut: FeedbackShortcutSchema.nullable(),
161
+ /** Retour de son auteur : le raccourci choisi et sa précision, une ligne chacun. */
162
+ text: z.string(),
163
+ })
164
+ .nullable(),
153
165
  /** Pour la réponse de l'agent : sa demande, ses points à régler et les modifications de son lot, actives ou annulées. */
154
166
  reply: z
155
167
  .object({
@@ -211,6 +223,17 @@ export const TestDetailSchema = z.object({
211
223
  /** Reviews soumises, de la plus récente à la plus ancienne. */
212
224
  reviews: z.array(SubmittedReviewViewSchema),
213
225
  });
226
+ /** Retour ciblé en attente ou en cours sur un élément de la tâche. */
227
+ export const TaskFeedbackViewSchema = z.object({
228
+ requestId: IdSchema,
229
+ targetKind: FeedbackTargetKindSchema,
230
+ targetId: IdSchema.nullable(),
231
+ excerpt: z.string(),
232
+ status: z.enum(["pending", "processing"]),
233
+ authorName: z.string(),
234
+ /** Vrai si l'utilisateur peut annuler le retour : il attend encore l'agent, et l'utilisateur est membre de l'espace. */
235
+ canCancel: z.boolean(),
236
+ });
214
237
  export const TaskDetailResponseSchema = z.object({
215
238
  task: TaskViewSchema,
216
239
  /** Tâches parentes, de la racine au parent direct. */
@@ -232,6 +255,8 @@ export const TaskDetailResponseSchema = z.object({
232
255
  agentEdit: z.object({ actionId: IdSchema, at: TimestampSchema }).nullable(),
233
256
  /** Temps passé : sessions de chrono de tous les membres. */
234
257
  time: TaskTimeSchema,
258
+ /** Retours ciblés que l'agent n'a pas encore traités, du plus ancien au plus récent. */
259
+ feedbacks: z.array(TaskFeedbackViewSchema),
235
260
  });
236
261
  // --- Requêtes ---
237
262
  export const CreateTaskRequestSchema = z.object({
@@ -297,6 +322,20 @@ export const ToggleCheckboxRequestSchema = z.object({
297
322
  checked: z.boolean(),
298
323
  });
299
324
  export const CommentRequestSchema = z.object({ body: z.string().trim().min(1, "Le commentaire est vide.").max(10_000) });
325
+ export const MAX_FEEDBACK_PRECISION_LENGTH = 4000;
326
+ /**
327
+ * Retour ciblé envoyé à l'agent sur un élément de la tâche : l'élément, son
328
+ * texte tel que le membre le voit, un raccourci et/ou une précision libre.
329
+ */
330
+ export const SendFeedbackRequestSchema = z
331
+ .object({
332
+ targetKind: FeedbackTargetKindSchema,
333
+ targetId: IdSchema.nullable(),
334
+ excerpt: z.string().trim().min(1, "L'élément visé est vide.").max(MAX_FEEDBACK_EXCERPT_LENGTH, `Le passage visé dépasse ${MAX_FEEDBACK_EXCERPT_LENGTH} caractères.`),
335
+ shortcut: FeedbackShortcutSchema.nullable(),
336
+ precision: z.string().max(MAX_FEEDBACK_PRECISION_LENGTH, `La précision dépasse ${MAX_FEEDBACK_PRECISION_LENGTH} caractères.`),
337
+ })
338
+ .refine((input) => input.shortcut !== null || input.precision.trim() !== "", { message: "Choisissez un raccourci ou écrivez votre retour.", path: ["precision"] });
300
339
  /** Type MIME `type/sous-type`, sans paramètres. */
301
340
  export const MimeTypeSchema = z.string().regex(/^[\w.+-]+\/[\w.+-]+$/, "Type de fichier invalide.");
302
341
  /** Pièce jointe transmise par le serveur web, qui lit le formulaire multipart du navigateur. */
@@ -3,6 +3,7 @@ import { attachmentImages } from "../../shared/logic/attachments.js";
3
3
  import { combinedResult } from "../../shared/logic/test-summary.js";
4
4
  import { actFor, ago, attachmentLines, assigneesSummary, createdTaskSummary, ideaData, imageNote, documentData, memberData, recentIdeas, requireText, resolveMembers, resolveTask, spaceContextLines, spaceData, taskData, taskKey, taskUpdateSummary, treeData, userLabel, } from "../core/agent.js";
5
5
  import { OrganizerError } from "../core/errors.js";
6
+ import { applyTextEdits } from "../core/text-edits.js";
6
7
  import { questionData, questionLines, questionsOf } from "./questions.js";
7
8
  import { parseInput, respond } from "./types.js";
8
9
  /** Espace du jeton et ses tâches : contexte, lecture, recherche, création, modification, assignés, tags, commentaires. */
@@ -192,10 +193,13 @@ export const taskRoutes = [
192
193
  path: "/tasks/:ref",
193
194
  handle: ({ store }, { agent, params, body }) => {
194
195
  const input = parseInput(UpdateTaskBodySchema, body);
195
- const { title, description, status, priority, type, parent, after_task, tested_task_id } = input;
196
+ const { title, description, description_edits, status, priority, type, parent, after_task, tested_task_id } = input;
196
197
  const { task, summary } = actFor(store, agent, input.request_id, (tx, space) => {
197
- if ([title, description, status, priority, type, parent, after_task, tested_task_id].every((value) => value === undefined)) {
198
- throw new OrganizerError("Nothing to change: give at least one of title, description, status, priority, type, parent, after_task or tested_task_id.");
198
+ if ([title, description, description_edits, status, priority, type, parent, after_task, tested_task_id].every((value) => value === undefined)) {
199
+ throw new OrganizerError("Nothing to change: give at least one of title, description, description_edits, status, priority, type, parent, after_task or tested_task_id.");
200
+ }
201
+ if (description !== undefined && description_edits !== undefined) {
202
+ throw new OrganizerError("Give either description (the whole new text) or description_edits (passages to replace), not both.");
199
203
  }
200
204
  const patch = {};
201
205
  if (title !== undefined)
@@ -209,6 +213,8 @@ export const taskRoutes = [
209
213
  if (type !== undefined)
210
214
  patch.type = type;
211
215
  const task = resolveTask(tx.store, space, params.ref);
216
+ if (description_edits !== undefined)
217
+ patch.description = applyTextEdits(task.description, description_edits, `the description of ${taskKey(tx.store, task)}`);
212
218
  if (parent !== undefined)
213
219
  patch.parentId = parent === null ? null : resolveTask(tx.store, space, parent).id;
214
220
  if (tested_task_id !== undefined)
@@ -6,6 +6,8 @@ import { PRIORITY_LABELS, STATUS_LABELS, TYPE_LABELS } from "../../shared/logic/
6
6
  import { summarizeTest } from "../../shared/logic/test-summary.js";
7
7
  import { attachmentsOfRequest } from "./request-attachments.js";
8
8
  import { attachmentImages } from "../../shared/logic/attachments.js";
9
+ import { FEEDBACK_SHORTCUT_LABELS } from "../../shared/logic/feedback.js";
10
+ import { targetText } from "./feedback.js";
9
11
  export function agentActor(agent, requestId) {
10
12
  return { type: "agent", requestId, tokenId: agent.token.id };
11
13
  }
@@ -266,7 +268,42 @@ const KIND_GUIDANCE = {
266
268
  test_review: "A test review written by a tester of the context task: feed it back into the existing tasks (status, checklist, comments, priorities) or create a task for each problem found.",
267
269
  idea_promotion: "Promote the context idea into a well-formed task (clear title, description, type, priority, parent if relevant) with promote_idea.",
268
270
  direct: "A batch of actions the agent performed directly, without a request: there is nothing to process.",
271
+ feedback: "A targeted feedback of a member on one element of the context task: change that element as asked (rephrase, correct, detail, simplify), or answer it without changing anything when the feedback asks for information.",
269
272
  };
273
+ /** Élément visé par un retour, désigné pour l'agent, avec l'outil qui le modifie. */
274
+ const FEEDBACK_TARGETS = {
275
+ description: { name: "the whole description", tool: "update_task with description_edits (or description to rework it as a whole)" },
276
+ section: { name: "a section of the description (the heading below)", tool: "update_task with description_edits, limited to that section" },
277
+ passage: { name: "a passage of the description (the text below, as rendered on screen)", tool: "update_task with description_edits, limited to that passage" },
278
+ question: { name: "a question", tool: "edit_questions" },
279
+ option: { name: "an option of a question", tool: "edit_questions" },
280
+ checklist_item: { name: "a checklist item", tool: "edit_checklist" },
281
+ checkpoint: { name: "a test checkpoint", tool: "edit_checklist" },
282
+ comment: { name: "a comment", tool: "none: a comment is never rewritten, answer it in your reply" },
283
+ };
284
+ /** Lignes d'un retour ciblé : l'élément visé, son texte au moment du retour et maintenant, le raccourci choisi, et la façon d'agir. */
285
+ function feedbackLines(store, request, task) {
286
+ const feedback = store.findRequestFeedback(request.id);
287
+ if (!feedback)
288
+ return [];
289
+ const target = FEEDBACK_TARGETS[feedback.targetKind];
290
+ const lines = [
291
+ "",
292
+ `This request is a targeted feedback of ${userLabel(store.getUser(request.authorId))} on ${target.name}${feedback.targetId === null ? "" : ` (id ${feedback.targetId})`}${task ? ` of ${taskKey(store, task)}` : ""}.`,
293
+ `Its text when the feedback was sent: "${feedback.excerpt}"`,
294
+ ];
295
+ const current = task ? targetText(store, task, feedback) : null;
296
+ if (feedback.targetId !== null) {
297
+ if (current === null)
298
+ lines.push("That element no longer exists: say so in your reply.");
299
+ else if (current.trim() !== feedback.excerpt)
300
+ lines.push(`Its text now: "${current.trim()}"`);
301
+ }
302
+ if (feedback.shortcut !== null)
303
+ lines.push(`Kind of feedback: ${feedback.shortcut} ("${FEEDBACK_SHORTCUT_LABELS[feedback.shortcut]}").`);
304
+ lines.push(`To change it: ${target.tool}. Change only that element: in a description, replace the sentences concerned with description_edits and leave the rest of the text untouched.`, "complete_request posts your reply as a comment of the task that quotes the element: write it as an answer to the feedback (what you changed, or the information asked). Do not add another comment for it.");
305
+ return lines;
306
+ }
270
307
  /**
271
308
  * Échanges précédents de l'auteur d'un message dans l'espace visé, du plus ancien
272
309
  * au plus récent, au nombre fixé dans ses paramètres ; aucun pour les autres types.
@@ -380,6 +417,10 @@ export function requestContext(store, agent, request) {
380
417
  const thread = requestThread(store, request);
381
418
  if (thread)
382
419
  lines.push(...threadLines(store, thread));
420
+ if (request.kind === "feedback") {
421
+ const discussed = request.contextTaskId === null ? null : store.findTask(request.contextTaskId);
422
+ lines.push(...feedbackLines(store, request, discussed && discussed.spaceId === request.targetSpaceId ? discussed : null));
423
+ }
383
424
  const history = requestHistory(store, request);
384
425
  if (history.length > 0) {
385
426
  lines.push("", `Previous exchanges of the author in this space (oldest first, ${history.length} most recent) — use them to understand the message:`);
@@ -0,0 +1,26 @@
1
+ import type { Store } from "./store.js";
2
+ import { type Comment, type RequestFeedback, type Task } from "../../shared/schemas/entities.schema.js";
3
+ import type { CommentView, SendFeedbackRequest, TaskFeedbackView } from "../../shared/schemas/tasks-api.schema.js";
4
+ /**
5
+ * Texte actuel de l'élément visé, ou null s'il n'existe plus ou n'appartient
6
+ * pas à la tâche : le texte d'une question, le libellé d'une proposition, le
7
+ * texte d'un élément de checklist ou d'un point, le corps d'un commentaire, la
8
+ * description. Une section ou un passage n'ont pas de texte propre : la
9
+ * description sert de référence.
10
+ */
11
+ export declare function targetText(store: Store, task: Task, target: Pick<RequestFeedback, "targetKind" | "targetId">): string | null;
12
+ /**
13
+ * Envoie un retour ciblé à l'agent. L'élément désigné par un identifiant doit
14
+ * appartenir à la tâche ; son extrait est son texte actuel. Une section ou un
15
+ * passage gardent le texte que le membre a vu ; la description entière est
16
+ * citée telle qu'elle est.
17
+ */
18
+ export declare function sendFeedback(store: Store, userId: string, taskId: string, input: SendFeedbackRequest): TaskFeedbackView;
19
+ /** Retours ciblés que l'agent n'a pas encore traités sur une tâche, du plus ancien au plus récent. */
20
+ export declare function openFeedbacks(store: Store, userId: string, taskId: string): TaskFeedbackView[];
21
+ /**
22
+ * Pour la réponse de l'agent à un retour ciblé — le commentaire publié par
23
+ * `complete_request`, dont le texte est la réponse de la demande — l'élément
24
+ * visé et le retour de son auteur ; null pour un autre commentaire.
25
+ */
26
+ export declare function answeredFeedback(store: Store, comment: Comment): CommentView["answersFeedback"];
@@ -0,0 +1,120 @@
1
+ import { InvariantError, NotFoundError } from "./errors.js";
2
+ import { requireTask } from "./tasks.js";
3
+ import { feedbackRequestText } from "../../shared/logic/feedback.js";
4
+ import { MAX_FEEDBACK_EXCERPT_LENGTH } from "../../shared/schemas/entities.schema.js";
5
+ /**
6
+ * Retours ciblés : un membre envoie à l'agent un retour sur un élément précis
7
+ * d'une tâche (question, proposition, élément de checklist, point de
8
+ * vérification, commentaire, description, section ou passage). Le retour est
9
+ * une demande `feedback` qui a la tâche pour contexte et retient l'élément
10
+ * visé ; la réponse de l'agent est publiée en commentaire de la tâche, qui
11
+ * cite l'élément.
12
+ */
13
+ const asUser = (userId) => ({ type: "user", userId });
14
+ function userName(store, userId) {
15
+ const user = store.findUser(userId);
16
+ return user ? (user.displayName ?? user.email) : "un ancien membre";
17
+ }
18
+ /** Texte limité à la longueur d'un extrait enregistré. */
19
+ function clipped(text) {
20
+ const trimmed = text.trim();
21
+ return trimmed.length > MAX_FEEDBACK_EXCERPT_LENGTH ? `${trimmed.slice(0, MAX_FEEDBACK_EXCERPT_LENGTH - 1)}…` : trimmed;
22
+ }
23
+ /**
24
+ * Texte actuel de l'élément visé, ou null s'il n'existe plus ou n'appartient
25
+ * pas à la tâche : le texte d'une question, le libellé d'une proposition, le
26
+ * texte d'un élément de checklist ou d'un point, le corps d'un commentaire, la
27
+ * description. Une section ou un passage n'ont pas de texte propre : la
28
+ * description sert de référence.
29
+ */
30
+ export function targetText(store, task, target) {
31
+ const { targetKind, targetId } = target;
32
+ if (targetKind === "description" || targetKind === "section" || targetKind === "passage")
33
+ return task.description;
34
+ if (targetId === null)
35
+ return null;
36
+ if (targetKind === "question") {
37
+ const question = store.findQuestion(targetId);
38
+ return question?.taskId === task.id ? question.text : null;
39
+ }
40
+ if (targetKind === "option") {
41
+ const option = store.findQuestionOption(targetId);
42
+ const question = option ? store.findQuestion(option.questionId) : null;
43
+ return option && question?.taskId === task.id ? option.label : null;
44
+ }
45
+ if (targetKind === "checklist_item") {
46
+ const item = store.findChecklistItem(targetId);
47
+ return item?.taskId === task.id ? item.text : null;
48
+ }
49
+ if (targetKind === "checkpoint") {
50
+ const checkpoint = store.findCheckpoint(targetId);
51
+ return checkpoint?.taskId === task.id ? checkpoint.text : null;
52
+ }
53
+ const comment = store.findComment(targetId);
54
+ return comment?.taskId === task.id ? comment.body : null;
55
+ }
56
+ /**
57
+ * Envoie un retour ciblé à l'agent. L'élément désigné par un identifiant doit
58
+ * appartenir à la tâche ; son extrait est son texte actuel. Une section ou un
59
+ * passage gardent le texte que le membre a vu ; la description entière est
60
+ * citée telle qu'elle est.
61
+ */
62
+ export function sendFeedback(store, userId, taskId, input) {
63
+ const request = store.mutate(asUser(userId), (tx) => {
64
+ const { task } = requireTask(tx.store, taskId, userId);
65
+ const designated = !["description", "section", "passage"].includes(input.targetKind);
66
+ if (designated !== (input.targetId !== null)) {
67
+ throw new InvariantError(designated ? "Indiquez l'élément visé par son identifiant." : "La description, une section ou un passage ne portent pas d'identifiant.");
68
+ }
69
+ const current = targetText(tx.store, task, input);
70
+ if (current === null)
71
+ throw new NotFoundError("L'élément visé n'existe plus dans cette tâche : rechargez la page.");
72
+ if (input.targetKind === "description" && current.trim() === "")
73
+ throw new InvariantError("La description est vide : il n'y a rien à reprendre.");
74
+ const excerpt = clipped(designated || input.targetKind === "description" ? current : input.excerpt);
75
+ return tx.createAgentRequest({
76
+ targetSpaceId: task.spaceId,
77
+ kind: "feedback",
78
+ text: feedbackRequestText(input.targetKind, excerpt, input.shortcut, input.precision),
79
+ contextTaskId: task.id,
80
+ feedback: { targetKind: input.targetKind, targetId: input.targetId, excerpt, shortcut: input.shortcut },
81
+ });
82
+ });
83
+ return feedbackView(store, userId, request, store.findRequestFeedback(request.id));
84
+ }
85
+ function feedbackView(store, userId, request, feedback) {
86
+ return {
87
+ requestId: request.id,
88
+ targetKind: feedback.targetKind,
89
+ targetId: feedback.targetId,
90
+ excerpt: feedback.excerpt,
91
+ status: request.status === "processing" ? "processing" : "pending",
92
+ authorName: userName(store, request.authorId),
93
+ canCancel: request.status === "pending" && store.isMember(request.targetSpaceId, userId),
94
+ };
95
+ }
96
+ /** Retours ciblés que l'agent n'a pas encore traités sur une tâche, du plus ancien au plus récent. */
97
+ export function openFeedbacks(store, userId, taskId) {
98
+ return store.listOpenFeedbackRequests(taskId).map(({ request, feedback }) => feedbackView(store, userId, request, feedback));
99
+ }
100
+ /**
101
+ * Pour la réponse de l'agent à un retour ciblé — le commentaire publié par
102
+ * `complete_request`, dont le texte est la réponse de la demande — l'élément
103
+ * visé et le retour de son auteur ; null pour un autre commentaire.
104
+ */
105
+ export function answeredFeedback(store, comment) {
106
+ const request = comment.requestId === null ? null : store.findAgentRequest(comment.requestId);
107
+ if (!request || request.kind !== "feedback" || request.reply === null || request.reply !== comment.body)
108
+ return null;
109
+ const feedback = store.findRequestFeedback(request.id);
110
+ if (!feedback)
111
+ return null;
112
+ return {
113
+ targetKind: feedback.targetKind,
114
+ targetId: feedback.targetId,
115
+ excerpt: feedback.excerpt,
116
+ authorName: userName(store, request.authorId),
117
+ shortcut: feedback.shortcut,
118
+ text: request.text.split("\n").slice(1).join("\n"),
119
+ };
120
+ }
@@ -851,6 +851,56 @@ export const MIGRATIONS = [
851
851
  PRIMARY KEY (user_id, space_id)
852
852
  );
853
853
  CREATE INDEX space_placements_category ON space_placements(category_id);
854
+ `,
855
+ // Type de demande `feedback` : retour d'un membre sur un élément précis d'une tâche, et l'élément visé.
856
+ `
857
+ CREATE TABLE agent_requests_next (
858
+ id TEXT PRIMARY KEY,
859
+ author_id TEXT NOT NULL REFERENCES users(id),
860
+ target_space_id TEXT NOT NULL REFERENCES spaces(id) ON DELETE CASCADE,
861
+ kind TEXT NOT NULL CHECK (kind IN ('idea', 'remark', 'test_review', 'message', 'idea_promotion', 'direct', 'feedback')),
862
+ context_task_id TEXT REFERENCES tasks(id) ON DELETE SET NULL,
863
+ context_idea_id TEXT REFERENCES ideas(id) ON DELETE SET NULL,
864
+ text TEXT NOT NULL CHECK (text <> ''),
865
+ status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'done', 'failed', 'cancelled')),
866
+ reply TEXT,
867
+ failure_reason TEXT,
868
+ created_at TEXT NOT NULL,
869
+ updated_at TEXT NOT NULL,
870
+ claimed_at TEXT,
871
+ completed_at TEXT,
872
+ cancelled_by TEXT REFERENCES users(id),
873
+ claimed_by_token_id TEXT REFERENCES agent_tokens(id) ON DELETE SET NULL,
874
+ stopped_at TEXT,
875
+ stopped_by TEXT REFERENCES users(id) ON DELETE SET NULL,
876
+ parent_request_id TEXT REFERENCES agent_requests(id) ON DELETE SET NULL,
877
+ comment_id TEXT REFERENCES comments(id) ON DELETE SET NULL,
878
+ dismissed_at TEXT,
879
+ dismissed_by TEXT REFERENCES users(id) ON DELETE SET NULL
880
+ );
881
+ INSERT INTO agent_requests_next (id, author_id, target_space_id, kind, context_task_id, context_idea_id, text, status, reply, failure_reason,
882
+ created_at, updated_at, claimed_at, completed_at, cancelled_by, claimed_by_token_id, stopped_at, stopped_by,
883
+ parent_request_id, comment_id, dismissed_at, dismissed_by)
884
+ SELECT id, author_id, target_space_id, kind, context_task_id, context_idea_id, text, status, reply, failure_reason,
885
+ created_at, updated_at, claimed_at, completed_at, cancelled_by, claimed_by_token_id, stopped_at, stopped_by,
886
+ parent_request_id, comment_id, dismissed_at, dismissed_by
887
+ FROM agent_requests;
888
+ DROP TABLE agent_requests;
889
+ ALTER TABLE agent_requests_next RENAME TO agent_requests;
890
+ CREATE INDEX agent_requests_status ON agent_requests(status, created_at);
891
+ CREATE INDEX agent_requests_claimed_by ON agent_requests(claimed_by_token_id);
892
+ CREATE INDEX agent_requests_target_status ON agent_requests(target_space_id, status, created_at);
893
+ CREATE INDEX agent_requests_parent ON agent_requests(parent_request_id);
894
+ CREATE INDEX agent_requests_comment ON agent_requests(comment_id);
895
+ CREATE INDEX agent_requests_context_task ON agent_requests(context_task_id);
896
+
897
+ CREATE TABLE request_feedbacks (
898
+ request_id TEXT PRIMARY KEY REFERENCES agent_requests(id) ON DELETE CASCADE,
899
+ target_kind TEXT NOT NULL CHECK (target_kind IN ('description', 'section', 'passage', 'question', 'option', 'checklist_item', 'checkpoint', 'comment')),
900
+ target_id TEXT,
901
+ excerpt TEXT NOT NULL CHECK (excerpt <> ''),
902
+ shortcut TEXT CHECK (shortcut IN ('rephrase', 'wrong', 'details', 'simplify'))
903
+ );
854
904
  `,
855
905
  ];
856
906
  /** Version du schéma attendue par ce code. */
@@ -69,6 +69,7 @@ export function requestView(store, userId, request) {
69
69
  const claimer = request.claimedByTokenId === null ? null : store.findAgentToken(request.claimedByTokenId);
70
70
  const steers = canSteer(store, userId, request);
71
71
  const parent = request.parentRequestId === null ? null : store.findAgentRequest(request.parentRequestId);
72
+ const feedback = request.kind === "feedback" ? store.findRequestFeedback(request.id) : null;
72
73
  return {
73
74
  id: request.id,
74
75
  kind: request.kind,
@@ -80,6 +81,7 @@ export function requestView(store, userId, request) {
80
81
  targetSpaceId: target.id,
81
82
  targetSpaceName: target.name,
82
83
  contextTask: task ? { id: task.id, key: `${store.getSpace(task.spaceId).keyPrefix}-${task.number}`, title: task.title } : null,
84
+ feedback: feedback ? { targetKind: feedback.targetKind, targetId: feedback.targetId, excerpt: feedback.excerpt, shortcut: feedback.shortcut } : null,
83
85
  reply: request.reply,
84
86
  followUps: store.listFollowUps(request.id).map((followUp) => followUpView(store, followUp)),
85
87
  failureReason: request.failureReason,
@@ -270,6 +272,10 @@ export function resendRequest(store, userId, requestId, text) {
270
272
  if (failed.kind === "idea_promotion" && (failed.contextIdeaId === null || !tx.store.findIdea(failed.contextIdeaId))) {
271
273
  throw new InvariantError("L'idée à promouvoir n'existe plus : cette demande ne peut pas être renvoyée.");
272
274
  }
275
+ const feedback = failed.kind === "feedback" ? tx.store.findRequestFeedback(failed.id) : null;
276
+ if (failed.kind === "feedback" && (contextTaskId === null || feedback === null)) {
277
+ throw new InvariantError("La tâche visée par ce retour n'existe plus : il ne peut pas être renvoyé.");
278
+ }
273
279
  const request = tx.createAgentRequest({
274
280
  targetSpaceId: failed.targetSpaceId,
275
281
  kind: failed.kind,
@@ -277,6 +283,7 @@ export function resendRequest(store, userId, requestId, text) {
277
283
  contextTaskId,
278
284
  contextIdeaId: failed.contextIdeaId,
279
285
  parentRequestId: failed.parentRequestId,
286
+ feedback: feedback ? { targetKind: feedback.targetKind, targetId: feedback.targetId, excerpt: feedback.excerpt, shortcut: feedback.shortcut } : undefined,
280
287
  });
281
288
  linkReferencedAttachments(tx, request);
282
289
  tx.setAgentRequestDismissed(failed.id, true);
@@ -1,7 +1,7 @@
1
1
  import type Database from "better-sqlite3";
2
2
  import { WatcherRegistry } from "./watchers.js";
3
3
  import { type BoardGrouping, type BoardLayout, type EntityType, type MemberRole, type RequestKind, type RequestStatus, type SpaceKind, type TaskPriority, type TaskStatus, type TaskType, type TestResultValue, type AccessLinkPurpose, type AgentOperation, type UserStatus, type VersionedEntityType } from "../../shared/schemas/enums.schema.js";
4
- import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRequest, type AgentToken, type Attachment, type RequestAttachment, type BoardView, type Change, type ChecklistItem, type Comment, type QuestionOption, type QuestionSnapshot, type TaskQuestion, type EntityVersion, type FollowUp, type Idea, type Invitation, type Note, type SpaceDocument, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type TimeSession, type PomodoroSettings, type EmailDigestMinutes, type SidebarMode, type TaskLinkLabel, type TaskOpenMode, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings, type SpaceCategory, type SpacePlacement } from "../../shared/schemas/entities.schema.js";
4
+ import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRequest, type AgentToken, type Attachment, type RequestAttachment, type RequestFeedback, type BoardView, type Change, type ChecklistItem, type Comment, type QuestionOption, type QuestionSnapshot, type TaskQuestion, type EntityVersion, type FollowUp, type Idea, type Invitation, type Note, type SpaceDocument, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type TimeSession, type PomodoroSettings, type EmailDigestMinutes, type SidebarMode, type TaskLinkLabel, type TaskOpenMode, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings, type SpaceCategory, type SpacePlacement } from "../../shared/schemas/entities.schema.js";
5
5
  import { type ClaudeConnection, type NewRunnerSession, type RunnerSessionRecord, type RunnerSettings } from "../../shared/schemas/admin-api.schema.js";
6
6
  import { type BroadcastRecord, type NewBroadcast } from "../../shared/schemas/broadcast-api.schema.js";
7
7
  /**
@@ -253,6 +253,13 @@ export declare class Store {
253
253
  listClosedRequestsOfAuthorBefore(spaceId: string, authorId: string, before: AgentRequest, limit: number): AgentRequest[];
254
254
  /** Demandes d'un espace, de la plus récente à la plus ancienne, au plus `limit`. */
255
255
  listAgentRequestsOfSpace(spaceId: string, limit: number): AgentRequest[];
256
+ /** Élément visé par une demande `feedback`, ou null pour une autre demande. */
257
+ findRequestFeedback(requestId: string): RequestFeedback | null;
258
+ /** Retours ciblés en attente ou en cours sur une tâche, du plus ancien au plus récent, avec l'élément visé. */
259
+ listOpenFeedbackRequests(taskId: string): {
260
+ request: AgentRequest;
261
+ feedback: RequestFeedback;
262
+ }[];
256
263
  /** Demande confiée à l'agent par un commentaire, ou null. */
257
264
  findRequestOfComment(commentId: string): AgentRequest | null;
258
265
  /** Suites d'une demande d'origine, de la plus ancienne à la plus récente. */
@@ -487,6 +494,8 @@ export interface CreateAgentRequestInput {
487
494
  parentRequestId?: string | null;
488
495
  /** Commentaire de tâche qui confie la demande à l'agent. */
489
496
  commentId?: string | null;
497
+ /** Élément de la tâche de contexte visé par une demande `feedback`. */
498
+ feedback?: Omit<RequestFeedback, "requestId">;
490
499
  }
491
500
  /**
492
501
  * Écritures d'une mutation en cours. Chaque méthode applique une modification