claude-sessions-mcp 0.3.0 → 0.4.1-beta.0

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 (108) hide show
  1. package/README.md +25 -78
  2. package/dist/index.js +402 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +20 -67
  5. package/dist/chunk-7MUU7A32.js +0 -47
  6. package/dist/chunk-7MUU7A32.js.map +0 -1
  7. package/dist/mcp/index.js +0 -714
  8. package/dist/mcp/index.js.map +0 -1
  9. package/dist/server.d.ts +0 -10
  10. package/dist/server.js +0 -9
  11. package/dist/server.js.map +0 -1
  12. package/dist/web/client/_app/immutable/assets/0.XO-DXdC4.css +0 -1
  13. package/dist/web/client/_app/immutable/assets/0.XO-DXdC4.css.br +0 -0
  14. package/dist/web/client/_app/immutable/assets/0.XO-DXdC4.css.gz +0 -0
  15. package/dist/web/client/_app/immutable/chunks/B2IHY0Hs.js +0 -1
  16. package/dist/web/client/_app/immutable/chunks/B2IHY0Hs.js.br +0 -0
  17. package/dist/web/client/_app/immutable/chunks/B2IHY0Hs.js.gz +0 -0
  18. package/dist/web/client/_app/immutable/chunks/BCJVXGHY.js +0 -1
  19. package/dist/web/client/_app/immutable/chunks/BCJVXGHY.js.br +0 -0
  20. package/dist/web/client/_app/immutable/chunks/BCJVXGHY.js.gz +0 -0
  21. package/dist/web/client/_app/immutable/chunks/CMwK7N_O.js +0 -1
  22. package/dist/web/client/_app/immutable/chunks/CMwK7N_O.js.br +0 -0
  23. package/dist/web/client/_app/immutable/chunks/CMwK7N_O.js.gz +0 -0
  24. package/dist/web/client/_app/immutable/chunks/CZTho13P.js +0 -1
  25. package/dist/web/client/_app/immutable/chunks/CZTho13P.js.br +0 -0
  26. package/dist/web/client/_app/immutable/chunks/CZTho13P.js.gz +0 -0
  27. package/dist/web/client/_app/immutable/chunks/F-H9hLgW.js +0 -2
  28. package/dist/web/client/_app/immutable/chunks/F-H9hLgW.js.br +0 -0
  29. package/dist/web/client/_app/immutable/chunks/F-H9hLgW.js.gz +0 -0
  30. package/dist/web/client/_app/immutable/chunks/gR9AL7GA.js +0 -2
  31. package/dist/web/client/_app/immutable/chunks/gR9AL7GA.js.br +0 -0
  32. package/dist/web/client/_app/immutable/chunks/gR9AL7GA.js.gz +0 -0
  33. package/dist/web/client/_app/immutable/entry/app.Boej0hfY.js +0 -2
  34. package/dist/web/client/_app/immutable/entry/app.Boej0hfY.js.br +0 -0
  35. package/dist/web/client/_app/immutable/entry/app.Boej0hfY.js.gz +0 -0
  36. package/dist/web/client/_app/immutable/entry/start.CVYJWPd9.js +0 -1
  37. package/dist/web/client/_app/immutable/entry/start.CVYJWPd9.js.br +0 -2
  38. package/dist/web/client/_app/immutable/entry/start.CVYJWPd9.js.gz +0 -0
  39. package/dist/web/client/_app/immutable/nodes/0.Lbeu1dpo.js +0 -1
  40. package/dist/web/client/_app/immutable/nodes/0.Lbeu1dpo.js.br +0 -0
  41. package/dist/web/client/_app/immutable/nodes/0.Lbeu1dpo.js.gz +0 -0
  42. package/dist/web/client/_app/immutable/nodes/1.DvRsCtcA.js +0 -1
  43. package/dist/web/client/_app/immutable/nodes/1.DvRsCtcA.js.br +0 -0
  44. package/dist/web/client/_app/immutable/nodes/1.DvRsCtcA.js.gz +0 -0
  45. package/dist/web/client/_app/immutable/nodes/2.CjVN0Bwe.js +0 -73
  46. package/dist/web/client/_app/immutable/nodes/2.CjVN0Bwe.js.br +0 -0
  47. package/dist/web/client/_app/immutable/nodes/2.CjVN0Bwe.js.gz +0 -0
  48. package/dist/web/client/_app/version.json +0 -1
  49. package/dist/web/client/_app/version.json.br +0 -0
  50. package/dist/web/client/_app/version.json.gz +0 -0
  51. package/dist/web/client/favicon.png +0 -0
  52. package/dist/web/env.js +0 -45
  53. package/dist/web/handler.js +0 -1390
  54. package/dist/web/index.js +0 -334
  55. package/dist/web/server/chunks/0-C_hzGzlo.js +0 -17
  56. package/dist/web/server/chunks/0-C_hzGzlo.js.map +0 -1
  57. package/dist/web/server/chunks/1-CSNAjAzD.js +0 -9
  58. package/dist/web/server/chunks/1-CSNAjAzD.js.map +0 -1
  59. package/dist/web/server/chunks/2-D_ZAFGkV.js +0 -9
  60. package/dist/web/server/chunks/2-D_ZAFGkV.js.map +0 -1
  61. package/dist/web/server/chunks/_layout.svelte-BWDuddeu.js +0 -33
  62. package/dist/web/server/chunks/_layout.svelte-BWDuddeu.js.map +0 -1
  63. package/dist/web/server/chunks/_page.svelte-BTPPI5f9.js +0 -113
  64. package/dist/web/server/chunks/_page.svelte-BTPPI5f9.js.map +0 -1
  65. package/dist/web/server/chunks/_server.ts-B0JVJ9FB.js +0 -28
  66. package/dist/web/server/chunks/_server.ts-B0JVJ9FB.js.map +0 -1
  67. package/dist/web/server/chunks/_server.ts-BLGLFyUk.js +0 -19
  68. package/dist/web/server/chunks/_server.ts-BLGLFyUk.js.map +0 -1
  69. package/dist/web/server/chunks/_server.ts-BaqmP9oG.js +0 -14
  70. package/dist/web/server/chunks/_server.ts-BaqmP9oG.js.map +0 -1
  71. package/dist/web/server/chunks/_server.ts-Beze9L3_.js +0 -19
  72. package/dist/web/server/chunks/_server.ts-Beze9L3_.js.map +0 -1
  73. package/dist/web/server/chunks/_server.ts-BlgHsHoW.js +0 -8
  74. package/dist/web/server/chunks/_server.ts-BlgHsHoW.js.map +0 -1
  75. package/dist/web/server/chunks/_server.ts-Bw_uJ6TN.js +0 -11
  76. package/dist/web/server/chunks/_server.ts-Bw_uJ6TN.js.map +0 -1
  77. package/dist/web/server/chunks/_server.ts-CHX8x48n.js +0 -27
  78. package/dist/web/server/chunks/_server.ts-CHX8x48n.js.map +0 -1
  79. package/dist/web/server/chunks/_server.ts-Cb5-fa8C.js +0 -37
  80. package/dist/web/server/chunks/_server.ts-Cb5-fa8C.js.map +0 -1
  81. package/dist/web/server/chunks/_server.ts-ChE2aT-W.js +0 -29
  82. package/dist/web/server/chunks/_server.ts-ChE2aT-W.js.map +0 -1
  83. package/dist/web/server/chunks/_server.ts-Cksv90lD.js +0 -18
  84. package/dist/web/server/chunks/_server.ts-Cksv90lD.js.map +0 -1
  85. package/dist/web/server/chunks/_server.ts-D80JJ66s.js +0 -26
  86. package/dist/web/server/chunks/_server.ts-D80JJ66s.js.map +0 -1
  87. package/dist/web/server/chunks/_server.ts-DjWf5N-i.js +0 -18
  88. package/dist/web/server/chunks/_server.ts-DjWf5N-i.js.map +0 -1
  89. package/dist/web/server/chunks/_server.ts-DmMLJ93T.js +0 -18
  90. package/dist/web/server/chunks/_server.ts-DmMLJ93T.js.map +0 -1
  91. package/dist/web/server/chunks/context-R2425nfV.js +0 -64
  92. package/dist/web/server/chunks/context-R2425nfV.js.map +0 -1
  93. package/dist/web/server/chunks/error.svelte-DazOwnSn.js +0 -45
  94. package/dist/web/server/chunks/error.svelte-DazOwnSn.js.map +0 -1
  95. package/dist/web/server/chunks/exports-BzHwARwz.js +0 -326
  96. package/dist/web/server/chunks/exports-BzHwARwz.js.map +0 -1
  97. package/dist/web/server/chunks/index-CXFDTUAl.js +0 -913
  98. package/dist/web/server/chunks/index-CXFDTUAl.js.map +0 -1
  99. package/dist/web/server/chunks/index-CoD1IJuy.js +0 -190
  100. package/dist/web/server/chunks/index-CoD1IJuy.js.map +0 -1
  101. package/dist/web/server/chunks/session-DmOGNZUD.js +0 -781
  102. package/dist/web/server/chunks/session-DmOGNZUD.js.map +0 -1
  103. package/dist/web/server/index.js +0 -7938
  104. package/dist/web/server/index.js.map +0 -1
  105. package/dist/web/server/manifest.js +0 -137
  106. package/dist/web/server/manifest.js.map +0 -1
  107. package/dist/web/shims.js +0 -32
  108. /package/dist/{mcp/index.d.ts → index.d.ts} +0 -0
