@crafter/skillkit 0.2.0 → 0.2.2
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/package.json +1 -1
- package/src/bin.ts +4 -0
- package/src/commands/scan.ts +50 -2
- package/src/commands/stats.ts +24 -4
- package/src/scanner/connectors/claude.ts +52 -4
- package/src/scanner/index.ts +5 -2
package/package.json
CHANGED
package/src/bin.ts
CHANGED
|
@@ -24,6 +24,10 @@ function printHelp(): void {
|
|
|
24
24
|
${cyan("version")} Print version
|
|
25
25
|
${cyan("help")} Show this help message
|
|
26
26
|
|
|
27
|
+
${bold("FLAGS")}
|
|
28
|
+
${dim("scan")} ${cyan("--include-commands")} Also track slash commands (not just skills)
|
|
29
|
+
${dim("stats")} ${cyan("--days N")} Time range in days (default: 30)
|
|
30
|
+
|
|
27
31
|
${dim("Install skills via skills.sh: npx skills add <owner/repo>")}
|
|
28
32
|
`);
|
|
29
33
|
}
|
package/src/commands/scan.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
3
4
|
import { upsertInstalledSkill, deduplicateInvocations } from "../db/queries";
|
|
4
5
|
import { getDb } from "../db/schema";
|
|
5
6
|
import { countAllSessions, scanAllSessions } from "../scanner/index";
|
|
@@ -22,6 +23,7 @@ function detectSource(skillPath: string): "skills.sh" | "manual" {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export async function runScan(): Promise<void> {
|
|
26
|
+
const includeCommands = process.argv.includes("--include-commands");
|
|
25
27
|
const db = getDb();
|
|
26
28
|
|
|
27
29
|
const agents = getDetectedAgents();
|
|
@@ -86,6 +88,52 @@ export async function runScan(): Promise<void> {
|
|
|
86
88
|
} catch {}
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
const knownSkills = new Set<string>();
|
|
92
|
+
for (const skill of skills) {
|
|
93
|
+
knownSkills.add(skill.name);
|
|
94
|
+
knownSkills.add(basename(skill.path));
|
|
95
|
+
}
|
|
96
|
+
if (existsSync(localSkillsDir)) {
|
|
97
|
+
try {
|
|
98
|
+
for (const e of readdirSync(localSkillsDir)) {
|
|
99
|
+
try {
|
|
100
|
+
if (statSync(join(localSkillsDir, e)).isDirectory()) {
|
|
101
|
+
knownSkills.add(e);
|
|
102
|
+
}
|
|
103
|
+
} catch {}
|
|
104
|
+
}
|
|
105
|
+
} catch {}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (includeCommands) {
|
|
109
|
+
const commandDirs = [
|
|
110
|
+
join(process.cwd(), ".claude", "commands"),
|
|
111
|
+
join(homedir(), ".claude", "commands"),
|
|
112
|
+
];
|
|
113
|
+
let commandCount = 0;
|
|
114
|
+
for (const dir of commandDirs) {
|
|
115
|
+
if (!existsSync(dir)) continue;
|
|
116
|
+
try {
|
|
117
|
+
for (const e of readdirSync(dir)) {
|
|
118
|
+
if (e.endsWith(".md")) {
|
|
119
|
+
knownSkills.add(e.slice(0, -3));
|
|
120
|
+
commandCount++;
|
|
121
|
+
} else {
|
|
122
|
+
try {
|
|
123
|
+
if (statSync(join(dir, e)).isDirectory()) {
|
|
124
|
+
knownSkills.add(e);
|
|
125
|
+
commandCount++;
|
|
126
|
+
}
|
|
127
|
+
} catch {}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} catch {}
|
|
131
|
+
}
|
|
132
|
+
if (commandCount > 0) {
|
|
133
|
+
console.log(dim(` + ${commandCount} slash commands`));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
89
137
|
const removed = deduplicateInvocations(db);
|
|
90
138
|
if (removed > 0) {
|
|
91
139
|
console.log(` ${dim(`Cleaned ${removed} duplicate entries`)}`);
|
|
@@ -94,7 +142,7 @@ export async function runScan(): Promise<void> {
|
|
|
94
142
|
console.log(dim(" Scanning sessions..."));
|
|
95
143
|
|
|
96
144
|
const sessionCount = countAllSessions();
|
|
97
|
-
const newInvocations = await scanAllSessions(db);
|
|
145
|
+
const newInvocations = await scanAllSessions(db, knownSkills);
|
|
98
146
|
const totalRow = db
|
|
99
147
|
.query<{ count: number }, []>(
|
|
100
148
|
"SELECT COUNT(*) as count FROM skill_invocations",
|
package/src/commands/stats.ts
CHANGED
|
@@ -23,15 +23,32 @@ function getMostActiveDay(db: ReturnType<typeof getDb>): string {
|
|
|
23
23
|
return days[parseInt(row.day, 10)] ?? "N/A";
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function parseDays(args: string[]): number {
|
|
27
|
+
for (let i = 0; i < args.length; i++) {
|
|
28
|
+
if (args[i] === "--days" && args[i + 1]) {
|
|
29
|
+
const n = parseInt(args[i + 1], 10);
|
|
30
|
+
if (!isNaN(n) && n > 0) return n;
|
|
31
|
+
}
|
|
32
|
+
const match = args[i]?.match(/^--days=(\d+)$/);
|
|
33
|
+
if (match) {
|
|
34
|
+
const n = parseInt(match[1], 10);
|
|
35
|
+
if (!isNaN(n) && n > 0) return n;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return 30;
|
|
39
|
+
}
|
|
40
|
+
|
|
26
41
|
export async function runStats(): Promise<void> {
|
|
27
42
|
const db = getDb();
|
|
43
|
+
const days = parseDays(process.argv.slice(3));
|
|
44
|
+
|
|
28
45
|
console.log("\n Scanning sessions...");
|
|
29
46
|
const newCount = await scanAllSessions(db);
|
|
30
47
|
if (newCount > 0) {
|
|
31
48
|
console.log(` Found ${newCount} new invocations.\n`);
|
|
32
49
|
}
|
|
33
50
|
|
|
34
|
-
const stats = getSkillStats(db,
|
|
51
|
+
const stats = getSkillStats(db, days);
|
|
35
52
|
|
|
36
53
|
if (stats.total === 0) {
|
|
37
54
|
console.log(`\n ${yellow("No analytics data yet.")}`);
|
|
@@ -39,10 +56,13 @@ export async function runStats(): Promise<void> {
|
|
|
39
56
|
return;
|
|
40
57
|
}
|
|
41
58
|
|
|
42
|
-
const topSkills = getTopSkills(db,
|
|
59
|
+
const topSkills = getTopSkills(db, days);
|
|
43
60
|
const activeDay = getMostActiveDay(db);
|
|
44
61
|
|
|
45
|
-
|
|
62
|
+
const label =
|
|
63
|
+
days === 30 ? "last 30 days" : days === 7 ? "last 7 days" : `last ${days} days`;
|
|
64
|
+
|
|
65
|
+
console.log(`\n ${bold("SKILL-KIT ANALYTICS")} ${dim(`(${label})`)}\n`);
|
|
46
66
|
console.log(` Total invocations: ${bold(String(stats.total))}`);
|
|
47
67
|
console.log(` Unique skills: ${bold(String(stats.unique_skills))}`);
|
|
48
68
|
console.log(` Most active day: ${bold(activeDay)}\n`);
|
|
@@ -52,7 +72,7 @@ export async function runStats(): Promise<void> {
|
|
|
52
72
|
const barWidth = 20;
|
|
53
73
|
|
|
54
74
|
for (const skill of topSkills.slice(0, 10)) {
|
|
55
|
-
const daily = getDailyUsage(db, skill.skill_name,
|
|
75
|
+
const daily = getDailyUsage(db, skill.skill_name, days);
|
|
56
76
|
const filled = Math.round((skill.total / maxCount) * barWidth);
|
|
57
77
|
const bar = "█".repeat(filled);
|
|
58
78
|
const spark = sparkline(daily.map((d) => d.count));
|
|
@@ -19,7 +19,28 @@ function extractSkillName(block: ToolUseBlock): string | null {
|
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const COMMAND_NAME_RE = /<command-name>\/?([a-zA-Z][\w-]*(?::[\w-]*)*)<\/command-name>/g;
|
|
23
|
+
|
|
24
|
+
function extractCommandNames(
|
|
25
|
+
text: string,
|
|
26
|
+
knownSkills: Set<string>,
|
|
27
|
+
): string[] {
|
|
28
|
+
const names: string[] = [];
|
|
29
|
+
let match: RegExpExecArray | null;
|
|
30
|
+
while ((match = COMMAND_NAME_RE.exec(text)) !== null) {
|
|
31
|
+
const name = match[1];
|
|
32
|
+
if (knownSkills.has(name)) {
|
|
33
|
+
names.push(name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
COMMAND_NAME_RE.lastIndex = 0;
|
|
37
|
+
return names;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseSessionFile(
|
|
41
|
+
filePath: string,
|
|
42
|
+
knownSkills: Set<string> = new Set(),
|
|
43
|
+
): Invocation[] {
|
|
23
44
|
const results: Invocation[] = [];
|
|
24
45
|
const sessionId = basename(filePath, ".jsonl");
|
|
25
46
|
|
|
@@ -49,9 +70,35 @@ export function parseSessionFile(filePath: string): Invocation[] {
|
|
|
49
70
|
: new Date().toISOString();
|
|
50
71
|
|
|
51
72
|
const msg = obj.message as
|
|
52
|
-
| { content: Array<Record<string, unknown>> }
|
|
73
|
+
| { content: Array<Record<string, unknown>> | string }
|
|
53
74
|
| undefined;
|
|
54
|
-
|
|
75
|
+
|
|
76
|
+
if (obj.type === "user" && msg) {
|
|
77
|
+
const text =
|
|
78
|
+
typeof msg.content === "string"
|
|
79
|
+
? msg.content
|
|
80
|
+
: Array.isArray(msg.content)
|
|
81
|
+
? msg.content
|
|
82
|
+
.filter(
|
|
83
|
+
(b): b is { type: string; text: string } =>
|
|
84
|
+
typeof b === "object" &&
|
|
85
|
+
b !== null &&
|
|
86
|
+
b.type === "text" &&
|
|
87
|
+
typeof b.text === "string",
|
|
88
|
+
)
|
|
89
|
+
.map((b) => b.text)
|
|
90
|
+
.join("\n")
|
|
91
|
+
: "";
|
|
92
|
+
for (const name of extractCommandNames(text, knownSkills)) {
|
|
93
|
+
results.push({ skillName: name, timestamp, sessionId });
|
|
94
|
+
}
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const msgContent =
|
|
99
|
+
obj.type === "assistant" && msg && Array.isArray(msg.content)
|
|
100
|
+
? (msg.content as Array<Record<string, unknown>>)
|
|
101
|
+
: null;
|
|
55
102
|
|
|
56
103
|
if (!Array.isArray(msgContent)) continue;
|
|
57
104
|
|
|
@@ -88,6 +135,7 @@ export function countClaudeSessions(): number {
|
|
|
88
135
|
export async function scanClaudeSessions(
|
|
89
136
|
db: Database,
|
|
90
137
|
trackedSet: Set<string>,
|
|
138
|
+
knownSkills: Set<string> = new Set(),
|
|
91
139
|
): Promise<number> {
|
|
92
140
|
const projectsDir = join(homedir(), ".claude", "projects");
|
|
93
141
|
if (!existsSync(projectsDir)) return 0;
|
|
@@ -101,7 +149,7 @@ export async function scanClaudeSessions(
|
|
|
101
149
|
|
|
102
150
|
let total = 0;
|
|
103
151
|
for (const file of files) {
|
|
104
|
-
const invocations = parseSessionFile(file);
|
|
152
|
+
const invocations = parseSessionFile(file, knownSkills);
|
|
105
153
|
total += recordNewInvocations(db, trackedSet, invocations);
|
|
106
154
|
}
|
|
107
155
|
|
package/src/scanner/index.ts
CHANGED
|
@@ -43,10 +43,13 @@ export function recordNewInvocations(
|
|
|
43
43
|
return count;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export async function scanAllSessions(
|
|
46
|
+
export async function scanAllSessions(
|
|
47
|
+
db: Database,
|
|
48
|
+
knownSkills: Set<string> = new Set(),
|
|
49
|
+
): Promise<number> {
|
|
47
50
|
const trackedSet = getTrackedSet(db);
|
|
48
51
|
let total = 0;
|
|
49
|
-
total += await scanClaudeSessions(db, trackedSet);
|
|
52
|
+
total += await scanClaudeSessions(db, trackedSet, knownSkills);
|
|
50
53
|
total += scanOpenCodeSessions(db, trackedSet);
|
|
51
54
|
return total;
|
|
52
55
|
}
|