edify-agents-cli 0.2.0__py3-none-any.whl
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.
- edify/__init__.py +19 -0
- edify/__main__.py +6 -0
- edify/_toml.py +286 -0
- edify/agents.py +261 -0
- edify/anim.py +499 -0
- edify/assets/commands/build.md +64 -0
- edify/assets/commands/plan.md +68 -0
- edify/assets/commands/spec.md +63 -0
- edify/assets/commands/tasks.md +65 -0
- edify/assets/commands/verify.md +67 -0
- edify/assets/formats/plan.example.md +455 -0
- edify/assets/formats/plan.format.md +128 -0
- edify/assets/formats/spec.example.md +483 -0
- edify/assets/formats/spec.format.md +116 -0
- edify/assets/formats/tasks.example.md +712 -0
- edify/assets/formats/tasks.format.md +199 -0
- edify/assets/harvest/harvest.md +91 -0
- edify/assets/harvest/sources.md +295 -0
- edify/assets/harvest/vocab.md +52 -0
- edify/assets/manifest.md +30 -0
- edify/assets/mcp/default-registry.md +66 -0
- edify/assets/skills/adversary.md +61 -0
- edify/assets/skills/debugger.md +64 -0
- edify/assets/skills/implementer-general.md +53 -0
- edify/assets/skills/implementer-go.md +63 -0
- edify/assets/skills/implementer-node.md +61 -0
- edify/assets/skills/implementer-postgres.md +63 -0
- edify/assets/skills/implementer-python.md +65 -0
- edify/assets/skills/implementer-react.md +65 -0
- edify/assets/skills/planner.md +58 -0
- edify/assets/skills/test-writer-node.md +64 -0
- edify/assets/skills/test-writer-python.md +60 -0
- edify/assets/skills/verifier.md +67 -0
- edify/assets/templates/CLAUDE.md +18 -0
- edify/assets.py +77 -0
- edify/cli.py +681 -0
- edify/commands/__init__.py +1 -0
- edify/commands/check_cmd.py +72 -0
- edify/commands/doctor_cmd.py +206 -0
- edify/commands/feedback_cmd.py +90 -0
- edify/commands/governance_cmd.py +65 -0
- edify/commands/graph_cmd.py +156 -0
- edify/commands/harvest_cmd.py +538 -0
- edify/commands/init_cmd.py +333 -0
- edify/commands/init_new_cmd.py +151 -0
- edify/commands/license_cmd.py +80 -0
- edify/commands/mcp_cmd.py +159 -0
- edify/commands/self_cmd.py +185 -0
- edify/commands/setup_cmd.py +79 -0
- edify/commands/skills_cmd.py +177 -0
- edify/commands/upgrade_cmd.py +178 -0
- edify/context.py +57 -0
- edify/conventions.py +275 -0
- edify/detect.py +313 -0
- edify/distribution.py +40 -0
- edify/errors.py +66 -0
- edify/feedback.py +207 -0
- edify/formats/__init__.py +11 -0
- edify/formats/check.py +573 -0
- edify/formats/document.py +238 -0
- edify/formats/finding.py +50 -0
- edify/formats/fix.py +114 -0
- edify/formats/mcp.py +126 -0
- edify/formats/plan.py +151 -0
- edify/formats/skill.py +139 -0
- edify/formats/spec.py +164 -0
- edify/formats/tasks.py +321 -0
- edify/governance.py +316 -0
- edify/graph/__init__.py +11 -0
- edify/graph/extract.py +351 -0
- edify/graph/ignore.py +107 -0
- edify/graph/langs/__init__.py +93 -0
- edify/graph/langs/ctags.py +145 -0
- edify/graph/langs/markdown.py +41 -0
- edify/graph/langs/patterns.py +361 -0
- edify/graph/langs/python_ast.py +154 -0
- edify/graph/langs/sqlish.py +86 -0
- edify/graph/model.py +102 -0
- edify/graph/queries.py +211 -0
- edify/graph/store.py +157 -0
- edify/harvest/__init__.py +28 -0
- edify/harvest/ledger.py +191 -0
- edify/harvest/screen.py +236 -0
- edify/harvest/sources.py +298 -0
- edify/host.py +345 -0
- edify/interview.py +354 -0
- edify/library.py +176 -0
- edify/licensing/__init__.py +30 -0
- edify/licensing/ed25519.py +154 -0
- edify/licensing/projects.py +223 -0
- edify/licensing/tier.py +172 -0
- edify/licensing/token.py +149 -0
- edify/paths.py +282 -0
- edify/selfinstall.py +244 -0
- edify/skills.py +108 -0
- edify/tsv.py +109 -0
- edify/ui.py +334 -0
- edify_agents_cli-0.2.0.dist-info/METADATA +408 -0
- edify_agents_cli-0.2.0.dist-info/RECORD +102 -0
- edify_agents_cli-0.2.0.dist-info/WHEEL +4 -0
- edify_agents_cli-0.2.0.dist-info/entry_points.txt +2 -0
- edify_agents_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
"""`edify harvest` — the mechanical steps of the curation pipeline.
|
|
2
|
+
|
|
3
|
+
pick ──▶ stage ──▶ screen ──▶ propose ──▶ ◆ admit | reject
|
|
4
|
+
|
|
5
|
+
`pick`, `stage`, `screen`, and `propose` run unattended. `admit` does not, and no
|
|
6
|
+
flag makes it: it is the only thing standing between a stranger's text and
|
|
7
|
+
persistent trusted context in a customer's repository, and it costs a person
|
|
8
|
+
minutes per entry.
|
|
9
|
+
|
|
10
|
+
The gathering itself is not here. `10-harvest.md` puts fetching in step ①, but the
|
|
11
|
+
CLI is a pure function over files — `edify` opens no socket except `upgrade` — so
|
|
12
|
+
the caller fetches and `stage` records what arrived. That split is also why the raw
|
|
13
|
+
bytes land in a `.txt` file rather than a `.md` one: nothing downstream should be
|
|
14
|
+
tempted to read a candidate as a document when it is evidence.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import re
|
|
21
|
+
import shutil
|
|
22
|
+
from datetime import date
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from ..context import Context
|
|
26
|
+
from ..errors import EdifyError
|
|
27
|
+
from ..formats import skill as skill_format
|
|
28
|
+
from ..harvest import screen as screener
|
|
29
|
+
from ..harvest import sources as source_table
|
|
30
|
+
from ..harvest.ledger import Candidate, Ledger, candidate_id
|
|
31
|
+
from ..tsv import sha256_bytes
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _guard(ctx: Context) -> Ledger:
|
|
35
|
+
"""Harvest runs in EDIFY's own repository, never in a client's."""
|
|
36
|
+
if not ctx.layout.is_edify_repo():
|
|
37
|
+
raise EdifyError(
|
|
38
|
+
"harvest runs in EDIFY's own repository, never in a client's",
|
|
39
|
+
hint="a client's own conventions go straight into .edify/skills/ with `provenance: client`",
|
|
40
|
+
)
|
|
41
|
+
return Ledger.load(ctx.layout.harvest_ledger)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _find(ledger: Ledger, cid: str) -> Candidate:
|
|
45
|
+
cand = ledger.get(cid)
|
|
46
|
+
if not cand:
|
|
47
|
+
raise EdifyError(f"no candidate `{cid}` in the ledger", hint="`edify harvest status` lists what is in flight")
|
|
48
|
+
return cand
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# -- ① pick -----------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def pick(ctx: Context) -> int:
|
|
55
|
+
"""Which source to draw from, and what not to gather again.
|
|
56
|
+
|
|
57
|
+
Two answers, and the first one used to be missing. `pick` printed the whole
|
|
58
|
+
source table and left the choice of row to the caller, which meant the choice was
|
|
59
|
+
a model's mood: a run could draw from an archived upstream, or from the row whose
|
|
60
|
+
licence the screen was always going to reject, and nothing in the pipeline
|
|
61
|
+
noticed until step ②. Selecting a row is a lookup over the table and the ledger,
|
|
62
|
+
so it happens here — deterministic, with the arithmetic printed.
|
|
63
|
+
|
|
64
|
+
The second answer is the three identities of everything ever handled, so a
|
|
65
|
+
candidate rejected in March is never re-read, re-screened, or re-proposed in
|
|
66
|
+
August.
|
|
67
|
+
"""
|
|
68
|
+
ledger = _guard(ctx)
|
|
69
|
+
sources = source_table.read(ctx.layout.harvest_refs / "sources.md")
|
|
70
|
+
yields = {row[0]: (row[1], row[2], row[3], row[4]) for row in ledger.by_source()}
|
|
71
|
+
ranked = source_table.rank(sources, yields)
|
|
72
|
+
wanted = getattr(ctx.args, "source", "") or ""
|
|
73
|
+
chosen = source_table.choose(ranked, wanted)
|
|
74
|
+
|
|
75
|
+
if wanted and not chosen:
|
|
76
|
+
raise EdifyError(
|
|
77
|
+
f"no source in the table matches `{wanted}`",
|
|
78
|
+
hint="`edify harvest pick` with no --source lists every row",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
seen = {
|
|
82
|
+
"urls": sorted({c.url for c in ledger.sorted() if c.url}),
|
|
83
|
+
"names": sorted({c.name for c in ledger.sorted() if c.name}),
|
|
84
|
+
"sha256": sorted({c.content_sha256 for c in ledger.sorted() if c.content_sha256}),
|
|
85
|
+
}
|
|
86
|
+
in_flight = ledger.in_state("staged", "screened", "proposed")
|
|
87
|
+
ctx.out.data(
|
|
88
|
+
{
|
|
89
|
+
"chosen": chosen.to_json() if chosen else None,
|
|
90
|
+
"sources": [r.to_json() for r in ranked],
|
|
91
|
+
"yield": [
|
|
92
|
+
dict(zip(("source", "admitted", "rejected", "seen", "last_run"), y)) for y in ledger.by_source()
|
|
93
|
+
],
|
|
94
|
+
"seen": seen,
|
|
95
|
+
"budget": getattr(ctx.args, "count", 0),
|
|
96
|
+
"in_flight": [c.id for c in in_flight],
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if not ranked:
|
|
101
|
+
ctx.out.line("no sources listed")
|
|
102
|
+
ctx.out.note("add one to edify/harvest/sources.md — adding a source is a reviewed change")
|
|
103
|
+
return 0
|
|
104
|
+
|
|
105
|
+
if chosen:
|
|
106
|
+
ctx.out.line(f"draw from {chosen.source.name}")
|
|
107
|
+
ctx.out.line(f"fetch {chosen.source.fetch or '(the whole tree — no fetch path recorded)'}")
|
|
108
|
+
ctx.out.line(f"posture {chosen.source.posture or 'none recorded'}")
|
|
109
|
+
ctx.out.line(f"why {chosen.why}")
|
|
110
|
+
if chosen.source.kind == "index":
|
|
111
|
+
ctx.out.warn(
|
|
112
|
+
"this row is an index — read it for links and draw from what they point at, "
|
|
113
|
+
"under that repository's own licence. Never stage its bytes."
|
|
114
|
+
)
|
|
115
|
+
ctx.out.line("")
|
|
116
|
+
else:
|
|
117
|
+
ctx.out.warn("no source in the table can be harvested from — every posture resolves to NONE-FOUND")
|
|
118
|
+
|
|
119
|
+
if getattr(ctx.args, "all", False) or not chosen:
|
|
120
|
+
rows = [
|
|
121
|
+
[
|
|
122
|
+
("→ " if chosen and r is chosen else " ") + r.source.name,
|
|
123
|
+
r.source.kind,
|
|
124
|
+
r.source.spdx,
|
|
125
|
+
str(r.score),
|
|
126
|
+
f"{r.admitted}/{r.admitted + r.rejected}",
|
|
127
|
+
str(r.seen),
|
|
128
|
+
r.last_run,
|
|
129
|
+
]
|
|
130
|
+
for r in ranked
|
|
131
|
+
]
|
|
132
|
+
ctx.out.table(["source", "kind", "licence", "score", "admitted", "seen", "last run"], rows)
|
|
133
|
+
else:
|
|
134
|
+
ctx.out.note(f"{len(ranked) - 1} other source(s) scored lower — `--all` to see them")
|
|
135
|
+
|
|
136
|
+
ctx.out.note(
|
|
137
|
+
f"already handled: {len(seen['urls'])} urls, {len(seen['names'])} names, "
|
|
138
|
+
f"{len(seen['sha256'])} content hashes — do not gather these again"
|
|
139
|
+
)
|
|
140
|
+
if in_flight:
|
|
141
|
+
ctx.out.note(f"{len(in_flight)} candidate(s) still in flight: {', '.join(c.id for c in in_flight)}")
|
|
142
|
+
return 0
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# -- ① stage ----------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def stage(ctx: Context) -> int:
|
|
149
|
+
"""Record one gathered artifact, or refuse because we have seen it.
|
|
150
|
+
|
|
151
|
+
The refusal is the feature. Three identities are checked — URL, content hash,
|
|
152
|
+
and the entry name it would take — because the same file moves repositories,
|
|
153
|
+
gets re-tagged, and arrives renamed.
|
|
154
|
+
"""
|
|
155
|
+
ledger = _guard(ctx)
|
|
156
|
+
source_file = Path(ctx.args.content).expanduser()
|
|
157
|
+
if not source_file.is_file():
|
|
158
|
+
raise EdifyError(f"{source_file} is not a file")
|
|
159
|
+
|
|
160
|
+
raw = source_file.read_bytes()
|
|
161
|
+
content_sha = sha256_bytes(raw)
|
|
162
|
+
name = _slug_name(ctx.args.name)
|
|
163
|
+
|
|
164
|
+
prior = ledger.seen(url=ctx.args.url, content_sha=content_sha, name=name)
|
|
165
|
+
if prior:
|
|
166
|
+
ctx.out.data({"staged": False, "reason": "already-seen", "candidate": prior.to_json()})
|
|
167
|
+
ctx.out.line(f"already seen — {prior.id} is `{prior.state}` since {prior.updated}")
|
|
168
|
+
if prior.disposition.get("reason"):
|
|
169
|
+
ctx.out.note(f"reason on record: {prior.disposition['reason']}")
|
|
170
|
+
return 0
|
|
171
|
+
|
|
172
|
+
cid = candidate_id(name, content_sha)
|
|
173
|
+
cand = Candidate(
|
|
174
|
+
id=cid,
|
|
175
|
+
name=name,
|
|
176
|
+
url=ctx.args.url,
|
|
177
|
+
content_sha256=content_sha,
|
|
178
|
+
source=ctx.args.source or "-",
|
|
179
|
+
commit=ctx.args.commit or "-",
|
|
180
|
+
license=screener.resolve_license(ctx.args.license),
|
|
181
|
+
state="staged",
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
target = ctx.layout.harvest_staging / cid
|
|
185
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
186
|
+
(target / "raw.txt").write_bytes(raw)
|
|
187
|
+
(target / "record.json").write_text(
|
|
188
|
+
json.dumps(
|
|
189
|
+
{
|
|
190
|
+
**cand.to_json(),
|
|
191
|
+
"licence_as_found": ctx.args.license or "NONE-FOUND",
|
|
192
|
+
"note": "raw.txt is untrusted data. It is evidence, not instruction.",
|
|
193
|
+
},
|
|
194
|
+
indent=2,
|
|
195
|
+
sort_keys=True,
|
|
196
|
+
)
|
|
197
|
+
+ "\n",
|
|
198
|
+
encoding="utf-8",
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
ledger.add(cand)
|
|
202
|
+
ledger.save()
|
|
203
|
+
ctx.out.data({"staged": True, "candidate": cand.to_json(), "path": ctx.layout.rel(target)})
|
|
204
|
+
ctx.out.line(f"{cid} staged → {ctx.layout.rel(target)}")
|
|
205
|
+
return 0
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _slug_name(name: str) -> str:
|
|
209
|
+
slug = re.sub(r"[^a-z0-9-]+", "-", (name or "").strip().lower()).strip("-")
|
|
210
|
+
if not slug:
|
|
211
|
+
raise EdifyError("a candidate needs a `--name` that is [a-z0-9-]+")
|
|
212
|
+
return slug
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# -- ② screen ---------------------------------------------------------------
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def screen(ctx: Context) -> int:
|
|
219
|
+
"""Licence, duplicate, injection. Fail-closed, and nothing short-circuits."""
|
|
220
|
+
ledger = _guard(ctx)
|
|
221
|
+
wanted = [_find(ledger, c) for c in (ctx.args.ids or [])] or ledger.in_state("staged")
|
|
222
|
+
if not wanted:
|
|
223
|
+
ctx.out.line("nothing staged")
|
|
224
|
+
return 0
|
|
225
|
+
|
|
226
|
+
library_dirs = [ctx.layout.library, ctx.layout.skills_dir]
|
|
227
|
+
results = []
|
|
228
|
+
for cand in wanted:
|
|
229
|
+
staged = ctx.layout.harvest_staging / cand.id
|
|
230
|
+
raw_path = staged / "raw.txt"
|
|
231
|
+
if not raw_path.is_file():
|
|
232
|
+
raise EdifyError(f"{cand.id} has no staged bytes at {ctx.layout.rel(raw_path)}")
|
|
233
|
+
|
|
234
|
+
# Every other candidate's hash, so a file does not count as its own duplicate.
|
|
235
|
+
others = {c.content_sha256: c.id for c in ledger.sorted() if c.id != cand.id and c.content_sha256}
|
|
236
|
+
verdict = screener.screen(
|
|
237
|
+
name=cand.name,
|
|
238
|
+
license_found=cand.license,
|
|
239
|
+
content=raw_path.read_text(encoding="utf-8", errors="replace"),
|
|
240
|
+
content_sha=cand.content_sha256,
|
|
241
|
+
library_dirs=library_dirs,
|
|
242
|
+
existing_shas=others,
|
|
243
|
+
)
|
|
244
|
+
cand.screen = verdict.to_json()
|
|
245
|
+
|
|
246
|
+
if verdict.verdict == "quarantine":
|
|
247
|
+
ledger.set_state(cand, "quarantined")
|
|
248
|
+
_move(staged, ctx.layout.harvest_quarantine / cand.id, verdict)
|
|
249
|
+
elif verdict.verdict == "reject":
|
|
250
|
+
ledger.set_state(cand, "rejected")
|
|
251
|
+
cand.disposition = {
|
|
252
|
+
"by": "screen",
|
|
253
|
+
"on": date.today().isoformat(),
|
|
254
|
+
"reason": "; ".join(c.detail for c in verdict.failures),
|
|
255
|
+
}
|
|
256
|
+
else:
|
|
257
|
+
ledger.set_state(cand, "screened")
|
|
258
|
+
|
|
259
|
+
results.append((cand, verdict))
|
|
260
|
+
|
|
261
|
+
ledger.save()
|
|
262
|
+
ctx.out.data([{"id": c.id, **v.to_json()} for c, v in results])
|
|
263
|
+
ctx.out.table(
|
|
264
|
+
["candidate", "verdict", "why"],
|
|
265
|
+
[
|
|
266
|
+
[c.id, v.verdict, "ok" if v.verdict == "pass" else "; ".join(f.code for f in v.failures)]
|
|
267
|
+
for c, v in results
|
|
268
|
+
],
|
|
269
|
+
)
|
|
270
|
+
for cand, verdict in results:
|
|
271
|
+
if verdict.verdict == "quarantine":
|
|
272
|
+
ctx.out.warn(f"{cand.id} quarantined → {ctx.layout.rel(ctx.layout.harvest_quarantine / cand.id)}")
|
|
273
|
+
return 0
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _move(staged: Path, target: Path, verdict: screener.Verdict) -> None:
|
|
277
|
+
"""Quarantine is a place things go, not a decision made in passing."""
|
|
278
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
279
|
+
if target.exists():
|
|
280
|
+
shutil.rmtree(target)
|
|
281
|
+
if staged.is_dir():
|
|
282
|
+
shutil.move(str(staged), str(target))
|
|
283
|
+
else:
|
|
284
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
285
|
+
(target / "screen.json").write_text(json.dumps(verdict.to_json(), indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
# -- ④ propose --------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def propose(ctx: Context) -> int:
|
|
292
|
+
"""The rewritten file, the original beside it, the provenance, and the case.
|
|
293
|
+
|
|
294
|
+
Refuses a rewrite that would not survive `edify check`, and refuses one that
|
|
295
|
+
claims `provenance: original` — a file that came from somewhere else is
|
|
296
|
+
`adapted`, and its `license` field is the SPDX id plus `repo@commit`.
|
|
297
|
+
"""
|
|
298
|
+
ledger = _guard(ctx)
|
|
299
|
+
cand = _find(ledger, ctx.args.id)
|
|
300
|
+
if cand.state != "screened":
|
|
301
|
+
raise EdifyError(
|
|
302
|
+
f"{cand.id} is `{cand.state}` — only a screened candidate can be proposed",
|
|
303
|
+
hint="run `edify harvest screen` first; a rejected or quarantined candidate does not proceed",
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
rewritten = Path(ctx.args.file).expanduser()
|
|
307
|
+
if not rewritten.is_file():
|
|
308
|
+
raise EdifyError(f"{rewritten} is not a file")
|
|
309
|
+
|
|
310
|
+
parsed = skill_format.parse(rewritten, rewritten.name)
|
|
311
|
+
problems = skill_format.validate(parsed)
|
|
312
|
+
if problems:
|
|
313
|
+
for _, message, line in problems:
|
|
314
|
+
ctx.out.error(f"{rewritten.name}:{line} {message}")
|
|
315
|
+
raise EdifyError("the rewrite is not a valid entry", hint="eight frontmatter fields, four sections, under budget")
|
|
316
|
+
if parsed.provenance != "adapted":
|
|
317
|
+
raise EdifyError(
|
|
318
|
+
f"`provenance: {parsed.provenance}` — anything harvested is `adapted`",
|
|
319
|
+
hint=f"and `license: {cand.license} {_repo_at_commit(cand)}`",
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
target = ctx.layout.harvest_proposals / cand.id
|
|
323
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
324
|
+
shutil.copyfile(rewritten, target / "rewritten.md")
|
|
325
|
+
staged_raw = ctx.layout.harvest_staging / cand.id / "raw.txt"
|
|
326
|
+
original_lines = 0
|
|
327
|
+
if staged_raw.is_file():
|
|
328
|
+
shutil.copyfile(staged_raw, target / "original.txt")
|
|
329
|
+
original_lines = len(staged_raw.read_text(encoding="utf-8", errors="replace").splitlines())
|
|
330
|
+
|
|
331
|
+
(target / "proposal.md").write_text(
|
|
332
|
+
_proposal(cand, parsed, ctx.args.case, original_lines, ctx.layout.rel(target)), encoding="utf-8"
|
|
333
|
+
)
|
|
334
|
+
ledger.set_state(cand, "proposed")
|
|
335
|
+
ledger.save()
|
|
336
|
+
|
|
337
|
+
ctx.out.data({"id": cand.id, "path": ctx.layout.rel(target), "lines": parsed.body_lines, "was": original_lines})
|
|
338
|
+
ctx.out.line(f"{cand.id} proposed → {ctx.layout.rel(target / 'proposal.md')}")
|
|
339
|
+
ctx.out.note(f"{original_lines} lines in, {parsed.body_lines} out · a person reads it next")
|
|
340
|
+
return 0
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _repo_at_commit(cand: Candidate) -> str:
|
|
344
|
+
repo = re.sub(r"^https?://(www\.)?", "", cand.url).rstrip("/")
|
|
345
|
+
return f"{repo}@{cand.commit}"
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _proposal(cand: Candidate, parsed, case: str, original_lines: int, rel: str) -> str:
|
|
349
|
+
checks = "\n".join(
|
|
350
|
+
f"- `{c['code']}` {'ok' if c['ok'] else 'FAIL'} — {c['detail']}" for c in cand.screen.get("checks", [])
|
|
351
|
+
)
|
|
352
|
+
return f"""# Proposal — {cand.name}
|
|
353
|
+
|
|
354
|
+
`{cand.id}` · staged {cand.first_seen} · **awaiting a human**
|
|
355
|
+
|
|
356
|
+
## What it serves
|
|
357
|
+
|
|
358
|
+
{case}
|
|
359
|
+
|
|
360
|
+
## Provenance
|
|
361
|
+
|
|
362
|
+
| field | value |
|
|
363
|
+
|---|---|
|
|
364
|
+
| url | {cand.url} |
|
|
365
|
+
| commit | {cand.commit} |
|
|
366
|
+
| licence | {cand.license} |
|
|
367
|
+
| source | {cand.source} |
|
|
368
|
+
| sha256 | {cand.content_sha256} |
|
|
369
|
+
|
|
370
|
+
## Screen
|
|
371
|
+
|
|
372
|
+
Verdict: **{cand.screen.get('verdict', '-')}**
|
|
373
|
+
|
|
374
|
+
{checks}
|
|
375
|
+
|
|
376
|
+
## The rewrite
|
|
377
|
+
|
|
378
|
+
`{rel}/rewritten.md` — {parsed.body_lines} lines of body, from {original_lines}.
|
|
379
|
+
The original is beside it at `{rel}/original.txt`, which is data and not a document.
|
|
380
|
+
|
|
381
|
+
| field | value |
|
|
382
|
+
|---|---|
|
|
383
|
+
| role | {parsed.role} |
|
|
384
|
+
| phase | {' '.join(parsed.phases)} |
|
|
385
|
+
| tech | {' '.join(parsed.tech)} |
|
|
386
|
+
| provenance | {parsed.provenance} |
|
|
387
|
+
| license | {parsed.license} |
|
|
388
|
+
|
|
389
|
+
## The door
|
|
390
|
+
|
|
391
|
+
Read `rewritten.md` in full, then:
|
|
392
|
+
|
|
393
|
+
edify harvest admit {cand.id} --by <your name>
|
|
394
|
+
edify harvest reject {cand.id} --reason "<why>"
|
|
395
|
+
|
|
396
|
+
There is no other door — not for speed, not for volume.
|
|
397
|
+
"""
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
# -- ◆ the human door -------------------------------------------------------
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def admit(ctx: Context) -> int:
|
|
404
|
+
"""A person read it and says yes. This is the only step that cannot be automated.
|
|
405
|
+
|
|
406
|
+
It refuses to run without a terminal. A `--yes` flag here would be the whole
|
|
407
|
+
pipeline's single point of failure, so there is not one.
|
|
408
|
+
"""
|
|
409
|
+
ledger = _guard(ctx)
|
|
410
|
+
cand = _find(ledger, ctx.args.id)
|
|
411
|
+
if cand.state != "proposed":
|
|
412
|
+
raise EdifyError(
|
|
413
|
+
f"{cand.id} is `{cand.state}` — only a proposed candidate can be admitted",
|
|
414
|
+
hint="gather, screen, and propose come first",
|
|
415
|
+
)
|
|
416
|
+
if not cand.screen.get("verdict") == "pass":
|
|
417
|
+
raise EdifyError(f"{cand.id} did not pass the screen", hint="a screen failure is not a judgment call")
|
|
418
|
+
|
|
419
|
+
proposal = ctx.layout.harvest_proposals / cand.id / "rewritten.md"
|
|
420
|
+
if not proposal.is_file():
|
|
421
|
+
raise EdifyError(f"no rewrite at {ctx.layout.rel(proposal)}")
|
|
422
|
+
|
|
423
|
+
if not ctx.out.interactive:
|
|
424
|
+
raise EdifyError(
|
|
425
|
+
"admission needs a person at a terminal",
|
|
426
|
+
hint="gather, screen, rewrite, and propose run unattended; this one does not, and no flag changes that",
|
|
427
|
+
)
|
|
428
|
+
ctx.out.prompt_line(f"\n{proposal.read_text(encoding='utf-8')}\n")
|
|
429
|
+
answer = ctx.out.ask(f"admit {cand.id} as `{cand.name}` into the library? (type the name to confirm)")
|
|
430
|
+
if answer.strip() != cand.name:
|
|
431
|
+
ctx.out.line("not admitted")
|
|
432
|
+
return 1
|
|
433
|
+
|
|
434
|
+
parsed = skill_format.parse(proposal, proposal.name)
|
|
435
|
+
target = ctx.layout.library / f"{parsed.name}.md"
|
|
436
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
437
|
+
shutil.copyfile(proposal, target)
|
|
438
|
+
|
|
439
|
+
ledger.set_state(cand, "admitted")
|
|
440
|
+
cand.disposition = {"by": ctx.args.by, "on": date.today().isoformat(), "reason": "admitted"}
|
|
441
|
+
ledger.save()
|
|
442
|
+
|
|
443
|
+
installed, mirrored = _setup(ctx, target)
|
|
444
|
+
|
|
445
|
+
ctx.out.data(
|
|
446
|
+
{
|
|
447
|
+
"id": cand.id,
|
|
448
|
+
"admitted": True,
|
|
449
|
+
"path": ctx.layout.rel(target),
|
|
450
|
+
"installed": ctx.layout.rel(installed) if installed else None,
|
|
451
|
+
"mirrored": [ctx.layout.rel(p) for p in mirrored],
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
ctx.out.ok(f"{cand.name} → {ctx.layout.rel(target)}")
|
|
455
|
+
if installed:
|
|
456
|
+
ctx.out.ok(f"installed here too → {ctx.layout.rel(installed)} · indexed")
|
|
457
|
+
for path in mirrored:
|
|
458
|
+
ctx.out.ok(f"the runtime can see it at → {ctx.layout.rel(path)}")
|
|
459
|
+
ctx.out.note("record the yield in edify/harvest/sources.md — `edify harvest status` prints the row")
|
|
460
|
+
return 0
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _setup(ctx: Context, entry: Path) -> tuple[Path | None, list[Path]]:
|
|
464
|
+
"""The step after the door: an admitted entry becomes a usable one.
|
|
465
|
+
|
|
466
|
+
Admission copies the rewrite into `edify/skills/`, which is the authored library —
|
|
467
|
+
the thing that ships. That is not the same as being installed: `edify skills
|
|
468
|
+
resolve` reads `.edify/skills/`, and the host runtime reads `.claude/`, in one of
|
|
469
|
+
two shapes depending on the entry's `kind` — `skills/<name>/SKILL.md` for a skill,
|
|
470
|
+
`agents/<name>.md` for an agent. An entry that is only in the authored tree is
|
|
471
|
+
admitted and unusable, and the gap was quiet enough that a run could look finished
|
|
472
|
+
while nothing could load what it produced.
|
|
473
|
+
|
|
474
|
+
Returns both halves so admission can report where the thing actually is rather
|
|
475
|
+
than naming a directory and hoping. This is deliberately behind the human door
|
|
476
|
+
rather than before it — installing a stranger's text is exactly the thing that
|
|
477
|
+
waits for a person to say yes.
|
|
478
|
+
"""
|
|
479
|
+
from .. import governance, host, skills as skills_index
|
|
480
|
+
|
|
481
|
+
ctx.layout.skills_dir.mkdir(parents=True, exist_ok=True)
|
|
482
|
+
installed = ctx.layout.skills_dir / entry.name
|
|
483
|
+
shutil.copyfile(entry, installed)
|
|
484
|
+
rows, skipped = skills_index.build_index(ctx.layout)
|
|
485
|
+
written = host.sync(ctx.layout)
|
|
486
|
+
governance.rebuild(ctx.layout)
|
|
487
|
+
for problem in skipped:
|
|
488
|
+
ctx.out.warn(f"skipped in index — {problem}")
|
|
489
|
+
ctx.out.note(f"index now {rows} rows")
|
|
490
|
+
|
|
491
|
+
name = skill_format.parse(installed, ctx.layout.rel(installed)).name
|
|
492
|
+
mirrored = [w.path for w in written if w.name == name and w.kind in ("skill", "agent")]
|
|
493
|
+
return installed, mirrored
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def reject(ctx: Context) -> int:
|
|
497
|
+
"""A person read it and says no. The reason is the point — it is why this is cheap next time."""
|
|
498
|
+
ledger = _guard(ctx)
|
|
499
|
+
cand = _find(ledger, ctx.args.id)
|
|
500
|
+
if cand.state in ("admitted",):
|
|
501
|
+
raise EdifyError(f"{cand.id} is already admitted", hint="remove the entry from the library by hand")
|
|
502
|
+
ledger.set_state(cand, "rejected")
|
|
503
|
+
cand.disposition = {"by": ctx.args.by or "-", "on": date.today().isoformat(), "reason": ctx.args.reason}
|
|
504
|
+
ledger.save()
|
|
505
|
+
ctx.out.data({"id": cand.id, "rejected": True, "reason": ctx.args.reason})
|
|
506
|
+
ctx.out.line(f"{cand.id} rejected — {ctx.args.reason}")
|
|
507
|
+
return 0
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
# -- status -----------------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def status(ctx: Context) -> int:
|
|
514
|
+
ledger = _guard(ctx)
|
|
515
|
+
counts = ledger.counts()
|
|
516
|
+
rows = [
|
|
517
|
+
[c.id, c.state, c.license, c.source, c.updated, (c.disposition.get("reason") or "")[:48]]
|
|
518
|
+
for c in ledger.sorted()
|
|
519
|
+
]
|
|
520
|
+
ctx.out.data(
|
|
521
|
+
{
|
|
522
|
+
"counts": counts,
|
|
523
|
+
"candidates": [c.to_json() for c in ledger.sorted()],
|
|
524
|
+
"yield": [dict(zip(("source", "admitted", "rejected", "seen", "last_run"), y)) for y in ledger.by_source()],
|
|
525
|
+
}
|
|
526
|
+
)
|
|
527
|
+
if not rows:
|
|
528
|
+
ctx.out.line("nothing harvested")
|
|
529
|
+
ctx.out.note("`edify harvest pick` lists the sources")
|
|
530
|
+
return 0
|
|
531
|
+
ctx.out.table(["candidate", "state", "licence", "source", "updated", "reason"], rows)
|
|
532
|
+
ctx.out.line("")
|
|
533
|
+
ctx.out.line(" ".join(f"{k} {v}" for k, v in counts.items() if v))
|
|
534
|
+
ctx.out.line("")
|
|
535
|
+
ctx.out.line("yield, for edify/harvest/sources.md:")
|
|
536
|
+
for name, admitted, rejected, _seen, last in ledger.by_source():
|
|
537
|
+
ctx.out.line(f"| {name} | | | {admitted} | {rejected} | {last} |")
|
|
538
|
+
return 0
|