@imenam/mcp-organizer 1.0.16 → 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.
@@ -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,
@@ -1,6 +1,6 @@
1
1
  import { ForbiddenError, InvariantError, NotFoundError } from "./errors.js";
2
2
  import { CheckpointSnapshotSchema, isTracked, snapshotOf, taskIdOfAction } from "./snapshots.js";
3
- import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, CommentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
3
+ import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotSchema, CommentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
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
@@ -19,6 +19,10 @@ function comparable(entityType, snapshot) {
19
19
  const item = ChecklistItemSchema.parse(snapshot);
20
20
  return [item.text, item.done];
21
21
  }
22
+ case "task_question": {
23
+ const { text, multiple, otherAnswer, options } = QuestionSnapshotSchema.parse(snapshot);
24
+ return [text, multiple, otherAnswer, options.map(({ id, label, detail, recommended, selected }) => [id, label, detail, recommended, selected])];
25
+ }
22
26
  case "test_checkpoint":
23
27
  return [TestCheckpointSchema.parse(snapshot).text];
24
28
  case "comment":
@@ -51,6 +55,8 @@ function describe(store, entityType, snapshot) {
51
55
  }
52
56
  case "checklist_item":
53
57
  return { label: `L'élément de checklist « ${ChecklistItemSchema.parse(snapshot).text} »`, feminine: false };
58
+ case "task_question":
59
+ return { label: `La question « ${excerpt(QuestionSnapshotSchema.parse(snapshot).text)} »`, feminine: true };
54
60
  case "test_checkpoint":
55
61
  return { label: `Le point de vérification « ${TestCheckpointSchema.parse(snapshot).text} »`, feminine: false };
56
62
  case "comment":
