agentikit 0.0.13 → 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 (145) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +180 -110
  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/stash-add.d.ts +0 -4
  72. package/dist/src/stash-clone.d.ts +0 -22
  73. package/dist/src/stash-clone.js +0 -83
  74. package/dist/src/stash-ref.d.ts +0 -31
  75. package/dist/src/stash-registry.d.ts +0 -18
  76. package/dist/src/stash-resolve.d.ts +0 -2
  77. package/dist/src/stash-search.d.ts +0 -8
  78. package/dist/src/stash-show.d.ts +0 -5
  79. package/dist/src/stash-source.d.ts +0 -24
  80. package/dist/src/stash-types.d.ts +0 -227
  81. package/dist/src/stash.d.ts +0 -16
  82. package/dist/src/stash.js +0 -9
  83. package/dist/src/tool-runner.d.ts +0 -35
  84. package/dist/src/walker.d.ts +0 -19
  85. package/src/asset-spec.ts +0 -85
  86. package/src/asset-type-handler.ts +0 -77
  87. package/src/cli.ts +0 -427
  88. package/src/common.ts +0 -76
  89. package/src/config-cli.ts +0 -499
  90. package/src/config.ts +0 -305
  91. package/src/db.ts +0 -411
  92. package/src/embedder.ts +0 -128
  93. package/src/frontmatter.ts +0 -95
  94. package/src/github.ts +0 -21
  95. package/src/handlers/agent-handler.ts +0 -32
  96. package/src/handlers/command-handler.ts +0 -29
  97. package/src/handlers/index.ts +0 -25
  98. package/src/handlers/knowledge-handler.ts +0 -62
  99. package/src/handlers/markdown-helpers.ts +0 -19
  100. package/src/handlers/script-handler.ts +0 -92
  101. package/src/handlers/skill-handler.ts +0 -37
  102. package/src/handlers/tool-handler.ts +0 -71
  103. package/src/indexer.ts +0 -392
  104. package/src/init.ts +0 -114
  105. package/src/llm.ts +0 -125
  106. package/src/markdown.ts +0 -106
  107. package/src/metadata.ts +0 -333
  108. package/src/origin-resolve.ts +0 -67
  109. package/src/registry-install.ts +0 -361
  110. package/src/registry-resolve.ts +0 -341
  111. package/src/registry-search.ts +0 -335
  112. package/src/registry-types.ts +0 -72
  113. package/src/ripgrep-install.ts +0 -200
  114. package/src/ripgrep-resolve.ts +0 -72
  115. package/src/ripgrep.ts +0 -3
  116. package/src/stash-add.ts +0 -63
  117. package/src/stash-clone.ts +0 -127
  118. package/src/stash-ref.ts +0 -99
  119. package/src/stash-registry.ts +0 -259
  120. package/src/stash-resolve.ts +0 -50
  121. package/src/stash-search.ts +0 -613
  122. package/src/stash-show.ts +0 -55
  123. package/src/stash-source.ts +0 -103
  124. package/src/stash-types.ts +0 -231
  125. package/src/stash.ts +0 -39
  126. package/src/tool-runner.ts +0 -142
  127. package/src/walker.ts +0 -53
  128. /package/dist/{src/asset-spec.js → asset-spec.js} +0 -0
  129. /package/dist/{src/asset-type-handler.js → asset-type-handler.js} +0 -0
  130. /package/dist/{src/frontmatter.js → frontmatter.js} +0 -0
  131. /package/dist/{src/github.js → github.js} +0 -0
  132. /package/dist/{src/handlers → handlers}/agent-handler.js +0 -0
  133. /package/dist/{src/handlers → handlers}/knowledge-handler.js +0 -0
  134. /package/dist/{src/handlers → handlers}/markdown-helpers.js +0 -0
  135. /package/dist/{src/handlers → handlers}/script-handler.js +0 -0
  136. /package/dist/{src/handlers → handlers}/skill-handler.js +0 -0
  137. /package/dist/{src/handlers → handlers}/tool-handler.js +0 -0
  138. /package/dist/{src/llm.js → llm.js} +0 -0
  139. /package/dist/{src/markdown.js → markdown.js} +0 -0
  140. /package/dist/{src/registry-types.js → registry-types.js} +0 -0
  141. /package/dist/{src/ripgrep.js → ripgrep.js} +0 -0
  142. /package/dist/{src/stash-ref.js → stash-ref.js} +0 -0
  143. /package/dist/{src/stash-resolve.js → stash-resolve.js} +0 -0
  144. /package/dist/{src/stash-types.js → stash-types.js} +0 -0
  145. /package/dist/{src/tool-runner.js → tool-runner.js} +0 -0
