@wowok/skills 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,447 +1,286 @@
1
1
  ---
2
2
  name: wowok-machine
3
3
  description: |
4
- WoWok Machine workflow designdefines multi-step workflows (state machines)
5
- for order processing. Machines control how orders progress through stages,
6
- who can advance them, and what conditions must be met at each step.
7
-
8
- Use this skill when designing or modifying Machine workflows, creating
9
- Progress tracking, or troubleshooting workflow advancement issues.
4
+ WoWok Machine Workflow Designthe canonical skill for designing, building,
5
+ and operating automated workflow templates (Machines) on WoWok. Machines are
6
+ directed graphs that define how orders progress through stages, who can
7
+ advance them, and what conditions must be met at each step.
8
+
9
+ Covers Machine architecture (Nodes, Pairs, Forwards, Guards, Thresholds),
10
+ lifecycle management (create, configure, publish, pause), node operations
11
+ (add, exchange, rename, granular forward/prior-node manipulation),
12
+ Progress integration, cross-service sub-order creation, privacy-preserving
13
+ consensus patterns, and export/import workflows via machineNode2file.
10
14
  when_to_use:
11
15
  - User wants to create or modify a Machine workflow
12
16
  - User asks about workflow steps, state transitions, or progress
13
17
  - User needs to design order processing pipelines
14
18
  - User mentions "machine", "workflow", "progress", "state machine", "pipeline"
19
+ - User wants to export Machine nodes to a file or import from a file
20
+ - User needs to understand threshold mechanics, forward permissions, or guard bindings
15
21
  ---
16
22
 
17
23
  # WoWok Machine Workflow Design
18
24
 
19
- ## What is a Machine?
25
+ Design, build, and operate automated workflow templates.
20
26
 
21
- A Machine is a **workflow template** that defines how orders progress through stages. It's a directed graph where:
22
- - **Nodes** = stages/states in the workflow
23
- - **Forwards** = allowed transitions between nodes
24
- - **Guards** = conditions that must be met to advance
25
- - **Pairs** = data fields tracked at each node
27
+ > **Role**: Service Provider or Workflow Designer
28
+ > **Key Tools**: `onchain_operations` with `operation_type: "machine"`
29
+ > **Related Skills**: [wowok-guard](../wowok-guard/SKILL.md) (Guards), [wowok-provider](../wowok-provider/SKILL.md) (Service binding), [wowok-order](../wowok-order/SKILL.md) (customer perspective), [wowok-tools](../wowok-tools/SKILL.md) (schema reference)
26
30
 
27
- ## Machine Structure
28
-
29
- **Operation**: `onchain_operations` with `operation_type: "machine"`.
30
-
31
- **Schema Reference**: `schema_query({ action: "get", name: "onchain_operations_machine" })`
32
-
33
- **Key Fields**:
34
- - `object`: Machine object name (CREATE) or ID (MODIFY)
35
- - `service`: Which Service this Machine belongs to
36
- - `guard`: Guard for workflow validation
37
- - `node`: Node configuration with:
38
- - `op`: Operation type ("set", "add", "remove")
39
- - `nodes`: Array of node definitions
40
- - `bReplace`: Replace existing nodes flag
41
-
42
- ### Node Structure
43
-
44
- Each node contains:
45
- - `name`: Unique node identifier
46
- - `pairs`: Data fields at this node (array of pair definitions)
47
- - `forwards`: Allowed next nodes (array of forward definitions)
48
- - `guard`: Guard for entering this node
49
- - `threshold`: Required signers to advance
31
+ ---
50
32
 
51
- ## Machine Node Design Rules
33
+ ## Core Concepts
52
34
 
53
- ### Rule 1: Every Node Needs a Unique Name
54
- Node names are identifiers. Use descriptive names like "pending", "in_progress", "review", "completed".
35
+ ### What is a Machine?
55
36
 
56
- ### Rule 2: Forwards Define the Graph
57
- Each node's `forwards` array defines which nodes can be reached next. A node without forwards is a terminal/end state.
37
+ A Machine is a **workflow template** — a directed graph that defines how orders progress from creation to completion. Machines can be bound to Services (one-to-many) or operate standalone for collaborative workflows. When bound to a Service, the Machine is instantiated as a **Progress** object when an order is created. The Machine defines the rules; the Progress tracks the live execution.
58
38
 
