weft

repository·main·Indexed 19 days ago

https://github.com/jonesphillip/weft

An AI-driven task management platform designed for self-hosting on Cloudflare. Weft utilizes agents to perform tasks such as managing emails, updating spreadsheets, and writing code, with a focus on data privacy. It features a registry-driven architecture for integrations, support for the Model Context Protocol (MCP), and a two-stage execution model for scheduled tasks to ensure human review of state-mutating actions.

Tokens
8K
Snippets
28
Records
47
Agent score
67%

What's inside weft

  1. How scheduled tasks work in Weft

    main

    Scheduled tasks (Daily, Weekly, or Cron) follow a two-stage execution model to ensure safety:

    1. Trigger: A Durable Object alarm triggers the scheduled time.
    2. Read-Only Parent Agent: The parent agent runs with read-only tool access. It cannot send emails, create PRs, or modify documents. Its purpose is to analyze data (e.g., scanning an inbox) and call create_task to fork child tasks.
    3. Full-Access Child Tasks: Each child task receives its own agent context with full tool access. These tasks run until they complete or require human approval for state-mutating actions.

    This architecture allows agents to perform overnight analysis while ensuring that no actual changes (like sending an email) occur without human review.

  2. Configure board settings and tools

    main

    Each Weft board has its own configuration accessible via the Settings menu. Settings are organized into two main areas:

    • Credentials:
      • Anthropic API key: Required for agents to function. This is stored per-board.
      • OAuth accounts: Connect your Google and GitHub accounts for integration access.
    • Integrations:
      • Enable built-in tools like Gmail, Docs, Sheets, or GitHub.
      • Add remote MCP servers to bring in custom tools via the Model Context Protocol.
  3. Set up Google OAuth credentials

    main

    To use Gmail, Docs, or Sheets integrations, you must configure a Google OAuth client:

    1. In the Google Cloud Console, enable the Gmail API, Google Docs API, and Google Sheets API.
    2. Configure the OAuth consent screen (External mode is sufficient; add yourself as a test user).
    3. Create OAuth client ID credentials for a Web application.
    4. Authorized JavaScript origins:
      • Dev: http://localhost:5174
      • Prod: https://weft.<your-subdomain>.workers.dev
    5. Authorized redirect URIs:
      • Dev: http://localhost:5174/google/callback
      • Prod: https://weft.<your-subdomain>.workers.dev/google/callback
    6. Add the resulting GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET to your .env file.
  4. Deploy Weft to Cloudflare

    main

    To deploy Weft to your Cloudflare account, you must first set your required secrets using Wrangler, then run the production deployment command.

    Required Secrets:

    • ENCRYPTION_KEY: Encrypts stored credentials. Generate with openssl rand -base64 32.
    • GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET: For Google integrations.
    • GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET: For GitHub integration.

    Deployment Commands:

    npx wrangler secret put ENCRYPTION_KEY --env production
    npx wrangler secret put GOOGLE_CLIENT_ID --env production
    npx wrangler secret put GOOGLE_CLIENT_SECRET --env production
    npx wrangler secret put GITHUB_CLIENT_ID --env production
    npx wrangler secret put GITHUB_CLIENT_SECRET --env production
    
    npm run deploy:prod
  5. Install and run Weft locally

    main

    To set up Weft on your local machine, follow these steps:

    1. Clone and install dependencies:
      git clone https://github.com/jonesphillip/weft.git
      cd weft
      npm install
    2. Configure environment variables: Copy the example file to .env:
      cp .env.example .env
      Edit .env to include your ENCRYPTION_KEY (generated via openssl rand -base64 32) and any OAuth credentials for Google or GitHub.
    3. Start the development server:
      npm run dev
      This launches the Vite frontend and Wrangler worker. Access the application at http://localhost:5174.
    git clone https://github.com/jonesphillip/weft.git
    cd weft
    npm install
    cp .env.example .env
    npm run dev
  6. Set up GitHub OAuth credentials

    main

    To use GitHub integrations, configure a GitHub OAuth App:

    1. Go to GitHub Developer Settings and click New OAuth App.
    2. Set the Homepage URL to your Weft deployment URL.
    3. Set the Authorization callback URL:
      • Dev: http://localhost:5174/github/callback
      • Prod: https://weft.<your-subdomain>.workers.dev/github/callback
    4. Copy the Client ID and Client Secret to your .env file.
  7. How to build new integrations

    main

    Weft uses a registry-driven architecture for integrations. To add a new built-in integration, follow these steps:

    1. Create the MCP server: Implement the server logic within the worker/ directory (e.g., worker/google/GmailMCP.ts).
    2. Register the server: Add the new server to the registry in worker/mcp/AccountMCPRegistry.ts.
    3. Handle OAuth (if required): If the integration requires OAuth, add the necessary handler in worker/handlers/oauth.ts.

    The registry handles tool schemas, OAuth configuration, and workflow guidance, meaning you do not need to modify the core agent workflow logic.

  8. Core Domain Entities: User, Board, Column, and Task

    main

    The core data model of Weft revolves around a hierarchical structure:

    1. User: Represents an authenticated user with an id, email, and an optional logoutUrl.
    2. Board: The top-level container for organization. It contains columns, a name, an ownerId, and optional toolConfig for agentic capabilities.
    3. Column: A vertical grouping within a Board used to organize tasks. It has a position for ordering.
    4. Task: The fundamental unit of work. Tasks belong to a columnId and boardId. They include title, description, priority ('low' | 'medium' | 'high' | 'critical'), and position. Tasks can also have a parentTaskId for nesting and a scheduleConfig for automation.
  9. Use MCP Servers for Tool Integration

    main

    Weft supports the Model Context Protocol (MCP) to connect boards to external tools and data sources via MCPServer.

    Server Configuration:

    • type: Either 'remote' or 'hosted'.
    • authType: Supports 'none', 'oauth', 'api_key', or 'bearer'.
    • transportType: For remote servers, defaults to 'streamable-http', but can be set to 'sse'.

    MCP Tools: Each server provides one or more MCPTools. Tools are defined by an inputSchema (JSON Schema) which describes the arguments required to call the tool.

    export interface MCPServer {
      id: string;
      boardId: string;
      name: string;
      type: 'remote' | 'hosted';
      endpoint?: string;
      authType: 'none' | 'oauth' | 'api_key' | 'bearer';
      credentialId?: string;
      transportType?: 'streamable-http' | 'sse';
      enabled: boolean;
      status: 'connected' | 'disconnected' | 'error';
      urlPatterns?: MCPUrlPattern[];
      createdAt: string;
      updatedAt: string;
    }
  10. Configure authentication modes

    main

    Authentication in Weft is controlled by the AUTH_MODE variable in wrangler.jsonc.

    AUTH_MODEDescriptionUse case
    noneNo authentication. Uses USER_ID/USER_EMAIL from config as singleton user.Personal/single-user deployments
    accessCloudflare Access JWT verification. Requires ACCESS_AUD/ACCESS_TEAM secrets.Multi-user or login-protected deployments

    To enable Cloudflare Access for multi-user deployments:

    1. Create a Self-hosted application in the Cloudflare Zero Trust dashboard.
    2. Add an Access policy.
    3. Retrieve the Application Audience (AUD) Tag and your team name from the dashboard.
    4. Set the secrets via Wrangler:
      npx wrangler secret put ACCESS_AUD --env production
      npx wrangler secret put ACCESS_TEAM --env production
    5. Update wrangler.jsonc to set AUTH_MODE to "access" in the production environment.
    "env": {
      "production": {
        "vars": {
          "AUTH_MODE": "access",
          // ...
        }
      }
    }
  11. Configure Board Tools and Agent Capabilities

    main

    Boards can be extended with agentic capabilities via BoardToolConfig. This allows the board to interact with external systems using defined tools and credentials.

    ToolDefinition: Defines a specific capability.

    • type: Can be 'mcp' (Model Context Protocol), 'api', 'filesystem', or 'browser'.
    • config: Contains endpoint, permissions, and scope.

    CredentialRef: References encrypted credentials stored by the system.

    SandboxSettings: Controls the execution environment for tools, allowing limits on memoryLimitMb, timeoutMs, and allowedDomains.

    export interface BoardToolConfig {
      tools: ToolDefinition[];
      credentials: CredentialRef[];
      sandboxConfig?: SandboxSettings;
    }
  12. Understand Workflow Plans and Execution

    main

    A WorkflowPlan represents a sequence of steps (an agentic plan) to achieve a goal.

    Lifecycle (WorkflowPlanStatus): 'planning' -> 'draft' -> 'approved' -> 'executing' -> 'checkpoint' -> 'completed' | 'failed'

    Workflow Steps: Each plan consists of WorkflowSteps. Steps can be of type:

    • tool_call: Invoking a specific tool.
    • checkpoint: A pause point for human intervention or state saving.
    • internal: System-level operations.
    • agent: An LLM-driven turn.
    • tool: General tool usage.

    Results and Artifacts: Successful workflows produce WorkflowArtifacts, which can be 'google_doc', 'google_sheet', 'gmail_message', 'github_pr', 'file', or 'other'. The WorkflowResult captures the success status and any generated artifacts or step results.