pi-skill-search 0.1.0

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 (299) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +97 -0
  4. package/index.ts +163 -0
  5. package/package.json +48 -0
  6. package/skills/adaptyv/SKILL.md +92 -0
  7. package/skills/add-community-extension/SKILL.md +85 -0
  8. package/skills/aeon/SKILL.md +111 -0
  9. package/skills/ai-slop-cleaner/SKILL.md +118 -0
  10. package/skills/anndata/SKILL.md +83 -0
  11. package/skills/arboreto/SKILL.md +107 -0
  12. package/skills/ask/SKILL.md +55 -0
  13. package/skills/astropy/SKILL.md +30 -0
  14. package/skills/async-worker-recovery/SKILL.md +44 -0
  15. package/skills/autopilot/SKILL.md +63 -0
  16. package/skills/autoresearch/SKILL.md +64 -0
  17. package/skills/autoskill/SKILL.md +116 -0
  18. package/skills/babysit/SKILL.md +43 -0
  19. package/skills/benchling-integration/SKILL.md +106 -0
  20. package/skills/bgpt-paper-search/SKILL.md +67 -0
  21. package/skills/biopython/SKILL.md +29 -0
  22. package/skills/bioservices/SKILL.md +96 -0
  23. package/skills/brainstorming/SKILL.md +104 -0
  24. package/skills/cancel/SKILL.md +85 -0
  25. package/skills/ccg/SKILL.md +87 -0
  26. package/skills/celery-pipeline/SKILL.md +30 -0
  27. package/skills/cellxgene-census/SKILL.md +104 -0
  28. package/skills/child-pi-spawning/SKILL.md +85 -0
  29. package/skills/cirq/SKILL.md +113 -0
  30. package/skills/citation-management/SKILL.md +91 -0
  31. package/skills/clinical-decision-support/SKILL.md +117 -0
  32. package/skills/clinical-reports/SKILL.md +118 -0
  33. package/skills/clinical-trial/SKILL.md +28 -0
  34. package/skills/cobrapy/SKILL.md +116 -0
  35. package/skills/configure-notifications/SKILL.md +85 -0
  36. package/skills/consciousness-council/SKILL.md +120 -0
  37. package/skills/context-artifact-hygiene/SKILL.md +85 -0
  38. package/skills/context-mode-ops/SKILL.md +87 -0
  39. package/skills/dask/SKILL.md +85 -0
  40. package/skills/database-lookup/SKILL.md +118 -0
  41. package/skills/datamol/SKILL.md +108 -0
  42. package/skills/debug/SKILL.md +32 -0
  43. package/skills/deep-dive/SKILL.md +114 -0
  44. package/skills/deep-interview/SKILL.md +90 -0
  45. package/skills/deepchem/SKILL.md +117 -0
  46. package/skills/deepinit/SKILL.md +100 -0
  47. package/skills/deeptools/SKILL.md +118 -0
  48. package/skills/delegation-patterns/SKILL.md +56 -0
  49. package/skills/depmap/SKILL.md +94 -0
  50. package/skills/dhdna-profiler/SKILL.md +86 -0
  51. package/skills/diffdock/SKILL.md +101 -0
  52. package/skills/dispatching-parallel-agents/SKILL.md +119 -0
  53. package/skills/dnanexus-integration/SKILL.md +118 -0
  54. package/skills/do/SKILL.md +48 -0
  55. package/skills/docker-sandbox/SKILL.md +29 -0
  56. package/skills/docx/SKILL.md +119 -0
  57. package/skills/esm/SKILL.md +116 -0
  58. package/skills/etetoolkit/SKILL.md +103 -0
  59. package/skills/event-log-tracing/SKILL.md +85 -0
  60. package/skills/exa-search/SKILL.md +72 -0
  61. package/skills/executing-plans/SKILL.md +69 -0
  62. package/skills/exploratory-data-analysis/SKILL.md +118 -0
  63. package/skills/external-context/SKILL.md +80 -0
  64. package/skills/fastapi/SKILL.md +30 -0
  65. package/skills/finishing-a-development-branch/SKILL.md +106 -0
  66. package/skills/flowio/SKILL.md +114 -0
  67. package/skills/fluidsim/SKILL.md +108 -0
  68. package/skills/generate-image/SKILL.md +108 -0
  69. package/skills/geniml/SKILL.md +117 -0
  70. package/skills/geomaster/SKILL.md +109 -0
  71. package/skills/geopandas/SKILL.md +114 -0
  72. package/skills/get-available-resources/SKILL.md +100 -0
  73. package/skills/gget/SKILL.md +111 -0
  74. package/skills/ginkgo-cloud-lab/SKILL.md +52 -0
  75. package/skills/git-master/SKILL.md +85 -0
  76. package/skills/glycoengineering/SKILL.md +104 -0
  77. package/skills/gtars/SKILL.md +104 -0
  78. package/skills/hackernews-frontpage/SKILL.md +46 -0
  79. package/skills/histolab/SKILL.md +98 -0
  80. package/skills/how-it-works/SKILL.md +25 -0
  81. package/skills/hud/SKILL.md +86 -0
  82. package/skills/hugging-science/SKILL.md +93 -0
  83. package/skills/huggingface/SKILL.md +30 -0
  84. package/skills/hypogenic/SKILL.md +107 -0
  85. package/skills/hypothesis-generation/SKILL.md +118 -0
  86. package/skills/imaging-data-commons/SKILL.md +119 -0
  87. package/skills/infographics/SKILL.md +102 -0
  88. package/skills/iso-13485-certification/SKILL.md +114 -0
  89. package/skills/knowledge-agent/SKILL.md +83 -0
  90. package/skills/labarchive-integration/SKILL.md +98 -0
  91. package/skills/lamindb/SKILL.md +119 -0
  92. package/skills/landsat/SKILL.md +29 -0
  93. package/skills/latchbio-integration/SKILL.md +118 -0
  94. package/skills/latex-posters/SKILL.md +112 -0
  95. package/skills/learn-codebase/SKILL.md +24 -0
  96. package/skills/learner/SKILL.md +118 -0
  97. package/skills/literature-review/SKILL.md +118 -0
  98. package/skills/live-agent-lifecycle/SKILL.md +85 -0
  99. package/skills/mailbox-interactive/SKILL.md +85 -0
  100. package/skills/make-plan/SKILL.md +59 -0
  101. package/skills/markdown-mermaid-writing/SKILL.md +118 -0
  102. package/skills/market-research-reports/SKILL.md +119 -0
  103. package/skills/markitdown/SKILL.md +111 -0
  104. package/skills/markitdown-docs/SKILL.md +28 -0
  105. package/skills/matchms/SKILL.md +91 -0
  106. package/skills/matlab/SKILL.md +118 -0
  107. package/skills/matplotlib/SKILL.md +30 -0
  108. package/skills/mcp-setup/SKILL.md +84 -0
  109. package/skills/medchem/SKILL.md +109 -0
  110. package/skills/mem-search/SKILL.md +96 -0
  111. package/skills/modal/SKILL.md +104 -0
  112. package/skills/model-routing-context/SKILL.md +85 -0
  113. package/skills/molecular-dynamics/SKILL.md +116 -0
  114. package/skills/molfeat/SKILL.md +110 -0
  115. package/skills/multi-perspective-review/SKILL.md +85 -0
  116. package/skills/networkx/SKILL.md +111 -0
  117. package/skills/neurokit2/SKILL.md +114 -0
  118. package/skills/neuropixels-analysis/SKILL.md +112 -0
  119. package/skills/nilearn/SKILL.md +29 -0
  120. package/skills/observability-reliability/SKILL.md +43 -0
  121. package/skills/omc-doctor/SKILL.md +86 -0
  122. package/skills/omc-reference/SKILL.md +119 -0
  123. package/skills/omc-setup/SKILL.md +82 -0
  124. package/skills/omc-teams/SKILL.md +81 -0
  125. package/skills/omero-integration/SKILL.md +111 -0
  126. package/skills/open-notebook/SKILL.md +100 -0
  127. package/skills/openephys/SKILL.md +28 -0
  128. package/skills/opentrons-integration/SKILL.md +110 -0
  129. package/skills/optimize-for-gpu/SKILL.md +119 -0
  130. package/skills/orchestration/SKILL.md +85 -0
  131. package/skills/ownership-session-security/SKILL.md +43 -0
  132. package/skills/paper-lookup/SKILL.md +119 -0
  133. package/skills/paperzilla/SKILL.md +114 -0
  134. package/skills/parallel-web/SKILL.md +64 -0
  135. package/skills/pathfinder/SKILL.md +114 -0
  136. package/skills/pathml/SKILL.md +98 -0
  137. package/skills/pdf/SKILL.md +113 -0
  138. package/skills/peer-review/SKILL.md +119 -0
  139. package/skills/pennylane/SKILL.md +119 -0
  140. package/skills/phylogenetics/SKILL.md +102 -0
  141. package/skills/pi-extension-lifecycle/SKILL.md +41 -0
  142. package/skills/plan/SKILL.md +66 -0
  143. package/skills/polars/SKILL.md +114 -0
  144. package/skills/polars-bio/SKILL.md +84 -0
  145. package/skills/pptx/SKILL.md +118 -0
  146. package/skills/pptx-posters/SKILL.md +112 -0
  147. package/skills/primekg/SKILL.md +97 -0
  148. package/skills/project-session-manager/SKILL.md +85 -0
  149. package/skills/protocolsio-integration/SKILL.md +119 -0
  150. package/skills/pubmed-search/SKILL.md +29 -0
  151. package/skills/pufferlib/SKILL.md +103 -0
  152. package/skills/pydeseq2/SKILL.md +106 -0
  153. package/skills/pydicom/SKILL.md +115 -0
  154. package/skills/pyhealth/SKILL.md +117 -0
  155. package/skills/pylabrobot/SKILL.md +100 -0
  156. package/skills/pymatgen/SKILL.md +28 -0
  157. package/skills/pymc/SKILL.md +108 -0
  158. package/skills/pymoo/SKILL.md +90 -0
  159. package/skills/pyopenms/SKILL.md +119 -0
  160. package/skills/pysam/SKILL.md +118 -0
  161. package/skills/pyspark/SKILL.md +30 -0
  162. package/skills/pytdc/SKILL.md +102 -0
  163. package/skills/pytorch/SKILL.md +31 -0
  164. package/skills/pytorch-lightning/SKILL.md +119 -0
  165. package/skills/pyzotero/SKILL.md +104 -0
  166. package/skills/qiskit/SKILL.md +119 -0
  167. package/skills/qutip/SKILL.md +111 -0
  168. package/skills/ralph/SKILL.md +23 -0
  169. package/skills/ralplan/SKILL.md +105 -0
  170. package/skills/rdflib/SKILL.md +29 -0
  171. package/skills/rdkit/SKILL.md +30 -0
  172. package/skills/read-only-explorer/SKILL.md +85 -0
  173. package/skills/receiving-code-review/SKILL.md +103 -0
  174. package/skills/release/SKILL.md +117 -0
  175. package/skills/remember/SKILL.md +39 -0
  176. package/skills/requesting-code-review/SKILL.md +85 -0
  177. package/skills/requirements-to-task-packet/SKILL.md +65 -0
  178. package/skills/research-grants/SKILL.md +118 -0
  179. package/skills/research-lookup/SKILL.md +117 -0
  180. package/skills/research-reproducibility/SKILL.md +28 -0
  181. package/skills/resource-discovery-config/SKILL.md +43 -0
  182. package/skills/rowan/SKILL.md +100 -0
  183. package/skills/runtime-state-reader/SKILL.md +46 -0
  184. package/skills/safe-bash/SKILL.md +85 -0
  185. package/skills/scanpy/SKILL.md +32 -0
  186. package/skills/scholar-evaluation/SKILL.md +115 -0
  187. package/skills/scientific-brainstorming/SKILL.md +118 -0
  188. package/skills/scientific-critical-thinking/SKILL.md +119 -0
  189. package/skills/scientific-schematics/SKILL.md +116 -0
  190. package/skills/scientific-slides/SKILL.md +117 -0
  191. package/skills/scientific-visualization/SKILL.md +109 -0
  192. package/skills/scientific-writing/SKILL.md +119 -0
  193. package/skills/scikit-bio/SKILL.md +92 -0
  194. package/skills/scikit-learn/SKILL.md +99 -0
  195. package/skills/scikit-survival/SKILL.md +110 -0
  196. package/skills/sciomc/SKILL.md +86 -0
  197. package/skills/scvelo/SKILL.md +106 -0
  198. package/skills/scvi-tools/SKILL.md +114 -0
  199. package/skills/seaborn/SKILL.md +97 -0
  200. package/skills/secure-agent-orchestration-review/SKILL.md +47 -0
  201. package/skills/self-improve/SKILL.md +119 -0
  202. package/skills/semantic-compression/SKILL.md +62 -0
  203. package/skills/setup/SKILL.md +42 -0
  204. package/skills/shap/SKILL.md +103 -0
  205. package/skills/simpy/SKILL.md +116 -0
  206. package/skills/skill/SKILL.md +117 -0
  207. package/skills/skill-search/SKILL.md +67 -0
  208. package/skills/skillify/SKILL.md +46 -0
  209. package/skills/smart-explore/SKILL.md +94 -0
  210. package/skills/sqlite-pandas/SKILL.md +30 -0
  211. package/skills/stable-baselines3/SKILL.md +86 -0
  212. package/skills/state-mutation-locking/SKILL.md +44 -0
  213. package/skills/statistical-analysis/SKILL.md +108 -0
  214. package/skills/statsmodels/SKILL.md +29 -0
  215. package/skills/subagent-driven-development/SKILL.md +89 -0
  216. package/skills/sympy/SKILL.md +115 -0
  217. package/skills/system-prompts/SKILL.md +116 -0
  218. package/skills/systematic-debugging/SKILL.md +119 -0
  219. package/skills/team/SKILL.md +85 -0
  220. package/skills/test-driven-development/SKILL.md +84 -0
  221. package/skills/tiledbvcf/SKILL.md +119 -0
  222. package/skills/timeline-report/SKILL.md +85 -0
  223. package/skills/timesfm-forecasting/SKILL.md +112 -0
  224. package/skills/torch-geometric/SKILL.md +118 -0
  225. package/skills/torchdrug/SKILL.md +118 -0
  226. package/skills/trace/SKILL.md +118 -0
  227. package/skills/transformers/SKILL.md +110 -0
  228. package/skills/treatment-plans/SKILL.md +119 -0
  229. package/skills/ui-render-performance/SKILL.md +41 -0
  230. package/skills/ultragoal/SKILL.md +63 -0
  231. package/skills/ultraqa/SKILL.md +85 -0
  232. package/skills/ultrawork/SKILL.md +20 -0
  233. package/skills/umap-learn/SKILL.md +119 -0
  234. package/skills/usfiscaldata/SKILL.md +118 -0
  235. package/skills/using-git-worktrees/SKILL.md +112 -0
  236. package/skills/using-superpowers/SKILL.md +85 -0
  237. package/skills/using-vetc/SKILL.md +92 -0
  238. package/skills/vaex/SKILL.md +111 -0
  239. package/skills/venue-templates/SKILL.md +113 -0
  240. package/skills/verification-before-completion/SKILL.md +88 -0
  241. package/skills/verification-before-done/SKILL.md +68 -0
  242. package/skills/verify/SKILL.md +33 -0
  243. package/skills/version-bump/SKILL.md +54 -0
  244. package/skills/vetc-analyze-ba/SKILL.md +117 -0
  245. package/skills/vetc-analyze-codebase/SKILL.md +118 -0
  246. package/skills/vetc-api-design/SKILL.md +103 -0
  247. package/skills/vetc-brainstorming/SKILL.md +116 -0
  248. package/skills/vetc-change-proposal/SKILL.md +111 -0
  249. package/skills/vetc-cicd/SKILL.md +113 -0
  250. package/skills/vetc-continuous-learning/SKILL.md +115 -0
  251. package/skills/vetc-deep-interview/SKILL.md +103 -0
  252. package/skills/vetc-docgen/SKILL.md +108 -0
  253. package/skills/vetc-frontend-patterns/SKILL.md +99 -0
  254. package/skills/vetc-iterative-retrieval/SKILL.md +110 -0
  255. package/skills/vetc-java-patterns/SKILL.md +113 -0
  256. package/skills/vetc-meta-skill-creator/SKILL.md +99 -0
  257. package/skills/vetc-oracle-patterns/SKILL.md +109 -0
  258. package/skills/vetc-performance-testing/SKILL.md +104 -0
  259. package/skills/vetc-pr-response/SKILL.md +106 -0
  260. package/skills/vetc-ralph/SKILL.md +108 -0
  261. package/skills/vetc-ralplan/SKILL.md +116 -0
  262. package/skills/vetc-receiving-review/SKILL.md +106 -0
  263. package/skills/vetc-reconcile-patterns/SKILL.md +117 -0
  264. package/skills/vetc-refactoring/SKILL.md +96 -0
  265. package/skills/vetc-runbook/SKILL.md +118 -0
  266. package/skills/vetc-sast/SKILL.md +118 -0
  267. package/skills/vetc-sdlc/SKILL.md +97 -0
  268. package/skills/vetc-security/SKILL.md +117 -0
  269. package/skills/vetc-spec-driven/SKILL.md +111 -0
  270. package/skills/vetc-spec-quality/SKILL.md +117 -0
  271. package/skills/vetc-systematic-debugging/SKILL.md +74 -0
  272. package/skills/vetc-tdd/SKILL.md +96 -0
  273. package/skills/vetc-thinking-pm/SKILL.md +110 -0
  274. package/skills/vetc-ui-visual-qa/SKILL.md +117 -0
  275. package/skills/vetc-verify/SKILL.md +101 -0
  276. package/skills/visual-verdict/SKILL.md +59 -0
  277. package/skills/what-if-oracle/SKILL.md +87 -0
  278. package/skills/widget-rendering/SKILL.md +85 -0
  279. package/skills/wiki/SKILL.md +69 -0
  280. package/skills/workspace-isolation/SKILL.md +85 -0
  281. package/skills/worktree-isolation/SKILL.md +85 -0
  282. package/skills/wowerpoint/SKILL.md +101 -0
  283. package/skills/writer-memory/SKILL.md +82 -0
  284. package/skills/writing-plans/SKILL.md +115 -0
  285. package/skills/writing-skills/SKILL.md +115 -0
  286. package/skills/xgboost/SKILL.md +29 -0
  287. package/skills/xgboost-ts/SKILL.md +28 -0
  288. package/skills/xlsx/SKILL.md +111 -0
  289. package/skills/zarr-python/SKILL.md +101 -0
  290. package/src/categories.ts +383 -0
  291. package/src/format.ts +104 -0
  292. package/src/indexer.ts +101 -0
  293. package/src/proactive.ts +51 -0
  294. package/src/scanner.ts +85 -0
  295. package/src/search.ts +89 -0
  296. package/src/strip.ts +29 -0
  297. package/src/synonyms.ts +83 -0
  298. package/src/text.ts +118 -0
  299. package/src/types.ts +64 -0
