返回 DeepSeek-Reasonix
runtime_state.go
根目录 / internal / event / runtime_state.go
1 package event
2
3 import (
4 goaldomain "reasonix/internal/goal"
5 "reasonix/internal/nilutil"
6 )
7
8 // Todo is the v2 execution protocol's complete current-turn todo item. It is
9 // intentionally flat; legacy hierarchy and sign-off fields never enter this
10 // runtime projection.
11 type Todo struct {
12 Content string `json:"content"`
13 Status string `json:"status"`
14 }
15
16 // PendingInteraction is an immutable identity from the controller's shared
17 // interaction registry. Answer content and authorization are never exposed in
18 // the replaceable runtime snapshot.
19 type PendingInteraction struct {
20 RequestID string `json:"requestId"`
21 ToolCallID string `json:"toolCallId,omitempty"`
22 Kind string `json:"kind"`
23 HeadID string `json:"headId"`
24 TurnID string `json:"turnId"`
25 RuntimeEpoch string `json:"runtimeEpoch"`
26 }
27
28 // MaintenanceState is the currently active controller-owned maintenance job.
29 // It is absent for ordinary turns and idle sessions.
30 type MaintenanceState struct {
31 OperationID string `json:"operationId"`
32 OperationRevision uint64 `json:"operationRevision,omitempty"`
33 RuntimeEpoch string `json:"runtimeEpoch,omitempty"`
34 Kind string `json:"kind"`
35 Activity string `json:"activity"`
36 Status string `json:"status,omitempty"`
37 ErrorCode string `json:"errorCode,omitempty"`
38 Detail string `json:"detail,omitempty"`
39 Applied bool `json:"applied,omitempty"`
40 InputTokens int `json:"inputTokens,omitempty"`
41 ResultTokens int `json:"resultTokens,omitempty"`
42 Messages int `json:"messages,omitempty"`
43 }
44
45 // RuntimeStateSnapshot is a host-only, replaceable observation. It is never a
46 // transcript or durable turn record. Running retains the legacy admission gate.
47 type RuntimeStateSnapshot struct {
48 SchemaVersion int `json:"schemaVersion"`
49 HostID string `json:"hostId,omitempty"`
50 SessionID string `json:"sessionId,omitempty"`
51 SessionCodec string `json:"sessionCodec,omitempty"`
52 ProjectionEpoch string `json:"projectionEpoch"`
53 RuntimeEpoch string `json:"runtimeEpoch"`
54 ActivityRevision uint64 `json:"activityRevision"`
55 Revision uint64 `json:"revision"`
56 Phase string `json:"phase"`
57 Running bool `json:"running"`
58 TurnID string `json:"turnId"`
59 TurnStatus TurnStatus `json:"turnStatus"`
60 TurnEventSeq uint64 `json:"turnEventSeq"`
61 CommittedSeq uint64 `json:"committedEventSeq"`
62 DurableSeq uint64 `json:"durableEventSeq"`
63 Persistence string `json:"persistenceStatus"`
64 PersistenceErr string `json:"persistenceError,omitempty"`
65 HeadID string `json:"headId"`
66 PendingPrompt bool `json:"pendingPrompt"`
67 Interactions []PendingInteraction `json:"pendingInteractions"`
68 Todos []Todo `json:"todos"`
69 TodoWritten bool `json:"todoWritten"`
70 CancelRequested bool `json:"cancelRequested"`
71 Cancellable bool `json:"cancellable"`
72 BackgroundJobs int `json:"backgroundJobs"`
73 Activity string `json:"activity"`
74 Recovery *RecoveryStatus `json:"recovery,omitempty"`
75 Goal *goaldomain.View `json:"goal,omitempty"`
76 GoalError string `json:"goalError,omitempty"`
77 Maintenance *MaintenanceState `json:"maintenance,omitempty"`
78 }
79
80 func (s RuntimeStateSnapshot) ActiveWork() bool {
81 return s.Running || s.PendingPrompt || s.BackgroundJobs > 0
82 }
83
84 // RuntimeStateSink is independent of Emit: a state refresh must not become a
85 // new ledger record, extension invocation, or model-visible message.
86 type RuntimeStateSink interface{ RuntimeStateChanged(RuntimeStateSnapshot) }
87
88 func PublishRuntimeState(sink Sink, snapshot RuntimeStateSnapshot) {
89 if nilutil.IsNil(sink) {
90 return
91 }
92 if target, ok := sink.(RuntimeStateSink); ok {
93 target.RuntimeStateChanged(snapshot)
94 }
95 }
96
97 func (f AuditForwarder) RuntimeStateChanged(s RuntimeStateSnapshot) { PublishRuntimeState(f.Inner, s) }
98 func (s *syncSink) RuntimeStateChanged(snapshot RuntimeStateSnapshot) {
99 s.mu.Lock()
100 defer s.mu.Unlock()
101 PublishRuntimeState(s.inner, snapshot)
102 }
103 func (c *coalescer) RuntimeStateChanged(snapshot RuntimeStateSnapshot) {
104 c.enqueueCapability(func() { PublishRuntimeState(c.inner, snapshot) })
105 }
106
106 lines GO