@yaks/persona 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +401 -2
- package/_dist/comp.d.ts +13 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/effects.d.ts +22 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/mod.d.ts +40 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/name.d.ts +49 -0
- package/_dist/name.d.ts.map +1 -0
- package/_dist/owed.d.ts +56 -0
- package/_dist/owed.d.ts.map +1 -0
- package/_dist/part.d.ts +4 -0
- package/_dist/part.d.ts.map +1 -0
- package/_dist/shipped.d.ts +30 -0
- package/_dist/shipped.d.ts.map +1 -0
- package/_dist/skill-checkout.d.ts +6 -0
- package/_dist/skill-checkout.d.ts.map +1 -0
- package/_dist/skill-effects.d.ts +25 -0
- package/_dist/skill-effects.d.ts.map +1 -0
- package/_dist/skill-mirror-io.d.ts +7 -0
- package/_dist/skill-mirror-io.d.ts.map +1 -0
- package/_dist/skill-mirror.d.ts +15 -0
- package/_dist/skill-mirror.d.ts.map +1 -0
- package/_dist/skill-text.d.ts +28 -0
- package/_dist/skill-text.d.ts.map +1 -0
- package/_dist/skills.d.ts +22 -0
- package/_dist/skills.d.ts.map +1 -0
- package/_dist/tools.d.ts +9 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/ui.d.ts +6 -0
- package/_dist/ui.d.ts.map +1 -0
- package/_dist/views.d.ts +19 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/voice.d.ts +47 -0
- package/_dist/voice.d.ts.map +1 -0
- package/_dist/worn.d.ts +55 -0
- package/_dist/worn.d.ts.map +1 -0
- package/carried.js +201 -0
- package/carried.js.map +1 -0
- package/carried.ts +269 -0
- package/comp.js +31 -0
- package/comp.js.map +1 -0
- package/comp.ts +38 -0
- package/deno.json +1 -0
- package/desk.js +201 -0
- package/desk.js.map +1 -0
- package/desk.ts +301 -0
- package/effects.js +106 -0
- package/effects.js.map +1 -0
- package/effects.ts +120 -0
- package/files.js +305 -0
- package/files.js.map +1 -0
- package/files.ts +319 -0
- package/inspect.js +66 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +30 -0
- package/mod.js +40 -0
- package/mod.js.map +1 -0
- package/mod.ts +61 -0
- package/name.js +161 -0
- package/name.js.map +1 -0
- package/name.ts +184 -0
- package/owed.js +196 -0
- package/owed.js.map +1 -0
- package/owed.ts +256 -0
- package/package.json +83 -4
- package/part.js +4 -0
- package/part.js.map +1 -0
- package/part.ts +4 -0
- package/shipped.js +130 -0
- package/shipped.js.map +1 -0
- package/shipped.ts +131 -0
- package/skill-checkout.js +92 -0
- package/skill-checkout.js.map +1 -0
- package/skill-checkout.ts +121 -0
- package/skill-effects.js +244 -0
- package/skill-effects.js.map +1 -0
- package/skill-effects.ts +274 -0
- package/skill-mirror-io.js +193 -0
- package/skill-mirror-io.js.map +1 -0
- package/skill-mirror-io.ts +212 -0
- package/skill-mirror.js +659 -0
- package/skill-mirror.js.map +1 -0
- package/skill-mirror.ts +640 -0
- package/skill-text.js +158 -0
- package/skill-text.js.map +1 -0
- package/skill-text.ts +183 -0
- package/skills.js +238 -0
- package/skills.js.map +1 -0
- package/skills.ts +383 -0
- package/text.js +59 -0
- package/text.js.map +1 -0
- package/text.ts +60 -0
- package/tools.js +76 -0
- package/tools.js.map +1 -0
- package/tools.ts +91 -0
- package/ui.js +19 -0
- package/ui.js.map +1 -0
- package/ui.ts +34 -0
- package/views.js +27 -0
- package/views.js.map +1 -0
- package/views.ts +29 -0
- package/vocab.js +14 -0
- package/vocab.js.map +1 -0
- package/vocab.json +270 -0
- package/vocab.ts +16 -0
- package/voice.js +105 -0
- package/voice.js.map +1 -0
- package/voice.ts +133 -0
- package/worn.js +328 -0
- package/worn.js.map +1 -0
- package/worn.ts +336 -0
package/skill-text.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// A SKILL.md and its entity say the same thing: doc holds the folder name and
|
|
2
|
+
// description, content holds the instructions, and skill holds invocation and
|
|
3
|
+
// loading metadata. Only the frontmatter is interpreted here. The body is an
|
|
4
|
+
// opaque string: commands, file references and substitutions are never run.
|
|
5
|
+
import { parse, stringify, YamlSyntaxError } from "@yaks/yaml";
|
|
6
|
+
import { Refused } from "@yaks/graph/errors";
|
|
7
|
+
let object = (value)=>value != null && typeof value == 'object' && !Array.isArray(value) && (Object.getPrototypeOf(value) == Object.prototype || Object.getPrototypeOf(value) == null);
|
|
8
|
+
let folder = (value)=>{
|
|
9
|
+
if (typeof value != 'string' || !/^[a-z0-9][a-z0-9_-]*$/i.test(value)) {
|
|
10
|
+
throw new Refused('Unsafe skill folder name');
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
let description = (value)=>{
|
|
15
|
+
if (typeof value != 'string' || !value.trim()) {
|
|
16
|
+
throw new Refused('Skill description must be a non-empty string');
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
// Claude accepts these spellings as well as YAML booleans. Anything else is
|
|
21
|
+
// refused rather than turning a misspelled restriction into permission.
|
|
22
|
+
let boolean = (value, fallback, field)=>{
|
|
23
|
+
if (value === undefined) return fallback;
|
|
24
|
+
if (typeof value == 'boolean') return value;
|
|
25
|
+
if (typeof value != 'string' && typeof value != 'number') {
|
|
26
|
+
throw new Refused(`${field} must be a boolean`);
|
|
27
|
+
}
|
|
28
|
+
let word = String(value).toLowerCase();
|
|
29
|
+
if ([
|
|
30
|
+
'true',
|
|
31
|
+
'yes',
|
|
32
|
+
'on',
|
|
33
|
+
'1'
|
|
34
|
+
].includes(word)) return true;
|
|
35
|
+
if ([
|
|
36
|
+
'false',
|
|
37
|
+
'no',
|
|
38
|
+
'off',
|
|
39
|
+
'0'
|
|
40
|
+
].includes(word)) return false;
|
|
41
|
+
throw new Refused(`${field} must be a boolean`);
|
|
42
|
+
};
|
|
43
|
+
let strings = (value, field)=>{
|
|
44
|
+
if (value === undefined) return [];
|
|
45
|
+
if (!Array.isArray(value) || !value.every((v)=>typeof v == 'string')) {
|
|
46
|
+
throw new Refused(`${field} must be a string list`);
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
...value
|
|
50
|
+
];
|
|
51
|
+
};
|
|
52
|
+
let list = (value, field, separator)=>typeof value == 'string' ? value.split(separator).map((v)=>v.trim()).filter(Boolean) : strings(value, field);
|
|
53
|
+
let owned = new Set([
|
|
54
|
+
'name',
|
|
55
|
+
'description',
|
|
56
|
+
'disable-model-invocation',
|
|
57
|
+
'user-invocable',
|
|
58
|
+
'arguments',
|
|
59
|
+
'paths'
|
|
60
|
+
]);
|
|
61
|
+
/** Decode frontmatter, retaining every byte after the closing delimiter's
|
|
62
|
+
* line ending. An omitted name uses the folder; an explicit one must agree. */ export let parseSkill = (text, title)=>{
|
|
63
|
+
folder(title);
|
|
64
|
+
let opening = /^---[\t ]*\r?\n/.exec(text);
|
|
65
|
+
if (!opening) throw new Refused('Skill must start with YAML frontmatter');
|
|
66
|
+
let rest = text.slice(opening[0].length);
|
|
67
|
+
let closing = /^---[\t ]*(?:\r?\n|$)/m.exec(rest);
|
|
68
|
+
if (!closing) throw new Refused('Skill frontmatter has no closing delimiter');
|
|
69
|
+
let fields;
|
|
70
|
+
try {
|
|
71
|
+
fields = parse(rest.slice(0, closing.index));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// YAML syntax is authored input. Anything else is an unexpected parser
|
|
74
|
+
// failure and must reach the caller rather than look like a refusal.
|
|
75
|
+
if (!(error instanceof YamlSyntaxError)) throw error;
|
|
76
|
+
throw new Refused(`Invalid skill frontmatter: ${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
if (!object(fields)) throw new Refused('Skill frontmatter must be an object');
|
|
79
|
+
if ('name' in fields && fields.name !== title) {
|
|
80
|
+
throw new Refused('Skill frontmatter name must match its folder');
|
|
81
|
+
}
|
|
82
|
+
let body = description(fields.description);
|
|
83
|
+
let model = !boolean(fields['disable-model-invocation'], false, 'disable-model-invocation');
|
|
84
|
+
let user = boolean(fields['user-invocable'], true, 'user-invocable');
|
|
85
|
+
// The vocabulary has no "neither" invocation mode. Losing either restriction
|
|
86
|
+
// while importing would make an intentionally inaccessible skill callable.
|
|
87
|
+
if (!model && !user) {
|
|
88
|
+
throw new Refused('Skill disables both invocation modes');
|
|
89
|
+
}
|
|
90
|
+
let fork = fields.context === 'fork';
|
|
91
|
+
let options = Object.fromEntries(Object.entries(fields).filter(([key])=>!owned.has(key) && !(key == 'context' && fork)));
|
|
92
|
+
return {
|
|
93
|
+
doc: {
|
|
94
|
+
title,
|
|
95
|
+
body
|
|
96
|
+
},
|
|
97
|
+
content: {
|
|
98
|
+
body: rest.slice(closing.index + closing[0].length)
|
|
99
|
+
},
|
|
100
|
+
skill: {
|
|
101
|
+
invoke: model ? user ? 'both' : 'model' : 'user',
|
|
102
|
+
arguments: list(fields.arguments, 'arguments', /\s+/),
|
|
103
|
+
paths: list(fields.paths, 'paths', /,/),
|
|
104
|
+
fork,
|
|
105
|
+
options
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/** Claude frontmatter from the entity's canonical fields. Unknown options
|
|
110
|
+
* survive, but cannot override the name, description or invocation policy. */ export let frontmatter = (bundle)=>{
|
|
111
|
+
let doc = object(bundle.doc) ? bundle.doc : {};
|
|
112
|
+
let title = folder(doc.title);
|
|
113
|
+
let body = description(doc.body);
|
|
114
|
+
if (!object(bundle.skill)) {
|
|
115
|
+
throw new Refused('Skill component must be an object');
|
|
116
|
+
}
|
|
117
|
+
let skill = bundle.skill;
|
|
118
|
+
let invoke = skill.invoke === undefined ? 'both' : skill.invoke;
|
|
119
|
+
if (typeof invoke != 'string' || ![
|
|
120
|
+
'user',
|
|
121
|
+
'model',
|
|
122
|
+
'both'
|
|
123
|
+
].includes(invoke)) {
|
|
124
|
+
throw new Refused('Skill invoke must be user, model or both');
|
|
125
|
+
}
|
|
126
|
+
let options = skill.options === undefined ? {} : skill.options;
|
|
127
|
+
if (!object(options)) throw new Refused('Skill options must be an object');
|
|
128
|
+
let fork = skill.fork === undefined ? false : skill.fork;
|
|
129
|
+
if (typeof fork != 'boolean') {
|
|
130
|
+
throw new Refused('Skill fork must be a boolean');
|
|
131
|
+
}
|
|
132
|
+
let fields = {
|
|
133
|
+
name: title,
|
|
134
|
+
description: body,
|
|
135
|
+
...Object.fromEntries(Object.entries(options).filter(([k])=>!owned.has(k)))
|
|
136
|
+
};
|
|
137
|
+
if (invoke == 'user') fields['disable-model-invocation'] = true;
|
|
138
|
+
if (invoke == 'model') fields['user-invocable'] = false;
|
|
139
|
+
let args = strings(skill.arguments, 'arguments');
|
|
140
|
+
let paths = strings(skill.paths, 'paths');
|
|
141
|
+
if (args.length) fields.arguments = args;
|
|
142
|
+
if (paths.length) fields.paths = paths;
|
|
143
|
+
if (fork) fields.context = 'fork';
|
|
144
|
+
return fields;
|
|
145
|
+
};
|
|
146
|
+
/** Serialize only the header; append the instructions without normalizing
|
|
147
|
+
* whitespace, line endings, placeholders or a missing final newline. */ export let renderSkill = (bundle)=>{
|
|
148
|
+
let fields = frontmatter(bundle);
|
|
149
|
+
if (bundle.content !== undefined && !object(bundle.content)) {
|
|
150
|
+
throw new Refused('Skill content must be an object');
|
|
151
|
+
}
|
|
152
|
+
let body = object(bundle.content) ? bundle.content.body : '';
|
|
153
|
+
if (typeof body != 'string') {
|
|
154
|
+
throw new Refused('Skill content must be a string');
|
|
155
|
+
}
|
|
156
|
+
return `---\n${stringify(fields)}---\n${body}`;
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=skill-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-text.js","sources":["./skill-text.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E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OAAO,OAAO,CAAC,SAAS,MAAM,CAAC,CAAC,CAAC,EAAE,GAAK,CAAC,MAAM,GAAG,CAAC,IACpD;EACH;EACA,IAAI,UAAU,QAAQ,MAAM,CAAC,2BAA2B,GAAG;EAC3D,IAAI,UAAU,SAAS,MAAM,CAAC,iBAAiB,GAAG;EAClD,IAAI,OAAO,QAAQ,MAAM,SAAS,EAAE;EACpC,IAAI,QAAQ,QAAQ,MAAM,KAAK,EAAE;EACjC,IAAI,KAAK,MAAM,EAAE,OAAO,SAAS,GAAG;EACpC,IAAI,MAAM,MAAM,EAAE,OAAO,KAAK,GAAG;EACjC,IAAI,MAAM,OAAO,OAAO,GAAG;EAC3B,OAAO;AACT,EAAC;AAED;sEACsE,GACtE,OAAO,IAAI,cAAc,CAAC;EACxB,IAAI,SAAS,YAAY;EACzB,IAAI,OAAO,OAAO,KAAK,aAAa,CAAC,OAAO,OAAO,OAAO,GAAG;IAC3D,MAAM,IAAI,QAAQ;EACpB;EACA,IAAI,OAAO,OAAO,OAAO,OAAO,IAAI,OAAO,OAAO,CAAC,IAAI,GAAG;EAC1D,IAAI,OAAO,QAAQ,UAAU;IAC3B,MAAM,IAAI,QAAQ;EACpB;EACA,OAAO,CAAC,KAAK,EAAE,UAAU,QAAQ,KAAK,EAAE,MAAM;AAChD,EAAC"}
|
package/skill-text.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// A SKILL.md and its entity say the same thing: doc holds the folder name and
|
|
2
|
+
// description, content holds the instructions, and skill holds invocation and
|
|
3
|
+
// loading metadata. Only the frontmatter is interpreted here. The body is an
|
|
4
|
+
// opaque string: commands, file references and substitutions are never run.
|
|
5
|
+
|
|
6
|
+
import { parse, stringify, YamlSyntaxError } from '@yaks/yaml'
|
|
7
|
+
import { Refused } from '@yaks/graph/errors'
|
|
8
|
+
|
|
9
|
+
/** The normalized parts of a skill, without an entity id or graph effects. */
|
|
10
|
+
export type SkillText = {
|
|
11
|
+
doc: { title: string; body: string }
|
|
12
|
+
content: { body: string }
|
|
13
|
+
skill: {
|
|
14
|
+
invoke: 'user' | 'model' | 'both'
|
|
15
|
+
arguments: string[]
|
|
16
|
+
paths: string[]
|
|
17
|
+
fork: boolean
|
|
18
|
+
options: Record<string, unknown>
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type SkillBundle = { doc?: unknown; content?: unknown; skill?: unknown }
|
|
23
|
+
|
|
24
|
+
let object = (value: unknown): value is Record<string, unknown> =>
|
|
25
|
+
value != null && typeof value == 'object' && !Array.isArray(value) &&
|
|
26
|
+
(Object.getPrototypeOf(value) == Object.prototype ||
|
|
27
|
+
Object.getPrototypeOf(value) == null)
|
|
28
|
+
|
|
29
|
+
let folder = (value: unknown): string => {
|
|
30
|
+
if (typeof value != 'string' || !/^[a-z0-9][a-z0-9_-]*$/i.test(value)) {
|
|
31
|
+
throw new Refused('Unsafe skill folder name')
|
|
32
|
+
}
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let description = (value: unknown): string => {
|
|
37
|
+
if (typeof value != 'string' || !value.trim()) {
|
|
38
|
+
throw new Refused('Skill description must be a non-empty string')
|
|
39
|
+
}
|
|
40
|
+
return value
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Claude accepts these spellings as well as YAML booleans. Anything else is
|
|
44
|
+
// refused rather than turning a misspelled restriction into permission.
|
|
45
|
+
let boolean = (value: unknown, fallback: boolean, field: string): boolean => {
|
|
46
|
+
if (value === undefined) return fallback
|
|
47
|
+
if (typeof value == 'boolean') return value
|
|
48
|
+
if (typeof value != 'string' && typeof value != 'number') {
|
|
49
|
+
throw new Refused(`${field} must be a boolean`)
|
|
50
|
+
}
|
|
51
|
+
let word = String(value).toLowerCase()
|
|
52
|
+
if (['true', 'yes', 'on', '1'].includes(word)) return true
|
|
53
|
+
if (['false', 'no', 'off', '0'].includes(word)) return false
|
|
54
|
+
throw new Refused(`${field} must be a boolean`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let strings = (value: unknown, field: string): string[] => {
|
|
58
|
+
if (value === undefined) return []
|
|
59
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v == 'string')) {
|
|
60
|
+
throw new Refused(`${field} must be a string list`)
|
|
61
|
+
}
|
|
62
|
+
return [...value]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let list = (value: unknown, field: string, separator: RegExp): string[] =>
|
|
66
|
+
typeof value == 'string'
|
|
67
|
+
? value.split(separator).map((v) => v.trim()).filter(Boolean)
|
|
68
|
+
: strings(value, field)
|
|
69
|
+
|
|
70
|
+
let owned = new Set([
|
|
71
|
+
'name',
|
|
72
|
+
'description',
|
|
73
|
+
'disable-model-invocation',
|
|
74
|
+
'user-invocable',
|
|
75
|
+
'arguments',
|
|
76
|
+
'paths',
|
|
77
|
+
])
|
|
78
|
+
|
|
79
|
+
/** Decode frontmatter, retaining every byte after the closing delimiter's
|
|
80
|
+
* line ending. An omitted name uses the folder; an explicit one must agree. */
|
|
81
|
+
export let parseSkill = (text: string, title: string): SkillText => {
|
|
82
|
+
folder(title)
|
|
83
|
+
let opening = /^---[\t ]*\r?\n/.exec(text)
|
|
84
|
+
if (!opening) throw new Refused('Skill must start with YAML frontmatter')
|
|
85
|
+
let rest = text.slice(opening[0].length)
|
|
86
|
+
let closing = /^---[\t ]*(?:\r?\n|$)/m.exec(rest)
|
|
87
|
+
if (!closing) throw new Refused('Skill frontmatter has no closing delimiter')
|
|
88
|
+
let fields: unknown
|
|
89
|
+
try {
|
|
90
|
+
fields = parse(rest.slice(0, closing.index))
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// YAML syntax is authored input. Anything else is an unexpected parser
|
|
93
|
+
// failure and must reach the caller rather than look like a refusal.
|
|
94
|
+
if (!(error instanceof YamlSyntaxError)) throw error
|
|
95
|
+
throw new Refused(`Invalid skill frontmatter: ${error.message}`)
|
|
96
|
+
}
|
|
97
|
+
if (!object(fields)) throw new Refused('Skill frontmatter must be an object')
|
|
98
|
+
if ('name' in fields && fields.name !== title) {
|
|
99
|
+
throw new Refused('Skill frontmatter name must match its folder')
|
|
100
|
+
}
|
|
101
|
+
let body = description(fields.description)
|
|
102
|
+
let model = !boolean(
|
|
103
|
+
fields['disable-model-invocation'],
|
|
104
|
+
false,
|
|
105
|
+
'disable-model-invocation',
|
|
106
|
+
)
|
|
107
|
+
let user = boolean(fields['user-invocable'], true, 'user-invocable')
|
|
108
|
+
// The vocabulary has no "neither" invocation mode. Losing either restriction
|
|
109
|
+
// while importing would make an intentionally inaccessible skill callable.
|
|
110
|
+
if (!model && !user) {
|
|
111
|
+
throw new Refused('Skill disables both invocation modes')
|
|
112
|
+
}
|
|
113
|
+
let fork = fields.context === 'fork'
|
|
114
|
+
let options = Object.fromEntries(
|
|
115
|
+
Object.entries(fields).filter(([key]) =>
|
|
116
|
+
!owned.has(key) && !(key == 'context' && fork)
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
return {
|
|
120
|
+
doc: { title, body },
|
|
121
|
+
content: { body: rest.slice(closing.index + closing[0].length) },
|
|
122
|
+
skill: {
|
|
123
|
+
invoke: model ? (user ? 'both' : 'model') : 'user',
|
|
124
|
+
arguments: list(fields.arguments, 'arguments', /\s+/),
|
|
125
|
+
paths: list(fields.paths, 'paths', /,/),
|
|
126
|
+
fork,
|
|
127
|
+
options,
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Claude frontmatter from the entity's canonical fields. Unknown options
|
|
133
|
+
* survive, but cannot override the name, description or invocation policy. */
|
|
134
|
+
export let frontmatter = (bundle: SkillBundle): Record<string, unknown> => {
|
|
135
|
+
let doc = object(bundle.doc) ? bundle.doc : {}
|
|
136
|
+
let title = folder(doc.title)
|
|
137
|
+
let body = description(doc.body)
|
|
138
|
+
if (!object(bundle.skill)) {
|
|
139
|
+
throw new Refused('Skill component must be an object')
|
|
140
|
+
}
|
|
141
|
+
let skill = bundle.skill
|
|
142
|
+
let invoke = skill.invoke === undefined ? 'both' : skill.invoke
|
|
143
|
+
if (
|
|
144
|
+
typeof invoke != 'string' || !['user', 'model', 'both'].includes(invoke)
|
|
145
|
+
) {
|
|
146
|
+
throw new Refused('Skill invoke must be user, model or both')
|
|
147
|
+
}
|
|
148
|
+
let options = skill.options === undefined ? {} : skill.options
|
|
149
|
+
if (!object(options)) throw new Refused('Skill options must be an object')
|
|
150
|
+
let fork = skill.fork === undefined ? false : skill.fork
|
|
151
|
+
if (typeof fork != 'boolean') {
|
|
152
|
+
throw new Refused('Skill fork must be a boolean')
|
|
153
|
+
}
|
|
154
|
+
let fields: Record<string, unknown> = {
|
|
155
|
+
name: title,
|
|
156
|
+
description: body,
|
|
157
|
+
...Object.fromEntries(
|
|
158
|
+
Object.entries(options).filter(([k]) => !owned.has(k)),
|
|
159
|
+
),
|
|
160
|
+
}
|
|
161
|
+
if (invoke == 'user') fields['disable-model-invocation'] = true
|
|
162
|
+
if (invoke == 'model') fields['user-invocable'] = false
|
|
163
|
+
let args = strings(skill.arguments, 'arguments')
|
|
164
|
+
let paths = strings(skill.paths, 'paths')
|
|
165
|
+
if (args.length) fields.arguments = args
|
|
166
|
+
if (paths.length) fields.paths = paths
|
|
167
|
+
if (fork) fields.context = 'fork'
|
|
168
|
+
return fields
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Serialize only the header; append the instructions without normalizing
|
|
172
|
+
* whitespace, line endings, placeholders or a missing final newline. */
|
|
173
|
+
export let renderSkill = (bundle: SkillBundle): string => {
|
|
174
|
+
let fields = frontmatter(bundle)
|
|
175
|
+
if (bundle.content !== undefined && !object(bundle.content)) {
|
|
176
|
+
throw new Refused('Skill content must be an object')
|
|
177
|
+
}
|
|
178
|
+
let body = object(bundle.content) ? bundle.content.body : ''
|
|
179
|
+
if (typeof body != 'string') {
|
|
180
|
+
throw new Refused('Skill content must be a string')
|
|
181
|
+
}
|
|
182
|
+
return `---\n${stringify(fields)}---\n${body}`
|
|
183
|
+
}
|
package/skills.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// Graph reads of skills, pure over the graph: a checkout's working-tree view
|
|
2
|
+
// is ./skill-checkout.ts, so a host with no filesystem reads skills here.
|
|
3
|
+
import { Refused } from "@yaks/graph/errors";
|
|
4
|
+
import { and, contains, eq, every, fields, list, present } from "@yaks/query";
|
|
5
|
+
import { SKILL } from "./comp.js";
|
|
6
|
+
import { renderSkill } from "./skill-text.js";
|
|
7
|
+
let component = (b, name)=>{
|
|
8
|
+
let value = b[name];
|
|
9
|
+
return value && typeof value == 'object' && !Array.isArray(value) ? value : {};
|
|
10
|
+
};
|
|
11
|
+
let text = (b, name, prop)=>{
|
|
12
|
+
let value = component(b, name)[prop];
|
|
13
|
+
return typeof value == 'string' ? value : undefined;
|
|
14
|
+
};
|
|
15
|
+
/** Whether a title can name a skill's folder. */ export let folder = (title)=>/^[a-z0-9][a-z0-9_-]*$/i.test(title);
|
|
16
|
+
/** Where a skill titled `title` lives in a repository. */ export let pathOf = (title)=>`.claude/skills/${title}/SKILL.md`;
|
|
17
|
+
let primary = (path)=>/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/SKILL\.md$/i.test(path);
|
|
18
|
+
/** Skills in title order. */ export let sorted = (skills)=>skills.sort((a, b)=>(text(a, 'doc', 'title') ?? '').localeCompare(text(b, 'doc', 'title') ?? ''));
|
|
19
|
+
let rendered = (b)=>renderSkill({
|
|
20
|
+
doc: b.doc,
|
|
21
|
+
skill: b.skill,
|
|
22
|
+
content: b.content
|
|
23
|
+
});
|
|
24
|
+
let shaped = (b)=>{
|
|
25
|
+
let title = text(b, 'doc', 'title');
|
|
26
|
+
if (b.file || title == undefined || !folder(title) || text(b, 'doc', 'body') == undefined || text(b, 'content', 'body') == undefined) return false;
|
|
27
|
+
try {
|
|
28
|
+
rendered(b);
|
|
29
|
+
return true;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// Authored metadata can be incomplete; programming and I/O errors escape.
|
|
32
|
+
if (!(error instanceof Refused)) throw error;
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** Resolve referenced SKILL.md entities together. A locator may still name
|
|
37
|
+
* the old folder while a graph rename is waiting to be materialized. */ let skillSites = async (g, skills)=>{
|
|
38
|
+
let locations = new Map();
|
|
39
|
+
let links = new Map();
|
|
40
|
+
let result = {
|
|
41
|
+
places: locations,
|
|
42
|
+
links
|
|
43
|
+
};
|
|
44
|
+
if (!g.vocab.comps.includes('references') || !g.vocab.comps.includes('file')) return result;
|
|
45
|
+
let ids = skills.map((b)=>typeof b == 'string' ? b : b.entity.eid);
|
|
46
|
+
if (!ids.length) return result;
|
|
47
|
+
let edges = await g.read(and(present('references'), eq('edge.from', list(...ids)), every()));
|
|
48
|
+
let targets = new Map();
|
|
49
|
+
let remember = (from, b)=>{
|
|
50
|
+
if (!links.has(from)) links.set(from, []);
|
|
51
|
+
links.get(from).push(b);
|
|
52
|
+
let to = text(b, 'edge', 'to');
|
|
53
|
+
if (!to) return;
|
|
54
|
+
if (!targets.has(from)) targets.set(from, new Set());
|
|
55
|
+
targets.get(from).add(to);
|
|
56
|
+
};
|
|
57
|
+
// A reader may mask the source property after filtering by it. In that
|
|
58
|
+
// case the individual predicate supplies the identity we cannot read.
|
|
59
|
+
if (edges.some((b)=>!text(b, 'edge', 'from'))) {
|
|
60
|
+
for (let eid of ids){
|
|
61
|
+
for (let b of (await g.read(and(present('references'), eq('edge.from', eid), every()))))remember(eid, b);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
for (let b of edges)remember(text(b, 'edge', 'from'), b);
|
|
65
|
+
}
|
|
66
|
+
let eids = [
|
|
67
|
+
...new Set([
|
|
68
|
+
...targets.values()
|
|
69
|
+
].flatMap((ids)=>[
|
|
70
|
+
...ids
|
|
71
|
+
]))
|
|
72
|
+
];
|
|
73
|
+
let files = eids.length ? await g.get(eids, [
|
|
74
|
+
'file'
|
|
75
|
+
]) : [];
|
|
76
|
+
let index = new Map(files.filter((b)=>{
|
|
77
|
+
let path = text(b, 'file', 'path');
|
|
78
|
+
return !!text(b, 'file', 'root') && !!path && primary(path);
|
|
79
|
+
}).map((b)=>[
|
|
80
|
+
b.entity.eid,
|
|
81
|
+
b
|
|
82
|
+
]));
|
|
83
|
+
for (let eid of ids){
|
|
84
|
+
let found = [
|
|
85
|
+
...targets.get(eid) ?? []
|
|
86
|
+
].map((id)=>index.get(id)).filter((b)=>b != undefined);
|
|
87
|
+
if (found.length > 1) {
|
|
88
|
+
throw new Refused(`Skill ${eid} references more than one SKILL.md`);
|
|
89
|
+
}
|
|
90
|
+
if (found[0]) locations.set(eid, found[0]);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
export let skillLocations = async (g, skills)=>(await skillSites(g, skills)).places;
|
|
95
|
+
export let skillLocation = async (g, skill)=>(await skillLocations(g, [
|
|
96
|
+
skill
|
|
97
|
+
])).get(typeof skill == 'string' ? skill : skill.entity.eid);
|
|
98
|
+
let inRepo = async (g, skills, repository)=>{
|
|
99
|
+
if (repository == undefined) return skills;
|
|
100
|
+
if (![
|
|
101
|
+
'file',
|
|
102
|
+
'references'
|
|
103
|
+
].every((name)=>g.vocab.comps.includes(name))) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
if (!skills.length) return [];
|
|
107
|
+
let edges = await g.read(and(present('references'), eq('edge.from', list(...skills.map((b)=>b.entity.eid))), fields('edge.from', 'edge.to')));
|
|
108
|
+
let targets = edges.map((b)=>text(b, 'edge', 'to')).filter((id)=>id != undefined);
|
|
109
|
+
let files = targets.length ? await g.get([
|
|
110
|
+
...new Set(targets)
|
|
111
|
+
], [
|
|
112
|
+
'file'
|
|
113
|
+
]) : [];
|
|
114
|
+
let locations = new Set(files.filter((b)=>text(b, 'file', 'root') == repository && primary(text(b, 'file', 'path') ?? '')).map((b)=>b.entity.eid));
|
|
115
|
+
let linked = new Set(edges.filter((b)=>locations.has(text(b, 'edge', 'to') ?? '')).map((b)=>text(b, 'edge', 'from')));
|
|
116
|
+
return skills.filter((b)=>linked.has(b.entity.eid));
|
|
117
|
+
};
|
|
118
|
+
/** Discover descriptions without reading instruction bodies. */ export let skillCatalog = async (g, repository)=>{
|
|
119
|
+
if (!g.vocab.comps.includes(SKILL)) return [];
|
|
120
|
+
return sorted(await inRepo(g, (await g.read(and(present(SKILL), present('doc.title'), present('doc.body'), present('content.body'), fields('entity.eid', 'doc.title', 'doc.body', 'skill.invoke')))).filter((b)=>folder(text(b, 'doc', 'title') ?? '') && !!text(b, 'doc', 'body')?.trim()), repository));
|
|
121
|
+
};
|
|
122
|
+
/** Exact graph instructions, optionally limited to one repository. */ export let graphSkill = async (g, title, repository)=>{
|
|
123
|
+
let found = await inRepo(g, (await g.read(and(present(SKILL), eq('doc.title', title), every()))).filter(shaped), repository);
|
|
124
|
+
if (!found.length) throw new Refused(`No skill named ${title}`);
|
|
125
|
+
if (found.length > 1) {
|
|
126
|
+
throw new Refused(`Skill ${title} belongs to more than one repository`);
|
|
127
|
+
}
|
|
128
|
+
return found[0];
|
|
129
|
+
};
|
|
130
|
+
/** Complete skills and their locators for one repository. Other repositories
|
|
131
|
+
* supply no bodies; every selected skill still has its full locator checked.
|
|
132
|
+
* Companions include file contents in the same repository read for a mirror. */ export let skillScope = async (g, repository, companions = false)=>{
|
|
133
|
+
let places = new Map();
|
|
134
|
+
if (![
|
|
135
|
+
SKILL,
|
|
136
|
+
'references',
|
|
137
|
+
'file'
|
|
138
|
+
].every((c)=>g.vocab.comps.includes(c))) {
|
|
139
|
+
return {
|
|
140
|
+
skills: [],
|
|
141
|
+
places,
|
|
142
|
+
edges: [],
|
|
143
|
+
files: []
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
let rows = companions ? await g.read(and(present('file'), eq('file.root', repository), contains('file.path', '.claude/skills/'), fields('file.path', 'file.root', 'content.body'))) : await g.read(and(present('references'), eq('edge.to.file.root', repository), contains('edge.to.file.path', '.claude/skills/'), fields('edge.from', 'edge.to', 'edge.to.file.path')));
|
|
147
|
+
let files = new Set(rows.filter((b)=>primary(text(b, 'file', 'path') ?? '')).map((b)=>b.entity.eid));
|
|
148
|
+
let links = companions ? files.size ? await g.read(and(present('references'), eq('edge.to', list(...files)), fields('edge.from', 'edge.to'))) : [] : rows.filter((b)=>files.has(text(b, 'edge', 'to') ?? ''));
|
|
149
|
+
let ids = new Set(links.map((b)=>text(b, 'edge', 'from')).filter((id)=>id != undefined));
|
|
150
|
+
// A post-read mask may hide the source while leaving its target visible.
|
|
151
|
+
// Use the predicate's identity, as skillLocations does for the same mask.
|
|
152
|
+
if (links.some((b)=>!text(b, 'edge', 'from'))) {
|
|
153
|
+
for (let b of (await g.read(and(present(SKILL), fields('entity.eid'))))){
|
|
154
|
+
let from = b.entity.eid;
|
|
155
|
+
let linked = await g.read(and(present('references'), eq('edge.from', from), eq('edge.to', list(...files)), fields('edge.to')));
|
|
156
|
+
if (linked.some((b)=>files.has(text(b, 'edge', 'to') ?? ''))) {
|
|
157
|
+
ids.add(from);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let skills = ids.size ? (await g.read(and(present(SKILL), eq('entity.eid', list(...ids)), every()))).filter(shaped) : [];
|
|
162
|
+
let sites = await skillSites(g, skills);
|
|
163
|
+
places = sites.places;
|
|
164
|
+
skills = sorted(skills.filter((b)=>{
|
|
165
|
+
let location = places.get(b.entity.eid);
|
|
166
|
+
return location && text(location, 'file', 'root') == repository;
|
|
167
|
+
}));
|
|
168
|
+
return {
|
|
169
|
+
skills,
|
|
170
|
+
places,
|
|
171
|
+
files: companions ? rows : [],
|
|
172
|
+
edges: skills.flatMap((b)=>sites.links.get(b.entity.eid) ?? [])
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
/** Complete graph skills. Unlinked skills are visible without a repository,
|
|
176
|
+
* but cannot be exported or attributed to a repository until linked. */ export let repoSkills = async (g, repository)=>{
|
|
177
|
+
if (repository != undefined) return (await skillScope(g, repository)).skills;
|
|
178
|
+
if (!g.vocab.comps.includes(SKILL)) return [];
|
|
179
|
+
return sorted((await g.read(and(present(SKILL), every()))).filter(shaped));
|
|
180
|
+
};
|
|
181
|
+
// Paths are portable repository-relative names, not host paths. Reject both
|
|
182
|
+
// separators and all dot segments before a mirror ever joins them to a root.
|
|
183
|
+
let relative = (path)=>!path.includes('\\') && [
|
|
184
|
+
...path
|
|
185
|
+
].every((char)=>{
|
|
186
|
+
let code = char.charCodeAt(0);
|
|
187
|
+
return code >= 32 && code != 127;
|
|
188
|
+
}) && !path.includes(':') && path.split('/').every((part)=>!!part && part != '.' && part != '..');
|
|
189
|
+
/** Render one read's skills and locators together, including pending renames. */ export let renderFiles = (skills, locations, supports)=>{
|
|
190
|
+
let files = new Map();
|
|
191
|
+
let dirs = new Map();
|
|
192
|
+
let put = (path, body)=>{
|
|
193
|
+
if (files.has(path)) {
|
|
194
|
+
throw new Refused(`More than one skill file targets ${path}`);
|
|
195
|
+
}
|
|
196
|
+
files.set(path, body);
|
|
197
|
+
};
|
|
198
|
+
// The locator keeps the old folder until the mirror lands a rename. Move
|
|
199
|
+
// companions with their skill, keeping every suffix beneath that folder.
|
|
200
|
+
for (let skill of skills){
|
|
201
|
+
let title = text(skill, 'doc', 'title');
|
|
202
|
+
let to = `.claude/skills/${title}/`;
|
|
203
|
+
put(pathOf(title), rendered(skill));
|
|
204
|
+
let location = locations.get(skill.entity.eid);
|
|
205
|
+
let path = location && text(location, 'file', 'path');
|
|
206
|
+
if (path) {
|
|
207
|
+
let from = path.slice(0, -'SKILL.md'.length);
|
|
208
|
+
if (dirs.has(from)) throw new Refused(`More than one skill owns ${from}`);
|
|
209
|
+
dirs.set(from, to);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Files already at the destination can coexist with a pending rename only
|
|
213
|
+
// when they do not overwrite another companion. Locator ownership wins
|
|
214
|
+
// when two skills swap names.
|
|
215
|
+
for (let skill of skills){
|
|
216
|
+
let dir = `.claude/skills/${text(skill, 'doc', 'title')}/`;
|
|
217
|
+
if (!dirs.has(dir)) dirs.set(dir, dir);
|
|
218
|
+
}
|
|
219
|
+
if (!skills.length) return files;
|
|
220
|
+
for (let b of supports.toSorted((a, b)=>(text(a, 'file', 'path') ?? '').localeCompare(text(b, 'file', 'path') ?? ''))){
|
|
221
|
+
let path = text(b, 'file', 'path');
|
|
222
|
+
let body = text(b, 'content', 'body');
|
|
223
|
+
if (!path || body == undefined || !relative(path)) continue;
|
|
224
|
+
for (let [from, to] of dirs){
|
|
225
|
+
if (!path.startsWith(from)) continue;
|
|
226
|
+
put(`${to}${path.slice(from.length)}`, body);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return files;
|
|
231
|
+
};
|
|
232
|
+
/** The skill documents and text supporting files the graph owns. */ export let skillFiles = async (g, repository)=>{
|
|
233
|
+
let { skills, places, files } = await skillScope(g, repository, true);
|
|
234
|
+
return renderFiles(skills, places, files);
|
|
235
|
+
};
|
|
236
|
+
// The portable codec is shared by MCP manifests and repository views.
|
|
237
|
+
export { frontmatter, parseSkill, renderSkill } from "./skill-text.js";
|
|
238
|
+
//# sourceMappingURL=skills.js.map
|
package/skills.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","sources":["./skills.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAG1E,SAAS,OAAO,kCAAuC;AACvD,SAAS,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,2BAAgC;AACxF,SAAS,KAAK,oBAAmB;AACjC,SAAS,WAAW,0BAAyB;AAE7C,IAAI,YAAY,CAAC,GAAW;EAC1B,IAAI,QAAQ,CAAC,CAAC,KAAK;EACnB,OAAO,SAAS,OAAO,SAAS,YAAY,CAAC,MAAM,OAAO,CAAC,SACvD,QACA,CAAC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