diff --git a/web/paperclip_client.py b/web/paperclip_client.py index 8306e61..91785fd 100644 --- a/web/paperclip_client.py +++ b/web/paperclip_client.py @@ -24,6 +24,11 @@ PLUGIN_ID = "53461b5a-7f58-411a-9952-72f9c8d4a328" # marcusgroup.legal-ai PAPERCLIP_API_URL = os.environ.get("PAPERCLIP_API_URL", "http://localhost:3100") PAPERCLIP_BOARD_API_KEY = os.environ.get("PAPERCLIP_BOARD_API_KEY", "") +# Default workspace attached to every new Paperclip project — points agents at +# the legal-ai source tree on the host. Override via env if the path differs. +LEGAL_AI_WORKSPACE_CWD = os.environ.get("LEGAL_AI_WORKSPACE_CWD", "/home/chaim/legal-ai") +LEGAL_AI_WORKSPACE_NAME = os.environ.get("LEGAL_AI_WORKSPACE_NAME", "legal-ai") + # Company IDs from Paperclip DB COMPANIES = { "licensing": "42a7acd0-30c5-4cbd-ac97-7424f65df294", # CMP — רישוי ובניה @@ -99,6 +104,8 @@ async def create_project( f"%{case_number}%", company_id, ) if existing: + # Backfill: ensure legacy projects also have a default workspace. + await _ensure_default_workspace(conn, str(existing["id"]), company_id) return { "id": str(existing["id"]), "company_id": company_id, @@ -114,6 +121,8 @@ async def create_project( VALUES ($1, $2::uuid, $3, $4, 'backlog', $5)""", project_id, company_id, project_name, description[:500] if description else "", color, ) + # Default primary workspace — points agents at the legal-ai source tree. + await _ensure_default_workspace(conn, project_id, company_id) # Create initial issue linked to the project issue_id, identifier = await _create_issue( conn, company_id, project_id, case_number, title, prefix, @@ -212,6 +221,34 @@ async def restore_project(case_number: str) -> dict: await conn.close() +async def _ensure_default_workspace( + conn: asyncpg.Connection, + project_id: str, + company_id: str, +) -> None: + """Idempotently attach a primary workspace to the project so the + "סביבות עבודה" tab appears in the Paperclip UI and agents wake up with + cwd=`/home/chaim/legal-ai`. No-op if any workspace already exists. + """ + existing = await conn.fetchval( + "SELECT id FROM project_workspaces WHERE project_id = $1::uuid LIMIT 1", + project_id, + ) + if existing: + return + + await conn.execute( + """INSERT INTO project_workspaces + (company_id, project_id, name, cwd, is_primary, source_type, visibility) + VALUES ($1::uuid, $2::uuid, $3, $4, TRUE, 'local_path', 'default')""", + company_id, project_id, LEGAL_AI_WORKSPACE_NAME, LEGAL_AI_WORKSPACE_CWD, + ) + logger.info( + "Attached default workspace (cwd=%s) to project %s", + LEGAL_AI_WORKSPACE_CWD, project_id, + ) + + async def _create_issue( conn: asyncpg.Connection, company_id: str,