Validate providers and retain complete run debugging context

This commit is contained in:
2026-10-09 23:21:01 +01:00
parent f3d829bea5
commit 08b8647d5b
51 changed files with 1036 additions and 159 deletions
+5 -2
View File
@@ -66,7 +66,7 @@ func FromReference(path string) (*Connection, error) {
if err != nil {
return nil, err
}
if !info.Mode().IsRegular() || info.Mode().Perm() != 0600 || info.Size()>MaxRequest {
if !info.Mode().IsRegular() || info.Mode().Perm() != 0600 || info.Size() > MaxRequest {
return nil, fmt.Errorf("invalid private OpenCode connection reference")
}
if stat, ok := info.Sys().(*syscall.Stat_t); !ok || stat.Uid != uint32(os.Getuid()) {
@@ -242,7 +242,10 @@ func (c *Connection) Native(ctx context.Context, method, path string, body any)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
return nil, fmt.Errorf("OpenCode %s %s failed (HTTP %d)", method, path, response.StatusCode)
// The stage adapter stores bounded, redacted failure evidence separately;
// the public error string remains free of provider bodies and credentials.
evidence, _ := io.ReadAll(io.LimitReader(response.Body, 16<<10))
return evidence, fmt.Errorf("OpenCode %s %s failed (HTTP %d)", method, path, response.StatusCode)
}
if !strings.HasPrefix(response.Header.Get("Content-Type"), "application/json") {
return nil, fmt.Errorf("OpenCode %s %s returned a non-JSON API response", method, path)
+3 -3
View File
@@ -96,7 +96,7 @@ func (c *Connection) Call(ctx context.Context, method, path string, body any) ([
}
created, err := c.Native(ctx, "post", "/session", payload)
if err != nil {
return nil, err
return created, err
}
var session struct {
ID string `json:"id"`
@@ -163,7 +163,7 @@ func (c *Connection) Call(ctx context.Context, method, path string, body any) ([
}
response, err := c.Native(ctx, "post", "/session/"+id+"/message", payload)
if err != nil {
return nil, err
return response, err
}
c.responses[id] = response
if parts[1] == "prompt" {
@@ -171,7 +171,7 @@ func (c *Connection) Call(ctx context.Context, method, path string, body any) ([
}
result, err := messageText(response)
if err != nil {
return nil, err
return response, err
}
return json.Marshal(map[string]any{"data": map[string]string{"text": result}})
case "wait":