@zinn-dev/cli 0.45.0 → 0.47.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 (75) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/skills/zinn/SKILL.md +2 -2
  4. package/src/actor.d.ts +1 -1
  5. package/src/actor.js +4 -1
  6. package/src/capabilities-schema.d.ts +78 -0
  7. package/src/capabilities-schema.js +44 -0
  8. package/src/capabilities.d.ts +2 -0
  9. package/src/capabilities.js +2 -0
  10. package/src/column-hint.js +2 -9
  11. package/src/errors.d.ts +5 -0
  12. package/src/errors.js +19 -5
  13. package/src/input.d.ts +30 -0
  14. package/src/input.js +18 -0
  15. package/src/lib.d.ts +75 -6
  16. package/src/lib.js +121 -33
  17. package/src/presentation/activity-presentation.d.ts +2 -1
  18. package/src/presentation/activity-presentation.js +23 -6
  19. package/src/presentation/color.d.ts +12 -0
  20. package/src/presentation/color.js +12 -0
  21. package/src/presentation/doctor-presentation.d.ts +7 -1
  22. package/src/presentation/doctor-presentation.js +6 -2
  23. package/src/presentation/project-presentation.d.ts +4 -1
  24. package/src/presentation/project-presentation.js +18 -0
  25. package/src/presentation/relation-presentation.js +8 -20
  26. package/src/presentation/section.d.ts +7 -4
  27. package/src/presentation/section.js +21 -7
  28. package/src/presentation/skill-status-presentation.d.ts +9 -0
  29. package/src/presentation/skill-status-presentation.js +43 -0
  30. package/src/presentation/task-blame-presentation.d.ts +3 -1
  31. package/src/presentation/task-blame-presentation.js +7 -5
  32. package/src/presentation/task-presentation.d.ts +28 -5
  33. package/src/presentation/task-presentation.js +120 -42
  34. package/src/result-schemas.d.ts +230 -14
  35. package/src/result-schemas.js +52 -0
  36. package/src/routes/activity-router.d.ts +5 -3
  37. package/src/routes/activity-router.js +44 -33
  38. package/src/routes/backup-router.d.ts +1 -0
  39. package/src/routes/backup-router.js +6 -12
  40. package/src/routes/capabilities-router.d.ts +1 -0
  41. package/src/routes/capabilities-router.js +3 -10
  42. package/src/routes/comment-router.d.ts +7 -6
  43. package/src/routes/comment-router.js +18 -66
  44. package/src/routes/doctor-router.d.ts +1 -0
  45. package/src/routes/doctor-router.js +35 -62
  46. package/src/routes/info-router.d.ts +1 -0
  47. package/src/routes/info-router.js +3 -10
  48. package/src/routes/label-router.d.ts +5 -0
  49. package/src/routes/label-router.js +11 -48
  50. package/src/routes/migrate-router.d.ts +1 -0
  51. package/src/routes/migrate-router.js +7 -16
  52. package/src/routes/project-router.d.ts +10 -0
  53. package/src/routes/project-router.js +42 -121
  54. package/src/routes/reindex-router.d.ts +1 -0
  55. package/src/routes/reindex-router.js +3 -10
  56. package/src/routes/relation-router.d.ts +13 -4
  57. package/src/routes/relation-router.js +15 -23
  58. package/src/routes/restore-router.d.ts +1 -0
  59. package/src/routes/restore-router.js +5 -15
  60. package/src/routes/router.js +33 -12
  61. package/src/routes/routes.d.ts +142 -32
  62. package/src/routes/skill-router.d.ts +53 -2
  63. package/src/routes/skill-router.js +103 -35
  64. package/src/routes/task-router.d.ts +61 -28
  65. package/src/routes/task-router.js +224 -263
  66. package/src/routes/whoami-router.d.ts +1 -0
  67. package/src/routes/whoami-router.js +3 -10
  68. package/src/skill-copies.d.ts +34 -0
  69. package/src/skill-copies.js +109 -0
  70. package/src/telemetry.d.ts +2 -2
  71. package/src/telemetry.js +11 -7
  72. package/src/types.d.ts +9 -1
  73. package/src/types.js +6 -0
  74. package/src/views.d.ts +117 -0
  75. package/src/views.js +54 -0
