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/paths.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"""Where everything lives, and how the repository root is found.
|
|
2
|
+
|
|
3
|
+
The installed tree is nine paths, and they are a contract with every repository.
|
|
4
|
+
This module is the only place those names are written down.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from .errors import NotInstalled
|
|
15
|
+
|
|
16
|
+
# Markers that identify a repository root, in the order they are trusted.
|
|
17
|
+
ROOT_MARKERS = (
|
|
18
|
+
".edify",
|
|
19
|
+
".git",
|
|
20
|
+
"pyproject.toml",
|
|
21
|
+
"package.json",
|
|
22
|
+
"go.mod",
|
|
23
|
+
"Cargo.toml",
|
|
24
|
+
"pom.xml",
|
|
25
|
+
"build.gradle",
|
|
26
|
+
"build.gradle.kts",
|
|
27
|
+
"composer.json",
|
|
28
|
+
"Gemfile",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def find_root(start: str | os.PathLike[str] | None = None) -> Path:
|
|
33
|
+
"""Walk up from `start` to the nearest repository root.
|
|
34
|
+
|
|
35
|
+
`.edify` and `.git` win outright. A manifest file only counts if nothing
|
|
36
|
+
above it is a stronger marker, which keeps a monorepo package from being
|
|
37
|
+
mistaken for the repository.
|
|
38
|
+
"""
|
|
39
|
+
here = Path(start or os.environ.get("EDIFY_REPO") or Path.cwd()).resolve()
|
|
40
|
+
if here.is_file():
|
|
41
|
+
here = here.parent
|
|
42
|
+
strong: Path | None = None
|
|
43
|
+
weak: Path | None = None
|
|
44
|
+
for candidate in [here, *here.parents]:
|
|
45
|
+
if (candidate / ".edify").is_dir() or (candidate / ".git").exists():
|
|
46
|
+
strong = candidate
|
|
47
|
+
break
|
|
48
|
+
if weak is None:
|
|
49
|
+
for marker in ROOT_MARKERS[2:]:
|
|
50
|
+
if (candidate / marker).exists():
|
|
51
|
+
weak = candidate
|
|
52
|
+
break
|
|
53
|
+
return strong or weak or here
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class Layout:
|
|
58
|
+
"""The installed tree, resolved against one repository root."""
|
|
59
|
+
|
|
60
|
+
root: Path
|
|
61
|
+
|
|
62
|
+
# -- .edify ----------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def edify(self) -> Path:
|
|
66
|
+
return self.root / ".edify"
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def graph_dir(self) -> Path:
|
|
70
|
+
return self.edify / "graph"
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def nodes(self) -> Path:
|
|
74
|
+
return self.graph_dir / "nodes.tsv"
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def edges(self) -> Path:
|
|
78
|
+
return self.graph_dir / "edges.tsv"
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def meta(self) -> Path:
|
|
82
|
+
return self.graph_dir / "meta"
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def skills_dir(self) -> Path:
|
|
86
|
+
return self.edify / "skills"
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def skills_index(self) -> Path:
|
|
90
|
+
return self.skills_dir / "index.tsv"
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def commands_dir(self) -> Path:
|
|
94
|
+
return self.edify / "commands"
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def formats_dir(self) -> Path:
|
|
98
|
+
return self.edify / "formats"
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def mcp(self) -> Path:
|
|
102
|
+
return self.edify / "mcp.md"
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def conventions(self) -> Path:
|
|
106
|
+
return self.edify / "conventions.md"
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def stack(self) -> Path:
|
|
110
|
+
return self.edify / "stack.tsv"
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def profile(self) -> Path:
|
|
114
|
+
"""What the person said when `edify init new` asked. Theirs to edit, and the
|
|
115
|
+
one file here that was not derived from something already on disk."""
|
|
116
|
+
return self.edify / "profile.md"
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def governance(self) -> Path:
|
|
120
|
+
"""The ledger: every file EDIFY put in this repository, and where it came from."""
|
|
121
|
+
return self.edify / "governance.tsv"
|
|
122
|
+
|
|
123
|
+
# -- the host runtime's own tree --------------------------------------
|
|
124
|
+
# `.edify/` is canonical and `.claude/` is the mirror, so these names are here
|
|
125
|
+
# rather than spelled inline wherever something writes one. Three families,
|
|
126
|
+
# because Claude Code discovers three things in three different shapes and an
|
|
127
|
+
# entry filed under the wrong one is installed and undiscoverable.
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def host_dir(self) -> Path:
|
|
131
|
+
return self.root / ".claude"
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def host_commands(self) -> Path:
|
|
135
|
+
"""`/spec` and friends — one flat file per command."""
|
|
136
|
+
return self.host_dir / "commands"
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def host_skills(self) -> Path:
|
|
140
|
+
"""One directory per skill, each holding a `SKILL.md`."""
|
|
141
|
+
return self.host_dir / "skills"
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def host_agents(self) -> Path:
|
|
145
|
+
"""One flat file per subagent. A `kind: agent` entry belongs here and not
|
|
146
|
+
under `host_skills` — the runtime spawns from this directory and matches
|
|
147
|
+
skills from that one, so the choice decides whether the entry can be a
|
|
148
|
+
spawn at all."""
|
|
149
|
+
return self.host_dir / "agents"
|
|
150
|
+
|
|
151
|
+
# Every family as (directory, glob), for everything that has to walk all of them:
|
|
152
|
+
# the governance scan, the clearing `setup --fresh` and `init new` do, and the
|
|
153
|
+
# staleness check. Every runtime in the table, not only the one this run chose —
|
|
154
|
+
# a folder set up for Cursor last month still has Cursor's pointers in it, and
|
|
155
|
+
# they are EDIFY's to account for whether or not Cursor was named today.
|
|
156
|
+
def host_trees(self) -> tuple[tuple[Path, str], ...]:
|
|
157
|
+
from .agents import all_trees
|
|
158
|
+
|
|
159
|
+
return tuple((self.root / directory, pattern) for directory, pattern in all_trees())
|
|
160
|
+
|
|
161
|
+
def instruction_files(self) -> tuple[Path, ...]:
|
|
162
|
+
"""`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, and the rest — every file a runtime
|
|
163
|
+
reads at the start of a session and EDIFY owns one block inside."""
|
|
164
|
+
from .agents import all_instruction_paths
|
|
165
|
+
|
|
166
|
+
return tuple(self.root / path for path in all_instruction_paths())
|
|
167
|
+
|
|
168
|
+
# -- harvest ---------------------------------------------------------
|
|
169
|
+
# EDIFY's own repository only (`10-harvest.md` §3). Everything under here is
|
|
170
|
+
# untrusted text until a person has read it, and untrusted text does not belong
|
|
171
|
+
# in a customer's tree at any stage of processing — which is why `edify init`
|
|
172
|
+
# copies commands, formats, skills, and mcp, and never this.
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def harvest(self) -> Path:
|
|
176
|
+
return self.root / "harvest"
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def harvest_ledger(self) -> Path:
|
|
180
|
+
return self.harvest / "ledger.json"
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def harvest_staging(self) -> Path:
|
|
184
|
+
return self.harvest / "staging"
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def harvest_quarantine(self) -> Path:
|
|
188
|
+
return self.harvest / "quarantine"
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def harvest_proposals(self) -> Path:
|
|
192
|
+
return self.harvest / "proposals"
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def library(self) -> Path:
|
|
196
|
+
"""The authored library an admitted entry lands in — the source tree, not an install."""
|
|
197
|
+
return self.root / "edify" / "skills"
|
|
198
|
+
|
|
199
|
+
@property
|
|
200
|
+
def harvest_refs(self) -> Path:
|
|
201
|
+
"""`sources.md` and `vocab.md`, which are authored files rather than run state."""
|
|
202
|
+
return self.root / "edify" / "harvest"
|
|
203
|
+
|
|
204
|
+
def is_edify_repo(self) -> bool:
|
|
205
|
+
"""Whether this is the repository harvest is allowed to run in.
|
|
206
|
+
|
|
207
|
+
The marker is the authored methodology tree itself. A client repository has
|
|
208
|
+
`.edify/` and no `edify/harvest/`, so the boundary is checkable rather than
|
|
209
|
+
merely documented.
|
|
210
|
+
"""
|
|
211
|
+
return (self.harvest_refs / "sources.md").is_file()
|
|
212
|
+
|
|
213
|
+
# -- the rest of the tree --------------------------------------------
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def specs(self) -> Path:
|
|
217
|
+
return self.root / "specs"
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def claude_md(self) -> Path:
|
|
221
|
+
return self.root / "CLAUDE.md"
|
|
222
|
+
|
|
223
|
+
def feature(self, name: str) -> Path:
|
|
224
|
+
return self.specs / name
|
|
225
|
+
|
|
226
|
+
# -- checks ----------------------------------------------------------
|
|
227
|
+
|
|
228
|
+
def installed(self) -> bool:
|
|
229
|
+
return self.edify.is_dir()
|
|
230
|
+
|
|
231
|
+
def require_installed(self) -> None:
|
|
232
|
+
if not self.installed():
|
|
233
|
+
raise NotInstalled(str(self.root))
|
|
234
|
+
|
|
235
|
+
def rel(self, path: str | os.PathLike[str]) -> str:
|
|
236
|
+
"""A repository-relative POSIX path. Every path we write is in this form."""
|
|
237
|
+
p = Path(path)
|
|
238
|
+
try:
|
|
239
|
+
p = p.resolve().relative_to(self.root)
|
|
240
|
+
except ValueError:
|
|
241
|
+
return Path(path).as_posix()
|
|
242
|
+
return p.as_posix()
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def layout(start: str | os.PathLike[str] | None = None) -> Layout:
|
|
246
|
+
return Layout(find_root(start))
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def user_config_dir(os_name: str | None = None, platform: str | None = None) -> Path:
|
|
250
|
+
"""Where a licence and machine-local state live. Never inside a repository.
|
|
251
|
+
|
|
252
|
+
One directory per platform, each the one that platform's users expect:
|
|
253
|
+
|
|
254
|
+
macOS ~/Library/Application Support/edify
|
|
255
|
+
Windows %APPDATA%\\edify
|
|
256
|
+
elsewhere $XDG_CONFIG_HOME/edify, or ~/.config/edify
|
|
257
|
+
|
|
258
|
+
`EDIFY_HOME` overrides all of it, and an existing `~/.config/edify` wins on
|
|
259
|
+
macOS — a machine that already has a licence there keeps it rather than
|
|
260
|
+
silently losing it to a directory this version happens to prefer.
|
|
261
|
+
|
|
262
|
+
The platform is a parameter so the other two can be tested from any one of
|
|
263
|
+
them. Patching `os.name` to find out would change what `pathlib` builds.
|
|
264
|
+
"""
|
|
265
|
+
os_name = os_name or os.name
|
|
266
|
+
platform = platform or sys.platform
|
|
267
|
+
|
|
268
|
+
override = os.environ.get("EDIFY_HOME")
|
|
269
|
+
if override:
|
|
270
|
+
return Path(override).expanduser()
|
|
271
|
+
if os_name == "nt":
|
|
272
|
+
base = os.environ.get("APPDATA") or str(Path.home() / "AppData" / "Roaming")
|
|
273
|
+
return Path(base) / "edify"
|
|
274
|
+
xdg = os.environ.get("XDG_CONFIG_HOME")
|
|
275
|
+
if xdg:
|
|
276
|
+
return Path(xdg) / "edify"
|
|
277
|
+
if platform == "darwin":
|
|
278
|
+
legacy = Path.home() / ".config" / "edify"
|
|
279
|
+
if legacy.is_dir():
|
|
280
|
+
return legacy
|
|
281
|
+
return Path.home() / "Library" / "Application Support" / "edify"
|
|
282
|
+
return Path.home() / ".config" / "edify"
|
edify/selfinstall.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"""Where this `edify` came from, and how to put a newer one in its place.
|
|
2
|
+
|
|
3
|
+
`edify upgrade` is already taken and means something else entirely — it pulls a
|
|
4
|
+
newer *skill library*. This module is about the binary itself: which tool put
|
|
5
|
+
`edify` on PATH, which checkout the running code was imported from, and the exact
|
|
6
|
+
argv that would reinstall one from the other.
|
|
7
|
+
|
|
8
|
+
Everything here is a pure function. Nothing runs a subprocess, writes a file, or
|
|
9
|
+
prints — `commands/self_cmd.py` does all of that. That is what makes the part
|
|
10
|
+
worth getting right unit-testable without ever installing anything.
|
|
11
|
+
|
|
12
|
+
**The manager is detected, not assumed** (plan D-1, D-2). The binary was put on
|
|
13
|
+
PATH by uv, pipx, or pip, and only that tool can correctly replace it. A hardcoded
|
|
14
|
+
`pip install` into a uv tool environment produces a second, shadowed copy — the
|
|
15
|
+
worst possible outcome for a command named "update". `uv/tools/edify-agents-cli` and
|
|
16
|
+
`pipx/venvs/edify-agents-cli` are structural path segments rather than conventions, so
|
|
17
|
+
`sys.prefix` is enough to tell them apart, and `--manager` overrides when it is
|
|
18
|
+
not, which makes a mis-detection cost one flag rather than a broken install.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
#: The distribution name in `pyproject.toml`. A directory is a usable source
|
|
28
|
+
#: checkout only if its manifest names this — otherwise `--from .` typed in the
|
|
29
|
+
#: wrong folder would cheerfully install something else over `edify`.
|
|
30
|
+
from .distribution import DIST_NAME
|
|
31
|
+
from .errors import EdifyError
|
|
32
|
+
|
|
33
|
+
MANAGERS = ("uv", "pipx", "pip")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def is_source_checkout(path: Path | str) -> bool:
|
|
37
|
+
"""Does this directory hold a `pyproject.toml` naming `edify-agents-cli`?"""
|
|
38
|
+
manifest = Path(path) / "pyproject.toml"
|
|
39
|
+
try:
|
|
40
|
+
text = manifest.read_text(encoding="utf-8", errors="replace")
|
|
41
|
+
except (OSError, ValueError):
|
|
42
|
+
return False
|
|
43
|
+
# A dependency-free parse: `name = "edify-agents-cli"` on its own line. `tomllib`
|
|
44
|
+
# would do this on 3.11+ and not on 3.10, which this package supports.
|
|
45
|
+
for line in text.splitlines():
|
|
46
|
+
stripped = line.strip().replace(" ", "")
|
|
47
|
+
if stripped == 'name="' + DIST_NAME + '"':
|
|
48
|
+
return True
|
|
49
|
+
if stripped == "name='" + DIST_NAME + "'":
|
|
50
|
+
return True
|
|
51
|
+
return False
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def running_source() -> Path | None:
|
|
55
|
+
"""The checkout the running `edify` was imported from, when there is one.
|
|
56
|
+
|
|
57
|
+
Walks up from the package directory looking for a manifest that names
|
|
58
|
+
`edify-agents-cli`. On an editable install this resolves directly to the repository;
|
|
59
|
+
on a wheel install there is no such manifest above `site-packages`, so it
|
|
60
|
+
returns None and `resolve_source` falls back to the repository root.
|
|
61
|
+
"""
|
|
62
|
+
from . import __file__ as package_file
|
|
63
|
+
|
|
64
|
+
for parent in Path(package_file).resolve().parents:
|
|
65
|
+
if is_source_checkout(parent):
|
|
66
|
+
return parent
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def resolve_source(explicit: str | None = None, repo_root: Path | str | None = None) -> Path:
|
|
71
|
+
"""Which checkout to install from: `--from`, else the running one, else the repo.
|
|
72
|
+
|
|
73
|
+
Raises rather than guessing. Installing from a directory that is not an
|
|
74
|
+
`edify-agents-cli` checkout is not an update, and finding that out afterwards costs
|
|
75
|
+
the person the working binary they started with.
|
|
76
|
+
"""
|
|
77
|
+
if explicit:
|
|
78
|
+
path = Path(explicit).expanduser().resolve()
|
|
79
|
+
if not path.is_dir():
|
|
80
|
+
raise EdifyError(
|
|
81
|
+
str(path) + " is not a directory",
|
|
82
|
+
hint="--from takes a path to an edify checkout",
|
|
83
|
+
)
|
|
84
|
+
if not is_source_checkout(path):
|
|
85
|
+
raise EdifyError(
|
|
86
|
+
str(path) + " is not an edify checkout",
|
|
87
|
+
hint="its pyproject.toml does not name `" + DIST_NAME + "`",
|
|
88
|
+
)
|
|
89
|
+
return path
|
|
90
|
+
|
|
91
|
+
source = running_source()
|
|
92
|
+
if source is not None:
|
|
93
|
+
return source
|
|
94
|
+
|
|
95
|
+
if repo_root is not None and is_source_checkout(repo_root):
|
|
96
|
+
return Path(repo_root).resolve()
|
|
97
|
+
|
|
98
|
+
raise EdifyError(
|
|
99
|
+
"no edify source checkout to install from",
|
|
100
|
+
hint="run this inside a clone of the repository, or pass `--from PATH`",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def detect_manager(prefix: Path | str | None = None) -> str:
|
|
105
|
+
"""Which tool installed this binary, read from `sys.prefix`'s path segments.
|
|
106
|
+
|
|
107
|
+
uv keeps tool environments under `uv/tools/<dist>` and pipx under
|
|
108
|
+
`pipx/venvs/<dist>`; both are structural rather than conventional. Anything
|
|
109
|
+
else — a plain venv, a system Python, a `pip install -e .` — is `pip`, which
|
|
110
|
+
is also the right default: pip installs into the environment it is run from,
|
|
111
|
+
so a wrong guess there is a no-op rather than a shadowed second copy.
|
|
112
|
+
"""
|
|
113
|
+
# Split on both separators: `Path` on POSIX keeps `C:\Users\...` as one part.
|
|
114
|
+
raw = str(prefix if prefix is not None else sys.prefix)
|
|
115
|
+
parts = [p.lower() for p in re.split(r"[\\/]+", raw) if p]
|
|
116
|
+
for i, part in enumerate(parts):
|
|
117
|
+
nxt = parts[i + 1] if i + 1 < len(parts) else ""
|
|
118
|
+
if part == "uv" and nxt == "tools":
|
|
119
|
+
return "uv"
|
|
120
|
+
if part == "pipx" and nxt in ("venvs", "venv"):
|
|
121
|
+
return "pipx"
|
|
122
|
+
if "uv" in parts:
|
|
123
|
+
return "uv"
|
|
124
|
+
if "pipx" in parts:
|
|
125
|
+
return "pipx"
|
|
126
|
+
return "pip"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def install_command(
|
|
130
|
+
manager: str,
|
|
131
|
+
source: Path | str,
|
|
132
|
+
editable: bool = False,
|
|
133
|
+
offline: bool = False,
|
|
134
|
+
) -> list[str]:
|
|
135
|
+
"""The exact argv that reinstalls `edify` from `source` using `manager`.
|
|
136
|
+
|
|
137
|
+
Returned rather than run, so `--dry-run` prints the same list the real run
|
|
138
|
+
executes. There is no second code path for the two, which is the only way
|
|
139
|
+
`--dry-run` can be trusted to describe what will happen.
|
|
140
|
+
"""
|
|
141
|
+
if manager not in MANAGERS:
|
|
142
|
+
raise EdifyError(
|
|
143
|
+
"unknown installer `" + str(manager) + "`",
|
|
144
|
+
hint="--manager takes one of: " + ", ".join(MANAGERS),
|
|
145
|
+
)
|
|
146
|
+
src = str(source)
|
|
147
|
+
|
|
148
|
+
if manager == "uv":
|
|
149
|
+
argv = ["uv", "tool", "install", "--force", "--reinstall"]
|
|
150
|
+
if editable:
|
|
151
|
+
argv.append("--editable")
|
|
152
|
+
if offline:
|
|
153
|
+
argv.append("--offline")
|
|
154
|
+
argv.append(src)
|
|
155
|
+
return argv
|
|
156
|
+
|
|
157
|
+
if manager == "pipx":
|
|
158
|
+
argv = ["pipx", "install", "--force"]
|
|
159
|
+
if editable:
|
|
160
|
+
argv.append("--editable")
|
|
161
|
+
# pipx has no --offline of its own; it forwards pip options verbatim.
|
|
162
|
+
if offline:
|
|
163
|
+
argv += ["--pip-args", "--no-index"]
|
|
164
|
+
argv.append(src)
|
|
165
|
+
return argv
|
|
166
|
+
|
|
167
|
+
argv = [sys.executable, "-m", "pip", "install", "--force-reinstall"]
|
|
168
|
+
if editable:
|
|
169
|
+
argv.append("--editable")
|
|
170
|
+
if offline:
|
|
171
|
+
argv.append("--no-index")
|
|
172
|
+
argv.append(src)
|
|
173
|
+
return argv
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def binary_path() -> str:
|
|
177
|
+
"""The `edify` that is running, as the shell resolved it.
|
|
178
|
+
|
|
179
|
+
`sys.argv[0]` is what was invoked; on a console-script install that is the
|
|
180
|
+
launcher on PATH, which is what a person means by "which edify is this".
|
|
181
|
+
"""
|
|
182
|
+
argv0 = sys.argv[0] if sys.argv else ""
|
|
183
|
+
if not argv0:
|
|
184
|
+
return ""
|
|
185
|
+
try:
|
|
186
|
+
return str(Path(argv0).resolve())
|
|
187
|
+
except OSError:
|
|
188
|
+
return argv0
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def package_dir() -> Path:
|
|
192
|
+
from . import __file__ as package_file
|
|
193
|
+
|
|
194
|
+
return Path(package_file).resolve().parent
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def describe() -> dict[str, str]:
|
|
198
|
+
"""Everything `edify self where` prints, as data. No side effects at all."""
|
|
199
|
+
from . import __version__
|
|
200
|
+
|
|
201
|
+
source = running_source()
|
|
202
|
+
return {
|
|
203
|
+
"version": __version__,
|
|
204
|
+
"executable": binary_path(),
|
|
205
|
+
"interpreter": sys.executable,
|
|
206
|
+
"prefix": sys.prefix,
|
|
207
|
+
"package": str(package_dir()),
|
|
208
|
+
"manager": detect_manager(),
|
|
209
|
+
"source": str(source) if source is not None else "",
|
|
210
|
+
"editable": "yes" if source is not None else "no",
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
#: What an installer says when the running `edify.exe` is held open by this very
|
|
215
|
+
#: process. Windows cannot replace a running executable, so the failure has to be
|
|
216
|
+
#: recognised and reported with the command to run from another shell — never
|
|
217
|
+
#: swallowed, and never reported as the success it was not.
|
|
218
|
+
LOCKED_MARKERS = (
|
|
219
|
+
"access is denied",
|
|
220
|
+
"permission denied",
|
|
221
|
+
"being used by another process",
|
|
222
|
+
"used by another process",
|
|
223
|
+
"text file busy",
|
|
224
|
+
"winerror 5",
|
|
225
|
+
"winerror 32",
|
|
226
|
+
"failed to remove file",
|
|
227
|
+
"failed to persist",
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def looks_locked(text: str) -> bool:
|
|
232
|
+
"""Did this installer failure come from the running binary being held open?"""
|
|
233
|
+
low = (text or "").lower()
|
|
234
|
+
return any(marker in low for marker in LOCKED_MARKERS)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def unlock_hint(manager: str, source: Path | str, editable: bool = False) -> str:
|
|
238
|
+
"""The exact one-liner to run from another shell when the binary is locked."""
|
|
239
|
+
argv = install_command(manager, source, editable=editable)
|
|
240
|
+
return "close this shell, then run: " + " ".join(_quote(a) for a in argv)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _quote(arg: str) -> str:
|
|
244
|
+
return '"' + arg + '"' if " " in arg else arg
|
edify/skills.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""The skill index and the resolution lookup.
|
|
2
|
+
|
|
3
|
+
`resolve` is what `/build` performs before every spawn: a lookup over a sorted TSV
|
|
4
|
+
keyed on `role · phase · tech`, one line of output, no model involved. Not because
|
|
5
|
+
a model's judgment is bad — because a lookup is free, deterministic, and gives the
|
|
6
|
+
same answer on Tuesday.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from .errors import EdifyError
|
|
15
|
+
from .formats import skill as skill_format
|
|
16
|
+
from .paths import Layout
|
|
17
|
+
from .tsv import read_rows, write_rows
|
|
18
|
+
|
|
19
|
+
INDEX_HEADER = ("role", "phase", "tech", "name", "path")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Entry:
|
|
24
|
+
role: str
|
|
25
|
+
phase: str
|
|
26
|
+
tech: str
|
|
27
|
+
name: str
|
|
28
|
+
path: str
|
|
29
|
+
|
|
30
|
+
def row(self) -> list[str]:
|
|
31
|
+
return [self.role, self.phase, self.tech, self.name, self.path]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def build_index(layout: Layout) -> tuple[int, list[str]]:
|
|
35
|
+
"""Walk `.edify/skills/`, validate, and write the sorted lookup table.
|
|
36
|
+
|
|
37
|
+
An invalid file is skipped rather than indexed, and its name is returned so
|
|
38
|
+
the caller can say so. Loose metadata is fine for a wiki and useless here.
|
|
39
|
+
"""
|
|
40
|
+
skipped: list[str] = []
|
|
41
|
+
rows: list[list[str]] = []
|
|
42
|
+
for skill in skill_format.load_all(layout.skills_dir, layout.root):
|
|
43
|
+
problems = skill_format.validate(skill)
|
|
44
|
+
blocking = [p for p in problems if p[0] != "skill-over-budget"]
|
|
45
|
+
if blocking:
|
|
46
|
+
skipped.append(f"{skill.rel}: {blocking[0][1]}")
|
|
47
|
+
continue
|
|
48
|
+
rows.extend(skill.index_rows())
|
|
49
|
+
write_rows(layout.skills_index, rows, INDEX_HEADER)
|
|
50
|
+
return len(rows), skipped
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def load_index(layout: Layout) -> list[Entry]:
|
|
54
|
+
if not layout.skills_index.is_file():
|
|
55
|
+
raise EdifyError(
|
|
56
|
+
"no skill index",
|
|
57
|
+
hint="run `edify skills index`",
|
|
58
|
+
)
|
|
59
|
+
return [Entry(*row[:5]) for row in read_rows(layout.skills_index) if len(row) >= 5]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def resolve(layout: Layout, role: str, phase: str, tech: str | None = None) -> Entry:
|
|
63
|
+
"""Exact tech match, then `any`, then the role's default.
|
|
64
|
+
|
|
65
|
+
If none of the three resolve, the task fails at the gate rather than at build
|
|
66
|
+
time — a task whose role has no skill is a plan defect, and the cheap moment
|
|
67
|
+
to find it is before anything runs.
|
|
68
|
+
"""
|
|
69
|
+
entries = load_index(layout)
|
|
70
|
+
by_role = [e for e in entries if e.role == role]
|
|
71
|
+
if not by_role:
|
|
72
|
+
raise EdifyError(
|
|
73
|
+
f"no skill for role `{role}`",
|
|
74
|
+
hint="`edify skills list` shows what is installed; a role with no skill is a plan defect",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
in_phase = [e for e in by_role if e.phase == str(phase)] or by_role
|
|
78
|
+
|
|
79
|
+
if tech:
|
|
80
|
+
wanted = {t.strip().lower() for t in tech.replace(",", " ").split() if t.strip()}
|
|
81
|
+
exact = [e for e in in_phase if e.tech.lower() in wanted]
|
|
82
|
+
if exact:
|
|
83
|
+
return sorted(exact, key=lambda e: (e.tech, e.name))[0]
|
|
84
|
+
|
|
85
|
+
generic = [e for e in in_phase if e.tech.lower() == "any"]
|
|
86
|
+
if generic:
|
|
87
|
+
return sorted(generic, key=lambda e: e.name)[0]
|
|
88
|
+
|
|
89
|
+
return sorted(in_phase, key=lambda e: (e.tech, e.name))[0]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def select_for_stack(source_dir: Path, tech: list[str]) -> list[Path]:
|
|
93
|
+
"""Which library entries this repository's stack matches.
|
|
94
|
+
|
|
95
|
+
A Python API repository does not receive the React implementer. Every unused
|
|
96
|
+
skill file is context cost and, for anything sourced from outside, attack
|
|
97
|
+
surface.
|
|
98
|
+
"""
|
|
99
|
+
wanted = {t.lower() for t in tech}
|
|
100
|
+
chosen: list[Path] = []
|
|
101
|
+
for path in sorted(source_dir.glob("*.md")):
|
|
102
|
+
skill = skill_format.parse(path, path.name)
|
|
103
|
+
if not skill.role:
|
|
104
|
+
continue
|
|
105
|
+
techs = {t.lower() for t in skill.tech}
|
|
106
|
+
if "any" in techs or techs & wanted:
|
|
107
|
+
chosen.append(path)
|
|
108
|
+
return chosen
|