@zinn-dev/cli 0.43.0 → 0.44.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 (53) hide show
  1. package/README.md +1 -1
  2. package/index.js +3 -3
  3. package/package.json +7 -4
  4. package/skills/zinn/SKILL.md +1 -1
  5. package/src/actor.d.ts +8 -0
  6. package/src/actor.js +5 -1
  7. package/src/capabilities-schema.d.ts +1 -1
  8. package/src/column-hint.js +3 -4
  9. package/src/errors.d.ts +12 -3
  10. package/src/errors.js +19 -2
  11. package/src/failure-log.d.ts +6 -0
  12. package/src/failure-log.js +167 -0
  13. package/src/input.d.ts +11 -0
  14. package/src/input.js +25 -1
  15. package/src/lib.d.ts +7 -5
  16. package/src/lib.js +52 -33
  17. package/src/list-limit.d.ts +2 -2
  18. package/src/list-limit.js +2 -2
  19. package/src/overview.d.ts +10 -0
  20. package/src/overview.js +41 -0
  21. package/src/presentation/activity-presentation.d.ts +2 -0
  22. package/src/presentation/activity-presentation.js +96 -35
  23. package/src/presentation/column-presentation.d.ts +17 -2
  24. package/src/presentation/column-presentation.js +45 -6
  25. package/src/presentation/info-presentation.js +36 -6
  26. package/src/presentation/relation-presentation.d.ts +6 -2
  27. package/src/presentation/relation-presentation.js +36 -26
  28. package/src/presentation/task-blame-presentation.d.ts +11 -0
  29. package/src/presentation/task-blame-presentation.js +56 -0
  30. package/src/presentation/task-presentation.d.ts +6 -1
  31. package/src/presentation/task-presentation.js +21 -9
  32. package/src/result-schemas.d.ts +480 -15
  33. package/src/result-schemas.js +54 -1
  34. package/src/routes/activity-router.d.ts +9 -1
  35. package/src/routes/activity-router.js +15 -2
  36. package/src/routes/info-router.js +3 -2
  37. package/src/routes/migrate-router.js +2 -2
  38. package/src/routes/project-router.d.ts +1 -1
  39. package/src/routes/project-router.js +3 -12
  40. package/src/routes/restore-router.js +9 -3
  41. package/src/routes/router.js +24 -11
  42. package/src/routes/routes.d.ts +51 -8
  43. package/src/routes/task-router.d.ts +41 -6
  44. package/src/routes/task-router.js +81 -24
  45. package/src/routes/whoami-router.js +1 -1
  46. package/src/run-facts.d.ts +14 -0
  47. package/src/run-facts.js +14 -0
  48. package/src/store-folder.d.ts +5 -0
  49. package/src/store-folder.js +16 -0
  50. package/src/telemetry.d.ts +31 -0
  51. package/src/telemetry.js +329 -0
  52. package/src/text-input.js +1 -5
  53. package/src/types.d.ts +1 -1
@@ -1,18 +1,16 @@
1
1
  import packageJson from "../../package.json" with { type: "json" };
2
+ import { currentRuntime } from "../run-facts.js";
2
3
  export function presentInfo(report) {
3
- const bunVersion = process.versions.bun;
4
4
  return {
5
5
  settingsFiles: report.settingsFiles,
6
6
  storage: report.storage,
7
7
  defaultProject: report.defaultProject,
8
+ telemetry: report.telemetry,
8
9
  database: report.database,
9
10
  versions: {
10
11
  cli: packageJson.version,
11
12
  core: report.coreVersion,
12
- runtime: {
13
- name: bunVersion === undefined ? "Node" : "Bun",
14
- version: bunVersion ?? process.versions.node,
15
- },
13
+ runtime: currentRuntime(),
16
14
  },
17
15
  };
18
16
  }
@@ -31,6 +29,18 @@ function folderState(storage) {
31
29
  }
32
30
  return storage.exists ? "found" : "missing";
33
31
  }
