@dexto/agent-management 1.10.4 → 1.12.0
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/agent-creation.cjs +1 -1
- package/dist/agent-creation.js +1 -1
- package/dist/index.cjs +6 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/plugins/discover-skills.cjs +30 -19
- package/dist/plugins/discover-skills.d.ts +16 -8
- package/dist/plugins/discover-skills.d.ts.map +1 -1
- package/dist/plugins/discover-skills.js +28 -18
- package/dist/plugins/index.cjs +7 -6
- package/dist/plugins/index.d.ts +4 -6
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +9 -5
- package/dist/plugins/local-skills.cjs +198 -0
- package/dist/plugins/local-skills.d.ts +40 -0
- package/dist/plugins/local-skills.d.ts.map +1 -0
- package/dist/plugins/local-skills.js +163 -0
- package/dist/plugins/skill-markdown.cjs +61 -0
- package/dist/plugins/skill-markdown.d.ts +11 -0
- package/dist/plugins/skill-markdown.d.ts.map +1 -0
- package/dist/plugins/skill-markdown.js +36 -0
- package/dist/tool-factories/creator-tools/factory.cjs +77 -73
- package/dist/tool-factories/creator-tools/factory.d.ts.map +1 -1
- package/dist/tool-factories/creator-tools/factory.js +82 -74
- package/dist/utils/execution-context.cjs +3 -3
- package/dist/utils/execution-context.d.ts.map +1 -1
- package/dist/utils/execution-context.js +3 -3
- package/package.json +6 -6
- package/dist/plugins/local-skill-source.cjs +0 -104
- package/dist/plugins/local-skill-source.d.ts +0 -20
- package/dist/plugins/local-skill-source.d.ts.map +0 -1
- package/dist/plugins/local-skill-source.js +0 -70
- package/dist/plugins/local-skill-sources.cjs +0 -74
- package/dist/plugins/local-skill-sources.d.ts +0 -7
- package/dist/plugins/local-skill-sources.d.ts.map +0 -1
- package/dist/plugins/local-skill-sources.js +0 -40
|
@@ -35,8 +35,8 @@ var import_node_fs = require("node:fs");
|
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
36
|
var import_core = require("@dexto/core");
|
|
37
37
|
var import_discover_skills = require("../../plugins/discover-skills.js");
|
|
38
|
+
var import_skill_markdown = require("../../plugins/skill-markdown.js");
|
|
38
39
|
var import_schemas = require("./schemas.js");
|
|
39
|
-
var import_path = require("../../utils/path.js");
|
|
40
40
|
var import_zod = require("zod");
|
|
41
41
|
const SkillCreateInputSchema = import_zod.z.object({
|
|
42
42
|
id: import_zod.z.string().min(1).describe("Skill id (kebab-case)."),
|
|
@@ -56,7 +56,7 @@ const SkillListInputSchema = import_zod.z.object({
|
|
|
56
56
|
query: import_zod.z.string().optional().describe("Optional search term to filter skills by name or path")
|
|
57
57
|
}).strict();
|
|
58
58
|
const SkillRefreshInputSchema = import_zod.z.object({
|
|
59
|
-
id: import_zod.z.string().min(1).describe("Skill id to
|
|
59
|
+
id: import_zod.z.string().min(1).describe("Skill id to re-read in the running agent session."),
|
|
60
60
|
scope: import_zod.z.enum(["global", "workspace"]).optional()
|
|
61
61
|
}).strict();
|
|
62
62
|
const SkillSearchInputSchema = import_zod.z.object({
|
|
@@ -80,64 +80,74 @@ function matchesSkillQuery(value, query) {
|
|
|
80
80
|
if (!normalizedQuery) return false;
|
|
81
81
|
return normalizeSkillQuery(value).includes(normalizedQuery);
|
|
82
82
|
}
|
|
83
|
-
function resolveSkillName(info) {
|
|
84
|
-
return info.displayName || info.id;
|
|
85
|
-
}
|
|
86
83
|
function resolveWorkspaceBasePath(context) {
|
|
87
84
|
const workspacePath = context.workspace?.path;
|
|
88
85
|
const fallbackWorkingDir = context.services ? context.services.filesystemService?.getConfig().workingDirectory : void 0;
|
|
89
86
|
return workspacePath || fallbackWorkingDir || process.cwd();
|
|
90
87
|
}
|
|
91
|
-
function
|
|
88
|
+
function resolveWorkspaceSkillsDirectory(context) {
|
|
92
89
|
const base = resolveWorkspaceBasePath(context);
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
return (0, import_discover_skills.getStandaloneSkillPaths)(base).project;
|
|
91
|
+
}
|
|
92
|
+
function resolveGlobalSkillsDirectory() {
|
|
93
|
+
return (0, import_discover_skills.getStandaloneSkillPaths)().user;
|
|
94
|
+
}
|
|
95
|
+
function resolveSkillSearchDirectories(scope, context) {
|
|
96
|
+
const paths = scope === "global" ? (0, import_discover_skills.getStandaloneSkillPaths)() : (0, import_discover_skills.getStandaloneSkillPaths)(resolveWorkspaceBasePath(context));
|
|
97
|
+
return scope === "global" ? [paths.user, ...paths.legacyUser] : [paths.project, ...paths.legacyProject];
|
|
98
98
|
}
|
|
99
99
|
function resolveSkillBaseDirectory(scope, context) {
|
|
100
100
|
if (scope === "global") {
|
|
101
|
-
return { baseDir: (
|
|
101
|
+
return { baseDir: resolveGlobalSkillsDirectory(), scope: "global" };
|
|
102
102
|
}
|
|
103
|
-
return { baseDir:
|
|
103
|
+
return { baseDir: resolveWorkspaceSkillsDirectory(context), scope: "workspace" };
|
|
104
104
|
}
|
|
105
105
|
function resolveSkillDirectory(input, context) {
|
|
106
106
|
return resolveSkillBaseDirectory(input.scope, context);
|
|
107
107
|
}
|
|
108
108
|
async function pathExists(filePath) {
|
|
109
|
-
return await import_node_fs.promises.
|
|
109
|
+
return await import_node_fs.promises.lstat(filePath).then(() => true).catch(() => false);
|
|
110
110
|
}
|
|
111
|
-
async function
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return { baseDir: secondary, scope: "workspace" };
|
|
124
|
-
}
|
|
125
|
-
const legacyFile = import_node_path.default.join(legacy, skillId, "SKILL.md");
|
|
126
|
-
if (await pathExists(legacyFile)) {
|
|
127
|
-
return { baseDir: legacy, scope: "workspace" };
|
|
111
|
+
async function isSafeExistingSkillFile(baseDir, skillFile) {
|
|
112
|
+
try {
|
|
113
|
+
const [fileStat, physicalBaseDir, physicalSkillFile] = await Promise.all([
|
|
114
|
+
import_node_fs.promises.lstat(skillFile),
|
|
115
|
+
import_node_fs.promises.realpath(baseDir),
|
|
116
|
+
import_node_fs.promises.realpath(skillFile)
|
|
117
|
+
]);
|
|
118
|
+
if (!fileStat.isFile() || fileStat.isSymbolicLink()) return false;
|
|
119
|
+
const relativePath = import_node_path.default.relative(physicalBaseDir, physicalSkillFile);
|
|
120
|
+
return relativePath.length > 0 && relativePath !== ".." && !relativePath.startsWith(`..${import_node_path.default.sep}`) && !import_node_path.default.isAbsolute(relativePath);
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
128
123
|
}
|
|
129
|
-
return { baseDir: primary, scope: "workspace" };
|
|
130
124
|
}
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
function resolveSkillUpdateDirectory(input, context) {
|
|
126
|
+
return resolveSkillBaseDirectory(input.scope, context);
|
|
127
|
+
}
|
|
128
|
+
async function resolveExistingSkillLocation(input, context, toolId) {
|
|
129
|
+
const { baseDir, scope } = resolveSkillUpdateDirectory(input, context);
|
|
130
|
+
const searchDirectories = resolveSkillSearchDirectories(scope, context);
|
|
131
|
+
for (const searchDirectory of searchDirectories) {
|
|
132
|
+
const skillDir2 = import_node_path.default.join(searchDirectory, input.id.trim());
|
|
133
|
+
ensurePathWithinBase(searchDirectory, skillDir2, toolId);
|
|
134
|
+
const skillFile = import_node_path.default.join(skillDir2, "SKILL.md");
|
|
135
|
+
if (await isSafeExistingSkillFile(searchDirectory, skillFile)) {
|
|
136
|
+
return {
|
|
137
|
+
baseDir: searchDirectory,
|
|
138
|
+
scope,
|
|
139
|
+
skillDir: skillDir2,
|
|
140
|
+
skillFile
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
133
144
|
const skillDir = import_node_path.default.join(baseDir, input.id.trim());
|
|
134
|
-
ensurePathWithinBase(baseDir, skillDir,
|
|
135
|
-
const skillFile = import_node_path.default.join(skillDir, "SKILL.md");
|
|
145
|
+
ensurePathWithinBase(baseDir, skillDir, toolId);
|
|
136
146
|
return {
|
|
137
147
|
baseDir,
|
|
138
148
|
scope,
|
|
139
149
|
skillDir,
|
|
140
|
-
skillFile
|
|
150
|
+
skillFile: import_node_path.default.join(skillDir, "SKILL.md")
|
|
141
151
|
};
|
|
142
152
|
}
|
|
143
153
|
function ensurePathWithinBase(baseDir, targetDir, toolId) {
|
|
@@ -194,32 +204,24 @@ function buildSkillMarkdown(input) {
|
|
|
194
204
|
content: input.content
|
|
195
205
|
});
|
|
196
206
|
}
|
|
197
|
-
function frontmatterDescription(markdown) {
|
|
198
|
-
if (!markdown.startsWith("---\n")) return void 0;
|
|
199
|
-
const end = markdown.indexOf("\n---", 4);
|
|
200
|
-
if (end < 0) return void 0;
|
|
201
|
-
const line = markdown.slice(4, end).split("\n").find((candidate) => candidate.trim().startsWith("description:"));
|
|
202
|
-
return line?.split(":").slice(1).join(":").trim().replace(/^"|"$/g, "") || void 0;
|
|
203
|
-
}
|
|
204
207
|
async function readSkillDescription(skillFile) {
|
|
205
208
|
try {
|
|
206
209
|
const raw = await import_node_fs.promises.readFile(skillFile, "utf-8");
|
|
207
|
-
return
|
|
210
|
+
return (0, import_skill_markdown.getSkillFrontmatter)(raw).description;
|
|
208
211
|
} catch {
|
|
209
212
|
return void 0;
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
|
-
async function
|
|
213
|
-
const
|
|
214
|
-
if (!
|
|
215
|
-
await
|
|
216
|
-
return true;
|
|
215
|
+
async function checkSkillAvailable(context, name) {
|
|
216
|
+
const skills = context.services?.skills;
|
|
217
|
+
if (!skills) return false;
|
|
218
|
+
return await skills.load(name) !== null;
|
|
217
219
|
}
|
|
218
220
|
function inspectSkillBundle() {
|
|
219
221
|
return {
|
|
220
222
|
notes: [
|
|
221
223
|
"Files under mcps/ are inert bundled files. Configure MCP servers through normal MCP configuration paths.",
|
|
222
|
-
"
|
|
224
|
+
"Skills are read from their current files, so edits are visible to the next skill_load call."
|
|
223
225
|
]
|
|
224
226
|
};
|
|
225
227
|
}
|
|
@@ -263,20 +265,19 @@ const creatorToolsFactory = {
|
|
|
263
265
|
(directory) => import_node_fs.promises.mkdir(import_node_path.default.join(skillDir, directory), { recursive: true })
|
|
264
266
|
)
|
|
265
267
|
);
|
|
266
|
-
const
|
|
267
|
-
const displayName = titleizeSkillId(skillId) || skillId;
|
|
268
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
268
269
|
const bundleDetails = inspectSkillBundle();
|
|
269
270
|
return {
|
|
270
271
|
created: true,
|
|
271
272
|
id: skillId,
|
|
272
|
-
name:
|
|
273
|
+
name: skillId,
|
|
273
274
|
description: resolvedInput.description.trim(),
|
|
274
275
|
scope,
|
|
275
276
|
path: skillFile,
|
|
276
277
|
resourceDirectories: SKILL_RESOURCE_DIRECTORIES.map(
|
|
277
278
|
(directory) => import_node_path.default.join(skillDir, directory)
|
|
278
279
|
),
|
|
279
|
-
|
|
280
|
+
skillsAvailable,
|
|
280
281
|
...bundleDetails
|
|
281
282
|
};
|
|
282
283
|
}
|
|
@@ -292,7 +293,11 @@ const creatorToolsFactory = {
|
|
|
292
293
|
context: "skill_update",
|
|
293
294
|
hint: "Use kebab-case skill ids (e.g., release-notes)"
|
|
294
295
|
});
|
|
295
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
296
|
+
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
297
|
+
input,
|
|
298
|
+
context,
|
|
299
|
+
"skill_update"
|
|
300
|
+
);
|
|
296
301
|
const exists = await pathExists(skillFile);
|
|
297
302
|
if (!exists) {
|
|
298
303
|
throw import_core.ToolError.validationFailed(
|
|
@@ -314,7 +319,7 @@ const creatorToolsFactory = {
|
|
|
314
319
|
content: input.content.trim()
|
|
315
320
|
});
|
|
316
321
|
await import_node_fs.promises.writeFile(skillFile, markdown, "utf-8");
|
|
317
|
-
const
|
|
322
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
318
323
|
const bundleDetails = inspectSkillBundle();
|
|
319
324
|
return {
|
|
320
325
|
updated: true,
|
|
@@ -322,14 +327,14 @@ const creatorToolsFactory = {
|
|
|
322
327
|
description,
|
|
323
328
|
scope,
|
|
324
329
|
path: skillFile,
|
|
325
|
-
|
|
330
|
+
skillsAvailable,
|
|
326
331
|
...bundleDetails
|
|
327
332
|
};
|
|
328
333
|
}
|
|
329
334
|
});
|
|
330
335
|
const skillRefreshTool = (0, import_core.defineTool)({
|
|
331
336
|
id: "skill_refresh",
|
|
332
|
-
description: "
|
|
337
|
+
description: "Re-read one standalone skill bundle in the current session after editing SKILL.md, handlers/, scripts/, mcps/, or references/.",
|
|
333
338
|
inputSchema: SkillRefreshInputSchema,
|
|
334
339
|
presentation: { activity: import_core.TOOL_ACTIVITY.refreshSkill },
|
|
335
340
|
execute: async (input, context) => {
|
|
@@ -343,7 +348,11 @@ const creatorToolsFactory = {
|
|
|
343
348
|
"skill_refresh requires ToolExecutionContext.services.skills"
|
|
344
349
|
);
|
|
345
350
|
}
|
|
346
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
351
|
+
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
352
|
+
input,
|
|
353
|
+
context,
|
|
354
|
+
"skill_refresh"
|
|
355
|
+
);
|
|
347
356
|
const exists = await pathExists(skillFile);
|
|
348
357
|
if (!exists) {
|
|
349
358
|
throw import_core.ToolError.validationFailed(
|
|
@@ -351,14 +360,14 @@ const creatorToolsFactory = {
|
|
|
351
360
|
`Skill not found at ${skillFile}`
|
|
352
361
|
);
|
|
353
362
|
}
|
|
354
|
-
const
|
|
363
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
355
364
|
const bundleDetails = inspectSkillBundle();
|
|
356
365
|
return {
|
|
357
366
|
refreshed: true,
|
|
358
367
|
id: skillId,
|
|
359
368
|
scope,
|
|
360
369
|
path: skillFile,
|
|
361
|
-
|
|
370
|
+
skillsAvailable,
|
|
362
371
|
...bundleDetails
|
|
363
372
|
};
|
|
364
373
|
}
|
|
@@ -373,21 +382,16 @@ const creatorToolsFactory = {
|
|
|
373
382
|
const normalizedQuery = normalizeSkillQuery(query);
|
|
374
383
|
const hasQuery = normalizedQuery.length > 0;
|
|
375
384
|
const limit = input.limit ?? (hasQuery ? void 0 : 50);
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
385
|
+
const skills = context.services?.skills;
|
|
386
|
+
if (!skills) {
|
|
378
387
|
throw import_core.ToolError.configInvalid(
|
|
379
388
|
"skill_search requires ToolExecutionContext.services.skills"
|
|
380
389
|
);
|
|
381
390
|
}
|
|
382
|
-
const loaded = await
|
|
383
|
-
let results = loaded
|
|
384
|
-
id: info.id,
|
|
385
|
-
name: resolveSkillName(info),
|
|
386
|
-
...info.description ? { description: info.description } : {}
|
|
387
|
-
}));
|
|
391
|
+
const loaded = await skills.list();
|
|
392
|
+
let results = [...loaded];
|
|
388
393
|
if (hasQuery && normalizedQuery) {
|
|
389
394
|
results = results.filter((entry) => {
|
|
390
|
-
if (matchesSkillQuery(entry.id, normalizedQuery)) return true;
|
|
391
395
|
if (matchesSkillQuery(entry.name, normalizedQuery)) return true;
|
|
392
396
|
if (matchesSkillQuery(entry.description, normalizedQuery)) return true;
|
|
393
397
|
return false;
|
|
@@ -400,7 +404,7 @@ const creatorToolsFactory = {
|
|
|
400
404
|
count: limited.length,
|
|
401
405
|
total: results.length,
|
|
402
406
|
skills: limited,
|
|
403
|
-
_hint: limited.length > 0 ? "Use
|
|
407
|
+
_hint: limited.length > 0 ? "Use skill_load with the exact name for a matching skill." : "No skills matched the query."
|
|
404
408
|
};
|
|
405
409
|
}
|
|
406
410
|
});
|
|
@@ -419,7 +423,7 @@ const creatorToolsFactory = {
|
|
|
419
423
|
return false;
|
|
420
424
|
}) : skills;
|
|
421
425
|
return {
|
|
422
|
-
searchPaths: (0, import_discover_skills.getSkillSearchPaths)(),
|
|
426
|
+
searchPaths: (0, import_discover_skills.getSkillSearchPaths)(input.projectPath),
|
|
423
427
|
skills: filtered
|
|
424
428
|
};
|
|
425
429
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAevD,OAAO,EAIH,KAAK,kBAAkB,EAC1B,MAAM,cAAc,CAAC;AA0VtB,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CA2S/D,CAAC"}
|
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
defineTool,
|
|
7
7
|
assertValidPromptName
|
|
8
8
|
} from "@dexto/core";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
discoverStandaloneSkills,
|
|
11
|
+
getSkillSearchPaths,
|
|
12
|
+
getStandaloneSkillPaths
|
|
13
|
+
} from "../../plugins/discover-skills.js";
|
|
14
|
+
import { getSkillFrontmatter } from "../../plugins/skill-markdown.js";
|
|
10
15
|
import {
|
|
11
16
|
CREATOR_TOOL_NAMES,
|
|
12
17
|
CreatorToolsConfigSchema
|
|
13
18
|
} from "./schemas.js";
|
|
14
|
-
import { getDextoGlobalPath } from "../../utils/path.js";
|
|
15
19
|
import { z } from "zod";
|
|
16
20
|
const SkillCreateInputSchema = z.object({
|
|
17
21
|
id: z.string().min(1).describe("Skill id (kebab-case)."),
|
|
@@ -31,7 +35,7 @@ const SkillListInputSchema = z.object({
|
|
|
31
35
|
query: z.string().optional().describe("Optional search term to filter skills by name or path")
|
|
32
36
|
}).strict();
|
|
33
37
|
const SkillRefreshInputSchema = z.object({
|
|
34
|
-
id: z.string().min(1).describe("Skill id to
|
|
38
|
+
id: z.string().min(1).describe("Skill id to re-read in the running agent session."),
|
|
35
39
|
scope: z.enum(["global", "workspace"]).optional()
|
|
36
40
|
}).strict();
|
|
37
41
|
const SkillSearchInputSchema = z.object({
|
|
@@ -55,64 +59,74 @@ function matchesSkillQuery(value, query) {
|
|
|
55
59
|
if (!normalizedQuery) return false;
|
|
56
60
|
return normalizeSkillQuery(value).includes(normalizedQuery);
|
|
57
61
|
}
|
|
58
|
-
function resolveSkillName(info) {
|
|
59
|
-
return info.displayName || info.id;
|
|
60
|
-
}
|
|
61
62
|
function resolveWorkspaceBasePath(context) {
|
|
62
63
|
const workspacePath = context.workspace?.path;
|
|
63
64
|
const fallbackWorkingDir = context.services ? context.services.filesystemService?.getConfig().workingDirectory : void 0;
|
|
64
65
|
return workspacePath || fallbackWorkingDir || process.cwd();
|
|
65
66
|
}
|
|
66
|
-
function
|
|
67
|
+
function resolveWorkspaceSkillsDirectory(context) {
|
|
67
68
|
const base = resolveWorkspaceBasePath(context);
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
return getStandaloneSkillPaths(base).project;
|
|
70
|
+
}
|
|
71
|
+
function resolveGlobalSkillsDirectory() {
|
|
72
|
+
return getStandaloneSkillPaths().user;
|
|
73
|
+
}
|
|
74
|
+
function resolveSkillSearchDirectories(scope, context) {
|
|
75
|
+
const paths = scope === "global" ? getStandaloneSkillPaths() : getStandaloneSkillPaths(resolveWorkspaceBasePath(context));
|
|
76
|
+
return scope === "global" ? [paths.user, ...paths.legacyUser] : [paths.project, ...paths.legacyProject];
|
|
73
77
|
}
|
|
74
78
|
function resolveSkillBaseDirectory(scope, context) {
|
|
75
79
|
if (scope === "global") {
|
|
76
|
-
return { baseDir:
|
|
80
|
+
return { baseDir: resolveGlobalSkillsDirectory(), scope: "global" };
|
|
77
81
|
}
|
|
78
|
-
return { baseDir:
|
|
82
|
+
return { baseDir: resolveWorkspaceSkillsDirectory(context), scope: "workspace" };
|
|
79
83
|
}
|
|
80
84
|
function resolveSkillDirectory(input, context) {
|
|
81
85
|
return resolveSkillBaseDirectory(input.scope, context);
|
|
82
86
|
}
|
|
83
87
|
async function pathExists(filePath) {
|
|
84
|
-
return await fs.
|
|
88
|
+
return await fs.lstat(filePath).then(() => true).catch(() => false);
|
|
85
89
|
}
|
|
86
|
-
async function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return { baseDir: secondary, scope: "workspace" };
|
|
99
|
-
}
|
|
100
|
-
const legacyFile = path.join(legacy, skillId, "SKILL.md");
|
|
101
|
-
if (await pathExists(legacyFile)) {
|
|
102
|
-
return { baseDir: legacy, scope: "workspace" };
|
|
90
|
+
async function isSafeExistingSkillFile(baseDir, skillFile) {
|
|
91
|
+
try {
|
|
92
|
+
const [fileStat, physicalBaseDir, physicalSkillFile] = await Promise.all([
|
|
93
|
+
fs.lstat(skillFile),
|
|
94
|
+
fs.realpath(baseDir),
|
|
95
|
+
fs.realpath(skillFile)
|
|
96
|
+
]);
|
|
97
|
+
if (!fileStat.isFile() || fileStat.isSymbolicLink()) return false;
|
|
98
|
+
const relativePath = path.relative(physicalBaseDir, physicalSkillFile);
|
|
99
|
+
return relativePath.length > 0 && relativePath !== ".." && !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath);
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
103
102
|
}
|
|
104
|
-
return { baseDir: primary, scope: "workspace" };
|
|
105
103
|
}
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
function resolveSkillUpdateDirectory(input, context) {
|
|
105
|
+
return resolveSkillBaseDirectory(input.scope, context);
|
|
106
|
+
}
|
|
107
|
+
async function resolveExistingSkillLocation(input, context, toolId) {
|
|
108
|
+
const { baseDir, scope } = resolveSkillUpdateDirectory(input, context);
|
|
109
|
+
const searchDirectories = resolveSkillSearchDirectories(scope, context);
|
|
110
|
+
for (const searchDirectory of searchDirectories) {
|
|
111
|
+
const skillDir2 = path.join(searchDirectory, input.id.trim());
|
|
112
|
+
ensurePathWithinBase(searchDirectory, skillDir2, toolId);
|
|
113
|
+
const skillFile = path.join(skillDir2, "SKILL.md");
|
|
114
|
+
if (await isSafeExistingSkillFile(searchDirectory, skillFile)) {
|
|
115
|
+
return {
|
|
116
|
+
baseDir: searchDirectory,
|
|
117
|
+
scope,
|
|
118
|
+
skillDir: skillDir2,
|
|
119
|
+
skillFile
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
108
123
|
const skillDir = path.join(baseDir, input.id.trim());
|
|
109
|
-
ensurePathWithinBase(baseDir, skillDir,
|
|
110
|
-
const skillFile = path.join(skillDir, "SKILL.md");
|
|
124
|
+
ensurePathWithinBase(baseDir, skillDir, toolId);
|
|
111
125
|
return {
|
|
112
126
|
baseDir,
|
|
113
127
|
scope,
|
|
114
128
|
skillDir,
|
|
115
|
-
skillFile
|
|
129
|
+
skillFile: path.join(skillDir, "SKILL.md")
|
|
116
130
|
};
|
|
117
131
|
}
|
|
118
132
|
function ensurePathWithinBase(baseDir, targetDir, toolId) {
|
|
@@ -169,32 +183,24 @@ function buildSkillMarkdown(input) {
|
|
|
169
183
|
content: input.content
|
|
170
184
|
});
|
|
171
185
|
}
|
|
172
|
-
function frontmatterDescription(markdown) {
|
|
173
|
-
if (!markdown.startsWith("---\n")) return void 0;
|
|
174
|
-
const end = markdown.indexOf("\n---", 4);
|
|
175
|
-
if (end < 0) return void 0;
|
|
176
|
-
const line = markdown.slice(4, end).split("\n").find((candidate) => candidate.trim().startsWith("description:"));
|
|
177
|
-
return line?.split(":").slice(1).join(":").trim().replace(/^"|"$/g, "") || void 0;
|
|
178
|
-
}
|
|
179
186
|
async function readSkillDescription(skillFile) {
|
|
180
187
|
try {
|
|
181
188
|
const raw = await fs.readFile(skillFile, "utf-8");
|
|
182
|
-
return
|
|
189
|
+
return getSkillFrontmatter(raw).description;
|
|
183
190
|
} catch {
|
|
184
191
|
return void 0;
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
|
-
async function
|
|
188
|
-
const
|
|
189
|
-
if (!
|
|
190
|
-
await
|
|
191
|
-
return true;
|
|
194
|
+
async function checkSkillAvailable(context, name) {
|
|
195
|
+
const skills = context.services?.skills;
|
|
196
|
+
if (!skills) return false;
|
|
197
|
+
return await skills.load(name) !== null;
|
|
192
198
|
}
|
|
193
199
|
function inspectSkillBundle() {
|
|
194
200
|
return {
|
|
195
201
|
notes: [
|
|
196
202
|
"Files under mcps/ are inert bundled files. Configure MCP servers through normal MCP configuration paths.",
|
|
197
|
-
"
|
|
203
|
+
"Skills are read from their current files, so edits are visible to the next skill_load call."
|
|
198
204
|
]
|
|
199
205
|
};
|
|
200
206
|
}
|
|
@@ -238,20 +244,19 @@ const creatorToolsFactory = {
|
|
|
238
244
|
(directory) => fs.mkdir(path.join(skillDir, directory), { recursive: true })
|
|
239
245
|
)
|
|
240
246
|
);
|
|
241
|
-
const
|
|
242
|
-
const displayName = titleizeSkillId(skillId) || skillId;
|
|
247
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
243
248
|
const bundleDetails = inspectSkillBundle();
|
|
244
249
|
return {
|
|
245
250
|
created: true,
|
|
246
251
|
id: skillId,
|
|
247
|
-
name:
|
|
252
|
+
name: skillId,
|
|
248
253
|
description: resolvedInput.description.trim(),
|
|
249
254
|
scope,
|
|
250
255
|
path: skillFile,
|
|
251
256
|
resourceDirectories: SKILL_RESOURCE_DIRECTORIES.map(
|
|
252
257
|
(directory) => path.join(skillDir, directory)
|
|
253
258
|
),
|
|
254
|
-
|
|
259
|
+
skillsAvailable,
|
|
255
260
|
...bundleDetails
|
|
256
261
|
};
|
|
257
262
|
}
|
|
@@ -267,7 +272,11 @@ const creatorToolsFactory = {
|
|
|
267
272
|
context: "skill_update",
|
|
268
273
|
hint: "Use kebab-case skill ids (e.g., release-notes)"
|
|
269
274
|
});
|
|
270
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
275
|
+
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
276
|
+
input,
|
|
277
|
+
context,
|
|
278
|
+
"skill_update"
|
|
279
|
+
);
|
|
271
280
|
const exists = await pathExists(skillFile);
|
|
272
281
|
if (!exists) {
|
|
273
282
|
throw ToolError.validationFailed(
|
|
@@ -289,7 +298,7 @@ const creatorToolsFactory = {
|
|
|
289
298
|
content: input.content.trim()
|
|
290
299
|
});
|
|
291
300
|
await fs.writeFile(skillFile, markdown, "utf-8");
|
|
292
|
-
const
|
|
301
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
293
302
|
const bundleDetails = inspectSkillBundle();
|
|
294
303
|
return {
|
|
295
304
|
updated: true,
|
|
@@ -297,14 +306,14 @@ const creatorToolsFactory = {
|
|
|
297
306
|
description,
|
|
298
307
|
scope,
|
|
299
308
|
path: skillFile,
|
|
300
|
-
|
|
309
|
+
skillsAvailable,
|
|
301
310
|
...bundleDetails
|
|
302
311
|
};
|
|
303
312
|
}
|
|
304
313
|
});
|
|
305
314
|
const skillRefreshTool = defineTool({
|
|
306
315
|
id: "skill_refresh",
|
|
307
|
-
description: "
|
|
316
|
+
description: "Re-read one standalone skill bundle in the current session after editing SKILL.md, handlers/, scripts/, mcps/, or references/.",
|
|
308
317
|
inputSchema: SkillRefreshInputSchema,
|
|
309
318
|
presentation: { activity: TOOL_ACTIVITY.refreshSkill },
|
|
310
319
|
execute: async (input, context) => {
|
|
@@ -318,7 +327,11 @@ const creatorToolsFactory = {
|
|
|
318
327
|
"skill_refresh requires ToolExecutionContext.services.skills"
|
|
319
328
|
);
|
|
320
329
|
}
|
|
321
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
330
|
+
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
331
|
+
input,
|
|
332
|
+
context,
|
|
333
|
+
"skill_refresh"
|
|
334
|
+
);
|
|
322
335
|
const exists = await pathExists(skillFile);
|
|
323
336
|
if (!exists) {
|
|
324
337
|
throw ToolError.validationFailed(
|
|
@@ -326,14 +339,14 @@ const creatorToolsFactory = {
|
|
|
326
339
|
`Skill not found at ${skillFile}`
|
|
327
340
|
);
|
|
328
341
|
}
|
|
329
|
-
const
|
|
342
|
+
const skillsAvailable = await checkSkillAvailable(context, skillId);
|
|
330
343
|
const bundleDetails = inspectSkillBundle();
|
|
331
344
|
return {
|
|
332
345
|
refreshed: true,
|
|
333
346
|
id: skillId,
|
|
334
347
|
scope,
|
|
335
348
|
path: skillFile,
|
|
336
|
-
|
|
349
|
+
skillsAvailable,
|
|
337
350
|
...bundleDetails
|
|
338
351
|
};
|
|
339
352
|
}
|
|
@@ -348,21 +361,16 @@ const creatorToolsFactory = {
|
|
|
348
361
|
const normalizedQuery = normalizeSkillQuery(query);
|
|
349
362
|
const hasQuery = normalizedQuery.length > 0;
|
|
350
363
|
const limit = input.limit ?? (hasQuery ? void 0 : 50);
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
364
|
+
const skills = context.services?.skills;
|
|
365
|
+
if (!skills) {
|
|
353
366
|
throw ToolError.configInvalid(
|
|
354
367
|
"skill_search requires ToolExecutionContext.services.skills"
|
|
355
368
|
);
|
|
356
369
|
}
|
|
357
|
-
const loaded = await
|
|
358
|
-
let results = loaded
|
|
359
|
-
id: info.id,
|
|
360
|
-
name: resolveSkillName(info),
|
|
361
|
-
...info.description ? { description: info.description } : {}
|
|
362
|
-
}));
|
|
370
|
+
const loaded = await skills.list();
|
|
371
|
+
let results = [...loaded];
|
|
363
372
|
if (hasQuery && normalizedQuery) {
|
|
364
373
|
results = results.filter((entry) => {
|
|
365
|
-
if (matchesSkillQuery(entry.id, normalizedQuery)) return true;
|
|
366
374
|
if (matchesSkillQuery(entry.name, normalizedQuery)) return true;
|
|
367
375
|
if (matchesSkillQuery(entry.description, normalizedQuery)) return true;
|
|
368
376
|
return false;
|
|
@@ -375,7 +383,7 @@ const creatorToolsFactory = {
|
|
|
375
383
|
count: limited.length,
|
|
376
384
|
total: results.length,
|
|
377
385
|
skills: limited,
|
|
378
|
-
_hint: limited.length > 0 ? "Use
|
|
386
|
+
_hint: limited.length > 0 ? "Use skill_load with the exact name for a matching skill." : "No skills matched the query."
|
|
379
387
|
};
|
|
380
388
|
}
|
|
381
389
|
});
|
|
@@ -394,7 +402,7 @@ const creatorToolsFactory = {
|
|
|
394
402
|
return false;
|
|
395
403
|
}) : skills;
|
|
396
404
|
return {
|
|
397
|
-
searchPaths: getSkillSearchPaths(),
|
|
405
|
+
searchPaths: getSkillSearchPaths(input.projectPath),
|
|
398
406
|
skills: filtered
|
|
399
407
|
};
|
|
400
408
|
}
|
|
@@ -57,9 +57,9 @@ function getCaseInsensitiveRootFilename(dirPath, filename) {
|
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function hasWorkspaceAuthoringDirectory(dirPath,
|
|
60
|
+
function hasWorkspaceAuthoringDirectory(dirPath, relativePath) {
|
|
61
61
|
try {
|
|
62
|
-
return (0, import_fs.statSync)(path.join(dirPath,
|
|
62
|
+
return (0, import_fs.statSync)(path.join(dirPath, relativePath)).isDirectory();
|
|
63
63
|
} catch {
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
@@ -77,7 +77,7 @@ function hasDextoWorkspaceAgentsFile(dirPath) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
function hasWorkspaceScaffoldMarker(dirPath) {
|
|
80
|
-
return hasDextoWorkspaceAgentsFile(dirPath) && (hasWorkspaceAuthoringDirectory(dirPath, "agents") || hasWorkspaceAuthoringDirectory(dirPath, "skills"));
|
|
80
|
+
return hasDextoWorkspaceAgentsFile(dirPath) && (hasWorkspaceAuthoringDirectory(dirPath, "agents") || hasWorkspaceAuthoringDirectory(dirPath, ".agents/skills") || hasWorkspaceAuthoringDirectory(dirPath, "skills") || hasWorkspaceAuthoringDirectory(dirPath, ".dexto/skills"));
|
|
81
81
|
}
|
|
82
82
|
function readPackageName(dirPath) {
|
|
83
83
|
const packageJsonPath = path.join(dirPath, "package.json");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../src/utils/execution-context.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,eAAe,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../src/utils/execution-context.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,eAAe,GAAG,YAAY,CAAC;AA6J/E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAEpF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAMrF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,GAAE,MAAsB,GAAG,gBAAgB,CAiBvF"}
|