@claude-flow/cli 3.0.0-alpha.13 → 3.0.0-alpha.15

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 (106) hide show
  1. package/dist/src/commands/doctor.d.ts.map +1 -1
  2. package/dist/src/commands/doctor.js +75 -2
  3. package/dist/src/commands/doctor.js.map +1 -1
  4. package/dist/tsconfig.tsbuildinfo +1 -1
  5. package/package.json +12 -4
  6. package/.agentic-flow/intelligence.json +0 -17
  7. package/.claude-flow/agents/store.json +0 -16
  8. package/.claude-flow/daemon-state.json +0 -123
  9. package/.claude-flow/daemon-test.log +0 -0
  10. package/.claude-flow/daemon.log +0 -0
  11. package/.claude-flow/daemon2.log +0 -0
  12. package/.claude-flow/daemon3.log +0 -0
  13. package/.claude-flow/hive-mind/state.json +0 -51
  14. package/.claude-flow/metrics/agent-metrics.json +0 -1
  15. package/.claude-flow/metrics/codebase-map.json +0 -11
  16. package/.claude-flow/metrics/consolidation.json +0 -6
  17. package/.claude-flow/metrics/performance.json +0 -87
  18. package/.claude-flow/metrics/security-audit.json +0 -10
  19. package/.claude-flow/metrics/task-metrics.json +0 -10
  20. package/.claude-flow/metrics/test-gaps.json +0 -6
  21. package/__tests__/README.md +0 -140
  22. package/__tests__/TEST_SUMMARY.md +0 -144
  23. package/__tests__/cli.test.ts +0 -558
  24. package/__tests__/commands.test.ts +0 -726
  25. package/__tests__/config-adapter.test.ts +0 -362
  26. package/__tests__/config-loading.test.ts +0 -106
  27. package/__tests__/coverage/.tmp/coverage-0.json +0 -1
  28. package/__tests__/coverage/.tmp/coverage-1.json +0 -1
  29. package/__tests__/coverage/.tmp/coverage-2.json +0 -1
  30. package/__tests__/coverage/.tmp/coverage-3.json +0 -1
  31. package/__tests__/coverage/.tmp/coverage-4.json +0 -1
  32. package/__tests__/coverage/.tmp/coverage-5.json +0 -1
  33. package/__tests__/mcp-client.test.ts +0 -480
  34. package/__tests__/p1-commands.test.ts +0 -1064
  35. package/agents/architect.yaml +0 -11
  36. package/agents/coder.yaml +0 -11
  37. package/agents/reviewer.yaml +0 -10
  38. package/agents/security-architect.yaml +0 -10
  39. package/agents/tester.yaml +0 -10
  40. package/docs/CONFIG_LOADING.md +0 -236
  41. package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
  42. package/docs/MCP_CLIENT_GUIDE.md +0 -620
  43. package/docs/REFACTORING_SUMMARY.md +0 -247
  44. package/scripts/publish.sh +0 -46
  45. package/src/commands/agent.ts +0 -955
  46. package/src/commands/claims.ts +0 -317
  47. package/src/commands/completions.ts +0 -558
  48. package/src/commands/config.ts +0 -452
  49. package/src/commands/daemon.ts +0 -621
  50. package/src/commands/deployment.ts +0 -323
  51. package/src/commands/doctor.ts +0 -382
  52. package/src/commands/embeddings.ts +0 -686
  53. package/src/commands/hive-mind.ts +0 -928
  54. package/src/commands/hooks.ts +0 -2603
  55. package/src/commands/index.ts +0 -154
  56. package/src/commands/init.ts +0 -597
  57. package/src/commands/mcp.ts +0 -753
  58. package/src/commands/memory.ts +0 -1161
  59. package/src/commands/migrate.ts +0 -447
  60. package/src/commands/neural.ts +0 -253
  61. package/src/commands/performance.ts +0 -292
  62. package/src/commands/plugins.ts +0 -316
  63. package/src/commands/process.ts +0 -695
  64. package/src/commands/providers.ts +0 -259
  65. package/src/commands/security.ts +0 -288
  66. package/src/commands/session.ts +0 -891
  67. package/src/commands/start.ts +0 -457
  68. package/src/commands/status.ts +0 -736
  69. package/src/commands/swarm.ts +0 -648
  70. package/src/commands/task.ts +0 -792
  71. package/src/commands/workflow.ts +0 -742
  72. package/src/config-adapter.ts +0 -210
  73. package/src/index.ts +0 -443
  74. package/src/infrastructure/in-memory-repositories.ts +0 -310
  75. package/src/init/claudemd-generator.ts +0 -631
  76. package/src/init/executor.ts +0 -762
  77. package/src/init/helpers-generator.ts +0 -628
  78. package/src/init/index.ts +0 -60
  79. package/src/init/mcp-generator.ts +0 -83
  80. package/src/init/settings-generator.ts +0 -284
  81. package/src/init/statusline-generator.ts +0 -211
  82. package/src/init/types.ts +0 -447
  83. package/src/mcp-client.ts +0 -241
  84. package/src/mcp-server.ts +0 -577
  85. package/src/mcp-tools/agent-tools.ts +0 -466
  86. package/src/mcp-tools/config-tools.ts +0 -370
  87. package/src/mcp-tools/hive-mind-tools.ts +0 -521
  88. package/src/mcp-tools/hooks-tools.ts +0 -1888
  89. package/src/mcp-tools/index.ts +0 -16
  90. package/src/mcp-tools/memory-tools.ts +0 -270
  91. package/src/mcp-tools/session-tools.ts +0 -359
  92. package/src/mcp-tools/swarm-tools.ts +0 -105
  93. package/src/mcp-tools/task-tools.ts +0 -347
  94. package/src/mcp-tools/types.ts +0 -33
  95. package/src/mcp-tools/workflow-tools.ts +0 -573
  96. package/src/output.ts +0 -639
  97. package/src/parser.ts +0 -417
  98. package/src/prompt.ts +0 -619
  99. package/src/services/index.ts +0 -15
  100. package/src/services/worker-daemon.ts +0 -726
  101. package/src/suggest.ts +0 -245
  102. package/src/types.ts +0 -287
  103. package/tmp.json +0 -0
  104. package/tsconfig.json +0 -16
  105. package/tsconfig.tsbuildinfo +0 -1
  106. package/vitest.config.ts +0 -13
