projectworkspace

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeDisabled = "disabled"
	ModeReadOnly = "read_only"
	ModeEdit     = "edit"

	DiffScopeWorkingTree = "working_tree"
	DiffScopeStaged      = "staged"
	DiffScopeHead        = "head"
)
View Source
const (
	DefaultMaxDiffBytes = 64 << 10
	MaxDiffBytes        = 256 << 10
	DefaultMaxReadBytes = 64 << 10
	MaxReadBytes        = 256 << 10
	MaxPageSize         = 100
)

Variables

View Source
var (
	ErrProjectNotFound      = errors.New("workspace project not found")
	ErrInvalidInput         = errors.New("invalid workspace input")
	ErrWorkspaceDisabled    = errors.New("workspace disabled")
	ErrWorkspaceReadOnly    = errors.New("workspace read only")
	ErrGitUnavailable       = errors.New("git unavailable")
	ErrUnsafeContent        = errors.New("unsafe workspace content")
	ErrEditTokenInvalid     = errors.New("edit token invalid")
	ErrEditConflict         = errors.New("edit conflict")
	ErrIngestionUnsupported = errors.New("workspace ingestion unsupported")
)

Functions

This section is empty.

Types

type API

type API interface {
	GitAvailable(ctx context.Context, projectID string) (bool, error)
	GitStatus(ctx context.Context, projectID string, options GitStatusOptions) (GitStatus, error)
	GitDiff(ctx context.Context, projectID string, options GitDiffOptions) (GitDiff, error)
	GitCreateWorktree(ctx context.Context, projectID string, options GitCreateWorktreeOptions) (GitCreateWorktreeResult, error)
	ReadFile(ctx context.Context, projectID string, options ReadFileOptions) (WorkspaceFile, error)
	EditFile(ctx context.Context, projectID string, options EditFileOptions) (EditResult, error)
	CreateFile(ctx context.Context, projectID string, options CreateFileOptions) (CreateFileResult, error)
	DeleteFile(ctx context.Context, projectID string, options DeleteFileOptions) (DeleteFileResult, error)
}

type CreateFileOptions added in v0.1.13

type CreateFileOptions struct {
	RelativePath     string
	Text             string
	CreateParentDirs bool
	DryRun           bool
	WorktreeRef      string
}

type CreateFileResult added in v0.1.13

type CreateFileResult struct {
	Applied        bool          `json:"applied"`
	File           WorkspaceFile `json:"file"`
	IngestionRunID string        `json:"ingestion_run_id,omitempty"`
	NewEditToken   string        `json:"new_edit_token,omitempty"`
}

type DeleteFileOptions added in v0.1.13

type DeleteFileOptions struct {
	FileID       string
	RelativePath string
	EditToken    string
	DryRun       bool
	WorktreeRef  string
}

type DeleteFileResult added in v0.1.13

type DeleteFileResult struct {
	Deleted        bool   `json:"deleted"`
	ProjectID      string `json:"project_id"`
	RelativePath   string `json:"relative_path"`
	IngestionRunID string `json:"ingestion_run_id,omitempty"`
}

type DiffFile

type DiffFile struct {
	RelativePath string `json:"relative_path"`
	Status       string `json:"status"`
	Additions    int    `json:"additions"`
	Deletions    int    `json:"deletions"`
	Diff         string `json:"diff"`
}

type DiffSkip

type DiffSkip struct {
	RelativePath string `json:"relative_path,omitempty"`
	Reason       string `json:"reason"`
}

type EditFileOptions

type EditFileOptions struct {
	FileID       string
	RelativePath string
	EditToken    string
	DryRun       bool
	Edits        []ExactEdit
	WorktreeRef  string
}

type EditResult

type EditResult struct {
	Applied        bool          `json:"applied"`
	File           WorkspaceFile `json:"file"`
	DiffPreview    string        `json:"diff_preview,omitempty"`
	TextTruncated  bool          `json:"text_truncated"`
	IngestionRunID string        `json:"ingestion_run_id,omitempty"`
	NewEditToken   string        `json:"new_edit_token,omitempty"`
}

type ExactEdit

type ExactEdit struct {
	StartByte int    `json:"start_byte"`
	EndByte   int    `json:"end_byte"`
	OldText   string `json:"old_text"`
	NewText   string `json:"new_text"`
}

type GitCreateWorktreeOptions added in v0.1.19

type GitCreateWorktreeOptions struct {
	WorktreeRef string
	BranchRef   string
	BaseRef     string
	DryRun      bool
}

type GitCreateWorktreeResult added in v0.1.19

type GitCreateWorktreeResult struct {
	Applied      bool   `json:"applied"`
	ProjectID    string `json:"project_id"`
	WorktreeRef  string `json:"worktree_ref"`
	BranchRef    string `json:"branch_ref"`
	BaseRef      string `json:"base_ref"`
	IsolationRef string `json:"isolation_ref"`
	// WorktreePath is the absolute, server-verified on-disk worktree directory.
	// It is internal transport metadata: it MUST NOT be serialized to agents or
	// appear in any MCP tool result. The json:"-" tag guarantees the shared result
	// struct never leaks it; only the runner-only REST handler copies it into
	// RunnerWorktreeCreateResponse for the automation runner. See
	// httpapi.workspaceGitCreateWorktreeHandler.
	WorktreePath string `json:"-"`
}

type GitDiff

