@zinn-dev/cli 0.45.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 (59) 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 +4 -0
  7. package/src/errors.d.ts +4 -0
  8. package/src/errors.js +18 -5
  9. package/src/lib.d.ts +2 -1
  10. package/src/lib.js +52 -20
  11. package/src/presentation/activity-presentation.js +2 -0
  12. package/src/presentation/doctor-presentation.d.ts +7 -1
  13. package/src/presentation/doctor-presentation.js +6 -2
  14. package/src/presentation/skill-status-presentation.d.ts +9 -0
  15. package/src/presentation/skill-status-presentation.js +43 -0
  16. package/src/presentation/task-blame-presentation.d.ts +1 -0
  17. package/src/presentation/task-blame-presentation.js +3 -1
  18. package/src/presentation/task-presentation.d.ts +16 -4
  19. package/src/presentation/task-presentation.js +60 -33
  20. package/src/result-schemas.d.ts +137 -0
  21. package/src/result-schemas.js +51 -0
  22. package/src/routes/activity-router.d.ts +4 -2
  23. package/src/routes/activity-router.js +44 -17
  24. package/src/routes/backup-router.d.ts +1 -0
  25. package/src/routes/backup-router.js +4 -3
  26. package/src/routes/capabilities-router.d.ts +1 -0
  27. package/src/routes/capabilities-router.js +1 -1
  28. package/src/routes/comment-router.d.ts +5 -0
  29. package/src/routes/comment-router.js +5 -5
  30. package/src/routes/doctor-router.d.ts +1 -0
  31. package/src/routes/doctor-router.js +33 -53
  32. package/src/routes/info-router.d.ts +1 -0
  33. package/src/routes/info-router.js +1 -1
  34. package/src/routes/label-router.d.ts +5 -0
  35. package/src/routes/label-router.js +5 -5
  36. package/src/routes/migrate-router.d.ts +1 -0
  37. package/src/routes/migrate-router.js +5 -7
  38. package/src/routes/project-router.d.ts +10 -0
  39. package/src/routes/project-router.js +31 -24
  40. package/src/routes/reindex-router.d.ts +1 -0
  41. package/src/routes/reindex-router.js +1 -1
  42. package/src/routes/relation-router.d.ts +3 -0
  43. package/src/routes/relation-router.js +9 -6
  44. package/src/routes/restore-router.d.ts +1 -0
  45. package/src/routes/restore-router.js +3 -4
  46. package/src/routes/router.js +2 -2
  47. package/src/routes/routes.d.ts +113 -2
  48. package/src/routes/skill-router.d.ts +53 -2
  49. package/src/routes/skill-router.js +114 -31
  50. package/src/routes/task-router.d.ts +33 -0
  51. package/src/routes/task-router.js +182 -88
  52. package/src/routes/whoami-router.d.ts +1 -0
  53. package/src/routes/whoami-router.js +1 -1
  54. package/src/skill-copies.d.ts +34 -0
  55. package/src/skill-copies.js +109 -0
  56. package/src/telemetry.d.ts +2 -2
  57. package/src/telemetry.js +8 -3
  58. package/src/types.d.ts +4 -0
  59. package/src/types.js +6 -0
