@wirecat/cli-core 0.644.0 → 0.645.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 +21 -0
- package/dist/cli/app-doctor-command.js +65 -4
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/cli/messenger/archive-commands.js +2 -13
- package/dist/cli/messenger/store-maintenance-command.d.ts +14 -1
- package/dist/cli/messenger/store-maintenance-command.js +83 -51
- package/dist/cli/messenger/store-tables-command.d.ts +5 -2
- package/dist/cli/messenger/store-tables-command.js +5 -5
- package/dist/cli/shared-command-exports.d.ts +1 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/crm/cli/index.js +3 -1
- package/dist/kit/run-scope.js +7 -3
- package/dist/sends/pace.d.ts +2 -0
- package/dist/sends/pace.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ 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.645.0 — 12.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Every CLI on the shared store can back it up, check it and repair it.** `addStoreMaintenanceCommands(store, { app },
|
|
13
|
+
profile)` mounts the store file's commands — `store info`, `check`, `migrate`, `rebuild`, `backup`, `restore`,
|
|
14
|
+
`decrypt`, `repair`, `reset`, `copies delete`, `tables list`, `recover` — on a CLI's own `store` group; they were
|
|
15
|
+
only in a messenger's `storeCommand`. Without a `provider` they say "local store" and nothing about chats.
|
|
16
|
+
`addCrmCommands` mounts them under its `store`, so b24 has them with no change of its own. See
|
|
17
|
+
[REFERENCE.md](docs/REFERENCE.md#the-rule-this-package-keeps).
|
|
18
|
+
- **`doctor reports show|create` in `appDoctorCommand`.** A CLI that is not a messenger writes the same problem report
|
|
19
|
+
as `doctorCommand(messenger)`: what `doctor` answers and the newest failed run (or `--run <id>`), every id a label,
|
|
20
|
+
the home folder as `~`, mode 600; it holds no send journal.
|
|
21
|
+
- **`waitForTurn` takes `longestWaitMs`.** A CLI whose caller is often an agent refuses a long pace wait sooner than
|
|
22
|
+
the five minutes a run sits out: b24 refuses past a minute, so it can use the shared pace instead of its own copy.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **`runScopeCases` counts a command group that has an action of its own**, as `doctor` beside `doctor reports`, so a
|
|
27
|
+
CLI's `doctor` entry in `commands` or `skip` stays valid now that `appDoctorCommand` has subcommands.
|
|
28
|
+
|
|
8
29
|
## 0.644.0 — 12.11.2026
|
|
9
30
|
|
|
10
31
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { CliError, configFilePath, resolvePaths } from "@wirecat/cli-base";
|
|
3
|
+
import { CliError, configFilePath, resolvePaths, writeSecurely } 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,14 +8,17 @@ 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";
|
|
11
12
|
import { storePath } from "../store/path.js";
|
|
12
13
|
import { environmentOf, inCommandRun, outputFor } from "./context.js";
|
|
13
14
|
import { DOCTOR_ONLINE_OPTION, DOCTOR_SUMMARY } from "./doctor-text.js";
|
|
14
|
-
import { REMOTE_READ } from "./effects.js";
|
|
15
|
+
import { destroysNothing, LOCAL_WRITE, NO_EFFECTS, REMOTE_READ } from "./effects.js";
|
|
15
16
|
import { itemOf, renderAnswer } from "./envelope.js";
|
|
16
17
|
import { privateFiles } from "./messenger/private-files.js";
|
|
18
|
+
import { buildReport, reportFileName } from "./messenger/report.js";
|
|
17
19
|
import { unknownPermissionIssues } from "./permission-keys.js";
|
|
18
|
-
import { profileFree } from "./profile.js";
|
|
20
|
+
import { profileFree, rootOf } from "./profile.js";
|
|
21
|
+
import { lineOf, nextStep } from "./steps.js";
|
|
19
22
|
const localCheck = (env, options) => {
|
|
20
23
|
if (!options.local)
|
|
21
24
|
return { fields: {}, notes: [] };
|
|
@@ -165,4 +168,62 @@ export const appDoctorCommand = (app, configuration, options = {}) => profileFre
|
|
|
165
168
|
await inCommandRun(this, answer);
|
|
166
169
|
else
|
|
167
170
|
await answer();
|
|
168
|
-
})
|
|
171
|
+
})
|
|
172
|
+
.addCommand(reportsCommand(app, configuration, options));
|
|
173
|
+
const INCLUDES = [
|
|
174
|
+
"the version, the runtime and the operating system",
|
|
175
|
+
"what `doctor` answers: paths with the home folder shown as ~, the store's path, the config's problems, the locks",
|
|
176
|
+
"the failed run — the newest, or the one named: each request's operation, duration and error code",
|
|
177
|
+
"every id replaced by a label that means nothing outside the file",
|
|
178
|
+
];
|
|
179
|
+
const EXCLUDES = ["what the tool reads or writes", "names", "e-mail addresses", "phone numbers", "the sign-in"];
|
|
180
|
+
/** `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
|
+
const reports = new Command("reports").description("problem reports");
|
|
183
|
+
annotate(reports.command("show"), { effects: NO_EFFECTS, examples: [`${app.command} doctor reports show`] })
|
|
184
|
+
.description("what a problem report holds; writes nothing")
|
|
185
|
+
.action(function () {
|
|
186
|
+
const create = lineOf(this, "doctor reports create");
|
|
187
|
+
renderAnswer(this, outputFor(this), itemOf({ includes: INCLUDES, excludes: EXCLUDES, ...(app.issues ? { send_to: app.issues } : {}) }, { next: [nextStep("doctor.report-create", { args: {} })] }), () => [
|
|
188
|
+
`A problem report is one file for the author of ${app.command}.`,
|
|
189
|
+
"",
|
|
190
|
+
"It holds:",
|
|
191
|
+
...INCLUDES.map((line) => `- ${line}`),
|
|
192
|
+
"",
|
|
193
|
+
`It never holds: ${EXCLUDES.join(", ")}.`,
|
|
194
|
+
"",
|
|
195
|
+
`Create one: ${create}`,
|
|
196
|
+
`About a given run: ${create} --run <id> (ids: ${lineOf(this, "runs list")})`,
|
|
197
|
+
].join("\n"));
|
|
198
|
+
});
|
|
199
|
+
destroysNothing(annotate(reports.command("create"), {
|
|
200
|
+
effects: LOCAL_WRITE,
|
|
201
|
+
examples: [`${app.command} doctor reports create --output ./problem-report.json`],
|
|
202
|
+
}))
|
|
203
|
+
.description("write a problem report to a file, and say where to send it")
|
|
204
|
+
.option("--run <id>", "the run the report is about; the newest failed one if not given")
|
|
205
|
+
.option("--output <file>", "where to write it; a new file in this directory if not given")
|
|
206
|
+
.action(function () {
|
|
207
|
+
const given = this.opts();
|
|
208
|
+
const env = environmentOf(this).env ?? process.env;
|
|
209
|
+
const now = new Date();
|
|
210
|
+
const built = buildReport({
|
|
211
|
+
doctor: appDoctorReport(app, configuration, env, this, options).report,
|
|
212
|
+
runsDir: runsDirFor(app, env),
|
|
213
|
+
command: app.command,
|
|
214
|
+
sends: [],
|
|
215
|
+
now,
|
|
216
|
+
home: env.HOME ?? env.USERPROFILE,
|
|
217
|
+
program: rootOf(this),
|
|
218
|
+
...(given.run === undefined ? {} : { runId: given.run }),
|
|
219
|
+
});
|
|
220
|
+
const path = resolve(given.output ?? reportFileName(app.command, now));
|
|
221
|
+
writeSecurely(path, `${JSON.stringify(built, null, 2)}\n`, 0o600);
|
|
222
|
+
const output = outputFor(this);
|
|
223
|
+
renderAnswer(this, output, itemOf({ path, run: built.run?.metadata.runId ?? null, ...(app.issues ? { send_to: app.issues } : {}) }));
|
|
224
|
+
if (!built.run)
|
|
225
|
+
output.renderer.note("no failed run is recorded — run the failing command again, and the failure is kept by itself");
|
|
226
|
+
output.renderer.note(`read it before sending: ids are labels${app.issues ? ` — attach it to a new issue at ${app.issues}` : ""}`);
|
|
227
|
+
});
|
|
228
|
+
return reports;
|
|
229
|
+
};
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -121,7 +121,7 @@ export { DAY_MS, FIRST_FETCH_MS, type MemberFetches, memberFetches } from "./mes
|
|
|
121
121
|
export { OUTDATED_CHECK_MS, outdatedReason, ownPackageRoot, watchOutdated } from "./messenger/serve-outdated.js";
|
|
122
122
|
export { STEMS_EVERY_MS, STEMS_SLICE_MS, type StemFills, stemFills } from "./messenger/serve-stems.js";
|
|
123
123
|
export type { Running, ServerOptions, ServerProcess, ServerSystem } from "./messenger/server-command.js";
|
|
124
|
-
export { storeSummary } from "./messenger/store-maintenance-command.js";
|
|
124
|
+
export { type StoreOwner, storeSummary } from "./messenger/store-maintenance-command.js";
|
|
125
125
|
export { type Saving, stored } from "./messenger/stored.js";
|
|
126
126
|
export { dateOrNone } from "./messenger/tasks-command.js";
|
|
127
127
|
export { MODEL_CATALOGUE_QUERY, type ModelCatalogueOptions } from "./model-catalogue-command.js";
|
|
@@ -142,7 +142,7 @@ export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults
|
|
|
142
142
|
export { type Config, type Configuration, count, first, flag, fromFile, type GlobalFlags, NONE_NAMED, namedProfile, type ProfileKind, plain, type ResolveOptions, type Settings, type SettingsExtension, type SettingsExtensionContext, type Source, settingsFor, } from "./settings.js";
|
|
143
143
|
export { type PermissionAnswer, readSetupAnswers, type SetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
|
|
144
144
|
export { AGENTS, type Agent, agentFor, screenFor } from "./setup-screen.js";
|
|
145
|
-
export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
|
|
145
|
+
export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, addStoreMaintenanceCommands, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
|
|
146
146
|
export { assertSharedContracts, customizeSharedCommand, hasSharedContract, overrideSharedContract, type SharedContractOverride, sharedContractOverrides, sharedContracts, } from "./shared-contracts.js";
|
|
147
147
|
export { runnable, withSafety } from "./steps.js";
|
|
148
148
|
export { type StoreInfo, sharedStoreCommand, storeInfo, storeInfoCommand } from "./store-info.js";
|
package/dist/cli/index.js
CHANGED
|
@@ -131,7 +131,7 @@ export { settingRows, withSettingDefaults } from "./setting-defaults.js";
|
|
|
131
131
|
export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
|
|
132
132
|
export { readSetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
|
|
133
133
|
export { AGENTS, agentFor, screenFor } from "./setup-screen.js";
|
|
134
|
-
export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
|
|
134
|
+
export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, addStoreMaintenanceCommands, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
|
|
135
135
|
export { assertSharedContracts, customizeSharedCommand, hasSharedContract, overrideSharedContract, sharedContractOverrides, sharedContracts, } from "./shared-contracts.js";
|
|
136
136
|
export { runnable, withSafety } from "./steps.js";
|
|
137
137
|
export { sharedStoreCommand, storeInfo, storeInfoCommand } from "./store-info.js";
|
|
@@ -21,7 +21,7 @@ import { historyLimitGaps } from "./history-gaps.js";
|
|
|
21
21
|
import { messageItems } from "./message-items.js";
|
|
22
22
|
import { ENCRYPT_OPTION, passwordOf } from "./password.js";
|
|
23
23
|
import { storeImportCommand } from "./store-import-command.js";
|
|
24
|
-
import {
|
|
24
|
+
import { addStoreMaintenanceCommands } from "./store-maintenance-command.js";
|
|
25
25
|
/** `store`: the local store of messages — what it holds, filling it, reading it out, and looking after the file. */
|
|
26
26
|
export const storeCommand = (messenger) => {
|
|
27
27
|
const store = new Command("store")
|
|
@@ -33,30 +33,19 @@ export const storeCommand = (messenger) => {
|
|
|
33
33
|
.addCommand(exportCommand(messenger))
|
|
34
34
|
.addCommand(clearCommand(messenger))
|
|
35
35
|
.addCommand(storeImportCommand(messenger));
|
|
36
|
-
|
|
37
|
-
store.addCommand(command);
|
|
36
|
+
addStoreMaintenanceCommands(store, messenger, "personal");
|
|
38
37
|
const examples = {
|
|
39
|
-
backup: "./backup.db",
|
|
40
|
-
check: "",
|
|
41
38
|
"chats status": "",
|
|
42
39
|
clear: "--left --dry-run",
|
|
43
|
-
"copies delete": "messages_copy_1",
|
|
44
|
-
decrypt: "./backup.enc --output ./restored.db",
|
|
45
40
|
export: '"Book club" --output ./messages.jsonl',
|
|
46
41
|
"gaps show": '"Book club"',
|
|
47
42
|
"gaps repair": '"Book club" --limit 100',
|
|
48
43
|
import: "./synthetic-chats.json --yes",
|
|
49
|
-
info: "",
|
|
50
44
|
"jobs cancel": "job-101",
|
|
51
45
|
"jobs clear": "",
|
|
52
46
|
"jobs list": "",
|
|
53
47
|
"jobs retry": "--failed",
|
|
54
48
|
"jobs show": "",
|
|
55
|
-
migrate: "",
|
|
56
|
-
rebuild: "",
|
|
57
|
-
repair: "--dry-run",
|
|
58
|
-
reset: "",
|
|
59
|
-
restore: "./backup.db",
|
|
60
49
|
status: '"Book club"',
|
|
61
50
|
};
|
|
62
51
|
for (const [path, args] of Object.entries(examples)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../../ports/app.js";
|
|
2
3
|
import type { CacheDatabase } from "../../store/driver.js";
|
|
3
4
|
import type { Messenger } from "./context.js";
|
|
4
5
|
/**
|
|
@@ -98,7 +99,19 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
|
|
|
98
99
|
exists: boolean;
|
|
99
100
|
error: string;
|
|
100
101
|
}>;
|
|
101
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Who mounts the store file's commands: a messenger, or any CLI on the shared store. Without a `provider` nothing is
|
|
104
|
+
* said about chats.
|
|
105
|
+
*/
|
|
106
|
+
export type StoreOwner = {
|
|
107
|
+
app: AppIdentity;
|
|
108
|
+
} & Partial<Pick<Messenger, "provider" | "history" | "historyOnDemand">>;
|
|
109
|
+
export declare const storeMaintenanceCommands: (owner: StoreOwner) => Command[];
|
|
110
|
+
/**
|
|
111
|
+
* Mounts the store file's commands — `store info`, `check`, `backup`, `restore`, `repair` and the rest — on a CLI's
|
|
112
|
+
* `store` group, with examples under `profile`. Every WireCat tool shares the one file, so any of them looks after it.
|
|
113
|
+
*/
|
|
114
|
+
export declare const addStoreMaintenanceCommands: (store: Command, owner: StoreOwner, profile: string) => Command;
|
|
102
115
|
/**
|
|
103
116
|
* Stems what is left, after rebuilding stems made by other stemmer choices than the store's setting —
|
|
104
117
|
* only here and in `store rebuild`, never in a search's quick fill.
|
|
@@ -20,7 +20,7 @@ import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, invol
|
|
|
20
20
|
import { environmentOf, outputFor } from "../context.js";
|
|
21
21
|
import { destroysNothing, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
22
22
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
23
|
-
import { lineOf, nextStep } from "../steps.js";
|
|
23
|
+
import { commandAt, lineOf, nextStep } from "../steps.js";
|
|
24
24
|
import { storeInfoCommand } from "../store-info.js";
|
|
25
25
|
import { storeRecoverCommand } from "../store-recover.js";
|
|
26
26
|
import { answerOf } from "./ask.js";
|
|
@@ -134,28 +134,60 @@ export const storeSummary = async (env, { deep = false, command, version } = {})
|
|
|
134
134
|
};
|
|
135
135
|
/** A maintenance answer: one item, snake_case, its hints as steps where a registered one fits. */
|
|
136
136
|
const result = (command, value, next = []) => renderAnswer(command, outputFor(command), itemOf(snakeKeys(value), { next }));
|
|
137
|
-
|
|
137
|
+
/** Whether the owner is a messenger, whose words are chats and an archive. */
|
|
138
|
+
const chatty = (owner) => owner.provider !== undefined;
|
|
139
|
+
const archive = (owner) => (chatty(owner) ? "local archive" : "local store");
|
|
140
|
+
const createdBy = (owner) => chatty(owner)
|
|
141
|
+
? `the first \`${owner.app.command}\` command that reads a chat creates it`
|
|
142
|
+
: `the first \`${owner.app.command}\` command that saves anything creates it`;
|
|
143
|
+
export const storeMaintenanceCommands = (owner) => [
|
|
138
144
|
storeInfoCommand(),
|
|
139
|
-
checkCommand(
|
|
140
|
-
migrateCommand(
|
|
141
|
-
reindexCommand(
|
|
145
|
+
checkCommand(owner),
|
|
146
|
+
migrateCommand(owner),
|
|
147
|
+
reindexCommand(owner),
|
|
142
148
|
backupCommand(),
|
|
143
|
-
restoreCommand(
|
|
149
|
+
restoreCommand(owner),
|
|
144
150
|
decryptCommand(),
|
|
145
|
-
repairCommand(
|
|
146
|
-
resetCommand(
|
|
151
|
+
repairCommand(owner),
|
|
152
|
+
resetCommand(owner),
|
|
147
153
|
copiesCommand(),
|
|
148
|
-
storeTablesCommand(
|
|
149
|
-
storeRecoverCommand({ command:
|
|
154
|
+
storeTablesCommand(owner),
|
|
155
|
+
storeRecoverCommand({ command: owner.app.command, version: owner.app.version }),
|
|
150
156
|
];
|
|
157
|
+
const EXAMPLES = {
|
|
158
|
+
backup: "./backup.db",
|
|
159
|
+
check: "",
|
|
160
|
+
"copies delete": "messages_copy_1",
|
|
161
|
+
decrypt: "./backup.enc --output ./restored.db",
|
|
162
|
+
info: "",
|
|
163
|
+
migrate: "",
|
|
164
|
+
rebuild: "",
|
|
165
|
+
repair: "--dry-run",
|
|
166
|
+
reset: "",
|
|
167
|
+
restore: "./backup.db",
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Mounts the store file's commands — `store info`, `check`, `backup`, `restore`, `repair` and the rest — on a CLI's
|
|
171
|
+
* `store` group, with examples under `profile`. Every WireCat tool shares the one file, so any of them looks after it.
|
|
172
|
+
*/
|
|
173
|
+
export const addStoreMaintenanceCommands = (store, owner, profile) => {
|
|
174
|
+
for (const command of storeMaintenanceCommands(owner))
|
|
175
|
+
store.addCommand(command);
|
|
176
|
+
for (const [path, args] of Object.entries(EXAMPLES)) {
|
|
177
|
+
const command = commandAt(store, path);
|
|
178
|
+
if (command)
|
|
179
|
+
annotate(command, { examples: [`${owner.app.command} ${profile} store ${path} ${args}`.trimEnd()] });
|
|
180
|
+
}
|
|
181
|
+
return store;
|
|
182
|
+
};
|
|
151
183
|
/** Renaming tables under a running `serve` would pull them from under its statements. */
|
|
152
|
-
const refuseWhileServing = (command,
|
|
153
|
-
const serving = servingProfiles(
|
|
184
|
+
const refuseWhileServing = (command, owner) => {
|
|
185
|
+
const serving = servingProfiles(owner.app, environmentOf(command).env ?? process.env);
|
|
154
186
|
if (serving.length > 0) {
|
|
155
|
-
throw new CliError("validation_error", `${
|
|
187
|
+
throw new CliError("validation_error", `${owner.app.command} serve is running for ${serving.join(", ")} — ${serving.map((profile) => `\`${owner.app.command} ${profile} server stop\``).join(", ")} first`);
|
|
156
188
|
}
|
|
157
189
|
};
|
|
158
|
-
const repairCommand = (
|
|
190
|
+
const repairCommand = (owner) => annotate(new Command("repair"), { output: { entity: "store_repair" }, effects: LOCAL_WRITE })
|
|
159
191
|
.summary("repair table shapes while keeping the old tables")
|
|
160
192
|
.description("bring every table to this build's shape, deleting nothing: a table of the wrong shape is kept as a copy beside a new one")
|
|
161
193
|
.option("--dry-run", "say what it would do, and change nothing")
|
|
@@ -168,13 +200,13 @@ const repairCommand = (messenger) => annotate(new Command("repair"), { output: {
|
|
|
168
200
|
return;
|
|
169
201
|
}
|
|
170
202
|
if (!dryRun)
|
|
171
|
-
refuseWhileServing(this,
|
|
203
|
+
refuseWhileServing(this, owner);
|
|
172
204
|
const fresh = await openCache(":memory:");
|
|
173
205
|
try {
|
|
174
206
|
const report = await reading(path, (database) => repairStore(database, fresh, { dryRun: dryRun === true }));
|
|
175
207
|
result(this, { path, ...report });
|
|
176
208
|
if (format === "pretty")
|
|
177
|
-
for (const note of notesOf(report,
|
|
209
|
+
for (const note of notesOf(report, owner.app.command))
|
|
178
210
|
renderer.note(note);
|
|
179
211
|
}
|
|
180
212
|
finally {
|
|
@@ -220,9 +252,9 @@ const copiesCommand = () => new Command("copies").description("the tables `store
|
|
|
220
252
|
* fetched" (NEED-399 A). Times are the chat's newest message by the messenger's list against the
|
|
221
253
|
* newest message held, not `sync_ranges`: those are in message ids, which a chat list does not give.
|
|
222
254
|
*/
|
|
223
|
-
const checkCommand = (
|
|
224
|
-
.summary(
|
|
225
|
-
.description(
|
|
255
|
+
const checkCommand = (owner) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ })
|
|
256
|
+
.summary(`check the ${archive(owner)} for problems`)
|
|
257
|
+
.description(`whether the store is healthy — integrity, search indexes, disk${chatty(owner) ? ", and which chats are behind" : ""}`)
|
|
226
258
|
.action(async function () {
|
|
227
259
|
const { renderer } = outputFor(this);
|
|
228
260
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
@@ -238,7 +270,7 @@ const checkCommand = (messenger) => annotate(new Command("check"), { output: { e
|
|
|
238
270
|
result(this, { path, exists: true, ok: false, opens: false, error: messageOf(error) });
|
|
239
271
|
return;
|
|
240
272
|
}
|
|
241
|
-
const { command } =
|
|
273
|
+
const { command } = owner.app;
|
|
242
274
|
const next = new Map();
|
|
243
275
|
const step = (id, args = {}) => {
|
|
244
276
|
if (!next.has(id))
|
|
@@ -254,10 +286,10 @@ const checkCommand = (messenger) => annotate(new Command("check"), { output: { e
|
|
|
254
286
|
step("store.reindex");
|
|
255
287
|
else if (stems && !stems.ready)
|
|
256
288
|
step("store.migrate");
|
|
257
|
-
const behind = answer.chatsBehind.find((chat) => chat.provider ===
|
|
258
|
-
if (behind &&
|
|
289
|
+
const behind = answer.chatsBehind.find((chat) => chat.provider === owner.provider);
|
|
290
|
+
if (behind && owner.history !== "store")
|
|
259
291
|
step("messages.sync");
|
|
260
|
-
else if (behind && syncsOneChat(
|
|
292
|
+
else if (behind && syncsOneChat(owner))
|
|
261
293
|
step("messages.sync", { chat: behind.chat });
|
|
262
294
|
result(this, answer, [...next.values()]);
|
|
263
295
|
if (answer.schema.version < SPEAKS) {
|
|
@@ -275,7 +307,7 @@ const checkCommand = (messenger) => annotate(new Command("check"), { output: { e
|
|
|
275
307
|
renderer.note(`${orphans} pointers name a row that is gone or a type the store does not know — see orphan_pointers`);
|
|
276
308
|
if (answer.vectors && answer.vectors.unused > 0)
|
|
277
309
|
renderer.note(`${answer.vectors.unused} vectors belong to no text the store still holds — \`${command} store rebuild\` drops them`);
|
|
278
|
-
const older = answer.conversations.filter((chat) => chat.provider ===
|
|
310
|
+
const older = answer.conversations.filter((chat) => chat.provider === owner.provider && !chat.current).length;
|
|
279
311
|
if (older > 0) {
|
|
280
312
|
renderer.note(`${older} chats' conversations were built by older rules — \`${command} conversations links rebuild --chat <chat>\``);
|
|
281
313
|
}
|
|
@@ -405,22 +437,22 @@ const chatsBehind = (database) => database
|
|
|
405
437
|
held: row.held === null ? null : isoOf(row.held),
|
|
406
438
|
refreshed: isoOf(row.refreshed),
|
|
407
439
|
}));
|
|
408
|
-
const migrateCommand = (
|
|
409
|
-
.summary(
|
|
440
|
+
const migrateCommand = (owner) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE })
|
|
441
|
+
.summary(`migrate an older ${archive(owner)}`)
|
|
410
442
|
.description("bring the store up to this build's schema, then normalize, index and stem the messages and notes stored before it")
|
|
411
443
|
.action(async function () {
|
|
412
444
|
const { renderer } = outputFor(this);
|
|
413
445
|
const path = storePath(environmentOf(this).env ?? process.env);
|
|
414
446
|
if (!existsSync(path)) {
|
|
415
447
|
result(this, { path, exists: false });
|
|
416
|
-
renderer.note(`no store yet —
|
|
448
|
+
renderer.note(`no store yet — ${createdBy(owner)}`);
|
|
417
449
|
return;
|
|
418
450
|
}
|
|
419
451
|
const answer = await reading(path, (database) => {
|
|
420
452
|
const from = schemaOf(database).version;
|
|
421
453
|
migrate(database, {
|
|
422
|
-
command:
|
|
423
|
-
version:
|
|
454
|
+
command: owner.app.command,
|
|
455
|
+
version: owner.app.version,
|
|
424
456
|
rollback: { store: path, warn: (line) => renderer.warn(line) },
|
|
425
457
|
});
|
|
426
458
|
const { normalized, indexed, terms } = buildWordIndex(database, (note) => renderer.note(note));
|
|
@@ -478,8 +510,8 @@ const buildNoteIndex = (database, note, { reset = false } = {}) => {
|
|
|
478
510
|
note(`indexing ${pending} notes`);
|
|
479
511
|
return { notesIndexed: drainNoteIndex(database, stemmerCache()) };
|
|
480
512
|
};
|
|
481
|
-
const reindexCommand = (
|
|
482
|
-
.summary(
|
|
513
|
+
const reindexCommand = (owner) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE }))
|
|
514
|
+
.summary(`rebuild the ${archive(owner)}'s search indexes`)
|
|
483
515
|
.description("rebuild the word index, its typo vocabulary, the stems, the files' word index, the notes' indexes and who took part in what, from what is stored, and drop the vectors no stored text uses; loses nothing")
|
|
484
516
|
.action(async function () {
|
|
485
517
|
const { renderer } = outputFor(this);
|
|
@@ -595,7 +627,7 @@ const decryptCommand = () => annotate(new Command("decrypt"), { output: { entity
|
|
|
595
627
|
* process has the file open — it would go on writing to the file set aside — or while this CLI's
|
|
596
628
|
* `serve` runs: that opens the store on its first write, so until then it holds nothing to see.
|
|
597
629
|
*/
|
|
598
|
-
const restoreCommand = (
|
|
630
|
+
const restoreCommand = (owner) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE })
|
|
599
631
|
.summary("restore a backup and keep the current store, or roll back a breaking upgrade")
|
|
600
632
|
.description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback " +
|
|
601
633
|
"copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools " +
|
|
@@ -606,33 +638,33 @@ const restoreCommand = (messenger) => annotate(new Command("restore"), { output:
|
|
|
606
638
|
const given = resolve(file);
|
|
607
639
|
if (!existsSync(given))
|
|
608
640
|
throw new CliError("not_found", `no file at ${given}`);
|
|
609
|
-
refuseWhileServing(this,
|
|
641
|
+
refuseWhileServing(this, owner);
|
|
610
642
|
if (!isSealed(given))
|
|
611
|
-
return restoreFrom(this,
|
|
643
|
+
return restoreFrom(this, owner, given, given);
|
|
612
644
|
const opened = `${path}.unsealing-${process.pid}`;
|
|
613
645
|
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
614
646
|
try {
|
|
615
647
|
await unsealFile(given, opened, await passwordOf(this, { twice: false }));
|
|
616
|
-
await restoreFrom(this,
|
|
648
|
+
await restoreFrom(this, owner, opened, given);
|
|
617
649
|
}
|
|
618
650
|
finally {
|
|
619
651
|
rmSync(opened, { force: true });
|
|
620
652
|
}
|
|
621
653
|
});
|
|
622
|
-
const restoreFrom = async (command,
|
|
654
|
+
const restoreFrom = async (command, owner, backup, given) => {
|
|
623
655
|
const { renderer } = outputFor(command);
|
|
624
656
|
const path = storePath(environmentOf(command).env ?? process.env);
|
|
625
657
|
if (existsSync(path) && realpathSync(backup) === realpathSync(path)) {
|
|
626
658
|
throw new CliError("validation_error", `${backup} is the store itself`);
|
|
627
659
|
}
|
|
628
660
|
if (await isRollbackCopy(backup))
|
|
629
|
-
return rollBackFrom(command,
|
|
661
|
+
return rollBackFrom(command, owner, backup);
|
|
630
662
|
const schema = await backupSchema(backup);
|
|
631
663
|
const stamp = stampNow();
|
|
632
664
|
const kept = existsSync(path) ? `${path}.before-restore-${stamp}` : null;
|
|
633
665
|
if (kept) {
|
|
634
666
|
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
635
|
-
await quiesce(path,
|
|
667
|
+
await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
|
|
636
668
|
}
|
|
637
669
|
else
|
|
638
670
|
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
@@ -664,13 +696,13 @@ const isRollbackCopy = async (file) => {
|
|
|
664
696
|
}
|
|
665
697
|
};
|
|
666
698
|
/** In place, in one transaction: the copy holds only the tables the upgrade changed, never a whole store. */
|
|
667
|
-
const rollBackFrom = async (command,
|
|
699
|
+
const rollBackFrom = async (command, owner, copy) => {
|
|
668
700
|
const { renderer } = outputFor(command);
|
|
669
701
|
const path = storePath(environmentOf(command).env ?? process.env);
|
|
670
702
|
if (!existsSync(path))
|
|
671
703
|
throw new CliError("not_found", `no store at ${path} to roll back`);
|
|
672
704
|
const waitMs = environmentOf(command).storeLockWaitMs;
|
|
673
|
-
await quiesce(path,
|
|
705
|
+
await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
|
|
674
706
|
const { database } = await openSqlite(path);
|
|
675
707
|
let rolled;
|
|
676
708
|
try {
|
|
@@ -724,8 +756,8 @@ const STORE_LOCK_WAIT_MS = 1_000;
|
|
|
724
756
|
* so the file set aside is whole on its own. In WAL mode SQLite cannot say who has the file open —
|
|
725
757
|
* `EXCLUSIVE` behaves as `IMMEDIATE` — so that is asked of the system.
|
|
726
758
|
*/
|
|
727
|
-
const quiesce = async (path,
|
|
728
|
-
const { command } =
|
|
759
|
+
const quiesce = async (path, owner, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
|
|
760
|
+
const { command } = owner.app;
|
|
729
761
|
const files = [path, `${path}-wal`, `${path}-shm`]
|
|
730
762
|
.filter((file) => existsSync(file))
|
|
731
763
|
.map((file) => realpathSync(file));
|
|
@@ -759,26 +791,26 @@ const quiesce = async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS)
|
|
|
759
791
|
* the delete. A new file rather than `DELETE FROM` every table: deleted rows would stay readable in free
|
|
760
792
|
* pages until a VACUUM, and every table comes back in this build's shape.
|
|
761
793
|
*/
|
|
762
|
-
const resetCommand = (
|
|
763
|
-
.summary(
|
|
794
|
+
const resetCommand = (owner) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE })
|
|
795
|
+
.summary(`back up the ${archive(owner)} and replace it with an empty one`)
|
|
764
796
|
.description("back the store up beside itself, then delete it and start an empty one at this build's schema; asks first, or --yes")
|
|
765
797
|
.option("--no-backup", "delete the store without backing it up first")
|
|
766
798
|
.option("--dry-run", "list every table it would empty, with its rows, and delete nothing")
|
|
767
799
|
.action(async function ({ backup: keep, dryRun }) {
|
|
768
800
|
const { renderer } = outputFor(this);
|
|
769
|
-
const { command } =
|
|
801
|
+
const { command } = owner.app;
|
|
770
802
|
const env = environmentOf(this).env ?? process.env;
|
|
771
803
|
const path = storePath(env);
|
|
772
804
|
if (!existsSync(path)) {
|
|
773
805
|
result(this, { path, exists: false, reset: false });
|
|
774
|
-
renderer.note(`no store at ${path} — nothing to reset;
|
|
806
|
+
renderer.note(`no store at ${path} — nothing to reset; ${createdBy(owner)}`);
|
|
775
807
|
return;
|
|
776
808
|
}
|
|
777
809
|
if (dryRun) {
|
|
778
|
-
result(this, await resetPreview(path,
|
|
810
|
+
result(this, await resetPreview(path, owner, env, keep));
|
|
779
811
|
return;
|
|
780
812
|
}
|
|
781
|
-
refuseWhileServing(this,
|
|
813
|
+
refuseWhileServing(this, owner);
|
|
782
814
|
if (this.optsWithGlobals().yes !== true) {
|
|
783
815
|
const what = `this deletes the store at ${path} and starts an empty one, ${keep ? "after a backup beside it" : "with no backup"}`;
|
|
784
816
|
const answer = await answerOf(this, `${what}. Go ahead? [y/N] `);
|
|
@@ -787,7 +819,7 @@ const resetCommand = (messenger) => annotate(new Command("reset"), { output: { e
|
|
|
787
819
|
if (!/^\s*y(es)?\s*$/i.test(answer))
|
|
788
820
|
throw new CliError("cancelled", "cancelled — the store is unchanged");
|
|
789
821
|
}
|
|
790
|
-
await quiesce(path,
|
|
822
|
+
await quiesce(path, owner, "reset", (message) => renderer.warn(message), environmentOf(this).storeLockWaitMs);
|
|
791
823
|
const backup = keep ? `${path}.backup-${stampNow()}` : null;
|
|
792
824
|
let backedUp = null;
|
|
793
825
|
if (backup) {
|
|
@@ -820,10 +852,10 @@ const STORE_PARTS = ["", "-wal", "-shm"];
|
|
|
820
852
|
* What a reset would delete, read without a write lock so it answers while a sync runs. `in_use` is what the
|
|
821
853
|
* real run would refuse over now; `null` where this system cannot say who has the file open.
|
|
822
854
|
*/
|
|
823
|
-
const resetPreview = async (path,
|
|
855
|
+
const resetPreview = async (path, owner, env, keep) => {
|
|
824
856
|
const files = STORE_PARTS.map((suffix) => `${path}${suffix}`).filter((file) => existsSync(file));
|
|
825
857
|
const holders = holdersOf(files.map((file) => realpathSync(file)));
|
|
826
|
-
const serving = servingProfiles(
|
|
858
|
+
const serving = servingProfiles(owner.app, env).length > 0;
|
|
827
859
|
const read = await readingOnly(path, (database) => ({
|
|
828
860
|
schema: schemaOf(database).version,
|
|
829
861
|
tables: emptiedTables(database),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type QueryRegistry } from "@wirecat/cli-base/query";
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import type { Messenger } from "./context.js";
|
|
4
3
|
export declare const STORE_TABLES_QUERY: QueryRegistry;
|
|
5
|
-
export declare const storeTablesCommand: (
|
|
4
|
+
export declare const storeTablesCommand: (owner: {
|
|
5
|
+
app: {
|
|
6
|
+
command: string;
|
|
7
|
+
};
|
|
8
|
+
}) => Command;
|
|
@@ -27,14 +27,14 @@ const filterOf = (words) => {
|
|
|
27
27
|
const kind = terms.get("kind");
|
|
28
28
|
return { ...(name === undefined ? {} : { name }), ...(kind === undefined ? {} : { kind }) };
|
|
29
29
|
};
|
|
30
|
-
export const storeTablesCommand = (
|
|
31
|
-
const tables = new Command("tables").description("the tables of the local
|
|
30
|
+
export const storeTablesCommand = (owner) => {
|
|
31
|
+
const tables = new Command("tables").description("the tables of the local store");
|
|
32
32
|
withQuery(annotate(tables.command("list"), {
|
|
33
33
|
effects: LOCAL_READ,
|
|
34
34
|
examples: [
|
|
35
|
-
`${
|
|
36
|
-
`${
|
|
37
|
-
`${
|
|
35
|
+
`${owner.app.command} store tables list`,
|
|
36
|
+
`${owner.app.command} store tables list kind:data`,
|
|
37
|
+
`${owner.app.command} store tables list --full --json`,
|
|
38
38
|
],
|
|
39
39
|
}), STORE_TABLES_QUERY)
|
|
40
40
|
.summary("every table of the local archive, with its kind and row count")
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const addStoreMaintenanceCommands: (store: import("commander").Command, owner: import("./messenger/store-maintenance-command.js").StoreOwner, profile: string) => import("commander").Command;
|
|
1
2
|
export declare const appDoctorCommand: (app: import("./entry.js").AppIdentity, configuration: {
|
|
2
3
|
resolveSettings: (flags?: import("./settings.js").GlobalFlags, options?: import("./settings.js").ResolveOptions) => import("./settings.js").Settings & object;
|
|
3
4
|
configuredProfiles: (options?: import("./settings.js").ResolveOptions) => string[];
|
|
@@ -48,6 +48,7 @@ import { searchesCommand as searchesCommandDefinition } from "./messenger/search
|
|
|
48
48
|
import { serveCommand as serveCommandDefinition } from "./messenger/serve-command.js";
|
|
49
49
|
import { serverCommand as serverCommandDefinition } from "./messenger/server-command.js";
|
|
50
50
|
import { statsCommand as statsCommandDefinition } from "./messenger/stats-command.js";
|
|
51
|
+
import { addStoreMaintenanceCommands as addStoreMaintenanceCommandsDefinition } from "./messenger/store-maintenance-command.js";
|
|
51
52
|
import { tagsCommand as tagsCommandDefinition } from "./messenger/tags-command.js";
|
|
52
53
|
import { tasksCommand as tasksCommandDefinition, tasksStatsCommand as tasksStatsCommandDefinition, } from "./messenger/tasks-command.js";
|
|
53
54
|
import { topicsCommand as topicsCommandDefinition } from "./messenger/topics-command.js";
|
|
@@ -58,6 +59,7 @@ import { sharedCommand as protectedCommand } from "./shared-contracts.js";
|
|
|
58
59
|
import { skillCommand as skillCommandDefinition } from "./skill-command.js";
|
|
59
60
|
import { upgradeCommand as upgradeCommandDefinition } from "./upgrade-command.js";
|
|
60
61
|
const sharedCommand = (factory) => honoursDryRun(protectedCommand(factory));
|
|
62
|
+
export const addStoreMaintenanceCommands = sharedCommand(addStoreMaintenanceCommandsDefinition);
|
|
61
63
|
export const appDoctorCommand = sharedCommand(appDoctorCommandDefinition);
|
|
62
64
|
export const appCompleteCommand = sharedCommand(appCompleteCommandDefinition);
|
|
63
65
|
export const appMcpCommand = sharedCommand(appMcpCommandDefinition);
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { FETCH, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS, REMOTE_WRITE } from "../../
|
|
|
9
9
|
import { itemOf, listOf, renderAnswer, snakeKeys, snakeKeysKeeping } from "../../cli/envelope.js";
|
|
10
10
|
import { queryTerms, termField, unfilteredQuery, withQuery } from "../../cli/list-query.js";
|
|
11
11
|
import { terminalAsker } from "../../cli/messenger/ask.js";
|
|
12
|
+
import { addStoreMaintenanceCommands } from "../../cli/messenger/store-maintenance-command.js";
|
|
12
13
|
import { lineOf } from "../../cli/steps.js";
|
|
13
14
|
import { CRM_KINDS } from "../../domain/crm.js";
|
|
14
15
|
import { DEAL_KINDS, DEAL_STATUSES } from "../../domain/deals.js";
|
|
@@ -254,7 +255,7 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
254
255
|
});
|
|
255
256
|
});
|
|
256
257
|
});
|
|
257
|
-
const store = annotate(program.command("store").description("the local copy of the CRM"), { effects: NO_EFFECTS });
|
|
258
|
+
const store = annotate(program.command("store").description("the local copy of the CRM, and the shared store file it lives in"), { effects: NO_EFFECTS });
|
|
258
259
|
example(answerEntity(annotate(store.command("status"), { effects: LOCAL_READ }), "crm_sync_progress", crmSyncProgress).description("how far each kind's sync is: rows saved, partial or complete, when it last moved, how many are stored"), "store status --json").action(async (_opts, command) => {
|
|
259
260
|
await within(command, async (run) => {
|
|
260
261
|
const status = await crmStatus(run.store, run.account, { profile: run.profile, now: now() });
|
|
@@ -278,6 +279,7 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
278
279
|
return itemOf(snakeKeys({ ...removed, applied: yes }));
|
|
279
280
|
});
|
|
280
281
|
});
|
|
282
|
+
addStoreMaintenanceCommands(store, { app: options.app }, "work");
|
|
281
283
|
const items = (kind) => {
|
|
282
284
|
const plural = `${kind}s`;
|
|
283
285
|
const query = kind === "deal" ? DEALS_QUERY : LEADS_QUERY;
|
package/dist/kit/run-scope.js
CHANGED
|
@@ -8,13 +8,17 @@ import { findRun, runsDirFor } from "../runs/run.js";
|
|
|
8
8
|
/** A `fetch` that never settles, not even on abort: only the run's own deadline can end the command. */
|
|
9
9
|
export const neverAnswers = (() => new Promise(() => { }));
|
|
10
10
|
const GRACE_MS = 2000;
|
|
11
|
+
/** Commander keeps it private; a group with an action of its own, as `doctor` beside `doctor reports`, runs too. */
|
|
12
|
+
const acts = (command) => command._actionHandler != null;
|
|
11
13
|
const remoteCommands = (program, path = []) => program.commands.flatMap((command) => {
|
|
12
14
|
const at = [...path, command.name()];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const below = command.commands.length > 0 ? remoteCommands(command, at) : [];
|
|
16
|
+
if (command.commands.length > 0 && !acts(command))
|
|
17
|
+
return below;
|
|
15
18
|
const meta = metaOf(command);
|
|
16
19
|
const remote = meta.effects?.remote;
|
|
17
|
-
|
|
20
|
+
const own = remote && remote !== "none" ? [{ path: at.join(" "), remote, partial: meta.partial === true }] : [];
|
|
21
|
+
return [...own, ...below];
|
|
18
22
|
});
|
|
19
23
|
const within = async (ms, what, body) => {
|
|
20
24
|
let timer;
|
package/dist/sends/pace.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface TurnOptions {
|
|
|
41
41
|
/** Waits; a timer when absent. A test or a cancellable run passes its own. */
|
|
42
42
|
sleep?: (ms: number) => Promise<void>;
|
|
43
43
|
now?: () => number;
|
|
44
|
+
/** Refuse instead of waiting longer than this; five minutes when absent. A CLI an agent waits on sets less. */
|
|
45
|
+
longestWaitMs?: number;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Waits for this call's turn in the profile's pace, the same wait for every provider: a short one silently, a long
|
package/dist/sends/pace.js
CHANGED
|
@@ -96,7 +96,7 @@ export const waitForTurn = async (pacer, options) => {
|
|
|
96
96
|
const waitMs = at - now();
|
|
97
97
|
if (waitMs <= 0)
|
|
98
98
|
return;
|
|
99
|
-
if (waitMs > LONGEST_PACE_WAIT_MS)
|
|
99
|
+
if (waitMs > (options.longestWaitMs ?? LONGEST_PACE_WAIT_MS))
|
|
100
100
|
throw new CliError("rate_limited", `this profile's next request to ${name} has to wait ${Math.ceil(waitMs / 1000)} s more — nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
101
101
|
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
102
102
|
const seconds = Math.ceil(waitMs / 1000);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.645.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|