@perstack/core
v0.0.35
Published
Perstack Core
Readme
@perstack/core
Centralized schema definitions and type contracts for the Perstack monorepo.
Installation
npm install @perstack/coreUsage
Validation
import { expertSchema, type Expert } from "@perstack/core"
const expert = expertSchema.parse(data)Extending Core Schemas
When a package needs to add package-specific fields, extend the core schema:
import { expertSchema } from "@perstack/core"
import { z } from "zod"
export const apiExpertSchema = expertSchema.omit({
skills: true,
delegates: true
}).extend({
id: z.cuid2(),
createdAt: z.date(),
updatedAt: z.date()
})Package Responsibilities
- Single Source of Truth: All cross-package schemas live here.
- Version as Contract:
major.minortracks interface changes;patchtracks fixes. - Sync Updates: Dependent packages must update in sync with
coreversion changes.
What Core Should Contain
Package Boundary Schemas: Type definitions for data that crosses package boundaries, for example:
Expert- Expert definitions shared between runtime, api-client, and other packagesSkill- Skill configurations used across the systemMessage,ToolCall,ToolResult- Runtime execution types
Domain Common Types: Types that represent core domain concepts used throughout the system, for example:
Job- Top-level execution unit containing RunsRun- Single Expert execution within a JobCheckpoint- Execution state snapshotsUsage- Resource usage trackingProviderConfig- LLM provider configurations
Configuration Schemas: System-wide configuration structures, for example:
PerstackToml- Project configuration file schemaJobSetting- Job execution parametersRunSetting- Run execution parameters
Adapter Abstractions: Runtime adapter interfaces and base classes:
RuntimeAdapter- Interface for runtime adaptersBaseAdapter- Abstract base class for CLI-based adaptersAdapterRunParams,AdapterRunResult- Adapter execution types- Event creators for normalized checkpoint/event handling
Storage Abstractions: Abstract interface for data persistence:
Storage- Interface for storage backends (filesystem, S3, R2)EventMeta- Metadata type for event listings
Execution Hierarchy
| Schema | Description |
| ------------ | -------------------------------------------- |
| Job | Top-level execution unit. Contains all Runs. |
| Run | Single Expert execution within a Job. |
| Checkpoint | Snapshot at step end within a Run. |
For the full hierarchy and execution model, see State Management.
Storage Interface
The Storage interface provides an abstraction for persisting Perstack data:
import type { Storage, EventMeta } from "@perstack/core"
interface Storage {
storeCheckpoint(checkpoint: Checkpoint): Promise<void>
retrieveCheckpoint(jobId: string, checkpointId: string): Promise<Checkpoint>
getCheckpointsByJobId(jobId: string): Promise<Checkpoint[]>
storeEvent(event: RunEvent): Promise<void>
getEventsByRun(jobId: string, runId: string): Promise<EventMeta[]>
getEventContents(jobId: string, runId: string, maxStep?: number): Promise<RunEvent[]>
storeJob(job: Job): Promise<void>
retrieveJob(jobId: string): Promise<Job | undefined>
getAllJobs(): Promise<Job[]>
storeRunSetting(setting: RunSetting): Promise<void>
getAllRuns(): Promise<RunSetting[]>
}Available implementations:
@perstack/filesystem-storage- Local filesystem storage (default)@perstack/s3-storage- AWS S3 storage@perstack/r2-storage- Cloudflare R2 storage
What Core Should NOT Contain
Package-Internal Types: Implementation details that don't cross package boundaries should remain in their respective packages.
Package-Specific Business Logic: Core contains type definitions only. Business logic, utilities, and implementations belong in their respective packages.
API-Specific Extensions: API response/request schemas with API-specific metadata (ids, timestamps, pagination) should extend core schemas in
@perstack/api-client.Tool Input Schemas (Exception): The
@perstack/basepackage is an exception. Tool input schemas are defined inline for MCP SDK registration and don't cross package boundaries. This is documented in the type management guidelines.
Schema Change Rules
Patch Version (x.y.Z)
Allowed Changes:
- Bug fixes in schema validation logic
- Performance improvements
- Documentation updates
- Internal refactoring that doesn't affect exported schemas
Prohibited Changes:
- Any changes to schema definitions
- Adding or removing fields (even optional ones)
- Changing validation rules
Minor Version (x.Y.0)
Allowed Changes:
- Adding new optional fields to existing schemas
- Adding new schemas
- Deprecating (but not removing) existing fields
- Expanding validation rules (making them less strict)
Required Actions:
- All dependent packages must bump their minor versions
- Update CHANGELOG.md with migration guide if needed
Major Version (X.0.0)
Breaking Changes:
- Removing fields
- Changing field types
- Making optional fields required
- Renaming schemas or fields
- Tightening validation rules
Required Actions:
- All dependent packages must bump their major versions
- Comprehensive migration guide required
- Consider providing deprecation warnings
Related Documentation
- CONTRIBUTING.md - Version management rules and changeset workflow
