@imenam/mcp-organizer 1.0.13 → 1.0.14

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.
@@ -531,6 +531,45 @@ export const MIGRATIONS = [
531
531
  ALTER TABLE agent_requests ADD COLUMN comment_id TEXT REFERENCES comments(id) ON DELETE SET NULL;
532
532
  CREATE INDEX agent_requests_comment ON agent_requests(comment_id);
533
533
  ALTER TABLE comments ADD COLUMN reply_to_comment_id TEXT REFERENCES comments(id) ON DELETE SET NULL;
534
+ `,
535
+ // Type de demande `direct` : lot d'une action que l'agent fait sans demande, au nom du propriétaire de son jeton.
536
+ `
537
+ CREATE TABLE agent_requests_next (
538
+ id TEXT PRIMARY KEY,
539
+ author_id TEXT NOT NULL REFERENCES users(id),
540
+ target_space_id TEXT NOT NULL REFERENCES spaces(id) ON DELETE CASCADE,
541
+ kind TEXT NOT NULL CHECK (kind IN ('idea', 'remark', 'test_review', 'message', 'idea_promotion', 'direct')),
542
+ context_task_id TEXT REFERENCES tasks(id) ON DELETE SET NULL,
543
+ context_idea_id TEXT REFERENCES ideas(id) ON DELETE SET NULL,
544
+ text TEXT NOT NULL CHECK (text <> ''),
545
+ status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'done', 'failed', 'cancelled')),
546
+ reply TEXT,
547
+ failure_reason TEXT,
548
+ created_at TEXT NOT NULL,
549
+ updated_at TEXT NOT NULL,
550
+ claimed_at TEXT,
551
+ completed_at TEXT,
552
+ cancelled_by TEXT REFERENCES users(id),
553
+ claimed_by_token_id TEXT REFERENCES agent_tokens(id) ON DELETE SET NULL,
554
+ stopped_at TEXT,
555
+ stopped_by TEXT REFERENCES users(id) ON DELETE SET NULL,
556
+ parent_request_id TEXT REFERENCES agent_requests(id) ON DELETE SET NULL,
557
+ comment_id TEXT REFERENCES comments(id) ON DELETE SET NULL
558
+ );
559
+ INSERT INTO agent_requests_next (id, author_id, target_space_id, kind, context_task_id, context_idea_id, text, status, reply, failure_reason,
560
+ created_at, updated_at, claimed_at, completed_at, cancelled_by, claimed_by_token_id, stopped_at, stopped_by,
561
+ parent_request_id, comment_id)
562
+ SELECT id, author_id, target_space_id, kind, context_task_id, context_idea_id, text, status, reply, failure_reason,
563
+ created_at, updated_at, claimed_at, completed_at, cancelled_by, claimed_by_token_id, stopped_at, stopped_by,
564
+ parent_request_id, comment_id
565
+ FROM agent_requests;
566
+ DROP TABLE agent_requests;
567
+ ALTER TABLE agent_requests_next RENAME TO agent_requests;
568
+ CREATE INDEX agent_requests_status ON agent_requests(status, created_at);
569
+ CREATE INDEX agent_requests_claimed_by ON agent_requests(claimed_by_token_id);
570
+ CREATE INDEX agent_requests_target_status ON agent_requests(target_space_id, status, created_at);
571
+ CREATE INDEX agent_requests_parent ON agent_requests(parent_request_id);
572
+ CREATE INDEX agent_requests_comment ON agent_requests(comment_id);
534
573
  `,
535
574
  ];
536
575
  /** Version du schéma attendue par ce code. */
@@ -544,18 +583,38 @@ export function schemaVersion(db) {
544
583
  * qui relit la version : deux processus qui migrent la même base en même temps
545
584
  * n'appliquent chaque migration qu'une fois. Une base plus récente que le code
546
585
  * est refusée.
586
+ *
587
+ * Les clés étrangères sont désactivées le temps des migrations, comme le
588
+ * prescrit SQLite pour reconstruire une table référencée : supprimer
589
+ * l'ancienne table ne déclenche ainsi aucune suppression en cascade. Chaque
590
+ * migration vérifie ensuite les clés étrangères et échoue sur une violation.
547
591
  */
548
592
  export function migrate(db) {
549
593
  const current = schemaVersion(db);
550
594
  if (current > SCHEMA_VERSION) {
551
595
  throw new Error(`The database schema is version ${current}, newer than the version ${SCHEMA_VERSION} this mcp-organizer supports. Update the @imenam/mcp-organizer package.`);
552
596
  }
553
- for (let index = current; index < SCHEMA_VERSION; index++) {
554
- db.transaction(() => {
555
- if (schemaVersion(db) !== index)
556
- return;
557
- db.exec(MIGRATIONS[index]);
558
- db.pragma(`user_version = ${index + 1}`);
559
- }).immediate();
597
+ if (current === SCHEMA_VERSION)
598
+ return;
599
+ const foreignKeys = db.pragma("foreign_keys", { simple: true }) === 1;
600
+ db.pragma("foreign_keys = OFF");
601
+ try {
602
+ for (let index = current; index < SCHEMA_VERSION; index++) {
603
+ db.transaction(() => {
604
+ if (schemaVersion(db) !== index)
605
+ return;
606
+ db.exec(MIGRATIONS[index]);
607
+ const violations = db.pragma("foreign_key_check");
608
+ if (violations.length > 0) {
609
+ const { table, parent } = violations[0];
610
+ throw new Error(`Migration ${index + 1} leaves ${violations.length} foreign key violation(s), the first in ${table} towards ${parent}.`);
611
+ }
612
+ db.pragma(`user_version = ${index + 1}`);
613
+ }).immediate();
614
+ }
615
+ }
616
+ finally {
617
+ if (foreignKeys)
618
+ db.pragma("foreign_keys = ON");
560
619
  }
561
620
  }
@@ -3,6 +3,7 @@ import { stoppedByReason } from "./admin.js";
3
3
  import { requireMember } from "./spaces.js";
4
4
  import { requireTask } from "./tasks.js";
5
5
  import { undoAgentAction } from "./history.js";
6
+ import { actionTaskKey } from "./agent.js";
6
7
  import { taskIdOfAction } from "./snapshots.js";
7
8
  import { tokenState } from "./agent-tokens.js";
8
9
  import { followUpView, openFollowUps } from "./follow-ups.js";
@@ -40,14 +41,7 @@ function actionLabel(store, action) {
40
41
  return "Vue";
41
42
  if (action.entityType === "follow_up")
42
43
  return "Point";
43
- if (action.entityType === "task") {
44
- const snapshot = (action.after ?? action.before);
45
- const space = store.findSpace(snapshot.spaceId);
46
- return space ? `${space.keyPrefix}-${snapshot.number}` : "";
47
- }
48
- const taskId = taskIdOfAction(action);
49
- const task = taskId === null ? null : store.findTask(taskId);
50
- return task ? `${store.getSpace(task.spaceId).keyPrefix}-${task.number}` : "";
44
+ return actionTaskKey(store, action) ?? "";
51
45
  }
52
46
  export function actionView(store, action) {
53
47
  const taskId = taskIdOfAction(action);
@@ -88,7 +82,7 @@ export function requestView(store, userId, request) {
88
82
  followUps: store.listFollowUps(request.id).map((followUp) => followUpView(store, followUp)),
89
83
  failureReason: request.failureReason,
90
84
  parent: parent ? { id: parent.id, text: parent.text, openFollowUps: openFollowUps(store, parent.id) } : null,
91
- canFollowUp: member && request.parentRequestId === null && (request.status === "done" || request.status === "failed"),
85
+ canFollowUp: member && request.kind !== "direct" && request.parentRequestId === null && (request.status === "done" || request.status === "failed"),
92
86
  createdAt: request.createdAt,
93
87
  updatedAt: request.updatedAt,
94
88
  claimedAt: request.claimedAt,
@@ -218,6 +212,8 @@ export function createSuite(store, userId, requestId, text) {
218
212
  const suite = store.mutate(asUser(userId), (tx) => {
219
213
  const request = requireVisibleRequest(tx.store, userId, requestId);
220
214
  const origin = request.parentRequestId === null ? request : tx.store.getAgentRequest(request.parentRequestId);
215
+ if (origin.kind === "direct")
216
+ throw new InvariantError("Une action directe de l'agent n'a pas de suite : écrivez-lui un nouveau message.");
221
217
  if (origin.status !== "done" && origin.status !== "failed") {
222
218
  throw new InvariantError("L'agent n'a pas encore traité cette demande : attendez sa réponse pour lui demander une suite.");
223
219
  }
@@ -5,15 +5,16 @@ import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRe
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
8
- * son jeton pour une demande que ce jeton a prise, avec les droits du
9
- * propriétaire du jeton.
8
+ * son jeton, avec les droits du propriétaire du jeton, pour une demande que ce
9
+ * jeton a prise ou, sans demande (`requestId` nul), dans le lot direct que la
10
+ * mutation ouvre.
10
11
  */
11
12
  export type Actor = {
12
13
  type: "user";
13
14
  userId: string;
14
15
  } | {
15
16
  type: "agent";
16
- requestId: string;
17
+ requestId: string | null;
17
18
  tokenId: string;
18
19
  };
19
20
  /**
@@ -171,6 +172,7 @@ export declare class Store {
171
172
  /**
172
173
  * Échanges clos (traités ou en échec) d'un auteur dans un espace, antérieurs à
173
174
  * la demande `before`, du plus ancien au plus récent : les `limit` derniers.
175
+ * Les lots directs de l'agent n'en sont pas.
174
176
  */
175
177
  listClosedRequestsOfAuthorBefore(spaceId: string, authorId: string, before: AgentRequest, limit: number): AgentRequest[];
176
178
  /** Demandes d'un espace, de la plus récente à la plus ancienne, au plus `limit`. */
@@ -363,8 +365,8 @@ export declare class Mutation {
363
365
  readonly pendingRequestIds: string[];
364
366
  /** Espaces où la mutation a autorisé le runner. */
365
367
  readonly runnerAllowedSpaceIds: string[];
366
- /** Demande pour laquelle agit l'agent, lue au début de la mutation. */
367
- private readonly request;
368
+ /** Demande pour laquelle agit l'agent : lue au début de la mutation, ou créée par `openDirectRequest`. */
369
+ private request;
368
370
  /** Jeton avec lequel agit l'agent. */
369
371
  private readonly token;
370
372
  /** Vrai une fois vérifié que l'agent peut écrire pour sa demande. */
@@ -602,6 +604,20 @@ export declare class Mutation {
602
604
  abortAgentRequest(id: string, reason: string): AgentRequest;
603
605
  /** Demande et jeton de l'agent acteur. */
604
606
  private agentRequest;
607
+ /**
608
+ * Ouvre le lot d'une action directe de l'agent, sans demande : une demande
609
+ * `direct` du propriétaire du jeton, dans l'espace du jeton, prise par ce
610
+ * jeton. Le runner du site n'agit que pour les demandes qu'il prend.
611
+ */
612
+ openDirectRequest(): AgentRequest;
613
+ /** Clôt le lot direct ouvert par `openDirectRequest` : la demande est traitée et son texte (markdown) liste `lines`, une ligne par action du lot. */
614
+ closeDirectRequest(lines: string[]): AgentRequest;
615
+ /**
616
+ * Clôt le lot direct ouvert par `openDirectRequest` en compte rendu : la
617
+ * demande est traitée avec `reply` pour réponse et laisse `followUps` au
618
+ * propriétaire du jeton, qui en est notifié.
619
+ */
620
+ reportDirectRequest(reply: string, followUps: string[]): AgentRequest;
605
621
  /**
606
622
  * L'agent prend sa demande avec son jeton : `pending` devient `processing`
607
623
  * et la demande est réservée à ce jeton. La mise à jour conditionnelle, dans
@@ -811,13 +811,14 @@ export class Store {
811
811
  /**
812
812
  * Échanges clos (traités ou en échec) d'un auteur dans un espace, antérieurs à
813
813
  * la demande `before`, du plus ancien au plus récent : les `limit` derniers.
814
+ * Les lots directs de l'agent n'en sont pas.
814
815
  */
815
816
  listClosedRequestsOfAuthorBefore(spaceId, authorId, before, limit) {
816
817
  if (limit === 0)
817
818
  return [];
818
819
  const rows = this.db
819
820
  .prepare(`SELECT * FROM agent_requests
