@zinn-dev/cli 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -689
- package/index.js +2 -2
- package/package.json +4 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/capabilities-schema.d.ts +25 -26
- package/src/capabilities-schema.js +17 -82
- package/src/capabilities.d.ts +11 -3
- package/src/capabilities.js +12 -4
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.js +1 -4
- package/src/errors.d.ts +31 -3
- package/src/errors.js +77 -20
- package/src/input.d.ts +154 -43
- package/src/input.js +86 -13
- package/src/lib.d.ts +43 -6
- package/src/lib.js +134 -38
- package/src/list-continuation.d.ts +11 -0
- package/src/list-continuation.js +18 -0
- package/src/list-limit.d.ts +11 -0
- package/src/list-limit.js +17 -0
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +124 -28
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +6 -0
- package/src/presentation/column-presentation.js +10 -0
- package/src/presentation/comment-presentation.d.ts +15 -0
- package/src/presentation/comment-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +4 -0
- package/src/presentation/description-presentation.js +28 -5
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +11 -0
- package/src/presentation/project-presentation.js +27 -0
- package/src/presentation/relation-presentation.d.ts +12 -0
- package/src/presentation/relation-presentation.js +87 -0
- package/src/presentation/row-layout.d.ts +1 -1
- package/src/presentation/row-layout.js +6 -5
- package/src/presentation/task-presentation.d.ts +3 -3
- package/src/presentation/task-presentation.js +29 -19
- package/src/presentation/text-width.d.ts +2 -0
- package/src/presentation/text-width.js +43 -0
- package/src/presentation/time.d.ts +3 -1
- package/src/presentation/time.js +5 -2
- package/src/project.d.ts +14 -5
- package/src/project.js +18 -6
- package/src/result-schemas.d.ts +279 -26
- package/src/result-schemas.js +72 -4
- package/src/results.d.ts +34 -17
- package/src/results.js +19 -0
- package/src/routes/activity-router.d.ts +79 -2
- package/src/routes/activity-router.js +209 -38
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/capabilities-router.js +9 -3
- package/src/routes/comment-router.d.ts +41 -18
- package/src/routes/comment-router.js +65 -48
- package/src/routes/label-router.d.ts +57 -7
- package/src/routes/label-router.js +84 -39
- package/src/routes/project-router.d.ts +74 -12
- package/src/routes/project-router.js +131 -66
- package/src/routes/relation-router.d.ts +13 -9
- package/src/routes/relation-router.js +116 -116
- package/src/routes/restore-router.js +3 -6
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +88 -32
- package/src/routes/routes.d.ts +420 -50
- package/src/routes/routes.js +4 -0
- package/src/routes/task-router.d.ts +189 -30
- package/src/routes/task-router.js +254 -158
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +13 -9
- package/src/text-edit.js +23 -18
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/timestamp-input.d.ts +3 -0
- package/src/timestamp-input.js +31 -0
- package/src/types.d.ts +32 -9
- package/src/types.js +9 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { activity, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, } from "@zinn-dev/core";
|
|
1
|
+
import { activity, 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",
|
|
@@ -86,20 +87,12 @@ export function abbreviateActivityIds(ids) {
|
|
|
86
87
|
}
|
|
87
88
|
return prefixes;
|
|
88
89
|
}
|
|
89
|
-
function getTaskNavigation(events, taskKey) {
|
|
90
|
-
if (
|
|
91
|
-
return activity.getTaskIdentities(
|
|
90
|
+
function getTaskNavigation(events, taskKey, taskId) {
|
|
91
|
+
if (taskId !== undefined) {
|
|
92
|
+
return activity.getTaskIdentities({ taskId });
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
}
|
|
94
|
+
if (taskKey !== undefined) {
|
|
95
|
+
return activity.getTaskIdentities({ taskKey, showDeleted: true });
|
|
103
96
|
}
|
|
104
97
|
const historicalKeys = new Set();
|
|
105
98
|
function addKey(key) {
|
|
@@ -123,9 +116,44 @@ function getTaskNavigation(events, taskKey) {
|
|
|
123
116
|
}
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
const identities = new Map();
|
|
120
|
+
const needsTaskIdentities = historicalKeys.size > 0 || events.some((event) => event.entity_type === "task");
|
|
121
|
+
if (needsTaskIdentities) {
|
|
122
|
+
for (const item of task.getAll({ archive: "all" })) {
|
|
123
|
+
identities.set(item.id, {
|
|
124
|
+
id: item.id,
|
|
125
|
+
key: item.key,
|
|
126
|
+
title: item.title,
|
|
127
|
+
status: item.archived_at == null ? "active" : "archived",
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function addSnapshot(id, key, title) {
|
|
132
|
+
const parsedKey = activityTaskKeySchema.safeParse(key);
|
|
133
|
+
const isMatchingSnapshot = typeof id === "string" &&
|
|
134
|
+
typeof key === "string" &&
|
|
135
|
+
typeof title === "string" &&
|
|
136
|
+
parsedKey.success &&
|
|
137
|
+
historicalKeys.has(parsedKey.data);
|
|
138
|
+
if (isMatchingSnapshot && !identities.has(id)) {
|
|
139
|
+
identities.set(id, { id, key, title, status: "deleted" });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (historicalKeys.size > 0) {
|
|
143
|
+
for (const event of activity.getAll().events) {
|
|
144
|
+
if (event.action !== "delete") {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (event.entity_type === "task") {
|
|
148
|
+
addSnapshot(event.entity_id, event.changes?.key, event.changes?.title);
|
|
149
|
+
}
|
|
150
|
+
else if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
|
|
151
|
+
for (const snapshot of event.changes.tasks) {
|
|
152
|
+
if (isRecord(snapshot)) {
|
|
153
|
+
addSnapshot(snapshot.id, snapshot.key, snapshot.title);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
129
157
|
}
|
|
130
158
|
}
|
|
131
159
|
return [...identities.values()];
|
|
@@ -137,7 +165,15 @@ export function presentActivities(events, options = {}) {
|
|
|
137
165
|
const prefixes = options.showsFullIds
|
|
138
166
|
? new Map()
|
|
139
167
|
: abbreviateActivityIds(activity.getIds());
|
|
140
|
-
const
|
|
168
|
+
const hasProjectSelector = options.projectKey !== undefined || options.projectId !== undefined;
|
|
169
|
+
const navigationEvents = hasProjectSelector
|
|
170
|
+
? activity.getAll({
|
|
171
|
+
projectKey: options.projectKey,
|
|
172
|
+
projectId: options.projectId,
|
|
173
|
+
showDeleted: options.showDeleted,
|
|
174
|
+
}).events
|
|
175
|
+
: events;
|
|
176
|
+
const tasks = getTaskNavigation(navigationEvents, options.taskKey, options.taskId);
|
|
141
177
|
const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
|
|
142
178
|
const taskIdsByKey = new Map();
|
|
143
179
|
for (const identity of tasks) {
|
|
@@ -148,6 +184,32 @@ export function presentActivities(events, options = {}) {
|
|
|
148
184
|
? new Map(label.getAll().map((item) => [item.id, item]))
|
|
149
185
|
: new Map();
|
|
150
186
|
const navigationByEntity = new Map();
|
|
187
|
+
const recordedNames = new Map();
|
|
188
|
+
if (hasProjectSelector) {
|
|
189
|
+
for (const event of navigationEvents) {
|
|
190
|
+
const isSnapshot = event.action === "create" || event.action === "delete";
|
|
191
|
+
if (!isSnapshot) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const name = event.changes?.key ?? event.changes?.name;
|
|
195
|
+
const entityKey = `${event.entity_type}:${event.entity_id}`;
|
|
196
|
+
if (typeof name === "string" && !recordedNames.has(entityKey)) {
|
|
197
|
+
recordedNames.set(entityKey, name);
|
|
198
|
+
}
|
|
199
|
+
if (event.entity_type === "project" && Array.isArray(event.changes?.columns)) {
|
|
200
|
+
for (const snapshot of event.changes.columns) {
|
|
201
|
+
if (isRecord(snapshot) &&
|
|
202
|
+
typeof snapshot.id === "string" &&
|
|
203
|
+
typeof snapshot.name === "string") {
|
|
204
|
+
const columnKey = `column:${snapshot.id}`;
|
|
205
|
+
if (!recordedNames.has(columnKey)) {
|
|
206
|
+
recordedNames.set(columnKey, snapshot.name);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
151
213
|
return events.map((event) => {
|
|
152
214
|
const entityKey = `${event.entity_type}:${event.entity_id}`;
|
|
153
215
|
let navigation = navigationByEntity.get(entityKey);
|
|
@@ -159,7 +221,8 @@ export function presentActivities(events, options = {}) {
|
|
|
159
221
|
navigation = {
|
|
160
222
|
name: identity.key,
|
|
161
223
|
status: identity.status === "active" ? "current" : identity.status,
|
|
162
|
-
distinguishesTaskId: taskIdsByKey.get(identity.key) > 1,
|
|
224
|
+
distinguishesTaskId: options.taskId !== undefined || taskIdsByKey.get(identity.key) > 1,
|
|
225
|
+
showsStatus: options.taskId !== undefined,
|
|
163
226
|
};
|
|
164
227
|
}
|
|
165
228
|
break;
|
|
@@ -193,7 +256,8 @@ export function presentActivities(events, options = {}) {
|
|
|
193
256
|
// Every existing entity was found above, so it means that a missing one has been *deleted*.
|
|
194
257
|
if (navigation === undefined) {
|
|
195
258
|
navigation = {
|
|
196
|
-
name:
|
|
259
|
+
name: recordedNames.get(entityKey) ??
|
|
260
|
+
(isSnapshot && typeof recordedName === "string" ? recordedName : undefined),
|
|
197
261
|
status: "deleted",
|
|
198
262
|
};
|
|
199
263
|
}
|
|
@@ -205,7 +269,7 @@ export function presentActivities(events, options = {}) {
|
|
|
205
269
|
event,
|
|
206
270
|
displayId: options.showsFullIds ? event.id : prefixes.get(event.id),
|
|
207
271
|
navigation,
|
|
208
|
-
removedTasks: options.taskKey === undefined
|
|
272
|
+
removedTasks: !hasProjectSelector && options.taskKey === undefined && options.taskId === undefined
|
|
209
273
|
? []
|
|
210
274
|
: tasks.filter((identity) => removedTaskIds.has(identity.id)),
|
|
211
275
|
};
|
|
@@ -238,6 +302,12 @@ function isRecordedChangePair(event, value) {
|
|
|
238
302
|
Array.isArray(value) &&
|
|
239
303
|
value.length === 2);
|
|
240
304
|
}
|
|
305
|
+
function formatDeadline(value) {
|
|
306
|
+
const parsed = timestampSchema.safeParse(value);
|
|
307
|
+
return parsed.success
|
|
308
|
+
? formatLocalTime(parsed.data, { includesSeconds: true })
|
|
309
|
+
: summarizeValue(value);
|
|
310
|
+
}
|
|
241
311
|
function formatRemovedTasks(entry) {
|
|
242
312
|
return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
|
|
243
313
|
}
|
|
@@ -269,6 +339,11 @@ function formatChangeSummary(entry, options = {}) {
|
|
|
269
339
|
if (field === "title" && options.omitsIdentity && isSnapshot) {
|
|
270
340
|
return summarizeValue(value);
|
|
271
341
|
}
|
|
342
|
+
if (field === "due_at") {
|
|
343
|
+
return isRecordedChangePair(event, value)
|
|
344
|
+
? `${field}: ${formatDeadline(value[0])} → ${formatDeadline(value[1])}`
|
|
345
|
+
: `${field}: ${formatDeadline(value)}`;
|
|
346
|
+
}
|
|
272
347
|
if (isRecordedChangePair(event, value)) {
|
|
273
348
|
return `${field}: ${summarizeValue(value[0])} → ${summarizeValue(value[1])}`;
|
|
274
349
|
}
|
|
@@ -306,7 +381,11 @@ function formatActivityContent(entry) {
|
|
|
306
381
|
const entityType = event.entity_type === "task" && navigation.name !== undefined ? "" : `${event.entity_type} `;
|
|
307
382
|
const isMutableCurrentName = navigation.status === "current" &&
|
|
308
383
|
(event.entity_type === "label" || event.entity_type === "column");
|
|
309
|
-
const marker = navigation.status === "deleted"
|
|
384
|
+
const marker = navigation.status === "deleted" || navigation.showsStatus
|
|
385
|
+
? ` [${navigation.status}]`
|
|
386
|
+
: isMutableCurrentName
|
|
387
|
+
? " [current name]"
|
|
388
|
+
: "";
|
|
310
389
|
const action = ACTION_LABELS[event.action] ?? event.action;
|
|
311
390
|
const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
|
|
312
391
|
const lines = [
|
|
@@ -356,9 +435,10 @@ function formatRecordedChanges(event) {
|
|
|
356
435
|
unknownFields[field] = value;
|
|
357
436
|
continue;
|
|
358
437
|
}
|
|
438
|
+
const formatValue = field === "due_at" ? formatDeadline : formatRecordedValue;
|
|
359
439
|
const body = isRecordedChangePair(event, value)
|
|
360
|
-
? `${formatSection("From",
|
|
361
|
-
:
|
|
440
|
+
? `${formatSection("From", formatValue(value[0]))}\n\n${formatSection("To", formatValue(value[1]))}`
|
|
441
|
+
: formatValue(value);
|
|
362
442
|
sections.push(formatSection(field, body));
|
|
363
443
|
}
|
|
364
444
|
if (Object.keys(unknownFields).length > 0) {
|
|
@@ -366,6 +446,25 @@ function formatRecordedChanges(event) {
|
|
|
366
446
|
}
|
|
367
447
|
return sections.join("\n\n") || "{}";
|
|
368
448
|
}
|
|
449
|
+
export function presentActor(actor) {
|
|
450
|
+
return {
|
|
451
|
+
actor_name: actor.name,
|
|
452
|
+
actor_email: actor.email,
|
|
453
|
+
actor_kind: actor.kind,
|
|
454
|
+
actor_source: actor.source ?? null,
|
|
455
|
+
actor_session_id: actor.sessionId ?? null,
|
|
456
|
+
actor_thread_id: actor.threadId ?? null,
|
|
457
|
+
actor_agent: actor.agent ?? null,
|
|
458
|
+
actor_model: actor.model ?? null,
|
|
459
|
+
actor_effort: actor.effort ?? null,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
export function formatActor(actor) {
|
|
463
|
+
return [
|
|
464
|
+
actor.actor_name ?? UNKNOWN_ACTOR_NAME,
|
|
465
|
+
...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${actor[key] ?? "null"}`),
|
|
466
|
+
].join("\n");
|
|
467
|
+
}
|
|
369
468
|
export function formatActivityList(entries, options = {}) {
|
|
370
469
|
const rows = entries.map((entry) => {
|
|
371
470
|
const metadata = [
|
|
@@ -393,10 +492,7 @@ export function formatActivityList(entries, options = {}) {
|
|
|
393
492
|
...(entry.navigation.name === undefined
|
|
394
493
|
? []
|
|
395
494
|
: [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")),
|
|
495
|
+
formatSection("Actor", formatActor(entry.event)),
|
|
400
496
|
formatSection("Changes", formatRecordedChanges(entry.event)),
|
|
401
497
|
].join("\n\n"))
|
|
402
498
|
.join("\n\n");
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { RowCell } from "./row-layout.js";
|
|
2
|
+
import type { PresentedColumn } from "../result-schemas.js";
|
|
2
3
|
type ColumnRow = {
|
|
3
4
|
name: string;
|
|
4
5
|
project?: string;
|
|
5
6
|
taskCount?: number;
|
|
6
7
|
};
|
|
8
|
+
export declare function presentColumn(columnMatch: {
|
|
9
|
+
id: string;
|
|
10
|
+
project_id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}): PresentedColumn;
|
|
7
13
|
export declare function columnNameCell(columnName: string): RowCell;
|
|
8
14
|
/** The archived row is left out when there are no archived tasks. */
|
|
9
15
|
export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import { project } from "@zinn-dev/core";
|
|
1
2
|
import { formatRows } from "./row-layout.js";
|
|
2
3
|
/** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
|
|
3
4
|
const ARCHIVED_ROW_LABEL = "Archived";
|
|
5
|
+
export function presentColumn(columnMatch) {
|
|
6
|
+
const columnProject = project.getById(columnMatch.project_id);
|
|
7
|
+
return {
|
|
8
|
+
id: columnMatch.id,
|
|
9
|
+
project: columnProject.key,
|
|
10
|
+
project_id: columnMatch.project_id,
|
|
11
|
+
name: columnMatch.name,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
4
14
|
export function columnNameCell(columnName) {
|
|
5
15
|
// TODO: Derive column colors from column roles once roles exist instead of relying on names.
|
|
6
16
|
if (columnName === "Backlog") {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CommentWithKey } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedComment } from "../result-schemas.js";
|
|
3
|
+
export declare function presentComment(commentMatch: CommentWithKey): PresentedComment;
|
|
4
|
+
export declare function presentComments(taskKey: string): {
|
|
5
|
+
id: string;
|
|
6
|
+
key: string;
|
|
7
|
+
task_id: string;
|
|
8
|
+
text: string;
|
|
9
|
+
created_at: number;
|
|
10
|
+
updated_at: number;
|
|
11
|
+
}[];
|
|
12
|
+
export declare function formatCommentList(comments: Array<PresentedComment>, { showsCreatedAt, showsTextPreview }?: {
|
|
13
|
+
showsCreatedAt?: boolean | undefined;
|
|
14
|
+
showsTextPreview?: boolean | undefined;
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { comment } from "@zinn-dev/core";
|
|
2
|
+
import { formatDescriptionPreview } from "./description-presentation.js";
|
|
3
|
+
import { formatRows } from "./row-layout.js";
|
|
4
|
+
import { formatLocalTime } from "./time.js";
|
|
5
|
+
export function presentComment(commentMatch) {
|
|
6
|
+
return {
|
|
7
|
+
id: commentMatch.id,
|
|
8
|
+
key: commentMatch.key,
|
|
9
|
+
task_id: commentMatch.task_id,
|
|
10
|
+
text: commentMatch.text,
|
|
11
|
+
created_at: commentMatch.created_at,
|
|
12
|
+
updated_at: commentMatch.updated_at,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function presentComments(taskKey) {
|
|
16
|
+
return comment.getAll(taskKey).map(presentComment);
|
|
17
|
+
}
|
|
18
|
+
function commentRow(commentMatch, options) {
|
|
19
|
+
const createdAtCells = options.showsCreatedAt
|
|
20
|
+
? [{ text: formatLocalTime(commentMatch.created_at), style: "dim" }]
|
|
21
|
+
: [];
|
|
22
|
+
const text = options.showsTextPreview
|
|
23
|
+
? formatDescriptionPreview(commentMatch.text, { firstLineOnly: true })
|
|
24
|
+
: commentMatch.text;
|
|
25
|
+
return [{ text: commentMatch.key }, ...createdAtCells, { text }];
|
|
26
|
+
}
|
|
27
|
+
export function formatCommentList(comments, { showsCreatedAt = true, showsTextPreview = false } = {}) {
|
|
28
|
+
return formatRows(comments.map((commentMatch) => commentRow(commentMatch, { showsCreatedAt, showsTextPreview })), { indentsContinuationLines: true });
|
|
29
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** Formats a visual preview within a terminal-cell budget, including the ellipsis. */
|
|
1
2
|
export declare function formatDescriptionPreview(description: string | null, options?: {
|
|
2
3
|
maxLength?: number;
|
|
4
|
+
firstLineOnly?: boolean;
|
|
3
5
|
}): string;
|
|
6
|
+
/** Keeps parser reasons within their UTF-16-unit budget. */
|
|
7
|
+
export declare function formatParserReasonPreview(reason: string, maxLength: number): string;
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { displayWidth, graphemes } from "./text-width.js";
|
|
2
|
+
const DEFAULT_PREVIEW_LENGTH = 80;
|
|
3
|
+
function formatPreview(description, options, measure) {
|
|
4
|
+
const previewLength = options.maxLength ?? DEFAULT_PREVIEW_LENGTH;
|
|
3
5
|
if (description == null) {
|
|
4
6
|
return "";
|
|
5
7
|
}
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const lineBreakIndex = options.firstLineOnly ? description.search(/\r?\n/) : -1;
|
|
9
|
+
const hasMoreLines = lineBreakIndex !== -1;
|
|
10
|
+
const previewText = hasMoreLines ? description.slice(0, lineBreakIndex) : description;
|
|
11
|
+
const normalizedDescription = previewText.replace(/\s+/g, " ").trim();
|
|
12
|
+
if (measure(normalizedDescription) <= previewLength && !hasMoreLines) {
|
|
8
13
|
return normalizedDescription;
|
|
9
14
|
}
|
|
10
|
-
|
|
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);
|
|
11
34
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Label } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedLabel } from "../result-schemas.js";
|
|
3
|
+
import type { RowCell } from "./row-layout.js";
|
|
4
|
+
export declare function presentLabel(labelMatch: Label): PresentedLabel;
|
|
5
|
+
export declare function labelNameCell(name: string, color: string): RowCell;
|
|
6
|
+
export declare function formatLabelList(presentedLabels: Array<PresentedLabel>, options?: {
|
|
7
|
+
showsDescriptionPreview?: boolean;
|
|
8
|
+
}): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { labelColorSchema } from "@zinn-dev/core";
|
|
2
|
+
import { isColorEnabled } from "./color.js";
|
|
3
|
+
import { formatDescriptionPreview } from "./description-presentation.js";
|
|
4
|
+
import { formatRows } from "./row-layout.js";
|
|
5
|
+
export function presentLabel(labelMatch) {
|
|
6
|
+
return {
|
|
7
|
+
id: labelMatch.id,
|
|
8
|
+
name: labelMatch.name,
|
|
9
|
+
color: labelMatch.color,
|
|
10
|
+
description: labelMatch.description,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function labelNameCell(name, color) {
|
|
14
|
+
const style = labelColorSchema.options.find((labelColor) => labelColor === color);
|
|
15
|
+
return { text: name, style };
|
|
16
|
+
}
|
|
17
|
+
export function formatLabelList(presentedLabels, options = {}) {
|
|
18
|
+
return formatRows(presentedLabels.map((presented) => {
|
|
19
|
+
const description = options.showsDescriptionPreview && presented.description != null
|
|
20
|
+
? formatDescriptionPreview(presented.description, { firstLineOnly: true })
|
|
21
|
+
: presented.description;
|
|
22
|
+
const descriptionCells = description == null ? [] : [{ text: description }];
|
|
23
|
+
if (isColorEnabled()) {
|
|
24
|
+
return [labelNameCell(presented.name, presented.color), ...descriptionCells];
|
|
25
|
+
}
|
|
26
|
+
return [{ text: presented.name }, { text: presented.color }, ...descriptionCells];
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PresentedProject, PresentedProjectListEntry } from "../result-schemas.js";
|
|
2
|
+
type ProjectRow = PresentedProject & {
|
|
3
|
+
taskCounts?: PresentedProjectListEntry["taskCounts"];
|
|
4
|
+
};
|
|
5
|
+
type ProjectRowOptions = {
|
|
6
|
+
showsDescriptionPreview?: boolean;
|
|
7
|
+
showsTaskCounts?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function presentProject(projectMatch: PresentedProject): PresentedProject;
|
|
10
|
+
export declare function formatProjectList(presentedProjects: Array<ProjectRow>, { showsDescriptionPreview, showsTaskCounts }?: ProjectRowOptions): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { formatDescriptionPreview } from "./description-presentation.js";
|
|
2
|
+
import { formatCellSeparator, formatRows } from "./row-layout.js";
|
|
3
|
+
export function presentProject(projectMatch) {
|
|
4
|
+
return {
|
|
5
|
+
id: projectMatch.id,
|
|
6
|
+
key: projectMatch.key,
|
|
7
|
+
name: projectMatch.name,
|
|
8
|
+
description: projectMatch.description,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function formatProjectList(presentedProjects, { showsDescriptionPreview = true, showsTaskCounts = false } = {}) {
|
|
12
|
+
return formatRows(presentedProjects.map((presented) => {
|
|
13
|
+
const descriptionPreview = showsDescriptionPreview
|
|
14
|
+
? formatDescriptionPreview(presented.description)
|
|
15
|
+
: "";
|
|
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
|
+
}
|
|
25
|
+
return [{ text: presented.key }, { text: `${presented.name}${description}` }];
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedRelation, PresentedRelationChange } from "../result-schemas.js";
|
|
3
|
+
import { relation } from "@zinn-dev/core";
|
|
4
|
+
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 formatRelationChange(change: Pick<PresentedRelationChange, "type" | "source" | "target">, options: {
|
|
8
|
+
action: "create" | "delete";
|
|
9
|
+
} | {
|
|
10
|
+
action: "replace";
|
|
11
|
+
replaced: Array<PresentedRelationChange>;
|
|
12
|
+
}): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { column, relation } from "@zinn-dev/core";
|
|
2
|
+
import { columnNameCell } from "./column-presentation.js";
|
|
3
|
+
import { formatCellSeparator, formatRows } from "./row-layout.js";
|
|
4
|
+
export function presentRelationChange(entry, source, target) {
|
|
5
|
+
return {
|
|
6
|
+
id: entry.id,
|
|
7
|
+
type: entry.relation_type,
|
|
8
|
+
source: source.key,
|
|
9
|
+
source_task_id: source.id,
|
|
10
|
+
target: target.key,
|
|
11
|
+
target_task_id: target.id,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function presentRelations(taskMatch) {
|
|
15
|
+
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
16
|
+
const isSource = entry.source_task_id === taskMatch.id;
|
|
17
|
+
const other = isSource ? entry.target : entry.source;
|
|
18
|
+
if (other == null) {
|
|
19
|
+
throw new Error("Connected task details were not included in the relation");
|
|
20
|
+
}
|
|
21
|
+
let direction = null;
|
|
22
|
+
if (entry.relation_type !== "related") {
|
|
23
|
+
direction = isSource ? "outgoing" : "incoming";
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
id: entry.id,
|
|
27
|
+
type: entry.relation_type,
|
|
28
|
+
direction,
|
|
29
|
+
task: {
|
|
30
|
+
id: other.id,
|
|
31
|
+
key: other.key,
|
|
32
|
+
project_id: other.project_id,
|
|
33
|
+
column: column.getById(other.column_id).name,
|
|
34
|
+
column_id: other.column_id,
|
|
35
|
+
title: other.title,
|
|
36
|
+
status: other.archived_at == null ? "Active" : "Archived",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
64
|
+
return [
|
|
65
|
+
{ text: label },
|
|
66
|
+
{ text: entry.task.key },
|
|
67
|
+
columnNameCell(entry.task.column),
|
|
68
|
+
{ text: `${entry.task.title}${archived}` },
|
|
69
|
+
];
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
export function formatRelationChange(change, options) {
|
|
73
|
+
if (options.action === "replace") {
|
|
74
|
+
const previous = options.replaced.map((entry) => formatRelationChange(entry, { action: "create" }));
|
|
75
|
+
return `Replace these relations:\n${previous.join("\n")}\nWith:\n${formatRelationChange(change, { action: "create" })}?`;
|
|
76
|
+
}
|
|
77
|
+
if (options.action === "delete") {
|
|
78
|
+
return `Deleted ${change.type} relation from ${change.source} to ${change.target}`;
|
|
79
|
+
}
|
|
80
|
+
const label = {
|
|
81
|
+
related: "related to",
|
|
82
|
+
dependency: "depends on",
|
|
83
|
+
duplicate: "is a duplicate of",
|
|
84
|
+
subtask: "is a subtask of",
|
|
85
|
+
}[change.type];
|
|
86
|
+
return `${change.source} ${label} ${change.target}`;
|
|
87
|
+
}
|
|
@@ -10,7 +10,7 @@ export declare function formatCell(cell: RowCell, width?: number): string;
|
|
|
10
10
|
export declare function formatCellSeparator(): string;
|
|
11
11
|
/**
|
|
12
12
|
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
13
|
-
* Widths
|
|
13
|
+
* Widths count terminal cells, so wide text and emoji align with ASCII.
|
|
14
14
|
* A row's last cell holds free text such as a title and is left unpadded.
|
|
15
15
|
*
|
|
16
16
|
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { styleOutputText } from "./color.js";
|
|
2
|
+
import { displayWidth } from "./text-width.js";
|
|
2
3
|
const CELL_SEPARATOR = " | ";
|
|
3
4
|
const LINE_BREAK_PATTERN = /\r?\n/;
|
|
4
|
-
export function formatCell(cell, width = cell.text
|
|
5
|
-
const paddedText = cell.text.
|
|
5
|
+
export function formatCell(cell, width = displayWidth(cell.text)) {
|
|
6
|
+
const paddedText = `${cell.text}${" ".repeat(Math.max(0, width - displayWidth(cell.text)))}`;
|
|
6
7
|
if (cell.style == null) {
|
|
7
8
|
return paddedText;
|
|
8
9
|
}
|
|
@@ -19,7 +20,7 @@ function indentContinuationLines(text, indentWidth) {
|
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
22
|
-
* Widths
|
|
23
|
+
* Widths count terminal cells, so wide text and emoji align with ASCII.
|
|
23
24
|
* A row's last cell holds free text such as a title and is left unpadded.
|
|
24
25
|
*
|
|
25
26
|
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
@@ -30,7 +31,7 @@ export function formatRows(rows, options = {}) {
|
|
|
30
31
|
const columnWidths = [];
|
|
31
32
|
for (const row of rows) {
|
|
32
33
|
row.forEach((cell, columnIndex) => {
|
|
33
|
-
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, cell.text
|
|
34
|
+
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, displayWidth(cell.text));
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
return rows
|
|
@@ -38,7 +39,7 @@ export function formatRows(rows, options = {}) {
|
|
|
38
39
|
const lastCellIndex = row.length - 1;
|
|
39
40
|
const lastCellStartColumn = columnWidths
|
|
40
41
|
.slice(0, lastCellIndex)
|
|
41
|
-
.reduce((total, width) => total + width + CELL_SEPARATOR
|
|
42
|
+
.reduce((total, width) => total + width + displayWidth(CELL_SEPARATOR), 0);
|
|
42
43
|
return row
|
|
43
44
|
.map((cell, columnIndex) => {
|
|
44
45
|
if (columnIndex !== lastCellIndex) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TaskWithKey } from "@zinn-dev/core";
|
|
2
|
-
import type { PresentedTask } from "../result-schemas.js";
|
|
2
|
+
import type { PresentedTask, PresentedTaskDetail } from "../result-schemas.js";
|
|
3
3
|
export declare function presentTask(taskMatch: TaskWithKey): PresentedTask;
|
|
4
|
-
export declare function formatTaskRow(presented: PresentedTask): string;
|
|
5
4
|
export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
|
|
6
5
|
showsStatus?: boolean;
|
|
7
6
|
showsFullPriority?: boolean;
|
|
7
|
+
prefix?: string;
|
|
8
8
|
}): string;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function formatTaskTimestamps(task: Pick<PresentedTaskDetail, "created_at" | "updated_at">): string;
|