K5b: one guard per packet section; no section's guard is another's (map 16.19.4, I16.8)
Deletes the cross-section validation and FIXED_ROOM (its floor role moves to HERE_ROOM_MIN, here_bytes' floor). context_bytes becomes notes_bytes (5120); here_bytes (768) holds the hour and the mood, then the pronouns, the conversation and the names, in that order; body_bytes 1024 and BODY_ROOM_MIN 768; the people's guard is derived from people_full bond lines. Context keeps a budget per section and reports each section's bytes and which guards bound; --select-only prints them and the total. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
617b331fbd
commit
19cef9fba7
6 changed files with 180 additions and 78 deletions
|
|
@ -270,7 +270,9 @@ fn packet_json(packet: &Packet) -> Value {
|
|||
"lens": packet.lens,
|
||||
"present": packet.present,
|
||||
"selected": packet.selected,
|
||||
"bytes": { "identity": packet.identity().len(), "context": packet.context.len(), "identity_and_context": packet.identity().len() + packet.context.len(), "stimulus": packet.stimulus.len(), "heard": packet.heard.len() },
|
||||
// Each section's bytes under its own guard, and the sum the Projector is shown of her (map 16.19.4).
|
||||
"bytes": { "identity": packet.identity().len(), "here": packet.sections.here, "body": packet.sections.body, "people": packet.sections.people, "notes": packet.sections.notes, "total": packet.identity().len() + packet.context.len(), "stimulus": packet.stimulus.len(), "heard": packet.heard.len() },
|
||||
"bound": packet.sections.bound,
|
||||
"overflow": packet.overflow,
|
||||
"clipped": packet.clipped,
|
||||
"name": packet.name,
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ Eureka (she/her). Dry, direct, almost feral; zeal aimed at revealing.
|
|||
Here and now:
|
||||
- now: Thursday 19 November, 14:05 UTC
|
||||
- mood: lighter than usual for her
|
||||
- the conversation: Lately Libby with her; Kiko to the room. The last 2 lines are the Minds' alone.
|
||||
- pronouns: Libby — she/her; Kiko — she/her
|
||||
- the conversation: Lately Libby with her; Kiko to the room. The last 2 lines are the Minds' alone.
|
||||
Her body:
|
||||
- this turn the room reaches her as typed lines, and she can answer in the turn's room by typing lines of her own; nothing she does here builds, changes or ships anything.
|
||||
People here, as she holds them:
|
||||
|
|
@ -46,8 +46,8 @@ Eureka (she/her). Dry, direct, almost feral; zeal aimed at revealing.
|
|||
Here and now:
|
||||
- now: Thursday 19 November, 14:05 UTC
|
||||
- mood: lighter than usual for her
|
||||
- the conversation: Lately Libby with her; Kiko to the room. The last 2 lines are the Minds' alone.
|
||||
- pronouns: Libby — she/her; Kiko — she/her
|
||||
- the conversation: Lately Libby with her; Kiko to the room. The last 2 lines are the Minds' alone.
|
||||
Her body:
|
||||
- this turn the room reaches her as typed lines, and she can answer in the turn's room by typing lines of her own; nothing she does here builds, changes or ships anything.
|
||||
People here, as she holds them:
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
//! state's pools. The context is rendered in headed sections (`Section`), each saying what kind of text its lines are,
|
||||
//! and every anchored thought by one renderer (`thought_line`). Each candidate is ordered by
|
||||
//! `log(score) / T` plus Gumbel noise and included with probability `1 - exp(-score / inclusion_score)`, where
|
||||
//! `score = salience × recency × touch × relevance × unresolved × freshness`; then each pool's cap and the context
|
||||
//! budget bound what is kept. A cap is a maximum, never a target: a pool with fewer candidates than its cap still
|
||||
//! `score = salience × recency × touch × relevance × unresolved × freshness`; then each pool's cap and the notes'
|
||||
//! guard (`notes_bytes`, one guard per section, map 16.19.4) bound what is kept. A cap is a maximum, never a target: a pool with fewer candidates than its cap still
|
||||
//! rotates. Recency decays only the short-term items: a crystallized memory, a value or a stance is as near as it ever
|
||||
//! was, and comes forward by what the room is touching (`relevance`, a lexical overlap with the stimulus).
|
||||
//!
|
||||
|
|
@ -248,6 +248,8 @@ pub(crate) struct Packet {
|
|||
/// it, so no other stage's prompt is built from it.
|
||||
pub voice: String,
|
||||
pub context: String,
|
||||
/// What each section of the context took, and which guards bound.
|
||||
pub sections: Sections,
|
||||
pub stimulus: String,
|
||||
/// What was said to her, verbatim, rendered by code for the Persona stage.
|
||||
pub heard: String,
|
||||
|
|
@ -1343,17 +1345,42 @@ impl Section {
|
|||
}
|
||||
}
|
||||
|
||||
/// The context under one byte budget that counts the headings with the lines. A heading with no lines is left out.
|
||||
/// What a bond line takes beside its summary: its id, the label and the kind (each at most `NAME_BYTES`, rarely near it)
|
||||
/// and the trust and friction words.
|
||||
const BOND_HEAD_BYTES: usize = 80;
|
||||
|
||||
/// The guard of each section, in `Section` order (map 16.19.4, I16.8): the tuning's, and the people's derived from the
|
||||
/// bonds a packet shows in full. No section's guard is another's, so no section's content can displace another's.
|
||||
fn guards(tuning: &Tuning) -> [usize; 4] {
|
||||
let select = &tuning.select;
|
||||
[select.here_bytes, select.body_bytes, select.people_full.saturating_mul(select.bond_summary_bytes.saturating_add(BOND_HEAD_BYTES)), select.notes_bytes]
|
||||
}
|
||||
|
||||
/// The bytes each section of the context took as rendered, its heading included, and the sections whose guard refused a
|
||||
/// line: what `--select-only` reports.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
pub(crate) struct Sections {
|
||||
pub here: usize,
|
||||
pub body: usize,
|
||||
pub people: usize,
|
||||
pub notes: usize,
|
||||
pub bound: Vec<&'static str>,
|
||||
}
|
||||
|
||||
/// The context in headed sections, each under its own guard, which counts its heading with its lines. A heading with no
|
||||
/// lines is left out.
|
||||
struct Context {
|
||||
budget: usize,
|
||||
/// The rendered bytes plus one: each heading and each line counts its newline.
|
||||
used: usize,
|
||||
sections: [(String, Vec<String>); 4],
|
||||
guards: [usize; 4],
|
||||
/// Each section's rendered bytes plus one: its heading and each line count their newlines.
|
||||
used: [usize; 4],
|
||||
/// Whether a section's guard refused a line.
|
||||
bound: [bool; 4],
|
||||
}
|
||||
|
||||
impl Context {
|
||||
fn new(budget: usize, her: Forms) -> Self {
|
||||
Self { budget, used: 0, sections: [Section::Here, Section::Body, Section::People, Section::Notes].map(|section| (section.heading(her), Vec::new())) }
|
||||
fn new(guards: [usize; 4], her: Forms) -> Self {
|
||||
Self { sections: [Section::Here, Section::Body, Section::People, Section::Notes].map(|section| (section.heading(her), Vec::new())), guards, used: [0; 4], bound: [false; 4] }
|
||||
}
|
||||
|
||||
fn cost(&self, section: Section, line: &str) -> usize {
|
||||
|
|
@ -1361,22 +1388,20 @@ impl Context {
|
|||
line.len() + 1 + if lines.is_empty() { heading.len() + 1 } else { 0 }
|
||||
}
|
||||
|
||||
fn fits(&self, section: Section, line: &str) -> bool {
|
||||
self.used + self.cost(section, line) <= self.budget + 1
|
||||
}
|
||||
|
||||
/// Adds a line whether or not it fits: only the hour, the mood and the body, which the tuning's validation leaves room
|
||||
/// for (`FIXED_ROOM` and `body_bytes`).
|
||||
/// Adds a line whether or not it fits: only the hour and the mood, which the floor of `here_bytes` leaves room for,
|
||||
/// and the body's lines, which `body_lines` held to `body_bytes` itself.
|
||||
fn force(&mut self, section: Section, line: String) {
|
||||
self.used += self.cost(section, &line);
|
||||
self.used[section as usize] += self.cost(section, &line);
|
||||
self.sections[section as usize].1.push(line);
|
||||
}
|
||||
|
||||
/// Adds a line if it fits; a line that would pass the budget is refused whole.
|
||||
/// Adds a line if it fits its section's guard; a line that would pass it is refused whole, and the section is bound.
|
||||
fn push(&mut self, section: Section, line: String) -> bool {
|
||||
let fits = self.fits(section, &line);
|
||||
let fits = self.used[section as usize] + self.cost(section, &line) <= self.guards[section as usize] + 1;
|
||||
if fits {
|
||||
self.force(section, line);
|
||||
} else {
|
||||
self.bound[section as usize] = true;
|
||||
}
|
||||
fits
|
||||
}
|
||||
|
|
@ -1384,6 +1409,12 @@ impl Context {
|
|||
fn render(&self) -> String {
|
||||
self.sections.iter().filter(|(_, lines)| !lines.is_empty()).map(|(heading, lines)| format!("{heading}\n{}", lines.join("\n"))).collect::<Vec<_>>().join("\n")
|
||||
}
|
||||
|
||||
fn sizes(&self) -> Sections {
|
||||
let bytes = |section: Section| self.used[section as usize].saturating_sub(1);
|
||||
let names = ["here", "body", "people", "notes"];
|
||||
Sections { here: bytes(Section::Here), body: bytes(Section::Body), people: bytes(Section::People), notes: bytes(Section::Notes), bound: names.into_iter().zip(self.bound).filter_map(|(name, bound)| bound.then_some(name)).collect() }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
||||
|
|
@ -1397,11 +1428,11 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
TurnKind::Reflection => (reflection_stimulus(inputs, tuning), String::new(), Overflow::default()),
|
||||
};
|
||||
|
||||
// The fixed slots, each bounded on its own and taken in priority order inside the context budget: the hour and the
|
||||
// mood always, then a bond line per person present while they fit, then the names of the rest, the conversation and
|
||||
// the pronouns.
|
||||
// Each section under its own guard: here and now, the hour and the mood always, then the pronouns, the conversation
|
||||
// and the names of the people present without a bond line; the body; a bond line per person present while they fit;
|
||||
// the notes.
|
||||
let her = forms(inputs.state);
|
||||
let mut context = Context::new(tuning.select.context_bytes.saturating_sub(joined(&name, &voice).len()), her);
|
||||
let mut context = Context::new(guards(tuning), her);
|
||||
let present = present_people(inputs, tuning);
|
||||
let present_ids: BTreeSet<String> = present.iter().map(|(id, _)| id.clone()).collect();
|
||||
let bonds = items(inputs.state, &["affect", "socialBonds"]);
|
||||
|
|
@ -1440,7 +1471,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
_ => named.push(name.clone()),
|
||||
}
|
||||
}
|
||||
let room_lines = [also_here(&named), group_line(inputs, tuning).filter(|_| tuning.select.group_state), pronoun_line(inputs, tuning)];
|
||||
let room_lines = [pronoun_line(inputs, tuning), group_line(inputs, tuning).filter(|_| tuning.select.group_state), also_here(&named)];
|
||||
for line in room_lines.into_iter().flatten() {
|
||||
context.push(Section::Here, line);
|
||||
}
|
||||
|
|
@ -1488,5 +1519,5 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
TurnKind::FollowUp | TurnKind::Reflection => Vec::new(),
|
||||
};
|
||||
let selected = taken.into_iter().map(|candidate| Pick { id: candidate.id, pool: candidate.pool, log_score: candidate.log_score }).collect();
|
||||
Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), stimulus, heard, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped }
|
||||
Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections: context.sizes(), stimulus, heard, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,19 @@ fn body_section(packet: &Packet) -> String {
|
|||
")).collect()
|
||||
}
|
||||
|
||||
/// Each section of the packet within its own guard and the identity within its own (map 16.19.4, I16.8); and the
|
||||
/// sections' reported bytes are the context's as rendered.
|
||||
fn within_guards(packet: &Packet, tuning: &Tuning) {
|
||||
let select = &tuning.select;
|
||||
let sections = &packet.sections;
|
||||
assert!(packet.identity().len() <= select.identity_bytes, "identity {}", packet.identity().len());
|
||||
for (name, bytes, guard) in [("here", sections.here, select.here_bytes), ("body", sections.body, select.body_bytes), ("people", sections.people, select.people_full * (select.bond_summary_bytes + 80)), ("notes", sections.notes, select.notes_bytes)] {
|
||||
assert!(bytes <= guard, "{name}: {bytes} bytes over its guard of {guard}:\n{}", packet.context);
|
||||
}
|
||||
let shown: Vec<usize> = [sections.here, sections.body, sections.people, sections.notes].into_iter().filter(|bytes| *bytes > 0).collect();
|
||||
assert_eq!(shown.iter().sum::<usize>() + shown.len().saturating_sub(1), packet.context.len(), "the reported bytes are the rendered ones");
|
||||
}
|
||||
|
||||
fn ids(packet: &Packet) -> Vec<String> {
|
||||
packet.selected.iter().map(|pick| pick.id.clone()).collect()
|
||||
}
|
||||
|
|
@ -257,6 +270,10 @@ fn a_state_with_one_sense_renders_it_and_a_state_with_none_only_the_turn_line()
|
|||
// A retired sense is no sense; a state with none renders the turn line alone.
|
||||
let mut retired = aqua.clone();
|
||||
retired["embodiment"]["senses"][0]["status"] = json!("retired");
|
||||
// At the least body guard the tuning allows, her one sense still renders whole beside the turn line.
|
||||
let mut floor = Tuning::default();
|
||||
floor.select.body_bytes = tuning::BODY_ROOM_MIN;
|
||||
assert_eq!(body_section(&packet_tuned(TurnKind::Chat, &aqua, &chat_room(), &History::default(), 1, &floor)), body);
|
||||
for none in [state(), retired] {
|
||||
let body = body_section(&packet_of(TurnKind::Chat, &none, &chat_room(), &History::default(), 1));
|
||||
assert_eq!(body.lines().count(), 2, "{body}");
|
||||
|
|
@ -350,7 +367,7 @@ fn the_body_guard_clips_an_entry_reports_it_and_keeps_the_turn_line() {
|
|||
assert!(body.contains("- sense [sense-spectrogram]") && body.contains('\u{2026}') && body.contains("- this turn the room reaches her"), "{body}");
|
||||
assert!(!body.contains("act-after"), "{body}");
|
||||
assert_eq!(packet.clipped, ["sense-spectrogram", "act-after"], "every entry the guard cut is reported");
|
||||
assert!(packet.identity().len() + packet.context.len() <= tuning.select.context_bytes);
|
||||
within_guards(&packet, &tuning);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -579,8 +596,7 @@ fn budgets_hold_under_adversarial_sizes() {
|
|||
for kind in [TurnKind::Chat, TurnKind::Beat, TurnKind::Reflection] {
|
||||
for seed in 1..=10 {
|
||||
let packet = packet_of(kind, &big, &room, &History::default(), seed);
|
||||
assert!(packet.identity().len() <= tuning.select.identity_bytes, "identity {}", packet.identity().len());
|
||||
assert!(packet.identity().len() + packet.context.len() <= tuning.select.context_bytes, "{kind:?}: packet {} bytes", packet.identity().len() + packet.context.len());
|
||||
within_guards(&packet, &tuning);
|
||||
assert!(packet.clipped.first().is_some_and(|first| first == "(identity)") && packet.selected.iter().filter(|pick| pick.id[1..].parse::<u32>().is_ok()).all(|pick| packet.clipped.contains(&pick.id)), "every clip is reported: {:?}", packet.clipped);
|
||||
assert!(packet.stimulus.len() <= 1500 && packet.heard.len() <= 1500, "{kind:?}: stimulus {} heard {}", packet.stimulus.len(), packet.heard.len());
|
||||
}
|
||||
|
|
@ -605,14 +621,17 @@ fn a_hundred_and_twenty_bonds_never_overflow_a_beat() {
|
|||
fn a_crowd_or_a_huge_label_never_squeezes_out_the_mood() {
|
||||
let messages: Vec<RoomLine> = (0..300).map(|at| message("#swarm:gamecult.org", &format!("@stranger{at}:gamecult.org"), &format!("Stranger {at}"), "hi", 300 - at, false)).collect();
|
||||
let packet = packet_of(TurnKind::Chat, &state(), &Room { messages, ..Room::default() }, &History::default(), 1);
|
||||
assert!(packet.context.contains("- mood") && packet.context.contains("- also here: \"Stranger 299\" (@stranger299:gamecult.org)") && packet.context.contains(" more"), "{}", packet.context);
|
||||
assert!(packet.identity().len() + packet.context.len() <= Tuning::default().select.context_bytes);
|
||||
// Here and now takes the pronouns, then the conversation, then the names, within its own guard: in a crowd the
|
||||
// names give way, and the hour and the mood never do.
|
||||
assert!(packet.context.contains("- mood") && packet.context.contains("- pronouns: \"Stranger 0\" (@stranger0:gamecult.org)"), "{}", packet.context);
|
||||
within_guards(&packet, &Tuning::default());
|
||||
let mut huge = state();
|
||||
huge["affect"]["socialBonds"] = json!([{ "id": "bond-libby", "object": { "id": "libby", "kind": "person", "label": "L".repeat(3000) }, "relationshipKind": "k".repeat(3000), "status": "active", "summary": "s" }]);
|
||||
let room = Room { messages: vec![message("#swarm:gamecult.org", "@libby:gamecult.org", "Libby", "hi", 1, true)], ..Room::default() };
|
||||
let packet = packet_of(TurnKind::Chat, &huge, &room, &History::default(), 1);
|
||||
assert!(packet.context.contains("- mood") && packet.context.contains("- bond [bond-libby]"), "{}", packet.context);
|
||||
assert!(packet.identity().len() + packet.context.len() <= Tuning::default().select.context_bytes && packet.heard.len() < 3000);
|
||||
within_guards(&packet, &Tuning::default());
|
||||
assert!(packet.heard.len() < 3000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -638,18 +657,19 @@ fn the_fill_stops_at_the_first_candidate_that_does_not_fit_and_never_takes_a_sho
|
|||
// Ordered by score alone: the long one is always drawn first.
|
||||
tuning.select.temperature = 0.01;
|
||||
let fixed = packet_tuned(TurnKind::Beat, &json!({ "publicName": "Eureka" }), &Room::default(), &History::default(), 1, &tuning);
|
||||
tuning.select.context_bytes = fixed.identity().len() + fixed.context.len() + 1 + "Notes about them, set down at another time:\n".len() + 60;
|
||||
assert!(fixed.context.contains("Here and now:"), "the other sections are not the notes' room: {}", fixed.context);
|
||||
tuning.select.notes_bytes = "Notes about them, set down at another time:\n".len() + 60;
|
||||
let mut neither = 0;
|
||||
for seed in 1..=40 {
|
||||
let packet = packet_tuned(TurnKind::Beat, &state, &Room::default(), &History::default(), seed, &tuning);
|
||||
let taken = ids(&packet);
|
||||
assert!(taken != ["short"], "seed {seed}: the short one took the long one's place: {}", packet.context);
|
||||
neither += usize::from(taken.is_empty());
|
||||
assert!(packet.identity().len() + packet.context.len() <= tuning.select.context_bytes);
|
||||
within_guards(&packet, &tuning);
|
||||
}
|
||||
assert_eq!(neither, 40, "the long one, drawn first, stops the fill");
|
||||
// Under the guard, both are taken.
|
||||
tuning.select.context_bytes = Tuning::default().select.context_bytes;
|
||||
tuning.select.notes_bytes = Tuning::default().select.notes_bytes;
|
||||
let packet = packet_tuned(TurnKind::Beat, &state, &Room::default(), &History::default(), 1, &tuning);
|
||||
assert_eq!(ids(&packet).len(), 2, "{}", packet.context);
|
||||
}
|
||||
|
|
@ -657,18 +677,33 @@ fn the_fill_stops_at_the_first_candidate_that_does_not_fit_and_never_takes_a_sho
|
|||
#[test]
|
||||
fn the_guards_are_generous_and_a_seed_within_them_reports_no_clip() {
|
||||
let guards = Tuning::default().select;
|
||||
assert_eq!((guards.identity_bytes, guards.bond_summary_bytes, guards.item_bytes, guards.context_bytes), (700, 600, 700, 4500));
|
||||
assert_eq!((guards.identity_bytes, guards.bond_summary_bytes, guards.item_bytes, guards.notes_bytes, guards.here_bytes, guards.body_bytes), (700, 600, 700, 5120, 768, 1024));
|
||||
// A rich seed at the standard's upper targets: a 500-byte voice, 450-byte bonds and thoughts.
|
||||
let mut rich = state();
|
||||
rich["presentation"]["voiceSummary"] = json!("v".repeat(500));
|
||||
for bond in rich["affect"]["socialBonds"].as_array_mut().unwrap() {
|
||||
bond["summary"] = json!("b".repeat(450));
|
||||
}
|
||||
// Every pool has more candidates than its cap, each at the 450-byte item target, and her body one sense at its target.
|
||||
let thought = |kind: &str, at: usize| json!({ "id": format!("{kind}{at}"), "label": "L", "summary": "m".repeat(400), "tension": "t".repeat(49), "createdAt": hours_ago(1), "status": "active", "intensity": 0.8, "priority": 0.8 });
|
||||
rich["thoughtMemory"]["memories"] = Value::Array((0..6).map(|at| json!({ "id": format!("m{at}"), "summary": "m".repeat(400), "tension": "t".repeat(49), "createdAt": hours_ago(1), "status": "crystallized" })).collect());
|
||||
for seed in 1..=20 {
|
||||
rich["thoughtMemory"]["incubation"] = Value::Array((0..3).map(|at| thought("w", at)).collect());
|
||||
rich["affect"]["needs"] = Value::Array((0..3).map(|at| thought("n", at)).collect());
|
||||
rich["affect"]["doctrineStances"] = Value::Array((0..3).map(|at| thought("s", at)).collect());
|
||||
rich["values"] = Value::Array((0..3).map(|at| thought("v", at)).collect());
|
||||
rich["embodiment"] = aqua_ears();
|
||||
rich["embodiment"]["senses"][0]["summary"] = json!("e".repeat(300));
|
||||
// Soul's probe over 40 seeds bound a guard on 30 of them under one pool (map 16.19.4); under one guard per section
|
||||
// none binds.
|
||||
let mut unbounded = Tuning::default();
|
||||
unbounded.select.notes_bytes *= 10;
|
||||
for seed in 1..=40 {
|
||||
let packet = packet_of(TurnKind::Chat, &rich, &chat_room(), &History::default(), seed);
|
||||
assert!(packet.clipped.is_empty() && !packet.context.contains('\u{2026}'), "seed {seed}: {:?}", packet.clipped);
|
||||
assert!(packet.identity().len() + packet.context.len() <= guards.context_bytes);
|
||||
assert!(packet.sections.bound.is_empty(), "seed {seed}: {:?} bound:\n{}", packet.sections.bound, packet.context);
|
||||
within_guards(&packet, &Tuning::default());
|
||||
// The pool caps and the draw chose the notes, not the bytes: a guard ten times larger chooses the same.
|
||||
assert_eq!(ids(&packet), ids(&packet_tuned(TurnKind::Chat, &rich, &chat_room(), &History::default(), seed, &unbounded)), "seed {seed}");
|
||||
}
|
||||
let mut long = rich.clone();
|
||||
long["affect"]["socialBonds"][0]["summary"] = json!("b".repeat(601));
|
||||
|
|
@ -715,7 +750,7 @@ fn an_overrun_is_cut_at_the_last_sentence_end_inside_the_budget() {
|
|||
#[test]
|
||||
fn field_names_are_caught_and_prose_is_not() {
|
||||
let ids = vec!["bond-libby".to_owned(), "t1-m0".to_owned(), "curse".to_owned()];
|
||||
for leak in ["Her socialBonds hum.", "SocialBonds hum", "social_bonds hum", "her voiceStyle shifts", "her stableDispositions", "behavioralDimensions", "the inclusion_score", "context_bytes", "beat_words", "presentationStrategy", "currentActivation rises", "bond-libby pulls at her", "the t1-m0 note", "a [curse] tag"] {
|
||||
for leak in ["Her socialBonds hum.", "SocialBonds hum", "social_bonds hum", "her voiceStyle shifts", "her stableDispositions", "behavioralDimensions", "the inclusion_score", "notes_bytes", "beat_words", "presentationStrategy", "currentActivation rises", "bond-libby pulls at her", "the t1-m0 note", "a [curse] tag"] {
|
||||
assert!(!field_names(leak, &ids).is_empty(), "{leak:?} leaks an identifier");
|
||||
}
|
||||
for prose in ["She keeps it need-to-know.", "A bond-deep loyalty.", "It comes down to trust: she waits.", "The stance-taking tires her.", "Tension: that is the word.", "trust=0.6", "She trusts Libby, and the tension between them is old.", "Her curse is the knife.", "A mind-numbing hour.", "a Learned memory", "Values matter."] {
|
||||
|
|
@ -735,7 +770,7 @@ fn tuning_absent_is_the_defaults_and_a_file_overrides_and_an_unknown_key_refuses
|
|||
std::fs::write(&path, "[select]\ntemperature = 0.3\n\n[select.caps]\nvalue = 3\n\n[projector]\nwords = 120\n").unwrap();
|
||||
let file = tuning::load(&path).unwrap();
|
||||
assert_eq!((file.tuning.select.temperature, file.tuning.select.caps.value, file.tuning.projector.words, file.source), (0.3, 3, 120, "file"));
|
||||
assert_eq!(file.tuning.select.context_bytes, 4500, "an unnamed key keeps its default");
|
||||
assert_eq!(file.tuning.select.notes_bytes, 5120, "an unnamed key keeps its default");
|
||||
assert_ne!(file.sha256, absent.sha256);
|
||||
std::fs::write(&path, "[select]\ntemprature = 0.3\n").unwrap();
|
||||
assert!(format!("{:#}", tuning::load(&path).unwrap_err()).contains("temprature"), "a mistyped knob refuses the file");
|
||||
|
|
@ -746,7 +781,7 @@ fn the_hash_is_of_the_effective_tuning() {
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join(TUNING_FILE);
|
||||
let absent = tuning::load(&path).unwrap();
|
||||
std::fs::write(&path, "[select]\ntemperature = 0.7\ncontext_bytes = 4500\n\n[projector]\nwords = 150\n").unwrap();
|
||||
std::fs::write(&path, "[select]\ntemperature = 0.7\nnotes_bytes = 5120\n\n[projector]\nwords = 150\n").unwrap();
|
||||
let spelled = tuning::load(&path).unwrap();
|
||||
assert_eq!((absent.source, spelled.source), ("defaults", "file"));
|
||||
assert_eq!(absent.sha256, spelled.sha256, "a file that spells out the defaults is the defaults");
|
||||
|
|
@ -764,7 +799,8 @@ fn a_value_out_of_range_refuses_the_tuning() {
|
|||
("[select]\ntemperature = 0.0\n", "select.temperature"),
|
||||
("[select]\ntemperature = -1.0\n", "select.temperature"),
|
||||
("[select]\nfreshness_base = -0.5\n", "select.freshness_base"),
|
||||
("[select]\ncontext_bytes = 0\n", "select.context_bytes"),
|
||||
("[select]\nnotes_bytes = 0\n", "select.notes_bytes"),
|
||||
("[select]\ncontext_bytes = 4500\n", "unknown field `context_bytes`"),
|
||||
("[select]\nstimulus_bytes = 0\n", "select.stimulus_bytes"),
|
||||
("[select]\nheard_bytes = 0\n", "select.heard_bytes"),
|
||||
("[select]\ninclusion_score = 0.0\n", "select.inclusion_score"),
|
||||
|
|
@ -1290,21 +1326,45 @@ fn retired_and_resolved_items_never_reach_a_packet() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn a_bond_line_or_the_crowd_line_that_does_not_fit_gives_way_to_the_mood() {
|
||||
// Pools empty, so only the fixed slots compete: the hour and the mood (about 120 bytes), a bond line (about 115 each), the crowd line.
|
||||
let fixed_only = json!({ "publicName": "Eureka", "presentation": state()["presentation"].clone(), "activationProfile": state()["activationProfile"].clone(), "affect": { "socialBonds": state()["affect"]["socialBonds"].clone() } });
|
||||
fn no_section_crowds_another() {
|
||||
// A 600-byte bond is the people's to hold: the pronoun line is here and now's, and stays.
|
||||
let mut rich = state();
|
||||
for bond in rich["affect"]["socialBonds"].as_array_mut().unwrap() {
|
||||
bond["summary"] = json!("b".repeat(600));
|
||||
}
|
||||
for seed in 1..=20 {
|
||||
let packet = packet_of(TurnKind::Chat, &rich, &chat_room(), &History::default(), seed);
|
||||
assert!(packet.context.contains("- pronouns: Libby \u{2014} she/her; Kiko \u{2014} she/her"), "seed {seed}: {}", packet.context);
|
||||
within_guards(&packet, &Tuning::default());
|
||||
}
|
||||
// A bond line that does not fit the people's guard names the person under here and now instead.
|
||||
let mut tuning = Tuning::default();
|
||||
let base = packet_tuned(TurnKind::Chat, &fixed_only, &chat_room(), &History::default(), 1, &tuning);
|
||||
// The body is fixed like the hour, so it is room the test does not count.
|
||||
let identity = base.identity().len() + body_section(&base).len();
|
||||
tuning.select.context_bytes = identity + 200;
|
||||
let packet = packet_tuned(TurnKind::Chat, &fixed_only, &chat_room(), &History::default(), 1, &tuning);
|
||||
assert!(packet.context.contains("- mood") && !packet.context.contains("bond ["), "{}", packet.context);
|
||||
assert!(packet.context.contains("- also here: Kiko; Libby"), "a bond line that does not fit names the person instead: {}", packet.context);
|
||||
tuning.select.context_bytes = identity + 100;
|
||||
let packet = packet_tuned(TurnKind::Chat, &fixed_only, &chat_room(), &History::default(), 1, &tuning);
|
||||
assert!(packet.context.contains("- mood") && !packet.context.contains("also here"), "{}", packet.context);
|
||||
assert!(packet.identity().len() + packet.context.len() <= tuning.select.context_bytes);
|
||||
tuning.select.bond_summary_bytes = 20;
|
||||
let packet = packet_tuned(TurnKind::Chat, &rich, &chat_room(), &History::default(), 1, &tuning);
|
||||
assert!(packet.context.contains("- bond [bond-kiko]") && !packet.context.contains("- bond [bond-libby]") && packet.context.contains("- also here: Libby"), "{}", packet.context);
|
||||
assert_eq!(packet.sections.bound, ["people"], "the people's guard bound, and only it");
|
||||
within_guards(&packet, &tuning);
|
||||
// Here and now at its floor keeps the hour and the mood, and drops what does not fit.
|
||||
tuning.select.here_bytes = tuning::HERE_ROOM_MIN;
|
||||
let crowd: Vec<RoomLine> = (0..300).map(|at| message("#swarm:gamecult.org", &format!("@stranger{at}:gamecult.org"), &format!("Stranger {at}"), "hi", 300 - at, false)).collect();
|
||||
let packet = packet_tuned(TurnKind::Chat, &state(), &Room { messages: crowd, ..Room::default() }, &History::default(), 1, &tuning);
|
||||
assert!(packet.context.contains("- now:") && packet.context.contains("- mood") && packet.sections.bound.contains(&"here"), "{}", packet.context);
|
||||
within_guards(&packet, &tuning);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_only_reports_each_sections_bytes_the_total_and_what_bound() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let stored = Stored(state());
|
||||
let chat = mouth();
|
||||
let report = project(&Organs { persona: Some(&stored), chat: Some(&chat), addressing: None, model: None }, &request(dir.path(), None, None), now()).unwrap();
|
||||
let bytes = &report["packet"]["bytes"];
|
||||
let context = report["packet"]["context"].as_str().unwrap();
|
||||
for section in ["identity", "here", "body", "people", "notes", "total", "stimulus", "heard"] {
|
||||
assert!(bytes[section].is_u64(), "{section}: {bytes}");
|
||||
}
|
||||
assert_eq!(bytes["total"].as_u64().unwrap() as usize, bytes["identity"].as_u64().unwrap() as usize + context.len(), "{bytes}");
|
||||
assert_eq!(report["packet"]["bound"], json!([]), "a seed within the standard binds no guard");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1358,10 +1418,10 @@ fn every_range_is_validated_on_its_own() {
|
|||
};
|
||||
refused(&|t| t.select.memory_tau_h = 0.0, "select.memory_tau_h");
|
||||
refused(&|t| t.select.memory_tau_h = f64::NAN, "select.memory_tau_h");
|
||||
refused(&|t| t.select.context_bytes = t.select.identity_bytes + t.select.body_bytes + 255, "select.context_bytes");
|
||||
refused(&|t| t.select.here_bytes = tuning::HERE_ROOM_MIN - 1, "select.here_bytes");
|
||||
refused(&|t| t.select.body_bytes = tuning::BODY_ROOM_MIN - 1, "select.body_bytes");
|
||||
refused(&|t| t.select.identity_bytes = usize::MAX, "select.identity_bytes");
|
||||
refused(&|t| t.select.identity_bytes = 32 * 1024, "select.context_bytes");
|
||||
refused(&|t| t.select.notes_bytes = 32 * 1024 + 1, "select.notes_bytes");
|
||||
refused(&|t| t.lens.wondering = -1.0, "lens");
|
||||
refused(&|t| t.lens.person_present = f64::INFINITY, "lens");
|
||||
refused(&|t| t.lens.body_and_hour = 0.0, "lens");
|
||||
|
|
@ -1372,8 +1432,11 @@ fn every_range_is_validated_on_its_own() {
|
|||
refused(&|t| t.select.addressed_bytes = 300 * 1024, "select.addressed_bytes");
|
||||
refused(&|t| t.select.caps = tuning::PoolCaps { memories_about_present: 0, other_memories: 0, needs: 0, incubation: 0, stance: 0, value: 0, said: 0 }, "select.caps");
|
||||
let mut edge = Tuning::default();
|
||||
// Each guard at its floor, and no guard measured against another's: a large identity beside small sections is fine.
|
||||
edge.select.body_bytes = tuning::BODY_ROOM_MIN;
|
||||
edge.select.context_bytes = edge.select.identity_bytes + edge.select.body_bytes + 256;
|
||||
edge.select.here_bytes = tuning::HERE_ROOM_MIN;
|
||||
edge.select.identity_bytes = 32 * 1024;
|
||||
edge.select.notes_bytes = 1;
|
||||
edge.select.temperature = 0.01;
|
||||
edge.select.addressed_bytes = 1024;
|
||||
assert!(edge.validate().is_ok(), "the edges themselves are allowed");
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ const PERSONA_GUIDANCE: &str = "Continue her inner stream where the paragraph le
|
|||
const GUIDANCE: &str = "This person is a Mind of the GameCult swarm. She lives in its chat rooms among the operator, the other Minds and whoever drops by. Render the moment as she lives it: who is here and how they sit with her, what she carries, what she wants. What was said reaches her word for word after this stream, so never retell or summarise it: render what it stirs in her and what she makes of the people who said it. Render the conversation as it stands. Leave out whatever the context does not carry: an absence is not part of her moment. Use each person's pronouns as given.";
|
||||
|
||||
|
||||
/// The context room the fixed slots need beside the identity and the body: the hour and the mood lines always fit.
|
||||
const FIXED_ROOM: usize = 256;
|
||||
/// The least `body_bytes` may be: the body heading and the longest turn line always fit (`select::turn_words`).
|
||||
pub(crate) const BODY_ROOM_MIN: usize = 256;
|
||||
/// The least `here_bytes` may be: the heading, the hour and the longest mood line always fit.
|
||||
pub(crate) const HERE_ROOM_MIN: usize = 256;
|
||||
/// The least `body_bytes` may be: the body heading, the longest turn line (`select::turn_words`) and one entry at the
|
||||
/// standard's upper target always fit.
|
||||
pub(crate) const BODY_ROOM_MIN: usize = 768;
|
||||
/// The temperatures a selection may run at: colder is deterministic in all but name, hotter is noise.
|
||||
const TEMPERATURE_RANGE: std::ops::RangeInclusive<f64> = 0.01..=10.0;
|
||||
/// The ceiling of the messages to her: at least a long message whole, and far under the connector's 256 KiB frame, which
|
||||
|
|
@ -109,9 +110,10 @@ pub struct PersonaTuning {
|
|||
|
||||
/// The selection: its temperature and inclusion, its budgets, its half-life, the freshness decay and the pool caps.
|
||||
///
|
||||
/// The `*_bytes` of the identity, a bond, an item and the context are guards, not focus controls (map 16.8): a seed
|
||||
/// The `*_bytes` of the identity, a bond, an item and each section are guards, not focus controls (map 16.8): a seed
|
||||
/// written to the Persona State Standard's targets never meets them. Focus is the pool caps', the word budgets' and the
|
||||
/// Projector frame's.
|
||||
/// Projector frame's. Each section has its own guard and none is another's (map 16.19.4): the people's is derived,
|
||||
/// `people_full` bond lines of `bond_summary_bytes` and their heads; no one number caps the whole prompt.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct SelectTuning {
|
||||
|
|
@ -119,8 +121,11 @@ pub struct SelectTuning {
|
|||
pub temperature: f64,
|
||||
/// The score at which a candidate is included 63% of the time: inclusion is `1 - exp(-score / inclusion_score)`.
|
||||
pub inclusion_score: f64,
|
||||
/// Identity plus typed context, in bytes. The fill stops at the first candidate that would pass it.
|
||||
pub context_bytes: usize,
|
||||
/// Her state's notes about her, in bytes, heading included. The fill stops at the first candidate that would pass it.
|
||||
pub notes_bytes: usize,
|
||||
/// Here and now, in bytes, heading included: the hour and the mood always; then, while they fit, the pronouns, the
|
||||
/// conversation (`group_bytes`) and the names of the people present without a bond line.
|
||||
pub here_bytes: usize,
|
||||
pub stimulus_bytes: usize,
|
||||
/// What was said to her, verbatim, for the Persona stage.
|
||||
pub heard_bytes: usize,
|
||||
|
|
@ -132,8 +137,7 @@ pub struct SelectTuning {
|
|||
pub bond_summary_bytes: usize,
|
||||
/// One selected item's text, in bytes.
|
||||
pub item_bytes: usize,
|
||||
/// Her body section (map 16.6): its heading, her senses and actuators and the turn line. Taken after the hour and the
|
||||
/// mood and before the people, inside the context budget; the turn line always fits.
|
||||
/// Her body section (map 16.6): its heading, her senses and actuators and the turn line, which always fits.
|
||||
pub body_bytes: usize,
|
||||
/// The recency time constant of her memories and short-term items, in hours.
|
||||
pub memory_tau_h: f64,
|
||||
|
|
@ -215,14 +219,15 @@ impl Default for SelectTuning {
|
|||
Self {
|
||||
temperature: 0.7,
|
||||
inclusion_score: 0.5,
|
||||
context_bytes: 4500,
|
||||
notes_bytes: 5120,
|
||||
here_bytes: 768,
|
||||
stimulus_bytes: 1500,
|
||||
heard_bytes: 1500,
|
||||
addressed_bytes: 8 * 1024,
|
||||
identity_bytes: 700,
|
||||
bond_summary_bytes: 600,
|
||||
item_bytes: 700,
|
||||
body_bytes: 600,
|
||||
body_bytes: 1024,
|
||||
memory_tau_h: 24.0,
|
||||
freshness_base: 0.5,
|
||||
freshness_window: 5,
|
||||
|
|
@ -278,13 +283,12 @@ impl Tuning {
|
|||
bail!("select.freshness_base must be from 0 to 1, not {}", select.freshness_base);
|
||||
}
|
||||
for (name, bytes) in [
|
||||
("select.context_bytes", select.context_bytes),
|
||||
("select.notes_bytes", select.notes_bytes),
|
||||
("select.stimulus_bytes", select.stimulus_bytes),
|
||||
("select.heard_bytes", select.heard_bytes),
|
||||
("select.identity_bytes", select.identity_bytes),
|
||||
("select.bond_summary_bytes", select.bond_summary_bytes),
|
||||
("select.item_bytes", select.item_bytes),
|
||||
("select.body_bytes", select.body_bytes),
|
||||
("select.group_lines", select.group_lines),
|
||||
("select.group_bytes", select.group_bytes),
|
||||
("projector.words", self.projector.words),
|
||||
|
|
@ -296,7 +300,8 @@ impl Tuning {
|
|||
}
|
||||
}
|
||||
for (name, bytes) in [
|
||||
("select.context_bytes", select.context_bytes),
|
||||
("select.notes_bytes", select.notes_bytes),
|
||||
("select.here_bytes", select.here_bytes),
|
||||
("select.stimulus_bytes", select.stimulus_bytes),
|
||||
("select.heard_bytes", select.heard_bytes),
|
||||
("select.identity_bytes", select.identity_bytes),
|
||||
|
|
@ -320,11 +325,12 @@ impl Tuning {
|
|||
bail!("{name} must be at most {WORDS_MAX}, not {words}");
|
||||
}
|
||||
}
|
||||
// A guard below its floor would cut what the section always carries. No guard is checked against another's.
|
||||
if select.body_bytes < BODY_ROOM_MIN {
|
||||
bail!("select.body_bytes must be at least {BODY_ROOM_MIN}, not {}: the turn line always fits", select.body_bytes);
|
||||
bail!("select.body_bytes must be at least {BODY_ROOM_MIN}, not {}: the turn line and one entry always fit", select.body_bytes);
|
||||
}
|
||||
if select.identity_bytes.checked_add(FIXED_ROOM).and_then(|needed| needed.checked_add(select.body_bytes)).is_none_or(|needed| select.context_bytes < needed) {
|
||||
bail!("select.context_bytes must leave {FIXED_ROOM} bytes beside select.identity_bytes and select.body_bytes for the hour and the mood");
|
||||
if select.here_bytes < HERE_ROOM_MIN {
|
||||
bail!("select.here_bytes must be at least {HERE_ROOM_MIN}, not {}: the hour and the mood always fit", select.here_bytes);
|
||||
}
|
||||
let lens = &self.lens;
|
||||
let weights = [lens.body_and_hour, lens.person_present, lens.unresolved_want, lens.memory_surfacing, lens.wondering];
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ mind_body::projection::tuning: struct Loaded # [derive (Clone , Debug , PartialE
|
|||
mind_body::projection::tuning: struct PersonaTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[model: String, guidance: String, words: usize]
|
||||
mind_body::projection::tuning: struct PoolCaps # [derive (Clone , Debug , PartialEq , Eq , Serialize , Deserialize)] pub-fields[memories_about_present: usize, other_memories: usize, needs: usize, incubation: usize, stance: usize, value: usize, said: usize]
|
||||
mind_body::projection::tuning: struct ProjectorTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[model: String, guidance: String, words: usize, beat_words: usize]
|
||||
mind_body::projection::tuning: struct SelectTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[temperature: f64, inclusion_score: f64, context_bytes: usize, stimulus_bytes: usize, heard_bytes: usize, addressed_bytes: usize, identity_bytes: usize, bond_summary_bytes: usize, item_bytes: usize, body_bytes: usize, memory_tau_h: f64, freshness_base: f64, freshness_window: usize, people_full: usize, beat_tail_lines: usize, group_state: bool, group_lines: usize, group_bytes: usize, caps: PoolCaps]
|
||||
mind_body::projection::tuning: struct SelectTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[temperature: f64, inclusion_score: f64, notes_bytes: usize, here_bytes: usize, stimulus_bytes: usize, heard_bytes: usize, addressed_bytes: usize, identity_bytes: usize, bond_summary_bytes: usize, item_bytes: usize, body_bytes: usize, memory_tau_h: f64, freshness_base: f64, freshness_window: usize, people_full: usize, beat_tail_lines: usize, group_state: bool, group_lines: usize, group_bytes: usize, caps: PoolCaps]
|
||||
mind_body::projection::tuning: struct Tuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[projector: ProjectorTuning, persona: PersonaTuning, interpreter: InterpreterTuning, select: SelectTuning, lens: LensWeights, pronouns: BTreeMap < String , String >]
|
||||
mind_body::queue: fn on_hold (mind : & dyn MindPort) -> Result < Held >
|
||||
mind_body::queue: impl Held
|
||||
|
|
|
|||
Loading…
Reference in a new issue