@kentwynn/kgraph 0.1.22 → 0.1.24
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/README.md +38 -2
- package/dist/cli/commands/doctor.js +4 -0
- package/dist/cli/commands/init.js +11 -3
- package/dist/cli/commands/integrate.js +32 -5
- package/dist/cli/commands/session.d.ts +4 -0
- package/dist/cli/commands/session.js +112 -0
- package/dist/cli/commands/workflow.js +5 -0
- package/dist/cli/help.d.ts +6 -0
- package/dist/cli/help.js +15 -1
- package/dist/cli/index.js +2 -0
- package/dist/cognition/cognition-quality.d.ts +4 -0
- package/dist/cognition/cognition-quality.js +14 -0
- package/dist/config/config.js +6 -0
- package/dist/integrations/adapters/claude-code.js +59 -25
- package/dist/integrations/adapters/cline.js +3 -5
- package/dist/integrations/adapters/codex.js +9 -26
- package/dist/integrations/adapters/copilot.js +17 -43
- package/dist/integrations/adapters/cursor.js +3 -5
- package/dist/integrations/adapters/gemini.js +3 -5
- package/dist/integrations/adapters/windsurf.js +3 -5
- package/dist/integrations/instruction-blocks.d.ts +6 -0
- package/dist/integrations/instruction-blocks.js +45 -0
- package/dist/integrations/integration-store.d.ts +4 -2
- package/dist/integrations/integration-store.js +19 -5
- package/dist/scanner/repo-scanner.js +2 -0
- package/dist/session/session-store.d.ts +15 -0
- package/dist/session/session-store.js +170 -0
- package/dist/session/token-estimator.d.ts +1 -0
- package/dist/session/token-estimator.js +17 -0
- package/dist/storage/kgraph-paths.js +4 -2
- package/dist/types/config.d.ts +3 -0
- package/dist/types/maps.d.ts +1 -0
- package/dist/types/session.d.ts +51 -0
- package/dist/types/session.js +1 -0
- package/dist/visualization/graph-builder.d.ts +1 -0
- package/dist/visualization/graph-builder.js +14 -1
- package/dist/visualization/html-template.js +19 -2
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IntegrationName } from './config.js';
|
|
2
|
+
export type SessionAgent = IntegrationName;
|
|
3
|
+
export type SessionEventType = 'start' | 'read' | 'write' | 'end';
|
|
4
|
+
export type SessionCaptureSource = 'automatic' | 'agent-reported' | 'manual';
|
|
5
|
+
export interface SessionEvent {
|
|
6
|
+
id: string;
|
|
7
|
+
agent: SessionAgent;
|
|
8
|
+
type: SessionEventType;
|
|
9
|
+
path?: string;
|
|
10
|
+
tokenEstimate?: number;
|
|
11
|
+
repeated?: boolean;
|
|
12
|
+
captureSource: SessionCaptureSource;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentSession {
|
|
16
|
+
agent: SessionAgent;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
startedAt: string;
|
|
19
|
+
lastEventAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SessionState {
|
|
22
|
+
active: Record<string, AgentSession>;
|
|
23
|
+
events: SessionEvent[];
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionLedgerEntry {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
agent: SessionAgent;
|
|
29
|
+
startedAt: string;
|
|
30
|
+
endedAt: string;
|
|
31
|
+
readCount: number;
|
|
32
|
+
writeCount: number;
|
|
33
|
+
repeatedReadCount: number;
|
|
34
|
+
estimatedReadTokens: number;
|
|
35
|
+
estimatedRepeatedReadTokens: number;
|
|
36
|
+
}
|
|
37
|
+
export interface SessionReport {
|
|
38
|
+
activeAgents: AgentSession[];
|
|
39
|
+
readCount: number;
|
|
40
|
+
writeCount: number;
|
|
41
|
+
repeatedReadCount: number;
|
|
42
|
+
estimatedReadTokens: number;
|
|
43
|
+
estimatedRepeatedReadTokens: number;
|
|
44
|
+
topRepeatedReads: Array<{
|
|
45
|
+
path: string;
|
|
46
|
+
count: number;
|
|
47
|
+
estimatedTokens: number;
|
|
48
|
+
}>;
|
|
49
|
+
recentEvents: SessionEvent[];
|
|
50
|
+
ledger: SessionLedgerEntry[];
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -24,7 +24,9 @@ export function buildGraph(fileMap, symbolMap, dependencyMap, relationshipMap, c
|
|
|
24
24
|
const elements = [];
|
|
25
25
|
const edgeIds = new Set();
|
|
26
26
|
const nodeIds = new Set();
|
|
27
|
+
const tokenEstimate = fileMap.files.reduce((total, file) => total + (file.tokenEstimate ?? 0), 0);
|
|
27
28
|
for (const file of fileMap.files) {
|
|
29
|
+
const tokenBucket = getTokenBucket(file.tokenEstimate);
|
|
28
30
|
nodeIds.add(file.id);
|
|
29
31
|
elements.push({
|
|
30
32
|
data: {
|
|
@@ -35,9 +37,11 @@ export function buildGraph(fileMap, symbolMap, dependencyMap, relationshipMap, c
|
|
|
35
37
|
color: LANGUAGE_COLORS[file.language] ?? '#94a3b8',
|
|
36
38
|
type: 'file',
|
|
37
39
|
size: file.sizeBytes,
|
|
40
|
+
tokenEstimate: file.tokenEstimate ?? 0,
|
|
41
|
+
tokenBucket,
|
|
38
42
|
scanStatus: file.scanStatus,
|
|
39
43
|
},
|
|
40
|
-
classes: `file ${file.language}`,
|
|
44
|
+
classes: `file ${file.language} token-${tokenBucket}`,
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
for (const symbol of symbolMap.symbols) {
|
|
@@ -139,7 +143,16 @@ export function buildGraph(fileMap, symbolMap, dependencyMap, relationshipMap, c
|
|
|
139
143
|
fileCount: fileMap.files.length,
|
|
140
144
|
symbolCount: symbolMap.symbols.length,
|
|
141
145
|
cognitionCount: cognitionNotes.length,
|
|
146
|
+
tokenEstimate,
|
|
142
147
|
generatedAt: new Date().toISOString(),
|
|
143
148
|
},
|
|
144
149
|
};
|
|
145
150
|
}
|
|
151
|
+
function getTokenBucket(tokenEstimate) {
|
|
152
|
+
const tokens = tokenEstimate ?? 0;
|
|
153
|
+
if (tokens >= 1000)
|
|
154
|
+
return 'large';
|
|
155
|
+
if (tokens >= 200)
|
|
156
|
+
return 'medium';
|
|
157
|
+
return 'small';
|
|
158
|
+
}
|
|
@@ -51,7 +51,7 @@ select:hover,button:hover{background:#475569}
|
|
|
51
51
|
<body>
|
|
52
52
|
<div id="toolbar">
|
|
53
53
|
<span id="t-title">\u29e1 KGraph \u00b7 ${repoName}</span>
|
|
54
|
-
<span id="t-stats">${meta.fileCount} files · ${meta.symbolCount} symbols · ${meta.cognitionCount} notes</span>
|
|
54
|
+
<span id="t-stats">${meta.fileCount} files · ${meta.symbolCount} symbols · ${meta.cognitionCount} notes · ~${meta.tokenEstimate} tokens</span>
|
|
55
55
|
<div id="t-controls">
|
|
56
56
|
<label class="clabel"><input type="checkbox" id="tog-cog" checked> Cognition</label>
|
|
57
57
|
<select id="sel-layout" title="Graph layout algorithm">
|
|
@@ -81,6 +81,8 @@ select:hover,button:hover{background:#475569}
|
|
|
81
81
|
<span class="li"><span class="li-dot" style="background:#10b981"></span>Markdown</span>
|
|
82
82
|
<span class="li"><span class="li-dot" style="background:#8b5cf6"></span>YAML</span>
|
|
83
83
|
<span class="li"><span class="li-dot" style="background:#94a3b8"></span>Other</span>
|
|
84
|
+
<span class="li"><span class="li-dot" style="background:#475569"></span>200+ tok</span>
|
|
85
|
+
<span class="li"><span class="li-dot" style="background:#ef4444"></span>1000+ tok</span>
|
|
84
86
|
<span class="li-sep"></span>
|
|
85
87
|
<span class="li-head">Cognition</span>
|
|
86
88
|
<span class="li"><span class="li-dia" style="background:#10b981"></span>Current</span>
|
|
@@ -162,6 +164,20 @@ select:hover,button:hover{background:#475569}
|
|
|
162
164
|
'overlay-color': '#7dd3fc'
|
|
163
165
|
}
|
|
164
166
|
},
|
|
167
|
+
{
|
|
168
|
+
selector: 'node.token-medium',
|
|
169
|
+
style: {
|
|
170
|
+
'border-color': '#f59e0b',
|
|
171
|
+
'border-width': 2
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
selector: 'node.token-large',
|
|
176
|
+
style: {
|
|
177
|
+
'border-color': '#ef4444',
|
|
178
|
+
'border-width': 3
|
|
179
|
+
}
|
|
180
|
+
},
|
|
165
181
|
{
|
|
166
182
|
selector: 'edge.import',
|
|
167
183
|
style: {
|
|
@@ -217,7 +233,8 @@ select:hover,button:hover{background:#475569}
|
|
|
217
233
|
return '<div class="sb-badge" style="background:' + esc(d.color) + '22;color:' + esc(d.color) + ';border:1px solid ' + esc(d.color) + '44">' + esc(d.language) + '</div>' +
|
|
218
234
|
'<div class="sb-title">' + esc(d.path) + '</div>' +
|
|
219
235
|
'<div class="sb-sect"><div class="sb-lbl">Scan Status</div><div class="sb-val">' + esc(d.scanStatus) + '</div></div>' +
|
|
220
|
-
'<div class="sb-sect"><div class="sb-lbl">File Size</div><div class="sb-val">' + bytes(d.size) + '</div></div>'
|
|
236
|
+
'<div class="sb-sect"><div class="sb-lbl">File Size</div><div class="sb-val">' + bytes(d.size) + '</div></div>' +
|
|
237
|
+
'<div class="sb-sect"><div class="sb-lbl">Estimated Tokens</div><div class="sb-val">~' + esc(d.tokenEstimate || 0) + ' tokens</div></div>';
|
|
221
238
|
}
|
|
222
239
|
|
|
223
240
|
function renderCognitionPanel(d) {
|