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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! Uniform, render-ready view of the idea→plan funnel (DAG 2).
//!
//! Both data paths collapse into [`FunnelView`]:
//! * **embedded** — [`FunnelView::from_funnel`] over a replayed
//! [`nornir::funnel::Funnel`] (the viz opened the funnel `Store` locally),
//! * **remote** — built from the `Funnel.Show` gRPC `FunnelDump` (see
//! [`super::remote::funnel_show`]); that RPC already carries per-node
//! `deps`, so the funnel tab needs **no** proto/server change.
//!
//! The [`funnel_tab`](super::funnel_tab) renderer consumes only this model, so
//! it is identical local vs. remote.
use eframe::egui::Color32;
use crate::funnel::{self, NodeStatus};
/// Whole-funnel snapshot: every plan and its node DAG.
#[derive(Clone, Debug, Default)]
pub struct FunnelView {
pub plans: Vec<PlanView>,
}
/// One submitted intake item (idea or error), newest-first, with its derived
/// triage→plan status + lineage — the unit the FI2 history list renders. Both
/// the embedded path ([`FunnelView::history`]) and the remote `Funnel.History`
/// RPC collapse into this.
#[derive(Clone, Debug, PartialEq)]
pub struct HistoryItemView {
pub id: String,
/// `idea` | `error`.
pub item_kind: String,
pub text: String,
pub source: String,
pub submitted_at: String,
/// `untriaged` | `accepted` | `dropped` | `planned`.
pub status: String,
pub plan_ids: Vec<String>,
}
impl HistoryItemView {
/// True when this item is an error report (the red-tinted rows).
pub fn is_error(&self) -> bool {
self.item_kind == "error"
}
}
/// One plan = one DAG (nodes + dependency edges).
#[derive(Clone, Debug)]
pub struct PlanView {
pub id: String,
pub summary: String,
/// `PlanStatus` rendered lower-case (`draft|active|done|abandoned`).
pub status: String,
/// The originating idea's text (context header); empty when unknown.
pub idea_text: String,
pub nodes: Vec<NodeView>,
}
/// A single plan node. `deps` are the node ids this node depends on
/// (i.e. edges `dep -> self`), the wiring the topo layout flows along.
#[derive(Clone, Debug)]
pub struct NodeView {
pub id: String,
pub kind: String,
pub title: String,
pub status: NodeStat,
pub targets: Vec<String>,
pub deps: Vec<String>,
}
/// Lifecycle, mirrored from [`funnel::NodeStatus`] plus an `Unknown` for
/// statuses arriving as a free string over the wire.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NodeStat {
Pending,
Ready,
InProgress,
Done,
Blocked,
Failed,
Unknown,
}
impl NodeStat {
/// Lenient parse of the wire/Debug spelling (`Funnel.Show` ships the
/// snake_case serde repr; the CLI accepts a few synonyms).
pub fn parse(s: &str) -> Self {
match s.trim().to_ascii_lowercase().as_str() {
"pending" => Self::Pending,
"ready" => Self::Ready,
"inprogress" | "in_progress" | "active" => Self::InProgress,
"done" => Self::Done,
"blocked" => Self::Blocked,
"failed" | "abandoned" => Self::Failed,
_ => Self::Unknown,
}
}
pub fn from_node(s: NodeStatus) -> Self {
match s {
NodeStatus::Pending => Self::Pending,
NodeStatus::Ready => Self::Ready,
NodeStatus::InProgress => Self::InProgress,
NodeStatus::Done => Self::Done,
NodeStatus::Blocked => Self::Blocked,
NodeStatus::Failed => Self::Failed,
}
}
/// Palette-aware node / pin tint — routed through the active facett palette so
/// a theme switch re-skins the funnel (C8). Greens = progressing, amber =
/// stuck, red = failed: Done→GREEN, InProgress→accent, Ready→point,
/// Pending→dim, Blocked→AMBER, Failed→RED, Unknown→dim.
pub fn color_themed(&self, theme: &super::facett_theme::Theme) -> Color32 {
use super::facett_theme::{AMBER, GREEN, RED};
match self {
Self::Done => GREEN,
Self::InProgress => theme.accent,
Self::Ready => theme.point,
Self::Pending => theme.text_dim,
Self::Blocked => AMBER,
Self::Failed => RED,
Self::Unknown => theme.text_dim,
}
}
/// Compact status glyph for the node header.
pub fn glyph(self) -> &'static str {
match self {
Self::Done => "✓",
Self::InProgress => "◐",
Self::Ready => "●",
Self::Pending => "○",
Self::Blocked => "‖",
Self::Failed => "✗",
Self::Unknown => "?",
}
}
pub fn label(self) -> &'static str {
match self {
Self::Done => "done",
Self::InProgress => "in progress",
Self::Ready => "ready",
Self::Pending => "pending",
Self::Blocked => "blocked",
Self::Failed => "failed",
Self::Unknown => "unknown",
}
}
}
impl FunnelView {
/// Build from a locally-replayed funnel (embedded path).
pub fn from_funnel(f: &funnel::Funnel) -> Self {
let mut plans = Vec::new();
for plan in f.plans.values() {
let idea_text = f.ideas.get(&plan.idea_id).map(|i| i.text.clone()).unwrap_or_default();
let mut nodes = Vec::with_capacity(plan.nodes.len());
for node in plan.nodes.values() {
// deps of `node` = every `from` with edge (from -> node).
let deps = plan
.edges
.iter()
.filter(|(_, to)| to == &node.id)
.map(|(from, _)| from.to_string())
.collect();
let title = node
.prompt_excerpt
.clone()
.filter(|s| !s.is_empty())
.unwrap_or_default();
nodes.push(NodeView {
id: node.id.to_string(),
kind: node.kind.clone(),
title,
status: NodeStat::from_node(node.status),
targets: node.targets.clone(),
deps,
});
}
plans.push(PlanView {
id: plan.id.to_string(),
summary: plan.summary.clone(),
status: format!("{:?}", plan.status).to_ascii_lowercase(),
idea_text,
nodes,
});
}
// Stable, human order: by plan id.
plans.sort_by(|a, b| a.id.cmp(&b.id));
Self { plans }
}
/// FI2 — the intake history (newest-first), built from a locally-replayed
/// funnel via the shared [`crate::funnel::history`] projection so it derives
/// the exact same kind/status/lineage the CLI + server emit.
pub fn history(f: &funnel::Funnel) -> Vec<HistoryItemView> {
funnel::history(f, None, None)
.into_iter()
.map(|it| HistoryItemView {
id: it.id,
item_kind: it.item_kind.as_str().to_string(),
text: it.text,
source: it.source,
submitted_at: it.submitted_at,
status: it.status.as_str().to_string(),
plan_ids: it.plan_ids,
})
.collect()
}
}