#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum TaskIntent {
Explore,
Implement,
Debug,
Review,
Unknown,
}
impl TaskIntent {
pub(crate) fn classify(task: &str) -> Self {
let lower = task.to_lowercase();
if contains_any(
&lower,
&["implement", "add feature", "create", "build", "write"],
) {
return Self::Implement;
}
if contains_any(
&lower,
&["fix", "debug", "error", "bug", "crash", "failing"],
) {
return Self::Debug;
}
if contains_any(&lower, &["review", "audit", "check", "verify", "inspect"]) {
return Self::Review;
}
if contains_any(
&lower,
&[
"explore",
"understand",
"how does",
"what is",
"find",
"search",
"where",
],
) {
return Self::Explore;
}
Self::Unknown
}
pub(crate) fn compression_level(&self) -> CompressionLevel {
match self {
TaskIntent::Explore => CompressionLevel::High,
TaskIntent::Review | TaskIntent::Unknown => CompressionLevel::Medium,
TaskIntent::Debug => CompressionLevel::Low,
TaskIntent::Implement => CompressionLevel::Minimal,
}
}
pub(crate) fn suggested_read_mode(&self) -> &'static str {
match self {
TaskIntent::Explore => "map",
TaskIntent::Review => "signatures",
TaskIntent::Debug | TaskIntent::Implement => "full",
TaskIntent::Unknown => "auto",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum CompressionLevel {
Minimal,
Low,
Medium,
High,
}
fn contains_any(text: &str, keywords: &[&str]) -> bool {
keywords.iter().any(|kw| text.contains(kw))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn classify_explore() {
assert_eq!(
TaskIntent::classify("how does the cache work?"),
TaskIntent::Explore
);
assert_eq!(
TaskIntent::classify("find the database module"),
TaskIntent::Explore
);
}
#[test]
fn classify_implement() {
assert_eq!(
TaskIntent::classify("implement user authentication"),
TaskIntent::Implement
);
assert_eq!(
TaskIntent::classify("add feature for dark mode"),
TaskIntent::Implement
);
}
#[test]
fn classify_debug() {
assert_eq!(
TaskIntent::classify("fix the null pointer error"),
TaskIntent::Debug
);
assert_eq!(
TaskIntent::classify("debug why tests are failing"),
TaskIntent::Debug
);
}
#[test]
fn classify_review() {
assert_eq!(
TaskIntent::classify("review this pull request"),
TaskIntent::Review
);
}
#[test]
fn classification_drives_compression() {
assert_eq!(
TaskIntent::Explore.compression_level(),
CompressionLevel::High
);
assert_eq!(
TaskIntent::Implement.compression_level(),
CompressionLevel::Minimal
);
assert_eq!(TaskIntent::Debug.compression_level(), CompressionLevel::Low);
}
#[test]
fn classification_drives_read_mode() {
assert_eq!(TaskIntent::Explore.suggested_read_mode(), "map");
assert_eq!(TaskIntent::Implement.suggested_read_mode(), "full");
assert_eq!(TaskIntent::Debug.suggested_read_mode(), "full");
}
}