@mark1russell7/canon-ontology 0.4.0 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { R as pathOfId, r as ONTOLOGY_REPOSITORY } from "./targets-BwC2nZGy.mjs";
1
+ import { R as pathOfId, r as ONTOLOGY_REPOSITORY } from "./targets-DFXTvFDm.mjs";
2
2
  // src/board.ts
3
3
  /** The label of each issue of the board. */
4
4
  const TARGET_LABEL = "target";
@@ -224,4 +224,4 @@ function decideClaim(input) {
224
224
  }
225
225
  export { applyBoard as a, decideClaim as c, planBoard as d, targetOfIssue as f, actionComment as i, isExpired as l, CLAIM_HOURS as n, claimCommandOf as o, TARGET_LABEL as r, claimEnd as s, BOARD_LIMIT as t, issueText as u };
226
226
 
227
- //# sourceMappingURL=board-DAKpkjvV.mjs.map
227
+ //# sourceMappingURL=board-7NZb3yv_.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"board-DAKpkjvV.mjs","names":[],"sources":["../src/board.ts"],"sourcesContent":["// The target board: one GitHub issue for each claimable target, and the claims on the issues. The plan and the claim\n// decision are pure functions. The sync and the claim send the requests through an IssueApi.\nimport { pathOfId } from \"./ids.ts\";\nimport { ONTOLOGY_REPOSITORY, type TargetRecord } from \"./targets.ts\";\n\n/** The label of each issue of the board. */\nexport const TARGET_LABEL = \"target\";\n\n/** The time of a claim with no pull request, in hours. */\nexport const CLAIM_HOURS = 48;\n\n/** The most open issues of the board. */\nexport const BOARD_LIMIT = 20;\n\n/** The start of the hidden line of an issue body that has the id of its target. */\nconst MARK = \"<!-- canon-target: \";\n\n/** The end of the hidden line. */\nconst MARK_END = \" -->\";\n\n/** An issue of the board, as the API of the issues gives it. */\nexport interface BoardIssue {\n readonly number: number;\n readonly title: string;\n readonly body: string;\n readonly state: \"open\" | \"closed\";\n readonly labels: readonly string[];\n readonly assignees: readonly string[];\n /** This time is the start of the claim of an open issue with an assignee, in milliseconds since 1970. */\n readonly claimedAt?: number | undefined;\n}\n\n/** The title, the body and the labels of the issue of a target. */\nexport interface IssueText {\n readonly title: string;\n readonly body: string;\n readonly labels: readonly string[];\n}\n\n/** A change of an issue. Each field that is not here does not change. */\nexport interface IssueChange {\n readonly title?: string;\n readonly body?: string;\n readonly labels?: readonly string[];\n readonly state?: \"open\" | \"closed\";\n readonly stateReason?: \"completed\" | \"not_planned\" | \"reopened\";\n /** This list replaces the assignees of the issue. */\n readonly assignees?: readonly string[];\n}\n\n/** The API of the issues of one repository. A test gives a fake, and `githubIssueApi` gives the API of GitHub. */\nexport interface IssueApi {\n /** This method gives each issue with the label `target`, open and closed, with the start of each claim. */\n issues(): Promise<readonly BoardIssue[]>;\n /** This method tells if an open pull request names the target id. */\n hasOpenPull(targetId: string): Promise<boolean>;\n /** This method makes each label that does not exist. */\n ensureLabels(names: readonly string[]): Promise<void>;\n /** This method opens an issue, and gives its number. */\n create(text: IssueText): Promise<number>;\n /** This method changes an issue, and gives the issue after the change. */\n update(number: number, change: IssueChange): Promise<BoardIssue>;\n /** This method writes a comment on an issue. */\n comment(number: number, text: string): Promise<void>;\n}\n\n/** One step of the sync of the board. */\nexport type BoardAction =\n | { readonly kind: \"create\"; readonly target: string; readonly text: IssueText }\n | { readonly kind: \"update\"; readonly number: number; readonly target: string; readonly text: IssueText; readonly reopen: boolean }\n | { readonly kind: \"close\"; readonly number: number; readonly target: string; readonly reason: \"completed\" | \"not_planned\" }\n | { readonly kind: \"release\"; readonly number: number; readonly target: string; readonly users: readonly string[] };\n\n/** The inputs of the plan of the board. */\nexport interface BoardInput {\n /** Each target of the target query, in the order of `compareTargets`. */\n readonly targets: readonly TargetRecord[];\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n /** The ids of the targets that an open pull request names. */\n readonly pulls: ReadonlySet<string>;\n /** The most open issues. The default is `BOARD_LIMIT`. */\n readonly limit?: number | undefined;\n}\n\n/** This function gives the id of the target of an issue body, or undefined when the body has no hidden line. */\nexport function targetOfIssue(body: string): string | undefined {\n const start = body.indexOf(MARK);\n if (start < 0) return undefined;\n const end = body.indexOf(MARK_END, start + MARK.length);\n const id = end < 0 ? \"\" : body.slice(start + MARK.length, end).trim();\n return id === \"\" || /\\s/.test(id) ? undefined : id;\n}\n\n/** This function gives the time of the end of a claim, as an ISO 8601 text to the minute. */\nexport function claimEnd(claimedAt: number): string {\n return `${new Date(claimedAt + CLAIM_HOURS * 3_600_000).toISOString().slice(0, 16)}Z`;\n}\n\n/** This function tells if a claim is older than `CLAIM_HOURS`. A claim with no known start is live. */\nexport function isExpired(issue: BoardIssue, now: number): boolean {\n return issue.assignees.length > 0 && issue.claimedAt !== undefined && now - issue.claimedAt >= CLAIM_HOURS * 3_600_000;\n}\n\n/** This function gives the title, the body and the labels of the issue of a target. */\nexport function issueText(target: TargetRecord, repository: string = ONTOLOGY_REPOSITORY): IssueText {\n const { attrs } = target;\n const path = pathOfId(target.id);\n const body = [\n `${MARK}${target.id}${MARK_END}`,\n `**Target:** \\`${target.id}\\``,\n \"\",\n \"| Gap | Home | Size | Area |\",\n \"| --- | --- | --- | --- |\",\n `| \\`${attrs.gap}\\` | [${attrs.home}](https://github.com/${attrs.home}) | ${attrs.size} | ${attrs.area === undefined ? \"\" : `\\`${attrs.area}\\``} |`,\n \"\",\n \"## Acceptance\",\n \"\",\n attrs.acceptance.text,\n \"\",\n ...attrs.acceptance.checks.map((check) => `- [ ] ${check}`),\n \"\",\n \"## Why\",\n \"\",\n attrs.why,\n \"\",\n \"## Claim and close\",\n \"\",\n `1. Write the comment \\`/claim\\` on this issue. A claim stops after ${String(CLAIM_HOURS)} hours with no open pull request.`,\n `2. Do the work. [\\`AGENTS.md\\`](https://github.com/${repository}/blob/main/AGENTS.md) tells how.`,\n `3. In the pull request, write the line \\`Target: ${target.id}\\`.`,\n \"\",\n `The record of the target is [\\`${path}\\`](https://github.com/${repository}/blob/main/${path}). Write \\`/unclaim\\` to stop your claim.`,\n \"\",\n ].join(\"\\n\");\n return { title: attrs.title, body, labels: [TARGET_LABEL, `gap:${attrs.gap}`] };\n}\n\n/** This function tells if an issue has the text of a target: the same title, body and labels. */\nfunction sameText(issue: BoardIssue, text: IssueText): boolean {\n const labels = [...issue.labels].sort();\n const wanted = [...text.labels].sort();\n return issue.title === text.title && issue.body === text.body && labels.length === wanted.length && labels.every((label, index) => label === wanted[index]);\n}\n\n/**\n * This function gives the steps that make the board agree with the target query.\n *\n * - The board keeps the open issue of each claimable target. It adds other claimable targets, up to the limit. An issue\n * does not close because new targets come before it.\n * - Each added target is the first claimable target of the gap with the fewest targets on the board. So one gap with\n * many targets does not fill the board.\n * - An issue whose target is not claimable closes: `completed` when the target is gone, else `not_planned`.\n * - A claim older than `CLAIM_HOURS` stops when no open pull request names its target.\n * - An issue with no hidden line is not an issue of the board. Of two issues of one target, the board uses the first.\n */\nexport function planBoard(input: BoardInput): readonly BoardAction[] {\n const limit = input.limit ?? BOARD_LIMIT;\n const known = new Set(input.targets.map((target) => target.id));\n const claimable = input.targets.filter((target) => target.attrs.claimable);\n const byTarget = new Map<string, BoardIssue>();\n for (const issue of [...input.issues].sort((a, b) => a.number - b.number)) {\n const id = targetOfIssue(issue.body);\n if (id !== undefined && !byTarget.has(id)) byTarget.set(id, issue);\n }\n const board = new Set(claimable.filter((target) => byTarget.get(target.id)?.state === \"open\").map((target) => target.id));\n const gaps = new Map<string, number>();\n for (const target of claimable) if (board.has(target.id)) gaps.set(target.attrs.gap, (gaps.get(target.attrs.gap) ?? 0) + 1);\n const waiting = claimable.filter((target) => !board.has(target.id));\n while (board.size < limit && waiting.length > 0) {\n let best = 0;\n for (let index = 1; index < waiting.length; index += 1) {\n if ((gaps.get(waiting[index]?.attrs.gap ?? \"\") ?? 0) < (gaps.get(waiting[best]?.attrs.gap ?? \"\") ?? 0)) best = index;\n }\n const [next] = waiting.splice(best, 1);\n if (next === undefined) break;\n board.add(next.id);\n gaps.set(next.attrs.gap, (gaps.get(next.attrs.gap) ?? 0) + 1);\n }\n const actions: BoardAction[] = [];\n for (const target of claimable.filter((candidate) => board.has(candidate.id))) {\n const text = issueText(target);\n const issue = byTarget.get(target.id);\n if (issue === undefined) {\n actions.push({ kind: \"create\", target: target.id, text });\n continue;\n }\n if (issue.state === \"closed\" || !sameText(issue, text)) actions.push({ kind: \"update\", number: issue.number, target: target.id, text, reopen: issue.state === \"closed\" });\n if (issue.state === \"open\" && isExpired(issue, input.now) && !input.pulls.has(target.id)) {\n actions.push({ kind: \"release\", number: issue.number, target: target.id, users: issue.assignees });\n }\n }\n for (const [target, issue] of byTarget) {\n if (issue.state === \"open\" && !board.has(target)) actions.push({ kind: \"close\", number: issue.number, target, reason: known.has(target) ? \"not_planned\" : \"completed\" });\n }\n return actions;\n}\n\n/** The comment of a step of the board, or undefined for a step with no comment. */\nexport function actionComment(action: BoardAction): string | undefined {\n if (action.kind === \"release\") {\n return `The claim of ${action.users.map((user) => `\\`${user}\\``).join(\", \")} stopped: ${String(CLAIM_HOURS)} hours passed with no open pull request. Another contributor can claim the target now.`;\n }\n if (action.kind === \"close\") {\n return action.reason === \"completed\"\n ? \"The target query does not give this target now, so the gap is closed.\"\n : \"The target query does not give this target as claimable now. The issue opens again when the target is claimable.\";\n }\n return undefined;\n}\n\n/** This function applies the steps of the board through the API, in their order. It gives the number of each new issue. */\nexport async function applyBoard(api: IssueApi, actions: readonly BoardAction[]): Promise<readonly number[]> {\n const labels = new Set(actions.flatMap((action) => (action.kind === \"create\" || action.kind === \"update\" ? action.text.labels : [])));\n if (labels.size > 0) await api.ensureLabels([...labels].sort());\n const created: number[] = [];\n for (const action of actions) {\n if (action.kind === \"create\") {\n created.push(await api.create(action.text));\n continue;\n }\n if (action.kind === \"update\") {\n const { title, body, labels: issueLabels } = action.text;\n await api.update(action.number, { title, body, labels: issueLabels, ...(action.reopen ? { state: \"open\", stateReason: \"reopened\" } : {}) });\n continue;\n }\n if (action.kind === \"release\") await api.update(action.number, { assignees: [] });\n const comment = actionComment(action);\n if (comment !== undefined) await api.comment(action.number, comment);\n if (action.kind === \"close\") await api.update(action.number, { state: \"closed\", stateReason: action.reason });\n }\n return created;\n}\n\n/** The command of a claim comment. */\nexport type ClaimCommand = \"claim\" | \"unclaim\";\n\n/** This function gives the command of a comment: its first word is `/claim` or `/unclaim`. */\nexport function claimCommandOf(comment: string): ClaimCommand | undefined {\n const first = comment.trim().split(/\\s/, 1)[0];\n return first === \"/claim\" ? \"claim\" : first === \"/unclaim\" ? \"unclaim\" : undefined;\n}\n\n/** The inputs of the decision on a claim comment. */\nexport interface ClaimInput {\n readonly command: ClaimCommand;\n /** The login of the author of the comment. */\n readonly user: string;\n readonly issue: BoardIssue;\n /** The target of the issue, or undefined when the target query does not give it. */\n readonly target: TargetRecord | undefined;\n /** Each issue of the board, with the start of each claim. */\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n}\n\n/** The decision on a claim comment: the new assignees and a comment, or a refusal with its reason. */\nexport type ClaimDecision =\n | { readonly kind: \"set\"; readonly assignees: readonly string[]; readonly comment: string }\n | { readonly kind: \"refuse\"; readonly comment: string };\n\n/**\n * This function decides a claim comment. A contributor claims one target at a time, and a claim stops after\n * `CLAIM_HOURS` with no pull request. A claim that stopped does not block a new claim, also before the board removes it.\n */\nexport function decideClaim(input: ClaimInput): ClaimDecision {\n const { command, user, issue, target, now } = input;\n const who = `\\`${user}\\``;\n if (issue.state !== \"open\") return { kind: \"refuse\", comment: \"This issue is closed, so its target has no claim.\" };\n if (target === undefined || !target.attrs.claimable) {\n return { kind: \"refuse\", comment: \"The target of this issue is not claimable now. `AGENTS.md` tells which targets are claimable.\" };\n }\n const has = issue.assignees.includes(user);\n if (command === \"unclaim\") {\n return has\n ? { kind: \"set\", assignees: issue.assignees.filter((login) => login !== user), comment: `${who} stopped the claim. Another contributor can claim the target now.` }\n : { kind: \"refuse\", comment: `${who} has no claim on this target.` };\n }\n const until = issue.claimedAt === undefined ? \"the end of the claim\" : claimEnd(issue.claimedAt);\n if (has) return { kind: \"refuse\", comment: `${who} has the claim already, until ${until}.` };\n if (issue.assignees.length > 0 && !isExpired(issue, now)) {\n const holders = issue.assignees.map((login) => `\\`${login}\\``).join(\", \");\n return { kind: \"refuse\", comment: `${holders} has the claim until ${until}. Claim another target, or claim this target after that time.` };\n }\n const other = input.issues.find((candidate) => candidate.number !== issue.number && candidate.state === \"open\" && candidate.assignees.includes(user) && !isExpired(candidate, now));\n if (other !== undefined) {\n return { kind: \"refuse\", comment: `${who} has a claim on #${String(other.number)} already. Claim one target at a time. Write \\`/unclaim\\` on #${String(other.number)} to stop that claim.` };\n }\n return {\n kind: \"set\",\n assignees: [user],\n comment: `${who} claims this target until ${claimEnd(now)}. Open the pull request before that time, with the line \\`Target: ${target.id}\\`.`,\n };\n}\n"],"mappings":";;;AAMA,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAM,OAAO;;AAGb,MAAM,WAAW;;AAqEjB,SAAgB,cAAc,MAAkC;CAC9D,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,MAAM,MAAM,KAAK,QAAQ,UAAU,QAAQ,EAAW;CACtD,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,QAAQ,IAAa,GAAG,CAAC,CAAC,KAAK;CACpE,OAAO,OAAO,MAAM,KAAK,KAAK,EAAE,IAAI,KAAA,IAAY;AAClD;;AAGA,SAAgB,SAAS,WAA2B;CAClD,OAAO,GAAG,IAAI,KAAK,YAAA,MAAmC,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE,EAAE;AACrF;;AAGA,SAAgB,UAAU,OAAmB,KAAsB;CACjE,OAAO,MAAM,UAAU,SAAS,KAAK,MAAM,cAAc,KAAA,KAAa,MAAM,MAAM,aAAA;AACpF;;AAGA,SAAgB,UAAU,QAAsB,aAAqB,q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M;EAAO,WAAW,MAAM,UAAU,QAAQ,UAAU,UAAU,IAAI;EAAG,SAAS,GAAG,IAAI;CAAmE,IAChK;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI;CAA+B;CAEvE,MAAM,QAAQ,MAAM,cAAc,KAAA,IAAY,yBAAyB,SAAS,MAAM,SAAS;CAC/F,IAAI,KAAK,OAAO;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI,gCAAgC,MAAM;CAAG;CAC3F,IAAI,MAAM,UAAU,SAAS,KAAK,CAAC,UAAU,OAAO,GAAG,GAErD,OAAO;EAAE,MAAM;EAAU,SAAS,GADlB,MAAM,UAAU,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,IACzB,EAAE,uBAAuB,MAAM;CAA+D;CAE3I,MAAM,QAAQ,MAAM,OAAO,MAAM,cAAc,UAAU,WAAW,MAAM,UAAU,UAAU,UAAU,UAAU,UAAU,UAAU,SAAS,IAAI,KAAK,CAAC,UAAU,WAAW,GAAG,CAAC;CAClL,IAAI,UAAU,KAAA,GACZ,OAAO;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI,mBAAmB,OAAO,MAAM,MAAM,EAAE,+DAA+D,OAAO,MAAM,MAAM,EAAE;CAAsB;CAE7L,OAAO;EACL,MAAM;EACN,WAAW,CAAC,IAAI;EAChB,SAAS,GAAG,IAAI,4BAA4B,SAAS,GAAG,EAAE,oEAAoE,OAAO,GAAG;CAC1I;AACF"}
1
+ {"version":3,"file":"board-7NZb3yv_.mjs","names":[],"sources":["../src/board.ts"],"sourcesContent":["// The target board: one GitHub issue for each claimable target, and the claims on the issues. The plan and the claim\n// decision are pure functions. The sync and the claim send the requests through an IssueApi.\nimport { pathOfId } from \"./ids.ts\";\nimport { ONTOLOGY_REPOSITORY, type TargetRecord } from \"./targets.ts\";\n\n/** The label of each issue of the board. */\nexport const TARGET_LABEL = \"target\";\n\n/** The time of a claim with no pull request, in hours. */\nexport const CLAIM_HOURS = 48;\n\n/** The most open issues of the board. */\nexport const BOARD_LIMIT = 20;\n\n/** The start of the hidden line of an issue body that has the id of its target. */\nconst MARK = \"<!-- canon-target: \";\n\n/** The end of the hidden line. */\nconst MARK_END = \" -->\";\n\n/** An issue of the board, as the API of the issues gives it. */\nexport interface BoardIssue {\n readonly number: number;\n readonly title: string;\n readonly body: string;\n readonly state: \"open\" | \"closed\";\n readonly labels: readonly string[];\n readonly assignees: readonly string[];\n /** This time is the start of the claim of an open issue with an assignee, in milliseconds since 1970. */\n readonly claimedAt?: number | undefined;\n}\n\n/** The title, the body and the labels of the issue of a target. */\nexport interface IssueText {\n readonly title: string;\n readonly body: string;\n readonly labels: readonly string[];\n}\n\n/** A change of an issue. Each field that is not here does not change. */\nexport interface IssueChange {\n readonly title?: string;\n readonly body?: string;\n readonly labels?: readonly string[];\n readonly state?: \"open\" | \"closed\";\n readonly stateReason?: \"completed\" | \"not_planned\" | \"reopened\";\n /** This list replaces the assignees of the issue. */\n readonly assignees?: readonly string[];\n}\n\n/** The API of the issues of one repository. A test gives a fake, and `githubIssueApi` gives the API of GitHub. */\nexport interface IssueApi {\n /** This method gives each issue with the label `target`, open and closed, with the start of each claim. */\n issues(): Promise<readonly BoardIssue[]>;\n /** This method tells if an open pull request names the target id. */\n hasOpenPull(targetId: string): Promise<boolean>;\n /** This method makes each label that does not exist. */\n ensureLabels(names: readonly string[]): Promise<void>;\n /** This method opens an issue, and gives its number. */\n create(text: IssueText): Promise<number>;\n /** This method changes an issue, and gives the issue after the change. */\n update(number: number, change: IssueChange): Promise<BoardIssue>;\n /** This method writes a comment on an issue. */\n comment(number: number, text: string): Promise<void>;\n}\n\n/** One step of the sync of the board. */\nexport type BoardAction =\n | { readonly kind: \"create\"; readonly target: string; readonly text: IssueText }\n | { readonly kind: \"update\"; readonly number: number; readonly target: string; readonly text: IssueText; readonly reopen: boolean }\n | { readonly kind: \"close\"; readonly number: number; readonly target: string; readonly reason: \"completed\" | \"not_planned\" }\n | { readonly kind: \"release\"; readonly number: number; readonly target: string; readonly users: readonly string[] };\n\n/** The inputs of the plan of the board. */\nexport interface BoardInput {\n /** Each target of the target query, in the order of `compareTargets`. */\n readonly targets: readonly TargetRecord[];\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n /** The ids of the targets that an open pull request names. */\n readonly pulls: ReadonlySet<string>;\n /** The most open issues. The default is `BOARD_LIMIT`. */\n readonly limit?: number | undefined;\n}\n\n/** This function gives the id of the target of an issue body, or undefined when the body has no hidden line. */\nexport function targetOfIssue(body: string): string | undefined {\n const start = body.indexOf(MARK);\n if (start < 0) return undefined;\n const end = body.indexOf(MARK_END, start + MARK.length);\n const id = end < 0 ? \"\" : body.slice(start + MARK.length, end).trim();\n return id === \"\" || /\\s/.test(id) ? undefined : id;\n}\n\n/** This function gives the time of the end of a claim, as an ISO 8601 text to the minute. */\nexport function claimEnd(claimedAt: number): string {\n return `${new Date(claimedAt + CLAIM_HOURS * 3_600_000).toISOString().slice(0, 16)}Z`;\n}\n\n/** This function tells if a claim is older than `CLAIM_HOURS`. A claim with no known start is live. */\nexport function isExpired(issue: BoardIssue, now: number): boolean {\n return issue.assignees.length > 0 && issue.claimedAt !== undefined && now - issue.claimedAt >= CLAIM_HOURS * 3_600_000;\n}\n\n/** This function gives the title, the body and the labels of the issue of a target. */\nexport function issueText(target: TargetRecord, repository: string = ONTOLOGY_REPOSITORY): IssueText {\n const { attrs } = target;\n const path = pathOfId(target.id);\n const body = [\n `${MARK}${target.id}${MARK_END}`,\n `**Target:** \\`${target.id}\\``,\n \"\",\n \"| Gap | Home | Size | Area |\",\n \"| --- | --- | --- | --- |\",\n `| \\`${attrs.gap}\\` | [${attrs.home}](https://github.com/${attrs.home}) | ${attrs.size} | ${attrs.area === undefined ? \"\" : `\\`${attrs.area}\\``} |`,\n \"\",\n \"## Acceptance\",\n \"\",\n attrs.acceptance.text,\n \"\",\n ...attrs.acceptance.checks.map((check) => `- [ ] ${check}`),\n \"\",\n \"## Why\",\n \"\",\n attrs.why,\n \"\",\n \"## Claim and close\",\n \"\",\n `1. Write the comment \\`/claim\\` on this issue. A claim stops after ${String(CLAIM_HOURS)} hours with no open pull request.`,\n `2. Do the work. [\\`AGENTS.md\\`](https://github.com/${repository}/blob/main/AGENTS.md) tells how.`,\n `3. In the pull request, write the line \\`Target: ${target.id}\\`.`,\n \"\",\n `The record of the target is [\\`${path}\\`](https://github.com/${repository}/blob/main/${path}). Write \\`/unclaim\\` to stop your claim.`,\n \"\",\n ].join(\"\\n\");\n return { title: attrs.title, body, labels: [TARGET_LABEL, `gap:${attrs.gap}`] };\n}\n\n/** This function tells if an issue has the text of a target: the same title, body and labels. */\nfunction sameText(issue: BoardIssue, text: IssueText): boolean {\n const labels = [...issue.labels].sort();\n const wanted = [...text.labels].sort();\n return issue.title === text.title && issue.body === text.body && labels.length === wanted.length && labels.every((label, index) => label === wanted[index]);\n}\n\n/**\n * This function gives the steps that make the board agree with the target query.\n *\n * - The board keeps the open issue of each claimable target. It adds other claimable targets, up to the limit. An issue\n * does not close because new targets come before it.\n * - Each added target is the first claimable target of the gap with the fewest targets on the board. So one gap with\n * many targets does not fill the board.\n * - An issue whose target is not claimable closes: `completed` when the target is gone, else `not_planned`.\n * - A claim older than `CLAIM_HOURS` stops when no open pull request names its target.\n * - An issue with no hidden line is not an issue of the board. Of two issues of one target, the board uses the first.\n */\nexport function planBoard(input: BoardInput): readonly BoardAction[] {\n const limit = input.limit ?? BOARD_LIMIT;\n const known = new Set(input.targets.map((target) => target.id));\n const claimable = input.targets.filter((target) => target.attrs.claimable);\n const byTarget = new Map<string, BoardIssue>();\n for (const issue of [...input.issues].sort((a, b) => a.number - b.number)) {\n const id = targetOfIssue(issue.body);\n if (id !== undefined && !byTarget.has(id)) byTarget.set(id, issue);\n }\n const board = new Set(claimable.filter((target) => byTarget.get(target.id)?.state === \"open\").map((target) => target.id));\n const gaps = new Map<string, number>();\n for (const target of claimable) if (board.has(target.id)) gaps.set(target.attrs.gap, (gaps.get(target.attrs.gap) ?? 0) + 1);\n const waiting = claimable.filter((target) => !board.has(target.id));\n while (board.size < limit && waiting.length > 0) {\n let best = 0;\n for (let index = 1; index < waiting.length; index += 1) {\n if ((gaps.get(waiting[index]?.attrs.gap ?? \"\") ?? 0) < (gaps.get(waiting[best]?.attrs.gap ?? \"\") ?? 0)) best = index;\n }\n const [next] = waiting.splice(best, 1);\n if (next === undefined) break;\n board.add(next.id);\n gaps.set(next.attrs.gap, (gaps.get(next.attrs.gap) ?? 0) + 1);\n }\n const actions: BoardAction[] = [];\n for (const target of claimable.filter((candidate) => board.has(candidate.id))) {\n const text = issueText(target);\n const issue = byTarget.get(target.id);\n if (issue === undefined) {\n actions.push({ kind: \"create\", target: target.id, text });\n continue;\n }\n if (issue.state === \"closed\" || !sameText(issue, text)) actions.push({ kind: \"update\", number: issue.number, target: target.id, text, reopen: issue.state === \"closed\" });\n if (issue.state === \"open\" && isExpired(issue, input.now) && !input.pulls.has(target.id)) {\n actions.push({ kind: \"release\", number: issue.number, target: target.id, users: issue.assignees });\n }\n }\n for (const [target, issue] of byTarget) {\n if (issue.state === \"open\" && !board.has(target)) actions.push({ kind: \"close\", number: issue.number, target, reason: known.has(target) ? \"not_planned\" : \"completed\" });\n }\n return actions;\n}\n\n/** The comment of a step of the board, or undefined for a step with no comment. */\nexport function actionComment(action: BoardAction): string | undefined {\n if (action.kind === \"release\") {\n return `The claim of ${action.users.map((user) => `\\`${user}\\``).join(\", \")} stopped: ${String(CLAIM_HOURS)} hours passed with no open pull request. Another contributor can claim the target now.`;\n }\n if (action.kind === \"close\") {\n return action.reason === \"completed\"\n ? \"The target query does not give this target now, so the gap is closed.\"\n : \"The target query does not give this target as claimable now. The issue opens again when the target is claimable.\";\n }\n return undefined;\n}\n\n/** This function applies the steps of the board through the API, in their order. It gives the number of each new issue. */\nexport async function applyBoard(api: IssueApi, actions: readonly BoardAction[]): Promise<readonly number[]> {\n const labels = new Set(actions.flatMap((action) => (action.kind === \"create\" || action.kind === \"update\" ? action.text.labels : [])));\n if (labels.size > 0) await api.ensureLabels([...labels].sort());\n const created: number[] = [];\n for (const action of actions) {\n if (action.kind === \"create\") {\n created.push(await api.create(action.text));\n continue;\n }\n if (action.kind === \"update\") {\n const { title, body, labels: issueLabels } = action.text;\n await api.update(action.number, { title, body, labels: issueLabels, ...(action.reopen ? { state: \"open\", stateReason: \"reopened\" } : {}) });\n continue;\n }\n if (action.kind === \"release\") await api.update(action.number, { assignees: [] });\n const comment = actionComment(action);\n if (comment !== undefined) await api.comment(action.number, comment);\n if (action.kind === \"close\") await api.update(action.number, { state: \"closed\", stateReason: action.reason });\n }\n return created;\n}\n\n/** The command of a claim comment. */\nexport type ClaimCommand = \"claim\" | \"unclaim\";\n\n/** This function gives the command of a comment: its first word is `/claim` or `/unclaim`. */\nexport function claimCommandOf(comment: string): ClaimCommand | undefined {\n const first = comment.trim().split(/\\s/, 1)[0];\n return first === \"/claim\" ? \"claim\" : first === \"/unclaim\" ? \"unclaim\" : undefined;\n}\n\n/** The inputs of the decision on a claim comment. */\nexport interface ClaimInput {\n readonly command: ClaimCommand;\n /** The login of the author of the comment. */\n readonly user: string;\n readonly issue: BoardIssue;\n /** The target of the issue, or undefined when the target query does not give it. */\n readonly target: TargetRecord | undefined;\n /** Each issue of the board, with the start of each claim. */\n readonly issues: readonly BoardIssue[];\n /** This time is the time of the decision, in milliseconds since 1970. */\n readonly now: number;\n}\n\n/** The decision on a claim comment: the new assignees and a comment, or a refusal with its reason. */\nexport type ClaimDecision =\n | { readonly kind: \"set\"; readonly assignees: readonly string[]; readonly comment: string }\n | { readonly kind: \"refuse\"; readonly comment: string };\n\n/**\n * This function decides a claim comment. A contributor claims one target at a time, and a claim stops after\n * `CLAIM_HOURS` with no pull request. A claim that stopped does not block a new claim, also before the board removes it.\n */\nexport function decideClaim(input: ClaimInput): ClaimDecision {\n const { command, user, issue, target, now } = input;\n const who = `\\`${user}\\``;\n if (issue.state !== \"open\") return { kind: \"refuse\", comment: \"This issue is closed, so its target has no claim.\" };\n if (target === undefined || !target.attrs.claimable) {\n return { kind: \"refuse\", comment: \"The target of this issue is not claimable now. `AGENTS.md` tells which targets are claimable.\" };\n }\n const has = issue.assignees.includes(user);\n if (command === \"unclaim\") {\n return has\n ? { kind: \"set\", assignees: issue.assignees.filter((login) => login !== user), comment: `${who} stopped the claim. Another contributor can claim the target now.` }\n : { kind: \"refuse\", comment: `${who} has no claim on this target.` };\n }\n const until = issue.claimedAt === undefined ? \"the end of the claim\" : claimEnd(issue.claimedAt);\n if (has) return { kind: \"refuse\", comment: `${who} has the claim already, until ${until}.` };\n if (issue.assignees.length > 0 && !isExpired(issue, now)) {\n const holders = issue.assignees.map((login) => `\\`${login}\\``).join(\", \");\n return { kind: \"refuse\", comment: `${holders} has the claim until ${until}. Claim another target, or claim this target after that time.` };\n }\n const other = input.issues.find((candidate) => candidate.number !== issue.number && candidate.state === \"open\" && candidate.assignees.includes(user) && !isExpired(candidate, now));\n if (other !== undefined) {\n return { kind: \"refuse\", comment: `${who} has a claim on #${String(other.number)} already. Claim one target at a time. Write \\`/unclaim\\` on #${String(other.number)} to stop that claim.` };\n }\n return {\n kind: \"set\",\n assignees: [user],\n comment: `${who} claims this target until ${claimEnd(now)}. Open the pull request before that time, with the line \\`Target: ${target.id}\\`.`,\n };\n}\n"],"mappings":";;;AAMA,MAAa,eAAe;;AAG5B,MAAa,cAAc;;AAG3B,MAAa,cAAc;;AAG3B,MAAM,OAAO;;AAGb,MAAM,WAAW;;AAqEjB,SAAgB,cAAc,MAAkC;CAC9D,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,MAAM,MAAM,KAAK,QAAQ,UAAU,QAAQ,EAAW;CACtD,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,QAAQ,IAAa,GAAG,CAAC,CAAC,KAAK;CACpE,OAAO,OAAO,MAAM,KAAK,KAAK,EAAE,IAAI,KA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269,8 +269,9 @@ type ClaimDecision = {
269
269
  */
270
270
  export declare function decideClaim(input: ClaimInput): ClaimDecision;
271
271
  /**
272
- * This function tells if the `valid_from` of an envelope is not after its `valid_to`. The comparison uses the instants,
273
- * so two times with different offsets compare correctly. The record schema refuses a time that is not valid.
272
+ * This function tells if the `valid_from` of an envelope is not after its `valid_to`. The comparison uses the instants
273
+ * in nanoseconds, so two times with different offsets or in one millisecond compare correctly. The record schema refuses
274
+ * a time that is not valid.
274
275
  */
275
276
  export declare function timesInOrder(envelope: Envelope): boolean;
276
277
  /**
@@ -644,8 +645,10 @@ export declare function checkMatches(pattern: string, name: string): boolean;
644
645
  * - mutation: a lane file (`mutation.json`, or the input `lane` of the caller) and a job that calls `reusable-mutation.yml`.
645
646
  * - property: a package file that names `fast-check` or `@mark1russell7/rigor-testkit`. Its checks are the checks of
646
647
  * each job that calls `reusable-ci.yml` or starts the tests, and of each job that needs such a job.
647
- * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A bench job uses the
648
- * action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command with the word `bench`.
648
+ * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A summary job with
649
+ * `gate: speed` (the marker of `gate-summary`) gives the bench jobs. With no marker in the repository, the read uses
650
+ * a word rule. Then a bench job uses the action `stamp-gate`, a bin of the bench or a command with the word `bench`.
651
+ * The bins are `rigor-gate-line` and `rigor-stamp`.
649
652
  * - rigs: the file `docs/rigs.json` and a job that calls `reusable-rigs.yml`.
650
653
  *
651
654
  * A file with no answer, or a file that the read cannot parse, gives a no read for each gate that needs it.
@@ -657,7 +660,7 @@ export declare function gatesOf(tree: Tree, answers: ReadonlyMap<string, HomeAns
657
660
  * This function reads the test gates of each repository. The default fetch is `politeFetch` with no token, so each
658
661
  * request goes at the pace of its host. The read makes two rounds of requests:
659
662
  *
660
- * 1. the tree and the rules of the branch of each repository, from the API of GitHub,
663
+ * 1. the tree, the rules and the classic protection of the branch of each repository, from the API of GitHub,
661
664
  * 2. each workflow file and each package file of each tree, from the host of raw files. Two files with the same content
662
665
  * id give one request.
663
666
  *
package/build/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { arrayOf, booleanOf, isRecord, numberOf, readArray, readText, recordOf, textOf, timeOf } from "@mark1russell7/optional/read";
2
- import { A as GRAMMAR_FILE, C as scopeText, D as kindOf, E as isLive, F as makeId, I as npmPackageId, L as npmPurl, M as RECORD_SCHEMA_FILE, N as idPart, O as lineageOf, P as kindOfId, R as pathOfId, S as sameScope, T as isKindIn, _ as scopeOf, a as SIZES, b as inScope, c as targetsOf, d as leanKey, f as problemIdOf, g as resultClaimsOf, h as hasFullScope, i as PLACES_SHOWN, j as ONTOLOGY_FOLDER, k as relationOf, l as findProblem, m as claimFails, n as NECESSARY_GATES, o as compareTargets, p as CLAIM_STATUSES, r as ONTOLOGY_REPOSITORY, s as targetId, u as formalKeyOf, v as SCOPE_MODULUS_LIMIT, w as edgesOf, x as readScope, y as canonicalScope, z as repositoryId } from "./targets-BwC2nZGy.mjs";
3
- import { a as applyBoard, c as decideClaim, d as planBoard, f as targetOfIssue, i as actionComment, l as isExpired, n as CLAIM_HOURS, o as claimCommandOf, r as TARGET_LABEL, s as claimEnd, t as BOARD_LIMIT, u as issueText } from "./board-DAKpkjvV.mjs";
2
+ import { A as GRAMMAR_FILE, C as scopeText, D as kindOf, E as isLive, F as makeId, I as npmPackageId, L as npmPurl, M as RECORD_SCHEMA_FILE, N as idPart, O as lineageOf, P as kindOfId, R as pathOfId, S as sameScope, T as isKindIn, _ as scopeOf, a as SIZES, b as inScope, c as targetsOf, d as leanKey, f as problemIdOf, g as resultClaimsOf, h as hasFullScope, i as PLACES_SHOWN, j as ONTOLOGY_FOLDER, k as relationOf, l as findProblem, m as claimFails, n as NECESSARY_GATES, o as compareTargets, p as CLAIM_STATUSES, r as ONTOLOGY_REPOSITORY, s as targetId, u as formalKeyOf, v as SCOPE_MODULUS_LIMIT, w as edgesOf, x as readScope, y as canonicalScope, z as repositoryId } from "./targets-DFXTvFDm.mjs";
3
+ import { a as applyBoard, c as decideClaim, d as planBoard, f as targetOfIssue, i as actionComment, l as isExpired, n as CLAIM_HOURS, o as claimCommandOf, r as TARGET_LABEL, s as claimEnd, t as BOARD_LIMIT, u as issueText } from "./board-7NZb3yv_.mjs";
4
+ import { instantNanos, utcText } from "@mark1russell7/algebra/clock";
4
5
  import { Ajv2020 } from "ajv/dist/2020.js";
5
6
  import formats from "ajv-formats";
6
7
  import { countOf, listOf } from "@mark1russell7/text/english";
@@ -18,7 +19,6 @@ import { createRequire } from "node:module";
18
19
  import { redactSecrets } from "@mark1russell7/text/redact";
19
20
  import { fetchTransport, send } from "polite-crawler/api";
20
21
  import { HostScheduler, realClock } from "polite-crawler/politeness";
21
- import { utcText } from "@mark1russell7/algebra/clock";
22
22
  import { parse } from "yaml";
23
23
  // src/atlas.ts
24
24
  /** The URL of the data of the duplication atlas. */
@@ -327,13 +327,14 @@ function checkEnvelope(envelope, what, path, kinds, grammar, problems) {
327
327
  });
