GizStackGizStack
View .mdOpen in ChatGPTOpen in Claude

gizgame/mindrules

a mind's data and the rules of its acts, with no model in them: what a persona is, the verbs a mind may call and the validator of each call (refusal), what a call's result reads as (result), a mind's needs, goals, memories and bonds, how a memory is recalled, and what a ware costs as its stock runs short. gizgame/mind runs the minds with their models and voices, and re-exports this module.

gizlang
import * as Mindrules from "gizgame/mindrules";

Types

Persona

gizlang
type Persona = { kind: string; name: string; role: string; traits: string; knows?: string; goals?: Vec<string>; voice?: Map<string, Map<string, string>>; sells?: Vec<Ware>; rounds?: Vec<string>; barks?: Map<string, Vec<string>>; needs?: Vec<string>; aliases?: Vec<string>; bonds?: Vec<Bond>; may?: Vec<string>; }

Who a being of KIND is: its NAME, its ROLE in the world, its TRAITS (how it is and how it talks), what it KNOWS that others may ask, and the GOALS it pursues on its own. VOICE is how it sounds to each voice model (Minds.voice), by the model's name (with no "@URL" and no "gizai:"): that model's own parameters, such as { omnivoice: { instruct: "female, elderly, low pitch" } }; a model it does not name speaks in its own voice; in a parameter's value, {language} is the language of the one it speaks to (the first part of its tag: "ko"). With no VOICE the being speaks in text alone. It SELLS its wares to players (Ware). It walks its ROUNDS, the places of its day, one after another, staying at each a while, when nothing else holds it. Its BARKS are its own lines for common things (barks). Its NEEDS rise with time and drive it (rest, food and company unless given). Its BONDS are those it knows from the start (a sworn brother, a rival), its ALIASES its name in other tongues. MAY names the RESTRICTED acts its role allows (a soldier none, a lord all; unset: all). The first being of KIND not yet given a persona takes it; a persona with no NAME is a crowd: every being of its kind takes it, each with a name of its own (seated).

  • kind: string
  • name: string
  • role: string
  • traits: string
  • knows: _gizlang_sdk_core.Option<string>
  • goals: _gizlang_sdk_core.Option<Vec<string>>
  • voice: _gizlang_sdk_core.Option<_gizlang_sdk_collections.Map<string, _gizlang_sdk_collections.Map<string, string>>>
  • sells: _gizlang_sdk_core.Option<Vec<M207.Ware>>
  • rounds: _gizlang_sdk_core.Option<Vec<string>>
  • barks: _gizlang_sdk_core.Option<_gizlang_sdk_collections.Map<string, Vec<string>>>
  • needs: _gizlang_sdk_core.Option<Vec<string>>
  • aliases: _gizlang_sdk_core.Option<Vec<string>>
  • bonds: _gizlang_sdk_core.Option<Vec<M207.Bond>>
  • may: _gizlang_sdk_core.Option<Vec<string>>

Ware

gizlang
type Ware = { item: string; price: i64; }

An item of the realm (Realm.items, by name) a persona sells, for PRICE gold at a full stock (priceOf: dearer as it runs short). It keeps STOCK (5) of each, and one more comes back every two minutes.

  • item: string
  • price: i64

Landmark

gizlang
type Landmark = { name: string; at: Point3; }

A place of the world the minds know by NAME.

  • name: string
  • at: gizlang_geometry.Point3

Minds

gizlang
type Minds = { personas: Vec<Persona>; world: string; places?: Vec<Landmark>; things?: Vec<string>; kinds?: Vec<string>; builders?: Vec<string>; director?: string; model?: string; hear?: f64; every?: f64; thinkers?: i64; voice?: string; face?: string; ears?: string; listen?: Map<string, string>; picture?: string; cut?: string; shape?: string; day?: f64; builds?: Vec<Buildable>; }

