@milkenjoyer/toolchain 0.8.0 → 0.9.0
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/README.md +6 -0
- package/dist/verification.d.mts +28 -0
- package/dist/verification.mjs +98 -0
- package/package.json +4 -2
- package/src/verification.ts +172 -0
package/README.md
CHANGED
|
@@ -33,3 +33,9 @@ Before deployment, save the active generated stub's bytes and executable mode. C
|
|
|
33
33
|
Run `GH_TOKEN="$(gh auth token)" vp exec proof <owner/repo> <files>` to upload screenshots and video as Git objects under a hidden `refs/proof/<commit>` ref and print inline Markdown for the PR. The repository must be private; media stays private to repo members. The command accepts `GH_TOKEN` or `GITHUB_TOKEN`. Video uploads include a GIF preview capped at 30 seconds and 720 pixels and need ffmpeg on the runner.
|
|
34
34
|
|
|
35
35
|
In CI, give the job `permissions: contents: write`, set `GH_TOKEN: ${{ github.token }}`, and run `vp exec proof ${{ github.repository }} <files>` after generating the media.
|
|
36
|
+
|
|
37
|
+
## Verification check
|
|
38
|
+
|
|
39
|
+
The `verification` check requires a code-tier PR body to contain a `## Verification` section naming at least one real run in backticks. Record each command or verifier recipe and its outcome. Renovate PRs and PRs changing only Markdown, MDX, LICENSE files, art, media or fonts are exempt. Changeset-only PRs are exempt. An unknown or truncated file list requires verification. HTML comments do not count as runs.
|
|
40
|
+
|
|
41
|
+
In the PR job, set `permissions: contents: read` and `GH_TOKEN: ${{ github.token }}`, then run `vp exec verification`. The check reads the original pull request event and compares its base and head through the GitHub API. After editing a failing body, push again because a rerun reads the body from the original event.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { FileSystem } from "effect/FileSystem";
|
|
4
|
+
import * as Cause from "effect/Cause";
|
|
5
|
+
import * as Config from "effect/Config";
|
|
6
|
+
export type PullRequest = {
|
|
7
|
+
readonly author: string;
|
|
8
|
+
readonly body: string | null;
|
|
9
|
+
readonly files: ReadonlyArray<string> | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type Verdict = {
|
|
12
|
+
readonly _tag: "Exempt";
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly _tag: "Proven";
|
|
16
|
+
} | {
|
|
17
|
+
readonly _tag: "Unproven";
|
|
18
|
+
readonly reason: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const verdict: (pr: PullRequest) => Verdict;
|
|
21
|
+
declare const VerificationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
22
|
+
readonly _tag: "VerificationError";
|
|
23
|
+
} & Readonly<A>;
|
|
24
|
+
declare class VerificationError extends VerificationError_base<{
|
|
25
|
+
readonly message: string;
|
|
26
|
+
}> {}
|
|
27
|
+
export declare const checkVerification: Effect.Effect<0 | 1, Config.ConfigError | import("effect/PlatformError").PlatformError | Schema.SchemaError | VerificationError, FileSystem>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import { FileSystem } from "effect/FileSystem";
|
|
6
|
+
import { NodeServices } from "@effect/platform-node";
|
|
7
|
+
import { Octokit } from "@octokit/rest";
|
|
8
|
+
import * as Cause from "effect/Cause";
|
|
9
|
+
import * as Config from "effect/Config";
|
|
10
|
+
import * as Exit from "effect/Exit";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Console from "effect/Console";
|
|
13
|
+
// src/verification.ts
|
|
14
|
+
const exemptions = [{
|
|
15
|
+
reason: "Renovate PR",
|
|
16
|
+
applies: (pr) => pr.author === "renovate[bot]"
|
|
17
|
+
}, {
|
|
18
|
+
reason: "changes only docs, content or art",
|
|
19
|
+
applies: (pr) => pr.files !== void 0 && pr.files.length > 0 && pr.files.every((file) => /^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(file.split("/").at(-1) ?? ""))
|
|
20
|
+
}];
|
|
21
|
+
const verdict = (pr) => {
|
|
22
|
+
const exemption = exemptions.find((entry) => entry.applies(pr));
|
|
23
|
+
if (exemption !== void 0) return {
|
|
24
|
+
_tag: "Exempt",
|
|
25
|
+
reason: exemption.reason
|
|
26
|
+
};
|
|
27
|
+
const lines = (pr.body ?? "").replaceAll(/<!--[\s\S]*?-->/gu, "").split(/\r?\n/u);
|
|
28
|
+
const start = lines.findIndex((line) => /^##\s+Verification\s*$/iu.test(line));
|
|
29
|
+
if (start === -1) return {
|
|
30
|
+
_tag: "Unproven",
|
|
31
|
+
reason: "has no ## Verification section"
|
|
32
|
+
};
|
|
33
|
+
const fencedRun = "\0";
|
|
34
|
+
const [section = ""] = lines.slice(start + 1).join("\n").replaceAll(/^ {0,3}(`{3,}|~{3,})[^\n]*\n([\s\S]*?)^ {0,3}\1[ \t]*$/gmu, (_fence, _marker, content) => content.trim() === "" ? "" : fencedRun).split(/^(?:# |## )/mu);
|
|
35
|
+
return section.includes(fencedRun) || /`[^`\s][^`]*`/u.test(section) ? { _tag: "Proven" } : {
|
|
36
|
+
_tag: "Unproven",
|
|
37
|
+
reason: "names no run"
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var VerificationError = class extends Data.TaggedError("VerificationError") {};
|
|
41
|
+
const github = (request) => Effect.tryPromise({
|
|
42
|
+
try: request,
|
|
43
|
+
catch: (cause) => new VerificationError({ message: cause instanceof Error ? cause.message : String(cause) })
|
|
44
|
+
});
|
|
45
|
+
const PullRequestEvent = Schema.fromJsonString(Schema.Struct({
|
|
46
|
+
pull_request: Schema.Struct({
|
|
47
|
+
number: Schema.Finite,
|
|
48
|
+
body: Schema.NullOr(Schema.String),
|
|
49
|
+
user: Schema.Struct({ login: Schema.String }),
|
|
50
|
+
base: Schema.Struct({ sha: Schema.String }),
|
|
51
|
+
head: Schema.Struct({ sha: Schema.String })
|
|
52
|
+
}),
|
|
53
|
+
repository: Schema.Struct({ full_name: Schema.String })
|
|
54
|
+
}));
|
|
55
|
+
const checkVerification = Effect.gen(function* () {
|
|
56
|
+
if ((yield* Config.String("GITHUB_EVENT_NAME").pipe(Config.withDefault(""))) !== "pull_request") {
|
|
57
|
+
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
const fs = yield* FileSystem;
|
|
61
|
+
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
62
|
+
const payload = yield* fs.readFileString(eventPath);
|
|
63
|
+
const { pull_request: pr, repository } = yield* Schema.decodeEffect(PullRequestEvent)(payload);
|
|
64
|
+
const [, owner, repo] = /^([^/\s]+)\/([^/\s]+)$/u.exec(repository.full_name) ?? [];
|
|
65
|
+
if (owner === void 0 || repo === void 0) return yield* new VerificationError({ message: "Invalid repository.full_name" });
|
|
66
|
+
const token = yield* Config.schema(Schema.Redacted(Schema.NonEmptyString), "GH_TOKEN").pipe(Config.orElse(() => Config.schema(Schema.Redacted(Schema.NonEmptyString), "GITHUB_TOKEN")), Effect.mapError(() => new VerificationError({ message: "Missing GH_TOKEN or GITHUB_TOKEN" })));
|
|
67
|
+
const octokit = new Octokit({ auth: Redacted.value(token) });
|
|
68
|
+
const { data } = yield* github(() => octokit.rest.repos.compareCommitsWithBasehead({
|
|
69
|
+
owner,
|
|
70
|
+
repo,
|
|
71
|
+
basehead: `${pr.base.sha}...${pr.head.sha}`
|
|
72
|
+
}));
|
|
73
|
+
const result = verdict({
|
|
74
|
+
author: pr.user.login,
|
|
75
|
+
body: pr.body,
|
|
76
|
+
files: data.files === void 0 || data.files.length >= 300 ? void 0 : data.files.map((file) => file.filename)
|
|
77
|
+
});
|
|
78
|
+
if (result._tag === "Exempt") {
|
|
79
|
+
yield* Console.log(`PR #${pr.number} is exempt: ${result.reason}.`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (result._tag === "Proven") {
|
|
83
|
+
yield* Console.log(`PR #${pr.number}'s ## Verification names a run.`);
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
yield* Console.error(`PR #${pr.number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`);
|
|
87
|
+
return 1;
|
|
88
|
+
});
|
|
89
|
+
if (import.meta.main) {
|
|
90
|
+
const exit = await Effect.runPromiseExit(checkVerification.pipe(Effect.provide(NodeServices.layer)));
|
|
91
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
92
|
+
else {
|
|
93
|
+
const error = Cause.squash(exit.cause);
|
|
94
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export { checkVerification, verdict };
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
7
7
|
"directory": "packages/toolchain"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"proof": "./src/proof.ts"
|
|
10
|
+
"proof": "./src/proof.ts",
|
|
11
|
+
"verification": "./src/verification.ts"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"dist",
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
"node-version",
|
|
16
17
|
"renovate.json",
|
|
17
18
|
"src/proof.ts",
|
|
19
|
+
"src/verification.ts",
|
|
18
20
|
"tsconfig.base.json",
|
|
19
21
|
"vscode/extensions.json",
|
|
20
22
|
"vscode/settings.json"
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { NodeServices } from "@effect/platform-node";
|
|
3
|
+
import { Octokit } from "@octokit/rest";
|
|
4
|
+
import * as Cause from "effect/Cause";
|
|
5
|
+
import * as Config from "effect/Config";
|
|
6
|
+
import * as Console from "effect/Console";
|
|
7
|
+
import * as Data from "effect/Data";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Exit from "effect/Exit";
|
|
10
|
+
import { FileSystem } from "effect/FileSystem";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
|
|
14
|
+
export type PullRequest = {
|
|
15
|
+
readonly author: string;
|
|
16
|
+
readonly body: string | null;
|
|
17
|
+
readonly files: ReadonlyArray<string> | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type Verdict =
|
|
21
|
+
| { readonly _tag: "Exempt"; readonly reason: string }
|
|
22
|
+
| { readonly _tag: "Proven" }
|
|
23
|
+
| { readonly _tag: "Unproven"; readonly reason: string };
|
|
24
|
+
|
|
25
|
+
const exemptions: ReadonlyArray<{
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
readonly applies: (pr: PullRequest) => boolean;
|
|
28
|
+
}> = [
|
|
29
|
+
{
|
|
30
|
+
reason: "Renovate PR",
|
|
31
|
+
applies: (pr) => pr.author === "renovate[bot]",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
reason: "changes only docs, content or art",
|
|
35
|
+
applies: (pr) =>
|
|
36
|
+
pr.files !== undefined &&
|
|
37
|
+
pr.files.length > 0 &&
|
|
38
|
+
pr.files.every((file) =>
|
|
39
|
+
/^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(
|
|
40
|
+
file.split("/").at(-1) ?? ""
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
export const verdict = (pr: PullRequest): Verdict => {
|
|
47
|
+
const exemption = exemptions.find((entry) => entry.applies(pr));
|
|
48
|
+
if (exemption !== undefined)
|
|
49
|
+
return { _tag: "Exempt", reason: exemption.reason };
|
|
50
|
+
const lines = (pr.body ?? "")
|
|
51
|
+
.replaceAll(/<!--[\s\S]*?-->/gu, "")
|
|
52
|
+
.split(/\r?\n/u);
|
|
53
|
+
const start = lines.findIndex((line) =>
|
|
54
|
+
/^##\s+Verification\s*$/iu.test(line)
|
|
55
|
+
);
|
|
56
|
+
if (start === -1)
|
|
57
|
+
return { _tag: "Unproven", reason: "has no ## Verification section" };
|
|
58
|
+
const fencedRun = "\u0000";
|
|
59
|
+
const rest = lines
|
|
60
|
+
.slice(start + 1)
|
|
61
|
+
.join("\n")
|
|
62
|
+
.replaceAll(
|
|
63
|
+
/^ {0,3}(`{3,}|~{3,})[^\n]*\n([\s\S]*?)^ {0,3}\1[ \t]*$/gmu,
|
|
64
|
+
(_fence, _marker, content: string) =>
|
|
65
|
+
content.trim() === "" ? "" : fencedRun
|
|
66
|
+
);
|
|
67
|
+
const [section = ""] = rest.split(/^(?:# |## )/mu);
|
|
68
|
+
return section.includes(fencedRun) || /`[^`\s][^`]*`/u.test(section)
|
|
69
|
+
? { _tag: "Proven" }
|
|
70
|
+
: { _tag: "Unproven", reason: "names no run" };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
class VerificationError extends Data.TaggedError("VerificationError")<{
|
|
74
|
+
readonly message: string;
|
|
75
|
+
}> {}
|
|
76
|
+
|
|
77
|
+
const github = <A>(request: () => Promise<A>) =>
|
|
78
|
+
Effect.tryPromise({
|
|
79
|
+
try: request,
|
|
80
|
+
catch: (cause) =>
|
|
81
|
+
new VerificationError({
|
|
82
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const PullRequestEvent = Schema.fromJsonString(
|
|
87
|
+
Schema.Struct({
|
|
88
|
+
pull_request: Schema.Struct({
|
|
89
|
+
number: Schema.Finite,
|
|
90
|
+
body: Schema.NullOr(Schema.String),
|
|
91
|
+
user: Schema.Struct({ login: Schema.String }),
|
|
92
|
+
base: Schema.Struct({ sha: Schema.String }),
|
|
93
|
+
head: Schema.Struct({ sha: Schema.String }),
|
|
94
|
+
}),
|
|
95
|
+
repository: Schema.Struct({ full_name: Schema.String }),
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const checkVerification = Effect.gen(function* () {
|
|
100
|
+
const event = yield* Config.String("GITHUB_EVENT_NAME").pipe(
|
|
101
|
+
Config.withDefault("")
|
|
102
|
+
);
|
|
103
|
+
if (event !== "pull_request") {
|
|
104
|
+
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
const fs = yield* FileSystem;
|
|
108
|
+
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
109
|
+
const payload = yield* fs.readFileString(eventPath);
|
|
110
|
+
const { pull_request: pr, repository } =
|
|
111
|
+
yield* Schema.decodeEffect(PullRequestEvent)(payload);
|
|
112
|
+
const [, owner, repo] =
|
|
113
|
+
/^([^/\s]+)\/([^/\s]+)$/u.exec(repository.full_name) ?? [];
|
|
114
|
+
if (owner === undefined || repo === undefined)
|
|
115
|
+
return yield* new VerificationError({
|
|
116
|
+
message: "Invalid repository.full_name",
|
|
117
|
+
});
|
|
118
|
+
const token = yield* Config.schema(
|
|
119
|
+
Schema.Redacted(Schema.NonEmptyString),
|
|
120
|
+
"GH_TOKEN"
|
|
121
|
+
).pipe(
|
|
122
|
+
Config.orElse(() =>
|
|
123
|
+
Config.schema(Schema.Redacted(Schema.NonEmptyString), "GITHUB_TOKEN")
|
|
124
|
+
),
|
|
125
|
+
Effect.mapError(
|
|
126
|
+
() =>
|
|
127
|
+
new VerificationError({ message: "Missing GH_TOKEN or GITHUB_TOKEN" })
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
const octokit = new Octokit({ auth: Redacted.value(token) });
|
|
131
|
+
const { data } = yield* github(() =>
|
|
132
|
+
octokit.rest.repos.compareCommitsWithBasehead({
|
|
133
|
+
owner,
|
|
134
|
+
repo,
|
|
135
|
+
basehead: `${pr.base.sha}...${pr.head.sha}`,
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
const result = verdict({
|
|
139
|
+
author: pr.user.login,
|
|
140
|
+
body: pr.body,
|
|
141
|
+
files:
|
|
142
|
+
data.files === undefined || data.files.length >= 300
|
|
143
|
+
? undefined
|
|
144
|
+
: data.files.map((file) => file.filename),
|
|
145
|
+
});
|
|
146
|
+
if (result._tag === "Exempt") {
|
|
147
|
+
yield* Console.log(`PR #${pr.number} is exempt: ${result.reason}.`);
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
if (result._tag === "Proven") {
|
|
151
|
+
yield* Console.log(`PR #${pr.number}'s ## Verification names a run.`);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
yield* Console.error(
|
|
155
|
+
`PR #${pr.number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`
|
|
156
|
+
);
|
|
157
|
+
return 1;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (import.meta.main) {
|
|
161
|
+
const exit = await Effect.runPromiseExit(
|
|
162
|
+
checkVerification.pipe(Effect.provide(NodeServices.layer))
|
|
163
|
+
);
|
|
164
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
165
|
+
else {
|
|
166
|
+
const error = Cause.squash(exit.cause);
|
|
167
|
+
process.stderr.write(
|
|
168
|
+
`${error instanceof Error ? error.message : String(error)}\n`
|
|
169
|
+
);
|
|
170
|
+
process.exitCode = 1;
|
|
171
|
+
}
|
|
172
|
+
}
|