@zinn-dev/cli 0.20.0 → 0.22.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 CHANGED
@@ -71,6 +71,28 @@ zinn task view MDR-1
71
71
 
72
72
  When a project key is supplied, the list follows the project's column order and the task order within each column.
73
73
 
74
+ ## Search tasks
75
+
76
+ Search task titles, descriptions, and comments, optionally in one project:
77
+
78
+ ```sh
79
+ zinn task search refine
80
+ zinn task search "quarterly quota" MDR
81
+ zinn task search MDR-1
82
+ zinn task search auth --all --limit 5
83
+ ```
84
+
85
+ Each query matches the start of a word, ignoring case and accents, so `cafe` finds "Café" and `auth` finds "Authentication". Every word must match somewhere in the task: its title, its description, or any of its comments. A comment match lists the task the comment belongs to.
86
+
87
+ If the whole query is an existing task key, such as `mdr-1`, that task comes first. Other results follow by relevance, with title matches weighted highest. Equally relevant tasks are ordered by project key, then task number.
88
+
89
+ Note that by default only the active tasks are searched.
90
+ `--archived` searches only archived tasks and `--all` searches both, just like how it is with `task list`. When archived matches are left out, Zinn prints a note such as `2 archived matches hidden, use --all to include them`. This extra info is not a part of the `--json` output. `--limit <n>` shows at most `n` results.
91
+
92
+ Results use the same rows and `--json` shape as `task list`. A search with no results prints nothing and exits successfully. Put `--` before a query that begins with a dash: `zinn task search -- -flag`.
93
+
94
+ Search uses an index that Zinn keeps up to date as tasks and comments change.
95
+
74
96
  ## Labels
75
97
 
76
98
  Labels are global and reusable in all the available projects.
@@ -140,7 +162,8 @@ zinn task comment list MDR-1
140
162
  ```
141
163
 
142
164
  Comments receive keys per task like `MDR-1#1`.
143
- `task view` includes the task's comments.
165
+ Comment lists show each comment's creation time in local time as `YYYY-MM-DD HH:mm ±HH:mm`.
166
+ `task view` includes the task's comments in the same format.
144
167
 
145
168
  Edit or delete a comment using its key:
146
169
 
package/index.ts CHANGED
@@ -27,6 +27,7 @@ Commands:
27
27
  project column list
28
28
  task create
29
29
  task list
30
+ task search
30
31
  task view
31
32
  task edit
32
33
  task move
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "A kanban workflow in the terminal.",
5
5
  "license": "MIT",
6
6
  "bugs": {
@@ -42,6 +42,6 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@zinn-dev/core": "0.14.0"
45
+ "@zinn-dev/core": "0.15.0"
46
46
  }
47
47
  }
@@ -28,14 +28,39 @@ export function presentComments(taskKey: string) {
28
28
  return comment.getAll(taskKey).map(presentComment);
29
29
  }
30
30
 