The minds of a world: its PERSONAS, the WORLD in a few sentences, its PLACES, and what the director may make: the THINGS it may place and the KINDS of beings it may bring. BUILDERS are the players whose words the director takes (none: every player); a line is for the director when it starts with DIRECTOR ("world" unless given). MODEL is the chat model as Agent.chat names it. A mind hears lines said within HEAR meters (12); unasked, it greets a player who comes within 6 meters and, while one stays, may speak every EVERY seconds (90); THINKERS threads run the agents (3). VOICE is the model a persona speaks with, EARS the one that hears what players say aloud (LISTEN its own parameters, where {language} is the language of the player heard, so it does not guess one), PICTURE the one that draws a new thing, CUT the one that cuts it out of its picture and SHAPE the one that makes its 3D model. Each is a model as Agent.make names it: giz.ai's NAME, or NAME@URL straight on giz's inference worker at URL. A model this computer's setting names comes before the realm's, and the standard one after it (MIND, VOICE, FACE, EARS, PICTURE, CUT, SHAPE: the one table). A DAY of the world lasts that many seconds (1200): at each day's end a mind reflects on it, keeps what it concluded and sets its next goals. BUILDS are the things a being may build at a place (build): each stands as its side's until a claim of that place takes it.

  • personas: Vec<M207.Persona>
  • world: string
  • places: _gizlang_sdk_core.Option<Vec<M207.Landmark>>
  • things: _gizlang_sdk_core.Option<Vec<string>>
  • kinds: _gizlang_sdk_core.Option<Vec<string>>
  • builders: _gizlang_sdk_core.Option<Vec<string>>
  • director: _gizlang_sdk_core.Option<string>
  • model: _gizlang_sdk_core.Option<string>
  • hear: _gizlang_sdk_core.Option<f64>
  • every: _gizlang_sdk_core.Option<f64>
  • thinkers: _gizlang_sdk_core.Option<i64>
  • voice: _gizlang_sdk_core.Option<string>
  • face: _gizlang_sdk_core.Option<string>
  • ears: _gizlang_sdk_core.Option<string>
  • listen: _gizlang_sdk_core.Option<_gizlang_sdk_collections.Map<string, string>>
  • picture: _gizlang_sdk_core.Option<string>
  • cut: _gizlang_sdk_core.Option<string>
  • shape: _gizlang_sdk_core.Option<string>
  • day: _gizlang_sdk_core.Option<f64>
  • builds: _gizlang_sdk_core.Option<Vec<M207.Buildable>>

Buildable

gizlang
type Buildable = { thing: string; size: f64; }

A thing beings may build (build): the scene thing THING, SIZE meters.

  • thing: string
  • size: f64

Sensed

gizlang
type Sensed = { seat: i64; name: string; kind: string; at: Point3; yaw: f64; down: bool; mind: bool; gold: i64; doing?: string; team?: string; armed?: bool; }

