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
edify/interview.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"""The questions `edify init new` asks before it installs anything.
|
|
2
|
+
|
|
3
|
+
Everything else in this CLI is a pure function over files: it reads what is on disk
|
|
4
|
+
and writes what follows from it. Detection can find the language, the package manager,
|
|
5
|
+
and the test runner. It cannot find out that this is a rewrite of a system that is
|
|
6
|
+
already in production, that the person typing is the only one who knows the domain,
|
|
7
|
+
or that nothing may touch the payments module without a migration plan. Those are the
|
|
8
|
+
facts that decide how an agent should behave here, and there is exactly one place to
|
|
9
|
+
get them.
|
|
10
|
+
|
|
11
|
+
Three rules, which are the same three the library interview follows:
|
|
12
|
+
|
|
13
|
+
**A question is never load-bearing.** With no terminal — CI, a pipe, a model calling
|
|
14
|
+
the binary — nothing is asked, no profile is written, and the install is the one that
|
|
15
|
+
happened before this module existed.
|
|
16
|
+
|
|
17
|
+
**Every answer may be empty.** Enter skips a question; a profile with two answers in
|
|
18
|
+
it is worth more than an interrogation somebody abandoned halfway through.
|
|
19
|
+
|
|
20
|
+
**The answers are the repository's, not EDIFY's.** They are written to
|
|
21
|
+
`.edify/profile.md` in plain Markdown for a person to edit, and recorded in the ledger
|
|
22
|
+
as `answered` — an origin `edify upgrade` will never overwrite.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import os
|
|
28
|
+
import subprocess
|
|
29
|
+
from dataclasses import dataclass, field
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
from .agents import BY_ID
|
|
33
|
+
from .ui import Out
|
|
34
|
+
|
|
35
|
+
PROFILE_MARKER = "<!-- edify:profile -->"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class Question:
|
|
40
|
+
key: str
|
|
41
|
+
prompt: str
|
|
42
|
+
hint: str = ""
|
|
43
|
+
default: str = ""
|
|
44
|
+
# A question whose answer changes what gets installed, rather than what gets
|
|
45
|
+
# written down. Asked first, and asked even when the rest is skipped.
|
|
46
|
+
decides_install: bool = False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class Profile:
|
|
51
|
+
"""What the person said. Every field optional; the file shows what was answered."""
|
|
52
|
+
|
|
53
|
+
answers: dict[str, str] = field(default_factory=dict)
|
|
54
|
+
asked: bool = False
|
|
55
|
+
|
|
56
|
+
def get(self, key: str) -> str:
|
|
57
|
+
return (self.answers.get(key) or "").strip()
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def filled(self) -> dict[str, str]:
|
|
61
|
+
return {k: v.strip() for k, v in self.answers.items() if (v or "").strip()}
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def described(self) -> dict[str, str]:
|
|
65
|
+
"""The answers that describe the person and the work, as against the two that
|
|
66
|
+
decide what gets installed. Only these make a profile worth writing: a file
|
|
67
|
+
whose whole content is "runtimes: all" tells the next session nothing it could
|
|
68
|
+
not have seen by looking at the folder."""
|
|
69
|
+
return {k: v for k, v in self.filled.items() if k in DESCRIBING}
|
|
70
|
+
|
|
71
|
+
def as_dict(self) -> dict[str, str]:
|
|
72
|
+
return dict(self.filled)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# -- the questions -----------------------------------------------------------
|
|
76
|
+
# Eight, and they stop. The list is short on purpose: a setup command that interviews
|
|
77
|
+
# somebody for five minutes is a setup command they run once and then work around.
|
|
78
|
+
# The first two decide what gets installed, which is why they are asked first and why
|
|
79
|
+
# they are not part of what makes a profile worth writing.
|
|
80
|
+
|
|
81
|
+
QUESTIONS: tuple[Question, ...] = (
|
|
82
|
+
Question(
|
|
83
|
+
key="agents",
|
|
84
|
+
prompt=" which agents do you use here?",
|
|
85
|
+
hint="all · none · ids like claude,codex,cursor — this decides what gets installed",
|
|
86
|
+
default="all",
|
|
87
|
+
decides_install=True,
|
|
88
|
+
),
|
|
89
|
+
Question(
|
|
90
|
+
key="stack",
|
|
91
|
+
prompt=" anything in the stack that detection would miss?",
|
|
92
|
+
hint="tech ids like `postgres redis`, or enter to take what was detected",
|
|
93
|
+
default="",
|
|
94
|
+
decides_install=True,
|
|
95
|
+
),
|
|
96
|
+
Question(
|
|
97
|
+
key="name",
|
|
98
|
+
prompt=" what should an agent call you?",
|
|
99
|
+
),
|
|
100
|
+
Question(
|
|
101
|
+
key="role",
|
|
102
|
+
prompt=" what is your role on this?",
|
|
103
|
+
hint="founder · staff engineer · data scientist · learning to code — anything",
|
|
104
|
+
),
|
|
105
|
+
Question(
|
|
106
|
+
key="building",
|
|
107
|
+
prompt=" what is being built here, in one line?",
|
|
108
|
+
hint="this is the line every session starts from",
|
|
109
|
+
),
|
|
110
|
+
Question(
|
|
111
|
+
key="done",
|
|
112
|
+
prompt=" what does done look like for the next few weeks?",
|
|
113
|
+
),
|
|
114
|
+
Question(
|
|
115
|
+
key="explain",
|
|
116
|
+
prompt=" how much should an agent explain as it works?",
|
|
117
|
+
hint="brief · normal · teaching",
|
|
118
|
+
default="normal",
|
|
119
|
+
),
|
|
120
|
+
Question(
|
|
121
|
+
key="constraints",
|
|
122
|
+
prompt=" anything an agent must never do in this repository?",
|
|
123
|
+
hint="e.g. never touch migrations · never commit to main · ask before adding a dependency",
|
|
124
|
+
),
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
DESCRIBING = tuple(q.key for q in QUESTIONS if not q.decides_install)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def default_name() -> str:
|
|
132
|
+
"""A name to offer, from the machine rather than from a guess."""
|
|
133
|
+
try:
|
|
134
|
+
result = subprocess.run(
|
|
135
|
+
["git", "config", "--get", "user.name"],
|
|
136
|
+
capture_output=True,
|
|
137
|
+
text=True,
|
|
138
|
+
timeout=5,
|
|
139
|
+
)
|
|
140
|
+
if result.returncode == 0 and result.stdout.strip():
|
|
141
|
+
return result.stdout.strip()
|
|
142
|
+
except (OSError, subprocess.SubprocessError):
|
|
143
|
+
pass
|
|
144
|
+
return os.environ.get("USER") or os.environ.get("USERNAME") or ""
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def ask(out: Out, *, defaults: dict[str, str] | None = None) -> Profile:
|
|
148
|
+
"""Put the questions. Returns an unasked profile when there is nobody to ask."""
|
|
149
|
+
profile = Profile()
|
|
150
|
+
if not out.interactive:
|
|
151
|
+
return profile
|
|
152
|
+
|
|
153
|
+
supplied = dict(defaults or {})
|
|
154
|
+
out.prompt_line("")
|
|
155
|
+
out.prompt_line(out.c(" a few questions first", "bold"))
|
|
156
|
+
out.prompt_line(
|
|
157
|
+
out.c(
|
|
158
|
+
" Detection reads your files; these are the things files do not say."
|
|
159
|
+
" Enter skips any of them.",
|
|
160
|
+
"dim",
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
out.prompt_line("")
|
|
164
|
+
|
|
165
|
+
for question in QUESTIONS:
|
|
166
|
+
default = supplied.get(question.key, question.default)
|
|
167
|
+
if question.hint:
|
|
168
|
+
out.prompt_line(out.c(f" {question.hint}", "dim"))
|
|
169
|
+
profile.answers[question.key] = out.ask(question.prompt, default=default)
|
|
170
|
+
|
|
171
|
+
profile.asked = True
|
|
172
|
+
out.prompt_line("")
|
|
173
|
+
return profile
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# -- what the answers change -------------------------------------------------
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def agents_spec(profile: Profile, fallback: str) -> str:
|
|
180
|
+
"""The `--agents` value the answer implies, or the flag's own value.
|
|
181
|
+
|
|
182
|
+
A flag the person typed always beats an answer they gave to a default-filled
|
|
183
|
+
question, so an explicit `--agents claude` is not overridden by pressing enter
|
|
184
|
+
through the interview.
|
|
185
|
+
"""
|
|
186
|
+
answer = profile.get("agents")
|
|
187
|
+
if not answer:
|
|
188
|
+
return fallback
|
|
189
|
+
normalised = answer.replace(",", " ").split()
|
|
190
|
+
if len(normalised) == 1 and normalised[0].lower() in ("all", "none", "*"):
|
|
191
|
+
return normalised[0].lower()
|
|
192
|
+
known = [token.lower() for token in normalised if token.lower() in BY_ID]
|
|
193
|
+
return " ".join(known) if known else fallback
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def extra_tech(profile: Profile) -> list[str]:
|
|
197
|
+
"""Tech ids the person named that detection did not find."""
|
|
198
|
+
answer = profile.get("stack")
|
|
199
|
+
return [token.strip().lower() for token in answer.replace(",", " ").split() if token.strip()]
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# -- the file ----------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def render(profile: Profile) -> str:
|
|
206
|
+
"""`.edify/profile.md` — the answers, as prose an agent reads in one pass.
|
|
207
|
+
|
|
208
|
+
Written as headings and short lines rather than a table, because the reader is a
|
|
209
|
+
model loading it as context at the start of a session and a person editing it six
|
|
210
|
+
weeks later when the answers have changed. Both of them do better with sentences.
|
|
211
|
+
"""
|
|
212
|
+
name = profile.get("name")
|
|
213
|
+
role = profile.get("role")
|
|
214
|
+
who = " · ".join([p for p in (name, role) if p]) or "not stated"
|
|
215
|
+
|
|
216
|
+
lines = [
|
|
217
|
+
PROFILE_MARKER,
|
|
218
|
+
"# Who this repository is being built for",
|
|
219
|
+
"",
|
|
220
|
+
f"**Working here:** {who}",
|
|
221
|
+
"",
|
|
222
|
+
]
|
|
223
|
+
|
|
224
|
+
sections = (
|
|
225
|
+
("What is being built", "building"),
|
|
226
|
+
("What done looks like", "done"),
|
|
227
|
+
("Constraints — these are not suggestions", "constraints"),
|
|
228
|
+
)
|
|
229
|
+
for heading, key in sections:
|
|
230
|
+
value = profile.get(key)
|
|
231
|
+
if value:
|
|
232
|
+
lines += [f"## {heading}", "", value, ""]
|
|
233
|
+
|
|
234
|
+
explain = profile.get("explain")
|
|
235
|
+
if explain:
|
|
236
|
+
lines += [
|
|
237
|
+
"## How to talk to this person",
|
|
238
|
+
"",
|
|
239
|
+
f"Explanation: **{explain}**. "
|
|
240
|
+
+ _explain_note(explain),
|
|
241
|
+
"",
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
agents = profile.get("agents")
|
|
245
|
+
if agents:
|
|
246
|
+
lines += [f"**Agent runtimes installed here:** {agents}", ""]
|
|
247
|
+
|
|
248
|
+
lines += [
|
|
249
|
+
"---",
|
|
250
|
+
"",
|
|
251
|
+
"These answers came from `edify init new`. This file is yours: edit it whenever the",
|
|
252
|
+
"answers change. EDIFY records it in the ledger and never overwrites it on upgrade.",
|
|
253
|
+
"",
|
|
254
|
+
]
|
|
255
|
+
return "\n".join(lines)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _explain_note(explain: str) -> str:
|
|
259
|
+
key = explain.strip().lower()
|
|
260
|
+
if key.startswith("brief"):
|
|
261
|
+
return "Give the answer and the diff; skip the walkthrough unless it is asked for."
|
|
262
|
+
if key.startswith("teach"):
|
|
263
|
+
return "Say why, not only what — name the trade-off you took and the one you left."
|
|
264
|
+
return "Say what changed and why it was the right call, in a few lines."
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def block_lines(profile: Profile) -> list[str]:
|
|
268
|
+
"""The two or three lines the instruction files carry.
|
|
269
|
+
|
|
270
|
+
The profile itself stays in one file. What goes into `CLAUDE.md`, `AGENTS.md`, and
|
|
271
|
+
the rest is a pointer at it plus the one line that is worth spending context on
|
|
272
|
+
unconditionally — who this is and what they are building.
|
|
273
|
+
"""
|
|
274
|
+
if not profile.described:
|
|
275
|
+
return []
|
|
276
|
+
name = profile.get("name")
|
|
277
|
+
role = profile.get("role")
|
|
278
|
+
building = profile.get("building")
|
|
279
|
+
|
|
280
|
+
who = " · ".join([p for p in (name, role) if p])
|
|
281
|
+
first = who or ""
|
|
282
|
+
if building:
|
|
283
|
+
first = f"{first} — building {building}" if first else f"Building {building}"
|
|
284
|
+
lines = ["## Who you are working with", ""]
|
|
285
|
+
if first:
|
|
286
|
+
lines.append(first.rstrip(".") + ".")
|
|
287
|
+
lines.append("Read `.edify/profile.md` before the first task — constraints and tone are in it.")
|
|
288
|
+
return lines
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def write(path: Path, profile: Profile) -> bool:
|
|
292
|
+
"""Write the profile. Returns whether anything was written."""
|
|
293
|
+
if not profile.described:
|
|
294
|
+
return False
|
|
295
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
296
|
+
path.write_text(render(profile), encoding="utf-8")
|
|
297
|
+
return True
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def load(path: Path) -> Profile:
|
|
301
|
+
"""Read back what a previous run wrote, so a re-run can offer it as the default.
|
|
302
|
+
|
|
303
|
+
Deliberately forgiving: this file is meant to be hand-edited, and a person who
|
|
304
|
+
reformats it should not be re-interviewed from scratch. Only the fields that are
|
|
305
|
+
still recognisable come back; the rest are simply not offered as defaults.
|
|
306
|
+
"""
|
|
307
|
+
profile = Profile()
|
|
308
|
+
if not path.is_file():
|
|
309
|
+
return profile
|
|
310
|
+
try:
|
|
311
|
+
text = path.read_text(encoding="utf-8")
|
|
312
|
+
except (OSError, UnicodeDecodeError):
|
|
313
|
+
return profile
|
|
314
|
+
|
|
315
|
+
heading_keys = {
|
|
316
|
+
"what is being built": "building",
|
|
317
|
+
"what done looks like": "done",
|
|
318
|
+
"constraints — these are not suggestions": "constraints",
|
|
319
|
+
"constraints": "constraints",
|
|
320
|
+
}
|
|
321
|
+
current = ""
|
|
322
|
+
collected: dict[str, list[str]] = {}
|
|
323
|
+
for line in text.splitlines():
|
|
324
|
+
stripped = line.strip()
|
|
325
|
+
if stripped.startswith("## "):
|
|
326
|
+
current = heading_keys.get(stripped[3:].strip().lower(), "")
|
|
327
|
+
continue
|
|
328
|
+
if stripped == "---":
|
|
329
|
+
# The rule above the footer. Everything below it is EDIFY's own note
|
|
330
|
+
# about the file, and collecting it would append the note to whichever
|
|
331
|
+
# section happened to be last.
|
|
332
|
+
current = ""
|
|
333
|
+
continue
|
|
334
|
+
if stripped.startswith("Explanation:"):
|
|
335
|
+
profile.answers["explain"] = stripped.split("**")[1] if "**" in stripped else ""
|
|
336
|
+
continue
|
|
337
|
+
if stripped.startswith("**Working here:**"):
|
|
338
|
+
who = stripped.split("**Working here:**", 1)[1].strip()
|
|
339
|
+
if who and who != "not stated":
|
|
340
|
+
name, _, role = who.partition("·")
|
|
341
|
+
profile.answers["name"] = name.strip()
|
|
342
|
+
if role.strip():
|
|
343
|
+
profile.answers["role"] = role.strip()
|
|
344
|
+
continue
|
|
345
|
+
if stripped.startswith("**Agent runtimes installed here:**"):
|
|
346
|
+
profile.answers["agents"] = stripped.split(":**", 1)[1].strip()
|
|
347
|
+
continue
|
|
348
|
+
if current and stripped and not stripped.startswith(("#", "<!--", "**")):
|
|
349
|
+
collected.setdefault(current, []).append(stripped)
|
|
350
|
+
|
|
351
|
+
for key, value in collected.items():
|
|
352
|
+
profile.answers[key] = " ".join(value).strip()
|
|
353
|
+
profile.answers = {k: v for k, v in profile.answers.items() if v}
|
|
354
|
+
return profile
|
edify/library.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Choosing which library entries go into a repository.
|
|
2
|
+
|
|
3
|
+
A skill file is persistent trusted context: once installed, every matching spawn
|
|
4
|
+
loads it as instruction. `select_for_stack` already narrows the library to what the
|
|
5
|
+
detected stack can use — this module is the step after, where a person confirms the
|
|
6
|
+
list before any of it becomes trusted context in their codebase.
|
|
7
|
+
|
|
8
|
+
Two rules hold it in place:
|
|
9
|
+
|
|
10
|
+
**A question is never load-bearing.** With no terminal — CI, a pipe, a model calling
|
|
11
|
+
the binary — nothing is asked and the stack-matched set is installed, which is what
|
|
12
|
+
this command did before the question existed. `--skills` states the answer up front
|
|
13
|
+
for a script that wants one.
|
|
14
|
+
|
|
15
|
+
**The question is a person's, never a model's.** No `edify` command
|
|
16
|
+
lets a model decide what is installed. Being asked in a
|
|
17
|
+
terminal does not change that; it narrows a set that was already computed by lookup.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from .errors import EdifyError
|
|
26
|
+
from .formats import skill as skill_format
|
|
27
|
+
from .skills import select_for_stack
|
|
28
|
+
from .ui import Out
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class Candidate:
|
|
33
|
+
path: Path
|
|
34
|
+
skill: skill_format.Skill
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def name(self) -> str:
|
|
38
|
+
return self.skill.name or self.path.stem
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def candidates_for_stack(source_dir: Path, tech: list[str]) -> list[Candidate]:
|
|
42
|
+
"""The library entries this repository's stack matches, parsed and ordered."""
|
|
43
|
+
chosen = select_for_stack(source_dir, tech)
|
|
44
|
+
out = [Candidate(path, skill_format.parse(path, path.name)) for path in chosen]
|
|
45
|
+
# Role entries every repository needs come first, then the stack-specific ones.
|
|
46
|
+
return sorted(out, key=lambda c: (c.skill.tech != ["any"], c.skill.role, c.name))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def choose(out: Out, candidates: list[Candidate], spec: str = "auto") -> list[Candidate]:
|
|
50
|
+
"""Resolve `--skills` into the entries to install.
|
|
51
|
+
|
|
52
|
+
auto ask when there is a terminal, otherwise all
|
|
53
|
+
all | yes every entry the stack matched
|
|
54
|
+
none no entries — `edify skills add <path>` installs them later
|
|
55
|
+
ask ask, and fall back to all with nobody to ask
|
|
56
|
+
<names…> exactly these, by name or filename
|
|
57
|
+
"""
|
|
58
|
+
if not candidates:
|
|
59
|
+
return []
|
|
60
|
+
|
|
61
|
+
wanted = (spec or "auto").strip()
|
|
62
|
+
if wanted in ("all", "yes", "*"):
|
|
63
|
+
return list(candidates)
|
|
64
|
+
if wanted == "none":
|
|
65
|
+
return []
|
|
66
|
+
if wanted not in ("auto", "ask"):
|
|
67
|
+
return _by_name(candidates, wanted)
|
|
68
|
+
if wanted == "auto" and not out.interactive:
|
|
69
|
+
return list(candidates)
|
|
70
|
+
return _interview(out, candidates)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _interview(out: Out, candidates: list[Candidate]) -> list[Candidate]:
|
|
77
|
+
if not out.interactive:
|
|
78
|
+
return list(candidates)
|
|
79
|
+
|
|
80
|
+
out.prompt_line("")
|
|
81
|
+
out.prompt_line(out.c(" the agent library", "bold"))
|
|
82
|
+
out.prompt_line(
|
|
83
|
+
out.c(
|
|
84
|
+
" These files become trusted instruction in every matching session."
|
|
85
|
+
" Take the ones you want.",
|
|
86
|
+
"dim",
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
out.prompt_line("")
|
|
90
|
+
width = max(len(c.name) for c in candidates)
|
|
91
|
+
for i, candidate in enumerate(candidates, start=1):
|
|
92
|
+
skill = candidate.skill
|
|
93
|
+
out.prompt_line(
|
|
94
|
+
f" {str(i).rjust(2)} {candidate.name.ljust(width)} "
|
|
95
|
+
f"{(skill.role or '-').ljust(11)} {_tech(skill.tech).ljust(26)} "
|
|
96
|
+
+ out.c(f"{skill.body_lines} lines · {skill.provenance or '-'}", "dim")
|
|
97
|
+
)
|
|
98
|
+
out.prompt_line(f" {out.c(skill.description or '', 'dim')}")
|
|
99
|
+
out.prompt_line("")
|
|
100
|
+
|
|
101
|
+
while True:
|
|
102
|
+
answer = out.ask(
|
|
103
|
+
" which entries? all · none · numbers like 1-4,7 · names, then enter",
|
|
104
|
+
default="all",
|
|
105
|
+
)
|
|
106
|
+
try:
|
|
107
|
+
return _parse(candidates, answer)
|
|
108
|
+
except EdifyError as exc:
|
|
109
|
+
out.warn(exc.message)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _tech(tech: list[str], width: int = 26) -> str:
|
|
113
|
+
"""The stack column, kept to one width. A deep specialist names a dozen; the
|
|
114
|
+
first two say what it is, and `edify skills list` has the full set."""
|
|
115
|
+
full = " ".join(tech) or "any"
|
|
116
|
+
if len(full) <= width:
|
|
117
|
+
return full
|
|
118
|
+
kept: list[str] = []
|
|
119
|
+
for item in tech:
|
|
120
|
+
if len(" ".join([*kept, item])) > width - 2:
|
|
121
|
+
break
|
|
122
|
+
kept.append(item)
|
|
123
|
+
return " ".join(kept or tech[:1]) + " +" + str(len(tech) - len(kept or tech[:1]))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _parse(candidates: list[Candidate], answer: str) -> list[Candidate]:
|
|
127
|
+
text = answer.strip().lower()
|
|
128
|
+
if text in ("all", "a", "yes", "y", "*", ""):
|
|
129
|
+
return list(candidates)
|
|
130
|
+
if text in ("none", "n", "-"):
|
|
131
|
+
return []
|
|
132
|
+
if any(ch.isdigit() for ch in text) and not any(c.isalpha() for c in text.replace("-", " ")):
|
|
133
|
+
return _by_number(candidates, text)
|
|
134
|
+
return _by_name(candidates, text)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _by_number(candidates: list[Candidate], text: str) -> list[Candidate]:
|
|
138
|
+
picked: set[int] = set()
|
|
139
|
+
for part in text.replace(",", " ").split():
|
|
140
|
+
if "-" in part:
|
|
141
|
+
first, _, last = part.partition("-")
|
|
142
|
+
try:
|
|
143
|
+
lo, hi = int(first), int(last)
|
|
144
|
+
except ValueError:
|
|
145
|
+
raise EdifyError(f"`{part}` is not a number or a range") from None
|
|
146
|
+
picked.update(range(min(lo, hi), max(lo, hi) + 1))
|
|
147
|
+
continue
|
|
148
|
+
try:
|
|
149
|
+
picked.add(int(part))
|
|
150
|
+
except ValueError:
|
|
151
|
+
raise EdifyError(f"`{part}` is not a number or a range") from None
|
|
152
|
+
|
|
153
|
+
out_of_range = sorted(n for n in picked if not 1 <= n <= len(candidates))
|
|
154
|
+
if out_of_range:
|
|
155
|
+
raise EdifyError(f"there is no entry {out_of_range[0]} — the list runs 1 to {len(candidates)}")
|
|
156
|
+
return [candidates[n - 1] for n in sorted(picked)]
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _by_name(candidates: list[Candidate], text: str) -> list[Candidate]:
|
|
160
|
+
by_name = {c.name.lower(): c for c in candidates}
|
|
161
|
+
by_name.update({c.path.stem.lower(): c for c in candidates})
|
|
162
|
+
picked: list[Candidate] = []
|
|
163
|
+
unknown: list[str] = []
|
|
164
|
+
for token in text.replace(",", " ").split():
|
|
165
|
+
key = token.lower().removesuffix(".md")
|
|
166
|
+
candidate = by_name.get(key)
|
|
167
|
+
if candidate is None:
|
|
168
|
+
unknown.append(token)
|
|
169
|
+
elif candidate not in picked:
|
|
170
|
+
picked.append(candidate)
|
|
171
|
+
if unknown:
|
|
172
|
+
raise EdifyError(
|
|
173
|
+
f"no entry named `{unknown[0]}`",
|
|
174
|
+
hint="names are the ones in the list; `all` takes every one of them",
|
|
175
|
+
)
|
|
176
|
+
return sorted(picked, key=lambda c: candidates.index(c))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Offline licensing: a signed receipt, verified locally, with no phone-home.
|
|
2
|
+
|
|
3
|
+
Everything in EDIFY works with no network. A licence check is not going to be the
|
|
4
|
+
one exception, so the token carries its own proof and the verification is a
|
|
5
|
+
signature check against an embedded public key.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .tier import (
|
|
9
|
+
PLANS,
|
|
10
|
+
RETIRED_PLANS,
|
|
11
|
+
Entitlement,
|
|
12
|
+
clear,
|
|
13
|
+
current,
|
|
14
|
+
license_path,
|
|
15
|
+
save,
|
|
16
|
+
)
|
|
17
|
+
from .token import License, issue, parse
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"Entitlement",
|
|
21
|
+
"License",
|
|
22
|
+
"PLANS",
|
|
23
|
+
"RETIRED_PLANS",
|
|
24
|
+
"clear",
|
|
25
|
+
"current",
|
|
26
|
+
"issue",
|
|
27
|
+
"license_path",
|
|
28
|
+
"parse",
|
|
29
|
+
"save",
|
|
30
|
+
]
|