Repository navigation
feat(knowledge): check every specification in the repository as a knowledge record, and convert the native specs #8288
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
cixzhang
wants to merge
3
commits into
main
Choose a base branch
from
feat/knowledge-records-everywhere
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
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 |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ | |
| /* global module, require */ | ||
|
|
||
| /** | ||
| * One shared path contract for component-local knowledge records. It consumes | ||
| * the component-package registry so validation, change classification, and the | ||
| * spec-owner gate cannot disagree about supported package layouts. | ||
| * One shared path contract for component-local knowledge records, platform | ||
| * component records, package records, and the spec-shaped files that must be | ||
| * records (INV27). It consumes the component-package registry so validation, | ||
| * change classification, and the spec-owner gate cannot disagree about | ||
| * supported package layouts. | ||
| */ | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
|
|
@@ -93,14 +95,112 @@ function classifyComponentKnowledgePath(filePath) { | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Platform implementation packages and the language their component records | ||
| * name (`component:<language>/<PublicName>`). Each component root is a | ||
| * directory of the package's component tree; its record is the direct child | ||
| * `<PublicName>.spec.md`. Swift has one package, `packages/native/apple`, | ||
| * whose `Astryx` target holds one folder per component. | ||
| */ | ||
| const PLATFORM_COMPONENT_ROOTS = Object.freeze([ | ||
| Object.freeze({ | ||
| language: 'swift', | ||
| pattern: /^(packages\/native\/apple\/Sources\/Astryx)\/([^/]+)\/([^/]+)$/, | ||
| }), | ||
| ]); | ||
|
|
||
| /** | ||
| * Classify a platform implementation's component record by path alone: | ||
| * `<package component tree>/<Root>/<PublicName>.spec.md`. Its id, its | ||
| * `platform_of` link, and the core record it names are validated after | ||
| * parsing. | ||
| */ | ||
| function classifyPlatformComponentKnowledgePath(filePath) { | ||
| const normalized = normalizePath(filePath); | ||
| if (!normalized.endsWith('.spec.md')) return null; | ||
| for (const {language, pattern} of PLATFORM_COMPONENT_ROOTS) { | ||
| const match = pattern.exec(normalized); | ||
| if (!match) continue; | ||
| const [, componentTree, componentRoot, fileName] = match; | ||
| if (isIgnoredComponentKnowledgeSegment(componentRoot)) return null; | ||
| if (fileName.endsWith('.generated.spec.md')) return null; | ||
| const publicName = fileName.slice(0, -'.spec.md'.length); | ||
| if (!/^[A-Z][A-Za-z0-9]*$/.test(publicName)) return null; | ||
| return { | ||
| componentRoot, | ||
| componentTree, | ||
| fileName, | ||
| kind: 'component', | ||
| language, | ||
| layout: 'platform', | ||
| packageName: normalized.split('/')[1], | ||
| publicName, | ||
| relativePath: fileName, | ||
| }; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Classify a package's cross-component record: a `<slug>.spec.md` anywhere | ||
| * under `packages/<package>/specs/`. Its kind is `architecture` and its id is | ||
| * `architecture:<package>-<directories>-<slug>`, joined with hyphens. | ||
| */ | ||
| function classifyPackageArchitecturePath(filePath) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression: |
||
| const match = | ||
| /^packages\/([a-z0-9][a-z0-9-]*)\/specs\/((?:[a-z0-9][a-z0-9-]*\/)*)([a-z0-9][a-z0-9-]*)\.spec\.md$/.exec( | ||
| normalizePath(filePath), | ||
| ); | ||
| if (!match) return null; | ||
| const [, packageName, directories, slug] = match; | ||
| const parts = [packageName, ...directories.split('/').filter(Boolean), slug]; | ||
| return { | ||
| id: `architecture:${parts.join('-')}`, | ||
| kind: 'architecture', | ||
| packageName, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * A spec-shaped file that must be a valid knowledge record (INV27): a tracked | ||
| * Markdown file named `*.spec.md`, or any Markdown file under a directory | ||
| * named `specs`. README.md indexes, plan.md implementation plans, and paths | ||
| * discovery ignores (fixtures, tests, generated output, hidden directories) | ||
| * are not candidates. | ||
| */ | ||
| function isKnowledgeRecordCandidatePath(filePath) { | ||
| const normalized = normalizePath(filePath); | ||
| if (!normalized.endsWith('.md')) return false; | ||
| const segments = normalized.split('/'); | ||
| const fileName = segments.at(-1); | ||
| if (fileName === 'README.md' || fileName === 'plan.md') return false; | ||
| if (fileName.startsWith('.')) return false; | ||
| if (fileName.endsWith('.generated.spec.md')) return false; | ||
| const directories = segments.slice(0, -1); | ||
| if (directories.some(isIgnoredComponentKnowledgeSegment)) return false; | ||
| return fileName.endsWith('.spec.md') || directories.includes('specs'); | ||
| } | ||
|
|
||
| function isComponentSpecRecordPath(filePath) { | ||
| return classifyComponentKnowledgePath(filePath) !== null; | ||
| return ( | ||
| classifyComponentKnowledgePath(filePath) !== null || | ||
| classifyPlatformComponentKnowledgePath(filePath) !== null | ||
| ); | ||
| } | ||
|
|
||
| function isPackageArchitectureRecordPath(filePath) { | ||
| return classifyPackageArchitecturePath(filePath) !== null; | ||
| } | ||
|
|
||
| module.exports = { | ||
| COMPONENT_PACKAGE_NAMES, | ||
| IGNORED_COMPONENT_KNOWLEDGE_SEGMENTS, | ||
| PLATFORM_COMPONENT_ROOTS, | ||
| classifyComponentKnowledgePath, | ||
| classifyPackageArchitecturePath, | ||
| classifyPlatformComponentKnowledgePath, | ||
| isComponentSpecRecordPath, | ||
| isIgnoredComponentKnowledgeSegment, | ||
| isKnowledgeRecordCandidatePath, | ||
| isPackageArchitectureRecordPath, | ||
| }; | ||
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,57 @@ | ||
| { | ||
| "schemaVersion": 5, | ||
| "extends": 4, | ||
| "kinds": { | ||
| "component": { | ||
| "template": "docs/templates/knowledge/component-spec.md", | ||
| "requiredFrontmatter": [ | ||
| "schema_version", | ||
| "template_version", | ||
| "kind", | ||
| "id", | ||
| "platform_of", | ||
| "authority", | ||
| "archive_reason", | ||
| "superseded_by", | ||
| "approved_by", | ||
| "approved_at", | ||
| "owners", | ||
| "review_triggers", | ||
| "verified_by", | ||
| "modules", | ||
| "families", | ||
| "design_specs", | ||
| "architecture", | ||
| "contributing", | ||
| "system_specs" | ||
| ], | ||
| "requiredSections": [ | ||
| "Intent", | ||
| "Compatibility and migration", | ||
| "Ownership boundary", | ||
| "Public concepts", | ||
| "Behavioral and layout contract", | ||
| "Accessibility contract", | ||
| "Design relationships", | ||
| "Family and system relationships", | ||
| "Verification map", | ||
| "Decision log", | ||
| "Open questions", | ||
| "Content boundary" | ||
| ], | ||
| "currentNonEmptyFields": ["owners", "review_triggers", "verified_by"], | ||
| "listFields": [ | ||
| "owners", | ||
| "review_triggers", | ||
| "verified_by", | ||
| "modules", | ||
| "families", | ||
| "design_specs", | ||
| "architecture", | ||
| "contributing", | ||
| "system_specs" | ||
| ], | ||
| "idPattern": "^component:(?:[a-z][a-z0-9]*/)?[A-Z][A-Za-z0-9]*$" | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "architecture": 3, | ||
| "component": 7, | ||
| "component": 8, | ||
| "design": 2, | ||
| "family": 2, | ||
| "implementation-plan": 1, | ||
|
|
||
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
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.
Regression: AST-093 FR1 on
mainnow puts a Swift component's record atdocs/specs/components/<ComponentRoot>/<Name>.swift.spec.md, beside the core record, andmain'sclassifyPlatformComponentSpecPathalready classifies that path. This pattern, andvalidatePlatformComponentRecordbuilt on it, accepts a Swift record only underpackages/native/apple/Sources/Astryx/, wheremainrejects it. Dropping it in favour ofmain's classifier conforms.