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,161 @@
1
+ // Text a model wrote about author-controlled input, on its way to a public
2
+ // surface: PR comments, the step summary, the state block. A pull request can
3
+ // steer what the model says, so GitHub must not act on any of it.
4
+ //
5
+ // WHY shapes and not the keyword rules of redact.ts: those are for error
6
+ // messages, where `password hunter2` is a leak. A finding is ABOUT code, so
7
+ // "the password field" and `const TOKEN = getToken()` have to survive it.
8
+ //
9
+ // WHY every repeat that can start at many positions has a bound: this runs on
10
+ // whatever the model printed, and one long word must not stall publication.
11
+ //
12
+ // What each defusal does was checked against GitHub's own renderer
13
+ // (`gh api markdown --mode gfm`), not assumed.
14
+
15
+ const REDACTED = "[REDACTED]";
16
+ const ZERO_WIDTH_SPACE = "\u200b";
17
+
18
+ // `(?<![A-Za-z0-9])` instead of `\b`: `\b` does not fire after `_`, and
19
+ // `_ghp_..._` is a token in Markdown emphasis.
20
+ const SECRET_SHAPES: readonly RegExp[] = [
21
+ /(?<![A-Za-z0-9])gh[pousr]_[A-Za-z0-9_]{20,}/g,
22
+ /(?<![A-Za-z0-9])github_pat_[A-Za-z0-9_]{20,}/g,
23
+ /(?<![A-Za-z0-9])glpat-[A-Za-z0-9_-]{20,}/g,
24
+ /(?<![A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
25
+ // The prefixed form and the older unbroken form. A bare `sk-` plus hyphens is
26
+ // what a CSS class looks like.
27
+ /(?<![A-Za-z0-9])sk-(?:ant|proj|svcacct|admin)-[A-Za-z0-9_-]{16,}/g,
28
+ /(?<![A-Za-z0-9])sk-[A-Za-z0-9]{32,}/g,
29
+ /(?<![A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/g,
30
+ /(?<![A-Za-z0-9])xox[abeoprs]-[A-Za-z0-9-]{10,}/g,
31
+ /(?<![A-Za-z0-9])AIza[A-Za-z0-9_-]{35}/g,
32
+ /(?<![A-Za-z0-9])npm_[A-Za-z0-9]{36}\b/g,
33
+ /(?<![A-Za-z0-9])eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}/g,
34
+ // A digit is required: `Bearer verifyAccessTokenSignature` names a function.
35
+ /(?<![A-Za-z0-9])Bearer\s+(?=[A-Za-z0-9._~+/=-]{0,512}\d)[A-Za-z0-9._~+/=-]{20,}/gi,
36
+ ];
37
+
38
+ // `user:password@`, or a long user-only token. `git@` is a username, and `$`,
39
+ // `{` and `<` mean a placeholder (`redis://:${REDIS_PASSWORD}@cache`).
40
+ const URL_CREDENTIALS =
41
+ /(?<![A-Za-z0-9+.-])([a-z][a-z0-9+.-]{0,30}:\/\/)(?:[^\s/?#${<]{0,256}:[^\s/?#${<]{1,256}|[^\s/?#${<:@]{20,256})@/gi;
42
+
43
+ // A secret name followed by a value. The name alone decides nothing, because code
44
+ // is full of these: `TOKEN=getToken`, `API_KEY = "x-api-key"`, `SECRET: Uint8Array`.
45
+ // So isSecretValue reads the value.
46
+ const SECRET_ASSIGNMENT =
47
+ /(?<![A-Za-z0-9_-])(["']?)((?:[A-Za-z0-9_-]{0,40}[_-])?(?:password|passwd|secret|token|api[_-]?key|private[_-]?key|credentials?)(?:[_-][A-Za-z0-9_-]{0,40})?)\1(\s*[=:](?![=:])\s*)("[^"\n]{1,256}"|'[^'\n]{1,256}'|[^\s"',;]{1,256})/gi;
48
+
49
+ // A digit is the signal: a literal with one is rarely a word or an identifier. A
50
+ // password holds no such promise, so a password name also takes letters alone,
51
+ // unless the value only repeats the word (`PASSWORD = "password"`). This leaves
52
+ // letter-only values of other names, such as `API_KEY=hunter`: nothing tells them
53
+ // from `API_KEY=config`.
54
+ function isSecretValue(name: string, separator: string, raw: string): boolean {
55
+ const quoted = raw.startsWith('"') || raw.startsWith("'");
56
+ const value = quoted ? raw.slice(1, -1) : raw;
57
+ if (value.length < 6 || /^[\d_,.]+$/.test(value) || value.includes("$")) {
58
+ return false;
59
+ }
60
+ // `config/credentials:100-120` is a file and a line range, nothing else.
61
+ if (separator === ":" && /^\d+-\d+$/.test(value)) return false;
62
+ const colon = separator.includes(":");
63
+ if (!quoted) {
64
+ // Spaces around `=` are source code, and a bracket or a dot is an expression.
65
+ if (!colon && separator !== "=") return false;
66
+ if (/[.()[\]{}<>]/.test(value)) return false;
67
+ // A type annotation: `SECRET: Uint8Array`.
68
+ if (colon && /^[A-Z][a-z]/.test(value)) return false;
69
+ }
70
+ if (/\d/.test(value)) return true;
71
+ if (!/pass(?:word|wd)$/i.test(name) || /pass(?:word|wd)/i.test(value)) {
72
+ return false;
73
+ }
74
+ // `password: string` is a type. An upper-case name is a config key.
75
+ return quoted || !colon || name === name.toUpperCase();
76
+ }
77
+
78
+ const PEM_BEGIN = /-----BEGIN [A-Z0-9 ]{0,40}PRIVATE KEY(?: BLOCK)?-----/g;
79
+ const PEM_END = /-----END [A-Z0-9 ]{0,40}PRIVATE KEY(?: BLOCK)?-----/g;
80
+ const PEM_BODY = /(?:\s*[A-Za-z0-9+/=]{16,})*/y;
81
+
82
+ // Up to the closing line, or, when that was cut off, across the base64 lines:
83
+ // half a private key is still a private key, and the sentence after it is not
84
+ // part of the key. A loop and not one regex, so many openers with no closer stay
85
+ // linear.
86
+ function redactPrivateKeys(text: string): string {
87
+ if (!text.includes("PRIVATE KEY")) return text;
88
+ let out = "";
89
+ let from = 0;
90
+ let noMoreEnds = false;
91
+ PEM_BEGIN.lastIndex = 0;
92
+ for (;;) {
93
+ const begin = PEM_BEGIN.exec(text);
94
+ if (begin === null) break;
95
+ let to = PEM_BEGIN.lastIndex;
96
+ let closed = false;
97
+ if (!noMoreEnds) {
98
+ PEM_END.lastIndex = to;
99
+ closed = PEM_END.test(text);
100
+ if (closed) to = PEM_END.lastIndex;
101
+ else noMoreEnds = true;
102
+ }
103
+ if (!closed) {
104
+ PEM_BODY.lastIndex = to;
105
+ PEM_BODY.test(text);
106
+ to = PEM_BODY.lastIndex;
107
+ }
108
+ out += text.slice(from, begin.index) + REDACTED;
109
+ from = to;
110
+ PEM_BEGIN.lastIndex = to;
111
+ }
112
+ return out + text.slice(from);
113
+ }
114
+
115
+ export function redactSecrets(text: string): string {
116
+ let out = redactPrivateKeys(text);
117
+ for (const shape of SECRET_SHAPES) out = out.replace(shape, REDACTED);
118
+ return out
119
+ .replace(URL_CREDENTIALS, `$1${REDACTED}@`)
120
+ .replace(
121
+ SECRET_ASSIGNMENT,
122
+ (
123
+ match: string,
124
+ quote: string,
125
+ name: string,
126
+ separator: string,
127
+ raw: string,
128
+ ) =>
129
+ isSecretValue(name, separator, raw)
130
+ ? `${quote}${name}${quote}${separator}${REDACTED}`
131
+ : match,
132
+ );
133
+ }
134
+
135
+ // A secret was removed from this text, so the words around it are not all the
136
+ // words the model wrote. A guard reading it for safety content must not treat it
137
+ // as complete.
138
+ export function wasRedacted(text: string): boolean {
139
+ return text.includes(REDACTED);
140
+ }
141
+
142
+ // A zero-width space reads the same and stops GitHub from parsing a mention, an
143
+ // image or a tag out of the text. Breaking `<` also means no model text can spell
144
+ // a marker the comment parsers read. `@` after a letter, digit or `/` is left
145
+ // alone because GitHub does not read it as a mention, and emails, URLs and
146
+ // `src/@types` stay copyable. `&` is broken because `&#64;octocat` IS a mention.
147
+ //
148
+ // Idempotent, because a posted claim is read back from its comment and rendered
149
+ // again.
150
+ function defuseMarkup(text: string): string {
151
+ return text
152
+ .replace(/(?<![A-Za-z0-9/])@(?!\u200b)/g, `@${ZERO_WIDTH_SPACE}`)
153
+ .replace(/&(?=#|commat)/gi, `&${ZERO_WIDTH_SPACE}`)
154
+ .replaceAll("![", `!${ZERO_WIDTH_SPACE}[`)
155
+ .replace(/<(?=[a-zA-Z/!?])/g, `<${ZERO_WIDTH_SPACE}`)
156
+ .replaceAll("-->", `--${ZERO_WIDTH_SPACE}>`);
157
+ }
158
+
159
+ export function publishedText(text: string): string {
160
+ return defuseMarkup(redactSecrets(text));
161
+ }
@@ -10,6 +10,7 @@
10
10
  // sides agree on.
11
11
  //
12
12
  import { MARKER_OPEN, matchMarkerPrefix } from "../brand";
13
+ import { publishedText } from "../security/published-text";
13
14
 
14
15
  // Disjoint from PR_COMMENT_MARKER_PREFIX and PR_FINDING_MARKER_PREFIX on
15
16
  // purpose, same reasoning as their own disjointness (pr/preflight.ts): a
@@ -129,7 +130,7 @@ export function renderTriageReplyBody(
129
130
  reasoning: string,
130
131
  ): string {
131
132
  const head = `${triageMarker(fields)}\n\n${triageBadge(fields)}`;
132
- const prose = reasoning.trim();
133
+ const prose = publishedText(reasoning.trim());
133
134
  return prose.length === 0 ? `${head}\n` : `${head}\n\n${prose}\n`;
134
135
  }
135
136
 
package/src/updater.ts CHANGED
@@ -54,7 +54,7 @@ export function detectInstallMethod(
54
54
  ): InstallMethod {
55
55
  const home = options.home ?? os.homedir();
56
56
  const execPath = options.execPath ?? process.execPath;
57
- const version = options.version ?? "0.3.3";
57
+ const version = options.version ?? "0.4.0";
58
58
  const exists = options.exists ?? existsSync;
59
59
 
60
60
  const isSource =