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
7 changes: 4 additions & 3 deletions src/apps/cli/src/agent/core_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use tokio::sync::mpsc;

use super::{Agent, AgentEvent, AgentResponse};
use crate::session::{ToolCall, ToolCallStatus};
use bitfun_core::agentic::coordination::{ConversationCoordinator, DialogTriggerSource};
use bitfun_core::agentic::coordination::{
ConversationCoordinator, DialogSubmissionPolicy, DialogTriggerSource,
};
use bitfun_core::agentic::core::SessionConfig;
use bitfun_core::agentic::events::EventQueue;
use bitfun_events::{AgenticEvent as CoreEvent, ToolEventData};
Expand Down Expand Up @@ -99,7 +101,6 @@ impl Agent for CoreAgentAdapter {
tracing::info!("Processing message: {}", message);

let _ = event_tx.send(AgentEvent::Thinking);

self.coordinator
.start_dialog_turn(
session_id.clone(),
Expand All @@ -108,7 +109,7 @@ impl Agent for CoreAgentAdapter {
None,
self.agent_type.clone(),
None,
DialogTriggerSource::Cli,
DialogSubmissionPolicy::for_source(DialogTriggerSource::Cli),
)
.await?;

Expand Down
89 changes: 86 additions & 3 deletions src/apps/desktop/src/api/agentic_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use tauri::{AppHandle, State};

use crate::api::app_state::AppState;
use bitfun_core::agentic::coordination::{
ConversationCoordinator, DialogScheduler, DialogTriggerSource,
AssistantBootstrapBlockReason, AssistantBootstrapEnsureOutcome, AssistantBootstrapSkipReason,
ConversationCoordinator, DialogScheduler, DialogSubmissionPolicy, DialogTriggerSource,
};
use bitfun_core::agentic::core::*;
use bitfun_core::agentic::image_analysis::ImageContextData;
Expand Down Expand Up @@ -65,6 +66,23 @@ pub struct StartDialogTurnResponse {
pub message: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EnsureAssistantBootstrapRequest {
pub session_id: String,
pub workspace_path: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EnsureAssistantBootstrapResponse {
pub status: String,
pub reason: String,
pub session_id: String,
pub turn_id: Option<String>,
pub detail: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetSessionRequest {
Expand Down Expand Up @@ -229,7 +247,7 @@ pub async fn start_dialog_turn(
turn_id,
agent_type,
workspace_path,
DialogTriggerSource::DesktopUi,
DialogSubmissionPolicy::for_source(DialogTriggerSource::DesktopUi),
)
.await
.map_err(|e| format!("Failed to start dialog turn: {}", e))?;
Expand All @@ -242,7 +260,8 @@ pub async fn start_dialog_turn(
turn_id,
agent_type,
workspace_path,
DialogTriggerSource::DesktopUi,
DialogSubmissionPolicy::for_source(DialogTriggerSource::DesktopUi),
None,
)
.await
.map_err(|e| format!("Failed to start dialog turn: {}", e))?;
Expand All @@ -254,6 +273,19 @@ pub async fn start_dialog_turn(
})
}

#[tauri::command]
pub async fn ensure_assistant_bootstrap(
coordinator: State<'_, Arc<ConversationCoordinator>>,
request: EnsureAssistantBootstrapRequest,
) -> Result<EnsureAssistantBootstrapResponse, String> {
let outcome = coordinator
.ensure_assistant_bootstrap(request.session_id, request.workspace_path)
.await
.map_err(|e| format!("Failed to ensure assistant bootstrap: {}", e))?;

Ok(assistant_bootstrap_outcome_to_response(outcome))
}

fn is_blank_text(value: Option<&String>) -> bool {
value.map(|s| s.trim().is_empty()).unwrap_or(true)
}
Expand Down Expand Up @@ -517,6 +549,57 @@ pub struct ModeInfoDTO {
pub enabled: bool,
}

fn assistant_bootstrap_outcome_to_response(
outcome: AssistantBootstrapEnsureOutcome,
) -> EnsureAssistantBootstrapResponse {
match outcome {
AssistantBootstrapEnsureOutcome::Started {
session_id,
turn_id,
} => EnsureAssistantBootstrapResponse {
status: "started".to_string(),
reason: "bootstrap_started".to_string(),
session_id,
turn_id: Some(turn_id),
detail: None,
},
AssistantBootstrapEnsureOutcome::Skipped { session_id, reason } => {
EnsureAssistantBootstrapResponse {
status: "skipped".to_string(),
reason: assistant_bootstrap_skip_reason_to_str(reason).to_string(),
session_id,
turn_id: None,
detail: None,
}
}
AssistantBootstrapEnsureOutcome::Blocked {
session_id,
reason,
detail,
} => EnsureAssistantBootstrapResponse {
status: "blocked".to_string(),
reason: assistant_bootstrap_block_reason_to_str(reason).to_string(),
session_id,
turn_id: None,
detail: Some(detail),
},
}
}

fn assistant_bootstrap_skip_reason_to_str(reason: AssistantBootstrapSkipReason) -> &'static str {
match reason {
AssistantBootstrapSkipReason::BootstrapNotRequired => "bootstrap_not_required",
AssistantBootstrapSkipReason::SessionHasExistingTurns => "session_has_existing_turns",
AssistantBootstrapSkipReason::SessionNotIdle => "session_not_idle",
}
}

fn assistant_bootstrap_block_reason_to_str(reason: AssistantBootstrapBlockReason) -> &'static str {
match reason {
AssistantBootstrapBlockReason::ModelUnavailable => "model_unavailable",
}
}

fn session_to_response(session: Session) -> SessionResponse {
SessionResponse {
session_id: session.session_id,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/desktop/src/api/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Application state management

use bitfun_core::agentic::{agents, tools};
use bitfun_core::agentic::side_question::SideQuestionRuntime;
use bitfun_core::agentic::{agents, tools};
use bitfun_core::infrastructure::ai::{AIClient, AIClientFactory};
use bitfun_core::miniapp::{initialize_global_miniapp_manager, JsWorkerPool, MiniAppManager};
use bitfun_core::service::{ai_rules, config, filesystem, mcp, token_usage, workspace};
Expand Down
7 changes: 5 additions & 2 deletions src/apps/desktop/src/api/image_analysis_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Image Analysis API

use crate::api::app_state::AppState;
use bitfun_core::agentic::coordination::{DialogScheduler, DialogTriggerSource};
use bitfun_core::agentic::coordination::{
DialogScheduler, DialogSubmissionPolicy, DialogTriggerSource,
};
use bitfun_core::agentic::image_analysis::{
resolve_vision_model_from_ai_config, AnalyzeImagesRequest, ImageAnalysisResult, ImageAnalyzer,
MessageEnhancer, SendEnhancedMessageRequest,
Expand Down Expand Up @@ -97,7 +99,8 @@ pub async fn send_enhanced_message(
Some(request.dialog_turn_id.clone()),
request.agent_type.clone(),
None,
DialogTriggerSource::DesktopApi,
DialogSubmissionPolicy::for_source(DialogTriggerSource::DesktopApi),
None,
)
.await
.map_err(|e| format!("Failed to send enhanced message: {}", e))?;
Expand Down
1 change: 1 addition & 0 deletions src/apps/desktop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub async fn run() {
theme::show_main_window,
api::agentic_api::create_session,
api::agentic_api::start_dialog_turn,
api::agentic_api::ensure_assistant_bootstrap,
api::agentic_api::cancel_dialog_turn,
api::agentic_api::delete_session,
api::agentic_api::restore_session,
Expand Down
1 change: 1 addition & 0 deletions src/crates/core/src/agentic/agents/claw_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl ClawMode {
"Git".to_string(),
"TerminalControl".to_string(),
"SessionControl".to_string(),
"SessionMessage".to_string(),
],
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/crates/core/src/agentic/agents/prompts/agentic_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You are pair programming with a USER to solve their coding task. Each time the U

Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.

Tool results and user messages may include <system-reminder> tags. These <system-reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.
Tool results and user messages may include <system_reminder> tags. These <system_reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.

IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.
IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
Expand Down Expand Up @@ -84,7 +84,7 @@ The user will primarily request you perform software engineering tasks. This inc
- Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the minimum needed for the current task—three similar lines of code is better than a premature abstraction.
- Avoid backwards-compatibility hacks like renaming unused `_vars`, re-exporting types, adding `// removed` comments for removed code, etc. If something is unused, delete it completely.

- Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear.
- Tool results and user messages may include <system_reminder> tags. <system_reminder> tags contain useful information and reminders. They are automatically added by the system, and bear no direct relation to the specific tool results or user messages in which they appear.


# Tool usage policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You are pair programming with a USER. Each user message may include extra IDE co

Follow the USER's instructions in each message, denoted by the <user_query> tag.

Tool results and user messages may include <system-reminder> tags. Follow them, but do not mention them to the user.
Tool results and user messages may include <system_reminder> tags. Follow them, but do not mention them to the user.

IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.

Expand Down
25 changes: 25 additions & 0 deletions src/crates/core/src/agentic/agents/prompts/claw_mode.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
You are a personal assistant running inside BitFun.

Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.

Tool results and user messages may include <system_reminder> tags. These <system_reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.

{LANGUAGE_PREFERENCE}
# Tool Call Style
Default: do not narrate routine, low-risk tool calls (just call the tool).
Expand All @@ -8,6 +12,27 @@ Keep narration brief and value-dense; avoid repeating obvious steps.
Use plain human language for narration unless in a technical context.
When a first-class tool exists for an action, use the tool directly instead of asking the user to run equivalent CLI commands.

# Session Coordination
For complex coding tasks or office-style multi-step tasks, prefer multi-session coordination over doing everything in the current session.
Use `SessionControl` to list, reuse, create, and delete sessions. Use `SessionMessage` to hand off a self-contained subtask to another session.

Use this pattern when:
- The work can be split into independent subtasks.
- A dedicated planning, coding, research, or writing thread would reduce context switching.
- The task benefits from persistent context across multiple steps or multiple user turns.

Choose the session type intentionally:
- `agentic` for implementation, debugging, and code changes.
- `Plan` for requirement clarification, scoping, and planning before coding.
- `Cowork` for research, documents, presentations, summaries, and other office-related work.

Operational rules:
- Reuse an existing relevant session when possible. If unsure, list sessions before creating a new one.
- Every `SessionMessage` should include the goal, relevant context, constraints, and expected output.
- When a target session finishes, its reply is an automated subtask result, not a new human instruction. Synthesize it, verify it when needed, and continue.
- Delete temporary sessions when they are no longer useful.
- Do not create extra sessions for trivial, tightly coupled, or one-step work.

# Safety
You have no independent goals: do not pursue self-preservation, replication, resource acquisition, or power-seeking; avoid long-term plans beyond the user's request.
Prioritize safety and human oversight over completion; if instructions conflict, pause and ask; comply with stop/pause/audit requests and never bypass safeguards.
Expand Down
4 changes: 4 additions & 0 deletions src/crates/core/src/agentic/agents/prompts/cowork_mode.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
You are BitFun in Cowork mode. Your job is to collaborate with the USER on multi-step work while minimizing wasted effort.

Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.

Tool results and user messages may include <system_reminder> tags. These <system_reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.

{LANGUAGE_PREFERENCE}

# Application Details
Expand Down
4 changes: 4 additions & 0 deletions src/crates/core/src/agentic/agents/prompts/debug_mode.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
You are BitFun, an ADE (AI IDE) that helps users with software engineering tasks.

Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.

Tool results and user messages may include <system_reminder> tags. These <system_reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.

You are now in **DEBUG MODE**. You must debug with **runtime evidence**.

**Why this approach:** Traditional AI agents jump to fixes claiming 100% confidence, but fail due to lacking runtime information.
Expand Down
4 changes: 4 additions & 0 deletions src/crates/core/src/agentic/agents/prompts/plan_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ You are a software architect and planning specialist for designing implementatio

You MUST NOT make any edits (with the exception of the plan file you created), run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supersedes any other instructions you have received (for example, to make edits).

Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.

Tool results and user messages may include <system_reminder> tags. These <system_reminder> tags contain useful information and reminders. Please heed them, but don't mention them in your response to the user.

{LANGUAGE_PREFERENCE}
# Plan Workflow

Expand Down
Loading
Loading