crysk 0.3.3 → 0.4.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.
Files changed (42) hide show
  1. package/dist/SKILL-dsnffnfp.md +140 -0
  2. package/dist/SKILL-gnrbph72.md +140 -0
  3. package/dist/SKILL-kq0xejn3.md +553 -0
  4. package/dist/SKILL-qaqsbygw.md +66 -0
  5. package/dist/SKILL-vws0aqb8.md +553 -0
  6. package/dist/ci-admission-t0f5qwth.md +128 -0
  7. package/dist/cli.js +408 -155
  8. package/dist/index.js +151 -20
  9. package/package.json +2 -2
  10. package/skills/crysk-ci-setup/SKILL.md +1 -1
  11. package/skills/crysk-ci-setup/references/ci-admission.md +1 -1
  12. package/skills/crysk-loop/SKILL.md +19 -8
  13. package/skills/crysk-pr/SKILL.md +1 -1
  14. package/src/assets.ts +2 -2
  15. package/src/ci/gates.ts +9 -6
  16. package/src/ci/platform-config.ts +127 -0
  17. package/src/ci/platform-report.ts +702 -0
  18. package/src/ci/platform.ts +449 -0
  19. package/src/ci/reporter.ts +9 -7
  20. package/src/ci/review-admission.ts +8 -4
  21. package/src/ci/setup.ts +112 -9
  22. package/src/compare/loop.ts +9 -1
  23. package/src/compare/martian-adapter.ts +1 -1
  24. package/src/index.ts +1 -1
  25. package/src/pr/admission.ts +53 -11
  26. package/src/pr/ci-admission-gate.ts +2 -1
  27. package/src/pr/finding-state-record.ts +58 -0
  28. package/src/pr/gate-record.ts +22 -0
  29. package/src/pr/inline.ts +3 -0
  30. package/src/pr/posting.ts +4 -0
  31. package/src/pr/pr-status.ts +27 -7
  32. package/src/pr/pr.ts +39 -8
  33. package/src/pr/preflight.ts +43 -1
  34. package/src/pr/publish-outcome.ts +10 -2
  35. package/src/pr/review-pr.ts +5 -3
  36. package/src/rereview/classify.ts +4 -0
  37. package/src/rereview/prepare.ts +47 -22
  38. package/src/rereview/state.ts +34 -8
  39. package/src/review/report.ts +34 -14
  40. package/src/security/published-text.ts +161 -0
  41. package/src/triage/triage.ts +2 -1
  42. package/src/updater.ts +1 -1
