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
//! Cross-target instrumentation for AI-assisted egui development.
//!
//! `eguidev` captures widget state at frame boundaries and injects input
//! through an egui plugin registered on the first instrumented frame, keeping
//! automation aligned with the app's real event loop. This crate is the
//! instrumentation half of the automation stack: it is valid for native and
//! `wasm32` builds, and it intentionally does not ship the embedded script
//! runtime, MCP server, or screenshot machinery.
//!
//! # Quick start
//!
//! Add a [`DevMcp`] handle to your app state and wrap each frame with
//! [`FrameGuard`]. Input injection is automatic from there: the first
//! [`FrameGuard`] registers an egui plugin that drains queued input into
//! every pass of every viewport, so apps do not need any raw-input wiring.
//! The handle stays inert until a native app opts into `eguidev_runtime` and
//! attaches the embedded runtime in one bootstrap location.
//!
//! ```rust
//! use eframe::{App, egui};
//! use eguidev::{DevMcp, DevUiExt, FrameGuard};
//!
//! struct MyApp {
//! devmcp: DevMcp,
//! name: String,
//! }
//!
//! impl MyApp {
//! fn new() -> Self {
//! Self {
//! devmcp: DevMcp::new(),
//! name: String::new(),
//! }
//! }
//! }
//!
//! impl App for MyApp {
//! fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
//! let ctx = ui.ctx().clone();
//! let _guard = FrameGuard::new(&self.devmcp, &ctx);
//! egui::Frame::central_panel(ui.style()).show(ui, |ui| {
//! ui.dev_text_edit("app.name", &mut self.name);
//! if ui.dev_button("app.submit", "Submit").clicked() {
//! // ...
//! }
//! });
//! }
//! }
//! ```
//!
//! # Build modes
//!
//! - **Cross-target instrumentation**: depend on `eguidev` only. [`DevMcp`],
//! [`FrameGuard`], widget tagging, and fixtures all compile for native and
//! `wasm32` targets.
//! - **Native embedded runtime**: add an app-local feature that enables the
//! optional `eguidev_runtime` dependency, then call
//! `eguidev_runtime::attach(devmcp)` in one bootstrap location. Keep that
//! branch local to startup code instead of pushing `#[cfg]` into widget code.
//!
//! # Instrumenting widgets
//!
//! Use the [`DevUiExt`] trait for standard widgets. Each `dev_*` method takes
//! an explicit string id and auto-populates role, label, and value metadata:
//!
//! ```rust,ignore
//! ui.dev_button("settings.save", "Save");
//! ui.dev_text_edit("settings.name", &mut name);
//! ui.dev_checkbox("settings.enabled", &mut enabled, "Enabled");
//! ui.dev_slider("settings.level", &mut level, 0.0..=100.0);
//! ```
//!
//! For custom widgets, use [`id`] (geometry only) or [`id_with_meta`] (explicit
//! role/value/label). If you already have an `egui::Response`, use
//! [`track_response_full`] to register it after the fact. Use [`container`] to
//! annotate hierarchy so scripts can traverse parent/child relationships.
//!
//! Custom widgets that should accept scripted `set_value(...)` calls must also
//! consume queued overrides before rendering:
//!
//! ```rust,ignore
//! let id = "settings.mode";
//! if let Some(crate::WidgetValue::Int(index)) = take_widget_value_override(ui, id) {
//! *selected = index as usize;
//! }
//!
//! let response = render_custom_mode_picker(ui, selected);
//! track_response_full(
//! id,
//! &response,
//! WidgetMeta {
//! role: WidgetRole::ComboBox,
//! value: Some(WidgetValue::Int(*selected as i64)),
//! role_state: Some(RoleState::ComboBox {
//! options: mode_labels.clone(),
//! }),
//! ..Default::default()
//! },
//! );
//! ```
//!
//! Widget ids are the one canonical selector in the scripting API. Explicit ids
//! must be unique within a captured frame; duplicates are treated as a hard
//! automation fault.
//!
//! # Fixtures
//!
//! Apps register fixtures with [`DevMcp::fixtures`] and a handler callback
//! with [`DevMcp::on_fixture`]. Each fixture must be independently invokable
//! from any prior state and must leave the app in a baseline that can be
//! described with readiness anchors. Use fixture preconditions for state that
//! must already be true before the handler runs, such as an external service
//! connection. Scripts call `fixture("name")` to apply the named baseline, wait
//! for fresh captures, and verify those anchors before returning. Widget and
//! viewport handles resolve fresh across fixture boundaries, so rebinding
//! `root()` after each fixture is usually unnecessary. Use `fixture_raw("name")`
//! only when you explicitly want the old fire-and-forget behavior for debugging
//! or manual setup flows.
//!
//! # Scripting reference
//!
//! The canonical Luau API, direct script evaluation helpers, and the smoketest
//! runner all live in `eguidev_runtime`. `edev` serves those checked-in
//! definitions through `script_api` and `edev --script-docs`.
pub
pub use crate::;