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.
Files changed (108) hide show
  1. package/README.md +139 -208
  2. package/dist/index.d.ts +8 -2
  3. package/dist/index.js +4 -1
  4. package/dist/src/asset-spec.d.ts +2 -0
  5. package/dist/src/asset-spec.js +22 -3
  6. package/dist/src/asset-type-handler.d.ts +27 -0
  7. package/dist/src/asset-type-handler.js +33 -0
  8. package/dist/src/cli.js +201 -75
  9. package/dist/src/common.d.ts +6 -1
  10. package/dist/src/common.js +18 -4
  11. package/dist/src/config-cli.d.ts +9 -0
  12. package/dist/src/config-cli.js +473 -0
  13. package/dist/src/config.d.ts +19 -6
  14. package/dist/src/config.js +139 -29
  15. package/dist/src/db.d.ts +46 -0
  16. package/dist/src/db.js +299 -0
  17. package/dist/src/embedder.js +12 -7
  18. package/dist/src/github.d.ts +4 -0
  19. package/dist/src/github.js +19 -0
  20. package/dist/src/handlers/agent-handler.d.ts +2 -0
  21. package/dist/src/handlers/agent-handler.js +26 -0
  22. package/dist/src/handlers/command-handler.d.ts +2 -0
  23. package/dist/src/handlers/command-handler.js +23 -0
  24. package/dist/src/handlers/index.d.ts +6 -0
  25. package/dist/src/handlers/index.js +23 -0
  26. package/dist/src/handlers/knowledge-handler.d.ts +2 -0
  27. package/dist/src/handlers/knowledge-handler.js +56 -0
  28. package/dist/src/handlers/markdown-helpers.d.ts +7 -0
  29. package/dist/src/handlers/markdown-helpers.js +15 -0
  30. package/dist/src/handlers/script-handler.d.ts +2 -0
  31. package/dist/src/handlers/script-handler.js +78 -0
  32. package/dist/src/handlers/skill-handler.d.ts +2 -0
  33. package/dist/src/handlers/skill-handler.js +30 -0
  34. package/dist/src/handlers/tool-handler.d.ts +2 -0
  35. package/dist/src/handlers/tool-handler.js +58 -0
  36. package/dist/src/indexer.d.ts +1 -23
  37. package/dist/src/indexer.js +162 -155
  38. package/dist/src/init.d.ts +2 -2
  39. package/dist/src/init.js +21 -9
  40. package/dist/src/llm.js +4 -3
  41. package/dist/src/metadata.d.ts +0 -1
  42. package/dist/src/metadata.js +6 -64
  43. package/dist/src/origin-resolve.d.ts +19 -0
  44. package/dist/src/origin-resolve.js +53 -0
  45. package/dist/src/registry-install.d.ts +2 -2
  46. package/dist/src/registry-install.js +142 -35
  47. package/dist/src/registry-resolve.js +90 -22
  48. package/dist/src/registry-search.d.ts +22 -0
  49. package/dist/src/registry-search.js +231 -97
  50. package/dist/src/registry-types.d.ts +9 -2
  51. package/dist/src/stash-add.js +4 -4
  52. package/dist/src/stash-clone.d.ts +22 -0
  53. package/dist/src/stash-clone.js +83 -0
  54. package/dist/src/stash-ref.d.ts +27 -3
  55. package/dist/src/stash-ref.js +63 -24
  56. package/dist/src/stash-registry.js +12 -12
  57. package/dist/src/stash-resolve.js +3 -0
  58. package/dist/src/stash-search.js +168 -164
  59. package/dist/src/stash-show.d.ts +1 -1
  60. package/dist/src/stash-show.js +28 -96
  61. package/dist/src/stash-source.d.ts +24 -0
  62. package/dist/src/stash-source.js +81 -0
  63. package/dist/src/stash-types.d.ts +14 -4
  64. package/dist/src/stash.d.ts +6 -0
  65. package/dist/src/stash.js +3 -0
  66. package/dist/src/tool-runner.d.ts +1 -1
  67. package/dist/src/tool-runner.js +18 -5
  68. package/package.json +7 -2
  69. package/src/asset-spec.ts +20 -4
  70. package/src/asset-type-handler.ts +77 -0
  71. package/src/cli.ts +213 -82
  72. package/src/common.ts +23 -5
  73. package/src/config-cli.ts +499 -0
  74. package/src/config.ts +160 -38
  75. package/src/db.ts +411 -0
  76. package/src/embedder.ts +22 -11
  77. package/src/github.ts +21 -0
  78. package/src/handlers/agent-handler.ts +32 -0
  79. package/src/handlers/command-handler.ts +29 -0
  80. package/src/handlers/index.ts +25 -0
  81. package/src/handlers/knowledge-handler.ts +62 -0
  82. package/src/handlers/markdown-helpers.ts +19 -0
  83. package/src/handlers/script-handler.ts +92 -0
  84. package/src/handlers/skill-handler.ts +37 -0
  85. package/src/handlers/tool-handler.ts +71 -0
  86. package/src/indexer.ts +208 -187
  87. package/src/init.ts +17 -9
  88. package/src/llm.ts +4 -3
  89. package/src/metadata.ts +5 -65
  90. package/src/origin-resolve.ts +67 -0
  91. package/src/registry-install.ts +158 -42
  92. package/src/registry-resolve.ts +92 -23
  93. package/src/registry-search.ts +288 -98
  94. package/src/registry-types.ts +10 -2
  95. package/src/stash-add.ts +14 -17
  96. package/src/stash-clone.ts +127 -0
  97. package/src/stash-ref.ts +84 -26
  98. package/src/stash-registry.ts +12 -12
  99. package/src/stash-resolve.ts +3 -0
  100. package/src/stash-search.ts +202 -184
  101. package/src/stash-show.ts +33 -90
  102. package/src/stash-source.ts +103 -0
  103. package/src/stash-types.ts +14 -4
  104. package/src/stash.ts +8 -0
  105. package/src/tool-runner.ts +18 -5
  106. package/dist/src/similarity.d.ts +0 -34
  107. package/dist/src/similarity.js +0 -211
  108. 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
