-
Notifications
You must be signed in to change notification settings - Fork 43
ci(docs): enforce governed knowledge records #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
testikun
wants to merge
3
commits into
openpi-dev:main
Choose a base branch
from
testikun:codex/issue-198-knowledge-contract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| status: draft | ||
| created: YYYY-MM-DD | ||
| last-verified: YYYY-MM-DD | ||
| applies-to: OpenPI revision or release | ||
| related-issues: "#NNN" | ||
| related-prs: none | ||
| supersedes: none | ||
| source-revision: commit SHA | ||
| model: provider/model and immutable version when available | ||
| thinking-level: exact setting | ||
| task-set: stable task identity | ||
| verifier: stable verifier identity | ||
| sample-size: exact count | ||
| isolation: workspace and scheduling boundary | ||
| usage-accounting: receipt or measurement method | ||
| failure-classification: explicit taxonomy and counts | ||
| limitations: known gaps | ||
| evidence-reference: retrievable archive identity and receipt | ||
| rerun-entry-point: command or runbook | ||
| --- | ||
|
|
||
| # Benchmark title | ||
|
|
||
| Record protocol, results, interpretation, and limitations without embedding private or unbounded raw evidence. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| status: draft | ||
| created: YYYY-MM-DD | ||
| last-verified: YYYY-MM-DD | ||
| applies-to: revision, release, or source boundary | ||
| related-issues: "#NNN" | ||
| related-prs: none | ||
| supersedes: none | ||
| --- | ||
|
|
||
| # Research title | ||
|
|
||
| ## Verified facts | ||
|
|
||
| State sourced observations and their verification boundary. | ||
|
|
||
| ## Inferences | ||
|
|
||
| Separate interpretations from observations. | ||
|
|
||
| ## Recommendations | ||
|
|
||
| Record proposed action without presenting it as an adopted Decision. | ||
|
|
||
| ## Unknowns | ||
|
|
||
| List unresolved questions and evidence that would answer them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs"; | ||
| import { dirname, relative, resolve, sep } from "node:path"; | ||
| import { fileURLToPath, pathToFileURL } from "node:url"; | ||
|
|
||
| const REPOSITORY_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const RECORD_METADATA = [ | ||
| "status", | ||
| "created", | ||
| "last-verified", | ||
| "applies-to", | ||
| "related-issues", | ||
| "related-prs", | ||
| "supersedes", | ||
| ]; | ||
| const BENCHMARK_METADATA = [ | ||
| "source-revision", | ||
| "model", | ||
| "thinking-level", | ||
| "task-set", | ||
| "verifier", | ||
| "sample-size", | ||
| "isolation", | ||
| "usage-accounting", | ||
| "failure-classification", | ||
| "limitations", | ||
| "evidence-reference", | ||
| "rerun-entry-point", | ||
| ]; | ||
| const RESEARCH_SECTIONS = [ | ||
| "verified facts", | ||
| "inferences", | ||
| "recommendations", | ||
| "unknowns", | ||
| ]; | ||
| const RECORD_STATUSES = new Set(["draft", "validated", "superseded"]); | ||
| const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/; | ||
| const LEGACY_RECORDS = new Set([ | ||
| "docs/research/CLAUDE_CODE_WORKFLOW_FANOUT_POLICY_2026-08-23.md", | ||
| "docs/research/CLAUDE_CODE_WORKFLOW_RUNTIME_CONTRACT_2026-08-23.md", | ||
| ]); | ||
| const MARKDOWN_LINK_PATTERN = | ||
| /!?\[[^\]]*\]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)/g; | ||
|
|
||
| function markdownFiles(directory) { | ||
| if (!existsSync(directory)) return []; | ||
| return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { | ||
| const path = resolve(directory, entry.name); | ||
| if (entry.isDirectory()) return markdownFiles(path); | ||
| return entry.isFile() && entry.name.endsWith(".md") ? [path] : []; | ||
| }); | ||
| } | ||
|
|
||
| export function parseRecordFrontmatter(source) { | ||
| const lines = source.split(/\r?\n/); | ||
| if (lines[0] !== "---") return undefined; | ||
| const end = lines.indexOf("---", 1); | ||
| if (end < 0) return undefined; | ||
| const metadata = new Map(); | ||
| for (const line of lines.slice(1, end)) { | ||
| const match = /^([a-z][a-z0-9-]*):\s*(.*?)\s*$/.exec(line); | ||
| if (!match) continue; | ||
| metadata.set(match[1], match[2].replace(/^(?:"(.*)"|'(.*)')$/, "$1$2")); | ||
| } | ||
| return metadata; | ||
| } | ||
|
|
||
| function isTemplateOrIndex(path) { | ||
| return ["README.md", "TEMPLATE.md"].includes(path.split(sep).at(-1)); | ||
| } | ||
|
|
||
| function relativeRecordPath(root, path) { | ||
| return relative(root, path).split(sep).join("/"); | ||
| } | ||
|
|
||
| function validateMetadata({ category, metadata, record, problems }) { | ||
| for (const key of RECORD_METADATA) { | ||
| if (!metadata.get(key)?.trim()) problems.push(`${record}: missing ${key}`); | ||
| } | ||
| const status = metadata.get("status"); | ||
| if (status && !RECORD_STATUSES.has(status)) { | ||
| problems.push(`${record}: unsupported status ${status}`); | ||
| } | ||
| for (const key of ["created", "last-verified"]) { | ||
| const value = metadata.get(key); | ||
| if (value && !DATE_PATTERN.test(value)) { | ||
| problems.push(`${record}: ${key} must use YYYY-MM-DD`); | ||
| } | ||
| } | ||
| if (category === "benchmarks") { | ||
| for (const key of BENCHMARK_METADATA) { | ||
| if (!metadata.get(key)?.trim()) | ||
| problems.push(`${record}: missing ${key}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function validateResearchSections({ source, record, problems }) { | ||
| const headings = new Set( | ||
| source | ||
| .split(/\r?\n/) | ||
| .map((line) => /^##\s+(.+?)\s*$/.exec(line)?.[1].toLowerCase()) | ||
| .filter(Boolean), | ||
| ); | ||
| for (const section of RESEARCH_SECTIONS) { | ||
| if (!headings.has(section)) | ||
| problems.push(`${record}: missing section ${section}`); | ||
| } | ||
| } | ||
|
|
||
| function validateLinks({ root, path, source, problems }) { | ||
| for (const match of source.matchAll(MARKDOWN_LINK_PATTERN)) { | ||
| const target = match[1]; | ||
| if (/^(?:[a-z]+:|#|\/)/i.test(target)) continue; | ||
| const decoded = decodeURIComponent(target.split(/[?#]/, 1)[0]); | ||
| const resolved = resolve(dirname(path), decoded); | ||
| const withinRoot = | ||
| resolved === root || resolved.startsWith(`${root}${sep}`); | ||
| if (!withinRoot || !existsSync(resolved)) { | ||
| problems.push( | ||
| `${relativeRecordPath(root, path)}: broken repository link ${target}`, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function checkKnowledgeContract(root = REPOSITORY_ROOT) { | ||
| const canonicalRoot = realpathSync(root); | ||
| const problems = []; | ||
| const records = []; | ||
|
|
||
| for (const category of ["research", "benchmarks"]) { | ||
| const directory = resolve(canonicalRoot, "docs", category); | ||
| const indexPath = resolve(directory, "README.md"); | ||
| const indexSource = existsSync(indexPath) | ||
| ? readFileSync(indexPath, "utf8") | ||
| : ""; | ||
| if (!indexSource) | ||
| problems.push(`docs/${category}/README.md: missing category index`); | ||
|
|
||
| for (const path of markdownFiles(directory)) { | ||
| if (isTemplateOrIndex(path)) continue; | ||
| const source = readFileSync(path, "utf8"); | ||
| const metadata = parseRecordFrontmatter(source); | ||
| const record = relativeRecordPath(canonicalRoot, path); | ||
| // Decision 0001 is forward-only, but legacy is an immutable allowlist, | ||
| // not an opt-out available to newly added files. | ||
| if (!metadata) { | ||
| if (LEGACY_RECORDS.has(record)) continue; | ||
| problems.push(`${record}: missing frontmatter`); | ||
| continue; | ||
| } | ||
| records.push(record); | ||
| validateMetadata({ category, metadata, record, problems }); | ||
| if (category === "research") { | ||
| validateResearchSections({ source, record, problems }); | ||
| } | ||
|
|
||
| const indexTarget = relative(directory, path).split(sep).join("/"); | ||
| if (!indexSource.includes(`](${indexTarget})`)) { | ||
| problems.push( | ||
| `${record}: not reachable from docs/${category}/README.md`, | ||
| ); | ||
| } | ||
| validateLinks({ root: canonicalRoot, path, source, problems }); | ||
| } | ||
|
|
||
| if (indexSource) { | ||
| validateLinks({ | ||
| root: canonicalRoot, | ||
| path: indexPath, | ||
| source: indexSource, | ||
| problems, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { records: records.sort(), problems }; | ||
| } | ||
|
|
||
| export function assertKnowledgeContract(root = REPOSITORY_ROOT) { | ||
| const result = checkKnowledgeContract(root); | ||
| if (result.problems.length > 0) { | ||
| throw new Error( | ||
| [ | ||
| "Knowledge contract check failed:", | ||
| ...result.problems.map((problem) => `- ${problem}`), | ||
| ].join("\n"), | ||
| ); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| if ( | ||
| process.argv[1] && | ||
| pathToFileURL(resolve(process.argv[1])).href === import.meta.url | ||
| ) { | ||
| const result = assertKnowledgeContract(); | ||
| process.stdout.write( | ||
| `✓ knowledge contract (${result.records.length} governed records)\n`, | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Describe the fixed legacy allowlist instead of the removed opt-out rule
The sentence says any record without frontmatter remains legacy, while the current checker rejects every such record except the two paths in LEGACY_RECORDS. A contributor following this instruction gets
missing frontmatter. Please state that only the explicitly enumerated historical records are exempt. The PR Approach/Impact sections still describe the old opt-in behavior too.