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:
+31
-3
@@ -1,8 +1,29 @@
|
|||||||
import { dirname } from "node:path";
|
import { dirname } from "node:path";
|
||||||
import type { ExtensionAPI, Skill } from "@earendil-works/pi-coding-agent";
|
import { isToolCallEventType, type ExtensionAPI, type ExtensionContext, type Skill } from "@earendil-works/pi-coding-agent";
|
||||||
import { detectSlashSkill, parseSkillBlocksFromText, userMessageText } from "./detect.js";
|
import { detectSlashSkill, matchReadPathToSkillWhenEnabled, parseSkillBlocksFromText, userMessageText } from "./detect.js";
|
||||||
|
import { readSettings } from "./settings.js";
|
||||||
import { findRegisteredSkillByName, resolveRegisteredSkills } from "./skills-registry.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 {
|
export default function skillReinject(pi: ExtensionAPI): void {
|
||||||
const state = createInitialState();
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user