Persona search: keep her words and drop the rest; the Interpreter is shown the reads refused earlier
Soul's R8 item 1 (F.2: Heimdall's "I open the merge pages PR" with q=Merge pages and notices was refused four times). A search whose query has words she never wrote is no longer refused: it keeps, in the query's order, the words carrying content that her prose has, and searches with those (q=merge pages). Only a query with none of hers left is refused. The conversation carries every refused read as `kind target (why)`, and the Interpreter's read frame lists those and the ones refused earlier this wake, so it does not name the same refused read again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4c9f07243
commit
6c2b51f84c
6 changed files with 77 additions and 18 deletions
|
|
@ -39,6 +39,14 @@ pub(crate) struct Exchange {
|
|||
pub(crate) tried: Vec<Tried>,
|
||||
/// When the conversation began: her first turn in it. What she closed since is still listed (Soul's R7).
|
||||
pub(crate) since: Option<DateTime<Utc>>,
|
||||
/// Every read refused in it, as `kind target (why)`, once each: shown to the Interpreter so it never names the same
|
||||
/// refused read again (Soul's R8).
|
||||
pub(crate) refused: Vec<String>,
|
||||
}
|
||||
|
||||
/// A refused read as the Interpreter is shown it: `kind target (why)`.
|
||||
pub(crate) fn refused_read(refused: &Value) -> String {
|
||||
format!("{} {} ({})", refused["read"]["kind"].as_str().unwrap_or("?"), refused["read"]["target"].as_str().unwrap_or("?").trim(), refused["why"].as_str().unwrap_or("?"))
|
||||
}
|
||||
|
||||
/// A read's latest result as her view shows it.
|
||||
|
|
@ -96,6 +104,11 @@ pub(crate) fn exchange_of(records: &[Value], room: &str, now: DateTime<Utc>, her
|
|||
.collect();
|
||||
exchange.lines.push(Did { at: *at, text: format!("- {}{reply}: {}{}", coarse(*at, now), spoken(text), added.join("")) });
|
||||
}
|
||||
for refused in decision["read_refused"].as_array().into_iter().flatten().map(refused_read) {
|
||||
if !exchange.refused.contains(&refused) {
|
||||
exchange.refused.push(refused);
|
||||
}
|
||||
}
|
||||
for read in decision["reads"].as_array().into_iter().flatten() {
|
||||
let Ok(request) = serde_json::from_value::<ReadRequest>(read["request"].clone()) else { continue };
|
||||
let found = read["ok"] == true;
|
||||
|
|
|
|||
|
|
@ -66,3 +66,12 @@ fn r7_a_not_found_read_is_remembered_and_a_broken_one_is_not() {
|
|||
let exchange = exchange_of(&[turn(10, MINDS, &[], json!([missing, broken]), json!([]), json!([]))], MINDS, now(), her());
|
||||
assert_eq!(exchange.tried, [Tried { key: "repo:gamecult/bifrost?q=consent receipt".into(), found: false, what: "a search".into() }]);
|
||||
}
|
||||
|
||||
/// Soul's R8: the reads refused in the conversation are carried, once each, as `kind target (why)`.
|
||||
#[test]
|
||||
fn r8_the_conversation_carries_its_refused_reads() {
|
||||
let mut record = turn(10, MINDS, &[], json!([]), json!([]), json!([]));
|
||||
record["interpreter"]["read_refused"] = json!([{ "read": { "kind": "repo", "target": "GameCult/Bifrost?q=Merge pages and notices" }, "why": "search_words_not_in_her_thought" }]);
|
||||
let exchange = exchange_of(&[record.clone(), record], MINDS, now(), her());
|
||||
assert_eq!(exchange.refused, ["repo GameCult/Bifrost?q=Merge pages and notices (search_words_not_in_her_thought)"]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -410,12 +410,13 @@ struct Proposed {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn speech_prompt(packet: &Packet, narration: &str, prose: &str, tuning: &Tuning) -> String {
|
||||
speech_prompt_in(packet, narration, prose, tuning, "", &drafts(prose))
|
||||
speech_prompt_in(packet, narration, prose, tuning, "", &drafts(prose), &[])
|
||||
}
|
||||
|
||||
/// The speech prompt for one segment of her wake: `prose` is the new segment, `before` her earlier segments and the
|
||||
/// bridges between them (none on her first), and `found` the drafts this call may send, numbered across the wake.
|
||||
pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tuning: &Tuning, before: &str, found: &Drafts) -> String {
|
||||
/// bridges between them (none on her first), `found` the drafts this call may send, numbered across the wake, and
|
||||
/// `wake_refused` the reads refused by this wake's earlier calls.
|
||||
pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tuning: &Tuning, before: &str, found: &Drafts, wake_refused: &[Value]) -> String {
|
||||
let her = packet.forms;
|
||||
let mut people = String::new();
|
||||
for (label, id) in &packet.people {
|
||||
|
|
@ -471,7 +472,16 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu
|
|||
// What she can read, and how to name it, only when this turn can read (map 16.22.3); and what is already in her view,
|
||||
// not to be read again (K26).
|
||||
let in_view = if packet.already_read.is_empty() { String::new() } else { format!(" Already read in this conversation, so never named as a read: {}.", packet.already_read.iter().map(|tried| if tried.found { tried.what.clone() } else { format!("{} (nothing was there)", tried.what) }).collect::<Vec<_>>().join("; ")) };
|
||||
let reading = if packet.affordances.contains(&Affordance::Read) { format!("{}{in_view}\n\n", read_frame(her)) } else { String::new() };
|
||||
// The reads refused earlier in this conversation and this wake, with why, so the same refused read is never named
|
||||
// again (Soul's R8).
|
||||
let mut refused: Vec<String> = packet.refused_reads.clone();
|
||||
for read in wake_refused.iter().map(crate::projection::exchange::refused_read) {
|
||||
if !refused.contains(&read) {
|
||||
refused.push(read);
|
||||
}
|
||||
}
|
||||
let refused = if refused.is_empty() { String::new() } else { format!(" Refused earlier, so never named again as it was: {}.", refused.join("; ")) };
|
||||
let reading = if packet.affordances.contains(&Affordance::Read) { format!("{}{in_view}{refused}\n\n", read_frame(her)) } else { String::new() };
|
||||
// Her earlier segments this wake, already decided on: context, never hers to send again.
|
||||
// Her earlier segments this wake and what she read between them. Her drafts are numbered across the whole moment, and
|
||||
// a draft from earlier is sent only if nothing she wrote after it says it is superseded or wrong (Soul's R6).
|
||||
|
|
@ -533,7 +543,7 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra
|
|||
pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, narration: &str, prose: &str, tuning: &Tuning, wake: Wake) -> Value {
|
||||
let found = drafts(prose);
|
||||
let segment = prose.get(wake.from..).unwrap_or_default();
|
||||
let answer = match model.ask(request_id, &tuning.interpreter.model, &speech_prompt_in(packet, narration, segment, tuning, wake.before, &found), Some(SPEECH_SCHEMA)) {
|
||||
let answer = match model.ask(request_id, &tuning.interpreter.model, &speech_prompt_in(packet, narration, segment, tuning, wake.before, &found, &wake.earlier.and_then(|earlier| earlier["read_refused"].as_array()).cloned().unwrap_or_default()), Some(SPEECH_SCHEMA)) {
|
||||
Ok(answer) => answer,
|
||||
Err(failed) => return json!({ "failed": failed.reason, "usage": failed.usage }),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -839,7 +839,7 @@ fn r6_a_draft_the_later_prose_supersedes_is_not_sent() {
|
|||
/// The prompt a decision on `wake` sends.
|
||||
fn model_prompt(packet: &Packet, prose: &str, wake: Wake) -> String {
|
||||
let found = drafts(prose);
|
||||
speech_prompt_in(packet, "The room is warm.", &prose[wake.from..], &Tuning::default(), wake.before, &found)
|
||||
speech_prompt_in(packet, "The room is warm.", &prose[wake.from..], &Tuning::default(), wake.before, &found, &[])
|
||||
}
|
||||
|
||||
/// Soul's p1b: an address that stands only in a page she read is not in front of her, so no read chains from a read.
|
||||
|
|
@ -960,7 +960,11 @@ fn r7_recall_and_search_words_are_her_own_whole_words() {
|
|||
}
|
||||
let search = |words: &str| asked(&reading, prose, json!({ "kind": "repo", "target": format!("GameCult/Bifrost?q={words}"), "quote": "I want to find the Bifrost change" }));
|
||||
assert!(search("consent receipt")["read_refused"].is_null(), "{}", search("consent receipt"));
|
||||
for bad in ["consent rec", "the about", "consent signature"] {
|
||||
// Soul's R8: words she never wrote are dropped, hers kept; only a query with none of hers left is refused.
|
||||
for (asked_for, searched) in [("consent rec", "consent"), ("consent signature", "consent"), ("Receipt CONSENT", "receipt consent")] {
|
||||
assert_eq!(search(asked_for)["read"]["request"]["target"], format!("GameCult/Bifrost?q={searched}"), "{asked_for}");
|
||||
}
|
||||
for bad in ["the about", "signature gate"] {
|
||||
assert_eq!(search(bad)["read_refused"][0]["why"], "search_words_not_in_her_thought", "{bad}");
|
||||
}
|
||||
}
|
||||
|
|
@ -990,3 +994,18 @@ fn r7_a_promise_needs_only_a_repo_in_her_prose_or_view() {
|
|||
assert_eq!(invented["promise_to_dropped"][0]["needs"], "GameCult/Nowhere#3", "{invented}");
|
||||
assert!(invented["state"].as_array().into_iter().flatten().all(|p| p["needs"].is_null()), "{invented}");
|
||||
}
|
||||
|
||||
/// Soul's R8 (F.2, Heimdall): a search keeps her words and drops the rest; the reads refused earlier in the wake and the
|
||||
/// conversation are listed for the Interpreter, with why, so it never names the same refused read again.
|
||||
#[test]
|
||||
fn r8_a_search_keeps_her_words_and_refused_reads_are_listed() {
|
||||
let reading = reading_packet();
|
||||
let prose = "So I open the merge pages PR and read it before I answer.";
|
||||
let read = asked(&reading, prose, json!({ "kind": "repo", "target": "GameCult/Bifrost?q=Merge pages and notices", "quote": "So I open the merge pages PR" }));
|
||||
assert_eq!(read["read"]["request"], json!({ "kind": "repo", "target": "GameCult/Bifrost?q=merge pages" }), "{read}");
|
||||
let mut seen = reading_packet();
|
||||
seen.refused_reads = vec!["repo GameCult/Bifrost?q=sign-in gate (search_words_not_in_her_thought)".into()];
|
||||
let wake_refused = [json!({ "read": { "kind": "repo", "target": "GameCult/Lodur#3", "quote": "x" }, "why": "quote_not_located" })];
|
||||
let prompt = speech_prompt_in(&seen, "x", prose, &Tuning::default(), "", &drafts(prose), &wake_refused);
|
||||
assert!(prompt.contains(" Refused earlier, so never named again as it was: repo GameCult/Bifrost?q=sign-in gate (search_words_not_in_her_thought); repo GameCult/Lodur#3 (quote_not_located)."), "{prompt}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,16 +295,21 @@ pub(crate) fn resolve(asked: &Asked, packet: &Packet, prose: &str, reached: &[St
|
|||
// A digest id resolves only as a domain item, never inside a repo target (`GameCult/Bifrost#d3`, Soul's R5).
|
||||
// A search's words must stand in her prose (map 16.24.3), as a quote must.
|
||||
Kind::Repo => match repo_target(target) {
|
||||
// A search is by whole words of her prose, at least one that carries content (Soul's R7).
|
||||
Some(target)
|
||||
if target.split_once("?q=").is_some_and(|(_, words)| {
|
||||
let (words, said) = (word_tokens(words), word_tokens(prose));
|
||||
!words.iter().all(|word| said.contains(word)) || !words.iter().any(|word| content(word))
|
||||
}) =>
|
||||
{
|
||||
Err("search_words_not_in_her_thought")
|
||||
}
|
||||
Some(target) => Ok(ReadRequest::Repo(target)),
|
||||
// A search is by her own words (Soul's R8): the query keeps, in its order, the words carrying content that her
|
||||
// prose has, and searches with those; only when none remain is it refused.
|
||||
Some(target) => match target.split_once("?q=") {
|
||||
Some((repo, words)) => {
|
||||
let said = word_tokens(prose);
|
||||
let mut kept: Vec<String> = Vec::new();
|
||||
for word in word_tokens(words).into_iter().filter(|word| content(word) && said.contains(word)) {
|
||||
if !kept.contains(&word) {
|
||||
kept.push(word);
|
||||
}
|
||||
}
|
||||
if kept.is_empty() { Err("search_words_not_in_her_thought") } else { Ok(ReadRequest::Repo(format!("{repo}?q={}", kept.join(" ")))) }
|
||||
}
|
||||
None => Ok(ReadRequest::Repo(target)),
|
||||
},
|
||||
None if target.to_lowercase().starts_with("gamecult/") || digest_id(target) => Err("malformed_target"),
|
||||
None => Err("not_a_gamecult_repo"),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -358,6 +358,8 @@ pub(crate) struct Packet {
|
|||
/// Every read she made in this conversation, shown or not, found or not (K26, Soul's R7): never made again, and
|
||||
/// marked for the Interpreter.
|
||||
pub already_read: Vec<exchange::Tried>,
|
||||
/// The reads refused in this conversation, as `kind target (why)` (Soul's R8): for the Interpreter, never named again.
|
||||
pub refused_reads: Vec<String>,
|
||||
/// What came of her last turn that the outcome's guard left out, whole: counted in the packet's last outcome line and
|
||||
/// reported here (map 16.20.5, I16.11), never shown to a model.
|
||||
pub unshown: Vec<String>,
|
||||
|
|
@ -2237,9 +2239,10 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
// Her side of the conversation, between her promises and her domain (map 16.24.1).
|
||||
let exchange_view = inputs.exchange.map(|exchange| exchange::render(exchange, her, tuning.select.exchange_bytes, inputs.now)).unwrap_or_default();
|
||||
let already_read = inputs.exchange.map(|exchange| exchange.tried.clone()).unwrap_or_default();
|
||||
let refused_reads = inputs.exchange.map(|exchange| exchange.refused.clone()).unwrap_or_default();
|
||||
let in_view = [promises_view.as_str(), exchange_view.as_str(), domain_view.as_str()].into_iter().filter(|part| !part.is_empty()).collect::<Vec<_>>().join("\n\n");
|
||||
let mut sections = context.sizes();
|
||||
(sections.promises, sections.domain) = (promises_view.len(), domain_view.len());
|
||||
let now_ms = u64::try_from(inputs.now.timestamp_millis()).unwrap_or_default();
|
||||
Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections, stimulus, heard, bridged, 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, amendable, quotable, promises, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown }
|
||||
Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections, stimulus, heard, bridged, 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, amendable, quotable, promises, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, refused_reads, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue