@zinn-dev/cli 0.43.0 → 0.44.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 +1 -1
- package/index.js +3 -3
- package/package.json +7 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/actor.d.ts +8 -0
- package/src/actor.js +5 -1
- package/src/capabilities-schema.d.ts +1 -1
- package/src/column-hint.js +3 -4
- package/src/errors.d.ts +12 -3
- package/src/errors.js +19 -2
- package/src/failure-log.d.ts +6 -0
- package/src/failure-log.js +167 -0
- package/src/input.d.ts +11 -0
- package/src/input.js +25 -1
- package/src/lib.d.ts +7 -5
- package/src/lib.js +52 -33
- package/src/list-limit.d.ts +2 -2
- package/src/list-limit.js +2 -2
- package/src/overview.d.ts +10 -0
- package/src/overview.js +41 -0
- package/src/presentation/activity-presentation.d.ts +2 -0
- package/src/presentation/activity-presentation.js +96 -35
- package/src/presentation/column-presentation.d.ts +17 -2
- package/src/presentation/column-presentation.js +45 -6
- package/src/presentation/info-presentation.js +36 -6
- package/src/presentation/relation-presentation.d.ts +6 -2
- package/src/presentation/relation-presentation.js +36 -26
- package/src/presentation/task-blame-presentation.d.ts +11 -0
- package/src/presentation/task-blame-presentation.js +56 -0
- package/src/presentation/task-presentation.d.ts +6 -1
- package/src/presentation/task-presentation.js +21 -9
- package/src/result-schemas.d.ts +480 -15
- package/src/result-schemas.js +54 -1
- package/src/routes/activity-router.d.ts +9 -1
- package/src/routes/activity-router.js +15 -2
- package/src/routes/info-router.js +3 -2
- package/src/routes/migrate-router.js +2 -2
- package/src/routes/project-router.d.ts +1 -1
- package/src/routes/project-router.js +3 -12
- package/src/routes/restore-router.js +9 -3
- package/src/routes/router.js +24 -11
- package/src/routes/routes.d.ts +51 -8
- package/src/routes/task-router.d.ts +41 -6
- package/src/routes/task-router.js +81 -24
- package/src/routes/whoami-router.js +1 -1
- package/src/run-facts.d.ts +14 -0
- package/src/run-facts.js +14 -0
- package/src/store-folder.d.ts +5 -0
- package/src/store-folder.js +16 -0
- package/src/telemetry.d.ts +31 -0
- package/src/telemetry.js +329 -0
- package/src/text-input.js +1 -5
- package/src/types.d.ts +1 -1
package/src/lib.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
1
2
|
import { parseArgs } from "node:util";
|
|
2
3
|
import { createInterface } from "node:readline/promises";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { assertWritable, InputValidationError } from "@zinn-dev/core";
|
|
5
6
|
import { CliError, classifyFailure, recoveryHint } from "./errors.js";
|
|
6
|
-
import {
|
|
7
|
+
import { writeFailureLog } from "./failure-log.js";
|
|
8
|
+
import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
|
|
7
9
|
import { formatParserReasonPreview } from "./presentation/description-presentation.js";
|
|
10
|
+
import { writeRunRecord } from "./telemetry.js";
|
|
8
11
|
let outputMode = "text";
|
|
9
12
|
let legacyReadAllowed = false;
|
|
10
13
|
const diagnostics = [];
|
|
11
|
-
|
|
14
|
+
/** Every notice of this run in order, kept for the failure log */
|
|
15
|
+
const runNotices = [];
|
|
16
|
+
/** Failures that write a log, because the error alone does not say what went wrong */
|
|
17
|
+
const LOGGED_ERROR_CODES = ["storage", "internal"];
|
|
12
18
|
const MAX_PARSER_MESSAGE_LENGTH = 1024;
|
|
13
19
|
/** Keeps recovery guidance outside the shortened reason and never clips a repair command. */
|
|
14
20
|
export function boundParserMessage(message, options = {}) {
|
|
@@ -27,12 +33,12 @@ export function getOutputMode() {
|
|
|
27
33
|
}
|
|
28
34
|
/** Selects output before routing, without treating words after `--` as flags. */
|
|
29
35
|
export function prepareOutput(args) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
setOutputMode(options.some(isJsonFlag) ? "json" : "text");
|
|
36
|
+
const { optionWords } = splitAtOptionSeparator(args);
|
|
37
|
+
setOutputMode(optionWords.some(isJsonFlag) ? "json" : "text");
|
|
33
38
|
}
|
|
34
39
|
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
35
40
|
export function diagnostic(message) {
|
|
41
|
+
runNotices.push(message);
|
|
36
42
|
if (outputMode === "json") {
|
|
37
43
|
diagnostics.push(message);
|
|
38
44
|
}
|
|
@@ -45,15 +51,23 @@ export function flushDiagnostics() {
|
|
|
45
51
|
console.error(message);
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
// ZINN_DEBUG=1 prints routing detail on stderr, so stdout and `--json` results stay unchanged.
|
|
55
|
+
export function isDebugOutputEnabled() {
|
|
56
|
+
return process.env.ZINN_DEBUG === "1";
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
function recordRun(outcome) {
|
|
59
|
+
const problem = writeRunRecord(outcome);
|
|
60
|
+
if (problem !== undefined && isDebugOutputEnabled()) {
|
|
61
|
+
diagnostic(`::telemetry ${problem}`);
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Ends a successful run after its output, recording telemetry then releasing notices held back in JSON mode.
|
|
66
|
+
* Telemetry goes first so its own debug notice is released with the rest.
|
|
67
|
+
*/
|
|
68
|
+
export function finishRun() {
|
|
69
|
+
recordRun({});
|
|
70
|
+
flushDiagnostics();
|
|
57
71
|
}
|
|
58
72
|
export function setLegacyReadAllowed(allowed) {
|
|
59
73
|
legacyReadAllowed = allowed;
|
|
@@ -161,14 +175,22 @@ export function renderFailure(reason) {
|
|
|
161
175
|
help: classified.help,
|
|
162
176
|
message: failureMessage(reason, "Something went wrong"),
|
|
163
177
|
};
|
|
178
|
+
const logPath = LOGGED_ERROR_CODES.includes(failure.code)
|
|
179
|
+
? writeFailureLog(reason, runNotices)
|
|
180
|
+
: undefined;
|
|
181
|
+
recordRun({
|
|
182
|
+
failure: classified,
|
|
183
|
+
...(logPath === undefined ? {} : { logFileName: basename(logPath) }),
|
|
184
|
+
});
|
|
164
185
|
const pendingDiagnostics = diagnostics.splice(0);
|
|
165
186
|
if (outputMode === "json") {
|
|
166
|
-
const details =
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
const details = {
|
|
188
|
+
...Object.fromEntries(Object.entries(failure.details ?? {}).filter(([, value]) => value !== undefined)),
|
|
189
|
+
...(logPath === undefined ? {} : { logPath }),
|
|
190
|
+
};
|
|
169
191
|
const error = {
|
|
170
192
|
...failure,
|
|
171
|
-
details:
|
|
193
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
172
194
|
diagnostics: pendingDiagnostics.length > 0 ? pendingDiagnostics : undefined,
|
|
173
195
|
};
|
|
174
196
|
console.error(JSON.stringify({ error }, null, 2));
|
|
@@ -178,6 +200,9 @@ export function renderFailure(reason) {
|
|
|
178
200
|
console.error(message);
|
|
179
201
|
}
|
|
180
202
|
console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
|
|
203
|
+
if (logPath !== undefined) {
|
|
204
|
+
console.error(`Full log: ${logPath}`);
|
|
205
|
+
}
|
|
181
206
|
}
|
|
182
207
|
// Let piped stderr finish writing before Node exits
|
|
183
208
|
process.stderr.write("", () => process.exit(1));
|
|
@@ -266,9 +291,6 @@ export function requireStringOption(option, value, name, message) {
|
|
|
266
291
|
}
|
|
267
292
|
return value;
|
|
268
293
|
}
|
|
269
|
-
export function isHelpFlag(flag) {
|
|
270
|
-
return helpSpellings.includes(flag);
|
|
271
|
-
}
|
|
272
294
|
/**
|
|
273
295
|
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
274
296
|
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
@@ -353,13 +375,8 @@ function unknownOptionMessage(message, args, suggestFor, route) {
|
|
|
353
375
|
if (suggestion === undefined) {
|
|
354
376
|
return { message: boundParserMessage(reason) };
|
|
355
377
|
}
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
const correctedArgs = [
|
|
359
|
-
...suggestion.args.slice(0, optionEnd),
|
|
360
|
-
...args.filter(isRouterFlag),
|
|
361
|
-
...suggestion.args.slice(optionEnd),
|
|
362
|
-
];
|
|
378
|
+
const { optionWords, passthroughWords } = splitAtOptionSeparator(suggestion.args);
|
|
379
|
+
const correctedArgs = [...optionWords, ...args.filter(isRouterFlag), ...passthroughWords];
|
|
363
380
|
return {
|
|
364
381
|
message: boundParserMessage(`${reason}. Did you mean: ${formatCommand(correctedArgs)}`, {
|
|
365
382
|
reason,
|
|
@@ -369,9 +386,8 @@ function unknownOptionMessage(message, args, suggestFor, route) {
|
|
|
369
386
|
};
|
|
370
387
|
}
|
|
371
388
|
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
389
|
+
const { optionWords } = splitAtOptionSeparator(args);
|
|
390
|
+
const wordIndex = optionWords.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
375
391
|
if (wordIndex === -1) {
|
|
376
392
|
return { message: boundParserMessage(message) };
|
|
377
393
|
}
|
|
@@ -397,7 +413,7 @@ function unknownOptionMessage(message, args, suggestFor, route) {
|
|
|
397
413
|
const fixedCommand = formatCommand([
|
|
398
414
|
...args.slice(0, wordIndex),
|
|
399
415
|
...routerFlagsAfter,
|
|
400
|
-
|
|
416
|
+
OPTION_SEPARATOR,
|
|
401
417
|
word,
|
|
402
418
|
...plainWordsAfter,
|
|
403
419
|
]);
|
|
@@ -406,17 +422,20 @@ function unknownOptionMessage(message, args, suggestFor, route) {
|
|
|
406
422
|
suggestedRoute: route,
|
|
407
423
|
};
|
|
408
424
|
}
|
|
425
|
+
export function isParseArgsError(error) {
|
|
426
|
+
const code = error?.code;
|
|
427
|
+
return typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
428
|
+
}
|
|
409
429
|
/**
|
|
410
430
|
* An argument failure from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
411
431
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
412
432
|
* `null` for any other error.
|
|
413
433
|
*/
|
|
414
434
|
export function parseArgsFailure(error, args, suggestFor, route) {
|
|
415
|
-
|
|
416
|
-
const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
417
|
-
if (!isParseArgsError) {
|
|
435
|
+
if (!isParseArgsError(error)) {
|
|
418
436
|
return null;
|
|
419
437
|
}
|
|
438
|
+
const code = error.code;
|
|
420
439
|
const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
|
|
421
440
|
if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
422
441
|
const hint = unknownOptionMessage(error.message, args, suggestFor, route);
|
package/src/list-limit.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const listLimitDescription = "Return at most n results after all filters.
|
|
1
|
+
export declare const listLimitDescription = "Return at most n results after all filters.";
|
|
2
2
|
export declare const listLimitOption: {
|
|
3
3
|
readonly type: "string";
|
|
4
4
|
readonly value: {
|
|
@@ -6,6 +6,6 @@ export declare const listLimitOption: {
|
|
|
6
6
|
readonly name: "n";
|
|
7
7
|
readonly pattern: string;
|
|
8
8
|
};
|
|
9
|
-
readonly description: "Return at most n results after all filters.
|
|
9
|
+
readonly description: "Return at most n results after all filters.";
|
|
10
10
|
};
|
|
11
11
|
export declare function parseListLimit(value: string | undefined): number | undefined;
|
package/src/list-limit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { listLimitMessage, listLimitPattern } from "@zinn-dev/core";
|
|
2
2
|
import { quit } from "./lib.js";
|
|
3
|
-
export const listLimitDescription =
|
|
3
|
+
export const listLimitDescription = "Return at most n results after all filters.";
|
|
4
4
|
export const listLimitOption = {
|
|
5
5
|
type: "string",
|
|
6
6
|
value: { kind: "positive-integer", name: "n", pattern: listLimitPattern },
|
package/src/overview.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const overview = [
|
|
2
|
+
{
|
|
3
|
+
summary: "Set deadlines and sort or filter by them",
|
|
4
|
+
uses: [
|
|
5
|
+
{ command: "task create", flags: ["--due"] },
|
|
6
|
+
{ command: "task edit", flags: ["--due"] },
|
|
7
|
+
{ command: "task list", flags: ["--sort due", "--due-since", "--due-until"] },
|
|
8
|
+
],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
summary: "Change several tasks in one command",
|
|
12
|
+
uses: [{ command: "task move" }, { command: "task archive" }, { command: "task delete" }],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
summary: "Read text from a file or stdin",
|
|
16
|
+
uses: [
|
|
17
|
+
{ command: "task create", flags: ["--description-file"] },
|
|
18
|
+
{ command: "task comment create", flags: ["--text-file"] },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{ summary: "Search titles, descriptions and comments", uses: [{ command: "task search" }] },
|
|
22
|
+
{
|
|
23
|
+
summary: "Continue a long list",
|
|
24
|
+
uses: [
|
|
25
|
+
{ command: "task list", flags: ["--limit", "--starting-after"] },
|
|
26
|
+
{ command: "activity list", flags: ["--limit", "--starting-after"] },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
summary: "See the agent and session behind each change",
|
|
31
|
+
uses: [{ command: "activity list" }, { command: "activity view" }],
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
export function formatOverview() {
|
|
35
|
+
return overview
|
|
36
|
+
.map(({ summary, uses }) => {
|
|
37
|
+
const named = uses.map(({ command, flags = [] }) => [command, ...flags].join(" "));
|
|
38
|
+
return ` ${summary}: ${named.join(", ")}`;
|
|
39
|
+
})
|
|
40
|
+
.join("\n");
|
|
41
|
+
}
|
|
@@ -22,6 +22,8 @@ export declare function presentActivities(events: Array<Activity>, options?: {
|
|
|
22
22
|
taskKey?: string;
|
|
23
23
|
taskId?: string;
|
|
24
24
|
showsFullIds?: boolean;
|
|
25
|
+
/** Only deletions among the events mark a reused key, as in one current task's history */
|
|
26
|
+
keysFromEventsOnly?: boolean;
|
|
25
27
|
}): Array<PresentedActivity>;
|
|
26
28
|
export declare function presentActor(actor: Actor): PresentedActor;
|
|
27
29
|
export declare function formatActor(actor: PresentedActor): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { activity, activityTaskKeySchema, column, label, minimumActivityIdLength, project, task, timestampSchema, } from "@zinn-dev/core";
|
|
1
|
+
import { activity, activityTaskIdSchema, 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";
|
|
@@ -36,6 +36,7 @@ const ACTOR_DETAIL_FIELDS = [
|
|
|
36
36
|
{ key: "actor_agent", label: "Agent" },
|
|
37
37
|
{ key: "actor_model", label: "Model" },
|
|
38
38
|
{ key: "actor_effort", label: "Effort" },
|
|
39
|
+
{ key: "actor_client", label: "Client" },
|
|
39
40
|
];
|
|
40
41
|
const ACTION_LABELS = {
|
|
41
42
|
create: "created",
|
|
@@ -87,21 +88,23 @@ export function abbreviateActivityIds(ids) {
|
|
|
87
88
|
}
|
|
88
89
|
return prefixes;
|
|
89
90
|
}
|
|
90
|
-
function getTaskNavigation(
|
|
91
|
+
function getTaskNavigation(pageEvents, { navigationEvents, taskKey, taskId, }) {
|
|
91
92
|
if (taskId !== undefined) {
|
|
92
93
|
return activity.getTaskIdentities({ taskId });
|
|
93
94
|
}
|
|
94
95
|
if (taskKey !== undefined) {
|
|
95
96
|
return activity.getTaskIdentities({ taskKey, showDeleted: true });
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
+
// A project selection counts only keys its own deletions recorded. Other pages check every key.
|
|
99
|
+
const selectionKeys = navigationEvents === undefined ? undefined : new Set();
|
|
100
|
+
const deletionEvents = navigationEvents ?? pageEvents;
|
|
98
101
|
function addKey(key) {
|
|
99
102
|
const parsed = activityTaskKeySchema.safeParse(key);
|
|
100
103
|
if (parsed.success) {
|
|
101
|
-
|
|
104
|
+
selectionKeys?.add(parsed.data);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
|
-
for (const event of
|
|
107
|
+
for (const event of navigationEvents ?? []) {
|
|
105
108
|
if (event.action !== "delete") {
|
|
106
109
|
continue;
|
|
107
110
|
}
|
|
@@ -116,48 +119,98 @@ function getTaskNavigation(events, taskKey, taskId) {
|
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
|
-
const
|
|
120
|
-
const needsTaskIdentities =
|
|
121
|
-
if (needsTaskIdentities) {
|
|
122
|
-
|
|
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
|
-
}
|
|
122
|
+
const isHistoricalKey = (key) => selectionKeys?.has(key) ?? true;
|
|
123
|
+
const needsTaskIdentities = (selectionKeys?.size ?? 0) > 0 || pageEvents.some((event) => event.entity_type === "task");
|
|
124
|
+
if (!needsTaskIdentities) {
|
|
125
|
+
return [];
|
|
130
126
|
}
|
|
131
|
-
|
|
127
|
+
/** A deleted task's recorded identity, when it is complete and holds a historical key. */
|
|
128
|
+
function toSnapshot(id, key, title) {
|
|
132
129
|
const parsedKey = activityTaskKeySchema.safeParse(key);
|
|
133
130
|
const isMatchingSnapshot = typeof id === "string" &&
|
|
134
131
|
typeof key === "string" &&
|
|
135
132
|
typeof title === "string" &&
|
|
136
133
|
parsedKey.success &&
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
identities.set(id, { id, key, title, status: "deleted" });
|
|
140
|
-
}
|
|
134
|
+
isHistoricalKey(parsedKey.data);
|
|
135
|
+
return isMatchingSnapshot ? [{ id, key, title, status: "deleted" }] : [];
|
|
141
136
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
const snapshots = deletionEvents.flatMap((event) => {
|
|
138
|
+
if (event.action !== "delete") {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
if (event.entity_type === "task") {
|
|
142
|
+
return toSnapshot(event.entity_id, event.changes?.key, event.changes?.title);
|
|
143
|
+
}
|
|
144
|
+
if (event.entity_type === "project" && Array.isArray(event.changes?.tasks)) {
|
|
145
|
+
return event.changes.tasks
|
|
146
|
+
.filter(isRecord)
|
|
147
|
+
.flatMap((snapshot) => toSnapshot(snapshot.id, snapshot.key, snapshot.title));
|
|
148
|
+
}
|
|
149
|
+
return [];
|
|
150
|
+
});
|
|
151
|
+
// Current tasks the page names, removes or shares a deleted key with.
|
|
152
|
+
const referencedIds = new Set(snapshots.map((snapshot) => snapshot.id));
|
|
153
|
+
const pageTaskIds = new Set();
|
|
154
|
+
for (const event of pageEvents) {
|
|
155
|
+
if (event.entity_type === "task") {
|
|
156
|
+
referencedIds.add(event.entity_id);
|
|
157
|
+
pageTaskIds.add(event.entity_id);
|
|
158
|
+
}
|
|
159
|
+
else if (event.entity_type === "project" &&
|
|
160
|
+
event.action === "delete" &&
|
|
161
|
+
Array.isArray(event.changes?.tasks)) {
|
|
162
|
+
for (const snapshot of event.changes.tasks.filter(isRecord)) {
|
|
163
|
+
referencedIds.add(snapshot.id);
|
|
149
164
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Current identities come first, recorded deletions fill the gaps
|
|
168
|
+
const identities = new Map();
|
|
169
|
+
function addIdentities(items) {
|
|
170
|
+
for (const item of items) {
|
|
171
|
+
if (!identities.has(item.id)) {
|
|
172
|
+
identities.set(item.id, item);
|
|
156
173
|
}
|
|
157
174
|
}
|
|
158
175
|
}
|
|
176
|
+
function addDeletedIdentities(items) {
|
|
177
|
+
addIdentities(items.flatMap((item) => item.status === "deleted" ? toSnapshot(item.id, item.key, item.title) : []));
|
|
178
|
+
}
|
|
179
|
+
addIdentities(activity.getCurrentTaskIdentities({ taskIds: parseTaskIds(referencedIds) }));
|
|
180
|
+
addIdentities(snapshots);
|
|
181
|
+
if (selectionKeys?.size === 0) {
|
|
182
|
+
return [...identities.values()];
|
|
183
|
+
}
|
|
184
|
+
// A page task deleted outside the deletion events above can still hold a historical key.
|
|
185
|
+
addDeletedIdentities(activity.getDeletedTaskIdentities({
|
|
186
|
+
taskIds: parseTaskIds(pageTaskIds).filter((id) => !identities.has(id)),
|
|
187
|
+
}));
|
|
188
|
+
// A historical key on the page needs every identity in the database that holds it
|
|
189
|
+
const pageKeys = new Set();
|
|
190
|
+
for (const id of pageTaskIds) {
|
|
191
|
+
const parsedKey = activityTaskKeySchema.safeParse(identities.get(id)?.key);
|
|
192
|
+
if (parsedKey.success && isHistoricalKey(parsedKey.data)) {
|
|
193
|
+
pageKeys.add(parsedKey.data);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
addIdentities(activity.getCurrentTaskIdentities({ taskKeys: [...pageKeys] }));
|
|
197
|
+
// Two identities already settle that a key is shared.
|
|
198
|
+
const identityCounts = new Map();
|
|
199
|
+
for (const identity of identities.values()) {
|
|
200
|
+
identityCounts.set(identity.key, (identityCounts.get(identity.key) ?? 0) + 1);
|
|
201
|
+
}
|
|
202
|
+
addDeletedIdentities(activity.getDeletedTaskIdentities({
|
|
203
|
+
taskKeys: [...pageKeys].filter((key) => (identityCounts.get(key) ?? 0) < 2),
|
|
204
|
+
}));
|
|
159
205
|
return [...identities.values()];
|
|
160
206
|
}
|
|
207
|
+
/** The valid task IDs among the given values */
|
|
208
|
+
function parseTaskIds(values) {
|
|
209
|
+
return [...values].flatMap((value) => {
|
|
210
|
+
const parsed = activityTaskIdSchema.safeParse(value);
|
|
211
|
+
return parsed.success ? [parsed.data] : [];
|
|
212
|
+
});
|
|
213
|
+
}
|
|
161
214
|
export function presentActivities(events, options = {}) {
|
|
162
215
|
if (events.length === 0) {
|
|
163
216
|
return [];
|
|
@@ -166,14 +219,20 @@ export function presentActivities(events, options = {}) {
|
|
|
166
219
|
? new Map()
|
|
167
220
|
: abbreviateActivityIds(activity.getIds());
|
|
168
221
|
const hasProjectSelector = options.projectKey !== undefined || options.projectId !== undefined;
|
|
222
|
+
// Recorded names and deleted task keys come only from create and delete snapshots
|
|
169
223
|
const navigationEvents = hasProjectSelector
|
|
170
224
|
? activity.getAll({
|
|
171
225
|
projectKey: options.projectKey,
|
|
172
226
|
projectId: options.projectId,
|
|
173
227
|
showDeleted: options.showDeleted,
|
|
228
|
+
actions: ["create", "delete"],
|
|
174
229
|
}).events
|
|
175
230
|
: events;
|
|
176
|
-
const tasks = getTaskNavigation(
|
|
231
|
+
const tasks = getTaskNavigation(events, {
|
|
232
|
+
navigationEvents: hasProjectSelector || options.keysFromEventsOnly ? navigationEvents : undefined,
|
|
233
|
+
taskKey: options.taskKey,
|
|
234
|
+
taskId: options.taskId,
|
|
235
|
+
});
|
|
177
236
|
const tasksById = new Map(tasks.map((identity) => [identity.id, identity]));
|
|
178
237
|
const taskIdsByKey = new Map();
|
|
179
238
|
for (const identity of tasks) {
|
|
@@ -457,6 +516,7 @@ export function presentActor(actor) {
|
|
|
457
516
|
actor_agent: actor.agent ?? null,
|
|
458
517
|
actor_model: actor.model ?? null,
|
|
459
518
|
actor_effort: actor.effort ?? null,
|
|
519
|
+
actor_client: actor.client ?? null,
|
|
460
520
|
};
|
|
461
521
|
}
|
|
462
522
|
export function formatActor(actor) {
|
|
@@ -471,6 +531,7 @@ export function formatActivityList(entries, options = {}) {
|
|
|
471
531
|
{ text: entry.displayId },
|
|
472
532
|
{ text: formatLocalTime(entry.event.created_at), style: "dim" },
|
|
473
533
|
{ text: `${entry.event.actor_name ?? UNKNOWN_ACTOR_NAME} (${entry.event.actor_kind})` },
|
|
534
|
+
{ text: entry.event.actor_client ?? "null" },
|
|
474
535
|
];
|
|
475
536
|
if (!options.showsDetails) {
|
|
476
537
|
return [...metadata, { text: formatActivityContent(entry) }];
|
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import type { RowCell } from "./row-layout.js";
|
|
2
|
-
import type { PresentedColumn } from "../result-schemas.js";
|
|
2
|
+
import type { PresentedColumn, PresentedColumnTaskCount } from "../result-schemas.js";
|
|
3
|
+
import { column } from "@zinn-dev/core";
|
|
3
4
|
type ColumnRow = {
|
|
4
5
|
name: string;
|
|
5
6
|
project?: string;
|
|
6
7
|
taskCount?: number;
|
|
8
|
+
is_first?: boolean;
|
|
9
|
+
is_last?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** A project's columns in board order. */
|
|
12
|
+
export type ProjectColumns = ReturnType<typeof column.getAllByProjectKey>;
|
|
13
|
+
/** Reads each project's columns once, so presenting many rows costs one read per project. */
|
|
14
|
+
export type ColumnBoard = (projectId: string) => ProjectColumns;
|
|
15
|
+
export declare function createColumnBoard(): ColumnBoard;
|
|
16
|
+
/** A column off its board, such as a deleted one, has no placement and no color. */
|
|
17
|
+
export declare function columnPlacement(projectColumns: ProjectColumns, columnId: string): {
|
|
18
|
+
is_first: boolean;
|
|
19
|
+
is_last: boolean;
|
|
7
20
|
};
|
|
8
21
|
export declare function presentColumn(columnMatch: {
|
|
9
22
|
id: string;
|
|
10
23
|
project_id: string;
|
|
11
24
|
name: string;
|
|
12
25
|
}): PresentedColumn;
|
|
13
|
-
|
|
26
|
+
/** Shapes one board's column rows, in order, with the placement each name is colored by. */
|
|
27
|
+
export declare function presentColumnTaskCounts(taskCounts: ReturnType<typeof column.getTaskCountsByProjectKey>): Array<PresentedColumnTaskCount>;
|
|
28
|
+
export declare function columnNameCell(columnName: string, placement?: Pick<ColumnRow, "is_first" | "is_last">): RowCell;
|
|
14
29
|
/** The archived row is left out when there are no archived tasks. */
|
|
15
30
|
export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
|
|
16
31
|
showsProject?: boolean;
|
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
import { project } from "@zinn-dev/core";
|
|
1
|
+
import { column, project } from "@zinn-dev/core";
|
|
2
2
|
import { formatRows } from "./row-layout.js";
|
|
3
3
|
/** Archived tasks are off the board, so they share one row below the columns instead of a column of their own. */
|
|
4
4
|
const ARCHIVED_ROW_LABEL = "Archived";
|
|
5
|
+
export function createColumnBoard() {
|
|
6
|
+
const projectColumnsByProjectId = new Map();
|
|
7
|
+
return (projectId) => {
|
|
8
|
+
const cachedColumns = projectColumnsByProjectId.get(projectId);
|
|
9
|
+
if (cachedColumns != null) {
|
|
10
|
+
return cachedColumns;
|
|
11
|
+
}
|
|
12
|
+
const boardColumns = column.getAllByProjectKey(project.getById(projectId).key);
|
|
13
|
+
projectColumnsByProjectId.set(projectId, boardColumns);
|
|
14
|
+
return boardColumns;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** A column off its board, such as a deleted one, has no placement and no color. */
|
|
18
|
+
export function columnPlacement(projectColumns, columnId) {
|
|
19
|
+
const columnIndex = projectColumns.findIndex((boardColumn) => boardColumn.id === columnId);
|
|
20
|
+
const isOnBoard = columnIndex !== -1;
|
|
21
|
+
return {
|
|
22
|
+
is_first: isOnBoard && columnIndex === 0,
|
|
23
|
+
is_last: isOnBoard && columnIndex === projectColumns.length - 1,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
5
26
|
export function presentColumn(columnMatch) {
|
|
6
27
|
const columnProject = project.getById(columnMatch.project_id);
|
|
28
|
+
const placement = columnPlacement(column.getAllByProjectKey(columnProject.key), columnMatch.id);
|
|
7
29
|
return {
|
|
8
30
|
id: columnMatch.id,
|
|
9
31
|
project: columnProject.key,
|
|
10
32
|
project_id: columnMatch.project_id,
|
|
11
33
|
name: columnMatch.name,
|
|
34
|
+
is_first: placement.is_first,
|
|
35
|
+
is_last: placement.is_last,
|
|
12
36
|
};
|
|
13
37
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
38
|
+
/** Shapes one board's column rows, in order, with the placement each name is colored by. */
|
|
39
|
+
export function presentColumnTaskCounts(taskCounts) {
|
|
40
|
+
const lastColumnIndex = taskCounts.columns.length - 1;
|
|
41
|
+
return taskCounts.columns.map((columnCount, columnIndex) => ({
|
|
42
|
+
id: columnCount.column.id,
|
|
43
|
+
name: columnCount.column.name,
|
|
44
|
+
is_first: columnIndex === 0,
|
|
45
|
+
is_last: columnIndex === lastColumnIndex,
|
|
46
|
+
taskCount: columnCount.taskCount,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
export function columnNameCell(columnName, placement = {}) {
|
|
50
|
+
// A board's first column is gray and its last is green. A one-column board is both, and colors as first.
|
|
51
|
+
if (placement.is_first) {
|
|
17
52
|
return { text: columnName, style: "gray" };
|
|
18
53
|
}
|
|
19
|
-
if (
|
|
54
|
+
if (placement.is_last) {
|
|
20
55
|
return { text: columnName, style: "green" };
|
|
21
56
|
}
|
|
22
57
|
return { text: columnName };
|
|
@@ -30,7 +65,11 @@ export function formatColumnList(presentedColumns, options = {}) {
|
|
|
30
65
|
const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
|
|
31
66
|
? [{ text: String(presentedColumn.taskCount) }]
|
|
32
67
|
: [];
|
|
33
|
-
return [
|
|
68
|
+
return [
|
|
69
|
+
...projectCells,
|
|
70
|
+
columnNameCell(presentedColumn.name, presentedColumn),
|
|
71
|
+
...taskCountCells,
|
|
72
|
+
];
|
|
34
73
|
});
|
|
35
74
|
if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
|
|
36
75
|
rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
|