32
+ function telemetrySource(telemetry) {
33
+ return telemetry.settingsPath ?? telemetry.source ?? "unavailable";
34
+ }
35
+ function telemetryFolderState(telemetry) {
36
+ if (telemetry.exists === null) {
37
+ return "unavailable";
38
+ }
39
+ if (!telemetry.exists) {
40
+ return telemetry.sizeBytes === null ? "not a directory" : "missing";
41
+ }
42
+ return telemetry.sizeBytes === null ? "cannot be read" : `${telemetry.sizeBytes} bytes`;
43
+ }
34
44
  function databaseState(database) {
35
45
  if (database.error !== null) {
36
46
  return database.error;
@@ -38,7 +48,7 @@ function databaseState(database) {
38
48
  return `${database.state}; schema ${database.version ?? "unavailable"}, latest ${database.latestVersion}`;
39
49
  }
40
50
  export function formatInfo(report) {
41
- const { storage, database, defaultProject, versions } = report;
51
+ const { storage, database, defaultProject, telemetry, versions } = report;
42
52
  const storeIsUnavailable = storage.directory === null;
43
53
  //
44
54
  /**
@@ -56,12 +66,23 @@ export function formatInfo(report) {
56
66
  ? (defaultProject.key ?? "not configured")
57
67
  : `unavailable (${unavailableReason(defaultProject.error)})`;
58
68
  const defaultProjectSuffix = defaultProject.settingsPath === null ? "" : ` (${defaultProject.settingsPath})`;
69
+ const telemetryReason = telemetry.error === null ? "" : ` (${unavailableReason(telemetry.error)})`;
70
+ const telemetryText = telemetry.mode === null
71
+ ? `unavailable${telemetryReason}`
72
+ : `${telemetry.mode} (${telemetrySource(telemetry)})`;
73
+ const telemetryLimit = telemetry.maxMegabytes === null ? "" : `, limit ${telemetry.maxMegabytes} MB`;
74
+ const telemetryAge = telemetry.maxAgeDays === null ? "" : `, kept ${telemetry.maxAgeDays} days`;
75
+ const telemetryFolderText = telemetry.directory === null
76
+ ? `unavailable${telemetryReason}`
77
+ : `${telemetry.directory} (${telemetryFolderState(telemetry)})`;
59
78
  const lines = [
60
79
  `Store: ${storeHeader}`,
61
80
  `Store folder: ${storeIsUnavailable ? "unavailable" : folderState(storage)}`,
62
81
  `Database: ${database.path ?? "unavailable"}`,
63
82
  `Database state: ${storeIsUnavailable ? "unavailable" : databaseState(database)}`,
64
83
  `Default project: ${defaultProjectText}${defaultProjectSuffix}`,
84
+ `Telemetry: ${telemetryText}${telemetryLimit}${telemetryAge}`,
85
+ `Telemetry folder: ${telemetryFolderText}`,
65
86
  "",
66
87
  "Settings:",
67
88
  ];
@@ -89,6 +110,15 @@ export function formatInfo(report) {
89
110
  if (file.settings.defaultProject !== undefined) {
90
111
  lines.push(` defaultProject: ${file.settings.defaultProject}`);
91
112
  }
113
+ if (file.settings.telemetry?.mode !== undefined) {
114
+ lines.push(` telemetry.mode: ${file.settings.telemetry.mode}`);
115
+ }
116
+ if (file.settings.telemetry?.maxMegabytes !== undefined) {
117
+ lines.push(` telemetry.maxMegabytes: ${file.settings.telemetry.maxMegabytes}`);
118
+ }
119
+ if (file.settings.telemetry?.maxAgeDays !== undefined) {
120
+ lines.push(` telemetry.maxAgeDays: ${file.settings.telemetry.maxAgeDays}`);
121
+ }
92
122
  }
93
123
  }
94
124
  lines.push("", `CLI: ${versions.cli}`, `Core: ${versions.core}`, `Runtime: ${versions.runtime.name} ${versions.runtime.version}`);
@@ -1,9 +1,13 @@
1
1
  import type { TaskWithKey } from "@zinn-dev/core";
2
2
  import type { PresentedRelation, PresentedRelationChange } from "../result-schemas.js";
3
+ import type { ColumnBoard } from "./column-presentation.js";
4
+ import type { RowCell } from "./row-layout.js";
3
5
  import { relation } from "@zinn-dev/core";
4
6
  export declare function presentRelationChange(entry: ReturnType<typeof relation.create>, source: TaskWithKey, target: TaskWithKey): PresentedRelationChange;
5
- export declare function presentRelations(taskMatch: TaskWithKey): Array<PresentedRelation>;
6
- export declare function formatRelationList(relations: Array<PresentedRelation>): string;
7
+ export declare function presentRelations(taskMatch: TaskWithKey, board?: ColumnBoard): Array<PresentedRelation>;
8
+ export declare function formatRelationList(relations: Array<PresentedRelation>, options?: {
9
+ trailingCell?: (entry: PresentedRelation) => RowCell;
10
+ }): string;
7
11
  export declare function formatRelationChange(change: Pick<PresentedRelationChange, "type" | "source" | "target">, options: {
8
12
  action: "create" | "delete";
9
13
  } | {
@@ -1,5 +1,5 @@
1
- import { column, relation } from "@zinn-dev/core";
2
- import { columnNameCell } from "./column-presentation.js";
1
+ import { relation } from "@zinn-dev/core";
2
+ import { columnNameCell, columnPlacement, createColumnBoard } from "./column-presentation.js";
3
3
  import { formatCellSeparator, formatRows } from "./row-layout.js";
4
4
  export function presentRelationChange(entry, source, target) {
5
5
  return {
@@ -11,7 +11,7 @@ export function presentRelationChange(entry, source, target) {
11
11
  target_task_id: target.id,
12
12
  };
13
13
  }
14
- export function presentRelations(taskMatch) {
14
+ export function presentRelations(taskMatch, board = createColumnBoard()) {
15
15
  return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
16
16
  const isSource = entry.source_task_id === taskMatch.id;
17
17
  const other = isSource ? entry.target : entry.source;
@@ -22,6 +22,9 @@ export function presentRelations(taskMatch) {
22
22
  if (entry.relation_type !== "related") {
23
23
  direction = isSource ? "outgoing" : "incoming";
24
24
  }
25
+ const projectColumns = board(other.project_id);
26
+ const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === other.column_id);
27
+ const placement = columnPlacement(projectColumns, other.column_id);
25
28
  return {
26
29
  id: entry.id,
27
30
  type: entry.relation_type,
@@ -30,42 +33,49 @@ export function presentRelations(taskMatch) {
30
33
  id: other.id,
31
34
  key: other.key,
32
35
  project_id: other.project_id,
33
- column: column.getById(other.column_id).name,
36
+ column: columnMatch.name,
34
37
  column_id: other.column_id,
38
+ is_first: placement.is_first,
39
+ is_last: placement.is_last,
35
40
  title: other.title,
36
41
  status: other.archived_at == null ? "Active" : "Archived",
37
42
  },
38
43
  };
39
44
  });
40
45
  }
41
- export function formatRelationList(relations) {
42
- return formatRows(relations.map((entry) => {
43
- const isOutgoing = entry.direction === "outgoing";
44
- let label = entry.type;
45
- switch (entry.type) {
46
- case "related": {
47
- label = "Related to";
48
- break;
49
- }
50
- case "dependency": {
51
- label = isOutgoing ? "Depends on" : "Depended on by";
52
- break;
53
- }
54
- case "subtask": {
55
- label = isOutgoing ? "Parent" : "Subtask";
56
- break;
57
- }
58
- case "duplicate": {
59
- label = isOutgoing ? "Duplicate of" : "Duplicated by";
60
- break;
61
- }
46
+ function formatRelationLabel(entry) {
47
+ const isOutgoing = entry.direction === "outgoing";
48
+ let label = entry.type;
49
+ switch (entry.type) {
50
+ case "related": {
51
+ label = "Related to";
52
+ break;
53
+ }
54
+ case "dependency": {
55
+ label = isOutgoing ? "Depends on" : "Depended on by";
56
+ break;
57
+ }
58
+ case "subtask": {
59
+ label = isOutgoing ? "Parent" : "Subtask";
60
+ break;
61
+ }
62
+ case "duplicate": {
63
+ label = isOutgoing ? "Duplicate of" : "Duplicated by";
64
+ break;
62
65
  }
66
+ }
67
+ return label;
68
+ }
69
+ export function formatRelationList(relations, options = {}) {
70
+ return formatRows(relations.map((entry) => {
71
+ const label = formatRelationLabel(entry);
63
72
  const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
64
73
  return [
65
74
  { text: label },
66
75
  { text: entry.task.key },
67
- columnNameCell(entry.task.column),
76
+ columnNameCell(entry.task.column, entry.task),
68
77
  { text: `${entry.task.title}${archived}` },
78
+ ...(options.trailingCell === undefined ? [] : [options.trailingCell(entry)]),
69
79
  ];
70
80
  }));
71
81
  }
@@ -0,0 +1,11 @@
1
+ import type { PresentedRelation, PresentedTaskBlame } from "../result-schemas.js";
2
+ export declare function formatTaskBlame(blame: PresentedTaskBlame, options: {
3
+ relations: Array<PresentedRelation>;
4
+ columnPlacement: {
5
+ is_first: boolean;
6
+ is_last: boolean;
7
+ };
8
+ isArchived: boolean;
9
+ /** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
10
+ activityIdPrefixes: Map<string, string>;
11
+ }): string;
@@ -0,0 +1,56 @@
1
+ import { formatActor } from "./activity-presentation.js";
2
+ import { columnNameCell } from "./column-presentation.js";
3
+ import { formatRelationList } from "./relation-presentation.js";
4
+ import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
5
+ import { formatSection } from "./section.js";
6
+ import { formatLabelNames, taskPriorityCell } from "./task-presentation.js";
7
+ import { formatLocalTime } from "./time.js";
8
+ export function formatTaskBlame(blame, options) {
9
+ const events = new Map();
10
+ function reference(attribution) {
11
+ if (attribution === null) {
12
+ return "unrecorded";
13
+ }
14
+ events.set(attribution.id, attribution);
15
+ return options.activityIdPrefixes.get(attribution.id) ?? attribution.id;
16
+ }
17
+ function field(name, value, attribution) {
18
+ return `${name}: ${value} [${reference(attribution)}]`;
19
+ }
20
+ const { fields } = blame;
21
+ const labelNames = fields.labels.value.map((label) => label.name);
22
+ const content = [
23
+ `${blame.task.key} (${blame.task.id})${options.isArchived ? `${formatCellSeparator()}Archived` : ""}`,
24
+ formatSection("Fields", [
25
+ field("Title", fields.title.value, fields.title.attribution),
26
+ field("Column", formatCell(columnNameCell(fields.column.value.name, options.columnPlacement)), fields.column.attribution),
27
+ field("Priority", formatCell(taskPriorityCell(fields.priority.value, true)), fields.priority.attribution),
28
+ field("Due", fields.due_at.value === null
29
+ ? "none"
30
+ : formatLocalTime(fields.due_at.value, { includesSeconds: true }), fields.due_at.attribution),
31
+ field("Labels", labelNames.length === 0 ? "none" : formatLabelNames(labelNames), fields.labels.attribution),
32
+ field("Parent", fields.parent.value?.key ?? "none", fields.parent.attribution),
33
+ ].join("\n")),
34
+ ];
35
+ if (options.relations.length > 0) {
36
+ const relationAttributions = new Map(blame.relations.map((entry) => [entry.id, entry.attribution]));
37
+ content.push(formatSection("Relations", formatRelationList(options.relations, {
38
+ trailingCell: (entry) => ({
39
+ text: `[${reference(relationAttributions.get(entry.id) ?? null)}]`,
40
+ }),
41
+ })));
42
+ }
43
+ if (blame.description.length > 0) {
44
+ content.push(formatSection("Description", formatRows(blame.description.map((line) => [
45
+ { text: String(line.line) },
46
+ { text: `[${reference(line.attribution)}]` },
47
+ { text: line.text },
48
+ ]))));
49
+ }
50
+ if (events.size > 0) {
51
+ content.push(formatSection("Attribution", [...events.values()]
52
+ .map((event) => `${event.id}\n${formatLocalTime(event.created_at, { includesSeconds: true })}\n${formatActor(event)}`)
53
+ .join("\n\n")));
54
+ }
55
+ return content.join("\n\n");
56
+ }
@@ -1,6 +1,11 @@
1
1
  import type { TaskWithKey } from "@zinn-dev/core";
2
+ import type { RowCell } from "./row-layout.js";
2
3
  import type { PresentedTask, PresentedTaskDetail } from "../result-schemas.js";
3
- export declare function presentTask(taskMatch: TaskWithKey): PresentedTask;
4
+ import type { ColumnBoard } from "./column-presentation.js";
5
+ export declare function taskPriorityCell(priority: PresentedTask["priority"], showsFullPriority: boolean): RowCell;
6
+ /** A task's label names on their own, colored as in a task row. */
7
+ export declare function formatLabelNames(labelNames: Array<string>): string;
8
+ export declare function presentTask(taskMatch: TaskWithKey, board?: ColumnBoard): PresentedTask;
4
9
  export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
5
10
  showsStatus?: boolean;
6
11
  showsFullPriority?: boolean;
@@ -1,11 +1,11 @@
1
- import { column, label, task } from "@zinn-dev/core";
2
- import { columnNameCell } from "./column-presentation.js";
1
+ import { label, task } from "@zinn-dev/core";
2
+ import { columnNameCell, columnPlacement, createColumnBoard } from "./column-presentation.js";
3
3
  import { labelNameCell } from "./label-presentation.js";
4
4
  import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
5
5
  import { formatLocalTime } from "./time.js";
6
6
  const EMPTY_CELL_MARKER = "-";
7
7
  const LABEL_NAME_SEPARATOR = ", ";
8
- function taskPriorityCell(priority, showsFullPriority) {
8
+ export function taskPriorityCell(priority, showsFullPriority) {
9
9
  if (priority == null) {
10
10
  return { text: EMPTY_CELL_MARKER, style: "dim" };
11
11
  }
@@ -19,15 +19,29 @@ function taskPriorityCell(priority, showsFullPriority) {
19
19
  function getLabelColorsByName() {
20
20
  return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
21
21
  }
22
- export function presentTask(taskMatch) {
22
+ function formatTaskLabelNames(labelNames, labelColorsByName) {
23
+ return labelNames
24
+ .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
25
+ .join(LABEL_NAME_SEPARATOR);
26
+ }
27
+ /** A task's label names on their own, colored as in a task row. */
28
+ export function formatLabelNames(labelNames) {
29
+ return formatTaskLabelNames(labelNames, getLabelColorsByName());
30
+ }
31
+ export function presentTask(taskMatch, board = createColumnBoard()) {
23
32
  const labels = task.label.getAll(taskMatch.key);
33
+ const projectColumns = board(taskMatch.project_id);
34
+ const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === taskMatch.column_id);
35
+ const placement = columnPlacement(projectColumns, taskMatch.column_id);
24
36
  return {
25
37
  id: taskMatch.id,
26
38
  key: taskMatch.key,
27
39
  project_id: taskMatch.project_id,
28
40
  status: taskMatch.archived_at == null ? "Active" : "Archived",
29
- column: column.getById(taskMatch.column_id).name,
41
+ column: columnMatch.name,
30
42
  column_id: taskMatch.column_id,
43
+ is_first: placement.is_first,
44
+ is_last: placement.is_last,
31
45
  title: taskMatch.title,
32
46
  description: taskMatch.description,
33
47
  priority: taskMatch.priority,
@@ -46,9 +60,7 @@ export function formatTaskList(presentedTasks, options = {}) {
46
60
  : [];
47
61
  const hasLabels = presentedTask.labels.length > 0;
48
62
  // The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
49
- const labelNames = presentedTask.labels
50
- .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
51
- .join(LABEL_NAME_SEPARATOR);
63
+ const labelNames = formatTaskLabelNames(presentedTask.labels, labelColorsByName);
52
64
  const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
53
65
  const deadline = presentedTask.due_at == null
54
66
  ? ""
@@ -56,7 +68,7 @@ export function formatTaskList(presentedTasks, options = {}) {
56
68
  return [
57
69
  { text: `${options.prefix ?? ""}${presentedTask.key}` },
58
70
  ...statusCells,
59
- columnNameCell(presentedTask.column),
71
+ columnNameCell(presentedTask.column, presentedTask),
60
72
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
61
73
  { text: `${presentedTask.title}${deadline}${labels}` },
62
74
  ];