@wirecat/cli-base 1.0.0 → 1.2.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 CHANGED
@@ -8,6 +8,98 @@ 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
+ ## 1.2.0 — 28.11.2026
12
+
13
+ ### Added
14
+
15
+ - **`@wirecat/cli-base/dev` exports the parts of `cli-dev bundle` that another package's own build reuses.**
16
+ `commonJsNames`, `ownPlaces` (now taking one options object, which works with no anchored packages),
17
+ `DEFAULT_EXTERNAL`, `DEFAULT_HARMLESS` and `bundle`. cli-core's pre-bundle script imports them instead of
18
+ copying them. The entry is not in `wirecat.stable`: it may change in a minor release.
19
+ - **`cli-dev version` checks a CLI's override of `@wirecat/cli-core` (WC-TOOL-21).** cli-core's `X.Y.Z` now ships no
20
+ type files, and its `X.Y.Z-dev` is the same code with them. A CLI pins `X.Y.Z` in `package.json` and overrides it to
21
+ `X.Y.Z-dev` under `overrides:` in `pnpm-workspace.yaml`, which its users never read. `cli-dev version` fails when the
22
+ override names another version, or is missing while the installed cli-core has no types, and prints the line to
23
+ write. It only notes a missing override while the CLI pins a cli-core released before the `-dev` releases.
24
+ `node-ci.yml` runs the same check (`cli-dev version --cli-core-only`) right after install, so the message comes before
25
+ typecheck's TS7016. `cli-dev adopt` now moves the override with the pin
26
+ ([Toolchain](docs/standards/toolchain.md#wc-tool-21--pin-cli-core-xyz-and-override-it-to-xyz-dev-at-the-root)).
27
+ - **A CLI can name its fixed MCP port in its manifest.** `ManifestIdentity.mcpPort` writes `desktop.mcpServer.port` in
28
+ `contracts/wirecat.json`, so WireCat Desktop reads the port of a WireCat tool's MCP server from the tool itself
29
+ instead of its own catalog. Without `mcpPort` the key is absent and the manifest of every other CLI stays the same,
30
+ byte for byte. A CLI that sets `mcpPort` without `mcp server start`, `stop`, `status` and `mcp revoke` is refused.
31
+ Only WireCat's own tools set it, each with a port no other tool has
32
+ ([reference](docs/REFERENCE.md)).
33
+ - **A CLI can name the sync Desktop runs when it has several `<noun> sync` commands.** `ManifestIdentity.syncCommand`
34
+ takes the command and its flags, `["messages", "sync", "--all"]`, and the manifest's `desktop.sync` then runs it and
35
+ finds its last run. Before, such a CLI stated no sync, so Desktop kept its own words for the messengers. Words that
36
+ name no command are refused ([reference](docs/REFERENCE.md)).
37
+ - **A CLI can name Desktop's timer for its sync.** `ManifestIdentity.syncSchedule` writes `desktop.sync.schedule`
38
+ with the interval a new timer starts with, the intervals Desktop offers and the command it runs. It needs cli-core's
39
+ `schedule command`, `list`, `remove` and `run`. Without it the key is absent and the manifest stays the same, byte
40
+ for byte.
41
+ - **A WireCat tool's sign-in methods can say where Desktop passes what the person typed.** `signIn.methods` takes
42
+ `address`, `clientFile`, `portal` and `appId` (flags the command must take), `password` (the variable the CLI reads),
43
+ `clientId` (the setting that names the person's own OAuth app) and `oauth` (the words for a browser sign-in), as
44
+ Desktop's own catalog has them. Only `@wirecat` packages may set them, since Desktop refuses them from any other
45
+ tool.
46
+
47
+ ### Fixed
48
+
49
+ - **`cli-dev bundle` drops the `.d.ts` and `.map` files tsc wrote to `dist/`, in a CLI with no `exports`.** Nothing
50
+ imports such a CLI, and no map is read for the bundle a user runs: esbuild writes no maps, and the tsc maps point at
51
+ `src/`, which a CLI does not publish. tg-cli's package loses 204 files and 2.0 MB unpacked, an estimated 20 MB
52
+ across the CLIs. A package with `exports`, such as drive-cli and zoom-cli, keeps them for whoever imports it. Run
53
+ `pnpm typecheck` before `pnpm build`, as CI does: its `--emitDeclarationOnly` writes the `.d.ts` files again.
54
+
55
+ ## 1.1.0 — 27.11.2026
56
+
57
+ ### Added
58
+
59
+ - **`node-ci.yml` has a `secrets` input**: false skips its gitleaks scan of the whole history, for a repository whose
60
+ pull request security checks already scan it. It is on by default. Drop `validation / ci / secrets` from the
61
+ ruleset before turning it off, or the required check never reports. WC-CI-3 now lets such a repository keep lint,
62
+ types and secrets in one place ([CI standards](docs/standards/ci.md#wc-ci-3--run-the-fast-standards-job-on-every-pull-request-and-every-push-to-main)).
63
+ - **`cli-dev lint` reports a command at a path cli-core reserves when the CLI built it itself.** The paths are
64
+ `session start`, `session status`, `session end`, `session list`, `doctor`, `mcp`, `account remove`, `mirrors` and
65
+ `complete`. The new rule `reserved-shared-command` reads `commands --json` and names each such path that has no
66
+ `origin: "cli-core"`, with the cli-core helper to mount instead. Audits found own sessions, an own `mirrors`, an own
67
+ `doctor` and an own MCP server in several CLIs, and no check saw them, because `assertSharedContracts` looks only at
68
+ commands cli-core marked. For now it is a warning in `cli-dev lint` and in the family audit, so no CI run fails on
69
+ it. It becomes an error in a later release, planned for 2027-01-15, once cli-core marks `tokenSessionCommand`,
70
+ `oauthSessionCommand`, `fileMirrorsCommand` and `accountRemoveCommand`. Until then a CLI that mounts one of those is
71
+ reported too. A deliberate difference goes in `lint/overrides.json` with its reason, owner and `review_after`. An
72
+ entry for this rule in `lint/baseline/` fails the lint, because it has no reason or date. The rule is
73
+ [WC-CMD-34](docs/standards/commands.md#wc-cmd-34--mount-cli-cores-shared-command-at-a-reserved-path-never-one-of-your-own).
74
+
75
+ ### Changed — experimental
76
+
77
+ - **A GraphQL CLI's agent skill has one API page per entity, not one for queries and one for mutations.**
78
+ `adaptGraphql` now gives each operation two tags. The first is the entity its field name acts on
79
+ (`issueLabelCreate` → `issue-label`, `searchIssues` → `issue`), or `query` / `mutation` for a name with no entity in
80
+ it. The second is `query` or `mutation`, as before. `apiSkillFiles` files a page per first tag, so an agent that
81
+ wants to archive an issue reads `<cli> skill show api-issue` instead of Linear's 4,335-line `api-mutation` page.
82
+ Regenerating rewrites `references/api/`, and `api show` prints both tags. Commands, their names and permission keys
83
+ stay the same. `api list tag:mutation` still works, and `tag:issue` now works too. A CLI that groups its `api`
84
+ commands by tag (`names.groups: "tags"`) would mount them by entity; no GraphQL CLI does today.
85
+ - **drive is compared with the other CLIs on the shared roots only, as ydisk is.** It left the `all`, `mail-shared`
86
+ and `gcal-shared` parity groups. Its `notes` and `search` are cli-core's documents commands: a note about one
87
+ imported document is not memo's note of your own, and a search over imported documents is not the messengers'
88
+ archive search. In `all` they differed from memo's and the messengers' in 21 paths, more than the group's budget
89
+ of 10 differences. `commands`, `doctor`, `skill`, `mcp` and `upgrade` are still compared in `shared-roots`.
90
+
91
+ ### Fixed
92
+
93
+ - **A release makes its GitHub release again.** The release workflow pushed only the tag, so GitHub's releases page
94
+ stopped at the last release made by hand. The `tag` job now creates the release from the version's changelog
95
+ section, as the CLIs' release workflows do. 1.x was backfilled by hand.
96
+ - **WC-ACCT-12 has no exceptions.** memo was listed as one, but it signs in to no account: it reads the stores of the
97
+ other CLIs, and `memo models keys` keeps a model provider's key. The rule covers only CLIs that sign in, so memo was
98
+ never under it.
99
+ - **WC-ACCT-12 has no known gaps left but memo.** drive has `session status` since 0.76.0. tg, max and wa have
100
+ `session status` and `session list`, and `account list` is removed from them with no alias.
101
+ WC-ACCT-1 no longer says that tg, max and wa name their profile list `account list`.
102
+
11
103
  ## 1.0.0 — 25.11.2026
12
104
 
13
105
  ### Fixed
@@ -6,10 +6,13 @@
6
6
  * One field of `Query` or `Mutation` is one operation. Its arguments are the request body (the variables), each also a
7
7
  * flag; its answer is `data.<field>`, typed by the field's type. A query reads; a mutation writes, and one whose name
8
8
  * ends in `Delete` or `Archive` deletes. A Relay connection pages as a `cursor`: `after`, `pageInfo.endCursor`.
9
+ * Its first tag is the entity its name acts on (`issueLabelCreate` → `issue-label`), its second `query` or `mutation`:
10
+ * the agent skill files one page per first tag, and an agent looking for an issue's writes reads only the issue page.
9
11
  * SDL is not read: that needs graphql-js, and codegen adds no runtime dependency.
10
12
  */
11
13
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
12
14
  import { join } from "node:path";
15
+ import { kebab } from "./names.js";
13
16
  import { CodegenError } from "./pipeline.js";
14
17
  import { sha256, sortKeys } from "./snapshot.js";
15
18
  const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
@@ -161,6 +164,39 @@ export const adaptGraphql = (introspection, options) => {
161
164
  const node = connectionOf(name);
162
165
  return node ? `nodes { ${oneLevel(node)} } pageInfo { hasNextPage endCursor }` : oneLevel(name);
163
166
  };
167
+ const entities = new Map([...types.values()]
168
+ .filter((type) => fieldsOf(type.name)?.some((one) => one.name === "id"))
169
+ .map((type) => [type.name.toLowerCase(), type.name]));
170
+ const singulars = (word) => [
171
+ word,
172
+ ...(word.endsWith("ies") ? [`${word.slice(0, -3)}y`] : []),
173
+ ...(word.endsWith("es") ? [word.slice(0, -2)] : []),
174
+ ...(word.endsWith("s") ? [word.slice(0, -1)] : []),
175
+ ];
176
+ /**
177
+ * The earliest, then longest, run of the name's words that names an object with an id, its last word read singular
178
+ * too: `issueLabels` → `issue-label`, `searchIssues` → `issue`. A mutation's whole name is never its entity, as
179
+ * `projectUpdate` changes a project while the type `ProjectUpdate` is a status post. None: its kind, one page for
180
+ * the few leftovers rather than a page per verb.
181
+ */
182
+ const entityOf = (name, operation) => {
183
+ const words = name
184
+ .split(/_+|(?=[A-Z])/)
185
+ .filter(Boolean)
186
+ .map((word) => word.toLowerCase());
187
+ for (let start = 0; start < words.length; start++)
188
+ for (let end = words.length; end > start; end--) {
189
+ if (operation === "mutation" && start === 0 && end === words.length)
190
+ continue;
191
+ const head = words.slice(start, end - 1).join("");
192
+ const found = singulars(words[end - 1] ?? "")
193
+ .map((last) => entities.get(head + last))
194
+ .find(Boolean);
195
+ if (found)
196
+ return kebab(found);
197
+ }
198
+ return operation;
199
+ };
164
200
  // An answer that is only a reference is named after its type, which would drop a nullable field's null: such an
165
201
  // answer is wrapped, so it gets a name of its own that keeps it.
166
202
  const answerOf = (node) => node.type === "ref" && node.nullable
@@ -222,7 +258,7 @@ export const adaptGraphql = (introspection, options) => {
222
258
  binding,
223
259
  ...(summary ? { summary } : {}),
224
260
  ...described(field.description),
225
- tags: [operation],
261
+ tags: [entityOf(field.name, operation), operation],
226
262
  parameters: field.args.map((one) => ({
227
263
  name: one.name,
228
264
  in: "body",
@@ -1,6 +1,7 @@
1
1
  export type Run = (command: string, args: readonly string[]) => number;
2
2
  /**
3
- * Moves the CLI onto `version` of a shared package the same way every time: the pin in package.json, the lockfile,
3
+ * Moves the CLI onto `version` of a shared package the same way every time: the pin in package.json (and for cli-core
4
+ * the -dev override beside it, WC-TOOL-21), the lockfile,
4
5
  * the generated files and the quick checks. What the checks then report (pins, baselines) is the adoption's work.
5
6
  */
6
7
  export declare const adopt: (cwd: string, name: string, version: string, run: Run, log: (line: string) => void) => number;
package/dist/dev/adopt.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { readFileSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { CORE, DEV_SUFFIX, needsCoreOverride, writeCoreOverride } from "./core-override.js";
3
4
  const SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
4
5
  /**
5
- * Moves the CLI onto `version` of a shared package the same way every time: the pin in package.json, the lockfile,
6
+ * Moves the CLI onto `version` of a shared package the same way every time: the pin in package.json (and for cli-core
7
+ * the -dev override beside it, WC-TOOL-21), the lockfile,
6
8
  * the generated files and the quick checks. What the checks then report (pins, baselines) is the adoption's work.
7
9
  */
8
10
  export const adopt = (cwd, name, version, run, log) => {
@@ -24,6 +26,10 @@ export const adopt = (cwd, name, version, run, log) => {
24
26
  }
25
27
  writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
26
28
  log(`${name} ${version} in package.json`);
29
+ if (name === CORE && needsCoreOverride(cwd)) {
30
+ writeCoreOverride(cwd, version);
31
+ log(`${name} ${version}${DEV_SUFFIX} in pnpm-workspace.yaml`);
32
+ }
27
33
  const steps = [
28
34
  ["pnpm", ["install"]],
29
35
  ...["generate", "ci:quick"]
package/dist/dev/audit.js CHANGED
@@ -2,7 +2,7 @@ import { AUDIT_RULES, SHARED_DIFFERENCES, } from "../standards/audit.js";
2
2
  import { BASE_REASONS } from "../standards/errors.js";
3
3
  import { LINT_RULES, OVERRIDE_BUDGET, overdue, overridesDueSoon } from "../standards/lint.js";
4
4
  import { capabilityDifference } from "./capabilities.js";
5
- import { judge, kindOf, lintCommands, longName, registeredKinds, summaryOf, walk } from "./lint.js";
5
+ import { judge, kindOf, lintCommands, longName, OVERRIDE_ONLY_RULES, registeredKinds, summaryOf, WARNING_RULES, walk, } from "./lint.js";
6
6
  import { sharedContractProblems } from "./shared-contracts.js";
7
7
  const UNLISTED_RULES = new Set(["same-entity-schema", "same-error-reason"]);
8
8
  const STRICT_CONTRACT_RULES = new Set([
@@ -357,7 +357,8 @@ export const auditClis = (inputs, options, rules = AUDIT_RULES) => {
357
357
  fixed: verdict.stale.filter((entry) => entry.in === "baseline").length,
358
358
  new_targets: verdict.fresh.map((violation) => `${cli}: ${violation.target}`),
359
359
  };
360
- blocking.push(...mine.filter((finding) => row.new_targets.includes(finding.target)));
360
+ if (!WARNING_RULES.has(rule))
361
+ blocking.push(...mine.filter((finding) => row.new_targets.includes(finding.target)));
361
362
  }
362
363
  else {
363
364
  const open = mine.filter((finding) => !declared.has(`${rule} ${finding.target}`) &&
@@ -378,7 +379,7 @@ export const auditClis = (inputs, options, rules = AUDIT_RULES) => {
378
379
  (!here.has(target) || declared.has(`${rule} ${target}`))).length,
379
380
  new_targets: fresh.map((finding) => finding.target),
380
381
  };
381
- const blocks = lintIds.includes(rule) || options.blocks === "new";
382
+ const blocks = !WARNING_RULES.has(rule) && (lintIds.includes(rule) || options.blocks === "new");
382
383
  if (blocks)
383
384
  blocking.push(...fresh);
384
385
  }
@@ -395,6 +396,8 @@ export const auditClis = (inputs, options, rules = AUDIT_RULES) => {
395
396
  !inheritedAccepted.has(`${rule} ${finding.target}`))
396
397
  .filter((finding) => !(lintIds.includes(rule) && selfJudged.has(finding.clis[0] ?? "")))
397
398
  .map((finding) => finding.target);
399
+ if (OVERRIDE_ONLY_RULES.has(rule))
400
+ return [rule, []];
398
401
  return [rule, STRICT_CONTRACT_RULES.has(rule) ? kept : [...new Set([...kept, ...now])].sort(byText)];
399
402
  }));
400
403
  const unique = new Map(blocking.map((finding) => [`${finding.rule} ${finding.target}`, finding]));
@@ -1,3 +1,4 @@
1
+ import type { Plugin } from "esbuild";
1
2
  export interface BundleOptions {
2
3
  /** The CLI's root: `dist/` and `package.json` are under it. */
3
4
  root: string;
@@ -20,6 +21,27 @@ export declare const DEFAULT_EXTERNAL: string[];
20
21
  export declare const DEFAULT_ANCHORED: string[];
21
22
  export declare const DEFAULT_HARMLESS: string[];
22
23
  export declare const LOADER_MARK = "// cli-dev bundle loader\n";
24
+ export interface OwnPlacesOptions {
25
+ /** The modules under it keep their place: `import.meta.url` becomes their file before bundling. */
26
+ dist: string;
27
+ /** Where the bundle is written: the places are relative to it. */
28
+ out: string;
29
+ /** Packages whose modules keep their installed place too. */
30
+ anchored?: readonly string[];
31
+ /** Third-party files that may look themselves up (a path suffix each); `DEFAULT_HARMLESS` when not given. */
32
+ harmless?: readonly string[];
33
+ /** What stays outside the bundle; a run-time import of it resolves from the module's own place. */
34
+ isExternal?: (specifier: string) => boolean;
35
+ /** Collects each module that would look for a file or package in the wrong place. */
36
+ problems: string[];
37
+ }
38
+ /** The esbuild plugin that keeps each module's place (the header says why). */
39
+ export declare const ownPlaces: ({ dist, out, anchored, harmless, isExternal, problems, }: OwnPlacesOptions) => Plugin;
40
+ /**
41
+ * `await import("yaml")` gets CommonJS's named exports from Node, but only `default` from a bundled chunk. A dynamic
42
+ * import of CommonJS goes through a module that exports the names Node itself finds in it.
43
+ */
44
+ export declare const commonJsNames: Plugin;
23
45
  /**
24
46
  * Whether the loader runs a server: `serve`, `watch` or `mcp serve`, or `mcp` alone as before cli-core 0.463. Flags
25
47
  * are skipped, so `<cli> personal --read-only mcp serve` counts; four words leave room for one flag's value. It is
@@ -9,8 +9,10 @@
9
9
  * anchored packages (cli-core, cli-base), `import.meta.url` becomes the module's own place, and a package they load
10
10
  * at run time is resolved from there too: pnpm installs cli-core's dependencies beside cli-core, not beside the CLI.
11
11
  * - The build fails when a bundled module would still look in the wrong place.
12
+ * - A CLI with no `exports` drops tsc's `.d.ts` and `.map` files from `dist/`: nothing imports it, and no map is read
13
+ * for the bundle a user runs. A package with `exports` keeps them for whoever imports it.
12
14
  */
13
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
15
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
14
16
  import { isBuiltin } from "node:module";
15
17
  import { basename, dirname, join, relative, sep } from "node:path";
16
18
  import { pathToFileURL } from "node:url";
@@ -71,7 +73,8 @@ export const importFrom = async (parent, specifier) => import(resolveFrom(parent
71
73
  `;
72
74
  const BY_NAME = /(?<![\w$.])import\(\s*(?!["'`.])/g;
73
75
  const LITERAL = /(?<![\w$.])import\(\s*(["'])([^"'.][^"']*)\1\s*\)/g;
74
- const ownPlaces = (dist, out, anchored, harmless, isExternal, problems) => {
76
+ /** The esbuild plugin that keeps each module's place (the header says why). */
77
+ export const ownPlaces = ({ dist, out, anchored = [], harmless = DEFAULT_HARMLESS, isExternal = () => false, problems, }) => {
75
78
  const placeOf = (file) => {
76
79
  if (file.startsWith(dist + sep))
77
80
  return `new URL(${JSON.stringify(posix(relative(out, file)))}, import.meta.url).href`;
@@ -138,7 +141,7 @@ const isCommonJs = (file) => {
138
141
  * `await import("yaml")` gets CommonJS's named exports from Node, but only `default` from a bundled chunk. A dynamic
139
142
  * import of CommonJS goes through a module that exports the names Node itself finds in it.
140
143
  */
141
- const commonJsNames = {
144
+ export const commonJsNames = {
142
145
  name: "common-js-names",
143
146
  setup(context) {
144
147
  context.onResolve({ filter: /.*/ }, async (args) => {
@@ -232,7 +235,7 @@ export const bundle = async (options) => {
232
235
  return { problems: [`${options.bin} is not under dist/`], chunks: [] };
233
236
  if (readFileSync(bin, "utf8").includes(LOADER_MARK))
234
237
  return { problems: [`${options.bin} is already the loader — compile it again (tsc) first`], chunks: [] };
235
- const { version } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
238
+ const { version, exports } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
236
239
  rmSync(out, { recursive: true, force: true });
237
240
  const { metafile } = await build({
238
241
  absWorkingDir: root,
@@ -253,7 +256,14 @@ export const bundle = async (options) => {
253
256
  },
254
257
  plugins: [
255
258
  commonJsNames,
256
- ownPlaces(dist, out, [...DEFAULT_ANCHORED, ...(options.anchored ?? [])], [...DEFAULT_HARMLESS, ...(options.harmless ?? [])], isExternal, problems),
259
+ ownPlaces({
260
+ dist,
261
+ out,
262
+ anchored: [...DEFAULT_ANCHORED, ...(options.anchored ?? [])],
263
+ harmless: [...DEFAULT_HARMLESS, ...(options.harmless ?? [])],
264
+ isExternal,
265
+ problems,
266
+ }),
257
267
  ],
258
268
  metafile: true,
259
269
  logLevel: "silent",
@@ -285,5 +295,10 @@ export const bundle = async (options) => {
285
295
  if (missing.length > 0)
286
296
  return { problems: missing.map((chunk) => `the loader names ${chunk}, not built`), chunks };
287
297
  writeFileSync(bin, loaderSource(name, version, chunks));
298
+ if (exports === undefined) {
299
+ for (const file of readdirSync(dist, { recursive: true, encoding: "utf8" }))
300
+ if (/\.js\.map$|\.d\.ts(\.map)?$/.test(file))
301
+ rmSync(join(dist, file));
302
+ }
288
303
  return { problems: [], chunks };
289
304
  };
@@ -0,0 +1,15 @@
1
+ export declare const CORE = "@wirecat/cli-core";
2
+ export declare const DEV_SUFFIX = "-dev";
3
+ export interface OverrideCheck {
4
+ problems: string[];
5
+ notes: string[];
6
+ }
7
+ /**
8
+ * Problems are a wrong override, or none while the installed cli-core is the user package (no `dist/index.d.ts`):
9
+ * that one is published only beside its -dev twin, so the override can be added. An older cli-core, released before
10
+ * the twins, still ships its types and has no -dev to point at; then the missing override is only a note.
11
+ */
12
+ export declare const coreOverrideCheck: (root: string) => OverrideCheck;
13
+ /** Points the override at `version`-dev, as `adopt` does with the pin; keeps the file's other lines and comments. */
14
+ export declare const writeCoreOverride: (root: string, version: string) => void;
15
+ export declare const needsCoreOverride: (root: string) => boolean;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * WC-TOOL-21: a CLI pins `@wirecat/cli-core` X.Y.Z in package.json, which is what its users install, and overrides it
3
+ * to X.Y.Z-dev in pnpm-workspace.yaml, which only the CLI's own checkout reads. X.Y.Z ships no type files; X.Y.Z-dev
4
+ * is the same JavaScript with the types, their maps and src/.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { parseDocument } from "yaml";
9
+ export const CORE = "@wirecat/cli-core";
10
+ export const DEV_SUFFIX = "-dev";
11
+ const WORKSPACE = "pnpm-workspace.yaml";
12
+ const EXACT = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
13
+ const readManifest = (root) => JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
14
+ /** The CLI's pin when the rule applies to it: cli-core itself, and a package with no `bin`, are not CLIs. */
15
+ const pinOf = (pkg) => pkg.name === CORE || pkg.bin === undefined ? undefined : pkg.dependencies?.[CORE];
16
+ const overrideOf = (root) => {
17
+ const path = join(root, WORKSPACE);
18
+ if (!existsSync(path))
19
+ return undefined;
20
+ const value = parseDocument(readFileSync(path, "utf8")).getIn(["overrides", CORE]);
21
+ return value === undefined || value === null ? undefined : String(value);
22
+ };
23
+ const line = (pin) => ` "${CORE}": ${pin}${DEV_SUFFIX}`;
24
+ /**
25
+ * Problems are a wrong override, or none while the installed cli-core is the user package (no `dist/index.d.ts`):
26
+ * that one is published only beside its -dev twin, so the override can be added. An older cli-core, released before
27
+ * the twins, still ships its types and has no -dev to point at; then the missing override is only a note.
28
+ */
29
+ export const coreOverrideCheck = (root) => {
30
+ const pin = pinOf(readManifest(root));
31
+ if (pin === undefined)
32
+ return { problems: [], notes: [] };
33
+ if (!EXACT.test(pin))
34
+ return { problems: [`package.json gives ${CORE} as "${pin}": pin the exact version, such as 2.1.0`], notes: [] };
35
+ const override = overrideOf(root);
36
+ const wanted = `${pin}${DEV_SUFFIX}`;
37
+ if (override === wanted)
38
+ return { problems: [], notes: [] };
39
+ if (override !== undefined)
40
+ return {
41
+ problems: [
42
+ `${WORKSPACE} overrides ${CORE} to ${override}, but package.json pins ${pin}, so this repository builds and ` +
43
+ `tests against a cli-core its users never get. Change that line under "overrides:" to\n${line(pin)}\n` +
44
+ "and run `pnpm install` (WC-TOOL-21).",
45
+ ],
46
+ notes: [],
47
+ };
48
+ const installed = join(root, "node_modules", CORE);
49
+ if (existsSync(join(installed, "package.json")) && !existsSync(join(installed, "dist/index.d.ts")))
50
+ return {
51
+ problems: [
52
+ `${WORKSPACE} does not override ${CORE}. ${pin} is the package users install and has no type files, so ` +
53
+ `\`pnpm typecheck\` fails with TS7016 ("Could not find a declaration file for module '${CORE}'"). ` +
54
+ `Add this line under "overrides:" in ${WORKSPACE}\n${line(pin)}\nand run \`pnpm install\` (WC-TOOL-21).`,
55
+ ],
56
+ notes: [],
57
+ };
58
+ return {
59
+ problems: [],
60
+ notes: [`${CORE} ${pin} predates the -dev releases; from the next cli-core, \`cli-dev adopt\` adds the override`],
61
+ };
62
+ };
63
+ /** Points the override at `version`-dev, as `adopt` does with the pin; keeps the file's other lines and comments. */
64
+ export const writeCoreOverride = (root, version) => {
65
+ const path = join(root, WORKSPACE);
66
+ const doc = parseDocument(existsSync(path) ? readFileSync(path, "utf8") : "");
67
+ doc.setIn(["overrides", CORE], `${version}${DEV_SUFFIX}`);
68
+ writeFileSync(path, String(doc));
69
+ };
70
+ export const needsCoreOverride = (root) => pinOf(readManifest(root)) !== undefined;
@@ -0,0 +1,2 @@
1
+ /** The parts of `cli-dev bundle` another package's own build reuses, as cli-core's bundle script does. */
2
+ export { type BundleOptions, type BundleResult, bundle, commonJsNames, DEFAULT_EXTERNAL, DEFAULT_HARMLESS, type OwnPlacesOptions, ownPlaces, } from "./bundle.js";
@@ -0,0 +1,2 @@
1
+ /** The parts of `cli-dev bundle` another package's own build reuses, as cli-core's bundle script does. */
2
+ export { bundle, commonJsNames, DEFAULT_EXTERNAL, DEFAULT_HARMLESS, ownPlaces, } from "./bundle.js";
@@ -18,6 +18,22 @@ export declare const kindOf: (option: OptionInfo) => string;
18
18
  export { summaryOf };
19
19
  /** The kinds of value the vocabulary lets each flag take: its own value, or `switch`, then its `otherValues`. */
20
20
  export declare const registeredKinds: (vocabulary: Vocabulary) => Map<string, string[]>;
21
+ /**
22
+ * WC-CMD-34: root paths only cli-core's shared commands may hold. A group is judged by its own node, so a subcommand a
23
+ * CLI adds to a shared group stays allowed; `session` is judged by its four leaves, which a CLI may hold in its own group.
24
+ */
25
+ export declare const RESERVED_COMMANDS: readonly {
26
+ path: string;
27
+ leaves?: readonly string[];
28
+ helpers: string;
29
+ }[];
30
+ /**
31
+ * Rules in their warning phase: `cli-dev lint` and the audit print them and never fail on them. The rule's page names
32
+ * the release that ends the phase.
33
+ */
34
+ export declare const WARNING_RULES: ReadonlySet<string>;
35
+ /** Rules whose exception must carry a reason and a date: a baseline entry has neither, so it is refused. */
36
+ export declare const OVERRIDE_ONLY_RULES: ReadonlySet<string>;
21
37
  export interface LintContext {
22
38
  /** The commands document as the CLI printed it; parsing drops keys it does not know, so casing is checked here. */
23
39
  raw?: unknown;
package/dist/dev/lint.js CHANGED
@@ -33,6 +33,29 @@ export const registeredKinds = (vocabulary) => new Map(vocabulary.flags.map((fla
33
33
  [flag.value?.slice(1, -1).toLowerCase() ?? "switch", ...(flag.otherValues ?? [])],
34
34
  ]));
35
35
  const label = (command) => command.path.join(" ");
36
+ /**
37
+ * WC-CMD-34: root paths only cli-core's shared commands may hold. A group is judged by its own node, so a subcommand a
38
+ * CLI adds to a shared group stays allowed; `session` is judged by its four leaves, which a CLI may hold in its own group.
39
+ */
40
+ export const RESERVED_COMMANDS = [
41
+ {
42
+ path: "session",
43
+ leaves: ["start", "status", "end", "list"],
44
+ helpers: "`tokenSessionCommand`, `oauthSessionCommand` or `messengerSessionCommands`",
45
+ },
46
+ { path: "doctor", helpers: "`appDoctorCommand` or `doctorCommand`" },
47
+ { path: "mcp", helpers: "`appMcpCommand` or `mcpCommand`" },
48
+ { path: "account remove", helpers: "`accountRemoveCommand` (or the group from `accountCommand`)" },
49
+ { path: "mirrors", helpers: "`fileMirrorsCommand` or `addDocumentMirrorCommands`" },
50
+ { path: "complete", helpers: "`appCompleteCommand` or `completeCommand`" },
51
+ ];
52
+ /**
53
+ * Rules in their warning phase: `cli-dev lint` and the audit print them and never fail on them. The rule's page names
54
+ * the release that ends the phase.
55
+ */
56
+ export const WARNING_RULES = new Set(["reserved-shared-command"]);
57
+ /** Rules whose exception must carry a reason and a date: a baseline entry has neither, so it is refused. */
58
+ export const OVERRIDE_ONLY_RULES = new Set(["reserved-shared-command"]);
36
59
  /** The run log's reader and its switches; what `runsCommand` and cli-core's shared program add. */
37
60
  export const RUN_LOG_COMMANDS = ["runs list", "runs show"];
38
61
  export const RUN_LOG_FLAGS = ["--record", "--no-record"];
@@ -429,6 +452,20 @@ const CHECKS = {
429
452
  : []),
430
453
  ];
431
454
  },
455
+ "reserved-shared-command": (document) => {
456
+ const at = new Map(walk(document.commands).map((command) => [label(command), command]));
457
+ return RESERVED_COMMANDS.flatMap(({ path, leaves, helpers }) => {
458
+ const own = (leaves ? leaves.map((leaf) => `${path} ${leaf}`) : [path]).filter((one) => at.has(one) && at.get(one)?.origin !== "cli-core");
459
+ return own.length === 0
460
+ ? []
461
+ : [
462
+ {
463
+ target: path,
464
+ message: `${own.join(", ")} built by the CLI. Mount cli-core's ${helpers}, or add an override with the reason`,
465
+ },
466
+ ];
467
+ });
468
+ },
432
469
  "raw-network": (_document, _vocabulary, context) => (context.network ? rawNetwork(context.network) : []),
433
470
  "undeclared-host": (_document, _vocabulary, context) => (context.network ? undeclaredHosts(context.network) : []),
434
471
  "result-shape": (_document, _vocabulary, context) => (context.declarations ? resultShape(context.declarations) : []),
@@ -478,10 +515,12 @@ export const baselineOf = (violations, overrides, rules = LINT_RULES) => {
478
515
  const overridden = new Set(overrides.map((entry) => `${entry.rule} ${entry.target}`));
479
516
  return Object.fromEntries(rules.map((rule) => [
480
517
  rule.id,
481
- violations
482
- .filter((violation) => violation.rule === rule.id && !overridden.has(`${violation.rule} ${violation.target}`))
483
- .map((violation) => violation.target)
484
- .sort(),
518
+ OVERRIDE_ONLY_RULES.has(rule.id)
519
+ ? []
520
+ : violations
521
+ .filter((violation) => violation.rule === rule.id && !overridden.has(`${violation.rule} ${violation.target}`))
522
+ .map((violation) => violation.target)
523
+ .sort(),
485
524
  ]));
486
525
  };
487
526
  /** The rules about words: which list an exception goes in depends on who owns the word (WC-TOOL-16). */
@@ -491,14 +530,18 @@ const WORD_RULES = new Set(["unknown-verb", "unknown-resource", "option-role", "
491
530
  * mounts belongs in the baseline until cli-core or the vocabulary catches up. Silent until cli-core marks its commands.
492
531
  */
493
532
  export const misfiled = (document, baseline, overrides) => {
533
+ const reasonless = [...OVERRIDE_ONLY_RULES]
534
+ .filter((rule) => (baseline[rule] ?? []).length > 0)
535
+ .map((rule) => `an exception to ${rule} is in the baseline: move it to the overrides, with its reason and date`);
494
536
  const commands = walk(document.commands).sort((a, b) => b.path.length - a.path.length);
495
537
  if (!commands.some((command) => command.origin === "cli-core"))
496
- return [];
538
+ return reasonless;
497
539
  const ownerOf = (target) => commands.find((command) => {
498
540
  const path = label(command);
499
541
  return target === path || target.startsWith(`${path} `) || target.startsWith(`${path}:`);
500
542
  })?.origin;
501
543
  return [
544
+ ...reasonless,
502
545
  ...Object.entries(baseline)
503
546
  .filter(([rule]) => WORD_RULES.has(rule))
504
547
  .flatMap(([rule, targets]) => targets
package/dist/dev/main.js CHANGED
@@ -13,7 +13,7 @@ import * as v from "valibot";
13
13
  import { parseCommandsDocument } from "../commands/document.js";
14
14
  import { describeProgram } from "../commands/registry.js";
15
15
  import { taggedSection } from "../release/fold.js";
16
- import { CHANGELOG_HEADINGS, changelogProblems, collectFragments, docsProblems, fragmentProblems, JOURNAL_IDS, markdownFiles, packageVersion, readFragments, structureProblems, versionScript, } from "../release/index.js";
16
+ import { CHANGELOG_HEADINGS, changelogProblems, collectFragments, docsProblems, fragmentProblems, JOURNAL_IDS, markdownFiles, packageVersion, readFragments, structureProblems, } from "../release/index.js";
17
17
  import { AUDIT_BLOCKS, defineParityGroups, PARITY_GROUPS, REQUIRED_ROOTS } from "../standards/audit.js";
18
18
  import { defineReasons } from "../standards/errors.js";
19
19
  import { baselineProblems, baselineSchema, LINT_RULES, OVERRIDE_BUDGET, OVERRIDE_RULE_REVIEW, overdue, overrideSchema, overridesDueSoon, overridesProblems, rulesForReview, } from "../standards/lint.js";
@@ -27,13 +27,14 @@ import { readCapabilities } from "./capabilities.js";
27
27
  import { CONFORMANCE_USAGE, conformanceCommand } from "./conformance.js";
28
28
  import { familyPackages, installFamily } from "./family.js";
29
29
  import { changelogChange, landChange, landFold, newestTag, processShell, restoreChange } from "./land.js";
30
- import { baselineOf, judge, lintCommands, misfiled, RUN_LOG_COMMANDS, walk } from "./lint.js";
30
+ import { baselineOf, judge, lintCommands, misfiled, RUN_LOG_COMMANDS, WARNING_RULES, walk, } from "./lint.js";
31
31
  import { readSources } from "./network.js";
32
32
  import { levelCommand, nextVersion } from "./next-version.js";
33
33
  import { READY_USAGE, ready } from "./ready.js";
34
34
  import { readDeclarations } from "./result-shape.js";
35
35
  import { slowTests } from "./slow-tests.js";
36
36
  import { matrixPage, matrixRows, parseArgvLog } from "./test-matrix.js";
37
+ import { versionCommand } from "./version-command.js";
37
38
  import { binNameWarnings, describeWarnings, hostsWarnings, WCAT_RULES } from "./wcat-lint.js";
38
39
  const USAGE = `usage: cli-dev <command> [options]
39
40
 
@@ -42,7 +43,11 @@ const USAGE = `usage: cli-dev <command> [options]
42
43
  exits 1 when the report is missing
43
44
  next-version <wanted> <latest> <versions-json>
44
45
  the version bin/release publishes, given npm's answers
45
- version [--sync] [--file <path>] package.json's version against src/version.ts
46
+ version [--sync] [--file <path>] [--cli-core-only]
47
+ package.json's version against src/version.ts, and a CLI's override of
48
+ @wirecat/cli-core in pnpm-workspace.yaml against its pin: the pinned
49
+ version plus -dev, the one with the type files (WC-TOOL-21);
50
+ --cli-core-only checks only the override
46
51
  changelog fold [--version <x.y.z>] [--unreleased <title>] [--file <path>] [--land]
47
52
  folds the unreleased section (Unreleased) into the dated
48
53
  section below it when that is --version (package.json's), and
@@ -56,7 +61,8 @@ const USAGE = `usage: cli-dev <command> [options]
56
61
  to the unreleased section. Prints a line when it changed the
57
62
  file. --land lands it on main through a pull request
58
63
  adopt <x.y.z> [--package <name>] moves the CLI onto that version of a shared package
59
- (@wirecat/cli-core): the pin in package.json, pnpm install,
64
+ (@wirecat/cli-core): the pin in package.json (for cli-core also
65
+ its x.y.z-dev override in pnpm-workspace.yaml), pnpm install,
60
66
  then pnpm generate and ci:quick when the CLI has them
61
67
  changelog fragments [--collect <x.y.z>] [--ids <A,B>] [--file <path>]
62
68
  checks the changes/<branch>.md fragments (### headings of the
@@ -108,7 +114,9 @@ const USAGE = `usage: cli-dev <command> [options]
108
114
  whose modules keep their installed place, as cli-core's do;
109
115
  --harmless names a third-party file whose import.meta or
110
116
  __dirname was read and found harmless. Fails when a bundled
111
- module would look for a file or package in the wrong place
117
+ module would look for a file or package in the wrong place.
118
+ A CLI with no exports in package.json loses the .d.ts and .map
119
+ files tsc wrote to dist/, which nothing reads
112
120
  ${CONFORMANCE_USAGE}
113
121
  ${READY_USAGE}
114
122
  ${API_REPORT_USAGE}`;
@@ -539,7 +547,7 @@ const lintRun = (args, io) => {
539
547
  }
540
548
  const verdict = judge(violations, baseline, ruleOverrides, budget);
541
549
  // A low rule is advice: it is printed and never fails, so polishing help text never holds a merge.
542
- const advice = (rule) => severity.get(rule) === "low";
550
+ const advice = (rule) => severity.get(rule) === "low" || WARNING_RULES.has(rule);
543
551
  const advised = [];
544
552
  for (const id of verdict.unknownRules)
545
553
  problems.push(`no lint rule "${id}" (named in ${values.baseline} or ${values.overrides})`);
@@ -931,18 +939,8 @@ export const main = async (argv, io) => {
931
939
  io.out(found.version);
932
940
  return 0;
933
941
  }
934
- case "version": {
935
- const { values } = parseArgs({
936
- args,
937
- options: { sync: { type: "boolean", default: false }, file: { type: "string", default: "src/version.ts" } },
938
- });
939
- const { code, message } = versionScript(io.cwd, values.sync ? ["--sync"] : [], values.file);
940
- if (code === 0)
941
- io.out(message);
942
- else
943
- io.err(message);
944
- return code;
945
- }
942
+ case "version":
943
+ return versionCommand(args, io);
946
944
  case "changelog":
947
945
  return changelog(args, io);
948
946
  case "api-report":
@@ -0,0 +1,8 @@
1
+ interface Io {
2
+ cwd: string;
3
+ out: (text: string) => void;
4
+ err: (text: string) => void;
5
+ }
6
+ /** `cli-dev version`: the version in package.json against src/version.ts, then the cli-core override (WC-TOOL-21). */
7
+ export declare const versionCommand: (args: string[], io: Io) => number;
8
+ export {};