@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.
Files changed (115) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +401 -2
  3. package/_dist/comp.d.ts +13 -0
  4. package/_dist/comp.d.ts.map +1 -0
  5. package/_dist/effects.d.ts +22 -0
  6. package/_dist/effects.d.ts.map +1 -0
  7. package/_dist/mod.d.ts +40 -0
  8. package/_dist/mod.d.ts.map +1 -0
  9. package/_dist/name.d.ts +49 -0
  10. package/_dist/name.d.ts.map +1 -0
  11. package/_dist/owed.d.ts +56 -0
  12. package/_dist/owed.d.ts.map +1 -0
  13. package/_dist/part.d.ts +4 -0
  14. package/_dist/part.d.ts.map +1 -0
  15. package/_dist/shipped.d.ts +30 -0
  16. package/_dist/shipped.d.ts.map +1 -0
  17. package/_dist/skill-checkout.d.ts +6 -0
  18. package/_dist/skill-checkout.d.ts.map +1 -0
  19. package/_dist/skill-effects.d.ts +25 -0
  20. package/_dist/skill-effects.d.ts.map +1 -0
  21. package/_dist/skill-mirror-io.d.ts +7 -0
  22. package/_dist/skill-mirror-io.d.ts.map +1 -0
  23. package/_dist/skill-mirror.d.ts +15 -0
  24. package/_dist/skill-mirror.d.ts.map +1 -0
  25. package/_dist/skill-text.d.ts +28 -0
  26. package/_dist/skill-text.d.ts.map +1 -0
  27. package/_dist/skills.d.ts +22 -0
  28. package/_dist/skills.d.ts.map +1 -0
  29. package/_dist/tools.d.ts +9 -0
  30. package/_dist/tools.d.ts.map +1 -0
  31. package/_dist/ui.d.ts +6 -0
  32. package/_dist/ui.d.ts.map +1 -0
  33. package/_dist/views.d.ts +19 -0
  34. package/_dist/views.d.ts.map +1 -0
  35. package/_dist/vocab.d.ts +7 -0
  36. package/_dist/vocab.d.ts.map +1 -0
  37. package/_dist/voice.d.ts +47 -0
  38. package/_dist/voice.d.ts.map +1 -0
  39. package/_dist/worn.d.ts +55 -0
  40. package/_dist/worn.d.ts.map +1 -0
  41. package/carried.js +201 -0
  42. package/carried.js.map +1 -0
  43. package/carried.ts +269 -0
  44. package/comp.js +31 -0
  45. package/comp.js.map +1 -0
  46. package/comp.ts +38 -0
  47. package/deno.json +1 -0
  48. package/desk.js +201 -0
  49. package/desk.js.map +1 -0
  50. package/desk.ts +301 -0
  51. package/effects.js +106 -0
  52. package/effects.js.map +1 -0
  53. package/effects.ts +120 -0
  54. package/files.js +305 -0
  55. package/files.js.map +1 -0
  56. package/files.ts +319 -0
  57. package/inspect.js +66 -0
  58. package/inspect.js.map +1 -0
  59. package/inspect.ts +30 -0
  60. package/mod.js +40 -0
  61. package/mod.js.map +1 -0
  62. package/mod.ts +61 -0
  63. package/name.js +161 -0
  64. package/name.js.map +1 -0
  65. package/name.ts +184 -0
  66. package/owed.js +196 -0
  67. package/owed.js.map +1 -0
  68. package/owed.ts +256 -0
  69. package/package.json +83 -4
  70. package/part.js +4 -0
  71. package/part.js.map +1 -0
  72. package/part.ts +4 -0
  73. package/shipped.js +130 -0
  74. package/shipped.js.map +1 -0
  75. package/shipped.ts +131 -0
  76. package/skill-checkout.js +92 -0
  77. package/skill-checkout.js.map +1 -0
  78. package/skill-checkout.ts +121 -0
  79. package/skill-effects.js +244 -0
  80. package/skill-effects.js.map +1 -0
  81. package/skill-effects.ts +274 -0
  82. package/skill-mirror-io.js +193 -0
  83. package/skill-mirror-io.js.map +1 -0
  84. package/skill-mirror-io.ts +212 -0
  85. package/skill-mirror.js +659 -0
  86. package/skill-mirror.js.map +1 -0
  87. package/skill-mirror.ts +640 -0
  88. package/skill-text.js +158 -0
  89. package/skill-text.js.map +1 -0
  90. package/skill-text.ts +183 -0
  91. package/skills.js +238 -0
  92. package/skills.js.map +1 -0
  93. package/skills.ts +383 -0
  94. package/text.js +59 -0
  95. package/text.js.map +1 -0
  96. package/text.ts +60 -0
  97. package/tools.js +76 -0
  98. package/tools.js.map +1 -0
  99. package/tools.ts +91 -0
  100. package/ui.js +19 -0
  101. package/ui.js.map +1 -0
  102. package/ui.ts +34 -0
  103. package/views.js +27 -0
  104. package/views.js.map +1 -0
  105. package/views.ts +29 -0
  106. package/vocab.js +14 -0
  107. package/vocab.js.map +1 -0
  108. package/vocab.json +270 -0
  109. package/vocab.ts +16 -0
  110. package/voice.js +105 -0
  111. package/voice.js.map +1 -0
  112. package/voice.ts +133 -0
  113. package/worn.js +328 -0
  114. package/worn.js.map +1 -0
  115. package/worn.ts +336 -0
