addAgentFileWithTracking installs a single agent file from a package to the agentic engine agents directory.
(resolved *ResolvedWorkflow, tracker *FileTracker, opts AddOptions, gitRoot string)
| 799 | // addAgentFileWithTracking installs a single agent file from a package to the agentic engine |
| 800 | // agents directory. |
| 801 | func addAgentFileWithTracking(resolved *ResolvedWorkflow, tracker *FileTracker, opts AddOptions, gitRoot string) error { |
| 802 | engineAgentsDir := workflow.GetEngineSubAgentDir(opts.EngineOverride) |
| 803 | agentsDir := filepath.Join(gitRoot, engineAgentsDir) |
| 804 | if err := os.MkdirAll(agentsDir, constants.DirPermPublic); err != nil { |
| 805 | return fmt.Errorf("failed to create agents directory %s: %w", agentsDir, err) |
| 806 | } |
| 807 | |
| 808 | fileName := filepath.Base(resolved.Spec.WorkflowPath) |
| 809 | destFile := filepath.Join(agentsDir, fileName) |
| 810 | |
| 811 | addLog.Printf("Adding agent file: dest=%s, content_size=%d bytes", destFile, len(resolved.Content)) |
| 812 | |
| 813 | if opts.Verbose { |
| 814 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Adding agent file to %s: %s", engineAgentsDir, fileName))) |
| 815 | } |
| 816 | |
| 817 | fileExists := false |
| 818 | if fileutil.FileExists(destFile) { |
| 819 | fileExists = true |
| 820 | if !opts.Force { |
| 821 | if opts.Verbose { |
| 822 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Agent file '%s' already exists. Skipping.", destFile))) |
| 823 | } |
| 824 | return nil |
| 825 | } |
| 826 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Overwriting existing agent file: "+destFile)) |
| 827 | } |
| 828 | |
| 829 | if tracker != nil { |
| 830 | if fileExists { |
| 831 | tracker.TrackModified(destFile) |
| 832 | } else { |
| 833 | tracker.TrackCreated(destFile) |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | if err := os.WriteFile(destFile, resolved.Content, constants.FilePermPublic); err != nil { |
| 838 | return fmt.Errorf("failed to write agent file '%s': %w", destFile, err) |
| 839 | } |
| 840 | |
| 841 | if !opts.Quiet { |
| 842 | fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Added agent file: %s/%s", engineAgentsDir, fileName))) |
| 843 | } |
| 844 | |
| 845 | return nil |
| 846 | } |
| 847 | |
| 848 | // printCompilationError formats and writes a compilation error to stderr. |
| 849 | // Redirect-only workflow errors are treated as informational messages rather than errors, |
no test coverage detected