skilltally 1.0.1 → 1.0.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +12 -0
- package/bin/cli.mjs +1 -1
- package/bin/track.mjs +89 -18
- package/gemini-extension.json +1 -1
- package/hooks/claude-codex-hooks.json +14 -1
- package/hooks.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/src/backfill/antigravity.mjs +46 -3
- package/src/backfill/claude.mjs +38 -4
- package/src/backfill/codex.mjs +60 -8
- package/src/backfill/gemini.mjs +7 -1
- package/src/install/antigravity.mjs +2 -2
- package/src/install/claude.mjs +1 -1
- package/src/install/codex.mjs +63 -32
- package/src/install/doctor.mjs +2 -2
- package/src/install/gemini.mjs +1 -1
- package/src/install/runtime.mjs +33 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.2] - 2026-11-19
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Realtime `UserPromptSubmit` hook and `<skill>` / `[$skill](.../SKILL.md)` backfill detection for Codex explicit `$skill` invocations (`via: "mention"`).
|
|
12
|
+
- Expanded hook matchers and backfill parsers across all 4 providers:
|
|
13
|
+
- **Antigravity**: added `run_command` to `PostToolUse` matcher and fallback `<SKILL>` slash-command detection in `backfillAntigravity`.
|
|
14
|
+
- **Claude Code**: added `View|Bash` to `PostToolUse` matcher and `Base directory for this skill:` slash-command detection in `backfillClaude`.
|
|
15
|
+
- **Gemini CLI**: added `read_file|view_file|read_many_files|run_shell_command` to `AfterTool` matcher and `read_many_files` array path support.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- Verify trust status across both `post_tool_use` and `user_prompt_submit` hook indices in `~/.codex/config.toml` and clean up all hook events on `uninstall`.
|
|
19
|
+
|
|
8
20
|
## [1.0.1] - 2026-11-19
|
|
9
21
|
|
|
10
22
|
### Fixed
|
package/bin/cli.mjs
CHANGED
package/bin/track.mjs
CHANGED
|
@@ -17,8 +17,17 @@ import { fileURLToPath } from 'node:url';
|
|
|
17
17
|
export const SKILL_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
18
18
|
export const SKILL_PATH_RE =
|
|
19
19
|
/((?:[A-Za-z]:|~)?[^\s"'`<>|;(){}\[\]]*?[\\/]skills[\\/]([A-Za-z0-9][A-Za-z0-9._-]{0,127})[\\/]SKILL\.md)(?=$|[\s"'`<>|;),}\]])/gi;
|
|
20
|
+
const EXPLICIT_SKILL_LINK_RE =
|
|
21
|
+
/\[[\$@\/]?([A-Za-z0-9][A-Za-z0-9._-]{0,127})\]\(([^()\s]*?[\\/]skills[\\/][A-Za-z0-9][A-Za-z0-9._-]{0,127}[\\/]SKILL\.md)\)/gi;
|
|
22
|
+
const CODEX_SKILL_TAG_RE =
|
|
23
|
+
/<skill>\s*<name>([^<\r\n]+)<\/name>\s*<path>([^<\r\n]*?[\\/]SKILL\.md)<\/path>/gi;
|
|
24
|
+
const AGY_SKILL_TAG_RE =
|
|
25
|
+
/<SKILL>[\s\S]*?read and use the "([^"]+)" skill\.\s*The path to the skill file is:\s*([^\s<]+?[\\/]SKILL\.md)\s*<\/SKILL>/gi;
|
|
26
|
+
const CLAUDE_SKILL_BASEDIR_RE =
|
|
27
|
+
/Base directory for this skill:\s*([^\r\n<]+?[\\/]skills[\\/]([A-Za-z0-9][A-Za-z0-9._-]{0,127}))\/?(?=\r?\n|$|<)/gi;
|
|
20
28
|
|
|
21
29
|
const PATH_KEYS = ['Path', 'AbsolutePath', 'TargetFile', 'file_path', 'path', 'absolute_path'];
|
|
30
|
+
const ARRAY_PATH_KEYS = ['paths', 'include', 'files'];
|
|
22
31
|
const CMD_KEYS = ['CommandLine', 'command', 'cmd', 'input', 'argv'];
|
|
23
32
|
const WRITE_TOOL_RE = /^(write|edit|replace|apply_patch|multiedit|notebookedit|create_file|delete_file)/i;
|
|
24
33
|
const READ_CMD_RE = /^(cat|sed|head|tail|less|more|bat|nl|awk|type|Get-Content)\b/i;
|
|
@@ -56,7 +65,13 @@ export function resolveHost(hostFlag, payload, env = process.env) {
|
|
|
56
65
|
return hostFlag;
|
|
57
66
|
}
|
|
58
67
|
if (payload?.toolCall) return refineAntigravityHost(payload);
|
|
59
|
-
if (
|
|
68
|
+
if (
|
|
69
|
+
payload?.hook_event_name === 'AfterTool' ||
|
|
70
|
+
payload?.hook_event_name === 'BeforeAgent' ||
|
|
71
|
+
env.GEMINI_PROJECT_DIR
|
|
72
|
+
) {
|
|
73
|
+
return 'gemini';
|
|
74
|
+
}
|
|
60
75
|
const tp = String(payload?.transcript_path ?? '');
|
|
61
76
|
if (
|
|
62
77
|
env.CODEX_THREAD_ID ||
|
|
@@ -91,10 +106,22 @@ export function normalizeHookPayload(host, payload) {
|
|
|
91
106
|
Boolean(p.error) ||
|
|
92
107
|
resp?.is_error === true ||
|
|
93
108
|
(typeof resp?.exit_code === 'number' && resp.exit_code !== 0);
|
|
109
|
+
const prompt =
|
|
110
|
+
typeof p.prompt === 'string'
|
|
111
|
+
? p.prompt
|
|
112
|
+
: typeof p.user_prompt === 'string'
|
|
113
|
+
? p.user_prompt
|
|
114
|
+
: typeof p.userMessage === 'string'
|
|
115
|
+
? p.userMessage
|
|
116
|
+
: undefined;
|
|
117
|
+
const hookEvent = p.hook_event_name ?? p.hookEventName;
|
|
94
118
|
return {
|
|
95
|
-
tool:
|
|
119
|
+
tool:
|
|
120
|
+
p.tool_name ??
|
|
121
|
+
(hookEvent === 'UserPromptSubmit' || hookEvent === 'BeforeAgent' ? hookEvent : undefined),
|
|
96
122
|
args: p.tool_input ?? {},
|
|
97
|
-
|
|
123
|
+
...(prompt !== undefined ? { prompt } : {}),
|
|
124
|
+
callId: p.tool_use_id ?? p.call_id ?? p.turn_id ?? p.prompt_id,
|
|
98
125
|
sessionId: p.session_id,
|
|
99
126
|
cwd: p.cwd,
|
|
100
127
|
model: p.model,
|
|
@@ -153,7 +180,14 @@ function extractCodexCommandStrings(text) {
|
|
|
153
180
|
return extracted.length > 0 ? extracted : [text];
|
|
154
181
|
}
|
|
155
182
|
|
|
156
|
-
export function detectSkillCalls({
|
|
183
|
+
export function detectSkillCalls({
|
|
184
|
+
tool,
|
|
185
|
+
args,
|
|
186
|
+
prompt,
|
|
187
|
+
cwd = '',
|
|
188
|
+
homeDir = homedir(),
|
|
189
|
+
allowShell = true,
|
|
190
|
+
}) {
|
|
157
191
|
const safeArgs = args && typeof args === 'object' ? args : {};
|
|
158
192
|
|
|
159
193
|
if (tool === 'Skill' && safeArgs.skill) {
|
|
@@ -178,26 +212,54 @@ export function detectSkillCalls({ tool, args, cwd = '', homeDir = homedir(), al
|
|
|
178
212
|
}
|
|
179
213
|
}
|
|
180
214
|
|
|
181
|
-
if (WRITE_TOOL_RE.test(tool ?? '')) return [];
|
|
182
|
-
|
|
183
215
|
const hits = [];
|
|
184
216
|
const seenPaths = new Set();
|
|
185
217
|
|
|
218
|
+
const pushPathHit = (skill, skillPath, via) => {
|
|
219
|
+
const cleanSkill = String(skill || '').trim();
|
|
220
|
+
const cleanPath = String(skillPath || '').trim();
|
|
221
|
+
if (!cleanSkill || !cleanPath) return;
|
|
222
|
+
const normKey = cleanPath.replace(/\\/g, '/');
|
|
223
|
+
if (seenPaths.has(normKey)) return;
|
|
224
|
+
seenPaths.add(normKey);
|
|
225
|
+
hits.push({
|
|
226
|
+
skill: cleanSkill,
|
|
227
|
+
skill_path: cleanPath,
|
|
228
|
+
source: resolveSource(cleanPath, cwd, homeDir),
|
|
229
|
+
via,
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
if (typeof prompt === 'string' && prompt.trim()) {
|
|
234
|
+
CODEX_SKILL_TAG_RE.lastIndex = 0;
|
|
235
|
+
for (const m of prompt.matchAll(CODEX_SKILL_TAG_RE)) {
|
|
236
|
+
pushPathHit(m[1], m[2], 'mention');
|
|
237
|
+
}
|
|
238
|
+
EXPLICIT_SKILL_LINK_RE.lastIndex = 0;
|
|
239
|
+
for (const m of prompt.matchAll(EXPLICIT_SKILL_LINK_RE)) {
|
|
240
|
+
pushPathHit(m[1], m[2], 'mention');
|
|
241
|
+
}
|
|
242
|
+
AGY_SKILL_TAG_RE.lastIndex = 0;
|
|
243
|
+
for (const m of prompt.matchAll(AGY_SKILL_TAG_RE)) {
|
|
244
|
+
pushPathHit(m[1], m[2], 'slash_command');
|
|
245
|
+
}
|
|
246
|
+
CLAUDE_SKILL_BASEDIR_RE.lastIndex = 0;
|
|
247
|
+
for (const m of prompt.matchAll(CLAUDE_SKILL_BASEDIR_RE)) {
|
|
248
|
+
const baseDir = m[1].trim().replace(/[\\/]+$/, '');
|
|
249
|
+
pushPathHit(m[2], `${baseDir}/SKILL.md`, 'slash_command');
|
|
250
|
+
}
|
|
251
|
+
if (hits.length > 0 && (!tool || tool === 'UserPromptSubmit' || tool === 'BeforeAgent' || tool === 'USER_INPUT')) {
|
|
252
|
+
return hits;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (WRITE_TOOL_RE.test(tool ?? '')) return hits;
|
|
257
|
+
|
|
186
258
|
const collectFromText = (text, via) => {
|
|
187
259
|
if (!text.toLowerCase().includes('skill.md')) return;
|
|
188
260
|
SKILL_PATH_RE.lastIndex = 0;
|
|
189
261
|
for (const m of text.matchAll(SKILL_PATH_RE)) {
|
|
190
|
-
|
|
191
|
-
const skill = m[2];
|
|
192
|
-
const normKey = skillPath.replace(/\\/g, '/');
|
|
193
|
-
if (seenPaths.has(normKey)) continue;
|
|
194
|
-
seenPaths.add(normKey);
|
|
195
|
-
hits.push({
|
|
196
|
-
skill,
|
|
197
|
-
skill_path: skillPath,
|
|
198
|
-
source: resolveSource(skillPath, cwd, homeDir),
|
|
199
|
-
via,
|
|
200
|
-
});
|
|
262
|
+
pushPathHit(m[2], m[1], via);
|
|
201
263
|
}
|
|
202
264
|
};
|
|
203
265
|
|
|
@@ -206,6 +268,15 @@ export function detectSkillCalls({ tool, args, cwd = '', homeDir = homedir(), al
|
|
|
206
268
|
collectFromText(unwrapArg(safeArgs[key]), 'read');
|
|
207
269
|
}
|
|
208
270
|
}
|
|
271
|
+
for (const key of ARRAY_PATH_KEYS) {
|
|
272
|
+
if (Array.isArray(safeArgs[key])) {
|
|
273
|
+
for (const item of safeArgs[key]) {
|
|
274
|
+
if (typeof item === 'string' && !item.includes('*')) {
|
|
275
|
+
collectFromText(unwrapArg(item), 'read');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
209
280
|
if (hits.length > 0) return hits;
|
|
210
281
|
|
|
211
282
|
if (!allowShell) return [];
|
|
@@ -280,7 +351,7 @@ export function main() {
|
|
|
280
351
|
const payload = JSON.parse(raw);
|
|
281
352
|
const host = resolveHost(hostFlag, payload);
|
|
282
353
|
const n = normalizeHookPayload(host, payload);
|
|
283
|
-
const hits = detectSkillCalls({ tool: n.tool, args: n.args, cwd: n.cwd });
|
|
354
|
+
const hits = detectSkillCalls({ tool: n.tool, args: n.args, prompt: n.prompt, cwd: n.cwd });
|
|
284
355
|
if (hits.length === 0) return;
|
|
285
356
|
|
|
286
357
|
mkdirSync(home, { recursive: true, mode: 0o700 });
|
package/gemini-extension.json
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
"hooks": {
|
|
3
3
|
"PostToolUse": [
|
|
4
4
|
{
|
|
5
|
-
"matcher": "Skill|Read|Bash|exec|exec_command|shell|shell_command|local_shell",
|
|
5
|
+
"matcher": "Skill|Read|View|Bash|exec|exec_command|shell|shell_command|local_shell|read_file|view_file",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/bin/track.mjs\" --host auto",
|
|
10
|
+
"async": true,
|
|
11
|
+
"timeout": 5,
|
|
12
|
+
"statusMessage": "skilltally"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"UserPromptSubmit": [
|
|
18
|
+
{
|
|
6
19
|
"hooks": [
|
|
7
20
|
{
|
|
8
21
|
"type": "command",
|
package/hooks.json
CHANGED
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "skilltally",
|
|
3
3
|
"displayName": "SkillTally",
|
|
4
4
|
"description": "Real-time skill usage tracking via hooks for Antigravity, Claude Code, Codex & Gemini CLI. See which skills you actually use and which eat context.",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "112516101106",
|
|
8
8
|
"url": "https://github.com/112516101106"
|
|
@@ -80,6 +80,8 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
80
80
|
|
|
81
81
|
const lines = raw.split('\n');
|
|
82
82
|
const fullCache = { lines: undefined };
|
|
83
|
+
const convEvents = [];
|
|
84
|
+
const pendingUserSkills = [];
|
|
83
85
|
|
|
84
86
|
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
85
87
|
const line = lines[lineIdx];
|
|
@@ -93,6 +95,41 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
93
95
|
continue;
|
|
94
96
|
}
|
|
95
97
|
|
|
98
|
+
const ts = obj.created_at;
|
|
99
|
+
const stepIdx = obj.step_index ?? lineIdx;
|
|
100
|
+
|
|
101
|
+
if (obj.type === 'USER_INPUT' && typeof obj.content === 'string' && obj.content.includes('<SKILL>')) {
|
|
102
|
+
if (sinceMs !== null && ts) {
|
|
103
|
+
const tsMs = Date.parse(ts);
|
|
104
|
+
if (Number.isFinite(tsMs) && tsMs < sinceMs) continue;
|
|
105
|
+
}
|
|
106
|
+
const promptHits = detectSkillCalls({
|
|
107
|
+
tool: 'USER_INPUT',
|
|
108
|
+
args: {},
|
|
109
|
+
prompt: obj.content,
|
|
110
|
+
cwd: '',
|
|
111
|
+
homeDir,
|
|
112
|
+
allowShell: false,
|
|
113
|
+
});
|
|
114
|
+
promptHits.forEach((h, hitIdx) => {
|
|
115
|
+
pendingUserSkills.push({
|
|
116
|
+
v: 1,
|
|
117
|
+
id: `${item.host}:${item.sessionId}:${stepIdx}#${hitIdx}`,
|
|
118
|
+
ts: ts || new Date(0).toISOString(),
|
|
119
|
+
host: item.host,
|
|
120
|
+
skill: h.skill,
|
|
121
|
+
...(h.skill_path ? { skill_path: h.skill_path } : {}),
|
|
122
|
+
source: h.source,
|
|
123
|
+
via: h.via,
|
|
124
|
+
tool: 'USER_INPUT',
|
|
125
|
+
session_id: item.sessionId,
|
|
126
|
+
origin: 'backfill',
|
|
127
|
+
ok: obj.status !== 'ERROR',
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
96
133
|
if (Array.isArray(obj.truncated_fields) && obj.truncated_fields.includes('tool_calls')) {
|
|
97
134
|
const fullObj = loadFullRecord(fullCache, item.fullPath, lineIdx, obj.step_index);
|
|
98
135
|
if (fullObj) obj = fullObj;
|
|
@@ -101,13 +138,11 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
101
138
|
const toolCalls = obj.tool_calls;
|
|
102
139
|
if (!Array.isArray(toolCalls) || toolCalls.length === 0) continue;
|
|
103
140
|
|
|
104
|
-
const ts = obj.created_at;
|
|
105
141
|
if (sinceMs !== null && ts) {
|
|
106
142
|
const tsMs = Date.parse(ts);
|
|
107
143
|
if (Number.isFinite(tsMs) && tsMs < sinceMs) continue;
|
|
108
144
|
}
|
|
109
145
|
|
|
110
|
-
const stepIdx = obj.step_index ?? lineIdx;
|
|
111
146
|
let stepHitIdx = 0;
|
|
112
147
|
|
|
113
148
|
for (const tc of toolCalls) {
|
|
@@ -123,7 +158,7 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
123
158
|
allowShell: true,
|
|
124
159
|
});
|
|
125
160
|
for (const h of hits) {
|
|
126
|
-
|
|
161
|
+
convEvents.push({
|
|
127
162
|
v: 1,
|
|
128
163
|
id: `${item.host}:${item.sessionId}:${stepIdx}#${stepHitIdx++}`,
|
|
129
164
|
ts: ts || new Date(0).toISOString(),
|
|
@@ -141,6 +176,14 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
141
176
|
}
|
|
142
177
|
}
|
|
143
178
|
}
|
|
179
|
+
|
|
180
|
+
const readSkillSet = new Set(convEvents.map((e) => e.skill));
|
|
181
|
+
for (const uEv of pendingUserSkills) {
|
|
182
|
+
if (!readSkillSet.has(uEv.skill)) {
|
|
183
|
+
convEvents.push(uEv);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
events.push(...convEvents);
|
|
144
187
|
}
|
|
145
188
|
|
|
146
189
|
return {
|
package/src/backfill/claude.mjs
CHANGED
|
@@ -37,7 +37,7 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
37
37
|
} catch {
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
|
-
if (!raw || (!raw.includes('"Skill"') && !raw.includes('SKILL.md'))) continue;
|
|
40
|
+
if (!raw || (!raw.includes('"Skill"') && !raw.includes('SKILL.md') && !raw.includes('Base directory for this skill:'))) continue;
|
|
41
41
|
|
|
42
42
|
let sessionId = basename(file, '.jsonl');
|
|
43
43
|
let cwd = '';
|
|
@@ -57,17 +57,50 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
57
57
|
if (obj.cwd) cwd = obj.cwd;
|
|
58
58
|
|
|
59
59
|
const content = obj.message?.content;
|
|
60
|
-
if (!Array.isArray(content)) continue;
|
|
61
|
-
|
|
62
60
|
if (obj.type === 'user') {
|
|
61
|
+
if (typeof content === 'string') {
|
|
62
|
+
if (content.includes('Base directory for this skill:') || content.includes('SKILL.md') || content.includes('<skill>')) {
|
|
63
|
+
pendingCalls.push({
|
|
64
|
+
idx: pendingCalls.length,
|
|
65
|
+
ts: obj.timestamp,
|
|
66
|
+
tool: 'UserPromptSubmit',
|
|
67
|
+
callId: obj.uuid || `user_${pendingCalls.length}`,
|
|
68
|
+
input: {},
|
|
69
|
+
prompt: content,
|
|
70
|
+
cwd,
|
|
71
|
+
model: undefined,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (!Array.isArray(content)) continue;
|
|
63
77
|
for (const block of content) {
|
|
64
78
|
if (block?.type === 'tool_result' && block.is_error === true && block.tool_use_id) {
|
|
65
79
|
failedIds.add(block.tool_use_id);
|
|
80
|
+
} else if (
|
|
81
|
+
block?.type === 'text' &&
|
|
82
|
+
typeof block.text === 'string' &&
|
|
83
|
+
(block.text.includes('Base directory for this skill:') ||
|
|
84
|
+
block.text.includes('SKILL.md') ||
|
|
85
|
+
block.text.includes('<skill>'))
|
|
86
|
+
) {
|
|
87
|
+
pendingCalls.push({
|
|
88
|
+
idx: pendingCalls.length,
|
|
89
|
+
ts: obj.timestamp,
|
|
90
|
+
tool: 'UserPromptSubmit',
|
|
91
|
+
callId: obj.uuid || `user_${pendingCalls.length}`,
|
|
92
|
+
input: {},
|
|
93
|
+
prompt: block.text,
|
|
94
|
+
cwd,
|
|
95
|
+
model: undefined,
|
|
96
|
+
});
|
|
66
97
|
}
|
|
67
98
|
}
|
|
68
99
|
continue;
|
|
69
100
|
}
|
|
70
101
|
|
|
102
|
+
if (!Array.isArray(content)) continue;
|
|
103
|
+
|
|
71
104
|
if (obj.type !== 'assistant') continue;
|
|
72
105
|
const model = obj.message?.model;
|
|
73
106
|
|
|
@@ -94,9 +127,10 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
94
127
|
const hits = detectSkillCalls({
|
|
95
128
|
tool: call.tool,
|
|
96
129
|
args: call.input,
|
|
130
|
+
prompt: call.prompt,
|
|
97
131
|
cwd: call.cwd,
|
|
98
132
|
homeDir,
|
|
99
|
-
allowShell:
|
|
133
|
+
allowShell: call.tool !== 'UserPromptSubmit',
|
|
100
134
|
});
|
|
101
135
|
|
|
102
136
|
const ok = call.callId ? !failedIds.has(call.callId) : true;
|
package/src/backfill/codex.mjs
CHANGED
|
@@ -86,7 +86,7 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
86
86
|
continue;
|
|
87
87
|
}
|
|
88
88
|
const raw = readRes.text;
|
|
89
|
-
if (!raw || !raw.includes('SKILL.md')) continue;
|
|
89
|
+
if (!raw || (!raw.includes('SKILL.md') && !raw.includes('<skill>'))) continue;
|
|
90
90
|
|
|
91
91
|
let sessionId = sessionIdFromFilename(file);
|
|
92
92
|
let cwd = '';
|
|
@@ -94,6 +94,8 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
94
94
|
|
|
95
95
|
const pendingCalls = [];
|
|
96
96
|
const failedCalls = new Set();
|
|
97
|
+
let turnIdx = 0;
|
|
98
|
+
const turnPromptSkills = new Set();
|
|
97
99
|
|
|
98
100
|
for (const line of raw.split('\n')) {
|
|
99
101
|
if (!line) continue;
|
|
@@ -115,12 +117,59 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
115
117
|
if (obj.type === 'turn_context' && obj.payload) {
|
|
116
118
|
if (obj.payload.cwd) cwd = obj.payload.cwd;
|
|
117
119
|
if (obj.payload.model) model = obj.payload.model;
|
|
120
|
+
turnPromptSkills.clear();
|
|
121
|
+
turnIdx += 1;
|
|
118
122
|
continue;
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
if (obj.type !== 'response_item' || !obj.payload) continue;
|
|
122
126
|
const p = obj.payload;
|
|
123
127
|
|
|
128
|
+
if (p.type === 'message' && p.role === 'user' && Array.isArray(p.content)) {
|
|
129
|
+
for (const part of p.content) {
|
|
130
|
+
const text = part?.text;
|
|
131
|
+
if (
|
|
132
|
+
typeof text !== 'string' ||
|
|
133
|
+
(!text.includes('<skill>') && !text.includes('SKILL.md'))
|
|
134
|
+
) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const promptHits = detectSkillCalls({
|
|
138
|
+
tool: 'UserPromptSubmit',
|
|
139
|
+
args: {},
|
|
140
|
+
prompt: text,
|
|
141
|
+
cwd,
|
|
142
|
+
homeDir,
|
|
143
|
+
allowShell: false,
|
|
144
|
+
});
|
|
145
|
+
const uniqueTurnHits = [];
|
|
146
|
+
for (const h of promptHits) {
|
|
147
|
+
const key = `${h.skill}\0${(h.skill_path || '').replace(/\\/g, '/')}`;
|
|
148
|
+
if (turnPromptSkills.has(key)) continue;
|
|
149
|
+
turnPromptSkills.add(key);
|
|
150
|
+
uniqueTurnHits.push(h);
|
|
151
|
+
}
|
|
152
|
+
if (uniqueTurnHits.length > 0) {
|
|
153
|
+
pendingCalls.push({
|
|
154
|
+
idx: pendingCalls.length,
|
|
155
|
+
ts: obj.timestamp,
|
|
156
|
+
tool: 'UserPromptSubmit',
|
|
157
|
+
callId: p.id || `prompt_${turnIdx}_${pendingCalls.length}`,
|
|
158
|
+
args: {},
|
|
159
|
+
precomputedHits: uniqueTurnHits,
|
|
160
|
+
cwd,
|
|
161
|
+
model,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (p.type === 'message' && p.role === 'assistant') {
|
|
169
|
+
turnPromptSkills.clear();
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
124
173
|
if (p.type === 'function_call_output' || p.type === 'custom_tool_call_output') {
|
|
125
174
|
if (p.call_id && isOutputError(p.output)) {
|
|
126
175
|
failedCalls.add(p.call_id);
|
|
@@ -129,6 +178,7 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
129
178
|
}
|
|
130
179
|
|
|
131
180
|
if (p.type !== 'function_call' && p.type !== 'custom_tool_call') continue;
|
|
181
|
+
turnPromptSkills.clear();
|
|
132
182
|
|
|
133
183
|
const textToScan = p.type === 'function_call' ? p.arguments : p.input;
|
|
134
184
|
if (typeof textToScan !== 'string' || !textToScan.includes('SKILL.md')) continue;
|
|
@@ -162,13 +212,15 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
162
212
|
if (Number.isFinite(tsMs) && tsMs < sinceMs) continue;
|
|
163
213
|
}
|
|
164
214
|
|
|
165
|
-
const hits =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
215
|
+
const hits =
|
|
216
|
+
call.precomputedHits ||
|
|
217
|
+
detectSkillCalls({
|
|
218
|
+
tool: call.tool,
|
|
219
|
+
args: call.args,
|
|
220
|
+
cwd: call.cwd,
|
|
221
|
+
homeDir,
|
|
222
|
+
allowShell: true,
|
|
223
|
+
});
|
|
172
224
|
|
|
173
225
|
const ok = call.callId ? !failedCalls.has(call.callId) : true;
|
|
174
226
|
hits.forEach((h, hitIdx) => {
|
package/src/backfill/gemini.mjs
CHANGED
|
@@ -3,7 +3,13 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
4
|
import { detectSkillCalls } from '../core/detect.mjs';
|
|
5
5
|
|
|
6
|
-
const TARGET_TOOLS = new Set([
|
|
6
|
+
const TARGET_TOOLS = new Set([
|
|
7
|
+
'activate_skill',
|
|
8
|
+
'read_file',
|
|
9
|
+
'view_file',
|
|
10
|
+
'read_many_files',
|
|
11
|
+
'run_shell_command',
|
|
12
|
+
]);
|
|
7
13
|
|
|
8
14
|
function findGeminiChatFiles(homeDir) {
|
|
9
15
|
const tmpRoot = join(homeDir, '.gemini', 'tmp');
|
|
@@ -35,7 +35,7 @@ function buildAntigravityHooksJson() {
|
|
|
35
35
|
skilltally: {
|
|
36
36
|
PostToolUse: [
|
|
37
37
|
{
|
|
38
|
-
matcher: 'read_file|view_file',
|
|
38
|
+
matcher: 'read_file|view_file|run_command',
|
|
39
39
|
hooks: [
|
|
40
40
|
{
|
|
41
41
|
type: 'command',
|
|
@@ -88,7 +88,7 @@ export function installAntigravity({
|
|
|
88
88
|
|
|
89
89
|
writeJsonAtomic(join(target, 'hooks.json'), buildAntigravityHooksJson(), 0o644);
|
|
90
90
|
|
|
91
|
-
let version = '1.0.
|
|
91
|
+
let version = '1.0.2';
|
|
92
92
|
try {
|
|
93
93
|
version = JSON.parse(readFileSync(join(pkgRoot, 'package.json'), 'utf8')).version || version;
|
|
94
94
|
} catch {}
|
package/src/install/claude.mjs
CHANGED
|
@@ -62,7 +62,7 @@ export function installClaude({
|
|
|
62
62
|
const settingsPath = join(homeDir, '.claude', 'settings.json');
|
|
63
63
|
const doc = readJsonObject(settingsPath);
|
|
64
64
|
const { nextDoc, changed, action } = mergePostToolUseHook(doc, {
|
|
65
|
-
matcher: 'Skill|Read',
|
|
65
|
+
matcher: 'Skill|Read|View|Bash',
|
|
66
66
|
command,
|
|
67
67
|
async: true,
|
|
68
68
|
timeout: 5,
|
package/src/install/codex.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getPackageRoot,
|
|
8
8
|
isSkilltallyHandler,
|
|
9
9
|
mergePostToolUseHook,
|
|
10
|
+
mergeUserPromptSubmitHook,
|
|
10
11
|
readJsonObject,
|
|
11
12
|
removeSkilltallyHooks,
|
|
12
13
|
syncRuntime,
|
|
@@ -57,59 +58,80 @@ export function hasCodexPluginInstalled(homeDir = homedir()) {
|
|
|
57
58
|
|
|
58
59
|
export function checkCodexHookTrust(homeDir = homedir()) {
|
|
59
60
|
const hooksPath = join(homeDir, '.codex', 'hooks.json');
|
|
60
|
-
|
|
61
|
+
const requiredHooks = [];
|
|
61
62
|
try {
|
|
62
63
|
const doc = readJsonObject(hooksPath);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
for (const [eventName, snakeName] of [
|
|
65
|
+
['PostToolUse', 'post_tool_use'],
|
|
66
|
+
['UserPromptSubmit', 'user_prompt_submit'],
|
|
67
|
+
]) {
|
|
68
|
+
const groups = doc?.hooks?.[eventName] || [];
|
|
69
|
+
for (let gi = 0; gi < groups.length; gi++) {
|
|
70
|
+
const handlers = groups[gi]?.hooks;
|
|
71
|
+
if (!Array.isArray(handlers)) continue;
|
|
72
|
+
let foundInEvent = false;
|
|
73
|
+
for (let hi = 0; hi < handlers.length; hi++) {
|
|
74
|
+
if (isSkilltallyHandler(handlers[hi])) {
|
|
75
|
+
requiredHooks.push({
|
|
76
|
+
snakeName,
|
|
77
|
+
groupIdx: gi,
|
|
78
|
+
handlerIdx: hi,
|
|
79
|
+
exactKey: `hooks.json:${snakeName}:${gi}:${hi}`,
|
|
80
|
+
legacyRe: new RegExp(`:hooks\\.json:${snakeName}(?:"|'|])`),
|
|
81
|
+
});
|
|
82
|
+
foundInEvent = true;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
71
85
|
}
|
|
86
|
+
if (foundInEvent) break;
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
} catch {}
|
|
75
90
|
|
|
76
91
|
const hasPlugin = hasCodexPluginInstalled(homeDir);
|
|
77
|
-
if (
|
|
92
|
+
if (requiredHooks.length === 0 && !hasPlugin) return 'unknown';
|
|
78
93
|
|
|
79
94
|
const raw = readCodexToml(homeDir);
|
|
80
|
-
if (!raw) return
|
|
95
|
+
if (!raw) return requiredHooks.length > 0 ? 'untrusted' : 'unknown';
|
|
81
96
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
: null;
|
|
85
|
-
|
|
86
|
-
let inRelevantState = false;
|
|
87
|
-
let sawSection = false;
|
|
88
|
-
let sawTrustedHash = false;
|
|
97
|
+
const stateSections = [];
|
|
98
|
+
let currentSection = null;
|
|
89
99
|
|
|
90
100
|
for (const line of raw.split(/\r?\n/)) {
|
|
91
101
|
const trimmed = line.replace(/#.*$/, '').trim();
|
|
92
102
|
if (!trimmed) continue;
|
|
93
103
|
if (trimmed.startsWith('[')) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(trimmed.includes(exactHookKey) || /:hooks\.json:post_tool_use(?:"|'|])/.test(trimmed));
|
|
98
|
-
if (/^\[hooks\.state\./.test(trimmed) && (matchesSkilltally || matchesUserHook)) {
|
|
99
|
-
inRelevantState = true;
|
|
100
|
-
sawSection = true;
|
|
104
|
+
if (/^\[hooks\.state\./.test(trimmed)) {
|
|
105
|
+
currentSection = { header: trimmed, hasTrustedHash: false };
|
|
106
|
+
stateSections.push(currentSection);
|
|
101
107
|
} else {
|
|
102
|
-
|
|
108
|
+
currentSection = null;
|
|
103
109
|
}
|
|
104
110
|
continue;
|
|
105
111
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
112
|
+
if (currentSection && /^trusted_hash\s*=/.test(trimmed)) {
|
|
113
|
+
currentSection.hasTrustedHash = true;
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
117
|
+
if (requiredHooks.length > 0) {
|
|
118
|
+
for (const req of requiredHooks) {
|
|
119
|
+
const matching = stateSections.filter(
|
|
120
|
+
(s) =>
|
|
121
|
+
s.header.includes('skilltally') ||
|
|
122
|
+
s.header.includes(req.exactKey) ||
|
|
123
|
+
req.legacyRe.test(s.header)
|
|
124
|
+
);
|
|
125
|
+
if (!matching.some((s) => s.hasTrustedHash)) return 'untrusted';
|
|
126
|
+
}
|
|
127
|
+
return 'trusted';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const pluginSections = stateSections.filter((s) => s.header.includes('skilltally'));
|
|
131
|
+
if (pluginSections.length > 0) {
|
|
132
|
+
return pluginSections.some((s) => s.hasTrustedHash) ? 'trusted' : 'untrusted';
|
|
133
|
+
}
|
|
134
|
+
return 'unknown';
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
export function installCodex({
|
|
@@ -131,13 +153,22 @@ export function installCodex({
|
|
|
131
153
|
const command = `node "${runtime.target.replace(/\\/g, '/')}" --host codex`;
|
|
132
154
|
const hooksPath = join(homeDir, '.codex', 'hooks.json');
|
|
133
155
|
const doc = readJsonObject(hooksPath);
|
|
134
|
-
const
|
|
156
|
+
const postRes = mergePostToolUseHook(doc, {
|
|
135
157
|
matcher: 'exec|exec_command|shell|shell_command|local_shell|Bash',
|
|
136
158
|
command,
|
|
137
159
|
async: true,
|
|
138
160
|
timeout: 5,
|
|
139
161
|
statusMessage: 'skilltally',
|
|
140
162
|
});
|
|
163
|
+
const promptRes = mergeUserPromptSubmitHook(postRes.nextDoc, {
|
|
164
|
+
command,
|
|
165
|
+
async: true,
|
|
166
|
+
timeout: 5,
|
|
167
|
+
statusMessage: 'skilltally',
|
|
168
|
+
});
|
|
169
|
+
const nextDoc = promptRes.nextDoc;
|
|
170
|
+
const changed = postRes.changed || promptRes.changed;
|
|
171
|
+
const action = postRes.action === 'added' && promptRes.action === 'added' ? 'added' : 'updated';
|
|
141
172
|
|
|
142
173
|
let backup = null;
|
|
143
174
|
if (changed) {
|
|
@@ -152,7 +183,7 @@ export function installCodex({
|
|
|
152
183
|
status: changed ? (action === 'added' ? 'installed' : 'updated') : 'unchanged',
|
|
153
184
|
target: hooksPath,
|
|
154
185
|
backup,
|
|
155
|
-
note: 'Run codex and open /hooks to review and trust the skilltally
|
|
186
|
+
note: 'Run codex and open /hooks to review and trust the skilltally hooks.',
|
|
156
187
|
};
|
|
157
188
|
}
|
|
158
189
|
|
package/src/install/doctor.mjs
CHANGED
|
@@ -34,13 +34,13 @@ function collectNestedHookCommands(hooksJsonObj) {
|
|
|
34
34
|
const commands = [];
|
|
35
35
|
if (!hooksJsonObj || typeof hooksJsonObj !== 'object') return commands;
|
|
36
36
|
|
|
37
|
-
for (const eventName of ['PostToolUse', 'AfterTool']) {
|
|
37
|
+
for (const eventName of ['PostToolUse', 'AfterTool', 'UserPromptSubmit', 'BeforeAgent']) {
|
|
38
38
|
const groups = hooksJsonObj?.hooks?.[eventName];
|
|
39
39
|
if (!Array.isArray(groups)) continue;
|
|
40
40
|
for (const group of groups) {
|
|
41
41
|
for (const h of group?.hooks || []) {
|
|
42
42
|
if (isSkilltallyHandler(h) && typeof h?.command === 'string') {
|
|
43
|
-
commands.push(h.command);
|
|
43
|
+
if (!commands.includes(h.command)) commands.push(h.command);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/install/gemini.mjs
CHANGED
|
@@ -32,7 +32,7 @@ export function installGemini({
|
|
|
32
32
|
const doc = readJsonObject(settingsPath);
|
|
33
33
|
|
|
34
34
|
const { nextDoc, changed, action } = mergeEventHook(doc, 'AfterTool', {
|
|
35
|
-
matcher: 'activate_skill',
|
|
35
|
+
matcher: 'activate_skill|read_file|view_file|read_many_files|run_shell_command',
|
|
36
36
|
handler: {
|
|
37
37
|
name: 'skilltally',
|
|
38
38
|
type: 'command',
|
package/src/install/runtime.mjs
CHANGED
|
@@ -103,6 +103,7 @@ function handlersEqual(a, b) {
|
|
|
103
103
|
export function mergeEventHook(doc, eventName, { matcher, handler }) {
|
|
104
104
|
const nextDoc = structuredClone(doc && typeof doc === 'object' ? doc : {});
|
|
105
105
|
const desired = { ...handler };
|
|
106
|
+
const normalizedMatcher = matcher ?? undefined;
|
|
106
107
|
|
|
107
108
|
if (!nextDoc.hooks || typeof nextDoc.hooks !== 'object' || Array.isArray(nextDoc.hooks)) {
|
|
108
109
|
nextDoc.hooks = {};
|
|
@@ -116,7 +117,7 @@ export function mergeEventHook(doc, eventName, { matcher, handler }) {
|
|
|
116
117
|
for (const h of group.hooks) {
|
|
117
118
|
if (isSkilltallyHandler(h)) {
|
|
118
119
|
existingCount += 1;
|
|
119
|
-
if (group.matcher ===
|
|
120
|
+
if ((group.matcher ?? undefined) === normalizedMatcher && handlersEqual(h, desired)) {
|
|
120
121
|
exactMatch = true;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
@@ -137,7 +138,7 @@ export function mergeEventHook(doc, eventName, { matcher, handler }) {
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
cleaned.push({
|
|
140
|
-
matcher,
|
|
141
|
+
...(normalizedMatcher !== undefined ? { matcher: normalizedMatcher } : {}),
|
|
141
142
|
hooks: [desired],
|
|
142
143
|
});
|
|
143
144
|
nextDoc.hooks[eventName] = cleaned;
|
|
@@ -165,6 +166,22 @@ export function mergePostToolUseHook(
|
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
export function mergeUserPromptSubmitHook(
|
|
170
|
+
doc,
|
|
171
|
+
{ command, async = true, timeout = 5, statusMessage = 'skilltally' }
|
|
172
|
+
) {
|
|
173
|
+
return mergeEventHook(doc, 'UserPromptSubmit', {
|
|
174
|
+
matcher: undefined,
|
|
175
|
+
handler: {
|
|
176
|
+
type: 'command',
|
|
177
|
+
command,
|
|
178
|
+
...(async ? { async: true } : {}),
|
|
179
|
+
timeout,
|
|
180
|
+
statusMessage,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
168
185
|
export function removeSkilltallyHooksForEvent(doc, eventName) {
|
|
169
186
|
const nextDoc = structuredClone(doc && typeof doc === 'object' ? doc : {});
|
|
170
187
|
const list = nextDoc?.hooks?.[eventName];
|
|
@@ -206,5 +223,18 @@ export function removeSkilltallyHooksForEvent(doc, eventName) {
|
|
|
206
223
|
}
|
|
207
224
|
|
|
208
225
|
export function removeSkilltallyHooks(doc) {
|
|
209
|
-
|
|
226
|
+
let current = structuredClone(doc && typeof doc === 'object' ? doc : {});
|
|
227
|
+
let totalRemoved = 0;
|
|
228
|
+
const eventNames =
|
|
229
|
+
current?.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
|
|
230
|
+
? Object.keys(current.hooks)
|
|
231
|
+
: [];
|
|
232
|
+
for (const eventName of eventNames) {
|
|
233
|
+
const res = removeSkilltallyHooksForEvent(current, eventName);
|
|
234
|
+
if (res.changed) {
|
|
235
|
+
current = res.nextDoc;
|
|
236
|
+
totalRemoved += res.removedCount;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { nextDoc: current, changed: totalRemoved > 0, removedCount: totalRemoved };
|
|
210
240
|
}
|