@zinn-dev/cli 0.42.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 (69) hide show
  1. package/README.md +1 -1
  2. package/index.js +3 -3
  3. package/package.json +6 -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 +4 -4
  8. package/src/column-hint.js +3 -4
  9. package/src/errors.d.ts +40 -3
  10. package/src/errors.js +93 -21
  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 +21 -10
  16. package/src/lib.js +116 -62
  17. package/src/list-continuation.d.ts +11 -0
  18. package/src/list-continuation.js +18 -0
  19. package/src/list-limit.d.ts +11 -0
  20. package/src/list-limit.js +17 -0
  21. package/src/overview.d.ts +10 -0
  22. package/src/overview.js +41 -0
  23. package/src/presentation/activity-presentation.d.ts +2 -0
  24. package/src/presentation/activity-presentation.js +112 -38
  25. package/src/presentation/column-presentation.d.ts +17 -2
  26. package/src/presentation/column-presentation.js +45 -6
  27. package/src/presentation/description-presentation.d.ts +3 -16
  28. package/src/presentation/description-presentation.js +22 -21
  29. package/src/presentation/info-presentation.js +36 -6
  30. package/src/presentation/project-presentation.d.ts +6 -2
  31. package/src/presentation/project-presentation.js +9 -1
  32. package/src/presentation/relation-presentation.d.ts +12 -3
  33. package/src/presentation/relation-presentation.js +50 -26
  34. package/src/presentation/row-layout.d.ts +1 -1
  35. package/src/presentation/row-layout.js +6 -5
  36. package/src/presentation/task-blame-presentation.d.ts +11 -0
  37. package/src/presentation/task-blame-presentation.js +56 -0
  38. package/src/presentation/task-presentation.d.ts +6 -1
  39. package/src/presentation/task-presentation.js +28 -10
  40. package/src/presentation/text-width.d.ts +2 -0
  41. package/src/presentation/text-width.js +43 -0
  42. package/src/presentation/time.d.ts +3 -1
  43. package/src/presentation/time.js +5 -2
  44. package/src/result-schemas.d.ts +529 -18
  45. package/src/result-schemas.js +66 -4
  46. package/src/routes/activity-router.d.ts +53 -1
  47. package/src/routes/activity-router.js +126 -15
  48. package/src/routes/info-router.js +3 -2
  49. package/src/routes/migrate-router.js +2 -2
  50. package/src/routes/project-router.d.ts +41 -1
  51. package/src/routes/project-router.js +76 -24
  52. package/src/routes/relation-router.d.ts +7 -3
  53. package/src/routes/relation-router.js +73 -56
  54. package/src/routes/restore-router.js +10 -7
  55. package/src/routes/router.js +77 -37
  56. package/src/routes/routes.d.ts +213 -8
  57. package/src/routes/task-router.d.ts +119 -6
  58. package/src/routes/task-router.js +177 -32
  59. package/src/routes/whoami-router.js +1 -1
  60. package/src/run-facts.d.ts +14 -0
  61. package/src/run-facts.js +14 -0
  62. package/src/store-folder.d.ts +5 -0
  63. package/src/store-folder.js +16 -0
  64. package/src/telemetry.d.ts +31 -0
  65. package/src/telemetry.js +329 -0
  66. package/src/text-input.js +1 -5
  67. package/src/timestamp-input.d.ts +3 -0
  68. package/src/timestamp-input.js +31 -0
  69. package/src/types.d.ts +4 -4
@@ -1,4 +1,4 @@
1
- import { activity, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, } from "@zinn-dev/core";
1
+ import { activity, activityTaskIdSchema, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, timestampSchema, } from "@zinn-dev/core";
2
2
  import { formatDescriptionPreview } from "./description-presentation.js";
3
3
  import { formatRows } from "./row-layout.js";
4
4
  import { formatSection } from "./section.js";
