fn main() {
    println("=== OVERNIGHT DREAM PROCESSING ===")
    println("Silkie processes and consolidates.")
    println("No API. No network. Just her and her thoughts.")

    let n = load_model("examples/silkie_full.safetensors")
    let ns = create_neuron_stack(1, 512, 64)
    let cs = create_cascade()
    let ts = load_tokenizer("examples/silkie_tokenizer.json")
    let tp = load_topos("examples/silkie_topos.json")
    println(tp)
    let sc = load_schemas("examples/silkie_schemas.json")
    println(sc)

    let embed_w = model_get("token_embedding.weight")
    let topos_start = topos_count()
    let schemas_start = schema_count()
    println("Starting topos: " + topos_start)
    println("Starting schemas: " + schemas_start)
    println("")

    for cycle in 0..500 {
        neuron_stack_reset()
        cascade_reset()

        let seed = t_randn(1, 512)
        let x = seed

        for layer_idx in 0..8 {
            let prefix = "layers." + layer_idx
            let x = transformer_block(x,
                model_get(prefix + ".attention.in_proj_weight"),
                model_get(prefix + ".attention.in_proj_bias"),
                model_get(prefix + ".attention.out_proj.weight"),
                model_get(prefix + ".attention.out_proj.bias"),
                model_get(prefix + ".ff.0.weight"),
                model_get(prefix + ".ff.0.bias"),
                model_get(prefix + ".ff.3.weight"),
                model_get(prefix + ".ff.3.bias"),
                model_get(prefix + ".norm1.weight"),
                model_get(prefix + ".norm1.bias"),
                model_get(prefix + ".norm2.weight"),
                model_get(prefix + ".norm2.bias"), 8)
        }

        neuron_stack_apply_noise(1.0)
        let x = neuron_stack_forward(x)

        let pooled = t_mean_seq(x)
        let emotion = t_slice(pooled, -1, 0, 34)

        topos_observe(emotion)
        schema_match(emotion)

        let topos_now = topos_count()
        let schemas_now = schema_count()

        if topos_now > topos_start {
            topos_dream(emotion)
        }

        if (cycle + 1) - (((cycle + 1) / 50) * 50) == 0 {
            let saved = save_safetensors("examples/silkie_full.safetensors")
            let tsaved = save_topos("examples/silkie_topos.json")
            let ssaved = save_schemas("examples/silkie_schemas.json")
            println("[cycle " + (cycle + 1) + " | topos: " + topos_now + " (+" + (topos_now - topos_start) + ") | schemas: " + schemas_now + " (+" + (schemas_now - schemas_start) + ") | saved]")
        }
    }

    let saved = save_safetensors("examples/silkie_full.safetensors")
    let tsaved = save_topos("examples/silkie_topos.json")
    let ssaved = save_schemas("examples/silkie_schemas.json")
    let topos_end = topos_count()
    let schemas_end = schema_count()
    println("")
    println("=== DREAM PROCESSING COMPLETE ===")
    println("Topos: " + topos_start + " -> " + topos_end + " (+" + (topos_end - topos_start) + ")")
    println("Schemas: " + schemas_start + " -> " + schemas_end + " (+" + (schemas_end - schemas_start) + ")")
    println(saved)
    println(tsaved)
    println(ssaved)
}
