@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.
@@ -0,0 +1,51 @@
1
+ import { Console, Effect } from "effect";
2
+ import { Command } from "effect/unstable/cli";
3
+ import { jsonFlag } from "../lib/flags.js";
4
+ import { encodeJson } from "../lib/json.js";
5
+ import { LinearService } from "../services/Linear.js";
6
+
7
+ export const projectListCommand = Command.make("list", { json: jsonFlag }, ({ json }) =>
8
+ Effect.gen(function* () {
9
+ const linear = yield* LinearService;
10
+ const projects = yield* linear.getProjects;
11
+
12
+ if (json) {
13
+ yield* Console.log(
14
+ encodeJson(
15
+ projects.map((project) => ({
16
+ id: project.id,
17
+ name: project.name,
18
+ slug: project.slug,
19
+ state: project.state,
20
+ url: project.url,
21
+ })),
22
+ ),
23
+ );
24
+ return;
25
+ }
26
+
27
+ if (projects.length === 0) {
28
+ yield* Console.log("No projects found.");
29
+ return;
30
+ }
31
+
32
+ yield* Console.log("\nProjects:\n");
33
+ for (const project of projects) {
34
+ yield* Console.log(` ${project.name} ${project.state} ${project.id}`);
35
+ }
36
+ yield* Console.log("");
37
+ }),
38
+ ).pipe(
39
+ Command.withDescription("List Linear projects"),
40
+ Command.withExamples([
41
+ { command: "linear project list", description: "List all projects" },
42
+ { command: "linear project list --json", description: "List all projects as JSON" },
43
+ ]),
44
+ );
45
+
46
+ export const project = Command.make("project", {}, () =>
47
+ Console.log("Use 'linear project list' to list projects. See --help for more."),
48
+ ).pipe(
49
+ Command.withDescription("Manage Linear projects"),
50
+ Command.withSubcommands([projectListCommand]),
51
+ );
@@ -1,15 +1,31 @@
1
- import { Command } from "@effect/cli";
1
+ import { Command } from "effect/unstable/cli";
2
2
  import { Console, Effect } from "effect";
3
+ import { jsonFlag } from "../lib/flags.js";
4
+ import { encodeJson } from "../lib/json.js";
3
5
  import { LinearService } from "../services/Linear.js";
4
6
 
5
7
  // linear team list - List all teams
