Skip to content
Open
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
34 changes: 34 additions & 0 deletions crates/jp_cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,40 @@ impl From<crate::error::Error> for Error {
)]
.into(),
Compaction(error) => [("message", "Compaction error".into()), ("error", error)].into(),
SummaryOverlap {
authored,
from,
to,
required_from,
required_to,
} => [
("message", "Summary overlap".to_owned()),
(
"reason",
if authored {
format!(
"A summary cannot be nested inside or split across another one, so \
your text for turns {from}..{to} would have to stand in for turns \
{required_from}..{required_to} as well."
)
} else {
format!(
"Summarizing turns {from}..{to} would have to grow to turns \
{required_from}..{required_to}, replacing a summary you wrote by \
hand with a generated one."
)
},
),
(
"suggestion",
format!(
"Re-run with `--from {required_from} --to {required_to}` to cover the \
whole range, or `jp conversation compact --reset` to drop the existing \
compactions first."
),
),
]
.into(),
Summarize { model, reason } => [
("message", "Summarization failed".to_owned()),
("model", model),
Expand Down
20 changes: 11 additions & 9 deletions crates/jp_cli/src/cmd/compact_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl clap::Args for CompactFlag {
`--compact=SPEC` flags add multiple rules.\n\nBoth forms compose: bare \
`--compact` includes config rules, each `--compact=SPEC` adds a DSL \
rule.\n\nDSL format: POLICIES[:RANGE]\n\nPolicies are joined with `+`:\n- \
`r` / `reasoning`: strip reasoning blocks\n- `s` / `summarize`: generate an \
`r` / `reasoning`: strip reasoning blocks\n- `s` / `summary`: generate an \
LLM summary\n- `t` / `tools` (or `t=MODE`): strip tool calls; bare strips \
both, or MODE is one of `strip`/`s`, `strip-requests`/`sreq`, \
`strip-responses`/`sres`, `omit`/`o`\n\nRange: FROM..TO (1-based, inclusive \
Expand Down Expand Up @@ -161,7 +161,7 @@ pub(crate) struct CompactSpec {
/// `None` = no tool-call policy.
/// The mode mirrors the `--tools` flag.
pub tools: Option<ToolCallsMode>,
pub summarize: bool,
pub summary: bool,
/// `None` = use config defaults for range.
pub range: Option<DslRange>,
}
Expand Down Expand Up @@ -189,7 +189,7 @@ impl CompactSpec {
rule.reasoning = Some(ReasoningMode::Strip);
}
rule.tool_calls = self.tools;
if self.summarize {
if self.summary {
rule.summary = Some(PartialSummaryConfig::default());
}

Expand All @@ -216,7 +216,7 @@ impl FromStr for CompactSpec {

let mut reasoning = false;
let mut tools: Option<ToolCallsMode> = None;
let mut summarize = false;
let mut summary = false;

for policy in policies_str.split('+') {
let policy = policy.trim();
Expand All @@ -232,11 +232,13 @@ impl FromStr for CompactSpec {
}
reasoning = true;
}
"s" | "summarize" => {
// `summarize` predates the `summary` spelling and stays
// accepted so existing specs keep parsing.
"s" | "summary" | "summarize" => {
if value.is_some() {
return Err("`summarize` does not take a value".into());
return Err("`summary` does not take a value".into());
}
summarize = true;
summary = true;
}
"t" | "tools" => {
tools = Some(match value {
Expand All @@ -250,7 +252,7 @@ impl FromStr for CompactSpec {
}
}

if !reasoning && tools.is_none() && !summarize {
if !reasoning && tools.is_none() && !summary {
return Err("at least one policy required (r, t=MODE, s)".into());
}

Expand All @@ -259,7 +261,7 @@ impl FromStr for CompactSpec {
Ok(CompactSpec {
reasoning,
tools,
summarize,
summary,
range,
})
}
Expand Down
37 changes: 26 additions & 11 deletions crates/jp_cli/src/cmd/compact_flag_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,43 @@ fn parse_policy_only() {
assert_eq!("s".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: false,
tools: None,
summarize: true,
summary: true,
range: None,
});
assert_eq!("r+t=strip".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: true,
tools: Some(ToolCallsMode::Strip),
summarize: false,
summary: false,
range: None,
});
assert_eq!(
"reasoning+tools=strip+summarize"
"reasoning+tools=strip+summary"
.parse::<CompactSpec>()
.unwrap(),
CompactSpec {
reasoning: true,
tools: Some(ToolCallsMode::Strip),
summarize: true,
summary: true,
range: None,
}
);
}

#[test]
fn summarize_is_accepted_as_an_alias_for_summary() {
// Specs written against the older spelling keep parsing.
assert_eq!(
"summarize:..-3".parse::<CompactSpec>().unwrap(),
"summary:..-3".parse::<CompactSpec>().unwrap()
);

// Either spelling still rejects a value, naming the canonical one.
assert_eq!(
"summarize=x".parse::<CompactSpec>().unwrap_err(),
"`summary` does not take a value"
);
}

#[test]
fn parse_tool_modes() {
let mode = |s: &str| s.parse::<CompactSpec>().unwrap().tools;
Expand All @@ -48,7 +63,7 @@ fn parse_tool_mode_with_range() {
assert_eq!("t=sres:..-3".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: false,
tools: Some(ToolCallsMode::StripResponses),
summarize: false,
summary: false,
range: Some(DslRange {
from: None,
to: Some(RuleBound::FromEnd(3)),
Expand All @@ -61,7 +76,7 @@ fn parse_with_range() {
assert_eq!("s:..-3".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: false,
tools: None,
summarize: true,
summary: true,
range: Some(DslRange {
from: None,
to: Some(RuleBound::FromEnd(3)),
Expand All @@ -72,7 +87,7 @@ fn parse_with_range() {
CompactSpec {
reasoning: true,
tools: Some(ToolCallsMode::Strip),
summarize: false,
summary: false,
range: Some(DslRange {
from: Some(RuleBound::Absolute(5)),
to: Some(RuleBound::FromEnd(3)),
Expand All @@ -82,7 +97,7 @@ fn parse_with_range() {
assert_eq!("s:..".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: false,
tools: None,
summarize: true,
summary: true,
range: Some(DslRange {
from: None,
to: None,
Expand All @@ -91,7 +106,7 @@ fn parse_with_range() {
assert_eq!("r:5..".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: true,
tools: None,
summarize: false,
summary: false,
range: Some(DslRange {
from: Some(RuleBound::Absolute(5)),
to: None,
Expand Down Expand Up @@ -131,7 +146,7 @@ fn parse_single_number_shorthand() {
assert_eq!("s:-3".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: false,
tools: None,
summarize: true,
summary: true,
range: Some(DslRange {
from: None,
to: Some(RuleBound::FromEnd(3)),
Expand All @@ -141,7 +156,7 @@ fn parse_single_number_shorthand() {
assert_eq!("r:5".parse::<CompactSpec>().unwrap(), CompactSpec {
reasoning: true,
tools: None,
summarize: false,
summary: false,
range: Some(DslRange {
from: Some(RuleBound::Absolute(5)),
to: None,
Expand Down
Loading
Loading