alma 0.1.1

A Bevy-native modal text editor with Vim-style navigation.
Documentation
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
use super::error::{WasmtimePluginRuntimeError, WasmtimeWorkspaceObserveTaskEnqueueError};
use crate::plugin::{
    PluginHostOwnerBatches, PluginHostOwnerDiscardReport, PluginIdentity, PluginOperationalEvent,
    PluginRevocationReport, PluginWorkspaceObserveTaskCancellationReport,
    PluginWorkspaceObserveTaskDiscardReport, PluginWorkspaceObserveTaskEnqueueReport,
    SealedPluginEffectBatch, SealedPluginWorkspaceIoBatch,
};
use std::fmt::{Debug, Formatter};

/// Runtime cleanup produced while revoking a matching Wasmtime plugin instance.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WasmtimePluginRevocationCleanup {
    /// Lifecycle revocation proof from the host state.
    pub(super) revocation: PluginRevocationReport,
    /// Runtime-owned workspace observation task cleanup.
    pub(super) workspace_observe_tasks: PluginWorkspaceObserveTaskCancellationReport,
}

impl WasmtimePluginRevocationCleanup {
    /// Returns the revoked plugin identity for display and serialization.
    #[must_use]
    pub fn identity(&self) -> &str {
        self.revocation.identity()
    }

    /// Returns the validated revoked identity.
    #[must_use]
    pub const fn identity_proof(&self) -> &PluginIdentity {
        self.revocation.identity_proof()
    }

    /// Returns the lifecycle revocation proof.
    #[must_use]
    pub const fn revocation(&self) -> &PluginRevocationReport {
        &self.revocation
    }

    /// Returns runtime-owned workspace observation task cleanup.
    #[must_use]
    pub const fn workspace_observe_tasks(&self) -> &PluginWorkspaceObserveTaskCancellationReport {
        &self.workspace_observe_tasks
    }

    /// Splits lifecycle revocation from runtime-owned cleanup.
    #[must_use]
    pub fn into_parts(self) -> WasmtimePluginRevocationCleanupParts {
        WasmtimePluginRevocationCleanupParts {
            revocation: self.revocation,
            workspace_observe_tasks: self.workspace_observe_tasks,
        }
    }
}

/// Revocation cleanup split by lifecycle and runtime-owned task cleanup.
pub struct WasmtimePluginRevocationCleanupParts {
    /// Lifecycle revocation proof from the host state.
    pub revocation: PluginRevocationReport,
    /// Runtime-owned workspace observation task cleanup.
    pub workspace_observe_tasks: PluginWorkspaceObserveTaskCancellationReport,
}

/// Successful Wasmtime update with workspace observation tasks already scheduled.
pub struct WasmtimePluginScheduledUpdate {
    /// Successful-return work for non-runtime owners.
    owner_batches: PluginHostOwnerBatches,
    /// Task ids admitted to the runtime-owned observation queue.
    scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
}

/// Scheduled update work split by the owners that must consume it next.
pub struct WasmtimePluginScheduledUpdateParts {
    /// Successful-return work for non-runtime owners.
    pub owner_batches: PluginHostOwnerBatches,
    /// Task ids already admitted to the runtime-owned observation queue.
    pub scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
}

impl WasmtimePluginScheduledUpdate {
    /// Builds the scheduled-update proof after runtime task admission succeeds.
    pub(super) fn new(
        owner_batches: PluginHostOwnerBatches,
        scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
    ) -> Self {
        assert_eq!(
            owner_batches.identity_proof(),
            scheduled_workspace_observe_tasks.identity_proof(),
            "scheduled Wasmtime update must share one plugin identity",
        );
        Self {
            owner_batches,
            scheduled_workspace_observe_tasks,
        }
    }

    /// Returns the plugin identity for display and serialization.
    #[must_use]
    pub fn identity(&self) -> &str {
        self.owner_batches.identity()
    }

    /// Returns the identity proof shared by all scheduled update work.
    #[must_use]
    pub const fn identity_proof(&self) -> &PluginIdentity {
        self.owner_batches.identity_proof()
    }

    /// Returns the sealed editor effects.
    #[must_use]
    pub const fn effects(&self) -> &SealedPluginEffectBatch {
        self.owner_batches.effects()
    }

    /// Returns the sealed workspace I/O batch.
    #[must_use]
    pub const fn workspace_io(&self) -> &SealedPluginWorkspaceIoBatch {
        self.owner_batches.workspace_io()
    }

    /// Returns the scheduled workspace observation tasks.
    #[must_use]
    pub const fn scheduled_workspace_observe_tasks(
        &self,
    ) -> &PluginWorkspaceObserveTaskEnqueueReport {
        &self.scheduled_workspace_observe_tasks
    }

    /// Returns the successful-return work that must still reach non-runtime owners.
    #[must_use]
    pub const fn owner_batches(&self) -> &PluginHostOwnerBatches {
        &self.owner_batches
    }