package/dist/mcp/index.js DELETED
@@ -1,714 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- startWebServer,
4
- stopWebServer
5
- } from "../chunk-7MUU7A32.js";
6
-
7
- // src/mcp/index.ts
8
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
9
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
10
- import { Effect as Effect3 } from "effect";
11
- import { z } from "zod";
12
-
13
- // src/lib/session.ts
14
- import { Effect as Effect2, pipe, Array as A, Option as O } from "effect";
15
- import * as fs2 from "fs/promises";
16
- import * as path2 from "path";
17
-
18
- // src/lib/shared/session-core.ts
19
- import { Effect } from "effect";
20
- import * as fs from "fs/promises";
21
- import * as path from "path";
22
- import * as os from "os";
23
- var getSessionsDir = () => path.join(os.homedir(), ".claude", "projects");
24
- var getTodosDir = () => path.join(os.homedir(), ".claude", "todos");
25
- var findLinkedAgents = (projectName, sessionId) => Effect.gen(function* () {
26
- const projectPath = path.join(getSessionsDir(), projectName);
27
- const files = yield* Effect.tryPromise(() => fs.readdir(projectPath));
28
- const agentFiles = files.filter((f) => f.startsWith("agent-") && f.endsWith(".jsonl"));
29
- const linkedAgents = [];
30
- for (const agentFile of agentFiles) {
31
- const filePath = path.join(projectPath, agentFile);
32
- const content = yield* Effect.tryPromise(() => fs.readFile(filePath, "utf-8"));
33
- const firstLine = content.split("\n")[0];
34
- if (firstLine) {
35
- try {
36
- const parsed = JSON.parse(firstLine);
37
- if (parsed.sessionId === sessionId) {
38
- linkedAgents.push(agentFile.replace(".jsonl", ""));
39
- }
40
- } catch {
41
- }
42
- }
43
- }
44
- return linkedAgents;
45
- });
46
- var findOrphanAgents = (projectName) => Effect.gen(function* () {
47
- const projectPath = path.join(getSessionsDir(), projectName);
48
- const files = yield* Effect.tryPromise(() => fs.readdir(projectPath));
49
- const sessionIds = new Set(
50
- files.filter((f) => !f.startsWith("agent-") && f.endsWith(".jsonl")).map((f) => f.replace(".jsonl", ""))
51
- );
52
- const agentFiles = files.filter((f) => f.startsWith("agent-") && f.endsWith(".jsonl"));
53
- const orphanAgents = [];
54
- for (const agentFile of agentFiles) {
55
- const filePath = path.join(projectPath, agentFile);
56
- const content = yield* Effect.tryPromise(() => fs.readFile(filePath, "utf-8"));
57
- const firstLine = content.split("\n")[0];
58
- if (firstLine) {
59
- try {
60
- const parsed = JSON.parse(firstLine);
61
- if (parsed.sessionId && !sessionIds.has(parsed.sessionId)) {
62
- orphanAgents.push({
63
- agentId: agentFile.replace(".jsonl", ""),
64
- sessionId: parsed.sessionId
65
- });
66
- }
67
- } catch {
68
- }
69
- }
70
- }
71
- return orphanAgents;
72
- });
73
- var deleteOrphanAgents = (projectName) => Effect.gen(function* () {
74
- const projectPath = path.join(getSessionsDir(), projectName);
75
- const orphans = yield* findOrphanAgents(projectName);
76
- const backupDir = path.join(projectPath, ".bak");
77
- yield* Effect.tryPromise(() => fs.mkdir(backupDir, { recursive: true }));
78
- const deletedAgents = [];
79
- for (const orphan of orphans) {
80
- const agentPath = path.join(projectPath, `${orphan.agentId}.jsonl`);
81
- const agentBackupPath = path.join(backupDir, `${orphan.agentId}.jsonl`);
82
- yield* Effect.tryPromise(() => fs.rename(agentPath, agentBackupPath));
83
- deletedAgents.push(orphan.agentId);
84
- }
85
- return { success: true, deletedAgents, count: deletedAgents.length };
86
- });
87
- var deleteLinkedTodos = (sessionId, agentIds) => Effect.gen(function* () {
88
- const todosDir = getTodosDir();
89
- const exists = yield* Effect.tryPromise(
90
- () => fs.access(todosDir).then(() => true).catch(() => false)
91
- );
92
- if (!exists) return { deletedCount: 0 };
93
- const backupDir = path.join(todosDir, ".bak");
94
- yield* Effect.tryPromise(() => fs.mkdir(backupDir, { recursive: true }));
95
- let deletedCount = 0;
96
- const sessionTodoPath = path.join(todosDir, `${sessionId}.json`);
97
- const sessionTodoExists = yield* Effect.tryPromise(
98
- () => fs.access(sessionTodoPath).then(() => true).catch(() => false)
99
- );
100
- if (sessionTodoExists) {
101
- const backupPath = path.join(backupDir, `${sessionId}.json`);
102
- yield* Effect.tryPromise(() => fs.rename(sessionTodoPath, backupPath));
103
- deletedCount++;
104
- }
105
- for (const agentId of agentIds) {
106
- const shortAgentId = agentId.replace("agent-", "");
107
- const agentTodoPath = path.join(todosDir, `${sessionId}-agent-${shortAgentId}.json`);
108
- const agentTodoExists = yield* Effect.tryPromise(
109
- () => fs.access(agentTodoPath).then(() => true).catch(() => false)
110
- );
111
- if (agentTodoExists) {
112
- const backupPath = path.join(backupDir, `${sessionId}-agent-${shortAgentId}.json`);
113
- yield* Effect.tryPromise(() => fs.rename(agentTodoPath, backupPath));
114
- deletedCount++;
115
- }
116
- }
117
- return { deletedCount };
118
- });
119
-
120
- // src/lib/session.ts
121
- var listProjects = Effect2.gen(function* () {
122
- const sessionsDir = getSessionsDir();
123
- const exists = yield* Effect2.tryPromise(
124
- () => fs2.access(sessionsDir).then(() => true).catch(() => false)
125
- );
126
- if (!exists) {
127
- return [];
128
- }
129
- const entries = yield* Effect2.tryPromise(() => fs2.readdir(sessionsDir, { withFileTypes: true }));
130
- const projects = yield* Effect2.all(
131
- entries.filter((e) => e.isDirectory()).map(
132
- (entry) => Effect2.gen(function* () {
133
- const projectPath = path2.join(sessionsDir, entry.name);
134
- const files = yield* Effect2.tryPromise(() => fs2.readdir(projectPath));
135
- const sessionFiles = files.filter((f) => f.endsWith(".jsonl"));
136
- return {
137
- name: entry.name,
138
- path: projectPath,
139
- sessionCount: sessionFiles.length
140
- };
141
- })
142
- ),
143
- { concurrency: 10 }
144
- );
145
- return projects;
146
- });
147
- var listSessions = (projectName) => Effect2.gen(function* () {
148
- const projectPath = path2.join(getSessionsDir(), projectName);
149
- const files = yield* Effect2.tryPromise(() => fs2.readdir(projectPath));
150
- const sessionFiles = files.filter((f) => f.endsWith(".jsonl"));
151
- const sessions = yield* Effect2.all(
152
- sessionFiles.map(
153
- (file) => Effect2.gen(function* () {
154
- const filePath = path2.join(projectPath, file);
155
- const content = yield* Effect2.tryPromise(() => fs2.readFile(filePath, "utf-8"));
156
- const lines = content.trim().split("\n").filter(Boolean);
157
- const messages = lines.map((line) => JSON.parse(line));
158
- const sessionId = file.replace(".jsonl", "");
159
- const firstMessage = messages[0];
160
- const lastMessage = messages[messages.length - 1];
161
- const title = pipe(
162
- messages,
163
- A.findFirst((m) => m.type === "human"),
164
- O.map((m) => {
165
- const msg = m.message;
166
- const content2 = msg?.content ?? "";
167
- return content2.slice(0, 50) + (content2.length > 50 ? "..." : "");
168
- }),
169
- O.getOrElse(() => "Untitled")
170
- );
171
- return {
172
- id: sessionId,
173
- projectName,
174
- title,
175
- messageCount: messages.length,
176
- createdAt: firstMessage?.timestamp,
177
- updatedAt: lastMessage?.timestamp
178
- };
179
- })
180
- ),
181
- { concurrency: 10 }
182
- );
183
- return sessions;
184
- });
185
- var readSession = (projectName, sessionId) => Effect2.gen(function* () {
186
- const filePath = path2.join(getSessionsDir(), projectName, `${sessionId}.jsonl`);
187
- const content = yield* Effect2.tryPromise(() => fs2.readFile(filePath, "utf-8"));
188
- const lines = content.trim().split("\n").filter(Boolean);
189
- return lines.map((line) => JSON.parse(line));
190
- });
191
- var deleteSession = (projectName, sessionId) => Effect2.gen(function* () {
192
- const sessionsDir = getSessionsDir();
193
- const projectPath = path2.join(sessionsDir, projectName);
194
- const filePath = path2.join(projectPath, `${sessionId}.jsonl`);
195
- const backupDir = path2.join(projectPath, ".bak");
196
- yield* Effect2.tryPromise(() => fs2.mkdir(backupDir, { recursive: true }));
197
- const linkedAgents = yield* findLinkedAgents(projectName, sessionId);
198
- const deletedAgents = [];
199
- for (const agentId of linkedAgents) {
200
- const agentPath = path2.join(projectPath, `${agentId}.jsonl`);
201
- const agentBackupPath = path2.join(backupDir, `${agentId}.jsonl`);
202
- yield* Effect2.tryPromise(() => fs2.rename(agentPath, agentBackupPath));
203
- deletedAgents.push(agentId);
204
- }
205
- const todosResult = yield* deleteLinkedTodos(sessionId, linkedAgents);
206
- const backupPath = path2.join(backupDir, `${sessionId}.jsonl`);
207
- yield* Effect2.tryPromise(() => fs2.rename(filePath, backupPath));
208
- return { success: true, backupPath, deletedAgents, deletedTodos: todosResult.deletedCount };
209
- });
210
- var renameSession = (projectName, sessionId, newTitle) => Effect2.gen(function* () {
211
- const filePath = path2.join(getSessionsDir(), projectName, `${sessionId}.jsonl`);
212
- const content = yield* Effect2.tryPromise(() => fs2.readFile(filePath, "utf-8"));
213
- const lines = content.trim().split("\n").filter(Boolean);
214
- if (lines.length === 0) {
215
- return { success: false, error: "Empty session" };
216
- }
217
- const messages = lines.map((line) => JSON.parse(line));
218
- const firstMsg = messages[0];
219
- if (firstMsg && typeof firstMsg.message === "object" && firstMsg.message !== null) {
220
- const msg = firstMsg.message;
221
- if (msg.content) {
222
- const cleanContent = msg.content.replace(/^\[.*?\]\s*/, "");
223
- msg.content = `[${newTitle}] ${cleanContent}`;
224
- }
225
- }
226
- const newContent = messages.map((m) => JSON.stringify(m)).join("\n") + "\n";
227
- yield* Effect2.tryPromise(() => fs2.writeFile(filePath, newContent, "utf-8"));
228
- return { success: true };
229
- });
230
- var deleteMessage = (projectName, sessionId, messageUuid) => Effect2.gen(function* () {
231
- const filePath = path2.join(getSessionsDir(), projectName, `${sessionId}.jsonl`);
232
- const content = yield* Effect2.tryPromise(() => fs2.readFile(filePath, "utf-8"));
233
- const lines = content.trim().split("\n").filter(Boolean);
234
- const messages = lines.map((line) => JSON.parse(line));
235
- const targetIndex = messages.findIndex(
236
- (m) => m.uuid === messageUuid || m.messageId === messageUuid
237
- );
238
- if (targetIndex === -1) {
239
- return { success: false, error: "Message not found" };
240
- }
241
- const deletedMsg = messages[targetIndex];
242
- const parentUuid = deletedMsg?.parentUuid;
243
- const nextMsg = messages[targetIndex + 1];
244
- if (nextMsg) {
245
- nextMsg.parentUuid = parentUuid;
246
- }
247
- messages.splice(targetIndex, 1);
248
- const newContent = messages.map((m) => JSON.stringify(m)).join("\n") + "\n";
249
- yield* Effect2.tryPromise(() => fs2.writeFile(filePath, newContent, "utf-8"));
250
- return { success: true };
251
- });
252
- var previewCleanup = (projectName) => Effect2.gen(function* () {
253
- const projects = yield* listProjects;
254
- const targetProjects = projectName ? projects.filter((p) => p.name === projectName) : projects;
255
- const results = yield* Effect2.all(
256
- targetProjects.map(
257
- (project) => Effect2.gen(function* () {
258
- const sessions = yield* listSessions(project.name);
259
- const emptySessions = sessions.filter((s) => s.messageCount === 0);
260
- const invalidSessions = sessions.filter(
261
- (s) => s.title?.includes("Invalid API key") || s.title?.includes("API key")
262
- );
263
- return {
264
- project: project.name,
265
- emptySessions,
266
- invalidSessions
267
- };
268
- })
269
- ),
270
- { concurrency: 5 }
271
- );
272
- return results;
273
- });
274
- var clearSessions = (options) => Effect2.gen(function* () {
275
- const {
276
- projectName,
277
- clearEmpty = true,
278
- clearInvalid = true,
279
- clearOrphanAgents = true
280
- } = options;
281
- const cleanupPreview = yield* previewCleanup(projectName);
282
- let deletedCount = 0;
283
- let deletedAgentCount = 0;
284
- for (const result of cleanupPreview) {
285
- const toDelete = [
286
- ...clearEmpty ? result.emptySessions : [],
287
- ...clearInvalid ? result.invalidSessions : []
288
- ];
289
- for (const session of toDelete) {
290
- const deleteResult = yield* deleteSession(result.project, session.id);
291
- deletedCount++;
292
- deletedAgentCount += deleteResult.deletedAgents.length;
293
- }
294
- if (clearOrphanAgents) {
295
- const orphanResult = yield* deleteOrphanAgents(result.project);
296
- deletedAgentCount += orphanResult.count;
297
- }
298
- }
299
- return { success: true, deletedCount, deletedAgentCount };
300
- });
301
- var getSessionFiles = (projectName, sessionId) => Effect2.gen(function* () {
302
- const messages = yield* readSession(projectName, sessionId);
303
- const fileChanges = [];
304
- const seenFiles = /* @__PURE__ */ new Set();
305
- for (const msg of messages) {
306
- if (msg.type === "file-history-snapshot") {
307
- const snapshot = msg;
308
- const backups = snapshot.snapshot?.trackedFileBackups;
309
- if (backups && typeof backups === "object") {
310
- for (const filePath of Object.keys(backups)) {
311
- if (!seenFiles.has(filePath)) {
312
- seenFiles.add(filePath);
313
- fileChanges.push({
314
- path: filePath,
315
- action: "modified",
316
- timestamp: snapshot.snapshot?.timestamp,
317
- messageUuid: snapshot.messageId ?? msg.uuid
318
- });
319
- }
320
- }
321
- }
322
- }
323
- if (msg.type === "assistant" && msg.message) {
324
- const assistantMsg = msg.message;
325
- const content = assistantMsg.content;
326
- if (Array.isArray(content)) {
327
- for (const block of content) {
328
- if (block.type === "tool_use" && (block.name === "Write" || block.name === "Edit")) {
329
- const filePath = block.input?.file_path;
330
- if (filePath && !seenFiles.has(filePath)) {
331
- seenFiles.add(filePath);
332
- fileChanges.push({
333
- path: filePath,
334
- action: block.name === "Write" ? "created" : "modified",
335
- timestamp: msg.timestamp,
336
- messageUuid: msg.uuid
337
- });
338
- }
339
- }
340
- }
341
- }
342
- }
343
- }
344
- return {
345
- sessionId,
346
- projectName,
347
- files: fileChanges,
348
- totalChanges: fileChanges.length
349
- };
350
- });
351
- var splitSession = (projectName, sessionId, splitAtMessageUuid) => Effect2.gen(function* () {
352
- const projectPath = path2.join(getSessionsDir(), projectName);
353
- const filePath = path2.join(projectPath, `${sessionId}.jsonl`);
354
- const content = yield* Effect2.tryPromise(() => fs2.readFile(filePath, "utf-8"));
355
- const lines = content.trim().split("\n").filter(Boolean);
356
- const allMessages = lines.map((line) => JSON.parse(line));
357
- const splitIndex = allMessages.findIndex((m) => m.uuid === splitAtMessageUuid);
358
- if (splitIndex === -1) {
359
- return { success: false, error: "Message not found" };
360
- }
361
- if (splitIndex === 0) {
362
- return { success: false, error: "Cannot split at first message" };
363
- }
364
- const newSessionId = crypto.randomUUID();
365
- const remainingMessages = allMessages.slice(0, splitIndex);
366
- const movedMessages = allMessages.slice(splitIndex);
367
- const updatedMovedMessages = movedMessages.map((msg, index) => {
368
- const updated = { ...msg, sessionId: newSessionId };
369
- if (index === 0) {
370
- updated.parentUuid = null;
371
- }
372
- return updated;
373
- });
374
- const remainingContent = remainingMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
375
- yield* Effect2.tryPromise(() => fs2.writeFile(filePath, remainingContent, "utf-8"));
376
- const newFilePath = path2.join(projectPath, `${newSessionId}.jsonl`);
377
- const newContent = updatedMovedMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
378
- yield* Effect2.tryPromise(() => fs2.writeFile(newFilePath, newContent, "utf-8"));
379
- const agentFiles = yield* Effect2.tryPromise(() => fs2.readdir(projectPath));
380
- const agentJsonlFiles = agentFiles.filter((f) => f.startsWith("agent-") && f.endsWith(".jsonl"));
381
- for (const agentFile of agentJsonlFiles) {
382
- const agentPath = path2.join(projectPath, agentFile);
383
- const agentContent = yield* Effect2.tryPromise(() => fs2.readFile(agentPath, "utf-8"));
384
- const agentLines = agentContent.trim().split("\n").filter(Boolean);
385
- if (agentLines.length === 0) continue;
386
- const firstAgentMsg = JSON.parse(agentLines[0]);
387
- if (firstAgentMsg.sessionId === sessionId) {
388
- const agentId = agentFile.replace("agent-", "").replace(".jsonl", "");
389
- const isRelatedToMoved = movedMessages.some(
390
- (msg) => msg.agentId === agentId
391
- );
392
- if (isRelatedToMoved) {
393
- const updatedAgentMessages = agentLines.map((line) => {
394
- const msg = JSON.parse(line);
395
- return JSON.stringify({ ...msg, sessionId: newSessionId });
396
- });
397
- const updatedAgentContent = updatedAgentMessages.join("\n") + "\n";
398
- yield* Effect2.tryPromise(() => fs2.writeFile(agentPath, updatedAgentContent, "utf-8"));
399
- }
400
- }
401
- }
402
- return {
403
- success: true,
404
- newSessionId,
405
- newSessionPath: newFilePath,
406
- movedMessageCount: movedMessages.length
407
- };
408
- });
409
- var getSessionDiffSummary = (projectName, sessionId) => Effect2.gen(function* () {
410
- const messages = yield* readSession(projectName, sessionId);
411
- const title = pipe(
412
- messages,
413
- A.findFirst((m) => m.type === "human"),
414
- O.map((m) => {
415
- const msg = m.message;
416
- const content = msg?.content ?? "";
417
- return content.slice(0, 50) + (content.length > 50 ? "..." : "");
418
- }),
419
- O.getOrElse(() => "Untitled")
420
- );
421
- const changes = [];
422
- const seenFiles = /* @__PURE__ */ new Set();
423
- let snapshotCount = 0;
424
- for (const msg of messages) {
425
- if (msg.type === "file-history-snapshot") {
426
- snapshotCount++;
427
- const snapshot = msg;
428
- const backups = snapshot.snapshot?.trackedFileBackups;
429
- if (backups && typeof backups === "object") {
430
- for (const [filePath, backup] of Object.entries(backups)) {
431
- if (!seenFiles.has(filePath)) {
432
- seenFiles.add(filePath);
433
- const backupData = backup;
434
- const content = backupData?.content ?? "";
435
- changes.push({
436
- path: filePath,
437
- action: "modified",
438
- hasBackup: content.length > 0,
439
- backupPreview: content.slice(0, 100) + (content.length > 100 ? "..." : "")
440
- });
441
- }
442
- }
443
- }
444
- }
445
- }
446
- return {
447
- sessionId,
448
- projectName,
449
- title,
450
- changes,
451
- totalFiles: changes.length,
452
- snapshotCount
453
- };
454
- });
455
-
456
- // src/mcp/index.ts
457
- var server = new McpServer({
458
- name: "claude-sessions-mcp",
459
- version: "0.1.0"
460
- });
461
- server.tool("list_projects", "List all Claude Code projects with session counts", {}, async () => {
462
- const result = await Effect3.runPromise(listProjects);
463
- return {
464
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
465
- };
466
- });
467
- server.tool(
468
- "list_sessions",
469
- "List all sessions in a project",
470
- {
471
- project_name: z.string().describe("Project folder name (e.g., '-Users-young-works-myproject')")
472
- },
473
- async ({ project_name }) => {
474
- const result = await Effect3.runPromise(listSessions(project_name));
475
- return {
476
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
477
- };
478
- }
479
- );
480
- server.tool(
481
- "rename_session",
482
- "Rename a session by adding a title prefix to the first message",
483
- {
484
- project_name: z.string().describe("Project folder name"),
485
- session_id: z.string().describe("Session ID (filename without .jsonl)"),
486
- new_title: z.string().describe("New title to add as prefix")
487
- },
488
- async ({ project_name, session_id, new_title }) => {
489
- const result = await Effect3.runPromise(
490
- renameSession(project_name, session_id, new_title)
491
- );
492
- return {
493
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
494
- };
495
- }
496
- );
497
- server.tool(
498
- "delete_session",
499
- "Delete a session (moves to .bak folder for recovery)",
500
- {
501
- project_name: z.string().describe("Project folder name"),
502
- session_id: z.string().describe("Session ID to delete")
503
- },
504
- async ({ project_name, session_id }) => {
505
- const result = await Effect3.runPromise(deleteSession(project_name, session_id));
506
- return {
507
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
508
- };
509
- }
510
- );
511
- server.tool(
512
- "delete_message",
513
- "Delete a message from a session and repair the parentUuid chain",
514
- {
515
- project_name: z.string().describe("Project folder name"),
516
- session_id: z.string().describe("Session ID"),
517
- message_uuid: z.string().describe("UUID of the message to delete")
518
- },
519
- async ({ project_name, session_id, message_uuid }) => {
520
- const result = await Effect3.runPromise(
521
- deleteMessage(project_name, session_id, message_uuid)
522
- );
523
- return {
524
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
525
- };
526
- }
527
- );
528
- server.tool(
529
- "preview_cleanup",
530
- "Preview sessions that would be cleaned (empty and invalid API key sessions)",
531
- {
532
- project_name: z.string().optional().describe("Optional: filter by project name")
533
- },
534
- async ({ project_name }) => {
535
- const result = await Effect3.runPromise(previewCleanup(project_name));
536
- return {
537
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
538
- };
539
- }
540
- );
541
- server.tool(
542
- "clear_sessions",
543
- "Delete all empty sessions and invalid API key sessions",
544
- {
545
- project_name: z.string().optional().describe("Optional: filter by project name"),
546
- clear_empty: z.boolean().default(true).describe("Clear empty sessions (default: true)"),
547
- clear_invalid: z.boolean().default(true).describe("Clear invalid API key sessions (default: true)"),
548
- clear_orphan_agents: z.boolean().default(true).describe("Clear orphan agent files whose session no longer exists (default: true)")
549
- },
550
- async ({ project_name, clear_empty, clear_invalid, clear_orphan_agents }) => {
551
- const result = await Effect3.runPromise(
552
- clearSessions({
553
- projectName: project_name,
554
- clearEmpty: clear_empty,
555
- clearInvalid: clear_invalid,
556
- clearOrphanAgents: clear_orphan_agents
557
- })
558
- );
559
- return {
560
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
561
- };
562
- }
563
- );
564
- server.tool(
565
- "get_session_files",
566
- "Get list of all files changed in a session (from file-history-snapshot and tool_use)",
567
- {
568
- project_name: z.string().describe("Project folder name"),
569
- session_id: z.string().describe("Session ID")
570
- },
571
- async ({ project_name, session_id }) => {
572
- const result = await Effect3.runPromise(getSessionFiles(project_name, session_id));
573
- return {
574
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
575
- };
576
- }
577
- );
578
- server.tool(
579
- "get_session_diff",
580
- "Get diff summary for a session including file changes and snapshot info",
581
- {
582
- project_name: z.string().describe("Project folder name"),
583
- session_id: z.string().describe("Session ID")
584
- },
585
- async ({ project_name, session_id }) => {
586
- const result = await Effect3.runPromise(getSessionDiffSummary(project_name, session_id));
587
- return {
588
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
589
- };
590
- }
591
- );
592
- server.tool(
593
- "split_session",
594
- "Split a session at a specific message, creating a new session with messages from that point onwards",
595
- {
596
- project_name: z.string().describe("Project folder name"),
597
- session_id: z.string().describe("Session ID to split"),
598
- message_uuid: z.string().describe(
599
- "UUID of the message where the split starts (this message becomes the first message of the new session)"
600
- )
601
- },
602
- async ({ project_name, session_id, message_uuid }) => {
603
- const result = await Effect3.runPromise(
604
- splitSession(project_name, session_id, message_uuid)
605
- );
606
- return {
607
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
608
- };
609
- }
610
- );
611
- var webServerInstance = null;
612
- server.tool(
613
- "start_gui",
614
- "Start the web GUI for session management and open it in browser",
615
- {
616
- port: z.number().default(5173).describe("Port to run the web server on (default: 5173)"),
617
- open_browser: z.boolean().default(true).describe("Whether to open browser automatically (default: true)"),
618
- restart: z.boolean().default(false).describe("Restart the server if already running (default: false)")
619
- },
620
- async ({ port, open_browser, restart }) => {
621
- try {
622
- if (webServerInstance) {
623
- if (restart) {
624
- await stopWebServer(webServerInstance);
625
- webServerInstance = null;
626
- } else {
627
- return {
628
- content: [
629
- {
630
- type: "text",
631
- text: JSON.stringify(
632
- {
633
- success: true,
634
- message: "Web GUI is already running",
635
- url: `http://localhost:${port}`
636
- },
637
- null,
638
- 2
639
- )
640
- }
641
- ]
642
- };
643
- }
644
- }
645
- webServerInstance = await startWebServer(port, open_browser);
646
- return {
647
- content: [
648
- {
649
- type: "text",
650
- text: JSON.stringify(
651
- {
652
- success: true,
653
- message: "Web GUI started successfully",
654
- url: `http://localhost:${port}`,
655
- pid: process.pid
656
- },
657
- null,
658
- 2
659
- )
660
- }
661
- ]
662
- };
663
- } catch (error) {
664
- return {
665
- content: [
666
- {
667
- type: "text",
668
- text: JSON.stringify(
669
- {
670
- success: false,
671
- error: String(error)
672
- },
673
- null,
674
- 2
675
- )
676
- }
677
- ]
678
- };
679
- }
680
- }
681
- );
682
- server.tool("stop_gui", "Stop the web GUI server", {}, async () => {
683
- if (webServerInstance) {
684
- const port = webServerInstance.port;
685
- try {
686
- await fetch(`http://localhost:${port}/api/shutdown`, { method: "POST" });
687
- } catch {
688
- }
689
- await stopWebServer(webServerInstance);
690
- webServerInstance = null;
691
- return {
692
- content: [
693
- {
694
- type: "text",
695
- text: JSON.stringify({ success: true, message: "Web GUI stopped successfully" }, null, 2)
696
- }
697
- ]
698
- };
699
- }
700
- return {
701
- content: [
702
- {
703
- type: "text",
704
- text: JSON.stringify({ success: true, message: "Web GUI was not running" }, null, 2)
705
- }
706
- ]
707
- };
708
- });
709
- async function main() {
710
- const transport = new StdioServerTransport();
711
- await server.connect(transport);
712
- }
713
- main().catch(console.error);
714
- //# sourceMappingURL=index.js.map