agentikit 0.0.12 → 0.0.14

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 (146) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +186 -100
  3. package/dist/cli.js +671 -0
  4. package/dist/common.js +192 -0
  5. package/dist/{src/config-cli.js → config-cli.js} +14 -6
  6. package/dist/{src/config.js → config.js} +92 -24
  7. package/dist/{src/db.js → db.js} +109 -35
  8. package/dist/{src/embedder.js → embedder.js} +57 -2
  9. package/dist/file-context.js +158 -0
  10. package/dist/{src/handlers → handlers}/command-handler.js +2 -0
  11. package/dist/{src/handlers → handlers}/index.js +0 -6
  12. package/dist/{src/indexer.js → indexer.js} +34 -10
  13. package/dist/init.js +43 -0
  14. package/dist/lockfile.js +55 -0
  15. package/dist/matchers.js +157 -0
  16. package/dist/{src/metadata.js → metadata.js} +12 -1
  17. package/dist/{src/origin-resolve.js → origin-resolve.js} +10 -9
  18. package/dist/paths.js +82 -0
  19. package/dist/{src/registry-install.js → registry-install.js} +145 -17
  20. package/dist/{src/registry-resolve.js → registry-resolve.js} +178 -18
  21. package/dist/{src/registry-search.js → registry-search.js} +8 -16
  22. package/dist/renderers.js +276 -0
  23. package/dist/{src/ripgrep-install.js → ripgrep-install.js} +5 -5
  24. package/dist/{src/ripgrep-resolve.js → ripgrep-resolve.js} +21 -11
  25. package/dist/self-update.js +220 -0
  26. package/dist/{src/stash-add.js → stash-add.js} +11 -2
  27. package/dist/stash-clone.js +115 -0
  28. package/dist/{src/stash-registry.js → stash-registry.js} +15 -41
  29. package/dist/{src/stash-search.js → stash-search.js} +67 -55
  30. package/dist/{src/stash-show.js → stash-show.js} +30 -3
  31. package/dist/{src/stash-source.js → stash-source.js} +56 -9
  32. package/dist/submit.js +552 -0
  33. package/dist/{src/walker.js → walker.js} +38 -0
  34. package/package.json +7 -16
  35. package/dist/index.d.ts +0 -28
  36. package/dist/index.js +0 -15
  37. package/dist/src/asset-spec.d.ts +0 -16
  38. package/dist/src/asset-type-handler.d.ts +0 -27
  39. package/dist/src/cli.d.ts +0 -2
  40. package/dist/src/cli.js +0 -399
  41. package/dist/src/common.d.ts +0 -13
  42. package/dist/src/common.js +0 -60
  43. package/dist/src/config-cli.d.ts +0 -9
  44. package/dist/src/config.d.ts +0 -50
  45. package/dist/src/db.d.ts +0 -46
  46. package/dist/src/embedder.d.ts +0 -10
  47. package/dist/src/frontmatter.d.ts +0 -30
  48. package/dist/src/github.d.ts +0 -4
  49. package/dist/src/handlers/agent-handler.d.ts +0 -2
  50. package/dist/src/handlers/command-handler.d.ts +0 -2
  51. package/dist/src/handlers/index.d.ts +0 -6
  52. package/dist/src/handlers/knowledge-handler.d.ts +0 -2
  53. package/dist/src/handlers/markdown-helpers.d.ts +0 -7
  54. package/dist/src/handlers/script-handler.d.ts +0 -2
  55. package/dist/src/handlers/skill-handler.d.ts +0 -2
  56. package/dist/src/handlers/tool-handler.d.ts +0 -2
  57. package/dist/src/indexer.d.ts +0 -22
  58. package/dist/src/init.d.ts +0 -19
  59. package/dist/src/init.js +0 -99
  60. package/dist/src/llm.d.ts +0 -15
  61. package/dist/src/markdown.d.ts +0 -18
  62. package/dist/src/metadata.d.ts +0 -41
  63. package/dist/src/origin-resolve.d.ts +0 -19
  64. package/dist/src/registry-install.d.ts +0 -11
  65. package/dist/src/registry-resolve.d.ts +0 -3
  66. package/dist/src/registry-search.d.ts +0 -27
  67. package/dist/src/registry-types.d.ts +0 -62
  68. package/dist/src/ripgrep-install.d.ts +0 -12
  69. package/dist/src/ripgrep-resolve.d.ts +0 -13
  70. package/dist/src/ripgrep.d.ts +0 -3
  71. package/dist/src/similarity.js +0 -211
  72. package/dist/src/stash-add.d.ts +0 -4
  73. package/dist/src/stash-clone.d.ts +0 -22
  74. package/dist/src/stash-clone.js +0 -83
  75. package/dist/src/stash-ref.d.ts +0 -31
  76. package/dist/src/stash-registry.d.ts +0 -18
  77. package/dist/src/stash-resolve.d.ts +0 -2
  78. package/dist/src/stash-search.d.ts +0 -8
  79. package/dist/src/stash-show.d.ts +0 -5
  80. package/dist/src/stash-source.d.ts +0 -24
  81. package/dist/src/stash-types.d.ts +0 -227
  82. package/dist/src/stash.d.ts +0 -16
  83. package/dist/src/stash.js +0 -9
  84. package/dist/src/tool-runner.d.ts +0 -35
  85. package/dist/src/walker.d.ts +0 -19
  86. package/src/asset-spec.ts +0 -85
  87. package/src/asset-type-handler.ts +0 -77
  88. package/src/cli.ts +0 -427
  89. package/src/common.ts +0 -76
  90. package/src/config-cli.ts +0 -499
  91. package/src/config.ts +0 -305
  92. package/src/db.ts +0 -411
  93. package/src/embedder.ts +0 -128
  94. package/src/frontmatter.ts +0 -95
  95. package/src/github.ts +0 -21
  96. package/src/handlers/agent-handler.ts +0 -32
  97. package/src/handlers/command-handler.ts +0 -29
  98. package/src/handlers/index.ts +0 -25
  99. package/src/handlers/knowledge-handler.ts +0 -62
  100. package/src/handlers/markdown-helpers.ts +0 -19
  101. package/src/handlers/script-handler.ts +0 -92
  102. package/src/handlers/skill-handler.ts +0 -37
  103. package/src/handlers/tool-handler.ts +0 -71
  104. package/src/indexer.ts +0 -392
  105. package/src/init.ts +0 -114
  106. package/src/llm.ts +0 -125
  107. package/src/markdown.ts +0 -106
  108. package/src/metadata.ts +0 -333
  109. package/src/origin-resolve.ts +0 -67
  110. package/src/registry-install.ts +0 -361
  111. package/src/registry-resolve.ts +0 -341
  112. package/src/registry-search.ts +0 -335
  113. package/src/registry-types.ts +0 -72
  114. package/src/ripgrep-install.ts +0 -200
  115. package/src/ripgrep-resolve.ts +0 -72
  116. package/src/ripgrep.ts +0 -3
  117. package/src/stash-add.ts +0 -63
  118. package/src/stash-clone.ts +0 -127
  119. package/src/stash-ref.ts +0 -99
  120. package/src/stash-registry.ts +0 -259
  121. package/src/stash-resolve.ts +0 -50
  122. package/src/stash-search.ts +0 -613
  123. package/src/stash-show.ts +0 -55
  124. package/src/stash-source.ts +0 -103
  125. package/src/stash-types.ts +0 -231
  126. package/src/stash.ts +0 -39
  127. package/src/tool-runner.ts +0 -142
  128. package/src/walker.ts +0 -53
  129. /package/dist/{src/asset-spec.js → asset-spec.js} +0 -0
  130. /package/dist/{src/asset-type-handler.js → asset-type-handler.js} +0 -0
  131. /package/dist/{src/frontmatter.js → frontmatter.js} +0 -0
  132. /package/dist/{src/github.js → github.js} +0 -0
  133. /package/dist/{src/handlers → handlers}/agent-handler.js +0 -0
  134. /package/dist/{src/handlers → handlers}/knowledge-handler.js +0 -0
  135. /package/dist/{src/handlers → handlers}/markdown-helpers.js +0 -0
  136. /package/dist/{src/handlers → handlers}/script-handler.js +0 -0
  137. /package/dist/{src/handlers → handlers}/skill-handler.js +0 -0
  138. /package/dist/{src/handlers → handlers}/tool-handler.js +0 -0
  139. /package/dist/{src/llm.js → llm.js} +0 -0
  140. /package/dist/{src/markdown.js → markdown.js} +0 -0
  141. /package/dist/{src/registry-types.js → registry-types.js} +0 -0
  142. /package/dist/{src/ripgrep.js → ripgrep.js} +0 -0
  143. /package/dist/{src/stash-ref.js → stash-ref.js} +0 -0
  144. /package/dist/{src/stash-resolve.js → stash-resolve.js} +0 -0
  145. /package/dist/{src/stash-types.js → stash-types.js} +0 -0
  146. /package/dist/{src/tool-runner.js → tool-runner.js} +0 -0
@@ -1,30 +0,0 @@
1
- /**
2
- * Shared frontmatter parsing utilities.
3
- *
4
- * Provides a single, canonical YAML-subset frontmatter parser used by both
5
- * the stash open logic and the metadata generator.
6
- */
7
- /**
8
- * Parse YAML-subset frontmatter from a Markdown (or similar) string.
9
- *
10
- * Returns the parsed key-value data and the remaining body content.
11
- */
12
- export declare function parseFrontmatter(raw: string): {
13
- data: Record<string, unknown>;
14
- content: string;
15
- frontmatter: string | null;
16
- bodyStartLine: number;
17
- };
18
- export declare function parseFrontmatterBlock(raw: string): {
19
- frontmatter: string;
20
- content: string;
21
- bodyStartLine: number;
22
- } | null;
23
- /**
24
- * Parse a simple YAML scalar value (string, boolean, or number).
25
- */
26
- export declare function parseYamlScalar(value: string): unknown;
27
- /**
28
- * Coerce an unknown value to a trimmed string, or return undefined if empty/non-string.
29
- */
30
- export declare function toStringOrUndefined(value: unknown): string | undefined;
@@ -1,4 +0,0 @@
1
- export declare const GITHUB_API_BASE = "https://api.github.com";
2
- export declare function githubHeaders(): HeadersInit;
3
- export declare function asRecord(value: unknown): Record<string, unknown>;
4
- export declare function asString(value: unknown): string | undefined;
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const agentHandler: AssetTypeHandler;
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const commandHandler: AssetTypeHandler;
@@ -1,6 +0,0 @@
1
- export { toolHandler } from "./tool-handler";
2
- export { skillHandler } from "./skill-handler";
3
- export { commandHandler } from "./command-handler";
4
- export { agentHandler } from "./agent-handler";
5
- export { knowledgeHandler } from "./knowledge-handler";
6
- export { scriptHandler } from "./script-handler";
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const knowledgeHandler: AssetTypeHandler;
@@ -1,7 +0,0 @@
1
- /**
2
- * Shared file-system helpers for markdown-based asset types
3
- * (command, agent, knowledge).
4
- */
5
- export declare function isMarkdownFile(fileName: string): boolean;
6
- export declare function markdownCanonicalName(typeRoot: string, filePath: string): string | undefined;
7
- export declare function markdownAssetPath(typeRoot: string, name: string): string;
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const scriptHandler: AssetTypeHandler;
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const skillHandler: AssetTypeHandler;
@@ -1,2 +0,0 @@
1
- import type { AssetTypeHandler } from "../asset-type-handler";
2
- export declare const toolHandler: AssetTypeHandler;
@@ -1,22 +0,0 @@
1
- import { type StashEntry } from "./metadata";
2
- export interface IndexResponse {
3
- stashDir: string;
4
- totalEntries: number;
5
- generatedMetadata: number;
6
- indexPath: string;
7
- mode: "full" | "incremental";
8
- directoriesScanned: number;
9
- directoriesSkipped: number;
10
- /** Timing counters in milliseconds */
11
- timing?: {
12
- totalMs: number;
13
- walkMs: number;
14
- embedMs: number;
15
- ftsMs: number;
16
- };
17
- }
18
- export declare function agentikitIndex(options?: {
19
- stashDir?: string;
20
- full?: boolean;
21
- }): Promise<IndexResponse>;
22
- export declare function buildSearchText(entry: StashEntry): string;
@@ -1,19 +0,0 @@
1
- /**
2
- * Agentikit initialization logic.
3
- *
4
- * Creates the working stash directory structure, sets the AKM_STASH_DIR
5
- * environment variable, and ensures ripgrep is available.
6
- */
7
- export interface InitResponse {
8
- stashDir: string;
9
- created: boolean;
10
- envSet: boolean;
11
- profileUpdated?: string;
12
- configPath: string;
13
- ripgrep?: {
14
- rgPath: string;
15
- installed: boolean;
16
- version: string;
17
- };
18
- }
19
- export declare function agentikitInit(): Promise<InitResponse>;
package/dist/src/init.js DELETED
@@ -1,99 +0,0 @@
1
- /**
2
- * Agentikit initialization logic.
3
- *
4
- * Creates the working stash directory structure, sets the AKM_STASH_DIR
5
- * environment variable, and ensures ripgrep is available.
6
- */
7
- import { spawnSync } from "node:child_process";
8
- import fs from "node:fs";
9
- import path from "node:path";
10
- import { IS_WINDOWS, TYPE_DIRS } from "./common";
11
- import { ensureRg } from "./ripgrep-install";
12
- import { getConfigPath, saveConfig, DEFAULT_CONFIG } from "./config";
13
- export async function agentikitInit() {
14
- let stashDir;
15
- if (IS_WINDOWS) {
16
- const userProfile = process.env.USERPROFILE?.trim();
17
- if (!userProfile) {
18
- throw new Error("Unable to determine Documents folder. Ensure USERPROFILE is set.");
19
- }
20
- const docs = path.join(userProfile, "Documents");
21
- stashDir = path.join(docs, "agentikit");
22
- }
23
- else {
24
- const home = process.env.HOME?.trim();
25
- if (!home) {
26
- throw new Error("Unable to determine home directory. Set HOME.");
27
- }
28
- stashDir = path.join(home, "agentikit");
29
- }
30
- let created = false;
31
- if (!fs.existsSync(stashDir)) {
32
- fs.mkdirSync(stashDir, { recursive: true });
33
- created = true;
34
- }
35
- for (const sub of Object.values(TYPE_DIRS)) {
36
- const subDir = path.join(stashDir, sub);
37
- if (!fs.existsSync(subDir)) {
38
- fs.mkdirSync(subDir, { recursive: true });
39
- }
40
- }
41
- let envSet = false;
42
- let profileUpdated;
43
- if (IS_WINDOWS) {
44
- const result = spawnSync("setx", ["AKM_STASH_DIR", stashDir], {
45
- encoding: "utf8",
46
- timeout: 10_000,
47
- });
48
- envSet = result.status === 0;
49
- }
50
- else {
51
- const shell = process.env.SHELL || "";
52
- const homeDir = process.env.HOME; // already validated non-empty above
53
- let profile;
54
- if (shell.endsWith("/zsh")) {
55
- profile = path.join(homeDir, ".zshrc");
56
- }
57
- else if (shell.endsWith("/bash")) {
58
- profile = path.join(homeDir, ".bashrc");
59
- }
60
- else {
61
- profile = path.join(homeDir, ".profile");
62
- }
63
- const exportLine = `export AKM_STASH_DIR="${stashDir}"`;
64
- const existing = fs.existsSync(profile) ? fs.readFileSync(profile, "utf8") : "";
65
- if (!existing.includes("AKM_STASH_DIR")) {
66
- const updated = existing + `\n# Agentikit working stash directory\n${exportLine}\n`;
67
- const tmpPath = profile + `.tmp.${process.pid}`;
68
- try {
69
- fs.writeFileSync(tmpPath, updated, "utf8");
70
- fs.renameSync(tmpPath, profile);
71
- }
72
- catch (err) {
73
- try {
74
- fs.unlinkSync(tmpPath);
75
- }
76
- catch { /* ignore */ }
77
- throw err;
78
- }
79
- envSet = true;
80
- profileUpdated = profile;
81
- }
82
- }
83
- // Create default config.json if it doesn't exist
84
- const configPath = getConfigPath();
85
- if (!fs.existsSync(configPath)) {
86
- saveConfig(DEFAULT_CONFIG);
87
- }
88
- process.env.AKM_STASH_DIR = stashDir;
89
- // Ensure ripgrep is available (install to stash/bin if needed)
90
- let ripgrep;
91
- try {
92
- const rgResult = ensureRg(stashDir);
93
- ripgrep = rgResult;
94
- }
95
- catch {
96
- // Non-fatal: ripgrep is optional, search works without it
97
- }
98
- return { stashDir, created, envSet, profileUpdated, configPath, ripgrep };
99
- }
package/dist/src/llm.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { LlmConnectionConfig } from "./config";
2
- import type { StashEntry } from "./metadata";
3
- /**
4
- * Use an LLM to enhance a stash entry's metadata: improve description,
5
- * generate intents, and suggest tags.
6
- */
7
- export declare function enhanceMetadata(config: LlmConnectionConfig, entry: StashEntry, fileContent?: string): Promise<{
8
- description?: string;
9
- intents?: string[];
10
- tags?: string[];
11
- }>;
12
- /**
13
- * Check if the LLM endpoint is reachable.
14
- */
15
- export declare function isLlmAvailable(config: LlmConnectionConfig): Promise<boolean>;
@@ -1,18 +0,0 @@
1
- export interface TocHeading {
2
- level: number;
3
- text: string;
4
- line: number;
5
- }
6
- export interface KnowledgeToc {
7
- headings: TocHeading[];
8
- totalLines: number;
9
- }
10
- export declare function parseMarkdownToc(content: string): KnowledgeToc;
11
- export declare function extractSection(content: string, heading: string): {
12
- content: string;
13
- startLine: number;
14
- endLine: number;
15
- } | null;
16
- export declare function extractLineRange(content: string, start: number, end: number): string;
17
- export declare function extractFrontmatterOnly(content: string): string | null;
18
- export declare function formatToc(toc: KnowledgeToc): string;
@@ -1,41 +0,0 @@
1
- import { type AgentikitAssetType } from "./common";
2
- import { type TocHeading } from "./markdown";
3
- export interface StashIntent {
4
- when?: string;
5
- input?: string;
6
- output?: string;
7
- }
8
- export interface StashEntry {
9
- name: string;
10
- type: AgentikitAssetType;
11
- description?: string;
12
- tags?: string[];
13
- examples?: string[];
14
- intents?: string[];
15
- intent?: StashIntent;
16
- entry?: string;
17
- generated?: boolean;
18
- quality?: "generated" | "curated";
19
- confidence?: number;
20
- source?: "package" | "frontmatter" | "comments" | "filename" | "manual" | "llm";
21
- aliases?: string[];
22
- toc?: TocHeading[];
23
- usage?: string[];
24
- }
25
- export interface StashFile {
26
- entries: StashEntry[];
27
- }
28
- export declare function stashFilePath(dirPath: string): string;
29
- export declare function loadStashFile(dirPath: string): StashFile | null;
30
- export declare function writeStashFile(dirPath: string, stash: StashFile): void;
31
- export declare function validateStashEntry(entry: unknown): StashEntry | null;
32
- export declare function generateMetadata(dirPath: string, assetType: AgentikitAssetType, files: string[], typeRoot?: string): StashFile;
33
- export declare function extractDescriptionFromComments(filePath: string): string | null;
34
- export declare function extractFrontmatterDescription(filePath: string): string | null;
35
- export declare function extractPackageMetadata(dirPath: string): {
36
- name?: string;
37
- description?: string;
38
- keywords?: string[];
39
- } | null;
40
- export declare function fileNameToDescription(fileName: string): string;
41
- export declare function extractTagsFromPath(filePath: string, rootDir: string): string[];
@@ -1,19 +0,0 @@
1
- import type { StashSource } from "./stash-source";
2
- /**
3
- * Given an origin string (from an AssetRef) and the full list of stash
4
- * sources, return the subset of sources to search.
5
- *
6
- * Resolution order:
7
- * 1. undefined → all sources (working → mounted → installed)
8
- * 2. "local" → working stash only
9
- * 3. exact match → installed source whose registryId matches verbatim
10
- * 4. parsed match → parse origin as a registry ref, match by parsed ID
11
- * 5. path match → mounted source whose path matches
12
- * 6. empty → indicates a remote/uninstalled origin (caller decides)
13
- */
14
- export declare function resolveSourcesForOrigin(origin: string | undefined, allSources: StashSource[]): StashSource[];
15
- /**
16
- * Check whether an origin refers to something that could be fetched remotely
17
- * (i.e. it looks like a registry ref but isn't installed locally).
18
- */
19
- export declare function isRemoteOrigin(origin: string, allSources: StashSource[]): boolean;
@@ -1,11 +0,0 @@
1
- import { type AgentikitConfig } from "./config";
2
- import type { RegistryInstallResult, RegistryInstalledEntry } from "./registry-types";
3
- export interface InstallRegistryRefOptions {
4
- cacheRootDir?: string;
5
- now?: Date;
6
- }
7
- export declare function installRegistryRef(ref: string, options?: InstallRegistryRefOptions): Promise<RegistryInstallResult>;
8
- export declare function upsertInstalledRegistryEntry(entry: RegistryInstalledEntry): AgentikitConfig;
9
- export declare function removeInstalledRegistryEntry(id: string): AgentikitConfig;
10
- export declare function getRegistryCacheRootDir(): string;
11
- export declare function detectStashRoot(extractedDir: string): string;
@@ -1,3 +0,0 @@
1
- import type { ParsedRegistryRef, ResolvedRegistryArtifact } from "./registry-types";
2
- export declare function parseRegistryRef(rawRef: string): ParsedRegistryRef;
3
- export declare function resolveRegistryArtifact(parsed: ParsedRegistryRef): Promise<ResolvedRegistryArtifact>;
@@ -1,27 +0,0 @@
1
- import type { RegistrySearchResponse } from "./registry-types";
2
- export interface RegistryIndex {
3
- version: number;
4
- updatedAt: string;
5
- kits: RegistryKitEntry[];
6
- }
7
- export interface RegistryKitEntry {
8
- id: string;
9
- name: string;
10
- description?: string;
11
- ref: string;
12
- source: "npm" | "github" | "git";
13
- homepage?: string;
14
- tags?: string[];
15
- assetTypes?: string[];
16
- author?: string;
17
- license?: string;
18
- latestVersion?: string;
19
- /** Whether this entry was manually reviewed and approved */
20
- curated?: boolean;
21
- }
22
- export interface RegistrySearchOptions {
23
- limit?: number;
24
- /** Override registry URL(s). Accepts a single URL or an array. */
25
- registryUrls?: string | string[];
26
- }
27
- export declare function searchRegistry(query: string, options?: RegistrySearchOptions): Promise<RegistrySearchResponse>;
@@ -1,62 +0,0 @@
1
- export type RegistrySource = "npm" | "github" | "git";
2
- export interface RegistryRefBase {
3
- source: RegistrySource;
4
- ref: string;
5
- id: string;
6
- }
7
- export interface ParsedNpmRef extends RegistryRefBase {
8
- source: "npm";
9
- packageName: string;
10
- requestedVersionOrTag?: string;
11
- }
12
- export interface ParsedGithubRef extends RegistryRefBase {
13
- source: "github";
14
- owner: string;
15
- repo: string;
16
- requestedRef?: string;
17
- }
18
- export interface ParsedGitRef extends RegistryRefBase {
19
- source: "git";
20
- repoRoot: string;
21
- sourcePath: string;
22
- }
23
- export type ParsedRegistryRef = ParsedNpmRef | ParsedGithubRef | ParsedGitRef;
24
- export interface ResolvedRegistryArtifact {
25
- id: string;
26
- source: RegistrySource;
27
- ref: string;
28
- artifactUrl: string;
29
- resolvedVersion?: string;
30
- resolvedRevision?: string;
31
- }
32
- export interface RegistryInstalledEntry {
33
- id: string;
34
- source: RegistrySource;
35
- ref: string;
36
- resolvedVersion?: string;
37
- resolvedRevision?: string;
38
- artifactUrl: string;
39
- stashRoot: string;
40
- cacheDir: string;
41
- installedAt: string;
42
- }
43
- export interface RegistryInstallResult extends RegistryInstalledEntry {
44
- extractedDir: string;
45
- }
46
- export interface RegistrySearchHit {
47
- source: RegistrySource;
48
- id: string;
49
- title: string;
50
- description?: string;
51
- ref: string;
52
- homepage?: string;
53
- score?: number;
54
- metadata?: Record<string, string>;
55
- /** Whether this entry was manually reviewed and approved */
56
- curated?: boolean;
57
- }
58
- export interface RegistrySearchResponse {
59
- query: string;
60
- hits: RegistrySearchHit[];
61
- warnings: string[];
62
- }
@@ -1,12 +0,0 @@
1
- export interface EnsureRgResult {
2
- rgPath: string;
3
- installed: boolean;
4
- version: string;
5
- }
6
- /**
7
- * Ensure ripgrep is available. If not found on PATH or in stash/bin,
8
- * download and install it to stash/bin.
9
- *
10
- * Returns the path to the ripgrep binary and whether it was newly installed.
11
- */
12
- export declare function ensureRg(stashDir: string): EnsureRgResult;
@@ -1,13 +0,0 @@
1
- export declare const RG_BINARY: string;
2
- /**
3
- * Resolve the path to a usable ripgrep binary.
4
- * Checks in order:
5
- * 1. stashDir/bin/rg
6
- * 2. system PATH (rg)
7
- * Returns null if ripgrep is not available.
8
- */
9
- export declare function resolveRg(stashDir?: string): string | null;
10
- /**
11
- * Check if ripgrep is available (either in stash/bin or system PATH).
12
- */
13
- export declare function isRgAvailable(stashDir?: string): boolean;
@@ -1,3 +0,0 @@
1
- export { resolveRg, isRgAvailable } from "./ripgrep-resolve";
2
- export { ensureRg } from "./ripgrep-install";
3
- export type { EnsureRgResult } from "./ripgrep-install";
@@ -1,211 +0,0 @@
1
- export class TfIdfAdapter {
2
- documents = [];
3
- idf = new Map();
4
- entries = [];
5
- buildIndex(entries) {
6
- this.entries = entries;
7
- const docCount = entries.length;
8
- if (docCount === 0)
9
- return;
10
- // Compute term frequencies per document
11
- const docFreqs = new Map();
12
- this.documents = entries.map((entry) => {
13
- const tokens = tokenize(entry.text);
14
- const termFreqs = new Map();
15
- for (const token of tokens) {
16
- termFreqs.set(token, (termFreqs.get(token) || 0) + 1);
17
- }
18
- // Track document frequency for IDF
19
- for (const term of termFreqs.keys()) {
20
- docFreqs.set(term, (docFreqs.get(term) || 0) + 1);
21
- }
22
- return { entry, termFreqs, magnitude: 0 };
23
- });
24
- // Compute IDF: log(N / df)
25
- this.idf = new Map();
26
- for (const [term, df] of docFreqs) {
27
- this.idf.set(term, Math.log(docCount / df));
28
- }
29
- // Compute document magnitudes for cosine similarity
30
- for (const doc of this.documents) {
31
- let sumSq = 0;
32
- for (const [term, tf] of doc.termFreqs) {
33
- const idf = this.idf.get(term) || 0;
34
- const tfidf = tf * idf;
35
- sumSq += tfidf * tfidf;
36
- }
37
- doc.magnitude = Math.sqrt(sumSq);
38
- }
39
- }
40
- search(query, limit, typeFilter) {
41
- if (this.documents.length === 0)
42
- return [];
43
- const queryTokens = tokenize(query.toLowerCase());
44
- if (queryTokens.length === 0) {
45
- // Empty query: return all, sorted by type
46
- return this.documents
47
- .filter((d) => !typeFilter || typeFilter === "any" || d.entry.entry.type === typeFilter)
48
- .slice(0, limit)
49
- .map((d) => ({
50
- entry: d.entry.entry,
51
- path: d.entry.path,
52
- score: 1,
53
- }));
54
- }
55
- // Build query TF-IDF vector
56
- const queryTermFreqs = new Map();
57
- for (const token of queryTokens) {
58
- queryTermFreqs.set(token, (queryTermFreqs.get(token) || 0) + 1);
59
- }
60
- let queryMagnitude = 0;
61
- const queryVector = new Map();
62
- for (const [term, tf] of queryTermFreqs) {
63
- const idf = this.idf.get(term) || 0;
64
- const tfidf = tf * idf;
65
- queryVector.set(term, tfidf);
66
- queryMagnitude += tfidf * tfidf;
67
- }
68
- queryMagnitude = Math.sqrt(queryMagnitude);
69
- if (queryMagnitude === 0) {
70
- // All query terms are unknown — fallback to substring match
71
- return this.substringFallback(query, limit, typeFilter);
72
- }
73
- const results = [];
74
- const querySet = new Set(queryTokens);
75
- for (const doc of this.documents) {
76
- if (typeFilter && typeFilter !== "any" && doc.entry.entry.type !== typeFilter)
77
- continue;
78
- // Cosine similarity
79
- let dotProduct = 0;
80
- for (const [term, queryTfidf] of queryVector) {
81
- const docTf = doc.termFreqs.get(term) || 0;
82
- if (docTf === 0)
83
- continue;
84
- const docIdf = this.idf.get(term) || 0;
85
- dotProduct += queryTfidf * (docTf * docIdf);
86
- }
87
- let score = doc.magnitude > 0 && queryMagnitude > 0
88
- ? dotProduct / (doc.magnitude * queryMagnitude)
89
- : 0;
90
- // Boost: tag exact match
91
- const tags = doc.entry.entry.tags || [];
92
- for (const tag of tags) {
93
- if (querySet.has(tag.toLowerCase())) {
94
- score += 0.15;
95
- }
96
- }
97
- // Boost: intent phrase contains query token
98
- const intents = doc.entry.entry.intents || [];
99
- for (const intent of intents) {
100
- const intentLower = intent.toLowerCase();
101
- for (const token of queryTokens) {
102
- if (intentLower.includes(token)) {
103
- score += 0.12;
104
- break; // one boost per intent phrase
105
- }
106
- }
107
- }
108
- // Boost: name contains query token
109
- const nameLower = doc.entry.entry.name.toLowerCase().replace(/[-_]/g, " ");
110
- for (const token of queryTokens) {
111
- if (nameLower.includes(token)) {
112
- score += 0.1;
113
- break;
114
- }
115
- }
116
- if (score > 0) {
117
- results.push({
118
- entry: doc.entry.entry,
119
- path: doc.entry.path,
120
- score: Math.round(score * 1000) / 1000,
121
- });
122
- }
123
- }
124
- results.sort((a, b) => b.score - a.score);
125
- return results.slice(0, limit);
126
- }
127
- serialize() {
128
- const idf = {};
129
- for (const [term, val] of this.idf) {
130
- idf[term] = val;
131
- }
132
- const docs = this.documents.map((d) => {
133
- const termFreqs = {};
134
- for (const [term, tf] of d.termFreqs) {
135
- termFreqs[term] = tf;
136
- }
137
- return { id: d.entry.id, termFreqs, magnitude: d.magnitude };
138
- });
139
- return { idf, docs };
140
- }
141
- static deserialize(data, entries) {
142
- const adapter = new TfIdfAdapter();
143
- adapter.entries = entries;
144
- adapter.idf = new Map(Object.entries(data.idf));
145
- const entryMap = new Map(entries.map((e) => [e.id, e]));
146
- adapter.documents = data.docs
147
- .map((d) => {
148
- const entry = entryMap.get(d.id);
149
- if (!entry)
150
- return null;
151
- return {
152
- entry,
153
- termFreqs: new Map(Object.entries(d.termFreqs)),
154
- magnitude: d.magnitude,
155
- };
156
- })
157
- .filter((d) => d !== null);
158
- return adapter;
159
- }
160
- substringFallback(query, limit, typeFilter) {
161
- const q = query.toLowerCase();
162
- const tokens = tokenize(q);
163
- return this.documents
164
- .map((d) => {
165
- if (typeFilter && typeFilter !== "any" && d.entry.entry.type !== typeFilter)
166
- return null;
167
- // Check if any query token matches the document text or name
168
- const text = d.entry.text;
169
- const name = d.entry.entry.name.toLowerCase();
170
- let matchCount = 0;
171
- for (const token of tokens) {
172
- if (text.includes(token) || name.includes(token))
173
- matchCount++;
174
- }
175
- // Also check full substring match
176
- if (text.includes(q) || name.includes(q))
177
- matchCount = Math.max(matchCount, tokens.length);
178
- if (matchCount === 0)
179
- return null;
180
- return {
181
- entry: d.entry.entry,
182
- path: d.entry.path,
183
- score: Math.round((matchCount / Math.max(tokens.length, 1)) * 500) / 1000,
184
- };
185
- })
186
- .filter((d) => d !== null)
187
- .sort((a, b) => b.score - a.score)
188
- .slice(0, limit);
189
- }
190
- }
191
- // ── Tokenization ────────────────────────────────────────────────────────────
192
- const STOP_WORDS = new Set([
193
- "a", "an", "the", "is", "are", "was", "were", "be", "been", "being",
194
- "have", "has", "had", "do", "does", "did", "will", "would", "could",
195
- "should", "may", "might", "shall", "can", "need", "dare", "ought",
196
- "to", "of", "in", "for", "on", "with", "at", "by", "from", "as",
197
- "into", "through", "during", "before", "after", "above", "below",
198
- "and", "but", "or", "nor", "not", "so", "yet", "both", "either",
199
- "neither", "each", "every", "all", "any", "few", "more", "most",
200
- "other", "some", "such", "no", "only", "own", "same", "than",
201
- "too", "very", "just", "because", "if", "when", "where", "how",
202
- "what", "which", "who", "whom", "this", "that", "these", "those",
203
- "it", "its",
204
- ]);
205
- function tokenize(text) {
206
- return text
207
- .toLowerCase()
208
- .replace(/[^a-z0-9]+/g, " ")
209
- .split(/\s+/)
210
- .filter((t) => t.length > 1 && !STOP_WORDS.has(t));
211
- }