type GitDiff struct {
	ProjectID     string     `json:"project_id"`
	Scope         string     `json:"scope"`
	Files         []DiffFile `json:"files"`
	Skipped       []DiffSkip `json:"skipped,omitempty"`
	DiffTruncated bool       `json:"diff_truncated"`
	NextPageToken string     `json:"next_page_token,omitempty"`
}

type GitDiffOptions

type GitDiffOptions struct {
	Scope        string
	FileID       string
	RelativePath string
	PathPrefix   string
	ContextLines int
	MaxDiffBytes int
	PageToken    string
	WorktreeRef  string
}

type GitRunner

type GitRunner interface {
	Run(ctx context.Context, root string, maxBytes int, args ...string) ([]byte, bool, error)
}

type GitStatus

type GitStatus struct {
	ProjectID     string        `json:"project_id"`
	Branch        string        `json:"branch,omitempty"`
	HeadOIDShort  string        `json:"head_oid_short,omitempty"`
	Entries       []StatusEntry `json:"entries"`
	Truncated     bool          `json:"truncated"`
	NextPageToken string        `json:"next_page_token,omitempty"`
}

type GitStatusOptions

type GitStatusOptions struct {
	IncludeUntracked bool
	PathPrefix       string
	PageSize         int
	PageToken        string
	WorktreeRef      string
}

type Options

type Options struct {
	Enabled bool
}

type ReadFileOptions

type ReadFileOptions struct {
	FileID       string
	RelativePath string
	MaxBytes     int
	WorktreeRef  string
}

type RunnerWorktreeCreateResponse added in v0.3.0

type RunnerWorktreeCreateResponse struct {
	Applied      bool   `json:"applied"`
	ProjectID    string `json:"project_id"`
	WorktreeRef  string `json:"worktree_ref"`
	BranchRef    string `json:"branch_ref"`
	BaseRef      string `json:"base_ref"`
	IsolationRef string `json:"isolation_ref"`
	WorktreePath string `json:"worktree_path,omitempty"`
}

RunnerWorktreeCreateResponse is returned ONLY by the internal runner-facing REST route (POST /api/v1/projects/{id}/workspace/git/worktrees) that the automation runner calls directly. It carries the absolute WorktreePath so the runner can pass the correct per-project worktree directory to codex --cd and to worktree cleanup, instead of recomputing it from a single global --codex-cd flag (which mismatches any project whose root_path differs from that flag).

It MUST NOT be used by the MCP adapter or any agent-facing surface. The agent-facing git_worktree_create tool result stays ref-only via the shared GitCreateWorktreeResult whose WorktreePath field is json:"-".

func RunnerWorktreeCreateResponseFromResult added in v0.3.0

func RunnerWorktreeCreateResponseFromResult(result GitCreateWorktreeResult) RunnerWorktreeCreateResponse

RunnerWorktreeCreateResponseFromResult maps an internal GitCreateWorktreeResult into the runner-only REST response, preserving the absolute worktree path.

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(registry *projectregistry.Registry, ingest workspaceIngestion, options Options) *Service

func (*Service) CreateFile added in v0.1.13

func (svc *Service) CreateFile(ctx context.Context, projectID string, options CreateFileOptions) (CreateFileResult, error)

func (*Service) DeleteFile added in v0.1.13

func (svc *Service) DeleteFile(ctx context.Context, projectID string, options DeleteFileOptions) (DeleteFileResult, error)

func (*Service) EditFile

func (svc *Service) EditFile(ctx context.Context, projectID string, options EditFileOptions) (EditResult, error)

func (*Service) GitAvailable added in v0.1.6

func (svc *Service) GitAvailable(ctx context.Context, projectID string) (bool, error)

func (*Service) GitCreateWorktree added in v0.1.19

func (svc *Service) GitCreateWorktree(ctx context.Context, projectID string, options GitCreateWorktreeOptions) (GitCreateWorktreeResult, error)

func (*Service) GitDiff

func (svc *Service) GitDiff(ctx context.Context, projectID string, options GitDiffOptions) (GitDiff, error)

func (*Service) GitStatus

func (svc *Service) GitStatus(ctx context.Context, projectID string, options GitStatusOptions) (GitStatus, error)

func (*Service) ReadFile

func (svc *Service) ReadFile(ctx context.Context, projectID string, options ReadFileOptions) (WorkspaceFile, error)

func (*Service) SetGitRunner

func (svc *Service) SetGitRunner(runner GitRunner)

func (*Service) SetPolicyRecorder added in v0.1.12

func (svc *Service) SetPolicyRecorder(recorder *agentactivity.Recorder)

type StatusEntry

type StatusEntry struct {
	RelativePath   string `json:"relative_path"`
	Status         string `json:"status"`
	StagedStatus   string `json:"staged_status,omitempty"`
	WorktreeStatus string `json:"worktree_status,omitempty"`
	RenamedFrom    string `json:"renamed_from,omitempty"`
}

type WorkspaceFile

type WorkspaceFile struct {
	FileID        string    `json:"file_id,omitempty"`
	ProjectID     string    `json:"project_id"`
	RelativePath  string    `json:"relative_path"`
	Extension     string    `json:"extension,omitempty"`
	SizeBytes     int64     `json:"size_bytes"`
	ModifiedAt    time.Time `json:"modified_at"`
	Text          string    `json:"text"`
	TextTruncated bool      `json:"text_truncated"`
	LineCount     int       `json:"line_count"`
	EditToken     string    `json:"edit_token,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL