Files
clawmates/migrations/0011_companies_orgs.sql
T
Omar SobhandClaude Opus 4.8 3eca4ed70c Recursive deploy ladder: Company + Org tiers, mesh mark, two-tier rail
Completes the scale ladder (single → team → company → org). Every tier is a
topology whose nodes are the tier below; running a parent recursively runs each
child's sub-topology down to the leaf claws.

Backend:
- migration 0011: companies/company_teams, orgs/org_companies, topology_runs.tier
- cm-db repos for companies + orgs (mirror teams)
- TurnRequest.attrs (forwarded from node.attrs) for child-id binding
- SubTopologyExecutor (recursive_exec.rs): a parent "turn" runs the child's
  sub-topology; durability via parent updated_at keepalive + cancel propagation
  + depth cap; boxed future breaks the org→company recursion
- topology_worker selects executor by job.tier
- routes: /api/companies, /api/orgs (create/list/get/run) + unified
  /api/structure/{level}/{id} for the zoom canvas

Frontend:
- MeshMark: node-mesh brand glyph (replaces the claw PNG), tier variants
- TopologyGraphView: optional onNodeClick/nodeMeta + dark-token theming
- StructureCanvas + Breadcrumb: one recursive zoom view for every tier
  (drill down on node click, breadcrumb up); TeamRunPanel extracted + shared
- two-tier Discord-style rail: StructureRail (mesh mark + org/company/team
  glyphs + tools popover + deploy + user) | RosterColumn (selected group's
  children, or your claws); SecondaryNav for cross-cutting tools
- ComposeWizard (company/org) wired into DeployWizard; /companies + /orgs pages

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-18 14:25:06 -07:00

57 lines
2.6 KiB
SQL

-- Companies and Orgs: the upper rungs of the deploy ladder (single → team →
-- company → org). The model is recursive — *every tier is a topology whose
-- nodes are the tier below*. A team binds nodes to claws (migration 0010); a
-- company binds nodes to teams; an org binds nodes to companies. Children are
-- resolved from these tables at execution time (cm-topology stays pure — the
-- parent graph never embeds a child graph, only a string id in node.attrs).
-- A company = a baseline TOPOLOGY staffed with real teams. `graph` is the
-- TopologyGraph whose nodes carry attrs["team_id"] = the bound team's uuid
-- (and attrs["agent"] = the same id, so the recursive executor receives it via
-- TurnRequest the same way a team node forwards its claw alias).
CREATE TABLE companies (
id UUID PRIMARY KEY,
workspace_id UUID NOT NULL REFERENCES workspaces (id) ON DELETE CASCADE,
name TEXT NOT NULL,
kind TEXT NOT NULL, -- TopologyKind (snake_case)
graph JSONB NOT NULL, -- TopologyGraph (nodes/edges)
status TEXT NOT NULL DEFAULT 'active',
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX companies_workspace_idx ON companies (workspace_id, created_at DESC);
CREATE TABLE company_teams (
company_id UUID NOT NULL REFERENCES companies (id) ON DELETE CASCADE,
node_id TEXT NOT NULL, -- topology node id in companies.graph
team_id UUID NOT NULL REFERENCES teams (id) ON DELETE CASCADE,
role TEXT NOT NULL,
PRIMARY KEY (company_id, node_id)
);
-- An org = a TOPOLOGY whose nodes are companies. Nodes carry
-- attrs["company_id"] = the bound company's uuid.
CREATE TABLE orgs (
id UUID PRIMARY KEY,
workspace_id UUID NOT NULL REFERENCES workspaces (id) ON DELETE CASCADE,
name TEXT NOT NULL,
kind TEXT NOT NULL,
graph JSONB NOT NULL,
status TEXT NOT NULL DEFAULT 'active',
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX orgs_workspace_idx ON orgs (workspace_id, created_at DESC);
CREATE TABLE org_companies (
org_id UUID NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
node_id TEXT NOT NULL,
company_id UUID NOT NULL REFERENCES companies (id) ON DELETE CASCADE,
role TEXT NOT NULL,
PRIMARY KEY (org_id, node_id)
);
-- Which deploy tier a durable run belongs to. 'team' drives claws directly
-- (today's path); 'company'/'org' drive the recursive sub-topology executor.
ALTER TABLE topology_runs ADD COLUMN tier TEXT NOT NULL DEFAULT 'team';