59
- ### Rule 3: Guards Control Transitions
60
- Each forward can have a `guard` that must pass before the transition is allowed. This enables conditional workflows.
39
+ **Key Analogy**: Machine = workflow blueprint, Progress = live workflow instance.
61
40
 
62
- ### Rule 4: Pairs Define Node Data
63
- Each node's `pairs` define what data is tracked at that stage. Different nodes can track different data.
41
+ ### Immutability Rules
64
42
 
65
- ### Rule 5: Threshold Controls Multi-Sig
66
- The `threshold` field defines how many signers must approve to advance from this node. Use for multi-party approval workflows.
43
+ | Object | When Immutable | Impact |
44
+ |--------|---------------|--------|
45
+ | **Machine** | After `publish: true` | All nodes are locked; workflow topology frozen |
46
+ | **Guard** | After creation | CREATE-only, cannot modify |
67
47
 
68
- ## Common Workflow Patterns
48
+ Because published Machines are immutable, you must design the complete workflow before publishing. However, before publishing, nodes can be freely added, removed, renamed, and reorganized.
69
49
 
70
- ### Pattern 1: Linear Pipeline
71
- ```
72
- Start → Step1 → Step2 → Step3 → Done
73
- ```
74
- Simple sequential workflow. Each node forwards to exactly one next node.
50
+ ---
75
51
 
76
- **Node Configuration**:
77
- - Node "pending": forwards to "in_progress"
78
- - Node "in_progress": forwards to "review"
79
- - Node "review": forwards to "completed"
80
- - Node "completed": no forwards (terminal)
52
+ ## Machine Architecture
81
53
 
82
- ### Pattern 2: Branching Workflow
83
- ```
84
- → Approved → Completed
85
- Start → Review
86
- → Rejected → Revision → Review
87
- ```
88
- Conditional branching based on Guard validation.
89
-
90
- **Node Configuration**:
91
- - Node "review": two forwards with different guards
92
- - Forward to "approved" with approval guard
93
- - Forward to "rejected" with rejection guard
94
- - Node "approved": forward to "completed"
95
- - Node "rejected": forward to "revision"
96
- - Node "revision": forward back to "review"
97
- - Node "completed": terminal
98
-
99
- ### Pattern 3: Multi-Party Approval
100
- ```
101
- Start → Review (threshold: 3) → Completed
102
- ```
103
- Requires multiple signers to advance.
54
+ ### The Building Blocks
104
55
 
105
- **Node Configuration**:
106
- - Node "review": threshold = 3, forward to "completed"
56
+ A Machine is composed of three structural layers:
107
57
 
108
- ### Pattern 4: Parallel Tracks
109
58
  ```
110
- → Track A → Merge
111
- Start
112
- Track B Merge Done
59
+ Machine
60
+ └── Nodes (up to 200)
61
+ └── Pairs (up to 40 per node)
62
+ ├── prev_node: which prior node this pair connects from
63
+ ├── threshold: required total forward weight to advance
64
+ └── Forwards (up to 20 per pair)
65
+ ├── name: operation identifier
66
+ ├── weight: contribution toward threshold
67
+ ├── permissionIndex | namedOperator: who can execute
68
+ └── guard (optional): condition that must pass
113
69
  ```
114
- Multiple parallel work streams that converge.
115
-
116
- ## Progress Operations
117
70
 
118
- Progress tracks an order's movement through a Machine's workflow.
71
+ **Schema Reference**: `schema_query({ action: "get", name: "onchain_operations_machine" })`
119
72
 
120
- ### Advance Progress
73
+ ### Node
121
74
 
122
- **Operation**: `onchain_operations` with `operation_type: "progress"`.
75
+ A Node represents a **stage or state** in the workflow. Each node has a unique name and contains one or more Pairs defining how to reach it and what Forwards are available from it.
123
76
 
124
- **Key Fields**:
125
- - `op`: Operation type ("advance", "create", etc.)
126
- - `order`: Order ID to advance
127
- - `node`: Target node name
128
- - `pairs`: Node data to submit
77
+ Node names must be unique within a Machine. The empty string (`""`) represents the initial state — any Pair with `prev_node: ""` is an entry point. A Machine can have multiple entry nodes, each with its own threshold configuration.
129
78
 
130
- ### Query Progress History
79
+ ### Pair (NodePair)
131
80
 
132
- **Tool**: `onchain_table_data` with `query_type: "onchain_table_item_progress_history"`.
81
+ A Pair connects a previous node to the current node, defining:
82
+ - **`prev_node`**: Source node name (`""` for entry point)
83
+ - **`threshold`**: Total weight required to trigger advancement
84
+ - **`forwards`**: Available operations from this Pair
133
85
 
