@wirecat/cli-core 0.617.0 → 0.619.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 +406 -1
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES +3 -0
- package/dist/background/backfill.d.ts +21 -0
- package/dist/background/backfill.js +41 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/deliver.d.ts +5 -2
- package/dist/background/deliver.js +30 -12
- package/dist/background/report/messages.js +4 -1
- package/dist/background/report/render.d.ts +3 -1
- package/dist/background/report/render.js +3 -1
- package/dist/background/report/view.js +4 -1
- package/dist/background/schedules.d.ts +17 -0
- package/dist/background/schedules.js +21 -8
- package/dist/calendar/cli/answers.d.ts +1 -0
- package/dist/calendar/cli/answers.js +6 -1
- package/dist/calendar/cli/index.js +2 -14
- package/dist/calendar/cli/people-link.d.ts +3 -0
- package/dist/calendar/cli/people-link.js +23 -0
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/base-stages-command.d.ts +22 -0
- package/dist/cli/base-stages-command.js +174 -0
- package/dist/cli/command-runs.d.ts +2 -0
- package/dist/cli/command-runs.js +3 -1
- package/dist/cli/config-command.js +6 -1
- package/dist/cli/context.d.ts +5 -0
- package/dist/cli/context.js +1 -0
- package/dist/cli/group-lock.d.ts +42 -0
- package/dist/cli/group-lock.js +130 -0
- package/dist/cli/index.d.ts +10 -4
- package/dist/cli/index.js +10 -4
- package/dist/cli/messenger/backfill-command.js +27 -15
- package/dist/cli/messenger/contacts-command.js +10 -3
- package/dist/cli/messenger/context.js +1 -0
- package/dist/cli/messenger/doctor-command.js +3 -1
- package/dist/cli/messenger/models-command.js +1 -1
- package/dist/cli/messenger/serve-command.js +24 -2
- package/dist/cli/messenger/serve-outdated.d.ts +22 -0
- package/dist/cli/messenger/serve-outdated.js +100 -0
- package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
- package/dist/cli/messenger/store-maintenance-command.js +9 -4
- package/dist/cli/model-catalogue-command.d.ts +3 -1
- package/dist/cli/model-catalogue-command.js +46 -2
- package/dist/cli/profile.d.ts +8 -0
- package/dist/cli/profile.js +25 -0
- package/dist/cli/program.js +2 -0
- package/dist/cli/runs/search-query.d.ts +1 -1
- package/dist/cli/runs/search-query.js +4 -0
- package/dist/cli/runs/search.d.ts +5 -1
- package/dist/cli/runs/search.js +12 -1
- package/dist/cli/schedule/schedule-command.d.ts +9 -0
- package/dist/cli/schedule/schedule-command.js +13 -0
- package/dist/cli/search-left-out.d.ts +6 -1
- package/dist/cli/search-left-out.js +9 -4
- package/dist/cli/settings.d.ts +8 -0
- package/dist/cli/settings.js +17 -2
- package/dist/cli/shared-command-exports.d.ts +16 -0
- package/dist/cli/store-recover.d.ts +3 -3
- package/dist/cli/store-recover.js +47 -23
- package/dist/cli/store-settings.d.ts +2 -0
- package/dist/cli/store-settings.js +37 -9
- package/dist/crm/cli/index.js +38 -6
- package/dist/crm/group-hint.d.ts +8 -0
- package/dist/crm/group-hint.js +13 -0
- package/dist/crm/source.d.ts +12 -1
- package/dist/crm/sync.d.ts +31 -2
- package/dist/crm/sync.js +110 -3
- package/dist/crm/testing/acme-scenario.d.ts +40 -0
- package/dist/crm/testing/acme-scenario.js +170 -0
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/source-contract.js +12 -0
- package/dist/crm/testing/source.d.ts +2 -0
- package/dist/crm/testing/source.js +1 -0
- package/dist/domain/addresses.d.ts +13 -0
- package/dist/domain/addresses.js +63 -0
- package/dist/domain/categories.d.ts +3 -0
- package/dist/domain/categories.js +2 -0
- package/dist/domain/crm.d.ts +23 -0
- package/dist/domain/crm.js +7 -0
- package/dist/domain/links.d.ts +17 -4
- package/dist/domain/links.js +20 -7
- package/dist/domain/mentions.d.ts +2 -12
- package/dist/domain/mentions.js +2 -19
- package/dist/domain/orders.d.ts +8 -1
- package/dist/domain/orders.js +6 -2
- package/dist/domain/phones.d.ts +26 -0
- package/dist/domain/phones.js +48 -0
- package/dist/domain/record-types.d.ts +1 -1
- package/dist/domain/record-types.js +1 -0
- package/dist/domain/records.d.ts +5 -0
- package/dist/domain/ref-summaries.d.ts +39 -0
- package/dist/domain/ref-summaries.js +51 -3
- package/dist/domain/relations.d.ts +27 -2
- package/dist/domain/relations.js +37 -3
- package/dist/domain/vcard.d.ts +2 -2
- package/dist/domain/vcard.js +4 -10
- package/dist/embeddings/models.d.ts +11 -3
- package/dist/embeddings/models.js +28 -4
- package/dist/entities/business-context.d.ts +149 -0
- package/dist/entities/business-context.js +192 -0
- package/dist/entities/contact-activity.d.ts +2 -0
- package/dist/entities/contact-activity.js +7 -1
- package/dist/entities/contact-context.d.ts +157 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +10 -0
- package/dist/entities/deal.js +2 -0
- package/dist/entities/index.d.ts +23 -3
- package/dist/entities/index.js +5 -0
- package/dist/entities/mention.d.ts +4 -3
- package/dist/entities/mention.js +2 -1
- package/dist/entities/message-transfer.d.ts +4 -2
- package/dist/entities/message-transfer.js +2 -2
- package/dist/entities/model.d.ts +2 -2
- package/dist/entities/model.js +1 -1
- package/dist/entities/relationship.d.ts +4 -0
- package/dist/entities/relationship.js +4 -0
- package/dist/errors/reasons.js +44 -4
- package/dist/fetch/page.js +2 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/meetings/context-store.d.ts +2 -0
- package/dist/meetings/findings-rules.d.ts +4 -0
- package/dist/meetings/findings-rules.js +5 -2
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/result-items.d.ts +1 -0
- package/dist/meetings/result-items.js +1 -0
- package/dist/models/index.js +22 -5
- package/dist/runs/events.d.ts +11 -1
- package/dist/runs/events.js +3 -1
- package/dist/runs/log-attributes.js +4 -0
- package/dist/runs/log-events.js +2 -0
- package/dist/runs/recording.d.ts +3 -0
- package/dist/runs/recording.js +36 -12
- package/dist/runs/run.d.ts +12 -3
- package/dist/runs/run.js +32 -13
- package/dist/search/account-list.d.ts +6 -0
- package/dist/search/account-list.js +9 -3
- package/dist/search/groups.d.ts +68 -0
- package/dist/search/groups.js +172 -0
- package/dist/services/account-groups.d.ts +28 -0
- package/dist/services/account-groups.js +89 -0
- package/dist/services/archive.d.ts +7 -1
- package/dist/services/archive.js +19 -3
- package/dist/services/business-context.d.ts +113 -0
- package/dist/services/business-context.js +156 -0
- package/dist/services/communications.d.ts +50 -0
- package/dist/services/communications.js +140 -0
- package/dist/services/deal-context.d.ts +90 -0
- package/dist/services/deal-context.js +131 -0
- package/dist/services/deps.d.ts +2 -0
- package/dist/services/enrichment.d.ts +7 -2
- package/dist/services/enrichment.js +46 -5
- package/dist/services/events-search.js +2 -1
- package/dist/services/group-guard.d.ts +28 -0
- package/dist/services/group-guard.js +131 -0
- package/dist/services/index.d.ts +15 -2
- package/dist/services/index.js +9 -2
- package/dist/services/ingest.d.ts +12 -0
- package/dist/services/ingest.js +4 -0
- package/dist/services/link-scorers/chat-senders.js +39 -29
- package/dist/services/link-scorers/member-chats.js +4 -3
- package/dist/services/link-scorers/member-dialog.js +5 -7
- package/dist/services/link-scorers/scan.js +17 -8
- package/dist/services/link-scorers/shared.d.ts +6 -2
- package/dist/services/link-scorers/shared.js +6 -2
- package/dist/services/link-scorers/types.d.ts +2 -0
- package/dist/services/meaning-model.d.ts +7 -0
- package/dist/services/meaning-model.js +20 -0
- package/dist/services/meeting-context.d.ts +6 -1
- package/dist/services/meeting-context.js +12 -5
- package/dist/services/message-resolution.js +2 -3
- package/dist/services/messages-meaning.js +4 -5
- package/dist/services/messages-search.d.ts +5 -1
- package/dist/services/messages-search.js +1 -1
- package/dist/services/model-downloads.d.ts +1 -1
- package/dist/services/model-downloads.js +6 -4
- package/dist/services/money-context.d.ts +73 -0
- package/dist/services/money-context.js +77 -0
- package/dist/services/notes-search.d.ts +4 -1
- package/dist/services/notes-search.js +19 -7
- package/dist/services/organization-context.d.ts +80 -0
- package/dist/services/organization-context.js +154 -0
- package/dist/services/people.d.ts +22 -6
- package/dist/services/people.js +38 -8
- package/dist/services/person-business.d.ts +43 -0
- package/dist/services/person-business.js +67 -0
- package/dist/services/person-context.d.ts +9 -1
- package/dist/services/person-context.js +5 -3
- package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
- package/dist/services/proposals/kinds/identity-link.js +48 -0
- package/dist/services/proposals/kinds/orders.js +1 -1
- package/dist/services/proposals/registry.js +2 -0
- package/dist/services/search-kind.d.ts +12 -5
- package/dist/services/search-kind.js +49 -10
- package/dist/services/text-model-choice.js +1 -1
- package/dist/store/accounts.d.ts +18 -0
- package/dist/store/accounts.js +18 -3
- package/dist/store/damage.d.ts +43 -10
- package/dist/store/damage.js +119 -36
- package/dist/store/decisions.js +3 -1
- package/dist/store/evidence-findings.d.ts +14 -0
- package/dist/store/evidence-findings.js +2 -0
- package/dist/store/exports.d.ts +2 -1
- package/dist/store/identity-links.d.ts +92 -0
- package/dist/store/identity-links.js +6 -0
- package/dist/store/index.d.ts +11 -5
- package/dist/store/index.js +5 -2
- package/dist/store/journal.d.ts +10 -0
- package/dist/store/journal.js +33 -0
- package/dist/store/marks.d.ts +19 -1
- package/dist/store/marks.js +23 -1
- package/dist/store/migrations.d.ts +1 -1
- package/dist/store/migrations.js +35 -12
- package/dist/store/people.d.ts +22 -0
- package/dist/store/people.js +15 -1
- package/dist/store/recover.d.ts +34 -0
- package/dist/store/recover.js +188 -6
- package/dist/store/refill.d.ts +28 -0
- package/dist/store/refill.js +120 -0
- package/dist/store/sqlite/accounts.js +2 -0
- package/dist/store/sqlite/base-stages.d.ts +122 -0
- package/dist/store/sqlite/base-stages.js +443 -0
- package/dist/store/sqlite/base-suggest.d.ts +13 -0
- package/dist/store/sqlite/base-suggest.js +62 -0
- package/dist/store/sqlite/business-contracts.js +10 -1
- package/dist/store/sqlite/clients.d.ts +7 -3
- package/dist/store/sqlite/clients.js +11 -7
- package/dist/store/sqlite/crm-settings.d.ts +12 -2
- package/dist/store/sqlite/crm-settings.js +56 -13
- package/dist/store/sqlite/crm.d.ts +13 -1
- package/dist/store/sqlite/crm.js +20 -4
- package/dist/store/sqlite/deals.d.ts +33 -0
- package/dist/store/sqlite/deals.js +42 -4
- package/dist/store/sqlite/decision-requests.js +7 -3
- package/dist/store/sqlite/email-index.js +17 -15
- package/dist/store/sqlite/evidence-findings.js +29 -5
- package/dist/store/sqlite/findings-core.js +4 -2
- package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
- package/dist/store/sqlite/identity-link-rows.js +146 -0
- package/dist/store/sqlite/identity-proposals.d.ts +53 -0
- package/dist/store/sqlite/identity-proposals.js +234 -0
- package/dist/store/sqlite/knowledge.js +5 -3
- package/dist/store/sqlite/link-kinds.d.ts +1 -0
- package/dist/store/sqlite/link-kinds.js +1 -0
- package/dist/store/sqlite/link-row.d.ts +6 -0
- package/dist/store/sqlite/link-row.js +35 -0
- package/dist/store/sqlite/link-source.d.ts +10 -0
- package/dist/store/sqlite/link-source.js +16 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/meeting-context-links.js +9 -6
- package/dist/store/sqlite/memories.js +9 -7
- package/dist/store/sqlite/mentions.d.ts +4 -1
- package/dist/store/sqlite/mentions.js +14 -9
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/note-index.js +9 -7
- package/dist/store/sqlite/notes.d.ts +2 -3
- package/dist/store/sqlite/notes.js +6 -29
- package/dist/store/sqlite/open-store.js +3 -0
- package/dist/store/sqlite/open.js +11 -2
- package/dist/store/sqlite/orders.d.ts +2 -0
- package/dist/store/sqlite/orders.js +9 -3
- package/dist/store/sqlite/organization-categories.d.ts +18 -0
- package/dist/store/sqlite/organization-categories.js +34 -0
- package/dist/store/sqlite/organizations.d.ts +5 -1
- package/dist/store/sqlite/organizations.js +14 -4
- package/dist/store/sqlite/person-links.d.ts +19 -4
- package/dist/store/sqlite/person-links.js +49 -11
- package/dist/store/sqlite/person-match-scan.d.ts +13 -0
- package/dist/store/sqlite/person-match-scan.js +251 -0
- package/dist/store/sqlite/person-matcher.d.ts +16 -0
- package/dist/store/sqlite/person-matcher.js +32 -0
- package/dist/store/sqlite/proposed-actions.js +6 -0
- package/dist/store/sqlite/record-matching.d.ts +2 -8
- package/dist/store/sqlite/record-matching.js +8 -40
- package/dist/store/sqlite/record-projectors-phone.js +2 -1
- package/dist/store/sqlite/record-relationships.d.ts +52 -0
- package/dist/store/sqlite/record-relationships.js +243 -0
- package/dist/store/sqlite/record-run.d.ts +5 -0
- package/dist/store/sqlite/record-run.js +62 -2
- package/dist/store/sqlite/record-writes.d.ts +1 -1
- package/dist/store/sqlite/record-writes.js +4 -2
- package/dist/store/sqlite/records.js +27 -2
- package/dist/store/sqlite/ref-accounts.d.ts +13 -0
- package/dist/store/sqlite/ref-accounts.js +117 -0
- package/dist/store/sqlite/ref-summaries.js +5 -1
- package/dist/store/sqlite/relation-list.d.ts +4 -1
- package/dist/store/sqlite/relation-list.js +20 -2
- package/dist/store/sqlite/relation-proposals.d.ts +18 -1
- package/dist/store/sqlite/relation-proposals.js +53 -11
- package/dist/store/sqlite/relation-roles.js +12 -6
- package/dist/store/sqlite/reported-relations.d.ts +11 -1
- package/dist/store/sqlite/reported-relations.js +59 -18
- package/dist/store/sqlite/schema.d.ts +32 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/dist/store/sqlite/transaction.d.ts +13 -0
- package/dist/store/sqlite/transaction.js +33 -15
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/write-events.d.ts +18 -0
- package/dist/store/write-events.js +88 -0
- package/package.json +3 -3
- package/parity.json +11 -4
- package/schemas/records-envelope.v1.schema.json +3 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { refsForLink } from "../../domain/links.js";
|
|
3
4
|
import { jsonOfAnswer, REPORT_FORMAT, withoutLeaks } from "./schema.js";
|
|
4
5
|
import { momentFor } from "./view.js";
|
|
5
6
|
const WHAT_LIMIT = 160;
|
|
@@ -188,7 +189,9 @@ const LINK_WORDS = {
|
|
|
188
189
|
};
|
|
189
190
|
const wordsOf = (language) => LINK_WORDS[language] ?? LINK_WORDS.en;
|
|
190
191
|
const linkOfRefs = (refs, linkOf, label) => {
|
|
191
|
-
const url = refs
|
|
192
|
+
const url = refsForLink(refs)
|
|
193
|
+
.map(linkOf)
|
|
194
|
+
.find((one) => one !== null);
|
|
192
195
|
return url ? [{ kind: "open", url, label }] : [];
|
|
193
196
|
};
|
|
194
197
|
export const GAPS_CAP = 15;
|
|
@@ -58,7 +58,9 @@ export interface ReportRun {
|
|
|
58
58
|
}
|
|
59
59
|
export interface PreparedReport {
|
|
60
60
|
telegram: string;
|
|
61
|
-
/**
|
|
61
|
+
/** HTML with inline CSS for `mail messages send --html`; absent for an invalid report, which goes as `text`. */
|
|
62
|
+
email?: string;
|
|
63
|
+
/** Plain text with web links: the email when the installed mail cannot send `--html`. */
|
|
62
64
|
text: string;
|
|
63
65
|
/** Plain text with app links (`wirecat://`), which a desktop terminal opens: `latest.txt`. */
|
|
64
66
|
terminal: string;
|
|
@@ -255,9 +255,10 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
255
255
|
: {};
|
|
256
256
|
const web = viewFor("web");
|
|
257
257
|
const telegram = await renderReport(web, "telegram", templateOf(templates, "telegram"));
|
|
258
|
+
const email = await renderReport(web, "email", templateOf(templates, "email"));
|
|
258
259
|
const text = await renderReport(web, "text", templateOf(templates, "text"));
|
|
259
260
|
const terminal = await renderReport(viewFor("app"), "text", templateOf(templates, "text"));
|
|
260
|
-
const renderings = [telegram, text, terminal];
|
|
261
|
+
const renderings = [telegram, email, text, terminal];
|
|
261
262
|
const reasons = [
|
|
262
263
|
...(lookupFailed || renderings.some((one) => one.templateFailed) ? [REPORT_REASONS.templateFailed] : []),
|
|
263
264
|
...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
|
|
@@ -265,6 +266,7 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
265
266
|
const title = text.text.split("\n")[0] ?? "";
|
|
266
267
|
return {
|
|
267
268
|
telegram: telegram.text,
|
|
269
|
+
email: email.text,
|
|
268
270
|
text: text.text,
|
|
269
271
|
terminal: terminal.text,
|
|
270
272
|
document: `${JSON.stringify(reportDocument(parsed.report), null, 2)}\n`,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { refsForLink } from "../../domain/links.js";
|
|
1
2
|
const LINK_WORDS = {
|
|
2
3
|
ru: { open: "открыть", fix: "исправить" },
|
|
3
4
|
en: { open: "open", fix: "fix" },
|
|
@@ -126,7 +127,9 @@ export const reportView = (report, { language, now, timeZone, linkOf = () => nul
|
|
|
126
127
|
const moment = (iso) => (iso === null ? null : momentFor(iso, now, language, timeZone));
|
|
127
128
|
const words = LINK_WORDS[language] ?? LINK_WORDS.en;
|
|
128
129
|
const linksOf = (refs, label) => {
|
|
129
|
-
const url = refs
|
|
130
|
+
const url = refsForLink(refs)
|
|
131
|
+
.map(linkOf)
|
|
132
|
+
.find((one) => one !== null);
|
|
130
133
|
return url ? [{ kind: "open", url, label }] : [];
|
|
131
134
|
};
|
|
132
135
|
const itemOf = (item) => {
|
|
@@ -161,10 +161,14 @@ export declare const launchdTimer: (app: AppIdentity, system: ServerSystem, env:
|
|
|
161
161
|
*/
|
|
162
162
|
export declare const windowsTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|
|
163
163
|
export declare const timerFor: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|
|
164
|
+
/** The shared `links` settings; a config file that cannot be read keeps the default rather than stop a digest. */
|
|
165
|
+
export declare const sharedLinks: (env: NodeJS.ProcessEnv) => import("../domain/links.js").LinkConfig;
|
|
164
166
|
/** A desktop notification; a machine without one loses only the notice, never the run. */
|
|
165
167
|
export declare const notify: (system: ServerSystem, env: NodeJS.ProcessEnv, title: string, body: string) => Promise<boolean>;
|
|
166
168
|
/** Finds a program on PATH, as the timer will not have the shell's PATH to find it by. */
|
|
167
169
|
export declare const findProgram: (name: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform) => string | undefined;
|
|
170
|
+
/** How long a stopped child has to save and answer after SIGTERM before it is killed. */
|
|
171
|
+
export declare const KILL_AFTER_MS = 10000;
|
|
168
172
|
/**
|
|
169
173
|
* The reason tg and max give when a profile that has logged in here cannot read its sign-in: the keyring is
|
|
170
174
|
* locked or out of reach, which a later try fixes and a new login does not.
|
|
@@ -199,3 +203,16 @@ export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env:
|
|
|
199
203
|
*/
|
|
200
204
|
skipRepeatedInput?: boolean;
|
|
201
205
|
}) => Promise<LastRun>;
|
|
206
|
+
/** One run of the schedule's command or agent: its output in `runs/`, its result in `last.json`. */
|
|
207
|
+
export declare const attemptSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, schedule: Schedule, folder: string, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput, at, }: {
|
|
208
|
+
now: () => Date;
|
|
209
|
+
signal: AbortSignal | undefined;
|
|
210
|
+
killAfterMs: number;
|
|
211
|
+
agentRuns: readonly AgentCli[];
|
|
212
|
+
agentInput: AgentInput | undefined;
|
|
213
|
+
skipRepeatedInput?: boolean;
|
|
214
|
+
/** A backfill's run time: the files are named for it, and `last.json` is left as it is. */
|
|
215
|
+
at?: Date;
|
|
216
|
+
}) => Promise<LastRun | {
|
|
217
|
+
repeated: LastRun;
|
|
218
|
+
}>;
|
|
@@ -349,7 +349,7 @@ export const timerFor = (app, system, env) => {
|
|
|
349
349
|
throw new CliError("validation_error", `${app.command} schedule knows Linux, macOS and Windows, not ${system.platform}`);
|
|
350
350
|
};
|
|
351
351
|
/** The shared `links` settings; a config file that cannot be read keeps the default rather than stop a digest. */
|
|
352
|
-
const sharedLinks = (env) => {
|
|
352
|
+
export const sharedLinks = (env) => {
|
|
353
353
|
try {
|
|
354
354
|
return linkConfigOf(readSharedSection(sharedConfigPath(storePath(env), env), "links"));
|
|
355
355
|
}
|
|
@@ -432,7 +432,7 @@ export const findProgram = (name, env, platform) => {
|
|
|
432
432
|
};
|
|
433
433
|
const KEEP_RUNS = 30;
|
|
434
434
|
/** How long a stopped child has to save and answer after SIGTERM before it is killed. */
|
|
435
|
-
const KILL_AFTER_MS = 10_000;
|
|
435
|
+
export const KILL_AFTER_MS = 10_000;
|
|
436
436
|
/**
|
|
437
437
|
* The reason tg and max give when a profile that has logged in here cannot read its sign-in: the keyring is
|
|
438
438
|
* locked or out of reach, which a later try fixes and a new login does not.
|
|
@@ -523,7 +523,9 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
523
523
|
else if (agent && exitCode === 0)
|
|
524
524
|
rmSync(latestText, { force: true });
|
|
525
525
|
const stampOf = (file) => file.split(".")[0] ?? file;
|
|
526
|
-
const
|
|
526
|
+
const stamps = [...new Set(readdirSync(runs).map(stampOf))].sort();
|
|
527
|
+
const old = new Set(stamps.filter((stamp) => backfilled(runs, stamp)));
|
|
528
|
+
const kept = new Set([...stamps.filter((stamp) => !old.has(stamp)).slice(-KEEP_RUNS), ...old]);
|
|
527
529
|
for (const file of readdirSync(runs))
|
|
528
530
|
if (!kept.has(stampOf(file)))
|
|
529
531
|
rmSync(join(runs, file), { force: true });
|
|
@@ -650,9 +652,9 @@ const inputOf = async (agentInput, system, env, schedule, log) => {
|
|
|
650
652
|
}
|
|
651
653
|
};
|
|
652
654
|
/** One run of the schedule's command or agent: its output in `runs/`, its result in `last.json`. */
|
|
653
|
-
const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput = false, }) => {
|
|
655
|
+
export const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput = false, at, }) => {
|
|
654
656
|
const runs = join(folder, "runs");
|
|
655
|
-
const stamp = now()
|
|
657
|
+
const stamp = (at ?? now())
|
|
656
658
|
.toISOString()
|
|
657
659
|
.replaceAll(":", "-")
|
|
658
660
|
.replace(/\.\d+Z$/, "Z");
|
|
@@ -736,13 +738,24 @@ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal
|
|
|
736
738
|
durationMs: ended.getTime() - began,
|
|
737
739
|
...(costUsd === undefined ? {} : { costUsd }),
|
|
738
740
|
});
|
|
739
|
-
|
|
740
|
-
at: ended.toISOString(),
|
|
741
|
+
const run = {
|
|
742
|
+
at: (at ?? ended).toISOString(),
|
|
741
743
|
exitCode,
|
|
742
744
|
output,
|
|
743
745
|
traceId: trace.traceId,
|
|
744
746
|
...(costUsd === undefined ? {} : { costUsd }),
|
|
745
747
|
...(inputHash === undefined ? {} : { inputHash }),
|
|
746
748
|
...(exitCode === 0 ? {} : failureOf(readFileSync(errors, "utf8"), exitCode)),
|
|
747
|
-
}
|
|
749
|
+
};
|
|
750
|
+
return at ? run : recordRun(join(folder, "last.json"), run);
|
|
751
|
+
};
|
|
752
|
+
/** A backfilled run is older than the runs it joins, so the count that keeps the newest runs would remove it first. */
|
|
753
|
+
const backfilled = (runs, stamp) => {
|
|
754
|
+
const document = join(runs, `${stamp}.report.json`);
|
|
755
|
+
try {
|
|
756
|
+
return (existsSync(document) && JSON.parse(readFileSync(document, "utf8")).backfill === true);
|
|
757
|
+
}
|
|
758
|
+
catch {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
748
761
|
};
|
|
@@ -487,6 +487,7 @@ export declare const calendarLinkedPerson: v.StrictObjectSchema<{
|
|
|
487
487
|
readonly person: v.StringSchema<undefined>;
|
|
488
488
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
489
489
|
readonly identities: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
490
|
+
readonly proposal: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
490
491
|
}, undefined>;
|
|
491
492
|
export declare const calendarLinkReview: v.StrictObjectSchema<{
|
|
492
493
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
@@ -238,7 +238,12 @@ export const calendarEventPreparation = v.strictObject({
|
|
|
238
238
|
limits: v.strictObject({ people: count, messages: count, bytes: count }),
|
|
239
239
|
untrusted,
|
|
240
240
|
});
|
|
241
|
-
export const calendarLinkedPerson = v.strictObject({
|
|
241
|
+
export const calendarLinkedPerson = v.strictObject({
|
|
242
|
+
person: text,
|
|
243
|
+
name: nullableText,
|
|
244
|
+
identities: v.array(text),
|
|
245
|
+
proposal: v.optional(text),
|
|
246
|
+
});
|
|
242
247
|
export const calendarLinkReview = v.strictObject({
|
|
243
248
|
id,
|
|
244
249
|
entry_id: id,
|
|
@@ -14,7 +14,6 @@ import { secretInput } from "../../runs/run-context.js";
|
|
|
14
14
|
import { searchEvents } from "../../services/events-search.js";
|
|
15
15
|
import { dateWindow } from "../../services/moment.js";
|
|
16
16
|
import { embedEvents } from "../../services/notes-search.js";
|
|
17
|
-
import { linkPeople } from "../../services/people.js";
|
|
18
17
|
import { BUSY_QUERY, BUSY_QUERY_NOTE, busyAnswer, busyQuery, workingHoursOf } from "../busy.js";
|
|
19
18
|
import { isFeedCalendar, isPlainHttp, syncWithFeeds } from "../feeds.js";
|
|
20
19
|
import { eventPreparation, nextMeeting, PREPARE_MESSAGES } from "../prepare.js";
|
|
@@ -27,6 +26,7 @@ import { CALENDARS_QUERY, declareCalendarAnswers, PEOPLE_QUERY } from "./answers
|
|
|
27
26
|
import { hitsBody, itemBody, listBody, messagesOf, pathOf } from "./bodies.js";
|
|
28
27
|
import { ICS_MAX_BYTES, readIcsFile, writeIcsFile } from "./files.js";
|
|
29
28
|
import { localTimesView } from "./local-times.js";
|
|
29
|
+
import { addPeopleLink } from "./people-link.js";
|
|
30
30
|
import { addRemind } from "./remind.js";
|
|
31
31
|
import { addSearchAll } from "./search-all.js";
|
|
32
32
|
const LOCAL_READ = { remote: "none", local: "read" };
|
|
@@ -444,19 +444,7 @@ const addCalendarCommandsDefinition = (program, options) => {
|
|
|
444
444
|
return listBody(command, eachMarked(found, ATTENDEE_UNTRUSTED));
|
|
445
445
|
});
|
|
446
446
|
});
|
|
447
|
-
|
|
448
|
-
.description("join an attendee to a person the owner knows elsewhere")
|
|
449
|
-
.argument("<person>", "an attendee's address as email:<address>, or a person:<id>")
|
|
450
|
-
.argument("<other>", "the same person in another tool, as <provider>:<person>, or me"), "people link email:ana@example.com telegram:12345").action(async (person, other, _opts, command) => {
|
|
451
|
-
await within(command, async (run) => {
|
|
452
|
-
const linked = await linkPeople(messagesOf(run, "people link"), run.account, person, other);
|
|
453
|
-
return itemBody({
|
|
454
|
-
person: `person:${linked.uid}`,
|
|
455
|
-
name: linked.name,
|
|
456
|
-
identities: linked.identities.map(({ provider, id }) => `${provider}:${id}`),
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
});
|
|
447
|
+
addPeopleLink(people, { within, example });
|
|
460
448
|
const links = annotate(program.command("links").description("calendar copies the rules could not join alone"), {
|
|
461
449
|
effects: GROUP,
|
|
462
450
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { actorOf } from "../../cli/author.js";
|
|
3
|
+
import { LOCAL_WRITE } from "../../cli/effects.js";
|
|
4
|
+
import { linkPeople } from "../../services/people.js";
|
|
5
|
+
import { itemBody, messagesOf } from "./bodies.js";
|
|
6
|
+
export const addPeopleLink = (people, { within, example }) => example(annotate(people.command("link"), { effects: LOCAL_WRITE })
|
|
7
|
+
.description("join an attendee to a person the owner knows elsewhere")
|
|
8
|
+
.argument("<person>", "an attendee's address as email:<address>, or a person:<id>")
|
|
9
|
+
.argument("<other>", "the same person in another tool, as <provider>:<person>, or me")
|
|
10
|
+
.option("--reason <text>", "why they are one person; an agent's link is a proposal and needs it"), "people link email:ana@example.com telegram:12345").action(async (person, other, opts, command) => {
|
|
11
|
+
await within(command, async (run) => {
|
|
12
|
+
const linked = await linkPeople(messagesOf(run, "people link"), run.account, person, other, {
|
|
13
|
+
by: actorOf(command),
|
|
14
|
+
reason: opts.reason,
|
|
15
|
+
});
|
|
16
|
+
return itemBody({
|
|
17
|
+
person: `person:${linked.uid}`,
|
|
18
|
+
name: linked.name,
|
|
19
|
+
identities: linked.identities.map(({ provider, id }) => `${provider}:${id}`),
|
|
20
|
+
...(linked.proposal === undefined ? {} : { proposal: linked.proposal }),
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/dist/calendar/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { CalendarAccessRole, CalendarInput, EntryAttachment, EntryAttachmen
|
|
|
2
2
|
export { expandSeries, localMoment, unexpandable } from "./expand.js";
|
|
3
3
|
export { type CalendarFeeds, FEED_LIMITS, FEED_PREFIX, type FeedLimits, type FeedRecord, type FeedRegistry, type FeedSyncStats, type FeedsSyncReport, feedAddress, fetchFeed, icsFeeds, isFeedCalendar, readFeed, syncWithFeeds, } from "./feeds.js";
|
|
4
4
|
export { type IcsEvent, type IcsOverride, type IcsRead, type IcsSkip, readIcs, writeIcs } from "./ics.js";
|
|
5
|
-
export { accountsMeta } from "./reads.js";
|
|
5
|
+
export { accountsMeta, EVENT_TYPES, EVENTS_QUERY, EVENTS_QUERY_NOTE, eventAnswer, eventOf, eventsAnswer, eventsFilter, type ReadAccount, sourceAccounts, } from "./reads.js";
|
|
6
6
|
export { repeatRule } from "./recurrence.js";
|
|
7
7
|
export type { BusyTimes, CalendarExpander, CalendarSource, CalendarSourceTraits, ChangePage, ChangeResult, FreeBusyRequest, SearchPage, SyncWindow, } from "./source.js";
|
|
8
8
|
export { type CalendarCursor, type CalendarSyncOptions, type CalendarSyncReport, type CalendarSyncResult, calendarStatus, calendarSyncWindow, type PendingRound, parseCalendarCursor, syncCalendars, } from "./sync.js";
|
package/dist/calendar/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { expandSeries, localMoment, unexpandable } from "./expand.js";
|
|
2
2
|
export { FEED_LIMITS, FEED_PREFIX, feedAddress, fetchFeed, icsFeeds, isFeedCalendar, readFeed, syncWithFeeds, } from "./feeds.js";
|
|
3
3
|
export { readIcs, writeIcs } from "./ics.js";
|
|
4
|
-
export { accountsMeta } from "./reads.js";
|
|
4
|
+
export { accountsMeta, EVENT_TYPES, EVENTS_QUERY, EVENTS_QUERY_NOTE, eventAnswer, eventOf, eventsAnswer, eventsFilter, sourceAccounts, } from "./reads.js";
|
|
5
5
|
export { repeatRule } from "./recurrence.js";
|
|
6
6
|
export { calendarStatus, calendarSyncWindow, parseCalendarCursor, syncCalendars, } from "./sync.js";
|
|
7
7
|
export { CALENDAR_WRITE_DEFAULTS, CALENDAR_WRITE_KEYS, calendarConflict, EVENTS_DELETE_SERIES_KEY, EVENTS_NOTIFY_KEY, EVENTS_REMIND_HOOK_KEY, } from "./writer.js";
|
|
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
|
|
|
10
10
|
inputSchema: {
|
|
11
11
|
type: string;
|
|
12
12
|
properties: {
|
|
13
|
+
limit?: undefined;
|
|
13
14
|
account_id: {
|
|
14
15
|
type: string;
|
|
15
16
|
minimum: number;
|
|
16
17
|
};
|
|
17
18
|
query?: undefined;
|
|
18
19
|
timezone?: undefined;
|
|
19
|
-
limit?: undefined;
|
|
20
20
|
page?: undefined;
|
|
21
21
|
event?: undefined;
|
|
22
22
|
} | {
|
|
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
|
|
|
45
45
|
};
|
|
46
46
|
event?: undefined;
|
|
47
47
|
} | {
|
|
48
|
+
limit?: undefined;
|
|
48
49
|
query?: undefined;
|
|
49
50
|
timezone?: undefined;
|
|
50
|
-
limit?: undefined;
|
|
51
51
|
page?: undefined;
|
|
52
52
|
event: {
|
|
53
53
|
type: string;
|
|
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
|
|
|
58
58
|
minimum: number;
|
|
59
59
|
};
|
|
60
60
|
} | {
|
|
61
|
+
limit?: undefined;
|
|
61
62
|
query?: undefined;
|
|
62
63
|
timezone?: undefined;
|
|
63
|
-
limit?: undefined;
|
|
64
64
|
page?: undefined;
|
|
65
65
|
event?: undefined;
|
|
66
66
|
account_id?: undefined;
|
|
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
|
|
|
80
80
|
inputSchema: {
|
|
81
81
|
type: string;
|
|
82
82
|
properties: {
|
|
83
|
+
limit?: undefined;
|
|
83
84
|
account_id: {
|
|
84
85
|
type: string;
|
|
85
86
|
minimum: number;
|
|
86
87
|
};
|
|
87
88
|
query?: undefined;
|
|
88
89
|
timezone?: undefined;
|
|
89
|
-
limit?: undefined;
|
|
90
90
|
page?: undefined;
|
|
91
91
|
event?: undefined;
|
|
92
92
|
} | {
|
|
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
|
|
|
115
115
|
};
|
|
116
116
|
event?: undefined;
|
|
117
117
|
} | {
|
|
118
|
+
limit?: undefined;
|
|
118
119
|
query?: undefined;
|
|
119
120
|
timezone?: undefined;
|
|
120
|
-
limit?: undefined;
|
|
121
121
|
page?: undefined;
|
|
122
122
|
event: {
|
|
123
123
|
type: string;
|
|
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
|
|
|
128
128
|
minimum: number;
|
|
129
129
|
};
|
|
130
130
|
} | {
|
|
131
|
+
limit?: undefined;
|
|
131
132
|
query?: undefined;
|
|
132
133
|
timezone?: undefined;
|
|
133
|
-
limit?: undefined;
|
|
134
134
|
page?: undefined;
|
|
135
135
|
event?: undefined;
|
|
136
136
|
account_id?: undefined;
|
|
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
|
|
|
150
150
|
inputSchema: {
|
|
151
151
|
type: string;
|
|
152
152
|
properties: {
|
|
153
|
+
limit?: undefined;
|
|
153
154
|
account_id: {
|
|
154
155
|
type: string;
|
|
155
156
|
minimum: number;
|
|
156
157
|
};
|
|
157
158
|
query?: undefined;
|
|
158
159
|
timezone?: undefined;
|
|
159
|
-
limit?: undefined;
|
|
160
160
|
page?: undefined;
|
|
161
161
|
event?: undefined;
|
|
162
162
|
} | {
|
|
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
|
|
|
185
185
|
};
|
|
186
186
|
event?: undefined;
|
|
187
187
|
} | {
|
|
188
|
+
limit?: undefined;
|
|
188
189
|
query?: undefined;
|
|
189
190
|
timezone?: undefined;
|
|
190
|
-
limit?: undefined;
|
|
191
191
|
page?: undefined;
|
|
192
192
|
event: {
|
|
193
193
|
type: string;
|
|
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
|
|
|
198
198
|
minimum: number;
|
|
199
199
|
};
|
|
200
200
|
} | {
|
|
201
|
+
limit?: undefined;
|
|
201
202
|
query?: undefined;
|
|
202
203
|
timezone?: undefined;
|
|
203
|
-
limit?: undefined;
|
|
204
204
|
page?: undefined;
|
|
205
205
|
event?: undefined;
|
|
206
206
|
account_id?: undefined;
|
|
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
|
|
|
220
220
|
inputSchema: {
|
|
221
221
|
type: string;
|
|
222
222
|
properties: {
|
|
223
|
+
limit?: undefined;
|
|
223
224
|
account_id: {
|
|
224
225
|
type: string;
|
|
225
226
|
minimum: number;
|
|
226
227
|
};
|
|
227
228
|
query?: undefined;
|
|
228
229
|
timezone?: undefined;
|
|
229
|
-
limit?: undefined;
|
|
230
230
|
page?: undefined;
|
|
231
231
|
event?: undefined;
|
|
232
232
|
} | {
|
|
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
|
|
|
255
255
|
};
|
|
256
256
|
event?: undefined;
|
|
257
257
|
} | {
|
|
258
|
+
limit?: undefined;
|
|
258
259
|
query?: undefined;
|
|
259
260
|
timezone?: undefined;
|
|
260
|
-
limit?: undefined;
|
|
261
261
|
page?: undefined;
|
|
262
262
|
event: {
|
|
263
263
|
type: string;
|
|
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
|
|
|
268
268
|
minimum: number;
|
|
269
269
|
};
|
|
270
270
|
} | {
|
|
271
|
+
limit?: undefined;
|
|
271
272
|
query?: undefined;
|
|
272
273
|
timezone?: undefined;
|
|
273
|
-
limit?: undefined;
|
|
274
274
|
page?: undefined;
|
|
275
275
|
event?: undefined;
|
|
276
276
|
account_id?: undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
+
import type { MessageStore } from "../store/store.js";
|
|
4
|
+
import type { AccountKey } from "../store/types.js";
|
|
5
|
+
import { type Body } from "./envelope.js";
|
|
6
|
+
export interface BaseStagesCommandOptions {
|
|
7
|
+
/** The run's environment, read for an agent's markers: an agent suggests mappings, the owner confirms and edits. */
|
|
8
|
+
env: () => NodeJS.ProcessEnv;
|
|
9
|
+
/** The store for one command; the command closes it once its answer is built. */
|
|
10
|
+
open: (command: Command) => Promise<MessageStore>;
|
|
11
|
+
output: (answer: Body, command: Command) => void;
|
|
12
|
+
/**
|
|
13
|
+
* The CRM accounts the run may read and change, such as a group lock's; `undefined` for all. The owner's own
|
|
14
|
+
* pipelines are always in.
|
|
15
|
+
*/
|
|
16
|
+
accounts?: (store: MessageStore, command: Command) => Promise<readonly AccountKey[] | undefined>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `stages …`: the owner's base stages of deals and of leads, and the stages of every other pipeline mapped onto them. memo mounts it; a CRM
|
|
20
|
+
* CLI moves a card to a base stage with `deals move <ref> stage:<id>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const baseStagesCommand: (app: AppIdentity, options: BaseStagesCommandOptions) => Command;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { Argument, Command, InvalidArgumentError, Option } from "commander";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
import { DEAL_KINDS, STAGE_OUTCOMES } from "../domain/deals.js";
|
|
6
|
+
import { count, reference, text, untrusted } from "../entities/fields.js";
|
|
7
|
+
import { agentOf } from "../runs/run-context.js";
|
|
8
|
+
import { answerEntity } from "./answer-entity.js";
|
|
9
|
+
import { environmentOf } from "./context.js";
|
|
10
|
+
import { LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
11
|
+
import { itemOf, listOf, snakeKeys } from "./envelope.js";
|
|
12
|
+
import { queryTerms, termField, withQuery } from "./list-query.js";
|
|
13
|
+
const outcome = v.picklist(STAGE_OUTCOMES);
|
|
14
|
+
const kind = v.picklist(DEAL_KINDS);
|
|
15
|
+
const named = v.strictObject({ ref: reference, name: text });
|
|
16
|
+
const baseSet = v.strictObject({
|
|
17
|
+
kind,
|
|
18
|
+
/** `null`, with each stage's `ref`, only when a read-only store is read before the set's first use made it. */
|
|
19
|
+
pipeline: v.nullable(reference),
|
|
20
|
+
stages: v.array(v.strictObject({ ref: v.nullable(reference), name: text, position: count, outcome, open: count, mapped: count })),
|
|
21
|
+
unsorted: v.strictObject({ open: count, stages: count }),
|
|
22
|
+
});
|
|
23
|
+
const stageMapping = v.strictObject({
|
|
24
|
+
...named.entries,
|
|
25
|
+
position: count,
|
|
26
|
+
outcome,
|
|
27
|
+
external_id: v.nullable(text),
|
|
28
|
+
kind,
|
|
29
|
+
pipeline: reference,
|
|
30
|
+
pipeline_name: text,
|
|
31
|
+
account: v.nullable(v.strictObject({ provider: text, account: text })),
|
|
32
|
+
base_stage: v.nullable(named),
|
|
33
|
+
confirmed: v.boolean(),
|
|
34
|
+
open: count,
|
|
35
|
+
untrusted,
|
|
36
|
+
});
|
|
37
|
+
/** A CRM's users named its stages and pipelines; the base set's names are the owner's. */
|
|
38
|
+
const MAPPING_UNTRUSTED = ["name", "pipeline_name"];
|
|
39
|
+
/** What `stages list` narrows by. */
|
|
40
|
+
const MAPPING_QUERY = {
|
|
41
|
+
entity: "stage_mapping",
|
|
42
|
+
backend: "native",
|
|
43
|
+
fields: [
|
|
44
|
+
termField("kind", "enum", "kind:deal", { values: DEAL_KINDS }),
|
|
45
|
+
termField("pipeline", "kw", "pipeline:Sales", { relation: "pipeline:<id>, or a name only one pipeline has" }),
|
|
46
|
+
termField("confirmed", "bool", "confirmed:false"),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
const position = (value) => {
|
|
50
|
+
if (!/^[1-9]\d*$/.test(value))
|
|
51
|
+
throw new InvalidArgumentError("expected a position from 1");
|
|
52
|
+
return Number(value);
|
|
53
|
+
};
|
|
54
|
+
const kindArgument = () => new Argument("<kind>", "deal or lead: which base set").choices(DEAL_KINDS);
|
|
55
|
+
/**
|
|
56
|
+
* `stages …`: the owner's base stages of deals and of leads, and the stages of every other pipeline mapped onto them. memo mounts it; a CRM
|
|
57
|
+
* CLI moves a card to a base stage with `deals move <ref> stage:<id>`.
|
|
58
|
+
*/
|
|
59
|
+
export const baseStagesCommand = (app, options) => {
|
|
60
|
+
const isAgent = (command) => Boolean(environmentOf(command).agent || agentOf(options.env()));
|
|
61
|
+
// A guard against a change by mistake, not a boundary, as the owner-only store settings are.
|
|
62
|
+
const ownerOnly = (command, what) => {
|
|
63
|
+
if (isAgent(command))
|
|
64
|
+
throw new CliError("permission_error", `${what} is the owner's to do, in a terminal: an agent's run is stopped from changing it by mistake`, { reason: "stage.owner-only" });
|
|
65
|
+
};
|
|
66
|
+
const run = async (command, work) => {
|
|
67
|
+
const store = await options.open(command);
|
|
68
|
+
let body;
|
|
69
|
+
try {
|
|
70
|
+
const accounts = await options.accounts?.(store, command);
|
|
71
|
+
body = await work(store, accounts === undefined ? {} : { accounts });
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await store.close();
|
|
75
|
+
}
|
|
76
|
+
options.output(body, command);
|
|
77
|
+
};
|
|
78
|
+
const stages = annotate(new Command("stages"), { effects: LOCAL_READ })
|
|
79
|
+
.description("the owner's base stages of deals and of leads, the columns of a board across every pipeline and CRM, and " +
|
|
80
|
+
"how each other pipeline's stage maps onto them")
|
|
81
|
+
.summary("base stages and the stages mapped onto them");
|
|
82
|
+
const leaf = (name, effects, summary, ...examples) => annotate(stages.command(name), {
|
|
83
|
+
effects,
|
|
84
|
+
examples: examples.map((line) => `${app.command} stages ${line}`),
|
|
85
|
+
}).summary(summary);
|
|
86
|
+
const setAnswer = (set) => itemOf(snakeKeys(set));
|
|
87
|
+
const setCommand = (name, summary, ...examples) => answerEntity(leaf(name, LOCAL_WRITE, summary, ...examples), "base_stage_set", baseSet)
|
|
88
|
+
.addArgument(kindArgument())
|
|
89
|
+
.hook("preAction", (_root, command) => ownerOnly(command, `stages ${name}`));
|
|
90
|
+
const mappingRow = (row) => ({ ...snakeKeys(row), untrusted: MAPPING_UNTRUSTED });
|
|
91
|
+
const baseStage = "the base stage, by its stage:<id> or its name";
|
|
92
|
+
answerEntity(leaf("show", LOCAL_READ, "a base set's columns with what each holds", "show deal", "show lead --json"), "base_stage_set", baseSet)
|
|
93
|
+
.description("the base set in order, with the open rows and mapped stages each column holds, and what is unsorted (unmapped " +
|
|
94
|
+
"or only suggested); the first use takes the owner's only own pipeline of the kind, or makes the default set in " +
|
|
95
|
+
"the owner's language; a read-only store shows that set without making it")
|
|
96
|
+
.addArgument(kindArgument())
|
|
97
|
+
.action(async (chosen, _opts, command) => {
|
|
98
|
+
await run(command, async (store, scope) => setAnswer(await store.baseStages.show(chosen, scope)));
|
|
99
|
+
});
|
|
100
|
+
setCommand("create", "add a stage to a base set", 'create deal "Demo"', 'create lead "Spam" lost')
|
|
101
|
+
.description("add a stage to the base set: an open one goes before the first won or lost stage, a won or lost one last; " +
|
|
102
|
+
"move puts it elsewhere")
|
|
103
|
+
.argument("<name>", "the stage's name, once in its set")
|
|
104
|
+
.addArgument(new Argument("[outcome]", "open, won or lost; open by default").choices(STAGE_OUTCOMES))
|
|
105
|
+
.action(async (chosen, name, given, _opts, command) => {
|
|
106
|
+
await run(command, async (store) => setAnswer(await store.baseStages.add(chosen, { name, ...(given === undefined ? {} : { outcome: given }) })));
|
|
107
|
+
});
|
|
108
|
+
setCommand("rename", "rename a base stage", 'rename deal Proposal "Quote sent"')
|
|
109
|
+
.description("rename a base stage; what maps to it stays mapped")
|
|
110
|
+
.argument("<stage>", baseStage)
|
|
111
|
+
.argument("<name>", "its new name")
|
|
112
|
+
.action(async (chosen, stage, name, _opts, command) => {
|
|
113
|
+
await run(command, async (store) => setAnswer(await store.baseStages.rename(chosen, stage, name)));
|
|
114
|
+
});
|
|
115
|
+
setCommand("move", "put a base stage at another place in its set", "move deal Negotiation 2")
|
|
116
|
+
.description("put a base stage at another place in its set; unconfirmed suggestions follow the new order")
|
|
117
|
+
.argument("<stage>", baseStage)
|
|
118
|
+
.argument("<position>", "its new place, from 1", position)
|
|
119
|
+
.action(async (chosen, stage, at, _opts, command) => {
|
|
120
|
+
await run(command, async (store) => setAnswer(await store.baseStages.move(chosen, stage, at)));
|
|
121
|
+
});
|
|
122
|
+
setCommand("remove", "take a stage out of a base set", "remove deal Negotiation")
|
|
123
|
+
.description("take a stage out of the base set: refused for the last of its outcome and for one the owner's own rows stood " +
|
|
124
|
+
"in; what was mapped to it waits for a new confirm")
|
|
125
|
+
.argument("<stage>", baseStage)
|
|
126
|
+
.action(async (chosen, stage, _opts, command) => {
|
|
127
|
+
await run(command, async (store) => setAnswer(await store.baseStages.remove(chosen, stage)));
|
|
128
|
+
});
|
|
129
|
+
withQuery(answerEntity(leaf("list", LOCAL_READ, "every mapped stage with its base stage, confirmed or suggested", "list confirmed:false", "list kind:deal pipeline:pipeline:3 --json"), "stage_mapping", stageMapping).description("every stage outside the base sets in scope, a CRM's or an own pipeline's, with the base stage it maps to, and whether the owner confirmed that or it is the " +
|
|
130
|
+
"store's suggestion"), MAPPING_QUERY).action(async (words, _opts, command) => {
|
|
131
|
+
const terms = queryTerms(words, MAPPING_QUERY, "stages list");
|
|
132
|
+
await run(command, async (store, scope) => {
|
|
133
|
+
const rows = await store.baseStages.mappings({
|
|
134
|
+
...scope,
|
|
135
|
+
...(terms.has("kind") ? { kind: terms.get("kind") } : {}),
|
|
136
|
+
...(terms.has("pipeline") ? { pipeline: terms.get("pipeline") } : {}),
|
|
137
|
+
});
|
|
138
|
+
const confirmed = terms.get("confirmed");
|
|
139
|
+
const shown = confirmed === undefined ? rows : rows.filter((row) => row.confirmed === (confirmed === "true"));
|
|
140
|
+
return listOf("stages list", {
|
|
141
|
+
items: shown.map(mappingRow),
|
|
142
|
+
limit: Math.max(1, shown.length),
|
|
143
|
+
page: 1,
|
|
144
|
+
has_more: false,
|
|
145
|
+
...(words.length ? { args: { query: words } } : {}),
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
answerEntity(leaf("set", LOCAL_WRITE, "map one stage onto a base stage, confirmed", "set stage:41 Proposal"), "stage_mapping", stageMapping)
|
|
150
|
+
.description("map one stage of a CRM or own pipeline onto a base stage of its kind, confirmed, so a later sync keeps it; an agent's run records " +
|
|
151
|
+
"it as a suggestion the owner confirms")
|
|
152
|
+
.argument("<stage>", "the stage, by its stage:<id> as stages list shows it")
|
|
153
|
+
.argument("<base-stage>", baseStage)
|
|
154
|
+
.action(async (stage, target, _opts, command) => {
|
|
155
|
+
await run(command, async (store, scope) => itemOf(mappingRow(await store.baseStages.map(stage, target, scope, { confirmed: !isAgent(command) }))));
|
|
156
|
+
});
|
|
157
|
+
answerEntity(leaf("confirm", LOCAL_WRITE, "confirm the suggested mappings of a pipeline, or of all", "confirm --pipeline pipeline:3", "confirm --all"), "stage_mapping_confirm", v.strictObject({ confirmed: count }))
|
|
158
|
+
.description("confirm every suggestion of one pipeline, or of all of them in scope, as it stands")
|
|
159
|
+
.option("--pipeline <pipeline>", "pipeline:<id>, or a name only one pipeline has")
|
|
160
|
+
.option("--all", "every pipeline in scope")
|
|
161
|
+
.addOption(new Option("--kind <kind>", "with --all: only deal or only lead stages").choices(DEAL_KINDS))
|
|
162
|
+
.action(async (opts, command) => {
|
|
163
|
+
ownerOnly(command, "stages confirm");
|
|
164
|
+
if ((opts.pipeline === undefined) === (opts.all !== true))
|
|
165
|
+
throw new CliError("validation_error", "give --pipeline <pipeline> or --all", { reason: "stage.base-field" });
|
|
166
|
+
await run(command, async (store, scope) => {
|
|
167
|
+
const target = opts.pipeline === undefined
|
|
168
|
+
? { all: true, ...(opts.kind === undefined ? {} : { kind: opts.kind }) }
|
|
169
|
+
: { pipeline: opts.pipeline };
|
|
170
|
+
return itemOf({ confirmed: await store.baseStages.confirm(target, scope) });
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
return stages;
|
|
174
|
+
};
|
|
@@ -8,6 +8,7 @@ export interface SavedRunSettings {
|
|
|
8
8
|
record?: boolean | undefined;
|
|
9
9
|
keepRunsForDays?: number | undefined;
|
|
10
10
|
keepSuccessfulRunsForDays?: number | undefined;
|
|
11
|
+
keepStoreRunsForDays?: number | undefined;
|
|
11
12
|
runsSizeLimitMb?: number | undefined;
|
|
12
13
|
/** `record_input`: left out, the typed words are kept, secrets hidden. */
|
|
13
14
|
recordInput?: RecordInput | undefined;
|
|
@@ -17,6 +18,7 @@ export interface RunSettings {
|
|
|
17
18
|
keepFailedRuns: boolean;
|
|
18
19
|
keepRunsForDays: number;
|
|
19
20
|
keepSuccessfulRunsForDays: number;
|
|
21
|
+
keepStoreRunsForDays: number;
|
|
20
22
|
runsSizeLimitMb: number;
|
|
21
23
|
}
|
|
22
24
|
/**
|