@zinn-dev/cli 0.40.0 → 0.42.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 +11 -561
- package/index.js +24 -13
- package/package.json +8 -2
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +2 -1
- package/src/actor.js +78 -11
- package/src/capabilities-schema.d.ts +162 -0
- package/src/capabilities-schema.js +59 -0
- package/src/capabilities.d.ts +29 -0
- package/src/capabilities.js +30 -0
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.d.ts +1 -1
- package/src/database.js +5 -8
- package/src/errors.d.ts +158 -0
- package/src/errors.js +226 -0
- package/src/input.d.ts +227 -0
- package/src/input.js +192 -0
- package/src/lib.d.ts +71 -8
- package/src/lib.js +275 -18
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +120 -23
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +9 -5
- package/src/presentation/column-presentation.js +10 -0
- package/src/presentation/comment-presentation.d.ts +15 -0
- package/src/presentation/comment-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +17 -0
- package/src/presentation/description-presentation.js +26 -4
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +7 -0
- package/src/presentation/project-presentation.js +19 -0
- package/src/presentation/relation-presentation.d.ts +7 -0
- package/src/presentation/relation-presentation.js +73 -0
- package/src/presentation/task-presentation.d.ts +4 -12
- package/src/presentation/task-presentation.js +22 -18
- package/src/project.d.ts +18 -3
- package/src/project.js +37 -12
- package/src/result-schemas.d.ts +1194 -0
- package/src/result-schemas.js +279 -0
- package/src/results.d.ts +40 -0
- package/src/results.js +36 -0
- package/src/routes/activity-router.d.ts +104 -0
- package/src/routes/activity-router.js +155 -34
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/backup-router.d.ts +17 -0
- package/src/routes/backup-router.js +15 -3
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +34 -0
- package/src/routes/comment-router.d.ts +210 -8
- package/src/routes/comment-router.js +189 -65
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +217 -2
- package/src/routes/label-router.js +189 -62
- package/src/routes/migrate-router.d.ts +17 -0
- package/src/routes/migrate-router.js +17 -5
- package/src/routes/project-router.d.ts +373 -2
- package/src/routes/project-router.js +322 -132
- package/src/routes/reindex-router.d.ts +17 -0
- package/src/routes/reindex-router.js +15 -3
- package/src/routes/relation-router.d.ts +110 -14
- package/src/routes/relation-router.js +122 -79
- package/src/routes/restore-router.d.ts +29 -0
- package/src/routes/restore-router.js +31 -14
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +80 -32
- package/src/routes/routes.d.ts +1781 -8
- package/src/routes/routes.js +9 -1
- package/src/routes/task-router.d.ts +946 -4
- package/src/routes/task-router.js +524 -260
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +28 -6
- package/src/text-edit.js +40 -23
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/types.d.ts +37 -0
- package/src/types.js +9 -1
package/src/routes/router.js
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
|
-
import {
|
|
2
|
+
import { routerOptions, helpSpellings, versionSpellings, usageLabel } from "../input.js";
|
|
3
|
+
import { getCommandAliases } from "./aliases.js";
|
|
4
|
+
import { classifyFailure, CliError } from "../errors.js";
|
|
5
|
+
import { quotedColumnHint } from "../column-hint.js";
|
|
6
|
+
import { dashValueHelp, diagnostic, failureMessage, flushDiagnostics, isAllowLegacyReadFlag, isHelpFlag, isRouterFlag, parseArgsMessage, prepareOutput, quit, renderFailure, setLegacyReadAllowed, UsageError, validateUniqueOptions, } from "../lib.js";
|
|
7
|
+
// ZINN_DEBUG=1 prints routing detail on stderr, so stdout and `--json` results stay unchanged.
|
|
8
|
+
function isDebugOutputEnabled() {
|
|
9
|
+
return process.env.ZINN_DEBUG === "1";
|
|
10
|
+
}
|
|
3
11
|
function getIsRunnable(obj) {
|
|
4
12
|
return Object.hasOwn(obj, "run");
|
|
5
13
|
}
|
|
6
|
-
function isRouterFlag(arg) {
|
|
7
|
-
return isJsonFlag(arg) || isAllowLegacyReadFlag(arg);
|
|
8
|
-
}
|
|
9
14
|
// --json and --allow-legacy-read can each be given once, like a command's own flags.
|
|
10
15
|
function validateRouterFlags(routableArgs) {
|
|
11
16
|
const { tokens } = parseArgs({
|
|
12
17
|
args: routableArgs.filter(isRouterFlag),
|
|
13
|
-
options:
|
|
18
|
+
options: routerOptions,
|
|
14
19
|
strict: true,
|
|
15
20
|
tokens: true,
|
|
16
21
|
});
|
|
17
|
-
validateUniqueOptions(tokens);
|
|
22
|
+
validateUniqueOptions(tokens, routerOptions);
|
|
18
23
|
}
|
|
19
24
|
/** The usage lines that open a command's help, up to its first blank line. */
|
|
20
25
|
function getUsage(help) {
|
|
21
26
|
return help.split("\n\n")[0];
|
|
22
27
|
}
|
|
28
|
+
function getCommandHelp(help, aliases) {
|
|
29
|
+
if (aliases.length === 0) {
|
|
30
|
+
return help;
|
|
31
|
+
}
|
|
32
|
+
const [usage, ...details] = help.split("\n\n");
|
|
33
|
+
const aliasLine = `Alias: ${aliases.map((path) => `zinn ${path.join(" ")}`).join(", ")}`;
|
|
34
|
+
return [usage, aliasLine, ...details].join("\n\n");
|
|
35
|
+
}
|
|
23
36
|
function toCommand(args) {
|
|
24
37
|
return args.join(" ");
|
|
25
38
|
}
|
|
@@ -50,13 +63,13 @@ function formatCommands(parsedRoutes, prefix) {
|
|
|
50
63
|
}
|
|
51
64
|
function getRootHelp(parsedRoutes) {
|
|
52
65
|
// TODO: maybe "brand" text that is exported and used here for title and desc
|
|
53
|
-
return `ZINN - A kanban workflow in the terminal
|
|
66
|
+
return `ZINN - A kanban workflow in the terminal. Experimental.
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
${usageLabel}zinn <command>
|
|
56
69
|
|
|
57
70
|
Options:
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
${helpSpellings.join(", ")} Show help
|
|
72
|
+
${versionSpellings.join(", ")} Show version
|
|
60
73
|
--json Print command output as JSON
|
|
61
74
|
--allow-legacy-read Read a database without a schema version, best effort and read-only
|
|
62
75
|
|
|
@@ -65,16 +78,15 @@ ${formatCommands(parsedRoutes, "")}
|
|
|
65
78
|
|
|
66
79
|
Run zinn <namespace> --help or zinn <command> --help for more information.
|
|
67
80
|
--help shows help for the command words before it and runs nothing. The rest of the line is ignored.
|
|
68
|
-
-- ends the options
|
|
69
|
-
|
|
70
|
-
Running zinn without a command shows this help.`;
|
|
81
|
+
-- ends the options; every word after it is positional, even if it starts with a dash.
|
|
82
|
+
${dashValueHelp("--description")}`;
|
|
71
83
|
}
|
|
72
84
|
function getNamespaceHelp(parsedRoutes, namespace) {
|
|
73
85
|
const commands = formatCommands(parsedRoutes, `${namespace} `);
|
|
74
86
|
if (commands === "") {
|
|
75
87
|
return null;
|
|
76
88
|
}
|
|
77
|
-
return
|
|
89
|
+
return `${usageLabel}zinn ${namespace} <command>\n\nCommands:\n${commands}`;
|
|
78
90
|
}
|
|
79
91
|
// The longest leading run of words that names a namespace, or the root namespace "" when none does.
|
|
80
92
|
function findNearestNamespace(parsedRoutes, words) {
|
|
@@ -97,25 +109,33 @@ function routeToNamespace(parsedRoutes, words, isHelpRequest) {
|
|
|
97
109
|
return;
|
|
98
110
|
}
|
|
99
111
|
if (unknownWord == null) {
|
|
100
|
-
quit(`Missing a command for "${commandName}"`, help);
|
|
112
|
+
quit(`Missing a command for "${commandName}"`, help, { argument: "command" });
|
|
101
113
|
}
|
|
102
114
|
const reason = `Unrecognized command "${unknownWord}" for "${commandName}"`;
|
|
103
115
|
if (isHelpRequest) {
|
|
104
|
-
quit(reason, help);
|
|
116
|
+
quit(reason, help, { argument: "command" });
|
|
105
117
|
}
|
|
106
|
-
quit(`${reason}. Run \`${commandName} --help\` for a list of available commands
|
|
118
|
+
quit(`${reason}. Run \`${commandName} --help\` for a list of available commands`, undefined, {
|
|
119
|
+
argument: "command",
|
|
120
|
+
});
|
|
107
121
|
}
|
|
108
122
|
export function parseRoutes(routesDef, prefix) {
|
|
109
123
|
const routeDefinitions = [];
|
|
110
|
-
if (
|
|
111
|
-
|
|
124
|
+
if (isDebugOutputEnabled()) {
|
|
125
|
+
diagnostic(`::router.parseRoutes[${prefix ?? ""}] ${Object.keys(routesDef).join(" ")}`);
|
|
112
126
|
}
|
|
113
127
|
for (const key of Object.keys(routesDef)) {
|
|
114
128
|
const definition = routesDef[key];
|
|
115
129
|
const isRunnable = getIsRunnable(definition);
|
|
116
130
|
const combinedRoute = prefix ? `${prefix} ${key}` : key;
|
|
117
131
|
if (isRunnable) {
|
|
118
|
-
|
|
132
|
+
const aliases = getCommandAliases(combinedRoute);
|
|
133
|
+
routeDefinitions.push({
|
|
134
|
+
...definition,
|
|
135
|
+
command: combinedRoute,
|
|
136
|
+
aliases,
|
|
137
|
+
help: getCommandHelp(definition.help, aliases),
|
|
138
|
+
});
|
|
119
139
|
}
|
|
120
140
|
else {
|
|
121
141
|
const result = parseRoutes(definition, combinedRoute);
|
|
@@ -124,15 +144,13 @@ export function parseRoutes(routesDef, prefix) {
|
|
|
124
144
|
}
|
|
125
145
|
return routeDefinitions;
|
|
126
146
|
}
|
|
127
|
-
async function route(parsedRoutes, rawArgs) {
|
|
147
|
+
async function route(parsedRoutes, rawArgs, beforeRun) {
|
|
148
|
+
prepareOutput(rawArgs);
|
|
128
149
|
// Anything after "--" belongs to the command, so "--json" there is search text, not a flag.
|
|
129
150
|
const separatorIndex = rawArgs.indexOf("--");
|
|
130
151
|
const routableArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex);
|
|
131
152
|
const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex);
|
|
132
153
|
const filteredRoutableArgs = routableArgs.filter((arg) => !isRouterFlag(arg));
|
|
133
|
-
if (routableArgs.some(isJsonFlag)) {
|
|
134
|
-
setOutputMode("json");
|
|
135
|
-
}
|
|
136
154
|
if (routableArgs.some(isAllowLegacyReadFlag)) {
|
|
137
155
|
setLegacyReadAllowed(true);
|
|
138
156
|
}
|
|
@@ -146,15 +164,15 @@ async function route(parsedRoutes, rawArgs) {
|
|
|
146
164
|
let nestingLevel = 0;
|
|
147
165
|
for (let endIndex = args.length; endIndex >= 0; endIndex--) {
|
|
148
166
|
const command = toCommand(args.slice(0, endIndex));
|
|
149
|
-
const matchedRoute = parsedRoutes.find((r) => r.command === command);
|
|
167
|
+
const matchedRoute = parsedRoutes.find((r) => r.command === command || r.aliases.some((path) => toCommand(path) === command));
|
|
150
168
|
if (matchedRoute) {
|
|
151
169
|
match = matchedRoute;
|
|
152
170
|
nestingLevel = endIndex;
|
|
153
171
|
break;
|
|
154
172
|
}
|
|
155
173
|
}
|
|
156
|
-
if (
|
|
157
|
-
|
|
174
|
+
if (isDebugOutputEnabled()) {
|
|
175
|
+
diagnostic(`::router.route ${match?.command ?? "namespace"}`);
|
|
158
176
|
}
|
|
159
177
|
if (match == null) {
|
|
160
178
|
routeToNamespace(parsedRoutes, args, isHelpRequest);
|
|
@@ -167,19 +185,49 @@ async function route(parsedRoutes, rawArgs) {
|
|
|
167
185
|
validateRouterFlags(routableArgs);
|
|
168
186
|
const commandArgs = args.slice(nestingLevel);
|
|
169
187
|
try {
|
|
188
|
+
await beforeRun?.(match);
|
|
170
189
|
await match.run(commandArgs);
|
|
171
190
|
}
|
|
172
191
|
catch (err) {
|
|
173
192
|
if (err instanceof UsageError) {
|
|
174
|
-
|
|
193
|
+
err.help = getUsage(match.help);
|
|
194
|
+
}
|
|
195
|
+
const columnHint = quotedColumnHint(err, match, rawArgs, nestingLevel);
|
|
196
|
+
if (columnHint !== undefined) {
|
|
197
|
+
const failure = classifyFailure(err);
|
|
198
|
+
throw new CliError(`${failureMessage(err, "Command failed")}. Did you mean: ${columnHint}`, failure.code, failure.details, failure.help ?? getUsage(match.help));
|
|
199
|
+
}
|
|
200
|
+
if (err instanceof UsageError) {
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
if (match.command === "task search") {
|
|
204
|
+
const failure = classifyFailure(err);
|
|
205
|
+
const isMissingProject = failure.code === "not_found" && failure.details?.entity === "project";
|
|
206
|
+
if (isMissingProject) {
|
|
207
|
+
throw new CliError(failureMessage(err, "Search failed"), failure.code, failure.details, getUsage(match.help));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const suggestFor = (flag) => match.guessedFlags?.[flag]?.(commandArgs);
|
|
211
|
+
const parseArgsReason = parseArgsMessage(err, rawArgs, suggestFor);
|
|
212
|
+
if (parseArgsReason != null) {
|
|
213
|
+
const argument = /(?:Unknown option|Option) '(-[^' ]+)/.exec(err.message)?.[1];
|
|
214
|
+
quit(parseArgsReason, getUsage(match.help), argument === undefined ? undefined : { argument });
|
|
175
215
|
}
|
|
176
|
-
|
|
216
|
+
throw err;
|
|
177
217
|
}
|
|
178
218
|
}
|
|
179
|
-
export function createRouter(routesDef) {
|
|
180
|
-
const parsedRoutes = parseRoutes(routesDef);
|
|
219
|
+
export function createRouter(routesDef, beforeRun) {
|
|
220
|
+
const parsedRoutes = Array.isArray(routesDef) ? routesDef : parseRoutes(routesDef);
|
|
181
221
|
return {
|
|
182
|
-
route: (args) =>
|
|
222
|
+
route: async (args) => {
|
|
223
|
+
try {
|
|
224
|
+
await route(parsedRoutes, args, beforeRun);
|
|
225
|
+
flushDiagnostics();
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
renderFailure(error);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
183
231
|
help: getRootHelp(parsedRoutes),
|
|
184
232
|
};
|
|
185
233
|
}
|