134
- **Key Fields**:
135
- - `parent`: Progress ID
136
- - `u64`: Sequence number
86
+ A Node can have multiple Pairs, enabling multi-path entry (e.g., "Completed" from both "Normal" and "Express" delivery).
137
87
 
138
- **Schema Reference**: `schema_query({ action: "get", name: "onchain_table_data" })`
88
+ ### Forward
139
89
 
140
- ## Machine Creation Workflow
90
+ A Forward is a **named operation** that users execute to advance the workflow. Each Forward has:
141
91
 
142
- ### Step 1: Design Nodes on Paper
143
- Sketch the workflow graph before implementation. Identify all nodes, transitions, and conditions.
92
+ - **`name`**: A descriptive operation identifier (e.g., "Confirm Order", "Ship Goods", "Complete Signature").
93
+ - **`weight`**: A 16-bit unsigned integer (0-65535) representing this Forward's contribution toward the threshold. When the sum of completed Forward weights in the current session meets or exceeds the Pair's threshold, the node transition triggers.
94
+ - **`permissionIndex`** and/or **`namedOperator`**: At least one must be specified — both can be set simultaneously, in which case the executor needs EITHER permission to execute the Forward.
144
95
 
145
- ### Step 2: Create Guards for Transitions
146
- Each conditional forward needs a Guard. Create these Guards first (see [wowok-guard](../wowok-guard/SKILL.md) skill).
96
+ **Permission Model**:
147
97
 
148
- ### Step 3: Create the Machine (Dry Run)
149
-
150
- **Operation**: `onchain_operations` with `operation_type: "machine"`.
98
+ | Field | Scope | Typical Use |
99
+ |-------|-------|-------------|
100
+ | `permissionIndex` | Shared across ALL Progress instances from this Machine | Internal roles (merchant operators, admins) — same personnel handle all workflow instances |
101
+ | `namedOperator` | Per-Progress namespace | External roles that differ per workflow instance |
151
102
 
152
- **Key Fields**:
153
- - `op`: "create"
154
- - `object`: Machine name
155
- - `description`: Machine description
156
- - `service`: Service ID this Machine belongs to
157
- - `guard`: Guard ID for workflow validation
158
- - `node`: Node configuration object
103
+ - Use `namedOperator: ""` (empty string) to grant order owner and their agents the right to execute the Forward. This is the standard way to let customers operate on their own orders.
104
+ - Use `namedOperator: "<role_name>"` for role-based operators managed per Progress instance — ideal when different orders have different delivery personnel or reviewers.
105
+ - **Both set**: When `permissionIndex` AND `namedOperator` are both specified, the executor needs EITHER permission to execute the Forward — the permissions act as alternatives. This is useful when the same operation should be executable by either internal staff (via `permissionIndex`) or external roles (via `namedOperator`).
159
106
 
160
- ### Step 4: Export and Review
107
+ **Best Practice**: Forwards should use **custom permissions** rather than built-in indices to avoid management chaos. Either create a dedicated Permission object via `onchain_operations` with `operation_type: "permission"`, or add custom indices to an existing Permission object. Define workflow-specific roles, then reference those indices in your Forwards. Query the Permission schema via `schema_query({ action: "get", name: "onchain_operations_permission" })`.
161
108
 
162
- **Tool**: `machineNode2file`.
109
+ ### Guard on Forwards
163
110
 
164
- **Key Fields**:
165
- - `machine`: Machine ID
166
- - `file_path`: Output file path
167
- - `format`: Output format ("json" or "markdown")
111
+ A Forward can include a **Guard** — an on-chain validation rule that must pass for the Forward to complete. Guards are IMMUTABLE after creation.
168
112
 
169
- ### Step 5: Execute
170
- After review, add `submission` field to execute the operation.
113
+ **Common uses**: Time-locks, external condition checks, sub-order validation, penalty verification.
171
114
 
172
- ## Machine from File
115
+ **Retained submissions**: Guards can preserve submitted values for subsequent nodes via `retained_submission`.
173
116
 
174
- Load node definitions from a local file:
117
+ > **Full Reference**: See [wowok-guard](../wowok-guard/SKILL.md) for 70+ Guard node types.
175
118
 
176
- **Operation**: `onchain_operations` with `operation_type: "machine"`.
119
+ ### Threshold Mechanics
177
120
 
178
- **Key Fields**:
179
- - `op`: "create"
180
- - `object`: Machine name
181
- - `service`: Service ID
182
- - `node.json_or_markdown_file`: Path to node definition file
121
+ The threshold is the **trigger value** for node advancement. Users execute Forwards from the current node, accumulating weight. When the **sum of completed Forward weights ≥ threshold**, the session finalizes: completed Forwards move to history, and the workflow advances to the next node.
183
122
 
184
- ## Common Machine Errors
123
+ **Competing Transitions**: If a node has multiple Pairs leading to different next nodes, the first Pair to meet its threshold wins — subsequent completions go to the newly active node. This enables competitive workflows where different paths race to completion.
185
124
 
186
- | Error | Cause | Fix |
187
- |-------|-------|-----|
188
- | "node not found" | Forward references non-existent node | Check all forward names match node names |
189
- | "guard not found" | Forward references non-existent Guard | Create the Guard first |
190
- | "circular dependency" | Infinite loop in forwards | Ensure at least one terminal node |
191
- | "threshold not met" | Not enough signers | Check threshold value and signer count |
192
- | "invalid pairs" | Node data doesn't match pairs schema | Check pairs definition matches submitted data |
125
+ **Parallel vs Sequential Execution**: By configuring thresholds and weights, you control task coordination:
126
+ - **Sequential**: `threshold = 1`, single Forward with `weight = 1` — one completion triggers advancement
127
+ - **Parallel (AND)**: `threshold = N`, N Forwards each with `weight = 1` all must complete before advancing
128
+ - **Parallel (OR)**: Multiple Pairs from same node, each with `threshold = 1` first completion wins, enabling branching paths like `A→B→C` vs `A→C` where B is optional
193
129
 
194
- ## Real-World Machine Workflows (from tested examples)
130
+ ---
195
131
 
196
- ### MyShop: 4-Node Order Processing
132
+ ## Machine Lifecycle
197
133
 
198
- **Source**: [MyShop Example](../examples/MyShop/MyShop.md)
134
+ ### Dependency-First Construction
199
135
 
200
- A linear order fulfillment workflow for an e-commerce store:
136
+ A Machine depends on a **Permission** object. Build in this order:
201
137
 
202
138
  ```
203
- Order Confirmation Shipping In TransitCompleted
204
- Order End (Cancel Order)
139
+ 1. Permission (CREATE or MODIFY to add indices) provides access control foundation; add custom indices anytime for Forwards
140
+ 2. Machine (CREATE, unpublished) → define structure and ALL nodes
141
+ 3. Guards (CREATE) → build conditions needed by Forwards
142
+ 4. Bind Guards to Forwards (MODIFY Machine) → add guard references to specific forwards
143
+ 5. Publish Machine → nodes become IMMUTABLE
144
+ 6. Bind Machine to Service (MODIFY Service) → machine field
205
145
  ```
206
146
 
207
- **Key Design**: The first node (`Order Confirmation`) has two `pairs` entries one for the initial transition (threshold=0, from empty `prev_node`) and one for cancel. Normal flow goes through Shipping → In Transit → Completed. The customer (order owner) can cancel from Order Confirmation.
147
+ **Schema Reference**: Query all Machine operations via `schema_query({ action: "get", name: "onchain_operations_machine" })`. This includes configuration (description, repository binding, pause control, publish, owner receive, contact binding, progress creation, etc.) and node manipulation operations.
208
148
 
209
- **Node Structure**:
210
- - Node "Order Confirmation": Two pairs
211
- - From empty prev_node: threshold 0, forward to "Confirm Order"
212
- - From "Order Confirmation": threshold 0, forward to "Cancel Order"
213
- - Node "Shipping": From "Order Confirmation", threshold 1, forward to "Start Shipping"
214
- - Node "In Transit": From "Shipping", threshold 1, forward to "Mark In Transit"
215
- - Node "Completed": From "In Transit", threshold 1, forward to "Complete Order"
149
+ ### Node Operations (Pre-Publish Only)
216
150
 
217
- ### MyShop Advanced: 11-Node Multi-Path Workflow
151
+ Use the `node` field with `op` value: `"add"`, `"set"`, `"remove"`, `"clear"`, `"exchange"`, `"rename"`, `"remove prior node"`, `"add forward"`, `"remove forward"`.
218
152
 
219
- **Source**: [MyShop Advanced Example](../examples/MyShop_Advanced/MyShop_Advanced.md)
153
+ **File-based Workflow**: Export via `machineNode2file`, edit, then import via `node.json_or_markdown_file`.
220
154
 
221
- An enterprise-grade workflow with dual-signature returns, reward incentives, and time-based auto-completion:
155
+ ---
222
156
 
223
- ```
224
- Order Confirmed ──→ Shipping ──→ Delivery Complete ──→ Order Complete
225
- │ │ │ │ │
226
- │ │ │ │ └──→ Non-receipt Return ──→ Return Complete
227
- │ │ │ │
228
- │ │ ├──→ Wonderful
229
- │ │ ├──→ Order Complete (time >= 10d)
230
- │ │ └──→ Lost (dual-sig, threshold=2)
231
- │ │
232
- └── Order Cancel ──┘ Receipt Return ──→ Return Fail (time >= 10d)
233
- └──→ Return Complete (dual-sig)
234
- ```
157
+ ## Progress: The Live Workflow Instance
235
158
 
236
- **Key Design Decisions**:
237
- - **Dual-signature returns**: Lost, Non-receipt Return, Receipt Return, and Return Complete all use `threshold: 2` — requiring both customer and merchant to confirm
238
- - **Time-based auto-completion**: Order Complete and Return Fail use time guards (10 days) for automatic transitions
239
- - **Wonderful rating**: Customer can rate delivery as "Wonderful" from the Shipping node, triggering reward
240
- - **"Who completes, who submits"**: The party responsible for an action submits the on-chain proof (e.g., merchant submits Merkle Root for shipping, customer for returns)
159
+ ### Progress Creation
241
160
 
242
- ### Insurance: 2-Node Time-Lock Workflow
161
+ Progress objects are created in two ways:
162
+ - **Service Order**: When an Order is created on a Service with a bound Machine, Progress is automatically instantiated
163
+ - **Direct Creation**: Via `progress_new` operation with appropriate permissions
243
164
 
244
- **Source**: [Insurance Example](../examples/Insurance/Insurance.md)
165
+ ### Progress Operations
245
166
 
246
- A minimal claim processing workflow with time-lock protection:
167
+ **Order-associated Progress** (when Forward with `namedOperator: ""`): Must advance via `order` operations.
247
168
 
248
- ```
249
- Start → Complete (time-lock guard: clock > progress.current_time + 1000ms)
250
- ```
169
+ **All other cases**: Advance via direct `progress` operations.
251
170
 
252
- **Key Design**: The Complete forward uses a Guard with `convert_witness: 100` (TypeOrderProgress) to access the Order's Progress object and query `progress.current_time`. This creates a time-lock — the claim cannot be completed until the lock duration passes.
171
+ **Advancing Progress**:
253
172
 
254
- **Node Structure**:
255
- - Node "Start": From empty prev_node, threshold 0, forward to "start_claim"
256
- - Node "Complete": From "Start", threshold 1, forward to "complete_claim" with time guard
173
+ Use `operate` field with `next_node_name`, `forward`, and optional `hold` for two-phase operation (lock with `hold: true`, submit with `hold: false`). Use `adminUnhold: true` to force-release locks.
257
174
 
258
- ### Travel: 5-Node Weather-Dependent Workflow
175
+ **Progress-level config**: `repository`, `progress_namedOperator`, `task(cannot be changed once set)`.
259
176
 
260
- **Source**: [Travel Example](../examples/Travel/Travel.md)
177
+ ### Querying Progress State
261
178
 
262
- A complex travel service workflow with insurance sub-order and weather-dependent activity:
179
+ **Tools**:
263
180
 
264
- ```
265
- Start Buy Insurance (creates sub-order) SPA Ice Scooting (weather check guard)
266
- ├──→ Complete (time-lock)
267
- └──→ Cancel
268
- ```
181
+ - `query_toolkit` with `query_type: "onchain_objects"` — query the Progress object to see its current node, sessions, and metadata.
182
+ - `query_toolkit` with `query_type: "onchain_table"` query all history records from Progress table (paginated)
183
+ - `query_toolkit` with `query_type: "onchain_table_item_progress_history"` — query single history record by sequence number
269
184
 
