agent-knowledge 1.5.2 → 1.6.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.
- package/README.md +14 -1
- package/agent-desk-plugin.json +2 -1
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js +43 -0
- package/dist/dashboard.js.map +1 -1
- package/dist/ui/app.js +7 -0
- package/dist/ui/index.html +92 -7
- package/dist/ui/render-graph.js +482 -0
- package/dist/ui/styles.css +72 -0
- package/dist/ui/vis-network.min.js +34 -0
- package/docs/INGEST.md +189 -0
- package/docs/SETUP.md +71 -10
- package/docs/hooks.md +116 -0
- package/package.json +6 -1
- package/scripts/copy-ui.js +4 -0
- package/scripts/hooks/precompact-distill.mjs +105 -0
- package/scripts/hooks/session-start-ingest.mjs +238 -0
- package/scripts/hooks/sessionend-distill.mjs +122 -0
- package/scripts/setup.js +217 -0
- package/scripts/tree-sitter-extract.mjs +464 -0
- package/scripts/tree-sitter-lang.mjs +366 -0
- package/skills/knowledge-ingest/SKILL.md +224 -0
- package/skills/knowledge-ingest/scripts/validate.mjs +170 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// validate.mjs — post-ingest validation for knowledge-ingest skill
|
|
5
|
+
//
|
|
6
|
+
// Checks that a knowledge-ingest run produced valid results:
|
|
7
|
+
// - Cache file exists and is well-formed
|
|
8
|
+
// - Expected knowledge entries exist on disk
|
|
9
|
+
// - Graph edges were created between entries
|
|
10
|
+
// - No orphaned entries (listed in cache but missing on disk)
|
|
11
|
+
//
|
|
12
|
+
// Usage:
|
|
13
|
+
// node scripts/validate.mjs <target-path> [--knowledge-dir <path>]
|
|
14
|
+
//
|
|
15
|
+
// Exits 0 if valid, 1 if issues found. Prints a structured report to stdout.
|
|
16
|
+
// =============================================================================
|
|
17
|
+
|
|
18
|
+
import { readFileSync, existsSync } from 'fs';
|
|
19
|
+
import { join, resolve } from 'path';
|
|
20
|
+
import { homedir } from 'os';
|
|
21
|
+
|
|
22
|
+
function parseArgs(argv) {
|
|
23
|
+
const args = { targetPath: null, knowledgeDir: null };
|
|
24
|
+
let i = 2;
|
|
25
|
+
while (i < argv.length) {
|
|
26
|
+
if (argv[i] === '--knowledge-dir' && argv[i + 1]) {
|
|
27
|
+
args.knowledgeDir = argv[++i];
|
|
28
|
+
} else if (!argv[i].startsWith('--')) {
|
|
29
|
+
args.targetPath = argv[i];
|
|
30
|
+
}
|
|
31
|
+
i++;
|
|
32
|
+
}
|
|
33
|
+
if (!args.targetPath) {
|
|
34
|
+
console.error('Usage: node validate.mjs <target-path> [--knowledge-dir <path>]');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
args.targetPath = resolve(args.targetPath);
|
|
38
|
+
args.knowledgeDir = args.knowledgeDir
|
|
39
|
+
? resolve(args.knowledgeDir)
|
|
40
|
+
: resolve(process.env.KNOWLEDGE_MEMORY_DIR || join(homedir(), 'agent-knowledge'));
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function main() {
|
|
45
|
+
const args = parseArgs(process.argv);
|
|
46
|
+
const issues = [];
|
|
47
|
+
const passed = [];
|
|
48
|
+
|
|
49
|
+
// ---- 1. Cache file ----
|
|
50
|
+
const cachePath = join(args.targetPath, '.knowledge-ingest-cache.json');
|
|
51
|
+
let cache = null;
|
|
52
|
+
|
|
53
|
+
if (!existsSync(cachePath)) {
|
|
54
|
+
issues.push(
|
|
55
|
+
'Cache file .knowledge-ingest-cache.json not found — ingest may not have completed',
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
try {
|
|
59
|
+
cache = JSON.parse(readFileSync(cachePath, 'utf-8'));
|
|
60
|
+
passed.push('Cache file exists and is valid JSON');
|
|
61
|
+
} catch (e) {
|
|
62
|
+
issues.push(`Cache file is not valid JSON: ${e.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (cache) {
|
|
67
|
+
// ---- 2. Cache structure ----
|
|
68
|
+
if (!cache.version || !cache.timestamp || !cache.project) {
|
|
69
|
+
issues.push('Cache file missing required fields (version, timestamp, project)');
|
|
70
|
+
} else {
|
|
71
|
+
passed.push(`Cache: project="${cache.project}", version=${cache.version}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!cache.entries_created || !Array.isArray(cache.entries_created)) {
|
|
75
|
+
issues.push('Cache file missing entries_created array');
|
|
76
|
+
} else if (cache.entries_created.length === 0) {
|
|
77
|
+
issues.push('Cache entries_created is empty — no entries were created');
|
|
78
|
+
} else {
|
|
79
|
+
passed.push(`Cache lists ${cache.entries_created.length} entries created`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!cache.files || typeof cache.files !== 'object') {
|
|
83
|
+
issues.push('Cache file missing files object');
|
|
84
|
+
} else {
|
|
85
|
+
const fileCount = Object.keys(cache.files).length;
|
|
86
|
+
if (fileCount === 0) {
|
|
87
|
+
issues.push('Cache files object is empty — no files were tracked');
|
|
88
|
+
} else {
|
|
89
|
+
passed.push(`Cache tracks ${fileCount} files with SHA256 hashes`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---- 3. Entry existence ----
|
|
94
|
+
if (cache.entries_created && Array.isArray(cache.entries_created)) {
|
|
95
|
+
const missing = [];
|
|
96
|
+
const found = [];
|
|
97
|
+
for (const entry of cache.entries_created) {
|
|
98
|
+
const entryPath = join(args.knowledgeDir, entry.endsWith('.md') ? entry : entry + '.md');
|
|
99
|
+
if (existsSync(entryPath)) {
|
|
100
|
+
found.push(entry);
|
|
101
|
+
} else {
|
|
102
|
+
missing.push(entry);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (found.length > 0) {
|
|
106
|
+
passed.push(`${found.length}/${cache.entries_created.length} entries exist on disk`);
|
|
107
|
+
}
|
|
108
|
+
if (missing.length > 0) {
|
|
109
|
+
issues.push(
|
|
110
|
+
`${missing.length} entries listed in cache but missing on disk:\n${missing.map((e) => ' - ' + e).join('\n')}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ---- 4. Project entry ----
|
|
116
|
+
if (cache.project) {
|
|
117
|
+
const projectEntry = join(args.knowledgeDir, 'projects', cache.project + '.md');
|
|
118
|
+
if (existsSync(projectEntry)) {
|
|
119
|
+
passed.push(`Project entry exists: projects/${cache.project}.md`);
|
|
120
|
+
|
|
121
|
+
const content = readFileSync(projectEntry, 'utf-8');
|
|
122
|
+
if (!content.includes('---')) {
|
|
123
|
+
issues.push('Project entry missing YAML frontmatter');
|
|
124
|
+
}
|
|
125
|
+
if (content.length < 100) {
|
|
126
|
+
issues.push('Project entry seems too short (< 100 chars)');
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
issues.push(`Project entry missing: projects/${cache.project}.md`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ---- 5. File hash integrity ----
|
|
134
|
+
if (cache.files && typeof cache.files === 'object') {
|
|
135
|
+
let missingHashes = 0;
|
|
136
|
+
let missingEntryRefs = 0;
|
|
137
|
+
for (const [filePath, meta] of Object.entries(cache.files)) {
|
|
138
|
+
if (!meta.sha256 || typeof meta.sha256 !== 'string' || meta.sha256.length !== 64) {
|
|
139
|
+
missingHashes++;
|
|
140
|
+
}
|
|
141
|
+
if (!meta.entries || !Array.isArray(meta.entries) || meta.entries.length === 0) {
|
|
142
|
+
missingEntryRefs++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (missingHashes > 0) {
|
|
146
|
+
issues.push(`${missingHashes} files have invalid or missing SHA256 hashes`);
|
|
147
|
+
}
|
|
148
|
+
if (missingEntryRefs > 0) {
|
|
149
|
+
issues.push(`${missingEntryRefs} files have no entry references`);
|
|
150
|
+
}
|
|
151
|
+
if (missingHashes === 0 && missingEntryRefs === 0) {
|
|
152
|
+
passed.push('All file entries have valid SHA256 hashes and entry references');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---- Report ----
|
|
158
|
+
const report = {
|
|
159
|
+
target: args.targetPath,
|
|
160
|
+
knowledgeDir: args.knowledgeDir,
|
|
161
|
+
status: issues.length === 0 ? 'PASS' : 'FAIL',
|
|
162
|
+
passed,
|
|
163
|
+
issues,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
console.log(JSON.stringify(report, null, 2));
|
|
167
|
+
process.exit(issues.length === 0 ? 0 : 1);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
main();
|