Indices of unclassified tool-derived nodes grouped into sequences separated by structural boundaries (goals, patches, human gates, errors).
(nodes: &[GraphNode])
| 125 | /// Indices of unclassified tool-derived nodes grouped into sequences |
| 126 | /// separated by structural boundaries (goals, patches, human gates, errors). |
| 127 | fn find_sequences(nodes: &[GraphNode]) -> Vec<Vec<usize>> { |
| 128 | let mut sequences = Vec::new(); |
| 129 | let mut current = Vec::new(); |
| 130 | |
| 131 | for (i, node) in nodes.iter().enumerate() { |
| 132 | if node.classified { |
| 133 | if current.len() >= 2 { |
| 134 | sequences.push(std::mem::take(&mut current)); |
| 135 | } else { |
| 136 | current.clear(); |
| 137 | } |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | match node.kind { |
| 142 | // Structural boundaries break sequences |
| 143 | NodeKind::Goal |
| 144 | | NodeKind::PatchProposal |
| 145 | | NodeKind::HumanGate |
| 146 | | NodeKind::Todo |
| 147 | | NodeKind::TodoStatusChange |
| 148 | | NodeKind::PhaseTransition |
| 149 | | NodeKind::Lesson |
| 150 | | NodeKind::LlmResponse |
| 151 | | NodeKind::HumanGateResolution => { |
| 152 | if current.len() >= 2 { |
| 153 | sequences.push(std::mem::take(&mut current)); |
| 154 | } else { |
| 155 | current.clear(); |
| 156 | } |
| 157 | } |
| 158 | // Decision nodes are already consolidated |
| 159 | NodeKind::Decision => { |
| 160 | if current.len() >= 2 { |
| 161 | sequences.push(std::mem::take(&mut current)); |
| 162 | } else { |
| 163 | current.clear(); |
| 164 | } |
| 165 | } |
| 166 | // Tool-derived nodes accumulate into the current sequence |
| 167 | NodeKind::Exploration |
| 168 | | NodeKind::Commitment |
| 169 | | NodeKind::Verification |
| 170 | | NodeKind::Execution |
| 171 | | NodeKind::Error => { |
| 172 | current.push(i); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if current.len() >= 2 { |
| 178 | sequences.push(current); |
| 179 | } |
| 180 | |
| 181 | sequences |
| 182 | } |
| 183 | |
| 184 | // ============================================================================= |