RunStructured executes the plugin and always returns a StructuredResult, preferring the structured executor when available and falling back to the legacy ExecuteWithStream pair otherwise. The infrastructure error (network timeout, ctx canceled, plugin binary not found) is returned separately so the
(ctx context.Context, p Plugin, args []string, onOutput func(string))
| 206 | // timeout, ctx canceled, plugin binary not found) is returned separately so |
| 207 | // the orchestrator can decide whether to abort the batch. |
| 208 | func RunStructured(ctx context.Context, p Plugin, args []string, onOutput func(string)) (StructuredResult, error) { |
| 209 | if p == nil { |
| 210 | return StructuredResult{}, errNilPlugin |
| 211 | } |
| 212 | if se, ok := p.(StructuredExecutor); ok { |
| 213 | return se.ExecuteStructured(ctx, args, onOutput) |
| 214 | } |
| 215 | out, err := p.ExecuteWithStream(ctx, args, onOutput) |
| 216 | res := StructuredResult{Output: out} |
| 217 | if err != nil { |
| 218 | res.IsError = true |
| 219 | // ErrorCode classification lives in cli/agent — callers wrap this |
| 220 | // StructuredResult with agent.WrapStructuredResult to populate |
| 221 | // ErrorCode. Keeping the classifier out of this package avoids |
| 222 | // an import cycle (cli/plugins ↛ cli/agent). |
| 223 | } |
| 224 | return res, err |
| 225 | } |