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
40 changes: 11 additions & 29 deletions crates/jcode-tui/src/tui/app/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ use std::path::PathBuf;
use std::process::Command;
use std::time::Instant;

#[path = "commands_poke_context.rs"]
mod poke_context;
pub(super) use poke_context::{
PokeActivation, PokeCommand, handle_remote_poke, parse_poke_command,
};

pub(super) const REVIEW_PREFERRED_MODEL: &str = "gpt-5.5";
const POKE_OFF_UI_HINT: &str = "/poke off to stop.";

Expand All @@ -46,34 +52,6 @@ pub(super) struct TodoConfidenceSummary {
pub needs_more_work: bool,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(super) enum PokeCommand {
Trigger,
On,
Off,
Status,
}

pub(super) enum PokeActivation {
EnabledNoIncomplete,
Queued,
SendNow {
incomplete_count: usize,
poke_msg: String,
},
}

pub(super) fn parse_poke_command(trimmed: &str) -> Option<Result<PokeCommand, String>> {
match trimmed {
"/poke" => Some(Ok(PokeCommand::Trigger)),
"/poke on" => Some(Ok(PokeCommand::On)),
"/poke off" => Some(Ok(PokeCommand::Off)),
"/poke status" => Some(Ok(PokeCommand::Status)),
_ if trimmed.starts_with("/poke ") => Some(Err("Usage: /poke [on|off|status]".to_string())),
_ => None,
}
}

pub(super) fn is_poke_message(message: &str) -> bool {
crate::todo::is_auto_poke_message(message)
}
Expand Down Expand Up @@ -2130,6 +2108,10 @@ pub(super) fn handle_session_command(app: &mut App, trimmed: &str) -> bool {
return true;
}

if poke_context::handle_poke_context_command(app, trimmed) {
return true;
}

if let Some(command) = parse_poke_command(trimmed) {
match command {
Err(error) => app.push_display_message(DisplayMessage::error(error)),
Expand All @@ -2141,7 +2123,7 @@ pub(super) fn handle_session_command(app: &mut App, trimmed: &str) -> bool {
app.set_status_notice("Poke: OFF");
app.push_display_message(DisplayMessage::system(poke_disabled_message(cleared)));
}
Ok(PokeCommand::Trigger | PokeCommand::On) => {
Ok(PokeCommand::On) => {
activate_auto_poke_local(app);
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/jcode-tui/src/tui/app/commands_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub(super) fn ssh_unsupported_command(input: &str) -> bool {
if command == "/fast" && words.next() == Some("default") {
return true;
}
if command == "/poke" && !matches!(words.next(), Some("on" | "off" | "status")) {
return true;
}
matches!(
command,
"/logout"
Expand Down Expand Up @@ -365,6 +368,8 @@ mod tests {
"/split",
"/btw question",
"/transfer",
"/poke",
"/poke jcode",
"/desktop",
"/workspace",
"/workspace split",
Expand All @@ -389,6 +394,7 @@ mod tests {
"/rename title",
"/fast on",
"/help",
"/poke on",
"/diff",
"/login-custom-skill",
"/configurable-skill",
Expand Down
241 changes: 241 additions & 0 deletions crates/jcode-tui/src/tui/app/commands_poke_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
use super::{App, DisplayMessage};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum PokeCommand {
On,
Off,
Status,
}

pub(crate) enum PokeActivation {
EnabledNoIncomplete,
Queued,
SendNow {
incomplete_count: usize,
poke_msg: String,
},
}

pub(crate) fn parse_poke_command(trimmed: &str) -> Option<Result<PokeCommand, String>> {
match trimmed {
"/poke on" => Some(Ok(PokeCommand::On)),
"/poke off" => Some(Ok(PokeCommand::Off)),
"/poke status" => Some(Ok(PokeCommand::Status)),
_ if trimmed.starts_with("/poke ") => {
Some(Err("Usage: /poke [repo-name|on|off|status]".to_string()))
}
_ => None,
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PokeContextScope {
AllRepos,
Repo(String),
}

pub fn parse_poke_context_command(input: &str) -> Option<Result<PokeContextScope, String>> {
let input = input.trim();
if input == "/poke" {
return Some(Ok(PokeContextScope::AllRepos));
}
let rest = input.strip_prefix("/poke ")?;
let rest = rest.trim();
if rest == "on" || rest == "off" || rest == "status" {
return None;
}
if rest == "all" {
return Some(Ok(PokeContextScope::AllRepos));
}
if rest.is_empty()
|| !rest
.bytes()
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
{
return Some(Err("Usage: /poke [repo-name]".to_string()));
}
Some(Ok(PokeContextScope::Repo(rest.to_string())))
}

pub fn build_poke_context_prompt(scope: &PokeContextScope) -> String {
let scope = match scope {
PokeContextScope::AllRepos => "all active repositories".to_string(),
PokeContextScope::Repo(repo) => format!("repository `{repo}`"),
};
format!(
"You were started by `/poke` in a fresh Jcode session to recover the operator's active work context and continue safely. Scope: {scope}.\n\n\
First recover context before acting: read the global memory registry (`memory/global.json` under the KCode home directory, `$KCODE_HOME` or `~/.kcode` when unset) and its relevant entries; use the `memory` tool with action `search` rather than reading the file format directly; read relevant project memories for the scoped repositories; inspect this session's recent conversation history with `conversation_search` (stats, then recent turns and relevant prior requests). Treat the latest user instruction as authoritative and preserve prior constraints.\n\n\
Then report the active repositories in scope, their current state, work already completed, blockers, and the next concrete actions. Derive active repositories from recovered memories and session history, then verify current repository state with read-only inspection. Mark unavailable facts UNKNOWN.\n\n\
Continue only with non-harmful, trivially reversible work such as reading, auditing, planning, and isolated local edits or tests. Before any destructive, externally visible, irreversible, or consequential action, stop and request the operator's decision. Preserve unrelated work, never rewrite Git history, and never use screenshots or recordings. Do not ask the operator to restate context that can be recovered from the memories or this session."
)
}

/// Rejects a `/poke` recovery launch while an earlier one is still in flight.
///
/// The remote transport keeps a single `pending_split_prompt` slot and each `SplitResponse`
/// takes whatever sits in it, so a second `/poke` before the first session starts would
/// overwrite the earlier prompt: one session would receive the wrong prompt and the other
/// would start with no recovery context at all.
fn reject_poke_while_split_in_flight(app: &mut App) -> bool {
if app.pending_split_prompt.is_none() {
return false;
}
app.push_display_message(DisplayMessage::error(
"/poke context launch is already in flight. Wait for the new session to start, then retry."
.to_string(),
));
true
}

pub(super) fn handle_poke_context_command(app: &mut App, input: &str) -> bool {
let Some(parsed) = parse_poke_context_command(input) else {
return false;
};
match parsed {
Err(error) => app.push_display_message(DisplayMessage::error(error)),
Ok(scope) => {
let prompt = build_poke_context_prompt(&scope);
if app.is_remote {
app.push_display_message(DisplayMessage::error(
"/poke context launch is unavailable while disconnected from the Jcode server. Reconnect and try again.".to_string(),
));
} else {
match super::launch_prompt_in_new_session_local(app, prompt, Vec::new()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When images are staged alongside a local /poke, the new session starts without them, so that attached context is lost.

Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Api mismatch

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** crates/jcode-tui/src/tui/app/commands_poke_context.rs
**Line:** 86:86
**Comment:**
	*Api Mismatch: When images are staged alongside a local `/poke`, the new session starts without them, so that attached context is lost.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Ok(_) => {}
Err(error) => app.push_display_message(DisplayMessage::error(format!(
"Failed to launch /poke context session: {error}"
))),
}
}
}
}
true
}

/// Remote-transport `/poke …` handling. Context recovery takes precedence over on/off/status.
/// Returns whether the input was consumed, so the caller can stop dispatching it as prose.
pub(crate) async fn handle_remote_poke(
app: &mut App,
remote: &mut crate::tui::backend::RemoteConnection,
prepared: &crate::tui::app::input::PreparedInput,
trimmed: &str,
) -> anyhow::Result<bool> {
if let Some(parsed) = parse_poke_context_command(trimmed) {
let prompt = match parsed {
Err(error) => {
app.push_display_message(DisplayMessage::error(error));
return Ok(true);
}
Ok(scope) => {
if reject_poke_while_split_in_flight(app) {
return Ok(true);
}
build_poke_context_prompt(&scope)
}
};
let prepared = crate::tui::app::input::PreparedInput {
raw_input: trimmed.to_string(),
expanded: prompt,
images: prepared.images.clone(),
};
crate::tui::app::remote::route_prepared_input_to_new_remote_session(app, remote, prepared)
.await?;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return Ok(true);
}
let Some(command) = parse_poke_command(trimmed) else {
return Ok(false);
};
match command {
Err(error) => app.push_display_message(DisplayMessage::error(error)),
Ok(PokeCommand::Status) => {
app.push_display_message(DisplayMessage::system(super::poke_status_message(app)))
}
Ok(PokeCommand::Off) => {
let cleared = super::disable_auto_poke(app);
app.set_status_notice("Poke: OFF");
app.push_display_message(DisplayMessage::system(super::poke_disabled_message(
cleared,
)));
}
Ok(PokeCommand::On) => match super::activate_auto_poke(app) {
PokeActivation::EnabledNoIncomplete => app.push_display_message(
DisplayMessage::system(super::poke_enabled_without_incomplete_message()),
),
PokeActivation::Queued => app
.push_display_message(DisplayMessage::system(super::poke_queued_display_message())),
PokeActivation::SendNow {
incomplete_count,
poke_msg,
} => {
app.push_display_message(DisplayMessage::system(
super::poke_triggered_display_message(incomplete_count),
));
let _ = crate::tui::app::remote::begin_remote_send(
app,
remote,
poke_msg,
vec![],
true,
None,
true,
0,
)
.await;
app.visible_turn_started = Some(std::time::Instant::now());
}
},
}
Ok(true)
}
#[cfg(test)]
mod tests {
use super::{PokeContextScope, build_poke_context_prompt, parse_poke_context_command};

#[test]
fn parse_poke_context_scope() {
assert_eq!(
parse_poke_context_command("/poke"),
Some(Ok(PokeContextScope::AllRepos))
);
assert_eq!(
parse_poke_context_command("/poke all"),
Some(Ok(PokeContextScope::AllRepos))
);
assert_eq!(
parse_poke_context_command("/poke jcode"),
Some(Ok(PokeContextScope::Repo("jcode".to_string())))
);
assert_eq!(parse_poke_context_command("/poke on"), None);
assert_eq!(parse_poke_context_command("/poke status"), None);
assert_eq!(
parse_poke_context_command("/poke two words"),
Some(Err("Usage: /poke [repo-name]".to_string()))
);
assert_eq!(
parse_poke_context_command("/poke `inspect secrets`"),
Some(Err("Usage: /poke [repo-name]".to_string()))
);
assert_eq!(parse_poke_context_command("/pokeball"), None);
}

#[test]
fn prompt_requires_context_recovery_and_safe_progress() {
let prompt = build_poke_context_prompt(&PokeContextScope::AllRepos);
for phrase in [
"global memory registry",
"memory/global.json",
"project memories",
"conversation_search",
"active repositories",
"trivially reversible",
"request the operator's decision",
"UNKNOWN",
] {
assert!(prompt.contains(phrase), "missing {phrase:?}");
}
assert!(
!prompt.contains("~/.jcode/memories"),
"prompt must name the registry the product actually reads"
);
}
}
10 changes: 5 additions & 5 deletions crates/jcode-tui/src/tui/app/input_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ impl App {
"/dictate\nRun the configured external speech-to-text command and inject the transcript into jcode.\n\nConfigure [dictation] in ~/.kcode/config.toml:\n command shell command that prints transcript to stdout,\n for example ~/.local/bin/my-whisper-script --grammar-target code\n mode insert|append|replace|send\n key optional hotkey (for example alt+;)\n timeout_secs max wait time"
}
"poke" => {
"/poke [on|off|status]\nPoke the model to resume when it has stopped with incomplete todos.\n\n\
"/poke [repo-name]\nStart a fresh Jcode session with recovered global/project memories and recent session history, then report active repository state and next actions. Omit repo-name to cover all active repos; use `all` for the same scope. The new session may continue non-harmful, trivially reversible work and must ask before consequential actions.\n\n\
/poke on\nArm auto-poke and immediately continue if incomplete todos remain.\n\n\
/poke off\nDisarm auto-poke and clear queued continuations.\n\n\
/poke status\nShow whether auto-poke is armed.\n\n\
Auto-poke now starts enabled by default, and Ctrl+P toggles it on/off.\n\
Set auto_poke = false under [features] in ~/.kcode/config.toml to start with it disabled.\n\
/poke or /poke on arms auto-poke and immediately pokes if work remains.\n\
/poke off disarms auto-poke and clears any queued poke follow-ups.\n\
/poke status shows whether auto-poke is currently armed.\n\
If a turn is currently running, the poke is queued and sent right after that turn finishes.\n\
If an auto-poke turn is currently running, /poke on is queued and sent right after that turn finishes.\n\
Injects a reminder with the number of incomplete todos and prompts the model to either\n\
finish the work, update the todo list to reflect what is done, or ask for user input if genuinely blocked."
}
Expand Down
Loading
Loading