@kentwynn/kgraph 0.2.10 → 0.2.12
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 +59 -29
- package/dist/cli/commands/blame.d.ts +2 -0
- package/dist/cli/commands/blame.js +52 -0
- package/dist/cli/commands/doctor.js +42 -12
- package/dist/cli/commands/impact.js +11 -5
- package/dist/cli/commands/init.js +2 -0
- package/dist/cli/commands/knowledge.d.ts +2 -0
- package/dist/cli/commands/knowledge.js +137 -0
- package/dist/cli/commands/pack.d.ts +2 -0
- package/dist/cli/commands/pack.js +49 -0
- package/dist/cli/commands/repair.js +3 -3
- package/dist/cli/commands/stale.d.ts +2 -0
- package/dist/cli/commands/stale.js +33 -0
- package/dist/cli/commands/visualize.js +7 -6
- package/dist/cli/help.js +17 -11
- package/dist/cli/index.js +8 -0
- package/dist/cognition/cognition-quality.d.ts +5 -0
- package/dist/cognition/cognition-quality.js +98 -5
- package/dist/cognition/cognition-updater.js +14 -0
- package/dist/cognition/compact.js +129 -28
- package/dist/cognition/conclusion.d.ts +2 -0
- package/dist/cognition/conclusion.js +22 -0
- package/dist/context/context-pack.d.ts +3 -0
- package/dist/context/context-pack.js +71 -0
- package/dist/context/context-query.js +53 -28
- package/dist/integrations/adapters/claude-code.js +23 -3
- package/dist/integrations/adapters/codex.js +1 -1
- package/dist/integrations/adapters/copilot.js +46 -3
- package/dist/integrations/workflow-steps.js +17 -8
- package/dist/knowledge/atom-store.d.ts +60 -0
- package/dist/knowledge/atom-store.js +484 -0
- package/dist/storage/kgraph-paths.js +5 -2
- package/dist/types/config.d.ts +1 -0
- package/dist/types/knowledge.d.ts +92 -0
- package/dist/types/knowledge.js +1 -0
- package/dist/visualization/graph-builder.d.ts +5 -2
- package/dist/visualization/graph-builder.js +43 -18
- package/dist/visualization/html-template.js +24 -17
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { estimateTokens } from '../session/token-estimator.js';
|
|
2
|
+
export function buildContextPack(response, budget) {
|
|
3
|
+
const candidates = [
|
|
4
|
+
...response.relevantFiles.map((ranked) => ({
|
|
5
|
+
kind: 'file',
|
|
6
|
+
id: ranked.item.path,
|
|
7
|
+
title: ranked.item.path,
|
|
8
|
+
tokenEstimate: ranked.item.tokenEstimate ?? 0,
|
|
9
|
+
reasons: ranked.reasons,
|
|
10
|
+
data: ranked.item,
|
|
11
|
+
})),
|
|
12
|
+
...response.relevantSymbols.map((ranked) => ({
|
|
13
|
+
kind: 'symbol',
|
|
14
|
+
id: ranked.item.id,
|
|
15
|
+
title: ranked.item.name,
|
|
16
|
+
tokenEstimate: 20,
|
|
17
|
+
reasons: ranked.reasons,
|
|
18
|
+
data: ranked.item,
|
|
19
|
+
})),
|
|
20
|
+
...response.relevantCognition.map((ranked) => ({
|
|
21
|
+
kind: 'atom',
|
|
22
|
+
id: ranked.item.id,
|
|
23
|
+
title: ranked.item.title,
|
|
24
|
+
tokenEstimate: estimateTokens([ranked.item.title, ranked.item.summary ?? ''].join('\n'), `${ranked.item.id}.md`),
|
|
25
|
+
reasons: ranked.reasons,
|
|
26
|
+
data: ranked.item,
|
|
27
|
+
})),
|
|
28
|
+
...response.relationships.map((relationship) => ({
|
|
29
|
+
kind: 'relationship',
|
|
30
|
+
id: [
|
|
31
|
+
relationship.sourceId,
|
|
32
|
+
relationship.relationshipType,
|
|
33
|
+
relationship.targetId,
|
|
34
|
+
].join(' -> '),
|
|
35
|
+
title: `${relationship.sourceId} ${relationship.relationshipType} ${relationship.targetId}`,
|
|
36
|
+
tokenEstimate: 16,
|
|
37
|
+
reasons: response.relationshipExplanations?.find((item) => item.relationship.sourceId === relationship.sourceId &&
|
|
38
|
+
item.relationship.targetId === relationship.targetId &&
|
|
39
|
+
item.relationship.relationshipType === relationship.relationshipType)?.reasons ?? ['related graph edge'],
|
|
40
|
+
data: relationship,
|
|
41
|
+
})),
|
|
42
|
+
...(response.gitChanges ?? []).map((change) => ({
|
|
43
|
+
kind: 'git-change',
|
|
44
|
+
id: change.path,
|
|
45
|
+
title: `${change.status}: ${change.path}`,
|
|
46
|
+
tokenEstimate: 12,
|
|
47
|
+
reasons: [change.reason],
|
|
48
|
+
data: change,
|
|
49
|
+
})),
|
|
50
|
+
];
|
|
51
|
+
const items = [];
|
|
52
|
+
const omitted = [];
|
|
53
|
+
let usedTokens = 0;
|
|
54
|
+
for (const candidate of candidates) {
|
|
55
|
+
if (usedTokens + candidate.tokenEstimate <= budget) {
|
|
56
|
+
items.push(candidate);
|
|
57
|
+
usedTokens += candidate.tokenEstimate;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
omitted.push(candidate);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
task: response.query,
|
|
65
|
+
budget,
|
|
66
|
+
usedTokens,
|
|
67
|
+
items,
|
|
68
|
+
omitted,
|
|
69
|
+
warnings: response.warnings,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { getRecentlyCommittedFiles, getWorkingTreeChangesDetailed, isGitRepo, } from '../scanner/git-utils.js';
|
|
2
|
-
import {
|
|
2
|
+
import { readDomainRecords } from '../storage/cognition-store.js';
|
|
3
3
|
import { readSessionState } from '../session/session-store.js';
|
|
4
|
+
import { atomToCognitionNote, refreshKnowledgeAtomStatuses, } from '../knowledge/atom-store.js';
|
|
4
5
|
import { rankByFields } from './ranking.js';
|
|
5
6
|
export async function queryContext(workspace, config, maps, query) {
|
|
6
|
-
const
|
|
7
|
+
const refreshedAtoms = await refreshKnowledgeAtomStatuses(workspace, {
|
|
8
|
+
fileMap: maps.fileMap,
|
|
9
|
+
symbolMap: maps.symbolMap,
|
|
10
|
+
});
|
|
11
|
+
const atoms = refreshedAtoms.atoms;
|
|
12
|
+
const cognition = atoms
|
|
13
|
+
.filter((atom) => atom.status !== 'archived')
|
|
14
|
+
.map(atomToCognitionNote);
|
|
7
15
|
const domains = await readDomainRecords(workspace);
|
|
8
16
|
const session = await readSessionState(workspace);
|
|
9
17
|
const sessionTouchedPaths = new Set(session.events
|
|
@@ -31,17 +39,23 @@ export async function queryContext(workspace, config, maps, query) {
|
|
|
31
39
|
{ name: 'kind', value: (symbol) => symbol.kind },
|
|
32
40
|
{ name: 'parent', value: (symbol) => symbol.parentName },
|
|
33
41
|
]).slice(0, max);
|
|
34
|
-
const relevantCognition = rankByFields(query,
|
|
35
|
-
{ name: '
|
|
36
|
-
{ name: '
|
|
37
|
-
{ name: '
|
|
38
|
-
{ name: '
|
|
39
|
-
{ name: '
|
|
40
|
-
{ name: '
|
|
41
|
-
{ name: '
|
|
42
|
-
{ name: '
|
|
42
|
+
const relevantCognition = rankByFields(query, atoms.filter((atom) => atom.status !== 'archived'), [
|
|
43
|
+
{ name: 'topic', value: (atom) => atom.topic },
|
|
44
|
+
{ name: 'claim', value: (atom) => atom.claim },
|
|
45
|
+
{ name: 'type', value: (atom) => atom.type },
|
|
46
|
+
{ name: 'confidence', value: (atom) => atom.confidence },
|
|
47
|
+
{ name: 'status', value: (atom) => atom.status },
|
|
48
|
+
{ name: 'source', value: (atom) => atom.provenance.sourceCommand },
|
|
49
|
+
{ name: 'domains', value: (atom) => atom.scopeRefs.domains },
|
|
50
|
+
{ name: 'files', value: (atom) => atom.scopeRefs.files },
|
|
51
|
+
{ name: 'symbols', value: (atom) => atom.scopeRefs.symbols },
|
|
52
|
+
{ name: 'summary', value: (atom) => atom.summary },
|
|
43
53
|
])
|
|
44
|
-
.map((ranked) =>
|
|
54
|
+
.map((ranked) => applyAtomRankAdjustments(ranked))
|
|
55
|
+
.map((ranked) => ({
|
|
56
|
+
...ranked,
|
|
57
|
+
item: atomToCognitionNote(ranked.item),
|
|
58
|
+
}))
|
|
45
59
|
.sort((a, b) => b.score - a.score)
|
|
46
60
|
.slice(0, max);
|
|
47
61
|
const matchedDomains = rankByFields(query, domains, [
|
|
@@ -292,33 +306,44 @@ function explainRelationships(relationships, context) {
|
|
|
292
306
|
return { relationship, reasons: [...reasons] };
|
|
293
307
|
});
|
|
294
308
|
}
|
|
295
|
-
function
|
|
309
|
+
function applyAtomRankAdjustments(ranked) {
|
|
296
310
|
const reasons = [...ranked.reasons];
|
|
297
311
|
let score = ranked.score;
|
|
298
312
|
if (ranked.item.confidence === 'high') {
|
|
313
|
+
score += 4;
|
|
314
|
+
reasons.push('high confidence atom');
|
|
315
|
+
}
|
|
316
|
+
else if (ranked.item.confidence === 'medium') {
|
|
317
|
+
score += 1;
|
|
318
|
+
reasons.push('medium confidence atom');
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
score -= 3;
|
|
322
|
+
reasons.push('low confidence penalty');
|
|
323
|
+
}
|
|
324
|
+
if (ranked.item.status === 'active') {
|
|
299
325
|
score += 3;
|
|
300
|
-
reasons.push('
|
|
326
|
+
reasons.push('active atom evidence');
|
|
301
327
|
}
|
|
302
|
-
else if (ranked.item.
|
|
328
|
+
else if (ranked.item.status === 'needs-review') {
|
|
303
329
|
score -= 2;
|
|
304
|
-
reasons.push('
|
|
330
|
+
reasons.push('needs-review stale penalty');
|
|
305
331
|
}
|
|
306
|
-
if (ranked.item.
|
|
332
|
+
else if (ranked.item.status === 'stale') {
|
|
333
|
+
score -= 6;
|
|
334
|
+
reasons.push('stale atom penalty');
|
|
335
|
+
}
|
|
336
|
+
if (ranked.item.type === 'decision' || ranked.item.type === 'gotcha') {
|
|
307
337
|
score += 2;
|
|
308
|
-
reasons.push(
|
|
338
|
+
reasons.push(`${ranked.item.type} atom`);
|
|
309
339
|
}
|
|
310
|
-
|
|
340
|
+
if (ranked.item.provenance.sourceCommand === 'legacy-migration') {
|
|
311
341
|
score -= 1;
|
|
312
|
-
reasons.push('
|
|
313
|
-
}
|
|
314
|
-
else if (ranked.item.referencesStatus === 'stale' ||
|
|
315
|
-
ranked.item.referencesStatus === 'unresolved') {
|
|
316
|
-
score -= 4;
|
|
317
|
-
reasons.push('stale reference penalty');
|
|
342
|
+
reasons.push('legacy compatibility atom');
|
|
318
343
|
}
|
|
319
|
-
if (ranked.item.
|
|
320
|
-
score
|
|
321
|
-
reasons.push(
|
|
344
|
+
if (ranked.item.lifecycle.supersededBy) {
|
|
345
|
+
score -= 8;
|
|
346
|
+
reasons.push('superseded atom penalty');
|
|
322
347
|
}
|
|
323
348
|
return { ...ranked, score, reasons };
|
|
324
349
|
}
|
|
@@ -5,7 +5,7 @@ export const claudeCodeAdapter = {
|
|
|
5
5
|
targetPath: 'CLAUDE.md',
|
|
6
6
|
instructions: `## KGraph Workflow
|
|
7
7
|
|
|
8
|
-
{{KGRAPH_CONTEXT_POLICY}} Use /kgraph for the full automated workflow. Run \`kgraph conclude\` for durable typed engineering memory and \`kgraph compact --dry-run\` when cognition looks duplicated or stale. 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
|
+
{{KGRAPH_CONTEXT_POLICY}} Use /kgraph for the full automated workflow. Run \`kgraph pack "<task>" --budget 8000 --json\` for a machine-readable token-budgeted context pack, \`kgraph knowledge list\` or \`kgraph knowledge get <atom-id>\` to inspect durable atoms, \`kgraph stale\` and \`kgraph blame <atom-id>\` when lifecycle/provenance matters, \`kgraph conclude\` for durable typed engineering memory, and \`kgraph compact --dry-run\` when cognition looks duplicated or stale. 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.
|
|
9
9
|
`,
|
|
10
10
|
commandFiles: [
|
|
11
11
|
{
|
|
@@ -22,12 +22,32 @@ ${numberedWorkflow('claude-code', { sessionQualifier: 'when native hooks are una
|
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
path: '.claude/commands/kgraph-repair.md',
|
|
25
|
-
content: `Run \`kgraph repair --dry-run\` first and summarize the proposed
|
|
25
|
+
content: `Run \`kgraph repair --dry-run\` first and summarize the proposed atom-reference cleanup. Run \`kgraph repair\` only when the user asks to apply the cleanup.
|
|
26
26
|
`,
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
path: '.claude/commands/kgraph-compact.md',
|
|
30
30
|
content: `Run \`kgraph compact --dry-run\` first and summarize duplicate cognition groups and stale low-confidence notes. Run \`kgraph compact\` only when the user asks to apply compaction.
|
|
31
|
+
`,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
path: '.claude/commands/kgraph-pack.md',
|
|
35
|
+
content: `Run \`kgraph pack "$ARGUMENTS" --budget 8000 --json\` to build a machine-readable context pack. Summarize token use, included files, symbols, relationships, git changes, session history, atoms, and omitted items with the inclusion reasons.
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: '.claude/commands/kgraph-knowledge.md',
|
|
40
|
+
content: `Use \`kgraph knowledge list\` and \`kgraph knowledge get <atom-id>\` to inspect durable atoms, evidence, provenance, and lifecycle. Run \`kgraph knowledge archive <atom-id>\` or \`kgraph knowledge supersede <old-id> <new-id>\` only when the user explicitly asks to mutate atom lifecycle.
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: '.claude/commands/kgraph-stale.md',
|
|
45
|
+
content: `Run \`kgraph stale\` to refresh atom status against the current scan and summarize stale or needs-review atoms with invalidation reasons.
|
|
46
|
+
`,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
path: '.claude/commands/kgraph-blame.md',
|
|
50
|
+
content: `Run \`kgraph blame "$ARGUMENTS"\` to show who or what created a knowledge atom, the source command/session/commit, evidence refs, and lifecycle links.
|
|
31
51
|
`,
|
|
32
52
|
},
|
|
33
53
|
{
|
|
@@ -47,7 +67,7 @@ ${numberedWorkflow('claude-code', { sessionQualifier: 'when native hooks are una
|
|
|
47
67
|
},
|
|
48
68
|
{
|
|
49
69
|
path: '.claude/commands/kgraph-impact.md',
|
|
50
|
-
content: `Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related
|
|
70
|
+
content: `Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related knowledge atoms, and risk hints.
|
|
51
71
|
`,
|
|
52
72
|
},
|
|
53
73
|
{
|
|
@@ -5,7 +5,7 @@ export const codexAdapter = {
|
|
|
5
5
|
targetPath: 'AGENTS.md',
|
|
6
6
|
instructions: `## KGraph Workflow
|
|
7
7
|
|
|
8
|
-
{{KGRAPH_CONTEXT_POLICY}} The /kgraph skill handles the full automated workflow. Run \`kgraph conclude\` for durable typed engineering memory and \`kgraph compact --dry-run\` when cognition looks duplicated or stale. 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
|
+
{{KGRAPH_CONTEXT_POLICY}} The /kgraph skill handles the full automated workflow. Run \`kgraph pack "<task>" --budget 8000 --json\` for a machine-readable token-budgeted context pack, \`kgraph knowledge list\` or \`kgraph knowledge get <atom-id>\` to inspect durable atoms, \`kgraph stale\` and \`kgraph blame <atom-id>\` when lifecycle/provenance matters, \`kgraph conclude\` for durable typed engineering memory, and \`kgraph compact --dry-run\` when cognition looks duplicated or stale. 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.
|
|
9
9
|
`,
|
|
10
10
|
commandFiles: [
|
|
11
11
|
{
|
|
@@ -12,7 +12,7 @@ ${numberedWorkflow('copilot')}
|
|
|
12
12
|
path: '.github/agents/kgraph.agent.md',
|
|
13
13
|
content: `---
|
|
14
14
|
name: kgraph
|
|
15
|
-
description: Use KGraph persistent repo intelligence to answer questions about this codebase. Runs kgraph context, scan, update, conclude, compact, impact, history, and session commands to ground responses in durable local knowledge.
|
|
15
|
+
description: Use KGraph persistent repo intelligence to answer questions about this codebase. Runs kgraph context, pack, knowledge, stale, blame, scan, update, conclude, compact, impact, history, and session commands to ground responses in durable local knowledge.
|
|
16
16
|
tools:
|
|
17
17
|
- run_in_terminal
|
|
18
18
|
- read_file
|
|
@@ -46,7 +46,7 @@ agent: agent
|
|
|
46
46
|
argument-hint: "--dry-run or apply"
|
|
47
47
|
---
|
|
48
48
|
|
|
49
|
-
Run \`kgraph repair --dry-run\` first and summarize the proposed
|
|
49
|
+
Run \`kgraph repair --dry-run\` first and summarize the proposed atom-reference cleanup. Run \`kgraph repair\` only when the user asks to apply the cleanup.
|
|
50
50
|
`,
|
|
51
51
|
},
|
|
52
52
|
{
|
|
@@ -58,6 +58,49 @@ argument-hint: "--dry-run or apply"
|
|
|
58
58
|
---
|
|
59
59
|
|
|
60
60
|
Run \`kgraph compact --dry-run\` first and summarize duplicate cognition groups and stale low-confidence notes. Run \`kgraph compact\` only when the user asks to apply compaction.
|
|
61
|
+
`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
path: '.github/prompts/kgraph-pack.prompt.md',
|
|
65
|
+
content: `---
|
|
66
|
+
description: Build a budget-aware KGraph context pack
|
|
67
|
+
agent: agent
|
|
68
|
+
argument-hint: "Task description"
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
Run \`kgraph pack "$ARGUMENTS" --budget 8000 --json\` to build a machine-readable context pack. Summarize token use, included files, symbols, relationships, git changes, session history, atoms, and omitted items with the inclusion reasons.
|
|
72
|
+
`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
path: '.github/prompts/kgraph-knowledge.prompt.md',
|
|
76
|
+
content: `---
|
|
77
|
+
description: Inspect or manage KGraph canonical knowledge atoms
|
|
78
|
+
agent: agent
|
|
79
|
+
argument-hint: "list, get <atom-id>, archive <atom-id>, or supersede <old-id> <new-id>"
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
Use \`kgraph knowledge list\` and \`kgraph knowledge get <atom-id>\` to inspect durable atoms, evidence, provenance, and lifecycle. Run \`kgraph knowledge archive <atom-id>\` or \`kgraph knowledge supersede <old-id> <new-id>\` only when the user explicitly asks to mutate atom lifecycle.
|
|
83
|
+
`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
path: '.github/prompts/kgraph-stale.prompt.md',
|
|
87
|
+
content: `---
|
|
88
|
+
description: Show KGraph knowledge invalidated by changed or missing refs
|
|
89
|
+
agent: agent
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
Run \`kgraph stale\` to refresh atom status against the current scan and summarize stale or needs-review atoms with invalidation reasons.
|
|
93
|
+
`,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
path: '.github/prompts/kgraph-blame.prompt.md',
|
|
97
|
+
content: `---
|
|
98
|
+
description: Show KGraph atom provenance and evidence
|
|
99
|
+
agent: agent
|
|
100
|
+
argument-hint: "Atom id"
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
Run \`kgraph blame "$ARGUMENTS"\` to show who or what created a knowledge atom, the source command/session/commit, evidence refs, and lifecycle links.
|
|
61
104
|
`,
|
|
62
105
|
},
|
|
63
106
|
{
|
|
@@ -122,7 +165,7 @@ agent: agent
|
|
|
122
165
|
argument-hint: "File, symbol, or topic"
|
|
123
166
|
---
|
|
124
167
|
|
|
125
|
-
Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related
|
|
168
|
+
Run \`kgraph impact "$ARGUMENTS"\` to show matched files/symbols, import users, callers, callees, related knowledge atoms, and risk hints.
|
|
126
169
|
`,
|
|
127
170
|
},
|
|
128
171
|
{
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const DOCTOR_STEP = `Run \`kgraph doctor\` when setup, maps, inbox processing, or integrations look wrong. Run \`kgraph doctor --quality\` when context shows stale/noisy cognition references.`;
|
|
6
6
|
const IMPACT_STEP = `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.`;
|
|
7
|
-
const REPAIR_STEP = `Run \`kgraph repair --dry-run\` before cleanup when stale/noisy
|
|
7
|
+
const REPAIR_STEP = `Run \`kgraph repair --dry-run\` before cleanup when stale/noisy atom refs need fixing. Run \`kgraph repair\` only when the user asks to apply that cleanup.`;
|
|
8
8
|
const COMPACT_STEP = `Run \`kgraph compact --dry-run\` when cognition looks duplicated, noisy, or stale. Run \`kgraph compact\` only when the user asks to merge/archive cognition.`;
|
|
9
9
|
const HISTORY_STEP = `Run \`kgraph history\` or \`kgraph history "<topic>"\` to review past cognition sessions with git author attribution.`;
|
|
10
|
+
const KNOWLEDGE_STEP = `Run \`kgraph knowledge list --topic "<topic>"\` or \`kgraph knowledge get <atom-id>\` when the user asks what KGraph remembers or atom provenance/lifecycle matters.`;
|
|
11
|
+
const PACK_STEP = `Run \`kgraph pack "<task>" --budget 8000 --json\` when an agent needs a machine-readable, token-budgeted context pack instead of human Markdown context.`;
|
|
12
|
+
const STALE_STEP = `Run \`kgraph stale\` when changed or deleted code may have invalidated durable knowledge. Run \`kgraph blame <atom-id>\` when provenance or evidence for a memory matters.`;
|
|
10
13
|
function sessionStep(agentName, qualifier) {
|
|
11
14
|
const base = `Track meaningful session activity with \`kgraph session start --agent ${agentName}\`, \`kgraph session read <path> --agent ${agentName}\`, \`kgraph session write <path> --agent ${agentName}\`, and \`kgraph session end --agent ${agentName} --conclude --topic "<topic>"\` when durable session memory is useful`;
|
|
12
15
|
return qualifier ? `${base} ${qualifier}.` : `${base}.`;
|
|
@@ -19,16 +22,19 @@ export function numberedWorkflow(agentName, options = {}) {
|
|
|
19
22
|
return `1. Infer the topic from the user's request.
|
|
20
23
|
2. {{KGRAPH_CONTEXT_POLICY}}
|
|
21
24
|
3. Use the returned files, symbols, relationships, and cognition before broad exploration.
|
|
22
|
-
4. ${
|
|
23
|
-
5. ${
|
|
24
|
-
6. ${
|
|
25
|
+
4. ${PACK_STEP}
|
|
26
|
+
5. ${KNOWLEDGE_STEP}
|
|
27
|
+
6. ${DOCTOR_STEP}
|
|
28
|
+
7. ${STALE_STEP}
|
|
29
|
+
8. ${sessionStep(agentName, options.sessionQualifier)}
|
|
30
|
+
9. ${IMPACT_STEP}
|
|
25
31
|
|
|
26
32
|
{{KGRAPH_CAPTURE_POLICY}}
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
10. ${REPAIR_STEP}
|
|
35
|
+
11. ${COMPACT_STEP}
|
|
36
|
+
12. Run \`kgraph visualize\` when the user wants to inspect the dependency graph — opens an interactive graph at http://localhost:4242 with PNG export.
|
|
37
|
+
13. ${HISTORY_STEP}`;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
34
40
|
* Returns the bullet-list workflow for rules files.
|
|
@@ -36,7 +42,10 @@ export function numberedWorkflow(agentName, options = {}) {
|
|
|
36
42
|
*/
|
|
37
43
|
export function bulletWorkflow(agentName, options = {}) {
|
|
38
44
|
return `- {{KGRAPH_CONTEXT_POLICY}}
|
|
45
|
+
- ${PACK_STEP}
|
|
46
|
+
- ${KNOWLEDGE_STEP}
|
|
39
47
|
- ${DOCTOR_STEP}
|
|
48
|
+
- ${STALE_STEP}
|
|
40
49
|
- ${sessionStep(agentName, options.sessionQualifier)}
|
|
41
50
|
- ${IMPACT_STEP}
|
|
42
51
|
{{KGRAPH_CAPTURE_POLICY}}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CognitionConfidence, CognitionNote } from '../types/cognition.js';
|
|
2
|
+
import type { KGraphWorkspace } from '../types/config.js';
|
|
3
|
+
import type { KnowledgeAtom, KnowledgeValidationIssue } from '../types/knowledge.js';
|
|
4
|
+
import type { FileMap, SymbolMap } from '../types/maps.js';
|
|
5
|
+
export declare const KNOWLEDGE_SCHEMA_VERSION = 1;
|
|
6
|
+
export interface AtomInput {
|
|
7
|
+
type: KnowledgeAtom['type'];
|
|
8
|
+
topic: string;
|
|
9
|
+
claim: string;
|
|
10
|
+
summary?: string;
|
|
11
|
+
confidence?: CognitionConfidence;
|
|
12
|
+
files?: string[];
|
|
13
|
+
symbols?: string[];
|
|
14
|
+
domains?: string[];
|
|
15
|
+
packages?: string[];
|
|
16
|
+
sourceCommand: KnowledgeAtom['provenance']['sourceCommand'];
|
|
17
|
+
agent?: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
commit?: string;
|
|
20
|
+
createdAt?: string;
|
|
21
|
+
idSeed?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AtomStatusRefreshResult {
|
|
24
|
+
atoms: KnowledgeAtom[];
|
|
25
|
+
updated: Array<{
|
|
26
|
+
atomId: string;
|
|
27
|
+
previousStatus: KnowledgeAtom['status'];
|
|
28
|
+
nextStatus: KnowledgeAtom['status'];
|
|
29
|
+
reasons: string[];
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export declare function ensureKnowledgeStore(workspace: KGraphWorkspace): Promise<void>;
|
|
33
|
+
export declare function readKnowledgeAtoms(workspace: KGraphWorkspace): Promise<KnowledgeAtom[]>;
|
|
34
|
+
export declare function readAtomsFile(workspace: KGraphWorkspace): Promise<KnowledgeAtom[]>;
|
|
35
|
+
export declare function parseAtomsJsonl(raw: string): KnowledgeAtom[];
|
|
36
|
+
export declare function writeKnowledgeAtoms(workspace: KGraphWorkspace, atoms: KnowledgeAtom[]): Promise<void>;
|
|
37
|
+
export declare function appendKnowledgeAtom(workspace: KGraphWorkspace, atom: KnowledgeAtom): Promise<KnowledgeAtom>;
|
|
38
|
+
export declare function createKnowledgeAtom(workspace: KGraphWorkspace, input: AtomInput, maps?: {
|
|
39
|
+
fileMap: FileMap;
|
|
40
|
+
symbolMap: SymbolMap;
|
|
41
|
+
}): Promise<KnowledgeAtom>;
|
|
42
|
+
export declare function migrateLegacyCognitionToAtoms(workspace: KGraphWorkspace): Promise<void>;
|
|
43
|
+
export declare function updateKnowledgeAtom(workspace: KGraphWorkspace, atomId: string, updater: (atom: KnowledgeAtom) => KnowledgeAtom): Promise<KnowledgeAtom>;
|
|
44
|
+
export declare function refreshKnowledgeAtomStatuses(workspace: KGraphWorkspace, maps: {
|
|
45
|
+
fileMap: FileMap;
|
|
46
|
+
symbolMap: SymbolMap;
|
|
47
|
+
}, dryRun?: boolean): Promise<AtomStatusRefreshResult>;
|
|
48
|
+
export declare function validateKnowledgeStore(workspace: KGraphWorkspace, maps?: {
|
|
49
|
+
fileMap: FileMap;
|
|
50
|
+
symbolMap: SymbolMap;
|
|
51
|
+
}): Promise<KnowledgeValidationIssue[]>;
|
|
52
|
+
export declare function atomToCognitionNote(atom: KnowledgeAtom): CognitionNote;
|
|
53
|
+
export declare function knowledgePaths(workspace: KGraphWorkspace): {
|
|
54
|
+
atoms: string;
|
|
55
|
+
schema: string;
|
|
56
|
+
indexes: string;
|
|
57
|
+
terms: string;
|
|
58
|
+
refs: string;
|
|
59
|
+
topics: string;
|
|
60
|
+
};
|