@imenam/mcp-organizer 1.0.15 → 1.0.17

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 (37) hide show
  1. package/README.md +13 -9
  2. package/dist/shared/schemas/agent-api.schema.d.ts +3 -0
  3. package/dist/shared/schemas/agent-tools.schema.d.ts +155 -1
  4. package/dist/shared/schemas/agent-tools.schema.js +53 -3
  5. package/dist/shared/schemas/entities.schema.d.ts +62 -4
  6. package/dist/shared/schemas/entities.schema.js +39 -4
  7. package/dist/shared/schemas/enums.schema.d.ts +2 -1
  8. package/dist/shared/schemas/enums.schema.js +1 -0
  9. package/dist/shared/schemas/tasks-api.schema.d.ts +51 -0
  10. package/dist/shared/schemas/tasks-api.schema.js +23 -1
  11. package/dist/shared/schemas/views-api.schema.d.ts +4 -0
  12. package/dist/shared/schemas/views-api.schema.js +3 -1
  13. package/dist/src/agent-api/questions.d.ts +15 -0
  14. package/dist/src/agent-api/questions.js +128 -0
  15. package/dist/src/agent-api/router.js +2 -1
  16. package/dist/src/agent-api/tasks.js +5 -0
  17. package/dist/src/agent-api/views.js +32 -7
  18. package/dist/src/core/board-views.js +11 -4
  19. package/dist/src/core/history.js +23 -3
  20. package/dist/src/core/migrations.js +31 -0
  21. package/dist/src/core/questions.d.ts +13 -0
  22. package/dist/src/core/questions.js +33 -0
  23. package/dist/src/core/snapshots.d.ts +3 -3
  24. package/dist/src/core/snapshots.js +3 -1
  25. package/dist/src/core/store.d.ts +55 -1
  26. package/dist/src/core/store.js +219 -7
  27. package/dist/src/core/tasks.js +2 -0
  28. package/dist/src/gui-api.js +6 -1
  29. package/dist/src/mcp/start.d.ts +1 -1
  30. package/dist/src/mcp/start.js +3 -3
  31. package/dist/src/mcp/tools.js +62 -5
  32. package/gui/dist/assets/index-Bby49RH2.css +1 -0
  33. package/gui/dist/assets/index-CQZQd34A.js +99 -0
  34. package/gui/dist/index.html +2 -2
  35. package/package.json +1 -1
  36. package/gui/dist/assets/index-CVwckTU6.css +0 -1
  37. package/gui/dist/assets/index-DS_BdlK5.js +0 -99
@@ -152,6 +152,39 @@ export const ChecklistItemSchema = z.object({
152
152
  done: z.boolean(),
153
153
  position: PositionSchema,
154
154
  });
