@wirecat/cli-base 0.108.0 → 0.109.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/CHANGELOG.md +23 -0
- package/dist/codegen/index.d.ts +1 -0
- package/dist/codegen/index.js +1 -0
- package/dist/codegen/pipeline.d.ts +5 -0
- package/dist/codegen/pipeline.js +16 -2
- package/dist/codegen/skill.d.ts +35 -0
- package/dist/codegen/skill.js +171 -0
- package/dist/dev/ready.d.ts +2 -2
- package/dist/dev/ready.js +73 -12
- package/docs/standards/kit-surface.md +28 -0
- package/docs/standards/layout.md +1 -1
- package/docs/standards/new-cli.md +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,29 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
|
|
|
8
8
|
Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
|
|
9
9
|
[`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).
|
|
10
10
|
|
|
11
|
+
## 0.109.0 — 16.11.2026
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **`apiSkillFiles` writes the API part of a CLI's agent skill from the manifest and the command tree**: an index,
|
|
16
|
+
`references/api.md`, and one file per tag, `references/api/api-<group>.md`, which an agent reads with
|
|
17
|
+
`<cli> skill show api-<group>`. Usage, arguments and flags come only from `describeProgram`, matched to each
|
|
18
|
+
operation by `api_operation`; a mismatch either way, two commands for one operation, two tags with one file name, a
|
|
19
|
+
hand-written part that would hide a generated one, or a `SKILL.md` that does not link the index stops the
|
|
20
|
+
generation. Vendor text is cut to one line and escaped. The manifest adds the call, effect, sign-in scopes, permission keys, paging
|
|
21
|
+
and body schema. No examples are made up. `writeArtifacts` takes `owns`, folders that hold only generated files, so a
|
|
22
|
+
file no longer generated is stale under `--check` and removed when writing.
|
|
23
|
+
[Kit surface](docs/standards/kit-surface.md#the-api-part-of-the-agent-skill)
|
|
24
|
+
|
|
25
|
+
### Changed — may break callers
|
|
26
|
+
|
|
27
|
+
- **`cli-dev ready` needs every contract of the CLI's category, not one.** A contract the CLI does not run goes in
|
|
28
|
+
`lint/contract-exceptions.json` with its reason (`[{ "contract": "crmSyncContract", "reason": "…" }]`); the row
|
|
29
|
+
then shows partially with the reason, and the exit code does not wait for it. An exception without a reason, for
|
|
30
|
+
another category's contract, for one that runs, listed twice, or for every contract is not verified, as is a file
|
|
31
|
+
that is not a JSON list. A CLI that ran one contract of several and was verified under 0.108.0 now exits 1 until it
|
|
32
|
+
runs or excepts the rest. [New CLI](docs/standards/new-cli.md#done-when)
|
|
33
|
+
|
|
11
34
|
## 0.108.0 — 16.11.2026
|
|
12
35
|
|
|
13
36
|
### Added
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
|
18
18
|
export { detectPagination } from "./pagination.js";
|
|
19
19
|
export { type PatchedSpec, type PatchSpecOptions, patchSpec, type SpecPatch } from "./patch.js";
|
|
20
20
|
export { type AuthOverride, applyNames, applyOverrides, applyPagination, applyPermissionRule, CodegenError, type CommandNames, type GenerateOptions, generate, type PermissionRule, READING_POST_REASON, validateModel, type WriteOptions, writeArtifacts, } from "./pipeline.js";
|
|
21
|
+
export { API_SKILL_GROUPS, API_SKILL_INDEX, type ApiSkillOptions, apiSkillFiles } from "./skill.js";
|
|
21
22
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
22
23
|
export { typesGenerator } from "./typescript.js";
|
|
23
24
|
export { type ValibotOptions, valibotGenerator } from "./valibot.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
|
17
17
|
export { detectPagination } from "./pagination.js";
|
|
18
18
|
export { patchSpec } from "./patch.js";
|
|
19
19
|
export { applyNames, applyOverrides, applyPagination, applyPermissionRule, CodegenError, generate, READING_POST_REASON, validateModel, writeArtifacts, } from "./pipeline.js";
|
|
20
|
+
export { API_SKILL_GROUPS, API_SKILL_INDEX, apiSkillFiles } from "./skill.js";
|
|
20
21
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
21
22
|
export { typesGenerator } from "./typescript.js";
|
|
22
23
|
export { valibotGenerator } from "./valibot.js";
|
|
@@ -69,6 +69,11 @@ export interface WriteOptions {
|
|
|
69
69
|
check?: boolean;
|
|
70
70
|
/** The consumer's formatter, so a check compares what would actually be committed. */
|
|
71
71
|
format?: (path: string, content: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* Folders, relative to `root`, that hold only generated files: a file there that was not generated this time (a
|
|
74
|
+
* group that left the spec) is stale too, and removed when writing.
|
|
75
|
+
*/
|
|
76
|
+
owns?: readonly string[];
|
|
72
77
|
}
|
|
73
78
|
/** Paths whose committed content differs from what was generated — written, or with `check`, only reported. */
|
|
74
79
|
export declare const writeArtifacts: (artifacts: readonly GeneratedArtifact[], options: WriteOptions) => string[];
|
package/dist/codegen/pipeline.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, extname, join } from "node:path";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, extname, join, posix } from "node:path";
|
|
3
3
|
import { identifier, kebab } from "./names.js";
|
|
4
4
|
import { answerPaths, detectPagination, requestParameters } from "./pagination.js";
|
|
5
5
|
export class CodegenError extends Error {
|
|
@@ -382,5 +382,19 @@ export const writeArtifacts = (artifacts, options) => {
|
|
|
382
382
|
mkdirSync(dirname(target), { recursive: true });
|
|
383
383
|
writeFileSync(target, content);
|
|
384
384
|
}
|
|
385
|
+
const generated = new Set(artifacts.map((artifact) => posix.normalize(artifact.path)));
|
|
386
|
+
for (const owned of options.owns ?? []) {
|
|
387
|
+
const folder = posix.normalize(owned).replace(/\/+$/, "");
|
|
388
|
+
if (!existsSync(join(options.root, folder)))
|
|
389
|
+
continue;
|
|
390
|
+
for (const entry of readdirSync(join(options.root, folder), { withFileTypes: true })) {
|
|
391
|
+
const path = posix.join(folder, entry.name);
|
|
392
|
+
if (!entry.isFile() || generated.has(path))
|
|
393
|
+
continue;
|
|
394
|
+
stale.push(path);
|
|
395
|
+
if (!options.check)
|
|
396
|
+
rmSync(join(options.root, path));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
385
399
|
return stale;
|
|
386
400
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API part of a CLI's agent skill: `references/api.md`, a short index, and `references/api/api-<group>.md`, one
|
|
3
|
+
* file per first tag of the operations, so an agent loads only the group it needs (`<cli> skill show api-<group>`). Each command,
|
|
4
|
+
* its usage, arguments and flags come from the built program's command tree, as `--help` prints them; the manifest
|
|
5
|
+
* adds only what the API says: the HTTP call, the effect, sign-in scopes, permission keys and paging.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommandInfo } from "../commands/registry.js";
|
|
8
|
+
import type { ManifestOperation } from "./manifest.js";
|
|
9
|
+
import type { GeneratedArtifact } from "./model.js";
|
|
10
|
+
export interface ApiSkillOptions {
|
|
11
|
+
/** The command word `skill show` runs under: `notion`. */
|
|
12
|
+
cli: string;
|
|
13
|
+
/** The skill's folder, beside its SKILL.md: `skills/notion-cli`. */
|
|
14
|
+
folder: string;
|
|
15
|
+
/**
|
|
16
|
+
* The files already in that folder, relative to it, as `skillFiles` lists them: `skill show` finds a part by its
|
|
17
|
+
* base name, so a hand-written `api-pages.md` elsewhere would hide the generated one.
|
|
18
|
+
*/
|
|
19
|
+
files: readonly string[];
|
|
20
|
+
/** The service, for the headings: `Notion`. */
|
|
21
|
+
service: string;
|
|
22
|
+
operations: readonly ManifestOperation[];
|
|
23
|
+
/** The SKILL.md beside these files, as text: an agent reaches them only through its link to `references/api.md`. */
|
|
24
|
+
skill: string;
|
|
25
|
+
/** `describeProgram(createProgram())`: the generated commands carry `api_operation`. */
|
|
26
|
+
commands: readonly CommandInfo[];
|
|
27
|
+
banner: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const API_SKILL_INDEX = "references/api.md";
|
|
30
|
+
export declare const API_SKILL_GROUPS = "references/api";
|
|
31
|
+
/**
|
|
32
|
+
* Throws `CodegenError` when an operation has no command or a generated command names no operation: a flag is
|
|
33
|
+
* never taken from anywhere but the command tree. Sorted, and with no version or date, so `generate:check` holds.
|
|
34
|
+
*/
|
|
35
|
+
export declare const apiSkillFiles: (options: ApiSkillOptions) => GeneratedArtifact[];
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { flatten } from "../commands/registry.js";
|
|
2
|
+
import { kebab } from "./names.js";
|
|
3
|
+
import { CodegenError } from "./pipeline.js";
|
|
4
|
+
export const API_SKILL_INDEX = "references/api.md";
|
|
5
|
+
export const API_SKILL_GROUPS = "references/api";
|
|
6
|
+
const firstLine = (value) => (value ?? "").split(/\r\n|[\r\n\u2028\u2029]/)[0]?.trim() ?? "";
|
|
7
|
+
/**
|
|
8
|
+
* Vendor text becomes instructions an agent follows: its first line only, HTML and every Markdown mark escaped, and
|
|
9
|
+
* always after a label, so no heading, list, fence or link can start it.
|
|
10
|
+
*/
|
|
11
|
+
const text = (value) => firstLine(value)
|
|
12
|
+
.replaceAll("&", "&")
|
|
13
|
+
.replaceAll("<", "<")
|
|
14
|
+
.replaceAll(">", ">")
|
|
15
|
+
.replace(/[\\`*_[\]~|]/g, "\\$&");
|
|
16
|
+
/** A code span; in a table cell `|` still ends the cell, so it is escaped there. */
|
|
17
|
+
const code = (value, cell = false) => {
|
|
18
|
+
const plain = value.replace(/[\r\n\u2028\u2029]+/g, " ").replaceAll("`", "'");
|
|
19
|
+
return `\`${cell ? plain.replaceAll("|", "\\|") : plain}\``;
|
|
20
|
+
};
|
|
21
|
+
const pages = (pagination) => {
|
|
22
|
+
const sent = (parameter) => `${code(parameter.name)} (${parameter.in})`;
|
|
23
|
+
const limit = "limit" in pagination && pagination.limit ? `; page size in ${sent(pagination.limit)}` : "";
|
|
24
|
+
const items = pagination.items ? `; items in ${code(pagination.items)}` : "";
|
|
25
|
+
const total = "total" in pagination && pagination.total ? `; the count of all in ${code(pagination.total)}` : "";
|
|
26
|
+
switch (pagination.style) {
|
|
27
|
+
case "cursor": {
|
|
28
|
+
const more = pagination.hasMore ? `; ${code(pagination.hasMore)} is false on the last page` : "";
|
|
29
|
+
return `cursor: send ${sent(pagination.cursor)}, read the next one from ${code(pagination.next)}${items}${more}${limit}`;
|
|
30
|
+
}
|
|
31
|
+
case "offset":
|
|
32
|
+
return `offset: send ${sent(pagination.offset)}, raised by the items read so far${items}${total}${limit}`;
|
|
33
|
+
case "page":
|
|
34
|
+
return `page number: send ${sent(pagination.page)}, one more for each page${items}${total}${limit}`;
|
|
35
|
+
case "link":
|
|
36
|
+
return `the answer's ${code(pagination.next)} is the next page's address${items}`;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const flagRow = (option) => `| ${code(option.flags, true)} | ${option.mandatory ? "yes" : "no"} | ${text(option.description)} |`;
|
|
40
|
+
const section = (operation, command) => {
|
|
41
|
+
const call = operation.binding.kind === "http" ? `${operation.binding.method} ${operation.binding.path}` : operation.binding.name;
|
|
42
|
+
const scopes = (operation.security ?? []).map((requirement) => Object.entries(requirement)
|
|
43
|
+
.map(([scheme, list]) => (list.length > 0 ? `${scheme} (${list.join(", ")})` : scheme))
|
|
44
|
+
.join(" and "));
|
|
45
|
+
const lines = [
|
|
46
|
+
`## ${code(command.usage)}`,
|
|
47
|
+
"",
|
|
48
|
+
`- What: ${text(operation.summary ?? command.summary ?? command.description) || operation.id}`,
|
|
49
|
+
`- Call: ${code(call)}, effect: ${operation.effect}${operation.deprecated ? ", deprecated" : ""}`,
|
|
50
|
+
];
|
|
51
|
+
if (scopes.length > 0)
|
|
52
|
+
lines.push(`- Sign-in: ${scopes.map(text).join("; or ")}`);
|
|
53
|
+
if (operation.permissions && operation.permissions.length > 0)
|
|
54
|
+
lines.push(`- Permission keys: ${operation.permissions.map((permission) => code(permission.key)).join(", ")}`);
|
|
55
|
+
if (operation.pagination)
|
|
56
|
+
lines.push(`- Pages: ${pages(operation.pagination)}`);
|
|
57
|
+
if (operation.request?.schema)
|
|
58
|
+
lines.push(`- Body: ${code(operation.request.schema)}${operation.request.required ? ", required" : ""}`);
|
|
59
|
+
if (command.arguments.length > 0) {
|
|
60
|
+
lines.push("", "| Argument | Required | What |", "|---|---|---|");
|
|
61
|
+
for (const argument of command.arguments)
|
|
62
|
+
lines.push(`| ${code(argument.name, true)} | ${argument.required ? "yes" : "no"} | ${text(argument.description)} |`);
|
|
63
|
+
}
|
|
64
|
+
if (command.options.length > 0) {
|
|
65
|
+
lines.push("", "| Flag | Required | What |", "|---|---|---|");
|
|
66
|
+
for (const option of command.options)
|
|
67
|
+
lines.push(flagRow(option));
|
|
68
|
+
}
|
|
69
|
+
return [...lines, ""];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Throws `CodegenError` when an operation has no command or a generated command names no operation: a flag is
|
|
73
|
+
* never taken from anywhere but the command tree. Sorted, and with no version or date, so `generate:check` holds.
|
|
74
|
+
*/
|
|
75
|
+
export const apiSkillFiles = (options) => {
|
|
76
|
+
const generated = flatten(options.commands).filter((command) => command.origin === "generated" && command.api_operation);
|
|
77
|
+
const byOperation = new Map();
|
|
78
|
+
const problems = [];
|
|
79
|
+
for (const command of generated) {
|
|
80
|
+
const id = command.api_operation ?? "";
|
|
81
|
+
const earlier = byOperation.get(id);
|
|
82
|
+
if (earlier)
|
|
83
|
+
problems.push(`${earlier.path.join(" ")} and ${command.path.join(" ")} both name operation ${id}`);
|
|
84
|
+
byOperation.set(id, command);
|
|
85
|
+
}
|
|
86
|
+
const ids = new Set(options.operations.map((operation) => operation.id));
|
|
87
|
+
const linked = /\]\(\s*(\.\/)?references\/api\.md(#[^)]*)?\s*\)/.test(options.skill.replace(/<!--[\s\S]*?-->/g, ""));
|
|
88
|
+
const hidden = options.files.filter((file) => {
|
|
89
|
+
const base = file.split("/").at(-1)?.replace(/\.md$/, "") ?? "";
|
|
90
|
+
const ours = file === API_SKILL_INDEX || file.startsWith(`${API_SKILL_GROUPS}/`);
|
|
91
|
+
return !ours && file.endsWith(".md") && (base === "api" || base.startsWith("api-"));
|
|
92
|
+
});
|
|
93
|
+
if (!linked)
|
|
94
|
+
problems.push(`SKILL.md does not link ${API_SKILL_INDEX}`);
|
|
95
|
+
for (const file of hidden)
|
|
96
|
+
problems.push(`${file} would hide a generated part of the same name in skill show`);
|
|
97
|
+
for (const operation of options.operations)
|
|
98
|
+
if (!byOperation.has(operation.id))
|
|
99
|
+
problems.push(`operation ${operation.id} has no command in the program`);
|
|
100
|
+
for (const command of generated)
|
|
101
|
+
if (!ids.has(command.api_operation ?? ""))
|
|
102
|
+
problems.push(`${command.path.join(" ")} names operation ${command.api_operation}, not in the manifest`);
|
|
103
|
+
const groups = new Map();
|
|
104
|
+
for (const operation of options.operations) {
|
|
105
|
+
const tag = operation.tags[0] ?? "untagged";
|
|
106
|
+
const name = kebab(tag);
|
|
107
|
+
const group = groups.get(name);
|
|
108
|
+
if (!name)
|
|
109
|
+
problems.push(`tag "${tag}" of ${operation.id} has no Latin letter or digit for a file name`);
|
|
110
|
+
else if (group && group.tag !== tag)
|
|
111
|
+
problems.push(`tags "${group.tag}" and "${tag}" both make the file api-${name}.md`);
|
|
112
|
+
else if (group)
|
|
113
|
+
group.operations.push(operation);
|
|
114
|
+
else
|
|
115
|
+
groups.set(name, { tag, operations: [operation] });
|
|
116
|
+
}
|
|
117
|
+
if (problems.length > 0)
|
|
118
|
+
throw new CodegenError(problems);
|
|
119
|
+
const parentPaths = new Set(generated.map((command) => command.path.slice(0, -1).join(" ")));
|
|
120
|
+
const parents = flatten(options.commands).filter((command) => parentPaths.has(command.path.join(" ")));
|
|
121
|
+
const names = [...groups.keys()].sort();
|
|
122
|
+
const commandOf = (operation) => byOperation.get(operation.id);
|
|
123
|
+
const program = options.cli;
|
|
124
|
+
const index = [
|
|
125
|
+
`<!-- ${options.banner} -->`,
|
|
126
|
+
"",
|
|
127
|
+
`# ${text(options.service)} API`,
|
|
128
|
+
"",
|
|
129
|
+
`Every operation of the ${text(options.service)} API this CLI offers is a command of its own. Read only the group`,
|
|
130
|
+
`you need: ${code(`${program} skill show api-<group>`)} prints it, as does the file \`api/api-<group>.md\` beside`,
|
|
131
|
+
"this one. Each command lists its usage and flags as `--help` prints them.",
|
|
132
|
+
"",
|
|
133
|
+
"Effects: `read` changes nothing; `write` changes the service; `destructive` deletes or overwrites there.",
|
|
134
|
+
"",
|
|
135
|
+
];
|
|
136
|
+
for (const parent of parents) {
|
|
137
|
+
if (parent.options.length === 0)
|
|
138
|
+
continue;
|
|
139
|
+
index.push(`Options of ${code(parent.usage)} for every command under it:`, "", "| Flag | Required | What |");
|
|
140
|
+
index.push("|---|---|---|");
|
|
141
|
+
for (const option of parent.options)
|
|
142
|
+
index.push(flagRow(option));
|
|
143
|
+
index.push("");
|
|
144
|
+
}
|
|
145
|
+
index.push("| Group | Read with | Commands | read | write | destructive |", "|---|---|---|---|---|---|");
|
|
146
|
+
for (const name of names) {
|
|
147
|
+
const { tag, operations } = groups.get(name);
|
|
148
|
+
const count = (effect) => operations.filter((operation) => operation.effect === effect).length;
|
|
149
|
+
index.push(`| ${text(tag)} | ${code(`${program} skill show api-${name}`, true)} | ${operations.length} | ${count("read")} | ` +
|
|
150
|
+
`${count("write")} | ${count("destructive")} |`);
|
|
151
|
+
}
|
|
152
|
+
const files = names.map((name) => {
|
|
153
|
+
const { tag, operations } = groups.get(name);
|
|
154
|
+
const usage = (operation) => commandOf(operation).usage;
|
|
155
|
+
// Code-unit order: a locale's collation would differ between machines and fail generate:check.
|
|
156
|
+
const sorted = [...operations].sort((one, other) => usage(one) < usage(other) ? -1 : usage(one) > usage(other) ? 1 : 0);
|
|
157
|
+
return {
|
|
158
|
+
path: `${options.folder}/${API_SKILL_GROUPS}/api-${name}.md`,
|
|
159
|
+
content: [
|
|
160
|
+
`<!-- ${options.banner} -->`,
|
|
161
|
+
"",
|
|
162
|
+
`# ${text(options.service)} API: ${text(tag)}`,
|
|
163
|
+
"",
|
|
164
|
+
...sorted.flatMap((operation) => section(operation, commandOf(operation))),
|
|
165
|
+
]
|
|
166
|
+
.join("\n")
|
|
167
|
+
.replace(/\n+$/, "\n"),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
return [{ path: `${options.folder}/${API_SKILL_INDEX}`, content: `${index.join("\n")}\n` }, ...files];
|
|
171
|
+
};
|
package/dist/dev/ready.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ReadyRow {
|
|
|
17
17
|
export interface ReadyReport {
|
|
18
18
|
category?: string;
|
|
19
19
|
rows: ReadyRow[];
|
|
20
|
-
/** The fix of the first row that
|
|
20
|
+
/** The fix of the first row that has one; a row partially verified only by excepted contracts has none. */
|
|
21
21
|
next?: string;
|
|
22
22
|
}
|
|
23
23
|
export declare const designCategory: (design: string) => string | undefined;
|
|
@@ -26,5 +26,5 @@ export declare const READY_TESTS = "coverage/ready-tests.json";
|
|
|
26
26
|
export declare const readyReport: (io: DevIo, shell: Shell) => ReadyReport;
|
|
27
27
|
export declare const readyText: (report: ReadyReport) => string;
|
|
28
28
|
export declare const ready: (args: string[], io: DevIo, shell: Shell) => number;
|
|
29
|
-
export declare const READY_USAGE = " ready [--json] runs the CLI's checks in order (typecheck and lint, tests and its\n category's cli-core contracts, the family audit, docs:check,\n generate:check, smoke, security:no-leak,\n deps:check) and reads the live-check record; prints each row as\n verified, partially, not verified or unsupported with its evidence,\n and the one next step; exits 1
|
|
29
|
+
export declare const READY_USAGE = " ready [--json] runs the CLI's checks in order (typecheck and lint, tests and its\n category's cli-core contracts, the family audit, docs:check,\n generate:check, smoke, security:no-leak,\n deps:check) and reads the live-check record; prints each row as\n verified, partially, not verified or unsupported with its evidence,\n and the one next step; exits 1 while a row has a fix (a category\n contract excepted with its reason in lint/contract-exceptions.json\n shows partially and needs none)";
|
|
30
30
|
export {};
|
package/dist/dev/ready.js
CHANGED
|
@@ -110,6 +110,35 @@ const scriptRow = (id, title, runs, extra = []) => {
|
|
|
110
110
|
: {}),
|
|
111
111
|
};
|
|
112
112
|
};
|
|
113
|
+
/** `[{ "contract": "crmSyncContract", "reason": "…" }]`: a category contract this CLI does not run, and why. */
|
|
114
|
+
const EXCEPTIONS = "lint/contract-exceptions.json";
|
|
115
|
+
const contractExceptions = (cwd) => {
|
|
116
|
+
const path = join(cwd, EXCEPTIONS);
|
|
117
|
+
if (!existsSync(path))
|
|
118
|
+
return { entries: [], problems: [] };
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return { entries: [], problems: [`is not valid JSON: ${error instanceof Error ? error.message : error}`] };
|
|
125
|
+
}
|
|
126
|
+
if (!Array.isArray(parsed))
|
|
127
|
+
return { entries: [], problems: ['is not a list of { "contract", "reason" }'] };
|
|
128
|
+
const entries = [];
|
|
129
|
+
const problems = [];
|
|
130
|
+
parsed.forEach((entry, index) => {
|
|
131
|
+
if (!isRecord(entry) || typeof entry.contract !== "string" || !entry.contract) {
|
|
132
|
+
problems.push(`entry ${index + 1} is not { "contract", "reason" }`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (entries.some((seen) => seen.contract === entry.contract))
|
|
136
|
+
problems.push(`${entry.contract} is listed twice`);
|
|
137
|
+
entries.push({ contract: entry.contract, reason: typeof entry.reason === "string" ? entry.reason.trim() : "" });
|
|
138
|
+
});
|
|
139
|
+
return { entries, problems };
|
|
140
|
+
};
|
|
141
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
113
142
|
const CATEGORY_NAMES = CATEGORY_CONTRACTS.flatMap((entry) => entry.names);
|
|
114
143
|
const contractsRow = (cwd, category, runs, report) => {
|
|
115
144
|
const title = "Tests and category contracts";
|
|
@@ -136,18 +165,44 @@ const contractsRow = (cwd, category, runs, report) => {
|
|
|
136
165
|
});
|
|
137
166
|
const ran = new Set(calls.filter(({ file }) => ranInReport(report, file) === undefined).map((call) => call.contract));
|
|
138
167
|
const notRun = contracts.filter((contract) => !ran.has(contract));
|
|
168
|
+
const { entries: exceptions, problems } = contractExceptions(cwd);
|
|
169
|
+
const reasonOf = (contract) => exceptions.find((entry) => entry.contract === contract)?.reason;
|
|
170
|
+
const wrong = [
|
|
171
|
+
...problems,
|
|
172
|
+
...exceptions.filter((entry) => !entry.reason).map((entry) => `${entry.contract} has no reason`),
|
|
173
|
+
...exceptions
|
|
174
|
+
.filter((entry) => !contracts.includes(entry.contract))
|
|
175
|
+
.map((entry) => `${entry.contract} is no contract of "${category}"`),
|
|
176
|
+
...exceptions.filter((entry) => ran.has(entry.contract)).map((entry) => `${entry.contract} runs now`),
|
|
177
|
+
];
|
|
178
|
+
const excepted = notRun.filter((contract) => reasonOf(contract));
|
|
179
|
+
const missing = notRun.filter((contract) => !reasonOf(contract));
|
|
139
180
|
const row = scriptRow("contracts", title, runs, [
|
|
140
181
|
...evidence,
|
|
141
|
-
...(
|
|
182
|
+
...excepted.map((contract) => `not run, excepted in ${EXCEPTIONS}: ${contract} — ${reasonOf(contract)}`),
|
|
183
|
+
...(missing.length > 0 ? [`not run: ${missing.join(", ")}`] : []),
|
|
184
|
+
...wrong.map((problem) => `${EXCEPTIONS}: ${problem}`),
|
|
142
185
|
]);
|
|
143
|
-
if (
|
|
186
|
+
if (row.fix)
|
|
144
187
|
return row;
|
|
145
|
-
|
|
146
|
-
...row,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
188
|
+
if (wrong.length > 0)
|
|
189
|
+
return { ...row, status: "not verified", fix: `correct ${EXCEPTIONS}: ${wrong[0]}, then run cli-dev ready again` };
|
|
190
|
+
if (missing.length > 0)
|
|
191
|
+
return {
|
|
192
|
+
...row,
|
|
193
|
+
status: ran.size > 0 ? "partially" : "not verified",
|
|
194
|
+
fix: `run cli-core's ${missing[0]} in a test (testing.md), or except it in ${EXCEPTIONS} with its reason, ` +
|
|
195
|
+
"then run cli-dev ready again",
|
|
196
|
+
};
|
|
197
|
+
// Every contract excepted leaves the row checking nothing.
|
|
198
|
+
if (ran.size === 0)
|
|
199
|
+
return {
|
|
200
|
+
...row,
|
|
201
|
+
status: "not verified",
|
|
202
|
+
fix: `run at least one of ${contracts.join(", ")} in a test (testing.md), then run cli-dev ready again`,
|
|
203
|
+
};
|
|
204
|
+
// An exception is a known gap, not a check that passed; it needs no fix, so it does not hold back `next`.
|
|
205
|
+
return excepted.length > 0 ? { ...row, status: "partially" } : row;
|
|
151
206
|
};
|
|
152
207
|
const liveRow = (cwd, shell, version) => {
|
|
153
208
|
const title = "Live check against the service";
|
|
@@ -214,7 +269,7 @@ export const readyReport = (io, shell) => {
|
|
|
214
269
|
scriptRow("deps", "Dependencies", run("deps:check")),
|
|
215
270
|
liveRow(cwd, shell, packageVersion(cwd)),
|
|
216
271
|
];
|
|
217
|
-
const next = rows.find((row) => row.
|
|
272
|
+
const next = rows.find((row) => row.fix)?.fix;
|
|
218
273
|
return { ...(category ? { category } : {}), rows, ...(next ? { next } : {}) };
|
|
219
274
|
};
|
|
220
275
|
const MARK = {
|
|
@@ -231,7 +286,12 @@ export const readyText = (report) => {
|
|
|
231
286
|
for (const evidence of row.evidence)
|
|
232
287
|
lines.push(`${" ".repeat(width + 2)}${evidence}`);
|
|
233
288
|
}
|
|
234
|
-
|
|
289
|
+
const excepted = report.rows.filter((row) => row.status === "partially").map((row) => row.title);
|
|
290
|
+
lines.push("", report.next
|
|
291
|
+
? `next: ${report.next}`
|
|
292
|
+
: excepted.length > 0
|
|
293
|
+
? `next: nothing to do; partially, by declared exceptions: ${excepted.join(", ")}`
|
|
294
|
+
: "next: nothing; every check is verified or does not apply");
|
|
235
295
|
return lines.join("\n");
|
|
236
296
|
};
|
|
237
297
|
export const ready = (args, io, shell) => {
|
|
@@ -245,5 +305,6 @@ export const READY_USAGE = ` ready [--json] runs the CLI'
|
|
|
245
305
|
generate:check, smoke, security:no-leak,
|
|
246
306
|
deps:check) and reads the live-check record; prints each row as
|
|
247
307
|
verified, partially, not verified or unsupported with its evidence,
|
|
248
|
-
and the one next step; exits 1
|
|
249
|
-
|
|
308
|
+
and the one next step; exits 1 while a row has a fix (a category
|
|
309
|
+
contract excepted with its reason in lint/contract-exceptions.json
|
|
310
|
+
shows partially and needs none)`;
|
|
@@ -140,6 +140,34 @@ hosts a link points at (`downloader.disk.yandex.ru`, `*.disk.yandex.net`), and r
|
|
|
140
140
|
scheme or with the `auth` header. A CLI writes only its scenarios. `looseObjects` lets unknown fields through, for a
|
|
141
141
|
source whose subtypes the definitions cannot tell apart.
|
|
142
142
|
|
|
143
|
+
### The API part of the agent skill
|
|
144
|
+
|
|
145
|
+
`apiSkillFiles({ cli, folder, files, service, skill, operations, commands, banner })` writes the API part of the
|
|
146
|
+
CLI's skill, in the shape of [openapi-to-skills](https://github.com/neutree-ai/openapi-to-skills): `references/api.md`,
|
|
147
|
+
a short index of the groups with their effects, and `references/api/api-<group>.md`, one file per group. An
|
|
148
|
+
operation's group is its first tag; one without a tag is in `api-untagged.md`. A tag with no Latin letter or digit
|
|
149
|
+
cannot name a file and stops the generation. An agent reads
|
|
150
|
+
the index, then only the group it needs, with `<cli> skill show api-<group>`. The `skill` command already ships and
|
|
151
|
+
shows every file beside `SKILL.md`; nothing else is needed.
|
|
152
|
+
|
|
153
|
+
- `commands` is `describeProgram(createProgram())` from the built program, made with the CLI's own copy of cli-base.
|
|
154
|
+
Each command's usage, arguments and flags come from there, as `--help` prints them; a flag is never made up from
|
|
155
|
+
the spec. An operation and its command are matched by the command's `api_operation`. An operation without a
|
|
156
|
+
command, a generated command whose operation is not in the manifest, and two commands for one operation stop the
|
|
157
|
+
generation.
|
|
158
|
+
- The manifest adds what only the API knows: the HTTP call, the effect, sign-in scopes, permission keys, paging
|
|
159
|
+
(named by the API's parameters and answer fields) and the request body's schema. Vendor text is cut to its first
|
|
160
|
+
line, its HTML and Markdown marks are escaped, and it always follows a label, since an installed skill is
|
|
161
|
+
instructions an agent follows.
|
|
162
|
+
- There are no examples: the manifest has none, and the generated commands carry none.
|
|
163
|
+
- `skill` is the text of `SKILL.md`, which must link `references/api.md`, or the agent never finds the files.
|
|
164
|
+
`files` is `skillFiles(<SKILL.md URL>)`: `skill show` finds a part by its base name, so a hand-written `api.md` or
|
|
165
|
+
`api-<name>.md` elsewhere in the folder, which would hide a generated one, stops the generation.
|
|
166
|
+
- Run it after the build, beside the commands page, and write it with
|
|
167
|
+
`writeArtifacts(files, { root, check, owns: ["skills/<cli>/references/api"] })`: `owns` makes a file of a group
|
|
168
|
+
that left the spec stale, so `generate:check` catches it, and `pnpm generate` removes it. The output holds no
|
|
169
|
+
version or date, so a version bump leaves it current.
|
|
170
|
+
|
|
143
171
|
### Provenance
|
|
144
172
|
|
|
145
173
|
The coverage page lists every operation, with its call, command, effect and how far its request body can be trusted
|
package/docs/standards/layout.md
CHANGED
|
@@ -20,7 +20,7 @@ Rule ids on this page are `WC-LAY-<n>`. How to read a rule, how ids work and whi
|
|
|
20
20
|
- `bin/`: the repository's own scripts, such as `bin/release` and a wrapper that runs the local build;
|
|
21
21
|
- `scripts/`: development scripts in TypeScript or JavaScript;
|
|
22
22
|
- `docs/`: user pages; `docs/dev/`: developer pages;
|
|
23
|
-
- `lint/`: `baseline/` and `overrides.json` for the command lint
|
|
23
|
+
- `lint/`: `baseline/` and `overrides.json` for the command lint, `contract-exceptions.json` for `cli-dev ready`;
|
|
24
24
|
- `contracts/`: the offline contract plan and its snapshots;
|
|
25
25
|
- `config/wirecat/`: the shared presets;
|
|
26
26
|
- `skills/`: the agent skill the package ships;
|
|
@@ -183,7 +183,11 @@ All of these pass on `main`, before the first release. `cli-dev ready` runs the
|
|
|
183
183
|
order and prints what each one proves: verified (a script passed, a test runs the category's cli-core contract, the
|
|
184
184
|
live-check record is of this code), partially, not verified, or unsupported (a check that cannot apply: the live
|
|
185
185
|
check in cli-template itself). A contract call counts only when vitest's report shows its test file ran with no test
|
|
186
|
-
skipped
|
|
186
|
+
skipped, and every contract of the category must run. A CLI that cannot run one lists it in
|
|
187
|
+
`lint/contract-exceptions.json` as `[{ "contract": "crmSyncContract", "reason": "…" }]`; the row then shows
|
|
188
|
+
partially with the reason, and the exception does not hold back the exit code. An exception without a reason, for
|
|
189
|
+
another category's contract, for a contract that runs, or for every contract is not verified. A missing script is
|
|
190
|
+
not verified. `--json` gives the same rows and the one next
|
|
187
191
|
step to an agent. It never runs the live check: that is the owner's run against their account.
|
|
188
192
|
|
|
189
193
|
- `pnpm standards:check`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.109.0",
|
|
4
4
|
"description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|