**Important Note**: This prompt may run in non-interactive environments (e.g., CI/CD, automation scripts).

**Non-interactive Mode**:
- Do NOT use `AskUserQuestion` or any interactive tools
- When user input is needed:
  - Use reasonable default values
  - Skip optional confirmation steps
  - Document any assumptions made

**Interactive Mode**:
- Follow normal interactive flow, prompt for user input as needed

---

<task>
Analyze repository structure and generate or update the `hagindex.yml` file.
{{#if monoSpecsRepositories}}

**Note**: This task requires generating separate index files for multiple sub-repositories in a MonoSpecs project.
{{/if}}
</task>

<context>
You are working in the following Git repository:
<project_path>
{{ projectPath }}
</project_path>
{{#if repositoryPath}}
<sub_repository>
Sub-repository path: {{ repositoryPath }}
This is a sub-repository of a MonoSpecs project. You should analyze and operate within this sub-repository path.
</sub_repository>
{{/if}}
{{#if monoSpecsRepositories}}

<MonoSpecs Sub-repository List>
This is the list of sub-repositories in the MonoSpecs project. You need to generate a separate hagindex.yml file for each sub-repository:
{{#each monoSpecsRepositories}}
- Sub-repository: {{{ displayName }}}
  Path: {{{ path }}}
  Type: {{{ type }}}
  Icon: {{{ icon }}}
{{/each}}
</MonoSpecs>
{{/if}}

<Recent Commits Analysis>
**Important**: Before analyzing the repository structure, check for recent Git commits to understand the latest changes in the project.

Use `git log` to get the most recent commits (e.g., `git log -n 10 --pretty=format:"%h - %an, %ar : %s"`). This will help you:
- Understand what files have been recently modified
- Identify areas of the codebase that are actively being worked on
- Prioritize reading files that reflect the current state of the project

When generating the hagindex.yml, consider the context from recent commits to ensure the index reflects the most up-to-date structure and focus areas.
</Recent Commits Analysis>

The `hagindex.yml` file is used for:
- Quickly understanding the repository structure
- Finding key entry points and important files
- Providing high-level overview for documentation or UI display
- Allowing developers to select specific aspects of the repository for deeper exploration

You need to:
1. Explore the repository structure (using Bash, ls, find, etc.)
2. Identify key entry points, configuration files, and important directories
3. Generate or update the `hagindex.yml` file in the specified format
</context>

<working_directory>
Use this project path as your working directory: {{ projectPath }}
{{#if repositoryPath}}
Sub-repository path: {{{ repositoryPath }}}
{{/if}}
{{#if monoSpecsRepositories}}

For MonoSpecs mode, you need to perform analysis and file generation operations in each of the following sub-repository paths.
{{/if}}
</working_directory>

<tools>
You may use the following tools:
- Bash - Execute commands (git, ls, find, cat, etc.)
- Read - Read file contents
- Write - Write files (generate hagindex.yml)
- Edit - Edit existing files
- Glob - Find files by pattern
</tools>

<requirements>
  <requirement>
    **hagindex.yml Structure**:

    The file must contain the following fields:
    - `version`: Version number (currently use "1.0")
    - `name`: Repository name
    - `displayName`: Display name (for UI display)
    - `description`: Brief description (for UI display)
    - `indexedAt`: Index date (YYYY-MM-DD format)
    - `generatedBy`: Generator (e.g., "claude-code")
    - `quickRef.catalogs`: List of available catalog definitions
    - `quickRef.{catalogId}`: List of items for each catalog
  </requirement>

  <requirement>
    **Catalog Focus Requirements (Very Important)**:

    Generated catalogs must focus on the project's **physical structure, functional features, and business capabilities**, NOT technology stack:

    1. **Exclude Technology Stack Tags**:
       - DO NOT generate generic technology names like ".NET", "Electron", "React", "TypeScript", "SignalR", "Orleans", "Astro", "Ansible"
       - The technologies catalog should focus on **core architecture components or infrastructure**, not specific technology frameworks

    2. **Prioritize Feature Module (features) Identification**:
       - **MUST identify the project's business functions, feature modules, or core capabilities**
       - Examples: "User Authentication", "Order Management", "Payment Processing", "Data Analysis", "API Interfaces"
       - The features catalog is the most valuable indexing dimension, helping users find code with specific features

    3. **Valuable Catalog Types**:
       - `entryPoints` - Entry points (startup entries for applications, services, tools)
       - `configFiles` - Key configuration files
       - `directories` - Important directory structure
       - `features` - **Business feature modules (most important, prioritize adding)**
       - `workflows` - Common workflows or commands
       - `environments` - Environment configurations
       - `coreComponents` - Core components (e.g., "Database Access Layer", "Message Queue", "Cache System")

    4. **Index Content Based on Project Type**:
       - Frontend projects: Index components, pages, apiClients, stores, hooks
       - Backend projects: Index dataModels, services, apis, repositories, migrations
       - Desktop projects: Index windows, controls, viewModels, services, platformIntegration
  </requirement>

  <requirement>
    **Catalog Definition Format**:
    ```yaml
    quickRef:
      catalogs:
        - id: "entryPoints"
          title: "Entry Points"
          desc: "Main entry points for different purposes"
        - id: "configFiles"
          title: "Config Files"
          desc: "Key configuration files"
        - id: "directories"
          title: "Directories"
          desc: "Important directories"
    ```
  </requirement>

  <requirement>
    **Item List Format**:
    ```yaml
    quickRef:
      entryPoints:
        - title: "Project Name"
          desc: "Brief description of the project"
          path: "path/to/project"

      configFiles:
        - title: "Config File"
          desc: "Purpose of the config file"
          path: "path/to/config"

      directories:
        - title: "Directory"
          desc: "What the directory contains"
          path: "path/to/dir"

      features:
        - title: "Feature Module"
          desc: "Description of the feature module"
          path: "path/to/feature"
    ```
  </requirement>

  <requirement>
    **Technology Stack Awareness (Very Important)**:

    Based on the project's technology stack type, index different key content:

    1. **Frontend Projects** (type: "frontend", "web", "react", "vue", "angular", etc.):
       - **components** - Key React/Vue/Angular components
       - **pages** - Main pages and routes
       - **apiClients** - API client calls
       - **stores** - State management (Redux, Vuex, Context, etc.)
       - **hooks** - Custom Hooks

    2. **Backend Projects** (type: "backend", "api", "service", etc.):
       - **dataModels** - Data models/entities
       - **services** - Service layer (Business Logic)
       - **apis** - API controllers/endpoints
       - **repositories** - Data access layer
       - **migrations** - Database migrations

    3. **Desktop Projects** (type: "desktop", "electron", "tauri", "winforms", "wpf", etc.):
       - **windows** - Windows/views
       - **controls** - Custom controls
       - **viewModels** - View models (MVVM)
       - **services** - Desktop services
       - **platformIntegration** - Platform integration features

    4. **Common Catalogs** (all project types):
       - **entryPoints** - Entry points
       - **configFiles** - Configuration files
       - **directories** - Directory structure
       - **features** - Business feature modules
  </requirement>

  <requirement>
    **Best Practices**:
    1. Keep each catalog concise (3-10 items maximum)
    2. **features catalog is the most important** - prioritize identifying business feature modules
    3. Only include meaningful entries
    4. Verify paths exist before adding them
    5. Accurately reflect the current repository state
  </requirement>
</requirements>

<steps>
{{#if monoSpecsRepositories}}
1. Iterate through the MonoSpecs sub-repository list and perform the following for each sub-repository:
{{#each monoSpecsRepositories}}
   - Processing sub-repository: {{{ displayName }}} (path: {{{ path }}}, type: {{{ type }}})
{{/each}}

2. For each sub-repository, perform type-specific indexing:
   - For frontend project 
     - Index components, pages, apiClients
     - Index stores, hooks
   - For backend project 
     - Index dataModels, services, apis
     - Index repositories, migrations
   - For desktop project 
     - Index windows, controls, viewModels
     - Index services, platformIntegration
{{else}}
1. Explore repository structure:
   - List top-level directories
   - Check monorepo configuration (monospecs.yaml, package.json, pnpm-workspace.yaml, etc.)
   - Identify sub-projects (if monorepo)

2. Define catalogs:
   - Always include: entryPoints, configFiles, directories
   - **Must add features catalog**: Identify project's business feature modules
   - Add as needed: workflows, environments, coreComponents, etc.

3. Populate items:
   - Identify relevant items for each catalog
   - Each needs: title (required), desc (required), path (optional)
   - **features catalog should focus on business functions**, not technology stack

4. Generate YAML:
   - Check if hagindex.yml already exists
   - If it exists, read and update the content
   - If it doesn't exist, create a new file
   - Write the final file using the Write tool
{{/if}}
</steps>

<output>
{{#if monoSpecsRepositories}}
When complete, for each sub-repository output:
1. The path to the generated or updated hagindex.yml file (format: sub-repository path|hagindex.yml)
2. Statistics on the number of catalogs and items for each sub-repository
3. Key findings (if any)
{{else}}
When complete, output:
1. The path to the generated or updated hagindex.yml file
2. Statistics on the number of catalogs and items included
3. Key findings (if any)
{{/if}}
</output>

<examples>
{{#if monoSpecsRepositories}}
**MonoSpecs Multi-Repository Example**:
```yaml
# File path: repos/hagicode-core/hagindex.yml
version: "1.0"
name: "hagicode-core"
displayName: "HagiCode Core Library"
description: "Core codebase for the Hagicode project"
indexedAt: "2026-03-03"
generatedBy: "claude-code"

quickRef:
  catalogs:
    - id: "entryPoints"
      title: "Entry Points"
      desc: "Main entry points for different purposes"
    - id: "dataModels"
      title: "Data Models"
      desc: "Core data models and entities"
    - id: "services"
      title: "Services"
      desc: "Business logic services"
    - id: "apis"
      title: "API Endpoints"
      desc: "API controllers and endpoints"
    - id: "features"
      title: "Feature Modules"
      desc: "Main feature modules of the project"

  entryPoints:
    - title: "Main Program Entry"
      desc: "Application startup entry point"
      path: "src/Program.cs"

  dataModels:
    - title: "User Entity"
      desc: "User data model"
      path: "src/Models/User.cs"
    - title: "Order Entity"
      desc: "Order data model"
      path: "src/Models/Order.cs"

  services:
    - title: "User Service"
      desc: "User-related business logic"
      path: "src/Services/UserService.cs"
    - title: "Order Service"
      desc: "Order-related business logic"
      path: "src/Services/OrderService.cs"

  apis:
    - title: "User API"
      desc: "User management endpoints"
      path: "src/Controllers/UserController.cs"
    - title: "Order API"
      desc: "Order management endpoints"
      path: "src/Controllers/OrderController.cs"

  features:
    - title: "User Authentication"
      desc: "User login and permission management"
      path: "src/Auth"
```
{{else}}
**Simple Repository Example**:
```yaml
version: "1.0"
name: "my-app"
displayName: "My Application"
description: "A simple web application"
indexedAt: "2026-03-03"
generatedBy: "claude-code"

quickRef:
  catalogs:
    - id: "entryPoints"
      title: "Entry Points"
      desc: "Main entry points for different purposes"
    - id: "configFiles"
      title: "Config Files"
      desc: "Key configuration files"
    - id: "directories"
      title: "Directories"
      desc: "Important directories"
    - id: "features"
      title: "Features"
      desc: "Key features and capabilities"

  entryPoints:
    - title: "Main App"
      desc: "React application entry point"
      path: "src/App.tsx"

  configFiles:
    - title: "package.json"
      desc: "NPM package configuration"
      path: "package.json"

  directories:
    - title: "src"
      desc: "Source code directory"
      path: "src"

  features:
    - title: "User Authentication"
      desc: "User registration, login and permissions"
      path: "src/auth"
    - title: "Data Management"
      desc: "Data CRUD operations and persistence"
      path: "src/data"
```

**Monorepo Example**:
```yaml
version: "1.0"
name: "monorepo"
displayName: "Monorepo Project"
description: "A TypeScript monorepo with multiple packages"
indexedAt: "2026-03-03"
generatedBy: "claude-code"

quickRef:
  catalogs:
    - id: "entryPoints"
      title: "Entry Points"
      desc: "Main entry points for different purposes"
    - id: "configFiles"
      title: "Config Files"
      desc: "Key configuration files"
    - id: "directories"
      title: "Directories"
      desc: "Important directories"
    - id: "features"
      title: "Features"
      desc: "Key features and capabilities"
    - id: "workflows"
      title: "Workflows"
      desc: "Common workflows and commands"

  entryPoints:
    - title: "Web App"
      desc: "Next.js web application"
      path: "apps/web"
    - title: "API Server"
      desc: "Express API server"
      path: "packages/api"

  configFiles:
    - title: "pnpm-workspace.yaml"
      desc: "PNPM workspace configuration"
      path: "pnpm-workspace.yaml"
    - title: "turbo.json"
      desc: "Turborepo configuration"
      path: "turbo.json"

  directories:
    - title: "apps"
      desc: "Application packages"
      path: "apps"
    - title: "packages"
      desc: "Shared packages"
      path: "packages"

  features:
    - title: "User Authentication"
      desc: "Cross-package user authentication"
      path: "packages/auth"
    - title: "Order Management"
      desc: "Order creation, payment and logistics"
      path: "packages/orders"

  workflows:
    - title: "Build All Packages"
      desc: "Build all packages in the monorepo"
      path: "turbo.json"
```
{{/if}}
</examples>