@@ -1,16 +0,0 @@
1
- /**
2
- * MCP Tools Index for CLI
3
- *
4
- * Re-exports all tool definitions for use within the CLI package.
5
- */
6
-
7
- export type { MCPTool, MCPToolInputSchema, MCPToolResult } from './types.js';
8
- export { agentTools } from './agent-tools.js';
9
- export { swarmTools } from './swarm-tools.js';
10
- export { memoryTools } from './memory-tools.js';
11
- export { configTools } from './config-tools.js';
12
- export { hooksTools } from './hooks-tools.js';
13
- export { taskTools } from './task-tools.js';
14
- export { sessionTools } from './session-tools.js';
15
- export { hiveMindTools } from './hive-mind-tools.js';
16
- export { workflowTools } from './workflow-tools.js';
@@ -1,270 +0,0 @@
1
- /**
2
- * Memory MCP Tools for CLI
3
- *
4
- * Tool definitions for memory management with file-based persistence.
5
- */
6
-
7
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
8
- import { join, resolve } from 'path';
9
- import type { MCPTool } from './types.js';
10
-
11
- // Simple file-based memory store
12
- interface MemoryEntry {
13
- key: string;
14
- value: unknown;
15
- metadata?: Record<string, unknown>;
16
- storedAt: string;
17
- accessCount: number;
18
- lastAccessed: string;
19
- }
20
-
21
- interface MemoryStore {
22
- entries: Record<string, MemoryEntry>;
23
- version: string;
24
- }
25
-
26
- const MEMORY_DIR = '.claude-flow/memory';
27
- const MEMORY_FILE = 'store.json';
28
-
29
- function getMemoryPath(): string {
30
- return resolve(join(MEMORY_DIR, MEMORY_FILE));
31
- }
32
-
33
- function ensureMemoryDir(): void {
34
- const dir = resolve(MEMORY_DIR);
35
- if (!existsSync(dir)) {
36
- mkdirSync(dir, { recursive: true });
37
- }
38
- }
39
-
40
- function loadMemoryStore(): MemoryStore {
41
- try {
42
- const path = getMemoryPath();
43
- if (existsSync(path)) {
44
- const data = readFileSync(path, 'utf-8');
45
- return JSON.parse(data);
46
- }
47
- } catch {
48
- // Return empty store on error
49
- }
50
- return { entries: {}, version: '3.0.0' };
51
- }
52
-
53
- function saveMemoryStore(store: MemoryStore): void {
54
- ensureMemoryDir();
55
- writeFileSync(getMemoryPath(), JSON.stringify(store, null, 2), 'utf-8');
56
- }
57
-
58
- export const memoryTools: MCPTool[] = [
59
- {
60
- name: 'memory/store',
61
- description: 'Store a value in memory (persisted to disk)',
62
- category: 'memory',
63
- inputSchema: {
64
- type: 'object',
65
- properties: {
66
- key: { type: 'string', description: 'Memory key' },
67
- value: { description: 'Value to store' },
68
- metadata: { type: 'object', description: 'Optional metadata' },
69
- },
70
- required: ['key', 'value'],
71
- },
72
- handler: async (input) => {
73
- const store = loadMemoryStore();
74
- const now = new Date().toISOString();
75
-
76
- const entry: MemoryEntry = {
77
- key: input.key as string,
78
- value: input.value,
79
- metadata: (input.metadata as Record<string, unknown>) || {},
80
- storedAt: now,
81
- accessCount: 0,
82
- lastAccessed: now,
83
- };
84
-
85
- store.entries[input.key as string] = entry;
86
- saveMemoryStore(store);
87
-
88
- return {
89
- success: true,
90
- key: input.key,
91
- stored: true,
92
- storedAt: now,
93
- totalEntries: Object.keys(store.entries).length,
94
- };
95
- },
96
- },
97
- {
98
- name: 'memory/retrieve',
99
- description: 'Retrieve a value from memory',
100
- category: 'memory',
101
- inputSchema: {
102
- type: 'object',
103
- properties: {
104
- key: { type: 'string', description: 'Memory key' },
105
- },
106
- required: ['key'],
107
- },
108
- handler: async (input) => {
109
- const store = loadMemoryStore();
110
- const key = input.key as string;
111
- const entry = store.entries[key];
112
-
113
- if (entry) {
114
- // Update access stats
115
- entry.accessCount++;
116
- entry.lastAccessed = new Date().toISOString();
117
- saveMemoryStore(store);
118
-
119
- return {
120
- key,
121
- value: entry.value,
122
- metadata: entry.metadata,
123
- storedAt: entry.storedAt,
124
- accessCount: entry.accessCount,
125
- found: true,
126
- };
127
- }
128
-
129
- return {
130
- key,
131
- value: null,
132
- found: false,
133
- };
134
- },
135
- },
136
- {
137
- name: 'memory/search',
138
- description: 'Search memory by keyword',
139
- category: 'memory',
140
- inputSchema: {
141
- type: 'object',
142
- properties: {
143
- query: { type: 'string', description: 'Search query' },
144
- limit: { type: 'number', description: 'Result limit' },
145
- },
146
- required: ['query'],
147
- },
148
- handler: async (input) => {
149
- const store = loadMemoryStore();
150
- const query = (input.query as string).toLowerCase();
151
- const limit = (input.limit as number) || 10;
152
- const startTime = performance.now();
153
-
154
- const results = Object.values(store.entries)
155
- .filter(entry => {
156
- const keyMatch = entry.key.toLowerCase().includes(query);
157
- const valueStr = typeof entry.value === 'string' ? entry.value.toLowerCase() : JSON.stringify(entry.value).toLowerCase();
158
- const valueMatch = valueStr.includes(query);
159
- return keyMatch || valueMatch;
160
- })
161
- .slice(0, limit)
162
- .map(entry => ({
163
- key: entry.key,
164
- value: entry.value,
165
- score: 1.0, // Simple keyword match
166
- storedAt: entry.storedAt,
167
- }));
168
-
169
- const duration = performance.now() - startTime;
170
-
171
- return {
172
- query: input.query,
173
- results,
174
- total: results.length,
175
- searchTime: `${duration.toFixed(2)}ms`,
176
- };
177
- },
178
- },
179
- {
180
- name: 'memory/delete',
181
- description: 'Delete a memory entry',
182
- category: 'memory',
183
- inputSchema: {
184
- type: 'object',
185
- properties: {
186
- key: { type: 'string', description: 'Memory key' },
187
- },
188
- required: ['key'],
189
- },
190
- handler: async (input) => {
191
- const store = loadMemoryStore();
192
- const key = input.key as string;
193
- const existed = key in store.entries;
194
-
195
- if (existed) {
196
- delete store.entries[key];
197
- saveMemoryStore(store);
198
- }
199
-
200
- return {
201
- success: existed,
202
- key,
203
- deleted: existed,
204
- remainingEntries: Object.keys(store.entries).length,
205
- };
206
- },
207
- },
208
- {
209
- name: 'memory/list',
210
- description: 'List all memory entries',
211
- category: 'memory',
212
- inputSchema: {
213
- type: 'object',
214
- properties: {
215
- limit: { type: 'number', description: 'Result limit' },
216
- offset: { type: 'number', description: 'Result offset' },
217
- },
218
- },
219
- handler: async (input) => {
220
- const store = loadMemoryStore();
221
- const limit = (input.limit as number) || 50;
222
- const offset = (input.offset as number) || 0;
223
-
224
- const allEntries = Object.values(store.entries);
225
- const entries = allEntries.slice(offset, offset + limit).map(e => ({
226
- key: e.key,
227
- storedAt: e.storedAt,
228
- accessCount: e.accessCount,
229
- preview: typeof e.value === 'string'
230
- ? e.value.substring(0, 50) + (e.value.length > 50 ? '...' : '')
231
- : JSON.stringify(e.value).substring(0, 50),
232
- }));
233
-
234
- return {
235
- entries,
236
- total: allEntries.length,
237
- limit,
238
- offset,
239
- };
240
- },
241
- },
242
- {
243
- name: 'memory/stats',
244
- description: 'Get memory storage statistics',
245
- category: 'memory',
246
- inputSchema: {
247
- type: 'object',
248
- properties: {},
249
- },
250
- handler: async () => {
251
- const store = loadMemoryStore();
252
- const entries = Object.values(store.entries);
253
- const totalSize = JSON.stringify(store).length;
254
-
255
- return {
256
- totalEntries: entries.length,
257
- totalSize: `${(totalSize / 1024).toFixed(2)} KB`,
258
- version: store.version,
259
- backend: 'file',
260
- location: getMemoryPath(),
261
- oldestEntry: entries.length > 0
262
- ? entries.reduce((a, b) => a.storedAt < b.storedAt ? a : b).storedAt
263
- : null,
264
- newestEntry: entries.length > 0
265
- ? entries.reduce((a, b) => a.storedAt > b.storedAt ? a : b).storedAt
266
- : null,
267
- };
268
- },
269
- },
270
- ];
@@ -1,359 +0,0 @@
1
- /**
2
- * Session MCP Tools for CLI
3
- *
4
- * Tool definitions for session management with file persistence.
5
- */
6
-
7
- import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, unlinkSync, statSync } from 'node:fs';
8
- import { join } from 'node:path';
9
- import type { MCPTool } from './types.js';
10
-
11
- // Storage paths
12
- const STORAGE_DIR = '.claude-flow';
13
- const SESSION_DIR = 'sessions';
14
-
15
- interface SessionRecord {
16
- sessionId: string;
17
- name: string;
18
- description?: string;
19
- savedAt: string;
20
- stats: {
21
- tasks: number;
22
- agents: number;
23
- memoryEntries: number;
24
- totalSize: number;
25
- };
26
- data?: {
27
- memory?: Record<string, unknown>;
28
- tasks?: Record<string, unknown>;
29
- agents?: Record<string, unknown>;
30
- };
31
- }
32
-
33
- function getSessionDir(): string {
34
- return join(process.cwd(), STORAGE_DIR, SESSION_DIR);
35
- }
36
-
37
- function getSessionPath(sessionId: string): string {
38
- // Sanitize sessionId to prevent path traversal
39
- const safeId = sessionId.replace(/[^a-zA-Z0-9_-]/g, '_');
40
- return join(getSessionDir(), `${safeId}.json`);
41
- }
42
-
43
- function ensureSessionDir(): void {
44
- const dir = getSessionDir();
45
- if (!existsSync(dir)) {
46
- mkdirSync(dir, { recursive: true });
47
- }
48
- }
49
-
50
- function loadSession(sessionId: string): SessionRecord | null {
51
- try {
52
- const path = getSessionPath(sessionId);
53
- if (existsSync(path)) {
54
- const data = readFileSync(path, 'utf-8');
55
- return JSON.parse(data);
56
- }
57
- } catch {
58
- // Return null on error
59
- }
60
- return null;
61
- }
62
-
63
- function saveSession(session: SessionRecord): void {
64
- ensureSessionDir();
65
- writeFileSync(getSessionPath(session.sessionId), JSON.stringify(session, null, 2), 'utf-8');
66
- }
67
-
68
- function listSessions(): SessionRecord[] {
69
- ensureSessionDir();
70
- const dir = getSessionDir();
71
- const files = readdirSync(dir).filter(f => f.endsWith('.json'));
72
-
73
- const sessions: SessionRecord[] = [];
74
- for (const file of files) {
75
- try {
76
- const data = readFileSync(join(dir, file), 'utf-8');
77
- sessions.push(JSON.parse(data));
78
- } catch {
79
- // Skip invalid files
80
- }
81
- }
82
-
83
- return sessions;
84
- }
85
-
86
- // Load related stores for session data
87
- function loadRelatedStores(options: { includeMemory?: boolean; includeTasks?: boolean; includeAgents?: boolean }) {
88
- const data: SessionRecord['data'] = {};
89
-
90
- if (options.includeMemory) {
91
- try {
92
- const memoryPath = join(process.cwd(), STORAGE_DIR, 'memory', 'store.json');
93
- if (existsSync(memoryPath)) {
94
- data.memory = JSON.parse(readFileSync(memoryPath, 'utf-8'));
95
- }
96
- } catch { /* ignore */ }
97
- }
98
-
99
- if (options.includeTasks) {
100
- try {
101
- const taskPath = join(process.cwd(), STORAGE_DIR, 'tasks', 'store.json');
102
- if (existsSync(taskPath)) {
103
- data.tasks = JSON.parse(readFileSync(taskPath, 'utf-8'));
104
- }
105
- } catch { /* ignore */ }
106
- }
107
-
108
- if (options.includeAgents) {
109
- try {
110
- const agentPath = join(process.cwd(), STORAGE_DIR, 'agents', 'store.json');
111
- if (existsSync(agentPath)) {
112
- data.agents = JSON.parse(readFileSync(agentPath, 'utf-8'));
113
- }
114
- } catch { /* ignore */ }
115
- }
116
-
117
- return data;
118
- }
119
-
120
- export const sessionTools: MCPTool[] = [
121
- {
122
- name: 'session/save',
123
- description: 'Save current session state',
124
- category: 'session',
125
- inputSchema: {
126
- type: 'object',
127
- properties: {
128
- name: { type: 'string', description: 'Session name' },
129
- description: { type: 'string', description: 'Session description' },
130
- includeMemory: { type: 'boolean', description: 'Include memory in session' },
131
- includeTasks: { type: 'boolean', description: 'Include tasks in session' },
132
- includeAgents: { type: 'boolean', description: 'Include agents in session' },
133
- },
134
- required: ['name'],
135
- },
136
- handler: async (input) => {
137
- const sessionId = `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
138
-
139
- // Load related data based on options
140
- const data = loadRelatedStores({
141
- includeMemory: input.includeMemory as boolean,
142
- includeTasks: input.includeTasks as boolean,
143
- includeAgents: input.includeAgents as boolean,
144
- });
145
-
146
- // Calculate stats
147
- const stats = {
148
- tasks: data.tasks ? Object.keys((data.tasks as { tasks?: object }).tasks || {}).length : 0,
149
- agents: data.agents ? Object.keys((data.agents as { agents?: object }).agents || {}).length : 0,
150
- memoryEntries: data.memory ? Object.keys((data.memory as { entries?: object }).entries || {}).length : 0,
151
- totalSize: 0,
152
- };
153
-
154
- const session: SessionRecord = {
155
- sessionId,
156
- name: input.name as string,
157
- description: input.description as string,
158
- savedAt: new Date().toISOString(),
159
- stats,
160
- data: Object.keys(data).length > 0 ? data : undefined,
161
- };
162
-
163
- // Calculate size
164
- const sessionJson = JSON.stringify(session);
165
- session.stats.totalSize = Buffer.byteLength(sessionJson, 'utf-8');
166
-
167
- saveSession(session);
168
-
169
- return {
170
- sessionId,
171
- name: session.name,
172
- savedAt: session.savedAt,
173
- stats: session.stats,
174
- path: getSessionPath(sessionId),
175
- };
176
- },
177
- },
178
- {
179
- name: 'session/restore',
180
- description: 'Restore a saved session',
181
- category: 'session',
182
- inputSchema: {
183
- type: 'object',
184
- properties: {
185
- sessionId: { type: 'string', description: 'Session ID to restore' },
186
- name: { type: 'string', description: 'Session name to restore' },
187
- },
188
- },
189
- handler: async (input) => {
190
- let session: SessionRecord | null = null;
191
-
192
- // Try to find by sessionId first
193
- if (input.sessionId) {
194
- session = loadSession(input.sessionId as string);
195
- }
196
-
197
- // Try to find by name if sessionId not found
198
- if (!session && input.name) {
199
- const sessions = listSessions();
200
- session = sessions.find(s => s.name === input.name) || null;
201
- }
202
-
203
- // Try to find latest if no params
204
- if (!session && !input.sessionId && !input.name) {
205
- const sessions = listSessions();
206
- if (sessions.length > 0) {
207
- sessions.sort((a, b) => new Date(b.savedAt).getTime() - new Date(a.savedAt).getTime());
208
- session = sessions[0];
209
- }
210
- }
211
-
212
- if (session) {
213
- // Restore data to respective stores
214
- if (session.data?.memory) {
215
- const memoryDir = join(process.cwd(), STORAGE_DIR, 'memory');
216
- if (!existsSync(memoryDir)) mkdirSync(memoryDir, { recursive: true });
217
- writeFileSync(join(memoryDir, 'store.json'), JSON.stringify(session.data.memory, null, 2), 'utf-8');
218
- }
219
- if (session.data?.tasks) {
220
- const taskDir = join(process.cwd(), STORAGE_DIR, 'tasks');
221
- if (!existsSync(taskDir)) mkdirSync(taskDir, { recursive: true });
222
- writeFileSync(join(taskDir, 'store.json'), JSON.stringify(session.data.tasks, null, 2), 'utf-8');
223
- }
224
- if (session.data?.agents) {
225
- const agentDir = join(process.cwd(), STORAGE_DIR, 'agents');
226
- if (!existsSync(agentDir)) mkdirSync(agentDir, { recursive: true });
227
- writeFileSync(join(agentDir, 'store.json'), JSON.stringify(session.data.agents, null, 2), 'utf-8');
228
- }
229
-
230
- return {
231
- sessionId: session.sessionId,
232
- name: session.name,
233
- restored: true,
234
- restoredAt: new Date().toISOString(),
235
- stats: session.stats,
236
- };
237
- }
238
-
239
- return {
240
- sessionId: input.sessionId || input.name || 'latest',
241
- restored: false,
242
- error: 'Session not found',
243
- };
244
- },
245
- },
246
- {
247
- name: 'session/list',
248
- description: 'List saved sessions',
249
- category: 'session',
250
- inputSchema: {
251
- type: 'object',
252
- properties: {
253
- limit: { type: 'number', description: 'Maximum sessions to return' },
254
- sortBy: { type: 'string', description: 'Sort field (date, name, size)' },
255
- },
256
- },
257
- handler: async (input) => {
258
- let sessions = listSessions();
259
-
260
- // Sort
261
- const sortBy = (input.sortBy as string) || 'date';
262
- if (sortBy === 'date') {
263
- sessions.sort((a, b) => new Date(b.savedAt).getTime() - new Date(a.savedAt).getTime());
264
- } else if (sortBy === 'name') {
265
- sessions.sort((a, b) => a.name.localeCompare(b.name));
266
- } else if (sortBy === 'size') {
267
- sessions.sort((a, b) => b.stats.totalSize - a.stats.totalSize);
268
- }
269
-
270
- // Apply limit
271
- const limit = (input.limit as number) || 10;
272
- sessions = sessions.slice(0, limit);
273
-
274
- return {
275
- sessions: sessions.map(s => ({
276
- sessionId: s.sessionId,
277
- name: s.name,
278
- description: s.description,
279
- savedAt: s.savedAt,
280
- stats: s.stats,
281
- })),
282
- total: sessions.length,
283
- limit,
284
- };
285
- },
286
- },
287
- {
288
- name: 'session/delete',
289
- description: 'Delete a saved session',
290
- category: 'session',
291
- inputSchema: {
292
- type: 'object',
293
- properties: {
294
- sessionId: { type: 'string', description: 'Session ID to delete' },
295
- },
296
- required: ['sessionId'],
297
- },
298
- handler: async (input) => {
299
- const sessionId = input.sessionId as string;
300
- const path = getSessionPath(sessionId);
301
-
302
- if (existsSync(path)) {
303
- unlinkSync(path);
304
- return {
305
- sessionId,
306
- deleted: true,
307
- deletedAt: new Date().toISOString(),
308
- };
309
- }
310
-
311
- return {
312
- sessionId,
313
- deleted: false,
314
- error: 'Session not found',
315
- };
316
- },
317
- },
318
- {
319
- name: 'session/info',
320
- description: 'Get detailed session information',
321
- category: 'session',
322
- inputSchema: {
323
- type: 'object',
324
- properties: {
325
- sessionId: { type: 'string', description: 'Session ID' },
326
- },
327
- required: ['sessionId'],
328
- },
329
- handler: async (input) => {
330
- const sessionId = input.sessionId as string;
331
- const session = loadSession(sessionId);
332
-
333
- if (session) {
334
- const path = getSessionPath(sessionId);
335
- const stat = statSync(path);
336
-
337
- return {
338
- sessionId: session.sessionId,
339
- name: session.name,
340
- description: session.description,
341
- savedAt: session.savedAt,
342
- stats: session.stats,
343
- fileSize: stat.size,
344
- path,
345
- hasData: {
346
- memory: !!session.data?.memory,
347
- tasks: !!session.data?.tasks,
348
- agents: !!session.data?.agents,
349
- },
350
- };
351
- }
352
-
353
- return {
354
- sessionId,
355
- error: 'Session not found',
356
- };
357
- },
358
- },
359
- ];