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.
Files changed (102) hide show
  1. edify/__init__.py +19 -0
  2. edify/__main__.py +6 -0
  3. edify/_toml.py +286 -0
  4. edify/agents.py +261 -0
  5. edify/anim.py +499 -0
  6. edify/assets/commands/build.md +64 -0
  7. edify/assets/commands/plan.md +68 -0
  8. edify/assets/commands/spec.md +63 -0
  9. edify/assets/commands/tasks.md +65 -0
  10. edify/assets/commands/verify.md +67 -0
  11. edify/assets/formats/plan.example.md +455 -0
  12. edify/assets/formats/plan.format.md +128 -0
  13. edify/assets/formats/spec.example.md +483 -0
  14. edify/assets/formats/spec.format.md +116 -0
  15. edify/assets/formats/tasks.example.md +712 -0
  16. edify/assets/formats/tasks.format.md +199 -0
  17. edify/assets/harvest/harvest.md +91 -0
  18. edify/assets/harvest/sources.md +295 -0
  19. edify/assets/harvest/vocab.md +52 -0
  20. edify/assets/manifest.md +30 -0
  21. edify/assets/mcp/default-registry.md +66 -0
  22. edify/assets/skills/adversary.md +61 -0
  23. edify/assets/skills/debugger.md +64 -0
  24. edify/assets/skills/implementer-general.md +53 -0
  25. edify/assets/skills/implementer-go.md +63 -0
  26. edify/assets/skills/implementer-node.md +61 -0
  27. edify/assets/skills/implementer-postgres.md +63 -0
  28. edify/assets/skills/implementer-python.md +65 -0
  29. edify/assets/skills/implementer-react.md +65 -0
  30. edify/assets/skills/planner.md +58 -0
  31. edify/assets/skills/test-writer-node.md +64 -0
  32. edify/assets/skills/test-writer-python.md +60 -0
  33. edify/assets/skills/verifier.md +67 -0
  34. edify/assets/templates/CLAUDE.md +18 -0
  35. edify/assets.py +77 -0
  36. edify/cli.py +681 -0
  37. edify/commands/__init__.py +1 -0
  38. edify/commands/check_cmd.py +72 -0
  39. edify/commands/doctor_cmd.py +206 -0
  40. edify/commands/feedback_cmd.py +90 -0
  41. edify/commands/governance_cmd.py +65 -0
  42. edify/commands/graph_cmd.py +156 -0
  43. edify/commands/harvest_cmd.py +538 -0
  44. edify/commands/init_cmd.py +333 -0
  45. edify/commands/init_new_cmd.py +151 -0
  46. edify/commands/license_cmd.py +80 -0
  47. edify/commands/mcp_cmd.py +159 -0
  48. edify/commands/self_cmd.py +185 -0
  49. edify/commands/setup_cmd.py +79 -0
  50. edify/commands/skills_cmd.py +177 -0
  51. edify/commands/upgrade_cmd.py +178 -0
  52. edify/context.py +57 -0
  53. edify/conventions.py +275 -0
  54. edify/detect.py +313 -0
  55. edify/distribution.py +40 -0
  56. edify/errors.py +66 -0
  57. edify/feedback.py +207 -0
  58. edify/formats/__init__.py +11 -0
  59. edify/formats/check.py +573 -0
  60. edify/formats/document.py +238 -0
  61. edify/formats/finding.py +50 -0
  62. edify/formats/fix.py +114 -0
  63. edify/formats/mcp.py +126 -0
  64. edify/formats/plan.py +151 -0
  65. edify/formats/skill.py +139 -0
  66. edify/formats/spec.py +164 -0
  67. edify/formats/tasks.py +321 -0
  68. edify/governance.py +316 -0
  69. edify/graph/__init__.py +11 -0
  70. edify/graph/extract.py +351 -0
  71. edify/graph/ignore.py +107 -0
  72. edify/graph/langs/__init__.py +93 -0
  73. edify/graph/langs/ctags.py +145 -0
  74. edify/graph/langs/markdown.py +41 -0
  75. edify/graph/langs/patterns.py +361 -0
  76. edify/graph/langs/python_ast.py +154 -0
  77. edify/graph/langs/sqlish.py +86 -0
  78. edify/graph/model.py +102 -0
  79. edify/graph/queries.py +211 -0
  80. edify/graph/store.py +157 -0
  81. edify/harvest/__init__.py +28 -0
  82. edify/harvest/ledger.py +191 -0
  83. edify/harvest/screen.py +236 -0
  84. edify/harvest/sources.py +298 -0
  85. edify/host.py +345 -0
  86. edify/interview.py +354 -0
  87. edify/library.py +176 -0
  88. edify/licensing/__init__.py +30 -0
  89. edify/licensing/ed25519.py +154 -0
  90. edify/licensing/projects.py +223 -0
  91. edify/licensing/tier.py +172 -0
  92. edify/licensing/token.py +149 -0
  93. edify/paths.py +282 -0
  94. edify/selfinstall.py +244 -0
  95. edify/skills.py +108 -0
  96. edify/tsv.py +109 -0
  97. edify/ui.py +334 -0
  98. edify_agents_cli-0.2.0.dist-info/METADATA +408 -0
  99. edify_agents_cli-0.2.0.dist-info/RECORD +102 -0
  100. edify_agents_cli-0.2.0.dist-info/WHEEL +4 -0
  101. edify_agents_cli-0.2.0.dist-info/entry_points.txt +2 -0
  102. edify_agents_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,159 @@