@@ -1,103 +0,0 @@
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,231 +0,0 @@
1
- import type { AgentikitAssetType } from "./common"
2
- import type { RegistrySource } from "./registry-types"
3
- import type { ToolKind } from "./tool-runner"
4
-
5
- export type AgentikitSearchType = AgentikitAssetType | "any"
6
- export type SearchUsageMode = "none" | "both" | "item" | "guide"
7
- export type SearchSource = "local" | "registry" | "both"
8
-
9
- export interface LocalSearchHit {
10
- hitSource: "local"
11
- type: AgentikitAssetType
12
- name: string
13
- path: string
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
19
- description?: string
20
- tags?: string[]
21
- score?: number
22
- whyMatched?: string[]
23
- runCmd?: string
24
- kind?: ToolKind
25
- usage?: string[]
26
- }
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
-
54
- export interface SearchResponse {
55
- stashDir: string
56
- source: SearchSource
57
- hits: SearchHit[]
58
- usageGuide?: Partial<Record<AgentikitAssetType, string[]>>
59
- tip?: string
60
- warnings?: string[]
61
- /** Timing counters in milliseconds */
62
- timing?: { totalMs: number; rankMs?: number; embedMs?: number }
63
- }
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
-
208
- export interface ShowResponse {
209
- type: AgentikitAssetType
210
- name: string
211
- path: string
212
- content?: string
213
- template?: string
214
- prompt?: string
215
- description?: string
216
- toolPolicy?: unknown
217
- modelHint?: unknown
218
- runCmd?: string
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
224
- }
225
-
226
- export type KnowledgeView =
227
- | { mode: "full" }
228
- | { mode: "toc" }
229
- | { mode: "frontmatter" }
230
- | { mode: "section"; heading: string }
231
- | { mode: "lines"; start: number; end: number }
package/src/stash.ts DELETED
@@ -1,39 +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
-
9
- export { agentikitSearch } from "./stash-search"
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"
17
-
18
- export type {
19
- AddResponse,
20
- AgentikitSearchType,
21
- LocalSearchHit,
22
- RegistrySearchResultHit,
23
- SearchSource,
24
- SearchUsageMode,
25
- SearchHit,
26
- SearchResponse,
27
- ShowResponse,
28
- KnowledgeView,
29
- ListResponse,
30
- RemoveResponse,
31
- ReinstallResponse,
32
- UpdateResponse,
33
- RegistryListEntry,
34
- RegistryInstallStatus,
35
- ReinstallResultItem,
36
- UpdateResultItem,
37
- } from "./stash-types"
38
-
39
- export type { CloneOptions, CloneResponse } from "./stash-clone"
@@ -1,142 +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
-
8
- import fs from "node:fs"
9
- import path from "node:path"
10
- import { IS_WINDOWS, isWithin } from "./common"
11
-
12
- // ── Types ───────────────────────────────────────────────────────────────────
13
-
14
- /** The supported tool execution kinds. */
15
- export type ToolKind = "bash" | "bun" | "powershell" | "cmd"
16
-
17
- export interface ToolExecution {
18
- command: string
19
- args: string[]
20
- cwd?: string
21
- }
22
-
23
- export interface ToolInfo {
24
- runCmd: string
25
- kind: ToolKind
26
- install?: ToolExecution
27
- execute: ToolExecution
28
- }
29
-
30
- // ── Public API ──────────────────────────────────────────────────────────────
31
-
32
- /**
33
- * Build execution metadata for a tool file based on its extension.
34
- *
35
- * For `.ts` / `.js` files, looks up the nearest `package.json` so that
36
- * `bun install` can be run in the correct working directory when the
37
- * `AKM_BUN_INSTALL` env flag is set.
38
- */
39
- export function buildToolInfo(stashDir: string, filePath: string): ToolInfo {
40
- const ext = path.extname(filePath).toLowerCase()
41
-
42
- if (ext === ".sh") {
43
- return {
44
- runCmd: `bash ${shellQuote(filePath)}`,
45
- kind: "bash",
46
- execute: { command: "bash", args: [filePath] },
47
- }
48
- }
49
-
50
- if (ext === ".ps1") {
51
- return {
52
- runCmd: `powershell -ExecutionPolicy Bypass -File ${shellQuote(filePath)}`,
53
- kind: "powershell",
54
- execute: { command: "powershell", args: ["-ExecutionPolicy", "Bypass", "-File", filePath] },
55
- }
56
- }
57
-
58
- if (ext === ".cmd" || ext === ".bat") {
59
- return {
60
- runCmd: `cmd /c ${shellQuote(filePath)}`,
61
- kind: "cmd",
62
- execute: { command: "cmd", args: ["/c", filePath] },
63
- }
64
- }
65
-
66
- if (ext !== ".ts" && ext !== ".js") {
67
- throw new Error(`Unsupported tool extension: ${ext}`)
68
- }
69
-
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)
81
- if (!pkgDir) {
82
- return {
83
- runCmd: `bun ${shellQuote(filePath)}`,
84
- kind: "bun",
85
- execute: { command: "bun", args: [filePath] },
86
- }
87
- }
88
- const installFlag = process.env.AKM_BUN_INSTALL
89
- const shouldInstall = installFlag === "1" || installFlag === "true" || installFlag === "yes"
90
-
91
- const quotedPkgDir = shellQuote(pkgDir)
92
- const quotedFilePath = shellQuote(filePath)
93
- const cdCmd = IS_WINDOWS ? `cd /d ${quotedPkgDir}` : `cd ${quotedPkgDir}`
94
- const chain = IS_WINDOWS ? " & " : " && "
95
- return {
96
- runCmd: shouldInstall
97
- ? `${cdCmd}${chain}bun install${chain}bun ${quotedFilePath}`
98
- : `${cdCmd}${chain}bun ${quotedFilePath}`,
99
- kind: "bun",
100
- install: shouldInstall ? { command: "bun", args: ["install"], cwd: pkgDir } : undefined,
101
- execute: { command: "bun", args: [filePath], cwd: pkgDir },
102
- }
103
- }
104
-
105
- /**
106
- * Shell-quote a path for inclusion in a human-readable `runCmd` string.
107
- */
108
- export function shellQuote(input: string): string {
109
- if (/[\r\n\t\0]/.test(input)) {
110
- throw new Error("Unsupported control characters in stash path.")
111
- }
112
- if (IS_WINDOWS) {
113
- const escaped = input
114
- .replace(/%/g, "%%")
115
- .replace(/([\\^|&<>])/g, "^$1")
116
- .replace(/"/g, '""')
117
- return `"${escaped}"`
118
- }
119
- const escaped = input
120
- .replace(/\\/g, "\\\\")
121
- .replace(/"/g, '\\"')
122
- .replace(/\$/g, "\\$")
123
- .replace(/`/g, "\\`")
124
- return `"${escaped}"`
125
- }
126
-
127
- /**
128
- * Walk up from `startDir` toward `toolsRoot` looking for the nearest `package.json`.
129
- */
130
- export function findNearestPackageDir(startDir: string, toolsRoot: string): string | undefined {
131
- let current = path.resolve(startDir)
132
- const root = path.resolve(toolsRoot)
133
- while (isWithin(current, root)) {
134
- if (fs.existsSync(path.join(current, "package.json"))) {
135
- return current
136
- }
137
- if (current === root) return undefined
138
- current = path.dirname(current)
139
- }
140
- return undefined
141
- }
142
-
package/src/walker.ts DELETED
@@ -1,53 +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
-
9
- import fs from "node:fs"
10
- import path from "node:path"
11
- import { type AgentikitAssetType } from "./common"
12
- import { isRelevantAssetFile } from "./asset-spec"
13
-
14
- export interface DirectoryGroup {
15
- dirPath: string
16
- files: string[]
17
- }
18
-
19
- /**
20
- * Walk a type root directory and return files grouped by their parent directory.
21
- *
22
- * Only files relevant to the given `assetType` are included (e.g. `.md` for
23
- * commands, script extensions for tools, `SKILL.md` for skills).
24
- */
25
- export function walkStash(typeRoot: string, assetType: AgentikitAssetType): DirectoryGroup[] {
26
- if (!fs.existsSync(typeRoot)) return []
27
-
28
- const groups = new Map<string, string[]>()
29
-
30
- const stack = [typeRoot]
31
- while (stack.length > 0) {
32
- const current = stack.pop()
33
- if (!current) continue
34
- const entries = fs.readdirSync(current, { withFileTypes: true })
35
- for (const entry of entries) {
36
- if (entry.name === ".stash.json") continue
37
- const fullPath = path.join(current, entry.name)
38
- if (entry.isDirectory()) {
39
- stack.push(fullPath)
40
- } else if (entry.isFile() && isRelevantAssetFile(assetType, entry.name)) {
41
- const parentDir = path.dirname(fullPath)
42
- const existing = groups.get(parentDir)
43
- if (existing) {
44
- existing.push(fullPath)
45
- } else {
46
- groups.set(parentDir, [fullPath])
47
- }
48
- }
49
- }
50
- }
51
-
52
- return Array.from(groups, ([dirPath, files]) => ({ dirPath, files }))
53
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes