cliper-memory 0.1.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 (134) hide show
  1. package/README.md +268 -0
  2. package/dist/auth/config.d.ts +13 -0
  3. package/dist/auth/config.d.ts.map +1 -0
  4. package/dist/auth/config.js +33 -0
  5. package/dist/auth/config.js.map +1 -0
  6. package/dist/auth/github.d.ts +5 -0
  7. package/dist/auth/github.d.ts.map +1 -0
  8. package/dist/auth/github.js +38 -0
  9. package/dist/auth/github.js.map +1 -0
  10. package/dist/cognee/legacyClient.d.ts +20 -0
  11. package/dist/cognee/legacyClient.d.ts.map +1 -0
  12. package/dist/cognee/legacyClient.js +409 -0
  13. package/dist/cognee/legacyClient.js.map +1 -0
  14. package/dist/commands/analyze.d.ts +6 -0
  15. package/dist/commands/analyze.d.ts.map +1 -0
  16. package/dist/commands/analyze.js +216 -0
  17. package/dist/commands/analyze.js.map +1 -0
  18. package/dist/commands/auth.d.ts +3 -0
  19. package/dist/commands/auth.d.ts.map +1 -0
  20. package/dist/commands/auth.js +85 -0
  21. package/dist/commands/auth.js.map +1 -0
  22. package/dist/commands/export.d.ts +6 -0
  23. package/dist/commands/export.d.ts.map +1 -0
  24. package/dist/commands/export.js +64 -0
  25. package/dist/commands/export.js.map +1 -0
  26. package/dist/commands/init.d.ts +7 -0
  27. package/dist/commands/init.d.ts.map +1 -0
  28. package/dist/commands/init.js +220 -0
  29. package/dist/commands/init.js.map +1 -0
  30. package/dist/commands/push.d.ts +2 -0
  31. package/dist/commands/push.d.ts.map +1 -0
  32. package/dist/commands/push.js +94 -0
  33. package/dist/commands/push.js.map +1 -0
  34. package/dist/commands/scope.d.ts +2 -0
  35. package/dist/commands/scope.d.ts.map +1 -0
  36. package/dist/commands/scope.js +124 -0
  37. package/dist/commands/scope.js.map +1 -0
  38. package/dist/commands/status.d.ts +2 -0
  39. package/dist/commands/status.d.ts.map +1 -0
  40. package/dist/commands/status.js +100 -0
  41. package/dist/commands/status.js.map +1 -0
  42. package/dist/commands/sync.d.ts +6 -0
  43. package/dist/commands/sync.d.ts.map +1 -0
  44. package/dist/commands/sync.js +83 -0
  45. package/dist/commands/sync.js.map +1 -0
  46. package/dist/commands/view.d.ts +2 -0
  47. package/dist/commands/view.d.ts.map +1 -0
  48. package/dist/commands/view.js +60 -0
  49. package/dist/commands/view.js.map +1 -0
  50. package/dist/context/builder.d.ts +19 -0
  51. package/dist/context/builder.d.ts.map +1 -0
  52. package/dist/context/builder.js +143 -0
  53. package/dist/context/builder.js.map +1 -0
  54. package/dist/gaps/detector.d.ts +10 -0
  55. package/dist/gaps/detector.d.ts.map +1 -0
  56. package/dist/gaps/detector.js +139 -0
  57. package/dist/gaps/detector.js.map +1 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +101 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/providers/cognee/client.d.ts +32 -0
  63. package/dist/providers/cognee/client.d.ts.map +1 -0
  64. package/dist/providers/cognee/client.js +189 -0
  65. package/dist/providers/cognee/client.js.map +1 -0
  66. package/dist/providers/cognee/provider.d.ts +7 -0
  67. package/dist/providers/cognee/provider.d.ts.map +1 -0
  68. package/dist/providers/cognee/provider.js +17 -0
  69. package/dist/providers/cognee/provider.js.map +1 -0
  70. package/dist/providers/memoryProvider.d.ts +4 -0
  71. package/dist/providers/memoryProvider.d.ts.map +1 -0
  72. package/dist/providers/memoryProvider.js +3 -0
  73. package/dist/providers/memoryProvider.js.map +1 -0
  74. package/dist/resolver/urlFetcher.d.ts +9 -0
  75. package/dist/resolver/urlFetcher.d.ts.map +1 -0
  76. package/dist/resolver/urlFetcher.js +134 -0
  77. package/dist/resolver/urlFetcher.js.map +1 -0
  78. package/dist/scanner/dependencies.d.ts +14 -0
  79. package/dist/scanner/dependencies.d.ts.map +1 -0
  80. package/dist/scanner/dependencies.js +203 -0
  81. package/dist/scanner/dependencies.js.map +1 -0
  82. package/dist/scanner/fileContent.d.ts +8 -0
  83. package/dist/scanner/fileContent.d.ts.map +1 -0
  84. package/dist/scanner/fileContent.js +133 -0
  85. package/dist/scanner/fileContent.js.map +1 -0
  86. package/dist/scanner/fileTree.d.ts +2 -0
  87. package/dist/scanner/fileTree.d.ts.map +1 -0
  88. package/dist/scanner/fileTree.js +152 -0
  89. package/dist/scanner/fileTree.js.map +1 -0
  90. package/dist/scanner/gitContext.d.ts +25 -0
  91. package/dist/scanner/gitContext.d.ts.map +1 -0
  92. package/dist/scanner/gitContext.js +76 -0
  93. package/dist/scanner/gitContext.js.map +1 -0
  94. package/dist/scanner/github.d.ts +5 -0
  95. package/dist/scanner/github.d.ts.map +1 -0
  96. package/dist/scanner/github.js +30 -0
  97. package/dist/scanner/github.js.map +1 -0
  98. package/dist/scanner/githubIssues.d.ts +12 -0
  99. package/dist/scanner/githubIssues.d.ts.map +1 -0
  100. package/dist/scanner/githubIssues.js +31 -0
  101. package/dist/scanner/githubIssues.js.map +1 -0
  102. package/dist/scanner/githubPullRequests.d.ts +17 -0
  103. package/dist/scanner/githubPullRequests.d.ts.map +1 -0
  104. package/dist/scanner/githubPullRequests.js +57 -0
  105. package/dist/scanner/githubPullRequests.js.map +1 -0
  106. package/dist/scanner/semanticLabels.d.ts +12 -0
  107. package/dist/scanner/semanticLabels.d.ts.map +1 -0
  108. package/dist/scanner/semanticLabels.js +185 -0
  109. package/dist/scanner/semanticLabels.js.map +1 -0
  110. package/dist/scope/autoScope.d.ts +2 -0
  111. package/dist/scope/autoScope.d.ts.map +1 -0
  112. package/dist/scope/autoScope.js +233 -0
  113. package/dist/scope/autoScope.js.map +1 -0
  114. package/dist/scope/config.d.ts +10 -0
  115. package/dist/scope/config.d.ts.map +1 -0
  116. package/dist/scope/config.js +71 -0
  117. package/dist/scope/config.js.map +1 -0
  118. package/dist/sdk/cliper.d.ts +8 -0
  119. package/dist/sdk/cliper.d.ts.map +1 -0
  120. package/dist/sdk/cliper.js +11 -0
  121. package/dist/sdk/cliper.js.map +1 -0
  122. package/dist/sdk/memory/memory.d.ts +11 -0
  123. package/dist/sdk/memory/memory.d.ts.map +1 -0
  124. package/dist/sdk/memory/memory.js +3 -0
  125. package/dist/sdk/memory/memory.js.map +1 -0
  126. package/dist/sdk/memoryBuilder.d.ts +56 -0
  127. package/dist/sdk/memoryBuilder.d.ts.map +1 -0
  128. package/dist/sdk/memoryBuilder.js +821 -0
  129. package/dist/sdk/memoryBuilder.js.map +1 -0
  130. package/dist/sdk/memoryDeduplicator.d.ts +5 -0
  131. package/dist/sdk/memoryDeduplicator.d.ts.map +1 -0
  132. package/dist/sdk/memoryDeduplicator.js +14 -0
  133. package/dist/sdk/memoryDeduplicator.js.map +1 -0
  134. package/package.json +67 -0
