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
//! MotherChild trait and supporting types
//!
//! Defines the plugin interface for Mother's children.
//! Children are black boxes that own state and handle requests.
//! Mother iterates children, routes to them, doesn't know their internals.
//!
//! Today these are native Rust traits (dependable-rust pattern).
//! The trait maps to a WIT world — when patina-platform lands,
//! children become WASM plugins. Same shape at both stages.
//!
//! See: layer/surface/build/feat/mother-architecture/SPEC.md
use Result;
use fmt;
// =========================================================================
// Core Trait
// =========================================================================
/// A child plugin running in Mother's daemon context.
///
/// Children are black boxes: they own some state and handle requests.
/// Mother iterates children, routes to them by name, doesn't know their
/// internals. Children never spawn processes directly — they request
/// toys via `tick()` and Mother runs them.
///
/// # Concurrency
///
/// `handle()` takes `&self` because the daemon serves requests concurrently.
/// Children needing mutable state in handlers use interior mutability (Mutex).
/// `on_load()`, `on_unload()`, and `tick()` take `&mut self` — they run
/// single-threaded in the daemon's lifecycle/heartbeat loop.
// =========================================================================
// Health
// =========================================================================
/// Child health status, returned by health checks.
// =========================================================================
// Request / Response
// =========================================================================
/// A request routed to a child by Mother.
///
/// Children receive actions as strings and deserialize the payload
/// into their own types. This maps cleanly to a future WIT interface
/// where actions are string-dispatched.
/// A response from a child.
// =========================================================================
// Toys
// =========================================================================
/// Work that a child asks Mother to run.
///
/// The child decides *what*. Mother handles *how*.
/// Children never spawn processes directly — they return toys
/// from `tick()` and Mother spawns and monitors them.
// =========================================================================
// Host Capabilities
// =========================================================================
/// Capabilities Mother provides to children.
///
/// A child only sees what the host exposes. It cannot reach into
/// other children's state or touch project internals.
///
/// Note: Exact API emerges from implementing children.
/// Methods are added as needs become concrete.