@zinn-dev/cli 0.44.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/package.json +2 -2
  2. package/skills/zinn/SKILL.md +7 -9
  3. package/src/capabilities-schema.d.ts +5 -1
  4. package/src/column-hint.js +1 -3
  5. package/src/database.d.ts +1 -2
  6. package/src/database.js +1 -6
  7. package/src/duration-input.d.ts +7 -0
  8. package/src/duration-input.js +31 -0
  9. package/src/errors.d.ts +22 -0
  10. package/src/errors.js +30 -5
  11. package/src/expected-values.d.ts +48 -0
  12. package/src/expected-values.js +60 -0
  13. package/src/follow.d.ts +9 -0
  14. package/src/follow.js +58 -0
  15. package/src/input.d.ts +0 -8
  16. package/src/input.js +36 -16
  17. package/src/lib.d.ts +5 -2
  18. package/src/lib.js +18 -8
  19. package/src/list-continuation.js +1 -4
  20. package/src/presentation/activity-presentation.d.ts +2 -0
  21. package/src/presentation/activity-presentation.js +58 -3
  22. package/src/presentation/column-presentation.d.ts +9 -4
  23. package/src/presentation/column-presentation.js +29 -12
  24. package/src/presentation/doctor-presentation.d.ts +4 -0
  25. package/src/presentation/doctor-presentation.js +24 -0
  26. package/src/presentation/relation-presentation.js +2 -1
  27. package/src/presentation/task-blame-presentation.d.ts +1 -4
  28. package/src/presentation/task-blame-presentation.js +1 -1
  29. package/src/presentation/task-presentation.d.ts +2 -0
  30. package/src/presentation/task-presentation.js +39 -2
  31. package/src/result-schemas.d.ts +353 -58
  32. package/src/result-schemas.js +46 -2
  33. package/src/results.d.ts +6 -2
  34. package/src/results.js +9 -3
  35. package/src/routes/activity-router.d.ts +12 -3
  36. package/src/routes/activity-router.js +93 -59
  37. package/src/routes/aliases.js +1 -0
  38. package/src/routes/comment-router.d.ts +24 -6
  39. package/src/routes/comment-router.js +15 -5
  40. package/src/routes/doctor-router.d.ts +39 -0
  41. package/src/routes/doctor-router.js +103 -0
  42. package/src/routes/label-router.d.ts +39 -6
  43. package/src/routes/label-router.js +22 -5
  44. package/src/routes/project-router.d.ts +60 -11
  45. package/src/routes/project-router.js +100 -33
  46. package/src/routes/restore-router.js +2 -2
  47. package/src/routes/router.js +3 -7
  48. package/src/routes/routes.d.ts +404 -33
  49. package/src/routes/routes.js +4 -0
  50. package/src/routes/skill-router.d.ts +25 -0
  51. package/src/routes/skill-router.js +96 -0
  52. package/src/routes/task-router.d.ts +231 -13
  53. package/src/routes/task-router.js +247 -19
  54. package/src/text-edit.d.ts +2 -2
  55. package/src/text-input.d.ts +19 -1
  56. package/src/text-input.js +26 -5
package/src/input.js CHANGED
@@ -63,10 +63,9 @@ export const archiveConstraint = {
63
63
  kind: "exclusive",
64
64
  members: ["option:archived", "option:all"],
65
65
  };
66
- export const routerOptionNames = { json: "json", legacyRead: "allow-legacy-read" };
66
+ export const routerOptionNames = { json: "json" };
67
67
  export const routerOptions = {
68
68
  [routerOptionNames.json]: { type: "boolean" },
69
- [routerOptionNames.legacyRead]: { type: "boolean" },
70
69
  };
71
70
  export const helpSpellings = ["-h", "--help"];
72
71
  export const versionSpellings = ["-v", "--version"];
@@ -74,12 +73,9 @@ export const OPTION_SEPARATOR = "--";
74
73
  export function isJsonFlag(flag) {
75
74
  return flag === `--${routerOptionNames.json}`;
76
75
  }
