Getting Started â
Learn the basics of using the CAL Runtime in 10 minutes.
Your First CAL Script â
Create a file analysis.cal:
-- Find entities with high urgency signals
FORAGE entities
WHERE sound > 7
SURFACE resultsCreate sample data entities.json:
{
"entities": [
{
"id": "entity-1",
"name": "High Priority Item",
"type": "customer",
"sound": 9,
"space": 8,
"time": 8
},
{
"id": "entity-2",
"name": "Low Priority Item",
"type": "customer",
"sound": 3,
"space": 4,
"time": 3
}
]
}Run the script:
cal run analysis.cal --data entities.jsonOutput:
ðŠķ âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Cormorant Agentic Language (CAL) v0.1.0
Sound à Space à Time â 6D Analysis â Action
ðŠķ âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð Script: analysis.cal
ð§ Parsing CAL...
â
Parsing successful
ð Executing action plan...
âââ EXECUTION RESULTS âââ
â
Execution completed
Actions executed: 1
Outputs: 1
Watchers: 0
âââ OUTPUTS âââ
ðĶ results:
Type: Array
Count: 1
ðŠķ Done.Using in TypeScript â
Basic Usage â
import { compile, Executor, createDataAdapter } from '@stratiqx/cal-runtime';
// Compile CAL script
const calSource = `
FORAGE entities
WHERE sound > 7
SURFACE results
`;
const compileResult = compile(calSource);
if (!compileResult.success) {
console.error('Parse error:', compileResult.error);
process.exit(1);
}
// Create data adapter
const dataAdapter = createDataAdapter({
type: 'memory',
initialData: {
entities: [
{
id: 'entity-1',
name: 'High Priority',
type: 'customer',
sound: 9,
space: 8,
time: 8
}
]
}
});
// Execute
const executor = new Executor({ dataAdapter });
const result = await executor.execute(compileResult.actionPlan);
console.log('Results:', result.outputs.results);With File Data â
import { compile, Executor, createDataAdapter } from '@stratiqx/cal-runtime';
import * as fs from 'fs/promises';
// Read and compile script
const calSource = await fs.readFile('analysis.cal', 'utf-8');
const { actionPlan } = compile(calSource);
// Create JSON file adapter
const dataAdapter = createDataAdapter({
type: 'json',
basePath: './data'
});
// Execute
const executor = new Executor({ dataAdapter });
const result = await executor.execute(actionPlan);Key Concepts â
1. Compilation â
Transform CAL source into an executable action plan:
import { compile } from '@stratiqx/cal-runtime';
const result = compile('FORAGE entities SURFACE results');
// result.success: boolean
// result.actionPlan: ActionPlan (if successful)
// result.error: Error (if failed)2. Adapters â
Connect to data sources and alert channels:
Data Adapters:
memory- In-memory collectionsjson- JSON filescomposite- Multiple sources
Alert Adapters:
console- Terminal outputfile- Log fileswebhook- Slack/Discord/etcjson- Testing/accumulation
3. Execution â
Run action plans with the executor:
const executor = new Executor({
dataAdapter: myDataAdapter,
alertAdapter: myAlertAdapter
});
const result = await executor.execute(actionPlan);
// result.outputs: Record<string, any>
// result.actions: ActionResult[]
// result.watchers: Watcher[]Common Patterns â
Query and Filter â
FORAGE customers
WHERE sound > 7 AND segment = "enterprise"
SURFACE high_priorityMulti-Dimensional Analysis â
FORAGE entities
WHERE sound > 7
ACROSS D1, D2, D3, D5, D6
DEPTH 3
SURFACE cascade_mapGap Measurement (DRIFT) â
FORAGE targets
WHERE impact = "high"
SURFACE analysis
DRIFT analysis
METHODOLOGY 85
PERFORMANCE 40Decision Logic (FETCH) â
FETCH cascade_map
THRESHOLD 1000
ON EXECUTE CHIRP critical "Take action now"
ON CONFIRM CHIRP warning "Review needed"
ON QUEUE SURFACE report
ON WAIT PERCH ON status:"monitoring"Monitoring â
PERCH ON segment:"enterprise"
LISTEN FOR churn signals, revenue signals
WAKE AFTER 30d
CHIRP warningWorking with 6D Dimensions â
Entities must have dimension data:
{
"id": "customer-1",
"name": "Enterprise Corp",
"sound": 8,
"space": 7,
"time": 9,
"dimensions": {
"D1": { "sound": 7, "space": 6, "time": 8 },
"D2": { "sound": 8, "space": 7, "time": 7 },
"D3": { "sound": 9, "space": 8, "time": 9 },
"D4": { "sound": 5, "space": 5, "time": 5 },
"D5": { "sound": 6, "space": 7, "time": 6 },
"D6": { "sound": 8, "space": 8, "time": 8 }
}
}Analyze across dimensions:
FORAGE entities
WHERE sound > 7
ACROSS D1, D2, D3 -- Only analyze these dimensions
DEPTH 2 -- Cascade depth
SURFACE cascade_analysisFormula Usage â
3D Lens â
Automatically calculated for all entities:
Lens = (Sound à Space à Time) / 10Provides urgency score 0-100. Used for filtering and prioritization.
DRIFT â
Measure methodology-performance gap:
DRIFT target_entities
METHODOLOGY 85 -- Expected performance
PERFORMANCE 40 -- Actual performance
-- Gap = 85 - 40 = 45FETCH â
Decision routing based on threshold:
FETCH analysis_results
THRESHOLD 1000
-- Routes actions based on calculated FETCH score:
-- FETCH = Chirp à |DRIFT| à ConfidenceError Handling â
Compilation Errors â
const result = compile('FORAGE invalid syntax');
if (!result.success) {
console.error('Parse error:', result.error.message);
if (result.error.location) {
console.error(`At line ${result.error.location.start.line}`);
}
}Execution Errors â
try {
const result = await executor.execute(actionPlan);
if (!result.success) {
console.error('Execution failed:', result.error);
}
} catch (error) {
console.error('Fatal error:', error);
}Configuration â
Create cal.config.json for project settings:
{
"name": "my-analysis-project",
"data": {
"path": "./data",
"adapter": "json"
},
"alerts": {
"type": "console"
},
"thresholds": {
"lens": 6.0,
"drift": 30,
"fetch": 1000
}
}Load configuration:
import { loadConfig } from '@stratiqx/cal-runtime';
const config = await loadConfig();
console.log('Project:', config.name);CLI Quick Reference â
# Run script
cal run script.cal --data entities.json
# Analyze without execution
cal analyze script.cal --verbose
# Validate syntax
cal validate script.cal
# Inline execution
cal run --inline "FORAGE entities SURFACE results" --data-path ./data
# Save output
cal run script.cal --data entities.json --output results.json
# Quiet mode
cal run script.cal --quietNext Steps â
Now that you understand the basics:
- Configuration - Set up project configuration
- Data Adapters - Connect to data sources
- Alert Adapters - Configure alerts
- CLI Reference - Explore all CLI commands
- Examples - Study real-world examples
- Validation - Ensure data quality
Troubleshooting â
"Cannot find module" â
Ensure you've installed the package:
npm install @stratiqx/cal-runtime"Unexpected token" â
Check that you're using ES modules:
// package.json
{
"type": "module"
}"Grammar not compiled" â
The package should include pre-compiled grammar. If not:
cd node_modules/@stratiqx/cal-runtime
npm run build:grammarData not found â
Verify your data file path and structure:
# Check file exists
ls ./data/entities.json
# Validate JSON
cat entities.json | jq .