@wirecat/cli-base 0.116.0 → 0.118.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.
@@ -0,0 +1,333 @@
1
+ /**
2
+ * WordPress's REST index (`/wp-json/?context=help`), already parsed → an OpenAPI 3.1 document, so `adaptOpenApi` reads
3
+ * it like any other. WordPress publishes no OpenAPI: the index lists each route's endpoints with their arguments, and
4
+ * with `context=help` also the schema of what the route answers, the same one an `OPTIONS` call returns. One request
5
+ * holds the whole API, so `syncWpJson` keeps that one answer with its provenance and `readWpJson` loads it back only
6
+ * while its hash still matches.
7
+ *
8
+ * Strict like `adaptOpenApi`: a route that cannot become a path template, two routes on one path, or an argument with
9
+ * no type stops generation unless `exclude` names the route with a reason.
10
+ */
11
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { CodegenError } from "./pipeline.js";
14
+ import { sha256, sortKeys } from "./snapshot.js";
15
+ const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
16
+ /** WordPress's own, beside JSON Schema: which `context` shows a field, and its spelling of `readOnly`. */
17
+ const DROPPED = new Set(["context", "readonly", "arg_options", "links", "$schema", "patternProperties", "required"]);
18
+ /** WordPress names the boolean type `bool` in a few block attributes. */
19
+ const typeName = (type) => type === "bool" ? "boolean" : Array.isArray(type) ? type.map(typeName) : type;
20
+ /**
21
+ * One JSON Schema draft 4 node, as WordPress writes it, → its OpenAPI 3.1 form: a field's `required: true` joins its
22
+ * object's `required` list, a node with `properties` and no type is an object, and a draft 4 `exclusiveMinimum: true`
23
+ * goes, keeping `minimum`, which accepts one value more and refuses nothing valid. `patternProperties` (block names to their hooks) becomes the object's
24
+ * `additionalProperties`: the keys are free, the values keep their schema.
25
+ */
26
+ const schemaOf = (value, where) => {
27
+ if (!object(value))
28
+ throw new CodegenError([`${where}: expected a schema object`]);
29
+ const out = {};
30
+ for (const [key, field] of Object.entries(value)) {
31
+ if (DROPPED.has(key))
32
+ continue;
33
+ if ((key === "exclusiveMinimum" || key === "exclusiveMaximum") && typeof field === "boolean")
34
+ continue;
35
+ if (key === "type")
36
+ out.type = typeName(field);
37
+ else if (key === "properties" && object(field))
38
+ out.properties = Object.fromEntries(Object.entries(field).map(([name, inner]) => [name, schemaOf(inner, `${where}/properties/${name}`)]));
39
+ else if (key === "items")
40
+ out.items = schemaOf(field, `${where}/items`);
41
+ else if ((key === "oneOf" || key === "anyOf") && Array.isArray(field))
42
+ // A `required` beside the alternatives names fields each of them holds.
43
+ out[key] = field.map((member, index) => schemaOf(object(member) && Array.isArray(value.required) && object(member.properties)
44
+ ? {
45
+ ...member,
46
+ required: [...new Set([...(Array.isArray(member.required) ? member.required : []), ...value.required])],
47
+ }
48
+ : member, `${where}/${key}/${index}`));
49
+ else if (key === "additionalProperties" && object(field))
50
+ out.additionalProperties = schemaOf(field, `${where}/additionalProperties`);
51
+ else
52
+ out[key] = field;
53
+ }
54
+ if (object(value.properties)) {
55
+ const required = [
56
+ ...(Array.isArray(value.required) ? value.required.map(String) : []),
57
+ ...Object.entries(value.properties)
58
+ .filter(([, inner]) => object(inner) && inner.required === true)
59
+ .map(([name]) => name),
60
+ ];
61
+ if (required.length > 0)
62
+ out.required = [...new Set(required)];
63
+ out.type ??= "object";
64
+ }
65
+ if (object(value.patternProperties) && out.additionalProperties === undefined) {
66
+ const members = Object.entries(value.patternProperties).map(([pattern, inner]) => schemaOf(inner, `${where}/patternProperties/${pattern}`));
67
+ out.additionalProperties = members.length === 1 ? members[0] : { anyOf: members };
68
+ }
69
+ if (out.type === undefined && out.oneOf === undefined && out.anyOf === undefined)
70
+ throw new CodegenError([`${where}: no type`]);
71
+ return out;
72
+ };
73
+ /**
74
+ * `(?P<id>[\d]+)` → `{id}`, with the group's pattern; `"slash"` when a value may hold one; `undefined` when the rest
75
+ * is still a pattern, not a path.
76
+ */
77
+ const template = (route) => {
78
+ const patterns = {};
79
+ let path = "";
80
+ let at = 0;
81
+ while (at < route.length) {
82
+ const start = route.indexOf("(?P<", at);
83
+ if (start < 0) {
84
+ path += route.slice(at);
85
+ break;
86
+ }
87
+ path += route.slice(at, start);
88
+ const close = route.indexOf(">", start);
89
+ const name = route.slice(start + 4, close);
90
+ let depth = 1;
91
+ let index = close + 1;
92
+ let inClass = false;
93
+ for (; index < route.length && depth > 0; index++) {
94
+ const char = route[index];
95
+ if (char === "\\")
96
+ index++;
97
+ else if (inClass)
98
+ inClass = char !== "]";
99
+ else if (char === "[")
100
+ inClass = true;
101
+ else if (char === "(")
102
+ depth++;
103
+ else if (char === ")")
104
+ depth--;
105
+ }
106
+ if (depth > 0)
107
+ return undefined;
108
+ patterns[name] = route.slice(close + 1, index - 1);
109
+ path += `{${name}}`;
110
+ at = index;
111
+ }
112
+ if (/[()[\]?*+\\^$|]/.test(path))
113
+ return undefined;
114
+ // A value that may hold a slash, as a template's `theme//slug`, does not fit in one path segment.
115
+ const slashed = (pattern) => {
116
+ try {
117
+ const regex = new RegExp(`^(?:${pattern})$`);
118
+ return ["a/b", "1/2", "/", "a/", "/a", "a-b/c_d", "1/a"].some((sample) => regex.test(sample));
119
+ }
120
+ catch {
121
+ return true;
122
+ }
123
+ };
124
+ if (Object.values(patterns).some(slashed))
125
+ return "slash";
126
+ return { path, patterns };
127
+ };
128
+ /** Collection reads page with `page` and `per_page` and answer a list; every other answer is one item. */
129
+ const isList = (args) => "per_page" in args && "page" in args;
130
+ /**
131
+ * The OpenAPI document of the routes under `namespaces`. A route offers GET as a read, DELETE as a delete with its
132
+ * arguments in the query (`force=true`), and one write: POST where the route takes it, as WordPress takes the same
133
+ * call by POST, PUT and PATCH. A write's arguments are its JSON body. An array argument in the query travels as one
134
+ * comma-separated value, which WordPress splits, as PHP keeps only the last of a repeated name.
135
+ */
136
+ export const wpJsonToOpenApi = (index, options) => {
137
+ if (!object(index) || !object(index.routes))
138
+ throw new CodegenError(["not a WordPress REST index: no routes"]);
139
+ const exclude = options.exclude ?? {};
140
+ const used = new Set();
141
+ const problems = [];
142
+ const omissions = [];
143
+ const paths = {};
144
+ const schemas = {};
145
+ const left = new Map();
146
+ const schemaRef = (route, schema) => {
147
+ const title = object(schema) && typeof schema.title === "string" ? schema.title : route;
148
+ const base = title.replace(/[^A-Za-z0-9]+/g, "_");
149
+ const converted = schemaOf(schema, `${route} schema`);
150
+ let name = base;
151
+ for (let n = 2; schemas[name] && JSON.stringify(schemas[name]) !== JSON.stringify(converted); n++)
152
+ name = `${base}${n}`;
153
+ schemas[name] = converted;
154
+ return { $ref: `#/components/schemas/${name}` };
155
+ };
156
+ for (const [route, raw] of Object.entries(index.routes)) {
157
+ if (!object(raw))
158
+ throw new CodegenError([`${route}: not a route`]);
159
+ const namespace = String(raw.namespace ?? "");
160
+ if (!options.namespaces.includes(namespace)) {
161
+ left.set(namespace, (left.get(namespace) ?? 0) + 1);
162
+ continue;
163
+ }
164
+ // The namespace's own index: the description, not an operation.
165
+ if (route === `/${namespace}`)
166
+ continue;
167
+ if (exclude[route] !== undefined) {
168
+ used.add(route);
169
+ omissions.push(`${route}: excluded — ${exclude[route]}`);
170
+ continue;
171
+ }
172
+ const templated = template(route);
173
+ if (templated === "slash") {
174
+ omissions.push(`${route}: left out, as its value may hold a slash, which no path segment carries`);
175
+ continue;
176
+ }
177
+ if (!templated) {
178
+ problems.push(`${route}: the route is a pattern no path template expresses; exclude it with a reason`);
179
+ continue;
180
+ }
181
+ const { path, patterns } = templated;
182
+ if (paths[path]) {
183
+ problems.push(`${route}: a second route on ${path}; exclude one with a reason`);
184
+ continue;
185
+ }
186
+ const item = {};
187
+ const endpoints = Array.isArray(raw.endpoints) ? raw.endpoints.filter(object) : [];
188
+ try {
189
+ for (const endpoint of endpoints) {
190
+ const methods = (Array.isArray(endpoint.methods) ? endpoint.methods : []).map(String);
191
+ const args = object(endpoint.args) ? endpoint.args : {};
192
+ const write = ["POST", "PUT", "PATCH"].find((method) => methods.includes(method));
193
+ const dropped = methods.filter((method) => method !== write && ["PUT", "PATCH"].includes(method));
194
+ if (dropped.length > 0)
195
+ omissions.push(`${route}: ${dropped.join(", ")} left out, as ${write} does the same`);
196
+ for (const method of methods.filter((one) => one === "GET" || one === "DELETE" || one === write)) {
197
+ const verb = method.toLowerCase();
198
+ if (item[verb])
199
+ throw new CodegenError([`${route}: two endpoints answer ${method}`]);
200
+ const where = `${route} ${method}`;
201
+ const pathParameters = Object.entries(patterns).map(([name, pattern]) => ({
202
+ name,
203
+ in: "path",
204
+ required: true,
205
+ schema: object(args[name])
206
+ ? schemaOf(args[name], `${where} ${name}`)
207
+ : { type: "string", pattern: `^(?:${pattern})$` },
208
+ }));
209
+ const rest = Object.entries(args).filter(([name]) => patterns[name] === undefined);
210
+ const operation = { parameters: pathParameters };
211
+ if (method === write) {
212
+ if (rest.length > 0)
213
+ operation.requestBody = {
214
+ required: rest.some(([, arg]) => object(arg) && arg.required === true),
215
+ content: {
216
+ "application/json": {
217
+ schema: schemaOf({ type: "object", properties: Object.fromEntries(rest) }, `${where} body`),
218
+ },
219
+ },
220
+ };
221
+ }
222
+ else
223
+ operation.parameters = [
224
+ ...pathParameters,
225
+ ...rest.map(([name, arg]) => {
226
+ const schema = schemaOf(arg, `${where} ${name}`);
227
+ const list = schema.type === "array" || (Array.isArray(schema.type) && schema.type.includes("array"));
228
+ return {
229
+ name,
230
+ in: "query",
231
+ required: object(arg) && arg.required === true,
232
+ ...(typeof schema.description === "string" ? { description: schema.description } : {}),
233
+ schema: list
234
+ ? { type: "string", description: `${schema.description ?? name}; several, comma-separated` }
235
+ : schema,
236
+ };
237
+ }),
238
+ ];
239
+ if (raw.schema !== undefined && method !== "DELETE") {
240
+ const ref = schemaRef(route, raw.schema);
241
+ const answer = method === "GET" && isList(args) ? { type: "array", items: ref } : ref;
242
+ operation.responses = { "200": { description: "OK", content: { "application/json": { schema: answer } } } };
243
+ }
244
+ else
245
+ operation.responses = { "200": { description: "OK" } };
246
+ item[verb] = operation;
247
+ }
248
+ }
249
+ }
250
+ catch (error) {
251
+ if (!(error instanceof CodegenError))
252
+ throw error;
253
+ for (const problem of error.problems)
254
+ problems.push(problem);
255
+ continue;
256
+ }
257
+ if (Object.keys(item).length > 0)
258
+ paths[path] = item;
259
+ }
260
+ for (const [namespace, count] of left)
261
+ omissions.push(`${namespace || "routes outside a namespace"}: not offered, ${count} routes`);
262
+ const stale = Object.keys(exclude).filter((route) => !used.has(route));
263
+ for (const route of stale)
264
+ problems.push(`exclusion "${route}" matches no route — stale, or the route changed`);
265
+ if (problems.length > 0)
266
+ throw new CodegenError(problems);
267
+ return {
268
+ document: {
269
+ openapi: "3.1.0",
270
+ info: { title: "WordPress REST API", version: options.version ?? "unknown" },
271
+ servers: [{ url: "https://{site}/wp-json", variables: { site: { default: options.site ?? "example.com" } } }],
272
+ // An application password, sent as Basic `<user>:<password>`.
273
+ components: { schemas, securitySchemes: { applicationPassword: { type: "http", scheme: "basic" } } },
274
+ security: [{ applicationPassword: [] }],
275
+ paths,
276
+ },
277
+ omissions,
278
+ };
279
+ };
280
+ const FILE = "wp-json.json";
281
+ /** The site's name, address, time zone and links go, the schemas' `links` too: the API is the same from any site. */
282
+ const ROUTE_FIELDS = ["namespace", "methods", "endpoints", "schema"];
283
+ /**
284
+ * Asks `root` (`https://<site>/wp-json/`) for its index with every schema and writes `wp-json.json` and
285
+ * `provenance.json` to `dir`. Take it from a plain WordPress, as the CLI serves every site: a plugin's routes and
286
+ * fields belong to that site. Run by hand, then review the diff: the build never fetches.
287
+ */
288
+ export const syncWpJson = async (options) => {
289
+ const fetch = options.fetch ?? globalThis.fetch;
290
+ const url = new URL(options.root);
291
+ // The URL goes into provenance.json; a user or password in it must not.
292
+ url.username = "";
293
+ url.password = "";
294
+ url.searchParams.set("context", "help");
295
+ const response = await fetch(url, { signal: AbortSignal.timeout(30_000), redirect: "error" });
296
+ if (!response.ok)
297
+ throw new Error(`WordPress index fetch failed: HTTP ${response.status}`);
298
+ const index = await response.json();
299
+ if (!object(index) || !object(index.routes) || !Array.isArray(index.namespaces))
300
+ throw new Error(`${options.root} is not a WordPress REST index`);
301
+ const routes = Object.fromEntries(Object.entries(index.routes).map(([route, value]) => [
302
+ route,
303
+ object(value)
304
+ ? Object.fromEntries(ROUTE_FIELDS.filter((key) => key in value).map((key) => {
305
+ const field = value[key];
306
+ if (key !== "schema" || !object(field))
307
+ return [key, field];
308
+ const { links: _, ...schema } = field;
309
+ return [key, schema];
310
+ }))
311
+ : value,
312
+ ]));
313
+ const written = `${JSON.stringify(sortKeys({ namespaces: index.namespaces, routes }), null, 2)}\n`;
314
+ const provenance = {
315
+ source: url.href,
316
+ version: options.version,
317
+ sha256: sha256(written),
318
+ retrieved_at: (options.now ?? new Date()).toISOString(),
319
+ normalization: "the namespaces and each route's namespace, methods, endpoints and schema (without its links); keys sorted, 2-space JSON",
320
+ };
321
+ mkdirSync(options.dir, { recursive: true });
322
+ writeFileSync(join(options.dir, FILE), written);
323
+ writeFileSync(join(options.dir, "provenance.json"), `${JSON.stringify(provenance, null, 2)}\n`);
324
+ return provenance;
325
+ };
326
+ /** The snapshot `syncWpJson` wrote, parsed. Throws if its hash changed. */
327
+ export const readWpJson = (dir) => {
328
+ const provenance = JSON.parse(readFileSync(join(dir, "provenance.json"), "utf8"));
329
+ const raw = readFileSync(join(dir, FILE));
330
+ if (sha256(raw) !== provenance.sha256)
331
+ throw new CodegenError([`WordPress index hash mismatch: ${join(dir, FILE)}`]);
332
+ return JSON.parse(raw.toString("utf8"));
333
+ };
@@ -8,6 +8,7 @@ const PACKAGES = new Map([
8
8
  ...FIRST_PARTY_TOOLS.flatMap((tool) => (tool.package ? [[tool.name, tool.package]] : [])),
9
9
  ["gcal", "@wirecat/gcal-cli"],
10
10
  ["b24", "@wirecat/bitrix24-cli"],
11
+ ["ydisk", "@wirecat/yandex-disk-cli"],
11
12
  ]);
