@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "A kanban workflow in the terminal. Experimental.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zinn.sh",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "zod": "4.6.7",
42
- "@zinn-dev/core": "0.33.0"
42
+ "@zinn-dev/core": "0.34.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.44.0"
10
+ zinn-cli-reviewed-version: "0.45.0"
11
11
  ---
12
12
 
13
13
  # Work with a Zinn board
@@ -17,8 +17,8 @@ Use the user's existing project and workflow. Repository and user instructions d
17
17
  ## Find the work
18
18
 
19
19
  1. Before substantial work, resolve the project. Use `zinn info --json` for the configured default project and selected database. If the project remains unidentified, use the user or repository's project setting and `zinn project list --json` to identify it. Ask when the project is ambiguous; do not create a project just to proceed. Result: one identified project in the intended store.
20
- 2. Read an explicitly referenced task with `zinn task view <task-key> --json`. Otherwise inspect the project's tasks and find an existing task matching the requested work, then fetch it with `zinn task view <task-key> --json` before changing it. A list or search result does not include the task's comments and relations. Read the full task even when its title and description already match. On resuming, refresh that task instead of creating another. If substantial authorized work has no task, create one describing its scope and completion criteria. Result: a matching task with its description, comments, and relations read.
21
- 3. Read the project's columns with `zinn project column list <project-key> --json`. Follow the project's workflow rather than assuming default column names. Check the task's current column before taking it: another agent may already be working on it. Move it to the working column before the first implementation edit. Ask when the workflow or ownership is unclear. Result: the task is visibly in progress before implementation begins.
20
+ 2. Read an explicitly referenced task with `zinn task view <task-key> --json`. Otherwise inspect the project's tasks and find an existing task matching the requested work. When asked to pick up the next work without a particular task, run `zinn task next <project-key> --json`. It returns a ready task from the project's todo columns, or its backlog columns when no todo task is ready, or `null` when none is ready. Fetch any task you choose with `zinn task view <task-key> --json` before changing it. A list, search or next result does not include the task's comments and relations. Read the full task even when its title and description already match. On resuming, refresh that task instead of creating another. If substantial authorized work has no task, create one describing its scope and completion criteria. Result: a matching task with its description, comments, and relations read.
21
+ 3. Read the project's columns with `zinn project column list <project-key> --json`. Each column's `category` says what it holds, whatever the column is called. Follow the project's workflow rather than assuming default column names. Check the task's current column before taking it: another agent may already be working on it. Before the first implementation edit, take the task by moving it to the working column, the one with the `in_progress` category, with `--from` naming the column you saw it in: `zinn task move <task-key> '<working column>' --from '<current column>' --json`. If that move fails with a `conflict` error, someone else moved the task first: leave it, and pick again. After the move succeeds, claim the task so others can see that the work is alive: `zinn task claim <task-key> --lease 30m --json`. If the claim fails with a `conflict` error whose reason is `claimed`, someone else holds the task, even though your move succeeded: leave it where it is, and pick again. Never pass `--force` unless the user tells you to. Every change you make to the task, such as a comment, an edit or a move, renews the claim. Before a long stretch without such a change, run `zinn task heartbeat <task-key>`. A heartbeat renews the lease, not the 24-hour limit since your last change to the task. If it fails, the claim is not yours to continue: `claimed` means someone else took it over, `not_claimed` means it is gone, and `claim_limit` means it expired 24 hours after your last change. Leave it, and pick again. A claim refuses nobody else's writes, so keep guarding your own: `--from` on moves, and the `--expect-*` flags of `task edit` for values you read before editing. Ask when the workflow or ownership is unclear. Result: the task is visibly in progress and claimed before implementation begins.
22
22
 
23
23
  ## Keep context useful
24
24
 
@@ -34,19 +34,17 @@ When follow-up work appears, search for an existing task before creating one. Re
34
34
 
35
35
  ## Finish or hand off
36
36
 