package/files.ts ADDED
@@ -0,0 +1,319 @@
1
+ // The persona files: each project's personas written into its checkout, where
2
+ // a harness started there finds them. The persona a project `contains` is
3
+ // `.tasks/AGENTS.md`, which a repository's CLAUDE.md and AGENTS.md link to,
4
+ // and every other persona whose `home` is the project is
5
+ // `.tasks/personas/<name>.md`, which `.claude/agents/<name>.md` links to. A
6
+ // sub-project without a checkout of its own lands in its nearest ancestor's,
7
+ // so its personas, its common one included, are specialists there.
8
+ //
9
+ // The text is {@link voice}'s. A file adds only what being a file needs: a line
10
+ // saying where to edit it, and, for a specialist, the frontmatter a Claude
11
+ // agent file has to open with (without `name` and `description` first, claude
12
+ // reports the agent as not found). A specialist says its home's common persona
13
+ // too, and is read beside AGENTS.md, so what AGENTS.md already says is left out
14
+ // of it rather than said twice. Which persona is a project's common one, and
15
+ // the text of its file, are ./owed.ts's, the same answers a harness asks for an
16
+ // agent's own checkout.
17
+ //
18
+ // A write-only @yaks/mirror binding: the graph owns these files. A hand edit
19
+ // is put back, and one made while the graph also moved is a conflict, left as
20
+ // it is. Every file already under an owned `.tasks` directory is in the binding
21
+ // too, so a renamed or deleted persona's file is removed.
22
+ //
23
+ // The links in `.claude/agents` follow the files: a specialist no link names
24
+ // gets one, and a link into `.tasks/personas` naming no current file is
25
+ // removed, so a renamed persona's link moves with its file. Anything else there is a
26
+ // person's own agent, left alone.
27
+ //
28
+ // Which checkout is borrowed, not declared here: a project's `repo.repository`
29
+ // (@yaks/project) and that repository's main worktree (@yaks/git), the one
30
+ // whose own Git directory is the repository's common one. Every linked
31
+ // worktree is an agent's or a session's, whoever cut it; the main one is where
32
+ // a person works. A graph composed without either package has no checkouts,
33
+ // and writes no files. An archived project keeps what it last had.
34
+
35
+ import * as fs from '@yaks/file/io'
36
+
37
+ import { type Binding, memo, present as exists } from '@yaks/mirror'
38
+ import { and, eq, every, type Input, list, present } from '@yaks/query'
39
+ import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
40
+ import { DOC, TITLE } from '@yaks/doc'
41
+ import { human, parse } from '@yaks/id'
42
+ import { lineage } from '@yaks/project'
43
+ import { PERSONA } from './comp.js'
44
+ import { voice, type Worn } from './voice.js'
45
+ import { beside, fold, wear } from './worn.js'
46
+ import { banner, common, projection } from './owed.js'
47
+
48
+ /** One file the graph says a checkout holds. */
49
+ export type File = { path: string; text: string }
50
+
51
+ let comp = (b: Bundle | undefined, name: string): Comp =>
52
+ (b?.[name] ?? {}) as Comp
53
+
54
+ let str = (v: unknown): string => v == null ? '' : String(v)
55
+
56
+ let value = (eids: Eid[]): Input => eids.length == 1 ? eids[0] : list(...eids)
57
+
58
+ let eidOf = (b: Bundle): Eid => b.entity.eid
59
+
60
+ // Each project's checkout root: the main worktree of its repository, which
61
+ // Git knows by its own directory being the common one. Whoever cut a linked
62
+ // worktree, by hand or by a tool, it is never the one. A checkout moved
63
+ // leaves its old row behind, so the first by path wins, and the answer never
64
+ // depends on the order rows come back in.
65
+ let checkouts = async (g: Graph): Promise<Map<Eid, string>> => {
66
+ let out = new Map<Eid, string>()
67
+ let needs = ['repo', 'repository', 'worktree']
68
+ if (!needs.every((c) => g.vocab.comp(c))) return out
69
+ let projects = (await g.storage.read(
70
+ and(present('project'), present('repo')),
71
+ )).filter((b) => !b.archived && comp(b, 'repo').repository)
72
+ let repos = [...new Set(projects.map((b) => str(comp(b, 'repo').repository)))]
73
+ if (!repos.length) return out
74
+ let common = new Map<Eid, string>()
75
+ for (let r of await g.get(repos)) {
76
+ let dir = str(comp(r, 'repository').common)
77
+ if (dir) common.set(eidOf(r), dir)
78
+ }
79
+ if (!common.size) return out
80
+ let mains = (await g.storage.read(
81
+ and(eq('worktree.gitdir', value([...new Set(common.values())])), every()),
82
+ ))
83
+ .map((b): Comp => ({
84
+ ...comp(b, 'worktree'),
85
+ path: comp(b, 'workspace').root,
86
+ }))
87
+ .filter((w) => w.path && w.gitdir == common.get(str(w.repository)))
88
+ .sort((a, b) => str(a.path).localeCompare(str(b.path)))
89
+ for (let p of projects) {
90
+ let tree = mains.find((w) => w.repository == comp(p, 'repo').repository)
91
+ if (tree) out.set(eidOf(p), str(tree.path))
92
+ }
93
+ return out
94
+ }
95
+
96
+ // The name a persona registers under as a Claude agent: its alias
97
+ // (@yaks/alias keeps one as a `key`), reduced to claude's charset, or its
98
+ // lowered id where it has none. An alias that is itself an id (`N-4568`, an
99
+ // old number kept when a series was renumbered) is no name. The file is named
100
+ // for it too, because claude keys an agent by its frontmatter `name`, and a
101
+ // harness resolves the file by its own.
102
+ let names = async (g: Graph, eids: Eid[]): Promise<Map<Eid, string>> => {
103
+ let out = new Map<Eid, string>()
104
+ if (!eids.length || !g.vocab.comp('alias') || !g.vocab.comp('key')) {
105
+ return out
106
+ }
107
+ let keys = (await g.storage.read(
108
+ and(eq('key.of', value(eids)), present('alias')),
109
+ )).map((b) => comp(b, 'key'))
110
+ .filter((k) => !parse(str(k.value)))
111
+ .sort((a, b) => str(a.value).localeCompare(str(b.value)))
112
+ for (let k of keys) {
113
+ if (!out.has(str(k.of))) out.set(str(k.of), str(k.value))
114
+ }
115
+ return out
116
+ }
117
+
118
+ let slug = (name: string): string =>
119
+ name.toLowerCase().replace(/[^a-z0-9-]+/g, '-')
120
+
121
+ /** What the persona files are: each file's path and text, the `.tasks`
122
+ * directories they are written into (where a file the graph no longer says is
123
+ * found), and every entity a file says something about. */
124
+ export type Files = { files: File[]; roots: string[]; said: Set<Eid> }
125
+
126
+ /** Every persona file the graph says its checkouts hold. */
127
+ export let personaFiles = async (g: Graph): Promise<Files> => {
128
+ let homes = await checkouts(g)
129
+ let files: File[] = []
130
+ let said = new Set<Eid>()
131
+ if (!homes.size) return { files, roots: [], said }
132
+ let id = human(g.vocab)
133
+ let render = voice(g.vocab)
134
+ let wearing = wear(g.storage, g.vocab)
135
+ let heard = (w: Worn): Worn => {
136
+ for (let b of [w.persona, ...w.contains, ...w.names]) said.add(eidOf(b))
137
+ return w
138
+ }
139
+ // Each project's common persona along its lineage, read once a pass.
140
+ let shared = new Map<Eid, Worn | undefined>()
141
+ let everyone = async (project: Eid) => {
142
+ if (!shared.has(project)) {
143
+ let w = await common(g, project)
144
+ shared.set(project, w && heard(w))
145
+ }
146
+ return shared.get(project)
147
+ }
148
+ let personas = await g.storage.read(and(present(PERSONA)))
149
+ let named = await names(g, personas.map(eidOf))
150
+ // The checkout each home lands in: the nearest project along its lineage
151
+ // that has one, so a sub-project's personas are written into its parent's.
152
+ let lands = new Map<Eid, Eid | undefined>()
153
+ for (let home of new Set(personas.map((p) => str(comp(p, PERSONA).home)))) {
154
+ if (!home) continue
155
+ let line = (await lineage(g, home)).map(eidOf)
156
+ lands.set(home, line.find((p) => homes.has(p)))
157
+ }
158
+ let head = banner(g.vocab)
159
+ let agents = projection(g.vocab)
160
+ for (let [project, root] of homes) {
161
+ let dir = `${root}/.tasks`
162
+ let base = await everyone(project)
163
+ if (base) files.push({ path: `${dir}/AGENTS.md`, text: agents(base) })
164
+ for (let p of personas) {
165
+ let home = str(comp(p, PERSONA).home)
166
+ if (lands.get(home) != project || eidOf(p) == base?.persona.entity.eid) {
167
+ continue
168
+ }
169
+ let w = await wearing(eidOf(p))
170
+ if (!w) continue
171
+ let own = await everyone(home)
172
+ let whole = heard(own ? fold(w, own) : w)
173
+ let name = slug(named.get(eidOf(p)) ?? id(p))
174
+ let title = str(comp(p, DOC)[TITLE])
175
+ files.push({
176
+ path: `${dir}/personas/${name}.md`,
177
+ text: `---\nname: ${name}\ndescription: ${JSON.stringify(title)}\n` +
178
+ `---\n${head(p)}\n\n${render(base ? beside(whole, base) : whole)}`,
179
+ })
180
+ }
181
+ }
182
+ let roots = [...new Set(homes.values())].map((r) => `${r}/.tasks`)
183
+ return { files, roots, said }
184
+ }
185
+
186
+ // What an owned directory holds now: its AGENTS.md and its personas. Owned
187
+ // end to end, so anything of those two shapes is ours.
188
+ let held = (dir: string): string[] => {
189
+ let out = [`${dir}/AGENTS.md`]
190
+ try {
191
+ for (let e of fs.readDirSync(`${dir}/personas`)) {
192
+ if (e.isFile && e.name.endsWith('.md')) {
193
+ out.push(`${dir}/personas/${e.name}`)
194
+ }
195
+ }
196
+ } catch { /* no specialists here */ }
197
+ return out
198
+ }
199
+
200
+ /** Where a graph remembers what each persona file last agreed on: a file
201
+ * beside its database, or nothing for a graph in memory. */
202
+ export let remembered = (
203
+ db: string | undefined,
204
+ ): Pick<Binding, 'agreed' | 'remember'> =>
205
+ !db || db == ':memory:' ? { agreed: () => Promise.resolve(new Map()) } : memo(
206
+ `${db.slice(0, db.lastIndexOf('/') + 1) || './'}mirror/personas.json`,
207
+ )
208
+
209
+ /** The persona files as a write-only @yaks/mirror binding — hand it to
210
+ * `sync` to write them, or to `plan` to see what would change — the
211
+ * `.claude/agents` links they want made or removed (hand those to `link`),
212
+ * and every entity they say something about. */
213
+ export let personaMirror = async (
214
+ g: Graph,
215
+ memory: Pick<Binding, 'agreed' | 'remember'>,
216
+ ): Promise<{ binding: Binding; links: Link[]; said: Set<Eid> }> => {
217
+ let all = await personaFiles(g)
218
+ let { files, roots, said } = all
219
+ let paths = new Set([...files.map((f) => f.path), ...roots.flatMap(held)])
220
+ return {
221
+ binding: {
222
+ name: 'personas',
223
+ files: () => exists([...paths]),
224
+ values: () =>
225
+ Promise.resolve(new Map(files.map((f) => [f.path, f.text]))),
226
+ ...memory,
227
+ },
228
+ links: agentLinks(all),
229
+ said,
230
+ }
231
+ }
232
+
233
+ let PERSONAS = '/.tasks/personas/'
234
+
235
+ /** One `.claude/agents` link a sync makes, or removes where `to` is absent:
236
+ * the persona file it names, relative to the link. */
237
+ export type Link = { path: string; to?: string }
238
+
239
+ // Whether anything is at a path, a dangling link included.
240
+ let taken = (path: string): boolean => {
241
+ try {
242
+ return !!fs.lstatSync(path)
243
+ } catch {
244
+ return false
245
+ }
246
+ }
247
+
248
+ let linkOf = (path: string): string | undefined => {
249
+ try {
250
+ return fs.readLinkSync(path)
251
+ } catch {
252
+ return undefined
253
+ }
254
+ }
255
+
256
+ /** The `.claude/agents` links the persona files want changed: a specialist
257
+ * whose file no link names gets `<name>.md`, and a link into
258
+ * `.tasks/personas` naming no file the graph still says is removed, so a
259
+ * renamed persona's link moves with its file. A link of another name that
260
+ * names a current file is kept, and a person's own file at a link's path is
261
+ * left. */
262
+ export let agentLinks = ({ files, roots }: Files): Link[] => {
263
+ let current = new Set(files.map((f) => f.path))
264
+ let out: Link[] = []
265
+ for (let root of roots) {
266
+ let dir = `${root.slice(0, -'/.tasks'.length)}/.claude/agents`
267
+ let named = new Set<string>()
268
+ let entries: fs.DirEntry[] = []
269
+ try {
270
+ entries = [...fs.readDirSync(dir)]
271
+ } catch { /* no agents here */ }
272
+ for (let e of entries) {
273
+ let path = `${dir}/${e.name}`
274
+ let to = e.isSymlink ? linkOf(path) : undefined
275
+ if (!to) continue
276
+ let target = fs.resolve(dir, to)
277
+ if (current.has(target)) named.add(target)
278
+ else if (target.startsWith(`${root}/personas/`)) out.push({ path })
279
+ }
280
+ for (let path of current) {
281
+ if (!path.startsWith(`${root}/personas/`) || named.has(path)) continue
282
+ let name = path.slice(path.lastIndexOf('/') + 1)
283
+ let at = `${dir}/${name}`
284
+ if (linkOf(at) == null && taken(at)) continue
285
+ out.push({ path: at, to: `../..${PERSONAS}${name}` })
286
+ }
287
+ }
288
+ return out.sort((a, b) => a.path.localeCompare(b.path))
289
+ }
290
+
291
+ /** Make and remove the links: each made one is swapped in by a rename, so a
292
+ * harness reading it sees the old link or the new one. A failure on one link
293
+ * never stops the others. */
294
+ export let link = async (
295
+ links: Link[],
296
+ ): Promise<{ linked: string[]; unlinked: string[]; failed: string[] }> => {
297
+ let out = {
298
+ linked: [] as string[],
299
+ unlinked: [] as string[],
300
+ failed: [] as string[],
301
+ }
302
+ for (let { path, to } of links) {
303
+ try {
304
+ if (to == null) {
305
+ await fs.remove(path)
306
+ out.unlinked.push(path)
307
+ continue
308
+ }
309
+ await fs.mkdir(fs.dirname(path), { recursive: true })
310
+ let tmp = `${path}.${crypto.randomUUID()}.tmp`
311
+ await fs.symlink(to, tmp)
312
+ await fs.rename(tmp, path)
313
+ out.linked.push(path)
314
+ } catch (e) {
315
+ out.failed.push(`${path}: ${(e as Error).message}`)
316
+ }
317
+ }
318
+ return out
319
+ }
package/inspect.js ADDED
@@ -0,0 +1,66 @@
1
+ // What this package draws, as @yaks/render registrations: the desk of every
2
+ // persona and skill (`Context.Page`, the page the sidebar offers); a persona
3
+ // or a skill opened at the desk (`Context`, the tab it opens on); the body of
4
+ // its Full page, where what it says and every document it carries are typed
5
+ // into (`Full.Body`, and a card's face, `Card.Context`); and what an agent is
6
+ // given, as its Markdown view (`Markdown`, more specific than any doc's).
7
+ // Loaded only by an interface that draws them (./views.ts).
8
+ import { parse } from "@yaks/query";
9
+ import { DeskPage, Workshop } from "./desk.js";
10
+ import { asks, PersonaBody, SkillBody } from "./carried.js";
11
+ import { PersonaText, SkillText } from "./text.js";
12
+ import { PERSONA, SKILL } from "./comp.js";
13
+ let persona = parse(`.doc .${PERSONA}`);
14
+ let skill = parse(`.doc .${SKILL}`);
15
+ /** The views this package draws. */ export let inspectViews = [
16
+ {
17
+ view: 'Context.Page',
18
+ match: true,
19
+ Render: DeskPage
20
+ },
21
+ {
22
+ view: 'Context',
23
+ match: persona,
24
+ Render: Workshop
25
+ },
26
+ {
27
+ view: 'Context',
28
+ match: skill,
29
+ Render: Workshop
30
+ },
31
+ {
32
+ view: 'Full.Body',
33
+ match: persona,
34
+ asks,
35
+ Render: PersonaBody
36
+ },
37
+ {
38
+ view: 'Full.Body',
39
+ match: skill,
40
+ asks,
41
+ Render: SkillBody
42
+ },
43
+ {
44
+ view: 'Card.Context',
45
+ match: persona,
46
+ asks,
47
+ Render: PersonaBody
48
+ },
49
+ {
50
+ view: 'Card.Context',
51
+ match: skill,
52
+ asks,
53
+ Render: SkillBody
54
+ },
55
+ {
56
+ view: 'Markdown',
57
+ match: persona,
58
+ Render: PersonaText
59
+ },
60
+ {
61
+ view: 'Markdown',
62
+ match: skill,
63
+ Render: SkillText
64
+ }
65
+ ];
66
+ //# sourceMappingURL=inspect.js.map
package/inspect.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sources":["./inspect.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,4DAA4D;AAE5D,SAAS,KAAK,2BAAgC;AAE9C,SAAS,QAAQ,EAAE,QAAQ,oBAAmB;AAC9C,SAAS,IAAI,EAAE,WAAW,EAAE,SAAS,uBAAsB;AAC3D,SAAS,WAAW,EAAE,SAAS,oBAAmB;AAClD,SAAS,OAAO,EAAE,KAAK,oBAAmB;AAE1C,IAAI,UAAU,MAAM,CAAC,MAAM,EAAE,SAAS;AACtC,IAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO;AAElC,kCAAkC,GAClC,OAAO,IAAI,eAAuB;EAChC;IAAE,MAAM;IAAgB,OAAO;IAAM,QAAQ;EAAS;EACtD;IAAE,MAAM;IAAW,OAAO;IAAS,QAAQ;EAAS;EACpD;IAAE,MAAM;IAAW,OAAO;IAAO,QAAQ;EAAS;EAClD;IAAE,MAAM;IAAa,OAAO;IAAS;IAAM,QAAQ;EAAY;EAC/D;IAAE,MAAM;IAAa,OAAO;IAAO;IAAM,QAAQ;EAAU;EAC3D;IAAE,MAAM;IAAgB,OAAO;IAAS;IAAM,QAAQ;EAAY;EAClE;IAAE,MAAM;IAAgB,OAAO;IAAO;IAAM,QAAQ;EAAU;EAC9D;IAAE,MAAM;IAAY,OAAO;IAAS,QAAQ;EAAY;EACxD;IAAE,MAAM;IAAY,OAAO;IAAO,QAAQ;EAAU;CACrD,CAAA"}
package/inspect.ts ADDED
@@ -0,0 +1,30 @@
1
+ // What this package draws, as @yaks/render registrations: the desk of every
2
+ // persona and skill (`Context.Page`, the page the sidebar offers); a persona
3
+ // or a skill opened at the desk (`Context`, the tab it opens on); the body of
4
+ // its Full page, where what it says and every document it carries are typed
5
+ // into (`Full.Body`, and a card's face, `Card.Context`); and what an agent is
6
+ // given, as its Markdown view (`Markdown`, more specific than any doc's).
7
+ // Loaded only by an interface that draws them (./views.ts).
8
+
9
+ import { parse } from '@yaks/query'
10
+ import type { View } from 'jsr:@yaks/inspect@0.2.36'
11
+ import { DeskPage, Workshop } from './desk.js'
12
+ import { asks, PersonaBody, SkillBody } from './carried.js'
13
+ import { PersonaText, SkillText } from './text.js'
14
+ import { PERSONA, SKILL } from './comp.js'
15
+
16
+ let persona = parse(`.doc .${PERSONA}`)
17
+ let skill = parse(`.doc .${SKILL}`)
18
+
19
+ /** The views this package draws. */
20
+ export let inspectViews: View[] = [
21
+ { view: 'Context.Page', match: true, Render: DeskPage },
22
+ { view: 'Context', match: persona, Render: Workshop },
23
+ { view: 'Context', match: skill, Render: Workshop },
24
+ { view: 'Full.Body', match: persona, asks, Render: PersonaBody },
25
+ { view: 'Full.Body', match: skill, asks, Render: SkillBody },
26
+ { view: 'Card.Context', match: persona, asks, Render: PersonaBody },
27
+ { view: 'Card.Context', match: skill, asks, Render: SkillBody },
28
+ { view: 'Markdown', match: persona, Render: PersonaText },
29
+ { view: 'Markdown', match: skill, Render: SkillText },
30
+ ]
package/mod.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Who is acting, what they are responsible for, and the instructions they run
3
+ * with. A `person` is a human being the graph knows by name; a `persona` is a
4
+ * set of instructions an agent runs with, held in the `doc` body on the same
5
+ * entity; and a `role` is what an agent running one is responsible for, and
6
+ * whether it runs in this process or another. When a role next runs is a
7
+ * `@yaks/wake` wake pointing at it, where it works is a `@yaks/git` worktree,
8
+ * and what it last decided is `@yaks/kernel`'s `decided` — the role keeps no
9
+ * second copy of any of them.
10
+ *
11
+ * Besides those components, this package renders one document. A persona has
12
+ * edges to the documents it includes in full (`contains`) and the documents it
13
+ * only mentions by id (`reads`); {@link wear} reads them out of a storage and
14
+ * {@link voice} renders the set as markdown — the text an agent is given at
15
+ * the top of its context.
16
+ *
17
+ * ```ts ignore
18
+ * import { voice, wear } from '@yaks/persona'
19
+ *
20
+ * let worn = await wear(storage, vocab)('N-1')
21
+ * if (worn) console.log(voice(vocab)(worn))
22
+ * ```
23
+ *
24
+ * It returns text. Where that text goes — a file, a repo, the system prompt
25
+ * of a spawned agent — is the caller's decision. {@link owed} is what a
26
+ * harness asks before it starts an agent: the persona the agent's checkout
27
+ * carries, or the one {@link common} to the work it is on, unless an
28
+ * instruction file its provider reads there already says it. One caller ships beside it
29
+ * and stays out of this entry point, because it writes files: each project's
30
+ * personas in its checkout, `persona_sync` in `./tools` and kept current by
31
+ * `./effects`.
32
+ *
33
+ * @module
34
+ */ export { PERSON, PERSONA, personaDoc, SKILL } from "./comp.js";
35
+ export { NAMED, PART, voice } from "./voice.js";
36
+ export { beside, CONTAINS, fold, offer, QUERY, READS, served, TOOL, wear, wearLayers } from "./worn.js";
37
+ export { christened, given, LONGEST, named, NAMES, pick } from "./name.js";
38
+ export { carried, common, owed, unsaid, wearing } from "./owed.js";
39
+ export { kept, shipped } from "./shipped.js";
40
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCC,GAED,SAAS,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,oBAAmB;AAC9D,SAAS,KAAK,EAAE,IAAI,EAAE,KAAK,qBAA+B;AAC1D,SACE,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EAEL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,oBACM;AAClB,SAAS,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,oBAAmB;AAC1E,SAEE,OAAO,EACP,MAAM,EAEN,IAAI,EACJ,MAAM,EACN,OAAO,oBACS;AAClB,SAAS,IAAI,EAAE,OAAO,uBAAsB"}
package/mod.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Who is acting, what they are responsible for, and the instructions they run
3
+ * with. A `person` is a human being the graph knows by name; a `persona` is a
4
+ * set of instructions an agent runs with, held in the `doc` body on the same
5
+ * entity; and a `role` is what an agent running one is responsible for, and
6
+ * whether it runs in this process or another. When a role next runs is a
7
+ * `@yaks/wake` wake pointing at it, where it works is a `@yaks/git` worktree,
8
+ * and what it last decided is `@yaks/kernel`'s `decided` — the role keeps no
9
+ * second copy of any of them.
10
+ *
11
+ * Besides those components, this package renders one document. A persona has
12
+ * edges to the documents it includes in full (`contains`) and the documents it
13
+ * only mentions by id (`reads`); {@link wear} reads them out of a storage and
14
+ * {@link voice} renders the set as markdown — the text an agent is given at
15
+ * the top of its context.
16
+ *
17
+ * ```ts ignore
18
+ * import { voice, wear } from '@yaks/persona'
19
+ *
20
+ * let worn = await wear(storage, vocab)('N-1')
21
+ * if (worn) console.log(voice(vocab)(worn))
22
+ * ```
23
+ *
24
+ * It returns text. Where that text goes — a file, a repo, the system prompt
25
+ * of a spawned agent — is the caller's decision. {@link owed} is what a
26
+ * harness asks before it starts an agent: the persona the agent's checkout
27
+ * carries, or the one {@link common} to the work it is on, unless an
28
+ * instruction file its provider reads there already says it. One caller ships beside it
29
+ * and stays out of this entry point, because it writes files: each project's
30
+ * personas in its checkout, `persona_sync` in `./tools` and kept current by
31
+ * `./effects`.
32
+ *
33
+ * @module
34
+ */
35
+
36
+ export { PERSON, PERSONA, personaDoc, SKILL } from './comp.js'
37
+ export { NAMED, PART, voice, type Worn } from './voice.js'
38
+ export {
39
+ beside,
40
+ CONTAINS,
41
+ fold,
42
+ offer,
43
+ QUERY,
44
+ READS,
45
+ type Reads,
46
+ served,
47
+ TOOL,
48
+ wear,
49
+ wearLayers,
50
+ } from './worn.js'
51
+ export { christened, given, LONGEST, named, NAMES, pick } from './name.js'
52
+ export {
53
+ type As,
54
+ carried,
55
+ common,
56
+ type Owed,
57
+ owed,
58
+ unsaid,
59
+ wearing,
60
+ } from './owed.js'
61
+ export { kept, shipped } from './shipped.js'
package/name.js ADDED
@@ -0,0 +1,161 @@
1
+ // What a persona is called: its `doc{title}`, the name alone. A new one is
2
+ // given one of NAMES, clear of the names of those its people already reach
3
+ // (`christened`), and a person may give it another (`given`), or give it one
4
+ // of their own as it is made (`named`).
5
+ import { CallError } from "@yaks/tools/errors";
6
+ /** The names a new persona is given: short, plain to say aloud, mostly trees
7
+ * and creatures. */ export let NAMES = [
8
+ 'Acorn',
9
+ 'Alder',
10
+ 'Amos',
11
+ 'Arden',
12
+ 'Ash',
13
+ 'Aspen',
14
+ 'Badger',
15
+ 'Barley',
16
+ 'Bear',
17
+ 'Birch',
18
+ 'Bison',
19
+ 'Boulder',
20
+ 'Bracken',
21
+ 'Bram',
22
+ 'Bramble',
23
+ 'Briar',
24
+ 'Burr',
25
+ 'Cedar',
26
+ 'Chestnut',
27
+ 'Cinder',
28
+ 'Clove',
29
+ 'Clover',
30
+ 'Copper',
31
+ 'Cove',
32
+ 'Cypress',
33
+ 'Dell',
34
+ 'Elm',
35
+ 'Ember',
36
+ 'Ezra',
37
+ 'Felix',
38
+ 'Fern',
39
+ 'Finch',
40
+ 'Flint',
41
+ 'Ford',
42
+ 'Granite',
43
+ 'Hawthorn',
44
+ 'Hickory',
45
+ 'Jasper',
46
+ 'Juniper',
47
+ 'Kestrel',
48
+ 'Kip',
49
+ 'Kit',
50
+ 'Larch',
51
+ 'Lark',
52
+ 'Levi',
53
+ 'Linden',
54
+ 'Maple',
55
+ 'Milo',
56
+ 'Moose',
57
+ 'Moss',
58
+ 'Oak',
59
+ 'Ollie',
60
+ 'Otto',
61
+ 'Pine',
62
+ 'Pip',
63
+ 'Quill',
64
+ 'Reed',
65
+ 'Ridge',
66
+ 'Rook',
67
+ 'Rowan',
68
+ 'Rusty',
69
+ 'Rye',
70
+ 'Sage',
71
+ 'Scout',
72
+ 'Slate',
73
+ 'Sparrow',
74
+ 'Spruce',
75
+ 'Teal',
76
+ 'Tern',
77
+ 'Thatch',
78
+ 'Theo',
79
+ 'Thistle',
80
+ 'Tiller',
81
+ 'Timber',
82
+ 'Walnut',
83
+ 'Willow',
84
+ 'Yarrow'
85
+ ];
86
+ // FNV-1a over the eid: where in the list an entity starts looking.
87
+ let start = (eid)=>{
88
+ let h = 0x811c9dc5;
89
+ for(let i = 0; i < eid.length; i++){
90
+ h = Math.imul(h ^ eid.charCodeAt(i), 0x01000193);
91
+ }
92
+ return (h >>> 0) % NAMES.length;
93
+ };
94
+ /** The first name from `eid`'s place in {@link NAMES} that `taken` does not
95
+ * hold; the place's own name when every one is taken. */ export let pick = (eid, taken = new Set())=>{
96
+ let at = start(eid);
97
+ for(let i = 0; i < NAMES.length; i++){
98
+ let name = NAMES[(at + i) % NAMES.length];
99
+ if (!taken.has(name)) return name;
100
+ }
101
+ return NAMES[at];
102
+ };
103
+ /** A new name for `eid`, clear of the names `others` go by: those its people
104
+ * already reach. An unnamed one among them that sorts first picks first, so
105
+ * names given in one pass, which cannot read each other, still choose apart.
106
+ *
107
+ * ```ts
108
+ * import { equal } from '@yaks/testing'
109
+ * import { christened, pick } from './name.ts'
110
+ * let mine = pick('b')
111
+ * equal(christened('b', []), mine)
112
+ * equal(christened('b', [{ eid: 'z', name: mine }]) != mine, true)
113
+ * equal(christened('b', [{ eid: 'a' }]) != pick('a'), true)
114
+ * ```
115
+ */ export let christened = (eid, others)=>{
116
+ let taken = new Set(others.flatMap((o)=>o.name ? [
117
+ o.name
118
+ ] : []));
119
+ for (let o of others.filter((o)=>!o.name && o.eid < eid).sort((a, b)=>a.eid.localeCompare(b.eid)))taken.add(pick(o.eid, taken));
120
+ return pick(eid, taken);
121
+ };
122
+ /** The most characters a name is. */ export let LONGEST = 40;
123
+ /** A name a person gave: its spaces closed up, up to {@link LONGEST}
124
+ * characters.
125
+ *
126
+ * ```ts
127
+ * import { equal } from '@yaks/testing'
128
+ * import { assertThrows } from '@std/assert'
129
+ * import { given } from './name.ts'
130
+ * equal(given(' Ada Lovelace '), 'Ada Lovelace')
131
+ * assertThrows(() => given(' '), Error, 'Give it a name.')
132
+ * assertThrows(() => given('a'.repeat(41)), Error, 'up to 40 characters')
133
+ * ```
134
+ */ export let given = (said)=>{
135
+ let name = said.replace(/\s+/g, ' ').trim();
136
+ if (!name) throw new CallError('arguments', 'Give it a name.');
137
+ if (name.length > LONGEST) {
138
+ throw new CallError('arguments', `A name is up to ${LONGEST} characters.`);
139
+ }
140
+ return name;
141
+ };
142
+ /** A name `said` for a new persona, as {@link given} takes it, refused when
143
+ * one of `others` (those its people already reach) goes by it, in any case.
144
+ *
145
+ * ```ts
146
+ * import { equal } from '@yaks/testing'
147
+ * import { assertThrows } from '@std/assert'
148
+ * import { named, pick } from './name.ts'
149
+ * equal(named(' Menno ', [{ eid: 'a', name: 'Cedar' }]), 'Menno')
150
+ * assertThrows(() => named('cedar', [{ eid: 'a', name: 'Cedar' }]), Error)
151
+ * assertThrows(() => named(pick('a'), [{ eid: 'a' }]), Error)
152
+ * ```
153
+ */ export let named = (said, others)=>{
154
+ let name = given(said);
155
+ let fold = name.toLowerCase();
156
+ if (others.some((o)=>(o.name || pick(o.eid)).toLowerCase() == fold)) {
157
+ throw new CallError('conflict', `Another of their Operators is called ${name}. Give another name, or ` + 'leave it out and one is picked.');
158
+ }
159
+ return name;
160
+ };
161
+ //# sourceMappingURL=name.js.map