    /// Splits scheduled update work by runtime and non-runtime owner boundaries.
    #[must_use]
    pub fn into_parts(self) -> WasmtimePluginScheduledUpdateParts {
        WasmtimePluginScheduledUpdateParts {
            owner_batches: self.owner_batches,
            scheduled_workspace_observe_tasks: self.scheduled_workspace_observe_tasks,
        }
    }
}

impl Debug for WasmtimePluginScheduledUpdate {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        formatter
            .debug_struct("WasmtimePluginScheduledUpdate")
            .field("identity", self.identity_proof())
            .field("effect_count", &self.owner_batches.effects().effect_count())
            .field(
                "workspace_io_request_count",
                &self.owner_batches.workspace_io().request_count(),
            )
            .field(
                "scheduled_workspace_observe_task_count",
                &self.scheduled_workspace_observe_tasks.task_count(),
            )
            .finish()
    }
}

/// Workspace observation tasks that could not be scheduled after a successful update.
///
/// The guest update has already crossed the successful-return boundary. Owner work is still
/// unpublished, and the observe-task batch remains retryable through the enqueue error.
#[derive(thiserror::Error)]
#[error("plugin workspace observe task scheduling failed: {source}")]
pub struct WasmtimeWorkspaceObserveTaskScheduleError {
    /// Successful-return owner work that was not yet published.
    owner_batches: Box<PluginHostOwnerBatches>,
    /// Retryable task scheduling failure.
    #[source]
    source: Box<WasmtimeWorkspaceObserveTaskEnqueueError>,
}

/// Post-update scheduling failure split by retry owner.
pub struct WasmtimeWorkspaceObserveTaskScheduleErrorParts {
    /// Successful-return owner work that was not yet published.
    pub owner_batches: PluginHostOwnerBatches,
    /// Retryable task scheduling failure.
    pub enqueue_error: WasmtimeWorkspaceObserveTaskEnqueueError,
}

impl WasmtimeWorkspaceObserveTaskScheduleError {
    /// Builds a post-update schedule failure while keeping owner batches paired.
    pub(super) fn new(
        owner_batches: PluginHostOwnerBatches,
        source: WasmtimeWorkspaceObserveTaskEnqueueError,
    ) -> Self {
        assert_eq!(
            owner_batches.identity_proof(),
            source.batch().identity_proof(),
            "Wasmtime observe-task schedule error must share one plugin identity",
        );
        Self {
            owner_batches: Box::new(owner_batches),
            source: Box::new(source),
        }
    }

    /// Returns the plugin identity for display and serialization.
    #[must_use]
    pub fn identity(&self) -> &str {
        self.owner_batches.identity()
    }

    /// Returns the identity proof for the unpublished owner work.
    #[must_use]
    pub const fn identity_proof(&self) -> &PluginIdentity {
        self.owner_batches.identity_proof()
    }

    /// Returns the unpublished editor effects.
    #[must_use]
    pub fn effects(&self) -> &SealedPluginEffectBatch {
        self.owner_batches.effects()
    }

    /// Returns the unpublished workspace I/O.
    #[must_use]
    pub fn workspace_io(&self) -> &SealedPluginWorkspaceIoBatch {
        self.owner_batches.workspace_io()
    }

    /// Returns the unpublished owner work as one identity proof.
    #[must_use]
    pub fn owner_batches(&self) -> &PluginHostOwnerBatches {
        &self.owner_batches
    }

    /// Returns the retryable task enqueue failure.
    #[must_use]
    pub fn enqueue_error(&self) -> &WasmtimeWorkspaceObserveTaskEnqueueError {
        &self.source
    }

    /// Redacted operational event for the scheduling failure, when one is useful.
    #[must_use]
    pub fn operational_event(&self) -> Option<PluginOperationalEvent> {
        self.source.operational_event()
    }

    /// Splits successful-return work from the retryable task enqueue failure.
    #[must_use]
    pub fn into_parts(self) -> WasmtimeWorkspaceObserveTaskScheduleErrorParts {
        WasmtimeWorkspaceObserveTaskScheduleErrorParts {
            owner_batches: *self.owner_batches,
            enqueue_error: *self.source,
        }
    }

    /// Discards unpublished owner work and unscheduled observe-task work.
    #[must_use]
    pub fn discard(self) -> WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
        let WasmtimeWorkspaceObserveTaskScheduleErrorParts {
            owner_batches,
            enqueue_error,
        } = self.into_parts();
        WasmtimeWorkspaceObserveTaskScheduleDiscardReport::new(
            owner_batches.discard(),
            enqueue_error.discard_batch(),
        )
    }
}

impl Debug for WasmtimeWorkspaceObserveTaskScheduleError {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        formatter
            .debug_struct("WasmtimeWorkspaceObserveTaskScheduleError")
            .field("identity", self.identity_proof())
            .field("effect_count", &self.owner_batches.effects().effect_count())
            .field(
                "workspace_io_request_count",
                &self.owner_batches.workspace_io().request_count(),
            )
            .field("enqueue_error_kind", &self.source.kind())
            .field(
                "workspace_observe_task_count",
                &self.source.batch().task_count(),
            )
            .finish()
    }
}

