@wirecat/cli-core 0.677.0 → 0.679.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 +68 -0
  2. package/dist/background/budget.d.ts +2 -0
  3. package/dist/background/budget.js +2 -0
  4. package/dist/background/report/render.d.ts +3 -1
  5. package/dist/background/report/render.js +2 -2
  6. package/dist/background/report/schema.d.ts +7 -4
  7. package/dist/background/report/schema.js +23 -7
  8. package/dist/background/report/templates/morning-digest.email.en.liquid +3 -2
  9. package/dist/background/report/templates/morning-digest.email.ru.liquid +3 -2
  10. package/dist/background/report/templates/morning-digest.telegram.en.liquid +3 -2
  11. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +3 -2
  12. package/dist/background/report/templates/morning-digest.text.en.liquid +3 -2
  13. package/dist/background/report/templates/morning-digest.text.ru.liquid +3 -2
  14. package/dist/background/report/view.js +2 -0
  15. package/dist/background/schedules.js +21 -11
  16. package/dist/cli/help/first-screen.js +5 -0
  17. package/dist/cli/list-query.d.ts +1 -1
  18. package/dist/cli/list-query.js +2 -2
  19. package/dist/cli/setup-command.js +26 -11
  20. package/dist/crm/cli/activities.d.ts +17 -0
  21. package/dist/crm/cli/activities.js +133 -0
  22. package/dist/crm/cli/changes.d.ts +23 -0
  23. package/dist/crm/cli/changes.js +255 -0
  24. package/dist/crm/cli/index.d.ts +1 -0
  25. package/dist/crm/cli/index.js +7 -4
  26. package/dist/crm/digest.d.ts +27 -0
  27. package/dist/crm/digest.js +166 -0
  28. package/dist/crm/stage-tasks.d.ts +1 -1
  29. package/dist/crm/stage-tasks.js +1 -1
  30. package/dist/crm/sync.d.ts +9 -0
  31. package/dist/crm/sync.js +27 -0
  32. package/dist/crm/testing/source.d.ts +5 -1
  33. package/dist/crm/testing/source.js +19 -0
  34. package/dist/crm/testing/sync-contract.d.ts +2 -0
  35. package/dist/crm/testing/sync-contract.js +56 -2
  36. package/dist/documents/scope.d.ts +3 -3
  37. package/dist/documents/scope.js +8 -4
  38. package/dist/entities/business-context.js +4 -0
  39. package/dist/entities/recorded-meeting.d.ts +1 -0
  40. package/dist/entities/recorded-meeting.js +2 -0
  41. package/dist/services/communications.d.ts +35 -0
  42. package/dist/services/communications.js +52 -2
  43. package/dist/services/documents/plan.js +27 -6
  44. package/dist/services/documents/sync.js +6 -2
  45. package/dist/services/index.d.ts +2 -1
  46. package/dist/services/index.js +1 -0
  47. package/dist/services/metadata.d.ts +1 -1
  48. package/dist/services/person-meetings.d.ts +2 -0
  49. package/dist/services/person-meetings.js +16 -1
  50. package/dist/store/index.d.ts +2 -0
  51. package/dist/store/index.js +1 -0
  52. package/dist/store/sqlite/crm-activities.d.ts +41 -1
  53. package/dist/store/sqlite/crm-activities.js +152 -14
  54. package/dist/store/sqlite/crm-changes.d.ts +84 -0
  55. package/dist/store/sqlite/crm-changes.js +199 -0
  56. package/dist/store/sqlite/crm.d.ts +2 -1
  57. package/dist/store/sqlite/crm.js +2 -0
  58. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,74 @@ 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.679.0 — 16.11.2026
9
+
10
+ ### Added
11
+
12
+ - **The first screen and first run list `notion`**, the Notion tool (`@wirecat/notion-cli`), under "Works with" and
13
+ among the tools first run offers to install.
14
+ - **`personHistory(store, "person:<id>")`** gives what happened with one person lately, across every source in scope,
15
+ newest first: their one-to-one messages, mail, calendar events and recorded meetings and calls, the same reads a
16
+ deal's and an organization's context make. `limit` (10 by default) ends a page and `next` is the `until` of the
17
+ older one; `since`, `until`, `accounts` and `deniedKinds` narrow it, and `coverage` says what was read.
18
+ - **A touch of a deal's context, and of a person's history, carries what was said**: a message's `text`, and on a
19
+ recorded call its `call` (direction, the employee, the other side's number), `duration_ms` and the start of its
20
+ transcript as `text`. A calendar event a call was held for carries them too.
21
+ - **A recorded meeting in a person's context has `snippet`**, the start of its transcript on one line, beside
22
+ `has_transcript`.
23
+
24
+ ### Changed — may break callers
25
+
26
+ - **A saved `exclude` query that matches a page with sub-pages, or a folder, drops the whole branch.** The sub-pages
27
+ stayed in the documents and were listed at the top of the catalog with no parent; the next sync now removes them,
28
+ and the sync no longer lists what is below an excluded folder. A file that also sits under a parent the query keeps
29
+ stays. A selected folder the query matches drops only its own row, as before. Once the folder stops matching, the
30
+ next sync brings the whole branch back. See [Bind a provider](docs/dev/DOCUMENTS.md#bind-a-provider).
31
+ - **`inScope` and `within` take `folders: Record<string, M>`**, the type of the files they check, instead of
32
+ `Record<string, SourceFile>`; `within` is generic and takes an optional `cut` after `seen`.
33
+
34
+ ### Fixed
35
+
36
+ - **A documents sync with a deadline shorter than its margin moves on.** The run's budget stops 5 s or more before
37
+ the deadline, and it was asked before the first folder listing and the first file read, so `sync --timeout 3s`
38
+ said "sync again" forever with nothing done. Each call now makes its first listing and its first read while one
39
+ request still fits before the deadline itself, as it already did for the entry bound. See
40
+ [Walks over several syncs](docs/dev/DOCUMENTS.md#walks-over-several-syncs).
41
+ - **`setup apply --dry-run` opens the keyring only when the answers reach a secret.** It read every secret's saved
42
+ state up front, so a dry run of the first step touched the keyring, and the shared deny contract (`cli-contract`,
43
+ WC-PERM-23) failed amo's `contracts:check` once 0.678.0 let an empty dry run through.
44
+
45
+ ## 0.678.0 — 16.11.2026
46
+
47
+ ### Added
48
+
49
+ - **`changes list [query]`** answers what changed in the CRM copy in a window, newest first: deals and leads made,
50
+ moved, won, lost and given another owner, activities added and done, and contacts added. `at:` sets the window (the
51
+ last day when left out), `change:`, `owner:` and `pipeline:` filter it, `--limit` and `--cursor` page it over the
52
+ same window, `--format csv` prints it, and `meta` names the time zone and the window. A won or lost deal is dated by
53
+ the CRM's own stage history when it has one (`exact: true`).
54
+ - **`changes list --format report`** prints a CRM morning digest document: deals won and lost first, then overdue CRM
55
+ tasks, those due today, stage moves, new deals, new owners, new contacts and the tasks the stage rules opened, with
56
+ "and N more" counted in full. It names a failed or stale sync. Run by a schedule, each digest starts where the last
57
+ one ended, and each ends where the last complete sync started, so a late or missed run or a sync that copies a
58
+ change after the digest loses nothing, and no deal shows twice. Phone numbers and e-mail addresses in its text are
59
+ masked. Scheduled with `schedule command`, it is
60
+ rendered and delivered like an agent's digest.
61
+ - **`activities list [query]`** in a CLI that copies the CRM's activities: open ones overdue first, then by due time,
62
+ then undated; `status:`, `due:`, `overdue:`, `kind:`, `deal:`, `lead:`, `person:`, `organization:` and `owner:`.
63
+ With the activities setting off it says so in `missing`.
64
+ - **A `command` schedule whose output is a report document is rendered and delivered as a report**, with a `crm`
65
+ section kind in the morning digest. Its text is the store's data: a title such as `follow_up` is kept as it is.
66
+ - A profile that may read only its own part of a CRM copy sees in these commands only its own deals and leads, the
67
+ activities on them and the contacts linked to them.
68
+
69
+ ### Fixed
70
+
71
+ - **`setup apply --dry-run` with nothing on stdin answers instead of refusing.** It checks no answers and names the
72
+ first step in `at`, so a program can ask where a flow starts, and the shared deny-keys contract
73
+ (`cli-contract`) can run it: amo's `contracts:check` failed with "setup apply --dry-run exited 2". `setup apply`
74
+ without `--dry-run` still refuses an empty stdin.
75
+
8
76
  ## 0.677.0 — 16.11.2026
9
77
 
10
78
  ### Added
@@ -23,6 +23,8 @@ export declare const DEADLINE_MARGIN_MS = 5000;
23
23
  export declare const DEADLINE_MARGIN_SHARE = 0.15;
24
24
  /** How long one request to a provider is expected to take when the CLI does not say (`AppIdentity.requestMs`). */
25
25
  export declare const DEFAULT_REQUEST_MS = 2000;
26
+ /** Whether one more request still ends before the deadline itself, inside its margin. */
27
+ export declare const oneMoreFits: (deadline: Deadline | undefined, at: number, requestMs?: number) => boolean;
26
28
  export declare const deadlineMargin: (deadline: Deadline) => number;
27
29
  /** The requests that fit before the margin: `(deadline − margin) / requestMs`, at least one; none without a deadline. */
28
30
  export declare const requestsFor: (deadline: Deadline | undefined, requestMs?: number) => number | null;
@@ -2,6 +2,8 @@ export const DEADLINE_MARGIN_MS = 5_000;
2
2
  export const DEADLINE_MARGIN_SHARE = 0.15;
3
3
  /** How long one request to a provider is expected to take when the CLI does not say (`AppIdentity.requestMs`). */
4
4
  export const DEFAULT_REQUEST_MS = 2_000;
5
+ /** Whether one more request still ends before the deadline itself, inside its margin. */
6
+ export const oneMoreFits = (deadline, at, requestMs = DEFAULT_REQUEST_MS) => deadline !== undefined && at + requestMs < deadline.endsAt;
5
7
  export const deadlineMargin = (deadline) => Math.max(DEADLINE_MARGIN_MS, deadline.ms * DEADLINE_MARGIN_SHARE);
6
8
  /** The requests that fit before the margin: `(deadline − margin) / requestMs`, at least one; none without a deadline. */
7
9
  export const requestsFor = (deadline, requestMs = DEFAULT_REQUEST_MS) => deadline === undefined ? null : Math.max(1, Math.floor((deadline.ms - deadlineMargin(deadline)) / requestMs));
@@ -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);
@@ -58,6 +58,11 @@ export const WIRECAT_TOOLS = [
58
58
  package: "@wirecat/asterisk-cli",
59
59
  does: "Asterisk PBX calls and recordings, searchable with your other WireCat data",
60
60
  },
61
+ {
62
+ command: "notion",
63
+ package: "@wirecat/notion-cli",
64
+ does: "Notion pages and databases as local text, searchable with your other WireCat data",
65
+ },
61
66
  ];
62
67
  const WIDTH = 100;
63
68
  const widest = (texts) => texts.reduce((most, text) => Math.max(most, text.length), 0);
@@ -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 }),
@@ -48,7 +48,18 @@ export const setupCommand = (setup) => {
48
48
  const currentOf = (command, context) => {
49
49
  const { settings, renderer } = context;
50
50
  const current = {};
51
- const store = storeFor(command, renderer.warn);
51
+ let store;
52
+ // Read only when the path reaches the secret: a dry run of the first step must not open the keyring (WC-PERM-23).
53
+ const keptOf = (secret) => {
54
+ try {
55
+ store ??= storeFor(command, renderer.warn);
56
+ return readKept(store, settings.profile, secret) ? { set: true } : undefined;
57
+ }
58
+ catch {
59
+ // A keyring that cannot be read says nothing about the secret; the flow asks for it again.
60
+ return undefined;
61
+ }
62
+ };
52
63
  for (const field of allFields(document)) {
53
64
  if (field.setting !== undefined) {
54
65
  const value = fromFile(settings, field.setting, undefined).value;
@@ -56,15 +67,16 @@ export const setupCommand = (setup) => {
56
67
  current[field.setting] = value;
57
68
  }
58
69
  const secret = secretOf(field);
59
- if (secret === undefined || current[secret])
70
+ if (secret === undefined || secret in current)
60
71
  continue;
61
- try {
62
- if (readKept(store, settings.profile, secret))
63
- current[secret] = { set: true };
64
- }
65
- catch {
66
- // A keyring that cannot be read says nothing about the secret; the flow asks for it again.
67
- }
72
+ let read;
73
+ Object.defineProperty(current, secret, {
74
+ enumerable: true,
75
+ get: () => {
76
+ read ??= { value: keptOf(secret) };
77
+ return read.value;
78
+ },
79
+ });
68
80
  }
69
81
  return current;
70
82
  };
@@ -83,13 +95,16 @@ export const setupCommand = (setup) => {
83
95
  ]));
