Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,28 @@ from code-deploy ZIP packaging (uses .gitignore syntax).`,
if err := absolutizeRelativeManifestPaths(flags); err != nil {
return err
}
_, statErr := os.Stat(folderName)
newlyCreated := errors.Is(statErr, fs.ErrNotExist)
targetDir = folderName
if newlyCreated && !existingProject {
folderDisplay = filepath.ToSlash(folderName)

// When the manifest lives in the current directory, the agent
// source code is already here — treat it like --from-code and
// initialize in-place rather than copying files into a new
// subdirectory. The existing isSamePath guard in copyDirectory
// will skip the copy when src and dst resolve to the same path.
manifestInCwd := false
if isLocalFilePath(flags.manifestPointer) {
if cwd, cwdErr := os.Getwd(); cwdErr == nil {
manifestInCwd = isSamePath(filepath.Dir(flags.manifestPointer), cwd)
}
}

if !manifestInCwd {
_, statErr := os.Stat(folderName)
newlyCreated := errors.Is(statErr, fs.ErrNotExist)
targetDir = folderName
if newlyCreated && !existingProject {
folderDisplay = filepath.ToSlash(folderName)
}
} else if flags.src == "" {
flags.src = "."
}
}

Expand Down Expand Up @@ -1969,7 +1986,8 @@ func (a *InitAction) configureModelChoice(
return agentManifest, nil
}

func (a *InitAction) isLocalFilePath(path string) bool {
// isLocalFilePath reports whether path refers to a local file (not an http/https URL).
func isLocalFilePath(path string) bool {
// Check if it starts with http:// or https://
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
return false
Expand Down Expand Up @@ -2142,7 +2160,7 @@ func (a *InitAction) downloadAgentYaml(
useGhCli := false

// Check if manifestPointer is a local file path or a URI
if a.isLocalFilePath(manifestPointer) {
if isLocalFilePath(manifestPointer) {
// Guard against directories (defense in depth — the caller should
// have caught this already, but check here for safety).
if err := checkNotDirectory(manifestPointer); err != nil {
Expand Down Expand Up @@ -2389,7 +2407,7 @@ func (a *InitAction) downloadAgentYaml(
a.serviceNameOverride = serviceName

// Safety checks for local container-based agents should happen before prompting for model SKU, etc.
if a.isLocalFilePath(manifestPointer) {
if isLocalFilePath(manifestPointer) {
if _, isContainerAgent := agentManifest.Template.(agent_yaml.ContainerAgent); isContainerAgent {
if err := a.validateLocalContainerAgentCopy(ctx, manifestPointer, targetDir); err != nil {
return nil, "", err
Expand All @@ -2403,7 +2421,7 @@ func (a *InitAction) downloadAgentYaml(
return nil, "", fmt.Errorf("creating target directory %s: %w", targetDir, err)
}

if a.isLocalFilePath(manifestPointer) {
if isLocalFilePath(manifestPointer) {
// Check if the template is a ContainerAgent
_, isHostedContainer := agentManifest.Template.(agent_yaml.ContainerAgent)

Expand Down
Loading