@oh-my-tool/cli 0.3.1 → 0.3.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.
@@ -1,33 +0,0 @@
1
- import type { ExtensionManifest } from "@oh-my-tool/sdk";
2
- import type { InstalledExtension } from "../extension/discovery";
3
-
4
- import { RuntimeError as OmtError } from "../runtime/errors";
5
- export { OmtError };
6
-
7
- export interface Registry {
8
- byTool: Map<string, { extension: InstalledExtension; tool: ExtensionManifest["tools"][number] }>;
9
- byId: Map<string, InstalledExtension>;
10
- }
11
-
12
- export function createRegistry(installed: InstalledExtension[]): Registry {
13
- const byTool = new Map();
14
- const byId = new Map();
15
- for (const ext of installed) {
16
- byId.set(ext.id, ext);
17
- for (const tool of ext.manifest.tools) {
18
- byTool.set(tool.name, { extension: ext, tool });
19
- }
20
- }
21
- return { byTool, byId };
22
- }
23
-
24
- export function resolveTool(
25
- reg: Registry,
26
- toolName: string,
27
- ): { extension: InstalledExtension; tool: ExtensionManifest["tools"][number] } {
28
- const hit = reg.byTool.get(toolName);
29
- if (!hit) {
30
- throw new OmtError("UNKNOWN_TOOL", `unknown tool '${toolName}'`);
31
- }
32
- return hit;
33
- }
@@ -1,14 +0,0 @@
1
- export interface OmtOk {
2
- ok: true;
3
- tool: string;
4
- data: unknown;
5
- meta: Record<string, unknown>;
6
- }
7
-
8
- export interface OmtErr {
9
- ok: false;
10
- tool: string;
11
- error: { code: string; message: string; details?: unknown };
12
- }
13
-
14
- export type OmtResult = OmtOk | OmtErr;
@@ -1,2 +0,0 @@
1
- export { validateInput } from "../runtime/schema";
2
- export type { Schema } from "../runtime/schema";
@@ -1,78 +0,0 @@
1
- import type { ExtensionManifest } from "@oh-my-tool/sdk";
2
-
3
- export interface SearchHit {
4
- name: string;
5
- description: string;
6
- extension: string;
7
- risk: string;
8
- score: number;
9
- }
10
-
11
- interface Searchable {
12
- name: string;
13
- description: string;
14
- keywords: string[];
15
- risk: string;
16
- extension: string;
17
- extName: string;
18
- }
19
-
20
- const NAME_WEIGHT = 3;
21
- const KEYWORD_WEIGHT = 2;
22
- const DESC_WEIGHT = 1;
23
-
24
- function toSearchable(ext: ExtensionManifest) {
25
- const out: Searchable[] = [];
26
- for (const tool of ext.tools) {
27
- out.push({
28
- name: tool.name.toLowerCase(),
29
- description: tool.description.toLowerCase(),
30
- keywords: (tool.keywords ?? []).map((k) => k.toLowerCase()),
31
- risk: tool.risk ?? "read",
32
- extension: ext.id,
33
- extName: ext.name.toLowerCase(),
34
- });
35
- }
36
- return out;
37
- }
38
-
39
- function bestWeight(s: Searchable, token: string): number {
40
- if (s.name.includes(token)) return NAME_WEIGHT;
41
- if (s.extName.includes(token)) return NAME_WEIGHT;
42
- if (s.keywords.some((k) => k.includes(token) || token.includes(k))) {
43
- return KEYWORD_WEIGHT;
44
- }
45
- if (s.description.includes(token)) return DESC_WEIGHT;
46
- return 0;
47
- }
48
-
49
- export function searchTools(query: string, manifests: ExtensionManifest[]): SearchHit[] {
50
- const tokens = query
51
- .toLowerCase()
52
- .split(/\s+/)
53
- .filter((t) => t.length > 0);
54
-
55
- if (tokens.length === 0) return [];
56
-
57
- const hits: SearchHit[] = [];
58
- for (const ext of manifests) {
59
- for (const s of toSearchable(ext)) {
60
- let score = 0;
61
- for (const token of tokens) {
62
- score += bestWeight(s, token);
63
- }
64
- if (score > 0) {
65
- hits.push({
66
- name: s.name,
67
- description: s.description,
68
- extension: s.extension,
69
- risk: s.risk,
70
- score,
71
- });
72
- }
73
- }
74
- }
75
-
76
- hits.sort((a, b) => b.score - a.score);
77
- return hits;
78
- }