返回 DeepSeek-Reasonix
tool_recovery.go
根目录 / internal / control / tool_recovery.go
1 package control
2
3 import (
4 "context"
5 "crypto/sha256"
6 "encoding/hex"
7 "encoding/json"
8 "fmt"
9 "reasonix/internal/agent"
10
11 "reasonix/internal/provider"
12 )
13
14 type ToolRecoverySnapshot struct {
15 Silent bool `json:"silent"`
16 Statistics agent.ToolRecoveryStatistics `json:"statistics"`
17 SessionPath string `json:"sessionPath"`
18 RuntimeEpoch string `json:"runtimeEpoch"`
19 Revision string `json:"revision"`
20 Calls []provider.ToolCallRecord `json:"calls"`
21 RetryEnabled bool `json:"retryEnabled"`
22 Retired bool `json:"retired"`
23 }
24
25 type ToolRecoveryRequest struct {
26 SessionPath string `json:"sessionPath"`
27 RuntimeEpoch string `json:"runtimeEpoch"`
28 Revision string `json:"revision"`
29 AttemptID string `json:"attemptId"`
30 InspectionID string `json:"inspectionId"`
31 Action string `json:"action"` // inspect | confirm | reject | retry
32 }
33
34 func (c *Controller) ToolRecoverySnapshot() ToolRecoverySnapshot {
35 view := ToolRecoverySnapshot{SessionPath: c.SessionPath(), RuntimeEpoch: c.RuntimeStateSnapshot().RuntimeEpoch, Calls: []provider.ToolCallRecord{}, Retired: true}
36 if c.executor != nil {
37 view.Calls = c.executor.PendingToolRecovery()
38 view.Statistics = c.executor.ToolRecoveryStatistics()
39 view.Silent = c.executor.SilentToolRecovery()
40 }
41 // Raw parameters stay in the session. Frontends get immutable identities
42 // and inspection facts, never an executable payload supplied by the UI.
43 for i := range view.Calls {
44 view.Calls[i].Arguments = nil
45 }
46 bytes, _ := json.Marshal(view)
47 sum := sha256.Sum256(bytes)
48 view.Revision = hex.EncodeToString(sum[:])
49 return view
50 }
51
52 // ResolveToolRecovery is a wire-compatible retired endpoint. Historical facts
53 // remain queryable, but no UI or client can confirm, reject, inspect, or replay
54 // an operation through the host.
55 func (c *Controller) ResolveToolRecovery(_ context.Context, _ ToolRecoveryRequest) (ToolRecoverySnapshot, error) {
56 view := c.ToolRecoverySnapshot()
57 return view, fmt.Errorf("tool_recovery_retired: historical execution facts are read-only; inspect external state and invoke tools normally if further work is needed")
58 }
59
59 lines GO