820
- WHERE target_space_id = @spaceId AND author_id = @authorId AND status IN ('done', 'failed')
821
+ WHERE target_space_id = @spaceId AND author_id = @authorId AND status IN ('done', 'failed') AND kind <> 'direct'
821
822
  AND (created_at < @createdAt OR (created_at = @createdAt AND id < @id))
822
823
  ORDER BY created_at DESC, id DESC LIMIT @limit`)
823
824
  .all({ spaceId, authorId, createdAt: before.createdAt, id: before.id, limit });
@@ -1027,6 +1028,10 @@ export class Store {
1027
1028
  }
1028
1029
  }
1029
1030
  const VERSIONED = new Set(["task", "idea"]);
1031
+ /** Texte d'une demande `direct` dont le lot n'a aucune action. */
1032
+ const DIRECT_REQUEST_TEXT = "Action directe de l'agent";
1033
+ /** Texte d'une demande `direct` qui porte un compte rendu de l'agent et ses points à régler. */
1034
+ const DIRECT_REPORT_TEXT = "Compte rendu de l'agent";
1030
1035
  /**
1031
1036
  * Écritures d'une mutation en cours. Chaque méthode applique une modification
1032
1037
  * et la note ; `finish` vérifie les invariants et écrit versions et journal.
@@ -1043,7 +1048,7 @@ export class Mutation {
1043
1048
  pendingRequestIds = [];
1044
1049
  /** Espaces où la mutation a autorisé le runner. */
1045
1050
  runnerAllowedSpaceIds = [];
1046
- /** Demande pour laquelle agit l'agent, lue au début de la mutation. */
1051
+ /** Demande pour laquelle agit l'agent : lue au début de la mutation, ou créée par `openDirectRequest`. */
1047
1052
  request;
1048
1053
  /** Jeton avec lequel agit l'agent. */
1049
1054
  token;
@@ -1057,7 +1062,7 @@ export class Mutation {
1057
1062
  this.actor = actor;
1058
1063
  this.db = store.db;
1059
1064
  if (actor.type === "agent") {
1060
- this.request = this.loadAgentRequest(actor.requestId);
1065
+ this.request = actor.requestId === null ? null : this.loadAgentRequest(actor.requestId);
1061
1066
  this.token = this.store.findAgentToken(actor.tokenId);
1062
1067
  if (!this.token)
1063
1068
  throw new NotFoundError(`Agent token ${actor.tokenId} not found.`);
@@ -1100,10 +1105,9 @@ export class Mutation {
1100
1105
  * Vérifié à la première écriture d'une entité autre que la demande elle-même.
1101
1106
  */
1102
1107
  assertAgentMayWrite() {
1103
- const request = this.request;
1104
- const token = this.token;
1105
- if (!request || !token || this.agentWriteChecked)
1108
+ if (this.actor.type !== "agent" || this.agentWriteChecked)
1106
1109
  return;
1110
+ const { request, token } = this.agentRequest();
1107
1111
  this.assertRequestInTokenSpace(request, token);
1108
1112
  this.assertClaimedByToken(request, token);
1109
1113
  if (!this.store.isMember(request.targetSpaceId, token.userId)) {
@@ -2101,10 +2105,82 @@ export class Mutation {
2101
2105
  }
2102
2106
  /** Demande et jeton de l'agent acteur. */
2103
2107
  agentRequest() {
2104
- if (!this.request || !this.token)
2108
+ if (!this.token)
2105
2109
  throw new InvariantError("Only the agent can claim, complete or fail a request, or record an agent action.");
2110
+ if (!this.request)
2111
+ throw new InvariantError("The agent acts for a request it claimed, or in a direct batch opened first.");
2106
2112
  return { request: this.request, token: this.token };
2107
2113
  }
2114
+ /**
2115
+ * Ouvre le lot d'une action directe de l'agent, sans demande : une demande
2116
+ * `direct` du propriétaire du jeton, dans l'espace du jeton, prise par ce
2117
+ * jeton. Le runner du site n'agit que pour les demandes qu'il prend.
2118
+ */
2119
+ openDirectRequest() {
2120
+ const token = this.token;
2121
+ if (this.actor.type !== "agent" || this.actor.requestId !== null || !token || this.request) {
2122
+ throw new InvariantError("Only an agent acting without a request can open a direct batch, once per mutation.");
2123
+ }
2124
+ if (token.isRunner)
2125
+ throw new ForbiddenError("The site runner acts only for the requests it claims: pass the request_id of the request you process.");
2126
+ const request = validate(AgentRequestSchema, {
2127
+ id: newId(),
2128
+ authorId: token.userId,
2129
+ targetSpaceId: token.spaceId,
2130
+ kind: "direct",
2131
+ contextTaskId: null,
2132
+ contextIdeaId: null,
2133
+ text: DIRECT_REQUEST_TEXT,
2134
+ status: "processing",
2135
+ reply: null,
2136
+ failureReason: null,
2137
+ parentRequestId: null,
2138
+ commentId: null,
2139
+ createdAt: this.now,
2140
+ updatedAt: this.now,
2141
+ claimedAt: this.now,
2142
+ claimedByTokenId: token.id,
2143
+ completedAt: null,
2144
+ cancelledBy: null,
2145
+ stoppedAt: null,
2146
+ stoppedBy: null,
2147
+ }, "request");
2148
+ this.db
2149
+ .prepare(`INSERT INTO agent_requests (id, author_id, target_space_id, kind, text, status, created_at, updated_at, claimed_at, claimed_by_token_id)
2150
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
2151
+ .run(request.id, request.authorId, request.targetSpaceId, request.kind, request.text, request.status, request.createdAt, request.updatedAt, request.claimedAt, request.claimedByTokenId);
2152
+ this.createdRequestIds.add(request.id);
2153
+ this.request = request;
2154
+ this.touchRequest(request);
2155
+ return request;
2156
+ }
2157
+ /** Clôt le lot direct ouvert par `openDirectRequest` : la demande est traitée et son texte (markdown) liste `lines`, une ligne par action du lot. */
2158
+ closeDirectRequest(lines) {
2159
+ const { request } = this.agentRequest();
2160
+ if (request.kind !== "direct" || request.status !== "processing")
2161
+ throw new InvariantError(`Request ${request.id} is not an open direct batch.`);
2162
+ const text = lines.length === 0 ? DIRECT_REQUEST_TEXT : lines.length === 1 ? lines[0] : lines.map((line) => `- ${line}`).join("\n");
2163
+ this.db.prepare("UPDATE agent_requests SET text = ?, status = 'done', completed_at = ?, updated_at = ? WHERE id = ?").run(text, this.now, this.now, request.id);
2164
+ const closed = this.store.getAgentRequest(request.id);
2165
+ this.request = closed;
2166
+ this.touchRequest(closed);
2167
+ return closed;
2168
+ }
2169
+ /**
2170
+ * Clôt le lot direct ouvert par `openDirectRequest` en compte rendu : la
2171
+ * demande est traitée avec `reply` pour réponse et laisse `followUps` au
2172
+ * propriétaire du jeton, qui en est notifié.
2173
+ */
2174
+ reportDirectRequest(reply, followUps) {
2175
+ const { request } = this.agentRequest();
2176
+ if (request.kind !== "direct" || request.status !== "processing")
2177
+ throw new InvariantError(`Request ${request.id} is not an open direct batch.`);
2178
+ if (followUps.every((point) => point.trim() === ""))
2179
+ throw new OrganizerError("A report leaves at least one point to your token's owner: pass them in follow_ups.");
2180
+ this.db.prepare("UPDATE agent_requests SET text = ? WHERE id = ?").run(DIRECT_REPORT_TEXT, request.id);
2181
+ this.request = this.store.getAgentRequest(request.id);
2182
+ return this.completeAgentRequest(reply, followUps);
2183
+ }
2108
2184
  /**
2109
2185
  * L'agent prend sa demande avec son jeton : `pending` devient `processing`
2110
2186
  * et la demande est réservée à ce jeton. La mise à jour conditionnelle, dans
@@ -1,6 +1,6 @@
1
1
  import { type SiteConnection } from "./client.js";
2
2
  /** Présentation du serveur transmise au client MCP : concepts et déroulé. */
3
- export declare const INSTRUCTIONS = "mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.\n\nYour token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.\n\nConcepts:\n- A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.\n- A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).\n- A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply and the points left to its author) or failed (with the reason). The points left to the author are checkboxes the members tick off. A **follow-up** is a message a member sends from a handled request: claim_request shows that original request, your reply and its points with their ids, and check_follow_ups ticks off the points the follow-up settles. A member can also hand a request to you by mentioning @agent in a comment of a task: claim_request then shows the task's thread, and complete_request posts your reply as a comment right after theirs.\n- A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.\n- A **view** is a tab of a member's dashboard: a layout (kanban, list, matrix), groupings by status or priority, and filters on status, priority and assignees. Each member has their own views in each space.\n- The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it. You change the views of the author of the request you process, and nobody else's: only when the author owns your token, or when you are the site runner.\n\nWork loop, when the user asks you to process the queue:\n1. list_requests to see the pending requests of your space.\n2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, for a message the previous exchanges of its author, task tree, members, recent ideas), along with the custom instructions of the site and of the space, which you follow. get_context shows the space at any time.\n3. Read what you need with get_task and search_tasks.\n4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea, with list_views, create_view, update_view, delete_view when the author asks how their board should look, and with check_follow_ups for a follow-up \u2014 always passing the request_id. Each write is one undoable action of the batch.\n5. complete_request with a short reply in the author's language and, in follow_ups, every point the author still has to handle (or fail_request with the reason), then go back to step 1 until no request is pending.\nWhen the queue is empty, tell the user.\n\nNotifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor, whatever the command (behind mcp-http-gateway, the gateway relay answers in place of this server and gives its own watcher command). Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line \"notifications stopped\" means the site refused the token, and a line \"[gateway-watch] \u2026 la veille \u00E9choue\" means the gateway watcher keeps failing: tell the user. wait_for_requests is the waiting tool of the watcher: you do not need to call it.\n\nHow to handle each kind of request:\n- **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.\n- **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.\n- **remark** and **message**: do whatever is useful \u2014 answer, update or create tasks, comment \u2014 and say what you did in the reply.\n- **idea_promotion**: turn the context idea into a well-formed task with promote_idea.\n\nRules: write titles, descriptions and replies in the language of the users; keep the reply short and factual (markdown is rendered); never bury in the reply something the author must act on: it belongs in follow_ups. Errors tell you what to do next; an error about the token (missing, revoked, expired, owner no longer a member) cannot be fixed by retrying: tell the user.";
3
+ export declare const INSTRUCTIONS = "mcp-organizer connects you to an organizer site: a multi-user task manager where people organize tasks in a web app and queue requests for the AI. You, the connected agent, process those requests when the user asks you to. The site never calls an LLM: you are the intelligence.\n\nYour token covers exactly one space, with the rights of the user who created the token. Every tool works on that space.\n\nConcepts:\n- A **space** holds tasks and an idea box. A user's **personal space** is private; a **shared space** has one owner and members.\n- A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).\n- A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply and the points left to its author) or failed (with the reason). The points left to the author are checkboxes the members tick off. A **follow-up** is a message a member sends from a handled request: claim_request shows that original request, your reply and its points with their ids, and check_follow_ups ticks off the points the follow-up settles. A member can also hand a request to you by mentioning @agent in a comment of a task: claim_request then shows the task's thread, and complete_request posts your reply as a comment right after theirs.\n- A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.\n- A **direct action** is a write you make without request_id, when your user asks you directly (in their editor, for example) rather than through a request: it is done in the name of your token's owner and forms its own batch, listed among the requests of the space as a direct action and undoable like any other. The site runner never acts directly: it always passes the request_id of the request it processes.\n- A **view** is a tab of a member's dashboard: a layout (kanban, list, matrix), groupings by status or priority, and filters on status, priority and assignees. Each member has their own views in each space.\n- The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it. You change the views of the author of the request you process, and nobody else's: only when the author owns your token, or when you are the site runner. A direct action on views changes those of your token's owner.\n\nWork loop, when the user asks you to process the queue:\n1. list_requests to see the pending requests of your space.\n2. claim_request on the oldest one: it becomes processing for you and you get its context (text, author, context task, for a message the previous exchanges of its author, task tree, members, recent ideas), along with the custom instructions of the site and of the space, which you follow. get_context shows the space at any time.\n3. Read what you need with get_task and search_tasks.\n4. Act with create_task, update_task, set_assignees, set_tags, edit_checklist, add_comment, create_idea, update_idea, promote_idea, with list_views, create_view, update_view, delete_view when the author asks how their board should look, and with check_follow_ups for a follow-up \u2014 always passing the request_id. Each write is one undoable action of the batch.\n5. complete_request with a short reply in the author's language and, in follow_ups, every point the author still has to handle (or fail_request with the reason), then go back to step 1 until no request is pending.\nWhen the queue is empty, tell the user.\n\nDirect work, when the user asks you to change the space outside any request: read with get_context, get_task and search_tasks, then call the write tools without request_id. Do not claim, complete or fail anything: there is no request to close. When your user still has points to handle afterwards, leave them with report_direct.\n\nNotifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor, whatever the command (behind mcp-http-gateway, the gateway relay answers in place of this server and gives its own watcher command). Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line \"notifications stopped\" means the site refused the token, and a line \"[gateway-watch] \u2026 la veille \u00E9choue\" means the gateway watcher keeps failing: tell the user. wait_for_requests is the waiting tool of the watcher: you do not need to call it.\n\nHow to handle each kind of request:\n- **idea**: classify it. If it belongs to an existing task or sub-task, attach it there (sub-task, checklist item or comment). If it is actionable and important enough, create a task (or sub-task) with a fitting priority. Otherwise, put it in the idea box with create_idea. Prefer existing tasks over duplicates.\n- **test_review**: feed the tester's findings back into the existing tasks (status, checklist, comments, priority of the affected tasks), or create a task for each problem that has none.\n- **remark** and **message**: do whatever is useful \u2014 answer, update or create tasks, comment \u2014 and say what you did in the reply.\n- **idea_promotion**: turn the context idea into a well-formed task with promote_idea.\n\nRules: write titles, descriptions and replies in the language of the users; keep the reply short and factual (markdown is rendered); never bury in the reply something the author must act on: it belongs in follow_ups. Errors tell you what to do next; an error about the token (missing, revoked, expired, owner no longer a member) cannot be fixed by retrying: tell the user.";
4
4
  /**
5
5
  * Connexion au site d'après `ORGANIZER_URL` et `ORGANIZER_TOKEN` ; une valeur
6
6
  * absente ou invalide, ou une URL http vers une autre machine, est une `ConfigError`.
@@ -18,8 +18,9 @@ Concepts:
18
18
  - A **task** has a title, a markdown description, a status (todo, doing, review, done), a priority (low, medium, high, critical), assignees and tags. Tasks nest on two levels: task > sub-task > sub-sub-task. A task is either standard (with a checklist) or a test (with checkpoints that each tester marks ok, ko, blocked or untested).
19
19
  - A **request** is something a member of your space asked the AI: an idea, a remark, a test review, a message or an idea promotion. It is pending, then processing once you claim it (only your token can then act for it), then done (with your reply and the points left to its author) or failed (with the reason). The points left to the author are checkboxes the members tick off. A **follow-up** is a message a member sends from a handled request: claim_request shows that original request, your reply and its points with their ids, and check_follow_ups ticks off the points the follow-up settles. A member can also hand a request to you by mentioning @agent in a comment of a task: claim_request then shows the task's thread, and complete_request posts your reply as a comment right after theirs.
20
20
  - A **batch** is the set of actions you perform for one request. Every action is logged with its before and after state and with your token, and users can undo one action or the whole batch.
21
+ - A **direct action** is a write you make without request_id, when your user asks you directly (in their editor, for example) rather than through a request: it is done in the name of your token's owner and forms its own batch, listed among the requests of the space as a direct action and undoable like any other. The site runner never acts directly: it always passes the request_id of the request it processes.
21
22
  - A **view** is a tab of a member's dashboard: a layout (kanban, list, matrix), groupings by status or priority, and filters on status, priority and assignees. Each member has their own views in each space.
22
- - The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it. You change the views of the author of the request you process, and nobody else's: only when the author owns your token, or when you are the site runner.
23
+ - The **scope** of your work is the space of your token: you see and process the requests of all its members, and you never act outside it. You change the views of the author of the request you process, and nobody else's: only when the author owns your token, or when you are the site runner. A direct action on views changes those of your token's owner.
23
24
 
24
25
  Work loop, when the user asks you to process the queue:
25
26
  1. list_requests to see the pending requests of your space.
@@ -29,6 +30,8 @@ Work loop, when the user asks you to process the queue:
29
30
  5. complete_request with a short reply in the author's language and, in follow_ups, every point the author still has to handle (or fail_request with the reason), then go back to step 1 until no request is pending.
30
31
  When the queue is empty, tell the user.
31
32
 
33
+ Direct work, when the user asks you to change the space outside any request: read with get_context, get_task and search_tasks, then call the write tools without request_id. Do not claim, complete or fail anything: there is no request to close. When your user still has points to handle afterwards, leave them with report_direct.
34
+
32
35
  Notifications: call enable_notifications once at the start of the session and arm the watcher it hands you with Monitor, whatever the command (behind mcp-http-gateway, the gateway relay answers in place of this server and gives its own watcher command). Each request that becomes pending in your space then arrives on its own as one line (kind, author, excerpt, request id), even while you are idle: process it with the work loop above, starting with claim_request. The host stops that watcher after 30 minutes at most: each time it tells you the watcher expired, re-arm it at once with the same Monitor call; otherwise notifications stop for good. A line "notifications stopped" means the site refused the token, and a line "[gateway-watch] … la veille échoue" means the gateway watcher keeps failing: tell the user. wait_for_requests is the waiting tool of the watcher: you do not need to call it.
33
36
 
34
37
  How to handle each kind of request:
@@ -11,14 +11,14 @@ export class ToolArgumentError extends Error {
11
11
  }
12
12
  const REQUEST_ID = {
13
13
  type: "string",
14
- description: "Id of the request you claimed with claim_request (status processing). Every write is recorded in its batch and can be undone by the users.",
14
+ description: "Id of the request you claimed with claim_request (status processing): the write is recorded in its batch. Omit it only when your user asks you directly, outside any request: the write then forms its own batch, in the name of your token's owner. Either way the users can undo it. The site runner always passes it.",
15
15
  };
16
16
  const TASK_REF = { type: "string", description: "Task of your space: its key (e.g. ORG-41) or its id." };
17
17
  const VIEW_REQUEST_ID = {
18
18
  type: "string",
19
- description: "Id of the request you claimed (status processing): you act on the board views of its author, and every write is recorded in its batch and can be undone by that author.",
19
+ description: "Id of the request you claimed (status processing): you act on the board views of its author, and every write is recorded in its batch and can be undone by that author. Omit it only when your user asks you directly, outside any request: you then act on the views of your token's owner, each write forming its own batch. The site runner always passes it.",
20
20
  };
21
- const VIEW_ID = { type: "string", description: "Id of a view of the request's author, from list_views." };
21
+ const VIEW_ID = { type: "string", description: "Id of a view of the request's author (or of your token's owner), from list_views." };
22
22
  /** Réglages d'une vue, communs à create_view et update_view. */
