@wirecat/cli-core 0.691.0 → 0.693.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +141 -203
  3. package/dist/calendar/prepare.d.ts +11 -0
  4. package/dist/cli/bot/api-http.d.ts +4 -1
  5. package/dist/cli/bot/api-http.js +17 -4
  6. package/dist/cli/bot/api-input.d.ts +4 -0
  7. package/dist/cli/bot/api-input.js +9 -0
  8. package/dist/cli/bot/api.d.ts +4 -0
  9. package/dist/cli/bot/api.js +16 -2
  10. package/dist/cli/documents/folders.js +1 -1
  11. package/dist/cli/documents/search.js +3 -3
  12. package/dist/cli/documents/words.d.ts +2 -0
  13. package/dist/cli/documents/words.js +1 -0
  14. package/dist/cli/envelope.d.ts +22 -0
  15. package/dist/cli/index.d.ts +7 -4
  16. package/dist/cli/index.js +7 -4
  17. package/dist/cli/oauth-session.d.ts +60 -0
  18. package/dist/cli/oauth-session.js +224 -0
  19. package/dist/cli/service-api-call.d.ts +27 -0
  20. package/dist/cli/service-api-call.js +32 -0
  21. package/dist/cli/service-api-manifest.d.ts +14 -10
  22. package/dist/cli/service-api-manifest.js +38 -34
  23. package/dist/cli/service-api.d.ts +17 -2
  24. package/dist/cli/service-api.js +42 -24
  25. package/dist/cli/token-session.d.ts +33 -0
  26. package/dist/cli/token-session.js +121 -0
  27. package/dist/crm/index.d.ts +3 -0
  28. package/dist/crm/index.js +3 -0
  29. package/dist/crm/manifest/manifest.d.ts +195 -0
  30. package/dist/crm/manifest/manifest.js +161 -0
  31. package/dist/crm/manifest/map.d.ts +58 -0
  32. package/dist/crm/manifest/map.js +240 -0
  33. package/dist/crm/manifest/paths.d.ts +11 -0
  34. package/dist/crm/manifest/paths.js +161 -0
  35. package/dist/crm/manifest/source.d.ts +18 -0
  36. package/dist/crm/manifest/source.js +385 -0
  37. package/dist/errors/reasons.js +1 -0
  38. package/dist/manifest/index.d.ts +53 -0
  39. package/dist/manifest/index.js +61 -0
  40. package/package.json +8 -3
