@wirecat/cli-core 0.647.0 → 0.649.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 +117 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-remove.d.ts +5 -0
- package/dist/cli/account-remove.js +6 -1
- package/dist/cli/app-doctor-command.js +15 -57
- package/dist/cli/app-store.d.ts +12 -0
- package/dist/cli/app-store.js +25 -0
- package/dist/cli/commands-command.js +10 -3
- package/dist/cli/doctor-reports-command.d.ts +22 -0
- package/dist/cli/doctor-reports-command.js +82 -0
- package/dist/cli/help/command-help.d.ts +1 -0
- package/dist/cli/help/command-help.js +7 -8
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/messenger/doctor-command.js +21 -64
- package/dist/cli/messenger/stats-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +3 -3
- package/dist/cli/messenger/tasks-command.js +1 -3
- package/dist/cli/permission-keys.js +4 -2
- package/dist/cli/program.js +26 -10
- package/dist/cli/settings.d.ts +2 -0
- package/dist/cli/settings.js +3 -2
- package/dist/cli/store-recover.js +2 -2
- package/dist/cli/unknown-profile.d.ts +9 -0
- package/dist/cli/unknown-profile.js +23 -0
- package/dist/crm/cli/search-all.js +4 -4
- package/dist/domain/providers.d.ts +4 -1
- package/dist/domain/providers.js +9 -2
- package/dist/domain/record-types.d.ts +24 -3
- package/dist/domain/record-types.js +23 -2
- package/dist/domain/records-table.js +4 -3
- package/dist/domain/records.d.ts +1 -1
- package/dist/domain/records.js +3 -2
- package/dist/errors/failures.d.ts +2 -0
- package/dist/errors/failures.js +6 -0
- package/dist/errors/reasons.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/kit/index.d.ts +1 -0
- package/dist/kit/index.js +1 -0
- package/dist/kit/own-catalogue.d.ts +7 -0
- package/dist/kit/own-catalogue.js +21 -0
- package/dist/oauth/index.d.ts +2 -2
- package/dist/oauth/index.js +2 -1
- package/dist/oauth/provider.d.ts +4 -0
- package/dist/oauth/provider.js +16 -1
- package/dist/oauth/storage.d.ts +5 -0
- package/dist/oauth/storage.js +20 -0
- package/dist/runs/error-detail.d.ts +1 -1
- package/dist/runs/error-detail.js +5 -2
- package/dist/runs/events.d.ts +1 -1
- package/dist/runs/secrets.d.ts +5 -4
- package/dist/runs/secrets.js +8 -4
- package/dist/sends/permissions.d.ts +2 -0
- package/dist/sends/permissions.js +4 -1
- package/dist/services/document-source.js +9 -1
- package/dist/services/notes-search.d.ts +10 -5
- package/dist/services/notes-search.js +19 -7
- package/dist/services/search-all.js +19 -11
- package/dist/sftp/index.d.ts +1 -0
- package/dist/sftp/index.js +1 -0
- package/dist/sftp/session.d.ts +61 -0
- package/dist/sftp/session.js +230 -0
- package/dist/sftp/ssh2.d.ts +38 -0
- package/dist/sftp/ssh2.js +306 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/sqlite/added-sources.d.ts +38 -0
- package/dist/store/sqlite/added-sources.js +80 -50
- package/dist/store/sqlite/crm-activities.d.ts +2 -0
- package/dist/store/sqlite/crm-activities.js +17 -0
- package/dist/store/sqlite/deals.d.ts +4 -3
- package/dist/store/sqlite/deals.js +8 -2
- package/dist/store/sqlite/open-store.js +14 -1
- package/dist/store/sqlite/record-projectors-document.d.ts +12 -0
- package/dist/store/sqlite/record-projectors-document.js +81 -0
- package/dist/store/sqlite/record-projectors.js +2 -0
- package/package.json +14 -4
- package/parity.json +2 -11
- package/schemas/records-envelope.v1.schema.json +57 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,123 @@ 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.649.0 — 13.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A records envelope carries text search finds: the record type `document`.** Fields `text`, `title`, `created_at`,
|
|
13
|
+
`updated_at`, `url` and `metadata`; relations `about` people, organizations, deals and events (a call, or a meeting's calendar event). It
|
|
14
|
+
becomes a document of the envelope's own account, keyed by the record's external id: the same record again is
|
|
15
|
+
`unchanged`, changed text is the same document's next revision, and a `delete` empties it. Like an SMS or a call, it
|
|
16
|
+
is taken only under an import-only provider. A document's `fields` may take 1 MiB; every other type keeps 64 KiB.
|
|
17
|
+
- **The seeded import-only provider `import`** holds what any other source brings in: `import:crm-notes`,
|
|
18
|
+
`import:obsidian-export`. It holds documents, SMS and calls.
|
|
19
|
+
- **Search reads the documents of import-only accounts under their own name.** An import-only provider (`phone`,
|
|
20
|
+
`import`) holds `documents` beside its other kinds: notes search, `search all` and meaning search read them,
|
|
21
|
+
`--source phone:office-pbx` reads only that account's, and a hit names `phone:office-pbx` with kind `document`.
|
|
22
|
+
The account's SMS and calls stay listed under the same name.
|
|
23
|
+
|
|
24
|
+
### Changed — may break callers
|
|
25
|
+
|
|
26
|
+
- **An import-only provider holds `documents` beside its own kinds.** `kindsIn("phone")` is now
|
|
27
|
+
`["messages", "events", "documents"]`, and `holdsKind(provider, "documents")` is true for `phone` and `import`. So
|
|
28
|
+
`--source documents` reaches their accounts, and `search notes --source phone:<account>` is read where it was refused.
|
|
29
|
+
- **`searchNotesOf(...).accounts` names an import's account by its own key** (`{ provider: "phone", account:
|
|
30
|
+
"office-pbx" }`): its `provider` is a `string`, no longer only `"notes"`. Every import-only account is in the list
|
|
31
|
+
of what an unscoped notes search read, one that holds only SMS and calls included.
|
|
32
|
+
- **`TABLE_RECORD_TYPES` holds `document`**, so a CSV sheet and `records templates` offer it. SMS and calls still
|
|
33
|
+
have no sheet.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- `searchNotesOf` hands its `env` to the search, so meaning search finds the models of the caller's state folder
|
|
38
|
+
instead of the process's.
|
|
39
|
+
|
|
40
|
+
## 0.648.0 — 13.11.2026
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- **`doctorReportsCommand({ app, includes, excludes, example, check, collect })`** builds the
|
|
45
|
+
`doctor reports show|create` group for a CLI that keeps its own `doctor`, so it no longer copies the builder;
|
|
46
|
+
`appDoctorCommand` and `doctorCommand` use it.
|
|
47
|
+
- **`mayRevoke(app, env, keyring?)`** says whether a sign-out may take the sign-in back at the provider. A run with a
|
|
48
|
+
moved config, state or cache folder shares the owner's keyring entry and session, so it must only forget its own
|
|
49
|
+
copy (WC-SECR-24). `account remove` uses it; a CLI's own `session end` calls it before it logs out at the provider.
|
|
50
|
+
- **`commands --json` marks what cli-core mounted, and `ownCatalogue(program, options)` pins only a CLI's own
|
|
51
|
+
commands.** Every command a shared builder made, group or leaf, has `"origin": "cli-core"`; a CLI's own commands keep
|
|
52
|
+
`"handwritten"`. A reader on cli-base below 0.98.0 refuses that value, so a CLI moves to cli-base 0.98.0 with this
|
|
53
|
+
version. `ownCatalogue` from `@wirecat/cli-core/testing` takes the same options as `toolsFromCommands` and
|
|
54
|
+
answers `{ "<path>": "read" | "write" }` for the CLI's own commands only: cli-core pins its own catalogue, so a CLI
|
|
55
|
+
that pins this no longer rewrites its catalogue on every cli-core release. A command a CLI adds with `.command()`
|
|
56
|
+
to a group cli-core built is its own; `customizeSharedCommand` keeps a changed shared command marked.
|
|
57
|
+
- **`openAppStore(env, { app, provider, readOnly })` opens the shared store as gcal, mail and b24 each did in their
|
|
58
|
+
own `store.ts`.** A writable open writes the CLI's provider entry; a read-only one writes nothing and fails on a
|
|
59
|
+
missing file or a needed migration. `registerProvider` is exported from `@wirecat/cli-core/store` too.
|
|
60
|
+
- **`settingsFor` takes `personal` entries: a CLI's own settings that a bot's section refuses.** A CLI that replaced
|
|
61
|
+
the shared schema with `schema` only to keep such a setting out of `bot` extends the shared one instead, and takes
|
|
62
|
+
every shared setting again.
|
|
63
|
+
- **`googleProvider(client, { loginHint })` and `googleTokenCodec` in `@wirecat/cli-core/oauth`.** Google's endpoints
|
|
64
|
+
and the entry that keeps a Desktop client's secret, which gcal, mail and drive each copied.
|
|
65
|
+
- **`e164Of`, `PHONE_COUNTRIES` and `PhoneCountry` are exported from the root entry.** A tool that reads phone numbers
|
|
66
|
+
from a source with a known country (a PBX's call records, a CRM) turns `89161234567` with region `ru` into
|
|
67
|
+
`+79161234567`, the same `phone:` identity the messengers and CRMs give that person. `e164Of(phone, region)` gives
|
|
68
|
+
`null` for a national number when no region is given and nothing for text that is no phone.
|
|
69
|
+
- **`search all` in a CRM CLI finds a deal or lead by the words of its activities.** The subject and text of each
|
|
70
|
+
stored `crm.activity` (a call, e-mail, meeting, to-do or task) count as the deal's words, beside its title,
|
|
71
|
+
company and contacts: `search all warehouse lease` finds the deal whose e-mail spoke of it. A query that names a
|
|
72
|
+
field is still refused for deals, with the reason now naming activities.
|
|
73
|
+
- **`@wirecat/cli-core/sftp`: a read-only SFTP client.** `openSftp({ host, username, auth, hostKey })` lists a
|
|
74
|
+
folder, stats a path and reads a file into memory up to `maxBytes`; it has no method that writes. The server's host
|
|
75
|
+
key must match the pinned `SHA256:` fingerprint before a credential is sent, and `sftpHostKey({ host })` gives the
|
|
76
|
+
fingerprint a sign-in shows the owner to confirm. Each step has a deadline, the run's signal closes the connection,
|
|
77
|
+
a dropped connection or a timeout is tried again over a new one with backoff, and each operation is a request in
|
|
78
|
+
the run's events with its host and never a path. `ssh2` is an optional peer: a CLI that uses SFTP adds it to its
|
|
79
|
+
own dependencies, and bundles it with `cli-dev bundle --external ssh2`. See [SFTP](docs/sftp.md).
|
|
80
|
+
|
|
81
|
+
### Changed — may break callers
|
|
82
|
+
|
|
83
|
+
- **cli-core needs `@wirecat/cli-base` 0.98.0 or later (peer `>=0.98.0 <1.0.0`).** cli-core's types import
|
|
84
|
+
`ListResult` from `@wirecat/cli-base/standards`, which cli-base exports only from 0.97.0 on: a CLI on an older
|
|
85
|
+
cli-base installed without a warning and got `any` for every list result. And `commands --json` now writes
|
|
86
|
+
`"origin": "cli-core"`, which a cli-base reader below 0.98.0 refuses. Bump cli-base with this cli-core.
|
|
87
|
+
- **`store reset` is no longer offered over MCP.** It needs the global `--yes`, which an MCP call cannot pass, so an
|
|
88
|
+
agent saw a write tool that could only fail. MCP catalogue pins lose `store reset`; `store restore` and
|
|
89
|
+
`store recover run` are listed as unavailable until `mcp.authority` is allowed.
|
|
90
|
+
- **Command help shows Returns only from a declared output.** A command without an output schema repeated its
|
|
91
|
+
description as "Returns"; that line is now left out of `--help` and of `commandHelpMarkdown`. A command group that
|
|
92
|
+
also runs on its own, such as `doctor` or `store recover`, now gets Returns, Next usually and an Example like any
|
|
93
|
+
other command. Help snapshots and generated command pages change once.
|
|
94
|
+
- **A mistyped profile is `not_found`, with the profiles here.** A command that fails as "not signed in"
|
|
95
|
+
(`authentication_error` with reason `session.missing`, `oauth.missing` or none) for a first word this computer has
|
|
96
|
+
never seen as a profile now answers `not_found` with reason `profile.unknown` and `details.profiles`; the message
|
|
97
|
+
keeps the sign-in hint for a profile that is new on purpose. A profile set in the environment, a bot and an MCP call
|
|
98
|
+
keep the sign-in refusal.
|
|
99
|
+
- **Unknown commands and options carry a reason.** Commander's usage errors stay `validation_error` with the same
|
|
100
|
+
text, and now give `usage.unknown-command` or `usage.unknown-option`, so a caller matches the reason, not English.
|
|
101
|
+
- **`stats tasks show` has no `--chat` any more: name the chat in the query, `-- chat:"Project room"`.** The query
|
|
102
|
+
already took `chat:` by id or name, so the flag only repeated it, and every messenger CLI had to exempt it from
|
|
103
|
+
the shared `filter-flag` lint rule until 2026-12-01. A CLI drops its `stats tasks show --chat` override when it
|
|
104
|
+
adopts this version.
|
|
105
|
+
|
|
106
|
+
### Fixed
|
|
107
|
+
|
|
108
|
+
- **A store path SQLite cannot open is a configuration error.** A store path that is a folder, or one this user may
|
|
109
|
+
not open, answered `internal_error` "this is a bug"; it now answers `configuration_error` with reason
|
|
110
|
+
`store.unopenable` and the path.
|
|
111
|
+
|
|
112
|
+
### Security
|
|
113
|
+
|
|
114
|
+
- **`doctor reports create --output` never overwrites a file.** It wrote over any existing file, though the command
|
|
115
|
+
promises it destroys nothing; it now refuses one with `validation_error` and the reason `doctor.report-exists`, as
|
|
116
|
+
`store backup` does. In a CLI that names its own permission keys, `doctor reports create` is now checked against
|
|
117
|
+
`doctor.reports.create` (default `ask`), as in a messenger.
|
|
118
|
+
- **Store file commands over MCP ask the owner first.** `store recover run`, which replaces the store file, has the key
|
|
119
|
+
`store.recover.run` (default `ask`; in a messenger `deny messages` still stops it). `store restore` and
|
|
120
|
+
`store recover run` can put older settings back, so they are marked as changing what a later run may do: an MCP
|
|
121
|
+
server offers them only when `mcp.authority` allows it, and the read-only lock refuses them with that reason.
|
|
122
|
+
- **Run records mask a Bitrix24 webhook's secret.** The segment after `/rest/<user id>/` in a URL is masked in kept
|
|
123
|
+
error text and in request endpoints, as a token in a query already was.
|
|
124
|
+
|
|
8
125
|
## 0.647.0 — 12.11.2026
|
|
9
126
|
|
|
10
127
|
### Added
|
|
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
|
|
26
26
|
export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
27
|
-
action?: undefined;
|
|
28
27
|
name: string;
|
|
29
28
|
installed: boolean;
|
|
30
29
|
active: boolean;
|
|
31
30
|
servicePath: string;
|
|
32
31
|
timerPath: string;
|
|
32
|
+
action?: undefined;
|
|
33
33
|
} | {
|
|
34
34
|
active?: undefined;
|
|
35
35
|
name: string;
|
|
@@ -14,6 +14,11 @@ export interface AccountRemovalContext {
|
|
|
14
14
|
*/
|
|
15
15
|
mayRevoke: boolean;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether a sign-out may revoke the sign-in at the provider. A run with moved folders shares the owner's keyring
|
|
19
|
+
* entry and session (WC-SECR-24), so it only forgets its own copy. An injected keyring is a test's own.
|
|
20
|
+
*/
|
|
21
|
+
export declare const mayRevoke: (app: AppIdentity, env: NodeJS.ProcessEnv, keyring?: KeyringStore) => boolean;
|
|
17
22
|
export interface SignedOut {
|
|
18
23
|
/** Whether the provider confirmed it took the sign-in back; `null` when the tool does not revoke. */
|
|
19
24
|
revoked: boolean | null;
|
|
@@ -20,6 +20,11 @@ import { itemOf, renderAnswer } from "./envelope.js";
|
|
|
20
20
|
import { accountFileFor, recalledAccount } from "./messenger/accounts.js";
|
|
21
21
|
import { answerOf } from "./messenger/ask.js";
|
|
22
22
|
import { profileFiles } from "./profile-files.js";
|
|
23
|
+
/**
|
|
24
|
+
* Whether a sign-out may revoke the sign-in at the provider. A run with moved folders shares the owner's keyring
|
|
25
|
+
* entry and session (WC-SECR-24), so it only forgets its own copy. An injected keyring is a test's own.
|
|
26
|
+
*/
|
|
27
|
+
export const mayRevoke = (app, env, keyring) => keyring !== undefined || !isMovedRun({ appName: app.appName, prefix: app.envPrefix, env });
|
|
23
28
|
const choiceOf = ({ keepData, deleteData }) => {
|
|
24
29
|
if (keepData === deleteData)
|
|
25
30
|
throw new CliError("validation_error", keepData
|
|
@@ -121,7 +126,7 @@ export const accountRemoveCommand = (app, removal, options = {}) => logsInOrOut(
|
|
|
121
126
|
const accountFile = accountFileFor(app, profile, env);
|
|
122
127
|
if (!settings.profilesHere.includes(profile) && !existsSync(accountFile))
|
|
123
128
|
throw new CliError("not_found", `no profile ${profile} on this computer — ${settings.profilesHere.join(", ") || "there is none"}`, { reason: "account-remove.unknown-profile", profiles: settings.profilesHere });
|
|
124
|
-
const moved =
|
|
129
|
+
const moved = !mayRevoke(app, env, context.keyring);
|
|
125
130
|
const hooks = {
|
|
126
131
|
env,
|
|
127
132
|
...(context.keyring ? { keyring: context.keyring } : {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { CliError, configFilePath, resolvePaths
|
|
3
|
+
import { CliError, configFilePath, resolvePaths } from "@wirecat/cli-base";
|
|
4
4
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
5
|
import { hostFetch } from "@wirecat/cli-base/http";
|
|
6
6
|
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
@@ -8,17 +8,15 @@ import { clockMeta } from "@wirecat/cli-base/standards";
|
|
|
8
8
|
import { isNewer, latestVersion } from "@wirecat/cli-base/update";
|
|
9
9
|
import { Command } from "commander";
|
|
10
10
|
import { envName, readOnlyLockOf } from "../ports/app.js";
|
|
11
|
-
import { runsDirFor } from "../runs/run.js";
|
|
12
11
|
import { storePath } from "../store/path.js";
|
|
13
12
|
import { environmentOf, inCommandRun, outputFor } from "./context.js";
|
|
13
|
+
import { doctorReportsCommand } from "./doctor-reports-command.js";
|
|
14
14
|
import { DOCTOR_ONLINE_OPTION, DOCTOR_SUMMARY } from "./doctor-text.js";
|
|
15
|
-
import {
|
|
15
|
+
import { REMOTE_READ } from "./effects.js";
|
|
16
16
|
import { itemOf, renderAnswer } from "./envelope.js";
|
|
17
17
|
import { privateFiles } from "./messenger/private-files.js";
|
|
18
|
-
import { buildReport, reportFileName } from "./messenger/report.js";
|
|
19
18
|
import { unknownPermissionIssues } from "./permission-keys.js";
|
|
20
|
-
import { profileFree
|
|
21
|
-
import { lineOf, nextStep } from "./steps.js";
|
|
19
|
+
import { profileFree } from "./profile.js";
|
|
22
20
|
const localCheck = (env, options) => {
|
|
23
21
|
if (!options.local)
|
|
24
22
|
return { fields: {}, notes: [] };
|
|
@@ -178,54 +176,14 @@ const INCLUDES = [
|
|
|
178
176
|
];
|
|
179
177
|
const EXCLUDES = ["what the tool reads or writes", "names", "e-mail addresses", "phone numbers", "the sign-in"];
|
|
180
178
|
/** `doctor reports`: one file for the author, as a messenger's `doctor reports` writes it, without the send journal. */
|
|
181
|
-
const reportsCommand = (app, configuration, options) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
...INCLUDES.map((line) => `- ${line}`),
|
|
193
|
-
"",
|
|
194
|
-
`It never holds: ${EXCLUDES.join(", ")}.`,
|
|
195
|
-
"",
|
|
196
|
-
`Create one: ${create}`,
|
|
197
|
-
`About a given run: ${create} --run <id> (ids: ${lineOf(this, "runs list")})`,
|
|
198
|
-
].join("\n"));
|
|
199
|
-
});
|
|
200
|
-
destroysNothing(annotate(reports.command("create"), {
|
|
201
|
-
effects: LOCAL_WRITE,
|
|
202
|
-
examples: [`${app.command} doctor reports create --output ./problem-report.json`],
|
|
203
|
-
}))
|
|
204
|
-
.description("write a problem report to a file, and say where to send it")
|
|
205
|
-
.summary("the report file written: its path, the run it is about, and where to send it")
|
|
206
|
-
.option("--run <id>", "the run the report is about; the newest failed one if not given")
|
|
207
|
-
.option("--output <file>", "where to write it; a new file in this directory if not given")
|
|
208
|
-
.action(function () {
|
|
209
|
-
const given = this.opts();
|
|
210
|
-
const env = environmentOf(this).env ?? process.env;
|
|
211
|
-
const now = new Date();
|
|
212
|
-
const built = buildReport({
|
|
213
|
-
doctor: appDoctorReport(app, configuration, env, this, options).report,
|
|
214
|
-
runsDir: runsDirFor(app, env),
|
|
215
|
-
command: app.command,
|
|
216
|
-
sends: [],
|
|
217
|
-
now,
|
|
218
|
-
home: env.HOME ?? env.USERPROFILE,
|
|
219
|
-
program: rootOf(this),
|
|
220
|
-
...(given.run === undefined ? {} : { runId: given.run }),
|
|
221
|
-
});
|
|
222
|
-
const path = resolve(given.output ?? reportFileName(app.command, now));
|
|
223
|
-
writeSecurely(path, `${JSON.stringify(built, null, 2)}\n`, 0o600);
|
|
224
|
-
const output = outputFor(this);
|
|
225
|
-
renderAnswer(this, output, itemOf({ path, run: built.run?.metadata.runId ?? null, ...(app.issues ? { send_to: app.issues } : {}) }));
|
|
226
|
-
if (!built.run)
|
|
227
|
-
output.renderer.note("no failed run is recorded — run the failing command again, and the failure is kept by itself");
|
|
228
|
-
output.renderer.note(`read it before sending: ids are labels${app.issues ? ` — attach it to a new issue at ${app.issues}` : ""}`);
|
|
229
|
-
});
|
|
230
|
-
return reports;
|
|
231
|
-
};
|
|
179
|
+
const reportsCommand = (app, configuration, options) => doctorReportsCommand({
|
|
180
|
+
app,
|
|
181
|
+
includes: INCLUDES,
|
|
182
|
+
excludes: EXCLUDES,
|
|
183
|
+
example: app.command,
|
|
184
|
+
check: "ids are labels",
|
|
185
|
+
collect: async (command) => ({
|
|
186
|
+
doctor: appDoctorReport(app, configuration, environmentOf(command).env ?? process.env, command, options).report,
|
|
187
|
+
sends: [],
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProviderEntry } from "../domain/providers.js";
|
|
2
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
+
import type { MessageStore } from "../store/store.js";
|
|
4
|
+
/**
|
|
5
|
+
* The shared store, with the CLI's provider entry written, so every other CLI's search knows it (WC-ARCH-21). A
|
|
6
|
+
* read-only open writes nothing, the entry included, and fails when the file is missing or needs a migration.
|
|
7
|
+
*/
|
|
8
|
+
export declare const openAppStore: (env: NodeJS.ProcessEnv, { app, provider, readOnly, }: {
|
|
9
|
+
app: Pick<AppIdentity, "command" | "version">;
|
|
10
|
+
provider: ProviderEntry;
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
}) => Promise<MessageStore>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared store, with the CLI's provider entry written, so every other CLI's search knows it (WC-ARCH-21). A
|
|
3
|
+
* read-only open writes nothing, the entry included, and fails when the file is missing or needs a migration.
|
|
4
|
+
*/
|
|
5
|
+
export const openAppStore = async (env, { app, provider, readOnly = false, }) => {
|
|
6
|
+
const { ensureSqlite } = await import("../sqlite-runtime.js");
|
|
7
|
+
await ensureSqlite();
|
|
8
|
+
const { openStore, registerProvider, storePath } = await import("../store/index.js");
|
|
9
|
+
const store = await openStore({
|
|
10
|
+
path: storePath(env),
|
|
11
|
+
env,
|
|
12
|
+
command: app.command,
|
|
13
|
+
version: app.version,
|
|
14
|
+
...(readOnly ? { readOnly } : {}),
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
if (!readOnly)
|
|
18
|
+
await registerProvider(store, provider);
|
|
19
|
+
return store;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
await store.close();
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -10,6 +10,7 @@ import { NO_EFFECTS } from "./effects.js";
|
|
|
10
10
|
import { renderDocument } from "./envelope.js";
|
|
11
11
|
import { commandsText } from "./help/commands-text.js";
|
|
12
12
|
import { rootOf } from "./profile.js";
|
|
13
|
+
import { hasSharedContract } from "./shared-contracts.js";
|
|
13
14
|
/**
|
|
14
15
|
* The major version of the JSON every command prints. The output types live in this package, so the
|
|
15
16
|
* contract is this package's: raise it with a major version, when a field is removed or renamed.
|
|
@@ -33,11 +34,17 @@ export const commandsCommand = (app) => {
|
|
|
33
34
|
const root = rootOf(this);
|
|
34
35
|
const output = outputFor(this);
|
|
35
36
|
const available = environmentOf(this).discoveryAvailability;
|
|
36
|
-
const annotateAvailability = (infos) => infos.map((info) => {
|
|
37
|
+
const annotateAvailability = (infos, parent) => infos.map((info) => {
|
|
37
38
|
const availability = available?.(info);
|
|
38
|
-
|
|
39
|
+
const own = parent?.commands.find((child) => child.name() === info.name);
|
|
40
|
+
return {
|
|
41
|
+
...info,
|
|
42
|
+
...(availability ? { availability } : {}),
|
|
43
|
+
...(own && hasSharedContract(own) && info.origin !== "generated" ? { origin: "cli-core" } : {}),
|
|
44
|
+
commands: annotateAvailability(info.commands, own),
|
|
45
|
+
};
|
|
39
46
|
});
|
|
40
|
-
const all = annotateAvailability(describeProgram(root));
|
|
47
|
+
const all = annotateAvailability(describeProgram(root), root);
|
|
41
48
|
const scoped = path.length > 0 ? scopeOf(root, all, path) : undefined;
|
|
42
49
|
const commands = scoped ? [scoped.command] : all;
|
|
43
50
|
const { json, jsonl } = this.optsWithGlobals();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
+
import type { SendEntry } from "../sends/journal.js";
|
|
4
|
+
import { type BaseContext } from "./context.js";
|
|
5
|
+
export interface DoctorReportsSource {
|
|
6
|
+
app: AppIdentity;
|
|
7
|
+
/** What the file holds and never holds, as `doctor reports show` lists it. */
|
|
8
|
+
includes: readonly string[];
|
|
9
|
+
excludes: readonly string[];
|
|
10
|
+
/** The words before `doctor reports create` in its example: `tg personal` for a messenger. */
|
|
11
|
+
example: string;
|
|
12
|
+
/** Said before sending, after "read it before sending: ". */
|
|
13
|
+
check: string;
|
|
14
|
+
/** What `doctor --json` answers, and the newest write attempts; `renderer` when the doctor resolved its own. */
|
|
15
|
+
collect: (command: Command) => Promise<{
|
|
16
|
+
doctor: Record<string, unknown>;
|
|
17
|
+
sends: SendEntry[];
|
|
18
|
+
renderer?: BaseContext["renderer"];
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/** `doctor reports show|create`: one file for the author, the same for every CLI; `collect` says what it holds. */
|
|
22
|
+
export declare const doctorReportsCommand: (source: DoctorReportsSource) => Command;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { CliError } from "@wirecat/cli-base";
|
|
4
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { runsDirFor } from "../runs/run.js";
|
|
7
|
+
import { environmentOf, outputFor } from "./context.js";
|
|
8
|
+
import { destroysNothing, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
|
|
9
|
+
import { itemOf, renderAnswer } from "./envelope.js";
|
|
10
|
+
import { buildReport, reportFileName } from "./messenger/report.js";
|
|
11
|
+
import { lineOf, nextStep, rootOf } from "./steps.js";
|
|
12
|
+
const writeNew = (path, text) => {
|
|
13
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
14
|
+
try {
|
|
15
|
+
writeFileSync(path, text, { mode: 0o600, flag: "wx" });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code !== "EEXIST")
|
|
19
|
+
throw error;
|
|
20
|
+
throw new CliError("validation_error", `${path} exists — a problem report never overwrites a file`, {
|
|
21
|
+
reason: "doctor.report-exists",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** `doctor reports show|create`: one file for the author, the same for every CLI; `collect` says what it holds. */
|
|
26
|
+
export const doctorReportsCommand = (source) => {
|
|
27
|
+
const { app, includes, excludes } = source;
|
|
28
|
+
const reports = annotate(new Command("reports"), { effects: NO_EFFECTS }).description("problem reports");
|
|
29
|
+
annotate(reports.command("show"), {
|
|
30
|
+
effects: NO_EFFECTS,
|
|
31
|
+
examples: [`${app.command} doctor reports show`],
|
|
32
|
+
})
|
|
33
|
+
.description("what a problem report holds; writes nothing")
|
|
34
|
+
.summary("what a report holds and never holds, and where to send it; writes nothing")
|
|
35
|
+
.action(function () {
|
|
36
|
+
const create = lineOf(this, "doctor reports create");
|
|
37
|
+
renderAnswer(this, outputFor(this), itemOf({ includes, excludes, ...(app.issues ? { send_to: app.issues } : {}) }, { next: [nextStep("doctor.report-create", { args: {} })] }), () => [
|
|
38
|
+
`A problem report is one file for the author of ${app.command}.`,
|
|
39
|
+
"",
|
|
40
|
+
"It holds:",
|
|
41
|
+
...includes.map((line) => `- ${line}`),
|
|
42
|
+
"",
|
|
43
|
+
`It never holds: ${excludes.join(", ")}.`,
|
|
44
|
+
"",
|
|
45
|
+
`Create one: ${create}`,
|
|
46
|
+
`About a given run: ${create} --run <id> (ids: ${lineOf(this, "runs list")})`,
|
|
47
|
+
].join("\n"));
|
|
48
|
+
});
|
|
49
|
+
destroysNothing(annotate(reports.command("create"), {
|
|
50
|
+
effects: LOCAL_WRITE,
|
|
51
|
+
examples: [`${source.example} doctor reports create --output ./problem-report.json`],
|
|
52
|
+
}))
|
|
53
|
+
.description("write a problem report to a file, and say where to send it")
|
|
54
|
+
.summary("the report file written: its path, the run it is about, and where to send it")
|
|
55
|
+
.option("--run <id>", "the run the report is about; the newest failed one if not given")
|
|
56
|
+
.option("--output <file>", "where to write it; a new file in this directory if not given")
|
|
57
|
+
.action(async function () {
|
|
58
|
+
const given = this.opts();
|
|
59
|
+
const env = environmentOf(this).env ?? process.env;
|
|
60
|
+
const { doctor, sends, renderer } = await source.collect(this);
|
|
61
|
+
const now = new Date();
|
|
62
|
+
const built = buildReport({
|
|
63
|
+
doctor,
|
|
64
|
+
runsDir: runsDirFor(app, env),
|
|
65
|
+
command: app.command,
|
|
66
|
+
sends,
|
|
67
|
+
now,
|
|
68
|
+
home: env.HOME ?? env.USERPROFILE,
|
|
69
|
+
program: rootOf(this),
|
|
70
|
+
...(given.run === undefined ? {} : { runId: given.run }),
|
|
71
|
+
});
|
|
72
|
+
const path = resolve(given.output ?? reportFileName(app.command, now));
|
|
73
|
+
writeNew(path, `${JSON.stringify(built, null, 2)}\n`);
|
|
74
|
+
const output = outputFor(this);
|
|
75
|
+
const out = renderer ?? output.renderer;
|
|
76
|
+
renderAnswer(this, { ...output, renderer: out }, itemOf({ path, run: built.run?.metadata.runId ?? null, ...(app.issues ? { send_to: app.issues } : {}) }));
|
|
77
|
+
if (!built.run)
|
|
78
|
+
out.note("no failed run is recorded — run the failing command again, and the failure is kept by itself");
|
|
79
|
+
out.note(`read it before sending: ${source.check}${app.issues ? ` — attach it to a new issue at ${app.issues}` : ""}`);
|
|
80
|
+
});
|
|
81
|
+
return reports;
|
|
82
|
+
};
|
|
@@ -10,6 +10,7 @@ export declare const nextUsually: <T extends Command>(command: T, choice: NextCh
|
|
|
10
10
|
/** The profile an example names, so a pasted one runs; the name the first screen's "Start here" uses. */
|
|
11
11
|
export declare const EXAMPLE_PROFILE = "personal";
|
|
12
12
|
export interface CommandHelp {
|
|
13
|
+
/** Empty when the command declares no output entity: its description already says what it does. */
|
|
13
14
|
returns: string;
|
|
14
15
|
next: readonly string[];
|
|
15
16
|
examples: readonly string[];
|
|
@@ -4,7 +4,6 @@ import { commandPathOf, outputOf } from "../command-contract.js";
|
|
|
4
4
|
import { environmentOf } from "../context.js";
|
|
5
5
|
import { takesProfile } from "../profile.js";
|
|
6
6
|
import { commandAt } from "../steps.js";
|
|
7
|
-
import { short } from "./commands-text.js";
|
|
8
7
|
/** Argument names onto the kinds `domain/references.ts` names; a plural takes the same kind. */
|
|
9
8
|
const ARGUMENT_KINDS = {
|
|
10
9
|
chat: "chat",
|
|
@@ -86,11 +85,11 @@ export const nextUsually = (command, choice) => {
|
|
|
86
85
|
return command;
|
|
87
86
|
};
|
|
88
87
|
const kindOfArgument = (argument) => ARGUMENT_KINDS[argument.name()];
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
const runs = (command) => command.commands.length === 0 || Boolean(command._actionHandler);
|
|
89
|
+
/** Every command that runs: the leaves, and a group that also runs on its own, such as `doctor`. */
|
|
91
90
|
const leaves = (command) => command.commands
|
|
92
91
|
.filter((child) => !child._hidden)
|
|
93
|
-
.flatMap((child) =>
|
|
92
|
+
.flatMap((child) => [...(runs(child) ? [child] : []), ...leaves(child)]);
|
|
94
93
|
const rootOf = (command) => {
|
|
95
94
|
let at = command;
|
|
96
95
|
while (at.parent)
|
|
@@ -113,7 +112,7 @@ const returnsOf = (command) => {
|
|
|
113
112
|
const output = metaOf(command).output;
|
|
114
113
|
const { item, coverage } = outputOf(command);
|
|
115
114
|
if (!output || coverage !== "declared-entity")
|
|
116
|
-
return
|
|
115
|
+
return "";
|
|
117
116
|
const fields = [...new Set(fieldsOf(item))];
|
|
118
117
|
const noun = (output.view ? `${output.entity} ${output.view}` : output.entity).replaceAll("_", " ");
|
|
119
118
|
const more = fields.length > 8 ? `, and ${fields.length - 8} more` : "";
|
|
@@ -221,7 +220,7 @@ export const commandHelpText = (command) => {
|
|
|
221
220
|
return [
|
|
222
221
|
"",
|
|
223
222
|
...access,
|
|
224
|
-
...rows("Returns:", [returns]),
|
|
223
|
+
...rows("Returns:", returns ? [returns] : []),
|
|
225
224
|
...rows("Next usually:", next),
|
|
226
225
|
...rows("Example:", examples),
|
|
227
226
|
"",
|
|
@@ -230,12 +229,12 @@ export const commandHelpText = (command) => {
|
|
|
230
229
|
/** The same, as Markdown lines for `docs/commands.md`: hand it to cli-base's `commandsPage` per command. */
|
|
231
230
|
export const commandHelpMarkdown = (root, path) => {
|
|
232
231
|
const command = commandAt(root, path.join(" "));
|
|
233
|
-
if (!command ||
|
|
232
|
+
if (!command || !runs(command))
|
|
234
233
|
return [];
|
|
235
234
|
const { returns, next, examples } = commandHelp(command);
|
|
236
235
|
const code = (values) => values.map((value) => `\`${value}\``).join(", ");
|
|
237
236
|
return [
|
|
238
|
-
`**Returns:** ${returns}
|
|
237
|
+
...(returns ? [`**Returns:** ${returns}`] : []),
|
|
239
238
|
...(next.length > 0 ? [`**Next usually:** ${code(next)}`] : []),
|
|
240
239
|
`**Example:** ${code(examples)}`,
|
|
241
240
|
];
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -45,12 +45,13 @@ export { unanswered } from "../services/questions.js";
|
|
|
45
45
|
export { openRequestTask } from "../services/task-rules.js";
|
|
46
46
|
export { TASK_PAIR_QUERY, TASK_QUERY } from "../services/tasks.js";
|
|
47
47
|
export { answerStdinOption, type Need, type SignInSteps, type SignInStepsOptions, signInSteps, } from "../terminal/sign-in-steps.js";
|
|
48
|
-
export { type AccountRemoval, type AccountRemovalContext, type AccountRemoveOptions, type AccountSecrets, accountRemoveCommand, type SignedOut, } from "./account-remove.js";
|
|
48
|
+
export { type AccountRemoval, type AccountRemovalContext, type AccountRemoveOptions, type AccountSecrets, accountRemoveCommand, mayRevoke, type SignedOut, } from "./account-remove.js";
|
|
49
49
|
export { liftOptionsAfterDashes } from "./after-dashes.js";
|
|
50
50
|
export { type AgentPolicy, type AgentTask, type EvaluationResult, evaluateAgent, type Observation, } from "./agent-evaluation.js";
|
|
51
51
|
export { answerEntity } from "./answer-entity.js";
|
|
52
52
|
export { type AppDoctorOptions, appDoctorReport } from "./app-doctor-command.js";
|
|
53
53
|
export type { AppMcpOptions } from "./app-mcp-command.js";
|
|
54
|
+
export { openAppStore } from "./app-store.js";
|
|
54
55
|
export { actorOf } from "./author.js";
|
|
55
56
|
export { type BaseStagesCommandOptions, baseStagesCommand } from "./base-stages-command.js";
|
|
56
57
|
export type { ApiCommandInput, ApiCommands } from "./bot/api.js";
|
|
@@ -79,6 +80,7 @@ export { csvCell, csvRecords, writeCsv } from "./csv.js";
|
|
|
79
80
|
export { type Closeable, withDeadline } from "./deadline.js";
|
|
80
81
|
export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
|
|
81
82
|
export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
|
|
83
|
+
export { type DoctorReportsSource, doctorReportsCommand } from "./doctor-reports-command.js";
|
|
82
84
|
export { refuseOffline } from "./early-refusal.js";
|
|
83
85
|
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, } from "./effects.js";
|
|
84
86
|
export { type CliEntry, type EntryContext, type EntryIo, openBrowser, startCli } from "./entry.js";
|
package/dist/cli/index.js
CHANGED
|
@@ -40,11 +40,12 @@ export { unanswered } from "../services/questions.js";
|
|
|
40
40
|
export { openRequestTask } from "../services/task-rules.js";
|
|
41
41
|
export { TASK_PAIR_QUERY, TASK_QUERY } from "../services/tasks.js";
|
|
42
42
|
export { answerStdinOption, signInSteps, } from "../terminal/sign-in-steps.js";
|
|
43
|
-
export { accountRemoveCommand, } from "./account-remove.js";
|
|
43
|
+
export { accountRemoveCommand, mayRevoke, } from "./account-remove.js";
|
|
44
44
|
export { liftOptionsAfterDashes } from "./after-dashes.js";
|
|
45
45
|
export { evaluateAgent, } from "./agent-evaluation.js";
|
|
46
46
|
export { answerEntity } from "./answer-entity.js";
|
|
47
47
|
export { appDoctorReport } from "./app-doctor-command.js";
|
|
48
|
+
export { openAppStore } from "./app-store.js";
|
|
48
49
|
export { actorOf } from "./author.js";
|
|
49
50
|
export { baseStagesCommand } from "./base-stages-command.js";
|
|
50
51
|
export { apiFlagOf, apiJson, apiOptionKey, apiPlainJson, checkApiBody, checkApiParameter, parseApiJson, readApiBody, } from "./bot/api-input.js";
|
|
@@ -70,6 +71,7 @@ export { csvCell, csvRecords, writeCsv } from "./csv.js";
|
|
|
70
71
|
export { withDeadline } from "./deadline.js";
|
|
71
72
|
export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
|
|
72
73
|
export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
|
|
74
|
+
export { doctorReportsCommand } from "./doctor-reports-command.js";
|
|
73
75
|
export { refuseOffline } from "./early-refusal.js";
|
|
74
76
|
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, } from "./effects.js";
|
|
75
77
|
export { openBrowser, startCli } from "./entry.js";
|