@zinn-dev/cli 0.40.0 → 0.41.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 +166 -38
- package/index.js +24 -13
- package/package.json +7 -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 +163 -0
- package/src/capabilities-schema.js +124 -0
- package/src/capabilities.d.ts +21 -0
- package/src/capabilities.js +22 -0
- package/src/database.d.ts +1 -1
- package/src/database.js +4 -4
- package/src/errors.d.ts +158 -0
- package/src/errors.js +224 -0
- package/src/input.d.ts +116 -0
- package/src/input.js +119 -0
- package/src/lib.d.ts +42 -7
- package/src/lib.js +213 -17
- package/src/presentation/activity-presentation.js +16 -2
- package/src/presentation/column-presentation.d.ts +3 -5
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/task-presentation.d.ts +2 -10
- package/src/project.d.ts +6 -0
- package/src/project.js +23 -10
- package/src/result-schemas.d.ts +987 -0
- package/src/result-schemas.js +220 -0
- package/src/results.d.ts +23 -0
- package/src/results.js +17 -0
- package/src/routes/activity-router.d.ts +71 -0
- package/src/routes/activity-router.js +59 -11
- 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 +28 -0
- package/src/routes/comment-router.d.ts +183 -4
- package/src/routes/comment-router.js +136 -29
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +165 -0
- package/src/routes/label-router.js +111 -29
- package/src/routes/migrate-router.d.ts +17 -0
- package/src/routes/migrate-router.js +17 -5
- package/src/routes/project-router.d.ts +349 -0
- package/src/routes/project-router.js +278 -92
- package/src/routes/reindex-router.d.ts +17 -0
- package/src/routes/reindex-router.js +15 -3
- package/src/routes/relation-router.d.ts +108 -12
- package/src/routes/relation-router.js +74 -14
- package/src/routes/restore-router.d.ts +29 -0
- package/src/routes/restore-router.js +30 -13
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +44 -25
- package/src/routes/routes.d.ts +1565 -0
- package/src/routes/routes.js +5 -1
- package/src/routes/task-router.d.ts +861 -0
- package/src/routes/task-router.js +419 -163
- package/src/text-edit.d.ts +20 -2
- package/src/text-edit.js +22 -10
- package/src/types.d.ts +14 -0
package/src/lib.js
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import { assertWritable, ReadOnlyDatabaseError, TextEditMatchError, UnmarkedDatabaseError, } from "@zinn-dev/core";
|
|
3
|
+
import { CliError, classifyFailure } from "./errors.js";
|
|
4
|
+
import { helpSpellings, routerOptionNames, positionalWords } from "./input.js";
|
|
3
5
|
let outputMode = "text";
|
|
4
6
|
let legacyReadAllowed = false;
|
|
7
|
+
const diagnostics = [];
|
|
8
|
+
const DOUBLE_DASH = "--";
|
|
5
9
|
export function setOutputMode(mode) {
|
|
6
10
|
outputMode = mode;
|
|
7
11
|
}
|
|
12
|
+
/** Selects output before routing, without treating words after `--` as flags. */
|
|
13
|
+
export function prepareOutput(args) {
|
|
14
|
+
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
15
|
+
const options = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
16
|
+
setOutputMode(options.some(isJsonFlag) ? "json" : "text");
|
|
17
|
+
}
|
|
18
|
+
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
19
|
+
export function diagnostic(message) {
|
|
20
|
+
if (outputMode === "json") {
|
|
21
|
+
diagnostics.push(message);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.error(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function flushDiagnostics() {
|
|
28
|
+
for (const message of diagnostics.splice(0)) {
|
|
29
|
+
console.error(message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
8
32
|
export function isJsonFlag(flag) {
|
|
9
|
-
return flag ===
|
|
33
|
+
return flag === `--${routerOptionNames.json}`;
|
|
10
34
|
}
|
|
11
35
|
export function isAllowLegacyReadFlag(flag) {
|
|
12
|
-
return flag ===
|
|
36
|
+
return flag === `--${routerOptionNames.legacyRead}`;
|
|
37
|
+
}
|
|
38
|
+
/** A flag the router reads wherever it appears before --, for every command. */
|
|
39
|
+
export function isRouterFlag(flag) {
|
|
40
|
+
return isJsonFlag(flag) || isAllowLegacyReadFlag(flag);
|
|
13
41
|
}
|
|
14
42
|
export function setLegacyReadAllowed(allowed) {
|
|
15
43
|
legacyReadAllowed = allowed;
|
|
@@ -33,17 +61,18 @@ export async function confirmAction(message, isPreconfirmed, jsonRefusal) {
|
|
|
33
61
|
assertWritable();
|
|
34
62
|
return askConfirmation(message, isPreconfirmed, jsonRefusal);
|
|
35
63
|
}
|
|
64
|
+
export const confirmationDescription = "Requires --yes with --json or without a terminal. Otherwise prompts on stderr and only y or Y confirms. Declining exits successfully without the requested mutation; interruption exits 130.";
|
|
36
65
|
/** Like confirmAction, without opening the database, for commands that bypass the open policy. */
|
|
37
66
|
export async function askConfirmation(message, isPreconfirmed, jsonRefusal = "Commands that ask for confirmation need --yes when used with --json") {
|
|
38
67
|
if (isPreconfirmed) {
|
|
39
68
|
return true;
|
|
40
69
|
}
|
|
41
70
|
if (outputMode === "json") {
|
|
42
|
-
quit(jsonRefusal);
|
|
71
|
+
quit(jsonRefusal, undefined, { argument: "--yes", reason: "confirmation_required" });
|
|
43
72
|
}
|
|
44
73
|
// Refuses rather than treating an unanswered prompt as declined, so scripts do not see a false success
|
|
45
74
|
if (!canPrompt()) {
|
|
46
|
-
quit("Commands that ask for confirmation need --yes when not running in a terminal");
|
|
75
|
+
quit("Commands that ask for confirmation need --yes when not running in a terminal", undefined, { argument: "--yes", reason: "confirmation_required" });
|
|
47
76
|
}
|
|
48
77
|
const prompt = createInterface({ input: process.stdin, output: process.stderr });
|
|
49
78
|
const closed = new AbortController();
|
|
@@ -86,40 +115,70 @@ export function failureMessage(error, fallback) {
|
|
|
86
115
|
if (error?.message === "no such table: task_search") {
|
|
87
116
|
return `${error.message}. Run \`zinn reindex\` to rebuild the search index.`;
|
|
88
117
|
}
|
|
89
|
-
return error?.message
|
|
118
|
+
return typeof error?.message === "string" ? error.message : fallback;
|
|
90
119
|
}
|
|
91
|
-
/**
|
|
92
|
-
export function quit(reason, help) {
|
|
120
|
+
/** Stops a command while retaining its classified error for the outer renderer. */
|
|
121
|
+
export function quit(reason, help, details) {
|
|
122
|
+
if (reason instanceof Error) {
|
|
123
|
+
throw reason;
|
|
124
|
+
}
|
|
125
|
+
throw new CliError(reason, "invalid_input", details, help);
|
|
126
|
+
}
|
|
127
|
+
/** Emits one handled failure, including any notices collected before it. */
|
|
128
|
+
export function renderFailure(reason) {
|
|
129
|
+
const failure = {
|
|
130
|
+
...classifyFailure(reason),
|
|
131
|
+
message: failureMessage(reason, "Something went wrong"),
|
|
132
|
+
};
|
|
133
|
+
const pendingDiagnostics = diagnostics.splice(0);
|
|
93
134
|
if (outputMode === "json") {
|
|
94
|
-
const
|
|
135
|
+
const details = failure.details === undefined
|
|
136
|
+
? undefined
|
|
137
|
+
: Object.fromEntries(Object.entries(failure.details).filter(([, value]) => value !== undefined));
|
|
138
|
+
const error = {
|
|
139
|
+
...failure,
|
|
140
|
+
details: details !== undefined && Object.keys(details).length > 0 ? details : undefined,
|
|
141
|
+
diagnostics: pendingDiagnostics.length > 0 ? pendingDiagnostics : undefined,
|
|
142
|
+
};
|
|
95
143
|
console.error(JSON.stringify({ error }, null, 2));
|
|
96
144
|
}
|
|
97
145
|
else {
|
|
98
|
-
|
|
146
|
+
for (const message of pendingDiagnostics) {
|
|
147
|
+
console.error(message);
|
|
148
|
+
}
|
|
149
|
+
console.error(failure.help == null ? failure.message : `${failure.message}\n\n${failure.help}`);
|
|
99
150
|
}
|
|
100
|
-
|
|
151
|
+
// Let piped stderr finish writing before Node exits
|
|
152
|
+
process.stderr.write("", () => process.exit(1));
|
|
101
153
|
}
|
|
102
154
|
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
103
|
-
export class UsageError extends
|
|
155
|
+
export class UsageError extends CliError {
|
|
156
|
+
constructor(message, details) {
|
|
157
|
+
super(message, "invalid_input", details);
|
|
158
|
+
}
|
|
104
159
|
}
|
|
105
160
|
/**
|
|
106
161
|
* Checks a command's words against its usage line, with the words written the same way:
|
|
107
162
|
* `<task-key>` is required, `[<project-key>]` is optional and `<task-key>...` repeats.
|
|
108
163
|
* Optional words go last.
|
|
109
164
|
*/
|
|
110
|
-
export function validatePositionals(positionals,
|
|
165
|
+
export function validatePositionals(positionals, form) {
|
|
166
|
+
const words = positionalWords(form);
|
|
111
167
|
const requiredWords = words.filter((word) => !word.startsWith("["));
|
|
112
168
|
const missingWord = requiredWords[positionals.length];
|
|
113
169
|
if (missingWord !== undefined) {
|
|
114
|
-
throw new UsageError(`Missing argument ${missingWord}
|
|
170
|
+
throw new UsageError(`Missing argument ${missingWord}`, {
|
|
171
|
+
argument: missingWord.replaceAll(/[\[\]<>]/g, "").replace(/\.\.\.$/, ""),
|
|
172
|
+
});
|
|
115
173
|
}
|
|
116
174
|
const hasRepeatingWord = words.some((word) => word.endsWith("..."));
|
|
117
175
|
const extraWord = positionals[words.length];
|
|
118
176
|
if (!hasRepeatingWord && extraWord !== undefined) {
|
|
119
|
-
throw new UsageError(`Unexpected argument "${extraWord}"
|
|
177
|
+
throw new UsageError(`Unexpected argument "${extraWord}"`, { field: [] });
|
|
120
178
|
}
|
|
121
179
|
}
|
|
122
|
-
export function validateUniqueOptions(tokens,
|
|
180
|
+
export function validateUniqueOptions(tokens, options) {
|
|
181
|
+
const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
|
|
123
182
|
const parsedArgs = new Set();
|
|
124
183
|
for (const token of tokens) {
|
|
125
184
|
if (token.kind !== "option") {
|
|
@@ -127,11 +186,148 @@ export function validateUniqueOptions(tokens, repeatableOptions = []) {
|
|
|
127
186
|
}
|
|
128
187
|
const isRepeatable = repeatableOptions.includes(token.name);
|
|
129
188
|
if (parsedArgs.has(token.name) && !isRepeatable) {
|
|
130
|
-
quit(`Option "--${token.name}" can only be specified once
|
|
189
|
+
quit(`Option "--${token.name}" can only be specified once`, undefined, {
|
|
190
|
+
argument: `--${token.name}`,
|
|
191
|
+
});
|
|
131
192
|
}
|
|
132
193
|
parsedArgs.add(token.name);
|
|
133
194
|
}
|
|
134
195
|
}
|
|
196
|
+
/** Selects an order form after checking its required leading words. */
|
|
197
|
+
export function validateOrderForms(positionals, forms) {
|
|
198
|
+
const firstForm = forms[0];
|
|
199
|
+
const directionIndex = firstForm.positionals.findIndex(({ name }) => name === "direction");
|
|
200
|
+
const leadingPositionals = firstForm.positionals.slice(0, directionIndex + 1);
|
|
201
|
+
const directions = forms.flatMap((form) => form.positionals[directionIndex].value.choices);
|
|
202
|
+
leadingPositionals[directionIndex] = {
|
|
203
|
+
...leadingPositionals[directionIndex],
|
|
204
|
+
value: { kind: "enum", choices: directions },
|
|
205
|
+
};
|
|
206
|
+
validatePositionals(positionals.slice(0, leadingPositionals.length), {
|
|
207
|
+
id: "leading",
|
|
208
|
+
positionals: leadingPositionals,
|
|
209
|
+
});
|
|
210
|
+
const direction = positionals[directionIndex];
|
|
211
|
+
const form = forms.find((candidate) => candidate.positionals[directionIndex].value.choices.includes(direction));
|
|
212
|
+
if (form === undefined) {
|
|
213
|
+
throw new UsageError(`Unknown order direction "${direction}"`, { argument: "direction" });
|
|
214
|
+
}
|
|
215
|
+
validatePositionals(positionals, form);
|
|
216
|
+
return form;
|
|
217
|
+
}
|
|
218
|
+
export function requireStringOption(option, value, name, message) {
|
|
219
|
+
if (value === undefined) {
|
|
220
|
+
quit(message, undefined, { argument: `--${name}` });
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
135
224
|
export function isHelpFlag(flag) {
|
|
136
|
-
return
|
|
225
|
+
return helpSpellings.includes(flag);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
229
|
+
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
230
|
+
* was forgotten, so we respect that refusal and not take the next word as the value
|
|
231
|
+
* @see {@link https://github.com/pkgjs/parseargs/issues/77}
|
|
232
|
+
*/
|
|
233
|
+
export function dashValueHelp(flag) {
|
|
234
|
+
return `A value that begins with a dash must be joined to its flag with =, as in ${flag}='- item'.`;
|
|
235
|
+
}
|
|
236
|
+
// "Option '--title' argument is ambiguous."
|
|
237
|
+
const DASH_VALUE_ERROR_PATTERN = /^Option '(--[^']+)' argument is ambiguous\./;
|
|
238
|
+
// The characters Python's `shlex.quote` leaves unquoted.
|
|
239
|
+
const SHELL_SAFE_WORD_PATTERN = /^[\w@%+=:,./-]+$/;
|
|
240
|
+
/** Quotes a word for a POSIX shell when it needs it, like Python's `shlex.quote` */
|
|
241
|
+
export function shellQuote(word) {
|
|
242
|
+
if (SHELL_SAFE_WORD_PATTERN.test(word)) {
|
|
243
|
+
return word;
|
|
244
|
+
}
|
|
245
|
+
return `'${word.replaceAll("'", `'\\''`)}'`;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The message for `parseArgs` refusal of a value that begins with a dash, showing the user's
|
|
249
|
+
* command with that value joined to its flag.
|
|
250
|
+
* `null` for any other error
|
|
251
|
+
*/
|
|
252
|
+
function dashValueMessage(error, args) {
|
|
253
|
+
const isInvalidOptionValue = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE";
|
|
254
|
+
const flag = isInvalidOptionValue ? DASH_VALUE_ERROR_PATTERN.exec(error.message)?.[1] : undefined;
|
|
255
|
+
const flagIndex = args.findIndex((arg, index) => arg === flag && args[index + 1]?.startsWith("-"));
|
|
256
|
+
if (flagIndex === -1) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const value = args[flagIndex + 1];
|
|
260
|
+
const fixedCommand = [
|
|
261
|
+
"zinn",
|
|
262
|
+
...args.slice(0, flagIndex).map(shellQuote),
|
|
263
|
+
`${flag}=${shellQuote(value)}`,
|
|
264
|
+
...args.slice(flagIndex + 2).map(shellQuote),
|
|
265
|
+
].join(" ");
|
|
266
|
+
return `Option "${flag}" is followed by "${value}", which begins with a dash. If it is the value, join it to the flag with =: ${fixedCommand}`;
|
|
267
|
+
}
|
|
268
|
+
// "Unknown option '--project'."
|
|
269
|
+
const UNKNOWN_LONG_OPTION_PATTERN = /^Unknown option '(--[^']+)'/;
|
|
270
|
+
// A word that begins with a single dash, such as -later.
|
|
271
|
+
const SHORT_OPTION_WORD_PATTERN = /^-[^-]/;
|
|
272
|
+
/** A command line to show, with each word quoted for the shell as needed. */
|
|
273
|
+
function formatCommand(args) {
|
|
274
|
+
return ["zinn", ...args].map(shellQuote).join(" ");
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The message for `parseArgs` refusal of an unknown option.
|
|
278
|
+
* A long flag is named, with the command the user likely meant when one is known,
|
|
279
|
+
* and otherwise the usage line shown with it is the fix.
|
|
280
|
+
* A word with a single dash shows the user's command with it after `--`.
|
|
281
|
+
*/
|
|
282
|
+
function unknownOptionMessage(message, args, suggestFor) {
|
|
283
|
+
const flag = UNKNOWN_LONG_OPTION_PATTERN.exec(message)?.[1];
|
|
284
|
+
if (flag !== undefined) {
|
|
285
|
+
const suggestion = suggestFor(flag);
|
|
286
|
+
const reason = `Unknown option "${flag}"`;
|
|
287
|
+
return suggestion === undefined
|
|
288
|
+
? reason
|
|
289
|
+
: `${reason}. Did you mean: ${formatCommand([...suggestion, ...args.filter(isRouterFlag)])}`;
|
|
290
|
+
}
|
|
291
|
+
// Commands define no short options, so `parseArgs` refused the first single-dash word before `--`.
|
|
292
|
+
const separatorIndex = args.indexOf(DOUBLE_DASH);
|
|
293
|
+
const optionArgs = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
294
|
+
const wordIndex = optionArgs.findIndex((arg) => SHORT_OPTION_WORD_PATTERN.test(arg));
|
|
295
|
+
if (wordIndex === -1) {
|
|
296
|
+
return message;
|
|
297
|
+
}
|
|
298
|
+
const word = args[wordIndex];
|
|
299
|
+
const readOptions = [...word.slice(1)].map((letter) => `-${letter}`);
|
|
300
|
+
const readAs = readOptions.length > 1 ? ` (Zinn read ${word} as ${readOptions.join(" ")})` : "";
|
|
301
|
+
const reason = `Unknown option "${readOptions[0]}"${readAs}. If it is a value, put it after --`;
|
|
302
|
+
// Flags after the word must stay before --, and only the router's own flags are known to be flags.
|
|
303
|
+
const wordsAfter = args.slice(wordIndex + 1);
|
|
304
|
+
const routerFlagsAfter = wordsAfter.filter(isRouterFlag);
|
|
305
|
+
const plainWordsAfter = wordsAfter.filter((arg) => !isRouterFlag(arg));
|
|
306
|
+
if (plainWordsAfter.some((arg) => arg.startsWith("-"))) {
|
|
307
|
+
return `${reason}.`;
|
|
308
|
+
}
|
|
309
|
+
const fixedCommand = formatCommand([
|
|
310
|
+
...args.slice(0, wordIndex),
|
|
311
|
+
...routerFlagsAfter,
|
|
312
|
+
DOUBLE_DASH,
|
|
313
|
+
word,
|
|
314
|
+
...plainWordsAfter,
|
|
315
|
+
]);
|
|
316
|
+
return `${reason}: ${fixedCommand}`;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
320
|
+
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
321
|
+
* `null` for any other error.
|
|
322
|
+
*/
|
|
323
|
+
export function parseArgsMessage(error, args, suggestFor) {
|
|
324
|
+
const code = error?.code;
|
|
325
|
+
const isParseArgsError = typeof code === "string" && code.startsWith("ERR_PARSE_ARGS_");
|
|
326
|
+
if (!isParseArgsError) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
330
|
+
return unknownOptionMessage(error.message, args, suggestFor);
|
|
331
|
+
}
|
|
332
|
+
return dashValueMessage(error, args) ?? error.message;
|
|
137
333
|
}
|
|
@@ -25,6 +25,17 @@ const RECORDED_FIELDS = new Set([
|
|
|
25
25
|
"text",
|
|
26
26
|
]);
|
|
27
27
|
const ENTITY_PREVIEW_LENGTH = 24;
|
|
28
|
+
const UNKNOWN_ACTOR_NAME = "unknown";
|
|
29
|
+
const ACTOR_DETAIL_FIELDS = [
|
|
30
|
+
{ key: "actor_kind", label: "Kind" },
|
|
31
|
+
{ key: "actor_email", label: "Email" },
|
|
32
|
+
{ key: "actor_source", label: "Source" },
|
|
33
|
+
{ key: "actor_session_id", label: "Session" },
|
|
34
|
+
{ key: "actor_thread_id", label: "Thread" },
|
|
35
|
+
{ key: "actor_agent", label: "Agent" },
|
|
36
|
+
{ key: "actor_model", label: "Model" },
|
|
37
|
+
{ key: "actor_effort", label: "Effort" },
|
|
38
|
+
];
|
|
28
39
|
const ACTION_LABELS = {
|
|
29
40
|
create: "created",
|
|
30
41
|
edit: "edited",
|
|
@@ -360,7 +371,7 @@ export function formatActivityList(entries, options = {}) {
|
|
|
360
371
|
const metadata = [
|
|
361
372
|
{ text: entry.displayId },
|
|
362
373
|
{ text: formatLocalTime(entry.event.created_at), style: "dim" },
|
|
363
|
-
{ text: `${entry.event.actor_name} (${entry.event.actor_kind})` },
|
|
374
|
+
{ text: `${entry.event.actor_name ?? UNKNOWN_ACTOR_NAME} (${entry.event.actor_kind})` },
|
|
364
375
|
];
|
|
365
376
|
if (!options.showsDetails) {
|
|
366
377
|
return [...metadata, { text: formatActivityContent(entry) }];
|
|
@@ -382,7 +393,10 @@ export function formatActivityList(entries, options = {}) {
|
|
|
382
393
|
...(entry.navigation.name === undefined
|
|
383
394
|
? []
|
|
384
395
|
: [formatSection("Navigation", formatNavigation(entry, { showsFullNames: true }))]),
|
|
385
|
-
formatSection("Actor",
|
|
396
|
+
formatSection("Actor", [
|
|
397
|
+
entry.event.actor_name ?? UNKNOWN_ACTOR_NAME,
|
|
398
|
+
...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${entry.event[key] ?? "null"}`),
|
|
399
|
+
].join("\n")),
|
|
386
400
|
formatSection("Changes", formatRecordedChanges(entry.event)),
|
|
387
401
|
].join("\n\n"))
|
|
388
402
|
.join("\n\n");
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { RowCell } from "./row-layout.js";
|
|
2
|
-
|
|
2
|
+
type ColumnRow = {
|
|
3
3
|
name: string;
|
|
4
4
|
project?: string;
|
|
5
5
|
taskCount?: number;
|
|
6
6
|
};
|
|
7
|
-
export type PresentedColumnTaskCount = PresentedColumn & {
|
|
8
|
-
taskCount: number;
|
|
9
|
-
};
|
|
10
7
|
export declare function columnNameCell(columnName: string): RowCell;
|
|
11
8
|
/** The archived row is left out when there are no archived tasks. */
|
|
12
|
-
export declare function formatColumnList(presentedColumns: Array<
|
|
9
|
+
export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
|
|
13
10
|
showsProject?: boolean;
|
|
14
11
|
showsTaskCounts?: boolean;
|
|
15
12
|
archivedTaskCount?: number;
|
|
16
13
|
}): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
2
|
+
export function presentInfo(report) {
|
|
3
|
+
const bunVersion = process.versions.bun;
|
|
4
|
+
return {
|
|
5
|
+
settingsFiles: report.settingsFiles,
|
|
6
|
+
storage: report.storage,
|
|
7
|
+
defaultProject: report.defaultProject,
|
|
8
|
+
database: report.database,
|
|
9
|
+
versions: {
|
|
10
|
+
cli: packageJson.version,
|
|
11
|
+
core: report.coreVersion,
|
|
12
|
+
runtime: {
|
|
13
|
+
name: bunVersion === undefined ? "Node" : "Bun",
|
|
14
|
+
version: bunVersion ?? process.versions.node,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function storeSource(storage) {
|
|
20
|
+
if (storage.settingsPath !== null) {
|
|
21
|
+
return storage.settingsPath;
|
|
22
|
+
}
|
|
23
|
+
return storage.source === "env" ? "ZINN_DIR" : "default";
|
|
24
|
+
}
|
|
25
|
+
function folderState(storage) {
|
|
26
|
+
if (storage.error !== null) {
|
|
27
|
+
return storage.error;
|
|
28
|
+
}
|
|
29
|
+
if (storage.exists === null) {
|
|
30
|
+
return "unavailable";
|
|
31
|
+
}
|
|
32
|
+
return storage.exists ? "found" : "missing";
|
|
33
|
+
}
|
|
34
|
+
function databaseState(database) {
|
|
35
|
+
if (database.error !== null) {
|
|
36
|
+
return database.error;
|
|
37
|
+
}
|
|
38
|
+
return `${database.state}; schema ${database.version ?? "unavailable"}, latest ${database.latestVersion}`;
|
|
39
|
+
}
|
|
40
|
+
export function formatInfo(report) {
|
|
41
|
+
const { storage, database, defaultProject, versions } = report;
|
|
42
|
+
const storeIsUnavailable = storage.directory === null;
|
|
43
|
+
//
|
|
44
|
+
/**
|
|
45
|
+
* A settings file's error text prints once, on its own line in the Settings list
|
|
46
|
+
* Other fields point to the file
|
|
47
|
+
*/
|
|
48
|
+
const unavailableReason = (error) => {
|
|
49
|
+
const file = report.settingsFiles.find((candidate) => candidate.state === "error" && candidate.error === error);
|
|
50
|
+
return file === undefined ? error : `settings file ${file.path} cannot be used`;
|
|
51
|
+
};
|
|
52
|
+
const storeHeader = storeIsUnavailable
|
|
53
|
+
? `unavailable${storage.error === null ? "" : ` (${unavailableReason(storage.error)})`}`
|
|
54
|
+
: `${storage.directory} (${storeSource(storage)})`;
|
|
55
|
+
const defaultProjectText = defaultProject.error === null
|
|
56
|
+
? (defaultProject.key ?? "not configured")
|
|
57
|
+
: `unavailable (${unavailableReason(defaultProject.error)})`;
|
|
58
|
+
const defaultProjectSuffix = defaultProject.settingsPath === null ? "" : ` (${defaultProject.settingsPath})`;
|
|
59
|
+
const lines = [
|
|
60
|
+
`Store: ${storeHeader}`,
|
|
61
|
+
`Store folder: ${storeIsUnavailable ? "unavailable" : folderState(storage)}`,
|
|
62
|
+
`Database: ${database.path ?? "unavailable"}`,
|
|
63
|
+
`Database state: ${storeIsUnavailable ? "unavailable" : databaseState(database)}`,
|
|
64
|
+
`Default project: ${defaultProjectText}${defaultProjectSuffix}`,
|
|
65
|
+
"",
|
|
66
|
+
"Settings:",
|
|
67
|
+
];
|
|
68
|
+
for (const file of report.settingsFiles) {
|
|
69
|
+
let state;
|
|
70
|
+
switch (file.state) {
|
|
71
|
+
case "found":
|
|
72
|
+
state = "found";
|
|
73
|
+
break;
|
|
74
|
+
case "missing":
|
|
75
|
+
state = "not configured";
|
|
76
|
+
break;
|
|
77
|
+
case "error":
|
|
78
|
+
state = file.error;
|
|
79
|
+
break;
|
|
80
|
+
case "not-read":
|
|
81
|
+
state = `not read (${file.reason} is set)`;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
lines.push(`${file.path}: ${state}`);
|
|
85
|
+
if (file.state === "found") {
|
|
86
|
+
if (file.settings.storage !== undefined) {
|
|
87
|
+
lines.push(` storage.directory: ${file.settings.storage.directory}`);
|
|
88
|
+
}
|
|
89
|
+
if (file.settings.defaultProject !== undefined) {
|
|
90
|
+
lines.push(` defaultProject: ${file.settings.defaultProject}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
lines.push("", `CLI: ${versions.cli}`, `Core: ${versions.core}`, `Runtime: ${versions.runtime.name} ${versions.runtime.version}`);
|
|
95
|
+
return lines.join("\n");
|
|
96
|
+
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
key: string;
|
|
4
|
-
status: "Active" | "Archived";
|
|
5
|
-
column: string;
|
|
6
|
-
title: string;
|
|
7
|
-
description: string | null;
|
|
8
|
-
priority: TaskPriority | null;
|
|
9
|
-
labels: Array<string>;
|
|
10
|
-
};
|
|
1
|
+
import type { TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedTask } from "../result-schemas.js";
|
|
11
3
|
export declare function presentTask(taskMatch: TaskWithKey): PresentedTask;
|
|
12
4
|
export declare function formatTaskRow(presented: PresentedTask): string;
|
|
13
5
|
export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
|
package/src/project.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export declare const projectScopeConstraint: {
|
|
2
|
+
readonly kind: "exclusive";
|
|
3
|
+
readonly members: readonly ["positional:project-key", "option:all-projects"];
|
|
4
|
+
};
|
|
5
|
+
export declare const requiredProjectDescription = "An omitted project key uses defaultProject from settings. Without a configured default, a project key is required. A missing configured project is an error.";
|
|
6
|
+
export declare const projectScopeDescription = "An omitted project key defaults to all projects unless defaultProject is configured. --all-projects overrides the defaultProject and excludes a typed project. A missing configured project is an error.";
|
|
1
7
|
/** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
|
|
2
8
|
export declare function resolveProjectKey(typedKey: string | undefined, { required, allProjects, useDefault, }?: {
|
|
3
9
|
required?: boolean;
|
package/src/project.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { project, resolveSettings } from "@zinn-dev/core";
|
|
2
|
+
import { chooseDefaultProject, project, resolveSettings } from "@zinn-dev/core";
|
|
3
3
|
import { UsageError } from "./lib.js";
|
|
4
|
+
import { CliError } from "./errors.js";
|
|
5
|
+
import { violatesConstraint } from "./input.js";
|
|
6
|
+
export const projectScopeConstraint = {
|
|
7
|
+
kind: "exclusive",
|
|
8
|
+
members: ["positional:project-key", "option:all-projects"],
|
|
9
|
+
};
|
|
10
|
+
export const requiredProjectDescription = "An omitted project key uses defaultProject from settings. Without a configured default, a project key is required. A missing configured project is an error.";
|
|
11
|
+
export const projectScopeDescription = "An omitted project key defaults to all projects unless defaultProject is configured. --all-projects overrides the defaultProject and excludes a typed project. A missing configured project is an error.";
|
|
4
12
|
/** Chooses the explicit project or the configured default, retaining unscoped list/search behavior. */
|
|
5
13
|
export function resolveProjectKey(typedKey, { required = false, allProjects = false, useDefault = true, } = {}) {
|
|
6
14
|
if (allProjects) {
|
|
7
|
-
if (
|
|
8
|
-
|
|
15
|
+
if (violatesConstraint(projectScopeConstraint, {
|
|
16
|
+
"positional:project-key": typedKey,
|
|
17
|
+
"option:all-projects": allProjects,
|
|
18
|
+
})) {
|
|
19
|
+
throw new UsageError("--all-projects cannot be combined with a project key", {
|
|
20
|
+
argument: "--all-projects",
|
|
21
|
+
});
|
|
9
22
|
}
|
|
10
23
|
return undefined;
|
|
11
24
|
}
|
|
@@ -16,16 +29,16 @@ export function resolveProjectKey(typedKey, { required = false, allProjects = fa
|
|
|
16
29
|
return undefined;
|
|
17
30
|
}
|
|
18
31
|
const settings = resolveSettings({ cwd: process.cwd(), env: process.env, home: homedir() });
|
|
19
|
-
const defaultProject = settings
|
|
20
|
-
if (defaultProject ===
|
|
32
|
+
const defaultProject = chooseDefaultProject(settings);
|
|
33
|
+
if (defaultProject === null) {
|
|
21
34
|
if (required) {
|
|
22
|
-
throw new UsageError("Missing argument <project-key>. Supply a key or configure defaultProject");
|
|
35
|
+
throw new UsageError("Missing argument <project-key>. Supply a key or configure defaultProject", { argument: "project-key" });
|
|
23
36
|
}
|
|
24
37
|
return undefined;
|
|
25
38
|
}
|
|
26
|
-
const
|
|
27
|
-
if (project.getByKey(
|
|
28
|
-
throw new
|
|
39
|
+
const { key, settingsPath } = defaultProject;
|
|
40
|
+
if (project.getByKey(key) == null) {
|
|
41
|
+
throw new CliError(`Default project "${key}" from settings file ${settingsPath} does not exist`, "not_found", { entity: "project", key, source: "defaultProject", settingsPath });
|
|
29
42
|
}
|
|
30
|
-
return
|
|
43
|
+
return key;
|
|
31
44
|
}
|