@zinn-dev/cli 0.43.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.
- package/README.md +1 -1
- package/index.js +3 -3
- package/package.json +7 -4
- package/skills/zinn/SKILL.md +7 -9
- package/src/actor.d.ts +8 -0
- package/src/actor.js +5 -1
- package/src/capabilities-schema.d.ts +6 -2
- package/src/column-hint.js +2 -5
- package/src/database.d.ts +1 -2
- package/src/database.js +1 -6
- package/src/duration-input.d.ts +7 -0
- package/src/duration-input.js +31 -0
- package/src/errors.d.ts +34 -3
- package/src/errors.js +49 -7
- package/src/expected-values.d.ts +48 -0
- package/src/expected-values.js +60 -0
- package/src/failure-log.d.ts +6 -0
- package/src/failure-log.js +167 -0
- package/src/follow.d.ts +9 -0
- package/src/follow.js +58 -0
- package/src/input.d.ts +10 -7
- package/src/input.js +57 -13
- package/src/lib.d.ts +12 -7
- package/src/lib.js +70 -41
- package/src/list-continuation.js +1 -4
- package/src/list-limit.d.ts +2 -2
- package/src/list-limit.js +2 -2
- package/src/overview.d.ts +10 -0
- package/src/overview.js +41 -0
- package/src/presentation/activity-presentation.d.ts +4 -0
- package/src/presentation/activity-presentation.js +154 -38
- package/src/presentation/column-presentation.d.ts +22 -2
- package/src/presentation/column-presentation.js +68 -12
- package/src/presentation/doctor-presentation.d.ts +4 -0
- package/src/presentation/doctor-presentation.js +24 -0
- package/src/presentation/info-presentation.js +36 -6
- package/src/presentation/relation-presentation.d.ts +6 -2
- package/src/presentation/relation-presentation.js +37 -26
- package/src/presentation/task-blame-presentation.d.ts +8 -0
- package/src/presentation/task-blame-presentation.js +56 -0
- package/src/presentation/task-presentation.d.ts +8 -1
- package/src/presentation/task-presentation.js +59 -10
- package/src/result-schemas.d.ts +780 -20
- package/src/result-schemas.js +99 -2
- package/src/results.d.ts +6 -2
- package/src/results.js +9 -3
- package/src/routes/activity-router.d.ts +21 -4
- package/src/routes/activity-router.js +107 -60
- package/src/routes/aliases.js +1 -0
- package/src/routes/comment-router.d.ts +24 -6
- package/src/routes/comment-router.js +15 -5
- package/src/routes/doctor-router.d.ts +39 -0
- package/src/routes/doctor-router.js +103 -0
- package/src/routes/info-router.js +3 -2
- package/src/routes/label-router.d.ts +39 -6
- package/src/routes/label-router.js +22 -5
- package/src/routes/migrate-router.js +2 -2
- package/src/routes/project-router.d.ts +61 -12
- package/src/routes/project-router.js +103 -45
- package/src/routes/restore-router.js +11 -5
- package/src/routes/router.js +25 -16
- package/src/routes/routes.d.ts +455 -41
- package/src/routes/routes.js +4 -0
- package/src/routes/skill-router.d.ts +25 -0
- package/src/routes/skill-router.js +96 -0
- package/src/routes/task-router.d.ts +272 -19
- package/src/routes/task-router.js +325 -40
- package/src/routes/whoami-router.js +1 -1
- package/src/run-facts.d.ts +14 -0
- package/src/run-facts.js +14 -0
- package/src/store-folder.d.ts +5 -0
- package/src/store-folder.js +16 -0
- package/src/telemetry.d.ts +31 -0
- package/src/telemetry.js +329 -0
- package/src/text-edit.d.ts +2 -2
- package/src/text-input.d.ts +19 -1
- package/src/text-input.js +27 -10
- package/src/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @zinn-dev/cli
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The command-line interface for [Zinn](https://zinn.sh), local kanban and task management for developers and coding agents.
|
|
4
4
|
|
|
5
5
|
> [!IMPORTANT]
|
|
6
6
|
> **Experimental.** Commands, output, and the database schema may change between releases. Save a backup with `zinn backup` before upgrading.
|
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import packageJson from "./package.json" with { type: "json" };
|
|
3
|
-
import { versionSpellings } from "./src/input.js";
|
|
3
|
+
import { isHelpFlag, versionSpellings } from "./src/input.js";
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
5
|
const isVersionRequest = args.length === 1 && versionSpellings.includes(args[0]);
|
|
6
6
|
if (isVersionRequest) {
|
|
7
7
|
console.info(packageJson.version);
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
const {
|
|
10
|
+
const { prepareOutput, finishRun, renderFailure } = await import("./src/lib.js");
|
|
11
11
|
prepareOutput(args);
|
|
12
12
|
try {
|
|
13
13
|
const { createRouter } = await import("./src/routes/router.js");
|
|
@@ -22,7 +22,7 @@ else {
|
|
|
22
22
|
});
|
|
23
23
|
if (args.length === 0 || isHelpFlag(args[0])) {
|
|
24
24
|
console.info(router.help);
|
|
25
|
-
|
|
25
|
+
finishRun();
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
await router.route(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinn-dev/cli",
|
|
3
|
-
"version": "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",
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"kanban",
|
|
22
22
|
"cli",
|
|
23
|
-
"terminal"
|
|
23
|
+
"terminal",
|
|
24
|
+
"task-management",
|
|
25
|
+
"task-tracker",
|
|
26
|
+
"coding-agents"
|
|
24
27
|
],
|
|
25
28
|
"files": [
|
|
26
29
|
"index.js",
|
|
@@ -35,8 +38,8 @@
|
|
|
35
38
|
"node": ">=24.15.0"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"zod": "4.6.
|
|
39
|
-
"@zinn-dev/core": "0.
|
|
41
|
+
"zod": "4.6.7",
|
|
42
|
+
"@zinn-dev/core": "0.34.0"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"ajv": "8.20.0"
|
package/skills/zinn/SKILL.md
CHANGED
|
@@ -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.
|
|
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,
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Actor } from "@zinn-dev/core";
|
|
2
2
|
type Env = Record<string, string | undefined>;
|
|
3
|
+
export declare function readExecutionIdentity(env: Env): {
|
|
4
|
+
sessionId: string | null;
|
|
5
|
+
threadId: string | null;
|
|
6
|
+
agent: string | null;
|
|
7
|
+
model: string | null;
|
|
8
|
+
effort: string | null;
|
|
9
|
+
client: string;
|
|
10
|
+
};
|
|
3
11
|
/** Generic flags establish an unnamed agent only when no identifying marker follows. */
|
|
4
12
|
export declare function detectAgent(env: Env): Actor | null;
|
|
5
13
|
export declare function resolveActor(env: Env): Actor;
|
package/src/actor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { userInfo } from "node:os";
|
|
3
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
3
4
|
/**
|
|
4
5
|
* Environment variables that coding agents set in the shells they run.
|
|
5
6
|
* Undetected tools can set `AI_AGENT` through their own env configuration.
|
|
@@ -27,7 +28,9 @@ function readDeclaration(env, variable) {
|
|
|
27
28
|
const value = variable === null ? undefined : env[variable]?.trim();
|
|
28
29
|
return value == null || value.length === 0 ? null : value;
|
|
29
30
|
}
|
|
30
|
-
function readExecutionIdentity(env) {
|
|
31
|
+
export function readExecutionIdentity(env) {
|
|
32
|
+
const ownClient = `zinn-cli/${packageJson.version}`;
|
|
33
|
+
const declaredClient = readDeclaration(env, "ZINN_CLIENT");
|
|
31
34
|
let sessionId = null;
|
|
32
35
|
let threadId = null;
|
|
33
36
|
for (const declaration of SESSION_DECLARATIONS) {
|
|
@@ -46,6 +49,7 @@ function readExecutionIdentity(env) {
|
|
|
46
49
|
agent: readDeclaration(env, "ZINN_AGENT"),
|
|
47
50
|
model: readDeclaration(env, "ZINN_MODEL"),
|
|
48
51
|
effort: readDeclaration(env, "ZINN_EFFORT"),
|
|
52
|
+
client: declaredClient === null ? ownClient : `${ownClient} ${declaredClient}`,
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
55
|
/** Generic flags establish an unnamed agent only when no identifying marker follows. */
|
|
@@ -125,8 +125,8 @@ export declare const capabilitiesSchema: z.ZodObject<{
|
|
|
125
125
|
}, z.core.$strict>;
|
|
126
126
|
confirmation: z.ZodObject<{
|
|
127
127
|
kind: z.ZodEnum<{
|
|
128
|
-
prompt: "prompt";
|
|
129
128
|
none: "none";
|
|
129
|
+
prompt: "prompt";
|
|
130
130
|
"project-delete": "project-delete";
|
|
131
131
|
}>;
|
|
132
132
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -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.
|
|
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<{
|
package/src/column-hint.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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, violatesConstraint } from "./input.js";
|
|
5
|
-
import { formatCommand,
|
|
4
|
+
import { routerOptions, getOptionInputs, isRouterFlag, splitAtOptionSeparator, violatesConstraint, } from "./input.js";
|
|
5
|
+
import { formatCommand, UsageError, validateUniqueOptions } from "./lib.js";
|
|
6
6
|
import { chooseProjectKey } from "./project.js";
|
|
7
7
|
function isEligible(error, command) {
|
|
8
8
|
const failure = classifyFailure(error);
|
|
@@ -76,8 +76,6 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
const args = rawArgs.slice(argumentStart);
|
|
79
|
-
const separatorIndex = rawArgs.indexOf("--");
|
|
80
|
-
const optionArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
|
|
81
79
|
const options = { ...route.input.options, ...routerOptions };
|
|
82
80
|
const { tokens, values } = parseArgs({
|
|
83
81
|
args,
|
|
@@ -113,7 +111,6 @@ export function quotedColumnHint(error, route, rawArgs, routeWordCount) {
|
|
|
113
111
|
}
|
|
114
112
|
const context = column.inspect({
|
|
115
113
|
taskKeys: isMove ? words.map((word) => word.value) : [],
|
|
116
|
-
allowsLegacyRead: optionArgs.some(isAllowLegacyReadFlag),
|
|
117
114
|
});
|
|
118
115
|
if (context === null) {
|
|
119
116
|
return undefined;
|
package/src/database.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
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,10 +42,16 @@ 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";
|
|
48
50
|
ambiguous_reference: "ambiguous_reference";
|
|
51
|
+
invalid_cursor: "invalid_cursor";
|
|
52
|
+
cursor_version: "cursor_version";
|
|
53
|
+
different_sort: "different_sort";
|
|
54
|
+
task_id_cursor: "task_id_cursor";
|
|
49
55
|
text_match_count: "text_match_count";
|
|
50
56
|
no_columns: "no_columns";
|
|
51
57
|
has_tasks: "has_tasks";
|
|
@@ -61,6 +67,9 @@ export declare const errorDetailsSchema: z.ZodObject<{
|
|
|
61
67
|
corrupt: "corrupt";
|
|
62
68
|
not_database: "not_database";
|
|
63
69
|
missing_index: "missing_index";
|
|
70
|
+
claimed: "claimed";
|
|
71
|
+
not_claimed: "not_claimed";
|
|
72
|
+
claim_limit: "claim_limit";
|
|
64
73
|
io: "io";
|
|
65
74
|
}>>;
|
|
66
75
|
matchCount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -71,6 +80,12 @@ export declare const errorDetailsSchema: z.ZodObject<{
|
|
|
71
80
|
backupPath: z.ZodOptional<z.ZodString>;
|
|
72
81
|
schemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
73
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>;
|
|
87
|
+
logPath: z.ZodOptional<z.ZodString>;
|
|
88
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
74
89
|
cause: z.ZodOptional<z.ZodObject<{
|
|
75
90
|
code: z.ZodOptional<z.ZodString>;
|
|
76
91
|
errcode: z.ZodOptional<z.ZodNumber>;
|
|
@@ -124,10 +139,16 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
124
139
|
already_exists: "already_exists";
|
|
125
140
|
parent_exists: "parent_exists";
|
|
126
141
|
relation_changed: "relation_changed";
|
|
142
|
+
column_changed: "column_changed";
|
|
143
|
+
value_changed: "value_changed";
|
|
127
144
|
cycle: "cycle";
|
|
128
145
|
different_project: "different_project";
|
|
129
146
|
different_column: "different_column";
|
|
130
147
|
ambiguous_reference: "ambiguous_reference";
|
|
148
|
+
invalid_cursor: "invalid_cursor";
|
|
149
|
+
cursor_version: "cursor_version";
|
|
150
|
+
different_sort: "different_sort";
|
|
151
|
+
task_id_cursor: "task_id_cursor";
|
|
131
152
|
text_match_count: "text_match_count";
|
|
132
153
|
no_columns: "no_columns";
|
|
133
154
|
has_tasks: "has_tasks";
|
|
@@ -143,6 +164,9 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
143
164
|
corrupt: "corrupt";
|
|
144
165
|
not_database: "not_database";
|
|
145
166
|
missing_index: "missing_index";
|
|
167
|
+
claimed: "claimed";
|
|
168
|
+
not_claimed: "not_claimed";
|
|
169
|
+
claim_limit: "claim_limit";
|
|
146
170
|
io: "io";
|
|
147
171
|
}>>;
|
|
148
172
|
matchCount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -153,6 +177,12 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
153
177
|
backupPath: z.ZodOptional<z.ZodString>;
|
|
154
178
|
schemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
155
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>;
|
|
184
|
+
logPath: z.ZodOptional<z.ZodString>;
|
|
185
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
156
186
|
cause: z.ZodOptional<z.ZodObject<{
|
|
157
187
|
code: z.ZodOptional<z.ZodString>;
|
|
158
188
|
errcode: z.ZodOptional<z.ZodNumber>;
|
|
@@ -165,7 +195,7 @@ export declare const errorDocumentSchema: z.ZodObject<{
|
|
|
165
195
|
export type ErrorCode = z.infer<typeof errorCodeSchema>;
|
|
166
196
|
export type ErrorDetails = z.infer<typeof errorDetailsSchema>;
|
|
167
197
|
export type CliFailure = z.infer<typeof errorDocumentSchema>["error"];
|
|
168
|
-
type ClassifiedFailure = Omit<CliFailure, "message"> & {
|
|
198
|
+
export type ClassifiedFailure = Omit<CliFailure, "message"> & {
|
|
169
199
|
suggestedRoute?: Array<string>;
|
|
170
200
|
};
|
|
171
201
|
/** A CLI failure with public facts and an internal recovery route. */
|
|
@@ -174,7 +204,9 @@ export declare class CliError extends Error {
|
|
|
174
204
|
readonly details?: ErrorDetails | undefined;
|
|
175
205
|
help?: string | undefined;
|
|
176
206
|
readonly suggestedRoute?: Array<string> | undefined;
|
|
177
|
-
|
|
207
|
+
/** The process exit code, when it is not the usual 1 */
|
|
208
|
+
exitCode?: number;
|
|
209
|
+
constructor(message: string, code?: ErrorCode, details?: ErrorDetails | undefined, help?: string | undefined, suggestedRoute?: Array<string> | undefined, cause?: unknown);
|
|
178
210
|
}
|
|
179
211
|
/** Recovery text and its single suggested route, when one is identified. */
|
|
180
212
|
export declare function recoveryHint(error: unknown): {
|
|
@@ -183,4 +215,3 @@ export declare function recoveryHint(error: unknown): {
|
|
|
183
215
|
} | undefined;
|
|
184
216
|
/** Finds causes of initialization wrappers without serializing their error chains. */
|
|
185
217
|
export declare function classifyFailure(error: unknown): ClassifiedFailure;
|
|
186
|
-
export {};
|
package/src/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { CoreError, ReadOnlyDatabaseError, SqliteError, TextEditMatchError,
|
|
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,10 +44,16 @@ 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",
|
|
49
52
|
"ambiguous_reference",
|
|
53
|
+
"invalid_cursor",
|
|
54
|
+
"cursor_version",
|
|
55
|
+
"different_sort",
|
|
56
|
+
"task_id_cursor",
|
|
50
57
|
"text_match_count",
|
|
51
58
|
"no_columns",
|
|
52
59
|
"has_tasks",
|
|
@@ -62,6 +69,9 @@ export const errorDetailsSchema = z.strictObject({
|
|
|
62
69
|
"corrupt",
|
|
63
70
|
"not_database",
|
|
64
71
|
"missing_index",
|
|
72
|
+
"claimed",
|
|
73
|
+
"not_claimed",
|
|
74
|
+
"claim_limit",
|
|
65
75
|
"io",
|
|
66
76
|
])
|
|
67
77
|
.optional(),
|
|
@@ -73,6 +83,16 @@ export const errorDetailsSchema = z.strictObject({
|
|
|
73
83
|
backupPath: z.string().optional(),
|
|
74
84
|
schemaVersion: z.number().int().nonnegative().optional(),
|
|
75
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(),
|
|
94
|
+
logPath: z.string().optional(),
|
|
95
|
+
exitCode: z.number().int().optional(),
|
|
76
96
|
cause: z
|
|
77
97
|
.strictObject({
|
|
78
98
|
code: z.string().optional(),
|
|
@@ -96,8 +116,10 @@ export class CliError extends Error {
|
|
|
96
116
|
details;
|
|
97
117
|
help;
|
|
98
118
|
suggestedRoute;
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
/** The process exit code, when it is not the usual 1 */
|
|
120
|
+
exitCode;
|
|
121
|
+
constructor(message, code = "invalid_input", details, help, suggestedRoute, cause) {
|
|
122
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
101
123
|
this.code = code;
|
|
102
124
|
this.details = details;
|
|
103
125
|
this.help = help;
|
|
@@ -105,14 +127,17 @@ export class CliError extends Error {
|
|
|
105
127
|
this.name = "CliError";
|
|
106
128
|
}
|
|
107
129
|
}
|
|
130
|
+
const taskCursorRecovery = {
|
|
131
|
+
invalid_cursor: ". Copy the cursor from the continuation command that zinn task list prints, or list again without --starting-after.",
|
|
132
|
+
cursor_version: ". Run zinn task list again without --starting-after to get a current cursor.",
|
|
133
|
+
different_sort: ". Keep the --sort of the zinn task list command that printed the cursor, or start again without --starting-after.",
|
|
134
|
+
task_id_cursor: ". When more tasks remain, zinn task list prints a continuation command with the cursor on stderr. Run that command.",
|
|
135
|
+
};
|
|
108
136
|
/** Recovery text and its single suggested route, when one is identified. */
|
|
109
137
|
export function recoveryHint(error) {
|
|
110
138
|
if (error instanceof ReadOnlyDatabaseError && error.reason === "older") {
|
|
111
139
|
return { suffix: ". Run `zinn migrate` to upgrade it.", suggestedRoute: ["migrate"] };
|
|
112
140
|
}
|
|
113
|
-
if (error instanceof UnmarkedDatabaseError) {
|
|
114
|
-
return { suffix: ". Add --allow-legacy-read to read it anyway." };
|
|
115
|
-
}
|
|
116
141
|
if (error instanceof TextEditMatchError && error.matchCount > 1) {
|
|
117
142
|
return { suffix: " Use --all to replace every match." };
|
|
118
143
|
}
|
|
@@ -124,15 +149,28 @@ export function recoveryHint(error) {
|
|
|
124
149
|
}
|
|
125
150
|
if (error instanceof CoreError && error.facts.reason === "no_columns") {
|
|
126
151
|
return {
|
|
127
|
-
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>.`,
|
|
128
153
|
suggestedRoute: ["project", "column", "create"],
|
|
129
154
|
};
|
|
130
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
|
+
}
|
|
131
163
|
if (error instanceof CoreError && error.facts.reason === "has_tasks") {
|
|
132
164
|
return {
|
|
133
165
|
suffix: ". Use zinn task move or zinn task delete to clear the column. Archived tasks must be unarchived before moving.",
|
|
134
166
|
};
|
|
135
167
|
}
|
|
168
|
+
const cursorRecovery = error instanceof CoreError && error.facts.reason !== undefined
|
|
169
|
+
? taskCursorRecovery[error.facts.reason]
|
|
170
|
+
: undefined;
|
|
171
|
+
if (cursorRecovery !== undefined) {
|
|
172
|
+
return { suffix: cursorRecovery, suggestedRoute: ["task", "list"] };
|
|
173
|
+
}
|
|
136
174
|
if (error instanceof Error && error.message === "no such table: task_search") {
|
|
137
175
|
return {
|
|
138
176
|
suffix: ". Run `zinn reindex` to rebuild the search index.",
|
|
@@ -200,6 +238,10 @@ function publicDetails(facts) {
|
|
|
200
238
|
backupPath: facts.backupPath,
|
|
201
239
|
schemaVersion: facts.schemaVersion,
|
|
202
240
|
supportedSchemaVersion: facts.supportedSchemaVersion,
|
|
241
|
+
expectedColumn: facts.expectedColumn,
|
|
242
|
+
actualColumn: facts.actualColumn,
|
|
243
|
+
changedFields: facts.changedFields,
|
|
244
|
+
claimExpiresAt: facts.claimExpiresAt,
|
|
203
245
|
};
|
|
204
246
|
return Object.fromEntries(Object.entries(details).filter(([, value]) => value !== undefined));
|
|
205
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,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes what a failure leaves out of its error message to a new file in the store's `logs` folder.
|
|
3
|
+
* Returns the file's path, or undefined when none was written. It never throws,
|
|
4
|
+
* so logging cannot hide the failure it reports.
|
|
5
|
+
*/
|
|
6
|
+
export declare function writeFailureLog(error: unknown, notices: ReadonlyArray<string>): string | undefined;
|