Adds a minimal but real ACP stack for the opencode process: - pkg/config: process.args default ["acp"] (opencodeCommand still "opencode") - internal/process: NewManager(command, args) — exec.Command uses args - internal/acp (new): NDJSON transport + JSON-RPC client over the existing process stdio. Implements initialize / session/new / session/prompt / session/cancel. Serves fs/read_text_file and fs/write_text_file from the workspace's fs.FileSystem. terminal/* requests get MethodNotFound. - internal/service/acp_service: per-workspace Client + mutex; starts the process on first prompt; transparently re-init on restart. - internal/api/acp_handler: GET /acp/status, GET /acp/history, POST /acp/prompt, POST /acp/cancel. - internal/model/acp: API DTOs. - internal/acp/client_test: NDJSON split-lines, request/response correlation, notification dispatch, agent-initiated request handling (fs + terminal). Existing process WS endpoint and Shell subsystem are unchanged. Conversation: 019f354c-a51b-7ec3-83ad-c647e9b50b19
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
package api
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"codespace/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// NewRouter builds a Gin engine with all API routes registered.
|
|
func NewRouter(workspaces *service.WorkspaceService, files *service.FileService, processes *service.ProcessService, shells *service.ShellService, acpSvc *service.AcpService, lg *slog.Logger, ginMode string) *gin.Engine {
|
|
gin.SetMode(ginMode)
|
|
r := gin.New()
|
|
r.Use(gin.Recovery())
|
|
r.Use(requestLogger(lg))
|
|
|
|
wsHandler := &workspaceHandler{svc: workspaces}
|
|
fileHandler := &fileHandler{svc: files}
|
|
procHandler := &processHandler{svc: processes}
|
|
shellHandler := &shellHandler{svc: shells}
|
|
acpHandler := &acpHandler{svc: acpSvc}
|
|
|
|
r.GET("/healthz", healthHandler)
|
|
|
|
api := r.Group("/api")
|
|
api.GET("/workspaces", wsHandler.list)
|
|
api.POST("/workspaces", wsHandler.create)
|
|
api.GET("/workspaces/:id", wsHandler.get)
|
|
api.DELETE("/workspaces/:id", wsHandler.delete)
|
|
|
|
api.GET("/workspaces/:id/files", fileHandler.list)
|
|
api.GET("/workspaces/:id/files/read", fileHandler.read)
|
|
api.GET("/workspaces/:id/files/stat", fileHandler.stat)
|
|
api.PUT("/workspaces/:id/files/write", fileHandler.write)
|
|
api.POST("/workspaces/:id/files/mkdir", fileHandler.mkdir)
|
|
api.DELETE("/workspaces/:id/files", fileHandler.remove)
|
|
api.POST("/workspaces/:id/files/rename", fileHandler.rename)
|
|
|
|
api.POST("/workspaces/:id/process/start", procHandler.start)
|
|
api.POST("/workspaces/:id/process/stop", procHandler.stop)
|
|
api.POST("/workspaces/:id/process/restart", procHandler.restart)
|
|
api.GET("/workspaces/:id/process/status", procHandler.status)
|
|
api.GET("/workspaces/:id/process/ws", procHandler.ws)
|
|
|
|
api.POST("/workspaces/:id/shell/start", shellHandler.start)
|
|
api.POST("/workspaces/:id/shell/stop", shellHandler.stop)
|
|
api.POST("/workspaces/:id/shell/restart", shellHandler.restart)
|
|
api.GET("/workspaces/:id/shell/status", shellHandler.status)
|
|
api.GET("/workspaces/:id/shell/ws", shellHandler.ws)
|
|
api.GET("/workspaces/:id/acp/status", acpHandler.status)
|
|
api.GET("/workspaces/:id/acp/history", acpHandler.history)
|
|
api.POST("/workspaces/:id/acp/prompt", acpHandler.prompt)
|
|
api.POST("/workspaces/:id/acp/cancel", acpHandler.cancel)
|
|
|
|
return r
|
|
}
|
|
|
|
func healthHandler(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
|
}
|