@zinn-dev/cli 0.37.0 → 0.38.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,5 +1,8 @@
1
- export function formatDescriptionPreview(description: string | null) {
2
- const DESCRIPTION_PREVIEW_LENGTH = 80;
1
+ export function formatDescriptionPreview(
2
+ description: string | null,
3
+ options: { maxLength?: number } = {},
4
+ ) {
5
+ const previewLength = options.maxLength ?? 80;
3
6
 
4
7
  if (description == null) {
5
8
  return "";
@@ -7,9 +10,9 @@ export function formatDescriptionPreview(description: string | null) {
7
10
 
8
11
  const normalizedDescription = description.replace(/\s+/g, " ").trim();
9
12
 
10
- if (normalizedDescription.length <= DESCRIPTION_PREVIEW_LENGTH) {
13
+ if (normalizedDescription.length <= previewLength) {
11
14
  return normalizedDescription;
12
15
  }
13
16
 
14
- return `${normalizedDescription.slice(0, DESCRIPTION_PREVIEW_LENGTH - 1).trimEnd()}…`;
17
+ return `${normalizedDescription.slice(0, previewLength - 1).trimEnd()}…`;
15
18
  }
@@ -20,12 +20,13 @@ export type PresentedTask = {
20
20
  const EMPTY_CELL_MARKER = "-";
21
21
  const LABEL_NAME_SEPARATOR = ", ";
22
22
 
23
- function taskPriorityCell(priority: TaskPriority | null): RowCell {
23
+ function taskPriorityCell(priority: TaskPriority | null, showsFullPriority: boolean): RowCell {
24
24
  if (priority == null) {
25
25
  return { text: EMPTY_CELL_MARKER, style: "dim" };
26
26
  }
27
27
 
28
- return { text: priority[0]!.toUpperCase() };
28
+ const priorityInitial = priority[0]!.toUpperCase();
29
+ return { text: showsFullPriority ? `${priorityInitial}${priority.slice(1)}` : priorityInitial };
29
30
  }
30
31
 
31
32
  /**
@@ -60,7 +61,7 @@ export function formatTaskRow(presented: PresentedTask) {
60
61
 
61
62
  export function formatTaskList(
62
63
  presentedTasks: Array<PresentedTask>,
63
- options: { showsStatus?: boolean } = {},
64
+ options: { showsStatus?: boolean; showsFullPriority?: boolean } = {},
64
65
  ) {
65
66
  const labelColorsByName = getLabelColorsByName();
66
67
 
@@ -79,7 +80,7 @@ export function formatTaskList(
79
80
  { text: presentedTask.key },
80
81
  ...statusCells,
81
82
  columnNameCell(presentedTask.column),
82
- taskPriorityCell(presentedTask.priority),
83
+ taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
83
84
  { text: `${presentedTask.title}${labels}` },
84
85
  ];
85
86
  }),
@@ -0,0 +1,17 @@
1
+ const MINUTES_PER_HOUR = 60;
2
+
3
+ export function formatLocalTime(timestamp: number) {
4
+ const date = new Date(timestamp);
5
+ const offsetMinutes = -date.getTimezoneOffset();
6
+ const offsetSign = offsetMinutes >= 0 ? "+" : "-";
7
+ const absoluteOffsetMinutes = Math.abs(offsetMinutes);
8
+ const offsetHours = Math.floor(absoluteOffsetMinutes / MINUTES_PER_HOUR);
9
+ const remainingOffsetMinutes = absoluteOffsetMinutes % MINUTES_PER_HOUR;
10
+ const pad = (value: number) => String(value).padStart(2, "0");
11
+
12
+ return (
13
+ `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
14
+ `${pad(date.getHours())}:${pad(date.getMinutes())} ` +
15
+ `${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`
16
+ );
17
+ }
@@ -0,0 +1,77 @@
1
+ import type { RouteDef } from "../types";
2
+
3
+ import { parseArgs } from "node:util";
4
+ import { activity, activityLimitMessage, positiveIntegerPattern } from "@zinn-dev/core";
5
+ import { output, quit, validatePositionals, validateUniqueOptions } from "../lib";
6
+ import { formatActivityList, presentActivities } from "../presentation/activity-presentation";
7
+
8
+ export const activityRouter = {
9
+ list: {
10
+ run: (args) => {
11
+ const { values, positionals, tokens } = parseArgs({
12
+ args,
13
+ options: { task: { type: "string" }, limit: { type: "string" } },
14
+ allowPositionals: true,
15
+ strict: true,
16
+ tokens: true,
17
+ });
18
+ validateUniqueOptions(tokens);
19
+ validatePositionals(positionals, []);
20
+
21
+ // Safe integers can have one more digit than readable task numbers.
22
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}\\d?$`);
23
+ if (values.limit !== undefined && !limitPattern.test(values.limit)) {
24
+ quit(activityLimitMessage);
25
+ }
26
+
27
+ const events = activity.getAll({
28
+ taskKey: values.task,
29
+ limit: values.limit === undefined ? undefined : Number(values.limit),
30
+ });
31
+
32
+ output(events, (items) =>
33
+ formatActivityList(presentActivities(items, { taskKey: values.task })),
34
+ );
35
+ },
36
+ help: `Usage: zinn activity list [--task <task-key>] [--limit <n>] [--json]
37
+
38
+ List recorded activity across the database, newest first.
39
+ By default, all matching events are returned. --limit takes a positive safe integer.
40
+ --task includes existing, archived and deleted task lifetimes for that key,
41
+ including the recorded project deletion that removed a task.
42
+ A key reused after project deletion includes every known lifetime.
43
+ A valid key without recoverable history returns an empty list.
44
+
45
+ Text times are local dates/times with a UTC offset.
46
+ Event IDs are the shortest globally unique left prefixes of at least eight hex digits.
47
+ Use activity view for full recorded changes; full IDs are durable, short prefixes may become ambiguous.
48
+ With --json, output is an array of full activity records, with parsed changes or null.
49
+
50
+ Examples:
51
+ zinn activity list --limit 10
52
+ zinn activity list --task APP-2 --json`,
53
+ },
54
+ view: {
55
+ run: (args) => {
56
+ const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
57
+ validatePositionals(positionals, ["<activity-id>"]);
58
+ output(activity.getById(positionals[0]!), (event) =>
59
+ formatActivityList(presentActivities([event], { showsFullIds: true }), {
60
+ showsDetails: true,
61
+ }),
62
+ );
63
+ },
64
+ help: `Usage: zinn activity view <activity-id> [--json]
65
+
66
+ Show one recorded event with full activity/entity IDs, actor and complete changes.
67
+ Text and line breaks are preserved; unknown change fields remain available as raw JSON.
68
+ Text times are local dates/times with a UTC offset.
69
+
70
+ Accept a full UUID or unique left prefix with at least eight hexadecimal digits.
71
+ Matching ignores case and accepts canonical hyphens or uninterrupted hexadecimal digits.
72
+ An ambiguous prefix lists candidate IDs and requires more characters.
73
+ With --json, output is one full activity record, with parsed changes or null.
74
+
75
+ Example: zinn activity view 019abcdf-1234-7`,
76
+ },
77
+ } satisfies RouteDef;
@@ -3,12 +3,13 @@ import type { Command } from "../types";
3
3
  import { parseArgs } from "node:util";
4
4
  import { backup } from "@zinn-dev/core";
5
5
 
6
- import { output } from "../lib";
6
+ import { output, validatePositionals } from "../lib";
7
7
  import packageJson from "../../package.json";
8
8
 
9
9
  export const backupCommand = {
10
10
  run: (args) => {
11
- parseArgs({ args, strict: true, allowPositionals: false });
11
+ const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
12
+ validatePositionals(positionals, []);
12
13
 
13
14
  const created = backup.create({ client: "cli", version: packageJson.version });
14
15
 
@@ -9,11 +9,13 @@ import {
9
9
  confirmAction,
10
10
  output,
11
11
  quit,
12
- validatePositionalCount,
12
+ validatePositionals,
13
13
  validateUniqueOptions,
14
14
  } from "../lib";
15
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
15
16
  import { currentActor } from "../actor";
16
17
  import { formatRows } from "../presentation/row-layout";
18
+ import { formatLocalTime } from "../presentation/time";
17
19
 
18
20
  type PresentedComment = Pick<CommentWithKey, "key" | "text" | "created_at" | "updated_at">;
19
21
 
@@ -30,25 +32,9 @@ export function presentComments(taskKey: string) {
30
32
  return comment.getAll(taskKey).map(presentComment);
31
33
  }
32
34
 
33
- function formatCommentCreatedAt(createdAt: number) {
34
- const date = new Date(createdAt);
35
- const offsetMinutes = -date.getTimezoneOffset();
36
- const offsetSign = offsetMinutes >= 0 ? "+" : "-";
37
- const absoluteOffsetMinutes = Math.abs(offsetMinutes);
38
- const offsetHours = Math.floor(absoluteOffsetMinutes / 60);
39
- const remainingOffsetMinutes = absoluteOffsetMinutes % 60;
40
- const pad = (value: number) => String(value).padStart(2, "0");
41
-
42
- return (
43
- `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
44
- `${pad(date.getHours())}:${pad(date.getMinutes())} ` +
45
- `${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`
46
- );
47
- }
48
-
49
35
  function commentRow(commentMatch: PresentedComment, options: { showsCreatedAt: boolean }) {
50
36
  const createdAtCells: Array<RowCell> = options.showsCreatedAt
51
- ? [{ text: formatCommentCreatedAt(commentMatch.created_at), style: "dim" }]
37
+ ? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
52
38
  : [];
53
39
 
54
40
  return [{ text: commentMatch.key }, ...createdAtCells, { text: commentMatch.text }];
@@ -67,7 +53,7 @@ export function formatComments(comments: Array<PresentedComment>) {
67
53
  );
68
54
  }
69
55
 
70
- function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
56
+ function parseTextArgs(args: Array<string>) {
71
57
  const { values, positionals, tokens } = parseArgs({
72
58
  args,
73
59
  options: { text: { type: "string" } },
@@ -76,8 +62,8 @@ function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
76
62
  tokens: true,
77
63
  });
78
64
 
79
- validatePositionalCount(positionals, 1, `Exactly one ${entityName} key is required`);
80
65
  validateUniqueOptions(tokens);
66
+ validatePositionals(positionals, ["<task-key>"]);
81
67
 
82
68
  if (values.text === undefined) {
83
69
  quit("Comment text must be specified with --text");
@@ -86,10 +72,30 @@ function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
86
72
  return { key: positionals[0]!, text: values.text };
87
73
  }
88
74
 
75
+ function parseCommentEditArgs(args: Array<string>) {
76
+ const { values, positionals, tokens } = parseArgs({
77
+ args,
78
+ options: { text: { type: "string" }, ...textEditOptions },
79
+ allowPositionals: true,
80
+ strict: true,
81
+ tokens: true,
82
+ });
83
+
84
+ validateUniqueOptions(tokens);
85
+ validatePositionals(positionals, ["<comment-key>"]);
86
+
87
+ const text = resolveTextEdit(values.text, values, "--text");
88
+ if (text === undefined) {
89
+ quit("Comment text must be specified with --text");
90
+ }
91
+
92
+ return { key: positionals[0]!, text };
93
+ }
94
+
89
95
  export const commentRouter = {
90
96
  create: {
91
97
  run: (args) => {
92
- const props = parseTextArgs(args, "task");
98
+ const props = parseTextArgs(args);
93
99
  const created = comment.create({ taskKey: props.key, text: props.text }, currentActor());
94
100
  output(presentComment(created), formatComment);
95
101
  },
@@ -103,7 +109,7 @@ Example: zinn task comment create MDR-1 --text "Ready for review"`,
103
109
  list: {
104
110
  run: (args) => {
105
111
  const { positionals } = parseArgs({ args, allowPositionals: true, strict: true });
106
- validatePositionalCount(positionals, 1, "Exactly one task key is required");
112
+ validatePositionals(positionals, ["<task-key>"]);
107
113
  output(presentComments(positionals[0]!), formatComments);
108
114
  },
109
115
  help: `Usage: zinn task comment list <task-key>
@@ -114,25 +120,31 @@ Example: zinn task comment list MDR-1`,
114
120
  },
115
121
  edit: {
116
122
  run: (args) => {
117
- const props = parseTextArgs(args, "comment");
123
+ const props = parseCommentEditArgs(args);
118
124
  const edited = comment.edit({ commentKey: props.key, text: props.text }, currentActor());
119
125
  output(presentComment(edited), formatComment);
120
126
  },
121
- help: `Usage: zinn task comment edit <comment-key> --text <text>
127
+ help: `Usage: zinn task comment edit <comment-key> --text <text> ${textEditUsage}
122
128
 
123
129
  Replace a comment's text. Comment text cannot be blank.
124
130
 
125
- Example: zinn task comment edit MDR-1#2 --text "Approved"`,
131
+ ${textEditHelp("--text")}
132
+
133
+ Examples:
134
+ zinn task comment edit MDR-1#2 --text "Approved"
135
+ zinn task comment edit MDR-1#2 --text "Also approved." --append`,
126
136
  },
127
137
  delete: {
128
138
  run: (args) => {
129
- const { values, positionals } = parseArgs({
139
+ const { values, positionals, tokens } = parseArgs({
130
140
  args,
131
141
  options: { yes: { type: "boolean" } },
132
142
  allowPositionals: true,
133
143
  strict: true,
144
+ tokens: true,
134
145
  });
135
- validatePositionalCount(positionals, 1, "Exactly one comment key is required");
146
+ validateUniqueOptions(tokens);
147
+ validatePositionals(positionals, ["<comment-key>"]);
136
148
 
137
149
  const commentMatch = comment.getByKey(positionals[0]!);
138
150
  const canDelete = confirmAction(
@@ -5,13 +5,8 @@ import type { RouteDef } from "../types";
5
5
  import { parseArgs } from "node:util";
6
6
  import { label, labelCreateSchema, labelDeleteSchema, labelEditSchema } from "@zinn-dev/core";
7
7
 
8
- import {
9
- confirmAction,
10
- output,
11
- quit,
12
- validatePositionalCount,
13
- validateUniqueOptions,
14
- } from "../lib";
8
+ import { confirmAction, output, quit, validatePositionals, validateUniqueOptions } from "../lib";
9
+ import { resolveTextEdit, textEditHelp, textEditOptions, textEditUsage } from "../text-edit";
15
10
  import { currentActor } from "../actor";
16
11
  import { isColorEnabled } from "../presentation/color";
17
12
  import { formatRows } from "../presentation/row-layout";
@@ -56,9 +51,8 @@ export const labelRouter = {
56
51
  tokens: true,
57
52
  });
58
53
 
59
- validatePositionalCount(positionals, 1, "Exactly one label name is required");
60
-
61
54
  validateUniqueOptions(tokens);
55
+ validatePositionals(positionals, ["<name>"]);
62
56
 
63
57
  const input = labelCreateSchema.parse({ name: positionals[0], ...values });
64
58
  const created = label.create(input, currentActor());
@@ -68,7 +62,7 @@ export const labelRouter = {
68
62
  help: `Usage: zinn label create <name> [--description <text>] [--color <color>]
69
63
 
70
64
  Create a global label. Names preserve casing, but uniqueness is case-insensitive.
71
- Names are trimmed and cannot be blank.
65
+ Names are trimmed and cannot be blank or contain line breaks or control characters.
72
66
  Description is optional.
73
67
 
74
68
  Color defaults to white.
@@ -78,7 +72,9 @@ Example: zinn label create bug --description "Unexpected behavior" --color red`,
78
72
  },
79
73
  list: {
80
74
  run: (args) => {
81
- parseArgs({ args, strict: true, allowPositionals: false });
75
+ const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
76
+ validatePositionals(positionals, []);
77
+
82
78
  output(label.getAll().map(presentLabel), formatLabelList);
83
79
  },
84
80
  help: `Usage: zinn label list
@@ -92,6 +88,7 @@ List all global label definitions.`,
92
88
  options: {
93
89
  name: { type: "string" },
94
90
  description: { type: "string" },
91
+ ...textEditOptions,
95
92
  color: { type: "string" },
96
93
  },
97
94
  allowPositionals: true,
@@ -99,35 +96,46 @@ List all global label definitions.`,
99
96
  tokens: true,
100
97
  });
101
98
 
102
- validatePositionalCount(positionals, 1, "Exactly one label name is required");
103
99
  validateUniqueOptions(tokens);
100
+ validatePositionals(positionals, ["<name>"]);
104
101
 
105
- const input = labelEditSchema.parse({ labelName: positionals[0], ...values });
102
+ const input = labelEditSchema.parse({
103
+ labelName: positionals[0],
104
+ name: values.name,
105
+ description: resolveTextEdit(values.description, values, "--description"),
106
+ color: values.color,
107
+ });
106
108
  const edited = label.edit(input, currentActor());
107
109
 
108
110
  output(presentLabel(edited), formatLabel);
109
111
  },
110
- help: `Usage: zinn label edit <name> [--name <text>] [--description <text>] [--color <color>]
112
+ help: `Usage: zinn label edit <name> [--name <text>] [--description <text> ${textEditUsage}] [--color <color>]
111
113
 
112
114
  Change specified fields.
113
115
  Provide at least one edit flag. Use --description "" to clear the description.
114
116
 
117
+ ${textEditHelp("--description")}
118
+
115
119
  Names are matched and kept unique case-insensitively while preserving their casing.
116
120
  Names are trimmed. Changing only the casing is allowed.
117
121
  Editing does not affect task attachments or task timestamps.
118
122
 
119
- Example: zinn label edit bug --name defect --color yellow`,
123
+ Examples:
124
+ zinn label edit bug --name defect --color yellow
125
+ zinn label edit bug --description "Reported by users." --append`,
120
126
  },
121
127
  delete: {
122
128
  run: (args) => {
123
- const { values, positionals } = parseArgs({
129
+ const { values, positionals, tokens } = parseArgs({
124
130
  args,
125
131
  options: { yes: { type: "boolean" } },
126
132
  strict: true,
127
133
  allowPositionals: true,
134
+ tokens: true,
128
135
  });
129
136
 
130
- validatePositionalCount(positionals, 1, "Exactly one label name is required");
137
+ validateUniqueOptions(tokens);
138
+ validatePositionals(positionals, ["<name>"]);
131
139
 
132
140
  const props = labelDeleteSchema.parse({ name: positionals[0] });
133
141
  const labelMatch = label.getByName(props.name);
@@ -4,12 +4,14 @@ import { parseArgs } from "node:util";
4
4
  import { migrate, MigrationRefusedError, getStorage } from "@zinn-dev/core";
5
5
 
6
6
  import { reportLockWait } from "../database";
7
- import { output } from "../lib";
7
+ import { output, validatePositionals } from "../lib";
8
8
  import packageJson from "../../package.json";
9
9
 
10
10
  export const migrateCommand = {
11
11
  run: (args) => {
12
- parseArgs({ args, strict: true, allowPositionals: false });
12
+ const { positionals } = parseArgs({ args, strict: true, allowPositionals: true });
13
+ validatePositionals(positionals, []);
14
+
13
15
  // Resolved before the try, so a store that cannot be resolved fails without the note about backups.
14
16
  const { backupDirectory } = getStorage();
15
17