@zinn-dev/cli 0.41.0 → 0.43.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 (81) hide show
  1. package/README.md +11 -689
  2. package/index.js +2 -2
  3. package/package.json +4 -4
  4. package/skills/zinn/SKILL.md +1 -1
  5. package/src/capabilities-schema.d.ts +25 -26
  6. package/src/capabilities-schema.js +17 -82
  7. package/src/capabilities.d.ts +11 -3
  8. package/src/capabilities.js +12 -4
  9. package/src/column-hint.d.ts +3 -0
  10. package/src/column-hint.js +225 -0
  11. package/src/database.js +1 -4
  12. package/src/errors.d.ts +31 -3
  13. package/src/errors.js +77 -20
  14. package/src/input.d.ts +154 -43
  15. package/src/input.js +86 -13
  16. package/src/lib.d.ts +43 -6
  17. package/src/lib.js +134 -38
  18. package/src/list-continuation.d.ts +11 -0
  19. package/src/list-continuation.js +18 -0
  20. package/src/list-limit.d.ts +11 -0
  21. package/src/list-limit.js +17 -0
  22. package/src/presentation/activity-presentation.d.ts +9 -1
  23. package/src/presentation/activity-presentation.js +124 -28
  24. package/src/presentation/capabilities-presentation.d.ts +2 -0
  25. package/src/presentation/capabilities-presentation.js +3 -0
  26. package/src/presentation/column-presentation.d.ts +6 -0
  27. package/src/presentation/column-presentation.js +10 -0
  28. package/src/presentation/comment-presentation.d.ts +15 -0
  29. package/src/presentation/comment-presentation.js +29 -0
  30. package/src/presentation/description-presentation.d.ts +4 -0
  31. package/src/presentation/description-presentation.js +28 -5
  32. package/src/presentation/label-presentation.d.ts +8 -0
  33. package/src/presentation/label-presentation.js +28 -0
  34. package/src/presentation/project-presentation.d.ts +11 -0
  35. package/src/presentation/project-presentation.js +27 -0
  36. package/src/presentation/relation-presentation.d.ts +12 -0
  37. package/src/presentation/relation-presentation.js +87 -0
  38. package/src/presentation/row-layout.d.ts +1 -1
  39. package/src/presentation/row-layout.js +6 -5
  40. package/src/presentation/task-presentation.d.ts +3 -3
  41. package/src/presentation/task-presentation.js +29 -19
  42. package/src/presentation/text-width.d.ts +2 -0
  43. package/src/presentation/text-width.js +43 -0
  44. package/src/presentation/time.d.ts +3 -1
  45. package/src/presentation/time.js +5 -2
  46. package/src/project.d.ts +14 -5
  47. package/src/project.js +18 -6
  48. package/src/result-schemas.d.ts +279 -26
  49. package/src/result-schemas.js +72 -4
  50. package/src/results.d.ts +34 -17
  51. package/src/results.js +19 -0
  52. package/src/routes/activity-router.d.ts +79 -2
  53. package/src/routes/activity-router.js +209 -38
  54. package/src/routes/aliases.d.ts +2 -0
  55. package/src/routes/aliases.js +11 -0
  56. package/src/routes/capabilities-router.js +9 -3
  57. package/src/routes/comment-router.d.ts +41 -18
  58. package/src/routes/comment-router.js +65 -48
  59. package/src/routes/label-router.d.ts +57 -7
  60. package/src/routes/label-router.js +84 -39
  61. package/src/routes/project-router.d.ts +74 -12
  62. package/src/routes/project-router.js +131 -66
  63. package/src/routes/relation-router.d.ts +13 -9
  64. package/src/routes/relation-router.js +116 -116
  65. package/src/routes/restore-router.js +3 -6
  66. package/src/routes/router.d.ts +1 -1
  67. package/src/routes/router.js +88 -32
  68. package/src/routes/routes.d.ts +420 -50
  69. package/src/routes/routes.js +4 -0
  70. package/src/routes/task-router.d.ts +189 -30
  71. package/src/routes/task-router.js +254 -158
  72. package/src/routes/whoami-router.d.ts +21 -0
  73. package/src/routes/whoami-router.js +31 -0
  74. package/src/text-edit.d.ts +13 -9
  75. package/src/text-edit.js +23 -18
  76. package/src/text-input.d.ts +47 -0
  77. package/src/text-input.js +187 -0
  78. package/src/timestamp-input.d.ts +3 -0
  79. package/src/timestamp-input.js +31 -0
  80. package/src/types.d.ts +32 -9
  81. package/src/types.js +9 -1
