@cvr/linear 0.3.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.
@@ -1,16 +1,13 @@
1
1
  import { Argument, Command, Flag, Prompt } from "effect/unstable/cli";
2
2
  import { Console, Effect, Option } from "effect";
3
+ import type { IssueDetails } from "../domain/Linear.js";
4
+ import { parseIssueSelector, validateText } from "../domain/Input.js";
3
5
  import { InvalidInputError, NoIssuesError } from "../lib/errors.js";
6
+ import { jsonFlag } from "../lib/flags.js";
4
7
  import { encodeJson } from "../lib/json.js";
5
- import { LinearService, type IssueDetails } from "../services/Linear.js";
8
+ import { LinearService } from "../services/Linear.js";
6
9
  import { ConfigService } from "../services/Config.js";
7
10
 
8
- /** Resolve LinearFetch<T> | undefined (LinearFetch is Promise-like lazy loader) */
9
- const resolveFetch = <T>(fetch: PromiseLike<T> | undefined): Effect.Effect<T | null> =>
10
- fetch !== undefined
11
- ? Effect.tryPromise(() => Promise.resolve(fetch)).pipe(Effect.orElseSucceed(() => null))
12
- : Effect.succeed(null);
13
-
14
11
  // Options
15
12
  const stateOption = Flag.string("state").pipe(
16
13
  Flag.withAlias("s"),
@@ -24,10 +21,6 @@ const limitOption = Flag.integer("limit").pipe(
24
21
  Flag.withDescription("Number of issues to show"),
25
22
  );
26
23
 
27
- const jsonOption = Flag.boolean("json").pipe(
28
- Flag.withDescription("Emit stable JSON for scripts and agents"),
29
- );
30
-
31
24
  const commentsOption = Flag.boolean("comments").pipe(
32
25
  Flag.withDescription("Include issue comments"),
33
26
  );
@@ -72,6 +65,10 @@ const dryRunOption = Flag.boolean("dry-run").pipe(
72
65
  Flag.withDescription("Validate and print the mutation without writing"),
73
66
  );
74
67
 
68
+ const interactiveOption = Flag.boolean("interactive").pipe(
69
+ Flag.withDescription("Allow prompts when required input is missing"),
70
+ );
71
+
75
72
  const bodyOption = Flag.string("body").pipe(Flag.withDescription("Comment body in Markdown"));
76
73
 
77
74
  // Args
@@ -83,52 +80,35 @@ const issueIdsArg = Argument.string("id").pipe(
83
80
  // linear issue list - List issues
84
81
  export const issueListCommand = Command.make(
85
82
  "list",
86
- { state: stateOption, limit: limitOption, json: jsonOption },
83
+ { state: stateOption, limit: limitOption, json: jsonFlag },
87
84
  ({ state, limit, json }) =>
88
85
  Effect.gen(function* () {
89
- const linear = yield* LinearService;
86
+ if (limit < 1 || limit > 250) {
87
+ return yield* InvalidInputError.make({
88
+ message: "--limit must be between 1 and 250. Example: linear issue list --limit 20",
89
+ });
90
+ }
90
91
 
92
+ const linear = yield* LinearService;
91
93
  const stateFilter = Option.getOrUndefined(state);
92
- const issues = yield* linear.getMyIssues({ state: stateFilter });
94
+ const issues = yield* linear.getMyIssues({ state: stateFilter, limit });
93
95
 
94
96
  if (issues.length === 0) {
95
97
  yield* Console.log(json ? "[]" : "No issues found.");
96
98
  return;
97
99
  }
98
100
 
99
- yield* Console.log("\nYour Issues:\n");
100
-
101
101
  const displayed = issues.slice(0, limit);
102
102
 
103
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));
104
+ yield* Console.log(encodeJson(displayed));
124
105
  return;
125
106
  }
126
107
 
108
+ yield* Console.log("\nYour Issues:\n");
127
109
  for (const issue of displayed) {
128
- const issueState = yield* resolveFetch(issue.state);
129
- const stateName = issueState?.name ?? "Unknown";
130
- const priority = issue.priority ?? 0;
131
- const priorityIcon = getPriorityIcon(priority);
110
+ const stateName = issue.state?.name ?? "Unknown";
111
+ const priorityIcon = getPriorityIcon(issue.priority.value);
132
112
 
133
113
  yield* Console.log(
134
114
  ` ${priorityIcon} ${issue.identifier.padEnd(10)} ${stateName.padEnd(12)} ${truncate(issue.title, 50)}`,
@@ -141,6 +121,15 @@ export const issueListCommand = Command.make(
141
121
 
142
122
  yield* Console.log("");
143
123
  }),
124
+ ).pipe(
125
+ Command.withDescription("List issues assigned to the authenticated user"),
126
+ Command.withExamples([
127
+ { command: "linear issue list --json", description: "List assigned issues as JSON" },
128
+ {
129
+ command: "linear issue list --state started --limit 10 --json",
130
+ description: "List up to ten started issues",
131
+ },
132
+ ]),
144
133
  );
145
134
 
146
135
  // linear issue view [id] - View issue details
@@ -148,15 +137,25 @@ export const issueViewCommand = Command.make(
148
137
  "view",
149
138
  {
150
139
  ids: issueIdsArg,
151
- json: jsonOption,
140
+ json: jsonFlag,
141
+ interactive: interactiveOption,
152
142
  comments: commentsOption,
153
143
  children: childrenOption,
154
144
  relations: relationsOption,
155
145
  },
156
- ({ ids, json, comments, children, relations }) =>
146
+ ({ ids, json, interactive, comments, children, relations }) =>
157
147
  Effect.gen(function* () {
148
+ if (ids.length === 0 && !interactive) {
149
+ return yield* InvalidInputError.make({
150
+ message:
151
+ "Issue identifier required in non-interactive mode. Usage: linear issue view ISSUE-123 --json",
152
+ });
153
+ }
154
+ const selectedIds = yield* Effect.forEach(
155
+ ids.length === 0 ? [yield* selectIssue] : ids,
156
+ parseIssueSelector,
157
+ );
158
158
  const linear = yield* LinearService;
159
- const selectedIds = ids.length === 0 ? [yield* selectIssue] : ids;
160
159
  const details = yield* Effect.forEach(
161
160
  selectedIds,
162
161
  (id) => linear.getIssueDetails(id, { comments, children, relations }),
@@ -170,6 +169,16 @@ export const issueViewCommand = Command.make(
170
169
 
171
170
  yield* Effect.forEach(details, renderIssueDetails, { discard: true });
172
171
  }),
172
+ ).pipe(
173
+ Command.withDescription("Read one or more issues"),
174
+ Command.withExamples([
175
+ { command: "linear issue view ENG-123 --json", description: "Read one issue as JSON" },
176
+ {
177
+ command: "linear issue view ENG-123 ENG-124 --comments --json",
178
+ description: "Read several issues with comments",
179
+ },
180
+ { command: "linear issue view --interactive", description: "Choose an issue interactively" },
181
+ ]),
173
182
  );
174
183
 
175
184
  // linear issue start [id] - Start working on an issue
@@ -178,48 +187,63 @@ const optionalIssueIdArg = Argument.string("id").pipe(
178
187
  Argument.optional,
179
188
  );
180
189
 
181
- export const issueStartCommand = Command.make("start", { id: optionalIssueIdArg }, ({ id }) =>
182
- Effect.gen(function* () {
183
- const linear = yield* LinearService;
184
-
185
- // If no ID provided, prompt for selection
186
- const issueId = yield* Option.match(id, {
187
- onNone: () => selectIssue,
188
- onSome: (selectedId) => Effect.succeed(selectedId),
189
- });
190
-
191
- const issue = yield* linear.getIssue(issueId);
192
- const issueTeam = yield* resolveFetch(issue.team);
193
-
194
- // Get the "Started" state for this team
195
- const states = yield* Effect.tryPromise({
196
- try: async () => {
197
- if (issueTeam === null) return [];
198
- const connection = await issueTeam.states();
199
- return connection.nodes;
200
- },
201
- catch: () => [],
202
- });
203
-
204
- const startedState = states.find(
205
- (s) => s.type === "started" || s.name.toLowerCase() === "in progress",
206
- );
207
-
208
- if (startedState !== undefined) {
209
- yield* linear.updateIssueState(issue.id, startedState.id);
210
- yield* Console.log(`\nStarted: ${issue.identifier} - ${issue.title}`);
211
- yield* Console.log(`State changed to: ${startedState.name}`);
212
- } else {
213
- yield* Console.log(`\nCould not find a "started" state for this issue's team.`);
214
- }
190
+ export const issueStartCommand = Command.make(
191
+ "start",
192
+ {
193
+ id: optionalIssueIdArg,
194
+ dryRun: dryRunOption,
195
+ json: jsonFlag,
196
+ interactive: interactiveOption,
197
+ },
198
+ ({ id, dryRun, json, interactive }) =>
199
+ Effect.gen(function* () {
200
+ const selectedIssue = yield* Option.match(id, {
201
+ onNone: () =>
202
+ interactive
203
+ ? selectIssue
204
+ : InvalidInputError.make({
205
+ message:
206
+ "Issue identifier required in non-interactive mode. Usage: linear issue start ISSUE-123 --dry-run",
207
+ }),
208
+ onSome: Effect.succeed,
209
+ });
210
+ const issueId = yield* parseIssueSelector(selectedIssue);
215
211
 
216
- // Show branch name for git
217
- if (issue.branchName !== undefined && issue.branchName !== null) {
218
- yield* Console.log(`\nBranch name: ${issue.branchName}`);
219
- }
212
+ const linear = yield* LinearService;
213
+ const started = yield* linear.startIssue(issueId, { dryRun });
214
+ if (dryRun) {
215
+ yield* Console.log(
216
+ encodeJson({
217
+ dryRun: true,
218
+ operation: "issue.start",
219
+ input: { id: issueId },
220
+ result: started,
221
+ }),
222
+ );
223
+ return;
224
+ }
225
+ if (json) {
226
+ yield* Console.log(encodeJson(started));
227
+ return;
228
+ }
220
229
 
221
- yield* Console.log("");
222
- }),
230
+ yield* Console.log(`\nStarted: ${started.issue.identifier} - ${started.issue.title}`);
231
+ yield* Console.log(`State changed to: ${started.state.name}`);
232
+ yield* Console.log(`\nBranch name: ${started.branchName}`);
233
+ yield* Console.log("");
234
+ }),
235
+ ).pipe(
236
+ Command.withDescription("Move an issue to its team's started state"),
237
+ Command.withExamples([
238
+ {
239
+ command: "linear issue start ENG-123 --dry-run",
240
+ description: "Validate and preview the state change",
241
+ },
242
+ {
243
+ command: "linear issue start ENG-123 --json",
244
+ description: "Start an issue and return the result as JSON",
245
+ },
246
+ ]),
223
247
  );
224
248
 
225
249
  // linear issue create - Create a new issue
@@ -233,20 +257,27 @@ export const issueCreateCommand = Command.make(
233
257
  project: projectOption,
234
258
  priority: priorityOption,
235
259
  dryRun: dryRunOption,
236
- json: jsonOption,
260
+ json: jsonFlag,
261
+ interactive: interactiveOption,
237
262
  },
238
- ({ title, description, team, parent, project, priority, dryRun, json }) =>
263
+ ({ title, description, team, parent, project, priority, dryRun, json, interactive }) =>
239
264
  Effect.gen(function* () {
265
+ if (Option.isNone(title) && !interactive) {
266
+ return yield* InvalidInputError.make({
267
+ message:
268
+ '--title is required in non-interactive mode. Usage: linear issue create --team ENG --title "Title" --dry-run',
269
+ });
270
+ }
271
+
240
272
  const linear = yield* LinearService;
241
273
  const config = yield* ConfigService;
242
274
  const linearConfig = yield* config.getConfig;
243
-
244
- // Get teams for selection
245
275
  const teams = yield* linear.getTeams;
246
276
 
247
277
  if (teams.length === 0) {
248
- yield* Console.error("No teams found. Cannot create issue.");
249
- return;
278
+ return yield* InvalidInputError.make({
279
+ message: "No teams found; an issue cannot be created",
280
+ });
250
281
  }
251
282
 
252
283
  const isInteractive = Option.isNone(title);
@@ -266,6 +297,17 @@ export const issueCreateCommand = Command.make(
266
297
  : Effect.succeed(""),
267
298
  onSome: Effect.succeed,
268
299
  });
300
+ const validatedTitle = yield* validateText({
301
+ name: "Issue title",
302
+ value: issueTitle,
303
+ maximumLength: 255,
304
+ });
305
+ const validatedDescription = yield* validateText({
306
+ name: "Issue description",
307
+ value: issueDescription,
308
+ maximumLength: 100_000,
309
+ allowEmpty: true,
310
+ });
269
311
  const priorityValue = Option.getOrUndefined(priority);
270
312
  if (priorityValue !== undefined && (priorityValue < 0 || priorityValue > 4)) {
271
313
  return yield* InvalidInputError.make({ message: "--priority must be between 0 and 4" });
@@ -277,10 +319,13 @@ export const issueCreateCommand = Command.make(
277
319
  ? undefined
278
320
  : yield* resolveProjectId(yield* linear.getProjects, projectSelector);
279
321
  const input = {
280
- title: issueTitle,
322
+ title: validatedTitle,
281
323
  teamId,
282
- description: issueDescription.length === 0 ? undefined : issueDescription,
283
- parentId: Option.getOrUndefined(parent),
324
+ description: validatedDescription.length === 0 ? undefined : validatedDescription,
325
+ parent: yield* Option.match(parent, {
326
+ onNone: () => Effect.succeed(undefined),
327
+ onSome: parseIssueSelector,
328
+ }),
284
329
  projectId,
285
330
  priority: priorityValue,
286
331
  };
@@ -302,6 +347,19 @@ export const issueCreateCommand = Command.make(
302
347
  yield* Console.log(`URL: ${created.url}`);
303
348
  yield* Console.log("");
304
349
  }),
350
+ ).pipe(
351
+ Command.withDescription("Create an issue interactively or from flags"),
352
+ Command.withExamples([
353
+ {
354
+ command: 'linear issue create --team ENG --title "Title" --dry-run',
355
+ description: "Validate and preview a non-interactive creation",
356
+ },
357
+ {
358
+ command: 'linear issue create --team ENG --title "Title" --json',
359
+ description: "Create an issue and return it as JSON",
360
+ },
361
+ { command: "linear issue create --interactive", description: "Create with prompts" },
362
+ ]),
305
363
  );
306
364
 
307
365
  export const issueCommentCommand = Command.make(
@@ -310,31 +368,54 @@ export const issueCommentCommand = Command.make(
310
368
  id: Argument.string("id").pipe(Argument.withDescription("Issue ID, URL, or identifier")),
311
369
  body: bodyOption,
312
370
  dryRun: dryRunOption,
313
- json: jsonOption,
371
+ json: jsonFlag,
314
372
  },
315
373
  ({ id, body, dryRun, json }) =>
316
374
  Effect.gen(function* () {
375
+ const issueId = yield* parseIssueSelector(id);
376
+ const commentBody = yield* validateText({
377
+ name: "Comment body",
378
+ value: body,
379
+ maximumLength: 100_000,
380
+ });
317
381
  if (dryRun) {
318
382
  yield* Console.log(
319
- encodeJson({ dryRun: true, operation: "issue.comment", input: { id, body } }),
383
+ encodeJson({
384
+ dryRun: true,
385
+ operation: "issue.comment",
386
+ input: { id: issueId, body: commentBody },
387
+ }),
320
388
  );
321
389
  return;
322
390
  }
323
391
 
324
392
  const linear = yield* LinearService;
325
- const comment = yield* linear.createComment(id, body);
393
+ const comment = yield* linear.createComment(issueId, commentBody);
326
394
  if (json) {
327
395
  yield* Console.log(encodeJson(comment));
328
396
  return;
329
397
  }
330
398
  yield* Console.log(`Comment created: ${comment.url}`);
331
399
  }),
400
+ ).pipe(
401
+ Command.withDescription("Add a Markdown comment to an issue"),
402
+ Command.withExamples([
403
+ {
404
+ command: 'linear issue comment ENG-123 --body "Ready" --dry-run',
405
+ description: "Preview a comment without sending it",
406
+ },
407
+ {
408
+ command: 'linear issue comment ENG-123 --body "Ready" --json',
409
+ description: "Create a comment and return its URL",
410
+ },
411
+ ]),
332
412
  );
333
413
 
334
414
  // Combined issue command with subcommands
335
415
  export const issue = Command.make("issue", {}, () =>
336
416
  Console.log("Use 'linear issue list' to list issues. See --help for more."),
337
417
  ).pipe(
418
+ Command.withDescription("Read and mutate Linear issues"),
338
419
  Command.withSubcommands([
339
420
  issueListCommand,
340
421
  issueViewCommand,
@@ -356,18 +437,11 @@ const selectIssue = Effect.gen(function* () {
356
437
  }
357
438
 
358
439
  // 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
- );
440
+ const choices = allIssues.slice(0, 20).map((candidate) => ({
441
+ title: `${candidate.identifier}: ${truncate(candidate.title, 40)}`,
442
+ value: candidate.identifier,
443
+ description: candidate.state?.name ?? "Unknown state",
444
+ }));
371
445
 
372
446
  const selected = yield* Prompt.select({
373
447
  message: "Select an issue",
@@ -457,7 +531,7 @@ const resolveTeamId = Effect.fn("IssueCommand.resolveTeamId")(function* (
457
531
  });
458
532
 
459
533
  const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
460
- projects: readonly { id: string; name: string; slugId: string }[],
534
+ projects: readonly { id: string; name: string; slug: string }[],
461
535
  selector: string,
462
536
  ) {
463
537
  const normalized = selector.toLowerCase();
@@ -465,7 +539,7 @@ const resolveProjectId = Effect.fn("IssueCommand.resolveProjectId")(function* (
465
539
  (project) =>
466
540
  project.id === selector ||
467
541
  project.name.toLowerCase() === normalized ||
468
- project.slugId.toLowerCase() === normalized,
542
+ project.slug.toLowerCase() === normalized,
469
543
  );
470
544
  return selected === undefined
471
545
  ? yield* InvalidInputError.make({ message: `Unknown project: ${selector}` })
@@ -504,20 +578,3 @@ function getPriorityIcon(priority: number): string {
504
578
  return "○";
505
579
  }
506
580
  }
507
-
508
- function getPriorityLabel(priority: number): string {
509
- switch (priority) {
510
- case 0:
511
- return "No priority";
512
- case 1:
513
- return "Urgent";
514
- case 2:
515
- return "High";
516
- case 3:
517
- return "Medium";
518
- case 4:
519
- return "Low";
520
- default:
521
- return "Unknown";
522
- }
523
- }
@@ -1,13 +1,10 @@
1
1
  import { Console, Effect } from "effect";
2
- import { Command, Flag } from "effect/unstable/cli";
2
+ import { Command } from "effect/unstable/cli";
3
+ import { jsonFlag } from "../lib/flags.js";
3
4
  import { encodeJson } from "../lib/json.js";
4
5
  import { LinearService } from "../services/Linear.js";
5
6
 
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 }) =>
7
+ export const projectListCommand = Command.make("list", { json: jsonFlag }, ({ json }) =>
11
8
  Effect.gen(function* () {
12
9
  const linear = yield* LinearService;
13
10
  const projects = yield* linear.getProjects;
@@ -18,7 +15,7 @@ export const projectListCommand = Command.make("list", { json: jsonOption }, ({
18
15
  projects.map((project) => ({
19
16
  id: project.id,
20
17
  name: project.name,
21
- slug: project.slugId,
18
+ slug: project.slug,
22
19
  state: project.state,
23
20
  url: project.url,
24
21
  })),
@@ -38,8 +35,17 @@ export const projectListCommand = Command.make("list", { json: jsonOption }, ({
38
35
  }
39
36
  yield* Console.log("");
40
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
+ ]),
41
44
  );
42
45
 
43
46
  export const project = Command.make("project", {}, () =>
44
47
  Console.log("Use 'linear project list' to list projects. See --help for more."),
45
- ).pipe(Command.withSubcommands([projectListCommand]));
48
+ ).pipe(
49
+ Command.withDescription("Manage Linear projects"),
50
+ Command.withSubcommands([projectListCommand]),
51
+ );
@@ -1,14 +1,11 @@
1
- import { Command, Flag } from "effect/unstable/cli";
1
+ import { Command } from "effect/unstable/cli";
2
2
  import { Console, Effect } from "effect";
3
+ import { jsonFlag } from "../lib/flags.js";
3
4
  import { encodeJson } from "../lib/json.js";
4
5
  import { LinearService } from "../services/Linear.js";
5
6
 
6
- const jsonOption = Flag.boolean("json").pipe(
7
- Flag.withDescription("Emit stable JSON for scripts and agents"),
8
- );
9
-
10
7
  // linear team list - List all teams
11
- export const teamListCommand = Command.make("list", { json: jsonOption }, ({ json }) =>
8
+ export const teamListCommand = Command.make("list", { json: jsonFlag }, ({ json }) =>
12
9
  Effect.gen(function* () {
13
10
  const linear = yield* LinearService;
14
11
  const teams = yield* linear.getTeams;
@@ -44,9 +41,15 @@ export const teamListCommand = Command.make("list", { json: jsonOption }, ({ jso
44
41
 
45
42
  yield* Console.log("");
46
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
+ ]),
47
50
  );
48
51
 
49
52
  // Combined team command with subcommands
50
53
  export const team = Command.make("team", {}, () =>
51
54
  Console.log("Use 'linear team list' to list teams. See --help for more."),
52
- ).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
+ });