@imenam/mcp-organizer 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +57 -19
  2. package/dist/shared/schemas/agent-api.schema.d.ts +40 -2
  3. package/dist/shared/schemas/agent-api.schema.js +12 -3
  4. package/dist/shared/schemas/agent-tools.schema.d.ts +373 -6
  5. package/dist/shared/schemas/agent-tools.schema.js +54 -3
  6. package/dist/shared/schemas/api.schema.d.ts +26 -0
  7. package/dist/shared/schemas/api.schema.js +9 -0
  8. package/dist/shared/schemas/entities.schema.d.ts +38 -4
  9. package/dist/shared/schemas/entities.schema.js +33 -5
  10. package/dist/shared/schemas/enums.schema.d.ts +4 -2
  11. package/dist/shared/schemas/enums.schema.js +2 -1
  12. package/dist/shared/schemas/notifications-api.schema.d.ts +29 -7
  13. package/dist/shared/schemas/notifications-api.schema.js +21 -5
  14. package/dist/shared/schemas/tasks-api.schema.d.ts +112 -0
  15. package/dist/shared/schemas/tasks-api.schema.js +43 -0
  16. package/dist/shared/schemas/views-api.schema.d.ts +8 -0
  17. package/dist/shared/schemas/views-api.schema.js +5 -1
  18. package/dist/src/agent-api/requests.d.ts +1 -1
  19. package/dist/src/agent-api/requests.js +56 -4
  20. package/dist/src/agent-api/router.js +2 -1
  21. package/dist/src/agent-api/views.d.ts +2 -0
  22. package/dist/src/agent-api/views.js +203 -0
  23. package/dist/src/core/agent.d.ts +5 -1
  24. package/dist/src/core/agent.js +61 -2
  25. package/dist/src/core/board-views.d.ts +11 -1
  26. package/dist/src/core/board-views.js +39 -15
  27. package/dist/src/core/follow-ups.d.ts +7 -0
  28. package/dist/src/core/follow-ups.js +15 -0
  29. package/dist/src/core/history.d.ts +2 -1
  30. package/dist/src/core/history.js +62 -3
  31. package/dist/src/core/migrations.js +482 -421
  32. package/dist/src/core/notifications.js +36 -9
  33. package/dist/src/core/requests.d.ts +10 -1
  34. package/dist/src/core/requests.js +41 -3
  35. package/dist/src/core/snapshots.d.ts +4 -4
  36. package/dist/src/core/snapshots.js +6 -2
  37. package/dist/src/core/spaces.d.ts +2 -2
  38. package/dist/src/core/spaces.js +12 -6
  39. package/dist/src/core/store.d.ts +45 -6
  40. package/dist/src/core/store.js +214 -75
  41. package/dist/src/core/tasks.d.ts +22 -2
  42. package/dist/src/core/tasks.js +121 -12
  43. package/dist/src/gui-api.js +14 -4
  44. package/dist/src/mcp/start.d.ts +1 -1
  45. package/dist/src/mcp/start.js +4 -3
  46. package/dist/src/mcp/tools.js +86 -2
  47. package/dist/src/server/runner.js +4 -18
  48. package/gui/dist/assets/index-CVwckTU6.css +1 -0
  49. package/gui/dist/assets/index-G5uiHeLf.js +99 -0
  50. package/gui/dist/index.html +3 -3
  51. package/package.json +1 -1
  52. package/gui/dist/assets/index-CsMeMdCn.css +0 -1
  53. package/gui/dist/assets/index-DAGRLFSo.js +0 -98
@@ -10,7 +10,9 @@ export const BoardViewNameSchema = z
10
10
  /**
11
11
  * Réglages d'une vue : nom, disposition, regroupements (`groupBy` : colonnes ou
12
12
  * sections ; `thenBy` : lignes d'une matrice ou sous-sections d'une liste),
13
- * groupes vides, filtres (vides : toutes les valeurs).
13
+ * groupes vides, filtres (vides : toutes les valeurs ; `assigneeIds` : membres
14
+ * de l'espace dont la vue montre les tâches ; `unassigned` : la vue montre
15
+ * aussi les tâches sans assigné).
14
16
  */
