workspace

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package workspace 提供 Agent 任务运行所需的共享文件系统约定。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArtifactStoragePath

func ArtifactStoragePath(orgID uint, workerID uint, storageKey string) (string, error)

ArtifactStoragePath 从 server 侧解析 worker workspace 相对的 storage key。

func FindRepoRoot

func FindRepoRoot(workDir string) (string, error)

FindRepoRoot 从给定的工作目录向上查找包含 .leros 目录的 repo 根目录。

func OpenArtifactStorageFile

func OpenArtifactStorageFile(ctx context.Context, orgID uint, workerID uint, storageKey string) (io.ReadCloser, error)

func PrepareTempWorkspace

func PrepareTempWorkspace() (string, error)

PrepareTempWorkspace 创建没有项目上下文时使用的临时兜底工作区。

func ProjectMemoryPath

func ProjectMemoryPath(repoDir string) string

ProjectMemoryPath 返回项目记忆文件的绝对路径。 repoDir 是项目 repo 根目录的绝对路径。

func ProjectRepoPath

func ProjectRepoPath(orgID uint, workerID uint, publicID string) (string, error)

ProjectRepoPath 返回项目 repo 在 worker workspace 下的绝对路径。 路径格式:{workspaceRoot}/{orgID}/{workerID}/workspace/projects/{orgID}/{publicID}/repo

func ReconcileArtifacts

func ReconcileArtifacts(ctx context.Context, plan *TaskWorkspace) error

ReconcileArtifacts compares the current repo state against the baseline, identifies new or modified files, and populates the manifest at plan.ArtifactManifestPath with any autodetected artifacts. It skips reconciliation when the manifest already contains final entries.

func RepoRelativePathFromStorageKey

func RepoRelativePathFromStorageKey(storageKey string) string

func SafeJoin

func SafeJoin(root string, child string) (string, error)

SafeJoin 解析相对路径,并确保最终路径仍在指定根目录内。

func WorkerMountedWorkspacePath

func WorkerMountedWorkspacePath(orgID uint, workerID uint) (string, error)

WorkerMountedWorkspacePath 返回 server 视角下某个 worker 的 workspace 挂载目录。 Server 挂载的是 workspace 根目录,单个 Worker 的实际目录位于 {workspaceRoot}/{orgID}/{workerID}/workspace。

func WriteBaseline

func WriteBaseline(ctx context.Context, plan *TaskWorkspace) error

WriteBaseline scans the repo directory, applies ignore rules, and writes a baseline.jsonl.

Types

type ArtifactRecord

type ArtifactRecord struct {
	Title        string
	Filename     string
	Description  string
	ArtifactType string
	RelativePath string
	StorageKey   string
	MimeType     string
	FileSize     int64
	Sha256       string
	Source       string
	Status       string
}

ArtifactRecord 是 manifest 产物声明经过校验后可持久化的结构。

func BuildArtifactRecord

func BuildArtifactRecord(plan *TaskWorkspace, item ManifestArtifact) (ArtifactRecord, error)

BuildArtifactRecord 校验一条产物声明,并生成可存储的产物记录。

func CollectFinalArtifacts

func CollectFinalArtifacts(ctx context.Context, plan *TaskWorkspace) ([]ArtifactRecord, error)

CollectFinalArtifacts 读取并校验最终产物 manifest。

type ArtifactStorageFile

type ArtifactStorageFile struct {
	Path     string
	Filename string
	MimeType string
	FileSize int64
	Sha256   string
	Data     []byte
}

func ResolveArtifactStorageFile

func ResolveArtifactStorageFile(ctx context.Context, orgID uint, workerID uint, storageKey string, declaredMimeType string) (*ArtifactStorageFile, error)

type FileSnapshot

type FileSnapshot struct {
	Path          string `json:"path"`
	Size          int64  `json:"size"`
	MtimeUnixNano int64  `json:"mtime_unix_nano"`
}

FileSnapshot records a single file's metadata at a point in time.

type IgnoreChecker

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

IgnoreChecker applies gitignore rules and Leros built-in excludes.

func NewIgnoreChecker

func NewIgnoreChecker(repoDir string) (*IgnoreChecker, error)

NewIgnoreChecker creates an IgnoreChecker for the given repo directory.

func (*IgnoreChecker) IsIgnored

func (c *IgnoreChecker) IsIgnored(absPath string) (bool, error)

IsIgnored returns true when a file should be excluded from scanning.

func (*IgnoreChecker) ShouldSkipDir

func (c *IgnoreChecker) ShouldSkipDir(absPath string) bool

ShouldSkipDir returns true when a directory should be excluded from scanning entirely.

type ManifestArtifact

type ManifestArtifact struct {
	Path         string `json:"path"`
	Title        string `json:"title,omitempty"`
	Description  string `json:"description,omitempty"`
	MimeType     string `json:"mime_type,omitempty"`
	ArtifactType string `json:"artifact_type,omitempty"`
	IsFinal      bool   `json:"is_final,omitempty"`
}

ManifestArtifact 表示 Agent 在一次 turn 中写入 JSON Lines manifest 的一条产物声明。

type TaskWorkspace

type TaskWorkspace struct {
	WorkspaceRoot        string
	ProjectRoot          string
	RepoDir              string
	TaskDir              string
	TurnDir              string
	TurnTmpDir           string
	TurnLogDir           string
	ArtifactManifestPath string
	BaselinePath         string
	EffectiveWorkDir     string
}

TaskWorkspace 描述一次任务 turn 会使用到的文件系统路径。

func FromAgentRequest

func FromAgentRequest(req *agent.RequestContext) (*TaskWorkspace, bool, error)

FromAgentRequest 从标准化运行请求中的 workspace 上下文解析工作区路径。

func PrepareTaskWorkspace

func PrepareTaskWorkspace(ctx context.Context, req TaskWorkspaceRequest) (*TaskWorkspace, error)

PrepareTaskWorkspace 创建并校验项目任务工作区。

func ResolveTaskWorkspace

func ResolveTaskWorkspace(req TaskWorkspaceRequest) (*TaskWorkspace, error)

ResolveTaskWorkspace 只计算任务 turn 工作区路径,不创建任何目录。

func (*TaskWorkspace) StorageKey

func (p *TaskWorkspace) StorageKey(relativePath string) (string, error)

StorageKey 返回适合持久化的 workspace root 相对路径。

type TaskWorkspaceRequest

type TaskWorkspaceRequest struct {
	OrgID            uint
	ProjectID        string
	TaskID           string
	RequestID        string
	RequestedWorkDir string
}

TaskWorkspaceRequest 标识一次任务 turn 的工作区和运行目录请求。

Jump to

Keyboard shortcuts

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