forked from Alishahryar1/free-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransitions.py
More file actions
174 lines (121 loc) · 4.12 KB
/
Copy pathtransitions.py
File metadata and controls
174 lines (121 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""Detached transition values crossing the messaging tree ownership boundary."""
from dataclasses import dataclass
from enum import Enum
from ..models import MessageScope
from .identity import TreeIdentity
from .node import MessageReferenceKind, MessageState
from .snapshot import TreeSnapshot
class CancellationUiOwner(Enum):
"""Component responsible for the final user-visible cancellation edit."""
RUNNER = "runner"
WORKFLOW = "workflow"
class CancellationReason(Enum):
"""Customer operation that cancelled a running messaging claim."""
STOP = "stop"
CLEAR = "clear"
class AdmissionRejection(Enum):
"""Why a turn was not admitted to an execution tree."""
DUPLICATE = "duplicate"
PARENT_REMOVED = "parent_removed"
@dataclass(frozen=True, slots=True)
class NodeUiTarget:
"""Copied node coordinates needed for an external UI effect."""
scope: MessageScope
node_id: str
status_message_id: str
@dataclass(frozen=True, slots=True)
class NodeClaim:
"""Exclusive permission to execute one node in a conversation tree."""
identity: TreeIdentity
claim_id: str
node: NodeUiTarget
prompt: str
parent_session_id: str | None
@dataclass(frozen=True, slots=True)
class QueueEntry:
"""One immutable queue-position update."""
node: NodeUiTarget
position: int
@dataclass(frozen=True, slots=True)
class QueueDecision:
"""Atomic result of admitting a node to a tree."""
claim: NodeClaim | None
position: int | None
snapshot: TreeSnapshot | None
rejection: AdmissionRejection | None = None
@property
def accepted(self) -> bool:
return self.snapshot is not None
@dataclass(frozen=True, slots=True)
class CompletionResult:
"""Atomic result of releasing a claim and selecting its successor."""
next_claim: NodeClaim | None
queue: tuple[QueueEntry, ...]
@dataclass(frozen=True, slots=True)
class CancellationEffect:
"""Copied cancellation fact for the UI layer."""
node: NodeUiTarget
ui_owner: CancellationUiOwner
@dataclass(frozen=True, slots=True)
class TreeCancellation:
"""Single-tree cancellation transition consumed by the manager."""
nodes: tuple[NodeUiTarget, ...]
active_claim: NodeClaim | None
queue_update: tuple[QueueEntry, ...] | None
@dataclass(frozen=True, slots=True)
class CancellationResult:
"""External effects and persistence snapshots from a cancellation request."""
effects: tuple[CancellationEffect, ...] = ()
snapshots: tuple[TreeSnapshot, ...] = ()
@dataclass(frozen=True, slots=True)
class MessageSubtreeRemoval:
"""Single-tree atomic cancellation and reference-subtree removal."""
cancellation: TreeCancellation
removed_message_ids: frozenset[str]
removed_entire_tree: bool
@dataclass(frozen=True, slots=True)
class MessageSubtreeRemovalResult:
"""Manager result for a literal message-subtree clear."""
cancellation: CancellationResult
removed_tree_identity: TreeIdentity | None
delete_message_ids: frozenset[str]
tree_matched: bool
@dataclass(frozen=True, slots=True)
class ReplyTarget:
"""Resolved reply destination and advisory position before admission."""
node_id: str
reference_id: str
reference_kind: MessageReferenceKind
queue_position: int | None
@dataclass(frozen=True, slots=True)
class NodeView:
"""Immutable read model for diagnostics, tests, and smoke assertions."""
identity: TreeIdentity
node_id: str
state: MessageState
parent_id: str | None
session_id: str | None
@dataclass(frozen=True, slots=True)
class FailureResult:
"""Atomic node failure plus copied child UI effects."""
affected: tuple[NodeUiTarget, ...]
queue_update: tuple[QueueEntry, ...] | None
snapshot: TreeSnapshot | None
__all__ = [
"AdmissionRejection",
"CancellationEffect",
"CancellationReason",
"CancellationResult",
"CancellationUiOwner",
"CompletionResult",
"FailureResult",
"MessageSubtreeRemoval",
"MessageSubtreeRemovalResult",
"NodeClaim",
"NodeUiTarget",
"NodeView",
"QueueDecision",
"QueueEntry",
"ReplyTarget",
"TreeCancellation",
]