37
- When implementation and appropriate verification are complete, add a concise outcome comment with checks and any remaining limitations, move the task to the project's review column, and report its key with the reviewable result. Follow explicit user or repository completion rules when they differ. If work remains incomplete or blocked, record that state and the next step rather than moving it to review. Result: the board and final report agree about what is ready.
37
+ When implementation and appropriate verification are complete, add a concise outcome comment with checks and any remaining limitations, move the task to the project's review column, the one with the `review` category, and report its key with the reviewable result. Then release your claim with `zinn task release <task-key>`. Follow explicit user or repository completion rules when they differ. If work remains incomplete or blocked, record that state and the next step rather than moving it to review. When you give up on a task, release your claim too. Result: the board and final report agree about what is ready.
38
38
 
39
39
  ## Use the installed CLI
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 a command or option required by this skill is unavailable, or installed help or command results contradict these instructions, check both the CLI and this skill for drift. Do this once per session, and repeat only if either installation changes. Ordinary input, missing-item, permission, and database errors do not trigger this check.
44
-
45
- Compare `zinn --version` with the latest published `@zinn-dev/cli` version in the npm registry, and compare the skill file loaded by this session with its installation source, respecting any pinned revision. The unpinned source is [Zinn's workflow skill](https://github.com/yethranayeh/zinn/blob/main/packages/cli/skills/zinn/SKILL.md). Use read-only metadata and file reads. A newer release or changed skill is evidence of a difference, not proof that it caused the problem. Report relevant differences or checks you could not complete. If the intended operation remains unclear, ask before proceeding. Update either installation only when authorized; after updating the skill, reload it or use a fresh session.
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.
46
44
 
47
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.
48
46
 
49
- Checking and moving a task is not an atomic claim. Coordinate parallel work with the user or host; task coordination does not isolate a shared working tree.
47
+ `task next` skips tasks with a live claim, but agents asking at the same moment can still receive the same task. Only a move with `--from` takes it, and of several agents moving one task from the same column, one succeeds. To find abandoned work, run `zinn task next <project-key> --column '<working column>' --json`: it returns an in-progress task with no live claim. Claim it before continuing it. Coordinate parallel work with the user or host; task coordination does not isolate a shared working tree.
50
48
 
51
49
  For example, substitute the actual project, task, and observed column names:
52
50
 
@@ -57,7 +55,7 @@ zinn project list --json
57
55
  zinn task list APP --json
58
56
  zinn task view APP-1 --json
59
57
  zinn project column list APP --json
60
- zinn task move APP-1 'In Progress' --json
58
+ zinn task move APP-1 Doing --json
61
59
  zinn task comment create APP-1 --text 'Implementation verified; ready for review.' --json
62
60
  zinn task move APP-1 Review --json
63
61
  ```
@@ -145,9 +145,13 @@ export declare const capabilitiesSchema: z.ZodObject<{
145
145
  max: z.ZodNullable<z.ZodNumber>;
146
146
  }, z.core.$strict>], "kind">;
147
147
  schemaRef: z.ZodString;
148
- mode: z.ZodLiteral<"json">;
148
+ mode: z.ZodEnum<{
149
+ json: "json";
150
+ "json-lines": "json-lines";
151
+ }>;
149
152
  stream: z.ZodLiteral<"stdout">;
150
153
  exitCode: z.ZodLiteral<0>;
154
+ findingsExitCode: z.ZodOptional<z.ZodLiteral<1>>;
151
155
  }, z.core.$strict>>>;
152
156
  }, z.core.$strict>>;
153
157
  error: z.ZodObject<{
@@ -1,7 +1,7 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { column, columnCreateSchema, parseTaskKey } from "@zinn-dev/core";
3
3
  import { classifyFailure } from "./errors.js";
4
- import { routerOptions, getOptionInputs, isAllowLegacyReadFlag, isRouterFlag, splitAtOptionSeparator, violatesConstraint, } from "./input.js";
4
+ import { routerOptions, getOptionInputs, isRouterFlag, splitAtOptionSeparator, violatesConstraint, } from "./input.js";
5
5
  import { formatCommand, UsageError, validateUniqueOptions } from "./lib.js";
6
6
  import { chooseProjectKey } from "./project.js";
7
7
  function isEligible(error, command) {
@@ -76,7 +76,6 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
76
76
  }
77
77
  }
78
78
  const args = rawArgs.slice(argumentStart);
79
- const { optionWords: optionArgs } = splitAtOptionSeparator(rawArgs);
80
79
  const options = { ...route.input.options, ...routerOptions };
81
80
  const { tokens, values } = parseArgs({
82
81
  args,
@@ -112,7 +111,6 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
112
111
  }
113
112
  const context = column.inspect({
114
113
  taskKeys: isMove ? words.map((word) => word.value) : [],
115
- allowsLegacyRead: optionArgs.some(isAllowLegacyReadFlag),
116
114
  });
117
115
  if (context === null) {
118
116
  return undefined;
package/src/database.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { DatabaseFacts, LockWait, OpenPolicy } from "@zinn-dev/core";
1
+ import type { LockWait, OpenPolicy } from "@zinn-dev/core";
2
2
  /** Says once on stderr that the command waits for another process to finish with the database. */
3
3
  export declare function reportLockWait({ budgetMs }: LockWait): void;
4
- export declare function reportLegacyRead({ databasePath }: DatabaseFacts): void;
5
4
  /** How the CLI asks core to open the database. */
6
5
  export declare function getCliOpenPolicy(): OpenPolicy;
package/src/database.js CHANGED
@@ -1,14 +1,11 @@
1
1
  import packageJson from "../package.json" with { type: "json" };
2
- import { diagnostic, isLegacyReadAllowed } from "./lib.js";
2
+ import { diagnostic } from "./lib.js";
3
3
  import { RELEASE_MODE } from "./release-identity.js";
4
4
  const MS_PER_SECOND = 1000;
5
5
  /** Says once on stderr that the command waits for another process to finish with the database. */
6
6
  export function reportLockWait({ budgetMs }) {
7
7
  diagnostic(`Another process is using the database. Waiting up to ${budgetMs / MS_PER_SECOND} seconds for it to finish.`);
8
8
  }
9
- export function reportLegacyRead({ databasePath }) {
10
- diagnostic(`Warning: the database at ${databasePath} has no schema version. Reads are best effort and may fail or omit data.`);
11
- }
12
9
  /** How the CLI asks core to open the database. */
13
10
  export function getCliOpenPolicy() {
14
11
  return {
@@ -17,8 +14,6 @@ export function getCliOpenPolicy() {
17
14
  // The script the CLI runs from; the runtime itself when there is none.
18
15
  executable: process.argv[1] ?? process.execPath,
19
16
  release: RELEASE_MODE,
20
- allowsLegacyRead: isLegacyReadAllowed(),
21
17
  onWait: reportLockWait,
22
- onLegacyRead: reportLegacyRead,
23
18
  };
24
19
  }
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ export declare const durationPattern = "^\\d+[mh]$";
3
+ export declare const durationInputSchema: z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>;
4
+ /** Spells milliseconds the way --lease accepts them, in whole hours when they divide evenly */
5
+ export declare function formatDurationInput(milliseconds: number): string;
6
+ /** Turns a duration such as 30m or 2h into milliseconds. Core checks the range */
7
+ export declare function parseDurationInput(value: string | undefined, argument: string): number | undefined;
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ import { quit } from "./lib.js";
3
+ const MS_PER_MINUTE = 60_000;
4
+ const MS_PER_HOUR = 3_600_000;
5
+ const MS_PER_UNIT = { m: MS_PER_MINUTE, h: MS_PER_HOUR };
6
+ export const durationPattern = "^\\d+[mh]$";
7
+ const durationInputMessage = "Use a whole number of minutes or hours, such as 30m or 2h";
8
+ export const durationInputSchema = z
9
+ .string()
10
+ .regex(new RegExp(durationPattern), durationInputMessage)
11
+ .transform((value) => {
12
+ const unit = value.at(-1);
13
+ return Number(value.slice(0, -1)) * MS_PER_UNIT[unit];
14
+ });
15
+ /** Spells milliseconds the way --lease accepts them, in whole hours when they divide evenly */
16
+ export function formatDurationInput(milliseconds) {
17
+ return milliseconds % MS_PER_HOUR === 0
18
+ ? `${milliseconds / MS_PER_HOUR}h`
19
+ : `${milliseconds / MS_PER_MINUTE}m`;
20
+ }
21
+ /** Turns a duration such as 30m or 2h into milliseconds. Core checks the range */
22
+ export function parseDurationInput(value, argument) {
23
+ if (value === undefined) {
24
+ return undefined;
25
+ }
26
+ const parsed = durationInputSchema.safeParse(value);
27
+ if (!parsed.success) {
28
+ quit(parsed.error.issues[0].message, undefined, { argument });
29
+ }
30
+ return parsed.data;
31
+ }
package/src/errors.d.ts CHANGED
@@ -42,6 +42,8 @@ export declare const errorDetailsSchema: z.ZodObject<{
42
42
  already_exists: "already_exists";
43
43
  parent_exists: "parent_exists";
44
44
  relation_changed: "relation_changed";
45
+ column_changed: "column_changed";
46
+ value_changed: "value_changed";
45
47
  cycle: "cycle";
46
48
  different_project: "different_project";
47
49
  different_column: "different_column";
@@ -65,6 +67,9 @@ export declare const errorDetailsSchema: z.ZodObject<{
65
67
  corrupt: "corrupt";
66
68
  not_database: "not_database";
67
69
  missing_index: "missing_index";
70
+ claimed: "claimed";
71
+ not_claimed: "not_claimed";
72
+ claim_limit: "claim_limit";
68
73
  io: "io";
69
74
  }>>;
70
75
  matchCount: z.ZodOptional<z.ZodNumber>;
@@ -75,7 +80,12 @@ export declare const errorDetailsSchema: z.ZodObject<{
75
80
  backupPath: z.ZodOptional<z.ZodString>;
76
81
  schemaVersion: z.ZodOptional<z.ZodNumber>;
77
82
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
83
+ expectedColumn: z.ZodOptional<z.ZodString>;
84
+ actualColumn: z.ZodOptional<z.ZodString>;
85
+ changedFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ claimExpiresAt: z.ZodOptional<z.ZodNumber>;
78
87
  logPath: z.ZodOptional<z.ZodString>;
88
+ exitCode: z.ZodOptional<z.ZodNumber>;
79
89
  cause: z.ZodOptional<z.ZodObject<{
80
90
  code: z.ZodOptional<z.ZodString>;
81
91
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -129,6 +139,8 @@ export declare const errorDocumentSchema: z.ZodObject<{
129
139
  already_exists: "already_exists";
130
140
  parent_exists: "parent_exists";
131
141
  relation_changed: "relation_changed";
142
+ column_changed: "column_changed";
143
+ value_changed: "value_changed";
132
144
  cycle: "cycle";
133
145
  different_project: "different_project";
134
146
  different_column: "different_column";
@@ -152,6 +164,9 @@ export declare const errorDocumentSchema: z.ZodObject<{
152
164
  corrupt: "corrupt";
153
165
  not_database: "not_database";
154
166
  missing_index: "missing_index";
167
+ claimed: "claimed";
168
+ not_claimed: "not_claimed";
169
+ claim_limit: "claim_limit";
155
170
  io: "io";
156
171
  }>>;
157
172
  matchCount: z.ZodOptional<z.ZodNumber>;
@@ -162,7 +177,12 @@ export declare const errorDocumentSchema: z.ZodObject<{
162
177
  backupPath: z.ZodOptional<z.ZodString>;
163
178
  schemaVersion: z.ZodOptional<z.ZodNumber>;
164
179
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
180
+ expectedColumn: z.ZodOptional<z.ZodString>;
181
+ actualColumn: z.ZodOptional<z.ZodString>;
182
+ changedFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
183
+ claimExpiresAt: z.ZodOptional<z.ZodNumber>;
165
184
  logPath: z.ZodOptional<z.ZodString>;
185
+ exitCode: z.ZodOptional<z.ZodNumber>;
166
186
  cause: z.ZodOptional<z.ZodObject<{
167
187
  code: z.ZodOptional<z.ZodString>;
168
188
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -184,6 +204,8 @@ export declare class CliError extends Error {
184
204
  readonly details?: ErrorDetails | undefined;
185
205
  help?: string | undefined;
186
206
  readonly suggestedRoute?: Array<string> | undefined;
207
+ /** The process exit code, when it is not the usual 1 */
208
+ exitCode?: number;
187
209
  constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined, cause?: unknown);
188
210
  }
189
211
  /** Recovery text and its single suggested route, when one is identified. */
package/src/errors.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, UnmarkedDatabaseError, isSqliteErrorFamily, } from "@zinn-dev/core";
2
+ import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError, isSqliteErrorFamily, } from "@zinn-dev/core";
3
+ import { formatLocalTime } from "./presentation/time.js";
3
4
  export const errorCodeSchema = z.enum([
4
5
  "invalid_input",
5
6
  "not_found",
@@ -43,6 +44,8 @@ export const errorDetailsSchema = z.strictObject({
43
44
  "archived",
44
45
  "parent_exists",
45
46
  "relation_changed",
47
+ "column_changed",
48
+ "value_changed",
46
49
  "cycle",
47
50
  "different_project",
48
51
  "different_column",
@@ -66,6 +69,9 @@ export const errorDetailsSchema = z.strictObject({
66
69
  "corrupt",
67
70
  "not_database",
68
71
  "missing_index",
72
+ "claimed",
73
+ "not_claimed",
74
+ "claim_limit",
69
75
  "io",
70
76
  ])
71
77
  .optional(),
@@ -77,7 +83,16 @@ export const errorDetailsSchema = z.strictObject({
77
83
  backupPath: z.string().optional(),
78
84
  schemaVersion: z.number().int().nonnegative().optional(),
79
85
  supportedSchemaVersion: z.number().int().nonnegative().optional(),
86
+ expectedColumn: z.string().optional(),
87
+ actualColumn: z.string().optional(),
88
+ changedFields: z.array(z.string()).optional(),
89
+ claimExpiresAt: z
90
+ .number()
91
+ .int()
92
+ .describe("When the task's current claim expires, in epoch milliseconds.")
93
+ .optional(),
80
94
  logPath: z.string().optional(),
95
+ exitCode: z.number().int().optional(),
81
96
  cause: z
82
97
  .strictObject({
83
98
  code: z.string().optional(),
@@ -101,6 +116,8 @@ export class CliError extends Error {
101
116
  details;
102
117
  help;
103
118
  suggestedRoute;
119
+ /** The process exit code, when it is not the usual 1 */
120
+ exitCode;
104
121
  constructor(message, code = "invalid_input", details, help, suggestedRoute, cause) {
105
122
  super(message, cause === undefined ? undefined : { cause });
106
123
  this.code = code;
@@ -121,9 +138,6 @@ export function recoveryHint(error) {
121
138
  if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
122
139
  return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
123
140
  }
124
- if (error instanceof UnmarkedDatabaseError) {
125
- return { suffix: ". Add --allow-legacy-read to read it anyway." };
126
- }
127
141
  if (error instanceof TextEditMatchError && error.matchCount > 1) {
128
142
  return { suffix: " Use --all to replace every match." };
129
143
  }
@@ -135,10 +149,17 @@ export function recoveryHint(error) {
135
149
  }
136
150
  if (error instanceof CoreError && error.facts.reason === "no_columns") {
137
151
  return {
138
- suffix: `. Add a column with zinn project column create ${error.facts.key} <name>.`,
152
+ suffix: `. Add a column with zinn project column create ${error.facts.key} <name> --category <category>.`,
139
153
  suggestedRoute: ["project", "column", "create"],
140
154
  };
141
155
  }
156
+ if (error instanceof CoreError &&
157
+ error.facts.reason === "claimed" &&
158
+ error.facts.claimExpiresAt !== undefined) {
159
+ const expiresAt = error.facts.claimExpiresAt;
160
+ const timing = Date.now() < expiresAt ? "until" : "whose claim expired at";
161
+ return { suffix: `, ${timing} ${formatLocalTime(expiresAt, { includesSeconds: true })}` };
162
+ }
142
163
  if (error instanceof CoreError && error.facts.reason === "has_tasks") {
143
164
  return {
144
165
  suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
@@ -217,6 +238,10 @@ function publicDetails(facts) {
217
238
  backupPath: facts.backupPath,
218
239
  schemaVersion: facts.schemaVersion,
219
240
  supportedSchemaVersion: facts.supportedSchemaVersion,
241
+ expectedColumn: facts.expectedColumn,
242
+ actualColumn: facts.actualColumn,
243
+ changedFields: facts.changedFields,
244
+ claimExpiresAt: facts.claimExpiresAt,
220
245
  };
221
246
  return Object.fromEntries(Object.entries(details).filter(([, value]) => value !== undefined));
222
247
  }
@@ -0,0 +1,48 @@
1
+ import type { InputOption } from "./input.js";
2
+ import { textFileOption } from "./text-input.js";
3
+ declare const expectTextOption: {
4
+ readonly type: "string";
5
+ readonly value: {
6
+ readonly kind: "text";
7
+ readonly name: "text";
8
+ };
9
+ };
10
+ /** A guarded field whose flag value is parsed on its own, such as a `title` or a `priority` */
11
+ type ValueGuard = {
12
+ field: string;
13
+ option: InputOption;
14
+ parse?: (value: string | undefined, flag: string) => unknown;
15
+ };
16
+ /** A guarded field whose text comes inline or from a file, like the text flag it guards */
17
+ type TextGuard = {
18
+ field: string;
19
+ text: true;
20
+ };
21
+ type Guards = Record<string, ValueGuard | TextGuard>;
22
+ type ExpectOptions<G extends Guards> = {
23
+ [Name in keyof G & string as `expect-${Name}`]: G[Name] extends ValueGuard ? G[Name]["option"] : typeof expectTextOption;
24
+ } & {
25
+ [Name in keyof G & string as G[Name] extends TextGuard ? `expect-${Name}-file` : never]: typeof textFileOption;
26
+ };
27
+ /** Parsed flag values of a command. Every expect flag holds one string. */
28
+ type ParsedValues = Record<string, unknown>;
29
+ /**
30
+ * Declares `--expect-<name>` flags, which give the stored values an edit expects to replace.
31
+ * Each key is a flag name, and its guard names the core field the flag checks.
32
+ */
33
+ export declare function expectedValueFlags<const G extends Guards>(guards: G): {
34
+ options: ExpectOptions<G>;
35
+ constraints: {
36
+ readonly kind: "exclusive";
37
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
38
+ }[];
39
+ textFlags: ("--description" | "--text" | "--expect-description" | "--expect-text")[];
40
+ help: string;
41
+ /** Parses every flag that needs no file or stdin, and refuses inline text together with its file flag. */
42
+ parseValues(values: ParsedValues): {
43
+ [k: string]: unknown;
44
+ };
45
+ /** Reads the expected text values, inline or from their file flags. */
46
+ resolveText(values: ParsedValues): Promise<Record<string, string | undefined>>;
47
+ };
48
+ export {};
@@ -0,0 +1,60 @@
1
+ import { checkSingleTextSource, resolveTextInput, textFileHelp, textFileOption, textOptionNames, textSourceConstraint, } from "./text-input.js";
2
+ const expectTextOption = { type: "string", value: { kind: "text", name: "text" } };
3
+ const stringValue = (values, name) => values[name];
4
+ const isTextGuard = (guard) => "text" in guard;
5
+ function joinFlags(flags) {
6
+ return flags.length < 2 ? flags.join("") : `${flags.slice(0, -1).join(", ")} and ${flags.at(-1)}`;
7
+ }
8
+ /**
9
+ * Declares `--expect-<name>` flags, which give the stored values an edit expects to replace.
10
+ * Each key is a flag name, and its guard names the core field the flag checks.
11
+ */
12
+ export function expectedValueFlags(guards) {
13
+ const entries = Object.entries(guards);
14
+ const valueGuards = entries.filter((entry) => !isTextGuard(entry[1]));
15
+ const textGuards = entries.filter((entry) => isTextGuard(entry[1]));
16
+ const textFlags = textGuards.map(([name]) => `--expect-${name}`);
17
+ const options = {};
18
+ for (const [name, guard] of entries) {
19
+ if (isTextGuard(guard)) {
20
+ options[`expect-${name}`] = expectTextOption;
21
+ options[`expect-${name}-file`] = textFileOption;
22
+ }
23
+ else {
24
+ options[`expect-${name}`] = guard.option;
25
+ }
26
+ }
27
+ const flagNames = entries.map(([name]) => `--expect-${name}`);
28
+ const guardSentence = flagNames.length === 1
29
+ ? `${flagNames[0]} gives the value read before the edit, spelled as for the edit flag. If it no longer matches the stored value, the edit fails and changes nothing.`
30
+ : `${joinFlags(flagNames)} give the values read before the edit, spelled as for the edit flags. If one of them no longer matches the stored value, the edit fails and changes nothing.`;
31
+ const help = [guardSentence, ...textFlags.map(textFileHelp)].join("\n");
32
+ return {
33
+ options: options,
34
+ constraints: textFlags.map(textSourceConstraint),
35
+ textFlags,
36
+ help,
37
+ /** Parses every flag that needs no file or stdin, and refuses inline text together with its file flag. */
38
+ parseValues(values) {
39
+ for (const textFlag of textFlags) {
40
+ const { text, file } = textOptionNames(textFlag);
41
+ checkSingleTextSource(stringValue(values, text), stringValue(values, file), textFlag);
42
+ }
43
+ return Object.fromEntries(valueGuards.map(([name, guard]) => {
44
+ const flag = `expect-${name}`;
45
+ const value = stringValue(values, flag);
46
+ return [guard.field, guard.parse === undefined ? value : guard.parse(value, `--${flag}`)];
47
+ }));
48
+ },
49
+ /** Reads the expected text values, inline or from their file flags. */
50
+ async resolveText(values) {
51
+ const resolved = {};
52
+ for (const [index, [, guard]] of textGuards.entries()) {
53
+ const textFlag = textFlags[index];
54
+ const { text, file } = textOptionNames(textFlag);
55
+ resolved[guard.field] = await resolveTextInput(stringValue(values, text), stringValue(values, file), textFlag);
56
+ }
57
+ return resolved;
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,9 @@
1
+ /** How often a following command looks for new commits. GNU `tail -f` sleeps one second between checks by default. */
2
+ export declare const FOLLOW_POLL_INTERVAL_MS = 1000;
3
+ /**
4
+ * Calls poll every interval until the command is stopped.
5
+ * Resolves when the reader of stdout has closed it, which a write reports.
6
+ * Rejects with what poll throws, which is how poll ends the command.
7
+ * An interrupt ends the process by its signal, as it ends a command that handles no signal.
8
+ */
9
+ export declare function followUntilStopped(poll: (signal: AbortSignal) => void | Promise<void>): Promise<void>;
package/src/follow.js ADDED
@@ -0,0 +1,58 @@
1
+ import { finishRun } from "./lib.js";
2
+ /** How often a following command looks for new commits. GNU `tail -f` sleeps one second between checks by default. */
3
+ export const FOLLOW_POLL_INTERVAL_MS = 1_000;
4
+ const INTERRUPT_SIGNAL = "SIGINT";
5
+ const CLOSED_PIPE_CODE = "EPIPE";
6
+ /**
7
+ * Calls poll every interval until the command is stopped.
8
+ * Resolves when the reader of stdout has closed it, which a write reports.
9
+ * Rejects with what poll throws, which is how poll ends the command.
10
+ * An interrupt ends the process by its signal, as it ends a command that handles no signal.
11
+ */
12
+ export function followUntilStopped(poll) {
13
+ return new Promise((resolve, reject) => {
14
+ const stopped = new AbortController();
15
+ let timer;
16
+ function stopPolling() {
17
+ clearTimeout(timer);
18
+ stopped.abort();
19
+ process.off(INTERRUPT_SIGNAL, interrupt);
20
+ }
21
+ async function pollOnce() {
22
+ try {
23
+ await poll(stopped.signal);
24
+ }
25
+ catch (error) {
26
+ if (!stopped.signal.aborted) {
27
+ stopPolling();
28
+ reject(error);
29
+ }
30
+ return;
31
+ }
32
+ if (!stopped.signal.aborted) {
33
+ timer = setTimeout(pollOnce, FOLLOW_POLL_INTERVAL_MS);
34
+ }
35
+ }
36
+ function interrupt() {
37
+ stopPolling();
38
+ finishRun();
39
+ // The listener is gone, so the signal now ends the process and the shell sees an interrupt.
40
+ process.kill(process.pid, INTERRUPT_SIGNAL);
41
+ }
42
+ process.once(INTERRUPT_SIGNAL, interrupt);
43
+ // Stays attached, so a write already on its way to the closed pipe cannot crash the process.
44
+ process.stdout.on("error", (error) => {
45
+ if (stopped.signal.aborted) {
46
+ return;
47
+ }
48
+ stopPolling();
49
+ if (error.code === CLOSED_PIPE_CODE) {
50
+ resolve();
51
+ }
52
+ else {
53
+ reject(error);
54
+ }
55
+ });
56
+ timer = setTimeout(pollOnce, FOLLOW_POLL_INTERVAL_MS);
57
+ });
58
+ }
package/src/input.d.ts CHANGED
@@ -173,21 +173,16 @@ export declare const archiveConstraint: {
173
173
  };
174
174
  export declare const routerOptionNames: {
175
175
  readonly json: "json";
176
- readonly legacyRead: "allow-legacy-read";
177
176
  };
178
177
  export declare const routerOptions: {
179
178
  readonly json: {
180
179
  readonly type: "boolean";
181
180
  };
182
- readonly "allow-legacy-read": {
183
- readonly type: "boolean";
184
- };
185
181
  };
186
182
  export declare const helpSpellings: readonly string[];
187
183
  export declare const versionSpellings: readonly string[];
188
184
  export declare const OPTION_SEPARATOR = "--";
189
185
  export declare function isJsonFlag(flag: string): boolean;
190
- export declare function isAllowLegacyReadFlag(flag: string): boolean;
191
186
  /** A flag the router reads wherever it appears before --, for every command. */
192
187
  export declare function isRouterFlag(flag: string): boolean;
193
188
  export declare function isHelpFlag(flag: string): boolean;
@@ -201,9 +196,6 @@ export declare const invocation: {
201
196
  readonly json: {
202
197
  readonly type: "boolean";
203
198
  };
204
- readonly "allow-legacy-read": {
205
- readonly type: "boolean";
206
- };
207
199
  };
208
200
  readonly routerOptionPlacement: "exact-tokens-anywhere-before-separator";
209
201
  readonly optionSeparator: "--";