@krysoworks/kryso 0.0.0-stage → 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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -2
  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 +65 -4
  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
@@ -0,0 +1,185 @@
1
+ // What diagnose.ts reads of the machine itself: the tools the drivers run on, the logins they need,
2
+ // and the kryso-runner images an older kryso left. Every tool is found on PATH as the drivers find
3
+ // it, and asked only for its version, its login or its image list, so nothing here writes. The
4
+ // model hosts are checked by the runner's own preflight in runner.sh, run by the first bash on
5
+ // PATH as a shift runs it, so doctor holds no second rule for them and makes no model request.
6
+ import { accessSync, constants, existsSync, statSync } from "node:fs";
7
+ import path from "node:path";
8
+ import { IMAGE } from "./isolate.js";
9
+ import { capture } from "./proc.js";
10
+ /** The oldest version of each tool the drivers run on, and what needs it. This is the one place
11
+ * a floor is written down.
12
+ *
13
+ * bash: the drivers' own code parses under 3.2, but it cannot run them. With /bin/bash 3.2 first
14
+ * on PATH and bash 5.3 behind it, 87 of the 164 checks in the first 40 cases of
15
+ * test-ship-pass.sh failed, against none under 5.3 (2026-12-01): `local why` leaves why set on
16
+ * 3.2, so every pass refused its issue as if gh had failed. The suites read BASHPID and declare
17
+ * associative arrays, which need 4.0, and the drivers and suites run under `set -u`, where bash
18
+ * before 4.4 calls an empty array's "${a[@]}" unbound.
19
+ *
20
+ * git: the ledger module and the runner read the common git directory with --path-format. gh: a
21
+ * pass finds an issue's open pull request by its closingIssuesReferences. jq: the drivers' filters
22
+ * use $ARGS, --rawfile, IN and walk. python3: as archiving.md and reporting.md say. node: the
23
+ * engines field of kryso's package. */
24
+ const FLOORS = {
25
+ bash: { floor: "4.4", for: "the drivers and their suites" },
26
+ git: { floor: "2.31", for: "git rev-parse --path-format" },
27
+ gh: { floor: "2.72", for: "the closingIssuesReferences field" },
28
+ jq: { floor: "1.6", for: "$ARGS, --rawfile, IN and walk" },
29
+ python3: { floor: "3.10", for: "report.py and archive.py" },
30
+ node: { floor: "20", for: "kryso itself" },
31
+ };
32
+ /** gum below this draws no styled output kryso can use. */
33
+ const GUM_FLOOR = "0.12";
34
+ const HOSTS = ["claude", "codex"];
35
+ const tools = (d) => ({ group: "tools", ...d });
36
+ /** Every executable file named tool on PATH, in PATH's order. */
37
+ function onPath(tool, env) {
38
+ const found = [];
39
+ for (const dir of (env.PATH ?? "").split(path.delimiter)) {
40
+ if (!dir)
41
+ continue;
42
+ const file = path.join(dir, tool);
43
+ try {
44
+ if (!statSync(file).isFile())
45
+ continue;
46
+ accessSync(file, constants.X_OK);
47
+ found.push(file);
48
+ }
49
+ catch {
50
+ // Not here, or not one that runs.
51
+ }
52
+ }
53
+ return found;
54
+ }
55
+ /** The first version a program prints for --version, as numbers: `jq-1.7.1`, `v22.1.0`. */
56
+ function versionOf(file, env) {
57
+ const r = capture(file, ["--version"], env);
58
+ const m = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(`${r.out}\n${r.err}`);
59
+ return r.ok && m ? m.slice(1).filter((n) => n !== undefined).map(Number) : undefined;
60
+ }
61
+ const numbers = (v) => v.split(".").map(Number);
62
+ const shown = (v) => v.join(".");
63
+ function atLeast(v, floor) {
64
+ const f = numbers(floor);
65
+ for (let i = 0; i < Math.max(v.length, f.length); i++) {
66
+ const a = v[i] ?? 0;
67
+ const b = f[i] ?? 0;
68
+ if (a !== b)
69
+ return a > b;
70
+ }
71
+ return true;
72
+ }
73
+ /** A required tool that is missing, or one whose version is below its floor. */
74
+ function required(tool, env) {
75
+ const { floor, for: need } = FLOORS[tool];
76
+ const all = onPath(tool, env);
77
+ const [first] = all;
78
+ if (!first) {
79
+ return [tools({ id: "tools.missing", severity: "error", fix: "person", subject: tool, text: `${tool} is not on PATH, and kryso needs ${tool} ${floor} or later for ${need}, so install it` })];
80
+ }
81
+ if (tool === "bash")
82
+ return [bash(all, env)];
83
+ const v = versionOf(first, env);
84
+ if (v && atLeast(v, floor))
85
+ return [];
86
+ const what = v ? `${tool} ${shown(v)} at ${first} is older than ${floor}, which kryso needs` : `${tool} at ${first} prints no version kryso can read, and kryso needs ${floor} or later`;
87
+ return [tools({ id: "tools.too-old", severity: "error", fix: "person", subject: first, text: `${what} for ${need}, so put ${tool} ${floor} or later first on PATH` })];
88
+ }
89
+ /** The first bash on PATH, which runs every driver, named whether or not it can, with a later
90
+ * one that could when it cannot. */
91
+ function bash(all, env) {
92
+ const { floor, for: need } = FLOORS.bash;
93
+ const [first, ...later] = all;
94
+ const v = versionOf(first, env);
95
+ const named = `the first bash on PATH is ${first}${v ? `, version ${shown(v)}` : ", which prints no version kryso can read"}`;
96
+ if (v && atLeast(v, floor))
97
+ return tools({ id: "tools.bash", severity: "info", fix: "person", subject: first, text: `${named}, which runs the drivers` });
98
+ const fit = later.map((file) => [file, versionOf(file, env)]).find(([, lv]) => lv && atLeast(lv, floor));
99
+ const fix = fit
100
+ ? `${fit[0]} is ${shown(fit[1])} and comes later on PATH, so put ${path.dirname(fit[0])} before ${path.dirname(first)}`
101
+ : `so install bash ${floor} or later and put it first on PATH`;
102
+ return tools({ id: "tools.bash", severity: "error", fix: "person", subject: first, text: `${named}, and ${need} need bash ${floor} or later: ${fix}` });
103
+ }
104
+ /** gum and docker: kryso runs without them, so a missing or old one is an info. */
105
+ function optional(env) {
106
+ const found = [];
107
+ const [gum] = onPath("gum", env);
108
+ const v = gum ? versionOf(gum, env) : undefined;
109
+ if (!gum || !v || !atLeast(v, GUM_FLOOR)) {
110
+ const what = !gum ? "gum is not on PATH" : `gum ${v ? shown(v) : "of no version kryso can read"} at ${gum} is older than ${GUM_FLOOR}`;
111
+ found.push(tools({ id: "tools.optional", severity: "info", fix: "person", subject: "gum", text: `${what}, so kryso prints its plain output; install gum ${GUM_FLOOR} or later for the styled one` }));
112
+ }
113
+ if (onPath("docker", env).length === 0) {
114
+ found.push(tools({ id: "tools.optional", severity: "info", fix: "person", subject: "docker", text: "docker is not on PATH, so --isolate docker cannot run; install it to run shifts in a container" }));
115
+ }
116
+ return found;
117
+ }
118
+ /** The gh login, by the exit status of `gh auth status`, as the shift's preflight reads it. */
119
+ function ghLogin(offline, env) {
120
+ if (onPath("gh", env).length === 0)
121
+ return [];
122
+ if (offline) {
123
+ return [tools({ id: "tools.login", severity: "info", fix: "command", subject: "gh", unknown: true, text: "the gh login is unknown, because --offline makes no GitHub read", command: "gh auth status" })];
124
+ }
125
+ if (capture("gh", ["auth", "status"], env).ok)
126
+ return [];
127
+ return [tools({ id: "tools.login", severity: "error", fix: "command", subject: "gh", text: "gh is not logged in, so a shift cannot read the tracker", command: "gh auth login" })];
128
+ }
129
+ /** The command that logs each model host in, as the runner's preflight names it when the login fails. */
130
+ const LOGIN = { claude: "claude auth login", codex: "codex login" };
131
+ /** Each model host: not installed, or installed and failing the runner's own preflight. */
132
+ function hostLogins(home, env) {
133
+ const installed = HOSTS.filter((host) => onPath(host, env).length > 0);
134
+ if (installed.length === 0) {
135
+ return [tools({ id: "tools.host-missing", severity: "error", fix: "person", subject: HOSTS.join(" "), text: `neither ${HOSTS.join(" nor ")} is on PATH, and every pass runs on one of them, so install one` })];
136
+ }
137
+ const found = HOSTS.filter((host) => !installed.includes(host)).map((host) => tools({ id: "tools.host-missing", severity: "info", fix: "person", subject: host, text: `${host} is not on PATH, so a profile on ${host} cannot run; install it to use one` }));
138
+ const runner = home ? path.join(home, "skills", "kryso-shift", "runner.sh") : undefined;
139
+ const [sh] = onPath("bash", env);
140
+ for (const host of installed) {
141
+ if (!runner || !existsSync(runner) || !sh) {
142
+ const why = !sh ? "there is no bash on PATH to run" : "kryso cannot find";
143
+ found.push(tools({ id: "tools.login", severity: "info", fix: "person", subject: host, unknown: true, text: `${host}'s login is unknown, because ${why} the runner's preflight in runner.sh` }));
144
+ continue;
145
+ }
146
+ const r = capture(sh, ["-c", 'source "$1" && runner_profile_load "$2" && runner_preflight', "kryso-doctor", runner, host], env);
147
+ if (r.ok)
148
+ continue;
149
+ const line = r.err.split("\n").reverse().find((l) => l.startsWith("runner: ")) ?? r.err.split("\n").pop() ?? "";
150
+ const text = `${host} fails the runner's preflight: ${line.replace(/^runner: /, "") || "it stopped without a reason"}`;
151
+ // The runner names the command that logs each host in. Any other failure is the host's version
152
+ // or flags, which a newer host settles.
153
+ const login = LOGIN[host];
154
+ found.push(login && line.includes(login)
155
+ ? tools({ id: "tools.login", severity: "error", fix: "command", subject: host, text, command: login })
156
+ : tools({ id: "tools.host-preflight", severity: "error", fix: "person", subject: host, text: `${text}, so update ${host}` }));
157
+ }
158
+ return found;
159
+ }
160
+ /** The tools group: the required tools, the first bash, gum and docker, and the logins. */
161
+ export function toolsGroup(home, offline, env) {
162
+ const found = Object.keys(FLOORS).flatMap((tool) => required(tool, env));
163
+ return [...found, ...optional(env), ...ghLogin(offline, env), ...hostLogins(home, env)];
164
+ }
165
+ /** The images group: each kryso-runner image built for another version than this kryso's, with
166
+ * the command that removes it. With docker missing or its daemon down there is nothing to say. */
167
+ export function imagesGroup(version, env) {
168
+ if (onPath("docker", env).length === 0)
169
+ return [];
170
+ const r = capture("docker", ["image", "ls", "--format", "{{.Repository}}:{{.Tag}}", IMAGE], env);
171
+ if (!r.ok)
172
+ return [];
173
+ return r.out
174
+ .split("\n")
175
+ .filter((image) => image.startsWith(`${IMAGE}:`) && image !== `${IMAGE}:${version}` && image !== `${IMAGE}:<none>`)
176
+ .map((image) => ({
177
+ id: "images.old-runner",
178
+ group: "images",
179
+ severity: "info",
180
+ fix: "command",
181
+ subject: image,
182
+ text: `${image} was built for another kryso than ${version}, and no run of this one uses it`,
183
+ command: `docker image rm ${image}`,
184
+ }));
185
+ }
@@ -0,0 +1,147 @@
1
+ /** kryso's colours, pill ends, marks, glyphs and outcome tones. A colour's xterm code is the nearest 256-colour code. */
2
+ export declare const palette: {
3
+ readonly colours: {
4
+ readonly cyan: {
5
+ readonly hex: "78dce8";
6
+ readonly rgb: readonly [120, 220, 232];
7
+ readonly xterm: 116;
8
+ };
9
+ readonly green: {
10
+ readonly hex: "a9dc76";
11
+ readonly rgb: readonly [169, 220, 118];
12
+ readonly xterm: 150;
13
+ };
14
+ readonly yellow: {
15
+ readonly hex: "ffd866";
16
+ readonly rgb: readonly [255, 216, 102];
17
+ readonly xterm: 221;
18
+ };
19
+ readonly red: {
20
+ readonly hex: "ff6188";
21
+ readonly rgb: readonly [255, 97, 136];
22
+ readonly xterm: 204;
23
+ };
24
+ readonly purple: {
25
+ readonly hex: "ab9df2";
26
+ readonly rgb: readonly [171, 157, 242];
27
+ readonly xterm: 147;
28
+ };
29
+ readonly gray: {
30
+ readonly hex: "939293";
31
+ readonly rgb: readonly [147, 146, 147];
32
+ readonly xterm: 246;
33
+ };
34
+ readonly ink: {
35
+ readonly hex: "2d2a2e";
36
+ readonly rgb: readonly [45, 42, 46];
37
+ readonly xterm: 236;
38
+ };
39
+ readonly muted: {
40
+ readonly hex: "727072";
41
+ readonly rgb: readonly [114, 112, 114];
42
+ readonly xterm: 243;
43
+ };
44
+ };
45
+ readonly roles: {
46
+ readonly brand: "cyan";
47
+ readonly "pill-text": "ink";
48
+ readonly value: "green";
49
+ readonly dim: "muted";
50
+ };
51
+ readonly pills: {
52
+ readonly primary: "cyan";
53
+ readonly secondary: "green";
54
+ readonly warn: "yellow";
55
+ readonly error: "red";
56
+ readonly prompt: "purple";
57
+ readonly sub: "gray";
58
+ };
59
+ readonly ends: {
60
+ readonly left: "";
61
+ readonly right: "";
62
+ };
63
+ readonly marks: {
64
+ readonly ok: {
65
+ readonly glyph: "✔";
66
+ readonly nerd: "";
67
+ readonly colour: "green";
68
+ };
69
+ readonly warn: {
70
+ readonly glyph: "!";
71
+ readonly nerd: "!";
72
+ readonly colour: "yellow";
73
+ };
74
+ readonly fail: {
75
+ readonly glyph: "✖";
76
+ readonly nerd: "";
77
+ readonly colour: "red";
78
+ };
79
+ readonly info: {
80
+ readonly glyph: "ℹ";
81
+ readonly nerd: "ℹ";
82
+ readonly colour: "cyan";
83
+ };
84
+ readonly bullet: {
85
+ readonly glyph: "•";
86
+ readonly nerd: "•";
87
+ readonly colour: "purple";
88
+ };
89
+ readonly arrow: {
90
+ readonly glyph: "→";
91
+ readonly nerd: "";
92
+ readonly colour: "muted";
93
+ };
94
+ readonly trace: {
95
+ readonly glyph: "↳";
96
+ readonly nerd: "↳";
97
+ readonly colour: "muted";
98
+ };
99
+ };
100
+ readonly glyphs: {
101
+ readonly "bar-done": {
102
+ readonly glyph: "▰";
103
+ readonly nerd: "";
104
+ };
105
+ readonly "bar-left": {
106
+ readonly glyph: "▱";
107
+ readonly nerd: "";
108
+ };
109
+ readonly dot: {
110
+ readonly glyph: "●";
111
+ readonly nerd: "";
112
+ };
113
+ readonly ellipsis: {
114
+ readonly glyph: "…";
115
+ readonly nerd: "";
116
+ };
117
+ readonly refresh: {
118
+ readonly glyph: "↻";
119
+ readonly nerd: "";
120
+ };
121
+ readonly pause: {
122
+ readonly glyph: "‖";
123
+ readonly nerd: "‖";
124
+ };
125
+ readonly alert: {
126
+ readonly glyph: "‼";
127
+ readonly nerd: "‼";
128
+ };
129
+ readonly pending: {
130
+ readonly glyph: "◌";
131
+ readonly nerd: "◌";
132
+ };
133
+ readonly minus: {
134
+ readonly glyph: "−";
135
+ readonly nerd: "−";
136
+ };
137
+ readonly ring: {
138
+ readonly glyph: "○";
139
+ readonly nerd: "";
140
+ };
141
+ };
142
+ readonly outcomes: {
143
+ readonly ok: readonly ["passed", "done", "proved", "shipped", "merged"];
144
+ readonly warn: readonly ["parked", "skipped", "locked", "nothing-to-take", "rate-limited", "budget-stop"];
145
+ readonly fail: readonly ["failed", "check-failed", "blocked", "interrupted", "none"];
146
+ };
147
+ };
@@ -0,0 +1,167 @@
1
+ // Written by `pnpm --filter kryso palette` from skills/kryso/palette.json. Edit that file, never this export.
2
+ /** kryso's colours, pill ends, marks, glyphs and outcome tones. A colour's xterm code is the nearest 256-colour code. */
3
+ export const palette = {
4
+ "colours": {
5
+ "cyan": {
6
+ "hex": "78dce8",
7
+ "rgb": [120, 220, 232],
8
+ "xterm": 116
9
+ },
10
+ "green": {
11
+ "hex": "a9dc76",
12
+ "rgb": [169, 220, 118],
13
+ "xterm": 150
14
+ },
15
+ "yellow": {
16
+ "hex": "ffd866",
17
+ "rgb": [255, 216, 102],
18
+ "xterm": 221
19
+ },
20
+ "red": {
21
+ "hex": "ff6188",
22
+ "rgb": [255, 97, 136],
23
+ "xterm": 204
24
+ },
25
+ "purple": {
26
+ "hex": "ab9df2",
27
+ "rgb": [171, 157, 242],
28
+ "xterm": 147
29
+ },
30
+ "gray": {
31
+ "hex": "939293",
32
+ "rgb": [147, 146, 147],
33
+ "xterm": 246
34
+ },
35
+ "ink": {
36
+ "hex": "2d2a2e",
37
+ "rgb": [45, 42, 46],
38
+ "xterm": 236
39
+ },
40
+ "muted": {
41
+ "hex": "727072",
42
+ "rgb": [114, 112, 114],
43
+ "xterm": 243
44
+ }
45
+ },
46
+ "roles": {
47
+ "brand": "cyan",
48
+ "pill-text": "ink",
49
+ "value": "green",
50
+ "dim": "muted"
51
+ },
52
+ "pills": {
53
+ "primary": "cyan",
54
+ "secondary": "green",
55
+ "warn": "yellow",
56
+ "error": "red",
57
+ "prompt": "purple",
58
+ "sub": "gray"
59
+ },
60
+ "ends": {
61
+ "left": "\ue0b6",
62
+ "right": "\ue0b4"
63
+ },
64
+ "marks": {
65
+ "ok": {
66
+ "glyph": "\u2714",
67
+ "nerd": "\uf00c",
68
+ "colour": "green"
69
+ },
70
+ "warn": {
71
+ "glyph": "!",
72
+ "nerd": "!",
73
+ "colour": "yellow"
74
+ },
75
+ "fail": {
76
+ "glyph": "\u2716",
77
+ "nerd": "\uf00d",
78
+ "colour": "red"
79
+ },
80
+ "info": {
81
+ "glyph": "\u2139",
82
+ "nerd": "\u2139",
83
+ "colour": "cyan"
84
+ },
85
+ "bullet": {
86
+ "glyph": "\u2022",
87
+ "nerd": "\u2022",
88
+ "colour": "purple"
89
+ },
90
+ "arrow": {
91
+ "glyph": "\u2192",
92
+ "nerd": "\uea9c",
93
+ "colour": "muted"
94
+ },
95
+ "trace": {
96
+ "glyph": "\u21b3",
97
+ "nerd": "\u21b3",
98
+ "colour": "muted"
99
+ }
100
+ },
101
+ "glyphs": {
102
+ "bar-done": {
103
+ "glyph": "\u25b0",
104
+ "nerd": "\uf0c8"
105
+ },
106
+ "bar-left": {
107
+ "glyph": "\u25b1",
108
+ "nerd": "\uf096"
109
+ },
110
+ "dot": {
111
+ "glyph": "\u25cf",
112
+ "nerd": "\uf111"
113
+ },
114
+ "ellipsis": {
115
+ "glyph": "\u2026",
116
+ "nerd": "\uf141"
117
+ },
118
+ "refresh": {
119
+ "glyph": "\u21bb",
120
+ "nerd": "\uf021"
121
+ },
122
+ "pause": {
123
+ "glyph": "\u2016",
124
+ "nerd": "\u2016"
125
+ },
126
+ "alert": {
127
+ "glyph": "\u203c",
128
+ "nerd": "\u203c"
129
+ },
130
+ "pending": {
131
+ "glyph": "\u25cc",
132
+ "nerd": "\u25cc"
133
+ },
134
+ "minus": {
135
+ "glyph": "\u2212",
136
+ "nerd": "\u2212"
137
+ },
138
+ "ring": {
139
+ "glyph": "\u25cb",
140
+ "nerd": "\uf10c"
141
+ }
142
+ },
143
+ "outcomes": {
144
+ "ok": [
145
+ "passed",
146
+ "done",
147
+ "proved",
148
+ "shipped",
149
+ "merged"
150
+ ],
151
+ "warn": [
152
+ "parked",
153
+ "skipped",
154
+ "locked",
155
+ "nothing-to-take",
156
+ "rate-limited",
157
+ "budget-stop"
158
+ ],
159
+ "fail": [
160
+ "failed",
161
+ "check-failed",
162
+ "blocked",
163
+ "interrupted",
164
+ "none"
165
+ ]
166
+ }
167
+ };
package/dist/plan.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/plan.js ADDED
@@ -0,0 +1,133 @@
1
+ // kryso's planner. bin/kryso runs it and execs the plan it writes; that file explains the
2
+ // protocol. This side decides: an answer of kryso's own, or the driver commands.ts names.
3
+ import { accessSync, constants, statSync, writeSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { give, helpAnswer, refusal, say } from "./answer.js";
7
+ import { find, help, isAnswer, version } from "./commands.js";
8
+ import { EX_NOT_FOUND, EX_SOFTWARE, EX_USAGE } from "./env.js";
9
+ import { findHome, HomeNotFound } from "./home.js";
10
+ import { packageRoot, versionLabel } from "./install.js";
11
+ import { isolate } from "./isolate.js";
12
+ import { readRemote } from "./remote.js";
13
+ const PLAN_FD = 3;
14
+ const READER = path.join(path.dirname(fileURLToPath(import.meta.url)), "read.js");
15
+ /** The commands #176 renamed, each the subcommand it now is. They answer for one release. */
16
+ const RETIRED = {
17
+ "ship-loop": "shift",
18
+ "ship-pass": "pass",
19
+ "ship-ledger": "ledger",
20
+ "ship-it-status": "status",
21
+ warden: "watch",
22
+ };
23
+ const REMOVED_IN = "3.0.0";
24
+ /** One word for sh, quoted so `eval` reads it back unchanged. */
25
+ function shellQuote(word) {
26
+ return `'${word.replaceAll("'", `'\\''`)}'`;
27
+ }
28
+ function onPath(program, env) {
29
+ return (env.PATH ?? "").split(path.delimiter).some((dir) => {
30
+ const file = path.join(dir || ".", program);
31
+ try {
32
+ accessSync(file, constants.X_OK);
33
+ return statSync(file).isFile();
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ });
39
+ }
40
+ /** What the arguments ask for: an answer, or a driver to run. */
41
+ function resolve(argv, env) {
42
+ const [name, ...args] = argv;
43
+ if (name === undefined)
44
+ return helpAnswer(help(), "help", version(), EX_USAGE);
45
+ if (name === "-h" || name === "--help")
46
+ return helpAnswer(help(), "help", version());
47
+ if (name === "help") {
48
+ return args.length === 0
49
+ ? helpAnswer(help(), "help", version())
50
+ : refusal(EX_USAGE, "kryso", "help takes no command", { hint: `Run kryso ${args[0]} --help for that command's help.`, join: ". " });
51
+ }
52
+ if (name === "-V" || name === "--version") {
53
+ const label = versionLabel(packageRoot(), env);
54
+ return { text: `${version()} (${label})\n`, status: 0, draw: (s) => s.brand(version(), label) };
55
+ }
56
+ const command = find(name);
57
+ if (!command)
58
+ return refusal(EX_USAGE, "kryso", `unknown command '${name}'`, { hint: "Run kryso --help for the list.", join: ". " });
59
+ let home = "";
60
+ try {
61
+ if (!command.withoutDrivers)
62
+ home = findHome(env);
63
+ }
64
+ catch (err) {
65
+ if (err instanceof HomeNotFound)
66
+ return refusal(EX_SOFTWARE, "kryso", err.message);
67
+ throw err;
68
+ }
69
+ let target = command.target(home, args, env);
70
+ if (command.reads && !isAnswer(target)) {
71
+ // With a remote set, the same subcommand asks the daemon's read API, in a node process that
72
+ // bin/kryso execs as it would the script. With none, the script runs as it always has.
73
+ const url = readRemote(env);
74
+ if (url)
75
+ target = { program: "node", head: [READER, command.name, url], verbs: 0, script: "dist/read.js" };
76
+ }
77
+ if (command.isolates && !isAnswer(target)) {
78
+ target = isolate(command.name, target, args, {
79
+ env,
80
+ cwd: process.cwd(),
81
+ tty: Boolean(process.stdin.isTTY && process.stdout.isTTY),
82
+ uid: process.getuid?.() ?? 0,
83
+ gid: process.getgid?.() ?? 0,
84
+ // bin/kryso's own pid, which the driver or docker keeps when it execs. The planner's parent
85
+ // is the command substitution's subshell, which some shells fork.
86
+ pid: Number(process.env.__kryso_pid) || process.ppid,
87
+ now: Date.now(),
88
+ version: version(),
89
+ home,
90
+ });
91
+ }
92
+ if (!isAnswer(target) && !onPath(target.program, env)) {
93
+ return refusal(EX_NOT_FOUND, "kryso", `cannot run ${target.script}: ${target.program} is not on PATH`);
94
+ }
95
+ return target;
96
+ }
97
+ /** The plan bin/kryso reads: how many of its arguments to shift away, then the head of the
98
+ * command line. An old command name carries no subcommand in the arguments to shift. */
99
+ function plan(target, named) {
100
+ return `${(named ? 1 : 0) + target.verbs} ${[target.program, ...target.head].map(shellQuote).join(" ")}`;
101
+ }
102
+ function main() {
103
+ const as = process.env.__kryso_as ?? "";
104
+ const retired = Object.hasOwn(RETIRED, as) ? RETIRED[as] : undefined;
105
+ if (retired) {
106
+ say({
107
+ text: `${as}: this command is now \`kryso ${retired}\`, and the old name goes in kryso ${REMOVED_IN}\n`,
108
+ draw: (s) => s.warn(`${s.val(as)} is now ${s.val(`kryso ${retired}`)}, and the old name goes in kryso ${REMOVED_IN}`),
109
+ }, process.stderr);
110
+ }
111
+ const argv = process.argv.slice(2);
112
+ const result = resolve(retired ? [retired, ...argv] : argv, process.env);
113
+ if (isAnswer(result)) {
114
+ give(result);
115
+ process.exitCode = result.status;
116
+ return;
117
+ }
118
+ // bin/kryso names the descriptor it reads, so a planner started some other way never writes
119
+ // into a descriptor 3 it merely inherited.
120
+ if (process.env.__kryso_plan_fd !== String(PLAN_FD)) {
121
+ give(refusal(EX_SOFTWARE, "kryso", "dist/plan.js only plans the command", { hint: "Run kryso through bin/kryso, which runs the plan.", join: ". " }));
122
+ process.exitCode = EX_SOFTWARE;
123
+ return;
124
+ }
125
+ writeSync(PLAN_FD, plan(result, !retired));
126
+ }
127
+ try {
128
+ main();
129
+ }
130
+ catch (err) {
131
+ process.stderr.write(`kryso: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
132
+ process.exitCode = EX_SOFTWARE;
133
+ }
package/dist/proc.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export interface Captured {
2
+ ok: boolean;
3
+ /** The program is not on PATH. */
4
+ missing: boolean;
5
+ out: string;
6
+ err: string;
7
+ /** The exit status, or null when the program did not run to its end: missing, timed out or
8
+ * ended by a signal. */
9
+ status: number | null;
10
+ }
11
+ /** A question, which gets a minute to answer, or the milliseconds given, before it counts as
12
+ * failed. */
13
+ export declare function capture(program: string, args: string[], env: NodeJS.ProcessEnv, cwd?: string, timeout?: number): Captured;
14
+ export interface Streamed {
15
+ /** The exit status, or 128 plus the signal's number when a signal ended it. */
16
+ status: number;
17
+ /** The program could not be found, so it never ran. */
18
+ missing: boolean;
19
+ }
20
+ /** Why a captured program failed, in its last line of output, or its exit status. */
21
+ export declare const failure: (r: Captured) => string;
22
+ /** Runs the program on kryso's own terminal. */
23
+ export declare function stream(program: string, args: string[], env: NodeJS.ProcessEnv, cwd?: string): Streamed;
package/dist/proc.js ADDED
@@ -0,0 +1,23 @@
1
+ // The two ways kryso's own commands run another program: captured, for a question whose answer
2
+ // it reads, and streamed, for a step whose output belongs on the person's terminal.
3
+ import { spawnSync } from "node:child_process";
4
+ import { constants } from "node:os";
5
+ /** A question, which gets a minute to answer, or the milliseconds given, before it counts as
6
+ * failed. */
7
+ export function capture(program, args, env, cwd, timeout = 60_000) {
8
+ const r = spawnSync(program, args, { cwd, env, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout });
9
+ const missing = r.error?.code === "ENOENT";
10
+ const status = r.error ? null : r.status;
11
+ return { ok: status === 0, missing, out: (r.stdout ?? "").trim(), err: (r.stderr ?? "").trim(), status };
12
+ }
13
+ /** Why a captured program failed, in its last line of output, or its exit status. */
14
+ export const failure = (r) => (r.err || r.out).split("\n").at(-1) || `it exited ${r.status ?? "on a signal"}`;
15
+ /** Runs the program on kryso's own terminal. */
16
+ export function stream(program, args, env, cwd) {
17
+ const r = spawnSync(program, args, { cwd, env, stdio: "inherit" });
18
+ if (r.error?.code === "ENOENT")
19
+ return { status: 127, missing: true };
20
+ if (r.signal)
21
+ return { status: 128 + (constants.signals[r.signal] ?? 0), missing: false };
22
+ return { status: r.status ?? 70, missing: false };
23
+ }