package/src/lib.js CHANGED
@@ -3,10 +3,10 @@ import { once } from "node:events";
3
3
  import { parseArgs } from "node:util";
4
4
  import { createInterface } from "node:readline/promises";
5
5
  import { z } from "zod";
6
- import { assertWritable, InputValidationError } from "@zinn-dev/core";
6
+ import { assertWritable, getFailedUpgradeBackupPath, parseTaskKey, InputValidationError, } from "@zinn-dev/core";
7
7
  import { CliError, classifyFailure, recoveryHint } from "./errors.js";
8
8
  import { writeFailureLog } from "./failure-log.js";
9
- import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
9
+ import { isJsonFlag, isRouterFlag, optionAliasEntries, OPTION_SEPARATOR, parseArgsOptions, positionalWords, splitAtOptionSeparator, } from "./input.js";
10
10
  import { formatParserReasonPreview } from "./presentation/description-presentation.js";
11
11
  import { writeRunRecord } from "./telemetry.js";
12
12
  let outputMode = "text";
@@ -184,6 +184,11 @@ export function renderFailure(reason) {
184
184
  help: classified.help,
185
185
  message: failureMessage(reason, "Something went wrong"),
186
186
  };
187
+ const backupPath = getFailedUpgradeBackupPath(reason);
188
+ if (backupPath !== undefined && failure.details?.backupPath === undefined) {
189
+ failure.details = { ...failure.details, backupPath };
190
+ failure.message += `. The pre-upgrade backup was saved to ${backupPath}`;
191
+ }
187
192
  const logPath = LOGGED_ERROR_CODES.includes(failure.code)
188
193
  ? writeFailureLog(reason, runNotices)
189
194
  : undefined;
@@ -208,7 +213,10 @@ export function renderFailure(reason) {
208
213
  for (const message of pendingDiagnostics) {
209
214
  console.error(message);
210
215
  }
211
- console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
216
+ const omitTextHelp = reason instanceof CliError && reason.omitTextHelp;
217
+ console.error(failure.help == null || omitTextHelp
218
+ ? failure.message
219
+ : `${failure.message}\n\n${failure.help}`);
212
220
  if (logPath !== undefined) {
213
221
  console.error(`Full log: ${logPath}`);
214
222
  }
@@ -247,21 +255,77 @@ export function validatePositionals(positionals, form) {
247
255
  });
248
256
  }
249
257
  }