package/README.md CHANGED
@@ -11,7 +11,7 @@ The command-line interface for [Zinn](https://zinn.sh), local kanban and task ma
11
11
  npm i -g @zinn-dev/cli
12
12
  ```
13
13
 
14
- Requires [Node.js](https://nodejs.org/) 24.15.0 or newer. See [Install](https://zinn.sh/docs/installation) for package setup and upgrade instructions.
14
+ Requires [Node.js](https://nodejs.org/) 24.16.0 or newer. See [Install](https://zinn.sh/docs/installation) for package setup and upgrade instructions.
15
15
 
16
16
  ## Use
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zinn.sh",
@@ -35,11 +35,11 @@
35
35
  ],
36
36
  "type": "module",
37
37
  "engines": {
38
- "node": ">=24.15.0"
38
+ "node": ">=24.16.0"
39
39
  },
40
40
  "dependencies": {
41
41
  "zod": "4.6.7",
42
- "@zinn-dev/core": "0.34.0"
42
+ "@zinn-dev/core": "0.35.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "ajv": "8.20.0"
@@ -7,7 +7,7 @@ description: >-
7
7
  it, repository instructions mention it, zinn.local.json exists, or a Zinn task
8
8
  key is referenced.
9
9
  metadata:
10
- zinn-cli-reviewed-version: "0.45.0"
10
+ zinn-cli-reviewed-version: "0.46.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
@@ -40,7 +40,7 @@ When implementation and appropriate verification are complete, add a concise out
40
40
 
41
41
  Discover exact commands and flags with `zinn --help` and `zinn <command> --help`. Follow the installed help if it differs from this skill; the skill and CLI can be updated separately. Use `--json` when consuming results programmatically. Check command exit status: errors go to stderr, and empty stdout from a failed command is not an empty successful result.
42
42
 
43
- If the installed CLI lacks a command or option this skill uses, tell the user that this skill and their CLI differ, and that `zinn skill install` installs the skill that matches their CLI. Continue with what the installed help offers.
43
+ If the installed CLI lacks a command or option this skill uses, tell the user that this skill and their CLI differ, and that `zinn skill install` installs the skill that matches their CLI. For a copy inside the project, such as `.agents/skills/zinn`, they run `zinn skill install --project` in that project. Continue with what the installed help offers.
44
44
 
45
45
  `ZINN_AGENT`, `ZINN_MODEL`, and `ZINN_EFFORT` can declare the agent, model, and effort of the execution making a change when automatic detection or host integration does not provide them. Use only known values; leave unknown values unset.
46
46
 
package/src/actor.d.ts CHANGED
@@ -10,6 +10,6 @@ export declare function readExecutionIdentity(env: Env): {
10
10
  };
11
11
  /** Generic flags establish an unnamed agent only when no identifying marker follows. */
12
12
  export declare function detectAgent(env: Env): Actor | null;
13
- export declare function resolveActor(env: Env): Actor;
13
+ export declare function resolveActor(env: Env, directory?: string): Actor;
14
14
  export declare function currentActor(): Actor;
15
15
  export {};
package/src/actor.js CHANGED
@@ -100,7 +100,10 @@ function readGitConfig(key, env) {
100
100
  return null;
101
101
  }
102
102
  }
103
- export function resolveActor(env) {
103
+ export function resolveActor(env, directory = process.cwd()) {
104
+ return { ...resolveIdentity(env), directory };
105
+ }
106
+ function resolveIdentity(env) {
104
107
  const agent = detectAgent(env);
105
108
  if (agent != null) {
106
109
  return agent;
@@ -122,6 +122,10 @@ export declare const capabilitiesSchema: z.ZodObject<{
122
122
  restore: "restore";
123
123
  inspect: "inspect";
124
124
  }>;
125
+ external: z.ZodArray<z.ZodEnum<{
126
+ files: "files";
127
+ network: "network";
128
+ }>>;
125
129
  }, z.core.$strict>;
126
130
  confirmation: z.ZodObject<{
127
131
  kind: z.ZodEnum<{
package/src/errors.d.ts CHANGED
@@ -58,6 +58,7 @@ export declare const errorDetailsSchema: z.ZodObject<{
58
58
  unmarked_database: "unmarked_database";
59
59
  newer_database: "newer_database";
60
60
  older_database: "older_database";
61
+ migration_paused: "migration_paused";
61
62
  invalid_backup: "invalid_backup";
62
63
  busy: "busy";
63
64
  locked: "locked";
@@ -78,6 +79,7 @@ export declare const errorDetailsSchema: z.ZodObject<{
78
79
  databasePath: z.ZodOptional<z.ZodString>;
79
80
  backupDirectory: z.ZodOptional<z.ZodString>;
80
81
  backupPath: z.ZodOptional<z.ZodString>;
82
+ applied: z.ZodOptional<z.ZodLiteral<true>>;
81
83
  schemaVersion: z.ZodOptional<z.ZodNumber>;
82
84
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
83
85
  expectedColumn: z.ZodOptional<z.ZodString>;
@@ -155,6 +157,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
155
157
  unmarked_database: "unmarked_database";
156
158
  newer_database: "newer_database";
157
159
  older_database: "older_database";
160
+ migration_paused: "migration_paused";
158
161
  invalid_backup: "invalid_backup";
159
162
  busy: "busy";
160
163
  locked: "locked";
@@ -175,6 +178,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
175
178
  databasePath: z.ZodOptional<z.ZodString>;
176
179
  backupDirectory: z.ZodOptional<z.ZodString>;
177
180
  backupPath: z.ZodOptional<z.ZodString>;
181
+ applied: z.ZodOptional<z.ZodLiteral<true>>;
178
182
  schemaVersion: z.ZodOptional<z.ZodNumber>;
179
183
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
180
184
  expectedColumn: z.ZodOptional<z.ZodString>;
package/src/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, isSqliteErrorFamily, } from "@zinn-dev/core";
2
+ import { AutomaticUpgradePausedError, CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, isSqliteErrorFamily, } from "@zinn-dev/core";
3
3
  import { formatLocalTime } from "./presentation/time.js";
4
4
  export const errorCodeSchema = z.enum([
5
5
  "invalid_input",
@@ -60,6 +60,7 @@ export const errorDetailsSchema = z.strictObject({
60
60
  "unmarked_database",
61
61
  "newer_database",
62
62
  "older_database",
63
+ "migration_paused",
63
64
  "invalid_backup",
64
65
  "busy",
65
66
  "locked",
@@ -81,6 +82,7 @@ export const errorDetailsSchema = z.strictObject({
81
82
  databasePath: z.string().optional(),
82
83
  backupDirectory: z.string().optional(),
83
84
  backupPath: z.string().optional(),
85
+ applied: z.literal(true).optional(),
84
86
  schemaVersion: z.number().int().nonnegative().optional(),
85
87
  supportedSchemaVersion: z.number().int().nonnegative().optional(),
86
88
  expectedColumn: z.string().optional(),
@@ -138,6 +140,15 @@ export function recoveryHint(error) {
138
140
  if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
139
141
  return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
140
142
  }
143
+ if (error instanceof CoreError && error.facts.reason === "migration_paused") {
144
+ return { suffix: ". Run `zinn migrate` to retry.", suggestedRoute: ["migrate"] };
145
+ }
146
+ if (error instanceof AutomaticUpgradePausedError) {
147
+ return {
148
+ suffix: ". Run `zinn migrate` to retry after fixing the cause.",
149
+ suggestedRoute: ["migrate"],
150
+ };
151
+ }
141
152
  if (error instanceof TextEditMatchError && error.matchCount > 1) {
142
153
  return { suffix: " Use --all to replace every match." };
143
154
  }
@@ -236,6 +247,7 @@ function publicDetails(facts) {
236
247
  databasePath: facts.databasePath,
237
248
  backupDirectory: facts.backupDirectory,
238
249
  backupPath: facts.backupPath,
250
+ applied: facts.applied,
239
251
  schemaVersion: facts.schemaVersion,
240
252
  supportedSchemaVersion: facts.supportedSchemaVersion,
241
253
  expectedColumn: facts.expectedColumn,
@@ -245,7 +257,7 @@ function publicDetails(facts) {
245
257
  };
246
258
  return Object.fromEntries(Object.entries(details).filter(([, value]) => value !== undefined));
247
259
  }
248
- function nativeFailure(error) {
260
+ function nativeFailure(error, hasStorageContext) {
249
261
  const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
250
262
  if (code === undefined) {
251
263
  return undefined;
@@ -253,11 +265,12 @@ function nativeFailure(error) {
253
265
  const reason = error instanceof SqliteError
254
266
  ? sqliteReasons.find(([primary]) => isSqliteErrorFamily(error, primary))?.[1]
255
267
  : osReasons[code];
256
- if (reason === undefined) {
268
+ const isStorageCause = hasStorageContext && "syscall" in error && typeof error.syscall === "string";
269
+ if (reason === undefined && !isStorageCause) {
257
270
  return undefined;
258
271
  }
259
272
  return {
260
- reason,
273
+ ...(reason === undefined ? {} : { reason }),
261
274
  ...("path" in error && typeof error.path === "string" ? { path: error.path } : {}),
262
275
  cause: {
263
276
  code,
@@ -299,7 +312,7 @@ export function classifyFailure(error) {
299
312
  },
300
313
  };
301
314
  }
302
- const native = nativeFailure(current);
315
+ const native = nativeFailure(current, classified?.code === "storage");
303
316
  if (classified?.code === "storage" && current instanceof SqliteError) {
304
317
  classified.details = {
305
318
  ...native,
package/src/lib.d.ts CHANGED
@@ -56,6 +56,7 @@ export declare class UsageError extends CliError {
56
56
  * Optional words go last.
57
57
  */
58
58
  export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
59
+ export declare function validateTaskKey(taskKey: string): void;
59
60
  export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
60
61
  /** The choices a positional accepts; positionals without choices contribute never. */
61
62
  type PositionalChoices<Positional> = Positional extends {
@@ -104,5 +105,5 @@ export declare function isParseArgsError(error: any): boolean;
104
105
  * parseArgs names the flag only in its message text, which Node and Bun word the same.
105
106
  * `null` for any other error.
106
107
  */
107
- export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>): CliError | null;
108
+ export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>, options: ParseArgsOptionsConfig): CliError | null;
108
109
  export {};
package/src/lib.js CHANGED
@@ -3,7 +3,7 @@ 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
9
  import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
@@ -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;
@@ -247,6 +252,13 @@ export function validatePositionals(positionals, form) {
247
252
  });
248
253
  }
249
254
  }
255
+ export function validateTaskKey(taskKey) {
256
+ if (parseTaskKey(taskKey) === null) {
257
+ throw new CliError(`Invalid task key "${taskKey}". Expected format PROJECT-1`, "invalid_input", {
258
+ field: ["taskKey"],
259
+ });
260
+ }
261
+ }
250
262
  export function validateUniqueOptions(tokens, options) {
251
263
  const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
252
264
  const parsedArgs = new Set();
@@ -322,28 +334,48 @@ export function shellQuote(word) {
322
334
  return `'${word.replaceAll("'", `'\\''`)}'`;
323
335
  }