package/CHANGELOG.md CHANGED
@@ -5,6 +5,68 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.693.0 — 17.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`@wirecat/cli-core/manifest`: `defineCli` and `parseCliConfig`, the shape of `wirecat.config.ts`.** One file names
13
+ the CLI (command, package, environment prefix, service, owner), its API description (an https URL), its sign-in
14
+ (`none`, `token`, or `oauth2-pkce` with the options `oauthPreset` takes), its category (cli-template's, or `other`)
15
+ and, for a CRM, its source. cli-template's `new --from-config` builds a CLI from it. Each error names the field; the
16
+ source is checked against the generated API by `parseCrmManifest`.
17
+ - **`crmManifestProblems(manifest, api, definitions)` checks every path a CRM manifest reads against what each
18
+ operation answers**, from the generated `definitions`: a misspelt or moved field is named with its operation and the
19
+ field it likely meant, before a sync runs. A part of a schema that says nothing passes.
20
+ - **A CRM manifest's `hooks.enrich`** reads more for a whole page before the map, in one batch request (HubSpot's
21
+ associations, which its search does not answer).
22
+ - **`optional` on a manifest kind:** the service refusing it (a plan or scope without it) is a gap with the manifest's
23
+ text and scope, and the other kinds still sync. A refusal part way through the id pass still fails it, so no unread row
24
+ is taken as deleted. Each gap is said once per call.
25
+ - **`select.max`:** `{select}` always asks for every mapped field, then the account's own while they fit; the count left
26
+ out is a gap, so an account with hundreds of custom fields still syncs.
27
+ - **A CRM source from a manifest: `crmSourceFromManifest(manifest, { api, call, hooks })` in `@wirecat/cli-core/crm`.**
28
+ A CLI with an OpenAPI spec describes its CRM as data: per kind, the operations (by their generated id) that list
29
+ every row, read changes after `{since}` (in the query or the body), list every id and read one record, and where each
30
+ shared field sits in the answer (a path, `first`, `join`, `all`, `each`, `map`, a constant or a function). The engine
31
+ pages by each operation's own `pagination` (or, for a change read sorted by modified time, by `keyset`: from the
32
+ last row's time, `reset` past the service's cap), keeps `<page>@<round start>` page tokens, re-reads a 10-minute overlap,
33
+ spends the run's budget after the first request, answers a 403 or 404 on `get` with null, asks a service that names
34
+ its returned fields (`"{select}"`) for only the mapped ones and the account's own, and leaves out a field the answer
35
+ did not carry, so the stored copy keeps it. Pipelines, custom field definitions and users are described the same
36
+ way; `hooks.after` corrects one record (async, with the metered call) and `hooks.extend` adds or replaces any `CrmSource` method.
37
+ `parseCrmManifest` checks the shape, every operation id (a read only) and every mapped field, and names the field at fault and the operation a typo
38
+ meant. See [docs/dev/CRM.md](docs/dev/CRM.md#a-source-from-a-manifest).
39
+ - `serviceApiCall({ manifest, service, fetch, token })` in `@wirecat/cli-core/cli`: one read operation of a generated
40
+ manifest sent as the `api` group sends it (request, sign-in header, redirect rule, run record, refusals), for code
41
+ that is not a command.
42
+ - **`oauthPreset(flow, options)`: an installed app's browser sign-in from the flow a spec declares.**
43
+ `oauthFlowOf(manifest)` reads the OpenAPI authorization code flow; a GraphQL service writes the same object by hand.
44
+ Each scope the CLI asks for must be one the flow lists, with a "did you mean" for a typo. The redirect stays the
45
+ CLI's choice: the spec cannot say which one the app registered. A sign-in URL that is not https is refused, and
46
+ `rotating` marks a provider that sends a new refresh token on each refresh, so a run with moved folders never
47
+ refreshes it.
48
+ - **`oauthSessionCommand(options)`: the shared `session start | status | end | list` for a browser sign-in.** PKCE on
49
+ the loopback, the CLI's `verify` and `claim` before anything is kept, refreshes under one lock, `--no-browser` and
50
+ `--credential-storage file`, which also forgets an older keyring copy. In a run with moved folders, `session end`
51
+ says the owner's sign-in stays.
52
+ - **A generated `api` group signs in with an API key in the query** (`apiKey` with `in: query`), as it already did
53
+ with one in a header. The key goes on every page of `--all`, a next link included, and never follows a redirect.
54
+ The run record keeps only the path template, so the key never lands in a file. Where an operation also takes a
55
+ header or a bearer token, that one is sent: a URL can be kept by a proxy or a server log.
56
+ - **`signRequest(manifest, operation, request, token)`** signs one request the way the `api` group and
57
+ `serviceApiCall` do.
58
+ - **`tokenSessionCommand(options)`: the shared `session start | status | end | list`** for a service signed in with one
59
+ token. The CLI gives its `verify` (ask the service whose the token is); the token is read hidden or from stdin,
60
+ checked, and only then kept in the keyring or a private file. It replaces each token CLI's own `session.ts`.
61
+
62
+ ## 0.692.0 — 17.11.2026
63
+
64
+ ### Fixed
65
+
66
+ - **A documents CLI that adds a folder by path shows that path in `folders add`'s example and in `search`'s hint.**
67
+ Both said `FOLDER_ID`, which ydisk refuses: its `folders add` takes a Disk path such as `/Documents`. The CLI sets
68
+ `text.folderToAdd` in its `DocumentWords`; without it both keep `FOLDER_ID`.
69
+
8
70
  ## 0.691.0 — 17.11.2026
9
71
 
10
72
  ### Added
package/README.md CHANGED
@@ -4,11 +4,55 @@
4
4
 
5
5
  # @wirecat/cli-core
6
6
 
7
- The engine behind the WireCat command-line tools for Telegram, MAX, WhatsApp, mail, notes, meetings and Google
8
- Drive. Everything that
9
- does not depend on one messenger lives here: the data model, a local SQLite store with full-text and semantic
10
- search, a Lucene query language, the shared commands, an MCP server for AI agents, and the guard around every
11
- write. A messenger plugs in as one adapter and gets all of it.
7
+ Build a CLI that lets people and AI agents search a messenger, a mailbox or any service with a history, in
8
+ TypeScript on Node or Bun. You write the adapter that talks to the service, and cli-core gives it a local store with
9
+ search, the shared commands and an MCP server.
10
+
11
+ ```ts
12
+ import { type Messenger, mcpCommand, messagesCommand, run, searchCommand, settingsFor } from "@wirecat/cli-core/cli"
13
+ import { acmeAdapter } from "./adapter.js" // your code: the only part that speaks to Acme Chat
14
+
15
+ const app = { command: "acme", appName: "acme-cli", envPrefix: "ACME", description: "Acme Chat", version: "0.1.0" }
16
+ const settings = settingsFor(app)
17
+
18
+ const acme: Messenger = {
19
+ app,
20
+ provider: "acme",
21
+ resolveSettings: settings.resolveSettings,
22
+ connect: async () => acmeAdapter(),
23
+ chatArgument: "a chat: its name or its Acme id",
24
+ }
25
+
26
+ process.exitCode = await run(process.argv.slice(2), {
27
+ app,
28
+ configuration: settings,
29
+ commands: () => [messagesCommand(acme), searchCommand(acme), mcpCommand(acme)],
30
+ })
31
+ ```
32
+
33
+ ```sh
34
+ acme personal messages sync --all # every chat's history into the local store
35
+ acme personal search messages come --json=excerpt # {"items":[{"excerpt":"are you coming?",…}],…}
36
+ acme personal mcp check # {"item":{"healthy":true,…,"tools":3,…},…}
37
+ ```
38
+
39
+ That output is real, from this program with the in-memory `fakeAdapter` of `@wirecat/cli-core/testing` in place of
40
+ Acme. The search found "are you coming?" from the word "come", with no network.
41
+
42
+ **Built on it:** [tg-cli](https://github.com/WireCatLabs/tg-cli), [max-cli](https://github.com/WireCatLabs/max-cli),
43
+ [gcal-cli](https://github.com/WireCatLabs/gcal-cli) and 12 more WireCat CLIs, such as the mail and notes tool
44
+ [cli-memo](https://github.com/WireCatLabs/cli-memo), the [WhatsApp tool](https://github.com/WireCatLabs/whatsapp-cli),
45
+ [zoom-cli](https://github.com/WireCatLabs/zoom-cli) and [drive-cli](https://github.com/WireCatLabs/drive-cli).
46
+
47
+ ## Install
48
+
49
+ ```sh
50
+ npm install --save-exact @wirecat/cli-core
51
+ ```
52
+
53
+ npm 7+ and pnpm also install its peers: `@wirecat/cli-base` in the range `package.json` names, and `commander` 15 or
54
+ later. `@napi-rs/canvas` is optional, and charts need it only for PNG output. It runs on Node 22.16+ and 24+, and on
55
+ Bun. Pin an exact version, because any release before 1.0 may break a caller ([Build on it](#build-on-it)).
12
56
 
13
57
  [Architecture](docs/dev/ARCHITECTURE.md) · [Write an adapter](docs/dev/ADAPTERS.md) ·
14
58
  [Query language](docs/search/query-language.md) · [Messenger rules](docs/dev/STANDARD.md) ·
@@ -20,57 +64,49 @@ write. A messenger plugs in as one adapter and gets all of it.
20
64
  [![Bun](https://img.shields.io/badge/bun-tested-f9f1e1)](https://bun.sh/)
21
65
  [![License: Apache 2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
22
66
 
23
- ## Key documents
67
+ ## Which package to install
24
68
 
25
- | Document | What it answers |
26
- |---|---|
27
- | [Architecture](docs/dev/ARCHITECTURE.md) | The layers, the module map, the store internals and migrations, who consumes what |
28
- | [Document workflows](docs/dev/DOCUMENTS.md) | Shared file ingestion, sync, scoped knowledge and extraction; the ports a file provider supplies |
29
- | [Media archives](docs/dev/MEDIA-ARCHIVE.md) | Independent verified file copies, interruption recovery and opt-in daily timers |
30
- | [Write an adapter](docs/dev/ADAPTERS.md) | How to add a messenger: the port, the `Messenger` description, the contract cases |
31
- | [Messenger rules](docs/dev/STANDARD.md) | What binds tg, max and wa beyond the [CLI standards handbook](https://github.com/WireCatLabs/cli-base/blob/main/docs/standards/README.md): parity, the option catalogue, `bot` |
32
- | [Glossary](docs/dev/GLOSSARY.md) | One word, one meaning across the tools |
33
- | [Query language](docs/search/query-language.md) · [spec](docs/search/query-language-spec.md) · [Image search](docs/search/images.md) | The search syntax and its exact grammar; finding pictures by context and by what they show |
34
- | [Mentions](docs/mentions.md) · [how they work](docs/dev/MENTIONS.md) | Phones, e-mail, links, documents and names found in messages: search, review, rebuild; the tables and the rules |
35
- | [Storage](docs/storage/README.md) | The schema, the search indexes and the decisions behind them |
36
- | [Knowledge](docs/dev/KNOWLEDGE.md) · [Meetings](docs/dev/MEETINGS.md) | Labels, links and proposals across sources; the meetings module and its providers |
37
- | [Testing](docs/dev/TESTING.md) · [Parity audit](docs/dev/PARITY-AUDIT.md) | The sandbox, the coverage floor, the checks across tg and max |
38
- | [Tool boundaries](docs/dev/TOOL-BOUNDARIES.md) | Which tool owns which command |
39
- | [API reference](docs/REFERENCE.md) | Every entry point and the detailed contract of each feature |
40
- | [Roadmap](docs/roadmap.md) | What is being built next for developers on this package |
41
- | [Changelog](CHANGELOG.md) | What each version changed, and what may break callers |
42
-
43
- ## What it is
44
-
45
- A messaging CLI has two halves. One speaks a protocol: MTProto for Telegram, a WebSocket for MAX, IMAP for mail.
46
- The other half is the same for every messenger: store what was read, search it, render it for a person and as JSON
47
- for a program, guard every send, expose it all to an agent. This package is the second half.
48
-
49
- [tg-cli](https://github.com/WireCatLabs/tg-cli), [max-cli](https://github.com/WireCatLabs/max-cli) and
50
- the [WhatsApp tool](https://github.com/WireCatLabs/whatsapp-cli) are built on it, and so are the mail and notes tool
51
- [cli-memo](https://github.com/WireCatLabs/cli-memo), [zoom-cli](https://github.com/WireCatLabs/zoom-cli) and
52
- [drive-cli](https://github.com/WireCatLabs/drive-cli). They import it as `@wirecat/cli-core`. Up to 0.261.0 the package
53
- was named `@wirecat/cli-messaging`, which is deprecated. The npm versions 0.0.0-stage, 0.0.0 and 0.18–0.20 of
54
- `@wirecat/cli-core` are deprecated too: they are placeholders and the old cli-base.
55
-
56
- **Who it is for.** First of all, it is the engine of the WireCat tools, and it changes as fast as they need. You can
57
- build your own messenger CLI on it, but expect to follow a moving API (see [Build on it](#build-on-it)).
58
-
59
- ```sh
60
- npm install --save-exact @wirecat/cli-core
69
+ ```mermaid
70
+ flowchart LR
71
+ cli["Your CLI"] -->|"keeps messages, mail or files to search"| core["@wirecat/cli-core"]
72
+ cli -->|"any other CLI"| base["@wirecat/cli-base"]
73
+ core --> base
74
+ base --> runtime["Node or Bun"]
61
75
  ```
62
76
 
63
- npm 7+ and pnpm also install its peers: `@wirecat/cli-base` in the range `package.json` names, and `commander` 15 or
64
- later. `@napi-rs/canvas` is optional; charts need it only for PNG output.
65
-
66
- It is built on [`@wirecat/cli-base`](https://github.com/WireCatLabs/cli-base), the layer every CLI needs: two output
67
- streams, closed error codes, the keyring, injectable clocks, the query parser. cli-base is a peer dependency, so an
68
- install holds one copy.
77
+ cli-core is for a tool that keeps what it reads in a local store and searches it. It is built on
78
+ [`@wirecat/cli-base`](https://github.com/WireCatLabs/cli-base), the layer every CLI needs: two output streams, closed
79
+ error codes, the keyring, injectable clocks and the query parser. cli-base is a peer dependency, so an install holds
80
+ one copy. A CLI with nothing to store needs only cli-base.
69
81
 
70
- It has 26 entry points (the `exports` of `package.json`), 27 search fields and 13 search presets.
71
- It runs on Node 22.16+ and 24+, and on Bun.
82
+ ## Features
72
83
 
73
- ## Architecture
84
+ - **Search that finds the message, not only the word.** One query language for every list and every source, a
85
+ TypeScript port of the Apache Lucene 9.12.3 parsers: phrases, `from:(alice OR bob)`, `date:[2026-01-01 TO
86
+ 2026-02-01}`, `size>10MB`. Word forms in Russian, English and Spanish (`встреча` finds `встречи`), any three letters
87
+ inside a word, and search by meaning when you opt in. A question over 100,341 synthetic messages took 54 ms at the
88
+ median ([measured](https://github.com/WireCatLabs/cli-testing/blob/main/performance/search/model-free/FRESH-VALIDATION.md#archive-size-latency-and-query-ram),
89
+ [every search measurement](https://github.com/WireCatLabs/cli-testing/tree/main/performance/search)).
90
+ [Syntax](docs/search/query-language.md) · [grammar](docs/search/query-language-spec.md) ·
91
+ [image search](docs/search/images.md)
92
+ - **One store for every source.** Messages from Telegram and MAX, mail, notes and meeting transcripts sit side by side
93
+ in one SQLite file, `wirecat.db`, so one query searches all of them. Edits are kept as revisions and deletions as
94
+ tombstones. Migrations only move forward, and an older CLI keeps reading a file a newer one migrated.
95
+ [Storage](docs/storage/README.md) · [why SQLite FTS5 and no daemon](docs/storage/decisions.md)
96
+ - **An MCP server that leaves room in the agent's context.** The shared commands reach an agent as 3 MCP tools: find a
97
+ command, run a read, run a write. It runs over stdio, or over HTTP on 127.0.0.1 behind the owner's tunnel with a
98
+ one-owner OAuth login.
99
+ - **Every write behind a guard.** A permission level per command path (deny, readonly, ask or allow), a list of
100
+ allowed recipients, and at most 30 sends an hour by default. A write whose outcome is unknown is never retried, and
101
+ a retry under the same send id cannot send twice.
102
+ - **Knowledge, tasks and meetings across sources.** What an agent proposes stays proposed until the owner accepts it.
103
+ Tasks have project keys like `RES-12`, and a meeting transcript is kept by revision.
104
+ [Knowledge](docs/dev/KNOWLEDGE.md) · [Meetings](docs/dev/MEETINGS.md) · [Mentions](docs/mentions.md)
105
+ - **Files and voice as text.** Readers for PDF, Word, HTML and more, each loaded on first use, and speech recognition
106
+ on your computer from a pinned model catalogue. [Document workflows](docs/dev/DOCUMENTS.md) ·
107
+ [Media archives](docs/dev/MEDIA-ARCHIVE.md)
108
+
109
+ ## How it works
74
110
 
75
111
  ```mermaid
76
112
  flowchart TB
@@ -90,152 +126,14 @@ Five layers, and each calls only the layers below it: domain, adapters behind a
90
126
 
91
127
  - **The CLI and the MCP server are two adapters over the same services.** A command and its MCP tool answer with
92
128
  the same data, because one service produces it.
93
- - **A port with one required core and optional groups.** `MessengerCore` is what every messenger must do. The other
94
- groups — server reads, polls, forums, reactions and the rest — are optional and reached through `capability()`.
95
- A messenger without a group refuses the command before connecting; it never crashes and never silently drops an
96
- option.
97
- - **Decorators, so no service can forget.** Every adapter is wrapped twice: `stored` saves what a read answered,
98
- and `observed` times each call for the run record.
99
- - **Override a use case, not a command.** A tool replaces one service through `Messenger.services`; every command
129
+ - **A port with one required core and optional groups.** `MessengerCore` is what every messenger must do. Groups such
130
+ as polls or forums are optional and reached through `capability()`. A messenger without a group refuses the command
131
+ before it connects. It never crashes and never drops an option in silence.
132
+ - **Override a use case, not a command.** A tool replaces one service through `Messenger.services`, and every command
100
133
  and tool that uses it follows.
101
- - **Tasks and meetings know nothing of SQLite.** They define their own ports (`TaskStore`, `MeetingStore`), and the
102
- store implements them.
103
-
104
- **The build enforces these boundaries.** Biome import rules refuse, under `src/`:
105
-
106
- - any messenger library or adapter — this package speaks no provider;
107
- - `commander` or a command file in services, sends or MCP;
108
- - the SQLite table modules anywhere outside the store's own interface;
109
- - any import from the rest of the package inside tasks and meetings, and any file system or SQLite there.
110
-
111
- Tests guard the rest. Migrations must be numbered without gaps and may not rebuild a table. The schema spec, the
112
- code and its document must agree. A search plan that reads an index once per message fails the build.
113
-
114
- ## Features
115
-
116
- ### Search that finds it
117
-
118
- - **One query language for every list and every source.** A TypeScript port of the Apache Lucene 9.12.3 parsers,
119
- with no runtime parser dependency. Phrases, `AND` / `OR` / `NOT`, `+required`, grouping, field groups like
120
- `from:(alice OR bob)`, ranges `date:[2026-01-01 TO 2026-02-01}`, comparisons `size>10MB`, wildcards and regular
121
- expressions. 27 fields: sender, chat, date, file name, MIME type, transcript, subject, label and more.
122
- Proximity `"invoice paid"~3` finds the words close together in one message; the fuzzy operator `word~1` is
123
- refused with an error that names the alternative.
124
- [Syntax](docs/search/query-language.md) · [grammar](docs/search/query-language-spec.md)
125
- - **Any three letters inside a word.** An FTS5 trigram index finds `port` inside `report`. A
126
- second, word index ranks by BM25.
127
- - **Word forms in three languages.** Snowball 3.1.1 stemmers for Russian, English and Spanish: `встреча` finds
128
- `встречи`. Exact forms rank first; `exact:` turns stemming off.
129
- - **Safe regular expressions.** A Thompson NFA without backtracking, with budgets for states and work, so no
130
- pattern can hang the search.
131
- - **Presets for what people actually look for.** `preset:password`, `api-key`, `card`, `phone`, `email`, `url` and
132
- seven more find candidates, labelled as candidates.
133
- - **Search by meaning, opt in.** Conversations are split into chunks and embedded locally by ONNX Runtime — native
134
- on Linux (glibc), Apple-silicon Macs and Windows once `models download` has fetched it, WebAssembly elsewhere, on
135
- Node and Bun alike — EmbeddingGemma by default (e5-small to choose), or any OpenAI-compatible API with your own key, after
136
- you see the cost. Results by meaning and by words are merged by reciprocal rank fusion.
137
- - **The archive and the server together.** `--backend both` also asks the messenger's own search; its hits are saved
138
- and filtered by the same query, so nothing is counted twice. `--thread` brings the reply thread around a hit.
139
- - **Bounded by design.** Query size, depth, nodes, pattern length, expansions and run time all have limits.
140
-
141
- Measured on synthetic data ([methodology and results](https://github.com/WireCatLabs/cli-testing/tree/main/performance/search)):
142
-
143
- | Stored messages | Search p50 / p95 |
144
- |---|---|
145
- | 10,341 | 9.0 / 22.6 ms |
146
- | 100,341 | 53.9 / 107.6 ms |
147
-
148
- ### One local store for every source
149
-
150
- - **One file, every messenger and account:** `wirecat.db` in `~/.local/share/WireCat/` (`%LOCALAPPDATA%\WireCat\Data\`
151
- on Windows). Messages from Telegram and MAX, mail, notes and meeting transcripts sit side by side, so one query
152
- searches all of them.
153
- - **`node:sqlite` under Node and `bun:sqlite` under Bun,** behind a small seam. WAL and a busy timeout on both.
154
- - **History you can trust.** Edits are kept as revisions and deletions as tombstones. Every sender is an identity
155
- with a person of their own, so one person across two messengers can be linked.
156
- - **Migrations an older build survives.** Forward-only, additive and frozen once released. `min_compatible` lets an
157
- older CLI keep using a file a newer one migrated, and refuses a file it cannot read.
158
- - **Built for the long run.** History download is resumable and respects the messenger's rate limits; it can run in
159
- the background as a job. `store check`, `backup` and `restore` look after the file itself.
160
-
161
- [Storage](docs/storage/README.md) · [why SQLite FTS5 and no daemon](docs/storage/decisions.md)
162
-
163
- ### A full CLI and an MCP server from one adapter
164
-
165
- Describe a messenger once — its name, how to connect, how `me` maps to a chat — and the tool gets about sixty
166
- shared commands: chats, contacts, messages, search, reactions, polls, the inbox of unread messages, `watch` for live
167
- updates, history download, the store, run records, configuration, shell completion, `doctor`, and `commands --json`,
168
- the whole command tree as data for an agent.
169
-
170
- The same commands become MCP tools for agents without a terminal. The server offers three tools — find a command,
171
- run a read, run a write — so an agent's context does not fill with a hundred tool schemas. It runs over stdio, or
172
- over HTTP on 127.0.0.1 behind the owner's tunnel, with a one-owner OAuth login.
173
-
174
- `serve` keeps the store current, one process per profile by a lock file; `server install` adds a systemd user unit
175
- or a launchd agent that starts at every login.
176
-
177
- ### Every write behind a guard
178
-
179
- - **A permission level per command path:** deny, readonly, ask or allow. The most specific key wins, and a built-in
180
- default can only tighten what the owner set. No level lets an agent delete for everyone.
181
- - **A recipient list and an hourly limit** for sends, and a journal of every attempt that records the length of the
182
- text, never the text. Each photo or file of an album counts as one send.
183
- - **A send id across retries.** A write whose outcome is unknown is never retried automatically; a retry under the
184
- same send id cannot send twice.
185
- - **Deletion asks first,** at most ten messages at a time.
186
- - **MCP writes follow the same profile permissions.** An agent sees only the tools the profile allows.
187
-
188
- ### Knowledge, tasks and meetings
189
-
190
- - **Labels, links and facts across sources,** always scoped to an explicit account. What an agent adds stays
191
- *proposed* until the owner accepts it, with a fingerprint so a stale review cannot overwrite a newer change.
192
- - **A shared vocabulary.** Before a new tag is created, similar existing tags and aliases are offered for review.
193
- - **Tasks** with project keys (`RES-12`), dependencies and a readiness check.
194
- - **Meetings:** a WebVTT parser, a `MeetingSource` port a provider implements, transcripts kept by revision, and
195
- references to one cue of one transcript.
196
-
197
- ### Files, voice and charts
198
-
199
- - **Readers for PDF, Word, ODF, HTML and more,** each library loaded on first use.
200
- - **Local speech recognition** from a pinned model catalogue; importing it loads no engine and downloads nothing.
201
- - **Charts from statistics** as JSON, SVG or PNG, with a replaceable renderer loaded only when an image is asked for.
202
-
203
- ## Engineering standards
204
-
205
- The [WireCat CLI standards handbook](https://github.com/WireCatLabs/cli-base/blob/main/docs/standards/README.md) in cli-base binds every WireCat CLI; the
206
- [messenger rules](docs/dev/STANDARD.md) add what binds tg, max and wa. They measure themselves against POSIX, GNU,
207
- [Command Line Interface Guidelines](https://clig.dev), the MCP specification and JSON Schema 2020-12, and say where
208
- they deliberately differ. A rule changes in its own pull request, before the code that needs it.
209
-
210
- - **stdout carries data, stderr carries diagnostics,** in every mode. `--json` prints one object; `--jsonl` one per
211
- line; `--json=id,text` only those fields.
212
- - **Stable exit codes** a script can branch on: 2 validation, 3 config, 4 auth, 5 permission, 6 not found,
213
- 8 rate limited, 9 timeout, 14 outcome unknown, and the rest. An error is one JSON object with a stable `code` and
214
- `reason` — callers never parse the message.
215
- - **Built for agents.** `--no-input` never prompts. Input and output are bounded (16 MiB in, 4 MiB out) and fail
216
- visibly instead of truncating. One-shot commands time out after 30 seconds and close what they hold. `--dry-run`
217
- previews any write.
218
- - **The tool never picks an account.** Every account command names its profile — the first word in tg, max and
219
- wa, an option such as `--account` or `--profile` in the others; without one, the command stops and lists the
220
- choices — even when there is only one.
221
- - **Run records keep the command as typed, never a secret.** Every run is kept, with one line per request it made,
222
- so `runs show` can explain it: successes for 7 days, failures for 30, within a size limit. A token, a password or
223
- a phone number is hidden; `record_input: false` leaves the typed words out, `"failed"` keeps them only for a
224
- failure, and `record: false` keeps failures only.
225
- - **Tests that cannot touch real data.** A sandbox keeps every test away from the owner's store, and no test may
226
- sleep. A coverage floor: 92% of lines, and at least half of every file.
227
- - **Contract cases for every adapter.** `contractCases` turns the port's promises into cases any test runner can run,
228
- over an in-memory fake or a real client.
229
- - **Checked across tools and runtimes.** CI runs on Linux: the test suite on Node 24, smoke checks on Bun and on
230
- Node 22.16, a parity workflow that builds the Telegram, MAX and WhatsApp CLIs against this repository, and
231
- gitleaks over the full history. macOS and Windows run only four workflows: the SQLite library build (macOS) and
232
- the ONNX runtime probe (macOS and Windows) run monthly and when started by hand; the native-runtime check (Linux,
233
- macOS and Windows, x64 and arm64, and Alpine) runs monthly and on every pull request that changes how models
234
- load; the scheduler test (macOS and Windows) runs only when started by hand. The rest of the suite does not run on
235
- macOS or Windows.
236
- - **One shared toolchain.** Biome, markdownlint, CSpell and Lefthook configs come from the
237
- [WireCat standards](https://github.com/WireCatLabs/community/blob/main/standards/README.md), and CI fails when a
238
- copy drifts.
134
+ - **The build keeps the lines.** Biome import rules refuse any messenger library under `src/`, `commander` in a
135
+ service, and the SQLite tables outside the store. Tests refuse a gap in the migration numbers and a search plan that
136
+ reads an index once per message.
239
137
 
240
138
  ## Build on it
241
139
 
@@ -243,8 +141,8 @@ A new messenger is three pieces: an adapter that implements `MessengerCore` (and
243
141
  `Messenger` that describes it, and the contract cases run against it. The
244
142
  [adapter guide](docs/dev/ADAPTERS.md) walks through each one.
245
143
 
246
- This runs as it is under vitest. `fakeAdapter` is the in-memory adapter the kit ships; put your own adapter there,
247
- built over a fake client filled from `seed`. The `./testing` kit is not stable yet.
144
+ This runs as it is under vitest and gives 29 cases. `fakeAdapter` is the in-memory adapter the kit ships. Put your own
145
+ adapter there, built over a fake client filled from `seed`. The `./testing` kit is not stable yet.
248
146
 
249
147
  ```ts
250
148
  import { contractCases, digitIds, fakeAdapter } from "@wirecat/cli-core/testing"
@@ -259,15 +157,30 @@ describe("the adapter keeps the port's promises", () => {
259
157
  })
260
158
  ```
261
159
 
262
- **Before 1.0, any release may break a caller.** Releases are frequent, sometimes several a day, and any of them
263
- may change any entry point. Every such change is listed in the [changelog](CHANGELOG.md) under "Changed — may break
264
- callers", with what to change. tg-cli and max-cli pin an exact version and move to a new one in their own pull request.
265
- Pin an exact version too.
160
+ **Before 1.0, any release may break a caller.** Releases are frequent, sometimes several a day, and any of them may
161
+ change any entry point. The [changelog](CHANGELOG.md) lists every such change in its own section, with what to change.
162
+ tg-cli and max-cli pin an exact version and move to a new one in their own pull request. Pin an exact version too.
266
163
  The full list of entry points and what each holds is in the [API reference](docs/REFERENCE.md).
267
164
 
268
165
  ⚠ **Errors are recognised by shape, not by class** (`isCliFailure`). A package linked during development brings its
269
166
  own copy of cli-base, and an error built by one copy is not an `instanceof` the other's class.
270
167
 
168
+ ## Engineering standards
169
+
170
+ The [WireCat CLI standards handbook](https://github.com/WireCatLabs/cli-base/blob/main/docs/standards/README.md) in
171
+ cli-base binds every WireCat CLI, and the [messenger rules](docs/dev/STANDARD.md) add what binds tg, max and wa. They
172
+ measure themselves against POSIX, GNU, [Command Line Interface Guidelines](https://clig.dev), the MCP specification
173
+ and JSON Schema 2020-12, and say where they differ on purpose.
174
+
175
+ - **Tests that cannot touch real data.** A sandbox keeps every test away from the owner's store, and no test may
176
+ sleep. The coverage floor is 92% of lines, and at least half of every file.
177
+ - **Checked against the tools that use it.** Every pull request builds tg-cli, max-cli, whatsapp-cli and
178
+ cli-template against the branch. Which checks run on macOS and Windows is in
179
+ [Testing](docs/dev/TESTING.md#platforms).
180
+ - **One shared toolchain.** Biome, markdownlint, CSpell and Lefthook configs come from the
181
+ [WireCat standards](https://github.com/WireCatLabs/community/blob/main/standards/README.md), and CI fails when a
182
+ copy drifts.
183
+
271
184
  ## Development
272
185
 
273
186
  ```sh
@@ -276,9 +189,34 @@ pnpm lint && pnpm typecheck && pnpm test
276
189
  pnpm smoke:bun # the same exports, run under Bun
277
190
  ```
278
191
 
279
- Releases go through `bin/release` from `main`: it refuses a dirty tree, runs every check, publishes to npm and tags
192
+ Releases go through `bin/release` from `main`. It refuses a dirty tree, runs every check, publishes to npm and tags
280
193
  `v<version>`. The steps and the release rules are in [RELEASING.md](docs/dev/RELEASING.md).
281
194
 
195
+ ## Key documents
196
+
197
+ | Document | What it answers |
198
+ |---|---|
199
+ | [Architecture](docs/dev/ARCHITECTURE.md) | The layers, the module map, the store internals and migrations, who consumes what |
200
+ | [Document workflows](docs/dev/DOCUMENTS.md) | Shared file ingestion, sync, scoped knowledge and extraction, and the ports a file provider supplies |
201
+ | [Media archives](docs/dev/MEDIA-ARCHIVE.md) | Independent verified file copies, interruption recovery and opt-in daily timers |
202
+ | [Write an adapter](docs/dev/ADAPTERS.md) | How to add a messenger: the port, the `Messenger` description, the contract cases |
203
+ | [Messenger rules](docs/dev/STANDARD.md) | What binds tg, max and wa beyond the [CLI standards handbook](https://github.com/WireCatLabs/cli-base/blob/main/docs/standards/README.md): parity, the option catalogue, `bot` |
204
+ | [Glossary](docs/dev/GLOSSARY.md) | One word, one meaning across the tools |
205
+ | [Query language](docs/search/query-language.md) · [spec](docs/search/query-language-spec.md) · [Image search](docs/search/images.md) | The search syntax and its exact grammar, and finding pictures by context and by what they show |
206
+ | [Mentions](docs/mentions.md) · [how they work](docs/dev/MENTIONS.md) | Phones, e-mail, links, documents and names found in messages: search, review, rebuild, the tables and the rules |
207
+ | [Storage](docs/storage/README.md) | The schema, the search indexes and the decisions behind them |
208
+ | [Knowledge](docs/dev/KNOWLEDGE.md) · [Meetings](docs/dev/MEETINGS.md) | Labels, links and proposals across sources, the meetings module and its providers |
209
+ | [Testing](docs/dev/TESTING.md) · [Parity audit](docs/dev/PARITY-AUDIT.md) | The sandbox, the coverage floor, the checks across tg and max |
210
+ | [Tool boundaries](docs/dev/TOOL-BOUNDARIES.md) | Which tool owns which command |
211
+ | [API reference](docs/REFERENCE.md) | Every entry point and the detailed contract of each feature |
212
+ | [Roadmap](docs/roadmap.md) | What is being built next for developers on this package |
213
+ | [Changelog](CHANGELOG.md) | What each version changed, and what may break callers |
214
+
215
+ ## History
216
+
217
+ Up to 0.261.0 the package was named `@wirecat/cli-messaging`, which is deprecated. The npm versions 0.0.0-stage, 0.0.0
218
+ and 0.18 to 0.20 of `@wirecat/cli-core` are deprecated too: they are placeholders and the old cli-base.
219
+
282
220
  ## Licence
283
221
 
284
222
  [Apache License 2.0](LICENSE).
@@ -153,5 +153,16 @@ export declare const eventPreparation: (details: EventDetails, options: Preparat
153
153
  } | undefined;
154
154
  ms: number;
155
155
  } | undefined;
156
+ query?: {
157
+ chat?: {
158
+ word: string;
159
+ chat_id: string;
160
+ title: string | null;
161
+ } | undefined;
162
+ respelled?: {
163
+ word: string;
164
+ tried: string[];
165
+ }[] | undefined;
166
+ } | undefined;
156
167
  }, "accounts" | "complete" | "issues" | "truncated">;
157
168
  }>;
@@ -7,7 +7,8 @@ export interface HttpApiRequest {
7
7
  method: string;
8
8
  url: URL;
9
9
  headers: Headers;
10
- body?: string;
10
+ /** JSON text, or an upload's bytes. */
11
+ body?: string | Uint8Array<ArrayBuffer>;
11
12
  /** `manual` for a request whose sign-in header a redirect to another host would carry along. */
12
13
  redirect?: "follow" | "manual" | "error";
13
14
  }
@@ -34,6 +35,8 @@ export interface HttpApiExecutorOptions {
34
35
  failure?: (status: number, answer: unknown, operation: ManifestOperation) => CliError | undefined;
35
36
  maxBytes?: number;
36
37
  }
38
+ /** Why the generated command cannot send the operation's body, or `undefined` when it can: JSON, or an upload's bytes. */
39
+ export declare const unsendableBody: (operation: ManifestOperation) => string | undefined;
37
40
  /** One generated HTTP operation and its flags as the request they stand for; nothing is sent. */
38
41
  export declare const httpApiRequest: (operation: ManifestOperation, input: ApiCommandInput, baseUrl: string) => HttpApiRequest;
39
42
  /** What one exchange needs: the service's name, the fetch, its own refusals and the answer's size limit. */
@@ -3,7 +3,7 @@ import { providerWaitMs, readJsonResponse, statusToCode } from "@wirecat/cli-bas
3
3
  import { providerRequest } from "../command-runs.js";
4
4
  import { outputFor } from "../context.js";
5
5
  import { itemOf, renderAnswer } from "../envelope.js";
6
- import { parseApiJson } from "./api-input.js";
6
+ import { parseApiJson, sendsBytes } from "./api-input.js";
7
7
  const LARGEST_ANSWER = 16 * 1024 * 1024;
8
8
  /** `new URL` folds a `.` or `..` segment into its parent, so such an id would reach another endpoint. */
9
9
  const segment = (name, value) => {
@@ -11,13 +11,20 @@ const segment = (name, value) => {
11
11
  throw new CliError("validation_error", `${name} must name one item; an empty, "." or ".." id is refused`);
12
12
  return encodeURIComponent(value);
13
13
  };
14
+ /** Why the generated command cannot send the operation's body, or `undefined` when it can: JSON, or an upload's bytes. */
15
+ export const unsendableBody = (operation) => {
16
+ const type = operation.request?.contentType;
17
+ return type === undefined || sendsBytes(operation)
18
+ ? undefined
19
+ : `it sends ${type}, which the generated command cannot send`;
20
+ };
14
21
  /** One generated HTTP operation and its flags as the request they stand for; nothing is sent. */
15
22
  export const httpApiRequest = (operation, input, baseUrl) => {
16
23
  const { binding } = operation;
17
24
  if (binding.kind !== "http")
18
25
  throw new CliError("configuration_error", `${operation.command} is not an HTTP operation`);
19
- if (operation.request?.contentType)
20
- throw new CliError("validation_error", `${operation.command} sends ${operation.request.contentType}, which the generated command cannot send; nothing was sent`, { sent: false });
26
+ if (unsendableBody(operation))
27
+ throw new CliError("validation_error", `${operation.command} sends ${operation.request?.contentType}, which the generated command cannot send; nothing was sent`, { sent: false });
21
28
  if (operation.response?.sensitive)
22
29
  throw new CliError("validation_error", `${operation.command} answers with a credential, which the generated command never prints; nothing was sent`, { sent: false });
23
30
  if (Object.keys(input.fields).length > 0)
@@ -36,13 +43,19 @@ export const httpApiRequest = (operation, input, baseUrl) => {
36
43
  url.searchParams.set(name, raw);
37
44
  }
38
45
  const headers = new Headers(input.headers);
46
+ headers.set("accept", "application/json");
47
+ if (sendsBytes(operation)) {
48
+ if (input.bytes === undefined)
49
+ return { method: binding.method, url, headers };
50
+ headers.set("content-type", operation.request?.contentType);
51
+ return { method: binding.method, url, headers, body: input.bytes };
52
+ }
39
53
  const body = input.body?.trim() ? input.body : undefined;
40
54
  // The command's checkBody may not parse the body; text that is not JSON never reaches the service.
41
55
  if (body !== undefined)
42
56
  parseApiJson(body);
43
57
  if (body !== undefined)
44
58
  headers.set("content-type", "application/json");
45
- headers.set("accept", "application/json");
46
59
  return { method: binding.method, url, headers, ...(body === undefined ? {} : { body }) };
47
60
  };
48
61
  /** `/v1/pages/{page_id}` → `/v1/pages/:page_id`: the run record keeps the template, never an id. */
@@ -3,6 +3,10 @@ import * as v from "valibot";
3
3
  export declare const apiFlagOf: (name: string) => string;
4
4
  export declare const apiOptionKey: (name: string) => string;
5
5
  export declare const checkApiParameter: (name: string, node: SchemaNode, raw: string, schemas: Readonly<Record<string, v.GenericSchema>>) => string | undefined;
6
+ /** An upload sent as the bytes themselves, as the spec types a binary body: `application/octet-stream`, `image/png`. */
7
+ export declare const sendsBytes: (operation: ManifestOperation) => boolean;
8
+ /** The file `--body-file` names, `-` for stdin, as the bytes an upload sends. */
9
+ export declare const readApiBytes: (path: string, read?: (path: string | number) => Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
6
10
  export declare const readApiBody: (options: {
7
11
  body?: string;
8
12
  bodyFile?: string;
@@ -55,6 +55,15 @@ export const checkApiParameter = (name, node, raw, schemas) => {
55
55
  return undefined;
56
56
  }
57
57
  };
58
+ const JSON_BODY = /[/+]json\s*(;|$)/i;
59
+ const FORM_BODY = /^(multipart\/form-data|application\/x-www-form-urlencoded)\s*(;|$)/i;
60
+ /** An upload sent as the bytes themselves, as the spec types a binary body: `application/octet-stream`, `image/png`. */
61
+ export const sendsBytes = (operation) => {
62
+ const type = operation.request?.contentType;
63
+ return type !== undefined && !JSON_BODY.test(type) && !FORM_BODY.test(type);
64
+ };
65
+ /** The file `--body-file` names, `-` for stdin, as the bytes an upload sends. */
66
+ export const readApiBytes = (path, read = (from) => new Uint8Array(readFileSync(from))) => read(path === "-" ? 0 : path);
58
67
  export const readApiBody = (options, read = (path) => readFileSync(path, "utf8")) => {
59
68
  if (options.body !== undefined && options.bodyFile !== undefined) {
60
69
  throw new CliError("validation_error", "--body and --body-file both given; pick one");
@@ -6,6 +6,8 @@ export interface ApiCommandInput {
6
6
  headers: Record<string, string>;
7
7
  fields: Record<string, string>;
8
8
  body?: string;
9
+ /** An upload's bytes, from `--body-file`. */
10
+ bytes?: Uint8Array<ArrayBuffer>;
9
11
  bodySource?: "argument" | "stdin" | "file";
10
12
  tokenProfile?: string;
11
13
  }
@@ -19,6 +21,8 @@ export interface ApiCommands {
19
21
  body?: string;
20
22
  bodyFile?: string;
21
23
  }) => string | undefined;
24
+ /** An upload's file, `-` for stdin. */
25
+ readBytes?: (command: Command, path: string) => Uint8Array<ArrayBuffer>;
22
26
  execute: (command: Command, operation: ManifestOperation, input: ApiCommandInput) => Promise<void>;
23
27
  }
24
28
  export declare const generatedApiCommand: (api: ApiCommands) => Command;