> ## Documentation Index
> Fetch the complete documentation index at: https://docs.namastex.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Task Templates

> Manage reusable task templates

## Overview

Task Templates allow you to create reusable task configurations for common workflows like bug fixes, feature development, code reviews, and refactoring.

**Base URL**: `http://localhost:8887/api/task-templates`

***

## List Templates

Get all available task templates.

```http theme={null}
GET /api/task-templates
```

### Query Parameters

| Parameter  | Type    | Description                  |
| ---------- | ------- | ---------------------------- |
| `page`     | integer | Page number (default: 1)     |
| `limit`    | integer | Items per page (default: 20) |
| `category` | string  | Filter by template category  |
| `search`   | string  | Search by template name      |

<RequestExample>
  ```bash cURL theme={null}
  curl "http://localhost:8887/api/task-templates?page=1&limit=10"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:8887/api/task-templates?page=1&limit=10');
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'http://localhost:8887/api/task-templates',
      params={'page': 1, 'limit': 10}
  )
  templates = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "data": [
      {
        "id": "template_bug_fix",
        "name": "Bug Fix Workflow",
        "description": "Standard bug fix workflow with reproduction, fix, and testing",
        "category": "bugfix",
        "tasks": [
          {
            "title": "Reproduce bug",
            "description": "Create minimal reproduction",
            "order": 1
          },
          {
            "title": "Fix bug",
            "description": "Implement fix",
            "order": 2
          },
          {
            "title": "Add tests",
            "description": "Add regression tests",
            "order": 3
          }
        ],
        "createdAt": "2024-01-10T00:00:00Z"
      }
    ],
    "pagination": {
      "page": 1,
      "limit": 10,
      "total": 5,
      "pages": 1
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```
</ResponseExample>

***

## Get Template

Get a specific template by ID.

```http theme={null}
GET /api/task-templates/:id
```

<RequestExample>
  ```bash cURL theme={null}
  curl http://localhost:8887/api/task-templates/template_feature
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:8887/api/task-templates/template_feature');
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get('http://localhost:8887/api/task-templates/template_feature')
  template = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "data": {
      "id": "template_feature",
      "name": "Feature Development",
      "description": "Complete feature development workflow",
      "category": "feature",
      "tasks": [
        {
          "title": "Design feature",
          "description": "Create technical design",
          "order": 1,
          "estimatedTime": 60
        },
        {
          "title": "Implement feature",
          "description": "Write implementation code",
          "order": 2,
          "estimatedTime": 180
        },
        {
          "title": "Write tests",
          "description": "Add unit and integration tests",
          "order": 3,
          "estimatedTime": 90
        },
        {
          "title": "Update documentation",
          "description": "Document new feature",
          "order": 4,
          "estimatedTime": 30
        }
      ],
      "metadata": {
        "totalEstimatedTime": 360,
        "difficulty": "medium"
      }
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "success": false,
    "error": {
      "code": "NOT_FOUND",
      "message": "Template not found"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```
</ResponseExample>

***

## Create Template

Create a new task template.

```http theme={null}
POST /api/task-templates
```

<ParamField body="name" type="string" required>
  Template name
</ParamField>

<ParamField body="description" type="string" required>
  Template description
</ParamField>

<ParamField body="category" type="string" required>
  Template category (e.g., "bugfix", "feature", "refactor", "review")
</ParamField>

