# Skill Generation Flow

How Agenvoy creates, updates, and validates a skill when you ask the agent to build a new workflow or scheduled skill.

## Flow

```mermaid
graph TB
    Start[User asks to create or update a skill] --> IsSched{Scheduled task or cron?}
    IsSched -->|No| GuideSkill[read_guides skill_generate]
    IsSched -->|Yes| GuideBoth[read_guides cron_generate + skill_generate<br/>ask_user if task or time is missing]
    GuideSkill --> Design
    GuideBoth --> Design[Confirm tool names via find_tools<br/>Draft YAML frontmatter + standalone body]
    Design --> WriteSkill[write_skill mode=write or patch or copy<br/>Automatic SKILL.md validation runs on every write/patch/copy]
    WriteSkill -->|Invalid SKILL.md| Fix[Fix issues via write_skill mode=patch]
    Fix --> WriteSkill
    WriteSkill -->|Valid| BindSched{Scheduled skill?}
    BindSched -->|Yes| WriteSched[write_schedule mode=write<br/>Bind cron or one-shot task]
    BindSched -->|No| Done
    WriteSched --> Done[Report skill path, name, and trigger]
```

## Step-by-step sequence

1. **Load the guide** — Call `read_guides(topics=["skill_generate"])` (and include `"cron_generate"` when creating a scheduled skill; if task or explicit time is missing for a schedule, call `ask_user` first).
2. **Draft with real tool names** — Verify every referenced tool name with `find_tools`. Give `SKILL.md` valid YAML frontmatter (`name` matching the directory, `description`, optional `version`) and keep any helper scripts under the skill's own `scripts/` directory.
3. **Write or patch (auto-validated)** — Call `write_skill` (`mode=write`, `patch`, or `copy`) targeting `~/.config/agenvoy/skills/<name>/SKILL.md` (or `scheduler/<short>-<hash8>/SKILL.md` for scheduled skills). Every `write`, `patch`, and `copy` automatically runs `skill.Validate` in-process and reports `valid: <path>` or `invalid: <path>` with every issue.
4. **Bind schedule (if scheduled)** — Call `write_schedule(mode=write)` to bind the cron expression or one-shot time, then report the resulting path and trigger.

## Editing a trusted skill

If `write_skill` (`write`, `patch`, or `copy`) modifies a skill listed in `trust_skill` (excluding files under `.doc/`), the edit still succeeds, but trust is automatically revoked and the user is prompted to re-trust it in `/skill` → `permission`.

## Version history

- v1.6.3: Added the dedicated skill generation flow page, reflecting automatic `skill.Validate` checks on `write_skill` `write`/`patch`/`copy` and removal of `mode=validate`.
