memhouse 0.0.1 → 0.3.1

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 (97) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +72 -3
  3. package/bin/memhouse.js +559 -0
  4. package/cache.js +850 -0
  5. package/ch-ingest.js +329 -0
  6. package/ch-schema.js +152 -0
  7. package/clickhouse.js +87 -0
  8. package/editors/adapter-errors.js +52 -0
  9. package/editors/antigravity.js +1048 -0
  10. package/editors/base.js +321 -0
  11. package/editors/claude.js +386 -0
  12. package/editors/codebuff.js +338 -0
  13. package/editors/codex.js +537 -0
  14. package/editors/commandcode.js +166 -0
  15. package/editors/copilot-jetbrains.js +207 -0
  16. package/editors/copilot.js +260 -0
  17. package/editors/cursor-agent.js +202 -0
  18. package/editors/cursor.js +498 -0
  19. package/editors/gemini.js +231 -0
  20. package/editors/goose.js +386 -0
  21. package/editors/gsd.js +366 -0
  22. package/editors/index.js +274 -0
  23. package/editors/kiro.js +315 -0
  24. package/editors/opencode.js +432 -0
  25. package/editors/vscode.js +413 -0
  26. package/editors/windsurf.js +634 -0
  27. package/editors/zed.js +229 -0
  28. package/index.js +424 -2
  29. package/mcp-server.js +294 -0
  30. package/mem-house/DESIGN.md +119 -0
  31. package/mem-house/delivery/AGENT-INSTALL.md +87 -0
  32. package/mem-house/delivery/PROMPT.md +42 -0
  33. package/mem-house/delivery/install.sh +181 -0
  34. package/mem-house/delivery/kernel-install.md +83 -0
  35. package/mem-house/delivery/plugin/.claude-plugin/plugin.json +8 -0
  36. package/mem-house/delivery/skills/memhouse-search/SKILL.md +104 -0
  37. package/mem-house/delivery/skills/memhouse-sessions/SKILL.md +94 -0
  38. package/mem-house/delivery/skills/memhouse-sql/SKILL.md +115 -0
  39. package/mem-house/rls.sql +17 -0
  40. package/mem-house/schema.sql +145 -0
  41. package/mem-house/server/queries.js +878 -0
  42. package/mem-house/server/server.js +228 -0
  43. package/mem-house/shipper/ship.js +461 -0
  44. package/misc/syntax-check.js +38 -0
  45. package/package.json +59 -7
  46. package/pricing.js +88 -0
  47. package/pricing.json +992 -0
  48. package/public/assets/index-CCPh7a2Z.js +75 -0
  49. package/public/assets/index-DV6ONi_F.css +2 -0
  50. package/public/index.html +16 -0
  51. package/relay-client.js +306 -0
  52. package/relay-server.js +577 -0
  53. package/server.js +860 -0
  54. package/share-image.js +367 -0
  55. package/ui/eslint.config.js +29 -0
  56. package/ui/index.html +15 -0
  57. package/ui/package-lock.json +4229 -0
  58. package/ui/package.json +38 -0
  59. package/ui/src/App.jsx +364 -0
  60. package/ui/src/components/ActivityHeatmap.jsx +206 -0
  61. package/ui/src/components/AiAuditCard.jsx +254 -0
  62. package/ui/src/components/AnimatedLoader.jsx +14 -0
  63. package/ui/src/components/AnimatedLogo.jsx +96 -0
  64. package/ui/src/components/ChatSidebar.jsx +226 -0
  65. package/ui/src/components/DateRangePicker.jsx +104 -0
  66. package/ui/src/components/EditorDot.jsx +11 -0
  67. package/ui/src/components/EditorIcon.jsx +117 -0
  68. package/ui/src/components/KpiCard.jsx +9 -0
  69. package/ui/src/components/LiveFeed.jsx +128 -0
  70. package/ui/src/components/LoginScreen.jsx +81 -0
  71. package/ui/src/components/MessageRenderer.jsx +148 -0
  72. package/ui/src/components/PageHeader.jsx +11 -0
  73. package/ui/src/components/SectionTitle.jsx +3 -0
  74. package/ui/src/components/ShareModal.jsx +305 -0
  75. package/ui/src/components/TokenTimeline.jsx +258 -0
  76. package/ui/src/hooks/useLive.jsx +15 -0
  77. package/ui/src/index.css +83 -0
  78. package/ui/src/lib/api.js +343 -0
  79. package/ui/src/lib/constants.js +88 -0
  80. package/ui/src/lib/theme.jsx +23 -0
  81. package/ui/src/main.jsx +16 -0
  82. package/ui/src/pages/Artifacts.jsx +575 -0
  83. package/ui/src/pages/Compare.jsx +232 -0
  84. package/ui/src/pages/CostAnalysis.jsx +354 -0
  85. package/ui/src/pages/Dashboard.jsx +529 -0
  86. package/ui/src/pages/DeepAnalysis.jsx +495 -0
  87. package/ui/src/pages/GSD.jsx +726 -0
  88. package/ui/src/pages/MCPs.jsx +744 -0
  89. package/ui/src/pages/ProjectDetail.jsx +325 -0
  90. package/ui/src/pages/Projects.jsx +249 -0
  91. package/ui/src/pages/RelayDashboard.jsx +590 -0
  92. package/ui/src/pages/RelayUserDetail.jsx +466 -0
  93. package/ui/src/pages/Sessions.jsx +535 -0
  94. package/ui/src/pages/Settings.jsx +241 -0
  95. package/ui/src/pages/SqlViewer.jsx +370 -0
  96. package/ui/src/pages/Subscriptions.jsx +411 -0
  97. package/ui/vite.config.js +18 -0
@@ -0,0 +1,315 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const os = require('os');
4
+ const { getAppDataPath } = require('./base');
5
+
6
+ // ============================================================
7
+ // Kiro editor adapter
8
+ // ============================================================
9
+
10
+ const name = 'kiro';
11
+
12
+ const KIRO_AGENT_DIR = path.join(
13
+ getAppDataPath('Kiro'), 'User', 'globalStorage', 'kiro.kiroagent'
14
+ );
15
+ const WORKSPACE_SESSIONS_DIR = path.join(KIRO_AGENT_DIR, 'workspace-sessions');
16
+
17
+ function getChats() {
18
+ const chats = [];
19
+ if (!fs.existsSync(KIRO_AGENT_DIR)) return chats;
20
+
21
+ // Strategy 1: workspace-sessions (structured, has workspace info)
22
+ if (fs.existsSync(WORKSPACE_SESSIONS_DIR)) {
23
+ try {
24
+ for (const folder of fs.readdirSync(WORKSPACE_SESSIONS_DIR)) {
25
+ const wsDir = path.join(WORKSPACE_SESSIONS_DIR, folder);
26
+ if (!fs.statSync(wsDir).isDirectory()) continue;
27
+
28
+ // Decode base64 folder name to get workspace path
29
+ let workspacePath = null;
30
+ try {
31
+ workspacePath = Buffer.from(folder, 'base64').toString('utf-8');
32
+ } catch {}
33
+
34
+ const indexPath = path.join(wsDir, 'sessions.json');
35
+ let sessions = [];
36
+ try {
37
+ sessions = JSON.parse(fs.readFileSync(indexPath, 'utf-8'));
38
+ } catch { continue; }
39
+
40
+ for (const session of sessions) {
41
+ const sessionFile = path.join(wsDir, `${session.sessionId}.json`);
42
+ const exists = fs.existsSync(sessionFile);
43
+
44
+ chats.push({
45
+ source: 'kiro',
46
+ composerId: session.sessionId,
47
+ name: cleanTitle(session.title),
48
+ createdAt: parseInt(session.dateCreated) || null,
49
+ lastUpdatedAt: exists ? getFileMtime(sessionFile) : parseInt(session.dateCreated) || null,
50
+ mode: 'kiro',
51
+ folder: session.workspaceDirectory || workspacePath || null,
52
+ encrypted: false,
53
+ bubbleCount: 0,
54
+ _fullPath: exists ? sessionFile : null,
55
+ _type: 'workspace-session',
56
+ });
57
+ }
58
+ }
59
+ } catch {}
60
+ }
61
+
62
+ // Strategy 2: .chat files in hash directories (individual agent executions)
63
+ // Kiro saves a snapshot of the conversation after each API call, so multiple
64
+ // .chat files can share the same executionId. We group by executionId and
65
+ // keep only the latest snapshot (highest message count) per conversation.
66
+ const seenIds = new Set(chats.map(c => c.composerId));
67
+ const executionMap = new Map(); // executionId -> best candidate
68
+ try {
69
+ for (const dir of fs.readdirSync(KIRO_AGENT_DIR)) {
70
+ // Skip known non-workspace directories
71
+ if (['default', 'dev_data', 'index', 'sessions', 'workspace-sessions'].includes(dir)) continue;
72
+ const fullDir = path.join(KIRO_AGENT_DIR, dir);
73
+ if (!fs.statSync(fullDir).isDirectory()) continue;
74
+
75
+ let files;
76
+ try { files = fs.readdirSync(fullDir).filter(f => f.endsWith('.chat')); } catch { continue; }
77
+
78
+ for (const file of files) {
79
+ const fullPath = path.join(fullDir, file);
80
+ try {
81
+ const stat = fs.statSync(fullPath);
82
+ const meta = peekChatMeta(fullPath);
83
+ const chatId = meta.executionId || `${dir}/${file.replace('.chat', '')}`;
84
+ if (seenIds.has(chatId)) continue;
85
+
86
+ const candidate = {
87
+ source: 'kiro',
88
+ composerId: chatId,
89
+ name: meta.title || null,
90
+ createdAt: meta.startTime || stat.birthtime.getTime(),
91
+ lastUpdatedAt: meta.endTime || stat.mtime.getTime(),
92
+ mode: meta.workflow || 'kiro',
93
+ folder: meta.folder || null,
94
+ encrypted: false,
95
+ bubbleCount: meta.messageCount || 0,
96
+ _fullPath: fullPath,
97
+ _type: 'chat-file',
98
+ };
99
+
100
+ // Keep the snapshot with the most messages per executionId
101
+ if (meta.executionId) {
102
+ const existing = executionMap.get(meta.executionId);
103
+ if (!existing || meta.messageCount > existing.bubbleCount) {
104
+ // Update createdAt to the earliest startTime seen
105
+ if (existing && existing.createdAt < candidate.createdAt) {
106
+ candidate.createdAt = existing.createdAt;
107
+ }
108
+ executionMap.set(meta.executionId, candidate);
109
+ } else if (existing && meta.startTime && meta.startTime < existing.createdAt) {
110
+ existing.createdAt = meta.startTime;
111
+ }
112
+ } else {
113
+ chats.push(candidate);
114
+ }
115
+ } catch {}
116
+ }
117
+ }
118
+ } catch {}
119
+
120
+ // Add the deduplicated execution sessions
121
+ for (const chat of executionMap.values()) {
122
+ chats.push(chat);
123
+ }
124
+
125
+ return chats;
126
+ }
127
+
128
+ function peekChatMeta(filePath) {
129
+ const meta = { title: null, folder: null, startTime: null, endTime: null, workflow: null, messageCount: 0, executionId: null };
130
+ try {
131
+ const raw = fs.readFileSync(filePath, 'utf-8');
132
+ const data = JSON.parse(raw);
133
+
134
+ meta.executionId = data.executionId || null;
135
+
136
+ if (data.metadata) {
137
+ meta.startTime = data.metadata.startTime || null;
138
+ meta.endTime = data.metadata.endTime || null;
139
+ meta.workflow = data.metadata.workflow || null;
140
+ }
141
+
142
+ const chat = data.chat || [];
143
+ for (const msg of chat) {
144
+ if (msg.role === 'human') {
145
+ // Try to extract user request from rules block
146
+ const userReq = extractUserRequest(msg.content);
147
+ if (userReq && !meta.title) {
148
+ meta.title = cleanTitle(userReq);
149
+ }
150
+ }
151
+ if (msg.role === 'bot' || msg.role === 'human') meta.messageCount++;
152
+ }
153
+
154
+ // Try to extract folder from context
155
+ for (const ctx of data.context || []) {
156
+ if (ctx.type === 'steering' && ctx.id) {
157
+ // Extract workspace from steering file path
158
+ const match = ctx.id.match(/file:\/\/(.*?)\/.kiro\//);
159
+ if (match) meta.folder = match[1];
160
+ }
161
+ }
162
+ } catch {}
163
+ return meta;
164
+ }
165
+
166
+ function isSystemPrompt(content) {
167
+ if (typeof content !== 'string') return false;
168
+ return content.startsWith('<identity>') || content.startsWith('# ');
169
+ }
170
+
171
+ function extractUserRequest(content) {
172
+ if (typeof content !== 'string') return null;
173
+ // "## Included Rules" messages contain the actual user request after </user-rule>
174
+ const ruleEnd = content.lastIndexOf('</user-rule>');
175
+ if (ruleEnd >= 0) {
176
+ let userPart = content.substring(ruleEnd + '</user-rule>'.length).trim();
177
+ // Strip trailing EnvironmentContext block
178
+ const envIdx = userPart.indexOf('<EnvironmentContext>');
179
+ if (envIdx >= 0) userPart = userPart.substring(0, envIdx).trim();
180
+ // Strip steering-reminder blocks
181
+ const steerIdx = userPart.indexOf('<steering-reminder>');
182
+ if (steerIdx >= 0) userPart = userPart.substring(0, steerIdx).trim();
183
+ if (userPart) return userPart;
184
+ }
185
+ return null;
186
+ }
187
+
188
+ function getMessages(chat) {
189
+ if (!chat._fullPath || !fs.existsSync(chat._fullPath)) return [];
190
+
191
+ if (chat._type === 'workspace-session') {
192
+ return getWorkspaceSessionMessages(chat._fullPath);
193
+ }
194
+ return getChatFileMessages(chat._fullPath);
195
+ }
196
+
197
+ function getWorkspaceSessionMessages(filePath) {
198
+ const messages = [];
199
+ try {
200
+ const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
201
+ const history = data.history || [];
202
+
203
+ for (const entry of history) {
204
+ const msg = entry.message;
205
+ if (!msg) continue;
206
+
207
+ const role = msg.role === 'user' ? 'user' : msg.role === 'assistant' ? 'assistant' : null;
208
+ if (!role) continue;
209
+
210
+ const content = extractContentFromMessage(msg.content);
211
+ if (!content) continue;
212
+
213
+ const result = { role, content };
214
+
215
+ // Extract model info from promptLogs
216
+ if (role === 'assistant' && entry.promptLogs && entry.promptLogs.length > 0) {
217
+ const log = entry.promptLogs[0];
218
+ result._model = log.modelTitle || null;
219
+ }
220
+
221
+ messages.push(result);
222
+ }
223
+ } catch {}
224
+ return messages;
225
+ }
226
+
227
+ function getChatFileMessages(filePath) {
228
+ const messages = [];
229
+ try {
230
+ const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
231
+ const chat = data.chat || [];
232
+ const model = data.metadata?.modelId || null;
233
+
234
+ for (const msg of chat) {
235
+ if (msg.role === 'human') {
236
+ if (isSystemPrompt(msg.content)) continue;
237
+ // Try extracting user request from rules block first
238
+ const userReq = extractUserRequest(msg.content);
239
+ const content = userReq || extractUserText(msg.content);
240
+ if (content) messages.push({ role: 'user', content });
241
+ } else if (msg.role === 'bot') {
242
+ const content = typeof msg.content === 'string' ? msg.content : '';
243
+ if (content) messages.push({ role: 'assistant', content, _model: model });
244
+ } else if (msg.role === 'tool') {
245
+ const content = typeof msg.content === 'string' ? msg.content : '';
246
+ if (content) messages.push({ role: 'tool', content: content.substring(0, 2000) });
247
+ }
248
+ }
249
+ } catch {}
250
+ return messages;
251
+ }
252
+
253
+ function extractContentFromMessage(content) {
254
+ if (typeof content === 'string') return content;
255
+ if (!Array.isArray(content)) return '';
256
+ return content
257
+ .filter(c => c.type === 'text' || c.type === 'mention')
258
+ .map(c => c.text)
259
+ .join('\n') || '';
260
+ }
261
+
262
+ function extractUserText(content) {
263
+ if (typeof content === 'string') {
264
+ // Skip system prompt content
265
+ if (isSystemPrompt(content)) return null;
266
+ // Strip XML tags and rules blocks
267
+ return cleanTitle(content);
268
+ }
269
+ if (Array.isArray(content)) {
270
+ return content
271
+ .filter(c => c.type === 'text' || c.type === 'mention')
272
+ .map(c => c.text)
273
+ .join('\n') || '';
274
+ }
275
+ return '';
276
+ }
277
+
278
+ function cleanTitle(title) {
279
+ if (!title) return null;
280
+ let clean = title
281
+ .replace(/<[^>]+>[\s\S]*?<\/[^>]+>/g, '')
282
+ .replace(/<[^>]+>/g, '')
283
+ .replace(/## Included Rules[\s\S]*$/m, '')
284
+ .replace(/\s+/g, ' ')
285
+ .trim()
286
+ .substring(0, 120);
287
+ return clean || null;
288
+ }
289
+
290
+ function getFileMtime(filePath) {
291
+ try { return fs.statSync(filePath).mtime.getTime(); } catch { return null; }
292
+ }
293
+
294
+ const labels = { 'kiro': 'Kiro' };
295
+
296
+ function getArtifacts(folder) {
297
+ const { scanArtifacts } = require('./base');
298
+ return scanArtifacts(folder, {
299
+ editor: 'kiro',
300
+ label: 'Kiro',
301
+ files: ['AGENTS.md'],
302
+ dirs: ['.kiro/specs', '.kiro/steering'],
303
+ });
304
+ }
305
+
306
+ function getMCPServers() {
307
+ const { parseMcpConfigFile } = require('./base');
308
+ // Global: ~/.kiro/settings/mcp.json
309
+ const globalConfig = path.join(os.homedir(), '.kiro', 'settings', 'mcp.json');
310
+ return [
311
+ ...parseMcpConfigFile(globalConfig, { editor: 'kiro', label: 'Kiro', scope: 'global' }),
312
+ ];
313
+ }
314
+
315
+ module.exports = { name, labels, getChats, getMessages, getArtifacts, getMCPServers };