@antelopejs/agent-skills 0.0.0-stage → 0.2.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/LICENSE +190 -0
- package/README.md +34 -2
- package/index.d.ts +58 -0
- package/index.mjs +281 -0
- package/package.json +53 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright (c) 2025-present - AntelopeJS Team
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @antelopejs/agent-skills
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Finds the agent skills that AntelopeJS packages ship. The Claude Code and Codex plugin of [AntelopeJS/agent-skills](https://github.com/AntelopeJS/agent-skills) and the dms-ai assistant both call it, so they see the same skills.
|
|
4
|
+
|
|
5
|
+
A package ships skills by declaring `antelopeJs.skills` in its `package.json`: directories (relative to the package root) whose subdirectories each hold a `SKILL.md`. This package decides which packages count and which copy of each wins. Reading the skills inside the directories, and naming them, stays with the caller.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { collectSkillPackages } from "@antelopejs/agent-skills";
|
|
9
|
+
|
|
10
|
+
const packages = collectSkillPackages({
|
|
11
|
+
modules: [{ dir: "/app/.antelope/cache/dms", id: "dms" }],
|
|
12
|
+
project: "/app",
|
|
13
|
+
installed: ["/app/node_modules/@antelopejs/core"],
|
|
14
|
+
onWarning: (message) => console.warn(message),
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Each result is `{ name, version, dir, skillDirs, kind }`. `skillDirs` are absolute and inside `dir`.
|
|
19
|
+
|
|
20
|
+
## Priority
|
|
21
|
+
|
|
22
|
+
Candidates are ordered, and the first one to carry a package name keeps it:
|
|
23
|
+
|
|
24
|
+
1. the `modules`, in the order given, then the `installed` directories whose `package.json` sets `antelopeJs.implements`;
|
|
25
|
+
2. the `dependencies` and `optionalDependencies` of every module, resolved from the module's real path through `node_modules/<dep>` in its ancestors;
|
|
26
|
+
3. the `dependencies`, `optionalDependencies` and `devDependencies` of `project`, resolved the same way;
|
|
27
|
+
4. the `installed` directories.
|
|
28
|
+
|
|
29
|
+
A module or dependency with a readable manifest and a name reserves that name even when it ships no skills, so the copy a runtime runs always hides an installed copy. A package without a `name` falls back to the module `id`, or to the dependency's own name, and is skipped when it has neither.
|
|
30
|
+
|
|
31
|
+
Only packages with at least one skill directory are returned. A skill directory outside its package is dropped and reported through `onWarning`. A missing or malformed `package.json` reads as absent and never throws.
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
Node.js 20.19 or later. The package is an ES module with no dependencies and no top-level `await`, so a CommonJS caller loads it with `require()`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Where a skill-shipping package was found. */
|
|
2
|
+
export type SkillPackageKind =
|
|
3
|
+
| "module"
|
|
4
|
+
| "dependency"
|
|
5
|
+
| "project"
|
|
6
|
+
| "installed";
|
|
7
|
+
|
|
8
|
+
/** A package that ships agent skills. */
|
|
9
|
+
export interface SkillPackage {
|
|
10
|
+
/** The `name` of its `package.json`, or the fallback name the caller or the dependency list gave it. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** The `version` of its `package.json`, or `null` when it has none. */
|
|
13
|
+
version: string | null;
|
|
14
|
+
/** The package root. */
|
|
15
|
+
dir: string;
|
|
16
|
+
/** Absolute directories declared in `antelopeJs.skills`, each inside {@link SkillPackage.dir}. Never empty. */
|
|
17
|
+
skillDirs: string[];
|
|
18
|
+
/**
|
|
19
|
+
* `module` for a module itself, `dependency` for a dependency of a module,
|
|
20
|
+
* `project` for a dependency of the project root, `installed` for a
|
|
21
|
+
* directory listed in {@link CollectSkillPackagesInput.installed}.
|
|
22
|
+
*/
|
|
23
|
+
kind: SkillPackageKind;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A module the runtime loads. */
|
|
27
|
+
export interface ModuleRef {
|
|
28
|
+
/** The module's package root. */
|
|
29
|
+
dir: string;
|
|
30
|
+
/** The name to use when its `package.json` has none. */
|
|
31
|
+
id?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CollectSkillPackagesInput {
|
|
35
|
+
/** Loaded modules, in priority order. Each reserves its package name even when it ships no skills. */
|
|
36
|
+
modules: readonly ModuleRef[];
|
|
37
|
+
/** The project root; its `dependencies`, `optionalDependencies` and `devDependencies` are read. */
|
|
38
|
+
project?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Extra package directories, lowest priority. One whose `package.json` sets
|
|
41
|
+
* `antelopeJs.implements` is a module the runtime can load, so it also counts
|
|
42
|
+
* as a module, after {@link CollectSkillPackagesInput.modules}.
|
|
43
|
+
*/
|
|
44
|
+
installed?: readonly string[];
|
|
45
|
+
/** Called with a message for each skill directory dropped because it escapes its package. */
|
|
46
|
+
onWarning?: (message: string) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Collects the packages that ship agent skills, in priority order, one per
|
|
51
|
+
* package name: modules (installed interface implementations included), then
|
|
52
|
+
* their dependencies, then the project's dependencies, then `installed`. The
|
|
53
|
+
* first candidate to carry a name keeps it.
|
|
54
|
+
* Only packages with at least one skill directory are returned.
|
|
55
|
+
*/
|
|
56
|
+
export function collectSkillPackages(
|
|
57
|
+
input: CollectSkillPackagesInput,
|
|
58
|
+
): SkillPackage[];
|
package/index.mjs
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
const MANIFEST_FILE = "package.json";
|
|
5
|
+
const NODE_MODULES_DIR = "node_modules";
|
|
6
|
+
/** @type {{ [K in import("./index.js").SkillPackageKind]: K }} */
|
|
7
|
+
const KIND = {
|
|
8
|
+
module: "module",
|
|
9
|
+
dependency: "dependency",
|
|
10
|
+
project: "project",
|
|
11
|
+
installed: "installed",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What discovery reads of a `package.json`.
|
|
16
|
+
* @typedef {object} Manifest
|
|
17
|
+
* @property {string | undefined} name
|
|
18
|
+
* @property {string | null} version
|
|
19
|
+
* @property {string[]} skills Declared `antelopeJs.skills` entries.
|
|
20
|
+
* @property {string[]} dependencies Names under `dependencies`.
|
|
21
|
+
* @property {string[]} optionalDependencies Names under `optionalDependencies`.
|
|
22
|
+
* @property {string[]} devDependencies Names under `devDependencies`.
|
|
23
|
+
* @property {boolean} implementsInterface Whether `antelopeJs.implements` is set.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A package directory to consider, and the name to use when it has none.
|
|
28
|
+
* @typedef {object} Candidate
|
|
29
|
+
* @property {string} dir
|
|
30
|
+
* @property {import("./index.js").SkillPackageKind} kind
|
|
31
|
+
* @property {string | undefined} fallbackName
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether `value` is a string.
|
|
36
|
+
* @param {unknown} value
|
|
37
|
+
* @returns {value is string}
|
|
38
|
+
*/
|
|
39
|
+
function isText(value) {
|
|
40
|
+
return String(value) === value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether `value` is a JSON object: not null, not an array, not a primitive.
|
|
45
|
+
* @param {unknown} value
|
|
46
|
+
* @returns {value is Record<string, unknown>}
|
|
47
|
+
*/
|
|
48
|
+
function isRecord(value) {
|
|
49
|
+
return Object(value) === value && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {unknown} value
|
|
54
|
+
* @returns {string | undefined}
|
|
55
|
+
*/
|
|
56
|
+
function nonEmptyText(value) {
|
|
57
|
+
return isText(value) && value.length > 0 ? value : undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {unknown} value
|
|
62
|
+
* @returns {string[]}
|
|
63
|
+
*/
|
|
64
|
+
function nonEmptyTexts(value) {
|
|
65
|
+
return Array.isArray(value)
|
|
66
|
+
? value.flatMap((entry) => nonEmptyText(entry) ?? [])
|
|
67
|
+
: [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {unknown} value
|
|
72
|
+
* @returns {string[]}
|
|
73
|
+
*/
|
|
74
|
+
function dependencyNames(value) {
|
|
75
|
+
return isRecord(value) ? Object.keys(value) : [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A manifest of any other form reads as absent: no name, no skills, no
|
|
80
|
+
* dependencies.
|
|
81
|
+
* @param {unknown} raw
|
|
82
|
+
* @returns {Manifest | null}
|
|
83
|
+
*/
|
|
84
|
+
function parseManifest(raw) {
|
|
85
|
+
if (!isRecord(raw)) return null;
|
|
86
|
+
const antelopeJs = raw.antelopeJs;
|
|
87
|
+
return {
|
|
88
|
+
name: nonEmptyText(raw.name),
|
|
89
|
+
version: isText(raw.version) ? raw.version : null,
|
|
90
|
+
skills: nonEmptyTexts(isRecord(antelopeJs) ? antelopeJs.skills : undefined),
|
|
91
|
+
dependencies: dependencyNames(raw.dependencies),
|
|
92
|
+
optionalDependencies: dependencyNames(raw.optionalDependencies),
|
|
93
|
+
devDependencies: dependencyNames(raw.devDependencies),
|
|
94
|
+
implementsInterface: isRecord(antelopeJs) && Boolean(antelopeJs.implements),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} dir
|
|
100
|
+
* @returns {Manifest | null}
|
|
101
|
+
*/
|
|
102
|
+
function readManifest(dir) {
|
|
103
|
+
try {
|
|
104
|
+
/** @type {unknown} */
|
|
105
|
+
const raw = JSON.parse(readFileSync(join(dir, MANIFEST_FILE), "utf8"));
|
|
106
|
+
return parseManifest(raw);
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} path
|
|
114
|
+
* @returns {string}
|
|
115
|
+
*/
|
|
116
|
+
function realpathOrSelf(path) {
|
|
117
|
+
try {
|
|
118
|
+
return realpathSync(path);
|
|
119
|
+
} catch {
|
|
120
|
+
return path;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Finds `node_modules/<dep>` from the real path of `fromDir` up its ancestors,
|
|
126
|
+
* which is how Node resolves a dependency and how pnpm's symlinked layout is
|
|
127
|
+
* entered from inside the store.
|
|
128
|
+
* @param {string} fromDir
|
|
129
|
+
* @param {string} dep
|
|
130
|
+
* @param {(dir: string) => Manifest | null} manifestOf
|
|
131
|
+
* @returns {string | null}
|
|
132
|
+
*/
|
|
133
|
+
function resolveDependencyDir(fromDir, dep, manifestOf) {
|
|
134
|
+
for (let dir = realpathOrSelf(fromDir); ; dir = dirname(dir)) {
|
|
135
|
+
const candidate = join(dir, NODE_MODULES_DIR, dep);
|
|
136
|
+
if (manifestOf(candidate) !== null) return candidate;
|
|
137
|
+
if (dirname(dir) === dir) return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {string} packageDir
|
|
143
|
+
* @param {string} dir
|
|
144
|
+
* @returns {boolean}
|
|
145
|
+
*/
|
|
146
|
+
function escapesPackage(packageDir, dir) {
|
|
147
|
+
const from = relative(packageDir, dir);
|
|
148
|
+
return from === ".." || from.startsWith(`..${sep}`) || isAbsolute(from);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {{ name: string, dir: string, manifest: Manifest }} source
|
|
153
|
+
* @param {(message: string) => void} onWarning
|
|
154
|
+
* @returns {string[]}
|
|
155
|
+
*/
|
|
156
|
+
function skillDirsOf({ name, dir, manifest }, onWarning) {
|
|
157
|
+
/** @type {Set<string>} */
|
|
158
|
+
const dirs = new Set();
|
|
159
|
+
for (const declared of manifest.skills) {
|
|
160
|
+
const skillDir = resolve(dir, declared);
|
|
161
|
+
if (escapesPackage(dir, skillDir)) {
|
|
162
|
+
onWarning(
|
|
163
|
+
`${name}: skills dir '${declared}' escapes the package — skipped.`,
|
|
164
|
+
);
|
|
165
|
+
} else {
|
|
166
|
+
dirs.add(skillDir);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return [...dirs];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} root
|
|
174
|
+
* @param {string[]} names
|
|
175
|
+
* @param {import("./index.js").SkillPackageKind} kind
|
|
176
|
+
* @param {(dir: string) => Manifest | null} manifestOf
|
|
177
|
+
* @returns {Candidate[]}
|
|
178
|
+
*/
|
|
179
|
+
function dependencyCandidates(root, names, kind, manifestOf) {
|
|
180
|
+
return names.flatMap((dep) => {
|
|
181
|
+
const dir = resolveDependencyDir(root, dep, manifestOf);
|
|
182
|
+
return dir === null ? [] : [{ dir, kind, fallbackName: dep }];
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {import("./index.js").CollectSkillPackagesInput} input
|
|
188
|
+
* @param {(dir: string) => Manifest | null} manifestOf
|
|
189
|
+
* @returns {Candidate[]}
|
|
190
|
+
*/
|
|
191
|
+
function candidatesOf({ modules, project, installed = [] }, manifestOf) {
|
|
192
|
+
/** @type {import("./index.js").ModuleRef[]} */
|
|
193
|
+
const installedModules = installed
|
|
194
|
+
.filter((dir) => manifestOf(dir)?.implementsInterface)
|
|
195
|
+
.map((dir) => ({ dir }));
|
|
196
|
+
const own = [...modules, ...installedModules].map((entry) => ({
|
|
197
|
+
dir: entry.dir,
|
|
198
|
+
kind: KIND.module,
|
|
199
|
+
fallbackName: entry.id,
|
|
200
|
+
}));
|
|
201
|
+
const moduleDependencies = own.flatMap((entry) => {
|
|
202
|
+
const manifest = manifestOf(entry.dir);
|
|
203
|
+
const names = manifest
|
|
204
|
+
? [...manifest.dependencies, ...manifest.optionalDependencies]
|
|
205
|
+
: [];
|
|
206
|
+
return dependencyCandidates(entry.dir, names, KIND.dependency, manifestOf);
|
|
207
|
+
});
|
|
208
|
+
const projectManifest = project === undefined ? null : manifestOf(project);
|
|
209
|
+
const projectDependencies =
|
|
210
|
+
project === undefined || projectManifest === null
|
|
211
|
+
? []
|
|
212
|
+
: dependencyCandidates(
|
|
213
|
+
project,
|
|
214
|
+
[
|
|
215
|
+
...projectManifest.dependencies,
|
|
216
|
+
...projectManifest.optionalDependencies,
|
|
217
|
+
...projectManifest.devDependencies,
|
|
218
|
+
],
|
|
219
|
+
KIND.project,
|
|
220
|
+
manifestOf,
|
|
221
|
+
);
|
|
222
|
+
const installedDirs = installed.map((dir) => ({
|
|
223
|
+
dir,
|
|
224
|
+
kind: KIND.installed,
|
|
225
|
+
fallbackName: undefined,
|
|
226
|
+
}));
|
|
227
|
+
return [
|
|
228
|
+
...own,
|
|
229
|
+
...moduleDependencies,
|
|
230
|
+
...projectDependencies,
|
|
231
|
+
...installedDirs,
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Collects the packages that ship agent skills, in priority order, one per
|
|
237
|
+
* package name: the first candidate to carry a name keeps it.
|
|
238
|
+
*
|
|
239
|
+
* The candidates, in order: the modules themselves, then the `installed`
|
|
240
|
+
* directories whose manifest sets `antelopeJs.implements`; the dependencies and
|
|
241
|
+
* optional dependencies of every module; the dependencies, optional
|
|
242
|
+
* dependencies and dev dependencies of `project`; the `installed` package
|
|
243
|
+
* directories. A candidate with a readable manifest and a name reserves that
|
|
244
|
+
* name even when it declares no skills, so the copy a runtime runs always hides
|
|
245
|
+
* an installed copy of the same package. A candidate without a usable name
|
|
246
|
+
* falls back to the module `id`, or to the dependency's own name, and is
|
|
247
|
+
* skipped when it has neither.
|
|
248
|
+
*
|
|
249
|
+
* Only packages with at least one skill directory are returned. A skill
|
|
250
|
+
* directory outside its package is dropped and reported through `onWarning`.
|
|
251
|
+
* Nothing here throws on a missing or malformed manifest.
|
|
252
|
+
* @param {import("./index.js").CollectSkillPackagesInput} input
|
|
253
|
+
* @returns {import("./index.js").SkillPackage[]}
|
|
254
|
+
*/
|
|
255
|
+
export function collectSkillPackages(input) {
|
|
256
|
+
const { onWarning = () => {} } = input;
|
|
257
|
+
/** @type {Map<string, Manifest | null>} */
|
|
258
|
+
const manifests = new Map();
|
|
259
|
+
/** @type {(dir: string) => Manifest | null} */
|
|
260
|
+
const manifestOf = (dir) => {
|
|
261
|
+
const known = manifests.get(dir);
|
|
262
|
+
if (known !== undefined) return known;
|
|
263
|
+
const read = readManifest(dir);
|
|
264
|
+
manifests.set(dir, read);
|
|
265
|
+
return read;
|
|
266
|
+
};
|
|
267
|
+
/** @type {Set<string>} */
|
|
268
|
+
const claimed = new Set();
|
|
269
|
+
/** @type {import("./index.js").SkillPackage[]} */
|
|
270
|
+
const found = [];
|
|
271
|
+
for (const { dir, kind, fallbackName } of candidatesOf(input, manifestOf)) {
|
|
272
|
+
const manifest = manifestOf(dir);
|
|
273
|
+
const name = manifest?.name ?? nonEmptyText(fallbackName);
|
|
274
|
+
if (manifest === null || name === undefined || claimed.has(name)) continue;
|
|
275
|
+
claimed.add(name);
|
|
276
|
+
const skillDirs = skillDirsOf({ name, dir, manifest }, onWarning);
|
|
277
|
+
if (skillDirs.length > 0)
|
|
278
|
+
found.push({ name, version: manifest.version, dir, skillDirs, kind });
|
|
279
|
+
}
|
|
280
|
+
return found;
|
|
281
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/agent-skills",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Finds the agent skills that AntelopeJS packages ship, so every tool that loads them sees the same ones.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent-skills",
|
|
7
|
+
"antelopejs",
|
|
8
|
+
"claude-code",
|
|
9
|
+
"codex"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/AntelopeJS/agent-skills/tree/main/plugin/packages/agent-skills#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/AntelopeJS/agent-skills/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/AntelopeJS/agent-skills.git",
|
|
19
|
+
"directory": "plugin/packages/agent-skills"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.mjs",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "index.mjs",
|
|
29
|
+
"types": "index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"default": "./index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true,
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"typecheck": "tsc -p .",
|
|
44
|
+
"release": "release-it"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^24.0.0",
|
|
48
|
+
"release-it": "^19.2.4",
|
|
49
|
+
"release-it-changelogen": "^0.1.0",
|
|
50
|
+
"typescript": "^6.0.3"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20.19"
|
|
54
|
+
}
|
|
55
|
+
}
|