agentikit 0.0.8 → 0.0.12

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 (112) hide show
  1. package/README.md +135 -117
  2. package/dist/index.d.ts +13 -3
  3. package/dist/index.js +7 -1
  4. package/dist/src/asset-spec.d.ts +2 -0
  5. package/dist/src/asset-spec.js +22 -3
  6. package/dist/src/asset-type-handler.d.ts +27 -0
  7. package/dist/src/asset-type-handler.js +33 -0
  8. package/dist/src/cli.js +335 -100
  9. package/dist/src/common.d.ts +6 -1
  10. package/dist/src/common.js +18 -4
  11. package/dist/src/config-cli.d.ts +9 -0
  12. package/dist/src/config-cli.js +473 -0
  13. package/dist/src/config.d.ts +25 -6
  14. package/dist/src/config.js +188 -28
  15. package/dist/src/db.d.ts +46 -0
  16. package/dist/src/db.js +299 -0
  17. package/dist/src/embedder.js +12 -7
  18. package/dist/src/github.d.ts +4 -0
  19. package/dist/src/github.js +19 -0
  20. package/dist/src/handlers/agent-handler.d.ts +2 -0
  21. package/dist/src/handlers/agent-handler.js +26 -0
  22. package/dist/src/handlers/command-handler.d.ts +2 -0
  23. package/dist/src/handlers/command-handler.js +23 -0
  24. package/dist/src/handlers/index.d.ts +6 -0
  25. package/dist/src/handlers/index.js +23 -0
  26. package/dist/src/handlers/knowledge-handler.d.ts +2 -0
  27. package/dist/src/handlers/knowledge-handler.js +56 -0
  28. package/dist/src/handlers/markdown-helpers.d.ts +7 -0
  29. package/dist/src/handlers/markdown-helpers.js +15 -0
  30. package/dist/src/handlers/script-handler.d.ts +2 -0
  31. package/dist/src/handlers/script-handler.js +78 -0
  32. package/dist/src/handlers/skill-handler.d.ts +2 -0
  33. package/dist/src/handlers/skill-handler.js +30 -0
  34. package/dist/src/handlers/tool-handler.d.ts +2 -0
  35. package/dist/src/handlers/tool-handler.js +58 -0
  36. package/dist/src/indexer.d.ts +1 -23
  37. package/dist/src/indexer.js +162 -155
  38. package/dist/src/init.d.ts +2 -2
  39. package/dist/src/init.js +21 -9
  40. package/dist/src/llm.js +4 -3
  41. package/dist/src/metadata.d.ts +1 -1
  42. package/dist/src/metadata.js +22 -64
  43. package/dist/src/origin-resolve.d.ts +19 -0
  44. package/dist/src/origin-resolve.js +53 -0
  45. package/dist/src/registry-install.d.ts +11 -0
  46. package/dist/src/registry-install.js +315 -0
  47. package/dist/src/registry-resolve.d.ts +3 -0
  48. package/dist/src/registry-resolve.js +299 -0
  49. package/dist/src/registry-search.d.ts +27 -0
  50. package/dist/src/registry-search.js +263 -0
  51. package/dist/src/registry-types.d.ts +62 -0
  52. package/dist/src/registry-types.js +1 -0
  53. package/dist/src/stash-add.d.ts +4 -0
  54. package/dist/src/stash-add.js +59 -0
  55. package/dist/src/stash-clone.d.ts +22 -0
  56. package/dist/src/stash-clone.js +83 -0
  57. package/dist/src/stash-ref.d.ts +27 -3
  58. package/dist/src/stash-ref.js +63 -24
  59. package/dist/src/stash-registry.d.ts +18 -0
  60. package/dist/src/stash-registry.js +221 -0
  61. package/dist/src/stash-resolve.js +3 -0
  62. package/dist/src/stash-search.d.ts +3 -1
  63. package/dist/src/stash-search.js +357 -138
  64. package/dist/src/stash-show.d.ts +1 -1
  65. package/dist/src/stash-show.js +28 -89
  66. package/dist/src/stash-source.d.ts +24 -0
  67. package/dist/src/stash-source.js +81 -0
  68. package/dist/src/stash-types.d.ts +175 -1
  69. package/dist/src/stash.d.ts +9 -1
  70. package/dist/src/stash.js +5 -0
  71. package/dist/src/tool-runner.d.ts +1 -1
  72. package/dist/src/tool-runner.js +18 -5
  73. package/package.json +7 -2
  74. package/src/asset-spec.ts +20 -4
  75. package/src/asset-type-handler.ts +77 -0
  76. package/src/cli.ts +354 -103
  77. package/src/common.ts +23 -5
  78. package/src/config-cli.ts +499 -0
  79. package/src/config.ts +218 -37
  80. package/src/db.ts +411 -0
  81. package/src/embedder.ts +22 -11
  82. package/src/github.ts +21 -0
  83. package/src/handlers/agent-handler.ts +32 -0
  84. package/src/handlers/command-handler.ts +29 -0
  85. package/src/handlers/index.ts +25 -0
  86. package/src/handlers/knowledge-handler.ts +62 -0
  87. package/src/handlers/markdown-helpers.ts +19 -0
  88. package/src/handlers/script-handler.ts +92 -0
  89. package/src/handlers/skill-handler.ts +37 -0
  90. package/src/handlers/tool-handler.ts +71 -0
  91. package/src/indexer.ts +208 -187
  92. package/src/init.ts +17 -9
  93. package/src/llm.ts +4 -3
  94. package/src/metadata.ts +21 -65
  95. package/src/origin-resolve.ts +67 -0
  96. package/src/registry-install.ts +361 -0
  97. package/src/registry-resolve.ts +341 -0
  98. package/src/registry-search.ts +335 -0
  99. package/src/registry-types.ts +72 -0
  100. package/src/stash-add.ts +63 -0
  101. package/src/stash-clone.ts +127 -0
  102. package/src/stash-ref.ts +84 -26
  103. package/src/stash-registry.ts +259 -0
  104. package/src/stash-resolve.ts +3 -0
  105. package/src/stash-search.ts +425 -155
  106. package/src/stash-show.ts +33 -82
  107. package/src/stash-source.ts +103 -0
  108. package/src/stash-types.ts +186 -1
  109. package/src/stash.ts +23 -0
  110. package/src/tool-runner.ts +18 -5
  111. package/dist/src/similarity.d.ts +0 -34
  112. package/src/similarity.ts +0 -271
