promptgraph-mcp 2.0.6 → 2.0.8
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/config.js +58 -59
- package/github-import.js +7 -1
- package/indexer.js +23 -17
- package/package.json +1 -1
- package/parser.js +3 -6
package/config.js
CHANGED
|
@@ -1,59 +1,58 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import os from 'os';
|
|
4
|
-
import readline from 'readline';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{ dir: path.join(
|
|
14
|
-
{ dir: path.join(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
fs.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import readline from 'readline';
|
|
5
|
+
|
|
6
|
+
const CLAUDE_DIR = path.join(os.homedir(), '.claude');
|
|
7
|
+
export const PROMPTGRAPH_DIR = path.join(CLAUDE_DIR, '.promptgraph');
|
|
8
|
+
export const SKILLS_STORE_DIR = path.join(CLAUDE_DIR, 'skills-store');
|
|
9
|
+
const CONFIG_PATH = path.join(PROMPTGRAPH_DIR, 'config.json');
|
|
10
|
+
|
|
11
|
+
const DEFAULTS = {
|
|
12
|
+
sources: [
|
|
13
|
+
{ dir: path.join(CLAUDE_DIR, 'skills-store'), source: 'skills-store' },
|
|
14
|
+
{ dir: path.join(CLAUDE_DIR, 'skills'), source: 'skills' },
|
|
15
|
+
{ dir: path.join(CLAUDE_DIR, 'commands'), source: 'commands' },
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export function loadConfig() {
|
|
21
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
22
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
23
|
+
}
|
|
24
|
+
return JSON.parse(JSON.stringify(DEFAULTS));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function saveConfig(config) {
|
|
28
|
+
fs.mkdirSync(path.dirname(CONFIG_PATH), { recursive: true });
|
|
29
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function promptConfig() {
|
|
33
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
34
|
+
const ask = (q) => new Promise(r => rl.question(q, r));
|
|
35
|
+
|
|
36
|
+
console.log('\n=== PromptGraph Setup ===\n');
|
|
37
|
+
console.log('Default skill directories:');
|
|
38
|
+
DEFAULTS.sources.forEach((s, i) => console.log(` ${i + 1}. ${s.dir}`));
|
|
39
|
+
|
|
40
|
+
const extra = await ask('\nAdd extra skill directories? (comma-separated paths, or press Enter to skip): ');
|
|
41
|
+
rl.close();
|
|
42
|
+
|
|
43
|
+
const config = structuredClone(DEFAULTS);
|
|
44
|
+
|
|
45
|
+
if (extra.trim()) {
|
|
46
|
+
const extraDirs = extra.split(',').map(d => d.trim()).filter(Boolean);
|
|
47
|
+
for (const dir of extraDirs) {
|
|
48
|
+
const base = path.basename(path.resolve(dir));
|
|
49
|
+
const existing = config.sources.filter(s => s.source === `custom:${base}`);
|
|
50
|
+
const tag = existing.length === 0 ? `custom:${base}` : `custom:${base}-${existing.length}`;
|
|
51
|
+
config.sources.push({ dir, source: tag });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
saveConfig(config);
|
|
56
|
+
console.log(`\nConfig saved to ${CONFIG_PATH}`);
|
|
57
|
+
return config;
|
|
58
|
+
}
|
package/github-import.js
CHANGED
|
@@ -58,7 +58,13 @@ export async function importFromGitHub(repoUrl) {
|
|
|
58
58
|
if (fs.existsSync(dest)) {
|
|
59
59
|
console.log(`Updating ${repoName}...`);
|
|
60
60
|
const pullResult = spawnSync('git', ['-C', dest, 'pull', '--depth=1'], { stdio: 'inherit' });
|
|
61
|
-
if (pullResult.status !== 0)
|
|
61
|
+
if (pullResult.status !== 0) {
|
|
62
|
+
// Force-push or unrelated histories — re-clone from scratch
|
|
63
|
+
console.log(`Pull failed (force-push?), re-cloning ${repoName}...`);
|
|
64
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
65
|
+
const cloneResult = spawnSync('git', ['clone', '--depth=1', url, dest], { stdio: 'inherit' });
|
|
66
|
+
if (cloneResult.status !== 0) throw new Error(`git clone failed for ${url}`);
|
|
67
|
+
}
|
|
62
68
|
} else {
|
|
63
69
|
console.log(`Cloning ${url}...`);
|
|
64
70
|
const cloneResult = spawnSync('git', ['clone', '--depth=1', url, dest], { stdio: 'inherit' });
|
package/indexer.js
CHANGED
|
@@ -11,11 +11,6 @@ import { buildAnnIndex } from './ann.js';
|
|
|
11
11
|
import { progress, progressDone, success, info, spinner } from './cli.js';
|
|
12
12
|
import chalk from 'chalk';
|
|
13
13
|
|
|
14
|
-
function fileHash(filePath) {
|
|
15
|
-
const content = fs.readFileSync(filePath);
|
|
16
|
-
return createHash('md5').update(content).digest('hex');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
14
|
async function indexBatch(db, skills) {
|
|
20
15
|
const upsertSkill = db.prepare(`
|
|
21
16
|
INSERT INTO skills (id, name, description, path, source, content, hash)
|
|
@@ -132,26 +127,37 @@ export async function indexAll() {
|
|
|
132
127
|
let skipped = 0;
|
|
133
128
|
let batch = [];
|
|
134
129
|
const start = Date.now();
|
|
135
|
-
|
|
130
|
+
|
|
131
|
+
// Build a path→{hash,id} map from DB for O(1) lookups
|
|
132
|
+
const dbByPath = new Map();
|
|
133
|
+
for (const row of db.prepare('SELECT id, path, hash FROM skills').all()) {
|
|
134
|
+
dbByPath.set(row.path, row);
|
|
135
|
+
}
|
|
136
136
|
|
|
137
137
|
for (const { file, source } of allFiles) {
|
|
138
138
|
try {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
// 1. Read file once
|
|
140
|
+
let raw;
|
|
141
|
+
try { raw = fs.readFileSync(file, 'utf8'); } catch { skipped++; count++; continue; }
|
|
142
|
+
|
|
143
|
+
// 2. Hash first — cheapest check
|
|
144
|
+
const hash = createHash('md5').update(raw).digest('hex');
|
|
145
|
+
|
|
146
|
+
// 3. If path already in DB with same hash → skip without parsing
|
|
147
|
+
const dbRow = dbByPath.get(file);
|
|
148
|
+
if (dbRow?.hash === hash) {
|
|
149
|
+
skipped++; count++;
|
|
150
|
+
if (count % 200 === 0) {
|
|
151
|
+
const eta = Math.round((total - count) * (Date.now() - start) / count / 1000);
|
|
150
152
|
progress(count, total, { skipped, eta, errors });
|
|
151
153
|
}
|
|
152
154
|
continue;
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
// 4. Only now check if it's a real skill (content already in memory)
|
|
158
|
+
if (!isSkillFile(file, raw)) { skipped++; count++; continue; }
|
|
159
|
+
|
|
160
|
+
const parsed = parseSkillFile(file, source, { raw });
|
|
155
161
|
batch.push({ ...parsed, hash });
|
|
156
162
|
|
|
157
163
|
if (batch.length >= BATCH_SIZE) {
|
package/package.json
CHANGED
package/parser.js
CHANGED
|
@@ -26,21 +26,18 @@ const SKIP_DIRS = new Set([
|
|
|
26
26
|
'node_modules', 'vendor', 'third_party',
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
|
-
export function isSkillFile(filePath) {
|
|
29
|
+
export function isSkillFile(filePath, raw) {
|
|
30
30
|
const parts = filePath.replace(/\\/g, '/').split('/');
|
|
31
31
|
const base = parts[parts.length - 1].replace(/\.md$/i, '').toLowerCase();
|
|
32
32
|
|
|
33
|
-
// Skip by filename
|
|
34
33
|
if (SKIP_FILENAMES.has(base)) return false;
|
|
35
34
|
|
|
36
|
-
// Skip if any parent directory is in the skip list
|
|
37
35
|
for (const part of parts.slice(0, -1)) {
|
|
38
36
|
if (SKIP_DIRS.has(part.toLowerCase())) return false;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
// Read and check content quality
|
|
42
39
|
try {
|
|
43
|
-
|
|
40
|
+
if (!raw) raw = fs.readFileSync(filePath, 'utf8');
|
|
44
41
|
|
|
45
42
|
// Too short to be a real skill
|
|
46
43
|
if (raw.length < 150) return false;
|
|
@@ -67,7 +64,7 @@ export function isSkillFile(filePath) {
|
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
export function parseSkillFile(filePath, source, opts = {}) {
|
|
70
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
67
|
+
const raw = opts.raw ?? fs.readFileSync(filePath, 'utf8');
|
|
71
68
|
|
|
72
69
|
let name, description, content;
|
|
73
70
|
|