Documentation
¶
Overview ¶
Package workspace 提供 Agent 任务运行所需的共享文件系统约定。
Index ¶
- func CapturePostRunTree(ctx context.Context, repoDir string) (string, error)
- func CapturePreRunTree(ctx context.Context, repoDir string) (string, error)
- func CapturePreRunTreeSafe(ctx context.Context, repoDir string) string
- func FindRepoRoot(workDir string) (string, error)
- func GitDiffReconcile(ctx context.Context, plan *TaskWorkspace, preTreeSHA string) error
- func IsRuntimeInternalPath(relPath string) bool
- func PrepareTempWorkspace() (string, error)
- func ProjectMemoryPath(repoDir string) string
- func ProjectRepoPath(orgID uint, workerID uint, publicID string) (string, error)
- func SafeJoin(root string, child string) (string, error)
- func ShouldSkipArtifactFile(absPath string) bool
- func WorkerMountedWorkspacePath(orgID uint, workerID uint) (string, error)
- type ArtifactRecord
- type ManifestArtifact
- type TaskWorkspace
- type TaskWorkspaceRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CapturePostRunTree ¶ added in v0.1.19
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
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
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 ¶
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
IsRuntimeInternalPath reports whether the given relative path belongs to a runtime-internal directory that should be excluded from artifacts.
func PrepareTempWorkspace ¶
PrepareTempWorkspace 创建没有项目上下文时使用的临时兜底工作区。
func ProjectMemoryPath ¶
ProjectMemoryPath 返回项目记忆文件的绝对路径。 repoDir 是项目 repo 根目录的绝对路径。
func ProjectRepoPath ¶
ProjectRepoPath 返回项目 repo 在 worker workspace 下的绝对路径。 路径格式:{workspaceRoot}/projects/{orgID}/{publicID}/repo
func ShouldSkipArtifactFile ¶ added in v0.1.19
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.
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.