@oss-autopilot/core 3.42.5 → 3.44.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 (192) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +428 -27
  3. package/dist/cli.bundle.cjs +212 -156
  4. package/dist/commands/check-integration.js +5 -1
  5. package/dist/commands/cleanup.d.ts +80 -0
  6. package/dist/commands/cleanup.js +334 -0
  7. package/dist/commands/comments.d.ts +14 -1
  8. package/dist/commands/comments.js +17 -5
  9. package/dist/commands/config.d.ts +2 -0
  10. package/dist/commands/config.js +63 -6
  11. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  12. package/dist/commands/daily-dismiss-filter.js +17 -1
  13. package/dist/commands/daily-ledger.d.ts +150 -0
  14. package/dist/commands/daily-ledger.js +248 -0
  15. package/dist/commands/daily-recent-prs.d.ts +26 -0
  16. package/dist/commands/daily-recent-prs.js +55 -0
  17. package/dist/commands/daily-render.d.ts +2 -1
  18. package/dist/commands/daily-render.js +4 -1
  19. package/dist/commands/daily.d.ts +5 -1
  20. package/dist/commands/daily.js +83 -93
  21. package/dist/commands/dashboard-cache.d.ts +2 -0
  22. package/dist/commands/dashboard-cache.js +33 -8
  23. package/dist/commands/dashboard-data.js +113 -69
  24. package/dist/commands/dashboard-gist-sync.js +3 -1
  25. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  26. package/dist/commands/dashboard-lifecycle.js +132 -39
  27. package/dist/commands/dashboard-process.d.ts +49 -1
  28. package/dist/commands/dashboard-process.js +111 -12
  29. package/dist/commands/dashboard-server.js +89 -23
  30. package/dist/commands/detect-formatters.js +1 -0
  31. package/dist/commands/dismiss.js +11 -7
  32. package/dist/commands/doctor.d.ts +15 -1
  33. package/dist/commands/doctor.js +66 -5
  34. package/dist/commands/draft.d.ts +77 -0
  35. package/dist/commands/draft.js +218 -0
  36. package/dist/commands/eval.js +1 -0
  37. package/dist/commands/fork-prune.d.ts +58 -0
  38. package/dist/commands/fork-prune.js +247 -0
  39. package/dist/commands/guidelines.d.ts +69 -2
  40. package/dist/commands/guidelines.js +158 -14
  41. package/dist/commands/index.d.ts +29 -4
  42. package/dist/commands/index.js +20 -3
  43. package/dist/commands/issue-thread.d.ts +46 -0
  44. package/dist/commands/issue-thread.js +123 -0
  45. package/dist/commands/ledger-backfill.d.ts +9 -0
  46. package/dist/commands/ledger-backfill.js +44 -1
  47. package/dist/commands/list-mark-done.d.ts +2 -1
  48. package/dist/commands/list-mark-done.js +3 -1
  49. package/dist/commands/list-move-tier.d.ts +2 -1
  50. package/dist/commands/list-move-tier.js +3 -1
  51. package/dist/commands/local-repos.js +10 -5
  52. package/dist/commands/locate-issue-list.d.ts +40 -17
  53. package/dist/commands/locate-issue-list.js +148 -88
  54. package/dist/commands/move.js +7 -1
  55. package/dist/commands/overnight-handoff.d.ts +17 -7
  56. package/dist/commands/overnight-handoff.js +36 -14
  57. package/dist/commands/overnight-push-prep.d.ts +14 -8
  58. package/dist/commands/overnight-push-prep.js +107 -35
  59. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  60. package/dist/commands/overnight-tool-rules.js +217 -0
  61. package/dist/commands/overnight.d.ts +5 -6
  62. package/dist/commands/overnight.js +61 -140
  63. package/dist/commands/parse-list.js +7 -1
  64. package/dist/commands/policy.d.ts +90 -0
  65. package/dist/commands/policy.js +276 -0
  66. package/dist/commands/pr-create.d.ts +48 -0
  67. package/dist/commands/pr-create.js +200 -0
  68. package/dist/commands/pr-preflight.d.ts +69 -0
  69. package/dist/commands/pr-preflight.js +348 -0
  70. package/dist/commands/repo-vet.d.ts +9 -0
  71. package/dist/commands/repo-vet.js +36 -11
  72. package/dist/commands/scout-bridge.js +18 -8
  73. package/dist/commands/search.js +7 -0
  74. package/dist/commands/setup.d.ts +3 -3
  75. package/dist/commands/setup.js +160 -48
  76. package/dist/commands/skip-add.js +10 -1
  77. package/dist/commands/startup.d.ts +12 -3
  78. package/dist/commands/startup.js +82 -49
  79. package/dist/commands/state-cmd.d.ts +2 -0
  80. package/dist/commands/state-cmd.js +5 -1
  81. package/dist/commands/stats.js +1 -0
  82. package/dist/commands/status.js +6 -0
  83. package/dist/commands/strategy.js +1 -0
  84. package/dist/commands/validation.d.ts +5 -0
  85. package/dist/commands/validation.js +5 -0
  86. package/dist/commands/vet-list.d.ts +6 -0
  87. package/dist/commands/vet-list.js +26 -1
  88. package/dist/commands/vet.d.ts +20 -0
  89. package/dist/commands/vet.js +133 -2
  90. package/dist/commands/work.d.ts +4 -0
  91. package/dist/commands/work.js +34 -11
  92. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  93. package/dist/core/anti-llm-policy.d.ts +3 -0
  94. package/dist/core/anti-llm-policy.js +3 -0
  95. package/dist/core/auth.js +2 -0
  96. package/dist/core/ci-analysis.d.ts +7 -2
  97. package/dist/core/ci-analysis.js +76 -21
  98. package/dist/core/commit-date.d.ts +45 -0
  99. package/dist/core/commit-date.js +45 -0
  100. package/dist/core/compliance-score.d.ts +3 -0
  101. package/dist/core/compliance-score.js +13 -9
  102. package/dist/core/config-registry.d.ts +27 -2
  103. package/dist/core/config-registry.js +94 -7
  104. package/dist/core/contributing.d.ts +2 -3
  105. package/dist/core/contributing.js +2 -3
  106. package/dist/core/daily-logic.d.ts +30 -5
  107. package/dist/core/daily-logic.js +68 -19
  108. package/dist/core/errors.d.ts +37 -3
  109. package/dist/core/errors.js +54 -5
  110. package/dist/core/fork-prune.d.ts +149 -0
  111. package/dist/core/fork-prune.js +333 -0
  112. package/dist/core/gist-health.d.ts +15 -3
  113. package/dist/core/gist-health.js +8 -0
  114. package/dist/core/gist-state-store.d.ts +24 -4
  115. package/dist/core/gist-state-store.js +98 -51
  116. package/dist/core/github-stats.d.ts +110 -16
  117. package/dist/core/github-stats.js +295 -110
  118. package/dist/core/http-cache.d.ts +0 -10
  119. package/dist/core/http-cache.js +0 -19
  120. package/dist/core/index.d.ts +13 -6
  121. package/dist/core/index.js +16 -6
  122. package/dist/core/issue-conversation.d.ts +8 -2
  123. package/dist/core/issue-conversation.js +31 -12
  124. package/dist/core/local-config.d.ts +95 -0
  125. package/dist/core/local-config.js +270 -0
  126. package/dist/core/merged-pr-notes.d.ts +2 -2
  127. package/dist/core/pacing.d.ts +41 -0
  128. package/dist/core/pacing.js +115 -0
  129. package/dist/core/pagination.d.ts +55 -0
  130. package/dist/core/pagination.js +59 -0
  131. package/dist/core/paths.d.ts +7 -0
  132. package/dist/core/paths.js +9 -0
  133. package/dist/core/pr-assembly.d.ts +2 -0
  134. package/dist/core/pr-assembly.js +6 -2
  135. package/dist/core/pr-graphql.d.ts +53 -4
  136. package/dist/core/pr-graphql.js +87 -14
  137. package/dist/core/pr-monitor.d.ts +35 -12
  138. package/dist/core/pr-monitor.js +110 -26
  139. package/dist/core/pr-preflight.d.ts +154 -0
  140. package/dist/core/pr-preflight.js +753 -0
  141. package/dist/core/pr-quality-rubric.d.ts +0 -6
  142. package/dist/core/pr-quality-rubric.js +0 -8
  143. package/dist/core/pr-template.d.ts +2 -0
  144. package/dist/core/pr-template.js +5 -1
  145. package/dist/core/prose-script.d.ts +72 -0
  146. package/dist/core/prose-script.js +223 -0
  147. package/dist/core/repo-policy.d.ts +111 -0
  148. package/dist/core/repo-policy.js +428 -0
  149. package/dist/core/repo-score-manager.d.ts +66 -0
  150. package/dist/core/repo-score-manager.js +140 -1
  151. package/dist/core/review-analysis.d.ts +49 -21
  152. package/dist/core/review-analysis.js +89 -15
  153. package/dist/core/reviewed-prs-fetch.js +11 -29
  154. package/dist/core/reviewed-prs.js +8 -15
  155. package/dist/core/stale-data.d.ts +78 -0
  156. package/dist/core/stale-data.js +153 -0
  157. package/dist/core/state-persistence.d.ts +62 -27
  158. package/dist/core/state-persistence.js +338 -119
  159. package/dist/core/state-schema.d.ts +152 -210
  160. package/dist/core/state-schema.js +232 -80
  161. package/dist/core/state.d.ts +81 -8
  162. package/dist/core/state.js +239 -46
  163. package/dist/core/status-determination.js +32 -12
  164. package/dist/core/strategy.js +3 -1
  165. package/dist/core/types.d.ts +22 -1
  166. package/dist/core/types.js +1 -0
  167. package/dist/core/untrusted-content.d.ts +30 -11
  168. package/dist/core/untrusted-content.js +95 -42
  169. package/dist/core/urls.d.ts +33 -0
  170. package/dist/core/urls.js +94 -0
  171. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  172. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  173. package/dist/dashboard/index.html +1 -1
  174. package/dist/formatters/json.d.ts +432 -10
  175. package/dist/formatters/json.js +156 -1
  176. package/package.json +6 -6
  177. package/dist/core/ci-enforced-tools.d.ts +0 -35
  178. package/dist/core/ci-enforced-tools.js +0 -109
  179. package/dist/core/comment-decision.d.ts +0 -79
  180. package/dist/core/comment-decision.js +0 -82
  181. package/dist/core/extraction-categories.d.ts +0 -55
  182. package/dist/core/extraction-categories.js +0 -108
  183. package/dist/core/follow-up-history.d.ts +0 -40
  184. package/dist/core/follow-up-history.js +0 -71
  185. package/dist/core/issue-effort.d.ts +0 -29
  186. package/dist/core/issue-effort.js +0 -47
  187. package/dist/core/maintainer-hints.d.ts +0 -23
  188. package/dist/core/maintainer-hints.js +0 -36
  189. package/dist/core/workflow-state.d.ts +0 -56
  190. package/dist/core/workflow-state.js +0 -101
  191. package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
  192. package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
