@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/skills.ts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
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
|
+
|
|
4
|
+
import type { Bundle, Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
5
|
+
import { Refused } from '@yaks/graph/errors'
|
|
6
|
+
import { and, contains, eq, every, fields, list, present } from '@yaks/query'
|
|
7
|
+
import { SKILL } from './comp.js'
|
|
8
|
+
import { renderSkill } from './skill-text.js'
|
|
9
|
+
|
|
10
|
+
let component = (b: Bundle, name: string): Comp => {
|
|
11
|
+
let value = b[name]
|
|
12
|
+
return value && typeof value == 'object' && !Array.isArray(value)
|
|
13
|
+
? value as Comp
|
|
14
|
+
: {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let text = (b: Bundle, name: string, prop: string): string | undefined => {
|
|
18
|
+
let value = component(b, name)[prop]
|
|
19
|
+
return typeof value == 'string' ? value : undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Whether a title can name a skill's folder. */
|
|
23
|
+
export let folder = (title: string): boolean =>
|
|
24
|
+
/^[a-z0-9][a-z0-9_-]*$/i.test(title)
|
|
25
|
+
/** Where a skill titled `title` lives in a repository. */
|
|
26
|
+
export let pathOf = (title: string): string =>
|
|
27
|
+
`.claude/skills/${title}/SKILL.md`
|
|
28
|
+
let primary = (path: string): boolean =>
|
|
29
|
+
/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/SKILL\.md$/i.test(path)
|
|
30
|
+
/** Skills in title order. */
|
|
31
|
+
export let sorted = (skills: Bundle[]): Bundle[] =>
|
|
32
|
+
skills.sort((a, b) =>
|
|
33
|
+
(text(a, 'doc', 'title') ?? '').localeCompare(text(b, 'doc', 'title') ?? '')
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
let rendered = (b: Bundle): string =>
|
|
37
|
+
renderSkill({ doc: b.doc, skill: b.skill, content: b.content })
|
|
38
|
+
|
|
39
|
+
let shaped = (b: Bundle): boolean => {
|
|
40
|
+
let title = text(b, 'doc', 'title')
|
|
41
|
+
if (
|
|
42
|
+
b.file || title == undefined || !folder(title) ||
|
|
43
|
+
text(b, 'doc', 'body') == undefined ||
|
|
44
|
+
text(b, 'content', 'body') == undefined
|
|
45
|
+
) return false
|
|
46
|
+
try {
|
|
47
|
+
rendered(b)
|
|
48
|
+
return true
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// Authored metadata can be incomplete; programming and I/O errors escape.
|
|
51
|
+
if (!(error instanceof Refused)) throw error
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Resolve referenced SKILL.md entities together. A locator may still name
|
|
57
|
+
* the old folder while a graph rename is waiting to be materialized. */
|
|
58
|
+
let skillSites = async (
|
|
59
|
+
g: Graph,
|
|
60
|
+
skills: (Bundle | string)[],
|
|
61
|
+
): Promise<{ places: Map<string, Bundle>; links: Map<string, Bundle[]> }> => {
|
|
62
|
+
let locations = new Map<string, Bundle>()
|
|
63
|
+
let links = new Map<string, Bundle[]>()
|
|
64
|
+
let result = { places: locations, links }
|
|
65
|
+
if (
|
|
66
|
+
!g.vocab.comps.includes('references') || !g.vocab.comps.includes('file')
|
|
67
|
+
) return result
|
|
68
|
+
let ids = skills.map((b) => typeof b == 'string' ? b : b.entity.eid)
|
|
69
|
+
if (!ids.length) return result
|
|
70
|
+
let edges = await g.read(and(
|
|
71
|
+
present('references'),
|
|
72
|
+
eq('edge.from', list(...ids)),
|
|
73
|
+
every(),
|
|
74
|
+
))
|
|
75
|
+
let targets = new Map<string, Set<string>>()
|
|
76
|
+
let remember = (from: string, b: Bundle) => {
|
|
77
|
+
if (!links.has(from)) links.set(from, [])
|
|
78
|
+
links.get(from)!.push(b)
|
|
79
|
+
let to = text(b, 'edge', 'to')
|
|
80
|
+
if (!to) return
|
|
81
|
+
if (!targets.has(from)) targets.set(from, new Set())
|
|
82
|
+
targets.get(from)!.add(to)
|
|
83
|
+
}
|
|
84
|
+
// A reader may mask the source property after filtering by it. In that
|
|
85
|
+
// case the individual predicate supplies the identity we cannot read.
|
|
86
|
+
if (edges.some((b) => !text(b, 'edge', 'from'))) {
|
|
87
|
+
for (let eid of ids) {
|
|
88
|
+
for (
|
|
89
|
+
let b of await g.read(and(
|
|
90
|
+
present('references'),
|
|
91
|
+
eq('edge.from', eid),
|
|
92
|
+
every(),
|
|
93
|
+
))
|
|
94
|
+
) remember(eid, b)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
for (let b of edges) remember(text(b, 'edge', 'from')!, b)
|
|
98
|
+
}
|
|
99
|
+
let eids = [...new Set([...targets.values()].flatMap((ids) => [...ids]))]
|
|
100
|
+
let files = eids.length ? await g.get(eids, ['file']) : []
|
|
101
|
+
let index = new Map(
|
|
102
|
+
files.filter((b) => {
|
|
103
|
+
let path = text(b, 'file', 'path')
|
|
104
|
+
return !!text(b, 'file', 'root') &&
|
|
105
|
+
!!path &&
|
|
106
|
+
primary(path)
|
|
107
|
+
}).map((b) => [b.entity.eid, b]),
|
|
108
|
+
)
|
|
109
|
+
for (let eid of ids) {
|
|
110
|
+
let found = [...targets.get(eid) ?? []].map((id) => index.get(id))
|
|
111
|
+
.filter((b): b is Bundle => b != undefined)
|
|
112
|
+
if (found.length > 1) {
|
|
113
|
+
throw new Refused(`Skill ${eid} references more than one SKILL.md`)
|
|
114
|
+
}
|
|
115
|
+
if (found[0]) locations.set(eid, found[0])
|
|
116
|
+
}
|
|
117
|
+
return result
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export let skillLocations = async (
|
|
121
|
+
g: Graph,
|
|
122
|
+
skills: (Bundle | string)[],
|
|
123
|
+
): Promise<Map<string, Bundle>> => (await skillSites(g, skills)).places
|
|
124
|
+
|
|
125
|
+
export let skillLocation = async (
|
|
126
|
+
g: Graph,
|
|
127
|
+
skill: Bundle | string,
|
|
128
|
+
): Promise<Bundle | undefined> =>
|
|
129
|
+
(await skillLocations(g, [skill])).get(
|
|
130
|
+
typeof skill == 'string' ? skill : skill.entity.eid,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
let inRepo = async (
|
|
134
|
+
g: Graph,
|
|
135
|
+
skills: Bundle[],
|
|
136
|
+
repository?: string,
|
|
137
|
+
): Promise<Bundle[]> => {
|
|
138
|
+
if (repository == undefined) return skills
|
|
139
|
+
if (!['file', 'references'].every((name) => g.vocab.comps.includes(name))) {
|
|
140
|
+
return []
|
|
141
|
+
}
|
|
142
|
+
if (!skills.length) return []
|
|
143
|
+
let edges = await g.read(and(
|
|
144
|
+
present('references'),
|
|
145
|
+
eq('edge.from', list(...skills.map((b) => b.entity.eid))),
|
|
146
|
+
fields('edge.from', 'edge.to'),
|
|
147
|
+
))
|
|
148
|
+
let targets = edges.map((b) => text(b, 'edge', 'to'))
|
|
149
|
+
.filter((id): id is string => id != undefined)
|
|
150
|
+
let files = targets.length ? await g.get([...new Set(targets)], ['file']) : []
|
|
151
|
+
let locations = new Set(
|
|
152
|
+
files.filter((b) =>
|
|
153
|
+
text(b, 'file', 'root') == repository &&
|
|
154
|
+
primary(
|
|
155
|
+
text(b, 'file', 'path') ?? '',
|
|
156
|
+
)
|
|
157
|
+
).map((b) => b.entity.eid),
|
|
158
|
+
)
|
|
159
|
+
let linked = new Set(
|
|
160
|
+
edges.filter((b) => locations.has(text(b, 'edge', 'to') ?? '')).map((b) =>
|
|
161
|
+
text(b, 'edge', 'from')
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
return skills.filter((b) => linked.has(b.entity.eid))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Discover descriptions without reading instruction bodies. */
|
|
168
|
+
export let skillCatalog = async (
|
|
169
|
+
g: Graph,
|
|
170
|
+
repository?: string,
|
|
171
|
+
): Promise<Bundle[]> => {
|
|
172
|
+
if (!g.vocab.comps.includes(SKILL)) return []
|
|
173
|
+
return sorted(
|
|
174
|
+
await inRepo(
|
|
175
|
+
g,
|
|
176
|
+
(await g.read(and(
|
|
177
|
+
present(SKILL),
|
|
178
|
+
present('doc.title'),
|
|
179
|
+
present('doc.body'),
|
|
180
|
+
present('content.body'),
|
|
181
|
+
fields('entity.eid', 'doc.title', 'doc.body', 'skill.invoke'),
|
|
182
|
+
))).filter((b) =>
|
|
183
|
+
folder(text(b, 'doc', 'title') ?? '') &&
|
|
184
|
+
!!text(b, 'doc', 'body')?.trim()
|
|
185
|
+
),
|
|
186
|
+
repository,
|
|
187
|
+
),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Exact graph instructions, optionally limited to one repository. */
|
|
192
|
+
export let graphSkill = async (
|
|
193
|
+
g: Graph,
|
|
194
|
+
title: string,
|
|
195
|
+
repository?: string,
|
|
196
|
+
): Promise<Bundle> => {
|
|
197
|
+
let found = await inRepo(
|
|
198
|
+
g,
|
|
199
|
+
(await g.read(and(
|
|
200
|
+
present(SKILL),
|
|
201
|
+
eq('doc.title', title),
|
|
202
|
+
every(),
|
|
203
|
+
))).filter(shaped),
|
|
204
|
+
repository,
|
|
205
|
+
)
|
|
206
|
+
if (!found.length) throw new Refused(`No skill named ${title}`)
|
|
207
|
+
if (found.length > 1) {
|
|
208
|
+
throw new Refused(`Skill ${title} belongs to more than one repository`)
|
|
209
|
+
}
|
|
210
|
+
return found[0]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Complete skills and their locators for one repository. Other repositories
|
|
214
|
+
* supply no bodies; every selected skill still has its full locator checked.
|
|
215
|
+
* Companions include file contents in the same repository read for a mirror. */
|
|
216
|
+
export let skillScope = async (
|
|
217
|
+
g: Graph,
|
|
218
|
+
repository: string,
|
|
219
|
+
companions = false,
|
|
220
|
+
): Promise<{
|
|
221
|
+
skills: Bundle[]
|
|
222
|
+
places: Map<string, Bundle>
|
|
223
|
+
edges: Bundle[]
|
|
224
|
+
files: Bundle[]
|
|
225
|
+
}> => {
|
|
226
|
+
let places = new Map<string, Bundle>()
|
|
227
|
+
if (![SKILL, 'references', 'file'].every((c) => g.vocab.comps.includes(c))) {
|
|
228
|
+
return { skills: [], places, edges: [], files: [] }
|
|
229
|
+
}
|
|
230
|
+
let rows = companions
|
|
231
|
+
? await g.read(and(
|
|
232
|
+
present('file'),
|
|
233
|
+
eq('file.root', repository),
|
|
234
|
+
contains('file.path', '.claude/skills/'),
|
|
235
|
+
fields('file.path', 'file.root', 'content.body'),
|
|
236
|
+
))
|
|
237
|
+
: await g.read(and(
|
|
238
|
+
present('references'),
|
|
239
|
+
eq('edge.to.file.root', repository),
|
|
240
|
+
contains('edge.to.file.path', '.claude/skills/'),
|
|
241
|
+
fields('edge.from', 'edge.to', 'edge.to.file.path'),
|
|
242
|
+
))
|
|
243
|
+
let files = new Set(
|
|
244
|
+
rows.filter((b) => primary(text(b, 'file', 'path') ?? ''))
|
|
245
|
+
.map((b) => b.entity.eid),
|
|
246
|
+
)
|
|
247
|
+
let links = companions
|
|
248
|
+
? files.size
|
|
249
|
+
? await g.read(and(
|
|
250
|
+
present('references'),
|
|
251
|
+
eq('edge.to', list(...files)),
|
|
252
|
+
fields('edge.from', 'edge.to'),
|
|
253
|
+
))
|
|
254
|
+
: []
|
|
255
|
+
: rows.filter((b) => files.has(text(b, 'edge', 'to') ?? ''))
|
|
256
|
+
let ids = new Set(
|
|
257
|
+
links.map((b) => text(b, 'edge', 'from'))
|
|
258
|
+
.filter((id): id is string => id != undefined),
|
|
259
|
+
)
|
|
260
|
+
// A post-read mask may hide the source while leaving its target visible.
|
|
261
|
+
// Use the predicate's identity, as skillLocations does for the same mask.
|
|
262
|
+
if (links.some((b) => !text(b, 'edge', 'from'))) {
|
|
263
|
+
for (let b of await g.read(and(present(SKILL), fields('entity.eid')))) {
|
|
264
|
+
let from = b.entity.eid
|
|
265
|
+
let linked = await g.read(and(
|
|
266
|
+
present('references'),
|
|
267
|
+
eq('edge.from', from),
|
|
268
|
+
eq('edge.to', list(...files)),
|
|
269
|
+
fields('edge.to'),
|
|
270
|
+
))
|
|
271
|
+
if (linked.some((b) => files.has(text(b, 'edge', 'to') ?? ''))) {
|
|
272
|
+
ids.add(from)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
let skills = ids.size
|
|
277
|
+
? (await g.read(and(
|
|
278
|
+
present(SKILL),
|
|
279
|
+
eq('entity.eid', list(...ids)),
|
|
280
|
+
every(),
|
|
281
|
+
))).filter(shaped)
|
|
282
|
+
: []
|
|
283
|
+
let sites = await skillSites(g, skills)
|
|
284
|
+
places = sites.places
|
|
285
|
+
skills = sorted(skills.filter((b) => {
|
|
286
|
+
let location = places.get(b.entity.eid)
|
|
287
|
+
return location && text(location, 'file', 'root') == repository
|
|
288
|
+
}))
|
|
289
|
+
return {
|
|
290
|
+
skills,
|
|
291
|
+
places,
|
|
292
|
+
files: companions ? rows : [],
|
|
293
|
+
edges: skills.flatMap((b) => sites.links.get(b.entity.eid) ?? []),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Complete graph skills. Unlinked skills are visible without a repository,
|
|
298
|
+
* but cannot be exported or attributed to a repository until linked. */
|
|
299
|
+
export let repoSkills = async (
|
|
300
|
+
g: Graph,
|
|
301
|
+
repository?: string,
|
|
302
|
+
): Promise<Bundle[]> => {
|
|
303
|
+
if (repository != undefined) return (await skillScope(g, repository)).skills
|
|
304
|
+
if (!g.vocab.comps.includes(SKILL)) return []
|
|
305
|
+
return sorted((await g.read(and(present(SKILL), every()))).filter(shaped))
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Paths are portable repository-relative names, not host paths. Reject both
|
|
309
|
+
// separators and all dot segments before a mirror ever joins them to a root.
|
|
310
|
+
let relative = (path: string): boolean =>
|
|
311
|
+
!path.includes('\\') && [...path].every((char) => {
|
|
312
|
+
let code = char.charCodeAt(0)
|
|
313
|
+
return code >= 32 && code != 127
|
|
314
|
+
}) &&
|
|
315
|
+
!path.includes(':') &&
|
|
316
|
+
path.split('/').every((part) => !!part && part != '.' && part != '..')
|
|
317
|
+
|
|
318
|
+
/** Render one read's skills and locators together, including pending renames. */
|
|
319
|
+
export let renderFiles = (
|
|
320
|
+
skills: Bundle[],
|
|
321
|
+
locations: Map<string, Bundle>,
|
|
322
|
+
supports: Bundle[],
|
|
323
|
+
): Map<string, string> => {
|
|
324
|
+
let files = new Map<string, string>()
|
|
325
|
+
let dirs = new Map<string, string>()
|
|
326
|
+
let put = (path: string, body: string): void => {
|
|
327
|
+
if (files.has(path)) {
|
|
328
|
+
throw new Refused(`More than one skill file targets ${path}`)
|
|
329
|
+
}
|
|
330
|
+
files.set(path, body)
|
|
331
|
+
}
|
|
332
|
+
// The locator keeps the old folder until the mirror lands a rename. Move
|
|
333
|
+
// companions with their skill, keeping every suffix beneath that folder.
|
|
334
|
+
for (let skill of skills) {
|
|
335
|
+
let title = text(skill, 'doc', 'title')!
|
|
336
|
+
let to = `.claude/skills/${title}/`
|
|
337
|
+
put(pathOf(title), rendered(skill))
|
|
338
|
+
let location = locations.get(skill.entity.eid)
|
|
339
|
+
let path = location && text(location, 'file', 'path')
|
|
340
|
+
if (path) {
|
|
341
|
+
let from = path.slice(0, -'SKILL.md'.length)
|
|
342
|
+
if (dirs.has(from)) throw new Refused(`More than one skill owns ${from}`)
|
|
343
|
+
dirs.set(from, to)
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// Files already at the destination can coexist with a pending rename only
|
|
347
|
+
// when they do not overwrite another companion. Locator ownership wins
|
|
348
|
+
// when two skills swap names.
|
|
349
|
+
for (let skill of skills) {
|
|
350
|
+
let dir = `.claude/skills/${text(skill, 'doc', 'title')}/`
|
|
351
|
+
if (!dirs.has(dir)) dirs.set(dir, dir)
|
|
352
|
+
}
|
|
353
|
+
if (!skills.length) return files
|
|
354
|
+
for (
|
|
355
|
+
let b of supports.toSorted((a, b) =>
|
|
356
|
+
(text(a, 'file', 'path') ?? '').localeCompare(
|
|
357
|
+
text(b, 'file', 'path') ?? '',
|
|
358
|
+
)
|
|
359
|
+
)
|
|
360
|
+
) {
|
|
361
|
+
let path = text(b, 'file', 'path')
|
|
362
|
+
let body = text(b, 'content', 'body')
|
|
363
|
+
if (!path || body == undefined || !relative(path)) continue
|
|
364
|
+
for (let [from, to] of dirs) {
|
|
365
|
+
if (!path.startsWith(from)) continue
|
|
366
|
+
put(`${to}${path.slice(from.length)}`, body)
|
|
367
|
+
break
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return files
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The skill documents and text supporting files the graph owns. */
|
|
374
|
+
export let skillFiles = async (
|
|
375
|
+
g: Graph,
|
|
376
|
+
repository: string,
|
|
377
|
+
): Promise<Map<string, string>> => {
|
|
378
|
+
let { skills, places, files } = await skillScope(g, repository, true)
|
|
379
|
+
return renderFiles(skills, places, files)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// The portable codec is shared by MCP manifests and repository views.
|
|
383
|
+
export { frontmatter, parseSkill, renderSkill } from './skill-text.js'
|
package/text.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent is given, as the Markdown view of a persona or a skill draws
|
|
3
|
+
* it, so that view is the preview. A persona's is its whole text: its own
|
|
4
|
+
* words, then each document it contains in full and what it reads, the text
|
|
5
|
+
* `yak persona read` says and a session wearing it is given (`voice` of
|
|
6
|
+
* `wear`). The page composes it with that same code over what the page holds
|
|
7
|
+
* (@yaks/inspect's `useReading`), so it is recomposed as anything it read
|
|
8
|
+
* moves. A skill's is its SKILL.md, as an agent loads it (`renderSkill`).
|
|
9
|
+
* Either is drawn as its source, as written.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
|
|
13
|
+
import * as ui from "@yaks/ui";
|
|
14
|
+
import { useReading } from "@yaks/inspect";
|
|
15
|
+
import { Refused } from "@yaks/graph/errors";
|
|
16
|
+
import { voice } from "./voice.js";
|
|
17
|
+
import { wear } from "./worn.js";
|
|
18
|
+
import { renderSkill } from "./skill-text.js";
|
|
19
|
+
/** A text as its source, once it is all there. */ let Source = ({ eid, text, ready })=>ready ? /*#__PURE__*/ h(ui.Body, {
|
|
20
|
+
mod: 'source',
|
|
21
|
+
'data-markdown': eid
|
|
22
|
+
}, /*#__PURE__*/ h(ui.Body.Source, {}, text)) : /*#__PURE__*/ h(ui.Loading, {});
|
|
23
|
+
/** A persona's whole text, as an agent wearing it is given it. */ export let PersonaText = ({ e, io })=>{
|
|
24
|
+
let { value, ready } = useReading(io, (r)=>{
|
|
25
|
+
let worn = wear(r, io.vocab)(e.entity.eid);
|
|
26
|
+
return worn ? voice(io.vocab)(worn) : '';
|
|
27
|
+
});
|
|
28
|
+
return /*#__PURE__*/ h(Source, {
|
|
29
|
+
eid: e.entity.eid,
|
|
30
|
+
text: value,
|
|
31
|
+
ready
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/** A skill's SKILL.md, or why it cannot be written as one. */ export let skillText = (b)=>{
|
|
35
|
+
try {
|
|
36
|
+
return renderSkill({
|
|
37
|
+
doc: b.doc,
|
|
38
|
+
skill: b.skill,
|
|
39
|
+
content: b.content
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (!(error instanceof Refused)) throw error;
|
|
43
|
+
return `${error.message}.`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** A skill's SKILL.md, as an agent loads it. */ export let SkillText = ({ e, io })=>{
|
|
47
|
+
let { value, ready } = useReading(io, (r)=>{
|
|
48
|
+
let [b] = r.get([
|
|
49
|
+
e.entity.eid
|
|
50
|
+
]);
|
|
51
|
+
return b ? skillText(b) : '';
|
|
52
|
+
});
|
|
53
|
+
return /*#__PURE__*/ h(Source, {
|
|
54
|
+
eid: e.entity.eid,
|
|
55
|
+
text: value,
|
|
56
|
+
ready
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=text.js.map
|
package/text.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sources":["./text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoC;AACzG,YAAY,wBAA6B;AACzC,SAAkC,UAAU,6BAAkC;AAC9E,SAAS,OAAO,kCAAuC;AACvD,SAAS,KAAK,qBAA+B;AAC7C,SAAS,IAAI,oBAAmB;AAChC,SAAS,WAAW,0BAAyB;AAE7C,gDAAgD,GAChD,IAAI,SAAS,CACX,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAiD,GAEnE,sBACI,EACA,GAAG,IAAI,EACP;IAAE,KAAK;IAAU,iBAAiB;EAAI,iBACtC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,uBAEtB,EAAE,GAAG,OAAO,EAAE,CAAC;AAErB,gEAAgE,GAChE,OAAO,IAAI,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,EAAS;EACxC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,WAAW,IAAI,CAAC;IACrC,IAAI,OAAO,KAAK,GAAG,GAAG,KAAK,EAAE,EAAE,MAAM,CAAC,GAAG;IACzC,OAAO,OAAO,MAAM,GAAG,KAAK,EAAE,QAAQ;EACxC;EACA,qBAAO,EAAE,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAE,MAAM;IAAO;EAAM;AAC3D,EAAC;AAED,4DAA4D,GAC5D,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI;IACF,OAAO,YAAY;MAAE,KAAK,EAAE,GAAG;MAAE,OAAO,EAAE,KAAK;MAAE,SAAS,EAAE,OAAO;IAAC;EACtE,EAAE,OAAO,OAAO;IACd,IAAI,CAAC,CAAC,iBAAiB,OAAO,GAAG,MAAM;IACvC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC;EAC5B;AACF,EAAC;AAED,8CAA8C,GAC9C,OAAO,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,EAAS;EACtC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,WAAW,IAAI,CAAC;IACrC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;MAAC,EAAE,MAAM,CAAC,GAAG;KAAC;IAC9B,OAAO,IAAI,UAAU,KAAK;EAC5B;EACA,qBAAO,EAAE,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAE,MAAM;IAAO;EAAM;AAC3D,EAAC"}
|
package/text.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent is given, as the Markdown view of a persona or a skill draws
|
|
3
|
+
* it, so that view is the preview. A persona's is its whole text: its own
|
|
4
|
+
* words, then each document it contains in full and what it reads, the text
|
|
5
|
+
* `yak persona read` says and a session wearing it is given (`voice` of
|
|
6
|
+
* `wear`). The page composes it with that same code over what the page holds
|
|
7
|
+
* (@yaks/inspect's `useReading`), so it is recomposed as anything it read
|
|
8
|
+
* moves. A skill's is its SKILL.md, as an agent loads it (`renderSkill`).
|
|
9
|
+
* Either is drawn as its source, as written.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX } from 'react'
|
|
15
|
+
import * as ui from '@yaks/ui'
|
|
16
|
+
import { type Bundle, type Props, useReading } from '@yaks/inspect'
|
|
17
|
+
import { Refused } from '@yaks/graph/errors'
|
|
18
|
+
import { voice, type Worn } from './voice.js'
|
|
19
|
+
import { wear } from './worn.js'
|
|
20
|
+
import { renderSkill } from './skill-text.js'
|
|
21
|
+
|
|
22
|
+
/** A text as its source, once it is all there. */
|
|
23
|
+
let Source = (
|
|
24
|
+
{ eid, text, ready }: { eid: string; text: string; ready: boolean },
|
|
25
|
+
): JSX.Element =>
|
|
26
|
+
ready
|
|
27
|
+
? h(
|
|
28
|
+
ui.Body,
|
|
29
|
+
{ mod: 'source', 'data-markdown': eid },
|
|
30
|
+
h(ui.Body.Source, {}, text),
|
|
31
|
+
)
|
|
32
|
+
: h(ui.Loading, {})
|
|
33
|
+
|
|
34
|
+
/** A persona's whole text, as an agent wearing it is given it. */
|
|
35
|
+
export let PersonaText = ({ e, io }: Props): JSX.Element => {
|
|
36
|
+
let { value, ready } = useReading(io, (r) => {
|
|
37
|
+
let worn = wear(r, io.vocab)(e.entity.eid) as Worn | undefined
|
|
38
|
+
return worn ? voice(io.vocab)(worn) : ''
|
|
39
|
+
})
|
|
40
|
+
return h(Source, { eid: e.entity.eid, text: value, ready })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A skill's SKILL.md, or why it cannot be written as one. */
|
|
44
|
+
export let skillText = (b: Bundle): string => {
|
|
45
|
+
try {
|
|
46
|
+
return renderSkill({ doc: b.doc, skill: b.skill, content: b.content })
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (!(error instanceof Refused)) throw error
|
|
49
|
+
return `${error.message}.`
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A skill's SKILL.md, as an agent loads it. */
|
|
54
|
+
export let SkillText = ({ e, io }: Props): JSX.Element => {
|
|
55
|
+
let { value, ready } = useReading(io, (r) => {
|
|
56
|
+
let [b] = r.get([e.entity.eid])
|
|
57
|
+
return b ? skillText(b) : ''
|
|
58
|
+
})
|
|
59
|
+
return h(Source, { eid: e.entity.eid, text: value, ready })
|
|
60
|
+
}
|
package/tools.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// What an agent can ask for here, exported as `@yaks/persona/tools`: the
|
|
2
|
+
// implementations behind `persona_read` and `persona_sync` in ./vocab.json.
|
|
3
|
+
//
|
|
4
|
+
// `persona_read` returns text — a `content{body}` entity with `output{source}`
|
|
5
|
+
// naming the call it came from (@yaks/tools' components, the shape every
|
|
6
|
+
// transport already renders) — not a file and not a path. `persona_sync` is
|
|
7
|
+
// where that text becomes files: each project's personas in its checkout
|
|
8
|
+
// (./files.ts), and a line for each file that moved.
|
|
9
|
+
import * as systemProcess from "@yaks/process/system";
|
|
10
|
+
import { argsOf } from "@yaks/graph/call";
|
|
11
|
+
import { Refused } from "@yaks/graph/errors";
|
|
12
|
+
import { plan, sync } from "@yaks/mirror";
|
|
13
|
+
import { link, personaMirror, remembered } from "./files.js";
|
|
14
|
+
import { voice } from "./voice.js";
|
|
15
|
+
import { wear } from "./worn.js";
|
|
16
|
+
let answer = (call, body)=>[
|
|
17
|
+
{
|
|
18
|
+
entity: {
|
|
19
|
+
eid: '$voice'
|
|
20
|
+
},
|
|
21
|
+
content: {
|
|
22
|
+
body
|
|
23
|
+
},
|
|
24
|
+
output: {
|
|
25
|
+
source: call.entity.eid
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
let CURRENT = 'every persona file is current';
|
|
30
|
+
// What a sync did. A file that could not be written is not the caller's to
|
|
31
|
+
// fix, so it throws, and the call is recorded as failed.
|
|
32
|
+
let synced = async (graph, db)=>{
|
|
33
|
+
let m = await personaMirror(graph, remembered(db));
|
|
34
|
+
let done = await sync(m.binding);
|
|
35
|
+
let links = await link(m.links);
|
|
36
|
+
let failed = [
|
|
37
|
+
...done.failed,
|
|
38
|
+
...links.failed
|
|
39
|
+
];
|
|
40
|
+
if (failed.length) throw new Error(failed.join('\n'));
|
|
41
|
+
let lines = [
|
|
42
|
+
...done.wrote.map((p)=>`wrote ${p}`),
|
|
43
|
+
...done.removed.map((p)=>`removed ${p}`),
|
|
44
|
+
...links.linked.map((p)=>`linked ${p}`),
|
|
45
|
+
...links.unlinked.map((p)=>`unlinked ${p}`),
|
|
46
|
+
...done.conflicts.map((p)=>`left ${p}: edited by hand while the graph moved; delete it to take ` + "the graph's")
|
|
47
|
+
];
|
|
48
|
+
return lines.join('\n') || CURRENT;
|
|
49
|
+
};
|
|
50
|
+
// What a sync would do, without doing it.
|
|
51
|
+
let drift = async (graph, db)=>{
|
|
52
|
+
let m = await personaMirror(graph, remembered(db));
|
|
53
|
+
return [
|
|
54
|
+
...(await plan(m.binding)).filter((p)=>p.act != 'same').map((p)=>`${p.act == 'conflict' ? 'conflict' : p.text == null ? 'remove' : 'write'} ${p.path}`),
|
|
55
|
+
...m.links.map((l)=>`${l.to == null ? 'unlink' : 'link'} ${l.path}`)
|
|
56
|
+
].join('\n') || CURRENT;
|
|
57
|
+
};
|
|
58
|
+
/** The implementations behind the tools ./vocab.json declares. The host's
|
|
59
|
+
* config names the database, beside which `persona_sync` remembers what each
|
|
60
|
+
* file last agreed on. */ export let runs = (host)=>{
|
|
61
|
+
let db = host?.config?.db ?? systemProcess.env.get('DB_PATH');
|
|
62
|
+
return {
|
|
63
|
+
persona_read: async (call, graph)=>{
|
|
64
|
+
let said = String(argsOf(call).persona ?? '').trim();
|
|
65
|
+
if (!said) throw new Refused('persona_read needs a persona');
|
|
66
|
+
let worn = await wear(graph.storage, graph.vocab)(said);
|
|
67
|
+
// An entity that is not a persona is refused rather than rendered as an
|
|
68
|
+
// empty document: a caller that named a task would otherwise read the
|
|
69
|
+
// task's own body as instructions.
|
|
70
|
+
if (!worn) throw new Refused(`no persona called ${said}`);
|
|
71
|
+
return answer(call, voice(graph.vocab)(worn));
|
|
72
|
+
},
|
|
73
|
+
persona_sync: async (call, graph)=>answer(call, argsOf(call).check == true ? await drift(graph, db) : await synced(graph, db))
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=tools.js.map
|
package/tools.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sources":["./tools.ts"],"names":[],"mappings":"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"}
|
package/tools.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// What an agent can ask for here, exported as `@yaks/persona/tools`: the
|
|
2
|
+
// implementations behind `persona_read` and `persona_sync` in ./vocab.json.
|
|
3
|
+
//
|
|
4
|
+
// `persona_read` returns text — a `content{body}` entity with `output{source}`
|
|
5
|
+
// naming the call it came from (@yaks/tools' components, the shape every
|
|
6
|
+
// transport already renders) — not a file and not a path. `persona_sync` is
|
|
7
|
+
// where that text becomes files: each project's personas in its checkout
|
|
8
|
+
// (./files.ts), and a line for each file that moved.
|
|
9
|
+
|
|
10
|
+
import * as systemProcess from '@yaks/process/system'
|
|
11
|
+
|
|
12
|
+
import type { Bundle, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
13
|
+
import { argsOf } from '@yaks/graph/call'
|
|
14
|
+
import { Refused } from '@yaks/graph/errors'
|
|
15
|
+
import type { Runs } from 'jsr:@yaks/graph@0.2.36/tools'
|
|
16
|
+
import { plan, sync } from '@yaks/mirror'
|
|
17
|
+
import { link, personaMirror, remembered } from './files.js'
|
|
18
|
+
import { voice } from './voice.js'
|
|
19
|
+
import { wear } from './worn.js'
|
|
20
|
+
|
|
21
|
+
let answer = (call: Bundle, body: string): Bundle[] => [{
|
|
22
|
+
entity: { eid: '$voice' },
|
|
23
|
+
content: { body },
|
|
24
|
+
output: { source: call.entity.eid },
|
|
25
|
+
}]
|
|
26
|
+
|
|
27
|
+
let CURRENT = 'every persona file is current'
|
|
28
|
+
|
|
29
|
+
// What a sync did. A file that could not be written is not the caller's to
|
|
30
|
+
// fix, so it throws, and the call is recorded as failed.
|
|
31
|
+
let synced = async (graph: Graph, db?: string): Promise<string> => {
|
|
32
|
+
let m = await personaMirror(graph, remembered(db))
|
|
33
|
+
let done = await sync(m.binding)
|
|
34
|
+
let links = await link(m.links)
|
|
35
|
+
let failed = [...done.failed, ...links.failed]
|
|
36
|
+
if (failed.length) throw new Error(failed.join('\n'))
|
|
37
|
+
let lines = [
|
|
38
|
+
...done.wrote.map((p) => `wrote ${p}`),
|
|
39
|
+
...done.removed.map((p) => `removed ${p}`),
|
|
40
|
+
...links.linked.map((p) => `linked ${p}`),
|
|
41
|
+
...links.unlinked.map((p) => `unlinked ${p}`),
|
|
42
|
+
...done.conflicts.map((p) =>
|
|
43
|
+
`left ${p}: edited by hand while the graph moved; delete it to take ` +
|
|
44
|
+
"the graph's"
|
|
45
|
+
),
|
|
46
|
+
]
|
|
47
|
+
return lines.join('\n') || CURRENT
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// What a sync would do, without doing it.
|
|
51
|
+
let drift = async (graph: Graph, db?: string): Promise<string> => {
|
|
52
|
+
let m = await personaMirror(graph, remembered(db))
|
|
53
|
+
return [
|
|
54
|
+
...(await plan(m.binding))
|
|
55
|
+
.filter((p) => p.act != 'same')
|
|
56
|
+
.map((p) =>
|
|
57
|
+
`${
|
|
58
|
+
p.act == 'conflict' ? 'conflict' : p.text == null ? 'remove' : 'write'
|
|
59
|
+
} ${p.path}`
|
|
60
|
+
),
|
|
61
|
+
...m.links.map((l) => `${l.to == null ? 'unlink' : 'link'} ${l.path}`),
|
|
62
|
+
].join('\n') || CURRENT
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The implementations behind the tools ./vocab.json declares. The host's
|
|
66
|
+
* config names the database, beside which `persona_sync` remembers what each
|
|
67
|
+
* file last agreed on. */
|
|
68
|
+
export let runs = (host?: { config?: { db?: string } }): Runs => {
|
|
69
|
+
let db = host?.config?.db ?? systemProcess.env.get('DB_PATH')
|
|
70
|
+
return {
|
|
71
|
+
persona_read: async (call, graph): Promise<Bundle[]> => {
|
|
72
|
+
let said = String(argsOf(call).persona ?? '').trim()
|
|
73
|
+
if (!said) throw new Refused('persona_read needs a persona')
|
|
74
|
+
let worn = await wear(graph.storage, graph.vocab)(
|
|
75
|
+
said,
|
|
76
|
+
)
|
|
77
|
+
// An entity that is not a persona is refused rather than rendered as an
|
|
78
|
+
// empty document: a caller that named a task would otherwise read the
|
|
79
|
+
// task's own body as instructions.
|
|
80
|
+
if (!worn) throw new Refused(`no persona called ${said}`)
|
|
81
|
+
return answer(call, voice(graph.vocab)(worn))
|
|
82
|
+
},
|
|
83
|
+
persona_sync: async (call, graph): Promise<Bundle[]> =>
|
|
84
|
+
answer(
|
|
85
|
+
call,
|
|
86
|
+
argsOf(call).check == true
|
|
87
|
+
? await drift(graph, db)
|
|
88
|
+
: await synced(graph, db),
|
|
89
|
+
),
|
|
90
|
+
}
|
|
91
|
+
}
|