/// Discard report for post-update work when observe-task scheduling is abandoned.
#[derive(Eq, PartialEq)]
pub struct WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
    /// Successful-return owner work discarded instead of published.
    owner_work: PluginHostOwnerDiscardReport,
    /// Observe-task batch discarded before filesystem policy execution.
    workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
}

/// Post-update schedule discard report split by owner boundary.
pub struct WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
    /// Successful-return owner work discarded instead of published.
    pub owner_work: PluginHostOwnerDiscardReport,
    /// Observe-task batch discarded before filesystem policy execution.
    pub workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
}

impl WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
    /// Builds a paired discard report for a post-update schedule failure.
    pub(super) fn new(
        owner_work: PluginHostOwnerDiscardReport,
        workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
    ) -> Self {
        assert_eq!(
            owner_work.identity_proof(),
            workspace_observe_tasks.identity_proof(),
            "Wasmtime observe-task schedule discard report must share one plugin identity",
        );
        Self {
            owner_work,
            workspace_observe_tasks,
        }
    }

    /// Returns the plugin identity whose post-update work was discarded.
    #[must_use]
    pub fn identity(&self) -> &str {
        self.identity_proof().as_str()
    }

    /// Returns the validated identity shared by both report halves.
    #[must_use]
    pub const fn identity_proof(&self) -> &PluginIdentity {
        self.owner_work.identity_proof()
    }

    /// Returns the discarded owner work report.
    #[must_use]
    pub const fn owner_work(&self) -> &PluginHostOwnerDiscardReport {
        &self.owner_work
    }

    /// Returns the discarded observe-task work report.
    #[must_use]
    pub const fn workspace_observe_tasks(&self) -> &PluginWorkspaceObserveTaskDiscardReport {
        &self.workspace_observe_tasks
    }

    /// Splits the paired discard report by owner boundary.
    #[must_use]
    pub fn into_parts(self) -> WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
        WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
            owner_work: self.owner_work,
            workspace_observe_tasks: self.workspace_observe_tasks,
        }
    }
}

impl Debug for WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        formatter
            .debug_struct("WasmtimeWorkspaceObserveTaskScheduleDiscardReport")
            .field("identity", self.identity_proof())
            .field(
                "discarded_effect_count",
                &self.owner_work.effects().discarded_effects(),
            )
            .field(
                "discarded_workspace_io_request_count",
                &self.owner_work.workspace_io().discarded_requests(),
            )
            .field(
                "discarded_workspace_observe_task_count",
                &self.workspace_observe_tasks.discarded_tasks(),
            )
            .finish()
    }
}

/// Failure while running an update and scheduling its workspace observation tasks.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum WasmtimePluginUpdateScheduleError {
    /// Guest update failed before successful-return task scheduling.
    #[error(transparent)]
    Update(#[from] WasmtimePluginRuntimeError),
    /// Task scheduling failed after the guest update returned successfully.
    #[error(transparent)]
    WorkspaceObserveTasks(#[from] WasmtimeWorkspaceObserveTaskScheduleError),
}

impl WasmtimePluginUpdateScheduleError {
    /// Returns the update failure when scheduling never started.
    #[must_use]
    pub const fn update_error(&self) -> Option<&WasmtimePluginRuntimeError> {
        match self {
            Self::Update(source) => Some(source),
            Self::WorkspaceObserveTasks(_) => None,
        }
    }

    /// Returns the post-update task schedule failure.
    #[must_use]
    pub const fn workspace_observe_task_schedule_error(
        &self,
    ) -> Option<&WasmtimeWorkspaceObserveTaskScheduleError> {
        match self {
            Self::WorkspaceObserveTasks(source) => Some(source),
            Self::Update(_) => None,
        }
    }

    /// Returns the task scheduling failure when the guest update returned successfully.
    #[must_use]
    pub fn workspace_observe_task_enqueue_error(
        &self,
    ) -> Option<&WasmtimeWorkspaceObserveTaskEnqueueError> {
        match self {
            Self::WorkspaceObserveTasks(source) => Some(source.enqueue_error()),
            Self::Update(_) => None,
        }
    }

    /// Redacted operational event for this update or post-update scheduling failure.
    #[must_use]
    pub fn operational_event(&self) -> Option<PluginOperationalEvent> {
        match self {
            Self::Update(source) => source.operational_event(),
            Self::WorkspaceObserveTasks(source) => source.operational_event(),
        }
    }

    /// Consumes the top-level error and returns the paired post-update schedule failure.
    #[must_use]
    pub fn into_workspace_observe_task_schedule_error(
        self,
    ) -> Option<WasmtimeWorkspaceObserveTaskScheduleError> {
        match self {
            Self::WorkspaceObserveTasks(source) => Some(source),
            Self::Update(_) => None,
        }
    }
}