agentikit 0.0.7 → 0.0.9
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 +215 -76
- package/dist/index.d.ts +17 -3
- package/dist/index.js +10 -2
- package/dist/src/asset-spec.d.ts +14 -0
- package/dist/src/asset-spec.js +46 -0
- package/dist/src/cli.js +268 -57
- package/dist/src/common.d.ts +8 -0
- package/dist/src/common.js +46 -0
- package/dist/src/config.d.ts +37 -0
- package/dist/src/config.js +124 -0
- package/dist/src/embedder.d.ts +10 -0
- package/dist/src/embedder.js +87 -0
- package/dist/src/frontmatter.d.ts +30 -0
- package/dist/src/frontmatter.js +86 -0
- package/dist/src/indexer.d.ts +20 -2
- package/dist/src/indexer.js +212 -80
- package/dist/src/init.d.ts +19 -0
- package/dist/src/init.js +87 -0
- package/dist/src/llm.d.ts +15 -0
- package/dist/src/llm.js +91 -0
- package/dist/src/markdown.d.ts +18 -0
- package/dist/src/markdown.js +77 -0
- package/dist/src/metadata.d.ts +11 -2
- package/dist/src/metadata.js +161 -29
- package/dist/src/registry-install.d.ts +11 -0
- package/dist/src/registry-install.js +208 -0
- package/dist/src/registry-resolve.d.ts +3 -0
- package/dist/src/registry-resolve.js +231 -0
- package/dist/src/registry-search.d.ts +5 -0
- package/dist/src/registry-search.js +129 -0
- package/dist/src/registry-types.d.ts +55 -0
- package/dist/src/registry-types.js +1 -0
- package/dist/src/ripgrep-install.d.ts +12 -0
- package/dist/src/ripgrep-install.js +169 -0
- package/dist/src/ripgrep-resolve.d.ts +13 -0
- package/dist/src/ripgrep-resolve.js +68 -0
- package/dist/src/ripgrep.d.ts +3 -36
- package/dist/src/ripgrep.js +2 -262
- package/dist/src/similarity.d.ts +1 -2
- package/dist/src/similarity.js +11 -0
- package/dist/src/stash-add.d.ts +4 -0
- package/dist/src/stash-add.js +59 -0
- package/dist/src/stash-ref.d.ts +7 -0
- package/dist/src/stash-ref.js +33 -0
- package/dist/src/stash-registry.d.ts +18 -0
- package/dist/src/stash-registry.js +221 -0
- package/dist/src/stash-resolve.d.ts +2 -0
- package/dist/src/stash-resolve.js +45 -0
- package/dist/src/stash-search.d.ts +8 -0
- package/dist/src/stash-search.js +484 -0
- package/dist/src/stash-show.d.ts +5 -0
- package/dist/src/stash-show.js +114 -0
- package/dist/src/stash-types.d.ts +217 -0
- package/dist/src/stash-types.js +1 -0
- package/dist/src/stash.d.ts +10 -63
- package/dist/src/stash.js +6 -633
- package/dist/src/tool-runner.d.ts +35 -0
- package/dist/src/tool-runner.js +100 -0
- package/dist/src/walker.d.ts +19 -0
- package/dist/src/walker.js +47 -0
- package/package.json +8 -14
- package/src/asset-spec.ts +69 -0
- package/src/cli.ts +282 -46
- package/src/common.ts +58 -0
- package/src/config.ts +183 -0
- package/src/embedder.ts +117 -0
- package/src/frontmatter.ts +95 -0
- package/src/indexer.ts +244 -84
- package/src/init.ts +106 -0
- package/src/llm.ts +124 -0
- package/src/markdown.ts +106 -0
- package/src/metadata.ts +171 -27
- package/src/registry-install.ts +245 -0
- package/src/registry-resolve.ts +272 -0
- package/src/registry-search.ts +145 -0
- package/src/registry-types.ts +64 -0
- package/src/ripgrep-install.ts +200 -0
- package/src/ripgrep-resolve.ts +72 -0
- package/src/ripgrep.ts +3 -315
- package/src/similarity.ts +13 -1
- package/src/stash-add.ts +66 -0
- package/src/stash-ref.ts +41 -0
- package/src/stash-registry.ts +259 -0
- package/src/stash-resolve.ts +47 -0
- package/src/stash-search.ts +595 -0
- package/src/stash-show.ts +112 -0
- package/src/stash-types.ts +221 -0
- package/src/stash.ts +31 -760
- package/src/tool-runner.ts +129 -0
- package/src/walker.ts +53 -0
- package/.claude-plugin/plugin.json +0 -21
- package/commands/open.md +0 -11
- package/commands/run.md +0 -11
- package/commands/search.md +0 -11
- package/dist/src/plugin.d.ts +0 -2
- package/dist/src/plugin.js +0 -55
- package/skills/stash/SKILL.md +0 -73
- package/src/plugin.ts +0 -56
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isAssetType } from "./common";
|
|
3
|
+
export function parseOpenRef(ref) {
|
|
4
|
+
const separator = ref.indexOf(":");
|
|
5
|
+
if (separator <= 0) {
|
|
6
|
+
throw new Error("Invalid open ref. Expected format '<type>:<name>'.");
|
|
7
|
+
}
|
|
8
|
+
const rawType = ref.slice(0, separator);
|
|
9
|
+
const rawName = ref.slice(separator + 1);
|
|
10
|
+
if (!isAssetType(rawType)) {
|
|
11
|
+
throw new Error(`Invalid open ref type: "${rawType}".`);
|
|
12
|
+
}
|
|
13
|
+
let name;
|
|
14
|
+
try {
|
|
15
|
+
name = decodeURIComponent(rawName);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new Error("Invalid open ref encoding.");
|
|
19
|
+
}
|
|
20
|
+
const normalized = path.posix.normalize(name.replace(/\\/g, "/"));
|
|
21
|
+
if (!name
|
|
22
|
+
|| name.includes("\0")
|
|
23
|
+
|| /^[A-Za-z]:/.test(name)
|
|
24
|
+
|| path.posix.isAbsolute(normalized)
|
|
25
|
+
|| normalized === ".."
|
|
26
|
+
|| normalized.startsWith("../")) {
|
|
27
|
+
throw new Error("Invalid open ref name.");
|
|
28
|
+
}
|
|
29
|
+
return { type: rawType, name: normalized };
|
|
30
|
+
}
|
|
31
|
+
export function makeOpenRef(type, name) {
|
|
32
|
+
return `${type}:${encodeURIComponent(name)}`;
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ListResponse, RemoveResponse, ReinstallResponse, UpdateResponse } from "./stash-types";
|
|
2
|
+
export declare function agentikitList(input?: {
|
|
3
|
+
stashDir?: string;
|
|
4
|
+
}): Promise<ListResponse>;
|
|
5
|
+
export declare function agentikitRemove(input: {
|
|
6
|
+
target: string;
|
|
7
|
+
stashDir?: string;
|
|
8
|
+
}): Promise<RemoveResponse>;
|
|
9
|
+
export declare function agentikitReinstall(input?: {
|
|
10
|
+
target?: string;
|
|
11
|
+
all?: boolean;
|
|
12
|
+
stashDir?: string;
|
|
13
|
+
}): Promise<ReinstallResponse>;
|
|
14
|
+
export declare function agentikitUpdate(input?: {
|
|
15
|
+
target?: string;
|
|
16
|
+
all?: boolean;
|
|
17
|
+
stashDir?: string;
|
|
18
|
+
}): Promise<UpdateResponse>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { resolveStashDir } from "./common";
|
|
3
|
+
import { loadConfig } from "./config";
|
|
4
|
+
import { agentikitIndex } from "./indexer";
|
|
5
|
+
import { installRegistryRef, removeInstalledRegistryEntry, upsertInstalledRegistryEntry, } from "./registry-install";
|
|
6
|
+
import { parseRegistryRef } from "./registry-resolve";
|
|
7
|
+
export async function agentikitList(input) {
|
|
8
|
+
const stashDir = input?.stashDir ?? resolveStashDir();
|
|
9
|
+
const config = loadConfig(stashDir);
|
|
10
|
+
const installed = config.registry?.installed ?? [];
|
|
11
|
+
return {
|
|
12
|
+
stashDir,
|
|
13
|
+
installed: installed.map((entry) => ({
|
|
14
|
+
...entry,
|
|
15
|
+
status: {
|
|
16
|
+
cacheDirExists: directoryExists(entry.cacheDir),
|
|
17
|
+
stashRootExists: directoryExists(entry.stashRoot),
|
|
18
|
+
},
|
|
19
|
+
})),
|
|
20
|
+
totalInstalled: installed.length,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export async function agentikitRemove(input) {
|
|
24
|
+
const target = input.target.trim();
|
|
25
|
+
if (!target)
|
|
26
|
+
throw new Error("Target is required.");
|
|
27
|
+
const stashDir = input.stashDir ?? resolveStashDir();
|
|
28
|
+
const config = loadConfig(stashDir);
|
|
29
|
+
const installed = config.registry?.installed ?? [];
|
|
30
|
+
const entry = resolveInstalledTarget(installed, target);
|
|
31
|
+
const updatedConfig = removeInstalledRegistryEntry(entry.id, stashDir);
|
|
32
|
+
cleanupDirectoryBestEffort(entry.cacheDir);
|
|
33
|
+
const index = await agentikitIndex({ stashDir });
|
|
34
|
+
return {
|
|
35
|
+
stashDir,
|
|
36
|
+
target,
|
|
37
|
+
removed: {
|
|
38
|
+
id: entry.id,
|
|
39
|
+
source: entry.source,
|
|
40
|
+
ref: entry.ref,
|
|
41
|
+
cacheDir: entry.cacheDir,
|
|
42
|
+
stashRoot: entry.stashRoot,
|
|
43
|
+
},
|
|
44
|
+
config: {
|
|
45
|
+
additionalStashDirs: updatedConfig.additionalStashDirs,
|
|
46
|
+
installedRegistryCount: updatedConfig.registry?.installed.length ?? 0,
|
|
47
|
+
},
|
|
48
|
+
index: {
|
|
49
|
+
mode: index.mode,
|
|
50
|
+
totalEntries: index.totalEntries,
|
|
51
|
+
directoriesScanned: index.directoriesScanned,
|
|
52
|
+
directoriesSkipped: index.directoriesSkipped,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export async function agentikitReinstall(input) {
|
|
57
|
+
const stashDir = input?.stashDir ?? resolveStashDir();
|
|
58
|
+
const target = input?.target?.trim();
|
|
59
|
+
const all = input?.all === true;
|
|
60
|
+
const installedEntries = loadConfig(stashDir).registry?.installed ?? [];
|
|
61
|
+
const selectedEntries = selectTargets(installedEntries, target, all);
|
|
62
|
+
const processed = [];
|
|
63
|
+
for (const entry of selectedEntries) {
|
|
64
|
+
const installed = await installRegistryRef(entry.ref);
|
|
65
|
+
upsertInstalledRegistryEntry(toInstalledEntry(installed), stashDir);
|
|
66
|
+
if (entry.cacheDir !== installed.cacheDir) {
|
|
67
|
+
cleanupDirectoryBestEffort(entry.cacheDir);
|
|
68
|
+
}
|
|
69
|
+
processed.push({
|
|
70
|
+
id: entry.id,
|
|
71
|
+
source: entry.source,
|
|
72
|
+
ref: entry.ref,
|
|
73
|
+
previousCacheDir: entry.cacheDir,
|
|
74
|
+
installed: toInstallStatus(installed),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const index = await agentikitIndex({ stashDir });
|
|
78
|
+
const config = loadConfig(stashDir);
|
|
79
|
+
return {
|
|
80
|
+
stashDir,
|
|
81
|
+
target,
|
|
82
|
+
all,
|
|
83
|
+
processed,
|
|
84
|
+
config: {
|
|
85
|
+
additionalStashDirs: config.additionalStashDirs,
|
|
86
|
+
installedRegistryCount: config.registry?.installed.length ?? 0,
|
|
87
|
+
},
|
|
88
|
+
index: {
|
|
89
|
+
mode: index.mode,
|
|
90
|
+
totalEntries: index.totalEntries,
|
|
91
|
+
directoriesScanned: index.directoriesScanned,
|
|
92
|
+
directoriesSkipped: index.directoriesSkipped,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export async function agentikitUpdate(input) {
|
|
97
|
+
const stashDir = input?.stashDir ?? resolveStashDir();
|
|
98
|
+
const target = input?.target?.trim();
|
|
99
|
+
const all = input?.all === true;
|
|
100
|
+
const installedEntries = loadConfig(stashDir).registry?.installed ?? [];
|
|
101
|
+
const selectedEntries = selectTargets(installedEntries, target, all);
|
|
102
|
+
const processed = [];
|
|
103
|
+
for (const entry of selectedEntries) {
|
|
104
|
+
const installed = await installRegistryRef(entry.ref);
|
|
105
|
+
upsertInstalledRegistryEntry(toInstalledEntry(installed), stashDir);
|
|
106
|
+
if (entry.cacheDir !== installed.cacheDir) {
|
|
107
|
+
cleanupDirectoryBestEffort(entry.cacheDir);
|
|
108
|
+
}
|
|
109
|
+
const versionChanged = (entry.resolvedVersion ?? "") !== (installed.resolvedVersion ?? "");
|
|
110
|
+
const revisionChanged = (entry.resolvedRevision ?? "") !== (installed.resolvedRevision ?? "");
|
|
111
|
+
processed.push({
|
|
112
|
+
id: entry.id,
|
|
113
|
+
source: entry.source,
|
|
114
|
+
ref: entry.ref,
|
|
115
|
+
previous: {
|
|
116
|
+
resolvedVersion: entry.resolvedVersion,
|
|
117
|
+
resolvedRevision: entry.resolvedRevision,
|
|
118
|
+
cacheDir: entry.cacheDir,
|
|
119
|
+
},
|
|
120
|
+
installed: toInstallStatus(installed),
|
|
121
|
+
changed: {
|
|
122
|
+
version: versionChanged,
|
|
123
|
+
revision: revisionChanged,
|
|
124
|
+
any: versionChanged || revisionChanged,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const index = await agentikitIndex({ stashDir });
|
|
129
|
+
const config = loadConfig(stashDir);
|
|
130
|
+
return {
|
|
131
|
+
stashDir,
|
|
132
|
+
target,
|
|
133
|
+
all,
|
|
134
|
+
processed,
|
|
135
|
+
config: {
|
|
136
|
+
additionalStashDirs: config.additionalStashDirs,
|
|
137
|
+
installedRegistryCount: config.registry?.installed.length ?? 0,
|
|
138
|
+
},
|
|
139
|
+
index: {
|
|
140
|
+
mode: index.mode,
|
|
141
|
+
totalEntries: index.totalEntries,
|
|
142
|
+
directoriesScanned: index.directoriesScanned,
|
|
143
|
+
directoriesSkipped: index.directoriesSkipped,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function selectTargets(installed, target, all) {
|
|
148
|
+
if (all && target) {
|
|
149
|
+
throw new Error("Specify either <target> or --all, not both.");
|
|
150
|
+
}
|
|
151
|
+
if (all)
|
|
152
|
+
return installed;
|
|
153
|
+
if (!target) {
|
|
154
|
+
throw new Error("Either <target> or --all is required.");
|
|
155
|
+
}
|
|
156
|
+
return [resolveInstalledTarget(installed, target)];
|
|
157
|
+
}
|
|
158
|
+
function resolveInstalledTarget(installed, target) {
|
|
159
|
+
const byId = installed.find((entry) => entry.id === target);
|
|
160
|
+
if (byId)
|
|
161
|
+
return byId;
|
|
162
|
+
const byRef = installed.find((entry) => entry.ref === target);
|
|
163
|
+
if (byRef)
|
|
164
|
+
return byRef;
|
|
165
|
+
let parsedId;
|
|
166
|
+
try {
|
|
167
|
+
parsedId = parseRegistryRef(target).id;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
parsedId = undefined;
|
|
171
|
+
}
|
|
172
|
+
if (parsedId) {
|
|
173
|
+
const byParsedId = installed.find((entry) => entry.id === parsedId);
|
|
174
|
+
if (byParsedId)
|
|
175
|
+
return byParsedId;
|
|
176
|
+
}
|
|
177
|
+
throw new Error(`No installed registry entry matched target: ${target}`);
|
|
178
|
+
}
|
|
179
|
+
function toInstalledEntry(status) {
|
|
180
|
+
return {
|
|
181
|
+
id: status.id,
|
|
182
|
+
source: status.source,
|
|
183
|
+
ref: status.ref,
|
|
184
|
+
artifactUrl: status.artifactUrl,
|
|
185
|
+
resolvedVersion: status.resolvedVersion,
|
|
186
|
+
resolvedRevision: status.resolvedRevision,
|
|
187
|
+
stashRoot: status.stashRoot,
|
|
188
|
+
cacheDir: status.cacheDir,
|
|
189
|
+
installedAt: status.installedAt,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function toInstallStatus(status) {
|
|
193
|
+
return {
|
|
194
|
+
id: status.id,
|
|
195
|
+
source: status.source,
|
|
196
|
+
ref: status.ref,
|
|
197
|
+
artifactUrl: status.artifactUrl,
|
|
198
|
+
resolvedVersion: status.resolvedVersion,
|
|
199
|
+
resolvedRevision: status.resolvedRevision,
|
|
200
|
+
stashRoot: status.stashRoot,
|
|
201
|
+
cacheDir: status.cacheDir,
|
|
202
|
+
extractedDir: status.extractedDir,
|
|
203
|
+
installedAt: status.installedAt,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function cleanupDirectoryBestEffort(target) {
|
|
207
|
+
try {
|
|
208
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// Best-effort cleanup only.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function directoryExists(target) {
|
|
215
|
+
try {
|
|
216
|
+
return fs.statSync(target).isDirectory();
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { hasErrnoCode, isWithin } from "./common";
|
|
4
|
+
import { TYPE_DIRS, isRelevantAssetFile, resolveAssetPathFromName } from "./asset-spec";
|
|
5
|
+
export function resolveAssetPath(stashDir, type, name) {
|
|
6
|
+
const root = path.join(stashDir, TYPE_DIRS[type]);
|
|
7
|
+
const target = resolveAssetPathFromName(type, root, name);
|
|
8
|
+
const resolvedRoot = resolveAndValidateTypeRoot(root, type, name);
|
|
9
|
+
const resolvedTarget = path.resolve(target);
|
|
10
|
+
if (!isWithin(resolvedTarget, resolvedRoot)) {
|
|
11
|
+
throw new Error("Ref resolves outside the stash root.");
|
|
12
|
+
}
|
|
13
|
+
if (!fs.existsSync(resolvedTarget) || !fs.statSync(resolvedTarget).isFile()) {
|
|
14
|
+
throw new Error(`Stash asset not found for ref: ${type}:${name}`);
|
|
15
|
+
}
|
|
16
|
+
const realTarget = fs.realpathSync(resolvedTarget);
|
|
17
|
+
if (!isWithin(realTarget, resolvedRoot)) {
|
|
18
|
+
throw new Error("Ref resolves outside the stash root.");
|
|
19
|
+
}
|
|
20
|
+
if (!isRelevantAssetFile(type, path.basename(resolvedTarget))) {
|
|
21
|
+
if (type === "tool") {
|
|
22
|
+
throw new Error("Tool ref must resolve to a .sh, .ts, .js, .ps1, .cmd, or .bat file.");
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`Stash asset not found for ref: ${type}:${name}`);
|
|
25
|
+
}
|
|
26
|
+
return realTarget;
|
|
27
|
+
}
|
|
28
|
+
function resolveAndValidateTypeRoot(root, type, name) {
|
|
29
|
+
const rootStat = readTypeRootStat(root, type, name);
|
|
30
|
+
if (!rootStat.isDirectory()) {
|
|
31
|
+
throw new Error(`Stash type root is not a directory for ref: ${type}:${name}`);
|
|
32
|
+
}
|
|
33
|
+
return fs.realpathSync(root);
|
|
34
|
+
}
|
|
35
|
+
function readTypeRootStat(root, type, name) {
|
|
36
|
+
try {
|
|
37
|
+
return fs.statSync(root);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (hasErrnoCode(error, "ENOENT")) {
|
|
41
|
+
throw new Error(`Stash type root not found for ref: ${type}:${name}`);
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentikitSearchType, SearchResponse, SearchSource, SearchUsageMode } from "./stash-types";
|
|
2
|
+
export declare function agentikitSearch(input: {
|
|
3
|
+
query: string;
|
|
4
|
+
type?: AgentikitSearchType;
|
|
5
|
+
limit?: number;
|
|
6
|
+
usage?: SearchUsageMode;
|
|
7
|
+
source?: SearchSource;
|
|
8
|
+
}): Promise<SearchResponse>;
|