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,178 @@
1
+ """`edify upgrade` — pull a newer skill library and re-index.
2
+
3
+ The one command in the working set that is allowed to reach the network, and it
4
+ has a documented plain-archive path so an air-gapped machine can still be
5
+ upgraded: download the archive somewhere with a network, carry it across, and
6
+ point `--archive` at it.
7
+
8
+ Nothing else in this CLI opens a socket while it is doing your work. The one other
9
+ command that can reach out is `edify self update`, which replaces the binary
10
+ itself rather than anything in a repository, and which hands the fetching to uv,
11
+ pipx, or pip rather than doing any of it here.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import shutil
18
+ import tarfile
19
+ import tempfile
20
+ import urllib.error
21
+ import urllib.request
22
+ import zipfile
23
+ from pathlib import Path
24
+
25
+ from .. import __version__, assets, governance, host, library, skills as skills_index
26
+ from ..context import Context
27
+ from ..errors import EdifyError
28
+ from ..formats import skill as skill_format
29
+ from ..tsv import sha256_file
30
+
31
+ DEFAULT_CHANNEL = "stable"
32
+ INDEX_URL = "https://registry.edify.dev/library/{channel}.json"
33
+
34
+
35
+ def run(ctx: Context) -> int:
36
+ ctx.layout.require_installed()
37
+
38
+ if ctx.args.archive:
39
+ return _from_archive(ctx, Path(ctx.args.archive).expanduser())
40
+ if ctx.args.check:
41
+ return _check_only(ctx)
42
+ return _from_network(ctx)
43
+
44
+
45
+ # ---------------------------------------------------------------------------
46
+
47
+
48
+ def _check_only(ctx: Context) -> int:
49
+ manifest = _fetch_manifest(ctx)
50
+ current = assets.manifest().get("library", "0")
51
+ ctx.out.data({"installed": current, "available": manifest.get("version"), "cli": __version__})
52
+ ctx.out.line(f"installed library {current} · available {manifest.get('version', 'unknown')}")
53
+ return 0
54
+
55
+
56
+ def _from_network(ctx: Context) -> int:
57
+ manifest = _fetch_manifest(ctx)
58
+ url = manifest.get("archive")
59
+ checksum = manifest.get("sha256")
60
+ if not url:
61
+ raise EdifyError("the channel manifest names no archive")
62
+
63
+ with tempfile.TemporaryDirectory() as tmp:
64
+ target = Path(tmp) / "library-archive"
65
+ try:
66
+ with urllib.request.urlopen(url, timeout=60) as response: # noqa: S310 - pinned https
67
+ target.write_bytes(response.read())
68
+ except (urllib.error.URLError, OSError) as exc:
69
+ raise EdifyError(
70
+ f"could not reach {url}: {exc}",
71
+ hint="download it on a networked machine and use `edify upgrade --archive <path>`",
72
+ ) from exc
73
+
74
+ actual = sha256_file(target)
75
+ if checksum and actual != checksum:
76
+ raise EdifyError(
77
+ "the downloaded archive does not match the checksum in the manifest",
78
+ hint="this is refused rather than installed — untrusted text becomes trusted context once installed",
79
+ )
80
+ return _from_archive(ctx, target)
81
+
82
+
83
+ def _from_archive(ctx: Context, archive: Path) -> int:
84
+ """Install skill entries from a local archive.
85
+
86
+ Every entry is validated before it lands. An archive is untrusted text until
87
+ something has read it, and a skill file is persistent trusted context in every
88
+ session that loads it — so an invalid entry is rejected, not repaired.
89
+ """
90
+ if not archive.is_file():
91
+ raise EdifyError(f"{archive} is not a file")
92
+
93
+ with tempfile.TemporaryDirectory() as tmp:
94
+ staging = Path(tmp) / "staged"
95
+ staging.mkdir()
96
+ _unpack(archive, staging)
97
+
98
+ candidates = sorted(staging.rglob("*.md"))
99
+ if not candidates:
100
+ raise EdifyError("the archive contains no skill entries")
101
+
102
+ staged, rejected = [], []
103
+ for path in candidates:
104
+ parsed = skill_format.parse(path, path.name)
105
+ problems = [p for p in skill_format.validate(parsed) if p[0] != "skill-over-budget"]
106
+ if problems:
107
+ rejected.append((path.name, problems[0][1]))
108
+ continue
109
+ if parsed.provenance == "adapted" and not parsed.license:
110
+ rejected.append((path.name, "adapted with no licence"))
111
+ continue
112
+ staged.append(library.Candidate(path, parsed))
113
+
114
+ # The same question `init` asks, for the same reason: these arrived from
115
+ # outside and become trusted instruction the moment they land.
116
+ spec = "all" if getattr(ctx.args, "yes", False) else getattr(ctx.args, "skills", "auto")
117
+ chosen = library.choose(ctx.out, staged, spec)
118
+ installed = []
119
+ for candidate in chosen:
120
+ shutil.copyfile(candidate.path, ctx.layout.skills_dir / candidate.path.name)
121
+ installed.append(candidate.name)
122
+ declined = len(staged) - len(chosen)
123
+
124
+ rows, skipped = skills_index.build_index(ctx.layout)
125
+ # A newly installed entry that the host runtime cannot see is not installed in the
126
+ # only sense the person cares about, so the mirror moves with the library.
127
+ mirrored = host.sync(ctx.layout)
128
+ ledger = governance.rebuild(ctx.layout)
129
+ ctx.out.data(
130
+ {
131
+ "installed": installed,
132
+ "declined": declined,
133
+ "rejected": rejected,
134
+ "index_rows": rows,
135
+ "mirrored": sum(1 for m in mirrored if m.kind == "skill"),
136
+ "governed_files": len(ledger),
137
+ }
138
+ )
139
+ ctx.out.line(
140
+ f"{len(installed)} entries installed · {declined} declined · index now {rows} rows"
141
+ )
142
+ for name, reason in rejected:
143
+ ctx.out.warn(f"rejected {name}: {reason}")
144
+ for problem in skipped:
145
+ ctx.out.warn(f"skipped in index — {problem}")
146
+ for path in host.stale(ctx.layout):
147
+ ctx.out.warn(f"{ctx.layout.rel(path)} points at an entry that is no longer installed — safe to delete")
148
+ return 0
149
+
150
+
151
+ def _fetch_manifest(ctx: Context) -> dict:
152
+ url = INDEX_URL.format(channel=ctx.args.channel or DEFAULT_CHANNEL)
153
+ try:
154
+ with urllib.request.urlopen(url, timeout=30) as response: # noqa: S310 - pinned https
155
+ return json.loads(response.read().decode("utf-8"))
156
+ except (urllib.error.URLError, OSError, json.JSONDecodeError) as exc:
157
+ raise EdifyError(
158
+ f"could not reach the library channel: {exc}",
159
+ hint="everything except `upgrade` works offline; use `--archive <path>` on an air-gapped network",
160
+ ) from exc
161
+
162
+
163
+ def _unpack(archive: Path, into: Path) -> None:
164
+ if zipfile.is_zipfile(archive):
165
+ with zipfile.ZipFile(archive) as zf:
166
+ for member in zf.namelist():
167
+ if member.startswith("/") or ".." in Path(member).parts:
168
+ raise EdifyError(f"the archive contains an unsafe path: {member}")
169
+ zf.extractall(into)
170
+ return
171
+ if tarfile.is_tarfile(archive):
172
+ with tarfile.open(archive) as tf:
173
+ for member in tf.getmembers():
174
+ if member.name.startswith("/") or ".." in Path(member.name).parts:
175
+ raise EdifyError(f"the archive contains an unsafe path: {member.name}")
176
+ tf.extractall(into, filter="data")
177
+ return
178
+ raise EdifyError(f"{archive} is neither a zip nor a tar archive")
edify/context.py ADDED
@@ -0,0 +1,57 @@
1
+ """What every command receives.
2
+
3
+ One object: where the repository is, how to write output, and what this machine is
4
+ entitled to. Nothing here holds state between invocations — the CLI is a pure
5
+ function over files.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ from dataclasses import dataclass
12
+ from functools import cached_property
13
+ from typing import TYPE_CHECKING
14
+
15
+ from .graph.store import GraphStore
16
+ from .licensing.tier import Entitlement, current
17
+ from .paths import Layout, layout
18
+ from .ui import Out
19
+
20
+ if TYPE_CHECKING: # the interview is only ever loaded by the command that runs it
21
+ from .interview import Profile
22
+
23
+
24
+ @dataclass
25
+ class Context:
26
+ args: argparse.Namespace
27
+ layout: Layout
28
+ out: Out
29
+ # What the person answered when `edify init new` asked, or None when nobody was
30
+ # asked — which is every other command, and `init new` in a pipeline. Nothing
31
+ # reads this without checking, because a question is never load-bearing.
32
+ profile: "Profile | None" = None
33
+
34
+ @cached_property
35
+ def entitlement(self) -> Entitlement:
36
+ return current()
37
+
38
+ @cached_property
39
+ def store(self) -> GraphStore:
40
+ return GraphStore(self.layout)
41
+
42
+ @property
43
+ def root(self):
44
+ return self.layout.root
45
+
46
+
47
+ def build_context(args: argparse.Namespace) -> Context:
48
+ return Context(
49
+ args=args,
50
+ layout=layout(getattr(args, "repo", None)),
51
+ out=Out(
52
+ json_mode=getattr(args, "json", False),
53
+ color=False if getattr(args, "no_color", False) else None,
54
+ quiet=getattr(args, "quiet", False),
55
+ anim=not getattr(args, "no_anim", False),
56
+ ),
57
+ )
edify/conventions.py ADDED
@@ -0,0 +1,275 @@
1
+ """The conventions scrape. A config read, not an analysis — zero model calls.
2
+
3
+ Every convention below is already stated in a file on disk: the lint config, the
4
+ formatter, the type-checker's strictness, the editor config, the test layout, the
5
+ commit convention, and the CI job's real commands. Reading them costs a few hundred
6
+ milliseconds and nothing else.
7
+
8
+ What a scrape cannot get — where fixtures live, which patterns are finished versus
9
+ legacy, the module nobody should touch — is covered by the task format's
10
+ `Follow the pattern at` pointer, which transfers a convention more reliably than a
11
+ paragraph describing it. That is why there is no discovery pass here.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import re
18
+ from pathlib import Path
19
+
20
+ from . import _toml as tomllib
21
+ from .detect import Stack
22
+
23
+ _LINTERS = {
24
+ ".eslintrc": "eslint",
25
+ ".eslintrc.js": "eslint",
26
+ ".eslintrc.cjs": "eslint",
27
+ ".eslintrc.json": "eslint",
28
+ ".eslintrc.yml": "eslint",
29
+ "eslint.config.js": "eslint (flat)",
30
+ "eslint.config.mjs": "eslint (flat)",
31
+ "biome.json": "biome",
32
+ ".rubocop.yml": "rubocop",
33
+ ".golangci.yml": "golangci-lint",
34
+ ".golangci.yaml": "golangci-lint",
35
+ "clippy.toml": "clippy",
36
+ ".flake8": "flake8",
37
+ "setup.cfg": "flake8/setup.cfg",
38
+ ".pylintrc": "pylint",
39
+ }
40
+
41
+ _FORMATTERS = {
42
+ ".prettierrc": "prettier",
43
+ ".prettierrc.json": "prettier",
44
+ ".prettierrc.js": "prettier",
45
+ "prettier.config.js": "prettier",
46
+ ".editorconfig": "editorconfig",
47
+ "rustfmt.toml": "rustfmt",
48
+ ".rustfmt.toml": "rustfmt",
49
+ }
50
+
51
+
52
+ def scrape(root: Path, stack: Stack) -> str:
53
+ """The `.edify/conventions.md` body. Roughly fifteen to twenty-five lines."""
54
+ lines: list[str] = ["# Conventions", ""]
55
+ lines.append(
56
+ "Scraped from the configuration files in this repository by `edify init`. "
57
+ "No model produced any line here. Regenerate with `edify init --force`."
58
+ )
59
+ lines.append("")
60
+
61
+ facts: list[tuple[str, str]] = []
62
+
63
+ facts.append(("Languages", ", ".join(stack.languages) or "none detected"))
64
+ if stack.frameworks:
65
+ facts.append(("Frameworks", ", ".join(stack.frameworks)))
66
+ facts.append(("Package manager", stack.package_manager))
67
+ facts.append(("Test runner", stack.test_runner))
68
+
69
+ linters = [name for f, name in _LINTERS.items() if (root / f).is_file()]
70
+ if linters:
71
+ facts.append(("Lint", ", ".join(sorted(set(linters)))))
72
+ formatters = [name for f, name in _FORMATTERS.items() if (root / f).is_file()]
73
+ if formatters:
74
+ facts.append(("Format", ", ".join(sorted(set(formatters)))))
75
+
76
+ ruff = _ruff(root)
77
+ if ruff:
78
+ facts.append(("Ruff", ruff))
79
+ ts = _typescript(root)
80
+ if ts:
81
+ facts.append(("TypeScript", ts))
82
+ mypy = _mypy(root)
83
+ if mypy:
84
+ facts.append(("Type checking", mypy))
85
+ indent = _editorconfig(root)
86
+ if indent:
87
+ facts.append(("Indent", indent))
88
+
89
+ layout = _test_layout(root)
90
+ if layout:
91
+ facts.append(("Tests live in", layout))
92
+ commit = _commit_convention(root)
93
+ if commit:
94
+ facts.append(("Commits", commit))
95
+
96
+ for label, value in facts:
97
+ lines.append(f"- **{label}**: {value}")
98
+
99
+ scripts = _scripts(root)
100
+ if scripts:
101
+ lines.append("")
102
+ lines.append("## Commands, as this repository actually invokes them")
103
+ lines.append("")
104
+ for name, command in scripts:
105
+ lines.append(f"- `{name}` → `{command}`")
106
+
107
+ ci = _ci_commands(root)
108
+ if ci:
109
+ lines.append("")
110
+ lines.append("## What CI runs")
111
+ lines.append("")
112
+ for command in ci:
113
+ lines.append(f"- `{command}`")
114
+
115
+ lines.append("")
116
+ lines.append(
117
+ "Anything not listed here was not stated in a config file. It is not missing "
118
+ "because nobody looked — it is missing because nothing on disk declares it."
119
+ )
120
+ lines.append("")
121
+ return "\n".join(lines)
122
+
123
+
124
+ # ---------------------------------------------------------------------------
125
+
126
+
127
+ def _ruff(root: Path) -> str | None:
128
+ data = _toml(root / "pyproject.toml")
129
+ ruff = (data.get("tool") or {}).get("ruff") or {}
130
+ if not ruff and (root / "ruff.toml").is_file():
131
+ ruff = _toml(root / "ruff.toml")
132
+ if not ruff:
133
+ return None
134
+ bits = []
135
+ if ruff.get("line-length"):
136
+ bits.append(f"line length {ruff['line-length']}")
137
+ select = (ruff.get("lint") or {}).get("select") or ruff.get("select")
138
+ if select:
139
+ bits.append("rules " + ",".join(str(s) for s in select[:8]))
140
+ return "; ".join(bits) or "configured"
141
+
142
+
143
+ def _typescript(root: Path) -> str | None:
144
+ path = root / "tsconfig.json"
145
+ if not path.is_file():
146
+ return None
147
+ data = _jsonc(path)
148
+ opts = data.get("compilerOptions") or {}
149
+ bits = []
150
+ bits.append("strict on" if opts.get("strict") else "strict off")
151
+ if opts.get("target"):
152
+ bits.append(f"target {opts['target']}")
153
+ if opts.get("noUncheckedIndexedAccess"):
154
+ bits.append("noUncheckedIndexedAccess")
155
+ return ", ".join(bits)
156
+
157
+
158
+ def _mypy(root: Path) -> str | None:
159
+ data = _toml(root / "pyproject.toml")
160
+ mypy = (data.get("tool") or {}).get("mypy") or {}
161
+ if mypy:
162
+ return "mypy strict" if mypy.get("strict") else "mypy"
163
+ if (root / "mypy.ini").is_file():
164
+ return "mypy"
165
+ if (root / ".mypy.ini").is_file():
166
+ return "mypy"
167
+ return None
168
+
169
+
170
+ def _editorconfig(root: Path) -> str | None:
171
+ path = root / ".editorconfig"
172
+ if not path.is_file():
173
+ return None
174
+ style = size = None
175
+ for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
176
+ m = re.match(r"\s*indent_style\s*=\s*(\w+)", line)
177
+ if m and style is None:
178
+ style = m.group(1)
179
+ m = re.match(r"\s*indent_size\s*=\s*(\w+)", line)
180
+ if m and size is None:
181
+ size = m.group(1)
182
+ if not style and not size:
183
+ return None
184
+ return f"{style or 'unspecified'} {size or ''}".strip()
185
+
186
+
187
+ def _test_layout(root: Path) -> str | None:
188
+ candidates = []
189
+ for name in ("tests", "test", "spec", "__tests__", "src/test", "e2e"):
190
+ if (root / name).is_dir():
191
+ candidates.append(f"{name}/")
192
+ colocated = list(root.glob("src/**/*.test.*"))[:1] or list(root.glob("src/**/*_test.go"))[:1]
193
+ if colocated:
194
+ candidates.append("beside the code they test")
195
+ return ", ".join(candidates) if candidates else None
196
+
197
+
198
+ def _commit_convention(root: Path) -> str | None:
199
+ for name in ("commitlint.config.js", ".commitlintrc", ".commitlintrc.json"):
200
+ if (root / name).is_file():
201
+ return "conventional commits (commitlint configured)"
202
+ if (root / ".gitmessage").is_file():
203
+ return "template in .gitmessage"
204
+ return None
205
+
206
+
207
+ def _scripts(root: Path) -> list[tuple[str, str]]:
208
+ """The build, test, lint and typecheck commands, exactly as declared."""
209
+ wanted = ("build", "test", "lint", "typecheck", "type-check", "check", "dev", "start")
210
+ out: list[tuple[str, str]] = []
211
+ pkg = root / "package.json"
212
+ if pkg.is_file():
213
+ scripts = (_jsonc(pkg).get("scripts") or {})
214
+ pm = _pm_prefix(root)
215
+ for name in wanted:
216
+ if name in scripts:
217
+ out.append((f"{pm} run {name}", str(scripts[name])))
218
+ makefile = root / "Makefile"
219
+ if makefile.is_file():
220
+ for line in makefile.read_text(encoding="utf-8", errors="replace").splitlines():
221
+ m = re.match(r"^([a-zA-Z][\w\-]*):\s*(?:[\w\- ]*)$", line)
222
+ if m and m.group(1) in wanted:
223
+ out.append((f"make {m.group(1)}", "see Makefile"))
224
+ return out[:10]
225
+
226
+
227
+ def _pm_prefix(root: Path) -> str:
228
+ for lockfile, pm in (("pnpm-lock.yaml", "pnpm"), ("yarn.lock", "yarn"), ("bun.lockb", "bun")):
229
+ if (root / lockfile).is_file():
230
+ return pm
231
+ return "npm"
232
+
233
+
234
+ def _ci_commands(root: Path) -> list[str]:
235
+ """The `run:` lines from CI workflows — the commands that actually gate a merge."""
236
+ out: list[str] = []
237
+ workflows = root / ".github" / "workflows"
238
+ if workflows.is_dir():
239
+ for path in sorted(workflows.glob("*.y*ml"))[:4]:
240
+ for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
241
+ m = re.match(r"\s*-?\s*run:\s*(.+)$", line)
242
+ if m:
243
+ command = m.group(1).strip().strip("|>").strip()
244
+ if command and command not in out and len(command) < 120:
245
+ out.append(command)
246
+ for name in (".gitlab-ci.yml", "Jenkinsfile", ".circleci/config.yml"):
247
+ path = root / name
248
+ if path.is_file():
249
+ out.append(f"declared in {name}")
250
+ return out[:12]
251
+
252
+
253
+ def _toml(path: Path) -> dict:
254
+ if not path.is_file():
255
+ return {}
256
+ try:
257
+ with path.open("rb") as fh:
258
+ return tomllib.load(fh)
259
+ except (OSError, tomllib.TOMLDecodeError):
260
+ return {}
261
+
262
+
263
+ def _jsonc(path: Path) -> dict:
264
+ """tsconfig.json is JSON with comments often enough to be worth handling."""
265
+ try:
266
+ text = path.read_text(encoding="utf-8", errors="replace")
267
+ except OSError:
268
+ return {}
269
+ text = re.sub(r"^\s*//.*$", "", text, flags=re.MULTILINE)
270
+ text = re.sub(r"/\*.*?\*/", "", text, flags=re.DOTALL)
271
+ text = re.sub(r",(\s*[}\]])", r"\1", text)
272
+ try:
273
+ return json.loads(text) or {}
274
+ except json.JSONDecodeError:
275
+ return {}