328
328
  }
329
329
  /**
330
- * This function tells if the `valid_from` of an envelope is not after its `valid_to`. The comparison uses the instants,
331
- * so two times with different offsets compare correctly. The record schema refuses a time that is not valid.
330
+ * This function tells if the `valid_from` of an envelope is not after its `valid_to`. The comparison uses the instants
331
+ * in nanoseconds, so two times with different offsets or in one millisecond compare correctly. The record schema refuses
332
+ * a time that is not valid.
332
333
  */
333
334
  function timesInOrder(envelope) {
334
- const from = Date.parse(envelope.valid_from ?? "");
335
- const to = Date.parse(envelope.valid_to ?? "");
336
- return Number.isNaN(from) || Number.isNaN(to) || from <= to;
335
+ const from = instantNanos(envelope.valid_from ?? "");
336
+ const to = instantNanos(envelope.valid_to ?? "");
337
+ return from === void 0 || to === void 0 || from <= to;
337
338
  }
338
339
  /** This function gives the key of a relation: the values of the parts of the key of its kind. The default key is the two ends. */
339
340
  /**
@@ -632,6 +633,11 @@ function cloneReport(groups, records, floor = 200) {
632
633
  return lines.join("\n");
633
634
  }
634
635
  // src/engine.ts
636
+ /**
637
+ * The audience of canon: each record is public (`schema/record.schema.json`). It is the default scope of each kind, and
638
+ * the engine refuses a record or an edge with a more private scope.
639
+ */
640
+ const CANON_AUDIENCE = "public";
635
641
  /** The folder of the files that the engine generates from the grammar, relative to the root of the repository. */
