Skip to content

Commit f28bf5d

Browse files
committed
feat(cli): add projects, runs and env set commands
Adds `projects create/get/rename/delete`, `runs list/get/replay/cancel` and `env set` to the CLI, all on top of endpoints that already exist. `projects` uses the personal access token client. `runs` uses the core `ApiClient` scoped to the project environment's secret key, via a new `getProjectEnvApiClient` helper that builds on `getProjectClient`. `env set` upserts through the env var import endpoint with `override: true`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018FdBUQs2td6uAPB4KGQxFB
1 parent 7e56062 commit f28bf5d

21 files changed

Lines changed: 1039 additions & 1 deletion

‎.changeset/lucky-runs-projects.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
New CLI commands: `projects create/get/rename/delete`, `runs list/get/replay/cancel`, and `env set`

‎docs/cli-env-commands.mdx‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "CLI env set command"
3+
sidebarTitle: "env set"
4+
description: "Use the env set command to create or update an environment variable."
5+
---
6+
7+
import CommonOptions from "/snippets/cli-options-common.mdx";
8+
import ConfigFileOptions from "/snippets/cli-options-config-file.mdx";
9+
import ProjectRefOptions from "/snippets/cli-options-project-ref.mdx";
10+
import BranchOptions from "/snippets/cli-options-branch.mdx";
11+
12+
Sets an environment variable on your project, creating it if it doesn't exist and overwriting the
13+
value if it does.
14+
15+
<CodeGroup>
16+
17+
```bash npm
18+
npx trigger.dev@latest env set MY_VAR my-value
19+
```
20+
21+
```bash pnpm
22+
pnpm dlx trigger.dev@latest env set MY_VAR my-value
23+
```
24+
25+
```bash yarn
26+
yarn dlx trigger.dev@latest env set MY_VAR my-value
27+
```
28+
29+
</CodeGroup>
30+
31+
## Arguments
32+
33+
```
34+
npx trigger.dev@latest env set <name> <value>
35+
```
36+
37+
<ParamField body="Name" type="<name>">
38+
The name of the environment variable.
39+
</ParamField>
40+
41+
<ParamField body="Value" type="<value>">
42+
The value to set.
43+
</ParamField>
44+
45+
## Options
46+
47+
<ParamField body="Secret" type="--secret">
48+
Store the value as a secret, so it can't be read back.
49+
</ParamField>
50+
51+
<ParamField body="Environment" type="--env | -e">
52+
The environment to set the variable in: `prod`, `staging` or `preview`. Defaults to `prod`.
53+
</ParamField>
54+
55+
<ConfigFileOptions />
56+
<ProjectRefOptions />
57+
<BranchOptions />
58+
59+
### Common options
60+
61+
These options are available on most commands.
62+
63+
<CommonOptions />

‎docs/cli-projects-commands.mdx‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "CLI projects commands"
3+
sidebarTitle: "projects"
4+
description: "Use these commands to create, inspect, rename and delete your Trigger.dev projects."
5+
---
6+
7+
import CommonOptions from "/snippets/cli-options-common.mdx";
8+
9+
These commands act on the organizations and projects your account can access, so run
10+
[`login`](/cli-login-commands) first.
11+
12+
## projects create
13+
14+
Creates a project. You are prompted for the organization and name when the options are omitted.
15+
16+
<CodeGroup>
17+
18+
```bash npm
19+
npx trigger.dev@latest projects create
20+
```
21+
22+
```bash pnpm
23+
pnpm dlx trigger.dev@latest projects create
24+
```
25+
26+
```bash yarn
27+
yarn dlx trigger.dev@latest projects create
28+
```
29+
30+
</CodeGroup>
31+
32+
<ParamField body="Organization" type="--org | -o">
33+
The organization slug or ID to create the project in.
34+
</ParamField>
35+
36+
<ParamField body="Name" type="--name | -n">
37+
The name of the new project.
38+
</ParamField>
39+
40+
## projects get
41+
42+
Prints the name, ref, slug, organization, default runtime and region of a project.
43+
44+
```bash
45+
npx trigger.dev@latest projects get proj_abc123
46+
```
47+
48+
## projects rename
49+
50+
Renames a project. The project ref does not change.
51+
52+
```bash
53+
npx trigger.dev@latest projects rename proj_abc123 "My new name"
54+
```
55+
56+
## projects delete
57+
58+
Deletes a project and everything in it. You are asked to confirm first.
59+
60+
```bash
61+
npx trigger.dev@latest projects delete proj_abc123
62+
```
63+
64+
<ParamField body="Skip confirmation" type="--yes | -y">
65+
Delete without the confirmation prompt. Required in non-interactive environments such as CI.
66+
</ParamField>
67+
68+
## Options
69+
70+
### Common options
71+
72+
These options are available on most commands.
73+
74+
<CommonOptions />

