@cvr/linear 0.2.0 → 0.3.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 +30 -1
- package/bin/linear +0 -0
- package/package.json +23 -21
- package/skills/linear/SKILL.md +141 -0
- package/src/commands/api.ts +67 -0
- package/src/commands/auth.ts +25 -6
- package/src/commands/issue.ts +352 -135
- package/src/commands/project.ts +45 -0
- package/src/commands/team.ts +24 -4
- package/src/lib/errors.ts +16 -8
- package/src/lib/json.ts +5 -0
- package/src/main.ts +20 -16
- package/src/services/Browser.ts +3 -3
- package/src/services/Config.ts +15 -15
- package/src/services/Linear.ts +314 -14
- package/src/services/Stdin.ts +14 -21
- package/tsconfig.json +67 -7
package/src/lib/errors.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
export class ConfigError extends Schema.
|
|
3
|
+
export class ConfigError extends Schema.TaggedErrorClass<ConfigError>()("ConfigError", {
|
|
4
4
|
message: Schema.String,
|
|
5
5
|
}) {}
|
|
6
6
|
|
|
7
|
-
export class LinearApiError extends Schema.
|
|
7
|
+
export class LinearApiError extends Schema.TaggedErrorClass<LinearApiError>()("LinearApiError", {
|
|
8
8
|
message: Schema.String,
|
|
9
9
|
code: Schema.optional(Schema.String),
|
|
10
10
|
}) {}
|
|
11
11
|
|
|
12
|
-
export class BrowserError extends Schema.
|
|
12
|
+
export class BrowserError extends Schema.TaggedErrorClass<BrowserError>()("BrowserError", {
|
|
13
13
|
message: Schema.String,
|
|
14
14
|
}) {}
|
|
15
15
|
|
|
16
|
-
export class TokenNotFoundError extends Schema.
|
|
16
|
+
export class TokenNotFoundError extends Schema.TaggedErrorClass<TokenNotFoundError>()(
|
|
17
17
|
"TokenNotFoundError",
|
|
18
18
|
{
|
|
19
19
|
message: Schema.String,
|
|
@@ -24,25 +24,33 @@ export class TokenNotFoundError extends Schema.TaggedError<TokenNotFoundError>()
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export class InvalidTokenError extends Schema.
|
|
27
|
+
export class InvalidTokenError extends Schema.TaggedErrorClass<InvalidTokenError>()(
|
|
28
28
|
"InvalidTokenError",
|
|
29
29
|
{
|
|
30
30
|
message: Schema.String,
|
|
31
31
|
},
|
|
32
32
|
) {}
|
|
33
33
|
|
|
34
|
-
export class NoIssuesError extends Schema.
|
|
34
|
+
export class NoIssuesError extends Schema.TaggedErrorClass<NoIssuesError>()("NoIssuesError", {
|
|
35
35
|
message: Schema.String,
|
|
36
36
|
}) {
|
|
37
37
|
static readonly default = NoIssuesError.make({ message: "No issues found to select from." });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export
|
|
40
|
+
export class InvalidInputError extends Schema.TaggedErrorClass<InvalidInputError>()(
|
|
41
|
+
"InvalidInputError",
|
|
42
|
+
{
|
|
43
|
+
message: Schema.String,
|
|
44
|
+
},
|
|
45
|
+
) {}
|
|
46
|
+
|
|
47
|
+
export const AppError = Schema.Union([
|
|
41
48
|
ConfigError,
|
|
42
49
|
LinearApiError,
|
|
43
50
|
BrowserError,
|
|
44
51
|
TokenNotFoundError,
|
|
45
52
|
InvalidTokenError,
|
|
46
53
|
NoIssuesError,
|
|
47
|
-
|
|
54
|
+
InvalidInputError,
|
|
55
|
+
]);
|
|
48
56
|
export type AppError = typeof AppError.Type;
|
package/src/lib/json.ts
ADDED
package/src/main.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// @effect-diagnostics strictEffectProvide:off
|
|
2
|
+
import { Command } from "effect/unstable/cli";
|
|
3
|
+
import { BunRuntime, BunServices } from "@effect/platform-bun";
|
|
3
4
|
import { Console, Effect, Layer } from "effect";
|
|
5
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
4
6
|
import { auth } from "./commands/auth.js";
|
|
7
|
+
import { api } from "./commands/api.js";
|
|
5
8
|
import { team } from "./commands/team.js";
|
|
6
9
|
import { issue } from "./commands/issue.js";
|
|
10
|
+
import { project } from "./commands/project.js";
|
|
7
11
|
import { ConfigService } from "./services/Config.js";
|
|
8
12
|
import { LinearService } from "./services/Linear.js";
|
|
9
13
|
import { BrowserService } from "./services/Browser.js";
|
|
@@ -12,16 +16,13 @@ import { StdinService } from "./services/Stdin.js";
|
|
|
12
16
|
// Root command
|
|
13
17
|
const linear = Command.make("linear", {}, () =>
|
|
14
18
|
Console.log("Linear CLI - Use --help to see available commands"),
|
|
15
|
-
).pipe(Command.withSubcommands([auth, team, issue]));
|
|
19
|
+
).pipe(Command.withSubcommands([auth, team, project, issue, api]));
|
|
16
20
|
|
|
17
21
|
// Build the CLI runner
|
|
18
|
-
const cli = Command.run(linear, {
|
|
19
|
-
name: "linear",
|
|
20
|
-
version: "0.1.0",
|
|
21
|
-
});
|
|
22
|
+
const cli = Command.run(linear, { version: packageJson.version });
|
|
22
23
|
|
|
23
24
|
// Layer composition:
|
|
24
|
-
// -
|
|
25
|
+
// - BunServices provides FileSystem, Path, Terminal, Stdio, and child processes
|
|
25
26
|
// - ConfigService depends on FileSystem, Path
|
|
26
27
|
// - LinearService depends on ConfigService
|
|
27
28
|
// - BrowserService is standalone
|
|
@@ -31,16 +32,19 @@ const MainLayer = StdinService.layer.pipe(
|
|
|
31
32
|
Layer.provideMerge(BrowserService.layer),
|
|
32
33
|
Layer.provideMerge(LinearService.layer),
|
|
33
34
|
Layer.provideMerge(ConfigService.layer),
|
|
34
|
-
Layer.provideMerge(
|
|
35
|
+
Layer.provideMerge(BunServices.layer),
|
|
35
36
|
);
|
|
36
37
|
|
|
37
38
|
// Run the CLI
|
|
38
|
-
cli
|
|
39
|
-
Effect.
|
|
40
|
-
Effect.
|
|
41
|
-
Effect.
|
|
42
|
-
Effect.
|
|
43
|
-
|
|
39
|
+
cli.pipe(
|
|
40
|
+
Effect.tapErrorTag("TokenNotFoundError", (e) => Console.error(`Error: ${e.message}`)),
|
|
41
|
+
Effect.tapErrorTag("LinearApiError", (e) => Console.error(`Linear API Error: ${e.message}`)),
|
|
42
|
+
Effect.tapErrorTag("ConfigError", (e) => Console.error(`Config Error: ${e.message}`)),
|
|
43
|
+
Effect.tapErrorTag("InvalidTokenError", (e) =>
|
|
44
|
+
Console.error(`Authentication Error: ${e.message}`),
|
|
45
|
+
),
|
|
46
|
+
Effect.tapErrorTag("NoIssuesError", (e) => Console.error(e.message)),
|
|
47
|
+
Effect.tapErrorTag("InvalidInputError", (e) => Console.error(`Invalid input: ${e.message}`)),
|
|
44
48
|
Effect.provide(MainLayer),
|
|
45
|
-
BunRuntime.runMain,
|
|
49
|
+
BunRuntime.runMain({ disableErrorReporting: true }),
|
|
46
50
|
);
|
package/src/services/Browser.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from "effect";
|
|
2
2
|
import { BrowserError } from "../lib/errors.js";
|
|
3
3
|
|
|
4
|
-
export class BrowserService extends Context.
|
|
4
|
+
export class BrowserService extends Context.Service<
|
|
5
5
|
BrowserService,
|
|
6
6
|
{
|
|
7
7
|
readonly open: (url: string) => Effect.Effect<void, BrowserError>;
|
|
8
8
|
}
|
|
9
|
-
>() {
|
|
9
|
+
>()("@cvr/linear/services/Browser/BrowserService") {
|
|
10
10
|
// macOS-only implementation using `open` command
|
|
11
11
|
static readonly layer = Layer.succeed(BrowserService, {
|
|
12
12
|
open: (url) =>
|
|
@@ -17,7 +17,7 @@ export class BrowserService extends Context.Tag("@linear/BrowserService")<
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
// No-op layer for testing
|
|
20
|
-
static readonly
|
|
20
|
+
static readonly layerTest = Layer.succeed(BrowserService, {
|
|
21
21
|
open: (_url) => Effect.void,
|
|
22
22
|
});
|
|
23
23
|
}
|
package/src/services/Config.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Option } from "effect";
|
|
2
|
-
import { FileSystem, Path } from "@effect/platform";
|
|
1
|
+
import { Config, Context, Effect, FileSystem, Layer, Option, Path } from "effect";
|
|
3
2
|
import { ConfigError, TokenNotFoundError } from "../lib/errors.js";
|
|
4
3
|
|
|
5
4
|
// Config structure for .linear.toml
|
|
@@ -9,21 +8,22 @@ export interface LinearConfig {
|
|
|
9
8
|
readonly issueSort?: "manual" | "priority";
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
export class ConfigService extends Context.
|
|
11
|
+
export class ConfigService extends Context.Service<
|
|
13
12
|
ConfigService,
|
|
14
13
|
{
|
|
15
14
|
readonly getToken: Effect.Effect<string, TokenNotFoundError | ConfigError>;
|
|
16
15
|
readonly saveToken: (token: string) => Effect.Effect<void, ConfigError>;
|
|
17
16
|
readonly getConfig: Effect.Effect<LinearConfig, ConfigError>;
|
|
18
17
|
}
|
|
19
|
-
>() {
|
|
18
|
+
>()("@cvr/linear/services/Config/ConfigService") {
|
|
20
19
|
static readonly layer = Layer.effect(
|
|
21
20
|
ConfigService,
|
|
22
21
|
Effect.gen(function* () {
|
|
23
22
|
const fs = yield* FileSystem.FileSystem;
|
|
24
23
|
const path = yield* Path.Path;
|
|
25
24
|
|
|
26
|
-
const homeDir =
|
|
25
|
+
const homeDir = yield* Config.string("HOME").pipe(Config.withDefault(""));
|
|
26
|
+
const envToken = yield* Config.string("LINEAR_API_KEY").pipe(Config.option);
|
|
27
27
|
const configDir = path.join(homeDir, ".config", "linear");
|
|
28
28
|
const tokenPath = path.join(configDir, "token");
|
|
29
29
|
const configPath = path.join(configDir, "config.toml");
|
|
@@ -34,8 +34,8 @@ export class ConfigService extends Context.Tag("@linear/ConfigService")<
|
|
|
34
34
|
yield* fs.makeDirectory(configDir, { recursive: true });
|
|
35
35
|
}
|
|
36
36
|
}).pipe(
|
|
37
|
-
Effect.
|
|
38
|
-
ConfigError.make({ message: `Failed to create config directory: ${e}` }),
|
|
37
|
+
Effect.catch((e) =>
|
|
38
|
+
Effect.fail(ConfigError.make({ message: `Failed to create config directory: ${e}` })),
|
|
39
39
|
),
|
|
40
40
|
);
|
|
41
41
|
|
|
@@ -46,28 +46,28 @@ export class ConfigService extends Context.Tag("@linear/ConfigService")<
|
|
|
46
46
|
catch: () => null,
|
|
47
47
|
}).pipe(Effect.option);
|
|
48
48
|
|
|
49
|
-
if (Option.isSome(fileToken) && fileToken.value.trim()) {
|
|
49
|
+
if (Option.isSome(fileToken) && fileToken.value.trim().length > 0) {
|
|
50
50
|
return fileToken.value.trim();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// 2. Try env var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return envToken;
|
|
54
|
+
if (Option.isSome(envToken)) {
|
|
55
|
+
return envToken.value;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
// 3. Error
|
|
60
59
|
return yield* TokenNotFoundError.default;
|
|
61
60
|
}).pipe(Effect.withSpan("ConfigService.getToken"));
|
|
62
61
|
|
|
63
|
-
const saveToken = (token: string) =>
|
|
62
|
+
const saveToken = Effect.fn("ConfigService.saveToken")((token: string) =>
|
|
64
63
|
Effect.gen(function* () {
|
|
65
64
|
yield* ensureConfigDir;
|
|
66
65
|
yield* Effect.tryPromise({
|
|
67
66
|
try: () => Bun.write(tokenPath, token.trim()),
|
|
68
67
|
catch: (e) => ConfigError.make({ message: `Failed to save token: ${e}` }),
|
|
69
68
|
});
|
|
70
|
-
})
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
71
|
|
|
72
72
|
const getConfig = Effect.gen(function* () {
|
|
73
73
|
// Try project config first (.linear.toml in cwd or git root)
|
|
@@ -89,7 +89,7 @@ export class ConfigService extends Context.Tag("@linear/ConfigService")<
|
|
|
89
89
|
}),
|
|
90
90
|
);
|
|
91
91
|
|
|
92
|
-
static readonly
|
|
92
|
+
static readonly layerTest = (options?: { token?: string; config?: LinearConfig }) =>
|
|
93
93
|
Layer.succeed(ConfigService, {
|
|
94
94
|
getToken:
|
|
95
95
|
options?.token != null
|
|
@@ -123,7 +123,7 @@ const loadTomlConfig = Effect.fn("ConfigService.loadTomlConfig")((filePath: stri
|
|
|
123
123
|
.trim()
|
|
124
124
|
.replace(/^["']|["']$/g, "");
|
|
125
125
|
|
|
126
|
-
switch (key
|
|
126
|
+
switch (key?.trim()) {
|
|
127
127
|
case "team_id":
|
|
128
128
|
teamId = value;
|
|
129
129
|
break;
|