@zinn-dev/cli 0.41.0 → 0.42.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 +3 -2
- package/skills/zinn/SKILL.md +1 -1
- package/src/capabilities-schema.d.ts +22 -23
- 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.js +2 -0
- package/src/input.d.ts +154 -43
- package/src/input.js +86 -13
- package/src/lib.d.ts +30 -2
- package/src/lib.js +74 -13
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +108 -25
- 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 +17 -0
- package/src/presentation/description-presentation.js +26 -4
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +7 -0
- package/src/presentation/project-presentation.js +19 -0
- package/src/presentation/relation-presentation.d.ts +7 -0
- package/src/presentation/relation-presentation.js +73 -0
- package/src/presentation/task-presentation.d.ts +3 -3
- package/src/presentation/task-presentation.js +22 -18
- package/src/project.d.ts +14 -5
- package/src/project.js +18 -6
- package/src/result-schemas.d.ts +230 -23
- package/src/result-schemas.js +62 -3
- package/src/results.d.ts +34 -17
- package/src/results.js +19 -0
- package/src/routes/activity-router.d.ts +34 -1
- package/src/routes/activity-router.js +104 -31
- 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 +34 -12
- package/src/routes/project-router.js +59 -55
- package/src/routes/relation-router.d.ts +6 -6
- package/src/routes/relation-router.js +52 -69
- package/src/routes/restore-router.js +1 -1
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +38 -9
- package/src/routes/routes.d.ts +253 -45
- package/src/routes/routes.js +4 -0
- package/src/routes/task-router.d.ts +107 -26
- package/src/routes/task-router.js +151 -143
- 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/types.d.ts +32 -9
- package/src/types.js +9 -1
|
@@ -86,20 +86,12 @@ export function abbreviateActivityIds(ids) {
|
|
|
86
86
|
}
|
|
87
87
|
return prefixes;
|
|
88
88
|
}
|
|
89
|
-
function getTaskNavigation(events, taskKey) {
|
|
90
|
-
if (
|
|
91
|
-
return activity.getTaskIdentities(
|
|
89
|
+
function getTaskNavigation(events, taskKey, taskId) {
|
|
90
|
+
if (taskId !== undefined) {
|
|
91
|
+
return activity.getTaskIdentities({ taskId });
|
|
92
92
|
}
|
|
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
|
-
}
|
|
93
|
+
if (taskKey !== undefined) {
|
|
94
|
+
return activity.getTaskIdentities({ taskKey, showDeleted: true });
|
|
103
95
|
}
|
|
104
96
|
const historicalKeys = new Set();
|
|
105
97
|
function addKey(key) {
|
|
@@ -123,9 +115,44 @@ function getTaskNavigation(events, taskKey) {
|
|
|
123
115
|
}
|
|
124
116
|
}
|
|
125
117
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function addSnapshot(id, key, title) {
|
|
131
|
+
const parsedKey = activityTaskKeySchema.safeParse(key);
|
|
132
|
+
const isMatchingSnapshot = typeof id === "string" &&
|
|
133
|
+
typeof key === "string" &&
|
|
134
|
+
typeof title === "string" &&
|
|
135
|
+
parsedKey.success &&
|
|
136
|
+
historicalKeys.has(parsedKey.data);
|
|
137
|
+
if (isMatchingSnapshot && !identities.has(id)) {
|
|
138
|
+
identities.set(id, { id, key, title, status: "deleted" });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
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);
|
|
148
|
+
}
|
|
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
|
+
}
|
|
155
|
+
}
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
158
|
return [...identities.values()];
|
|
@@ -137,7 +164,15 @@ export function presentActivities(events, options = {}) {
|
|
|
137
164
|
const prefixes = options.showsFullIds
|
|
138
165
|
? new Map()
|
|
139
166
|
: abbreviateActivityIds(activity.getIds());
|
|
140
|
-
const
|
|
167
|
+
const hasProjectSelector = options.projectKey !== undefined || options.projectId !== undefined;
|
|
168
|
+
const navigationEvents = hasProjectSelector
|
|
169
|
+
? activity.getAll({
|
|
170
|
+
projectKey: options.projectKey,
|
|
171
|
+
projectId: options.projectId,
|
|
172
|
+
showDeleted: options.showDeleted,
|
|
173
|
+
})
|
|
174
|
+
: events;
|
|
175
|
+
const tasks = getTaskNavigation(navigationEvents, options.taskKey, options.taskId);
|
|
141
176
|
const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
|
|
142
177
|
const taskIdsByKey = new Map();
|
|
143
178
|
for (const identity of tasks) {
|
|
@@ -148,6 +183,32 @@ export function presentActivities(events, options = {}) {
|
|
|
148
183
|
? new Map(label.getAll().map((item) => [item.id, item]))
|
|
149
184
|
: new Map();
|
|
150
185
|
const navigationByEntity = new Map();
|
|
186
|
+
const recordedNames = new Map();
|
|
187
|
+
if (hasProjectSelector) {
|
|
188
|
+
for (const event of navigationEvents) {
|
|
189
|
+
const isSnapshot = event.action === "create" || event.action === "delete";
|
|
190
|
+
if (!isSnapshot) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const name = event.changes?.key ?? event.changes?.name;
|
|
194
|
+
const entityKey = `${event.entity_type}:${event.entity_id}`;
|
|
195
|
+
if (typeof name === "string" && !recordedNames.has(entityKey)) {
|
|
196
|
+
recordedNames.set(entityKey, name);
|
|
197
|
+
}
|
|
198
|
+
if (event.entity_type === "project" && Array.isArray(event.changes?.columns)) {
|
|
199
|
+
for (const snapshot of event.changes.columns) {
|
|
200
|
+
if (isRecord(snapshot) &&
|
|
201
|
+
typeof snapshot.id === "string" &&
|
|
202
|
+
typeof snapshot.name === "string") {
|
|
203
|
+
const columnKey = `column:${snapshot.id}`;
|
|
204
|
+
if (!recordedNames.has(columnKey)) {
|
|
205
|
+
recordedNames.set(columnKey, snapshot.name);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
151
212
|
return events.map((event) => {
|
|
152
213
|
const entityKey = `${event.entity_type}:${event.entity_id}`;
|
|
153
214
|
let navigation = navigationByEntity.get(entityKey);
|
|
@@ -159,7 +220,8 @@ export function presentActivities(events, options = {}) {
|
|
|
159
220
|
navigation = {
|
|
160
221
|
name: identity.key,
|
|
161
222
|
status: identity.status === "active" ? "current" : identity.status,
|
|
162
|
-
distinguishesTaskId: taskIdsByKey.get(identity.key) > 1,
|
|
223
|
+
distinguishesTaskId: options.taskId !== undefined || taskIdsByKey.get(identity.key) > 1,
|
|
224
|
+
showsStatus: options.taskId !== undefined,
|
|
163
225
|
};
|
|
164
226
|
}
|
|
165
227
|
break;
|
|
@@ -193,7 +255,8 @@ export function presentActivities(events, options = {}) {
|
|
|
193
255
|
// Every existing entity was found above, so it means that a missing one has been *deleted*.
|
|
194
256
|
if (navigation === undefined) {
|
|
195
257
|
navigation = {
|
|
196
|
-
name:
|
|
258
|
+
name: recordedNames.get(entityKey) ??
|
|
259
|
+
(isSnapshot && typeof recordedName === "string" ? recordedName : undefined),
|
|
197
260
|
status: "deleted",
|
|
198
261
|
};
|
|
199
262
|
}
|
|
@@ -205,7 +268,7 @@ export function presentActivities(events, options = {}) {
|
|
|
205
268
|
event,
|
|
206
269
|
displayId: options.showsFullIds ? event.id : prefixes.get(event.id),
|
|
207
270
|
navigation,
|
|
208
|
-
removedTasks: options.taskKey === undefined
|
|
271
|
+
removedTasks: !hasProjectSelector && options.taskKey === undefined && options.taskId === undefined
|
|
209
272
|
? []
|
|
210
273
|
: tasks.filter((identity) => removedTaskIds.has(identity.id)),
|
|
211
274
|
};
|
|
@@ -306,7 +369,11 @@ function formatActivityContent(entry) {
|
|
|
306
369
|
const entityType = event.entity_type === "task" && navigation.name !== undefined ? "" : `${event.entity_type} `;
|
|
307
370
|
const isMutableCurrentName = navigation.status === "current" &&
|
|
308
371
|
(event.entity_type === "label" || event.entity_type === "column");
|
|
309
|
-
const marker = navigation.status === "deleted"
|
|
372
|
+
const marker = navigation.status === "deleted" || navigation.showsStatus
|
|
373
|
+
? ` [${navigation.status}]`
|
|
374
|
+
: isMutableCurrentName
|
|
375
|
+
? " [current name]"
|
|
376
|
+
: "";
|
|
310
377
|
const action = ACTION_LABELS[event.action] ?? event.action;
|
|
311
378
|
const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
|
|
312
379
|
const lines = [
|
|
@@ -366,6 +433,25 @@ function formatRecordedChanges(event) {
|
|
|
366
433
|
}
|
|
367
434
|
return sections.join("\n\n") || "{}";
|
|
368
435
|
}
|
|
436
|
+
export function presentActor(actor) {
|
|
437
|
+
return {
|
|
438
|
+
actor_name: actor.name,
|
|
439
|
+
actor_email: actor.email,
|
|
440
|
+
actor_kind: actor.kind,
|
|
441
|
+
actor_source: actor.source ?? null,
|
|
442
|
+
actor_session_id: actor.sessionId ?? null,
|
|
443
|
+
actor_thread_id: actor.threadId ?? null,
|
|
444
|
+
actor_agent: actor.agent ?? null,
|
|
445
|
+
actor_model: actor.model ?? null,
|
|
446
|
+
actor_effort: actor.effort ?? null,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
export function formatActor(actor) {
|
|
450
|
+
return [
|
|
451
|
+
actor.actor_name ?? UNKNOWN_ACTOR_NAME,
|
|
452
|
+
...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${actor[key] ?? "null"}`),
|
|
453
|
+
].join("\n");
|
|
454
|
+
}
|
|
369
455
|
export function formatActivityList(entries, options = {}) {
|
|
370
456
|
const rows = entries.map((entry) => {
|
|
371
457
|
const metadata = [
|
|
@@ -393,10 +479,7 @@ export function formatActivityList(entries, options = {}) {
|
|
|
393
479
|
...(entry.navigation.name === undefined
|
|
394
480
|
? []
|
|
395
481
|
: [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")),
|
|
482
|
+
formatSection("Actor", formatActor(entry.event)),
|
|
400
483
|
formatSection("Changes", formatRecordedChanges(entry.event)),
|
|
401
484
|
].join("\n\n"))
|
|
402
485
|
.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,20 @@
|
|
|
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
17
|
export declare function formatDescriptionPreview(description: string | null, options?: {
|
|
2
18
|
maxLength?: number;
|
|
19
|
+
firstLineOnly?: boolean;
|
|
3
20
|
}): string;
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
+
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
|
+
*/
|
|
1
18
|
export function formatDescriptionPreview(description, options = {}) {
|
|
2
|
-
const previewLength = options.maxLength ??
|
|
19
|
+
const previewLength = options.maxLength ?? DEFAULT_PREVIEW_LENGTH;
|
|
3
20
|
if (description == null) {
|
|
4
21
|
return "";
|
|
5
22
|
}
|
|
6
|
-
const
|
|
7
|
-
|
|
23
|
+
const lineBreakIndex = options.firstLineOnly ? description.search(/\r?\n/) : -1;
|
|
24
|
+
const hasMoreLines = lineBreakIndex !== -1;
|
|
25
|
+
const previewText = hasMoreLines ? description.slice(0, lineBreakIndex) : description;
|
|
26
|
+
const normalizedDescription = previewText.replace(/\s+/g, " ").trim();
|
|
27
|
+
if (normalizedDescription.length <= previewLength && !hasMoreLines) {
|
|
8
28
|
return normalizedDescription;
|
|
9
29
|
}
|
|
10
|
-
|
|
30
|
+
const truncatedDescription = normalizedDescription.slice(0, previewLength - 1);
|
|
31
|
+
const completePrefix = truncatedDescription.replace(/\p{Surrogate}$/u, "");
|
|
32
|
+
return `${completePrefix.trimEnd()}…`;
|
|
11
33
|
}
|
|
@@ -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,7 @@
|
|
|
1
|
+
import type { PresentedProject } from "../result-schemas.js";
|
|
2
|
+
type ProjectRowOptions = {
|
|
3
|
+
showsDescriptionPreview?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function presentProject(projectMatch: PresentedProject): PresentedProject;
|
|
6
|
+
export declare function formatProjectList(presentedProjects: Array<PresentedProject>, { showsDescriptionPreview }?: ProjectRowOptions): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 } = {}) {
|
|
12
|
+
return formatRows(presentedProjects.map((presented) => {
|
|
13
|
+
const descriptionPreview = showsDescriptionPreview
|
|
14
|
+
? formatDescriptionPreview(presented.description)
|
|
15
|
+
: "";
|
|
16
|
+
const description = descriptionPreview.length > 0 ? `${formatCellSeparator()}${descriptionPreview}` : "";
|
|
17
|
+
return [{ text: presented.key }, { text: `${presented.name}${description}` }];
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TaskWithKey } from "@zinn-dev/core";
|
|
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: {
|
|
6
|
+
action: "create" | "delete";
|
|
7
|
+
}): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 presentRelations(taskMatch) {
|
|
5
|
+
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
6
|
+
const isSource = entry.source_task_id === taskMatch.id;
|
|
7
|
+
const other = isSource ? entry.target : entry.source;
|
|
8
|
+
if (other == null) {
|
|
9
|
+
throw new Error("Connected task details were not included in the relation");
|
|
10
|
+
}
|
|
11
|
+
let direction = null;
|
|
12
|
+
if (entry.relation_type !== "related") {
|
|
13
|
+
direction = isSource ? "outgoing" : "incoming";
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
id: entry.id,
|
|
17
|
+
type: entry.relation_type,
|
|
18
|
+
direction,
|
|
19
|
+
task: {
|
|
20
|
+
id: other.id,
|
|
21
|
+
key: other.key,
|
|
22
|
+
project_id: other.project_id,
|
|
23
|
+
column: column.getById(other.column_id).name,
|
|
24
|
+
column_id: other.column_id,
|
|
25
|
+
title: other.title,
|
|
26
|
+
status: other.archived_at == null ? "Active" : "Archived",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function formatRelationList(relations) {
|
|
32
|
+
return formatRows(relations.map((entry) => {
|
|
33
|
+
const isOutgoing = entry.direction === "outgoing";
|
|
34
|
+
let label = entry.type;
|
|
35
|
+
switch (entry.type) {
|
|
36
|
+
case "related": {
|
|
37
|
+
label = "Related to";
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "dependency": {
|
|
41
|
+
label = isOutgoing ? "Depends on" : "Depended on by";
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "subtask": {
|
|
45
|
+
label = isOutgoing ? "Parent" : "Subtask";
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "duplicate": {
|
|
49
|
+
label = isOutgoing ? "Duplicate of" : "Duplicated by";
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
54
|
+
return [
|
|
55
|
+
{ text: label },
|
|
56
|
+
{ text: entry.task.key },
|
|
57
|
+
columnNameCell(entry.task.column),
|
|
58
|
+
{ text: `${entry.task.title}${archived}` },
|
|
59
|
+
];
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
export function formatRelationChange(change, options) {
|
|
63
|
+
if (options.action === "delete") {
|
|
64
|
+
return `Deleted ${change.type} relation from ${change.source} to ${change.target}`;
|
|
65
|
+
}
|
|
66
|
+
const label = {
|
|
67
|
+
related: "related to",
|
|
68
|
+
dependency: "depends on",
|
|
69
|
+
duplicate: "is a duplicate of",
|
|
70
|
+
subtask: "is a subtask of",
|
|
71
|
+
}[change.type];
|
|
72
|
+
return `${change.source} ${label} ${change.target}`;
|
|
73
|
+
}
|
|
@@ -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;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { column, label, task } from "@zinn-dev/core";
|
|
2
|
-
import { styleOutputText } from "./color.js";
|
|
3
2
|
import { columnNameCell } from "./column-presentation.js";
|
|
4
|
-
import {
|
|
3
|
+
import { labelNameCell } from "./label-presentation.js";
|
|
4
|
+
import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
|
|
5
|
+
import { formatLocalTime } from "./time.js";
|
|
5
6
|
const EMPTY_CELL_MARKER = "-";
|
|
6
7
|
const LABEL_NAME_SEPARATOR = ", ";
|
|
7
8
|
function taskPriorityCell(priority, showsFullPriority) {
|
|
@@ -12,31 +13,28 @@ function taskPriorityCell(priority, showsFullPriority) {
|
|
|
12
13
|
return { text: showsFullPriority ? `${priorityInitial}${priority.slice(1)}` : priorityInitial };
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
|
-
* `PresentedTask` carries label names
|
|
16
|
+
* `PresentedTask` carries label names and IDs, without colors.
|
|
16
17
|
* Text output looks the colors up from the label definitions instead.
|
|
17
18
|
*/
|
|
18
19
|
function getLabelColorsByName() {
|
|
19
20
|
return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
|
|
20
21
|
}
|
|
21
|
-
function formatLabelNames(labelNames, labelColorsByName) {
|
|
22
|
-
return labelNames
|
|
23
|
-
.map((labelName) => styleOutputText(labelColorsByName.get(labelName), labelName))
|
|
24
|
-
.join(LABEL_NAME_SEPARATOR);
|
|
25
|
-
}
|
|
26
22
|
export function presentTask(taskMatch) {
|
|
23
|
+
const labels = task.label.getAll(taskMatch.key);
|
|
27
24
|
return {
|
|
25
|
+
id: taskMatch.id,
|
|
28
26
|
key: taskMatch.key,
|
|
27
|
+
project_id: taskMatch.project_id,
|
|
29
28
|
status: taskMatch.archived_at == null ? "Active" : "Archived",
|
|
30
29
|
column: column.getById(taskMatch.column_id).name,
|
|
30
|
+
column_id: taskMatch.column_id,
|
|
31
31
|
title: taskMatch.title,
|
|
32
32
|
description: taskMatch.description,
|
|
33
33
|
priority: taskMatch.priority,
|
|
34
|
-
labels:
|
|
34
|
+
labels: labels.map((label) => label.name),
|
|
35
|
+
label_ids: labels.map((label) => label.id),
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
export function formatTaskRow(presented) {
|
|
38
|
-
return formatTaskList([presented]);
|
|
39
|
-
}
|
|
40
38
|
export function formatTaskList(presentedTasks, options = {}) {
|
|
41
39
|
const labelColorsByName = getLabelColorsByName();
|
|
42
40
|
return formatRows(presentedTasks.map((presentedTask) => {
|
|
@@ -45,11 +43,12 @@ export function formatTaskList(presentedTasks, options = {}) {
|
|
|
45
43
|
: [];
|
|
46
44
|
const hasLabels = presentedTask.labels.length > 0;
|
|
47
45
|
// The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const labelNames = presentedTask.labels
|
|
47
|
+
.map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
|
|
48
|
+
.join(LABEL_NAME_SEPARATOR);
|
|
49
|
+
const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
|
|
51
50
|
return [
|
|
52
|
-
{ text: presentedTask.key },
|
|
51
|
+
{ text: `${options.prefix ?? ""}${presentedTask.key}` },
|
|
53
52
|
...statusCells,
|
|
54
53
|
columnNameCell(presentedTask.column),
|
|
55
54
|
taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
|
|
@@ -57,6 +56,11 @@ export function formatTaskList(presentedTasks, options = {}) {
|
|
|
57
56
|
];
|
|
58
57
|
}));
|
|
59
58
|
}
|
|
60
|
-
export function
|
|
61
|
-
return
|
|
59
|
+
export function formatTaskTimestamps(task) {
|
|
60
|
+
return formatRows([
|
|
61
|
+
[
|
|
62
|
+
{ text: `Task created at: ${formatLocalTime(task.created_at)}`, style: "dim" },
|
|
63
|
+
{ text: `Task updated at: ${formatLocalTime(task.updated_at)}`, style: "dim" },
|
|
64
|
+
],
|
|
65
|
+
]);
|
|
62
66
|
}
|
package/src/project.d.ts
CHANGED
|
@@ -2,11 +2,20 @@ export declare const projectScopeConstraint: {
|
|
|
2
2
|
readonly kind: "exclusive";
|
|
3
3
|
readonly members: readonly ["positional:project-key", "option:all-projects"];
|
|
4
4
|
};
|
|
5
|
-
export declare const requiredProjectDescription = "
|
|
6
|
-
export declare const projectScopeDescription = "An omitted project key
|
|
7
|
-
|
|
8
|
-
export declare function resolveProjectKey(typedKey: string | undefined, { required, allProjects, useDefault, }?: {
|
|
5
|
+
export declare const requiredProjectDescription = "Omit the project key to use defaultProject from settings; otherwise a project key is required.";
|
|
6
|
+
export declare const projectScopeDescription = "An omitted project key uses defaultProject, or all projects if unset. --all-projects overrides the default and cannot be combined with a project key.";
|
|
7
|
+
type ProjectKeyOptions = {
|
|
9
8
|
required?: boolean;
|
|
10
9
|
allProjects?: boolean;
|
|
11
10
|
useDefault?: boolean;
|
|
12
|
-
}
|
|
11
|
+
};
|
|
12
|
+
type ProjectKeyChoice = {
|
|
13
|
+
key: string;
|
|
14
|
+
settingsPath?: string;
|
|
15
|
+
};
|
|
16
|
+
/** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
|
|
17
|
+
export declare function resolveProjectKey(typedKey: string | undefined, options?: ProjectKeyOptions): string | undefined;
|
|
18
|
+
export declare function chooseProjectKey(typedKey: string | undefined, { required, allProjects, useDefault }?: ProjectKeyOptions): ProjectKeyChoice | undefined;
|
|
19
|
+
/** Fails when the key came from defaultProject and that project does not exist. */
|
|
20
|
+
export declare function checkDefaultProject({ key, settingsPath }: ProjectKeyChoice): void;
|
|
21
|
+
export {};
|