From edc01d1079906cb78023d722495b69db64abbcaf Mon Sep 17 00:00:00 2001 From: GRayHook Date: Wed, 17 Jun 2026 12:30:57 +0700 Subject: [PATCH] =?UTF-8?q?Phase=209:=20track=20read=20tool=20paths=20to?= =?UTF-8?q?=20SKILL.md=20on=20tool=5Fcall=20=E2=80=94=20SPEC=20=C2=A76.2?= =?UTF-8?q?=20#3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Match read tool paths against registered skills when trackReadPaths is enabled and upsert with source read. Co-authored-by: Cursor --- src/index.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) 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); + }); }