Synced from monorepo

Synced from monorepo

Changes:
- Shell: accept target response id on rewind execute
- Shell: stamp response id on chat user message chunks
- Worktree: optional rebuild and stale git registration cleanup in auto-GC
- Worktree: kind-aware auto-GC TTLs and config knobs
- Worktree: macOS process CWD scan and Unix PID liveness for GC guards
- Worktree: automatic throttled GC on startup (Linux age-based; non-Linux dead-only)
- Pager: add `[ui].combine_queued_prompts` to batch queued follow-ups
- Shell: stop overwriting user skills
- Tools: read markdown in `skills/` directories untruncated
- `/usage` shows per-session token and dollar usage in the TUI
- Security: prompt on environment-dumping `ps` variants
- Security: always-safe `kubectl` no longer runs arbitrary kubeconfig credential plugins without permission
- Tools: make scheduler deletion durable
- Shell: add relocation storage primitives
- Shell: give side model calls their own conversation ids
- Fix five workflow-runtime bugs (budget, pause, cancel, reconnect)
- Security: peel `env -S` / `--split-string` operands in the Bash permission gate (managed deny/ask)
- Pager: expose doctor in the TUI
- Security: block unauthorized RCE via abused safe commands
- Pager idle watcher cue: "1 subagent still running" instead of "watching · 1 subagent"
- Security: block `rg --pre` arbitrary code execution in auto-mode
- Voice: diagnose silent-mic failures (macOS permission) and add doctor/terminal-setup Voice section
- App builder deployer: `allow_forking` and `show_built_with_grok`
- Pager: stop stacking duplicate "Worked for" markers on parked turns
- Shell: support `max` as a distinct reasoning effort tier
- Tools: serialize background `/loop` fires on the whole work unit
- Shell: add working-directory relocation state primitives
- Proto: `ClientToolResult` and `ChatConfig` client-side tools
- Shell: model providers
- Chat: select App Builder product on the Build path
- Shell: attach author identity to feedback when the deployment opts in
- Doctor: fix for SSH wrap setup
- Workflow authoring skills: create-workflow and import-claude-workflow docs
- Add read-only grok doctor
- Sandbox: apply Landlock without a controlling TTY
- Pager: recover image paste over grok wrap on headless remotes
- Pager: make actions screen-mode aware
- Shell: resume sessions when the working directory moves
- Pager: centralize terminal diagnostics
- Workspace: gate inline shell file access
- Pager: centralize terminal probes
- Pager: edit minimal prompts in an external editor
- Pager: standardize backgrounding on Ctrl+B
- Shell: recap rides the parent turn's prompt cache
- Tools: add scheduler lifecycle version clock

Source-Revision: 0f4d7c91b8b2b408333f6de1e8a76cb8eaa71899
This commit is contained in:
grokkybara[bot] 2026-07-21 18:10:23 +00:00
commit 3af4d5d398
556 changed files with 56609 additions and 21892 deletions

View file

@ -7,8 +7,6 @@ description = "Shared prompt-queue wire types for xai-grok-shell and xai-grok-pa
[dependencies]
serde = { workspace = true, features = ["derive"] }
[dev-dependencies]
serde_json = { workspace = true }
[lints]

View file

