ExtraWorkspace returns the directory to mount as a read-only extra workspace when the agent file lives outside the main workspace. The agent reference may be a path, an OCI/URL reference, a built-in name, or an alias defined in the user's config — ExtraWorkspace delegates resolution to [config.Reso
(wd, agentRef string)
| 21 | // under wd), the reference cannot be resolved, or the resolved source |
| 22 | // has no on-disk parent directory. |
| 23 | func ExtraWorkspace(wd, agentRef string) string { |
| 24 | if agentRef == "" { |
| 25 | return "" |
| 26 | } |
| 27 | |
| 28 | source, err := config.Resolve(agentRef, nil) |
| 29 | if err != nil { |
| 30 | return "" |
| 31 | } |
| 32 | |
| 33 | parent := source.ParentDir() |
| 34 | if parent == "" { |
| 35 | return "" |
| 36 | } |
| 37 | |
| 38 | absParent, err := filepath.Abs(parent) |
| 39 | if err != nil { |
| 40 | return "" |
| 41 | } |
| 42 | absWd, err := filepath.Abs(wd) |
| 43 | if err != nil { |
| 44 | return "" |
| 45 | } |
| 46 | |
| 47 | // No extra mount needed if the file is already under the workspace. |
| 48 | rel, err := filepath.Rel(absWd, absParent) |
| 49 | if err == nil && rel != ".." && !startsWithParent(rel) { |
| 50 | return "" |
| 51 | } |
| 52 | |
| 53 | return absParent |
| 54 | } |
| 55 | |
| 56 | // startsWithParent reports whether rel begins with a "../" segment, |
| 57 | // which means absParent is not a subdirectory of absWd. |