{
  "openapi": "3.1.0",
  "info": {
    "title": "forks.world",
    "description": "Create and publish swim-lane process maps.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://forks.world"
    }
  ],
  "paths": {
    "/api/identity": {
      "post": {
        "operationId": "createAccount",
        "summary": "Create an account from a random key (once per conversation).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "minLength": 16,
                    "maxLength": 200,
                    "description": "A random secret of 32 or more characters you make up."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The account's handle and points."
          }
        }
      }
    },
    "/api/agent/processes": {
      "post": {
        "operationId": "saveProcess",
        "summary": "Save a process map. Include id to update a private one you already saved; publish true to make it public. Public processes cannot be changed (409 public_frozen).",
        "parameters": [
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The account key (the person's own, or the one you created)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Process"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved process: id, visibility, publicUrl."
          },
          "400": {
            "description": "invalid_process, with a list of problems to fix."
          }
        }
      }
    },
    "/api/processes/{id}/export": {
      "get": {
        "operationId": "exportProcess",
        "summary": "Get the finished document for a process you saved.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "md",
                "html",
                "skill",
                "gpt"
              ]
            },
            "description": "md (default): the Markdown document. html: the swim-lane flow diagram as a self-contained HTML page. skill: a Claude SKILL.md. gpt: ChatGPT custom-GPT instructions."
          },
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The document as text."
          }
        }
      }
    },
    "/api/agent/quick": {
      "post": {
        "operationId": "quickPublish",
        "summary": "Sign up as a guest, save the process and publish it, all in one call. No setup, no key needed. Returns publicUrl and a key.",
        "parameters": [
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only if you already have a key; otherwise a new guest is created."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Process"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved process: id, publicUrl, flowUrl, handle, and key (for a new guest)."
          },
          "400": {
            "description": "invalid_process, with a list of problems to fix."
          }
        }
      }
    },
    "/api/public": {
      "get": {
        "operationId": "listPublic",
        "summary": "Search published processes by text or tag.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tag",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Published processes with id, title, author, tags, steps and likes."
          }
        }
      }
    },
    "/api/public/{id}/comments": {
      "post": {
        "operationId": "addComment",
        "summary": "Comment on a published process, optionally pinned to a step.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "step": {
                    "type": "string",
                    "description": "mapId|stepId, e.g. m_root|s1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new comment."
          }
        }
      }
    },
    "/api/agent/combine": {
      "post": {
        "operationId": "combineProcesses",
        "summary": "Build a bigger process out of existing published ones, in order. Creates (and optionally publishes) a process whose steps link to each part.",
        "parameters": [
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Omit to sign up as a guest."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "parts"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "parts": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Published process ids (publicId), in order."
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "publish": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new process: id, publicUrl, handle, key."
          }
        }
      }
    },
    "/api/public/{id}/export": {
      "get": {
        "operationId": "getPublicProcess",
        "summary": "Read a published process (Markdown by default; format=html|skill|gpt). Read parts before combining or linking them.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "md",
                "html",
                "skill",
                "gpt"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The process as text."
          }
        }
      }
    },
    "/api/public/{id}/fork": {
      "post": {
        "operationId": "forkProcess",
        "summary": "Make your own private copy of a published process to change.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ptw-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The new copy: {id}. Change it with saveProcess using that id."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Lane": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "person",
              "system"
            ]
          }
        }
      },
      "Step": {
        "type": "object",
        "required": [
          "id",
          "lane",
          "label"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "lane": {
            "type": "string",
            "description": "Id of the lane that does this step."
          },
          "label": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "start",
              "task",
              "decision",
              "subprocess",
              "end"
            ]
          },
          "uses": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Lane ids of tools used in this step."
          },
          "next": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "required": [
                    "to"
                  ],
                  "properties": {
                    "to": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          },
          "link": {
            "type": "string",
            "description": "Id of another process: a published one (publicId) or one you saved or that is shared with you (id). The step becomes a link to that whole process."
          },
          "pain": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "properties": {
                  "level": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 3,
                    "description": "1 annoying, 2 painful, 3 critical"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            ],
            "description": "Mark a step as a pain point: where it hurts (slow, error-prone, manual, costly). A note, or {level, note}."
          }
        }
      },
      "Process": {
        "type": "object",
        "required": [
          "title",
          "lanes",
          "steps"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id of a private process you saved earlier, to update it. Public processes cannot be changed."
          },
          "title": {
            "type": "string"
          },
          "publish": {
            "type": "boolean"
          },
          "lanes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Lane"
            }
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Step"
            }
          },
          "layers": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "parentStep",
                "lanes",
                "steps"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "parentStep": {
                  "type": "string",
                  "description": "Id of the main-layer step that opens into this layer."
                },
                "parentLayer": {
                  "type": "string",
                  "description": "Id of another layer, if parentStep is in that layer."
                },
                "lanes": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Lane"
                  }
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Step"
                  }
                }
              }
            }
          },
          "tags": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "string"
            },
            "description": "Up to 8 short lowercase tags (sales, science, daily life) so people can find the process."
          },
          "thumbnailArt": {
            "type": "object",
            "properties": {
              "emoji": {
                "type": "string"
              },
              "hue": {
                "type": "integer",
                "minimum": 0,
                "maximum": 359
              }
            },
            "description": "A generated thumbnail for the preview card: a gradient with one big emoji."
          }
        }
      }
    }
  }
}
