@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/effects.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// What a host does about a persona that changed, exported as
|
|
2
|
+
// `@yaks/persona/effects`: the code behind `persona_files` (./vocab.json),
|
|
3
|
+
// which writes the persona files again (./files.ts) a moment after the write
|
|
4
|
+
// commits, so a checkout's AGENTS.md says what the graph says without anybody
|
|
5
|
+
// running `persona sync`.
|
|
6
|
+
//
|
|
7
|
+
// Only where the config asks for it: `{"use": "@yaks/persona", "with":
|
|
8
|
+
// {"files": true}}`. Each file's path comes from a project's checkout, not from
|
|
9
|
+
// the database, so a host opened on a copy of a graph would write into the
|
|
10
|
+
// checkouts the original names. The live host opts in; a probe does not.
|
|
11
|
+
//
|
|
12
|
+
// A write starts a timer and returns, so the commit is never held open, and a
|
|
13
|
+
// burst of writes is one pass. A pass renders every persona (a few hundred
|
|
14
|
+
// milliseconds over the fleet's graph) and writes only the files whose text
|
|
15
|
+
// moved, so a run only has to avoid passes nothing asked for: a text edit or a
|
|
16
|
+
// new link counts when it touches something the last pass said, and archiving
|
|
17
|
+
// or restoring a project with a repository counts because that moves its
|
|
18
|
+
// checkout in or out of the files. A host that has not made a pass yet counts
|
|
19
|
+
// every one, and its first pass learns the set. Passes run one at a time; the timer is dropped when the
|
|
20
|
+
// host shuts down.
|
|
21
|
+
|
|
22
|
+
import * as systemProcess from '@yaks/process/system'
|
|
23
|
+
|
|
24
|
+
import type { Handlers } from 'jsr:@yaks/effects@0.2.36'
|
|
25
|
+
import type { Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
26
|
+
import { EDGE } from '@yaks/edge'
|
|
27
|
+
import { DOC } from '@yaks/doc'
|
|
28
|
+
import { sync } from '@yaks/mirror'
|
|
29
|
+
import { link, personaMirror, remembered } from './files.js'
|
|
30
|
+
import {
|
|
31
|
+
skillEffects,
|
|
32
|
+
type SkillHost,
|
|
33
|
+
type SkillRuntime,
|
|
34
|
+
} from './skill-effects.js'
|
|
35
|
+
|
|
36
|
+
/** What this plugin reads from its entry in a config. */
|
|
37
|
+
export type Options = { files?: boolean; skills?: boolean }
|
|
38
|
+
|
|
39
|
+
/** How long a burst of writes settles before one pass answers all of it. */
|
|
40
|
+
export let AFTER = 1_000
|
|
41
|
+
|
|
42
|
+
/** Injectable boundaries for tests: the skills' (./skill-effects.ts), and how
|
|
43
|
+
* long a burst settles. */
|
|
44
|
+
export type Runtime = SkillRuntime & { after?: number }
|
|
45
|
+
|
|
46
|
+
type Fired = Parameters<Handlers[string]>
|
|
47
|
+
|
|
48
|
+
/** Whether a write moves the persona files, given the entities the last pass
|
|
49
|
+
* said (none until a pass has been made, and then every write counts). Text or
|
|
50
|
+
* a link counts when it touches what the last pass said, a link that went
|
|
51
|
+
* read by the ends its `edge` had (@yaks/effects `Event.before`); a persona
|
|
52
|
+
* moving always does. A project with a repository put away or brought back
|
|
53
|
+
* does too: the last pass never said it while it was archived, and its
|
|
54
|
+
* checkout is what the files are written into. */
|
|
55
|
+
export let moves = async (
|
|
56
|
+
e: Fired[0],
|
|
57
|
+
tx: Fired[1],
|
|
58
|
+
said: Set<Eid>,
|
|
59
|
+
): Promise<boolean> => {
|
|
60
|
+
let about = (...eids: unknown[]) =>
|
|
61
|
+
!said.size || eids.some((x) => said.has(String(x)))
|
|
62
|
+
if (e.name == 'archived') {
|
|
63
|
+
let [row] = await tx.get([e.entity.eid], ['project', 'repo'])
|
|
64
|
+
return !!(row?.project && row.repo)
|
|
65
|
+
}
|
|
66
|
+
if (e.name == DOC || e.name == 'content') return about(e.entity.eid)
|
|
67
|
+
if (e.name == EDGE || e.name == 'contains' || e.name == 'reads') {
|
|
68
|
+
let ends = (e.before?.[EDGE] ??
|
|
69
|
+
(await tx.get([e.entity.eid], [EDGE]))[0]?.[EDGE]) as Comp | undefined
|
|
70
|
+
return about(ends?.from, ends?.to)
|
|
71
|
+
}
|
|
72
|
+
return true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The code that keeps the persona files current, when `files` is on. */
|
|
76
|
+
export let effects = (
|
|
77
|
+
host: SkillHost,
|
|
78
|
+
options: Options = {},
|
|
79
|
+
runtime: Runtime = {},
|
|
80
|
+
): Handlers => {
|
|
81
|
+
let skills = skillEffects(host, options, runtime)
|
|
82
|
+
if (!options.files) return skills
|
|
83
|
+
let db = host.config?.db ?? systemProcess.env.get('DB_PATH')
|
|
84
|
+
let said = new Set<Eid>()
|
|
85
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
86
|
+
let last = Promise.resolve()
|
|
87
|
+
let pass = async () => {
|
|
88
|
+
try {
|
|
89
|
+
let m = await personaMirror(host.graph, remembered(db))
|
|
90
|
+
said = m.said
|
|
91
|
+
let done = await sync(m.binding)
|
|
92
|
+
for (let f of [...done.failed, ...(await link(m.links)).failed]) {
|
|
93
|
+
console.warn('@yaks/persona files —', f)
|
|
94
|
+
await host.report?.(new Error(`persona files: ${f}`), {
|
|
95
|
+
tags: { step: 'persona_files' },
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
for (let p of done.conflicts) {
|
|
99
|
+
console.warn(`@yaks/persona files — ${p} was edited by hand, left`)
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn('@yaks/persona files —', error)
|
|
103
|
+
await host.report?.(error, { tags: { step: 'persona_files' } })
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let soon = () => {
|
|
107
|
+
if (host.stopping?.aborted) return
|
|
108
|
+
clearTimeout(timer)
|
|
109
|
+
timer = setTimeout(() => last = last.then(pass), runtime.after ?? AFTER)
|
|
110
|
+
}
|
|
111
|
+
host.stopping?.addEventListener('abort', () => clearTimeout(timer), {
|
|
112
|
+
once: true,
|
|
113
|
+
})
|
|
114
|
+
return {
|
|
115
|
+
...skills,
|
|
116
|
+
persona_files: async (e, tx) => {
|
|
117
|
+
if (await moves(e, tx, said)) soon()
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
}
|
package/files.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
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
|
+
import * as fs from "@yaks/file/io";
|
|
35
|
+
import { memo, present as exists } from "@yaks/mirror";
|
|
36
|
+
import { and, eq, every, list, present } from "@yaks/query";
|
|
37
|
+
import { DOC, TITLE } from "@yaks/doc";
|
|
38
|
+
import { human, parse } from "@yaks/id";
|
|
39
|
+
import { lineage } from "@yaks/project";
|
|
40
|
+
import { PERSONA } from "./comp.js";
|
|
41
|
+
import { voice } from "./voice.js";
|
|
42
|
+
import { beside, fold, wear } from "./worn.js";
|
|
43
|
+
import { banner, common, projection } from "./owed.js";
|
|
44
|
+
let comp = (b, name)=>b?.[name] ?? {};
|
|
45
|
+
let str = (v)=>v == null ? '' : String(v);
|
|
46
|
+
let value = (eids)=>eids.length == 1 ? eids[0] : list(...eids);
|
|
47
|
+
let eidOf = (b)=>b.entity.eid;
|
|
48
|
+
// Each project's checkout root: the main worktree of its repository, which
|
|
49
|
+
// Git knows by its own directory being the common one. Whoever cut a linked
|
|
50
|
+
// worktree, by hand or by a tool, it is never the one. A checkout moved
|
|
51
|
+
// leaves its old row behind, so the first by path wins, and the answer never
|
|
52
|
+
// depends on the order rows come back in.
|
|
53
|
+
let checkouts = async (g)=>{
|
|
54
|
+
let out = new Map();
|
|
55
|
+
let needs = [
|
|
56
|
+
'repo',
|
|
57
|
+
'repository',
|
|
58
|
+
'worktree'
|
|
59
|
+
];
|
|
60
|
+
if (!needs.every((c)=>g.vocab.comp(c))) return out;
|
|
61
|
+
let projects = (await g.storage.read(and(present('project'), present('repo')))).filter((b)=>!b.archived && comp(b, 'repo').repository);
|
|
62
|
+
let repos = [
|
|
63
|
+
...new Set(projects.map((b)=>str(comp(b, 'repo').repository)))
|
|
64
|
+
];
|
|
65
|
+
if (!repos.length) return out;
|
|
66
|
+
let common = new Map();
|
|
67
|
+
for (let r of (await g.get(repos))){
|
|
68
|
+
let dir = str(comp(r, 'repository').common);
|
|
69
|
+
if (dir) common.set(eidOf(r), dir);
|
|
70
|
+
}
|
|
71
|
+
if (!common.size) return out;
|
|
72
|
+
let mains = (await g.storage.read(and(eq('worktree.gitdir', value([
|
|
73
|
+
...new Set(common.values())
|
|
74
|
+
])), every()))).map((b)=>({
|
|
75
|
+
...comp(b, 'worktree'),
|
|
76
|
+
path: comp(b, 'workspace').root
|
|
77
|
+
})).filter((w)=>w.path && w.gitdir == common.get(str(w.repository))).sort((a, b)=>str(a.path).localeCompare(str(b.path)));
|
|
78
|
+
for (let p of projects){
|
|
79
|
+
let tree = mains.find((w)=>w.repository == comp(p, 'repo').repository);
|
|
80
|
+
if (tree) out.set(eidOf(p), str(tree.path));
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
};
|
|
84
|
+
// The name a persona registers under as a Claude agent: its alias
|
|
85
|
+
// (@yaks/alias keeps one as a `key`), reduced to claude's charset, or its
|
|
86
|
+
// lowered id where it has none. An alias that is itself an id (`N-4568`, an
|
|
87
|
+
// old number kept when a series was renumbered) is no name. The file is named
|
|
88
|
+
// for it too, because claude keys an agent by its frontmatter `name`, and a
|
|
89
|
+
// harness resolves the file by its own.
|
|
90
|
+
let names = async (g, eids)=>{
|
|
91
|
+
let out = new Map();
|
|
92
|
+
if (!eids.length || !g.vocab.comp('alias') || !g.vocab.comp('key')) {
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
let keys = (await g.storage.read(and(eq('key.of', value(eids)), present('alias')))).map((b)=>comp(b, 'key')).filter((k)=>!parse(str(k.value))).sort((a, b)=>str(a.value).localeCompare(str(b.value)));
|
|
96
|
+
for (let k of keys){
|
|
97
|
+
if (!out.has(str(k.of))) out.set(str(k.of), str(k.value));
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
};
|
|
101
|
+
let slug = (name)=>name.toLowerCase().replace(/[^a-z0-9-]+/g, '-');
|
|
102
|
+
/** Every persona file the graph says its checkouts hold. */ export let personaFiles = async (g)=>{
|
|
103
|
+
let homes = await checkouts(g);
|
|
104
|
+
let files = [];
|
|
105
|
+
let said = new Set();
|
|
106
|
+
if (!homes.size) return {
|
|
107
|
+
files,
|
|
108
|
+
roots: [],
|
|
109
|
+
said
|
|
110
|
+
};
|
|
111
|
+
let id = human(g.vocab);
|
|
112
|
+
let render = voice(g.vocab);
|
|
113
|
+
let wearing = wear(g.storage, g.vocab);
|
|
114
|
+
let heard = (w)=>{
|
|
115
|
+
for (let b of [
|
|
116
|
+
w.persona,
|
|
117
|
+
...w.contains,
|
|
118
|
+
...w.names
|
|
119
|
+
])said.add(eidOf(b));
|
|
120
|
+
return w;
|
|
121
|
+
};
|
|
122
|
+
// Each project's common persona along its lineage, read once a pass.
|
|
123
|
+
let shared = new Map();
|
|
124
|
+
let everyone = async (project)=>{
|
|
125
|
+
if (!shared.has(project)) {
|
|
126
|
+
let w = await common(g, project);
|
|
127
|
+
shared.set(project, w && heard(w));
|
|
128
|
+
}
|
|
129
|
+
return shared.get(project);
|
|
130
|
+
};
|
|
131
|
+
let personas = await g.storage.read(and(present(PERSONA)));
|
|
132
|
+
let named = await names(g, personas.map(eidOf));
|
|
133
|
+
// The checkout each home lands in: the nearest project along its lineage
|
|
134
|
+
// that has one, so a sub-project's personas are written into its parent's.
|
|
135
|
+
let lands = new Map();
|
|
136
|
+
for (let home of new Set(personas.map((p)=>str(comp(p, PERSONA).home)))){
|
|
137
|
+
if (!home) continue;
|
|
138
|
+
let line = (await lineage(g, home)).map(eidOf);
|
|
139
|
+
lands.set(home, line.find((p)=>homes.has(p)));
|
|
140
|
+
}
|
|
141
|
+
let head = banner(g.vocab);
|
|
142
|
+
let agents = projection(g.vocab);
|
|
143
|
+
for (let [project, root] of homes){
|
|
144
|
+
let dir = `${root}/.tasks`;
|
|
145
|
+
let base = await everyone(project);
|
|
146
|
+
if (base) files.push({
|
|
147
|
+
path: `${dir}/AGENTS.md`,
|
|
148
|
+
text: agents(base)
|
|
149
|
+
});
|
|
150
|
+
for (let p of personas){
|
|
151
|
+
let home = str(comp(p, PERSONA).home);
|
|
152
|
+
if (lands.get(home) != project || eidOf(p) == base?.persona.entity.eid) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
let w = await wearing(eidOf(p));
|
|
156
|
+
if (!w) continue;
|
|
157
|
+
let own = await everyone(home);
|
|
158
|
+
let whole = heard(own ? fold(w, own) : w);
|
|
159
|
+
let name = slug(named.get(eidOf(p)) ?? id(p));
|
|
160
|
+
let title = str(comp(p, DOC)[TITLE]);
|
|
161
|
+
files.push({
|
|
162
|
+
path: `${dir}/personas/${name}.md`,
|
|
163
|
+
text: `---\nname: ${name}\ndescription: ${JSON.stringify(title)}\n` + `---\n${head(p)}\n\n${render(base ? beside(whole, base) : whole)}`
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let roots = [
|
|
168
|
+
...new Set(homes.values())
|
|
169
|
+
].map((r)=>`${r}/.tasks`);
|
|
170
|
+
return {
|
|
171
|
+
files,
|
|
172
|
+
roots,
|
|
173
|
+
said
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
// What an owned directory holds now: its AGENTS.md and its personas. Owned
|
|
177
|
+
// end to end, so anything of those two shapes is ours.
|
|
178
|
+
let held = (dir)=>{
|
|
179
|
+
let out = [
|
|
180
|
+
`${dir}/AGENTS.md`
|
|
181
|
+
];
|
|
182
|
+
try {
|
|
183
|
+
for (let e of fs.readDirSync(`${dir}/personas`)){
|
|
184
|
+
if (e.isFile && e.name.endsWith('.md')) {
|
|
185
|
+
out.push(`${dir}/personas/${e.name}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch {}
|
|
189
|
+
return out;
|
|
190
|
+
};
|
|
191
|
+
/** Where a graph remembers what each persona file last agreed on: a file
|
|
192
|
+
* beside its database, or nothing for a graph in memory. */ export let remembered = (db)=>!db || db == ':memory:' ? {
|
|
193
|
+
agreed: ()=>Promise.resolve(new Map())
|
|
194
|
+
} : memo(`${db.slice(0, db.lastIndexOf('/') + 1) || './'}mirror/personas.json`);
|
|
195
|
+
/** The persona files as a write-only @yaks/mirror binding — hand it to
|
|
196
|
+
* `sync` to write them, or to `plan` to see what would change — the
|
|
197
|
+
* `.claude/agents` links they want made or removed (hand those to `link`),
|
|
198
|
+
* and every entity they say something about. */ export let personaMirror = async (g, memory)=>{
|
|
199
|
+
let all = await personaFiles(g);
|
|
200
|
+
let { files, roots, said } = all;
|
|
201
|
+
let paths = new Set([
|
|
202
|
+
...files.map((f)=>f.path),
|
|
203
|
+
...roots.flatMap(held)
|
|
204
|
+
]);
|
|
205
|
+
return {
|
|
206
|
+
binding: {
|
|
207
|
+
name: 'personas',
|
|
208
|
+
files: ()=>exists([
|
|
209
|
+
...paths
|
|
210
|
+
]),
|
|
211
|
+
values: ()=>Promise.resolve(new Map(files.map((f)=>[
|
|
212
|
+
f.path,
|
|
213
|
+
f.text
|
|
214
|
+
]))),
|
|
215
|
+
...memory
|
|
216
|
+
},
|
|
217
|
+
links: agentLinks(all),
|
|
218
|
+
said
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
let PERSONAS = '/.tasks/personas/';
|
|
222
|
+
// Whether anything is at a path, a dangling link included.
|
|
223
|
+
let taken = (path)=>{
|
|
224
|
+
try {
|
|
225
|
+
return !!fs.lstatSync(path);
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
let linkOf = (path)=>{
|
|
231
|
+
try {
|
|
232
|
+
return fs.readLinkSync(path);
|
|
233
|
+
} catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
/** The `.claude/agents` links the persona files want changed: a specialist
|
|
238
|
+
* whose file no link names gets `<name>.md`, and a link into
|
|
239
|
+
* `.tasks/personas` naming no file the graph still says is removed, so a
|
|
240
|
+
* renamed persona's link moves with its file. A link of another name that
|
|
241
|
+
* names a current file is kept, and a person's own file at a link's path is
|
|
242
|
+
* left. */ export let agentLinks = ({ files, roots })=>{
|
|
243
|
+
let current = new Set(files.map((f)=>f.path));
|
|
244
|
+
let out = [];
|
|
245
|
+
for (let root of roots){
|
|
246
|
+
let dir = `${root.slice(0, -'/.tasks'.length)}/.claude/agents`;
|
|
247
|
+
let named = new Set();
|
|
248
|
+
let entries = [];
|
|
249
|
+
try {
|
|
250
|
+
entries = [
|
|
251
|
+
...fs.readDirSync(dir)
|
|
252
|
+
];
|
|
253
|
+
} catch {}
|
|
254
|
+
for (let e of entries){
|
|
255
|
+
let path = `${dir}/${e.name}`;
|
|
256
|
+
let to = e.isSymlink ? linkOf(path) : undefined;
|
|
257
|
+
if (!to) continue;
|
|
258
|
+
let target = fs.resolve(dir, to);
|
|
259
|
+
if (current.has(target)) named.add(target);
|
|
260
|
+
else if (target.startsWith(`${root}/personas/`)) out.push({
|
|
261
|
+
path
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
for (let path of current){
|
|
265
|
+
if (!path.startsWith(`${root}/personas/`) || named.has(path)) continue;
|
|
266
|
+
let name = path.slice(path.lastIndexOf('/') + 1);
|
|
267
|
+
let at = `${dir}/${name}`;
|
|
268
|
+
if (linkOf(at) == null && taken(at)) continue;
|
|
269
|
+
out.push({
|
|
270
|
+
path: at,
|
|
271
|
+
to: `../..${PERSONAS}${name}`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return out.sort((a, b)=>a.path.localeCompare(b.path));
|
|
276
|
+
};
|
|
277
|
+
/** Make and remove the links: each made one is swapped in by a rename, so a
|
|
278
|
+
* harness reading it sees the old link or the new one. A failure on one link
|
|
279
|
+
* never stops the others. */ export let link = async (links)=>{
|
|
280
|
+
let out = {
|
|
281
|
+
linked: [],
|
|
282
|
+
unlinked: [],
|
|
283
|
+
failed: []
|
|
284
|
+
};
|
|
285
|
+
for (let { path, to } of links){
|
|
286
|
+
try {
|
|
287
|
+
if (to == null) {
|
|
288
|
+
await fs.remove(path);
|
|
289
|
+
out.unlinked.push(path);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
await fs.mkdir(fs.dirname(path), {
|
|
293
|
+
recursive: true
|
|
294
|
+
});
|
|
295
|
+
let tmp = `${path}.${crypto.randomUUID()}.tmp`;
|
|
296
|
+
await fs.symlink(to, tmp);
|
|
297
|
+
await fs.rename(tmp, path);
|
|
298
|
+
out.linked.push(path);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
out.failed.push(`${path}: ${e.message}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
};
|
|
305
|
+
//# sourceMappingURL=files.js.map
|
package/files.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sources":["./files.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0EAA0E;AAC1E,4EAA4E;AAC5E,yDAAyD;AACzD,4EAA4E;AAC5E,6EAA6E;AAC7E,mEAAmE;AACnE,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAC3E,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,wBAAwB;AACxB,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,0DAA0D;AAC1D,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,qFAAqF;AACrF,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,uEAAuE;AACvE,+EAA+E;AAC/E,4EAA4E;AAC5E,mEAAmE;AAEnE,YAAY,6BAAkC;AAE9C,SAAuB,IAAI,EAAE,WAAW,MAAM,4BAAiC;AAC/E,SAAS,GAAG,EAAE,EAAE,EAAE,KAAK,EAAc,IAAI,EAAE,OAAO,2BAAgC;AAElF,SAAS,GAAG,EAAE,KAAK,yBAA8B;AACjD,SAAS,KAAK,EAAE,KAAK,wBAA6B;AAClD,SAAS,OAAO,6BAAkC;AAClD,SAAS,OAAO,oBAAmB;AACnC,SA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