Repository navigation
Expand file tree
/
Copy pathcmd.ts
More file actions
1006 lines (996 loc) · 37.4 KB
/
Copy pathcmd.ts
File metadata and controls
1006 lines (996 loc) · 37.4 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
import { Model } from "@codeworksh/aikit";
import { Schema } from "effect";
import { Argument, Flag } from "effect/cli";
import * as Spec from "../../framework/spec.ts";
/**
* The full command surface of the `codework` CLI. Declarations only -- each
* command's behaviour lives in `./handlers`, wired up in `src/index.ts`.
*/
const thinkingLevels = Object.values(Model.ThinkingLevelEnum);
/**
* Every `auth` subcommand answers the same three questions: which provider,
* whose credentials, and where they live. Only `login` needs anything more.
*/
const AuthParams = {
openaiCodex: Flag.Boolean("openai-codex").pipe(
Flag.withDescription("Use OpenAI Codex OAuth"),
Flag.withDefault(false),
),
githubCopilot: Flag.Boolean("github-copilot").pipe(
Flag.withDescription("Use GitHub Copilot OAuth (device flow)"),
Flag.withDefault(false),
),
server: Flag.String("server").pipe(Flag.withDescription("RPC server URL (ws://host:port/rpc/v1)"), Flag.optional),
authFile: Flag.String("auth-file").pipe(
Flag.withDescription("Credential file (defaults to <home>/aikit/auth.json)"),
Flag.optional,
),
};
/** Where the background server binds when `service` has to start one. */
const ServerAddress = {
host: Flag.String("host").pipe(
Flag.withDescription("Host interface the background server binds"),
Flag.withDefault("127.0.0.1"),
),
port: Flag.Int("port").pipe(
Flag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),
Flag.withDescription("Port the background server listens on"),
Flag.withDefault(7433),
),
};
/** For commands that only talk to a server that is already running. */
const RunningServer = Flag.String("server").pipe(
Flag.withDescription("RPC server URL (defaults to this home's server)"),
Flag.optional,
);
/** A thread's MCP server in a running server: every thread sharing its instance is affected. */
const McpControlParams = {
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
session: Flag.String("session").pipe(Flag.withAlias("s"), Flag.withDescription("The session")),
thread: Flag.String("thread").pipe(
Flag.withDescription("Thread of --session whose server it is: a thread ID, or main (default)"),
Flag.optional,
),
server: RunningServer,
};
/**
* The soft layer an MCP command acts on, on this home's server: This Session with --session, else
* Project Settings of --project or of the project this directory is in.
*/
const McpLayerTarget = {
session: Flag.String("session").pipe(
Flag.withAlias("s"),
Flag.withDescription("Act on This Session of this session instead of Project Settings"),
Flag.optional,
),
project: Flag.String("project").pipe(
Flag.withDescription("Project ID (default: the project of this directory)"),
Flag.optional,
),
server: RunningServer,
};
const McpSlot = Argument.String("slot").pipe(
Argument.withDescription("A connector id for a connector server, else the server name"),
);
const McpConnector = Argument.String("connector").pipe(Argument.withDescription("Connector id, e.g. app.linear"));
const JsonFlag = Flag.Boolean("json").pipe(
Flag.withDescription("Print machine-readable output"),
Flag.withDefault(false),
);
export const Cmd = Spec.make("codework", {
description: "CodeWork Command Line Interface",
shared: {
userConfigDir: Flag.String("user-config-dir").pipe(
Flag.withDescription("Directory whose settings.jsonc replaces the user settings in --home"),
Flag.optional,
),
home: Flag.String("home").pipe(
Flag.withDescription("CodeWork home: user settings, credentials, cache and data (default: ~/.codework)"),
Flag.optional,
),
database: Flag.String("database").pipe(Flag.withDescription("SQLite database path or :memory:"), Flag.optional),
},
commands: [
Spec.make("auth", {
description: "Manage OAuth credentials",
commands: [
Spec.make("login", {
description: "Sign in to a provider",
params: {
...AuthParams,
browser: Flag.Boolean("browser").pipe(
Flag.withDescription("Open the authorization URL in the default browser"),
Flag.withDefault(true),
),
device: Flag.Boolean("device").pipe(
Flag.withDescription("Use the device-code flow instead of a localhost browser callback"),
Flag.withDefault(false),
),
enterprise: Flag.String("enterprise").pipe(
Flag.withDescription("GitHub Enterprise domain for GitHub Copilot login"),
Flag.optional,
),
enableModels: Flag.Boolean("enable-models").pipe(
Flag.withDescription("Enable unconfigured Copilot catalog models after login"),
Flag.withDefault(false),
),
json: JsonFlag,
},
examples: [
{ command: "codework auth login --openai-codex", description: "Sign in with ChatGPT" },
{ command: "codework auth login --github-copilot", description: "Sign in with GitHub Copilot" },
{
command: "codework auth login --openai-codex --device",
description: "Sign in with a device code, no local port",
},
{
command: "codework auth login --openai-codex --server ws://127.0.0.1:7433/rpc/v1",
description: "Sign in the running server",
},
],
}),
Spec.make("status", {
description: "Show a stored login without refreshing it",
params: { ...AuthParams, json: JsonFlag },
examples: [{ command: "codework auth status --openai-codex", description: "Show the stored login" }],
}),
Spec.make("refresh", {
description: "Refresh a stored login if it has expired",
params: { ...AuthParams, json: JsonFlag },
examples: [{ command: "codework auth refresh --openai-codex", description: "Renew an expired login" }],
}),
Spec.make("logout", {
description: "Clear a stored login",
params: AuthParams,
examples: [{ command: "codework auth logout --github-copilot", description: "Clear the stored login" }],
}),
],
}),
Spec.make("mcp", {
description: "Manage MCP servers",
commands: [
Spec.make("add", {
description: "Add or replace a server in mcp.json",
params: {
name: Argument.String("name").pipe(Argument.withDescription("Server name")),
command: Argument.String("command").pipe(
Argument.withDescription("Command and arguments of a stdio server, after --"),
Argument.variadic({ min: 0 }),
),
url: Flag.String("url").pipe(
Flag.withDescription("Streamable HTTP server URL (instead of a command)"),
Flag.optional,
),
connector: Flag.String("connector").pipe(
Flag.withDescription(
"Catalog connector id, run on your stored connection (instead of a url or command)",
),
Flag.optional,
),
env: Flag.KeyValuePair("env").pipe(
Flag.withDescription("Environment variable of a stdio server, as KEY=VALUE"),
Flag.optional,
),
cwd: Flag.String("cwd").pipe(
Flag.withDescription("Working directory of a stdio server"),
Flag.optional,
),
header: Flag.KeyValuePair("header").pipe(
Flag.withDescription("HTTP header, as KEY=VALUE"),
Flag.optional,
),
bearerTokenEnvVar: Flag.String("bearer-token-env-var").pipe(
Flag.withDescription('Send "Authorization: Bearer ${NAME}"'),
Flag.optional,
),
oauthClientId: Flag.String("oauth-client-id").pipe(
Flag.withDescription("Pre-registered OAuth client id"),
Flag.optional,
),
oauthClientSecret: Flag.String("oauth-client-secret").pipe(
Flag.withDescription("OAuth client secret (may be ${NAME} or !command)"),
Flag.optional,
),
oauthCallbackPort: Flag.Int("oauth-callback-port").pipe(
Flag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }))),
Flag.withDescription("Fixed OAuth callback port"),
Flag.optional,
),
oauthClientName: Flag.String("oauth-client-name").pipe(
Flag.withDescription("Client name sent when registering with the OAuth server"),
Flag.optional,
),
exposure: Flag.Literals("exposure", ["direct", "hidden", "codemode", "deferred"]).pipe(
Flag.withDescription("How the model reaches the server's tools (default: direct)"),
Flag.optional,
),
description: Flag.String("description").pipe(
Flag.withDescription("What the server offers"),
Flag.optional,
),
local: Flag.Boolean("local").pipe(
Flag.withAlias("l"),
Flag.withDescription("Write the project's .codework/mcp.json instead of the user one"),
Flag.withDefault(false),
),
},
examples: [
{
command: "codework mcp add fs -- npx -y @modelcontextprotocol/server-filesystem .",
description: "Add a stdio server",
},
{
command: "codework mcp add linear --url https://mcp.linear.app/mcp",
description: "Add an HTTP server; sign in with codework mcp login linear",
},
{
command: "codework mcp add tools -l --url http://127.0.0.1:8080/mcp",
description: "Add a server to this project only",
},
{
command: "codework mcp add linear --connector app.linear",
description: "Add a catalog connector; it runs on your app.linear connection",
},
],
}),
Spec.make("remove", {
description: "Remove a server from mcp.json",
params: {
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
local: Flag.Boolean("local").pipe(
Flag.withAlias("l"),
Flag.withDescription("Remove it from the project's .codework/mcp.json instead of the user one"),
Flag.withDefault(false),
),
},
examples: [{ command: "codework mcp remove linear", description: "Remove the linear server" }],
}),
Spec.make("list", {
description: "Connect to every enabled server and show its state, tools and errors",
params: { json: JsonFlag },
examples: [
{ command: "codework mcp list", description: "Check every configured server; exits 1 on a failure" },
],
}),
Spec.make("login", {
description: "Sign in to an MCP server with OAuth",
params: {
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
browser: Flag.Boolean("browser").pipe(
Flag.withDescription("Open the authorization URL in the default browser"),
Flag.withDefault(true),
),
timeout: Flag.Int("timeout").pipe(
Flag.withSchema(Schema.Int.check(Schema.isGreaterThan(0))),
Flag.withDescription("Seconds the whole sign-in may take"),
Flag.withDefault(300),
),
},
examples: [
{ command: "codework mcp login linear", description: "Sign in to the linear server" },
{
command: "codework mcp login linear --browser=false",
description: "Print the URL; paste the redirected URL back if the browser is elsewhere",
},
],
}),
Spec.make("logout", {
description: "Remove the stored OAuth credentials of an MCP server",
params: {
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
},
examples: [{ command: "codework mcp logout linear", description: "Sign out of the linear server" }],
}),
Spec.make("reconnect", {
description: "Connect a thread's MCP server afresh in a running server",
params: McpControlParams,
examples: [
{
command: "codework mcp reconnect linear --session ses_01h9",
description: "Restart the linear server the main thread uses; its tools return from the next turn",
},
{
command: "codework mcp reconnect linear --session ses_01h9 --thread thr_01ja",
description: "Restart the one a thread of the session uses",
},
],
}),
Spec.make("disconnect", {
description: "Close a thread's MCP server in a running server until it is reconnected",
params: McpControlParams,
examples: [
{
command: "codework mcp disconnect linear --session ses_01h9",
description: "Close the linear server the main thread uses",
},
],
}),
Spec.make("view", {
description: "Show Project Settings, and with --session This Session, as the server resolves them",
params: { ...McpLayerTarget, json: JsonFlag },
examples: [
{ command: "codework mcp view", description: "Project Settings of this directory's project" },
{ command: "codework mcp view --session ses_01h9", description: "This Session over its project's" },
],
}),
Spec.make("off", {
description: "Switch a server off in Project Settings, or in This Session with --session",
params: { slot: McpSlot, ...McpLayerTarget },
examples: [
{
command: "codework mcp off app.linear",
description: "Switch the Linear connector off for this project",
},
{
command: "codework mcp off fs --session ses_01h9",
description: "Switch the fs server off in one session",
},
],
}),
Spec.make("on", {
description: "Switch back on a server this layer switched off",
params: { slot: McpSlot, ...McpLayerTarget },
examples: [{ command: "codework mcp on app.linear", description: "Undo this project's off" }],
}),
Spec.make("attach", {
description: "Add a connector no mcp.json names to Project Settings, or This Session with --session",
params: {
connector: McpConnector,
account: Flag.String("account").pipe(
Flag.withDescription("Connection uid to run it on (default: the layer's account)"),
Flag.optional,
),
...McpLayerTarget,
},
examples: [
{ command: "codework mcp attach app.linear", description: "Add Linear to this project" },
{
command: "codework mcp attach app.linear --account app.linear/side --session ses_01h9",
description: "Add it to one session on another account",
},
],
}),
Spec.make("detach", {
description: "Remove a connector this layer attached",
params: { connector: McpConnector, ...McpLayerTarget },
examples: [
{ command: "codework mcp detach app.linear", description: "Remove Linear from this project" },
],
}),
Spec.make("account", {
description: "Pick the connection a connector runs on in this layer",
params: {
connector: McpConnector,
uid: Argument.String("uid").pipe(Argument.withDescription("Connection uid, e.g. app.linear/side")),
...McpLayerTarget,
},
examples: [
{
command: "codework mcp account app.linear app.linear/side",
description: "Run Linear on the side account for this project",
},
],
}),
Spec.make("reset", {
description: "Drop this layer's off and account pick for a server",
params: { slot: McpSlot, ...McpLayerTarget },
examples: [{ command: "codework mcp reset app.linear", description: "Follow the layer below again" }],
}),
],
}),
Spec.make("run", {
description: "Start or continue an agent session",
params: {
server: Flag.String("server").pipe(
Flag.withDescription("RPC server URL (ws://host:port/rpc/v1)"),
Flag.optional,
),
prompt: Argument.String("prompt").pipe(Argument.withDescription("Prompt for the agent")),
session: Flag.String("session").pipe(
Flag.withAlias("s"),
Flag.withDescription("Continue an existing session"),
Flag.optional,
),
thread: Flag.String("thread").pipe(
Flag.withDescription("Thread of --session to continue: a thread ID, or main (default)"),
Flag.optional,
),
cwd: Flag.String("cwd").pipe(
Flag.withAlias("C"),
Flag.withDescription("Working directory for a new session"),
Flag.optional,
),
sandboxDriver: Flag.String("sandbox-driver").pipe(
Flag.withDescription("Sandbox driver for a new session (default: local)"),
Flag.optional,
),
sandboxId: Flag.String("sandbox-id").pipe(
Flag.withDescription("Reuse an existing sandbox instance"),
Flag.optional,
),
sandboxProviderId: Flag.String("sandbox-provider-id").pipe(
Flag.withDescription("Provider ID of an existing remote sandbox"),
Flag.optional,
),
provider: Flag.String("provider").pipe(Flag.withDescription("Model catalog provider ID"), Flag.optional),
model: Flag.String("model").pipe(Flag.withDescription("Model ID"), Flag.optional),
thinking: Flag.Literals("thinking", thinkingLevels).pipe(
Flag.withDescription("Reasoning effort the model uses before answering"),
Flag.optional,
),
},
examples: [
{ command: 'codework run "Inspect the failing tests"', description: "Create a session" },
{
command: 'codework run --provider openai --model gpt-5.5 --thinking high "Inspect the failing tests"',
description: "Create a session with an explicit model",
},
{
command: 'codework run --sandbox-driver daytona "Inspect the repository"',
description: "Create a Daytona sandbox and session",
},
{
command: 'codework run --sandbox-driver daytona --sandbox-provider-id <id> "Inspect the repository"',
description: "Use an existing remote sandbox",
},
{
command: 'codework run --session <id> --provider openai --model gpt-5.6-luna "Now fix them"',
description: "Continue a session with explicit model bindings",
},
{
command: 'codework run --session <id> --thread <thread-id> "Try OAuth instead"',
description: "Continue one of the session's threads",
},
],
}),
Spec.make("connect", {
description: "Connect this machine to a workspace, or manage external Connectors & Connections",
params: {
workspace: Flag.String("workspace").pipe(
Flag.withDescription("Workspace to connect to; otherwise the approver picks it"),
Flag.optional,
),
machineId: Flag.String("machine-id").pipe(
Flag.withDescription("Set this home's machine id instead of generating one, e.g. build-box-1"),
Flag.optional,
),
},
examples: [
{ command: "codework connect", description: "Show a code to approve in the CodeWork app" },
{
command: "codework connect --machine-id build-box-1",
description: "Connect with a fixed id, replacing a rebuilt machine's old link",
},
{ command: "codework connect discover", description: "Browse available Connectors in the catalog" },
{
command: "codework connect create app.linear",
description: "Create and authorize a Linear MCP connection",
},
],
commands: [
Spec.make("discover", {
description: "Browse available Connectors in the catalog",
params: {
query: Argument.String("query").pipe(
Argument.withDescription("Optional search query"),
Argument.optional,
),
kind: Flag.Literals("kind", ["provider", "mcp", "integration"]).pipe(
Flag.withDescription("Filter by page group: provider, mcp, or integration"),
Flag.optional,
),
category: Flag.String("category").pipe(
Flag.withDescription("Filter by category slug (e.g. ai, developer, productivity)"),
Flag.optional,
),
refresh: Flag.Boolean("refresh").pipe(
Flag.withDescription("Fetch the latest catalog from catalog.codework.sh"),
Flag.withDefault(false),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect discover", description: "List all catalog connectors" },
{ command: "codework connect discover --kind mcp", description: "List MCP connectors" },
],
}),
Spec.make("categories", {
description: "List connector catalog categories",
params: {
server: RunningServer,
json: JsonFlag,
},
examples: [{ command: "codework connect categories", description: "Show available categories" }],
}),
Spec.make("create", {
description: "Create a workspace Connection from a catalog Connector",
params: {
connector: Argument.String("connector").pipe(
Argument.withDescription(
"Connector reverse-DNS id or alias (e.g. app.linear, linear, com.anthropic)",
),
),
name: Flag.String("name").pipe(
Flag.withDescription("Connection slug within this workspace (default: default)"),
Flag.optional,
),
label: Flag.String("label").pipe(
Flag.withDescription("Display label shown in the UI"),
Flag.optional,
),
auth: Flag.Literals("auth", ["oauth", "apikey"]).pipe(
Flag.withDescription("Authentication method (oauth or apikey)"),
Flag.optional,
),
ownership: Flag.Literals("ownership", ["personal", "shared"]).pipe(
Flag.withDescription(
"Credential ownership: personal (default for oauth) or shared (default for apikey)",
),
Flag.optional,
),
apiKey: Flag.String("api-key").pipe(
Flag.withDescription("API key value (only for --auth apikey; omits interactive prompt)"),
Flag.optional,
),
device: Flag.Boolean("device").pipe(
Flag.withDescription("Use device-code OAuth flow when supported"),
Flag.withDefault(false),
),
enterprise: Flag.String("enterprise").pipe(
Flag.withDescription("GitHub Enterprise URL for GitHub Copilot"),
Flag.optional,
),
noAuth: Flag.Boolean("no-auth").pipe(
Flag.withDescription("Create the connection record without authenticating immediately"),
Flag.withDefault(false),
),
browser: Flag.Boolean("browser").pipe(
Flag.withDescription("Open the authorization URL in the default browser"),
Flag.withDefault(true),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect create app.linear", description: "Create and sign in to Linear MCP" },
{
command: "codework connect create com.anthropic --name work --auth apikey",
description: "Create a named Anthropic API key connection",
},
],
}),
Spec.make("login", {
description: "Authenticate or re-authenticate an existing Connection",
params: {
ref: Argument.String("ref").pipe(
Argument.withDescription("Connection uid (e.g. app.linear/default) or id"),
),
apiKey: Flag.String("api-key").pipe(
Flag.withDescription("API key value (for apikey connections)"),
Flag.optional,
),
device: Flag.Boolean("device").pipe(
Flag.withDescription("Use device-code OAuth flow when supported"),
Flag.withDefault(false),
),
enterprise: Flag.String("enterprise").pipe(
Flag.withDescription("GitHub Enterprise URL for GitHub Copilot"),
Flag.optional,
),
browser: Flag.Boolean("browser").pipe(
Flag.withDescription("Open the authorization URL in the default browser"),
Flag.withDefault(true),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect login app.linear/default", description: "Sign in to Linear MCP" },
],
}),
Spec.make("list", {
description: "List workspace Connections (including auto-detected host env)",
params: {
kind: Flag.Literals("kind", ["provider", "mcp", "integration"]).pipe(
Flag.withDescription("Filter by page group: provider, mcp, or integration"),
Flag.optional,
),
connector: Flag.String("connector").pipe(
Flag.withDescription("Filter by connector reverse-DNS id"),
Flag.optional,
),
includeEnv: Flag.Boolean("include-env").pipe(
Flag.withDescription("Include read-only auto-detected host env connections"),
Flag.withDefault(true),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect list", description: "List all connections in this workspace" },
{ command: "codework connect list --kind provider", description: "List LLM provider connections" },
],
}),
Spec.make("status", {
description: "Show status of a Connection without refreshing or printing secrets",
params: {
ref: Argument.String("ref").pipe(
Argument.withDescription("Connection uid (e.g. app.linear/default) or id"),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect status app.linear/default", description: "Show connection status" },
],
}),
Spec.make("disconnect", {
description: "Clear stored credentials for a Connection without deleting it",
params: {
ref: Argument.String("ref").pipe(
Argument.withDescription("Connection uid (e.g. app.linear/default) or id"),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{ command: "codework connect disconnect app.linear/default", description: "Sign out of Linear MCP" },
],
}),
Spec.make("remove", {
description: "Delete a Connection and all its stored credentials",
params: {
ref: Argument.String("ref").pipe(
Argument.withDescription("Connection uid (e.g. app.linear/default) or id"),
),
server: RunningServer,
json: JsonFlag,
},
examples: [
{
command: "codework connect remove app.linear/default",
description: "Delete the Linear MCP connection",
},
],
}),
],
}),
Spec.make("disconnect", {
description: "Disconnect this machine from a workspace",
params: {
workspace: Flag.String("workspace").pipe(
Flag.withDescription("Workspace to leave; optional when only one is connected"),
Flag.optional,
),
},
examples: [{ command: "codework disconnect", description: "Leave the only connected workspace" }],
}),
Spec.make("serve", {
description: "Start the CodeWork RPC server",
params: {
host: Flag.String("host").pipe(
Flag.withDescription("Host interface to bind"),
Flag.withDefault("127.0.0.1"),
),
port: Flag.Int("port").pipe(
Flag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),
Flag.withDescription("Port to listen on (0 for an ephemeral port)"),
Flag.withDefault(7433),
),
service: Flag.Boolean("service").pipe(
Flag.withDescription(
"Run as the background server `codework service` manages, logging to <home>/log/server.log",
),
Flag.withDefault(false),
),
trustedProxy: Flag.String("trusted-proxy").pipe(
Flag.withDescription(
"Address or CIDR range of a TLS proxy in front of the server, repeatable or comma-separated (default: CODEWORK_TRUSTED_PROXY, then server.trustedProxy in user settings)",
),
Flag.atLeast(0),
),
},
examples: [
{ command: "codework serve", description: "Start the RPC server on 127.0.0.1:7433" },
{ command: "codework serve --port 0", description: "Choose an available local port" },
{
command: "codework serve --host 0.0.0.0 --trusted-proxy 10.0.0.0/8",
description: "Believe X-Forwarded-Proto from a proxy in 10.0.0.0/8",
},
],
}),
Spec.make("service", {
description: "Manage the background server",
commands: [
Spec.make("start", { description: "Start the background server", params: ServerAddress }),
Spec.make("restart", { description: "Restart the background server", params: ServerAddress }),
Spec.make("status", { description: "Show background server status" }),
Spec.make("stop", { description: "Stop the background server" }),
Spec.make("pair", {
description: "Print a one-time code another computer pairs with, valid 10 minutes",
}),
Spec.make("devices", { description: "List paired devices" }),
Spec.make("revoke", {
description: "Unpair a device and end its connections",
params: { id: Argument.String("device-id").pipe(Argument.withDescription("The device to unpair")) },
}),
],
}),
Spec.make("session", {
description: "Manage sessions",
commands: [
Spec.make("link", {
description: "Anchor a session to a host directory",
params: {
session: Argument.String("session-id").pipe(Argument.withDescription("The session to link")),
path: Argument.String("path").pipe(
// The anchor is not a configuration mechanism, but `.codework` is the landmark
// a person recognises, so the help names it to make the directory concrete.
Argument.withDescription(
"Host directory to anchor to — typically the directory holding your .codework configuration; defaults to the shell's",
),
Argument.optional,
),
unlink: Flag.Boolean("unlink").pipe(
Flag.withDescription("Clear the anchor, leaving the session with no host directory"),
Flag.withDefault(false),
),
server: RunningServer,
},
examples: [
{
command: "codework session link ses_01h9",
description: "Link it to the directory you are standing in",
},
{
command: "codework session link ses_01h9 ~/work/api",
description: "Link it to a project elsewhere on this machine",
},
{
command: "codework session link ses_01h9 --unlink",
description: "Clear the anchor",
},
],
}),
Spec.make("relink", {
description: "Move where a session's work, or one thread's, happens",
params: {
session: Argument.String("session-id").pipe(Argument.withDescription("The session to move")),
thread: Flag.String("thread").pipe(
Flag.withDescription(
"Move only this thread: a thread ID, or main; omitted moves the session's default",
),
Flag.optional,
),
directory: Flag.String("directory").pipe(
Flag.withAlias("C"),
Flag.withDescription(
"Checkout to move into; the work keeps its position under it when that path exists there",
),
Flag.optional,
),
sandboxId: Flag.String("sandbox-id").pipe(
Flag.withDescription("Sandbox instance to move to (default: local)"),
Flag.optional,
),
json: JsonFlag,
server: RunningServer,
},
examples: [
{
command: "codework session relink ses_01h9 -C ~/work/api",
description: "Move the session to a local checkout",
},
{
command: "codework session relink ses_01h9 --thread thr_01ja --sandbox-id sbx_01k2",
description: "Run one thread in a sandbox, leaving the others where they are",
},
],
}),
],
}),
Spec.make("thread", {
description: "Manage a session's threads",
commands: [
Spec.make("list", {
description: "List a session's threads, newest first",
params: {
session: Argument.String("session-id").pipe(Argument.withDescription("The session")),
json: JsonFlag,
server: RunningServer,
},
examples: [{ command: "codework thread list ses_01h9", description: "List the session's threads" }],
}),
Spec.make("fork", {
description: "Start a new thread from a committed entry of a thread's history",
params: {
session: Argument.String("session-id").pipe(Argument.withDescription("The session")),
thread: Flag.String("thread").pipe(
Flag.withDescription("Thread to fork: a thread ID, or main (default)"),
Flag.optional,
),
at: Flag.String("at").pipe(Flag.withDescription("Keep history through this entry"), Flag.optional),
before: Flag.String("before").pipe(
Flag.withDescription("Keep history up to this user entry, and print its text to edit"),
Flag.optional,
),
json: JsonFlag,
server: RunningServer,
},
examples: [
{
command: "codework thread fork ses_01h9 --at 01jb",
description: "Continue the main thread's history through an entry in a new thread",
},
{
command: "codework thread fork ses_01h9 --thread thr_01ja --before 01jc",
description: "Branch just before a prompt, to send it again differently",
},
],
}),
],
}),
Spec.make("plugin", {
description: "Manage plugins",
commands: [
Spec.make("add", {
description: "Install a plugin and add it to a settings file",
params: {
package: Argument.String("package").pipe(
Argument.withDescription("Package spec, path, or file: URL"),
),
global: Flag.Boolean("global").pipe(
Flag.withAlias("g"),
Flag.withDescription("Write the user-wide settings file instead of this project's"),
Flag.withDefault(false),
),
session: Flag.String("session").pipe(
Flag.withDescription("Write the project a session is linked to, rather than this directory's"),
Flag.optional,
),
},
examples: [
{
description: "Install a published plugin into this project's settings",
},
{
command: "codework plugin add @acme/codework-tool-proc --session ses_01h9",
description: "Write the project that session is linked to, from anywhere",
},
{
command: "codework plugin add @acme/codework-tool-proc -g",
description: "Install it for every project this user runs",
},
],
}),
Spec.make("install", {
description: "Install every plugin the settings files name",
params: {},
examples: [
{
command: "codework plugin install",
description: "Materialise what a fresh checkout already declares",
},
],
}),
Spec.make("list", {
description: "List configured plugins and what each one resolved to",
params: {
verbose: Flag.Boolean("verbose").pipe(
Flag.withDescription("Show the message behind a failure, not only its reason"),
Flag.withDefault(false),
),
},
examples: [{ command: "codework plugin list", description: "Show every configured plugin" }],
}),
Spec.make("check", {
description: "Report which configured plugins have a newer revision available",
params: {
spec: Argument.String("spec").pipe(
Argument.withDescription("Only this configured plugin: a package name or spec, git spec, or path"),
Argument.optional,
),
// An answer is reused for an hour, which is right for a command someone may
// run repeatedly and wrong for the minute after they pushed a plugin. Without
// this there is no way to say "ask again", and `check` reports a moving branch
// as current while `update` — which always refreshes — moves it.
refresh: Flag.Boolean("refresh").pipe(
Flag.withDescription("Ask the remote again instead of reusing a recent answer"),
Flag.withDefault(false),
),
},
examples: [
{ command: "codework plugin check", description: "Ask the registry what has moved" },
{ command: "codework plugin check @acme/codework-tool-proc", description: "Ask about one plugin" },
{
command: "codework plugin check --refresh",
description: "Ignore the cached answer, after pushing a plugin",
},
],
}),
Spec.make("update", {
description: "Fetch a newer revision of every plugin that has one",
params: {
spec: Argument.String("spec").pipe(
Argument.withDescription("Only this configured plugin: a package name or spec, git spec, or path"),
Argument.optional,
),
},
examples: [
{ command: "codework plugin update", description: "Take whatever `check` found" },
{ command: "codework plugin update @acme/codework-tool-proc", description: "Update one plugin" },
],
}),
Spec.make("reload", {
description: "Re-import configured plugins in a running server",
params: {
server: RunningServer,
},
examples: [
{
command: "codework plugin reload",
description: "Pick up edits to a local plugin without restarting",
},
],
}),
Spec.make("remove", {
description: "Remove a plugin from a settings file",
params: {
package: Argument.String("package").pipe(
Argument.withDescription("Configured package spec, path, or plugin ID"),
),
global: Flag.Boolean("global").pipe(
Flag.withAlias("g"),
Flag.withDescription("Edit the user-wide settings file instead of this project's"),
Flag.withDefault(false),
),
},
examples: [
{
command: "codework plugin remove @acme/codework-tool-proc",
description: "Drop a plugin and any configuration written against it",
},
],
}),
],
}),
Spec.make("models", {
description: "List or refresh the model catalog",
params: {
provider: Flag.String("provider").pipe(Flag.withDescription("Model catalog provider ID"), Flag.optional),
},
examples: [
{ command: "codework models", description: "List all models from all providers" },
{
command: "codework models --provider openai",
description: "List models for a specific provider",
},
{ command: "codework models providers", description: "List all available provider IDs" },
],
commands: [
Spec.make("providers", {
description: "List available model providers in the catalog",
}),
Spec.make("refresh", {
description: "Download the model catalog into the home if it is stale",
params: {
force: Flag.Boolean("force").pipe(
Flag.withDescription("Download it even if it is still fresh"),
Flag.withDefault(false),
),
},
examples: [
{ command: "codework models refresh", description: "Refresh a catalog older than 15 minutes" },
{ command: "codework models refresh --force", description: "Download the catalog now" },
],
}),
],
}),