@@ -56,12 +56,6 @@ export declare const TITLE_LENGTH_BUDGET = 72;
56
56
  * checklist in; the weights total 100 across the scored entries.
57
57
  */
58
58
  export declare const PR_QUALITY_RUBRIC: readonly PRQualityCheck[];
59
- /**
60
- * Look up a check by id. Used by `compliance-score.ts` to wire the
61
- * scored checks to their canonical weight without hardcoding the
62
- * value in two places.
63
- */
64
- export declare function getRubricCheck(id: PRQualityCheck['id']): PRQualityCheck | undefined;
65
59
  /**
66
60
  * Sum of the weights for scored checks. Should equal 100. Tests pin
67
61
  * this so a future edit that fails to balance the weights surfaces
@@ -103,14 +103,6 @@ export const PR_QUALITY_RUBRIC = [
103
103
  weight: null,
104
104
  },
105
105
  ];
106
- /**
107
- * Look up a check by id. Used by `compliance-score.ts` to wire the
108
- * scored checks to their canonical weight without hardcoding the
109
- * value in two places.
110
- */
111
- export function getRubricCheck(id) {
112
- return PR_QUALITY_RUBRIC.find((c) => c.id === id);
113
- }
114
106
  /**
115
107
  * Sum of the weights for scored checks. Should equal 100. Tests pin
116
108
  * this so a future edit that fails to balance the weights surfaces
@@ -19,6 +19,8 @@ export interface PRTemplateResult {
19
19
  /** If non-null, an error prevented a complete check of all template paths. */
