Conversation
New agent skill documenting the three PSL syntax tree layers (green tree, red tree, strongly-typed AST classes), when to use each, and the four anti-patterns to avoid (re-stringifying the AST, reading green nodes, collecting lazy child iterators into arrays, and red-tree spelunking on nodes of known type). Covers the navigation helpers from the red tree (findAncestor, tokenAtOffset, coveringElement, trivia-aware movement). Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new documentation file, SKILL.md, under skills-contrib/psl-ast-layers, describing the PSL parser's three syntax tree layers (green tree, red tree, typed AST), when to use each, recommended getter-based navigation patterns, anti-patterns to avoid, and a quick-reference API list. ChangesPSL AST Layers Documentation
Estimated code review effort: 1 (Trivial) | ~3 minutes Related Issues: None specified Related PRs: None specified Suggested labels: documentation Suggested reviewers: None specified Poem: A rabbit hops through layers three, / Green, red, and typed as can be, / With getters clean and paths made clear, / No text round-trips, no spelunking here, / A tidy doc for all to see! 🐇📄 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Linked issue
n/a — small change (no ticket; agent-skill documentation only).
At a glance
New skill at
skills-contrib/psl-ast-layers/SKILL.md. The core of what it teaches, in one exchange:Until now the layering rules for the PSL syntax tree (green tree vs red tree vs typed AST classes) lived only in reviewers' heads; agents working on PSL interpreters and the language server kept re-deriving them — or not.
Decision
Ship one agent skill,
psl-ast-layers, that fires on any PSL-related work (contract-psl interpreters, psl-parser internals, language server, formatters) and encodes:printSyntax/SourceFileoffset-slicing) to extract structural facts, reading throughnode.green, collecting lazy child iterators into arrays, and red-tree spelunking on nodes of known type.findAncestor,tokenAtOffset(+ seam-awareTokenAtOffsetbiasing),coveringElement,nextToken/prevToken, and the trivia-aware helpers fromsyntax/navigation.ts, so hand-rolled ancestor/whitespace-skipping loops are called out as re-implementations.How it fits together
casts, combinable withany(…)) → unknown node type (offset anchoring viatokenAtOffset/coveringElement) → green tree (parser-internal only).syntax/ast/(built fromfindChildToken/findFirstChild/filterChildren) instead of hand-rolling child iteration at call sites.sourceFile.positionAt/offsetAt).Reviewer notes
packages/1-framework/2-authoring/psl-parser/src/syntax/at currentorigin/main— including the navigation helpers that landed in TML-2946: Add PSL type and generic block completions #871 (findAncestor,tokenAtOffset,SyntaxTokenas a class,syntax/navigation.ts,anycombinator).printSyntaxandSourceFileoffsets are deliberately not banned outright — the skill carves out their legitimate human-facing uses (error snippets, formatter output, LSP ranges) and forbids only extracting structural facts from re-stringified text.skills-contrib/; the.agents/skills/and.claude/skills/symlinks are materialized by thepreparehook and stay untracked.Testing performed
pnpm lint:skills— all skills-contrib skills pass frontmatter/structure validation.Skill update
This PR is a skill addition (
skills-contrib/psl-ast-layers/SKILL.md); no user-facing product surface changed, so no updates underpackages/0-shared/skills/are required.Alternatives considered
.agents/rules/*.mdc) instead of a skill — rules are always-on and terse; this content needs worked examples and a decision flow, which fits the on-demand skill format. The layering guidance is only relevant when touching PSL code.Array.fromon child iterators is acceptable; dropped to keep the anti-pattern absolute and easier for agents to follow.Checklist
git commit -s) per the DCO. The DCO status check will block merge if any commit is missing aSigned-off-by:trailer.pnpm lint:skillsvalidates the skill).TML-NNNN: <sentence-case title>form — intentionally omitted: no Linear ticket exists for this change (maintainer decision).Summary by CodeRabbit