@zinn-dev/cli 0.40.0 → 0.42.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.
Files changed (84) hide show
  1. package/README.md +11 -561
  2. package/index.js +24 -13
  3. package/package.json +8 -2
  4. package/skills/zinn/SKILL.md +63 -0
  5. package/src/actor.d.ts +2 -1
  6. package/src/actor.js +78 -11
  7. package/src/capabilities-schema.d.ts +162 -0
  8. package/src/capabilities-schema.js +59 -0
  9. package/src/capabilities.d.ts +29 -0
  10. package/src/capabilities.js +30 -0
  11. package/src/column-hint.d.ts +3 -0
  12. package/src/column-hint.js +225 -0
  13. package/src/database.d.ts +1 -1
  14. package/src/database.js +5 -8
  15. package/src/errors.d.ts +158 -0
  16. package/src/errors.js +226 -0
  17. package/src/input.d.ts +227 -0
  18. package/src/input.js +192 -0
  19. package/src/lib.d.ts +71 -8
  20. package/src/lib.js +275 -18
  21. package/src/presentation/activity-presentation.d.ts +9 -1
  22. package/src/presentation/activity-presentation.js +120 -23
  23. package/src/presentation/capabilities-presentation.d.ts +2 -0
  24. package/src/presentation/capabilities-presentation.js +3 -0
  25. package/src/presentation/column-presentation.d.ts +9 -5
  26. package/src/presentation/column-presentation.js +10 -0
  27. package/src/presentation/comment-presentation.d.ts +15 -0
  28. package/src/presentation/comment-presentation.js +29 -0
  29. package/src/presentation/description-presentation.d.ts +17 -0
  30. package/src/presentation/description-presentation.js +26 -4
  31. package/src/presentation/info-presentation.d.ts +4 -0
  32. package/src/presentation/info-presentation.js +96 -0
  33. package/src/presentation/label-presentation.d.ts +8 -0
  34. package/src/presentation/label-presentation.js +28 -0
  35. package/src/presentation/project-presentation.d.ts +7 -0
  36. package/src/presentation/project-presentation.js +19 -0
  37. package/src/presentation/relation-presentation.d.ts +7 -0
  38. package/src/presentation/relation-presentation.js +73 -0
  39. package/src/presentation/task-presentation.d.ts +4 -12
  40. package/src/presentation/task-presentation.js +22 -18
  41. package/src/project.d.ts +18 -3
  42. package/src/project.js +37 -12
  43. package/src/result-schemas.d.ts +1194 -0
  44. package/src/result-schemas.js +279 -0
  45. package/src/results.d.ts +40 -0
  46. package/src/results.js +36 -0
  47. package/src/routes/activity-router.d.ts +104 -0
  48. package/src/routes/activity-router.js +155 -34
  49. package/src/routes/aliases.d.ts +2 -0
  50. package/src/routes/aliases.js +11 -0
  51. package/src/routes/backup-router.d.ts +17 -0
  52. package/src/routes/backup-router.js +15 -3
  53. package/src/routes/capabilities-router.d.ts +21 -0
  54. package/src/routes/capabilities-router.js +34 -0
  55. package/src/routes/comment-router.d.ts +210 -8
  56. package/src/routes/comment-router.js +189 -65
  57. package/src/routes/info-router.d.ts +21 -0
  58. package/src/routes/info-router.js +29 -0
  59. package/src/routes/label-router.d.ts +217 -2
  60. package/src/routes/label-router.js +189 -62
  61. package/src/routes/migrate-router.d.ts +17 -0
  62. package/src/routes/migrate-router.js +17 -5
  63. package/src/routes/project-router.d.ts +373 -2
  64. package/src/routes/project-router.js +322 -132
  65. package/src/routes/reindex-router.d.ts +17 -0
  66. package/src/routes/reindex-router.js +15 -3
  67. package/src/routes/relation-router.d.ts +110 -14
  68. package/src/routes/relation-router.js +122 -79
  69. package/src/routes/restore-router.d.ts +29 -0
  70. package/src/routes/restore-router.js +31 -14
  71. package/src/routes/router.d.ts +1 -1
  72. package/src/routes/router.js +80 -32
  73. package/src/routes/routes.d.ts +1781 -8
  74. package/src/routes/routes.js +9 -1
  75. package/src/routes/task-router.d.ts +946 -4
  76. package/src/routes/task-router.js +524 -260
  77. package/src/routes/whoami-router.d.ts +21 -0
  78. package/src/routes/whoami-router.js +31 -0
  79. package/src/text-edit.d.ts +28 -6
  80. package/src/text-edit.js +40 -23
  81. package/src/text-input.d.ts +47 -0
  82. package/src/text-input.js +187 -0
  83. package/src/types.d.ts +37 -0
  84. package/src/types.js +9 -1
