workspace

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapturePostRunTree added in v0.1.19

func CapturePostRunTree(ctx context.Context, repoDir string) (string, error)

CapturePostRunTree captures the current working tree as a Git tree object, using the same temporary-index approach as CapturePreRunTree.

func CapturePreRunTree added in v0.1.19

func CapturePreRunTree(ctx context.Context, repoDir string) (string, error)

CapturePreRunTree writes the current working tree to a Git tree object using a temporary GIT_INDEX_FILE, and returns the tree SHA. This captures the state of the repo before the agent begins execution so that generated files can be identified later.

It handles:

  • Repos with HEAD: git read-tree HEAD into the temp index first.
  • Repos without HEAD: git read-tree --empty into the temp index first.
  • Then git add --all + git write-tree, all using the temp index.

The real .git/index is never modified. The caller is responsible for handling the returned empty string (e.g. when .git does not exist).

func CapturePreRunTreeSafe added in v0.1.19

func CapturePreRunTreeSafe(ctx context.Context, repoDir string) string

CapturePreRunTreeSafe is a best-effort wrapper that logs a warning on failure instead of returning an error. Callers that cannot abort on Git failures should use this.

func FindRepoRoot

func FindRepoRoot(workDir string) (string, error)

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

func GitDiffReconcile added in v0.1.19

func GitDiffReconcile(ctx context.Context, plan *TaskWorkspace, preTreeSHA string) error

GitDiffReconcile runs when the manifest has no explicit final entries. It computes the diff between the pre-run and post-run Git trees and appends the resulting entries to the artifact manifest. This replaces the old baseline.jsonl-based ReconcileArtifacts.

Failures during post-run capture or diff-tree are logged as warnings and do not prevent explicit declarations, finalization, or commit/push from proceeding.

func IsRuntimeInternalPath added in v0.1.19

func IsRuntimeInternalPath(relPath string) bool

IsRuntimeInternalPath reports whether the given relative path belongs to a runtime-internal directory that should be excluded from artifacts.

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}/projects/{orgID}/{publicID}/repo

func SafeJoin

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

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

func ShouldSkipArtifactFile added in v0.1.19

func ShouldSkipArtifactFile(absPath string) bool

ShouldSkipArtifactFile reports whether an absolute file path should be excluded from artifact publication. It checks the path against builtin excluded dirs and builtin excluded file names.

func WorkerMountedWorkspacePath

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

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

Types

type ArtifactRecord

type ArtifactRecord struct {
	Title        string
	Filename     string
	OriginalName string
	Description  string
	ArtifactType string
	RelativePath string
	StorageKey   string
	StorageURI   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 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"`
	Source       string `json:"source,omitempty"`
}

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

func DiffArtifacts added in v0.1.19

func DiffArtifacts(ctx context.Context, repoDir, preTreeSHA, postTreeSHA string) ([]ManifestArtifact, error)

DiffArtifacts computes the files changed between two Git tree SHAs using git diff-tree. It returns a list of manifest artifact entries for new, modified, copied, renamed, and type-changed files. Deleted files, directories, and .gitignored files are excluded.

Returns nil if either treeSHA is empty or trees are identical.

type TaskWorkspace

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

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

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 returns a repo-relative path suitable for persistence and Gitea API access.

type TaskWorkspaceRequest

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

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

Jump to

Keyboard shortcuts

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