agentikit 0.0.9 → 0.0.13
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 +139 -208
- package/dist/index.d.ts +8 -2
- package/dist/index.js +4 -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 +201 -75
- 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 +19 -6
- package/dist/src/config.js +139 -29
- 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 +0 -1
- package/dist/src/metadata.js +6 -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 +2 -2
- package/dist/src/registry-install.js +142 -35
- package/dist/src/registry-resolve.js +90 -22
- package/dist/src/registry-search.d.ts +22 -0
- package/dist/src/registry-search.js +231 -97
- package/dist/src/registry-types.d.ts +9 -2
- package/dist/src/stash-add.js +4 -4
- 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.js +12 -12
- package/dist/src/stash-resolve.js +3 -0
- package/dist/src/stash-search.js +168 -164
- package/dist/src/stash-show.d.ts +1 -1
- package/dist/src/stash-show.js +28 -96
- package/dist/src/stash-source.d.ts +24 -0
- package/dist/src/stash-source.js +81 -0
- package/dist/src/stash-types.d.ts +14 -4
- package/dist/src/stash.d.ts +6 -0
- package/dist/src/stash.js +3 -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 +213 -82
- package/src/common.ts +23 -5
- package/src/config-cli.ts +499 -0
- package/src/config.ts +160 -38
- 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 +5 -65
- package/src/origin-resolve.ts +67 -0
- package/src/registry-install.ts +158 -42
- package/src/registry-resolve.ts +92 -23
- package/src/registry-search.ts +288 -98
- package/src/registry-types.ts +10 -2
- package/src/stash-add.ts +14 -17
- package/src/stash-clone.ts +127 -0
- package/src/stash-ref.ts +84 -26
- package/src/stash-registry.ts +12 -12
- package/src/stash-resolve.ts +3 -0
- package/src/stash-search.ts +202 -184
- package/src/stash-show.ts +33 -90
- package/src/stash-source.ts +103 -0
- package/src/stash-types.ts +14 -4
- package/src/stash.ts +8 -0
- package/src/tool-runner.ts +18 -5
- package/dist/src/similarity.d.ts +0 -34
- package/dist/src/similarity.js +0 -211
- package/src/similarity.ts +0 -271
package/src/stash-ref.ts
CHANGED
|
@@ -1,41 +1,99 @@
|
|
|
1
1
|
import path from "node:path"
|
|
2
2
|
import { type AgentikitAssetType, isAssetType } from "./common"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// ── Types ───────────────────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
export interface AssetRef {
|
|
5
7
|
type: AgentikitAssetType
|
|
6
8
|
name: string
|
|
9
|
+
/**
|
|
10
|
+
* Where to find this asset.
|
|
11
|
+
* - undefined: search all sources (working → mounted → installed)
|
|
12
|
+
* - "local": working stash only
|
|
13
|
+
* - registry ref: e.g. "npm:@scope/pkg", "owner/repo", "github:owner/repo#v1"
|
|
14
|
+
* - filesystem path: e.g. "/mnt/shared-stash"
|
|
15
|
+
*/
|
|
16
|
+
origin?: string
|
|
7
17
|
}
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
// ── Construction ────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Build a ref string from components.
|
|
23
|
+
*
|
|
24
|
+
* Examples:
|
|
25
|
+
* makeAssetRef("tool", "deploy.sh")
|
|
26
|
+
* → "tool:deploy.sh"
|
|
27
|
+
* makeAssetRef("tool", "deploy.sh", "npm:@scope/pkg")
|
|
28
|
+
* → "npm:@scope/pkg//tool:deploy.sh"
|
|
29
|
+
* makeAssetRef("skill", "code-review", "local")
|
|
30
|
+
* → "local//skill:code-review"
|
|
31
|
+
* makeAssetRef("tool", "db/migrate/run.sh", "owner/repo")
|
|
32
|
+
* → "owner/repo//tool:db/migrate/run.sh"
|
|
33
|
+
*/
|
|
34
|
+
export function makeAssetRef(
|
|
35
|
+
type: AgentikitAssetType,
|
|
36
|
+
name: string,
|
|
37
|
+
origin?: string,
|
|
38
|
+
): string {
|
|
39
|
+
validateName(name)
|
|
40
|
+
const normalized = normalizeName(name)
|
|
41
|
+
const asset = `${type}:${normalized}`
|
|
42
|
+
if (!origin) return asset
|
|
43
|
+
return `${origin}//${asset}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── Parsing ─────────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse a ref string in the format `[origin//]type:name`.
|
|
50
|
+
*/
|
|
51
|
+
export function parseAssetRef(ref: string): AssetRef {
|
|
52
|
+
const trimmed = ref.trim()
|
|
53
|
+
if (!trimmed) throw new Error("Empty ref.")
|
|
54
|
+
|
|
55
|
+
let origin: string | undefined
|
|
56
|
+
let body = trimmed
|
|
57
|
+
|
|
58
|
+
const boundary = trimmed.indexOf("//")
|
|
59
|
+
if (boundary >= 0) {
|
|
60
|
+
origin = trimmed.slice(0, boundary)
|
|
61
|
+
body = trimmed.slice(boundary + 2)
|
|
62
|
+
if (!origin) throw new Error("Empty origin in ref.")
|
|
13
63
|
}
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
throw new Error(`Invalid
|
|
64
|
+
|
|
65
|
+
const colon = body.indexOf(":")
|
|
66
|
+
if (colon <= 0) {
|
|
67
|
+
throw new Error(`Invalid ref "${trimmed}". Expected [origin//]type:name`)
|
|
18
68
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
69
|
+
|
|
70
|
+
const rawType = body.slice(0, colon)
|
|
71
|
+
const rawName = body.slice(colon + 1)
|
|
72
|
+
|
|
73
|
+
if (!isAssetType(rawType)) {
|
|
74
|
+
throw new Error(`Invalid asset type: "${rawType}".`)
|
|
24
75
|
}
|
|
76
|
+
|
|
77
|
+
validateName(rawName)
|
|
78
|
+
const name = normalizeName(rawName)
|
|
79
|
+
|
|
80
|
+
return { type: rawType, name, origin: origin || undefined }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── Validation ──────────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
function validateName(name: string): void {
|
|
86
|
+
if (!name) throw new Error("Empty asset name.")
|
|
87
|
+
if (name.includes("\0")) throw new Error("Null byte in asset name.")
|
|
88
|
+
if (/^[A-Za-z]:/.test(name)) throw new Error("Windows drive path in asset name.")
|
|
89
|
+
|
|
25
90
|
const normalized = path.posix.normalize(name.replace(/\\/g, "/"))
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|| /^[A-Za-z]:/.test(name)
|
|
30
|
-
|| path.posix.isAbsolute(normalized)
|
|
31
|
-
|| normalized === ".."
|
|
32
|
-
|| normalized.startsWith("../")
|
|
33
|
-
) {
|
|
34
|
-
throw new Error("Invalid open ref name.")
|
|
91
|
+
if (path.posix.isAbsolute(normalized)) throw new Error("Absolute path in asset name.")
|
|
92
|
+
if (normalized === ".." || normalized.startsWith("../")) {
|
|
93
|
+
throw new Error("Path traversal in asset name.")
|
|
35
94
|
}
|
|
36
|
-
return { type: rawType, name: normalized }
|
|
37
95
|
}
|
|
38
96
|
|
|
39
|
-
|
|
40
|
-
return
|
|
97
|
+
function normalizeName(name: string): string {
|
|
98
|
+
return path.posix.normalize(name.replace(/\\/g, "/"))
|
|
41
99
|
}
|
package/src/stash-registry.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
|
|
20
20
|
export async function agentikitList(input?: { stashDir?: string }): Promise<ListResponse> {
|
|
21
21
|
const stashDir = input?.stashDir ?? resolveStashDir()
|
|
22
|
-
const config = loadConfig(
|
|
22
|
+
const config = loadConfig()
|
|
23
23
|
const installed = config.registry?.installed ?? []
|
|
24
24
|
|
|
25
25
|
return {
|
|
@@ -40,11 +40,11 @@ export async function agentikitRemove(input: { target: string; stashDir?: string
|
|
|
40
40
|
if (!target) throw new Error("Target is required.")
|
|
41
41
|
|
|
42
42
|
const stashDir = input.stashDir ?? resolveStashDir()
|
|
43
|
-
const config = loadConfig(
|
|
43
|
+
const config = loadConfig()
|
|
44
44
|
const installed = config.registry?.installed ?? []
|
|
45
45
|
const entry = resolveInstalledTarget(installed, target)
|
|
46
46
|
|
|
47
|
-
const updatedConfig = removeInstalledRegistryEntry(entry.id
|
|
47
|
+
const updatedConfig = removeInstalledRegistryEntry(entry.id)
|
|
48
48
|
cleanupDirectoryBestEffort(entry.cacheDir)
|
|
49
49
|
const index = await agentikitIndex({ stashDir })
|
|
50
50
|
|
|
@@ -59,7 +59,7 @@ export async function agentikitRemove(input: { target: string; stashDir?: string
|
|
|
59
59
|
stashRoot: entry.stashRoot,
|
|
60
60
|
},
|
|
61
61
|
config: {
|
|
62
|
-
|
|
62
|
+
mountedStashDirs: updatedConfig.mountedStashDirs,
|
|
63
63
|
installedRegistryCount: updatedConfig.registry?.installed.length ?? 0,
|
|
64
64
|
},
|
|
65
65
|
index: {
|
|
@@ -79,13 +79,13 @@ export async function agentikitReinstall(input?: {
|
|
|
79
79
|
const stashDir = input?.stashDir ?? resolveStashDir()
|
|
80
80
|
const target = input?.target?.trim()
|
|
81
81
|
const all = input?.all === true
|
|
82
|
-
const installedEntries = loadConfig(
|
|
82
|
+
const installedEntries = loadConfig().registry?.installed ?? []
|
|
83
83
|
const selectedEntries = selectTargets(installedEntries, target, all)
|
|
84
84
|
|
|
85
85
|
const processed: ReinstallResponse["processed"] = []
|
|
86
86
|
for (const entry of selectedEntries) {
|
|
87
87
|
const installed = await installRegistryRef(entry.ref)
|
|
88
|
-
upsertInstalledRegistryEntry(toInstalledEntry(installed)
|
|
88
|
+
upsertInstalledRegistryEntry(toInstalledEntry(installed))
|
|
89
89
|
if (entry.cacheDir !== installed.cacheDir) {
|
|
90
90
|
cleanupDirectoryBestEffort(entry.cacheDir)
|
|
91
91
|
}
|
|
@@ -100,7 +100,7 @@ export async function agentikitReinstall(input?: {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const index = await agentikitIndex({ stashDir })
|
|
103
|
-
const config = loadConfig(
|
|
103
|
+
const config = loadConfig()
|
|
104
104
|
|
|
105
105
|
return {
|
|
106
106
|
stashDir,
|
|
@@ -108,7 +108,7 @@ export async function agentikitReinstall(input?: {
|
|
|
108
108
|
all,
|
|
109
109
|
processed,
|
|
110
110
|
config: {
|
|
111
|
-
|
|
111
|
+
mountedStashDirs: config.mountedStashDirs,
|
|
112
112
|
installedRegistryCount: config.registry?.installed.length ?? 0,
|
|
113
113
|
},
|
|
114
114
|
index: {
|
|
@@ -128,13 +128,13 @@ export async function agentikitUpdate(input?: {
|
|
|
128
128
|
const stashDir = input?.stashDir ?? resolveStashDir()
|
|
129
129
|
const target = input?.target?.trim()
|
|
130
130
|
const all = input?.all === true
|
|
131
|
-
const installedEntries = loadConfig(
|
|
131
|
+
const installedEntries = loadConfig().registry?.installed ?? []
|
|
132
132
|
const selectedEntries = selectTargets(installedEntries, target, all)
|
|
133
133
|
|
|
134
134
|
const processed: UpdateResponse["processed"] = []
|
|
135
135
|
for (const entry of selectedEntries) {
|
|
136
136
|
const installed = await installRegistryRef(entry.ref)
|
|
137
|
-
upsertInstalledRegistryEntry(toInstalledEntry(installed)
|
|
137
|
+
upsertInstalledRegistryEntry(toInstalledEntry(installed))
|
|
138
138
|
if (entry.cacheDir !== installed.cacheDir) {
|
|
139
139
|
cleanupDirectoryBestEffort(entry.cacheDir)
|
|
140
140
|
}
|
|
@@ -161,7 +161,7 @@ export async function agentikitUpdate(input?: {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
const index = await agentikitIndex({ stashDir })
|
|
164
|
-
const config = loadConfig(
|
|
164
|
+
const config = loadConfig()
|
|
165
165
|
|
|
166
166
|
return {
|
|
167
167
|
stashDir,
|
|
@@ -169,7 +169,7 @@ export async function agentikitUpdate(input?: {
|
|
|
169
169
|
all,
|
|
170
170
|
processed,
|
|
171
171
|
config: {
|
|
172
|
-
|
|
172
|
+
mountedStashDirs: config.mountedStashDirs,
|
|
173
173
|
installedRegistryCount: config.registry?.installed.length ?? 0,
|
|
174
174
|
},
|
|
175
175
|
index: {
|
package/src/stash-resolve.ts
CHANGED
|
@@ -22,6 +22,9 @@ export function resolveAssetPath(stashDir: string, type: AgentikitAssetType, nam
|
|
|
22
22
|
if (type === "tool") {
|
|
23
23
|
throw new Error("Tool ref must resolve to a .sh, .ts, .js, .ps1, .cmd, or .bat file.")
|
|
24
24
|
}
|
|
25
|
+
if (type === "script") {
|
|
26
|
+
throw new Error("Script ref must resolve to a file with a supported script extension. Refer to the Agentikit documentation for the complete list of supported script extensions.");
|
|
27
|
+
}
|
|
25
28
|
throw new Error(`Stash asset not found for ref: ${type}:${name}`)
|
|
26
29
|
}
|
|
27
30
|
return realTarget
|