返回 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 // RuntimeStateSnapshot is a host-only, replaceable observation. It is never a
29 // transcript or durable turn record. Running retains the legacy admission gate.
30 type RuntimeStateSnapshot struct {
31 SchemaVersion int `json:"schemaVersion"`
32 HostID string `json:"hostId,omitempty"`
33 SessionID string `json:"sessionId,omitempty"`
34 SessionCodec string `json:"sessionCodec,omitempty"`
35 ProjectionEpoch string `json:"projectionEpoch"`
36 RuntimeEpoch string `json:"runtimeEpoch"`
37 ActivityRevision uint64 `json:"activityRevision"`
38 Revision uint64 `json:"revision"`
39 Phase string `json:"phase"`
40 Running bool `json:"running"`
41 TurnID string `json:"turnId"`
42 TurnStatus TurnStatus `json:"turnStatus"`
43 TurnEventSeq uint64 `json:"turnEventSeq"`
44 CommittedSeq uint64 `json:"committedEventSeq"`
45 DurableSeq uint64 `json:"durableEventSeq"`
46 Persistence string `json:"persistenceStatus"`
47 PersistenceErr string `json:"persistenceError,omitempty"`
48 HeadID string `json:"headId"`
49 PendingPrompt bool `json:"pendingPrompt"`
50 Interactions []PendingInteraction `json:"pendingInteractions"`
51 Todos []Todo `json:"todos"`
52 TodoWritten bool `json:"todoWritten"`
53 CancelRequested bool `json:"cancelRequested"`
54 Cancellable bool `json:"cancellable"`
55 BackgroundJobs int `json:"backgroundJobs"`
56 Activity string `json:"activity"`
57 Recovery *RecoveryStatus `json:"recovery,omitempty"`
58 Goal *goaldomain.View `json:"goal,omitempty"`
59 GoalError string `json:"goalError,omitempty"`
60 }
61
62 func (s RuntimeStateSnapshot) ActiveWork() bool {
63 return s.Running || s.PendingPrompt || s.BackgroundJobs > 0
64 }
65
66 // RuntimeStateSink is independent of Emit: a state refresh must not become a
67 // new ledger record, extension invocation, or model-visible message.
68 type RuntimeStateSink interface{ RuntimeStateChanged(RuntimeStateSnapshot) }
69
70 func PublishRuntimeState(sink Sink, snapshot RuntimeStateSnapshot) {
71 if nilutil.IsNil(sink) {
72 return
73 }
74 if target, ok := sink.(RuntimeStateSink); ok {
75 target.RuntimeStateChanged(snapshot)
76 }
77 }
78
79 func (f AuditForwarder) RuntimeStateChanged(s RuntimeStateSnapshot) { PublishRuntimeState(f.Inner, s) }
80 func (s *syncSink) RuntimeStateChanged(snapshot RuntimeStateSnapshot) {
81 s.mu.Lock()
82 defer s.mu.Unlock()
83 PublishRuntimeState(s.inner, snapshot)
84 }
85 func (c *coalescer) RuntimeStateChanged(snapshot RuntimeStateSnapshot) {
86 c.enqueueCapability(func() { PublishRuntimeState(c.inner, snapshot) })
87 }
88
88 lines GO