20
20
  error?: string;
21
21
  }
22
+ /** UTF-8 text of a base64 `content` field from the contents API. */
23
+ export declare function decodeBase64(content: string): string;
22
24
  /**
23
25
  * Fetch a repository's PR template by trying each standard location.
24
26
  * Returns on the first successful match. Rate limit and auth errors
@@ -20,6 +20,10 @@ const TEMPLATE_PATHS = [
20
20
  'docs/pull_request_template.md',
21
21
  'pull_request_template.md',
22
22
  ];
23
+ /** UTF-8 text of a base64 `content` field from the contents API. */
24
+ export function decodeBase64(content) {
25
+ return Buffer.from(content, 'base64').toString('utf8');
26
+ }
23
27
  /**
24
28
  * Fetch a repository's PR template by trying each standard location.
25
29
  * Returns on the first successful match. Rate limit and auth errors
@@ -43,7 +47,7 @@ export async function fetchPRTemplate(octokit, owner, repo) {
43
47
  debug(MODULE, `${path} has no content, skipping`);
44
48
  continue;
45
49
  }
46
- const template = Buffer.from(data.content, 'base64').toString('utf8');
50
+ const template = decodeBase64(data.content);
47
51
  debug(MODULE, `Found PR template at ${path} (${template.length} chars)`);
48
52
  return { template, source: path };
49
53
  }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The writing system of outgoing prose against the one a repo uses (#1909).
3
+ *
4
+ * A cheap script check, not language detection: it counts letters per
5
+ * Unicode script outside code, quoted text, URLs and identifiers. English and
6
+ * Spanish are both Latin script and look the same here; Chinese text sent to
7
+ * an English-language repo, the failure this guards against, does not.
8
+ * Latin-script text is never refused: English is welcome in any repo, and a
9
+ * non-Latin README that names English products would otherwise block it.
10
+ */
11
+ import type { Octokit } from '@octokit/rest';
12
+ export type ProseScript = 'Latin' | 'Han/Kana' | 'Hangul' | 'Cyrillic' | 'Arabic' | 'Hebrew' | 'Thai' | 'Devanagari' | 'Greek';
13
+ /** The script assumed when the repo's README and CONTRIBUTING cannot be read: English, per #1909. */
14
+ export declare const DEFAULT_REPO_SCRIPTS: readonly ProseScript[];
15
+ /** A script with at least this share of a repo's doc prose is one the repo writes in; two can pass (bilingual docs). */
16
+ export declare const REPO_SCRIPT_MIN_SHARE = 0.2;
17
+ /** Below this much weighted prose the docs say nothing reliable about the repo's language. */
18
+ export declare const MIN_REPO_PROSE_WEIGHT = 40;
19
+ /** Text is refused only when foreign-script prose is the majority: names and quoted errors in another script pass. */
20
+ export declare const MISMATCH_SHARE = 0.5;
21
+ /** Less foreign-script prose than this never blocks, so a short reply with one foreign word passes. */
22
+ export declare const MIN_FOREIGN_WEIGHT = 12;
23
+ /** Titles count every letter as 1: a short English title naming a CJK product (`Add 微信支付 support`) stays English. */
24
+ export declare const MIN_TITLE_FOREIGN_LETTERS = 4;
25
+ /** A title is refused only when more than two thirds of its letters are foreign, so a name beside two English words passes. */
26
+ export declare const TITLE_MISMATCH_SHARE: number;
27
+ /**
28
+ * The prose lines of `text`: no code, blockquotes, comments, URLs, tags or
29
+ * identifiers. A fence that never closes is text, so it cannot hide what follows.
30
+ */
31
+ export declare function proseLines(text: string): string[];
32
+ /** The scripts a repo's docs are written in; null when they hold too little prose to tell. */
33
+ export declare function docScripts(docs: string): ProseScript[] | null;
34
+ export interface ScriptMismatch {
35
+ /** Scripts in the text the repo does not write in (never Latin). */
36
+ foreign: ProseScript[];
37
+ /** Weighted share of the text's prose in those scripts, 0 to 1. */
38
+ share: number;
39
+ /** The first prose lines with a foreign-script letter, cut short. */
40
+ excerpt: string;
41
+ }
42
+ /**
43
+ * Null when `text` is written in the `accepted` scripts, in Latin script, or
44
+ * is too short to tell; else what does not match.
45
+ */
46
+ export declare function scriptMismatch(text: string, accepted: readonly ProseScript[]): ScriptMismatch | null;
47
+ /** {@link scriptMismatch} for a PR title: prefix dropped, every letter weighs 1, a stricter share. */
48
+ export declare function titleMismatch(title: string, accepted: readonly ProseScript[]): ScriptMismatch | null;
49
+ export interface RepoScripts {
50
+ scripts: readonly ProseScript[];
51
+ /** True when the docs could not be read or said too little, so {@link DEFAULT_REPO_SCRIPTS} was used. */
52
+ isDefault: boolean;
53
+ }
54
+ /** The denial text: which repo, which scripts, how much, and the offending lines. */
55
+ export declare function describeMismatch(repo: string, repoScripts: RepoScripts, mismatch: ScriptMismatch): string;
56
+ /**
57
+ * The scripts `owner/repo` writes in, read from its README and CONTRIBUTING
58
+ * through the shared ETag cache. Never throws: an unreadable repo gets the
59
+ * English default, marked `isDefault`.
60
+ */
61
+ export declare function readRepoScripts(octokit: Octokit, owner: string, repo: string): Promise<RepoScripts>;
62
+ /**
63
+ * Check `text` against the script `owner/repo` writes in (#1909). Every
64
+ * comment `post` and `claim` send, from the CLI or MCP, crosses this before
65
+ * GitHub is written to. A mismatch is refused; with `isMismatchAllowed` (a CLI
66
+ * flag only, never an MCP argument) it comes back as a warning instead. No
67
+ * rewrite, no translation.
68
+ */
69
+ export declare function checkRepoScript(octokit: Octokit, target: {
70
+ owner: string;
71
+ repo: string;
72
+ }, text: string, isMismatchAllowed: boolean): Promise<string | undefined>;
@@ -0,0 +1,223 @@
1
+ /**
2
+ * The writing system of outgoing prose against the one a repo uses (#1909).
3
+ *
4
+ * A cheap script check, not language detection: it counts letters per
5
+ * Unicode script outside code, quoted text, URLs and identifiers. English and
6
+ * Spanish are both Latin script and look the same here; Chinese text sent to
7
+ * an English-language repo, the failure this guards against, does not.
8
+ * Latin-script text is never refused: English is welcome in any repo, and a
9
+ * non-Latin README that names English products would otherwise block it.
10
+ */
11
+ import { codeMask } from './compliance-score.js';
12
+ import { ValidationError } from './errors.js';
13
+ import { cachedRequest, getHttpCache } from './http-cache.js';
14
+ import { decodeBase64 } from './pr-template.js';
15
+ /**
16
+ * Each script with the weight of one of its letters. A Han or Kana character
17
+ * carries about a word, a Hangul syllable about a syllable, so they count for
18
+ * more than one alphabet letter: a Chinese body sprinkled with English terms
19
+ * still reads as Chinese.
20
+ */
21
+ const SCRIPTS = [
22
+ { script: 'Latin', pattern: /\p{Script=Latin}/u, weight: 1 },
23
+ { script: 'Han/Kana', pattern: /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u, weight: 3 },
24
+ { script: 'Hangul', pattern: /\p{Script=Hangul}/u, weight: 2 },
25
+ { script: 'Cyrillic', pattern: /\p{Script=Cyrillic}/u, weight: 1 },
26
+ { script: 'Arabic', pattern: /\p{Script=Arabic}/u, weight: 1 },
27
+ { script: 'Hebrew', pattern: /\p{Script=Hebrew}/u, weight: 1 },
28
+ { script: 'Thai', pattern: /\p{Script=Thai}/u, weight: 1 },
29
+ { script: 'Devanagari', pattern: /\p{Script=Devanagari}/u, weight: 1 },
30
+ { script: 'Greek', pattern: /\p{Script=Greek}/u, weight: 1 },
31
+ ];
32
+ /** The script assumed when the repo's README and CONTRIBUTING cannot be read: English, per #1909. */
33
+ export const DEFAULT_REPO_SCRIPTS = ['Latin'];
34
+ /** A script with at least this share of a repo's doc prose is one the repo writes in; two can pass (bilingual docs). */
35
+ export const REPO_SCRIPT_MIN_SHARE = 0.2;
36
+ /** Below this much weighted prose the docs say nothing reliable about the repo's language. */
37
+ export const MIN_REPO_PROSE_WEIGHT = 40;
38
+ /** Text is refused only when foreign-script prose is the majority: names and quoted errors in another script pass. */
39
+ export const MISMATCH_SHARE = 0.5;
40
+ /** Less foreign-script prose than this never blocks, so a short reply with one foreign word passes. */
41
+ export const MIN_FOREIGN_WEIGHT = 12;
42
+ /** Titles count every letter as 1: a short English title naming a CJK product (`Add 微信支付 support`) stays English. */
43
+ export const MIN_TITLE_FOREIGN_LETTERS = 4;
44
+ /** A title is refused only when more than two thirds of its letters are foreign, so a name beside two English words passes. */
45
+ export const TITLE_MISMATCH_SHARE = 2 / 3;
46
+ /** A leading Conventional Commits prefix (`fix(scope)!: `) is boilerplate, not the language the title is written in. */
47
+ const CONVENTIONAL_PREFIX = /^\s*\w+(?:\([^)\n]*\))?!?:\s*/;
48
+ const MAX_EXCERPT_CHARS = 200;
49
+ const QUOTE_LINE = /^\s*>/;
50
+ const HTML_COMMENT = /<!--[\s\S]*?(?:-->|$)/g;
51
+ const URL = /(?:https?:\/\/|www\.)[\w$.,/\\?#&=%:;@~+!*'-]+/gi;
52
+ const HTML_TAG = /<[^<>\n]*>/g;
53
+ /** A run of code-like characters. CJK has no spaces, so the run, not the whole word, is what gets removed. */
54
+ const CODE_RUN = /[\w$./\\()-]+/g;
55
+ // A run that is a path, a snake_case or camelCase name, a dotted name or a call: code, not prose.
56
+ const IDENTIFIER = /[_/\\]|[A-Za-z\d]\.[A-Za-z\d]|[a-z][A-Z]|\(\)/;
57
+ /** `text` with fenced and inline code (closed spans only, as the compliance score reads them) blanked out. */
58
+ function withoutCode(text) {
59
+ const mask = codeMask(text);
60
+ return text.replaceAll(/[^\n]/g, (char, offset) => (mask[offset] === 1 ? ' ' : char));
61
+ }
62
+ /**
63
+ * The prose lines of `text`: no code, blockquotes, comments, URLs, tags or
64
+ * identifiers. A fence that never closes is text, so it cannot hide what follows.
65
+ */
66
+ export function proseLines(text) {
67
+ const lines = [];
68
+ for (const line of withoutCode(text).replaceAll(HTML_COMMENT, ' ').split('\n')) {
69
+ const prose = QUOTE_LINE.test(line) ? '' : lineProse(line);
70
+ if (prose !== '')
71
+ lines.push(prose);
72
+ }
73
+ return lines;
74
+ }
75
+ function lineProse(line) {
76
+ return line
77
+ .replaceAll(URL, ' ')
78
+ .replaceAll(HTML_TAG, ' ')
79
+ .replaceAll(CODE_RUN, (run) => (IDENTIFIER.test(run) ? ' ' : run))
80
+ .replaceAll(/\s+/g, ' ')
81
+ .trim();
82
+ }
83
+ function scriptOf(char) {
84
+ return SCRIPTS.find((entry) => entry.pattern.test(char));
85
+ }
86
+ const byScriptWeight = (entry) => entry.weight;
87
+ /** Weighted letter count per script. Letters of scripts not listed (and digits, punctuation) are ignored. */
88
+ function scriptWeights(lines, weigh = byScriptWeight) {
89
+ const weights = new Map();
90
+ for (const char of lines.join(' ')) {
91
+ const entry = scriptOf(char);
92
+ if (entry)
93
+ weights.set(entry.script, (weights.get(entry.script) ?? 0) + weigh(entry));
94
+ }
95
+ return weights;
96
+ }
97
+ function total(weights) {
98
+ let sum = 0;
99
+ for (const weight of weights.values())
100
+ sum += weight;
101
+ return sum;
102
+ }
103
+ /** The scripts a repo's docs are written in; null when they hold too little prose to tell. */
104
+ export function docScripts(docs) {
105
+ const weights = scriptWeights(proseLines(docs));
106
+ const sum = total(weights);
107
+ if (sum < MIN_REPO_PROSE_WEIGHT)
108
+ return null;
109
+ return SCRIPTS.map((entry) => entry.script).filter((script) => (weights.get(script) ?? 0) / sum >= REPO_SCRIPT_MIN_SHARE);
110
+ }
111
+ const BODY_RULE = { weigh: byScriptWeight, minForeign: MIN_FOREIGN_WEIGHT, share: MISMATCH_SHARE };
112
+ const TITLE_RULE = { weigh: () => 1, minForeign: MIN_TITLE_FOREIGN_LETTERS, share: TITLE_MISMATCH_SHARE };
113
+ /**
114
+ * Null when `text` is written in the `accepted` scripts, in Latin script, or
115
+ * is too short to tell; else what does not match.
116
+ */
117
+ export function scriptMismatch(text, accepted) {
118
+ return mismatchUnder(text, accepted, BODY_RULE);
119
+ }
120
+ /** {@link scriptMismatch} for a PR title: prefix dropped, every letter weighs 1, a stricter share. */
121
+ export function titleMismatch(title, accepted) {
122
+ return mismatchUnder(title.replace(CONVENTIONAL_PREFIX, ''), accepted, TITLE_RULE);
123
+ }
124
+ function mismatchUnder(text, accepted, rule) {
125
+ const lines = proseLines(text);
126
+ const weights = scriptWeights(lines, rule.weigh);
127
+ const foreignScripts = SCRIPTS.map((entry) => entry.script).filter(
128
+ // Latin is never foreign: English is welcome everywhere, so only a non-Latin majority is refused.
129
+ (script) => script !== 'Latin' && !accepted.includes(script) && weights.has(script));
130
+ let foreignWeight = 0;
131
+ for (const script of foreignScripts)
132
+ foreignWeight += weights.get(script) ?? 0;
133
+ const share = foreignWeight / (total(weights) || 1);
134
+ if (foreignWeight < rule.minForeign || share <= rule.share)
135
+ return null;
136
+ const isForeign = (char) => {
137
+ const script = scriptOf(char)?.script;
138
+ return script !== undefined && foreignScripts.includes(script);
139
+ };
140
+ const excerpt = lines.filter((line) => [...line].some((char) => isForeign(char))).join('\n');
141
+ return {
142
+ share,
143
+ foreign: foreignScripts,
144
+ excerpt: excerpt.length > MAX_EXCERPT_CHARS ? `${excerpt.slice(0, MAX_EXCERPT_CHARS)}…` : excerpt,
145
+ };
146
+ }
147
+ /** The denial text: which repo, which scripts, how much, and the offending lines. */
148
+ export function describeMismatch(repo, repoScripts, mismatch) {
149
+ const assumed = repoScripts.isDefault
150
+ ? ' (assumed: its README and CONTRIBUTING could not be read or say too little)'
151
+ : '';
152
+ const percent = Math.round(mismatch.share * 100);
153
+ return (`language mismatch: ${repo} writes in ${repoScripts.scripts.join(' and ')} script${assumed}, ` +
154
+ `but ${percent}% of this text's prose is in ${mismatch.foreign.join(' and ')} script; ` +
155
+ `rewrite it in the repo's language. Quoted log or error text in another script can go in a \`\`\` code fence or a > blockquote, which this check ignores. ` +
156
+ `Only if the user confirms the repo's language was misjudged, they can post from the terminal with --allow-script-mismatch. ` +
157
+ `Offending text: ${JSON.stringify(mismatch.excerpt)}`);
158
+ }
159
+ /** A doc's decoded text through the ETag cache (a repeat read is a free 304); '' when missing or unreadable. */
160
+ async function cachedDocText(url, fetch) {
161
+ let data;
162
+ try {
163
+ data = await cachedRequest(getHttpCache(), url, fetch);
164
+ }
165
+ catch {
166
+ return '';
167
+ }
168
+ const content = data.content;
169
+ return typeof content === 'string' ? decodeBase64(content) : '';
170
+ }
171
+ /**
172
+ * The CONTRIBUTING file wherever GitHub finds it (root, `.github/`, `docs/`),
173
+ * located through the community profile. Both reads go through the ETag cache;
174
+ * the profile answers 200 even without the file, so a missing CONTRIBUTING
175
+ * costs a free 304 on later reads instead of fresh 404s.
176
+ */
177
+ async function contributingText(octokit, owner, repo, base) {
178
+ let profile;
179
+ try {
180
+ profile = await cachedRequest(getHttpCache(), `${base}/community/profile`, (headers) => octokit.repos.getCommunityProfileMetrics({ owner, repo, headers }));
181
+ }
182
+ catch {
183
+ return '';
184
+ }
185
+ const url = profile.files?.contributing?.url;
186
+ const path = typeof url === 'string' ? /\/contents\/([^?#]+)/.exec(url)?.[1] : undefined;
187
+ if (path === undefined)
188
+ return '';
189
+ return cachedDocText(`${base}/contents/${path}`, (headers) => octokit.repos.getContent({ owner, repo, path, headers }));
190
+ }
191
+ /**
192
+ * The scripts `owner/repo` writes in, read from its README and CONTRIBUTING
193
+ * through the shared ETag cache. Never throws: an unreadable repo gets the
194
+ * English default, marked `isDefault`.
195
+ */
196
+ export async function readRepoScripts(octokit, owner, repo) {
197
+ const base = `/repos/${owner}/${repo}`;
198
+ const docs = await Promise.all([
199
+ cachedDocText(`${base}/readme`, (headers) => octokit.repos.getReadme({ owner, repo, headers })),
200
+ contributingText(octokit, owner, repo, base),
201
+ ]);
202
+ const scripts = docScripts(docs.join('\n'));
203
+ return scripts && scripts.length > 0
204
+ ? { scripts, isDefault: false }
205
+ : { scripts: DEFAULT_REPO_SCRIPTS, isDefault: true };
206
+ }
207
+ /**
208
+ * Check `text` against the script `owner/repo` writes in (#1909). Every
209
+ * comment `post` and `claim` send, from the CLI or MCP, crosses this before
210
+ * GitHub is written to. A mismatch is refused; with `isMismatchAllowed` (a CLI
211
+ * flag only, never an MCP argument) it comes back as a warning instead. No
212
+ * rewrite, no translation.
213
+ */
214
+ export async function checkRepoScript(octokit, target, text, isMismatchAllowed) {
215
+ const repoScripts = await readRepoScripts(octokit, target.owner, target.repo);
216
+ const mismatch = scriptMismatch(text, repoScripts.scripts);
217
+ if (!mismatch)
218
+ return undefined;
219
+ const message = describeMismatch(`${target.owner}/${target.repo}`, repoScripts, mismatch);
220
+ if (isMismatchAllowed)
221
+ return message;
222
+ throw new ValidationError(message);
223
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Per-repo contribution policy (#1953): AI policy, disclosure line, CLA,
3
+ * commit rules and the gate before a PR, as one record per repo.
4
+ *
5
+ * `derivePolicy` runs the anti-LLM / disclosure scans (anti-llm-policy.ts)
6
+ * and the CONTRIBUTING requirement extraction (contributing.ts) over a repo's
7
+ * docs. `vet` and `vet-list` store the result unreviewed, `policy set` stores the user's
8
+ * record, and `pr-preflight` enforces it (including the commit rules).
9
+ *
10
+ * Policy text comes from other people's repos, so a record holds only
11
+ * enumerated values plus short quoted lines ({@link quote}). The older
12
+ * `config.aiPolicyBlocklist` is read as a ban on top of any stored record:
13
+ * nothing stored can lift it ({@link effectivePolicy}).
14
+ */
15
+ import { type AgentState, type RepoPolicy } from './state-schema.js';
16
+ export type { RepoPolicy } from './state-schema.js';
17
+ export type AiPolicy = RepoPolicy['aiPolicy'];
18
+ export type PrGate = RepoPolicy['prGate'];
19
+ export type ClaPolicy = RepoPolicy['cla'];
20
+ export declare const AI_POLICIES: readonly AiPolicy[];
21
+ export declare const PR_GATES: readonly PrGate[];
22
+ export declare const CLA_POLICIES: readonly ClaPolicy[];
23
+ export declare const COMMIT_RULES: readonly ["conventional-commits", "dco-signoff", "no-closing-keyword-in-commit"];
24
+ /** Source label for a ban that comes from `config.aiPolicyBlocklist`. */
25
+ export declare const BLOCKLIST_SOURCE = "config aiPolicyBlocklist";
26
+ type PolicyState = Pick<AgentState, 'config' | 'repoPolicies'>;
27
+ /** One repo document the parsers read: a path and its text. */
28
+ export interface PolicyDoc {
29
+ file: string;
30
+ content: string;
31
+ }
32
+ /** Enumerated fields only: safe to show without a fence. */
33
+ export interface RepoPolicySummary {
34
+ aiPolicy: AiPolicy;
35
+ cla: ClaPolicy;
36
+ prGate: PrGate;
37
+ commitRules: string[];
38
+ maxOpenAiPRs?: number;
39
+ reviewedByUser: boolean;
40
+ }
41
+ /** One line, control characters removed, capped at {@link POLICY_QUOTE_MAX}. */
42
+ export declare function quote(text: string): string;
43
+ /**
44
+ * Derive a policy from a repo's docs (CONTRIBUTING, PR template, ...). With no
45
+ * docs every field is `unknown`; a doc that is silent on CLA or a PR gate reads
46
+ * as `none`. Silence on AI stays `unknown`: it is not permission.
47
+ */
48
+ export declare function derivePolicy(docs: readonly PolicyDoc[], now?: Date): RepoPolicy;
49
+ /**
50
+ * Up to `max` paths in `repo` that its README links to and that look like a
51
+ * contribution guide or AI policy (relative links, or github.com blob links to
52
+ * the same repo). Links to other sites, other repos or outside the repo root
53
+ * are dropped, as are the CONTRIBUTING paths scout reads anyway.
54
+ */
55
+ export declare function linkedPolicyDocs(readme: string, repo: string, max?: number): string[];
56
+ /** Fields of the stored entry this release does not know (a newer release added them), to keep across an edit. */
57
+ export declare function unknownFields(state: PolicyState, repo: string): Record<string, unknown>;
58
+ /** A stored entry this release cannot parse, e.g. one a newer release wrote with a value added since. */
59
+ export declare function isUnreadable(state: PolicyState, repo: string): boolean;
60
+ /**
61
+ * The stored record for `repo`, or null when there is none. An entry that does
62
+ * not parse but says `aiPolicy: 'banned'` still reads as a ban (every other
63
+ * field unknown): a newer release's record must not lift a ban here. A
64
+ * disclosure excerpt an older release stored is dropped on read.
65
+ */
66
+ export declare function storedPolicy(state: PolicyState, repo: string): RepoPolicy | null;
67
+ /** True when the raw stored entry says the user set it, even when this release cannot parse the rest. */
68
+ export declare function isUserReviewed(state: PolicyState, repo: string): boolean;
69
+ export declare function isBlocklisted(state: PolicyState, repo: string): boolean;
70
+ /**
71
+ * The policy that applies to `repo`: the user's record, else a stored ban,
72
+ * else a freshly derived one when given, else the stored unreviewed one. A repo
73
+ * in `config.aiPolicyBlocklist` is banned whatever is stored: the blocklist is
74
+ * the older ban list, still synced to clients that predate policy records, and
75
+ * a record never relaxes it. Null when nothing is known.
76
+ */
77
+ export declare function effectivePolicy(state: PolicyState, repo: string, fresh?: RepoPolicy): RepoPolicy | null;
78
+ /**
79
+ * Where a ban came from, for the user: nothing for one they confirmed; how to
80
+ * lift it otherwise. A blocklist ban is lifted in config, an unreviewed one
81
+ * with `policy set`.
82
+ */
83
+ export declare function banNote(policy: RepoPolicy, repo: string): string;
84
+ /** Stored `banned` records (lowercase keys), reviewed or not. */
85
+ export declare function storedBans(state: PolicyState): Array<{
86
+ repo: string;
87
+ reviewedByUser: boolean;
88
+ }>;
89
+ /**
90
+ * Repos search leaves out: the blocklist as written, then bans the user
91
+ * confirmed. A ban vet read from the docs but nobody reviewed stays searchable
92
+ * (a heuristic must not shrink discovery on its own); vet still says skip.
93
+ */
94
+ export declare function bannedRepos(state: PolicyState): string[];
95
+ export declare function summarizePolicy(policy: RepoPolicy): RepoPolicySummary;
96
+ /** `{ policy }` with the summary to spread into an output, or `{}` when there is no policy. */
97
+ export declare function policyField(policy: RepoPolicy | null): {
98
+ policy?: RepoPolicySummary;
99
+ };
100
+ /**
101
+ * Quoted lines, disclosure text and the gate label inside `<github-content>`
102
+ * fences, for agent-facing output. `disclosureText` and `gateLabel` are only
103
+ * ever what the user set.
104
+ */
105
+ export declare function fencePolicyText(repo: string, policy: RepoPolicy): {
106
+ disclosureText?: string;
107
+ gateLabel?: string;
108
+ sources?: string;
109
+ };
110
+ /** Same rules, ignoring when they were recorded. */
111
+ export declare function isSamePolicy(a: RepoPolicy, b: RepoPolicy): boolean;