@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.
- package/README.md +1 -1
- package/package.json +3 -3
- package/skills/zinn/SKILL.md +7 -9
- package/src/actor.d.ts +1 -1
- package/src/actor.js +4 -1
- package/src/capabilities-schema.d.ts +9 -1
- package/src/column-hint.js +1 -3
- 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 +26 -0
- package/src/errors.js +46 -8
- package/src/expected-values.d.ts +48 -0
- package/src/expected-values.js +60 -0
- package/src/follow.d.ts +9 -0
- package/src/follow.js +58 -0
- package/src/input.d.ts +0 -8
- package/src/input.js +36 -16
- package/src/lib.d.ts +7 -3
- package/src/lib.js +70 -28
- package/src/list-continuation.js +1 -4
- package/src/presentation/activity-presentation.d.ts +2 -0
- package/src/presentation/activity-presentation.js +60 -3
- package/src/presentation/column-presentation.d.ts +9 -4
- package/src/presentation/column-presentation.js +29 -12
- package/src/presentation/doctor-presentation.d.ts +10 -0
- package/src/presentation/doctor-presentation.js +28 -0
- package/src/presentation/relation-presentation.js +2 -1
- package/src/presentation/skill-status-presentation.d.ts +9 -0
- package/src/presentation/skill-status-presentation.js +43 -0
- package/src/presentation/task-blame-presentation.d.ts +2 -4
- package/src/presentation/task-blame-presentation.js +4 -2
- package/src/presentation/task-presentation.d.ts +18 -4
- package/src/presentation/task-presentation.js +94 -30
- package/src/result-schemas.d.ts +490 -58
- package/src/result-schemas.js +97 -2
- package/src/results.d.ts +6 -2
- package/src/results.js +9 -3
- package/src/routes/activity-router.d.ts +16 -5
- package/src/routes/activity-router.js +131 -70
- package/src/routes/aliases.js +1 -0
- package/src/routes/backup-router.d.ts +1 -0
- package/src/routes/backup-router.js +4 -3
- package/src/routes/capabilities-router.d.ts +1 -0
- package/src/routes/capabilities-router.js +1 -1
- package/src/routes/comment-router.d.ts +29 -6
- package/src/routes/comment-router.js +20 -10
- package/src/routes/doctor-router.d.ts +40 -0
- package/src/routes/doctor-router.js +83 -0
- package/src/routes/info-router.d.ts +1 -0
- package/src/routes/info-router.js +1 -1
- package/src/routes/label-router.d.ts +44 -6
- package/src/routes/label-router.js +27 -10
- package/src/routes/migrate-router.d.ts +1 -0
- package/src/routes/migrate-router.js +5 -7
- package/src/routes/project-router.d.ts +70 -11
- package/src/routes/project-router.js +130 -56
- package/src/routes/reindex-router.d.ts +1 -0
- package/src/routes/reindex-router.js +1 -1
- package/src/routes/relation-router.d.ts +3 -0
- package/src/routes/relation-router.js +9 -6
- package/src/routes/restore-router.d.ts +1 -0
- package/src/routes/restore-router.js +5 -6
- package/src/routes/router.js +5 -9
- package/src/routes/routes.d.ts +517 -35
- package/src/routes/routes.js +4 -0
- package/src/routes/skill-router.d.ts +76 -0
- package/src/routes/skill-router.js +179 -0
- package/src/routes/task-router.d.ts +264 -13
- package/src/routes/task-router.js +415 -93
- package/src/routes/whoami-router.d.ts +1 -0
- package/src/routes/whoami-router.js +1 -1
- package/src/skill-copies.d.ts +34 -0
- package/src/skill-copies.js +109 -0
- package/src/telemetry.d.ts +2 -2
- package/src/telemetry.js +8 -3
- package/src/text-edit.d.ts +2 -2
- package/src/text-input.d.ts +19 -1
- package/src/text-input.js +26 -5
- package/src/types.d.ts +4 -0
- package/src/types.js +6 -0
package/src/follow.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { finishRun } from "./lib.js";
|
|
2
|
+
/** How often a following command looks for new commits. GNU `tail -f` sleeps one second between checks by default. */
|
|
3
|
+
export const FOLLOW_POLL_INTERVAL_MS = 1_000;
|
|
4
|
+
const INTERRUPT_SIGNAL = "SIGINT";
|
|
5
|
+
const CLOSED_PIPE_CODE = "EPIPE";
|
|
6
|
+
/**
|
|
7
|
+
* Calls poll every interval until the command is stopped.
|
|
8
|
+
* Resolves when the reader of stdout has closed it, which a write reports.
|
|
9
|
+
* Rejects with what poll throws, which is how poll ends the command.
|
|
10
|
+
* An interrupt ends the process by its signal, as it ends a command that handles no signal.
|
|
11
|
+
*/
|
|
12
|
+
export function followUntilStopped(poll) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const stopped = new AbortController();
|
|
15
|
+
let timer;
|
|
16
|
+
function stopPolling() {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
stopped.abort();
|
|
19
|
+
process.off(INTERRUPT_SIGNAL, interrupt);
|
|
20
|
+
}
|
|
21
|
+
async function pollOnce() {
|
|
22
|
+
try {
|
|
23
|
+
await poll(stopped.signal);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!stopped.signal.aborted) {
|
|
27
|
+
stopPolling();
|
|
28
|
+
reject(error);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!stopped.signal.aborted) {
|
|
33
|
+
timer = setTimeout(pollOnce, FOLLOW_POLL_INTERVAL_MS);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function interrupt() {
|
|
37
|
+
stopPolling();
|
|
38
|
+
finishRun();
|
|
39
|
+
// The listener is gone, so the signal now ends the process and the shell sees an interrupt.
|
|
40
|
+
process.kill(process.pid, INTERRUPT_SIGNAL);
|
|
41
|
+
}
|
|
42
|
+
process.once(INTERRUPT_SIGNAL, interrupt);
|
|
43
|
+
// Stays attached, so a write already on its way to the closed pipe cannot crash the process.
|
|
44
|
+
process.stdout.on("error", (error) => {
|
|
45
|
+
if (stopped.signal.aborted) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
stopPolling();
|
|
49
|
+
if (error.code === CLOSED_PIPE_CODE) {
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
reject(error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
timer = setTimeout(pollOnce, FOLLOW_POLL_INTERVAL_MS);
|
|
57
|
+
});
|
|
58
|
+
}
|
package/src/input.d.ts
CHANGED
|
@@ -173,21 +173,16 @@ export declare const archiveConstraint: {
|
|
|
173
173
|
};
|
|
174
174
|
export declare const routerOptionNames: {
|
|
175
175
|
readonly json: "json";
|
|
176
|
-
readonly legacyRead: "allow-legacy-read";
|
|
177
176
|
};
|
|
178
177
|
export declare const routerOptions: {
|
|
179
178
|
readonly json: {
|
|
180
179
|
readonly type: "boolean";
|
|
181
180
|
};
|
|
182
|
-
readonly "allow-legacy-read": {
|
|
183
|
-
readonly type: "boolean";
|
|
184
|
-
};
|
|
185
181
|
};
|
|
186
182
|
export declare const helpSpellings: readonly string[];
|
|
187
183
|
export declare const versionSpellings: readonly string[];
|
|
188
184
|
export declare const OPTION_SEPARATOR = "--";
|
|
189
185
|
export declare function isJsonFlag(flag: string): boolean;
|
|
190
|
-
export declare function isAllowLegacyReadFlag(flag: string): boolean;
|
|
191
186
|
/** A flag the router reads wherever it appears before --, for every command. */
|
|
192
187
|
export declare function isRouterFlag(flag: string): boolean;
|
|
193
188
|
export declare function isHelpFlag(flag: string): boolean;
|
|
@@ -201,9 +196,6 @@ export declare const invocation: {
|
|
|
201
196
|
readonly json: {
|
|
202
197
|
readonly type: "boolean";
|
|
203
198
|
};
|
|
204
|
-
readonly "allow-legacy-read": {
|
|
205
|
-
readonly type: "boolean";
|
|
206
|
-
};
|
|
207
199
|
};
|
|
208
200
|
readonly routerOptionPlacement: "exact-tokens-anywhere-before-separator";
|
|
209
201
|
readonly optionSeparator: "--";
|
package/src/input.js
CHANGED
|
@@ -63,10 +63,9 @@ export const archiveConstraint = {
|
|
|
63
63
|
kind: "exclusive",
|
|
64
64
|
members: ["option:archived", "option:all"],
|
|
65
65
|
};
|
|
66
|
-
export const routerOptionNames = { json: "json"
|
|
66
|
+
export const routerOptionNames = { json: "json" };
|
|
67
67
|
export const routerOptions = {
|
|
68
68
|
[routerOptionNames.json]: { type: "boolean" },
|
|
69
|
-
[routerOptionNames.legacyRead]: { type: "boolean" },
|
|
70
69
|
};
|
|
71
70
|
export const helpSpellings = ["-h", "--help"];
|
|
72
71
|
export const versionSpellings = ["-v", "--version"];
|
|
@@ -74,12 +73,9 @@ export const OPTION_SEPARATOR = "--";
|
|
|
74
73
|
export function isJsonFlag(flag) {
|
|
75
74
|
return flag === `--${routerOptionNames.json}`;
|
|
76
75
|
}
|
|
77
|
-
export function isAllowLegacyReadFlag(flag) {
|
|
78
|
-
return flag === `--${routerOptionNames.legacyRead}`;
|
|
79
|
-
}
|
|
80
76
|
/** A flag the router reads wherever it appears before --, for every command. */
|
|
81
77
|
export function isRouterFlag(flag) {
|
|
82
|
-
return isJsonFlag(flag)
|
|
78
|
+
return isJsonFlag(flag);
|
|
83
79
|
}
|
|
84
80
|
export function isHelpFlag(flag) {
|
|
85
81
|
return helpSpellings.includes(flag);
|
|
@@ -165,7 +161,7 @@ export function generateInputUsage(input) {
|
|
|
165
161
|
constraint.members.length === members.length &&
|
|
166
162
|
constraint.members.every((member) => members.includes(member)));
|
|
167
163
|
const choice = (alternatives, isRequired) => isRequired ? `(${alternatives.join("|")})` : `[${alternatives.join("|")}]`;
|
|
168
|
-
return input.forms.
|
|
164
|
+
return input.forms.flatMap((form) => {
|
|
169
165
|
const words = new Map([
|
|
170
166
|
...form.positionals.map((positional, index) => [`positional:${positional.name}`, positionalWords(form)[index]]),
|
|
171
167
|
...options.map(({ reference, word }) => [reference, word]),
|
|
@@ -194,18 +190,42 @@ export function generateInputUsage(input) {
|
|
|
194
190
|
words.delete(reference);
|
|
195
191
|
}
|
|
196
192
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
193
|
+
const exclusiveGroups = input.constraints
|
|
194
|
+
.filter((constraint) => constraint.kind === "exclusive")
|
|
195
|
+
.map((constraint) => constraint.members)
|
|
196
|
+
.filter((members) => members.every((member) => words.has(member)));
|
|
197
|
+
function renderChoices(remaining) {
|
|
198
|
+
const groups = exclusiveGroups
|
|
199
|
+
.map((members) => members.filter((member) => remaining.has(member)))
|
|
200
|
+
.filter((members) => members.length > 1);
|
|
201
|
+
const overlappingMember = groups
|
|
202
|
+
.flat()
|
|
203
|
+
.find((member) => groups.filter((members) => members.includes(member)).length > 1);
|
|
204
|
+
// Separate usage lines preserve combinations allowed by overlapping exclusions.
|
|
205
|
+
if (overlappingMember !== undefined) {
|
|
206
|
+
const withoutMember = new Map(remaining);
|
|
207
|
+
withoutMember.delete(overlappingMember);
|
|
208
|
+
const withMember = new Map(remaining);
|
|
209
|
+
withMember.set(overlappingMember, remaining.get(overlappingMember).slice(1, -1));
|
|
210
|
+
for (const members of groups.filter((members) => members.includes(overlappingMember))) {
|
|
211
|
+
for (const member of members) {
|
|
212
|
+
if (member !== overlappingMember) {
|
|
213
|
+
withMember.delete(member);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return [...renderChoices(withoutMember), ...renderChoices(withMember)];
|
|
201
218
|
}
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
219
|
+
for (const members of groups) {
|
|
220
|
+
const alternatives = members.map((member) => remaining.get(member).slice(1, -1));
|
|
221
|
+
remaining.set(members[0], choice(alternatives, isRequiredChoice(members)));
|
|
222
|
+
for (const member of members.slice(1)) {
|
|
223
|
+
remaining.delete(member);
|
|
224
|
+
}
|
|
206
225
|
}
|
|
226
|
+
return [[...remaining.values()].join(" ")];
|
|
207
227
|
}
|
|
208
|
-
return
|
|
228
|
+
return renderChoices(words);
|
|
209
229
|
});
|
|
210
230
|
}
|
|
211
231
|
export const usageLabel = "Usage: ";
|
package/src/lib.d.ts
CHANGED
|
@@ -23,9 +23,12 @@ export declare function isDebugOutputEnabled(): boolean;
|
|
|
23
23
|
* Telemetry goes first so its own debug notice is released with the rest.
|
|
24
24
|
*/
|
|
25
25
|
export declare function finishRun(): void;
|
|
26
|
-
export declare function setLegacyReadAllowed(allowed: boolean): void;
|
|
27
|
-
export declare function isLegacyReadAllowed(): boolean;
|
|
28
26
|
export declare function output<T>(data: T, transformToString: (data: T) => string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Prints items as they arrive for a command that keeps running. JSON mode prints one document per line.
|
|
29
|
+
* It writes to the stream itself, whose error event reports a closed pipe under Node and Bun alike.
|
|
30
|
+
*/
|
|
31
|
+
export declare function outputStream<T>(items: Array<T>, transformToString: (items: Array<T>) => string, signal: AbortSignal): Promise<void>;
|
|
29
32
|
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
30
33
|
export declare function outputChanges<Change extends {
|
|
31
34
|
changed: boolean;
|
|
@@ -53,6 +56,7 @@ export declare class UsageError extends CliError {
|
|
|
53
56
|
* Optional words go last.
|
|
54
57
|
*/
|
|
55
58
|
export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
|
|
59
|
+
export declare function validateTaskKey(taskKey: string): void;
|
|
56
60
|
export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
|
|
57
61
|
/** The choices a positional accepts; positionals without choices contribute never. */
|
|
58
62
|
type PositionalChoices<Positional> = Positional extends {
|
|
@@ -101,5 +105,5 @@ export declare function isParseArgsError(error: any): boolean;
|
|
|
101
105
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
102
106
|
* `null` for any other error.
|
|
103
107
|
*/
|
|
104
|
-
export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string
|
|
108
|
+
export declare function parseArgsFailure(error: any, args: Array<string>, suggestFor: SuggestFor, route: Array<string>, options: ParseArgsOptionsConfig): CliError | null;
|
|
105
109
|
export {};
|
package/src/lib.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { basename } from "node:path";
|
|
2
|
+
import { once } from "node:events";
|
|
2
3
|
import { parseArgs } from "node:util";
|
|
3
4
|
import { createInterface } from "node:readline/promises";
|
|
4
5
|
import { z } from "zod";
|
|
5
|
-
import { assertWritable, InputValidationError } from "@zinn-dev/core";
|
|
6
|
+
import { assertWritable, getFailedUpgradeBackupPath, parseTaskKey, InputValidationError, } from "@zinn-dev/core";
|
|
6
7
|
import { CliError, classifyFailure, recoveryHint } from "./errors.js";
|
|
7
8
|
import { writeFailureLog } from "./failure-log.js";
|
|
8
9
|
import { isJsonFlag, isRouterFlag, OPTION_SEPARATOR, positionalWords, splitAtOptionSeparator, } from "./input.js";
|
|
9
10
|
import { formatParserReasonPreview } from "./presentation/description-presentation.js";
|
|
10
11
|
import { writeRunRecord } from "./telemetry.js";
|
|
11
12
|
let outputMode = "text";
|
|
12
|
-
let legacyReadAllowed = false;
|
|
13
13
|
const diagnostics = [];
|
|
14
14
|
/** Every notice of this run in order, kept for the failure log */
|
|
15
15
|
const runNotices = [];
|
|
@@ -69,12 +69,6 @@ export function finishRun() {
|
|
|
69
69
|
recordRun({});
|
|
70
70
|
flushDiagnostics();
|
|
71
71
|
}
|
|
72
|
-
export function setLegacyReadAllowed(allowed) {
|
|
73
|
-
legacyReadAllowed = allowed;
|
|
74
|
-
}
|
|
75
|
-
export function isLegacyReadAllowed() {
|
|
76
|
-
return legacyReadAllowed;
|
|
77
|
-
}
|
|
78
72
|
export function output(data, transformToString) {
|
|
79
73
|
if (outputMode === "json") {
|
|
80
74
|
console.info(JSON.stringify(data, null, 2));
|
|
@@ -85,6 +79,21 @@ export function output(data, transformToString) {
|
|
|
85
79
|
console.info(dataText);
|
|
86
80
|
}
|
|
87
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Prints items as they arrive for a command that keeps running. JSON mode prints one document per line.
|
|
84
|
+
* It writes to the stream itself, whose error event reports a closed pipe under Node and Bun alike.
|
|
85
|
+
*/
|
|
86
|
+
export async function outputStream(items, transformToString, signal) {
|
|
87
|
+
if (items.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const text = outputMode === "json"
|
|
91
|
+
? items.map((item) => JSON.stringify(item)).join("\n")
|
|
92
|
+
: transformToString(items);
|
|
93
|
+
if (!process.stdout.write(`${text}\n`)) {
|
|
94
|
+
await once(process.stdout, "drain", { signal });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
88
97
|
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
89
98
|
export function outputChanges(changes, present, formatEntries, describeUnchanged) {
|
|
90
99
|
const presentedChanges = changes.map((change) => ({
|
|
@@ -175,6 +184,11 @@ export function renderFailure(reason) {
|
|
|
175
184
|
help: classified.help,
|
|
176
185
|
message: failureMessage(reason, "Something went wrong"),
|
|
177
186
|
};
|
|
187
|
+
const backupPath = getFailedUpgradeBackupPath(reason);
|
|
188
|
+
if (backupPath !== undefined && failure.details?.backupPath === undefined) {
|
|
189
|
+
failure.details = { ...failure.details, backupPath };
|
|
190
|
+
failure.message += `. The pre-upgrade backup was saved to ${backupPath}`;
|
|
191
|
+
}
|
|
178
192
|
const logPath = LOGGED_ERROR_CODES.includes(failure.code)
|
|
179
193
|
? writeFailureLog(reason, runNotices)
|
|
180
194
|
: undefined;
|
|
@@ -204,8 +218,9 @@ export function renderFailure(reason) {
|
|
|
204
218
|
console.error(`Full log: ${logPath}`);
|
|
205
219
|
}
|
|
206
220
|
}
|
|
221
|
+
const exitCode = reason instanceof CliError && reason.exitCode !== undefined ? reason.exitCode : 1;
|
|
207
222
|
// Let piped stderr finish writing before Node exits
|
|
208
|
-
process.stderr.write("", () => process.exit(
|
|
223
|
+
process.stderr.write("", () => process.exit(exitCode));
|
|
209
224
|
}
|
|
210
225
|
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
211
226
|
export class UsageError extends CliError {
|
|
@@ -237,6 +252,13 @@ export function validatePositionals(positionals, form) {
|
|
|
237
252
|
});
|
|
238
253
|
}
|
|
239
254
|
}
|
|
255
|
+
export function validateTaskKey(taskKey) {
|
|
256
|
+
if (parseTaskKey(taskKey) === null) {
|
|
257
|
+
throw new CliError(`Invalid task key "${taskKey}". Expected format PROJECT-1`, "invalid_input", {
|
|
258
|
+
field: ["taskKey"],
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
240
262
|
export function validateUniqueOptions(tokens, options) {
|
|
241
263
|
const repeatableOptions = Object.keys(options).filter((name) => options[name].multiple);
|
|
242
264
|
const parsedArgs = new Set();
|
|
@@ -312,28 +334,48 @@ export function shellQuote(word) {
|
|
|
312
334
|
return `'${word.replaceAll("'", `'\\''`)}'`;
|
|
313
335
|
}
|
|
314
336
|
/**
|
|
315
|
-
* The message for `parseArgs` refusal of
|
|
316
|
-
* command with
|
|
337
|
+
* The message for `parseArgs` refusal of values that begin with a dash, showing the user's
|
|
338
|
+
* command with every such value joined to its flag.
|
|
317
339
|
* `null` for any other error
|
|
318
340
|
*/
|
|
319
|
-
function dashValueMessage(error, args) {
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
341
|
+
function dashValueMessage(error, args, options) {
|
|
342
|
+
const isDashValueError = error?.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" &&
|
|
343
|
+
DASH_VALUE_ERROR_PATTERN.test(error.message);
|
|
344
|
+
if (!isDashValueError) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
// Without strict checks, parseArgs reads the word after a string flag as its value.
|
|
348
|
+
const { tokens } = parseArgs({
|
|
349
|
+
args,
|
|
350
|
+
options,
|
|
351
|
+
allowPositionals: true,
|
|
352
|
+
strict: false,
|
|
353
|
+
tokens: true,
|
|
354
|
+
});
|
|
355
|
+
const dashValues = tokens.flatMap((token) => token.kind === "option" && !token.inlineValue && token.value?.startsWith("-")
|
|
356
|
+
? [{ index: token.index, flag: token.rawName, value: token.value }]
|
|
357
|
+
: []);
|
|
358
|
+
if (dashValues.length === 0) {
|
|
324
359
|
return null;
|
|
325
360
|
}
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
]
|
|
333
|
-
const reason =
|
|
334
|
-
|
|
361
|
+
const fixedWords = args.map(shellQuote);
|
|
362
|
+
for (const { index, flag, value } of dashValues) {
|
|
363
|
+
fixedWords[index] = `${flag}=${shellQuote(value)}`;
|
|
364
|
+
fixedWords[index + 1] = "";
|
|
365
|
+
}
|
|
366
|
+
const fixedCommand = ["zinn", ...fixedWords.filter((word) => word !== "")].join(" ");
|
|
367
|
+
const [first] = dashValues;
|
|
368
|
+
const reason = dashValues.length === 1
|
|
369
|
+
? `Option "${first.flag}" is followed by "${first.value}", which begins with a dash.`
|
|
370
|
+
: `Options are followed by values that begin with a dash: ${dashValues
|
|
371
|
+
.map(({ flag, value }) => `${flag} "${value}"`)
|
|
372
|
+
.join(", ")}.`;
|
|
373
|
+
const fix = dashValues.length === 1
|
|
374
|
+
? "If it is the value, join it to the flag with ="
|
|
375
|
+
: "If they are the values, join each to its flag with =";
|
|
376
|
+
return boundParserMessage(`${reason} ${fix}: ${fixedCommand}`, {
|
|
335
377
|
reason,
|
|
336
|
-
guidance: "Join
|
|
378
|
+
guidance: "Join each original value to its flag with =. Full command omitted because it is long.",
|
|
337
379
|
});
|
|
338
380
|
}
|
|
339
381
|
// "Unknown option '--project'."
|
|
@@ -431,7 +473,7 @@ export function isParseArgsError(error) {
|
|
|
431
473
|
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
432
474
|
* `null` for any other error.
|
|
433
475
|
*/
|
|
434
|
-
export function parseArgsFailure(error, args, suggestFor, route) {
|
|
476
|
+
export function parseArgsFailure(error, args, suggestFor, route, options) {
|
|
435
477
|
if (!isParseArgsError(error)) {
|
|
436
478
|
return null;
|
|
437
479
|
}
|
|
@@ -441,7 +483,7 @@ export function parseArgsFailure(error, args, suggestFor, route) {
|
|
|
441
483
|
const hint = unknownOptionMessage(error.message, args, suggestFor, route);
|
|
442
484
|
return new CliError(hint.message, "invalid_input", { argument, reason: "unknown_option" }, undefined, hint.suggestedRoute);
|
|
443
485
|
}
|
|
444
|
-
const dashMessage = dashValueMessage(error, args);
|
|
486
|
+
const dashMessage = dashValueMessage(error, args, options);
|
|
445
487
|
const isMissingValue = code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && / argument missing$/.test(error.message);
|
|
446
488
|
const reason = dashMessage !== null ? "dash_value" : isMissingValue ? "missing_argument" : undefined;
|
|
447
489
|
return new CliError(dashMessage ?? boundParserMessage(error.message), "invalid_input", { argument, reason }, undefined, dashMessage === null ? undefined : route);
|
package/src/list-continuation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatCommand, getOutputMode
|
|
1
|
+
import { formatCommand, getOutputMode } from "./lib.js";
|
|
2
2
|
/** Rebuilds a list command with its existing filters and the next cursor. */
|
|
3
3
|
export function formatListContinuation(command, positionals, tokens, cursorOption, cursorId) {
|
|
4
4
|
const continuation = tokens.flatMap((token) => {
|
|
@@ -10,9 +10,6 @@ export function formatListContinuation(command, positionals, tokens, cursorOptio
|
|
|
10
10
|
if (getOutputMode() === "json") {
|
|
11
11
|
continuation.push("--json");
|
|
12
12
|
}
|
|
13
|
-
if (isLegacyReadAllowed()) {
|
|
14
|
-
continuation.push("--allow-legacy-read");
|
|
15
|
-
}
|
|
16
13
|
continuation.push(`--${cursorOption}`, cursorId);
|
|
17
14
|
return formatCommand([...command, ...positionals, ...continuation]);
|
|
18
15
|
}
|
|
@@ -27,6 +27,8 @@ export declare function presentActivities(events: Array<Activity>, options?: {
|
|
|
27
27
|
}): Array<PresentedActivity>;
|
|
28
28
|
export declare function presentActor(actor: Actor): PresentedActor;
|
|
29
29
|
export declare function formatActor(actor: PresentedActor): string;
|
|
30
|
+
/** An actor's name and kind, as activity rows show who acted */
|
|
31
|
+
export declare function formatActorLabel(actor: Pick<PresentedActor, "actor_name" | "actor_kind">): string;
|
|
30
32
|
export declare function formatActivityList(entries: Array<PresentedActivity>, options?: {
|
|
31
33
|
showsDetails?: boolean;
|
|
32
34
|
}): string;
|
|
@@ -24,7 +24,24 @@ const RECORDED_FIELDS = new Set([
|
|
|
24
24
|
"target",
|
|
25
25
|
"comment",
|
|
26
26
|
"text",
|
|
27
|
+
"lease_ms",
|
|
28
|
+
"replaced",
|
|
29
|
+
"previous_expires_at",
|
|
30
|
+
"claimed_at",
|
|
31
|
+
"expires_at",
|
|
32
|
+
"cause",
|
|
27
33
|
]);
|
|
34
|
+
const CLAIM_ACTIONS = new Set(["claim", "claim_take", "claim_heartbeat", "claim_release"]);
|
|
35
|
+
// A released claim records its holder as actor fields, which summaries show as one holder.
|
|
36
|
+
const CLAIM_HOLDER_FIELDS = new Set([
|
|
37
|
+
"actor_kind",
|
|
38
|
+
"actor_name",
|
|
39
|
+
"actor_session_id",
|
|
40
|
+
"actor_thread_id",
|
|
41
|
+
]);
|
|
42
|
+
const RECORDED_TIME_FIELDS = new Set(["due_at", "previous_expires_at", "claimed_at", "expires_at"]);
|
|
43
|
+
// Summaries leave out a released claim's own times, which activity view shows.
|
|
44
|
+
const CLAIM_SPAN_FIELDS = new Set(["claimed_at", "expires_at"]);
|
|
28
45
|
const ENTITY_PREVIEW_LENGTH = 24;
|
|
29
46
|
const UNKNOWN_ACTOR_NAME = "unknown";
|
|
30
47
|
const ACTOR_DETAIL_FIELDS = [
|
|
@@ -37,6 +54,7 @@ const ACTOR_DETAIL_FIELDS = [
|
|
|
37
54
|
{ key: "actor_model", label: "Model" },
|
|
38
55
|
{ key: "actor_effort", label: "Effort" },
|
|
39
56
|
{ key: "actor_client", label: "Client" },
|
|
57
|
+
{ key: "actor_directory", label: "Directory" },
|
|
40
58
|
];
|
|
41
59
|
const ACTION_LABELS = {
|
|
42
60
|
create: "created",
|
|
@@ -51,6 +69,10 @@ const ACTION_LABELS = {
|
|
|
51
69
|
comment_create: "added comment",
|
|
52
70
|
comment_edit: "edited comment",
|
|
53
71
|
comment_delete: "deleted comment",
|
|
72
|
+
claim: "claimed",
|
|
73
|
+
claim_take: "took over claim",
|
|
74
|
+
claim_heartbeat: "renewed claim",
|
|
75
|
+
claim_release: "released claim",
|
|
54
76
|
};
|
|
55
77
|
function isRecord(value) {
|
|
56
78
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -367,6 +389,28 @@ function formatDeadline(value) {
|
|
|
367
389
|
? formatLocalTime(parsed.data, { includesSeconds: true })
|
|
368
390
|
: summarizeValue(value);
|
|
369
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Summarizes a claim action's holder, replaced claim and times.
|
|
394
|
+
* Returns `null` to leave the field out, or `undefined` for the usual summary.
|
|
395
|
+
*/
|
|
396
|
+
function summarizeClaimChange(changes, field, value) {
|
|
397
|
+
if (CLAIM_HOLDER_FIELDS.has(field)) {
|
|
398
|
+
const holder = changes;
|
|
399
|
+
return field === "actor_kind" ? `holder: ${formatActorLabel(holder)}` : null;
|
|
400
|
+
}
|
|
401
|
+
if (CLAIM_SPAN_FIELDS.has(field)) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (field === "replaced") {
|
|
405
|
+
return isRecord(value)
|
|
406
|
+
? `replaced: ${formatActorLabel(value)}`
|
|
407
|
+
: null;
|
|
408
|
+
}
|
|
409
|
+
if (RECORDED_TIME_FIELDS.has(field)) {
|
|
410
|
+
return `${field}: ${formatDeadline(value)}`;
|
|
411
|
+
}
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
370
414
|
function formatRemovedTasks(entry) {
|
|
371
415
|
return entry.removedTasks.map((identity) => `removed ${identity.key} (${identity.id})`);
|
|
372
416
|
}
|
|
@@ -382,6 +426,12 @@ function formatChangeSummary(entry, options = {}) {
|
|
|
382
426
|
if (isSnapshot && value === null) {
|
|
383
427
|
return null;
|
|
384
428
|
}
|
|
429
|
+
if (CLAIM_ACTIONS.has(event.action)) {
|
|
430
|
+
const claimSummary = summarizeClaimChange(changes, field, value);
|
|
431
|
+
if (claimSummary !== undefined) {
|
|
432
|
+
return claimSummary;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
385
435
|
const repeatsIdentity = options.omitsIdentity &&
|
|
386
436
|
isSnapshot &&
|
|
387
437
|
(field === "key" || field === "name") &&
|
|
@@ -489,12 +539,14 @@ function formatRecordedChanges(event) {
|
|
|
489
539
|
}
|
|
490
540
|
const sections = [];
|
|
491
541
|
const unknownFields = {};
|
|
542
|
+
const isClaimAction = CLAIM_ACTIONS.has(event.action);
|
|
492
543
|
for (const [field, value] of Object.entries(event.changes)) {
|
|
493
|
-
|
|
544
|
+
const isRecordedField = RECORDED_FIELDS.has(field) || (isClaimAction && CLAIM_HOLDER_FIELDS.has(field));
|
|
545
|
+
if (!isRecordedField) {
|
|
494
546
|
unknownFields[field] = value;
|
|
495
547
|
continue;
|
|
496
548
|
}
|
|
497
|
-
const formatValue = field
|
|
549
|
+
const formatValue = RECORDED_TIME_FIELDS.has(field) ? formatDeadline : formatRecordedValue;
|
|
498
550
|
const body = isRecordedChangePair(event, value)
|
|
499
551
|
? `${formatSection("From", formatValue(value[0]))}\n\n${formatSection("To", formatValue(value[1]))}`
|
|
500
552
|
: formatValue(value);
|
|
@@ -517,6 +569,7 @@ export function presentActor(actor) {
|
|
|
517
569
|
actor_model: actor.model ?? null,
|
|
518
570
|
actor_effort: actor.effort ?? null,
|
|
519
571
|
actor_client: actor.client ?? null,
|
|
572
|
+
actor_directory: actor.directory ?? null,
|
|
520
573
|
};
|
|
521
574
|
}
|
|
522
575
|
export function formatActor(actor) {
|
|
@@ -525,12 +578,16 @@ export function formatActor(actor) {
|
|
|
525
578
|
...ACTOR_DETAIL_FIELDS.map(({ key, label }) => `${label}: ${actor[key] ?? "null"}`),
|
|
526
579
|
].join("\n");
|
|
527
580
|
}
|
|
581
|
+
/** An actor's name and kind, as activity rows show who acted */
|
|
582
|
+
export function formatActorLabel(actor) {
|
|
583
|
+
return `${actor.actor_name ?? UNKNOWN_ACTOR_NAME} (${actor.actor_kind})`;
|
|
584
|
+
}
|
|
528
585
|
export function formatActivityList(entries, options = {}) {
|
|
529
586
|
const rows = entries.map((entry) => {
|
|
530
587
|
const metadata = [
|
|
531
588
|
{ text: entry.displayId },
|
|
532
589
|
{ text: formatLocalTime(entry.event.created_at), style: "dim" },
|
|
533
|
-
{ text:
|
|
590
|
+
{ text: formatActorLabel(entry.event) },
|
|
534
591
|
{ text: entry.event.actor_client ?? "null" },
|
|
535
592
|
];
|
|
536
593
|
if (!options.showsDetails) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import type { ColumnCategory } from "@zinn-dev/core";
|
|
1
2
|
import type { RowCell } from "./row-layout.js";
|
|
2
3
|
import type { PresentedColumn, PresentedColumnTaskCount } from "../result-schemas.js";
|
|
3
4
|
import { column } from "@zinn-dev/core";
|
|
4
5
|
type ColumnRow = {
|
|
5
6
|
name: string;
|
|
7
|
+
category?: string | null;
|
|
6
8
|
project?: string;
|
|
7
9
|
taskCount?: number;
|
|
8
|
-
is_first?: boolean;
|
|
9
|
-
is_last?: boolean;
|
|
10
10
|
};
|
|
11
11
|
/** A project's columns in board order. */
|
|
12
12
|
export type ProjectColumns = ReturnType<typeof column.getAllByProjectKey>;
|
|
@@ -22,10 +22,15 @@ export declare function presentColumn(columnMatch: {
|
|
|
22
22
|
id: string;
|
|
23
23
|
project_id: string;
|
|
24
24
|
name: string;
|
|
25
|
+
category?: ColumnCategory;
|
|
25
26
|
}): PresentedColumn;
|
|
26
|
-
/** Shapes one board's column rows
|
|
27
|
+
/** Shapes one board's column rows in order.*/
|
|
27
28
|
export declare function presentColumnTaskCounts(taskCounts: ReturnType<typeof column.getTaskCountsByProjectKey>): Array<PresentedColumnTaskCount>;
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Colors a column name by its category.
|
|
31
|
+
* Names without a category, as on an older database, stay uncolored
|
|
32
|
+
*/
|
|
33
|
+
export declare function columnNameCell(columnName: string, category?: string | null): RowCell;
|
|
29
34
|
/** The archived row is left out when there are no archived tasks. */
|
|
30
35
|
export declare function formatColumnList(presentedColumns: Array<ColumnRow>, options?: {
|
|
31
36
|
showsProject?: boolean;
|
|
@@ -33,9 +33,10 @@ export function presentColumn(columnMatch) {
|
|
|
33
33
|
name: columnMatch.name,
|
|
34
34
|
is_first: placement.is_first,
|
|
35
35
|
is_last: placement.is_last,
|
|
36
|
+
category: columnMatch.category ?? null,
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
|
-
/** Shapes one board's column rows
|
|
39
|
+
/** Shapes one board's column rows in order.*/
|
|
39
40
|
export function presentColumnTaskCounts(taskCounts) {
|
|
40
41
|
const lastColumnIndex = taskCounts.columns.length - 1;
|
|
41
42
|
return taskCounts.columns.map((columnCount, columnIndex) => ({
|
|
@@ -43,18 +44,25 @@ export function presentColumnTaskCounts(taskCounts) {
|
|
|
43
44
|
name: columnCount.column.name,
|
|
44
45
|
is_first: columnIndex === 0,
|
|
45
46
|
is_last: columnIndex === lastColumnIndex,
|
|
47
|
+
category: columnCount.column.category ?? null,
|
|
46
48
|
taskCount: columnCount.taskCount,
|
|
47
49
|
}));
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
/** The color of each category's column names */
|
|
52
|
+
const CATEGORY_STYLES = {
|
|
53
|
+
backlog: "gray",
|
|
54
|
+
in_progress: "blue",
|
|
55
|
+
review: "yellow",
|
|
56
|
+
done: "green",
|
|
57
|
+
cancelled: "gray",
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Colors a column name by its category.
|
|
61
|
+
* Names without a category, as on an older database, stay uncolored
|
|
62
|
+
*/
|
|
63
|
+
export function columnNameCell(columnName, category) {
|
|
64
|
+
const style = category == null ? undefined : CATEGORY_STYLES[category];
|
|
65
|
+
return style === undefined ? { text: columnName } : { text: columnName, style };
|
|
58
66
|
}
|
|
59
67
|
/** The archived row is left out when there are no archived tasks. */
|
|
60
68
|
export function formatColumnList(presentedColumns, options = {}) {
|
|
@@ -62,17 +70,26 @@ export function formatColumnList(presentedColumns, options = {}) {
|
|
|
62
70
|
const projectCells = options.showsProject && presentedColumn.project != null
|
|
63
71
|
? [{ text: presentedColumn.project }]
|
|
64
72
|
: [];
|
|
73
|
+
// The cell stays, empty, for a column without a category on an older database.
|
|
74
|
+
const categoryCells = presentedColumn.category === undefined ? [] : [{ text: presentedColumn.category ?? "" }];
|
|
65
75
|
const taskCountCells = options.showsTaskCounts && presentedColumn.taskCount != null
|
|
66
76
|
? [{ text: String(presentedColumn.taskCount) }]
|
|
67
77
|
: [];
|
|
68
78
|
return [
|
|
69
79
|
...projectCells,
|
|
70
|
-
columnNameCell(presentedColumn.name, presentedColumn),
|
|
80
|
+
columnNameCell(presentedColumn.name, presentedColumn.category),
|
|
81
|
+
...categoryCells,
|
|
71
82
|
...taskCountCells,
|
|
72
83
|
];
|
|
73
84
|
});
|
|
74
85
|
if (options.archivedTaskCount != null && options.archivedTaskCount > 0) {
|
|
75
|
-
|
|
86
|
+
// An empty cell keeps the count under the task counts when rows show categories.
|
|
87
|
+
const hasCategoryCell = presentedColumns.some((presentedColumn) => presentedColumn.category !== undefined);
|
|
88
|
+
rows.push([
|
|
89
|
+
{ text: ARCHIVED_ROW_LABEL },
|
|
90
|
+
...(hasCategoryCell ? [{ text: "" }] : []),
|
|
91
|
+
{ text: String(options.archivedTaskCount) },
|
|
92
|
+
]);
|
|
76
93
|
}
|
|
77
94
|
return formatRows(rows);
|
|
78
95
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DoctorCheck, DoctorStatus } from "@zinn-dev/core";
|
|
2
|
+
import type { PresentedDoctor } from "../result-schemas.js";
|
|
3
|
+
export declare function presentDoctor(checks: ReadonlyArray<DoctorCheck>, agentSkill: DoctorCheck<"agent_skill">): PresentedDoctor;
|
|
4
|
+
/** A status label and message per row, with the remedy on its own line below when there is one */
|
|
5
|
+
export declare function formatStatusRows(rows: ReadonlyArray<{
|
|
6
|
+
status: DoctorStatus;
|
|
7
|
+
message: string;
|
|
8
|
+
remedy: string | null;
|
|
9
|
+
}>): string;
|
|
10
|
+
export declare function formatDoctor(report: PresentedDoctor): string;
|