23
23
  const VIEW_SETTINGS = {
24
24
  name: { type: "string", maxLength: MAX_BOARD_VIEW_NAME_LENGTH, description: "Name of the view, shown as its tab, in the language of the users." },
@@ -65,7 +65,7 @@ export const AGENT_TOOLS = [
65
65
  path: "requests/{request_id}/claim",
66
66
  definition: {
67
67
  name: "claim_request",
68
- description: "Claim a pending request before working on it: it becomes processing for your token only (no other agent can take it or act for it) and you get its full context — text, author, context task or idea, for a message the previous exchanges of its author (their requests and your replies), the task tree of your space with keys, statuses, priorities and assignees, its members and recent ideas. Every write tool then needs this request_id.",
68
+ description: "Claim a pending request before working on it: it becomes processing for your token only (no other agent can take it or act for it) and you get its full context — text, author, context task or idea, for a message the previous exchanges of its author (their requests and your replies), the task tree of your space with keys, statuses, priorities and assignees, its members and recent ideas. Pass this request_id to every write tool while you process it.",
69
69
  inputSchema: {
70
70
  type: "object",
71
71
  properties: { request_id: { type: "string", description: "Id of a pending request, from list_requests." } },
@@ -129,7 +129,7 @@ export const AGENT_TOOLS = [
129
129
  status: { type: "string", enum: [...TASK_STATUSES], description: "Default: todo." },
130
130
  parent: { type: "string", description: "Parent task key (e.g. ORG-41) or id, to create a sub-task." },
131
131
  },
132
- required: ["request_id", "title"],
132
+ required: ["title"],
133
133
  additionalProperties: false,
134
134
  },
135
135
  },
@@ -160,7 +160,7 @@ export const AGENT_TOOLS = [
160
160
  description: "Test tasks only: the task of your space this test verifies (key or id, not the test itself); null removes the link. A task changed to standard loses it.",
161
161
  },
162
162
  },
163
- required: ["request_id", "task"],
163
+ required: ["task"],
164
164
  additionalProperties: false,
165
165
  },
