agentikit 0.0.13 → 0.0.15

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 (156) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +187 -110
  3. package/dist/{src/asset-spec.js → asset-spec.js} +11 -2
  4. package/dist/{src/asset-type-handler.js → asset-type-handler.js} +4 -3
  5. package/dist/cli.js +709 -0
  6. package/dist/common.js +192 -0
  7. package/dist/{src/config-cli.js → config-cli.js} +36 -30
  8. package/dist/{src/config.js → config.js} +95 -25
  9. package/dist/{src/db.js → db.js} +123 -51
  10. package/dist/{src/embedder.js → embedder.js} +57 -2
  11. package/dist/errors.js +28 -0
  12. package/dist/file-context.js +188 -0
  13. package/dist/{src/frontmatter.js → frontmatter.js} +1 -1
  14. package/dist/{src/github.js → github.js} +1 -3
  15. package/dist/handlers/agent-handler.js +19 -0
  16. package/dist/handlers/command-handler.js +20 -0
  17. package/dist/handlers/handler-bridge.js +51 -0
  18. package/dist/handlers/index.js +19 -0
  19. package/dist/handlers/knowledge-handler.js +32 -0
  20. package/dist/handlers/script-handler.js +42 -0
  21. package/dist/{src/handlers → handlers}/skill-handler.js +5 -6
  22. package/dist/{src/handlers → handlers}/tool-handler.js +8 -24
  23. package/dist/{src/indexer.js → indexer.js} +50 -26
  24. package/dist/init.js +43 -0
  25. package/dist/{src/llm.js → llm.js} +6 -11
  26. package/dist/lockfile.js +60 -0
  27. package/dist/matchers.js +163 -0
  28. package/dist/{src/metadata.js → metadata.js} +36 -16
  29. package/dist/{src/origin-resolve.js → origin-resolve.js} +10 -9
  30. package/dist/paths.js +83 -0
  31. package/dist/{src/registry-install.js → registry-install.js} +151 -19
  32. package/dist/{src/registry-resolve.js → registry-resolve.js} +190 -26
  33. package/dist/{src/registry-search.js → registry-search.js} +13 -21
  34. package/dist/renderers.js +286 -0
  35. package/dist/{src/ripgrep-install.js → ripgrep-install.js} +8 -27
  36. package/dist/{src/ripgrep-resolve.js → ripgrep-resolve.js} +21 -11
  37. package/dist/ripgrep.js +2 -0
  38. package/dist/self-update.js +226 -0
  39. package/dist/{src/stash-add.js → stash-add.js} +14 -4
  40. package/dist/stash-clone.js +115 -0
  41. package/dist/{src/stash-ref.js → stash-ref.js} +10 -9
  42. package/dist/{src/stash-registry.js → stash-registry.js} +21 -46
  43. package/dist/{src/stash-resolve.js → stash-resolve.js} +10 -9
  44. package/dist/{src/stash-search.js → stash-search.js} +89 -74
  45. package/dist/stash-show.js +74 -0
  46. package/dist/stash-source.js +127 -0
  47. package/dist/submit.js +557 -0
  48. package/dist/{src/tool-runner.js → tool-runner.js} +1 -5
  49. package/dist/{src/walker.js → walker.js} +38 -0
  50. package/dist/warn.js +20 -0
  51. package/package.json +13 -18
  52. package/dist/index.d.ts +0 -28
  53. package/dist/index.js +0 -15
  54. package/dist/src/asset-spec.d.ts +0 -16
  55. package/dist/src/asset-type-handler.d.ts +0 -27
  56. package/dist/src/cli.d.ts +0 -2
  57. package/dist/src/cli.js +0 -399
  58. package/dist/src/common.d.ts +0 -13
  59. package/dist/src/common.js +0 -60
  60. package/dist/src/config-cli.d.ts +0 -9
  61. package/dist/src/config.d.ts +0 -50
  62. package/dist/src/db.d.ts +0 -46
  63. package/dist/src/embedder.d.ts +0 -10
  64. package/dist/src/frontmatter.d.ts +0 -30
  65. package/dist/src/github.d.ts +0 -4
  66. package/dist/src/handlers/agent-handler.d.ts +0 -2
  67. package/dist/src/handlers/agent-handler.js +0 -26
  68. package/dist/src/handlers/command-handler.d.ts +0 -2
  69. package/dist/src/handlers/command-handler.js +0 -23
  70. package/dist/src/handlers/index.d.ts +0 -6
  71. package/dist/src/handlers/index.js +0 -23
  72. package/dist/src/handlers/knowledge-handler.d.ts +0 -2
  73. package/dist/src/handlers/knowledge-handler.js +0 -56
  74. package/dist/src/handlers/markdown-helpers.d.ts +0 -7
  75. package/dist/src/handlers/script-handler.d.ts +0 -2
  76. package/dist/src/handlers/script-handler.js +0 -78
  77. package/dist/src/handlers/skill-handler.d.ts +0 -2
  78. package/dist/src/handlers/tool-handler.d.ts +0 -2
  79. package/dist/src/indexer.d.ts +0 -22
  80. package/dist/src/init.d.ts +0 -19
  81. package/dist/src/init.js +0 -99
  82. package/dist/src/llm.d.ts +0 -15
  83. package/dist/src/markdown.d.ts +0 -18
  84. package/dist/src/metadata.d.ts +0 -41
  85. package/dist/src/origin-resolve.d.ts +0 -19
  86. package/dist/src/registry-install.d.ts +0 -11
  87. package/dist/src/registry-resolve.d.ts +0 -3
  88. package/dist/src/registry-search.d.ts +0 -27
  89. package/dist/src/registry-types.d.ts +0 -62
  90. package/dist/src/ripgrep-install.d.ts +0 -12
  91. package/dist/src/ripgrep-resolve.d.ts +0 -13
  92. package/dist/src/ripgrep.d.ts +0 -3
  93. package/dist/src/ripgrep.js +0 -2
  94. package/dist/src/stash-add.d.ts +0 -4
  95. package/dist/src/stash-clone.d.ts +0 -22
  96. package/dist/src/stash-clone.js +0 -83
  97. package/dist/src/stash-ref.d.ts +0 -31
  98. package/dist/src/stash-registry.d.ts +0 -18
  99. package/dist/src/stash-resolve.d.ts +0 -2
  100. package/dist/src/stash-search.d.ts +0 -8
  101. package/dist/src/stash-show.d.ts +0 -5
  102. package/dist/src/stash-show.js +0 -46
  103. package/dist/src/stash-source.d.ts +0 -24
  104. package/dist/src/stash-source.js +0 -81
  105. package/dist/src/stash-types.d.ts +0 -227
  106. package/dist/src/stash.d.ts +0 -16
  107. package/dist/src/stash.js +0 -9
  108. package/dist/src/tool-runner.d.ts +0 -35
  109. package/dist/src/walker.d.ts +0 -19
  110. package/src/asset-spec.ts +0 -85
  111. package/src/asset-type-handler.ts +0 -77
  112. package/src/cli.ts +0 -427
  113. package/src/common.ts +0 -76
  114. package/src/config-cli.ts +0 -499
  115. package/src/config.ts +0 -305
  116. package/src/db.ts +0 -411
  117. package/src/embedder.ts +0 -128
  118. package/src/frontmatter.ts +0 -95
  119. package/src/github.ts +0 -21
  120. package/src/handlers/agent-handler.ts +0 -32
  121. package/src/handlers/command-handler.ts +0 -29
  122. package/src/handlers/index.ts +0 -25
  123. package/src/handlers/knowledge-handler.ts +0 -62
  124. package/src/handlers/markdown-helpers.ts +0 -19
  125. package/src/handlers/script-handler.ts +0 -92
  126. package/src/handlers/skill-handler.ts +0 -37
  127. package/src/handlers/tool-handler.ts +0 -71
  128. package/src/indexer.ts +0 -392
  129. package/src/init.ts +0 -114
  130. package/src/llm.ts +0 -125
  131. package/src/markdown.ts +0 -106
  132. package/src/metadata.ts +0 -333
  133. package/src/origin-resolve.ts +0 -67
  134. package/src/registry-install.ts +0 -361
  135. package/src/registry-resolve.ts +0 -341
  136. package/src/registry-search.ts +0 -335
  137. package/src/registry-types.ts +0 -72
  138. package/src/ripgrep-install.ts +0 -200
  139. package/src/ripgrep-resolve.ts +0 -72
  140. package/src/ripgrep.ts +0 -3
  141. package/src/stash-add.ts +0 -63
  142. package/src/stash-clone.ts +0 -127
  143. package/src/stash-ref.ts +0 -99
  144. package/src/stash-registry.ts +0 -259
  145. package/src/stash-resolve.ts +0 -50
  146. package/src/stash-search.ts +0 -613
  147. package/src/stash-show.ts +0 -55
  148. package/src/stash-source.ts +0 -103
  149. package/src/stash-types.ts +0 -231
  150. package/src/stash.ts +0 -39
  151. package/src/tool-runner.ts +0 -142
  152. package/src/walker.ts +0 -53
  153. /package/dist/{src/handlers → handlers}/markdown-helpers.js +0 -0
  154. /package/dist/{src/markdown.js → markdown.js} +0 -0
  155. /package/dist/{src/registry-types.js → registry-types.js} +0 -0
  156. /package/dist/{src/stash-types.js → stash-types.js} +0 -0