package/src/stash-show.ts CHANGED
@@ -1,24 +1,17 @@
1
1
  import fs from "node:fs"
2
- import path from "node:path"
3
- import { parseFrontmatter, toStringOrUndefined } from "./frontmatter"
4
- import { resolveStashDir } from "./common"
5
- import { parseOpenRef } from "./stash-ref"
2
+ import { parseAssetRef } from "./stash-ref"
3
+ import { resolveSourcesForOrigin } from "./origin-resolve"
6
4
  import { resolveAssetPath } from "./stash-resolve"
7
5
  import type { KnowledgeView, ShowResponse } from "./stash-types"
8
- import { parseMarkdownToc, extractSection, extractLineRange, extractFrontmatterOnly, formatToc } from "./markdown"
9
- import { buildToolInfo } from "./tool-runner"
10
- import { loadConfig } from "./config"
6
+ import { getHandler } from "./asset-type-handler"
7
+ import { resolveStashSources, findSourceForPath } from "./stash-source"
11
8
 
12
- export function agentikitShow(input: { ref: string; view?: KnowledgeView }): ShowResponse {
13
- const parsed = parseOpenRef(input.ref)
14
- const stashDir = resolveStashDir()
15
- const config = loadConfig(stashDir)
16
- const allStashDirs = [
17
- stashDir,
18
- ...config.additionalStashDirs.filter((d) => {
19
- try { return fs.statSync(d).isDirectory() } catch { return false }
20
- }),
21
- ]
9
+ export async function agentikitShow(input: { ref: string; view?: KnowledgeView }): Promise<ShowResponse> {
10
+ const parsed = parseAssetRef(input.ref)
11
+ const allSources = resolveStashSources()
12
+ const searchSources = resolveSourcesForOrigin(parsed.origin, allSources)
13
+
14
+ const allStashDirs = searchSources.map((s) => s.path)
22
15
 
23
16
  let assetPath: string | undefined
24
17
  let lastError: Error | undefined
@@ -30,75 +23,33 @@ export function agentikitShow(input: { ref: string; view?: KnowledgeView }): Sho
30
23
  lastError = err instanceof Error ? err : new Error(String(err))
31
24
  }
32
25
  }
