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
11 changes: 7 additions & 4 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| **Status** | Adopted |
| **Scope** | `web/admin/` (the runtime admin console). The Settings WebApp (`web/settings/`, Framework7 + Telegram theme) is explicitly out of scope. |
| **Owners** | OpenPlotva maintainers |
| **Last updated** | 2026-08-03 |
| **Last updated** | 2026-10-11 |
| **Source of truth** | `web/admin/tokens.css`, `web/admin/components.css`, `web/admin/components.js` |
| **Enforced by** | guard tests in `crates/openplotva-web/src/lib.rs`; the `openplotva-design-system-review` skill |
| **Related** | `AGENTS.md` (§ Web UI / Design System), `docs/admin-ux-audit.md`, `skills/openplotva-design-system-review/SKILL.md` |
Expand Down Expand Up @@ -111,11 +111,12 @@ Three tiers. Components reference **only** the semantic/extended tiers.
|---|---|---|---|
| Primitive | `--p-*` | Raw, theme-agnostic palette. Never referenced by components. | `--p-slate-900`, `--p-indigo-500`, `--p-cyan-400`, `--p-red-500` |
| Semantic | `--c-*`, `--sp-*`, `--rad-*`, `--fs-*`, `--fw-*`, `--lh-*`, `--elev-*`, `--dur-*`, `--ease-*`, `--z-*` | Meaning-based aliases — the vocabulary components use. | `--c-bg-card`, `--c-primary`, `--c-danger`, `--c-text-main`, `--c-focus-ring`, `--sp-4`, `--rad-md`, `--fs-base`, `--elev-2`, `--z-modal` |
| Extended | `--c-json-*`, `--c-log-*`, `--c-status-*`, `--c-shield-*`, `--c-cardtype-*`, `--c-relation-*`, `--c-visibility-*`, `--c-ent-*`, `--c-role-*`, `--c-slot-*`, `--grad-*` | Domain palettes (syntax highlighting, log levels, status dots, shield categories, memory card-type/relation/visibility categories, routing entity/role/slot categories, brand gradients). | `--c-log-error`, `--c-status-ok`, `--c-shield-red`, `--c-cardtype-event`, `--c-relation-contradicts`, `--c-ent-pool`, `--c-role-overflow`, `--c-slot-busy`, `--grad-brand` |
| Extended | `--c-json-*`, `--c-log-*`, `--c-status-*`, `--c-shield-*`, `--c-cardtype-*`, `--c-relation-*`, `--c-visibility-*`, `--c-ent-*`, `--c-role-*`, `--c-slot-*`, `--c-flow-*`, `--c-step-*`, `--grad-*` | Domain palettes (syntax highlighting, log levels, status dots, shield categories, memory card-type/relation/visibility categories, routing entity/role/slot categories, LLM run kinds and run-timeline step kinds — one hue per actor: model, tools, people, memory, runtime — brand gradients). | `--c-log-error`, `--c-status-ok`, `--c-shield-red`, `--c-cardtype-event`, `--c-relation-contradicts`, `--c-ent-pool`, `--c-role-overflow`, `--c-slot-busy`, `--grad-brand` |

Token families:

- **Color** — surfaces (`--c-bg-app/sidebar/card/card-hover/input/elevated`), borders, brand
- **Color** — surfaces (`--c-bg-app/sidebar/card/card-hover/input/elevated`, plus `--c-bg-raised` for a
block raised inside a card, distinct from the card in both themes), borders, brand
(`--c-primary`, `--c-primary-hover`, `--c-accent`), state (`--c-success/warning/danger/info`) with
tinted-surface variants (`--c-*-bg`, `--c-*-bg-strong`, derived via `color-mix`), text
(`--c-text-main/sec/muted/on-primary`), and interaction (`--c-focus-ring`, `--c-scrim`,
Expand All @@ -126,7 +127,7 @@ Token families:
weights `--fw-normal … --fw-extrabold`; line-heights `--lh-tight/snug/normal`.
- **Elevation** — `--elev-0 … --elev-3`, `--elev-modal`, `--elev-glow-brand`.
- **Motion** — `--dur-instant/quick/base`, `--ease-out`; legacy aliases `--trans-fast/norm`.
- **Z-index** — a named ladder `--z-base/resizer/sidebar/mobile-sidebar/dropdown/overlay/modal/toast`
- **Z-index** — a named ladder `--z-base/resizer/sticky/sidebar/mobile-sidebar/dropdown/overlay/modal/toast`
(formalizes the old `5/10/100/9999` magic numbers).
- **Layout** — `--w-sidebar`, `--h-header`.

Expand Down Expand Up @@ -155,6 +156,8 @@ working — tokens were only added, never renamed.
| `pl-timeline` | — (bitemporal) | JS prop `data = {lanes:[{key,label}], items:[{id,lane,label,card_type,validFrom,validUntil,recordedAt,status,competing}], now, asOf}`; emits `pl:item-click {id}`, `pl:asof-change {date}` | SVG swimlanes; valid bars, recorded markers, superseded muted, competing ring, now + as-of lines; click-to-set as-of; `role=img` |
| `pl-slotbar` | — (pool occupancy) | attrs/props `capacity` (int; absent = unlimited), `busy`, `blocked`, `size=mini\|card\|cockpit`; pure renderer, re-renders on attribute change | discrete cells (`--c-slot-busy/free/blocked`) when capacity ≤ 16, continuous bar + `busy/capacity` text otherwise; `role=img` + "N of M slots busy" label; busy pulse gated behind `prefers-reduced-motion: no-preference` |
| `pl-flow` | — (routing DAG) | JS prop `data = {nodes:[{id,kind:workflow\|model\|provider\|pool,label,state?,badge?}], edges:[{from,to,kind:primary\|fallback\|overflow\|canary\|shadow\|attach,weight?,order?,engaged?}]}`; emits `pl:node-click {id,kind}` | deterministic layered layout (fixed columns by kind), cubic bezier edges stroked by `--c-role-*` (width ∝ weight, overflow dashed unless engaged), nodes tinted by `--c-ent-*` with breaker/capacity state rings; nodes focusable (`tabindex=0`, Enter activates); horizontal scroll container |
| `pl-disclosure` | ad-hoc ghost-button toggles + hidden bodies | `PL.disclosure({summary, meta, open, render, content, className})`; props `summary`/`meta` (Node\|string), `content` (Node), `render` (lazy body, runs once on first open), `open` get/set, `toggle()`; emits `pl:toggle {open}`; `data-raw` opts a block out of "expand all" | one-line head is the toggle (`role=button`, `aria-expanded`, `aria-controls`, Enter/Space); controls inside the head and text selections do not toggle; chevron rotates; body `hidden` until open |
| `pl-constellation` | — (recall map) | JS prop `data = {center:{label,title}, nodes:[{id,mark,title,group,color,weight,size,ring}], edges:[{from,to,kind,color,dashed}], legend:[{group,label,color,count}], rings}`; `highlight(id)`, `highlightGroup(group)`, `select(id)`; emits `pl:node-hover {id\|null}`, `pl:node-click {id}` | radial SVG: distance from the centre encodes weight (stronger = closer), one sector per group, node size ∝ `size`, `ring` draws the competing stroke, `mark` (rank number) inside the node pairs it with an adjacent list; hover/focus dims non-neighbours; nodes focusable (`tabindex=0`, Enter activates); legend hover highlights a group |
| `pl-diff-list` | — (model import diff) | JS prop `data = {groups:[{key:new\|imported\|gone, title, items:[{name,selected?,meta?}]}]}`; `selected` getter; emits `pl:diff-change {selected}` | "new" groups selectable via per-row `pl-toggle` + a select-all toggle; other groups informational; sticky group headers |

Actions are wired by **event delegation**: a single document listener maps `[data-action="fn"]`
Expand Down
3 changes: 3 additions & 0 deletions crates/openplotva-app/src/dialog_jobs/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ fn turn_context_artifact(
.map(|image| image.data_url.chars().count())
.sum::<usize>();
TurnContextArtifact {
chat_title: input.context.chat_title.trim().to_owned(),
memories,
persona: Some(persona),
settings: chat_settings_context_kv(settings),
Expand Down Expand Up @@ -1714,6 +1715,7 @@ mod context_artifact_tests {
fn artifact_snapshots_persona_settings_and_counts() {
let mut input = DialogInput::default();
input.message.id = 100;
input.context.chat_title = " Tea Club ".to_owned();
input.persona.mood = "playful".to_owned();
input.persona.custom_persona = "be terse".to_owned();
input.persona.profanity = true;
Expand Down Expand Up @@ -1757,6 +1759,7 @@ mod context_artifact_tests {
..ChatSettings::defaults(-1)
};
let artifact = turn_context_artifact(&input, &settings, Vec::new());
assert_eq!(artifact.chat_title, "Tea Club");
let persona = artifact.persona.expect("persona snapshot");
assert_eq!(persona.mood, "playful");
assert!(persona.custom);
Expand Down
13 changes: 12 additions & 1 deletion crates/openplotva-app/src/dialog_turn/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,9 @@ where
.await,
);
}
let tool_started = tokio::time::Instant::now();
let tool_started = parallel_media_results
.get(&call_index)
.map_or_else(tokio::time::Instant::now, |prepared| prepared.started);
let semantic_key = semantic_tool_call_key(
active_params.message_id,
&call.step,
Expand Down Expand Up @@ -1450,6 +1452,13 @@ where
crate::runtime_llm_runs::RunToolCall {
name: call.step.step.clone(),
status: result.status.clone(),
started_at: Some(
ctx.now
+ TimeDuration::try_from(
tool_started.saturating_duration_since(processing_started),
)
.unwrap_or_default(),
),
duration_ms: i64::try_from(tool_duration_ms).ok(),
args_json: serde_json::to_string(&call.step).ok(),
result_json: serde_json::to_string(&result).ok(),
Expand Down Expand Up @@ -1883,6 +1892,7 @@ fn reused_tool_result(cached: &ToolResult, original_call_id: &str) -> ToolResult

struct TimedToolResult {
result: ToolResult,
started: tokio::time::Instant,
duration_ms: u128,
}

Expand Down Expand Up @@ -1968,6 +1978,7 @@ async fn execute_timed_session_tool(
index,
TimedToolResult {
result,
started,
duration_ms: started.elapsed().as_millis(),
},
)
Expand Down
111 changes: 100 additions & 11 deletions crates/openplotva-app/src/runtime_llm_runs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl RunStatus {
pub struct RunToolCall {
pub name: String,
pub status: String,
/// Wall-clock start; parallel calls are recorded after the whole batch ends.
pub started_at: Option<OffsetDateTime>,
pub duration_ms: Option<i64>,
/// Serialized tool arguments, capped at [`RUN_TOOL_JSON_MAX_CHARS`].
pub args_json: Option<String>,
Expand Down Expand Up @@ -167,6 +169,17 @@ pub struct RunRecord {
}

impl RunRecord {
/// The latest non-auxiliary round, or the latest round when every round
/// so far is auxiliary.
fn last_main_round_mut(&mut self) -> Option<&mut RunRound> {
let index = self
.rounds
.iter()
.rposition(|round| !round.is_aux)
.or_else(|| self.rounds.len().checked_sub(1))?;
self.rounds.get_mut(index)
}

/// Final-response preview for the list skeleton.
#[must_use]
pub fn preview(&self) -> Option<String> {
Expand Down Expand Up @@ -280,7 +293,9 @@ impl RuntimeLlmRunBuffer {
Some(seq)
}

/// Attach an executed tool result to the run's latest round.
/// Attach an executed tool result to the round that issued it: the latest
/// non-auxiliary round, since a tool's own nested calls (vision inside
/// `understand_media`) are recorded as auxiliary rounds before it returns.
pub fn record_tool_result(&self, run_id: &str, mut tool: RunToolCall) {
tool.args_json = tool
.args_json
Expand All @@ -293,28 +308,32 @@ impl RuntimeLlmRunBuffer {
return;
};
record.totals.tool_calls += 1;
if let Some(round) = record.rounds.last_mut() {
if let Some(round) = record.last_main_round_mut() {
round.tool_calls.push(tool);
}
}

/// Attach the captured turn-context artifact (recalled memories, persona,
/// settings) to an open run for the admin "Context X-ray". No-op for unknown
/// or already-closed runs.
/// settings) to an open run for the admin "Context X-ray", and fill the
/// origin's chat title from it when the caller did not know the title.
/// No-op for unknown or already-closed runs.
pub fn record_context(&self, run_id: &str, context: openplotva_dialog::TurnContextArtifact) {
let mut inner = self.lock();
if let Some(record) = inner.open.get_mut(run_id) {
if record.origin.chat_title.is_none() && !context.chat_title.is_empty() {
record.origin.chat_title = Some(context.chat_title.clone());
}
record.context = Some(context);
}
}

/// Mark the latest round's text as delivered to the chat.
/// Mark the latest model round's text as delivered to the chat.
pub fn mark_round_sent(&self, run_id: &str, sent: RunRoundSent) {
let mut inner = self.lock();
if let Some(round) = inner
.open
.get_mut(run_id)
.and_then(|record| record.rounds.last_mut())
.and_then(RunRecord::last_main_round_mut)
{
round.sent = sent;
}
Expand Down Expand Up @@ -355,12 +374,18 @@ impl RuntimeLlmRunBuffer {
round.response_text = round
.response_text
.map(|text| cap_chars(&text, RUN_ROUND_RESPONSE_TEXT_MAX_CHARS));
// A round is stamped when its call returns, so the call began
// `duration_ms` earlier.
let started_at = OffsetDateTime::parse(&round.at, &Rfc3339).map_or_else(
|_| round.at.clone(),
|end| format_ts(end - Duration::milliseconds(i64::from(round.duration_ms))),
);
let record = RunRecord {
id,
run_id: format!("call-{}", round.trace_id),
kind: kind.to_owned(),
origin,
started_at: round.at.clone(),
started_at,
ended_at: Some(format_ts(now)),
status: if failed {
RunStatus::Failed
Expand Down Expand Up @@ -402,8 +427,7 @@ impl RuntimeLlmRunBuffer {
return;
};
if record
.rounds
.last()
.last_main_round_mut()
.is_some_and(|round| round.sent == RunRoundSent::Final)
{
mark_queued_outcome_delivered(outcome.as_mut());
Expand Down Expand Up @@ -490,7 +514,7 @@ impl RuntimeLlmRunBuffer {
}

fn mark_record_delivered(record: &mut RunRecord) {
if let Some(round) = record.rounds.last_mut() {
if let Some(round) = record.last_main_round_mut() {
round.sent = RunRoundSent::Final;
}
mark_queued_outcome_delivered(record.outcome.as_mut());
Expand Down Expand Up @@ -535,6 +559,7 @@ impl RunToolCall {
serde_json::json!({
"name": self.name,
"status": self.status,
"started_at": self.started_at.map(format_ts),
"duration_ms": self.duration_ms,
"args_json": self.args_json,
"result_json": self.result_json,
Expand Down Expand Up @@ -794,6 +819,7 @@ mod tests {
let buffer = RuntimeLlmRunBuffer::new(4);
buffer.begin_run("job-1".to_owned(), "dialog", RunOrigin::default(), ts(0));
let artifact = openplotva_dialog::TurnContextArtifact {
chat_title: "Tea Club".to_owned(),
memories: vec![openplotva_dialog::CapturedMemory {
card_id: 42,
salience: 0.9,
Expand Down Expand Up @@ -827,8 +853,29 @@ mod tests {
record.detail_json()["context"]["persona"]["mood"],
"playful"
);
// The list skeleton never carries the heavy context.
// The list skeleton never carries the heavy context, but it does pick
// up the chat title the turn was rendered with.
assert!(record.skeleton_json().get("context").is_none());
assert_eq!(record.skeleton_json()["origin"]["chat_title"], "Tea Club");

let titled = RunOrigin {
chat_title: Some("Known".to_owned()),
..RunOrigin::default()
};
buffer.begin_run("job-2".to_owned(), "dialog", titled, ts(2));
buffer.record_context(
"job-2",
openplotva_dialog::TurnContextArtifact {
chat_title: "Other".to_owned(),
..openplotva_dialog::TurnContextArtifact::default()
},
);
let record = buffer
.list(&RunListFilter::default(), ts(3))
.into_iter()
.find(|record| record.run_id == "job-2")
.expect("second run present");
assert_eq!(record.origin.chat_title.as_deref(), Some("Known"));
}

#[test]
Expand Down Expand Up @@ -886,6 +933,44 @@ mod tests {
);
}

#[test]
fn tools_and_sent_markers_skip_nested_auxiliary_rounds() {
let buffer = RuntimeLlmRunBuffer::new(4);
buffer.begin_run("job-7".to_owned(), "dialog", RunOrigin::default(), ts(0));
assert_eq!(buffer.record_round("job-7", round("")), Some(1));
let vision = RunRound {
flow: Some("vision".to_owned()),
is_aux: true,
..round("a cat on a sofa")
};
assert_eq!(buffer.record_round("job-7", vision), Some(2));
buffer.record_tool_result(
"job-7",
RunToolCall {
name: "understand_media".to_owned(),
status: "ok".to_owned(),
started_at: Some(ts(1)),
duration_ms: Some(5_600),
..RunToolCall::default()
},
);
buffer.mark_round_sent("job-7", RunRoundSent::Intermediate);

let run = buffer
.list(&RunListFilter::default(), ts(8))
.into_iter()
.next()
.expect("open run");
assert_eq!(run.rounds[0].tool_calls.len(), 1);
assert_eq!(run.rounds[0].sent, RunRoundSent::Intermediate);
assert!(run.rounds[1].tool_calls.is_empty());
assert_eq!(run.rounds[1].sent, RunRoundSent::No);
assert_eq!(
run.rounds[0].to_json()["tool_calls"][0]["started_at"],
serde_json::json!(format_ts(ts(1)))
);
}

#[test]
fn delivered_outbox_reconciles_closed_queued_run() {
let buffer = RuntimeLlmRunBuffer::new(4);
Expand Down Expand Up @@ -985,6 +1070,10 @@ mod tests {
assert_eq!(runs[0].kind, "memory_extraction");
assert_eq!(runs[0].status, RunStatus::Failed);
assert_eq!(runs[0].totals.rounds, 1);
assert_eq!(
runs[0].started_at,
format_ts(ts(0) - Duration::milliseconds(1_200))
);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions crates/openplotva-dialog/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ pub struct SettingKv {
/// Light, in-memory X-ray of everything that shaped one dialog turn's request.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct TurnContextArtifact {
/// Chat title the turn was rendered with; empty for untitled private chats.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub chat_title: String,
pub memories: Vec<CapturedMemory>,
pub persona: Option<PersonaSnapshot>,
pub settings: Vec<SettingKv>,
Expand Down
Loading
Loading