31
- export function formatComment(commentMatch: PresentedComment) {
32
- const continuationIndent = " ".repeat(`${commentMatch.key} | `.length);
31
+ function formatCommentCreatedAt(createdAt: number) {
32
+ const date = new Date(createdAt);
33
+ const offsetMinutes = -date.getTimezoneOffset();
34
+ const offsetSign = offsetMinutes >= 0 ? "+" : "-";
35
+ const absoluteOffsetMinutes = Math.abs(offsetMinutes);
36
+ const offsetHours = Math.floor(absoluteOffsetMinutes / 60);
37
+ const remainingOffsetMinutes = absoluteOffsetMinutes % 60;
38
+ const pad = (value: number) => String(value).padStart(2, "0");
39
+
40
+ return (
41
+ `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
42
+ `${pad(date.getHours())}:${pad(date.getMinutes())} ` +
43
+ `${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`
44
+ );
45
+ }
46
+
47
+ export function formatComment(
48
+ commentMatch: PresentedComment,
49
+ options: { showsCreatedAt?: boolean } = {},
50
+ ) {
51
+ const createdAt = options.showsCreatedAt
52
+ ? ` | ${formatCommentCreatedAt(commentMatch.created_at)}`
53
+ : "";
54
+ const prefix = `${commentMatch.key}${createdAt} | `;
55
+ const continuationIndent = " ".repeat(prefix.length);
33
56
  const text = commentMatch.text.split(/\r?\n/).join(`\n${continuationIndent}`);
34
- return `${commentMatch.key} | ${text}`;
57
+ return `${prefix}${text}`;
35
58
  }
36
59
 
37
60
  export function formatComments(comments: Array<PresentedComment>) {
38
- return comments.map(formatComment).join("\n");
61
+ return comments
62
+ .map((commentMatch) => formatComment(commentMatch, { showsCreatedAt: true }))
63
+ .join("\n");
39
64
  }
40
65
 
41
66
  function parseTextArgs(args: Array<string>, entityName: "task" | "comment") {
@@ -64,6 +64,22 @@ test("router calls the deepest nesting command", () => {
64
64
  expect(routes.foo.create.run).not.toHaveBeenCalled();
65
65
  });
66
66
 
67
+ test("only arguments before the first -- are treated as router flags", () => {
68
+ const run = mock(() => {});
69
+ const router = createRouter({ foo: { run, help: "" } });
70
+
71
+ router.route(["foo", "--", "--json", "--help"]);
72
+ expect(run).toHaveBeenCalledWith(["--", "--json", "--help"]);
73
+ });
74
+
75
+ test("router flags before a -- still apply", () => {
76
+ const run = mock(() => {});
77
+ const router = createRouter({ foo: { run, help: "" } });
78
+
79
+ router.route(["foo", "--json", "--", "literal"]);
80
+ expect(run).toHaveBeenCalledWith(["--", "literal"]);
81
+ });
82
+
67
83
  test("a help request never runs a command even when its help is empty", () => {
68
84
  const run = mock(() => {});
69
85
  const info = spyOn(console, "info").mockImplementation(() => {});
@@ -47,17 +47,21 @@ export function parseRoutes(routesDef: RouteDef, prefix?: string) {
47
47
  }
48
48
 
49
49
  function route(parsedRoutes: Array<ParsedRoute>, rawArgs: Array<string>) {
50
- // Stripped here so commands with strict `parseArgs` never see an unknown "--json" option
51
- const args = rawArgs.filter((arg) => !isJsonFlag(arg));
50
+ // Anything after "--" belongs to the command, so "--json" there is search text, not a flag.
51
+ const separatorIndex = rawArgs.indexOf("--");
52
+ const routableArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
53
+ const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex);
54
+ const filteredRoutableArgs = routableArgs.filter((arg) => !isJsonFlag(arg));
52
55
 
53
- if (args.length !== rawArgs.length) {
56
+ if (filteredRoutableArgs.length !== routableArgs.length) {
54
57
  setOutputMode("json");
55
58
  }
56
59
 
57
- const isHelpRequest = isHelpFlag(args.at(-1) ?? "");
60
+ const args = [...filteredRoutableArgs, ...passthroughArgs];
61
+ const isHelpRequest = isHelpFlag(filteredRoutableArgs.at(-1) ?? "");
58
62
 
59
63
  if (isHelpRequest && args.length > 1) {
60
- const namespace = toCommand(args.slice(0, -1));
64
+ const namespace = toCommand(filteredRoutableArgs.slice(0, -1));
61
65
  const namespaceHelp = getNamespaceHelp(parsedRoutes, namespace);
62
66
  if (namespaceHelp != null) {
63
67
  console.info(namespaceHelp);
@@ -1,7 +1,7 @@
1
1
  import type { RouteDef } from "../types";
2
2
 
3
3
  import { parseArgs } from "node:util";
4
- import { task, project } from "@zinn-dev/core";
4
+ import { task, project, positiveIntegerPattern, searchLimitMessage } from "@zinn-dev/core";
5
5
 
6
6
  import {
7
7
  confirmAction,
@@ -21,6 +21,8 @@ import {
21
21
  presentTask,
22
22
  } from "../presentation/task-presentation";
23
23
 
24
+ const limitPattern = new RegExp(`^${positiveIntegerPattern}$`);
25
+
24
26
  export const taskRouter = {
25
27
  edit: {
26
28
  run: (args) => {
@@ -175,6 +177,74 @@ Use --archived to list archived tasks or --all to list both.
175
177
  Priority markers: - unassigned, L low, M medium, H high, U urgent.
176
178
 
177
179
  Example: zinn task list MDR --all`,
180
+ },
181
+ search: {
182
+ run: (args) => {
183
+ const { values, positionals, tokens } = parseArgs({
184
+ args,
185
+ options: {
186
+ archived: { type: "boolean" },
187
+ all: { type: "boolean" },
188
+ limit: { type: "string" },
189
+ },
190
+ allowPositionals: true,
191
+ strict: true,
192
+ tokens: true,
193
+ });
194
+
195
+ const [query, projectKey] = positionals;
196
+
197
+ if (query == null) {
198
+ quit("A search query must be specified");
199
+ }
200
+
201
+ if (positionals.length > 2) {
202
+ quit("Only one query and one project key can be specified; quote multi-word queries");
203
+ }
204
+
205
+ validateUniqueOptions(tokens);
206
+
207
+ if (values.archived && values.all) {
208
+ quit('Use either "--archived" or "--all", not both');
209
+ }
210
+
211
+ const archive = values.all ? "all" : values.archived ? "archived" : "active";
212
+
213
+ if (values.limit !== undefined && !limitPattern.test(values.limit)) {
214
+ quit(searchLimitMessage);
215
+ }
216
+
217
+ const limit = values.limit === undefined ? undefined : Number(values.limit);
218
+ const result = task.search({ query, projectKey, archive, limit });
219
+
220
+ output(result.tasks.map(presentTask), (presentedTasks) =>
221
+ formatTaskList(presentedTasks, { showsStatus: values.all }),
222
+ );
223
+
224
+ if (result.hiddenArchivedCount > 0) {
225
+ const count = result.hiddenArchivedCount;
226
+ const noun = count === 1 ? "match" : "matches";
227
+ console.error(`${count} archived ${noun} hidden, use --all to include them`);
228
+ }
229
+ },
230
+ help: `Usage: zinn task search <query> [project-key] [--archived | --all] [--limit <n>]
231
+
232
+ Search task titles, descriptions, and comments. A comment match lists the task it belongs to.
233
+ Each word matches the start of a word, ignoring case and accents: e.g. "auth" finds "Authentication".
234
+ Every word must match. Quote a query with several words.
235
+
236
+ A query that is exactly a task key, such as MDR-1, lists that task first.
237
+ Other results are ordered by relevance, with title matches weighted highest.
238
+ Equally relevant tasks are ordered by project key, then task number.
239
+
240
+ By default, only active tasks are searched. Use --archived to search archived tasks or --all to search both.
241
+ When archived matches are hidden, a note is printed to say how many.
242
+ Use --limit to show at most <n> results.
243
+ A search result's output matches that of 'task list'.
244
+
245
+ Use -- before a query that begins with a dash.
246
+
247
+ Example: zinn task search "refinement quota" MDR --limit 5`,
178
248
  },
179
249
  view: {
180
250
  run: (args) => {