@dexto/agent-management 1.10.4 → 1.11.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
|
@@ -0,0 +1,198 @@
|
|
|
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 local_skills_exports = {};
|
|
30
|
+
__export(local_skills_exports, {
|
|
31
|
+
LocalSkills: () => LocalSkills,
|
|
32
|
+
createLocalSkills: () => createLocalSkills
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(local_skills_exports);
|
|
35
|
+
var import_node_fs = require("node:fs");
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_core = require("@dexto/core");
|
|
38
|
+
var import_discover_plugins = require("./discover-plugins.js");
|
|
39
|
+
var import_discover_skills = require("./discover-skills.js");
|
|
40
|
+
var import_load_plugin = require("./load-plugin.js");
|
|
41
|
+
var import_skill_markdown = require("./skill-markdown.js");
|
|
42
|
+
class LocalSkills {
|
|
43
|
+
constructor(discoverRoots, initialWorkspaceRoot = void 0) {
|
|
44
|
+
this.discoverRoots = discoverRoots;
|
|
45
|
+
this.initialWorkspaceRoot = initialWorkspaceRoot;
|
|
46
|
+
}
|
|
47
|
+
activeWorkspaceRoot;
|
|
48
|
+
/**
|
|
49
|
+
* Internal host lifecycle hook used by DextoAgent when the active workspace changes.
|
|
50
|
+
* This is deliberately outside the public Core Skills contract.
|
|
51
|
+
*/
|
|
52
|
+
setWorkspaceRoot(workspaceRoot) {
|
|
53
|
+
this.activeWorkspaceRoot = workspaceRoot;
|
|
54
|
+
}
|
|
55
|
+
async list() {
|
|
56
|
+
const summaries = [];
|
|
57
|
+
for (const root of await this.discoverRoots(this.getWorkspaceRoot())) {
|
|
58
|
+
const skill = await this.readSkillFile(root);
|
|
59
|
+
if (!skill) continue;
|
|
60
|
+
summaries.push({ name: skill.root.name, description: skill.description });
|
|
61
|
+
}
|
|
62
|
+
return summaries;
|
|
63
|
+
}
|
|
64
|
+
async load(name) {
|
|
65
|
+
const skill = await this.findSkill(name);
|
|
66
|
+
if (!skill) return null;
|
|
67
|
+
return {
|
|
68
|
+
name: skill.root.name,
|
|
69
|
+
instructions: skill.instructions,
|
|
70
|
+
supportingFiles: await listSupportingFiles(import_node_path.default.dirname(skill.root.skillFile)),
|
|
71
|
+
filesLocation: "workspace",
|
|
72
|
+
baseDirectory: import_node_path.default.dirname(skill.root.skillFile)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async readFile(name, requestedPath) {
|
|
76
|
+
const skill = await this.findSkill(name);
|
|
77
|
+
const skillDirectory = skill ? import_node_path.default.dirname(skill.root.skillFile) : void 0;
|
|
78
|
+
const skillFile = skill?.root.skillFile;
|
|
79
|
+
if (!skillDirectory || skillFile === void 0 || !(0, import_core.isSafeRelativeSkillPath)(requestedPath)) {
|
|
80
|
+
throw new Error(`Skill file not found: ${name}/${requestedPath}`);
|
|
81
|
+
}
|
|
82
|
+
const resolvedPath = import_node_path.default.resolve(skillDirectory, requestedPath);
|
|
83
|
+
const directoryPrefix = `${import_node_path.default.resolve(skillDirectory)}${import_node_path.default.sep}`;
|
|
84
|
+
if (!resolvedPath.startsWith(directoryPrefix) || resolvedPath === import_node_path.default.resolve(skillFile)) {
|
|
85
|
+
throw new Error(`Skill file not found: ${name}/${requestedPath}`);
|
|
86
|
+
}
|
|
87
|
+
const notFoundMessage = `Skill file not found: ${name}/${requestedPath}`;
|
|
88
|
+
try {
|
|
89
|
+
const [physicalSkillDirectory, physicalResolvedPath, physicalSkillFile] = await Promise.all([
|
|
90
|
+
import_node_fs.promises.realpath(skillDirectory),
|
|
91
|
+
import_node_fs.promises.realpath(resolvedPath),
|
|
92
|
+
import_node_fs.promises.realpath(skillFile)
|
|
93
|
+
]);
|
|
94
|
+
const relativePath = import_node_path.default.relative(physicalSkillDirectory, physicalResolvedPath);
|
|
95
|
+
if (relativePath.length === 0 || relativePath === ".." || relativePath.startsWith(`..${import_node_path.default.sep}`) || import_node_path.default.isAbsolute(relativePath) || physicalResolvedPath === physicalSkillFile) {
|
|
96
|
+
throw new Error(notFoundMessage);
|
|
97
|
+
}
|
|
98
|
+
return await import_node_fs.promises.readFile(physicalResolvedPath, "utf8");
|
|
99
|
+
} catch {
|
|
100
|
+
throw new Error(notFoundMessage);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async findSkill(name) {
|
|
104
|
+
for (const root of await this.discoverRoots(this.getWorkspaceRoot())) {
|
|
105
|
+
if (root.name !== name) continue;
|
|
106
|
+
const skill = await this.readSkillFile(root);
|
|
107
|
+
if (skill) return skill;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
async readSkillFile(root) {
|
|
112
|
+
let instructions;
|
|
113
|
+
try {
|
|
114
|
+
instructions = await import_node_fs.promises.readFile(root.skillFile, "utf8");
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const frontmatter = (0, import_skill_markdown.getSkillFrontmatter)(instructions);
|
|
119
|
+
const localSkillName = import_node_path.default.basename(import_node_path.default.dirname(root.skillFile));
|
|
120
|
+
if (frontmatter.name !== void 0 && frontmatter.name !== root.name && frontmatter.name !== localSkillName) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const description = root.description ?? frontmatter.description;
|
|
124
|
+
return {
|
|
125
|
+
root,
|
|
126
|
+
instructions,
|
|
127
|
+
description: description?.trim() || deriveDescription(instructions, root.name)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
getWorkspaceRoot() {
|
|
131
|
+
return this.activeWorkspaceRoot ?? this.initialWorkspaceRoot;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function createLocalSkills(options = {}) {
|
|
135
|
+
return new LocalSkills(
|
|
136
|
+
(workspaceRoot) => discoverLocalSkillRoots({ ...options, workspaceRoot }),
|
|
137
|
+
options.workspaceRoot
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
function discoverLocalSkillRoots(options) {
|
|
141
|
+
const roots = [];
|
|
142
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
143
|
+
const addRoot = (root) => {
|
|
144
|
+
if (seenNames.has(root.name)) return;
|
|
145
|
+
seenNames.add(root.name);
|
|
146
|
+
roots.push({ ...root, skillFile: import_node_path.default.resolve(root.skillFile) });
|
|
147
|
+
};
|
|
148
|
+
for (const skill of (0, import_discover_skills.discoverStandaloneSkills)(options.workspaceRoot)) {
|
|
149
|
+
addRoot({ name: skill.name, skillFile: skill.skillFile });
|
|
150
|
+
}
|
|
151
|
+
for (const plugin of (0, import_discover_plugins.discoverClaudeCodePlugins)(
|
|
152
|
+
options.workspaceRoot,
|
|
153
|
+
options.bundledPlugins ?? []
|
|
154
|
+
)) {
|
|
155
|
+
const loaded = (0, import_load_plugin.loadClaudeCodePlugin)(plugin);
|
|
156
|
+
for (const command of loaded.commands) {
|
|
157
|
+
if (!command.isSkill) continue;
|
|
158
|
+
const skillName = import_node_path.default.basename(import_node_path.default.dirname(command.file));
|
|
159
|
+
addRoot({
|
|
160
|
+
name: `${command.namespace}:${skillName}`,
|
|
161
|
+
skillFile: command.file
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return roots;
|
|
166
|
+
}
|
|
167
|
+
async function listSupportingFiles(skillDirectory) {
|
|
168
|
+
const files = [];
|
|
169
|
+
await walk(skillDirectory, skillDirectory, files);
|
|
170
|
+
return files.sort();
|
|
171
|
+
}
|
|
172
|
+
async function walk(directory, rootDirectory, files) {
|
|
173
|
+
let entries;
|
|
174
|
+
try {
|
|
175
|
+
entries = await import_node_fs.promises.readdir(directory, { withFileTypes: true });
|
|
176
|
+
} catch {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
const absolutePath = import_node_path.default.join(directory, entry.name);
|
|
181
|
+
if (entry.isDirectory()) {
|
|
182
|
+
await walk(absolutePath, rootDirectory, files);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!entry.isFile() || absolutePath === import_node_path.default.join(rootDirectory, "SKILL.md")) continue;
|
|
186
|
+
files.push(import_node_path.default.relative(rootDirectory, absolutePath).split(import_node_path.default.sep).join("/"));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function deriveDescription(markdown, name) {
|
|
190
|
+
const withoutFrontmatter = (0, import_skill_markdown.stripSkillFrontmatter)(markdown);
|
|
191
|
+
const line = withoutFrontmatter.split("\n").map((candidate) => candidate.trim()).find((candidate) => candidate.length > 0 && !candidate.startsWith("#"));
|
|
192
|
+
return line ?? `Instructions for the ${name} skill.`;
|
|
193
|
+
}
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
LocalSkills,
|
|
197
|
+
createLocalSkills
|
|
198
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LoadedSkill, SkillSummary, Skills } from '@dexto/core';
|
|
2
|
+
export interface LocalSkillRoot {
|
|
3
|
+
/** Exact name exposed to callers and accepted by `skill_load`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Absolute path to the skill's SKILL.md file. */
|
|
6
|
+
skillFile: string;
|
|
7
|
+
/** Optional host-provided routing description. */
|
|
8
|
+
description?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateLocalSkillsOptions {
|
|
11
|
+
workspaceRoot?: string | undefined;
|
|
12
|
+
bundledPlugins?: string[] | undefined;
|
|
13
|
+
}
|
|
14
|
+
type LocalSkillRootDiscovery = (workspaceRoot: string | undefined) => readonly LocalSkillRoot[] | Promise<readonly LocalSkillRoot[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Local host implementation of the Core `Skills` contract.
|
|
17
|
+
*
|
|
18
|
+
* Roots are rediscovered for each operation so creator tools and ordinary file edits are visible
|
|
19
|
+
* without a Core-level refresh/source abstraction.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LocalSkills implements Skills {
|
|
22
|
+
private readonly discoverRoots;
|
|
23
|
+
private readonly initialWorkspaceRoot;
|
|
24
|
+
private activeWorkspaceRoot;
|
|
25
|
+
constructor(discoverRoots: LocalSkillRootDiscovery, initialWorkspaceRoot?: string | undefined);
|
|
26
|
+
/**
|
|
27
|
+
* Internal host lifecycle hook used by DextoAgent when the active workspace changes.
|
|
28
|
+
* This is deliberately outside the public Core Skills contract.
|
|
29
|
+
*/
|
|
30
|
+
setWorkspaceRoot(workspaceRoot: string | undefined): void;
|
|
31
|
+
list(): Promise<readonly SkillSummary[]>;
|
|
32
|
+
load(name: string): Promise<LoadedSkill | null>;
|
|
33
|
+
readFile(name: string, requestedPath: string): Promise<string>;
|
|
34
|
+
private findSkill;
|
|
35
|
+
private readSkillFile;
|
|
36
|
+
private getWorkspaceRoot;
|
|
37
|
+
}
|
|
38
|
+
export declare function createLocalSkills(options?: CreateLocalSkillsOptions): LocalSkills;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=local-skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-skills.d.ts","sourceRoot":"","sources":["../../src/plugins/local-skills.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAMrE,MAAM,WAAW,cAAc;IAC3B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACzC;AAQD,KAAK,uBAAuB,GAAG,CAC3B,aAAa,EAAE,MAAM,GAAG,SAAS,KAChC,SAAS,cAAc,EAAE,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,MAAM;IAIlC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAJzC,OAAO,CAAC,mBAAmB,CAAqB;gBAG3B,aAAa,EAAE,uBAAuB,EACtC,oBAAoB,GAAE,MAAM,GAAG,SAAqB;IAGzE;;;OAGG;IACH,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAInD,IAAI,IAAI,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC;IAUxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAa/C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAuCtD,SAAS;YAST,aAAa;IA0B3B,OAAO,CAAC,gBAAgB;CAG3B;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,WAAW,CAKrF"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isSafeRelativeSkillPath } from "@dexto/core";
|
|
4
|
+
import { discoverClaudeCodePlugins } from "./discover-plugins.js";
|
|
5
|
+
import { discoverStandaloneSkills } from "./discover-skills.js";
|
|
6
|
+
import { loadClaudeCodePlugin } from "./load-plugin.js";
|
|
7
|
+
import { getSkillFrontmatter, stripSkillFrontmatter } from "./skill-markdown.js";
|
|
8
|
+
class LocalSkills {
|
|
9
|
+
constructor(discoverRoots, initialWorkspaceRoot = void 0) {
|
|
10
|
+
this.discoverRoots = discoverRoots;
|
|
11
|
+
this.initialWorkspaceRoot = initialWorkspaceRoot;
|
|
12
|
+
}
|
|
13
|
+
activeWorkspaceRoot;
|
|
14
|
+
/**
|
|
15
|
+
* Internal host lifecycle hook used by DextoAgent when the active workspace changes.
|
|
16
|
+
* This is deliberately outside the public Core Skills contract.
|
|
17
|
+
*/
|
|
18
|
+
setWorkspaceRoot(workspaceRoot) {
|
|
19
|
+
this.activeWorkspaceRoot = workspaceRoot;
|
|
20
|
+
}
|
|
21
|
+
async list() {
|
|
22
|
+
const summaries = [];
|
|
23
|
+
for (const root of await this.discoverRoots(this.getWorkspaceRoot())) {
|
|
24
|
+
const skill = await this.readSkillFile(root);
|
|
25
|
+
if (!skill) continue;
|
|
26
|
+
summaries.push({ name: skill.root.name, description: skill.description });
|
|
27
|
+
}
|
|
28
|
+
return summaries;
|
|
29
|
+
}
|
|
30
|
+
async load(name) {
|
|
31
|
+
const skill = await this.findSkill(name);
|
|
32
|
+
if (!skill) return null;
|
|
33
|
+
return {
|
|
34
|
+
name: skill.root.name,
|
|
35
|
+
instructions: skill.instructions,
|
|
36
|
+
supportingFiles: await listSupportingFiles(path.dirname(skill.root.skillFile)),
|
|
37
|
+
filesLocation: "workspace",
|
|
38
|
+
baseDirectory: path.dirname(skill.root.skillFile)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async readFile(name, requestedPath) {
|
|
42
|
+
const skill = await this.findSkill(name);
|
|
43
|
+
const skillDirectory = skill ? path.dirname(skill.root.skillFile) : void 0;
|
|
44
|
+
const skillFile = skill?.root.skillFile;
|
|
45
|
+
if (!skillDirectory || skillFile === void 0 || !isSafeRelativeSkillPath(requestedPath)) {
|
|
46
|
+
throw new Error(`Skill file not found: ${name}/${requestedPath}`);
|
|
47
|
+
}
|
|
48
|
+
const resolvedPath = path.resolve(skillDirectory, requestedPath);
|
|
49
|
+
const directoryPrefix = `${path.resolve(skillDirectory)}${path.sep}`;
|
|
50
|
+
if (!resolvedPath.startsWith(directoryPrefix) || resolvedPath === path.resolve(skillFile)) {
|
|
51
|
+
throw new Error(`Skill file not found: ${name}/${requestedPath}`);
|
|
52
|
+
}
|
|
53
|
+
const notFoundMessage = `Skill file not found: ${name}/${requestedPath}`;
|
|
54
|
+
try {
|
|
55
|
+
const [physicalSkillDirectory, physicalResolvedPath, physicalSkillFile] = await Promise.all([
|
|
56
|
+
fs.realpath(skillDirectory),
|
|
57
|
+
fs.realpath(resolvedPath),
|
|
58
|
+
fs.realpath(skillFile)
|
|
59
|
+
]);
|
|
60
|
+
const relativePath = path.relative(physicalSkillDirectory, physicalResolvedPath);
|
|
61
|
+
if (relativePath.length === 0 || relativePath === ".." || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath) || physicalResolvedPath === physicalSkillFile) {
|
|
62
|
+
throw new Error(notFoundMessage);
|
|
63
|
+
}
|
|
64
|
+
return await fs.readFile(physicalResolvedPath, "utf8");
|
|
65
|
+
} catch {
|
|
66
|
+
throw new Error(notFoundMessage);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async findSkill(name) {
|
|
70
|
+
for (const root of await this.discoverRoots(this.getWorkspaceRoot())) {
|
|
71
|
+
if (root.name !== name) continue;
|
|
72
|
+
const skill = await this.readSkillFile(root);
|
|
73
|
+
if (skill) return skill;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async readSkillFile(root) {
|
|
78
|
+
let instructions;
|
|
79
|
+
try {
|
|
80
|
+
instructions = await fs.readFile(root.skillFile, "utf8");
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const frontmatter = getSkillFrontmatter(instructions);
|
|
85
|
+
const localSkillName = path.basename(path.dirname(root.skillFile));
|
|
86
|
+
if (frontmatter.name !== void 0 && frontmatter.name !== root.name && frontmatter.name !== localSkillName) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const description = root.description ?? frontmatter.description;
|
|
90
|
+
return {
|
|
91
|
+
root,
|
|
92
|
+
instructions,
|
|
93
|
+
description: description?.trim() || deriveDescription(instructions, root.name)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
getWorkspaceRoot() {
|
|
97
|
+
return this.activeWorkspaceRoot ?? this.initialWorkspaceRoot;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createLocalSkills(options = {}) {
|
|
101
|
+
return new LocalSkills(
|
|
102
|
+
(workspaceRoot) => discoverLocalSkillRoots({ ...options, workspaceRoot }),
|
|
103
|
+
options.workspaceRoot
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function discoverLocalSkillRoots(options) {
|
|
107
|
+
const roots = [];
|
|
108
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
109
|
+
const addRoot = (root) => {
|
|
110
|
+
if (seenNames.has(root.name)) return;
|
|
111
|
+
seenNames.add(root.name);
|
|
112
|
+
roots.push({ ...root, skillFile: path.resolve(root.skillFile) });
|
|
113
|
+
};
|
|
114
|
+
for (const skill of discoverStandaloneSkills(options.workspaceRoot)) {
|
|
115
|
+
addRoot({ name: skill.name, skillFile: skill.skillFile });
|
|
116
|
+
}
|
|
117
|
+
for (const plugin of discoverClaudeCodePlugins(
|
|
118
|
+
options.workspaceRoot,
|
|
119
|
+
options.bundledPlugins ?? []
|
|
120
|
+
)) {
|
|
121
|
+
const loaded = loadClaudeCodePlugin(plugin);
|
|
122
|
+
for (const command of loaded.commands) {
|
|
123
|
+
if (!command.isSkill) continue;
|
|
124
|
+
const skillName = path.basename(path.dirname(command.file));
|
|
125
|
+
addRoot({
|
|
126
|
+
name: `${command.namespace}:${skillName}`,
|
|
127
|
+
skillFile: command.file
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return roots;
|
|
132
|
+
}
|
|
133
|
+
async function listSupportingFiles(skillDirectory) {
|
|
134
|
+
const files = [];
|
|
135
|
+
await walk(skillDirectory, skillDirectory, files);
|
|
136
|
+
return files.sort();
|
|
137
|
+
}
|
|
138
|
+
async function walk(directory, rootDirectory, files) {
|
|
139
|
+
let entries;
|
|
140
|
+
try {
|
|
141
|
+
entries = await fs.readdir(directory, { withFileTypes: true });
|
|
142
|
+
} catch {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
for (const entry of entries) {
|
|
146
|
+
const absolutePath = path.join(directory, entry.name);
|
|
147
|
+
if (entry.isDirectory()) {
|
|
148
|
+
await walk(absolutePath, rootDirectory, files);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!entry.isFile() || absolutePath === path.join(rootDirectory, "SKILL.md")) continue;
|
|
152
|
+
files.push(path.relative(rootDirectory, absolutePath).split(path.sep).join("/"));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function deriveDescription(markdown, name) {
|
|
156
|
+
const withoutFrontmatter = stripSkillFrontmatter(markdown);
|
|
157
|
+
const line = withoutFrontmatter.split("\n").map((candidate) => candidate.trim()).find((candidate) => candidate.length > 0 && !candidate.startsWith("#"));
|
|
158
|
+
return line ?? `Instructions for the ${name} skill.`;
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
LocalSkills,
|
|
162
|
+
createLocalSkills
|
|
163
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var skill_markdown_exports = {};
|
|
20
|
+
__export(skill_markdown_exports, {
|
|
21
|
+
getSkillFrontmatter: () => getSkillFrontmatter,
|
|
22
|
+
stripSkillFrontmatter: () => stripSkillFrontmatter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(skill_markdown_exports);
|
|
25
|
+
var import_yaml = require("yaml");
|
|
26
|
+
const SKILL_FRONTMATTER_PATTERN = /^---\r?\n((?:[\s\S]*?\r?\n)?)---(?:\r?\n|$)/u;
|
|
27
|
+
function getSkillFrontmatter(markdown) {
|
|
28
|
+
const match = SKILL_FRONTMATTER_PATTERN.exec(markdown);
|
|
29
|
+
if (!match) return {};
|
|
30
|
+
const rawFrontmatter = match[1] ?? "";
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = (0, import_yaml.parse)(rawFrontmatter);
|
|
34
|
+
} catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
if (!isRecord(parsed)) return {};
|
|
38
|
+
const name = stringField(parsed.name);
|
|
39
|
+
const description = stringField(parsed.description);
|
|
40
|
+
return {
|
|
41
|
+
...name !== void 0 ? { name } : {},
|
|
42
|
+
...description !== void 0 ? { description } : {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function stripSkillFrontmatter(markdown) {
|
|
46
|
+
const match = SKILL_FRONTMATTER_PATTERN.exec(markdown);
|
|
47
|
+
return match ? markdown.slice(match[0].length) : markdown;
|
|
48
|
+
}
|
|
49
|
+
function isRecord(value) {
|
|
50
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
|
+
}
|
|
52
|
+
function stringField(value) {
|
|
53
|
+
if (typeof value !== "string") return void 0;
|
|
54
|
+
const trimmed = value.trim();
|
|
55
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
getSkillFrontmatter,
|
|
60
|
+
stripSkillFrontmatter
|
|
61
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface SkillFrontmatter {
|
|
2
|
+
name?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Reads the small metadata subset used by standalone Skills.
|
|
7
|
+
* Invalid or absent frontmatter is treated as empty metadata so the file remains loadable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getSkillFrontmatter(markdown: string): SkillFrontmatter;
|
|
10
|
+
export declare function stripSkillFrontmatter(markdown: string): string;
|
|
11
|
+
//# sourceMappingURL=skill-markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-markdown.d.ts","sourceRoot":"","sources":["../../src/plugins/skill-markdown.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAoBtE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG9D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
const SKILL_FRONTMATTER_PATTERN = /^---\r?\n((?:[\s\S]*?\r?\n)?)---(?:\r?\n|$)/u;
|
|
3
|
+
function getSkillFrontmatter(markdown) {
|
|
4
|
+
const match = SKILL_FRONTMATTER_PATTERN.exec(markdown);
|
|
5
|
+
if (!match) return {};
|
|
6
|
+
const rawFrontmatter = match[1] ?? "";
|
|
7
|
+
let parsed;
|
|
8
|
+
try {
|
|
9
|
+
parsed = parseYaml(rawFrontmatter);
|
|
10
|
+
} catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
if (!isRecord(parsed)) return {};
|
|
14
|
+
const name = stringField(parsed.name);
|
|
15
|
+
const description = stringField(parsed.description);
|
|
16
|
+
return {
|
|
17
|
+
...name !== void 0 ? { name } : {},
|
|
18
|
+
...description !== void 0 ? { description } : {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function stripSkillFrontmatter(markdown) {
|
|
22
|
+
const match = SKILL_FRONTMATTER_PATTERN.exec(markdown);
|
|
23
|
+
return match ? markdown.slice(match[0].length) : markdown;
|
|
24
|
+
}
|
|
25
|
+
function isRecord(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function stringField(value) {
|
|
29
|
+
if (typeof value !== "string") return void 0;
|
|
30
|
+
const trimmed = value.trim();
|
|
31
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
getSkillFrontmatter,
|
|
35
|
+
stripSkillFrontmatter
|
|
36
|
+
};
|