@krysoworks/kryso 0.0.2 → 2.0.0-rc.1

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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -6
  3. package/bin/kryso +31 -0
  4. package/bin/ship-it-status +14 -0
  5. package/bin/ship-ledger +14 -0
  6. package/bin/ship-loop +14 -0
  7. package/bin/ship-pass +14 -0
  8. package/bin/warden +14 -0
  9. package/dist/answer.d.ts +38 -0
  10. package/dist/answer.js +48 -0
  11. package/dist/bytes.d.ts +5 -0
  12. package/dist/bytes.js +35 -0
  13. package/dist/cleanup.d.ts +1 -0
  14. package/dist/cleanup.js +629 -0
  15. package/dist/commands.d.ts +48 -0
  16. package/dist/commands.js +293 -0
  17. package/dist/completions.d.ts +24 -0
  18. package/dist/completions.js +239 -0
  19. package/dist/daemon.d.ts +15 -0
  20. package/dist/daemon.js +23 -0
  21. package/dist/diagnose.d.ts +47 -0
  22. package/dist/diagnose.js +314 -0
  23. package/dist/doctor.d.ts +1 -0
  24. package/dist/doctor.js +241 -0
  25. package/dist/env.d.ts +9 -0
  26. package/dist/env.js +17 -0
  27. package/dist/evidence.d.ts +39 -0
  28. package/dist/evidence.js +327 -0
  29. package/dist/home.d.ts +3 -0
  30. package/dist/home.js +27 -0
  31. package/dist/install.d.ts +59 -0
  32. package/dist/install.js +137 -0
  33. package/dist/isolate.d.ts +28 -0
  34. package/dist/isolate.js +402 -0
  35. package/dist/leftovers.d.ts +5 -0
  36. package/dist/leftovers.js +156 -0
  37. package/dist/machine.d.ts +6 -0
  38. package/dist/machine.js +185 -0
  39. package/dist/palette.d.ts +147 -0
  40. package/dist/palette.js +167 -0
  41. package/dist/plan.d.ts +1 -0
  42. package/dist/plan.js +133 -0
  43. package/dist/proc.d.ts +23 -0
  44. package/dist/proc.js +23 -0
  45. package/dist/read.d.ts +1 -0
  46. package/dist/read.js +297 -0
  47. package/dist/readiness.d.ts +5 -0
  48. package/dist/readiness.js +64 -0
  49. package/dist/remote.d.ts +6 -0
  50. package/dist/remote.js +85 -0
  51. package/dist/self-update.d.ts +1 -0
  52. package/dist/self-update.js +224 -0
  53. package/dist/semver.d.ts +7 -0
  54. package/dist/semver.js +42 -0
  55. package/dist/style.d.ts +71 -0
  56. package/dist/style.js +187 -0
  57. package/dist/update.d.ts +47 -0
  58. package/dist/update.js +190 -0
  59. package/dist/work.d.ts +25 -0
  60. package/dist/work.js +449 -0
  61. package/dist/workflows.d.ts +4 -0
  62. package/dist/workflows.js +73 -0
  63. package/docker/entrypoint.sh +44 -0
  64. package/docker/runner.Dockerfile +39 -0
  65. package/package.json +55 -22
  66. package/scripts/install-skills.sh +607 -0
  67. package/skills/code-review/SKILL.md +231 -0
  68. package/skills/kryso/SKILL.md +107 -0
  69. package/skills/kryso/golden/help.rounded.ansi +23 -0
  70. package/skills/kryso/golden/help.square.ansi +23 -0
  71. package/skills/kryso/golden/help.txt +23 -0
  72. package/skills/kryso/golden/table-narrow.json +11 -0
  73. package/skills/kryso/golden/table-narrow.rounded.ansi +4 -0
  74. package/skills/kryso/golden/table-narrow.square.ansi +4 -0
  75. package/skills/kryso/golden/table.ansi +5 -0
  76. package/skills/kryso/golden/table.json +11 -0
  77. package/skills/kryso/ledger.sh +2146 -0
  78. package/skills/kryso/palette.json +57 -0
  79. package/skills/kryso/reference/resuming.md +30 -0
  80. package/skills/kryso/reference/routing.md +23 -0
  81. package/skills/kryso/reference/stage-1-claim.md +79 -0
  82. package/skills/kryso/reference/stage-2-build.md +133 -0
  83. package/skills/kryso/reference/stage-3-prove.md +51 -0
  84. package/skills/kryso/reference/stage-4-pr.md +76 -0
  85. package/skills/kryso/reference/stage-5-reconcile.md +81 -0
  86. package/skills/kryso/reference/stage-6-merge-or-park.md +73 -0
  87. package/skills/kryso/reference/stage-7-close-out.md +62 -0
  88. package/skills/kryso/reference/terminal.md +7 -0
  89. package/skills/kryso/ship-it-status.sh +1503 -0
  90. package/skills/kryso/ui.py +274 -0
  91. package/skills/kryso/ui.sh +609 -0
  92. package/skills/kryso-build/SKILL.md +168 -0
  93. package/skills/kryso-shift/SKILL.md +167 -0
  94. package/skills/kryso-shift/archive.py +2784 -0
  95. package/skills/kryso-shift/archive_checker.py +462 -0
  96. package/skills/kryso-shift/archive_checker_lambda.py +155 -0
  97. package/skills/kryso-shift/archive_health.py +364 -0
  98. package/skills/kryso-shift/archive_launchd.py +140 -0
  99. package/skills/kryso-shift/archive_remote.py +990 -0
  100. package/skills/kryso-shift/archiving-checker.md +140 -0
  101. package/skills/kryso-shift/archiving-keep.md +115 -0
  102. package/skills/kryso-shift/archiving-recovery.md +112 -0
  103. package/skills/kryso-shift/archiving-remote.md +166 -0
  104. package/skills/kryso-shift/archiving.md +146 -0
  105. package/skills/kryso-shift/coverage.schema.json +225 -0
  106. package/skills/kryso-shift/deadline.sh +254 -0
  107. package/skills/kryso-shift/feedback.schema.json +35 -0
  108. package/skills/kryso-shift/feedback.sh +228 -0
  109. package/skills/kryso-shift/history-manifest.schema.json +331 -0
  110. package/skills/kryso-shift/keep-after.sh +55 -0
  111. package/skills/kryso-shift/measure.sh +611 -0
  112. package/skills/kryso-shift/merge-ready.sh +207 -0
  113. package/skills/kryso-shift/outcome.schema.json +16 -0
  114. package/skills/kryso-shift/pass-rules.md +8 -0
  115. package/skills/kryso-shift/profile.schema.json +42 -0
  116. package/skills/kryso-shift/reader.sh +692 -0
  117. package/skills/kryso-shift/reads.sh +151 -0
  118. package/skills/kryso-shift/reference/allowance.md +21 -0
  119. package/skills/kryso-shift/reference/driver.md +95 -0
  120. package/skills/kryso-shift/reference/measuring.md +67 -0
  121. package/skills/kryso-shift/reference/outputs.md +21 -0
  122. package/skills/kryso-shift/reference/pass-script.md +115 -0
  123. package/skills/kryso-shift/reference/reconcile-and-merge.md +55 -0
  124. package/skills/kryso-shift/reference/second-reader.md +9 -0
  125. package/skills/kryso-shift/reference/sweeps.md +83 -0
  126. package/skills/kryso-shift/repair.schema.json +14 -0
  127. package/skills/kryso-shift/report-template.html +679 -0
  128. package/skills/kryso-shift/report.py +389 -0
  129. package/skills/kryso-shift/report_fixture.py +65 -0
  130. package/skills/kryso-shift/reporting.md +58 -0
  131. package/skills/kryso-shift/result.sh +91 -0
  132. package/skills/kryso-shift/runner.sh +1178 -0
  133. package/skills/kryso-shift/ship-loop.sh +3977 -0
  134. package/skills/kryso-shift/ship-pass.sh +4987 -0
  135. package/skills/kryso-shift/steps.jq +19 -0
  136. package/skills/kryso-shift/workflow.mjs +830 -0
  137. package/skills/kryso-shift/workflows/default.json +22 -0
  138. package/skills/kryso-shift/workflows/ralph.json +13 -0
  139. package/skills/kryso-watch/SKILL.md +100 -0
  140. package/skills/kryso-watch/answer.schema.json +23 -0
  141. package/skills/kryso-watch/base-refs.sh +44 -0
  142. package/skills/kryso-watch/board.sh +58 -0
  143. package/skills/kryso-watch/reference/config.md +23 -0
  144. package/skills/kryso-watch/reference/outputs.md +30 -0
  145. package/skills/kryso-watch/reference/report.md +29 -0
  146. package/skills/kryso-watch/reference/scheduler.md +32 -0
  147. package/skills/kryso-watch/reference/settlement.md +29 -0
  148. package/skills/kryso-watch/reference/shift.md +44 -0
  149. package/skills/kryso-watch/reference/shim-limits.md +22 -0
  150. package/skills/kryso-watch/reference/triage.md +26 -0
  151. package/skills/kryso-watch/schema.jq +40 -0
  152. package/skills/kryso-watch/settle.schema.json +36 -0
  153. package/skills/kryso-watch/stage-common.sh +187 -0
  154. package/skills/kryso-watch/stages/report.sh +525 -0
  155. package/skills/kryso-watch/stages/settle.sh +722 -0
  156. package/skills/kryso-watch/stages/shift.sh +466 -0
  157. package/skills/kryso-watch/stages/triage.sh +379 -0
  158. package/skills/kryso-watch/tracker.sh +27 -0
  159. package/skills/kryso-watch/triage.schema.json +77 -0
  160. package/skills/kryso-watch/warden.launchd.plist +50 -0
  161. package/skills/kryso-watch/warden.schema.json +98 -0
  162. package/skills/kryso-watch/warden.sh +1004 -0
  163. package/bin/kryso.js +0 -11
