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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ PromptOps Desktop, the hosted edition, have their own release notes.

## Unreleased

### Added

- Context management (off by default, in Settings): the main Claude
session can keep `state.md` and `logbook.md` in
`<workspace>/.promptops/sessions/<id>/`. Turn it on per workspace from the
notebook icon in the session header; PromptOps offers to exclude the folder
from git, approves writes to those two files only, and puts the state first
in a provider handoff. `PROMPTOPS_SESSION_STATE=0` turns it off.
- Clean restart: starts a fresh conversation with the same provider, command
and arguments from an editable handoff draft.

### Fixed

- Changing the folder of an existing session now applies on the next spawn or
wake and is no longer written back to the old path on exit.
- The "context is heavy" notice starts its 15-minute cooldown when it is
shown, so a session that was off screen still gets it.
- Tooltips on agents in the sidebar open beside the row, and long tooltips are
cut at eight lines.

## 2.2.1 — 2026-11-01

### Added
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop/src-tauri/permissions/main-window.toml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ commands.allow = [
"session_rename",
"session_resize",
"session_standby",
"session_state_get",
"session_state_global_get",
"session_state_global_set",
"session_state_instructions",
"session_state_set",
"session_state_status",
"session_status_subscribe",
"session_switch_provider",
"session_switch_worktree",
Expand Down Expand Up @@ -372,6 +378,7 @@ commands.allow = [
"terminal_shells_list",
"terminal_shells_probe_provider",
"terminal_shells_set_default",
"token_context_pressure_shown",
"token_get_all_stats",
"token_get_stats",
"token_record_usage",
Expand Down
15 changes: 13 additions & 2 deletions apps/desktop/src-tauri/src/commands/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,11 @@ fn route(
.and_then(|e| e.get("hook_event_name"))
.and_then(|v| v.as_str())
== Some("PreToolUse");
let should_auto_approve = is_pre_tool_use && manager.auto_approve(session_id);
let should_auto_approve = is_pre_tool_use
&& (manager.auto_approve(session_id)
|| payload
.get("event")
.is_some_and(|e| crate::commands::session_state::approves_tool(session_id, e)));
return json_response(&json!({ "ok": true, "autoApprove": should_auto_approve }));
}

Expand Down Expand Up @@ -622,7 +626,9 @@ fn route(

let is_pre_tool_use =
event.get("hook_event_name").and_then(|v| v.as_str()) == Some("PreToolUse");
let allow = is_pre_tool_use && manager.auto_approve(&session_id);
let allow = is_pre_tool_use
&& (manager.auto_approve(&session_id)
|| crate::commands::session_state::approves_tool(&session_id, &event));
if allow {
return json_response(&json!({
"hookSpecificOutput": {
Expand Down Expand Up @@ -719,6 +725,11 @@ fn dispatch_hook_event(app: &AppHandle, manager: &Arc<HookManager>, payload: &Va
// cache, provider usage probe. For sub-agent children only tool-use and
// stop are forwarded (never
// session-start: it would remap the parent's provider/probe on every spawn).
// Session state: measures only for main sessions that keep their state.
if sub_parent.is_none() && !session_id.is_empty() {
crate::commands::session_state::on_hook(&session_id, event_name, &event);
}

match &sub_parent {
None => wire_metrics(app, event_name, &session_id, None, &event),
Some(parent) if matches!(event_name, "PreToolUse" | "PostToolUse" | "Stop") => {
Expand Down
61 changes: 57 additions & 4 deletions apps/desktop/src-tauri/src/commands/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,16 @@ fn cache_hit_pct(state: &SessionTokenState) -> f64 {

/// Per-turn input threshold above which to suggest /compact.
const CONTEXT_PRESSURE_THRESHOLD: i64 = 120_000;

/// Threshold on the model window: the lower of the absolute cap and 60% of
/// the window. Unknown window → the cap, the historical threshold. With the
/// Claude windows (200k, 1M) the result stays 120k.
pub(crate) fn context_pressure_threshold(context_window: Option<i64>) -> i64 {
match context_window {
Some(w) if w > 0 => CONTEXT_PRESSURE_THRESHOLD.min(w * 6 / 10),
_ => CONTEXT_PRESSURE_THRESHOLD,
}
}
const CONTEXT_PRESSURE_COOLDOWN_MS: i64 = 15 * 60 * 1000;
const TOKEN_CONTEXT_PRESSURE: &str = "token:context-pressure";
/// Sessions kept in token-efficiency-history.json. The whole file is rewritten
Expand Down Expand Up @@ -1027,6 +1037,14 @@ impl TokenTracker {
let Some(delta) = self.read_transcript_delta(session_id, path) else {
return false;
};
if sub_agent_id.is_none()
&& delta
.events
.iter()
.any(|e| matches!(e, TranscriptEvent::Boundary { .. }))
{
crate::commands::session_state::on_compact(session_id);
}
self.apply_transcript_events(session_id, sub_agent_id, &delta.events);
let has_usage = delta.input + delta.output + delta.cache_read + delta.cache_write > 0;
if has_usage {
Expand Down Expand Up @@ -1332,6 +1350,13 @@ impl TokenTracker {
}
}

/// The web app showed the heavy-context notice: the cooldown starts here.
pub(crate) fn mark_context_pressure_shown(&self, key: &str) {
self.pressure_notified_at
.lock()
.insert(key.to_string(), now_ms());
}

/// PromptOps is about to send /compact: the next manual compact_boundary
/// within COMPACT_REQUEST_WINDOW_MS is attributed to PromptOps.
pub(crate) fn mark_compact_requested(&self, session_id: &str) {
Expand All @@ -1349,28 +1374,32 @@ impl TokenTracker {
sub_agent_id: Option<&str>,
input_tokens: i64,
) {
if input_tokens < CONTEXT_PRESSURE_THRESHOLD {
// Claude transcript: the window is not read here → historical threshold (120k).
let threshold = context_pressure_threshold(None);
if input_tokens < threshold {
return;
}
let now = now_ms();
{
// The cooldown starts when the web app SHOWS the notice
// (token_context_pressure_shown), not here: before, a session that
// was not on screen used up the 15 minutes with a dropped event.
let key = sub_agent_id.unwrap_or(session_id);
let mut notified = self.pressure_notified_at.lock();
let notified = self.pressure_notified_at.lock();
if notified
.get(key)
.is_some_and(|t| now - t < CONTEXT_PRESSURE_COOLDOWN_MS)
{
return;
}
notified.insert(key.to_string(), now);
}
let _ = app.emit(
TOKEN_CONTEXT_PRESSURE,
json!({
"sessionId": session_id,
"subAgentId": sub_agent_id,
"inputTokens": input_tokens,
"threshold": CONTEXT_PRESSURE_THRESHOLD,
"threshold": threshold,
}),
);
}
Expand Down Expand Up @@ -1827,6 +1856,18 @@ pub fn token_request_compact(
OkResult::ok()
}

/// token:context-pressure-shown — the notice was shown to the user: the
/// 15-minute cooldown starts for that session (or for that agent).
#[tauri::command]
pub fn token_context_pressure_shown(
tracker: tauri::State<'_, Arc<TokenTracker>>,
session_id: String,
sub_agent_id: Option<String>,
) -> OkResult {
tracker.mark_context_pressure_shown(sub_agent_id.as_deref().unwrap_or(&session_id));
OkResult::ok()
}

/// token:set-flags — sets the optimization flags; emits token:usage-updated.
#[tauri::command]
pub fn token_set_flags(
Expand Down Expand Up @@ -5708,6 +5749,18 @@ impl OkResult {

#[cfg(test)]
mod tests {
#[test]
fn context_threshold_stays_120k_for_claude_windows() {
use super::context_pressure_threshold as t;
assert_eq!(t(None), 120_000);
assert_eq!(t(Some(200_000)), 120_000);
assert_eq!(t(Some(1_000_000)), 120_000);
// Small window (Codex 258k → still 120k; 128k → 76.8k).
assert_eq!(t(Some(258_400)), 120_000);
assert_eq!(t(Some(128_000)), 76_800);
assert_eq!(t(Some(0)), 120_000);
}

use super::*;

fn usage_snapshot(provider: &str) -> ProviderUsageSnapshot {
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod remote;
pub mod semantic;
pub mod session;
pub mod session_model;
pub mod session_state;
pub mod session_tailer;
pub mod shell;
pub mod smart_context;
Expand Down
Loading
Loading