@@ -141,6 +147,7 @@ function remove(tx, entityType, current, label) {
141
147
  const dependents = [
142
148
  [store.listChildren(task.id).length, "des sous-tâches"],
143
149
  [store.listChecklist(task.id).length, "une checklist"],
150
+ [store.listQuestions(task.id).length, "des questions"],
144
151
  [store.listCheckpoints(task.id).length, "des points de vérification"],
145
152
  [store.listComments(task.id).length, "des commentaires"],
146
153
  [store.listAttachments(task.id).length, "des pièces jointes"],
@@ -155,6 +162,9 @@ function remove(tx, entityType, current, label) {
155
162
  case "checklist_item":
156
163
  tx.deleteChecklistItem(ChecklistItemSchema.parse(current).id);
157
164
  return;
165
+ case "task_question":
166
+ tx.deleteQuestion(QuestionSnapshotSchema.parse(current).id);
167
+ return;
158
168
  case "test_checkpoint": {
159
169
  const checkpoint = CheckpointSnapshotSchema.parse(current);
160
170
  if (checkpoint.results.length > 0)
@@ -188,6 +198,13 @@ function recreate(tx, entityType, before) {
188
198
  tx.restoreChecklistItem(item);
189
199
  return;
190
200
  }
201
+ case "task_question": {
202
+ const question = QuestionSnapshotSchema.parse(before);
203
+ if (!tx.store.findTask(question.taskId))
204
+ throw new InvariantError(`La tâche de la question « ${excerpt(question.text)} » n'existe plus : rien à recréer.`);
205
+ tx.restoreQuestion(question);
206
+ return;
207
+ }
191
208
  case "test_checkpoint": {
192
209
  const checkpoint = CheckpointSnapshotSchema.parse(before);
193
210
  if (!tx.store.findTask(checkpoint.taskId))
@@ -219,6 +236,9 @@ function restore(tx, entityType, entityId, before) {
219
236
  tx.updateChecklistItem(entityId, { text: item.text, done: item.done });
220
237
  return;
221
238
  }
239
+ case "task_question":
240
+ tx.replaceQuestion(QuestionSnapshotSchema.parse(before));
241
+ return;
222
242
  case "test_checkpoint":
223
243
  tx.updateCheckpoint(entityId, TestCheckpointSchema.parse(before).text);
224
244
  return;
@@ -577,6 +577,30 @@ export const MIGRATIONS = [
577
577
  ALTER TABLE board_views ADD COLUMN tag_ids TEXT NOT NULL DEFAULT '[]';
578
578
  UPDATE agent_actions SET before = json_set(before, '$.tagIds', json('[]')) WHERE entity_type = 'board_view' AND before IS NOT NULL;
579
579
  UPDATE agent_actions SET after = json_set(after, '$.tagIds', json('[]')) WHERE entity_type = 'board_view' AND after IS NOT NULL;
580
+ `,
581
+ // Questions posées par l'agent dans une tâche, leurs propositions et la réponse des membres.
582
+ `
583
+ CREATE TABLE task_questions (
584
+ id TEXT PRIMARY KEY,
585
+ task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
586
+ text TEXT NOT NULL CHECK (text <> ''),
587
+ multiple INTEGER NOT NULL DEFAULT 0 CHECK (multiple IN (0, 1)),
588
+ other_answer TEXT CHECK (other_answer IS NULL OR other_answer <> ''),
589
+ answered_by TEXT REFERENCES users(id) ON DELETE SET NULL,
590
+ answered_at TEXT,
591
+ position REAL NOT NULL
592
+ );
593
+ CREATE INDEX task_questions_task ON task_questions(task_id, position);
594
+ CREATE TABLE question_options (
595
+ id TEXT PRIMARY KEY,
596
+ question_id TEXT NOT NULL REFERENCES task_questions(id) ON DELETE CASCADE,
597
+ label TEXT NOT NULL CHECK (label <> ''),
598
+ detail TEXT NOT NULL DEFAULT '',
599
+ recommended INTEGER NOT NULL DEFAULT 0 CHECK (recommended IN (0, 1)),
600
+ selected INTEGER NOT NULL DEFAULT 0 CHECK (selected IN (0, 1)),
601
+ position REAL NOT NULL
602
+ );
603
+ CREATE INDEX question_options_question ON question_options(question_id, position);
580
604
  `,
581
605
  ];
582
606
  /** Version du schéma attendue par ce code. */
@@ -0,0 +1,13 @@
1
+ import type { Store } from "./store.js";
2
+ import type { QuestionSnapshot } from "../../shared/schemas/entities.schema.js";
3
+ import type { AnswerQuestionRequest, QuestionView } from "../../shared/schemas/tasks-api.schema.js";
4
+ /**
5
+ * Questions d'une tâche côté site : l'agent les pose, tout membre de l'espace
6
+ * y répond. Une réponse est enregistrée sans rien envoyer à l'agent, qui la
7
+ * lit quand il consulte la tâche.
8
+ */
9
+ export declare function questionView(store: Store, question: QuestionSnapshot): QuestionView;
10
+ /** Questions d'une tâche, dans l'ordre. */
11
+ export declare function questionViews(store: Store, taskId: string): QuestionView[];
12
+ /** Enregistre la réponse d'un membre de l'espace de la tâche ; une question introuvable ou hors de ses espaces reçoit la même réponse. */
13
+ export declare function answerQuestion(store: Store, userId: string, questionId: string, answer: AnswerQuestionRequest): QuestionView;
@@ -0,0 +1,33 @@
1
+ import { NotFoundError } from "./errors.js";
2
+ /**
3
+ * Questions d'une tâche côté site : l'agent les pose, tout membre de l'espace
4
+ * y répond. Une réponse est enregistrée sans rien envoyer à l'agent, qui la
5
+ * lit quand il consulte la tâche.
6
+ */
7
+ export function questionView(store, question) {
8
+ const author = question.answeredBy === null ? null : store.findUser(question.answeredBy);
9
+ return {
10
+ id: question.id,
11
+ text: question.text,
12
+ multiple: question.multiple,
13
+ options: question.options.map(({ id, label, detail, recommended, selected }) => ({ id, label, detail, recommended, selected })),
14
+ otherAnswer: question.otherAnswer,
15
+ answeredBy: author ? (author.displayName ?? author.email) : null,
16
+ answeredAt: question.answeredAt,
17
+ };
18
+ }
19
+ /** Questions d'une tâche, dans l'ordre. */
20
+ export function questionViews(store, taskId) {
21
+ return store.listQuestions(taskId).map((question) => questionView(store, store.questionSnapshot(question.id)));
22
+ }
23
+ /** Enregistre la réponse d'un membre de l'espace de la tâche ; une question introuvable ou hors de ses espaces reçoit la même réponse. */
24
+ export function answerQuestion(store, userId, questionId, answer) {
25
+ const question = store.mutate({ type: "user", userId }, (tx) => {
26
+ const current = tx.store.findQuestion(questionId);
27
+ const task = current === null ? null : tx.store.findTask(current.taskId);
28
+ if (!current || !task || !tx.store.isMember(task.spaceId, userId))
29
+ throw new NotFoundError("Question introuvable.");
30
+ return tx.answerQuestion(questionId, answer, userId);
31
+ });
32
+ return questionView(store, question);
33
+ }
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import type { Store } from "./store.js";
3
3
  import type { EntityType } from "../../shared/schemas/enums.schema.js";
4
- import { type AgentAction, type BoardView, type ChecklistItem, type Comment, type FollowUp, type Idea, type TaskSnapshot } from "../../shared/schemas/entities.schema.js";
4
+ import { type AgentAction, type BoardView, type ChecklistItem, type Comment, type FollowUp, type Idea, type QuestionSnapshot, type TaskSnapshot } from "../../shared/schemas/entities.schema.js";
5
5
  /** Instantanés des entités que l'agent modifie : l'état avant et après chaque action de son lot. */
6
6
  /** Point de vérification avec les résultats saisis dessus. */
7
7
  export declare const CheckpointSnapshotSchema: z.ZodObject<{
@@ -24,9 +24,9 @@ export declare const CheckpointSnapshotSchema: z.ZodObject<{
24
24
  }, z.core.$strip>;
25
25
  export type CheckpointSnapshot = z.infer<typeof CheckpointSnapshotSchema>;
26
26
  /** Entités dont l'agent enregistre l'état avant et après chaque action. */
27
- export type TrackedEntityType = "task" | "checklist_item" | "test_checkpoint" | "comment" | "idea" | "board_view" | "follow_up";
27
+ export type TrackedEntityType = "task" | "checklist_item" | "task_question" | "test_checkpoint" | "comment" | "idea" | "board_view" | "follow_up";
28
28
  export declare function isTracked(entityType: EntityType): entityType is TrackedEntityType;
29
29
  /** Instantané courant d'une entité, ou null si elle n'existe pas. */
30
- export declare function snapshotOf(store: Store, entityType: TrackedEntityType, entityId: string): TaskSnapshot | ChecklistItem | CheckpointSnapshot | Comment | Idea | BoardView | FollowUp | null;
30
+ export declare function snapshotOf(store: Store, entityType: TrackedEntityType, entityId: string): TaskSnapshot | ChecklistItem | QuestionSnapshot | CheckpointSnapshot | Comment | Idea | BoardView | FollowUp | null;
31
31
  /** Tâche concernée par une action : la tâche elle-même, ou celle qui porte l'élément ; null pour une idée, une vue ou un point à régler. */
32
32
  export declare function taskIdOfAction(action: Pick<AgentAction, "entityType" | "entityId" | "before" | "after">): string | null;
@@ -3,7 +3,7 @@ import { TestCheckpointSchema, TestResultSchema } from "../../shared/schemas/ent
3
3
  /** Instantanés des entités que l'agent modifie : l'état avant et après chaque action de son lot. */
4
4
  /** Point de vérification avec les résultats saisis dessus. */
5
5
  export const CheckpointSnapshotSchema = TestCheckpointSchema.extend({ results: z.array(TestResultSchema) });
6
- const TRACKED = new Set(["task", "checklist_item", "test_checkpoint", "comment", "idea", "board_view", "follow_up"]);
6
+ const TRACKED = new Set(["task", "checklist_item", "task_question", "test_checkpoint", "comment", "idea", "board_view", "follow_up"]);
7
7
  export function isTracked(entityType) {
8
8
  return TRACKED.has(entityType);
9
9
  }
@@ -14,6 +14,8 @@ export function snapshotOf(store, entityType, entityId) {
14
14
  return store.findTask(entityId) ? store.taskSnapshot(entityId) : null;
15
15
  case "checklist_item":
16
16
  return store.findChecklistItem(entityId);
17
+ case "task_question":
18
+ return store.findQuestionSnapshot(entityId);
17
19
  case "test_checkpoint": {
18
20
  const checkpoint = store.findCheckpoint(entityId);
19
21
  if (!checkpoint)
@@ -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 BoardView, type Change, type ChecklistItem, type Comment, type EntityVersion, type FollowUp, type Idea, type Invitation, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings } from "../../shared/schemas/entities.schema.js";
4
+ import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRequest, type AgentToken, type Attachment, type BoardView, type Change, type ChecklistItem, type Comment, type QuestionOption, type QuestionSnapshot, type TaskQuestion, type EntityVersion, type FollowUp, type Idea, type Invitation, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings } from "../../shared/schemas/entities.schema.js";
5
5
  import { type RunnerSessionRecord, type RunnerSettings } from "../../shared/schemas/admin-api.schema.js";
6
6
  /**
7
7
  * Auteur d'une mutation : un utilisateur de la GUI, ou un agent qui agit avec
@@ -114,6 +114,16 @@ export declare class Store {
114
114
  findChecklistItem(id: string): ChecklistItem | null;
115
115
  getChecklistItem(id: string): ChecklistItem;
116
116
  listChecklist(taskId: string): ChecklistItem[];
117
+ findQuestion(id: string): TaskQuestion | null;
118
+ getQuestion(id: string): TaskQuestion;
119
+ /** Questions d'une tâche, dans l'ordre. */
120
+ listQuestions(taskId: string): TaskQuestion[];
121
+ findQuestionOption(id: string): QuestionOption | null;
122
+ /** Propositions d'une question, dans l'ordre. */
123
+ listQuestionOptions(questionId: string): QuestionOption[];
124
+ /** Question et ses propositions, ou null si elle n'existe pas. */
125
+ findQuestionSnapshot(id: string): QuestionSnapshot | null;
126
+ questionSnapshot(id: string): QuestionSnapshot;
117
127
  findCheckpoint(id: string): TestCheckpoint | null;
118
128
  getCheckpoint(id: string): TestCheckpoint;
119
129
  /** Points de vérification d'une tâche de test, dans l'ordre. */
@@ -311,6 +321,12 @@ export interface UpdateIdeaInput {
311
321
  promotedTaskId?: string | null;
312
322
  archived?: boolean;
313
323
  }
324
+ /** Proposition d'une question à créer. */
325
+ export interface QuestionOptionInput {
326
+ label: string;
327
+ detail?: string;
328
+ recommended?: boolean;
329
+ }
314
330
  /** Réglages d'une vue du tableau de bord. */
315
331
  export interface BoardViewSettings {
316
332
  name: string;
@@ -491,6 +507,43 @@ export declare class Mutation {
491
507
  /** Remplace les tags d'une tâche ; un nom absent de l'espace y crée le tag (noms comparés sans la casse). */
492
508
  setTags(taskId: string, names: readonly string[]): Tag[];
493
509
  private createTag;
510
+ /** Ajoute une question en fin de liste d'une tâche, avec ses propositions dans l'ordre donné. */
511
+ addQuestion(taskId: string, input: {
512
+ text: string;
513
+ multiple: boolean;
514
+ options: readonly QuestionOptionInput[];
515
+ }): QuestionSnapshot;
516
+ /** Change le texte d'une question ou son type de choix ; un choix unique n'accepte qu'une réponse. */
517
+ updateQuestion(id: string, patch: {
518
+ text?: string;
519
+ multiple?: boolean;
520
+ }): QuestionSnapshot;
521
+ deleteQuestion(id: string): void;
522
+ /** Ajoute une proposition en fin de question. */
523
+ addQuestionOption(questionId: string, input: QuestionOptionInput): QuestionOption;
524
+ updateQuestionOption(id: string, patch: {
525
+ label?: string;
526
+ detail?: string;
527
+ recommended?: boolean;
528
+ }): QuestionOption;
529
+ deleteQuestionOption(id: string): void;
530
+ /**
531
+ * Réponse d'un membre : les propositions choisies et la réponse libre
532
+ * remplacent les précédentes. Une réponse vide efface l'auteur et la date.
533
+ */
534
+ answerQuestion(id: string, answer: {
535
+ selectedOptionIds: readonly string[];
536
+ otherAnswer: string | null;
537
+ }, userId: string): QuestionSnapshot;
538
+ /** Recrée une question supprimée, avec ses identifiants, ses propositions et sa réponse. */
539
+ restoreQuestion(snapshot: QuestionSnapshot): void;
540
+ /** Ramène une question à un état enregistré : texte, type de choix, réponse et propositions. */
541
+ replaceQuestion(snapshot: QuestionSnapshot): void;
542
+ private insertQuestion;
543
+ private insertQuestionOption;
544
+ /** Un choix unique a pour réponse une seule proposition ou la réponse libre. */
545
+ private requireSingleAnswer;
546
+ private touchQuestion;
494
547
  /** Ajoute un élément en fin de checklist d'une tâche standard. */
495
548
  addChecklistItem(taskId: string, text: string): ChecklistItem;
496
549
  updateChecklistItem(id: string, patch: {