ast-visitor-pattern
This skill teaches agents to use the visitor pattern with frozen subclasses for discriminated unions that need multiple dispatch sites.
Identity proven by GitHub's verified organisation badge (prisma)
- Agents
- Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
- License
- Apache-2.0 (permissive)
- Pin
- 55458c4pinned Oct 9, 2026
- Context cost
- about 710 tokenswhen the skill loads
- GitHub stars
- 415on prisma/prisma-next
- Scripts
- None found
What it does
“Use the frozen-class/visitor pattern for discriminated unions that have multiple dispatch sites. Use when creating a new set of variants (commands, IR nodes, factory calls) that will be switched over in 2+ places, or when refactoring an existing union type that has grown multiple switch sites.”
Generated summary from the skill's own text
This skill teaches agents to use the visitor pattern with frozen subclasses for discriminated unions that need multiple dispatch sites. The agent learns to structure abstract base classes, visitor interfaces, and concrete subclasses to ensure compiler-checked exhaustiveness when adding new variants to commands, IR nodes, or similar type hierarchies.
When to use it
- Creating new union types with 3+ variants processed in 2+ places
- Refactoring existing unions that have grown multiple switch sites
- Building factory systems or IR nodes requiring type-safe extensions
- Ensuring compiler errors when a new variant lacks a handler
When not to
- Single dispatch site where plain union and switch suffice
- Fewer than 3 variants without anticipated growth
- When frozen object literals better match the design intent
Install
These commands install from the publisher's repository and need no account.
skills CLI
npx skills add prisma/prisma-next --skill ast-visitor-patternInstalls from the repository's default branch, which may have changed since the commit we checked.
GitHub CLI 2.90 or later
gh skill install prisma/prisma-next ast-visitor-pattern@55458c441d2cf452028c22eed21370447720840aInstalls the commit we checked (55458c4).
Copy by hand
Download the folder at 55458c4 and put it in .claude/skills/ast-visitor-pattern for Claude Code and in .agents/skills/ast-visitor-pattern for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Copy for your agent
A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.
Prompt
Install the agent skill "ast-visitor-pattern" by Prisma. Source, pinned to commit 55458c441d2cf452028c22eed21370447720840a: https://github.com/prisma/prisma-next/tree/55458c441d2cf452028c22eed21370447720840a/skills-contrib/ast-visitor-pattern 1. Download that folder at exactly this commit. Do not use the default branch. 2. Copy every file unchanged, keeping the folder structure, into .claude/skills/ast-visitor-pattern/ for Claude Code and .agents/skills/ast-visitor-pattern/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist. 3. Do not edit the files, and do not run any script in the folder unless I ask you to. 4. When you are done, list the files you copied and where you put them. Listing and checks: https://www.agentnative.dev/skills/prisma/ast-visitor-pattern
SKILL.md at the pin
---
name: ast-visitor-pattern
description: >-
Use the frozen-class/visitor pattern for discriminated unions that have
multiple dispatch sites. Use when creating a new set of variants
(commands, IR nodes, factory calls) that will be switched over in 2+
places, or when refactoring an existing union type that has grown
multiple switch sites.
---
# AST Class/Visitor Pattern
When a discriminated union has **3+ variants** and **2+ dispatch sites** (renderers, serializers, classifiers, etc.), replace plain union + switch with frozen subclasses and a visitor interface. This makes adding a new variant a compiler error at every consumer, instead of a silent omission.
## Structure
Four pieces, always in the same file:
```typescript
// 1. Abstract base (not exported — consumers use the union type)
abstract class FooNode {
abstract readonly kind: string;
abstract accept<R>(visitor: FooVisitor<R>): R;
protected freeze(): void { Object.freeze(this); }
}
// 2. Visitor interface
export interface FooVisitor<R> {
bar(node: BarNode): R;
baz(node: BazNode): R;
}
// 3. Concrete subclasses — readonly fields, freeze() in constructor
export class BarNode extends FooNode {
readonly kind = 'bar' as const;
readonly value: string;
constructor(value: string) {
super();
this.value = value;
this.freeze();
}
accept<R>(visitor: FooVisitor<R>): R { return visitor.bar(this); }
}
export class BazNode extends FooNode {
readonly kind = 'baz' as const;
readonly count: number;
constructor(count: number) {
super();
this.count = count;
this.freeze();
}
accept<R>(visitor: FooVisitor<R>): R { return visitor.baz(this); }
}
// 4. Union type
export type Foo = BarNode | BazNode;
```
## Consuming
Define a visitor object (or class) per concern:
```typescript
const renderVisitor: FooVisitor<string> = {
bar(node) { return node.value; },
baz(node) { return String(node.count); },
};
function render(node: Foo): string {
return node.accept(renderVisitor);
}
```
## Always construct instances, never frozen object literals
This holds everywhere a node is built — tests **and** production construction surfaces (contract-free factories, builders). A factory must return `new BarNode(...)`, never `Object.freeze({ kind: 'bar', value: 'x' })`. A frozen plain object has no prototype, so `instanceof` fails, `accept()` is missing, and a downstream shallow-copy (`{ ...node }`) silently strips the type back to an anonymous bag; constructor-time invariants are skipped too.
```typescript
// ✅
const call = new BarNode('x');
export function bar(value: string): BarNode { return new BarNode(value); }
// ❌
const call: Foo = { kind: 'bar', value: 'x' };
export function bar(value: string): Foo { return Object.freeze({ kind: 'bar', value }); }
```
## When NOT to use
- Single dispatch site → plain union + switch is simpler
- Fewer than 3 variants with no expected growth → not worth the boilerplate
## Codebase examples
- `MongoAstNode` / `MongoDdlCommandVisitor` — `packages/2-mongo-family/4-query/query-ast/src/ddl-commands.ts`
- `OpFactoryCall` / `OpFactoryCallVisitor` — `packages/3-mongo-target/1-mongo-target/src/core/op-factory-call.ts`
From prisma/prisma-next at 55458c4, shown as plain text under its license: Apache-2.0 (permissive). The license text is in LICENSE.
View SKILL.md on GitHub at 55458c4Files
- SKILL.md3.2 KB · 293b5dd9a788
1 file, 3.2 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at 55458c4More from Prisma
prisma-8
This skill helps agents work with Prisma 8, a contract-first data layer for TypeScript projects.
Contains scripts
Claude Code, Codex, Cursor +3 · about 3.5K tokens · pinned 6 days ago
adr-review
This skill reviews Architecture Decision Records (ADRs) from a fresh perspective, identifying clarity and structural issues, then rewrites them for future…
Claude Code, Codex, Cursor +4 · about 590 tokens · pinned 6 days ago
bumping-biome
Updates the biome code formatter package to a specified version using pnpm, renames configuration files to biome.jsonc format, updates schema references, and…
Claude Code, Codex, Cursor +4 · about 290 tokens · pinned 6 days ago
contrib-pr
This skill guides external contributors through opening a pull request against prisma-next by following the project's contribution guidelines.
Claude Code, Codex, Cursor +4 · about 2.2K tokens · pinned 6 days ago
create-pr
This skill creates a GitHub pull request with a Linear-ticket-prefixed title and a decision-led narrative description for the prisma-next repository.
Claude Code, Codex, Cursor +4 · about 4.3K tokens · pinned 6 days ago
draft-release-notes
Authors release notes for stable Prisma Next releases by enumerating merged PRs since the previous stable tag, resolving Linear issue references to…
Claude Code, Codex, Cursor +4 · about 4.9K tokens · pinned 6 days ago
Related in Coding workflow
planning
This skill orchestrates multi-workflow projects with dependencies and shared data tables by creating a task graph in the orchestrator via the create-tasks tool.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 2.4K tokens · pinned 6 days ago
progressive-building
This skill implements incremental workflow development for agents building or extending workflows.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 1.4K tokens · pinned 6 days ago
workflow-builder
Builds and edits n8n workflows using the TypeScript SDK.
by n8nOfficial publisher
Claude Code, Codex, Cursor +3 · about 14.2K tokens · pinned 6 days ago
remotion-upgrade
This skill upgrades Remotion and its related packages to the latest stable version.
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 460 tokens · pinned 6 days ago
remotion-upgrade
This skill upgrades Remotion and related packages across a project, automatically detecting the package manager and workspaces.
by RemotionOfficial publisher
Claude Code, Codex, Cursor +3 · about 460 tokens · pinned 6 days ago
final-release-review
Audits Python SDK release candidates or plans against the previous release, comparing diffs for regressions, API changes, and version compatibility.
by OpenAIOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 5.4K tokens · pinned 6 days ago