Download Game! Currently 53 players and visitors. Last logged in:ArnoldiMahjongWhlxchCavalier

Blitzer's Blog >> 72300

Back to blogs index
Posted: 12 Sep 2026 14:48 [ permalink ]
To make this fully modular, we will finalize compiler.js by exporting its
functions, and then write index.js to act as the main entry point.
We will use a 3-node "Microservice" spec to demonstrate how the pipeline
routes to different AI providers, injects dependencies, and halts for a human
checkpoint.
1. Finalize compiler.js
At the very bottom of your compiler.js file, add this export block:
module.exports = {
    parseAST,
    buildAndValidateGraph,
    sortBottomUp,
    runOrchestrator
};

2. The Main Entry Point (index.js)
Create a new file named index.js. This script imports the compiler engine,
defines a sample AST-MD specification, and triggers the build.
const { 
    parseAST, 
    buildAndValidateGraph, 
    sortBottomUp, 
    runOrchestrator 
} = require('./compiler');

/ ==========================================
/ 1. THE CEO SPECIFICATION (AST-MD)
/ ==========================================
const ceoSpec = `
> description: A tiny backend service to demonstrate the AST compilation
pipeline.
> type: system

## DATABASE_MODELS
> description: Define a simple Mongoose schema for a User (name, email, age).
> type: data_structure
> provider: local

## BUSINESS_LOGIC
> description: Create a function to validate user age (must be > 18) and save
to the database.
> type: logic
> depends_on: [DATABASE_MODELS]
> provider: online_llm
> checkpoint: true

## REST_API
> description: Express.js router exposing a POST /users endpoint that utilizes
the business logic.
> type: endpoint
> depends_on: [BUSINESS_LOGIC]
> provider: local
`;

/ ==========================================
/ 2. PIPELINE EXECUTION
/ ==========================================
async function main() {
    try {
        console.log("Parsing CEO Spec...");
        
        // 1. Parse raw text into node objects
        const rawNodes = parseAST(ceoSpec);
        
        // 2. Validate dependencies (Ensure Node B exists if Node A needs it)
        const validGraph = buildAndValidateGraph(rawNodes);
        
        // 3. Determine the execution order (Bottom-Up DAG traversal)
        const buildOrder = sortBottomUp(validGraph);
        
        console.log("
--- CALCULATED BUILD ORDER ---");
        buildOrder.forEach((n, i) => console.log(`${i + 1}. ${n.id} [Provider:
${n.provider || 'local'}]`));
        
        // 4. Execute the AI generation loop
        await runOrchestrator(buildOrder, validGraph);

    } catch (error) {
        console.error(`
[PIPELINE ABORTED] ${error.message}`);
        process.exit(1);
    }
}

/ Run the application
main();

How to test the true power of this system:
 * Run it the first time:
   Run node index.js. Watch it build DATABASE_MODELS, route BUSINESS_LOGIC to
the simulated "Online LLM", and then halt because it hit the checkpoint: true
flag. It will exit the process before building the REST_API.
 * Inspect the artifacts:
   Look inside the newly created ./build folder. You will see
DATABASE_MODELS.js and BUSINESS_LOGIC.js.
 * Run it the second time:
   Run node index.js again. The orchestrator will instantly recognize that
nodes 1 and 2 exist. It skips them, loads their code into the context window,
and seamlessly generates the final REST_API.js file.