@@ -1,6 +1,16 @@
1
+ import { project } from "@zinn-dev/core";
1
2
  import { formatRows } from "./row-layout.js";
2
3
  /** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
3
4
  const ARCHIVED_ROW_LABEL = "Archived";
5
+ export function presentColumn(columnMatch) {
6
+ const columnProject = project.getById(columnMatch.project_id);
7
+ return {
8
+ id: columnMatch.id,
9
+ project: columnProject.key,
10
+ project_id: columnMatch.project_id,
11
+ name: columnMatch.name,
12
+ };
13
+ }
4
14
  export function columnNameCell(columnName) {
5
15
  // TODO: Derive column colors from column roles once roles exist instead of relying on names.
6
16
  if (columnName === "Backlog") {
@@ -0,0 +1,15 @@
1
+ import type { CommentWithKey } from "@zinn-dev/core";
2
+ import type { PresentedComment } from "../result-schemas.js";
3
+ export declare function presentComment(commentMatch: CommentWithKey): PresentedComment;
4
+ export declare function presentComments(taskKey: string): {
5
+ id: string;
6
+ key: string;
7
+ task_id: string;
8
+ text: string;
9
+ created_at: number;
10
+ updated_at: number;
11
+ }[];
12
+ export declare function formatCommentList(comments: Array<PresentedComment>, { showsCreatedAt, showsTextPreview }?: {
13
+ showsCreatedAt?: boolean | undefined;
14
+ showsTextPreview?: boolean | undefined;
15
+ }): string;
@@ -0,0 +1,29 @@
1
+ import { comment } from "@zinn-dev/core";
2
+ import { formatDescriptionPreview } from "./description-presentation.js";
3
+ import { formatRows } from "./row-layout.js";
4
+ import { formatLocalTime } from "./time.js";
5
+ export function presentComment(commentMatch) {
6
+ return {
7
+ id: commentMatch.id,
8
+ key: commentMatch.key,
9
+ task_id: commentMatch.task_id,
10
+ text: commentMatch.text,
11
+ created_at: commentMatch.created_at,
12
+ updated_at: commentMatch.updated_at,
13
+ };
14
+ }
15
+ export function presentComments(taskKey) {
16
+ return comment.getAll(taskKey).map(presentComment);
17
+ }
18
+ function commentRow(commentMatch, options) {
19
+ const createdAtCells = options.showsCreatedAt
20
+ ? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
21
+ : [];
22
+ const text = options.showsTextPreview
23
+ ? formatDescriptionPreview(commentMatch.text, { firstLineOnly: true })
24
+ : commentMatch.text;
25
+ return [{ text: commentMatch.key }, ...createdAtCells, { text }];
26
+ }
27
+ export function formatCommentList(comments, { showsCreatedAt = true, showsTextPreview = false } = {}) {
28
+ return formatRows(comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt, showsTextPreview })), { indentsContinuationLines: true });
29
+ }
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Formats a description preview, capped at `maxLength` (80 by default)
3
+ * and ending with an ellipsis when shortened.
4
+ *
5
+ * The cap counts UTF-16 units, which means it can land inside an emoji 😀
6
+ * and cut it in half 🫡.
7
+ * The cut half cannot render, so it is dropped.
8
+ *
9
+ * @example
10
+ * // The cut lands after both halves, so the emoji is kept.
11
+ * formatDescriptionPreview("a😀zz", { maxLength: 4 }); // "a😀…"
12
+ *
13
+ * @example
14
+ * // The cut lands between the halves, so the orphaned half is dropped.
15
+ * formatDescriptionPreview("a😀z", { maxLength: 3 }); // "a…"
16
+ */
1
17
  export declare function formatDescriptionPreview(description: string | null, options?: {
2
18
  maxLength?: number;
19
+ firstLineOnly?: boolean;
3
20
  }): string;
