@cvr/linear 0.3.0 → 0.5.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 +22 -10
- package/bin/linear +2 -2
- package/package.json +8 -6
- package/skills/linear/SKILL.md +23 -6
- package/src/cli.ts +15 -0
- package/src/commands/api.ts +94 -12
- package/src/commands/auth.ts +41 -41
- package/src/commands/file.ts +61 -0
- package/src/commands/issue.ts +307 -153
- package/src/commands/project.ts +14 -8
- package/src/commands/team.ts +23 -11
- package/src/domain/Files.ts +81 -0
- package/src/domain/Input.ts +68 -0
- package/src/domain/Linear.ts +158 -0
- package/src/lib/downloads.ts +71 -0
- package/src/lib/effect.ts +9 -0
- package/src/lib/errors.ts +3 -14
- package/src/lib/flags.ts +15 -0
- package/src/main.ts +3 -18
- package/src/services/Config.ts +126 -125
- package/src/services/Linear.ts +534 -438
- package/tsconfig.json +22 -3
- package/src/services/Browser.ts +0 -23
- package/src/services/Stdin.ts +0 -27
package/README.md
CHANGED
|
@@ -28,7 +28,8 @@ 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
|
|
@@ -39,8 +40,8 @@ linear issue view ABC-123 ABC-124 --json
|
|
|
39
40
|
# Include comments, sub-issues, and relations
|
|
40
41
|
linear issue view ABC-123 --comments --children --relations --json
|
|
41
42
|
|
|
42
|
-
# Create a new issue
|
|
43
|
-
linear issue create
|
|
43
|
+
# Create a new issue with prompts
|
|
44
|
+
linear issue create --interactive
|
|
44
45
|
|
|
45
46
|
# Non-interactive creation with validation
|
|
46
47
|
linear issue create --team ABC --title "Title" --project "Tech Debt" --dry-run
|
|
@@ -63,13 +64,20 @@ linear team list
|
|
|
63
64
|
|
|
64
65
|
### Issues
|
|
65
66
|
|
|
66
|
-
| Command | Description
|
|
67
|
-
| ------------------------- |
|
|
68
|
-
| `linear issue list` | List your assigned issues
|
|
69
|
-
| `linear issue view [id]` | View issue details
|
|
70
|
-
| `linear issue start [id]` | Start
|
|
71
|
-
| `linear issue create` | Create a new issue
|
|
72
|
-
| `linear issue comment ID` | Add a comment, with `--dry-run` support
|
|
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 |
|
|
74
|
+
| `linear issue files ID` | List uploads; `--download` saves them |
|
|
75
|
+
|
|
76
|
+
### Files
|
|
77
|
+
|
|
78
|
+
| Command | Description |
|
|
79
|
+
| --------------------------- | --------------------------------------------------- |
|
|
80
|
+
| `linear file download URL…` | Download `uploads.linear.app` files with your token |
|
|
73
81
|
|
|
74
82
|
### Teams
|
|
75
83
|
|
|
@@ -90,8 +98,12 @@ linear team list
|
|
|
90
98
|
- `issue view --json` always returns an array and accepts multiple identifiers or Linear issue URLs.
|
|
91
99
|
- Use `--comments`, `--children`, and `--relations` only when that context is needed.
|
|
92
100
|
- Run supported mutations with `--dry-run` before executing them.
|
|
101
|
+
- Prompts are opt-in with `--interactive`; missing agent inputs fail fast.
|
|
93
102
|
- Prefer typed commands. Use `linear api graphql` only for operations the typed CLI cannot express.
|
|
103
|
+
- Keep `--query-file` paths inside the current workspace; traversal and escaping symlinks are rejected.
|
|
104
|
+
- Raw GraphQL mutations require the explicit `--allow-mutation` flag.
|
|
94
105
|
- Never read or interpolate the token directly; the CLI owns authentication.
|
|
106
|
+
- Download attachments with `linear issue files ID --download` or `linear file download URL`. The token is sent only to `uploads.linear.app`, never to a redirect target. Existing files are kept unless `--overwrite` is passed.
|
|
95
107
|
|
|
96
108
|
## Configuration
|
|
97
109
|
|
package/bin/linear
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/linear
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 84186592 bytes
|
|
4
|
+
sha256: d2e8660ed2ec348271c4ec15f498e46fda5ea587ecc1ed7235a309446af2d2c8
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cvr/linear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cevr/linear-cli.git"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lint:fix": "oxlint --fix",
|
|
28
28
|
"fmt": "oxfmt",
|
|
29
29
|
"fmt:check": "oxfmt --check",
|
|
30
|
-
"typecheck": "
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
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
32
|
"prepare": "lefthook install && effect-tsgo patch",
|
|
33
33
|
"version": "changeset version",
|
|
@@ -36,11 +36,13 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@effect/platform-bun": "4.0.0-beta.98",
|
|
38
38
|
"@linear/sdk": "^88.2.0",
|
|
39
|
-
"effect": "4.0.0-beta.98"
|
|
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": "^
|
|
44
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
45
|
+
"@changesets/cli": "^3.0.3",
|
|
44
46
|
"@effect/tsgo": "^0.23.0",
|
|
45
47
|
"@effect/vitest": "4.0.0-beta.98",
|
|
46
48
|
"@types/bun": "^1.3.14",
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
"lefthook": "^2.1.10",
|
|
50
52
|
"oxfmt": "^0.59.0",
|
|
51
53
|
"oxlint": "^1.74.0",
|
|
52
|
-
"oxlint-plugin-effect": "
|
|
54
|
+
"oxlint-plugin-effect": "^0.5.0",
|
|
53
55
|
"typescript": "^7.0.2",
|
|
54
56
|
"vitest": "^4.1.10"
|
|
55
57
|
},
|
package/skills/linear/SKILL.md
CHANGED
|
@@ -16,8 +16,10 @@ Use the `linear` CLI for Linear work. It owns authentication, stable JSON output
|
|
|
16
16
|
4. Treat issue identifiers and Linear issue URLs as equivalent inputs.
|
|
17
17
|
5. Do not mutate Linear unless the user explicitly requested the mutation.
|
|
18
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
|
|
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
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.
|
|
21
23
|
|
|
22
24
|
If `/linear` is invoked without an issue or task, run `linear issue list --json` and summarize the available work.
|
|
23
25
|
|
|
@@ -52,22 +54,35 @@ linear issue view BITE-123 --children --comments --relations --json
|
|
|
52
54
|
|
|
53
55
|
Use the returned `branchName`; do not invent a branch name from the title.
|
|
54
56
|
|
|
57
|
+
### Download attachments
|
|
58
|
+
|
|
59
|
+
Files attached to an issue are Markdown links to `https://uploads.linear.app/...`, which need the Linear credential. Never fetch them with `curl`; use the CLI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
linear issue files BITE-123 --json
|
|
63
|
+
linear issue files BITE-123 --download --output-dir ./files --json
|
|
64
|
+
linear file download https://uploads.linear.app/... --output-dir ./files --json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`issue files` scans the description and every comment and returns `name`, `url`, and `source` (`description` or the comment ID). With `--download`, each file is saved under its Markdown name, and the output lists `path`, `bytes`, and `contentType`. The CLI accepts only `uploads.linear.app` URLs, and it does not send the token to a redirect target. An existing file stops the run unless you pass `--overwrite`.
|
|
68
|
+
|
|
55
69
|
## Mutations
|
|
56
70
|
|
|
57
71
|
### Start work
|
|
58
72
|
|
|
59
73
|
```bash
|
|
60
|
-
linear issue start BITE-123
|
|
74
|
+
linear issue start BITE-123 --dry-run
|
|
75
|
+
linear issue start BITE-123 --json
|
|
61
76
|
```
|
|
62
77
|
|
|
63
|
-
|
|
78
|
+
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.
|
|
64
79
|
|
|
65
80
|
### Create an issue
|
|
66
81
|
|
|
67
82
|
Interactive:
|
|
68
83
|
|
|
69
84
|
```bash
|
|
70
|
-
linear issue create
|
|
85
|
+
linear issue create --interactive
|
|
71
86
|
```
|
|
72
87
|
|
|
73
88
|
Non-interactive agent flow:
|
|
@@ -116,10 +131,12 @@ linear api graphql \
|
|
|
116
131
|
For multiline documents, keep the query in a file:
|
|
117
132
|
|
|
118
133
|
```bash
|
|
119
|
-
linear api graphql --query-file /
|
|
134
|
+
linear api graphql --query-file .linear/issue-query.graphql --variables '{"id":"BITE-123"}'
|
|
120
135
|
```
|
|
121
136
|
|
|
122
|
-
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.
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
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.
|
|
123
140
|
|
|
124
141
|
## Authentication and configuration
|
|
125
142
|
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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 { file } from "./commands/file.js";
|
|
6
|
+
import { issue } from "./commands/issue.js";
|
|
7
|
+
import { project } from "./commands/project.js";
|
|
8
|
+
import { team } from "./commands/team.js";
|
|
9
|
+
|
|
10
|
+
export const linear = Command.make("linear").pipe(
|
|
11
|
+
Command.withDescription("Manage Linear issues, teams, projects, and authentication"),
|
|
12
|
+
Command.withSubcommands([auth, team, project, issue, file, api]),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const runCli = Command.runWith(linear, { version: packageJson.version });
|
package/src/commands/api.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Console, Effect, FileSystem, Option, Schema } from "effect";
|
|
1
|
+
import { Console, Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
2
2
|
import { Command, Flag } from "effect/unstable/cli";
|
|
3
|
+
import { Kind } from "graphql/language/kinds.js";
|
|
4
|
+
import { parse } from "graphql/language/parser.js";
|
|
3
5
|
import { InvalidInputError } from "../lib/errors.js";
|
|
4
6
|
import { encodeJson } from "../lib/json.js";
|
|
5
7
|
import { LinearService } from "../services/Linear.js";
|
|
@@ -19,13 +21,57 @@ const variablesOption = Flag.string("variables").pipe(
|
|
|
19
21
|
Flag.withDefault("{}"),
|
|
20
22
|
);
|
|
21
23
|
|
|
24
|
+
const allowMutationOption = Flag.boolean("allow-mutation").pipe(
|
|
25
|
+
Flag.withDescription("Explicitly authorize a raw GraphQL mutation"),
|
|
26
|
+
);
|
|
27
|
+
|
|
22
28
|
const VariablesJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
|
|
23
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
|
+
});
|
|
24
65
|
|
|
25
66
|
export const graphqlCommand = Command.make(
|
|
26
67
|
"graphql",
|
|
27
|
-
{
|
|
28
|
-
|
|
68
|
+
{
|
|
69
|
+
query: queryOption,
|
|
70
|
+
queryFile: queryFileOption,
|
|
71
|
+
variables: variablesOption,
|
|
72
|
+
allowMutation: allowMutationOption,
|
|
73
|
+
},
|
|
74
|
+
({ query, queryFile, variables, allowMutation }) =>
|
|
29
75
|
Effect.gen(function* () {
|
|
30
76
|
if (Option.isSome(query) && Option.isSome(queryFile)) {
|
|
31
77
|
return yield* InvalidInputError.make({
|
|
@@ -40,17 +86,34 @@ export const graphqlCommand = Command.make(
|
|
|
40
86
|
onNone: () =>
|
|
41
87
|
InvalidInputError.make({ message: "--query or --query-file is required" }),
|
|
42
88
|
onSome: (path) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
readWorkspaceQueryFile(path).pipe(
|
|
90
|
+
Effect.mapError((error) => {
|
|
91
|
+
if (error._tag === "InvalidInputError") {
|
|
92
|
+
return error;
|
|
93
|
+
}
|
|
94
|
+
return InvalidInputError.make({
|
|
95
|
+
message: `Could not read GraphQL query file ${path}: ${error}`,
|
|
96
|
+
});
|
|
97
|
+
}),
|
|
51
98
|
),
|
|
52
99
|
}),
|
|
53
100
|
});
|
|
101
|
+
if (document.length > maximumInputLength) {
|
|
102
|
+
return yield* InvalidInputError.make({
|
|
103
|
+
message: `GraphQL documents cannot exceed ${maximumInputLength} characters`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (variables.length > maximumInputLength) {
|
|
107
|
+
return yield* InvalidInputError.make({
|
|
108
|
+
message: `--variables cannot exceed ${maximumInputLength} characters`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if ((yield* containsMutation(document)) && !allowMutation) {
|
|
112
|
+
return yield* InvalidInputError.make({
|
|
113
|
+
message:
|
|
114
|
+
"Raw GraphQL mutations require explicit authorization with --allow-mutation. Preview and inspect the document before retrying.",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
54
117
|
const parsedVariables = yield* decodeVariables(variables).pipe(
|
|
55
118
|
Effect.mapError((error) =>
|
|
56
119
|
InvalidInputError.make({ message: `--variables must be a JSON object: ${error}` }),
|
|
@@ -60,8 +123,27 @@ export const graphqlCommand = Command.make(
|
|
|
60
123
|
const data = yield* linear.rawQuery(document, parsedVariables);
|
|
61
124
|
yield* Console.log(encodeJson(data));
|
|
62
125
|
}),
|
|
126
|
+
).pipe(
|
|
127
|
+
Command.withDescription("Execute an authenticated Linear GraphQL operation"),
|
|
128
|
+
Command.withExamples([
|
|
129
|
+
{
|
|
130
|
+
command: 'linear api graphql --query "query { viewer { id name } }"',
|
|
131
|
+
description: "Run an inline GraphQL query",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
command: "linear api graphql --query-file query.graphql --variables '{}'",
|
|
135
|
+
description: "Run a GraphQL query from a file with variables",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
command: "linear api graphql --query-file mutation.graphql --allow-mutation",
|
|
139
|
+
description: "Explicitly authorize a raw GraphQL mutation",
|
|
140
|
+
},
|
|
141
|
+
]),
|
|
63
142
|
);
|
|
64
143
|
|
|
65
144
|
export const api = Command.make("api", {}, () =>
|
|
66
145
|
Console.log("Use 'linear api graphql' for GraphQL operations not covered by typed commands."),
|
|
67
|
-
).pipe(
|
|
146
|
+
).pipe(
|
|
147
|
+
Command.withDescription("Access the Linear GraphQL API"),
|
|
148
|
+
Command.withSubcommands([graphqlCommand]),
|
|
149
|
+
);
|
package/src/commands/auth.ts
CHANGED
|
@@ -1,61 +1,51 @@
|
|
|
1
|
-
import { Command,
|
|
1
|
+
import { Command, Prompt } from "effect/unstable/cli";
|
|
2
|
+
import { ChildProcess } from "effect/unstable/process";
|
|
2
3
|
import { Console, Effect } from "effect";
|
|
4
|
+
import { jsonFlag } from "../lib/flags.js";
|
|
3
5
|
import { encodeJson } from "../lib/json.js";
|
|
4
|
-
import { ConfigService } from "../services/Config.js";
|
|
5
6
|
import { LinearService } from "../services/Linear.js";
|
|
6
|
-
import { BrowserService } from "../services/Browser.js";
|
|
7
|
-
import { StdinService } from "../services/Stdin.js";
|
|
8
7
|
|
|
9
8
|
const LINEAR_API_KEY_URL = "https://linear.app/settings/account/security";
|
|
10
9
|
|
|
11
|
-
const jsonOption = Flag.boolean("json").pipe(
|
|
12
|
-
Flag.withDescription("Emit stable JSON for scripts and agents"),
|
|
13
|
-
);
|
|
14
|
-
|
|
15
10
|
// linear auth - Interactive authentication flow
|
|
16
11
|
export const authCommand = Command.make("auth", {}, () =>
|
|
17
12
|
Effect.gen(function* () {
|
|
18
|
-
const browser = yield* BrowserService;
|
|
19
|
-
const config = yield* ConfigService;
|
|
20
|
-
const stdin = yield* StdinService;
|
|
21
|
-
|
|
22
13
|
yield* Console.log(`\nTo authenticate, you'll need a Linear API key.`);
|
|
23
14
|
yield* Console.log(`Opening: ${LINEAR_API_KEY_URL}\n`);
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
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.orElseSucceed(() => false),
|
|
25
|
+
);
|
|
26
|
+
if (!browserOpened) {
|
|
27
|
+
yield* Console.log(`Could not open browser. Please visit the URL manually.`);
|
|
28
|
+
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
const token = yield* stdin.readLine("Paste your API key: ");
|
|
30
|
+
const token = yield* Prompt.hidden({ message: "Paste your API key" });
|
|
34
31
|
|
|
35
32
|
// Validate token by making an API call
|
|
36
33
|
yield* Console.log("\nValidating token...");
|
|
37
34
|
|
|
38
|
-
// Save token first so LinearService can use it
|
|
39
|
-
yield* config.saveToken(token);
|
|
40
|
-
|
|
41
|
-
// Now validate with the saved token
|
|
42
35
|
const linear = yield* LinearService;
|
|
43
|
-
const viewer = yield* linear.
|
|
44
|
-
Effect.catchTag("InvalidTokenError", (e) =>
|
|
45
|
-
Effect.gen(function* () {
|
|
46
|
-
yield* Console.error(`\nError: ${e.message}`);
|
|
47
|
-
yield* Console.error("Please try again with a valid API key.");
|
|
48
|
-
return yield* Effect.die(e);
|
|
49
|
-
}),
|
|
50
|
-
),
|
|
51
|
-
);
|
|
36
|
+
const viewer = yield* linear.authenticate(token);
|
|
52
37
|
|
|
53
38
|
yield* Console.log(`\nAuthenticated as ${viewer.name} (${viewer.email})`);
|
|
54
39
|
}),
|
|
40
|
+
).pipe(
|
|
41
|
+
Command.withDescription("Authenticate with Linear"),
|
|
42
|
+
Command.withExamples([
|
|
43
|
+
{ command: "linear auth", description: "Authenticate using a Linear API key" },
|
|
44
|
+
]),
|
|
55
45
|
);
|
|
56
46
|
|
|
57
47
|
// linear auth whoami - Show current user
|
|
58
|
-
export const whoamiCommand = Command.make("whoami", { json:
|
|
48
|
+
export const whoamiCommand = Command.make("whoami", { json: jsonFlag }, ({ json }) =>
|
|
59
49
|
Effect.gen(function* () {
|
|
60
50
|
const linear = yield* LinearService;
|
|
61
51
|
const viewer = yield* linear.getViewer;
|
|
@@ -67,10 +57,7 @@ export const whoamiCommand = Command.make("whoami", { json: jsonOption }, ({ jso
|
|
|
67
57
|
name: viewer.name,
|
|
68
58
|
email: viewer.email,
|
|
69
59
|
admin: viewer.admin,
|
|
70
|
-
status:
|
|
71
|
-
emoji: viewer.statusEmoji ?? undefined,
|
|
72
|
-
label: viewer.statusLabel ?? undefined,
|
|
73
|
-
},
|
|
60
|
+
status: viewer.status,
|
|
74
61
|
}),
|
|
75
62
|
);
|
|
76
63
|
return;
|
|
@@ -79,12 +66,25 @@ export const whoamiCommand = Command.make("whoami", { json: jsonOption }, ({ jso
|
|
|
79
66
|
yield* Console.log(`\nLogged in as:`);
|
|
80
67
|
yield* Console.log(` Name: ${viewer.name}`);
|
|
81
68
|
yield* Console.log(` Email: ${viewer.email}`);
|
|
82
|
-
yield* Console.log(` Admin: ${viewer.admin
|
|
83
|
-
if (viewer.
|
|
84
|
-
yield* Console.log(` Status: ${viewer.
|
|
69
|
+
yield* Console.log(` Admin: ${formatYesNo(viewer.admin)}`);
|
|
70
|
+
if (viewer.status?.label !== undefined) {
|
|
71
|
+
yield* Console.log(` Status: ${viewer.status.emoji ?? ""} ${viewer.status.label}`);
|
|
85
72
|
}
|
|
86
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
|
+
]),
|
|
87
80
|
);
|
|
88
81
|
|
|
89
82
|
// Combined auth command with subcommands
|
|
90
83
|
export const auth = authCommand.pipe(Command.withSubcommands([whoamiCommand]));
|
|
84
|
+
|
|
85
|
+
function formatYesNo(value: boolean): string {
|
|
86
|
+
if (value) {
|
|
87
|
+
return "Yes";
|
|
88
|
+
}
|
|
89
|
+
return "No";
|
|
90
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Argument, Command } from "effect/unstable/cli";
|
|
2
|
+
import { Console, Effect } from "effect";
|
|
3
|
+
import type { SavedFile } from "../domain/Linear.js";
|
|
4
|
+
import { parseUploadUrl } from "../domain/Input.js";
|
|
5
|
+
import { saveDownloads } from "../lib/downloads.js";
|
|
6
|
+
import { InvalidInputError } from "../lib/errors.js";
|
|
7
|
+
import { jsonFlag, outputDirFlag, overwriteFlag } from "../lib/flags.js";
|
|
8
|
+
import { encodeJson } from "../lib/json.js";
|
|
9
|
+
|
|
10
|
+
const uploadUrlsArg = Argument.string("url").pipe(
|
|
11
|
+
Argument.withDescription("https://uploads.linear.app/... URL (repeat for several files)"),
|
|
12
|
+
Argument.variadic(),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const logSavedFiles = (savedFiles: ReadonlyArray<SavedFile>, json: boolean) =>
|
|
16
|
+
Effect.gen(function* () {
|
|
17
|
+
if (json) {
|
|
18
|
+
yield* Console.log(encodeJson(savedFiles));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const savedFile of savedFiles) {
|
|
22
|
+
yield* Console.log(`Saved ${savedFile.path} (${savedFile.bytes} bytes)`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// linear file download <url>... - Download files uploaded to Linear
|
|
27
|
+
export const fileDownloadCommand = Command.make(
|
|
28
|
+
"download",
|
|
29
|
+
{ urls: uploadUrlsArg, outputDir: outputDirFlag, overwrite: overwriteFlag, json: jsonFlag },
|
|
30
|
+
({ urls, outputDir, overwrite, json }) =>
|
|
31
|
+
Effect.gen(function* () {
|
|
32
|
+
if (urls.length === 0) {
|
|
33
|
+
return yield* InvalidInputError.make({
|
|
34
|
+
message:
|
|
35
|
+
"Upload URL required. Usage: linear file download https://uploads.linear.app/... --json",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const uploadUrls = yield* Effect.forEach(urls, parseUploadUrl);
|
|
39
|
+
const savedFiles = yield* saveDownloads({
|
|
40
|
+
requests: uploadUrls.map((url) => ({ url })),
|
|
41
|
+
outputDir,
|
|
42
|
+
overwrite,
|
|
43
|
+
});
|
|
44
|
+
yield* logSavedFiles(savedFiles, json);
|
|
45
|
+
}),
|
|
46
|
+
).pipe(
|
|
47
|
+
Command.withDescription("Download files uploaded to Linear with the configured credential"),
|
|
48
|
+
Command.withExamples([
|
|
49
|
+
{
|
|
50
|
+
command: "linear file download https://uploads.linear.app/... --output-dir ./files --json",
|
|
51
|
+
description: "Save one upload and print its path as JSON",
|
|
52
|
+
},
|
|
53
|
+
]),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const file = Command.make("file", {}, () =>
|
|
57
|
+
Console.log("Use 'linear file download <url>' to download an upload. See --help for more."),
|
|
58
|
+
).pipe(
|
|
59
|
+
Command.withDescription("Download files uploaded to Linear"),
|
|
60
|
+
Command.withSubcommands([fileDownloadCommand]),
|
|
61
|
+
);
|