@wowok/skills 1.0.6 → 1.1.0

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,606 +1,139 @@
1
- ---
1
+ ---
2
2
  name: wowok-build
3
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.
4
+ WoWok commercial service building — the canonical skill for constructing
5
+ production-ready service marketplaces (Service + Machine + Guard + Allocators + Reward + Arbitration).
8
6
 
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.
7
+ This skill covers the complete 4-phase build process for commercial services.
8
+ For individual tool usage and auxiliary objects (Demand, Treasury, Repository, Contact),
9
+ see wowok-tools.
12
10
  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
11
+ - User wants to create a commercial service/marketplace on WoWok
12
+ - User wants to build a complete workflow system with order management
13
+ - User wants to set up order splitting (Allocators), incentive pools (Reward), or dispute resolution (Arbitration)
14
+ - User mentions "build service", "create marketplace", "setup workflow", "revenue sharing"
18
15
  ---
19
16
 
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
- ```
17
+ # WoWok Commercial Service Building
334
18
 
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.
19
+ Build production-ready service marketplaces on WoWok with proper dependency management.
341
20
 
342
- ### Phase 6: Build Runtime Objects
21
+ > **Prerequisites**: Understand CREATE vs MODIFY pattern in [_index.md](../docs/skills/onchain_operations/_index.md)
22
+ > **Auxiliary Objects**: Demand, Treasury, Repository, Contact — see [wowok-tools](../wowok-tools/SKILL.md)
23
+ > **Guard Design**: See [wowok-guard](../wowok-guard/SKILL.md) | **Order Lifecycle**: See [wowok-order](../wowok-order/SKILL.md)
343
24
 
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
- ```
25
+ ---
405
26
 
406
- **ALWAYS do Phase 1 first** and show the result to the user before Phase 2.
27
+ ## Core Principle: Dependency-First Construction
407
28
 
408
- ## Common Build Patterns
29
+ Commercial services MUST be built in strict dependency order. An object cannot reference another object that does not yet exist.
409
30
 
410
- ### Pattern 1: Simple Marketplace (Permission + Guard + Service)
31
+ **Immutability Rules**:
32
+ - **Machine**: Nodes become **IMMUTABLE** after `publish: true`
33
+ - **Service**: `machine` and `order_allocators` become **LOCKED** after `publish: true`
34
+ - **Guard**: **IMMUTABLE** after creation (CREATE-only)
411
35
 
412
- For a basic buy/sell marketplace with no workflow.
36
+ **Why This Matters**: Guards created in Phase 2 validate **FUTURE** runtime objects (Order, Progress) that don't exist yet. They store query logic, not object state.
413
37
 
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)
38
+ ---
421
39
 
422
- For services that need order progress tracking through defined stages.
40
+ ## The 4-Phase Build Process
423
41
 
424
42
  ```
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
- ```
43
+ PHASE 1 Foundation
44
+ 1. Permission [permission.md](../docs/skills/onchain_operations/permission.md)
45
+ 2. Service — [service.md](../docs/skills/onchain_operations/service.md) — CREATE only, DO NOT publish
46
+ 3. Machine — [machine.md](../docs/skills/onchain_operations/machine.md) — CREATE and define ALL nodes, DO NOT publish
428
47
 
429
- ### Pattern 3: Full Commerce System (Permission + Guard + Service + Machine + Allocation + Reward + Treasury)
48
+ PHASE 2 Trust Layer
49
+ 4. Guards — [guard.md](../docs/skills/onchain_operations/guard.md) — validate Reward claims, Allocators conditions, Machine node transitions, etc. Create all guards needed.
430
50
 
431
- A complete marketplace with workflow, payment splitting, incentives, and treasury.
51
+ PHASE 3 Sub-Components
52
+ 5. Allocators — [service.md](../docs/skills/onchain_operations/service.md) — CREATE rules, MODIFY Service.order_allocators to bind
53
+ 6. Reward — [reward.md](../docs/skills/onchain_operations/reward.md) — CREATE/MODIFY incentive pools
54
+ 7. Arbitration — [arbitration.md](../docs/skills/onchain_operations/arbitration.md) — CREATE/MODIFY dispute resolution
432
55
 
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
56
+ PHASE 4 — Publication
57
+ 8. Publish Machine nodes become IMMUTABLE
58
+ 9. Bind Machine to Service MODIFY Service.machine
59
+ 10. Publish Service Machine & Allocators LOCKED
438
60
  ```
439
61
 
440
- ### Pattern 4: Order Lifecycle (after Service is published)
62
+ ---
441
63
 
442
- ```
443
- Published Service + Published Machine → Phase 6b: Demand → Phase 6c: Order → Progress tracking
444
- ```
64
+ ## Pre-Build: Discover Resources
445
65
 
446
- ### Pattern 5: Service with Arbitration (Permission + Guard + Service + Arbitration)
66
+ Query before building to avoid collisions:
447
67
 
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)
68
+ ```typescript
69
+ query_toolkit({ query_type: "account_list" })
70
+ query_toolkit({ query_type: "local_mark_list" })
71
+ query_toolkit({ query_type: "onchain_objects", objects: ["<name>"] })
72
+ wowok_buildin_info({ info_type: "permissions" })
73
+ wowok_buildin_info({ info_type: "guard_instructions" })
452
74
  ```
453
75
 
454
- ## Real-World Build Examples
76
+ **Schema**: [query_toolkit](../docs/skills/schema-query_toolkit.md) | [wowok_buildin_info](../docs/skills/schema-wowok_buildin_info.md)
455
77
 
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.
78
+ ---
457
79
 
458
- ### Example Build Sequence Comparison
80
+ ## Key Operations Reference
459
81
 
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 | — | — | — |
82
+ ### CREATE vs MODIFY
471
83
 
472
- ### Key Patterns Observed Across All Examples
84
+ See [_index.md](../docs/skills/onchain_operations/_index.md) for the unified pattern:
85
+ - **Object shape** (`{ name?, ... }`) = CREATE
86
+ - **String value** (`"<name>"`) = MODIFY
473
87
 
474
- #### Pattern A: Inline Publish (Insurance, Travel, ThreeBody)
88
+ ### Reuse Existing Objects (Recommended)
475
89
 
476
- The simplest pattern: create and publish Machine + Service in as few transactions as possible.
90
+ Instead of defining from scratch, **export from existing on-chain objects** as templates:
477
91
 
478
- ```
479
- Permission → Guard(s) → Machine (create with nodes, publish: true)
480
- Service (create with machine + order_allocators + sales, publish: true)
92
+ **Export Machine for editing:**
93
+ ```typescript
94
+ // Use any existing Machine ID or name as template
95
+ machineNode2file({ machine: "<existing_machine_id>", file_path: "./my_nodes.json" })
96
+ // Edit my_nodes.json, then use it to create new Machine
481
97
  ```
