@zinn-dev/cli 0.44.0 → 0.46.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 (82) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/skills/zinn/SKILL.md +7 -9
  4. package/src/actor.d.ts +1 -1
  5. package/src/actor.js +4 -1
  6. package/src/capabilities-schema.d.ts +9 -1
  7. package/src/column-hint.js +1 -3
  8. package/src/database.d.ts +1 -2
  9. package/src/database.js +1 -6
  10. package/src/duration-input.d.ts +7 -0
  11. package/src/duration-input.js +31 -0
  12. package/src/errors.d.ts +26 -0
  13. package/src/errors.js +46 -8
  14. package/src/expected-values.d.ts +48 -0
  15. package/src/expected-values.js +60 -0
  16. package/src/follow.d.ts +9 -0
  17. package/src/follow.js +58 -0
  18. package/src/input.d.ts +0 -8
  19. package/src/input.js +36 -16
  20. package/src/lib.d.ts +7 -3
  21. package/src/lib.js +70 -28
  22. package/src/list-continuation.js +1 -4
  23. package/src/presentation/activity-presentation.d.ts +2 -0
  24. package/src/presentation/activity-presentation.js +60 -3
  25. package/src/presentation/column-presentation.d.ts +9 -4
  26. package/src/presentation/column-presentation.js +29 -12
  27. package/src/presentation/doctor-presentation.d.ts +10 -0
  28. package/src/presentation/doctor-presentation.js +28 -0
  29. package/src/presentation/relation-presentation.js +2 -1
  30. package/src/presentation/skill-status-presentation.d.ts +9 -0
  31. package/src/presentation/skill-status-presentation.js +43 -0
  32. package/src/presentation/task-blame-presentation.d.ts +2 -4
  33. package/src/presentation/task-blame-presentation.js +4 -2
  34. package/src/presentation/task-presentation.d.ts +18 -4
  35. package/src/presentation/task-presentation.js +94 -30
  36. package/src/result-schemas.d.ts +490 -58
  37. package/src/result-schemas.js +97 -2
  38. package/src/results.d.ts +6 -2
  39. package/src/results.js +9 -3
  40. package/src/routes/activity-router.d.ts +16 -5
  41. package/src/routes/activity-router.js +131 -70
  42. package/src/routes/aliases.js +1 -0
  43. package/src/routes/backup-router.d.ts +1 -0
  44. package/src/routes/backup-router.js +4 -3
  45. package/src/routes/capabilities-router.d.ts +1 -0
  46. package/src/routes/capabilities-router.js +1 -1
  47. package/src/routes/comment-router.d.ts +29 -6
  48. package/src/routes/comment-router.js +20 -10
  49. package/src/routes/doctor-router.d.ts +40 -0
  50. package/src/routes/doctor-router.js +83 -0
  51. package/src/routes/info-router.d.ts +1 -0
  52. package/src/routes/info-router.js +1 -1
  53. package/src/routes/label-router.d.ts +44 -6
  54. package/src/routes/label-router.js +27 -10
  55. package/src/routes/migrate-router.d.ts +1 -0
  56. package/src/routes/migrate-router.js +5 -7
  57. package/src/routes/project-router.d.ts +70 -11
  58. package/src/routes/project-router.js +130 -56
  59. package/src/routes/reindex-router.d.ts +1 -0
  60. package/src/routes/reindex-router.js +1 -1
  61. package/src/routes/relation-router.d.ts +3 -0
  62. package/src/routes/relation-router.js +9 -6
  63. package/src/routes/restore-router.d.ts +1 -0
  64. package/src/routes/restore-router.js +5 -6
  65. package/src/routes/router.js +5 -9
  66. package/src/routes/routes.d.ts +517 -35
  67. package/src/routes/routes.js +4 -0
  68. package/src/routes/skill-router.d.ts +76 -0
  69. package/src/routes/skill-router.js +179 -0
  70. package/src/routes/task-router.d.ts +264 -13
  71. package/src/routes/task-router.js +415 -93
  72. package/src/routes/whoami-router.d.ts +1 -0
  73. package/src/routes/whoami-router.js +1 -1
  74. package/src/skill-copies.d.ts +34 -0
  75. package/src/skill-copies.js +109 -0
  76. package/src/telemetry.d.ts +2 -2
  77. package/src/telemetry.js +8 -3
  78. package/src/text-edit.d.ts +2 -2
  79. package/src/text-input.d.ts +19 -1
  80. package/src/text-input.js +26 -5
  81. package/src/types.d.ts +4 -0
  82. package/src/types.js +6 -0
