(
&self,
dest_path: &Path,
task_type: &str,
ctx: &AppContext,
)
| 561 | } |
| 562 | |
| 563 | async fn write_instructions_content( |
| 564 | &self, |
| 565 | dest_path: &Path, |
| 566 | task_type: &str, |
| 567 | ctx: &AppContext, |
| 568 | ) -> Result<String, Box<dyn Error>> { |
| 569 | if let Some(ref file_path) = self.existing_instructions_file { |
| 570 | // Existing instructions file (retry) - copy content as-is |
| 571 | let content = crate::file_system::read_file(file_path).await?; |
| 572 | crate::file_system::write_file(dest_path, &content).await?; |
| 573 | } else { |
| 574 | // Resolve prompt: prefer explicit prompt, fall back to file contents |
| 575 | let effective_prompt = if let Some(ref prompt_text) = self.prompt { |
| 576 | Some(prompt_text.clone()) |
| 577 | } else if let Some(ref file_path) = self.prompt_file_path { |
| 578 | let content = crate::file_system::read_file(file_path).await?; |
| 579 | let trimmed = content.trim(); |
| 580 | if trimmed.is_empty() { |
| 581 | None |
| 582 | } else { |
| 583 | Some(trimmed.to_string()) |
| 584 | } |
| 585 | } else { |
| 586 | None |
| 587 | }; |
| 588 | |
| 589 | if let Some(ref prompt_text) = effective_prompt { |
| 590 | // Check if a template exists for this task type |
| 591 | let content = if task_type != "generic" { |
| 592 | match find_template(task_type, self.repo_root.as_deref(), &ctx.tsk_env()) { |
| 593 | Ok(template_content) => { |
| 594 | let body = strip_frontmatter(&template_content); |
| 595 | let mut content = body.replace("{{PROMPT}}", prompt_text); |
| 596 | if body.contains("{{DESCRIPTION}}") { |
| 597 | eprintln!( |
| 598 | "Warning: {{{{DESCRIPTION}}}} placeholder is deprecated. Use {{{{PROMPT}}}} instead." |
| 599 | ); |
| 600 | content = content.replace("{{DESCRIPTION}}", prompt_text); |
| 601 | } |
| 602 | content |
| 603 | } |
| 604 | Err(e) => { |
| 605 | eprintln!("Warning: Failed to read template: {e}"); |
| 606 | prompt_text.clone() |
| 607 | } |
| 608 | } |
| 609 | } else { |
| 610 | prompt_text.clone() |
| 611 | }; |
| 612 | |
| 613 | crate::file_system::write_file(dest_path, &content).await?; |
| 614 | } else { |
| 615 | // No prompt provided - use template as-is or create empty file |
| 616 | let initial_content = if task_type != "generic" { |
| 617 | match find_template(task_type, self.repo_root.as_deref(), &ctx.tsk_env()) { |
| 618 | Ok(template_content) => { |
| 619 | let body = strip_frontmatter(&template_content); |
| 620 | if self.edit |
no test coverage detected