- export interface OpenRef {
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
- export function parseOpenRef(ref: string): OpenRef {
10
- const separator = ref.indexOf(":")
11
- if (separator <= 0) {
12
- throw new Error("Invalid open ref. Expected format '<type>:<name>'.")
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
- const rawType = ref.slice(0, separator)
15
- const rawName = ref.slice(separator + 1)
16
- if (!isAssetType(rawType)) {
17
- throw new Error(`Invalid open ref type: "${rawType}".`)
64
+
65
+ const colon = body.indexOf(":")
66
+ if (colon <= 0) {
67
+ throw new Error(`Invalid ref "${trimmed}". Expected [origin//]type:name`)
18
68
  }
19
- let name: string
20
- try {
21
- name = decodeURIComponent(rawName)
22
- } catch {
23
- throw new Error("Invalid open ref encoding.")
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
- !name
28
- || name.includes("\0")
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
- export function makeOpenRef(type: AgentikitAssetType, name: string): string {
40
- return `${type}:${encodeURIComponent(name)}`
97
+ function normalizeName(name: string): string {
98
+ return path.posix.normalize(name.replace(/\\/g, "/"))
41
99
  }
@@ -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(stashDir)
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(stashDir)
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, stashDir)
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
- additionalStashDirs: updatedConfig.additionalStashDirs,
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(stashDir).registry?.installed ?? []
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), stashDir)
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(stashDir)
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
- additionalStashDirs: config.additionalStashDirs,
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(stashDir).registry?.installed ?? []
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), stashDir)
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(stashDir)
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
- additionalStashDirs: config.additionalStashDirs,
172
+ mountedStashDirs: config.mountedStashDirs,
173
173
  installedRegistryCount: config.registry?.installed.length ?? 0,
174
174
  },
175
175
  index: {
@@ -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