@zinn-dev/cli 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import type { parseArgs } from "node:util";
2
2
 
3
- import { assertWritable, ReadOnlyDatabaseError, UnmarkedDatabaseError } from "@zinn-dev/core";
3
+ import {
4
+ assertWritable,
5
+ ReadOnlyDatabaseError,
6
+ TextEditMatchError,
7
+ UnmarkedDatabaseError,
8
+ } from "@zinn-dev/core";
4
9
 
5
10
  type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
6
11
  type OutputMode = "text" | "json";
@@ -73,6 +78,10 @@ export function failureMessage(error: any, fallback: string) {
73
78
  return `${error.message}. Add --allow-legacy-read to read it anyway.`;
74
79
  }
75
80
 
81
+ if (error instanceof TextEditMatchError && error.matchCount > 1) {
82
+ return `${error.message} Use --all to replace every match.`;
83
+ }
84
+
76
85
  if (error?.message === "no such table: task_search") {
77
86
  return `${error.message}. Run \`zinn reindex\` to rebuild the search index.`;
78
87
  }
@@ -80,23 +89,37 @@ export function failureMessage(error: any, fallback: string) {
80
89
  return error?.message ?? fallback;
81
90
  }
82
91
 
83
- export function quit(reason: string): never {
92
+ /** Prints the reason as an error, followed by help when given, and exits with code 1. */
93
+ export function quit(reason: string, help?: string): never {
84
94
  if (outputMode === "json") {
85
- console.error(JSON.stringify({ error: { message: reason } }, null, 2));
95
+ const error = help == null ? { message: reason } : { message: reason, help };
96
+ console.error(JSON.stringify({ error }, null, 2));
86
97
  } else {
87
- console.error(reason);
98
+ console.error(help == null ? reason : `${reason}\n\n${help}`);
88
99
  }
89
100
 
90
101
  process.exit(1);
91
102
  }
92
103
 
93
- export function validatePositionalCount(
94
- positionals: Array<string>,
95
- expected: number,
96
- message: string,
97
- ) {
98
- if (positionals.length !== expected) {
99
- quit(message);
104
+ /** A command was given the wrong words. The router prints the message with the command's usage lines. */
105
+ export class UsageError extends Error {}
106
+
107
+ /**
108
+ * Checks a command's words against its usage line, with the words written the same way:
109
+ * `<task-key>` is required, `[<project-key>]` is optional and `<task-key>...` repeats.
110
+ * Optional words go last.
111
+ */
112
+ export function validatePositionals(positionals: Array<string>, words: Array<string>) {
113
+ const requiredWords = words.filter((word) => !word.startsWith("["));
114
+ const missingWord = requiredWords[positionals.length];
115
+ if (missingWord !== undefined) {
116
+ throw new UsageError(`Missing argument ${missingWord}`);
117
+ }
118
+
119
+ const hasRepeatingWord = words.some((word) => word.endsWith("..."));
120
+ const extraWord = positionals[words.length];
121
+ if (!hasRepeatingWord && extraWord !== undefined) {
122
+ throw new UsageError(`Unexpected argument "${extraWord}"`);
100
123
  }
101
124
  }
102
125
 
@@ -0,0 +1,71 @@
1
+ import type { Activity } from "@zinn-dev/core";
2
+
3
+ import { expect, test } from "bun:test";
4
+ import { abbreviateActivityIds, formatActivityList } from "./activity-presentation";
5
+
6
+ test("activity abbreviations are shortest unique canonical prefixes across all supplied IDs", () => {
7
+ const first = "019abcdf-1234-7000-8000-123456abcde1";
8
+ const second = "019abcdf-1234-7000-8000-123456abcde2";
9
+ const earlier = "019abcdf-0234-7000-8000-123456abcde1";
10
+ const separate = "019abcda-1234-7000-8000-123456abcde1";
11
+ const prefixes = abbreviateActivityIds([second, separate, first, earlier]);
12
+ expect(prefixes.get(first)).toBe(first);
13
+ expect(prefixes.get(second)).toBe(second);
14
+ expect(prefixes.get(earlier)).toBe("019abcdf-0");
15
+ expect(prefixes.get(separate)).toBe("019abcda");
16
+ expect(abbreviateActivityIds([first]).get(first)).toBe("019abcdf");
17
+ });
18
+
19
+ test("activity text keeps full task identities when a long reused key needs disambiguation", () => {
20
+ const event: Activity = {
21
+ id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
22
+ actor_name: "Test", actor_email: null, actor_kind: "human",
23
+ entity_type: "task", entity_id: "019abcdf-1234-7000-8000-123456abcde2",
24
+ action: "archive", changes: null,
25
+ };
26
+ const text = formatActivityList([{ event, displayId: "019abcdf", removedTasks: [],
27
+ navigation: { name: `${"A".repeat(100)}-1`, status: "deleted", distinguishesTaskId: true } }]);
28
+ expect(text).toContain(event.entity_id);
29
+ expect(text).toContain("deleted");
30
+ expect(text).toContain("archive");
31
+ });
32
+
33
+ test("activity details keep explicit empty containers distinct from null changes", () => {
34
+ const event: Activity = {
35
+ id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
36
+ actor_name: "Test", actor_email: null, actor_kind: "human",
37
+ entity_type: "task", entity_id: "019abcdf-1234-7000-8000-123456abcde2",
38
+ action: "create", changes: { labels: [], column: {} },
39
+ };
40
+ const entry = { event, displayId: event.id, removedTasks: [] };
41
+ const text = formatActivityList([entry], { showsDetails: true });
42
+ expect(text).toContain("labels:\n[]");
43
+ expect(text).toContain("column:\n{}");
44
+ expect(formatActivityList([{ ...entry, event: { ...event, changes: null } }], { showsDetails: true }))
45
+ .toContain("Changes:\nnull");
46
+ });
47
+
48
+ test("long entity identities do not pad neighboring activity descriptions", () => {
49
+ const event: Activity = {
50
+ id: "019abcdf-1234-7000-8000-123456abcde1", created_at: 1,
51
+ actor_name: "Test", actor_email: null, actor_kind: "human",
52
+ entity_type: "task", entity_id: "task-id", action: "archive", changes: null,
53
+ };
54
+ const short = { event, displayId: "019abcdf", removedTasks: [],
55
+ navigation: { name: "APP-1", status: "archived" as const } };
56
+ const longKey = "PB137E58A84AC41B5A704693239312DF2";
57
+ const outlier = { ...short, displayId: "019abcda",
58
+ event: { ...event, id: "019abcda-1234-7000-8000-123456abcde1", entity_type: "project" as const,
59
+ action: "delete" as const, changes: { key: longKey, name: "Active ordering tail" } },
60
+ navigation: { name: longKey, status: "recorded" as const } };
61
+ const alone = formatActivityList([short]);
62
+ const together = formatActivityList([short, outlier]);
63
+ expect(together.split("\n")[0]).toBe(alone);
64
+ expect(alone).toContain("APP-1 · archived");
65
+ expect(alone).not.toContain("[archived]");
66
+ expect(together).toContain(`Full project key: ${longKey}`);
67
+ const contentColumn = alone.indexOf("APP-1");
68
+ expect(together.split("\n").find((line) => line.includes("Full project key:"))!.indexOf("Full project key:"))
69
+ .toBe(contentColumn);
70
+ expect(together.split("\n")[1]).not.toContain(longKey);
71
+ });
@@ -0,0 +1,489 @@
1
+ import type { Activity, ActivityAction, ActivityTaskIdentity } from "@zinn-dev/core";
2
+
3
+ import {
4
+ activity,
5
+ activityTaskKeySchema,
6
+ column,
7
+ label,
8
+ minimumActivityIdLength,
9
+ project,
10
+ task,
11
+ } from "@zinn-dev/core";
12
+ import { formatDescriptionPreview } from "./description-presentation";
13
+ import { formatRows } from "./row-layout";
14
+ import { formatSection } from "./section";
15
+ import { formatLocalTime } from "./time";
16
+
17
+ type NavigationIdentity = {
18
+ name: string;
19
+ status: "current" | "archived" | "deleted" | "recorded";
20
+ distinguishesTaskId?: boolean;
21
+ };
22
+
23
+ export type PresentedActivity = {
24
+ event: Activity;
25
+ displayId: string;
26
+ navigation?: NavigationIdentity;
27
+ removedTasks: Array<ActivityTaskIdentity>;
28
+ };
29
+
30
+ const RECORDED_FIELDS = new Set([
31
+ "id",
32
+ "key",
33
+ "name",
34
+ "title",
35
+ "description",
36
+ "priority",
37
+ "color",
38
+ "column",
39
+ "columns",
40
+ "project",
41
+ "tasks",
42
+ "labels",
43
+ "added",
44
+ "removed",
45
+ "type",
46
+ "source",
47
+ "target",
48
+ "comment",
49
+ "text",
50
+ ]);
51
+
52
+ const ENTITY_PREVIEW_LENGTH = 24;
53
+ const ACTION_LABELS: Record<ActivityAction, string> = {
54
+ create: "created",
55
+ edit: "edited",
56
+ move: "moved",
57
+ order: "reordered",
58
+ archive: "archived",
59
+ unarchive: "unarchived",
60
+ delete: "deleted",
61
+ relation_create: "added relation",
62
+ relation_delete: "removed relation",
63
+ comment_create: "added comment",
64
+ comment_edit: "edited comment",
65
+ comment_delete: "deleted comment",
66
+ };
67
+
68
+ function isRecord(value: unknown): value is Record<string, unknown> {
69
+ return value != null && typeof value === "object" && !Array.isArray(value);
70
+ }
71
+
72
+ function commonPrefixLength(left: string, right: string) {
73
+ let length = 0;
74
+ while (length < left.length && length < right.length && left[length] === right[length]) {
75
+ length++;
76
+ }
77
+
78
+ return length;
79
+ }
80
+
81
+ function canonicalPrefix(id: string, hexLength: number) {
82
+ let digits = 0;
83
+
84
+ for (let index = 0; index < id.length; index++) {
85
+ if (id[index] !== "-") {
86
+ digits++;
87
+ }
88
+ if (digits === hexLength) {
89
+ return id.slice(0, index + 1);
90
+ }
91
+ }
92
+ return id;
93
+ }
94
+
95
+ /** Neighbors in sorted UUID order determine the shortest globally unique left prefix. */
96
+ export function abbreviateActivityIds(ids: Array<string>) {
97
+ const sorted = ids
98
+ .map((id) => ({ id, hex: id.replaceAll("-", "").toLowerCase() }))
99
+ .sort((left, right) => left.hex.localeCompare(right.hex));
100
+ const prefixes = new Map<string, string>();
101
+
102
+ for (const [index, entry] of sorted.entries()) {
103
+ const previous = sorted[index - 1]?.hex ?? "";
104
+ const next = sorted[index + 1]?.hex ?? "";
105
+ const length = Math.max(
106
+ minimumActivityIdLength,
107
+ commonPrefixLength(entry.hex, previous) + 1,
108
+ commonPrefixLength(entry.hex, next) + 1,
109
+ );
110
+ prefixes.set(entry.id, canonicalPrefix(entry.id, length));
111
+ }
112
+
113
+ return prefixes;
114
+ }
115
+
116
+ function getTaskNavigation(events: Array<Activity>, taskKey?: string) {
117
+ if (taskKey !== undefined) {
118
+ return activity.getTaskIdentities(taskKey);
119
+ }
120
+
121
+ const identities = new Map<string, ActivityTaskIdentity>();
122
+ if (events.some((event) => event.entity_type === "task")) {
123
+ for (const item of task.getAll({ archive: "all" })) {
124
+ identities.set(item.id, {
125
+ id: item.id,
126
+ key: item.key,
127
+ title: item.title,
128
+ status: item.archived_at == null ? "active" : "archived",
129
+ });
130
+ }
131
+ }
132
+
133
+ const historicalKeys = new Set<string>();
134
+ function addKey(key: unknown) {
135
+ const parsed = activityTaskKeySchema.safeParse(key);
136
+ if (parsed.success) {
137
+ historicalKeys.add(parsed.data);
138
+ }
139
+ }
140
+
141
+ for (const event of events) {
142
+ if (event.action !== "delete") {
143
+ continue;
144
+ }
145
+
146
+ if (event.entity_type === "task") {
147
+ addKey(event.changes?.key);
148
+ } else if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
149
+ for (const snapshot of event.changes.tasks) {
150
+ if (isRecord(snapshot)) {
151
+ addKey(snapshot.key);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ for (const key of historicalKeys) {
157
+ for (const identity of activity.getTaskIdentities(key)) {
158
+ identities.set(identity.id, identity);
159
+ }
160
+ }
161
+
162
+ return [...identities.values()];
163
+ }
164
+
165
+ export function presentActivities(
166
+ events: Array<Activity>,
167
+ options: { taskKey?: string; showsFullIds?: boolean } = {},
168
+ ): Array<PresentedActivity> {
169
+ if (events.length === 0) {
170
+ return [];
171
+ }
172
+
173
+ const prefixes = options.showsFullIds
174
+ ? new Map<string, string>()
175
+ : abbreviateActivityIds(activity.getIds());
176
+ const tasks = getTaskNavigation(events, options.taskKey);
177
+ const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
178
+ const taskIdsByKey = new Map<string, number>();
179
+
180
+ for (const identity of tasks) {
181
+ taskIdsByKey.set(identity.key, (taskIdsByKey.get(identity.key) ?? 0) + 1);
182
+ }
183
+
184
+ const projectsById = new Map(project.getAll().map((item) => [item.id, item]));
185
+ const labelsById = events.some((event) => event.entity_type === "label")
186
+ ? new Map(label.getAll().map((item) => [item.id, item]))
187
+ : new Map();
188
+ const navigationByEntity = new Map<string, NavigationIdentity | undefined>();
189
+
190
+ return events.map((event) => {
191
+ const entityKey = `${event.entity_type}:${event.entity_id}`;
192
+ let navigation = navigationByEntity.get(entityKey);
193
+
194
+ if (!navigationByEntity.has(entityKey)) {
195
+ switch (event.entity_type) {
196
+ case "task": {
197
+ const identity = tasksById.get(event.entity_id);
198
+ if (identity !== undefined) {
199
+ navigation = {
200
+ name: identity.key,
201
+ status: identity.status === "active" ? "current" : identity.status,
202
+ distinguishesTaskId: taskIdsByKey.get(identity.key)! > 1,
203
+ };
204
+ }
205
+ break;
206
+ }
207
+ case "project": {
208
+ const current = projectsById.get(event.entity_id);
209
+ if (current !== undefined) {
210
+ navigation = { name: current.key, status: "current" };
211
+ }
212
+ break;
213
+ }
214
+ case "column": {
215
+ const current = column.getById(event.entity_id);
216
+ if (current != null) {
217
+ navigation = { name: current.name, status: "current" };
218
+ }
219
+ break;
220
+ }
221
+ case "label": {
222
+ const current = labelsById.get(event.entity_id);
223
+ if (current !== undefined) {
224
+ navigation = { name: current.name, status: "current" };
225
+ }
226
+ break;
227
+ }
228
+ }
229
+ navigationByEntity.set(entityKey, navigation);
230
+ }
231
+ const isSnapshot = event.action === "create" || event.action === "delete";
232
+ const recordedName = event.changes?.key ?? event.changes?.name;
233
+
234
+ if (navigation === undefined && isSnapshot && typeof recordedName === "string") {
235
+ navigation = { name: recordedName, status: "recorded" };
236
+ }
237
+
238
+ const removedTaskIds =
239
+ event.entity_type === "project" &&
240
+ event.action === "delete" &&
241
+ Array.isArray(event.changes?.tasks)
242
+ ? new Set(event.changes.tasks.filter(isRecord).map((snapshot) => snapshot.id))
243
+ : new Set();
244
+
245
+ return {
246
+ event,
247
+ displayId: options.showsFullIds ? event.id : prefixes.get(event.id)!,
248
+ navigation,
249
+ removedTasks:
250
+ options.taskKey === undefined
251
+ ? []
252
+ : tasks.filter((identity) => removedTaskIds.has(identity.id)),
253
+ };
254
+ });
255
+ }
256
+
257
+ function formatNavigation(entry: PresentedActivity, options: { showsFullNames?: boolean } = {}) {
258
+ const { event, navigation } = entry;
259
+ if (navigation === undefined) {
260
+ return `${event.entity_type} ${event.entity_id}`;
261
+ }
262
+
263
+ const identity = navigation.distinguishesTaskId ? `; ${event.entity_id}` : "";
264
+ const name = options.showsFullNames ? navigation.name : formatDescriptionPreview(navigation.name);
265
+ return `${event.entity_type} ${name} [${navigation.status}${identity}]`;
266
+ }
267
+
268
+ function summarizeValue(value: unknown): string {
269
+ if (typeof value === "string") {
270
+ return value;
271
+ }
272
+
273
+ if (isRecord(value)) {
274
+ const name = value.key ?? value.name ?? value.title ?? value.id;
275
+ if (typeof name === "string") {
276
+ return name;
277
+ }
278
+ }
279
+
280
+ return JSON.stringify(value);
281
+ }
282
+
283
+ function isRecordedChangePair(event: Activity, value: unknown): value is [unknown, unknown] {
284
+ return (
285
+ ["edit", "move", "comment_edit"].includes(event.action) &&
286
+ Array.isArray(value) &&
287
+ value.length === 2
288
+ );
289
+ }
290
+
291
+ function formatRemovedTasks(entry: PresentedActivity) {
292
+ return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
293
+ }
294
+
295
+ function formatChangeSummary(
296
+ entry: PresentedActivity,
297
+ options: { showsRemovedTasks?: boolean; omitsIdentity?: boolean } = {},
298
+ ) {
299
+ const { event } = entry;
300
+ const changes = event.changes;
301
+ let summary = "-";
302
+
303
+ if (changes !== null) {
304
+ summary =
305
+ Object.entries(changes)
306
+ .map(([field, value]) => {
307
+ const isSnapshot = event.action === "create" || event.action === "delete";
308
+ if (isSnapshot && value === null) {
309
+ return null;
310
+ }
311
+ const repeatsIdentity =
312
+ options.omitsIdentity &&
313
+ isSnapshot &&
314
+ (field === "key" || field === "name") &&
315
+ value === entry.navigation?.name;
316
+ if (repeatsIdentity) {
317
+ return null;
318
+ }
319
+ if (!RECORDED_FIELDS.has(field)) {
320
+ return `${field}: ${JSON.stringify(value)}`;
321
+ }
322
+ if (field === "description") {
323
+ return event.action === "edit" ? "description changed" : "description recorded";
324
+ }
325
+ if (field === "title" && options.omitsIdentity && isSnapshot) {
326
+ return summarizeValue(value);
327
+ }
328
+ if (isRecordedChangePair(event, value)) {
329
+ return `${field}: ${summarizeValue(value[0])} → ${summarizeValue(value[1])}`;
330
+ }
331
+ if (Array.isArray(value)) {
332
+ if (field === "labels" && value.length === 0) {
333
+ return null;
334
+ }
335
+ return `${field}: ${value.length}`;
336
+ }
337
+ if (field === "labels" && isRecord(value)) {
338
+ const additions =
339
+ Array.isArray(value.added) && value.added.length > 0
340
+ ? `added labels ${value.added.map(summarizeValue).join(", ")}`
341
+ : "";
342
+ const removals =
343
+ Array.isArray(value.removed) && value.removed.length > 0
344
+ ? `removed labels ${value.removed.map(summarizeValue).join(", ")}`
345
+ : "";
346
+ return (
347
+ [additions, removals].filter((part) => part.length > 0).join("; ") ||
348
+ `labels: ${JSON.stringify(value)}`
349
+ );
350
+ }
351
+ if (field === "comment" && isRecord(value)) {
352
+ return `comment ${summarizeValue(value)}${typeof value.text === "string" ? `: ${value.text}` : ""}`;
353
+ }
354
+ return `${field}: ${summarizeValue(value)}`;
355
+ })
356
+ .filter((part) => part !== null)
357
+ .join("; ") || "-";
358
+ }
359
+ const removed = options.showsRemovedTasks === false ? "" : formatRemovedTasks(entry).join("; ");
360
+ return [formatDescriptionPreview(summary), removed].filter((part) => part.length > 0).join("; ");
361
+ }
362
+
363
+ function formatActivityContent(entry: PresentedActivity) {
364
+ const { event, navigation } = entry;
365
+ const name = navigation?.name ?? event.entity_id;
366
+ const shortName = formatDescriptionPreview(name, { maxLength: ENTITY_PREVIEW_LENGTH });
367
+ const entityType =
368
+ event.entity_type === "task" && navigation !== undefined ? "" : `${event.entity_type} `;
369
+ const isMutableCurrentName =
370
+ navigation?.status === "current" &&
371
+ (event.entity_type === "label" || event.entity_type === "column");
372
+ const provenance =
373
+ navigation?.status === "recorded"
374
+ ? " [recorded]"
375
+ : isMutableCurrentName
376
+ ? " [current name]"
377
+ : "";
378
+ const action = ACTION_LABELS[event.action] ?? event.action;
379
+ const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
380
+ const lines = [
381
+ `${entityType}${shortName}${provenance} · ${action}${summary === "-" ? "" : `: ${summary}`}`,
382
+ ];
383
+
384
+ if (shortName !== name) {
385
+ const nameLabel =
386
+ navigation === undefined
387
+ ? "Entity ID"
388
+ : event.entity_type === "task" || event.entity_type === "project"
389
+ ? `Full ${event.entity_type} key`
390
+ : `Full ${event.entity_type} name`;
391
+ lines.push(`${nameLabel}: ${name}`);
392
+ }
393
+ if (navigation?.distinguishesTaskId) {
394
+ lines.push(`Task identity: ${navigation.status}; ${event.entity_id}`);
395
+ }
396
+ lines.push(...formatRemovedTasks(entry));
397
+ return lines.join("\n");
398
+ }
399
+
400
+ function formatRecordedValue(value: unknown): string {
401
+ if (typeof value === "string") {
402
+ return value;
403
+ }
404
+ if (Array.isArray(value)) {
405
+ if (value.length === 0) {
406
+ return "[]";
407
+ }
408
+ return value
409
+ .map((item, index) => formatSection(`Item ${index + 1}`, formatRecordedValue(item)))
410
+ .join("\n\n");
411
+ }
412
+ if (isRecord(value)) {
413
+ return (
414
+ Object.entries(value)
415
+ .map(([field, item]) =>
416
+ formatSection(
417
+ field,
418
+ RECORDED_FIELDS.has(field) ? formatRecordedValue(item) : JSON.stringify(item, null, 2),
419
+ ),
420
+ )
421
+ .join("\n\n") || "{}"
422
+ );
423
+ }
424
+ return JSON.stringify(value);
425
+ }
426
+
427
+ function formatRecordedChanges(event: Activity) {
428
+ if (event.changes === null) {
429
+ return "null";
430
+ }
431
+
432
+ const sections: Array<string> = [];
433
+ const unknownFields: Record<string, unknown> = {};
434
+ for (const [field, value] of Object.entries(event.changes)) {
435
+ if (!RECORDED_FIELDS.has(field)) {
436
+ unknownFields[field] = value;
437
+ continue;
438
+ }
439
+ const body = isRecordedChangePair(event, value)
440
+ ? `${formatSection("From", formatRecordedValue(value[0]))}\n\n${formatSection("To", formatRecordedValue(value[1]))}`
441
+ : formatRecordedValue(value);
442
+ sections.push(formatSection(field, body));
443
+ }
444
+ if (Object.keys(unknownFields).length > 0) {
445
+ sections.push(formatSection("Raw JSON", JSON.stringify(unknownFields, null, 2)));
446
+ }
447
+ return sections.join("\n\n") || "{}";
448
+ }
449
+
450
+ export function formatActivityList(
451
+ entries: Array<PresentedActivity>,
452
+ options: { showsDetails?: boolean } = {},
453
+ ) {
454
+ const rows = entries.map((entry) => {
455
+ const metadata = [
456
+ { text: entry.displayId },
457
+ { text: formatLocalTime(entry.event.created_at), style: "dim" as const },
458
+ { text: `${entry.event.actor_name} (${entry.event.actor_kind})` },
459
+ ];
460
+ if (!options.showsDetails) {
461
+ return [...metadata, { text: formatActivityContent(entry) }];
462
+ }
463
+ return [
464
+ ...metadata,
465
+ { text: formatNavigation(entry, { showsFullNames: true }) },
466
+ { text: entry.event.action },
467
+ { text: formatChangeSummary(entry) },
468
+ ];
469
+ });
470
+ if (!options.showsDetails) {
471
+ return formatRows(rows, { indentsContinuationLines: true });
472
+ }
473
+ return entries
474
+ .map((entry, index) =>
475
+ [
476
+ formatRows([rows[index]!]),
477
+ formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`),
478
+ ...(entry.navigation === undefined
479
+ ? []
480
+ : [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
481
+ formatSection(
482
+ "Actor",
483
+ `${entry.event.actor_name}\nKind: ${entry.event.actor_kind}\nEmail: ${entry.event.actor_email ?? "null"}`,
484
+ ),
485
+ formatSection("Changes", formatRecordedChanges(entry.event)),
486
+ ].join("\n\n"),
487
+ )
488
+ .join("\n\n");
489
+ }
@@ -2,7 +2,8 @@ import type { RowCell } from "./row-layout";
2
2
 
3
3
  import { formatRows } from "./row-layout";
4
4
 
5
- export type PresentedColumnTaskCount = { name: string; taskCount: number };
5
+ export type PresentedColumn = { name: string; project?: string; taskCount?: number };
6
+ export type PresentedColumnTaskCount = PresentedColumn & { taskCount: number };
6
7
 
7
8
  /** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
8
9
  const ARCHIVED_ROW_LABEL = "Archived";
@@ -21,16 +22,25 @@ export function columnNameCell(columnName: string): RowCell {
21
22
  }
22
23
 
23
24
  /** The archived row is left out when there are no archived tasks. */
24
- export function formatColumnTaskCounts(
25
- presentedColumns: Array<PresentedColumnTaskCount>,
26
- options: { archivedTaskCount: number },
25
+ export function formatColumnList(
26
+ presentedColumns: Array<PresentedColumn>,
27
+ options: { showsProject?: boolean; showsTaskCounts?: boolean; archivedTaskCount?: number } = {},
27
28
  ) {
28
- const rows: Array<Array<RowCell>> = presentedColumns.map((presentedColumn) => [
29
- columnNameCell(presentedColumn.name),
30
- { text: String(presentedColumn.taskCount) },
31
- ]);
29
+ const rows: Array<Array<RowCell>> = presentedColumns.map((presentedColumn) => {
30
+ const projectCells: Array<RowCell> =
31
+ options.showsProject && presentedColumn.project != null
32
+ ? [{ text: presentedColumn.project }]
33
+ : [];
32
34
 
33
- if (options.archivedTaskCount > 0) {
35
+ const taskCountCells: Array<RowCell> =
36
+ options.showsTaskCounts && presentedColumn.taskCount != null
37
+ ? [{ text: String(presentedColumn.taskCount) }]
38
+ : [];
39
+
40
+ return [...projectCells, columnNameCell(presentedColumn.name), ...taskCountCells];
41
+ });
42
+
43
+ if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
34
44
  rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
35
45
  }
36
46