@zinn-dev/cli 0.44.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/skills/zinn/SKILL.md +7 -9
  4. package/src/actor.d.ts +1 -1
  5. package/src/actor.js +4 -1
  6. package/src/capabilities-schema.d.ts +9 -1
  7. package/src/column-hint.js +1 -3
  8. package/src/database.d.ts +1 -2
  9. package/src/database.js +1 -6
  10. package/src/duration-input.d.ts +7 -0
  11. package/src/duration-input.js +31 -0
  12. package/src/errors.d.ts +26 -0
  13. package/src/errors.js +46 -8
  14. package/src/expected-values.d.ts +48 -0
  15. package/src/expected-values.js +60 -0
  16. package/src/follow.d.ts +9 -0
  17. package/src/follow.js +58 -0
  18. package/src/input.d.ts +0 -8
  19. package/src/input.js +36 -16
  20. package/src/lib.d.ts +7 -3
  21. package/src/lib.js +70 -28
  22. package/src/list-continuation.js +1 -4
  23. package/src/presentation/activity-presentation.d.ts +2 -0
  24. package/src/presentation/activity-presentation.js +60 -3
  25. package/src/presentation/column-presentation.d.ts +9 -4
  26. package/src/presentation/column-presentation.js +29 -12
  27. package/src/presentation/doctor-presentation.d.ts +10 -0
  28. package/src/presentation/doctor-presentation.js +28 -0
  29. package/src/presentation/relation-presentation.js +2 -1
  30. package/src/presentation/skill-status-presentation.d.ts +9 -0
  31. package/src/presentation/skill-status-presentation.js +43 -0
  32. package/src/presentation/task-blame-presentation.d.ts +2 -4
  33. package/src/presentation/task-blame-presentation.js +4 -2
  34. package/src/presentation/task-presentation.d.ts +18 -4
  35. package/src/presentation/task-presentation.js +94 -30
  36. package/src/result-schemas.d.ts +490 -58
  37. package/src/result-schemas.js +97 -2
  38. package/src/results.d.ts +6 -2
  39. package/src/results.js +9 -3
  40. package/src/routes/activity-router.d.ts +16 -5
  41. package/src/routes/activity-router.js +131 -70
  42. package/src/routes/aliases.js +1 -0
  43. package/src/routes/backup-router.d.ts +1 -0
  44. package/src/routes/backup-router.js +4 -3
  45. package/src/routes/capabilities-router.d.ts +1 -0
  46. package/src/routes/capabilities-router.js +1 -1
  47. package/src/routes/comment-router.d.ts +29 -6
  48. package/src/routes/comment-router.js +20 -10
  49. package/src/routes/doctor-router.d.ts +40 -0
  50. package/src/routes/doctor-router.js +83 -0
  51. package/src/routes/info-router.d.ts +1 -0
  52. package/src/routes/info-router.js +1 -1
  53. package/src/routes/label-router.d.ts +44 -6
  54. package/src/routes/label-router.js +27 -10
  55. package/src/routes/migrate-router.d.ts +1 -0
  56. package/src/routes/migrate-router.js +5 -7
  57. package/src/routes/project-router.d.ts +70 -11
  58. package/src/routes/project-router.js +130 -56
  59. package/src/routes/reindex-router.d.ts +1 -0
  60. package/src/routes/reindex-router.js +1 -1
  61. package/src/routes/relation-router.d.ts +3 -0
  62. package/src/routes/relation-router.js +9 -6
  63. package/src/routes/restore-router.d.ts +1 -0
  64. package/src/routes/restore-router.js +5 -6
  65. package/src/routes/router.js +5 -9
  66. package/src/routes/routes.d.ts +517 -35
  67. package/src/routes/routes.js +4 -0
  68. package/src/routes/skill-router.d.ts +76 -0
  69. package/src/routes/skill-router.js +179 -0
  70. package/src/routes/task-router.d.ts +264 -13
  71. package/src/routes/task-router.js +415 -93
  72. package/src/routes/whoami-router.d.ts +1 -0
  73. package/src/routes/whoami-router.js +1 -1
  74. package/src/skill-copies.d.ts +34 -0
  75. package/src/skill-copies.js +109 -0
  76. package/src/telemetry.d.ts +2 -2
  77. package/src/telemetry.js +8 -3
  78. package/src/text-edit.d.ts +2 -2
  79. package/src/text-input.d.ts +19 -1
  80. package/src/text-input.js +26 -5
  81. package/src/types.d.ts +4 -0
  82. package/src/types.js +6 -0
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.44.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.33.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.44.0"
10
+ zinn-cli-reviewed-version: "0.46.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. 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.
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
  ```
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<{
@@ -145,9 +149,13 @@ export declare const capabilitiesSchema: z.ZodObject<{
145
149
  max: z.ZodNullable<z.ZodNumber>;
146
150
  }, z.core.$strict>], "kind">;
147
151
  schemaRef: z.ZodString;
148
- mode: z.ZodLiteral<"json">;
152
+ mode: z.ZodEnum<{
153
+ json: "json";
154
+ "json-lines": "json-lines";
155
+ }>;
149
156
  stream: z.ZodLiteral<"stdout">;
150
157
  exitCode: z.ZodLiteral<0>;
158
+ findingsExitCode: z.ZodOptional<z.ZodLiteral<1>>;
151
159
  }, z.core.$strict>>>;
152
160
  }, z.core.$strict>>;
153
161
  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";
@@ -56,6 +58,7 @@ export declare const errorDetailsSchema: z.ZodObject<{
56
58
  unmarked_database: "unmarked_database";
57
59
  newer_database: "newer_database";
58
60
  older_database: "older_database";
61
+ migration_paused: "migration_paused";
59
62
  invalid_backup: "invalid_backup";
60
63
  busy: "busy";
61
64
  locked: "locked";
@@ -65,6 +68,9 @@ export declare const errorDetailsSchema: z.ZodObject<{
65
68
  corrupt: "corrupt";
66
69
  not_database: "not_database";
67
70
  missing_index: "missing_index";
71
+ claimed: "claimed";
72
+ not_claimed: "not_claimed";
73
+ claim_limit: "claim_limit";
68
74
  io: "io";
69
75
  }>>;
70
76
  matchCount: z.ZodOptional<z.ZodNumber>;
@@ -73,9 +79,15 @@ export declare const errorDetailsSchema: z.ZodObject<{
73
79
  databasePath: z.ZodOptional<z.ZodString>;
74
80
  backupDirectory: z.ZodOptional<z.ZodString>;
75
81
  backupPath: z.ZodOptional<z.ZodString>;
82
+ applied: z.ZodOptional<z.ZodLiteral<true>>;
76
83
  schemaVersion: z.ZodOptional<z.ZodNumber>;
77
84
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
85
+ expectedColumn: z.ZodOptional<z.ZodString>;
86
+ actualColumn: z.ZodOptional<z.ZodString>;
87
+ changedFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ claimExpiresAt: z.ZodOptional<z.ZodNumber>;
78
89
  logPath: z.ZodOptional<z.ZodString>;
90
+ exitCode: z.ZodOptional<z.ZodNumber>;
79
91
  cause: z.ZodOptional<z.ZodObject<{
80
92
  code: z.ZodOptional<z.ZodString>;
81
93
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -129,6 +141,8 @@ export declare const errorDocumentSchema: z.ZodObject<{
129
141
  already_exists: "already_exists";
130
142
  parent_exists: "parent_exists";
131
143
  relation_changed: "relation_changed";
144
+ column_changed: "column_changed";
145
+ value_changed: "value_changed";
132
146
  cycle: "cycle";
133
147
  different_project: "different_project";
134
148
  different_column: "different_column";
@@ -143,6 +157,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
143
157
  unmarked_database: "unmarked_database";
144
158
  newer_database: "newer_database";
145
159
  older_database: "older_database";
160
+ migration_paused: "migration_paused";
146
161
  invalid_backup: "invalid_backup";
147
162
  busy: "busy";
148
163
  locked: "locked";
@@ -152,6 +167,9 @@ export declare const errorDocumentSchema: z.ZodObject<{
152
167
  corrupt: "corrupt";
153
168
  not_database: "not_database";
154
169
  missing_index: "missing_index";
170
+ claimed: "claimed";
171
+ not_claimed: "not_claimed";
172
+ claim_limit: "claim_limit";
155
173
  io: "io";
156
174
  }>>;
157
175
  matchCount: z.ZodOptional<z.ZodNumber>;
@@ -160,9 +178,15 @@ export declare const errorDocumentSchema: z.ZodObject<{
160
178
  databasePath: z.ZodOptional<z.ZodString>;
161
179
  backupDirectory: z.ZodOptional<z.ZodString>;
162
180
  backupPath: z.ZodOptional<z.ZodString>;
181
+ applied: z.ZodOptional<z.ZodLiteral<true>>;
163
182
  schemaVersion: z.ZodOptional<z.ZodNumber>;
164
183
  supportedSchemaVersion: z.ZodOptional<z.ZodNumber>;
184
+ expectedColumn: z.ZodOptional<z.ZodString>;
185
+ actualColumn: z.ZodOptional<z.ZodString>;
186
+ changedFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
187
+ claimExpiresAt: z.ZodOptional<z.ZodNumber>;
165
188
  logPath: z.ZodOptional<z.ZodString>;
189
+ exitCode: z.ZodOptional<z.ZodNumber>;
166
190
  cause: z.ZodOptional<z.ZodObject<{
167
191
  code: z.ZodOptional<z.ZodString>;
168
192
  errcode: z.ZodOptional<z.ZodNumber>;
@@ -184,6 +208,8 @@ export declare class CliError extends Error {
184
208
  readonly details?: ErrorDetails | undefined;
185
209
  help?: string | undefined;
186
210
  readonly suggestedRoute?: Array<string> | undefined;
211
+ /** The process exit code, when it is not the usual 1 */
212
+ exitCode?: number;
187
213
  constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined, cause?: unknown);
188
214
  }
189
215
  /** 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 { AutomaticUpgradePausedError, 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",
@@ -57,6 +60,7 @@ export const errorDetailsSchema = z.strictObject({
57
60
  "unmarked_database",
58
61
  "newer_database",
59
62
  "older_database",
63
+ "migration_paused",
60
64
  "invalid_backup",
61
65
  "busy",
62
66
  "locked",
@@ -66,6 +70,9 @@ export const errorDetailsSchema = z.strictObject({
66
70
  "corrupt",
67
71
  "not_database",
68
72
  "missing_index",
73
+ "claimed",
74
+ "not_claimed",
75
+ "claim_limit",
69
76
  "io",
70
77
  ])
71
78
  .optional(),
@@ -75,9 +82,19 @@ export const errorDetailsSchema = z.strictObject({
75
82
  databasePath: z.string().optional(),
76
83
  backupDirectory: z.string().optional(),
77
84
  backupPath: z.string().optional(),
85
+ applied: z.literal(true).optional(),
78
86
  schemaVersion: z.number().int().nonnegative().optional(),
79
87
  supportedSchemaVersion: z.number().int().nonnegative().optional(),
88
+ expectedColumn: z.string().optional(),
89
+ actualColumn: z.string().optional(),
90
+ changedFields: z.array(z.string()).optional(),
91
+ claimExpiresAt: z
92
+ .number()
93
+ .int()
94
+ .describe("When the task's current claim expires, in epoch milliseconds.")
95
+ .optional(),
80
96
  logPath: z.string().optional(),
97
+ exitCode: z.number().int().optional(),
81
98
  cause: z
82
99
  .strictObject({
83
100
  code: z.string().optional(),
@@ -101,6 +118,8 @@ export class CliError extends Error {
101
118
  details;
102
119
  help;
103
120
  suggestedRoute;
121
+ /** The process exit code, when it is not the usual 1 */
122
+ exitCode;
104
123
  constructor(message, code = "invalid_input", details, help, suggestedRoute, cause) {
105
124
  super(message, cause === undefined ? undefined : { cause });
106
125
  this.code = code;
@@ -121,8 +140,14 @@ export function recoveryHint(error) {
121
140
  if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
122
141
  return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
123
142
  }
124
- if (error instanceof UnmarkedDatabaseError) {
125
- return { suffix: ". Add --allow-legacy-read to read it anyway." };
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
+ };
126
151
  }
127
152
  if (error instanceof TextEditMatchError && error.matchCount > 1) {
128
153
  return { suffix: " Use --all to replace every match." };
@@ -135,10 +160,17 @@ export function recoveryHint(error) {
135
160
  }
136
161
  if (error instanceof CoreError && error.facts.reason === "no_columns") {
137
162
  return {
138
- suffix: `. Add a column with zinn project column create ${error.facts.key} <name>.`,
163
+ suffix: `. Add a column with zinn project column create ${error.facts.key} <name> --category <category>.`,
139
164
  suggestedRoute: ["project", "column", "create"],
140
165
  };
141
166
  }
167
+ if (error instanceof CoreError &&
168
+ error.facts.reason === "claimed" &&
169
+ error.facts.claimExpiresAt !== undefined) {
170
+ const expiresAt = error.facts.claimExpiresAt;
171
+ const timing = Date.now() < expiresAt ? "until" : "whose claim expired at";
172
+ return { suffix: `, ${timing} ${formatLocalTime(expiresAt, { includesSeconds: true })}` };
173
+ }
142
174
  if (error instanceof CoreError && error.facts.reason === "has_tasks") {
143
175
  return {
144
176
  suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
@@ -215,12 +247,17 @@ function publicDetails(facts) {
215
247
  databasePath: facts.databasePath,
216
248
  backupDirectory: facts.backupDirectory,
217
249
  backupPath: facts.backupPath,
250
+ applied: facts.applied,
218
251
  schemaVersion: facts.schemaVersion,
219
252
  supportedSchemaVersion: facts.supportedSchemaVersion,
253
+ expectedColumn: facts.expectedColumn,
254
+ actualColumn: facts.actualColumn,
255
+ changedFields: facts.changedFields,
256
+ claimExpiresAt: facts.claimExpiresAt,
220
257
  };
221
258
  return Object.fromEntries(Object.entries(details).filter(([, value]) => value !== undefined));
222
259
  }
223
- function nativeFailure(error) {
260
+ function nativeFailure(error, hasStorageContext) {
224
261
  const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
225
262
  if (code === undefined) {
226
263
  return undefined;
@@ -228,11 +265,12 @@ function nativeFailure(error) {
228
265
  const reason = error instanceof SqliteError
229
266
  ? sqliteReasons.find(([primary]) => isSqliteErrorFamily(error, primary))?.[1]
230
267
  : osReasons[code];
231
- if (reason === undefined) {
268
+ const isStorageCause = hasStorageContext && "syscall" in error && typeof error.syscall === "string";
269
+ if (reason === undefined && !isStorageCause) {
232
270
  return undefined;
233
271
  }
234
272
  return {
235
- reason,
273
+ ...(reason === undefined ? {} : { reason }),
236
274
  ...("path" in error && typeof error.path === "string" ? { path: error.path } : {}),
237
275
  cause: {
238
276
  code,
@@ -274,7 +312,7 @@ export function classifyFailure(error) {
274
312
  },
275
313
  };
276
314
  }
277
- const native = nativeFailure(current);
315
+ const native = nativeFailure(current, classified?.code === "storage");
278
316
  if (classified?.code === "storage" && current instanceof SqliteError) {
279
317
  classified.details = {
280
318
  ...native,
@@ -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>;