04-skills.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Skills Configuration
  3. *
  4. * Skills provide specialized instructions loaded into the system prompt.
  5. * Discover, filter, merge, or replace them.
  6. */
  7. import {
  8. createAgentSession,
  9. createSyntheticSourceInfo,
  10. DefaultResourceLoader,
  11. getAgentDir,
  12. SessionManager,
  13. type Skill,
  14. } from "@earendil-works/pi-coding-agent";
  15. // Or define custom skills inline
  16. const customSkill: Skill = {
  17. name: "my-skill",
  18. description: "Custom project instructions",
  19. filePath: "/virtual/SKILL.md",
  20. baseDir: "/virtual",
  21. sourceInfo: createSyntheticSourceInfo("/virtual/SKILL.md", { source: "sdk" }),
  22. disableModelInvocation: false,
  23. };
  24. const loader = new DefaultResourceLoader({
  25. cwd: process.cwd(),
  26. agentDir: getAgentDir(),
  27. skillsOverride: (current) => {
  28. const filteredSkills = current.skills.filter((s) => s.name.includes("browser") || s.name.includes("search"));
  29. return {
  30. skills: [...filteredSkills, customSkill],
  31. diagnostics: current.diagnostics,
  32. };
  33. },
  34. });
  35. await loader.reload();
  36. // Discover all skills from cwd/.pi/skills, ~/.pi/agent/skills, etc.
  37. const { skills: allSkills, diagnostics } = loader.getSkills();
  38. console.log(
  39. "Discovered skills:",
  40. allSkills.map((s) => s.name),
  41. );
  42. if (diagnostics.length > 0) {
  43. console.log("Warnings:", diagnostics);
  44. }
  45. const { session } = await createAgentSession({
  46. resourceLoader: loader,
  47. sessionManager: SessionManager.inMemory(),
  48. });
  49. console.log("Session created with filtered skills");
  50. session.dispose();