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/host.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"""The host runtimes' view of what is installed.
|
|
2
|
+
|
|
3
|
+
`.edify/` is the canonical tree and the only one EDIFY reasons about. A host runtime
|
|
4
|
+
discovers its own capabilities somewhere else, in shapes that differ per runtime and,
|
|
5
|
+
for Claude Code, in three shapes at once: commands at `.claude/commands/<name>.md`,
|
|
6
|
+
skills at `.claude/skills/<name>/SKILL.md` one directory each, and subagents at
|
|
7
|
+
`.claude/agents/<name>.md`. A library entry that exists only under `.edify/skills/`
|
|
8
|
+
is installed as far as `edify skills list` is concerned and invisible to the runtime
|
|
9
|
+
the person is actually typing into.
|
|
10
|
+
|
|
11
|
+
Which runtimes those are is `agents.py`, and this module takes the table as given:
|
|
12
|
+
one row means one set of directories to write into, and adding Cursor or Gemini to the
|
|
13
|
+
install is adding a row rather than a branch here.
|
|
14
|
+
|
|
15
|
+
Which of the three an entry gets is `kind`, and it is not cosmetic. The runtime
|
|
16
|
+
*matches* a skill against what the session is doing and *spawns* an agent by name, so
|
|
17
|
+
a `kind: agent` entry mirrored into `.claude/skills/` is loadable and unspawnable —
|
|
18
|
+
`/build` resolves it, asks for a subagent by that name, and gets nothing. That was
|
|
19
|
+
the state until this module learned the difference: `kind` had two legal values in
|
|
20
|
+
the skill format and one destination on disk.
|
|
21
|
+
|
|
22
|
+
So this module writes the mirror, and the mirror is **pointers**. Each generated file
|
|
23
|
+
carries the two fields the host discovers on (`name`, `description`) and then names
|
|
24
|
+
the canonical path; the method itself stays in exactly one place. A copy would go
|
|
25
|
+
stale the first time a skill file changed and nothing would say so.
|
|
26
|
+
|
|
27
|
+
Everything written here is `origin: generated` in `.edify/governance.tsv`, so
|
|
28
|
+
`edify governance verify` reports a hand-edit to a pointer as what it is: an edit to
|
|
29
|
+
a file EDIFY will overwrite.
|
|
30
|
+
|
|
31
|
+
One file is deliberately not touched: a `SKILL.md` that EDIFY did not generate. The
|
|
32
|
+
harvest skill in EDIFY's own repository is hand-authored at
|
|
33
|
+
`.claude/skills/harvest/SKILL.md` and is not a mirror of anything — overwriting it
|
|
34
|
+
with a pointer to a file that does not exist is the kind of helpfulness nobody asks
|
|
35
|
+
for twice.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
from dataclasses import dataclass
|
|
41
|
+
from pathlib import Path
|
|
42
|
+
|
|
43
|
+
from . import agents as agent_table
|
|
44
|
+
from . import assets
|
|
45
|
+
from .agents import Target
|
|
46
|
+
from .formats import skill as skill_format
|
|
47
|
+
from .paths import Layout
|
|
48
|
+
|
|
49
|
+
# The line every generated file carries, so `written_by_edify` is a read rather than
|
|
50
|
+
# a guess and a person opening one knows what it is in the first two seconds.
|
|
51
|
+
MARKER = agent_table.MARKER_MD
|
|
52
|
+
MARKER_TOML = agent_table.MARKER_TOML
|
|
53
|
+
|
|
54
|
+
# The shape the command pointers had before there was a marker. A repository that ran
|
|
55
|
+
# an earlier `init` has six of them, and without this they would all be treated as
|
|
56
|
+
# somebody's own files and never brought up to date.
|
|
57
|
+
LEGACY_MARKERS = agent_table.LEGACY_MARKERS
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass
|
|
61
|
+
class Written:
|
|
62
|
+
path: Path
|
|
63
|
+
kind: str # command | skill | agent
|
|
64
|
+
name: str
|
|
65
|
+
action: str # written | kept | skipped
|
|
66
|
+
target: str = "claude" # which runtime this pointer is for
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def sync(layout: Layout, *, host: str = "claude", agents: str = "") -> list[Written]:
|
|
70
|
+
"""Mirror the installed commands and skills into every chosen runtime's directories.
|
|
71
|
+
|
|
72
|
+
There is no `force`, and that is the point. A pointer is derived output: if it
|
|
73
|
+
differs from what it should say it is brought up to date, because a pointer at a
|
|
74
|
+
file that has been renamed is worse than no pointer at all. And a file that is not
|
|
75
|
+
one of ours is never written, with or without a flag — `init --force` means
|
|
76
|
+
"replace what EDIFY installed", never "replace what you wrote".
|
|
77
|
+
|
|
78
|
+
`agents` names the runtimes; unset, it means whichever ones are already set up in
|
|
79
|
+
this folder, falling back to `host` when none are.
|
|
80
|
+
"""
|
|
81
|
+
out: list[Written] = []
|
|
82
|
+
for target in agent_table.resolve(agents, host, root=layout.root):
|
|
83
|
+
out += sync_target(layout, target)
|
|
84
|
+
return out
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sync_target(layout: Layout, target: Target) -> list[Written]:
|
|
88
|
+
"""One runtime's whole mirror: its commands, and its skills where it has them."""
|
|
89
|
+
return _sync_commands(layout, target) + _sync_library(layout, target)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _sync_commands(layout: Layout, target: Target) -> list[Written]:
|
|
93
|
+
"""Thin pointers so `/spec` resolves in the runtime.
|
|
94
|
+
|
|
95
|
+
Written from the shipped set rather than from `.edify/commands/`, so a repository
|
|
96
|
+
that has not run `init` yet still gets the full five.
|
|
97
|
+
"""
|
|
98
|
+
if not target.commands:
|
|
99
|
+
return []
|
|
100
|
+
target_dir = layout.root / target.commands
|
|
101
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
102
|
+
out: list[Written] = []
|
|
103
|
+
for source in sorted(assets.subtree("commands").glob("*.md")):
|
|
104
|
+
name = source.stem
|
|
105
|
+
pointer = target_dir / f"{name}{target.command_suffix}"
|
|
106
|
+
body = _command_pointer(name, target)
|
|
107
|
+
out.append(_write(pointer, body, "command", name, target.id))
|
|
108
|
+
return out
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _command_pointer(name: str, target: Target) -> str:
|
|
112
|
+
"""The same two sentences, in whichever file format this runtime parses.
|
|
113
|
+
|
|
114
|
+
The body never varies: read the contract, follow it. Only the wrapper does, and a
|
|
115
|
+
runtime that reads TOML gets a `#` marker rather than an HTML comment because an
|
|
116
|
+
HTML comment in a TOML file is a parse error, not a nicety.
|
|
117
|
+
"""
|
|
118
|
+
instruction = (
|
|
119
|
+
f"Read `.edify/commands/{name}.md` and follow it for this repository.\n"
|
|
120
|
+
f"That file is the contract; this one only points at it."
|
|
121
|
+
)
|
|
122
|
+
if target.command_format == "toml":
|
|
123
|
+
return (
|
|
124
|
+
f"{MARKER_TOML}\n"
|
|
125
|
+
f'description = "EDIFY /{name}"\n'
|
|
126
|
+
f'prompt = """\n{instruction}\n"""\n'
|
|
127
|
+
)
|
|
128
|
+
return f"---\ndescription: EDIFY /{name}\n---\n\n{MARKER}\n\n{instruction}\n"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _sync_library(layout: Layout, target: Target) -> list[Written]:
|
|
132
|
+
"""Every installed entry, each into the directory its `kind` belongs in.
|
|
133
|
+
|
|
134
|
+
The description is copied rather than pointed at, in both shapes: it is what the
|
|
135
|
+
runtime matches on when it decides whether a skill is relevant and what it reads
|
|
136
|
+
when it decides which subagent to spawn, so a pointer whose description said "see
|
|
137
|
+
the other file" would never be chosen. The coordinates go in beside it because
|
|
138
|
+
`role · phase · tech` is what `/build` resolves on, and a person reading `.claude/`
|
|
139
|
+
should be able to see why this entry exists without opening two files.
|
|
140
|
+
|
|
141
|
+
A runtime with no skill directory of its own — most of them — gets nothing here,
|
|
142
|
+
and that is correct rather than a gap: its instruction file names `.edify/skills/`
|
|
143
|
+
and `edify skills resolve`, which is the whole library through one door.
|
|
144
|
+
"""
|
|
145
|
+
if not (target.skills or target.agents):
|
|
146
|
+
return []
|
|
147
|
+
entries = skill_format.load_all(layout.skills_dir, layout.root)
|
|
148
|
+
out: list[Written] = []
|
|
149
|
+
for entry in entries:
|
|
150
|
+
if not entry.name:
|
|
151
|
+
continue # an invalid file is not indexed, so it is not mirrored either
|
|
152
|
+
if entry.kind == "agent" and target.agents:
|
|
153
|
+
path = layout.root / target.agents / f"{entry.name}.md"
|
|
154
|
+
out.append(_write(path, _agent_pointer(entry), "agent", entry.name, target.id))
|
|
155
|
+
elif target.skills:
|
|
156
|
+
path = layout.root / target.skills / entry.name / target.skill_file
|
|
157
|
+
out.append(_write(path, _skill_pointer(entry), "skill", entry.name, target.id))
|
|
158
|
+
return out
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _coordinates(entry: skill_format.Skill) -> str:
|
|
162
|
+
return " · ".join([entry.role or "-", " ".join(entry.phases) or "-", " ".join(entry.tech) or "any"])
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _attribution(entry: skill_format.Skill) -> str:
|
|
166
|
+
"""Where this entry came from, on the face of the pointer.
|
|
167
|
+
|
|
168
|
+
An adapted entry carries somebody else's licence, and the person who has to
|
|
169
|
+
honour it is the one reading `.claude/`, not the one reading the source tree.
|
|
170
|
+
"""
|
|
171
|
+
line = f"- **provenance** {entry.provenance or '-'}"
|
|
172
|
+
if entry.license and entry.license != "-":
|
|
173
|
+
line += f" · **licence** {entry.license}"
|
|
174
|
+
return line
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _skill_pointer(entry: skill_format.Skill) -> str:
|
|
178
|
+
return (
|
|
179
|
+
f"---\nname: {entry.name}\ndescription: {entry.description}\n---\n\n"
|
|
180
|
+
f"{MARKER}\n\n"
|
|
181
|
+
f"# {entry.name}\n\n"
|
|
182
|
+
f"Read `{entry.rel}` and follow it. That file is the entry; this one only points at it.\n\n"
|
|
183
|
+
f"- **resolves at** `{_coordinates(entry)}` (role · phase · tech)\n"
|
|
184
|
+
f"{_attribution(entry)}\n\n"
|
|
185
|
+
f"`edify skills resolve {entry.role or '<role>'} <phase>` is what a build spawn runs to get here.\n"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _agent_pointer(entry: skill_format.Skill) -> str:
|
|
190
|
+
"""A subagent definition, which is one flat file and not a directory.
|
|
191
|
+
|
|
192
|
+
Same pointer discipline as a skill — the method stays in `.edify/skills/` and this
|
|
193
|
+
file carries only what the runtime discovers on. The difference is that a spawn
|
|
194
|
+
starts with no history, so the pointer says to read the entry *first*: an agent
|
|
195
|
+
that begins work before loading the method it was spawned for is the failure this
|
|
196
|
+
shape exists to prevent.
|
|
197
|
+
"""
|
|
198
|
+
return (
|
|
199
|
+
f"---\nname: {entry.name}\ndescription: {entry.description}\n---\n\n"
|
|
200
|
+
f"{MARKER}\n\n"
|
|
201
|
+
f"# {entry.name}\n\n"
|
|
202
|
+
f"Read `{entry.rel}` in full before doing anything else, then follow it. That file is\n"
|
|
203
|
+
f"the entry; this one only points at it.\n\n"
|
|
204
|
+
f"- **resolves at** `{_coordinates(entry)}` (role · phase · tech)\n"
|
|
205
|
+
f"{_attribution(entry)}\n\n"
|
|
206
|
+
f"The task you were spawned with names its own files and assertions. This entry is the\n"
|
|
207
|
+
f"method; it never overrides the task.\n"
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _write(path: Path, body: str, kind: str, name: str, target: str = "claude") -> Written:
|
|
212
|
+
if path.exists():
|
|
213
|
+
current = _text(path)
|
|
214
|
+
if not _ours(current):
|
|
215
|
+
return Written(path, kind, name, "skipped", target)
|
|
216
|
+
if current == body:
|
|
217
|
+
return Written(path, kind, name, "kept", target)
|
|
218
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
219
|
+
path.write_text(body, encoding="utf-8")
|
|
220
|
+
return Written(path, kind, name, "written", target)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def written_by_edify(path: Path) -> bool:
|
|
224
|
+
"""Whether this file is one of ours, and therefore ours to replace."""
|
|
225
|
+
return _ours(_text(path))
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _ours(text: str) -> bool:
|
|
229
|
+
return agent_table.MARKER_TEXT in text or any(legacy in text for legacy in LEGACY_MARKERS)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _text(path: Path) -> str:
|
|
233
|
+
try:
|
|
234
|
+
return path.read_text(encoding="utf-8")
|
|
235
|
+
except (OSError, UnicodeDecodeError):
|
|
236
|
+
return ""
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def stale(layout: Layout) -> list[Path]:
|
|
240
|
+
"""Generated skill and agent pointers whose entry is no longer installed.
|
|
241
|
+
|
|
242
|
+
An entry removed from `.edify/skills/` leaves a pointer behind, and a pointer to a
|
|
243
|
+
file that is gone is a capability the runtime will offer and then fail to read.
|
|
244
|
+
Both families are walked, in every runtime that has them, including the case an
|
|
245
|
+
entry changes `kind`: flipping `skill` to `agent` writes the new pointer and leaves
|
|
246
|
+
the old one, which is one entry offered twice with only one of them working.
|
|
247
|
+
|
|
248
|
+
Only ever our own files, and only ever reported — deleting is the caller's call.
|
|
249
|
+
"""
|
|
250
|
+
entries = [s for s in skill_format.load_all(layout.skills_dir, layout.root) if s.name]
|
|
251
|
+
installed = {s.name for s in entries}
|
|
252
|
+
agents = {s.name for s in entries if s.kind == "agent"}
|
|
253
|
+
out: list[Path] = []
|
|
254
|
+
|
|
255
|
+
for target in agent_table.TARGETS:
|
|
256
|
+
if target.skills:
|
|
257
|
+
skills_dir = layout.root / target.skills
|
|
258
|
+
if skills_dir.is_dir():
|
|
259
|
+
for child in sorted(skills_dir.iterdir()):
|
|
260
|
+
pointer = child / target.skill_file
|
|
261
|
+
if not (child.is_dir() and pointer.is_file() and written_by_edify(pointer)):
|
|
262
|
+
continue
|
|
263
|
+
# Gone from the library, or still installed but now an agent —
|
|
264
|
+
# either way this file is a pointer nothing stands behind.
|
|
265
|
+
if child.name not in installed or child.name in agents:
|
|
266
|
+
out.append(pointer)
|
|
267
|
+
|
|
268
|
+
if target.agents:
|
|
269
|
+
agents_dir = layout.root / target.agents
|
|
270
|
+
if agents_dir.is_dir():
|
|
271
|
+
for pointer in sorted(agents_dir.glob("*.md")):
|
|
272
|
+
if not written_by_edify(pointer):
|
|
273
|
+
continue
|
|
274
|
+
if pointer.stem not in agents:
|
|
275
|
+
out.append(pointer)
|
|
276
|
+
|
|
277
|
+
return out
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def clear(layout: Layout) -> list[tuple[Path, str]]:
|
|
281
|
+
"""Remove EDIFY's own surface and nothing else. `(path, what happened to it)`.
|
|
282
|
+
|
|
283
|
+
Three families, and the third is the one that needs care. `.edify/` is entirely
|
|
284
|
+
ours. The runtime pointers — commands, skills, and agents, across every runtime in
|
|
285
|
+
the table — are ours only where they carry the marker, so a command, skill, or
|
|
286
|
+
subagent somebody wrote by hand stays. An instruction file (`CLAUDE.md`,
|
|
287
|
+
`AGENTS.md`, `GEMINI.md`, …) is somebody else's file with our block in it, so the
|
|
288
|
+
block goes and the file does not, and the report says which of those happened
|
|
289
|
+
rather than calling both "removed".
|
|
290
|
+
|
|
291
|
+
Shared by `setup --fresh` and `init new`, which both mean "install everything,
|
|
292
|
+
again, properly" and would otherwise each have their own idea of what that clears.
|
|
293
|
+
"""
|
|
294
|
+
import shutil
|
|
295
|
+
|
|
296
|
+
cleared: list[tuple[Path, str]] = []
|
|
297
|
+
|
|
298
|
+
if layout.edify.is_dir():
|
|
299
|
+
shutil.rmtree(layout.edify)
|
|
300
|
+
cleared.append((layout.edify, "removed"))
|
|
301
|
+
|
|
302
|
+
for directory, pattern in layout.host_trees():
|
|
303
|
+
if not directory.is_dir():
|
|
304
|
+
continue
|
|
305
|
+
for path in sorted(directory.glob(pattern)):
|
|
306
|
+
if not written_by_edify(path):
|
|
307
|
+
continue
|
|
308
|
+
path.unlink()
|
|
309
|
+
cleared.append((path, "removed"))
|
|
310
|
+
# A skill is a directory per entry, so an emptied one goes with it. A
|
|
311
|
+
# command and an agent are flat files, and their directory is shared.
|
|
312
|
+
if path.parent != directory and not any(path.parent.iterdir()):
|
|
313
|
+
path.parent.rmdir()
|
|
314
|
+
|
|
315
|
+
for path in layout.instruction_files():
|
|
316
|
+
if not path.is_file():
|
|
317
|
+
continue
|
|
318
|
+
text = _text(path)
|
|
319
|
+
if agent_table.BLOCK_BEGIN not in text or agent_table.BLOCK_END not in text:
|
|
320
|
+
continue
|
|
321
|
+
start = text.index(agent_table.BLOCK_BEGIN)
|
|
322
|
+
end = text.index(agent_table.BLOCK_END) + len(agent_table.BLOCK_END)
|
|
323
|
+
rest = (text[:start] + text[end:]).strip()
|
|
324
|
+
if _has_content(rest):
|
|
325
|
+
path.write_text(rest + "\n", encoding="utf-8")
|
|
326
|
+
cleared.append((path, "edify block removed from"))
|
|
327
|
+
else:
|
|
328
|
+
# Nothing but our block was in it, so the file was ours after all. A
|
|
329
|
+
# Cursor rule file keeps a frontmatter header outside the block, and a
|
|
330
|
+
# file that is nothing but a header is a leftover, not somebody's work.
|
|
331
|
+
path.unlink()
|
|
332
|
+
cleared.append((path, "removed"))
|
|
333
|
+
|
|
334
|
+
return cleared
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _has_content(text: str) -> bool:
|
|
338
|
+
"""Whether anything but a frontmatter header survived the block's removal."""
|
|
339
|
+
lines = text.strip().splitlines()
|
|
340
|
+
if lines and lines[0].strip() == "---":
|
|
341
|
+
for i, line in enumerate(lines[1:], start=1):
|
|
342
|
+
if line.strip() == "---":
|
|
343
|
+
lines = lines[i + 1:]
|
|
344
|
+
break
|
|
345
|
+
return any(line.strip() for line in lines)
|