DEV Community

owly
owly

Posted on

Plug, Play, and Think: The LivinGrimoire Personality Structure Explained

🧠 Introducing the LivinGrimoire Personality File Structure

LivinGrimoire is a software design pattern that absorbs skills with just one line of code needed to add a skill.


🧩 Personality Directory Structure

The personality directory structure is plug and play minimalist Livingrimoire directory

structure that does not require dynamic dispatch support for programming languages like Swift.

Paste in the livingrimoire packet directory, a DLC directory, and the main file.

To add skills:

Add the skill files into the DLC directory, and edit the personality

file, in which you add each skill with 1 line of code.

Personality Structure

While in the Structure Supreme, skills can be added by only copy-pasting files into the DLC directory,

the personality structure also requires editing the personality file.

A merit to this is a clear view of all the skills inside a centralized location,

as well as the ability to package a complete set of skills in one go.


πŸ”„ Comparison: Personality vs. Structure Supreme

Feature Structure Personality Structure Supreme
Skill Addition Manual (edit personality) Automatic (drop-in DLC files)
Centralized Skill Overview βœ… Yes ❌ No
Packaging Skills βœ… Easy ⚠️ Manual grouping
Language Compatibility βœ… Works in Swift ❌ Requires dynamic dispatch
Runtime Skill Loading ❌ Not supported βœ… Hot-plugging via DLC

πŸ§ͺ See Example Project (Swift)

πŸ”— LivinGrimoire Swift Example Project


🧠 Main Example (Swift)

import Foundation

let brain = Brain()
loadPersonality(brain)

let brainQueue = DispatchQueue(label: "com.livingrimoire.queue")
let tickInterval: TimeInterval = 2

func brainLoop() {
    while true {
        let message = readLine() ?? ""
        brain.think(message)

        if message.lowercased() == "exit" {
            print("Exiting...")
            exit(0)
        }
    }
}

func tickLoop() {
    var nextTick = Date().timeIntervalSince1970
    while true {
        let now = Date().timeIntervalSince1970
        if now >= nextTick {
            brainQueue.async {
                brain.think()
            }
            nextTick += tickInterval
        }
        Thread.sleep(forTimeInterval: 0.01)
    }
}

DispatchQueue.global().async { tickLoop() }
brainLoop()
Enter fullscreen mode Exit fullscreen mode

🧬 Example Personality File (Swift)

import Foundation

func loadPersonality(_ brain: Brain) {
    brain.addSkill(DiHelloWorld()) // hello world skill
    brain.addSkill(DiTime()) // time utility skill
    brain.addSkill(DiSysOut()) // output to console skill
    // brain.chained(DiHelloWorld()).chained(DiTime()).chained(DiSysOut()) // alternative method to add the skills in 1 LOC
}
Enter fullscreen mode Exit fullscreen mode

Would you like to know more?

πŸ”— LivinGrimoire GitHub Repository

Top comments (0)