Run tasks directly with language-independent project tools

This commit is contained in:
2026-10-09 01:48:46 +01:00
parent 998b0941d3
commit ed93d055bf
23 changed files with 170 additions and 156 deletions
+27 -9
View File
@@ -74,12 +74,27 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
return nil, fmt.Errorf("too many write paths")
}
for _, path := range request.WritePaths {
if filepath.IsAbs(path) || filepath.Clean(path) != path || strings.HasPrefix(path, "..") || strings.ContainsAny(path, "*?\\") || !strings.HasSuffix(path, ".go") {
return nil, fmt.Errorf("write paths must be exact project-local Go files")
if filepath.IsAbs(path) || filepath.Clean(path) != path || path == ".." || strings.HasPrefix(path, ".."+string(os.PathSeparator)) || strings.ContainsAny(path, "*?\\") {
return nil, fmt.Errorf("optional write paths must be exact run-directory-relative paths")
}
resolved, err := filepath.EvalSymlinks(filepath.Join(workspace, path))
if err != nil || !strings.HasPrefix(resolved, workspace+string(os.PathSeparator)) {
return nil, fmt.Errorf("write path must be an existing file within workspace")
parent := filepath.Join(workspace, path)
for {
_, err := os.Lstat(parent)
if err == nil {
break
}
if !os.IsNotExist(err) {
return nil, err
}
next := filepath.Dir(parent)
if next == parent {
return nil, fmt.Errorf("write path is unavailable")
}
parent = next
}
resolved, err := filepath.EvalSymlinks(parent)
if err != nil || (resolved != workspace && !strings.HasPrefix(resolved, workspace+string(os.PathSeparator))) {
return nil, fmt.Errorf("write path must stay within the run directory")
}
}
if request.Input == nil {
@@ -99,13 +114,16 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
if stage.EffectiveType(s.Type) != stage.ModelType {
continue
}
tools, _, err := stage.ToolNames(pipeline.StageDefinition(s))
tools, explicit, err := stage.ToolNames(pipeline.StageDefinition(s))
if err != nil {
return nil, err
}
if !explicit {
request.AllowTools = true
}
for _, tool := range tools {
if (tool == "edit" || tool == "shell") && !request.AllowTools {
return nil, fmt.Errorf("stage %s: %s requires explicit manual tool approval", s.Key, tool)
if tool == "edit" || tool == "shell" {
request.AllowTools = true
}
}
}
@@ -217,7 +235,7 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
finish("failed", "error", toolErr.Error())
return
}
useAgent := stage.EffectiveType(def.Type) == stage.ModelType && (len(tools) > 0 || (request.AllowTools && !explicitTools))
useAgent := stage.EffectiveType(def.Type) == stage.ModelType && (len(tools) > 0 || !explicitTools)
client := &stage.AgentClient{OpenCodeClient: stage.OpenCodeClient{Directory: workspace}, WritePaths: request.WritePaths, Tools: tools}
client.OnSession = func(session string, active bool) error {
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)