@ -0,0 +1,247 @@
//! Pure merge rules for `[ui].combine_queued_prompts`.
//!
//! Pager and shell keep separate call sites (local drain vs promote) but share
//! eligibility, join, and content-meta stamping so stop conditions cannot drift.
use crate::COMBINED_DISPLAY_TEXTS_META;
/// Separator between original follow-ups in the joined model body.
pub const TEXT_SEPARATOR: &str = "\n\n";
/// Adapter-filled gate for one queue row.
#[derive(Debug, Clone, Copy)]
pub struct CombineGate<'a> {
pub id: &'a str,
/// Plain user prompt (`kind == "prompt"`), not bash/command/cron.
pub is_plain_prompt: bool,
/// Synthetic / auto-wake origins never combine.
pub is_synthetic: bool,
/// Client-expanded skill payload (`displayText` meta).
pub is_expanded_skill: bool,
/// Bash command (meta or kind).
pub is_bash: bool,
/// Followers must have no images; front may keep its own.
pub has_images: bool,
/// Non-empty display / body text required to participate.
pub text: &'a str,
}
/// Front of a combine run: plain user prompt; may carry images.
pub fn can_merge_front(g: &CombineGate<'_>) -> bool {
g.is_plain_prompt && !g.is_synthetic && !g.is_expanded_skill && !g.is_bash && !g.text.is_empty()
}
/// Follower: same as front, no images, and not under edit hold.
pub fn can_merge_follower(g: &CombineGate<'_>, skip_ids: &[&str]) -> bool {
can_merge_front(g) && !g.has_images && !skip_ids.contains(&g.id)
}
/// Length of the mergeable prefix (including front). `1` means take front only.
/// `0` if `items` is empty.
pub fn combine_prefix_len<'a>(
items: impl IntoIterator<Item = CombineGate<'a>>,
skip_ids: &[&str],
) -> usize {
let mut iter = items.into_iter();
let Some(front) = iter.next() else {
return 0;
};
if !can_merge_front(&front) {
return 1;
}
let mut n = 1;
for next in iter {
if !can_merge_follower(&next, skip_ids) {
break;
}
n += 1;
}
n
}
pub fn join_texts<'a>(texts: impl IntoIterator<Item = &'a str>) -> String {
texts
.into_iter()
.filter(|t| !t.is_empty())
.collect::<Vec<_>>()
.join(TEXT_SEPARATOR)
}
/// Multi-bubble UI when at least two original prompts were merged.
#[inline]
pub fn is_combined(segs: &[String]) -> bool {
segs.len() >= 2
}
/// Stamp [`COMBINED_DISPLAY_TEXTS_META`] when `segs.len() >= 2`.
pub fn stamp_combined_display_texts(
meta: &mut serde_json::Map<String, serde_json::Value>,
segs: &[String],
) {
if !is_combined(segs) {
return;
}
meta.insert(
COMBINED_DISPLAY_TEXTS_META.to_string(),
serde_json::Value::Array(
segs.iter()
.cloned()
.map(serde_json::Value::String)
.collect(),
),
);
}
#[cfg(test)]
mod tests {
use super::*;
fn plain<'a>(id: &'a str, text: &'a str) -> CombineGate<'a> {
CombineGate {
id,
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: false,
is_bash: false,
has_images: false,
text,
}
}
#[test]
fn three_plain_prompts_merge() {
let items = [plain("a", "one"), plain("b", "two"), plain("c", "three")];
assert_eq!(combine_prefix_len(items, &[]), 3);
assert_eq!(join_texts(["one", "two", "three"]), "one\n\ntwo\n\nthree");
}
#[test]
fn stops_at_bash() {
let bash = CombineGate {
id: "bash",
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: false,
is_bash: true,
has_images: false,
text: "ls",
};
let items = [
plain("a", "one"),
plain("b", "two"),
bash,
plain("c", "three"),
];
assert_eq!(combine_prefix_len(items, &[]), 2);
}
#[test]
fn stops_at_non_prompt_kind() {
let cmd = CombineGate {
id: "cmd",
is_plain_prompt: false,
is_synthetic: false,
is_expanded_skill: false,
is_bash: false,
has_images: false,
text: "/compact",
};
assert_eq!(
combine_prefix_len([plain("a", "one"), plain("b", "two"), cmd], &[]),
2
);
}
#[test]
fn stops_at_expanded_skill() {
let skill = CombineGate {
id: "sk",
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: true,
is_bash: false,
has_images: false,
text: "/commit",
};
assert_eq!(
combine_prefix_len([plain("a", "one"), skill, plain("b", "two")], &[]),
1
);
}
#[test]
fn stops_at_image_follower() {
let img = CombineGate {
id: "img",
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: false,
is_bash: false,
has_images: true,
text: "see",
};
assert_eq!(
combine_prefix_len([plain("a", "one"), plain("b", "two"), img], &[]),
2
);
// Front may keep images.
let front_img = CombineGate {
id: "f",
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: false,
is_bash: false,
has_images: true,
text: "with image",
};
assert_eq!(combine_prefix_len([front_img, plain("b", "two")], &[]), 2);
}
#[test]
fn skips_row_under_edit() {
assert_eq!(
combine_prefix_len(
[
plain("a", "one"),
plain("edit", "draft"),
plain("c", "three")
],
&["edit"],
),
1
);
assert_eq!(
combine_prefix_len(
[plain("a", "one"), plain("b", "two"), plain("edit", "draft")],
&["edit"],
),
2
);
}
#[test]
fn stamp_only_when_multi() {
let mut meta = serde_json::Map::new();
stamp_combined_display_texts(&mut meta, &["only".into()]);
assert!(meta.is_empty());
stamp_combined_display_texts(&mut meta, &["a".into(), "b".into()]);
assert_eq!(
meta.get(COMBINED_DISPLAY_TEXTS_META),
Some(&serde_json::json!(["a", "b"]))
);
}
#[test]
fn ineligible_front_is_taken_alone() {
let bash = CombineGate {
id: "b",
is_plain_prompt: true,
is_synthetic: false,
is_expanded_skill: false,
is_bash: true,
has_images: false,
text: "pwd",
};
assert_eq!(combine_prefix_len([bash, plain("a", "x")], &[]), 1);
}
}