26
+
27
+ if (!assetPath && parsed.origin && searchSources.length === 0) {
28
+ const installCmd = `akm add ${parsed.origin}`
29
+ throw new Error(
30
+ `Stash asset not found for ref: ${parsed.type}:${parsed.name}. ` +
31
+ `Kit "${parsed.origin}" is not installed. Run: ${installCmd}`
32
+ )
33
+ }
34
+
33
35
  if (!assetPath) {
34
36
  throw lastError ?? new Error(`Stash asset not found for ref: ${parsed.type}:${parsed.name}`)
35
37
  }
36
38
  const content = fs.readFileSync(assetPath, "utf8")
37
39
 
38
- switch (parsed.type) {
39
- case "skill":
40
- return {
41
- type: "skill",
42
- name: parsed.name,
43
- path: assetPath,
44
- content,
45
- }
46
- case "command": {
47
- const parsedMd = parseFrontmatter(content)
48
- return {
49
- type: "command",
50
- name: parsed.name,
51
- path: assetPath,
52
- description: toStringOrUndefined(parsedMd.data.description),
53
- template: parsedMd.content,
54
- }
55
- }
56
- case "agent": {
57
- const parsedMd = parseFrontmatter(content)
58
- return {
59
- type: "agent",
60
- name: parsed.name,
61
- path: assetPath,
62
- description: toStringOrUndefined(parsedMd.data.description),
63
- prompt: parsedMd.content,
64
- toolPolicy: parsedMd.data.tools,
65
- modelHint: parsedMd.data.model,
66
- }
67
- }
68
- case "tool": {
69
- const assetStashDir = allStashDirs.find((d) => path.resolve(assetPath!).startsWith(path.resolve(d) + path.sep)) ?? stashDir
70
- const toolInfo = buildToolInfo(assetStashDir, assetPath)
71
- return {
72
- type: "tool",
73
- name: parsed.name,
74
- path: assetPath,
75
- runCmd: toolInfo.runCmd,
76
- kind: toolInfo.kind,
77
- }
78
- }
79
- case "knowledge": {
80
- const v = input.view ?? { mode: "full" }
81
- switch (v.mode) {
82
- case "toc": {
83
- const toc = parseMarkdownToc(content)
84
- return { type: "knowledge", name: parsed.name, path: assetPath, content: formatToc(toc) }
85
- }
86
- case "frontmatter": {
87
- const fm = extractFrontmatterOnly(content)
88
- return { type: "knowledge", name: parsed.name, path: assetPath, content: fm ?? "(no frontmatter)" }
89
- }
90
- case "section": {
91
- const section = extractSection(content, v.heading)
92
- if (!section) throw new Error(`Section "${v.heading}" not found in ${parsed.name}`)
93
- return { type: "knowledge", name: parsed.name, path: assetPath, content: section.content }
94
- }
95
- case "lines": {
96
- return { type: "knowledge", name: parsed.name, path: assetPath, content: extractLineRange(content, v.start, v.end) }
97
- }
98
- default: {
99
- return { type: "knowledge", name: parsed.name, path: assetPath, content }
100
- }
101
- }
102
- }
40
+ const source = findSourceForPath(assetPath, allSources)
41
+ const handler = getHandler(parsed.type)
42
+ const response = handler.buildShowResponse({
43
+ name: parsed.name,
44
+ path: assetPath,
45
+ content,
46
+ view: input.view,
47
+ stashDirs: allStashDirs,
48
+ })
49
+
50
+ return {
51
+ ...response,
52
+ registryId: source?.registryId,
53
+ editable: source?.writable ?? false,
103
54
  }
104
55
  }
