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