---
name: Objective Management
description: Manage the parent objective for this task. Update the objective's details or break it down into sub-objectives. When users ask about parent objectives, ALWAYS invoke this skill first to check - never assume whether a parent objective exists.
argument-hint: update | breakdown
---

# Objective Management Skill

This skill allows you to help the user manage the parent objective that this task was launched from.

**IMPORTANT**: This skill requires explicit user approval before making any changes. Always explain what changes you're proposing and ask the user to confirm before executing.

## Available Commands

### 1. Update Parent Objective (`/objective update`)

Use this to help the user update the parent objective's details based on learnings from this task.

**When to use:**
- The user asks to update the parent objective
- Discoveries during this task suggest the objective needs refinement
- The scope or requirements have changed

**Process:**
1. Fetch the current objective details
2. Discuss proposed changes with the user
3. Only after user approval, submit the update

### 2. Create Sub-Objectives (`/objective breakdown`)

Use this to help the user break down the parent objective into smaller, more manageable sub-objectives.

**When to use:**
- The user wants to decompose a large objective
- The task reveals the objective is too broad
- Multiple distinct workstreams are identified

**Process:**
1. Fetch the current objective details and existing children
2. Propose a breakdown structure to the user
3. Only after user approval, create the sub-objectives

## How It Works

This skill communicates with the CoderFlow server via the objective management API. The server URL and task credentials are automatically available in the container environment.

### Environment Variables (automatically set when task has parent objective):
- `SOURCE_OBJECTIVE_ID` - The ID of the parent objective
- `CODERFLOW_SERVER_URL` - The CoderFlow server URL for API calls
- `TASK_ID` - This task's ID (for authentication)

### API Endpoints:
- `GET /api/objective-management/parent` - Fetch parent objective details
- `PATCH /api/objective-management/parent` - Update parent objective
- `POST /api/objective-management/sub-objectives` - Create sub-objectives
- `GET /api/objective-management/children` - List existing sub-objectives
- `GET /api/objective-management/siblings` - List sibling objectives

## Usage Examples

### Updating an Objective

```
User: "Update the parent objective to reflect that we also need to handle edge cases"

Agent: I'll help you update the parent objective. Let me first fetch the current details...

[Fetches objective]

Current objective:
- Name: "Implement user authentication"
- Instructions: "Add login and logout functionality"

I propose updating the instructions to:
"Add login and logout functionality, including edge case handling for:
- Invalid credentials
- Session expiration
- Concurrent login attempts"

Would you like me to apply this update? (Please confirm)

User: "Yes, apply it"

Agent: [Executes update via API]
Updated successfully!
```

### Breaking Down an Objective

```
User: "Break this objective into smaller tasks"

Agent: I'll help break down the parent objective. Let me fetch the details first...

[Fetches objective and existing children]

Current objective: "Build complete e-commerce checkout flow"
Existing sub-objectives: None

I propose breaking this into the following sub-objectives:

1. **Cart Management** - Implement add/remove items, quantity updates
2. **Payment Integration** - Integrate Stripe for payment processing
3. **Order Confirmation** - Create confirmation page and email notifications
4. **Shipping Calculation** - Implement shipping cost calculation

Would you like me to create these sub-objectives? (Please confirm)

User: "Yes, create them"

Agent: [Executes API calls to create sub-objectives]
Created 4 sub-objectives successfully!
```

## Implementation

The skill executes shell commands to interact with the CoderFlow API:

### Fetch Parent Objective Details
```bash
curl -s "${CODERFLOW_SERVER_URL}/api/objective-management/parent" \
  -H "X-Task-Id: ${TASK_ID}"
```

**Response:**
```json
{
  "taskId": "obj-xxx",
  "name": "Objective name",
  "status": "objective",
  "instructions": "Objective instructions...",
  "environment": "my-environment",
  "parentObjectiveId": null,
  "launchCount": 3
}
```

### Update Parent Objective
```bash
curl -s -X PATCH "${CODERFLOW_SERVER_URL}/api/objective-management/parent" \
  -H "Content-Type: application/json" \
  -H "X-Task-Id: ${TASK_ID}" \
  -d '{
    "name": "Updated objective name",
    "instructions": "Updated instructions..."
  }'
```

**Response:**
```json
{
  "success": true,
  "taskId": "obj-xxx",
  "name": "Updated objective name",
  "instructions": "Updated instructions...",
  "updatedAt": "2024-01-15T10:30:00Z"
}
```

### Create Sub-Objectives
```bash
curl -s -X POST "${CODERFLOW_SERVER_URL}/api/objective-management/sub-objectives" \
  -H "Content-Type: application/json" \
  -H "X-Task-Id: ${TASK_ID}" \
  -d '{
    "objectives": [
      {
        "name": "Sub-objective 1",
        "instructions": "Details for first sub-objective"
      },
      {
        "name": "Sub-objective 2",
        "instructions": "Details for second sub-objective"
      }
    ]
  }'
```

**Response:**
```json
{
  "success": true,
  "created": 2,
  "objectives": [
    {
      "taskId": "obj-yyy",
      "name": "Sub-objective 1",
      "instructions": "Details for first sub-objective",
      "parentObjectiveId": "obj-xxx",
      "sortOrder": 1000
    },
    {
      "taskId": "obj-zzz",
      "name": "Sub-objective 2",
      "instructions": "Details for second sub-objective",
      "parentObjectiveId": "obj-xxx",
      "sortOrder": 2000
    }
  ]
}
```

### List Existing Sub-Objectives (Children)
```bash
curl -s "${CODERFLOW_SERVER_URL}/api/objective-management/children" \
  -H "X-Task-Id: ${TASK_ID}"
```

**Response:**
```json
{
  "children": [
    {
      "taskId": "obj-yyy",
      "name": "Existing sub-objective",
      "sortOrder": 1000,
      "createdAt": "2024-01-14T09:00:00Z"
    }
  ],
  "parentObjectiveId": "obj-xxx"
}
```

### List Sibling Objectives
```bash
curl -s "${CODERFLOW_SERVER_URL}/api/objective-management/siblings" \
  -H "X-Task-Id: ${TASK_ID}"
```

## Important Notes

1. **User Approval Required**: Never execute updates or create sub-objectives without explicit user confirmation
2. **Explain Changes**: Always clearly explain what changes will be made before asking for approval
3. **Preserve Context**: When updating, preserve any existing context that's still relevant
4. **Check for Existing Children**: Before proposing a breakdown, always check for existing sub-objectives
5. **Atomic Operations**: Each sub-objective should be a self-contained unit of work
6. **Naming Conventions**: Use clear, descriptive names for sub-objectives
7. **Error Handling**: If an API call fails, explain the error to the user and suggest alternatives
