@dexto/agent-management 1.6.13 → 1.6.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.
- package/dist/config/config-enrichment.cjs +24 -7
- package/dist/config/config-enrichment.d.ts +5 -0
- package/dist/config/config-enrichment.d.ts.map +1 -1
- package/dist/config/config-enrichment.js +24 -7
- package/dist/config/discover-prompts.cjs +7 -7
- package/dist/config/discover-prompts.d.ts +5 -3
- package/dist/config/discover-prompts.d.ts.map +1 -1
- package/dist/config/discover-prompts.js +7 -7
- package/dist/config/error-codes.cjs +1 -0
- package/dist/config/error-codes.d.ts +1 -0
- package/dist/config/error-codes.d.ts.map +1 -1
- package/dist/config/error-codes.js +1 -0
- package/dist/config/errors.cjs +12 -2
- package/dist/config/errors.d.ts +5 -0
- package/dist/config/errors.d.ts.map +1 -1
- package/dist/config/errors.js +12 -2
- package/dist/index.cjs +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -0
- package/dist/plugins/discover-skills.cjs +2 -0
- package/dist/plugins/discover-skills.d.ts +7 -5
- package/dist/plugins/discover-skills.d.ts.map +1 -1
- package/dist/plugins/discover-skills.js +2 -0
- package/dist/project-registry.cjs +380 -0
- package/dist/project-registry.d.ts +153 -0
- package/dist/project-registry.d.ts.map +1 -0
- package/dist/project-registry.js +329 -0
- package/dist/resolver.cjs +23 -2
- package/dist/resolver.d.ts.map +1 -1
- package/dist/resolver.js +26 -2
- package/dist/tool-factories/agent-spawner/factory.cjs +12 -0
- package/dist/tool-factories/agent-spawner/factory.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/factory.js +12 -0
- package/dist/tool-factories/agent-spawner/runtime.cjs +189 -27
- package/dist/tool-factories/agent-spawner/runtime.d.ts +7 -1
- package/dist/tool-factories/agent-spawner/runtime.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/runtime.js +189 -27
- package/dist/tool-factories/agent-spawner/schemas.cjs +6 -3
- package/dist/tool-factories/agent-spawner/schemas.d.ts +3 -2
- package/dist/tool-factories/agent-spawner/schemas.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/schemas.js +6 -3
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.cjs +4 -3
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.d.ts.map +1 -1
- package/dist/tool-factories/agent-spawner/spawn-agent-tool.js +4 -3
- package/dist/utils/execution-context.cjs +61 -16
- package/dist/utils/execution-context.d.ts.map +1 -1
- package/dist/utils/execution-context.js +62 -17
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -25,6 +25,26 @@ import {
|
|
|
25
25
|
writePreferencesToAgent
|
|
26
26
|
} from "./writer.js";
|
|
27
27
|
import { AgentManager } from "./AgentManager.js";
|
|
28
|
+
import {
|
|
29
|
+
ProjectRegistryEntrySchema,
|
|
30
|
+
ProjectRegistrySchema,
|
|
31
|
+
getProjectRegistryPath,
|
|
32
|
+
getProjectRegistryCandidatePaths,
|
|
33
|
+
findProjectRegistryPath,
|
|
34
|
+
findProjectRegistryPathSync,
|
|
35
|
+
readProjectRegistry,
|
|
36
|
+
readProjectRegistrySync,
|
|
37
|
+
loadProjectRegistry,
|
|
38
|
+
loadProjectRegistrySync,
|
|
39
|
+
getDefaultProjectRegistryEntry,
|
|
40
|
+
resolveProjectRegistryEntryConfigPath,
|
|
41
|
+
resolveProjectRegistryEntryConfigPathSync,
|
|
42
|
+
resolveProjectRegistryEntry,
|
|
43
|
+
resolveProjectRegistryAgentPath,
|
|
44
|
+
resolveDefaultProjectRegistryAgentPath,
|
|
45
|
+
ProjectRegistryError,
|
|
46
|
+
isProjectRegistryError
|
|
47
|
+
} from "./project-registry.js";
|
|
28
48
|
import {
|
|
29
49
|
installBundledAgent,
|
|
30
50
|
installCustomAgent,
|
|
@@ -203,6 +223,9 @@ export {
|
|
|
203
223
|
PluginManifestSchema,
|
|
204
224
|
PreferenceError,
|
|
205
225
|
PreferenceErrorCode,
|
|
226
|
+
ProjectRegistryEntrySchema,
|
|
227
|
+
ProjectRegistryError,
|
|
228
|
+
ProjectRegistrySchema,
|
|
206
229
|
RegistryError,
|
|
207
230
|
RegistryErrorCode,
|
|
208
231
|
SHARED_API_KEY_PROVIDERS,
|
|
@@ -229,6 +252,8 @@ export {
|
|
|
229
252
|
findDextoProjectRoot,
|
|
230
253
|
findDextoSourceRoot,
|
|
231
254
|
findPackageRoot,
|
|
255
|
+
findProjectRegistryPath,
|
|
256
|
+
findProjectRegistryPathSync,
|
|
232
257
|
formatSize,
|
|
233
258
|
getActiveModel,
|
|
234
259
|
getActiveModelId,
|
|
@@ -238,6 +263,7 @@ export {
|
|
|
238
263
|
getCustomModel,
|
|
239
264
|
getCustomModelsPath,
|
|
240
265
|
getDefaultImageStoreDir,
|
|
266
|
+
getDefaultProjectRegistryEntry,
|
|
241
267
|
getDextoApiKeyFromAuth,
|
|
242
268
|
getDextoEnvPath,
|
|
243
269
|
getDextoGlobalPath,
|
|
@@ -262,6 +288,8 @@ export {
|
|
|
262
288
|
getModelsDiskUsage,
|
|
263
289
|
getPluginSearchPaths,
|
|
264
290
|
getPrimaryApiKeyEnvVar,
|
|
291
|
+
getProjectRegistryCandidatePaths,
|
|
292
|
+
getProjectRegistryPath,
|
|
265
293
|
getProviderKeyStatus,
|
|
266
294
|
getTotalInstalledSize,
|
|
267
295
|
getUninstalledDefaults,
|
|
@@ -277,6 +305,7 @@ export {
|
|
|
277
305
|
isModelInstalled,
|
|
278
306
|
isPath,
|
|
279
307
|
isPluginInstalled,
|
|
308
|
+
isProjectRegistryError,
|
|
280
309
|
listAllMarketplacePlugins,
|
|
281
310
|
listInstalledAgents,
|
|
282
311
|
listInstalledPlugins,
|
|
@@ -293,9 +322,13 @@ export {
|
|
|
293
322
|
loadImageRegistry,
|
|
294
323
|
loadModelPickerState,
|
|
295
324
|
loadModelState,
|
|
325
|
+
loadProjectRegistry,
|
|
326
|
+
loadProjectRegistrySync,
|
|
296
327
|
modelFileExists,
|
|
297
328
|
parseImageSpecifier,
|
|
298
329
|
pruneModelPickerState,
|
|
330
|
+
readProjectRegistry,
|
|
331
|
+
readProjectRegistrySync,
|
|
299
332
|
recordRecentModel,
|
|
300
333
|
registerManualModel,
|
|
301
334
|
reloadAgentConfigFromFile,
|
|
@@ -308,9 +341,14 @@ export {
|
|
|
308
341
|
resolveAgentPath,
|
|
309
342
|
resolveApiKeyForProvider,
|
|
310
343
|
resolveBundledScript,
|
|
344
|
+
resolveDefaultProjectRegistryAgentPath,
|
|
311
345
|
resolveFileLikeImageSpecifierToFileUrl,
|
|
312
346
|
resolveFileLikeImageSpecifierToPath,
|
|
313
347
|
resolveImageEntryFileFromStore,
|
|
348
|
+
resolveProjectRegistryAgentPath,
|
|
349
|
+
resolveProjectRegistryEntry,
|
|
350
|
+
resolveProjectRegistryEntryConfigPath,
|
|
351
|
+
resolveProjectRegistryEntryConfigPathSync,
|
|
314
352
|
saveAgentPreferences,
|
|
315
353
|
saveCustomModel,
|
|
316
354
|
saveDextoInstalledPlugins,
|
|
@@ -68,6 +68,7 @@ function discoverStandaloneSkills(projectPath) {
|
|
|
68
68
|
} catch {
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
+
scanSkillsDir(path.join(cwd, "skills"), "project");
|
|
71
72
|
scanSkillsDir(path.join(cwd, ".agents", "skills"), "project");
|
|
72
73
|
scanSkillsDir(path.join(cwd, ".dexto", "skills"), "project");
|
|
73
74
|
if (homeDir) {
|
|
@@ -80,6 +81,7 @@ function getSkillSearchPaths() {
|
|
|
80
81
|
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
|
|
81
82
|
const cwd = process.cwd();
|
|
82
83
|
return [
|
|
84
|
+
path.join(cwd, "skills"),
|
|
83
85
|
path.join(cwd, ".agents", "skills"),
|
|
84
86
|
path.join(cwd, ".dexto", "skills"),
|
|
85
87
|
homeDir ? path.join(homeDir, ".agents", "skills") : "",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Standalone Skill Discovery
|
|
3
3
|
*
|
|
4
|
-
* Discovers standalone skills from
|
|
4
|
+
* Discovers standalone skills from project-local and user-local skill directories.
|
|
5
5
|
* These are different from plugin skills - they're just directories containing a SKILL.md file.
|
|
6
6
|
*
|
|
7
7
|
* Structure:
|
|
8
|
+
* skills/
|
|
8
9
|
* ~/.agents/skills/
|
|
9
10
|
* ~/.dexto/skills/
|
|
10
11
|
* └── skill-name/
|
|
@@ -30,10 +31,11 @@ export interface DiscoveredSkill {
|
|
|
30
31
|
* Discovers standalone skills from standard locations.
|
|
31
32
|
*
|
|
32
33
|
* Search Locations:
|
|
33
|
-
* 1. <
|
|
34
|
-
* 2. <
|
|
35
|
-
* 3.
|
|
36
|
-
* 4. ~/.
|
|
34
|
+
* 1. <projectRoot>/skills/* (project)
|
|
35
|
+
* 2. <projectRoot>/.agents/skills/* (project)
|
|
36
|
+
* 3. <projectRoot>/.dexto/skills/* (project)
|
|
37
|
+
* 4. ~/.agents/skills/* (user)
|
|
38
|
+
* 5. ~/.dexto/skills/* (user)
|
|
37
39
|
*
|
|
38
40
|
* @param projectPath Optional project path (defaults to cwd)
|
|
39
41
|
* @returns Array of discovered skills
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-skills.d.ts","sourceRoot":"","sources":["../../src/plugins/discover-skills.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"discover-skills.d.ts","sourceRoot":"","sources":["../../src/plugins/discover-skills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAkEhF;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAW9C"}
|
|
@@ -34,6 +34,7 @@ function discoverStandaloneSkills(projectPath) {
|
|
|
34
34
|
} catch {
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
scanSkillsDir(path.join(cwd, "skills"), "project");
|
|
37
38
|
scanSkillsDir(path.join(cwd, ".agents", "skills"), "project");
|
|
38
39
|
scanSkillsDir(path.join(cwd, ".dexto", "skills"), "project");
|
|
39
40
|
if (homeDir) {
|
|
@@ -46,6 +47,7 @@ function getSkillSearchPaths() {
|
|
|
46
47
|
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
|
|
47
48
|
const cwd = process.cwd();
|
|
48
49
|
return [
|
|
50
|
+
path.join(cwd, "skills"),
|
|
49
51
|
path.join(cwd, ".agents", "skills"),
|
|
50
52
|
path.join(cwd, ".dexto", "skills"),
|
|
51
53
|
homeDir ? path.join(homeDir, ".agents", "skills") : "",
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var project_registry_exports = {};
|
|
30
|
+
__export(project_registry_exports, {
|
|
31
|
+
ProjectRegistryEntrySchema: () => ProjectRegistryEntrySchema,
|
|
32
|
+
ProjectRegistryError: () => ProjectRegistryError,
|
|
33
|
+
ProjectRegistrySchema: () => ProjectRegistrySchema,
|
|
34
|
+
findProjectRegistryPath: () => findProjectRegistryPath,
|
|
35
|
+
findProjectRegistryPathSync: () => findProjectRegistryPathSync,
|
|
36
|
+
getDefaultProjectRegistryEntry: () => getDefaultProjectRegistryEntry,
|
|
37
|
+
getProjectRegistryCandidatePaths: () => getProjectRegistryCandidatePaths,
|
|
38
|
+
getProjectRegistryPath: () => getProjectRegistryPath,
|
|
39
|
+
isProjectRegistryError: () => isProjectRegistryError,
|
|
40
|
+
loadProjectRegistry: () => loadProjectRegistry,
|
|
41
|
+
loadProjectRegistrySync: () => loadProjectRegistrySync,
|
|
42
|
+
readProjectRegistry: () => readProjectRegistry,
|
|
43
|
+
readProjectRegistrySync: () => readProjectRegistrySync,
|
|
44
|
+
resolveDefaultProjectRegistryAgentPath: () => resolveDefaultProjectRegistryAgentPath,
|
|
45
|
+
resolveProjectRegistryAgentPath: () => resolveProjectRegistryAgentPath,
|
|
46
|
+
resolveProjectRegistryEntry: () => resolveProjectRegistryEntry,
|
|
47
|
+
resolveProjectRegistryEntryConfigPath: () => resolveProjectRegistryEntryConfigPath,
|
|
48
|
+
resolveProjectRegistryEntryConfigPathSync: () => resolveProjectRegistryEntryConfigPathSync
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(project_registry_exports);
|
|
51
|
+
var import_fs = require("fs");
|
|
52
|
+
var import_fs2 = require("fs");
|
|
53
|
+
var import_path = __toESM(require("path"), 1);
|
|
54
|
+
var import_zod = require("zod");
|
|
55
|
+
const NonEmptyStringSchema = import_zod.z.string().trim().min(1);
|
|
56
|
+
const ProjectRegistryEntrySchema = import_zod.z.object({
|
|
57
|
+
id: NonEmptyStringSchema,
|
|
58
|
+
name: NonEmptyStringSchema,
|
|
59
|
+
description: NonEmptyStringSchema,
|
|
60
|
+
configPath: NonEmptyStringSchema,
|
|
61
|
+
author: NonEmptyStringSchema.optional(),
|
|
62
|
+
tags: import_zod.z.array(NonEmptyStringSchema).optional(),
|
|
63
|
+
parentAgentId: NonEmptyStringSchema.optional()
|
|
64
|
+
}).strict();
|
|
65
|
+
const ProjectRegistrySchema = import_zod.z.object({
|
|
66
|
+
primaryAgent: NonEmptyStringSchema.optional(),
|
|
67
|
+
allowGlobalAgents: import_zod.z.boolean().default(false),
|
|
68
|
+
agents: import_zod.z.array(ProjectRegistryEntrySchema)
|
|
69
|
+
}).strict().superRefine((registry, ctx) => {
|
|
70
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const [index, agent] of registry.agents.entries()) {
|
|
72
|
+
if (seenIds.has(agent.id)) {
|
|
73
|
+
ctx.addIssue({
|
|
74
|
+
code: import_zod.z.ZodIssueCode.custom,
|
|
75
|
+
path: ["agents", index, "id"],
|
|
76
|
+
message: `Duplicate agent id '${agent.id}'.`
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
seenIds.add(agent.id);
|
|
81
|
+
}
|
|
82
|
+
if (registry.primaryAgent && !registry.agents.some((agent) => agent.id === registry.primaryAgent)) {
|
|
83
|
+
ctx.addIssue({
|
|
84
|
+
code: import_zod.z.ZodIssueCode.custom,
|
|
85
|
+
path: ["primaryAgent"],
|
|
86
|
+
message: `Primary agent '${registry.primaryAgent}' must match an agent id in 'agents'.`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
class ProjectRegistryError extends Error {
|
|
91
|
+
code;
|
|
92
|
+
registryPath;
|
|
93
|
+
agentId;
|
|
94
|
+
configPath;
|
|
95
|
+
constructor(options) {
|
|
96
|
+
super(options.message, options.cause ? { cause: options.cause } : void 0);
|
|
97
|
+
this.name = "ProjectRegistryError";
|
|
98
|
+
this.code = options.code;
|
|
99
|
+
this.registryPath = options.registryPath;
|
|
100
|
+
this.agentId = options.agentId;
|
|
101
|
+
this.configPath = options.configPath;
|
|
102
|
+
}
|
|
103
|
+
static invalidRegistry(registryPath, message, cause) {
|
|
104
|
+
return new ProjectRegistryError({
|
|
105
|
+
code: "PROJECT_REGISTRY_INVALID",
|
|
106
|
+
message,
|
|
107
|
+
registryPath,
|
|
108
|
+
cause
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
static invalidPrimaryAgent(registryPath, primaryAgent) {
|
|
112
|
+
return new ProjectRegistryError({
|
|
113
|
+
code: "PROJECT_REGISTRY_INVALID_PRIMARY",
|
|
114
|
+
message: `Primary agent '${primaryAgent}' not found in ${registryPath}.`,
|
|
115
|
+
registryPath,
|
|
116
|
+
agentId: primaryAgent
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static invalidConfigPath(options) {
|
|
120
|
+
return new ProjectRegistryError({
|
|
121
|
+
code: "PROJECT_REGISTRY_INVALID_CONFIG_PATH",
|
|
122
|
+
message: `Agent '${options.agentId}' in ${options.registryPath} has invalid configPath '${options.configPath}': ${options.reason}.`,
|
|
123
|
+
registryPath: options.registryPath,
|
|
124
|
+
agentId: options.agentId,
|
|
125
|
+
configPath: options.configPath
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function isProjectRegistryError(error) {
|
|
130
|
+
return error instanceof ProjectRegistryError;
|
|
131
|
+
}
|
|
132
|
+
const PROJECT_REGISTRY_RELATIVE_PATHS = [
|
|
133
|
+
import_path.default.join("agents", "registry.json"),
|
|
134
|
+
import_path.default.join("agents", "agent-registry.json")
|
|
135
|
+
];
|
|
136
|
+
function getProjectRegistryPath(projectRoot) {
|
|
137
|
+
return import_path.default.join(projectRoot, "agents", "registry.json");
|
|
138
|
+
}
|
|
139
|
+
function getProjectRegistryCandidatePaths(projectRoot) {
|
|
140
|
+
return PROJECT_REGISTRY_RELATIVE_PATHS.map(
|
|
141
|
+
(relativePath) => import_path.default.join(projectRoot, relativePath)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
async function findProjectRegistryPath(projectRoot) {
|
|
145
|
+
for (const registryPath of getProjectRegistryCandidatePaths(projectRoot)) {
|
|
146
|
+
try {
|
|
147
|
+
if ((await import_fs2.promises.stat(registryPath)).isFile()) {
|
|
148
|
+
return registryPath;
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
function findProjectRegistryPathSync(projectRoot) {
|
|
160
|
+
for (const registryPath of getProjectRegistryCandidatePaths(projectRoot)) {
|
|
161
|
+
try {
|
|
162
|
+
if ((0, import_fs.existsSync)(registryPath) && (0, import_fs.statSync)(registryPath).isFile()) {
|
|
163
|
+
return registryPath;
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.code === "EISDIR" || error.code === "ENOTDIR") {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function parseProjectRegistryContent(content, registryPath) {
|
|
175
|
+
let parsed;
|
|
176
|
+
try {
|
|
177
|
+
parsed = JSON.parse(content);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error instanceof SyntaxError) {
|
|
180
|
+
throw ProjectRegistryError.invalidRegistry(
|
|
181
|
+
registryPath,
|
|
182
|
+
`Invalid workspace registry at ${registryPath}: ${error.message}`,
|
|
183
|
+
error
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
return ProjectRegistrySchema.parse(parsed);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (error instanceof import_zod.z.ZodError) {
|
|
192
|
+
const rawPrimaryAgent = parsed && typeof parsed === "object" && typeof parsed.primaryAgent === "string" ? parsed.primaryAgent : void 0;
|
|
193
|
+
const hasPrimaryAgentIssue = error.issues.some(
|
|
194
|
+
(issue) => issue.path[0] === "primaryAgent"
|
|
195
|
+
);
|
|
196
|
+
if (hasPrimaryAgentIssue && rawPrimaryAgent) {
|
|
197
|
+
throw ProjectRegistryError.invalidPrimaryAgent(registryPath, rawPrimaryAgent);
|
|
198
|
+
}
|
|
199
|
+
throw ProjectRegistryError.invalidRegistry(
|
|
200
|
+
registryPath,
|
|
201
|
+
`Invalid workspace registry at ${registryPath}: ${error.message}`,
|
|
202
|
+
error
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function readProjectRegistry(registryPath) {
|
|
209
|
+
const content = await import_fs2.promises.readFile(registryPath, "utf-8");
|
|
210
|
+
return parseProjectRegistryContent(content, registryPath);
|
|
211
|
+
}
|
|
212
|
+
function readProjectRegistrySync(registryPath) {
|
|
213
|
+
return parseProjectRegistryContent((0, import_fs.readFileSync)(registryPath, "utf-8"), registryPath);
|
|
214
|
+
}
|
|
215
|
+
async function loadProjectRegistry(projectRoot) {
|
|
216
|
+
const registryPath = await findProjectRegistryPath(projectRoot);
|
|
217
|
+
if (!registryPath) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
registryPath,
|
|
222
|
+
registry: await readProjectRegistry(registryPath)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function loadProjectRegistrySync(projectRoot) {
|
|
226
|
+
const registryPath = findProjectRegistryPathSync(projectRoot);
|
|
227
|
+
if (!registryPath) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
registryPath,
|
|
232
|
+
registry: readProjectRegistrySync(registryPath)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function resolveProjectRegistryEntry(projectRoot, agentId) {
|
|
236
|
+
const loaded = await loadProjectRegistry(projectRoot);
|
|
237
|
+
if (!loaded) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
const entry = loaded.registry.agents.find((agent) => agent.id === agentId);
|
|
241
|
+
if (!entry) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
registryPath: loaded.registryPath,
|
|
246
|
+
entry
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function getDefaultProjectRegistryEntry(registry, registryPath) {
|
|
250
|
+
if (registry.primaryAgent) {
|
|
251
|
+
const primaryEntry = registry.agents.find((agent) => agent.id === registry.primaryAgent);
|
|
252
|
+
if (!primaryEntry) {
|
|
253
|
+
throw ProjectRegistryError.invalidPrimaryAgent(registryPath, registry.primaryAgent);
|
|
254
|
+
}
|
|
255
|
+
return primaryEntry;
|
|
256
|
+
}
|
|
257
|
+
if (registry.agents.length === 1) {
|
|
258
|
+
return registry.agents[0] ?? null;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
function assertProjectRegistryConfigPathSync(options) {
|
|
263
|
+
const absolutePath = import_path.default.resolve(import_path.default.dirname(options.registryPath), options.entry.configPath);
|
|
264
|
+
const relativeToProject = import_path.default.relative(options.projectRoot, absolutePath);
|
|
265
|
+
if (relativeToProject.startsWith("..") || import_path.default.isAbsolute(relativeToProject) || relativeToProject === "") {
|
|
266
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
267
|
+
registryPath: options.registryPath,
|
|
268
|
+
agentId: options.entry.id,
|
|
269
|
+
configPath: options.entry.configPath,
|
|
270
|
+
reason: "path must stay within the workspace root"
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
let stat;
|
|
274
|
+
try {
|
|
275
|
+
stat = (0, import_fs.statSync)(absolutePath);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error.code === "ENOENT") {
|
|
278
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
279
|
+
registryPath: options.registryPath,
|
|
280
|
+
agentId: options.entry.id,
|
|
281
|
+
configPath: options.entry.configPath,
|
|
282
|
+
reason: "file does not exist"
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
if (!stat.isFile()) {
|
|
288
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
289
|
+
registryPath: options.registryPath,
|
|
290
|
+
agentId: options.entry.id,
|
|
291
|
+
configPath: options.entry.configPath,
|
|
292
|
+
reason: "path must point to a file"
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return absolutePath;
|
|
296
|
+
}
|
|
297
|
+
async function assertProjectRegistryConfigPath(options) {
|
|
298
|
+
const absolutePath = import_path.default.resolve(import_path.default.dirname(options.registryPath), options.entry.configPath);
|
|
299
|
+
const relativeToProject = import_path.default.relative(options.projectRoot, absolutePath);
|
|
300
|
+
if (relativeToProject.startsWith("..") || import_path.default.isAbsolute(relativeToProject) || relativeToProject === "") {
|
|
301
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
302
|
+
registryPath: options.registryPath,
|
|
303
|
+
agentId: options.entry.id,
|
|
304
|
+
configPath: options.entry.configPath,
|
|
305
|
+
reason: "path must stay within the workspace root"
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
let stat;
|
|
309
|
+
try {
|
|
310
|
+
stat = await import_fs2.promises.stat(absolutePath);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (error.code === "ENOENT") {
|
|
313
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
314
|
+
registryPath: options.registryPath,
|
|
315
|
+
agentId: options.entry.id,
|
|
316
|
+
configPath: options.entry.configPath,
|
|
317
|
+
reason: "file does not exist"
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
if (!stat.isFile()) {
|
|
323
|
+
throw ProjectRegistryError.invalidConfigPath({
|
|
324
|
+
registryPath: options.registryPath,
|
|
325
|
+
agentId: options.entry.id,
|
|
326
|
+
configPath: options.entry.configPath,
|
|
327
|
+
reason: "path must point to a file"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return absolutePath;
|
|
331
|
+
}
|
|
332
|
+
async function resolveProjectRegistryEntryConfigPath(projectRoot, registryPath, entry) {
|
|
333
|
+
return await assertProjectRegistryConfigPath({ projectRoot, registryPath, entry });
|
|
334
|
+
}
|
|
335
|
+
function resolveProjectRegistryEntryConfigPathSync(projectRoot, registryPath, entry) {
|
|
336
|
+
return assertProjectRegistryConfigPathSync({ projectRoot, registryPath, entry });
|
|
337
|
+
}
|
|
338
|
+
async function resolveProjectRegistryAgentPath(projectRoot, agentId) {
|
|
339
|
+
const resolved = await resolveProjectRegistryEntry(projectRoot, agentId);
|
|
340
|
+
if (!resolved) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
return await resolveProjectRegistryEntryConfigPath(
|
|
344
|
+
projectRoot,
|
|
345
|
+
resolved.registryPath,
|
|
346
|
+
resolved.entry
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
async function resolveDefaultProjectRegistryAgentPath(projectRoot) {
|
|
350
|
+
const loaded = await loadProjectRegistry(projectRoot);
|
|
351
|
+
if (!loaded) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
const entry = getDefaultProjectRegistryEntry(loaded.registry, loaded.registryPath);
|
|
355
|
+
if (!entry) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
return await resolveProjectRegistryEntryConfigPath(projectRoot, loaded.registryPath, entry);
|
|
359
|
+
}
|
|
360
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
361
|
+
0 && (module.exports = {
|
|
362
|
+
ProjectRegistryEntrySchema,
|
|
363
|
+
ProjectRegistryError,
|
|
364
|
+
ProjectRegistrySchema,
|
|
365
|
+
findProjectRegistryPath,
|
|
366
|
+
findProjectRegistryPathSync,
|
|
367
|
+
getDefaultProjectRegistryEntry,
|
|
368
|
+
getProjectRegistryCandidatePaths,
|
|
369
|
+
getProjectRegistryPath,
|
|
370
|
+
isProjectRegistryError,
|
|
371
|
+
loadProjectRegistry,
|
|
372
|
+
loadProjectRegistrySync,
|
|
373
|
+
readProjectRegistry,
|
|
374
|
+
readProjectRegistrySync,
|
|
375
|
+
resolveDefaultProjectRegistryAgentPath,
|
|
376
|
+
resolveProjectRegistryAgentPath,
|
|
377
|
+
resolveProjectRegistryEntry,
|
|
378
|
+
resolveProjectRegistryEntryConfigPath,
|
|
379
|
+
resolveProjectRegistryEntryConfigPathSync
|
|
380
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ProjectRegistryEntrySchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
description: z.ZodString;
|
|
6
|
+
configPath: z.ZodString;
|
|
7
|
+
author: z.ZodOptional<z.ZodString>;
|
|
8
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
parentAgentId: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, "strict", z.ZodTypeAny, {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
configPath: string;
|
|
15
|
+
author?: string | undefined;
|
|
16
|
+
tags?: string[] | undefined;
|
|
17
|
+
parentAgentId?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
configPath: string;
|
|
23
|
+
author?: string | undefined;
|
|
24
|
+
tags?: string[] | undefined;
|
|
25
|
+
parentAgentId?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export type ProjectRegistryEntry = z.output<typeof ProjectRegistryEntrySchema>;
|
|
28
|
+
export declare const ProjectRegistrySchema: z.ZodEffects<z.ZodObject<{
|
|
29
|
+
primaryAgent: z.ZodOptional<z.ZodString>;
|
|
30
|
+
allowGlobalAgents: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
description: z.ZodString;
|
|
35
|
+
configPath: z.ZodString;
|
|
36
|
+
author: z.ZodOptional<z.ZodString>;
|
|
37
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
38
|
+
parentAgentId: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strict", z.ZodTypeAny, {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
configPath: string;
|
|
44
|
+
author?: string | undefined;
|
|
45
|
+
tags?: string[] | undefined;
|
|
46
|
+
parentAgentId?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
configPath: string;
|
|
52
|
+
author?: string | undefined;
|
|
53
|
+
tags?: string[] | undefined;
|
|
54
|
+
parentAgentId?: string | undefined;
|
|
55
|
+
}>, "many">;
|
|
56
|
+
}, "strict", z.ZodTypeAny, {
|
|
57
|
+
agents: {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
description: string;
|
|
61
|
+
configPath: string;
|
|
62
|
+
author?: string | undefined;
|
|
63
|
+
tags?: string[] | undefined;
|
|
64
|
+
parentAgentId?: string | undefined;
|
|
65
|
+
}[];
|
|
66
|
+
allowGlobalAgents: boolean;
|
|
67
|
+
primaryAgent?: string | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
agents: {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
description: string;
|
|
73
|
+
configPath: string;
|
|
74
|
+
author?: string | undefined;
|
|
75
|
+
tags?: string[] | undefined;
|
|
76
|
+
parentAgentId?: string | undefined;
|
|
77
|
+
}[];
|
|
78
|
+
primaryAgent?: string | undefined;
|
|
79
|
+
allowGlobalAgents?: boolean | undefined;
|
|
80
|
+
}>, {
|
|
81
|
+
agents: {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
configPath: string;
|
|
86
|
+
author?: string | undefined;
|
|
87
|
+
tags?: string[] | undefined;
|
|
88
|
+
parentAgentId?: string | undefined;
|
|
89
|
+
}[];
|
|
90
|
+
allowGlobalAgents: boolean;
|
|
91
|
+
primaryAgent?: string | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
agents: {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
description: string;
|
|
97
|
+
configPath: string;
|
|
98
|
+
author?: string | undefined;
|
|
99
|
+
tags?: string[] | undefined;
|
|
100
|
+
parentAgentId?: string | undefined;
|
|
101
|
+
}[];
|
|
102
|
+
primaryAgent?: string | undefined;
|
|
103
|
+
allowGlobalAgents?: boolean | undefined;
|
|
104
|
+
}>;
|
|
105
|
+
export type ProjectRegistry = z.output<typeof ProjectRegistrySchema>;
|
|
106
|
+
export type ProjectRegistryErrorCode = 'PROJECT_REGISTRY_INVALID' | 'PROJECT_REGISTRY_INVALID_PRIMARY' | 'PROJECT_REGISTRY_INVALID_CONFIG_PATH';
|
|
107
|
+
export declare class ProjectRegistryError extends Error {
|
|
108
|
+
readonly code: ProjectRegistryErrorCode;
|
|
109
|
+
readonly registryPath: string;
|
|
110
|
+
readonly agentId: string | undefined;
|
|
111
|
+
readonly configPath: string | undefined;
|
|
112
|
+
constructor(options: {
|
|
113
|
+
code: ProjectRegistryErrorCode;
|
|
114
|
+
message: string;
|
|
115
|
+
registryPath: string;
|
|
116
|
+
agentId?: string | undefined;
|
|
117
|
+
configPath?: string | undefined;
|
|
118
|
+
cause?: unknown;
|
|
119
|
+
});
|
|
120
|
+
static invalidRegistry(registryPath: string, message: string, cause?: unknown): ProjectRegistryError;
|
|
121
|
+
static invalidPrimaryAgent(registryPath: string, primaryAgent: string): ProjectRegistryError;
|
|
122
|
+
static invalidConfigPath(options: {
|
|
123
|
+
registryPath: string;
|
|
124
|
+
agentId: string;
|
|
125
|
+
configPath: string;
|
|
126
|
+
reason: string;
|
|
127
|
+
}): ProjectRegistryError;
|
|
128
|
+
}
|
|
129
|
+
export declare function isProjectRegistryError(error: unknown): error is ProjectRegistryError;
|
|
130
|
+
export declare function getProjectRegistryPath(projectRoot: string): string;
|
|
131
|
+
export declare function getProjectRegistryCandidatePaths(projectRoot: string): string[];
|
|
132
|
+
export declare function findProjectRegistryPath(projectRoot: string): Promise<string | null>;
|
|
133
|
+
export declare function findProjectRegistryPathSync(projectRoot: string): string | null;
|
|
134
|
+
export declare function readProjectRegistry(registryPath: string): Promise<ProjectRegistry>;
|
|
135
|
+
export declare function readProjectRegistrySync(registryPath: string): ProjectRegistry;
|
|
136
|
+
export declare function loadProjectRegistry(projectRoot: string): Promise<{
|
|
137
|
+
registryPath: string;
|
|
138
|
+
registry: ProjectRegistry;
|
|
139
|
+
} | null>;
|
|
140
|
+
export declare function loadProjectRegistrySync(projectRoot: string): {
|
|
141
|
+
registryPath: string;
|
|
142
|
+
registry: ProjectRegistry;
|
|
143
|
+
} | null;
|
|
144
|
+
export declare function resolveProjectRegistryEntry(projectRoot: string, agentId: string): Promise<{
|
|
145
|
+
registryPath: string;
|
|
146
|
+
entry: ProjectRegistryEntry;
|
|
147
|
+
} | null>;
|
|
148
|
+
export declare function getDefaultProjectRegistryEntry(registry: ProjectRegistry, registryPath: string): ProjectRegistryEntry | null;
|
|
149
|
+
export declare function resolveProjectRegistryEntryConfigPath(projectRoot: string, registryPath: string, entry: ProjectRegistryEntry): Promise<string>;
|
|
150
|
+
export declare function resolveProjectRegistryEntryConfigPathSync(projectRoot: string, registryPath: string, entry: ProjectRegistryEntry): string;
|
|
151
|
+
export declare function resolveProjectRegistryAgentPath(projectRoot: string, agentId: string): Promise<string | null>;
|
|
152
|
+
export declare function resolveDefaultProjectRegistryAgentPath(projectRoot: string): Promise<string | null>;
|
|
153
|
+
//# sourceMappingURL=project-registry.d.ts.map
|