@@ -0,0 +1,274 @@
1
+ """ui.sh's pills and lines for kryso's Python commands, archive.py and report.py (ADR 0042).
2
+
3
+ Beside Style, the drawing, it holds what both commands draw with: styled() for a Style only on an
4
+ attended stream, say_error() and say_failed() for their stderr lines, and KrysoParser, the
5
+ argument parser whose help and usage errors are drawn.
6
+
7
+ It reads palette.json beside it, the one source of the colours, the pill ends and the marks, and
8
+ draws the bytes ui.sh draws for the same call: test-ui.sh checks the two against each other and
9
+ against the golden help. The attended check is ui.sh's: never under NO_COLOR, then always under
10
+ CLICOLOR_FORCE set to anything but 0, then only on a terminal. A pill is rounded with Nerd Font half
11
+ circles, or square with plain marks under KRYSO_PILLS=square. A colour is 24-bit when COLORTERM is
12
+ truecolor or 24bit, else the nearest xterm 256-colour code, worked out the way the palette's
13
+ generator works it out. Unattended, every call prints nothing and a tint is its text alone.
14
+ """
15
+
16
+ import argparse
17
+ import json
18
+ import os
19
+ import re
20
+ import shutil
21
+ import sys
22
+ from pathlib import Path
23
+
24
+ PALETTE = Path(__file__).resolve().parent / "palette.json"
25
+ ESC = "\x1b["
26
+ RESET = f"{ESC}0m"
27
+
28
+
29
+ def attended(stream, env=None):
30
+ env = os.environ if env is None else env
31
+ if env.get("NO_COLOR"):
32
+ return False
33
+ if env.get("CLICOLOR_FORCE") and env.get("CLICOLOR_FORCE") != "0":
34
+ return True
35
+ try:
36
+ return stream.isatty()
37
+ except (AttributeError, ValueError):
38
+ return False
39
+
40
+
41
+ def xterm(hex_colour):
42
+ """The xterm code from 16 to 255 nearest the colour, by distance in RGB, ties to the lower code."""
43
+ r, g, b = (int(hex_colour[i:i + 2], 16) for i in (0, 2, 4))
44
+ levels = (0, 95, 135, 175, 215, 255)
45
+ best, best_distance = 16, None
46
+ for code in range(16, 256):
47
+ if code < 232:
48
+ n = code - 16
49
+ c = (levels[n // 36], levels[(n // 6) % 6], levels[n % 6])
50
+ else:
51
+ v = 8 + 10 * (code - 232)
52
+ c = (v, v, v)
53
+ d = (c[0] - r) ** 2 + (c[1] - g) ** 2 + (c[2] - b) ** 2
54
+ if best_distance is None or d < best_distance:
55
+ best, best_distance = code, d
56
+ return best
57
+
58
+
59
+ def width(text):
60
+ """Characters, so a glyph takes one cell, as ui.sh counts them."""
61
+ return len(text)
62
+
63
+
64
+ class Style:
65
+ """The styled output for an out stream and an err stream, under an environment."""
66
+
67
+ def __init__(self, out=None, err=None, env=None, palette=PALETTE):
68
+ self.out = sys.stdout if out is None else out
69
+ self.err = sys.stderr if err is None else err
70
+ self.env = os.environ if env is None else env
71
+ self.on = attended(self.out, self.env)
72
+ self.p = json.loads(Path(palette).read_text())
73
+ self.truecolor = self.env.get("COLORTERM") in ("truecolor", "24bit")
74
+ self.square = self.env.get("KRYSO_PILLS") == "square"
75
+
76
+ def _sgr(self, layer, name):
77
+ hex_colour = self.p["colours"][name]
78
+ if self.truecolor:
79
+ return f"{layer};2;" + ";".join(str(int(hex_colour[i:i + 2], 16)) for i in (0, 2, 4))
80
+ return f"{layer};5;{xterm(hex_colour)}"
81
+
82
+ def _pill(self, colour, label):
83
+ ink = self._sgr(38, self.p["roles"]["pill-text"])
84
+ fill = self._sgr(48, colour)
85
+ if self.square:
86
+ return f"{ESC}1;{ink};{fill}m {label} {RESET}"
87
+ edge = self._sgr(38, colour)
88
+ ends = self.p["ends"]
89
+ return f"{ESC}{edge}m{ends['left']}{ESC}1;{ink};{fill}m{label}{ESC}0;{edge}m{ends['right']}{RESET}"
90
+
91
+ def _dim(self, text):
92
+ return f"{ESC}{self._sgr(38, self.p['roles']['dim'])}m{text}{RESET}"
93
+
94
+ def _write(self, stream, text):
95
+ stream.write(text)
96
+ stream.flush()
97
+
98
+ def brand(self, subcommand, summary=""):
99
+ """The kryso pill, the subcommand bold, the summary dim and ending at the last of COLUMNS."""
100
+ if not self.on:
101
+ return
102
+ head = f"{self._pill(self.p['roles']['brand'], 'kryso')} {ESC}1m{subcommand}{RESET}"
103
+ if not summary:
104
+ self._write(self.out, f"{head}\n")
105
+ return
106
+ columns = self.env.get("COLUMNS", "")
107
+ columns = int(columns) if re.fullmatch(r"[1-9][0-9]*", columns) else 80
108
+ left = width(f"kryso {subcommand}") + 2
109
+ gap = columns - left - width(summary)
110
+ if gap >= 2:
111
+ self._write(self.out, f"{head}{' ' * gap}{self._dim(summary)}\n")
112
+ else:
113
+ self._write(self.out, f"{head}\n{' ' * max(columns - width(summary), 0)}{self._dim(summary)}\n")
114
+
115
+ def pill(self, kind, label):
116
+ if self.on:
117
+ self._write(self.out, f"{self._pill(self.p['pills'][kind], label)}\n")
118
+
119
+ def section(self, kind, label, note=""):
120
+ """A blank line, then the pill, the note dim after it."""
121
+ if self.on:
122
+ self._write(self.out, f"\n{self._pill(self.p['pills'][kind], label)}{' ' + self._dim(note) if note else ''}\n")
123
+
124
+ def _line(self, mark, message):
125
+ if not self.on:
126
+ return
127
+ m = self.p["marks"][mark]
128
+ glyph = m["glyph"] if self.square else m.get("nerd", m["glyph"])
129
+ self._write(self.out, f"{ESC}{self._sgr(38, m['colour'])}m{glyph}{RESET} {message}\n")
130
+
131
+ def ok(self, message):
132
+ self._line("ok", message)
133
+
134
+ def warn(self, message):
135
+ self._line("warn", message)
136
+
137
+ def fail(self, message):
138
+ self._line("fail", message)
139
+
140
+ def info(self, message):
141
+ self._line("info", message)
142
+
143
+ def arrow(self, message):
144
+ self._line("arrow", message)
145
+
146
+ def tint(self, tone, text):
147
+ """The text in a tone, value, dim, bold, ok, warn or fail, or the text alone unattended."""
148
+ if not self.on:
149
+ return text
150
+ if tone == "bold":
151
+ return f"{ESC}1m{text}{ESC}22m"
152
+ colour = self.p["roles"][tone] if tone in ("value", "dim") else self.p["marks"][tone]["colour"]
153
+ return f"{ESC}{self._sgr(38, colour)}m{text}{ESC}39m"
154
+
155
+ def val(self, text):
156
+ return self.tint("value", text)
157
+
158
+ def error(self, message, hint=""):
159
+ """An ERROR pill and the message bold, then the hint as hint() draws it, on the err stream."""
160
+ if not attended(self.err, self.env):
161
+ return
162
+ self._write(self.err, f"\n{self._pill(self.p['pills']['error'], 'ERROR')}\n{ESC}1m{message}{RESET}\n")
163
+ if hint:
164
+ self.hint(hint)
165
+
166
+ def hint(self, hint):
167
+ if attended(self.err, self.env):
168
+ self._write(self.err, f"\n{self._pill(self.p['pills']['sub'], 'HINT')}\n{self._dim(hint)}\n")
169
+
170
+ def help(self, text):
171
+ """A plain help drawn by the contract ADR 0042's amendment records, as ui.sh's ui_help."""
172
+ if not self.on:
173
+ self._write(self.out, text)
174
+ return
175
+ usage, text_at, lines = False, 0, []
176
+ for raw in text.split("\n"):
177
+ m = re.fullmatch(r"Usage: (.*)", raw)
178
+ if m:
179
+ usage, text_at = True, 0
180
+ lines.append(f"{self.tint('dim', 'Usage:')} {self.tint('bold', m.group(1))}")
181
+ continue
182
+ m = re.fullmatch(r"( +)(kryso .*)", raw)
183
+ if usage and m:
184
+ lines.append(f"{m.group(1)}{self.tint('bold', m.group(2))}")
185
+ continue
186
+ usage = False
187
+ if re.fullmatch(r"[A-Z][A-Za-z]*( [A-Za-z]+){0,2}:", raw):
188
+ text_at = 0
189
+ lines.append(self._pill(self.p["pills"]["sub"], raw[:-1].upper()))
190
+ continue
191
+ indent = len(raw) - len(raw.lstrip(" "))
192
+ m = re.fullmatch(r"( +)(\S+(?: \S+)*)( {2,})(\S.*)", raw)
193
+ if indent > 0 and not (text_at > 0 and indent >= text_at) and m:
194
+ lead, term, gap, rest = m.groups()
195
+ text_at = width(lead + term + gap)
196
+ note = re.fullmatch(r"(.* )(\([^()]*\))", rest)
197
+ lines.append(f"{lead}{self.tint('value', term)}{gap}"
198
+ f"{note.group(1) + self.tint('dim', note.group(2)) if note else rest}")
199
+ continue
200
+ if indent == 0:
201
+ text_at = 0
202
+ lines.append(raw)
203
+ self._write(self.out, "\n".join(lines))
204
+
205
+
206
+ # ---- the commands' pieces ------------------------------------------------------------------
207
+
208
+ def styled(stream=None):
209
+ """A Style drawing on the stream, stdout by default, or None when the stream is not attended, so
210
+ a pipe, a file, NO_COLOR or the scheduler gets a command's plain lines."""
211
+ style = Style(out=stream or sys.stdout)
212
+ return style if style.on else None
213
+
214
+
215
+ def say_error(prefix, message, hint=""):
216
+ """A refusal on stderr: under an ERROR pill when stderr is attended, else `<prefix>: <message>`."""
217
+ style = styled(sys.stderr)
218
+ if style:
219
+ style.error(message, hint)
220
+ else:
221
+ print(f"{prefix}: {message}", file=sys.stderr)
222
+
223
+
224
+ def say_failed(prefix, message):
225
+ """One failure among a command's results, on stderr after its JSON: a fail line when attended."""
226
+ style = styled(sys.stderr)
227
+ if style:
228
+ style.fail(message)
229
+ else:
230
+ print(f"{prefix}: {message}", file=sys.stderr)
231
+
232
+
233
+ class HelpFormatter(argparse.RawDescriptionHelpFormatter):
234
+ """The usage line as every kryso help writes it, so help() draws the help in sections, and
235
+ no line wider than 80 columns or the terminal, whichever is less."""
236
+
237
+ def __init__(self, prog, **kwargs):
238
+ kwargs.setdefault("width", min(80, shutil.get_terminal_size().columns))
239
+ super().__init__(prog, **kwargs)
240
+
241
+ def add_usage(self, usage, actions, groups, prefix=None):
242
+ return super().add_usage(usage, actions, groups, "Usage: " if prefix is None else prefix)
243
+
244
+
245
+ class KrysoParser(argparse.ArgumentParser):
246
+ """A parser whose help is drawn under the brand line and whose usage error is an ERROR pill, with
247
+ the help as its hint, on an attended run. Plain, both are argparse's own. A usage error exits
248
+ `code`."""
249
+
250
+ code = 2
251
+
252
+ def __init__(self, *args, **kwargs):
253
+ kwargs.setdefault("formatter_class", HelpFormatter)
254
+ super().__init__(*args, **kwargs)
255
+ self._positionals.title = "Arguments"
256
+ self._optionals.title = "Options"
257
+ for action in self._actions:
258
+ if isinstance(action, argparse._HelpAction):
259
+ action.help = "print this help"
260
+
261
+ def print_help(self, file=None):
262
+ style = styled() if file in (None, sys.stdout) else None
263
+ if not style:
264
+ return super().print_help(file)
265
+ style.brand(self.prog[len("kryso "):] if self.prog.startswith("kryso ") else self.prog, "help")
266
+ return style.help(self.format_help())
267
+
268
+ def error(self, message):
269
+ style = styled(sys.stderr)
270
+ if style:
271
+ style.error(message, f"{self.prog} --help lists the options")
272
+ self.exit(self.code)
273
+ self.print_usage(sys.stderr)
274
+ self.exit(self.code, f"{self.prog}: error: {message}\n")