@zinn-dev/cli 0.39.0 → 0.41.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 (113) hide show
  1. package/README.md +171 -40
  2. package/index.d.ts +2 -0
  3. package/index.js +34 -0
  4. package/package.json +27 -18
  5. package/skills/zinn/SKILL.md +63 -0
  6. package/src/actor.d.ts +7 -0
  7. package/src/actor.js +129 -0
  8. package/src/capabilities-schema.d.ts +163 -0
  9. package/src/capabilities-schema.js +124 -0
  10. package/src/capabilities.d.ts +21 -0
  11. package/src/capabilities.js +22 -0
  12. package/src/database.d.ts +6 -0
  13. package/src/database.js +27 -0
  14. package/src/errors.d.ts +158 -0
  15. package/src/errors.js +224 -0
  16. package/src/input.d.ts +116 -0
  17. package/src/input.js +119 -0
  18. package/src/lib.d.ts +66 -0
  19. package/src/lib.js +333 -0
  20. package/src/presentation/activity-presentation.d.ts +23 -0
  21. package/src/presentation/activity-presentation.js +403 -0
  22. package/src/presentation/color.d.ts +9 -0
  23. package/src/presentation/color.js +21 -0
  24. package/src/presentation/column-presentation.d.ts +14 -0
  25. package/src/presentation/column-presentation.js +29 -0
  26. package/src/presentation/description-presentation.d.ts +3 -0
  27. package/src/presentation/description-presentation.js +11 -0
  28. package/src/presentation/info-presentation.d.ts +4 -0
  29. package/src/presentation/info-presentation.js +96 -0
  30. package/src/presentation/row-layout.d.ts +22 -0
  31. package/src/presentation/row-layout.js +58 -0
  32. package/src/presentation/section.d.ts +4 -0
  33. package/src/presentation/section.js +9 -0
  34. package/src/presentation/task-presentation.d.ts +9 -0
  35. package/src/presentation/task-presentation.js +62 -0
  36. package/src/presentation/time.d.ts +1 -0
  37. package/src/presentation/time.js +13 -0
  38. package/src/project.d.ts +12 -0
  39. package/src/project.js +44 -0
  40. package/src/release-identity.d.ts +2 -0
  41. package/src/release-identity.js +1 -0
  42. package/src/result-schemas.d.ts +987 -0
  43. package/src/result-schemas.js +220 -0
  44. package/src/results.d.ts +23 -0
  45. package/src/results.js +17 -0
  46. package/src/routes/activity-router.d.ts +81 -0
  47. package/src/routes/activity-router.js +119 -0
  48. package/src/routes/backup-router.d.ts +21 -0
  49. package/src/routes/backup-router.js +30 -0
  50. package/src/routes/capabilities-router.d.ts +21 -0
  51. package/src/routes/capabilities-router.js +28 -0
  52. package/src/routes/comment-router.d.ts +203 -0
  53. package/src/routes/comment-router.js +241 -0
  54. package/src/routes/info-router.d.ts +21 -0
  55. package/src/routes/info-router.js +29 -0
  56. package/src/routes/label-router.d.ts +183 -0
  57. package/src/routes/label-router.js +218 -0
  58. package/src/routes/migrate-router.d.ts +21 -0
  59. package/src/routes/migrate-router.js +49 -0
  60. package/src/routes/project-router.d.ts +389 -0
  61. package/src/routes/project-router.js +514 -0
  62. package/src/routes/reindex-router.d.ts +21 -0
  63. package/src/routes/reindex-router.js +33 -0
  64. package/src/routes/relation-router.d.ts +124 -0
  65. package/src/routes/relation-router.js +223 -0
  66. package/src/routes/restore-router.d.ts +33 -0
  67. package/src/routes/restore-router.js +88 -0
  68. package/src/routes/router.d.ts +6 -0
  69. package/src/routes/router.js +204 -0
  70. package/src/routes/routes.d.ts +1735 -0
  71. package/src/routes/routes.js +23 -0
  72. package/src/routes/task-router.d.ts +945 -0
  73. package/src/routes/task-router.js +789 -0
  74. package/src/text-edit.d.ts +43 -0
  75. package/src/text-edit.js +57 -0
  76. package/src/types.d.ts +24 -0
  77. package/src/types.js +1 -0
  78. package/index.ts +0 -26
  79. package/release-stamp.json +0 -1
  80. package/src/actor.test.ts +0 -41
  81. package/src/actor.ts +0 -78
  82. package/src/database.test.ts +0 -70
  83. package/src/database.ts +0 -41
  84. package/src/lib.test.ts +0 -86
  85. package/src/lib.ts +0 -159
  86. package/src/presentation/activity-presentation.test.ts +0 -112
  87. package/src/presentation/activity-presentation.ts +0 -490
  88. package/src/presentation/color.ts +0 -29
  89. package/src/presentation/column-presentation.ts +0 -48
  90. package/src/presentation/description-presentation.ts +0 -18
  91. package/src/presentation/row-layout.ts +0 -77
  92. package/src/presentation/section.ts +0 -16
  93. package/src/presentation/task-presentation.ts +0 -92
  94. package/src/presentation/time.ts +0 -17
  95. package/src/project.test.ts +0 -479
  96. package/src/project.ts +0 -53
  97. package/src/routes/activity-router.ts +0 -81
  98. package/src/routes/backup-router.ts +0 -24
  99. package/src/routes/comment-router.ts +0 -171
  100. package/src/routes/label-router.ts +0 -168
  101. package/src/routes/migrate-router.test.ts +0 -31
  102. package/src/routes/migrate-router.ts +0 -48
  103. package/src/routes/project-router.ts +0 -415
  104. package/src/routes/reindex-router.ts +0 -27
  105. package/src/routes/relation-router.ts +0 -194
  106. package/src/routes/restore-router.test.ts +0 -44
  107. package/src/routes/restore-router.ts +0 -90
  108. package/src/routes/router.test.ts +0 -136
  109. package/src/routes/router.ts +0 -248
  110. package/src/routes/routes.ts +0 -20
  111. package/src/routes/task-router.ts +0 -649
  112. package/src/text-edit.ts +0 -68
  113. package/src/types.ts +0 -6
@@ -0,0 +1,403 @@
1
+ import { activity, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, } from "@zinn-dev/core";
2
+ import { formatDescriptionPreview } from "./description-presentation.js";
3
+ import { formatRows } from "./row-layout.js";
4
+ import { formatSection } from "./section.js";
5
+ import { formatLocalTime } from "./time.js";
6
+ const RECORDED_FIELDS = new Set([
7
+ "id",
8
+ "key",
9
+ "name",
10
+ "title",
11
+ "description",
12
+ "priority",
13
+ "color",
14
+ "column",
15
+ "columns",
16
+ "project",
17
+ "tasks",
18
+ "labels",
19
+ "added",
20
+ "removed",
21
+ "type",
22
+ "source",
23
+ "target",
24
+ "comment",
25
+ "text",
26
+ ]);
27
+ const ENTITY_PREVIEW_LENGTH = 24;
28
+ const UNKNOWN_ACTOR_NAME = "unknown";
29
+ const ACTOR_DETAIL_FIELDS = [
30
+ { key: "actor_kind", label: "Kind" },
31
+ { key: "actor_email", label: "Email" },
32
+ { key: "actor_source", label: "Source" },
33
+ { key: "actor_session_id", label: "Session" },
34
+ { key: "actor_thread_id", label: "Thread" },
35
+ { key: "actor_agent", label: "Agent" },
36
+ { key: "actor_model", label: "Model" },
37
+ { key: "actor_effort", label: "Effort" },
38
+ ];
39
+ const ACTION_LABELS = {
40
+ create: "created",
41
+ edit: "edited",
42
+ move: "moved",
43
+ order: "reordered",
44
+ archive: "archived",
45
+ unarchive: "unarchived",
46
+ delete: "deleted",
47
+ relation_create: "added relation",
48
+ relation_delete: "removed relation",
49
+ comment_create: "added comment",
50
+ comment_edit: "edited comment",
51
+ comment_delete: "deleted comment",
52
+ };
53
+ function isRecord(value) {
54
+ return value != null && typeof value === "object" && !Array.isArray(value);
55
+ }
56
+ function commonPrefixLength(left, right) {
57
+ let length = 0;
58
+ while (length < left.length && length < right.length && left[length] === right[length]) {
59
+ length++;
60
+ }
61
+ return length;
62
+ }
63
+ function canonicalPrefix(id, hexLength) {
64
+ let digits = 0;
65
+ for (let index = 0; index < id.length; index++) {
66
+ if (id[index] !== "-") {
67
+ digits++;
68
+ }
69
+ if (digits === hexLength) {
70
+ return id.slice(0, index + 1);
71
+ }
72
+ }
73
+ return id;
74
+ }
75
+ /** Neighbors in sorted UUID order determine the shortest globally unique left prefix. */
76
+ export function abbreviateActivityIds(ids) {
77
+ const sorted = ids
78
+ .map((id) => ({ id, hex: id.replaceAll("-", "").toLowerCase() }))
79
+ .sort((left, right) => left.hex.localeCompare(right.hex));
80
+ const prefixes = new Map();
81
+ for (const [index, entry] of sorted.entries()) {
82
+ const previous = sorted[index - 1]?.hex ?? "";
83
+ const next = sorted[index + 1]?.hex ?? "";
84
+ const length = Math.max(minimumActivityIdLength, commonPrefixLength(entry.hex, previous) + 1, commonPrefixLength(entry.hex, next) + 1);
85
+ prefixes.set(entry.id, canonicalPrefix(entry.id, length));
86
+ }
87
+ return prefixes;
88
+ }
89
+ function getTaskNavigation(events, taskKey) {
90
+ if (taskKey !== undefined) {
91
+ return activity.getTaskIdentities(taskKey);
92
+ }
93
+ const identities = new Map();
94
+ if (events.some((event) => event.entity_type === "task")) {
95
+ for (const item of task.getAll({ archive: "all" })) {
96
+ identities.set(item.id, {
97
+ id: item.id,
98
+ key: item.key,
99
+ title: item.title,
100
+ status: item.archived_at == null ? "active" : "archived",
101
+ });
102
+ }
103
+ }
104
+ const historicalKeys = new Set();
105
+ function addKey(key) {
106
+ const parsed = activityTaskKeySchema.safeParse(key);
107
+ if (parsed.success) {
108
+ historicalKeys.add(parsed.data);
109
+ }
110
+ }
111
+ for (const event of events) {
112
+ if (event.action !== "delete") {
113
+ continue;
114
+ }
115
+ if (event.entity_type === "task") {
116
+ addKey(event.changes?.key);
117
+ }
118
+ else if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
119
+ for (const snapshot of event.changes.tasks) {
120
+ if (isRecord(snapshot)) {
121
+ addKey(snapshot.key);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ for (const key of historicalKeys) {
127
+ for (const identity of activity.getTaskIdentities(key)) {
128
+ identities.set(identity.id, identity);
129
+ }
130
+ }
131
+ return [...identities.values()];
132
+ }
133
+ export function presentActivities(events, options = {}) {
134
+ if (events.length === 0) {
135
+ return [];
136
+ }
137
+ const prefixes = options.showsFullIds
138
+ ? new Map()
139
+ : abbreviateActivityIds(activity.getIds());
140
+ const tasks = getTaskNavigation(events, options.taskKey);
141
+ const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
142
+ const taskIdsByKey = new Map();
143
+ for (const identity of tasks) {
144
+ taskIdsByKey.set(identity.key, (taskIdsByKey.get(identity.key) ?? 0) + 1);
145
+ }
146
+ const projectsById = new Map(project.getAll().map((item) => [item.id, item]));
147
+ const labelsById = events.some((event) => event.entity_type === "label")
148
+ ? new Map(label.getAll().map((item) => [item.id, item]))
149
+ : new Map();
150
+ const navigationByEntity = new Map();
151
+ return events.map((event) => {
152
+ const entityKey = `${event.entity_type}:${event.entity_id}`;
153
+ let navigation = navigationByEntity.get(entityKey);
154
+ if (!navigationByEntity.has(entityKey)) {
155
+ switch (event.entity_type) {
156
+ case "task": {
157
+ const identity = tasksById.get(event.entity_id);
158
+ if (identity !== undefined) {
159
+ navigation = {
160
+ name: identity.key,
161
+ status: identity.status === "active" ? "current" : identity.status,
162
+ distinguishesTaskId: taskIdsByKey.get(identity.key) > 1,
163
+ };
164
+ }
165
+ break;
166
+ }
167
+ case "project": {
168
+ const current = projectsById.get(event.entity_id);
169
+ if (current !== undefined) {
170
+ navigation = { name: current.key, status: "current" };
171
+ }
172
+ break;
173
+ }
174
+ case "column": {
175
+ const current = column.getById(event.entity_id);
176
+ if (current != null) {
177
+ navigation = { name: current.name, status: "current" };
178
+ }
179
+ break;
180
+ }
181
+ case "label": {
182
+ const current = labelsById.get(event.entity_id);
183
+ if (current !== undefined) {
184
+ navigation = { name: current.name, status: "current" };
185
+ }
186
+ break;
187
+ }
188
+ }
189
+ navigationByEntity.set(entityKey, navigation);
190
+ }
191
+ const isSnapshot = event.action === "create" || event.action === "delete";
192
+ const recordedName = event.changes?.key ?? event.changes?.name;
193
+ // Every existing entity was found above, so it means that a missing one has been *deleted*.
194
+ if (navigation === undefined) {
195
+ navigation = {
196
+ name: isSnapshot && typeof recordedName === "string" ? recordedName : undefined,
197
+ status: "deleted",
198
+ };
199
+ }
200
+ const isProjectDeletion = event.entity_type === "project" && event.action === "delete";
201
+ const removedTaskIds = isProjectDeletion && Array.isArray(event.changes?.tasks)
202
+ ? new Set(event.changes.tasks.filter(isRecord).map((snapshot) => snapshot.id))
203
+ : new Set();
204
+ return {
205
+ event,
206
+ displayId: options.showsFullIds ? event.id : prefixes.get(event.id),
207
+ navigation,
208
+ removedTasks: options.taskKey === undefined
209
+ ? []
210
+ : tasks.filter((identity) => removedTaskIds.has(identity.id)),
211
+ };
212
+ });
213
+ }
214
+ function formatNavigation(entry, options = {}) {
215
+ const { event, navigation } = entry;
216
+ const identity = navigation.distinguishesTaskId ? `; ${event.entity_id}` : "";
217
+ const name = navigation.name === undefined
218
+ ? event.entity_id
219
+ : options.showsFullNames
220
+ ? navigation.name
221
+ : formatDescriptionPreview(navigation.name);
222
+ return `${event.entity_type} ${name} [${navigation.status}${identity}]`;
223
+ }
224
+ function summarizeValue(value) {
225
+ if (typeof value === "string") {
226
+ return value;
227
+ }
228
+ if (isRecord(value)) {
229
+ const name = value.key ?? value.name ?? value.title ?? value.id;
230
+ if (typeof name === "string") {
231
+ return name;
232
+ }
233
+ }
234
+ return JSON.stringify(value);
235
+ }
236
+ function isRecordedChangePair(event, value) {
237
+ return (["edit", "move", "comment_edit"].includes(event.action) &&
238
+ Array.isArray(value) &&
239
+ value.length === 2);
240
+ }
241
+ function formatRemovedTasks(entry) {
242
+ return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
243
+ }
244
+ function formatChangeSummary(entry, options = {}) {
245
+ const { event } = entry;
246
+ const changes = event.changes;
247
+ let summary = "-";
248
+ if (changes !== null) {
249
+ summary =
250
+ Object.entries(changes)
251
+ .map(([field, value]) => {
252
+ const isSnapshot = event.action === "create" || event.action === "delete";
253
+ if (isSnapshot && value === null) {
254
+ return null;
255
+ }
256
+ const repeatsIdentity = options.omitsIdentity &&
257
+ isSnapshot &&
258
+ (field === "key" || field === "name") &&
259
+ value === entry.navigation.name;
260
+ if (repeatsIdentity) {
261
+ return null;
262
+ }
263
+ if (!RECORDED_FIELDS.has(field)) {
264
+ return `${field}: ${JSON.stringify(value)}`;
265
+ }
266
+ if (field === "description") {
267
+ return event.action === "edit" ? "description changed" : "description recorded";
268
+ }
269
+ if (field === "title" && options.omitsIdentity && isSnapshot) {
270
+ return summarizeValue(value);
271
+ }
272
+ if (isRecordedChangePair(event, value)) {
273
+ return `${field}: ${summarizeValue(value[0])} → ${summarizeValue(value[1])}`;
274
+ }
275
+ if (Array.isArray(value)) {
276
+ if (field === "labels" && value.length === 0) {
277
+ return null;
278
+ }
279
+ return `${field}: ${value.length}`;
280
+ }
281
+ if (field === "labels" && isRecord(value)) {
282
+ const additions = Array.isArray(value.added) && value.added.length > 0
283
+ ? `added labels ${value.added.map(summarizeValue).join(", ")}`
284
+ : "";
285
+ const removals = Array.isArray(value.removed) && value.removed.length > 0
286
+ ? `removed labels ${value.removed.map(summarizeValue).join(", ")}`
287
+ : "";
288
+ return ([additions, removals].filter((part) => part.length > 0).join("; ") ||
289
+ `labels: ${JSON.stringify(value)}`);
290
+ }
291
+ if (field === "comment" && isRecord(value)) {
292
+ return `comment ${summarizeValue(value)}${typeof value.text === "string" ? `: ${value.text}` : ""}`;
293
+ }
294
+ return `${field}: ${summarizeValue(value)}`;
295
+ })
296
+ .filter((part) => part !== null)
297
+ .join("; ") || "-";
298
+ }
299
+ const removed = options.showsRemovedTasks === false ? "" : formatRemovedTasks(entry).join("; ");
300
+ return [formatDescriptionPreview(summary), removed].filter((part) => part.length > 0).join("; ");
301
+ }
302
+ function formatActivityContent(entry) {
303
+ const { event, navigation } = entry;
304
+ const name = navigation.name ?? event.entity_id;
305
+ const shortName = formatDescriptionPreview(name, { maxLength: ENTITY_PREVIEW_LENGTH });
306
+ const entityType = event.entity_type === "task" && navigation.name !== undefined ? "" : `${event.entity_type} `;
307
+ const isMutableCurrentName = navigation.status === "current" &&
308
+ (event.entity_type === "label" || event.entity_type === "column");
309
+ const marker = navigation.status === "deleted" ? " [deleted]" : isMutableCurrentName ? " [current name]" : "";
310
+ const action = ACTION_LABELS[event.action] ?? event.action;
311
+ const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
312
+ const lines = [
313
+ `${entityType}${shortName}${marker} · ${action}${summary === "-" ? "" : `: ${summary}`}`,
314
+ ];
315
+ if (shortName !== name) {
316
+ const nameLabel = navigation.name === undefined
317
+ ? "Entity ID"
318
+ : event.entity_type === "task" || event.entity_type === "project"
319
+ ? `Full ${event.entity_type} key`
320
+ : `Full ${event.entity_type} name`;
321
+ lines.push(`${nameLabel}: ${name}`);
322
+ }
323
+ if (navigation.distinguishesTaskId) {
324
+ lines.push(`Task ID: ${event.entity_id}`);
325
+ }
326
+ lines.push(...formatRemovedTasks(entry));
327
+ return lines.join("\n");
328
+ }
329
+ function formatRecordedValue(value) {
330
+ if (typeof value === "string") {
331
+ return value;
332
+ }
333
+ if (Array.isArray(value)) {
334
+ if (value.length === 0) {
335
+ return "[]";
336
+ }
337
+ return value
338
+ .map((item, index) => formatSection(`Item ${index + 1}`, formatRecordedValue(item)))
339
+ .join("\n\n");
340
+ }
341
+ if (isRecord(value)) {
342
+ return (Object.entries(value)
343
+ .map(([field, item]) => formatSection(field, RECORDED_FIELDS.has(field) ? formatRecordedValue(item) : JSON.stringify(item, null, 2)))
344
+ .join("\n\n") || "{}");
345
+ }
346
+ return JSON.stringify(value);
347
+ }
348
+ function formatRecordedChanges(event) {
349
+ if (event.changes === null) {
350
+ return "null";
351
+ }
352
+ const sections = [];
353
+ const unknownFields = {};
354
+ for (const [field, value] of Object.entries(event.changes)) {
355
+ if (!RECORDED_FIELDS.has(field)) {
356
+ unknownFields[field] = value;
357
+ continue;
358
+ }
359
+ const body = isRecordedChangePair(event, value)
360
+ ? `${formatSection("From", formatRecordedValue(value[0]))}\n\n${formatSection("To", formatRecordedValue(value[1]))}`
361
+ : formatRecordedValue(value);
362
+ sections.push(formatSection(field, body));
363
+ }
364
+ if (Object.keys(unknownFields).length > 0) {
365
+ sections.push(formatSection("Raw JSON", JSON.stringify(unknownFields, null, 2)));
366
+ }
367
+ return sections.join("\n\n") || "{}";
368
+ }
369
+ export function formatActivityList(entries, options = {}) {
370
+ const rows = entries.map((entry) => {
371
+ const metadata = [
372
+ { text: entry.displayId },
373
+ { text: formatLocalTime(entry.event.created_at), style: "dim" },
374
+ { text: `${entry.event.actor_name ?? UNKNOWN_ACTOR_NAME} (${entry.event.actor_kind})` },
375
+ ];
376
+ if (!options.showsDetails) {
377
+ return [...metadata, { text: formatActivityContent(entry) }];
378
+ }
379
+ return [
380
+ ...metadata,
381
+ { text: formatNavigation(entry, { showsFullNames: true }) },
382
+ { text: entry.event.action },
383
+ { text: formatChangeSummary(entry) },
384
+ ];
385
+ });
386
+ if (!options.showsDetails) {
387
+ return formatRows(rows, { indentsContinuationLines: true });
388
+ }
389
+ return entries
390
+ .map((entry, index) => [
391
+ formatRows([rows[index]]),
392
+ formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`),
393
+ ...(entry.navigation.name === undefined
394
+ ? []
395
+ : [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
396
+ formatSection("Actor", [
397
+ entry.event.actor_name ?? UNKNOWN_ACTOR_NAME,
398
+ ...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${entry.event[key] ?? "null"}`),
399
+ ].join("\n")),
400
+ formatSection("Changes", formatRecordedChanges(entry.event)),
401
+ ].join("\n\n"))
402
+ .join("\n\n");
403
+ }
@@ -0,0 +1,9 @@
1
+ import { styleText } from "node:util";
2
+ export type StyleFormat = Parameters<typeof styleText>[0];
3
+ /**
4
+ * Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
5
+ * FORCE_COLOR (https://force-color.org/) wins over NO_COLOR and the TTY check.
6
+ * Following https://no-color.org/, any NO_COLOR value turns color off.
7
+ */
8
+ export declare function isColorEnabled(): boolean;
9
+ export declare function styleOutputText(format: StyleFormat, text: string): string;
@@ -0,0 +1,21 @@
1
+ import { styleText } from "node:util";
2
+ /**
3
+ * Bun's styleText emits ANSI even when stdout is piped or NO_COLOR is set, so Zinn decides when to color.
4
+ * FORCE_COLOR (https://force-color.org/) wins over NO_COLOR and the TTY check.
5
+ * Following https://no-color.org/, any NO_COLOR value turns color off.
6
+ */
7
+ export function isColorEnabled() {
8
+ const forceColor = process.env.FORCE_COLOR ?? "";
9
+ const isForceColorSet = forceColor.length > 0;
10
+ if (isForceColorSet) {
11
+ return forceColor !== "0";
12
+ }
13
+ const isNoColorSet = (process.env.NO_COLOR ?? "").length > 0;
14
+ return process.stdout.isTTY === true && !isNoColorSet;
15
+ }
16
+ export function styleOutputText(format, text) {
17
+ if (!isColorEnabled()) {
18
+ return text;
19
+ }
20
+ return styleText(format, text, { validateStream: false });
21
+ }
@@ -0,0 +1,14 @@
1
+ import type { RowCell } from "./row-layout.js";
2
+ type ColumnRow = {
3
+ name: string;
4
+ project?: string;
5
+ taskCount?: number;
6
+ };
7
+ export declare function columnNameCell(columnName: string): RowCell;
8
+ /** The archived row is left out when there are no archived tasks. */
9
+ export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
10
+ showsProject?: boolean;
11
+ showsTaskCounts?: boolean;
12
+ archivedTaskCount?: number;
13
+ }): string;
14
+ export {};
@@ -0,0 +1,29 @@
1
+ import { formatRows } from "./row-layout.js";
2
+ /** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
3
+ const ARCHIVED_ROW_LABEL = "Archived";
4
+ export function columnNameCell(columnName) {
5
+ // TODO: Derive column colors from column roles once roles exist instead of relying on names.
6
+ if (columnName === "Backlog") {
7
+ return { text: columnName, style: "gray" };
8
+ }
9
+ if (columnName === "Done") {
10
+ return { text: columnName, style: "green" };
11
+ }
12
+ return { text: columnName };
13
+ }
14
+ /** The archived row is left out when there are no archived tasks. */
15
+ export function formatColumnList(presentedColumns, options = {}) {
16
+ const rows = presentedColumns.map((presentedColumn) => {
17
+ const projectCells = options.showsProject && presentedColumn.project != null
18
+ ? [{ text: presentedColumn.project }]
19
+ : [];
20
+ const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
21
+ ? [{ text: String(presentedColumn.taskCount) }]
22
+ : [];
23
+ return [...projectCells, columnNameCell(presentedColumn.name), ...taskCountCells];
24
+ });
25
+ if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
26
+ rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
27
+ }
28
+ return formatRows(rows);
29
+ }
@@ -0,0 +1,3 @@
1
+ export declare function formatDescriptionPreview(description: string | null, options?: {
2
+ maxLength?: number;
3
+ }): string;
@@ -0,0 +1,11 @@
1
+ export function formatDescriptionPreview(description, options = {}) {
2
+ const previewLength = options.maxLength ?? 80;
3
+ if (description == null) {
4
+ return "";
5
+ }
6
+ const normalizedDescription = description.replace(/\s+/g, " ").trim();
7
+ if (normalizedDescription.length <= previewLength) {
8
+ return normalizedDescription;
9
+ }
10
+ return `${normalizedDescription.slice(0, previewLength - 1).trimEnd()}…`;
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { StoreInfo } from "@zinn-dev/core";
2
+ import type { PresentedInfo } from "../result-schemas.js";
3
+ export declare function presentInfo(report: StoreInfo): PresentedInfo;
4
+ export declare function formatInfo(report: PresentedInfo): string;
@@ -0,0 +1,96 @@
1
+ import packageJson from "../../package.json" with { type: "json" };
2
+ export function presentInfo(report) {
3
+ const bunVersion = process.versions.bun;
4
+ return {
5
+ settingsFiles: report.settingsFiles,
6
+ storage: report.storage,
7
+ defaultProject: report.defaultProject,
8
+ database: report.database,
9
+ versions: {
10
+ cli: packageJson.version,
11
+ core: report.coreVersion,
12
+ runtime: {
13
+ name: bunVersion === undefined ? "Node" : "Bun",
14
+ version: bunVersion ?? process.versions.node,
15
+ },
16
+ },
17
+ };
18
+ }
19
+ function storeSource(storage) {
20
+ if (storage.settingsPath !== null) {
21
+ return storage.settingsPath;
22
+ }
23
+ return storage.source === "env" ? "ZINN_DIR" : "default";
24
+ }
25
+ function folderState(storage) {
26
+ if (storage.error !== null) {
27
+ return storage.error;
28
+ }
29
+ if (storage.exists === null) {
30
+ return "unavailable";
31
+ }
32
+ return storage.exists ? "found" : "missing";
33
+ }
34
+ function databaseState(database) {
35
+ if (database.error !== null) {
36
+ return database.error;
37
+ }
38
+ return `${database.state}; schema ${database.version ?? "unavailable"}, latest ${database.latestVersion}`;
39
+ }
40
+ export function formatInfo(report) {
41
+ const { storage, database, defaultProject, versions } = report;
42
+ const storeIsUnavailable = storage.directory === null;
43
+ //
44
+ /**
45
+ * A settings file's error text prints once, on its own line in the Settings list
46
+ * Other fields point to the file
47
+ */
48
+ const unavailableReason = (error) => {
49
+ const file = report.settingsFiles.find((candidate) => candidate.state === "error" && candidate.error === error);
50
+ return file === undefined ? error : `settings file ${file.path} cannot be used`;
51
+ };
52
+ const storeHeader = storeIsUnavailable
53
+ ? `unavailable${storage.error === null ? "" : ` (${unavailableReason(storage.error)})`}`
54
+ : `${storage.directory} (${storeSource(storage)})`;
55
+ const defaultProjectText = defaultProject.error === null
56
+ ? (defaultProject.key ?? "not configured")
57
+ : `unavailable (${unavailableReason(defaultProject.error)})`;
58
+ const defaultProjectSuffix = defaultProject.settingsPath === null ? "" : ` (${defaultProject.settingsPath})`;
59
+ const lines = [
60
+ `Store: ${storeHeader}`,
61
+ `Store folder: ${storeIsUnavailable ? "unavailable" : folderState(storage)}`,
62
+ `Database: ${database.path ?? "unavailable"}`,
63
+ `Database state: ${storeIsUnavailable ? "unavailable" : databaseState(database)}`,
64
+ `Default project: ${defaultProjectText}${defaultProjectSuffix}`,
65
+ "",
66
+ "Settings:",
67
+ ];
68
+ for (const file of report.settingsFiles) {
69
+ let state;
70
+ switch (file.state) {
71
+ case "found":
72
+ state = "found";
73
+ break;
74
+ case "missing":
75
+ state = "not configured";
76
+ break;
77
+ case "error":
78
+ state = file.error;
79
+ break;
80
+ case "not-read":
81
+ state = `not read (${file.reason} is set)`;
82
+ break;
83
+ }
84
+ lines.push(`${file.path}: ${state}`);
85
+ if (file.state === "found") {
86
+ if (file.settings.storage !== undefined) {
87
+ lines.push(` storage.directory: ${file.settings.storage.directory}`);
88
+ }
89
+ if (file.settings.defaultProject !== undefined) {
90
+ lines.push(` defaultProject: ${file.settings.defaultProject}`);
91
+ }
92
+ }
93
+ }
94
+ lines.push("", `CLI: ${versions.cli}`, `Core: ${versions.core}`, `Runtime: ${versions.runtime.name} ${versions.runtime.version}`);
95
+ return lines.join("\n");
96
+ }
@@ -0,0 +1,22 @@
1
+ import type { StyleFormat } from "./color.js";
2
+ export type RowCell = {
3
+ text: string;
4
+ style?: StyleFormat;
5
+ };
6
+ export declare function formatCell(cell: RowCell, width?: number): string;
7
+ /**
8
+ * Rows that join extra text onto their last cell, such as a task's labels, put one there too, which is why it is exported.
9
+ */
10
+ export declare function formatCellSeparator(): string;
11
+ /**
12
+ * Lines rows up by padding each cell's text to its column's **widest** text.
13
+ * Widths use `String.length`, so emoji and CJK misalign.
14
+ * A row's last cell holds free text such as a title and is left unpadded.
15
+ *
16
+ * With `indentsContinuationLines`, a last cell that spans several lines starts each later line
17
+ * where the cell starts, below the padded cells before it. Without it, those lines are left as they are.
18
+ * Only a last cell may span lines: the widths do not account for line breaks.
19
+ */
20
+ export declare function formatRows(rows: Array<Array<RowCell>>, options?: {
21
+ indentsContinuationLines?: boolean;
22
+ }): string;
@@ -0,0 +1,58 @@
1
+ import { styleOutputText } from "./color.js";
2
+ const CELL_SEPARATOR = " | ";
3
+ const LINE_BREAK_PATTERN = /\r?\n/;
4
+ export function formatCell(cell, width = cell.text.length) {
5
+ const paddedText = cell.text.padEnd(width);
6
+ if (cell.style == null) {
7
+ return paddedText;
8
+ }
9
+ return styleOutputText(cell.style, paddedText);
10
+ }
11
+ /**
12
+ * Rows that join extra text onto their last cell, such as a task's labels, put one there too, which is why it is exported.
13
+ */
14
+ export function formatCellSeparator() {
15
+ return styleOutputText("dim", CELL_SEPARATOR);
16
+ }
17
+ function indentContinuationLines(text, indentWidth) {
18
+ return text.split(LINE_BREAK_PATTERN).join(`\n${" ".repeat(indentWidth)}`);
19
+ }
20
+ /**
21
+ * Lines rows up by padding each cell's text to its column's **widest** text.
22
+ * Widths use `String.length`, so emoji and CJK misalign.
23
+ * A row's last cell holds free text such as a title and is left unpadded.
24
+ *
25
+ * With `indentsContinuationLines`, a last cell that spans several lines starts each later line
26
+ * where the cell starts, below the padded cells before it. Without it, those lines are left as they are.
27
+ * Only a last cell may span lines: the widths do not account for line breaks.
28
+ */
29
+ export function formatRows(rows, options = {}) {
30
+ const columnWidths = [];
31
+ for (const row of rows) {
32
+ row.forEach((cell, columnIndex) => {
33
+ columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, cell.text.length);
34
+ });
35
+ }
36
+ return rows
37
+ .map((row) => {
38
+ const lastCellIndex = row.length - 1;
39
+ const lastCellStartColumn = columnWidths
40
+ .slice(0, lastCellIndex)
41
+ .reduce((total, width) => total + width + CELL_SEPARATOR.length, 0);
42
+ return row
43
+ .map((cell, columnIndex) => {
44
+ if (columnIndex !== lastCellIndex) {
45
+ return formatCell(cell, columnWidths[columnIndex]);
46
+ }
47
+ if (!options.indentsContinuationLines) {
48
+ return formatCell(cell);
49
+ }
50
+ return formatCell({
51
+ ...cell,
52
+ text: indentContinuationLines(cell.text, lastCellStartColumn),
53
+ });
54
+ })
55
+ .join(formatCellSeparator());
56
+ })
57
+ .join("\n");
58
+ }