Skip to content

Implement Project Management API for Multi-Project Sessions #64

@riatzukiza

Description

@riatzukiza

Summary

This feature implements a comprehensive project management API that allows a single instance of Opencode to run sessions for multiple projects and different worktrees per project.

Context

The current Opencode instance manages sessions for a single project directory. This spec defines a new API structure to support multiple projects with multiple worktrees each, providing proper isolation and management capabilities.

Note: Some aspects are partially covered by issue anomalyco#1877 which proposes root folder aggregation and cwd metadata for sessions.

Requirements

API Implementation

Implement the following REST API endpoints:

GET /project -> Project[]
POST /project/init -> Project

GET /project/:projectID/session -> Session[]
GET /project/:projectID/session/:sessionID -> Session
POST /project/:projectID/session -> Session
{
  id?: string
  parentID?: string
  directory: string
}
DELETE /project/:projectID/session/:sessionID
POST /project/:projectID/session/:sessionID/init
POST /project/:projectID/session/:sessionID/abort
POST /project/:projectID/session/:sessionID/share
DELETE /project/:projectID/session/:sessionID/share
POST /project/:projectID/session/:sessionID/compact

GET /project/:projectID/session/:sessionID/message -> { info: Message, parts: Part[] }[]
GET /project/:projectID/session/:sessionID/message/:messageID -> { info: Message, parts: Part[] }
POST /project/:projectID/session/:sessionID/message -> { info: Message, parts: Part[] }

POST /project/:projectID/session/:sessionID/revert -> Session
POST /project/:projectID/session/:sessionID/unrevert -> Session
POST /project/:projectID/session/:sessionID/permission/:permissionID -> Session

GET /project/:projectID/session/:sessionID/find/file -> string[]
GET /project/:projectID/session/:sessionID/file -> { type: "raw" | "patch", content: string }
GET /project/:projectID/session/:sessionID/file/status -> File[]

POST /log

// Provider and config endpoints with directory resolution
GET /provider?directory=<resolve path> -> Provider
GET /config?directory=<resolve path> -> Config
GET /project/:projectID/agent?directory=<resolve path> -> Agent
GET /project/:projectID/find/file?directory=<resolve path> -> File

Key Features

  1. Project Isolation: Each project maintains its own session namespace and configuration
  2. Worktree Support: Sessions can be created for different working directories within a project
  3. Session Management: Full CRUD operations for sessions within each project context
  4. File Operations: File access and status operations scoped to project/session contexts
  5. Directory Resolution: Provider, config, and agent endpoints support directory-based resolution

Definition of Done

  • All API endpoints implemented with proper request/response validation
  • Project and session data models implemented with appropriate persistence layer
  • Directory resolution logic handles cross-project path references correctly
  • Session isolation between projects is maintained
  • Integration with existing Opencode CLI and TUI interfaces
  • Comprehensive test coverage for all endpoints and edge cases
  • Documentation for API usage and migration from single-project setup

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions