@kentwynn/kgraph 0.1.21 → 0.1.23
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 +56 -3
- package/dist/cli/commands/doctor.js +8 -0
- package/dist/cli/commands/history.d.ts +3 -1
- package/dist/cli/commands/history.js +22 -7
- package/dist/cli/commands/impact.d.ts +4 -0
- package/dist/cli/commands/impact.js +51 -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 +17 -2
- package/dist/cli/index.js +4 -0
- package/dist/cognition/cognition-quality.d.ts +13 -1
- package/dist/cognition/cognition-quality.js +60 -0
- package/dist/config/config.js +6 -0
- package/dist/context/context-query.js +1 -0
- package/dist/context/impact.d.ts +20 -0
- package/dist/context/impact.js +72 -0
- package/dist/context/ranking.js +21 -6
- package/dist/integrations/adapters/claude-code.js +68 -10
- package/dist/integrations/adapters/cline.js +8 -6
- package/dist/integrations/adapters/codex.js +12 -10
- package/dist/integrations/adapters/copilot.js +35 -10
- package/dist/integrations/adapters/cursor.js +8 -6
- package/dist/integrations/adapters/gemini.js +8 -6
- package/dist/integrations/adapters/windsurf.js +8 -6
- package/dist/integrations/instruction-blocks.d.ts +4 -0
- package/dist/integrations/instruction-blocks.js +17 -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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { overwriteDomainRecord, readCognitionNotes, readDomainRecords, writeCognitionNote, } from '../storage/cognition-store.js';
|
|
2
|
+
import { buildSessionReport } from '../session/session-store.js';
|
|
2
3
|
export async function analyzeCognitionQuality(workspace, maps) {
|
|
3
4
|
const notes = await readCognitionNotes(workspace);
|
|
5
|
+
const session = await buildSessionReport(workspace);
|
|
4
6
|
const changes = notes
|
|
5
7
|
.map((note) => analyzeNote(note, maps))
|
|
6
8
|
.filter((change) => change.removedFileRefs.length > 0 ||
|
|
@@ -10,11 +12,20 @@ export async function analyzeCognitionQuality(workspace, maps) {
|
|
|
10
12
|
mixedOrStaleCount: notes.filter((note) => ['mixed', 'stale', 'unresolved'].includes(note.referencesStatus)).length,
|
|
11
13
|
noisyFileRefCount: changes.reduce((total, change) => total + change.removedFileRefs.length, 0),
|
|
12
14
|
noisySymbolRefCount: changes.reduce((total, change) => total + change.removedSymbolRefs.length, 0),
|
|
15
|
+
unresolvedLocalImportCount: countUnresolvedLocalImports(maps.dependencyMap),
|
|
16
|
+
unresolvedCallCount: countUnresolvedCalls(maps.symbolMap, maps.relationshipMap),
|
|
17
|
+
duplicateTitleCount: countDuplicateTitles(notes),
|
|
18
|
+
generatedFileScanCount: countGeneratedScannedFiles(maps.fileMap),
|
|
19
|
+
expensiveFileCount: countExpensiveFiles(maps.fileMap),
|
|
20
|
+
sessionRepeatedReadCount: session.repeatedReadCount,
|
|
21
|
+
sessionEstimatedReadTokens: session.estimatedReadTokens,
|
|
22
|
+
sessionEstimatedRepeatedReadTokens: session.estimatedRepeatedReadTokens,
|
|
13
23
|
changes,
|
|
14
24
|
};
|
|
15
25
|
}
|
|
16
26
|
export async function repairCognition(workspace, maps, dryRun = false) {
|
|
17
27
|
const notes = await readCognitionNotes(workspace);
|
|
28
|
+
const session = await buildSessionReport(workspace);
|
|
18
29
|
const nextNotes = [];
|
|
19
30
|
const changes = [];
|
|
20
31
|
for (const note of notes) {
|
|
@@ -37,9 +48,58 @@ export async function repairCognition(workspace, maps, dryRun = false) {
|
|
|
37
48
|
mixedOrStaleCount: nextNotes.filter((note) => ['mixed', 'stale', 'unresolved'].includes(note.referencesStatus)).length,
|
|
38
49
|
noisyFileRefCount: changes.reduce((total, change) => total + change.removedFileRefs.length, 0),
|
|
39
50
|
noisySymbolRefCount: changes.reduce((total, change) => total + change.removedSymbolRefs.length, 0),
|
|
51
|
+
unresolvedLocalImportCount: countUnresolvedLocalImports(maps.dependencyMap),
|
|
52
|
+
unresolvedCallCount: countUnresolvedCalls(maps.symbolMap, maps.relationshipMap),
|
|
53
|
+
duplicateTitleCount: countDuplicateTitles(nextNotes),
|
|
54
|
+
generatedFileScanCount: countGeneratedScannedFiles(maps.fileMap),
|
|
55
|
+
expensiveFileCount: countExpensiveFiles(maps.fileMap),
|
|
56
|
+
sessionRepeatedReadCount: session.repeatedReadCount,
|
|
57
|
+
sessionEstimatedReadTokens: session.estimatedReadTokens,
|
|
58
|
+
sessionEstimatedRepeatedReadTokens: session.estimatedRepeatedReadTokens,
|
|
40
59
|
changes,
|
|
41
60
|
};
|
|
42
61
|
}
|
|
62
|
+
function countUnresolvedLocalImports(dependencyMap) {
|
|
63
|
+
return (dependencyMap?.dependencies.filter((dependency) => dependency.kind === 'local' && !dependency.resolvedFile).length ?? 0);
|
|
64
|
+
}
|
|
65
|
+
function countUnresolvedCalls(symbolMap, relationshipMap) {
|
|
66
|
+
const symbolIds = new Set(symbolMap.symbols.map((symbol) => symbol.id));
|
|
67
|
+
const symbolNames = new Set(symbolMap.symbols.map((symbol) => symbol.name));
|
|
68
|
+
return (relationshipMap?.relationships.filter((relationship) => relationship.relationshipType === 'calls' &&
|
|
69
|
+
relationship.targetType === 'symbol' &&
|
|
70
|
+
!symbolIds.has(relationship.targetId) &&
|
|
71
|
+
!symbolNames.has(relationship.targetId) &&
|
|
72
|
+
![...symbolNames].some((name) => relationship.targetId.endsWith(`#${name}`))).length ?? 0);
|
|
73
|
+
}
|
|
74
|
+
function countDuplicateTitles(notes) {
|
|
75
|
+
const seen = new Set();
|
|
76
|
+
const duplicates = new Set();
|
|
77
|
+
for (const note of notes) {
|
|
78
|
+
const key = note.title.trim().toLowerCase();
|
|
79
|
+
if (!key)
|
|
80
|
+
continue;
|
|
81
|
+
if (seen.has(key))
|
|
82
|
+
duplicates.add(key);
|
|
83
|
+
seen.add(key);
|
|
84
|
+
}
|
|
85
|
+
return duplicates.size;
|
|
86
|
+
}
|
|
87
|
+
function countGeneratedScannedFiles(fileMap) {
|
|
88
|
+
return fileMap.files.filter((file) => [
|
|
89
|
+
'.agents/',
|
|
90
|
+
'.claude/',
|
|
91
|
+
'.cursor/',
|
|
92
|
+
'.windsurf/',
|
|
93
|
+
'.clinerules/',
|
|
94
|
+
'.github/prompts/',
|
|
95
|
+
'AGENTS.md',
|
|
96
|
+
'CLAUDE.md',
|
|
97
|
+
'GEMINI.md',
|
|
98
|
+
].some((prefix) => file.path === prefix || file.path.startsWith(prefix))).length;
|
|
99
|
+
}
|
|
100
|
+
function countExpensiveFiles(fileMap) {
|
|
101
|
+
return fileMap.files.filter((file) => (file.tokenEstimate ?? 0) >= 1000).length;
|
|
102
|
+
}
|
|
43
103
|
function analyzeNote(note, maps) {
|
|
44
104
|
const filePaths = new Set(maps.fileMap.files.map((file) => file.path));
|
|
45
105
|
const symbolNames = new Set(maps.symbolMap.symbols.map((symbol) => symbol.name));
|
package/dist/config/config.js
CHANGED
|
@@ -150,8 +150,14 @@ function normalizeIntegrations(value) {
|
|
|
150
150
|
integrations.push({
|
|
151
151
|
name: candidate.name,
|
|
152
152
|
enabled: candidate.enabled !== false,
|
|
153
|
+
mode: normalizeIntegrationMode(candidate.mode),
|
|
153
154
|
targetPath: candidate.targetPath,
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
return integrations;
|
|
157
158
|
}
|
|
159
|
+
function normalizeIntegrationMode(value) {
|
|
160
|
+
return value === 'always' || value === 'manual' || value === 'off'
|
|
161
|
+
? value
|
|
162
|
+
: 'smart';
|
|
163
|
+
}
|
|
@@ -12,6 +12,7 @@ export async function queryContext(workspace, config, maps, query) {
|
|
|
12
12
|
{ name: 'name', value: (symbol) => symbol.name },
|
|
13
13
|
{ name: 'path', value: (symbol) => symbol.filePath },
|
|
14
14
|
{ name: 'kind', value: (symbol) => symbol.kind },
|
|
15
|
+
{ name: 'parent', value: (symbol) => symbol.parentName },
|
|
15
16
|
]).slice(0, max);
|
|
16
17
|
const relevantCognition = rankByFields(query, cognition, [
|
|
17
18
|
{ name: 'title', value: (note) => note.title },
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CognitionNote } from '../types/cognition.js';
|
|
2
|
+
import type { DependencyMap, FileMap, Relationship, RelationshipMap, SymbolMap } from '../types/maps.js';
|
|
3
|
+
import { type Ranked } from './ranking.js';
|
|
4
|
+
export interface ImpactResponse {
|
|
5
|
+
query: string;
|
|
6
|
+
files: Ranked<FileMap['files'][number]>[];
|
|
7
|
+
symbols: Ranked<SymbolMap['symbols'][number]>[];
|
|
8
|
+
importedBy: string[];
|
|
9
|
+
callers: Relationship[];
|
|
10
|
+
calls: Relationship[];
|
|
11
|
+
ownership: Relationship[];
|
|
12
|
+
relatedCognition: CognitionNote[];
|
|
13
|
+
risk: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare function analyzeImpact(query: string, maps: {
|
|
16
|
+
fileMap: FileMap;
|
|
17
|
+
symbolMap: SymbolMap;
|
|
18
|
+
dependencyMap: DependencyMap;
|
|
19
|
+
relationshipMap: RelationshipMap;
|
|
20
|
+
}, cognition: CognitionNote[], max?: number): ImpactResponse;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { rankByFields } from './ranking.js';
|
|
2
|
+
export function analyzeImpact(query, maps, cognition, max = 8) {
|
|
3
|
+
const files = rankByFields(query, maps.fileMap.files, [
|
|
4
|
+
{ name: 'path', value: (file) => file.path },
|
|
5
|
+
{ name: 'language', value: (file) => file.language },
|
|
6
|
+
]).slice(0, max);
|
|
7
|
+
const symbols = rankByFields(query, maps.symbolMap.symbols, [
|
|
8
|
+
{ name: 'name', value: (symbol) => symbol.name },
|
|
9
|
+
{ name: 'path', value: (symbol) => symbol.filePath },
|
|
10
|
+
{ name: 'kind', value: (symbol) => symbol.kind },
|
|
11
|
+
{ name: 'parent', value: (symbol) => symbol.parentName },
|
|
12
|
+
]).slice(0, max);
|
|
13
|
+
const filePaths = new Set([
|
|
14
|
+
...files.map((file) => file.item.path),
|
|
15
|
+
...symbols.map((symbol) => symbol.item.filePath),
|
|
16
|
+
]);
|
|
17
|
+
const symbolIds = new Set(symbols.map((symbol) => symbol.item.id));
|
|
18
|
+
const symbolNames = new Set(symbols.map((symbol) => symbol.item.name));
|
|
19
|
+
const importHints = new Set([
|
|
20
|
+
...[...filePaths].map((file) => basenameWithoutExtension(file).toLowerCase()),
|
|
21
|
+
...[...symbolNames].map((name) => name.toLowerCase()),
|
|
22
|
+
]);
|
|
23
|
+
const importedBy = unique(maps.dependencyMap.dependencies
|
|
24
|
+
.filter((dep) => (dep.resolvedFile && filePaths.has(dep.resolvedFile)) ||
|
|
25
|
+
[...importHints].some((hint) => hint && dep.specifier.toLowerCase().includes(hint)))
|
|
26
|
+
.map((dep) => dep.fromFile)).slice(0, max);
|
|
27
|
+
const calls = maps.relationshipMap.relationships
|
|
28
|
+
.filter((rel) => rel.relationshipType === 'calls' &&
|
|
29
|
+
(symbolIds.has(rel.sourceId) || symbolNames.has(rel.sourceId)))
|
|
30
|
+
.slice(0, max);
|
|
31
|
+
const callers = maps.relationshipMap.relationships
|
|
32
|
+
.filter((rel) => rel.relationshipType === 'calls' &&
|
|
33
|
+
(symbolIds.has(rel.targetId) || symbolNames.has(rel.targetId) || [...symbolNames].some((name) => rel.targetId.endsWith(`#${name}`))))
|
|
34
|
+
.slice(0, max);
|
|
35
|
+
const ownership = maps.relationshipMap.relationships
|
|
36
|
+
.filter((rel) => rel.relationshipType === 'symbol-contains' &&
|
|
37
|
+
(symbolIds.has(rel.sourceId) || symbolIds.has(rel.targetId)))
|
|
38
|
+
.slice(0, max);
|
|
39
|
+
const relatedCognition = cognition
|
|
40
|
+
.filter((note) => note.relatedFiles.some((file) => filePaths.has(file)) ||
|
|
41
|
+
note.relatedSymbols.some((symbol) => symbolNames.has(symbol) || symbolIds.has(symbol)))
|
|
42
|
+
.slice(0, max);
|
|
43
|
+
const risk = [];
|
|
44
|
+
if (importedBy.length > 2)
|
|
45
|
+
risk.push(`Shared file imported by ${importedBy.length} files`);
|
|
46
|
+
if (callers.length > 2)
|
|
47
|
+
risk.push(`Symbol called by ${callers.length} known callers`);
|
|
48
|
+
if (relatedCognition.some((note) => note.referencesStatus !== 'current')) {
|
|
49
|
+
risk.push('Related cognition has stale or mixed references');
|
|
50
|
+
}
|
|
51
|
+
if (calls.some((rel) => rel.confidence === 'low') || callers.some((rel) => rel.confidence === 'low')) {
|
|
52
|
+
risk.push('Some call relationships are low confidence');
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
query,
|
|
56
|
+
files,
|
|
57
|
+
symbols,
|
|
58
|
+
importedBy,
|
|
59
|
+
callers,
|
|
60
|
+
calls,
|
|
61
|
+
ownership,
|
|
62
|
+
relatedCognition,
|
|
63
|
+
risk,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function unique(items) {
|
|
67
|
+
return [...new Set(items)];
|
|
68
|
+
}
|
|
69
|
+
function basenameWithoutExtension(filePath) {
|
|
70
|
+
const basename = filePath.split('/').pop() ?? filePath;
|
|
71
|
+
return basename.replace(/\.[^.]+$/, '');
|
|
72
|
+
}
|
package/dist/context/ranking.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function tokenize(query) {
|
|
2
|
-
return query
|
|
2
|
+
return expandTokens(query
|
|
3
3
|
.toLowerCase()
|
|
4
4
|
.split(/[^a-z0-9_$./-]+/)
|
|
5
5
|
.map((token) => token.trim())
|
|
6
|
-
.filter(Boolean);
|
|
6
|
+
.filter(Boolean));
|
|
7
7
|
}
|
|
8
8
|
export function rankByFields(query, items, fields) {
|
|
9
9
|
const tokens = tokenize(query);
|
|
@@ -14,14 +14,19 @@ export function rankByFields(query, items, fields) {
|
|
|
14
14
|
for (const field of fields) {
|
|
15
15
|
const value = field.value(item);
|
|
16
16
|
const values = Array.isArray(value) ? value : value ? [value] : [];
|
|
17
|
-
const haystack = values.join(' ').toLowerCase();
|
|
17
|
+
const haystack = values.flatMap((value) => [value, splitIdentifier(value).join(' ')]).join(' ').toLowerCase();
|
|
18
18
|
for (const token of tokens) {
|
|
19
19
|
if (haystack.includes(token)) {
|
|
20
|
-
const baseScore = field.name === 'path' || field.name === 'name'
|
|
20
|
+
const baseScore = field.name === 'path' || field.name === 'name'
|
|
21
|
+
? 4
|
|
22
|
+
: field.name === 'summary' || field.name === 'title'
|
|
23
|
+
? 2
|
|
24
|
+
: 1;
|
|
21
25
|
const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
22
26
|
const wordBoundary = new RegExp(`\\b${escaped}\\b`).test(haystack);
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
const exactValue = values.some((value) => value.toLowerCase() === token);
|
|
28
|
+
score += baseScore + (wordBoundary ? 2 : 0) + (exactValue ? 4 : 0);
|
|
29
|
+
reasons.push(`${field.name} matched "${token}"${wordBoundary || exactValue ? ' (exact)' : ''}`);
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
}
|
|
@@ -30,3 +35,13 @@ export function rankByFields(query, items, fields) {
|
|
|
30
35
|
.filter((ranked) => ranked.score > 0)
|
|
31
36
|
.sort((a, b) => b.score - a.score);
|
|
32
37
|
}
|
|
38
|
+
function expandTokens(tokens) {
|
|
39
|
+
return [...new Set(tokens.flatMap((token) => [token, ...splitIdentifier(token)]))];
|
|
40
|
+
}
|
|
41
|
+
function splitIdentifier(value) {
|
|
42
|
+
return value
|
|
43
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
44
|
+
.split(/[^A-Za-z0-9_$]+/)
|
|
45
|
+
.map((part) => part.toLowerCase())
|
|
46
|
+
.filter((part) => part.length > 1);
|
|
47
|
+
}
|
|
@@ -4,7 +4,7 @@ export const claudeCodeAdapter = {
|
|
|
4
4
|
targetPath: 'CLAUDE.md',
|
|
5
5
|
instructions: `## KGraph Workflow
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
{{KGRAPH_CONTEXT_POLICY}} Use /kgraph for the full automated workflow. Run \`kgraph doctor\` when setup or generated maps look wrong. Run \`kgraph scan\`, \`kgraph update\`, and \`kgraph context\` manually only when you need one specific step.
|
|
8
8
|
`,
|
|
9
9
|
commandFiles: [
|
|
10
10
|
{
|
|
@@ -12,16 +12,18 @@ Before exploring the repository, run \`kgraph "<topic>"\` to refresh repo intell
|
|
|
12
12
|
content: `Use KGraph persistent repo intelligence for the current request.
|
|
13
13
|
|
|
14
14
|
1. Infer the topic from the user's request.
|
|
15
|
-
2.
|
|
15
|
+
2. {{KGRAPH_CONTEXT_POLICY}}
|
|
16
16
|
3. Use the returned files, symbols, relationships, and cognition before broad exploration.
|
|
17
17
|
4. Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
18
|
-
5.
|
|
19
|
-
6.
|
|
20
|
-
7.
|
|
21
|
-
8. Do not
|
|
22
|
-
9.
|
|
23
|
-
10.
|
|
24
|
-
11. Run \`kgraph
|
|
18
|
+
5. Track meaningful session activity with \`kgraph session start --agent claude-code\`, \`kgraph session read <path> --agent claude-code\`, \`kgraph session write <path> --agent claude-code\`, and \`kgraph session end --agent claude-code\` when native hooks are unavailable.
|
|
19
|
+
6. Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
20
|
+
7. At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
21
|
+
8. Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
22
|
+
9. Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
23
|
+
10. After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
24
|
+
11. Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
25
|
+
12. Run \`kgraph visualize\` when the user wants to inspect the dependency graph — opens an interactive graph at http://localhost:4242 with PNG export.
|
|
26
|
+
13. Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
25
27
|
|
|
26
28
|
The inbox note must use this structure:
|
|
27
29
|
\`\`\`markdown
|
|
@@ -64,13 +66,69 @@ Any implementation or product decision future sessions should know.
|
|
|
64
66
|
{
|
|
65
67
|
path: '.claude/commands/kgraph-visualize.md',
|
|
66
68
|
content: `Run \`kgraph visualize\` to start an interactive dependency graph at http://localhost:4242. Opens in browser automatically. Use \`--no-open\` to print URL only, \`--port <n>\` for a custom port.
|
|
69
|
+
`,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
path: '.claude/commands/kgraph-impact.md',
|
|
73
|
+
content: `Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related cognition, and risk hints.
|
|
74
|
+
`,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
path: '.claude/commands/kgraph-session.md',
|
|
78
|
+
content: `Use \`kgraph session\` to inspect session read/write/token estimates. Record meaningful events with \`kgraph session start --agent claude-code\`, \`kgraph session read <path> --agent claude-code\`, \`kgraph session write <path> --agent claude-code\`, and \`kgraph session end --agent claude-code\`.
|
|
67
79
|
`,
|
|
68
80
|
},
|
|
69
81
|
{
|
|
70
82
|
path: '.claude/commands/kgraph-history.md',
|
|
71
|
-
content: `Run \`kgraph history\`
|
|
83
|
+
content: `Run \`kgraph history\` or \`kgraph history "$ARGUMENTS"\` to show processed cognition sessions. Includes git author attribution when available. Use \`--last <n>\` to limit entries, \`--json\` for machine-readable output.
|
|
72
84
|
`,
|
|
73
85
|
},
|
|
86
|
+
{
|
|
87
|
+
path: '.claude/hooks/kgraph-session-start.cjs',
|
|
88
|
+
content: hookScript('start'),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: '.claude/hooks/kgraph-session-pre-read.cjs',
|
|
92
|
+
content: hookScript('read'),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
path: '.claude/hooks/kgraph-session-post-write.cjs',
|
|
96
|
+
content: hookScript('write'),
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
path: '.claude/hooks/kgraph-session-stop.cjs',
|
|
100
|
+
content: hookScript('end'),
|
|
101
|
+
},
|
|
74
102
|
],
|
|
75
103
|
obsoleteCommandFiles: [],
|
|
76
104
|
};
|
|
105
|
+
function hookScript(event) {
|
|
106
|
+
const pathArg = event === 'read' || event === 'write'
|
|
107
|
+
? `const payload = readPayload();
|
|
108
|
+
const filePath = payload?.tool_input?.file_path || payload?.toolInput?.file_path || payload?.file_path;
|
|
109
|
+
if (!filePath) process.exit(0);
|
|
110
|
+
args.push(filePath);`
|
|
111
|
+
: '';
|
|
112
|
+
return `#!/usr/bin/env node
|
|
113
|
+
const { spawnSync } = require('node:child_process');
|
|
114
|
+
|
|
115
|
+
function readPayload() {
|
|
116
|
+
try {
|
|
117
|
+
const chunks = [];
|
|
118
|
+
let chunk;
|
|
119
|
+
while ((chunk = require('node:fs').readFileSync(0, { encoding: 'utf8' }))) {
|
|
120
|
+
chunks.push(chunk);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return chunks.join('') ? JSON.parse(chunks.join('')) : {};
|
|
124
|
+
} catch {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const args = ['session', '${event}', '--agent', 'claude-code', '--source', 'automatic'];
|
|
130
|
+
${pathArg}
|
|
131
|
+
const result = spawnSync('kgraph', args, { stdio: 'ignore' });
|
|
132
|
+
process.exit(result.status || 0);
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
@@ -4,14 +4,16 @@ export const clineAdapter = {
|
|
|
4
4
|
targetPath: '.clinerules/kgraph.md',
|
|
5
5
|
instructions: `# KGraph Workflow
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- {{KGRAPH_CONTEXT_POLICY}}
|
|
8
8
|
- Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- Do not
|
|
9
|
+
- Track meaningful session activity with \`kgraph session start --agent cline\`, \`kgraph session read <path> --agent cline\`, \`kgraph session write <path> --agent cline\`, and \`kgraph session end --agent cline\`.
|
|
10
|
+
- Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
11
|
+
- At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
12
|
+
- Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
13
|
+
- Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
14
|
+
- After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
13
15
|
- Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
14
16
|
- Run \`kgraph visualize\` to open the interactive dependency graph at http://localhost:4242 with PNG export.
|
|
15
|
-
- Run \`kgraph history\`
|
|
17
|
+
- Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
16
18
|
`,
|
|
17
19
|
};
|
|
@@ -4,14 +4,14 @@ export const codexAdapter = {
|
|
|
4
4
|
targetPath: 'AGENTS.md',
|
|
5
5
|
instructions: `## KGraph Workflow
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
{{KGRAPH_CONTEXT_POLICY}} The /kgraph skill handles the full automated workflow. Run \`kgraph doctor\` when setup or generated maps look wrong. Run \`kgraph scan\`, \`kgraph update\`, and \`kgraph context\` manually only when you need one specific step.
|
|
8
8
|
`,
|
|
9
9
|
commandFiles: [
|
|
10
10
|
{
|
|
11
11
|
path: '.agents/skills/kgraph/SKILL.md',
|
|
12
12
|
content: `---
|
|
13
13
|
name: kgraph
|
|
14
|
-
description: Use KGraph persistent repo intelligence
|
|
14
|
+
description: Use KGraph persistent repo intelligence according to the configured integration mode. Use when asked about repo structure, debugging context, architecture decisions, or to avoid rediscovering what is already known.
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
# KGraph Skill
|
|
@@ -19,16 +19,18 @@ description: Use KGraph persistent repo intelligence before broad repository exp
|
|
|
19
19
|
Workflow:
|
|
20
20
|
|
|
21
21
|
1. Infer the current topic from the user request.
|
|
22
|
-
2.
|
|
22
|
+
2. {{KGRAPH_CONTEXT_POLICY}}
|
|
23
23
|
3. Use KGraph's returned files, symbols, relationships, and cognition as navigation hints.
|
|
24
24
|
4. Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
25
|
-
5.
|
|
26
|
-
6.
|
|
27
|
-
7.
|
|
28
|
-
8. Do not
|
|
29
|
-
9.
|
|
30
|
-
10.
|
|
31
|
-
11. Run \`kgraph
|
|
25
|
+
5. Track meaningful session activity with \`kgraph session start --agent codex\`, \`kgraph session read <path> --agent codex\`, \`kgraph session write <path> --agent codex\`, and \`kgraph session end --agent codex\`.
|
|
26
|
+
6. Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
27
|
+
7. At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
28
|
+
8. Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
29
|
+
9. Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
30
|
+
10. After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
31
|
+
11. Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
32
|
+
12. Run \`kgraph visualize\` when the user wants to inspect the dependency graph — opens an interactive graph at http://localhost:4242 with PNG export.
|
|
33
|
+
13. Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
32
34
|
|
|
33
35
|
The inbox note must use this structure:
|
|
34
36
|
\`\`\`markdown
|
|
@@ -4,13 +4,15 @@ export const copilotAdapter = {
|
|
|
4
4
|
targetPath: '.github/copilot-instructions.md',
|
|
5
5
|
instructions: `## KGraph Workflow
|
|
6
6
|
|
|
7
|
-
1.
|
|
7
|
+
1. {{KGRAPH_CONTEXT_POLICY}}
|
|
8
8
|
2. Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
9
|
-
3.
|
|
10
|
-
4.
|
|
11
|
-
5.
|
|
12
|
-
6. Do not
|
|
13
|
-
7.
|
|
9
|
+
3. Track meaningful session activity with \`kgraph session start --agent copilot\`, \`kgraph session read <path> --agent copilot\`, \`kgraph session write <path> --agent copilot\`, and \`kgraph session end --agent copilot\`.
|
|
10
|
+
4. Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
11
|
+
5. At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
12
|
+
6. Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
13
|
+
7. Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
14
|
+
8. After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
15
|
+
9. Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
14
16
|
|
|
15
17
|
The inbox note must use this structure:
|
|
16
18
|
\`\`\`markdown
|
|
@@ -91,9 +93,9 @@ argument-hint: "Brief description of what was done"
|
|
|
91
93
|
|
|
92
94
|
Capture this session into KGraph cognition.
|
|
93
95
|
|
|
94
|
-
1. For any completed code or repo-file change,
|
|
95
|
-
2.
|
|
96
|
-
3.
|
|
96
|
+
1. For any completed code or repo-file change, write one Markdown note to \`.kgraph/inbox/<slug>.md\` using the structure below.
|
|
97
|
+
2. Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
98
|
+
3. Use the user's message as context, but keep the note factual and concise.
|
|
97
99
|
4. Run \`kgraph\` once to process the note and refresh maps. Use \`kgraph update\` only when you intentionally want inbox processing without a scan.
|
|
98
100
|
|
|
99
101
|
Note structure:
|
|
@@ -112,6 +114,28 @@ One or two sentences describing what was done.
|
|
|
112
114
|
## Decisions
|
|
113
115
|
Any architectural or implementation decisions made.
|
|
114
116
|
\`\`\`
|
|
117
|
+
`,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
path: '.github/prompts/kgraph-impact.prompt.md',
|
|
121
|
+
content: `---
|
|
122
|
+
description: Show KGraph change impact for a file, symbol, or topic
|
|
123
|
+
agent: agent
|
|
124
|
+
argument-hint: "File, symbol, or topic"
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related cognition, and risk hints.
|
|
128
|
+
`,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
path: '.github/prompts/kgraph-session.prompt.md',
|
|
132
|
+
content: `---
|
|
133
|
+
description: Track KGraph session read/write activity and token estimates
|
|
134
|
+
agent: agent
|
|
135
|
+
argument-hint: "start, read <path>, write <path>, end, or status"
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
Use \`kgraph session\` to inspect current session activity. Record meaningful events with \`kgraph session start --agent copilot\`, \`kgraph session read <path> --agent copilot\`, \`kgraph session write <path> --agent copilot\`, and \`kgraph session end --agent copilot\`.
|
|
115
139
|
`,
|
|
116
140
|
},
|
|
117
141
|
{
|
|
@@ -119,9 +143,10 @@ Any architectural or implementation decisions made.
|
|
|
119
143
|
content: `---
|
|
120
144
|
description: Show timeline of KGraph cognition sessions with git attribution
|
|
121
145
|
agent: agent
|
|
146
|
+
argument-hint: "Optional topic"
|
|
122
147
|
---
|
|
123
148
|
|
|
124
|
-
Run \`kgraph history\`
|
|
149
|
+
Run \`kgraph history\` or \`kgraph history "$ARGUMENTS"\` to display processed cognition sessions. Summarize who contributed what and when. Use \`--last <n>\` to limit entries.
|
|
125
150
|
`,
|
|
126
151
|
},
|
|
127
152
|
],
|
|
@@ -9,15 +9,17 @@ alwaysApply: true
|
|
|
9
9
|
|
|
10
10
|
## KGraph Workflow
|
|
11
11
|
|
|
12
|
-
-
|
|
12
|
+
- {{KGRAPH_CONTEXT_POLICY}}
|
|
13
13
|
- Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
- Do not
|
|
14
|
+
- Track meaningful session activity with \`kgraph session start --agent cursor\`, \`kgraph session read <path> --agent cursor\`, \`kgraph session write <path> --agent cursor\`, and \`kgraph session end --agent cursor\`.
|
|
15
|
+
- Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
16
|
+
- At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
17
|
+
- Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
18
|
+
- Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
19
|
+
- After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
18
20
|
- Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
19
21
|
- Run \`kgraph visualize\` to open the interactive dependency graph at http://localhost:4242 with PNG export.
|
|
20
|
-
- Run \`kgraph history\`
|
|
22
|
+
- Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
21
23
|
`,
|
|
22
24
|
obsoleteCommandFiles: ['.cursor/rules/kgraph-commands.mdc'],
|
|
23
25
|
};
|
|
@@ -4,14 +4,16 @@ export const geminiAdapter = {
|
|
|
4
4
|
targetPath: 'GEMINI.md',
|
|
5
5
|
instructions: `## KGraph Workflow
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- {{KGRAPH_CONTEXT_POLICY}}
|
|
8
8
|
- Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- Do not
|
|
9
|
+
- Track meaningful session activity with \`kgraph session start --agent gemini\`, \`kgraph session read <path> --agent gemini\`, \`kgraph session write <path> --agent gemini\`, and \`kgraph session end --agent gemini\`.
|
|
10
|
+
- Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
11
|
+
- At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
12
|
+
- Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
13
|
+
- Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
14
|
+
- After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
13
15
|
- Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
14
16
|
- Run \`kgraph visualize\` to open the interactive dependency graph at http://localhost:4242 with PNG export.
|
|
15
|
-
- Run \`kgraph history\`
|
|
17
|
+
- Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
16
18
|
`,
|
|
17
19
|
};
|
|
@@ -4,14 +4,16 @@ export const windsurfAdapter = {
|
|
|
4
4
|
targetPath: '.windsurf/rules/kgraph.md',
|
|
5
5
|
instructions: `# KGraph Workflow
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- {{KGRAPH_CONTEXT_POLICY}}
|
|
8
8
|
- Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- Do not
|
|
9
|
+
- Track meaningful session activity with \`kgraph session start --agent windsurf\`, \`kgraph session read <path> --agent windsurf\`, \`kgraph session write <path> --agent windsurf\`, and \`kgraph session end --agent windsurf\`.
|
|
10
|
+
- Run \`kgraph impact "<file-or-symbol>"\` when the user asks what a change may affect. Run \`kgraph history "<topic>"\` when prior work or decisions matter.
|
|
11
|
+
- At the end of any session that changed repository files, write one concise Markdown note to \`.kgraph/inbox/<slug>.md\` before finishing.
|
|
12
|
+
- Do not skip capture for UI text, button, link, route, styling, or small file edits. Skip capture only when no repository files changed.
|
|
13
|
+
- Do not run KGraph repeatedly. Run it once at the start with \`kgraph "<topic>"\`. If repo files changed, write the inbox note first, then run \`kgraph\` once at the end.
|
|
14
|
+
- After the final \`kgraph\` run, mention whether the inbox note was processed.
|
|
13
15
|
- Run \`kgraph repair --dry-run\` before cleanup when stale/noisy cognition needs fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.
|
|
14
16
|
- Run \`kgraph visualize\` to open the interactive dependency graph at http://localhost:4242 with PNG export.
|
|
15
|
-
- Run \`kgraph history\`
|
|
17
|
+
- Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.
|
|
16
18
|
`,
|
|
17
19
|
};
|