-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.ts
More file actions
28 lines (27 loc) · 1.19 KB
/
Copy pathextract.ts
File metadata and controls
28 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export type InvocationCounts = Record<string, number>
// Parses the output of scripts/grep-skill-usage.sh: lines like
// ` 3 skill: superpowers:brainstorming"` (from grepping the Skill tool's
// input JSON) and ` 2 /clear` (from grepping <command-name> tags).
export function parseSkillUsage(text: string): InvocationCounts {
const counts: InvocationCounts = {}
for (const line of text.split('\n')) {
const skillMatch = /^\s*(\d+)\s+skill:\s*([a-zA-Z0-9_.:-]+)/.exec(line)
if (skillMatch) {
const [, n, name] = skillMatch
counts[name] = (counts[name] ?? 0) + Number(n)
continue
}
const cmdMatch = /^\s*(\d+)\s+\/([a-zA-Z0-9_:-]+)/.exec(line)
if (cmdMatch) {
const [, n, name] = cmdMatch
// A namespaced invocation (e.g. /cronjobs:cronjob) already matches the
// `plugin:skill` gene-key convention the Skill-tool branch above uses —
// route it there directly. A bare command (e.g. /clear) has no plugin
// namespace, so it gets the slash: prefix to avoid colliding with a
// same-named gene key.
const key = name.includes(':') ? name : `slash:${name}`
counts[key] = (counts[key] ?? 0) + Number(n)
}
}
return counts
}