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
package/src/cli.ts DELETED
@@ -1,427 +0,0 @@
1
- #!/usr/bin/env node
2
- import { defineCommand, runMain } from "citty"
3
- import {
4
- agentikitAdd,
5
- agentikitList,
6
- agentikitReinstall,
7
- agentikitRemove,
8
- agentikitSearch,
9
- agentikitShow,
10
- agentikitUpdate,
11
- type KnowledgeView,
12
- } from "./stash"
13
- import type { SearchSource, SearchUsageMode } from "./stash-types"
14
- import { agentikitInit } from "./init"
15
- import { agentikitIndex } from "./indexer"
16
- import { agentikitClone } from "./stash-clone"
17
-
18
- import { resolveStashSources } from "./stash-source"
19
- import { loadConfig, saveConfig } from "./config"
20
- import {
21
- getConfigValue,
22
- listConfig,
23
- listProviders,
24
- parseConfigValue,
25
- setConfigValue,
26
- unsetConfigValue,
27
- useProvider,
28
- } from "./config-cli"
29
-
30
- const initCommand = defineCommand({
31
- meta: { name: "init", description: "Initialize Agent-i-Kit's working stash directory and set AKM_STASH_DIR" },
32
- async run() {
33
- await runWithJsonErrors(async () => {
34
- const result = await agentikitInit()
35
- console.log(JSON.stringify(result, null, 2))
36
- })
37
- },
38
- })
39
-
40
- const indexCommand = defineCommand({
41
- meta: { name: "index", description: "Build search index (incremental by default; --full forces full reindex)" },
42
- args: {
43
- full: { type: "boolean", description: "Force full reindex", default: false },
44
- },
45
- async run({ args }) {
46
- await runWithJsonErrors(async () => {
47
- const result = await agentikitIndex({ full: args.full })
48
- console.log(JSON.stringify(result, null, 2))
49
- })
50
- },
51
- })
52
-
53
- const searchCommand = defineCommand({
54
- meta: { name: "search", description: "Search the stash" },
55
- args: {
56
- query: { type: "positional", description: "Search query", required: false, default: "" },
57
- type: { type: "string", description: "Asset type filter (tool|skill|command|agent|knowledge|script|any)" },
58
- limit: { type: "string", description: "Maximum number of results" },
59
- usage: { type: "string", description: "Usage metadata mode (none|both|item|guide)", default: "both" },
60
- source: { type: "string", description: "Search source (local|registry|both)", default: "local" },
61
- },
62
- async run({ args }) {
63
- await runWithJsonErrors(async () => {
64
- const type = args.type as "tool" | "skill" | "command" | "agent" | "knowledge" | "script" | "any" | undefined
65
- const limit = args.limit ? parseInt(args.limit, 10) : undefined
66
- const usage = parseSearchUsageMode(args.usage)
67
- const source = parseSearchSource(args.source)
68
- console.log(JSON.stringify(await agentikitSearch({ query: args.query, type, limit, usage, source }), null, 2))
69
- })
70
- },
71
- })
72
-
73
- const addCommand = defineCommand({
74
- meta: { name: "add", description: "Install a registry package or local git directory into the stash" },
75
- args: {
76
- ref: {
77
- type: "positional",
78
- description: "Registry ref (npm package, owner/repo, github URL, or local git directory)",
79
- required: true,
80
- },
81
- },
82
- async run({ args }) {
83
- await runWithJsonErrors(async () => {
84
- console.log(JSON.stringify(await agentikitAdd({ ref: args.ref }), null, 2))
85
- })
86
- },
87
- })
88
-
89
- const listCommand = defineCommand({
90
- meta: { name: "list", description: "List installed registry packages from config" },
91
- async run() {
92
- await runWithJsonErrors(async () => {
93
- console.log(JSON.stringify(await agentikitList(), null, 2))
94
- })
95
- },
96
- })
97
-
98
- const removeCommand = defineCommand({
99
- meta: { name: "remove", description: "Remove an installed registry package by id or ref" },
100
- args: {
101
- target: { type: "positional", description: "Installed target (id or ref)", required: true },
102
- },
103
- async run({ args }) {
104
- await runWithJsonErrors(async () => {
105
- console.log(JSON.stringify(await agentikitRemove({ target: args.target }), null, 2))
106
- })
107
- },
108
- })
109
-
110
- const updateCommand = defineCommand({
111
- meta: { name: "update", description: "Update one or all installed registry packages" },
112
- args: {
113
- target: { type: "positional", description: "Installed target (id or ref)", required: false },
114
- all: { type: "boolean", description: "Update all installed entries", default: false },
115
- },
116
- async run({ args }) {
117
- await runWithJsonErrors(async () => {
118
- console.log(JSON.stringify(await agentikitUpdate({ target: args.target, all: args.all }), null, 2))
119
- })
120
- },
121
- })
122
-
123
- const reinstallCommand = defineCommand({
124
- meta: { name: "reinstall", description: "Reinstall one or all installed registry packages" },
125
- args: {
126
- target: { type: "positional", description: "Installed target (id or ref)", required: false },
127
- all: { type: "boolean", description: "Reinstall all installed entries", default: false },
128
- },
129
- async run({ args }) {
130
- await runWithJsonErrors(async () => {
131
- console.log(JSON.stringify(await agentikitReinstall({ target: args.target, all: args.all }), null, 2))
132
- })
133
- },
134
- })
135
-
136
- const showCommand = defineCommand({
137
- meta: { name: "show", description: "Show a stash asset by ref (e.g. agent:bunjs-typescript-coder.md)" },
138
- args: {
139
- ref: { type: "positional", description: "Asset ref (type:name)", required: true },
140
- view: { type: "string", description: "Knowledge view mode (full|toc|frontmatter|section|lines)" },
141
- heading: { type: "string", description: "Section heading (for --view section)" },
142
- start: { type: "string", description: "Start line (for --view lines)" },
143
- end: { type: "string", description: "End line (for --view lines)" },
144
- },
145
- async run({ args }) {
146
- await runWithJsonErrors(async () => {
147
- let view: KnowledgeView | undefined
148
- if (args.view) {
149
- switch (args.view) {
150
- case "section":
151
- view = { mode: "section", heading: args.heading ?? "" }
152
- break
153
- case "lines":
154
- view = {
155
- mode: "lines",
156
- start: Number(args.start ?? "1"),
157
- end: args.end ? parseInt(args.end, 10) : Number.MAX_SAFE_INTEGER,
158
- }
159
- break
160
- case "toc":
161
- case "frontmatter":
162
- case "full":
163
- view = { mode: args.view }
164
- break
165
- default:
166
- throw new Error(`Unknown view mode: ${args.view}. Expected one of: full|toc|frontmatter|section|lines`)
167
- }
168
- }
169
- console.log(JSON.stringify(await agentikitShow({ ref: args.ref, view }), null, 2))
170
- })
171
- },
172
- })
173
-
174
- const configCommand = defineCommand({
175
- meta: { name: "config", description: "Show configuration, get/set keys, and manage embedding/LLM providers" },
176
- args: {
177
- list: { type: "boolean", description: "List current configuration with effective defaults", default: false },
178
- get: { type: "string", description: "Get a configuration value by key" },
179
- unset: { type: "string", description: "Unset an optional configuration key or whole embedding/llm section" },
180
- set: { type: "string", description: "Back-compat alias for updating a key (key=value format)" },
181
- },
182
- subCommands: {
183
- list: defineCommand({
184
- meta: { name: "list", description: "List current configuration with effective embedding/LLM settings" },
185
- run() {
186
- return runWithJsonErrors(() => {
187
- console.log(JSON.stringify(listConfig(loadConfig()), null, 2))
188
- })
189
- },
190
- }),
191
- get: defineCommand({
192
- meta: { name: "get", description: "Get a configuration value by key" },
193
- args: {
194
- key: { type: "positional", required: true, description: "Config key (for example: embedding.provider)" },
195
- },
196
- run({ args }) {
197
- return runWithJsonErrors(() => {
198
- console.log(JSON.stringify(getConfigValue(loadConfig(), args.key), null, 2))
199
- })
200
- },
201
- }),
202
- set: defineCommand({
203
- meta: { name: "set", description: "Set a configuration value by key" },
204
- args: {
205
- key: { type: "positional", required: true, description: "Config key (for example: llm.temperature)" },
206
- value: { type: "positional", required: true, description: "Config value" },
207
- },
208
- run({ args }) {
209
- return runWithJsonErrors(() => {
210
- const updated = setConfigValue(loadConfig(), args.key, args.value)
211
- saveConfig(updated)
212
- console.log(JSON.stringify(listConfig(updated), null, 2))
213
- })
214
- },
215
- }),
216
- unset: defineCommand({
217
- meta: { name: "unset", description: "Unset an optional configuration key or whole embedding/llm section" },
218
- args: {
219
- key: { type: "positional", required: true, description: "Config key to unset" },
220
- },
221
- run({ args }) {
222
- return runWithJsonErrors(() => {
223
- const updated = unsetConfigValue(loadConfig(), args.key)
224
- saveConfig(updated)
225
- console.log(JSON.stringify(listConfig(updated), null, 2))
226
- })
227
- },
228
- }),
229
- providers: defineCommand({
230
- meta: { name: "providers", description: "List available embedding or LLM providers" },
231
- args: {
232
- scope: { type: "positional", required: true, description: "Provider scope: embedding or llm" },
233
- },
234
- run({ args }) {
235
- return runWithJsonErrors(() => {
236
- const scope = parseProviderScope(args.scope)
237
- console.log(JSON.stringify(listProviders(scope, loadConfig()), null, 2))
238
- })
239
- },
240
- }),
241
- use: defineCommand({
242
- meta: { name: "use", description: "Switch the default embedding or LLM provider" },
243
- args: {
244
- scope: { type: "positional", required: true, description: "Provider scope: embedding or llm" },
245
- provider: { type: "positional", required: true, description: "Provider name" },
246
- },
247
- run({ args }) {
248
- return runWithJsonErrors(() => {
249
- const scope = parseProviderScope(args.scope)
250
- const updated = useProvider(loadConfig(), scope, args.provider)
251
- saveConfig(updated)
252
- console.log(JSON.stringify(listConfig(updated), null, 2))
253
- })
254
- },
255
- }),
256
- },
257
- run({ args }) {
258
- return runWithJsonErrors(() => {
259
- if (hasConfigSubcommand(args)) return
260
- if (args.list) {
261
- console.log(JSON.stringify(listConfig(loadConfig()), null, 2))
262
- return
263
- }
264
- if (args.get) {
265
- console.log(JSON.stringify(getConfigValue(loadConfig(), args.get), null, 2))
266
- return
267
- }
268
- if (args.unset) {
269
- const updated = unsetConfigValue(loadConfig(), args.unset)
270
- saveConfig(updated)
271
- console.log(JSON.stringify(listConfig(updated), null, 2))
272
- return
273
- }
274
- if (args.set) {
275
- const eqIndex = args.set.indexOf("=")
276
- if (eqIndex === -1) {
277
- throw new Error("--set expects key=value format")
278
- }
279
- const key = args.set.slice(0, eqIndex)
280
- const value = args.set.slice(eqIndex + 1)
281
- const partial = parseConfigValue(key, value)
282
- const config = { ...loadConfig(), ...partial }
283
- saveConfig(config)
284
- console.log(JSON.stringify(listConfig(config), null, 2))
285
- } else {
286
- console.log(JSON.stringify(listConfig(loadConfig()), null, 2))
287
- }
288
- })
289
- },
290
- })
291
-
292
- const cloneCommand = defineCommand({
293
- meta: { name: "clone", description: "Clone an asset from any stash source into the working stash" },
294
- args: {
295
- ref: { type: "positional", description: "Asset ref (e.g. @installed:pkg/tool:script.sh)", required: true },
296
- name: { type: "string", description: "New name for the cloned asset" },
297
- force: { type: "boolean", description: "Overwrite if asset already exists in working stash", default: false },
298
- },
299
- async run({ args }) {
300
- await runWithJsonErrors(async () => {
301
- const result = await agentikitClone({
302
- sourceRef: args.ref,
303
- newName: args.name,
304
- force: args.force,
305
- })
306
- console.log(JSON.stringify(result, null, 2))
307
- })
308
- },
309
- })
310
-
311
-
312
- const sourcesCommand = defineCommand({
313
- meta: { name: "sources", description: "List all stash sources with their kind, path, and status" },
314
- run() {
315
- return runWithJsonErrors(() => {
316
- const sources = resolveStashSources()
317
- console.log(JSON.stringify({ sources }, null, 2))
318
- })
319
- },
320
- })
321
-
322
- const main = defineCommand({
323
- meta: {
324
- name: "akm",
325
- description: "CLI tool to search, open, and manage assets from Agent-i-Kit stash.",
326
- },
327
- subCommands: {
328
- init: initCommand,
329
- index: indexCommand,
330
- add: addCommand,
331
- list: listCommand,
332
- remove: removeCommand,
333
- update: updateCommand,
334
- reinstall: reinstallCommand,
335
- search: searchCommand,
336
- show: showCommand,
337
- clone: cloneCommand,
338
- sources: sourcesCommand,
339
- config: configCommand,
340
- },
341
- })
342
-
343
- const SEARCH_USAGE_MODES: SearchUsageMode[] = ["none", "both", "item", "guide"]
344
- const SEARCH_SOURCES: SearchSource[] = ["local", "registry", "both"]
345
- const CONFIG_SUBCOMMAND_SET = new Set(["list", "get", "set", "unset", "providers", "use"])
346
-
347
- // Note: citty reads process.argv directly, so we must normalize it in-place.
348
- // This is done once at startup before runMain.
349
- normalizeConfigArgv(process.argv)
350
- runMain(main)
351
-
352
- function parseSearchUsageMode(value: string): SearchUsageMode {
353
- if ((SEARCH_USAGE_MODES as string[]).includes(value)) return value as SearchUsageMode
354
- throw new Error(`Invalid value for --usage: ${value}. Expected one of: ${SEARCH_USAGE_MODES.join("|")}`)
355
- }
356
-
357
- function parseSearchSource(value: string): SearchSource {
358
- if ((SEARCH_SOURCES as string[]).includes(value)) return value as SearchSource
359
- throw new Error(`Invalid value for --source: ${value}. Expected one of: ${SEARCH_SOURCES.join("|")}`)
360
- }
361
-
362
- async function runWithJsonErrors(fn: (() => void) | (() => Promise<void>)): Promise<void> {
363
- try {
364
- await fn()
365
- } catch (error: unknown) {
366
- const message = error instanceof Error ? error.message : String(error)
367
- const hint = buildHint(message)
368
- console.error(JSON.stringify({ ok: false, error: message, hint }, null, 2))
369
- process.exit(1)
370
- }
371
- }
372
-
373
- function buildHint(message: string): string | undefined {
374
- if (message.includes("AKM_STASH_DIR")) return "Run `akm init` or set AKM_STASH_DIR to a valid directory."
375
- if (message.includes("Either <target> or --all is required")) return "Use `akm update --all` or pass a target like `akm update npm:@scope/pkg`."
376
- if (message.includes("Specify either <target> or --all")) return "Use only one: a positional target or `--all`."
377
- if (message.includes("No installed registry entry matched target")) return "Run `akm list` to view installed ids/refs, then retry with one of those values."
378
- if (message.includes("Invalid value for --source")) return "Pick one of: local, registry, both."
379
- if (message.includes("Invalid value for --usage")) return "Pick one of: none, both, item, guide."
380
- if (message.includes("expected JSON object with endpoint and model")) {
381
- return "Quote JSON values in your shell, for example: akm config set embedding '{\"endpoint\":\"http://localhost:11434/v1/embeddings\",\"model\":\"nomic-embed-text\"}'."
382
- }
383
- return undefined
384
- }
385
-
386
- function parseProviderScope(value: string): "embedding" | "llm" {
387
- if (value === "embedding" || value === "llm") return value
388
- throw new Error(`Invalid provider scope: ${value}. Expected one of: embedding|llm`)
389
- }
390
-
391
- function hasConfigSubcommand(args: Record<string, unknown>): boolean {
392
- const command = Array.isArray(args._) ? args._[0] : undefined
393
- return typeof command === "string" && CONFIG_SUBCOMMAND_SET.has(command)
394
- }
395
-
396
- /**
397
- * Mutate argv before citty parses it so git-style config forms like
398
- * `akm config llm.maxTokens 512` and `akm config --get llm.maxTokens`
399
- * are normalized into the existing config subcommands.
400
- */
401
- function normalizeConfigArgv(argv: string[]): void {
402
- const [, , command, argAfterCommand, argAfterKey, ...rest] = argv
403
- if (command !== "config") return
404
- if (!argAfterCommand) return
405
- if (argAfterCommand === "--list") {
406
- argv.splice(3, argv.length - 3, "list")
407
- return
408
- }
409
- if (argAfterCommand === "--get" && argAfterKey) {
410
- argv.splice(3, argv.length - 3, "get", argAfterKey, ...rest)
411
- return
412
- }
413
- if (argAfterCommand === "--unset" && argAfterKey) {
414
- argv.splice(3, argv.length - 3, "unset", argAfterKey, ...rest)
415
- return
416
- }
417
- if (argAfterCommand.startsWith("-")) return
418
- if (CONFIG_SUBCOMMAND_SET.has(argAfterCommand)) return
419
-
420
- // A single arg after `config` behaves like `git config <key>` and reads the value.
421
- if (argAfterKey === undefined) {
422
- argv.splice(3, argv.length - 3, "get", argAfterCommand)
423
- return
424
- }
425
-
426
- argv.splice(3, argv.length - 3, "set", argAfterCommand, argAfterKey, ...rest)
427
- }
package/src/common.ts DELETED
@@ -1,76 +0,0 @@
1
- import fs from "node:fs"
2
- import path from "node:path"
3
- import { TYPE_DIRS } from "./asset-spec"
4
-
5
- // ── Types ───────────────────────────────────────────────────────────────────
6
-
7
- export type AgentikitAssetType = "tool" | "skill" | "command" | "agent" | "knowledge" | "script"
8
-
9
- // ── Constants ───────────────────────────────────────────────────────────────
10
-
11
- export const IS_WINDOWS = process.platform === "win32"
12
- export { SCRIPT_EXTENSIONS, TYPE_DIRS } from "./asset-spec"
13
-
14
- // ── Validators ──────────────────────────────────────────────────────────────
15
-
16
- export function isAssetType(type: string): type is AgentikitAssetType {
17
- return type in TYPE_DIRS
18
- }
19
-
20
- // ── Utilities ───────────────────────────────────────────────────────────────
21
-
22
- export function resolveStashDir(): string {
23
- const raw = process.env.AKM_STASH_DIR?.trim()
24
- if (!raw) {
25
- throw new Error("AKM_STASH_DIR is not set. Set it to your Agentikit stash path.")
26
- }
27
- const stashDir = path.resolve(raw)
28
- let stat: fs.Stats
29
- try {
30
- stat = fs.statSync(stashDir)
31
- } catch {
32
- throw new Error(`Unable to read AKM_STASH_DIR at "${stashDir}".`)
33
- }
34
- if (!stat.isDirectory()) {
35
- throw new Error(`AKM_STASH_DIR must point to a directory: "${stashDir}".`)
36
- }
37
- return stashDir
38
- }
39
-
40
- export function toPosix(input: string): string {
41
- return input.replace(/\\/g, "/")
42
- }
43
-
44
- export function hasErrnoCode(error: unknown, code: string): boolean {
45
- if (typeof error !== "object" || error === null || !("code" in error)) return false
46
- return (error as Record<string, unknown>).code === code
47
- }
48
-
49
- export function isWithin(candidate: string, root: string): boolean {
50
- const normalizedRoot = normalizeFsPathForComparison(path.resolve(root))
51
- const normalizedCandidate = normalizeFsPathForComparison(path.resolve(candidate))
52
- const rel = path.relative(normalizedRoot, normalizedCandidate)
53
- return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel))
54
- }
55
-
56
- function normalizeFsPathForComparison(value: string): string {
57
- return process.platform === "win32" ? value.toLowerCase() : value
58
- }
59
-
60
- /**
61
- * Fetch with an AbortController timeout.
62
- * Defaults to 30 seconds if no timeout is specified.
63
- */
64
- export async function fetchWithTimeout(
65
- url: string,
66
- opts?: RequestInit,
67
- timeoutMs = 30_000,
68
- ): Promise<Response> {
69
- const controller = new AbortController()
70
- const timer = setTimeout(() => controller.abort(), timeoutMs)
71
- try {
72
- return await fetch(url, { ...opts, signal: controller.signal })
73
- } finally {
74
- clearTimeout(timer)
75
- }
76
- }