@wowok/skills 1.0.6

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.
Files changed (70) hide show
  1. package/README.md +156 -0
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +177 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +19 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/skills.d.ts +5 -0
  11. package/dist/skills.d.ts.map +1 -0
  12. package/dist/skills.js +46 -0
  13. package/dist/skills.js.map +1 -0
  14. package/dist/types.d.ts +9 -0
  15. package/dist/types.d.ts.map +1 -0
  16. package/dist/types.js +3 -0
  17. package/dist/types.js.map +1 -0
  18. package/examples/Insurance/Insurance.md +594 -0
  19. package/examples/Insurance/Insurance_TestResults.md +481 -0
  20. package/examples/Insurance/insurance_complete_guard_v1.json +50 -0
  21. package/examples/MyShop/MyShop.md +1353 -0
  22. package/examples/MyShop/MyShop_TestResults.md +1003 -0
  23. package/examples/MyShop_Advanced/MyShop_Advanced.md +1898 -0
  24. package/examples/MyShop_Advanced/MyShop_Advanced_MerchantSystem_TestResults.md +1297 -0
  25. package/examples/MyShop_Advanced/MyShop_Advanced_OrderFlow_TestResults.md +743 -0
  26. package/examples/MyShop_Advanced/machine_nodes.json +222 -0
  27. package/examples/ThreeBody_Signature/ThreeBody_Signature.md +776 -0
  28. package/examples/ThreeBody_Signature/ThreeBody_Signature_TestResults.md +599 -0
  29. package/examples/Travel/Travel.md +1157 -0
  30. package/examples/Travel/Travel_TestResults.md +743 -0
  31. package/examples/Travel/calc-weather-timestamps.js +8 -0
  32. package/examples/Travel/travel_machine_v2_export.json +104 -0
  33. package/examples/Travel/weather_check_guard_v1.json +51 -0
  34. package/package.json +56 -0
  35. package/schemas/onchain_operations/_common.md +236 -0
  36. package/schemas/onchain_operations/_index.md +22 -0
  37. package/schemas/onchain_operations/allocation.md +50 -0
  38. package/schemas/onchain_operations/arbitration.md +95 -0
  39. package/schemas/onchain_operations/contact.md +36 -0
  40. package/schemas/onchain_operations/demand.md +52 -0
  41. package/schemas/onchain_operations/gen_passport.md +43 -0
  42. package/schemas/onchain_operations/guard.md +136 -0
  43. package/schemas/onchain_operations/machine.md +70 -0
  44. package/schemas/onchain_operations/order.md +57 -0
  45. package/schemas/onchain_operations/payment.md +32 -0
  46. package/schemas/onchain_operations/permission.md +57 -0
  47. package/schemas/onchain_operations/personal.md +59 -0
  48. package/schemas/onchain_operations/progress.md +35 -0
  49. package/schemas/onchain_operations/repository.md +81 -0
  50. package/schemas/onchain_operations/reward.md +40 -0
  51. package/schemas/onchain_operations/service.md +104 -0
  52. package/schemas/onchain_operations/treasury.md +74 -0
  53. package/schemas/schema-account_operation.md +402 -0
  54. package/schemas/schema-guard2file.md +153 -0
  55. package/schemas/schema-local_info_operation.md +160 -0
  56. package/schemas/schema-local_mark_operation.md +148 -0
  57. package/schemas/schema-machineNode2file.md +155 -0
  58. package/schemas/schema-messenger_operation.md +547 -0
  59. package/schemas/schema-onchain_events.md +201 -0
  60. package/schemas/schema-onchain_table_data.md +334 -0
  61. package/schemas/schema-query_toolkit.md +375 -0
  62. package/schemas/schema-wip_file.md +240 -0
  63. package/schemas/schema-wowok_buildin_info.md +296 -0
  64. package/scripts/install.js +113 -0
  65. package/wowok-build/SKILL.md +606 -0
  66. package/wowok-guard/SKILL.md +374 -0
  67. package/wowok-machine/SKILL.md +512 -0
  68. package/wowok-order/SKILL.md +499 -0
  69. package/wowok-safety/SKILL.md +381 -0
  70. package/wowok-tools/SKILL.md +635 -0
