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,333 @@
|
|
|
1
|
+
"""`edify init` — seven things, and then it stops.
|
|
2
|
+
|
|
3
|
+
Detect · extract · scrape conventions · select skills · seed the registry · write
|
|
4
|
+
`CLAUDE.md` · record what it installed. No interview, no constitution, no governance
|
|
5
|
+
level, and no archetype.
|
|
6
|
+
|
|
7
|
+
The one question it asks is which library entries to take, because those become
|
|
8
|
+
trusted instruction in every matching session and a person should see the list
|
|
9
|
+
first. With no terminal it asks nothing and installs the stack-matched set.
|
|
10
|
+
|
|
11
|
+
`init` on a repository that already has an AI instruction file **merges, never
|
|
12
|
+
overwrites**. Somebody wrote that file on purpose.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import shutil
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from .. import (
|
|
21
|
+
__version__, agents, anim, assets, governance, host, interview, library,
|
|
22
|
+
skills as skills_index,
|
|
23
|
+
)
|
|
24
|
+
from ..agents import BLOCK_BEGIN, BLOCK_END, Instructions
|
|
25
|
+
from ..conventions import scrape
|
|
26
|
+
from ..context import Context
|
|
27
|
+
from ..detect import Stack, detect
|
|
28
|
+
from ..graph import extract
|
|
29
|
+
from ..tsv import write_rows
|
|
30
|
+
|
|
31
|
+
# Kept under their old names because `setup` and anything else that reasoned about
|
|
32
|
+
# the block imported them from here first. The definition lives in `agents.py` now,
|
|
33
|
+
# with the rest of what a runtime reads.
|
|
34
|
+
CLAUDE_BEGIN = BLOCK_BEGIN
|
|
35
|
+
CLAUDE_END = BLOCK_END
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def run(ctx: Context) -> int:
|
|
39
|
+
root = ctx.layout.root
|
|
40
|
+
out = ctx.out
|
|
41
|
+
force = ctx.args.force
|
|
42
|
+
|
|
43
|
+
# `setup` and `init new` print the wordmark themselves before their own opening
|
|
44
|
+
# lines, and say so with `caller_opens` — otherwise it appears twice in eight
|
|
45
|
+
# lines. Mirrors `caller_closes` at the bottom of this function.
|
|
46
|
+
if not getattr(ctx.args, "caller_opens", False):
|
|
47
|
+
anim.banner(out, "init")
|
|
48
|
+
|
|
49
|
+
out.note(f"repository root: {root}")
|
|
50
|
+
|
|
51
|
+
# 1 · detect ---------------------------------------------------------
|
|
52
|
+
stack = detect(root)
|
|
53
|
+
if ctx.args.stack and ctx.args.stack != "auto":
|
|
54
|
+
declared = [t.strip().lower() for t in ctx.args.stack.replace(",", " ").split() if t.strip()]
|
|
55
|
+
stack.frameworks = sorted(set(stack.frameworks) | set(declared))
|
|
56
|
+
out.field("stack", f"{', '.join(stack.tech) or 'nothing detected'}")
|
|
57
|
+
out.field("manager", f"{stack.package_manager} · test runner {stack.test_runner}")
|
|
58
|
+
|
|
59
|
+
ctx.layout.edify.mkdir(parents=True, exist_ok=True)
|
|
60
|
+
|
|
61
|
+
_write_stack(ctx, stack)
|
|
62
|
+
|
|
63
|
+
# 2 · extract --------------------------------------------------------
|
|
64
|
+
result = None
|
|
65
|
+
if not ctx.args.no_graph:
|
|
66
|
+
with anim.spinner(out, "reading every file, building the map"):
|
|
67
|
+
result = extract.build(ctx.layout, backend=ctx.args.extractor)
|
|
68
|
+
out.field("graph", f"{result.nodes} nodes · {result.edges} edges · {result.files} files")
|
|
69
|
+
if result.uncovered:
|
|
70
|
+
out.line(
|
|
71
|
+
" " * 12 + "not covered: "
|
|
72
|
+
+ ", ".join(sorted(result.uncovered))
|
|
73
|
+
+ " — these have no nodes, which is stated rather than guessed"
|
|
74
|
+
)
|
|
75
|
+
else:
|
|
76
|
+
out.field("graph", "skipped (--no-graph)")
|
|
77
|
+
|
|
78
|
+
# 3 · conventions ----------------------------------------------------
|
|
79
|
+
if force or not ctx.layout.conventions.exists():
|
|
80
|
+
ctx.layout.conventions.write_text(scrape(root, stack), encoding="utf-8")
|
|
81
|
+
out.field("conventions", "scraped from config files · zero model calls")
|
|
82
|
+
else:
|
|
83
|
+
out.field("conventions", "kept (already present)")
|
|
84
|
+
|
|
85
|
+
# 4 · select skills --------------------------------------------------
|
|
86
|
+
# No spinner around this one: `_install_skills` may stop and ask which entries
|
|
87
|
+
# to take, and an animation painting over a question is a question nobody can
|
|
88
|
+
# read. `Out.interactive` and `Out.animated` are both true at a terminal.
|
|
89
|
+
installed, declined, unmatched = _install_skills(ctx, stack, force)
|
|
90
|
+
detail = f"{installed} installed"
|
|
91
|
+
if declined:
|
|
92
|
+
detail += f" · {declined} declined"
|
|
93
|
+
detail += f" · {unmatched} in the library did not match this stack"
|
|
94
|
+
out.field("skills", detail)
|
|
95
|
+
rows, invalid = skills_index.build_index(ctx.layout)
|
|
96
|
+
out.field("index", f"{rows} lookup rows")
|
|
97
|
+
for problem in invalid:
|
|
98
|
+
out.warn(f"skipped in index — {problem}")
|
|
99
|
+
|
|
100
|
+
# 5 · seed the registry ----------------------------------------------
|
|
101
|
+
if force or not ctx.layout.mcp.exists():
|
|
102
|
+
ctx.layout.mcp.write_text(assets.read("mcp", "default-registry.md"), encoding="utf-8")
|
|
103
|
+
out.field("mcp", "registry seeded with one entry: the documentation server")
|
|
104
|
+
else:
|
|
105
|
+
out.field("mcp", "kept (already present)")
|
|
106
|
+
|
|
107
|
+
# 6 · the methodology surface and CLAUDE.md --------------------------
|
|
108
|
+
commands = _install_commands(ctx, force)
|
|
109
|
+
out.field("commands", f"{commands} installed under .edify/commands/")
|
|
110
|
+
_install_formats(ctx, force)
|
|
111
|
+
|
|
112
|
+
targets = agents.resolve(
|
|
113
|
+
getattr(ctx.args, "agents", ""),
|
|
114
|
+
getattr(ctx.args, "host", "claude"),
|
|
115
|
+
root=ctx.layout.root,
|
|
116
|
+
)
|
|
117
|
+
for path, action in _write_instructions(ctx, stack, targets):
|
|
118
|
+
out.field("wrote", f"{path} — {action}")
|
|
119
|
+
|
|
120
|
+
if targets:
|
|
121
|
+
out.field("agents", f"{len(targets)} runtime(s) — each one's own commands and skills:")
|
|
122
|
+
with anim.spinner(out, "mirroring skills into each runtime"):
|
|
123
|
+
lines = _sync_host(ctx, targets)
|
|
124
|
+
for kind, text in lines:
|
|
125
|
+
(out.warn if kind == "warn" else out.line)(text)
|
|
126
|
+
ctx.layout.specs.mkdir(parents=True, exist_ok=True)
|
|
127
|
+
|
|
128
|
+
profile = getattr(ctx, "profile", None)
|
|
129
|
+
if profile is not None and interview.write(ctx.layout.profile, profile):
|
|
130
|
+
out.field("profile", ".edify/profile.md — your answers, which every session reads")
|
|
131
|
+
|
|
132
|
+
# 7 · record what was installed --------------------------------------
|
|
133
|
+
ledger = governance.rebuild(ctx.layout)
|
|
134
|
+
out.field(
|
|
135
|
+
"governance",
|
|
136
|
+
f"{len(ledger)} files recorded in .edify/governance.tsv — origin, licence, and hash for each",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
out.data(
|
|
140
|
+
{
|
|
141
|
+
"root": str(root),
|
|
142
|
+
"stack": stack.as_dict(),
|
|
143
|
+
"graph": result.as_dict() if result else None,
|
|
144
|
+
"skills_installed": installed,
|
|
145
|
+
"skills_declined": declined,
|
|
146
|
+
"index_rows": rows,
|
|
147
|
+
"governed_files": len(ledger),
|
|
148
|
+
"agents": [t.id for t in targets],
|
|
149
|
+
"instructions": [i.path for i in agents.instruction_files(targets)],
|
|
150
|
+
"profile": profile.as_dict() if profile is not None else None,
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
# A caller that prints its own closing summary says so, so the person is not told
|
|
154
|
+
# what to do next twice in eight lines.
|
|
155
|
+
if not getattr(ctx.args, "caller_closes", False):
|
|
156
|
+
out.line("")
|
|
157
|
+
out.next("Next: /spec — write the spec before anything else.")
|
|
158
|
+
return 0
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# ---------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _write_stack(ctx: Context, stack: Stack) -> None:
|
|
165
|
+
rows = [["language", lang] for lang in stack.languages]
|
|
166
|
+
rows += [["framework", fw] for fw in stack.frameworks]
|
|
167
|
+
rows += [
|
|
168
|
+
["package_manager", stack.package_manager],
|
|
169
|
+
["test_runner", stack.test_runner],
|
|
170
|
+
["edify_version", __version__],
|
|
171
|
+
]
|
|
172
|
+
write_rows(ctx.layout.stack, rows, ("key", "value"))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _install_skills(ctx: Context, stack: Stack, force: bool) -> tuple[int, int, int]:
|
|
176
|
+
"""Install the entries the person kept. Returns (installed, declined, unmatched).
|
|
177
|
+
|
|
178
|
+
An entry already on disk that is declined this time is left alone rather than
|
|
179
|
+
deleted — `init` merges. `edify skills list` shows what is there, and removing
|
|
180
|
+
one is `rm`, which is a thing a person can see themselves doing.
|
|
181
|
+
"""
|
|
182
|
+
source = assets.subtree("skills")
|
|
183
|
+
ctx.layout.skills_dir.mkdir(parents=True, exist_ok=True)
|
|
184
|
+
candidates = library.candidates_for_stack(source, stack.tech)
|
|
185
|
+
spec = "all" if getattr(ctx.args, "yes", False) else getattr(ctx.args, "skills", "auto")
|
|
186
|
+
chosen = library.choose(ctx.out, candidates, spec)
|
|
187
|
+
chosen_paths = {c.path for c in chosen}
|
|
188
|
+
|
|
189
|
+
for candidate in chosen:
|
|
190
|
+
target = ctx.layout.skills_dir / candidate.path.name
|
|
191
|
+
if target.exists() and not force:
|
|
192
|
+
continue
|
|
193
|
+
shutil.copyfile(candidate.path, target)
|
|
194
|
+
|
|
195
|
+
total = len(list(source.glob("*.md")))
|
|
196
|
+
return len(chosen), len(candidates) - len(chosen), max(0, total - len(candidates))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _install_commands(ctx: Context, force: bool) -> int:
|
|
200
|
+
source = assets.subtree("commands")
|
|
201
|
+
ctx.layout.commands_dir.mkdir(parents=True, exist_ok=True)
|
|
202
|
+
count = 0
|
|
203
|
+
for path in sorted(source.glob("*.md")):
|
|
204
|
+
target = ctx.layout.commands_dir / path.name
|
|
205
|
+
if not target.exists() or force:
|
|
206
|
+
shutil.copyfile(path, target)
|
|
207
|
+
count += 1
|
|
208
|
+
return count
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _install_formats(ctx: Context, force: bool) -> None:
|
|
212
|
+
source = assets.subtree("formats")
|
|
213
|
+
ctx.layout.formats_dir.mkdir(parents=True, exist_ok=True)
|
|
214
|
+
for path in sorted(source.glob("*.md")):
|
|
215
|
+
target = ctx.layout.formats_dir / path.name
|
|
216
|
+
if not target.exists() or force:
|
|
217
|
+
shutil.copyfile(path, target)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _sync_host(ctx: Context, targets: list[agents.Target]) -> list[tuple[str, str]]:
|
|
221
|
+
"""Each runtime's own directories: one pointer per command, skill, and agent.
|
|
222
|
+
|
|
223
|
+
A library entry under `.edify/skills/` is installed as far as `edify skills list`
|
|
224
|
+
is concerned and invisible to the runtime the person is typing into, which
|
|
225
|
+
discovers skills at `.claude/skills/<name>/SKILL.md` and subagents at
|
|
226
|
+
`.claude/agents/<name>.md`. `host.sync_target` writes that mirror and `kind`
|
|
227
|
+
decides which of the two an entry gets; `host.stale` reports the pointers whose
|
|
228
|
+
entry has since been removed or changed kind, because a capability the runtime
|
|
229
|
+
offers and then cannot read is worse than one it never knew about.
|
|
230
|
+
|
|
231
|
+
It **returns** its lines rather than printing them, because it runs inside the
|
|
232
|
+
spinner and a `print` racing an animation is two half-written lines. The caller
|
|
233
|
+
emits them once the region is erased.
|
|
234
|
+
"""
|
|
235
|
+
lines: list[tuple[str, str]] = []
|
|
236
|
+
if not targets:
|
|
237
|
+
return lines
|
|
238
|
+
skipped: list = []
|
|
239
|
+
for target in targets:
|
|
240
|
+
written = host.sync_target(ctx.layout, target)
|
|
241
|
+
if not written:
|
|
242
|
+
continue
|
|
243
|
+
counts: dict[str, int] = {}
|
|
244
|
+
for item in written:
|
|
245
|
+
counts[item.kind] = counts.get(item.kind, 0) + (1 if item.action != "skipped" else 0)
|
|
246
|
+
skipped += [item for item in written if item.action == "skipped"]
|
|
247
|
+
parts = [f"{counts.get('command', 0)} commands"]
|
|
248
|
+
if target.skills:
|
|
249
|
+
parts.append(f"{counts.get('skill', 0)} skills")
|
|
250
|
+
if target.agents:
|
|
251
|
+
parts.append(f"{counts.get('agent', 0)} agents")
|
|
252
|
+
lines.append(("line", f" {target.id.ljust(9)} {' · '.join(parts)} ({target.label})"))
|
|
253
|
+
|
|
254
|
+
for item in skipped:
|
|
255
|
+
lines.append(("warn", f"kept your own file at {ctx.layout.rel(item.path)} — not an edify pointer"))
|
|
256
|
+
for path in host.stale(ctx.layout):
|
|
257
|
+
lines.append(
|
|
258
|
+
("warn", f"{ctx.layout.rel(path)} points at an entry that is no longer installed — safe to delete")
|
|
259
|
+
)
|
|
260
|
+
return lines
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _write_instructions(ctx: Context, stack: Stack, targets: list[agents.Target]) -> list[tuple[str, str]]:
|
|
264
|
+
"""One instruction file per runtime, deduplicated. `(path, what happened)` each.
|
|
265
|
+
|
|
266
|
+
`CLAUDE.md`, `AGENTS.md`, `GEMINI.md` and the rest all carry the same block: the
|
|
267
|
+
same commands resolve, the same graph answers the same questions, and a team with
|
|
268
|
+
two tools open should not be running two methodologies. Only the wrapper differs.
|
|
269
|
+
"""
|
|
270
|
+
body = _instruction_body(ctx, stack)
|
|
271
|
+
out: list[tuple[str, str]] = []
|
|
272
|
+
for item in agents.instruction_files(targets):
|
|
273
|
+
path = ctx.layout.root / item.path
|
|
274
|
+
out.append((item.path, _merge_block(path, body, item)))
|
|
275
|
+
return out
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _merge_block(path: Path, body: str, item: Instructions) -> str:
|
|
279
|
+
"""Fifteen lines. Merged into an existing file, never over it."""
|
|
280
|
+
block = f"{BLOCK_BEGIN}\n{body}\n{BLOCK_END}\n"
|
|
281
|
+
|
|
282
|
+
if not path.exists():
|
|
283
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
284
|
+
path.write_text(_header(item) + block, encoding="utf-8")
|
|
285
|
+
return "written"
|
|
286
|
+
|
|
287
|
+
existing = path.read_text(encoding="utf-8")
|
|
288
|
+
if BLOCK_BEGIN in existing and BLOCK_END in existing:
|
|
289
|
+
start = existing.index(BLOCK_BEGIN)
|
|
290
|
+
end = existing.index(BLOCK_END) + len(BLOCK_END)
|
|
291
|
+
updated = existing[:start] + block.rstrip("\n") + existing[end:]
|
|
292
|
+
path.write_text(updated, encoding="utf-8")
|
|
293
|
+
return "updated (edify block replaced)"
|
|
294
|
+
|
|
295
|
+
separator = "" if existing.endswith("\n\n") else ("\n" if existing.endswith("\n") else "\n\n")
|
|
296
|
+
path.write_text(existing + separator + "\n" + block, encoding="utf-8")
|
|
297
|
+
return "merged (existing content kept above)"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _header(item: Instructions) -> str:
|
|
301
|
+
"""What has to sit outside the block for this runtime to read the file at all.
|
|
302
|
+
|
|
303
|
+
Cursor decides whether a rule applies from its frontmatter, so a `.mdc` file
|
|
304
|
+
without `alwaysApply` is a file Cursor has and never loads. It goes outside the
|
|
305
|
+
markers because it belongs to the file rather than to the block, and a re-run that
|
|
306
|
+
replaces the block leaves it where it is.
|
|
307
|
+
"""
|
|
308
|
+
if item.style == "mdc":
|
|
309
|
+
return (
|
|
310
|
+
"---\n"
|
|
311
|
+
"description: EDIFY — the harness this repository is built with\n"
|
|
312
|
+
"alwaysApply: true\n"
|
|
313
|
+
"---\n\n"
|
|
314
|
+
)
|
|
315
|
+
return ""
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _instruction_body(ctx: Context, stack: Stack) -> str:
|
|
319
|
+
template = assets.read("templates", "CLAUDE.md")
|
|
320
|
+
languages = ", ".join(stack.languages) or "not detected"
|
|
321
|
+
frameworks = ", ".join(stack.frameworks)
|
|
322
|
+
stack_line = languages + (f" · {frameworks}" if frameworks else "")
|
|
323
|
+
body = (
|
|
324
|
+
template.replace("{{repo}}", ctx.layout.root.name)
|
|
325
|
+
.replace("{{stack}}", stack_line)
|
|
326
|
+
.replace("{{test}}", stack.test_runner)
|
|
327
|
+
.strip()
|
|
328
|
+
)
|
|
329
|
+
# The interview's answers, in the two lines that are worth spending context on
|
|
330
|
+
# every session. Everything else it asked stays in `.edify/profile.md`.
|
|
331
|
+
profile = getattr(ctx, "profile", None)
|
|
332
|
+
extra = interview.block_lines(profile) if profile is not None else []
|
|
333
|
+
return body + ("\n\n" + "\n".join(extra) if extra else "")
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""`edify init new [PATH]` — a folder, from nothing, for whichever agent is opened.
|
|
2
|
+
|
|
3
|
+
Three commands now install, and they differ in what they assume:
|
|
4
|
+
|
|
5
|
+
edify init a repository already under way. Finds its root by walking up,
|
|
6
|
+
keeps every file already there, merges into an instruction
|
|
7
|
+
file somebody else wrote. One runtime: Claude Code.
|
|
8
|
+
edify setup PATH the same install, with the root pinned to one folder so a new
|
|
9
|
+
directory inside a checkout does not install into its parent.
|
|
10
|
+
edify init new a folder set up from zero. Root pinned, EDIFY's own surface
|
|
11
|
+
cleared first, every library entry installed, and an
|
|
12
|
+
instruction file written for **every** agent runtime in the
|
|
13
|
+
table — CLAUDE.md, AGENTS.md, GEMINI.md, the Copilot file, the
|
|
14
|
+
Cursor rule — each with the same block in it.
|
|
15
|
+
|
|
16
|
+
And one thing none of the others do: it asks. Detection reads `package.json` and finds
|
|
17
|
+
the test runner. It cannot find out that this is a rewrite of something already in
|
|
18
|
+
production, that the person typing is the only one who knows the domain, or that
|
|
19
|
+
nothing may touch the payments module without a migration plan. Those facts decide how
|
|
20
|
+
an agent should behave in this repository and there is exactly one place to get them,
|
|
21
|
+
so `init new` asks eight short questions before it installs anything, writes the
|
|
22
|
+
answers to `.edify/profile.md`, and points every instruction file at that file.
|
|
23
|
+
|
|
24
|
+
The questions are asked **first**, because two of them change what gets installed —
|
|
25
|
+
which runtimes, and what detection missed. An interview after the install would be a
|
|
26
|
+
survey.
|
|
27
|
+
|
|
28
|
+
With no terminal — CI, a pipe, a model calling the binary — nothing is asked, no
|
|
29
|
+
profile is written, and the install is the full one. A question is never load-bearing.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
|
|
36
|
+
from .. import agents, anim, host, interview
|
|
37
|
+
from ..context import Context
|
|
38
|
+
from ..errors import EdifyError
|
|
39
|
+
from ..paths import Layout
|
|
40
|
+
from . import init_cmd
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def run(ctx: Context) -> int:
|
|
44
|
+
root = Path(getattr(ctx.args, "path", None) or ".").expanduser()
|
|
45
|
+
if root.exists() and not root.is_dir():
|
|
46
|
+
raise EdifyError(f"{root} is a file, not a folder")
|
|
47
|
+
|
|
48
|
+
created = not root.exists()
|
|
49
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
root = root.resolve()
|
|
51
|
+
|
|
52
|
+
# The root is pinned, not searched. `find_root` walks upward, so `mkdir service &&
|
|
53
|
+
# cd service && edify init` inside an existing checkout installs into the parent —
|
|
54
|
+
# silently, into the same `.edify/` the outer repository already has.
|
|
55
|
+
layout = Layout(root)
|
|
56
|
+
out = ctx.out
|
|
57
|
+
|
|
58
|
+
# Once, above the first line, and `init_cmd` is told not to print a second.
|
|
59
|
+
anim.banner(out, "init new")
|
|
60
|
+
ctx.args.caller_opens = True
|
|
61
|
+
|
|
62
|
+
out.field("init new", f"{root}{' (created)' if created else ''}")
|
|
63
|
+
out.field("", "a folder set up from zero, for every agent that reads a repository")
|
|
64
|
+
|
|
65
|
+
# 1 · ask, before anything is written ---------------------------------
|
|
66
|
+
profile = _interview(ctx, layout)
|
|
67
|
+
|
|
68
|
+
# 2 · what the answers changed ----------------------------------------
|
|
69
|
+
ctx.args.agents = interview.agents_spec(profile, getattr(ctx.args, "agents", "all") or "all")
|
|
70
|
+
extra = interview.extra_tech(profile)
|
|
71
|
+
if extra:
|
|
72
|
+
declared = getattr(ctx.args, "stack", "auto")
|
|
73
|
+
base = "" if declared in ("auto", "", None) else declared
|
|
74
|
+
ctx.args.stack = " ".join(filter(None, [base, *extra]))
|
|
75
|
+
|
|
76
|
+
chosen = agents.resolve(ctx.args.agents, getattr(ctx.args, "host", "claude"), root=root)
|
|
77
|
+
out.line("")
|
|
78
|
+
if chosen:
|
|
79
|
+
out.line("installing for:")
|
|
80
|
+
for target in chosen:
|
|
81
|
+
out.line(f" {target.id.ljust(9)} {target.label.ljust(22)} {target.notes}")
|
|
82
|
+
else:
|
|
83
|
+
out.line("installing for: nothing but .edify/ — no runtime files were asked for")
|
|
84
|
+
|
|
85
|
+
# 3 · clear EDIFY's own surface ---------------------------------------
|
|
86
|
+
# `init new` means everything, again, properly. `--keep` is for re-running it over
|
|
87
|
+
# a folder whose pointers are fine and whose answers have changed.
|
|
88
|
+
if not getattr(ctx.args, "keep", False):
|
|
89
|
+
cleared = host.clear(layout)
|
|
90
|
+
out.line("")
|
|
91
|
+
out.field("fresh", f"{len(cleared)} edify-owned path(s) cleared before installing")
|
|
92
|
+
for path, action in cleared:
|
|
93
|
+
out.note(f" {action} {layout.rel(path)}")
|
|
94
|
+
|
|
95
|
+
# 4 · install ----------------------------------------------------------
|
|
96
|
+
ctx.args.force = True # `new` means install everything, not merge into it
|
|
97
|
+
ctx.args.caller_closes = True # the closing summary below is this command's
|
|
98
|
+
if getattr(ctx.args, "skills", "all") in ("auto", "", None):
|
|
99
|
+
ctx.args.skills = "all"
|
|
100
|
+
|
|
101
|
+
scoped = Context(args=ctx.args, layout=layout, out=out, profile=profile)
|
|
102
|
+
out.line("")
|
|
103
|
+
code = init_cmd.run(scoped)
|
|
104
|
+
if code != 0:
|
|
105
|
+
return code
|
|
106
|
+
|
|
107
|
+
_closing(ctx, layout, chosen, profile)
|
|
108
|
+
return 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _interview(ctx: Context, layout: Layout) -> interview.Profile:
|
|
115
|
+
"""The questions, with a re-run offering last time's answers as the defaults.
|
|
116
|
+
|
|
117
|
+
`--yes` and `--no-interview` both skip them, and so does having nobody to ask.
|
|
118
|
+
They are not the same thing said twice: `--yes` is "take every default", which is
|
|
119
|
+
what a script means, and `--no-interview` is "install, and I will write the profile
|
|
120
|
+
myself", which is what somebody with a profile already in hand means.
|
|
121
|
+
"""
|
|
122
|
+
if getattr(ctx.args, "yes", False) or getattr(ctx.args, "no_interview", False):
|
|
123
|
+
return interview.load(layout.profile)
|
|
124
|
+
|
|
125
|
+
previous = interview.load(layout.profile)
|
|
126
|
+
defaults = {k: v for k, v in previous.filled.items()}
|
|
127
|
+
defaults.setdefault("name", interview.default_name())
|
|
128
|
+
defaults.setdefault("agents", getattr(ctx.args, "agents", "all") or "all")
|
|
129
|
+
|
|
130
|
+
profile = interview.ask(ctx.out, defaults=defaults)
|
|
131
|
+
if not profile.asked and previous.filled:
|
|
132
|
+
# No terminal, but a previous run's answers are on disk. Keeping them is the
|
|
133
|
+
# only behaviour that does not quietly throw away what somebody typed.
|
|
134
|
+
return previous
|
|
135
|
+
return profile
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _closing(ctx: Context, layout: Layout, chosen: list[agents.Target], profile: interview.Profile) -> None:
|
|
139
|
+
out = ctx.out
|
|
140
|
+
files = [item.path for item in agents.instruction_files(chosen)]
|
|
141
|
+
width = max([len(p) for p in [*files, ".edify/profile.md", ".edify/"]] or [10])
|
|
142
|
+
|
|
143
|
+
out.line("")
|
|
144
|
+
out.line("what is on disk now")
|
|
145
|
+
out.line(f" {'.edify/'.ljust(width)} the harness: graph, skills, commands, formats, registry, ledger")
|
|
146
|
+
for path in files:
|
|
147
|
+
out.line(f" {path.ljust(width)} read at the start of every session")
|
|
148
|
+
if profile.filled:
|
|
149
|
+
out.line(f" {'.edify/profile.md'.ljust(width)} your answers — edit them whenever they change")
|
|
150
|
+
out.line("")
|
|
151
|
+
out.next("Next: /spec — write the spec before anything else.")
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""`edify license` — what this machine is entitled to, and how to change it.
|
|
2
|
+
|
|
3
|
+
`status` says which plan this machine is on and what a licence would add;
|
|
4
|
+
`activate` installs a signed token; `deactivate` removes it. There is no purchase
|
|
5
|
+
and no price: the public edition is every command, uncapped, and a team or
|
|
6
|
+
partner licence is issued on request.
|
|
7
|
+
|
|
8
|
+
Offline throughout. Activation writes a signed token to a file; nothing is sent
|
|
9
|
+
anywhere, and no command in this CLI opens a socket to check a plan.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import time
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from ..context import Context
|
|
18
|
+
from ..distribution import CONTACT
|
|
19
|
+
from ..errors import EdifyError
|
|
20
|
+
from ..licensing import tier
|
|
21
|
+
from ..licensing.token import parse
|
|
22
|
+
from ..ui import MARKS
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def status(ctx: Context) -> int:
|
|
26
|
+
ent = ctx.entitlement
|
|
27
|
+
ctx.out.data(ent.as_dict())
|
|
28
|
+
|
|
29
|
+
ctx.out.field("plan", ent.plan)
|
|
30
|
+
if ent.license:
|
|
31
|
+
lic = ent.license
|
|
32
|
+
ctx.out.field("licensed", f"{lic.email or lic.subject or 'unnamed'} · {lic.seats} seat(s)")
|
|
33
|
+
if lic.expires_at:
|
|
34
|
+
when = time.strftime("%Y-%m-%d", time.gmtime(lic.expires_at))
|
|
35
|
+
ctx.out.field("expires", f"{when} ({lic.days_left} days)")
|
|
36
|
+
if ent.problem:
|
|
37
|
+
ctx.out.warn(f"a licence was found and not accepted: {ent.problem}")
|
|
38
|
+
ctx.out.field("source", str(ent.source))
|
|
39
|
+
ctx.out.line("")
|
|
40
|
+
|
|
41
|
+
ctx.out.line(ctx.out.c("entitlements", "muted"))
|
|
42
|
+
for feature, description in sorted(tier.FEATURE_NAMES.items()):
|
|
43
|
+
allowed = ent.allows(feature)
|
|
44
|
+
if ctx.out.fancy:
|
|
45
|
+
# At a terminal, the site's state device: enforced, or not covered.
|
|
46
|
+
mark = ctx.out.c(MARKS["pass"], "signal") if allowed else ctx.out.c(MARKS["uncovered"], "faint")
|
|
47
|
+
else:
|
|
48
|
+
mark = "[yes]" if allowed else "[no ]"
|
|
49
|
+
ctx.out.line(f" {mark} {feature:<19} {ctx.out.c(description, 'dim')}")
|
|
50
|
+
ctx.out.line("")
|
|
51
|
+
ctx.out.field("registry", 'unlimited' if ent.mcp_cap is None else f'{ent.mcp_cap} server')
|
|
52
|
+
if not ent.paid:
|
|
53
|
+
ctx.out.line("")
|
|
54
|
+
ctx.out.line("public edition — every command, uncapped, no account")
|
|
55
|
+
ctx.out.line(f"team edition edify license activate <token> · ask for one: {CONTACT}")
|
|
56
|
+
return 0
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def activate(ctx: Context) -> int:
|
|
60
|
+
token = ctx.args.token.strip()
|
|
61
|
+
if Path(token).expanduser().is_file():
|
|
62
|
+
token = Path(token).expanduser().read_text(encoding="utf-8").strip()
|
|
63
|
+
|
|
64
|
+
verdict = parse(token)
|
|
65
|
+
if not verdict.valid or verdict.license is None:
|
|
66
|
+
raise EdifyError(f"not activated — {verdict.reason}")
|
|
67
|
+
|
|
68
|
+
path = tier.save(token)
|
|
69
|
+
lic = verdict.license
|
|
70
|
+
ctx.out.data({"path": str(path), "license": lic.as_dict()})
|
|
71
|
+
ctx.out.ok(f"{lic.plan} plan activated for {lic.email or lic.subject or 'this machine'}")
|
|
72
|
+
ctx.out.line(str(path))
|
|
73
|
+
return 0
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def deactivate(ctx: Context) -> int:
|
|
77
|
+
removed = tier.clear()
|
|
78
|
+
ctx.out.data({"removed": removed})
|
|
79
|
+
ctx.out.line("licence removed" if removed else "no licence file to remove")
|
|
80
|
+
return 0
|