@@ -10,6 +10,7 @@ const RECORDED_FIELDS = new Set([
10
10
  "title",
11
11
  "description",
12
12
  "priority",
13
+ "due_at",
13
14
  "color",
14
15
  "column",
15
16
  "columns",
@@ -35,6 +36,7 @@ const ACTOR_DETAIL_FIELDS = [
35
36
  { key: "actor_agent", label: "Agent" },
36
37
  { key: "actor_model", label: "Model" },
37
38
  { key: "actor_effort", label: "Effort" },
39
+ { key: "actor_client", label: "Client" },
38
40
  ];
39
41
  const ACTION_LABELS = {
40
42
  create: "created",
@@ -86,21 +88,23 @@ export function abbreviateActivityIds(ids) {
86
88
  }
87
89
  return prefixes;
88
90
  }
89
- function getTaskNavigation(events, taskKey, taskId) {
91
+ function getTaskNavigation(pageEvents, { navigationEvents, taskKey, taskId, }) {
90
92
  if (taskId !== undefined) {
91
93
  return activity.getTaskIdentities({ taskId });
92
94
  }
93
95
  if (taskKey !== undefined) {
94
96
  return activity.getTaskIdentities({ taskKey, showDeleted: true });
95
97
  }
96
- const historicalKeys = new Set();
98
+ // A project selection counts only keys its own deletions recorded. Other pages check every key.
99
+ const selectionKeys = navigationEvents === undefined ? undefined : new Set();
100
+ const deletionEvents = navigationEvents ?? pageEvents;
97
101
  function addKey(key) {
98
102
  const parsed = activityTaskKeySchema.safeParse(key);
99
103
  if (parsed.success) {
100
- historicalKeys.add(parsed.data);
104
+ selectionKeys?.add(parsed.data);
101
105
  }
102
106
  }
103
- for (const event of events) {
107
+ for (const event of navigationEvents ?? []) {
104
108
  if (event.action !== "delete") {
105
109
  continue;
106
110
  }
@@ -115,48 +119,98 @@ function getTaskNavigation(events, taskKey, taskId) {
115
119
  }
116
120
  }
117
121
  }
118
- const identities = new Map();
119
- const needsTaskIdentities = historicalKeys.size > 0 || events.some((event) => event.entity_type === "task");
120
- if (needsTaskIdentities) {
121
- for (const item of task.getAll({ archive: "all" })) {
122
- identities.set(item.id, {
123
- id: item.id,
124
- key: item.key,
125
- title: item.title,
126
- status: item.archived_at == null ? "active" : "archived",
127
- });
128
- }
122
+ const isHistoricalKey = (key) => selectionKeys?.has(key) ?? true;
123
+ const needsTaskIdentities = (selectionKeys?.size ?? 0) > 0 || pageEvents.some((event) => event.entity_type === "task");
124
+ if (!needsTaskIdentities) {
125
+ return [];
129
126
  }
130
- function addSnapshot(id, key, title) {
127
+ /** A deleted task's recorded identity, when it is complete and holds a historical key. */
128
+ function toSnapshot(id, key, title) {
131
129
  const parsedKey = activityTaskKeySchema.safeParse(key);
132
130
  const isMatchingSnapshot = typeof id === "string" &&
133
131
  typeof key === "string" &&
134
132
  typeof title === "string" &&
135
133
  parsedKey.success &&
136
- historicalKeys.has(parsedKey.data);
137
- if (isMatchingSnapshot && !identities.has(id)) {
138
- identities.set(id, { id, key, title, status: "deleted" });
139
- }
134
+ isHistoricalKey(parsedKey.data);
135
+ return isMatchingSnapshot ? [{ id, key, title, status: "deleted" }] : [];
140
136
  }
141
- if (historicalKeys.size > 0) {
142
- for (const event of activity.getAll()) {
143
- if (event.action !== "delete") {
144
- continue;
145
- }
146
- if (event.entity_type === "task") {
147
- addSnapshot(event.entity_id, event.changes?.key, event.changes?.title);
137
+ const snapshots = deletionEvents.flatMap((event) => {
138
+ if (event.action !== "delete") {
139
+ return [];
140
+ }
141
+ if (event.entity_type === "task") {
142
+ return toSnapshot(event.entity_id, event.changes?.key, event.changes?.title);
143
+ }
144
+ if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
145
+ return event.changes.tasks
146
+ .filter(isRecord)
147
+ .flatMap((snapshot) => toSnapshot(snapshot.id, snapshot.key, snapshot.title));
148
+ }
149
+ return [];
150
+ });
151
+ // Current tasks the page names, removes or shares a deleted key with.
152
+ const referencedIds = new Set(snapshots.map((snapshot) => snapshot.id));
153
+ const pageTaskIds = new Set();
154
+ for (const event of pageEvents) {
155
+ if (event.entity_type === "task") {
156
+ referencedIds.add(event.entity_id);
157
+ pageTaskIds.add(event.entity_id);
158
+ }
159
+ else if (event.entity_type === "project" &&
160
+ event.action === "delete" &&
161
+ Array.isArray(event.changes?.tasks)) {
162
+ for (const snapshot of event.changes.tasks.filter(isRecord)) {
163
+ referencedIds.add(snapshot.id);
148
164
  }
149
- else if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
150
- for (const snapshot of event.changes.tasks) {
151
- if (isRecord(snapshot)) {
152
- addSnapshot(snapshot.id, snapshot.key, snapshot.title);
153
- }
154
- }
165
+ }
166
+ }
167
+ // Current identities come first, recorded deletions fill the gaps
168
+ const identities = new Map();
169
+ function addIdentities(items) {
170
+ for (const item of items) {
171
+ if (!identities.has(item.id)) {
172
+ identities.set(item.id, item);
155
173
  }
156
174
  }
157
175
  }
176
+ function addDeletedIdentities(items) {
177
+ addIdentities(items.flatMap((item) => item.status === "deleted" ? toSnapshot(item.id, item.key, item.title) : []));
178
+ }
179
+ addIdentities(activity.getCurrentTaskIdentities({ taskIds: parseTaskIds(referencedIds) }));
180
+ addIdentities(snapshots);
181
+ if (selectionKeys?.size === 0) {
182
+ return [...identities.values()];
183
+ }
184
+ // A page task deleted outside the deletion events above can still hold a historical key.
185
+ addDeletedIdentities(activity.getDeletedTaskIdentities({
186
+ taskIds: parseTaskIds(pageTaskIds).filter((id) => !identities.has(id)),
187
+ }));
188
+ // A historical key on the page needs every identity in the database that holds it
189
+ const pageKeys = new Set();
190
+ for (const id of pageTaskIds) {
191
+ const parsedKey = activityTaskKeySchema.safeParse(identities.get(id)?.key);
192
+ if (parsedKey.success && isHistoricalKey(parsedKey.data)) {
193
+ pageKeys.add(parsedKey.data);
194
+ }
195
+ }
196
+ addIdentities(activity.getCurrentTaskIdentities({ taskKeys: [...pageKeys] }));
197
+ // Two identities already settle that a key is shared.
198
+ const identityCounts = new Map();
199
+ for (const identity of identities.values()) {
200
+ identityCounts.set(identity.key, (identityCounts.get(identity.key) ?? 0) + 1);
201
+ }
202
+ addDeletedIdentities(activity.getDeletedTaskIdentities({
203
+ taskKeys: [...pageKeys].filter((key) => (identityCounts.get(key) ?? 0) < 2),
204
+ }));
158
205
  return [...identities.values()];
159
206
  }
207
+ /** The valid task IDs among the given values */
208
+ function parseTaskIds(values) {
209
+ return [...values].flatMap((value) => {
210
+ const parsed = activityTaskIdSchema.safeParse(value);
211
+ return parsed.success ? [parsed.data] : [];
212
+ });
213
+ }
160
214
  export function presentActivities(events, options = {}) {
161
215
  if (events.length === 0) {
162
216
  return [];
@@ -165,14 +219,20 @@ export function presentActivities(events, options = {}) {
165
219
  ? new Map()
166
220
  : abbreviateActivityIds(activity.getIds());
167
221
  const hasProjectSelector = options.projectKey !== undefined || options.projectId !== undefined;
222
+ // Recorded names and deleted task keys come only from create and delete snapshots
168
223
  const navigationEvents = hasProjectSelector
169
224
  ? activity.getAll({
170
225
  projectKey: options.projectKey,
171
226
  projectId: options.projectId,
172
227
  showDeleted: options.showDeleted,
173
- })
228
+ actions: ["create", "delete"],
229
+ }).events
174
230
  : events;
175
- const tasks = getTaskNavigation(navigationEvents, options.taskKey, options.taskId);
231
+ const tasks = getTaskNavigation(events, {
232
+ navigationEvents: hasProjectSelector || options.keysFromEventsOnly ? navigationEvents : undefined,
233
+ taskKey: options.taskKey,
234
+ taskId: options.taskId,
235
+ });
176
236
  const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
177
237
  const taskIdsByKey = new Map();
178
238
  for (const identity of tasks) {
@@ -301,6 +361,12 @@ function isRecordedChangePair(event, value) {
301
361
  Array.isArray(value) &&
302
362
  value.length === 2);
303
363
  }
364
+ function formatDeadline(value) {
365
+ const parsed = timestampSchema.safeParse(value);
366
+ return parsed.success
367
+ ? formatLocalTime(parsed.data, { includesSeconds: true })
368
+ : summarizeValue(value);
369
+ }
304
370
  function formatRemovedTasks(entry) {
305
371
  return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
306
372
  }
@@ -332,6 +398,11 @@ function formatChangeSummary(entry, options = {}) {
332
398
  if (field === "title" && options.omitsIdentity && isSnapshot) {
333
399
  return summarizeValue(value);
334
400
  }
401
+ if (field === "due_at") {
402
+ return isRecordedChangePair(event, value)
403
+ ? `${field}: ${formatDeadline(value[0])} → ${formatDeadline(value[1])}`
404
+ : `${field}: ${formatDeadline(value)}`;
405
+ }
335
406
  if (isRecordedChangePair(event, value)) {
336
407
  return `${field}: ${summarizeValue(value[0])} → ${summarizeValue(value[1])}`;
337
408
  }
@@ -423,9 +494,10 @@ function formatRecordedChanges(event) {
423
494
  unknownFields[field] = value;
424
495
  continue;
425
496
  }
497
+ const formatValue = field === "due_at" ? formatDeadline : formatRecordedValue;
426
498
  const body = isRecordedChangePair(event, value)
427
- ? `${formatSection("From", formatRecordedValue(value[0]))}\n\n${formatSection("To", formatRecordedValue(value[1]))}`
428
- : formatRecordedValue(value);
499
+ ? `${formatSection("From", formatValue(value[0]))}\n\n${formatSection("To", formatValue(value[1]))}`
500
+ : formatValue(value);
429
501
  sections.push(formatSection(field, body));
430
502
  }
431
503
  if (Object.keys(unknownFields).length > 0) {
@@ -444,6 +516,7 @@ export function presentActor(actor) {
444
516
  actor_agent: actor.agent ?? null,
445
517
  actor_model: actor.model ?? null,
446
518
  actor_effort: actor.effort ?? null,
519
+ actor_client: actor.client ?? null,
447
520
  };
448
521
  }
449
522
  export function formatActor(actor) {
@@ -458,6 +531,7 @@ export function formatActivityList(entries, options = {}) {
458
531
  { text: entry.displayId },
459
532
  { text: formatLocalTime(entry.event.created_at), style: "dim" },
460
533
  { text: `${entry.event.actor_name ?? UNKNOWN_ACTOR_NAME} (${entry.event.actor_kind})` },
534
+ { text: entry.event.actor_client ?? "null" },
461
535
  ];
462
536
  if (!options.showsDetails) {
463
537
  return [...metadata, { text: formatActivityContent(entry) }];
@@ -1,16 +1,31 @@
1
1
  import type { RowCell } from "./row-layout.js";
2
- import type { PresentedColumn } from "../result-schemas.js";
2
+ import type { PresentedColumn, PresentedColumnTaskCount } from "../result-schemas.js";
3
+ import { column } from "@zinn-dev/core";
3
4
  type ColumnRow = {
4
5
  name: string;
5
6
  project?: string;
6
7
  taskCount?: number;
8
+ is_first?: boolean;
9
+ is_last?: boolean;
10
+ };
11
+ /** A project's columns in board order. */
12
+ export type ProjectColumns = ReturnType<typeof column.getAllByProjectKey>;
13
+ /** Reads each project's columns once, so presenting many rows costs one read per project. */
14
+ export type ColumnBoard = (projectId: string) => ProjectColumns;
15
+ export declare function createColumnBoard(): ColumnBoard;
16
+ /** A column off its board, such as a deleted one, has no placement and no color. */
17
+ export declare function columnPlacement(projectColumns: ProjectColumns, columnId: string): {
18
+ is_first: boolean;
19
+ is_last: boolean;
7
20
  };
8
21
  export declare function presentColumn(columnMatch: {
9
22
  id: string;
10
23
  project_id: string;
11
24
  name: string;
12
25
  }): PresentedColumn;
13
- export declare function columnNameCell(columnName: string): RowCell;
26
+ /** Shapes one board's column rows, in order, with the placement each name is colored by. */
27
+ export declare function presentColumnTaskCounts(taskCounts: ReturnType<typeof column.getTaskCountsByProjectKey>): Array<PresentedColumnTaskCount>;
28
+ export declare function columnNameCell(columnName: string, placement?: Pick<ColumnRow, "is_first" | "is_last">): RowCell;
14
29
  /** The archived row is left out when there are no archived tasks. */
15
30
  export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
16
31
  showsProject?: boolean;
@@ -1,22 +1,57 @@
1
- import { project } from "@zinn-dev/core";
1
+ import { column, project } from "@zinn-dev/core";
2
2
  import { formatRows } from "./row-layout.js";
3
3
  /** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
4
4
  const ARCHIVED_ROW_LABEL = "Archived";
5
+ export function createColumnBoard() {
6
+ const projectColumnsByProjectId = new Map();
7
+ return (projectId) => {
8
+ const cachedColumns = projectColumnsByProjectId.get(projectId);
9
+ if (cachedColumns != null) {
10
+ return cachedColumns;
11
+ }
12
+ const boardColumns = column.getAllByProjectKey(project.getById(projectId).key);
13
+ projectColumnsByProjectId.set(projectId, boardColumns);
14
+ return boardColumns;
15
+ };
16
+ }
17
+ /** A column off its board, such as a deleted one, has no placement and no color. */
18
+ export function columnPlacement(projectColumns, columnId) {
19
+ const columnIndex = projectColumns.findIndex((boardColumn) => boardColumn.id === columnId);
20
+ const isOnBoard = columnIndex !== -1;
21
+ return {
22
+ is_first: isOnBoard && columnIndex === 0,
23
+ is_last: isOnBoard && columnIndex === projectColumns.length - 1,
24
+ };
25
+ }
5
26
  export function presentColumn(columnMatch) {
6
27
  const columnProject = project.getById(columnMatch.project_id);
28
+ const placement = columnPlacement(column.getAllByProjectKey(columnProject.key), columnMatch.id);
7
29
  return {
8
30
  id: columnMatch.id,
9
31
  project: columnProject.key,
10
32
  project_id: columnMatch.project_id,
11
33
  name: columnMatch.name,
34
+ is_first: placement.is_first,
35
+ is_last: placement.is_last,
12
36
  };
13
37
  }
14
- export function columnNameCell(columnName) {
15
- // TODO: Derive column colors from column roles once roles exist instead of relying on names.
16
- if (columnName === "Backlog") {
38
+ /** Shapes one board's column rows, in order, with the placement each name is colored by. */
39
+ export function presentColumnTaskCounts(taskCounts) {
40
+ const lastColumnIndex = taskCounts.columns.length - 1;
41
+ return taskCounts.columns.map((columnCount, columnIndex) => ({
42
+ id: columnCount.column.id,
43
+ name: columnCount.column.name,
44
+ is_first: columnIndex === 0,
45
+ is_last: columnIndex === lastColumnIndex,
46
+ taskCount: columnCount.taskCount,
47
+ }));
48
+ }
49
+ export function columnNameCell(columnName, placement = {}) {
50
+ // A board's first column is gray and its last is green. A one-column board is both, and colors as first.
51
+ if (placement.is_first) {
17
52
  return { text: columnName, style: "gray" };
18
53
  }
19
- if (columnName === "Done") {
54
+ if (placement.is_last) {
20
55
  return { text: columnName, style: "green" };
21
56
  }
22
57
  return { text: columnName };
@@ -30,7 +65,11 @@ export function formatColumnList(presentedColumns, options = {}) {
30
65
  const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
31
66
  ? [{ text: String(presentedColumn.taskCount) }]
32
67
  : [];
33
- return [...projectCells, columnNameCell(presentedColumn.name), ...taskCountCells];
68
+ return [
69
+ ...projectCells,
70
+ columnNameCell(presentedColumn.name, presentedColumn),
71
+ ...taskCountCells,
72
+ ];
34
73
  });
35
74
  if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
36
75
  rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
@@ -1,20 +1,7 @@
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
+ /** Formats a visual preview within a terminal-cell budget, including the ellipsis. */
17
2
  export declare function formatDescriptionPreview(description: string | null, options?: {
18
3
  maxLength?: number;
19
4
  firstLineOnly?: boolean;
20
5
  }): string;
6
+ /** Keeps parser reasons within their UTF-16-unit budget. */
7
+ export declare function formatParserReasonPreview(reason: string, maxLength: number): string;
@@ -1,21 +1,6 @@
1
+ import { displayWidth, graphemes } from "./text-width.js";
1
2
  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
- */
18
- export function formatDescriptionPreview(description, options = {}) {
3
+ function formatPreview(description, options, measure) {
19
4
  const previewLength = options.maxLength ?? DEFAULT_PREVIEW_LENGTH;
20
5
  if (description == null) {
21
6
  return "";
@@ -24,10 +9,26 @@ export function formatDescriptionPreview(description, options = {}) {
24
9
  const hasMoreLines = lineBreakIndex !== -1;
25
10
  const previewText = hasMoreLines ? description.slice(0, lineBreakIndex) : description;
26
11
  const normalizedDescription = previewText.replace(/\s+/g, " ").trim();
27
- if (normalizedDescription.length <= previewLength && !hasMoreLines) {
12
+ if (measure(normalizedDescription) <= previewLength && !hasMoreLines) {
28
13
  return normalizedDescription;
29
14
  }
30
- const truncatedDescription = normalizedDescription.slice(0, previewLength - 1);
31
- const completePrefix = truncatedDescription.replace(/\p{Surrogate}$/u, "");
32
- return `${completePrefix.trimEnd()}…`;
15
+ let prefix = "";
16
+ let prefixLength = 0;
17
+ for (const { segment } of graphemes(normalizedDescription)) {
18
+ const segmentLength = measure(segment);
19
+ if (prefixLength + segmentLength > previewLength - 1) {
20
+ break;
21
+ }
22
+ prefix += segment;
23
+ prefixLength += segmentLength;
24
+ }
25
+ return `${prefix.trimEnd()}…`;
26
+ }
27
+ /** Formats a visual preview within a terminal-cell budget, including the ellipsis. */
28
+ export function formatDescriptionPreview(description, options = {}) {
29
+ return formatPreview(description, options, displayWidth);
30
+ }
31
+ /** Keeps parser reasons within their UTF-16-unit budget. */
32
+ export function formatParserReasonPreview(reason, maxLength) {
33
+ return formatPreview(reason, { maxLength }, (text) => text.length);
33
34
  }
@@ -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,7 +1,11 @@
1
- import type { PresentedProject } from "../result-schemas.js";
1
+ import type { PresentedProject, PresentedProjectListEntry } from "../result-schemas.js";
2
+ type ProjectRow = PresentedProject & {
3
+ taskCounts?: PresentedProjectListEntry["taskCounts"];
4
+ };
2
5
  type ProjectRowOptions = {
3
6
  showsDescriptionPreview?: boolean;
7
+ showsTaskCounts?: boolean;
4
8
  };
5
9
  export declare function presentProject(projectMatch: PresentedProject): PresentedProject;
6
- export declare function formatProjectList(presentedProjects: Array<PresentedProject>, { showsDescriptionPreview }?: ProjectRowOptions): string;
10
+ export declare function formatProjectList(presentedProjects: Array<ProjectRow>, { showsDescriptionPreview, showsTaskCounts }?: ProjectRowOptions): string;
7
11
  export {};
@@ -8,12 +8,20 @@ export function presentProject(projectMatch) {
8
8
  description: projectMatch.description,
9
9
  };
10
10
  }
11
- export function formatProjectList(presentedProjects, { showsDescriptionPreview = true } = {}) {
11
+ export function formatProjectList(presentedProjects, { showsDescriptionPreview = true, showsTaskCounts = false } = {}) {
12
12
  return formatRows(presentedProjects.map((presented) => {
13
13
  const descriptionPreview = showsDescriptionPreview
14
14
  ? formatDescriptionPreview(presented.description)
15
15
  : "";
16
16
  const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
17
+ if (showsTaskCounts && presented.taskCounts != null) {
18
+ return [
19
+ { text: presented.key },
20
+ { text: presented.name },
21
+ { text: `${presented.taskCounts.active} active` },
22
+ { text: `${presented.taskCounts.archived} archived${description}` },
23
+ ];
24
+ }
17
25
  return [{ text: presented.key }, { text: `${presented.name}${description}` }];
18
26
  }));
19
27
  }
@@ -1,7 +1,16 @@
1
1
  import type { TaskWithKey } from "@zinn-dev/core";
2
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: {
3
+ import type { ColumnBoard } from "./column-presentation.js";
4
+ import type { RowCell } from "./row-layout.js";
5
+ import { relation } from "@zinn-dev/core";
6
+ export declare function presentRelationChange(entry: ReturnType<typeof relation.create>, source: TaskWithKey, target: TaskWithKey): PresentedRelationChange;
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;
11
+ export declare function formatRelationChange(change: Pick<PresentedRelationChange, "type" | "source" | "target">, options: {
6
12
  action: "create" | "delete";
13
+ } | {
14
+ action: "replace";
15
+ replaced: Array<PresentedRelationChange>;
7
16
  }): string;