@wowok/skills 1.1.11 → 1.1.12

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.
@@ -0,0 +1,561 @@
1
+ # Appendix — wowok-safety
2
+
3
+ > This file is loaded on-demand (Progressive Disclosure).
4
+ > Main skill: [SKILL.md](./SKILL.md)
5
+
6
+ ---
7
+
8
+ ## Dialogue Scripts (R1-R10)
9
+
10
+ A guided 10-round dialogue for the safety verification journey — runs before ANY on-chain write operation. Each round has a specific AI Goal, Key Questions, Tool Calls, Success Criteria, Fallback, and Checkpoint. Checkpoints persist via `local_info_operation` so the verification can resume after interruption.
11
+
12
+ > **Trigger**: This dialogue is automatically invoked when the user requests an on-chain write operation (transfer, publish, create, modify, etc.). It is the safety gate that all writes must pass through.
13
+
14
+ ### R1 — Operation Intent Capture
15
+
16
+ **AI Goal**: Understand exactly what operation the user wants to perform, which objects are involved, and on which network. Classify the operation as LOCAL, ON-CHAIN, or QUERY to determine the required safety checks.
17
+
18
+ **Key Questions**:
19
+ - What operation do you want to perform? (transfer, publish, create, modify, etc.)
20
+ - Which objects are involved? (names, IDs, or types)
21
+ - Which network? (testnet default, or mainnet)
22
+ - Which account? (default `""` or a specific account)
23
+
24
+ **Tool Calls**:
25
+ 1. Classify the operation: LOCAL (`account_operation`, `local_mark_operation`, `local_info_operation`) / ON-CHAIN (`onchain_operations`, `messenger_operation` some ops, `wip_file` sign) / QUERY (read-only).
26
+ 2. If QUERY → no safety gate needed, proceed directly.
27
+ 3. If LOCAL → minimal safety checks (no gas, no confirmation).
28
+ 4. If ON-CHAIN → full safety gate (R2-R10).
29
+ 5. `local_info_operation` → create a session checkpoint `{ round: R1, operation_type, objects, network, account, classification }`.
30
+
31
+ **Success Criteria**: Operation classified correctly. All involved objects identified. Network and account confirmed.
32
+
33
+ **Fallback**: User provides vague intent ("transfer some funds") → ask for specific amount, token, and recipient. User doesn't know the network → default to testnet, inform user. User doesn't specify an account → use default `""`.
34
+
35
+ **Checkpoint**: Persist `{ round: R1, operation_type, objects: [...], network, account, classification: LOCAL|ONCHAIN|QUERY }`. Mark R1 COMPLETE.
36
+
37
+ ### R2 — Account & Network Verification
38
+
39
+ **AI Goal**: Verify the account exists and has sufficient balance for the operation. Confirm the network matches the objects' chain.
40
+
41
+ **Key Questions**:
42
+ - Confirm: account `<address>` on `<network>`. Correct?
43
+ - Does the account have sufficient balance for gas and the operation amount?
44
+
45
+ **Tool Calls**:
46
+ 1. `account_operation` → `get` to confirm the account exists.
47
+ 2. `query_toolkit` → `onchain_objects` for the account object. Check balance.
48
+ 3. If balance insufficient → inform user, suggest faucet (`account_operation` → `faucet` on testnet).
49
+ 4. `local_info_operation` → persist account verification.
50
+
51
+ **Success Criteria**: Account exists. Balance sufficient for gas + operation amount. Network confirmed.
52
+
53
+ **Fallback**: Account not found → guide through `account_operation` → `gen`. Balance insufficient → suggest faucet (testnet) or fund the account (mainnet). Wrong network → warn user, switch via `env.network`.
54
+
55
+ **Checkpoint**: Persist `{ round: R2, account_verified: true, balance_sufficient: true, network_confirmed: true }`. Mark R2 COMPLETE.
56
+
57
+ ### R3 — Object Reuse vs Create Decision
58
+
59
+ **AI Goal**: For each object involved in the operation, determine whether to reuse an existing object (string reference) or create a new one (object shape). Apply the Object Reuse Principle.
60
+
61
+ **Key Questions**:
62
+ - For each object: do you have an existing one to reuse, or do you need to create new?
63
+ - If reusing: provide the name or ID.
64
+ - If creating: confirm the need for a new object.
65
+
66
+ **Tool Calls**:
67
+ 1. For each object the user wants to reuse: `query_toolkit` → `onchain_objects` to verify it exists and is owned by the account.
68
+ 2. Confirm the CREATE vs MODIFY pattern:
69
+ - String `"<name>"` or `"<0x...>"` → REUSE existing.
70
+ - Object `{ name?, ... }` → CREATE new.
71
+ 3. For Permission objects: strongly recommend reuse (centralized control).
72
+ 4. For Arbitration objects: always reuse (customers choose established arbiters).
73
+ 5. `local_info_operation` → persist the reuse/create decision per object.
74
+
75
+ **Success Criteria**: Each object has a clear reuse/create decision. Reused objects verified to exist. Created objects confirmed as necessary.
76
+
77
+ **Fallback**: User wants to reuse but object doesn't exist → SDK will throw `GetObjectExisted()` error. Either create new or correct the name/ID. User wants to create but an equivalent object exists → recommend reuse to reduce management overhead.
78
+
79
+ **Checkpoint**: Persist `{ round: R3, objects: [{name, decision: reuse|create, verified: bool}] }`. Mark R3 COMPLETE.
80
+
81
+ ### R4 — Permission & Guard Pre-Check
82
+
83
+ **AI Goal**: Verify the account has the required Permission indices for the operation. If Guards are involved, verify the user can satisfy them (or has a valid passport).
84
+
85
+ **Key Questions**:
86
+ - Does the operation require specific Permission indices?
87
+ - If Guards are involved: can you satisfy the conditions? Do you have a valid passport?
88
+
89
+ **Tool Calls**:
90
+ 1. `query_toolkit` → `onchain_objects` for the Permission object. Check the account's role/indices.
91
+ 2. For Machine forwards: verify the `namedOperator` and Guard requirements per [wowok-machine](../wowok-machine/SKILL.md).
92
+ 3. If a Guard is required and user needs a passport: `onchain_operations` → `gen_passport`.
93
+ 4. `guard2file` to export and review the Guard logic if unclear.
94
+ 5. `local_info_operation` → persist permission and guard verification.
95
+
96
+ **Success Criteria**: Account has required Permission indices. Guards are satisfiable (or passport obtained). No permission denied errors expected.
97
+
98
+ **Fallback**: Permission denied → check the object's Permission configuration. User lacks the required index → request the permission holder to grant access. Guard cannot be satisfied → flag the blocker, consider alternative path or hand off to [wowok-guard](../wowok-guard/SKILL.md) for redesign.
99
+
100
+ **Checkpoint**: Persist `{ round: R4, permission_verified: true, guard_requirements: [...], passport_obtained: bool }`. Mark R4 COMPLETE.
101
+
102
+ ### R5 — Amount & Token Verification
103
+
104
+ **AI Goal**: Verify all amounts in the operation are correct. Query token decimals — never assume. Confirm amounts are submitted as U64 integers.
105
+
106
+ **Key Questions**:
107
+ - What is the amount and token for this operation?
108
+ - Do you know the token's decimals? (I will query to verify.)
109
+ - Confirm: `<human_readable_amount>` = `<u64_integer>`?
110
+
111
+ **Tool Calls**:
112
+ 1. `query_toolkit` → `token_list` to get the token's `decimals` and `symbol`.
113
+ 2. Calculate: `u64_amount = human_amount × (10 ^ decimals)`.
114
+ 3. Present both: "2 WOW = 2000000000 (U64, 9 decimals)".
115
+ 4. Verify the operation submits the U64 integer, not the human-readable string.
116
+ 5. For multi-token operations: verify each token's decimals independently.
117
+ 6. `local_info_operation` → persist amount verification.
118
+
119
+ **Success Criteria**: Token decimals queried (not assumed). Amount converted to U64 integer. User confirmed both human-readable and U64 amounts.
120
+
121
+ **Fallback**: Token decimals cannot be queried → HALT the amount submission. Alert the user. Do not proceed with hardcoded or guessed precision. User specifies "2 WOW" → submit `2000000000`, not the string "2 WOW".
122
+
123
+ **Checkpoint**: Persist `{ round: R5, token: {symbol, decimals}, human_amount, u64_amount, verified: true }`. Mark R5 COMPLETE.
124
+
125
+ ### R6 — Export & Review (Publish Operations Only)
126
+
127
+ **AI Goal**: For publish operations (Service, Machine), export and review the definitions before publishing. Warn about immutability — many fields become locked after publish.
128
+
129
+ **Key Questions**:
130
+ - Ready to review the Guard and Machine definitions before publishing?
131
+ - Are you aware that after publish, many fields become immutable?
132
+ - Have you tested all Guard conditions and Machine transitions?
133
+
134
+ **Tool Calls**:
135
+ 1. `guard2file` to export all Guard definitions.
136
+ 2. `machineNode2file` to export all Machine node definitions.
137
+ 3. Review the exported files with the user. Confirm logic matches intent.
138
+ 4. Warn about immutability: list which fields become locked after publish.
139
+ 5. `local_info_operation` → persist the export review.
140
+
141
+ **Success Criteria**: All Guards and Machine nodes exported and reviewed. User confirms logic matches intent. User acknowledges immutability constraints.
142
+
143
+ **Fallback**: Export fails → check file format and schema compliance. User finds a logic error → fix before publishing (after publish, must create replacement objects). User is unsure about logic → hand off to [wowok-guard](../wowok-guard/SKILL.md) or [wowok-machine](../wowok-machine/SKILL.md) for detailed review.
144
+
145
+ **Checkpoint**: Persist `{ round: R6, guards_exported: [...], machine_exported: bool, reviewed: true, immutability_acknowledged: true }`. Mark R6 COMPLETE. (Skip if not a publish operation.)
146
+
147
+ ### R7 — Immutability Warning & User Confirmation
148
+
149
+ **AI Goal**: Present the final operation preview. For irreversible operations (publish, arbitration verdict, transfer), obtain explicit user confirmation. Use the confirmation template.
150
+
151
+ **Key Questions**:
152
+ - Here is the operation preview. Proceed?
153
+ - Are you aware this operation is irreversible? (if applicable)
154
+ - For amount-sensitive operations: confirm the amount and recipient.
155
+
156
+ **Tool Calls**:
157
+ 1. Render the confirmation template:
158
+ ```
159
+ 📋 Operation Preview
160
+ | Field | Value |
161
+ |-------|-------|
162
+ | Operation | {operation_type} — {op} |
163
+ | Object | {object_name} |
164
+ | Network | {network} |
165
+ | Account | {account} |
166
+ ⚠️ This will {describe_what_will_happen}
167
+ Proceed with execution?
168
+ ```
169
+ 2. For publish: add the publish confirmation warning.
170
+ 3. For transfers: display amount with token symbol (from R5).
171
+ 4. Wait for explicit user confirmation ("yes", "proceed", "confirm").
172
+ 5. `local_info_operation` → persist the confirmation.
173
+
174
+ **Success Criteria**: Operation preview rendered. User explicitly confirmed. For irreversible operations, user acknowledged irreversibility.
175
+
176
+ **Fallback**: User says "no" or hesitates → abort, ask for clarification. User says "maybe" → explain the operation in more detail, re-confirm. User asks to modify → return to the relevant R round for the change.
177
+
178
+ **Checkpoint**: Persist `{ round: R7, confirmation_template_rendered: true, user_confirmed: true, irreversible_acknowledged: bool }`. Mark R7 COMPLETE.
179
+
180
+ ### R8 — Two-Phase Submission (Call Without Submission)
181
+
182
+ **AI Goal**: Execute the first phase of the two-phase submission loop. Call the operation WITHOUT `submission` — the SDK returns a prompt confirming the operation details.
183
+
184
+ **Key Questions**:
185
+ - Ready to submit the operation? I will first call without submission to verify.
186
+ - Does the SDK prompt match our expectations?
187
+
188
+ **Tool Calls**:
189
+ 1. `onchain_operations` (or relevant tool) with the assembled operation, WITHOUT `submission`.
190
+ 2. SDK returns a prompt confirming the operation details.
191
+ 3. Verify the prompt matches R1-R7 expectations.
192
+ 4. If prompt is unexpected → diagnose (wrong object, wrong amount, wrong account).
193
+ 5. `local_info_operation` → persist the SDK prompt.
194
+
195
+ **Success Criteria**: SDK prompt received and matches expectations. Operation is ready for the second phase (with submission).
196
+
197
+ **Fallback**: SDK returns an error → diagnose: wrong object name, insufficient gas, permission denied, Guard validation failure. SDK prompt doesn't match → re-verify R1-R7, correct the issue. `GetObjectExisted()` error → the string reference couldn't be resolved; either create new or correct the name.
198
+
199
+ **Checkpoint**: Persist `{ round: R8, sdk_prompt_received: true, prompt_matches: true }`. Mark R8 COMPLETE.
200
+
201
+ ### R9 — Execute with Submission
202
+
203
+ **AI Goal**: Execute the second phase of the two-phase submission loop. Call the operation WITH `submission` to execute it on-chain.
204
+
205
+ **Key Questions**:
206
+ - Confirm: execute the operation on-chain? This is the final step.
207
+ - (For publish) Reminder: after this, the object is publicly accessible and many fields are immutable.
208
+
209
+ **Tool Calls**:
210
+ 1. `onchain_operations` (or relevant tool) with the same operation AND `submission`.
211
+ 2. SDK executes the transaction on-chain.
212
+ 3. Capture the transaction digest and result.
213
+ 4. `query_toolkit` → `onchain_objects` to verify the result (new object created, balance updated, state changed).
214
+ 5. `local_info_operation` → persist the transaction digest and result.
215
+
216
+ **Success Criteria**: Transaction executed on-chain. Digest captured. Result verified via query.
217
+
218
+ **Fallback**: Transaction fails → check the error: Guard validation failure (review Guard logic and submitted data), insufficient gas (add more), permission denied (check Permission indices), object not found (verify name/ID with `no_cache: true`). Transaction succeeds but result is unexpected → query with `no_cache: true` to bypass cache lag.
219
+
220
+ **Checkpoint**: Persist `{ round: R9, tx_digest, result: success|failure, verified: true }`. Mark R9 COMPLETE.
221
+
222
+ ### R10 — Post-Operation Verification & Handoff
223
+
224
+ **AI Goal**: Verify the operation's outcome. Confirm the on-chain state matches expectations. Hand off to the next workflow with a clean state.
225
+
226
+ **Key Questions**:
227
+ - The operation is complete. Would you like to verify the result?
228
+ - What's your next operation? (hand off to the appropriate Skill)
229
+
230
+ **Tool Calls**:
231
+ 1. `query_toolkit` → `onchain_objects` with `no_cache: true` for the affected objects.
232
+ 2. `onchain_events` → check for relevant events (NewOrderEvent, ProgressEvent, ArbEvent, etc.).
233
+ 3. Confirm the state change matches expectations.
234
+ 4. `local_info_operation` → write the final verification and handoff packet.
235
+ 5. Recommend next Skills based on the operation type:
236
+ - After `service.buy` → [wowok-order](../wowok-order/SKILL.md) for order operations.
237
+ - After `service.publish` → [wowok-provider](../wowok-provider/SKILL.md) for merchant operations.
238
+ - After `arbitration.create` → [wowok-arbitrator](../wowok-arbitrator/SKILL.md) for case management.
239
+ - After `guard.create` → [wowok-guard](../wowok-guard/SKILL.md) for binding.
240
+ - After `machine.create` → [wowok-machine](../wowok-machine/SKILL.md) for publish.
241
+
242
+ **Success Criteria**: On-chain state verified. Events checked. Handoff packet written. Next Skill recommended.
243
+
244
+ **Fallback**: State doesn't match expectations → check with `no_cache: true` (cache lag). If still wrong → diagnose: transaction may have partially failed, or a Guard blocked a sub-operation. User wants to undo → for most operations, impossible (immutable); for some, a reverse operation exists (e.g., `transfer_to` for ownership).
245
+
246
+ **Checkpoint**: Persist `{ round: R10, state_verified: true, events_checked: true, handoff_emitted: true, next_skill: <recommended> }`. Mark safety verification COMPLETE.
247
+
248
+ ---
249
+
250
+ ## Decision Trees
251
+
252
+ ### D1: Object Reuse vs Create
253
+
254
+ ```
255
+ For each object involved in the operation:
256
+ ├── Does an equivalent object already exist?
257
+ │ ├── YES (user provides name/ID)
258
+ │ │ ├── Verify via query_toolkit → onchain_objects
259
+ │ │ │ ├── Exists and owned by account → REUSE (string reference)
260
+ │ │ │ ├── Exists but owned by another → Cannot reuse. CREATE new.
261
+ │ │ │ └── Does not exist → Name typo or never created. CREATE new.
262
+ │ │ └── Object type matters:
263
+ │ │ ├── Permission → STRONGLY recommend reuse (centralized control)
264
+ │ │ ├── Arbitration → ALWAYS reuse (established arbiters)
265
+ │ │ ├── Machine → Reuse if workflow fits
266
+ │ │ ├── Guard → Reuse if logic matches
267
+ │ │ └── Contact → Reuse if same customer service point
268
+ │ └── NO (no equivalent exists)
269
+ │ └── CREATE new (object shape { name?, ... })
270
+ ├── SDK enforcement:
271
+ │ ├── String "<name>" or "<0x...>" → GetObjectExisted() resolves
272
+ │ │ ├── Resolution succeeds → REUSE
273
+ │ │ └── Resolution fails → Hard error. Fix name or switch to CREATE.
274
+ │ └── Object { name?, ... } → Always creates new
275
+ └── replaceExistName flag (for name collisions):
276
+ ├── false (default) → Throws error if name in use (safe)
277
+ └── true → Steals name from existing object (development only)
278
+ ```
279
+
280
+ ### D2: Confirmation Level Required
281
+
282
+ ```
283
+ What level of confirmation does this operation need?
284
+ ├── Operation type:
285
+ │ ├── QUERY (read-only) → No confirmation needed
286
+ │ ├── LOCAL (account_operation, local_mark, local_info) → No confirmation needed
287
+ │ ├── ON-CHAIN write (modify, create) → Standard confirmation (R7 template)
288
+ │ ├── Amount-sensitive (transfer, payment, reward) → AMOUNT VERIFICATION required
289
+ │ │ ├── Query token decimals (never assume)
290
+ │ │ ├── Convert to U64 integer
291
+ │ │ ├── Display both human-readable and U64
292
+ │ │ └── Explicit user confirmation
293
+ │ ├── Publish (Service, Machine) → PUBLISH CONFIRMATION required
294
+ │ │ ├── Export and review (guard2file, machineNode2file)
295
+ │ │ ├── Warn about immutability
296
+ │ │ └── Explicit user confirmation
297
+ │ └── Irreversible (arbitration verdict, transfer) → DOUBLE CONFIRMATION
298
+ │ ├── First: standard R7 template
299
+ │ └── Second: "Are you absolutely sure? This cannot be undone."
300
+ ├── Amount threshold (user-configurable):
301
+ │ ├── Small (< 1 WOW) → Standard confirmation
302
+ │ ├── Medium (1-100 WOW) → Standard + amount display
303
+ │ └── Large (> 100 WOW) → Explicit verbal confirmation + amount display
304
+ └── Network:
305
+ ├── testnet → Standard confirmation (low risk)
306
+ └── mainnet → Heightened confirmation (real funds)
307
+ ```
308
+
309
+ ### D3: LOCAL vs ON-CHAIN vs QUERY
310
+
311
+ ```
312
+ Classifying the operation:
313
+ ├── LOCAL ONLY (no gas, no confirmation)
314
+ │ ├── account_operation (gen, get, faucet, messenger, etc.)
315
+ │ ├── local_mark_operation
316
+ │ └── local_info_operation
317
+ ├── ON-CHAIN (gas required, confirmation required)
318
+ │ ├── onchain_operations (all 16 operation_types)
319
+ │ ├── messenger_operation (some ops — sign, proof_message)
320
+ │ └── wip_file (sign)
321
+ ├── QUERY (read-only, no gas, no confirmation)
322
+ │ ├── query_toolkit
323
+ │ ├── onchain_table_data
324
+ │ ├── onchain_events
325
+ │ ├── guard2file
326
+ │ ├── machineNode2file
327
+ │ └── wowok_buildin_info
328
+ └── ENCRYPTED (local encryption, no gas)
329
+ └── messenger_operation (watch/send messages — local ops)
330
+ ```
331
+
332
+ ### D4: Publish Readiness Check
333
+
334
+ ```
335
+ Before publishing a Service or Machine:
336
+ ├── Have all Guards been created and tested?
337
+ │ ├── YES → continue
338
+ │ └── NO → STOP. Create and test Guards first (gen_passport).
339
+ ├── Has the Machine been created and nodes exported?
340
+ │ ├── YES → machineNode2file export reviewed
341
+ │ └── NO → STOP. Create Machine first.
342
+ ├── Has the Permission object been configured with required indices?
343
+ │ ├── YES → continue
344
+ │ └── NO → STOP. Machine forwards reference Permission indices.
345
+ ├── Have all mutable fields been finalized?
346
+ │ ├── YES → continue
347
+ │ └── NO → STOP. After publish, many fields are immutable.
348
+ ├── Has the Contact (um) been configured?
349
+ │ ├── YES → continue
350
+ │ └── NO → STOP. Customers need a contact channel.
351
+ ├── Has the compensation_fund been funded (for Services)?
352
+ │ ├── YES → continue
353
+ │ └── NO → Warn. Fund may be insufficient for arbitration awards.
354
+ ├── Are you on the correct network?
355
+ │ ├── testnet → OK for testing
356
+ │ └── mainnet → DOUBLE CHECK. Real users, real funds.
357
+ └── All checks pass → Proceed with publish confirmation (R7).
358
+ ```
359
+
360
+ ### D5: Error Recovery Path
361
+
362
+ ```
363
+ An operation failed. What's the error?
364
+ ├── Guard validation failure
365
+ │ ├── Review Guard's rule tree via guard2file
366
+ │ ├── Check submitted data values
367
+ │ ├── Re-submit with corrected data
368
+ │ └── If Guard logic is wrong → create replacement Guard (immutable)
369
+ ├── Cache stale reads
370
+ │ ├── Retry with env.no_cache: true
371
+ │ ├── If still fails → wait, then retry
372
+ │ └── For sequential operations → always set no_cache: true
373
+ ├── Permission denied
374
+ │ ├── Check the object's Permission configuration
375
+ │ ├── Verify account has required indices
376
+ │ └── Request permission holder to grant access
377
+ ├── Object not found
378
+ │ ├── Verify name/ID spelling
379
+ │ ├── Check env.network matches
380
+ │ ├── Retry with no_cache: true
381
+ │ └── If truly doesn't exist → create new or correct reference
382
+ ├── Insufficient gas
383
+ │ ├── Add more gas to the account
384
+ │ ├── Faucet on testnet (account_operation → faucet)
385
+ │ └── Retry the operation
386
+ ├── File parsing failure
387
+ │ ├── Check machineNode2file / guard2file output format
388
+ │ ├── Verify schema compliance
389
+ │ └── Regenerate the export
390
+ └── GetObjectExisted() error
391
+ ├── String reference couldn't be resolved
392
+ ├── Check name spelling
393
+ ├── Check if object exists via query_toolkit
394
+ └── Switch to CREATE (object shape) if object doesn't exist
395
+ ```
396
+
397
+ ---
398
+
399
+ ## Failure Playbooks
400
+
401
+ ### F1: Cache Stale Reads
402
+
403
+ **Trigger**: Sequential operations fail unexpectedly. For example, "object not found" when the object was just created in the previous step.
404
+
405
+ **Diagnosis**:
406
+ - WoWok's caching layer hasn't propagated the latest state.
407
+ - The previous operation succeeded, but the cache still returns the old state.
408
+ - Common in rapid sequential operations (create object → reference object in next call).
409
+
410
+ **Recovery**:
411
+ 1. Retry the failing operation with `env.no_cache: true`.
412
+ 2. If the retry succeeds → cache lag confirmed. Always use `no_cache: true` for sequential operations.
413
+ 3. If the retry still fails → the object truly doesn't exist or the operation has a different error.
414
+ 4. For ongoing sequential operations: set `no_cache: true` on ALL operations in the chain.
415
+
416
+ **Prevention**: When building multiple interdependent objects, set `env.no_cache: true` on all operations. This is listed in §Common Mistakes as "Forgetting no_cache."
417
+
418
+ ### F2: Missing Permission Indices
419
+
420
+ **Trigger**: A Machine forward references a Permission index that doesn't exist. The operation fails with "permission denied" or "index out of bounds."
421
+
422
+ **Diagnosis**:
423
+ - The Machine's forward specifies a `namedOperator` index that the Permission object doesn't have.
424
+ - The Permission object was created with fewer indices than the Machine requires.
425
+ - The Machine was designed before the Permission object was fully configured.
426
+
427
+ **Recovery**:
428
+ 1. `machineNode2file` to export the Machine and identify all `namedOperator` indices.
429
+ 2. `query_toolkit` → `onchain_objects` for the Permission object. Check available indices.
430
+ 3. If the Permission object is mutable → add the missing indices.
431
+ 4. If the Permission object is immutable → create a new Permission with the required indices, then update the Machine (if mutable) or create a new Machine.
432
+ 5. If the Machine is already published → cannot modify. Must create a new Machine with correct references.
433
+
434
+ **Prevention**: Before creating a Machine, verify the Permission object has all required indices. This is listed in §Common Mistakes as "Missing permission indices." Design the Permission object first, then the Machine.
435
+
436
+ ### F3: Token Decimals Assumption
437
+
438
+ **Trigger**: An amount-sensitive operation fails or produces unexpected results because the token's decimals were assumed rather than queried.
439
+
440
+ **Diagnosis**:
441
+ - The AI assumed WOW has 9 decimals (correct, but should still query).
442
+ - The AI assumed a custom token has the same decimals as WOW (wrong).
443
+ - The amount was submitted as a human-readable string ("2 WOW") instead of a U64 integer (`2000000000`).
444
+ - The token's decimals couldn't be queried, and the AI guessed (wrong).
445
+
446
+ **Recovery**:
447
+ 1. `query_toolkit` → `token_list` to get the correct `decimals` and `symbol`.
448
+ 2. Recalculate: `u64_amount = human_amount × (10 ^ decimals)`.
449
+ 3. Re-submit the operation with the correct U64 integer.
450
+ 4. If the token's decimals cannot be queried → HALT. Alert the user. Do not proceed with guessed precision.
451
+
452
+ **Prevention**: NEVER assume token decimals. ALWAYS query via `query_toolkit` with `query_type: "token_list"` before any amount-sensitive operation. This is documented in §2.2 Amount Verification and §5.1 Multi-Token Support.
453
+
454
+ ### F4: Name Collision (replaceExistName)
455
+
456
+ **Trigger**: An operation fails because an object with the same name already exists. Or, `replaceExistName: true` was used accidentally, stealing the name from an existing object.
457
+
458
+ **Diagnosis**:
459
+ - `replaceExistName: false` (default) → throws error if name is in use.
460
+ - `replaceExistName: true` → steals the name; the old object becomes unnamed (potentially orphaned).
461
+ - The user didn't realize the name was already in use.
462
+ - The user used `replaceExistName: true` in production (should be development only).
463
+
464
+ **Recovery**:
465
+ 1. If `replaceExistName: false` and name collision → either:
466
+ - Choose a different name (e.g., append `_v2`).
467
+ - Use `replaceExistName: true` intentionally if the old object is obsolete.
468
+ 2. If `replaceExistName: true` was used accidentally → the old object is now unnamed. Query by ID to find it. Re-name it or accept the orphaned state.
469
+ 3. For production systems → use versioned names (`_v1`, `_v2`) instead of `replaceExistName`.
470
+
471
+ **Prevention**: Default to `replaceExistName: false` in production. Use versioned names for iterations. Only use `replaceExistName: true` during development with fixed test names. This is documented in §4.1 replaceExistName Flag.
472
+
473
+ ### F5: Guard Validation Failure
474
+
475
+ **Trigger**: An operation with `submission` fails because the Guard logic evaluated to false. The Guard rejected the submitted data.
476
+
477
+ **Diagnosis**:
478
+ - The Guard's rule tree was satisfied by the conditions, but the submitted data didn't meet the requirements.
479
+ - The Guard logic itself may be correct, but the data values are wrong.
480
+ - The Guard logic may be wrong (designed incorrectly), but since Guards are immutable, it cannot be patched.
481
+
482
+ **Recovery**:
483
+ 1. `guard2file` to export and review the Guard's rule tree.
484
+ 2. Compare the submitted data values against the Guard's requirements.
485
+ 3. If the data is wrong → correct the data and re-submit.
486
+ 4. If the Guard logic is wrong → create a replacement Guard with corrected logic. Update the host object (if mutable) to reference the new Guard.
487
+ 5. If the host object is immutable → cannot update the Guard reference. Must create a new host object.
488
+
489
+ **Prevention**: Test Guards with `gen_passport` before binding them to objects. Review the Guard's rule tree via `guard2file` before finalizing. This is documented in §7 Error Patterns.
490
+
491
+ ### F6: Immutable Field Modification Attempt
492
+
493
+ **Trigger**: The user tries to modify a field that became immutable after publish (e.g., Service machine, Service order_allocators, Guard rules, Machine node topology).
494
+
495
+ **Diagnosis**:
496
+ - After a Service is published, `machine` and `order_allocators` are locked.
497
+ - After a Guard is created, all rules are locked.
498
+ - After a Machine is published, node topology and forwards are locked.
499
+ - The operation fails with an error indicating the field cannot be modified.
500
+
501
+ **Recovery**:
502
+ 1. Identify which field is immutable.
503
+ 2. If the field is on a Service:
504
+ - `machine` and `order_allocators` → immutable after publish. Must create a new Service.
505
+ - `description`, `location`, `sales`, `customer_required`, `um` → mutable. Can modify.
506
+ 3. If the field is on a Guard → all rules immutable. Must create a replacement Guard.
507
+ 4. If the field is on a Machine → node topology and forwards immutable after publish. Must create a new Machine.
508
+ 5. Communicate to the user: the only path is creating a new object (Service, Guard, or Machine) with the desired configuration.
509
+
510
+ **Prevention**: Before publishing, thoroughly test and review all configurations. Use the Export & Review step (R6) to verify. Warn about immutability in the confirmation template (R7). This is documented in §2.3 Publish Confirmation.
511
+
512
+ ---
513
+
514
+ ## Tier Layering
515
+
516
+ ### Novice — Always Confirm, Always Query First
517
+
518
+ **Profile**: First-time user. Unfamiliar with WoWok safety rules. Needs explicit confirmation for every operation.
519
+
520
+ **AI Behavior**:
521
+ - Always run the full R1-R10 safety dialogue for ON-CHAIN operations.
522
+ - Always query token decimals before amount-sensitive operations (never assume).
523
+ - Always use the confirmation template (R7) with full operation preview.
524
+ - Always set `env.no_cache: true` for sequential operations.
525
+ - Always verify object existence before referencing (R3).
526
+ - For publish operations: always export and review (R6) before confirming.
527
+ - Default to conservative: if any check is uncertain, STOP and ask the user.
528
+
529
+ **Typical Journey**: R1 (intent) → R2 (account) → R3 (reuse/create) → R4 (permission) → R5 (amount) → R6 (export if publish) → R7 (confirmation) → R8 (call without submission) → R9 (execute) → R10 (verify).
530
+
531
+ ### Advanced — Batch Operations, Incremental Building
532
+
533
+ **Profile**: Experienced user. Understands WoWok safety rules. Wants efficient operations without redundant checks.
534
+
535
+ **AI Behavior**:
536
+ - Batch related operations: verify all objects in R3 before proceeding.
537
+ - For incremental object building: allow step-by-step creation with verification at each step, but don't re-run the full R1-R10 for each step.
538
+ - For amount-sensitive operations: query token decimals once, cache for the session.
539
+ - For sequential operations: set `no_cache: true` globally for the session.
540
+ - For publish operations: export and review, but allow the user to skip detailed review if they've tested independently.
541
+ - Use `replaceExistName` strategically during development (with user awareness).
542
+ - Support multi-account operations: verify permissions for each account independently.
543
+
544
+ **Typical Journey**: R1 (intent, batch) → R2 (account, batch) → R3 (reuse/create, batch) → R4 (permission, batch) → R5 (amount, cached) → R6 (export if publish) → R7 (confirmation, batch) → R8-R9 (execute, batch) → R10 (verify, batch).
545
+
546
+ ### Expert — Complex Multi-Object Systems, Circular References
547
+
548
+ **Profile**: Power user. Builds complex systems with circular references (CREATE object → CREATE Guard → MODIFY object). Needs advanced safety patterns.
549
+
550
+ **AI Behavior**:
551
+ - Support circular reference patterns: CREATE object (without Guard binding) → CREATE Guard (references object by name) → MODIFY object (binds Guard).
552
+ - Manage dependency chains: track which objects depend on which, execute in the correct order.
553
+ - For multi-object systems: create a dependency graph, execute in topological order.
554
+ - Support `replaceExistName` for iterative development with fixed names.
555
+ - Support multi-network operations: testnet for development, mainnet for production, with explicit network switching.
556
+ - For publish operations: comprehensive readiness check (D4) before proceeding.
557
+ - Support custom confirmation thresholds: user-configurable amount thresholds for heightened confirmation.
558
+ - Track immutability constraints across the system: warn when a modification would require creating replacement objects.
559
+ - Support rollback planning: before irreversible operations, document the recovery path (e.g., "if this publish fails, create a new Service with corrected config").
560
+
561
+ **Typical Journey**: R1 (intent, system-level) → R2 (account, multi-account) → R3 (reuse/create, dependency graph) → R4 (permission, multi-account) → R5 (amount, multi-token) → R6 (export, full system review) → R7 (confirmation, system-level) → R8-R9 (execute, dependency-ordered) → R10 (verify, system-level handoff).