1
+ """`edify mcp` — the registry, and what a spawn in a given position would load.
2
+
3
+ `for` exists so the scoping is inspectable rather than implicit. "Why did this task
4
+ have the browser loaded?" should be one command, not an investigation.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import shutil
11
+ import subprocess
12
+ from pathlib import Path
13
+
14
+ from ..context import Context
15
+ from ..errors import TierRequired
16
+ from ..formats import mcp as mcp_format
17
+ from ..licensing import tier
18
+
19
+
20
+ def _licence_hint() -> str:
21
+ """The one licence sentence, taken from the refusal rather than retyped."""
22
+ return TierRequired(tier.FEATURE_NAMES["mcp.multi"]).hint
23
+
24
+
25
+ def list_(ctx: Context) -> int:
26
+ ctx.layout.require_installed()
27
+ registry = mcp_format.parse(ctx.layout.mcp)
28
+ if not registry.servers:
29
+ ctx.out.line("the registry is empty — everything works with it empty")
30
+ return 0
31
+
32
+ cap = ctx.entitlement.mcp_cap
33
+ ctx.out.data(
34
+ [
35
+ {
36
+ "server": s.name,
37
+ "version": s.version,
38
+ "provides": s.provides,
39
+ "roles": s.roles,
40
+ "phases": s.phases,
41
+ "network": s.network,
42
+ "source": s.source,
43
+ "needs_licence": cap is not None and i >= cap,
44
+ }
45
+ for i, s in enumerate(registry.servers)
46
+ ]
47
+ )
48
+ ctx.out.table(
49
+ ["server", "version", "roles", "phases", "network", "provides"],
50
+ [
51
+ [s.name, s.version, " ".join(s.roles) or "—", " ".join(s.phases) or "—", s.network, s.provides[:48]]
52
+ for s in registry.servers
53
+ ],
54
+ )
55
+ if cap is not None and len(registry.servers) > cap:
56
+ ctx.out.warn(
57
+ f"{len(registry.servers)} servers declared; the public edition loads the first {cap}."
58
+ " The rest stay on disk and load once a team or partner licence is present."
59
+ )
60
+ ctx.out.note(_licence_hint())
61
+ return 0
62
+
63
+
64
+ def for_(ctx: Context) -> int:
65
+ ctx.layout.require_installed()
66
+ registry = mcp_format.parse(ctx.layout.mcp)
67
+ servers = registry.for_spawn(ctx.args.role, ctx.args.phase)
68
+
69
+ cap = ctx.entitlement.mcp_cap
70
+ if cap is not None:
71
+ allowed = {s.name for s in registry.servers[:cap]}
72
+ withheld = [s for s in servers if s.name not in allowed]
73
+ servers = [s for s in servers if s.name in allowed]
74
+ for server in withheld:
75
+ ctx.out.warn(
76
+ f"`{server.name}` needs a team or partner licence (more than {cap} server) and was not loaded"
77
+ )
78
+ if withheld:
79
+ ctx.out.note(_licence_hint())
80
+
81
+ ctx.out.data([{"server": s.name, "version": s.version, "network": s.network} for s in servers])
82
+ if not servers:
83
+ ctx.out.line("none")
84
+ return 0
85
+ for server in servers:
86
+ ctx.out.line(f"{server.name}@{server.version}\t{server.network}")
87
+ return 0
88
+
89
+
90
+ def check(ctx: Context) -> int:
91
+ """Each server responds and its version matches the pin — where that is knowable.
92
+
93
+ A server we cannot probe is reported as unprobeable rather than as passing.
94
+ An unreachable `outbound` server on an air-gapped network is absent and says
95
+ so; a silent fallback to recollection is the failure this exists to prevent.
96
+ """
97
+ ctx.layout.require_installed()
98
+ registry = mcp_format.parse(ctx.layout.mcp)
99
+ configured = _configured_servers(ctx.layout.root)
100
+
101
+ rows = []
102
+ results = []
103
+ worst = 0
104
+ for server in registry.servers:
105
+ state, detail = _probe(server, configured)
106
+ rows.append([server.name, server.version, state, detail])
107
+ results.append({"server": server.name, "state": state, "detail": detail})
108
+ if state == "missing":
109
+ worst = max(worst, 1)
110
+
111
+ for problem in mcp_format.validate(registry):
112
+ ctx.out.warn(f"{ctx.layout.rel(ctx.layout.mcp)}:{problem[2]}: {problem[1]}")
113
+
114
+ ctx.out.data(results)
115
+ ctx.out.table(["server", "pinned", "state", "detail"], rows)
116
+ return worst
117
+
118
+
119
+ # ---------------------------------------------------------------------------
120
+
121
+
122
+ def _configured_servers(root: Path) -> dict[str, dict]:
123
+ """What the host runtime is actually configured to launch, if it says so."""
124
+ for candidate in (root / ".mcp.json", root / "mcp.json", root / ".claude" / "mcp.json"):
125
+ if candidate.is_file():
126
+ try:
127
+ data = json.loads(candidate.read_text(encoding="utf-8"))
128
+ except json.JSONDecodeError:
129
+ continue
130
+ servers = data.get("mcpServers") or data.get("servers") or {}
131
+ if isinstance(servers, dict):
132
+ return servers
133
+ return {}
134
+
135
+
136
+ def _probe(server: mcp_format.Server, configured: dict[str, dict]) -> tuple[str, str]:
137
+ entry = configured.get(server.name)
138
+ if entry is None:
139
+ if not configured:
140
+ return "unprobeable", "no host mcp configuration found in this repository"
141
+ return "missing", "declared in the registry, not configured for the host runtime"
142
+
143
+ command = entry.get("command")
144
+ if not command:
145
+ return "configured", "remote transport — the pin cannot be checked from here"
146
+ if not shutil.which(str(command)):
147
+ return "missing", f"`{command}` is not on PATH"
148
+
149
+ try:
150
+ out = subprocess.run(
151
+ [str(command), "--version"], capture_output=True, text=True, timeout=15, check=False
152
+ )
153
+ except (OSError, subprocess.SubprocessError):
154
+ return "configured", "does not answer --version; the pin cannot be checked"
155
+ text = (out.stdout + out.stderr).strip().splitlines()
156
+ reported = text[0] if text else ""
157
+ if server.version and server.version in reported:
158
+ return "ok", reported[:60]
159
+ return "drifted", f"reports `{reported[:40]}`, registry pins `{server.version}`"
@@ -0,0 +1,185 @@
1
+ """`edify self` — the binary talking about itself.
2
+
3
+ Two commands, and the split between them is deliberate: one reads, one writes.
4
+
5
+ edify self where which edify is this, and where did it come from
6
+ edify self update put an edited checkout behind that binary
7
+
8
+ **This is not `edify upgrade`.** `upgrade` pulls a newer *skill library* into
9
+ `.edify/`; `self update` replaces the CLI. Two different things, two names, and
10
+ the closing line of each says which one the person probably wanted.
11
+
12
+ **This is the second command that reaches the network.** `cli.py` claims none do
13
+ except `upgrade`, and building a wheel from a checkout fetches `hatchling` unless
14
+ it is already cached, so the claim is amended here rather than quietly broken.
15
+ `--offline` is the opt-in that fails cleanly instead of reaching out.
16
+
17
+ **It does not touch `.edify/` in any repository.** Updating the CLI and
18
+ reinstalling the harness into a checkout are separate operations; the second one
19
+ is `edify setup . --fresh`.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import json
25
+ import subprocess
26
+ import sys
27
+
28
+ from .. import __version__, selfinstall
29
+ from ..context import Context
30
+ from ..errors import EdifyError
31
+
32
+ #: An install builds a wheel and may resolve a build backend over the network.
33
+ #: Generous, because a slow first build on a cold cache is not a failure.
34
+ TIMEOUT = 600
35
+
36
+
37
+ def where(ctx: Context) -> int:
38
+ """Which edify is this, and where did it come from. Reads only."""
39
+ info = selfinstall.describe()
40
+ ctx.out.data(info)
41
+
42
+ ctx.out.line("version edify " + info["version"])
43
+ ctx.out.line("binary " + (info["executable"] or "not resolvable from argv[0]"))
44
+ ctx.out.line("interpreter " + info["interpreter"])
45
+ ctx.out.line("prefix " + info["prefix"])
46
+ ctx.out.line("package " + info["package"])
47
+ ctx.out.line("installer " + info["manager"] + " (override with --manager)")
48
+ ctx.out.line("source " + (info["source"] or "none — this is a built install, not a checkout"))
49
+
50
+ argv = selfinstall.install_command(
51
+ info["manager"], info["source"] or ".", editable=bool(info["source"])
52
+ )
53
+ ctx.out.line("")
54
+ ctx.out.line("update with " + " ".join(argv))
55
+ return 0
56
+
57
+
58
+ def update(ctx: Context) -> int:
59
+ """Reinstall `edify` from a source checkout, using the tool that installed it."""
60
+ out = ctx.out
61
+ args = ctx.args
62
+
63
+ source = selfinstall.resolve_source(
64
+ getattr(args, "from_path", None), repo_root=ctx.layout.root
65
+ )
66
+ manager = getattr(args, "manager", "") or selfinstall.detect_manager()
67
+ editable = bool(getattr(args, "editable", False))
68
+ offline = bool(getattr(args, "offline", False))
69
+ argv = selfinstall.install_command(manager, source, editable=editable, offline=offline)
70
+
71
+ before = __version__
72
+ out.note("source " + str(source))
73
+ out.note("installer " + manager + (" (editable)" if editable else ""))
74
+
75
+ if getattr(args, "dry_run", False):
76
+ out.data({"source": str(source), "manager": manager, "command": argv, "ran": False})
77
+ out.line(" ".join(argv))
78
+ out.note("nothing was installed — this is --dry-run")
79
+ return 0
80
+
81
+ with _spinner(ctx, "installing edify from " + str(source)):
82
+ code, output = _run(argv)
83
+
84
+ if code != 0:
85
+ if selfinstall.looks_locked(output):
86
+ raise EdifyError(
87
+ "the running edify could not be replaced — this binary is open in this shell",
88
+ hint=selfinstall.unlock_hint(manager, source, editable=editable),
89
+ )
90
+ raise EdifyError(
91
+ manager + " could not install from " + str(source) + " (exit " + str(code) + ")",
92
+ hint=_first_useful_line(output) or "run the command above by hand to see the whole failure",
93
+ )
94
+
95
+ after = _installed_version()
96
+ out.data(
97
+ {
98
+ "source": str(source),
99
+ "manager": manager,
100
+ "command": argv,
101
+ "ran": True,
102
+ "version_before": before,
103
+ "version_after": after,
104
+ }
105
+ )
106
+ if after and after != before:
107
+ out.ok("edify " + before + " -> " + after)
108
+ elif after:
109
+ # Not a failure — reinstalling an unchanged version is the common case
110
+ # while developing. But it is also exactly what a shadowed second copy
111
+ # looks like, so the sentence says both rather than only the happy one.
112
+ out.ok("edify " + after + " installed from " + str(source))
113
+ out.note("the version did not change. If you expected it to, `edify self where` "
114
+ "shows which binary is answering.")
115
+ else:
116
+ out.ok("installed from " + str(source))
117
+ out.note("the new binary did not report a version; check `edify self where`")
118
+
119
+ out.line("")
120
+ out.line("This replaced the CLI. To reinstall the harness into a repository, "
121
+ "run `edify setup . --fresh`.")
122
+ return 0
123
+
124
+
125
+ # ---------------------------------------------------------------------------
126
+
127
+
128
+ def _run(argv: list[str]) -> tuple[int, str]:
129
+ """Run the installer. Its output is captured so a failure can be read."""
130
+ try:
131
+ proc = subprocess.run(
132
+ argv,
133
+ capture_output=True,
134
+ text=True,
135
+ timeout=TIMEOUT,
136
+ check=False,
137
+ )
138
+ except FileNotFoundError:
139
+ return 127, argv[0] + " is not on PATH"
140
+ except subprocess.TimeoutExpired:
141
+ return 124, "timed out after " + str(TIMEOUT) + "s"
142
+ except OSError as exc:
143
+ return 1, str(exc)
144
+ return proc.returncode, (proc.stdout or "") + (proc.stderr or "")
145
+
146
+
147
+ def _installed_version() -> str:
148
+ """Ask the *new* binary what it is.
149
+
150
+ Deliberately invoked as a fresh subprocess rather than read from the module
151
+ already imported here — the whole point is to find out what the next
152
+ invocation will be, and a shadowed install shows up as a version that did not
153
+ move (plan, Risks).
154
+ """
155
+ for argv in (["edify", "version", "--json"], [sys.executable, "-m", "edify.cli", "version", "--json"]):
156
+ try:
157
+ proc = subprocess.run(argv, capture_output=True, text=True, timeout=60, check=False)
158
+ except (OSError, subprocess.SubprocessError):
159
+ continue
160
+ if proc.returncode != 0:
161
+ continue
162
+ try:
163
+ return str(json.loads(proc.stdout).get("version", ""))
164
+ except (ValueError, AttributeError):
165
+ continue
166
+ return ""
167
+
168
+
169
+ def _first_useful_line(output: str) -> str:
170
+ for line in reversed((output or "").splitlines()):
171
+ line = line.strip()
172
+ if line and not line.startswith(("Resolved", "Prepared", "Downloaded")):
173
+ return line[:200]
174
+ return ""
175
+
176
+
177
+ def _spinner(ctx: Context, label: str):
178
+ """The infinity, while the installer runs.
179
+
180
+ `anim.spinner` decides whether to paint: at a terminal it does, and everywhere
181
+ else the label is printed once as a static line.
182
+ """
183
+ from .. import anim
184
+
185
+ return anim.spinner(ctx.out, label)
@@ -0,0 +1,79 @@
1
+ """`edify setup [PATH]` — the whole harness, in a folder, from nothing.
2
+
3
+ `init` is the incremental one: it finds the repository root by walking upward, keeps
4
+ every file that is already there, and merges into an instruction file somebody else
5
+ wrote. That is the right behaviour for a repository under way and the wrong behaviour
6
+ twice over for a folder you are starting in:
7
+
8
+ **It installs somewhere else.** `find_root` walks up until it finds `.edify/`, `.git/`,
9
+ or a manifest, so `mkdir service && cd service && edify init` inside an existing
10
+ checkout installs into the *parent* — the same `.edify/` the outer repository already
11
+ has, silently. `setup` anchors the root at exactly the path it was given and never
12
+ looks above it. A folder that does not exist yet is created.
13
+
14
+ **It keeps what is there.** "Install everything, again, properly" is not what `init`
15
+ does without `--force`, and `--force` still leaves behind the files a previous version
16
+ wrote under names this one no longer uses. `--fresh` removes EDIFY's own surface
17
+ first — `.edify/`, the host pointers it generated, and its block in `CLAUDE.md` — and
18
+ then installs the lot. Nothing outside that surface is touched, ever: `--fresh` is not
19
+ `rm -rf`, and a folder with source code in it comes out with the source code in it.
20
+
21
+ Everything else is `init`, called with `force` on, so there is one install path and not
22
+ two that drift.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ from pathlib import Path
28
+
29
+ from .. import anim
30
+ from ..context import Context
31
+ from ..errors import EdifyError
32
+ from ..host import clear as host_clear
33
+ from ..paths import Layout
34
+ from . import init_cmd
35
+
36
+
37
+ def run(ctx: Context) -> int:
38
+ root = Path(getattr(ctx.args, "path", None) or ".").expanduser()
39
+ if root.exists() and not root.is_dir():
40
+ raise EdifyError(f"{root} is a file, not a folder")
41
+
42
+ created = not root.exists()
43
+ root.mkdir(parents=True, exist_ok=True)
44
+ root = root.resolve()
45
+
46
+ # The one thing `setup` does that `init` cannot: pin the root rather than search
47
+ # for it, so a new folder inside an existing checkout installs into the new folder.
48
+ layout = Layout(root)
49
+ scoped = Context(args=ctx.args, layout=layout, out=ctx.out)
50
+
51
+ # The wordmark opens the install, once, above `setup`'s own first line rather
52
+ # than in the middle of it. `caller_opens` is how `init_cmd` is told not to
53
+ # print a second one — the same shape as `caller_closes` at the other end.
54
+ anim.banner(ctx.out, "setup")
55
+ ctx.args.caller_opens = True
56
+
57
+ ctx.out.field("setup", f"{root}{' (created)' if created else ''}")
58
+
59
+ if getattr(ctx.args, "fresh", False):
60
+ cleared = _clear(layout)
61
+ ctx.out.field("fresh", f"{len(cleared)} edify-owned path(s) cleared before installing")
62
+ for path, action in cleared:
63
+ ctx.out.note(f" {action} {layout.rel(path)}")
64
+
65
+ # `init` merges by default; setup means install everything, so force is on.
66
+ scoped.args.force = True
67
+ ctx.out.line("")
68
+ return init_cmd.run(scoped)
69
+
70
+
71
+ def _clear(layout: Layout) -> list[tuple[Path, str]]:
72
+ """Remove EDIFY's own surface and nothing else. `(path, what happened to it)`.
73
+
74
+ The work is `host.clear`, which `init new` also runs. Two commands that both mean
75
+ "install everything, again, properly" must not each have their own idea of what
76
+ that clears — the second one to be written would inevitably miss a family the
77
+ first one knew about.
78
+ """
79
+ return host_clear(layout)
@@ -0,0 +1,177 @@
1
+ """`edify skills` — what is installed, and which file a spawn loads.
2
+
3
+ `resolve` is the lookup `/build` performs before every spawn. It prints one line.
4
+
5
+ There is deliberately no `skills install <url>` and no registry browsing. Anything
6
+ arriving from outside goes through `/harvest` and a human in EDIFY's own
7
+ repository: an ad-hoc import is a stranger's text loaded as trusted instruction
8
+ into every matching session in a customer's codebase.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import shutil
14
+ from pathlib import Path
15
+
16
+ from .. import governance, host, skills as skills_index
17
+ from ..context import Context
18
+ from ..errors import EdifyError
19
+ from ..formats import skill as skill_format
20
+ from ..tsv import read_rows
21
+
22
+
23
+ def list_(ctx: Context) -> int:
24
+ ctx.layout.require_installed()
25
+ entries = skill_format.load_all(ctx.layout.skills_dir, ctx.layout.root)
26
+ if not entries:
27
+ ctx.out.line("no skills installed")
28
+ return 0
29
+
30
+ rows = []
31
+ for skill in entries:
32
+ rows.append(
33
+ [
34
+ skill.name or "(invalid)",
35
+ skill.role or "-",
36
+ " ".join(skill.phases) or "-",
37
+ " ".join(skill.tech) or "-",
38
+ skill.provenance or "-",
39
+ skill.license or "-",
40
+ f"{skill.body_lines}/{skill.budget}",
41
+ ]
42
+ )
43
+ ctx.out.data(
44
+ [
45
+ {
46
+ "name": s.name,
47
+ "role": s.role,
48
+ "phases": s.phases,
49
+ "tech": s.tech,
50
+ "provenance": s.provenance,
51
+ "license": s.license,
52
+ "lines": s.body_lines,
53
+ "budget": s.budget,
54
+ "path": s.rel,
55
+ }
56
+ for s in entries
57
+ ]
58
+ )
59
+ ctx.out.table(["name", "role", "phase", "tech", "provenance", "license", "lines"], rows)
60
+ return 0
61
+
62
+
63
+ def resolve(ctx: Context) -> int:
64
+ ctx.layout.require_installed()
65
+ tech = ctx.args.tech or _stack_tech(ctx)
66
+ entry = skills_index.resolve(ctx.layout, ctx.args.role, ctx.args.phase, tech)
67
+ ctx.out.data({"role": entry.role, "phase": entry.phase, "tech": entry.tech, "name": entry.name, "path": entry.path})
68
+ ctx.out.line(entry.path)
69
+ return 0
70
+
71
+
72
+ def index(ctx: Context) -> int:
73
+ ctx.layout.require_installed()
74
+ rows, skipped = skills_index.build_index(ctx.layout)
75
+ ctx.out.data({"rows": rows, "skipped": skipped})
76
+ ctx.out.line(f"{rows} rows")
77
+ for problem in skipped:
78
+ ctx.out.warn(f"skipped — {problem}")
79
+ return 0
80
+
81
+
82
+ def sync(ctx: Context) -> int:
83
+ """Mirror the installed library into each agent runtime's own directories.
84
+
85
+ `.edify/skills/<name>.md` is where an entry lives and `edify skills resolve` is
86
+ how a build spawn finds it. Neither is where Claude Code looks: it discovers
87
+ skills at `.claude/skills/<name>/SKILL.md`, one directory each, and subagents at
88
+ `.claude/agents/<name>.md`, one flat file each. `kind` decides which an entry gets.
89
+ Until that mirror exists an installed entry is invisible to the runtime the person
90
+ is typing into, which is the gap this closes.
91
+
92
+ Which runtimes, with no `--agents`, is whichever ones are already set up in this
93
+ folder — a folder `init new` prepared for six of them gets all six updated here.
94
+
95
+ Run by `init`, `upgrade`, `setup`, and the last step of an admission. Standalone
96
+ for the case where a skill file was added or removed by hand.
97
+ """
98
+ ctx.layout.require_installed()
99
+ written = host.sync(
100
+ ctx.layout,
101
+ host=getattr(ctx.args, "host", "claude"),
102
+ agents=getattr(ctx.args, "agents", ""),
103
+ )
104
+ leftovers = host.stale(ctx.layout)
105
+ # These are governed files, so the ledger moves with them. Without this the next
106
+ # `governance verify` reports every pointer this command just wrote as unrecorded.
107
+ governance.rebuild(ctx.layout)
108
+
109
+ ctx.out.data(
110
+ {
111
+ "written": [
112
+ {"path": ctx.layout.rel(w.path), "kind": w.kind, "name": w.name, "action": w.action}
113
+ for w in written
114
+ ],
115
+ "stale": [ctx.layout.rel(p) for p in leftovers],
116
+ }
117
+ )
118
+ if not written:
119
+ ctx.out.line("nothing to mirror")
120
+ return 0
121
+
122
+ rows = [[ctx.layout.rel(w.path), w.kind, w.action] for w in written]
123
+ ctx.out.table(["path", "kind", "action"], rows)
124
+ changed = sum(1 for w in written if w.action == "written")
125
+ ctx.out.line("")
126
+ ctx.out.line(f"{changed} written · {len(written) - changed} already current")
127
+ for item in written:
128
+ if item.action == "skipped":
129
+ ctx.out.warn(f"kept your own file at {ctx.layout.rel(item.path)} — not an edify pointer")
130
+ for path in leftovers:
131
+ ctx.out.warn(f"{ctx.layout.rel(path)} points at an entry that is no longer installed — safe to delete")
132
+ return 0
133
+
134
+
135
+ def add(ctx: Context) -> int:
136
+ """Install one entry from the shipped library, or a local file.
137
+
138
+ Local only, by design. A path on disk is something a person can read before it
139
+ becomes trusted context; a URL is not.
140
+ """
141
+ ctx.layout.require_installed()
142
+ source = Path(ctx.args.path).expanduser()
143
+ if not source.is_file():
144
+ raise EdifyError(f"{source} is not a file")
145
+ if source.suffix != ".md":
146
+ raise EdifyError("a skill entry is a markdown file with flat YAML frontmatter")
147
+
148
+ parsed = skill_format.parse(source, source.name)
149
+ problems = [p for p in skill_format.validate(parsed) if p[0] != "skill-over-budget"]
150
+ if problems:
151
+ for _, message, _line in problems:
152
+ ctx.out.error(message)
153
+ raise EdifyError("not installed — the frontmatter is invalid")
154
+
155
+ target = ctx.layout.skills_dir / source.name
156
+ ctx.layout.skills_dir.mkdir(parents=True, exist_ok=True)
157
+ shutil.copyfile(source, target)
158
+ rows, _ = skills_index.build_index(ctx.layout)
159
+ host.sync(ctx.layout)
160
+ governance.rebuild(ctx.layout)
161
+ ctx.out.line(f"installed {parsed.name} → {ctx.layout.rel(target)} · index now {rows} rows")
162
+ mirror = (
163
+ f".claude/agents/{parsed.name}.md"
164
+ if parsed.kind == "agent"
165
+ else f".claude/skills/{parsed.name}/SKILL.md"
166
+ )
167
+ ctx.out.note(f"mirrored to {mirror}")
168
+ return 0
169
+
170
+
171
+ def _stack_tech(ctx: Context) -> str:
172
+ """The repository's own stack, so `resolve` needs only a role and a phase."""
173
+ values: list[str] = []
174
+ for row in read_rows(ctx.layout.stack):
175
+ if len(row) >= 2 and row[0] in ("language", "framework"):
176
+ values.append(row[1])
177
+ return " ".join(values)