166
166
  },
@@ -178,7 +178,7 @@ export const AGENT_TOOLS = [
178
178
  task: TASK_REF,
179
179
  assignees: { type: "array", items: { type: "string" }, description: "Member ids or e-mails: the complete new list." },
180
180
  },
181
- required: ["request_id", "task", "assignees"],
181
+ required: ["task", "assignees"],
182
182
  additionalProperties: false,
183
183
  },
184
184
  },
@@ -196,7 +196,7 @@ export const AGENT_TOOLS = [
196
196
  task: TASK_REF,
197
197
  tags: { type: "array", items: { type: "string", maxLength: MAX_TAG_LENGTH }, description: "Tag names: the complete new list." },
198
198
  },
199
- required: ["request_id", "task", "tags"],
199
+ required: ["task", "tags"],
200
200
  additionalProperties: false,
201
201
  },
202
202
  },
@@ -229,7 +229,7 @@ export const AGENT_TOOLS = [
229
229
  },
230
230
  },
231
231
  },
232
- required: ["request_id", "task", "operations"],
232
+ required: ["task", "operations"],
233
233
  additionalProperties: false,
234
234
  },
235
235
  },
@@ -247,7 +247,7 @@ export const AGENT_TOOLS = [
247
247
  task: TASK_REF,
248
248
  body: { type: "string", maxLength: MAX_COMMENT_LENGTH, description: "Comment text, in the language of the space." },
249
249
  },
