Dynamic Variables
Dynamic Variables
Dynamic variables let you parameterize scripts without editing them. Pass --var KEY=VALUE on the command line, and the script reads it as mentu.vars.KEY.
Basics
mentu script run my-script --var ENV=production --var THRESHOLD=5In the script:
const env = mentu.vars.ENV ?? 'development';
const threshold = parseInt(mentu.vars.THRESHOLD ?? '10', 10);
console.log(`Running in ${env} with threshold ${threshold}`);mentu.vars is a frozen, read-only Record<string, string>. All values are strings — parse numbers and booleans in your script. If a variable is not passed, accessing it returns undefined.
Use cases
Environment-specific configuration
const env = mentu.vars.ENV ?? 'development';
const domain = mentu.vars.DOMAIN ?? 'default';
const signals = mentu.cir.query({
domain,
since: env === 'production' ? '1h' : '24h',
limit: env === 'production' ? 100 : 10,
});
console.log(`[${env}] Found ${signals.length} signals in domain "${domain}"`);mentu script run check --var ENV=production --var DOMAIN=infrastructureCI/CD parameters
const buildId = mentu.vars.BUILD_ID;
const branch = mentu.vars.BRANCH ?? 'main';
if (!buildId) {
console.log('BUILD_ID required');
return { error: 'missing BUILD_ID' };
}
mentu.cir.capture(`Build ${buildId} completed on ${branch}`, {
type: 'observation',
domain: 'ci',
source: 'ci-capture',
tags: ['build', branch],
});
return { captured: true, build: buildId, branch };mentu script run ci-capture --var BUILD_ID=42 --var BRANCH=feat/authPattern: Vault-driven variables
Instead of passing sensitive values on the command line (where they appear in shell history), read them from the vault:
// Don't pass secrets via --var — read them from vault
const apiKey = mentu.vault.get('EXTERNAL_API_KEY');
const deployToken = mentu.vault.get('DEPLOY_TOKEN', { scope: 'ci' });
if (!apiKey) {
console.log('Missing EXTERNAL_API_KEY in vault');
console.log('Store it with: mentu vault set EXTERNAL_API_KEY <value>');
return { error: 'missing secret' };
}
// Use --var for non-sensitive parameters
const target = mentu.vars.TARGET ?? 'staging';
console.log(`Deploying to ${target} with key ${apiKey.slice(0, 8)}...`);# Secrets come from vault, config comes from --var
mentu script run deploy --var TARGET=productionPattern: Temporal variables
When a temporal fires a script, you can pre-configure the context in the temporal definition by setting variables in the workspace or environment. The script reads runtime context from mentu.vars and CIR:
// A temporal-fired script can check its own schedule
const temporals = mentu.temporal.list();
const self = temporals.find(t => t.target === 'health-check');
if (self?.circuit_broken) {
console.log('Circuit is broken — this is a probe run');
}
const stats = mentu.cir.stats();
console.log(`Health check: ${stats.signals} signals, ${stats.contradictions} contradictions`);
return { probe: self?.circuit_broken ?? false, stats };Pattern: Sequence variables
When triggering a sequence from a script, forward variables to provide context:
const threshold = parseInt(mentu.vars.THRESHOLD ?? '3', 10);
const contradictions = mentu.cir.contradictions();
if (contradictions.length > threshold) {
// Forward relevant context as sequence variables
mentu.sequence.run('cir-audit', {
vars: {
CONTRADICTION_COUNT: String(contradictions.length),
THRESHOLD: String(threshold),
TRIGGERED_BY: 'monitor-script',
},
});
}mentu script run monitor --var THRESHOLD=5Pattern: Script-to-script context via CIR
Variables don't persist between script runs. To pass context from one script to a future run, capture it in CIR:
// Script A: capture context
mentu.cir.capture(`Last audit found ${issues.length} issues`, {
type: 'observation',
domain: 'audit',
source: 'audit-script',
tags: ['audit-result'],
});
// Script B (runs later): read context
const lastAudit = mentu.cir.search('Last audit found', {
type: 'observation',
domain: 'audit',
limit: 1,
});
if (lastAudit.length > 0) {
console.log(`Previous: ${lastAudit[0].body}`);
}CIR is the persistence layer between script executions. Variables are ephemeral; signals are permanent.