@@ -0,0 +1,28 @@
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
+ /** A status label and message per row, with the remedy on its own line below when there is one */
17
+ export function formatStatusRows(rows) {
18
+ return rows
19
+ .flatMap(({ status, message, remedy }) => {
20
+ const label = styleOutputText(STATUS_STYLES[status], status.padEnd(STATUS_WIDTH));
21
+ const line = `${label} ${message}`;
22
+ return remedy === null ? [line] : [line, `${REMEDY_INDENT}${remedy}`];
23
+ })
24
+ .join("\n");
25
+ }
26
+ export function formatDoctor(report) {
27
+ return formatStatusRows(report.checks);
28
+ }
@@ -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
  ];
@@ -0,0 +1,9 @@
1
+ import type { PresentedSkillStatus } from "../result-schemas.js";
2
+ import type { SkillCopies } from "../skill-copies.js";
3
+ /** What a skill file's frontmatter says about the CLI version it was reviewed for */
4
+ export declare function describeSkillCopy({ readable, reviewedVersion, }: {
5
+ readable: boolean;
6
+ reviewedVersion: string | null;
7
+ }): string;
8
+ export declare function presentSkillStatus({ bundledVersion, copies }: SkillCopies, bundledPath: string, workingFolder: string): PresentedSkillStatus;
9
+ export declare function formatSkillStatus({ bundled, copies }: PresentedSkillStatus): string;
@@ -0,0 +1,43 @@
1
+ import { formatStatusRows } from "./doctor-presentation.js";
2
+ import { skillInstallCommand } from "../skill-copies.js";
3
+ /** What a skill file's frontmatter says about the CLI version it was reviewed for */
4
+ export function describeSkillCopy({ readable, reviewedVersion, }) {
5
+ if (!readable) {
6
+ return "cannot be read";
7
+ }
8
+ return reviewedVersion === null
9
+ ? "names no reviewed CLI version"
10
+ : `was reviewed for CLI ${reviewedVersion}`;
11
+ }
12
+ export function presentSkillStatus({ bundledVersion, copies }, bundledPath, workingFolder) {
13
+ return {
14
+ bundled: { path: bundledPath, reviewedVersion: bundledVersion },
15
+ copies: copies.map(({ path, links, scope, reviewedVersion, matches, readable }) => ({
16
+ path,
17
+ links,
18
+ scope,
19
+ reviewedVersion,
20
+ matches,
21
+ readable,
22
+ remedy: matches ? null : `Update the skill with ${skillInstallCommand(scope, workingFolder)}`,
23
+ })),
24
+ };
25
+ }
26
+ export function formatSkillStatus({ bundled, copies }) {
27
+ const bundledLine = `The skill this CLI installs at ${bundled.path} ${describeSkillCopy({ readable: true, reviewedVersion: bundled.reviewedVersion })}`;
28
+ if (copies.length === 0) {
29
+ return [bundledLine, "No Zinn skill is installed for agents"].join("\n");
30
+ }
31
+ const rows = copies.map((copy) => {
32
+ const description = `${copy.path} ${describeSkillCopy(copy)}`;
33
+ const message = copy.links.length === 0
34
+ ? description
35
+ : `${description}, also reached through ${copy.links.join(", ")}`;
36
+ return {
37
+ status: copy.matches ? "ok" : "warning",
38
+ message,
39
+ remedy: copy.remedy,
40
+ };
41
+ });
42
+ return [bundledLine, formatStatusRows(rows)].join("\n");
43
+ }
@@ -1,11 +1,9 @@
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;
6
+ labelColorsByName: ReadonlyMap<string, string>;
9
7
  /** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
10
8
  activityIdPrefixes: Map<string, string>;
11
9
  }): string;
@@ -23,12 +23,14 @@ 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"
30
30
  : formatLocalTime(fields.due_at.value, { includesSeconds: true }), fields.due_at.attribution),
31
- field("Labels", labelNames.length === 0 ? "none" : formatLabelNames(labelNames), fields.labels.attribution),
31
+ field("Labels", labelNames.length === 0
32
+ ? "none"
33
+ : formatLabelNames(labelNames, options.labelColorsByName), fields.labels.attribution),
32
34
  field("Parent", fields.parent.value?.key ?? "none", fields.parent.attribution),
33
35
  ].join("\n")),
34
36
  ];
@@ -1,14 +1,28 @@
1
- import type { TaskWithKey } from "@zinn-dev/core";
1
+ import type { TaskSearchMatch, TaskWithKey } from "@zinn-dev/core";
2
2
  import type { RowCell } from "./row-layout.js";
3
3
  import type { PresentedTask, PresentedTaskDetail } from "../result-schemas.js";
4
4
  import type { ColumnBoard } from "./column-presentation.js";
5
5
  export declare function taskPriorityCell(priority: PresentedTask["priority"], showsFullPriority: boolean): RowCell;
6
- /** A task's label names on their own, colored as in a task row. */
7
- export declare function formatLabelNames(labelNames: Array<string>): string;
6
+ /**
7
+ * `PresentedTask` carries label names and IDs, without colors.
8
+ * Text output looks the colors up from the label definitions instead.
9
+ */
10
+ export declare function getLabelColorsByName(): Map<string, "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray">;
11
+ export declare function formatLabelNames(labelNames: Array<string>, labelColorsByName: ReadonlyMap<string, string>): string;
12
+ /** Shapes many tasks with one label read for all of them */
13
+ export declare function presentTasks(taskMatches: ReadonlyArray<TaskWithKey>, board?: ColumnBoard): Array<PresentedTask>;
8
14
  export declare function presentTask(taskMatch: TaskWithKey, board?: ColumnBoard): PresentedTask;
