Documentation
¶
Overview ¶
Package serve provides port file lifecycle management and web session bootstrap for the td serve HTTP server.
Package serve provides the HTTP API layer for td serve, including response envelopes, DTOs with explicit JSON serialization, and request validation helpers.
Index ¶
- Constants
- func BumpSessionActivity(database *db.DB, sessionID string) error
- func DeletePortFile(baseDir string) error
- func GenerateInstanceID() (string, error)
- func GetOrCreateWebSession(database *db.DB) (*db.SessionRow, error)
- func HandleAddComment(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleAddDependency(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleApprove(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleBlock(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleClose(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleCreateBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleCreateIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleDeleteBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleDeleteComment(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleDeleteDependency(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleDeleteIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleGetBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleGetIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleHealth(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleListBoards(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleListIssues(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleListLabels(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleListSessions(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleMonitor(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleRecordReview(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleReject(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleRemoveBoardPosition(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleReopen(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleReview(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleSetBoardPosition(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleSetFocus(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleStart(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleStats(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleUnblock(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleUpdateBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func HandleUpdateIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
- func IsPortFileStale(info *PortInfo) bool
- func IsServerHealthy(port int) bool
- func ServeCloseDecisionForTest(mode reviewpolicy.Mode, issue *models.Issue, sessionID string, ...) reviewpolicy.CloseEligibility
- func ServeReviewerDecisionForTest(mode reviewpolicy.Mode, issue *models.Issue, sessionID string, ...) reviewpolicy.ReviewerEligibility
- func StartSessionHeartbeat(ctx context.Context, database *db.DB, sessionID string)
- func WriteError(w http.ResponseWriter, code, message string, status int)
- func WritePortFile(baseDir string, info *PortInfo) error
- func WriteSuccess(w http.ResponseWriter, data interface{}, status int)
- func WriteValidation(w http.ResponseWriter, fields []FieldError)
- type ActivityItemDTO
- type BoardCreateBody
- type BoardDTO
- type BoardPositionBody
- type BoardUpdateBody
- type CommentCreateBody
- type CommentDTO
- type DependencyCreateBody
- type DependencyDTO
- type Envelope
- type ErrorPayload
- type FieldError
- type FocusBody
- type HandlerConfig
- type HandlerContext
- type HandoffDTO
- type IssueCreateBody
- type IssueDTO
- type IssueReviewDTO
- type IssueReviewSummary
- type IssueUpdateBody
- type LogDTO
- type MonitorDTO
- type PaginatedResponse
- type PaginationDTO
- type PortInfo
- type RecentHandoffDTO
- type SSEEvent
- type SSEHub
- type ServeConfig
- type Server
- type SessionDTO
- type StatsDTO
- type TaskListDTO
- type ValidationDetails
Constants ¶
const ( ErrValidation = "validation_error" // 400 ErrNotFound = "not_found" // 404 ErrConflict = "conflict" // 409 ErrForbidden = "forbidden" // 403 ErrInternal = "internal" // 500 )
Standard error codes mapped to HTTP status codes.
Variables ¶
This section is empty.
Functions ¶
func BumpSessionActivity ¶
BumpSessionActivity updates the last_activity timestamp for a session.
func DeletePortFile ¶
DeletePortFile removes the port file. Called on server shutdown. Errors are returned but callers may choose to ignore them during cleanup.
func GenerateInstanceID ¶
GenerateInstanceID creates a new random instance ID with the srv_ prefix and 6 random hex characters (e.g. "srv_8f3b2c").
func GetOrCreateWebSession ¶
func GetOrCreateWebSession(database *db.DB) (*db.SessionRow, error)
GetOrCreateWebSession finds or creates the shared web session used by the td serve HTTP server. The session is identified by:
- agent_type = "web"
- agent_pid = 0
- branch = "default"
If a matching session exists, its activity timestamp is bumped. If none exists, a new session named "td-serve-web" is created.
func HandleAddComment ¶ added in v0.45.0
func HandleAddComment(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleAddComment adds a comment to an issue. Pure-function form of (s *Server).handleAddComment.
func HandleAddDependency ¶ added in v0.45.0
func HandleAddDependency(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleAddDependency adds a dependency between two issues. Pure-function form of (s *Server).handleAddDependency.
func HandleApprove ¶ added in v0.45.0
func HandleApprove(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleApprove transitions an issue from in_review to closed, stamps the reviewer/closed_at, and runs parent-close + dependency-unblock cascades. Pure-function form of (s *Server).handleApprove.
Step 3: under delegated mode, if an active approval review exists and the caller is NOT the eligible reviewer, the handler performs a close-after- review (Mode C). The existing reviewer_session / reviewed_at are preserved; only closed_by_session and closed_at are stamped. When closer != reviewer_of_record, the request must include a reason in the body — otherwise the handler returns 400 so CLI and API enforce the same rule.
func HandleBlock ¶ added in v0.45.0
func HandleBlock(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleBlock marks an issue as blocked, logging a blocker entry. Pure-function form of (s *Server).handleBlock.
func HandleClose ¶ added in v0.45.0
func HandleClose(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleClose closes an issue from any non-closed state and runs parent-close + dependency-unblock cascades. Pure-function form of (s *Server).handleClose.
Batch 1c: an `in_review` issue cannot be closed through this path. The plan mandates that reviewed implementation work flow through `td approve` (i.e. HandleApprove) so the review attestation is enforced; allowing HandleClose to finish the close would be a backdoor. The handler rejects with a clear message pointing to approve.
func HandleCreateBoard ¶ added in v0.45.0
func HandleCreateBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleCreateBoard creates a new board from a JSON request body. Pure-function form of (s *Server).handleCreateBoard.
func HandleCreateIssue ¶ added in v0.45.0
func HandleCreateIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleCreateIssue creates a new issue from a JSON request body. Pure-function form of (s *Server).handleCreateIssue.
func HandleDeleteBoard ¶ added in v0.45.0
func HandleDeleteBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleDeleteBoard deletes a board. Pure-function form of (s *Server).handleDeleteBoard.
func HandleDeleteComment ¶ added in v0.45.0
func HandleDeleteComment(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleDeleteComment deletes a comment from an issue. Pure-function form of (s *Server).handleDeleteComment.
func HandleDeleteDependency ¶ added in v0.45.0
func HandleDeleteDependency(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleDeleteDependency removes a dependency by its dep_id. Pure-function form of (s *Server).handleDeleteDependency.
func HandleDeleteIssue ¶ added in v0.45.0
func HandleDeleteIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleDeleteIssue soft-deletes an issue. Pure-function form of (s *Server).handleDeleteIssue.
func HandleGetBoard ¶ added in v0.45.0
func HandleGetBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleGetBoard returns a board and its issue list (resolved either via the board's TDQ query or via stored positions). Pure-function form of (s *Server).handleGetBoard.
func HandleGetIssue ¶ added in v0.45.0
func HandleGetIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleGetIssue returns a single issue with its logs, comments, latest handoff, and dependency graph. Pure-function form of (s *Server).handleGetIssue.
func HandleHealth ¶ added in v0.45.0
func HandleHealth(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleHealth returns server status, the active session id, and the current change_token. Pure-function form of (s *Server).handleHealth.
func HandleListBoards ¶ added in v0.45.0
func HandleListBoards(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleListBoards returns all boards. Pure-function form of (s *Server).handleListBoards.
func HandleListIssues ¶ added in v0.45.0
func HandleListIssues(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleListIssues returns a paginated list of issues with optional filtering (status, type, priority, labels, epic, search). Pure-function form of (s *Server).handleListIssues.
func HandleListLabels ¶ added in v0.45.0
func HandleListLabels(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleListLabels returns the distinct label catalog for the project. Pure- function form of (s *Server).handleListLabels.
func HandleListSessions ¶ added in v0.45.0
func HandleListSessions(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleListSessions returns the list of known sessions and the caller's current session id. Pure-function form of (s *Server).handleListSessions.
func HandleMonitor ¶ added in v0.45.0
func HandleMonitor(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleMonitor returns the consolidated monitor view (boards, focus, recent activity). Pure-function form of (s *Server).handleMonitor.
func HandleRecordReview ¶ added in v0.45.0
func HandleRecordReview(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleRecordReview implements POST /v1/issues/{id}/reviews. Under the delegated policy mode, it records an approval (or changes_requested) review without closing the issue. Rejects with 409 when the mode isn't delegated so clients get a clear signal rather than a silent success that doesn't unblock the close-after-review flow.
Status codes:
- 201 Created on success
- 400 on missing summary / invalid decision / unknown issue
- 403 on ineligible reviewer
- 404 when issue doesn't exist
- 409 when mode != delegated or an active approval already exists
func HandleReject ¶ added in v0.45.0
func HandleReject(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleReject sends an issue back from in_review to open and clears the implementer/reviewer session and closed_at. Pure-function form of (s *Server).handleReject.
func HandleRemoveBoardPosition ¶ added in v0.45.0
func HandleRemoveBoardPosition(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleRemoveBoardPosition removes an issue's explicit position from a board. Pure-function form of (s *Server).handleRemoveBoardPosition.
func HandleReopen ¶ added in v0.45.0
func HandleReopen(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleReopen reopens a closed issue, clearing reviewer + closed_at. Pure-function form of (s *Server).handleReopen.
func HandleReview ¶ added in v0.45.0
func HandleReview(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleReview transitions an issue to in_review and cascades the parent's status to in_review when all siblings qualify. Pure-function form of (s *Server).handleReview.
func HandleSetBoardPosition ¶ added in v0.45.0
func HandleSetBoardPosition(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleSetBoardPosition sets or updates an issue's position on a board. Pure-function form of (s *Server).handleSetBoardPosition.
func HandleSetFocus ¶ added in v0.45.0
func HandleSetFocus(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleSetFocus sets or clears the focused issue via config.json. Requires ctx.BaseDir to be non-empty (focus state lives in the local on-disk config). Pure-function form of (s *Server).handleSetFocus.
func HandleStart ¶ added in v0.45.0
func HandleStart(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleStart transitions an issue from open to in_progress and stamps the caller's session as the implementer. Pure-function form of (s *Server).handleStart.
func HandleStats ¶ added in v0.45.0
func HandleStats(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleStats returns aggregate counts and progress metrics. Pure-function form of (s *Server).handleStats.
func HandleUnblock ¶ added in v0.45.0
func HandleUnblock(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleUnblock returns a blocked issue to open. Pure-function form of (s *Server).handleUnblock.
func HandleUpdateBoard ¶ added in v0.45.0
func HandleUpdateBoard(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleUpdateBoard applies a partial update to an existing board. Pure-function form of (s *Server).handleUpdateBoard.
func HandleUpdateIssue ¶ added in v0.45.0
func HandleUpdateIssue(ctx HandlerContext, w http.ResponseWriter, r *http.Request)
HandleUpdateIssue applies a partial update to an existing issue. Pure-function form of (s *Server).handleUpdateIssue.
func IsPortFileStale ¶
IsPortFileStale checks whether the port file describes a server that is no longer running. A port file is stale if:
- The PID is not alive, OR
- The PID is alive but the health endpoint doesn't respond
func IsServerHealthy ¶
IsServerHealthy checks if a server at the given port is alive by sending an HTTP GET to localhost:{port}/health. Returns true only if a 200 response is received within the health timeout.
func ServeCloseDecisionForTest ¶ added in v0.45.0
func ServeCloseDecisionForTest(mode reviewpolicy.Mode, issue *models.Issue, sessionID string, hasImplementationHistory, wasAnyInvolved, hasActiveApproval, selfReviewAcknowledged bool) reviewpolicy.CloseEligibility
ServeCloseDecisionForTest exposes the close-eligibility decision that the serve close handler runs. See ServeReviewerDecisionForTest for why this shim exists.
func ServeReviewerDecisionForTest ¶ added in v0.45.0
func ServeReviewerDecisionForTest(mode reviewpolicy.Mode, issue *models.Issue, sessionID string, hasImplementationHistory, wasAnyInvolved, hasActiveApproval, selfReviewAcknowledged bool) reviewpolicy.ReviewerEligibility
ServeReviewerDecisionForTest exposes the same inputs-assembly path the runtime uses so the cross-surface parity suite can exercise it with synthetic inputs. The parity suite lives outside this package, which is why a thin exported shim is needed; runtime callers should use serveReviewerDecision directly.
func StartSessionHeartbeat ¶
StartSessionHeartbeat launches a goroutine that periodically bumps the session's last_activity timestamp. The goroutine stops when the provided context is cancelled. Errors during bumps are silently ignored since heartbeats are best-effort.
func WriteError ¶
func WriteError(w http.ResponseWriter, code, message string, status int)
WriteError writes a JSON error envelope.
func WritePortFile ¶
WritePortFile writes the port file to baseDir/.todos/serve-port after acquiring an exclusive lock on the lock file. The lock is released after writing. This ensures only one server instance can register itself at a time.
func WriteSuccess ¶
func WriteSuccess(w http.ResponseWriter, data interface{}, status int)
WriteSuccess writes a JSON success envelope with the given data and status.
func WriteValidation ¶
func WriteValidation(w http.ResponseWriter, fields []FieldError)
WriteValidation writes a 400 validation_error response with field-level details.
Types ¶
type ActivityItemDTO ¶
type ActivityItemDTO struct {
Timestamp string `json:"timestamp"`
SessionID string `json:"session_id"`
Type string `json:"type"`
IssueID string `json:"issue_id"`
IssueTitle string `json:"issue_title"`
Message string `json:"message"`
LogType string `json:"log_type"`
Action string `json:"action"`
EntityID string `json:"entity_id"`
EntityType string `json:"entity_type"`
PreviousData string `json:"previous_data"`
NewData string `json:"new_data"`
}
ActivityItemDTO is the API representation of a unified activity feed item.
func ActivityItemToDTO ¶
func ActivityItemToDTO(item *monitor.ActivityItem) ActivityItemDTO
ActivityItemToDTO converts a monitor.ActivityItem to an ActivityItemDTO.
func ActivityItemsToDTOs ¶
func ActivityItemsToDTOs(items []monitor.ActivityItem) []ActivityItemDTO
ActivityItemsToDTOs converts a slice of activity items to DTOs.
type BoardCreateBody ¶
BoardCreateBody represents the expected JSON body for creating a board.
type BoardDTO ¶
type BoardDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Query string `json:"query"`
IsBuiltin bool `json:"is_builtin"`
ViewMode string `json:"view_mode"`
LastViewedAt *string `json:"last_viewed_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
BoardDTO is the API representation of a board.
func BoardToDTO ¶
BoardToDTO converts a models.Board to a BoardDTO.
func BoardsToDTOs ¶
BoardsToDTOs converts a slice of boards to DTOs.
type BoardPositionBody ¶
BoardPositionBody represents the expected JSON body for setting an issue position on a board.
type BoardUpdateBody ¶
BoardUpdateBody represents the expected JSON body for updating a board. All fields are optional; only present fields are applied.
type CommentCreateBody ¶
type CommentCreateBody struct {
Text string `json:"text"`
}
CommentCreateBody represents the expected JSON body for adding a comment.
type CommentDTO ¶
type CommentDTO struct {
ID string `json:"id"`
IssueID string `json:"issue_id"`
SessionID string `json:"session_id"`
Text string `json:"text"`
CreatedAt string `json:"created_at"`
}
CommentDTO is the API representation of a comment.
func CommentToDTO ¶
func CommentToDTO(comment *models.Comment) CommentDTO
CommentToDTO converts a models.Comment to a CommentDTO.
func CommentsToDTOs ¶
func CommentsToDTOs(comments []models.Comment) []CommentDTO
CommentsToDTOs converts a slice of comments to DTOs.
type DependencyCreateBody ¶
type DependencyCreateBody struct {
DependsOn string `json:"depends_on"`
}
DependencyCreateBody represents the expected JSON body for adding a dependency.
type DependencyDTO ¶
type DependencyDTO struct {
DepID string `json:"dep_id"`
IssueID string `json:"issue_id"`
DependsOnID string `json:"depends_on_id"`
RelationType string `json:"relation_type"`
}
DependencyDTO is the API representation of an issue dependency.
func DependenciesToDTOs ¶
func DependenciesToDTOs(deps []models.IssueDependency) []DependencyDTO
DependenciesToDTOs converts a slice of dependencies to DTOs.
func DependencyToDTO ¶
func DependencyToDTO(dep *models.IssueDependency) DependencyDTO
DependencyToDTO converts a models.IssueDependency to a DependencyDTO.
type Envelope ¶
type Envelope struct {
OK bool `json:"ok"`
Data interface{} `json:"data,omitempty"`
Error *ErrorPayload `json:"error,omitempty"`
}
Envelope is the standard response wrapper for all API responses. Success: {"ok": true, "data": {...}} Error: {"ok": false, "error": {"code": "...", "message": "...", "details": ...}}
type ErrorPayload ¶
type ErrorPayload struct {
Code string `json:"code"`
Message string `json:"message"`
Details interface{} `json:"details,omitempty"`
}
ErrorPayload holds structured error information.
type FieldError ¶
type FieldError struct {
Field string `json:"field"`
Rule string `json:"rule"`
Value interface{} `json:"value,omitempty"`
Expected interface{} `json:"expected,omitempty"`
Message string `json:"message"`
}
FieldError describes a single validation failure on a request field.
func ValidateIssueCreate ¶
func ValidateIssueCreate(body *IssueCreateBody, titleMin, titleMax int) []FieldError
ValidateIssueCreate validates an IssueCreateBody and returns any field errors. The titleMin and titleMax parameters allow callers to pass configured limits.
func ValidateIssueUpdate ¶
func ValidateIssueUpdate(body *IssueUpdateBody, titleMin, titleMax int) []FieldError
ValidateIssueUpdate validates an IssueUpdateBody and returns any field errors. The titleMin and titleMax parameters allow callers to pass configured limits.
func ValidatePagination ¶
func ValidatePagination(limit, offset int) []FieldError
ValidatePagination validates limit and offset query parameters.
type FocusBody ¶
type FocusBody struct {
IssueID *string `json:"issue_id"`
}
FocusBody represents the expected JSON body for setting focus. IssueID is a pointer so that null/absent can be distinguished from empty string.
type HandlerConfig ¶ added in v0.45.0
type HandlerConfig struct {
// TitleMin and TitleMax bound issue title length when set (>0). Zero
// means "use default". Populated by S1.2.
TitleMin int
TitleMax int
// NotifyChange, when non-nil, is invoked by write handlers after a
// successful mutation. The local `td serve` Server uses this to broadcast
// SSE refresh events and trigger debounced autosync. td-sync leaves this
// nil — its REST routes handle event-log promotion at the route adapter
// layer instead.
NotifyChange func()
}
HandlerConfig carries optional, request-scoped configuration consumed by handlers. It exists so that handlers do not depend on the local `*serve.Server` (and its `ServeConfig`) and can be invoked by other servers — notably td-sync's per-project HTTP routes.
Fields are added as handlers are converted to take a HandlerContext. For the read-handler refactor (S1.1) no config is required; later streams (S1.2, S1.3) will populate fields such as title length limits.
type HandlerContext ¶ added in v0.45.0
type HandlerContext struct {
DB *db.DB
SessionID string
BaseDir string
Config HandlerConfig
}
HandlerContext is the request-scoped dependency bundle that pure handler functions receive in place of a `*Server` receiver. It lets td-sync mount the same handlers against per-project DBs without standing up a `*serve.Server`.
`BaseDir` is empty when there is no on-disk td root (e.g. td-sync). Handlers that touch on-disk config (focus, title-limit lookup) must guard on `BaseDir != ""` or fall back to `Config`.
type HandoffDTO ¶
type HandoffDTO struct {
ID string `json:"id"`
IssueID string `json:"issue_id"`
SessionID string `json:"session_id"`
Done []string `json:"done"`
Remaining []string `json:"remaining"`
Decisions []string `json:"decisions"`
Uncertain []string `json:"uncertain"`
Timestamp string `json:"timestamp"`
}
HandoffDTO is the API representation of a handoff.
func HandoffToDTO ¶
func HandoffToDTO(handoff *models.Handoff) HandoffDTO
HandoffToDTO converts a models.Handoff to a HandoffDTO.
type IssueCreateBody ¶
type IssueCreateBody struct {
Title string `json:"title"`
Description string `json:"description"`
Type string `json:"type"`
Priority string `json:"priority"`
Points int `json:"points"`
Labels []string `json:"labels"`
ParentID string `json:"parent_id"`
Acceptance string `json:"acceptance"`
Sprint string `json:"sprint"`
Minor bool `json:"minor"`
DeferUntil string `json:"defer_until"`
DueDate string `json:"due_date"`
}
IssueCreateBody represents the expected JSON body for creating an issue.
type IssueDTO ¶
type IssueDTO struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Status string `json:"status"`
Type string `json:"type"`
Priority string `json:"priority"`
Points int `json:"points"`
Labels []string `json:"labels"`
ParentID *string `json:"parent_id"`
Acceptance string `json:"acceptance"`
Sprint string `json:"sprint"`
ImplementerSession *string `json:"implementer_session"`
CreatorSession *string `json:"creator_session"`
ReviewerSession *string `json:"reviewer_session"`
ReviewRequestedBySession *string `json:"review_requested_by_session"`
ClosedBySession *string `json:"closed_by_session"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ReviewedAt *string `json:"reviewed_at"`
ClosedAt *string `json:"closed_at"`
DeletedAt *string `json:"deleted_at"`
Minor bool `json:"minor"`
CreatedBranch *string `json:"created_branch"`
DeferUntil *string `json:"defer_until"`
DueDate *string `json:"due_date"`
DeferCount int `json:"defer_count"`
// ActiveReview is populated by GET /v1/issues/{id} and transition-response
// payloads when the issue carries a non-superseded approval. Clients can
// key off this field to distinguish "reviewed, awaiting close" from
// "not yet reviewed". Omitted for issues without an active approval.
ActiveReview *IssueReviewSummary `json:"active_review,omitempty"`
// Reviews is populated by GET /v1/issues/{id}?with=reviews only. Kept
// off the default response to keep list payloads compact.
Reviews []IssueReviewDTO `json:"reviews,omitempty"`
}
IssueDTO is the API representation of an issue. All documented fields are always present (no omitempty for documented fields). Nullable fields use *string so they serialize as JSON null when nil. Collections serialize as [] when empty, never null.
func IssueToDTO ¶
IssueToDTO converts a models.Issue to an IssueDTO with proper null/empty handling for the API layer.
func IssuesToDTOs ¶
IssuesToDTOs converts a slice of issues to DTOs.
type IssueReviewDTO ¶ added in v0.45.0
type IssueReviewDTO struct {
ID string `json:"id"`
IssueID string `json:"issue_id"`
ReviewerSession string `json:"reviewer_session"`
Decision string `json:"decision"`
Summary string `json:"summary,omitempty"`
RequestedBySession string `json:"requested_by_session,omitempty"`
CreatedAt time.Time `json:"created_at"`
SupersededAt *time.Time `json:"superseded_at,omitempty"`
}
IssueReviewDTO is the full per-row representation returned when the caller explicitly asks for review history (GET /v1/issues/{id}?with=reviews).
func IssueReviewToDTO ¶ added in v0.45.0
func IssueReviewToDTO(r *models.IssueReview) IssueReviewDTO
IssueReviewToDTO converts a models.IssueReview to a DTO for API consumers.
type IssueReviewSummary ¶ added in v0.45.0
type IssueReviewSummary struct {
ID string `json:"id"`
Decision string `json:"decision"`
ReviewerSession string `json:"reviewer_session"`
RequestedBySession string `json:"requested_by_session,omitempty"`
Summary string `json:"summary,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
IssueReviewSummary is the nested DTO used for the issue's active approval review when an active (non-superseded) row exists.
type IssueUpdateBody ¶
type IssueUpdateBody struct {
Title *string `json:"title"`
Description *string `json:"description"`
Type *string `json:"type"`
Priority *string `json:"priority"`
Points *int `json:"points"`
Labels []string `json:"labels"`
ParentID *string `json:"parent_id"`
Acceptance *string `json:"acceptance"`
Sprint *string `json:"sprint"`
Minor *bool `json:"minor"`
DeferUntil *string `json:"defer_until"`
DueDate *string `json:"due_date"`
}
IssueUpdateBody represents the expected JSON body for updating an issue. All fields are optional; only present fields are applied.
type LogDTO ¶
type LogDTO struct {
ID string `json:"id"`
IssueID string `json:"issue_id"`
SessionID string `json:"session_id"`
WorkSessionID string `json:"work_session_id"`
Message string `json:"message"`
Type string `json:"type"`
Timestamp string `json:"timestamp"`
}
LogDTO is the API representation of a session log entry.
func LogsToDTOs ¶
LogsToDTOs converts a slice of logs to DTOs.
type MonitorDTO ¶
type MonitorDTO struct {
FocusedIssue *IssueDTO `json:"focused_issue"`
InProgress []IssueDTO `json:"in_progress"`
Activity []ActivityItemDTO `json:"activity"`
TaskList TaskListDTO `json:"task_list"`
RecentHandoffs []RecentHandoffDTO `json:"recent_handoffs"`
ActiveSessions []string `json:"active_sessions"`
Timestamp string `json:"timestamp"`
}
MonitorDTO is the API representation of the full monitor state.
func MonitorDataToDTO ¶
func MonitorDataToDTO(msg *monitor.RefreshDataMsg) MonitorDTO
MonitorDataToDTO converts a RefreshDataMsg to a MonitorDTO.
type PaginatedResponse ¶
type PaginatedResponse struct {
Items interface{} `json:"items"`
Pagination PaginationDTO `json:"pagination"`
}
PaginatedResponse wraps a list result with pagination metadata.
type PaginationDTO ¶
type PaginationDTO struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Total int `json:"total"`
}
PaginationDTO describes the pagination state returned alongside list results.
type PortInfo ¶
type PortInfo struct {
Port int `json:"port"`
PID int `json:"pid"`
StartedAt time.Time `json:"started_at"`
InstanceID string `json:"instance_id"`
}
PortInfo contains the metadata written to the port file when the server starts.
func ReadPortFile ¶
ReadPortFile reads and parses the port file from baseDir/.todos/serve-port. Returns an error if the file doesn't exist or is missing required fields.
type RecentHandoffDTO ¶
type RecentHandoffDTO struct {
IssueID string `json:"issue_id"`
SessionID string `json:"session_id"`
Timestamp string `json:"timestamp"`
}
RecentHandoffDTO is the API representation of a recent handoff summary.
type SSEEvent ¶
type SSEEvent struct {
ID string // change_token used as event ID
Event string // "refresh" or "ping"
Data string // JSON payload
}
SSEEvent represents a single Server-Sent Event.
type SSEHub ¶
type SSEHub struct {
// contains filtered or unexported fields
}
SSEHub manages connected SSE clients and broadcasts events.
func (*SSEHub) Broadcast ¶
Broadcast sends a refresh event to all connected clients with the given change token.
type ServeConfig ¶
type ServeConfig struct {
Port int
Addr string
Token string
CORSOrigin string
PollInterval time.Duration
}
ServeConfig holds the configuration for the HTTP server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the td serve HTTP server.
func NewServer ¶
func NewServer(database *db.DB, baseDir, sessionID string, config ServeConfig) *Server
NewServer creates a new Server, registers all routes, and sets up the middleware chain. Handlers are placeholder 501s until subsequent tasks implement them.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server on the configured address and port, and handles graceful shutdown when the context is cancelled.
func (*Server) NotifyChange ¶
func (s *Server) NotifyChange()
NotifyChange is called after successful write operations. It: 1. Gets the current change_token 2. Broadcasts a refresh event to all SSE clients 3. Triggers a debounced autosync
func (*Server) Shutdown ¶
Shutdown gracefully stops the HTTP server. If the server has not been started, this is a no-op.
func (*Server) StartBackground ¶
StartBackground starts long-lived background processes (SSE polling loop).
func (*Server) StopBackground ¶
func (s *Server) StopBackground()
StopBackground stops long-lived background processes.
type SessionDTO ¶
type SessionDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Branch string `json:"branch"`
AgentType string `json:"agent_type"`
AgentPID int `json:"agent_pid"`
ContextID string `json:"context_id"`
PreviousSessionID *string `json:"previous_session_id"`
StartedAt string `json:"started_at"`
LastActivity string `json:"last_activity"`
}
SessionDTO is the API representation of a session.
func SessionToDTO ¶
func SessionToDTO(sess *session.Session) SessionDTO
SessionToDTO converts a session.Session to a SessionDTO.
func SessionsToDTOs ¶
func SessionsToDTOs(sessions []session.Session) []SessionDTO
SessionsToDTOs converts a slice of sessions to DTOs.
type StatsDTO ¶
type StatsDTO struct {
Total int `json:"total"`
ByStatus map[string]int `json:"by_status"`
ByType map[string]int `json:"by_type"`
ByPriority map[string]int `json:"by_priority"`
OldestOpen *IssueDTO `json:"oldest_open"`
NewestTask *IssueDTO `json:"newest_task"`
LastClosed *IssueDTO `json:"last_closed"`
CreatedToday int `json:"created_today"`
CreatedThisWeek int `json:"created_this_week"`
TotalPoints int `json:"total_points"`
AvgPointsPerTask float64 `json:"avg_points_per_task"`
CompletionRate float64 `json:"completion_rate"`
TotalLogs int `json:"total_logs"`
TotalHandoffs int `json:"total_handoffs"`
MostActiveSession string `json:"most_active_session"`
}
StatsDTO is the API representation of extended project statistics.
func StatsToDTO ¶
func StatsToDTO(stats *models.ExtendedStats) StatsDTO
StatsToDTO converts a models.ExtendedStats to a StatsDTO.
type TaskListDTO ¶
type TaskListDTO struct {
Reviewable []IssueDTO `json:"reviewable"`
NeedsRework []IssueDTO `json:"needs_rework"`
InProgress []IssueDTO `json:"in_progress"`
Ready []IssueDTO `json:"ready"`
PendingReview []IssueDTO `json:"pending_review"`
Blocked []IssueDTO `json:"blocked"`
Closed []IssueDTO `json:"closed"`
}
TaskListDTO is the API representation of categorized task lists.
type ValidationDetails ¶
type ValidationDetails struct {
Fields []FieldError `json:"fields"`
}
ValidationDetails wraps field-level validation errors in error.details.