-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrait-wp-codebox-abilities-schemas.php
More file actions
1219 lines (1149 loc) · 55.9 KB
/
Copy pathtrait-wp-codebox-abilities-schemas.php
File metadata and controls
1219 lines (1149 loc) · 55.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WP_Codebox_Abilities_Schemas implementation.
*
* @package WPCodebox
*/
defined( 'ABSPATH' ) || exit;
trait WP_Codebox_Abilities_Schemas {
private static function mount_schema(): array {
return array(
'type' => 'array',
'description' => 'Additional host directories to mount into the sandbox. Callers may attach repo metadata for downstream tools that need to map sandbox paths back to source repositories.',
'items' => array(
'type' => 'object',
'required' => array( 'source', 'target' ),
'properties' => array(
'source' => array(
'type' => 'string',
'description' => 'Host directory path to mount.',
),
'target' => array(
'type' => 'string',
'description' => 'Absolute sandbox path, such as /wordpress/wp-content/plugins/example.',
),
'mode' => array(
'type' => 'string',
'enum' => array( 'readonly', 'readwrite' ),
),
'metadata' => array(
'type' => 'object',
'description' => 'Opaque caller metadata, for example repo, default_branch, repo_root_relative_to_mount, and editable flags.',
),
),
),
);
}
/** @return array<string,mixed> */
private static function site_seed_schema(): array {
$scope_schema = array(
'type' => 'object',
'properties' => array(
'ids' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ) ),
'slugs' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'names' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'postTypes' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'taxonomies' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'roles' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'statuses' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'includeFiles' => array( 'type' => 'boolean' ),
'anonymize' => array( 'type' => 'boolean' ),
'maxRecords' => array( 'type' => 'integer', 'minimum' => 1, 'maximum' => 100 ),
),
);
return array(
'type' => 'array',
'description' => 'Explicit opt-in bounded parent-site seed exports for existing-site sandboxes. Exported data is written to a temporary JSON fixture and imported into the sandbox before the task runs.',
'items' => array(
'type' => 'object',
'required' => array( 'type', 'name', 'scopes' ),
'properties' => array(
'type' => array( 'type' => 'string', 'enum' => array( 'parent_site' ) ),
'name' => array( 'type' => 'string' ),
'scopes' => array(
'type' => 'object',
'properties' => array(
'posts' => $scope_schema,
'terms' => $scope_schema,
'options' => $scope_schema,
'users' => $scope_schema,
'media' => $scope_schema,
'activePlugins' => array( 'type' => 'boolean' ),
'activeTheme' => array( 'type' => 'boolean' ),
),
),
),
),
);
}
/** @return array<string,mixed> */
private static function agent_bundle_schema(): array {
return array(
'type' => 'array',
'description' => 'Runtime agent bundles to import into the disposable sandbox before invoking the selected runtime agent. Installed runtime plugins provide importer implementations.',
'items' => array(
'type' => 'object',
'anyOf' => array(
array( 'required' => array( 'source' ) ),
array( 'required' => array( 'bundle' ) ),
),
'properties' => array(
'source' => array(
'type' => 'string',
'description' => 'Bundle source accepted by the runtime importer, such as a local directory, .zip, .json, or remote URL.',
),
'bundle' => array(
'type' => 'object',
'description' => 'Inline runtime agent bundle JSON staged in the sandbox and passed to the registered importer.',
),
'slug' => array( 'type' => 'string' ),
'on_conflict' => array( 'type' => 'string', 'enum' => array( 'error', 'skip', 'upgrade' ) ),
'owner_id' => array( 'type' => 'integer' ),
'token_env' => array( 'type' => 'string' ),
'import_principal' => array(
'type' => 'object',
'description' => 'Optional non-secret importer principal context. Runtime importers define the shape they accept.',
),
),
),
);
}
/** @return array<string,mixed> */
private static function inherit_schema(): array {
$credential_secret_schema = array(
'type' => 'object',
'required' => array( 'name', 'status' ),
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Sandbox environment variable name. Secret values are never transported.',
),
'status' => array(
'type' => 'string',
'enum' => array( 'available', 'missing', 'denied' ),
),
'scope' => array(
'type' => 'string',
'description' => 'Parent-side connector scope that authorized this secret name.',
),
'source' => array(
'type' => 'string',
'description' => 'Redacted source label, such as parent-env or connector.',
),
'reason' => array(
'type' => 'string',
'description' => 'Redacted missing/denied reason for audit surfaces.',
),
),
);
return array(
'type' => 'object',
'description' => 'Declarative request for parent-environment connector or setting inheritance. Parent filters resolve names into a sanitized sandbox payload with explicit connector-scoped credential envelopes; secret values are never accepted here.',
'properties' => array(
'connectors' => array(
'type' => 'array',
'description' => 'Connector names the parent environment should resolve for this sandbox run.',
'items' => array( 'type' => 'string' ),
),
'settings' => array(
'type' => 'array',
'description' => 'Setting names the parent environment should resolve for artifact/audit metadata. Values are not transported in this slice.',
'items' => array( 'type' => 'string' ),
),
'credentials' => array(
'type' => 'object',
'description' => 'Observable credential envelope shape returned under inheritance.connectors[].credentials by parent filters. Values are not accepted.',
'properties' => array(
'schema' => array( 'type' => 'string' ),
'connector' => array( 'type' => 'string' ),
'scope' => array( 'type' => 'string', 'enum' => array( 'connector' ) ),
'status' => array( 'type' => 'string', 'enum' => array( 'available', 'missing', 'denied' ) ),
'reason' => array( 'type' => 'string' ),
'secrets' => array( 'type' => 'array', 'items' => $credential_secret_schema ),
),
),
),
);
}
/** @return array<string,array<string,mixed>> */
private static function preview_input_schema(): array {
return WP_Codebox_Preview_Options::input_schema();
}
/** @return array<string,mixed> */
private static function sandbox_session_input_schema(): array {
return array(
'sandbox_session_id' => array(
'type' => 'string',
'description' => 'Caller-owned sandbox session id for external job/session systems. WP Codebox returns it in the response but does not persist sessions itself.',
),
'orchestrator' => array(
'type' => 'object',
'description' => 'Optional caller-owned job/session metadata, such as external job system, job id, or control-plane id. Values are copied into the response session envelope for correlation only.',
'properties' => array(
'id' => array( 'type' => 'string' ),
'type' => array( 'type' => 'string' ),
'job_id' => array( 'type' => 'string' ),
),
),
);
}
/** @return array<string,mixed> */
private static function remediation_outcome_schema(): array {
return array(
'type' => 'object',
'description' => 'Strict audit-remediation terminal outcome. Sandbox runs return reviewed artifacts when they can remediate, or an explicit terminal no-op/failure outcome when they cannot. Parent orchestrators apply artifacts and open PRs outside the sandbox.',
'properties' => array(
'schema' => array( 'type' => 'string' ),
'success' => array( 'type' => 'boolean' ),
'kind' => array(
'type' => 'string',
'enum' => array( 'completed', 'failed', 'unable_to_remediate', 'provider_error', 'agent_no_pr_outcome', 'max_turns_exceeded', 'runtime_tool_pending' ),
),
'failure' => array(
'type' => 'string',
'enum' => array( 'failed', 'provider_error', 'agent_no_pr_outcome', 'max_turns_exceeded', 'runtime_tool_pending', '' ),
),
'pr_url' => array( 'type' => 'string' ),
'false_positive_pr_url' => array( 'type' => 'string' ),
'exit_code' => array( 'type' => 'integer' ),
'retryable' => array( 'type' => 'boolean' ),
'provider_error' => array( 'type' => 'object' ),
'artifact' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
'diagnostics' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function completion_outcome_schema(): array {
return array(
'type' => 'object',
'description' => 'Generic sandbox completion outcome emitted as files/completion-outcome.json and returned for orchestration without parsing prose.',
'properties' => array(
'schema' => array( 'type' => 'string' ),
'status' => array(
'type' => 'string',
'enum' => array( 'succeeded', 'blocked', 'failed', 'partial' ),
),
'summary' => array( 'type' => 'string' ),
'changedFiles' => array( 'type' => 'object' ),
'patch' => array( 'type' => 'object' ),
'artifacts' => array( 'type' => 'object' ),
'verification' => array( 'type' => 'object' ),
'blockers' => array( 'type' => 'array' ),
'riskNotes' => array( 'type' => 'array' ),
'confidence' => array( 'type' => 'string' ),
'nextAction' => array( 'type' => 'string' ),
'provenance' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function sandbox_session_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'schema' => array(
'type' => 'string',
'description' => 'Session envelope contract version. Use wp-codebox/sandbox-session/v1.',
),
'id' => array(
'type' => 'string',
'description' => 'Caller-owned sandbox session id echoed for external orchestration correlation.',
),
'status' => array(
'type' => 'string',
'enum' => array( 'ready', 'completed' ),
'description' => 'Synchronous WP Codebox preparation/run status. Durable queued/running/cancelled/expired state belongs to the external orchestrator.',
),
'persistence' => array(
'type' => 'string',
'enum' => array( 'external-orchestrator' ),
'description' => 'WP Codebox does not persist host-site session lifecycle state; callers own durable records.',
),
'agent_session_id' => array( 'type' => 'string' ),
'orchestrator' => array( 'type' => 'object' ),
'authorization' => array( 'type' => 'object' ),
'artifacts' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function browser_playground_session_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'preview_only' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string' ),
'execution' => array(
'type' => 'string',
'enum' => array( 'browser-playground' ),
'description' => 'The caller browser executes WordPress Playground; the host site does not run the WP Codebox CLI.',
),
'execution_scope' => array(
'type' => 'string',
'enum' => array( 'disposable-playground' ),
'description' => 'Browser sessions run inside a disposable WordPress Playground sandbox, not the host site.',
),
'permission_model' => array(
'type' => 'string',
'enum' => array( 'runtime-principal' ),
'description' => 'The generated browser runner authorizes Agents API calls through a scoped runtime principal inside the disposable Playground sandbox.',
),
'session' => array( 'type' => 'object' ),
'preview_boot' => array( 'type' => 'object' ),
'runtime_access' => array( 'type' => 'object' ),
'preview_ref' => array( 'type' => 'object' ),
'artifact_refs' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'contained_site' => self::browser_contained_site_schema(),
'signals' => array( 'type' => 'object' ),
'artifacts' => array( 'type' => 'object' ),
'product' => self::browser_product_dto_schema(),
),
);
}
/** @return array<string,mixed> */
private static function browser_materializer_contract_schema(): array {
return self::browser_product_dto_schema();
}
/** @return array<string,mixed> */
private static function browser_internal_materializer_contract_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string' ),
'execution' => array(
'type' => 'string',
'enum' => array( 'browser-playground' ),
),
'execution_scope' => array(
'type' => 'string',
'enum' => array( 'disposable-playground' ),
),
'permission_model' => array(
'type' => 'string',
'enum' => array( 'runtime-principal' ),
),
'session_id' => array( 'type' => 'string' ),
'contained_site' => self::browser_contained_site_schema(),
'authorization' => array( 'type' => 'object' ),
'task_input' => self::task_input_schema(),
'task_payload' => array( 'type' => 'object' ),
'materialization' => array( 'type' => 'object' ),
'recipe' => array( 'type' => 'object' ),
'playground' => array( 'type' => 'object' ),
'runtime' => array( 'type' => 'object' ),
'artifacts' => array( 'type' => 'object' ),
'compact' => self::browser_product_dto_schema(),
),
);
}
/** @return array<string,mixed> */
private static function browser_task_contract_schema(): array {
return self::browser_product_dto_schema();
}
/** @return array<string,mixed> */
private static function browser_internal_task_contract_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string' ),
'execution' => array(
'type' => 'string',
'enum' => array( 'browser-playground' ),
),
'execution_scope' => array(
'type' => 'string',
'enum' => array( 'disposable-playground' ),
),
'permission_model' => array(
'type' => 'string',
'enum' => array( 'runtime-principal' ),
),
'session' => array( 'type' => 'object' ),
'contained_site' => self::browser_contained_site_schema(),
'primary' => self::browser_playground_session_schema(),
'phases' => array(
'type' => 'array',
'description' => 'Named browser task phases. Materializer phases include a browser-materializer-contract envelope; fanout and host-delegation phases preserve explicit request envelopes during contract preparation and include results only when host-side phase execution is requested.',
'items' => array(
'type' => 'object',
'properties' => array(
'name' => array( 'type' => 'string' ),
'kind' => array( 'type' => 'string', 'enum' => self::browser_task_phase_kinds() ),
'index' => array( 'type' => 'integer' ),
'label' => array( 'type' => 'string' ),
'status' => array( 'type' => 'string' ),
'metadata' => array( 'type' => 'object' ),
'request' => array( 'type' => 'object' ),
'contract' => array( 'type' => 'object' ),
'result' => array( 'type' => 'object' ),
),
),
),
'execution_metrics' => array( 'type' => 'object' ),
'provenance' => array( 'type' => 'object' ),
'compact' => self::browser_product_dto_schema(),
),
);
}
/** @return array<int,string> */
private static function browser_task_phase_kinds(): array {
return array( 'materializer', 'agent', 'validator', 'repair', 'aggregator', 'host-delegation' );
}
/** @return array<string,mixed> */
private static function browser_product_dto_schema(): array {
return array(
'type' => 'object',
'description' => 'Compact product-facing browser task/session DTO for durable product records and REST responses. It exposes stable ids, preview refs, artifact refs, status, and compact diagnostics while omitting raw playground, runtime, recipe, task payload, sandbox path, and implementation diagnostic contracts.',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'preview_only' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string' ),
'dto_schema' => array( 'type' => 'string' ),
'source_schema' => array( 'type' => 'string' ),
'execution' => array( 'type' => 'string' ),
'execution_scope' => array( 'type' => 'string' ),
'permission_model' => array( 'type' => 'string' ),
'status' => array( 'type' => 'string' ),
'session_id' => array( 'type' => 'string' ),
'session' => array( 'type' => 'object' ),
'contained_site' => self::browser_contained_site_schema(),
'primary' => array( 'type' => 'object' ),
'phases' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'task' => array( 'type' => 'string' ),
'target' => array( 'type' => 'object' ),
'agent' => array( 'type' => 'string' ),
'provider' => array( 'type' => 'string' ),
'model' => array( 'type' => 'string' ),
'preview_boot' => array( 'type' => 'object' ),
'preview_lease' => array( 'type' => 'object' ),
'blueprint_ref' => array( 'type' => 'object' ),
'runtime_access' => array( 'type' => 'object' ),
'runtime_capabilities' => self::browser_runtime_capabilities_schema(),
'runtime_readiness' => self::browser_runtime_readiness_schema(),
'artifact_refs' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'signals' => array( 'type' => 'object' ),
'error' => array( 'type' => 'object' ),
'diagnostics' => array( 'type' => 'object' ),
'execution_metrics' => array( 'type' => 'object' ),
'provenance' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function browser_executable_session_schema(): array {
return array(
'type' => 'object',
'description' => 'Codebox-owned public executable browser session DTO. Hosts can store and hand this to browser clients without raw Playground blueprints, package internals, runtime recipes, sandbox paths, or downstream implementation names.',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/browser-executable-session/v1' ),
'session_id' => array( 'type' => 'string' ),
'status' => array( 'type' => 'string' ),
'execution' => array( 'type' => 'string' ),
'execution_scope' => array( 'type' => 'string' ),
'permission_model' => array( 'type' => 'string' ),
'preview' => array( 'type' => 'object' ),
'preview_ref' => array( 'type' => 'object' ),
'preview_boot' => array( 'type' => 'object' ),
'blueprint_ref' => array( 'type' => 'object' ),
'runtime_access' => array( 'type' => 'object' ),
'runtime_capabilities' => self::browser_runtime_capabilities_schema(),
'runtime_readiness' => self::browser_runtime_readiness_schema(),
'contained_site' => self::browser_contained_site_schema(),
'runtime_handoff' => array( 'type' => 'object' ),
'parent_tool_bridge' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function browser_runtime_capabilities_schema(): array {
return array(
'type' => 'object',
'description' => 'Product-safe browser runtime capability summary. Values name portable capabilities only and omit package, plugin, provider, and source implementation details.',
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/browser-runtime-capabilities/v1' ),
'capabilities' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
),
);
}
/** @return array<string,mixed> */
private static function browser_runtime_readiness_schema(): array {
return array(
'type' => 'object',
'description' => 'Product-safe browser runtime readiness summary. It exposes readiness booleans and missing portable requirements without raw dependency plans or implementation diagnostics.',
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/browser-runtime-readiness/v1' ),
'status' => array( 'type' => 'string', 'enum' => array( 'ready', 'blocked', 'unknown' ) ),
'ready' => array( 'type' => 'boolean' ),
'requirements' => array( 'type' => 'object' ),
'missing' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'message' => array( 'type' => 'string' ),
),
);
}
/** @return array<string,mixed> */
private static function browser_contained_site_schema(): array {
return array(
'type' => 'object',
'description' => 'Durable browser-contained WordPress site handle. The caller stores this envelope and can call the status ability to recover a prepared runtime blueprint when the transient still exists.',
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/browser-contained-site/v1' ),
'site_id' => array( 'type' => 'string' ),
'preview_id' => array( 'type' => 'string' ),
'session_id' => array( 'type' => 'string' ),
'caller_id' => array( 'type' => 'string' ),
'status' => array( 'type' => 'string', 'enum' => array( 'ready', 'blocked', 'recoverable_prepared_runtime', 'current', 'live', 'materialized', 'miss', 'disabled', 'incompatible', 'unusable' ) ),
'open_mode' => array( 'type' => 'string', 'enum' => array( 'reuse_current', 'reuse_live', 'reuse_materialized', 'reuse_prepared_runtime', 'materialize', 'unavailable' ) ),
'reuse_level' => array( 'type' => 'string', 'enum' => array( 'current', 'live', 'materialized', 'prepared_runtime', 'none' ) ),
'requires_materialization' => array( 'type' => 'boolean' ),
'prepared_runtime_recoverable' => array( 'type' => 'boolean' ),
'live' => array( 'type' => 'boolean' ),
'current' => array( 'type' => 'boolean' ),
'materialized' => array( 'type' => 'boolean' ),
'resolution' => array( 'type' => 'object' ),
'persistence' => array( 'type' => 'string', 'enum' => array( 'browser-contained' ) ),
'artifact_seed' => array( 'type' => 'string' ),
'artifact_revision' => array( 'type' => 'string' ),
'recovery' => array( 'type' => 'object' ),
'recovery_handle' => array( 'type' => 'string' ),
'source_digest' => array( 'type' => 'object' ),
'artifact_digest' => array( 'type' => 'object' ),
'materialization_digest' => array( 'type' => 'object' ),
'preview' => array( 'type' => 'object' ),
'prepared_runtime' => array( 'type' => 'object' ),
'blueprint_ref' => array( 'type' => 'object' ),
'preview_boot' => array( 'type' => 'object' ),
'preview_lease' => array( 'type' => 'object' ),
'runtime_access' => array( 'type' => 'object' ),
'session' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function browser_session_authorization_schema(): array {
return self::trusted_orchestrator_authorization_schema( self::BROWSER_SESSION_CREATE_SCOPE, 'Explicit trusted orchestrator authorization for browser session creation. Callers must provide a caller id and the browser-session:create scope; sites grant trust through wp_codebox_trusted_browser_session_callers.' );
}
/** @return array<string,mixed> */
private static function browser_connector_authorization_schema(): array {
return self::trusted_orchestrator_authorization_schema( self::BROWSER_CONNECTOR_REQUEST_SCOPE, 'Explicit trusted orchestrator authorization for browser connector/provider requests. Callers must provide a caller id and the browser-connector:request scope; sites grant trust through wp_codebox_trusted_browser_session_callers.' );
}
/** @return array<string,mixed> */
private static function trusted_orchestrator_authorization_schema( string $scope, string $description ): array {
return array(
'type' => 'object',
'description' => $description,
'properties' => array(
'schema' => array(
'type' => 'string',
'description' => 'Authorization contract version. Use wp-codebox/trusted-orchestrator-authorization/v1.',
),
'caller' => array(
'type' => 'string',
'description' => 'Stable caller id, for example browser-client.',
),
'scope' => array(
'type' => 'string',
'enum' => array( $scope ),
'description' => 'Required trusted-orchestrator capability scope.',
),
),
);
}
/** @return array<string,mixed> */
private static function task_input_schema(): array {
return WP_Codebox_Task_Input_Contract::schema();
}
/** @return array<string,mixed> */
private static function agent_workload_schema(): array {
return WP_Codebox_Agent_Workload::schema();
}
/** @return array<string,mixed> */
private static function string_property_schema( string $description = '' ): array {
$schema = array( 'type' => 'string' );
if ( '' !== $description ) {
$schema['description'] = $description;
}
return $schema;
}
/** @return array<string,mixed> */
private static function object_property_schema( string $description = '' ): array {
$schema = array( 'type' => 'object' );
if ( '' !== $description ) {
$schema['description'] = $description;
}
return $schema;
}
/** @return array<string,mixed> */
private static function string_array_property_schema( string $description = '' ): array {
$schema = array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
);
if ( '' !== $description ) {
$schema['description'] = $description;
}
return $schema;
}
/** @return array<string,mixed> */
private static function object_array_property_schema( string $description = '' ): array {
$schema = array(
'type' => 'array',
'items' => array( 'type' => 'object' ),
);
if ( '' !== $description ) {
$schema['description'] = $description;
}
return $schema;
}
/** @return array<string,mixed> */
private static function approved_files_schema( string $description ): array {
return self::string_array_property_schema( $description );
}
/** @return array<string,mixed> */
private static function artifact_apply_input_properties( string $approved_files_description, string $approver_description, string $apply_target_description ): array {
return array(
'approved_files' => self::approved_files_schema( $approved_files_description ),
'approver' => self::string_property_schema( $approver_description ),
'apply_target' => self::object_property_schema( $apply_target_description ),
);
}
/** @return array<string,mixed> */
private static function runtime_task_request_schema(): array {
return array(
'type' => 'object',
'required' => array( 'task', 'target_id' ),
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/runtime-task-request/v1' ),
'task' => array( 'type' => array( 'string', 'object' ) ),
'input' => array( 'type' => 'object' ),
'task_input' => self::task_input_schema(),
'target_id' => array(
'type' => 'string',
'description' => 'Explicit runtime target id. Built-in targets are wp-codebox/host-playground and wp-codebox/browser-playground; extension providers may register additional target ids.',
),
'mode' => self::string_property_schema(),
'agent' => self::string_property_schema(),
'provider' => self::string_property_schema(),
'model' => self::string_property_schema(),
'sandbox_session_id' => self::string_property_schema(),
'orchestrator' => self::object_property_schema(),
'metadata' => self::object_property_schema(),
'options' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function runtime_task_result_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/runtime-task-result/v1' ),
'status' => array( 'type' => 'string' ),
'execution' => array( 'type' => 'string' ),
'task' => array( 'type' => array( 'string', 'object' ) ),
'result' => array( 'type' => 'object' ),
'error' => array( 'type' => 'object' ),
'events' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'artifacts' => array( 'type' => array( 'object', 'array', 'string' ) ),
'run' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
'upstream_refs' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function runtime_package_task_schema(): array {
return array(
'type' => 'object',
'required' => array( 'schema', 'package', 'workflow', 'input', 'artifact_declarations', 'required_artifacts' ),
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/runtime-package-task/v1' ),
'package' => array(
'type' => 'object',
'required' => array( 'slug', 'source' ),
'properties' => array(
'slug' => array( 'type' => 'string', 'minLength' => 1, 'description' => 'Runtime package identity.' ),
'source' => array( 'type' => 'string', 'minLength' => 1, 'description' => 'Runtime package import path, normalized against an explicit workspace root before execution when workspace-relative.' ),
),
),
'workflow' => array(
'type' => 'object',
'required' => array( 'id' ),
'properties' => array(
'id' => array( 'type' => 'string', 'minLength' => 1 ),
'spec' => array( 'type' => 'object' ),
),
),
'input' => array( 'type' => 'object' ),
'artifact_declarations' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'output_projections' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'required_artifacts' => array( 'type' => 'array', 'items' => array( 'type' => 'string', 'minLength' => 1 ) ),
'metadata' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function runtime_package_result_schema(): array {
return array(
'type' => 'object',
'required' => array( 'schema', 'status', 'success', 'outputs', 'artifacts', 'diagnostics', 'metadata' ),
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/runtime-package-result/v1' ),
'status' => array( 'type' => 'string', 'enum' => array( 'success', 'failed' ) ),
'success' => array( 'type' => 'boolean' ),
'package' => array( 'type' => 'object' ),
'outputs' => array( 'type' => 'object' ),
'artifacts' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'diagnostics' => array( 'type' => 'array', 'items' => array( 'type' => 'object' ) ),
'metadata' => array( 'type' => 'object' ),
),
);
}
/** @return array<string,mixed> */
private static function wordpress_workload_run_request_schema(): array {
return array(
'type' => 'object',
'required' => array( 'schema', 'steps' ),
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/wordpress-workload-run/v1' ),
'wordpress_version' => self::string_property_schema( 'WordPress version requested for the disposable Playground workload.' ),
'blueprint' => self::object_property_schema( 'Optional WordPress Playground blueprint object.' ),
'post_runtime_blueprint' => self::object_property_schema( 'Optional WordPress Playground blueprint steps to run after runtime dependencies are materialized.' ),
'preview' => self::object_property_schema( 'Optional preview settings for the workload.' ),
'mounts' => self::mount_schema(),
'runtime_stack_mounts' => self::object_array_property_schema( 'Runtime stack mounts for the disposable workload.' ),
'runtime_overlays' => self::object_array_property_schema( 'Runtime overlays for the disposable workload.' ),
'runtime_env' => self::object_property_schema( 'Non-secret runtime environment values. Secret values must use secret_env names.' ),
'secret_env' => self::string_array_property_schema( 'Parent environment variable names expected by the workload. Values are never accepted in this payload.' ),
'staged_files' => self::object_array_property_schema( 'Explicit staged file descriptors accepted by the recipe runtime.' ),
'artifacts' => self::object_array_property_schema( 'Artifact refs declared by the safe recipe runtime.' ),
'before' => self::wordpress_workload_steps_schema(),
'steps' => self::wordpress_workload_steps_schema(),
'after' => self::wordpress_workload_steps_schema(),
'metadata' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function wordpress_workload_steps_schema(): array {
return array(
'type' => 'array',
'items' => array(
'type' => 'object',
'required' => array( 'command' ),
'properties' => array(
'command' => array( 'type' => 'string' ),
'args' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'allowFailure' => array( 'type' => 'boolean' ),
'advisory' => array( 'type' => 'boolean' ),
),
),
);
}
/** @return array<string,mixed> */
private static function wordpress_workload_run_result_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/wordpress-workload-run-result/v1' ),
'status' => array( 'type' => 'string', 'enum' => array( 'completed', 'failed', 'skipped', 'unsupported' ) ),
'request' => self::object_property_schema(),
'steps' => self::object_array_property_schema(),
'artifacts' => self::object_array_property_schema(),
'diagnostics' => self::object_array_property_schema(),
'metadata' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function fuzz_runner_capabilities_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/fuzz-runner-capabilities/v1' ),
'mode' => array( 'type' => 'string', 'enum' => array( 'php-in-process', 'runtime-backed' ) ),
'capabilities' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'targetKinds' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'runtimeActionTypes' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'commands' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'unsupportedRequiredCapabilities' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ),
'metadata' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function fuzz_suite_request_schema(): array {
return array(
'type' => 'object',
'required' => array( 'schema', 'id', 'cases' ),
'properties' => array(
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/fuzz-suite/v1' ),
'id' => array( 'type' => 'string' ),
'version' => array( 'type' => 'string' ),
'runnerMode' => array( 'type' => 'string', 'enum' => array( 'auto', 'php-in-process', 'runtime-backed' ) ),
'runner_mode' => array( 'type' => 'string', 'enum' => array( 'auto', 'php-in-process', 'runtime-backed' ) ),
'requireCoverage' => array( 'type' => 'boolean' ),
'require_coverage' => array( 'type' => 'boolean' ),
'target' => self::fuzz_suite_target_schema(),
'cases' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'required' => array( 'id' ),
'properties' => array(
'id' => array( 'type' => 'string' ),
'target' => self::fuzz_suite_target_schema(),
'input' => array(),
'description' => array( 'type' => 'string' ),
'metadata' => self::object_property_schema(),
),
),
),
'coveragePlan' => self::object_property_schema(),
'metadata' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function fuzz_suite_target_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'kind' => array( 'type' => 'string', 'enum' => array( 'ability', 'command', 'http', 'rest', 'runtime', 'runtime-action' ) ),
'id' => array( 'type' => 'string' ),
'entrypoint' => array( 'type' => 'string' ),
'label' => array( 'type' => 'string' ),
'metadata' => self::object_property_schema(),
),
);
}
/** @return array<string,mixed> */
private static function fuzz_suite_result_schema(): array {
return array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'schema' => array( 'type' => 'string', 'const' => 'wp-codebox/fuzz-suite-result/v1' ),
'status' => array( 'type' => 'string', 'enum' => array( 'passed', 'failed', 'error', 'skipped', 'unsupported' ) ),
'suite' => self::object_property_schema(),
'summary' => self::object_property_schema(),
'coverageSummary' => self::object_property_schema(),
'coveragePlan' => self::object_property_schema(),
'cases' => self::object_array_property_schema(),
'diagnostics' => self::object_array_property_schema(),
'artifactRefs' => self::object_array_property_schema(),
'metadata' => self::object_property_schema(),
),
);
}
/**
* Shared host-side sandbox runner input fields used by task, batch, and fanout abilities.
*
* @param array<string,mixed> $task_input_schema Task input schema.
* @param array<string,mixed> $mount_schema Mount schema.
* @param array<string,mixed> $site_seed_schema Site seed schema.
* @param array<string,mixed> $inherit_schema Inheritance schema.
* @param array<string,mixed> $session_input Session input schema.
* @param array<string,mixed> $preview_schema Preview input schema.
* @param array<string,mixed> $options Composition options.
* @return array<string,mixed>
*/
private static function host_agent_task_input_properties( array $task_input_schema, array $mount_schema, array $site_seed_schema, array $inherit_schema, array $session_input, array $preview_schema, array $options = array() ): array {
$detailed = ! empty( $options['detailed'] );
$properties = array(
'agent_workload' => self::agent_workload_schema(),
'workload' => self::agent_workload_schema(),
'agent' => self::string_property_schema( $detailed ? 'Codebox agent runtime id. Defaults through wp_codebox_default_agent.' : '' ),
'mode' => self::string_property_schema( $detailed ? 'Agent execution mode. Defaults to sandbox.' : '' ),
'provider' => self::string_property_schema( $detailed ? 'AI provider id to seed into the sandbox agent config.' : '' ),
'model' => self::string_property_schema( $detailed ? 'AI model id to seed into the sandbox agent config.' : '' ),
'runtime_profile' => self::object_property_schema( $detailed ? 'Portable wp-codebox/runtime-profile/v1 descriptor for runtime dependencies, capabilities, provider selection, and prepared runtime metadata.' : '' ),
'workspace_artifact_policy' => self::object_property_schema( $detailed ? 'Caller policy for artifact capture, retention, publication handoff, and optional public artifact URL roots. WP Codebox returns refs; callers own publication decisions.' : '' ),
'agent_bundles' => self::agent_bundle_schema(),
'runtime_task' => self::object_property_schema( $detailed ? 'Internal runtime adapter task request. Prefer agent_workload.agent_runtime.runtime_task for public callers.' : '' ),
'parent_request' => self::object_property_schema( $detailed ? 'Canonical wp-codebox/task-input/v1 parent request normalized into the WP Codebox runner contract.' : '' ),
'component_contracts' => self::component_contracts_schema( $detailed ? 'Caller-declared runtime components WP Codebox should package, mount, or probe.' : '' ),
'mounts' => $mount_schema,
'workspaces' => self::object_array_property_schema( $detailed ? 'Recipe workspace entries to seed as policy-checked writable repositories.' : '' ),
'runtime_stack_mounts' => self::object_array_property_schema( $detailed ? 'Runtime stack mounts to pass through to recipe.runtime.stack.mounts.' : '' ),
'runtime_state_mounts' => self::object_array_property_schema( $detailed ? 'Generic provider/runtime config or state files/directories mounted before provider plugins and runtime code load.' : '' ),
'runtime_config_mounts' => self::object_array_property_schema( $detailed ? 'Generic provider/runtime config files/directories mounted before provider plugins and runtime code load.' : '' ),
'runtime_env' => self::object_property_schema( $detailed ? 'Non-secret runtime environment values exposed to sandbox PHP before WordPress and provider plugins load. Secret values must use secret_env.' : '' ),
'runtime_overlays' => self::object_array_property_schema( $detailed ? 'Runtime overlays to pass through to recipe.runtime.overlays.' : '' ),
'inherit' => $inherit_schema,
'sandbox_session_id' => $session_input['sandbox_session_id'],
'orchestrator' => $session_input['orchestrator'],
'secret_env' => self::string_array_property_schema( $detailed ? 'Explicit parent environment variable names to expose inside the sandbox. Prefer connector-scoped inheritance credentials for product flows. Values are read from the parent process and are not accepted in this payload.' : '' ),
'max_turns' => $detailed ? array(
'type' => 'integer',
'description' => 'Maximum agent loop turns for this sandbox task.',
) : array( 'type' => 'integer' ),
'preview_hold_seconds' => $preview_schema['preview_hold_seconds'],
'preview_port' => $preview_schema['preview_port'],
'preview_bind' => $preview_schema['preview_bind'],
'preview_public_url' => $preview_schema['preview_public_url'],
'wp' => self::string_property_schema( $detailed ? 'WordPress version passed to Playground. Defaults to trunk.' : '' ),
'artifacts_path' => self::string_property_schema( $detailed ? 'Directory where WP Codebox should write artifact bundles.' : '' ),
);
if ( $detailed ) {
$properties['debug'] = array(
'type' => 'object',
'description' => 'Internal/debug execution overrides. Product callers should use runtime_profile and workspace_artifact_policy instead of shell, binary, path, or provider plugin path fields.',
'properties' => array(
'provider_plugin_paths' => self::string_array_property_schema( 'Internal provider plugin directories to mount and activate inside the sandbox.' ),
'wp_codebox_bin' => self::string_property_schema( 'Internal WP Codebox CLI binary override.' ),
),
);
}
if ( ! empty( $options['task_fields'] ) ) {
$properties = self::task_input_alias_properties( $task_input_schema ) + $properties;
}
if ( ! empty( $options['site_seeds'] ) ) {
$properties['site_seeds'] = $site_seed_schema;
}
if ( ! empty( $options['session_id'] ) ) {
$properties['session_id'] = self::string_property_schema( 'Existing sandbox conversation session id.' );
}
if ( ! empty( $options['task_timeout_seconds'] ) ) {
$properties['task_timeout_seconds'] = array(
'type' => 'integer',
'description' => $detailed ? 'Maximum wall-clock seconds for this sandbox task. Zero or omitted disables the host-side timeout.' : '',
);
if ( '' === $properties['task_timeout_seconds']['description'] ) {
unset( $properties['task_timeout_seconds']['description'] );
}
}
return $properties;
}
/** @return array<string,mixed> */
private static function component_contracts_schema( string $description = '' ): array {
$schema = array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'slug' => self::string_property_schema( 'Component plugin slug.' ),
'path' => self::string_property_schema( 'Host filesystem path to package for the sandbox.' ),
'source' => self::string_property_schema( 'Alias for path.' ),
'activate' => array( 'type' => 'boolean' ),
'loadAs' => self::string_property_schema( 'Recipe loading mode, such as mu-plugin.' ),
'required' => array( 'type' => 'boolean' ),
'readiness_probe' => array(
'type' => 'object',
'properties' => array(
'type' => array( 'type' => 'string', 'enum' => array( 'ability', 'filter' ) ),
'name' => array( 'type' => 'string' ),