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.
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/index.ts +163 -0
- package/package.json +48 -0
- package/skills/adaptyv/SKILL.md +92 -0
- package/skills/add-community-extension/SKILL.md +85 -0
- package/skills/aeon/SKILL.md +111 -0
- package/skills/ai-slop-cleaner/SKILL.md +118 -0
- package/skills/anndata/SKILL.md +83 -0
- package/skills/arboreto/SKILL.md +107 -0
- package/skills/ask/SKILL.md +55 -0
- package/skills/astropy/SKILL.md +30 -0
- package/skills/async-worker-recovery/SKILL.md +44 -0
- package/skills/autopilot/SKILL.md +63 -0
- package/skills/autoresearch/SKILL.md +64 -0
- package/skills/autoskill/SKILL.md +116 -0
- package/skills/babysit/SKILL.md +43 -0
- package/skills/benchling-integration/SKILL.md +106 -0
- package/skills/bgpt-paper-search/SKILL.md +67 -0
- package/skills/biopython/SKILL.md +29 -0
- package/skills/bioservices/SKILL.md +96 -0
- package/skills/brainstorming/SKILL.md +104 -0
- package/skills/cancel/SKILL.md +85 -0
- package/skills/ccg/SKILL.md +87 -0
- package/skills/celery-pipeline/SKILL.md +30 -0
- package/skills/cellxgene-census/SKILL.md +104 -0
- package/skills/child-pi-spawning/SKILL.md +85 -0
- package/skills/cirq/SKILL.md +113 -0
- package/skills/citation-management/SKILL.md +91 -0
- package/skills/clinical-decision-support/SKILL.md +117 -0
- package/skills/clinical-reports/SKILL.md +118 -0
- package/skills/clinical-trial/SKILL.md +28 -0
- package/skills/cobrapy/SKILL.md +116 -0
- package/skills/configure-notifications/SKILL.md +85 -0
- package/skills/consciousness-council/SKILL.md +120 -0
- package/skills/context-artifact-hygiene/SKILL.md +85 -0
- package/skills/context-mode-ops/SKILL.md +87 -0
- package/skills/dask/SKILL.md +85 -0
- package/skills/database-lookup/SKILL.md +118 -0
- package/skills/datamol/SKILL.md +108 -0
- package/skills/debug/SKILL.md +32 -0
- package/skills/deep-dive/SKILL.md +114 -0
- package/skills/deep-interview/SKILL.md +90 -0
- package/skills/deepchem/SKILL.md +117 -0
- package/skills/deepinit/SKILL.md +100 -0
- package/skills/deeptools/SKILL.md +118 -0
- package/skills/delegation-patterns/SKILL.md +56 -0
- package/skills/depmap/SKILL.md +94 -0
- package/skills/dhdna-profiler/SKILL.md +86 -0
- package/skills/diffdock/SKILL.md +101 -0
- package/skills/dispatching-parallel-agents/SKILL.md +119 -0
- package/skills/dnanexus-integration/SKILL.md +118 -0
- package/skills/do/SKILL.md +48 -0
- package/skills/docker-sandbox/SKILL.md +29 -0
- package/skills/docx/SKILL.md +119 -0
- package/skills/esm/SKILL.md +116 -0
- package/skills/etetoolkit/SKILL.md +103 -0
- package/skills/event-log-tracing/SKILL.md +85 -0
- package/skills/exa-search/SKILL.md +72 -0
- package/skills/executing-plans/SKILL.md +69 -0
- package/skills/exploratory-data-analysis/SKILL.md +118 -0
- package/skills/external-context/SKILL.md +80 -0
- package/skills/fastapi/SKILL.md +30 -0
- package/skills/finishing-a-development-branch/SKILL.md +106 -0
- package/skills/flowio/SKILL.md +114 -0
- package/skills/fluidsim/SKILL.md +108 -0
- package/skills/generate-image/SKILL.md +108 -0
- package/skills/geniml/SKILL.md +117 -0
- package/skills/geomaster/SKILL.md +109 -0
- package/skills/geopandas/SKILL.md +114 -0
- package/skills/get-available-resources/SKILL.md +100 -0
- package/skills/gget/SKILL.md +111 -0
- package/skills/ginkgo-cloud-lab/SKILL.md +52 -0
- package/skills/git-master/SKILL.md +85 -0
- package/skills/glycoengineering/SKILL.md +104 -0
- package/skills/gtars/SKILL.md +104 -0
- package/skills/hackernews-frontpage/SKILL.md +46 -0
- package/skills/histolab/SKILL.md +98 -0
- package/skills/how-it-works/SKILL.md +25 -0
- package/skills/hud/SKILL.md +86 -0
- package/skills/hugging-science/SKILL.md +93 -0
- package/skills/huggingface/SKILL.md +30 -0
- package/skills/hypogenic/SKILL.md +107 -0
- package/skills/hypothesis-generation/SKILL.md +118 -0
- package/skills/imaging-data-commons/SKILL.md +119 -0
- package/skills/infographics/SKILL.md +102 -0
- package/skills/iso-13485-certification/SKILL.md +114 -0
- package/skills/knowledge-agent/SKILL.md +83 -0
- package/skills/labarchive-integration/SKILL.md +98 -0
- package/skills/lamindb/SKILL.md +119 -0
- package/skills/landsat/SKILL.md +29 -0
- package/skills/latchbio-integration/SKILL.md +118 -0
- package/skills/latex-posters/SKILL.md +112 -0
- package/skills/learn-codebase/SKILL.md +24 -0
- package/skills/learner/SKILL.md +118 -0
- package/skills/literature-review/SKILL.md +118 -0
- package/skills/live-agent-lifecycle/SKILL.md +85 -0
- package/skills/mailbox-interactive/SKILL.md +85 -0
- package/skills/make-plan/SKILL.md +59 -0
- package/skills/markdown-mermaid-writing/SKILL.md +118 -0
- package/skills/market-research-reports/SKILL.md +119 -0
- package/skills/markitdown/SKILL.md +111 -0
- package/skills/markitdown-docs/SKILL.md +28 -0
- package/skills/matchms/SKILL.md +91 -0
- package/skills/matlab/SKILL.md +118 -0
- package/skills/matplotlib/SKILL.md +30 -0
- package/skills/mcp-setup/SKILL.md +84 -0
- package/skills/medchem/SKILL.md +109 -0
- package/skills/mem-search/SKILL.md +96 -0
- package/skills/modal/SKILL.md +104 -0
- package/skills/model-routing-context/SKILL.md +85 -0
- package/skills/molecular-dynamics/SKILL.md +116 -0
- package/skills/molfeat/SKILL.md +110 -0
- package/skills/multi-perspective-review/SKILL.md +85 -0
- package/skills/networkx/SKILL.md +111 -0
- package/skills/neurokit2/SKILL.md +114 -0
- package/skills/neuropixels-analysis/SKILL.md +112 -0
- package/skills/nilearn/SKILL.md +29 -0
- package/skills/observability-reliability/SKILL.md +43 -0
- package/skills/omc-doctor/SKILL.md +86 -0
- package/skills/omc-reference/SKILL.md +119 -0
- package/skills/omc-setup/SKILL.md +82 -0
- package/skills/omc-teams/SKILL.md +81 -0
- package/skills/omero-integration/SKILL.md +111 -0
- package/skills/open-notebook/SKILL.md +100 -0
- package/skills/openephys/SKILL.md +28 -0
- package/skills/opentrons-integration/SKILL.md +110 -0
- package/skills/optimize-for-gpu/SKILL.md +119 -0
- package/skills/orchestration/SKILL.md +85 -0
- package/skills/ownership-session-security/SKILL.md +43 -0
- package/skills/paper-lookup/SKILL.md +119 -0
- package/skills/paperzilla/SKILL.md +114 -0
- package/skills/parallel-web/SKILL.md +64 -0
- package/skills/pathfinder/SKILL.md +114 -0
- package/skills/pathml/SKILL.md +98 -0
- package/skills/pdf/SKILL.md +113 -0
- package/skills/peer-review/SKILL.md +119 -0
- package/skills/pennylane/SKILL.md +119 -0
- package/skills/phylogenetics/SKILL.md +102 -0
- package/skills/pi-extension-lifecycle/SKILL.md +41 -0
- package/skills/plan/SKILL.md +66 -0
- package/skills/polars/SKILL.md +114 -0
- package/skills/polars-bio/SKILL.md +84 -0
- package/skills/pptx/SKILL.md +118 -0
- package/skills/pptx-posters/SKILL.md +112 -0
- package/skills/primekg/SKILL.md +97 -0
- package/skills/project-session-manager/SKILL.md +85 -0
- package/skills/protocolsio-integration/SKILL.md +119 -0
- package/skills/pubmed-search/SKILL.md +29 -0
- package/skills/pufferlib/SKILL.md +103 -0
- package/skills/pydeseq2/SKILL.md +106 -0
- package/skills/pydicom/SKILL.md +115 -0
- package/skills/pyhealth/SKILL.md +117 -0
- package/skills/pylabrobot/SKILL.md +100 -0
- package/skills/pymatgen/SKILL.md +28 -0
- package/skills/pymc/SKILL.md +108 -0
- package/skills/pymoo/SKILL.md +90 -0
- package/skills/pyopenms/SKILL.md +119 -0
- package/skills/pysam/SKILL.md +118 -0
- package/skills/pyspark/SKILL.md +30 -0
- package/skills/pytdc/SKILL.md +102 -0
- package/skills/pytorch/SKILL.md +31 -0
- package/skills/pytorch-lightning/SKILL.md +119 -0
- package/skills/pyzotero/SKILL.md +104 -0
- package/skills/qiskit/SKILL.md +119 -0
- package/skills/qutip/SKILL.md +111 -0
- package/skills/ralph/SKILL.md +23 -0
- package/skills/ralplan/SKILL.md +105 -0
- package/skills/rdflib/SKILL.md +29 -0
- package/skills/rdkit/SKILL.md +30 -0
- package/skills/read-only-explorer/SKILL.md +85 -0
- package/skills/receiving-code-review/SKILL.md +103 -0
- package/skills/release/SKILL.md +117 -0
- package/skills/remember/SKILL.md +39 -0
- package/skills/requesting-code-review/SKILL.md +85 -0
- package/skills/requirements-to-task-packet/SKILL.md +65 -0
- package/skills/research-grants/SKILL.md +118 -0
- package/skills/research-lookup/SKILL.md +117 -0
- package/skills/research-reproducibility/SKILL.md +28 -0
- package/skills/resource-discovery-config/SKILL.md +43 -0
- package/skills/rowan/SKILL.md +100 -0
- package/skills/runtime-state-reader/SKILL.md +46 -0
- package/skills/safe-bash/SKILL.md +85 -0
- package/skills/scanpy/SKILL.md +32 -0
- package/skills/scholar-evaluation/SKILL.md +115 -0
- package/skills/scientific-brainstorming/SKILL.md +118 -0
- package/skills/scientific-critical-thinking/SKILL.md +119 -0
- package/skills/scientific-schematics/SKILL.md +116 -0
- package/skills/scientific-slides/SKILL.md +117 -0
- package/skills/scientific-visualization/SKILL.md +109 -0
- package/skills/scientific-writing/SKILL.md +119 -0
- package/skills/scikit-bio/SKILL.md +92 -0
- package/skills/scikit-learn/SKILL.md +99 -0
- package/skills/scikit-survival/SKILL.md +110 -0
- package/skills/sciomc/SKILL.md +86 -0
- package/skills/scvelo/SKILL.md +106 -0
- package/skills/scvi-tools/SKILL.md +114 -0
- package/skills/seaborn/SKILL.md +97 -0
- package/skills/secure-agent-orchestration-review/SKILL.md +47 -0
- package/skills/self-improve/SKILL.md +119 -0
- package/skills/semantic-compression/SKILL.md +62 -0
- package/skills/setup/SKILL.md +42 -0
- package/skills/shap/SKILL.md +103 -0
- package/skills/simpy/SKILL.md +116 -0
- package/skills/skill/SKILL.md +117 -0
- package/skills/skill-search/SKILL.md +67 -0
- package/skills/skillify/SKILL.md +46 -0
- package/skills/smart-explore/SKILL.md +94 -0
- package/skills/sqlite-pandas/SKILL.md +30 -0
- package/skills/stable-baselines3/SKILL.md +86 -0
- package/skills/state-mutation-locking/SKILL.md +44 -0
- package/skills/statistical-analysis/SKILL.md +108 -0
- package/skills/statsmodels/SKILL.md +29 -0
- package/skills/subagent-driven-development/SKILL.md +89 -0
- package/skills/sympy/SKILL.md +115 -0
- package/skills/system-prompts/SKILL.md +116 -0
- package/skills/systematic-debugging/SKILL.md +119 -0
- package/skills/team/SKILL.md +85 -0
- package/skills/test-driven-development/SKILL.md +84 -0
- package/skills/tiledbvcf/SKILL.md +119 -0
- package/skills/timeline-report/SKILL.md +85 -0
- package/skills/timesfm-forecasting/SKILL.md +112 -0
- package/skills/torch-geometric/SKILL.md +118 -0
- package/skills/torchdrug/SKILL.md +118 -0
- package/skills/trace/SKILL.md +118 -0
- package/skills/transformers/SKILL.md +110 -0
- package/skills/treatment-plans/SKILL.md +119 -0
- package/skills/ui-render-performance/SKILL.md +41 -0
- package/skills/ultragoal/SKILL.md +63 -0
- package/skills/ultraqa/SKILL.md +85 -0
- package/skills/ultrawork/SKILL.md +20 -0
- package/skills/umap-learn/SKILL.md +119 -0
- package/skills/usfiscaldata/SKILL.md +118 -0
- package/skills/using-git-worktrees/SKILL.md +112 -0
- package/skills/using-superpowers/SKILL.md +85 -0
- package/skills/using-vetc/SKILL.md +92 -0
- package/skills/vaex/SKILL.md +111 -0
- package/skills/venue-templates/SKILL.md +113 -0
- package/skills/verification-before-completion/SKILL.md +88 -0
- package/skills/verification-before-done/SKILL.md +68 -0
- package/skills/verify/SKILL.md +33 -0
- package/skills/version-bump/SKILL.md +54 -0
- package/skills/vetc-analyze-ba/SKILL.md +117 -0
- package/skills/vetc-analyze-codebase/SKILL.md +118 -0
- package/skills/vetc-api-design/SKILL.md +103 -0
- package/skills/vetc-brainstorming/SKILL.md +116 -0
- package/skills/vetc-change-proposal/SKILL.md +111 -0
- package/skills/vetc-cicd/SKILL.md +113 -0
- package/skills/vetc-continuous-learning/SKILL.md +115 -0
- package/skills/vetc-deep-interview/SKILL.md +103 -0
- package/skills/vetc-docgen/SKILL.md +108 -0
- package/skills/vetc-frontend-patterns/SKILL.md +99 -0
- package/skills/vetc-iterative-retrieval/SKILL.md +110 -0
- package/skills/vetc-java-patterns/SKILL.md +113 -0
- package/skills/vetc-meta-skill-creator/SKILL.md +99 -0
- package/skills/vetc-oracle-patterns/SKILL.md +109 -0
- package/skills/vetc-performance-testing/SKILL.md +104 -0
- package/skills/vetc-pr-response/SKILL.md +106 -0
- package/skills/vetc-ralph/SKILL.md +108 -0
- package/skills/vetc-ralplan/SKILL.md +116 -0
- package/skills/vetc-receiving-review/SKILL.md +106 -0
- package/skills/vetc-reconcile-patterns/SKILL.md +117 -0
- package/skills/vetc-refactoring/SKILL.md +96 -0
- package/skills/vetc-runbook/SKILL.md +118 -0
- package/skills/vetc-sast/SKILL.md +118 -0
- package/skills/vetc-sdlc/SKILL.md +97 -0
- package/skills/vetc-security/SKILL.md +117 -0
- package/skills/vetc-spec-driven/SKILL.md +111 -0
- package/skills/vetc-spec-quality/SKILL.md +117 -0
- package/skills/vetc-systematic-debugging/SKILL.md +74 -0
- package/skills/vetc-tdd/SKILL.md +96 -0
- package/skills/vetc-thinking-pm/SKILL.md +110 -0
- package/skills/vetc-ui-visual-qa/SKILL.md +117 -0
- package/skills/vetc-verify/SKILL.md +101 -0
- package/skills/visual-verdict/SKILL.md +59 -0
- package/skills/what-if-oracle/SKILL.md +87 -0
- package/skills/widget-rendering/SKILL.md +85 -0
- package/skills/wiki/SKILL.md +69 -0
- package/skills/workspace-isolation/SKILL.md +85 -0
- package/skills/worktree-isolation/SKILL.md +85 -0
- package/skills/wowerpoint/SKILL.md +101 -0
- package/skills/writer-memory/SKILL.md +82 -0
- package/skills/writing-plans/SKILL.md +115 -0
- package/skills/writing-skills/SKILL.md +115 -0
- package/skills/xgboost/SKILL.md +29 -0
- package/skills/xgboost-ts/SKILL.md +28 -0
- package/skills/xlsx/SKILL.md +111 -0
- package/skills/zarr-python/SKILL.md +101 -0
- package/src/categories.ts +383 -0
- package/src/format.ts +104 -0
- package/src/indexer.ts +101 -0
- package/src/proactive.ts +51 -0
- package/src/scanner.ts +85 -0
- package/src/search.ts +89 -0
- package/src/strip.ts +29 -0
- package/src/synonyms.ts +83 -0
- package/src/text.ts +118 -0
- 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
|
+
}
|
package/src/synonyms.ts
ADDED
|
@@ -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
|
+
}
|