@@ -0,0 +1,103 @@
1
+ import fs from "node:fs"
2
+ import path from "node:path"
3
+ import { resolveStashDir } from "./common"
4
+ import { loadConfig } from "./config"
5
+
6
+ // ── Types ───────────────────────────────────────────────────────────────────
7
+
8
+ export type StashSourceKind = "working" | "mounted" | "installed"
9
+
10
+ export interface StashSource {
11
+ kind: StashSourceKind
12
+ path: string
13
+ /** For installed sources, the registry entry id */
14
+ registryId?: string
15
+ /** Whether this source is writable (only working stash) */
16
+ writable: boolean
17
+ }
18
+
19
+ // ── Resolution ──────────────────────────────────────────────────────────────
20
+
21
+ /**
22
+ * Build the ordered list of stash sources:
23
+ * 1. Working stash (writable)
24
+ * 2. Mounted stash dirs (read-only, user-configured)
25
+ * 3. Installed stash dirs (read-only, derived from registry.installed)
26
+ */
27
+ export function resolveStashSources(overrideStashDir?: string): StashSource[] {
28
+ const stashDir = overrideStashDir ?? resolveStashDir()
29
+ const config = loadConfig()
30
+
31
+ const sources: StashSource[] = [
32
+ { kind: "working", path: stashDir, writable: true },
33
+ ]
34
+
35
+ for (const dir of config.mountedStashDirs) {
36
+ if (isSuspiciousStashRoot(dir)) {
37
+ console.warn(`Warning: stash root "${dir}" appears to be a system directory. This may be unintentional.`)
38
+ }
39
+ if (isValidDirectory(dir)) {
40
+ sources.push({ kind: "mounted", path: dir, writable: false })
41
+ }
42
+ }
43
+
44
+ for (const entry of config.registry?.installed ?? []) {
45
+ if (isSuspiciousStashRoot(entry.stashRoot)) {
46
+ console.warn(`Warning: stash root "${entry.stashRoot}" appears to be a system directory. This may be unintentional.`)
47
+ }
48
+ if (isValidDirectory(entry.stashRoot)) {
49
+ sources.push({
50
+ kind: "installed",
51
+ path: entry.stashRoot,
52
+ registryId: entry.id,
53
+ writable: false,
54
+ })
55
+ }
56
+ }
57
+
58
+ return sources
59
+ }
60
+
61
+ /**
62
+ * Convenience: returns just the directory paths, preserving priority order.
63
+ */
64
+ export function resolveAllStashDirs(overrideStashDir?: string): string[] {
65
+ return resolveStashSources(overrideStashDir).map((s) => s.path)
66
+ }
67
+
68
+ /**
69
+ * Find which source a file path belongs to.
70
+ */
71
+ export function findSourceForPath(filePath: string, sources: StashSource[]): StashSource | undefined {
72
+ const resolved = path.resolve(filePath)
73
+ for (const source of sources) {
74
+ if (resolved.startsWith(path.resolve(source.path) + path.sep)) return source
75
+ }
76
+ return undefined
77
+ }
78
+
79
+ // ── Validation ──────────────────────────────────────────────────────────────
80
+
81
+ const SUSPICIOUS_ROOTS = new Set(['/', '/etc', '/bin', '/sbin', '/usr', '/var', '/tmp', '/dev', '/proc', '/sys'])
82
+
83
+ function isSuspiciousStashRoot(dir: string): boolean {
84
+ const resolved = path.resolve(dir)
85
+ const normalized = process.platform === 'win32' ? resolved.toLowerCase() : resolved
86
+ if (SUSPICIOUS_ROOTS.has(normalized)) return true
87
+ if (process.platform === 'win32') {
88
+ // Check for Windows system directories
89
+ const winDir = (process.env.SystemRoot || 'C:\\Windows').toLowerCase()
90
+ if (normalized === winDir || normalized.startsWith(winDir + path.sep)) return true
91
+ }
92
+ return false
93
+ }
94
+
95
+ // ── Helpers ─────────────────────────────────────────────────────────────────
96
+
97
+ function isValidDirectory(dir: string): boolean {
98
+ try {
99
+ return fs.statSync(dir).isDirectory()
100
+ } catch {
101
+ return false
102
+ }
103
+ }
@@ -1,29 +1,210 @@
1
1
  import type { AgentikitAssetType } from "./common"
