Describe the bug
parse_agent_spec (in src/google/agents/cli/scaffold/utils/remote_template.py) drops the @<ref> (branch/tag) when the spec has no sub-path, and bakes it into the clone URL instead. So pinning a whole-repo remote template to a tag/branch clones the wrong (or a nonexistent) URL at the default main.
The two spec forms both document an optional trailing ref:
# line 77: <repo_url>[/<path>][@<ref>]
remote_pattern = r"^(https?://[^/]+/[^/]+/[^/]+)(?:/(.*?))?(?:@([^/]+))?/?$"
# line 105: <org>/<repo>[/<path>][@<ref>]
github_shorthand_pattern = r"^([^/]+)/([^/]+)(?:/(.*?))?(?:@([^/]+))?/?$"
The repo/name capture uses [^/]+, which includes @, so when there is no sub-path to force backtracking it greedily swallows @<ref>. The dedicated (?:@([^/]+))? ref group never matches, and git_ref silently falls back to "main". The if "@" in template_path fallback (line 90) doesn't help because in the no-path case the @ref lands in the repo capture, not in template_path (which is "").
Steps to reproduce
from google.agents.cli.scaffold.utils.remote_template import parse_agent_spec
parse_agent_spec("myorg/myrepo@v2.0")
# repo_url='https://github.com/myorg/myrepo@v2.0' template_path='' git_ref='main'
parse_agent_spec("https://github.com/myorg/myrepo@v2.0")
# repo_url='https://github.com/myorg/myrepo@v2.0' template_path='' git_ref='main'
fetch_remote_template then runs git clone --branch main https://github.com/myorg/myrepo@v2.0 …, which fails with a confusing "repository not found" for a repo that exists.
Expected behavior
The @<ref> should be parsed as the ref regardless of whether a sub-path is present:
myorg/myrepo@v2.0 -> repo='https://github.com/myorg/myrepo', path='', ref='v2.0'
The with-path forms already work (myorg/myrepo/sub/dir@v2.0 → ref v2.0), which masks the bug.
Suggested fix
Exclude @ from the repo-name character class so the ref group can match (GitHub org/repo names can't contain @, so this is safe):
# line 79
remote_pattern = r"^(https?://[^/]+/[^/]+/[^/@]+)(?:/(.*?))?(?:@([^/]+))?/?$"
# line 106
github_shorthand_pattern = r"^([^/]+)/([^/@]+)(?:/(.*?))?(?:@([^/]+))?/?$"
I verified this against the current source: the no-path forms then resolve ref='v2.0' while all with-path and no-ref cases (myorg/myrepo, myorg/myrepo/sub/dir@v2.0, adk@my-sample, the ADK-samples tree/main/... URL) are unchanged. Happy to provide a patch/test if useful — I noted CONTRIBUTING says PRs aren't currently accepted, so filing here.
Environment
google-agents-cli v1.0.0 (commit c40ed19)
- Python 3.12
Describe the bug
parse_agent_spec(insrc/google/agents/cli/scaffold/utils/remote_template.py) drops the@<ref>(branch/tag) when the spec has no sub-path, and bakes it into the clone URL instead. So pinning a whole-repo remote template to a tag/branch clones the wrong (or a nonexistent) URL at the defaultmain.The two spec forms both document an optional trailing ref:
The repo/name capture uses
[^/]+, which includes@, so when there is no sub-path to force backtracking it greedily swallows@<ref>. The dedicated(?:@([^/]+))?ref group never matches, andgit_refsilently falls back to"main". Theif "@" in template_pathfallback (line 90) doesn't help because in the no-path case the@reflands in the repo capture, not intemplate_path(which is"").Steps to reproduce
fetch_remote_templatethen runsgit clone --branch main https://github.com/myorg/myrepo@v2.0 …, which fails with a confusing "repository not found" for a repo that exists.Expected behavior
The
@<ref>should be parsed as the ref regardless of whether a sub-path is present:The with-path forms already work (
myorg/myrepo/sub/dir@v2.0→ refv2.0), which masks the bug.Suggested fix
Exclude
@from the repo-name character class so the ref group can match (GitHub org/repo names can't contain@, so this is safe):I verified this against the current source: the no-path forms then resolve
ref='v2.0'while all with-path and no-ref cases (myorg/myrepo,myorg/myrepo/sub/dir@v2.0,adk@my-sample, the ADK-samplestree/main/...URL) are unchanged. Happy to provide a patch/test if useful — I noted CONTRIBUTING says PRs aren't currently accepted, so filing here.Environment
google-agents-cliv1.0.0 (commitc40ed19)