636
642
  const ENGINE_FOLDER = "schema/engine";
637
643
  /** The options of the generation: the first line of each SQL file names the command that makes the files. */
@@ -770,7 +776,7 @@ function kindOf$1(kind, grammar, problems) {
770
776
  description: kind.description,
771
777
  attributes: shapeOf(kind.attributes, grammar, path, problems),
772
778
  ...kind.facets.length > 0 ? { facets: kind.facets } : {},
773
- defaultScope: "public",
779
+ defaultScope: CANON_AUDIENCE,
774
780
  ...requirements.length > 0 ? { requirements } : {}
775
781
  };
776
782
  }
@@ -792,21 +798,15 @@ function relationOf$1(relation, grammar, problems) {
792
798
  }
793
799
  /**
794
800
  * This function gives a relation kind of canon with the name of a relation kind of the engine as an extension. The
795
- * extension adds each kind that the end of the engine does not have yet. The engine end can permit more kinds than canon.
801
+ * extension adds one pair of ends: each `from` kind of canon with each `to` kind of canon. The pair of the spine relates
802
+ * no kind of canon, so the engine permits the same edges as canon.
796
803
  */
797
- function extensionOf(relation, spine, grammar, problems) {
804
+ function extensionOf(relation, problems) {
798
805
  if (relation.qualifiers !== void 0 || relation.key !== void 0 || relation.parent !== void 0) problems.push(`${GRAMMAR_FILE}#/relations/${relation.name}: a relation of the engine gets only more kinds at its ends.`);
799
- const lineage = (name) => {
800
- const kind = grammar.kinds.find((candidate) => candidate.name === name);
801
- return kind === void 0 || kind.parent === null ? [name, "entity"] : [name, ...lineage(kind.parent)];
802
- };
803
- const missing = (kinds, allowed) => kinds.filter((kind) => !lineage(kind).some((ancestor) => allowed.includes(ancestor)));
804
- const from = missing(relation.from, spine.from);
805
- const to = missing(relation.to, spine.to);
806
806
  return {
807
807
  relation: relation.name,
808
- ...from.length > 0 ? { from } : {},
809
- ...to.length > 0 ? { to } : {}
808
+ from: [...relation.from],
809
+ to: [...relation.to]
810
810
  };
811
811
  }
812
812
  /**
@@ -825,17 +825,15 @@ function engineAddOn(grammar) {
825
825
  const kinds = grammar.kinds.map((kind) => kindOf$1(kind, grammar, problems));
826
826
  const relations = [];
827
827
  const extensions = [];
828
- for (const relation of grammar.relations) {
829
- const spine = spineRelations.find((candidate) => candidate.name === relation.name);
830
- if (spine === void 0) relations.push(relationOf$1(relation, grammar, problems));
831
- else extensions.push(extensionOf(relation, spine, grammar, problems));
832
- }
828
+ for (const relation of grammar.relations) if (spineRelations.find((candidate) => candidate.name === relation.name) === void 0) relations.push(relationOf$1(relation, grammar, problems));
829
+ else extensions.push(extensionOf(relation, problems));
833
830
  if (problems.length > 0) throw new EngineGrammarError(problems);
834
831
  return withoutInherited({
835
832
  kinds,
836
833
  relations,
837
834
  ...facets.length > 0 ? { facets } : {},
838
- ...extensions.length > 0 ? { extensions } : {}
835
+ ...extensions.length > 0 ? { extensions } : {},
836
+ audience: CANON_AUDIENCE
839
837
  });
840
838
  }
841
839
  /** The schema of an attribute that a kind of canon does not have: it refuses each value. */
@@ -1336,6 +1334,13 @@ function treeUrl(repository) {
1336
1334
  function rulesUrl(repository) {
1337
1335
  return `https://api.github.com/repos/${repository.owner}/${repository.name}/rules/branches/${branchPath(repository.branch)}?per_page=${String(100)}`;
1338
1336
  }
1337
+ /**
1338
+ * This function gives the URL of the branch of a repository. Its answer has the classic protection of the branch, with
1339
+ * its necessary checks. GitHub gives it with no token.
1340
+ */
1341
+ function branchUrl(repository) {
1342
+ return `https://api.github.com/repos/${repository.owner}/${repository.name}/branches/${branchPath(repository.branch)}`;
1343
+ }
1339
1344
  /** This function gives the URL of the text of one file of the branch. The host of raw files is not the API. */
1340
1345
  function fileUrl(repository, path) {
1341
1346
  return `https://raw.githubusercontent.com/${repository.owner}/${repository.name}/${branchPath(repository.branch)}/${path.split("/").map(encodeURIComponent).join("/")}`;
@@ -1388,6 +1393,31 @@ function necessaryChecksOf(answer) {
1388
1393
  }
1389
1394
  return { checks: [...checks].sort() };
1390
1395
  }
1396
+ /**
1397
+ * This function reads the names of the necessary checks of the classic protection from the answer for a branch. A
1398
+ * branch with no classic protection, or with checks that are not enforced, gives no check.
1399
+ */
1400
+ function classicChecksOf(answer) {
1401
+ const read = textOrReason(answer, "the branch");
1402
+ if ("no_read" in read) return read;
1403
+ const branch = jsonOf(read.text);
1404
+ if (!isRecord(branch)) return { no_read: "The answer for the branch is not a JSON object." };
1405
+ const protection = recordOf(branch, "protection");
1406
+ const required = recordOf(protection, "required_status_checks");
1407
+ if (booleanOf(protection, "enabled") !== true || required === void 0 || textOf(required, "enforcement_level") === "off") return { checks: [] };
1408
+ const contexts = arrayOf(required, "contexts", readText) ?? [];
1409
+ const checks = arrayOf(required, "checks", (item) => textOf(item, "context")) ?? [];
1410
+ return { checks: [.../* @__PURE__ */ new Set([...contexts, ...checks])].sort() };
1411
+ }
1412
+ /**
1413
+ * This function gives the necessary checks of a branch: the checks of its rulesets and of its classic protection. A
1414
+ * no read of one of the two is a no read, because the missing part can make a check necessary.
1415
+ */
1416
+ function branchChecksOf(rules, classic) {
1417
+ if ("no_read" in rules) return rules;
1418
+ if ("no_read" in classic) return classic;
1419
+ return { checks: [.../* @__PURE__ */ new Set([...rules.checks, ...classic.checks])].sort() };
1420
+ }
1391
1421
  /** This function tells if a path is a workflow of GitHub Actions. GitHub reads only the files at the top of the folder. */
1392
1422
  function isWorkflowPath(path) {
1393
1423
  return /^\.github\/workflows\/[^/]+\.ya?ml$/.test(path);
@@ -1423,7 +1453,8 @@ function workflowOf(path, text) {
1423
1453
  needs: typeof needs === "string" ? [needs] : arrayOf(job, "needs", readText) ?? [],
1424
1454
  steps: arrayOf(job, "steps", (step) => isRecord(step) ? {
1425
1455
  uses: textOf(step, "uses"),
1426
- run: textOf(step, "run")
1456
+ run: textOf(step, "run"),
1457
+ with: recordOf(step, "with")
1427
1458
  } : void 0) ?? []
1428
1459
  };
1429
1460
  })
@@ -1434,6 +1465,25 @@ function callsTemplate(job, file) {
1434
1465
  const uses = job.uses ?? "";
1435
1466
  return (uses.startsWith("mark1russell7/template/") || uses.startsWith("./")) && new RegExp(`(^|/)\\.github/workflows/${file.replaceAll(".", "\\.")}(@|$)`).test(uses);
1436
1467
  }
1468
+ /** The paths of the action `gate-summary`: in the template, and in the copy of the template itself. */
1469
+ const GATE_SUMMARY = ["mark1russell7/template/.github/actions/gate-summary", "./.github/actions/gate-summary"];
1470
+ /** This function tells if a step uses the action `gate-summary` of the template, at a commit or with no ref. */
1471
+ function usesGateSummary(step) {
1472
+ const uses = step.uses ?? "";
1473
+ const at = uses.indexOf("@");
1474
+ return GATE_SUMMARY.includes(at === -1 ? uses : uses.slice(0, at));
1475
+ }
1476
+ /**
1477
+ * This function gives the kind of gate that the job marks: the input `gate` of its step `gate-summary` of the
1478
+ * template. A job with no marker, or with a word that is not a gate, gives undefined.
1479
+ */
1480
+ function markedGate(job) {
1481
+ for (const step of job.steps) {
1482
+ const gate = usesGateSummary(step) ? step.with?.["gate"] : void 0;
1483
+ const kind = GATE_NAMES.find((name) => name === gate);
1484
+ if (kind !== void 0) return kind;
1485
+ }
1486
+ }
1437
1487
  /** A command that starts the tests of a package. */
1438
1488
  const TEST_COMMAND = /\b(vitest|(pnpm|npm|yarn)(\s+-r|\s+--recursive)?\s+(run\s+)?test)\b/;
1439
1489
  /** A command or a step that starts a bench of `@mark1russell7/rigor-bench`. */
@@ -1598,8 +1648,10 @@ function factOf(parts, checks, rules) {
1598
1648
  * - mutation: a lane file (`mutation.json`, or the input `lane` of the caller) and a job that calls `reusable-mutation.yml`.
1599
1649
  * - property: a package file that names `fast-check` or `@mark1russell7/rigor-testkit`. Its checks are the checks of
1600
1650
  * each job that calls `reusable-ci.yml` or starts the tests, and of each job that needs such a job.
1601
- * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A bench job uses the
1602
- * action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command with the word `bench`.
1651
+ * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A summary job with
1652
+ * `gate: speed` (the marker of `gate-summary`) gives the bench jobs. With no marker in the repository, the read uses
1653
+ * a word rule. Then a bench job uses the action `stamp-gate`, a bin of the bench or a command with the word `bench`.
1654
+ * The bins are `rigor-gate-line` and `rigor-stamp`.
1603
1655
  * - rigs: the file `docs/rigs.json` and a job that calls `reusable-rigs.yml`.
1604
1656
  *
1605
1657
  * A file with no answer, or a file that the read cannot parse, gives a no read for each gate that needs it.
@@ -1641,12 +1693,13 @@ function gatesOf(tree, answers, rules) {
1641
1693
  files: propertyFiles,
1642
1694
  no_read: workflowFault
1643
1695
  } : factOf([propertyPart], testJobs.checks, rules);
1644
- const benchJobs = pickJobs(workflows, (job) => job.steps.some((step) => (step.uses ?? "").includes("/.github/actions/stamp-gate") || BENCH_COMMAND.test(step.run ?? "")));
1696
+ const marked = workflows.some((workflow) => workflow.jobs.some((job) => markedGate(job) === "speed"));
1697
+ const benchJobs = pickJobs(workflows, (job) => marked ? markedGate(job) === "speed" : job.steps.some((step) => (step.uses ?? "").includes("/.github/actions/stamp-gate") || BENCH_COMMAND.test(step.run ?? "")));
1645
1698
  const speed = (packageFault ?? workflowFault) !== void 0 ? { no_read: packageFault ?? workflowFault ?? "" } : factOf([{
1646
1699
  missing: `a package file that names \`${BENCH_PACKAGE}\` in its dependencies`,
1647
1700
  files: naming([BENCH_PACKAGE])
1648
1701
  }, {
1649
- missing: "a job that starts a bench: the action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command `bench`",
1702
+ missing: "a job that starts a bench: a summary job with `gate: speed`, the action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command `bench`",
1650
1703
  files: benchJobs.files
1651
1704
  }], benchJobs.checks, rules);
1652
1705
  const rigsJobs = pickJobs(workflows, (job) => callsTemplate(job, "reusable-rigs.yml"));
@@ -1682,18 +1735,22 @@ function noReadOfEach(reason) {
1682
1735
  * This function reads the test gates of each repository. The default fetch is `politeFetch` with no token, so each
1683
1736
  * request goes at the pace of its host. The read makes two rounds of requests:
1684
1737
  *
1685
- * 1. the tree and the rules of the branch of each repository, from the API of GitHub,
1738
+ * 1. the tree, the rules and the classic protection of the branch of each repository, from the API of GitHub,
1686
1739
  * 2. each workflow file and each package file of each tree, from the host of raw files. Two files with the same content
1687
1740
  * id give one request.
1688
1741
  *
1689
1742
  * A repository whose tree has no read gives a no read for each gate. The read does not throw for one repository.
1690
1743
  */
1691
1744
  async function readTestGates(repositories, fetch = politeFetch(), now = Date.now) {
1692
- const first = await fetch(repositories.flatMap((repository) => [treeUrl(repository), rulesUrl(repository)]));
1745
+ const first = await fetch(repositories.flatMap((repository) => [
1746
+ treeUrl(repository),
1747
+ rulesUrl(repository),
1748
+ branchUrl(repository)
1749
+ ]));
1693
1750
  const trees = repositories.map((repository) => ({
1694
1751
  repository,
1695
1752
  tree: treeOf(first.get(treeUrl(repository))),
1696
- rules: necessaryChecksOf(first.get(rulesUrl(repository)))
1753
+ rules: branchChecksOf(necessaryChecksOf(first.get(rulesUrl(repository))), classicChecksOf(first.get(branchUrl(repository))))
1697
1754
  }));
1698
1755
  const urlOfContent = /* @__PURE__ */ new Map();
1699
1756
  for (const { repository, tree } of trees) {