# Specification: Ingestion Workflows

## 1. The "Repo Walker" (Initial Index)
**Trigger:** Admin adds a new GitHub Repository URL.

**Steps:**
1.  **Clone:** Worker clones the repo to a scratch volume.
2.  **Vectorize (Files):**
    *   Iterate all non-ignored files.
    *   Chunk text (sliding window).
    *   Send to Embedding API -> Write to Qdrant.
    *   Write `(:Repository)-[:CONTAINS]->(:File)` to Neo4j.
3.  **Graph Build (Basic):**
    *   Parse `import` statements (Regex/AST).
    *   Resolve paths (e.g., `import ./utils` -> `src/utils.ts`).
    *   Write `(:File)-[:IMPORTS]->(:File)` to Neo4j.
4.  **Graph Build (History):**
    *   Iterate Git Log (last 6 months).
    *   Create `(:Commit)` nodes.
    *   Link `(:Commit)-[:MODIFIED]->(:File)`.
    *   Parse Commit Messages for "Fixes #123".
    *   Link `(:Commit)-[:LINKED_TO]->(:Issue)`.

## 2. The "Web Hook" (Incremental Sync)
**Trigger:** GitHub App sends `push` or `pull_request` event.

**Steps for `pull_request`:**
1.  Receive Event JSON.
2.  Upsert `(:PR)` node in Neo4j.
3.  Write Payload (Title, Body) to Qdrant `work_items` collection.
4.  Link `(:PR)-[:MODIFIED_BY]->(:User)`.
5.  Link `(:PR)-[:MODIFIED]->(Files in Diff)`.

**Steps for `push` to main:**
1.  identify changed files.
2.  Re-run **Vectorize** step for those files only.
3.  Update modification timestamps in Graph.

## 3. The "Entity Linker" (Background Job)
**Role:** Clean up and densify the graph asynchronously.
**Frequency:** Every hour.

**Logic:**
*   **User Resolution:** Merge `("Matt Davidson", "matthew@company.com")` and `("matchdav", "matchdav@users.noreply.github.com")` into a single `(:User)` identity.
*   **Code Reference Linking:** Scan Issue comments for code snippets or file paths. Create `(:Issue)-[:MENTIONS]->(:File)` links.
