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