Stitch

From mikeprasad/aria-knowledge · View interactive version

Stitch is an AI agent skill from the GitHub repository mikeprasad/aria-knowledge. Build or verify cross-repo STITCH.md linking backend + frontends in a product group. Modes: create, verify, diff, section. Uses CODEMAPs as drift source by default. Trigger: '/stitch create {group}', '/stitch diff {group}'.

How to use this skill

Skill file

/stitch — Cross-repo stitch layer

Generate a cross-repo binding artifact (STITCH.md) for a product group (backend + one or more frontends). Tables only, not narrative. Drift detection uses CODEMAP endpoint sections by default with explicit opt-in fallback to grep.

Step 0: Load config

<!-- shared-block: group-loader -->

Read ~/.gemini/antigravity/aria-knowledge.local.md. Parse YAML frontmatter projects_groups (multi-line YAML block — see CONFIG.md "Skill-only fields" for canonical schema, including the optional stitch_path sub-field and custom-role conventions).

Look up <tag> in projects_list (get project_root) and projects_groups (get role → folder dict).

Auto-propose bootstrap (when projects_groups[<tag>] is missing but <project_root> contains multiple sync-bound codebases — separate repo dirs or a contract→clients seam):

  1. Scan <project_root> one level deep for sub-directories with repo or contract markers:
  1. Handle role conflicts: if two dirs inferred as same role, prompt user to assign distinct keys (web, web-admin, etc.).
  2. Propose the group structure to user: sub-repo names, inferred roles, YAML block to insert. Show a preview diff of the change to ~/.gemini/antigravity/aria-knowledge.local.md.
  3. On approval, edit the config file to add the projects_groups[<tag>] entry, preserving existing fields and YAML structure.
  4. On decline, stop with "proceed after registering group manually".

Resolve each (role, folder) pair to absolute path: <project_root>/<folder>. For each absolute path, read CODEMAP.md if it exists. Read <project_root>/STITCH.md if it exists. Return resolved path map + warnings for any missing CODEMAPs.

<!-- /shared-block: group-loader -->

For /stitch specifically: the group MUST have ≥2 distinct codebases bound by a shared contract — at least one contract/backend source role + at least one client role that must stay in sync with it. Whether they live in separate git repos or one monorepo is irrelevant — the load-bearing condition is "multiple codebases that drift apart," not "multiple repos." A monorepo's contract/ → ios/+android/+backend/ seam (the dual-native keystone — one OpenAPI/proto/GraphQL source feeding generated clients) is exactly the drift seam STITCH exists to document. Only stop when there's a single undifferentiated codebase with no such seam: "/stitch needs ≥2 contract-bound codebases; this looks like one codebase — use /codemap."

Step 1: Resolve paths & output target

For create mode, require BACKEND_ROOT/CODEMAP.md and each frontend_root/CODEMAP.md. If any missing, list what's missing and recommend running /codemap create in each affected repo first.

Step 2: Load template (create mode only)

Start from ${CLAUDE_PLUGIN_ROOT}/template/stitch/STITCH.template.md. Fill Group identity with:

Step 3: Build sections 2–5 (create + section modes)

Using the loaded CODEMAPs, populate:

Only populate cells with information that appears in the loaded CODEMAPs. Leave cells blank rather than inventing.

Step 4: Drift log (create + diff modes)

Precedence (check in order):

  1. User-provided script — check for <workspace_root>/analyze-stitch.sh or <workspace_root>/analyze-stitch.py. If either exists, invoke with JSON stdin:

```json

{"backend_root": "<abs path>", "frontend_roots": ["<abs path>", ...], "group": "<tag>"}

```

Expect JSON stdout:

```json

{"fe_orphans": [{"call": "...", "file": "..."}, ...], "be_orphans": [{"route": "...", "file": "..."}, ...]}

```

Label output section: "Drift source: user script (analyze-stitch.)"*.

  1. CODEMAP-based (default expected path) — check both CODEMAPs for required endpoint sections:
  1. Missing CODEMAP endpoint data — prompt user explicitly (do NOT silently fall through):

```

STITCH drift detection requires endpoint sections in both CODEMAPs.

Currently missing:

Recommended: run /codemap section <missing section> in the affected repo(s) first

(better accuracy, self-improving as you maintain CODEMAPs).

Fallback: proceed with grep-based drift (coarse — catches presence/absence,

misses HTTP methods, dynamic paths, non-REST conventions). Output will be

labeled "Drift source: fallback grep."

Choose: [C]odemap (stop here, regenerate first) / [G]rep fallback (proceed now)

```

  1. On [G]rep fallback — grep FE for /api/ strings (and api/v1/, apiSlice, fetch( variants), grep backend for route definitions (Django urls.py patterns, or equivalent). Compare normalized sets. Label output: "Drift source: fallback grep — CODEMAPs incomplete; see recommendation above".
  1. On [C]odemap choice — exit /stitch with instruction: "Run /codemap section <name> in <repo>, then re-invoke /stitch <mode> <tag>."

Populate STITCH.md section 6 (Drift log):

Step 5: Write STITCH.md (create mode)

Overwrite safety (mirrors /distill Step 4):

Modes

| Mode | Behavior |

|------|----------|

| create <group> | Execute Steps 0-5. Write full STITCH_FILE. |

| verify <group> | Re-read STITCH_FILE tables; check cited file paths still exist on disk; flag stale rows. No rewrite unless user requests. |

| diff <group> | Run drift detection only (Step 4). Print drift summary; do not modify STITCH_FILE. |

| section <group> <n> | Rebuild section n in-place in STITCH_FILE. Skips overwrite safety (only that section changes). |

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.