6
- export const teamListCommand = Command.make("list", {}, () =>
8
+ export const teamListCommand = Command.make("list", { json: jsonFlag }, ({ json }) =>
7
9
  Effect.gen(function* () {
8
10
  const linear = yield* LinearService;
9
11
  const teams = yield* linear.getTeams;
10
12
 
11
13
  if (teams.length === 0) {
12
- yield* Console.log("No teams found.");
14
+ yield* Console.log(json ? "[]" : "No teams found.");
15
+ return;
16
+ }
17
+
18
+ if (json) {
19
+ yield* Console.log(
20
+ encodeJson(
21
+ teams.map((team) => ({
22
+ id: team.id,
23
+ key: team.key,
24
+ name: team.name,
25
+ description: team.description ?? undefined,
26
+ })),
27
+ ),
28
+ );
13
29
  return;
14
30
  }
15
31
 
@@ -18,15 +34,22 @@ export const teamListCommand = Command.make("list", {}, () =>
18
34
  for (const team of teams) {
19
35
  const key = team.key;
20
36
  const name = team.name;
21
- const description = team.description ? ` - ${team.description}` : "";
37
+ const description =
38
+ team.description !== undefined && team.description !== null ? ` - ${team.description}` : "";
22
39
  yield* Console.log(` ${key.padEnd(8)} ${name}${description}`);
23
40
  }
24
41
 
25
42
  yield* Console.log("");
26
43
  }),
44
+ ).pipe(
45
+ Command.withDescription("List Linear teams"),
46
+ Command.withExamples([
47
+ { command: "linear team list", description: "List all teams" },
48
+ { command: "linear team list --json", description: "List all teams as JSON" },
49
+ ]),
27
50
  );
28
51
 
29
52
  // Combined team command with subcommands
30
53
  export const team = Command.make("team", {}, () =>
31
54
  Console.log("Use 'linear team list' to list teams. See --help for more."),
32
- ).pipe(Command.withSubcommands([teamListCommand]));
55
+ ).pipe(Command.withDescription("Manage Linear teams"), Command.withSubcommands([teamListCommand]));
@@ -0,0 +1,55 @@
1
+ import { Effect } from "effect";
2
+ import { IssueSelector } from "./Linear.js";
3
+ import { InvalidInputError } from "../lib/errors.js";
4
+
5
+ const issueIdentifierPattern = /^[A-Za-z][A-Za-z0-9]*-\d+$/;
6
+ const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
7
+ const hasUnsupportedControlCharacter = (value: string): boolean =>
8
+ Array.from(value).some((character) => {
9
+ const code = character.codePointAt(0) ?? 0;
10
+ return code === 0x7f || (code < 0x20 && code !== 0x09 && code !== 0x0a && code !== 0x0d);
11
+ });
12
+
13
+ export const parseIssueSelector = Effect.fn("Input.parseIssueSelector")(function* (input: string) {
14
+ if (hasUnsupportedControlCharacter(input)) {
15
+ return yield* InvalidInputError.make({
16
+ message: "Issue identifiers cannot contain control characters",
17
+ });
18
+ }
19
+
20
+ const urlMatch = input.match(
21
+ /^https:\/\/linear\.app\/[^/]+\/issue\/([A-Za-z][A-Za-z0-9]*-\d+)(?:\/[^?#]*)?$/i,
22
+ );
23
+ if (urlMatch?.[1] !== undefined) {
24
+ return IssueSelector.make(urlMatch[1]);
25
+ }
26
+ if (issueIdentifierPattern.test(input) || uuidPattern.test(input)) {
27
+ return IssueSelector.make(input);
28
+ }
29
+
30
+ return yield* InvalidInputError.make({
31
+ message: `Invalid issue identifier: ${input}. Expected ENG-123, a Linear issue URL, or a UUID`,
32
+ });
33
+ });
34
+
35
+ export const validateText = Effect.fn("Input.validateText")(function* (options: {
36
+ readonly name: string;
37
+ readonly value: string;
38
+ readonly maximumLength: number;
39
+ readonly allowEmpty?: boolean;
40
+ }) {
41
+ if (hasUnsupportedControlCharacter(options.value)) {
42
+ return yield* InvalidInputError.make({
43
+ message: `${options.name} cannot contain control characters`,
44
+ });
45
+ }
46
+ if (options.allowEmpty !== true && options.value.trim().length === 0) {
47
+ return yield* InvalidInputError.make({ message: `${options.name} cannot be empty` });
48
+ }
49
+ if (options.value.length > options.maximumLength) {
50
+ return yield* InvalidInputError.make({
51
+ message: `${options.name} cannot exceed ${options.maximumLength} characters`,
52
+ });
53
+ }
54
+ return options.value;
55
+ });
@@ -0,0 +1,134 @@
1
+ import { Schema } from "effect";
2
+
3
+ export const IssueSelector = Schema.String.pipe(Schema.brand("IssueSelector"));
4
+ export type IssueSelector = Schema.Schema.Type<typeof IssueSelector>;
5
+
6
+ export class ViewerStatus extends Schema.Class<ViewerStatus>("ViewerStatus")({
7
+ emoji: Schema.optional(Schema.String),
8
+ label: Schema.optional(Schema.String),
9
+ }) {}
10
+
11
+ export class Viewer extends Schema.Class<Viewer>("Viewer")({
12
+ id: Schema.String,
13
+ name: Schema.String,
14
+ email: Schema.String,
15
+ admin: Schema.Boolean,
16
+ status: Schema.optional(ViewerStatus),
17
+ }) {}
18
+
19
+ export class Team extends Schema.Class<Team>("Team")({
20
+ id: Schema.String,
21
+ key: Schema.String,
22
+ name: Schema.String,
23
+ description: Schema.optional(Schema.String),
24
+ }) {}
25
+
26
+ export class Project extends Schema.Class<Project>("Project")({
27
+ id: Schema.String,
28
+ name: Schema.String,
29
+ slug: Schema.String,
30
+ state: Schema.String,
31
+ url: Schema.String,
32
+ }) {}
33
+
34
+ export class IssueReference extends Schema.Class<IssueReference>("IssueReference")({
35
+ id: Schema.String,
36
+ identifier: Schema.String,
37
+ title: Schema.String,
38
+ url: Schema.String,
39
+ }) {}
40
+
41
+ export class IssueState extends Schema.Class<IssueState>("IssueState")({
42
+ id: Schema.String,
43
+ name: Schema.String,
44
+ type: Schema.String,
45
+ }) {}
46
+
47
+ export class IssuePriority extends Schema.Class<IssuePriority>("IssuePriority")({
48
+ value: Schema.Number,
49
+ label: Schema.String,
50
+ }) {}
51
+
52
+ export class IssueSummary extends IssueReference.extend<IssueSummary>("IssueSummary")({
53
+ branchName: Schema.String,
54
+ priority: IssuePriority,
55
+ state: Schema.optional(IssueState),
56
+ }) {}
57
+
58
+ export class IssueTeam extends Schema.Class<IssueTeam>("IssueTeam")({
59
+ id: Schema.String,
60
+ key: Schema.String,
61
+ name: Schema.String,
62
+ }) {}
63
+
64
+ export class IssueAssignee extends Schema.Class<IssueAssignee>("IssueAssignee")({
65
+ id: Schema.String,
66
+ name: Schema.String,
67
+ email: Schema.String,
68
+ }) {}
69
+
70
+ export class IssueProject extends Schema.Class<IssueProject>("IssueProject")({
71
+ id: Schema.String,
72
+ name: Schema.String,
73
+ url: Schema.String,
74
+ }) {}
75
+
76
+ export class IssueLabel extends Schema.Class<IssueLabel>("IssueLabel")({
77
+ id: Schema.String,
78
+ name: Schema.String,
79
+ }) {}
80
+
81
+ export class IssueCommentAuthor extends Schema.Class<IssueCommentAuthor>("IssueCommentAuthor")({
82
+ id: Schema.String,
83
+ name: Schema.String,
84
+ }) {}
85
+
86
+ export class IssueComment extends Schema.Class<IssueComment>("IssueComment")({
87
+ id: Schema.String,
88
+ body: Schema.String,
89
+ createdAt: Schema.String,
90
+ url: Schema.String,
91
+ author: Schema.optional(IssueCommentAuthor),
92
+ }) {}
93
+
94
+ export class IssueRelation extends Schema.Class<IssueRelation>("IssueRelation")({
95
+ id: Schema.String,
96
+ type: Schema.String,
97
+ direction: Schema.Literals(["outbound", "inbound"]),
98
+ issue: IssueReference,
99
+ }) {}
100
+
101
+ export class IssueDetails extends IssueSummary.extend<IssueDetails>("IssueDetails")({
102
+ description: Schema.optional(Schema.String),
103
+ team: Schema.optional(IssueTeam),
104
+ assignee: Schema.optional(IssueAssignee),
105
+ project: Schema.optional(IssueProject),
106
+ parent: Schema.optional(IssueReference),
107
+ labels: Schema.Array(IssueLabel),
108
+ children: Schema.optional(Schema.Array(IssueReference)),
109
+ comments: Schema.optional(Schema.Array(IssueComment)),
110
+ relations: Schema.optional(Schema.Array(IssueRelation)),
111
+ }) {}
112
+
113
+ export class StartedIssue extends Schema.Class<StartedIssue>("StartedIssue")({
114
+ issue: IssueReference,
115
+ state: IssueState,
116
+ branchName: Schema.String,
117
+ }) {}
118
+
119
+ export class CreatedIssue extends IssueReference.extend<CreatedIssue>("CreatedIssue")({}) {}
120
+
121
+ export interface IssueDetailsOptions {
122
+ readonly comments: boolean;
123
+ readonly children: boolean;
124
+ readonly relations: boolean;
125
+ }
126
+
127
+ export interface CreateIssueInput {
128
+ readonly title: string;
129
+ readonly teamId: string;
130
+ readonly description?: string;
131
+ readonly parent?: IssueSelector;
132
+ readonly projectId?: string;
133
+ readonly priority?: number;
134
+ }
package/src/lib/errors.ts CHANGED
@@ -1,19 +1,15 @@
1
1
  import { Schema } from "effect";
2
2
 
3
- export class ConfigError extends Schema.TaggedError<ConfigError>()("ConfigError", {
3
+ export class ConfigError extends Schema.TaggedErrorClass<ConfigError>()("ConfigError", {
4
4
  message: Schema.String,
5
5
  }) {}
6
6
 
7
- export class LinearApiError extends Schema.TaggedError<LinearApiError>()("LinearApiError", {
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.TaggedError<BrowserError>()("BrowserError", {
13
- message: Schema.String,
14
- }) {}
15
-
16
- export class TokenNotFoundError extends Schema.TaggedError<TokenNotFoundError>()(
12
+ export class TokenNotFoundError extends Schema.TaggedErrorClass<TokenNotFoundError>()(
17
13
  "TokenNotFoundError",
18
14
  {
19
15
  message: Schema.String,
@@ -24,25 +20,22 @@ export class TokenNotFoundError extends Schema.TaggedError<TokenNotFoundError>()
24
20
  });
25
21
  }
26
22
 
27
- export class InvalidTokenError extends Schema.TaggedError<InvalidTokenError>()(
23
+ export class InvalidTokenError extends Schema.TaggedErrorClass<InvalidTokenError>()(
28
24
  "InvalidTokenError",
29
25
  {
30
26
  message: Schema.String,
31
27
  },
32
28
  ) {}
33
29
 
34
- export class NoIssuesError extends Schema.TaggedError<NoIssuesError>()("NoIssuesError", {
30
+ export class NoIssuesError extends Schema.TaggedErrorClass<NoIssuesError>()("NoIssuesError", {
35
31
  message: Schema.String,
36
32
  }) {
37
33
  static readonly default = NoIssuesError.make({ message: "No issues found to select from." });
38
34
  }
39
35
 
40
- export const AppError = Schema.Union(
41
- ConfigError,
42
- LinearApiError,
43
- BrowserError,
44
- TokenNotFoundError,
45
- InvalidTokenError,
46
- NoIssuesError,
47
- );
48
- export type AppError = typeof AppError.Type;
36
+ export class InvalidInputError extends Schema.TaggedErrorClass<InvalidInputError>()(
37
+ "InvalidInputError",
38
+ {
39
+ message: Schema.String,
40
+ },
41
+ ) {}
@@ -0,0 +1,5 @@
1
+ import { Flag } from "effect/unstable/cli";
2
+
3
+ export const jsonFlag = Flag.boolean("json").pipe(
4
+ Flag.withDescription("Emit stable JSON for scripts and agents"),
5
+ );
@@ -0,0 +1,5 @@
1
+ import { Schema } from "effect";
2
+
3
+ const JsonText = Schema.fromJsonString(Schema.Unknown);
4
+
5
+ export const encodeJson = Schema.encodeSync(JsonText);
package/src/main.ts CHANGED
@@ -1,46 +1,34 @@
1
- import { Command } from "@effect/cli";
2
- import { BunContext, BunRuntime } from "@effect/platform-bun";
1
+ import { Command } from "effect/unstable/cli";
2
+ import { BunRuntime, BunServices } from "@effect/platform-bun";
3
3
  import { Console, Effect, Layer } from "effect";
4
- import { auth } from "./commands/auth.js";
5
- import { team } from "./commands/team.js";
6
- import { issue } from "./commands/issue.js";
4
+ import packageJson from "../package.json" with { type: "json" };
5
+ import { linear } from "./cli.js";
7
6
  import { ConfigService } from "./services/Config.js";
8
7
  import { LinearService } from "./services/Linear.js";
9
- import { BrowserService } from "./services/Browser.js";
10
- import { StdinService } from "./services/Stdin.js";
11
-
12
- // Root command
13
- const linear = Command.make("linear", {}, () =>
14
- Console.log("Linear CLI - Use --help to see available commands"),
15
- ).pipe(Command.withSubcommands([auth, team, issue]));
16
8
 
17
9
  // Build the CLI runner
18
- const cli = Command.run(linear, {
19
- name: "linear",
20
- version: "0.1.0",
21
- });
10
+ const cli = Command.run(linear, { version: packageJson.version });
22
11
 
23
12
  // Layer composition:
24
- // - BunContext provides FileSystem, Path, Terminal
13
+ // - BunServices provides FileSystem, Path, Terminal, Stdio, and child processes
25
14
  // - ConfigService depends on FileSystem, Path
26
15
  // - LinearService depends on ConfigService
27
- // - BrowserService is standalone
28
-
29
16
  // Build layers with dependencies
30
- const MainLayer = StdinService.layer.pipe(
31
- Layer.provideMerge(BrowserService.layer),
32
- Layer.provideMerge(LinearService.layer),
17
+ const MainLayer = LinearService.layer.pipe(
33
18
  Layer.provideMerge(ConfigService.layer),
34
- Layer.provideMerge(BunContext.layer),
19
+ Layer.provideMerge(BunServices.layer),
35
20
  );
36
21
 
37
22
  // Run the CLI
38
- cli(process.argv).pipe(
39
- Effect.catchTag("TokenNotFoundError", (e) => Console.error(`Error: ${e.message}`)),
40
- Effect.catchTag("LinearApiError", (e) => Console.error(`Linear API Error: ${e.message}`)),
41
- Effect.catchTag("ConfigError", (e) => Console.error(`Config Error: ${e.message}`)),
42
- Effect.catchTag("InvalidTokenError", (e) => Console.error(`Authentication Error: ${e.message}`)),
43
- Effect.catchTag("NoIssuesError", (e) => Console.error(e.message)),
23
+ cli.pipe(
24
+ Effect.tapErrorTag("TokenNotFoundError", (e) => Console.error(`Error: ${e.message}`)),
25
+ Effect.tapErrorTag("LinearApiError", (e) => Console.error(`Linear API Error: ${e.message}`)),
26
+ Effect.tapErrorTag("ConfigError", (e) => Console.error(`Config Error: ${e.message}`)),
27
+ Effect.tapErrorTag("InvalidTokenError", (e) =>
28
+ Console.error(`Authentication Error: ${e.message}`),
29
+ ),
30
+ Effect.tapErrorTag("NoIssuesError", (e) => Console.error(e.message)),
31
+ Effect.tapErrorTag("InvalidInputError", (e) => Console.error(`Invalid input: ${e.message}`)),
44
32
  Effect.provide(MainLayer),
45
- BunRuntime.runMain,
33
+ BunRuntime.runMain({ disableErrorReporting: true }),
46
34
  );