@@ -0,0 +1,821 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.MemoryBuilder = void 0;
40
+ const path = __importStar(require("path"));
41
+ const simple_git_1 = __importDefault(require("simple-git"));
42
+ const memoryDeduplicator_1 = require("./memoryDeduplicator");
43
+ class MemoryBuilder {
44
+ buildGitMemory(projectName, gitContext) {
45
+ if (!gitContext.isGitRepo) {
46
+ return [];
47
+ }
48
+ return [{
49
+ id: "git-context",
50
+ type: "git",
51
+ title: "Git Context",
52
+ content: `
53
+ Project: ${projectName}
54
+ Branch: ${gitContext.branch}
55
+ Latest Commit:
56
+ ${gitContext.lastCommit?.message ?? "None"}
57
+ `.trim(),
58
+ metadata: {
59
+ branch: gitContext.branch
60
+ }
61
+ }];
62
+ }
63
+ extractExports(content) {
64
+ const exports = new Set();
65
+ const patterns = [
66
+ /export\s+(?:async\s+)?function\s+([A-Za-z0-9_]+)/g,
67
+ /export\s+class\s+([A-Za-z0-9_]+)/g,
68
+ /export\s+const\s+([A-Za-z0-9_]+)/g,
69
+ /export\s+interface\s+([A-Za-z0-9_]+)/g,
70
+ /export\s+type\s+([A-Za-z0-9_]+)/g,
71
+ ];
72
+ for (const pattern of patterns) {
73
+ for (const match of content.matchAll(pattern)) {
74
+ exports.add(match[1]);
75
+ }
76
+ }
77
+ return [...exports];
78
+ }
79
+ inferPurpose(filePath) {
80
+ const name = path.basename(filePath, path.extname(filePath));
81
+ if (filePath === "src/index.ts") {
82
+ return "Entry point for the Cliper CLI";
83
+ }
84
+ const purposeMap = {
85
+ init: "Initialize repository analysis and context generation",
86
+ sync: "Synchronize repository state",
87
+ status: "Display repository status information",
88
+ scope: "Manage repository scope configuration",
89
+ auth: "Handle authentication workflows",
90
+ export: "Export repository context",
91
+ analyze: "Analyze repository structure and intelligence",
92
+ dependencies: "Build dependency relationships",
93
+ gitContext: "Collect git repository information",
94
+ fileTree: "Generate repository file tree",
95
+ fileContent: "Extract file contents",
96
+ urlFetcher: "Fetch and resolve external references",
97
+ detector: "Detect repository gaps and missing information",
98
+ builder: "Build repository context documents",
99
+ client: "Communicate with Cognee services",
100
+ };
101
+ return (purposeMap[name] ??
102
+ `Provide functionality related to ${name}`);
103
+ }
104
+ inferResponsibilities(file) {
105
+ const responsibilities = [];
106
+ const content = file.content;
107
+ if (content.includes("generateFileTree")) {
108
+ responsibilities.push("Build repository file tree");
109
+ }
110
+ if (content.includes("extractFileContents")) {
111
+ responsibilities.push("Extract file contents");
112
+ }
113
+ if (content.includes("getGitContext")) {
114
+ responsibilities.push("Collect git metadata");
115
+ }
116
+ if (content.includes("detectGaps")) {
117
+ responsibilities.push("Detect repository gaps");
118
+ }
119
+ if (content.includes("buildContextDoc")) {
120
+ responsibilities.push("Generate repository context");
121
+ }
122
+ if (content.includes("rememberContext")) {
123
+ responsibilities.push("Sync memories to Cognee");
124
+ }
125
+ if (content.includes("buildDependencyMap")) {
126
+ responsibilities.push("Build dependency graph");
127
+ }
128
+ return responsibilities;
129
+ }
130
+ getFileCategory(filePath) {
131
+ if (filePath === "src/index.ts") {
132
+ return "CLI Entry Point";
133
+ }
134
+ if (filePath.includes("/commands/")) {
135
+ return "CLI Command";
136
+ }
137
+ if (filePath.includes("/scanner/")) {
138
+ return "Repository Scanner";
139
+ }
140
+ if (filePath.includes("/resolver/")) {
141
+ return "Reference Resolver";
142
+ }
143
+ if (filePath.includes("/scope/")) {
144
+ return "Scope Management";
145
+ }
146
+ if (filePath.includes("/gaps/")) {
147
+ return "Gap Detection";
148
+ }
149
+ if (filePath.includes("/context/")) {
150
+ return "Context Builder";
151
+ }
152
+ if (filePath.includes("/cognee/")) {
153
+ return "Cognee Integration";
154
+ }
155
+ return "Project File";
156
+ }
157
+ extractExternalPackages(content) {
158
+ const packages = new Set();
159
+ const importRegex = /from\s+["']([^"']+)["']/g;
160
+ const requireRegex = /require\(["']([^"']+)["']\)/g;
161
+ for (const match of content.matchAll(importRegex)) {
162
+ const pkg = match[1];
163
+ if (!pkg.startsWith(".") &&
164
+ !pkg.startsWith("/")) {
165
+ packages.add(pkg);
166
+ }
167
+ }
168
+ for (const match of content.matchAll(requireRegex)) {
169
+ const pkg = match[1];
170
+ if (!pkg.startsWith(".") &&
171
+ !pkg.startsWith("/")) {
172
+ packages.add(pkg);
173
+ }
174
+ }
175
+ return [...packages];
176
+ }
177
+ buildFileSummary(file, dependencyMap) {
178
+ const imports = dependencyMap.edges
179
+ .filter(edge => edge.from === file.relativePath)
180
+ .map(edge => edge.to);
181
+ return {
182
+ path: file.relativePath,
183
+ category: this.getFileCategory(file.relativePath),
184
+ purpose: this.inferPurpose(file.relativePath),
185
+ exports: this.extractExports(file.content),
186
+ imports,
187
+ responsibilities: this.inferResponsibilities(file),
188
+ externalPackages: this.extractExternalPackages(file.content)
189
+ };
190
+ }
191
+ async buildCommitSummaries(projectRoot, gitContext) {
192
+ if (!gitContext.isGitRepo) {
193
+ return [];
194
+ }
195
+ const git = (0, simple_git_1.default)(projectRoot);
196
+ const commits = [];
197
+ if (gitContext.lastCommit) {
198
+ commits.push({
199
+ hash: gitContext.lastCommit.hash,
200
+ author: gitContext.lastCommit.author,
201
+ message: gitContext.lastCommit.message,
202
+ timeAgo: gitContext.lastCommit.timeAgo,
203
+ filesChanged: await this.getFilesChangedForCommit(git, gitContext.lastCommit.hash)
204
+ });
205
+ }
206
+ for (const commit of gitContext.recentCommits) {
207
+ commits.push({
208
+ hash: commit.hash,
209
+ author: commit.author,
210
+ message: commit.message,
211
+ timeAgo: commit.timeAgo,
212
+ filesChanged: await this.getFilesChangedForCommit(git, commit.hash)
213
+ });
214
+ }
215
+ return commits;
216
+ }
217
+ async buildCommitMemories(projectRoot, gitContext) {
218
+ const commits = await this.buildCommitSummaries(projectRoot, gitContext);
219
+ return commits.map(commit => ({
220
+ id: `commit:${commit.hash}`,
221
+ type: "commit",
222
+ title: commit.message,
223
+ content: `
224
+ Commit:
225
+ ${commit.hash}
226
+
227
+ Author:
228
+ ${commit.author}
229
+
230
+ Message:
231
+ ${commit.message}
232
+
233
+ Files Changed:
234
+ ${commit.filesChanged.join("\n")}
235
+
236
+ Time:
237
+ ${commit.timeAgo}
238
+ `.trim(),
239
+ metadata: {
240
+ hash: commit.hash,
241
+ author: commit.author,
242
+ timeAgo: commit.timeAgo,
243
+ },
244
+ tags: ["git", "commit"],
245
+ relationships: [
246
+ "repository",
247
+ ...commit.filesChanged.map(file => `file:${file}`)
248
+ ],
249
+ }));
250
+ }
251
+ buildFileMemories(files, dependencyMap, semanticLabels, gitContext) {
252
+ return files.map(file => {
253
+ const summary = this.buildFileSummary(file, dependencyMap);
254
+ const semantic = semanticLabels.find(s => s.file === file.relativePath);
255
+ console.log(file.relativePath);
256
+ return {
257
+ id: `file:${summary.path}`,
258
+ type: "file",
259
+ title: summary.path,
260
+ content: this.buildFileSummaryContent(summary),
261
+ metadata: {
262
+ ...summary,
263
+ semantic
264
+ },
265
+ tags: [
266
+ summary.category,
267
+ ...(semantic?.tags ?? [])
268
+ ],
269
+ relationships: [
270
+ ...summary.imports.map(file => `file:${file}`),
271
+ ...gitContext.pullRequests
272
+ .filter(pr => pr.changedFiles.includes(summary.path))
273
+ .map(pr => `pr:${pr.number}`)
274
+ ]
275
+ };
276
+ });
277
+ }
278
+ buildFileSummaryContent(summary) {
279
+ return `
280
+ File: ${summary.path}
281
+
282
+ Category:
283
+ ${summary.category}
284
+
285
+ Purpose:
286
+ ${summary.purpose}
287
+
288
+ Responsibilities:
289
+ ${summary.responsibilities.join(", ") || "None"}
290
+
291
+ Exports:
292
+ ${summary.exports.join(", ") || "None"}
293
+
294
+ Imports:
295
+ ${summary.imports.join(", ") || "None"}
296
+
297
+ External Packages:
298
+ ${summary.externalPackages.join(", ") || "None"}
299
+ `.trim();
300
+ }
301
+ buildDependencyMemories(dependencyMap) {
302
+ return dependencyMap.edges.map(edge => ({
303
+ id: `${edge.from}->${edge.to}`,
304
+ type: "dependency",
305
+ title: `${edge.from} imports ${edge.to}`,
306
+ content: `
307
+ ${edge.from}
308
+ imports
309
+ ${edge.to}
310
+ `.trim(),
311
+ metadata: edge,
312
+ tags: [
313
+ "dependency"
314
+ ],
315
+ relationships: [
316
+ edge.from,
317
+ edge.to
318
+ ]
319
+ }));
320
+ }
321
+ buildExternalPackageMemories(dependencyMap) {
322
+ return dependencyMap.externalPackages.map(pkg => ({
323
+ id: `package:${pkg}`,
324
+ type: "package",
325
+ title: pkg,
326
+ content: `
327
+ External Package
328
+
329
+ ${pkg}
330
+ `.trim(),
331
+ metadata: {
332
+ package: pkg
333
+ },
334
+ tags: [
335
+ "package"
336
+ ],
337
+ relationships: []
338
+ }));
339
+ }
340
+ buildGapMemories(gaps) {
341
+ return gaps.map(gap => ({
342
+ id: `${gap.file}:${gap.line ?? 0}`,
343
+ type: "gap",
344
+ title: gap.description,
345
+ content: `
346
+ File:
347
+ ${gap.file}
348
+
349
+ Severity:
350
+ ${gap.severity}
351
+
352
+ Type:
353
+ ${gap.type}
354
+
355
+ Description:
356
+ ${gap.description}
357
+
358
+ Line:
359
+ ${gap.line ?? "Unknown"}
360
+ `.trim(),
361
+ metadata: gap,
362
+ tags: [
363
+ "gap",
364
+ gap.severity,
365
+ gap.type
366
+ ],
367
+ relationships: [
368
+ gap.file
369
+ ]
370
+ }));
371
+ }
372
+ buildArchitectureMemories(dependencyMap) {
373
+ const grouped = new Map();
374
+ for (const edge of dependencyMap.edges) {
375
+ if (!grouped.has(edge.from)) {
376
+ grouped.set(edge.from, new Set());
377
+ }
378
+ grouped.get(edge.from).add(edge.to);
379
+ }
380
+ return [...grouped.entries()].map(([module, imports]) => ({
381
+ id: module,
382
+ type: "architecture",
383
+ title: module,
384
+ content: `
385
+ Module:
386
+ ${module}
387
+
388
+ Depends on:
389
+ ${[...imports].join("\n")}
390
+ `.trim(),
391
+ metadata: {
392
+ module,
393
+ imports: [...imports]
394
+ },
395
+ tags: ["architecture"],
396
+ relationships: [...imports]
397
+ }));
398
+ }
399
+ buildResponsibilityMemories(files) {
400
+ const memories = [];
401
+ for (const file of files) {
402
+ const responsibilities = this.inferResponsibilities(file);
403
+ for (const responsibility of responsibilities) {
404
+ memories.push({
405
+ id: `${file.relativePath}:${responsibility}`,
406
+ type: "responsibility",
407
+ title: responsibility,
408
+ content: `
409
+ Responsibility:
410
+ ${responsibility}
411
+
412
+ Owner:
413
+ ${file.relativePath}
414
+ `.trim(),
415
+ metadata: {
416
+ responsibility,
417
+ owner: file.relativePath
418
+ },
419
+ tags: [
420
+ "responsibility"
421
+ ],
422
+ relationships: [
423
+ file.relativePath
424
+ ]
425
+ });
426
+ }
427
+ }
428
+ return memories;
429
+ }
430
+ async getFilesChangedForCommit(git, hash) {
431
+ const output = await git.show([
432
+ "--name-only",
433
+ "--pretty=format:",
434
+ hash,
435
+ ]);
436
+ return output
437
+ .split("\n")
438
+ .map(line => line.trim())
439
+ .filter(Boolean);
440
+ }
441
+ buildRepositorySummary(options) {
442
+ const modules = new Set();
443
+ for (const file of options.files) {
444
+ const parts = file.relativePath.split("/");
445
+ if (parts.length > 1) {
446
+ modules.add(parts[1]);
447
+ }
448
+ }
449
+ return {
450
+ name: options.projectName,
451
+ root: options.projectRoot,
452
+ language: "TypeScript",
453
+ entryPoint: options.files.find(f => f.relativePath === "src/index.ts")?.relativePath,
454
+ fileCount: options.files.length,
455
+ dependencyCount: options.dependencyMap.edges.length,
456
+ externalPackageCount: options.dependencyMap.externalPackages.length,
457
+ branch: options.gitContext.branch,
458
+ modules: [...modules].sort()
459
+ };
460
+ }
461
+ buildRepositoryMemory(options) {
462
+ const repo = this.buildRepositorySummary(options);
463
+ return [{
464
+ id: repo.name,
465
+ type: "repository",
466
+ title: repo.name,
467
+ content: `
468
+ Repository:
469
+ ${repo.name}
470
+
471
+ Language:
472
+ ${repo.language}
473
+
474
+ Entry Point:
475
+ ${repo.entryPoint ?? "Unknown"}
476
+
477
+ Files:
478
+ ${repo.fileCount}
479
+
480
+ Dependencies:
481
+ ${repo.dependencyCount}
482
+
483
+ External Packages:
484
+ ${repo.externalPackageCount}
485
+
486
+ Branch:
487
+ ${repo.branch ?? "Unknown"}
488
+
489
+ Modules:
490
+ ${repo.modules.join("\n")}
491
+ `.trim(),
492
+ metadata: repo,
493
+ tags: [
494
+ "repository"
495
+ ],
496
+ relationships: [
497
+ "git-context",
498
+ repo.entryPoint ?? "",
499
+ "package.json",
500
+ "README.md",
501
+ "timeline",
502
+ "statistics"
503
+ ].filter(Boolean)
504
+ }];
505
+ }
506
+ async buildReleaseSummaries(projectRoot, gitContext) {
507
+ if (!gitContext.isGitRepo) {
508
+ return [];
509
+ }
510
+ const git = (0, simple_git_1.default)(projectRoot);
511
+ const output = await git.raw([
512
+ "for-each-ref",
513
+ "--sort=-creatordate",
514
+ "--format=%(refname:short)|%(objectname)|%(creatordate:iso8601)|%(subject)",
515
+ "refs/tags"
516
+ ]);
517
+ if (!output.trim()) {
518
+ return [];
519
+ }
520
+ return output
521
+ .trim()
522
+ .split("\n")
523
+ .map(line => {
524
+ const [tag, commit, date, message] = line.split("|");
525
+ return {
526
+ tag,
527
+ commit,
528
+ date,
529
+ message
530
+ };
531
+ });
532
+ }
533
+ async buildReleaseMemories(projectRoot, gitContext) {
534
+ const releases = await this.buildReleaseSummaries(projectRoot, gitContext);
535
+ return releases.map(release => ({
536
+ id: `release:${release.tag}`,
537
+ type: "release",
538
+ title: release.tag,
539
+ content: `
540
+ Release:
541
+ ${release.tag}
542
+
543
+ Commit:
544
+ ${release.commit}
545
+
546
+ Date:
547
+ ${release.date}
548
+
549
+ Message:
550
+ ${release.message}
551
+ `.trim(),
552
+ metadata: release,
553
+ tags: [
554
+ "release"
555
+ ],
556
+ relationships: [
557
+ "repository",
558
+ release.commit
559
+ ]
560
+ }));
561
+ }
562
+ async buildRepositoryStats(projectRoot, files, dependencyMap, gaps, gitContext) {
563
+ const releases = await this.buildReleaseSummaries(projectRoot, gitContext);
564
+ return {
565
+ files: files.length,
566
+ commits: 1 + gitContext.recentCommits.length,
567
+ releases: releases.length,
568
+ dependencies: dependencyMap.edges.length,
569
+ externalPackages: dependencyMap.externalPackages.length,
570
+ architectureModules: new Set(dependencyMap.edges.map(e => e.from)).size,
571
+ gaps: {
572
+ high: gaps.filter(g => g.severity === "high").length,
573
+ medium: gaps.filter(g => g.severity === "medium").length,
574
+ low: gaps.filter(g => g.severity === "low").length,
575
+ }
576
+ };
577
+ }
578
+ async buildRepositoryStatisticsMemory(projectRoot, files, dependencyMap, gaps, gitContext) {
579
+ const stats = await this.buildRepositoryStats(projectRoot, files, dependencyMap, gaps, gitContext);
580
+ return [{
581
+ id: "statistics",
582
+ type: "repository",
583
+ title: "Repository Statistics",
584
+ content: `
585
+ Repository Statistics
586
+
587
+ Files:
588
+ ${stats.files}
589
+
590
+ Commits:
591
+ ${stats.commits}
592
+
593
+ Releases:
594
+ ${stats.releases}
595
+
596
+ Dependencies:
597
+ ${stats.dependencies}
598
+
599
+ External Packages:
600
+ ${stats.externalPackages}
601
+
602
+ Architecture Modules:
603
+ ${stats.architectureModules}
604
+
605
+ High Severity Gaps:
606
+ ${stats.gaps.high}
607
+
608
+ Medium Severity Gaps:
609
+ ${stats.gaps.medium}
610
+
611
+ Low Severity Gaps:
612
+ ${stats.gaps.low}
613
+ `.trim(),
614
+ metadata: stats,
615
+ tags: [
616
+ "repository",
617
+ "statistics"
618
+ ],
619
+ relationships: []
620
+ }];
621
+ }
622
+ async buildTimelineEvents(projectRoot, gitContext) {
623
+ if (!gitContext.isGitRepo) {
624
+ return [];
625
+ }
626
+ const releases = await this.buildReleaseSummaries(projectRoot, gitContext);
627
+ const events = [];
628
+ for (const commit of gitContext.recentCommits) {
629
+ events.push({
630
+ date: commit.date,
631
+ type: "commit",
632
+ title: commit.message,
633
+ description: commit.message,
634
+ relatedId: commit.hash
635
+ });
636
+ }
637
+ if (gitContext.lastCommit) {
638
+ events.push({
639
+ date: gitContext.lastCommit.date,
640
+ type: "commit",
641
+ title: gitContext.lastCommit.message,
642
+ description: gitContext.lastCommit.message,
643
+ relatedId: gitContext.lastCommit.hash
644
+ });
645
+ }
646
+ for (const release of releases) {
647
+ events.push({
648
+ date: release.date,
649
+ type: "release",
650
+ title: release.tag,
651
+ description: release.message,
652
+ relatedId: release.tag
653
+ });
654
+ }
655
+ return events.sort((a, b) => new Date(b.date).getTime() -
656
+ new Date(a.date).getTime());
657
+ }
658
+ async buildTimelineMemories(projectRoot, gitContext) {
659
+ const events = await this.buildTimelineEvents(projectRoot, gitContext);
660
+ if (events.length === 0) {
661
+ return [];
662
+ }
663
+ return [{
664
+ id: "timeline",
665
+ type: "timeline",
666
+ title: "Project Timeline",
667
+ content: `
668
+ Project Timeline
669
+
670
+ ${events.map(event => `
671
+ ${event.date}
672
+
673
+ ${event.type.toUpperCase()}
674
+
675
+ ${event.title}
676
+
677
+ ${event.description}
678
+ `).join("\n")}
679
+ `.trim(),
680
+ metadata: {
681
+ eventCount: events.length
682
+ },
683
+ tags: [
684
+ "timeline"
685
+ ],
686
+ relationships: [
687
+ "repository",
688
+ ...events.map(e => e.relatedId)
689
+ ]
690
+ }];
691
+ }
692
+ buildIssueMemories(gitContext) {
693
+ return gitContext.issues.map(issue => ({
694
+ id: `issue:${issue.number}`,
695
+ type: "issue",
696
+ title: `#${issue.number} ${issue.title}`,
697
+ content: `
698
+ Issue:
699
+ #${issue.number}
700
+
701
+ Title:
702
+ ${issue.title}
703
+
704
+ State:
705
+ ${issue.state}
706
+
707
+ Author:
708
+ ${issue.author}
709
+
710
+ Labels:
711
+ ${issue.labels.join(", ") || "None"}
712
+
713
+ Created:
714
+ ${issue.createdAt}
715
+
716
+ Updated:
717
+ ${issue.updatedAt}
718
+
719
+ GitHub:
720
+ ${issue.url}
721
+ `.trim(),
722
+ metadata: issue,
723
+ tags: [
724
+ "github",
725
+ "issue",
726
+ issue.state,
727
+ ...issue.labels
728
+ ],
729
+ relationships: [
730
+ "repository",
731
+ ...gitContext.pullRequests
732
+ .filter(pr => pr.issues.includes(issue.number))
733
+ .map(pr => `pr:${pr.number}`)
734
+ ]
735
+ }));
736
+ }
737
+ buildPullRequestMemories(gitContext) {
738
+ return gitContext.pullRequests.map(pr => ({
739
+ id: `pr:${pr.number}`,
740
+ type: "pull-request",
741
+ title: `PR #${pr.number} ${pr.title}`,
742
+ content: `
743
+ Pull Request:
744
+ #${pr.number}
745
+
746
+ Title:
747
+ ${pr.title}
748
+
749
+ State:
750
+ ${pr.state}
751
+
752
+ Merged:
753
+ ${pr.merged}
754
+
755
+ Commits:
756
+ ${pr.commits.length > 0
757
+ ? pr.commits.join("\n")
758
+ : "None"}
759
+
760
+ Changed Files:
761
+ ${pr.changedFiles.length > 0
762
+ ? pr.changedFiles.join("\n")
763
+ : "None"}
764
+
765
+ Author:
766
+ ${pr.author}
767
+
768
+ Base:
769
+ ${pr.baseBranch}
770
+
771
+ Head:
772
+ ${pr.headBranch}
773
+
774
+ Created:
775
+ ${pr.createdAt}
776
+
777
+ Updated:
778
+ ${pr.updatedAt}
779
+
780
+ GitHub:
781
+ ${pr.url}
782
+ `.trim(),
783
+ metadata: pr,
784
+ tags: [
785
+ "github",
786
+ "pull-request",
787
+ pr.state,
788
+ ...(pr.merged ? ["merged"] : [])
789
+ ],
790
+ relationships: [
791
+ "repository",
792
+ `branch:${pr.headBranch}`,
793
+ `branch:${pr.baseBranch}`,
794
+ ...pr.commits.map(c => `commit:${c}`),
795
+ ...pr.issues.map(i => `issue:${i}`),
796
+ ...pr.changedFiles.map(file => `file:${file}`)
797
+ ]
798
+ }));
799
+ }
800
+ async build(options) {
801
+ const memories = [];
802
+ memories.push(...this.buildGitMemory(options.projectName, options.gitContext));
803
+ memories.push(...this.buildFileMemories(options.files, options.dependencyMap, options.semanticLabels, options.gitContext));
804
+ memories.push(...this.buildDependencyMemories(options.dependencyMap));
805
+ memories.push(...this.buildExternalPackageMemories(options.dependencyMap));
806
+ memories.push(...await this.buildCommitMemories(options.projectRoot, options.gitContext));
807
+ memories.push(...this.buildGapMemories(options.gaps));
808
+ memories.push(...this.buildArchitectureMemories(options.dependencyMap));
809
+ memories.push(...this.buildResponsibilityMemories(options.files));
810
+ memories.push(...this.buildRepositoryMemory(options));
811
+ memories.push(...await this.buildRepositoryStatisticsMemory(options.projectRoot, options.files, options.dependencyMap, options.gaps, options.gitContext));
812
+ memories.push(...await this.buildReleaseMemories(options.projectRoot, options.gitContext));
813
+ memories.push(...await this.buildTimelineMemories(options.projectRoot, options.gitContext));
814
+ memories.push(...this.buildIssueMemories(options.gitContext));
815
+ memories.push(...this.buildPullRequestMemories(options.gitContext));
816
+ const deduplicator = new memoryDeduplicator_1.MemoryDeduplicator();
817
+ return deduplicator.deduplicate(memories);
818
+ }
819
+ }
820
+ exports.MemoryBuilder = MemoryBuilder;
821
+ //# sourceMappingURL=memoryBuilder.js.map