482
98
 
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)
99
+ **Export Guard for editing:**
100
+ ```typescript
101
+ // Use any existing Guard ID or name as template
102
+ guard2file({ guard: "<existing_guard_id>", file_path: "./my_guard.json" })
103
+ // Edit my_guard.json, then use it to create new Guard
501
104
  ```
502
105
 
503
- Used when: Guards need to verify that orders belong to a specific Service name, so the Service must exist before Guards are created.
106
+ **Use exported files to create new objects:**
107
+ - **Machine**: `node: { json_or_markdown_file: "./my_nodes.json" }` — loads complete node definition
108
+ - **Guard**: `root: { type: "file", file_path: "./my_guard.json" }` — loads rule tree from file
504
109
 
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
- ```
110
+ **Benefits**: Leverage proven templates, modify only what differs, significantly reduce definition workload.
526
111
 
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.
112
+ **Schemas**: [machineNode2file](../docs/skills/schema-machineNode2file.md) | [guard2file](../docs/skills/schema-guard2file.md)
528
113
 
529
- #### Pattern D: Simple Marketplace (MyShop)
114
+ ---
530
115
 
531
- When the system has allocation but the Machine is built before Guards for simplicity.
116
+ ### Error Recovery
532
117
 
533
- ```
534
- Permission → Machine (unpublished) → Contact → Guards → Service (with machine + allocation, publish)
535
- ```
118
+ | Error | Fix |
119
+ |-------|-----|
120
+ | "object not found" | `env.no_cache: true` |
121
+ | "permission denied" | Check Permission config |
122
+ | "dependency not found" | Create referenced objects first |
123
+ | "cannot modify after publish" | Machine/Allocators immutable |
124
+ | Guard validation failure | Review Guard table vs submitted data |
125
+ | "invalid object format" | Object=CREATE, String=MODIFY |
536
126
 
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.).
127
+ ---
538
128
 
539
- ### Pattern E: Minimal Guard (ThreeBody Signature)
129
+ ## Schema Reference
540
130
 
541
- The simplest possible system one Guard protecting a buy operation.
131
+ **Common Types**: [_common.md](../docs/skills/onchain_operations/_common.md)`TypedPermissionObject`, `WithPermissionObject`, `CallEnv`, `SubmissionCall`
542
132
 
543
- ```
544
- Permission → Guard (buyer == creator) → Machine (2 nodes + publish inline) → Service (with machine + publish inline)
545
- ```
133
+ **Operations** (CREATE & MODIFY): [service](../docs/skills/onchain_operations/service.md) | [machine](../docs/skills/onchain_operations/machine.md) | [permission](../docs/skills/onchain_operations/permission.md) | [repository](../docs/skills/onchain_operations/repository.md) | [treasury](../docs/skills/onchain_operations/treasury.md) | [demand](../docs/skills/onchain_operations/demand.md) | [contact](../docs/skills/onchain_operations/contact.md) | [reward](../docs/skills/onchain_operations/reward.md) | [arbitration](../docs/skills/onchain_operations/arbitration.md)
546
134
 
547
- ### Build Strategy Decision Tree
135
+ **CREATE-only**: [guard](../docs/skills/onchain_operations/guard.md) (immutable) | [payment](../docs/skills/onchain_operations/payment.md)
548
136
 
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
- ```
137
+ **MODIFY-only**: [order](../docs/skills/onchain_operations/order.md) | [progress](../docs/skills/onchain_operations/progress.md) | [personal](../docs/skills/onchain_operations/personal.md)
572
138
 
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 |
139
+ **Tools**: [query_toolkit](../docs/skills/schema-query_toolkit.md) | [guard2file](../docs/skills/schema-guard2file.md) | [machineNode2file](../docs/skills/schema-machineNode2file.md) | [all_tools](../wowok-tools/SKILL.md)