@cvr/linear 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -10
- package/bin/linear +0 -0
- package/package.json +25 -21
- package/skills/linear/SKILL.md +146 -0
- package/src/cli.ts +14 -0
- package/src/commands/api.ts +148 -0
- package/src/commands/auth.ts +46 -34
- package/src/commands/issue.ts +475 -201
- package/src/commands/project.ts +51 -0
- package/src/commands/team.ts +28 -5
- package/src/domain/Input.ts +55 -0
- package/src/domain/Linear.ts +134 -0
- package/src/lib/errors.ts +11 -18
- package/src/lib/flags.ts +5 -0
- package/src/lib/json.ts +5 -0
- package/src/main.ts +18 -30
- package/src/services/Config.ts +118 -129
- package/src/services/Linear.ts +421 -159
- package/tsconfig.json +67 -7
- package/src/services/Browser.ts +0 -23
- package/src/services/Stdin.ts +0 -34
package/README.md
CHANGED
|
@@ -28,13 +28,26 @@ linear auth whoami
|
|
|
28
28
|
linear issue list
|
|
29
29
|
|
|
30
30
|
# Start working on an issue
|
|
31
|
-
linear issue start ABC-123
|
|
31
|
+
linear issue start ABC-123 --dry-run
|
|
32
|
+
linear issue start ABC-123 --json
|
|
32
33
|
|
|
33
34
|
# View issue details
|
|
34
35
|
linear issue view ABC-123
|
|
35
36
|
|
|
36
|
-
#
|
|
37
|
-
linear issue
|
|
37
|
+
# Read one or many issues as JSON
|
|
38
|
+
linear issue view ABC-123 ABC-124 --json
|
|
39
|
+
|
|
40
|
+
# Include comments, sub-issues, and relations
|
|
41
|
+
linear issue view ABC-123 --comments --children --relations --json
|
|
42
|
+
|
|
43
|
+
# Create a new issue with prompts
|
|
44
|
+
linear issue create --interactive
|
|
45
|
+
|
|
46
|
+
# Non-interactive creation with validation
|
|
47
|
+
linear issue create --team ABC --title "Title" --project "Tech Debt" --dry-run
|
|
48
|
+
|
|
49
|
+
# List projects
|
|
50
|
+
linear project list --json
|
|
38
51
|
|
|
39
52
|
# List teams
|
|
40
53
|
linear team list
|
|
@@ -51,12 +64,13 @@ linear team list
|
|
|
51
64
|
|
|
52
65
|
### Issues
|
|
53
66
|
|
|
54
|
-
| Command | Description
|
|
55
|
-
| ------------------------- |
|
|
56
|
-
| `linear issue list` | List your assigned issues
|
|
57
|
-
| `linear issue view [id]` | View issue details
|
|
58
|
-
| `linear issue start [id]` | Start
|
|
59
|
-
| `linear issue create` | Create a new issue
|
|
67
|
+
| Command | Description |
|
|
68
|
+
| ------------------------- | --------------------------------------------------- |
|
|
69
|
+
| `linear issue list` | List your assigned issues |
|
|
70
|
+
| `linear issue view [id]` | View issue details; prompts require `--interactive` |
|
|
71
|
+
| `linear issue start [id]` | Start work, with `--dry-run` and `--json` support |
|
|
72
|
+
| `linear issue create` | Create a new issue |
|
|
73
|
+
| `linear issue comment ID` | Add a comment, with `--dry-run` support |
|
|
60
74
|
|
|
61
75
|
### Teams
|
|
62
76
|
|
|
@@ -64,6 +78,25 @@ linear team list
|
|
|
64
78
|
| ------------------ | -------------- |
|
|
65
79
|
| `linear team list` | List all teams |
|
|
66
80
|
|
|
81
|
+
### Projects and GraphQL
|
|
82
|
+
|
|
83
|
+
| Command | Description |
|
|
84
|
+
| ---------------------------- | ----------------------------------------------- |
|
|
85
|
+
| `linear project list --json` | List projects with stable machine-readable data |
|
|
86
|
+
| `linear api graphql` | Authenticated GraphQL escape hatch |
|
|
87
|
+
|
|
88
|
+
## Agent usage
|
|
89
|
+
|
|
90
|
+
- Add `--json` to reads; commands return stable JSON and meaningful exit codes.
|
|
91
|
+
- `issue view --json` always returns an array and accepts multiple identifiers or Linear issue URLs.
|
|
92
|
+
- Use `--comments`, `--children`, and `--relations` only when that context is needed.
|
|
93
|
+
- Run supported mutations with `--dry-run` before executing them.
|
|
94
|
+
- Prompts are opt-in with `--interactive`; missing agent inputs fail fast.
|
|
95
|
+
- Prefer typed commands. Use `linear api graphql` only for operations the typed CLI cannot express.
|
|
96
|
+
- Keep `--query-file` paths inside the current workspace; traversal and escaping symlinks are rejected.
|
|
97
|
+
- Raw GraphQL mutations require the explicit `--allow-mutation` flag.
|
|
98
|
+
- Never read or interpolate the token directly; the CLI owns authentication.
|
|
99
|
+
|
|
67
100
|
## Configuration
|
|
68
101
|
|
|
69
102
|
- **Token**: `~/.config/linear/token`
|
|
@@ -104,7 +137,7 @@ Built with:
|
|
|
104
137
|
|
|
105
138
|
- **[Bun](https://bun.sh)**: Fast JavaScript runtime with native compilation
|
|
106
139
|
- **[Effect](https://effect.website)**: TypeScript library for type-safe, composable code
|
|
107
|
-
- **[
|
|
140
|
+
- **[Effect CLI](https://github.com/Effect-TS/effect/tree/main/packages/effect/src/unstable/cli)**: CLI framework with prompts and argument parsing
|
|
108
141
|
- **[@linear/sdk](https://github.com/linear/linear)**: Official Linear GraphQL SDK
|
|
109
142
|
|
|
110
143
|
## Credits
|
package/bin/linear
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cvr/linear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cevr/linear-cli.git"
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"src",
|
|
13
|
+
"skills",
|
|
13
14
|
"tsconfig.json"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
@@ -22,34 +23,37 @@
|
|
|
22
23
|
"test": "vitest run",
|
|
23
24
|
"test:watch": "vitest",
|
|
24
25
|
"link": "ln -sf $(pwd)/bin/linear ~/.local/bin/linear",
|
|
25
|
-
"lint": "oxlint
|
|
26
|
+
"lint": "oxlint",
|
|
27
|
+
"lint:fix": "oxlint --fix",
|
|
26
28
|
"fmt": "oxfmt",
|
|
27
29
|
"fmt:check": "oxfmt --check",
|
|
28
|
-
"typecheck": "
|
|
29
|
-
"gate": "concurrently -n type,
|
|
30
|
-
"prepare": "lefthook install",
|
|
30
|
+
"typecheck": "tsgo --noEmit",
|
|
31
|
+
"gate": "concurrently -n type,style,build,test -c blue,yellow,cyan,green \"bun run typecheck\" \"bun run lint && bun run fmt:check\" \"bun run build\" \"bun run test\"",
|
|
32
|
+
"prepare": "lefthook install && effect-tsgo patch",
|
|
31
33
|
"version": "changeset version",
|
|
32
34
|
"release": "changeset publish"
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"@effect/
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
37
|
+
"@effect/platform-bun": "4.0.0-beta.98",
|
|
38
|
+
"@linear/sdk": "^88.2.0",
|
|
39
|
+
"effect": "4.0.0-beta.98",
|
|
40
|
+
"graphql": "^17.0.2",
|
|
41
|
+
"toml": "^5.0.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@changesets/changelog-github": "^0.
|
|
43
|
-
"@changesets/cli": "^2.
|
|
44
|
-
"@effect/
|
|
45
|
-
"@effect/vitest": "
|
|
46
|
-
"@types/bun": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
44
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
45
|
+
"@changesets/cli": "^2.31.1",
|
|
46
|
+
"@effect/tsgo": "^0.23.0",
|
|
47
|
+
"@effect/vitest": "4.0.0-beta.98",
|
|
48
|
+
"@types/bun": "^1.3.14",
|
|
49
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
50
|
+
"concurrently": "^10.0.3",
|
|
51
|
+
"lefthook": "^2.1.10",
|
|
52
|
+
"oxfmt": "^0.59.0",
|
|
53
|
+
"oxlint": "^1.74.0",
|
|
54
|
+
"oxlint-plugin-effect": "latest",
|
|
55
|
+
"typescript": "^7.0.2",
|
|
56
|
+
"vitest": "^4.1.10"
|
|
53
57
|
},
|
|
54
58
|
"engines": {
|
|
55
59
|
"bun": ">=1.0.0"
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: linear
|
|
3
|
+
description: Interact with Linear issues, comments, projects, teams, and GraphQL from the command line. Use for ticket context, bulk issue reads, starting work, or explicitly requested Linear mutations.
|
|
4
|
+
allowed-tools: [Bash]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Linear CLI
|
|
8
|
+
|
|
9
|
+
Use the `linear` CLI for Linear work. It owns authentication, stable JSON output, issue URL normalization, and actionable exit codes.
|
|
10
|
+
|
|
11
|
+
## Agent rules
|
|
12
|
+
|
|
13
|
+
1. Use typed commands before raw GraphQL.
|
|
14
|
+
2. Add `--json` to reads and parse the complete response. Do not truncate with `head` or `tail`.
|
|
15
|
+
3. Never read `~/.config/linear/token` directly and never put the token in `curl`, Python, logs, or shell history.
|
|
16
|
+
4. Treat issue identifiers and Linear issue URLs as equivalent inputs.
|
|
17
|
+
5. Do not mutate Linear unless the user explicitly requested the mutation.
|
|
18
|
+
6. For supported mutations, run `--dry-run` first, validate the result, then run the same command without `--dry-run`.
|
|
19
|
+
7. Use `linear api graphql` only when no typed command can express the operation. For GraphQL mutations, the user's request itself must explicitly authorize the write and the command must include `--allow-mutation`.
|
|
20
|
+
8. Trust exit codes: nonzero means the operation failed. Do not infer success from partial stdout.
|
|
21
|
+
9. Prompts are opt-in. Pass `--interactive` only when a human is present; otherwise provide every required input.
|
|
22
|
+
10. Keep `--query-file` inside the current workspace. The CLI rejects traversal and symlinks that escape it.
|
|
23
|
+
|
|
24
|
+
If `/linear` is invoked without an issue or task, run `linear issue list --json` and summarize the available work.
|
|
25
|
+
|
|
26
|
+
## Common reads
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
linear auth whoami --json
|
|
30
|
+
linear issue list --json
|
|
31
|
+
linear issue list --state started --limit 10 --json
|
|
32
|
+
linear team list --json
|
|
33
|
+
linear project list --json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Read one or many issues
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
linear issue view BITE-123 --json
|
|
40
|
+
linear issue view https://linear.app/acme/issue/BITE-123/slug --json
|
|
41
|
+
linear issue view BITE-123 BITE-124 BITE-125 --json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`issue view --json` always returns an array, including for one issue. Each item includes its ID, identifier, title, description, URL, branch name, priority, state, team, assignee, project, parent, and labels.
|
|
45
|
+
|
|
46
|
+
Request potentially larger relationships only when needed:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
linear issue view BITE-123 --children --json
|
|
50
|
+
linear issue view BITE-123 --comments --json
|
|
51
|
+
linear issue view BITE-123 --relations --json
|
|
52
|
+
linear issue view BITE-123 --children --comments --relations --json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Use the returned `branchName`; do not invent a branch name from the title.
|
|
56
|
+
|
|
57
|
+
## Mutations
|
|
58
|
+
|
|
59
|
+
### Start work
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
linear issue start BITE-123 --dry-run
|
|
63
|
+
linear issue start BITE-123 --json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The dry run resolves the issue and target state without updating Linear. The real command moves the issue to the team's started state and returns the Linear branch name. It does not create or check out a Git branch.
|
|
67
|
+
|
|
68
|
+
### Create an issue
|
|
69
|
+
|
|
70
|
+
Interactive:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
linear issue create --interactive
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Non-interactive agent flow:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
linear issue create \
|
|
80
|
+
--team BITE \
|
|
81
|
+
--title "Concise title" \
|
|
82
|
+
--description "Markdown description" \
|
|
83
|
+
--parent BITE-100 \
|
|
84
|
+
--project "Tech Debt" \
|
|
85
|
+
--priority 3 \
|
|
86
|
+
--dry-run
|
|
87
|
+
|
|
88
|
+
linear issue create \
|
|
89
|
+
--team BITE \
|
|
90
|
+
--title "Concise title" \
|
|
91
|
+
--description "Markdown description" \
|
|
92
|
+
--parent BITE-100 \
|
|
93
|
+
--project "Tech Debt" \
|
|
94
|
+
--priority 3 \
|
|
95
|
+
--json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`--team` accepts a team key or UUID. `--project` accepts a project name, slug, or UUID. `--parent` accepts an issue identifier or UUID. Priority is `0` through `4`.
|
|
99
|
+
|
|
100
|
+
### Add a comment
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
linear issue comment BITE-123 --body "Markdown comment" --dry-run
|
|
104
|
+
linear issue comment BITE-123 --body "Markdown comment" --json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Comments are external messages. Only send one when the user explicitly requested it.
|
|
108
|
+
|
|
109
|
+
## GraphQL escape hatch
|
|
110
|
+
|
|
111
|
+
Use this only when typed commands cannot express the operation:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
linear api graphql \
|
|
115
|
+
--query 'query Issue($id: String!) { issue(id: $id) { id identifier title } }' \
|
|
116
|
+
--variables '{"id":"BITE-123"}'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
For multiline documents, keep the query in a file:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
linear api graphql --query-file .linear/issue-query.graphql --variables '{"id":"BITE-123"}'
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The query file must resolve inside the current workspace. The command uses the configured credential and emits only the GraphQL `data` object as JSON. Keep variables separate from the query. Prefer one bulk GraphQL operation over shell loops when migrating a large issue tree.
|
|
126
|
+
|
|
127
|
+
Raw GraphQL mutations are rejected unless `--allow-mutation` is present. Add that flag only after verifying that the user explicitly authorized the write and inspecting the complete mutation document and variables.
|
|
128
|
+
|
|
129
|
+
## Authentication and configuration
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
linear auth
|
|
133
|
+
linear auth whoami --json
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Token resolution order:
|
|
137
|
+
|
|
138
|
+
1. `~/.config/linear/token`
|
|
139
|
+
2. `LINEAR_API_KEY`
|
|
140
|
+
3. Actionable authentication error
|
|
141
|
+
|
|
142
|
+
Project defaults live in `.linear.toml`:
|
|
143
|
+
|
|
144
|
+
```toml
|
|
145
|
+
team_id = "BITE"
|
|
146
|
+
```
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "effect/unstable/cli";
|
|
2
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
3
|
+
import { api } from "./commands/api.js";
|
|
4
|
+
import { auth } from "./commands/auth.js";
|
|
5
|
+
import { issue } from "./commands/issue.js";
|
|
6
|
+
import { project } from "./commands/project.js";
|
|
7
|
+
import { team } from "./commands/team.js";
|
|
8
|
+
|
|
9
|
+
export const linear = Command.make("linear").pipe(
|
|
10
|
+
Command.withDescription("Manage Linear issues, teams, projects, and authentication"),
|
|
11
|
+
Command.withSubcommands([auth, team, project, issue, api]),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const runCli = Command.runWith(linear, { version: packageJson.version });
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Console, Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
2
|
+
import { Command, Flag } from "effect/unstable/cli";
|
|
3
|
+
import { Kind } from "graphql/language/kinds.js";
|
|
4
|
+
import { parse } from "graphql/language/parser.js";
|
|
5
|
+
import { InvalidInputError } from "../lib/errors.js";
|
|
6
|
+
import { encodeJson } from "../lib/json.js";
|
|
7
|
+
import { LinearService } from "../services/Linear.js";
|
|
8
|
+
|
|
9
|
+
const queryOption = Flag.string("query").pipe(
|
|
10
|
+
Flag.withDescription("GraphQL document"),
|
|
11
|
+
Flag.optional,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const queryFileOption = Flag.string("query-file").pipe(
|
|
15
|
+
Flag.withDescription("Read the GraphQL document from a file"),
|
|
16
|
+
Flag.optional,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const variablesOption = Flag.string("variables").pipe(
|
|
20
|
+
Flag.withDescription("GraphQL variables as a JSON object"),
|
|
21
|
+
Flag.withDefault("{}"),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const allowMutationOption = Flag.boolean("allow-mutation").pipe(
|
|
25
|
+
Flag.withDescription("Explicitly authorize a raw GraphQL mutation"),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const VariablesJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
|
|
29
|
+
const decodeVariables = Schema.decodeUnknownEffect(VariablesJson);
|
|
30
|
+
const maximumInputLength = 1_000_000;
|
|
31
|
+
|
|
32
|
+
const containsMutation = Effect.fn("ApiCommand.containsMutation")(function* (document: string) {
|
|
33
|
+
const parsed = yield* Effect.try({
|
|
34
|
+
try: () => parse(document),
|
|
35
|
+
catch: (error) =>
|
|
36
|
+
InvalidInputError.make({ message: `Invalid GraphQL document: ${String(error)}` }),
|
|
37
|
+
});
|
|
38
|
+
return parsed.definitions.some(
|
|
39
|
+
(definition) =>
|
|
40
|
+
definition.kind === Kind.OPERATION_DEFINITION && definition.operation === "mutation",
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const readWorkspaceQueryFile = Effect.fn("ApiCommand.readWorkspaceQueryFile")(function* (
|
|
45
|
+
requestedPath: string,
|
|
46
|
+
) {
|
|
47
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
48
|
+
const path = yield* Path.Path;
|
|
49
|
+
const workspace = yield* fileSystem.realPath(path.resolve("."));
|
|
50
|
+
const queryFile = yield* fileSystem.realPath(path.resolve(requestedPath));
|
|
51
|
+
const relative = path.relative(workspace, queryFile);
|
|
52
|
+
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
53
|
+
return yield* InvalidInputError.make({
|
|
54
|
+
message: `--query-file must stay within the current workspace: ${requestedPath}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const document = yield* fileSystem.readFileString(queryFile);
|
|
58
|
+
if (document.length > maximumInputLength) {
|
|
59
|
+
return yield* InvalidInputError.make({
|
|
60
|
+
message: `GraphQL query files cannot exceed ${maximumInputLength} characters`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return document;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const graphqlCommand = Command.make(
|
|
67
|
+
"graphql",
|
|
68
|
+
{
|
|
69
|
+
query: queryOption,
|
|
70
|
+
queryFile: queryFileOption,
|
|
71
|
+
variables: variablesOption,
|
|
72
|
+
allowMutation: allowMutationOption,
|
|
73
|
+
},
|
|
74
|
+
({ query, queryFile, variables, allowMutation }) =>
|
|
75
|
+
Effect.gen(function* () {
|
|
76
|
+
if (Option.isSome(query) && Option.isSome(queryFile)) {
|
|
77
|
+
return yield* InvalidInputError.make({
|
|
78
|
+
message: "Use exactly one of --query or --query-file",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const document = yield* Option.match(query, {
|
|
83
|
+
onSome: Effect.succeed,
|
|
84
|
+
onNone: () =>
|
|
85
|
+
Option.match(queryFile, {
|
|
86
|
+
onNone: () =>
|
|
87
|
+
InvalidInputError.make({ message: "--query or --query-file is required" }),
|
|
88
|
+
onSome: (path) =>
|
|
89
|
+
readWorkspaceQueryFile(path).pipe(
|
|
90
|
+
Effect.mapError((error) =>
|
|
91
|
+
error._tag === "InvalidInputError"
|
|
92
|
+
? error
|
|
93
|
+
: InvalidInputError.make({
|
|
94
|
+
message: `Could not read GraphQL query file ${path}: ${error}`,
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
if (document.length > maximumInputLength) {
|
|
101
|
+
return yield* InvalidInputError.make({
|
|
102
|
+
message: `GraphQL documents cannot exceed ${maximumInputLength} characters`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (variables.length > maximumInputLength) {
|
|
106
|
+
return yield* InvalidInputError.make({
|
|
107
|
+
message: `--variables cannot exceed ${maximumInputLength} characters`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if ((yield* containsMutation(document)) && !allowMutation) {
|
|
111
|
+
return yield* InvalidInputError.make({
|
|
112
|
+
message:
|
|
113
|
+
"Raw GraphQL mutations require explicit authorization with --allow-mutation. Preview and inspect the document before retrying.",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const parsedVariables = yield* decodeVariables(variables).pipe(
|
|
117
|
+
Effect.mapError((error) =>
|
|
118
|
+
InvalidInputError.make({ message: `--variables must be a JSON object: ${error}` }),
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
const linear = yield* LinearService;
|
|
122
|
+
const data = yield* linear.rawQuery(document, parsedVariables);
|
|
123
|
+
yield* Console.log(encodeJson(data));
|
|
124
|
+
}),
|
|
125
|
+
).pipe(
|
|
126
|
+
Command.withDescription("Execute an authenticated Linear GraphQL operation"),
|
|
127
|
+
Command.withExamples([
|
|
128
|
+
{
|
|
129
|
+
command: 'linear api graphql --query "query { viewer { id name } }"',
|
|
130
|
+
description: "Run an inline GraphQL query",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
command: "linear api graphql --query-file query.graphql --variables '{}'",
|
|
134
|
+
description: "Run a GraphQL query from a file with variables",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
command: "linear api graphql --query-file mutation.graphql --allow-mutation",
|
|
138
|
+
description: "Explicitly authorize a raw GraphQL mutation",
|
|
139
|
+
},
|
|
140
|
+
]),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export const api = Command.make("api", {}, () =>
|
|
144
|
+
Console.log("Use 'linear api graphql' for GraphQL operations not covered by typed commands."),
|
|
145
|
+
).pipe(
|
|
146
|
+
Command.withDescription("Access the Linear GraphQL API"),
|
|
147
|
+
Command.withSubcommands([graphqlCommand]),
|
|
148
|
+
);
|
package/src/commands/auth.ts
CHANGED
|
@@ -1,70 +1,82 @@
|
|
|
1
|
-
import { Command } from "
|
|
1
|
+
import { Command, Prompt } from "effect/unstable/cli";
|
|
2
|
+
import { ChildProcess } from "effect/unstable/process";
|
|
2
3
|
import { Console, Effect } from "effect";
|
|
3
|
-
import {
|
|
4
|
+
import { jsonFlag } from "../lib/flags.js";
|
|
5
|
+
import { encodeJson } from "../lib/json.js";
|
|
4
6
|
import { LinearService } from "../services/Linear.js";
|
|
5
|
-
import { BrowserService } from "../services/Browser.js";
|
|
6
|
-
import { StdinService } from "../services/Stdin.js";
|
|
7
7
|
|
|
8
8
|
const LINEAR_API_KEY_URL = "https://linear.app/settings/account/security";
|
|
9
9
|
|
|
10
10
|
// linear auth - Interactive authentication flow
|
|
11
11
|
export const authCommand = Command.make("auth", {}, () =>
|
|
12
12
|
Effect.gen(function* () {
|
|
13
|
-
const browser = yield* BrowserService;
|
|
14
|
-
const config = yield* ConfigService;
|
|
15
|
-
const stdin = yield* StdinService;
|
|
16
|
-
|
|
17
13
|
yield* Console.log(`\nTo authenticate, you'll need a Linear API key.`);
|
|
18
14
|
yield* Console.log(`Opening: ${LINEAR_API_KEY_URL}\n`);
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
const browserOpened = yield* Effect.gen(function* () {
|
|
17
|
+
const process = yield* ChildProcess.make("open", [LINEAR_API_KEY_URL], {
|
|
18
|
+
stdout: "ignore",
|
|
19
|
+
stderr: "ignore",
|
|
20
|
+
});
|
|
21
|
+
return (yield* process.exitCode) === 0;
|
|
22
|
+
}).pipe(
|
|
23
|
+
Effect.scoped,
|
|
24
|
+
Effect.catch(() => Effect.succeed(false)),
|
|
25
|
+
);
|
|
26
|
+
if (!browserOpened) {
|
|
27
|
+
yield* Console.log(`Could not open browser. Please visit the URL manually.`);
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
const token = yield* stdin.readLine("Paste your API key: ");
|
|
30
|
+
const token = yield* Prompt.hidden({ message: "Paste your API key" });
|
|
31
31
|
|
|
32
32
|
// Validate token by making an API call
|
|
33
33
|
yield* Console.log("\nValidating token...");
|
|
34
34
|
|
|
35
|
-
// Save token first so LinearService can use it
|
|
36
|
-
yield* config.saveToken(token);
|
|
37
|
-
|
|
38
|
-
// Now validate with the saved token
|
|
39
35
|
const linear = yield* LinearService;
|
|
40
|
-
const viewer = yield* linear.
|
|
41
|
-
Effect.catchTag("InvalidTokenError", (e) =>
|
|
42
|
-
Effect.gen(function* () {
|
|
43
|
-
yield* Console.error(`\nError: ${e.message}`);
|
|
44
|
-
yield* Console.error("Please try again with a valid API key.");
|
|
45
|
-
return yield* Effect.die(e);
|
|
46
|
-
}),
|
|
47
|
-
),
|
|
48
|
-
);
|
|
36
|
+
const viewer = yield* linear.authenticate(token);
|
|
49
37
|
|
|
50
38
|
yield* Console.log(`\nAuthenticated as ${viewer.name} (${viewer.email})`);
|
|
51
39
|
}),
|
|
40
|
+
).pipe(
|
|
41
|
+
Command.withDescription("Authenticate with Linear"),
|
|
42
|
+
Command.withExamples([
|
|
43
|
+
{ command: "linear auth", description: "Authenticate using a Linear API key" },
|
|
44
|
+
]),
|
|
52
45
|
);
|
|
53
46
|
|
|
54
47
|
// linear auth whoami - Show current user
|
|
55
|
-
export const whoamiCommand = Command.make("whoami", {}, () =>
|
|
48
|
+
export const whoamiCommand = Command.make("whoami", { json: jsonFlag }, ({ json }) =>
|
|
56
49
|
Effect.gen(function* () {
|
|
57
50
|
const linear = yield* LinearService;
|
|
58
51
|
const viewer = yield* linear.getViewer;
|
|
59
52
|
|
|
53
|
+
if (json) {
|
|
54
|
+
yield* Console.log(
|
|
55
|
+
encodeJson({
|
|
56
|
+
id: viewer.id,
|
|
57
|
+
name: viewer.name,
|
|
58
|
+
email: viewer.email,
|
|
59
|
+
admin: viewer.admin,
|
|
60
|
+
status: viewer.status,
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
yield* Console.log(`\nLogged in as:`);
|
|
61
67
|
yield* Console.log(` Name: ${viewer.name}`);
|
|
62
68
|
yield* Console.log(` Email: ${viewer.email}`);
|
|
63
69
|
yield* Console.log(` Admin: ${viewer.admin ? "Yes" : "No"}`);
|
|
64
|
-
if (viewer.
|
|
65
|
-
yield* Console.log(` Status: ${viewer.
|
|
70
|
+
if (viewer.status?.label !== undefined) {
|
|
71
|
+
yield* Console.log(` Status: ${viewer.status.emoji ?? ""} ${viewer.status.label}`);
|
|
66
72
|
}
|
|
67
73
|
}),
|
|
74
|
+
).pipe(
|
|
75
|
+
Command.withDescription("Show the authenticated Linear user"),
|
|
76
|
+
Command.withExamples([
|
|
77
|
+
{ command: "linear auth whoami", description: "Show the authenticated user" },
|
|
78
|
+
{ command: "linear auth whoami --json", description: "Show the authenticated user as JSON" },
|
|
79
|
+
]),
|
|
68
80
|
);
|
|
69
81
|
|
|
70
82
|
// Combined auth command with subcommands
|