Provide an extensibility hook for azd init so extensions can reuse core init logic (incl. .azdignore)
- Dominant language
- Go
- Stars
- 569
- Forks
- 364
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 136
Description
## Motivation
Today, `azd init -t ` runs through core `cli/azd/internal/repository/initializer.go`, which handles the full template lifecycle: download/clone, `.azdignore` filtering, hooks, and project file generation.
Extensions that own their own init flows (e.g. `azd ai agent init` in `cli/azd/extensions/azure.ai.agents`) currently cannot reuse this pipeline. They re-implement template download, copy, and now `.azdignore` handling, which causes:
- **Drift risk**: features added to core init (`.azdignore`, future ignore rules, security hardening, hook execution) need to be duplicated in every extension that does its own scaffolding.
- **Inconsistent UX**: behavior between `azd init -t` and `azd ai agent init -m ` can diverge silently.
- **Duplicate maintenance**: the extension just had to copy `loadAzdIgnore` / `removeAzdIgnoredFiles` to fix #8384.
## Ask
Expose an extensibility hook so an extension can ask core to perform a template init into a target directory, returning the populated tree. Options worth exploring:
1. A new `azd-server` gRPC method (e.g. `Project.InitFromTemplate` or `Templates.Copy`) that takes a source URL/local path + target directory + flags and runs the same pipeline core uses for `azd init -t`.
2. A public Go package factored out of `cli/azd/internal/repository` (e.g. `cli/azd/pkg/template`) that extensions can import directly, since Go module versioning for `cli/azd/...` is now in place (see `cli/azd/docs/sdk-versioning.md`).
3. A new top-level `azd` subcommand or hook contract extensions can invoke instead of spawning their own copy logic.
Either approach should let extensions inherit, at minimum:
- `.azdignore` handling
- existing/future ignore mechanisms
- copy / download with consistent error reporting
- hook execution (post-template-copy hooks)
## Background / motivating bug
#8384 -- `azd ai agent init` did not honor `.azdignore`. The fix duplicates core's contract inside the extension at `cli/azd/extensions/azure.ai.agents/internal/pkg/azdignore`. That duplication is exactly the kind of thing this hook would prevent.
Contributor guide
Assessment
This issue has not been assessed yet.