pi-skill-search 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +48 -5
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  *
5
5
  * Thay the Pi's inject-all pattern bang on-demand search tool + category summary.
6
6
  */
7
+ import * as fs from "node:fs";
8
+ import * as os from "node:os";
7
9
  import * as path from "node:path";
8
10
  import { formatCategorySummary, formatResults, renderToolDescription } from "./src/format.ts";
9
11
  import { buildIndex, fingerprintSkills } from "./src/indexer.ts";
@@ -46,13 +48,50 @@ export default function (pi: ExtensionAPI): void {
46
48
  let index: SkillIndex | undefined;
47
49
  let lastSkillsFingerprint = "";
48
50
  let toolRegistered = false;
51
+ let skillSetupDone = false;
49
52
 
50
- // Scan skills/ directory — bộ skill chính thức do pi-skill-search quản lý
53
+ /**
54
+ * Auto-setup: copy skill-search to ~/.pi/agent/skills/ if not exists.
55
+ * Runs once at first before_agent_start event.
56
+ */
57
+ function ensureSkillSearchInstalled(): void {
58
+ if (skillSetupDone) return;
59
+ skillSetupDone = true;
60
+
61
+ const home = os.homedir();
62
+ const destDir = path.join(home, ".pi", "agent", "skills", "skill-search");
63
+ const destFile = path.join(destDir, "SKILL.md");
64
+
65
+ // Already installed?
66
+ if (fs.existsSync(destFile)) {
67
+ console.log("pi-skill-search: skill-search already installed");
68
+ return;
69
+ }
70
+
71
+ // Find source SKILL.md in extension data/
72
+ const extRoot = resolveExtensionRoot();
73
+ const sourceFile = pathJoin(extRoot, "data", "skill-search", "SKILL.md");
74
+
75
+ if (!fs.existsSync(sourceFile)) {
76
+ console.error("pi-skill-search: skill-search/SKILL.md not found in data/");
77
+ return;
78
+ }
79
+
80
+ try {
81
+ fs.mkdirSync(destDir, { recursive: true });
82
+ fs.copyFileSync(sourceFile, destFile);
83
+ console.log(`pi-skill-search: installed skill-search to ${destFile}`);
84
+ } catch (err) {
85
+ console.error("pi-skill-search: failed to install skill-search", err);
86
+ }
87
+ }
88
+
89
+ // Scan data/ directory — bộ skill chính thức do pi-skill-search quản lý
51
90
  const extensionRoot = resolveExtensionRoot();
52
- const skillsDir = pathJoin(extensionRoot, "skills");
53
- const bundledSkills = scanSkillDirectory(skillsDir);
91
+ const dataDir = pathJoin(extensionRoot, "data");
92
+ const bundledSkills = scanSkillDirectory(dataDir);
54
93
  if (bundledSkills.length > 0) {
55
- console.log(`pi-skill-search: loaded ${bundledSkills.length} bundled skills from ${skillsDir}`);
94
+ console.log(`pi-skill-search: loaded ${bundledSkills.length} bundled skills from ${dataDir}`);
56
95
  }
57
96
  /**
58
97
  * Build (hoac rebuild) index.
@@ -79,12 +118,16 @@ export default function (pi: ExtensionAPI): void {
79
118
  }
80
119
  /**
81
120
  * before_agent_start handler:
121
+ * - Auto-setup skill-search (first time only)
82
122
  * - Build/rebuild index
83
123
  * - Register skill-search tool (first time only)
84
124
  * - Strip <available_skills> block (ALWAYS — prevent Pi reset)
85
125
  * - Inject category summary (when skills exist)
86
126
  */
87
127
  pi.on("before_agent_start", async (event: BeforeAgentStartEvent): Promise<BeforeAgentStartEventResult> => {
128
+ // Auto-setup skill-search on first activation
129
+ ensureSkillSearchInstalled();
130
+
88
131
  const skills = event.systemPromptOptions?.skills as PiSkill[] | undefined;
89
132
  const idx = ensureIndex(skills);
90
133
 
@@ -160,4 +203,4 @@ function makeSearchResult(
160
203
  console.error("pi-skill-search: search failed", err);
161
204
  return { content: [{ type: "text", text: `Search failed: ${message}` }], details: {} };
162
205
  }
163
- }
206
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-skill-search",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "On-demand skill search extension for Pi — replaces inject-all with search tool + category summary",
5
5
  "type": "module",
6
6
  "types": "index.ts",