Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/continuum-cognition/src/cognition/context_streams/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ impl Source<ContextMessage> for Actions<'_> {
Some(ContextMessage::user(format!("{label}{body}")))
}

/// Her oldest acts as one line: the first and last `#n`, how many, and how one reopens
/// (`tool/output` with `act`), so her floor is one block however many acts she has taken
/// (Aris, the M5, 2026-10-29: 95 pointers at ~190 chars before anything whole fit). Reads
/// only the run's ends: the banner, when it is in the run, is its first item and folds
/// with it. `None` for a run with no act in it (the banner alone): nothing to name.
fn fold(&self, folded: &[Item<ContextMessage>]) -> Option<ContextMessage> {
// The banner stands as itself ahead of the run (the view never folds a standing head),
// so the run is her acts alone, keyed by their #n.
let first: u64 = folded.first()?.key.parse().ok()?;
let last: u64 = folded.last()?.key.parse().ok()?;
let count = folded.len();
Some(ContextMessage::user(format!(
"[actions #{first}-#{last}: {count} earlier acts folded; reopen one with tool/output act=<n>]"
)))
}

/// Once she has acted, the void said earlier in this epoch is superseded, never edited:
/// her view reads as the timeline it is (the statement was true when it was made).
fn retired(&self) -> Vec<Item<ContextMessage>> {
Expand Down
16 changes: 16 additions & 0 deletions core/continuum-cognition/src/cognition/context_streams/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,19 @@ fn a_thought_renders_the_same_whatever_the_served_window() {
memory.set_served_window(131_072);
assert_eq!(render(&memory), narrow, "the window changed and the thought's rendering did not");
}

// what this catches: her floor growing with every act she ever took (Aris, the M5, 2026-10-29:
// 95 pointers at ~190 chars before anything whole fit). Her oldest acts fold into ONE line that
// names the first and last #n, how many, and how one reopens (tool/output act=<n>), never a list
// of ids. The banner stands ahead of the run (the view never folds a standing head), so the
// run is acts alone; a run whose keys are not act numbers names nothing rather than a guess.
#[test]
fn her_folded_acts_name_their_range_and_count_in_one_line() {
let memory = WorkingMemory::new(2);
let actions = Actions { memory: &memory, persona: uuid::Uuid::nil() };
let item = |key: &str| continuum_context::source::Item::whole(key, super::ContextMessage::user(format!("act {key}")));
let run: Vec<_> = (3200..=3330).map(|seq: u64| item(&seq.to_string())).collect();
let Some(block) = actions.fold(&run) else { panic!("a run with acts folds") };
assert_eq!(block.text, "[actions #3200-#3330: 131 earlier acts folded; reopen one with tool/output act=<n>]");
assert!(actions.fold(&[item("banner")]).is_none(), "a run that is not acts names nothing");
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl LlmDeliberationFaculty {

/// Her view's sources as claims in the window's one allocation, each `view/<source>`,
/// priced in the unit the final fit charges ([`Self::message_cost`], template overhead
/// included): floor = the source collapsed, want = the source whole, at the source's
/// included): floor = the source folded or collapsed, want = the source whole, at the source's
/// priority. There is no separate history claim for the view, so the allocation that
/// weighs her reply also decides, once, how much of her context she reads.
pub(in super::super) fn view_claims(&self, streams: &Streams) -> Vec<crate::cognition::rag_budget::RagSourceBudget> {
Expand All @@ -63,7 +63,9 @@ impl LlmDeliberationFaculty {
.map(|source| {
let items = source.items();
let cost = |message: &ContextMessage| Self::message_cost(&message.to_chat());
let floor: usize = items.iter().map(|item| item.pointer.as_ref().map_or(0, cost)).sum(); // map_or: an item that leaves when collapsed costs nothing
// Its floor from the view's one owner: one fold block when the source folds its
// oldest run, else each item's pointer, so the allocation prices the true floor.
let floor = continuum_context::view::floor(source, &items, cost);
// An item's WHOLE level, stored or resident (`whole_chars`): a body evicted from RAM
// is priced from its measured size, never as the pointer resident in its place,
// or the allocation would never grant room to see it (FOCUS-CONTRACT rule 7).
Expand Down Expand Up @@ -313,6 +315,7 @@ impl LlmDeliberationFaculty {
epoch = start.epoch,
start_chars = start.chars,
collapsed_items = start.collapsed,
folded_items = start.folded,
"her view started a new epoch: the one re-prefill an epoch costs, collapsed \
by the flexbox at its start"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl LlmDeliberationFaculty {
}
let Some(memory) = self.working_memory.as_ref() else { return false };
let Some((seq, _)) = memory.active_action_full() else { return false };
let Some(handle) = memory.saved_handle(seq) else {
let Ok(handle) = memory.saved_handle(seq) else {
continuum_base::probe!(
class = "delib.newest_result.unsaved_over_window",
persona = %self.persona_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fn window_plan(claims: &[Claim], window: u32) -> FlexAllocation {
.map(|claim| RagSourceBudget {
source_id: format!("view/{}", claim.source),
priority: claim.priority,
floor_tokens: claim.pointer_chars as u32,
min_tokens: claim.pointer_chars as u32,
floor_tokens: claim.floor_chars as u32,
min_tokens: claim.floor_chars as u32,
max_tokens: claim.full_chars as u32,
required: false,
})
Expand Down
7 changes: 5 additions & 2 deletions core/continuum-cognition/src/cognition/open_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ impl OpenViews {
/// touches that file's view: its line numbers are the saved result's, which open with a
/// header line, not the file's.
fn note_output_page(&mut self, act: &Observation, seq: u64) -> bool {
let Some(handle) = act.call.input.get("outputId").and_then(|v| v.as_str()) else {
let header = crate::cognition::tool_executor::spill::result_scalars(&act.output.result.content);
// The output she named, or, for a call by act number, the one the result echoes.
let named = act.call.input.get("outputId").and_then(|v| v.as_str());
let echoed = header.as_ref().and_then(|h| h.get("outputId")?.as_str());
let Some(handle) = named.or(echoed) else {
return false;
};
let Some(index) = self.views.iter().position(|v| {
Expand All @@ -175,7 +179,6 @@ impl OpenViews {
let mut view = self.views.remove(index);
view.touched_seq = seq;
if act.completed_successfully() && matches!(view.subject, ViewSubject::Output { .. }) {
let header = crate::cognition::tool_executor::spill::result_scalars(&act.output.result.content);
let total = header.as_ref().and_then(|h| h.get("totalLines")?.as_u64()).and_then(|n| u32::try_from(n).ok());
let truncated = header.as_ref().and_then(|h| h.get("truncated")?.as_bool()).unwrap_or(true); // unwrap_or: a page that does not say it came back whole is not counted as read
let line = |key: &str| act.call.input.get(key)?.as_u64().and_then(|n| u32::try_from(n).ok());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::cognition::rag_budget::RagSource;
/// owner's schema, native path, and cross-process checkpoint exclusion.
pub mod checkpoint_adoption;

mod act_output;
mod rehome;
pub use rehome::RehomeReason;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! A resident's act number resolved to its saved output, for `tool/output` called with `act`.
//! Her folded acts name only their range ("#a-#b"), so the number is the handle she holds.

use std::sync::Arc;

use uuid::Uuid;

use super::PersonaWorkspaceRegistry;
use crate::cognition::working_memory::ActOutputRefusal;

impl PersonaWorkspaceRegistry {
/// The saved-output handle of `persona`'s act `act`, through her public cycle's working
/// memory, the record her view's actions source numbers. Her mind cycle keeps its own
/// record and is not consulted: its acts are not in the view that folds them.
pub fn act_output_handle(&self, persona: Uuid, act: u64) -> Result<String, ActOutputRefusal> {
let memory = self
.cycles
.lock()
.get(&persona)
.map(|resident| Arc::clone(&resident.working_memory));
memory
.ok_or(ActOutputRefusal::NoResident { act })?
.saved_handle(act)
}
}
1 change: 1 addition & 0 deletions core/continuum-cognition/src/cognition/working_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ mod ledger;
mod perception;
mod residency;

pub use action_log::ActOutputRefusal;
pub use faculty::WorkingMemoryFaculty;
pub(crate) use faculty::render_dispatched;
pub(crate) use ledger::operation_level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ use uuid::Uuid;
/// handle keeps it live and stays in the log (`receipt_keys`, `prune`).
const POINTER_INDEX: usize = 12;

/// Why an act number does not reopen a saved output (`tool/output` with `act`): a typed
/// refusal naming the act, never a fallback to some other output.
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
pub enum ActOutputRefusal {
/// No record of hers carries this number.
#[error("act #{act} is not on your record; use a #n your view names")]
Unknown { act: u64 },
/// The act is on record but its save failed: what her view showed of it is all there is.
#[error("act #{act} has no saved output: its save failed, so what your view showed of it is all there is")]
Unsaved { act: u64 },
/// The caller has no resident mind whose record could resolve the number.
#[error("act #{act} cannot be resolved: no resident mind runs for this caller")]
NoResident { act: u64 },
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub(crate) struct ActionRecord {
pub seq: u64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ impl WorkingMemory {
format!("Full result of your most recent action ({attribution}):\n{full}")
}

/// The handle the saved whole of act `seq` is reopened by (`tool/output`), `None` when its
/// save failed: such a result has no other copy, so it is never shown as less than whole.
pub(crate) fn saved_handle(&self, seq: u64) -> Option<String> {
self.actions.lock().get(seq).and_then(|record| record.handle.clone())
/// The handle the saved whole of act `seq` is reopened by (`tool/output`, by handle or by
/// `act`): the one resolution of an act number to its saved output. A refusal when no
/// record carries `seq`, or when its save failed: such a result has no other copy, so it
/// is never shown as less than whole.
pub fn saved_handle(&self, seq: u64) -> Result<String, ActOutputRefusal> {
let actions = self.actions.lock();
let record = actions.get(seq).ok_or(ActOutputRefusal::Unknown { act: seq })?;
record.handle.clone().ok_or(ActOutputRefusal::Unsaved { act: seq })
}

/// The provenance of the act whose native results the turn carries: `[result #n; room …;
Expand Down
2 changes: 1 addition & 1 deletion core/continuum-context/examples/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn item(key: String, text: String) -> Item<String> {
/// goes to sources by priority level, highest first, sources of one level sharing in
/// proportion to what each wants. (In the core this is `flex_allocate`.)
fn allocate(claims: &[continuum_context::view::Claim], budget: usize) -> Vec<usize> {
let mut grants: Vec<usize> = claims.iter().map(|claim| claim.pointer_chars).collect();
let mut grants: Vec<usize> = claims.iter().map(|claim| claim.floor_chars).collect();
let mut spare = budget.saturating_sub(grants.iter().sum());
let mut levels: Vec<u8> = claims.iter().map(|claim| claim.priority).collect();
levels.sort_unstable_by(|a, b| b.cmp(a));
Expand Down
10 changes: 10 additions & 0 deletions core/continuum-context/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ pub trait Source<T: Block> {
fn load(&self, _item: &Item<T>) -> Option<T> {
None
}

/// One block standing for `folded`, the contiguous oldest run of this source's items at a
/// start: the range it covers and how to reopen one, its length independent of the run's
/// (never a list of ids). It reads only the run's ends, O(1) in the run: a start asks once
/// per item it raises. The view folds the run only when this block is smaller than the
/// run's pointers, so a source's floor stops growing with every item it ever held. Fixed
/// for the epoch it starts. The default cannot fold: its items floor at their pointers.
fn fold(&self, _folded: &[Item<T>]) -> Option<T> {
None
}
}

/// What an item's whole level costs: its stored size when the whole is not resident, else
Expand Down
Loading
Loading