@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { dirname
|
|
3
|
-
import { configFilePath, resolvePaths
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { configFilePath, resolvePaths } from "@wirecat/cli-base";
|
|
4
4
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { engineStates } from "../../attachments/extract.js";
|
|
@@ -11,16 +11,16 @@ import { FloodMemory, floodPathFor } from "../../sends/flood.js";
|
|
|
11
11
|
import { SendJournal, sendsPathFor } from "../../sends/journal.js";
|
|
12
12
|
import { storePath } from "../../store/path.js";
|
|
13
13
|
import { baseContext, environmentOf, outputFor } from "../context.js";
|
|
14
|
+
import { doctorReportsCommand } from "../doctor-reports-command.js";
|
|
14
15
|
import { DOCTOR_ONLINE_OPTION, DOCTOR_SUMMARY } from "../doctor-text.js";
|
|
15
|
-
import {
|
|
16
|
+
import { REMOTE_READ } from "../effects.js";
|
|
16
17
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
17
18
|
import { unknownPermissionIssues } from "../permission-keys.js";
|
|
18
19
|
import { NONE_NAMED } from "../settings.js";
|
|
19
|
-
import {
|
|
20
|
+
import { nextStep } from "../steps.js";
|
|
20
21
|
import { recalledAccount } from "./accounts.js";
|
|
21
22
|
import { messengerContext } from "./context.js";
|
|
22
23
|
import { privateFiles, withSqliteSidecars } from "./private-files.js";
|
|
23
|
-
import { buildReport, reportFileName } from "./report.js";
|
|
24
24
|
import { DAY_MS } from "./serve-members.js";
|
|
25
25
|
import { storeSummary } from "./store-maintenance-command.js";
|
|
26
26
|
/**
|
|
@@ -84,65 +84,22 @@ const INCLUDES = [
|
|
|
84
84
|
"every chat, message and account id replaced by a label that means nothing outside the file",
|
|
85
85
|
];
|
|
86
86
|
const EXCLUDES = ["message text", "chat titles", "names", "phone numbers", "the session", "the app credentials"];
|
|
87
|
-
const reportCommand = (messenger) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
...INCLUDES.map((line) => `- ${line}`),
|
|
104
|
-
"",
|
|
105
|
-
`It never holds: ${EXCLUDES.join(", ")}.`,
|
|
106
|
-
"",
|
|
107
|
-
`Create one: ${create}`,
|
|
108
|
-
`About a given run: ${create} --run <id> (ids: ${lineOf(this, "runs list")})`,
|
|
109
|
-
].join("\n"));
|
|
110
|
-
});
|
|
111
|
-
destroysNothing(annotate(report.command("create"), {
|
|
112
|
-
effects: LOCAL_WRITE,
|
|
113
|
-
examples: [`${app.command} personal doctor reports create --output ./problem-report.json`],
|
|
114
|
-
}))
|
|
115
|
-
.description("write a problem report to a file, and say where to send it")
|
|
116
|
-
.summary("the report file written: its path, the run it is about, and where to send it")
|
|
117
|
-
.option("--run <id>", "the run the report is about; the newest failed one if not given")
|
|
118
|
-
.option("--output <file>", "where to write it; a new file in this directory if not given")
|
|
119
|
-
.action(async function () {
|
|
120
|
-
const options = this.opts();
|
|
121
|
-
const env = environmentOf(this).env ?? process.env;
|
|
122
|
-
const { report: doctor, renderer, profile } = await diagnose(this, messenger);
|
|
123
|
-
const now = new Date();
|
|
124
|
-
const built = buildReport({
|
|
125
|
-
doctor,
|
|
126
|
-
runsDir: runsDirFor(app, env),
|
|
127
|
-
command: app.command,
|
|
128
|
-
sends: profile ? new SendJournal(sendsPathFor(app, profile, env)).entries() : [],
|
|
129
|
-
now,
|
|
130
|
-
home: env.HOME ?? env.USERPROFILE,
|
|
131
|
-
program: rootOf(this),
|
|
132
|
-
...(options.run === undefined ? {} : { runId: options.run }),
|
|
133
|
-
});
|
|
134
|
-
const path = resolve(options.output ?? reportFileName(app.command, now));
|
|
135
|
-
writeSecurely(path, `${JSON.stringify(built, null, 2)}\n`, 0o600);
|
|
136
|
-
const output = outputFor(this);
|
|
137
|
-
const out = renderer ?? output.renderer;
|
|
138
|
-
renderAnswer(this, { ...output, renderer: out }, itemOf({ path, run: built.run?.metadata.runId ?? null, ...(app.issues ? { send_to: app.issues } : {}) }));
|
|
139
|
-
if (!built.run) {
|
|
140
|
-
out.note("no failed run is recorded — run the failing command again, and the failure is kept by itself");
|
|
141
|
-
}
|
|
142
|
-
out.note(`read it before sending: no message text, and ids are labels${app.issues ? ` — attach it to a new issue at ${app.issues}` : ""}`);
|
|
143
|
-
});
|
|
144
|
-
return report;
|
|
145
|
-
};
|
|
87
|
+
const reportCommand = (messenger) => doctorReportsCommand({
|
|
88
|
+
app: messenger.app,
|
|
89
|
+
includes: INCLUDES,
|
|
90
|
+
excludes: EXCLUDES,
|
|
91
|
+
example: `${messenger.app.command} personal`,
|
|
92
|
+
check: "no message text, and ids are labels",
|
|
93
|
+
collect: async (command) => {
|
|
94
|
+
const env = environmentOf(command).env ?? process.env;
|
|
95
|
+
const { report, renderer, profile } = await diagnose(command, messenger);
|
|
96
|
+
return {
|
|
97
|
+
doctor: report,
|
|
98
|
+
sends: profile ? new SendJournal(sendsPathFor(messenger.app, profile, env)).entries() : [],
|
|
99
|
+
...(renderer ? { renderer } : {}),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
});
|
|
146
103
|
const rememberedOf = (report) => report.account?.remembered ?? undefined;
|
|
147
104
|
/**
|
|
148
105
|
* What `doctor` answers, as data. A configuration that will not load is a field, not an exception:
|
|
@@ -105,7 +105,7 @@ export const statsCommand = (messenger, loadRenderer = chartRenderer) => {
|
|
|
105
105
|
"messages top": 'chat:"Book club" --limit 10',
|
|
106
106
|
"messages unanswered": 'chat:"Project room"',
|
|
107
107
|
"messages waiting": "kind:private",
|
|
108
|
-
"tasks show": '--chat
|
|
108
|
+
"tasks show": '-- chat:"Project room"',
|
|
109
109
|
};
|
|
110
110
|
for (const [path, args] of Object.entries(examples)) {
|
|
111
111
|
const command = commandAt(stats, path);
|
|
@@ -18,7 +18,7 @@ import { storePath } from "../../store/path.js";
|
|
|
18
18
|
import { deleteCopy, repairStore } from "../../store/repair.js";
|
|
19
19
|
import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetNoteIndex, resetSearchIndex, resetStems, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
|
|
20
20
|
import { environmentOf, outputFor } from "../context.js";
|
|
21
|
-
import { destroysNothing, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
21
|
+
import { destroysNothing, grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
22
22
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
23
23
|
import { commandAt, lineOf, nextStep } from "../steps.js";
|
|
24
24
|
import { storeInfoCommand } from "../store-info.js";
|
|
@@ -627,7 +627,7 @@ const decryptCommand = () => annotate(new Command("decrypt"), { output: { entity
|
|
|
627
627
|
* process has the file open — it would go on writing to the file set aside — or while this CLI's
|
|
628
628
|
* `serve` runs: that opens the store on its first write, so until then it holds nothing to see.
|
|
629
629
|
*/
|
|
630
|
-
const restoreCommand = (owner) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE })
|
|
630
|
+
const restoreCommand = (owner) => grantsAuthority(annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }))
|
|
631
631
|
.summary("restore a backup and keep the current store, or roll back a breaking upgrade")
|
|
632
632
|
.description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback " +
|
|
633
633
|
"copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools " +
|
|
@@ -791,7 +791,7 @@ const quiesce = async (path, owner, then, warn, waitMs = STORE_LOCK_WAIT_MS) =>
|
|
|
791
791
|
* the delete. A new file rather than `DELETE FROM` every table: deleted rows would stay readable in free
|
|
792
792
|
* pages until a VACUUM, and every table comes back in this build's shape.
|
|
793
793
|
*/
|
|
794
|
-
const resetCommand = (owner) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE })
|
|
794
|
+
const resetCommand = (owner) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE, mcp: false })
|
|
795
795
|
.summary(`back up the ${archive(owner)} and replace it with an empty one`)
|
|
796
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")
|
|
797
797
|
.option("--no-backup", "delete the store without backing it up first")
|
|
@@ -558,19 +558,17 @@ export const tasksStatsCommand = (messenger) => {
|
|
|
558
558
|
.description("tasks per chat, meeting or project: open now, and opened and closed in the period (created: in the query), " +
|
|
559
559
|
"with the median time to close and the mean age of the open ones")
|
|
560
560
|
.option("--by <group>", "chat (default) or meeting: this account's tasks; project: the owner's project tasks, every project", statsByOf)
|
|
561
|
-
.option("--chat <chat>", `only this chat; ${messenger.chatArgument}`)
|
|
562
561
|
.option("--type <type>", "only this type: question, request, mention or promise", taskTypeOf)
|
|
563
562
|
.option("--timezone <zone>", "the IANA timezone for calendar days in the period, such as created>=today")
|
|
564
563
|
.action(async function (words) {
|
|
565
564
|
const context = messengerContext(this, messenger);
|
|
566
|
-
const { by,
|
|
565
|
+
const { by, type, timezone } = this.opts();
|
|
567
566
|
refuseJsonl(context.format);
|
|
568
567
|
const query = listQuery(typedQuery(words), TASK_STATS_QUERY, "stats tasks show");
|
|
569
568
|
const accounts = messenger.accountsOf?.(this);
|
|
570
569
|
const { stats, account } = await context.withServices(async (services) => ({
|
|
571
570
|
stats: await services.tasks.stats({
|
|
572
571
|
...(by === undefined ? {} : { by }),
|
|
573
|
-
...(chat === undefined ? {} : { chat }),
|
|
574
572
|
...(type === undefined ? {} : { kind: type }),
|
|
575
573
|
...(query === undefined ? {} : { query }),
|
|
576
574
|
...(timezone === undefined ? {} : { timezone }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { AUTHORITY_KEY, CEILING_KEY, DEFAULT_PERMISSIONS, keyForCommand, WRITE_KEYS, } from "../sends/permissions.js";
|
|
2
|
+
import { AUTHORITY_KEY, CEILING_KEY, DEFAULT_PERMISSIONS, KEYED_UNDER_HOUSEKEEPING, keyForCommand, WRITE_KEYS, } from "../sends/permissions.js";
|
|
3
3
|
import { issueMessage, permissionIssues, publicIssue } from "./config-issues.js";
|
|
4
4
|
const HOUSEKEEPING = new Set([
|
|
5
5
|
"help",
|
|
@@ -15,7 +15,9 @@ const HOUSEKEEPING = new Set([
|
|
|
15
15
|
"runs",
|
|
16
16
|
]);
|
|
17
17
|
/** A command's own path is its key; the commands that look after the tool have none. */
|
|
18
|
-
export const commandPathKey = (path) => path[0] === undefined || HOUSEKEEPING.has(path[0])
|
|
18
|
+
export const commandPathKey = (path) => path[0] === undefined || (HOUSEKEEPING.has(path[0]) && !KEYED_UNDER_HOUSEKEEPING.has(path.join(".")))
|
|
19
|
+
? null
|
|
20
|
+
: path.join(".");
|
|
19
21
|
export const commandPermissions = ({ keyOf = commandPathKey, extra = [], defaults = {}, alsoChecks, } = {}) => ({
|
|
20
22
|
keyOf,
|
|
21
23
|
extra: [AUTHORITY_KEY, ...extra],
|
package/dist/cli/program.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Command, Help } from "commander";
|
|
|
7
7
|
import { relayCommand } from "../background/relay.js";
|
|
8
8
|
import { failingNotice, scheduledRuns } from "../background/schedules.js";
|
|
9
9
|
import { parseDuration } from "../domain/duration.js";
|
|
10
|
-
import { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
|
|
10
|
+
import { isCliFailure, isCommanderFailure, storeDamaged, usageReason } from "../errors/failures.js";
|
|
11
11
|
import { failureContext } from "../errors/reasons.js";
|
|
12
12
|
import { envName, readOnlyLockOf, readOnlyRefusal } from "../ports/app.js";
|
|
13
13
|
import { recorded, wasSettled } from "../runs/recording.js";
|
|
@@ -42,6 +42,7 @@ import { assertSharedContracts } from "./shared-contracts.js";
|
|
|
42
42
|
import { skillSourceOf } from "./skill-command.js";
|
|
43
43
|
import { refreshSkills, skipsSkillRefresh } from "./skill-refresh.js";
|
|
44
44
|
import { commandAt, failureSteps, lineOf, withLines } from "./steps.js";
|
|
45
|
+
import { unknownProfile } from "./unknown-profile.js";
|
|
45
46
|
const OUTPUT_OPTIONS = [
|
|
46
47
|
["output", "--output"],
|
|
47
48
|
["outputDir", "--output-dir"],
|
|
@@ -579,12 +580,17 @@ const runOnce = async (argv, definition, options) => {
|
|
|
579
580
|
message = message.trimEnd();
|
|
580
581
|
message += ` — "${profile}" is not a command, so it was read as a profile name — which left "${rest[0]}" to be one.`;
|
|
581
582
|
}
|
|
582
|
-
const
|
|
583
|
+
const reason = usageReason(error.code);
|
|
584
|
+
const failure = new CliError("validation_error", message, reason ? { reason } : {});
|
|
583
585
|
const settled = await settleFailure(failure, { definition, program, rest, argv, profile, options });
|
|
584
586
|
return report(streams, reporting, failed(definition, program, rest, failure, settled, debug));
|
|
585
587
|
}
|
|
586
588
|
const settled = await settleFailure(error, { definition, program, rest, argv, profile, options });
|
|
587
|
-
|
|
589
|
+
// An MCP call's profile is the one its server was started for, not a word typed now.
|
|
590
|
+
const told = options.agent
|
|
591
|
+
? error
|
|
592
|
+
: unknownProfile(error, () => failureSettings(definition, program, rest, profile, options));
|
|
593
|
+
const exit = report(streams, reporting, failed(definition, program, rest, told, settled, debug));
|
|
588
594
|
return signalExit ?? exit;
|
|
589
595
|
}
|
|
590
596
|
finally {
|
|
@@ -690,19 +696,29 @@ const settleFailure = async (failure, state) => {
|
|
|
690
696
|
* Its words are kept as `record_input` says (`maskArgv`); a configuration that did not load masks them, since it may
|
|
691
697
|
* be the one that turned recording input off.
|
|
692
698
|
*/
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return;
|
|
696
|
-
const env = options.env ?? process.env;
|
|
699
|
+
/** The settings a failed run had, read again without asking for a profile; `undefined` when they do not load. */
|
|
700
|
+
const failureSettings = (definition, program, rest, profile, options) => {
|
|
697
701
|
const path = commandPath(program, program.args.length > 0 ? program.args : rest);
|
|
698
702
|
const { resolveSettings } = definition.configuration ?? settingsFor(definition.app);
|
|
699
|
-
let settings;
|
|
700
703
|
try {
|
|
701
|
-
|
|
704
|
+
return resolveSettings({ ...program.opts(), ...(profile === undefined ? {} : { profile }) }, {
|
|
705
|
+
env: options.env ?? process.env,
|
|
706
|
+
kind: path.split(" ")[0] === "bot" ? "bot" : "personal",
|
|
707
|
+
needsProfile: false,
|
|
708
|
+
readOnly: true,
|
|
709
|
+
});
|
|
702
710
|
}
|
|
703
711
|
catch {
|
|
704
|
-
|
|
712
|
+
return undefined;
|
|
705
713
|
}
|
|
714
|
+
};
|
|
715
|
+
const keepFailure = async (failure, { definition, program, rest, argv, profile, options }) => {
|
|
716
|
+
if (wasSettled(failure))
|
|
717
|
+
return;
|
|
718
|
+
const env = options.env ?? process.env;
|
|
719
|
+
const path = commandPath(program, program.args.length > 0 ? program.args : rest);
|
|
720
|
+
// A configuration that will not load is a failure worth keeping too; the flags are all there is to go on.
|
|
721
|
+
const settings = failureSettings(definition, program, rest, profile, options);
|
|
706
722
|
const command = `${options.agent ? "mcp " : ""}${path || definition.app.command}`;
|
|
707
723
|
await recorded({
|
|
708
724
|
app: definition.app,
|
package/dist/cli/settings.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface SettingsExtension<T extends object = Record<never, never>> {
|
|
|
31
31
|
sources: Record<string, Source>;
|
|
32
32
|
};
|
|
33
33
|
profile?: v.ObjectEntries;
|
|
34
|
+
/** Like `profile`, but a bot's section refuses them: settings only a personal account reads. */
|
|
35
|
+
personal?: v.ObjectEntries;
|
|
34
36
|
/** For the whole program only, never per profile. */
|
|
35
37
|
defaults?: v.ObjectEntries;
|
|
36
38
|
/** Its own scalar settings, written into the file's `defaults` beside the shared ones (WC-CMD-30). */
|
package/dist/cli/settings.js
CHANGED
|
@@ -227,11 +227,12 @@ export const fromFile = (settings, key, fallback) => first([
|
|
|
227
227
|
*/
|
|
228
228
|
export const settingsFor = (app, extension = {}) => {
|
|
229
229
|
const declared = extension.permissions;
|
|
230
|
-
const
|
|
230
|
+
const botEntries = {
|
|
231
231
|
...SHARED_PROFILE_ENTRIES,
|
|
232
232
|
...(declared ? { permissions: v.optional(commandPathLevels) } : {}),
|
|
233
233
|
...extension.profile,
|
|
234
234
|
};
|
|
235
|
+
const profileEntries = { ...botEntries, ...extension.personal };
|
|
235
236
|
const defaultsOnly = { ...SHARED_DEFAULTS_ONLY, ...extension.defaults };
|
|
236
237
|
const defaultsEntries = { ...profileEntries, ...defaultsOnly };
|
|
237
238
|
const strictOf = (entries) => v.strictObject(entries, objectMessage);
|
|
@@ -243,7 +244,7 @@ export const settingsFor = (app, extension = {}) => {
|
|
|
243
244
|
defaults: v.optional(strictOf(defaultsEntries)),
|
|
244
245
|
profiles: v.optional(v.record(v.string(), strictOf(profileEntries), "has to be an object of profiles, by name"), {}),
|
|
245
246
|
personal: v.optional(kindSection(profileEntries)),
|
|
246
|
-
bot: v.optional(kindSection({ ...
|
|
247
|
+
bot: v.optional(kindSection({ ...botEntries, ...BOT_ONLY_ENTRIES })),
|
|
247
248
|
};
|
|
248
249
|
const schema = strictOf(configEntries);
|
|
249
250
|
const defaultsOnlyKeys = Object.keys(defaultsOnly);
|
|
@@ -10,7 +10,7 @@ import { storePath } from "../store/path.js";
|
|
|
10
10
|
import { activeTimers, recoverStore, sqlite3Program, storeHolders, tableRows, } from "../store/recover.js";
|
|
11
11
|
import { openSqlite } from "../store/store.js";
|
|
12
12
|
import { environmentOf, outputFor } from "./context.js";
|
|
13
|
-
import { LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
13
|
+
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
14
14
|
import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
|
|
15
15
|
/** The tables whose counts say what the store holds; every other table is in `store info`. */
|
|
16
16
|
const COUNTED = [
|
|
@@ -173,7 +173,7 @@ export const storeRecoverCommand = ({ command, version }) => {
|
|
|
173
173
|
for (const line of recoveryNotes(answer))
|
|
174
174
|
output.renderer.note(line);
|
|
175
175
|
});
|
|
176
|
-
recover.addCommand(annotate(new Command("run"), { effects: LOCAL_WRITE, examples: [`${command} store recover run`] })
|
|
176
|
+
recover.addCommand(grantsAuthority(annotate(new Command("run"), { effects: LOCAL_WRITE, examples: [`${command} store recover run`] }))
|
|
177
177
|
.summary("rebuild a damaged store from every row it can read")
|
|
178
178
|
.description("copy every readable row into a new file with the sqlite3 program, rebuild the search indexes, mentions and vector index, " +
|
|
179
179
|
"check it, and put it in place of the store; the damaged file is kept beside it. Refuses while a WireCat timer or process has the store")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Settings } from "./settings.js";
|
|
2
|
+
/**
|
|
3
|
+
* A "not signed in" failure for a first word this computer has never seen as a profile is most likely a typo: it
|
|
4
|
+
* answers `not_found` with the profiles here (FIND-2583), and keeps the sign-in hint for a profile that is new on
|
|
5
|
+
* purpose. Only after a command failed, so a working profile and the `setup` or `session start` that makes a new one
|
|
6
|
+
* never reach it; a profile set in the environment is a script's deliberate choice and keeps its refusal, and a bot
|
|
7
|
+
* gets its token with `bot auth set` under any new name.
|
|
8
|
+
*/
|
|
9
|
+
export declare const unknownProfile: (error: unknown, settingsOf: () => (Pick<Settings, "profile"> & Partial<Pick<Settings, "sources" | "profilesHere" | "kind">>) | undefined) => unknown;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
|
+
const NOT_SIGNED_IN = new Set([undefined, "session.missing", "oauth.missing"]);
|
|
3
|
+
/**
|
|
4
|
+
* A "not signed in" failure for a first word this computer has never seen as a profile is most likely a typo: it
|
|
5
|
+
* answers `not_found` with the profiles here (FIND-2583), and keeps the sign-in hint for a profile that is new on
|
|
6
|
+
* purpose. Only after a command failed, so a working profile and the `setup` or `session start` that makes a new one
|
|
7
|
+
* never reach it; a profile set in the environment is a script's deliberate choice and keeps its refusal, and a bot
|
|
8
|
+
* gets its token with `bot auth set` under any new name.
|
|
9
|
+
*/
|
|
10
|
+
export const unknownProfile = (error, settingsOf) => {
|
|
11
|
+
if (!isCliError(error) || error.code !== "authentication_error")
|
|
12
|
+
return error;
|
|
13
|
+
if (!NOT_SIGNED_IN.has(error.details.reason))
|
|
14
|
+
return error;
|
|
15
|
+
const settings = settingsOf();
|
|
16
|
+
const here = settings?.profilesHere;
|
|
17
|
+
if (!settings || !here || settings.kind === "bot" || settings.sources?.profile !== "first word")
|
|
18
|
+
return error;
|
|
19
|
+
if (here.includes(settings.profile))
|
|
20
|
+
return error;
|
|
21
|
+
return new CliError("not_found", `no profile named ${settings.profile} on this computer — profiles here: ${here.join(", ") || "none"}; ` +
|
|
22
|
+
`if ${settings.profile} is a new one: ${error.message}`, { reason: "profile.unknown", profiles: here });
|
|
23
|
+
};
|
|
@@ -22,10 +22,10 @@ const DEFAULT_LIMIT = 20;
|
|
|
22
22
|
export const addCrmSearchAll = (searches, { within, app, example, }) => {
|
|
23
23
|
const all = annotate(new Command("all"), { effects: LOCAL_READ, partial: true, output: { entity: "hit" } })
|
|
24
24
|
.summary("search stored deals and leads, messages, notes, calendar events and meetings")
|
|
25
|
-
.description("search the CRM's deals and leads by the words of their title, company and
|
|
26
|
-
"calendar events and meetings other WireCat tools stored — best match first. Use it when
|
|
27
|
-
"where something was written")
|
|
28
|
-
.argument("<query...>", 'words and "phrases"; deals and leads match the words of their title, company and
|
|
25
|
+
.description("search the CRM's deals and leads by the words of their title, company, contacts and activities, and the " +
|
|
26
|
+
"messages, notes, calendar events and meetings other WireCat tools stored — best match first. Use it when " +
|
|
27
|
+
"you do not know where something was written")
|
|
28
|
+
.argument("<query...>", 'words and "phrases"; deals and leads match the words of their title, company, contacts and activities')
|
|
29
29
|
.addHelpText("after", SAVE_HELP);
|
|
30
30
|
searches.addCommand(searchAllOptions(all, SEARCHED));
|
|
31
31
|
example(all, "search all Example LLC", "search all website --only crm --json");
|
|
@@ -89,7 +89,10 @@ export declare const isKind: (word: string) => word is Kind;
|
|
|
89
89
|
export declare const providerNamed: (word: string) => ProviderEntry | undefined;
|
|
90
90
|
/** The kind of a provider the registry knows; `undefined` for one no entry names, which a search skips. */
|
|
91
91
|
export declare const kindIn: (provider: Provider) => Kind | undefined;
|
|
92
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Every kind a provider's accounts hold, its `kind` first; empty for one no entry names. An import-only provider's
|
|
94
|
+
* accounts hold documents too: a records import writes them beside its calls and SMS.
|
|
95
|
+
*/
|
|
93
96
|
export declare const kindsIn: (provider: Provider) => readonly Kind[];
|
|
94
97
|
/**
|
|
95
98
|
* Whether an entry may carry `imported`, beside one stored before (`held`): never for a built-in a sync writes, only
|
package/dist/domain/providers.js
CHANGED
|
@@ -21,6 +21,8 @@ export const PROVIDERS = [
|
|
|
21
21
|
{ name: "zoom", kind: "meetings", aliases: [] },
|
|
22
22
|
// A phone export's records: its SMS and its calls in the one account the import names.
|
|
23
23
|
{ name: "phone", kind: "messages", kinds: ["messages", "events"], aliases: [], imported: true },
|
|
24
|
+
// Any other import: a folder of notes, a CRM's export, a script's records, under `import:<what it is>`.
|
|
25
|
+
{ name: "import", kind: "documents", kinds: ["documents", "messages", "events"], aliases: [], imported: true },
|
|
24
26
|
];
|
|
25
27
|
const LABELS = {
|
|
26
28
|
telegram: "Telegram",
|
|
@@ -188,12 +190,17 @@ export const providerNamed = (word) => {
|
|
|
188
190
|
};
|
|
189
191
|
/** The kind of a provider the registry knows; `undefined` for one no entry names, which a search skips. */
|
|
190
192
|
export const kindIn = (provider) => isFolderProvider(provider) ? "notes" : registry.find(({ name }) => name === provider)?.kind;
|
|
191
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Every kind a provider's accounts hold, its `kind` first; empty for one no entry names. An import-only provider's
|
|
195
|
+
* accounts hold documents too: a records import writes them beside its calls and SMS.
|
|
196
|
+
*/
|
|
192
197
|
export const kindsIn = (provider) => {
|
|
193
198
|
if (isFolderProvider(provider))
|
|
194
199
|
return ["notes"];
|
|
195
200
|
const entry = registry.find(({ name }) => name === provider);
|
|
196
|
-
|
|
201
|
+
if (!entry)
|
|
202
|
+
return [];
|
|
203
|
+
return entry.imported ? unitedKinds(kindsOfEntry(entry), ["documents"]) : kindsOfEntry(entry);
|
|
197
204
|
};
|
|
198
205
|
/**
|
|
199
206
|
* Whether an entry may carry `imported`, beside one stored before (`held`): never for a built-in a sync writes, only
|
|
@@ -56,6 +56,10 @@ export interface RecordTypeSpec {
|
|
|
56
56
|
* never land in a messenger's chat or a calendar's account.
|
|
57
57
|
*/
|
|
58
58
|
importOnly?: boolean;
|
|
59
|
+
/** A phone's own export carries it, never a hand-made sheet: no template and no CSV. */
|
|
60
|
+
sheet?: false;
|
|
61
|
+
/** How many bytes its `fields` may take as JSON, when more than every type's 64 KiB: a document's text. */
|
|
62
|
+
fieldsBytes?: number;
|
|
59
63
|
/** The type's `fields`: known keys typed, any other key kept as sent. */
|
|
60
64
|
fields: FieldSchema;
|
|
61
65
|
/** The roles the entity is made from; any other role word is kept as the source's own. */
|
|
@@ -440,6 +444,7 @@ export declare const RECORD_TYPES: {
|
|
|
440
444
|
readonly update: "in-place";
|
|
441
445
|
readonly tombstone: true;
|
|
442
446
|
readonly importOnly: true;
|
|
447
|
+
readonly sheet: false;
|
|
443
448
|
readonly fields: FieldSchema;
|
|
444
449
|
readonly roles: {
|
|
445
450
|
readonly counterpart: {
|
|
@@ -454,6 +459,7 @@ export declare const RECORD_TYPES: {
|
|
|
454
459
|
readonly update: "in-place";
|
|
455
460
|
readonly tombstone: true;
|
|
456
461
|
readonly importOnly: true;
|
|
462
|
+
readonly sheet: false;
|
|
457
463
|
readonly fields: FieldSchema;
|
|
458
464
|
readonly roles: {
|
|
459
465
|
readonly counterpart: {
|
|
@@ -462,6 +468,21 @@ export declare const RECORD_TYPES: {
|
|
|
462
468
|
};
|
|
463
469
|
};
|
|
464
470
|
};
|
|
471
|
+
readonly document: {
|
|
472
|
+
readonly table: "documents";
|
|
473
|
+
readonly review: "direct";
|
|
474
|
+
readonly update: "in-place";
|
|
475
|
+
readonly tombstone: true;
|
|
476
|
+
readonly importOnly: true;
|
|
477
|
+
readonly fieldsBytes: 1048576;
|
|
478
|
+
readonly fields: FieldSchema;
|
|
479
|
+
readonly roles: {
|
|
480
|
+
readonly about: {
|
|
481
|
+
readonly targets: readonly ["person", "organization", "deal", "event"];
|
|
482
|
+
readonly many: true;
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
};
|
|
465
486
|
readonly pipeline: {
|
|
466
487
|
readonly table: "pipelines";
|
|
467
488
|
readonly review: "direct";
|
|
@@ -487,8 +508,8 @@ type Identity<T> = {
|
|
|
487
508
|
} ? K : never;
|
|
488
509
|
}[keyof T];
|
|
489
510
|
export type IdentityType = Identity<typeof RECORD_TYPES>;
|
|
490
|
-
export type BusinessType = Exclude<RecordType, IdentityType>;
|
|
491
|
-
/** A business record (an invoice, a deal, a wallet): not a person, organization or
|
|
511
|
+
export type BusinessType = Exclude<RecordType, IdentityType | "document">;
|
|
512
|
+
/** A business record (an invoice, a deal, a wallet): not a person, organization, project or document. */
|
|
492
513
|
export declare const isBusinessType: (type: string) => type is BusinessType;
|
|
493
514
|
export declare const isIdentityType: (type: unknown) => type is IdentityType;
|
|
494
515
|
export declare const RECORD_ENTITY_TYPES: RecordType[];
|
|
@@ -528,7 +549,7 @@ export declare const AMOUNT_ROLES: string[];
|
|
|
528
549
|
export declare const FIELD_REFERENCE_ROLES: string[];
|
|
529
550
|
/** The types whose records v1 projected: their v1 roles keep v1's reading. */
|
|
530
551
|
export declare const hasV1Roles: (type: RecordType) => boolean;
|
|
531
|
-
export declare const IDENTITY_TYPES: ("contract" | "deal" | "event" | "invoice" | "lead" | "message" | "order" | "organization" | "payment" | "person" | "pipeline" | "product" | "project" | "subscription" | "transaction" | "wallet")[];
|
|
552
|
+
export declare const IDENTITY_TYPES: ("contract" | "deal" | "document" | "event" | "invoice" | "lead" | "message" | "order" | "organization" | "payment" | "person" | "pipeline" | "product" | "project" | "subscription" | "transaction" | "wallet")[];
|
|
532
553
|
/** `a` or `an` before a type word: `an event`, `an invoice`, `a message`. */
|
|
533
554
|
export declare const article: (word: string) => "a" | "an";
|
|
534
555
|
export {};
|
|
@@ -307,6 +307,7 @@ export const RECORD_TYPES = {
|
|
|
307
307
|
update: "in-place",
|
|
308
308
|
tombstone: true,
|
|
309
309
|
importOnly: true,
|
|
310
|
+
sheet: false,
|
|
310
311
|
fields: objectOf({
|
|
311
312
|
kind: enumOf(["sms"], "sms: a text message of the phone"),
|
|
312
313
|
direction: enumOf(SMS_DIRECTIONS, "in: the other side wrote it; out: the owner did"),
|
|
@@ -324,6 +325,7 @@ export const RECORD_TYPES = {
|
|
|
324
325
|
update: "in-place",
|
|
325
326
|
tombstone: true,
|
|
326
327
|
importOnly: true,
|
|
328
|
+
sheet: false,
|
|
327
329
|
fields: objectOf({
|
|
328
330
|
kind: enumOf(["call"], "call: a phone call"),
|
|
329
331
|
direction: enumOf(CALL_DIRECTIONS, "in, out, or missed: a call the owner did not take"),
|
|
@@ -333,6 +335,25 @@ export const RECORD_TYPES = {
|
|
|
333
335
|
}, { required: ["kind", "direction", "phone", "started_at"] }),
|
|
334
336
|
roles: COUNTERPART,
|
|
335
337
|
},
|
|
338
|
+
document: {
|
|
339
|
+
table: "documents",
|
|
340
|
+
review: "direct",
|
|
341
|
+
update: "in-place",
|
|
342
|
+
tombstone: true,
|
|
343
|
+
importOnly: true,
|
|
344
|
+
fieldsBytes: 1_048_576,
|
|
345
|
+
fields: objectOf({
|
|
346
|
+
title: text("What the document is called; its external id when left out", 500),
|
|
347
|
+
text: { type: "string", maxLength: 1_000_000, description: "The text search reads" },
|
|
348
|
+
created_at: instant("When the source made it"),
|
|
349
|
+
updated_at: instant("When the source last changed it: what date: reads"),
|
|
350
|
+
url: text("Where the original is", 4096),
|
|
351
|
+
metadata: { type: "object", description: "Anything else the source knows about it, kept as sent" },
|
|
352
|
+
}, { required: ["text"] }),
|
|
353
|
+
roles: {
|
|
354
|
+
about: { targets: ["person", "organization", "deal", "event"], many: true },
|
|
355
|
+
},
|
|
356
|
+
},
|
|
336
357
|
pipeline: {
|
|
337
358
|
table: "pipelines",
|
|
338
359
|
review: "direct",
|
|
@@ -353,8 +374,8 @@ export const RECORD_TYPES = {
|
|
|
353
374
|
},
|
|
354
375
|
};
|
|
355
376
|
export const isRecordType = (type) => Object.hasOwn(RECORD_TYPES, type);
|
|
356
|
-
/** A business record (an invoice, a deal, a wallet): not a person, organization or
|
|
357
|
-
export const isBusinessType = (type) => isRecordType(type) && RECORD_TYPES[type].review !== "identity";
|
|
377
|
+
/** A business record (an invoice, a deal, a wallet): not a person, organization, project or document. */
|
|
378
|
+
export const isBusinessType = (type) => isRecordType(type) && RECORD_TYPES[type].review !== "identity" && type !== "document";
|
|
358
379
|
export const isIdentityType = (type) => typeof type === "string" && isRecordType(type) && RECORD_TYPES[type].review === "identity";
|
|
359
380
|
export const RECORD_ENTITY_TYPES = Object.keys(RECORD_TYPES);
|
|
360
381
|
/** Each registered type's table, for the store's polymorphic pointers. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RECORD_TYPES } from "./record-types.js";
|
|
2
2
|
import { pointerOf, RECORDS_SCHEMA_VERSION, } from "./records.js";
|
|
3
3
|
/** The types a table can carry: an SMS and a call come from a phone's own export, never from a hand-made sheet. */
|
|
4
|
-
export const TABLE_RECORD_TYPES = Object.keys(RECORD_TYPES).filter((type) =>
|
|
4
|
+
export const TABLE_RECORD_TYPES = Object.keys(RECORD_TYPES).filter((type) => RECORD_TYPES[type].sheet !== false);
|
|
5
5
|
export class TableError extends Error {
|
|
6
6
|
errors;
|
|
7
7
|
constructor(errors) {
|
|
@@ -63,7 +63,7 @@ const roleColumn = (name, role) => ({
|
|
|
63
63
|
/** A type's columns: the external id, its flat fields, one per role, then one per key of each list of items. */
|
|
64
64
|
export const recordColumns = (type) => {
|
|
65
65
|
const spec = specOf(type);
|
|
66
|
-
if (!spec || spec.
|
|
66
|
+
if (!spec || spec.sheet === false)
|
|
67
67
|
return [];
|
|
68
68
|
const fields = spec.fields.properties ?? {};
|
|
69
69
|
const required = spec.fields.required ?? [];
|
|
@@ -134,7 +134,8 @@ export const recordTemplate = (type, format, { source, separator = "," } = {}) =
|
|
|
134
134
|
const envelope = {
|
|
135
135
|
schema_version: RECORDS_SCHEMA_VERSION,
|
|
136
136
|
source: {
|
|
137
|
-
provider:
|
|
137
|
+
// An import-only type is refused under a sheet's provider: `import` is the one any folder or export may use.
|
|
138
|
+
provider: source?.provider ?? (specOf(type)?.importOnly ? "import" : "sheet"),
|
|
138
139
|
account: source?.account ?? "main",
|
|
139
140
|
batch_id: source?.batch_id ?? "first-import",
|
|
140
141
|
},
|
package/dist/domain/records.d.ts
CHANGED
|
@@ -167,7 +167,7 @@ export declare const RECORDS_ENVELOPE_SCHEMA: {
|
|
|
167
167
|
if: {
|
|
168
168
|
properties: {
|
|
169
169
|
type: {
|
|
170
|
-
const: "contract" | "deal" | "event" | "invoice" | "lead" | "message" | "order" | "organization" | "payment" | "person" | "pipeline" | "product" | "project" | "subscription" | "transaction" | "wallet";
|
|
170
|
+
const: "contract" | "deal" | "document" | "event" | "invoice" | "lead" | "message" | "order" | "organization" | "payment" | "person" | "pipeline" | "product" | "project" | "subscription" | "transaction" | "wallet";
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
173
|
required: string[];
|
package/dist/domain/records.js
CHANGED
|
@@ -234,8 +234,9 @@ export const recordErrors = (record, index) => {
|
|
|
234
234
|
return withKey([invalid([...at, "fields"], "an upsert carries its fields as an object")]);
|
|
235
235
|
if (record.fields !== undefined && !isObject(record.fields))
|
|
236
236
|
return withKey([invalid([...at, "fields"], "fields is an object")]);
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
const most = (isRecordType(record.type) && RECORD_TYPES[record.type].fieldsBytes) || MAX_FIELDS_BYTES;
|
|
238
|
+
if (record.fields !== undefined && Buffer.byteLength(JSON.stringify(record.fields)) > most)
|
|
239
|
+
return withKey([invalid([...at, "fields"], `fields take at most ${most} bytes`, "record.too-large")]);
|
|
239
240
|
const secret = record.fields === undefined ? undefined : secretIn(record.fields, [...at, "fields"]);
|
|
240
241
|
if (secret)
|
|
241
242
|
return withKey([
|
|
@@ -12,6 +12,8 @@ export declare const isCommanderFailure: (value: unknown) => value is Error & {
|
|
|
12
12
|
code: string;
|
|
13
13
|
exitCode: number;
|
|
14
14
|
};
|
|
15
|
+
/** The reason of a commander usage error a caller matches instead of commander's English, when it has one. */
|
|
16
|
+
export declare const usageReason: (code: string) => string | undefined;
|
|
15
17
|
/** What failed, never what it said: a messenger's refusal can quote the message back. */
|
|
16
18
|
export declare const failureKey: (error: unknown) => string;
|
|
17
19
|
/**
|
package/dist/errors/failures.js
CHANGED
|
@@ -14,6 +14,12 @@ export const isCommanderFailure = (value) => {
|
|
|
14
14
|
const { code, exitCode } = (value ?? {});
|
|
15
15
|
return (value instanceof Error && typeof code === "string" && code.startsWith("commander.") && typeof exitCode === "number");
|
|
16
16
|
};
|
|
17
|
+
const USAGE_REASONS = {
|
|
18
|
+
"commander.unknownCommand": "usage.unknown-command",
|
|
19
|
+
"commander.unknownOption": "usage.unknown-option",
|
|
20
|
+
};
|
|
21
|
+
/** The reason of a commander usage error a caller matches instead of commander's English, when it has one. */
|
|
22
|
+
export const usageReason = (code) => USAGE_REASONS[code];
|
|
17
23
|
/** What failed, never what it said: a messenger's refusal can quote the message back. */
|
|
18
24
|
export const failureKey = (error) => isCliFailure(error) ? error.code : error instanceof Error ? error.name : "error";
|
|
19
25
|
const SQLITE_CORRUPT = 11;
|