Skip to content

patch: Support monorepo subdirectory cloning in patch flow #16

@rdwj

Description

@rdwj

Problem

The patch flow in `check_for_updates()` and `patch_category()` uses `clone_template(url, temp_path)` to fetch the latest template for comparison. This works for standalone template repos (MCP server, gateway, UI, sandbox) but not for agent or workflow templates, which live in subdirectories of a monorepo (`templates/agent-loop/` and `templates/workflow/`).

Cloning the full agent-template repo and comparing against the project root would match against monorepo-level files (top-level Makefile, packages/, etc.) instead of the actual template subdirectory.

Proposed change

When patching a monorepo-based project, the patch flow needs to:

  1. Read `template.subdir` from `.template-info` (added in patch: Store project type in .template-info metadata #13)
  2. Clone the full repo to a temp directory
  3. Resolve the subdirectory within the clone (`temp_path / subdir`)
  4. Use that subdirectory as the comparison root (instead of `temp_path` itself)

This is essentially what `clone_template_subdir()` already does during `create`, but the patch code needs to replicate the subdir-extraction logic without calling `clone_template_subdir` directly (since that function copies to the target, which isn't what patch wants — patch needs the template files in-place for comparison).

Approach

Add a helper in `tools/patching.py`:

```python
def _clone_template_for_patch(template_info: dict) -> tuple[Path, Path]:
"""Clone template and return (temp_dir_path, template_root).

For standalone repos, template_root == temp_dir_path.
For monorepo subdirs, template_root == temp_dir_path / subdir.

Caller must clean up temp_dir_path.
"""

```

Then `check_for_updates()` and `patch_category()` use `template_root` for glob/compare instead of `temp_path`.

Part of

Tracking issue: #12
Depends on: #13 (needs `template.subdir` in `.template-info`)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions