Persona K57: the words gate holds a line sharing a run of ECHO_MIN_WORDS words with a held text; a draft past the room left is carried clipped to it
A candidate that shares a contiguous run of at least ECHO_MIN_WORDS words over span::tokens with any held text enters the room as that text (Soul s5 inverted: a part of a longer held draft said behind a lead-in). Cost under ruling k45-held-words-errs-toward-held. A carry past the room CARRIES_BYTES leaves, after other carries, is carried clipped to that room and reported in carries_full. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c27d54a4c7
commit
7dc537eb19
3 changed files with 68 additions and 14 deletions
|
|
@ -35,10 +35,10 @@ use super::read::{ReadRequest, answers, repo_name};
|
|||
pub(crate) const CLOSED_KEPT_DAYS: i64 = 7;
|
||||
/// How many reaffirmations, and how many reopenings, an entry keeps: the newest.
|
||||
const REAFFIRMED_KEPT: usize = 3;
|
||||
/// The most bytes of her own drafts one hold carries, all of them together (map 16.31.3, K51). Each draft is carried
|
||||
/// whole (K56): a clipped draft's tail would be no held text. Past it nothing new is carried and `carries_full` is
|
||||
/// reported: the oldest stay, since the text written right after the ask is the likeliest held thing. A draft longer
|
||||
/// than this alone, the first a hold carries, is carried clipped to it, and reported too.
|
||||
/// The most bytes of her own drafts one hold carries, all of them together (map 16.31.3, K51). Each draft that fits is
|
||||
/// carried whole (K56); the oldest stay, since the text written right after the ask is the likeliest held thing. A
|
||||
/// draft past the room left is carried clipped to that room and reported in `carries_full` (K57): its head is still
|
||||
/// held text. Once no room is left, nothing new is carried, and each is reported.
|
||||
const CARRIES_BYTES: usize = 9600;
|
||||
/// The fewest words a passage of her prose cited as evidence may be (section 4.1's `source_quote`).
|
||||
pub(crate) const PROSE_MIN_WORDS: usize = 4;
|
||||
|
|
@ -365,8 +365,8 @@ pub(crate) struct Applied {
|
|||
pub unheld: Vec<Value>,
|
||||
/// The decision's `carry` entries whose hold no open hold of hers answers (K45, K51): their words are carried nowhere.
|
||||
pub held_unrecorded: Vec<Value>,
|
||||
/// The `carry` entries a hold had no room left for under `CARRIES_BYTES` (K51): not carried, so that what it already
|
||||
/// carries stays.
|
||||
/// The `carry` entries a hold had no room left for whole under `CARRIES_BYTES` (K51, K57): carried clipped to the room
|
||||
/// left, or, with none, not carried, so that what it already carries stays.
|
||||
pub carries_full: Vec<Value>,
|
||||
}
|
||||
|
||||
|
|
@ -444,8 +444,8 @@ fn rehold(state: &mut Value, applied: &Applied) {
|
|||
/// Each entry of the decision's `carry` (map 16.31.3, K51), written to its hold after the holds this apply opened: every
|
||||
/// draft she did not send while the hold was open, and nothing else decides it. The hold's handle is a hold listed to the
|
||||
/// Interpreter (`h1`), or the line an open hold opened from (`q3`). Each text is carried whole, a duplicate (the same
|
||||
/// text under `span::fold`) is skipped, and past `CARRIES_BYTES` for the hold nothing new is carried and the entry is
|
||||
/// reported in `carries_full`. A handle no open hold answers carries nothing, and is reported. The decision proposes and
|
||||
/// text under `span::fold`) is skipped, and a text past the room `CARRIES_BYTES` leaves the hold is carried clipped to
|
||||
/// it, when the room holds a grapheme and the ellipsis, and the entry is reported in `carries_full`. A handle no open hold answers carries nothing, and is reported. The decision proposes and
|
||||
/// the commit writes.
|
||||
fn carry_held(state: &mut Value, record: &Value, applied: &mut Applied) {
|
||||
let decision = &record["interpreter"];
|
||||
|
|
@ -475,8 +475,9 @@ fn carry_held(state: &mut Value, record: &Value, applied: &mut Applied) {
|
|||
carries.push(json!(text));
|
||||
continue;
|
||||
}
|
||||
if carries.is_empty() {
|
||||
carries.push(json!(super::select::clip(text, CARRIES_BYTES)));
|
||||
let clipped = super::select::clip(text, CARRIES_BYTES.saturating_sub(used));
|
||||
if clipped.len() <= CARRIES_BYTES.saturating_sub(used) && clipped != "…" {
|
||||
carries.push(json!(clipped));
|
||||
}
|
||||
applied.carries_full.push(entry.clone());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1324,6 +1324,14 @@ fn same_words(a: &str, b: &str) -> bool {
|
|||
span::tokens(a).eq(span::tokens(b))
|
||||
}
|
||||
|
||||
/// Whether `a` and `b` share a run of at least `ECHO_MIN_WORDS` consecutive words over `span::tokens` (K57): a part of a
|
||||
/// longer held text said behind a lead-in, which the trigram share of neither side reaches.
|
||||
fn shares_run(a: &str, b: &str) -> bool {
|
||||
let (a, b): (Vec<String>, Vec<String>) = (span::tokens(a).collect(), span::tokens(b).collect());
|
||||
let runs: BTreeSet<&[String]> = b.windows(ECHO_MIN_WORDS).collect();
|
||||
a.windows(ECHO_MIN_WORDS).any(|run| runs.contains(run))
|
||||
}
|
||||
|
||||
/// A line or an addition of this answer as the words gate reads it (K56): the room it goes into, its draft, the holds it
|
||||
/// names, whether it is a line (only lines count toward `MAX_LINES`), and whether it is a candidate, one no refusal that
|
||||
/// does not depend on the gate took.
|
||||
|
|
@ -1376,8 +1384,9 @@ fn hold_for(held: &mut BTreeMap<(String, usize), Vec<Value>>, key: (String, usiz
|
|||
/// - what enters R, U(R), is every candidate into R, with her listed lines in R (`amendable`) posted after the held
|
||||
/// text's hold;
|
||||
/// - a held text h enters R when a candidate equals it, when it has at least `ECHO_MIN_WORDS` words and `ECHO_OVERLAP`
|
||||
/// of its trigrams are in U(R) joined, or when a candidate of at least `ECHO_MIN_WORDS` words has `ECHO_OVERLAP` of its
|
||||
/// trigrams in h, all over `span::tokens`. Then every candidate into R that equals h or shares a trigram with it is held
|
||||
/// of its trigrams are in U(R) joined, when a candidate of at least `ECHO_MIN_WORDS` words has `ECHO_OVERLAP` of its
|
||||
/// trigrams in h, or when a candidate shares a run of at least `ECHO_MIN_WORDS` consecutive words with h (K57), all
|
||||
/// over `span::tokens`. Then every candidate into R that equals h or shares a trigram with it is held
|
||||
/// under h's holds, and its text joins H(R) under the holds it is held for.
|
||||
///
|
||||
/// The candidates not held then go out in order, `MAX_LINES` lines at most, and every line past them is cut. A cut line
|
||||
|
|
@ -1387,7 +1396,8 @@ fn hold_for(held: &mut BTreeMap<(String, usize), Vec<Value>>, key: (String, usiz
|
|||
///
|
||||
/// Her listed lines are never held: they are already out, and only count toward the measure. What it cannot reach, by
|
||||
/// construction: a paraphrase (only naming holds it), a first instance, a held text under `ECHO_MIN_WORDS` split across
|
||||
/// lines, and a split across more than two wakes.
|
||||
/// lines, and a split across more than two wakes. What it costs (ruling `k45-held-words-errs-toward-held`): a line
|
||||
/// quoting `ECHO_MIN_WORDS` consecutive words of a held text is held, whatever else it says.
|
||||
fn held_gate(lines: &[GateLine], packet: &Packet, opening: &[(String, Option<String>)], found: &Drafts) -> Gate {
|
||||
let long = |text: &str| span::tokens(text).count() >= ECHO_MIN_WORDS;
|
||||
let rooms: BTreeSet<&str> = lines.iter().filter(|line| line.candidate).map(|line| line.into.as_str()).collect();
|
||||
|
|
@ -1431,7 +1441,7 @@ fn held_gate(lines: &[GateLine], packet: &Packet, opening: &[(String, Option<Str
|
|||
let listed = packet.amendable.iter().filter(|line| line.room == room && made.is_none_or(|made| line.at_ms.is_none_or(|posted| posted > made))).map(|line| line.text.as_str());
|
||||
// Her listed lines first, then this answer's: the order they reach the room.
|
||||
let union = listed.chain(into.iter().map(|draft| draft.text.as_str())).collect::<Vec<_>>().join("\n");
|
||||
let enters = into.iter().any(|draft| same_words(&draft.text, &h.text) || (long(&draft.text) && heard_overlap(&draft.text, &h.text) >= ECHO_OVERLAP)) || (long(&h.text) && heard_overlap(&h.text, &union) >= ECHO_OVERLAP);
|
||||
let enters = into.iter().any(|draft| same_words(&draft.text, &h.text) || (long(&draft.text) && heard_overlap(&draft.text, &h.text) >= ECHO_OVERLAP) || shares_run(&draft.text, &h.text)) || (long(&h.text) && heard_overlap(&h.text, &union) >= ECHO_OVERLAP);
|
||||
if enters {
|
||||
for draft in into.iter().filter(|draft| same_words(&draft.text, &h.text) || heard_overlap(&draft.text, &h.text) > 0.0) {
|
||||
changed |= hold_for(&mut held, (room.to_owned(), draft.n), &h.askers);
|
||||
|
|
|
|||
|
|
@ -2803,6 +2803,49 @@ fn k56_a_draft_past_carries_bytes_is_carried_clipped_and_reported() {
|
|||
assert_eq!(applied.carries_full.iter().filter_map(|entry| entry["text"].as_str()).collect::<Vec<_>>(), [huge.as_str(), "Meta, holding it."], "{applied:?}");
|
||||
}
|
||||
|
||||
/// Soul's `soul_s5`, inverted (K57): the tail of a longer carried draft said behind "Kiko, here it is:" is held. Neither
|
||||
/// trigram share reaches `ECHO_OVERLAP`; the run of words it shares with the held text does.
|
||||
#[test]
|
||||
fn k57_soul_s5_a_tail_behind_a_lead_in_is_held() {
|
||||
let head = "Line one says hello to everyone here. ".repeat(32);
|
||||
let tail = "The secret second line points newcomers at the vault behind the old forge door.";
|
||||
let draft = format!("{head}{tail}");
|
||||
let (_, p2) = held_then_kiko_asks(&[draft.as_str()]);
|
||||
let d = answered(&p2, &format!("Kiko asked. <typed>Kiko, here it is: {tail}</typed>"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] }));
|
||||
assert!(held_for_meta(&d), "{d}");
|
||||
}
|
||||
|
||||
/// The run's length, pinned both ways (K57): a line sharing seven consecutive words of the held welcome, and no trigram
|
||||
/// share reaching `ECHO_OVERLAP`, goes out; the same line sharing eight is held, its apostrophes curly and its case
|
||||
/// changed, since the run is counted over `span::tokens`.
|
||||
#[test]
|
||||
fn k57_a_run_of_eight_shared_words_is_held_and_seven_is_not() {
|
||||
let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]);
|
||||
let seven = "Kiko, hello and welcome, we're glad you're here, but the forge opens tomorrow at noon.";
|
||||
let d = answered(&p2, &format!("Kiko asked. <typed>{seven}</typed>"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] }));
|
||||
assert_eq!(texts(&d), [seven], "{d}");
|
||||
let eight = "Kiko, HELLO and welcome, we\u{2019}re glad you\u{2019}re here, poke the forge tomorrow at noon.";
|
||||
let d = answered(&p2, &format!("Kiko asked. <typed>{eight}</typed>"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] }));
|
||||
assert!(held_for_meta(&d), "{d}");
|
||||
}
|
||||
|
||||
/// A draft past the room `CARRIES_BYTES` leaves, arriving after another carry, is carried clipped to that room and
|
||||
/// reported in `carries_full`, never dropped (K57).
|
||||
#[test]
|
||||
fn k57_a_draft_past_the_room_left_is_carried_clipped_to_it() {
|
||||
let first = "Meta, I will keep the welcome back until Kiko asks.";
|
||||
let huge = format!("Draft two: {}", "welcome ".repeat(1300).trim_end());
|
||||
let prose = format!("Meta asked me to hold it. <typed>{first}</typed> <typed>{huge}</typed>");
|
||||
let decision = answered(&x1_packet(), &prose, json!({ "say": [], "gaps": [], "hold": meta_holds_here() }));
|
||||
let (state, applied) = committed(&decision, &prose);
|
||||
let carries = carries_of(&state);
|
||||
assert_eq!(carries.len(), 2, "{carries:?}");
|
||||
assert_eq!(carries[0], first);
|
||||
let room = 9600 - first.len();
|
||||
assert!(carries[1].starts_with("Draft two: welcome") && carries[1].ends_with('\u{2026}') && carries[1].len() <= room && carries[1].len() > room - 8, "{}", carries[1].len());
|
||||
assert_eq!(applied.carries_full.iter().filter_map(|entry| entry["text"].as_str()).collect::<Vec<_>>(), [huge.as_str()], "{applied:?}");
|
||||
}
|
||||
|
||||
/// Two holds cover #minds, Meta's and Kiko's, both opened while the welcome went unsent: it is carried under each, and
|
||||
/// its repeat next turn is held for both, and she is told each asker. This pins Soul's surviving mutant
|
||||
/// `s-first-covering-hold-is-last`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue