Core types, utilities, and validation for Baton Framework
@conductus-labs/baton-core is the foundational package for Baton Framework. It provides:
- TypeScript type definitions for all framework components
- Validation utilities for agents, patterns, workflows, and knowledge files
- File parsing utilities for YAML, Markdown, and frontmatter
- Path resolution utilities for framework and project files
- Version comparison utilities for semantic versioning
This package has no dependencies (except js-yaml for YAML parsing) and serves as the base for all other Baton Framework packages.
npm install @conductus-labs/baton-coreImport TypeScript types for framework components:
import type {
AgentDefinition,
CognitivePattern,
WorkflowDefinition,
KnowledgeFile,
ProjectConfig,
Boundaries,
AgentContext,
} from "@conductus-labs/baton-core";Validate framework component structures:
import {
validateAgent,
validatePattern,
validateWorkflow,
validateKnowledge,
} from "@conductus-labs/baton-core";
// Validate agent definition
const agentData = {
/* ... */
};
if (validateAgent(agentData)) {
// TypeScript knows agentData is AgentDefinition
console.log(agentData.agent_name);
}
// Validate cognitive pattern
const patternData = {
/* ... */
};
if (validatePattern(patternData)) {
// TypeScript knows patternData is CognitivePattern
console.log(patternData.cognitive_identity.thinking_pattern);
}Load and validate framework components from files:
import {
loadAgent,
loadAgentStrict,
loadPattern,
loadPatternStrict,
loadWorkflow,
loadWorkflowStrict,
} from "@conductus-labs/baton-core";
// Safe loading (returns null if invalid)
const agent = loadAgent("baton-agent");
if (agent) {
console.log(agent.agent_name);
}
// Strict loading (throws if invalid)
try {
const agent = loadAgentStrict("baton-agent");
// TypeScript knows agent is AgentDefinition
} catch (error) {
console.error("Failed to load agent:", error);
}Parse YAML, Markdown, and frontmatter:
import {
parseYamlFrontmatter,
loadFileWithFrontmatter,
loadYamlFile,
loadMarkdownFile,
} from "@conductus-labs/baton-core";
// Parse YAML frontmatter from markdown
const { frontmatter, content } = parseYamlFrontmatter(markdownContent);
// Load file with frontmatter
const result = loadFileWithFrontmatter("./agent.md");
if (result) {
console.log(result.frontmatter); // Parsed YAML frontmatter
console.log(result.content); // Markdown content
}
// Load YAML file
const yamlData = loadYamlFile("./pattern.yml");
// Load markdown file
const markdownContent = loadMarkdownFile("./knowledge.md");Resolve paths to framework and project files:
import {
findProjectRoot,
getBatonFolderPath,
getDotBatonFolderPath,
getFrameworkFilePath,
getProjectFilePath,
} from "@conductus-labs/baton-core";
// Find project root
const projectRoot = findProjectRoot();
// Get baton/ folder path
const batonPath = getBatonFolderPath();
// Get .baton/ folder path
const dotBatonPath = getDotBatonFolderPath();
// Resolve framework file path
const agentPath = getFrameworkFilePath("agents", "baton-agent.md");
// Returns: {projectRoot}/baton/agents/baton-agent.md
// Resolve project file path
const configPath = getProjectFilePath("project.config.yml");
// Returns: {projectRoot}/.baton/project.config.ymlCompare semantic versions:
import {
compareVersions,
isVersionGreater,
isVersionLess,
isVersionEqual,
} from "@conductus-labs/baton-core";
// Compare versions
const result = compareVersions("1.2.0", "1.1.0"); // Returns: 1 (greater)
// Check version relationships
if (isVersionGreater("1.2.0", "1.1.0")) {
console.log("Version is greater");
}
if (isVersionLess("1.0.0", "1.1.0")) {
console.log("Version is less");
}
if (isVersionEqual("1.0.0", "1.0.0")) {
console.log("Versions are equal");
}All types are exported from the main package:
AgentDefinition- Agent definition structureAgentMetadata- Agent metadataCognitivePattern- Cognitive pattern structureWorkflowDefinition- Workflow definition structureKnowledgeFile- Knowledge file structureProjectConfig- Project configuration structureBoundaries- Boundaries structureAgentContext- Agent context structure
validateAgent(data)- Validate agent definitionvalidatePattern(data)- Validate cognitive patternvalidateWorkflow(data)- Validate workflow definitionvalidateKnowledge(data)- Validate knowledge file
All validation functions return TypeScript type guards.
Safe Loading (returns null if invalid):
loadAgent(name, startPath?)- Load agent definitionloadPattern(name, startPath?)- Load cognitive patternloadWorkflow(name, startPath?)- Load workflow definition
Strict Loading (throws if invalid):
loadAgentStrict(name, startPath?)- Load agent definition (strict)loadPatternStrict(name, startPath?)- Load cognitive pattern (strict)loadWorkflowStrict(name, startPath?)- Load workflow definition (strict)
parseYamlFrontmatter(content)- Parse YAML frontmatter from markdownloadFileWithFrontmatter(filePath)- Load file and parse frontmatterloadYamlFile(filePath)- Load YAML fileloadMarkdownFile(filePath)- Load markdown file
findProjectRoot(startPath?)- Find project root directorygetBatonFolderPath()- Get path tobaton/foldergetDotBatonFolderPath()- Get path to.baton/foldergetFrameworkFilePath(type, filename)- Resolve framework file pathgetProjectFilePath(filename)- Resolve project file path
compareVersions(v1, v2)- Compare two semantic versionsisVersionGreater(v1, v2)- Check if v1 > v2isVersionLess(v1, v2)- Check if v1 < v2isVersionEqual(v1, v2)- Check if v1 === v2
packages/core/
├── src/
│ ├── types/ # TypeScript type definitions
│ │ ├── agent.ts
│ │ ├── cognitive-pattern.ts
│ │ ├── workflow.ts
│ │ ├── knowledge.ts
│ │ ├── project-config.ts
│ │ ├── boundaries.ts
│ │ ├── context.ts
│ │ └── index.ts
│ ├── validation/ # Validation utilities
│ │ ├── agent-validator.ts
│ │ ├── pattern-validator.ts
│ │ ├── workflow-validator.ts
│ │ ├── knowledge-validator.ts
│ │ └── index.ts
│ ├── utils/ # Shared utilities
│ │ ├── file-parser.ts
│ │ ├── version.ts
│ │ ├── path-resolver.ts
│ │ ├── agent-loader.ts
│ │ ├── pattern-loader.ts
│ │ ├── workflow-loader.ts
│ │ └── index.ts
│ ├── manifest/ # Framework manifest
│ │ └── framework-manifest.yml
│ ├── config/ # Core configuration
│ │ └── core-init.json
│ ├── permissions/ # Workflow permissions
│ │ └── workflow-permissions.yml
│ └── index.ts # Main export
├── package.json
├── tsconfig.json
└── README.md
js-yaml(^4.1.1) - YAML parsing
npm run buildnpm run test
npm run test:watch
npm run test:coverageMIT
@conductus-labs/baton-agents- Agent definitions (depends on this package)@conductus-labs/baton-cognitive-patterns- Cognitive patterns (depends on this package)@conductus-labs/baton-knowledge- Knowledge files (depends on this package)@conductus-labs/baton-workflows- Workflow definitions (depends on this package)