@wirecat/cli-core 0.676.0 → 0.678.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/background/report/render.d.ts +3 -1
  4. package/dist/background/report/render.js +2 -2
  5. package/dist/background/report/schema.d.ts +7 -4
  6. package/dist/background/report/schema.js +23 -7
  7. package/dist/background/report/templates/morning-digest.email.en.liquid +3 -2
  8. package/dist/background/report/templates/morning-digest.email.ru.liquid +3 -2
  9. package/dist/background/report/templates/morning-digest.telegram.en.liquid +3 -2
  10. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +3 -2
  11. package/dist/background/report/templates/morning-digest.text.en.liquid +3 -2
  12. package/dist/background/report/templates/morning-digest.text.ru.liquid +3 -2
  13. package/dist/background/report/view.js +2 -0
  14. package/dist/background/schedules.js +21 -11
  15. package/dist/cli/command-runs.d.ts +2 -0
  16. package/dist/cli/command-runs.js +2 -0
  17. package/dist/cli/index.d.ts +1 -1
  18. package/dist/cli/index.js +1 -1
  19. package/dist/cli/list-query.d.ts +1 -1
  20. package/dist/cli/list-query.js +2 -2
  21. package/dist/cli/setup-command.js +5 -2
  22. package/dist/crm/cli/activities.d.ts +17 -0
  23. package/dist/crm/cli/activities.js +133 -0
  24. package/dist/crm/cli/changes.d.ts +23 -0
  25. package/dist/crm/cli/changes.js +255 -0
  26. package/dist/crm/cli/index.d.ts +1 -0
  27. package/dist/crm/cli/index.js +7 -4
  28. package/dist/crm/digest.d.ts +27 -0
  29. package/dist/crm/digest.js +166 -0
  30. package/dist/crm/stage-tasks.d.ts +1 -1
  31. package/dist/crm/stage-tasks.js +1 -1
  32. package/dist/crm/sync.d.ts +9 -0
  33. package/dist/crm/sync.js +27 -0
  34. package/dist/crm/testing/source.d.ts +5 -1
  35. package/dist/crm/testing/source.js +19 -0
  36. package/dist/crm/testing/sync-contract.d.ts +2 -0
  37. package/dist/crm/testing/sync-contract.js +56 -2
  38. package/dist/errors/reasons.js +1 -0
  39. package/dist/store/identity-links.d.ts +73 -0
  40. package/dist/store/identity-links.js +14 -0
  41. package/dist/store/index.d.ts +3 -1
  42. package/dist/store/index.js +2 -1
  43. package/dist/store/people.d.ts +23 -1
  44. package/dist/store/people.js +12 -1
  45. package/dist/store/sqlite/agent-links.d.ts +34 -0
  46. package/dist/store/sqlite/agent-links.js +184 -0
  47. package/dist/store/sqlite/crm-activities.d.ts +41 -1
  48. package/dist/store/sqlite/crm-activities.js +152 -14
  49. package/dist/store/sqlite/crm-changes.d.ts +84 -0
  50. package/dist/store/sqlite/crm-changes.js +199 -0
  51. package/dist/store/sqlite/crm.d.ts +2 -1
  52. package/dist/store/sqlite/crm.js +2 -0
  53. package/dist/store/sqlite/identity-proposals.d.ts +2 -0
  54. package/dist/store/sqlite/identity-proposals.js +2 -0
  55. package/dist/store/sqlite/person-match-scan.d.ts +29 -0
  56. package/dist/store/sqlite/person-match-scan.js +4 -4
  57. package/dist/store/sqlite/person-merges.d.ts +3 -0
  58. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,53 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.678.0 — 16.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`changes list [query]`** answers what changed in the CRM copy in a window, newest first: deals and leads made,
