@wirecat/cli-base 0.85.1 → 0.86.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,36 @@ 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.86.0 — 08.11.2026
12
+
13
+ ### Added
14
+
15
+ - **The vocabulary has the noun `groups` and the option `--position`.** `groups` is memo's account groups
16
+ (`memo groups list|add|remove|move`, WC-ACCT-13); `--position <title>` is a person's job title on a relationship,
17
+ stored as `position` and never the role. memo can drop the lint baseline entries it kept for them.
18
+ - **The vocabulary has the resource `roles` and the option `--label`.** `roles` is the parts a person plays in a
19
+ relationship (`memo relationships roles list|add|remove`); `--label <label>` is a human-readable label for an id,
20
+ such as a custom relationship role's name. memo can drop its `unknown-resource` and `option-role` baseline entries
21
+ for them.
22
+
23
+ ### Fixed
24
+
25
+ - **`hostFetch` lets go of a finished request's memory at once.** Its timeout used `AbortSignal.timeout`, whose timer,
26
+ and everything the request's async context held, stayed alive until the deadline (30 s by default) after the answer
27
+ was read. tg-cli's Bot API tests, routed through it, peaked at 3.0 to 3.4 GB instead of 0.8 to 1.1 GB, which is
28
+ how they once ran out of heap on macOS. The timer is now cleared when the request fails or its body has been read
29
+ to the end. The timeout still bounds the whole exchange, body included. The response it hands back is a copy with
30
+ the same status, headers, `url` and `redirected`.
31
+ - **`raw-network` no longer reports code that reaches no host.** It reported the word "fetch (" in a doc comment, a
32
+ `node:net` import of `isIP` alone and a `node:http` import of `createServer` alone (a loopback sign-in server).
33
+ cli-core had all three. Comment lines are skipped now, as `undeclared-host` already skipped them, and a named import
34
+ of only `createServer`, `STATUS_CODES` or `METHODS` (`http`, `https`) or `isIP`, `isIPv4` or `isIPv6` (`net`)
35
+ passes. An import that also names `request` or `createConnection` is still reported. It also read `this.#fetch(`, a
36
+ call of a class's own fetch, as the global one (tg-cli's Bot API transport). A CLI that baselined such a finding
37
+ removes the entry, which `cli-dev lint` now reports as stale.
38
+ - **`undeclared-host` no longer reports a name with no dot**, such as `host` in `http://host:port`, a placeholder in
39
+ tg-cli's proxy help, or `localhost`. Neither is an internet host a manifest could list.
40
+
11
41
  ## 0.85.1 — 08.11.2026
12
42
 
13
43
  ### Fixed
@@ -29,17 +29,39 @@ export const readSources = (cwd, dir = "src") => {
29
29
  });
30
30
  return walk(root).sort((a, b) => (a.path < b.path ? -1 : 1));
31
31
  };
