@imenam/mcp-organizer 1.0.7 → 1.0.9
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.
- package/README.md +107 -28
- package/dist/shared/schemas/admin-api.schema.d.ts +92 -0
- package/dist/shared/schemas/admin-api.schema.js +46 -1
- package/dist/shared/schemas/agent-api.schema.d.ts +31 -4
- package/dist/shared/schemas/agent-api.schema.js +16 -4
- package/dist/shared/schemas/agent-tools.schema.d.ts +14 -0
- package/dist/shared/schemas/agent-tools.schema.js +12 -1
- package/dist/shared/schemas/api.schema.d.ts +17 -0
- package/dist/shared/schemas/api.schema.js +9 -0
- package/dist/shared/schemas/entities.schema.d.ts +63 -0
- package/dist/shared/schemas/entities.schema.js +47 -1
- package/dist/shared/schemas/enums.schema.d.ts +19 -1
- package/dist/shared/schemas/enums.schema.js +8 -0
- package/dist/shared/schemas/instructions-api.schema.d.ts +42 -0
- package/dist/shared/schemas/instructions-api.schema.js +25 -0
- package/dist/shared/schemas/tasks-api.schema.d.ts +5 -0
- package/dist/shared/schemas/tasks-api.schema.js +2 -0
- package/dist/shared/schemas/views-api.schema.d.ts +139 -0
- package/dist/shared/schemas/views-api.schema.js +33 -0
- package/dist/src/agent-api/requests.js +4 -2
- package/dist/src/cli/setup.d.ts +9 -6
- package/dist/src/cli/setup.js +108 -35
- package/dist/src/core/admin.d.ts +21 -1
- package/dist/src/core/admin.js +68 -0
- package/dist/src/core/agent-instructions.d.ts +6 -0
- package/dist/src/core/agent-instructions.js +43 -0
- package/dist/src/core/agent.d.ts +2 -0
- package/dist/src/core/agent.js +16 -2
- package/dist/src/core/board-views.d.ts +12 -0
- package/dist/src/core/board-views.js +84 -0
- package/dist/src/core/migrations.js +71 -0
- package/dist/src/core/requests.d.ts +21 -10
- package/dist/src/core/requests.js +54 -39
- package/dist/src/core/spaces.d.ts +7 -1
- package/dist/src/core/spaces.js +29 -0
- package/dist/src/core/store.d.ts +48 -5
- package/dist/src/core/store.js +213 -16
- package/dist/src/core/tasks.js +1 -0
- package/dist/src/deploy/env-render.d.ts +1 -1
- package/dist/src/deploy/env-render.js +2 -0
- package/dist/src/gui-api.d.ts +12 -1
- package/dist/src/gui-api.js +56 -6
- package/dist/src/mcp/start.d.ts +1 -1
- package/dist/src/mcp/start.js +4 -4
- package/dist/src/mcp/tools.js +13 -3
- package/dist/src/server/claude-processes.d.ts +26 -0
- package/dist/src/server/claude-processes.js +72 -0
- package/dist/src/server/claude-stream.d.ts +39 -0
- package/dist/src/server/claude-stream.js +111 -0
- package/dist/src/server/runner.d.ts +40 -0
- package/dist/src/server/runner.js +157 -24
- package/dist/src/server/start.js +19 -1
- package/gui/dist/assets/index--vL3hM-5.js +70 -0
- package/gui/dist/assets/index-D0rq0343.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/gui/dist/assets/index-DuoSNpBr.js +0 -70
- package/gui/dist/assets/index-duxL0fvO.css +0 -1
package/dist/src/core/spaces.js
CHANGED
|
@@ -83,6 +83,35 @@ export function listMembers(store, userId, spaceId, now = new Date()) {
|
|
|
83
83
|
const invitations = store.listOpenInvitations(spaceId).map((invitation) => invitationView(invitation, now));
|
|
84
84
|
return { space: summary(space, membership), members, invitations };
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Comptes actifs que le propriétaire peut ajouter sans connaître leur adresse :
|
|
88
|
+
* les membres de ses autres espaces communs qui ne sont pas déjà membres de
|
|
89
|
+
* celui-ci, par nom. Tout autre compte ne s'ajoute qu'en saisissant son e-mail.
|
|
90
|
+
*/
|
|
91
|
+
export function listMemberSuggestions(store, userId, spaceId) {
|
|
92
|
+
requireOwner(store, spaceId, userId, "ajouter un membre");
|
|
93
|
+
const sharedSpaces = new Map();
|
|
94
|
+
for (const space of store.listSpacesOf(userId)) {
|
|
95
|
+
if (space.kind !== "shared" || space.id === spaceId)
|
|
96
|
+
continue;
|
|
97
|
+
for (const membership of store.listMemberships(space.id)) {
|
|
98
|
+
if (membership.userId === userId || store.isMember(spaceId, membership.userId))
|
|
99
|
+
continue;
|
|
100
|
+
sharedSpaces.set(membership.userId, [...(sharedSpaces.get(membership.userId) ?? []), space.name]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const suggestions = [...sharedSpaces]
|
|
104
|
+
.map(([id, spaces]) => ({ user: store.getUser(id), spaces }))
|
|
105
|
+
.filter(({ user }) => user.status === "active")
|
|
106
|
+
.sort((a, b) => userName(a.user).localeCompare(userName(b.user), "fr"))
|
|
107
|
+
.map(({ user, spaces }) => ({
|
|
108
|
+
userId: user.id,
|
|
109
|
+
email: user.email,
|
|
110
|
+
displayName: user.displayName,
|
|
111
|
+
sharedSpaces: spaces.sort((a, b) => a.localeCompare(b, "fr")),
|
|
112
|
+
}));
|
|
113
|
+
return { suggestions };
|
|
114
|
+
}
|
|
86
115
|
/** Le propriétaire retire un membre d'un espace commun. */
|
|
87
116
|
export function removeMember(store, userId, spaceId, memberId) {
|
|
88
117
|
store.mutate({ type: "user", userId }, (tx) => {
|
package/dist/src/core/store.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type Database from "better-sqlite3";
|
|
2
2
|
import { WatcherRegistry } from "./watchers.js";
|
|
3
|
-
import { 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 AgentRequest, type AgentToken, type Attachment, type Change, type ChecklistItem, type Comment, type EntityVersion, 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";
|
|
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 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
|
+
import { type RunnerSessionRecord, type RunnerSettings } from "../../shared/schemas/admin-api.schema.js";
|
|
5
6
|
/**
|
|
6
7
|
* Auteur d'une mutation : un utilisateur de la GUI, ou un agent qui agit avec
|
|
7
8
|
* son jeton pour une demande que ce jeton a prise, avec les droits du
|
|
@@ -42,6 +43,12 @@ export declare class Store {
|
|
|
42
43
|
countAdmins(): number;
|
|
43
44
|
/** Préférences de notification propres à un espace, ou null si l'utilisateur y suit celles de son compte. */
|
|
44
45
|
findSpaceNotificationSettings(userId: string, spaceId: string): SpaceNotificationSettings | null;
|
|
46
|
+
/** Limites d'une session du runner. */
|
|
47
|
+
getRunnerSettings(): RunnerSettings;
|
|
48
|
+
/** Sessions du runner commencées depuis `since`, de la plus récente à la plus ancienne. */
|
|
49
|
+
listRunnerSessionsSince(since: string): RunnerSessionRecord[];
|
|
50
|
+
/** Instructions de l'agent propres à un espace, ou celles du site quand `spaceId` est null ; null s'il n'y en a pas. */
|
|
51
|
+
findAgentInstructions(spaceId: string | null): AgentInstructions | null;
|
|
45
52
|
/** Préférences de notification qui s'appliquent à un utilisateur dans un espace : celles de l'espace, sinon celles du compte. */
|
|
46
53
|
notificationPreferences(userId: string, spaceId: string): NotificationPreferences;
|
|
47
54
|
getUserSettings(userId: string): UserSettings;
|
|
@@ -143,6 +150,10 @@ export declare class Store {
|
|
|
143
150
|
listIdeas(spaceId: string): Idea[];
|
|
144
151
|
/** Demandes de promotion (`idea_promotion`) en attente ou en cours sur les idées d'un espace. */
|
|
145
152
|
listOpenPromotionRequests(spaceId: string): AgentRequest[];
|
|
153
|
+
findBoardView(id: string): BoardView | null;
|
|
154
|
+
getBoardView(id: string): BoardView;
|
|
155
|
+
/** Vues d'un membre dans un espace, dans l'ordre des onglets. */
|
|
156
|
+
listBoardViews(spaceId: string, userId: string): BoardView[];
|
|
146
157
|
/** Tâches de test qui vérifient une tâche. */
|
|
147
158
|
listTestsOf(taskId: string): Task[];
|
|
148
159
|
findAgentRequest(id: string): AgentRequest | null;
|
|
@@ -284,6 +295,16 @@ export interface UpdateIdeaInput {
|
|
|
284
295
|
promotedTaskId?: string | null;
|
|
285
296
|
archived?: boolean;
|
|
286
297
|
}
|
|
298
|
+
/** Réglages d'une vue du tableau de bord. */
|
|
299
|
+
export interface BoardViewSettings {
|
|
300
|
+
name: string;
|
|
301
|
+
layout: BoardLayout;
|
|
302
|
+
groupBy: BoardGrouping;
|
|
303
|
+
thenBy: BoardGrouping;
|
|
304
|
+
showEmptyGroups: boolean;
|
|
305
|
+
statuses: TaskStatus[];
|
|
306
|
+
priorities: TaskPriority[];
|
|
307
|
+
}
|
|
287
308
|
/** Action de l'agent à enregistrer dans le lot de sa demande. */
|
|
288
309
|
export interface AgentActionInput {
|
|
289
310
|
entityType: EntityType;
|
|
@@ -527,6 +548,10 @@ export declare class Mutation {
|
|
|
527
548
|
updateIdea(id: string, patch: UpdateIdeaInput): Idea;
|
|
528
549
|
/** Supprime une idée ; sa version de suppression a un instantané nul. */
|
|
529
550
|
deleteIdea(id: string): void;
|
|
551
|
+
/** Ajoute une vue à celles d'un membre dans un espace, après la dernière. */
|
|
552
|
+
createBoardView(spaceId: string, userId: string, settings: BoardViewSettings): BoardView;
|
|
553
|
+
updateBoardView(id: string, patch: Partial<BoardViewSettings>): BoardView;
|
|
554
|
+
deleteBoardView(id: string): void;
|
|
530
555
|
/** Dépose une demande `pending` de l'utilisateur acteur. */
|
|
531
556
|
createAgentRequest(input: CreateAgentRequestInput): AgentRequest;
|
|
532
557
|
/** Note la modification d'une demande, pour son espace. */
|
|
@@ -538,7 +563,16 @@ export declare class Mutation {
|
|
|
538
563
|
/** Annule une demande en attente : l'agent ne la traitera pas. */
|
|
539
564
|
cancelAgentRequest(id: string): AgentRequest;
|
|
540
565
|
/** Repasse en attente une demande `processing` : un agent pourra la reprendre. */
|
|
541
|
-
|
|
566
|
+
/**
|
|
567
|
+
* Stoppe une demande `processing` au nom de l'utilisateur acteur : elle
|
|
568
|
+
* passe en échec, marquée stoppée, avec la raison montrée à son auteur.
|
|
569
|
+
* Le jeton qui l'avait prise ne peut plus agir pour elle.
|
|
570
|
+
*/
|
|
571
|
+
stopAgentRequest(id: string, reason: string): AgentRequest;
|
|
572
|
+
/** Remet en attente une demande stoppée : un agent pourra la reprendre ; les actions déjà faites restent dans son lot. */
|
|
573
|
+
relaunchAgentRequest(id: string): AgentRequest;
|
|
574
|
+
/** Termine en échec une demande `processing` dont l'agent a été arrêté, avec la raison montrée à son auteur. */
|
|
575
|
+
abortAgentRequest(id: string, reason: string): AgentRequest;
|
|
542
576
|
/** Demande et jeton de l'agent acteur. */
|
|
543
577
|
private agentRequest;
|
|
544
578
|
/**
|
|
@@ -547,8 +581,8 @@ export declare class Mutation {
|
|
|
547
581
|
* la transaction exclusive, garantit qu'un seul agent prend une demande donnée.
|
|
548
582
|
*/
|
|
549
583
|
claimAgentRequest(): AgentRequest;
|
|
550
|
-
/** Termine la demande de l'agent avec son message de compte rendu. */
|
|
551
|
-
completeAgentRequest(reply: string): AgentRequest;
|
|
584
|
+
/** Termine la demande de l'agent avec son message de compte rendu et les points que l'auteur doit encore régler. */
|
|
585
|
+
completeAgentRequest(reply: string, followUps: string[]): AgentRequest;
|
|
552
586
|
/** Termine la demande de l'agent en échec, avec la raison montrée à son auteur. */
|
|
553
587
|
failAgentRequest(reason: string): AgentRequest;
|
|
554
588
|
private finishAgentRequest;
|
|
@@ -579,6 +613,15 @@ export declare class Mutation {
|
|
|
579
613
|
* null les retire, et il y suit de nouveau celles de son compte.
|
|
580
614
|
*/
|
|
581
615
|
setSpaceNotificationSettings(userId: string, spaceId: string, preferences: NotificationPreferences | null): SpaceNotificationSettings | null;
|
|
616
|
+
/**
|
|
617
|
+
* Fixe les instructions de l'agent d'un espace, ou celles du site quand
|
|
618
|
+
* `spaceId` est null ; un texte vide les retire.
|
|
619
|
+
*/
|
|
620
|
+
setAgentInstructions(spaceId: string | null, text: string): AgentInstructions | null;
|
|
621
|
+
/** Fixe les limites d'une session du runner. */
|
|
622
|
+
setRunnerSettings(settings: RunnerSettings): RunnerSettings;
|
|
623
|
+
/** Enregistre le relevé d'une session du runner terminée. */
|
|
624
|
+
recordRunnerSession(record: RunnerSessionRecord): void;
|
|
582
625
|
/** Vérifie les invariants sur l'état final, puis écrit les versions et le journal. */
|
|
583
626
|
finish(): void;
|
|
584
627
|
private checkInvariants;
|
package/dist/src/core/store.js
CHANGED
|
@@ -3,8 +3,9 @@ import { ForbiddenError, InvariantError, NotFoundError, OrganizerError } from ".
|
|
|
3
3
|
import { positionBetween } from "../../shared/logic/positions.js";
|
|
4
4
|
import { newId } from "./ids.js";
|
|
5
5
|
import { WatcherRegistry } from "./watchers.js";
|
|
6
|
-
import { MAX_TASK_DEPTH, } from "../../shared/schemas/enums.schema.js";
|
|
7
|
-
import { AccessLinkSchema, AgentActionSchema, AgentTokenSchema, AgentRequestSchema, AttachmentSchema, ChangeSchema, ChecklistItemSchema, CommentSchema, EntityVersionSchema, IdeaSchema, IdeaSnapshotSchema, InvitationSchema, MembershipSchema, NotificationSchema, SessionSchema, SpaceSchema, TagSchema, TaskSchema, TaskSnapshotSchema, TestCheckpointSchema, TestResultSchema, TestReviewSchema, UserSchema, UserSettingsSchema, SpaceNotificationSettingsSchema, } from "../../shared/schemas/entities.schema.js";
|
|
6
|
+
import { MAX_TASK_DEPTH, TASK_PRIORITIES, TASK_STATUSES, } from "../../shared/schemas/enums.schema.js";
|
|
7
|
+
import { AccessLinkSchema, AgentActionSchema, AgentInstructionsSchema, AgentTokenSchema, AgentRequestSchema, AttachmentSchema, BoardViewSchema, ChangeSchema, ChecklistItemSchema, CommentSchema, EntityVersionSchema, IdeaSchema, IdeaSnapshotSchema, InvitationSchema, MembershipSchema, NotificationSchema, SessionSchema, SpaceSchema, TagSchema, TaskSchema, TaskSnapshotSchema, TestCheckpointSchema, TestResultSchema, TestReviewSchema, UserSchema, UserSettingsSchema, SpaceNotificationSettingsSchema, } from "../../shared/schemas/entities.schema.js";
|
|
8
|
+
import { RunnerSessionRecordSchema, RunnerSettingsSchema } from "../../shared/schemas/admin-api.schema.js";
|
|
8
9
|
/** Valide `value` avec `schema` ; une donnée invalide est une erreur métier qui liste les champs fautifs. */
|
|
9
10
|
function validate(schema, value, what) {
|
|
10
11
|
const parsed = schema.safeParse(value);
|
|
@@ -38,6 +39,26 @@ function spaceNotificationSettingsFromRow(row) {
|
|
|
38
39
|
notifyCommentEmail: bool(row.notify_comment_email),
|
|
39
40
|
});
|
|
40
41
|
}
|
|
42
|
+
function agentInstructionsFromRow(row) {
|
|
43
|
+
return AgentInstructionsSchema.parse({ spaceId: row.space_id, text: row.text, updatedAt: row.updated_at, updatedBy: row.updated_by });
|
|
44
|
+
}
|
|
45
|
+
function runnerSessionFromRow(row) {
|
|
46
|
+
return RunnerSessionRecordSchema.parse({
|
|
47
|
+
id: row.id,
|
|
48
|
+
spaceId: row.space_id,
|
|
49
|
+
spaceName: row.space_name,
|
|
50
|
+
startedAt: row.started_at,
|
|
51
|
+
endedAt: row.ended_at,
|
|
52
|
+
outcome: row.outcome,
|
|
53
|
+
model: row.model,
|
|
54
|
+
turns: row.turns,
|
|
55
|
+
costUsd: row.cost_usd,
|
|
56
|
+
inputTokens: row.input_tokens,
|
|
57
|
+
outputTokens: row.output_tokens,
|
|
58
|
+
cacheReadTokens: row.cache_read_tokens,
|
|
59
|
+
cacheCreationTokens: row.cache_creation_tokens,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
41
62
|
/** Les quatre préférences de notification d'un objet qui les porte. */
|
|
42
63
|
function preferencesOf(source) {
|
|
43
64
|
const { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail } = source;
|
|
@@ -144,6 +165,23 @@ function ideaFromRow(row) {
|
|
|
144
165
|
createdAt: row.created_at,
|
|
145
166
|
});
|
|
146
167
|
}
|
|
168
|
+
function boardViewFromRow(row) {
|
|
169
|
+
return BoardViewSchema.parse({
|
|
170
|
+
id: row.id,
|
|
171
|
+
spaceId: row.space_id,
|
|
172
|
+
userId: row.user_id,
|
|
173
|
+
name: row.name,
|
|
174
|
+
layout: row.layout,
|
|
175
|
+
groupBy: row.group_by,
|
|
176
|
+
thenBy: row.then_by,
|
|
177
|
+
showEmptyGroups: bool(row.show_empty_groups),
|
|
178
|
+
statuses: JSON.parse(row.statuses),
|
|
179
|
+
priorities: JSON.parse(row.priorities),
|
|
180
|
+
position: row.position,
|
|
181
|
+
createdAt: row.created_at,
|
|
182
|
+
updatedAt: row.updated_at,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
147
185
|
function requestFromRow(row) {
|
|
148
186
|
return AgentRequestSchema.parse({
|
|
149
187
|
id: row.id,
|
|
@@ -155,6 +193,7 @@ function requestFromRow(row) {
|
|
|
155
193
|
text: row.text,
|
|
156
194
|
status: row.status,
|
|
157
195
|
reply: row.reply,
|
|
196
|
+
followUps: JSON.parse(row.follow_ups),
|
|
158
197
|
failureReason: row.failure_reason,
|
|
159
198
|
createdAt: row.created_at,
|
|
160
199
|
updatedAt: row.updated_at,
|
|
@@ -162,6 +201,8 @@ function requestFromRow(row) {
|
|
|
162
201
|
claimedByTokenId: row.claimed_by_token_id,
|
|
163
202
|
completedAt: row.completed_at,
|
|
164
203
|
cancelledBy: row.cancelled_by,
|
|
204
|
+
stoppedAt: row.stopped_at,
|
|
205
|
+
stoppedBy: row.stopped_by,
|
|
165
206
|
});
|
|
166
207
|
}
|
|
167
208
|
function versionFromRow(row) {
|
|
@@ -340,6 +381,20 @@ export class Store {
|
|
|
340
381
|
const row = this.db.prepare("SELECT * FROM space_notification_settings WHERE user_id = ? AND space_id = ?").get(userId, spaceId);
|
|
341
382
|
return row ? spaceNotificationSettingsFromRow(row) : null;
|
|
342
383
|
}
|
|
384
|
+
/** Limites d'une session du runner. */
|
|
385
|
+
getRunnerSettings() {
|
|
386
|
+
const row = this.db.prepare("SELECT * FROM runner_settings WHERE id = 1").get();
|
|
387
|
+
return RunnerSettingsSchema.parse({ maxTurns: row.max_turns, maxMinutes: row.max_minutes, maxBudgetUsd: row.max_budget_usd });
|
|
388
|
+
}
|
|
389
|
+
/** Sessions du runner commencées depuis `since`, de la plus récente à la plus ancienne. */
|
|
390
|
+
listRunnerSessionsSince(since) {
|
|
391
|
+
return this.db.prepare("SELECT * FROM runner_sessions WHERE started_at >= ? ORDER BY started_at DESC, id").all(since).map(runnerSessionFromRow);
|
|
392
|
+
}
|
|
393
|
+
/** Instructions de l'agent propres à un espace, ou celles du site quand `spaceId` est null ; null s'il n'y en a pas. */
|
|
394
|
+
findAgentInstructions(spaceId) {
|
|
395
|
+
const row = this.db.prepare("SELECT * FROM agent_instructions WHERE space_id IS ?").get(spaceId);
|
|
396
|
+
return row ? agentInstructionsFromRow(row) : null;
|
|
397
|
+
}
|
|
343
398
|
/** Préférences de notification qui s'appliquent à un utilisateur dans un espace : celles de l'espace, sinon celles du compte. */
|
|
344
399
|
notificationPreferences(userId, spaceId) {
|
|
345
400
|
return preferencesOf(this.findSpaceNotificationSettings(userId, spaceId) ?? this.getUserSettings(userId));
|
|
@@ -668,6 +723,22 @@ export class Store {
|
|
|
668
723
|
.all(spaceId);
|
|
669
724
|
return rows.map(requestFromRow);
|
|
670
725
|
}
|
|
726
|
+
// --- Vues du tableau de bord ---
|
|
727
|
+
findBoardView(id) {
|
|
728
|
+
const row = this.db.prepare("SELECT * FROM board_views WHERE id = ?").get(id);
|
|
729
|
+
return row ? boardViewFromRow(row) : null;
|
|
730
|
+
}
|
|
731
|
+
getBoardView(id) {
|
|
732
|
+
const view = this.findBoardView(id);
|
|
733
|
+
if (!view)
|
|
734
|
+
throw new NotFoundError(`Board view ${id} not found.`);
|
|
735
|
+
return view;
|
|
736
|
+
}
|
|
737
|
+
/** Vues d'un membre dans un espace, dans l'ordre des onglets. */
|
|
738
|
+
listBoardViews(spaceId, userId) {
|
|
739
|
+
const rows = this.db.prepare("SELECT * FROM board_views WHERE space_id = ? AND user_id = ? ORDER BY position, id").all(spaceId, userId);
|
|
740
|
+
return rows.map(boardViewFromRow);
|
|
741
|
+
}
|
|
671
742
|
/** Tâches de test qui vérifient une tâche. */
|
|
672
743
|
listTestsOf(taskId) {
|
|
673
744
|
const rows = this.db.prepare("SELECT * FROM tasks WHERE tested_task_id = ? ORDER BY number").all(taskId);
|
|
@@ -1259,6 +1330,7 @@ export class Mutation {
|
|
|
1259
1330
|
throw new NotFoundError(`User ${userId} is not a member of space ${spaceId}.`);
|
|
1260
1331
|
this.db.prepare("DELETE FROM memberships WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
|
|
1261
1332
|
this.db.prepare("DELETE FROM space_notification_settings WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
|
|
1333
|
+
this.db.prepare("DELETE FROM board_views WHERE space_id = ? AND user_id = ?").run(spaceId, userId);
|
|
1262
1334
|
this.touch("membership", `${spaceId}:${userId}`, spaceId, userId);
|
|
1263
1335
|
const tokenIds = this.db.prepare("SELECT id FROM agent_tokens WHERE space_id = ? AND user_id = ? AND revoked_at IS NULL").pluck().all(spaceId, userId);
|
|
1264
1336
|
this.db.prepare("UPDATE agent_tokens SET revoked_at = ? WHERE space_id = ? AND user_id = ? AND revoked_at IS NULL").run(this.now, spaceId, userId);
|
|
@@ -1785,6 +1857,43 @@ export class Mutation {
|
|
|
1785
1857
|
this.db.prepare("DELETE FROM ideas WHERE id = ?").run(id);
|
|
1786
1858
|
this.touch("idea", id, idea.spaceId, null);
|
|
1787
1859
|
}
|
|
1860
|
+
// --- Vues du tableau de bord ---
|
|
1861
|
+
/** Ajoute une vue à celles d'un membre dans un espace, après la dernière. */
|
|
1862
|
+
createBoardView(spaceId, userId, settings) {
|
|
1863
|
+
if (!this.store.findMembership(spaceId, userId))
|
|
1864
|
+
throw new NotFoundError(`User ${userId} is not a member of space ${spaceId}.`);
|
|
1865
|
+
const last = this.db.prepare("SELECT MAX(position) AS max FROM board_views WHERE space_id = ? AND user_id = ?").get(spaceId, userId);
|
|
1866
|
+
const view = validate(BoardViewSchema, {
|
|
1867
|
+
id: newId(),
|
|
1868
|
+
spaceId,
|
|
1869
|
+
userId,
|
|
1870
|
+
...normalizedSettings(settings),
|
|
1871
|
+
position: last.max === null ? 1 : Math.floor(last.max) + 1,
|
|
1872
|
+
createdAt: this.now,
|
|
1873
|
+
updatedAt: this.now,
|
|
1874
|
+
}, "board view");
|
|
1875
|
+
this.db
|
|
1876
|
+
.prepare(`INSERT INTO board_views (id, space_id, user_id, name, layout, group_by, then_by, show_empty_groups, statuses, priorities, position, created_at, updated_at)
|
|
1877
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
1878
|
+
.run(view.id, view.spaceId, view.userId, view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), view.position, view.createdAt, view.updatedAt);
|
|
1879
|
+
this.touch("board_view", view.id, null, userId);
|
|
1880
|
+
return view;
|
|
1881
|
+
}
|
|
1882
|
+
updateBoardView(id, patch) {
|
|
1883
|
+
const current = this.store.getBoardView(id);
|
|
1884
|
+
const view = validate(BoardViewSchema, { ...current, ...normalizedSettings({ ...current, ...definedFields(patch) }), updatedAt: this.now }, "board view");
|
|
1885
|
+
this.db
|
|
1886
|
+
.prepare(`UPDATE board_views SET name = ?, layout = ?, group_by = ?, then_by = ?, show_empty_groups = ?, statuses = ?, priorities = ?, updated_at = ?
|
|
1887
|
+
WHERE id = ?`)
|
|
1888
|
+
.run(view.name, view.layout, view.groupBy, view.thenBy, view.showEmptyGroups ? 1 : 0, JSON.stringify(view.statuses), JSON.stringify(view.priorities), view.updatedAt, id);
|
|
1889
|
+
this.touch("board_view", id, null, view.userId);
|
|
1890
|
+
return view;
|
|
1891
|
+
}
|
|
1892
|
+
deleteBoardView(id) {
|
|
1893
|
+
const view = this.store.getBoardView(id);
|
|
1894
|
+
this.db.prepare("DELETE FROM board_views WHERE id = ?").run(id);
|
|
1895
|
+
this.touch("board_view", id, null, view.userId);
|
|
1896
|
+
}
|
|
1788
1897
|
// --- Demandes ---
|
|
1789
1898
|
/** Dépose une demande `pending` de l'utilisateur acteur. */
|
|
1790
1899
|
createAgentRequest(input) {
|
|
@@ -1800,6 +1909,7 @@ export class Mutation {
|
|
|
1800
1909
|
text: input.text,
|
|
1801
1910
|
status: "pending",
|
|
1802
1911
|
reply: null,
|
|
1912
|
+
followUps: [],
|
|
1803
1913
|
failureReason: null,
|
|
1804
1914
|
createdAt: this.now,
|
|
1805
1915
|
updatedAt: this.now,
|
|
@@ -1807,6 +1917,8 @@ export class Mutation {
|
|
|
1807
1917
|
claimedByTokenId: null,
|
|
1808
1918
|
completedAt: null,
|
|
1809
1919
|
cancelledBy: null,
|
|
1920
|
+
stoppedAt: null,
|
|
1921
|
+
stoppedBy: null,
|
|
1810
1922
|
}, "request");
|
|
1811
1923
|
this.store.getSpace(request.targetSpaceId);
|
|
1812
1924
|
this.db
|
|
@@ -1853,17 +1965,51 @@ export class Mutation {
|
|
|
1853
1965
|
return request;
|
|
1854
1966
|
}
|
|
1855
1967
|
/** Repasse en attente une demande `processing` : un agent pourra la reprendre. */
|
|
1856
|
-
|
|
1968
|
+
/**
|
|
1969
|
+
* Stoppe une demande `processing` au nom de l'utilisateur acteur : elle
|
|
1970
|
+
* passe en échec, marquée stoppée, avec la raison montrée à son auteur.
|
|
1971
|
+
* Le jeton qui l'avait prise ne peut plus agir pour elle.
|
|
1972
|
+
*/
|
|
1973
|
+
stopAgentRequest(id, reason) {
|
|
1857
1974
|
if (this.actor.type !== "user")
|
|
1858
|
-
throw new InvariantError("Only a user can
|
|
1975
|
+
throw new InvariantError("Only a user can stop a request.");
|
|
1859
1976
|
const current = this.store.getAgentRequest(id);
|
|
1860
1977
|
if (current.status !== "processing")
|
|
1861
|
-
throw new InvariantError(`Request ${id} is ${current.status}: only a processing request can be
|
|
1862
|
-
this.db
|
|
1863
|
-
|
|
1978
|
+
throw new InvariantError(`Request ${id} is ${current.status}: only a processing request can be stopped.`);
|
|
1979
|
+
this.db
|
|
1980
|
+
.prepare("UPDATE agent_requests SET status = 'failed', failure_reason = ?, stopped_at = ?, stopped_by = ?, completed_at = ?, updated_at = ? WHERE id = ?")
|
|
1981
|
+
.run(reason, this.now, this.actingUserId, this.now, this.now, id);
|
|
1982
|
+
const stopped = this.store.getAgentRequest(id);
|
|
1983
|
+
this.touchRequest(stopped);
|
|
1984
|
+
return stopped;
|
|
1985
|
+
}
|
|
1986
|
+
/** Remet en attente une demande stoppée : un agent pourra la reprendre ; les actions déjà faites restent dans son lot. */
|
|
1987
|
+
relaunchAgentRequest(id) {
|
|
1988
|
+
if (this.actor.type !== "user")
|
|
1989
|
+
throw new InvariantError("Only a user can relaunch a request.");
|
|
1990
|
+
const current = this.store.getAgentRequest(id);
|
|
1991
|
+
if (current.status !== "failed" || current.stoppedAt === null)
|
|
1992
|
+
throw new InvariantError(`Request ${id} is ${current.status}: only a stopped request can be relaunched.`);
|
|
1993
|
+
this.db
|
|
1994
|
+
.prepare(`UPDATE agent_requests SET status = 'pending', claimed_at = NULL, claimed_by_token_id = NULL, completed_at = NULL, failure_reason = NULL,
|
|
1995
|
+
follow_ups = '[]', stopped_at = NULL, stopped_by = NULL, updated_at = ? WHERE id = ?`)
|
|
1996
|
+
.run(this.now, id);
|
|
1997
|
+
const relaunched = this.store.getAgentRequest(id);
|
|
1864
1998
|
this.pendingRequestIds.push(id);
|
|
1865
|
-
this.touchRequest(
|
|
1866
|
-
return
|
|
1999
|
+
this.touchRequest(relaunched);
|
|
2000
|
+
return relaunched;
|
|
2001
|
+
}
|
|
2002
|
+
/** Termine en échec une demande `processing` dont l'agent a été arrêté, avec la raison montrée à son auteur. */
|
|
2003
|
+
abortAgentRequest(id, reason) {
|
|
2004
|
+
if (this.actor.type !== "user")
|
|
2005
|
+
throw new InvariantError("Only a user can abort a request.");
|
|
2006
|
+
const current = this.store.getAgentRequest(id);
|
|
2007
|
+
if (current.status !== "processing")
|
|
2008
|
+
throw new InvariantError(`Request ${id} is ${current.status}: only a processing request can be aborted.`);
|
|
2009
|
+
this.db.prepare("UPDATE agent_requests SET status = 'failed', failure_reason = ?, completed_at = ?, updated_at = ? WHERE id = ?").run(reason, this.now, this.now, id);
|
|
2010
|
+
const aborted = this.store.getAgentRequest(id);
|
|
2011
|
+
this.touchRequest(aborted);
|
|
2012
|
+
return aborted;
|
|
1867
2013
|
}
|
|
1868
2014
|
/** Demande et jeton de l'agent acteur. */
|
|
1869
2015
|
agentRequest() {
|
|
@@ -1889,15 +2035,15 @@ export class Mutation {
|
|
|
1889
2035
|
this.touchRequest(claimed);
|
|
1890
2036
|
return claimed;
|
|
1891
2037
|
}
|
|
1892
|
-
/** Termine la demande de l'agent avec son message de compte rendu. */
|
|
1893
|
-
completeAgentRequest(reply) {
|
|
1894
|
-
return this.finishAgentRequest("done", reply, "reply");
|
|
2038
|
+
/** Termine la demande de l'agent avec son message de compte rendu et les points que l'auteur doit encore régler. */
|
|
2039
|
+
completeAgentRequest(reply, followUps) {
|
|
2040
|
+
return this.finishAgentRequest("done", reply, "reply", followUps);
|
|
1895
2041
|
}
|
|
1896
2042
|
/** Termine la demande de l'agent en échec, avec la raison montrée à son auteur. */
|
|
1897
2043
|
failAgentRequest(reason) {
|
|
1898
|
-
return this.finishAgentRequest("failed", reason, "reason");
|
|
2044
|
+
return this.finishAgentRequest("failed", reason, "reason", []);
|
|
1899
2045
|
}
|
|
1900
|
-
finishAgentRequest(status, message, what) {
|
|
2046
|
+
finishAgentRequest(status, message, what, followUps) {
|
|
1901
2047
|
const { request, token } = this.agentRequest();
|
|
1902
2048
|
this.assertRequestInTokenSpace(request, token);
|
|
1903
2049
|
if (request.status !== "processing") {
|
|
@@ -1908,9 +2054,10 @@ export class Mutation {
|
|
|
1908
2054
|
if (text === "")
|
|
1909
2055
|
throw new OrganizerError(`The ${what} is empty: write a short message for the author of the request.`);
|
|
1910
2056
|
const column = status === "done" ? "reply" : "failure_reason";
|
|
2057
|
+
const points = followUps.map((point) => point.trim()).filter((point) => point !== "");
|
|
1911
2058
|
this.db
|
|
1912
|
-
.prepare(`UPDATE agent_requests SET status = ?, ${column} = ?, completed_at = ?, updated_at = ? WHERE id = ?`)
|
|
1913
|
-
.run(status, text, this.now, this.now, request.id);
|
|
2059
|
+
.prepare(`UPDATE agent_requests SET status = ?, ${column} = ?, follow_ups = ?, completed_at = ?, updated_at = ? WHERE id = ?`)
|
|
2060
|
+
.run(status, text, JSON.stringify(points), this.now, this.now, request.id);
|
|
1914
2061
|
const finished = this.store.getAgentRequest(request.id);
|
|
1915
2062
|
this.touchRequest(finished);
|
|
1916
2063
|
return finished;
|
|
@@ -2056,6 +2203,43 @@ export class Mutation {
|
|
|
2056
2203
|
.run(userId, spaceId, settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0);
|
|
2057
2204
|
return settings;
|
|
2058
2205
|
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Fixe les instructions de l'agent d'un espace, ou celles du site quand
|
|
2208
|
+
* `spaceId` est null ; un texte vide les retire.
|
|
2209
|
+
*/
|
|
2210
|
+
setAgentInstructions(spaceId, text) {
|
|
2211
|
+
if (this.actor.type !== "user")
|
|
2212
|
+
throw new InvariantError("Only a user can change the agent instructions.");
|
|
2213
|
+
if (spaceId !== null)
|
|
2214
|
+
this.store.getSpace(spaceId);
|
|
2215
|
+
this.touch("agent_instructions", spaceId ?? "site", spaceId, null);
|
|
2216
|
+
this.db.prepare("DELETE FROM agent_instructions WHERE space_id IS ?").run(spaceId);
|
|
2217
|
+
if (text.trim() === "")
|
|
2218
|
+
return null;
|
|
2219
|
+
const instructions = validate(AgentInstructionsSchema, { spaceId, text, updatedAt: this.now, updatedBy: this.actor.userId }, "agent instructions");
|
|
2220
|
+
this.db
|
|
2221
|
+
.prepare("INSERT INTO agent_instructions (space_id, text, updated_at, updated_by) VALUES (?, ?, ?, ?)")
|
|
2222
|
+
.run(instructions.spaceId, instructions.text, instructions.updatedAt, instructions.updatedBy);
|
|
2223
|
+
return instructions;
|
|
2224
|
+
}
|
|
2225
|
+
/** Fixe les limites d'une session du runner. */
|
|
2226
|
+
setRunnerSettings(settings) {
|
|
2227
|
+
if (this.actor.type !== "user")
|
|
2228
|
+
throw new InvariantError("Only a user can change the runner settings.");
|
|
2229
|
+
const valid = validate(RunnerSettingsSchema, settings, "runner settings");
|
|
2230
|
+
this.db
|
|
2231
|
+
.prepare("UPDATE runner_settings SET max_turns = ?, max_minutes = ?, max_budget_usd = ?, updated_at = ?, updated_by = ? WHERE id = 1")
|
|
2232
|
+
.run(valid.maxTurns, valid.maxMinutes, valid.maxBudgetUsd, this.now, this.actor.userId);
|
|
2233
|
+
return valid;
|
|
2234
|
+
}
|
|
2235
|
+
/** Enregistre le relevé d'une session du runner terminée. */
|
|
2236
|
+
recordRunnerSession(record) {
|
|
2237
|
+
const valid = validate(RunnerSessionRecordSchema, record, "runner session");
|
|
2238
|
+
this.db
|
|
2239
|
+
.prepare(`INSERT INTO runner_sessions (id, space_id, space_name, started_at, ended_at, outcome, model, turns, cost_usd, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens)
|
|
2240
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
2241
|
+
.run(valid.id, valid.spaceId, valid.spaceName, valid.startedAt, valid.endedAt, valid.outcome, valid.model, valid.turns, valid.costUsd, valid.inputTokens, valid.outputTokens, valid.cacheReadTokens, valid.cacheCreationTokens);
|
|
2242
|
+
}
|
|
2059
2243
|
// --- Fin de mutation ---
|
|
2060
2244
|
/** Vérifie les invariants sur l'état final, puis écrit les versions et le journal. */
|
|
2061
2245
|
finish() {
|
|
@@ -2236,6 +2420,19 @@ export class Mutation {
|
|
|
2236
2420
|
}
|
|
2237
2421
|
}
|
|
2238
2422
|
}
|
|
2423
|
+
/** Réglages d'une vue avec des filtres sans doublon, dans l'ordre des statuts et des priorités. */
|
|
2424
|
+
function normalizedSettings(settings) {
|
|
2425
|
+
const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities } = settings;
|
|
2426
|
+
return {
|
|
2427
|
+
name,
|
|
2428
|
+
layout,
|
|
2429
|
+
groupBy,
|
|
2430
|
+
thenBy,
|
|
2431
|
+
showEmptyGroups,
|
|
2432
|
+
statuses: TASK_STATUSES.filter((status) => statuses.includes(status)),
|
|
2433
|
+
priorities: TASK_PRIORITIES.filter((priority) => priorities.includes(priority)),
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2239
2436
|
/** Champs de `patch` dont la valeur n'est pas `undefined`. */
|
|
2240
2437
|
function definedFields(patch) {
|
|
2241
2438
|
return Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined));
|
package/dist/src/core/tasks.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* variables gérées absentes du fichier sont ajoutées à la fin.
|
|
8
8
|
*/
|
|
9
9
|
/** Variables écrites par le setup, dans l'ordre d'un fichier neuf. */
|
|
10
|
-
export declare const MANAGED_ENV_KEYS: readonly ["ORGANIZER_PUBLIC_URL", "ORGANIZER_BASE_PATH", "PORT", "HOST", "ORGANIZER_TRUST_PROXY", "MCP_ORGANIZER_DATA_DIR", "GROQ_API_KEY", "ORGANIZER_TRANSCRIBE_MODEL", "SMTP_URL", "MAIL_FROM"];
|
|
10
|
+
export declare const MANAGED_ENV_KEYS: readonly ["ORGANIZER_PUBLIC_URL", "ORGANIZER_BASE_PATH", "PORT", "HOST", "ORGANIZER_TRUST_PROXY", "MCP_ORGANIZER_DATA_DIR", "GROQ_API_KEY", "ORGANIZER_TRANSCRIBE_MODEL", "SMTP_URL", "MAIL_FROM", "ORGANIZER_RUNNER_CLAUDE"];
|
|
11
11
|
export type ManagedEnvKey = (typeof MANAGED_ENV_KEYS)[number];
|
|
12
12
|
/**
|
|
13
13
|
* Variables d'amorçage du premier compte : le setup crée le compte en base et
|
|
@@ -18,6 +18,7 @@ export const MANAGED_ENV_KEYS = [
|
|
|
18
18
|
"ORGANIZER_TRANSCRIBE_MODEL",
|
|
19
19
|
"SMTP_URL",
|
|
20
20
|
"MAIL_FROM",
|
|
21
|
+
"ORGANIZER_RUNNER_CLAUDE",
|
|
21
22
|
];
|
|
22
23
|
/**
|
|
23
24
|
* Variables d'amorçage du premier compte : le setup crée le compte en base et
|
|
@@ -51,6 +52,7 @@ const COMMENTS = {
|
|
|
51
52
|
ORGANIZER_PUBLIC_URL: "# URL ouverte par les utilisateurs, derrière nginx.",
|
|
52
53
|
PORT: "# Écoute du site ; nginx le joint à cette adresse.",
|
|
53
54
|
MCP_ORGANIZER_DATA_DIR: "# Base SQLite, pièces jointes et journaux.",
|
|
55
|
+
ORGANIZER_RUNNER_CLAUDE: "# Claude Code du runner, connecté pour le compte du site.",
|
|
54
56
|
GROQ_API_KEY: "# Dictée vocale (Groq).",
|
|
55
57
|
SMTP_URL: "# Envoi des e-mails (invitations, notifications).",
|
|
56
58
|
};
|
package/dist/src/gui-api.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ApiRequestData, type ApiResponseData, type ApiErrorKind } from "../shared/schemas/gui-api.schema.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type RunnerFailure } from "../shared/schemas/agent-api.schema.js";
|
|
3
|
+
import { type KillAllResponse, type RunnerStatus } from "../shared/schemas/admin-api.schema.js";
|
|
3
4
|
import type { AttachmentStorage } from "./core/attachments.js";
|
|
4
5
|
import type { Mailer } from "./core/mail.js";
|
|
5
6
|
import type { Store } from "./core/store.js";
|
|
@@ -31,6 +32,16 @@ export interface GuiApiContext {
|
|
|
31
32
|
runner: {
|
|
32
33
|
status: RunnerStatus;
|
|
33
34
|
runNow: ((spaceId: string) => void) | null;
|
|
35
|
+
/** Dernière session du runner dans un espace, quand elle a échoué. */
|
|
36
|
+
lastFailure: (spaceId: string) => RunnerFailure | null;
|
|
37
|
+
/** Session du runner en cours dans un espace. */
|
|
38
|
+
currentSession: (spaceId: string) => {
|
|
39
|
+
startedAt: string;
|
|
40
|
+
} | null;
|
|
41
|
+
/** Arrête la session en cours dans un espace ; rend les demandes passées en échec, null sans session (null quand le runner est désactivé). */
|
|
42
|
+
stopSession: ((spaceId: string, userId: string) => number | null) | null;
|
|
43
|
+
/** Arrêt d'urgence : tue tous les processus Claude Code de la machine du site. */
|
|
44
|
+
killAll: (userId: string) => Promise<KillAllResponse>;
|
|
34
45
|
};
|
|
35
46
|
/** Horloge, imposée par les tests. */
|
|
36
47
|
now?: () => Date;
|