Skip to main content

resolve_task

Function resolve_task 

Source
pub fn resolve_task(
    arg: Option<&str>,
    agent_name: &str,
    description: &str,
    stdin_is_terminal: &dyn Fn() -> bool,
) -> Result<String>
Expand description

Resolve the task text from what --task was given, if anything.

  • Some(s) naming an existing file → its contents, trimmed.
  • Some(s) naming an existing directory → error.
  • Some(s) naming nothing, but shaped like a path (no whitespace, and a separator or a ~ prefix) → error, so a mistyped filename does not quietly become the prompt.
  • Some(s) otherwise → s as a literal prompt.
  • None when stdin is not a TTY → error.
  • None when stdin is a TTY → the user’s editor on a commented template.

description comes from the blueprint and is "" when the manifest sets none; it only ever reaches the editor template.

stdin_is_terminal is injected (a &dyn Fn() -> bool) rather than probing the real process stdin here, so the library core stays free of direct std::io::stdin() access and is fully testable. In production the binary passes &|| std::io::stdin().is_terminal().