| layout | default |
|---|---|
| title | Chapter 3: Workflow Construction and Deterministic Runtime |
| nav_order | 3 |
| parent | Refly Tutorial |
Welcome to Chapter 3: Workflow Construction and Deterministic Runtime. In this part of Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.
This chapter focuses on constructing workflows that remain stable under real operational pressure.
- build workflows from intent while preserving deterministic behavior
- validate graph logic before execution
- use state transitions to avoid accidental invalid runs
- design workflows for recovery and reuse
- start workflow construction (visual or CLI builder)
- define nodes, dependencies, and variable contracts
- validate structure before commit/run
- run with explicit input and inspect status/output
- iterate with small deltas and versioned changes
| Signal | Why It Matters |
|---|---|
| DAG validation | prevents cycle-based runtime failures |
| explicit state transitions | reduces partial/invalid commits |
| JSON-first outputs | improves machine readability and automation |
| versioned skills | enables safe reuse and rollback |
You now have a practical pattern for building stable workflows and iterating safely.
Next: Chapter 4: API and Webhook Integrations
The getDirectorySize function in scripts/cleanup-node-modules.js handles a key part of this chapter's functionality:
* @param {string} dirPath - Path to directory
*/
function getDirectorySize(dirPath) {
let totalSize = 0;
try {
const items = fs.readdirSync(dirPath, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dirPath, item.name);
if (item.isDirectory()) {
totalSize += getDirectorySize(fullPath);
} else {
try {
const stats = fs.statSync(fullPath);
totalSize += stats.size;
} catch (_error) {
// Skip files we can't stat
}
}
}
} catch (_error) {
// Skip directories we can't read
}
return totalSize;
}
async function main() {
console.log('🔍 Searching for node_modules directories...\n');This function is important because it defines how Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code implements the patterns covered in this chapter.
The main function in scripts/cleanup-node-modules.js handles a key part of this chapter's functionality:
}
async function main() {
console.log('🔍 Searching for node_modules directories...\n');
const startTime = Date.now();
const rootDir = process.cwd();
// Find all node_modules directories
const nodeModulesPaths = findNodeModules(rootDir);
if (nodeModulesPaths.length === 0) {
console.log('✨ No node_modules directories found!');
return;
}
console.log(`\n📊 Found ${nodeModulesPaths.length} node_modules directories`);
// Calculate total size before deletion
let totalSize = 0;
console.log('\n📏 Calculating sizes...');
for (const dirPath of nodeModulesPaths) {
const size = getDirectorySize(dirPath);
totalSize += size;
console.log(` ${path.relative(rootDir, dirPath)}: ${formatBytes(size)}`);
}
console.log(`\n💾 Total size to be freed: ${formatBytes(totalSize)}`);
console.log('\n🗑️ Starting deletion...\n');
// Delete all found node_modules directories
let deletedCount = 0;This function is important because it defines how Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code implements the patterns covered in this chapter.
flowchart TD
A[getDirectorySize]
B[main]
A --> B