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)