paperclip: auto-attach default workspace on project creation
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 8s
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 8s
Without a primary workspace on a project, the "סביבות עבודה" tab in Paperclip stays hidden (gate: enableIsolatedWorkspaces && S0t list non-empty), and agents wake with cwd=`/home/chaim` instead of the legal-ai source tree. New helper inserts a primary workspace pointing at LEGAL_AI_WORKSPACE_CWD (default /home/chaim/legal-ai) on both new and legacy/existing-project paths. Idempotent — skips if any workspace row already exists. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user