A being as the minds see it this tick: its SEAT, NAME, KIND, where it stands and looks, whether it is down, its GOLD, whether a mind drives it, what a player is DOING now (its quest's step, as words) and its TEAM (beings of two teams are foes).

  • seat: i64
  • name: string
  • kind: string
  • at: gizlang_geometry.Point3
  • yaw: f64
  • down: bool
  • mind: bool
  • gold: i64
  • doing: _gizlang_sdk_core.Option<string>
  • team: _gizlang_sdk_core.Option<string>
  • armed: _gizlang_sdk_core.Option<bool>

Deed

gizlang
type Deed = { seat: i64; verb: string; args: Json.Json; by: string; at: Point3; yaw: f64; then?: bool; shop?: bool; }

What a mind decided to do: VERB with ARGS, by the mind of SEAT (-1: the director), asked by the being named BY, who stood AT, looking along YAW (where "me" and "here" are). THEN says it follows another call of the same answer: a later step of one plan, not a new plan. SHOP says a player bought at a shop: the seller answers with its barks.

  • seat: i64
  • verb: string
  • args: gizlang_json.Json
  • by: string
  • at: gizlang_geometry.Point3
  • yaw: f64
  • then: _gizlang_sdk_core.Option<bool>
  • shop: _gizlang_sdk_core.Option<bool>

Built

gizlang
type Built = { deed: Deed; data: bytes; job: i64; }

A thing the director brought in (make, find, or a builder's own pick): its DEED, its GLB model, and the JOB that made it (0: a find, at once).

  • deed: M207.Deed
  • data: bytes
  • job: i64

Making

gizlang
type Making = { job: i64; deed: Deed; stage: string; percent: f64; }

A thing being made: its JOB, its DEED, and how far it is (STAGE, PERCENT).

  • job: i64
  • deed: M207.Deed
  • stage: string
  • percent: f64

Arg

gizlang
type Arg = { name: string; about: string; number?: bool; choices?: Vec<string>; optional?: bool; }

A field of a verb: NAME, what it is (ABOUT), a NUMBER or a string, one of CHOICES when given; OPTIONAL.

  • name: string
  • about: string
  • number: _gizlang_sdk_core.Option<bool>
  • choices: _gizlang_sdk_core.Option<Vec<string>>
  • optional: _gizlang_sdk_core.Option<bool>

Verb

gizlang
type Verb = { name: string; about: string; args: Vec<Arg>; kind?: string; }

Something a mind can do: the one registry of the models' tools and of what the server runs. Its KIND (VERB_KINDS): it observes the world, queries the mind's memory, plans, or acts on the world; only an act reaches the world's fast layer, after the validator (refusal).

  • name: string
  • about: string
  • args: Vec<M207.Arg>
  • kind: _gizlang_sdk_core.Option<string>

Offered

gizlang
type Offered = { seller: string; item: string; price: i64; left: i64; }

A ware on offer: who SELLS it, the ITEM, its PRICE in gold and how many are LEFT.

  • seller: string
  • item: string
  • price: i64
  • left: i64

Met

gizlang
type Met = { name: string; gold: i64; mind: bool; kind: string; team: string; armed?: bool; }

A being a mind can deal with now: its NAME, its GOLD, whether a mind drives it, its KIND, its TEAM and whether it is ARMED (a civilian is not).

  • name: string
  • gold: i64
  • mind: bool
  • kind: string
  • team: string
  • armed: _gizlang_sdk_core.Option<bool>

Facts

gizlang
type Facts = { sells: Vec<Offered>; others: Vec<Offered>; places: Vec<string>; near: Vec<Met>; team: string; asked?: Met; warmth: f64; builds?: Vec<string>; may?: Vec<string>; }

What is true of the world for one mind's turn, taken from the game: what it SELLS, what OTHERS sell, the PLACES and the beings NEAR it, its own TEAM and the one who ASKED (when someone did) with how WARM it feels to them. Its words are grounded in them, and each call it makes is checked against them (refusal).

  • sells: Vec<M207.Offered>
  • others: Vec<M207.Offered>
  • places: Vec<string>
  • near: Vec<M207.Met>
  • team: string
  • asked: _gizlang_sdk_core.Option<M207.Met>
  • warmth: f64
  • builds: _gizlang_sdk_core.Option<Vec<string>>
  • may: _gizlang_sdk_core.Option<Vec<string>>

Bond

gizlang
type Bond = { name: string; warmth: f64; }

What a mind thinks of a being it met, by NAME: WARMTH from -1 (hate) to 1 (love).

  • name: string
  • warmth: f64

Mind

gizlang
type Mind = { name: string; mood: string; bonds: Vec<Bond>; history: Vec<Agent.Message>; goals: Vec<Goal>; stock: Vec<i64>; memories: Vec<Memory>; needs: Vec<Need>; felt: f64; reflected: i64; }

A mind as it is kept: who it is (by its persona's NAME), its MOOD, its BONDS, its conversation (HISTORY: what it heard, said and did, compacted into its memory as it grows), its GOALS now, and the STOCK of each of its persona's wares, in order.

  • name: string
  • mood: string
  • bonds: Vec<M207.Bond>
  • history: Vec<gizlang_openai.Message>
  • goals: Vec<M207.Goal>
  • stock: Vec<i64>
  • memories: Vec<M207.Memory>
  • needs: Vec<M207.Need>
  • felt: f64
  • reflected: i64

Need

gizlang
type Need = { name: string; level: f64; }

A need of a mind by NAME, its LEVEL from 0 (met) to 1 (pressing): it rises with time and falls as the mind tends it.

  • name: string
  • level: f64

Goal

gizlang
type Goal = { text: string; steps: Vec<string>; done: i64; under: string; set: f64; }

A goal of a mind, in a tree (a hierarchical task network): its TEXT, the STEPS to it in order, how many are DONE, the goal it serves (UNDER, "" for a life goal) and when it was SET (the world's seconds). It lasts across restarts until the mind plans it done or drops it.

  • text: string
  • steps: Vec<string>
  • done: i64
  • under: string
  • set: f64

Memory

gizlang
type Memory = { when: f64; kind: string; text: string; who: Vec<string>; where: string; matters: f64; source: string; confidence: f64; }

A thing a mind remembers, made only of what reached it: WHEN (the world's seconds), its KIND ("experience": it saw, heard or did it; "fact": a thing learned; "social": of a being; "place": of a place), its TEXT, the beings WHO and the place WHERE it names, how much it MATTERS (0 to 1), its SOURCE ("seen", or the name of the one who told it) and the CONFIDENCE it holds (1 for what it saw; a told thing less: a rumor stays a rumor).

  • when: f64
  • kind: string
  • text: string
  • who: Vec<string>
  • where: string
  • matters: f64
  • source: string
  • confidence: f64

Functions

sameName

gizlang
function sameName(a: string, b: string): bool

Whether A and B name the same being: a model writes "zhangfei", "Zhang Fei" or "zhang-fei" for one name.

Effects: fail, alloc.

names

gizlang
function names(p: Persona, text: string): bool

Whether TEXT (lowercase) names the being P: by its name or one of its ALIASES (its name in other tongues).

Effects: fail, alloc.

seated

gizlang
function seated(p: Persona, seat: i64): Persona

P as the persona of seat SEAT: a crowd persona (no NAME) is every being of its kind, each called by its seat (Procgen.called), the same on every side.

Effects: fail, alloc.

barks

gizlang
function barks(event: string): Vec<string>

The lines a mind says at once, with no model, when a common thing happens, by EVENT, unless its persona has its own (Persona barks): "greet" ({0} the one who came), "sold" ({0} the ware, {1} the buyer), "poor" ({0} the ware, {1} its price), "none" ({0} the ware) and "bought" ({0} the ware, {1} what it paid). They are English, said in the game's language through its catalogs; their voices are kept, so a line said again costs no model at all.

Effects: fail, alloc.

refusal

gizlang
function refusal(verb: string, args: Json.Json, facts: Facts): string

Why VERB with ARGS cannot be done as FACTS stand, "" when it can: the agent reads it as the call's result and says what is true; a refused call never reaches the world. It is the one validator of a mind's calls.

Effects: fail, alloc.

observed

gizlang
function observed(facts: Facts): string

What a mind sees around it as FACTS stand: the beings near it and the places it knows (look).

Effects: fail, alloc.

acted

gizlang
function acted(line: string): { verb: string; args: Json.Json } | undefined

The deed a player's LINE asks for ("/pay Mara 5"), none when it names no PLAYER_ACTS verb.

Effects: fail, read, write, console, io, alloc.

result

gizlang
function result(verb: string, args: Json.Json): string

What a call of VERB with ARGS did, as the agent reads it.

Effects: fail, alloc.

toolOf

gizlang
function toolOf(v: Verb, run: (arguments: string) => string throws string): Agent.Tool throws string

Verb V as an agent's tool (gizai/agent): its arguments' schema from V's fields. RUN answers a call of it.

Effects: fail, alloc.

aged

gizlang
function aged(mind: Mind, now: f64, seconds: f64): Mind

MIND after SECONDS more of the world: its needs rise, its mood fades to calm, its bonds cool.

Effects: fail.

pressing

gizlang
function pressing(needs: Vec<Need>): string

NEEDS as words of a turn: those past half, the most pressing first.

Effects: fail, alloc.

planned

gizlang
function planned(goals: Vec<Goal>, args: Json.Json, now: f64): Vec<Goal>

GOALS with the plan ARGS of a call at NOW: a new goal, or one of the same text changed (its steps, its done count, the goal it serves); a goal with all steps done, or dropped, goes, with the goals under it.

Effects: fail, alloc.

outlined

gizlang
function outlined(goals: Vec<Goal>): string

GOALS as lines of a turn, each under the goal it serves, with its next step.

Effects: fail, alloc.

looks

gizlang
function looks(o: Sensed, me: Sensed): bool

Whether O looks at ME (gaze): ME stands within 15 degrees of where O faces, and within LOOKS meters.

Effects: fail.

recall

gizlang
function recall(memories: Vec<Memory>, cue: string, now: f64, most: i64): Vec<Memory>

The MOST memories of MEMORIES worth most for CUE at NOW (worth), the worthiest first: a mind's turn carries those, not its whole past.

Effects: fail, alloc.

remembered

gizlang
function remembered(memories: Vec<Memory>, m: Memory): Vec<Memory>

MEMORIES with M added; past MEMORIES the one worth least now (for no cue) is forgotten.

Effects: fail, alloc.

recalled

gizlang
function recalled(m: Memory): string

Memory M as a line of a turn: a told thing names who told it and how sure the mind is.

Effects: fail, alloc.

priceOf

gizlang
function priceOf(w: Ware, left: i64): i64

What ware W costs with LEFT of it in stock (supply): its price at a full stock, a fifth more for each one sold, so the last one costs about twice as much. The one owner of a ware's price.

Effects: fail.

effortOf

gizlang
function effortOf(facts: Facts): Effort

How hard a turn with FACTS is to think: "medium" (it reasons first, about 1.5 s on a 27B model of this network) when its words may change the world: a turn of its own (its plan), an ask from its own side when it may order or build (an order), an ask where it sells (a trade), or an armed foe near (a conflict); else "none" (a fit answer in about 0.4 s).

Effects: fail, alloc.

Constants

RESTRICTED

gizlang
const RESTRICTED = ["recruit", "order", "claim", "build", "arrest"]

The acts a role must be allowed (Persona may): hiring (recruit), commanding (order), taking places (claim), building and holding someone (arrest). A persona without MAY may do them all; with it, only those it names.

VERB_KINDS

gizlang
const VERB_KINDS = ["observe", "query", "plan", "act"]

The kinds of a verb, as Verb.kind names them.

DEEDS

gizlang
const DEEDS: Vec<Verb> = [{ name: "look", about: "Look around: who is near you and the places you know.", args: [], kind: "observe" }, { name: "recall", about: "Search your memory about something.", args: [arg("about", "What to remember.")], kind: "query" }, { name: "plan", about: "Set or update one of your goals: its steps, how many are done, the bigger goal it serves; it lasts until all its steps are done or you drop it.", args: [arg("goal", "The goal."), { name: "steps", about: "The steps in order, ; between.", optional: true }, count("done", "How many of its steps are done."), { name: "under", about: "The bigger goal this one serves.", optional: true }, { name: "drop", about: "yes to give the goal up.", choices: ["yes"], optional: true }], kind: "plan" }, { name: "go", about: "Walk to a place or a being.", args: [arg("to", "The name of a place or a being.")] }, { name: "follow", about: "Walk with a being for a minute, or until a new plan.", args: [arg("who", "The being's name.")] }, { name: "lead", about: "Show a being the way: walk ahead of it to a place, waiting when it falls behind; you are told when you arrive.", args: [arg("who", "The being's name."), arg("to", "The name of the place.")] }, { name: "patrol", about: "Walk round places in order: those named, or every place when none is named.", args: [{ name: "places", about: "Places, comma between, in order; empty: all.", optional: true }, count("rounds", "How many times round (1).")] }, { name: "stay", about: "Stop and stay here a minute.", args: [] }, { name: "wait", about: "Wait some seconds before your next step.", args: [count("seconds", "How long, in seconds (5).")] }, { name: "jump", about: "Jump once.", args: [] }, { name: "attack", about: "Fight a being by its name, or the nearest of a kind or team (as \"risen\"), on to the next of it until none stands near.", args: [arg("who", "A name, a kind or a team.")] }, { name: "flee", about: "Run away from a being.", args: [arg("from", "The being's name.")] }, { name: "feel", about: "Your feelings changed: toward a being, or your mood.", args: [{ name: "toward", about: "The being's name.", optional: true }, count("warmth", "How much warmer (up to 1) or colder (down to -1) you feel toward it."), { name: "mood", about: "Your mood now, one or two words.", optional: true }, { name: "why", about: "What made you feel so, in a few words.", optional: true }] }, { name: "sell", about: "Sell one of your wares to a being for its price; it fails when the buyer has too little gold.", args: [arg("item", "The ware."), arg("to", "The buyer's name.")] }, { name: "tend", about: "Spend a while on one of your needs (rest, food, company): you stay where you are and it is met.", args: [arg("need", "The need.")] }, { name: "pay", about: "Give gold of your own to a being near you.", args: [arg("to", "The being's name."), count("gold", "How much.")] }, { name: "recruit", about: "Ask a being near you to join you and follow your orders; it answers in its own time.", args: [arg("who", "The being's name.")] }, { name: "join", about: "Join a being near you who asked you: you serve it and follow its orders until you leave.", args: [arg("leader", "The being's name, or none to leave.")] }, { name: "order", about: "Order one who serves you, wherever it is, to do something.", args: [arg("who", "The being's name."), arg("words", "What it is to do.")] }, { name: "arrest", about: "Hold one near you where it stands for a minute (a guard's act): it may not move on.", args: [arg("who", "The being's name.")] }, { name: "report", about: "Send word to a being anywhere by a runner: it hears it as your word.", args: [arg("to", "The being's name."), arg("words", "What you tell.")] }, { name: "claim", about: "Take a place for your side: you must stand at it, and no foe may still stand there.", args: [arg("place", "The place.")] }, { name: "build", about: "Build a thing (a house, a tent, a fence) at a place your side holds or no one holds; you must stand there, and it costs 10 gold. It is your side's.", args: [arg("thing", "One of the things that can be built."), arg("place", "The place.")] }, { name: "give", about: "Give one of your wares to a being for nothing.", args: [arg("item", "The ware."), arg("to", "The being's name.")] }]

What a being can do.

EDITS

gizlang
const EDITS: Vec<Verb> = [{ name: "place", about: "Put things of the list in the world.", args: [arg("thing", "What to place: one of the things."), arg("near", "Where: a place, a being or me."), count("count", "How many (1 to 40)."), count("spread", "Over how many meters (0: one spot)."), count("size", "How big, in meters.")] }, { name: "remove", about: "Clear what was placed or brought in an area.", args: [arg("near", "Where."), count("radius", "Meters.")] }, { name: "populate", about: "Bring beings into the world.", args: [arg("kind", "One of the kinds."), arg("near", "Where."), count("count", "How many (1 to 12)."), count("spread", "Meters.")] }, { name: "terrain", about: "Raise, lower or level the ground; with TO, along a line, as a river or a road.", args: [arg("near", "Where."), { name: "to", about: "Where the line ends.", optional: true }, count("radius", "Meters."), count("height", "Meters up, or down when negative; the level with flatten."), { name: "shape", about: "raise or flatten.", choices: ["raise", "flatten"], optional: true }] }, { name: "weather", about: "Change the weather or the time of day.", args: [{ name: "weather", about: "The weather.", choices: ["clear", "rain", "storm", "fog", "snow", "night", "day"] }] }, { name: "tune", about: "Change a kind of being.", args: [arg("kind", "One of the kinds."), arg("fields", "As field=value; ...: speed, jump, hits, lift, worth, team.")] }, { name: "find", about: "Find a ready model of a thing no list has in the public catalogs (free, low-poly game models) and put it in the world; it takes seconds. The result says what was found, or that nothing was.", args: [arg("thing", "What to look for, one to three English words (a barrel, a stone well)."), arg("near", "Where."), count("size", "How big, in meters.")] }, { name: "make", about: "Make a new thing from a description with AI and put it in the world; it takes a minute or two. Use it when asked to make or design something, or when find found nothing.", args: [arg("thing", "Its name, one or two words."), arg("looks", "What it looks like, for a picture of it alone."), arg("near", "Where."), count("size", "How big, in meters."), { name: "use", about: "What it does when a player uses it.", choices: ["none", "light", "heal"], optional: true }] }]

What the director can do to the world. NEAR is a place, a being, or "me" (the one who asked).

NO_FACTS

gizlang
const NO_FACTS: Facts = { sells: [], others: [], places: [], near: [], team: "", warmth: 0 }

No facts: a turn that is not one being's in the world (the director's, which builds) has none to go by.

CHECKS

gizlang
const CHECKS = ["precondition", "permission", "resources", "reach", "combat"]

The checks of the world a call can fail, named first in a refusal: what must hold before (precondition), who may (permission), what it costs (resources), whether its target is there (reach) and the fight's rules (combat).

NEEDS

gizlang
const NEEDS = ["rest", "food", "company"]

The needs a persona has unless it names its own.

STOCK

gizlang
const STOCK: i64 = 5

The most of a ware a mind keeps, and the seconds until one more comes back.