250
- export function validateUniqueOptions(tokens, options) {
258
+ export function validateTaskKey(taskKey) {
259
+ if (parseTaskKey(taskKey) === null) {
260
+ throw new CliError(`Invalid task key "${taskKey}". Expected format PROJECT-1`, "invalid_input", {
261
+ field: ["taskKey"],
262
+ });
263
+ }
264
+ }
265
+ /** `typedSpellings` maps an argument index to the flag the caller typed there, when it differs from the token name */
266
+ export function validateUniqueOptions(tokens, options, typedSpellings = new Map()) {
251
267
  const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
252
- const parsedArgs = new Set();
268
+ const firstSpellings = new Map();
253
269
  for (const token of tokens) {
254
270
  if (token.kind !== "option") {
255
271
  continue;
256
272
  }
273
+ const spelling = typedSpellings.get(token.index) ?? `--${token.name}`;
274
+ const firstSpelling = firstSpellings.get(token.name);
257
275
  const isRepeatable = repeatableOptions.includes(token.name);
258
- if (parsedArgs.has(token.name) && !isRepeatable) {
259
- quit(`Option "--${token.name}" can only be specified once`, undefined, {
260
- argument: `--${token.name}`,
261
- });
276
+ if (firstSpelling !== undefined && !isRepeatable) {
277
+ const message = firstSpelling === spelling
278
+ ? `Option "${spelling}" can only be specified once`
279
+ : `Options "${firstSpelling}" and "${spelling}" are the same option, which can only be specified once`;
280
+ quit(message, undefined, { argument: `--${token.name}` });
281
+ }
282
+ firstSpellings.set(token.name, spelling);
283
+ }
284
+ }
285
+ /** Parses command options and collects positionals before checking their form. */
286
+ export function parseOptionArgs(args, options) {
287
+ const parse = (words, spellings) => parseArgs({
288
+ args: words,
289
+ options: spellings,
290
+ allowPositionals: true,
291
+ strict: true,
292
+ tokens: true,
293
+ });
294
+ const aliases = optionAliasEntries(options);
295
+ let parsed = parse(args, parseArgsOptions(options, aliases));
296
+ let typedSpellings;
297
+ if (aliases.length > 0) {
298
+ const aliasNames = new Map(aliases);
299
+ let canonicalArgs;
300
+ typedSpellings = new Map();
301
+ for (const token of parsed.tokens) {
302
+ if (token.kind !== "option") {
303
+ continue;
304
+ }
305
+ const name = aliasNames.get(token.name);
306
+ if (name !== undefined) {
307
+ canonicalArgs ??= [...args];
308
+ typedSpellings.set(token.index, token.rawName);
309
+ canonicalArgs[token.index] = `--${name}${token.inlineValue ? `=${token.value}` : ""}`;
310
+ }
311
+ }
312
+ // Merge both spellings before checking duplicates and passing values to the command.
313
+ if (canonicalArgs !== undefined) {
314
+ parsed = parse(canonicalArgs, options);
262
315
  }
263
- parsedArgs.add(token.name);
264
316
  }
317
+ validateUniqueOptions(parsed.tokens, options, typedSpellings);
318
+ // TypeScript widens the result inside this generic function, but callers get the precise type.
319
+ return parsed;
320
+ }
321
+ /** Checks the positionals of a command with a single form. With several forms the caller selects one. */
322
+ export function parseCommandArgs(args, input) {
323
+ const parsed = parseOptionArgs(args, input.options);
324
+ const [onlyForm] = input.forms;
325
+ if (onlyForm !== undefined && input.forms.length === 1) {
326
+ validatePositionals(parsed.positionals, onlyForm);
327
+ }
328
+ return parsed;
265
329
  }
266
330
  /** Selects an order form after checking its required leading words. */
267
331
  export function validateOrderForms(positionals, forms) {
@@ -322,28 +386,48 @@ export function shellQuote(word) {
322
386
  return `'${word.replaceAll("'", `'\\''`)}'`;
323
387
  }
324
388
  /**
325
- * The message for `parseArgs` refusal of a value that begins with a dash, showing the user's
326
- * command with that value joined to its flag.
389
+ * The message for `parseArgs` refusal of values that begin with a dash, showing the user's
390
+ * command with every such value joined to its flag.
327
391
  * `null` for any other error
328
392
  */
329
- function dashValueMessage(error, args) {
330
- const isInvalidOptionValue = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE";
331
- const flag = isInvalidOptionValue ? DASH_VALUE_ERROR_PATTERN.exec(error.message)?.[1] : undefined;
332
- const flagIndex = args.findIndex((arg, index) => arg === flag && args[index + 1]?.startsWith("-"));
333
- if (flagIndex === -1) {
393
+ function dashValueMessage(error, args, options) {
394
+ const isDashValueError = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" &&
395
+ DASH_VALUE_ERROR_PATTERN.test(error.message);
396
+ if (!isDashValueError) {
397
+ return null;
398
+ }
399
+ // Without strict checks, parseArgs reads the word after a string flag as its value.
400
+ const { tokens } = parseArgs({
401
+ args,
402
+ options,
403
+ allowPositionals: true,
404
+ strict: false,
405
+ tokens: true,
406
+ });
407
+ const dashValues = tokens.flatMap((token) => token.kind === "option" && !token.inlineValue && token.value?.startsWith("-")
408
+ ? [{ index: token.index, flag: token.rawName, value: token.value }]
409
+ : []);
410
+ if (dashValues.length === 0) {
334
411
  return null;
335
412
  }
336
- const value = args[flagIndex + 1];
337
- const fixedCommand = [
338
- "zinn",
339
- ...args.slice(0, flagIndex).map(shellQuote),
340
- `${flag}=${shellQuote(value)}`,
341
- ...args.slice(flagIndex + 2).map(shellQuote),
342
- ].join(" ");
343
- const reason = `Option "${flag}" is followed by "${value}", which begins with a dash.`;
344
- return boundParserMessage(`${reason} If it is the value, join it to the flag with =: ${fixedCommand}`, {
413
+ const fixedWords = args.map(shellQuote);
414
+ for (const { index, flag, value } of dashValues) {
415
+ fixedWords[index] = `${flag}=${shellQuote(value)}`;
416
+ fixedWords[index + 1] = "";
417
+ }
418
+ const fixedCommand = ["zinn", ...fixedWords.filter((word) => word !== "")].join(" ");
419
+ const [first] = dashValues;
420
+ const reason = dashValues.length === 1
421
+ ? `Option "${first.flag}" is followed by "${first.value}", which begins with a dash.`
422
+ : `Options are followed by values that begin with a dash: ${dashValues
423
+ .map(({ flag, value }) => `${flag} "${value}"`)
424
+ .join(", ")}.`;
425
+ const fix = dashValues.length === 1
426
+ ? "If it is the value, join it to the flag with ="
427
+ : "If they are the values, join each to its flag with =";
428
+ return boundParserMessage(`${reason} ${fix}: ${fixedCommand}`, {
345
429
  reason,
346
- guidance: "Join the original value to its flag with =. Full command omitted because it is long.",
430
+ guidance: "Join each original value to its flag with =. Full command omitted because it is long.",
347
431
  });
348
432
  }
349
433
  // "Unknown option '--project'."
@@ -386,13 +470,15 @@ function unknownOptionMessage(message, args, suggestFor, route) {
386
470
  return { message: boundParserMessage(reason) };
387
471
  }
388
472
  const { optionWords, passthroughWords } = splitAtOptionSeparator(suggestion.args);
389
- const correctedArgs = [...optionWords, ...args.filter(isRouterFlag), ...passthroughWords];
473
+ const routerFlags = splitAtOptionSeparator(args).optionWords.filter(isRouterFlag);
474
+ const correctedArgs = [...optionWords, ...routerFlags, ...passthroughWords];
390
475
  return {
391
476
  message: boundParserMessage(`${reason}. Did you mean: ${formatCommand(correctedArgs)}`, {
392
- reason,
393
- guidance: "See usage for accepted arguments. Full command omitted because it is long.",
477
+ reason: `${reason}.`,
478
+ guidance: `${suggestion.guidance} Full command omitted because it is long.`,
394
479
  }),
395
480
  suggestedRoute: suggestion.route,
481
+ omitTextHelp: true,
396
482
  };
397
483
  }
398
484
  // Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
@@ -441,7 +527,7 @@ export function isParseArgsError(error) {
441
527
  * parseArgs names the flag only in its message text, which Node and Bun word the same.
442
528
  * `null` for any other error.
443
529
  */
444
- export function parseArgsFailure(error, args, suggestFor, route) {
530
+ export function parseArgsFailure(error, args, suggestFor, route, options) {
445
531
  if (!isParseArgsError(error)) {
446
532
  return null;
447
533
  }
@@ -449,9 +535,11 @@ export function parseArgsFailure(error, args, suggestFor, route) {
449
535
  const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(error.message)?.[1];
450
536
  if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
451
537
  const hint = unknownOptionMessage(error.message, args, suggestFor, route);
452
- return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
538
+ const failure = new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
539
+ failure.omitTextHelp = hint.omitTextHelp ?? false;
540
+ return failure;
453
541
  }
454
- const dashMessage = dashValueMessage(error, args);
542
+ const dashMessage = dashValueMessage(error, args, options);
455
543
  const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
456
544
  const reason = dashMessage !== null ? "dash_value" : isMissingValue ? "missing_argument" : undefined;
457
545
  return new CliError(dashMessage ?? boundParserMessage(error.message), "invalid_input", { argument, reason }, undefined, dashMessage === null ? undefined : route);
@@ -1,5 +1,6 @@
1
1
  import type { Activity, ActivityTaskIdentity, Actor } from "@zinn-dev/core";
2
2
  import type { PresentedActor } from "../result-schemas.js";
3
+ import type { TerminalProps } from "./color.js";
3
4
  type NavigationIdentity = {
4
5
  /** Undefined when the entity no longer exists and this event recorded no name for it. */
5
6
  name?: string;
@@ -31,5 +32,5 @@ export declare function formatActor(actor: PresentedActor): string;
31
32
  export declare function formatActorLabel(actor: Pick<PresentedActor, "actor_name" | "actor_kind">): string;
32
33
  export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
33
34
  showsDetails?: boolean;
34
- }): string;
35
+ } & TerminalProps): string;
35
36
  export {};
@@ -54,6 +54,7 @@ const ACTOR_DETAIL_FIELDS = [
54
54
  { key: "actor_model", label: "Model" },
55
55
  { key: "actor_effort", label: "Effort" },
56
56
  { key: "actor_client", label: "Client" },
57
+ { key: "actor_directory", label: "Directory" },
57
58
  ];
58
59
  const ACTION_LABELS = {
59
60
  create: "created",
@@ -482,6 +483,15 @@ function formatChangeSummary(entry, options = {}) {
482
483
  const removed = options.showsRemovedTasks === false ? "" : formatRemovedTasks(entry).join("; ");
483
484
  return [formatDescriptionPreview(summary), removed].filter((part) => part.length > 0).join("; ");
484
485
  }
486
+ function formatActivityAction(event) {
487
+ const previousExpiry = event.changes?.previous_expires_at;
488
+ const resumedExpiredClaim = event.action === "claim_heartbeat" &&
489
+ typeof previousExpiry === "number" &&
490
+ previousExpiry <= event.created_at;
491
+ return resumedExpiredClaim
492
+ ? "resumed expired claim"
493
+ : (ACTION_LABELS[event.action] ?? event.action);
494
+ }
485
495
  function formatActivityContent(entry) {
486
496
  const { event, navigation } = entry;
487
497
  const name = navigation.name ?? event.entity_id;
@@ -494,7 +504,7 @@ function formatActivityContent(entry) {
494
504
  : isMutableCurrentName
495
505
  ? " [current name]"
496
506
  : "";
497
- const action = ACTION_LABELS[event.action] ?? event.action;
507
+ const action = formatActivityAction(event);
498
508
  const summary = formatChangeSummary(entry, { showsRemovedTasks: false, omitsIdentity: true });
499
509
  const lines = [
500
510
  `${entityType}${shortName}${marker} · ${action}${summary === "-" ? "" : `: ${summary}`}`,
@@ -568,6 +578,7 @@ export function presentActor(actor) {
568
578
  actor_model: actor.model ?? null,
569
579
  actor_effort: actor.effort ?? null,
570
580
  actor_client: actor.client ?? null,
581
+ actor_directory: actor.directory ?? null,
571
582
  };
572
583
  }
573
584
  export function formatActor(actor) {
@@ -594,7 +605,11 @@ export function formatActivityList(entries, options = {}) {
594
605
  return [
595
606
  ...metadata,
596
607
  { text: formatNavigation(entry, { showsFullNames: true }) },
597
- { text: entry.event.action },
608
+ {
609
+ text: entry.event.action === "claim_heartbeat"
610
+ ? `${entry.event.action} (${formatActivityAction(entry.event)})`
611
+ : entry.event.action,
612
+ },
598
613
  { text: formatChangeSummary(entry) },
599
614
  ];
600
615
  });
@@ -604,12 +619,14 @@ export function formatActivityList(entries, options = {}) {
604
619
  return entries
605
620
  .map((entry, index) => [
606
621
  formatRows([rows[index]]),
607
- formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`),
622
+ formatSection("Entity", `${entry.event.entity_type} ${entry.event.entity_id}`, options),
608
623
  ...(entry.navigation.name === undefined
609
624
  ? []
610
- : [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
611
- formatSection("Actor", formatActor(entry.event)),
612
- formatSection("Changes", formatRecordedChanges(entry.event)),
625
+ : [
626
+ formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }), options),
627
+ ]),
628
+ formatSection("Actor", formatActor(entry.event), options),
629
+ formatSection("Changes", formatRecordedChanges(entry.event), options),
613
630
  ].join("\n\n"))