13
+ moved, won, lost and given another owner, activities added and done, and contacts added. `at:` sets the window (the
14
+ last day when left out), `change:`, `owner:` and `pipeline:` filter it, `--limit` and `--cursor` page it over the
15
+ same window, `--format csv` prints it, and `meta` names the time zone and the window. A won or lost deal is dated by
16
+ the CRM's own stage history when it has one (`exact: true`).
17
+ - **`changes list --format report`** prints a CRM morning digest document: deals won and lost first, then overdue CRM
18
+ tasks, those due today, stage moves, new deals, new owners, new contacts and the tasks the stage rules opened, with
19
+ "and N more" counted in full. It names a failed or stale sync. Run by a schedule, each digest starts where the last
20
+ one ended, and each ends where the last complete sync started, so a late or missed run or a sync that copies a
21
+ change after the digest loses nothing, and no deal shows twice. Phone numbers and e-mail addresses in its text are
22
+ masked. Scheduled with `schedule command`, it is
23
+ rendered and delivered like an agent's digest.
24
+ - **`activities list [query]`** in a CLI that copies the CRM's activities: open ones overdue first, then by due time,
25
+ then undated; `status:`, `due:`, `overdue:`, `kind:`, `deal:`, `lead:`, `person:`, `organization:` and `owner:`.
26
+ With the activities setting off it says so in `missing`.
27
+ - **A `command` schedule whose output is a report document is rendered and delivered as a report**, with a `crm`
28
+ section kind in the morning digest. Its text is the store's data: a title such as `follow_up` is kept as it is.
29
+ - A profile that may read only its own part of a CRM copy sees in these commands only its own deals and leads, the
30
+ activities on them and the contacts linked to them.
31
+
32
+ ### Fixed
33
+
34
+ - **`setup apply --dry-run` with nothing on stdin answers instead of refusing.** It checks no answers and names the
35
+ first step in `at`, so a program can ask where a flow starts, and the shared deny-keys contract
36
+ (`cli-contract`) can run it: amo's `contracts:check` failed with "setup apply --dry-run exited 2". `setup apply`
37
+ without `--dry-run` still refuses an empty stdin.
38
+
39
+ ## 0.677.0 — 16.11.2026
40
+
41
+ ### Added
42
+
43
+ - **An agent's link of two people merges at once on strong evidence** (`people.agentLink`). The store
44
+ decides, never the agent's word: one value only these two people hold, a mobile number or a personal address, from
45
+ two different sources, and for a phone at least one that keeps its user's own number (a messenger account or a
46
+ call's number). Anything weaker, the owner's own person, a pair the owner rejected, or `apply: false` opens a
47
+ proposal as before, whose payload now says why it is not strong (`strength`). The merge is recorded as an
48
+ `identity_link` the agent decided, with the evidence, the reason and the run, and `undoMerge` gives both people back.
49
+ - **`people.linkEvidence(pairs)`** answers what each pair of people shares and whether it is strong, reading the store
50
+ once; **`people.agentMerges()`** lists the agents' merges still in place; **`people.merges()`** names the agent, run,
51
+ reason and evidence of an agent's merge (`agent`).
52
+ - **`commandRunId()`** (`@wirecat/cli-core/cli`) gives the id `runs show` takes for the command under way, so a write
53
+ can name the run that made it.
54
+
8
55
  ## 0.676.0 — 16.11.2026
9
56
 
10
57
  ### Added
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
24
24
  }
25
25
  export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
26
26
  export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
27
- action?: undefined;
28
27
  name: string;
29
28
  installed: boolean;
30
29
  active: boolean;
31
30
  servicePath: string;
32
31
  timerPath: string;
32
+ action?: undefined;
33
33
  } | {
34
34
  active?: undefined;
35
35
  name: string;
@@ -76,7 +76,7 @@ export interface PreparedReport {
76
76
  * A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
77
77
  * line in the owner's language and is never shown raw.
78
78
  */
79
- export declare const prepareReport: (answer: string, { language, now, timeZone, templates: storedTemplates, links, env, }: {
79
+ export declare const prepareReport: (answer: string, { language, now, timeZone, templates: storedTemplates, links, env, trusted, }: {
80
80
  language: string;
81
81
  now: number;
82
82
  timeZone?: string;
@@ -85,6 +85,8 @@ export declare const prepareReport: (answer: string, { language, now, timeZone,
85
85
  links?: LinkConfig;
86
86
  /** Read for `WIRECAT_LINKS=off`. */
87
87
  env?: NodeJS.ProcessEnv;
88
+ /** A command's document, built from the store rather than written by an agent (`parseReport`). */
89
+ trusted?: boolean;
88
90
  }) => Promise<PreparedReport | undefined>;
89
91
  /** A message other than the digest, rendered for every channel: what `deliver` sends as a rendered parcel. */
90
92
  export interface PreparedMessage {
@@ -223,8 +223,8 @@ const INVALID_LINES = {
223
223
  * A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
224
224
  * line in the owner's language and is never shown raw.
225
225
  */
226
- export const prepareReport = async (answer, { language, now, timeZone, templates: storedTemplates, links = DEFAULT_LINK_CONFIG, env = process.env, }) => {
227
- const parsed = parseReport(answer);
226
+ export const prepareReport = async (answer, { language, now, timeZone, templates: storedTemplates, links = DEFAULT_LINK_CONFIG, env = process.env, trusted = false, }) => {
227
+ const parsed = parseReport(answer, trusted);
228
228
  if (!parsed)
229
229
  return undefined;
230
230
  if ("invalid" in parsed) {
@@ -2,11 +2,11 @@ export declare const REPORT_FORMAT = "wirecat.report/1";
2
2
  export declare const REPORT_KINDS: readonly ["morning-digest"];
3
3
  export type ReportKind = (typeof REPORT_KINDS)[number];
4
4
  /** In the order they are shown; `health` is not among them, it comes from the document's `health[]` only. */
5
- export declare const SECTION_KINDS: readonly ["today", "decisions", "money", "meetings", "projects", "mail"];
5
+ export declare const SECTION_KINDS: readonly ["today", "decisions", "money", "meetings", "projects", "crm", "mail"];
6
6
  export type SectionKind = (typeof SECTION_KINDS)[number];
7
7
  export declare const ITEM_TYPES: readonly ["reply", "question", "task", "fact", "risk", "money", "decision", "meeting"];
8
8
  export type ItemType = (typeof ITEM_TYPES)[number];
9
- export declare const CHANNEL_KINDS: readonly ["telegram", "max", "whatsapp", "mail", "meeting", "task"];
9
+ export declare const CHANNEL_KINDS: readonly ["telegram", "max", "whatsapp", "mail", "meeting", "task", "crm"];
10
10
  export type ChannelKind = (typeof CHANNEL_KINDS)[number];
11
11
  export interface Amount {
12
12
  value: number;
@@ -95,6 +95,8 @@ export declare const withoutLeaks: (text: string) => {
95
95
  export declare const reportDocument: (report: Report) => Record<string, unknown>;
96
96
  /** The JSON text of a run's answer: the bare object, or the only fenced `json` block; undefined for anything else. */
97
97
  export declare const jsonOfAnswer: (answer: string) => string | undefined;
98
+ /** Whether a command's stdout is a `wirecat.report/1` document, which a schedule renders and delivers as a report. */
99
+ export declare const isReportAnswer: (answer: string) => boolean;
98
100
  export type ParsedReport = {
99
101
  report: Report;
100
102
  leaks: number;
@@ -104,6 +106,7 @@ export type ParsedReport = {
104
106
  /**
105
107
  * A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
106
108
  * report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
107
- * of the first field that failed, and is never shown.
109
+ * of the first field that failed, and is never shown. `trusted` is a document a command built from the store: its
110
+ * strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
108
111
  */
109
- export declare const parseReport: (answer: string) => ParsedReport | undefined;
112
+ export declare const parseReport: (answer: string, trusted?: boolean) => ParsedReport | undefined;
@@ -1,9 +1,9 @@
1
1
  export const REPORT_FORMAT = "wirecat.report/1";
2
2
  export const REPORT_KINDS = ["morning-digest"];
3
3
  /** In the order they are shown; `health` is not among them, it comes from the document's `health[]` only. */
4
- export const SECTION_KINDS = ["today", "decisions", "money", "meetings", "projects", "mail"];
4
+ export const SECTION_KINDS = ["today", "decisions", "money", "meetings", "projects", "crm", "mail"];
5
5
  export const ITEM_TYPES = ["reply", "question", "task", "fact", "risk", "money", "decision", "meeting"];
6
- export const CHANNEL_KINDS = ["telegram", "max", "whatsapp", "mail", "meeting", "task"];
6
+ export const CHANNEL_KINDS = ["telegram", "max", "whatsapp", "mail", "meeting", "task", "crm"];
7
7
  export const HEALTH_REASONS = ["sync-failed", "no-schedule", "quiet"];
8
8
  const TEXT_LIMITS = {
9
9
  summary: 120,
@@ -140,14 +140,16 @@ const cut = (text, limit) => (text.length <= limit ? text : `${text.slice(0, lim
140
140
  * Checks a parsed document and keeps what the renderers may show. Any agent string loses what `withoutLeaks` finds
141
141
  * and is cut to its limit; a required field left empty by that makes the document invalid, as a missing one does.
142
142
  */
143
- const checked = (document) => {
143
+ const checked = (document, trusted) => {
144
144
  let leaks = 0;
145
145
  const text = (value, field, at) => {
146
146
  if (value === undefined || value === null)
147
147
  return null;
148
148
  if (typeof value !== "string")
149
149
  throw new Invalid(at);
150
- const clean = withoutLeaks(value.trim());
150
+ // A line break inside a field would draw a line of its own, as if the report had written it.
151
+ const flat = value.replace(/\s+/g, " ").trim();
152
+ const clean = trusted ? { text: flat, leaks: 0 } : withoutLeaks(flat);
151
153
  leaks += clean.leaks;
152
154
  return clean.text ? cut(clean.text, TEXT_LIMITS[field]) : null;
153
155
  };
@@ -264,12 +266,26 @@ export const jsonOfAnswer = (answer) => {
264
266
  const fenced = /^```json[ \t]*\n([\s\S]*?)\n```$/.exec(text)?.[1];
265
267
  return fenced ?? (text.startsWith("{") ? text : undefined);
266
268
  };
269
+ /** Whether a command's stdout is a `wirecat.report/1` document, which a schedule renders and delivers as a report. */
270
+ export const isReportAnswer = (answer) => {
271
+ const json = jsonOfAnswer(answer);
272
+ if (json === undefined)
273
+ return false;
274
+ try {
275
+ const document = JSON.parse(json);
276
+ return (typeof document === "object" && document !== null && "format" in document && document.format === REPORT_FORMAT);
277
+ }
278
+ catch {
279
+ return false;
280
+ }
281
+ };
267
282
  /**
268
283
  * A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
269
284
  * report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
270
- * of the first field that failed, and is never shown.
285
+ * of the first field that failed, and is never shown. `trusted` is a document a command built from the store: its
286
+ * strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
271
287
  */
272
- export const parseReport = (answer) => {
288
+ export const parseReport = (answer, trusted = false) => {
273
289
  const json = jsonOfAnswer(answer);
274
290
  if (json === undefined)
275
291
  return undefined;
@@ -281,7 +297,7 @@ export const parseReport = (answer) => {
281
297
  return { invalid: "json" };
282
298
  }
283
299
  try {
284
- return checked(document);
300
+ return checked(document, trusted);
285
301
  }
286
302
  catch (error) {
287
303
  if (error instanceof Invalid)
@@ -24,6 +24,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
24
24
  {%- when "meetings" %}Meetings
25
25
  {%- when "projects" %}Projects in motion
26
26
  {%- when "mail" %}New mail
27
+ {%- when "crm" %}CRM
27
28
  {%- endcase %}</b></p>
28
29
  {%- for item in section.items -%}
29
30
  {%- capture due -%}
@@ -60,7 +61,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
60
61
  {%- if item.channel %}{{ sep }}
61
62
  {%- case item.channel -%}
62
63
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
63
- {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task
64
+ {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task{% when "crm" %}CRM
64
65
  {%- endcase -%}
65
66
  {%- assign sep = " · " -%}
66
67
  {%- endif -%}
@@ -105,7 +106,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
105
106
  {%- if forloop.first %}: {% else %}, {% endif -%}
106
107
  {%- case source.kind -%}
107
108
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
108
- {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks
109
+ {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks{% when "crm" %}CRM
109
110
  {%- endcase -%}
110
111
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% if source.plural == "one" %}mailbox{% else %}mailboxes{% endif %}{% else %}{% if source.plural == "one" %}account{% else %}accounts{% endif %}{% endif %}){% endif -%}
111
112
  {%- endfor -%}
@@ -24,6 +24,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
24
24
  {%- when "meetings" %}Встречи
25
25
  {%- when "projects" %}Проекты в движении
26
26
  {%- when "mail" %}Новая почта
27
+ {%- when "crm" %}CRM
27
28
  {%- endcase %}</b></p>
28
29
  {%- for item in section.items -%}
29
30
  {%- capture due -%}
@@ -60,7 +61,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
60
61
  {%- if item.channel %}{{ sep }}
61
62
  {%- case item.channel -%}
62
63
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
63
- {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача
64
+ {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача{% when "crm" %}CRM
64
65
  {%- endcase -%}
65
66
  {%- assign sep = " · " -%}
66
67
  {%- endif -%}
@@ -105,7 +106,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
105
106
  {%- if forloop.first %}: {% else %}, {% endif -%}
106
107
  {%- case source.kind -%}
107
108
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
108
- {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи
109
+ {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи{% when "crm" %}CRM
109
110
  {%- endcase -%}
110
111
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% case source.plural %}{% when "one" %}ящик{% when "few" %}ящика{% else %}ящиков{% endcase %}{% else %}{% case source.plural %}{% when "one" %}аккаунт{% when "few" %}аккаунта{% else %}аккаунтов{% endcase %}{% endif %}){% endif -%}
111
112
  {%- endfor -%}
@@ -22,6 +22,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
22
22
  {%- when "meetings" %}Meetings
23
23
  {%- when "projects" %}Projects in motion
24
24
  {%- when "mail" %}New mail
25
+ {%- when "crm" %}CRM
25
26
  {%- endcase %}</b>
26
27
  {%- for item in section.items -%}
27
28
  {%- capture due -%}
@@ -58,7 +59,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
58
59
  {%- if item.channel %}{{ sep }}
59
60
  {%- case item.channel -%}
60
61
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
61
- {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task
62
+ {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task{% when "crm" %}CRM
62
63
  {%- endcase -%}
63
64
  {%- assign sep = " · " -%}
64
65
  {%- endif -%}
@@ -104,7 +105,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
104
105
  {%- if forloop.first %}: {% else %}, {% endif -%}
105
106
  {%- case source.kind -%}
106
107
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
107
- {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks
108
+ {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks{% when "crm" %}CRM
108
109
  {%- endcase -%}
109
110
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% if source.plural == "one" %}mailbox{% else %}mailboxes{% endif %}{% else %}{% if source.plural == "one" %}account{% else %}accounts{% endif %}{% endif %}){% endif -%}
110
111
  {%- endfor -%}
@@ -22,6 +22,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
22
22
  {%- when "meetings" %}Встречи
23
23
  {%- when "projects" %}Проекты в движении
24
24
  {%- when "mail" %}Новая почта
25
+ {%- when "crm" %}CRM
25
26
  {%- endcase %}</b>
26
27
  {%- for item in section.items -%}
27
28
  {%- capture due -%}
@@ -58,7 +59,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
58
59
  {%- if item.channel %}{{ sep }}
59
60
  {%- case item.channel -%}
60
61
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
61
- {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача
62
+ {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача{% when "crm" %}CRM
62
63
  {%- endcase -%}
63
64
  {%- assign sep = " · " -%}
64
65
  {%- endif -%}
@@ -104,7 +105,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
104
105
  {%- if forloop.first %}: {% else %}, {% endif -%}
105
106
  {%- case source.kind -%}
106
107
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
107
- {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи
108
+ {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи{% when "crm" %}CRM
108
109
  {%- endcase -%}
109
110
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% case source.plural %}{% when "one" %}ящик{% when "few" %}ящика{% else %}ящиков{% endcase %}{% else %}{% case source.plural %}{% when "one" %}аккаунт{% when "few" %}аккаунта{% else %}аккаунтов{% endcase %}{% endif %}){% endif -%}
110
111
  {%- endfor -%}
@@ -21,6 +21,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
21
21
  {%- when "meetings" %}Meetings
22
22
  {%- when "projects" %}Projects in motion
23
23
  {%- when "mail" %}New mail
24
+ {%- when "crm" %}CRM
24
25
  {%- endcase -%}
25
26
  {%- for item in section.items -%}
26
27
  {%- capture due -%}
@@ -57,7 +58,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
57
58
  {%- if item.channel %}{{ sep }}
58
59
  {%- case item.channel -%}
59
60
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
60
- {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task
61
+ {%- when "mail" %}mail{% when "meeting" %}meeting{% when "task" %}task{% when "crm" %}CRM
61
62
  {%- endcase -%}
62
63
  {%- assign sep = " · " -%}
63
64
  {%- endif -%}
@@ -103,7 +104,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
103
104
  {%- if forloop.first %}: {% else %}, {% endif -%}
104
105
  {%- case source.kind -%}
105
106
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
106
- {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks
107
+ {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks{% when "crm" %}CRM
107
108
  {%- endcase -%}
108
109
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% if source.plural == "one" %}mailbox{% else %}mailboxes{% endif %}{% else %}{% if source.plural == "one" %}account{% else %}accounts{% endif %}{% endif %}){% endif -%}
109
110
  {%- endfor -%}
@@ -21,6 +21,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
21
21
  {%- when "meetings" %}Встречи
22
22
  {%- when "projects" %}Проекты в движении
23
23
  {%- when "mail" %}Новая почта
24
+ {%- when "crm" %}CRM
24
25
  {%- endcase -%}
25
26
  {%- for item in section.items -%}
26
27
  {%- capture due -%}
@@ -57,7 +58,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
57
58
  {%- if item.channel %}{{ sep }}
58
59
  {%- case item.channel -%}
59
60
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
60
- {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача
61
+ {%- when "mail" %}почта{% when "meeting" %}встреча{% when "task" %}задача{% when "crm" %}CRM
61
62
  {%- endcase -%}
62
63
  {%- assign sep = " · " -%}
63
64
  {%- endif -%}
@@ -103,7 +104,7 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
103
104
  {%- if forloop.first %}: {% else %}, {% endif -%}
104
105
  {%- case source.kind -%}
105
106
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
106
- {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи
107
+ {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи{% when "crm" %}CRM
107
108
  {%- endcase -%}
108
109
  {%- if source.accounts > 1 %} ({{ source.accounts }} {% if source.kind == "mail" %}{% case source.plural %}{% when "one" %}ящик{% when "few" %}ящика{% else %}ящиков{% endcase %}{% else %}{% case source.plural %}{% when "one" %}аккаунт{% when "few" %}аккаунта{% else %}аккаунтов{% endcase %}{% endif %}){% endif -%}
109
110
  {%- endfor -%}
@@ -9,6 +9,7 @@ export const SECTION_EMOJI = {
9
9
  money: "💰",
10
10
  meetings: "📅",
11
11
  projects: "🚀",
12
+ crm: "🤝",
12
13
  mail: "📬",
13
14
  };
14
15
  export const SECTION_CAPS = {
@@ -17,6 +18,7 @@ export const SECTION_CAPS = {
17
18
  money: 5,
18
19
  meetings: 5,
19
20
  projects: 5,
21
+ crm: 7,
20
22
  mail: 5,
21
23
  health: 3,
22
24
  };
@@ -13,6 +13,7 @@ import { readSharedSection, sharedConfigPath } from "../store/shared-config.js";
13
13
  import { deliver } from "./deliver.js";
14
14
  import { causeOf, gapsView, noticeView, weeklyGapsOf } from "./report/messages.js";
15
15
  import { prepareMessage, prepareReport, } from "./report/render.js";
16
+ import { isReportAnswer } from "./report/schema.js";
16
17
  export { launchdTimer, systemdTimer, timerFor, windowsTimer } from "./timers.js";
17
18
  export { calendarOf, describeWhen, isCalendar, nextRun, previousRun, runsBetween, slotsOf, WEEKDAYS, } from "./when.js";
18
19
  /** Stands for an agent run's own work folder in its harness's variables and files; the run puts the real path in. */
@@ -326,7 +327,6 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
326
327
  const folder = join(file, "..");
327
328
  const runs = join(folder, "runs");
328
329
  mkdirSync(runs, { recursive: true, mode: 0o700 });
329
- const agent = schedule.kind === "agent";
330
330
  const retries = untilUnlocked && !("every" in schedule.when);
331
331
  const firstAt = now().getTime();
332
332
  const first = await attemptSchedule(app, system, env, schedule, folder, {
@@ -373,16 +373,19 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
373
373
  }
374
374
  }
375
375
  const { exitCode, output } = last;
376
- const errors = agent ? output.replace(/\.md$/, ".log") : output;
377
- if (agent && exitCode === 0)
376
+ // An agent's answer, or a command's that printed a report: either is rendered and delivered as a report.
377
+ const answered = output.endsWith(".md");
378
+ const errors = answered ? output.replace(/\.md$/, ".log") : output;
379
+ if (answered && exitCode === 0)
378
380
  copyFileSync(output, join(folder, "latest.md"));
379
381
  const runEnv = { ...env, ...schedule.environment };
380
- const prepared = agent && exitCode === 0
382
+ const prepared = answered && exitCode === 0
381
383
  ? await prepareReport(readFileSync(output, "utf8"), {
382
384
  language: await ownerLanguage(runEnv).catch(() => "ru"),
383
385
  now: now().getTime(),
384
386
  links: sharedLinks(runEnv),
385
387
  env: runEnv,
388
+ trusted: schedule.kind !== "agent",
386
389
  ...(reportTemplates ? { templates: reportTemplates(runEnv, schedule.name) } : {}),
387
390
  })
388
391
  : undefined;
@@ -393,7 +396,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
393
396
  writeFileSync(output.replace(/\.md$/, ".report.json"), prepared.document, { mode: 0o600 });
394
397
  last = rewriteRun(join(folder, "last.json"), { ...last, report: prepared.run });
395
398
  }
396
- else if (agent && exitCode === 0)
399
+ else if (answered && exitCode === 0)
397
400
  rmSync(latestText, { force: true });
398
401
  const stampOf = (file) => file.split(".")[0] ?? file;
399
402
  const stamps = [...new Set(readdirSync(runs).map(stampOf))].sort();
@@ -405,7 +408,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
405
408
  const title = `${app.command} ${schedule.name}`;
406
409
  // Routes the owner named for this run go whatever the schedule's notify says; none named, nobody is told.
407
410
  const mode = chosen === undefined ? notifyOf(schedule) : chosen.length ? "always" : "never";
408
- if (agent && exitCode === 0) {
411
+ if (answered && exitCode === 0) {
409
412
  if (mode === "always" && !announcedByDesktop(join(folder, ".."), schedule.name)) {
410
413
  const first = readFileSync(output, "utf8")
411
414
  .split("\n")
@@ -443,7 +446,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
443
446
  const deliveries = await sendAlong(exitCode === 0
444
447
  ? {
445
448
  title: `${title} · ${at}`,
446
- file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${agent ? "md" : "txt"}` },
449
+ file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${answered ? "md" : "txt"}` },
447
450
  ...(prepared ? { rendered: prepared } : {}),
448
451
  }
449
452
  : notice
@@ -533,8 +536,8 @@ export const attemptSchedule = async (app, system, env, schedule, folder, { now,
533
536
  .replaceAll(":", "-")
534
537
  .replace(/\.\d+Z$/, "Z");
535
538
  const agent = schedule.kind === "agent";
536
- const output = join(runs, `${stamp}.${agent ? "md" : "log"}`);
537
- const errors = agent ? join(runs, `${stamp}.log`) : output;
539
+ let output = join(runs, `${stamp}.${agent ? "md" : "log"}`);
540
+ let errors = agent ? join(runs, `${stamp}.log`) : output;
538
541
  const trace = childTrace();
539
542
  // An agent works in an empty folder of its own: one that could write where it runs never reaches its schedule file.
540
543
  const work = agent ? mkdtempSync(join(tmpdir(), "wirecat-agent-")) : folder;
@@ -610,11 +613,18 @@ export const attemptSchedule = async (app, system, env, schedule, folder, { now,
610
613
  signal?.removeEventListener("abort", stop);
611
614
  if (kill)
612
615
  clearTimeout(kill);
613
- const report = agent ? reportOf(Buffer.concat(out)) : { text: Buffer.concat([...out, ...err]) };
616
+ const printed = !agent && isReportAnswer(Buffer.concat(out).toString("utf8"));
617
+ if (printed) {
618
+ output = join(runs, `${stamp}.md`);
619
+ errors = join(runs, `${stamp}.log`);
620
+ }
621
+ const report = agent
622
+ ? reportOf(Buffer.concat(out))
623
+ : { text: printed ? Buffer.concat(out) : Buffer.concat([...out, ...err]) };
614
624
  costUsd = report.costUsd;
615
625
  writeFileSync(output, report.text, { mode: 0o600 });
616
626
  // The error is the agent's answer, so the log keeps it beside its stderr.
617
- if (agent)
627
+ if (agent || printed)
618
628
  writeFileSync(errors, Buffer.concat([...err, ...("failed" in report ? [report.text] : [])]), { mode: 0o600 });
619
629
  const exited = code ?? (killedBy === "SIGKILL" ? 137 : killedBy === "SIGTERM" ? 143 : 1);
620
630
  resolve("failed" in report && exited === 0 ? 1 : exited);
@@ -57,6 +57,8 @@ export interface CommandRuns {
57
57
  events(event: RequestEvent): void;
58
58
  }
59
59
  export declare const commandRuns: (options: CommandRunOptions) => CommandRuns;
60
+ /** The id `runs show` takes for the command under way, so a write can name the run that made it. */
61
+ export declare const commandRunId: () => string | undefined;
60
62
  /**
61
63
  * For a provider client far from the program: the event lands in the current command's run — a `startCli` command's,
62
64
  * or the run `run()` opened — or nowhere.
@@ -111,6 +111,8 @@ const tracker = (options, typed) => {
111
111
  };
112
112
  export const commandRuns = (options) => tracker(options);
113
113
  const parses = new AsyncLocalStorage();
114
+ /** The id `runs show` takes for the command under way, so a write can name the run that made it. */
115
+ export const commandRunId = () => parses.getStore()?.runs.runId();
114
116
  /**
115
117
  * For a provider client far from the program: the event lands in the current command's run — a `startCli` command's,
116
118
  * or the run `run()` opened — or nowhere.
@@ -72,7 +72,7 @@ export { PressLog, UpdatesCursor } from "./bot/updates.js";
72
72
  export { addCallStatsCommand, type CallStatsCommandDeps, type CallStatsRead } from "./call-stats-command.js";
73
73
  export type { CommandAvailability, DiscoveredCommand } from "./command-availability.js";
74
74
  export { commandContract, type JsonSchema, SCHEMA_DIALECT } from "./command-contract.js";
75
- export { type CommandRunOptions, type CommandRuns, commandRuns, type ProviderAnswer, type ProviderCall, providerEvent, providerRequest, type RunSettings, recordRuns, runSettings, type SavedRunSettings, } from "./command-runs.js";
75
+ export { type CommandRunOptions, type CommandRuns, commandRunId, commandRuns, type ProviderAnswer, type ProviderCall, providerEvent, providerRequest, type RunSettings, recordRuns, runSettings, type SavedRunSettings, } from "./command-runs.js";
76
76
  export { CONTRACT } from "./commands-command.js";
77
77
  export { type CompactOptions, compactText, entityRows, GENERIC_ROW, type RowColumn, type RowShape, type RowsResolver, type RowTable, type RowValue, rowShapeOf, rowsOfEntity, SHARED_ROWS, } from "./compact.js";
78
78
  export type { AppCompletionOptions, CompletionRequest } from "./complete-command.js";
package/dist/cli/index.js CHANGED
@@ -64,7 +64,7 @@ export { BotTokenStore } from "./bot/token.js";
64
64
  export { PressLog, UpdatesCursor } from "./bot/updates.js";
65
65
  export { addCallStatsCommand } from "./call-stats-command.js";
66
66
  export { commandContract, SCHEMA_DIALECT } from "./command-contract.js";
67
- export { commandRuns, providerEvent, providerRequest, recordRuns, runSettings, } from "./command-runs.js";
67
+ export { commandRunId, commandRuns, providerEvent, providerRequest, recordRuns, runSettings, } from "./command-runs.js";
68
68
  export { CONTRACT } from "./commands-command.js";
69
69
  export { compactText, entityRows, GENERIC_ROW, rowShapeOf, rowsOfEntity, SHARED_ROWS, } from "./compact.js";
70
70
  export { refuseUnknownKey } from "./config-command.js";
@@ -61,7 +61,7 @@ export declare const queryTerms: (words: QueryWords, registry: QueryRegistry, co
61
61
  * `until` is inclusive: an exclusive end (a bare date's next midnight, `… TO …}`) comes back 1 ms inside. `since` stays
62
62
  * as written, because the inbox reads strictly after a `date>` start.
63
63
  */
64
- export declare const timeBounds: (term: Predicate | undefined, zone?: string) => {
64
+ export declare const timeBounds: (term: Predicate | undefined, zone?: string, now?: number) => {
65
65
  since?: number;
66
66
  until?: number;
67
67
  meta?: {
@@ -171,11 +171,11 @@ export const queryTerms = (words, registry, command, ranged = []) => {
171
171
  * `until` is inclusive: an exclusive end (a bare date's next midnight, `… TO …}`) comes back 1 ms inside. `since` stays
172
172
  * as written, because the inbox reads strictly after a `date>` start.
173
173
  */
174
- export const timeBounds = (term, zone = timezoneOf()) => {
174
+ export const timeBounds = (term, zone = timezoneOf(), now) => {
175
175
  if (!term)
176
176
  return {};
177
177
  const upper = term.operator === "range" ? (term.upper ?? "*") : term.value;
178
- const range = dateRange(term.value, upper, term.operator === "range" ? term.lower_inclusive !== false : true, term.operator === "range" ? term.upper_inclusive !== false : true, zone, term.span);
178
+ const range = dateRange(term.value, upper, term.operator === "range" ? term.lower_inclusive !== false : true, term.operator === "range" ? term.upper_inclusive !== false : true, zone, term.span, now);
179
179
  const until = range.upper === undefined ? undefined : range.upper - (range.upper_inclusive ? 0 : 1);
180
180
  return {
181
181
  ...(range.lower === undefined ? {} : { since: range.lower }),
@@ -83,13 +83,16 @@ export const setupCommand = (setup) => {
83
83
  ]));
84
84
  return { ...document, steps };
85
85
  };
86
- const readAnswers = async (command, lines) => {
86
+ const readAnswers = async (command, lines, { noneAllowed = false } = {}) => {
87
87
  const input = environmentOf(command).stdin ?? process.stdin;
88
88
  if (!lines && input.isTTY)
89
89
  throw new CliError("validation_error", `pipe the answers as one JSON object on stdin: echo '{…}' | ${cli} …`, {
90
90
  reason: "input.required",
91
91
  });
92
92
  const text = lines ? await lines() : (await bufferedInput(input, { maxBytes: SETUP_LIMITS.bytes })).toString("utf8");
93
+ // A dry run of no answers names the first step to ask, and lets a contract learn the command's permission key.
94
+ if (noneAllowed && text.trim() === "")
95
+ return {};
93
96
  let parsed;
94
97
  try {
95
98
  parsed = JSON.parse(text);
@@ -192,7 +195,7 @@ export const setupCommand = (setup) => {
192
195
  "--dry-run only checks and saves nothing")
193
196
  .option("--dry-run", "check the answers, and save nothing")
194
197
  .action(async function ({ dryRun }) {
195
- const answers = await readAnswers(this);
198
+ const answers = await readAnswers(this, undefined, { noneAllowed: dryRun === true });
196
199
  const result = await apply(this, answers, { dryRun: dryRun === true, steps: stepsFor(this, false) });
197
200
  renderAnswer(this, contextFor(this, false, true), itemOf(result));
198
201
  });
@@ -0,0 +1,17 @@
1
+ import type { Command } from "commander";
2
+ import type { CrmRun, CrmWithin } from "./index.js";
3
+ export declare const ACTIVITIES_QUERY: {
4
+ readonly entity: "crm_activity";
5
+ readonly backend: "native";
6
+ readonly fields: readonly [import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec];
7
+ };
8
+ export interface CrmActivityCommandOptions {
9
+ within: CrmWithin;
10
+ example: (command: Command, ...lines: string[]) => Command;
11
+ now: () => number;
12
+ /** `owner:` as the identity an activity's assignee is stored as; `null` is none. */
13
+ ownerOf: (run: CrmRun, owner: string) => Promise<string | null>;
14
+ pathOf: (command: Command) => string[];
15
+ }
16
+ /** `activities list`: the copy's CRM activities and tasks, mounted when the CLI copies them (WC-ARCH-5). */
17
+ export declare const addCrmActivityCommands: (program: Command, options: CrmActivityCommandOptions) => void;