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
package/src/config.ts DELETED
@@ -1,305 +0,0 @@
1
- import fs from "node:fs"
2
- import path from "node:path"
3
- import type { RegistryInstalledEntry, RegistrySource } from "./registry-types"
4
-
5
- // ── Types ───────────────────────────────────────────────────────────────────
6
-
7
- export interface EmbeddingConnectionConfig {
8
- /** Provider name for display/CLI switching (e.g. "openai", "ollama") */
9
- provider?: string
10
- /** OpenAI-compatible embeddings endpoint (e.g. "http://localhost:11434/v1/embeddings") */
11
- endpoint: string
12
- /** Model name to use for embeddings (e.g. "nomic-embed-text") */
13
- model: string
14
- /** Optional output dimension for providers that support it */
15
- dimension?: number
16
- /** Optional API key for authenticated endpoints */
17
- apiKey?: string
18
- }
19
-
20
- export interface LlmConnectionConfig {
21
- /** Provider name for display/CLI switching (e.g. "openai", "ollama") */
22
- provider?: string
23
- /** OpenAI-compatible chat completions endpoint (e.g. "http://localhost:11434/v1/chat/completions") */
24
- endpoint: string
25
- /** Model name to use (e.g. "llama3.2") */
26
- model: string
27
- /** Optional sampling temperature */
28
- temperature?: number
29
- /** Optional response token limit */
30
- maxTokens?: number
31
- /** Optional API key for authenticated endpoints */
32
- apiKey?: string
33
- }
34
-
35
- export interface AgentikitConfig {
36
- /** Whether semantic search is enabled. Default: true */
37
- semanticSearch: boolean
38
- /** User-mounted read-only stash directories */
39
- mountedStashDirs: string[]
40
- /** OpenAI-compatible embedding endpoint config. If not set, uses local @xenova/transformers */
41
- embedding?: EmbeddingConnectionConfig
42
- /** OpenAI-compatible LLM endpoint config for metadata generation. If not set, uses heuristic generation */
43
- llm?: LlmConnectionConfig
44
- /** Installed registry sources and local cache metadata */
45
- registry?: RegistryConfig
46
- /** Registry index URLs for kit discovery. Default: official agentikit-registry on GitHub */
47
- registryUrls?: string[]
48
- }
49
-
50
- export interface RegistryConfig {
51
- installed: RegistryInstalledEntry[]
52
- }
53
-
54
- // ── Defaults ────────────────────────────────────────────────────────────────
55
-
56
- export const DEFAULT_CONFIG: AgentikitConfig = {
57
- semanticSearch: true,
58
- mountedStashDirs: [],
59
- }
60
-
61
- // ── Paths ───────────────────────────────────────────────────────────────────
62
-
63
- export function getConfigDir(
64
- env: NodeJS.ProcessEnv = process.env,
65
- platform = process.platform,
66
- ): string {
67
- if (platform === "win32") {
68
- const appData = env.APPDATA?.trim()
69
- if (appData) return path.join(appData, "agentikit")
70
-
71
- const userProfile = env.USERPROFILE?.trim()
72
- if (!userProfile) {
73
- throw new Error("Unable to determine config directory. Set APPDATA or USERPROFILE.")
74
- }
75
- return path.join(userProfile, "AppData", "Roaming", "agentikit")
76
- }
77
-
78
- const xdgConfigHome = env.XDG_CONFIG_HOME?.trim()
79
- if (xdgConfigHome) return path.join(xdgConfigHome, "agentikit")
80
-
81
- const home = env.HOME?.trim()
82
- if (!home) {
83
- throw new Error("Unable to determine config directory. Set XDG_CONFIG_HOME or HOME.")
84
- }
85
- return path.join(home, ".config", "agentikit")
86
- }
87
-
88
- export function getConfigPath(): string {
89
- return path.join(getConfigDir(), "config.json")
90
- }
91
-
92
- // ── Load / Save / Update ────────────────────────────────────────────────────
93
-
94
- export function loadConfig(): AgentikitConfig {
95
- const configPath = getConfigPath()
96
- const raw = readConfigObject(configPath)
97
- const config = raw ? pickKnownKeys(raw) : { ...DEFAULT_CONFIG }
98
-
99
- // Inject API keys from environment variables.
100
- // API keys should be provided via AKM_EMBED_API_KEY and AKM_LLM_API_KEY
101
- // rather than stored in the config file.
102
- if (config.embedding && !config.embedding.apiKey) {
103
- const envKey = process.env.AKM_EMBED_API_KEY?.trim()
104
- if (envKey) config.embedding.apiKey = envKey
105
- }
106
- if (config.llm && !config.llm.apiKey) {
107
- const envKey = process.env.AKM_LLM_API_KEY?.trim()
108
- if (envKey) config.llm.apiKey = envKey
109
- }
110
-
111
- return config
112
- }
113
-
114
- export function saveConfig(config: AgentikitConfig): void {
115
- const configPath = getConfigPath()
116
- const dir = path.dirname(configPath)
117
- fs.mkdirSync(dir, { recursive: true })
118
- const sanitized = sanitizeConfigForWrite(config)
119
- const tmpPath = configPath + `.tmp.${process.pid}`
120
- try {
121
- fs.writeFileSync(tmpPath, JSON.stringify(sanitized, null, 2) + "\n", "utf8")
122
- fs.renameSync(tmpPath, configPath)
123
- } catch (err) {
124
- try { fs.unlinkSync(tmpPath) } catch { /* ignore cleanup failure */ }
125
- throw err
126
- }
127
- }
128
-
129
- /**
130
- * Strip apiKey fields before writing config to disk.
131
- * API keys should be provided via environment variables
132
- * AKM_EMBED_API_KEY and AKM_LLM_API_KEY.
133
- */
134
- function sanitizeConfigForWrite(config: AgentikitConfig): AgentikitConfig {
135
- const sanitized = { ...config }
136
- if (sanitized.embedding) {
137
- const { apiKey, ...rest } = sanitized.embedding
138
- sanitized.embedding = rest as EmbeddingConnectionConfig
139
- }
140
- if (sanitized.llm) {
141
- const { apiKey, ...rest } = sanitized.llm
142
- sanitized.llm = rest as LlmConnectionConfig
143
- }
144
- return sanitized
145
- }
146
-
147
- export function updateConfig(partial: Partial<AgentikitConfig>): AgentikitConfig {
148
- const current = loadConfig()
149
- const merged: AgentikitConfig = { ...current, ...partial }
150
- saveConfig(merged)
151
- return merged
152
- }
153
-
154
- // ── Helpers ─────────────────────────────────────────────────────────────────
155
-
156
- function pickKnownKeys(raw: Record<string, unknown>): AgentikitConfig {
157
- const config: AgentikitConfig = { ...DEFAULT_CONFIG }
158
-
159
- if (typeof raw.semanticSearch === "boolean") {
160
- config.semanticSearch = raw.semanticSearch
161
- }
162
-
163
- if (Array.isArray(raw.mountedStashDirs)) {
164
- config.mountedStashDirs = raw.mountedStashDirs.filter(
165
- (d): d is string => typeof d === "string",
166
- )
167
- }
168
-
169
- const embedding = parseEmbeddingConfig(raw.embedding)
170
- if (embedding) config.embedding = embedding
171
-
172
- const llm = parseLlmConfig(raw.llm)
173
- if (llm) config.llm = llm
174
-
175
- const registry = parseRegistryConfig(raw.registry)
176
- if (registry) config.registry = registry
177
-
178
- if (Array.isArray(raw.registryUrls)) {
179
- config.registryUrls = raw.registryUrls.filter(
180
- (u): u is string => typeof u === "string" && u.startsWith("http"),
181
- )
182
- }
183
-
184
- return config
185
- }
186
-
187
- function readConfigObject(configPath: string): Record<string, unknown> | undefined {
188
- try {
189
- const raw = JSON.parse(fs.readFileSync(configPath, "utf8"))
190
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return undefined
191
- return raw
192
- } catch {
193
- return undefined
194
- }
195
- }
196
-
197
- function parseEmbeddingConfig(value: unknown): EmbeddingConnectionConfig | undefined {
198
- if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
199
- const obj = value as Record<string, unknown>
200
- if (typeof obj.endpoint !== "string" || !obj.endpoint) return undefined
201
- if (typeof obj.model !== "string" || !obj.model) return undefined
202
- const result: EmbeddingConnectionConfig = {
203
- endpoint: obj.endpoint,
204
- model: obj.model,
205
- }
206
- if (typeof obj.provider === "string" && obj.provider) {
207
- result.provider = obj.provider
208
- }
209
- if ("dimension" in obj) {
210
- if (
211
- typeof obj.dimension !== "number" ||
212
- !Number.isFinite(obj.dimension) ||
213
- !Number.isInteger(obj.dimension) ||
214
- obj.dimension <= 0
215
- ) {
216
- return undefined
217
- }
218
- result.dimension = obj.dimension
219
- }
220
- if (typeof obj.apiKey === "string" && obj.apiKey) {
221
- result.apiKey = obj.apiKey
222
- }
223
- return result
224
- }
225
-
226
- function parseLlmConfig(value: unknown): LlmConnectionConfig | undefined {
227
- if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
228
- const obj = value as Record<string, unknown>
229
- if (typeof obj.endpoint !== "string" || !obj.endpoint) return undefined
230
- if (typeof obj.model !== "string" || !obj.model) return undefined
231
- const result: LlmConnectionConfig = {
232
- endpoint: obj.endpoint,
233
- model: obj.model,
234
- }
235
- if (typeof obj.provider === "string" && obj.provider) {
236
- result.provider = obj.provider
237
- }
238
- if (typeof obj.temperature === "number" && Number.isFinite(obj.temperature)) {
239
- result.temperature = obj.temperature
240
- }
241
- if ("maxTokens" in obj) {
242
- if (
243
- typeof obj.maxTokens !== "number" ||
244
- !Number.isFinite(obj.maxTokens) ||
245
- !Number.isInteger(obj.maxTokens) ||
246
- obj.maxTokens <= 0
247
- ) {
248
- return undefined
249
- }
250
- result.maxTokens = obj.maxTokens
251
- }
252
- if (typeof obj.apiKey === "string" && obj.apiKey) {
253
- result.apiKey = obj.apiKey
254
- }
255
- return result
256
- }
257
-
258
- function parseRegistryConfig(value: unknown): RegistryConfig | undefined {
259
- if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
260
- const obj = value as Record<string, unknown>
261
- if (!Array.isArray(obj.installed)) return undefined
262
-
263
- const installed = obj.installed
264
- .map((entry) => parseRegistryInstalledEntry(entry))
265
- .filter((entry): entry is RegistryInstalledEntry => entry !== undefined)
266
-
267
- return { installed }
268
- }
269
-
270
- function parseRegistryInstalledEntry(value: unknown): RegistryInstalledEntry | undefined {
271
- if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
272
- const obj = value as Record<string, unknown>
273
-
274
- const id = asNonEmptyString(obj.id)
275
- const source = asRegistrySource(obj.source)
276
- const ref = asNonEmptyString(obj.ref)
277
- const artifactUrl = asNonEmptyString(obj.artifactUrl)
278
- const stashRoot = asNonEmptyString(obj.stashRoot)
279
- const cacheDir = asNonEmptyString(obj.cacheDir)
280
- const installedAt = asNonEmptyString(obj.installedAt)
281
- if (!id || !source || !ref || !artifactUrl || !stashRoot || !cacheDir || !installedAt) return undefined
282
-
283
- const entry: RegistryInstalledEntry = {
284
- id,
285
- source,
286
- ref,
287
- artifactUrl,
288
- stashRoot,
289
- cacheDir,
290
- installedAt,
291
- }
292
- const resolvedVersion = asNonEmptyString(obj.resolvedVersion)
293
- if (resolvedVersion) entry.resolvedVersion = resolvedVersion
294
- const resolvedRevision = asNonEmptyString(obj.resolvedRevision)
295
- if (resolvedRevision) entry.resolvedRevision = resolvedRevision
296
- return entry
297
- }
298
-
299
- function asNonEmptyString(value: unknown): string | undefined {
300
- return typeof value === "string" && value ? value : undefined
301
- }
302
-
303
- function asRegistrySource(value: unknown): RegistrySource | undefined {
304
- return value === "npm" || value === "github" || value === "git" ? value : undefined
305
- }