@@ -0,0 +1,606 @@
1
+ ---
2
+ name: wowok-build
3
+ description: |
4
+ WoWok complex system building — the canonical skill for constructing multi-object
5
+ on-chain systems (Service + Machine + Guard + Allocation + Reward + Treasury).
6
+ Use this skill whenever the user wants to build, deploy, or modify a WoWok
7
+ service system involving multiple interdependent on-chain objects.
8
+
9
+ This skill covers: dependency chains, canonical build order, step-by-step
10
+ construction patterns, and common pitfalls. It ensures AI follows the correct
11
+ sequence and avoids the most frequent build failures.
12
+ when_to_use:
13
+ - User wants to create a new service/marketplace on WoWok
14
+ - User wants to build a workflow system with Machine + Progress
15
+ - User wants to set up order splitting, incentive pools, or fund allocation
16
+ - User mentions "build", "deploy", "create service", "setup workflow"
17
+ - User is constructing multiple interdependent on-chain objects
18
+ ---
19
+
20
+ # WoWok Complex System Building
21
+
22
+ ## Core Principle: Dependency-First Construction
23
+
24
+ You MUST build objects in dependency order — an object cannot reference another object that does not yet exist.
25
+
26
+ ## Canonical Build Order
27
+
28
+ The build process has **6 phases**. Within a phase, objects may be built in parallel. Across phases, strict ordering is enforced.
29
+
30
+ ```
31
+ PHASE 1 — Foundation
32
+ 1. Permission (access control rules)
33
+
34
+ PHASE 2 — Trust Layer
35
+ 2. Guard (trust/validation rules) — may reference Permission
36
+ ⚠️ If a Guard queries specific on-chain objects (Service, Machine, etc.)
37
+ via query_type "object", that Guard MUST be created AFTER those objects.
38
+ Guards that query system objects only (entity_registrar, balance, etc.)
39
+ are safe to create here.
40
+
41
+ PHASE 3 — Service Scaffold (unpublished)
42
+ 3. Service (marketplace listing) — references Guard, may reference Permission
43
+ Create the Service but DO NOT publish yet. The Service acts as a hub that
44
+ Machine, Allocation, Reward, and Arbitration will reference.
45
+
46
+ PHASE 4 — Service Sub-Components (built before Service publish)
47
+ 4. Machine (workflow template) — references Guard, may reference Permission
48
+ 5. Allocation (auto-distribution rules) — references Service
49
+ 6. Reward (incentive pool) — references Service
50
+ 7. Arbitration (dispute resolution) — references Service
51
+
52
+ PHASE 5 — Publish Sequence (order within this phase is CRITICAL)
53
+ 8. Publish Machine(s) — once published, node definitions become IMMUTABLE
54
+ 9. Service: set Machine reference(s) — assign published Machine(s) to Service
55
+ 10. Publish Service — Machine & Allocation are now LOCKED;
56
+ Reward(s) & Arbitration(s) can still be added after publish;
57
+ other Service settings (products, pricing, etc.) remain modifiable
58
+
59
+ PHASE 6 — Runtime Objects
60
+ 11. Treasury (team fund) — references Service
61
+ 12. Demand (service request) — references Service
62
+ 13. Order (order management) — references Service, Machine
63
+ ```
64
+
65
+ ### Why This Order Matters
66
+
67
+ #### Core Dependency Rules
68
+
69
+ - **Permission** is the absolute foundation. Service, Machine, Reward, Demand, Treasury, Repository, Contract, and Arbitration ALL use their own `permission` field for access control. Permission MUST exist first (or be a pre-existing built-in).
70
+
71
+ - **Guard** provides programmable trust/validation. Services and Machines embed Guards. Guards that query system objects (entity_registrar, balance, personal profile, etc.) can be created here safely. However, **if a Guard queries a specific custom object** (using `query_type: "object"` targeting a Service or Machine), that Guard MUST be created AFTER the object it queries. Always verify Guard query targets before placement.
72
+
73
+ - **Service** is the central hub. Machine, Allocation, Reward, Arbitration, Treasury, Demand, and Order all reference a Service. Create the Service scaffold early so sub-components have an ID to reference — but defer publishing until all required sub-components are ready.
74
+
75
+ - **Machine, Allocation, Reward, Arbitration** each depend on Guards that must be created first (Phase 2). These sub-components also reference the Service (Phase 3).
76
+
77
+ #### Publish-Phase Immutability Rules
78
+
79
+ This is the most critical constraint in the system. When a Service is published:
80
+
81
+ | Setting | Locked on Publish? | Can modify after? |
82
+ |---------|-------------------|-------------------|
83
+ | Machine reference | ✅ LOCKED | ❌ Cannot change or remove |
84
+ | Allocation rules | ✅ LOCKED | ❌ Cannot change or remove |
85
+ | Reward(s) | ❌ Not locked | ✅ Can add more Rewards |
86
+ | Arbitration(s) | ❌ Not locked | ✅ Can add more Arbitrations |
87
+ | Products / pricing | ❌ Not locked | ✅ Can add/modify products |
88
+ | buy_guard / sell_guard | ❌ Not locked | ✅ Can update guard references |
89
+ | Description / metadata | ❌ Not locked | ✅ Can update |
90
+
91
+ When a Machine is published:
92
+ | Setting | Locked on Publish? | Can modify after? |
93
+ |---------|-------------------|-------------------|
94
+ | Node definitions | ✅ LOCKED | ❌ Cannot change nodes, forwards, or pairs |
95
+
96
+ **Therefore, the publish sequence is non-negotiable**: Machine(s) MUST be published BEFORE the Service sets them, and Service MUST NOT be published until all intended Machines and Allocations are finalized and attached.
97
+
98
+ #### Sequence Rationale Summary
99
+
100
+ | Object | Must exist BEFORE this object | Why |
101
+ |--------|------------------------------|-----|
102
+ | Permission | (nothing) | Foundation — referenced by all other objects' `permission` field |
103
+ | Guard | Permission (optional) | Guards may reference Permission indices in their logic |
104
+ | Service | Guard, Permission | Service embeds buy_guard/sell_guard and permission |
105
+ | Machine | Guard, Permission (optional) | Machine nodes use Guards for transition control |
106
+ | Allocation | Service | Allocation rules split payments for a specific Service |
107
+ | Reward | Service | Reward pools belong to a specific Service |
108
+ | Arbitration | Service | Arbitration resolves disputes for a specific Service |
109
+ | Treasury | Service | Treasury holds funds for a specific Service |
110
+ | Demand | Service | Demand is a request against a specific Service |
111
+ | Order | Service, Machine | Order references the Service and its workflow Machine |
112
+
113
+ ## Step-by-Step Construction Pattern
114
+
115
+ ### Phase 0: Discover Available Resources (ALWAYS FIRST)
116
+
117
+ Before building anything, query what already exists on-chain and locally:
118
+
119
+ ```
120
+ Tool: query_toolkit (query_type: "account_list")
121
+ → Discover available accounts and their addresses
122
+
123
+ Tool: query_toolkit (query_type: "local_mark_list")
124
+ → Discover named address mappings (name→address)
125
+
126
+ Tool: query_toolkit (query_type: "onchain_objects")
127
+ → Discover existing on-chain objects (avoid name collisions)
128
+
129
+ Tool: wowok_buildin_info (info_type: "permissions")
130
+ → Discover built-in permission indices (reuse when possible)
131
+
132
+ Tool: wowok_buildin_info (info_type: "guard_instructions")
133
+ → Discover available Guard instructions (needed for Guard design)
134
+ ```
135
+
136
+ ### Phase 1: Build Permission
137
+
138
+ Permissions define **who can do what** to all other objects. Every object — Service, Machine, Reward, Demand, Treasury, Repository, Contract, Arbitration — carries a `permission` field. Permission MUST be created first.
139
+
140
+ Use built-in permissions when they suffice. Otherwise, create a custom one:
141
+
142
+ ```
143
+ Tool: onchain_operations (operation_type: "permission")
144
+ Data: {
145
+ op: "create",
146
+ name: "<permission_name>",
147
+ description: "<description>",
148
+ builder: "<account_name_or_address>",
149
+ perm: [
150
+ { name: "<perm_name>", permission_index: <number>, description: "<desc>" }
151
+ ]
152
+ }
153
+ ```
154
+
155
+ **Key rules**:
156
+ - The `builder` account becomes the initial owner. Only the builder can modify the Permission later.
157
+ - Each entry in `perm` maps a human-readable name to a built-in `permission_index` (from `wowok_buildin_info`).
158
+ - After creation, mark it: `local_mark_operation({ op: "add", data: [{ name: "my_perm", address: "<perm_id>", tags: ["permission"] }] })`
159
+
160
+ ### Phase 2: Build Guard(s)
161
+
162
+ Guards are programmable trust/validation rules. See `wowok-guard` skill for detailed node tree design.
163
+
164
+ ```
165
+ Tool: onchain_operations (operation_type: "guard")
166
+ Data: {
167
+ op: "create",
168
+ name: "<guard_name>",
169
+ description: "<description>",
170
+ table: [
171
+ { name: "<field_name>", value_type: "<type>", description: "<desc>" }
172
+ ],
173
+ root: { <guard_node_tree> }
174
+ }
175
+ ```
176
+
177
+ **Critical rules**:
178
+ - The `table` defines what input data the Guard validates at runtime.
179
+ - The `root` defines the validation logic tree (typically an `and` node).
180
+ - Every `witness` reference in the tree MUST match a field name in `table`.
181
+ - Query nodes MUST have `convert_witness` to extract comparable values.
182
+ - **⚠️ Ordering constraint**: If this Guard queries a specific on-chain object (`query_type: "object"` targeting a Service or Machine ID), that target object MUST be created BEFORE this Guard. Guards that only query system objects (entity_registrar, balance, etc.) are safe to build here.
183
+ - After creation, mark it: `local_mark_operation({ op: "add", data: [{ name: "my_guard", address: "<guard_id>", tags: ["guard"] }] })`
184
+
185
+ ### Phase 3: Build Service Scaffold (UNPUBLISHED)
186
+
187
+ Create the Service as a scaffold — it will be referenced by sub-components but NOT published yet. Do NOT set `publish: true` at this stage.
188
+
189
+ ```
190
+ Tool: onchain_operations (operation_type: "service")
191
+ Data: {
192
+ op: "create",
193
+ name: "<service_name>",
194
+ description: "<description>",
195
+ buy_guard: "<guard_name_or_id>",
196
+ sell_guard: "<guard_name_or_id>",
197
+ permission: "<permission_name_or_id>",
198
+ token_type: "<token_type>",
199
+ price: "<price>",
200
+ ...
201
+ }
202
+ ```
203
+
204
+ **Key rules**:
205
+ - `buy_guard` validates buyers (e.g., entity registration, minimum reputation).
206
+ - `sell_guard` validates sellers (e.g., credential verification).
207
+ - `permission` controls who can administer this Service.
208
+ - The Service ID returned by creation is needed by Phase 4 components.
209
+ - After creation, mark it: `local_mark_operation({ op: "add", data: [{ name: "my_service", address: "<service_id>", tags: ["service"] }] })`
210
+
211
+ ### Phase 4: Build Service Sub-Components
212
+
213
+ All sub-components reference the Service created in Phase 3. These MUST be built BEFORE the Service is published (Phase 5).
214
+
215
+ #### 4a: Build Machine(s) (workflow templates)
216
+
217
+ ```
218
+ Tool: onchain_operations (operation_type: "machine")
219
+ Data: {
220
+ op: "create",
221
+ name: "<machine_name>",
222
+ description: "<description>",
223
+ service: "<service_name_or_id>",
224
+ guard: "<guard_name_or_id>",
225
+ node: {
226
+ op: "set",
227
+ nodes: [ <machine_node_definitions> ],
228
+ bReplace: true
229
+ }
230
+ }
231
+ ```
232
+
233
+ **Key rules**:
234
+ - Each node needs a unique name, `forwards` defining transitions, and optional `guard` per transition.
235
+ - The Machine's `guard` provides a default validation context for all nodes.
236
+ - Export for review: `machineNode2file({ machine: "<machine_id>", file_path: "<path>", format: "json" })`
237
+ - Nodes CAN be modified and re-exported UNTIL the Machine is published.
238
+
239
+ #### 4b: Build Allocation(s) (payment splitting)
240
+
241
+ ```
242
+ Tool: onchain_operations (operation_type: "allocation")
243
+ Data: {
244
+ op: "create",
245
+ name: "<allocation_name>",
246
+ service: "<service_name_or_id>",
247
+ rules: [
248
+ { recipient: "<address>", share: <percentage>, discount_type: "RATES" }
249
+ ]
250
+ }
251
+ ```
252
+
253
+ **Key rules**:
254
+ - `discount_type: "RATES"` = percentage-based (share is out of 100).
255
+ - `discount_type: "FIXED"` = fixed amount split.
256
+ - Total shares should sum to 100 for RATES type.
257
+ - Allocation rules become **LOCKED** when the Service is published.
258
+
259
+ #### 4c: Build Reward(s) (incentive pools)
260
+
261
+ ```
262
+ Tool: onchain_operations (operation_type: "reward")
263
+ Data: {
264
+ op: "create",
265
+ name: "<reward_name>",
266
+ service: "<service_name_or_id>",
267
+ ...
268
+ }
269
+ ```
270
+
271
+ **Key rules**:
272
+ - Rewards can be added AFTER Service publish as well.
273
+ - Each Reward defines conditions (via Guard) for claiming incentives.
274
+
275
+ #### 4d: Build Arbitration(s) (dispute resolution)
276
+
277
+ ```
278
+ Tool: onchain_operations (operation_type: "arbitration")
279
+ Data: {
280
+ op: "create",
281
+ name: "<arbitration_name>",
282
+ service: "<service_name_or_id>",
283
+ ...
284
+ }
285
+ ```
286
+
287
+ **Key rules**:
288
+ - Arbitrations can be added AFTER Service publish as well.
289
+ - Defines how disputes on orders for this Service are resolved.
290
+
291
+ ### Phase 5: Publish Sequence (ORDER IS CRITICAL)
292
+
293
+ This phase has a **non-negotiable** internal order. Incorrect sequencing will lock settings prematurely.
294
+
295
+ #### 5a: Publish Machine(s) FIRST
296
+
297
+ ```
298
+ Tool: onchain_operations (operation_type: "machine")
299
+ Data: {
300
+ op: "publish",
301
+ name: "<machine_name>",
302
+ ...
303
+ }
304
+ submission: { sender: "<account>", gas_budget: "<amount>" }
305
+ ```
306
+
307
+ **After publishing a Machine, its node definitions (nodes, forwards, pairs) become IMMUTABLE.** Review thoroughly before this step.
308
+
309
+ #### 5b: Service sets Machine reference(s)
310
+
311
+ ```
312
+ Tool: onchain_operations (operation_type: "service")
313
+ Data: {
314
+ op: "update",
315
+ name: "<service_name>",
316
+ machine: "<machine_name_or_id>",
317
+ ...
318
+ }
319
+ ```
320
+
321
+ Assign the published Machine(s) to the Service. This reference will be locked on Service publish.
322
+
323
+ #### 5c: Publish Service LAST
324
+
325
+ ```
326
+ Tool: onchain_operations (operation_type: "service")
327
+ Data: {
328
+ op: "publish",
329
+ name: "<service_name>",
330
+ ...
331
+ }
332
+ submission: { sender: "<account>", gas_budget: "<amount>" }
333
+ ```
334
+
335
+ **After publishing a Service**:
336
+ - ✅ Machine reference is **LOCKED** — cannot change or remove.
337
+ - ✅ Allocation rules are **LOCKED** — cannot change or remove.
338
+ - ✅ Reward(s) and Arbitration(s) can still be **ADDED** (but existing ones may lock).
339
+ - ✅ Products, pricing, description, guard references can still be **MODIFIED**.
340
+ - ✅ The Service can now receive Orders.
341
+
342
+ ### Phase 6: Build Runtime Objects
343
+
344
+ These objects operate on a published Service at runtime.
345
+
346
+ #### 6a: Treasury (team fund)
347
+
348
+ ```
349
+ Tool: onchain_operations (operation_type: "treasury")
350
+ Data: {
351
+ op: "create",
352
+ name: "<treasury_name>",
353
+ service: "<service_name_or_id>",
354
+ ...
355
+ }
356
+ ```
357
+
358
+ #### 6b: Demand (service request)
359
+
360
+ ```
361
+ Tool: onchain_operations (operation_type: "demand")
362
+ Data: {
363
+ op: "create",
364
+ service: "<service_name_or_id>",
365
+ ...
366
+ }
367
+ ```
368
+
369
+ #### 6c: Order (order instance)
370
+
371
+ ```
372
+ Tool: onchain_operations (operation_type: "order")
373
+ Data: {
374
+ op: "create",
375
+ service: "<service_name_or_id>",
376
+ machine: "<machine_name_or_id>",
377
+ buyer: "<buyer_address>",
378
+ seller: "<seller_address>",
379
+ price: "<amount>",
380
+ token_type: "<token_type>",
381
+ ...
382
+ }
383
+ ```
384
+
385
+ Orders reference both the Service (marketplace context) and Machine (workflow template).
386
+
387
+ ## The Submission Pattern (Critical for Safety)
388
+
389
+ Operations that modify on-chain state support a **two-phase submission** pattern:
390
+
391
+ 1. **Phase 1 — Dry Run**: Call without `submission` to validate and get a preview
392
+ 2. **Phase 2 — Execute**: Add `submission: { sender: "<account>", gas_budget: "<amount>" }` to execute
393
+
394
+ ```
395
+ // Phase 1: Validate
396
+ onchain_operations({ operation_type: "service", data: { op: "create", ... } })
397
+
398
+ // Phase 2: Execute (only after user confirms the preview)
399
+ onchain_operations({
400
+ operation_type: "service",
401
+ data: { op: "create", ... },
402
+ submission: { sender: "my_account", gas_budget: "10000000" }
403
+ })
404
+ ```
405
+
406
+ **ALWAYS do Phase 1 first** and show the result to the user before Phase 2.
407
+
408
+ ## Common Build Patterns
409
+
410
+ ### Pattern 1: Simple Marketplace (Permission + Guard + Service)
411
+
412
+ For a basic buy/sell marketplace with no workflow.
413
+
414
+ ```
415
+ Phase 1: Permission → Phase 2: Guard → Phase 3: Service (unpublished) → Phase 5c: Publish Service
416
+ ```
417
+
418
+ No Machines, no Allocations — just Permission, Guard, and Service. Publish Service directly.
419
+
420
+ ### Pattern 2: Workflow Service (Permission + Guard + Service + Machine)
421
+
422
+ For services that need order progress tracking through defined stages.
423
+
424
+ ```
425
+ Phase 1: Permission → Phase 2: Guard → Phase 3: Service (unpublished)
426
+ → Phase 4a: Machine → Phase 5a: Publish Machine → Phase 5b: Service sets Machine → Phase 5c: Publish Service
427
+ ```
428
+
429
+ ### Pattern 3: Full Commerce System (Permission + Guard + Service + Machine + Allocation + Reward + Treasury)
430
+
431
+ A complete marketplace with workflow, payment splitting, incentives, and treasury.
432
+
433
+ ```
434
+ Phase 1: Permission → Phase 2: Guard(s) → Phase 3: Service (unpublished)
435
+ → Phase 4a: Machine → Phase 4b: Allocation → Phase 4c: Reward
436
+ → Phase 5a: Publish Machine → Phase 5b: Service sets Machine → Phase 5c: Publish Service
437
+ → Phase 6a: Treasury
438
+ ```
439
+
440
+ ### Pattern 4: Order Lifecycle (after Service is published)
441
+
442
+ ```
443
+ Published Service + Published Machine → Phase 6b: Demand → Phase 6c: Order → Progress tracking
444
+ ```
445
+
446
+ ### Pattern 5: Service with Arbitration (Permission + Guard + Service + Arbitration)
447
+
448
+ ```
449
+ Phase 1: Permission → Phase 2: Guard(s) → Phase 3: Service (unpublished)
450
+ → Phase 4d: Arbitration → Phase 5c: Publish Service
451
+ (Additional Arbitrations can be added post-publish)
452
+ ```
453
+
454
+ ## Real-World Build Examples
455
+
456
+ The following build sequences are extracted from **tested, verified examples** in `d:\wowok\docs\examples\`. Each example has been executed on testnet with actual transaction results. See the corresponding `*_TestResults.md` files for real object addresses and execution logs.
457
+
458
+ ### Example Build Sequence Comparison
459
+
460
+ | Phase | [MyShop](../examples/MyShop/MyShop.md) | [MyShop Advanced](../examples/MyShop_Advanced/MyShop_Advanced.md) | [Insurance](../examples/Insurance/Insurance.md) | [Travel](../examples/Travel/Travel.md) | [ThreeBody](../examples/ThreeBody_Signature/ThreeBody_Signature.md) |
461
+ |-------|-----------|-------------------|-----------|--------|------------|
462
+ | 1 | Permission | Permission | Permission | Permission (weather) → Repository → Permission (travel) | Permission |
463
+ | 2 | Machine (unpublished) | Service (empty, unpublished) | Guard (complete) → Guard (withdraw) | Arbitration → Guards (weather, complete, cancel, buy-insurance) | Guard (buy) |
464
+ | 3 | Contact | Guards (machine ×4, service ×2) | Machine (with nodes + publish inline) | Machine (with nodes) → Publish | Machine (with nodes) → Publish |
465
+ | 4 | Guards (withdraw, refund) | Machine (with nodes) | Service (with machine + publish inline) | Service (with machine + allocation + publish inline) | Service (with machine + publish inline) |
466
+ | 5 | Service (with machine, allocation, publish) | Publish Machine | — | — | — |
467
+ | 6 | — | Bind Machine to Service | — | — | — |
468
+ | 7 | — | Arbitration | — | — | — |
469
+ | 8 | — | Service update + publish | — | — | — |
470
+ | 9 | — | Reward + Reward Guards | — | — | — |
471
+
472
+ ### Key Patterns Observed Across All Examples
473
+
474
+ #### Pattern A: Inline Publish (Insurance, Travel, ThreeBody)
475
+
476
+ The simplest pattern: create and publish Machine + Service in as few transactions as possible.
477
+
478
+ ```
479
+ Permission → Guard(s) → Machine (create with nodes, publish: true)
480
+ → Service (create with machine + order_allocators + sales, publish: true)
481
+ ```
482
+
483
+ Used when: the system has few Guards, no complex allocation, and the Machine workflow is straightforward.
484
+
485
+ **Concrete example** (Insurance — 2 transactions after Permission):
486
+ 1. `operation_type: "machine"` with `data.object: {name, permission}`, `data.node: {op: "add", nodes: [...]}`, `data.publish: true`
487
+ 2. `operation_type: "service"` with `data.object: {name, permission, type_parameter}`, `data.machine`, `data.order_allocators`, `data.sales`, `data.publish: true`
488
+
489
+ #### Pattern B: Scaffold-First (MyShop Advanced)
490
+
491
+ Create Service empty/unpublished first to get its address, then build Guards that reference it, then finalize.
492
+
493
+ ```
494
+ Permission → Service (create empty, NO publish)
495
+ → Guards (can query Service name/address)
496
+ → Machine (create with nodes)
497
+ → Publish Machine → Bind Machine to Service
498
+ → Arbitration
499
+ → Service update (add order_allocators, sales, arbitrations) + publish
500
+ → Reward (post-publish, can still be added)
501
+ ```
502
+
503
+ Used when: Guards need to verify that orders belong to a specific Service name, so the Service must exist before Guards are created.
504
+
505
+ **Concrete example** (MyShop Advanced — 9 major steps):
506
+ 1. `operation_type: "permission"` → create + add permission indexes (1000-1015)
507
+ 2. `operation_type: "service"` → create with `data.object: {name, permission}`, NO publish
508
+ 3. `operation_type: "guard"` ×6 → 4 machine guards (merkle_root, service_order, time_10d, time_2d) + 2 service guards (merchant_win, customer_win)
509
+ 4. `operation_type: "machine"` → create with `data.object: {name, permission}`, `data.node: {op: "add", nodes: [11 nodes]}`
510
+ 5. `operation_type: "machine"` → update with `data.publish: true`
511
+ 6. `operation_type: "service"` → update with `data.machine: "<machine_name>"`
512
+ 7. `operation_type: "arbitration"` → create
513
+ 8. `operation_type: "service"` → update with `data.order_allocators`, `data.sales`, `data.arbitrations`, `data.publish: true`
514
+ 9. `operation_type: "reward"` → create + `guard_add` (post-publish, rewards can be added)
515
+
516
+ #### Pattern C: Repository-Linked (Travel)
517
+
518
+ When the system depends on external data (Repository), that data provider's objects must be built first.
519
+
520
+ ```
521
+ Weather Provider: Permission → Repository (with policies + data)
522
+ Travel Provider: Permission → Arbitration → Guards (queries weather repo)
523
+ → Machine → Publish Machine
524
+ → Service (with machine + allocation) → Publish Service
525
+ ```
526
+
527
+ Used when: a Guard queries Repository data (e.g., weather conditions). The Repository and its data must exist before the Guard that queries it.
528
+
529
+ #### Pattern D: Simple Marketplace (MyShop)
530
+
531
+ When the system has allocation but the Machine is built before Guards for simplicity.
532
+
533
+ ```
534
+ Permission → Machine (unpublished) → Contact → Guards → Service (with machine + allocation, publish)
535
+ ```
536
+
537
+ Note: MyShop creates the Machine before Guards because its Guards don't query the Service. This is valid when Guards only reference system-level queries (entity_registrar, balance, etc.).
538
+
539
+ ### Pattern E: Minimal Guard (ThreeBody Signature)
540
+
541
+ The simplest possible system — one Guard protecting a buy operation.
542
+
543
+ ```
544
+ Permission → Guard (buyer == creator) → Machine (2 nodes + publish inline) → Service (with machine + publish inline)
545
+ ```
546
+
547
+ ### Build Strategy Decision Tree
548
+
549
+ ```
550
+ Building a WoWok Service?
551
+ ├─ Guards need to query THIS Service's name?
552
+ │ ├─ YES → Scaffold-First (Pattern B): create Service empty first
553
+ │ └─ NO → Inline Publish (Pattern A): create Machine+Service directly
554
+
555
+ ├─ System depends on external Repository data?
556
+ │ └─ YES → Repository-Linked (Pattern C): build data provider objects first
557
+
558
+ ├─ Need post-publish Rewards (incentives)?
559
+ │ └─ YES → Create Reward AFTER Service publish (can always be added later)
560
+
561
+ ├─ Need Allocation (payment splitting)?
562
+ │ └─ YES → Must be set BEFORE Service publish (becomes locked)
563
+
564
+ ├─ Need Arbitration (dispute resolution)?
565
+ │ └─ Can be added BEFORE or AFTER Service publish
566
+
567
+ └─ Complexity rules:
568
+ ├─ 1-2 Guards, simple workflow → Pattern A (inline)
569
+ ├─ 5+ Guards, complex allocation → Pattern B (scaffold-first)
570
+ └─ External data dependency → Pattern C (repository-linked)
571
+ ```
572
+
573
+ ### Cross-Reference: Actual Test Results
574
+
575
+ All patterns above are verified by real testnet executions:
576
+
577
+ | Example | Test Results File | Key Verified Behaviors |
578
+ |---------|------------------|----------------------|
579
+ | MyShop | [MyShop_TestResults.md](../examples/MyShop/MyShop_TestResults.md) | Order creation, progress advancement, allocation payment |
580
+ | MyShop Advanced | [MerchantSystem](../examples/MyShop_Advanced/MyShop_Advanced_MerchantSystem_TestResults.md) + [OrderFlow](../examples/MyShop_Advanced/MyShop_Advanced_OrderFlow_TestResults.md) | Multi-path workflow, reward claims, dual-signature returns |
581
+ | Insurance | [Insurance_TestResults.md](../examples/Insurance/Insurance_TestResults.md) | Time-lock guard, sub-order creation |
582
+ | Travel | [Travel_TestResults.md](../examples/Travel/Travel_TestResults.md) | Weather-dependent guard, insurance sub-order integration |
583
+ | ThreeBody | [ThreeBody_Signature_TestResults.md](../examples/ThreeBody_Signature/ThreeBody_Signature_TestResults.md) | Buy guard verification, simple workflow
584
+
585
+ ## Critical Rules
586
+
587
+ 1. **Never skip the query phase** — always check what accounts, marks, and on-chain objects exist before building.
588
+ 2. **Always use names, not raw addresses** — use `local_mark_operation` to create human-readable names for addresses. Mark every object immediately after creation.
589
+ 3. **Build in strict phase order** — Permission first, then Guards, then Service scaffold, then sub-components, then the publish sequence. An object cannot reference an object that does not yet exist.
590
+ 4. **Respect the publish sequence** — Machine(s) published FIRST, then Service sets Machine reference, then Service published LAST. This order is non-negotiable.
591
+ 5. **Understand what locks on publish** — Machine nodes lock on Machine publish. Machine reference and Allocation lock on Service publish. Plan accordingly.
592
+ 6. **Use `no_cache: true`** when querying an object you just created to avoid stale cache reads.
593
+ 7. **Export and review before publishing** — use `guard2file` and `machineNode2file` to export definitions. Publishing is the point of no return for node definitions and structural settings.
594
+ 8. **Verify Guard query targets** — if a Guard uses `query_type: "object"` targeting a Service or Machine, ensure that target object is created BEFORE the Guard.
595
+ 9. **Always dry-run first** — call `onchain_operations` without `submission` to validate, then only execute with `submission` after user confirms the preview.
596
+
597
+ ## Error Recovery
598
+
599
+ | Error | Cause | Fix |
600
+ |-------|-------|-----|
601
+ | "object not found" after creation | Cache stale read | Retry with `no_cache: true` |
602
+ | "permission denied" | Wrong account or missing perm | Check Permission config and sender account |
603
+ | Guard validation failure | Data doesn't match Guard rules | Review Guard table and submitted data |
604
+ | "dependency not found" | Wrong build order | Verify all referenced objects exist before the dependent object |
605
+ | "cannot modify after publish" | Attempting to change locked settings | Machine nodes, Machine reference, and Allocation are immutable after publish. Create new objects if changes are needed |
606
+ | Guard queries non-existent object | Guard created before its query target | Reorder: create the target object first, then the Guard |