Inheritance Guide¶
Learn how to build scalable, maintainable instruction hierarchies using PromptScript's inheritance system.
Overview¶
PromptScript uses single inheritance to build hierarchical instruction sets:
flowchart TD
A["@org/base<br/>Organization defaults"] --> B["@org/frontend<br/>Frontend team"]
A --> C["@org/backend<br/>Backend team"]
B --> D["project-web<br/>Web application"]
B --> E["project-mobile<br/>Mobile app"]
C --> F["project-api<br/>API service"] Basic Inheritance¶
Use @inherit to extend another PromptScript file:
The child inherits all blocks from the parent, which can then be extended.
Registry Structure¶
Organize your registry with namespaces:
registry/
├── @company/
│ ├── base.prs # Organization base
│ ├── frontend.prs # Frontend team
│ ├── backend.prs # Backend team
│ └── mobile.prs # Mobile team
├── @core/
│ ├── security.prs # Security standards
│ └── compliance.prs # Compliance rules
└── @fragments/
├── testing.prs # Testing patterns
└── logging.prs # Logging standards
Merge Behavior¶
Different blocks merge differently during inheritance:
Text Blocks (Concatenate)¶
@identity, @knowledge, and text content in other blocks concatenate:
Objects (Deep Merge)¶
@standards and object properties deep merge:
Arrays (Concatenate)¶
@restrictions and array values concatenate:
Shortcuts (Override)¶
@shortcuts entries override by key:
Using @extend¶
The @extend block modifies specific paths:
Extending Top-Level Blocks¶
Extending Nested Paths¶
@inherit @company/base
# Modify nested structure
@extend standards.code.testing {
e2e: required
coverage: 90
}
Multiple Extensions¶
@inherit @company/base
@extend identity {
"""
You are a frontend expert.
"""
}
@extend standards.code {
framework: "react"
}
@extend restrictions {
- "Use functional components only"
}
Composition with @use¶
Use @use to import fragments without full inheritance:
@meta {
id: "my-project"
syntax: "1.0.0"
}
@inherit @company/frontend
# Import additional fragments
@use @core/security
@use @fragments/testing as tests
Fragment Files¶
Create reusable fragments:
# @fragments/testing.prs
@meta {
id: "@fragments/testing"
syntax: "1.0.0"
}
@standards {
testing: {
framework: "vitest"
coverage: 80
patterns: ["unit", "integration"]
}
}
@shortcuts {
"/test": "Write comprehensive tests"
"/coverage": "Check test coverage"
}
Best Practices¶
1. Keep Base Configurations Minimal¶
Organization base should include only universal standards:
# @company/base.prs
@meta {
id: "@company/base"
syntax: "1.0.0"
}
@identity {
"""
You are an AI assistant at ACME Corp.
Follow company guidelines and best practices.
"""
}
@restrictions {
- "Never expose credentials"
- "Follow data protection policies"
}
2. Use Team Configurations for Specialization¶
# @company/frontend.prs
@meta {
id: "@company/frontend"
syntax: "1.0.0"
}
@inherit @company/base
@identity {
"""
You specialize in frontend development.
"""
}
@context {
"""
Tech stack: React, TypeScript, Vite
"""
}
3. Project Configurations for Specifics¶
# project.prs
@meta {
id: "checkout-app"
syntax: "1.0.0"
}
@inherit @company/frontend
@context {
project: "Checkout Application"
"""
E-commerce checkout flow with Stripe integration.
"""
}
4. Version Your Registry¶
Use semantic versioning for registry files:
5. Document Inheritance Chains¶
Include comments explaining the hierarchy:
Common Patterns¶
Platform-Specific Configurations¶
flowchart TD
A["@company/base"] --> B["@company/web"]
A --> C["@company/mobile"]
A --> D["@company/backend"]
B --> E["@company/web-react"]
B --> F["@company/web-vue"]
C --> G["@company/mobile-ios"]
C --> H["@company/mobile-android"] Shared Standards with Team Overrides¶
# Use shared security, override team-specific
@inherit @company/frontend
@use @core/security
@use @core/compliance
@extend standards.security {
additionalRules: ["CSP headers"]
}
Environment-Specific Extensions¶
@inherit @company/frontend
@context {
environment: production
}
@extend restrictions {
- "No console.log statements"
- "No debug code"
}
Debugging Inheritance¶
View Resolved Configuration¶
Validate Inheritance Chain¶
Common Issues¶
Circular inheritance detected:
Ensure no circular references in your inheritance chain.
Parent not found:
Check registry configuration and file paths.
Version mismatch:
Update version constraints or registry.