12
13
  /** Every other CLI of the parity groups that npm has, by name. */
13
14
  export const familyPackages = (groups, own) => new Map([...new Set(groups.flatMap((group) => group.members))]
@@ -159,10 +159,12 @@ export const PARITY_GROUPS = defineParityGroups([
159
159
  // bitrix24-cli's search is cli-core's CRM `search all`, and beeline-cli's and asterisk-cli's meetings take call
160
160
  // recordings, not zoom-cli's: they are compared on the root commands every CLI shares, the way gcal and mail are.
161
161
  // amo-cli and hubspot-cli share them too, and their CRM commands are compared with b24 in `crm` below.
162
- // notion-cli joins here until its documents commands ship; then it moves next to drive.
162
+ // notion-cli joins here until its documents commands ship; then it moves next to drive. ydisk joins here too: in "all"
163
+ // its search and notes differ from the messengers' and memo's as drive's do, and a documents group of drive, notion
164
+ // and ydisk differs in 39 paths (session, folders browse, summaries; measured on the published CLIs 2026-11-17).
163
165
  {
164
166
  name: "shared-roots",
165
- members: ["tg", "max", "memo", "drive", "zm", "wa", "b24", "beeline", "pbx", "notion", "amo", "hubspot"],
167
+ members: ["tg", "max", "memo", "drive", "zm", "wa", "b24", "beeline", "pbx", "notion", "amo", "hubspot", "ydisk"],
166
168
  covers: ["commands", "doctor", "skill", "mcp", "upgrade"],
167
169
  differences: [...MEMO_HAS_NO_PROFILES, ...MEMO_MCP_SUMMARIES, MEMO_DOCTOR_DEEP],
168
170
  },
@@ -289,6 +289,10 @@ const collections = [
289
289
  ["transactions", "money that moved in or out of a wallet, as the bank or the owner recorded it"],
290
290
  ["splits", "parts of one transaction, each with its own amount and category"],
291
291
  ["users", "people who work in the owner's account at a service, such as a CRM's employees"],
292
+ ["issues", "work items in an issue tracker, each in a team, a workflow state and maybe a project"],
293
+ ["teams", "groups in a tracker that own issues, states and labels"],
294
+ ["states", "the workflow steps a tracker team moves its issues through, each of a type such as started"],
295
+ ["labels", "a tracker's shared labels on issues, kept by the tracker and not by the owner"],
292
296
  ["fields", "a record type's field definitions: code, label, type and options, such as a CRM's custom fields"],
293
297
  ["activities", "a CRM's calls, e-mails, meetings, to-dos and comments on its records"],
294
298
  ["changes", "what changed in a copied source over a time: records added, moved, closed or reassigned"],
@@ -21,6 +21,20 @@ declare const signInSchema: v.StrictObjectSchema<{
21
21
  readonly gives: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
22
22
  /** What the person is asked for: "An Acme API token, from Settings → API." */
23
23
  readonly asks: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
24
+ /** Left out when the CLI signs in only at a terminal, so the manifest of every other CLI stays as it was. */
25
+ readonly methods: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
26
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a lower-case method id">]>;
27
+ /** The button or tab: "API token". */
28
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
29
+ /** `{profile}` first, then the command: `["{profile}", "session", "start", "--json"]`. */
30
+ readonly words: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, "a command word is at most 100 characters">, v.RegexAction<string, (issue: v.RegexIssue<string>) => string>]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
31
+ readonly stdin: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
32
+ }, undefined>, undefined>, v.MinLengthAction<{
33
+ id: string;
34
+ label: string;
35
+ words: string[];
36
+ stdin?: boolean | undefined;
37
+ }[], 1, undefined>]>, undefined>;
24
38
  }, undefined>;
25
39
  export type SignIn = v.InferOutput<typeof signInSchema>;
26
40
  /** Exactly the keys of a Desktop catalog entry that the tool itself knows; `null` when unused. */
@@ -42,6 +56,20 @@ declare const desktopSchema: v.StrictObjectSchema<{
42
56
  readonly gives: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
43
57
  /** What the person is asked for: "An Acme API token, from Settings → API." */
44
58
  readonly asks: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
59
+ /** Left out when the CLI signs in only at a terminal, so the manifest of every other CLI stays as it was. */
60
+ readonly methods: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
61
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a lower-case method id">]>;
62
+ /** The button or tab: "API token". */
63
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
64
+ /** `{profile}` first, then the command: `["{profile}", "session", "start", "--json"]`. */
65
+ readonly words: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, "a command word is at most 100 characters">, v.RegexAction<string, (issue: v.RegexIssue<string>) => string>]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
66
+ readonly stdin: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
67
+ }, undefined>, undefined>, v.MinLengthAction<{
68
+ id: string;
69
+ label: string;
70
+ words: string[];
71
+ stdin?: boolean | undefined;
72
+ }[], 1, undefined>]>, undefined>;
45
73
  }, undefined>, undefined>;
