@audiofool/moondog 0.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.
Files changed (109) hide show
  1. package/README.md +125 -0
  2. package/assets/brand/moondog-lunar-record/moondog-logo-1x1.png +0 -0
  3. package/contracts/v1/capability-policy.schema.json +572 -0
  4. package/contracts/v1/definitions.schema.json +365 -0
  5. package/contracts/v1/library-track-observation.schema.json +138 -0
  6. package/contracts/v1/listening-event.schema.json +111 -0
  7. package/contracts/v1/profile-evidence.schema.json +237 -0
  8. package/contracts/v1/taste-event.schema.json +258 -0
  9. package/contracts/v1/tool-invocation.schema.json +318 -0
  10. package/contracts/v1/tool-receipt.schema.json +1066 -0
  11. package/contracts/v1/track-ref.schema.json +275 -0
  12. package/contracts/v2/profile-evidence.schema.json +284 -0
  13. package/package.json +105 -0
  14. package/scripts/contract-lib.mjs +361 -0
  15. package/scripts/contract-semantics.mjs +2630 -0
  16. package/scripts/demo-studio.mjs +58 -0
  17. package/scripts/moondog +52 -0
  18. package/scripts/moondog.mjs +954 -0
  19. package/src/core/apple-data-migration.mjs +50 -0
  20. package/src/core/apple-library-source-status.mjs +220 -0
  21. package/src/core/apple-projection-domain-services.mjs +2356 -0
  22. package/src/core/capability-catalog.mjs +577 -0
  23. package/src/core/listening-profile-domain-services.mjs +1010 -0
  24. package/src/core/lyric-library.mjs +121 -0
  25. package/src/core/lyric-profile.mjs +50 -0
  26. package/src/core/lyric-service.mjs +41 -0
  27. package/src/core/moondog-application.mjs +1827 -0
  28. package/src/core/state-directory.mjs +19 -0
  29. package/src/core/synthetic-domain-services.mjs +1485 -0
  30. package/src/core/uuid-v5.mjs +42 -0
  31. package/src/demo/fictional-spotify-history.mjs +400 -0
  32. package/src/demo/moondog-demo.mjs +355 -0
  33. package/src/demo/moondog-interactive-tasteprint-demo.mjs +293 -0
  34. package/src/demo/moondog-tasteprint-demo.mjs +631 -0
  35. package/src/importers/apple-music-library/import-batch.mjs +290 -0
  36. package/src/importers/apple-music-library/index.mjs +76 -0
  37. package/src/importers/apple-music-library/normalize.mjs +1126 -0
  38. package/src/importers/apple-music-library/parse-plist.mjs +357 -0
  39. package/src/importers/apple-music-library/projection-records.mjs +557 -0
  40. package/src/importers/apple-music-library/read-batch.mjs +276 -0
  41. package/src/importers/apple-music-library/sqlite-projection.mjs +1307 -0
  42. package/src/importers/apple-music-library/stable-ids.mjs +19 -0
  43. package/src/importers/apple-music-library/track-snapshot.schema.json +136 -0
  44. package/src/integrations/apple-music/catalog.mjs +770 -0
  45. package/src/integrations/cross-catalog-artist-identity.mjs +222 -0
  46. package/src/integrations/listenbrainz/history-file.mjs +560 -0
  47. package/src/integrations/lyrics/lrclib.mjs +55 -0
  48. package/src/integrations/open-music-similarity/artist-radio.mjs +806 -0
  49. package/src/integrations/public-playlists.mjs +104 -0
  50. package/src/integrations/spotify/account-data-history.mjs +545 -0
  51. package/src/integrations/spotify/account-data-profile.mjs +918 -0
  52. package/src/integrations/spotify/authentication.mjs +791 -0
  53. package/src/integrations/spotify/catalog-resolver.mjs +657 -0
  54. package/src/integrations/spotify/connection.mjs +125 -0
  55. package/src/integrations/spotify/credential-store.mjs +26 -0
  56. package/src/integrations/spotify/extended-streaming-history.mjs +525 -0
  57. package/src/integrations/spotify/history-archive.mjs +59 -0
  58. package/src/integrations/spotify/index.mjs +80 -0
  59. package/src/integrations/spotify/recent-activity.mjs +198 -0
  60. package/src/integrations/spotify/resolution-cache.mjs +260 -0
  61. package/src/integrations/spotify/service.mjs +713 -0
  62. package/src/integrations/spotify/settings.mjs +89 -0
  63. package/src/integrations/spotify/web-api-client.mjs +761 -0
  64. package/src/integrations/web/codex-web.mjs +263 -0
  65. package/src/integrations/youtube-music/takeout.mjs +143 -0
  66. package/src/memory/local-memory-store.mjs +1705 -0
  67. package/src/memory/reflection-worker.mjs +87 -0
  68. package/src/profile/apple-library-import.mjs +28 -0
  69. package/src/profile/history-import.mjs +163 -0
  70. package/src/profile/listener-corrections.mjs +217 -0
  71. package/src/profile/listening-history-store.mjs +2055 -0
  72. package/src/profile/listening-profile-projection.mjs +2520 -0
  73. package/src/profile/local-music-data.mjs +812 -0
  74. package/src/profile/music-import-bundle.mjs +91 -0
  75. package/src/profile/music-providers.mjs +25 -0
  76. package/src/profile/spotify-archive-catalog-hints.mjs +210 -0
  77. package/src/profile/spotify-archive-taste.mjs +482 -0
  78. package/src/runtime/pi/agent-runtime.mjs +6444 -0
  79. package/src/runtime/pi/authentication.mjs +104 -0
  80. package/src/runtime/pi/configured-runtime.mjs +98 -0
  81. package/src/runtime/pi/memory-agent-runtime.mjs +337 -0
  82. package/src/runtime/pi/model-catalog.mjs +62 -0
  83. package/src/runtime/pi/model-transport.mjs +117 -0
  84. package/src/runtime/pi/persistent-credential-store.mjs +670 -0
  85. package/src/runtime/pi/provider-registry.mjs +74 -0
  86. package/src/runtime/pi/runtime-settings.mjs +81 -0
  87. package/src/surfaces/cli/auth-command.mjs +355 -0
  88. package/src/surfaces/cli/brand-components.mjs +390 -0
  89. package/src/surfaces/cli/brand-theme.mjs +231 -0
  90. package/src/surfaces/cli/catalog-command.mjs +509 -0
  91. package/src/surfaces/cli/command-completions.mjs +113 -0
  92. package/src/surfaces/cli/data-command.mjs +214 -0
  93. package/src/surfaces/cli/format-output.mjs +750 -0
  94. package/src/surfaces/cli/history-import-view.mjs +445 -0
  95. package/src/surfaces/cli/import-guides.mjs +9 -0
  96. package/src/surfaces/cli/listenbrainz-command.mjs +129 -0
  97. package/src/surfaces/cli/listening-menu.mjs +171 -0
  98. package/src/surfaces/cli/profile-command.mjs +290 -0
  99. package/src/surfaces/cli/spotify-command.mjs +849 -0
  100. package/src/surfaces/cli/taste-profile-model.mjs +306 -0
  101. package/src/surfaces/cli/taste-profile-view.mjs +272 -0
  102. package/src/surfaces/cli/terminal-art.mjs +295 -0
  103. package/src/surfaces/cli/tui.mjs +1714 -0
  104. package/src/surfaces/cli/web-command.mjs +52 -0
  105. package/src/surfaces/html/tasteprint-artifact.mjs +96 -0
  106. package/src/surfaces/html/tasteprint.mjs +3575 -0
  107. package/src/surfaces/web/showcase.mjs +272 -0
  108. package/src/surfaces/web/studio-page.mjs +4148 -0
  109. package/src/surfaces/web/studio.mjs +2288 -0
@@ -0,0 +1,1066 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:moondog:contract:tool-receipt:1",
4
+ "title": "Moondog ToolReceipt v1",
5
+ "type": "object",
6
+ "properties": {
7
+ "schema_version": {
8
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/schema_version"
9
+ },
10
+ "receipt_id": {
11
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
12
+ },
13
+ "invocation_id": {
14
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
15
+ },
16
+ "subject_id": {
17
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
18
+ },
19
+ "capability_id": {
20
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/namespaced_key"
21
+ },
22
+ "capability_version": {
23
+ "type": "integer",
24
+ "minimum": 1
25
+ },
26
+ "invocation_semantic_digest": {
27
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/sha256"
28
+ },
29
+ "attempt": {
30
+ "type": "integer",
31
+ "minimum": 1
32
+ },
33
+ "status": {
34
+ "enum": [
35
+ "simulated",
36
+ "denied",
37
+ "awaiting_confirmation",
38
+ "accepted",
39
+ "succeeded",
40
+ "failed",
41
+ "timed_out",
42
+ "partial",
43
+ "unknown",
44
+ "cancelled",
45
+ "requires_human"
46
+ ]
47
+ },
48
+ "recorded_at": {
49
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
50
+ },
51
+ "started_at": {
52
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
53
+ },
54
+ "finished_at": {
55
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
56
+ },
57
+ "policy_decision": {
58
+ "type": "object",
59
+ "properties": {
60
+ "decision": {
61
+ "enum": [
62
+ "allow",
63
+ "deny",
64
+ "require_confirmation",
65
+ "escalate"
66
+ ]
67
+ },
68
+ "policy_ref": {
69
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/policy_ref"
70
+ },
71
+ "capability_registry_version": {
72
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/non_empty_string"
73
+ },
74
+ "reason_codes": {
75
+ "type": "array",
76
+ "minItems": 1,
77
+ "items": {
78
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/namespaced_key"
79
+ },
80
+ "uniqueItems": true
81
+ }
82
+ },
83
+ "required": [
84
+ "decision",
85
+ "policy_ref",
86
+ "capability_registry_version",
87
+ "reason_codes"
88
+ ],
89
+ "additionalProperties": false
90
+ },
91
+ "confirmation": {
92
+ "type": "object",
93
+ "properties": {
94
+ "grant_id": {
95
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
96
+ },
97
+ "verified_at": {
98
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
99
+ },
100
+ "consumed_at": {
101
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
102
+ },
103
+ "scope_digest": {
104
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/sha256"
105
+ }
106
+ },
107
+ "required": [
108
+ "grant_id",
109
+ "verified_at",
110
+ "scope_digest"
111
+ ],
112
+ "additionalProperties": false
113
+ },
114
+ "idempotency": {
115
+ "type": "object",
116
+ "properties": {
117
+ "key_digest": {
118
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/sha256"
119
+ },
120
+ "semantic_digest": {
121
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/sha256"
122
+ },
123
+ "disposition": {
124
+ "enum": [
125
+ "new",
126
+ "replayed",
127
+ "conflict"
128
+ ]
129
+ }
130
+ },
131
+ "required": [
132
+ "key_digest",
133
+ "semantic_digest",
134
+ "disposition"
135
+ ],
136
+ "additionalProperties": false
137
+ },
138
+ "executor_ref": {
139
+ "type": "object",
140
+ "properties": {
141
+ "executor_id": {
142
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/namespaced_key"
143
+ },
144
+ "version": {
145
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/non_empty_string"
146
+ },
147
+ "external_refs": {
148
+ "type": "array",
149
+ "items": {
150
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/external_ref"
151
+ },
152
+ "uniqueItems": true
153
+ }
154
+ },
155
+ "required": [
156
+ "executor_id",
157
+ "version"
158
+ ],
159
+ "additionalProperties": false
160
+ },
161
+ "effects": {
162
+ "type": "array",
163
+ "items": {
164
+ "type": "object",
165
+ "properties": {
166
+ "effect_type": {
167
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/effect_kind"
168
+ },
169
+ "resource_ref": {
170
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/entity_ref"
171
+ },
172
+ "status": {
173
+ "enum": [
174
+ "planned",
175
+ "applied",
176
+ "rolled_back",
177
+ "unknown"
178
+ ]
179
+ },
180
+ "reversible": {
181
+ "type": "boolean"
182
+ }
183
+ },
184
+ "required": [
185
+ "effect_type",
186
+ "status",
187
+ "reversible"
188
+ ],
189
+ "additionalProperties": false
190
+ }
191
+ },
192
+ "usage": {
193
+ "type": "array",
194
+ "items": {
195
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/budget_amount"
196
+ },
197
+ "uniqueItems": true
198
+ },
199
+ "budget_reservation": {
200
+ "type": "object",
201
+ "properties": {
202
+ "reservation_id": {
203
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
204
+ },
205
+ "state": {
206
+ "enum": [
207
+ "none",
208
+ "reserved",
209
+ "held",
210
+ "reconciled",
211
+ "released"
212
+ ]
213
+ },
214
+ "reserved": {
215
+ "type": "array",
216
+ "items": {
217
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/budget_amount"
218
+ },
219
+ "uniqueItems": true
220
+ },
221
+ "actual": {
222
+ "type": "array",
223
+ "items": {
224
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/budget_amount"
225
+ },
226
+ "uniqueItems": true
227
+ },
228
+ "recorded_at": {
229
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
230
+ },
231
+ "reconciled_at": {
232
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
233
+ }
234
+ },
235
+ "required": [
236
+ "state",
237
+ "reserved",
238
+ "actual",
239
+ "recorded_at"
240
+ ],
241
+ "allOf": [
242
+ {
243
+ "if": {
244
+ "properties": {
245
+ "state": {
246
+ "const": "none"
247
+ }
248
+ },
249
+ "required": [
250
+ "state"
251
+ ]
252
+ },
253
+ "then": {
254
+ "properties": {
255
+ "reserved": {
256
+ "type": "array",
257
+ "maxItems": 0
258
+ },
259
+ "actual": {
260
+ "type": "array",
261
+ "maxItems": 0
262
+ }
263
+ },
264
+ "not": {
265
+ "anyOf": [
266
+ {
267
+ "required": [
268
+ "reservation_id"
269
+ ]
270
+ },
271
+ {
272
+ "required": [
273
+ "reconciled_at"
274
+ ]
275
+ }
276
+ ]
277
+ }
278
+ },
279
+ "else": {
280
+ "required": [
281
+ "reservation_id"
282
+ ]
283
+ }
284
+ },
285
+ {
286
+ "if": {
287
+ "properties": {
288
+ "state": {
289
+ "enum": [
290
+ "reconciled",
291
+ "released"
292
+ ]
293
+ }
294
+ },
295
+ "required": [
296
+ "state"
297
+ ]
298
+ },
299
+ "then": {
300
+ "required": [
301
+ "reconciled_at"
302
+ ]
303
+ }
304
+ }
305
+ ],
306
+ "additionalProperties": false
307
+ },
308
+ "privacy_egress": {
309
+ "type": "array",
310
+ "items": {
311
+ "type": "object",
312
+ "properties": {
313
+ "data_class": {
314
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/data_class"
315
+ },
316
+ "destination": {
317
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/external_destination"
318
+ },
319
+ "retained_until": {
320
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
321
+ }
322
+ },
323
+ "required": [
324
+ "data_class",
325
+ "destination"
326
+ ],
327
+ "additionalProperties": false
328
+ }
329
+ },
330
+ "artifacts": {
331
+ "type": "array",
332
+ "items": {
333
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/artifact_ref"
334
+ },
335
+ "uniqueItems": true
336
+ },
337
+ "result_summary": {
338
+ "type": "string",
339
+ "minLength": 1,
340
+ "maxLength": 2000,
341
+ "pattern": "\\S"
342
+ },
343
+ "error": {
344
+ "type": "object",
345
+ "properties": {
346
+ "category": {
347
+ "enum": [
348
+ "validation",
349
+ "authorization",
350
+ "policy",
351
+ "timeout",
352
+ "rate_limit",
353
+ "external_service",
354
+ "internal",
355
+ "unknown"
356
+ ]
357
+ },
358
+ "code": {
359
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/namespaced_key"
360
+ },
361
+ "safe_message": {
362
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/non_empty_string"
363
+ },
364
+ "retryable": {
365
+ "type": "boolean"
366
+ }
367
+ },
368
+ "required": [
369
+ "category",
370
+ "code",
371
+ "safe_message",
372
+ "retryable"
373
+ ],
374
+ "additionalProperties": false
375
+ },
376
+ "recovery": {
377
+ "type": "object",
378
+ "properties": {
379
+ "action": {
380
+ "enum": [
381
+ "none",
382
+ "retry",
383
+ "reconcile",
384
+ "rollback",
385
+ "request_confirmation",
386
+ "human_handoff"
387
+ ]
388
+ },
389
+ "safe_summary": {
390
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/non_empty_string"
391
+ }
392
+ },
393
+ "required": [
394
+ "action",
395
+ "safe_summary"
396
+ ],
397
+ "additionalProperties": false
398
+ },
399
+ "deduplicated_from_receipt_id": {
400
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/uuid"
401
+ },
402
+ "extensions": {
403
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/extensions"
404
+ }
405
+ },
406
+ "required": [
407
+ "schema_version",
408
+ "receipt_id",
409
+ "invocation_id",
410
+ "subject_id",
411
+ "capability_id",
412
+ "capability_version",
413
+ "invocation_semantic_digest",
414
+ "attempt",
415
+ "status",
416
+ "recorded_at",
417
+ "policy_decision",
418
+ "effects",
419
+ "usage",
420
+ "budget_reservation",
421
+ "privacy_egress",
422
+ "artifacts"
423
+ ],
424
+ "allOf": [
425
+ {
426
+ "if": {
427
+ "properties": {
428
+ "status": {
429
+ "enum": [
430
+ "failed",
431
+ "timed_out",
432
+ "partial",
433
+ "unknown"
434
+ ]
435
+ }
436
+ },
437
+ "required": [
438
+ "status"
439
+ ]
440
+ },
441
+ "then": {
442
+ "required": [
443
+ "error"
444
+ ]
445
+ }
446
+ },
447
+ {
448
+ "if": {
449
+ "properties": {
450
+ "status": {
451
+ "const": "denied"
452
+ }
453
+ },
454
+ "required": [
455
+ "status"
456
+ ]
457
+ },
458
+ "then": {
459
+ "properties": {
460
+ "policy_decision": {
461
+ "type": "object",
462
+ "properties": {
463
+ "decision": {
464
+ "const": "deny"
465
+ }
466
+ }
467
+ },
468
+ "effects": {
469
+ "type": "array",
470
+ "maxItems": 0
471
+ },
472
+ "usage": {
473
+ "type": "array",
474
+ "maxItems": 0
475
+ },
476
+ "privacy_egress": {
477
+ "type": "array",
478
+ "maxItems": 0
479
+ },
480
+ "artifacts": {
481
+ "type": "array",
482
+ "maxItems": 0
483
+ },
484
+ "budget_reservation": {
485
+ "type": "object",
486
+ "properties": {
487
+ "state": {
488
+ "const": "none"
489
+ }
490
+ }
491
+ }
492
+ },
493
+ "not": {
494
+ "anyOf": [
495
+ {
496
+ "required": [
497
+ "started_at"
498
+ ]
499
+ },
500
+ {
501
+ "required": [
502
+ "executor_ref"
503
+ ]
504
+ },
505
+ {
506
+ "properties": {
507
+ "confirmation": {
508
+ "type": "object",
509
+ "properties": {
510
+ "consumed_at": {
511
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
512
+ }
513
+ },
514
+ "required": [
515
+ "consumed_at"
516
+ ]
517
+ }
518
+ },
519
+ "required": [
520
+ "confirmation"
521
+ ]
522
+ }
523
+ ]
524
+ }
525
+ }
526
+ },
527
+ {
528
+ "if": {
529
+ "properties": {
530
+ "status": {
531
+ "enum": [
532
+ "awaiting_confirmation",
533
+ "requires_human"
534
+ ]
535
+ }
536
+ },
537
+ "required": [
538
+ "status"
539
+ ]
540
+ },
541
+ "then": {
542
+ "properties": {
543
+ "effects": {
544
+ "type": "array",
545
+ "maxItems": 0
546
+ },
547
+ "usage": {
548
+ "type": "array",
549
+ "maxItems": 0
550
+ },
551
+ "privacy_egress": {
552
+ "type": "array",
553
+ "maxItems": 0
554
+ },
555
+ "budget_reservation": {
556
+ "type": "object",
557
+ "properties": {
558
+ "state": {
559
+ "const": "none"
560
+ }
561
+ }
562
+ }
563
+ },
564
+ "not": {
565
+ "anyOf": [
566
+ {
567
+ "required": [
568
+ "started_at"
569
+ ]
570
+ },
571
+ {
572
+ "required": [
573
+ "executor_ref"
574
+ ]
575
+ },
576
+ {
577
+ "required": [
578
+ "idempotency"
579
+ ]
580
+ },
581
+ {
582
+ "properties": {
583
+ "confirmation": {
584
+ "type": "object",
585
+ "properties": {
586
+ "consumed_at": {
587
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
588
+ }
589
+ },
590
+ "required": [
591
+ "consumed_at"
592
+ ]
593
+ }
594
+ },
595
+ "required": [
596
+ "confirmation"
597
+ ]
598
+ }
599
+ ]
600
+ }
601
+ }
602
+ },
603
+ {
604
+ "if": {
605
+ "properties": {
606
+ "status": {
607
+ "const": "denied"
608
+ },
609
+ "idempotency": {
610
+ "type": "object"
611
+ }
612
+ },
613
+ "required": [
614
+ "status",
615
+ "idempotency"
616
+ ]
617
+ },
618
+ "then": {
619
+ "properties": {
620
+ "idempotency": {
621
+ "type": "object",
622
+ "properties": {
623
+ "disposition": {
624
+ "const": "conflict"
625
+ }
626
+ }
627
+ }
628
+ }
629
+ }
630
+ },
631
+ {
632
+ "if": {
633
+ "properties": {
634
+ "status": {
635
+ "const": "awaiting_confirmation"
636
+ }
637
+ },
638
+ "required": [
639
+ "status"
640
+ ]
641
+ },
642
+ "then": {
643
+ "required": [
644
+ "recovery"
645
+ ],
646
+ "properties": {
647
+ "policy_decision": {
648
+ "type": "object",
649
+ "properties": {
650
+ "decision": {
651
+ "const": "require_confirmation"
652
+ }
653
+ }
654
+ },
655
+ "recovery": {
656
+ "type": "object",
657
+ "properties": {
658
+ "action": {
659
+ "const": "request_confirmation"
660
+ }
661
+ }
662
+ }
663
+ }
664
+ }
665
+ },
666
+ {
667
+ "if": {
668
+ "properties": {
669
+ "status": {
670
+ "const": "requires_human"
671
+ }
672
+ },
673
+ "required": [
674
+ "status"
675
+ ]
676
+ },
677
+ "then": {
678
+ "required": [
679
+ "recovery"
680
+ ],
681
+ "properties": {
682
+ "policy_decision": {
683
+ "type": "object",
684
+ "properties": {
685
+ "decision": {
686
+ "const": "escalate"
687
+ }
688
+ }
689
+ },
690
+ "recovery": {
691
+ "type": "object",
692
+ "properties": {
693
+ "action": {
694
+ "const": "human_handoff"
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+ },
701
+ {
702
+ "if": {
703
+ "properties": {
704
+ "status": {
705
+ "enum": [
706
+ "accepted",
707
+ "succeeded",
708
+ "failed",
709
+ "timed_out",
710
+ "partial",
711
+ "unknown"
712
+ ]
713
+ },
714
+ "confirmation": {
715
+ "type": "object"
716
+ }
717
+ },
718
+ "required": [
719
+ "status",
720
+ "confirmation"
721
+ ]
722
+ },
723
+ "then": {
724
+ "properties": {
725
+ "confirmation": {
726
+ "type": "object",
727
+ "properties": {
728
+ "consumed_at": {
729
+ "$ref": "urn:moondog:contract:definitions:1#/$defs/utc_timestamp"
730
+ }
731
+ },
732
+ "required": [
733
+ "consumed_at"
734
+ ]
735
+ }
736
+ }
737
+ }
738
+ },
739
+ {
740
+ "if": {
741
+ "properties": {
742
+ "idempotency": {
743
+ "type": "object",
744
+ "properties": {
745
+ "disposition": {
746
+ "const": "conflict"
747
+ }
748
+ },
749
+ "required": [
750
+ "disposition"
751
+ ]
752
+ }
753
+ },
754
+ "required": [
755
+ "idempotency"
756
+ ]
757
+ },
758
+ "then": {
759
+ "properties": {
760
+ "status": {
761
+ "const": "denied"
762
+ }
763
+ }
764
+ }
765
+ },
766
+ {
767
+ "if": {
768
+ "properties": {
769
+ "status": {
770
+ "const": "simulated"
771
+ }
772
+ },
773
+ "required": [
774
+ "status"
775
+ ]
776
+ },
777
+ "then": {
778
+ "properties": {
779
+ "effects": {
780
+ "type": "array",
781
+ "items": {
782
+ "type": "object",
783
+ "properties": {
784
+ "status": {
785
+ "const": "planned"
786
+ }
787
+ }
788
+ }
789
+ },
790
+ "usage": {
791
+ "type": "array",
792
+ "maxItems": 0
793
+ },
794
+ "privacy_egress": {
795
+ "type": "array",
796
+ "maxItems": 0
797
+ },
798
+ "budget_reservation": {
799
+ "type": "object",
800
+ "properties": {
801
+ "state": {
802
+ "const": "none"
803
+ }
804
+ }
805
+ }
806
+ },
807
+ "not": {
808
+ "required": [
809
+ "executor_ref"
810
+ ]
811
+ }
812
+ }
813
+ },
814
+ {
815
+ "if": {
816
+ "properties": {
817
+ "status": {
818
+ "const": "accepted"
819
+ }
820
+ },
821
+ "required": [
822
+ "status"
823
+ ]
824
+ },
825
+ "then": {
826
+ "properties": {
827
+ "effects": {
828
+ "type": "array",
829
+ "items": {
830
+ "type": "object",
831
+ "properties": {
832
+ "status": {
833
+ "const": "planned"
834
+ }
835
+ }
836
+ }
837
+ }
838
+ }
839
+ }
840
+ },
841
+ {
842
+ "if": {
843
+ "properties": {
844
+ "status": {
845
+ "const": "succeeded"
846
+ }
847
+ },
848
+ "required": [
849
+ "status"
850
+ ]
851
+ },
852
+ "then": {
853
+ "properties": {
854
+ "effects": {
855
+ "type": "array",
856
+ "items": {
857
+ "type": "object",
858
+ "properties": {
859
+ "status": {
860
+ "enum": [
861
+ "applied",
862
+ "rolled_back"
863
+ ]
864
+ }
865
+ }
866
+ }
867
+ }
868
+ },
869
+ "not": {
870
+ "anyOf": [
871
+ {
872
+ "required": [
873
+ "error"
874
+ ]
875
+ },
876
+ {
877
+ "properties": {
878
+ "effects": {
879
+ "type": "array",
880
+ "contains": {
881
+ "type": "object",
882
+ "properties": {
883
+ "status": {
884
+ "const": "unknown"
885
+ }
886
+ },
887
+ "required": [
888
+ "status"
889
+ ]
890
+ }
891
+ }
892
+ },
893
+ "required": [
894
+ "effects"
895
+ ]
896
+ }
897
+ ]
898
+ }
899
+ }
900
+ },
901
+ {
902
+ "if": {
903
+ "properties": {
904
+ "status": {
905
+ "enum": [
906
+ "simulated",
907
+ "accepted",
908
+ "succeeded",
909
+ "failed",
910
+ "timed_out",
911
+ "partial",
912
+ "unknown",
913
+ "cancelled"
914
+ ]
915
+ }
916
+ },
917
+ "required": [
918
+ "status"
919
+ ]
920
+ },
921
+ "then": {
922
+ "properties": {
923
+ "policy_decision": {
924
+ "type": "object",
925
+ "properties": {
926
+ "decision": {
927
+ "const": "allow"
928
+ }
929
+ }
930
+ }
931
+ }
932
+ }
933
+ },
934
+ {
935
+ "if": {
936
+ "properties": {
937
+ "effects": {
938
+ "type": "array",
939
+ "contains": {
940
+ "type": "object",
941
+ "properties": {
942
+ "effect_type": {
943
+ "enum": [
944
+ "write_local",
945
+ "write_external",
946
+ "send_message",
947
+ "spend",
948
+ "publish",
949
+ "delete"
950
+ ]
951
+ },
952
+ "status": {
953
+ "const": "applied"
954
+ }
955
+ },
956
+ "required": [
957
+ "effect_type",
958
+ "status"
959
+ ]
960
+ }
961
+ }
962
+ },
963
+ "required": [
964
+ "effects"
965
+ ]
966
+ },
967
+ "then": {
968
+ "required": [
969
+ "executor_ref",
970
+ "idempotency"
971
+ ]
972
+ }
973
+ },
974
+ {
975
+ "if": {
976
+ "properties": {
977
+ "idempotency": {
978
+ "type": "object",
979
+ "properties": {
980
+ "disposition": {
981
+ "const": "replayed"
982
+ }
983
+ },
984
+ "required": [
985
+ "disposition"
986
+ ]
987
+ }
988
+ },
989
+ "required": [
990
+ "idempotency"
991
+ ]
992
+ },
993
+ "then": {
994
+ "required": [
995
+ "deduplicated_from_receipt_id"
996
+ ]
997
+ }
998
+ },
999
+ {
1000
+ "if": {
1001
+ "properties": {
1002
+ "status": {
1003
+ "const": "unknown"
1004
+ }
1005
+ },
1006
+ "required": [
1007
+ "status"
1008
+ ]
1009
+ },
1010
+ "then": {
1011
+ "required": [
1012
+ "recovery"
1013
+ ],
1014
+ "properties": {
1015
+ "error": {
1016
+ "type": "object",
1017
+ "properties": {
1018
+ "retryable": {
1019
+ "const": false
1020
+ }
1021
+ }
1022
+ },
1023
+ "recovery": {
1024
+ "type": "object",
1025
+ "properties": {
1026
+ "action": {
1027
+ "enum": [
1028
+ "reconcile",
1029
+ "human_handoff"
1030
+ ]
1031
+ }
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ },
1037
+ {
1038
+ "if": {
1039
+ "properties": {
1040
+ "status": {
1041
+ "enum": [
1042
+ "simulated",
1043
+ "denied",
1044
+ "succeeded",
1045
+ "failed",
1046
+ "timed_out",
1047
+ "partial",
1048
+ "unknown",
1049
+ "cancelled",
1050
+ "requires_human"
1051
+ ]
1052
+ }
1053
+ },
1054
+ "required": [
1055
+ "status"
1056
+ ]
1057
+ },
1058
+ "then": {
1059
+ "required": [
1060
+ "finished_at"
1061
+ ]
1062
+ }
1063
+ }
1064
+ ],
1065
+ "additionalProperties": false
1066
+ }