270
- **Key Design**:
271
- - **Insurance sub-order**: The "Buy Insurance" forward creates a sub-order on the Insurance Service via `forward_to_order_create`
272
- - **Weather-dependent activity**: The Ice Scooting forward uses a weather check Guard that queries the weather Repository
273
- - **Time-lock completion**: The Complete forward uses `convert_witness: 100` for time-lock (same as Insurance)
274
- - **Named forwards**: Each forward uses a descriptive `forward_name` for event tracking
185
+ **Schema Reference**: `schema_query({ action: "get", name: "onchain_table_data" })`
275
186
 
276
- ### ThreeBody Signature: 2-Node Simple Workflow
187
+ ---
277
188
 
278
- **Source**: [ThreeBody Signature Example](../examples/ThreeBody_Signature/ThreeBody_Signature.md)
189
+ ## Workflow Design Patterns
279
190
 
280
- The simplest possible workflow — just delivery and completion:
191
+ ### Multi-Path Workflow Example
281
192
 
193
+ **MyShop Advanced** — demonstrates branching, dual-signature, and time guards:
282
194
  ```
283
- Book DeliveredSignature Completed
195
+ Shipping Delivery Complete Order Complete
196
+ │ ├──→ Wonderful (rating, reward)
197
+ │ ├──→ Order Complete (time guard: ≥10 days, anyone push)
198
+ │ └──→ Lost (threshold: 2, merchant+customer dual-sig)
199
+
200
+ └── Delivery Complete → Non-receipt Return (threshold: 2)
201
+ └──→ Receipt Return (threshold: 2) → Return Fail (time guard)
202
+ └──→ Return Complete
284
203
  ```
285
204
 
286
- **Node Structure**:
287
- - Node "Book Delivered": From empty prev_node, threshold 0, forward to "Confirm Delivery"
288
- - Node "Signature Completed": From "Book Delivered", threshold 1, forward to "Complete Signature"
205
+ ### Sub-Order Creation (Supply Chain)
289
206
 
290
- ## Machine Workflow Design Checklist
291
-
292
- Based on patterns from all tested examples:
207
+ **Business Intent**: When advancing a Forward, automatically create a sub-order on another Service — committing to use a trusted supplier.
293
208
 
294
209
  ```
295
- Designing a Machine workflow?
296
- ├─ How many nodes?
297
- │ ├─ 2 nodes → Pattern: Start → Complete (Insurance, ThreeBody)
298
- │ ├─ 4 nodes → Pattern: Linear pipeline (MyShop)
299
- │ ├─ 5+ nodes → Pattern: Multi-path with branches (Travel, MyShop Advanced)
300
- │ └─ 11+ nodes → Pattern: Enterprise with dual-sig + time + rewards
301
-
302
- ├─ Need dual-signature (multi-party approval)?
303
- │ └─ Set threshold: 2 on the node → Both parties must confirm
304
-
305
- ├─ Need time-based auto-advancement?
306
- │ └─ Add a time guard on the forward (e.g., machine_time_10d_v2)
307
-
308
- ├─ Need sub-order creation (supply chain)?
309
- │ └─ Use forward_to_order_create on the forward (Travel → Insurance)
310
-
311
- ├─ Need initial entry (prev_node: "")?
312
- │ └─ threshold: 0 on the first pair means "anyone can enter from start"
313
-
314
- └─ Need guard on forward?
315
- └─ guard: { guard: "<guard_name>" } validates the transition
210
+ Start Buy Insurance (creates sub-order on Insurance Service) → Main Activity → Complete
316
211
  ```
317
212
 
318
- ## Machine Node Patterns Quick Reference
319
-
320
- | Pattern | Nodes | Threshold | Guard | Use Case |
321
- |---------|-------|-----------|-------|----------|
322
- | Auto-start | `prev_node: ""` | 0 | none | Entry point — anyone can start |
323
- | Single-party | `prev_node: "X"` | 1 | optional | One party advances (merchant or customer) |
324
- | Dual-signature | `prev_node: "X"` | 2 | optional | Both parties must confirm (returns, lost) |
325
- | Time-lock | `prev_node: "X"` | 1 | time guard | Auto-complete after duration |
326
- | Guarded | `prev_node: "X"` | 1 | condition guard | Weather check, Merkle root, etc. |
327
- | Sub-order | `prev_node: "X"` | 1 | guard + forward_to | Create order on another Service |
213
+ **Key Characteristics**:
214
+ - The Forward uses `forward_to_order_create` to specify the target Service for the sub-order
215
+ - The Guard on the Forward validates that the sub-order was successfully created
216
+ - Useful for supply chain transparency: "We use X supplier" becomes verifiable on-chain
328
217
 