View file

@ -1,5 +1,10 @@
//! Shared prompt-queue wire types for xai-grok-shell and xai-grok-pager.
//! Shared prompt-queue wire types and combine-queued-prompts merge rules.
mod combine;
mod types;
pub use types::{QueueChanged, QueueEntryMeta, QueueEntryWire};
pub use combine::{
CombineGate, TEXT_SEPARATOR, can_merge_follower, can_merge_front, combine_prefix_len,
is_combined, join_texts, stamp_combined_display_texts,
};
pub use types::{COMBINED_DISPLAY_TEXTS_META, QueueChanged, QueueEntryMeta, QueueEntryWire};

View file

@ -1,5 +1,9 @@
use serde::{Deserialize, Serialize};
/// Content-block `_meta` key for per-prompt display texts when several
/// follow-ups were combined (length ≥ 2). Empty / absent = not combined.
pub const COMBINED_DISPLAY_TEXTS_META: &str = "combinedDisplayTexts";
/// Per-item queue metadata the session actor attaches to user-originated inputs; synthetic
/// inputs (auto-wake, nudges) carry none and never appear in the visible queue. Held in
/// actor state, never serialized itself.
@ -17,6 +21,8 @@ pub struct QueueEntryMeta {
pub kind: String,
/// Plain prompt text for the shared queue display.
pub text: String,
/// Per-prompt display texts when combine merged several follow-ups (len ≥ 2).
pub combined_texts: Option<Vec<String>>,
}
/// One queue row on the wire.
@ -36,6 +42,9 @@ pub struct QueueEntryWire {
pub kind: String,
#[serde(default)]
pub text: String,
/// See [`QueueEntryMeta::combined_texts`].
#[serde(default, skip_serializing_if = "Option::is_none")]
pub combined_texts: Option<Vec<String>>,
/// 0-based position among queued, not-yet-running prompts.
#[serde(default)]
pub position: usize,
@ -53,6 +62,17 @@ pub struct QueueChanged {
/// signal a subscriber uses to adopt `current_prompt_id` for notification routing.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub running_prompt_id: Option<String>,
/// Display text for the running prompt. Carried explicitly because the
/// running row is omitted from [`Self::entries`]; clients use this for the
/// turn-start user block without relying on a stale local mirror.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub running_text: Option<String>,
/// Kind for the running prompt (`"prompt"` / `"bash"` / …).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub running_kind: Option<String>,
/// Per-prompt display texts when the running turn was combined (len ≥ 2).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub running_combined_texts: Option<Vec<String>>,
}
#[cfg(test)]
@ -72,6 +92,7 @@ mod tests {
kind: "prompt".into(),
text: "fix the bug".into(),
position: 0,
combined_texts: None,
},
QueueEntryWire {
id: "p2".into(),
@ -81,9 +102,14 @@ mod tests {
kind: "bash".into(),
text: "ls -la".into(),
position: 1,
combined_texts: None,
},
],
running_prompt_id: Some("p0".into()),
running_text: None,
running_kind: None,
running_combined_texts: None,
};
let json = serde_json::to_value(&original).unwrap();
assert_eq!(json["sessionId"], "sess-42");
@ -108,8 +134,13 @@ mod tests {
kind: "prompt".into(),
text: "hi".into(),
position: 0,
combined_texts: None,
}],
running_prompt_id: Some("p0".into()),
running_text: None,
running_kind: None,
running_combined_texts: None,
};
let expected = serde_json::json!({
"sessionId": "s1",
@ -168,4 +199,20 @@ mod tests {
assert!(d.entries.is_empty());
assert!(d.running_prompt_id.is_none());
}
#[test]
fn running_combined_texts_round_trip() {
let original = QueueChanged {
session_id: "s1".into(),
entries: vec![],
running_prompt_id: Some("p0".into()),
running_text: Some("a\n\nb".into()),
running_kind: Some("prompt".into()),
running_combined_texts: Some(vec!["a".into(), "b".into()]),
};
let json = serde_json::to_value(&original).unwrap();
assert_eq!(json["runningCombinedTexts"], serde_json::json!(["a", "b"]));
let round: QueueChanged = serde_json::from_value(json).unwrap();
assert_eq!(round, original);
}
}