package/src/scanner.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Custom directory scanner — doc skills tu thu muc chinh thuc
3
+ * do pi-skill-search quan ly, doc lap voi Pi's skill discovery.
4
+ *
5
+ * Scan `skills/` trong extension root, parse SKILL.md frontmatter,
6
+ * tra ve PiSkill[] de extension index.
7
+ * Pi KHONG quet thu muc nay khi khoi dong — extension tu scan.
8
+ */
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+ import type { PiSkill } from "./types.ts";
12
+
13
+ /**
14
+ * Parse YAML frontmatter tu SKILL.md content.
15
+ * Chi extract `name` va `description` — cac fields khac bo qua.
16
+ */
17
+ export function parseFrontmatter(content: string): { name: string; description: string } | null {
18
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
19
+ if (!match) return null;
20
+ const fm = match[1];
21
+ let name = "";
22
+ let description = "";
23
+ for (const line of fm.split(/\r?\n/)) {
24
+ const nameMatch = line.match(/^name:\s*(.+)$/);
25
+ if (nameMatch) name = nameMatch[1].trim();
26
+ const descMatch = line.match(/^description:\s*(.+)$/);
27
+ if (descMatch) description = descMatch[1].trim();
28
+ }
29
+ if (!name) return null;
30
+ return { name, description };
31
+ }
32
+
33
+ /**
34
+ * Scan mot thu muc de tim tat ca SKILL.md.
35
+ * Moi subdirectory chua SKILL.md la mot skill.
36
+ */
37
+ export function scanSkillDirectory(dir: string): PiSkill[] {
38
+ if (!fs.existsSync(dir)) return [];
39
+
40
+ const skills: PiSkill[] = [];
41
+
42
+ try {
43
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
44
+ for (const entry of entries) {
45
+ if (!entry.isDirectory()) continue;
46
+ const skillFile = path.join(dir, entry.name, "SKILL.md");
47
+ if (!fs.existsSync(skillFile)) continue;
48
+
49
+ try {
50
+ const content = fs.readFileSync(skillFile, "utf-8");
51
+ const parsed = parseFrontmatter(content);
52
+ if (!parsed) continue;
53
+
54
+ skills.push({
55
+ name: parsed.name,
56
+ description: parsed.description,
57
+ filePath: skillFile,
58
+ disableModelInvocation: false,
59
+ });
60
+ } catch {
61
+ // Skip unreadable files
62
+ }
63
+ }
64
+ } catch {
65
+ // Directory unreadable
66
+ }
67
+
68
+ return skills;
69
+ }
70
+
71
+ /**
72
+ * Resolve extension root — thu muc chua index.ts cua extension.
73
+ * Jiti/TS loader suong __dirname tu import.meta.
74
+ */
75
+ export function resolveExtensionRoot(): string {
76
+ const thisFile = path.dirname(
77
+ new URL(import.meta.url).pathname
78
+ // Windows: strip leading / from file:///C:/...
79
+ .replace(/^\/([A-Z]:)/, "$1"),
80
+ );
81
+ // thisFile = <root>/src khi chay tu src, hoac <root> khi chay tu index.ts
82
+ // Check: neu thisFile ten la "src" thi len 1 level
83
+ if (path.basename(thisFile) === "src") return path.dirname(thisFile);
84
+ return thisFile;
85
+ }
package/src/search.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { expandQuery } from "./synonyms.ts";
2
+ import { tokenize } from "./text.ts";
3
+ /**
4
+ * Search algorithm — tinh diem va rank skills theo query.
5
+ * Implement theo SPEC §5.1 scoring formula.
6
+ */
7
+ import type { SearchResult, SkillIndex } from "./types.ts";
8
+
9
+ /**
10
+ * Tim kiem skills trong index theo query.
11
+ *
12
+ * Scoring per SPEC §5.1:
13
+ * +50 exact name match
14
+ * +20 per name-token match
15
+ * +3 per first-120-char description-token match
16
+ * +1 per remaining description-token match
17
+ * +5 per category-keyword match
18
+ *
19
+ * Synonym expansion truoc khi scoring (expandQuery).
20
+ * Sort by score desc, ties broken by name asc.
21
+ */
22
+ export function search(index: SkillIndex, query: string, limit: number): SearchResult[] {
23
+ // Expand query voi synonyms
24
+ const expandedTokens = expandQuery(query);
25
+ const queryTokens = tokenize(query);
26
+
27
+ if (queryTokens.size === 0 && expandedTokens.size === 0) {
28
+ return [];
29
+ }
30
+
31
+ const results: SearchResult[] = [];
32
+
33
+ for (const entry of index.entries.values()) {
34
+ let score = 0;
35
+ const nameLower = entry.name.toLowerCase();
36
+
37
+ // Exact name match
38
+ if (nameLower === query.toLowerCase().trim()) {
39
+ score += 50;
40
+ }
41
+
42
+ // Score moi expanded token
43
+ for (const token of expandedTokens) {
44
+ // Name token match
45
+ if (entry.nameTokens.has(token)) {
46
+ score += 20;
47
+ }
48
+
49
+ // Description split at 120 chars
50
+ const desc = entry.description;
51
+ const first120 = desc.slice(0, 120).toLowerCase();
52
+ const rest = desc.slice(120).toLowerCase();
53
+
54
+ const first120Tokens = tokenize(first120);
55
+ const restTokens = tokenize(rest);
56
+
57
+ if (first120Tokens.has(token)) {
58
+ score += 5;
59
+ }
60
+ if (restTokens.has(token)) {
61
+ score += 2;
62
+ }
63
+
64
+ // Category keyword match
65
+ for (const cat of entry.categories) {
66
+ if (cat.toLowerCase().includes(token)) {
67
+ score += 5;
68
+ }
69
+ }
70
+ }
71
+
72
+ if (score > 0) {
73
+ results.push({
74
+ name: entry.name,
75
+ description: entry.description,
76
+ path: entry.path,
77
+ score,
78
+ });
79
+ }
80
+ }
81
+
82
+ // Sort: score desc, then name asc
83
+ results.sort((a, b) => {
84
+ if (b.score !== a.score) return b.score - a.score;
85
+ return a.name.localeCompare(b.name);
86
+ });
87
+
88
+ return results.slice(0, limit);
89
+ }
package/src/strip.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Strip regex — loai bo Pi's auto-injected <available_skills> block.
3
+ * Implement theo SPEC §7.3.
4
+ */
5
+
6
+ /**
7
+ * Regex de match <available_skills> block tu Pi's formatSkillsForPrompt().
8
+ * Anchor vao lead-in sentence: "The following skills provide specialized instructions"
9
+ * Ket thuc bang </available_skills> tag.
10
+ */
11
+ export const AVAILABLE_SKILLS_BLOCK_REGEX =
12
+ /\n*The following skills provide specialized instructions[\s\S]*?<\/available_skills>/;
13
+
14
+ /**
15
+ * Strip <available_skills> block tu system prompt.
16
+ * Neu khong tim thay → no-op, tra ve original string.
17
+ */
18
+ export function stripAvailableSkillsBlock(systemPrompt: string): string {
19
+ return systemPrompt.replace(AVAILABLE_SKILLS_BLOCK_REGEX, "");
20
+ }
21
+
22
+ /**
23
+ * Drift detector — kiem tra xem regex co match trong systemPrompt khong.
24
+ * Tra ve true neu block duoc tim thay va stripped.
25
+ * Tra ve false neu khong tim thay (Pi co the da thay doi format).
26
+ */
27
+ export function detectSkillsBlock(systemPrompt: string): boolean {
28
+ return AVAILABLE_SKILLS_BLOCK_REGEX.test(systemPrompt);
29
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Tu dong ngu (synonym dictionary) — SPEC §5.2.
3
+ * Moi entry key → danh sach tu dong ngu, cho phep expand query.
4
+ */
5
+ import { tokenize } from "./text.ts";
6
+
7
+ /**
8
+ * Bang tu dong ngu. Moi key danh cho cac tu co cung nghia.
9
+ * Bidirectional — moi cap phai duoc mirror thuan nghich.
10
+ */
11
+ export const SYNONYMS: Record<string, string[]> = {
12
+ // Chemistry
13
+ molecule: ["molecular", "molecules", "compound"],
14
+ molecular: ["molecule", "molecules", "compound"],
15
+ drug: ["pharmaceutical", "medicinal"],
16
+ chem: ["chemistry", "chemical", "rdkit", "cheminformatics"],
17
+ docking: ["dock", "binding", "pose", "diffdock"],
18
+ admet: ["absorption", "distribution", "metabolism", "excretion", "toxicity"],
19
+ metabolism: ["metabolic", "metabolite", "pathway", "flux"],
20
+ metabolic: ["metabolism", "metabolite", "pathway", "flux"],
21
+ smiles: ["rdkit", "molecular", "cheminformatics", "compound"],
22
+
23
+ // Biology
24
+ gene: ["genomic", "genomics", "sequence", "dna", "rna"],
25
+ protein: ["proteomics", "peptide", "amino acid"],
26
+ "single-cell": ["scrna-seq", "single cell", "scrnaseq", "scanpy", "anndata"],
27
+ "rna-seq": ["transcriptom", "rna seq", "expression", "scrna"],
28
+ dna: ["genome", "genomic", "sequence", "biopython"],
29
+ sequence: ["dna", "rna", "protein", "genome", "alignment"],
30
+
31
+ // ML
32
+ ml: ["machine learning", "machine-learning"],
33
+ dl: ["deep learning", "deep-learning", "neural network"],
34
+ nlp: ["natural language", "text mining"],
35
+
36
+ // Clinical
37
+ clinical: ["medical", "patient", "healthcare"],
38
+
39
+ // Physics
40
+ quantum: ["qubit", "quantum computing"],
41
+
42
+ // General
43
+ viz: ["visualization", "plotting", "chart", "matplotlib", "seaborn"],
44
+ stats: ["statistics", "statistical", "scipy"],
45
+ db: ["database"],
46
+ // Search & tools
47
+ pdf: ["markitdown", "convert", "document"],
48
+ markitdown: ["pdf", "convert", "document", "docx", "pptx"],
49
+ // Agent/dev workflow
50
+ delegation: ["subagent", "dispatch", "parallel"],
51
+ parallel: ["concurrent", "delegation", "dispatch"],
52
+ agent: ["subagent", "delegation", "worker"],
53
+ // Lab
54
+ robot: ["opentrons", "pylabrobot", "automation"],
55
+ opentrons: ["robot", "lab automation", "liquid handling"],
56
+ // Neural network
57
+ "neural network": ["pytorch", "deep learning", "tensorflow"],
58
+ "deep learning": ["pytorch", "neural network", "tensorflow"],
59
+ };
60
+
61
+ /**
62
+ * Expand query tokens voi tu dong ngu.
63
+ * Tokenize query truoc, sau do union them tat ca synonym values.
64
+ */
65
+ export function expandQuery(query: string): Set<string> {
66
+ const tokens = tokenize(query);
67
+ const expanded = new Set(tokens);
68
+
69
+ for (const token of tokens) {
70
+ const synonyms = SYNONYMS[token];
71
+ if (synonyms) {
72
+ for (const syn of synonyms) {
73
+ // Tokenize moi synonym vi co the la multi-word ("machine learning")
74
+ const synTokens = tokenize(syn);
75
+ for (const st of synTokens) {
76
+ expanded.add(st);
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ return expanded;
83
+ }
package/src/text.ts ADDED
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Tokenization — chuyen text thanh set cua tokens.
3
+ * Implement theo SPEC §5.3.
4
+ */
5
+
6
+ /**
7
+ * Tokenize text thanh Set cua lowercase tokens.
8
+ * - Split hyphenated names (-, _, /)
9
+ * - Remove punctuation va non-alphanumeric chars
10
+ * - Skip 1-char tokens (deliberate trade-off)
11
+ * - Deduplicate qua Set
12
+ */
13
+ const STOPWORDS = new Set([
14
+ "the",
15
+ "a",
16
+ "an",
17
+ "is",
18
+ "are",
19
+ "was",
20
+ "were",
21
+ "be",
22
+ "been",
23
+ "being",
24
+ "have",
25
+ "has",
26
+ "had",
27
+ "do",
28
+ "does",
29
+ "did",
30
+ "will",
31
+ "would",
32
+ "could",
33
+ "should",
34
+ "may",
35
+ "might",
36
+ "shall",
37
+ "can",
38
+ "to",
39
+ "of",
40
+ "in",
41
+ "for",
42
+ "on",
43
+ "with",
44
+ "at",
45
+ "by",
46
+ "from",
47
+ "as",
48
+ "into",
49
+ "through",
50
+ "during",
51
+ "before",
52
+ "after",
53
+ "above",
54
+ "below",
55
+ "and",
56
+ "or",
57
+ "but",
58
+ "not",
59
+ "no",
60
+ "nor",
61
+ "it",
62
+ "its",
63
+ "this",
64
+ "that",
65
+ "these",
66
+ "those",
67
+ "i",
68
+ "me",
69
+ "my",
70
+ "we",
71
+ "our",
72
+ "you",
73
+ "your",
74
+ "he",
75
+ "she",
76
+ "they",
77
+ "them",
78
+ "their",
79
+ "what",
80
+ "which",
81
+ "who",
82
+ "whom",
83
+ "how",
84
+ "when",
85
+ "where",
86
+ "why",
87
+ "all",
88
+ "each",
89
+ "every",
90
+ "both",
91
+ "few",
92
+ "more",
93
+ "most",
94
+ "other",
95
+ "some",
96
+ "such",
97
+ "than",
98
+ "too",
99
+ "very",
100
+ "just",
101
+ "about",
102
+ "also",
103
+ "then",
104
+ "up",
105
+ "out",
106
+ "if",
107
+ ]);
108
+
109
+ export function tokenize(text: string): Set<string> {
110
+ return new Set(
111
+ text
112
+ .toLowerCase()
113
+ .replace(/[-_/]/g, " ")
114
+ .replace(/[^a-z0-9\s]/g, "")
115
+ .split(/\s+/)
116
+ .filter((w) => w.length >= 2 && !STOPWORDS.has(w)),
117
+ );
118
+ }
package/src/types.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Domain types cho pi-skill-search extension.
3
+ * PiSkill la subset cua Pi's Skill interface (skills.ts:75).
4
+ * Extension khong import Skill tu package vi no khong duoc export.
5
+ */
6
+ import type {
7
+ BeforeAgentStartEvent,
8
+ BeforeAgentStartEventResult,
9
+ BuildSystemPromptOptions,
10
+ ExtensionAPI,
11
+ ToolCallEvent,
12
+ } from "@earendil-works/pi-coding-agent";
13
+
14
+ // Re-export Pi event types cho convenience
15
+ export type {
16
+ BeforeAgentStartEvent,
17
+ BeforeAgentStartEventResult,
18
+ BuildSystemPromptOptions,
19
+ ExtensionAPI,
20
+ ToolCallEvent,
21
+ };
22
+
23
+ /**
24
+ * Subset cua Pi's Skill interface (skills.ts:75) ma extension can.
25
+ * Khong export tu @earendil-works/pi-coding-agent — phai khai bao local.
26
+ */
27
+ export interface PiSkill {
28
+ name: string;
29
+ description: string;
30
+ filePath: string;
31
+ disableModelInvocation: boolean;
32
+ }
33
+
34
+ /** Internal representation cua mot skill da duoc index */
35
+ export interface SkillEntry {
36
+ name: string;
37
+ description: string;
38
+ path: string;
39
+ categories: string[];
40
+ nameTokens: Set<string>;
41
+ descTokens: Set<string>;
42
+ }
43
+
44
+ /** Ket qua tim kiem cho mot skill */
45
+ export interface SearchResult {
46
+ name: string;
47
+ description: string;
48
+ path: string;
49
+ score: number;
50
+ }
51
+
52
+ /** Tom tat mot category voi so luong va vi du */
53
+ export interface CategorySummary {
54
+ name: string;
55
+ count: number;
56
+ examples: string[];
57
+ }
58
+
59
+ /** Index chinh cua toan bo skills */
60
+ export interface SkillIndex {
61
+ entries: Map<string, SkillEntry>;
62
+ categories: CategorySummary[];
63
+ nameIndex: Map<string, string>;
64
+ }