pi-skill-search 0.2.2 → 0.2.4
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.
- package/README.md +6 -3
- package/index.ts +48 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,12 +21,15 @@ Result: **~97% token reduction** in skill-related system prompt content.
|
|
|
21
21
|
npx pi install .
|
|
22
22
|
|
|
23
23
|
# Or from npm (when published)
|
|
24
|
-
npx pi install pi-skill-search
|
|
24
|
+
npx pi install npm:pi-skill-search
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
> ⚠️ Note: Use `npm:pi-skill-search` prefix, not bare `pi-skill-search`.
|
|
28
|
+
> The `npm:` prefix tells Pi to install via npm which triggers the postinstall script.
|
|
29
|
+
|
|
27
30
|
After installation, the extension automatically:
|
|
28
|
-
1.
|
|
29
|
-
2.
|
|
31
|
+
1. Registers the `skill-search` tool and category summary for all Pi sessions
|
|
32
|
+
2. Installs the `skill-search` skill in `~/.pi/agent/skills/` (via postinstall script)
|
|
30
33
|
|
|
31
34
|
## Quick Start
|
|
32
35
|
|
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
|
-
|
|
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
|
|
53
|
-
const bundledSkills = scanSkillDirectory(
|
|
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 ${
|
|
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
|
+
}
|