skilltally 1.0.1 → 1.0.3

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.
@@ -10,7 +10,7 @@
10
10
  {
11
11
  "name": "skilltally",
12
12
  "description": "Track skill activations and identify unused skills eating context.",
13
- "version": "1.0.1",
13
+ "version": "1.0.3",
14
14
  "source": "./",
15
15
  "category": "productivity"
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skilltally",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Real-time skill usage tracking via hooks for Antigravity, Claude Code, Codex & Gemini CLI.",
5
5
  "author": {
6
6
  "name": "112516101106",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skilltally",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Real-time skill usage tracking via hooks for Antigravity, Claude Code, Codex & Gemini CLI.",
5
5
  "author": {
6
6
  "name": "112516101106",
package/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ 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.3] - 2026-11-19
9
+
10
+ ### Fixed
11
+ - Ignore paginated continuation reads across all 4 providers (`StartLine`/`start_line`/`offset > 1`, `ByteOffset`/`byte_offset > 0`, `sed -n 'N,Mp'` with `N > 1`, non-`+1` `tail`, and `awk` `NR >= N`/`NR > N`).
12
+ - Deduplicate same-session `(host, session_id, skill)` hook writes within a 30-second window at capture time in `bin/track.mjs`, and increase the default `dedupeEvents` query window from 5 seconds to 30 seconds in `src/core/normalize.mjs`.
13
+
14
+ ## [1.0.2] - 2026-11-19
15
+
16
+ ### Added
17
+ - Realtime `UserPromptSubmit` hook and `<skill>` / `[$skill](.../SKILL.md)` backfill detection for Codex explicit `$skill` invocations (`via: "mention"`).
18
+ - Expanded hook matchers and backfill parsers across all 4 providers:
19
+ - **Antigravity**: added `run_command` to `PostToolUse` matcher and fallback `<SKILL>` slash-command detection in `backfillAntigravity`.
20
+ - **Claude Code**: added `View|Bash` to `PostToolUse` matcher and `Base directory for this skill:` slash-command detection in `backfillClaude`.
21
+ - **Gemini CLI**: added `read_file|view_file|read_many_files|run_shell_command` to `AfterTool` matcher and `read_many_files` array path support.
22
+
23
+ ### Fixed
24
+ - 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`.
25
+
8
26
  ## [1.0.1] - 2026-11-19
9
27
 
10
28
  ### Fixed
package/bin/cli.mjs CHANGED
@@ -32,7 +32,7 @@ function getVersion() {
32
32
  try {
33
33
  return JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')).version;
34
34
  } catch {
35
- return '1.0.1';
35
+ return '1.0.3';
36
36
  }
37
37
  }
38
38
 
package/bin/track.mjs CHANGED
@@ -17,13 +17,65 @@ 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'];
31
+ const LINE_START_KEYS = ['StartLine', 'start_line', 'offset'];
32
+ const BYTE_OFFSET_KEYS = ['ByteOffset', 'byte_offset'];
22
33
  const CMD_KEYS = ['CommandLine', 'command', 'cmd', 'input', 'argv'];
23
34
  const WRITE_TOOL_RE = /^(write|edit|replace|apply_patch|multiedit|notebookedit|create_file|delete_file)/i;
24
35
  const READ_CMD_RE = /^(cat|sed|head|tail|less|more|bat|nl|awk|type|Get-Content)\b/i;
25
36
  const MUTATE_CMD_RE = /(?:^|\s)(?:sed|awk)\s+(?:[^\n]*\s)?(?:-i\S*|--in-place\b)|>{1,2}\s*[^\s]*SKILL\.md/i;
26
37
  const CODEX_EXEC_CMD_RE = /\bcmd\s*:\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/g;
38
+ const DEDUPE_WINDOW_MS = 30_000;
39
+
40
+ function isContinuationReadArgs(safeArgs) {
41
+ for (const key of LINE_START_KEYS) {
42
+ const raw = safeArgs[key];
43
+ if (raw === undefined || raw === null) continue;
44
+ const unwrapped = unwrapArg(raw);
45
+ if (typeof unwrapped === 'string' && unwrapped.trim() === '') continue;
46
+ const n = Number(unwrapped);
47
+ if (Number.isFinite(n) && n > 1) return true;
48
+ }
49
+ for (const key of BYTE_OFFSET_KEYS) {
50
+ const raw = safeArgs[key];
51
+ if (raw === undefined || raw === null) continue;
52
+ const unwrapped = unwrapArg(raw);
53
+ if (typeof unwrapped === 'string' && unwrapped.trim() === '') continue;
54
+ const n = Number(unwrapped);
55
+ if (Number.isFinite(n) && n > 0) return true;
56
+ }
57
+ return false;
58
+ }
59
+
60
+ function isContinuationShellSegment(seg) {
61
+ const mSed = seg.match(/\bsed\b[^;&\n]*?(?:^|[\s'"=])(\d+)(?:\s*,\s*(?:\d+|\$|\+\d+))?p(?=['"\s;|&]|$)/i);
62
+ if (mSed && Number(mSed[1]) > 1) return true;
63
+
64
+ if (
65
+ (/^tail\b/i.test(seg) || /\|\s*tail\b/i.test(seg)) &&
66
+ !/\btail\s+(?:-[^\s]+\s+)*-n\s*\+?[01]\b/i.test(seg)
67
+ ) {
68
+ return true;
69
+ }
70
+
71
+ const mAwkGe = seg.match(/\bawk\b[^;&\n]*?\bNR\s*>=\s*(\d+)/i);
72
+ if (mAwkGe && Number(mAwkGe[1]) > 1) return true;
73
+
74
+ const mAwkGt = seg.match(/\bawk\b[^;&\n]*?\bNR\s*>\s*(\d+)/i);
75
+ if (mAwkGt && Number(mAwkGt[1]) >= 1) return true;
76
+
77
+ return false;
78
+ }
27
79
 
28
80
  function argValue(flag, argv = process.argv) {
29
81
  const i = argv.indexOf(flag);
@@ -56,7 +108,13 @@ export function resolveHost(hostFlag, payload, env = process.env) {
56
108
  return hostFlag;
57
109
  }
58
110
  if (payload?.toolCall) return refineAntigravityHost(payload);
59
- if (payload?.hook_event_name === 'AfterTool' || env.GEMINI_PROJECT_DIR) return 'gemini';
111
+ if (
112
+ payload?.hook_event_name === 'AfterTool' ||
113
+ payload?.hook_event_name === 'BeforeAgent' ||
114
+ env.GEMINI_PROJECT_DIR
115
+ ) {
116
+ return 'gemini';
117
+ }
60
118
  const tp = String(payload?.transcript_path ?? '');
61
119
  if (
62
120
  env.CODEX_THREAD_ID ||
@@ -91,10 +149,22 @@ export function normalizeHookPayload(host, payload) {
91
149
  Boolean(p.error) ||
92
150
  resp?.is_error === true ||
93
151
  (typeof resp?.exit_code === 'number' && resp.exit_code !== 0);
152
+ const prompt =
153
+ typeof p.prompt === 'string'
154
+ ? p.prompt
155
+ : typeof p.user_prompt === 'string'
156
+ ? p.user_prompt
157
+ : typeof p.userMessage === 'string'
158
+ ? p.userMessage
159
+ : undefined;
160
+ const hookEvent = p.hook_event_name ?? p.hookEventName;
94
161
  return {
95
- tool: p.tool_name,
162
+ tool:
163
+ p.tool_name ??
164
+ (hookEvent === 'UserPromptSubmit' || hookEvent === 'BeforeAgent' ? hookEvent : undefined),
96
165
  args: p.tool_input ?? {},
97
- callId: p.tool_use_id ?? p.call_id,
166
+ ...(prompt !== undefined ? { prompt } : {}),
167
+ callId: p.tool_use_id ?? p.call_id ?? p.turn_id ?? p.prompt_id,
98
168
  sessionId: p.session_id,
99
169
  cwd: p.cwd,
100
170
  model: p.model,
@@ -153,7 +223,14 @@ function extractCodexCommandStrings(text) {
153
223
  return extracted.length > 0 ? extracted : [text];
154
224
  }
155
225
 
156
- export function detectSkillCalls({ tool, args, cwd = '', homeDir = homedir(), allowShell = true }) {
226
+ export function detectSkillCalls({
227
+ tool,
228
+ args,
229
+ prompt,
230
+ cwd = '',
231
+ homeDir = homedir(),
232
+ allowShell = true,
233
+ }) {
157
234
  const safeArgs = args && typeof args === 'object' ? args : {};
158
235
 
159
236
  if (tool === 'Skill' && safeArgs.skill) {
@@ -178,34 +255,73 @@ export function detectSkillCalls({ tool, args, cwd = '', homeDir = homedir(), al
178
255
  }
179
256
  }
180
257
 
181
- if (WRITE_TOOL_RE.test(tool ?? '')) return [];
182
-
183
258
  const hits = [];
184
259
  const seenPaths = new Set();
185
260
 
261
+ const pushPathHit = (skill, skillPath, via) => {
262
+ const cleanSkill = String(skill || '').trim();
263
+ const cleanPath = String(skillPath || '').trim();
264
+ if (!cleanSkill || !cleanPath) return;
265
+ const normKey = cleanPath.replace(/\\/g, '/');
266
+ if (seenPaths.has(normKey)) return;
267
+ seenPaths.add(normKey);
268
+ hits.push({
269
+ skill: cleanSkill,
270
+ skill_path: cleanPath,
271
+ source: resolveSource(cleanPath, cwd, homeDir),
272
+ via,
273
+ });
274
+ };
275
+
276
+ if (typeof prompt === 'string' && prompt.trim()) {
277
+ CODEX_SKILL_TAG_RE.lastIndex = 0;
278
+ for (const m of prompt.matchAll(CODEX_SKILL_TAG_RE)) {
279
+ pushPathHit(m[1], m[2], 'mention');
280
+ }
281
+ EXPLICIT_SKILL_LINK_RE.lastIndex = 0;
282
+ for (const m of prompt.matchAll(EXPLICIT_SKILL_LINK_RE)) {
283
+ pushPathHit(m[1], m[2], 'mention');
284
+ }
285
+ AGY_SKILL_TAG_RE.lastIndex = 0;
286
+ for (const m of prompt.matchAll(AGY_SKILL_TAG_RE)) {
287
+ pushPathHit(m[1], m[2], 'slash_command');
288
+ }
289
+ CLAUDE_SKILL_BASEDIR_RE.lastIndex = 0;
290
+ for (const m of prompt.matchAll(CLAUDE_SKILL_BASEDIR_RE)) {
291
+ const baseDir = m[1].trim().replace(/[\\/]+$/, '');
292
+ pushPathHit(m[2], `${baseDir}/SKILL.md`, 'slash_command');
293
+ }
294
+ if (hits.length > 0 && (!tool || tool === 'UserPromptSubmit' || tool === 'BeforeAgent' || tool === 'USER_INPUT')) {
295
+ return hits;
296
+ }
297
+ }
298
+
299
+ if (WRITE_TOOL_RE.test(tool ?? '')) return hits;
300
+
186
301
  const collectFromText = (text, via) => {
187
302
  if (!text.toLowerCase().includes('skill.md')) return;
188
303
  SKILL_PATH_RE.lastIndex = 0;
189
304
  for (const m of text.matchAll(SKILL_PATH_RE)) {
190
- const skillPath = m[1];
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
- });
305
+ pushPathHit(m[2], m[1], via);
201
306
  }
202
307
  };
203
308
 
309
+ if (isContinuationReadArgs(safeArgs)) return [];
310
+
204
311
  for (const key of PATH_KEYS) {
205
312
  if (typeof safeArgs[key] === 'string') {
206
313
  collectFromText(unwrapArg(safeArgs[key]), 'read');
207
314
  }
208
315
  }
316
+ for (const key of ARRAY_PATH_KEYS) {
317
+ if (Array.isArray(safeArgs[key])) {
318
+ for (const item of safeArgs[key]) {
319
+ if (typeof item === 'string' && !item.includes('*')) {
320
+ collectFromText(unwrapArg(item), 'read');
321
+ }
322
+ }
323
+ }
324
+ }
209
325
  if (hits.length > 0) return hits;
210
326
 
211
327
  if (!allowShell) return [];
@@ -228,6 +344,7 @@ export function detectSkillCalls({ tool, args, cwd = '', homeDir = homedir(), al
228
344
  const seg = rawSeg.trim().replace(/^(?:[A-Za-z_]\w*=\S+\s+)+/, '');
229
345
  if (!READ_CMD_RE.test(seg)) continue;
230
346
  if (MUTATE_CMD_RE.test(seg)) continue;
347
+ if (isContinuationShellSegment(seg)) continue;
231
348
  collectFromText(seg, 'shell_read');
232
349
  }
233
350
  }
@@ -261,6 +378,33 @@ function maybeRotateEvents(home, eventsPath) {
261
378
  } catch {}
262
379
  }
263
380
 
381
+ function readRecentSessionSkills(eventsPath, host, sessionId, nowMs) {
382
+ const recent = new Set();
383
+ if (!sessionId || !existsSync(eventsPath)) return recent;
384
+ try {
385
+ const raw = readFileSync(eventsPath, 'utf8');
386
+ const lines = raw.trim().split('\n');
387
+ const tail = lines.slice(-64);
388
+ for (const line of tail) {
389
+ if (!line) continue;
390
+ let ev;
391
+ try {
392
+ ev = JSON.parse(line);
393
+ } catch {
394
+ continue;
395
+ }
396
+ if (ev.ok === false || ev.host !== host || ev.session_id !== sessionId || !ev.skill) {
397
+ continue;
398
+ }
399
+ const evMs = Date.parse(ev.ts);
400
+ if (Number.isFinite(evMs) && Math.abs(nowMs - evMs) <= DEDUPE_WINDOW_MS) {
401
+ recent.add(ev.skill);
402
+ }
403
+ }
404
+ } catch {}
405
+ return recent;
406
+ }
407
+
264
408
  export function main() {
265
409
  const hostFlag = argValue('--host') ?? 'auto';
266
410
  const raw = readFileSync(0, 'utf8');
@@ -280,14 +424,26 @@ export function main() {
280
424
  const payload = JSON.parse(raw);
281
425
  const host = resolveHost(hostFlag, payload);
282
426
  const n = normalizeHookPayload(host, payload);
283
- const hits = detectSkillCalls({ tool: n.tool, args: n.args, cwd: n.cwd });
427
+ const hits = detectSkillCalls({ tool: n.tool, args: n.args, prompt: n.prompt, cwd: n.cwd });
284
428
  if (hits.length === 0) return;
285
429
 
430
+ const eventsPath = join(home, 'events.jsonl');
431
+ const ts = new Date().toISOString();
432
+ const nowMs = Date.parse(ts);
433
+ const recentSkills = !n.failed ? readRecentSessionSkills(eventsPath, host, n.sessionId, nowMs) : new Set();
434
+ const seenBatch = new Set();
435
+ const uniqueHits = [];
436
+ for (const h of hits) {
437
+ if (n.sessionId && (recentSkills.has(h.skill) || seenBatch.has(h.skill))) continue;
438
+ seenBatch.add(h.skill);
439
+ uniqueHits.push(h);
440
+ }
441
+ if (uniqueHits.length === 0) return;
442
+
286
443
  mkdirSync(home, { recursive: true, mode: 0o700 });
287
444
  const storeCwd = readStoreCwdFlag(home);
288
- const ts = new Date().toISOString();
289
445
 
290
- const lines = hits.map((h, idx) =>
446
+ const lines = uniqueHits.map((h, idx) =>
291
447
  JSON.stringify({
292
448
  v: 1,
293
449
  id: `${host}:${n.sessionId ?? '-'}:${n.callId ?? ts}#${idx}`,
@@ -308,7 +464,6 @@ export function main() {
308
464
  })
309
465
  );