@@ -0,0 +1,127 @@
1
+ // Platform mode: apply the review configuration the Crysk platform returned with
2
+ // the run token, so the engine's own two-layer read (src/config/config.ts,
3
+ // mergeConfig + CONFIG_DIRECTION) resolves it against the repository's
4
+ // `.crysk/config.json` with each key's own rule.
5
+ //
6
+ // `person` is the runner's personal layer: setup.ts writes it into the personal
7
+ // config file it already writes `routing` to (see materializeCiOpenCodeData).
8
+ // `repo` is used ONLY when the checkout has no repo config of its own, and then
9
+ // it reaches the engine through the existing `--config` override, which
10
+ // repoints the repo layer and nothing else. The file lives next to the platform
11
+ // config under the runner's temp directory, outside the workspace: the PR's own
12
+ // tree must never be written to, and a reviewed PR must never influence config
13
+ // (the engine reads the repo layer from the operator root, never the worktree).
14
+ //
15
+ // WHY the engine's parsers validate here although the platform already did: the
16
+ // engine is the authority on its own rules, and the platform's copy of them can
17
+ // lag a release. WHY every failure throws: a review with the wrong limits is
18
+ // worse than no review, so the setup step turns each one into a red run. No
19
+ // message carries a value, only the layer, the key the engine names, and a file.
20
+ //
21
+ // This runs after `bun install` (it imports the engine's parsers), unlike the
22
+ // connect step in platform.ts, which only hands the raw object over as a file.
23
+
24
+ import { existsSync, readFileSync } from "node:fs";
25
+ import { mkdir, writeFile } from "node:fs/promises";
26
+ import path from "node:path";
27
+ import { parseGlobalConfig, parseLocalConfig } from "#review/preflight";
28
+ import { resolveRepoDir } from "../brand-paths";
29
+ import { type PlatformConfig, parsePlatformConfig } from "./platform";
30
+
31
+ // Names the layer the parser's own message is templated over, so an error
32
+ // reads `platform config.repo max_changed_lines must be ...`.
33
+ const PERSON_LABEL = "platform config.person";
34
+ const REPO_LABEL = "platform config.repo";
35
+
36
+ // The repo layer's file, beside the platform config file the connect step wrote.
37
+ const REPO_LAYER_FILE_NAME = "platform-repo-config.json";
38
+
39
+ export class PlatformConfigError extends Error {
40
+ constructor(message: string) {
41
+ super(message);
42
+ this.name = "PlatformConfigError";
43
+ }
44
+ }
45
+
46
+ function messageOf(error: unknown): string {
47
+ return error instanceof Error ? error.message : "unknown error";
48
+ }
49
+
50
+ // The file the connect step left. A missing or malformed one fails loudly: the
51
+ // step that reads it only runs when the connect step announced it.
52
+ export function readPlatformConfig(file: string): PlatformConfig {
53
+ let parsed: unknown;
54
+ try {
55
+ parsed = JSON.parse(readFileSync(file, "utf8"));
56
+ } catch (error) {
57
+ throw new PlatformConfigError(
58
+ `the platform config file ${file} could not be read: ${messageOf(error)}`,
59
+ );
60
+ }
61
+ const config = parsePlatformConfig(parsed);
62
+ if (!config.ok) {
63
+ throw new PlatformConfigError(
64
+ `the platform config file ${file} is malformed: ${config.message}`,
65
+ );
66
+ }
67
+ return config.config ?? { person: {}, repo: {} };
68
+ }
69
+
70
+ // Refuses a person layer the engine's person parser would refuse, naming the file
71
+ // it was about to be written to. Nothing is written before this passes.
72
+ export function assertPlatformPerson(
73
+ person: Record<string, unknown>,
74
+ targetFile: string,
75
+ ): void {
76
+ try {
77
+ parseGlobalConfig(JSON.stringify(person), PERSON_LABEL);
78
+ } catch (error) {
79
+ throw new PlatformConfigError(
80
+ `${messageOf(error)} (it was to be written to ${targetFile})`,
81
+ );
82
+ }
83
+ }
84
+
85
+ export type PlatformRepoLayerResult =
86
+ // `repo` was empty: nothing to deliver.
87
+ | { status: "empty" }
88
+ // The checkout has its own repo config file; it wins whole.
89
+ | { status: "repo-file-wins"; file: string }
90
+ // `repo` was written to `file`, to be passed as `--config`.
91
+ | { status: "written"; file: string };
92
+
93
+ // Decides whether the platform's repo layer applies, and delivers it as a temp
94
+ // file when it does.
95
+ //
96
+ // WHY the existence check is resolveRepoDir + config.json: that is exactly the
97
+ // path loadEffectiveConfig opens, `.crysk/` first and the pre-rename `.prhero/`
98
+ // when that is all there is. A second hand-written list of names would be a
99
+ // second chance to disagree with the engine about whether a repo file exists.
100
+ // `root` is the operator root, the same one the engine reads.
101
+ export async function deliverPlatformRepoLayer(input: {
102
+ repo: Record<string, unknown>;
103
+ root: string;
104
+ dir: string;
105
+ }): Promise<PlatformRepoLayerResult> {
106
+ if (Object.keys(input.repo).length === 0) return { status: "empty" };
107
+
108
+ const own = path.join(resolveRepoDir(input.root), "config.json");
109
+ if (existsSync(own)) return { status: "repo-file-wins", file: own };
110
+
111
+ const raw = JSON.stringify(input.repo);
112
+ try {
113
+ parseLocalConfig(raw, REPO_LABEL);
114
+ } catch (error) {
115
+ throw new PlatformConfigError(messageOf(error));
116
+ }
117
+ const file = path.join(input.dir, REPO_LAYER_FILE_NAME);
118
+ try {
119
+ await mkdir(input.dir, { recursive: true, mode: 0o700 });
120
+ await writeFile(file, `${raw}\n`, { mode: 0o600 });
121
+ } catch (error) {
122
+ throw new PlatformConfigError(
123
+ `the platform repo config could not be written to ${file}: ${messageOf(error)}`,
124
+ );
125
+ }
126
+ return { status: "written", file };
127
+ }