Skip to content

parse_agent_spec drops @<ref> when the spec has no sub-path (bakes it into the clone URL) #53

Description

@Osamaali313

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions