feat(core): extend grammar with Actor, Outcome, Scenario blocks and native Field syntax#1
Merged
Conversation
…ative Field syntax - Add Actor block: first-class user role/persona, referenceable from Policy, Constraint, and Scenario via the actor attribute - Add Outcome block: measurable success criterion (metric/target/timeframe), exclusive to Feature; enforces quantitative definition of done - Add Scenario block: Given/When/Then acceptance criteria linked to a Policy and optional Actor; allowed in Feature and Section - Add native <Field /> child syntax for Definition blocks, replacing the JSON-encoded fields attribute (legacy JSON still supported for backward compat) Field supports min/max (number) and pattern (string) inline constraints - Add trigger attribute to Policy: semantic event name that fires the policy (e.g. cart.item.add), searchable but not runtime-evaluated - Add actor attribute to Policy and Constraint: space-separated Actor ID list parsed into string[] during MDX transformation - Expand Link relationship enum with: triggers, supersedes, validates, enables, blocks - Update GRAMMAR_TABLE to 10 block types; Outcome is Feature-only, Actor and Scenario are allowed in Feature and Section - Extend link-integrity validator to check Policy/Constraint actor references and Scenario policy/actor references, both per-document and workspace-wide - Update all tests (grammar, schema, parser, validator) and test fixtures - Update checkout.product.mdx example to demonstrate full v2 grammar
There was a problem hiding this comment.
Pull request overview
Extends the Product Model (core grammar + parser + validator) to support richer requirement semantics by adding Actor, Outcome, and Scenario blocks, introducing native <Field /> child syntax for Definition, and expanding link/reference integrity checking.
Changes:
- Added new block types (
Actor,Outcome,Scenario) to schemas, AST typing, and grammar rules. - Implemented native
<Field />parsing forDefinition(with legacy JSONfieldsstill supported) plus inline constraints (min/max/pattern) andvalues→enumValues. - Expanded link relationship vocabulary and extended link integrity validation to cover
Policy/Constraint.actorandScenario.policy/actorreferences.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/grammar.ts | Updates grammar table to allow new block types and enforce Outcome placement rules. |
| packages/core/src/schema/primitives.ts | Adds new block types to BlockTypeSchema. |
| packages/core/src/schema/blocks.ts | Introduces Zod schemas for Actor/Outcome/Scenario; extends Policy/Constraint/Link schemas. |
| packages/core/src/schema/fields.ts | Extends field schema with min/max/pattern constraints. |
| packages/core/src/schema/index.ts | Re-exports new schemas from the public schema surface. |
| packages/core/src/types/ast.ts | Exposes new block types through inferred AST typings. |
| packages/core/src/parser/remark-product-model.ts | Adds collection of native <Field /> child attributes during MDX extraction. |
| packages/core/src/parser/mdx-to-pmast.ts | Transforms <Field /> children into Definition.fields, parses Policy/Constraint.actor strings, preserves legacy JSON behavior. |
| packages/core/src/validator/rules/link-integrity.ts | Extends per-document reference checks to include actor/scenario references. |
| packages/core/src/validator/rules/workspace-link-integrity.ts | Extends cross-workspace reference checks to include actor/scenario references. |
| packages/core/tests/grammar.test.ts | Updates grammar table tests for 10 block types and new placement rules. |
| packages/core/tests/schema.test.ts | Adds schema coverage for new blocks, new link relationships, and field constraints. |
| packages/core/tests/parser.test.ts | Adds parser coverage for <Field />, legacy JSON fields, new blocks, trigger/actor parsing, and new link relationships. |
| packages/core/tests/validator.test.ts | Adds validator coverage for new grammar placements and new reference integrity checks. |
| packages/core/tests/fixtures/valid-full.product.mdx | Updates fixture to use new grammar and native <Field /> definitions. |
| models/examples/checkout.product.mdx | Rewrites example to demonstrate Actors/Outcomes/Scenarios, native Fields, triggers/actors, and new relationships. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- fields.ts: enforce min/max only for number fields, pattern only for string fields via .refine() - remark-product-model.ts: restrict <Field /> child collection to Definition blocks only - link-integrity.ts: validate actor/policy refs against typed ID sets (Actor/Policy) instead of allIds - workspace-link-integrity.ts: same type-aware validation using pre-built actorId/policyId sets - mdx-to-pmast.ts: only transform actor when it is a string; leave other values intact for Zod - checkout.product.mdx: remove inline JSX section divider comments that could pollute block content
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Extends the Product Model grammar from 7 to 10 block types to make product requirements more concrete, structured, and semantically precise.
New block types
Actor— First-class user role/personaExplicitly scopes who a requirement applies to. Referenceable from
Policy,Constraint, andScenariovia theactorattribute.Outcome— Measurable success criterionAnchors a
Featureto a quantitative definition of done. Only allowed insideFeature(notSection).Scenario— Given/When/Then acceptance criteriaLinks a structured acceptance test directly to a
Policyand optionalActor. Allowed inFeatureandSection.Native
<Field />syntax forDefinitionReplaces the error-prone JSON-encoded
fieldsattribute with readable MDX child elements. Supportsmin,max, andpatterninline constraints. Legacy JSON attribute still works for backward compatibility.Policy and Constraint enhancements
triggeronPolicy: semantic event name that fires the policy (e.g.cart.item.add), searchable but not runtime-evaluatedactoronPolicy/Constraint: space-separated Actor ID list, parsed intostring[]during MDX transformationExpanded
Linkrelationship vocabularyAdded 5 product-domain relationships alongside the original 4:
triggersfromcausestoto activatesupersedesfromreplacesto(e.g. v2 replacing v1)validatesfrommust pass beforetocan proceedenablesfromunlocks or gatestoblocksfrompreventstowhile activeValidator changes
Policy.actor[],Constraint.actor[],Scenario.policy, andScenario.actorreferences — both per-document and workspace-widegrammar-rulesenforcement picks up all new block types automatically via the updatedGRAMMAR_TABLEUpdated grammar table
Tests
grammar.test.ts: updated block type count (7→10), new parent/child assertionsschema.test.ts: full coverage forActorBlockSchema,OutcomeBlockSchema,ScenarioBlockSchema; fieldmin/max/pattern; newLinkrelationshipsparser.test.ts: native<Field />parsing, backward-compat JSON fields, new block type round-trips,actorarray parsing,triggerparsingvalidator.test.ts: grammar placement rules, actor/scenario broken-reference detectionvalid-full.product.mdxfixture updated to use v2 grammarcheckout.product.mdxexample rewritten to demonstrate all new features