@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.
- package/LICENSE +21 -0
- package/README.md +146 -6
- package/bin/kryso +31 -0
- package/bin/ship-it-status +14 -0
- package/bin/ship-ledger +14 -0
- package/bin/ship-loop +14 -0
- package/bin/ship-pass +14 -0
- package/bin/warden +14 -0
- package/dist/answer.d.ts +38 -0
- package/dist/answer.js +48 -0
- package/dist/bytes.d.ts +5 -0
- package/dist/bytes.js +35 -0
- package/dist/cleanup.d.ts +1 -0
- package/dist/cleanup.js +629 -0
- package/dist/commands.d.ts +48 -0
- package/dist/commands.js +293 -0
- package/dist/completions.d.ts +24 -0
- package/dist/completions.js +239 -0
- package/dist/daemon.d.ts +15 -0
- package/dist/daemon.js +23 -0
- package/dist/diagnose.d.ts +47 -0
- package/dist/diagnose.js +314 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +241 -0
- package/dist/env.d.ts +9 -0
- package/dist/env.js +17 -0
- package/dist/evidence.d.ts +39 -0
- package/dist/evidence.js +327 -0
- package/dist/home.d.ts +3 -0
- package/dist/home.js +27 -0
- package/dist/install.d.ts +59 -0
- package/dist/install.js +137 -0
- package/dist/isolate.d.ts +28 -0
- package/dist/isolate.js +402 -0
- package/dist/leftovers.d.ts +5 -0
- package/dist/leftovers.js +156 -0
- package/dist/machine.d.ts +6 -0
- package/dist/machine.js +185 -0
- package/dist/palette.d.ts +147 -0
- package/dist/palette.js +167 -0
- package/dist/plan.d.ts +1 -0
- package/dist/plan.js +133 -0
- package/dist/proc.d.ts +23 -0
- package/dist/proc.js +23 -0
- package/dist/read.d.ts +1 -0
- package/dist/read.js +297 -0
- package/dist/readiness.d.ts +5 -0
- package/dist/readiness.js +64 -0
- package/dist/remote.d.ts +6 -0
- package/dist/remote.js +85 -0
- package/dist/self-update.d.ts +1 -0
- package/dist/self-update.js +224 -0
- package/dist/semver.d.ts +7 -0
- package/dist/semver.js +42 -0
- package/dist/style.d.ts +71 -0
- package/dist/style.js +187 -0
- package/dist/update.d.ts +47 -0
- package/dist/update.js +190 -0
- package/dist/work.d.ts +25 -0
- package/dist/work.js +449 -0
- package/dist/workflows.d.ts +4 -0
- package/dist/workflows.js +73 -0
- package/docker/entrypoint.sh +44 -0
- package/docker/runner.Dockerfile +39 -0
- package/package.json +55 -22
- package/scripts/install-skills.sh +607 -0
- package/skills/code-review/SKILL.md +231 -0
- package/skills/kryso/SKILL.md +107 -0
- package/skills/kryso/golden/help.rounded.ansi +23 -0
- package/skills/kryso/golden/help.square.ansi +23 -0
- package/skills/kryso/golden/help.txt +23 -0
- package/skills/kryso/golden/table-narrow.json +11 -0
- package/skills/kryso/golden/table-narrow.rounded.ansi +4 -0
- package/skills/kryso/golden/table-narrow.square.ansi +4 -0
- package/skills/kryso/golden/table.ansi +5 -0
- package/skills/kryso/golden/table.json +11 -0
- package/skills/kryso/ledger.sh +2146 -0
- package/skills/kryso/palette.json +57 -0
- package/skills/kryso/reference/resuming.md +30 -0
- package/skills/kryso/reference/routing.md +23 -0
- package/skills/kryso/reference/stage-1-claim.md +79 -0
- package/skills/kryso/reference/stage-2-build.md +133 -0
- package/skills/kryso/reference/stage-3-prove.md +51 -0
- package/skills/kryso/reference/stage-4-pr.md +76 -0
- package/skills/kryso/reference/stage-5-reconcile.md +81 -0
- package/skills/kryso/reference/stage-6-merge-or-park.md +73 -0
- package/skills/kryso/reference/stage-7-close-out.md +62 -0
- package/skills/kryso/reference/terminal.md +7 -0
- package/skills/kryso/ship-it-status.sh +1503 -0
- package/skills/kryso/ui.py +274 -0
- package/skills/kryso/ui.sh +609 -0
- package/skills/kryso-build/SKILL.md +168 -0
- package/skills/kryso-shift/SKILL.md +167 -0
- package/skills/kryso-shift/archive.py +2784 -0
- package/skills/kryso-shift/archive_checker.py +462 -0
- package/skills/kryso-shift/archive_checker_lambda.py +155 -0
- package/skills/kryso-shift/archive_health.py +364 -0
- package/skills/kryso-shift/archive_launchd.py +140 -0
- package/skills/kryso-shift/archive_remote.py +990 -0
- package/skills/kryso-shift/archiving-checker.md +140 -0
- package/skills/kryso-shift/archiving-keep.md +115 -0
- package/skills/kryso-shift/archiving-recovery.md +112 -0
- package/skills/kryso-shift/archiving-remote.md +166 -0
- package/skills/kryso-shift/archiving.md +146 -0
- package/skills/kryso-shift/coverage.schema.json +225 -0
- package/skills/kryso-shift/deadline.sh +254 -0
- package/skills/kryso-shift/feedback.schema.json +35 -0
- package/skills/kryso-shift/feedback.sh +228 -0
- package/skills/kryso-shift/history-manifest.schema.json +331 -0
- package/skills/kryso-shift/keep-after.sh +55 -0
- package/skills/kryso-shift/measure.sh +611 -0
- package/skills/kryso-shift/merge-ready.sh +207 -0
- package/skills/kryso-shift/outcome.schema.json +16 -0
- package/skills/kryso-shift/pass-rules.md +8 -0
- package/skills/kryso-shift/profile.schema.json +42 -0
- package/skills/kryso-shift/reader.sh +692 -0
- package/skills/kryso-shift/reads.sh +151 -0
- package/skills/kryso-shift/reference/allowance.md +21 -0
- package/skills/kryso-shift/reference/driver.md +95 -0
- package/skills/kryso-shift/reference/measuring.md +67 -0
- package/skills/kryso-shift/reference/outputs.md +21 -0
- package/skills/kryso-shift/reference/pass-script.md +115 -0
- package/skills/kryso-shift/reference/reconcile-and-merge.md +55 -0
- package/skills/kryso-shift/reference/second-reader.md +9 -0
- package/skills/kryso-shift/reference/sweeps.md +83 -0
- package/skills/kryso-shift/repair.schema.json +14 -0
- package/skills/kryso-shift/report-template.html +679 -0
- package/skills/kryso-shift/report.py +389 -0
- package/skills/kryso-shift/report_fixture.py +65 -0
- package/skills/kryso-shift/reporting.md +58 -0
- package/skills/kryso-shift/result.sh +91 -0
- package/skills/kryso-shift/runner.sh +1178 -0
- package/skills/kryso-shift/ship-loop.sh +3977 -0
- package/skills/kryso-shift/ship-pass.sh +4987 -0
- package/skills/kryso-shift/steps.jq +19 -0
- package/skills/kryso-shift/workflow.mjs +830 -0
- package/skills/kryso-shift/workflows/default.json +22 -0
- package/skills/kryso-shift/workflows/ralph.json +13 -0
- package/skills/kryso-watch/SKILL.md +100 -0
- package/skills/kryso-watch/answer.schema.json +23 -0
- package/skills/kryso-watch/base-refs.sh +44 -0
- package/skills/kryso-watch/board.sh +58 -0
- package/skills/kryso-watch/reference/config.md +23 -0
- package/skills/kryso-watch/reference/outputs.md +30 -0
- package/skills/kryso-watch/reference/report.md +29 -0
- package/skills/kryso-watch/reference/scheduler.md +32 -0
- package/skills/kryso-watch/reference/settlement.md +29 -0
- package/skills/kryso-watch/reference/shift.md +44 -0
- package/skills/kryso-watch/reference/shim-limits.md +22 -0
- package/skills/kryso-watch/reference/triage.md +26 -0
- package/skills/kryso-watch/schema.jq +40 -0
- package/skills/kryso-watch/settle.schema.json +36 -0
- package/skills/kryso-watch/stage-common.sh +187 -0
- package/skills/kryso-watch/stages/report.sh +525 -0
- package/skills/kryso-watch/stages/settle.sh +722 -0
- package/skills/kryso-watch/stages/shift.sh +466 -0
- package/skills/kryso-watch/stages/triage.sh +379 -0
- package/skills/kryso-watch/tracker.sh +27 -0
- package/skills/kryso-watch/triage.schema.json +77 -0
- package/skills/kryso-watch/warden.launchd.plist +50 -0
- package/skills/kryso-watch/warden.schema.json +98 -0
- package/skills/kryso-watch/warden.sh +1004 -0
- package/bin/kryso.js +0 -11
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// kryso self-update: update this kryso the way it was installed (install.ts tells the kind). Each
|
|
2
|
+
// kind makes a plan: the version installed and the one available, whatever would refuse the
|
|
3
|
+
// update, the installer's running-copy check, and the steps. The steps run as child processes
|
|
4
|
+
// on kryso's own terminal, one after another, and the first that fails stops the update. bin/kryso
|
|
5
|
+
// execs this file, so it owns the process, its signals and its exit status. Every question
|
|
6
|
+
// to a registry goes through the tool that installed kryso, never a fetch of kryso's own.
|
|
7
|
+
//
|
|
8
|
+
// On an attended run (style.ts's check) the same run is drawn: the brand line with the install
|
|
9
|
+
// kind, a pill for each phase (CHECK, UPDATE, SKILLS, DONE, or DRY RUN), a mark on each line,
|
|
10
|
+
// an arrow before each step, and an ERROR pill with the fix as a HINT for a refusal. The
|
|
11
|
+
// children's own output is theirs either way.
|
|
12
|
+
import { descriptor, give, helpAnswer, refusal, say } from "./answer.js";
|
|
13
|
+
import { EX_CONFIG, EX_SOFTWARE, EX_TEMPFAIL, EX_UNAVAILABLE, EX_USAGE } from "./env.js";
|
|
14
|
+
import { detectInstall, LABELS, packageRoot } from "./install.js";
|
|
15
|
+
import { stream } from "./proc.js";
|
|
16
|
+
import { channelOf } from "./semver.js";
|
|
17
|
+
import { lineOf, planUpdate, show } from "./update.js";
|
|
18
|
+
const NAME = "kryso self-update";
|
|
19
|
+
const USAGE = `Usage: kryso self-update [--check] [--channel latest|next] [--dry-run]
|
|
20
|
+
|
|
21
|
+
It updates this kryso the way you installed it: a checkout installed with
|
|
22
|
+
scripts/install-skills.sh, a global npm, pnpm or bun package, or Homebrew's
|
|
23
|
+
formula. After a package update it runs kryso skills install, so the installed
|
|
24
|
+
skills match the new copy.
|
|
25
|
+
|
|
26
|
+
--check print the install, the version installed and the newest
|
|
27
|
+
one, and change nothing. It exits 0 when kryso is up to
|
|
28
|
+
date and 1 when an update is out
|
|
29
|
+
--channel CHANNEL the registry's channel, latest or next (default next for a
|
|
30
|
+
prerelease, latest for a release)
|
|
31
|
+
--dry-run print the commands an update would run, and run none
|
|
32
|
+
-h, --help print this help
|
|
33
|
+
|
|
34
|
+
It exits 75 while a shift, pass or watch runs from the copy it would replace,
|
|
35
|
+
and names them. It exits 78 and changes nothing when a checkout has uncommitted
|
|
36
|
+
changes, is on another branch than the one installed or has diverged from its
|
|
37
|
+
upstream, or when it cannot tell how kryso was installed. It exits 69 when it
|
|
38
|
+
cannot read the registry or the checkout's remote, or a tool a step runs is
|
|
39
|
+
missing, and 70 when a step fails.
|
|
40
|
+
`;
|
|
41
|
+
// Written straight to the descriptors, so a line is out before the next child starts.
|
|
42
|
+
const stdout = descriptor(1);
|
|
43
|
+
const stderr = descriptor(2);
|
|
44
|
+
// Every line below is declared once, plain and drawn, and answer.ts's say() picks one by its
|
|
45
|
+
// stream's attended check.
|
|
46
|
+
/** Output on stdout, plain or drawn. */
|
|
47
|
+
const print = (text, draw) => say({ text, draw }, stdout);
|
|
48
|
+
/** A line on stdout: plain, after kryso self-update's name, or drawn. */
|
|
49
|
+
const tell = (line, draw) => print(`${NAME}: ${line}\n`, draw);
|
|
50
|
+
/** A notice on stderr, as a warn line when drawn. */
|
|
51
|
+
const warn = (line) => say({ text: `${NAME}: ${line}\n`, draw: (s) => s.warn(line) }, stderr);
|
|
52
|
+
/** A refusal on stderr: the plain line, or an ERROR pill and the fix as a HINT. */
|
|
53
|
+
const refuse = (p) => say({ text: `${NAME}: ${lineOf(p)}\n`, draw: (s) => s.error(p.message, p.hint) }, stderr);
|
|
54
|
+
/** A phase's pill, after a blank line, drawn only. */
|
|
55
|
+
const phase = (label, kind = "primary") => print("", (s) => {
|
|
56
|
+
s.write("\n");
|
|
57
|
+
s.pill(kind, label);
|
|
58
|
+
});
|
|
59
|
+
function parse(argv) {
|
|
60
|
+
const opts = { check: false, dryRun: false };
|
|
61
|
+
const usage = (line) => refusal(EX_USAGE, NAME, line, { usage: USAGE });
|
|
62
|
+
for (let i = 0; i < argv.length; i++) {
|
|
63
|
+
const a = argv[i];
|
|
64
|
+
if (a === "-h" || a === "--help")
|
|
65
|
+
return helpAnswer(USAGE, "self-update", "help");
|
|
66
|
+
if (a === "--check")
|
|
67
|
+
opts.check = true;
|
|
68
|
+
else if (a === "--dry-run")
|
|
69
|
+
opts.dryRun = true;
|
|
70
|
+
else if (a === "--channel" || a.startsWith("--channel=")) {
|
|
71
|
+
const value = a === "--channel" ? argv[++i] : a.slice("--channel=".length);
|
|
72
|
+
if (value === undefined)
|
|
73
|
+
return usage("--channel takes latest or next");
|
|
74
|
+
if (value !== "latest" && value !== "next")
|
|
75
|
+
return usage(`--channel takes latest or next, got '${value}'`);
|
|
76
|
+
opts.channel = value;
|
|
77
|
+
}
|
|
78
|
+
else if (a.startsWith("-"))
|
|
79
|
+
return usage(`unknown option ${a}`);
|
|
80
|
+
else
|
|
81
|
+
return usage(`takes no arguments, got '${a}'`);
|
|
82
|
+
}
|
|
83
|
+
if (opts.check && opts.dryRun)
|
|
84
|
+
return usage("--check and --dry-run do not go together");
|
|
85
|
+
return opts;
|
|
86
|
+
}
|
|
87
|
+
/** What an install of no known kind gets: the reasons, and the commands for each kind. */
|
|
88
|
+
function unknown(install, opts) {
|
|
89
|
+
const spec = `${install.name}@${opts.channel ?? channelOf(install.version)}`;
|
|
90
|
+
const message = `kryso at ${install.root} is not an install it knows how to update, so nothing changed`;
|
|
91
|
+
const how = "Update it the way it was installed:";
|
|
92
|
+
const commands = [
|
|
93
|
+
["checkout", "git pull --ff-only && pnpm install --frozen-lockfile && pnpm build && scripts/install-skills.sh"],
|
|
94
|
+
["npm", `npm install -g ${spec}`],
|
|
95
|
+
["pnpm", `pnpm add -g ${spec}`],
|
|
96
|
+
["bun", `bun add -g ${spec}`],
|
|
97
|
+
["Homebrew", "brew upgrade kryso"],
|
|
98
|
+
];
|
|
99
|
+
say({
|
|
100
|
+
text: [
|
|
101
|
+
`${NAME}: ${message}:`,
|
|
102
|
+
...install.found.map((f) => ` ${f}`),
|
|
103
|
+
how,
|
|
104
|
+
...commands.map(([kind, command]) => ` ${kind.padEnd(11)}${command}`),
|
|
105
|
+
"",
|
|
106
|
+
].join("\n"),
|
|
107
|
+
draw: (s) => {
|
|
108
|
+
s.error(message);
|
|
109
|
+
install.found.forEach(s.info);
|
|
110
|
+
s.hint(how);
|
|
111
|
+
// A command a person copies is never cut, so this table takes no width: a terminal wraps it.
|
|
112
|
+
s.table(commands.map(([kind, command]) => [{ text: kind, tone: "value" }, command]), { indent: 2, width: Number.POSITIVE_INFINITY });
|
|
113
|
+
},
|
|
114
|
+
}, stderr);
|
|
115
|
+
}
|
|
116
|
+
/** Runs one step, or the guard, and returns undefined when it succeeds, or the status to exit
|
|
117
|
+
* with after saying why it did not. A child's own status is never passed through. */
|
|
118
|
+
function run(step, env, guard = false) {
|
|
119
|
+
const r = stream(step.argv[0], step.argv.slice(1), env, step.cwd);
|
|
120
|
+
if (r.status === 0)
|
|
121
|
+
return undefined;
|
|
122
|
+
if (r.missing) {
|
|
123
|
+
refuse({ message: `${step.argv[0]} is not on PATH, so ${show(step)} did not run${guard ? ", and nothing changed" : ""}` });
|
|
124
|
+
return EX_UNAVAILABLE;
|
|
125
|
+
}
|
|
126
|
+
if (r.status === 127) {
|
|
127
|
+
refuse({ message: `${show(step)} exited 127, because a command it runs is missing${guard ? ", and nothing changed" : ""}` });
|
|
128
|
+
return EX_UNAVAILABLE;
|
|
129
|
+
}
|
|
130
|
+
if (step.installer && r.status === EX_TEMPFAIL) {
|
|
131
|
+
refuse({
|
|
132
|
+
message: `a run holds the copy this would replace, so ${guard ? "nothing changed" : `${show(step)} changed nothing`}`,
|
|
133
|
+
hint: "wait for them, then run kryso self-update again",
|
|
134
|
+
});
|
|
135
|
+
return EX_TEMPFAIL;
|
|
136
|
+
}
|
|
137
|
+
refuse(guard
|
|
138
|
+
? { message: `the running-copy check (${show(step)}) failed with exit ${r.status}, so nothing changed` }
|
|
139
|
+
: { message: `${show(step)} failed with exit ${r.status}, so the update stopped there`, hint: "fix it, then run kryso self-update again" });
|
|
140
|
+
return EX_SOFTWARE;
|
|
141
|
+
}
|
|
142
|
+
/** --check: the install, the version installed and the one available, and whether to update. */
|
|
143
|
+
function check(plan) {
|
|
144
|
+
print(`install ${plan.label}, ${plan.where}\n`, (s) => s.info(`install ${s.val(plan.label)}, ${s.val(plan.where)}`));
|
|
145
|
+
print(`installed ${plan.installed}\n`, (s) => s.info(`installed ${s.val(plan.installed)}`));
|
|
146
|
+
print(`available ${plan.available}\n`, (s) => s.info(`available ${s.val(plan.available)}`));
|
|
147
|
+
if (plan.current) {
|
|
148
|
+
print("kryso is up to date\n", (s) => s.ok("kryso is up to date"));
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
for (const b of plan.blockers)
|
|
152
|
+
print(`${NAME} would refuse: ${lineOf(b)}\n`, (s) => s.fail(`would refuse: ${lineOf(b)}`));
|
|
153
|
+
print("an update is available: kryso self-update installs it\n", (s) => s.warn(`an update is available: ${s.val("kryso self-update")} installs it`));
|
|
154
|
+
return 1;
|
|
155
|
+
}
|
|
156
|
+
function selfUpdate(argv, env) {
|
|
157
|
+
const opts = parse(argv);
|
|
158
|
+
if ("text" in opts) {
|
|
159
|
+
give(opts, env, stdout, stderr);
|
|
160
|
+
return opts.status;
|
|
161
|
+
}
|
|
162
|
+
const install = detectInstall(packageRoot(), env);
|
|
163
|
+
print("", (s) => s.brand("self-update", LABELS[install.kind]));
|
|
164
|
+
if (install.kind === "none") {
|
|
165
|
+
unknown(install, opts);
|
|
166
|
+
return EX_CONFIG;
|
|
167
|
+
}
|
|
168
|
+
if (opts.channel && install.kind === "brew")
|
|
169
|
+
warn("Homebrew has one channel, the formula's, so kryso ignores --channel");
|
|
170
|
+
if (opts.channel && install.kind === "checkout")
|
|
171
|
+
warn("a checkout install follows its branch, so kryso ignores --channel");
|
|
172
|
+
const plan = planUpdate(install, { channel: opts.channel, fetch: true }, env);
|
|
173
|
+
if ("problem" in plan) {
|
|
174
|
+
refuse(plan.problem);
|
|
175
|
+
return plan.status;
|
|
176
|
+
}
|
|
177
|
+
phase("CHECK");
|
|
178
|
+
if (opts.check)
|
|
179
|
+
return check(plan);
|
|
180
|
+
if (plan.current) {
|
|
181
|
+
const again = install.kind === "brew" ? " (brew update fetches it again)" : "";
|
|
182
|
+
tell(`kryso is up to date at ${plan.installed} (${plan.label}), and the newest is ${plan.available}${again}`, (s) => s.ok(`kryso is up to date at ${s.val(plan.installed)}, and the newest is ${s.val(plan.available)}${again}`));
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
if (plan.blockers.length > 0) {
|
|
186
|
+
plan.blockers.forEach(refuse);
|
|
187
|
+
return EX_CONFIG;
|
|
188
|
+
}
|
|
189
|
+
const held = run(plan.guard, env, true);
|
|
190
|
+
if (held !== undefined)
|
|
191
|
+
return held;
|
|
192
|
+
print("", (s) => s.ok("no shift, pass or watch runs from the copy it replaces"));
|
|
193
|
+
tell(`${plan.label}, from ${plan.installed} to ${plan.available}`, (s) => s.info(`${plan.label}, from ${s.val(plan.installed)} to ${s.val(plan.available)}`));
|
|
194
|
+
if (opts.dryRun) {
|
|
195
|
+
print(`${NAME}: a dry run, so none of these runs:\n${plan.steps.map((step) => ` ${show(step)}\n`).join("")}`, (s) => {
|
|
196
|
+
s.write("\n");
|
|
197
|
+
s.pill("warn", "DRY RUN");
|
|
198
|
+
s.info("none of these runs:");
|
|
199
|
+
plan.steps.forEach((step) => s.arrow(show(step)));
|
|
200
|
+
});
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
let now = "";
|
|
204
|
+
for (const step of plan.steps) {
|
|
205
|
+
const next = step.installer ? "SKILLS" : "UPDATE";
|
|
206
|
+
if (next !== now)
|
|
207
|
+
phase((now = next));
|
|
208
|
+
tell(show(step), (s) => s.arrow(show(step)));
|
|
209
|
+
const failed = run(step, env);
|
|
210
|
+
if (failed !== undefined)
|
|
211
|
+
return failed;
|
|
212
|
+
}
|
|
213
|
+
const done = plan.done();
|
|
214
|
+
phase("DONE", "secondary");
|
|
215
|
+
tell(`kryso is now ${done} (${plan.label})`, (s) => s.ok(`kryso is now ${s.val(done)} (${plan.label})`));
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
process.exitCode = selfUpdate(process.argv.slice(2), process.env);
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
process.stderr.write(`${NAME}: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
223
|
+
process.exitCode = EX_SOFTWARE;
|
|
224
|
+
}
|
package/dist/semver.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const isVersion: (version: string) => boolean;
|
|
2
|
+
/** Below zero when a precedes b, zero when they rank the same, above zero when a follows b.
|
|
3
|
+
* Build metadata does not count. Throws on a string that is not a version. */
|
|
4
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
5
|
+
export type Channel = "latest" | "next";
|
|
6
|
+
/** The registry channel a version follows: next for a prerelease, latest for a release. */
|
|
7
|
+
export declare const channelOf: (version: string) => Channel;
|
package/dist/semver.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Semver 2.0.0 precedence, which is all self-update needs from a version: whether the one a
|
|
2
|
+
// channel offers is newer than the one installed, and which channel an installed one follows.
|
|
3
|
+
// It is small enough to keep here rather than take the semver package as a dependency.
|
|
4
|
+
const NUM = "0|[1-9]\\d*";
|
|
5
|
+
const ID = `(?:${NUM}|\\d*[a-zA-Z-][0-9a-zA-Z-]*)`;
|
|
6
|
+
const VERSION = new RegExp(`^(${NUM})\\.(${NUM})\\.(${NUM})(?:-(${ID}(?:\\.${ID})*))?(?:\\+[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*)?$`);
|
|
7
|
+
function parse(version) {
|
|
8
|
+
const m = VERSION.exec(version);
|
|
9
|
+
if (!m)
|
|
10
|
+
return undefined;
|
|
11
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split(".") : [] };
|
|
12
|
+
}
|
|
13
|
+
export const isVersion = (version) => parse(version) !== undefined;
|
|
14
|
+
const numeric = (id) => /^\d+$/.test(id);
|
|
15
|
+
/** Below zero when a precedes b, zero when they rank the same, above zero when a follows b.
|
|
16
|
+
* Build metadata does not count. Throws on a string that is not a version. */
|
|
17
|
+
export function compareVersions(a, b) {
|
|
18
|
+
const x = parse(a);
|
|
19
|
+
const y = parse(b);
|
|
20
|
+
if (!x || !y)
|
|
21
|
+
throw new Error(`not a semver version: ${x ? b : a}`);
|
|
22
|
+
for (let i = 0; i < 3; i++)
|
|
23
|
+
if (x.core[i] !== y.core[i])
|
|
24
|
+
return x.core[i] - y.core[i];
|
|
25
|
+
// A release ranks above any of its prereleases.
|
|
26
|
+
if (x.pre.length === 0 || y.pre.length === 0)
|
|
27
|
+
return y.pre.length - x.pre.length;
|
|
28
|
+
for (let i = 0; i < Math.min(x.pre.length, y.pre.length); i++) {
|
|
29
|
+
const p = x.pre[i];
|
|
30
|
+
const q = y.pre[i];
|
|
31
|
+
if (p === q)
|
|
32
|
+
continue;
|
|
33
|
+
if (numeric(p) && numeric(q))
|
|
34
|
+
return Number(p) - Number(q);
|
|
35
|
+
if (numeric(p) !== numeric(q))
|
|
36
|
+
return numeric(p) ? -1 : 1;
|
|
37
|
+
return p < q ? -1 : 1;
|
|
38
|
+
}
|
|
39
|
+
return x.pre.length - y.pre.length;
|
|
40
|
+
}
|
|
41
|
+
/** The registry channel a version follows: next for a prerelease, latest for a release. */
|
|
42
|
+
export const channelOf = (version) => ((parse(version)?.pre.length ?? 0) > 0 ? "next" : "latest");
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { palette } from "./palette.js";
|
|
2
|
+
export type PillKind = keyof typeof palette.pills;
|
|
3
|
+
/** How a fragment is drawn: the value colour, dim, bold, or a mark's colour. */
|
|
4
|
+
export type Tone = "value" | "dim" | "bold" | "ok" | "warn" | "fail";
|
|
5
|
+
/** A table cell: its text, plain or in a tone. */
|
|
6
|
+
export type Cell = string | {
|
|
7
|
+
text: string;
|
|
8
|
+
tone?: Tone;
|
|
9
|
+
};
|
|
10
|
+
/** What the module needs of a stream: somewhere to write, and whether it is a terminal. */
|
|
11
|
+
export interface Stream {
|
|
12
|
+
write(text: string): unknown;
|
|
13
|
+
isTTY?: boolean;
|
|
14
|
+
/** The terminal's width, which the brand line takes when COLUMNS is unset. */
|
|
15
|
+
columns?: number;
|
|
16
|
+
}
|
|
17
|
+
export type Env = Record<string, string | undefined>;
|
|
18
|
+
export interface Style {
|
|
19
|
+
/** Whether the out stream is attended, the check every call below makes. */
|
|
20
|
+
readonly attended: boolean;
|
|
21
|
+
/** The kryso pill, the subcommand in bold, and the summary dim, ending at the last of COLUMNS
|
|
22
|
+
* (80 when unset). A summary with no room for two spaces before it goes on the next line. */
|
|
23
|
+
brand(subcommand: string, summary?: string): void;
|
|
24
|
+
/** A pill on its own line. */
|
|
25
|
+
pill(kind: PillKind, label: string): void;
|
|
26
|
+
/** A line that starts with its mark in its colour. */
|
|
27
|
+
ok(message: string): void;
|
|
28
|
+
warn(message: string): void;
|
|
29
|
+
fail(message: string): void;
|
|
30
|
+
info(message: string): void;
|
|
31
|
+
/** A command or step about to run, after the arrow mark. */
|
|
32
|
+
arrow(message: string): void;
|
|
33
|
+
/** The text in the value colour for a message above, or the text alone when not attended. */
|
|
34
|
+
val(text: string): string;
|
|
35
|
+
/** The text in a tone, or the text alone when not attended. */
|
|
36
|
+
tint(tone: Tone, text: string): string;
|
|
37
|
+
/** A plain help text drawn in sections, after #345's contract: a `Usage:` line and the
|
|
38
|
+
* indented `kryso` lines under it in bold, an unindented line of a few words ending in `:` as
|
|
39
|
+
* a gray pill, an indented line with a term, two spaces and its text as an entry whose term is
|
|
40
|
+
* in the value colour and whose closing parenthesis is dim, and a line indented to an entry's
|
|
41
|
+
* text as its continuation. Every other line is as written. */
|
|
42
|
+
help(text: string): void;
|
|
43
|
+
/** Rows of cells in aligned columns two spaces apart, the first row bold as a header when
|
|
44
|
+
* asked, and no padding after a row's last cell that has text. A table wider than `width`,
|
|
45
|
+
* COLUMNS, the out stream's own width or 80, cuts its flexible column, the last unless `flex`
|
|
46
|
+
* names another by its index, to the room the others leave, and a cell cut there ends in the
|
|
47
|
+
* palette's ellipsis, as ui.sh's ui_table does. */
|
|
48
|
+
table(rows: Cell[][], options?: {
|
|
49
|
+
indent?: number;
|
|
50
|
+
header?: boolean;
|
|
51
|
+
width?: number;
|
|
52
|
+
flex?: number;
|
|
53
|
+
}): void;
|
|
54
|
+
/** One of the palette's glyphs, the Nerd Font form unless KRYSO_PILLS=square. */
|
|
55
|
+
glyph(name: keyof typeof palette.glyphs): string;
|
|
56
|
+
/** An ERROR pill and the message in bold, then the hint as hint() draws it, on the err stream. */
|
|
57
|
+
error(message: string, hint?: string): void;
|
|
58
|
+
/** A blank line, a HINT pill and the hint dim, on the err stream: the second half of error(),
|
|
59
|
+
* for an error whose hint follows lines of its own. */
|
|
60
|
+
hint(hint: string): void;
|
|
61
|
+
/** The text as it is, on the out stream, for a blank line or a line drawn from tints. */
|
|
62
|
+
write(text: string): void;
|
|
63
|
+
}
|
|
64
|
+
/** The tone an outcome word is drawn in, by the palette's outcomes, ui.sh's ui_outcome: ok, warn or
|
|
65
|
+
* fail, and info for a word the palette does not name. */
|
|
66
|
+
export declare function outcomeTone(word: string): "ok" | "warn" | "fail" | "info";
|
|
67
|
+
/** Never under NO_COLOR, then always under CLICOLOR_FORCE set to anything but 0, then only on a
|
|
68
|
+
* terminal. An empty NO_COLOR counts as unset. */
|
|
69
|
+
export declare function attended(stream: Stream, env?: Env): boolean;
|
|
70
|
+
/** The styled output for an out stream and an err stream, under an environment. */
|
|
71
|
+
export declare function style(out?: Stream, err?: Stream, env?: Env): Style;
|
package/dist/style.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// kryso's styled output in TypeScript: the pills and status lines skills/kryso/ui.sh draws, byte
|
|
2
|
+
// for byte, from the same palette (ADR 0042). Each draws only on an attended stream, NO_COLOR
|
|
3
|
+
// unset and either CLICOLOR_FORCE set or the stream a terminal, and prints nothing otherwise, so the
|
|
4
|
+
// plain output a caller writes beside it is the whole output on a pipe. A pill is rounded with
|
|
5
|
+
// Nerd Font half circles and the marks are Nerd Font glyphs, or the pill is square and the marks
|
|
6
|
+
// plain under KRYSO_PILLS=square, which means no Nerd Font. A colour is 24-bit when COLORTERM
|
|
7
|
+
// is truecolor or 24bit, else the nearest xterm 256-colour code. NO_COLOR wins over
|
|
8
|
+
// CLICOLOR_FORCE, as in ui.sh and gum.
|
|
9
|
+
//
|
|
10
|
+
// ui.sh draws the same arrow (a step's line), tint (a fragment in a tone), hint (error()'s HINT
|
|
11
|
+
// on its own), help and table, whose bytes the golden files in skills/kryso/golden/ pin for both
|
|
12
|
+
// modules. write (text as it is) is this module's alone.
|
|
13
|
+
import { palette } from "./palette.js";
|
|
14
|
+
/** The tone an outcome word is drawn in, by the palette's outcomes, ui.sh's ui_outcome: ok, warn or
|
|
15
|
+
* fail, and info for a word the palette does not name. */
|
|
16
|
+
export function outcomeTone(word) {
|
|
17
|
+
for (const [tone, words] of Object.entries(palette.outcomes)) {
|
|
18
|
+
if (words.includes(word))
|
|
19
|
+
return tone;
|
|
20
|
+
}
|
|
21
|
+
return "info";
|
|
22
|
+
}
|
|
23
|
+
const forced = (env) => Boolean(env.CLICOLOR_FORCE) && env.CLICOLOR_FORCE !== "0";
|
|
24
|
+
/** Never under NO_COLOR, then always under CLICOLOR_FORCE set to anything but 0, then only on a
|
|
25
|
+
* terminal. An empty NO_COLOR counts as unset. */
|
|
26
|
+
export function attended(stream, env = process.env) {
|
|
27
|
+
if (env.NO_COLOR)
|
|
28
|
+
return false;
|
|
29
|
+
return forced(env) || stream.isTTY === true;
|
|
30
|
+
}
|
|
31
|
+
const ESC = "\u001b[";
|
|
32
|
+
const RESET = `${ESC}0m`;
|
|
33
|
+
/** Characters, not UTF-16 units, so a glyph outside the BMP takes one cell as in ui.sh. */
|
|
34
|
+
const width = (text) => [...text].length;
|
|
35
|
+
/** The styled output for an out stream and an err stream, under an environment. */
|
|
36
|
+
export function style(out = process.stdout, err = process.stderr, env = process.env) {
|
|
37
|
+
const on = attended(out, env);
|
|
38
|
+
const truecolor = env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
39
|
+
const sgr = (layer, name) => {
|
|
40
|
+
const c = palette.colours[name];
|
|
41
|
+
return truecolor ? `${layer};2;${c.rgb.join(";")}` : `${layer};5;${c.xterm}`;
|
|
42
|
+
};
|
|
43
|
+
const pillText = (colour, label) => {
|
|
44
|
+
const ink = sgr(38, palette.roles["pill-text"]);
|
|
45
|
+
if (env.KRYSO_PILLS === "square")
|
|
46
|
+
return `${ESC}1;${ink};${sgr(48, colour)}m ${label} ${RESET}`;
|
|
47
|
+
const edge = sgr(38, colour);
|
|
48
|
+
return `${ESC}${edge}m${palette.ends.left}${ESC}1;${ink};${sgr(48, colour)}m${label}${ESC}0;${edge}m${palette.ends.right}${RESET}`;
|
|
49
|
+
};
|
|
50
|
+
const line = (mark) => (message) => {
|
|
51
|
+
if (!on)
|
|
52
|
+
return;
|
|
53
|
+
const m = palette.marks[mark];
|
|
54
|
+
// KRYSO_PILLS=square means no Nerd Font, so the marks fall back to their plain glyphs.
|
|
55
|
+
const glyph = env.KRYSO_PILLS === "square" ? m.glyph : m.nerd;
|
|
56
|
+
out.write(`${ESC}${sgr(38, m.colour)}m${glyph}${RESET} ${message}\n`);
|
|
57
|
+
};
|
|
58
|
+
const glyphOf = (name) => (env.KRYSO_PILLS === "square" ? palette.glyphs[name].glyph : palette.glyphs[name].nerd);
|
|
59
|
+
const dim = (text) => `${ESC}${sgr(38, palette.roles.dim)}m${text}${RESET}`;
|
|
60
|
+
const hintText = (hint) => `\n${pillText(palette.pills.sub, "HINT")}\n${dim(hint)}\n`;
|
|
61
|
+
const TONES = {
|
|
62
|
+
value: palette.roles.value,
|
|
63
|
+
dim: palette.roles.dim,
|
|
64
|
+
ok: palette.marks.ok.colour,
|
|
65
|
+
warn: palette.marks.warn.colour,
|
|
66
|
+
fail: palette.marks.fail.colour,
|
|
67
|
+
};
|
|
68
|
+
// A tint ends only what it started, so it sits inside a bold message as ui_val does.
|
|
69
|
+
const tint = (tone, text) => {
|
|
70
|
+
if (!on)
|
|
71
|
+
return text;
|
|
72
|
+
return tone === "bold" ? `${ESC}1m${text}${ESC}22m` : `${ESC}${sgr(38, TONES[tone])}m${text}${ESC}39m`;
|
|
73
|
+
};
|
|
74
|
+
const helpLine = (state, raw) => {
|
|
75
|
+
const usage = /^Usage: (.*)$/.exec(raw);
|
|
76
|
+
if (usage) {
|
|
77
|
+
state.usage = true;
|
|
78
|
+
state.text = 0;
|
|
79
|
+
return `${tint("dim", "Usage:")} ${tint("bold", usage[1])}`;
|
|
80
|
+
}
|
|
81
|
+
const more = /^( +)(kryso .*)$/.exec(raw);
|
|
82
|
+
if (state.usage && more)
|
|
83
|
+
return `${more[1]}${tint("bold", more[2])}`;
|
|
84
|
+
state.usage = false;
|
|
85
|
+
if (/^[A-Z][A-Za-z]*( [A-Za-z]+){0,2}:$/.test(raw)) {
|
|
86
|
+
state.text = 0;
|
|
87
|
+
return pillText(palette.pills.sub, raw.slice(0, -1).toUpperCase());
|
|
88
|
+
}
|
|
89
|
+
const indent = /^ */.exec(raw)[0].length;
|
|
90
|
+
const entry = /^( +)(\S+(?: \S+)*)( {2,})(\S.*)$/.exec(raw);
|
|
91
|
+
if (indent > 0 && !(state.text > 0 && indent >= state.text) && entry) {
|
|
92
|
+
const [, lead, term, gap, rest] = entry;
|
|
93
|
+
state.text = lead.length + term.length + gap.length;
|
|
94
|
+
const note = /^(.* )(\([^()]*\))$/.exec(rest);
|
|
95
|
+
return `${lead}${tint("value", term)}${gap}${note ? `${note[1]}${tint("dim", note[2])}` : rest}`;
|
|
96
|
+
}
|
|
97
|
+
if (indent === 0)
|
|
98
|
+
state.text = 0;
|
|
99
|
+
return raw;
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
attended: on,
|
|
103
|
+
brand(subcommand, summary = "") {
|
|
104
|
+
if (!on)
|
|
105
|
+
return;
|
|
106
|
+
const head = `${pillText(palette.roles.brand, "kryso")} ${ESC}1m${subcommand}${RESET}`;
|
|
107
|
+
if (!summary) {
|
|
108
|
+
out.write(`${head}\n`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const columns = /^[1-9][0-9]*$/.test(env.COLUMNS ?? "") ? Number(env.COLUMNS) : out.columns || 80;
|
|
112
|
+
// The pill is its label and two cells, a space or an end each side.
|
|
113
|
+
const left = width(`kryso ${subcommand}`) + 2;
|
|
114
|
+
const room = width(summary);
|
|
115
|
+
const gap = columns - left - room;
|
|
116
|
+
if (gap >= 2)
|
|
117
|
+
out.write(`${head}${" ".repeat(gap)}${dim(summary)}\n`);
|
|
118
|
+
else
|
|
119
|
+
out.write(`${head}\n${" ".repeat(Math.max(columns - room, 0))}${dim(summary)}\n`);
|
|
120
|
+
},
|
|
121
|
+
pill(kind, label) {
|
|
122
|
+
if (!on)
|
|
123
|
+
return;
|
|
124
|
+
out.write(`${pillText(palette.pills[kind], label)}\n`);
|
|
125
|
+
},
|
|
126
|
+
ok: line("ok"),
|
|
127
|
+
warn: line("warn"),
|
|
128
|
+
fail: line("fail"),
|
|
129
|
+
info: line("info"),
|
|
130
|
+
arrow: line("arrow"),
|
|
131
|
+
val: (text) => tint("value", text),
|
|
132
|
+
tint,
|
|
133
|
+
help(text) {
|
|
134
|
+
if (!on)
|
|
135
|
+
return;
|
|
136
|
+
const state = { usage: false, text: 0 };
|
|
137
|
+
out.write(text.split("\n").map((raw) => helpLine(state, raw)).join("\n"));
|
|
138
|
+
},
|
|
139
|
+
table(rows, { indent = 0, header = false, width: limit, flex } = {}) {
|
|
140
|
+
if (!on || rows.length === 0)
|
|
141
|
+
return;
|
|
142
|
+
const cells = rows.map((row) => row.map((c) => (typeof c === "string" ? { text: c } : c)));
|
|
143
|
+
const widths = [];
|
|
144
|
+
for (const row of cells)
|
|
145
|
+
row.forEach((c, i) => (widths[i] = Math.max(widths[i] ?? 0, width(c.text))));
|
|
146
|
+
const max = limit ?? (/^[1-9][0-9]*$/.test(env.COLUMNS ?? "") ? Number(env.COLUMNS) : out.columns || 80);
|
|
147
|
+
const at = flex ?? widths.length - 1;
|
|
148
|
+
const total = indent + widths.reduce((sum, w, i) => sum + w + (i > 0 ? 2 : 0), 0);
|
|
149
|
+
if (total > max && at >= 0 && at < widths.length) {
|
|
150
|
+
const room = Math.max(widths[at] - (total - max), 1);
|
|
151
|
+
widths[at] = room;
|
|
152
|
+
const ellipsis = glyphOf("ellipsis");
|
|
153
|
+
for (const row of cells) {
|
|
154
|
+
const c = row[at];
|
|
155
|
+
if (c && width(c.text) > room)
|
|
156
|
+
row[at] = { ...c, text: [...c.text].slice(0, room - 1).join("") + ellipsis };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const lines = cells.map((row, r) => {
|
|
160
|
+
let last = row.length - 1;
|
|
161
|
+
while (last > 0 && row[last].text === "")
|
|
162
|
+
last--;
|
|
163
|
+
const drawn = row.slice(0, last + 1).map((c, i) => {
|
|
164
|
+
const tone = header && r === 0 ? "bold" : c.tone;
|
|
165
|
+
const text = tone && c.text ? tint(tone, c.text) : c.text;
|
|
166
|
+
return i === last ? text : text + " ".repeat(widths[i] - width(c.text));
|
|
167
|
+
});
|
|
168
|
+
return " ".repeat(indent) + drawn.join(" ");
|
|
169
|
+
});
|
|
170
|
+
out.write(`${lines.join("\n")}\n`);
|
|
171
|
+
},
|
|
172
|
+
error(message, hint) {
|
|
173
|
+
if (!attended(err, env))
|
|
174
|
+
return;
|
|
175
|
+
err.write(`\n${pillText(palette.pills.error, "ERROR")}\n${ESC}1m${message}${RESET}\n${hint ? hintText(hint) : ""}`);
|
|
176
|
+
},
|
|
177
|
+
hint(hint) {
|
|
178
|
+
if (attended(err, env))
|
|
179
|
+
err.write(hintText(hint));
|
|
180
|
+
},
|
|
181
|
+
write(text) {
|
|
182
|
+
if (on)
|
|
183
|
+
out.write(text);
|
|
184
|
+
},
|
|
185
|
+
glyph: glyphOf,
|
|
186
|
+
};
|
|
187
|
+
}
|
package/dist/update.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Install } from "./install.js";
|
|
2
|
+
import { type Channel } from "./semver.js";
|
|
3
|
+
/** What a plan is asked for: the registry's channel, and whether a checkout's plan may fetch. */
|
|
4
|
+
export interface Ask {
|
|
5
|
+
channel?: Channel;
|
|
6
|
+
/** False to write nothing: a checkout's plan then reads its remote with git ls-remote. */
|
|
7
|
+
fetch: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** One command an update runs, and the directory it runs in. */
|
|
10
|
+
export interface Step {
|
|
11
|
+
argv: string[];
|
|
12
|
+
cwd?: string;
|
|
13
|
+
/** It runs install-skills.sh, whose exit 75 is a refusal: a run holds a copy it would replace. */
|
|
14
|
+
installer?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface Plan {
|
|
17
|
+
/** What install.ts calls the kind, as the lines name it. */
|
|
18
|
+
label: string;
|
|
19
|
+
where: string;
|
|
20
|
+
installed: string;
|
|
21
|
+
available: string;
|
|
22
|
+
current: boolean;
|
|
23
|
+
/** What refuses the update, each with its fix. */
|
|
24
|
+
blockers: Problem[];
|
|
25
|
+
/** The installer's running-copy check for every copy the steps replace. */
|
|
26
|
+
guard: Step;
|
|
27
|
+
steps: Step[];
|
|
28
|
+
/** The version the steps left, read from the new copy, for the line after the last step. */
|
|
29
|
+
done(): string;
|
|
30
|
+
}
|
|
31
|
+
/** Why the run stops: the message, and the fix when there is one. The plain line is the two
|
|
32
|
+
* joined by ": ". */
|
|
33
|
+
export interface Problem {
|
|
34
|
+
message: string;
|
|
35
|
+
hint?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const lineOf: (p: Problem) => string;
|
|
38
|
+
/** A plan, or the problem and the status that end the run before one. */
|
|
39
|
+
export type Planned = Plan | {
|
|
40
|
+
status: number;
|
|
41
|
+
problem: Problem;
|
|
42
|
+
};
|
|
43
|
+
export declare const show: (s: Step) => string;
|
|
44
|
+
/** The plan for an install of a kind kryso knows how to update. */
|
|
45
|
+
export declare function planUpdate(install: Exclude<Install, {
|
|
46
|
+
kind: "none";
|
|
47
|
+
}>, ask: Ask, env: NodeJS.ProcessEnv): Planned;
|