32
- const MODULE_REF = /\b(?:import\s+(type\s+)?(?:[\w$*{}\s,]+?\s+from\s*)?|export\s+(type\s+)?[\w$*{}\s,]*?\s*from\s*|import\s*\(\s*|require\s*\(\s*)["']([^"']+)["']/g;
32
+ const COMMENT_LINE = /^\s*(?:\/\/|\/\*|\*)/;
33
+ const MODULE_REF = /\b(?:import\s+(type\s+)?(?:([\w$*{}\s,]+?)\s+from\s*)?|export\s+(type\s+)?[\w$*{}\s,]*?\s*from\s*|import\s*\(\s*|require\s*\(\s*)["']([^"']+)["']/g;
34
+ // A server only listens and `isIP` only parses: neither reaches a host, so hostFetch has nothing to replace.
35
+ const OPENS_NOTHING = {
36
+ http: new Set(["createServer", "STATUS_CODES", "METHODS"]),
37
+ https: new Set(["createServer"]),
38
+ net: new Set(["isIP", "isIPv4", "isIPv6"]),
39
+ };
40
+ const opensNothing = (module, clause) => {
41
+ const allowed = OPENS_NOTHING[module.replace(/^node:/, "")];
42
+ const named = clause?.trim().match(/^\{([^}]*)\}$/)?.[1];
43
+ if (!allowed || named === undefined)
44
+ return false;
45
+ return named
46
+ .split(",")
47
+ .map((binding) => binding.trim())
48
+ .filter((binding) => binding !== "" && !binding.startsWith("type "))
49
+ .every((binding) => allowed.has(binding.split(/\s+as\s+/)[0]));
50
+ };
33
51
  // A file that binds its own `fetch` (an injected FetchLike, `const fetch = hostFetch(…)`) calls that one.
34
52
  const BINDS_FETCH = /\b(?:const|let|var|function)\s+fetch\b|[{,(]\s*fetch\s*[,}):=]/;
35
- const GLOBAL_FETCH_CALL = /(?<![\w$.])fetch\s*\(/;
53
+ const GLOBAL_FETCH_CALL = /(?<![\w$.#])fetch\s*\(/;
36
54
  const GLOBAL_FETCH = /(?<!\btypeof\s+)\b(?:globalThis|window|self)\s*\.\s*fetch\b/;
37
55
  export const rawNetwork = ({ sources }) => sources.flatMap(({ path, text }) => {
38
- const modules = [...text.matchAll(MODULE_REF)]
39
- .filter(([, type, exportType, module]) => !type && !exportType && module && NETWORK_MODULES.test(module))
40
- .map(([, , , module]) => module);
56
+ const code = text
57
+ .split("\n")
58
+ .filter((line) => !COMMENT_LINE.test(line))
59
+ .join("\n");
60
+ const modules = [...code.matchAll(MODULE_REF)]
61
+ .filter(([, type, clause, exportType, module]) => !type && !exportType && module && NETWORK_MODULES.test(module) && !opensNothing(module, clause))
62
+ .map(([, , , , module]) => module);
41
63
  const fetches = [
42
- ...(GLOBAL_FETCH.test(text) || (GLOBAL_FETCH_CALL.test(text) && !BINDS_FETCH.test(text)) ? ["fetch"] : []),
64
+ ...(GLOBAL_FETCH.test(code) || (GLOBAL_FETCH_CALL.test(code) && !BINDS_FETCH.test(code)) ? ["fetch"] : []),
43
65
  ];
44
66
  return [...new Set([...modules, ...fetches])].map((what) => ({
45
67
  target: `${path} ${what}`,
@@ -49,7 +71,6 @@ export const rawNetwork = ({ sources }) => sources.flatMap(({ path, text }) => {
49
71
  }));
50
72
  });
51
73
  const URL_HOST = /\bhttps?:\/\/([a-z0-9.-]+)/gi;
52
- const COMMENT_LINE = /^\s*(?:\/\/|\/\*|\*)/;
53
74
  /** Names, not addresses: placeholders and schema or namespace identifiers nobody fetches. */
54
75
  const NOT_CONTACTED = /(?:^|\.)(?:example(?:\.com|\.org|\.net)?|test|invalid)$|^(?:json-schema\.org|www\.w3\.org)$/;
55
76
  /** One finding per host, so a host named in many files takes one override. */
@@ -62,7 +83,8 @@ export const undeclaredHosts = ({ sources, hosts, docsHost, }) => {
62
83
  if (!COMMENT_LINE.test(line))
63
84
  for (const [, found] of line.matchAll(URL_HOST)) {
64
85
  const host = found.toLowerCase().replace(/\.$/, "");
65
- if (host === docsHost || NOT_CONTACTED.test(host) || hostCovered(host, hosts))
86
+ // A name with no dot (`socks5://host:port`) is a placeholder or this machine, not an internet host.
87
+ if (!host.includes(".") || host === docsHost || NOT_CONTACTED.test(host) || hostCovered(host, hosts))
66
88
  continue;
67
89
  const seen = files.get(host) ?? [];
68
90
  if (!seen.includes(path))
@@ -4,6 +4,29 @@ export const HOST_FETCH_TIMEOUT_MS = 30_000;
4
4
  const REDIRECTS = 5;
5
5
  const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
6
6
  const CREDENTIAL_HEADERS = ["authorization", "cookie", "proxy-authorization"];
7
+ const NO_BODY = new Set([204, 205, 304]);
8
+ // Not AbortSignal.timeout: its timer, and the async context it holds, lives to the deadline after the exchange ended.
9
+ // tg-cli's Bot API tests peaked at 3 GB with it and 0.8 GB with this timer, cleared once the body is read.
10
+ const deadline = (ms) => {
11
+ const controller = new AbortController();
12
+ const timer = setTimeout(() => controller.abort(new DOMException(`no answer within ${ms} ms`, "TimeoutError")), ms);
13
+ timer.unref?.();
14
+ return { signal: controller.signal, clear: () => clearTimeout(timer) };
15
+ };
16
+ /** The response with its body read through a stream that clears the timer at its end. */
17
+ const released = (response, clear) => {
18
+ if (!response.body || NO_BODY.has(response.status) || response.status < 200 || response.status > 599) {
19
+ clear();
20
+ return response;
21
+ }
22
+ const { status, statusText, headers, url, redirected } = response;
23
+ const wrapped = new Response(response.body.pipeThrough(new TransformStream({ flush: clear })), {
24
+ status,
25
+ statusText,
26
+ headers,
27
+ });
28
+ return Object.defineProperties(wrapped, { url: { value: url }, redirected: { value: redirected } });
29
+ };
7
30
  const undeclared = (url) => new CliError("configuration_error", `${url.hostname} is not a host this CLI declares: add "${url.hostname}" to \`hosts\` in its WCAT identity and run cli-dev manifest`, { reason: "network.host-undeclared", sent: false });
8
31
  const checked = (url, hosts) => {
9
32
  if (url.protocol !== "https:" && url.protocol !== "http:")
@@ -24,8 +47,8 @@ export const hostFetch = (options) => {
24
47
  const request = input instanceof Request ? input : undefined;
25
48
  let url = checked(new URL(request?.url ?? String(input)), hosts);
26
49
  const caller = init.signal ?? request?.signal;
27
- const timeout = AbortSignal.timeout(timeoutMs);
28
- const signal = caller ? AbortSignal.any([caller, timeout]) : timeout;
50
+ const timeout = deadline(timeoutMs);
51
+ const signal = caller ? AbortSignal.any([caller, timeout.signal]) : timeout.signal;
29
52
  const follow = (init.redirect ?? request?.redirect ?? "follow") === "follow";
30
53
  let method = (init.method ?? request?.method ?? "GET").toUpperCase();
31
54
  let body = init.body ?? request?.body ?? undefined;
@@ -35,7 +58,7 @@ export const hostFetch = (options) => {
35
58
  for (let hop = 0; follow && REDIRECT_STATUSES.has(response.status); hop += 1) {
36
59
  const location = response.headers.get("location");
37
60
  if (!location)
38
- return response;
61
+ return released(response, timeout.clear);
39
62
  if (hop >= redirects)
40
63
  throw new CliError("invalid_response", `more than ${redirects} redirects from ${url.hostname}`);
41
64
  void response.body?.cancel().catch(() => { });
@@ -54,14 +77,15 @@ export const hostFetch = (options) => {
54
77
  url = next;
55
78
  response = await send(url, { ...init, method, headers, body, signal, redirect: "manual" });
56
79
  }
57
- return response;
80
+ return released(response, timeout.clear);
58
81
  }
59
82
  catch (error) {
83
+ timeout.clear();
60
84
  if (isCliError(error))
61
85
  throw error;
62
86
  if (caller?.aborted)
63
87
  throw isCliError(caller.reason) ? caller.reason : new CliError("cancelled", "request cancelled");
64
- if (timeout.aborted)
88
+ if (timeout.signal.aborted)
65
89
  throw new CliError("timeout", `${url.hostname} did not answer within ${timeoutMs} ms`, { retryable: true });
66
90
  throw new CliError("network_error", `${url.hostname} could not be reached`, { retryable: true });
67
91
  }
@@ -28,6 +28,13 @@ export const CRM_FLAGS = [
28
28
  type: "time",
29
29
  meaning: "the day a deal or lead is expected to close, YYYY-MM-DD",
30
30
  },
31
+ {
32
+ name: "--position",
33
+ value: "<title>",
34
+ role: "value",
35
+ type: "string",
36
+ meaning: "a person's job title on a relationship, stored as position; never the role",
37
+ },
31
38
  {
32
39
  name: "--owner",
33
40
  value: "<user>",
@@ -844,6 +844,13 @@ export const WHAT_FLAGS = [
844
844
  },
845
845
  { name: "--remind-time", value: "<time>", role: "value", type: "time", meaning: "when to look at it again" },
846
846
  { name: "--role", value: "<role>", role: "value", type: "string", meaning: "the part it plays, in a word or two" },
847
+ {
848
+ name: "--label",
849
+ value: "<label>",
850
+ role: "value",
851
+ type: "string",
852
+ meaning: "a human-readable label for an id, such as the name shown for a custom relationship role",
853
+ },
847
854
  {
848
855
  name: "--scope",
849
856
  value: "<scope>",
@@ -244,6 +244,7 @@ const collections = [
244
244
  ["topics", "forum topics in a group"],
245
245
  ["models", "local or remote models"],
246
246
  ["tags", "labels the owner puts on things"],
247
+ ["groups", "account groups: the accounts a run in a group reads, such as work and personal (WC-ACCT-13)"],
247
248
  ["searches", "the owner's saved searches"],
248
249
  ["copies", "tables kept aside by a repair"],
249
250
  ["tables", "the tables of the local store, with their kind, row count and size"],
@@ -289,6 +290,7 @@ const collections = [
289
290
  ["facts", "what happened, with evidence"],
290
291
  ["memories", "what an agent concluded, with evidence and scope"],
291
292
  ["relationships", "confirmed or suggested links between people, organizations and projects"],
293
+ ["roles", "the parts a person plays in a relationship, built in or the owner's own"],
292
294
  ["sheets", "remote spreadsheets and their cell ranges, read or changed through a provider"],
293
295
  ["files", "files in the source, such as Google Drive, read and changed there"],
294
296
  ["comments", "comments people left on a thing in the source: a channel post or a file"],
@@ -32,7 +32,7 @@ the four steps that need a person. A new CLI is ready for its first release when
32
32
  | [Commands](commands.md) | `CMD` | 32 | Paths, vocabulary, flags, arguments, effects, lifetime, query, help, external references, joining `wcat`, settings in the config file, refs, network hosts |
33
33
  | [Output](output.md) | `OUT` | 24 | Data on stdout only, envelopes, errors, exit codes, partial answers, projection |
34
34
  | [MCP](mcp.md) | `MCP` | 13 | The MCP tools, how they come from commands, what each permission shows |
35
- | [Accounts](accounts.md) | `ACCT` | 12 | The explicit profile, reads across accounts, scope flags, linked identities, sign-in commands |
35
+ | [Accounts](accounts.md) | `ACCT` | 13 | The explicit profile, reads across accounts, scope flags, linked identities, sign-in commands, memo's account groups |
36
36
  | [Permissions](permissions.md) | `PERM` | 23 | Levels, keys, defaults, hard limits, the write guard and its journal, handing the keys to cli-core |
37
37
  | [Architecture](architecture.md) | `ARCH` | 19 | Layers, dependency direction, vendor types, what goes in which package, the command tree built once |
38
38
  | [Lifecycle](lifecycle.md) | `LIFE` | 16 | Opening late, who closes, deadlines, long-running commands, the `serve` relay, resumable syncs and their request budget, the run log, provider requests inside the run |
@@ -16,10 +16,14 @@ Rule ids on this page are `WC-ACCT-<n>`. How to read a rule, how ids work and wh
16
16
  cli-core resolves the profile for tg, max and wa. WC-ACCT-1 needs cli-core 0.319.0 or newer. memo has no messenger profile: its shared commands run without one, and they pick accounts with `--provider`
17
17
  and `--account` (WC-ACCT-7). memo never creates profiles of its own: it reads the stores of other CLIs and selects
18
18
  their accounts with `--source email:<name>` or `--account telegram:1`, so it has no `--profiles` either
19
- ([cli-base#390](https://github.com/WireCatLabs/cli-base/issues/390), owner decision 2026-10-31). zoom resolves its own profile word by the same rules (`zm <profile> …`, `ZM_PROFILE`,
20
- `ZM_PROFILE_LOCK`) from zoom-cli 0.35.0, with cli-core's `liftProfile` and `usableProfileName`. drive still has its own
21
- profile code: it registers its own profiles. That is a known gap, not an exception. gcal resolves the profile through
22
- cli-core's `run()`, like tg, max and wa. Which CLIs lack a sign-in command of WC-ACCT-12 is listed in that rule.
19
+ ([cli-base#390](https://github.com/WireCatLabs/cli-base/issues/390), owner decision 2026-10-31). memo's first
20
+ word is an account group instead (WC-ACCT-13), read with cli-core's groups
21
+ ([cli-core#2632](https://github.com/WireCatLabs/cli-core/pull/2632)) and memo's group word
22
+ ([cli-memo#698](https://github.com/WireCatLabs/cli-memo/pull/698)). zoom resolves its own profile word by the same
23
+ rules (`zm <profile> …`, `ZM_PROFILE`, `ZM_PROFILE_LOCK`) from zoom-cli 0.35.0, with cli-core's `liftProfile` and
24
+ `usableProfileName`. drive still has its own profile code: it registers its own profiles. That is a known gap, not
25
+ an exception. gcal resolves the profile through cli-core's `run()`, like tg, max and wa. Which CLIs lack a sign-in
26
+ command of WC-ACCT-12 is listed in that rule.
23
27
 
24
28
  ## Rules
25
29
 
@@ -50,9 +54,11 @@ profile.
50
54
  - **Example:** `max work bot messages send …` uses the same first word as `max work chats list`. `tg --json chats list`
51
55
  still works, because `--json` is an option.
52
56
  - **Exceptions:** `mcp serve --profiles <names|all>` names the profiles one server serves ([WC-MCP-9](mcp.md#wc-mcp-9--a-server-serves-the-profiles-it-is-told-with-one-connection-for-each)). It is used in
53
- place of the first word, never with it. memo has no profiles of its own, so it has neither the first word nor
54
- `--profiles`; it selects the accounts of other CLIs with `--source` and `--account`.
55
- - **Applies to:** all CLIs. **Since:** cli-base 0.41.0. **Rulings:** NEED-84, NEED-294, NEED-1881.
57
+ place of the first word, never with it. memo has no profiles of its own, so it has no `--profiles`, and its first
58
+ word is an account group, not a profile: `memo work search all invoice`
59
+ ([WC-ACCT-13](#wc-acct-13--memos-first-word-is-an-account-group-and-the-default-group-all-holds-every-account)).
60
+ It selects the accounts of other CLIs with `--source` and `--account`.
61
+ - **Applies to:** all CLIs. **Since:** cli-base 0.41.0. **Rulings:** NEED-84, NEED-294, NEED-1881, NEED-2378.
56
62
 
57
63
  ### WC-ACCT-3 · A missing profile is an error that lists the choices
58
64
 
@@ -190,6 +196,48 @@ Every CLI that signs in has four commands under `session`:
190
196
  ([WC-CMD-8](commands.md#wc-cmd-8--keep-no-aliases-a-renamed-path-stops-working-in-the-release-that-renames-it)).
191
197
  - **Applies to:** every CLI that signs in. **Since:** cli-base 0.65.0. **Rulings:** NEED-1884.
192
198
 
199
+ ### WC-ACCT-13 · memo's first word is an account group, and the default group `all` holds every account
200
+
201
+ A group is a list of accounts that the owner saves, store-wide, as `account_groups.<name>`; every reader takes it as
202
+ `--source group:<name>`. The default reads everything; groups and the lock are opt-in narrowing for agents.
203
+
204
+ - `all` is the default group. It always holds every account and is never saved or edited. No group word means `all`,
205
+ as before, and `memo all …`, `MEMO_GROUP=all` and `MEMO_GROUP_LOCK=all` restrict nothing.
206
+ - Any other group holds exactly the accounts it lists, `personal` like any other, and a group never saved does not
207
+ exist. A member is saved as `provider:account`, so renaming a profile changes nothing.
208
+ - One account may be in several groups. This is allowed and shown, not refused: a groups list gives each member its
209
+ profile names in every CLI and `also_in` (its other groups), and the answer has a `duplicates` summary.
210
+ - A profile named like a group never puts its account in the group. A groups list only suggests it
211
+ (`suggested`, "profile named work"), and only when another CLI's profile or a saved group uses the same name.
212
+ - A group name is letters, digits, `-` and `_`, and starts with a letter or a digit. It is not `all`, not `bots` and
213
+ not a memo command word.
214
+
215
+ `memo <group> …` reads only that group: a read without `--source` reads `group:<group>`, an explicit `--source`
216
+ narrows inside it, and an account outside it is `validation_error`, as is a write's `--account` outside it.
217
+ `MEMO_GROUP=<group>` does the same as the first word. `MEMO_GROUP_LOCK=<group>` pins the process as WC-ACCT-5 pins a
218
+ profile: another group, `all`, or an account outside the group is `permission_error`. Under the lock every source
219
+ list holds only the group's accounts, so a read that names no group stays inside it. The lock fails closed: a command
220
+ runs only when it is marked as keeping to a group (`groupAware`), and a reference in its arguments or options to
221
+ account data outside the group is refused: a message, a chat, mail, a calendar event, a CRM row, or a person seen only
222
+ by outside accounts. What the owner made, with no account (memo's notes, projects, tasks, invoices, memories,
223
+ facts), is visible in every group. Without the lock, a group is a convenience and not a boundary.
224
+
225
+ - **Why:** an agent can be held to the owner's work accounts across every CLI, without naming each account, while the
226
+ owner's own default still reads everything.
227
+ - **Enforced by:** `cli-core: src/search/groups.test.ts` · `cli-core: src/cli/group-lock.test.ts` ·
228
+ `cli-core: src/crm/sync.test.ts`.
229
+ - **Example:** with `account_groups.work` set to `telegram:102,bitrix24:acme.bitrix24.ru`, `memo work search all
230
+ invoice` reads those two accounts, and `memo search all invoice` reads every account. `memo work search all x
231
+ --source telegram:101` is refused because `telegram:101` is not in `work`. With nothing saved, `memo work …` is
232
+ refused with the groups listed (`all`), and the profiles named `work` are suggested. The first CRM sync of an
233
+ account no saved group lists answers `group_hint`, ``add it to a work group: `memo groups add work
234
+ <provider>:<account>` ``. Only the CRM sync answer carries it.
235
+ - **Exceptions:** the bare word `personal` in a `--source` list still means the messenger accounts that are not bots;
236
+ only `group:personal` is a saved group of that name. Besides memo's `groups` commands, tg and max save a group
237
+ (`config set account_groups.<name>`); they refuse `all` and `bots` but not a memo command word.
238
+ - **Applies to:** memo, and cli-core's source lists in every CLI. **Since:** cli-base 0.86.0. **Rulings:** NEED-2378,
239
+ NEED-2389.
240
+
193
241
  ## Sources
194
242
 
195
243
  These documents explain the rules on this page in more detail. Where one of them disagrees with this page, this page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-base",
3
- "version": "0.85.1",
3
+ "version": "0.86.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",