324
336
  /**
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.
337
+ * The message for `parseArgs` refusal of values that begin with a dash, showing the user's
338
+ * command with every such value joined to its flag.
327
339
  * `null` for any other error
328
340
  */
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) {
341
+ function dashValueMessage(error, args, options) {
342
+ const isDashValueError = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" &&
343
+ DASH_VALUE_ERROR_PATTERN.test(error.message);
344
+ if (!isDashValueError) {
345
+ return null;
346
+ }
347
+ // Without strict checks, parseArgs reads the word after a string flag as its value.
348
+ const { tokens } = parseArgs({
349
+ args,
350
+ options,
351
+ allowPositionals: true,
352
+ strict: false,
353
+ tokens: true,
354
+ });
355
+ const dashValues = tokens.flatMap((token) => token.kind === "option" && !token.inlineValue && token.value?.startsWith("-")
356
+ ? [{ index: token.index, flag: token.rawName, value: token.value }]
357
+ : []);
358
+ if (dashValues.length === 0) {
334
359
  return null;
335
360
  }
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}`, {
361
+ const fixedWords = args.map(shellQuote);
362
+ for (const { index, flag, value } of dashValues) {
363
+ fixedWords[index] = `${flag}=${shellQuote(value)}`;
364
+ fixedWords[index + 1] = "";
365
+ }
366
+ const fixedCommand = ["zinn", ...fixedWords.filter((word) => word !== "")].join(" ");
367
+ const [first] = dashValues;
368
+ const reason = dashValues.length === 1
369
+ ? `Option "${first.flag}" is followed by "${first.value}", which begins with a dash.`
370
+ : `Options are followed by values that begin with a dash: ${dashValues
371
+ .map(({ flag, value }) => `${flag} "${value}"`)
372
+ .join(", ")}.`;
373
+ const fix = dashValues.length === 1
374
+ ? "If it is the value, join it to the flag with ="
375
+ : "If they are the values, join each to its flag with =";
376
+ return boundParserMessage(`${reason} ${fix}: ${fixedCommand}`, {
345
377
  reason,
346
- guidance: "Join the original value to its flag with =. Full command omitted because it is long.",
378
+ guidance: "Join each original value to its flag with =. Full command omitted because it is long.",
347
379
  });
348
380
  }
349
381
  // "Unknown option '--project'."
@@ -441,7 +473,7 @@ export function isParseArgsError(error) {
441
473
  * parseArgs names the flag only in its message text, which Node and Bun word the same.
442
474
  * `null` for any other error.
443
475
  */
444
- export function parseArgsFailure(error, args, suggestFor, route) {
476
+ export function parseArgsFailure(error, args, suggestFor, route, options) {
445
477
  if (!isParseArgsError(error)) {
446
478
  return null;
447
479
  }
@@ -451,7 +483,7 @@ export function parseArgsFailure(error, args, suggestFor, route) {
451
483
  const hint = unknownOptionMessage(error.message, args, suggestFor, route);
452
484
  return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
453
485
  }
454
- const dashMessage = dashValueMessage(error, args);
486
+ const dashMessage = dashValueMessage(error, args, options);
455
487
  const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
456
488
  const reason = dashMessage !== null ? "dash_value" : isMissingValue ? "missing_argument" : undefined;
457
489
  return new CliError(dashMessage ?? boundParserMessage(error.message), "invalid_input", { argument, reason }, undefined, dashMessage === null ? undefined : route);
@@ -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",
@@ -568,6 +569,7 @@ export function presentActor(actor) {
568
569
  actor_model: actor.model ?? null,
569
570
  actor_effort: actor.effort ?? null,
570
571
  actor_client: actor.client ?? null,
572
+ actor_directory: actor.directory ?? null,
571
573
  };
572
574
  }
573
575
  export function formatActor(actor) {
@@ -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
+ }
@@ -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
+ }
@@ -3,6 +3,7 @@ export declare function formatTaskBlame(blame: PresentedTaskBlame, options: {
3
3
  relations: Array<PresentedRelation>;
4
4
  columnCategory: string | null;
5
5
  isArchived: boolean;
6
+ labelColorsByName: ReadonlyMap<string, string>;
6
7
  /** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
7
8
  activityIdPrefixes: Map<string, string>;
8
9
  }): string;
@@ -28,7 +28,9 @@ 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
35
  ].join("\n")),
34
36
  ];
@@ -1,15 +1,27 @@
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>;
13
25
  /** Shows an expired claim too, and when each claim's lease ends */
14
26
  showsClaimDetail?: boolean;
15
27
  }): string;
@@ -4,6 +4,7 @@ import { labelNameCell } from "./label-presentation.js";
4
4
  import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
5
5
  import { formatLocalTime } from "./time.js";
6
6
  import { formatActorLabel } from "./activity-presentation.js";
7
+ import { styleOutputText } from "./color.js";
7
8
  const EMPTY_CELL_MARKER = "-";
8
9
  const LABEL_NAME_SEPARATOR = ", ";
9
10
  export function taskPriorityCell(priority, showsFullPriority) {
@@ -17,43 +18,53 @@ export function taskPriorityCell(priority, showsFullPriority) {
17
18
  * `PresentedTask` carries label names and IDs, without colors.
18
19
  * Text output looks the colors up from the label definitions instead.
19
20
  */
20
- function getLabelColorsByName() {
21
+ export function getLabelColorsByName() {
21
22
  return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
22
23
  }
23
- function formatTaskLabelNames(labelNames, labelColorsByName) {
24
+ export function formatLabelNames(labelNames, labelColorsByName) {
24
25
  return labelNames
25
26
  .map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
26
27
  .join(LABEL_NAME_SEPARATOR);
27
28
  }
28
- /** A task's label names on their own, colored as in a task row. */
29
- export function formatLabelNames(labelNames) {
30
- 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
+ });
31
58
  }
32
- export function presentTask(taskMatch, board = createColumnBoard()) {
33
- const labels = task.label.getAll(taskMatch.key);
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
- };
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) }));
57
68
  }
58
69
  function presentClaim(claim) {
59
70
  if (claim == null) {
@@ -83,15 +94,30 @@ function formatClaim(claim, showsExpiry) {
83
94
  ? `Claimed by ${holder} until ${expiresAt}`
84
95
  : `Claim by ${holder} expired at ${expiresAt}`;
85
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
+ }
86
112
  export function formatTaskList(presentedTasks, options = {}) {
87
- const labelColorsByName = getLabelColorsByName();
113
+ const labelColorsByName = options.labelColorsByName ?? getLabelColorsByName();
88
114
  return formatRows(presentedTasks.map((presentedTask) => {
89
115
  const statusCells = options.showsStatus
90
116
  ? [{ text: presentedTask.status }]
91
117
  : [];
92
118
  const hasLabels = presentedTask.labels.length > 0;
93
119
  // The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
94
- const labelNames = formatTaskLabelNames(presentedTask.labels, labelColorsByName);
120
+ const labelNames = formatLabelNames(presentedTask.labels, labelColorsByName);
95
121
  const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
96
122
  const deadline = presentedTask.due_at == null
97
123
  ? ""
@@ -102,12 +128,13 @@ export function formatTaskList(presentedTasks, options = {}) {
102
128
  const claimText = showsClaim
103
129
  ? `${formatCellSeparator()}${formatClaim(claim, showsClaimDetail)}`
104
130
  : "";
131
+ const excerpts = presentedTask.matches?.map(formatSearchExcerpt).join("") ?? "";
105
132
  return [
106
133
  { text: `${options.prefix ?? ""}${presentedTask.key}` },
107
134
  ...statusCells,
108
135
  columnNameCell(presentedTask.column, presentedTask.column_category),
109
136
  taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
110
- { text: `${presentedTask.title}${deadline}${claimText}${labels}` },
137
+ { text: `${presentedTask.title}${deadline}${claimText}${labels}${excerpts}` },
111
138
  ];
112
139
  }));
113
140
  }