@@ -1,11 +1,33 @@
1
+ const DEFAULT_PREVIEW_LENGTH = 80;
2
+ /**
3
+ * Formats a description preview, capped at `maxLength` (80 by default)
4
+ * and ending with an ellipsis when shortened.
5
+ *
6
+ * The cap counts UTF-16 units, which means it can land inside an emoji 😀
7
+ * and cut it in half 🫡.
8
+ * The cut half cannot render, so it is dropped.
9
+ *
10
+ * @example
11
+ * // The cut lands after both halves, so the emoji is kept.
12
+ * formatDescriptionPreview("a😀zz", { maxLength: 4 }); // "a😀…"
13
+ *
14
+ * @example
15
+ * // The cut lands between the halves, so the orphaned half is dropped.
16
+ * formatDescriptionPreview("a😀z", { maxLength: 3 }); // "a…"
17
+ */
1
18
  export function formatDescriptionPreview(description, options = {}) {
2
- const previewLength = options.maxLength ?? 80;
19
+ const previewLength = options.maxLength ?? DEFAULT_PREVIEW_LENGTH;
3
20
  if (description == null) {
4
21
  return "";
5
22
  }
6
- const normalizedDescription = description.replace(/\s+/g, " ").trim();
7
- if (normalizedDescription.length <= previewLength) {
23
+ const lineBreakIndex = options.firstLineOnly ? description.search(/\r?\n/) : -1;
24
+ const hasMoreLines = lineBreakIndex !== -1;
25
+ const previewText = hasMoreLines ? description.slice(0, lineBreakIndex) : description;
26
+ const normalizedDescription = previewText.replace(/\s+/g, " ").trim();
27
+ if (normalizedDescription.length <= previewLength && !hasMoreLines) {
8
28
  return normalizedDescription;
9
29
  }
10
- return `${normalizedDescription.slice(0, previewLength - 1).trimEnd()}…`;
30
+ const truncatedDescription = normalizedDescription.slice(0, previewLength - 1);
31
+ const completePrefix = truncatedDescription.replace(/\p{Surrogate}$/u, "");
32
+ return `${completePrefix.trimEnd()}…`;
11
33
  }
@@ -0,0 +1,4 @@
1
+ import type { StoreInfo } from "@zinn-dev/core";
2
+ import type { PresentedInfo } from "../result-schemas.js";
3
+ export declare function presentInfo(report: StoreInfo): PresentedInfo;
4
+ export declare function formatInfo(report: PresentedInfo): string;
@@ -0,0 +1,96 @@
1
+ import packageJson from "../../package.json" with { type: "json" };
2
+ export function presentInfo(report) {
3
+ const bunVersion = process.versions.bun;
4
+ return {
5
+ settingsFiles: report.settingsFiles,
6
+ storage: report.storage,
7
+ defaultProject: report.defaultProject,
8
+ database: report.database,
9
+ versions: {
10
+ cli: packageJson.version,
11
+ core: report.coreVersion,
12
+ runtime: {
13
+ name: bunVersion === undefined ? "Node" : "Bun",
14
+ version: bunVersion ?? process.versions.node,
15
+ },
16
+ },
17
+ };
18
+ }
19
+ function storeSource(storage) {
20
+ if (storage.settingsPath !== null) {
21
+ return storage.settingsPath;
22
+ }
23
+ return storage.source === "env" ? "ZINN_DIR" : "default";
24
+ }
25
+ function folderState(storage) {
26
+ if (storage.error !== null) {
27
+ return storage.error;
28
+ }
29
+ if (storage.exists === null) {
30
+ return "unavailable";
31
+ }
32
+ return storage.exists ? "found" : "missing";
33
+ }
34
+ function databaseState(database) {
35
+ if (database.error !== null) {
36
+ return database.error;
37
+ }
38
+ return `${database.state}; schema ${database.version ?? "unavailable"}, latest ${database.latestVersion}`;
39
+ }
40
+ export function formatInfo(report) {
41
+ const { storage, database, defaultProject, versions } = report;
42
+ const storeIsUnavailable = storage.directory === null;
43
+ //
44
+ /**
45
+ * A settings file's error text prints once, on its own line in the Settings list
46
+ * Other fields point to the file
47
+ */
48
+ const unavailableReason = (error) => {
49
+ const file = report.settingsFiles.find((candidate) => candidate.state === "error" && candidate.error === error);
50
+ return file === undefined ? error : `settings file ${file.path} cannot be used`;
51
+ };
52
+ const storeHeader = storeIsUnavailable
53
+ ? `unavailable${storage.error === null ? "" : ` (${unavailableReason(storage.error)})`}`
54
+ : `${storage.directory} (${storeSource(storage)})`;
55
+ const defaultProjectText = defaultProject.error === null
56
+ ? (defaultProject.key ?? "not configured")
57
+ : `unavailable (${unavailableReason(defaultProject.error)})`;
58
+ const defaultProjectSuffix = defaultProject.settingsPath === null ? "" : ` (${defaultProject.settingsPath})`;
59
+ const lines = [
60
+ `Store: ${storeHeader}`,
61
+ `Store folder: ${storeIsUnavailable ? "unavailable" : folderState(storage)}`,
62
+ `Database: ${database.path ?? "unavailable"}`,
63
+ `Database state: ${storeIsUnavailable ? "unavailable" : databaseState(database)}`,
64
+ `Default project: ${defaultProjectText}${defaultProjectSuffix}`,
65
+ "",
66
+ "Settings:",
67
+ ];
68
+ for (const file of report.settingsFiles) {
69
+ let state;
70
+ switch (file.state) {
71
+ case "found":
72
+ state = "found";
73
+ break;
74
+ case "missing":
75
+ state = "not configured";
76
+ break;
77
+ case "error":
78
+ state = file.error;
79
+ break;
80
+ case "not-read":
81
+ state = `not read (${file.reason} is set)`;
82
+ break;
83
+ }
84
+ lines.push(`${file.path}: ${state}`);
85
+ if (file.state === "found") {
86
+ if (file.settings.storage !== undefined) {
87
+ lines.push(` storage.directory: ${file.settings.storage.directory}`);
88
+ }
89
+ if (file.settings.defaultProject !== undefined) {
90
+ lines.push(` defaultProject: ${file.settings.defaultProject}`);
91
+ }
92
+ }
93
+ }
94
+ lines.push("", `CLI: ${versions.cli}`, `Core: ${versions.core}`, `Runtime: ${versions.runtime.name} ${versions.runtime.version}`);
95
+ return lines.join("\n");
96
+ }
@@ -0,0 +1,8 @@
1
+ import type { Label } from "@zinn-dev/core";
2
+ import type { PresentedLabel } from "../result-schemas.js";
3
+ import type { RowCell } from "./row-layout.js";
4
+ export declare function presentLabel(labelMatch: Label): PresentedLabel;
5
+ export declare function labelNameCell(name: string, color: string): RowCell;
6
+ export declare function formatLabelList(presentedLabels: Array<PresentedLabel>, options?: {
7
+ showsDescriptionPreview?: boolean;
8
+ }): string;
@@ -0,0 +1,28 @@
1
+ import { labelColorSchema } from "@zinn-dev/core";
2
+ import { isColorEnabled } from "./color.js";
3
+ import { formatDescriptionPreview } from "./description-presentation.js";
4
+ import { formatRows } from "./row-layout.js";
5
+ export function presentLabel(labelMatch) {
6
+ return {
7
+ id: labelMatch.id,
8
+ name: labelMatch.name,
9
+ color: labelMatch.color,
10
+ description: labelMatch.description,
11
+ };
12
+ }
13
+ export function labelNameCell(name, color) {
14
+ const style = labelColorSchema.options.find((labelColor) => labelColor === color);
15
+ return { text: name, style };
16
+ }
17
+ export function formatLabelList(presentedLabels, options = {}) {
18
+ return formatRows(presentedLabels.map((presented) => {
19
+ const description = options.showsDescriptionPreview && presented.description != null
20
+ ? formatDescriptionPreview(presented.description, { firstLineOnly: true })
21
+ : presented.description;
22
+ const descriptionCells = description == null ? [] : [{ text: description }];
23
+ if (isColorEnabled()) {
24
+ return [labelNameCell(presented.name, presented.color), ...descriptionCells];
25
+ }
26
+ return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
27
+ }));
28
+ }
@@ -0,0 +1,7 @@
1
+ import type { PresentedProject } from "../result-schemas.js";
2
+ type ProjectRowOptions = {
3
+ showsDescriptionPreview?: boolean;
4
+ };
5
+ export declare function presentProject(projectMatch: PresentedProject): PresentedProject;
6
+ export declare function formatProjectList(presentedProjects: Array<PresentedProject>, { showsDescriptionPreview }?: ProjectRowOptions): string;
7
+ export {};
@@ -0,0 +1,19 @@
1
+ import { formatDescriptionPreview } from "./description-presentation.js";
2
+ import { formatCellSeparator, formatRows } from "./row-layout.js";
3
+ export function presentProject(projectMatch) {
4
+ return {
5
+ id: projectMatch.id,
6
+ key: projectMatch.key,
7
+ name: projectMatch.name,
8
+ description: projectMatch.description,
9
+ };
10
+ }
11
+ export function formatProjectList(presentedProjects, { showsDescriptionPreview = true } = {}) {
12
+ return formatRows(presentedProjects.map((presented) => {
13
+ const descriptionPreview = showsDescriptionPreview
14
+ ? formatDescriptionPreview(presented.description)
15
+ : "";
16
+ const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
17
+ return [{ text: presented.key }, { text: `${presented.name}${description}` }];
18
+ }));
19
+ }
@@ -0,0 +1,7 @@
1
+ import type { TaskWithKey } from "@zinn-dev/core";
2
+ import type { PresentedRelation, PresentedRelationChange } from "../result-schemas.js";
3
+ export declare function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation>;
4
+ export declare function formatRelationList(relations: Array<PresentedRelation>): string;
5
+ export declare function formatRelationChange(change: PresentedRelationChange, options: {
6
+ action: "create" | "delete";
7
+ }): string;
@@ -0,0 +1,73 @@
1
+ import { column, relation } from "@zinn-dev/core";
2
+ import { columnNameCell } from "./column-presentation.js";
3
+ import { formatCellSeparator, formatRows } from "./row-layout.js";
4
+ export function presentRelations(taskMatch) {
5
+ return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
6
+ const isSource = entry.source_task_id === taskMatch.id;
7
+ const other = isSource ? entry.target : entry.source;
8
+ if (other == null) {
9
+ throw new Error("Connected task details were not included in the relation");
10
+ }
11
+ let direction = null;
12
+ if (entry.relation_type !== "related") {
13
+ direction = isSource ? "outgoing" : "incoming";
14
+ }
15
+ return {
16
+ id: entry.id,
17
+ type: entry.relation_type,
18
+ direction,
19
+ task: {
20
+ id: other.id,
21
+ key: other.key,
22
+ project_id: other.project_id,
23
+ column: column.getById(other.column_id).name,
24
+ column_id: other.column_id,
25
+ title: other.title,
26
+ status: other.archived_at == null ? "Active" : "Archived",
27
+ },
28
+ };
29
+ });
30
+ }
31
+ export function formatRelationList(relations) {
32
+ return formatRows(relations.map((entry) => {
33
+ const isOutgoing = entry.direction === "outgoing";
34
+ let label = entry.type;
35
+ switch (entry.type) {
36
+ case "related": {
37
+ label = "Related to";
38
+ break;
39
+ }
40
+ case "dependency": {
41
+ label = isOutgoing ? "Depends on" : "Depended on by";
42
+ break;
43
+ }
44
+ case "subtask": {
45
+ label = isOutgoing ? "Parent" : "Subtask";
46
+ break;
47
+ }
48
+ case "duplicate": {
49
+ label = isOutgoing ? "Duplicate of" : "Duplicated by";
50
+ break;
51
+ }
52
+ }
53
+ const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
54
+ return [
55
+ { text: label },
56
+ { text: entry.task.key },
57
+ columnNameCell(entry.task.column),
58
+ { text: `${entry.task.title}${archived}` },
59
+ ];
60
+ }));
61
+ }
62
+ export function formatRelationChange(change, options) {
63
+ if (options.action === "delete") {
64
+ return `Deleted ${change.type} relation from ${change.source} to ${change.target}`;
65
+ }
66
+ const label = {
67
+ related: "related to",
68
+ dependency: "depends on",
69
+ duplicate: "is a duplicate of",
70
+ subtask: "is a subtask of",
71
+ }[change.type];
72
+ return `${change.source} ${label} ${change.target}`;
73
+ }
@@ -1,17 +1,9 @@
1
- import type { TaskPriority, TaskWithKey } from "@zinn-dev/core";
2
- export type PresentedTask = {
3
- key: string;
4
- status: "Active" | "Archived";
5
- column: string;
6
- title: string;
7
- description: string | null;
8
- priority: TaskPriority | null;
9
- labels: Array<string>;
10
- };
1
+ import type { TaskWithKey } from "@zinn-dev/core";
2
+ import type { PresentedTask, PresentedTaskDetail } from "../result-schemas.js";
11
3
  export declare function presentTask(taskMatch: TaskWithKey): PresentedTask;