614
631
  .join("\n\n");
615
632
  }
@@ -7,3 +7,15 @@ export type StyleFormat = Parameters<typeof styleText>[0];
7
7
  */
8
8
  export declare function isColorEnabled(): boolean;
9
9
  export declare function styleOutputText(format: StyleFormat, text: string): string;
10
+ /** Whether stdout is a terminal and the width it reports, which routers pass to components as props */
11
+ export type TerminalProps = {
12
+ isTerminal?: boolean;
13
+ terminalWidth?: number;
14
+ };
15
+ export declare function readTerminalProps(): TerminalProps;
16
+ /**
17
+ * Decoration is output that carries no information, such as a heading rule.
18
+ * It prints only in a terminal, so piped output keeps content alone.
19
+ * Color settings do not affect it.
20
+ */
21
+ export declare function formatDecoration(text: string, { isTerminal }: TerminalProps): string;
@@ -19,3 +19,15 @@ export function styleOutputText(format, text) {
19
19
  }
20
20
  return styleText(format, text, { validateStream: false });
21
21
  }
22
+ export function readTerminalProps() {
23
+ const isTerminal = process.stdout.isTTY === true;
24
+ return { isTerminal, terminalWidth: isTerminal ? process.stdout.columns : undefined };
25
+ }
26
+ /**
27
+ * Decoration is output that carries no information, such as a heading rule.
28
+ * It prints only in a terminal, so piped output keeps content alone.
29
+ * Color settings do not affect it.
30
+ */
31
+ export function formatDecoration(text, { isTerminal = false }) {
32
+ return isTerminal ? text : "";
33
+ }
@@ -1,4 +1,10 @@
1
- import type { DoctorCheck } from "@zinn-dev/core";
1
+ import type { DoctorCheck, DoctorStatus } from "@zinn-dev/core";
2
2
  import type { PresentedDoctor } from "../result-schemas.js";