250
- required: ["request_id", "task", "body"],
250
+ required: ["task", "body"],
251
251
  additionalProperties: false,
252
252
  },
253
253
  },
@@ -264,7 +264,7 @@ export const AGENT_TOOLS = [
264
264
  request_id: REQUEST_ID,
265
265
  text: { type: "string", maxLength: MAX_IDEA_LENGTH, description: "The idea, clearly worded, in the language of the space." },
266
266
  },
267
- required: ["request_id", "text"],
267
+ required: ["text"],
268
268
  additionalProperties: false,
269
269
  },
270
270
  },
@@ -283,7 +283,7 @@ export const AGENT_TOOLS = [
283
283
  text: { type: "string", maxLength: MAX_IDEA_LENGTH, description: "New wording." },
284
284
  archived: { type: "boolean" },
285
285
  },
286
- required: ["request_id", "idea_id"],
286
+ required: ["idea_id"],
287
287
  additionalProperties: false,
288
288
  },
289
289
  },
@@ -305,7 +305,7 @@ export const AGENT_TOOLS = [
305
305
  priority: { type: "string", enum: [...TASK_PRIORITIES], description: "Default: medium." },
306
306
  parent: { type: "string", description: "Parent task key or id, to create a sub-task." },
307
307
  },
308
- required: ["request_id", "idea_id", "title"],
308
+ required: ["idea_id", "title"],
309
309
  additionalProperties: false,
