(text: &str)
| 643 | } |
| 644 | |
| 645 | fn codex_goal_context_from_text(text: &str) -> Option<CodexGoalContext> { |
| 646 | const START: &str = "<codex_internal_context source=\"goal\">"; |
| 647 | const END: &str = "</codex_internal_context>"; |
| 648 | let start = text.find(START)?; |
| 649 | if !text[..start].trim().is_empty() { |
| 650 | return None; |
| 651 | } |
| 652 | let after_start = &text[start + START.len()..]; |
| 653 | let end = after_start.find(END)?; |
| 654 | if !after_start[end + END.len()..].trim().is_empty() { |
| 655 | return None; |
| 656 | } |
| 657 | let body = &after_start[..end]; |
| 658 | let objective = tag_body(body, "objective")?.trim(); |
| 659 | if objective.is_empty() { |
| 660 | return None; |
| 661 | } |
| 662 | let token_budget_line = budget_line_value(body, "Token budget:"); |
| 663 | let tokens_remaining_line = budget_line_value(body, "Tokens remaining:"); |
| 664 | Some(CodexGoalContext { |
| 665 | objective: objective.to_string(), |
| 666 | tokens_used: budget_line_value(body, "Tokens used:").and_then(parse_budget_count), |
| 667 | token_budget: token_budget_line.and_then(parse_budget_count), |
| 668 | token_budget_unbounded: token_budget_line.is_some_and(is_unbounded_budget_value), |
| 669 | tokens_remaining: tokens_remaining_line.and_then(parse_budget_count), |
| 670 | tokens_remaining_unbounded: tokens_remaining_line.is_some_and(is_unbounded_budget_value), |
| 671 | }) |
| 672 | } |
| 673 | |
| 674 | fn tag_body<'a>(text: &'a str, tag: &str) -> Option<&'a str> { |
| 675 | let start_tag = format!("<{tag}>"); |
no test coverage detected