3
3
  export declare function presentDoctor(checks: ReadonlyArray<DoctorCheck>, agentSkill: DoctorCheck<"agent_skill">): PresentedDoctor;
4
+ /** A status label and message per row, with the remedy on its own line below when there is one */
5
+ export declare function formatStatusRows(rows: ReadonlyArray<{
6
+ status: DoctorStatus;
7
+ message: string;
8
+ remedy: string | null;
9
+ }>): string;
4
10
  export declare function formatDoctor(report: PresentedDoctor): string;
@@ -13,8 +13,9 @@ export function presentDoctor(checks, agentSkill) {
13
13
  checks: presented,
14
14
  };
15
15
  }
16
- export function formatDoctor(report) {
17
- return report.checks
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
18
19
  .flatMap(({ status, message, remedy }) => {
19
20
  const label = styleOutputText(STATUS_STYLES[status], status.padEnd(STATUS_WIDTH));
20
21
  const line = `${label} ${message}`;
@@ -22,3 +23,6 @@ export function formatDoctor(report) {
22
23
  })
23
24
  .join("\n");
24
25
  }
26
+ export function formatDoctor(report) {
27
+ return formatStatusRows(report.checks);
28
+ }
@@ -1,4 +1,5 @@
1
- import type { PresentedProject, PresentedProjectListEntry } from "../result-schemas.js";
1
+ import type { PresentedProject, PresentedProjectListEntry, PresentedProjectView } from "../result-schemas.js";
2
+ import type { TerminalProps } from "./color.js";
2
3
  type ProjectRow = PresentedProject & {
3
4
  taskCounts?: PresentedProjectListEntry["taskCounts"];
4
5
  };
@@ -8,4 +9,6 @@ type ProjectRowOptions = {
8
9
  };
9
10
  export declare function presentProject(projectMatch: PresentedProject): PresentedProject;
10
11
  export declare function formatProjectList(presentedProjects: Array<ProjectRow>, { showsDescriptionPreview, showsTaskCounts }?: ProjectRowOptions): string;
12
+ /** The project row followed by its description and column task count sections, each shown when it has content */
13
+ export declare function formatProjectDetail(presentedProject: PresentedProjectView, terminal?: TerminalProps): string;
11
14
  export {};
@@ -1,5 +1,7 @@
1
+ import { formatColumnList } from "./column-presentation.js";
1
2
  import { formatDescriptionPreview } from "./description-presentation.js";
2
3
  import { formatCellSeparator, formatRows } from "./row-layout.js";
4
+ import { formatSection } from "./section.js";
3
5
  export function presentProject(projectMatch) {
4
6
  return {
5
7
  id: projectMatch.id,
@@ -25,3 +27,19 @@ export function formatProjectList(presentedProjects, { showsDescriptionPreview =
25
27
  return [{ text: presented.key }, { text: `${presented.name}${description}` }];
26
28
  }));
27
29
  }
30
+ /** The project row followed by its description and column task count sections, each shown when it has content */
31
+ export function formatProjectDetail(presentedProject, terminal = {}) {
32
+ // The full description follows as its own section, so the row leaves out the preview.
33
+ const sections = [formatProjectList([presentedProject], { showsDescriptionPreview: false })];
34
+ if (presentedProject.description != null) {
35
+ sections.push(formatSection("Description", presentedProject.description, terminal));
36
+ }
37
+ if (presentedProject.columns.length > 0) {
38
+ const columnTaskCounts = formatColumnList(presentedProject.columns, {
39
+ showsTaskCounts: true,
40
+ archivedTaskCount: presentedProject.archivedTaskCount,
41
+ });
42
+ sections.push(formatSection("Columns", columnTaskCounts, terminal));
43
+ }
44
+ return sections.join("\n\n");
45
+ }
@@ -1,6 +1,8 @@
1
1
  import { relation } from "@zinn-dev/core";
2
+ import { views } from "../views.js";
2
3
  import { columnNameCell, columnPlacement, createColumnBoard } from "./column-presentation.js";
3
4
  import { formatCellSeparator, formatRows } from "./row-layout.js";
5
+ const relationWords = views.words.relations;
4
6
  export function presentRelationChange(entry, source, target) {
5
7
  return {
6
8
  id: entry.id,
@@ -45,27 +47,13 @@ export function presentRelations(taskMatch, board = createColumnBoard()) {
45
47
  });
46
48
  }
47
49
  function formatRelationLabel(entry) {
48
- const isOutgoing = entry.direction === "outgoing";
49
- let label = entry.type;
50
- switch (entry.type) {
51
- case "related": {
52
- label = "Related to";
53
- break;
54
- }
55
- case "dependency": {
56
- label = isOutgoing ? "Depends on" : "Depended on by";
57
- break;
58
- }
59
- case "subtask": {
60
- label = isOutgoing ? "Parent" : "Subtask";
61
- break;
62
- }
63
- case "duplicate": {
64
- label = isOutgoing ? "Duplicate of" : "Duplicated by";
65
- break;
66
- }
50
+ if (!Object.hasOwn(relationWords, entry.type)) {
51
+ return entry.type;
67
52
  }
68
- return label;
53
+ const words = relationWords[entry.type];
54
+ return typeof words === "string"
55
+ ? words
56
+ : words[entry.direction === "outgoing" ? "outgoing" : "incoming"];
69
57
  }
70
58
  export function formatRelationList(relations, options = {}) {
71
59
  return formatRows(relations.map((entry) => {
@@ -1,4 +1,7 @@
1
- /** A bold heading above its body, optionally preceded by a dim horizontal rule. */
2
- export declare function formatSection(heading: string, body: string, options?: {
3
- separatorWidth?: number;
4
- }): string;
1
+ import type { TerminalProps } from "./color.js";
2
+ /**
3
+ * A bold heading above its body.
4
+ * A top-level section passes `terminal`. In a terminal its heading sits in a dim rule that fills the line.
5
+ * Otherwise, and in a nested section, the heading ends with a colon.
6
+ */
7
+ export declare function formatSection(heading: string, body: string, terminal?: TerminalProps): string;
@@ -1,9 +1,23 @@
1
- import { styleOutputText } from "./color.js";
2
- /** A bold heading above its body, optionally preceded by a dim horizontal rule. */
3
- export function formatSection(heading, body, options = {}) {
4
- const section = `${styleOutputText("bold", `${heading}:`)}\n${body}`;
5
- if (options.separatorWidth === undefined) {
6
- return section;
1
+ import { formatDecoration, styleOutputText } from "./color.js";
2
+ import { displayWidth } from "./text-width.js";
3
+ // Heading line width when a terminal reports zero or no width.
4
+ const FALLBACK_TERMINAL_WIDTH = 60;
5
+ const HEADING_RULE_CHARACTER = "-";
6
+ /**
7
+ * A bold heading above its body.
8
+ * A top-level section passes `terminal`. In a terminal its heading sits in a dim rule that fills the line.
9
+ * Otherwise, and in a nested section, the heading ends with a colon.
10
+ */
11
+ export function formatSection(heading, body, terminal) {
12
+ return `${formatSectionHeading(heading, terminal)}\n${body}`;
13
+ }
14
+ function formatSectionHeading(heading, terminal) {
15
+ if (terminal?.isTerminal !== true) {
16
+ return styleOutputText("bold", `${heading}:`);
7
17
  }
8
- return `${styleOutputText("dim", "-".repeat(options.separatorWidth))}\n${section}`;
18
+ const hasTerminalWidth = terminal.terminalWidth !== undefined && terminal.terminalWidth > 0;
19
+ const lineWidth = hasTerminalWidth ? terminal.terminalWidth : FALLBACK_TERMINAL_WIDTH;
20
+ const ruleLength = lineWidth - displayWidth(heading) - " ".length;
21
+ const rule = ruleLength > 0 ? ` ${styleOutputText("dim", HEADING_RULE_CHARACTER.repeat(ruleLength))}` : "";
22
+ return `${styleOutputText("bold", heading)}${formatDecoration(rule, terminal)}`;
9
23
  }
@@ -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,8 +1,10 @@
1
1
  import type { PresentedRelation, PresentedTaskBlame } from "../result-schemas.js";
2
+ import type { TerminalProps } from "./color.js";
2
3
  export declare function formatTaskBlame(blame: PresentedTaskBlame, options: {
3
4
  relations: Array<PresentedRelation>;
4
5
  columnCategory: string | null;
5
6
  isArchived: boolean;
7
+ labelColorsByName: ReadonlyMap<string, string>;
6
8
  /** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
7
9
  activityIdPrefixes: Map<string, string>;
8
- }): string;
10
+ } & TerminalProps): string;
@@ -28,9 +28,11 @@ export function formatTaskBlame(blame, options) {
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
- ].join("\n")),
35
+ ].join("\n"), options),
34
36
  ];
35
37
  if (options.relations.length > 0) {
36
38
  const relationAttributions = new Map(blame.relations.map((entry) => [entry.id, entry.attribution]));
@@ -38,19 +40,19 @@ export function formatTaskBlame(blame, options) {
38
40
  trailingCell: (entry) => ({
39
41
  text: `[${reference(relationAttributions.get(entry.id) ?? null)}]`,
40
42
  }),
41
- })));
43
+ }), options));
42
44
  }
43
45
  if (blame.description.length > 0) {
44
46
  content.push(formatSection("Description", formatRows(blame.description.map((line) => [
45
47
  { text: String(line.line) },
46
48
  { text: `[${reference(line.attribution)}]` },
47
49
  { text: line.text },
48
- ]))));
50
+ ])), options));
49
51
  }
50
52
  if (events.size > 0) {
51
53
  content.push(formatSection("Attribution", [...events.values()]
52
54
  .map((event) => `${event.id}\n${formatLocalTime(event.created_at, { includesSeconds: true })}\n${formatActor(event)}`)
53
- .join("\n\n")));
55
+ .join("\n\n"), options));
54
56
  }
55
57
  return content.join("\n\n");
56
58
  }