{
  "name": "write_work_json",
  "title": "工作JSON编写",
  "description": "生成work.json配置、验证JSON格式并写入文件",
  "group": "agent",
  "version": "1.0.0",
  "input_schema": {
    "type": "object",
    "properties": {
      "task": {
        "type": "string",
        "description": "需要编写的工作项描述"
      },
      "file_path": {
        "type": "string",
        "description": "work.json 文件写入路径"
      }
    },
    "required": ["task", "file_path"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "file_path": {
        "type": "string",
        "description": "写入的文件路径"
      },
      "passed": {
        "type": "boolean",
        "description": "是否通过校验"
      }
    }
  },
  "steps": [
    {
      "id": "generate",
      "description": "按work.json规范生成配置内容",
      "operator": "executor",
      "handler": "llm",
      "on_error": {
        "retry": 2,
        "retry_delay": 500
      },
      "params": {
        "system_prompt": "{{ $meta.system_prompt }}",
        "user_prompt": "{{ $input.task }}",
        "response_format": {
          "type": "json_object"
        }
      }
    },
    {
      "id": "validate_json",
      "description": "验证JSON语法和字段规范",
      "operator": "validator",
      "handler": "json",
      "params": {
        "code": "{{ $steps.generate.content }}"
      }
    },
    {
      "id": "check_valid",
      "description": "校验失败则中止，通过则写入文件",
      "operator": "dispatcher",
      "handler": "condition",
      "params": {
        "source": "{{ $steps.validate_json.valid }}",
        "operator": "truthy",
        "then_jump": "write_file",
        "else_jump": "end"
      }
    },
    {
      "id": "write_file",
      "description": "将work.json内容写入文件",
      "operator": "manager",
      "handler": "file",
      "params": {
        "action": "write",
        "file_path": "{{ $input.file_path }}",
        "content": "{{ $steps.generate.content }}"
      }
    }
  ]
}