12
- export declare function formatTaskRow(presented: PresentedTask): string;
13
4
  export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
14
5
  showsStatus?: boolean;
15
6
  showsFullPriority?: boolean;
7
+ prefix?: string;
16
8
  }): string;
17
- export declare function formatTaskListWithStatus(presentedTasks: Array<PresentedTask>): string;
9
+ export declare function formatTaskTimestamps(task: Pick<PresentedTaskDetail, "created_at" | "updated_at">): string;
@@ -1,7 +1,8 @@
1
1
  import { column, label, task } from "@zinn-dev/core";
2
- import { styleOutputText } from "./color.js";
3
2
  import { columnNameCell } from "./column-presentation.js";
4
- import { formatCellSeparator, formatRows } from "./row-layout.js";
3
+ import { labelNameCell } from "./label-presentation.js";
4
+ import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
5
+ import { formatLocalTime } from "./time.js";
5
6
  const EMPTY_CELL_MARKER = "-";
6
7
  const LABEL_NAME_SEPARATOR = ", ";
7
8
  function taskPriorityCell(priority, showsFullPriority) {
@@ -12,31 +13,28 @@ function taskPriorityCell(priority, showsFullPriority) {
12
13
  return { text: showsFullPriority ? `${priorityInitial}${priority.slice(1)}` : priorityInitial };
13
14
  }
14
15
  /**
15
- * `PresentedTask` carries label names only, so JSON stays a list of names.
16
+ * `PresentedTask` carries label names and IDs, without colors.
16
17
  * Text output looks the colors up from the label definitions instead.
17
18
  */
18
19
  function getLabelColorsByName() {
19
20
  return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
20
21
  }
21
- function formatLabelNames(labelNames, labelColorsByName) {
22
- return labelNames
23
- .map((labelName) => styleOutputText(labelColorsByName.get(labelName), labelName))
24
- .join(LABEL_NAME_SEPARATOR);
25
- }
26
22
  export function presentTask(taskMatch) {
23
+ const labels = task.label.getAll(taskMatch.key);
27
24
  return {
25
+ id: taskMatch.id,
28
26
  key: taskMatch.key,
27
+ project_id: taskMatch.project_id,
29
28
  status: taskMatch.archived_at == null ? "Active" : "Archived",
30
29
  column: column.getById(taskMatch.column_id).name,
30
+ column_id: taskMatch.column_id,
31
31
  title: taskMatch.title,
32
32
  description: taskMatch.description,
33
33
  priority: taskMatch.priority,
34
- labels: task.label.getAll(taskMatch.key).map((label) => label.name),
34
+ labels: labels.map((label) => label.name),
35
+ label_ids: labels.map((label) => label.id),
35
36
  };
36
37
  }
37
- export function formatTaskRow(presented) {
38
- return formatTaskList([presented]);
39
- }
40
38
  export function formatTaskList(presentedTasks, options = {}) {
41
39
  const labelColorsByName = getLabelColorsByName();
42
40
  return formatRows(presentedTasks.map((presentedTask) => {
@@ -45,11 +43,12 @@ export function formatTaskList(presentedTasks, options = {}) {
45
43
  : [];
46
44
  const hasLabels = presentedTask.labels.length > 0;
47
45
  // The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
48
- const labels = hasLabels
49
- ? `${formatCellSeparator()}${formatLabelNames(presentedTask.labels, labelColorsByName)}`
50
- : "";
46
+ const labelNames = presentedTask.labels
47
+ .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
48
+ .join(LABEL_NAME_SEPARATOR);
49
+ const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
51
50
  return [
52
- { text: presentedTask.key },
51
+ { text: `${options.prefix ?? ""}${presentedTask.key}` },
53
52
  ...statusCells,
54
53
  columnNameCell(presentedTask.column),
55
54
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
@@ -57,6 +56,11 @@ export function formatTaskList(presentedTasks, options = {}) {
57
56
  ];
58
57
  }));
59
58
  }
60
- export function formatTaskListWithStatus(presentedTasks) {
61
- return formatTaskList(presentedTasks, { showsStatus: true });
59
+ export function formatTaskTimestamps(task) {
60
+ return formatRows([
61
+ [
62
+ { text: `Task created at: ${formatLocalTime(task.created_at)}`, style: "dim" },
63
+ { text: `Task updated at: ${formatLocalTime(task.updated_at)}`, style: "dim" },
64
+ ],
65
+ ]);
62
66
  }
package/src/project.d.ts CHANGED
@@ -1,6 +1,21 @@
1
- /** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
2
- export declare function resolveProjectKey(typedKey: string | undefined, { required, allProjects, useDefault, }?: {
1
+ export declare const projectScopeConstraint: {
2
+ readonly kind: "exclusive";
3
+ readonly members: readonly ["positional:project-key", "option:all-projects"];
4
+ };
5
+ export declare const requiredProjectDescription = "Omit the project key to use defaultProject from settings; otherwise a project key is required.";
6
+ export declare const projectScopeDescription = "An omitted project key uses defaultProject, or all projects if unset. --all-projects overrides the default and cannot be combined with a project key.";
7
+ type ProjectKeyOptions = {
3
8
  required?: boolean;
4
9
  allProjects?: boolean;
5
10
  useDefault?: boolean;
6
- }): string | undefined;
11
+ };
12
+ type ProjectKeyChoice = {
13
+ key: string;
14
+ settingsPath?: string;
15
+ };
16
+ /** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
17
+ export declare function resolveProjectKey(typedKey: string | undefined, options?: ProjectKeyOptions): string | undefined;
18
+ export declare function chooseProjectKey(typedKey: string | undefined, { required, allProjects, useDefault }?: ProjectKeyOptions): ProjectKeyChoice | undefined;
19
+ /** Fails when the key came from defaultProject and that project does not exist. */
20
+ export declare function checkDefaultProject({ key, settingsPath }: ProjectKeyChoice): void;
21
+ export {};
package/src/project.js CHANGED
@@ -1,31 +1,56 @@
1
1
  import { homedir } from "node:os";
2
- import { project, resolveSettings } from "@zinn-dev/core";
2
+ import { chooseDefaultProject, project, resolveSettings } from "@zinn-dev/core";
3
3
  import { UsageError } from "./lib.js";
4
+ import { CliError } from "./errors.js";
5
+ import { violatesConstraint } from "./input.js";
6
+ export const projectScopeConstraint = {
7
+ kind: "exclusive",
8
+ members: ["positional:project-key", "option:all-projects"],
9
+ };
10
+ export const requiredProjectDescription = "Omit the project key to use defaultProject from settings; otherwise a project key is required.";
11
+ export const projectScopeDescription = "An omitted project key uses defaultProject, or all projects if unset. --all-projects overrides the default and cannot be combined with a project key.";
4
12
  /** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
5
- export function resolveProjectKey(typedKey, { required = false, allProjects = false, useDefault = true, } = {}) {
13
+ export function resolveProjectKey(typedKey, options = {}) {
14
+ const choice = chooseProjectKey(typedKey, options);
15
+ if (choice !== undefined) {
16
+ checkDefaultProject(choice);
17
+ }
18
+ return choice?.key;
19
+ }
20
+ export function chooseProjectKey(typedKey, { required = false, allProjects = false, useDefault = true } = {}) {
6
21
  if (allProjects) {
7
- if (typedKey !== undefined) {
8
- throw new UsageError("--all-projects cannot be combined with a project key");
22
+ if (violatesConstraint(projectScopeConstraint, {
23
+ "positional:project-key": typedKey,
24
+ "option:all-projects": allProjects,
25
+ })) {
26
+ throw new UsageError("--all-projects cannot be combined with a project key", {
27
+ argument: "--all-projects",
28
+ });
9
29
  }
10
30
  return undefined;
11
31
  }
12
32
  if (typedKey !== undefined) {
13
- return typedKey;
33
+ return { key: typedKey };
14
34
  }
15
35
  if (!useDefault) {
16
36
  return undefined;
17
37
  }
18
38
  const settings = resolveSettings({ cwd: process.cwd(), env: process.env, home: homedir() });
19
- const defaultProject = settings.merged.defaultProject;
20
- if (defaultProject === undefined) {
39
+ const defaultProject = chooseDefaultProject(settings);
40
+ if (defaultProject === null) {
21
41
  if (required) {
22
- throw new UsageError("Missing argument <project-key>. Supply a key or configure defaultProject");
42
+ throw new UsageError("Missing argument <project-key>. Supply a key or configure defaultProject", { argument: "project-key" });
23
43
  }
24
44
  return undefined;
25
45
  }
26
- const settingsFile = settings.local?.settings.defaultProject === undefined ? settings.global : settings.local;
27
- if (project.getByKey(defaultProject) == null) {
28
- throw new Error(`Default project "${defaultProject}" from settings file ${settingsFile.path} does not exist`);
29
- }
30
46
  return defaultProject;
31
47
  }
48
+ /** Fails when the key came from defaultProject and that project does not exist. */
49
+ export function checkDefaultProject({ key, settingsPath }) {
50
+ if (settingsPath === undefined) {
51
+ return;
52
+ }
53
+ if (project.getByKey(key) == null) {
54
+ throw new CliError(`Default project "${key}" from settings file ${settingsPath} does not exist`, "not_found", { entity: "project", key, source: "defaultProject", settingsPath });
55
+ }
56
+ }