diff --git a/src/index.ts b/src/index.ts index 3ed8865..8808d14 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,29 @@ import { dirname } from "node:path"; -import type { ExtensionAPI, Skill } from "@earendil-works/pi-coding-agent"; -import { detectSlashSkill, parseSkillBlocksFromText, userMessageText } from "./detect.js"; +import { isToolCallEventType, type ExtensionAPI, type ExtensionContext, type Skill } from "@earendil-works/pi-coding-agent"; +import { detectSlashSkill, matchReadPathToSkillWhenEnabled, parseSkillBlocksFromText, userMessageText } from "./detect.js"; +import { readSettings } from "./settings.js"; import { findRegisteredSkillByName, resolveRegisteredSkills } from "./skills-registry.js"; -import { createInitialState, trackSkill } from "./state.js"; +import { createInitialState, trackSkill, type ExtensionState } from "./state.js"; + +function trackReadSkillPath( + path: string, + ctx: ExtensionContext, + state: ExtensionState, + registeredSkills: Skill[], +): void { + const settings = readSettings(ctx); + const skills = resolveRegisteredSkills(ctx.cwd, registeredSkills); + const matched = matchReadPathToSkillWhenEnabled(path, skills, settings.trackReadPaths); + if (!matched) { + return; + } + trackSkill(state, { + name: matched.name, + filePath: matched.filePath, + baseDir: matched.baseDir, + source: "read", + }); +} export default function skillReinject(pi: ExtensionAPI): void { const state = createInitialState(); @@ -51,4 +72,11 @@ export default function skillReinject(pi: ExtensionAPI): void { }); } }); + + pi.on("tool_call", async (event, ctx) => { + if (!isToolCallEventType("read", event)) { + return; + } + trackReadSkillPath(event.input.path, ctx, state, registeredSkills); + }); }