Phase 9: track read tool paths to SKILL.md on tool_call — SPEC §6.2 #3.

Match read tool paths against registered skills when trackReadPaths is enabled and upsert with source read.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-17 12:30:57 +07:00
parent 2021ee1293
commit edc01d1079
+31 -3
View File
@@ -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);
});
}