46
74
  readonly skill: v.NullableSchema<v.StrictObjectSchema<{
47
75
  readonly status: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, "a command word is at most 100 characters">, v.RegexAction<string, (issue: v.RegexIssue<string>) => string>]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
@@ -137,6 +165,20 @@ export declare const manifestSchema: v.StrictObjectSchema<{
137
165
  readonly gives: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
138
166
  /** What the person is asked for: "An Acme API token, from Settings → API." */
139
167
  readonly asks: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
168
+ /** Left out when the CLI signs in only at a terminal, so the manifest of every other CLI stays as it was. */
169
+ readonly methods: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
170
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a lower-case method id">]>;
171
+ /** The button or tab: "API token". */
172
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "one line of text">, v.MaxLengthAction<string, number, undefined>]>;
173
+ /** `{profile}` first, then the command: `["{profile}", "session", "start", "--json"]`. */
174
+ readonly words: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, "a command word is at most 100 characters">, v.RegexAction<string, (issue: v.RegexIssue<string>) => string>]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
175
+ readonly stdin: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
176
+ }, undefined>, undefined>, v.MinLengthAction<{
177
+ id: string;
178
+ label: string;
179
+ words: string[];
180
+ stdin?: boolean | undefined;
181
+ }[], 1, undefined>]>, undefined>;
140
182
  }, undefined>, undefined>;
