@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.
- package/LICENSE +21 -0
- package/README.md +152 -2
- 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 +65 -4
- 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/dist/evidence.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// What diagnose.ts reads of the evidence: what it costs on disk in each repository, and whether it
|
|
2
|
+
// exists anywhere else. A repository's evidence is its shift folders and shipped copies under
|
|
3
|
+
// .claude/kryso, or .claude/ship-loop before the rename, read as archive.py reads them: each real
|
|
4
|
+
// directory once, a link the rename left never followed. Its largest logs are named with them.
|
|
5
|
+
//
|
|
6
|
+
// Whether the evidence exists anywhere else comes from the keep configuration the installed keep
|
|
7
|
+
// launch agent names, the archive's own status verb, which reads the upload queue and not the
|
|
8
|
+
// remote, and the newest health snapshot the keep wrote into the archive. The remote is not read.
|
|
9
|
+
// Those lines are the machine's, and a scope that holds no evidence gets none of them: with
|
|
10
|
+
// nothing to keep, a keep that is missing loses nothing.
|
|
11
|
+
//
|
|
12
|
+
// A shift folder or a shipped copy whose newest file is older than the retention period, 90 days
|
|
13
|
+
// unless kryso cleanup --older-than names another, is kryso cleanup --evidence's when every file
|
|
14
|
+
// in it is held, byte for byte, by an archive snapshot the upload queue records as verified on the
|
|
15
|
+
// keep's remote. Which archive snapshots those are comes from the same status verb, and what each
|
|
16
|
+
// holds is its manifest in the archive, read and never written. A copy with one file no such snapshot holds is
|
|
17
|
+
// a person's, kept whole.
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
import { size, sizeOf } from "./bytes.js";
|
|
23
|
+
import { startable } from "./commands.js";
|
|
24
|
+
import { capture, failure } from "./proc.js";
|
|
25
|
+
/** The state directories, the new name first, as archive.py's STATE_DIRS. */
|
|
26
|
+
const STATE_DIRS = [".claude/kryso", ".claude/ship-loop"];
|
|
27
|
+
/** How many of the largest logs are named. */
|
|
28
|
+
const LOGS = 3;
|
|
29
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
30
|
+
/** The longest the upload queue may hold a snapshot unverified before it is a warn. */
|
|
31
|
+
const BACKLOG_MS = DAY_MS;
|
|
32
|
+
/** How many days evidence stays before kryso cleanup --evidence may remove a copy the remote holds. */
|
|
33
|
+
export const RETENTION_DAYS = 90;
|
|
34
|
+
/** The keep's launch agents: the label archive_launchd.py installs, then the one before the rename. */
|
|
35
|
+
const KEEP_LABELS = ["io.github.krysoworks.kryso-keep", "com.github.jv-k.ship-archive.keep"];
|
|
36
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
37
|
+
const STAYS = "evidence stays until a person removes it";
|
|
38
|
+
function directories(at) {
|
|
39
|
+
try {
|
|
40
|
+
return readdirSync(at, { withFileTypes: true })
|
|
41
|
+
.filter((e) => e.isDirectory())
|
|
42
|
+
.map((e) => path.join(at, e.name))
|
|
43
|
+
.sort();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Every .log file under a directory, links never followed. */
|
|
50
|
+
function logs(at) {
|
|
51
|
+
let entries;
|
|
52
|
+
try {
|
|
53
|
+
entries = readdirSync(at, { withFileTypes: true });
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return entries.flatMap((e) => {
|
|
59
|
+
const p = path.join(at, e.name);
|
|
60
|
+
if (e.isDirectory())
|
|
61
|
+
return logs(p);
|
|
62
|
+
return e.isFile() && e.name.endsWith(".log") ? [p] : [];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** A repository's evidence: its state roots, each real directory once, and the shift folders and
|
|
66
|
+
* shipped copies under them. */
|
|
67
|
+
function copiesOf(repo) {
|
|
68
|
+
const roots = [];
|
|
69
|
+
for (const rel of STATE_DIRS) {
|
|
70
|
+
const at = path.join(repo, rel);
|
|
71
|
+
let st;
|
|
72
|
+
try {
|
|
73
|
+
st = lstatSync(at);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (st.isDirectory() && !roots.some((r) => realpathSync(r) === realpathSync(at)))
|
|
79
|
+
roots.push(at);
|
|
80
|
+
}
|
|
81
|
+
const shifts = roots.flatMap((r) => directories(r).filter((d) => path.basename(d) !== "shipped"));
|
|
82
|
+
const shipped = roots.flatMap((r) => directories(path.join(r, "shipped")));
|
|
83
|
+
return { roots, shifts, shipped };
|
|
84
|
+
}
|
|
85
|
+
/** The evidence group's diagnoses for the repository at repo, its main checkout. */
|
|
86
|
+
export function evidenceOf(repo) {
|
|
87
|
+
const { roots, shifts, shipped } = copiesOf(repo);
|
|
88
|
+
const base = { group: "evidence", severity: "info", fix: "person", repository: repo };
|
|
89
|
+
const where = path.relative(repo, roots[0] ?? path.join(repo, STATE_DIRS[0]));
|
|
90
|
+
const found = [];
|
|
91
|
+
for (const [id, dirs, one, many, under] of [
|
|
92
|
+
["evidence.shifts", shifts, "shift folder", "shift folders", where],
|
|
93
|
+
["evidence.shipped", shipped, "shipped copy", "shipped copies", path.join(where, "shipped")],
|
|
94
|
+
]) {
|
|
95
|
+
if (dirs.length === 0)
|
|
96
|
+
continue;
|
|
97
|
+
const bytes = dirs.reduce((sum, d) => sum + sizeOf(d), 0);
|
|
98
|
+
found.push({ ...base, id, subject: path.join(repo, under), bytes, text: `${plural(dirs.length, one, many)} under ${under} ${dirs.length === 1 ? "holds" : "hold"} ${size(bytes)}, and ${STAYS}` });
|
|
99
|
+
}
|
|
100
|
+
const largest = [...shifts, ...shipped]
|
|
101
|
+
.flatMap(logs)
|
|
102
|
+
.map((file) => ({ file, bytes: lstatSync(file).size }))
|
|
103
|
+
.sort((a, b) => b.bytes - a.bytes || a.file.localeCompare(b.file))
|
|
104
|
+
.slice(0, LOGS);
|
|
105
|
+
for (const { file, bytes } of largest) {
|
|
106
|
+
found.push({ ...base, id: "evidence.log", subject: file, bytes, text: `the log ${path.relative(repo, file)} holds ${size(bytes)}, one of the largest here` });
|
|
107
|
+
}
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
/** XML's five escapes, undone, for a string in a plist. */
|
|
111
|
+
const unxml = (s) => s.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("&", "&");
|
|
112
|
+
/** A path in a keep configuration: ~ is the home directory, and a relative one is from the file's
|
|
113
|
+
* directory, as archive.py's load_keep places it. */
|
|
114
|
+
function place(value, dir, user) {
|
|
115
|
+
if (typeof value !== "string" || value === "")
|
|
116
|
+
return undefined;
|
|
117
|
+
const held = value === "~" ? user : value.startsWith("~/") ? path.join(user, value.slice(2)) : value;
|
|
118
|
+
return path.isAbsolute(held) ? held : path.join(dir, held);
|
|
119
|
+
}
|
|
120
|
+
/** The time a health snapshot's name carries, or the newest snapshot's `at`, as the archive
|
|
121
|
+
* writes it: the newest file under <archive>/health/<day>/. */
|
|
122
|
+
function newestHealth(archive) {
|
|
123
|
+
const days = directories(path.join(archive, "health")).reverse();
|
|
124
|
+
for (const day of days) {
|
|
125
|
+
let names;
|
|
126
|
+
try {
|
|
127
|
+
names = readdirSync(day).filter((n) => n.endsWith(".json")).sort().reverse();
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (names.length === 0)
|
|
133
|
+
continue;
|
|
134
|
+
const file = path.join(day, names[0]);
|
|
135
|
+
try {
|
|
136
|
+
const doc = JSON.parse(readFileSync(file, "utf8"));
|
|
137
|
+
return { file, at: typeof doc.at === "string" ? doc.at : undefined };
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return { file, at: undefined };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
/** The keep configuration: the file named, or the one the installed keep launch agent names, read
|
|
146
|
+
* as archive.py's load_keep reads it, or why there is no usable one. */
|
|
147
|
+
export function keepOf(env, named) {
|
|
148
|
+
const user = env.HOME || os.homedir();
|
|
149
|
+
const agents = path.join(user, "Library", "LaunchAgents");
|
|
150
|
+
const base = { group: "evidence", fix: "person", severity: "warn" };
|
|
151
|
+
const plist = named ? undefined : KEEP_LABELS.map((label) => path.join(agents, `${label}.plist`)).find((p) => existsSync(p));
|
|
152
|
+
const config = named ?? (plist ? /<string>--config<\/string>\s*<string>([^<]*)<\/string>/.exec(readFileSync(plist, "utf8"))?.[1] : undefined);
|
|
153
|
+
if (!config) {
|
|
154
|
+
const at = plist ?? path.join(agents, `${KEEP_LABELS[0]}.plist`);
|
|
155
|
+
const why = plist ? `the launch agent ${at} names none` : `no keep launch agent is installed at ${at}`;
|
|
156
|
+
return {
|
|
157
|
+
why,
|
|
158
|
+
diagnosis: {
|
|
159
|
+
...base,
|
|
160
|
+
id: "evidence.keep-missing",
|
|
161
|
+
subject: at,
|
|
162
|
+
text: `no keep configuration found, because ${why}, so the evidence here exists on this machine alone; whether to keep it on a remote is a person's choice, which archiving-keep.md sets out`,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const file = named ? path.resolve(named) : unxml(config);
|
|
167
|
+
const unusable = (because) => {
|
|
168
|
+
const why = `the keep configuration ${file} ${plist ? `that ${plist} names` : "named with --config"} is unusable, because ${because}`;
|
|
169
|
+
return { why, diagnosis: { ...base, id: "evidence.keep-unusable", subject: file, text: `${why}, so no keep runs; a person puts it right` } };
|
|
170
|
+
};
|
|
171
|
+
let keep;
|
|
172
|
+
try {
|
|
173
|
+
keep = JSON.parse(readFileSync(file, "utf8"));
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
const code = err.code;
|
|
177
|
+
return unusable(code ? `it cannot be read (${code})` : "it is not valid JSON");
|
|
178
|
+
}
|
|
179
|
+
const archive = place(keep.archive, path.dirname(file), user);
|
|
180
|
+
if (!archive)
|
|
181
|
+
return unusable("it names no archive");
|
|
182
|
+
const remote = place(keep.remote, path.dirname(file), user);
|
|
183
|
+
return { file, ...(plist ? { plist } : {}), archive, ...(remote ? { remote } : {}) };
|
|
184
|
+
}
|
|
185
|
+
/** The archive's diagnoses, the machine's, with archive.py among the drivers, and the snapshots
|
|
186
|
+
* the remote has verified when the status verb said. The keep configuration is the one named, or
|
|
187
|
+
* the one the keep launch agent names. */
|
|
188
|
+
export function archiveOf(drivers, env, named, now = Date.now()) {
|
|
189
|
+
const keep = keepOf(env, named);
|
|
190
|
+
if ("why" in keep)
|
|
191
|
+
return { found: [keep.diagnosis] };
|
|
192
|
+
const { file, archive, remote } = keep;
|
|
193
|
+
const base = { group: "evidence", fix: "person" };
|
|
194
|
+
const health = newestHealth(archive);
|
|
195
|
+
const found = [];
|
|
196
|
+
if (!health) {
|
|
197
|
+
found.push({
|
|
198
|
+
...base,
|
|
199
|
+
id: "evidence.keep-never",
|
|
200
|
+
severity: "warn",
|
|
201
|
+
subject: file,
|
|
202
|
+
text: `no keep has run: the keep configuration ${file} names the archive ${archive}, which holds no health snapshot, so a person reads the keep's log to see why`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const ran = health ? `the last keep ran at ${health.at ?? `a time its health snapshot ${health.file} does not say`}` : undefined;
|
|
206
|
+
if (!remote) {
|
|
207
|
+
// No remote: the keep verifies nothing anywhere else, the newest verified upload never comes.
|
|
208
|
+
found.push({
|
|
209
|
+
...base,
|
|
210
|
+
id: "evidence.no-remote",
|
|
211
|
+
severity: "warn",
|
|
212
|
+
subject: file,
|
|
213
|
+
text: `the keep configuration ${file} names no remote, so the evidence the keep archives exists on this machine alone${ran ? `, and ${ran}` : ""}; whether to add one is a person's choice`,
|
|
214
|
+
});
|
|
215
|
+
return { found };
|
|
216
|
+
}
|
|
217
|
+
const args = ["status", "--archive", archive, "--remote", remote];
|
|
218
|
+
const target = drivers ? startable(drivers, "archive", args, env) : undefined;
|
|
219
|
+
const r = target ? capture(target.program, [...target.head, ...args], env) : undefined;
|
|
220
|
+
let status;
|
|
221
|
+
try {
|
|
222
|
+
status = r?.ok ? JSON.parse(r.out) : undefined;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
status = undefined;
|
|
226
|
+
}
|
|
227
|
+
if (!status) {
|
|
228
|
+
const why = !r ? "kryso cannot find archive.py" : r.ok ? "kryso archive status answered with no JSON" : `kryso archive status failed: ${failure(r)}`;
|
|
229
|
+
found.push({ ...base, id: "evidence.verified", severity: "info", unknown: true, subject: archive, text: `what the remote archive has verified is unknown, because ${why}${ran ? `; ${ran}` : ""}` });
|
|
230
|
+
return { found };
|
|
231
|
+
}
|
|
232
|
+
const verified = `the ${status.remote} remote has verified ${status.verified} of the archive's ${plural(status.snapshots, "snapshot", "snapshots")}${status.last_verified ? `, the last at ${status.last_verified}` : ""}`;
|
|
233
|
+
const pending = status.oldest_pending;
|
|
234
|
+
const queued = pending ? Date.parse(pending.queued) : NaN;
|
|
235
|
+
if (pending && !Number.isNaN(queued) && now - queued > BACKLOG_MS) {
|
|
236
|
+
found.push({
|
|
237
|
+
...base,
|
|
238
|
+
id: "evidence.backlog",
|
|
239
|
+
severity: "warn",
|
|
240
|
+
subject: archive,
|
|
241
|
+
text: `the upload queue has held snapshot ${pending.snapshot.slice(0, 12)} unverified since ${pending.queued}, more than 24 hours, so evidence since then may exist on this machine alone; ${verified}${ran ? `, and ${ran}` : ""}. A person reads the keep's log to see why uploads fail`,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
found.push({ ...base, id: "evidence.verified", severity: "info", subject: archive, text: `${verified}${ran ? `, and ${ran}` : ""}` });
|
|
246
|
+
}
|
|
247
|
+
const snapshots = (status.queue ?? []).filter((row) => row.state === "verified" && SNAPSHOT_ID.test(row.snapshot)).map((row) => row.snapshot);
|
|
248
|
+
return { found, verified: { archive, kind: status.remote, snapshots } };
|
|
249
|
+
}
|
|
250
|
+
const SNAPSHOT_ID = /^[0-9a-f]{64}$/;
|
|
251
|
+
/** What the verified snapshots hold, by the path each file was read from. A manifest that is not
|
|
252
|
+
* one the archive writes, or names another snapshot, vouches for nothing. */
|
|
253
|
+
function holdings(verified) {
|
|
254
|
+
const held = new Map();
|
|
255
|
+
for (const id of verified.snapshots) {
|
|
256
|
+
let doc;
|
|
257
|
+
try {
|
|
258
|
+
doc = JSON.parse(readFileSync(path.join(verified.archive, "snapshots", `${id}.json`), "utf8"));
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (!MANIFESTS.includes(doc.schema) || doc.snapshot?.id !== id || !Array.isArray(doc.entries))
|
|
264
|
+
continue;
|
|
265
|
+
for (const e of doc.entries) {
|
|
266
|
+
if (typeof e.source !== "string" || typeof e.sha256 !== "string" || typeof e.bytes !== "number")
|
|
267
|
+
continue;
|
|
268
|
+
held.set(e.source, [...(held.get(e.source) ?? []), { sha256: e.sha256, bytes: e.bytes }]);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return held;
|
|
272
|
+
}
|
|
273
|
+
/** The manifests archive.py writes, a pass's and a history capture's. */
|
|
274
|
+
const MANIFESTS = ["ship-archive-manifest/1", "ship-history-manifest/1"];
|
|
275
|
+
/** Every entry under a directory that is not itself a directory, links never followed. */
|
|
276
|
+
function entries(at) {
|
|
277
|
+
let names;
|
|
278
|
+
try {
|
|
279
|
+
names = readdirSync(at, { withFileTypes: true });
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
return names.flatMap((e) => (e.isDirectory() ? entries(path.join(at, e.name)) : [path.join(at, e.name)]));
|
|
285
|
+
}
|
|
286
|
+
/** The first file in a copy no verified snapshot holds as it is now, or undefined when they all
|
|
287
|
+
* are. A link or anything else that is not a regular file is never held, as a keep never collects
|
|
288
|
+
* one. */
|
|
289
|
+
function unheld(files, held) {
|
|
290
|
+
return files.find((file) => {
|
|
291
|
+
const st = lstatSync(file);
|
|
292
|
+
if (!st.isFile())
|
|
293
|
+
return true;
|
|
294
|
+
const sha256 = createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
295
|
+
const sources = [file, realpathSync(file)];
|
|
296
|
+
return !sources.some((s) => (held.get(s) ?? []).some((h) => h.sha256 === sha256 && h.bytes === st.size));
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/** The repository's shift folders and shipped copies whose newest file is older than the
|
|
300
|
+
* retention: cleanup's under --evidence when the verified snapshots hold every file in one, and a
|
|
301
|
+
* person's, kept whole, when they do not. A copy with no file in it has no age and is left out. */
|
|
302
|
+
export function pastRetention(repo, verified, days = RETENTION_DAYS, now = Date.now()) {
|
|
303
|
+
const { shifts, shipped } = copiesOf(repo);
|
|
304
|
+
let held;
|
|
305
|
+
const found = [];
|
|
306
|
+
for (const [what, dirs] of [
|
|
307
|
+
["shift folder", shifts],
|
|
308
|
+
["shipped copy", shipped],
|
|
309
|
+
]) {
|
|
310
|
+
for (const dir of dirs) {
|
|
311
|
+
const files = entries(dir).sort();
|
|
312
|
+
if (files.length === 0)
|
|
313
|
+
continue;
|
|
314
|
+
const newest = Math.max(...files.map((f) => lstatSync(f).mtimeMs));
|
|
315
|
+
if (now - newest <= days * DAY_MS)
|
|
316
|
+
continue;
|
|
317
|
+
held ??= holdings(verified);
|
|
318
|
+
const subject = `the ${what} ${path.relative(repo, dir)} is past the ${days}-day retention`;
|
|
319
|
+
const base = { group: "evidence", severity: "info", subject: dir, repository: repo, bytes: sizeOf(dir) };
|
|
320
|
+
const missing = unheld(files, held);
|
|
321
|
+
found.push(missing === undefined
|
|
322
|
+
? { ...base, id: "evidence.past-retention", fix: "cleanup", text: `${subject}, its newest file ${Math.floor((now - newest) / DAY_MS)} days old, and an archive snapshot the ${verified.kind} remote has verified holds every file in it, so kryso cleanup --evidence removes it` }
|
|
323
|
+
: { ...base, id: "evidence.past-retention-unheld", fix: "person", text: `${subject}, but no archive snapshot the ${verified.kind} remote has verified holds its file ${path.relative(dir, missing)} as it is now, so kryso cleanup --evidence keeps it whole` });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return found;
|
|
327
|
+
}
|
package/dist/home.d.ts
ADDED
package/dist/home.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Where the drivers are. A published package carries them beside dist/, copied in when it is
|
|
2
|
+
// packed. In this repository's workspace they are at the repository's root. KRYSO_HOME names
|
|
3
|
+
// another tree with the same layout, which the tests use.
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
const MARKER = path.join("skills", "kryso-shift", "ship-loop.sh");
|
|
8
|
+
export class HomeNotFound extends Error {
|
|
9
|
+
}
|
|
10
|
+
export function findHome(env = process.env, from = here()) {
|
|
11
|
+
const named = env.KRYSO_HOME;
|
|
12
|
+
if (named) {
|
|
13
|
+
if (existsSync(path.join(named, MARKER)))
|
|
14
|
+
return path.resolve(named);
|
|
15
|
+
throw new HomeNotFound(`KRYSO_HOME=${named} has no ${MARKER}`);
|
|
16
|
+
}
|
|
17
|
+
for (let dir = from;; dir = path.dirname(dir)) {
|
|
18
|
+
if (existsSync(path.join(dir, MARKER)))
|
|
19
|
+
return dir;
|
|
20
|
+
if (path.dirname(dir) === dir)
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
throw new HomeNotFound(`no ${MARKER} above ${from}, so the package is missing its drivers`);
|
|
24
|
+
}
|
|
25
|
+
function here() {
|
|
26
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Doctor } from "@krysoworks/core";
|
|
2
|
+
/** What install-skills.sh writes in install.json. */
|
|
3
|
+
export interface CheckoutRecord {
|
|
4
|
+
checkout: string;
|
|
5
|
+
branch: string | null;
|
|
6
|
+
sha: string;
|
|
7
|
+
installed: string;
|
|
8
|
+
bin: string | null;
|
|
9
|
+
}
|
|
10
|
+
export type PackageTool = "npm" | "pnpm" | "bun";
|
|
11
|
+
/** How each tool installs a global package, before the spec. */
|
|
12
|
+
export declare const ADD: Record<PackageTool, string[]>;
|
|
13
|
+
export type Install = {
|
|
14
|
+
kind: "checkout";
|
|
15
|
+
root: string;
|
|
16
|
+
version: string;
|
|
17
|
+
record: CheckoutRecord;
|
|
18
|
+
} | {
|
|
19
|
+
kind: PackageTool;
|
|
20
|
+
root: string;
|
|
21
|
+
version: string;
|
|
22
|
+
name: string;
|
|
23
|
+
globalRoot: string;
|
|
24
|
+
}
|
|
25
|
+
/** rest is the package's path inside the keg, which stays the same from one version to the next. */
|
|
26
|
+
| {
|
|
27
|
+
kind: "brew";
|
|
28
|
+
root: string;
|
|
29
|
+
version: string;
|
|
30
|
+
prefix: string;
|
|
31
|
+
formula: string;
|
|
32
|
+
rest: string;
|
|
33
|
+
}
|
|
34
|
+
/** found says, one line a kind, why it is none of them. */
|
|
35
|
+
| {
|
|
36
|
+
kind: "none";
|
|
37
|
+
root: string;
|
|
38
|
+
version: string;
|
|
39
|
+
name: string;
|
|
40
|
+
found: string[];
|
|
41
|
+
};
|
|
42
|
+
/** This package's own directory, with every link resolved, as node loaded it. */
|
|
43
|
+
export declare const packageRoot: () => string;
|
|
44
|
+
/** The path with every link resolved, or the path as given when it does not resolve. */
|
|
45
|
+
export declare const real: (dir: string) => string;
|
|
46
|
+
/** The record of the checkout install whose copy is at root, or nothing for any other install. */
|
|
47
|
+
export declare const checkoutRecord: (root?: string) => CheckoutRecord | undefined;
|
|
48
|
+
/** The install whose package is at root. The first kind that claims it wins, and the checks
|
|
49
|
+
* that need no program run first. */
|
|
50
|
+
export declare function detectInstall(root: string, env: NodeJS.ProcessEnv): Install;
|
|
51
|
+
export declare const LABELS: Record<Install["kind"], string>;
|
|
52
|
+
/** The kind told from the path and install.json alone, starting no program. Asking npm or pnpm
|
|
53
|
+
* for its global root can take seconds, or download a pnpm through corepack, so a package under
|
|
54
|
+
* some other node_modules is a global package of no named tool. */
|
|
55
|
+
export declare function pathKind(root: string, env: NodeJS.ProcessEnv): Doctor["install"]["kind"];
|
|
56
|
+
/** The kind as kryso --version names it after the version, from pathKind. */
|
|
57
|
+
export declare function versionLabel(root: string, env: NodeJS.ProcessEnv): string;
|
|
58
|
+
/** The formula of the Homebrew keg the package at root sits in: <prefix>/Cellar/<formula>/... */
|
|
59
|
+
export declare const formulaOf: (root: string) => string | undefined;
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// How this kryso was installed, told from where its package sits: a checkout install, which
|
|
2
|
+
// scripts/install-skills.sh records in install.json beside the copy; a global package of npm,
|
|
3
|
+
// pnpm or bun, under that tool's global root; a Homebrew keg, under brew --prefix's Cellar; or
|
|
4
|
+
// none of these. kryso self-update tells the kind and updates each its own way. kryso --version
|
|
5
|
+
// names it from the path alone, and starts no program to do so.
|
|
6
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { capture } from "./proc.js";
|
|
10
|
+
/** How each tool installs a global package, before the spec. */
|
|
11
|
+
export const ADD = { npm: ["install", "-g"], pnpm: ["add", "-g"], bun: ["add", "-g"] };
|
|
12
|
+
/** This package's own directory, with every link resolved, as node loaded it. */
|
|
13
|
+
export const packageRoot = () => realpathSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."));
|
|
14
|
+
const inside = (dir, parent) => {
|
|
15
|
+
const rel = path.relative(parent, dir);
|
|
16
|
+
return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
17
|
+
};
|
|
18
|
+
/** The path with every link resolved, or the path as given when it does not resolve. */
|
|
19
|
+
export const real = (dir) => {
|
|
20
|
+
try {
|
|
21
|
+
return realpathSync(dir);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return dir;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function readRecord(file) {
|
|
28
|
+
try {
|
|
29
|
+
const r = JSON.parse(readFileSync(file, "utf8"));
|
|
30
|
+
const nullable = (v) => v === null || typeof v === "string";
|
|
31
|
+
if (typeof r.checkout === "string" && typeof r.sha === "string" && typeof r.installed === "string" && nullable(r.branch) && nullable(r.bin)) {
|
|
32
|
+
return r;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Reported by the caller as a record it cannot read.
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
/** The record of the checkout install whose copy is at root, or nothing for any other install. */
|
|
41
|
+
export const checkoutRecord = (root = packageRoot()) => readRecord(path.join(root, "install.json"));
|
|
42
|
+
/** A tool's global root, or the line that says why there is none to look under. */
|
|
43
|
+
function toolRoot(tool, args, env) {
|
|
44
|
+
const r = capture(tool, args, env);
|
|
45
|
+
if (r.missing)
|
|
46
|
+
return { note: `${tool} is not on PATH` };
|
|
47
|
+
if (!r.ok || !r.out)
|
|
48
|
+
return { note: `${tool} ${args.join(" ")} failed` };
|
|
49
|
+
return r.out;
|
|
50
|
+
}
|
|
51
|
+
const bunRootOf = (env) => path.join(env.BUN_INSTALL_GLOBAL_DIR ?? path.join(env.BUN_INSTALL ?? path.join(env.HOME ?? "", ".bun"), "install", "global"), "node_modules");
|
|
52
|
+
/** A keg is <prefix>/Cellar/<formula>/<version>/, and the package sits somewhere inside it. */
|
|
53
|
+
const inACellar = (root) => root.split(path.sep).includes("Cellar");
|
|
54
|
+
/** The install whose package is at root. The first kind that claims it wins, and the checks
|
|
55
|
+
* that need no program run first. */
|
|
56
|
+
export function detectInstall(root, env) {
|
|
57
|
+
const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
|
|
58
|
+
const { name, version } = pkg;
|
|
59
|
+
const found = [];
|
|
60
|
+
const recordFile = path.join(root, "install.json");
|
|
61
|
+
if (existsSync(recordFile)) {
|
|
62
|
+
const record = readRecord(recordFile);
|
|
63
|
+
if (record)
|
|
64
|
+
return { kind: "checkout", root, version, record };
|
|
65
|
+
found.push(`${recordFile} is not one scripts/install-skills.sh wrote`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
found.push("no install.json beside it, which scripts/install-skills.sh writes for a checkout install");
|
|
69
|
+
}
|
|
70
|
+
if (inACellar(root)) {
|
|
71
|
+
const prefix = toolRoot("brew", ["--prefix"], env);
|
|
72
|
+
if (typeof prefix !== "string")
|
|
73
|
+
found.push(prefix.note);
|
|
74
|
+
else {
|
|
75
|
+
const cellar = path.join(real(prefix), "Cellar");
|
|
76
|
+
const [formula, kegVersion, ...rest] = path.relative(cellar, root).split(path.sep);
|
|
77
|
+
if (inside(root, cellar) && formula && kegVersion && rest.length > 0) {
|
|
78
|
+
return { kind: "brew", root, version, prefix, formula, rest: rest.join(path.sep) };
|
|
79
|
+
}
|
|
80
|
+
found.push(`not in Homebrew's Cellar ${cellar}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
found.push("not in a Homebrew Cellar");
|
|
85
|
+
}
|
|
86
|
+
const bunRoot = bunRootOf(env);
|
|
87
|
+
if (inside(root, real(bunRoot)))
|
|
88
|
+
return { kind: "bun", root, version, name, globalRoot: bunRoot };
|
|
89
|
+
found.push(`not under bun's global directory ${bunRoot}`);
|
|
90
|
+
for (const tool of ["pnpm", "npm"]) {
|
|
91
|
+
const globalRoot = toolRoot(tool, ["root", "-g"], env);
|
|
92
|
+
if (typeof globalRoot !== "string") {
|
|
93
|
+
found.push(globalRoot.note);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (inside(root, real(globalRoot)))
|
|
97
|
+
return { kind: tool, root, version, name, globalRoot };
|
|
98
|
+
found.push(`not under ${tool}'s global root ${globalRoot}`);
|
|
99
|
+
}
|
|
100
|
+
return { kind: "none", root, version, name, found };
|
|
101
|
+
}
|
|
102
|
+
export const LABELS = {
|
|
103
|
+
checkout: "checkout",
|
|
104
|
+
npm: "npm global",
|
|
105
|
+
pnpm: "pnpm global",
|
|
106
|
+
bun: "bun global",
|
|
107
|
+
brew: "Homebrew",
|
|
108
|
+
none: "unknown install",
|
|
109
|
+
};
|
|
110
|
+
/** The kind told from the path and install.json alone, starting no program. Asking npm or pnpm
|
|
111
|
+
* for its global root can take seconds, or download a pnpm through corepack, so a package under
|
|
112
|
+
* some other node_modules is a global package of no named tool. */
|
|
113
|
+
export function pathKind(root, env) {
|
|
114
|
+
if (readRecord(path.join(root, "install.json")))
|
|
115
|
+
return "checkout";
|
|
116
|
+
if (inACellar(root))
|
|
117
|
+
return "brew";
|
|
118
|
+
if (inside(root, real(bunRootOf(env))))
|
|
119
|
+
return "bun";
|
|
120
|
+
if (root.split(path.sep).includes("node_modules"))
|
|
121
|
+
return "package";
|
|
122
|
+
return "none";
|
|
123
|
+
}
|
|
124
|
+
/** The kind as kryso --version names it after the version, from pathKind. */
|
|
125
|
+
export function versionLabel(root, env) {
|
|
126
|
+
const record = readRecord(path.join(root, "install.json"));
|
|
127
|
+
if (record)
|
|
128
|
+
return `${LABELS.checkout}, ${record.branch ?? "detached HEAD"} at ${record.sha.slice(0, 7)}`;
|
|
129
|
+
const kind = pathKind(root, env);
|
|
130
|
+
return kind === "package" ? "global package" : LABELS[kind];
|
|
131
|
+
}
|
|
132
|
+
/** The formula of the Homebrew keg the package at root sits in: <prefix>/Cellar/<formula>/... */
|
|
133
|
+
export const formulaOf = (root) => {
|
|
134
|
+
const parts = root.split(path.sep);
|
|
135
|
+
const at = parts.lastIndexOf("Cellar");
|
|
136
|
+
return at >= 0 ? parts[at + 1] : undefined;
|
|
137
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Answer } from "./answer.js";
|
|
2
|
+
import type { Target } from "./commands.js";
|
|
3
|
+
export declare const IMAGE = "kryso-runner";
|
|
4
|
+
export declare const MODES: string[];
|
|
5
|
+
/** The file in the common git directory that says an isolated run is working the repository. */
|
|
6
|
+
export declare const PID_FILE = "kryso-isolated.json";
|
|
7
|
+
/** What the planner knows about the caller, so a test can state it. */
|
|
8
|
+
export interface Caller {
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
cwd: string;
|
|
11
|
+
/** Whether stdin and stdout are both terminals, which earns the container a terminal. */
|
|
12
|
+
tty: boolean;
|
|
13
|
+
uid: number;
|
|
14
|
+
gid: number;
|
|
15
|
+
/** The launcher's pid, which the docker client keeps, because the launcher execs it. */
|
|
16
|
+
pid: number;
|
|
17
|
+
now: number;
|
|
18
|
+
version: string;
|
|
19
|
+
/** The kryso home findHome returned, which holds skills/. */
|
|
20
|
+
home: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The target to run for `kryso <sub> [args...]`. Without `--isolate` first in args and without
|
|
24
|
+
* the config key, it is the given target unchanged. With `--isolate none` it is the same target
|
|
25
|
+
* with the flag consumed. With docker it is a `docker run` of the same driver, after a preflight
|
|
26
|
+
* whose every failure is an answer.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isolate(sub: string, target: Target, args: string[], caller: Caller): Target | Answer;
|