Refactor view modules for improved readability and consistency

- Updated markdown rendering logic to use more concise methods for obtaining vector lengths.
- Changed review status display to use the correct flag from settings.
- Cleaned up sidebar rendering code for better formatting and readability.
- Enhanced status bar rendering with improved string formatting and consistent style application.
- Refined workflow panel rendering, ensuring consistent style usage and improved readability.
- Added architecture overview and detailed documentation for backend, data, dependencies, and frontend structures.
This commit is contained in:
asepharyana
2026-07-16 07:56:11 +07:00
parent 7d99cd6618
commit a00aa9bec8
141 changed files with 3420 additions and 2172 deletions
+15 -1
View File
@@ -1,6 +1,5 @@
//! Chat message types shared across the DTO layer: `Role` and `ChatMessage`
//! with convenience constructors.
use serde::{Deserialize, Serialize};
/// The conversation participant who authored a message.
@@ -17,6 +16,21 @@ pub enum Role {
}
impl Role {
/// Return the role as a lowercase string.
pub fn as_str(&self) -> &'static str {
match self {
Role::User => "user",
Role::Assistant => "assistant",
Role::System => "system",
Role::Tool => "tool",
}
}
}
impl std::fmt::Display for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
/// A single message in a conversation, compatible with the OpenAI/Anthropic
-1
View File
@@ -1,4 +1,3 @@
//! Chat DTO submodules: message roles/content and tool-call structures.
pub mod message;
pub mod tool;
+11 -11
View File
@@ -7,7 +7,6 @@
//!
//! Why: kept separate from `dto::provider` because tool calls are a property
//! of a chat *message*, not of the request/response envelope.
use serde::{Deserialize, Serialize};
use serde_json::Value;
@@ -41,10 +40,7 @@ mod tests {
#[test]
fn repair_json_bracket_then_brace() {
// `[` opened first → `]` must close first, then `}`
assert_eq!(
repair_json("[[1, 2, {\"a\": 3"),
"[[1, 2, {\"a\": 3}]]"
);
assert_eq!(repair_json("[[1, 2, {\"a\": 3"), "[[1, 2, {\"a\": 3}]]");
}
#[test]
@@ -212,7 +208,8 @@ pub fn sanitize_tool_arguments(args: &Value) -> Value {
// Attempt 2: strip control chars (0x00-0x1F except \t, \n)
// that some LLM providers emit as literal bytes in JSON strings
// (e.g. multi-line commit messages), then retry.
let cleaned: String = s.chars()
let cleaned: String = s
.chars()
.filter(|&c| !c.is_control() || c == '\t' || c == '\n' || c == '\r')
.collect();
if cleaned.len() != s.len() {
@@ -225,20 +222,23 @@ pub fn sanitize_tool_arguments(args: &Value) -> Value {
}
}
// Attempt 3: repair truncated JSON and retry.
let input = if cleaned.len() == s.len() { s } else { &cleaned };
let input = if cleaned.len() == s.len() {
s
} else {
&cleaned
};
let repaired = repair_json(input);
match serde_json::from_str::<Value>(&repaired) {
Ok(v) => {
tracing::warn!(
"tool argument string was truncated — repaired successfully",
);
tracing::warn!("tool argument string was truncated — repaired successfully",);
v
}
Err(e2) => {
tracing::error!(
"tool argument is a JSON string but failed to parse. \
Wrapping in object. Error: {}. Raw (first 200): {}",
e2, s.chars().take(200).collect::<String>(),
e2,
s.chars().take(200).collect::<String>(),
);
serde_json::json!({"_raw": s, "_parse_error": e2.to_string()})
}
-1
View File
@@ -1,5 +1,4 @@
//! Data transfer objects shared across the app: chat messages/tool calls
//! and provider request/response/usage shapes.
pub mod chat;
pub mod provider;
-1
View File
@@ -1,5 +1,4 @@
//! Provider-facing DTOs: chat completion request, response, and usage/cost.
pub mod request;
pub mod response;
pub mod usage;
-1
View File
@@ -8,7 +8,6 @@
//! for reserved words like `type`) so no manual (de)serialization glue is
//! needed; optional fields use `skip_serializing_if` so unset knobs are
//! omitted rather than sent as `null`, matching provider expectations.
use serde::{Deserialize, Serialize};
use serde_json::Value;
-1
View File
@@ -6,7 +6,6 @@
//!
//! Why: separate from the streaming SSE path (see `app/runtime/stream/mod.rs`),
//! which parses incremental deltas rather than a single complete payload.
use serde::{Deserialize, Serialize};
/// Non-streaming chat completion response returned by the provider.
-1
View File
@@ -4,7 +4,6 @@
//! chunk when `stream_options.include_usage` is set, or the `usage` field of
//! a non-streaming `ChatResponse`) → surfaced to the TUI for cost/token
//! display.
use serde::{Deserialize, Serialize};
/// Token counts and optional cost breakdown for a single completion request.