@imayuur/contexthub-knowledge-graph 1.0.0 → 1.0.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.
- package/dist/deepsync-report.d.ts +30 -0
- package/dist/deepsync-report.js +211 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/package.json +4 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface DeepSyncReportOptions {
|
|
2
|
+
repoPath: string;
|
|
3
|
+
filesAnalyzed: number;
|
|
4
|
+
symbolCount: number;
|
|
5
|
+
nodeCount: number;
|
|
6
|
+
edgeCount: number;
|
|
7
|
+
docsIngested: number;
|
|
8
|
+
commitsAnalyzed: number;
|
|
9
|
+
memoryCount: number;
|
|
10
|
+
gitBranch?: string;
|
|
11
|
+
languageBreakdown?: Record<string, number>;
|
|
12
|
+
docFiles?: Array<{
|
|
13
|
+
path: string;
|
|
14
|
+
sizeKB: number;
|
|
15
|
+
}>;
|
|
16
|
+
hotFiles?: Array<{
|
|
17
|
+
path: string;
|
|
18
|
+
changes: number;
|
|
19
|
+
}>;
|
|
20
|
+
recentFocusAreas?: string[];
|
|
21
|
+
durationMs: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate a DEEPSYNC.md report summarising the deep sync results.
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateDeepSyncReport(options: DeepSyncReportOptions): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Write the DeepSync report to .contexthub/DEEPSYNC.md
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeDeepSyncReport(options: DeepSyncReportOptions): Promise<string>;
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateDeepSyncReport = generateDeepSyncReport;
|
|
37
|
+
exports.writeDeepSyncReport = writeDeepSyncReport;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const crypto = __importStar(require("crypto"));
|
|
41
|
+
const index_1 = require("./index");
|
|
42
|
+
/**
|
|
43
|
+
* Generate a DEEPSYNC.md report summarising the deep sync results.
|
|
44
|
+
*/
|
|
45
|
+
async function generateDeepSyncReport(options) {
|
|
46
|
+
const graphManager = new index_1.CodeGraphManager(options.repoPath);
|
|
47
|
+
const projectName = path.basename(options.repoPath);
|
|
48
|
+
const syncedAt = new Date().toISOString();
|
|
49
|
+
// Language breakdown table
|
|
50
|
+
let langTable = '| Language | Files |\n|----------|-------|\n';
|
|
51
|
+
if (options.languageBreakdown) {
|
|
52
|
+
const sorted = Object.entries(options.languageBreakdown).sort((a, b) => b[1] - a[1]);
|
|
53
|
+
const total = sorted.reduce((s, [, c]) => s + c, 0);
|
|
54
|
+
for (const [lang, count] of sorted) {
|
|
55
|
+
const pct = total > 0 ? ((count / total) * 100).toFixed(0) : '0';
|
|
56
|
+
langTable += `| ${lang} | ${count} (${pct}%) |\n`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
langTable += '| — | No data |\n';
|
|
61
|
+
}
|
|
62
|
+
// God-nodes section
|
|
63
|
+
let godNodesSection = '';
|
|
64
|
+
try {
|
|
65
|
+
const godNodes = await graphManager.getGodNodes(10);
|
|
66
|
+
if (godNodes.length > 0) {
|
|
67
|
+
const rows = godNodes
|
|
68
|
+
.map((gn, i) => `| ${i + 1} | \`${gn.path}\` | ${gn.degree} | ${gn.inDegree} | ${gn.outDegree} |`)
|
|
69
|
+
.join('\n');
|
|
70
|
+
godNodesSection = `### 🔗 God-Nodes (Most Connected Files)
|
|
71
|
+
|
|
72
|
+
| Rank | File | Degree | In | Out |
|
|
73
|
+
|------|------|--------|----|-----|
|
|
74
|
+
${rows}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch { }
|
|
79
|
+
// Communities section
|
|
80
|
+
let communitiesSection = '';
|
|
81
|
+
try {
|
|
82
|
+
const communities = await graphManager.detectCommunities();
|
|
83
|
+
if (communities.length > 0) {
|
|
84
|
+
const topCommunities = communities.slice(0, 8);
|
|
85
|
+
const rows = topCommunities
|
|
86
|
+
.map((c) => {
|
|
87
|
+
const preview = c.files
|
|
88
|
+
.slice(0, 4)
|
|
89
|
+
.map((f) => `\`${f}\``)
|
|
90
|
+
.join(', ');
|
|
91
|
+
const more = c.size > 4 ? ` +${c.size - 4} more` : '';
|
|
92
|
+
return `| ${c.id} | ${c.size} | ${preview}${more} |`;
|
|
93
|
+
})
|
|
94
|
+
.join('\n');
|
|
95
|
+
communitiesSection = `### 🏘️ Code Communities
|
|
96
|
+
|
|
97
|
+
Total: **${communities.length}** communities across **${communities.reduce((s, c) => s + c.size, 0)}** files.
|
|
98
|
+
|
|
99
|
+
| ID | Size | Files |
|
|
100
|
+
|----|------|-------|
|
|
101
|
+
${rows}
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch { }
|
|
106
|
+
// Documentation index
|
|
107
|
+
let docsSection = '';
|
|
108
|
+
if (options.docFiles && options.docFiles.length > 0) {
|
|
109
|
+
const rows = options.docFiles
|
|
110
|
+
.slice(0, 20)
|
|
111
|
+
.map((d) => `| \`${d.path}\` | ${d.sizeKB.toFixed(1)} KB |`)
|
|
112
|
+
.join('\n');
|
|
113
|
+
docsSection = `### 📄 Documentation Index
|
|
114
|
+
|
|
115
|
+
| File | Size |
|
|
116
|
+
|------|------|
|
|
117
|
+
${rows}
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
// Git intelligence
|
|
121
|
+
let gitSection = '';
|
|
122
|
+
if (options.gitBranch || (options.hotFiles && options.hotFiles.length > 0)) {
|
|
123
|
+
gitSection = `### 🔀 Git Intelligence
|
|
124
|
+
|
|
125
|
+
`;
|
|
126
|
+
if (options.gitBranch) {
|
|
127
|
+
gitSection += `- **Active Branch:** \`${options.gitBranch}\`\n`;
|
|
128
|
+
}
|
|
129
|
+
gitSection += `- **Commits Analyzed:** ${options.commitsAnalyzed}\n`;
|
|
130
|
+
if (options.hotFiles && options.hotFiles.length > 0) {
|
|
131
|
+
gitSection += `\n**Hot Files** (most changed recently):\n`;
|
|
132
|
+
for (const hf of options.hotFiles.slice(0, 10)) {
|
|
133
|
+
gitSection += `- \`${hf.path}\` — ${hf.changes} changes\n`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (options.recentFocusAreas && options.recentFocusAreas.length > 0) {
|
|
137
|
+
gitSection += `\n**Recent Focus Areas:** ${options.recentFocusAreas.join(', ')}\n`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const durationSec = (options.durationMs / 1000).toFixed(1);
|
|
141
|
+
const report = `# 🧠 DeepSync Report — ${projectName}
|
|
142
|
+
|
|
143
|
+
> Auto-generated by ContextHub DeepSync. Do not edit manually.
|
|
144
|
+
> Last synced: ${syncedAt} | Duration: ${durationSec}s
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 📊 Overview
|
|
149
|
+
|
|
150
|
+
| Metric | Count |
|
|
151
|
+
|--------|-------|
|
|
152
|
+
| Files Analyzed | ${options.filesAnalyzed} |
|
|
153
|
+
| Symbols Indexed | ${options.symbolCount} |
|
|
154
|
+
| Graph Nodes | ${options.nodeCount} |
|
|
155
|
+
| Graph Edges | ${options.edgeCount} |
|
|
156
|
+
| Docs Ingested | ${options.docsIngested} |
|
|
157
|
+
| Commits Analyzed | ${options.commitsAnalyzed} |
|
|
158
|
+
| Total Memories | ${options.memoryCount} |
|
|
159
|
+
|
|
160
|
+
## 🗂️ Languages
|
|
161
|
+
|
|
162
|
+
${langTable}
|
|
163
|
+
|
|
164
|
+
## 🏗️ Architecture
|
|
165
|
+
|
|
166
|
+
${godNodesSection || '> No high-connectivity files detected.\n'}
|
|
167
|
+
${communitiesSection || '> No communities detected.\n'}
|
|
168
|
+
|
|
169
|
+
${docsSection}
|
|
170
|
+
|
|
171
|
+
${gitSection}
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 🔄 Auto-Sync
|
|
176
|
+
|
|
177
|
+
DeepSync auto-updates the knowledge graph on every \`ensure_session\` call.
|
|
178
|
+
Changed files are detected via git and incrementally patched — no manual re-scan needed.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
*Generated by [ContextHub DeepSync](https://github.com/iMayuuR/contexthub) — One scan. Total recall. Forever in context.*
|
|
183
|
+
`;
|
|
184
|
+
return report;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Write the DeepSync report to .contexthub/DEEPSYNC.md
|
|
188
|
+
*/
|
|
189
|
+
async function writeDeepSyncReport(options) {
|
|
190
|
+
const report = await generateDeepSyncReport(options);
|
|
191
|
+
const outputPath = path.join(options.repoPath, '.contexthub', 'DEEPSYNC.md');
|
|
192
|
+
// Ensure .contexthub exists
|
|
193
|
+
const dir = path.dirname(outputPath);
|
|
194
|
+
if (!fs.existsSync(dir)) {
|
|
195
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
196
|
+
}
|
|
197
|
+
// Atomic write
|
|
198
|
+
const tmpPath = outputPath + `.tmp.${crypto.randomBytes(4).toString('hex')}`;
|
|
199
|
+
try {
|
|
200
|
+
fs.writeFileSync(tmpPath, report, { mode: 0o600 });
|
|
201
|
+
fs.renameSync(tmpPath, outputPath);
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
try {
|
|
205
|
+
fs.unlinkSync(tmpPath);
|
|
206
|
+
}
|
|
207
|
+
catch { }
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
return outputPath;
|
|
211
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -89,3 +89,5 @@ export declare class CodeGraphManager {
|
|
|
89
89
|
}
|
|
90
90
|
export { generateGraphReport, writeGraphReport } from './report';
|
|
91
91
|
export type { GraphReportOptions } from './report';
|
|
92
|
+
export { generateDeepSyncReport, writeDeepSyncReport } from './deepsync-report';
|
|
93
|
+
export type { DeepSyncReportOptions } from './deepsync-report';
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.writeGraphReport = exports.generateGraphReport = exports.CodeGraphManager = void 0;
|
|
36
|
+
exports.writeDeepSyncReport = exports.generateDeepSyncReport = exports.writeGraphReport = exports.generateGraphReport = exports.CodeGraphManager = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const crypto = __importStar(require("crypto"));
|
|
@@ -750,3 +750,7 @@ exports.CodeGraphManager = CodeGraphManager;
|
|
|
750
750
|
var report_1 = require("./report");
|
|
751
751
|
Object.defineProperty(exports, "generateGraphReport", { enumerable: true, get: function () { return report_1.generateGraphReport; } });
|
|
752
752
|
Object.defineProperty(exports, "writeGraphReport", { enumerable: true, get: function () { return report_1.writeGraphReport; } });
|
|
753
|
+
// Re-export DeepSync report utilities
|
|
754
|
+
var deepsync_report_1 = require("./deepsync-report");
|
|
755
|
+
Object.defineProperty(exports, "generateDeepSyncReport", { enumerable: true, get: function () { return deepsync_report_1.generateDeepSyncReport; } });
|
|
756
|
+
Object.defineProperty(exports, "writeDeepSyncReport", { enumerable: true, get: function () { return deepsync_report_1.writeDeepSyncReport; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imayuur/contexthub-knowledge-graph",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Code knowledge graph builder and query engine for ContextHub",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@imayuur/contexthub-shared-types": "^1.0.
|
|
31
|
-
"@imayuur/contexthub-core": "^1.0.
|
|
32
|
-
"@imayuur/contexthub-repo-parser": "^1.0.
|
|
30
|
+
"@imayuur/contexthub-shared-types": "^1.0.1",
|
|
31
|
+
"@imayuur/contexthub-core": "^1.0.1",
|
|
32
|
+
"@imayuur/contexthub-repo-parser": "^1.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^18.0.0",
|