310
466
 
311
- const eventsPath = join(home, 'events.jsonl');
312
467
  maybeRotateEvents(home, eventsPath);
313
468
  appendFileSync(eventsPath, lines.join('\n') + '\n', { mode: 0o600 });
314
469
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "skilltally",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Real-time skill usage tracking via hooks for Antigravity, Claude Code, Codex & Gemini CLI."
5
5
  }
@@ -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
@@ -2,7 +2,7 @@
2
2
  "skilltally": {
3
3
  "PostToolUse": [
4
4
  {
5
- "matcher": "read_file|view_file",
5
+ "matcher": "read_file|view_file|run_command",
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skilltally",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Real-time skill usage tracking via hooks for Antigravity, Claude Code, Codex & Gemini CLI.",
5
5
  "type": "module",
6
6
  "bin": {
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.1",
5
+ "version": "1.0.3",
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
- events.push({
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 {
@@ -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: true,
133
+ allowShell: call.tool !== 'UserPromptSubmit',
100
134
  });
101
135
 
102
136
  const ok = call.callId ? !failedIds.has(call.callId) : true;
@@ -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 = detectSkillCalls({
166
- tool: call.tool,
167
- args: call.args,
168
- cwd: call.cwd,
169
- homeDir,
170
- allowShell: true,
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) => {
@@ -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(['activate_skill', 'read_file', 'view_file', 'run_shell_command']);
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');
@@ -41,7 +41,7 @@ export function canonicalizeEvent(ev, inventoryIndex = null, aliases = {}) {
41
41
  };
42
42
  }
43
43
 
44
- export function dedupeEvents(events, windowMs = 5000) {
44
+ export function dedupeEvents(events, windowMs = 30_000) {
45
45
  // Prioritize real-time hook events over backfill events when deduplicating.
46
46
  const ordered = [
47
47
  ...events.filter((e) => e.origin === 'hook'),
@@ -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.1';
91
+ let version = '1.0.3';
92
92
  try {
93
93
  version = JSON.parse(readFileSync(join(pkgRoot, 'package.json'), 'utf8')).version || version;
94
94
  } catch {}
@@ -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,
@@ -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
- let userHookPos = null;
61
+ const requiredHooks = [];
61
62
  try {
62
63
  const doc = readJsonObject(hooksPath);
63
- const groups = doc?.hooks?.PostToolUse || [];
64
- for (let gi = 0; gi < groups.length && !userHookPos; gi++) {
65
- const handlers = groups[gi]?.hooks;
66
- if (!Array.isArray(handlers)) continue;
67
- for (let hi = 0; hi < handlers.length; hi++) {
68
- if (isSkilltallyHandler(handlers[hi])) {
69
- userHookPos = { groupIdx: gi, handlerIdx: hi };
70
- break;
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 (!userHookPos && !hasPlugin) return 'unknown';
92
+ if (requiredHooks.length === 0 && !hasPlugin) return 'unknown';
78
93
 
79
94
  const raw = readCodexToml(homeDir);
80
- if (!raw) return userHookPos ? 'untrusted' : 'unknown';
95
+ if (!raw) return requiredHooks.length > 0 ? 'untrusted' : 'unknown';
81
96
 
82
- const exactHookKey = userHookPos
83
- ? `hooks.json:post_tool_use:${userHookPos.groupIdx}:${userHookPos.handlerIdx}`
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
- const matchesSkilltally = trimmed.includes('skilltally');
95
- const matchesUserHook =
96
- exactHookKey !== null &&
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
- inRelevantState = false;
108
+ currentSection = null;
103
109
  }
104
110
  continue;
105
111
  }
106
- if (inRelevantState && /^trusted_hash\s*=/.test(trimmed)) {
107
- sawTrustedHash = true;
112
+ if (currentSection && /^trusted_hash\s*=/.test(trimmed)) {
113
+ currentSection.hasTrustedHash = true;
108
114
  }
109
115
  }
110
116
 
111
- if (sawSection) return sawTrustedHash ? 'trusted' : 'untrusted';
112
- return userHookPos ? 'untrusted' : 'unknown';
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 { nextDoc, changed, action } = mergePostToolUseHook(doc, {
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 PostToolUse hook.',
186
+ note: 'Run codex and open /hooks to review and trust the skilltally hooks.',
156
187
  };
157
188
  }
158
189
 
@@ -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
  }
@@ -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',
@@ -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 === matcher && handlersEqual(h, desired)) {
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
- return removeSkilltallyHooksForEvent(doc, 'PostToolUse');
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
  }