84
96
  return { ...document, steps };
85
97
  };
86
- const readAnswers = async (command, lines) => {
98
+ const readAnswers = async (command, lines, { noneAllowed = false } = {}) => {
87
99
  const input = environmentOf(command).stdin ?? process.stdin;
88
100
  if (!lines && input.isTTY)
89
101
  throw new CliError("validation_error", `pipe the answers as one JSON object on stdin: echo '{…}' | ${cli} …`, {
90
102
  reason: "input.required",
91
103
  });
92
104
  const text = lines ? await lines() : (await bufferedInput(input, { maxBytes: SETUP_LIMITS.bytes })).toString("utf8");
105
+ // A dry run of no answers names the first step to ask, and lets a contract learn the command's permission key.
106
+ if (noneAllowed && text.trim() === "")
107
+ return {};
93
108
  let parsed;
94
109
  try {
95
110
  parsed = JSON.parse(text);
@@ -192,7 +207,7 @@ export const setupCommand = (setup) => {
192
207
  "--dry-run only checks and saves nothing")
193
208
  .option("--dry-run", "check the answers, and save nothing")
194
209
  .action(async function ({ dryRun }) {
195
- const answers = await readAnswers(this);
210
+ const answers = await readAnswers(this, undefined, { noneAllowed: dryRun === true });
196
211
  const result = await apply(this, answers, { dryRun: dryRun === true, steps: stepsFor(this, false) });
197
212
  renderAnswer(this, contextFor(this, false, true), itemOf(result));
198
213
  });