141
183
  readonly skill: v.NullableSchema<v.StrictObjectSchema<{
142
184
  readonly status: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, "a command word is at most 100 characters">, v.RegexAction<string, (issue: v.RegexIssue<string>) => string>]>, undefined>, v.MinLengthAction<string[], 1, undefined>]>;
@@ -29,11 +29,25 @@ export const PLAIN_WORD = /^(?:--|-{0,2}(?:[A-Za-z0-9]|\{[A-Za-z]+\})(?:[A-Za-z0
29
29
  const plainWord = v.pipe(v.string(), v.maxLength(100, "a command word is at most 100 characters"), v.regex(PLAIN_WORD, (issue) => `${JSON.stringify(issue.input)} is not a plain word: letters, digits and ._:=,/+@-, at most two leading dashes, -- alone and {name} slots; no spaces, quotes or shell syntax`));
30
30
  const words = v.pipe(v.array(plainWord), v.minLength(1));
31
31
  const line = (max) => v.pipe(v.string(), v.regex(/^\S(?:[^\n\r]*\S)?$/, "one line of text"), v.maxLength(max));
32
+ /**
33
+ * A sign-in Desktop runs in its own window. Only the parts Desktop accepts from a tool it did not build: the words, and
34
+ * whether the secret the person types is the command's whole stdin.
35
+ */
36
+ const signInMethodSchema = v.strictObject({
37
+ id: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9-]{0,31}$/, "a lower-case method id")),
38
+ /** The button or tab: "API token". */
39
+ label: line(40),
40
+ /** `{profile}` first, then the command: `["{profile}", "session", "start", "--json"]`. */
41
+ words,
42
+ stdin: v.optional(v.boolean()),
43
+ });
32
44
  const signInSchema = v.strictObject({
33
45
  /** What signing in lets the agent do, in a sentence: "Lets your agent read your Acme contacts." */
34
46
  gives: line(300),
35
47
  /** What the person is asked for: "An Acme API token, from Settings → API." */
36
48
  asks: line(300),
49
+ /** Left out when the CLI signs in only at a terminal, so the manifest of every other CLI stays as it was. */
50
+ methods: v.optional(v.pipe(v.array(signInMethodSchema), v.minLength(1))),
37
51
  });