@@ -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,31 @@ 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
+ due_at: taskMatch.due_at ?? null,
35
+ labels: labels.map((label) => label.name),
36
+ label_ids: labels.map((label) => label.id),
37
+ created_at: taskMatch.created_at,
38
+ updated_at: taskMatch.updated_at,
35
39
  };
36
40
  }
37
- export function formatTaskRow(presented) {
38
- return formatTaskList([presented]);
39
- }
40
41
  export function formatTaskList(presentedTasks, options = {}) {
41
42
  const labelColorsByName = getLabelColorsByName();
42
43
  return formatRows(presentedTasks.map((presentedTask) => {
@@ -45,18 +46,27 @@ export function formatTaskList(presentedTasks, options = {}) {
45
46
  : [];
46
47
  const hasLabels = presentedTask.labels.length > 0;
47
48
  // 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
- : "";
49
+ const labelNames = presentedTask.labels
50
+ .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
51
+ .join(LABEL_NAME_SEPARATOR);
52
+ const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
53
+ const deadline = presentedTask.due_at == null
54
+ ? ""
55
+ : `${formatCellSeparator()}Due ${formatLocalTime(presentedTask.due_at, { includesSeconds: true })}`;
51
56
  return [
52
- { text: presentedTask.key },
57
+ { text: `${options.prefix ?? ""}${presentedTask.key}` },
53
58
  ...statusCells,
54
59
  columnNameCell(presentedTask.column),
55
60
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
56
- { text: `${presentedTask.title}${labels}` },
61
+ { text: `${presentedTask.title}${deadline}${labels}` },
57
62
  ];
58
63
  }));
59
64
  }
60
- export function formatTaskListWithStatus(presentedTasks) {
61
- return formatTaskList(presentedTasks, { showsStatus: true });
65
+ export function formatTaskTimestamps(task) {
66
+ return formatRows([
67
+ [
68
+ { text: `Task created at: ${formatLocalTime(task.created_at)}`, style: "dim" },
69
+ { text: `Task updated at: ${formatLocalTime(task.updated_at)}`, style: "dim" },
70
+ ],
71
+ ]);
62
72
  }
@@ -0,0 +1,2 @@
1
+ export declare function graphemes(text: string): Intl.Segments;
2
+ export declare function displayWidth(text: string): number;
@@ -0,0 +1,43 @@
1
+ const PRINTABLE_ASCII = /^[\x20-\x7e]*$/;
2
+ const ZERO_WIDTH_CODE_POINT = /^[\p{Mark}\p{Default_Ignorable_Code_Point}\p{Cc}]$/u;
3
+ // The constructor permits Unicode-set matching with the ES2023 declaration target.
4
+ const RGI_EMOJI = new RegExp("^\\p{RGI_Emoji}$", "v");
5
+ const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
6
+ export function graphemes(text) {
7
+ return segmenter.segment(text);
8
+ }
9
+ function isWideEastAsian(codePoint) {
10
+ // Unicode EastAsianWidth.txt lists the Hangul, CJK, kana, Yi and fullwidth blocks below.
11
+ // https://www.unicode.org/Public/18.0.0/ucd/EastAsianWidth.txt
12
+ return ((codePoint >= 0x1100 && codePoint <= 0x115f) ||
13
+ codePoint === 0x2329 ||
14
+ codePoint === 0x232a ||
15
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
16
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
17
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
18
+ (codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
19
+ (codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
20
+ (codePoint >= 0xff01 && codePoint <= 0xff60) ||
21
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
22
+ (codePoint >= 0x1aff0 && codePoint <= 0x1afff) ||
23
+ (codePoint >= 0x1b000 && codePoint <= 0x1b2ff) ||
24
+ (codePoint >= 0x20000 && codePoint <= 0x3fffd));
25
+ }
26
+ export function displayWidth(text) {
27
+ if (PRINTABLE_ASCII.test(text)) {
28
+ return text.length;
29
+ }
30
+ let width = 0;
31
+ for (const { segment } of graphemes(text)) {
32
+ if ([...segment].every((point) => ZERO_WIDTH_CODE_POINT.test(point))) {
33
+ continue;
34
+ }
35
+ if (RGI_EMOJI.test(segment) || isWideEastAsian(segment.codePointAt(0))) {
36
+ width += 2;
37
+ }
38
+ else {
39
+ width += 1;
40
+ }
41
+ }
42
+ return width;
43
+ }
@@ -1 +1,3 @@
1
- export declare function formatLocalTime(timestamp: number): string;
1
+ export declare function formatLocalTime(timestamp: number, options?: {
2
+ includesSeconds?: boolean;
3
+ }): string;
@@ -1,5 +1,5 @@
1
1
  const MINUTES_PER_HOUR = 60;
2
- export function formatLocalTime(timestamp) {
2
+ export function formatLocalTime(timestamp, options = {}) {
3
3
  const date = new Date(timestamp);
4
4
  const offsetMinutes = -date.getTimezoneOffset();
5
5
  const offsetSign = offsetMinutes >= 0 ? "+" : "-";
@@ -7,7 +7,10 @@ export function formatLocalTime(timestamp) {
7
7
  const offsetHours = Math.floor(absoluteOffsetMinutes / MINUTES_PER_HOUR);
8
8
  const remainingOffsetMinutes = absoluteOffsetMinutes % MINUTES_PER_HOUR;
9
9
  const pad = (value) => String(value).padStart(2, "0");
10
+ const milliseconds = date.getMilliseconds();
11
+ const fraction = milliseconds === 0 ? "" : `.${String(milliseconds).padStart(3, "0")}`;
12
+ const seconds = options.includesSeconds ? `:${pad(date.getSeconds())}${fraction}` : "";
10
13
  return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
11
- `${pad(date.getHours())}:${pad(date.getMinutes())} ` +
14
+ `${pad(date.getHours())}:${pad(date.getMinutes())}${seconds} ` +
12
15
  `${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`);
13
16
  }
package/src/project.d.ts CHANGED
@@ -2,11 +2,20 @@ export declare const projectScopeConstraint: {
2
2
  readonly kind: "exclusive";
3
3
  readonly members: readonly ["positional:project-key", "option:all-projects"];
4
4
  };
5
- export declare const requiredProjectDescription = "An omitted project key uses defaultProject from settings. Without a configured default, a project key is required. A missing configured project is an error.";
6
- export declare const projectScopeDescription = "An omitted project key defaults to all projects unless defaultProject is configured. --all-projects overrides the defaultProject and excludes a typed project. A missing configured project is an error.";
7
- /** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
8
- export declare function resolveProjectKey(typedKey: string | undefined, { required, allProjects, useDefault, }?: {
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 = {
9
8
  required?: boolean;
10
9
  allProjects?: boolean;
11
10
  useDefault?: boolean;
12
- }): 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
@@ -7,10 +7,17 @@ export const projectScopeConstraint = {
7
7
  kind: "exclusive",
8
8
  members: ["positional:project-key", "option:all-projects"],
9
9
  };
10
- export const requiredProjectDescription = "An omitted project key uses defaultProject from settings. Without a configured default, a project key is required. A missing configured project is an error.";
11
- export const projectScopeDescription = "An omitted project key defaults to all projects unless defaultProject is configured. --all-projects overrides the defaultProject and excludes a typed project. A missing configured project is an error.";
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.";
12
12
  /** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
13
- 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 } = {}) {
14
21
  if (allProjects) {
15
22
  if (violatesConstraint(projectScopeConstraint, {
16
23
  "positional:project-key": typedKey,
@@ -23,7 +30,7 @@ export function resolveProjectKey(typedKey, { required = false, allProjects = fa
23
30
  return undefined;
24
31
  }
25
32
  if (typedKey !== undefined) {
26
- return typedKey;
33
+ return { key: typedKey };
27
34
  }
28
35
  if (!useDefault) {
29
36
  return undefined;
@@ -36,9 +43,14 @@ export function resolveProjectKey(typedKey, { required = false, allProjects = fa
36
43
  }
37
44
  return undefined;
38
45
  }
39
- const { key, settingsPath } = defaultProject;
46
+ return defaultProject;
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
+ }
40
53
  if (project.getByKey(key) == null) {
41
54
  throw new CliError(`Default project "${key}" from settings file ${settingsPath} does not exist`, "not_found", { entity: "project", key, source: "defaultProject", settingsPath });
42
55
  }
43
- return key;
44
56
  }