-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkspaceAbilities.php
More file actions
4209 lines (3983 loc) · 161 KB
/
Copy pathWorkspaceAbilities.php
File metadata and controls
4209 lines (3983 loc) · 161 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
/**
* Workspace Abilities
*
* WordPress 6.9 Abilities API primitives for all agent workspace operations.
* These are the canonical entry points — CLI commands and chat tools delegate here.
*
* Read-only abilities (path, list, show, read, ls) are exposed via REST.
* Mutating abilities (clone, remove) are CLI-only (show_in_rest = false).
*
* @package DataMachineCode\Abilities
* @since 0.1.0
*/
namespace DataMachineCode\Abilities;
use DataMachineCode\Support\PermissionHelper;
use DataMachineCode\Workspace\CleanupRunService;
use DataMachineCode\Workspace\RemoteWorkspaceBackend;
use DataMachineCode\Workspace\RunnerWorkspacePublisher;
use DataMachineCode\Workspace\Workspace;
use DataMachineCode\Workspace\WorkspaceReader;
use DataMachineCode\Workspace\WorkspaceWriter;
use DataMachineCode\Support\GitRunner;
use DataMachineCode\Support\RuntimeCapabilities;
defined('ABSPATH') || exit;
if ( ! class_exists(AbilityRegistry::class) ) {
require_once __DIR__ . '/AbilityRegistry.php';
}
if ( ! class_exists(RuntimeCapabilities::class) ) {
require_once dirname(__DIR__) . '/Support/RuntimeCapabilities.php';
}
if ( ! class_exists(GitHubAbilities::class) ) {
require_once __DIR__ . '/GitHubAbilities.php';
}
if ( ! class_exists(RunnerWorkspacePublisher::class) ) {
require_once dirname(__DIR__) . '/Workspace/RunnerWorkspacePublisher.php';
}
class WorkspaceAbilities {
private static bool $registered = false;
public function __construct() {
if ( self::$registered ) {
return;
}
if ( ! function_exists('wp_register_ability') ) {
add_action(
'wp_abilities_api_init', function (): void {
if ( self::$registered || ! function_exists('wp_register_ability') ) {
return;
}
$this->registerAbilities();
self::$registered = true;
}
);
return;
}
$this->registerAbilities();
self::$registered = true;
}
private function registerAbilities(): void {
$register_callback = function () {
// -----------------------------------------------------------------
// Read-only discovery abilities (show_in_rest = true).
// -----------------------------------------------------------------
AbilityRegistry::register(
'datamachine-code/workspace-path',
array(
'label' => 'Get Workspace Path',
'description' => 'Get the agent workspace directory path. Optionally create the directory.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'ensure' => array(
'type' => 'boolean',
'description' => 'Create the workspace directory if it does not exist.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
'exists' => array( 'type' => 'boolean' ),
'created' => array( 'type' => 'boolean' ),
),
),
'execute_callback' => array( self::class, 'getPath' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-list',
array(
'label' => 'List Workspace Repos',
'description' => 'List repositories in the agent workspace. Primary rows include local-ref freshness metadata; refresh stale primaries before using them for verification.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Optional primary repository name to filter by. Includes the primary checkout and its worktrees.',
),
'type' => array(
'type' => 'string',
'enum' => array( 'primary', 'worktree', 'context' ),
'description' => 'Optional checkout type filter. Use "primary" for base checkouts, "worktree" for branch worktrees, or "context" for read-only context repositories.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
'repos' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'name' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'git' => array( 'type' => 'boolean' ),
// Local-only repos have no remote; detached HEAD has no branch.
'remote' => array( 'type' => array( 'string', 'null' ) ),
'branch' => array( 'type' => array( 'string', 'null' ) ),
'primary_freshness' => self::primaryFreshnessSchema(),
),
),
),
),
),
'execute_callback' => array( self::class, 'listRepos' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-capabilities',
array(
'label' => 'Inspect Workspace Capabilities',
'description' => 'Inspect the current Data Machine Code workspace backend and whether local git operations can execute in this runtime.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'backend' => array( 'type' => 'string' ),
'workspace_path' => array( 'type' => 'string' ),
'git_available' => array( 'type' => 'boolean' ),
'exec_available' => array( 'type' => 'boolean' ),
'proc_open_available' => array( 'type' => 'boolean' ),
'git_path' => array( 'type' => 'string' ),
'remediation' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getCapabilities' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-show',
array(
'label' => 'Show Workspace Repo',
'description' => 'Show detailed info about a workspace repository (branch, remote, latest commit, dirty status, and primary freshness).',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` for primary checkout or `<repo>@<branch-slug>` for a worktree.',
),
),
'required' => array( 'name' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'repo' => array( 'type' => 'string' ),
'is_worktree' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
// Nullable: detached HEAD has no branch; local-only repos
// have no remote; freshly-init'd repos have no commit yet.
'branch' => array( 'type' => array( 'string', 'null' ) ),
'remote' => array( 'type' => array( 'string', 'null' ) ),
'commit' => array( 'type' => array( 'string', 'null' ) ),
'dirty' => array( 'type' => 'integer' ),
'primary_freshness' => self::primaryFreshnessSchema(),
),
),
'execute_callback' => array( self::class, 'showRepo' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
// -----------------------------------------------------------------
// File reading abilities (show_in_rest = true).
// -----------------------------------------------------------------
AbilityRegistry::register(
'datamachine-code/workspace-read',
array(
'label' => 'Read Workspace File',
'description' => 'Read the contents of a text file from a workspace repository.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'path' => array(
'type' => 'string',
'description' => 'Relative file path within the repo.',
),
'max_size' => array(
'type' => 'integer',
'description' => 'Maximum file size in bytes (default 1 MB).',
),
'offset' => array(
'type' => 'integer',
'description' => 'Line number to start reading from (1-indexed).',
),
'limit' => array(
'type' => 'integer',
'description' => 'Maximum number of lines to return.',
),
),
'required' => array( 'path' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'content' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'size' => array( 'type' => 'integer' ),
'lines_read' => array( 'type' => 'integer' ),
'offset' => array( 'type' => 'integer' ),
),
),
'execute_callback' => array( self::class, 'readFile' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-ls',
array(
'label' => 'List Workspace Directory',
'description' => 'List directory contents within a workspace repository.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'path' => array(
'type' => 'string',
'description' => 'Relative directory path within the repo (omit for root).',
),
),
'required' => array(),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'repo' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'entries' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'name' => array( 'type' => 'string' ),
'type' => array( 'type' => 'string' ),
'size' => array( 'type' => 'integer' ),
),
),
),
),
),
'execute_callback' => array( self::class, 'listDirectory' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-grep',
array(
'label' => 'Search Workspace Files',
'description' => 'Search text files within a workspace repository using a regular expression pattern.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'pattern' => array(
'type' => 'string',
'description' => 'Regular expression pattern to search for.',
),
'path' => array(
'type' => 'string',
'description' => 'Optional relative file or directory path to search within.',
),
'include' => array(
'type' => 'string',
'description' => 'Optional glob pattern to limit matching file paths.',
),
'max_results' => array(
'type' => 'integer',
'description' => 'Maximum number of matches to return (default 100, max 500).',
),
'context_lines' => array(
'type' => 'integer',
'description' => 'Number of surrounding lines to include for each match (default 0, max 10).',
),
),
'required' => array( 'pattern' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'repo' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'pattern' => array( 'type' => 'string' ),
'count' => array( 'type' => 'integer' ),
'truncated' => array( 'type' => 'boolean' ),
'matches' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'path' => array( 'type' => 'string' ),
'line' => array( 'type' => 'integer' ),
'text' => array( 'type' => 'string' ),
'context' => array( 'type' => 'array' ),
),
),
),
),
),
'execute_callback' => array( self::class, 'grepFiles' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
// -----------------------------------------------------------------
// Mutating abilities (show_in_rest = false, CLI-only).
// -----------------------------------------------------------------
AbilityRegistry::register(
'datamachine-code/workspace-clone',
array(
'label' => 'Clone Workspace Repo',
'description' => 'Clone a git repository into the workspace as a primary checkout only when no primary for that remote already exists. If the remote exists, refresh/reuse that primary and create a worktree via `workspace-worktree-add`.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'url' => array(
'type' => 'string',
'description' => 'Git repository URL to clone.',
),
'name' => array(
'type' => 'string',
'description' => 'Directory name override (derived from URL if omitted).',
),
'full' => array(
'type' => 'boolean',
'description' => 'Disable the default blobless partial clone for remote repositories.',
),
'auth_token_env' => array(
'type' => 'string',
'description' => 'Optional environment variable name containing a bearer token for HTTPS clone authentication.',
),
'allow_duplicate_remote' => array(
'type' => 'boolean',
'description' => 'Explicitly allow cloning a second top-level primary for a remote already present in the workspace. Default false; use only for deliberate release/proof checkouts.',
),
),
'required' => array( 'url' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'cloneRepo' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-context-repositories',
array(
'label' => 'Register Workspace Context Repositories',
'description' => 'Register read-only context repositories for the current workspace run. Context repositories are exposed through workspace read/list/grep tools with path allowlists and are rejected by mutating workspace operations.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'target_repo' => array( 'type' => 'string' ),
'target_workspace' => array( 'type' => 'string' ),
'access' => array(
'type' => 'string',
'enum' => array( 'readonly', 'read_only' ),
'description' => 'Context repositories are currently read-only.',
),
'repositories' => array(
'type' => 'array',
'description' => 'Read-only context repository specs. Each entry is { repo, ref, alias, paths }.',
),
),
'required' => array( 'repositories' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'access' => array( 'type' => 'string' ),
'count' => array( 'type' => 'integer' ),
'repositories' => array( 'type' => 'array' ),
),
),
'execute_callback' => array( self::class, 'registerContextRepositories' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-adopt',
array(
'label' => 'Adopt Workspace Repo',
'description' => 'Validate an existing git primary checkout already located under the workspace root so it can be managed by workspace commands.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'path' => array(
'type' => 'string',
'description' => 'Existing git primary checkout path under DATAMACHINE_WORKSPACE_PATH.',
),
'name' => array(
'type' => 'string',
'description' => 'Workspace name override (derived from path basename if omitted).',
),
),
'required' => array( 'path' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'already_adopted' => array( 'type' => 'boolean' ),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'adoptRepo' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-remove',
array(
'label' => 'Remove Workspace Repo',
'description' => 'Remove a workspace handle. Refuses to remove a primary that has linked worktrees.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
),
'required' => array( 'name' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'removeRepo' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-write',
array(
'label' => 'Write Workspace File',
'description' => 'Create or overwrite a file in a workspace repository.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'path' => array(
'type' => 'string',
'description' => 'Relative file path within the repo.',
),
'content' => array(
'type' => 'string',
'description' => 'File content to write.',
),
),
'required' => array( 'path', 'content' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
'size' => array( 'type' => 'integer' ),
'created' => array( 'type' => 'boolean' ),
),
),
'execute_callback' => array( self::class, 'writeFile' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-edit',
array(
'label' => 'Edit Workspace File',
'description' => 'Find-and-replace text in a workspace repository file.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'path' => array(
'type' => 'string',
'description' => 'Relative file path within the repo.',
),
'old_string' => array(
'type' => 'string',
'description' => 'Text to find.',
),
'new_string' => array(
'type' => 'string',
'description' => 'Replacement text.',
),
'search' => array(
'type' => 'string',
'description' => 'Alias for old_string.',
),
'replace' => array(
'type' => 'string',
'description' => 'Alias for new_string.',
),
'old' => array(
'type' => 'string',
'description' => 'Alias for old_string.',
),
'new' => array(
'type' => 'string',
'description' => 'Alias for new_string.',
),
'replace_all' => array(
'type' => 'boolean',
'description' => 'Replace all occurrences (default false).',
),
),
'required' => array( 'path' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
'replacements' => array( 'type' => 'integer' ),
),
),
'execute_callback' => array( self::class, 'editFile' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-apply-patch',
array(
'label' => 'Apply Workspace Patch',
'description' => 'Apply a unified diff to a workspace repository through git apply. Mutating ops on the primary checkout require allow_primary_mutation=true. The patch is checked before apply and fails closed on context mismatch.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'patch' => array(
'type' => 'string',
'description' => 'Unified diff content to apply.',
),
'allow_primary_mutation' => array(
'type' => 'boolean',
'description' => 'Permit mutation on the primary checkout (default false). Worktrees are always allowed.',
),
),
'required' => array( 'repo', 'patch' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'changed_files' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
),
'diff' => array( 'type' => 'string' ),
'status' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'applyPatch' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-status',
array(
'label' => 'Workspace Git Status',
'description' => 'Get git status information for a workspace handle (primary or worktree).',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
),
'required' => array(),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'repo' => array( 'type' => 'string' ),
'is_worktree' => array( 'type' => 'boolean' ),
'path' => array( 'type' => 'string' ),
// Nullable: detached HEAD has no branch; local-only repos
// have no remote; freshly-init'd repos have no commit yet.
'branch' => array( 'type' => array( 'string', 'null' ) ),
'remote' => array( 'type' => array( 'string', 'null' ) ),
'commit' => array( 'type' => array( 'string', 'null' ) ),
'dirty' => array( 'type' => 'integer' ),
'files' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
),
),
),
'execute_callback' => array( self::class, 'gitStatus' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-log',
array(
'label' => 'Workspace Git Log',
'description' => 'Read git log entries for a workspace handle.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'limit' => array(
'type' => 'integer',
'description' => 'Maximum log entries to return (1-100).',
),
),
'required' => array( 'name' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'entries' => array(
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'hash' => array( 'type' => 'string' ),
'author' => array( 'type' => 'string' ),
'date' => array( 'type' => 'string' ),
'subject' => array( 'type' => 'string' ),
),
),
),
),
),
'execute_callback' => array( self::class, 'gitLog' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-diff',
array(
'label' => 'Workspace Git Diff',
'description' => 'Read git diff output for a workspace handle.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'from' => array(
'type' => 'string',
'description' => 'Optional from git ref.',
),
'to' => array(
'type' => 'string',
'description' => 'Optional to git ref.',
),
'staged' => array(
'type' => 'boolean',
'description' => 'Read staged diff instead of working tree diff.',
),
'path' => array(
'type' => 'string',
'description' => 'Optional relative path filter.',
),
),
'required' => array( 'name' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'diff' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'gitDiff' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => true ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-pull',
array(
'label' => 'Workspace Git Pull',
'description' => 'Run git pull --ff-only for a workspace handle. Mutating ops on the primary checkout require allow_primary_mutation=true.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'allow_dirty' => array(
'type' => 'boolean',
'description' => 'Allow pull when working tree is dirty.',
),
'allow_primary_mutation' => array(
'type' => 'boolean',
'description' => 'Permit mutation on the primary checkout (default false). Worktrees are always allowed.',
),
),
'required' => array( 'name' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'gitPull' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-add',
array(
'label' => 'Workspace Git Add',
'description' => 'Stage repository paths with git add. Mutating ops on the primary checkout require allow_primary_mutation=true.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'paths' => array(
'type' => 'array',
'description' => 'Relative paths to stage.',
'items' => array( 'type' => 'string' ),
),
'allow_primary_mutation' => array(
'type' => 'boolean',
'description' => 'Permit mutation on the primary checkout (default false). Worktrees are always allowed.',
),
),
'required' => array( 'name', 'paths' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'paths' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'gitAdd' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-delete',
array(
'label' => 'Delete Workspace Path',
'description' => 'Delete a tracked or untracked file or directory from a workspace repository. Tracked paths are removed via git rm; untracked paths are unlinked from disk. Mutating ops on the primary checkout require allow_primary_mutation=true.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'path' => array(
'type' => 'string',
'description' => 'Relative path within the repo (file or directory).',
),
'recursive' => array(
'type' => 'boolean',
'description' => 'Required when target is a directory. Default false.',
),
'allow_primary_mutation' => array(
'type' => 'boolean',
'description' => 'Permit mutation on the primary checkout (default false). Worktrees are always allowed.',
),
),
'required' => array( 'path' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'repo' => array( 'type' => 'string' ),
'path' => array( 'type' => 'string' ),
'deleted' => array(
'type' => 'array',
'description' => 'Every relative path removed (recursive deletes report each entry).',
'items' => array( 'type' => 'string' ),
),
'was_tracked' => array(
'type' => 'boolean',
'description' => 'True when the path was removed via git rm; false for untracked filesystem deletes.',
),
),
),
'execute_callback' => array( self::class, 'deletePath' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-commit',
array(
'label' => 'Workspace Git Commit',
'description' => 'Commit staged changes in a workspace handle. Mutating ops on the primary checkout require allow_primary_mutation=true.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(
'type' => 'string',
'description' => 'Workspace handle: `<repo>` (primary) or `<repo>@<branch-slug>` (worktree).',
),
'message' => array(
'type' => 'string',
'description' => 'Commit message.',
),
'allow_primary_mutation' => array(
'type' => 'boolean',
'description' => 'Permit mutation on the primary checkout (default false). Worktrees are always allowed.',
),
),
'required' => array( 'name', 'message' ),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'name' => array( 'type' => 'string' ),
'commit' => array( 'type' => 'string' ),
'message' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'gitCommit' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/workspace-git-push',
array(
'label' => 'Workspace Git Push',
'description' => 'Push commits for a workspace handle. `fixed_branch` policy applies only to the primary checkout; worktrees may push any branch.',
'category' => 'datamachine-code-workspace',
'input_schema' => array(
'type' => 'object',
'properties' => array(
'name' => array(