@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/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/persona",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/persona",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./vocab": {
|
|
12
|
+
"types": "./_dist/vocab.d.ts",
|
|
13
|
+
"default": "./vocab.js"
|
|
14
|
+
},
|
|
15
|
+
"./name": {
|
|
16
|
+
"types": "./_dist/name.d.ts",
|
|
17
|
+
"default": "./name.js"
|
|
18
|
+
},
|
|
19
|
+
"./part": {
|
|
20
|
+
"types": "./_dist/part.d.ts",
|
|
21
|
+
"default": "./part.js"
|
|
22
|
+
},
|
|
23
|
+
"./tools": {
|
|
24
|
+
"types": "./_dist/tools.d.ts",
|
|
25
|
+
"default": "./tools.js"
|
|
26
|
+
},
|
|
27
|
+
"./effects": {
|
|
28
|
+
"types": "./_dist/effects.d.ts",
|
|
29
|
+
"default": "./effects.js"
|
|
30
|
+
},
|
|
31
|
+
"./skills": {
|
|
32
|
+
"types": "./_dist/skills.d.ts",
|
|
33
|
+
"default": "./skills.js"
|
|
34
|
+
},
|
|
35
|
+
"./skill-checkout": {
|
|
36
|
+
"types": "./_dist/skill-checkout.d.ts",
|
|
37
|
+
"default": "./skill-checkout.js"
|
|
38
|
+
},
|
|
39
|
+
"./skill-mirror": {
|
|
40
|
+
"types": "./_dist/skill-mirror.d.ts",
|
|
41
|
+
"default": "./skill-mirror.js"
|
|
42
|
+
},
|
|
43
|
+
"./skill-text": {
|
|
44
|
+
"types": "./_dist/skill-text.d.ts",
|
|
45
|
+
"default": "./skill-text.js"
|
|
46
|
+
},
|
|
47
|
+
"./views": {
|
|
48
|
+
"types": "./_dist/views.d.ts",
|
|
49
|
+
"default": "./views.js"
|
|
50
|
+
},
|
|
51
|
+
"./ui": {
|
|
52
|
+
"types": "./_dist/ui.d.ts",
|
|
53
|
+
"default": "./ui.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"license": "Apache-2.0",
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@yaks/doc": "0.2.36",
|
|
59
|
+
"@yaks/edge": "0.2.36",
|
|
60
|
+
"@yaks/effects": "0.2.36",
|
|
61
|
+
"@yaks/file": "0.2.36",
|
|
62
|
+
"@yaks/fp": "0.2.36",
|
|
63
|
+
"@yaks/git": "0.2.36",
|
|
64
|
+
"@yaks/graph": "0.2.36",
|
|
65
|
+
"@yaks/id": "0.2.36",
|
|
66
|
+
"@yaks/inspect": "0.2.36",
|
|
67
|
+
"@yaks/markdown": "0.2.36",
|
|
68
|
+
"@yaks/mirror": "0.2.36",
|
|
69
|
+
"@yaks/process": "0.2.36",
|
|
70
|
+
"@yaks/project": "0.2.36",
|
|
71
|
+
"@yaks/query": "0.2.36",
|
|
72
|
+
"@yaks/text": "0.2.36",
|
|
73
|
+
"@yaks/tools": "0.2.36",
|
|
74
|
+
"@yaks/tracker": "0.2.36",
|
|
75
|
+
"@yaks/ui": "0.2.36",
|
|
76
|
+
"@yaks/ux": "0.2.36",
|
|
77
|
+
"@yaks/vocab": "0.2.36",
|
|
78
|
+
"@yaks/yaml": "0.2.36",
|
|
79
|
+
"@types/react": "19.3.0",
|
|
80
|
+
"lucide": "1.31.0",
|
|
81
|
+
"react": "19.3.0"
|
|
82
|
+
},
|
|
83
|
+
"description": "Who is acting and with what instructions — the people a graph knows, the personas an agent runs with, the skills it loads on demand, and a persona rendered as one markdown document.",
|
|
84
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
85
|
+
}
|
package/part.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** What stands between two parts of what an agent is told: each document
|
|
2
|
+
* worn, and what its host adds after them. Its own module, so a reader that
|
|
3
|
+
* splits what an agent was told (a browser's) imports nothing else. */ export let PART = '\n\n---\n\n';
|
|
4
|
+
//# sourceMappingURL=part.js.map
|
package/part.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part.js","sources":["./part.ts"],"names":[],"mappings":"AAAA;;qEAEqE,GACrE,OAAO,IAAI,OAAO,cAAa"}
|
package/part.ts
ADDED
package/shipped.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// A persona a package ships as files, read into the rows a store keeps: the
|
|
2
|
+
// other way round from ./files.ts, which writes a graph's personas out into a
|
|
3
|
+
// checkout. The files own what they say. A store is given each row they say
|
|
4
|
+
// something new in, and a document the persona no longer contains leaves it,
|
|
5
|
+
// so a change to the files reaches the store the next time they are kept.
|
|
6
|
+
//
|
|
7
|
+
// Each file is a content file (@yaks/yaml `front`): its frontmatter is the
|
|
8
|
+
// bundle, and the document under it is the `doc` body. One of them carries
|
|
9
|
+
// `persona`, and lists under `contains` the names of the documents it says in
|
|
10
|
+
// full, in the order it says them, and under `reads` those it only names, for
|
|
11
|
+
// an agent to open when its work needs one; each other file is one of those
|
|
12
|
+
// documents. A name is a
|
|
13
|
+
// file's name without `.md`, and the caller derives each row's eid from it,
|
|
14
|
+
// so the files name no entity. Reading takes texts, not a directory: a host
|
|
15
|
+
// without a filesystem (a Worker) is handed them at build time.
|
|
16
|
+
import { and, eq, present } from "@yaks/query";
|
|
17
|
+
import { unheld } from "@yaks/graph";
|
|
18
|
+
import { EDGE, link } from "@yaks/edge";
|
|
19
|
+
import { DOC } from "@yaks/doc";
|
|
20
|
+
import { front } from "@yaks/yaml";
|
|
21
|
+
import { PERSONA } from "./comp.js";
|
|
22
|
+
import { CONTAINS, READS } from "./worn.js";
|
|
23
|
+
/**
|
|
24
|
+
* The rows a persona's files say, by file name: the persona, each document it
|
|
25
|
+
* contains or reads, and the `contains` or `reads` edge to each in its order.
|
|
26
|
+
* `eid` gives the row a name stands for. A set with no persona, or two, a
|
|
27
|
+
* document the persona neither contains nor reads, or a name it lists that no
|
|
28
|
+
* file holds is refused.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { derivedEid } from '@yaks/graph/identity'
|
|
32
|
+
* import { shipped } from '@yaks/persona'
|
|
33
|
+
*
|
|
34
|
+
* let rows = shipped({
|
|
35
|
+
* 'base.md': '---\npersona: {}\ndoc:\n title: Helper\ncontains: [tone]\nreads: [calls]\n---\n\nHelp.\n',
|
|
36
|
+
* 'tone.md': '---\ndoc:\n title: Tone\n---\n\nBe brief.\n',
|
|
37
|
+
* 'calls.md': '---\ndoc:\n title: Calls\n---\n\nSpeak slowly.\n',
|
|
38
|
+
* }, (name) => derivedEid('helper|' + name))
|
|
39
|
+
* // the persona, `tone` and the edge containing it, `calls` and the edge
|
|
40
|
+
* // that reads it
|
|
41
|
+
* ```
|
|
42
|
+
*/ export let shipped = (files, eid)=>{
|
|
43
|
+
let read = Object.entries(files).map(([file, text])=>{
|
|
44
|
+
let { meta, body } = front(text, file);
|
|
45
|
+
if (meta.entity) throw new Error(`${file} names an entity: its name does`);
|
|
46
|
+
let { contains, reads, ...row } = meta;
|
|
47
|
+
return {
|
|
48
|
+
name: file.replace(/\.md$/, ''),
|
|
49
|
+
contains,
|
|
50
|
+
reads,
|
|
51
|
+
row: {
|
|
52
|
+
...row,
|
|
53
|
+
entity: {
|
|
54
|
+
eid: eid(file.replace(/\.md$/, ''))
|
|
55
|
+
},
|
|
56
|
+
[DOC]: {
|
|
57
|
+
...row[DOC],
|
|
58
|
+
body: body.replace(/^\n+/, '').replace(/\n+$/, '')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
let personas = read.filter((f)=>f.row[PERSONA]);
|
|
64
|
+
if (personas.length != 1) {
|
|
65
|
+
throw new Error(`a persona's files hold one persona, not ${personas.length}`);
|
|
66
|
+
}
|
|
67
|
+
let [persona] = personas;
|
|
68
|
+
let listed = (names)=>Array.isArray(names) ? names.map(String) : [];
|
|
69
|
+
let lists = [
|
|
70
|
+
[
|
|
71
|
+
CONTAINS,
|
|
72
|
+
listed(persona.contains)
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
READS,
|
|
76
|
+
listed(persona.reads)
|
|
77
|
+
]
|
|
78
|
+
];
|
|
79
|
+
let names = lists.flatMap(([, n])=>n);
|
|
80
|
+
let docs = read.filter((f)=>f != persona);
|
|
81
|
+
let by = new Map(docs.map((f)=>[
|
|
82
|
+
f.name,
|
|
83
|
+
f.row
|
|
84
|
+
]));
|
|
85
|
+
let missing = names.filter((n)=>!by.has(n));
|
|
86
|
+
if (missing.length) {
|
|
87
|
+
throw new Error(`${persona.name} lists ${missing.join(', ')}: no file`);
|
|
88
|
+
}
|
|
89
|
+
let loose = docs.filter((f)=>!names.includes(f.name)).map((f)=>f.name);
|
|
90
|
+
if (loose.length) {
|
|
91
|
+
throw new Error(`${persona.name} neither contains nor reads ${loose.join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
let from = persona.row.entity.eid;
|
|
94
|
+
return [
|
|
95
|
+
persona.row,
|
|
96
|
+
...lists.flatMap(([tag, list])=>list.flatMap((n, i)=>[
|
|
97
|
+
by.get(n),
|
|
98
|
+
link(from, tag, by.get(n).entity.eid, i + 1)
|
|
99
|
+
]))
|
|
100
|
+
];
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* What a store whose entities `storage` reads still needs written to keep a
|
|
104
|
+
* persona as `rows` ({@link shipped}) say: each row it does not already hold
|
|
105
|
+
* as they say it, and the removal of each `contains` or `reads` edge the
|
|
106
|
+
* persona has there that `rows` does not. Nothing, where the store already
|
|
107
|
+
* keeps it.
|
|
108
|
+
*/ export let kept = async (storage, rows)=>{
|
|
109
|
+
let persona = rows.find((b)=>b[PERSONA]);
|
|
110
|
+
if (!persona) return [];
|
|
111
|
+
let edges = (tag)=>storage.read(and(eq(`${EDGE}.from`, persona.entity.eid), present(tag)));
|
|
112
|
+
let [held, contained, read] = await Promise.all([
|
|
113
|
+
storage.get(rows.map((b)=>b.entity.eid)),
|
|
114
|
+
edges(CONTAINS),
|
|
115
|
+
edges(READS)
|
|
116
|
+
]);
|
|
117
|
+
let links = [
|
|
118
|
+
...contained,
|
|
119
|
+
...read
|
|
120
|
+
];
|
|
121
|
+
let said = new Set(rows.map((b)=>b.entity.eid));
|
|
122
|
+
return [
|
|
123
|
+
...links.filter((b)=>!said.has(b.entity.eid)).map((b)=>({
|
|
124
|
+
entity: b.entity,
|
|
125
|
+
$delete: true
|
|
126
|
+
})),
|
|
127
|
+
...unheld(held, rows)
|
|
128
|
+
];
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=shipped.js.map
|
package/shipped.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shipped.js","sources":["./shipped.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,yBAAyB;AACzB,4EAA4E;AAC5E,4EAA4E;AAC5E,gEAAgE;AAEhE,SAAS,GAAG,EAAE,EAAE,EAAE,OAAO,2BAAgC;AACzD,SAA2C,MAAM,2BAAgC;AACjF,SAAS,IAAI,EAAE,IAAI,0BAA+B;AAClD,SAAS,GAAG,yBAA8B;AAC1C,SAAS,KAAK,0BAA+B;AAC7C,SAAS,OAAO,oBAAmB;AACnC,SAAS,QAAQ,EAAE,KAAK,oBAA+B;AAEvD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,IAAI,UAAU,CACnB,OACA;EAEA,IAAI,OAAO,OAAO,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK;IAChD,IAAI,EAAE,IAAI,E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,IAAM,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,GAC1C,GAAG,CAAC,CAAC,IAAM,CAAC;QAAE,QAAQ,EAAE,MAAM;QAAE,SAAS;MAAK,CAAC;OAC/C,OAAO,MAAM;GACjB;AACH,EAAC"}
|
package/shipped.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// A persona a package ships as files, read into the rows a store keeps: the
|
|
2
|
+
// other way round from ./files.ts, which writes a graph's personas out into a
|
|
3
|
+
// checkout. The files own what they say. A store is given each row they say
|
|
4
|
+
// something new in, and a document the persona no longer contains leaves it,
|
|
5
|
+
// so a change to the files reaches the store the next time they are kept.
|
|
6
|
+
//
|
|
7
|
+
// Each file is a content file (@yaks/yaml `front`): its frontmatter is the
|
|
8
|
+
// bundle, and the document under it is the `doc` body. One of them carries
|
|
9
|
+
// `persona`, and lists under `contains` the names of the documents it says in
|
|
10
|
+
// full, in the order it says them, and under `reads` those it only names, for
|
|
11
|
+
// an agent to open when its work needs one; each other file is one of those
|
|
12
|
+
// documents. A name is a
|
|
13
|
+
// file's name without `.md`, and the caller derives each row's eid from it,
|
|
14
|
+
// so the files name no entity. Reading takes texts, not a directory: a host
|
|
15
|
+
// without a filesystem (a Worker) is handed them at build time.
|
|
16
|
+
|
|
17
|
+
import { and, eq, present } from '@yaks/query'
|
|
18
|
+
import { type Bundle, type Comp, type Eid, unheld } from '@yaks/graph'
|
|
19
|
+
import { EDGE, link } from '@yaks/edge'
|
|
20
|
+
import { DOC } from '@yaks/doc'
|
|
21
|
+
import { front } from '@yaks/yaml'
|
|
22
|
+
import { PERSONA } from './comp.js'
|
|
23
|
+
import { CONTAINS, READS, type Reads } from './worn.js'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The rows a persona's files say, by file name: the persona, each document it
|
|
27
|
+
* contains or reads, and the `contains` or `reads` edge to each in its order.
|
|
28
|
+
* `eid` gives the row a name stands for. A set with no persona, or two, a
|
|
29
|
+
* document the persona neither contains nor reads, or a name it lists that no
|
|
30
|
+
* file holds is refused.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { derivedEid } from '@yaks/graph/identity'
|
|
34
|
+
* import { shipped } from '@yaks/persona'
|
|
35
|
+
*
|
|
36
|
+
* let rows = shipped({
|
|
37
|
+
* 'base.md': '---\npersona: {}\ndoc:\n title: Helper\ncontains: [tone]\nreads: [calls]\n---\n\nHelp.\n',
|
|
38
|
+
* 'tone.md': '---\ndoc:\n title: Tone\n---\n\nBe brief.\n',
|
|
39
|
+
* 'calls.md': '---\ndoc:\n title: Calls\n---\n\nSpeak slowly.\n',
|
|
40
|
+
* }, (name) => derivedEid('helper|' + name))
|
|
41
|
+
* // the persona, `tone` and the edge containing it, `calls` and the edge
|
|
42
|
+
* // that reads it
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export let shipped = (
|
|
46
|
+
files: Record<string, string>,
|
|
47
|
+
eid: (name: string) => Eid,
|
|
48
|
+
): Bundle[] => {
|
|
49
|
+
let read = Object.entries(files).map(([file, text]) => {
|
|
50
|
+
let { meta, body } = front(text, file)
|
|
51
|
+
if (meta.entity) throw new Error(`${file} names an entity: its name does`)
|
|
52
|
+
let { contains, reads, ...row } = meta as Bundle & {
|
|
53
|
+
contains?: unknown
|
|
54
|
+
reads?: unknown
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
name: file.replace(/\.md$/, ''),
|
|
58
|
+
contains,
|
|
59
|
+
reads,
|
|
60
|
+
row: {
|
|
61
|
+
...row,
|
|
62
|
+
entity: { eid: eid(file.replace(/\.md$/, '')) },
|
|
63
|
+
[DOC]: {
|
|
64
|
+
...row[DOC] as Comp,
|
|
65
|
+
body: body.replace(/^\n+/, '').replace(/\n+$/, ''),
|
|
66
|
+
},
|
|
67
|
+
} as Bundle,
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
let personas = read.filter((f) => f.row[PERSONA])
|
|
71
|
+
if (personas.length != 1) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`a persona's files hold one persona, not ${personas.length}`,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
let [persona] = personas
|
|
77
|
+
let listed = (names: unknown) => Array.isArray(names) ? names.map(String) : []
|
|
78
|
+
let lists: [string, string[]][] = [
|
|
79
|
+
[CONTAINS, listed(persona.contains)],
|
|
80
|
+
[READS, listed(persona.reads)],
|
|
81
|
+
]
|
|
82
|
+
let names = lists.flatMap(([, n]) => n)
|
|
83
|
+
let docs = read.filter((f) => f != persona)
|
|
84
|
+
let by = new Map(docs.map((f) => [f.name, f.row]))
|
|
85
|
+
let missing = names.filter((n) => !by.has(n))
|
|
86
|
+
if (missing.length) {
|
|
87
|
+
throw new Error(`${persona.name} lists ${missing.join(', ')}: no file`)
|
|
88
|
+
}
|
|
89
|
+
let loose = docs.filter((f) => !names.includes(f.name)).map((f) => f.name)
|
|
90
|
+
if (loose.length) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`${persona.name} neither contains nor reads ${loose.join(', ')}`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
let from = persona.row.entity.eid
|
|
96
|
+
return [
|
|
97
|
+
persona.row,
|
|
98
|
+
...lists.flatMap(([tag, list]) =>
|
|
99
|
+
list.flatMap((n, i) => [
|
|
100
|
+
by.get(n)!,
|
|
101
|
+
link(from, tag, by.get(n)!.entity.eid, i + 1),
|
|
102
|
+
])
|
|
103
|
+
),
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* What a store whose entities `storage` reads still needs written to keep a
|
|
109
|
+
* persona as `rows` ({@link shipped}) say: each row it does not already hold
|
|
110
|
+
* as they say it, and the removal of each `contains` or `reads` edge the
|
|
111
|
+
* persona has there that `rows` does not. Nothing, where the store already
|
|
112
|
+
* keeps it.
|
|
113
|
+
*/
|
|
114
|
+
export let kept = async (storage: Reads, rows: Bundle[]): Promise<Bundle[]> => {
|
|
115
|
+
let persona = rows.find((b) => b[PERSONA])
|
|
116
|
+
if (!persona) return []
|
|
117
|
+
let edges = (tag: string) =>
|
|
118
|
+
storage.read(and(eq(`${EDGE}.from`, persona.entity.eid), present(tag)))
|
|
119
|
+
let [held, contained, read] = await Promise.all([
|
|
120
|
+
storage.get(rows.map((b) => b.entity.eid)),
|
|
121
|
+
edges(CONTAINS),
|
|
122
|
+
edges(READS),
|
|
123
|
+
])
|
|
124
|
+
let links = [...contained, ...read]
|
|
125
|
+
let said = new Set(rows.map((b) => b.entity.eid))
|
|
126
|
+
return [
|
|
127
|
+
...links.filter((b) => !said.has(b.entity.eid))
|
|
128
|
+
.map((b) => ({ entity: b.entity, $delete: true })),
|
|
129
|
+
...unheld(held, rows),
|
|
130
|
+
]
|
|
131
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// A checkout's skills: its working tree's directories in place of its graph
|
|
2
|
+
// skills. A local view never imports files into the graph: uncommitted edits
|
|
3
|
+
// belong to the checkout until its mirror runs.
|
|
4
|
+
import * as fs from "@yaks/file/io";
|
|
5
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
6
|
+
import { Refused } from "@yaks/graph/errors";
|
|
7
|
+
import { and, eq, every } from "@yaks/query";
|
|
8
|
+
import { locate } from "@yaks/git/host";
|
|
9
|
+
import { parseSkill } from "./skill-text.js";
|
|
10
|
+
import { folder, graphSkill, pathOf, repoSkills, skillLocations, sorted } from "./skills.js";
|
|
11
|
+
let text = (b, name, prop)=>{
|
|
12
|
+
let value = b[name]?.[prop];
|
|
13
|
+
return typeof value == 'string' ? value : undefined;
|
|
14
|
+
};
|
|
15
|
+
// Never follow a link in the skill tree. Missing files represent deletions,
|
|
16
|
+
// not permission to fall back to the graph's last imported instructions.
|
|
17
|
+
let plain = async (path, directory)=>{
|
|
18
|
+
try {
|
|
19
|
+
let stat = await fs.lstat(path);
|
|
20
|
+
return !stat.isSymlink && (directory ? stat.isDirectory : stat.isFile);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (fs.isNotFound(error)) return false;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
let localSkills = async (g, root, graph)=>{
|
|
27
|
+
let dir = `${root}/.claude/skills`;
|
|
28
|
+
if (!await plain(`${root}/.claude`, true) || !await plain(dir, true)) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
let byPath = new Map();
|
|
32
|
+
let locations = await skillLocations(g, graph);
|
|
33
|
+
for (let skill of graph){
|
|
34
|
+
let location = locations.get(skill.entity.eid);
|
|
35
|
+
let path = location && text(location, 'file', 'path');
|
|
36
|
+
if (path) byPath.set(path, skill);
|
|
37
|
+
}
|
|
38
|
+
let skills = [];
|
|
39
|
+
for await (let entry of fs.readDir(dir)){
|
|
40
|
+
if (!entry.isDirectory || entry.isSymlink || !folder(entry.name)) continue;
|
|
41
|
+
let path = pathOf(entry.name);
|
|
42
|
+
let local = `${root}/${path}`;
|
|
43
|
+
if (!await plain(`${dir}/${entry.name}`, true) || !await plain(local, false)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let source;
|
|
47
|
+
try {
|
|
48
|
+
source = await fs.readTextFile(local);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (fs.isNotFound(error)) continue;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
let parsed;
|
|
54
|
+
try {
|
|
55
|
+
parsed = parseSkill(source, entry.name);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (!(error instanceof Refused)) throw error;
|
|
58
|
+
throw new Refused(`Cannot load ${path}: ${String(error)}`);
|
|
59
|
+
}
|
|
60
|
+
let held = byPath.get(path);
|
|
61
|
+
skills.push({
|
|
62
|
+
...held,
|
|
63
|
+
entity: held?.entity ?? {
|
|
64
|
+
eid: derivedEid(`view:skill:${root}:${path}`)
|
|
65
|
+
},
|
|
66
|
+
...parsed
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return sorted(skills);
|
|
70
|
+
};
|
|
71
|
+
/** Without a cwd, read the graph. With one, the checkout's actual directories
|
|
72
|
+
* replace its graph skills, including untracked additions and deletions. */ export let skillsAt = async (g, cwd)=>{
|
|
73
|
+
if (cwd == undefined) return repoSkills(g);
|
|
74
|
+
let at = await locate(cwd);
|
|
75
|
+
if (!at) return [];
|
|
76
|
+
let repositories = g.vocab.comps.includes('repository') ? await g.read(and(eq('repository.common', at.common), every())) : [];
|
|
77
|
+
// An unregistered checkout still has readable local skills, but neither its
|
|
78
|
+
// repository nor their temporary view identities are written to the graph.
|
|
79
|
+
let repository = repositories[0]?.entity.eid ?? `view:repository:${at.common}`;
|
|
80
|
+
return localSkills(g, at.path, await repoSkills(g, repository));
|
|
81
|
+
};
|
|
82
|
+
/** Select an exact folder name. Without a checkout, duplicate names across
|
|
83
|
+
* repositories are ambiguous rather than silently choosing one. */ export let loadSkill = async (g, title, cwd)=>{
|
|
84
|
+
if (cwd == undefined) return graphSkill(g, title);
|
|
85
|
+
let found = (await skillsAt(g, cwd)).filter((b)=>text(b, 'doc', 'title') == title);
|
|
86
|
+
if (!found.length) throw new Refused(`No skill named ${title}`);
|
|
87
|
+
if (found.length > 1) {
|
|
88
|
+
throw new Refused(`Skill ${title} belongs to more than one repository; supply cwd`);
|
|
89
|
+
}
|
|
90
|
+
return found[0];
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=skill-checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-checkout.js","sources":["./skill-checkout.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,gDAAgD;AAChD,YAAY,6BAAkC;AAE9C,SAAS,UAAU,oCAAyC;AAC5D,SAAS,OAAO,kCAAuC;AACvD,SAAS,GAAG,EAAE,EAAE,EAAE,KAAK,2BAAgC;AACvD,SAAS,MAAM,8BAAmC;AAClD,SAAS,UAAU,0BAAyB;AAC5C,SACE,MAAM,EACN,UAAU,E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S,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,IAC3C,KAAK,GAAG,OAAO,YAAY;EAE7B,IAAI,CAAC,MAAM,MAAM,EAAE,MAAM,IAAI,QAAQ,CAAC,eAAe,EAAE,OAAO;EAC9D,IAAI,MAAM,MAAM,GAAG,GAAG;IACpB,MAAM,IAAI,QACR,CAAC,MAAM,EAAE,MAAM,gDAAgD,CAAC;EAEpE;EACA,OAAO,KAAK,CAAC,EAAE;AACjB,EAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// A checkout's skills: its working tree's directories in place of its graph
|
|
2
|
+
// skills. A local view never imports files into the graph: uncommitted edits
|
|
3
|
+
// belong to the checkout until its mirror runs.
|
|
4
|
+
import * as fs from '@yaks/file/io'
|
|
5
|
+
import type { Bundle, Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
7
|
+
import { Refused } from '@yaks/graph/errors'
|
|
8
|
+
import { and, eq, every } from '@yaks/query'
|
|
9
|
+
import { locate } from '@yaks/git/host'
|
|
10
|
+
import { parseSkill } from './skill-text.js'
|
|
11
|
+
import {
|
|
12
|
+
folder,
|
|
13
|
+
graphSkill,
|
|
14
|
+
pathOf,
|
|
15
|
+
repoSkills,
|
|
16
|
+
skillLocations,
|
|
17
|
+
sorted,
|
|
18
|
+
} from './skills.js'
|
|
19
|
+
|
|
20
|
+
let text = (b: Bundle, name: string, prop: string): string | undefined => {
|
|
21
|
+
let value = (b[name] as Comp | undefined)?.[prop]
|
|
22
|
+
return typeof value == 'string' ? value : undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Never follow a link in the skill tree. Missing files represent deletions,
|
|
26
|
+
// not permission to fall back to the graph's last imported instructions.
|
|
27
|
+
let plain = async (path: string, directory: boolean): Promise<boolean> => {
|
|
28
|
+
try {
|
|
29
|
+
let stat = await fs.lstat(path)
|
|
30
|
+
return !stat.isSymlink && (directory ? stat.isDirectory : stat.isFile)
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (fs.isNotFound(error)) return false
|
|
33
|
+
throw error
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let localSkills = async (
|
|
38
|
+
g: Graph,
|
|
39
|
+
root: string,
|
|
40
|
+
graph: Bundle[],
|
|
41
|
+
): Promise<Bundle[]> => {
|
|
42
|
+
let dir = `${root}/.claude/skills`
|
|
43
|
+
if (!await plain(`${root}/.claude`, true) || !await plain(dir, true)) {
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
let byPath = new Map<string, Bundle>()
|
|
47
|
+
let locations = await skillLocations(g, graph)
|
|
48
|
+
for (let skill of graph) {
|
|
49
|
+
let location = locations.get(skill.entity.eid)
|
|
50
|
+
let path = location && text(location, 'file', 'path')
|
|
51
|
+
if (path) byPath.set(path, skill)
|
|
52
|
+
}
|
|
53
|
+
let skills: Bundle[] = []
|
|
54
|
+
for await (let entry of fs.readDir(dir)) {
|
|
55
|
+
if (!entry.isDirectory || entry.isSymlink || !folder(entry.name)) continue
|
|
56
|
+
let path = pathOf(entry.name)
|
|
57
|
+
let local = `${root}/${path}`
|
|
58
|
+
if (
|
|
59
|
+
!await plain(`${dir}/${entry.name}`, true) || !await plain(local, false)
|
|
60
|
+
) {
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
let source: string
|
|
64
|
+
try {
|
|
65
|
+
source = await fs.readTextFile(local)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (fs.isNotFound(error)) continue
|
|
68
|
+
throw error
|
|
69
|
+
}
|
|
70
|
+
let parsed: ReturnType<typeof parseSkill>
|
|
71
|
+
try {
|
|
72
|
+
parsed = parseSkill(source, entry.name)
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!(error instanceof Refused)) throw error
|
|
75
|
+
throw new Refused(`Cannot load ${path}: ${String(error)}`)
|
|
76
|
+
}
|
|
77
|
+
let held = byPath.get(path)
|
|
78
|
+
skills.push({
|
|
79
|
+
...held,
|
|
80
|
+
entity: held?.entity ?? { eid: derivedEid(`view:skill:${root}:${path}`) },
|
|
81
|
+
...parsed,
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
return sorted(skills)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Without a cwd, read the graph. With one, the checkout's actual directories
|
|
88
|
+
* replace its graph skills, including untracked additions and deletions. */
|
|
89
|
+
export let skillsAt = async (g: Graph, cwd?: string): Promise<Bundle[]> => {
|
|
90
|
+
if (cwd == undefined) return repoSkills(g)
|
|
91
|
+
let at = await locate(cwd)
|
|
92
|
+
if (!at) return []
|
|
93
|
+
let repositories = g.vocab.comps.includes('repository')
|
|
94
|
+
? await g.read(and(eq('repository.common', at.common), every()))
|
|
95
|
+
: []
|
|
96
|
+
// An unregistered checkout still has readable local skills, but neither its
|
|
97
|
+
// repository nor their temporary view identities are written to the graph.
|
|
98
|
+
let repository = repositories[0]?.entity.eid ??
|
|
99
|
+
`view:repository:${at.common}`
|
|
100
|
+
return localSkills(g, at.path, await repoSkills(g, repository))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Select an exact folder name. Without a checkout, duplicate names across
|
|
104
|
+
* repositories are ambiguous rather than silently choosing one. */
|
|
105
|
+
export let loadSkill = async (
|
|
106
|
+
g: Graph,
|
|
107
|
+
title: string,
|
|
108
|
+
cwd?: string,
|
|
109
|
+
): Promise<Bundle> => {
|
|
110
|
+
if (cwd == undefined) return graphSkill(g, title)
|
|
111
|
+
let found = (await skillsAt(g, cwd)).filter((b) =>
|
|
112
|
+
text(b, 'doc', 'title') == title
|
|
113
|
+
)
|
|
114
|
+
if (!found.length) throw new Refused(`No skill named ${title}`)
|
|
115
|
+
if (found.length > 1) {
|
|
116
|
+
throw new Refused(
|
|
117
|
+
`Skill ${title} belongs to more than one repository; supply cwd`,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return found[0]
|
|
121
|
+
}
|