9
- export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
15
+ export declare function presentTaskSearchResults(taskMatches: TaskWithKey[], matchesByTaskId: ReadonlyMap<string, TaskSearchMatch[]> | undefined): Array<PresentedTask & {
16
+ matches?: TaskSearchMatch[];
17
+ }>;
18
+ export declare function formatTaskList(presentedTasks: Array<PresentedTask & {
19
+ matches?: TaskSearchMatch[];
20
+ }>, options?: {
10
21
  showsStatus?: boolean;
11
22
  showsFullPriority?: boolean;
12
23
  prefix?: string;
24
+ labelColorsByName?: ReadonlyMap<string, string>;
25
+ /** Shows an expired claim too, and when each claim's lease ends */
26
+ showsClaimDetail?: boolean;
13
27
  }): string;
14
28
  export declare function formatTaskTimestamps(task: Pick<PresentedTaskDetail, "created_at" | "updated_at">): string;
@@ -3,6 +3,8 @@ 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";
7
+ import { styleOutputText } from "./color.js";
6
8
  const EMPTY_CELL_MARKER = "-";
7
9
  const LABEL_NAME_SEPARATOR = ", ";
8
10
  export function taskPriorityCell(priority, showsFullPriority) {
@@ -16,61 +18,123 @@ export function taskPriorityCell(priority, showsFullPriority) {
16
18
  * `PresentedTask` carries label names and IDs, without colors.
17
19
  * Text output looks the colors up from the label definitions instead.
18
20
  */
19
- function getLabelColorsByName() {
21
+ export function getLabelColorsByName() {
20
22
  return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
21
23
  }
22
- function formatTaskLabelNames(labelNames, labelColorsByName) {
24
+ export function formatLabelNames(labelNames, labelColorsByName) {
23
25
  return labelNames
24
26
  .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
25
27
  .join(LABEL_NAME_SEPARATOR);
26
28
  }
27
- /** A task's label names on their own, colored as in a task row. */
28
- export function formatLabelNames(labelNames) {
29
- return formatTaskLabelNames(labelNames, getLabelColorsByName());
29
+ /** Shapes many tasks with one label read for all of them */
30
+ export function presentTasks(taskMatches, board = createColumnBoard()) {
31
+ const labelsByTaskId = task.label.getAllByTaskIds(taskMatches.map((taskMatch) => taskMatch.id));
32
+ return taskMatches.map((taskMatch) => {
33
+ const labels = labelsByTaskId.get(taskMatch.id);
34
+ const projectColumns = board(taskMatch.project_id);
35
+ const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === taskMatch.column_id);
36
+ const placement = columnPlacement(projectColumns, taskMatch.column_id);
37
+ return {
38
+ id: taskMatch.id,
39
+ key: taskMatch.key,
40
+ project_id: taskMatch.project_id,
41
+ status: taskMatch.archived_at == null ? "Active" : "Archived",
42
+ column: columnMatch.name,
43
+ column_id: taskMatch.column_id,
44
+ is_first: placement.is_first,
45
+ is_last: placement.is_last,
46
+ column_category: columnMatch.category ?? null,
47
+ title: taskMatch.title,
48
+ description: taskMatch.description,
49
+ priority: taskMatch.priority,
50
+ due_at: taskMatch.due_at ?? null,
51
+ labels: labels.map((label) => label.name),
52
+ label_ids: labels.map((label) => label.id),
53
+ created_at: taskMatch.created_at,
54
+ updated_at: taskMatch.updated_at,
55
+ claim: presentClaim(taskMatch.claim),
56
+ };
57
+ });
30
58
  }
31
- export function presentTask(taskMatch, board = createColumnBoard()) {
32
- const labels = task.label.getAll(taskMatch.key);
33
- const projectColumns = board(taskMatch.project_id);
34
- const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === taskMatch.column_id);
35
- const placement = columnPlacement(projectColumns, taskMatch.column_id);
59
+ export function presentTask(taskMatch, board) {
60
+ return presentTasks([taskMatch], board)[0];
61
+ }
62
+ export function presentTaskSearchResults(taskMatches, matchesByTaskId) {
63
+ const tasks = presentTasks(taskMatches);
64
+ if (matchesByTaskId === undefined) {
65
+ return tasks;
66
+ }
67
+ return tasks.map((task) => ({ ...task, matches: matchesByTaskId.get(task.id) }));
68
+ }
69
+ function presentClaim(claim) {
70
+ if (claim == null) {
71
+ return null;
72
+ }
36
73
  return {
37
- id: taskMatch.id,
38
- key: taskMatch.key,
39
- project_id: taskMatch.project_id,
40
- status: taskMatch.archived_at == null ? "Active" : "Archived",
41
- column: columnMatch.name,
42
- column_id: taskMatch.column_id,
43
- is_first: placement.is_first,
44
- is_last: placement.is_last,
45
- title: taskMatch.title,
46
- description: taskMatch.description,
47
- priority: taskMatch.priority,
48
- due_at: taskMatch.due_at ?? null,
49
- labels: labels.map((label) => label.name),
50
- label_ids: labels.map((label) => label.id),
51
- created_at: taskMatch.created_at,
52
- updated_at: taskMatch.updated_at,
74
+ state: claim.state,
75
+ actor_kind: claim.actor_kind,
76
+ actor_name: claim.actor_name,
77
+ actor_session_id: claim.actor_session_id,
78
+ actor_thread_id: claim.actor_thread_id,
79
+ claimed_at: claim.claimed_at,
80
+ renewed_at: claim.renewed_at,
81
+ worked_at: claim.worked_at,
82
+ lease_ms: claim.lease_ms,
83
+ expires_at: claim.expires_at,
53
84
  };
54
85
  }
86
+ /** Who holds the claim, and when its lease ends or ended when `showsExpiry` is set */
87
+ function formatClaim(claim, showsExpiry) {
88
+ const holder = formatActorLabel(claim);
89
+ if (!showsExpiry) {
90
+ return `Claimed by ${holder}`;
91
+ }
92
+ const expiresAt = formatLocalTime(claim.expires_at, { includesSeconds: true });
93
+ return claim.state === "live"
94
+ ? `Claimed by ${holder} until ${expiresAt}`
95
+ : `Claim by ${holder} expired at ${expiresAt}`;
96
+ }
97
+ const SEARCH_SOURCE_LABELS = { key: "Task key", title: "Title", description: "Description" };
98
+ function formatSearchExcerpt(match) {
99
+ const source = match.field === "comment" ? `Comment ${match.comment_key}` : SEARCH_SOURCE_LABELS[match.field];
100
+ // Render stored control characters without interpreting them as terminal commands
101
+ const points = Array.from(match.snippet.replace(/\p{Cc}/gu, "�"));
102
+ let snippet = "";
103
+ let offset = 0;
104
+ for (const [start, end] of match.highlights) {
105
+ snippet += points.slice(offset, start).join("");
106
+ snippet += styleOutputText(["bold", "yellow"], points.slice(start, end).join(""));
107
+ offset = end;
108
+ }
109
+ snippet += points.slice(offset).join("");
110
+ return `\n ${source}${formatCellSeparator()}${snippet}`;
111
+ }
55
112
  export function formatTaskList(presentedTasks, options = {}) {
56
- const labelColorsByName = getLabelColorsByName();
113
+ const labelColorsByName = options.labelColorsByName ?? getLabelColorsByName();
57
114
  return formatRows(presentedTasks.map((presentedTask) => {
58
115
  const statusCells = options.showsStatus
59
116
  ? [{ text: presentedTask.status }]
60
117
  : [];
61
118
  const hasLabels = presentedTask.labels.length > 0;
62
119
  // The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
63
- const labelNames = formatTaskLabelNames(presentedTask.labels, labelColorsByName);
120
+ const labelNames = formatLabelNames(presentedTask.labels, labelColorsByName);
64
121
  const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
65
122
  const deadline = presentedTask.due_at == null
66
123
  ? ""
67
124
  : `${formatCellSeparator()}Due ${formatLocalTime(presentedTask.due_at, { includesSeconds: true })}`;
125
+ const showsClaimDetail = options.showsClaimDetail ?? false;
126
+ const claim = presentedTask.claim;
127
+ const showsClaim = claim != null && (claim.state === "live" || showsClaimDetail);
128
+ const claimText = showsClaim
129
+ ? `${formatCellSeparator()}${formatClaim(claim, showsClaimDetail)}`
130
+ : "";
131
+ const excerpts = presentedTask.matches?.map(formatSearchExcerpt).join("") ?? "";
68
132
  return [
69
133
  { text: `${options.prefix ?? ""}${presentedTask.key}` },
70
134
  ...statusCells,
71
- columnNameCell(presentedTask.column, presentedTask),
135
+ columnNameCell(presentedTask.column, presentedTask.column_category),
72
136
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
73
- { text: `${presentedTask.title}${deadline}${labels}` },
137
+ { text: `${presentedTask.title}${deadline}${claimText}${labels}${excerpts}` },
74
138
  ];
75
139
  }));
76
140
  }