2
+ import type { RegistrySource } from "./registry-types"
2
3
  import type { ToolKind } from "./tool-runner"
3
4
 
4
5
  export type AgentikitSearchType = AgentikitAssetType | "any"
6
+ export type SearchUsageMode = "none" | "both" | "item" | "guide"
7
+ export type SearchSource = "local" | "registry" | "both"
5
8
 
6
- export interface SearchHit {
9
+ export interface LocalSearchHit {
10
+ hitSource: "local"
7
11
  type: AgentikitAssetType
8
12
  name: string
9
13
  path: string
10
14
  openRef: string
15
+ /** For installed sources, the registry id */
16
+ registryId?: string
17
+ /** Whether this asset is editable (only true for working stash) */
18
+ editable?: boolean
11
19
  description?: string
12
20
  tags?: string[]
13
21
  score?: number
14
22
  whyMatched?: string[]
15
23
  runCmd?: string
16
24
  kind?: ToolKind
25
+ usage?: string[]
17
26
  }
18
27
 
28
+ export interface RegistrySearchResultHit {
29
+ hitSource: "registry"
30
+ type: "registry"
31
+ name: string
32
+ path?: string
33
+ openRef?: string
34
+ id: string
35
+ registrySource: RegistrySource
36
+ ref: string
37
+ description?: string
38
+ tags?: string[]
39
+ homepage?: string
40
+ score?: number
41
+ whyMatched?: string[]
42
+ runCmd?: string
43
+ kind?: ToolKind
44
+ usage?: string[]
45
+ metadata?: Record<string, string>
46
+ installRef: string
47
+ installCmd: string
48
+ /** Whether this entry was manually reviewed and approved */
49
+ curated?: boolean
50
+ }
51
+
52
+ export type SearchHit = LocalSearchHit | RegistrySearchResultHit
53
+
19
54
  export interface SearchResponse {
20
55
  stashDir: string
56
+ source: SearchSource
21
57
  hits: SearchHit[]
58
+ usageGuide?: Partial<Record<AgentikitAssetType, string[]>>
22
59
  tip?: string
60
+ warnings?: string[]
23
61
  /** Timing counters in milliseconds */
24
62
  timing?: { totalMs: number; rankMs?: number; embedMs?: number }
25
63
  }
26
64
 
65
+ export interface AddResponse {
66
+ stashDir: string
67
+ ref: string
68
+ installed: {
69
+ id: string
70
+ source: RegistrySource
71
+ ref: string
72
+ artifactUrl: string
73
+ resolvedVersion?: string
74
+ resolvedRevision?: string
75
+ stashRoot: string
76
+ cacheDir: string
77
+ extractedDir: string
78
+ installedAt: string
79
+ }
80
+ config: {
81
+ mountedStashDirs: string[]
82
+ installedRegistryCount: number
83
+ }
84
+ index: {
85
+ mode: "full" | "incremental"
86
+ totalEntries: number
87
+ directoriesScanned: number
88
+ directoriesSkipped: number
89
+ }
90
+ }
91
+
92
+ export interface RegistryInstallStatus {
93
+ id: string
94
+ source: RegistrySource
95
+ ref: string
96
+ artifactUrl: string
97
+ resolvedVersion?: string
98
+ resolvedRevision?: string
99
+ stashRoot: string
100
+ cacheDir: string
101
+ extractedDir: string
102
+ installedAt: string
103
+ }
104
+
105
+ export interface RegistryListEntry {
106
+ id: string
107
+ source: RegistrySource
108
+ ref: string
109
+ artifactUrl: string
110
+ resolvedVersion?: string
111
+ resolvedRevision?: string
112
+ stashRoot: string
113
+ cacheDir: string
114
+ installedAt: string
115
+ status: {
116
+ cacheDirExists: boolean
117
+ stashRootExists: boolean
118
+ }
119
+ }
120
+
121
+ export interface ListResponse {
122
+ stashDir: string
123
+ installed: RegistryListEntry[]
124
+ totalInstalled: number
125
+ }
126
+
127
+ export interface RemoveResponse {
128
+ stashDir: string
129
+ target: string
130
+ removed: {
131
+ id: string
132
+ source: RegistrySource
133
+ ref: string
134
+ cacheDir: string
135
+ stashRoot: string
136
+ }
137
+ config: {
138
+ mountedStashDirs: string[]
139
+ installedRegistryCount: number
140
+ }
141
+ index: {
142
+ mode: "full" | "incremental"
143
+ totalEntries: number
144
+ directoriesScanned: number
145
+ directoriesSkipped: number
146
+ }
147
+ }
148
+
149
+ export interface ReinstallResultItem {
150
+ id: string
151
+ source: RegistrySource
152
+ ref: string
153
+ previousCacheDir: string
154
+ installed: RegistryInstallStatus
155
+ }
156
+
157
+ export interface ReinstallResponse {
158
+ stashDir: string
159
+ target?: string
160
+ all: boolean
161
+ processed: ReinstallResultItem[]
162
+ config: {
163
+ mountedStashDirs: string[]
164
+ installedRegistryCount: number
165
+ }
166
+ index: {
167
+ mode: "full" | "incremental"
168
+ totalEntries: number
169
+ directoriesScanned: number
170
+ directoriesSkipped: number
171
+ }
172
+ }
173
+
174
+ export interface UpdateResultItem {
175
+ id: string
176
+ source: RegistrySource
177
+ ref: string
178
+ previous: {
179
+ resolvedVersion?: string
180
+ resolvedRevision?: string
181
+ cacheDir: string
182
+ }
183
+ installed: RegistryInstallStatus
184
+ changed: {
185
+ version: boolean
186
+ revision: boolean
187
+ any: boolean
188
+ }
189
+ }
190
+
191
+ export interface UpdateResponse {
192
+ stashDir: string
193
+ target?: string
194
+ all: boolean
195
+ processed: UpdateResultItem[]
196
+ config: {
197
+ mountedStashDirs: string[]
198
+ installedRegistryCount: number
199
+ }
200
+ index: {
201
+ mode: "full" | "incremental"
202
+ totalEntries: number
203
+ directoriesScanned: number
204
+ directoriesSkipped: number
205
+ }
206
+ }
207
+
27
208
  export interface ShowResponse {
28
209
  type: AgentikitAssetType
29
210
  name: string
@@ -36,6 +217,10 @@ export interface ShowResponse {
36
217
  modelHint?: unknown
37
218
  runCmd?: string
38
219
  kind?: ToolKind
220
+ /** For installed sources, the registry id */
221
+ registryId?: string
222
+ /** Whether this asset is editable (only true for working stash) */
223
+ editable?: boolean
39
224
  }
40
225
 
41
226
  export type KnowledgeView =
package/src/stash.ts CHANGED
@@ -3,14 +3,37 @@ export { resolveStashDir } from "./common"
3
3
  export { agentikitInit } from "./init"
4
4
  export type { InitResponse } from "./init"
5
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"
6
8
 
7
9
  export { agentikitSearch } from "./stash-search"
8
10
  export { agentikitShow } from "./stash-show"
11
+ export { agentikitAdd } from "./stash-add"
12
+ export { agentikitClone } from "./stash-clone"
13
+
14
+ export { agentikitList, agentikitRemove, agentikitReinstall, agentikitUpdate } from "./stash-registry"
15
+ export { resolveStashSources, resolveAllStashDirs, findSourceForPath } from "./stash-source"
16
+ export type { StashSource, StashSourceKind } from "./stash-source"
9
17
 
10
18
  export type {
19
+ AddResponse,
11
20
  AgentikitSearchType,
21
+ LocalSearchHit,
22
+ RegistrySearchResultHit,
23
+ SearchSource,
24
+ SearchUsageMode,
12
25
  SearchHit,
13
26
  SearchResponse,
14
27
  ShowResponse,
15
28
  KnowledgeView,
29
+ ListResponse,
30
+ RemoveResponse,
31
+ ReinstallResponse,
32
+ UpdateResponse,
33
+ RegistryListEntry,
34
+ RegistryInstallStatus,
35
+ ReinstallResultItem,
36
+ UpdateResultItem,
16
37
  } from "./stash-types"
38
+
39
+ export type { CloneOptions, CloneResponse } from "./stash-clone"
@@ -34,7 +34,7 @@ export interface ToolInfo {
34
34
  *
35
35
  * For `.ts` / `.js` files, looks up the nearest `package.json` so that
36
36
  * `bun install` can be run in the correct working directory when the
37
- * `AGENTIKIT_BUN_INSTALL` env flag is set.
37
+ * `AKM_BUN_INSTALL` env flag is set.
38
38
  */
39
39
  export function buildToolInfo(stashDir: string, filePath: string): ToolInfo {
40
40
  const ext = path.extname(filePath).toLowerCase()
@@ -67,8 +67,17 @@ export function buildToolInfo(stashDir: string, filePath: string): ToolInfo {
67
67
  throw new Error(`Unsupported tool extension: ${ext}`)
68
68
  }
69
69
 
70
- const toolsRoot = path.resolve(path.join(stashDir, "tools"))
71
- const pkgDir = findNearestPackageDir(path.dirname(filePath), toolsRoot)
70
+ // Determine the type root by checking which subdirectory contains the file
71
+ const resolvedFile = path.resolve(filePath)
72
+ let typeRoot = path.resolve(path.join(stashDir, "tools"))
73
+ for (const subdir of ["tools", "scripts"]) {
74
+ const candidate = path.resolve(path.join(stashDir, subdir))
75
+ if (resolvedFile.startsWith(candidate + path.sep)) {
76
+ typeRoot = candidate
77
+ break
78
+ }
79
+ }
80
+ const pkgDir = findNearestPackageDir(path.dirname(filePath), typeRoot)
72
81
  if (!pkgDir) {
73
82
  return {
74
83
  runCmd: `bun ${shellQuote(filePath)}`,
@@ -76,7 +85,7 @@ export function buildToolInfo(stashDir: string, filePath: string): ToolInfo {
76
85
  execute: { command: "bun", args: [filePath] },
77
86
  }
78
87
  }
79
- const installFlag = process.env.AGENTIKIT_BUN_INSTALL
88
+ const installFlag = process.env.AKM_BUN_INSTALL
80
89
  const shouldInstall = installFlag === "1" || installFlag === "true" || installFlag === "yes"
81
90
 
82
91
  const quotedPkgDir = shellQuote(pkgDir)
@@ -101,7 +110,11 @@ export function shellQuote(input: string): string {
101
110
  throw new Error("Unsupported control characters in stash path.")
102
111
  }
103
112
  if (IS_WINDOWS) {
104
- return `"${input.replace(/"/g, '""')}"`
113
+ const escaped = input
114
+ .replace(/%/g, "%%")
115
+ .replace(/([\\^|&<>])/g, "^$1")
116
+ .replace(/"/g, '""')
117
+ return `"${escaped}"`
105
118
  }
106
119
  const escaped = input
107
120
  .replace(/\\/g, "\\\\")
@@ -1,34 +0,0 @@
1
- import type { StashEntry } from "./metadata";
2
- export interface ScoredEntry {
3
- id: string;
4
- text: string;
5
- entry: StashEntry;
6
- path: string;
7
- }
8
- export interface ScoredResult {
9
- entry: StashEntry;
10
- path: string;
11
- score: number;
12
- }
13
- export interface SearchAdapter {
14
- buildIndex(entries: ScoredEntry[]): void;
15
- search(query: string, limit: number, typeFilter?: string): ScoredResult[];
16
- }
17
- export interface SerializedTfIdf {
18
- idf: Record<string, number>;
19
- docs: Array<{
20
- id: string;
21
- termFreqs: Record<string, number>;
22
- magnitude: number;
23
- }>;
24
- }
25
- export declare class TfIdfAdapter implements SearchAdapter {
26
- private documents;
27
- private idf;
28
- private entries;
29
- buildIndex(entries: ScoredEntry[]): void;
30
- search(query: string, limit: number, typeFilter?: string): ScoredResult[];
31
- serialize(): SerializedTfIdf;
32
- static deserialize(data: SerializedTfIdf, entries: ScoredEntry[]): TfIdfAdapter;
33
- private substringFallback;
34
- }