<ParamField body="tasks" type="array" required>
  Array of task definitions with title, description, and order
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST http://localhost:8887/api/task-templates \
    -H "Content-Type: application/json" \
    -d '{
      "name": "API Endpoint Template",
      "description": "Template for creating new API endpoints",
      "category": "development",
      "tasks": [
        {
          "title": "Define API schema",
          "description": "Create OpenAPI specification",
          "order": 1
        },
        {
          "title": "Implement endpoint",
          "description": "Write handler and validation",
          "order": 2
        },
        {
          "title": "Add tests",
          "description": "Unit and integration tests",
          "order": 3
        },
        {
          "title": "Update API docs",
          "description": "Document in API reference",
          "order": 4
        }
      ]
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:8887/api/task-templates', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      name: 'API Endpoint Template',
      description: 'Template for creating new API endpoints',
      category: 'development',
      tasks: [...]
    })
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'http://localhost:8887/api/task-templates',
      json={
          'name': 'API Endpoint Template',
          'description': 'Template for creating new API endpoints',
          'category': 'development',
          'tasks': [...]
      }
  )
  template = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "data": {
      "id": "template_api_endpoint",
      "name": "API Endpoint Template",
      "description": "Template for creating new API endpoints",
      "category": "development",
      "tasks": [
        {
          "title": "Define API schema",
          "description": "Create OpenAPI specification",
          "order": 1
        },
        {
          "title": "Implement endpoint",
          "description": "Write handler and validation",
          "order": 2
        },
        {
          "title": "Add tests",
          "description": "Unit and integration tests",
          "order": 3
        },
        {
          "title": "Update API docs",
          "description": "Document in API reference",
          "order": 4
        }
      ],
      "createdAt": "2024-01-15T11:00:00Z"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```
</ResponseExample>

***

## Update Template

Update an existing template.

```http theme={null}
PUT /api/task-templates/:id
```

<ParamField body="name" type="string">
  Updated template name
</ParamField>

<ParamField body="description" type="string">
  Updated template description
</ParamField>

<ParamField body="category" type="string">
  Updated template category
</ParamField>

<ParamField body="tasks" type="array">
  Updated task definitions array
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT http://localhost:8887/api/task-templates/template_api_endpoint \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Updated Template Name",
      "description": "Updated description with new details"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:8887/api/task-templates/template_api_endpoint', {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      name: 'Updated Template Name',
      description: 'Updated description'
    })
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.put(
      'http://localhost:8887/api/task-templates/template_api_endpoint',
      json={
          'name': 'Updated Template Name',
          'description': 'Updated description'
      }
  )
  template = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "data": {
      "id": "template_api_endpoint",
      "name": "Updated Template Name",
      "description": "Updated description with new details",
      "category": "development",
      "tasks": [...],
      "updatedAt": "2024-01-15T14:30:00Z"
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "success": false,
    "error": {
      "code": "NOT_FOUND",
      "message": "Template not found"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```
</ResponseExample>

***

## Delete Template

Delete a template.

```http theme={null}
DELETE /api/task-templates/:id
```

<Warning>
  Deleting a template is permanent and cannot be undone.
</Warning>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE http://localhost:8887/api/task-templates/template_api_endpoint
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('http://localhost:8887/api/task-templates/template_api_endpoint', {
    method: 'DELETE'
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.delete('http://localhost:8887/api/task-templates/template_api_endpoint')
  result = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "success": true,
    "data": {
      "deleted": true,
      "templateId": "template_api_endpoint"
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "success": false,
    "error": {
      "code": "NOT_FOUND",
      "message": "Template not found"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```
</ResponseExample>

***

## Built-in Templates

Forge includes several built-in templates:

### Bug Fix

```yaml theme={null}
name: Bug Fix Workflow
tasks:
  - Reproduce bug
  - Fix issue
  - Add regression tests
  - Update changelog
```

### Feature Development

```yaml theme={null}
name: Feature Development
tasks:
  - Design feature
  - Implement code
  - Write tests
  - Update documentation
```

### Code Review

```yaml theme={null}
name: Code Review
tasks:
  - Review code quality
  - Check test coverage
  - Verify documentation
  - Approve or request changes
```

### Refactoring

```yaml theme={null}
name: Refactoring
tasks:
  - Analyze current code
  - Plan refactoring approach
  - Execute refactoring
  - Verify tests pass
```

***

## SDK Examples

```typescript theme={null}
import { ForgeClient } from '@automagik/forge-sdk';

const forge = new ForgeClient();

// List templates
const templates = await forge.templates.list();

// Get template
const template = await forge.templates.get('template_bug_fix');

// Create from template
const tasks = await forge.templates.createTasks('proj_123', 'template_feature', {
  context: {
    feature: 'User notifications',
    description: 'Add email and push notifications'
  }
});

// Create custom template
const newTemplate = await forge.templates.create({
  name: 'My Custom Template',
  category: 'custom',
  tasks: [...]
});
```

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Tasks API" icon="list-check" href="/forge/api/tasks">
    Create tasks from templates
  </Card>

  <Card title="Workflows" icon="diagram-project" href="/forge/workflows/feature-development">
    Template-based workflows
  </Card>
</CardGroup>