310
310
  },
311
311
  },
@@ -315,8 +315,8 @@ export const AGENT_TOOLS = [
315
315
  path: "views",
316
316
  definition: {
317
317
  name: "list_views",
318
- description: "List the board views of the author of a request, in your space: each view is a tab of their dashboard with a layout (kanban, list, matrix), groupings by status or priority, and filters on the status, priority and assignees of the top-level tasks. Read them before changing how someone's board looks.",
319
- inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID }, required: ["request_id"], additionalProperties: false },
318
+ description: "List the board views of the author of a request (without request_id: of your token's owner), in your space: each view is a tab of their dashboard with a layout (kanban, list, matrix), groupings by status or priority, and filters on the status, priority and assignees of the top-level tasks. Read them before changing how someone's board looks.",
319
+ inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID }, additionalProperties: false },
320
320
  },
321
321
  },
322
322
  {
@@ -324,8 +324,8 @@ export const AGENT_TOOLS = [
324
324
  path: "views",
325
325
  definition: {
326
326
  name: "create_view",
327
- description: "Create a board view for the author of a request (e.g. \"show me only my critical tasks, by status\"), after their other tabs; their open dashboard switches to it. Defaults: kanban grouped by status, then_by none (a matrix crosses status and priority), empty groups shown except in a list, no filter. Prefer update_view when the author asks to change a view they have.",
328
- inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, ...VIEW_SETTINGS }, required: ["request_id", "name"], additionalProperties: false },
327
+ description: "Create a board view for the author of a request, or for your token's owner without request_id (e.g. \"show me only my critical tasks, by status\"), after their other tabs; their open dashboard switches to it. Defaults: kanban grouped by status, then_by none (a matrix crosses status and priority), empty groups shown except in a list, no filter. Prefer update_view when the author asks to change a view they have.",
328
+ inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, ...VIEW_SETTINGS }, required: ["name"], additionalProperties: false },
329
329
  },
330
330
  },
331
331
  {
@@ -333,8 +333,8 @@ export const AGENT_TOOLS = [
333
333
  path: "views/{view_id}",
334
334
  definition: {
335
335
  name: "update_view",
336
- description: "Change a board view of the author of a request: name, layout, groupings, empty groups, filters. Only the given settings change; a list (statuses, priorities, assignees) replaces the previous one. Their open dashboard switches to the view.",
337
- inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, view_id: VIEW_ID, ...VIEW_SETTINGS }, required: ["request_id", "view_id"], additionalProperties: false },
336
+ description: "Change a board view of the author of a request (without request_id: of your token's owner): name, layout, groupings, empty groups, filters. Only the given settings change; a list (statuses, priorities, assignees) replaces the previous one. Their open dashboard switches to the view.",
337
+ inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, view_id: VIEW_ID, ...VIEW_SETTINGS }, required: ["view_id"], additionalProperties: false },
338
338
  },
339
339
  },
340
340
  {
@@ -342,8 +342,8 @@ export const AGENT_TOOLS = [
342
342
  path: "views/{view_id}/delete",
343
343
  definition: {
344
344
  name: "delete_view",
345
- description: "Delete a board view of the author of a request, when they ask for it. Their last view cannot be deleted.",
346
- inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, view_id: VIEW_ID }, required: ["request_id", "view_id"], additionalProperties: false },
345
+ description: "Delete a board view of the author of a request (without request_id: of your token's owner), when they ask for it. Their last view cannot be deleted.",
346
+ inputSchema: { type: "object", properties: { request_id: VIEW_REQUEST_ID, view_id: VIEW_ID }, required: ["view_id"], additionalProperties: false },
347
347
  },
348
348
  },
349
349
  {
@@ -391,6 +391,33 @@ export const AGENT_TOOLS = [
391
391
  },
392
392
  },
393
393
  },
394
+ {
395
+ method: "POST",
396
+ path: "requests",
397
+ definition: {
398
+ name: "report_direct",
399
+ description: "After direct work (writes without request_id), leave your token's owner the points they still have to handle: a decision to make, something to check or finish. It adds to the requests of the space a done direct request with your reply and the points as checkboxes; the owner is notified, and the request stays in their waiting list, in orange, until every point is checked. Do not use it while processing a request: complete_request carries its points. The site runner cannot use it.",
400
+ inputSchema: {
401
+ type: "object",
402
+ properties: {
403
+ reply: {
404
+ type: "string",
405
+ maxLength: MAX_REPLY_LENGTH,
406
+ description: "Short markdown report of the direct work, in the owner's language, with task keys (ORG-12). Do not repeat the points here.",
407
+ },
408
+ follow_ups: {
409
+ type: "array",
410
+ minItems: 1,
411
+ maxItems: MAX_FOLLOW_UPS,
412
+ items: { type: "string", maxLength: MAX_FOLLOW_UP_LENGTH },
413
+ description: "What the owner still has to do, one short actionable sentence each.",
414
+ },
415
+ },
416
+ required: ["reply", "follow_ups"],
417
+ additionalProperties: false,
418
+ },
419
+ },
420
+ },
394
421
  {
395
422
  method: "POST",
396
423
  path: "requests/{request_id}/fail",