77
- export function isAllowLegacyReadFlag(flag) {
78
- return flag === `--${routerOptionNames.legacyRead}`;
79
- }
80
76
  /** A flag the router reads wherever it appears before --, for every command. */
81
77
  export function isRouterFlag(flag) {
82
- return isJsonFlag(flag) || isAllowLegacyReadFlag(flag);
78
+ return isJsonFlag(flag);
83
79
  }
84
80
  export function isHelpFlag(flag) {
85
81
  return helpSpellings.includes(flag);
@@ -165,7 +161,7 @@ export function generateInputUsage(input) {
165
161
  constraint.members.length === members.length &&
166
162
  constraint.members.every((member) => members.includes(member)));
167
163
  const choice = (alternatives, isRequired) => isRequired ? `(${alternatives.join("|")})` : `[${alternatives.join("|")}]`;
168
- return input.forms.map((form) => {
164
+ return input.forms.flatMap((form) => {
169
165
  const words = new Map([
170
166
  ...form.positionals.map((positional, index) => [`positional:${positional.name}`, positionalWords(form)[index]]),
171
167
  ...options.map(({ reference, word }) => [reference, word]),
@@ -194,18 +190,42 @@ export function generateInputUsage(input) {
194
190
  words.delete(reference);
195
191
  }
196
192
  }
197
- for (const constraint of input.constraints) {
198
- const hasEveryMemberWord = constraint.kind === "exclusive" && constraint.members.every((member) => words.has(member));
199
- if (!hasEveryMemberWord) {
200
- continue;
193
+ const exclusiveGroups = input.constraints
194
+ .filter((constraint) => constraint.kind === "exclusive")
195
+ .map((constraint) => constraint.members)
196
+ .filter((members) => members.every((member) => words.has(member)));
197
+ function renderChoices(remaining) {
198
+ const groups = exclusiveGroups
199
+ .map((members) => members.filter((member) => remaining.has(member)))
200
+ .filter((members) => members.length > 1);
201
+ const overlappingMember = groups
202
+ .flat()
203
+ .find((member) => groups.filter((members) => members.includes(member)).length > 1);
204
+ // Separate usage lines preserve combinations allowed by overlapping exclusions.
205
+ if (overlappingMember !== undefined) {
206
+ const withoutMember = new Map(remaining);
207
+ withoutMember.delete(overlappingMember);
208
+ const withMember = new Map(remaining);
209
+ withMember.set(overlappingMember, remaining.get(overlappingMember).slice(1, -1));
210
+ for (const members of groups.filter((members) => members.includes(overlappingMember))) {
211
+ for (const member of members) {
212
+ if (member !== overlappingMember) {
213
+ withMember.delete(member);
214
+ }
215
+ }
216
+ }
217
+ return [...renderChoices(withoutMember), ...renderChoices(withMember)];
201
218
  }
202
- const alternatives = constraint.members.map((member) => words.get(member).slice(1, -1));
203
- words.set(constraint.members[0], choice(alternatives, isRequiredChoice(constraint.members)));
204
- for (const member of constraint.members.slice(1)) {
205
- words.delete(member);
219
+ for (const members of groups) {
220
+ const alternatives = members.map((member) => remaining.get(member).slice(1, -1));
221
+ remaining.set(members[0], choice(alternatives, isRequiredChoice(members)));
222
+ for (const member of members.slice(1)) {
223
+ remaining.delete(member);
224
+ }
206
225
  }
226
+ return [[...remaining.values()].join(" ")];
207
227
  }
208
- return [...words.values()].join(" ");
228
+ return renderChoices(words);
209
229
  });
210
230
  }
211
231
  export const usageLabel = "Usage: ";
package/src/lib.d.ts CHANGED
@@ -23,9 +23,12 @@ export declare function isDebugOutputEnabled(): boolean;
23
23
  * Telemetry goes first so its own debug notice is released with the rest.
24
24
  */
25
25
  export declare function finishRun(): void;
26
- export declare function setLegacyReadAllowed(allowed: boolean): void;
27
- export declare function isLegacyReadAllowed(): boolean;
28
26
  export declare function output<T>(data: T, transformToString: (data: T) => string): void;
27
+ /**
28
+ * Prints items as they arrive for a command that keeps running. JSON mode prints one document per line.
29
+ * It writes to the stream itself, whose error event reports a closed pipe under Node and Bun alike.
30
+ */
31
+ export declare function outputStream<T>(items: Array<T>, transformToString: (items: Array<T>) => string, signal: AbortSignal): Promise<void>;
29
32
  /** Includes change data in JSON and adds a stderr note for each unchanged object */
30
33
  export declare function outputChanges<Change extends {
31
34
  changed: boolean;
package/src/lib.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { basename } from "node:path";
2
+ import { once } from "node:events";
2
3
  import { parseArgs } from "node:util";
3
4
  import { createInterface } from "node:readline/promises";
4
5
  import { z } from "zod";
@@ -9,7 +10,6 @@ import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOpt
9
10
  import { formatParserReasonPreview } from "./presentation/description-presentation.js";
10
11
  import { writeRunRecord } from "./telemetry.js";
11
12
  let outputMode = "text";
12
- let legacyReadAllowed = false;
13
13
  const diagnostics = [];
14
14
  /** Every notice of this run in order, kept for the failure log */
15
15
  const runNotices = [];
@@ -69,12 +69,6 @@ export function finishRun() {
69
69
  recordRun({});
70
70
  flushDiagnostics();
71
71
  }
72
- export function setLegacyReadAllowed(allowed) {
73
- legacyReadAllowed = allowed;
74
- }
75
- export function isLegacyReadAllowed() {
76
- return legacyReadAllowed;
77
- }
78
72
  export function output(data, transformToString) {
79
73
  if (outputMode === "json") {
80
74
  console.info(JSON.stringify(data, null, 2));
@@ -85,6 +79,21 @@ export function output(data, transformToString) {
85
79
  console.info(dataText);
86
80
  }
87
81
  }
82
+ /**
83
+ * Prints items as they arrive for a command that keeps running. JSON mode prints one document per line.
84
+ * It writes to the stream itself, whose error event reports a closed pipe under Node and Bun alike.
85
+ */
86
+ export async function outputStream(items, transformToString, signal) {
87
+ if (items.length === 0) {
88
+ return;
89
+ }
90
+ const text = outputMode === "json"
91
+ ? items.map((item) => JSON.stringify(item)).join("\n")
92
+ : transformToString(items);
93
+ if (!process.stdout.write(`${text}\n`)) {
94
+ await once(process.stdout, "drain", { signal });
95
+ }
96
+ }
88
97
  /** Includes change data in JSON and adds a stderr note for each unchanged object */
89
98
  export function outputChanges(changes, present, formatEntries, describeUnchanged) {
90
99
  const presentedChanges = changes.map((change) => ({
@@ -204,8 +213,9 @@ export function renderFailure(reason) {
204
213
  console.error(`Full log: ${logPath}`);
205
214
  }
206
215
  }
216
+ const exitCode = reason instanceof CliError && reason.exitCode !== undefined ? reason.exitCode : 1;
207
217
  // Let piped stderr finish writing before Node exits
208
- process.stderr.write("", () => process.exit(1));
218
+ process.stderr.write("", () => process.exit(exitCode));
209
219
  }
210
220
  /** A command was given the wrong words. The router prints the message with the command's usage lines. */
211
221
  export class UsageError extends CliError {
@@ -1,4 +1,4 @@
1
- import { formatCommand, getOutputMode, isLegacyReadAllowed } from "./lib.js";
1
+ import { formatCommand, getOutputMode } from "./lib.js";
2
2
  /** Rebuilds a list command with its existing filters and the next cursor. */
3
3
  export function formatListContinuation(command, positionals, tokens, cursorOption, cursorId) {
4
4
  const continuation = tokens.flatMap((token) => {
@@ -10,9 +10,6 @@ export function formatListContinuation(command, positionals, tokens, cursorOptio
10
10
  if (getOutputMode() === "json") {
11
11
  continuation.push("--json");
12
12
  }
13
- if (isLegacyReadAllowed()) {
14
- continuation.push("--allow-legacy-read");
15
- }
16
13
  continuation.push(`--${cursorOption}`, cursorId);
17
14
  return formatCommand([...command, ...positionals, ...continuation]);
18
15
  }
@@ -27,6 +27,8 @@ export declare function presentActivities(events: Array<Activity>, options?: {
27
27
  }): Array<PresentedActivity>;
28
28
  export declare function presentActor(actor: Actor): PresentedActor;
29
29
  export declare function formatActor(actor: PresentedActor): string;
30
+ /** An actor's name and kind, as activity rows show who acted */
31
+ export declare function formatActorLabel(actor: Pick<PresentedActor, "actor_name" | "actor_kind">): string;
30
32
  export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
31
33
  showsDetails?: boolean;
32
34
  }): string;
@@ -24,7 +24,24 @@ const RECORDED_FIELDS = new Set([
24
24
  "target",
25
25
  "comment",
26
26
  "text",
27
+ "lease_ms",
28
+ "replaced",
29
+ "previous_expires_at",
30
+ "claimed_at",
31
+ "expires_at",
32
+ "cause",
27
33
  ]);
34
+ const CLAIM_ACTIONS = new Set(["claim", "claim_take", "claim_heartbeat", "claim_release"]);
35
+ // A released claim records its holder as actor fields, which summaries show as one holder.
36
+ const CLAIM_HOLDER_FIELDS = new Set([
37
+ "actor_kind",
38
+ "actor_name",
39
+ "actor_session_id",
40
+ "actor_thread_id",
41
+ ]);
42
+ const RECORDED_TIME_FIELDS = new Set(["due_at", "previous_expires_at", "claimed_at", "expires_at"]);
43
+ // Summaries leave out a released claim's own times, which activity view shows.
44
+ const CLAIM_SPAN_FIELDS = new Set(["claimed_at", "expires_at"]);
28
45
  const ENTITY_PREVIEW_LENGTH = 24;
29
46
  const UNKNOWN_ACTOR_NAME = "unknown";
30
47
  const ACTOR_DETAIL_FIELDS = [
@@ -51,6 +68,10 @@ const ACTION_LABELS = {
51
68
  comment_create: "added comment",
52
69
  comment_edit: "edited comment",
53
70
  comment_delete: "deleted comment",
71
+ claim: "claimed",
72
+ claim_take: "took over claim",
73
+ claim_heartbeat: "renewed claim",
74
+ claim_release: "released claim",
54
75
  };
55
76
  function isRecord(value) {
56
77
  return value != null && typeof value === "object" && !Array.isArray(value);
@@ -367,6 +388,28 @@ function formatDeadline(value) {
367
388
  ? formatLocalTime(parsed.data, { includesSeconds: true })
368
389
  : summarizeValue(value);
369
390
  }
391
+ /**
392
+ * Summarizes a claim action's holder, replaced claim and times.
393
+ * Returns `null` to leave the field out, or `undefined` for the usual summary.
394
+ */
395
+ function summarizeClaimChange(changes, field, value) {
396
+ if (CLAIM_HOLDER_FIELDS.has(field)) {
397
+ const holder = changes;
398
+ return field === "actor_kind" ? `holder: ${formatActorLabel(holder)}` : null;
399
+ }
400
+ if (CLAIM_SPAN_FIELDS.has(field)) {
401
+ return null;
402
+ }
403
+ if (field === "replaced") {
404
+ return isRecord(value)
405
+ ? `replaced: ${formatActorLabel(value)}`
406
+ : null;
407
+ }
408
+ if (RECORDED_TIME_FIELDS.has(field)) {
409
+ return `${field}: ${formatDeadline(value)}`;
410
+ }
411
+ return undefined;
412
+ }
370
413
  function formatRemovedTasks(entry) {
371
414
  return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
372
415
  }
@@ -382,6 +425,12 @@ function formatChangeSummary(entry, options = {}) {
382
425
  if (isSnapshot && value === null) {
383
426
  return null;
384
427
  }
428
+ if (CLAIM_ACTIONS.has(event.action)) {
429
+ const claimSummary = summarizeClaimChange(changes, field, value);
430
+ if (claimSummary !== undefined) {
431
+ return claimSummary;
432
+ }
433
+ }
385
434
  const repeatsIdentity = options.omitsIdentity &&
386
435
  isSnapshot &&
387
436
  (field === "key" || field === "name") &&
@@ -489,12 +538,14 @@ function formatRecordedChanges(event) {
489
538
  }
490
539
  const sections = [];
491
540
  const unknownFields = {};
541
+ const isClaimAction = CLAIM_ACTIONS.has(event.action);
492
542
  for (const [field, value] of Object.entries(event.changes)) {
493
- if (!RECORDED_FIELDS.has(field)) {
543
+ const isRecordedField = RECORDED_FIELDS.has(field) || (isClaimAction && CLAIM_HOLDER_FIELDS.has(field));
544
+ if (!isRecordedField) {
494
545
  unknownFields[field] = value;
495
546
  continue;
496
547
  }
497
- const formatValue = field === "due_at" ? formatDeadline : formatRecordedValue;
548
+ const formatValue = RECORDED_TIME_FIELDS.has(field) ? formatDeadline : formatRecordedValue;
498
549
  const body = isRecordedChangePair(event, value)
499
550
  ? `${formatSection("From", formatValue(value[0]))}\n\n${formatSection("To", formatValue(value[1]))}`
500
551
  : formatValue(value);
@@ -525,12 +576,16 @@ export function formatActor(actor) {
525
576
  ...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${actor[key] ?? "null"}`),
526
577
  ].join("\n");
527
578
  }
579
+ /** An actor's name and kind, as activity rows show who acted */
580
+ export function formatActorLabel(actor) {
581
+ return `${actor.actor_name ?? UNKNOWN_ACTOR_NAME} (${actor.actor_kind})`;
582
+ }
528
583
  export function formatActivityList(entries, options = {}) {
529
584
  const rows = entries.map((entry) => {
530
585
  const metadata = [
531
586
  { text: entry.displayId },
532
587
  { text: formatLocalTime(entry.event.created_at), style: "dim" },
533
- { text: `${entry.event.actor_name ?? UNKNOWN_ACTOR_NAME} (${entry.event.actor_kind})` },
588
+ { text: formatActorLabel(entry.event) },
534
589
  { text: entry.event.actor_client ?? "null" },
535
590
  ];
536
591
  if (!options.showsDetails) {
@@ -1,12 +1,12 @@
1
+ import type { ColumnCategory } from "@zinn-dev/core";
1
2
  import type { RowCell } from "./row-layout.js";
2
3
  import type { PresentedColumn, PresentedColumnTaskCount } from "../result-schemas.js";
3
4
  import { column } from "@zinn-dev/core";
4
5
  type ColumnRow = {
5
6
  name: string;
7
+ category?: string | null;
6
8
  project?: string;
7
9
  taskCount?: number;
8
- is_first?: boolean;
9
- is_last?: boolean;
10
10
  };
11
11
  /** A project's columns in board order. */
12
12
  export type ProjectColumns = ReturnType<typeof column.getAllByProjectKey>;
@@ -22,10 +22,15 @@ export declare function presentColumn(columnMatch: {
22
22
  id: string;
23
23
  project_id: string;
24
24
  name: string;
25
+ category?: ColumnCategory;
25
26
  }): PresentedColumn;
26
- /** Shapes one board's column rows, in order, with the placement each name is colored by. */
27
+ /** Shapes one board's column rows in order.*/
27
28
  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;
29
+ /**
30
+ * Colors a column name by its category.
31
+ * Names without a category, as on an older database, stay uncolored
32
+ */
33
+ export declare function columnNameCell(columnName: string, category?: string | null): RowCell;
29
34
  /** The archived row is left out when there are no archived tasks. */
30
35
  export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
31
36
  showsProject?: boolean;
@@ -33,9 +33,10 @@ export function presentColumn(columnMatch) {
33
33
  name: columnMatch.name,
34
34
  is_first: placement.is_first,
35
35
  is_last: placement.is_last,
36
+ category: columnMatch.category ?? null,
36
37
  };
37
38
  }
38
- /** Shapes one board's column rows, in order, with the placement each name is colored by. */
39
+ /** Shapes one board's column rows in order.*/
39
40
  export function presentColumnTaskCounts(taskCounts) {
40
41
  const lastColumnIndex = taskCounts.columns.length - 1;
41
42
  return taskCounts.columns.map((columnCount, columnIndex) => ({
@@ -43,18 +44,25 @@ export function presentColumnTaskCounts(taskCounts) {
43
44
  name: columnCount.column.name,
44
45
  is_first: columnIndex === 0,
45
46
  is_last: columnIndex === lastColumnIndex,
47
+ category: columnCount.column.category ?? null,
46
48
  taskCount: columnCount.taskCount,
47
49
  }));
48
50
  }
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) {
52
- return { text: columnName, style: "gray" };
53
- }
54
- if (placement.is_last) {
55
- return { text: columnName, style: "green" };
56
- }
57
- return { text: columnName };
51
+ /** The color of each category's column names */
52
+ const CATEGORY_STYLES = {
53
+ backlog: "gray",
54
+ in_progress: "blue",
55
+ review: "yellow",
56
+ done: "green",
57
+ cancelled: "gray",
58
+ };
59
+ /**
60
+ * Colors a column name by its category.
61
+ * Names without a category, as on an older database, stay uncolored
62
+ */
63
+ export function columnNameCell(columnName, category) {
64
+ const style = category == null ? undefined : CATEGORY_STYLES[category];
65
+ return style === undefined ? { text: columnName } : { text: columnName, style };
58
66
  }
59
67
  /** The archived row is left out when there are no archived tasks. */
60
68
  export function formatColumnList(presentedColumns, options = {}) {
@@ -62,17 +70,26 @@ export function formatColumnList(presentedColumns, options = {}) {
62
70
  const projectCells = options.showsProject && presentedColumn.project != null
63
71
  ? [{ text: presentedColumn.project }]
64
72
  : [];
73
+ // The cell stays, empty, for a column without a category on an older database.
74
+ const categoryCells = presentedColumn.category === undefined ? [] : [{ text: presentedColumn.category ?? "" }];
65
75
  const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
66
76
  ? [{ text: String(presentedColumn.taskCount) }]
67
77
  : [];
68
78
  return [
69
79
  ...projectCells,
70
- columnNameCell(presentedColumn.name, presentedColumn),
80
+ columnNameCell(presentedColumn.name, presentedColumn.category),
81
+ ...categoryCells,
71
82
  ...taskCountCells,
72
83
  ];
73
84
  });
74
85
  if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
75
- rows.push([{ text: ARCHIVED_ROW_LABEL }, { text: String(options.archivedTaskCount) }]);
86
+ // An empty cell keeps the count under the task counts when rows show categories.
87
+ const hasCategoryCell = presentedColumns.some((presentedColumn) => presentedColumn.category !== undefined);
88
+ rows.push([
89
+ { text: ARCHIVED_ROW_LABEL },
90
+ ...(hasCategoryCell ? [{ text: "" }] : []),
91
+ { text: String(options.archivedTaskCount) },
92
+ ]);
76
93
  }
77
94
  return formatRows(rows);
78
95
  }
@@ -0,0 +1,4 @@
1
+ import type { DoctorCheck } from "@zinn-dev/core";
2
+ import type { PresentedDoctor } from "../result-schemas.js";
3
+ export declare function presentDoctor(checks: ReadonlyArray<DoctorCheck>, agentSkill: DoctorCheck<"agent_skill">): PresentedDoctor;
4
+ export declare function formatDoctor(report: PresentedDoctor): string;
@@ -0,0 +1,24 @@
1
+ import { styleOutputText } from "./color.js";
2
+ const STATUS_STYLES = {
3
+ ok: "green",
4
+ warning: "yellow",
5
+ problem: "red",
6
+ };
7
+ const STATUS_WIDTH = Math.max(...Object.keys(STATUS_STYLES).map((status) => status.length));
8
+ const REMEDY_INDENT = " ".repeat(STATUS_WIDTH + 1);
9
+ export function presentDoctor(checks, agentSkill) {
10
+ const presented = [...checks, agentSkill];
11
+ return {
12
+ ok: presented.every((check) => check.status === "ok"),
13
+ checks: presented,
14
+ };
15
+ }
16
+ export function formatDoctor(report) {
17
+ return report.checks
18
+ .flatMap(({ status, message, remedy }) => {
19
+ const label = styleOutputText(STATUS_STYLES[status], status.padEnd(STATUS_WIDTH));
20
+ const line = `${label} ${message}`;
21
+ return remedy === null ? [line] : [line, `${REMEDY_INDENT}${remedy}`];
22
+ })
23
+ .join("\n");
24
+ }
@@ -37,6 +37,7 @@ export function presentRelations(taskMatch, board = createColumnBoard()) {
37
37
  column_id: other.column_id,
38
38
  is_first: placement.is_first,
39
39
  is_last: placement.is_last,
40
+ column_category: columnMatch.category ?? null,
40
41
  title: other.title,
41
42
  status: other.archived_at == null ? "Active" : "Archived",
42
43
  },
@@ -73,7 +74,7 @@ export function formatRelationList(relations, options = {}) {
73
74
  return [
74
75
  { text: label },
75
76
  { text: entry.task.key },
76
- columnNameCell(entry.task.column, entry.task),
77
+ columnNameCell(entry.task.column, entry.task.column_category),
77
78
  { text: `${entry.task.title}${archived}` },
78
79
  ...(options.trailingCell === undefined ? [] : [options.trailingCell(entry)]),
79
80
  ];
@@ -1,10 +1,7 @@
1
1
  import type { PresentedRelation, PresentedTaskBlame } from "../result-schemas.js";
2
2
  export declare function formatTaskBlame(blame: PresentedTaskBlame, options: {
3
3
  relations: Array<PresentedRelation>;
4
- columnPlacement: {
5
- is_first: boolean;
6
- is_last: boolean;
7
- };
4
+ columnCategory: string | null;
8
5
  isArchived: boolean;
9
6
  /** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
10
7
  activityIdPrefixes: Map<string, string>;
@@ -23,7 +23,7 @@ export function formatTaskBlame(blame, options) {
23
23
  `${blame.task.key} (${blame.task.id})${options.isArchived ? `${formatCellSeparator()}Archived` : ""}`,
24
24
  formatSection("Fields", [
25
25
  field("Title", fields.title.value, fields.title.attribution),
26
- field("Column", formatCell(columnNameCell(fields.column.value.name, options.columnPlacement)), fields.column.attribution),
26
+ field("Column", formatCell(columnNameCell(fields.column.value.name, options.columnCategory)), fields.column.attribution),
27
27
  field("Priority", formatCell(taskPriorityCell(fields.priority.value, true)), fields.priority.attribution),
28
28
  field("Due", fields.due_at.value === null
29
29
  ? "none"
@@ -10,5 +10,7 @@ export declare function formatTaskList(presentedTasks: Array<PresentedTask>, opt
10
10
  showsStatus?: boolean;
11
11
  showsFullPriority?: boolean;
12
12
  prefix?: string;
13
+ /** Shows an expired claim too, and when each claim's lease ends */
14
+ showsClaimDetail?: boolean;
13
15
  }): string;
14
16
  export declare function formatTaskTimestamps(task: Pick<PresentedTaskDetail, "created_at" | "updated_at">): string;
@@ -3,6 +3,7 @@ import { columnNameCell, columnPlacement, createColumnBoard } from "./column-pre
3
3
  import { labelNameCell } from "./label-presentation.js";
4
4
  import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
5
5
  import { formatLocalTime } from "./time.js";
6
+ import { formatActorLabel } from "./activity-presentation.js";
6
7
  const EMPTY_CELL_MARKER = "-";
7
8
  const LABEL_NAME_SEPARATOR = ", ";
8
9
  export function taskPriorityCell(priority, showsFullPriority) {
@@ -42,6 +43,7 @@ export function presentTask(taskMatch, board = createColumnBoard()) {
42
43
  column_id: taskMatch.column_id,
43
44
  is_first: placement.is_first,
44
45
  is_last: placement.is_last,
46
+ column_category: columnMatch.category ?? null,
45
47
  title: taskMatch.title,
46
48
  description: taskMatch.description,
47
49
  priority: taskMatch.priority,
@@ -50,8 +52,37 @@ export function presentTask(taskMatch, board = createColumnBoard()) {
50
52
  label_ids: labels.map((label) => label.id),
51
53
  created_at: taskMatch.created_at,
52
54
  updated_at: taskMatch.updated_at,
55
+ claim: presentClaim(taskMatch.claim),
53
56
  };
54
57
  }
58
+ function presentClaim(claim) {
59
+ if (claim == null) {
60
+ return null;
61
+ }
62
+ return {
63
+ state: claim.state,
64
+ actor_kind: claim.actor_kind,
65
+ actor_name: claim.actor_name,
66
+ actor_session_id: claim.actor_session_id,
67
+ actor_thread_id: claim.actor_thread_id,
68
+ claimed_at: claim.claimed_at,
69
+ renewed_at: claim.renewed_at,
70
+ worked_at: claim.worked_at,
71
+ lease_ms: claim.lease_ms,
72
+ expires_at: claim.expires_at,
73
+ };
74
+ }
75
+ /** Who holds the claim, and when its lease ends or ended when `showsExpiry` is set */
76
+ function formatClaim(claim, showsExpiry) {
77
+ const holder = formatActorLabel(claim);
78
+ if (!showsExpiry) {
79
+ return `Claimed by ${holder}`;
80
+ }
81
+ const expiresAt = formatLocalTime(claim.expires_at, { includesSeconds: true });
82
+ return claim.state === "live"
83
+ ? `Claimed by ${holder} until ${expiresAt}`
84
+ : `Claim by ${holder} expired at ${expiresAt}`;
85
+ }
55
86
  export function formatTaskList(presentedTasks, options = {}) {
56
87
  const labelColorsByName = getLabelColorsByName();
57
88
  return formatRows(presentedTasks.map((presentedTask) => {
@@ -65,12 +96,18 @@ export function formatTaskList(presentedTasks, options = {}) {
65
96
  const deadline = presentedTask.due_at == null
66
97
  ? ""
67
98
  : `${formatCellSeparator()}Due ${formatLocalTime(presentedTask.due_at, { includesSeconds: true })}`;
99
+ const showsClaimDetail = options.showsClaimDetail ?? false;
100
+ const claim = presentedTask.claim;
101
+ const showsClaim = claim != null && (claim.state === "live" || showsClaimDetail);
102
+ const claimText = showsClaim
103
+ ? `${formatCellSeparator()}${formatClaim(claim, showsClaimDetail)}`
104
+ : "";
68
105
  return [
69
106
  { text: `${options.prefix ?? ""}${presentedTask.key}` },
70
107
  ...statusCells,
71
- columnNameCell(presentedTask.column, presentedTask),
108
+ columnNameCell(presentedTask.column, presentedTask.column_category),
72
109
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
73
- { text: `${presentedTask.title}${deadline}${labels}` },
110
+ { text: `${presentedTask.title}${deadline}${claimText}${labels}` },
74
111
  ];
75
112
  }));
76
113
  }