@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/work.js
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
// What diagnose.ts reads of the work in one repository: each worktree under .claude/worktrees with
|
|
2
|
+
// what its ledger and its pull request say, the pass lock files, the watch lock and the isolation
|
|
3
|
+
// file, and the merged local branches. This is where the ledger and the tracker are set side by
|
|
4
|
+
// side: kryso status reads only open pull requests, so a pass a person merged by hand reads as
|
|
5
|
+
// interrupted there and as merged here.
|
|
6
|
+
//
|
|
7
|
+
// Ledgers, checkpoints and receipts are read through the ledger module's `read`, and lock state
|
|
8
|
+
// through its `locked` and `isolated`, in one bash that sources the module, so no file the module
|
|
9
|
+
// owns is parsed here. GitHub is read through gh, read-only, and under the offline switch not at
|
|
10
|
+
// all: a diagnosis that needed a read that was skipped or refused is unknown, never a guess, and
|
|
11
|
+
// never of fix cleanup. Nothing here writes, and git runs with GIT_OPTIONAL_LOCKS=0 so a status
|
|
12
|
+
// does not refresh an index either.
|
|
13
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { sizeOf } from "./bytes.js";
|
|
16
|
+
import { real } from "./install.js";
|
|
17
|
+
import { capture } from "./proc.js";
|
|
18
|
+
const OFFLINE = "because --offline makes no GitHub read";
|
|
19
|
+
/** The most a gh list returns. A list this long may be cut short, so it proves no absence. */
|
|
20
|
+
const LIMIT = 1000;
|
|
21
|
+
/** The bash that sources the ledger module once and answers each item on one tab-separated line:
|
|
22
|
+
* `read:<worktree>`, `locked:<file>`, `isolated`, and `drop`, whether the module has the verb
|
|
23
|
+
* that removes a pass lock file under its lock. A stale isolation file stays, because the module
|
|
24
|
+
* leaves it in place under KRYSO_READ_ONLY. */
|
|
25
|
+
const BATCH = `source "$1" || exit 70
|
|
26
|
+
repo="$2"; shift 2
|
|
27
|
+
for a; do
|
|
28
|
+
case "$a" in
|
|
29
|
+
read:*) doc="$(ledger read "\${a#read:}" 2>/dev/null)" || doc=null; printf 'read\\t%s\\n' "\${doc:-null}" ;;
|
|
30
|
+
locked:*) s=0; ledger locked "\${a#locked:}" || s=$?; printf 'locked\\t%s\\n' "$s" ;;
|
|
31
|
+
drop) s=0; declare -F _ledger_drop >/dev/null || s=1; printf 'drop\\t%s\\n' "$s" ;;
|
|
32
|
+
isolated) why="$( { KRYSO_READ_ONLY=1 ledger isolated "$repo" >/dev/null; } 2>&1 )" && s=0 || s=$?; printf 'isolated\\t%s\\t%s\\n' "$s" "\${why//$'\\n'/ }" ;;
|
|
33
|
+
esac
|
|
34
|
+
done`;
|
|
35
|
+
/** A list of numbers as the text names them: `#21, #22`. */
|
|
36
|
+
const issues = (ns) => ns.map((n) => `#${n}`).join(", ");
|
|
37
|
+
const realOr = (p) => {
|
|
38
|
+
try {
|
|
39
|
+
return real(p);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return p;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** The work, locks and branches groups for the repository at repo, its top-level path, read
|
|
46
|
+
* through the ledger module among the drivers at home. With no ledger module to read through,
|
|
47
|
+
* the work and locks are one unknown diagnosis. */
|
|
48
|
+
export function workGroups(repo, home, offline, env) {
|
|
49
|
+
const ledger = home ? ledgerModule(home) : undefined;
|
|
50
|
+
const quiet = { ...env, GIT_OPTIONAL_LOCKS: "0" };
|
|
51
|
+
const git = (args, cwd = repo) => capture("git", args, quiet, cwd);
|
|
52
|
+
const common = git(["rev-parse", "--path-format=absolute", "--git-common-dir"]).out;
|
|
53
|
+
const listed = worktreeList(git(["worktree", "list", "--porcelain"]).out);
|
|
54
|
+
const main = listed[0]?.path ?? repo;
|
|
55
|
+
const at = (d) => {
|
|
56
|
+
const placed = { ...d, repository: main };
|
|
57
|
+
const what = judged.get(d);
|
|
58
|
+
if (what)
|
|
59
|
+
judged.set(placed, what);
|
|
60
|
+
return placed;
|
|
61
|
+
};
|
|
62
|
+
const gh = (args) => {
|
|
63
|
+
if (offline)
|
|
64
|
+
return { ok: false, why: OFFLINE };
|
|
65
|
+
const r = capture("gh", args, env, repo);
|
|
66
|
+
if (r.missing)
|
|
67
|
+
return { ok: false, why: "because gh is not on PATH" };
|
|
68
|
+
if (!r.ok)
|
|
69
|
+
return { ok: false, why: `because gh refused: ${(r.err || r.out).split("\n")[0] || "it gave no reason"}` };
|
|
70
|
+
try {
|
|
71
|
+
return { ok: true, value: JSON.parse(r.out) };
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return { ok: false, why: "because gh answered with no JSON" };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const r = { main, listed, git, gh };
|
|
78
|
+
if (!ledger) {
|
|
79
|
+
return [
|
|
80
|
+
at({ id: "work.unreadable", group: "work", severity: "info", fix: "person", unknown: true, subject: main, text: `the worktrees and locks of ${main} are unknown, because kryso cannot find its ledger module` }),
|
|
81
|
+
...branchesGroup(r).map(at),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
// The worktrees, the pass lock files and the isolation file, read in one bash.
|
|
85
|
+
const dir = path.join(main, ".claude", "worktrees");
|
|
86
|
+
const trees = existsSync(dir)
|
|
87
|
+
? readdirSync(dir, { withFileTypes: true })
|
|
88
|
+
.filter((e) => e.isDirectory())
|
|
89
|
+
.map((e) => path.join(dir, e.name))
|
|
90
|
+
.sort()
|
|
91
|
+
: [];
|
|
92
|
+
const locks = common && existsSync(common) ? readdirSync(common).filter((n) => /^ship-it-pass-\d+\.lock$/.test(n)).sort((a, b) => issueOf(a) - issueOf(b)) : [];
|
|
93
|
+
const isolation = common ? path.join(common, "kryso-isolated.json") : "";
|
|
94
|
+
const items = [
|
|
95
|
+
...trees.map((t) => `read:${t}`),
|
|
96
|
+
...locks.map((n) => `locked:${path.join(common, n)}`),
|
|
97
|
+
...(locks.length > 0 ? ["drop"] : []),
|
|
98
|
+
...(isolation && existsSync(isolation) ? ["isolated"] : []),
|
|
99
|
+
];
|
|
100
|
+
const answers = items.length > 0 ? capture("bash", ["-c", BATCH, "kryso-doctor", ledger, repo, ...items], quiet, repo).out.split("\n").map((l) => l.split("\t")) : [];
|
|
101
|
+
const answer = (kind, i) => answers.filter((a) => a[0] === kind)[i];
|
|
102
|
+
// A read that failed is null, which is unknown, never a worktree with no ledger.
|
|
103
|
+
const docs = trees.map((_, i) => {
|
|
104
|
+
try {
|
|
105
|
+
return JSON.parse(answer("read", i)?.[1] ?? "null");
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const work = trees.flatMap((wt, i) => worktree(wt, docs[i] ?? null, r));
|
|
112
|
+
const lockStates = locks.map((n, i) => ({ issue: issueOf(n), held: answer("locked", i)?.[1] }));
|
|
113
|
+
const kept = new Set(docs.map((d) => Number(d?.header?.issue)).filter((n) => n > 0));
|
|
114
|
+
const isolated = answer("isolated", 0);
|
|
115
|
+
const droppable = answer("drop", 0)?.[1] === "0";
|
|
116
|
+
return [...work, ...passLocks(lockStates, kept, droppable, common, gh), ...deadFiles(main, isolation, isolated), ...branchesGroup(r)].map(at);
|
|
117
|
+
}
|
|
118
|
+
/** The pass a worktree's ledger names, read through the ledger module among the drivers at home,
|
|
119
|
+
* or undefined when it names no issue or cannot be read. The doctor document has no field for it,
|
|
120
|
+
* so a reader of a diagnosis asks the module again. */
|
|
121
|
+
export function passOf(wt, home, env) {
|
|
122
|
+
const r = capture("bash", [path.join(home, "skills", "kryso", LEDGER), "read", wt], { ...env, GIT_OPTIONAL_LOCKS: "0" }, wt);
|
|
123
|
+
try {
|
|
124
|
+
const header = JSON.parse(r.out).header;
|
|
125
|
+
return header?.issue ? { issue: header.issue, branch: header.branch } : undefined;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const issueOf = (name) => Number(/(\d+)/.exec(name)[1]);
|
|
132
|
+
const LEDGER = "ledger.sh";
|
|
133
|
+
/** The ledger module among the drivers at home, or undefined when the install has none. */
|
|
134
|
+
export function ledgerModule(home) {
|
|
135
|
+
const module = path.join(home, "skills", "kryso", LEDGER);
|
|
136
|
+
return existsSync(module) ? module : undefined;
|
|
137
|
+
}
|
|
138
|
+
/** What a cleanup diagnosis was judged on and the document has no field for: the tip a merged
|
|
139
|
+
* branch was judged at, and the issues whose lock files a locks diagnosis counts. It is kept
|
|
140
|
+
* beside the diagnosis object this module built, so kryso cleanup acts on what was judged and
|
|
141
|
+
* never on a later read or on the text. */
|
|
142
|
+
const judged = new WeakMap();
|
|
143
|
+
/** The tip a branches diagnosis judged its branch merged at. */
|
|
144
|
+
export const tipOf = (d) => judged.get(d)?.tip;
|
|
145
|
+
/** The pass lock files a locks diagnosis counts, in the directory its subject names. */
|
|
146
|
+
export function lockFiles(d) {
|
|
147
|
+
const dir = path.dirname(d.subject);
|
|
148
|
+
return (judged.get(d)?.issues ?? []).map((n) => ({ issue: String(n), file: path.join(dir, `ship-it-pass-${n}.lock`) }));
|
|
149
|
+
}
|
|
150
|
+
/** `git worktree list --porcelain`, the main checkout first, each with the branch it has. */
|
|
151
|
+
function worktreeList(out) {
|
|
152
|
+
return out
|
|
153
|
+
.split("\n\n")
|
|
154
|
+
.map((block) => {
|
|
155
|
+
const lines = block.split("\n");
|
|
156
|
+
const at = lines.find((l) => l.startsWith("worktree "))?.slice(9);
|
|
157
|
+
const branch = lines.find((l) => l.startsWith("branch refs/heads/"))?.slice(18);
|
|
158
|
+
return at ? { path: at, branch } : undefined;
|
|
159
|
+
})
|
|
160
|
+
.filter((w) => w !== undefined);
|
|
161
|
+
}
|
|
162
|
+
/** The pull request a branch has: the pass's own merged one first, then an open one, then a closed
|
|
163
|
+
* one, and the merged ones of earlier passes on the same branch name, which are not its own (#697).
|
|
164
|
+
* A merged pull request is the pass's own when its number is the one the ledger names, or its
|
|
165
|
+
* head is the checkpoint's or the worktree's tip, the check the branches group makes. */
|
|
166
|
+
function pullRequest(branch, gh, own) {
|
|
167
|
+
const r = gh(["pr", "list", "--head", branch, "--state", "all", "--json", "number,state,headRefOid"]);
|
|
168
|
+
if (!r.ok)
|
|
169
|
+
return r;
|
|
170
|
+
const merged = r.value.filter((p) => p.state === "MERGED");
|
|
171
|
+
let heads;
|
|
172
|
+
const isOwn = (p) => p.number === own.number || (!!p.headRefOid && (heads ??= own.heads()).includes(p.headRefOid));
|
|
173
|
+
const pr = merged.find(isOwn) ?? r.value.find((p) => p.state === "OPEN") ?? r.value.find((p) => p.state === "CLOSED");
|
|
174
|
+
return { ok: true, value: { pr, earlier: merged.filter((p) => !isOwn(p)).map((p) => p.number).sort((a, b) => a - b) } };
|
|
175
|
+
}
|
|
176
|
+
/** The number of a pull request the ledger names as a URL, `#<n>` or a number, or undefined. */
|
|
177
|
+
const prNumber = (pr) => {
|
|
178
|
+
const m = /^#?(\d+)$|\/pull\/(\d+)\/?$/.exec(String(pr ?? ""));
|
|
179
|
+
return m ? Number(m[1] ?? m[2]) : undefined;
|
|
180
|
+
};
|
|
181
|
+
/** One worktree's diagnoses: the worktree itself, then each abandoned receipt. A ledger the
|
|
182
|
+
* module could not read is one unknown diagnosis. */
|
|
183
|
+
function worktree(wt, doc, { main, listed, git, gh }) {
|
|
184
|
+
const rel = path.relative(main, wt);
|
|
185
|
+
if (doc === null) {
|
|
186
|
+
return [{ id: "work.unreadable", group: "work", severity: "info", fix: "person", unknown: true, subject: wt, text: `${rel}: its ledger and its pull request are unknown, because the ledger module could not read it` }];
|
|
187
|
+
}
|
|
188
|
+
const ledgered = doc.ledger === true;
|
|
189
|
+
const issue = ledgered ? doc.header?.issue : undefined;
|
|
190
|
+
const on = listed.find((w) => realOr(w.path) === realOr(wt))?.branch;
|
|
191
|
+
const branch = (ledgered && doc.header?.branch) || on;
|
|
192
|
+
const who = issue ? `${rel} for #${issue}` : `${rel} on ${on ?? "a detached HEAD"}`;
|
|
193
|
+
const script = ledgered && (doc.owner?.via === "handoff" ? doc.owner.engine === "script" : doc.engine === "script");
|
|
194
|
+
const engine = doc.engine === "script" ? "script engine's" : "/kryso engine's";
|
|
195
|
+
const stage = doc.stage;
|
|
196
|
+
const ledgerSays = ledgered && stage ? `its ${engine} ledger is at ${stage.name} ${stage.status}${stage.word ? ` ${stage.word}` : ""}` : "it has no ledger";
|
|
197
|
+
const own = {
|
|
198
|
+
number: ledgered ? prNumber(doc.pr) : undefined,
|
|
199
|
+
heads: () => [ledgered ? doc.checkpoint?.head : undefined, doc.tree?.head ?? git(["rev-parse", "HEAD"], wt).out].filter((h) => !!h && h !== "none"),
|
|
200
|
+
};
|
|
201
|
+
const read = branch ? pullRequest(branch, gh, own) : { ok: true, value: { pr: undefined, earlier: [] } };
|
|
202
|
+
const pr = read.ok ? read.value.pr : undefined;
|
|
203
|
+
const earlier = read.ok ? read.value.earlier : [];
|
|
204
|
+
const prSays = !read.ok
|
|
205
|
+
? `whether it has a pull request is unknown, ${read.why}`
|
|
206
|
+
: !pr
|
|
207
|
+
? earlier.length > 0
|
|
208
|
+
? `it has no pull request of its own, because ${issues(earlier)} merged at other heads`
|
|
209
|
+
: "it has no pull request"
|
|
210
|
+
: `its pull request #${pr.number} ${pr.state === "MERGED" ? "merged" : pr.state === "OPEN" ? "is open" : "was closed unmerged"}`;
|
|
211
|
+
const unknown = read.ok ? {} : { unknown: true };
|
|
212
|
+
const base = { group: "work", subject: wt, ...unknown };
|
|
213
|
+
const says = `${who}: ${ledgerSays}, and ${prSays}`;
|
|
214
|
+
const found = [];
|
|
215
|
+
// Off its ledger's branch, or behind its checkpoint's head: nothing resumes it until a person
|
|
216
|
+
// reads it, which is the resume's own refusal.
|
|
217
|
+
let moved;
|
|
218
|
+
if (ledgered && doc.header?.branch && on !== doc.header.branch) {
|
|
219
|
+
moved = `it is on ${on ?? "a detached HEAD"}, not its ledger's branch ${doc.header.branch}`;
|
|
220
|
+
}
|
|
221
|
+
else if (ledgered && doc.checkpoint?.head && doc.checkpoint.head !== "none" && !git(["merge-base", "--is-ancestor", doc.checkpoint.head, "HEAD"], wt).ok) {
|
|
222
|
+
moved = `its HEAD ${(doc.tree?.head ?? "").slice(0, 7)} does not contain its checkpoint's head ${doc.checkpoint.head.slice(0, 7)}`;
|
|
223
|
+
}
|
|
224
|
+
if (pr?.state === "MERGED" && moved) {
|
|
225
|
+
// The resume that closes a merged pass out refuses a moved tree first, so it is a person's.
|
|
226
|
+
found.push({ ...base, id: "work.merged", severity: "warn", fix: "person", text: `${says}; it reads as merged, but ${moved}, so a person reads it before anything closes it out` });
|
|
227
|
+
}
|
|
228
|
+
else if (pr?.state === "MERGED") {
|
|
229
|
+
const merged = `${says}; it reads as merged, and `;
|
|
230
|
+
const add = (d) => found.push({ ...base, id: "work.merged", severity: "warn", ...d });
|
|
231
|
+
if (script) {
|
|
232
|
+
// A pass that runs in it, or a receipt still open, leaves it to that run: cleanup never races
|
|
233
|
+
// one. A lock the module cannot read is unknown, and nothing unknown is cleanup's.
|
|
234
|
+
const open = doc.receipts.find((r) => r.state === "open");
|
|
235
|
+
if (doc.active === true)
|
|
236
|
+
add({ fix: "person", text: `${merged}a live pass holds it, so kryso cleanup leaves it to that pass` });
|
|
237
|
+
else if (doc.active !== false)
|
|
238
|
+
add({ fix: "person", unknown: true, text: `${merged}whether a live pass holds it is unknown, because the ledger module cannot read its lock, so kryso cleanup leaves it` });
|
|
239
|
+
else if (open)
|
|
240
|
+
add({ fix: "person", text: `${merged}its receipt ${ledgerFile(doc, open.file)} is open, so kryso cleanup leaves it until that command ends` });
|
|
241
|
+
else
|
|
242
|
+
add({ fix: "cleanup", bytes: sizeOf(wt), text: `${merged}kryso cleanup closes the pass out` });
|
|
243
|
+
}
|
|
244
|
+
else if (ledgered)
|
|
245
|
+
add({ fix: "person", text: `${merged}a person closes it out, because kryso pass resumes only the script engine's ledgers` });
|
|
246
|
+
else
|
|
247
|
+
add({ fix: "person", text: `${merged}a person removes it` });
|
|
248
|
+
}
|
|
249
|
+
else if (moved) {
|
|
250
|
+
found.push({ ...base, id: "work.moved", severity: "warn", fix: "person", text: `${says}; ${moved}, so a person reads it before anything resumes it` });
|
|
251
|
+
}
|
|
252
|
+
else if (script && doc.active !== true && pr?.state !== "CLOSED" && resumable(doc)) {
|
|
253
|
+
found.push({ ...base, id: "work.resumable", severity: "info", fix: "command", text: `${says}; a resume can continue it`, command: `kryso pass ${issue} --resume` });
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const why = pr?.state === "CLOSED" ? "whether to reopen its pull request or drop the change is a person's decision" : whyPerson(doc, script, issue);
|
|
257
|
+
found.push({ ...base, id: "work.worktree", severity: "info", fix: "person", text: `${says}; ${why}` });
|
|
258
|
+
}
|
|
259
|
+
for (const receipt of ledgered ? doc.receipts.filter((r) => r.state === "abandoned") : []) {
|
|
260
|
+
found.push({
|
|
261
|
+
id: "work.receipt-abandoned",
|
|
262
|
+
group: "work",
|
|
263
|
+
severity: "warn",
|
|
264
|
+
fix: "person",
|
|
265
|
+
subject: path.join(wt, ledgerFile(doc, receipt.file)),
|
|
266
|
+
text: `${who}: its receipt ${ledgerFile(doc, receipt.file)} is abandoned, because no live process can close it, so its command never finished`,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return found;
|
|
270
|
+
}
|
|
271
|
+
/** A file the ledger names, such as logs/<name>.log, by its path in the worktree, under the ledger
|
|
272
|
+
* directory the module's read names, so the doctor keeps no copy of the layout. */
|
|
273
|
+
const ledgerFile = (doc, file) => (doc.dir ? `${doc.dir}/${file}` : file);
|
|
274
|
+
/** Whether `kryso pass <issue> --resume` would re-enter the stage, by the disposition the ledger
|
|
275
|
+
* module gives it: resumable, or a spent rerun at reconcile or over a tree that changed since. */
|
|
276
|
+
function resumable(doc) {
|
|
277
|
+
if (doc.disposition === "resumable")
|
|
278
|
+
return true;
|
|
279
|
+
return doc.disposition === "retry-exhausted" && (doc.stage?.name === "reconcile" || doc.tree?.moved === true);
|
|
280
|
+
}
|
|
281
|
+
/** Why a worktree no resume continues is a person's. */
|
|
282
|
+
function whyPerson(doc, script, issue) {
|
|
283
|
+
if (!doc.ledger)
|
|
284
|
+
return "nothing resumes a worktree with no ledger, so it is a person's";
|
|
285
|
+
if (!script)
|
|
286
|
+
return "it is the /kryso engine's to continue, not kryso pass's";
|
|
287
|
+
if (doc.active === true)
|
|
288
|
+
return "a live pass is working it";
|
|
289
|
+
switch (doc.disposition) {
|
|
290
|
+
case "human-decision":
|
|
291
|
+
return "its park is a person's decision";
|
|
292
|
+
case "prerequisite":
|
|
293
|
+
return `put right what its park names, then resume it with kryso pass ${issue} --resume`;
|
|
294
|
+
case "retry-exhausted":
|
|
295
|
+
return "its rerun is spent and its tree has not changed since, so a person fixes the tree first";
|
|
296
|
+
case "terminal":
|
|
297
|
+
return "its pass ended, and no resume has anything left to do";
|
|
298
|
+
default:
|
|
299
|
+
return `its disposition ${doc.disposition ?? "is missing"}, which no resume reads as resumable`;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** The pass lock files nothing holds, one diagnosis per state with a count. A held lock is a
|
|
303
|
+
* live pass and no diagnosis. A closed issue's file is cleanup's only when no worktree's ledger
|
|
304
|
+
* names the issue, an issue is closed only when the open list gh gave was whole, and only a
|
|
305
|
+
* ledger module that can drop a lock file, removing it under its lock, makes any of them
|
|
306
|
+
* cleanup's: kryso cleanup never unlinks one itself. */
|
|
307
|
+
function passLocks(states, kept, droppable, common, gh) {
|
|
308
|
+
const unheld = states.filter((s) => s.held === "1").map((s) => s.issue);
|
|
309
|
+
const unreadable = states.filter((s) => s.held !== "0" && s.held !== "1").map((s) => s.issue);
|
|
310
|
+
const subject = path.join(common, "ship-it-pass-*.lock");
|
|
311
|
+
const count = (ns) => `${ns.length} pass lock file${ns.length === 1 ? "" : "s"}`;
|
|
312
|
+
const found = [];
|
|
313
|
+
const add = (id, fix, ns, what, unknown = false) => {
|
|
314
|
+
if (ns.length === 0)
|
|
315
|
+
return;
|
|
316
|
+
const d = { id, group: "locks", severity: "info", fix, subject, ...(unknown ? { unknown } : {}), text: `${count(ns)} ${what}: ${issues(ns)}` };
|
|
317
|
+
judged.set(d, { issues: ns });
|
|
318
|
+
found.push(d);
|
|
319
|
+
};
|
|
320
|
+
if (unheld.length > 0) {
|
|
321
|
+
const open = gh(["issue", "list", "--state", "open", "--limit", String(LIMIT), "--json", "number"]);
|
|
322
|
+
if (!open.ok)
|
|
323
|
+
add("locks.pass-unknown", "person", unheld, `nothing holds, for issues whose state is unknown, ${open.why}`, true);
|
|
324
|
+
else {
|
|
325
|
+
const isOpen = new Set(open.value.map((i) => i.number));
|
|
326
|
+
const whole = open.value.length < LIMIT;
|
|
327
|
+
const closed = unheld.filter((n) => !isOpen.has(n) && whole);
|
|
328
|
+
const gone = closed.filter((n) => !kept.has(n));
|
|
329
|
+
if (droppable)
|
|
330
|
+
add("locks.pass-closed", "cleanup", gone, "nothing holds, for closed issues with no worktree left");
|
|
331
|
+
else
|
|
332
|
+
add("locks.pass-closed", "person", gone, "nothing holds, for closed issues with no worktree left, which kryso cleanup leaves, because this ledger module has no drop verb to remove them under their lock");
|
|
333
|
+
add("locks.pass-open", "person", unheld.filter((n) => isOpen.has(n)), "nothing holds, for open issues");
|
|
334
|
+
add("locks.pass-worktree", "person", closed.filter((n) => kept.has(n)), "nothing holds, for closed issues whose worktree is left");
|
|
335
|
+
add("locks.pass-unknown", "person", unheld.filter((n) => !isOpen.has(n) && !whole), `nothing holds, for issues whose state is unknown, because gh lists only the first ${LIMIT} open issues`, true);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
add("locks.pass-unreadable", "person", unreadable, "whose holder cannot be read, because the ledger module cannot take or test their lock", true);
|
|
339
|
+
return found;
|
|
340
|
+
}
|
|
341
|
+
/** A watch lock whose pid is not running, and an isolation file the ledger module's `isolated`
|
|
342
|
+
* finds no run behind, which it leaves in place under KRYSO_READ_ONLY. A watch lock is the pid
|
|
343
|
+
* file warden.sh's take_lock writes, which no ledger verb reads. The state directory's old name
|
|
344
|
+
* may be a link to the new one, so a file is named once. */
|
|
345
|
+
function deadFiles(main, isolation, isolated) {
|
|
346
|
+
const found = [];
|
|
347
|
+
const seen = new Set();
|
|
348
|
+
for (const file of [path.join(main, ".claude", "kryso-watch", "lock"), path.join(main, ".claude", "warden", "lock")]) {
|
|
349
|
+
if (!existsSync(file) || seen.has(realOr(file)))
|
|
350
|
+
continue;
|
|
351
|
+
seen.add(realOr(file));
|
|
352
|
+
const pid = readFileSync(file, "utf8").split(/\s/)[0] ?? "";
|
|
353
|
+
if (/^\d+$/.test(pid) && running(Number(pid)))
|
|
354
|
+
continue;
|
|
355
|
+
const named = /^\d+$/.test(pid) ? `names pid ${pid}, which is not running` : "names no pid";
|
|
356
|
+
found.push({ id: "locks.dead", group: "locks", severity: "warn", fix: "person", subject: file, text: `the watch lock ${file} ${named}, so the next watch here stops until a person removes it` });
|
|
357
|
+
}
|
|
358
|
+
// Status 1 is no run, and a file still there is a stale one. The module's line says why.
|
|
359
|
+
if (isolated?.[1] === "1" && existsSync(isolation)) {
|
|
360
|
+
const why = /is stale: (.*), and KRYSO_READ_ONLY/.exec(isolated[2] ?? "")?.[1] ?? "no isolated run is behind it";
|
|
361
|
+
found.push({
|
|
362
|
+
id: "locks.dead",
|
|
363
|
+
group: "locks",
|
|
364
|
+
severity: "warn",
|
|
365
|
+
fix: "person",
|
|
366
|
+
subject: isolation,
|
|
367
|
+
text: `the isolation file ${isolation} is stale: ${why}, so a person removes it once no isolated run works this repository`,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
return found;
|
|
371
|
+
}
|
|
372
|
+
function running(pid) {
|
|
373
|
+
try {
|
|
374
|
+
process.kill(pid, 0);
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
return err.code === "EPERM";
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** The merged local branches: a tip on the default branch on origin, or a pull request merged at
|
|
382
|
+
* the local tip. The default branch is not listed, and integration/*, the current branch and a
|
|
383
|
+
* branch a worktree has checked out are never cleanup's. */
|
|
384
|
+
function branchesGroup({ main, listed, git, gh }) {
|
|
385
|
+
const refs = git(["for-each-ref", "--format=%(refname:short)%09%(objectname)", "refs/heads"])
|
|
386
|
+
.out.split("\n")
|
|
387
|
+
.filter(Boolean)
|
|
388
|
+
.map((l) => l.split("\t"));
|
|
389
|
+
let onOrigin = git(["symbolic-ref", "-q", "--short", "refs/remotes/origin/HEAD"]).out;
|
|
390
|
+
if (!onOrigin)
|
|
391
|
+
onOrigin = ["origin/main", "origin/master"].find((r) => git(["rev-parse", "-q", "--verify", `refs/remotes/${r}`]).ok) ?? "";
|
|
392
|
+
const merged = new Set(onOrigin ? git(["for-each-ref", `--merged=refs/remotes/${onOrigin}`, "--format=%(refname:short)", "refs/heads"]).out.split("\n") : []);
|
|
393
|
+
const current = git(["symbolic-ref", "-q", "--short", "HEAD"]).out;
|
|
394
|
+
let prs;
|
|
395
|
+
const found = [];
|
|
396
|
+
const unknown = [];
|
|
397
|
+
let why = "";
|
|
398
|
+
for (const [name, tip] of refs) {
|
|
399
|
+
if (onOrigin && name === onOrigin.replace(/^origin\//, ""))
|
|
400
|
+
continue;
|
|
401
|
+
let how;
|
|
402
|
+
if (merged.has(name))
|
|
403
|
+
how = `its tip is on ${onOrigin}`;
|
|
404
|
+
else {
|
|
405
|
+
// A squash merge older than the list is not found, so the branch is left out, never guessed.
|
|
406
|
+
prs ??= gh(["pr", "list", "--state", "merged", "--limit", String(LIMIT), "--json", "number,headRefName,headRefOid"]);
|
|
407
|
+
if (!prs.ok) {
|
|
408
|
+
unknown.push(name);
|
|
409
|
+
why = prs.why;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
const pr = prs.value.find((p) => p.headRefName === name && p.headRefOid === tip);
|
|
413
|
+
if (pr)
|
|
414
|
+
how = `its pull request #${pr.number} merged at its tip ${tip.slice(0, 7)}`;
|
|
415
|
+
}
|
|
416
|
+
if (!how)
|
|
417
|
+
continue;
|
|
418
|
+
const text = `the local branch ${name} is merged: ${how}`;
|
|
419
|
+
const holder = listed.find((w) => w.branch === name);
|
|
420
|
+
const keep = name.startsWith("integration/")
|
|
421
|
+
? "it is an integration branch"
|
|
422
|
+
: name === current
|
|
423
|
+
? "it is the current branch"
|
|
424
|
+
: holder
|
|
425
|
+
? `the worktree ${holder.path} has it checked out`
|
|
426
|
+
: undefined;
|
|
427
|
+
if (keep)
|
|
428
|
+
found.push({ id: "branches.kept", group: "branches", severity: "info", fix: "person", subject: name, text: `${text}, and kryso cleanup keeps it, because ${keep}` });
|
|
429
|
+
else {
|
|
430
|
+
const d = { id: "branches.merged", group: "branches", severity: "info", fix: "cleanup", subject: name, text };
|
|
431
|
+
judged.set(d, { tip });
|
|
432
|
+
found.push(d);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (unknown.length > 0) {
|
|
436
|
+
const n = unknown.length;
|
|
437
|
+
const against = onOrigin ? `not on ${onOrigin}` : "on no default branch of origin";
|
|
438
|
+
found.push({
|
|
439
|
+
id: "branches.unknown",
|
|
440
|
+
group: "branches",
|
|
441
|
+
severity: "info",
|
|
442
|
+
fix: "person",
|
|
443
|
+
unknown: true,
|
|
444
|
+
subject: main,
|
|
445
|
+
text: `${n} local branch${n === 1 ? " is" : "es are"} ${against}, and whether their pull requests merged is unknown, ${why}`,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
return found;
|
|
449
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Diagnosis } from "@krysoworks/core";
|
|
2
|
+
/** The repository group's workflow diagnoses for the repository at repo, its top-level path, named
|
|
3
|
+
* by main, its main checkout, with the drivers at home. */
|
|
4
|
+
export declare function workflowsGroup(repo: string, main: string, home: string | undefined, offline: boolean, env: NodeJS.ProcessEnv): Diagnosis[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// What diagnose.ts reads of one repository's workflows, through `kryso workflow pins`, so the
|
|
2
|
+
// resolver's rules stay in the one module a pass runs (ADR 0046). Each workflow file that does not
|
|
3
|
+
// resolve is an error, each pin kryso's store lacks is a warn that names the fetch, and each pin a
|
|
4
|
+
// file names itself that is behind its source's newest commit for the skill is an info that names
|
|
5
|
+
// kryso workflow update. A pin the file inherits from a built-in moves with kryso, so it is never
|
|
6
|
+
// behind here. Under the offline switch the module reads no source, and whether a pin is behind
|
|
7
|
+
// is unknown. A repository with no .kryso/workflows/ gets no line.
|
|
8
|
+
import { startable } from "./commands.js";
|
|
9
|
+
import { capture, failure } from "./proc.js";
|
|
10
|
+
/** How long the read gets: it clones each source a file pins, without the blobs. */
|
|
11
|
+
const PINS_TIMEOUT = 120_000;
|
|
12
|
+
/** The repository group's workflow diagnoses for the repository at repo, its top-level path, named
|
|
13
|
+
* by main, its main checkout, with the drivers at home. */
|
|
14
|
+
export function workflowsGroup(repo, main, home, offline, env) {
|
|
15
|
+
const args = ["pins", "--repo", repo, ...(offline ? ["--offline"] : [])];
|
|
16
|
+
const target = home === undefined ? undefined : startable(home, "workflow", args, env);
|
|
17
|
+
// A resolver that is missing is the install group's error.
|
|
18
|
+
if (!target)
|
|
19
|
+
return [];
|
|
20
|
+
const base = { group: "repository", repository: main };
|
|
21
|
+
const r = capture(target.program, [...target.head, ...args], env, repo, PINS_TIMEOUT);
|
|
22
|
+
let workflows;
|
|
23
|
+
try {
|
|
24
|
+
workflows = r.ok ? JSON.parse(r.out).workflows : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
workflows = undefined;
|
|
28
|
+
}
|
|
29
|
+
if (!Array.isArray(workflows)) {
|
|
30
|
+
const why = r.ok ? "it printed no workflows" : failure(r);
|
|
31
|
+
return [{ ...base, id: "repository.workflows", severity: "info", fix: "person", unknown: true, subject: "kryso workflow pins", text: `what this repository's workflows pin is unknown, because kryso workflow pins failed: ${why}` }];
|
|
32
|
+
}
|
|
33
|
+
const update = `kryso workflow update --repo ${repo}`;
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
/** Whether this is the first time the key is seen, which it then records. */
|
|
36
|
+
const firstSight = (key) => {
|
|
37
|
+
if (seen.has(key))
|
|
38
|
+
return false;
|
|
39
|
+
seen.add(key);
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
const found = [];
|
|
43
|
+
for (const w of workflows) {
|
|
44
|
+
if (w.error !== undefined) {
|
|
45
|
+
found.push({ ...base, id: "repository.workflow-unresolved", severity: "error", fix: "person", subject: w.file, text: `the workflow ${w.name} does not resolve, so a pass that picks it stops in preflight: ${w.error}` });
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const p of w.pins ?? []) {
|
|
49
|
+
const at = `${p.source} ${p.commit.slice(0, 12)}`;
|
|
50
|
+
if (!p.stored && firstSight(`store ${p.store}`)) {
|
|
51
|
+
found.push({
|
|
52
|
+
...base,
|
|
53
|
+
id: "repository.pin-missing",
|
|
54
|
+
severity: "warn",
|
|
55
|
+
fix: "command",
|
|
56
|
+
subject: p.store,
|
|
57
|
+
text: `the workflow ${w.name} pins ${p.skill} at ${at}, which kryso's store lacks, so the next pass fetches it before its claim`,
|
|
58
|
+
command: `kryso workflow fetch ${w.name} --repo ${repo}`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!p.own || !firstSight(`behind ${p.source} ${p.path} ${p.commit}`))
|
|
62
|
+
continue;
|
|
63
|
+
const behind = { ...base, id: "repository.pin-behind", severity: "info", fix: "command", subject: `${p.skill} ${at}`, command: update };
|
|
64
|
+
if (p.unknown !== undefined) {
|
|
65
|
+
found.push({ ...behind, unknown: true, text: `whether the pin ${p.skill} at ${at} in ${w.file} is behind its source is unknown, because ${p.unknown}` });
|
|
66
|
+
}
|
|
67
|
+
else if (p.behind && p.newest) {
|
|
68
|
+
found.push({ ...behind, text: `the workflow ${w.name} pins ${p.skill} at ${at}, and ${p.newest.slice(0, 12)} on its default branch changed ${p.path} since` });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# The kryso-runner entrypoint. kryso passes the allowlisted secrets and identity in an env file
|
|
3
|
+
# that docker has already read by now, and names that file in KRYSO_ENV_FILE. This deletes it and
|
|
4
|
+
# the Codex login copy, sets up git, gh and Claude Code in the container's own home, then runs
|
|
5
|
+
# the command it was given. /etc/passwd and /etc/group are kryso's read-only files.
|
|
6
|
+
set -eu
|
|
7
|
+
|
|
8
|
+
# The env file sits in the run's secrets directory, mounted from the host. Docker has read it,
|
|
9
|
+
# so the host copy goes before anything else runs.
|
|
10
|
+
if [ -n "${KRYSO_ENV_FILE:-}" ]; then rm -f -- "$KRYSO_ENV_FILE"; fi
|
|
11
|
+
unset KRYSO_ENV_FILE
|
|
12
|
+
|
|
13
|
+
# A Codex profile's login: copied into the container's own home, then deleted on the host.
|
|
14
|
+
if [ -n "${KRYSO_CODEX_AUTH:-}" ]; then
|
|
15
|
+
mkdir -p "$HOME/.codex"
|
|
16
|
+
chmod 700 "$HOME/.codex"
|
|
17
|
+
cp -- "$KRYSO_CODEX_AUTH" "$HOME/.codex/auth.json"
|
|
18
|
+
chmod 600 "$HOME/.codex/auth.json"
|
|
19
|
+
rm -f -- "$KRYSO_CODEX_AUTH"
|
|
20
|
+
fi
|
|
21
|
+
unset KRYSO_CODEX_AUTH
|
|
22
|
+
|
|
23
|
+
# Pushes go over https with the gh token. A remote written for ssh is rewritten to https, so no
|
|
24
|
+
# ssh client or key is needed.
|
|
25
|
+
if [ -n "${GH_TOKEN:-}" ]; then gh auth setup-git --hostname github.com; fi
|
|
26
|
+
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
|
27
|
+
git config --global --add url."https://github.com/".insteadOf "ssh://git@github.com/"
|
|
28
|
+
|
|
29
|
+
# The git author kryso read from the repository on the host.
|
|
30
|
+
if [ -n "${GIT_AUTHOR_NAME:-}" ]; then git config --global user.name "$GIT_AUTHOR_NAME"; fi
|
|
31
|
+
if [ -n "${GIT_AUTHOR_EMAIL:-}" ]; then git config --global user.email "$GIT_AUTHOR_EMAIL"; fi
|
|
32
|
+
|
|
33
|
+
# Claude Code: the repository's path trusted, so a headless run does not stop at the trust
|
|
34
|
+
# prompt, and the host's permissions block, which kryso read from ~/.claude/settings.json.
|
|
35
|
+
mkdir -p "$HOME/.claude"
|
|
36
|
+
jq -n --arg repo "${KRYSO_REPO:-}" \
|
|
37
|
+
'{hasCompletedOnboarding: true, projects: (if $repo == "" then {} else {($repo): {hasTrustDialogAccepted: true}} end)}' \
|
|
38
|
+
> "$HOME/.claude.json"
|
|
39
|
+
perms=${KRYSO_CLAUDE_PERMISSIONS:-}
|
|
40
|
+
[ -n "$perms" ] || perms='{}'
|
|
41
|
+
printf '%s' "$perms" | jq '{permissions: .}' > "$HOME/.claude/settings.json"
|
|
42
|
+
unset KRYSO_CLAUDE_PERMISSIONS perms
|
|
43
|
+
|
|
44
|
+
exec "$@"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# kryso-runner: the image `kryso shift --isolate docker` and `kryso pass --isolate docker` run
|
|
2
|
+
# the drivers in (ADR 0051). `kryso isolate build` builds it as kryso-runner:<package version>.
|
|
3
|
+
# It holds the drivers' tools and nothing of any host: the repository, the drivers and the skills
|
|
4
|
+
# are mounted at run time, and the secrets arrive through an env file the entrypoint deletes.
|
|
5
|
+
FROM node:22-bookworm-slim
|
|
6
|
+
|
|
7
|
+
ARG CLAUDE_CODE_VERSION=latest
|
|
8
|
+
ARG CODEX_VERSION=latest
|
|
9
|
+
ARG PNPM_VERSION=10
|
|
10
|
+
|
|
11
|
+
# The drivers' tools. procps gives them ps and pgrep. gh comes from GitHub's own apt repository,
|
|
12
|
+
# because Debian's package lags it.
|
|
13
|
+
RUN apt-get update \
|
|
14
|
+
&& apt-get install -y --no-install-recommends bash ca-certificates curl git jq procps python3 \
|
|
15
|
+
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
|
16
|
+
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
|
17
|
+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
|
|
18
|
+
> /etc/apt/sources.list.d/github-cli.list \
|
|
19
|
+
&& apt-get update \
|
|
20
|
+
&& apt-get install -y --no-install-recommends gh \
|
|
21
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
22
|
+
|
|
23
|
+
RUN npm install -g "pnpm@${PNPM_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" "@openai/codex@${CODEX_VERSION}" \
|
|
24
|
+
&& npm cache clean --force
|
|
25
|
+
|
|
26
|
+
# The container runs as the caller's uid and gid, which the image cannot know, so the home is
|
|
27
|
+
# open to any user. kryso mounts its own read-only /etc/passwd and /etc/group naming that uid,
|
|
28
|
+
# and starts the container with no-new-privileges. .claude and .agents exist here because the
|
|
29
|
+
# skills are mounted inside them, and a directory docker makes for a mount point belongs to root.
|
|
30
|
+
RUN mkdir -p /home/kryso/.claude /home/kryso/.agents \
|
|
31
|
+
&& chmod 1777 /home/kryso /home/kryso/.claude /home/kryso/.agents
|
|
32
|
+
|
|
33
|
+
COPY entrypoint.sh /usr/local/bin/kryso-entrypoint
|
|
34
|
+
RUN chmod 0755 /usr/local/bin/kryso-entrypoint
|
|
35
|
+
|
|
36
|
+
ENV HOME=/home/kryso
|
|
37
|
+
WORKDIR /home/kryso
|
|
38
|
+
ENTRYPOINT ["/usr/local/bin/kryso-entrypoint"]
|
|
39
|
+
CMD ["bash"]
|