@@ -1,227 +0,0 @@
1
- import type { AgentikitAssetType } from "./common";
2
- import type { RegistrySource } from "./registry-types";
3
- import type { ToolKind } from "./tool-runner";
4
- export type AgentikitSearchType = AgentikitAssetType | "any";
5
- export type SearchUsageMode = "none" | "both" | "item" | "guide";
6
- export type SearchSource = "local" | "registry" | "both";
7
- export interface LocalSearchHit {
8
- hitSource: "local";
9
- type: AgentikitAssetType;
10
- name: string;
11
- path: string;
12
- openRef: string;
13
- /** For installed sources, the registry id */
14
- registryId?: string;
15
- /** Whether this asset is editable (only true for working stash) */
16
- editable?: boolean;
17
- description?: string;
18
- tags?: string[];
19
- score?: number;
20
- whyMatched?: string[];
21
- runCmd?: string;
22
- kind?: ToolKind;
23
- usage?: string[];
24
- }
25
- export interface RegistrySearchResultHit {
26
- hitSource: "registry";
27
- type: "registry";
28
- name: string;
29
- path?: string;
30
- openRef?: string;
31
- id: string;
32
- registrySource: RegistrySource;
33
- ref: string;
34
- description?: string;
35
- tags?: string[];
36
- homepage?: string;
37
- score?: number;
38
- whyMatched?: string[];
39
- runCmd?: string;
40
- kind?: ToolKind;
41
- usage?: string[];
42
- metadata?: Record<string, string>;
43
- installRef: string;
44
- installCmd: string;
45
- /** Whether this entry was manually reviewed and approved */
46
- curated?: boolean;
47
- }
48
- export type SearchHit = LocalSearchHit | RegistrySearchResultHit;
49
- export interface SearchResponse {
50
- stashDir: string;
51
- source: SearchSource;
52
- hits: SearchHit[];
53
- usageGuide?: Partial<Record<AgentikitAssetType, string[]>>;
54
- tip?: string;
55
- warnings?: string[];
56
- /** Timing counters in milliseconds */
57
- timing?: {
58
- totalMs: number;
59
- rankMs?: number;
60
- embedMs?: number;
61
- };
62
- }
63
- export interface AddResponse {
64
- stashDir: string;
65
- ref: string;
66
- installed: {
67
- id: string;
68
- source: RegistrySource;
69
- ref: string;
70
- artifactUrl: string;
71
- resolvedVersion?: string;
72
- resolvedRevision?: string;
73
- stashRoot: string;
74
- cacheDir: string;
75
- extractedDir: string;
76
- installedAt: string;
77
- };
78
- config: {
79
- mountedStashDirs: string[];
80
- installedRegistryCount: number;
81
- };
82
- index: {
83
- mode: "full" | "incremental";
84
- totalEntries: number;
85
- directoriesScanned: number;
86
- directoriesSkipped: number;
87
- };
88
- }
89
- export interface RegistryInstallStatus {
90
- id: string;
91
- source: RegistrySource;
92
- ref: string;
93
- artifactUrl: string;
94
- resolvedVersion?: string;
95
- resolvedRevision?: string;
96
- stashRoot: string;
97
- cacheDir: string;
98
- extractedDir: string;
99
- installedAt: string;
100
- }
101
- export interface RegistryListEntry {
102
- id: string;
103
- source: RegistrySource;
104
- ref: string;
105
- artifactUrl: string;
106
- resolvedVersion?: string;
107
- resolvedRevision?: string;
108
- stashRoot: string;
109
- cacheDir: string;
110
- installedAt: string;
111
- status: {
112
- cacheDirExists: boolean;
113
- stashRootExists: boolean;
114
- };
115
- }
116
- export interface ListResponse {
117
- stashDir: string;
118
- installed: RegistryListEntry[];
119
- totalInstalled: number;
120
- }
121
- export interface RemoveResponse {
122
- stashDir: string;
123
- target: string;
124
- removed: {
125
- id: string;
126
- source: RegistrySource;
127
- ref: string;
128
- cacheDir: string;
129
- stashRoot: string;
130
- };
131
- config: {
132
- mountedStashDirs: string[];
133
- installedRegistryCount: number;
134
- };
135
- index: {
136
- mode: "full" | "incremental";
137
- totalEntries: number;
138
- directoriesScanned: number;
139
- directoriesSkipped: number;
140
- };
141
- }
142
- export interface ReinstallResultItem {
143
- id: string;
144
- source: RegistrySource;
145
- ref: string;
146
- previousCacheDir: string;
147
- installed: RegistryInstallStatus;
148
- }
149
- export interface ReinstallResponse {
150
- stashDir: string;
151
- target?: string;
152
- all: boolean;
153
- processed: ReinstallResultItem[];
154
- config: {
155
- mountedStashDirs: string[];
156
- installedRegistryCount: number;
157
- };
158
- index: {
159
- mode: "full" | "incremental";
160
- totalEntries: number;
161
- directoriesScanned: number;
162
- directoriesSkipped: number;
163
- };
164
- }
165
- export interface UpdateResultItem {
166
- id: string;
167
- source: RegistrySource;
168
- ref: string;
169
- previous: {
170
- resolvedVersion?: string;
171
- resolvedRevision?: string;
172
- cacheDir: string;
173
- };
174
- installed: RegistryInstallStatus;
175
- changed: {
176
- version: boolean;
177
- revision: boolean;
178
- any: boolean;
179
- };
180
- }
181
- export interface UpdateResponse {
182
- stashDir: string;
183
- target?: string;
184
- all: boolean;
185
- processed: UpdateResultItem[];
186
- config: {
187
- mountedStashDirs: string[];
188
- installedRegistryCount: number;
189
- };
190
- index: {
191
- mode: "full" | "incremental";
192
- totalEntries: number;
193
- directoriesScanned: number;
194
- directoriesSkipped: number;
195
- };
196
- }
197
- export interface ShowResponse {
198
- type: AgentikitAssetType;
199
- name: string;
200
- path: string;
201
- content?: string;
202
- template?: string;
203
- prompt?: string;
204
- description?: string;
205
- toolPolicy?: unknown;
206
- modelHint?: unknown;
207
- runCmd?: string;
208
- kind?: ToolKind;
209
- /** For installed sources, the registry id */
210
- registryId?: string;
211
- /** Whether this asset is editable (only true for working stash) */
212
- editable?: boolean;
213
- }
214
- export type KnowledgeView = {
215
- mode: "full";
216
- } | {
217
- mode: "toc";
218
- } | {
219
- mode: "frontmatter";
220
- } | {
221
- mode: "section";
222
- heading: string;
223
- } | {
224
- mode: "lines";
225
- start: number;
226
- end: number;
227
- };
@@ -1,16 +0,0 @@
1
- export type { AgentikitAssetType } from "./common";
2
- export { resolveStashDir } from "./common";
3
- export { agentikitInit } from "./init";
4
- export type { InitResponse } from "./init";
5
- export type { ToolKind } from "./tool-runner";
6
- export type { AssetTypeHandler, ShowInput } from "./asset-type-handler";
7
- export { registerAssetType, getHandler, getAllHandlers, getRegisteredTypeNames } from "./asset-type-handler";
8
- export { agentikitSearch } from "./stash-search";
9
- export { agentikitShow } from "./stash-show";
10
- export { agentikitAdd } from "./stash-add";
11
- export { agentikitClone } from "./stash-clone";
12
- export { agentikitList, agentikitRemove, agentikitReinstall, agentikitUpdate } from "./stash-registry";
13
- export { resolveStashSources, resolveAllStashDirs, findSourceForPath } from "./stash-source";
14
- export type { StashSource, StashSourceKind } from "./stash-source";
15
- export type { AddResponse, AgentikitSearchType, LocalSearchHit, RegistrySearchResultHit, SearchSource, SearchUsageMode, SearchHit, SearchResponse, ShowResponse, KnowledgeView, ListResponse, RemoveResponse, ReinstallResponse, UpdateResponse, RegistryListEntry, RegistryInstallStatus, ReinstallResultItem, UpdateResultItem, } from "./stash-types";
16
- export type { CloneOptions, CloneResponse } from "./stash-clone";
package/dist/src/stash.js DELETED
@@ -1,9 +0,0 @@
1
- export { resolveStashDir } from "./common";
2
- export { agentikitInit } from "./init";
3
- export { registerAssetType, getHandler, getAllHandlers, getRegisteredTypeNames } from "./asset-type-handler";
4
- export { agentikitSearch } from "./stash-search";
5
- export { agentikitShow } from "./stash-show";
6
- export { agentikitAdd } from "./stash-add";
7
- export { agentikitClone } from "./stash-clone";
8
- export { agentikitList, agentikitRemove, agentikitReinstall, agentikitUpdate } from "./stash-registry";
9
- export { resolveStashSources, resolveAllStashDirs, findSourceForPath } from "./stash-source";
@@ -1,35 +0,0 @@
1
- /**
2
- * Tool execution utilities.
3
- *
4
- * Handles building run commands and executing tool scripts for all supported
5
- * kinds (bash, bun, powershell, cmd).
6
- */
7
- /** The supported tool execution kinds. */
8
- export type ToolKind = "bash" | "bun" | "powershell" | "cmd";
9
- export interface ToolExecution {
10
- command: string;
11
- args: string[];
12
- cwd?: string;
13
- }
14
- export interface ToolInfo {
15
- runCmd: string;
16
- kind: ToolKind;
17
- install?: ToolExecution;
18
- execute: ToolExecution;
19
- }
20
- /**
21
- * Build execution metadata for a tool file based on its extension.
22
- *
23
- * For `.ts` / `.js` files, looks up the nearest `package.json` so that
24
- * `bun install` can be run in the correct working directory when the
25
- * `AKM_BUN_INSTALL` env flag is set.
26
- */
27
- export declare function buildToolInfo(stashDir: string, filePath: string): ToolInfo;
28
- /**
29
- * Shell-quote a path for inclusion in a human-readable `runCmd` string.
30
- */
31
- export declare function shellQuote(input: string): string;
32
- /**
33
- * Walk up from `startDir` toward `toolsRoot` looking for the nearest `package.json`.
34
- */
35
- export declare function findNearestPackageDir(startDir: string, toolsRoot: string): string | undefined;
@@ -1,19 +0,0 @@
1
- /**
2
- * Shared filesystem walker for agentikit stash directories.
3
- *
4
- * Provides a single implementation used by both the search fallback
5
- * (stash.ts) and the indexer (indexer.ts) to walk type-specific asset
6
- * directories and group files by parent directory.
7
- */
8
- import { type AgentikitAssetType } from "./common";
9
- export interface DirectoryGroup {
10
- dirPath: string;
11
- files: string[];
12
- }
13
- /**
14
- * Walk a type root directory and return files grouped by their parent directory.
15
- *
16
- * Only files relevant to the given `assetType` are included (e.g. `.md` for
17
- * commands, script extensions for tools, `SKILL.md` for skills).
18
- */
19
- export declare function walkStash(typeRoot: string, assetType: AgentikitAssetType): DirectoryGroup[];
package/src/asset-spec.ts DELETED
@@ -1,85 +0,0 @@
1
- import path from "node:path"
2
- import type { AgentikitAssetType } from "./common"
3
- import { toPosix } from "./common"
4
- import { tryGetHandler } from "./asset-type-handler"
5
-
6
- export const SCRIPT_EXTENSIONS = new Set([".sh", ".ts", ".js", ".ps1", ".cmd", ".bat"])
7
-
8
- export interface AssetSpec {
9
- stashDir: string
10
- isRelevantFile: (fileName: string) => boolean
11
- toCanonicalName: (typeRoot: string, filePath: string) => string | undefined
12
- toAssetPath: (typeRoot: string, name: string) => string
13
- }
14
-
15
- const markdownSpec: Omit<AssetSpec, "stashDir"> = {
16
- isRelevantFile: (fileName) => path.extname(fileName).toLowerCase() === ".md",
17
- toCanonicalName: (typeRoot, filePath) => toPosix(path.relative(typeRoot, filePath)),
18
- toAssetPath: (typeRoot, name) => path.join(typeRoot, name),
19
- }
20
-
21
- /** Extended set of script extensions for the script asset type */
22
- export const SCRIPT_EXTENSIONS_BROAD = new Set([
23
- ...SCRIPT_EXTENSIONS,
24
- ".py", ".rb", ".go", ".pl", ".php", ".lua", ".r", ".swift", ".kt", ".kts",
25
- ])
26
-
27
- export const ASSET_SPECS: Record<AgentikitAssetType, AssetSpec> = {
28
- tool: {
29
- stashDir: "tools",
30
- isRelevantFile: (fileName) => SCRIPT_EXTENSIONS.has(path.extname(fileName).toLowerCase()),
31
- toCanonicalName: (typeRoot, filePath) => toPosix(path.relative(typeRoot, filePath)),
32
- toAssetPath: (typeRoot, name) => path.join(typeRoot, name),
33
- },
34
- skill: {
35
- stashDir: "skills",
36
- isRelevantFile: (fileName) => fileName === "SKILL.md",
37
- toCanonicalName: (typeRoot, filePath) => {
38
- const relDir = toPosix(path.dirname(path.relative(typeRoot, filePath)))
39
- if (!relDir || relDir === ".") return undefined
40
- return relDir
41
- },
42
- toAssetPath: (typeRoot, name) => path.join(typeRoot, name, "SKILL.md"),
43
- },
44
- command: { stashDir: "commands", ...markdownSpec },
45
- agent: { stashDir: "agents", ...markdownSpec },
46
- knowledge: { stashDir: "knowledge", ...markdownSpec },
47
- script: {
48
- stashDir: "scripts",
49
- isRelevantFile: (fileName) => SCRIPT_EXTENSIONS_BROAD.has(path.extname(fileName).toLowerCase()),
50
- toCanonicalName: (typeRoot, filePath) => toPosix(path.relative(typeRoot, filePath)),
51
- toAssetPath: (typeRoot, name) => path.join(typeRoot, name),
52
- },
53
- }
54
-
55
- export const ASSET_TYPES = Object.keys(ASSET_SPECS) as AgentikitAssetType[]
56
-
57
- export const TYPE_DIRS: Record<AgentikitAssetType, string> = ASSET_TYPES.reduce(
58
- (acc, type) => {
59
- acc[type] = ASSET_SPECS[type].stashDir
60
- return acc
61
- },
62
- {} as Record<AgentikitAssetType, string>,
63
- )
64
-
65
- export function isRelevantAssetFile(assetType: AgentikitAssetType, fileName: string): boolean {
66
- const handler = tryGetHandler(assetType)
67
- if (handler) return handler.isRelevantFile(fileName)
68
- return ASSET_SPECS[assetType].isRelevantFile(fileName)
69
- }
70
-
71
- export function deriveCanonicalAssetName(
72
- assetType: AgentikitAssetType,
73
- typeRoot: string,
74
- filePath: string,
75
- ): string | undefined {
76
- const handler = tryGetHandler(assetType)
77
- if (handler) return handler.toCanonicalName(typeRoot, filePath)
78
- return ASSET_SPECS[assetType].toCanonicalName(typeRoot, filePath)
79
- }
80
-
81
- export function resolveAssetPathFromName(assetType: AgentikitAssetType, typeRoot: string, name: string): string {
82
- const handler = tryGetHandler(assetType)
83
- if (handler) return handler.toAssetPath(typeRoot, name)
84
- return ASSET_SPECS[assetType].toAssetPath(typeRoot, name)
85
- }
@@ -1,77 +0,0 @@
1
- import type { StashEntry } from "./metadata"
2
- import type { LocalSearchHit, ShowResponse, KnowledgeView } from "./stash-types"
3
-
4
- // ── Interface ────────────────────────────────────────────────────────────────
5
-
6
- export interface ShowInput {
7
- name: string
8
- path: string
9
- content: string
10
- view?: KnowledgeView
11
- stashDirs?: string[]
12
- }
13
-
14
- export interface AssetTypeHandler {
15
- /** The type name, e.g. "tool", "script" */
16
- readonly typeName: string
17
- /** Directory inside the stash root, e.g. "tools", "scripts" */
18
- readonly stashDir: string
19
-
20
- // -- File system spec --
21
- isRelevantFile(fileName: string): boolean
22
- toCanonicalName(typeRoot: string, filePath: string): string | undefined
23
- toAssetPath(typeRoot: string, name: string): string
24
-
25
- // -- Show behavior --
26
- buildShowResponse(input: ShowInput): ShowResponse
27
-
28
- // -- Search enrichment --
29
- enrichSearchHit?(hit: LocalSearchHit, stashDir: string): void
30
-
31
- // -- Usage guide --
32
- readonly defaultUsageGuide: string[]
33
-
34
- // -- Metadata generation hooks --
35
- extractTypeMetadata?(entry: StashEntry, file: string, ext: string): void
36
- }
37
-
38
- // ── Registry ─────────────────────────────────────────────────────────────────
39
-
40
- const handlers = new Map<string, AssetTypeHandler>()
41
-
42
- let handlersInitialized = false
43
-
44
- function ensureHandlersRegistered(): void {
45
- if (handlersInitialized) return
46
- handlersInitialized = true
47
- // Import handler registrations
48
- require("./handlers/index")
49
- }
50
-
51
- export function registerAssetType(handler: AssetTypeHandler): void {
52
- handlers.set(handler.typeName, handler)
53
- }
54
-
55
- export function getHandler(type: string): AssetTypeHandler {
56
- ensureHandlersRegistered()
57
- const handler = handlers.get(type)
58
- if (!handler) {
59
- throw new Error(`Unknown asset type: "${type}"`)
60
- }
61
- return handler
62
- }
63
-
64
- export function tryGetHandler(type: string): AssetTypeHandler | undefined {
65
- ensureHandlersRegistered()
66
- return handlers.get(type)
67
- }
68
-
69
- export function getAllHandlers(): AssetTypeHandler[] {
70
- ensureHandlersRegistered()
71
- return Array.from(handlers.values())
72
- }
73
-
74
- export function getRegisteredTypeNames(): string[] {
75
- ensureHandlersRegistered()
76
- return Array.from(handlers.keys())
77
- }