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/tsv.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Sorted, checksummed TSV.
|
|
2
|
+
|
|
3
|
+
Both graph files and the skill index are sorted text, so a rebuild over unchanged
|
|
4
|
+
input produces byte-identical output. That property is what makes "did the graph
|
|
5
|
+
change?" a comparison rather than an analysis, and it is why nothing here writes a
|
|
6
|
+
timestamp.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Iterable, Iterator, Sequence
|
|
14
|
+
|
|
15
|
+
_ESCAPES = {"\t": "\\t", "\n": "\\n", "\r": "\\r", "\\": "\\\\"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def escape(value: str) -> str:
|
|
19
|
+
"""Make a field safe for a tab-separated line, reversibly."""
|
|
20
|
+
out = []
|
|
21
|
+
for ch in str(value):
|
|
22
|
+
if ch == "\\":
|
|
23
|
+
out.append("\\\\")
|
|
24
|
+
elif ch == "\t":
|
|
25
|
+
out.append("\\t")
|
|
26
|
+
elif ch == "\n":
|
|
27
|
+
out.append("\\n")
|
|
28
|
+
elif ch == "\r":
|
|
29
|
+
out.append("\\r")
|
|
30
|
+
else:
|
|
31
|
+
out.append(ch)
|
|
32
|
+
return "".join(out)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def unescape(value: str) -> str:
|
|
36
|
+
out = []
|
|
37
|
+
i = 0
|
|
38
|
+
while i < len(value):
|
|
39
|
+
ch = value[i]
|
|
40
|
+
if ch == "\\" and i + 1 < len(value):
|
|
41
|
+
nxt = value[i + 1]
|
|
42
|
+
out.append({"t": "\t", "n": "\n", "r": "\r", "\\": "\\"}.get(nxt, nxt))
|
|
43
|
+
i += 2
|
|
44
|
+
continue
|
|
45
|
+
out.append(ch)
|
|
46
|
+
i += 1
|
|
47
|
+
return "".join(out)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def write_rows(path: Path, rows: Iterable[Sequence[str]], header: Sequence[str] | None = None) -> str:
|
|
51
|
+
"""Write rows sorted, LF-terminated, and return the file's sha256.
|
|
52
|
+
|
|
53
|
+
Sorting is on the rendered line, so the ordering is a property of the bytes
|
|
54
|
+
rather than of whatever object produced them.
|
|
55
|
+
"""
|
|
56
|
+
lines = sorted("\t".join(escape(c) for c in row) for row in rows)
|
|
57
|
+
body = ""
|
|
58
|
+
if header:
|
|
59
|
+
body += "#" + "\t".join(header) + "\n"
|
|
60
|
+
body += "".join(line + "\n" for line in lines)
|
|
61
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
path.write_bytes(body.encode("utf-8"))
|
|
63
|
+
return hashlib.sha256(body.encode("utf-8")).hexdigest()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def read_rows(path: Path) -> Iterator[list[str]]:
|
|
67
|
+
"""Stream a TSV, skipping the comment header. Never loads the whole file."""
|
|
68
|
+
if not path.exists():
|
|
69
|
+
return
|
|
70
|
+
with path.open("r", encoding="utf-8", errors="replace") as fh:
|
|
71
|
+
for line in fh:
|
|
72
|
+
line = line.rstrip("\n").rstrip("\r")
|
|
73
|
+
if not line or line.startswith("#"):
|
|
74
|
+
continue
|
|
75
|
+
yield [unescape(c) for c in line.split("\t")]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def sha256_bytes(data: bytes) -> str:
|
|
79
|
+
return hashlib.sha256(data).hexdigest()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def sha256_file(path: Path) -> str:
|
|
83
|
+
if not path.exists():
|
|
84
|
+
return "-"
|
|
85
|
+
h = hashlib.sha256()
|
|
86
|
+
with path.open("rb") as fh:
|
|
87
|
+
for chunk in iter(lambda: fh.read(65536), b""):
|
|
88
|
+
h.update(chunk)
|
|
89
|
+
return h.hexdigest()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def read_kv(path: Path) -> dict[str, str]:
|
|
93
|
+
"""The `meta` file: one `key=value` per line, no nesting, no timestamps."""
|
|
94
|
+
out: dict[str, str] = {}
|
|
95
|
+
if not path.exists():
|
|
96
|
+
return out
|
|
97
|
+
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
98
|
+
line = line.strip()
|
|
99
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
100
|
+
continue
|
|
101
|
+
key, _, value = line.partition("=")
|
|
102
|
+
out[key.strip()] = value.strip()
|
|
103
|
+
return out
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def write_kv(path: Path, values: dict[str, str]) -> None:
|
|
107
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
108
|
+
body = "".join(f"{k}={v}\n" for k, v in sorted(values.items()))
|
|
109
|
+
path.write_bytes(body.encode("utf-8"))
|
edify/ui.py
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"""Output. One place, so `--json` and `--no-color` are honoured everywhere.
|
|
2
|
+
|
|
3
|
+
Every command writes through here. Machine output goes to stdout as JSON when
|
|
4
|
+
`--json` is set; human notes and warnings go to stderr so a pipe stays clean.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
RESET = "\033[0m"
|
|
15
|
+
|
|
16
|
+
#: The site's tokens (`--ed-*` in the public site's DESIGN-TOKENS.md), as a
|
|
17
|
+
#: terminal can show them. Two sets, because the clips already come in two —
|
|
18
|
+
#: FOIL / NIGHT and FOIL / DAY — and a light terminal is a real place people read
|
|
19
|
+
#: this. Body text is never coloured: the terminal's own foreground is the one
|
|
20
|
+
#: colour guaranteed to read on the terminal's own background.
|
|
21
|
+
PALETTES = {
|
|
22
|
+
"night": {
|
|
23
|
+
"signal": "#7ABDFF", # --ed-blue-bright: a pass, the next step
|
|
24
|
+
"edge": "#2C6FD6", # --ed-blue: the ink
|
|
25
|
+
"advisory": "#F2A359", # --ed-amber-bright: works, degraded
|
|
26
|
+
"blocked": "#EA6B62", # --ed-oxide-bright: does not work
|
|
27
|
+
"muted": "#6A6D71", # --ed-text-3 over the void: notes, labels
|
|
28
|
+
"faint": "#4F5256", # --ed-text-4: hairlines, the curve at rest
|
|
29
|
+
},
|
|
30
|
+
"day": {
|
|
31
|
+
"signal": "#2C6FD6", # --ed-blue holds 4.9:1 on paper
|
|
32
|
+
"edge": "#0C3965", # --ed-blue-deep
|
|
33
|
+
"advisory": "#A8621C", # amber, darkened until it reads on paper
|
|
34
|
+
"blocked": "#C74B45", # --ed-oxide
|
|
35
|
+
"muted": "#6B6D72", # --ed-ink-3
|
|
36
|
+
"faint": "#A3A5AA",
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#: What a 16-colour terminal gets for each token.
|
|
41
|
+
_BASIC = {
|
|
42
|
+
"signal": "94", "edge": "34", "advisory": "33", "blocked": "31",
|
|
43
|
+
"muted": "2", "faint": "2",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#: The names call sites used before the palette existed. The brand's pass is blue,
|
|
47
|
+
#: not green: `[x] pass` on the site is the enforced blue.
|
|
48
|
+
_ALIASES = {
|
|
49
|
+
"green": "signal", "blue": "signal", "cyan": "signal",
|
|
50
|
+
"yellow": "advisory", "red": "blocked", "dim": "muted",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#: The site's state device, verbatim. ASCII, so no code page can break it.
|
|
54
|
+
MARKS = {"pass": "[x]", "advisory": "[!]", "blocked": "[-]", "uncovered": "[ ]"}
|
|
55
|
+
|
|
56
|
+
#: The label column of a report: wide enough for `conventions`, the longest one.
|
|
57
|
+
LABEL_WIDTH = 11
|
|
58
|
+
|
|
59
|
+
_TRUECOLOR_PROGRAMS =("vscode", "iTerm.app", "WezTerm", "ghostty")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def depth() -> int:
|
|
63
|
+
"""24, 256 or 16. Asked of the environment, because a terminal cannot be asked."""
|
|
64
|
+
if os.environ.get("COLORTERM", "").lower() in ("truecolor", "24bit"):
|
|
65
|
+
return 24
|
|
66
|
+
if os.environ.get("WT_SESSION") or os.environ.get("TERM_PROGRAM") in _TRUECOLOR_PROGRAMS:
|
|
67
|
+
return 24
|
|
68
|
+
if "256" in os.environ.get("TERM", "") or os.environ.get("TERM_PROGRAM") == "Apple_Terminal":
|
|
69
|
+
return 256
|
|
70
|
+
return 16
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def theme() -> str:
|
|
74
|
+
"""`night` unless told otherwise. `COLORFGBG` is `fg;bg`, and a bg of 7 or 15
|
|
75
|
+
is a light terminal; `EDIFY_THEME=day|night` overrides both."""
|
|
76
|
+
chosen = os.environ.get("EDIFY_THEME", "").lower()
|
|
77
|
+
if chosen in PALETTES:
|
|
78
|
+
return chosen
|
|
79
|
+
bg = os.environ.get("COLORFGBG", "").split(";")[-1]
|
|
80
|
+
return "day" if bg in ("7", "15") else "night"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def rgb(hexcode: str) -> tuple[int, int, int]:
|
|
84
|
+
return int(hexcode[1:3], 16), int(hexcode[3:5], 16), int(hexcode[5:7], 16)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _xterm256(colour: tuple[int, int, int]) -> int:
|
|
88
|
+
"""The nearest cell of the xterm 6x6x6 cube."""
|
|
89
|
+
steps = (0, 95, 135, 175, 215, 255)
|
|
90
|
+
index = [min(range(6), key=lambda i: abs(steps[i] - v)) for v in colour]
|
|
91
|
+
return 16 + 36 * index[0] + 6 * index[1] + index[2]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def fg(colour: tuple[int, int, int], bits: int | None = None) -> str:
|
|
95
|
+
"""The foreground escape for an exact colour, at whatever depth is available."""
|
|
96
|
+
bits = bits or depth()
|
|
97
|
+
if bits == 24:
|
|
98
|
+
return "\033[38;2;{};{};{}m".format(*colour)
|
|
99
|
+
return f"\033[38;5;{_xterm256(colour)}m"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def sgr(style: str) -> str:
|
|
103
|
+
"""The escape that starts `style`, or `""` for a name nobody defined."""
|
|
104
|
+
style = _ALIASES.get(style, style)
|
|
105
|
+
if style == "bold":
|
|
106
|
+
return "\033[1m"
|
|
107
|
+
palette = PALETTES[theme()]
|
|
108
|
+
if style not in palette:
|
|
109
|
+
return ""
|
|
110
|
+
bits = depth()
|
|
111
|
+
if bits == 16:
|
|
112
|
+
return f"\033[{_BASIC[style]}m"
|
|
113
|
+
return fg(rgb(palette[style]), bits)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def encodes(text: str, stream: Any = None) -> bool:
|
|
117
|
+
"""Whether `stream` can print `text` — the same probe `anim.frames_for` makes."""
|
|
118
|
+
stream = stream if stream is not None else sys.stdout
|
|
119
|
+
encoding = getattr(stream, "encoding", None)
|
|
120
|
+
if not encoding:
|
|
121
|
+
return False
|
|
122
|
+
try:
|
|
123
|
+
text.encode(encoding)
|
|
124
|
+
except (UnicodeEncodeError, LookupError, TypeError):
|
|
125
|
+
return False
|
|
126
|
+
return True
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _emit(text: str, stream: Any = None) -> None:
|
|
130
|
+
"""One `print`, for every channel, that a cp1252 console cannot kill.
|
|
131
|
+
|
|
132
|
+
Windows consoles still default to a code page that has no `→` and no `·`, and
|
|
133
|
+
a command that did its work and then died writing the sentence about it is the
|
|
134
|
+
worst of both outcomes — the ledger is saved, the exit code says failure. So an
|
|
135
|
+
unencodable character degrades to a replacement rather than a traceback.
|
|
136
|
+
"""
|
|
137
|
+
stream = stream if stream is not None else sys.stdout
|
|
138
|
+
try:
|
|
139
|
+
print(text, file=stream)
|
|
140
|
+
except UnicodeEncodeError:
|
|
141
|
+
encoding = getattr(stream, "encoding", None) or "ascii"
|
|
142
|
+
print(text.encode(encoding, "replace").decode(encoding, "replace"), file=stream)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _colour_stream(stream: Any) -> bool:
|
|
146
|
+
"""A terminal on `stream`, and nothing in the environment refusing colour."""
|
|
147
|
+
try:
|
|
148
|
+
tty = bool(stream.isatty())
|
|
149
|
+
except (AttributeError, ValueError): # a replaced or closed stream
|
|
150
|
+
return False
|
|
151
|
+
return tty and os.environ.get("NO_COLOR") is None and os.environ.get("TERM") != "dumb"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _has_terminal() -> bool:
|
|
155
|
+
"""A person at both ends of this invocation. The one place that is decided."""
|
|
156
|
+
try:
|
|
157
|
+
return bool(sys.stdin.isatty()) and bool(sys.stderr.isatty())
|
|
158
|
+
except (AttributeError, ValueError): # a replaced stdin, a closed stream
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class Out:
|
|
163
|
+
"""The output channel for one command invocation."""
|
|
164
|
+
|
|
165
|
+
def __init__(
|
|
166
|
+
self,
|
|
167
|
+
json_mode: bool = False,
|
|
168
|
+
color: bool | None = None,
|
|
169
|
+
quiet: bool = False,
|
|
170
|
+
anim: bool = True,
|
|
171
|
+
):
|
|
172
|
+
self.json_mode = json_mode
|
|
173
|
+
self.quiet = quiet
|
|
174
|
+
# `--no-anim`. Kept as its own attribute rather than folded into `animated`
|
|
175
|
+
# so `anim.banner` — which survives a pipe and a CI log, and so cannot ask
|
|
176
|
+
# `animated` — has something to read.
|
|
177
|
+
self.no_anim = not anim
|
|
178
|
+
# stderr is asked separately: the wordmark and the infinity paint there, and
|
|
179
|
+
# `edify init > log.txt` has a terminal on stderr that should still get ink.
|
|
180
|
+
# `--no-color` (an explicit False) turns off both.
|
|
181
|
+
self.color_err = color is not False and not json_mode and _colour_stream(sys.stderr)
|
|
182
|
+
if color is None:
|
|
183
|
+
color = _colour_stream(sys.stdout)
|
|
184
|
+
self.color = bool(color) and not json_mode
|
|
185
|
+
|
|
186
|
+
# -- styling ---------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
def c(self, text: str, style: str) -> str:
|
|
189
|
+
if not self.color:
|
|
190
|
+
return text
|
|
191
|
+
start = sgr(style)
|
|
192
|
+
return f"{start}{text}{RESET}" if start else text
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def fancy(self) -> bool:
|
|
196
|
+
"""Colour on, and a stdout that can print a hairline. Only then do rules
|
|
197
|
+
become `─` and states carry the site's marks; a pipe keeps plain ASCII."""
|
|
198
|
+
return self.color and encodes("─·")
|
|
199
|
+
|
|
200
|
+
def state(self, word: str, kind: str, width: int = 0) -> str:
|
|
201
|
+
"""A state word as the site sets it: `[x] ok`, `[!] degraded`, `[-] broken`.
|
|
202
|
+
|
|
203
|
+
The mark only at a terminal, so what a pipe or a script reads is unchanged.
|
|
204
|
+
`kind` is a key of `MARKS`.
|
|
205
|
+
"""
|
|
206
|
+
style = {"pass": "signal", "uncovered": "faint"}.get(kind, kind)
|
|
207
|
+
padded = word.ljust(width)
|
|
208
|
+
if not self.fancy:
|
|
209
|
+
return self.c(padded, style)
|
|
210
|
+
return f"{self.c(MARKS[kind], style)} {self.c(padded, style)}"
|
|
211
|
+
|
|
212
|
+
def rule(self, width: int) -> str:
|
|
213
|
+
"""A hairline: the only separator the identity allows."""
|
|
214
|
+
return self.c(("─" if self.fancy else "-") * width, "faint")
|
|
215
|
+
|
|
216
|
+
# -- channels --------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
def line(self, text: str = "") -> None:
|
|
219
|
+
"""A line of the command's actual answer. Suppressed in JSON mode."""
|
|
220
|
+
if self.json_mode or self.quiet:
|
|
221
|
+
return
|
|
222
|
+
_emit(text)
|
|
223
|
+
|
|
224
|
+
def note(self, text: str) -> None:
|
|
225
|
+
"""Context for a human. Never part of the answer, so it goes to stderr."""
|
|
226
|
+
if self.quiet:
|
|
227
|
+
return
|
|
228
|
+
_emit(self.c(text, "dim"), sys.stderr)
|
|
229
|
+
|
|
230
|
+
def warn(self, text: str) -> None:
|
|
231
|
+
_emit(f"{self.state('warning', 'advisory')} {text}", sys.stderr)
|
|
232
|
+
|
|
233
|
+
def error(self, text: str, hint: str | None = None) -> None:
|
|
234
|
+
_emit(f"{self.state('error', 'blocked')} {text}", sys.stderr)
|
|
235
|
+
if hint:
|
|
236
|
+
_emit(f" {self.c(hint, 'dim')}", sys.stderr)
|
|
237
|
+
|
|
238
|
+
def ok(self, text: str) -> None:
|
|
239
|
+
if self.quiet:
|
|
240
|
+
return
|
|
241
|
+
_emit(f"{self.state('ok', 'pass')} {text}", sys.stderr)
|
|
242
|
+
|
|
243
|
+
def field(self, label: str, value: str) -> None:
|
|
244
|
+
"""One line of a report: the label as a readout, the value in plain ink."""
|
|
245
|
+
self.line(f"{self.c(label.ljust(LABEL_WIDTH), 'muted')} {value}")
|
|
246
|
+
|
|
247
|
+
def next(self, text: str) -> None:
|
|
248
|
+
"""The step after this one. The site's boot log ends on it, in blue."""
|
|
249
|
+
self.line(self.c(text, "signal"))
|
|
250
|
+
|
|
251
|
+
def data(self, payload: Any) -> None:
|
|
252
|
+
"""The machine-readable form of the answer. Only emitted in JSON mode."""
|
|
253
|
+
if not self.json_mode:
|
|
254
|
+
return
|
|
255
|
+
_emit(json.dumps(payload, indent=2, sort_keys=True, default=str))
|
|
256
|
+
|
|
257
|
+
# -- asking ----------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
@property
|
|
260
|
+
def interactive(self) -> bool:
|
|
261
|
+
"""Whether this invocation is allowed to ask a person a question.
|
|
262
|
+
|
|
263
|
+
A prompt that appears inside a pipeline, a CI job, or a model's tool call is
|
|
264
|
+
a hang rather than a question. So it takes a terminal at both ends, human
|
|
265
|
+
output, and nothing in the environment saying otherwise. Every caller has a
|
|
266
|
+
defined answer for when this is false — a question is never load-bearing.
|
|
267
|
+
"""
|
|
268
|
+
if self.json_mode or self.quiet:
|
|
269
|
+
return False
|
|
270
|
+
if os.environ.get("EDIFY_ASSUME_YES") or os.environ.get("EDIFY_NO_PROMPT") or os.environ.get("CI"):
|
|
271
|
+
return False
|
|
272
|
+
return _has_terminal()
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def animated(self) -> bool:
|
|
276
|
+
"""Whether this invocation is allowed to paint over its own output.
|
|
277
|
+
|
|
278
|
+
The one place tty, `--json`, `--quiet`, `--no-anim`, `EDIFY_NO_ANIM`, `CI`
|
|
279
|
+
and `TERM=dumb` are decided, so no call site invents its own rule and the
|
|
280
|
+
two disagree. Sitting beside `interactive` on purpose: both answer "is
|
|
281
|
+
there a person watching this happen, right now?".
|
|
282
|
+
|
|
283
|
+
stderr specifically, because that is where the animation paints. A piped
|
|
284
|
+
stdout with a terminal on stderr still animates, which is what somebody
|
|
285
|
+
running `edify graph build > out.txt` wants to see.
|
|
286
|
+
"""
|
|
287
|
+
if self.json_mode or self.quiet or self.no_anim:
|
|
288
|
+
return False
|
|
289
|
+
if os.environ.get("EDIFY_NO_ANIM") or os.environ.get("CI"):
|
|
290
|
+
return False
|
|
291
|
+
if os.environ.get("TERM") == "dumb":
|
|
292
|
+
return False
|
|
293
|
+
try:
|
|
294
|
+
return bool(sys.stderr.isatty())
|
|
295
|
+
except (AttributeError, ValueError): # a replaced or closed stream
|
|
296
|
+
return False
|
|
297
|
+
|
|
298
|
+
def prompt_line(self, text: str = "") -> None:
|
|
299
|
+
"""Part of a question — a menu row, a heading. Never part of the answer."""
|
|
300
|
+
if self.json_mode or self.quiet:
|
|
301
|
+
return
|
|
302
|
+
_emit(text, sys.stderr)
|
|
303
|
+
|
|
304
|
+
def ask(self, question: str, default: str = "") -> str:
|
|
305
|
+
"""One line of input, on stderr so a pipe on stdout stays clean."""
|
|
306
|
+
if not self.interactive:
|
|
307
|
+
return default
|
|
308
|
+
suffix = f" [{default}]" if default else ""
|
|
309
|
+
print(f"{self.c(question, 'bold')}{suffix} ", end="", file=sys.stderr, flush=True)
|
|
310
|
+
try:
|
|
311
|
+
answer = input().strip()
|
|
312
|
+
except (EOFError, KeyboardInterrupt):
|
|
313
|
+
print(file=sys.stderr)
|
|
314
|
+
return default
|
|
315
|
+
return answer or default
|
|
316
|
+
|
|
317
|
+
# -- tables ----------------------------------------------------------
|
|
318
|
+
|
|
319
|
+
def table(self, headers: list[str], rows: list[list[str]]) -> None:
|
|
320
|
+
"""A plain aligned table. No box drawing — it has to survive a pipe."""
|
|
321
|
+
if self.json_mode or self.quiet:
|
|
322
|
+
return
|
|
323
|
+
if not rows:
|
|
324
|
+
return
|
|
325
|
+
widths = [len(h) for h in headers]
|
|
326
|
+
for row in rows:
|
|
327
|
+
for i, cell in enumerate(row):
|
|
328
|
+
if i < len(widths):
|
|
329
|
+
widths[i] = max(widths[i], len(str(cell)))
|
|
330
|
+
head = " ".join(h.ljust(widths[i]) for i, h in enumerate(headers))
|
|
331
|
+
_emit(self.c(head, "muted" if self.fancy else "bold"))
|
|
332
|
+
_emit(" ".join(self.rule(w) for w in widths))
|
|
333
|
+
for row in rows:
|
|
334
|
+
_emit(" ".join(str(c).ljust(widths[i]) for i, c in enumerate(row)))
|