329
- ---
218
+ **Real Example — Travel** (insurance sub-order):
219
+ - Forward "Buy Insurance" on the "Start" node creates a sub-order on the Insurance Service
220
+ - The Insurance sub-order follows its own Machine workflow independently
221
+ - Both workflows (Travel and Insurance) progress in parallel
330
222
 
331
- ## Privacy & Consensus via Messenger
223
+ ### Dual-Signature Consensus
332
224
 
333
- Sensitive logistics and customer data flow through Messenger's end-to-end encryption (never on-chain). Guard consensus follows: **who performs the key action, submits the proof; the other party confirms**.
225
+ Require both parties (customer and merchant) to confirm before advancing used for sensitive operations like returns, lost packages, and completion.
334
226
 
335
- | Scenario | Action | Proof Submission |
336
- |----------|--------|------------------|
337
- | Merchant ships | Receives address via Messenger, replies tracking number | Merchant submits Merkle Root to Guard |
338
- | Customer returns | Sends return tracking via Messenger | Customer submits Merkle Root to Guard |
339
- | Mutual confirmation | Both parties sign | Both submit confirmation proofs |
340
-
341
- This pattern is used in Machine workflows where off-chain actions (shipping, delivery) need on-chain verification via Guard proofs.
227
+ - Threshold: 2 with two Forwards each of weight: 1
228
+ - One Forward uses `namedOperator: ""` (customer), the other uses `permissionIndex` (merchant)
229
+ - Both must execute before the node transitions
342
230
 
343
231
  ---
344
232
 
345
- ## Forward Permission Model
346
-
347
- Each forward must specify either `permissionIndex` or `namedOperator`:
348
-
349
- | Field | Scope | Typical Use |
350
- |-------|-------|-------------|
351
- | `permissionIndex` | Shared across all Progress instances | Internal roles (merchant operators, admins) |
352
- | `namedOperator` | Per-Progress namespace | External roles per order instance |
233
+ ## Privacy & Off-Chain Consensus
353
234
 
354
- **Order user operations** MUST use `namedOperator("")` — this maps to the order's owner (customer).
235
+ ### The Messenger Pattern
355
236
 
356
- ---
237
+ Sensitive data (addresses, tracking numbers) flows through Messenger's end-to-end encryption — never stored on-chain. Only **Merkle Root** (cryptographic proof) goes on-chain.
357
238
 
358
- ## Guard in Forwards Use Cases
239
+ **The principle**: **Who performs the key action, submits the proof.** The other party confirms.
359
240
 
360
- The optional `guard` field in a Forward validates critical operation results before allowing the forward to complete:
241
+ | Scenario | Off-Chain Action | On-Chain Proof |
242
+ |----------|-----------------|----------------|
243
+ | Merchant ships order | Receives address via Messenger, replies with tracking number | Merchant submits Merkle Root to Guard on Forward |
244
+ | Customer returns item | Sends return tracking number via Messenger | Customer submits Merkle Root to Guard on Forward |
245
+ | Mutual confirmation | Both parties sign via Messenger | Both submit confirmation proofs |
361
246
 
362
- - **Repository submission validation**: Verify that required data was successfully submitted to a specified Repository object
363
- - **Supply chain commitment validation**: Confirm that sub-order commitments in the supply chain were fulfilled
364
- - **External condition checks**: Validate any external state or conditions that must be met before proceeding
365
- - **Service penalty validation**: Verify compensation payments for service failures (e.g., late delivery penalties)
247
+ The Merkle Root Guard validates that the communication matches the expected content pattern, ensuring accountability without exposing private data.
366
248
 
367
- When a forward has a Guard, the Guard's logic is evaluated when a user attempts to execute that forward. If the Guard returns `false`, the forward cannot be completed.
249
+ > **Full Guide**: See [wowok-messenger](../wowok-messenger/SKILL.md) for WTS evidence generation.
368
250
 
369
251
  ---
370
252
 
371
- ## Service Penalty & Compensation Pattern
253
+ ## Service Penalty Pattern
372
254
 
373
- Design Machines to handle **service failures gracefully** through automated compensation workflows. This pattern validates penalty payments before allowing workflow continuation.
255
+ Handle service failures through automated compensation workflows. Guards validate penalty payments before allowing continuation.
374
256
 
375
- ### Use Case: Late Delivery Compensation
257
+ ### Late Delivery Penalty Pattern
376
258
 
377
- **Scenario**: Courier service fails to deliver within promised timeframe. Machine requires courier to pay penalty to customer before order can proceed.
378
-
379
- ```
380
- Delivery Node ──→ Late Delivery Detected (Guard: time > deadline)
381
-
382
- ├──→ Penalty Payment Required ──→ Payment Verified (Guard)
383
- │ │
384
- └──→ Continue to Next Node ←─────────┘
385
- ```
386
-
387
- **Machine Design**:
388
- - Node "Delivery" with two forwards from "Shipping" node:
389
- - "On Time Delivery" forward: normal path
390
- - "Late Delivery" forward: with guard checking if past deadline
391
-
392
- **Guard Logic** (`delivery_penalty_guard`):
393
- - Query Progress: Get `progress.current_time` vs `expected_delivery_time`
394
- - If late: Verify Payment object showing penalty amount transferred to Order
395
- - Validate: Payment amount ≥ configured penalty rate
396
- - Validate: Payment completed within grace period
259
+ **Design**: The Shipping node has two Forwards one for on-time delivery (no guard), one for late delivery (guard checks if past deadline). The late path requires a Guard that verifies a Payment from the merchant to the customer's Order before allowing progression.
397
260
 
398
261
  **Benefits**:
399
- - **Automatic enforcement**: Late delivery cannot proceed without compensation
400
- - **Verified compensation**: Guard cryptographically verifies payment occurred
401
- - **Customer protection**: Guaranteed penalty for service failures
402
- - **Service accountability**: Forces service providers to meet commitments
403
-
404
- ### Cross-Service Collaboration Penalties
262
+ - Automatic enforcement late delivery cannot proceed without compensation
263
+ - Cryptographically verified payment
264
+ - Customer protection guarantee
265
+ - Service accountability
405
266
 
406
- **Pattern**: When multiple services collaborate (e.g., Travel + Insurance + Courier), any party's failure can trigger penalties paid to the affected customer's Order.
407
-
408
- ```
409
- Travel Order ──→ Courier Sub-order ──→ Late Delivery
410
-
411
- ├──→ Courier pays penalty to Travel Order
412
-
413
- └──→ Travel Order receives compensation
414
- (Order.receive to claim funds)
415
- ```
416
-
417
- **Implementation**:
418
- 1. Courier Service Machine has `late_delivery` node with penalty Guard
419
- 2. Guard verifies Payment from Courier Service to Travel Order
420
- 3. Travel Order's `receive` operation extracts penalty to customer
421
- 4. Workflow continues only after penalty verified
422
-
423
- **Schema Reference**: `schema_query({ action: "get", name: "onchain_operations_payment" })` — for penalty payment validation
267
+ > **Schema**: `schema_query({ action: "get", name: "onchain_operations_payment" })`
424
268
 
425
269
  ---
426
270
 
427
- ## Progress Advancement Rules
271
+ ## Common Pitfalls
428
272
 
429
- - Sum of completed forward weights ≥ threshold session moves to history, next node becomes current
430
- - Order users advance via `Order` object
431
- - Non-order users advance via `Progress` object directly
273
+ - **Publish before Guards ready**Cannot add after publish
274
+ - **No entry pair** (`prev_node: ""`) → Workflow cannot start
275
+ - **Orphaned paths** Orders get stuck
276
+ - **Wrong permission model** → Unauthorized access or lockout
277
+ - **Machine without Allocator design** → Fund distribution mismatch (map terminal nodes to allocators)
432
278
 
433
- ---
279
+ **Always test on testnet before mainnet** — Machines are immutable after publish.
434
280
 
435
- ## Schema Reference
281
+ ---
436
282
 
437
- | Purpose | Schema Name |
438
- |---------|-------------|
439
- | Machine operations | `onchain_operations_machine` |
440
- | Progress operations | `onchain_operations_progress` |
441
- | Query on-chain objects | `query_toolkit` |
442
- | Query table data | `onchain_table_data` |
443
- | Payment operations | `onchain_operations_payment` |
283
+ ## Quick Reference
444
284
 
445
- **Query Schema**: `schema_query({ action: "get", name: "<schema_name>" })`
285
+ **Limits**: 200 nodes, 40 Pairs/node, 20 Forwards/Pair | Weight: u16 | Threshold: u32
446
286
 
447
- **Related Skills**: [wowok-guard](../wowok-guard/SKILL.md) | [wowok-order](../wowok-order/SKILL.md) | [wowok-provider](../wowok-provider/SKILL.md)