‎docs/cli-runs-commands.mdx‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: "CLI runs commands"
3+
sidebarTitle: "runs"
4+
description: "Use these commands to list, inspect, replay and cancel runs from your terminal."
5+
---
6+
7+
import CommonOptions from "/snippets/cli-options-common.mdx";
8+
import ConfigFileOptions from "/snippets/cli-options-config-file.mdx";
9+
import ProjectRefOptions from "/snippets/cli-options-project-ref.mdx";
10+
import BranchOptions from "/snippets/cli-options-branch.mdx";
11+
12+
## runs list
13+
14+
Lists runs, newest first, in a table of ID, task, status, version, created time and duration.
15+
16+
<CodeGroup>
17+
18+
```bash npm
19+
npx trigger.dev@latest runs list
20+
```
21+
22+
```bash pnpm
23+
pnpm dlx trigger.dev@latest runs list
24+
```
25+
26+
```bash yarn
27+
yarn dlx trigger.dev@latest runs list
28+
```
29+
30+
</CodeGroup>
31+
32+
<ParamField body="Limit" type="--limit">
33+
The number of runs to list, up to 100. Defaults to 20.
34+
</ParamField>
35+
36+
<ParamField body="Status" type="--status">
37+
Only show runs with this status, e.g. `FAILED`.
38+
</ParamField>
39+
40+
<ParamField body="Task" type="--task">
41+
Only show runs for this task identifier.
42+
</ParamField>
43+
44+
<ParamField body="Tag" type="--tag">
45+
Only show runs with this tag.
46+
</ParamField>
47+
48+
<ParamField body="Cursor" type="--cursor">
49+
The pagination cursor printed at the end of the previous page.
50+
</ParamField>
51+
52+
## runs get
53+
54+
Prints the status, version, tags, timings, duration, cost and error of a single run.
55+
56+
```bash
57+
npx trigger.dev@latest runs get run_abc123
58+
```
59+
60+
## runs replay
61+
62+
Triggers a new run with the same payload as an existing one, using the latest version of the task.
63+
64+
```bash
65+
npx trigger.dev@latest runs replay run_abc123
66+
```
67+
68+
## runs cancel
69+
70+
Cancels a run that has not finished yet.
71+
72+
```bash
73+
npx trigger.dev@latest runs cancel run_abc123
74+
```
75+
76+
## Options
77+
78+
<ParamField body="Environment" type="--env | -e">
79+
The environment to use: `dev`, `prod`, `staging` or `preview`. Defaults to `prod`.
80+
</ParamField>
81+
82+
<ConfigFileOptions />
83+
<ProjectRefOptions />
84+
<BranchOptions />
85+
86+
### Common options
87+
88+
These options are available on most commands.
89+
90+
<CommonOptions />

‎docs/docs.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,15 @@
245245
"pages": [
246246
"cli-deploy-commands",
247247
"cli-dev-commands",
248+
"cli-env-commands",
248249
"cli-init-commands",
249250
"cli-list-profiles-commands",
250251
"cli-login-commands",
251252
"cli-logout-commands",
252253
"cli-preview-archive",
254+
"cli-projects-commands",
253255
"cli-promote-commands",
256+
"cli-runs-commands",
254257
"cli-switch",
255258
"cli-update-commands",
256259
"cli-whoami-commands"

‎packages/cli-v3/src/apiClient.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ const MarkProjectInitializedResponseBody = z.object({
110110
initializedAt: z.string().nullable(),
111111
});
112112

113+
const RenameProjectResponseBody = z.object({
114+
id: z.string(),
115+
name: z.string(),
116+
});
117+
118+
const DeleteProjectResponseBody = z.object({
119+
id: z.string(),
120+
});
121+
113122
export class CliApiClient {
114123
private engineURL: string;
115124
private source: "cli" | "mcp";
@@ -258,6 +267,29 @@ export class CliApiClient {
258267
});
259268
}
260269

270+
async renameProject(projectRef: string, body: { name: string }) {
271+
if (!this.accessToken) {
272+
throw new Error("renameProject: No access token");
273+
}
274+
275+
return wrapZodFetch(RenameProjectResponseBody, `${this.apiURL}/api/v1/projects/${projectRef}`, {
276+
method: "PATCH",
277+
headers: this.getHeaders(),
278+
body: JSON.stringify(body),
279+
});
280+
}
281+
282+
async deleteProject(projectRef: string) {
283+
if (!this.accessToken) {
284+
throw new Error("deleteProject: No access token");
285+
}
286+
287+
return wrapZodFetch(DeleteProjectResponseBody, `${this.apiURL}/api/v1/projects/${projectRef}`, {
288+
method: "DELETE",
289+
headers: this.getHeaders(),
290+
});
291+
}
292+
261293
async getWorkerByTag(projectRef: string, envName: string, tagName: string = "current") {
262294
if (!this.accessToken) {
263295
throw new Error("getWorkerByTag: No access token");

‎packages/cli-v3/src/cli/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { configureLogoutCommand } from "../commands/logout.js";
1010
import { configurePreviewCommand } from "../commands/preview.js";
1111
import { configureProjectsCommand } from "../commands/projects/index.js";
1212
import { configurePromoteCommand } from "../commands/promote.js";
13+
import { configureRunsCommand } from "../commands/runs/index.js";
1314
import { configureSwitchProfilesCommand } from "../commands/switch.js";
1415
import { configureUpdateCommand } from "../commands/update.js";
1516
import { configureWhoamiCommand } from "../commands/whoami.js";
@@ -43,6 +44,7 @@ configureSwitchProfilesCommand(program);
4344
configureUpdateCommand(program);
4445
configurePreviewCommand(program);
4546
configureProjectsCommand(program);
47+
configureRunsCommand(program);
4648
configureAnalyzeCommand(program);
4749
configureMcpCommand(program);
4850
configureReportCommand(program);

0 commit comments

Comments
 (0)