{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/activity.schema.json",
  "title": "Office activity",
  "description": "What GET /v1/activity returns and `activity-snapshot.mjs --json` prints, and what each GET /v1/activity/stream event carries: one room per repository, one table per run (its team; a session no run claims sits at a table of its own), one seat per agent seen in the recent window, the orchestrator at the head. Derived from disk on every call. No field is machine-local: there are no paths, seat labels come from allow-listed fields only (tool name, file basename, sidecar description), and every free-text string has been through the redactor, so the redacted and the full view are the same document.",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion", "generatedAt", "recentMinutes", "rooms", "corridors", "counts"],
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time",
      "x-sensitivity": "none"
    },
    "recentMinutes": {
      "type": "number",
      "description": "A session or subagent whose transcript changed within this window has a desk.",
      "x-sensitivity": "none"
    },
    "costBudget": {
      "type": "object",
      "additionalProperties": false,
      "required": ["maxUsd", "warnPct", "onExceed"],
      "x-sensitivity": "none",
      "description": "The cost budget from prefs.global.costBudget, present only while it is enabled and valid. A run's spend (a table's estUsd) is judged against it: ok under warnPct of maxUsd, warn from there to maxUsd, exceeded above.",
      "properties": {
        "maxUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "warnPct": {
          "type": "number",
          "minimum": 1,
          "maximum": 99
        },
        "onExceed": {
          "enum": ["warn", "halt"]
        }
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rooms", "tables", "seats", "live", "waiting"],
      "x-sensitivity": "none",
      "properties": {
        "rooms": {
          "type": "integer",
          "minimum": 0
        },
        "tables": {
          "type": "integer",
          "minimum": 0
        },
        "seats": {
          "type": "integer",
          "minimum": 0
        },
        "live": {
          "type": "integer",
          "minimum": 0
        },
        "waiting": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "rooms": {
      "type": "array",
      "x-sensitivity": "none",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["repo", "tables"],
        "properties": {
          "repo": {
            "type": "string"
          },
          "tables": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/table"
            }
          }
        }
      }
    },
    "corridors": {
      "type": "array",
      "x-sensitivity": "none",
      "description": "Runs over more than one repository: the table and the rooms its corridor joins.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["tableId", "repos"],
        "properties": {
          "tableId": {
            "type": "string"
          },
          "repos": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "$defs": {
    "table": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "kind",
        "runType",
        "command",
        "taskId",
        "title",
        "host",
        "limited",
        "sessionId",
        "matchedBy",
        "repos",
        "phase",
        "now",
        "status",
        "waitingForYou",
        "waitingSince",
        "waitingSinceSource",
        "pendingQuestion",
        "tokens",
        "estUsd",
        "costSource",
        "repo",
        "location",
        "branch",
        "phaseHistory",
        "currentTask",
        "progress",
        "startedAt",
        "elapsedSeconds",
        "holder",
        "previousHolder",
        "seats",
        "source",
        "pr",
        "waitingFor",
        "channels"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "enum": ["run", "session", "solo", "unmatched"],
          "description": "run: a pipeline run; session: a session no run claims (outside the pipeline); unmatched: a session more than one run could claim, kept apart rather than guessed. solo: a session the office started for a one-person job, seated at a desk."
        },
        "command": {
          "type": ["string", "null"],
          "description": "The command the table runs, for its room sign: /multi-agent, /multi-agent:analysis, /multi-agent:test-gen. Null for a session no command owns."
        },
        "runType": {
          "enum": ["development", "analysis", "autopilot", null],
          "description": "Which pipeline the table runs: /multi-agent (development), /multi-agent:analysis, or an autopilot run. Null for a session no pipeline owns. The office names the room after it."
        },
        "taskId": {
          "type": ["string", "null"]
        },
        "title": {
          "type": ["string", "null"]
        },
        "host": {
          "enum": ["claude", "copilot", "codex"]
        },
        "limited": {
          "type": "boolean",
          "description": "true for a Copilot CLI or Codex session: no subagent detail exists there."
        },
        "sessionId": {
          "type": ["string", "null"]
        },
        "matchedBy": {
          "enum": ["session", "cwd-branch", null],
          "description": "How the session was tied to the run: the session id the run recorded, or its working directory and branch."
        },
        "repos": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "phase": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "name", "last"],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                },
                "last": {
                  "type": "integer",
                  "description": "The last phase id, for an n of last display."
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "currentTask": {
          "type": ["string", "null"],
          "description": "The task in progress in the phase in progress, from the mirrored task list."
        },
        "progress": {
          "type": ["number", "null"],
          "minimum": 0,
          "maximum": 1
        },
        "now": {
          "type": ["string", "null"]
        },
        "status": {
          "type": ["string", "null"]
        },
        "waitingForYou": {
          "type": "boolean"
        },
        "pendingQuestion": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "text", "kind", "options"],
              "properties": {
                "id": {
                  "type": "string"
                },
                "text": {
                  "type": "string"
                },
                "kind": {
                  "enum": ["single-select", "multi-select"]
                },
                "options": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["id", "label"],
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "label": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "tokens": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["in", "out", "cached"],
              "properties": {
                "in": {
                  "type": "integer",
                  "minimum": 0
                },
                "out": {
                  "type": "integer",
                  "minimum": 0
                },
                "cached": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "estUsd": {
          "type": ["number", "null"]
        },
        "costSource": {
          "enum": ["tracker-state", "transcript", "not-measured"],
          "description": "Where tokens and estUsd come from. tracker-state: the run's own tracker; transcript: the usage records in a plain session's own transcripts, an estimate at list price; not-measured means the numbers are null, never 0."
        },
        "repo": {
          "type": "string",
          "description": "The room this table stands in."
        },
        "location": {
          "enum": ["worktree", "local", "unknown"],
          "description": "worktree: the run works in its own worktree; local: in the main checkout; unknown when the state does not say."
        },
        "branch": {
          "type": ["string", "null"]
        },
        "phaseHistory": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "status",
              "startedAt",
              "completedAt",
              "progress",
              "tasks",
              "model",
              "now",
              "tokens",
              "subs"
            ],
            "properties": {
              "id": {
                "type": ["integer", "null"]
              },
              "progress": {
                "type": ["number", "null"],
                "minimum": 0,
                "maximum": 1,
                "description": "How far the phase is, from its mirrored task list; null when it has none."
              },
              "tasks": {
                "type": "array",
                "maxItems": 20,
                "description": "The phase's task list as the host task widget shows it (mirrored by phase-tracker.sh task), redacted and cut short.",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["subject", "status"],
                  "properties": {
                    "subject": {
                      "type": "string",
                      "maxLength": 80
                    },
                    "status": {
                      "enum": ["pending", "in_progress", "completed"]
                    }
                  }
                }
              },
              "name": {
                "type": "string"
              },
              "status": {
                "type": "string"
              },
              "startedAt": {
                "type": ["string", "null"]
              },
              "completedAt": {
                "type": ["string", "null"]
              },
              "model": {
                "type": ["string", "null"],
                "maxLength": 40,
                "description": "The model that spent this phase's tokens, as the tracker recorded it; null until one is set."
              },
              "now": {
                "type": ["string", "null"],
                "maxLength": 60,
                "description": "What the phase is doing, for a running or failed phase only. Falls back to the name of the in-progress sub-step, and is null when neither exists."
              },
              "tokens": {
                "type": ["integer", "null"],
                "minimum": 0,
                "description": "Input plus output tokens for this phase; null when none were recorded."
              },
              "subs": {
                "type": "array",
                "maxItems": 20,
                "description": "The phase's own steps, as the card and the subject counter use them.",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["id", "name", "status"],
                  "properties": {
                    "id": {
                      "type": "string",
                      "maxLength": 12
                    },
                    "name": {
                      "type": "string",
                      "maxLength": 60
                    },
                    "status": {
                      "enum": ["pending", "in_progress", "completed"]
                    }
                  }
                }
              }
            }
          }
        },
        "startedAt": {
          "type": ["string", "null"]
        },
        "elapsedSeconds": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "holder": {
          "type": ["string", "null"],
          "description": "The seat id that holds the work now."
        },
        "previousHolder": {
          "type": ["string", "null"],
          "description": "The last seat of an earlier phase, for drawing the handoff."
        },
        "seats": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/seat"
          }
        },
        "job": {
          "description": "The office job a session was started for (run tables carry none).",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "role", "team"],
              "properties": {
                "id": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "team": {
                  "type": "boolean"
                }
              }
            }
          ]
        },
        "source": {
          "type": ["object", "null"],
          "additionalProperties": false,
          "required": ["kind", "jira", "issue"],
          "description": "Where the run's work came from, for the table sign: a Jira key, a GitHub issue or free text. Null for a session or a run that recorded neither.",
          "properties": {
            "kind": {
              "enum": ["jira", "github", "text"]
            },
            "jira": {
              "type": ["string", "null"],
              "pattern": "^[A-Z][A-Z0-9_]{0,30}-[0-9]{1,9}$"
            },
            "issue": {
              "type": ["string", "null"],
              "pattern": "^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[0-9]{1,9}$"
            }
          }
        },
        "pr": {
          "type": ["object", "null"],
          "additionalProperties": false,
          "required": ["number"],
          "properties": {
            "number": {
              "type": "integer",
              "minimum": 1
            }
          },
          "description": "The pull request the run opened, by number only."
        },
        "waitingSince": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "When the run began waiting for a person: its own record of when it parked, else its state file's modification time. Null when the run is not waiting, and for a session no run tracks."
        },
        "waitingSinceSource": {
          "enum": ["state", "file-time", null],
          "description": "Where waitingSince came from: state is exact, file-time is approximate because a rewrite of the file moves it. Null when waitingSince is null."
        },
        "waitingFor": {
          "enum": [
            "maturity",
            "user-channels-choice",
            "local-test",
            "attended-reply",
            "question",
            "terminal",
            null
          ],
          "description": "What a waiting run waits for: a step it paused at (the run's waitingFor), or terminal when its session holds a question open in its own window."
        },
        "channels": {
          "type": "array",
          "maxItems": 5,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["channel", "status"],
            "properties": {
              "channel": {
                "enum": ["pr", "jira", "confluence", "wiki", "issue"]
              },
              "status": {
                "enum": ["posted", "skipped", "failed"]
              }
            }
          },
          "description": "Where the run's report went, per adapter, for the run window; empty for a session or before Phase 5."
        }
      }
    },
    "seat": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tasks",
        "mcp",
        "id",
        "sessionId",
        "agentId",
        "agentType",
        "role",
        "label",
        "known",
        "sprite",
        "color",
        "model",
        "modelLabel",
        "description",
        "state",
        "tool",
        "detail",
        "live",
        "startedAt",
        "lastAt",
        "phase",
        "status",
        "doing"
      ],
      "properties": {
        "tasks": {
          "type": "array",
          "maxItems": 20,
          "description": "The desk's own task list from its transcript (TaskCreate / TaskUpdate / TodoWrite), phase tiles left out, redacted and cut short.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["subject", "status"],
            "properties": {
              "subject": {
                "type": "string",
                "maxLength": 80
              },
              "status": {
                "enum": ["pending", "in_progress", "completed"]
              }
            }
          }
        },
        "mcp": {
          "type": "array",
          "maxItems": 8,
          "description": "The desk's last MCP calls, newest last: server, tool, whether it is still running, failed or answered, and how long it took. No input or result.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["server", "tool", "state", "ms", "at"],
            "properties": {
              "server": {
                "type": "string"
              },
              "tool": {
                "type": "string"
              },
              "state": {
                "enum": ["running", "ok", "error"]
              },
              "ms": {
                "type": ["integer", "null"],
                "minimum": 0
              },
              "at": {
                "type": ["string", "null"]
              }
            }
          }
        },
        "id": {
          "type": "string"
        },
        "sessionId": {
          "type": ["string", "null"]
        },
        "agentId": {
          "type": ["string", "null"],
          "description": "null for the session's own (orchestrator) desk."
        },
        "agentType": {
          "type": ["string", "null"]
        },
        "role": {
          "type": "string"
        },
        "label": {
          "type": "string",
          "description": "The role, numbered when agents of the same role sit at one table (Reviewer 1, Reviewer 2)."
        },
        "known": {
          "type": "boolean",
          "description": "false when the agent type is in no role table entry and the raw type is shown."
        },
        "sprite": {
          "type": "integer",
          "minimum": 0
        },
        "color": {
          "type": "string",
          "pattern": "^#[0-9a-f]{6}$"
        },
        "model": {
          "type": ["string", "null"]
        },
        "modelLabel": {
          "type": ["string", "null"]
        },
        "description": {
          "type": ["string", "null"],
          "maxLength": 64
        },
        "state": {
          "enum": ["reading", "writing", "spawning", "waiting", "idle", "done"]
        },
        "tool": {
          "type": ["string", "null"]
        },
        "detail": {
          "type": ["string", "null"]
        },
        "live": {
          "type": ["boolean", "null"],
          "description": "Whether the session is alive per `claude agents --json`; null when that list cannot be read."
        },
        "startedAt": {
          "type": ["string", "null"],
          "format": "date-time"
        },
        "lastAt": {
          "type": ["string", "null"],
          "format": "date-time"
        },
        "phase": {
          "type": ["integer", "null"],
          "description": "The run phase the agent was spawned in; null for the orchestrator or outside a run."
        },
        "status": {
          "enum": ["working", "idle", "done"]
        },
        "doing": {
          "type": "string",
          "description": "What the seat is doing in a few plain words (Reading Foo.swift, Running a command), else the raw tool name."
        }
      }
    }
  }
}