15
17
  const BoardViewSettingsSchema = z.object({
16
18
  name: BoardViewNameSchema,
@@ -20,6 +22,8 @@ const BoardViewSettingsSchema = z.object({
20
22
  showEmptyGroups: z.boolean(),
21
23
  statuses: z.array(TaskStatusSchema),
22
24
  priorities: z.array(TaskPrioritySchema),
25
+ assigneeIds: z.array(IdSchema),
26
+ unassigned: z.boolean(),
23
27
  });
24
28
  /** Vue du tableau de bord telle que l'affiche la GUI. */
25
29
  export const BoardViewViewSchema = BoardViewSettingsSchema.extend({ id: IdSchema });
@@ -1,3 +1,3 @@
1
1
  import { type AgentRoute } from "./types.js";
2
- /** Demandes de l'espace du jeton : liste, prise, fin (réussie ou en échec). */
2
+ /** Demandes de l'espace du jeton : liste, prise, fin (réussie ou en échec), points de la demande d'origine qu'une suite règle. */
3
3
  export declare const requestRoutes: AgentRoute[];
@@ -1,7 +1,8 @@
1
- import { ClaimRequestBodySchema, ClaimRequestDataSchema, CompleteRequestBodySchema, FailRequestBodySchema, FinishRequestDataSchema, ListRequestsDataSchema, ListRequestsQuerySchema, } from "../../shared/schemas/agent-tools.schema.js";
2
- import { agentActor, ideaData, memberData, recentIdeas, requestContext, requestData, requestHistory, requestLine, requestOfSpace, spaceData, treeData } from "../core/agent.js";
1
+ import { CheckFollowUpsBodySchema, CheckFollowUpsDataSchema, ClaimRequestBodySchema, ClaimRequestDataSchema, CompleteRequestBodySchema, FailRequestBodySchema, FinishRequestDataSchema, ListRequestsDataSchema, ListRequestsQuerySchema, } from "../../shared/schemas/agent-tools.schema.js";
2
+ import { actFor, agentActor, ideaData, memberData, previousSuites, quote, recentIdeas, requestContext, requestData, requestHistory, requestLine, requestOfSpace, requestThread, spaceData, userLabel, treeData, } from "../core/agent.js";
3
+ import { InvariantError, NotFoundError } from "../core/errors.js";
3
4
  import { parseInput, respond } from "./types.js";
4
- /** Demandes de l'espace du jeton : liste, prise, fin (réussie ou en échec). */
5
+ /** Demandes de l'espace du jeton : liste, prise, fin (réussie ou en échec), points de la demande d'origine qu'une suite règle. */
5
6
  export const requestRoutes = [
6
7
  {
7
8
  method: "GET",
@@ -26,9 +27,22 @@ export const requestRoutes = [
26
27
  parseInput(ClaimRequestBodySchema, body);
27
28
  requestOfSpace(store, agent, params.requestId);
28
29
  const request = store.mutate(agentActor(agent, params.requestId), (tx) => tx.claimAgentRequest());
30
+ const origin = request.parentRequestId === null ? null : store.findAgentRequest(request.parentRequestId);
31
+ const thread = requestThread(store, request);
29
32
  return respond(ClaimRequestDataSchema, requestContext(store, agent, request), {
30
33
  request: requestData(store, agent, request),
31
34
  history: requestHistory(store, request).map((previous) => requestData(store, agent, previous)),
35
+ thread: thread
36
+ ? thread.map((comment) => ({
37
+ authorName: comment.requestId === null ? userLabel(store.getUser(comment.authorId)) : "Agent",
38
+ byAgent: comment.requestId !== null,
39
+ body: comment.body,
40
+ createdAt: comment.createdAt,
41
+ }))
42
+ : null,
43
+ parent: origin
44
+ ? { request: requestData(store, agent, origin), suites: previousSuites(store, origin, request).map((suite) => requestData(store, agent, suite)) }
45
+ : null,
32
46
  instructions: { site: store.findAgentInstructions(null)?.text ?? null, space: store.findAgentInstructions(agent.space.id)?.text ?? null },
33
47
  space: spaceData(agent.space),
34
48
  members: memberData(store, agent.space),
@@ -45,10 +59,48 @@ export const requestRoutes = [
45
59
  requestOfSpace(store, agent, params.requestId);
46
60
  const done = store.mutate(agentActor(agent, params.requestId), (tx) => tx.completeAgentRequest(input.reply, input.follow_ups));
47
61
  const actionCount = store.listAgentActions(done.id).length;
48
- const left = done.followUps.length === 0 ? "nothing left to its author" : `${done.followUps.length} point(s) left to its author`;
62
+ const points = store.listFollowUps(done.id).length;
63
+ const left = points === 0 ? "nothing left to its author" : `${points} point(s) left to its author, who is notified`;
49
64
  return respond(FinishRequestDataSchema, `Request ${done.id} is done (${actionCount} action(s) in its batch, ${left}). Call list_requests for the next one.`, { request: requestData(store, agent, done), actionCount });
50
65
  },
51
66
  },
67
+ {
68
+ method: "POST",
69
+ path: "/requests/:requestId/follow-ups",
70
+ handle: ({ store }, { agent, params, body }) => {
71
+ const input = parseInput(CheckFollowUpsBodySchema, body);
72
+ const origin = actFor(store, agent, params.requestId, (tx) => {
73
+ const suite = tx.store.getAgentRequest(params.requestId);
74
+ if (suite.parentRequestId === null) {
75
+ throw new InvariantError(`Request ${suite.id} is not a follow-up: only the points of the request a follow-up continues can be checked.`);
76
+ }
77
+ const origin = tx.store.getAgentRequest(suite.parentRequestId);
78
+ const points = tx.store.listFollowUps(origin.id);
79
+ for (const id of input.follow_ups) {
80
+ const point = points.find((candidate) => candidate.id === id.trim());
81
+ if (!point) {
82
+ throw new NotFoundError(`Point ${id} is not a point of request ${origin.id}. Its points are listed by claim_request: ${points.map((p) => p.id).join(", ") || "none"}.`);
83
+ }
84
+ if ((point.doneAt !== null) === input.done)
85
+ continue;
86
+ const after = tx.setFollowUpDone(point.id, input.done);
87
+ tx.recordAgentAction({
88
+ entityType: "follow_up",
89
+ entityId: point.id,
90
+ operation: "update",
91
+ before: point,
92
+ after,
93
+ summary: `${input.done ? "Point coché" : "Point rouvert"} : ${quote(point.text)}`,
94
+ taskId: null,
95
+ });
96
+ }
97
+ return origin;
98
+ });
99
+ const data = requestData(store, agent, origin);
100
+ const open = data.followUps.filter((point) => !point.done).length;
101
+ return respond(CheckFollowUpsDataSchema, `Points of request ${origin.id} updated: ${open === 0 ? "all are done" : `${open} still open`}. Mention it in your reply.`, { request: data });
102
+ },
103
+ },
52
104
  {
53
105
  method: "POST",
54
106
  path: "/requests/:requestId/fail",
@@ -5,6 +5,7 @@ import { ideaRoutes } from "./ideas.js";
5
5
  import { notificationRoutes } from "./notifications.js";
6
6
  import { requestRoutes } from "./requests.js";
7
7
  import { taskRoutes } from "./tasks.js";
8
+ import { viewRoutes } from "./views.js";
8
9
  function compile(route) {
9
10
  const keys = [];
10
11
  const source = route.path.replace(/:([A-Za-z]+)/g, (_, key) => {
@@ -13,7 +14,7 @@ function compile(route) {
13
14
  });
14
15
  return { route, pattern: new RegExp(`^${source}$`), keys };
15
16
  }
16
- const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...ideaRoutes, ...notificationRoutes].map(compile);
17
+ const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...ideaRoutes, ...viewRoutes, ...notificationRoutes].map(compile);
17
18
  /** Segment de chemin décodé ; un encodage `%` invalide est une erreur 400. */
18
19
  function decodeSegment(raw) {
19
20
  try {
@@ -0,0 +1,2 @@
1
+ import { type AgentRoute } from "./types.js";
2
+ export declare const viewRoutes: AgentRoute[];
@@ -0,0 +1,203 @@
1
+ import { CreateViewBodySchema, DeleteViewBodySchema, ListViewsQuerySchema, UpdateViewBodySchema, ViewDataSchema, ViewsDataSchema, } from "../../shared/schemas/agent-tools.schema.js";
2
+ import { PRIORITY_LABELS, STATUS_LABELS } from "../../shared/logic/labels.js";
3
+ import { actFor, actingRequest, quote, requireText, resolveMembers, userLabel } from "../core/agent.js";
4
+ import { ensureBoardViews, groupingIssue } from "../core/board-views.js";
5
+ import { ForbiddenError, InvariantError, NotFoundError, OrganizerError } from "../core/errors.js";
6
+ import { parseInput, respond } from "./types.js";
7
+ /**
8
+ * Vues du tableau de bord de l'auteur de la demande, dans l'espace du jeton :
9
+ * lecture, création, modification, suppression. L'agent n'agit que sur les
10
+ * vues de l'auteur de la demande qu'il traite.
11
+ */
12
+ const GROUPING_ERRORS = {
13
+ kanban_ungrouped: "A kanban view is grouped by status or priority: set group_by.",
14
+ kanban_second: "A kanban view has a single grouping: set then_by to none, or use the matrix layout to cross two groupings.",
15
+ matrix_incomplete: "A matrix view crosses two groupings: set group_by (columns) and then_by (rows) to status and priority.",
16
+ second_without_first: "then_by needs a first grouping: set group_by.",
17
+ second_same_as_first: "then_by must differ from group_by.",
18
+ };
19
+ const LAYOUT_LABELS = { kanban: "Kanban", list: "Liste", matrix: "Matrice" };
20
+ const GROUPING_LABELS = { status: "statut", priority: "priorité", none: "aucun" };
21
+ function requireGroupings(settings) {
22
+ const issue = groupingIssue(settings);
23
+ if (issue)
24
+ throw new OrganizerError(GROUPING_ERRORS[issue]);
25
+ }
26
+ /**
27
+ * Auteur de la demande, membre de l'espace : celui dont l'agent règle les vues.
28
+ * Seuls le runner du site et un jeton de l'auteur lui-même y ont accès.
29
+ */
30
+ function requestAuthor(store, agent, requestId) {
31
+ const { request, space } = actingRequest(store, agent, requestId);
32
+ const author = store.getUser(request.authorId);
33
+ if (!agent.token.isRunner && agent.token.userId !== author.id) {
34
+ throw new ForbiddenError(`Request ${requestId} was written by ${userLabel(author)}, not by the owner of your token: only their own agent or the site runner can read or change their views. Tell them so in your reply.`);
35
+ }
36
+ if (!store.isMember(space.id, author.id)) {
37
+ throw new ForbiddenError(`${userLabel(author)}, the author of request ${requestId}, is no longer a member of "${space.name}": their views cannot be changed.`);
38
+ }
39
+ return { author, space };
40
+ }
41
+ /** Vue de l'auteur dans l'espace ; une autre vue est introuvable pour l'agent. */
42
+ function resolveView(store, author, space, viewId) {
43
+ const view = store.findBoardView(viewId.trim());
44
+ if (!view || view.userId !== author.id || view.spaceId !== space.id) {
45
+ throw new NotFoundError(`View ${viewId} not found among the views of ${userLabel(author)} in "${space.name}". Call list_views to get their view ids.`);
46
+ }
47
+ return view;
48
+ }
49
+ function viewData(view) {
50
+ const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned } = view;
51
+ return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned };
52
+ }
53
+ function ownerData(author) {
54
+ return { id: author.id, name: userLabel(author), email: author.email };
55
+ }
56
+ /** Ligne d'une vue : identifiant, nom, disposition, regroupements et filtres. */
57
+ function viewLine(store, view) {
58
+ const grouping = view.groupBy === "none" ? "ungrouped" : `by ${view.groupBy}${view.thenBy === "none" ? "" : ` then ${view.thenBy}`}`;
59
+ const assignees = view.assigneeIds.map((id) => {
60
+ const user = store.findUser(id);
61
+ return user ? userLabel(user) : id;
62
+ });
63
+ if (view.unassigned)
64
+ assignees.push("unassigned");
65
+ const filters = [
66
+ `statuses ${view.statuses.length > 0 ? view.statuses.join(", ") : "all"}`,
67
+ `priorities ${view.priorities.length > 0 ? view.priorities.join(", ") : "all"}`,
68
+ `assignees ${assignees.length > 0 ? assignees.join(", ") : "all"}`,
69
+ ];
70
+ return `- ${view.id} "${view.name}": ${view.layout} ${grouping}, empty groups ${view.showEmptyGroups ? "shown" : "hidden"}; ${filters.join("; ")}`;
71
+ }
72
+ /** Réglages passés par l'agent, au format du modèle ; les assignés sont résolus parmi les membres. */
73
+ function settingsPatch(store, space, input) {
74
+ return {
75
+ name: input.name === undefined ? undefined : requireText(input.name, "name"),
76
+ layout: input.layout,
77
+ groupBy: input.group_by,
78
+ thenBy: input.then_by,
79
+ showEmptyGroups: input.show_empty_groups,
80
+ statuses: input.statuses,
81
+ priorities: input.priorities,
82
+ assigneeIds: input.assignees === undefined ? undefined : resolveMembers(store, space, input.assignees).map((user) => user.id),
83
+ unassigned: input.unassigned,
84
+ };
85
+ }
86
+ /** Résumé français des réglages changés d'une vue. */
87
+ function viewUpdateSummary(before, after) {
88
+ const parts = [];
89
+ if (before.name !== after.name)
90
+ parts.push(`Renommée ${quote(after.name)}`);
91
+ if (before.layout !== after.layout)
92
+ parts.push(`Disposition ${LAYOUT_LABELS[before.layout]} → ${LAYOUT_LABELS[after.layout]}`);
93
+ if (before.groupBy !== after.groupBy || before.thenBy !== after.thenBy) {
94
+ parts.push(`Regroupement par ${GROUPING_LABELS[after.groupBy]}${after.thenBy === "none" ? "" : ` puis ${GROUPING_LABELS[after.thenBy]}`}`);
95
+ }
96
+ if (before.showEmptyGroups !== after.showEmptyGroups)
97
+ parts.push(after.showEmptyGroups ? "Groupes vides affichés" : "Groupes vides masqués");
98
+ if (JSON.stringify(before.statuses) !== JSON.stringify(after.statuses)) {
99
+ parts.push(`Statuts : ${after.statuses.length > 0 ? after.statuses.map((status) => STATUS_LABELS[status]).join(", ") : "tous"}`);
100
+ }
101
+ if (JSON.stringify(before.priorities) !== JSON.stringify(after.priorities)) {
102
+ parts.push(`Priorités : ${after.priorities.length > 0 ? after.priorities.map((priority) => PRIORITY_LABELS[priority]).join(", ") : "toutes"}`);
103
+ }
104
+ if (JSON.stringify(before.assigneeIds) !== JSON.stringify(after.assigneeIds) || before.unassigned !== after.unassigned)
105
+ parts.push("Filtre des assignés modifié");
106
+ return `Vue ${quote(before.name)} : ${parts.join(" · ") || "inchangée"}`;
107
+ }
108
+ export const viewRoutes = [
109
+ {
110
+ method: "GET",
111
+ path: "/views",
112
+ handle: ({ store }, { agent, query }) => {
113
+ const input = parseInput(ListViewsQuerySchema, query);
114
+ const { author, space } = requestAuthor(store, agent, input.request_id);
115
+ const views = store.listBoardViews(space.id, author.id);
116
+ const header = `Board views of ${userLabel(author)} <${author.email}> in "${space.name}", in the order of their tabs:`;
117
+ 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)"];
118
+ return respond(ViewsDataSchema, [header, ...lines].join("\n"), { owner: ownerData(author), views: views.map(viewData) });
119
+ },
120
+ },
121
+ {
122
+ method: "POST",
123
+ path: "/views",
124
+ handle: ({ store }, { agent, body }) => {
125
+ const input = parseInput(CreateViewBodySchema, body);
126
+ const { author } = requestAuthor(store, agent, input.request_id);
127
+ const created = actFor(store, agent, input.request_id, (tx, space) => {
128
+ const patch = settingsPatch(tx.store, space, input);
129
+ const layout = patch.layout ?? "kanban";
130
+ const groupBy = patch.groupBy ?? "status";
131
+ const settings = {
132
+ name: requireText(input.name, "name"),
133
+ layout,
134
+ groupBy,
135
+ thenBy: patch.thenBy ?? (layout === "matrix" ? (groupBy === "status" ? "priority" : "status") : "none"),
136
+ showEmptyGroups: patch.showEmptyGroups ?? layout !== "list",
137
+ statuses: patch.statuses ?? [],
138
+ priorities: patch.priorities ?? [],
139
+ assigneeIds: patch.assigneeIds ?? [],
140
+ unassigned: patch.unassigned ?? false,
141
+ };
142
+ requireGroupings(settings);
143
+ ensureBoardViews(tx, space.id, author.id);
144
+ const view = tx.createBoardView(space.id, author.id, settings);
145
+ tx.recordAgentAction({
146
+ entityType: "board_view",
147
+ entityId: view.id,
148
+ operation: "create",
149
+ before: null,
150
+ after: view,
151
+ summary: `Vue ${quote(view.name)} créée pour ${userLabel(author)}`,
152
+ taskId: null,
153
+ });
154
+ return view;
155
+ });
156
+ return respond(ViewDataSchema, `Created view ${created.id} "${created.name}" for ${userLabel(author)}; their open dashboard switches to it.\n${viewLine(store, created)}`, {
157
+ owner: ownerData(author),
158
+ view: viewData(created),
159
+ });
160
+ },
161
+ },
162
+ {
163
+ method: "PATCH",
164
+ path: "/views/:viewId",
165
+ handle: ({ store }, { agent, params, body }) => {
166
+ const input = parseInput(UpdateViewBodySchema, body);
167
+ const { request_id, ...fields } = input;
168
+ if (Object.values(fields).every((value) => value === undefined))
169
+ throw new OrganizerError("Nothing to change: give at least one setting of the view.");
170
+ const { author } = requestAuthor(store, agent, request_id);
171
+ const updated = actFor(store, agent, request_id, (tx, space) => {
172
+ const view = resolveView(tx.store, author, space, params.viewId);
173
+ const patch = settingsPatch(tx.store, space, input);
174
+ requireGroupings({ layout: patch.layout ?? view.layout, groupBy: patch.groupBy ?? view.groupBy, thenBy: patch.thenBy ?? view.thenBy });
175
+ const updated = tx.updateBoardView(view.id, patch);
176
+ tx.recordAgentAction({ entityType: "board_view", entityId: view.id, operation: "update", before: view, after: updated, summary: viewUpdateSummary(view, updated), taskId: null });
177
+ return updated;
178
+ });
179
+ return respond(ViewDataSchema, `Updated view ${updated.id} of ${userLabel(author)}; their open dashboard switches to it.\n${viewLine(store, updated)}`, {
180
+ owner: ownerData(author),
181
+ view: viewData(updated),
182
+ });
183
+ },
184
+ },
185
+ {
186
+ method: "POST",
187
+ path: "/views/:viewId/delete",
188
+ handle: ({ store }, { agent, params, body }) => {
189
+ const input = parseInput(DeleteViewBodySchema, body);
190
+ const { author } = requestAuthor(store, agent, input.request_id);
191
+ const deleted = actFor(store, agent, input.request_id, (tx, space) => {
192
+ const view = resolveView(tx.store, author, space, params.viewId);
193
+ if (tx.store.listBoardViews(space.id, author.id).length === 1) {
194
+ throw new InvariantError(`View ${view.id} is the last view of ${userLabel(author)} in "${space.name}": create another one before deleting it.`);
195
+ }
196
+ tx.deleteBoardView(view.id);
197
+ tx.recordAgentAction({ entityType: "board_view", entityId: view.id, operation: "delete", before: view, after: null, summary: `Vue ${quote(view.name)} supprimée`, taskId: null });
198
+ return view;
199
+ });
200
+ return respond(ViewDataSchema, `Deleted view ${deleted.id} "${deleted.name}" of ${userLabel(author)}.`, { owner: ownerData(author), view: viewData(deleted) });
201
+ },
202
+ },
203
+ ];
@@ -1,5 +1,5 @@
1
1
  import type { Actor, Mutation, Store } from "./store.js";
2
- import type { AgentRequest, Idea, Space, Task, TaskSnapshot, User } from "../../shared/schemas/entities.schema.js";
2
+ import type { AgentRequest, Comment, Idea, Space, Task, TaskSnapshot, User } from "../../shared/schemas/entities.schema.js";
3
3
  import type { AgentIdea, AgentMember, AgentRequestSummary, AgentSpace, AgentTaskSummary } from "../../shared/schemas/agent-tools.schema.js";
4
4
  import type { ResolvedAgentToken } from "./agent-tokens.js";
5
5
  /**
@@ -49,6 +49,10 @@ export declare function requestLine(store: Store, agent: AgentCaller, request: A
49
49
  * au plus récent, au nombre fixé dans ses paramètres ; aucun pour les autres types.
50
50
  */
51
51
  export declare function requestHistory(store: Store, request: AgentRequest): AgentRequest[];
52
+ /** Commentaires du fil d'une demande confiée par un commentaire de tâche, jusqu'à ce commentaire compris ; null pour une autre demande. */
53
+ export declare function requestThread(store: Store, request: AgentRequest): Comment[] | null;
54
+ /** Suites précédentes d'une demande d'origine, closes avant `request`. */
55
+ export declare function previousSuites(store: Store, origin: AgentRequest, request: AgentRequest): AgentRequest[];
52
56
  /** Contexte complet d'une demande, renvoyé par claim_request. */
53
57
  export declare function requestContext(store: Store, agent: AgentCaller, request: AgentRequest): string;
54
58
  /** Instructions personnalisées de l'agent pour une demande de l'espace : celles du site, puis celles de l'espace. */
@@ -183,9 +183,61 @@ function historyLines(store, request) {
183
183
  const task = request.contextTaskId === null ? null : store.findTask(request.contextTaskId);
184
184
  const about = [request.kind !== "message" ? request.kind : null, task ? `context ${taskKey(store, task)}` : null].filter(Boolean).join(", ");
185
185
  const answer = request.status === "done" ? `Reply: ${request.reply ?? ""}` : `Failed: ${request.failureReason ?? ""}`;
186
- const followUps = request.followUps.map((point) => ` Left to the author: ${point}`);
186
+ const followUps = store.listFollowUps(request.id).map((point) => ` Left to the author${point.doneAt === null ? "" : " (done)"}: ${point.text}`);
187
187
  return [`- ${ago(request.createdAt)}${about ? ` (${about})` : ""}: ${request.text.trim()}`, ` ${answer.trim()}`, ...followUps];
188
188
  }
189
+ /** Nombre maximal de commentaires du fil transmis avec une demande confiée par un commentaire. */
190
+ const THREAD_COMMENTS = 30;
191
+ /** Commentaires du fil d'une demande confiée par un commentaire de tâche, jusqu'à ce commentaire compris ; null pour une autre demande. */
192
+ export function requestThread(store, request) {
193
+ const source = request.commentId === null ? null : store.findComment(request.commentId);
194
+ if (!source)
195
+ return null;
196
+ const comments = store.listComments(source.taskId);
197
+ const upTo = comments.findIndex((comment) => comment.id === source.id);
198
+ return comments.slice(0, upTo + 1).slice(-THREAD_COMMENTS);
199
+ }
200
+ /** Lignes du fil d'une demande confiée par un commentaire de tâche. */
201
+ function threadLines(store, thread) {
202
+ const source = thread[thread.length - 1];
203
+ const task = store.getTask(source.taskId);
204
+ const lines = [
205
+ "",
206
+ `This request comes from a comment of ${userLabel(store.getUser(source.authorId))} on ${taskKey(store, task)} "${task.title}" that mentions @agent. complete_request posts your reply as a comment right after it in the task's thread: write it as an answer in that conversation.`,
207
+ `Comments of the thread up to that one (oldest first, ${thread.length} most recent):`,
208
+ ];
209
+ for (const comment of thread) {
210
+ const who = comment.requestId === null ? userLabel(store.getUser(comment.authorId)) : "Agent";
211
+ lines.push(`- ${who}, ${ago(comment.createdAt)}: ${comment.body.trim().replace(/\s+/g, " ")}`);
212
+ }
213
+ return lines;
214
+ }
215
+ /** Suites précédentes d'une demande d'origine, closes avant `request`. */
216
+ export function previousSuites(store, origin, request) {
217
+ return store.listSuitesOf(origin.id).filter((suite) => suite.id !== request.id && (suite.status === "done" || suite.status === "failed"));
218
+ }
219
+ /** Lignes de la demande d'origine d'une suite : texte, réponse, points à régler avec leur identifiant, suites précédentes. */
220
+ function originLines(store, origin, request) {
221
+ const lines = [
222
+ "",
223
+ `This request is a follow-up of request ${origin.id} (${ago(origin.createdAt)}), sent by ${userLabel(store.getUser(request.authorId))} from that request:`,
224
+ ` Original request: ${origin.text.trim()}`,
225
+ ` ${origin.status === "done" ? `Your reply then: ${origin.reply ?? ""}` : `It failed: ${origin.failureReason ?? ""}`}`.trimEnd(),
226
+ ];
227
+ const points = store.listFollowUps(origin.id);
228
+ if (points.length > 0) {
229
+ lines.push(" Points left to the author (check with check_follow_ups those this follow-up settles):");
230
+ for (const point of points)
231
+ lines.push(` - ${point.id} [${point.doneAt === null ? "open" : "done"}] ${point.text}`);
232
+ }
233
+ const suites = previousSuites(store, origin, request);
234
+ if (suites.length > 0) {
235
+ lines.push(" Earlier follow-ups (oldest first):");
236
+ for (const suite of suites)
237
+ lines.push(...historyLines(store, suite).map((line) => ` ${line}`));
238
+ }
239
+ return lines;
240
+ }
189
241
  /** Contexte complet d'une demande, renvoyé par claim_request. */
190
242
  export function requestContext(store, agent, request) {
191
243
  const author = store.getUser(request.authorId);
@@ -220,6 +272,12 @@ export function requestContext(store, agent, request) {
220
272
  if (idea)
221
273
  lines.push(`Context idea: ${idea.id} "${idea.text}".`);
222
274
  }
275
+ const origin = request.parentRequestId === null ? null : store.findAgentRequest(request.parentRequestId);
276
+ if (origin)
277
+ lines.push(...originLines(store, origin, request));
278
+ const thread = requestThread(store, request);
279
+ if (thread)
280
+ lines.push(...threadLines(store, thread));
223
281
  const history = requestHistory(store, request);
224
282
  if (history.length > 0) {
225
283
  lines.push("", `Previous exchanges of the author in this space (oldest first, ${history.length} most recent) — use them to understand the message:`);
@@ -326,8 +384,9 @@ export function requestData(store, agent, request) {
326
384
  claimedAt: request.claimedAt,
327
385
  claimedByThisToken: request.claimedByTokenId === agent.token.id,
328
386
  reply: request.reply,
329
- followUps: request.followUps,
387
+ followUps: store.listFollowUps(request.id).map((point) => ({ id: point.id, text: point.text, done: point.doneAt !== null })),
330
388
  failureReason: request.failureReason,
389
+ parentRequestId: request.parentRequestId,
331
390
  };
332
391
  }
333
392
  // --- Résumés des actions (affichés dans la GUI, en français) ----------------------
@@ -1,7 +1,17 @@
1
- import type { BoardViewSettings, Store } from "./store.js";
1
+ import type { BoardViewSettings, Mutation, Store } from "./store.js";
2
2
  import type { BoardViewListResponse, BoardViewView, CreateBoardViewRequest, UpdateBoardViewRequest } from "../../shared/schemas/views-api.schema.js";
3
3
  /** Vues créées pour un membre qui n'en a aucune : le Kanban et la liste par statut, sans filtre. */
4
4
  export declare const DEFAULT_BOARD_VIEWS: readonly BoardViewSettings[];
5
+ /** Réglages de regroupement refusés par une disposition. */
6
+ export type GroupingIssue = "kanban_ungrouped" | "kanban_second" | "matrix_incomplete" | "second_without_first" | "second_same_as_first";
7
+ /**
8
+ * Regroupements permis par la disposition : un Kanban a un regroupement, une
9
+ * matrice en croise deux, une liste en a zéro, un ou deux ; le second suit le
10
+ * premier et en diffère. Renvoie le problème trouvé, ou null.
11
+ */
12
+ export declare function groupingIssue(settings: Pick<BoardViewSettings, "layout" | "groupBy" | "thenBy">): GroupingIssue | null;
13
+ /** Crée les vues par défaut d'un membre qui n'en a aucune dans l'espace. */
14
+ export declare function ensureBoardViews(tx: Mutation, spaceId: string, userId: string): void;
5
15
  /** Vues de l'utilisateur dans un espace ; les vues par défaut sont créées s'il n'en a aucune. */
6
16
  export declare function listBoardViews(store: Store, userId: string, spaceId: string): BoardViewListResponse;
7
17
  /** Ajoute une vue après les autres. */
@@ -8,12 +8,17 @@ 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: [] },
12
- { name: "Liste", layout: "list", groupBy: "status", thenBy: "none", showEmptyGroups: false, statuses: [], priorities: [] },
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 },
13
13
  ];
14
14
  function viewOf(view) {
15
- const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities } = view;
16
- return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities };
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 };
17
+ }
18
+ /** Assignés d'une vue : des membres de l'espace. */
19
+ function requireAssignees(store, spaceId, assigneeIds) {
20
+ if (assigneeIds?.some((id) => !store.isMember(spaceId, id)))
21
+ throw new OrganizerError("Une vue ne filtre que sur des membres de l'espace.");
17
22
  }
18
23
  /** Vue de l'utilisateur ; celle d'un autre reçoit la même réponse qu'une vue inexistante. */
19
24
  function requireOwnView(store, viewId, userId) {
@@ -26,20 +31,40 @@ function requireOwnView(store, viewId, userId) {
26
31
  /**
27
32
  * Regroupements permis par la disposition : un Kanban a un regroupement, une
28
33
  * matrice en croise deux, une liste en a zéro, un ou deux ; le second suit le
29
- * premier et en diffère.
34
+ * premier et en diffère. Renvoie le problème trouvé, ou null.
30
35
  */
31
- function requireGroupings(settings) {
36
+ export function groupingIssue(settings) {
32
37
  const { layout, groupBy, thenBy } = settings;
33
38
  if (layout === "kanban" && groupBy === "none")
34
- throw new OrganizerError("Un Kanban se regroupe par statut ou par priorité.");
39
+ return "kanban_ungrouped";
35
40
  if (layout === "kanban" && thenBy !== "none")
36
- throw new OrganizerError("Un Kanban n'a qu'un regroupement : choisissez la matrice pour en croiser deux.");
41
+ return "kanban_second";
37
42
  if (layout === "matrix" && (groupBy === "none" || thenBy === "none"))
38
- throw new OrganizerError("Une matrice croise deux regroupements : ses colonnes et ses lignes.");
43
+ return "matrix_incomplete";
39
44
  if (thenBy !== "none" && groupBy === "none")
40
- throw new OrganizerError("Le second regroupement suit un premier regroupement.");
45
+ return "second_without_first";
41
46
  if (thenBy !== "none" && thenBy === groupBy)
42
- throw new OrganizerError("Le second regroupement diffère du premier.");
47
+ return "second_same_as_first";
48
+ return null;
49
+ }
50
+ const GROUPING_MESSAGES = {
51
+ kanban_ungrouped: "Un Kanban se regroupe par statut ou par priorité.",
52
+ kanban_second: "Un Kanban n'a qu'un regroupement : choisissez la matrice pour en croiser deux.",
53
+ matrix_incomplete: "Une matrice croise deux regroupements : ses colonnes et ses lignes.",
54
+ second_without_first: "Le second regroupement suit un premier regroupement.",
55
+ second_same_as_first: "Le second regroupement diffère du premier.",
56
+ };
57
+ function requireGroupings(settings) {
58
+ const issue = groupingIssue(settings);
59
+ if (issue)
60
+ throw new OrganizerError(GROUPING_MESSAGES[issue]);
61
+ }
62
+ /** Crée les vues par défaut d'un membre qui n'en a aucune dans l'espace. */
63
+ export function ensureBoardViews(tx, spaceId, userId) {
64
+ if (tx.store.listBoardViews(spaceId, userId).length > 0)
65
+ return;
66
+ for (const settings of DEFAULT_BOARD_VIEWS)
67
+ tx.createBoardView(spaceId, userId, settings);
43
68
  }
44
69
  /** Vues de l'utilisateur dans un espace ; les vues par défaut sont créées s'il n'en a aucune. */
45
70
  export function listBoardViews(store, userId, spaceId) {
@@ -47,10 +72,7 @@ export function listBoardViews(store, userId, spaceId) {
47
72
  if (store.listBoardViews(spaceId, userId).length === 0) {
48
73
  store.mutate(asUser(userId), (tx) => {
49
74
  requireMember(tx.store, spaceId, userId);
50
- if (tx.store.listBoardViews(spaceId, userId).length > 0)
51
- return;
52
- for (const settings of DEFAULT_BOARD_VIEWS)
53
- tx.createBoardView(spaceId, userId, settings);
75
+ ensureBoardViews(tx, spaceId, userId);
54
76
  });
55
77
  }
56
78
  return { views: store.listBoardViews(spaceId, userId).map(viewOf) };
@@ -60,6 +82,7 @@ export function createBoardView(store, userId, spaceId, input) {
60
82
  requireGroupings(input);
61
83
  const view = store.mutate(asUser(userId), (tx) => {
62
84
  requireMember(tx.store, spaceId, userId);
85
+ requireAssignees(tx.store, spaceId, input.assigneeIds);
63
86
  return tx.createBoardView(spaceId, userId, input);
64
87
  });
65
88
  return viewOf(view);
@@ -69,6 +92,7 @@ export function updateBoardView(store, userId, viewId, patch) {
69
92
  const view = store.mutate(asUser(userId), (tx) => {
70
93
  const current = requireOwnView(tx.store, viewId, userId);
71
94
  requireGroupings({ layout: patch.layout ?? current.layout, groupBy: patch.groupBy ?? current.groupBy, thenBy: patch.thenBy ?? current.thenBy });
95
+ requireAssignees(tx.store, current.spaceId, patch.assigneeIds);
72
96
  return tx.updateBoardView(viewId, patch);
73
97
  });
74
98
  return viewOf(view);
@@ -0,0 +1,7 @@
1
+ import type { Store } from "./store.js";
2
+ import type { FollowUp } from "../../shared/schemas/entities.schema.js";
3
+ import type { FollowUpView } from "../../shared/schemas/tasks-api.schema.js";
4
+ /** Points à régler d'une demande vus de la GUI : la page Agent et les commentaires d'une tâche. */
5
+ export declare function followUpView(store: Store, followUp: FollowUp): FollowUpView;
6
+ /** Points encore ouverts d'une demande. */
7
+ export declare function openFollowUps(store: Store, requestId: string): number;
@@ -0,0 +1,15 @@
1
+ /** Points à régler d'une demande vus de la GUI : la page Agent et les commentaires d'une tâche. */
2
+ export function followUpView(store, followUp) {
3
+ const doneBy = followUp.doneBy === null ? null : store.findUser(followUp.doneBy);
4
+ return {
5
+ id: followUp.id,
6
+ text: followUp.text,
7
+ doneAt: followUp.doneAt,
8
+ doneByName: doneBy ? (doneBy.displayName ?? doneBy.email) : null,
9
+ doneByRequestId: followUp.doneByRequestId,
10
+ };
11
+ }
12
+ /** Points encore ouverts d'une demande. */
13
+ export function openFollowUps(store, requestId) {
14
+ return store.listFollowUps(requestId).filter((followUp) => followUp.doneAt === null).length;
15
+ }
@@ -11,7 +11,8 @@ declare const TASK_FIELDS: readonly ["title", "description", "status", "priority
11
11
  * Annule une action de l'agent dans la mutation `tx` (acteur utilisateur).
12
12
  * L'état courant de l'entité doit être celui que l'action a laissé ; sinon le
13
13
  * refus nomme l'auteur de la modification. Une création est supprimée, une
14
- * suppression recréée, une modification ramenée à l'état d'avant.
14
+ * suppression recréée, une modification ramenée à l'état d'avant. Une action
15
+ * sur une vue du tableau de bord ne s'annule que par le membre à qui la vue appartient.
15
16
  */
16
17
  export declare function undoAgentAction(tx: Mutation, action: AgentAction): void;
17
18
  /** Libellés français des champs restaurables d'une tâche ; « position » est le rang dans une même colonne. */