155
+ export const MAX_QUESTION_LENGTH = 500;
156
+ export const MAX_QUESTION_OPTION_LABEL_LENGTH = 200;
157
+ export const MAX_QUESTION_OPTION_DETAIL_LENGTH = 4000;
158
+ export const MAX_QUESTION_OPTIONS = 10;
159
+ export const MAX_OTHER_ANSWER_LENGTH = 4000;
160
+ /**
161
+ * Question posée par l'agent dans une tâche : un choix unique ou multiple
162
+ * parmi des propositions, et une réponse libre (`otherAnswer`). Pour un choix
163
+ * unique, la réponse est une proposition ou la réponse libre, pas les deux.
164
+ * `answeredBy` et `answeredAt` désignent le membre qui a répondu en dernier.
165
+ */
166
+ export const TaskQuestionSchema = z.object({
167
+ id: IdSchema,
168
+ taskId: IdSchema,
169
+ text: z.string().trim().min(1).max(MAX_QUESTION_LENGTH),
170
+ multiple: z.boolean(),
171
+ otherAnswer: z.string().trim().min(1).max(MAX_OTHER_ANSWER_LENGTH).nullable(),
172
+ answeredBy: IdSchema.nullable(),
173
+ answeredAt: TimestampSchema.nullable(),
174
+ position: PositionSchema,
175
+ });
176
+ /** Proposition d'une question : libellé, détail en markdown, recommandation de l'agent et choix du membre. */
177
+ export const QuestionOptionSchema = z.object({
178
+ id: IdSchema,
179
+ questionId: IdSchema,
180
+ label: z.string().trim().min(1).max(MAX_QUESTION_OPTION_LABEL_LENGTH),
181
+ detail: z.string().max(MAX_QUESTION_OPTION_DETAIL_LENGTH),
182
+ recommended: z.boolean(),
183
+ selected: z.boolean(),
184
+ position: PositionSchema,
185
+ });
186
+ /** Question avec ses propositions, dans l'ordre : l'état que l'agent modifie et que l'annulation restaure. */
187
+ export const QuestionSnapshotSchema = TaskQuestionSchema.extend({ options: z.array(QuestionOptionSchema) });
155
188
  export const TestCheckpointSchema = z.object({
156
189
  id: IdSchema,
157
190
  taskId: IdSchema,
@@ -209,10 +242,11 @@ export const IdeaSchema = z.object({
209
242
  export const MAX_BOARD_VIEW_NAME_LENGTH = 40;
210
243
  /**
211
244
  * Vue du tableau de bord d'un membre dans un espace : disposition, regroupements
212
- * et filtres sur le statut, la priorité et les assignés des tâches de premier
213
- * niveau. Un filtre vide garde toutes les valeurs ; le filtre des assignés
214
- * garde les tâches assignées à au moins un des membres choisis et, avec
215
- * `unassigned`, les tâches sans assigné. `groupBy` forme les colonnes d'un Kanban
245
+ * et filtres sur le statut, la priorité, les assignés et les tags des tâches de
246
+ * premier niveau. Un filtre vide garde toutes les valeurs ; le filtre des
247
+ * assignés garde les tâches assignées à au moins un des membres choisis et,
248
+ * avec `unassigned`, les tâches sans assigné ; le filtre des tags garde les
249
+ * tâches qui portent au moins un des tags choisis. `groupBy` forme les colonnes d'un Kanban
216
250
  * ou d'une matrice et les sections d'une liste ; `thenBy` forme les lignes d'une
217
251
  * matrice et les sous-sections d'une liste.
218
252
  */
@@ -230,6 +264,7 @@ export const BoardViewSchema = z
230
264
  priorities: z.array(TaskPrioritySchema),
231
265
  assigneeIds: z.array(IdSchema),
232
266
  unassigned: z.boolean(),
267
+ tagIds: z.array(IdSchema),
233
268
  position: PositionSchema,
234
269
  createdAt: TimestampSchema,
235
270
  updatedAt: TimestampSchema,
@@ -123,7 +123,7 @@ export declare const NotificationTypeSchema: z.ZodEnum<{
123
123
  }>;
124
124
  export type NotificationType = z.infer<typeof NotificationTypeSchema>;
125
125
  /** Types d'entités nommés dans le journal `Change`, les versions et les actions de l'agent. */
126
- export declare const ENTITY_TYPES: readonly ["user", "user_settings", "space", "membership", "invitation", "task", "tag", "checklist_item", "test_checkpoint", "test_result", "test_review", "comment", "attachment", "idea", "agent_request", "agent_action", "follow_up", "agent_token", "notification", "board_view", "agent_instructions"];
126
+ export declare const ENTITY_TYPES: readonly ["user", "user_settings", "space", "membership", "invitation", "task", "tag", "checklist_item", "task_question", "test_checkpoint", "test_result", "test_review", "comment", "attachment", "idea", "agent_request", "agent_action", "follow_up", "agent_token", "notification", "board_view", "agent_instructions"];
127
127
  export declare const EntityTypeSchema: z.ZodEnum<{
128
128
  agent_action: "agent_action";
129
129
  agent_instructions: "agent_instructions";
@@ -141,6 +141,7 @@ export declare const EntityTypeSchema: z.ZodEnum<{
141
141
  space: "space";
142
142
  tag: "tag";
143
143
  task: "task";
144
+ task_question: "task_question";
144
145
  test_checkpoint: "test_checkpoint";
145
146
  test_result: "test_result";
146
147
  test_review: "test_review";
@@ -48,6 +48,7 @@ export const ENTITY_TYPES = [
48
48
  "task",
49
49
  "tag",
50
50
  "checklist_item",
51
+ "task_question",
51
52
  "test_checkpoint",
52
53
  "test_result",
53
54
  "test_review",
@@ -224,6 +224,32 @@ export declare const ChecklistItemViewSchema: z.ZodObject<{
224
224
  position: z.ZodNumber;
225
225
  }, z.core.$strip>;
226
226
  export type ChecklistItemView = z.infer<typeof ChecklistItemViewSchema>;
227
+ /** Proposition d'une question : libellé, détail en markdown, recommandation de l'agent, choix des membres. */
228
+ export declare const QuestionOptionViewSchema: z.ZodObject<{
229
+ id: z.ZodString;
230
+ label: z.ZodString;
231
+ detail: z.ZodString;
232
+ recommended: z.ZodBoolean;
233
+ selected: z.ZodBoolean;
234
+ }, z.core.$strip>;
235
+ export type QuestionOptionView = z.infer<typeof QuestionOptionViewSchema>;
236
+ /** Question posée par l'agent : propositions, réponse libre, et membre qui a répondu en dernier. */
237
+ export declare const QuestionViewSchema: z.ZodObject<{
238
+ id: z.ZodString;
239
+ text: z.ZodString;
240
+ multiple: z.ZodBoolean;
241
+ options: z.ZodArray<z.ZodObject<{
242
+ id: z.ZodString;
243
+ label: z.ZodString;
244
+ detail: z.ZodString;
245
+ recommended: z.ZodBoolean;
246
+ selected: z.ZodBoolean;
247
+ }, z.core.$strip>>;
248
+ otherAnswer: z.ZodNullable<z.ZodString>;
249
+ answeredBy: z.ZodNullable<z.ZodString>;
250
+ answeredAt: z.ZodNullable<z.ZodISODateTime>;
251
+ }, z.core.$strip>;
252
+ export type QuestionView = z.infer<typeof QuestionViewSchema>;
227
253
  /** Point à régler d'une demande traitée, tel que l'affichent la page Agent, sa modale et les commentaires d'une tâche. */
228
254
  export declare const FollowUpViewSchema: z.ZodObject<{
229
255
  id: z.ZodString;
@@ -498,6 +524,21 @@ export declare const TaskDetailResponseSchema: z.ZodObject<{
498
524
  }, z.core.$strip>>;
499
525
  children: z.ZodArray<z.ZodObject</*elided*/ any, z.core.$strip>>;
500
526
  }, z.core.$strip>>;
527
+ questions: z.ZodArray<z.ZodObject<{
528
+ id: z.ZodString;
529
+ text: z.ZodString;
530
+ multiple: z.ZodBoolean;
531
+ options: z.ZodArray<z.ZodObject<{
532
+ id: z.ZodString;
533
+ label: z.ZodString;
534
+ detail: z.ZodString;
535
+ recommended: z.ZodBoolean;
536
+ selected: z.ZodBoolean;
537
+ }, z.core.$strip>>;
538
+ otherAnswer: z.ZodNullable<z.ZodString>;
539
+ answeredBy: z.ZodNullable<z.ZodString>;
540
+ answeredAt: z.ZodNullable<z.ZodISODateTime>;
541
+ }, z.core.$strip>>;
501
542
  checklist: z.ZodArray<z.ZodObject<{
502
543
  id: z.ZodString;
503
544
  text: z.ZodString;
@@ -702,6 +743,15 @@ export declare const UpdateChecklistItemRequestSchema: z.ZodObject<{
702
743
  done: z.ZodOptional<z.ZodBoolean>;
703
744
  }, z.core.$strip>;
704
745
  export type UpdateChecklistItemRequest = z.infer<typeof UpdateChecklistItemRequestSchema>;
746
+ /**
747
+ * Réponse à une question : propositions choisies et réponse libre, qui
748
+ * remplacent la réponse précédente ; un choix unique en prend une seule.
749
+ */
750
+ export declare const AnswerQuestionRequestSchema: z.ZodObject<{
751
+ selectedOptionIds: z.ZodArray<z.ZodString>;
752
+ otherAnswer: z.ZodNullable<z.ZodString>;
753
+ }, z.core.$strip>;
754
+ export type AnswerQuestionRequest = z.infer<typeof AnswerQuestionRequestSchema>;
705
755
  /** Réordonnancement : élément après lequel se placer (null : en tête). */
706
756
  export declare const MoveAfterRequestSchema: z.ZodObject<{
707
757
  afterId: z.ZodNullable<z.ZodString>;
@@ -774,6 +824,7 @@ export declare const ChangesResponseSchema: z.ZodObject<{
774
824
  space: "space";
775
825
  tag: "tag";
776
826
  task: "task";
827
+ task_question: "task_question";
777
828
  test_checkpoint: "test_checkpoint";
778
829
  test_result: "test_result";
779
830
  test_review: "test_review";
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { RequestStatusSchema, TaskPrioritySchema, TaskStatusSchema, TaskTypeSchema, TestResultValueSchema } from "./enums.schema.js";
3
- import { ChangeSchema, EmailSchema, IdSchema, PositionSchema, TimestampSchema } from "./entities.schema.js";
3
+ import { ChangeSchema, EmailSchema, IdSchema, MAX_OTHER_ANSWER_LENGTH, PositionSchema, TimestampSchema } from "./entities.schema.js";
4
4
  /** Corps des requêtes et des réponses de l'API des tâches de la GUI. */
5
5
  /** Taille maximale d'une pièce jointe : 20 Mo. */
6
6
  export const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
@@ -95,6 +95,18 @@ export const TaskRefSchema = z.object({ id: IdSchema, key: z.string(), title: z.
95
95
  /** `GET task-keys/:key` : espace du texte où la clé est écrite, préféré parmi ceux qui portent son préfixe. */
96
96
  export const TaskKeyQuerySchema = z.object({ spaceId: IdSchema.optional() }).strict();
97
97
  export const ChecklistItemViewSchema = z.object({ id: IdSchema, text: z.string(), done: z.boolean(), position: PositionSchema });
98
+ /** Proposition d'une question : libellé, détail en markdown, recommandation de l'agent, choix des membres. */
99
+ export const QuestionOptionViewSchema = z.object({ id: IdSchema, label: z.string(), detail: z.string(), recommended: z.boolean(), selected: z.boolean() });
100
+ /** Question posée par l'agent : propositions, réponse libre, et membre qui a répondu en dernier. */
101
+ export const QuestionViewSchema = z.object({
102
+ id: IdSchema,
103
+ text: z.string(),
104
+ multiple: z.boolean(),
105
+ options: z.array(QuestionOptionViewSchema),
106
+ otherAnswer: z.string().nullable(),
107
+ answeredBy: z.string().nullable(),
108
+ answeredAt: TimestampSchema.nullable(),
109
+ });
98
110
  /** Point à régler d'une demande traitée, tel que l'affichent la page Agent, sa modale et les commentaires d'une tâche. */
99
111
  export const FollowUpViewSchema = z.object({
100
112
  id: IdSchema,
@@ -195,6 +207,8 @@ export const TaskDetailResponseSchema = z.object({
195
207
  /** Tâche vérifiée par une tâche de test. */
196
208
  testedTask: TaskRefSchema.nullable(),
197
209
  children: z.array(TaskNodeSchema),
210
+ /** Questions posées par l'agent, dans l'ordre. */
211
+ questions: z.array(QuestionViewSchema),
198
212
  checklist: z.array(ChecklistItemViewSchema),
199
213
  /** Points de vérification, résultats et reviews d'une tâche de test ; null pour une tâche standard. */
200
214
  test: TestDetailSchema.nullable(),
@@ -236,6 +250,14 @@ export const AddChecklistItemRequestSchema = z.object({ text: ChecklistTextSchem
236
250
  export const UpdateChecklistItemRequestSchema = z
237
251
  .object({ text: ChecklistTextSchema.optional(), done: z.boolean().optional() })
238
252
  .refine((patch) => patch.text !== undefined || patch.done !== undefined, "Aucune modification demandée.");
253
+ /**
254
+ * Réponse à une question : propositions choisies et réponse libre, qui
255
+ * remplacent la réponse précédente ; un choix unique en prend une seule.
256
+ */
257
+ export const AnswerQuestionRequestSchema = z.object({
258
+ selectedOptionIds: z.array(IdSchema),
259
+ otherAnswer: z.string().max(MAX_OTHER_ANSWER_LENGTH, `La réponse dépasse ${MAX_OTHER_ANSWER_LENGTH} caractères.`).nullable(),
260
+ });
239
261
  /** Réordonnancement : élément après lequel se placer (null : en tête). */
240
262
  export const MoveAfterRequestSchema = z.object({ afterId: IdSchema.nullable() });
241
263
  export const CheckpointTextSchema = z.string().trim().min(1, "Le point de vérification est vide.").max(500);
@@ -34,6 +34,7 @@ export declare const BoardViewViewSchema: z.ZodObject<{
34
34
  }>>;
35
35
  assigneeIds: z.ZodArray<z.ZodString>;
36
36
  unassigned: z.ZodBoolean;
37
+ tagIds: z.ZodArray<z.ZodString>;
37
38
  id: z.ZodString;
38
39
  }, z.core.$strip>;
39
40
  export type BoardViewView = z.infer<typeof BoardViewViewSchema>;
@@ -71,6 +72,7 @@ export declare const BoardViewListResponseSchema: z.ZodObject<{
71
72
  }>>;
72
73
  assigneeIds: z.ZodArray<z.ZodString>;
73
74
  unassigned: z.ZodBoolean;
75
+ tagIds: z.ZodArray<z.ZodString>;
74
76
  id: z.ZodString;
75
77
  }, z.core.$strip>>;
76
78
  }, z.core.$strip>;
@@ -108,6 +110,7 @@ export declare const CreateBoardViewRequestSchema: z.ZodObject<{
108
110
  }>>;
109
111
  assigneeIds: z.ZodArray<z.ZodString>;
110
112
  unassigned: z.ZodBoolean;
113
+ tagIds: z.ZodArray<z.ZodString>;
111
114
  }, z.core.$strict>;
112
115
  export type CreateBoardViewRequest = z.infer<typeof CreateBoardViewRequestSchema>;
113
116
  /** Réglages à changer ; la vue obtenue doit rester valide. */
@@ -143,5 +146,6 @@ export declare const UpdateBoardViewRequestSchema: z.ZodObject<{
143
146
  }>>>;
144
147
  assigneeIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
145
148
  unassigned: z.ZodOptional<z.ZodBoolean>;
149
+ tagIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
146
150
  }, z.core.$strict>;
147
151
  export type UpdateBoardViewRequest = z.infer<typeof UpdateBoardViewRequestSchema>;
@@ -12,7 +12,8 @@ export const BoardViewNameSchema = z
12
12
  * sections ; `thenBy` : lignes d'une matrice ou sous-sections d'une liste),
13
13
  * groupes vides, filtres (vides : toutes les valeurs ; `assigneeIds` : membres
14
14
  * de l'espace dont la vue montre les tâches ; `unassigned` : la vue montre
15
- * aussi les tâches sans assigné).
15
+ * aussi les tâches sans assigné ; `tagIds` : tags de l'espace dont la vue
16
+ * montre les tâches).
16
17
  */
17
18
  const BoardViewSettingsSchema = z.object({
18
19
  name: BoardViewNameSchema,
@@ -24,6 +25,7 @@ const BoardViewSettingsSchema = z.object({
24
25
  priorities: z.array(TaskPrioritySchema),
25
26
  assigneeIds: z.array(IdSchema),
26
27
  unassigned: z.boolean(),
28
+ tagIds: z.array(IdSchema),
27
29
  });
28
30
  /** Vue du tableau de bord telle que l'affiche la GUI. */
29
31
  export const BoardViewViewSchema = BoardViewSettingsSchema.extend({ id: IdSchema });
@@ -0,0 +1,15 @@
1
+ import { type AgentQuestion } from "../../shared/schemas/agent-tools.schema.js";
2
+ import type { QuestionSnapshot } from "../../shared/schemas/entities.schema.js";
3
+ import type { Store } from "../core/store.js";
4
+ import { type AgentRoute } from "./types.js";
5
+ /**
6
+ * Questions d'une tâche : l'agent pose les questions et leurs propositions,
7
+ * les membres y répondent depuis le site. Les opérations s'appliquent en
8
+ * ordre, tout ou rien ; chacune est une action du lot sur la question.
9
+ */
10
+ export declare const questionRoutes: AgentRoute[];
11
+ /** Questions d'une tâche avec leurs propositions, dans l'ordre. */
12
+ export declare function questionsOf(store: Store, taskId: string): QuestionSnapshot[];
13
+ export declare function questionData(store: Store, question: QuestionSnapshot): AgentQuestion;
14
+ /** Questions rédigées pour l'agent : propositions avec leur identifiant et leur détail, réponse des membres. */
15
+ export declare function questionLines(store: Store, questions: readonly QuestionSnapshot[]): string[];
@@ -0,0 +1,128 @@
1
+ import { EditQuestionsBodySchema, QuestionsDataSchema } from "../../shared/schemas/agent-tools.schema.js";
2
+ import { actFor, ago, quote, resolveTask, taskData, taskKey, userLabel } from "../core/agent.js";
3
+ import { NotFoundError, OrganizerError } from "../core/errors.js";
4
+ import { parseInput, respond } from "./types.js";
5
+ /**
6
+ * Questions d'une tâche : l'agent pose les questions et leurs propositions,
7
+ * les membres y répondent depuis le site. Les opérations s'appliquent en
8
+ * ordre, tout ou rien ; chacune est une action du lot sur la question.
9
+ */
10
+ export const questionRoutes = [
11
+ {
12
+ method: "POST",
13
+ path: "/tasks/:ref/questions",
14
+ handle: ({ store }, { agent, params, body }) => {
15
+ const input = parseInput(EditQuestionsBodySchema, body);
16
+ const { task, outcomes } = actFor(store, agent, input.request_id, (tx, space) => {
17
+ const task = resolveTask(tx.store, space, params.ref);
18
+ return { task, outcomes: input.operations.map((operation) => apply(tx, task, operation)) };
19
+ });
20
+ const questions = questionsOf(store, task.id);
21
+ return respond(QuestionsDataSchema, `${taskKey(store, task)}: ${outcomes.join("; ")}.\n${questionLines(store, questions).join("\n")}`, {
22
+ task: taskData(store, task),
23
+ questions: questions.map((question) => questionData(store, question)),
24
+ });
25
+ },
26
+ },
27
+ ];
28
+ /** Questions d'une tâche avec leurs propositions, dans l'ordre. */
29
+ export function questionsOf(store, taskId) {
30
+ return store.listQuestions(taskId).map((question) => store.questionSnapshot(question.id));
31
+ }
32
+ export function questionData(store, question) {
33
+ const author = question.answeredBy === null ? null : store.findUser(question.answeredBy);
34
+ return {
35
+ id: question.id,
36
+ text: question.text,
37
+ multiple: question.multiple,
38
+ options: question.options.map(({ id, label, detail, recommended, selected }) => ({ id, label, detail, recommended, selected })),
39
+ otherAnswer: question.otherAnswer,
40
+ answeredBy: question.answeredBy === null ? null : author ? userLabel(author) : "a former member",
41
+ answeredAt: question.answeredAt,
42
+ };
43
+ }
44
+ /** Questions rédigées pour l'agent : propositions avec leur identifiant et leur détail, réponse des membres. */
45
+ export function questionLines(store, questions) {
46
+ const answered = questions.filter((question) => question.answeredAt !== null).length;
47
+ const lines = [`Questions (${answered}/${questions.length} answered):`];
48
+ if (questions.length === 0)
49
+ return [...lines, "(none)"];
50
+ questions.forEach((question, index) => {
51
+ const data = questionData(store, question);
52
+ lines.push(`${index + 1}. ${question.text} (${question.multiple ? "multiple choice" : "single choice"}, id ${question.id})`);
53
+ for (const option of question.options) {
54
+ lines.push(` - [${option.selected ? "x" : " "}] ${option.label} (${option.recommended ? "recommended, " : ""}id ${option.id})`);
55
+ for (const line of option.detail.split(/\r?\n/).filter((text) => text.trim() !== ""))
56
+ lines.push(` ${line}`);
57
+ }
58
+ if (question.otherAnswer !== null)
59
+ lines.push(` Free answer: ${question.otherAnswer}`);
60
+ lines.push(data.answeredAt === null ? " Not answered yet." : ` Answered by ${data.answeredBy}, ${ago(data.answeredAt)}.`);
61
+ });
62
+ return lines;
63
+ }
64
+ function requireQuestion(tx, task, questionId) {
65
+ const question = tx.store.findQuestionSnapshot(questionId);
66
+ if (!question || question.taskId !== task.id)
67
+ throw new NotFoundError(`Question ${questionId} is not in this task. Call get_task to get the question ids.`);
68
+ return question;
69
+ }
70
+ function requireOption(tx, task, optionId) {
71
+ const option = tx.store.findQuestionOption(optionId);
72
+ const question = option === null ? null : tx.store.findQuestionSnapshot(option.questionId);
73
+ if (!question || question.taskId !== task.id)
74
+ throw new NotFoundError(`Option ${optionId} is not in this task. Call get_task to get the option ids.`);
75
+ return question;
76
+ }
77
+ /** Applique une opération et l'enregistre dans le lot ; renvoie sa description pour la réponse. */
78
+ function apply(tx, task, operation) {
79
+ const record = (operationType, before, after, summary) => tx.recordAgentAction({ entityType: "task_question", entityId: (after ?? before).id, operation: operationType, before, after, summary, taskId: task.id });
80
+ switch (operation.action) {
81
+ case "add_question": {
82
+ const question = tx.addQuestion(task.id, { text: operation.text, multiple: operation.multiple ?? false, options: operation.options });
83
+ record("create", null, question, `Question posée : ${quote(question.text)}`);
84
+ return `added question ${question.id}`;
85
+ }
86
+ case "update_question": {
87
+ if (operation.text === undefined && operation.multiple === undefined)
88
+ throw new OrganizerError(`Nothing to update on question ${operation.question_id}: give text or multiple.`);
89
+ const before = requireQuestion(tx, task, operation.question_id);
90
+ const after = tx.updateQuestion(before.id, { text: operation.text, multiple: operation.multiple });
91
+ const parts = [];
92
+ if (after.text !== before.text)
93
+ parts.push(`Question ${quote(before.text)} reformulée en ${quote(after.text)}`);
94
+ if (after.multiple !== before.multiple)
95
+ parts.push(`Question ${quote(after.text)} : ${after.multiple ? "plusieurs choix" : "un seul choix"}`);
96
+ record("update", before, after, parts.join(" · ") || `Question ${quote(after.text)} inchangée`);
97
+ return `updated question ${after.id}`;
98
+ }
99
+ case "delete_question": {
100
+ const before = requireQuestion(tx, task, operation.question_id);
101
+ tx.deleteQuestion(before.id);
102
+ record("delete", before, null, `Question supprimée : ${quote(before.text)}`);
103
+ return `deleted question ${before.id}`;
104
+ }
105
+ case "add_option": {
106
+ const before = requireQuestion(tx, task, operation.question_id);
107
+ const option = tx.addQuestionOption(before.id, { label: operation.label, detail: operation.detail, recommended: operation.recommended });
108
+ record("update", before, tx.store.questionSnapshot(before.id), `Proposition ${quote(option.label)} ajoutée à ${quote(before.text)}`);
109
+ return `added option ${option.id} to question ${before.id}`;
110
+ }
111
+ case "update_option": {
112
+ if (operation.label === undefined && operation.detail === undefined && operation.recommended === undefined) {
113
+ throw new OrganizerError(`Nothing to update on option ${operation.option_id}: give label, detail or recommended.`);
114
+ }
115
+ const before = requireOption(tx, task, operation.option_id);
116
+ const option = tx.updateQuestionOption(operation.option_id, { label: operation.label, detail: operation.detail, recommended: operation.recommended });
117
+ record("update", before, tx.store.questionSnapshot(before.id), `Proposition ${quote(option.label)} de ${quote(before.text)} modifiée`);
118
+ return `updated option ${option.id}`;
119
+ }
120
+ case "delete_option": {
121
+ const before = requireOption(tx, task, operation.option_id);
122
+ const label = before.options.find((option) => option.id === operation.option_id).label;
123
+ tx.deleteQuestionOption(operation.option_id);
124
+ record("update", before, tx.store.questionSnapshot(before.id), `Proposition ${quote(label)} retirée de ${quote(before.text)}`);
125
+ return `deleted option ${operation.option_id}`;
126
+ }
127
+ }
128
+ }
@@ -1,6 +1,7 @@
1
1
  import { resolveAgentToken } from "../core/agent-tokens.js";
2
2
  import { NotFoundError, OrganizerError } from "../core/errors.js";
3
3
  import { checklistRoutes } from "./checklist.js";
4
+ import { questionRoutes } from "./questions.js";
4
5
  import { ideaRoutes } from "./ideas.js";
5
6
  import { notificationRoutes } from "./notifications.js";
6
7
  import { requestRoutes } from "./requests.js";
@@ -14,7 +15,7 @@ function compile(route) {
14
15
  });
15
16
  return { route, pattern: new RegExp(`^${source}$`), keys };
16
17
  }
17
- const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...ideaRoutes, ...viewRoutes, ...notificationRoutes].map(compile);
18
+ const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...questionRoutes, ...ideaRoutes, ...viewRoutes, ...notificationRoutes].map(compile);
18
19
  /** Segment de chemin décodé ; un encodage `%` invalide est une erreur 400. */
19
20
  function decodeSegment(raw) {
20
21
  try {
@@ -2,6 +2,7 @@ import { AddCommentBodySchema, CommentDataSchema, ContextDataSchema, CreateTaskB
2
2
  import { combinedResult } from "../../shared/logic/test-summary.js";
3
3
  import { actFor, ago, assigneesSummary, createdTaskSummary, ideaData, memberData, recentIdeas, requireText, resolveMembers, resolveTask, spaceContextLines, spaceData, taskData, taskKey, taskUpdateSummary, treeData, userLabel, } from "../core/agent.js";
4
4
  import { OrganizerError } from "../core/errors.js";
5
+ import { questionData, questionLines, questionsOf } from "./questions.js";
5
6
  import { parseInput, respond } from "./types.js";
6
7
  /** Espace du jeton et ses tâches : contexte, lecture, recherche, création, modification, assignés, tags, commentaires. */
7
8
  /** Nombre de commentaires récents affichés par get_task. */
@@ -55,6 +56,9 @@ export const taskRoutes = [
55
56
  lines.push(`Tags: ${summary.tags.length > 0 ? summary.tags.join(", ") : "none"}`);
56
57
  lines.push(`Created by ${name(task.createdBy)} ${ago(task.createdAt)}, updated ${ago(task.updatedAt)}.`);
57
58
  lines.push("", "Description:", task.description.trim() === "" ? "(empty)" : task.description);
59
+ const questions = questionsOf(store, task.id);
60
+ if (questions.length > 0)
61
+ lines.push("", ...questionLines(store, questions));
58
62
  const checklist = task.type === "standard" ? store.listChecklist(task.id) : [];
59
63
  const checkpoints = [];
60
64
  if (task.type === "standard") {
@@ -102,6 +106,7 @@ export const taskRoutes = [
102
106
  testedTaskKey: tested ? taskKey(store, tested) : null,
103
107
  checklist: checklist.map((item) => ({ id: item.id, text: item.text, done: item.done })),
104
108
  checkpoints,
109
+ questions: questions.map((question) => questionData(store, question)),
105
110
  children: children.map((child) => taskData(store, child)),
106
111
  comments: comments.map((comment) => ({
107
112
  id: comment.id,
@@ -53,9 +53,29 @@ function resolveView(store, author, space, viewId) {
53
53
  }
54
54
  return view;
55
55
  }
56
- function viewData(view) {
56
+ /** Noms des tags filtrés par une vue, dans l'ordre alphabétique des tags de l'espace. */
57
+ function tagNames(store, view) {
58
+ return store
59
+ .listTags(view.spaceId)
60
+ .filter((tag) => view.tagIds.includes(tag.id))
61
+ .map((tag) => tag.name);
62
+ }
63
+ function viewData(store, view) {
57
64
  const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned } = view;
58
- return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned };
65
+ return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tags: tagNames(store, view) };
66
+ }
67
+ /** Tags de l'espace désignés par leur nom (sans la casse) ou leur identifiant ; un tag inconnu est refusé. */
68
+ function resolveTags(store, space, refs) {
69
+ const tags = store.listTags(space.id);
70
+ return refs.map((ref) => {
71
+ const trimmed = ref.trim();
72
+ const tag = tags.find((candidate) => candidate.id === trimmed || candidate.name.toLowerCase() === trimmed.toLowerCase());
73
+ if (!tag) {
74
+ const known = tags.length > 0 ? `Its tags: ${tags.map((candidate) => `"${candidate.name}"`).join(", ")}.` : "It has no tag: a view filters only on the tags its tasks carry.";
75
+ throw new InvariantError(`"${trimmed}" is not a tag of "${space.name}". ${known}`);
76
+ }
77
+ return tag.id;
78
+ });
59
79
  }
60
80
  function ownerData(author) {
61
81
  return { id: author.id, name: userLabel(author), email: author.email };
@@ -73,10 +93,11 @@ function viewLine(store, view) {
73
93
  `statuses ${view.statuses.length > 0 ? view.statuses.join(", ") : "all"}`,
74
94
  `priorities ${view.priorities.length > 0 ? view.priorities.join(", ") : "all"}`,
75
95
  `assignees ${assignees.length > 0 ? assignees.join(", ") : "all"}`,
96
+ `tags ${view.tagIds.length > 0 ? tagNames(store, view).join(", ") : "all"}`,
76
97
  ];
77
98
  return `- ${view.id} "${view.name}": ${view.layout} ${grouping}, empty groups ${view.showEmptyGroups ? "shown" : "hidden"}; ${filters.join("; ")}`;
78
99
  }
79
- /** Réglages passés par l'agent, au format du modèle ; les assignés sont résolus parmi les membres. */
100
+ /** Réglages passés par l'agent, au format du modèle ; les assignés sont résolus parmi les membres, les tags parmi ceux de l'espace. */
80
101
  function settingsPatch(store, space, input) {
81
102
  return {
82
103
  name: input.name === undefined ? undefined : requireText(input.name, "name"),
@@ -88,6 +109,7 @@ function settingsPatch(store, space, input) {
88
109
  priorities: input.priorities,
89
110
  assigneeIds: input.assignees === undefined ? undefined : resolveMembers(store, space, input.assignees).map((user) => user.id),
90
111
  unassigned: input.unassigned,
112
+ tagIds: input.tags === undefined ? undefined : resolveTags(store, space, input.tags),
91
113
  };
92
114
  }
93
115
  /** Résumé français des réglages changés d'une vue. */
@@ -110,6 +132,8 @@ function viewUpdateSummary(before, after) {
110
132
  }
111
133
  if (JSON.stringify(before.assigneeIds) !== JSON.stringify(after.assigneeIds) || before.unassigned !== after.unassigned)
112
134
  parts.push("Filtre des assignés modifié");
135
+ if (JSON.stringify(before.tagIds) !== JSON.stringify(after.tagIds))
136
+ parts.push("Filtre des tags modifié");
113
137
  return `Vue ${quote(before.name)} : ${parts.join(" · ") || "inchangée"}`;
114
138
  }
115
139
  export const viewRoutes = [
@@ -122,7 +146,7 @@ export const viewRoutes = [
122
146
  const views = store.listBoardViews(space.id, author.id);
123
147
  const header = `Board views of ${userLabel(author)} <${author.email}> in "${space.name}", in the order of their tabs:`;
124
148
  const lines = views.length > 0 ? views.map((view) => viewLine(store, view)) : ["(none yet: they get the default views \"Tableau\" and \"Liste\" when they open the board, or when you create a view)"];
125
- return respond(ViewsDataSchema, [header, ...lines].join("\n"), { owner: ownerData(author), views: views.map(viewData) });
149
+ return respond(ViewsDataSchema, [header, ...lines].join("\n"), { owner: ownerData(author), views: views.map((view) => viewData(store, view)) });
126
150
  },
127
151
  },
128
152
  {
@@ -145,6 +169,7 @@ export const viewRoutes = [
145
169
  priorities: patch.priorities ?? [],
146
170
  assigneeIds: patch.assigneeIds ?? [],
147
171
  unassigned: patch.unassigned ?? false,
172
+ tagIds: patch.tagIds ?? [],
148
173
  };
149
174
  requireGroupings(settings);
150
175
  ensureBoardViews(tx, space.id, author.id);
@@ -162,7 +187,7 @@ export const viewRoutes = [
162
187
  });
163
188
  return respond(ViewDataSchema, `Created view ${created.id} "${created.name}" for ${userLabel(author)}; their open dashboard switches to it.\n${viewLine(store, created)}`, {
164
189
  owner: ownerData(author),
165
- view: viewData(created),
190
+ view: viewData(store, created),
166
191
  });
167
192
  },
168
193
  },
@@ -185,7 +210,7 @@ export const viewRoutes = [
185
210
  });
186
211
  return respond(ViewDataSchema, `Updated view ${updated.id} of ${userLabel(author)}; their open dashboard switches to it.\n${viewLine(store, updated)}`, {
187
212
  owner: ownerData(author),
188
- view: viewData(updated),
213
+ view: viewData(store, updated),
189
214
  });
190
215
  },
191
216
  },
@@ -204,7 +229,7 @@ export const viewRoutes = [
204
229
  tx.recordAgentAction({ entityType: "board_view", entityId: view.id, operation: "delete", before: view, after: null, summary: `Vue ${quote(view.name)} supprimée`, taskId: null });
205
230
  return view;
206
231
  });
207
- return respond(ViewDataSchema, `Deleted view ${deleted.id} "${deleted.name}" of ${userLabel(author)}.`, { owner: ownerData(author), view: viewData(deleted) });
232
+ return respond(ViewDataSchema, `Deleted view ${deleted.id} "${deleted.name}" of ${userLabel(author)}.`, { owner: ownerData(author), view: viewData(store, deleted) });
208
233
  },
209
234
  },
210
235
  ];
@@ -8,18 +8,23 @@ import { requireMember } from "./spaces.js";
8
8
  const asUser = (userId) => ({ type: "user", userId });
9
9
  /** Vues créées pour un membre qui n'en a aucune : le Kanban et la liste par statut, sans filtre. */
10
10
  export const DEFAULT_BOARD_VIEWS = [
11
- { name: "Tableau", layout: "kanban", groupBy: "status", thenBy: "none", showEmptyGroups: true, statuses: [], priorities: [], assigneeIds: [], unassigned: false },
12
- { name: "Liste", layout: "list", groupBy: "status", thenBy: "none", showEmptyGroups: false, statuses: [], priorities: [], assigneeIds: [], unassigned: false },
11
+ { name: "Tableau", layout: "kanban", groupBy: "status", thenBy: "none", showEmptyGroups: true, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [] },
12
+ { name: "Liste", layout: "list", groupBy: "status", thenBy: "none", showEmptyGroups: false, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [] },
13
13
  ];
14
14
  function viewOf(view) {
15
- const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned } = view;
16
- return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned };
15
+ const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds } = view;
16
+ return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds };
17
17
  }
18
18
  /** Assignés d'une vue : des membres de l'espace. */
19
19
  function requireAssignees(store, spaceId, assigneeIds) {
20
20
  if (assigneeIds?.some((id) => !store.isMember(spaceId, id)))
21
21
  throw new OrganizerError("Une vue ne filtre que sur des membres de l'espace.");
22
22
  }
23
+ /** Tags d'une vue : des tags de l'espace. */
24
+ function requireTags(store, spaceId, tagIds) {
25
+ if (tagIds?.some((id) => store.findTag(id)?.spaceId !== spaceId))
26
+ throw new OrganizerError("Une vue ne filtre que sur des tags de l'espace.");
27
+ }
23
28
  /** Vue de l'utilisateur ; celle d'un autre reçoit la même réponse qu'une vue inexistante. */
24
29
  function requireOwnView(store, viewId, userId) {
25
30
  const view = store.findBoardView(viewId);
@@ -83,6 +88,7 @@ export function createBoardView(store, userId, spaceId, input) {
83
88
  const view = store.mutate(asUser(userId), (tx) => {
84
89
  requireMember(tx.store, spaceId, userId);
85
90
  requireAssignees(tx.store, spaceId, input.assigneeIds);
91
+ requireTags(tx.store, spaceId, input.tagIds);
86
92
  return tx.createBoardView(spaceId, userId, input);
87
93
  });
88
94
  return viewOf(view);
@@ -93,6 +99,7 @@ export function updateBoardView(store, userId, viewId, patch) {
93
99
  const current = requireOwnView(tx.store, viewId, userId);
94
100
  requireGroupings({ layout: patch.layout ?? current.layout, groupBy: patch.groupBy ?? current.groupBy, thenBy: patch.thenBy ?? current.thenBy });
95
101
  requireAssignees(tx.store, current.spaceId, patch.assigneeIds);
102
+ requireTags(tx.store, current.spaceId, patch.tagIds);
96
103
  return tx.updateBoardView(viewId, patch);
97
104
  });
98
105
  return viewOf(view);