oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package claude
2
3import (
4 "encoding/json"
5 "errors"
6 "strings"
7
8 "amadan.net/oficina/equipo/internal/runner/provider"
9)
10
11// Only fixed categories and observed numbers leave this boundary, never stderr text.
12func failurePayload(s *sessionState, last string, exit provider.Exit, waitErr error) json.RawMessage {
13 d := struct {
14 Reason, LastFrame, Stderr string
15 ExitCode, Signal *int
16 EgressDenials *uint64
17 }{Reason: failureReason(s.err), LastFrame: last, Stderr: "unknown"}
18 if waitErr == nil {
19 d.ExitCode = &exit.Code
20 d.Signal = &exit.Signal
21 }
22 if s.capture.Diagnostics != nil {
23 d.Stderr = stderrCategory(s.capture.Diagnostics())
24 }
25 if p, ok := s.process.(interface{ EgressDenials() uint64 }); ok {
26 n := p.EgressDenials()
27 d.EgressDenials = &n
28 }
29 raw, _ := json.Marshal(d)
30 return raw
31}
32
33func failureReason(err error) string {
34 switch {
35 case errors.Is(err, provider.ErrPolicy):
36 return "policy_rejected"
37 case errors.Is(err, provider.ErrIdentity):
38 return "identity_rejected"
39 case errors.Is(err, errProtocol):
40 return "protocol_rejected"
41 case errors.Is(err, errFailed):
42 return "process_or_result_failed"
43 case errors.Is(err, errUncertain):
44 return "incomplete_turn"
45 default:
46 return "capture_or_lifecycle_failed"
47 }
48}
49
50func stderrCategory(s string) string {
51 switch {
52 case s == "":
53 return "empty"
54 case strings.Contains(s, "Sandbox required but unavailable"):
55 return "sandbox_unavailable"
56 case strings.Contains(s, "bwrap:"):
57 return "sandbox_setup_failed"
58 case strings.Contains(s, "403 Forbidden"):
59 return "http_forbidden"
60 case strings.Contains(s, "401 Unauthorized"):
61 return "authentication_failed"
62 case strings.Contains(s, "429"):
63 return "rate_limited"
64 default:
65 return "other"
66 }
67}
68
69func frameCategory(raw []byte) string {
70 var v struct{ Type, Subtype string }
71 if json.Unmarshal(raw, &v) != nil {
72 return "malformed"
73 }
74 switch v.Type {
75 case "system":
76 if v.Subtype == "init" {
77 return "system/init"
78 }
79 return "system/other"
80 case "assistant", "user", "result", "control_request", "control_response":
81 return v.Type
82 default:
83 return "other"
84 }
85}
86