@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.
@@ -1,41 +1,90 @@
1
- import { Args, Command, Options, Prompt } from "@effect/cli";
2
- import type { Terminal } from "@effect/platform";
3
- import type { Context, Types } from "effect";
1
+ import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
4
2
  import { Console, Effect, Option } from "effect";
5
- import { NoIssuesError, type LinearApiError, type TokenNotFoundError } from "../lib/errors.js";
6
- import { LinearService } from "../services/Linear.js";
3
+ import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
4
+ import { encodeJson } from "../lib/json.js";
5
+ import { LinearService, type IssueDetails } from "../services/Linear.js";
7
6
  import { ConfigService } from "../services/Config.js";
8
7
 
9
8
  /** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
10
9
  const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
11
- fetch
10
+ fetch !== undefined
12
11
  ? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
13
12
  : Effect.succeed(null);
14
13
 
15
14
  // Options
16
- const stateOption = Options.text("state").pipe(
17
- Options.withAlias("s"),
18
- Options.withDescription("Filter by state type (started, unstarted, backlog, etc.)"),
19
- Options.optional,
15
+ const stateOption = Flag.string("state").pipe(
16
+ Flag.withAlias("s"),
17
+ Flag.withDescription("Filter by state type (started, unstarted, backlog, etc.)"),
18
+ Flag.optional,
20
19
  );
21
20
 
22
- const limitOption = Options.integer("limit").pipe(
23
- Options.withAlias("n"),
24
- Options.withDefault(20),
25
- Options.withDescription("Number of issues to show"),
21
+ const limitOption = Flag.integer("limit").pipe(
22
+ Flag.withAlias("n"),
23
+ Flag.withDefault(20),
24
+ Flag.withDescription("Number of issues to show"),
26
25
  );
27
26
 
27
+ const jsonOption = Flag.boolean("json").pipe(
28
+ Flag.withDescription("Emit stable JSON for scripts and agents"),
29
+ );
30
+
31
+ const commentsOption = Flag.boolean("comments").pipe(
32
+ Flag.withDescription("Include issue comments"),
33
+ );
34
+
35
+ const childrenOption = Flag.boolean("children").pipe(Flag.withDescription("Include sub-issues"));
36
+
37
+ const relationsOption = Flag.boolean("relations").pipe(
38
+ Flag.withDescription("Include inbound and outbound issue relations"),
39
+ );
40
+
41
+ const titleOption = Flag.string("title").pipe(
42
+ Flag.withDescription("Issue title; enables non-interactive creation"),
43
+ Flag.optional,
44
+ );
45
+
46
+ const descriptionOption = Flag.string("description").pipe(
47
+ Flag.withDescription("Issue description in Markdown"),
48
+ Flag.optional,
49
+ );
50
+
51
+ const teamOption = Flag.string("team").pipe(
52
+ Flag.withDescription("Team key or UUID"),
53
+ Flag.optional,
54
+ );
55
+
56
+ const parentOption = Flag.string("parent").pipe(
57
+ Flag.withDescription("Parent issue identifier or UUID"),
58
+ Flag.optional,
59
+ );
60
+
61
+ const projectOption = Flag.string("project").pipe(
62
+ Flag.withDescription("Project name, slug, or UUID"),
63
+ Flag.optional,
64
+ );
65
+
66
+ const priorityOption = Flag.integer("priority").pipe(
67
+ Flag.withDescription("Priority from 0 (none) to 4 (low)"),
68
+ Flag.optional,
69
+ );
70
+
71
+ const dryRunOption = Flag.boolean("dry-run").pipe(
72
+ Flag.withDescription("Validate and print the mutation without writing"),
73
+ );
74
+
75
+ const bodyOption = Flag.string("body").pipe(Flag.withDescription("Comment body in Markdown"));
76
+
28
77
  // Args
29
- const issueIdArg = Args.text({ name: "id" }).pipe(
30
- Args.withDescription("Issue ID or identifier (e.g., ABC-123)"),
31
- Args.optional,
78
+ const issueIdsArg = Argument.string("id").pipe(
79
+ Argument.withDescription("Issue ID, URL, or identifier (repeat for bulk reads)"),
80
+ Argument.variadic(),
32
81
  );
33
82
 
34
83
  // linear issue list - List issues
35
84
  export const issueListCommand = Command.make(
36
85
  "list",
37
- { state: stateOption, limit: limitOption },
38
- ({ state, limit }) =>
86
+ { state: stateOption, limit: limitOption, json: jsonOption },
87
+ ({ state, limit, json }) =>
39
88
  Effect.gen(function* () {
40
89
  const linear = yield* LinearService;
41
90
 
@@ -43,13 +92,38 @@ export const issueListCommand = Command.make(
43
92
  const issues = yield* linear.getMyIssues({ state: stateFilter });
44
93
 
45
94
  if (issues.length === 0) {
46
- yield* Console.log("No issues found.");
95
+ yield* Console.log(json ? "[]" : "No issues found.");
47
96
  return;
48
97
  }
49
98
 
50
99
  yield* Console.log("\nYour Issues:\n");
51
100
 
52
101
  const displayed = issues.slice(0, limit);
102
+
103
+ if (json) {
104
+ const values = yield* Effect.forEach(
105
+ displayed,
106
+ (issue) =>
107
+ resolveFetch(issue.state).pipe(
108
+ Effect.map((issueState) => ({
109
+ id: issue.id,
110
+ identifier: issue.identifier,
111
+ title: issue.title,
112
+ url: issue.url,
113
+ branchName: issue.branchName,
114
+ priority: { value: issue.priority, label: getPriorityLabel(issue.priority) },
115
+ state:
116
+ issueState === null
117
+ ? undefined
118
+ : { id: issueState.id, name: issueState.name, type: issueState.type },
119
+ })),
120
+ ),
121
+ { concurrency: 4 },
122
+ );
123
+ yield* Console.log(encodeJson(values));
124
+ return;
125
+ }
126
+
53
127
  for (const issue of displayed) {
54
128
  const issueState = yield* resolveFetch(issue.state);
55
129
  const stateName = issueState?.name ?? "Unknown";
@@ -70,47 +144,48 @@ export const issueListCommand = Command.make(
70
144
  );
71
145
 
72
146
  // linear issue view [id] - View issue details
73
- export const issueViewCommand = Command.make("view", { id: issueIdArg }, ({ id }) =>
74
- Effect.gen(function* () {
75
- const linear = yield* LinearService;
76
-
77
- // If no ID provided, prompt for selection
78
- const issueId = yield* Option.match(id, {
79
- onNone: () => selectIssue(linear),
80
- onSome: (id) => Effect.succeed(id),
81
- });
82
-
83
- const issue = yield* linear.getIssue(issueId);
84
- const issueState = yield* resolveFetch(issue.state);
85
- const assignee = yield* resolveFetch(issue.assignee);
86
- const issueTeam = yield* resolveFetch(issue.team);
87
-
88
- yield* Console.log("");
89
- yield* Console.log(`${issue.identifier}: ${issue.title}`);
90
- yield* Console.log(`${"─".repeat(60)}`);
91
- yield* Console.log(`State: ${issueState?.name ?? "Unknown"}`);
92
- yield* Console.log(`Team: ${issueTeam?.name ?? "Unknown"}`);
93
- yield* Console.log(`Priority: ${getPriorityLabel(issue.priority ?? 0)}`);
94
- yield* Console.log(`Assignee: ${assignee?.name ?? "Unassigned"}`);
95
- yield* Console.log(`URL: ${issue.url}`);
96
-
97
- if (issue.description) {
98
- yield* Console.log(`\nDescription:\n${issue.description}`);
99
- }
147
+ export const issueViewCommand = Command.make(
148
+ "view",
149
+ {
150
+ ids: issueIdsArg,
151
+ json: jsonOption,
152
+ comments: commentsOption,
153
+ children: childrenOption,
154
+ relations: relationsOption,
155
+ },
156
+ ({ ids, json, comments, children, relations }) =>
157
+ Effect.gen(function* () {
158
+ const linear = yield* LinearService;
159
+ const selectedIds = ids.length === 0 ? [yield* selectIssue] : ids;
160
+ const details = yield* Effect.forEach(
161
+ selectedIds,
162
+ (id) => linear.getIssueDetails(id, { comments, children, relations }),
163
+ { concurrency: 4 },
164
+ );
165
+
166
+ if (json) {
167
+ yield* Console.log(encodeJson(details));
168
+ return;
169
+ }
100
170
 
101
- yield* Console.log("");
102
- }),
171
+ yield* Effect.forEach(details, renderIssueDetails, { discard: true });
172
+ }),
103
173
  );
104
174
 
105
175
  // linear issue start [id] - Start working on an issue
106
- export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id }) =>
176
+ const optionalIssueIdArg = Argument.string("id").pipe(
177
+ Argument.withDescription("Issue ID, URL, or identifier"),
178
+ Argument.optional,
179
+ );
180
+
181
+ export const issueStartCommand = Command.make("start", { id: optionalIssueIdArg }, ({ id }) =>
107
182
  Effect.gen(function* () {
108
183
  const linear = yield* LinearService;
109
184
 
110
185
  // If no ID provided, prompt for selection
111
186
  const issueId = yield* Option.match(id, {
112
- onNone: () => selectIssue(linear),
113
- onSome: (id) => Effect.succeed(id),
187
+ onNone: () => selectIssue,
188
+ onSome: (selectedId) => Effect.succeed(selectedId),
114
189
  });
115
190
 
116
191
  const issue = yield* linear.getIssue(issueId);
@@ -119,7 +194,7 @@ export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id
119
194
  // Get the "Started" state for this team
120
195
  const states = yield* Effect.tryPromise({
121
196
  try: async () => {
122
- if (!issueTeam) return [];
197
+ if (issueTeam === null) return [];
123
198
  const connection = await issueTeam.states();
124
199
  return connection.nodes;
125
200
  },
@@ -130,7 +205,7 @@ export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id
130
205
  (s) => s.type === "started" || s.name.toLowerCase() === "in progress",
131
206
  );
132
207
 
133
- if (startedState) {
208
+ if (startedState !== undefined) {
134
209
  yield* linear.updateIssueState(issue.id, startedState.id);
135
210
  yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`);
136
211
  yield* Console.log(`State changed to: ${startedState.name}`);
@@ -139,7 +214,7 @@ export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id
139
214
  }
140
215
 
141
216
  // Show branch name for git
142
- if (issue.branchName) {
217
+ if (issue.branchName !== undefined && issue.branchName !== null) {
143
218
  yield* Console.log(`\nBranch name: ${issue.branchName}`);
144
219
  }
145
220
 
@@ -148,60 +223,112 @@ export const issueStartCommand = Command.make("start", { id: issueIdArg }, ({ id
148
223
  );
149
224
 
150
225
  // linear issue create - Create a new issue
151
- export const issueCreateCommand = Command.make("create", {}, () =>
152
- Effect.gen(function* () {
153
- const linear = yield* LinearService;
154
- const config = yield* ConfigService;
155
- const linearConfig = yield* config.getConfig;
226
+ export const issueCreateCommand = Command.make(
227
+ "create",
228
+ {
229
+ title: titleOption,
230
+ description: descriptionOption,
231
+ team: teamOption,
232
+ parent: parentOption,
233
+ project: projectOption,
234
+ priority: priorityOption,
235
+ dryRun: dryRunOption,
236
+ json: jsonOption,
237
+ },
238
+ ({ title, description, team, parent, project, priority, dryRun, json }) =>
239
+ Effect.gen(function* () {
240
+ const linear = yield* LinearService;
241
+ const config = yield* ConfigService;
242
+ const linearConfig = yield* config.getConfig;
156
243
 
157
- // Get teams for selection
158
- const teams = yield* linear.getTeams;
244
+ // Get teams for selection
245
+ const teams = yield* linear.getTeams;
159
246
 
160
- if (teams.length === 0) {
161
- yield* Console.error("No teams found. Cannot create issue.");
162
- return;
163
- }
247
+ if (teams.length === 0) {
248
+ yield* Console.error("No teams found. Cannot create issue.");
249
+ return;
250
+ }
164
251
 
165
- // Select team (or use default from config)
166
- let teamId: string;
252
+ const isInteractive = Option.isNone(title);
253
+ const requestedTeam = Option.getOrUndefined(team) ?? linearConfig.teamId;
254
+ const teamId = yield* resolveTeamId(teams, requestedTeam, isInteractive);
255
+ const issueTitle = yield* Option.match(title, {
256
+ onNone: () => Prompt.text({ message: "Issue title" }),
257
+ onSome: Effect.succeed,
258
+ });
259
+ const issueDescription = yield* Option.match(description, {
260
+ onNone: () =>
261
+ isInteractive
262
+ ? Prompt.text({
263
+ message: "Description (optional, press Enter to skip)",
264
+ default: "",
265
+ })
266
+ : Effect.succeed(""),
267
+ onSome: Effect.succeed,
268
+ });
269
+ const priorityValue = Option.getOrUndefined(priority);
270
+ if (priorityValue !== undefined && (priorityValue < 0 || priorityValue > 4)) {
271
+ return yield* InvalidInputError.make({ message: "--priority must be between 0 and 4" });
272
+ }
167
273
 
168
- if (linearConfig.teamId) {
169
- const team = teams.find((t) => t.id === linearConfig.teamId || t.key === linearConfig.teamId);
170
- if (team) {
171
- teamId = team.id;
172
- yield* Console.log(`Using team from config: ${team.name}`);
173
- } else {
174
- teamId = yield* selectTeam(teams);
274
+ const projectSelector = Option.getOrUndefined(project);
275
+ const projectId =
276
+ projectSelector === undefined
277
+ ? undefined
278
+ : yield* resolveProjectId(yield* linear.getProjects, projectSelector);
279
+ const input = {
280
+ title: issueTitle,
281
+ teamId,
282
+ description: issueDescription.length === 0 ? undefined : issueDescription,
283
+ parentId: Option.getOrUndefined(parent),
284
+ projectId,
285
+ priority: priorityValue,
286
+ };
287
+
288
+ if (dryRun) {
289
+ yield* Console.log(encodeJson({ dryRun: true, operation: "issue.create", input }));
290
+ return;
175
291
  }
176
- } else if (teams.length === 1) {
177
- teamId = teams[0].id;
178
- yield* Console.log(`Using team: ${teams[0].name}`);
179
- } else {
180
- teamId = yield* selectTeam(teams);
181
- }
182
292
 
183
- // Prompt for title
184
- const title = yield* Prompt.text({
185
- message: "Issue title",
186
- });
293
+ // Create the issue
294
+ const created = yield* linear.createIssue(input);
187
295
 
188
- // Prompt for description (optional)
189
- const description = yield* Prompt.text({
190
- message: "Description (optional, press Enter to skip)",
191
- default: "",
192
- });
296
+ if (json) {
297
+ yield* Console.log(encodeJson(toCreatedIssue(created)));
298
+ return;
299
+ }
193
300
 
194
- // Create the issue
195
- const issue = yield* linear.createIssue({
196
- title,
197
- teamId,
198
- description: description || undefined,
199
- });
301
+ yield* Console.log(`\nCreated: ${created.identifier} - ${created.title}`);
302
+ yield* Console.log(`URL: ${created.url}`);
303
+ yield* Console.log("");
304
+ }),
305
+ );
200
306
 
201
- yield* Console.log(`\nCreated: ${issue.identifier} - ${issue.title}`);
202
- yield* Console.log(`URL: ${issue.url}`);
203
- yield* Console.log("");
204
- }),
307
+ export const issueCommentCommand = Command.make(
308
+ "comment",
309
+ {
310
+ id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
311
+ body: bodyOption,
312
+ dryRun: dryRunOption,
313
+ json: jsonOption,
314
+ },
315
+ ({ id, body, dryRun, json }) =>
316
+ Effect.gen(function* () {
317
+ if (dryRun) {
318
+ yield* Console.log(
319
+ encodeJson({ dryRun: true, operation: "issue.comment", input: { id, body } }),
320
+ );
321
+ return;
322
+ }
323
+
324
+ const linear = yield* LinearService;
325
+ const comment = yield* linear.createComment(id, body);
326
+ if (json) {
327
+ yield* Console.log(encodeJson(comment));
328
+ return;
329
+ }
330
+ yield* Console.log(`Comment created: ${comment.url}`);
331
+ }),
205
332
  );
206
333
 
207
334
  // Combined issue command with subcommands
@@ -213,49 +340,86 @@ export const issue = Command.make("issue", {}, () =>
213
340
  issueViewCommand,
214
341
  issueStartCommand,
215
342
  issueCreateCommand,
343
+ issueCommentCommand,
216
344
  ]),
217
345
  );
218
346
 
219
347
  // Helper functions
220
348
 
221
- function selectIssue(
222
- linear: Context.Tag.Service<typeof LinearService>,
223
- ): Effect.Effect<
224
- string,
225
- LinearApiError | TokenNotFoundError | NoIssuesError | Types.NoInfer<Terminal.QuitException>,
226
- Terminal.Terminal
227
- > {
228
- return Effect.gen(function* () {
229
- const issues = yield* linear.getMyIssues({ state: "started" });
230
- const allIssues =
231
- issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
232
-
233
- if (allIssues.length === 0) {
234
- return yield* NoIssuesError.default;
235
- }
236
-
237
- // Build choices with state info
238
- const choices = yield* Effect.all(
239
- allIssues.slice(0, 20).map((issue) =>
240
- Effect.gen(function* () {
241
- const issueState = yield* resolveFetch(issue.state);
242
- return {
243
- title: `${issue.identifier}: ${truncate(issue.title, 40)}`,
244
- value: issue.identifier,
245
- description: issueState?.name ?? "Unknown state",
246
- };
247
- }),
248
- ),
249
- );
349
+ const selectIssue = Effect.gen(function* () {
350
+ const linear = yield* LinearService;
351
+ const issues = yield* linear.getMyIssues({ state: "started" });
352
+ const allIssues = issues.length > 0 ? issues : yield* linear.getMyIssues({ state: "unstarted" });
250
353
 
251
- const selected = yield* Prompt.select({
252
- message: "Select an issue",
253
- choices,
254
- });
354
+ if (allIssues.length === 0) {
355
+ return yield* NoIssuesError.default;
356
+ }
255
357
 
256
- return selected;
358
+ // Build choices with state info
359
+ const choices = yield* Effect.all(
360
+ allIssues.slice(0, 20).map((candidate) =>
361
+ Effect.gen(function* () {
362
+ const issueState = yield* resolveFetch(candidate.state);
363
+ return {
364
+ title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
365
+ value: candidate.identifier,
366
+ description: issueState?.name ?? "Unknown state",
367
+ };
368
+ }),
369
+ ),
370
+ );
371
+
372
+ const selected = yield* Prompt.select({
373
+ message: "Select an issue",
374
+ choices,
257
375
  });
258
- }
376
+
377
+ return selected;
378
+ });
379
+
380
+ const renderIssueDetails = Effect.fn("IssueCommand.renderDetails")(function* (
381
+ details: IssueDetails,
382
+ ) {
383
+ yield* Console.log("");
384
+ yield* Console.log(`${details.identifier}: ${details.title}`);
385
+ yield* Console.log(`${"─".repeat(60)}`);
386
+ yield* Console.log(`State: ${details.state?.name ?? "Unknown"}`);
387
+ yield* Console.log(`Team: ${details.team?.name ?? "Unknown"}`);
388
+ yield* Console.log(`Priority: ${details.priority.label}`);
389
+ yield* Console.log(`Assignee: ${details.assignee?.name ?? "Unassigned"}`);
390
+ yield* Console.log(`Project: ${details.project?.name ?? "None"}`);
391
+ yield* Console.log(`Parent: ${details.parent?.identifier ?? "None"}`);
392
+ yield* Console.log(`Branch: ${details.branchName}`);
393
+ yield* Console.log(`URL: ${details.url}`);
394
+
395
+ if (details.description !== undefined) {
396
+ yield* Console.log(`\nDescription:\n${details.description}`);
397
+ }
398
+ if (details.children !== undefined) {
399
+ yield* Console.log(`\nSub-issues (${details.children.length}):`);
400
+ for (const child of details.children) {
401
+ yield* Console.log(` ${child.identifier} ${child.title}`);
402
+ }
403
+ }
404
+ if (details.comments !== undefined) {
405
+ yield* Console.log(`\nComments (${details.comments.length}):`);
406
+ for (const comment of details.comments) {
407
+ yield* Console.log(
408
+ ` ${comment.author?.name ?? "Unknown"} · ${comment.createdAt}\n ${comment.body}`,
409
+ );
410
+ }
411
+ }
412
+ if (details.relations !== undefined) {
413
+ yield* Console.log(`\nRelations (${details.relations.length}):`);
414
+ for (const relation of details.relations) {
415
+ yield* Console.log(
416
+ ` ${relation.direction} ${relation.type} ${relation.issue.identifier} ${relation.issue.title}`,
417
+ );
418
+ }
419
+ }
420
+
421
+ yield* Console.log("");
422
+ });
259
423
 
260
424
  function selectTeam(teams: readonly { id: string; key: string; name: string }[]) {
261
425
  return Prompt.select({
@@ -267,6 +431,59 @@ function selectTeam(teams: readonly { id: string; key: string; name: string }[])
267
431
  });
268
432
  }
269
433
 
434
+ const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
435
+ teams: readonly { id: string; key: string; name: string }[],
436
+ selector: string | undefined,
437
+ interactive: boolean,
438
+ ) {
439
+ if (selector !== undefined) {
440
+ const normalized = selector.toLowerCase();
441
+ const selected = teams.find(
442
+ (team) => team.id === selector || team.key.toLowerCase() === normalized,
443
+ );
444
+ return selected === undefined
445
+ ? yield* InvalidInputError.make({ message: `Unknown team: ${selector}` })
446
+ : selected.id;
447
+ }
448
+ if (teams.length === 1) {
449
+ const [team] = teams;
450
+ return team === undefined
451
+ ? yield* InvalidInputError.make({ message: "No team available" })
452
+ : team.id;
453
+ }
454
+ return interactive
455
+ ? yield* selectTeam(teams)
456
+ : yield* InvalidInputError.make({ message: "--team is required when multiple teams exist" });
457
+ });
458
+
459
+ const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
460
+ projects: readonly { id: string; name: string; slugId: string }[],
461
+ selector: string,
462
+ ) {
463
+ const normalized = selector.toLowerCase();
464
+ const selected = projects.find(
465
+ (project) =>
466
+ project.id === selector ||
467
+ project.name.toLowerCase() === normalized ||
468
+ project.slugId.toLowerCase() === normalized,
469
+ );
470
+ return selected === undefined
471
+ ? yield* InvalidInputError.make({ message: `Unknown project: ${selector}` })
472
+ : selected.id;
473
+ });
474
+
475
+ const toCreatedIssue = (created: {
476
+ id: string;
477
+ identifier: string;
478
+ title: string;
479
+ url: string;
480
+ }) => ({
481
+ id: created.id,
482
+ identifier: created.identifier,
483
+ title: created.title,
484
+ url: created.url,
485
+ });
486
+
270
487
  function truncate(str: string, len: number): string {
271
488
  return str.length > len ? str.slice(0, len - 1) + "…" : str;
272
489
  }
@@ -0,0 +1,45 @@
1
+ import { Console, Effect } from "effect";
2
+ import { Command, Flag } from "effect/unstable/cli";
3
+ import { encodeJson } from "../lib/json.js";
4
+ import { LinearService } from "../services/Linear.js";
5
+
6
+ const jsonOption = Flag.boolean("json").pipe(
7
+ Flag.withDescription("Emit stable JSON for scripts and agents"),
8
+ );
9
+
10
+ export const projectListCommand = Command.make("list", { json: jsonOption }, ({ json }) =>
11
+ Effect.gen(function* () {
12
+ const linear = yield* LinearService;
13
+ const projects = yield* linear.getProjects;
14
+
15
+ if (json) {
16
+ yield* Console.log(
17
+ encodeJson(
18
+ projects.map((project) => ({
19
+ id: project.id,
20
+ name: project.name,
21
+ slug: project.slugId,
22
+ state: project.state,
23
+ url: project.url,
24
+ })),
25
+ ),
26
+ );
27
+ return;
28
+ }
29
+
30
+ if (projects.length === 0) {
31
+ yield* Console.log("No projects found.");
32
+ return;
33
+ }
34
+
35
+ yield* Console.log("\nProjects:\n");
36
+ for (const project of projects) {
37
+ yield* Console.log(` ${project.name} ${project.state} ${project.id}`);
38
+ }
39
+ yield* Console.log("");
40
+ }),
41
+ );
42
+
43
+ export const project = Command.make("project", {}, () =>
44
+ Console.log("Use 'linear project list' to list projects. See --help for more."),
45
+ ).pipe(Command.withSubcommands([projectListCommand]));
@@ -1,15 +1,34 @@
1
- import { Command } from "@effect/cli";
1
+ import { Command, Flag } from "effect/unstable/cli";
2
2
  import { Console, Effect } from "effect";
3
+ import { encodeJson } from "../lib/json.js";
3
4
  import { LinearService } from "../services/Linear.js";
4
5
 
6
+ const jsonOption = Flag.boolean("json").pipe(
7
+ Flag.withDescription("Emit stable JSON for scripts and agents"),
8
+ );
9
+
5
10
  // linear team list - List all teams
6
- export const teamListCommand = Command.make("list", {}, () =>
11
+ export const teamListCommand = Command.make("list", { json: jsonOption }, ({ json }) =>
7
12
  Effect.gen(function* () {
8
13
  const linear = yield* LinearService;
9
14
  const teams = yield* linear.getTeams;
10
15
 
11
16
  if (teams.length === 0) {
12
- yield* Console.log("No teams found.");
17
+ yield* Console.log(json ? "[]" : "No teams found.");
18
+ return;
19
+ }
20
+
21
+ if (json) {
22
+ yield* Console.log(
23
+ encodeJson(
24
+ teams.map((team) => ({
25
+ id: team.id,
26
+ key: team.key,
27
+ name: team.name,
28
+ description: team.description ?? undefined,
29
+ })),
30
+ ),
31
+ );
13
32
  return;
14
33
  }
15
34
 
@@ -18,7 +37,8 @@ export const teamListCommand = Command.make("list", {}, () =>
18
37
  for (const team of teams) {
19
38
  const key = team.key;
20
39
  const name = team.name;
21
- const description = team.description ? ` - ${team.description}` : "";
40
+ const description =
41
+ team.description !== undefined && team.description !== null ? ` - ${team.description}` : "";
22
42
  yield* Console.log(` ${key.padEnd(8)} ${name}${description}`);
23
43
  }
24
44