38
52
  /** Exactly the keys of a Desktop catalog entry that the tool itself knows; `null` when unused. */
39
53
  const desktopSchema = v.strictObject({
@@ -199,6 +213,23 @@ export const buildManifest = ({ identity, commands, pkg, skills }) => {
199
213
  },
200
214
  }
201
215
  : {};
216
+ const methods = identity.signIn?.methods;
217
+ for (const method of methods ?? []) {
218
+ const [first, ...rest] = method.words;
219
+ if (first !== "{profile}" || !profiles)
220
+ throw new ManifestError([
221
+ `signIn method ${method.id}: Desktop signs in a profile, so its words start with {profile}`,
222
+ ]);
223
+ // Arguments may follow the command (`session start qr`), so any leading run of words that is a command will do.
224
+ const runsAt = (end) => {
225
+ const command = at.get(rest.slice(0, end + 1).join(" "));
226
+ return command !== undefined && (command.commands.length === 0 || command.runnable === true);
227
+ };
228
+ if (!rest.some((_, end) => runsAt(end)))
229
+ throw new ManifestError([`signIn method ${method.id}: \`${rest.join(" ")}\` names no command of this CLI`]);
230
+ if (rest.some((word) => word.includes("{")))
231
+ throw new ManifestError([`signIn method ${method.id}: {profile} is the only slot Desktop fills in a sign-in`]);
232
+ }
202
233
  const twice = identity.hosts?.filter((host, index) => identity.hosts?.indexOf(host) !== index) ?? [];
203
234
  if (twice.length > 0)
204
235
  throw new ManifestError(twice.map((host) => `hosts: ${host} is listed twice`));
@@ -257,7 +288,9 @@ export const buildManifest = ({ identity, commands, pkg, skills }) => {
257
288
  : null,
258
289
  search: null,
259
290
  setup: setupPath ? [...profile, ...setupPath.split(" ")] : null,
260
- signIn: identity.signIn ? { gives: identity.signIn.gives, asks: identity.signIn.asks } : null,
291
+ signIn: identity.signIn
292
+ ? { gives: identity.signIn.gives, asks: identity.signIn.asks, ...(methods ? { methods } : {}) }
293
+ : null,
261
294
  skill: skills && has("skill status", "skill install", "skill show")
262
295
  ? {
263
296
  status: ["skill", "status", "--no-record", "--json"],
@@ -39,7 +39,7 @@ the four steps that need a person. A new CLI is ready for its first release when
39
39
  | [Store](store.md) | `STORE` | 14 | Store areas, account scope, migrations, test isolation |
40
40
  | [Data model](data-model.md) | `DATA` | 9 | Core entities, entities and source records, `external_id`, field names, links and duplicates, files, calendar entries |
41
41
  | [Testing](testing.md) | `TEST` | 19 | Sandbox, no network, no real waits, one test time limit, leak tests, coverage, contracts, test matrix, parity, fakes as strict as the service |
42
- | [Security](security.md) | `SECR` | 24 | Secrets, logs, keyring, argv, error text, untrusted text, scanners, workflow hardening, reporting, OAuth sign-in and which app it uses, meeting secrets, keyring in moved-folder runs |
42
+ | [Security](security.md) | `SECR` | 25 | Secrets, logs, keyring, argv, error text, untrusted text, scanners, workflow hardening, reporting, OAuth sign-in and which app it uses, a provider token the owner pastes, meeting secrets, keyring in moved-folder runs |
43
43
  | [Documents](docs.md) | `DOC` | 24 | User pages and developer pages, generated pages, current facts, changelog, repository page |
44
44
  | [Comparisons](comparisons.md) | `CMP` | 11 | Which tools a comparison page lists, rows as user tasks, agents and safety, where others are better, proof of marks |
45
45
  | [Releases](releases.md) | `REL` | 16 | `bin/release`, the release lock, versions, the owner's yes, trusted publishing |
@@ -100,7 +100,12 @@ cli-core's entities, and the adapter behind cli-core's ports. CRM is the first d
100
100
  Telegram's app registration, or gcal's generated `api` commands. Known gap, as of 2026-11-08: b24's `people`,
101
101
  `organizations`, `products` and `users` are still its own commands, read live, with its own `people` and
102
102
  `organizations` writes; they move to cli-core's when it has them. Deals, leads, pipelines, stages and `sync` are
103
- cli-core's.
103
+ cli-core's. Known gap, as of 2026-11-17: cli-core has no shared files domain yet, so the live `files` group that
104
+ reads and changes the provider's files is hand-written in each file-storage CLI: drive's `files list`, `get`,
105
+ `copy`, `move`, `update`, `mkdir` and `upload` (`src/commands/remote.ts`), and ydisk's `files list`, `download`,
106
+ `upload`, `copy`, `move`, `delete` and `restore` (`src/commands/files.ts`). Their paths, flags and output may differ
107
+ until the group moves to cli-core; a third file-storage CLI waits for it or copies the nearer of the two, not a
108
+ third shape.
104
109
  - **Applies to:** messenger CLIs (tg, max, wa), calendar CLIs (gcal) and CRM CLIs (b24). **Since:** cli-base 0.41.0
105
110
  (CRM, and the shared domain built first: cli-base 0.80.1). **Rulings:** NEED-820, NEED-440, NEED-301, NEED-444,
106
111
  NEED-2298.
@@ -184,6 +184,7 @@ its prompt in cli-template says so from cli-template 0.8.0. A CLI on an older te
184
184
  | 02:55 | amo-cli |
185
185
  | 02:59 | max-cli |
186
186
  | 03:02 | cli-template |
187
+ | 03:04 | ydisk-cli |
187
188
  | 03:06 | tg-cli |
188
189
  | 03:09 | beeline-cli |
189
190
  | 03:11 | hubspot-cli |
@@ -390,7 +390,11 @@ file shipped, `--wcat-describe` answers format 2: the format-1 keys with `"wcat_
390
390
  and `manifest_sha256` of its bytes. Without it the answer stays format 1.
391
391
 
392
392
  A new CLI joins from its first release: that release installs `wcat-<name>` (a `"bin"` key) and its bin calls
393
- `wcatStart` first, so it answers `--wcat-describe`. The short name may stay beside it.
393
+ `wcatStart` first, so it answers `--wcat-describe`. That key is all the rule requires of the name. The short name
394
+ beside it, the command word people type (`ydisk`, `gcal`), is fine and is what WireCat CLIs do: the template writes
395
+ both keys, and tg, max, wa, zm, b24, gcal, drive, notion, memo, mail, pbx and ydisk each install `<name>` and
396
+ `wcat-<name>` from the same file. The short word is lower-case letters, digits and `-`, and a CLI outside WireCat
397
+ does not take a reserved one.
394
398
 
395
399
  - **Why:** `wcat <name>` runs any `wcat-<name>` program on PATH, and `wcat --help` lists each one with what it says
396
400
  about itself. A name WireCat reserves would be taken over by WireCat's own tool or by a `wcat` command. WireCat
@@ -406,9 +410,10 @@ A new CLI joins from its first release: that release installs `wcat-<name>` (a `
406
410
  answer `--wcat-describe`. `cli-dev manifest --program dist/program.js --identity dist/wcat.js --check` fails when
407
411
  `contracts/wirecat.json` is stale. `cli-dev release-pr` fails the pull request that raises the version from `0.0.0`,
408
412
  the version `new` writes, when `package.json` has no `wcat-` `"bin"` key.
409
- - **Exceptions:** a CLI keeps its short `"bin"` name beside `wcat-<name>` until callers have moved to the new name; the
410
- warning stays until then. A CLI that keeps the short name for good says why in `lint/overrides.json` (`"rule":
411
- "wcat-bin-name"`, the target as the warning prints it), which silences the warning and counts against the budget.
413
+ - **Exceptions:** `cli-dev lint` warns about every `"bin"` key without the prefix, the short name beside `wcat-<name>`
414
+ included. A CLI that keeps the short name says why in `lint/overrides.json` (`"rule": "wcat-bin-name"`, the target
415
+ as the warning prints it), which silences the warning and counts against the budget; gcal, pbx and beeline do,
416
+ and the other CLIs carry the warning. Either is allowed: the warning is not a failure.
412
417
  An override covers the short name only, never a CLI with no `wcat-<name>`: `cli-dev release-pr` does not read
413
418
  `lint/overrides.json`.
414
419
  A WireCat CLI listed in Desktop's own catalog needs no manifest until Desktop reads one for it.
@@ -48,6 +48,7 @@ what it cannot do yet.
48
48
  | Swagger 1.2 (Yandex Disk) | `upgradeToOpenApi3(listing, declarations)`: the resource listing, and each API declaration keyed by its `apis[].path`, fetched from the listing's `basePath` followed by that path |
49
49
  | Google Discovery | `adaptDiscovery(readDiscovery(dir))`, snapshots written by `syncDiscovery` |
50
50
  | GraphQL (Linear) | `adaptGraphql(readGraphql(dir), { url, scalars })`, the introspection result written by `syncGraphql` |
51
+ | WordPress's REST index | `adaptOpenApi(wpJsonToOpenApi(readWpJson(dir), { namespaces: ["wp/v2"] }).document)`, the index written by `syncWpJson` |
51
52
 
52
53
  `upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
53
54
  [@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
@@ -106,7 +107,7 @@ From the source the generator reads:
106
107
  empty or not in kebab case stops generation; map that operation in `commands`. `segments` renames a path segment
107
108
  or, with `""`, leaves it out: `{ "0-3": "deals", crm: "", objects: "" }`. Without `names` the command is the operation
108
109
  id in kebab case, as before.
109
- - **`permissions`**: `{ group, deletingFlags, shares }`. `group` is a name (`files`) or a function of the operation, for
110
+ - **`permissions`**: `{ group, deletingFlags, shares, valueKeys }`. `group` is a name (`files`) or a function of the operation, for
110
111
  example the first word of its `command` (set only with `names`). Each key lands in the manifest as the operation's `permissions`.
111
112
  - `<group>.delete` for every destructive operation (Yandex Disk's `DELETE /trash/resources` empties the whole
112
113
  trash), and for every operation that takes a flag in `deletingFlags`, as a top-level body field (Notion's
@@ -114,6 +115,13 @@ From the source the generator reads:
114
115
  key applies when the flag is `true`. A flag no operation takes stops generation.
115
116
  - `<group>.share` for the operation ids in `shares`: a public link opens a file to anyone, which is neither a
116
117
  plain write nor a delete.
118
+ - `<group>.<key>` for each of `valueKeys`, `{ key, field, values }`, on every write or delete whose body field or
119
+ query parameter `field` lists one of `values` in its `enum`, through a reference or a union too: WordPress
120
+ publishes by `status: "publish"`, so `{ key: "publish", field: "status", values: ["publish", "future"] }` gives
121
+ `posts.publish` and `pages.publish`. The key applies when the call sends one of those values, in the body or the
122
+ query; where the field's default is one of them (a WordPress template), leaving it out publishes too, and the key
123
+ always applies. A read that filters by the value gets no key, nor a field of that name without such an enum (a
124
+ comment's `status`); a rule no write matches stops generation.
117
125
 
118
126
  Which flags delete is the CLI's call: read the service's documentation, and count an undocumented flag as a delete.
119
127
  A flag counts on every method, a GET included: Yandex Disk's upload link is a GET whose `overwrite` replaces a file.
@@ -186,13 +194,17 @@ the coverage page after a spec sync.
186
194
 
187
195
  ### Limits
188
196
 
189
- - **Nothing checks the permission keys yet.** cli-core does not read an operation's `permissions`, `servers` or
190
- `securitySchemes` today. Until it does, a CLI adds the keys to its own `commandPermissions`, as notion-cli's
191
- `src/config.ts` does.
197
+ - **cli-core checks the permission keys; the CLI still shows them.** From cli-core 0.684.0, `serviceApiCommand`
198
+ reads each operation's `permissions`, `servers` and `securitySchemes`: it sends the call to the operation's server
199
+ with the sign-in its scheme names, and checks `api.<operation>` and each manifest key that applies to the call
200
+ (`files.delete` when `permanently` is true) before it sends. That guard runs whatever the CLI declares. `--dry-run`
201
+ and permission discovery show those keys only when the CLI merges `serviceApiPermissions(...)` into its own
202
+ `commandPermissions`, field by field (`extra`, `alsoChecks`, `defaults`), as ydisk's `src/config.ts` does:
203
+ `alsoChecks: (path) => [...api.alsoChecks(path), ...own(path)]`.
192
204
  - A merge joins every source's servers at the top, for every operation; sources on different hosts need a
193
205
  `servers` entry per path, which the merge does not write.
194
206
  - Pagination is found only from the names above; a service with its own names needs an override per operation.
195
- cli-core reads every page by the manifest once its executor does.
207
+ `serviceApiCommand` gives a read that pages `--all`, which reads every page.
196
208
  - Pagination is not found in an answer that is a union.
197
209
  - The fake checks shapes, not behaviour: it does not page, filter or keep state. A scenario that needs that writes
198
210
  it in `answers`. It checks neither header parameters nor RPC operations. A sample follows enums and limits but not