@wirecat/cli-core 0.611.0 → 0.613.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 (63) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/dist/background/report/render.d.ts +10 -1
  3. package/dist/background/report/render.js +20 -7
  4. package/dist/background/report/schema.d.ts +37 -0
  5. package/dist/background/report/schema.js +98 -4
  6. package/dist/background/report/templates/morning-digest.email.en.liquid +49 -8
  7. package/dist/background/report/templates/morning-digest.email.ru.liquid +49 -8
  8. package/dist/background/report/templates/morning-digest.telegram.en.liquid +49 -9
  9. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +49 -9
  10. package/dist/background/report/templates/morning-digest.text.en.liquid +49 -9
  11. package/dist/background/report/templates/morning-digest.text.ru.liquid +49 -9
  12. package/dist/background/report/view.d.ts +34 -3
  13. package/dist/background/report/view.js +59 -5
  14. package/dist/background/schedules.js +19 -3
  15. package/dist/calendar/mcp/index.d.ts +12 -12
  16. package/dist/cli/enrichment-consents-command.d.ts +19 -0
  17. package/dist/cli/enrichment-consents-command.js +110 -0
  18. package/dist/cli/model-catalogue-command.d.ts +8 -0
  19. package/dist/cli/model-catalogue-command.js +4 -1
  20. package/dist/domain/links.d.ts +72 -0
  21. package/dist/domain/links.js +139 -0
  22. package/dist/embeddings/keys.d.ts +2 -0
  23. package/dist/embeddings/keys.js +2 -0
  24. package/dist/errors/reasons.js +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/meetings/mcp/index.d.ts +15 -15
  28. package/dist/models/anthropic.js +6 -0
  29. package/dist/models/index.d.ts +1 -1
  30. package/dist/models/openai.js +8 -1
  31. package/dist/models/types.d.ts +7 -0
  32. package/dist/services/enrichment-setting.d.ts +50 -0
  33. package/dist/services/enrichment-setting.js +84 -0
  34. package/dist/services/enrichment.d.ts +111 -0
  35. package/dist/services/enrichment.js +240 -0
  36. package/dist/services/index.d.ts +2 -0
  37. package/dist/services/index.js +2 -0
  38. package/dist/services/notes-search.d.ts +15 -1
  39. package/dist/services/notes-search.js +38 -2
  40. package/dist/store/exports.d.ts +1 -0
  41. package/dist/store/exports.js +1 -0
  42. package/dist/store/sqlite/email-index.d.ts +2 -2
  43. package/dist/store/sqlite/email-index.js +6 -4
  44. package/dist/store/sqlite/emails.js +5 -0
  45. package/dist/store/sqlite/enrichments.d.ts +60 -0
  46. package/dist/store/sqlite/enrichments.js +113 -0
  47. package/dist/store/sqlite/entity-types.d.ts +1 -0
  48. package/dist/store/sqlite/entity-types.js +1 -0
  49. package/dist/store/sqlite/index-text.d.ts +2 -0
  50. package/dist/store/sqlite/index-text.js +2 -0
  51. package/dist/store/sqlite/mail-nearest.js +1 -1
  52. package/dist/store/sqlite/manifest.js +2 -0
  53. package/dist/store/sqlite/migrations.generated.js +14 -0
  54. package/dist/store/sqlite/note-index.d.ts +1 -2
  55. package/dist/store/sqlite/note-index.js +25 -4
  56. package/dist/store/sqlite/note-search.js +8 -1
  57. package/dist/store/sqlite/schema/enrichments.d.ts +137 -0
  58. package/dist/store/sqlite/schema/enrichments.js +12 -0
  59. package/dist/store/sqlite/schema.d.ts +1 -0
  60. package/dist/store/sqlite/schema.js +1 -0
  61. package/dist/store/store.d.ts +3 -0
  62. package/dist/store/store.js +5 -0
  63. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,10 +5,71 @@ 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
- ## Unreleased
8
+ ## 0.612.0 — 08.11.2026
9
+
10
+ ### Changed — may break callers
11
+
12
+ - **`models consents` is offered only when the tool asks for it** with `modelCatalogueCommand(app, { enrichment:
13
+ true })`, as memo will. Other CLIs (gcal, mail, drive…) no longer list it: turning enrichment on changes the shared
14
+ store for every CLI, so one tool owns the switch.
15
+
16
+ ### Added
17
+
18
+ - **Write-time enrichment, off by default.** With the owner's consent, a hosted model reads each note, document and
19
+ email and writes standalone facts and two questions in other words; search finds the record by them and still cites
20
+ the record. `models consents show` gives the state, the records covered and the cost estimate;
21
+ `models consents set openai --model gpt-4o-mini` says what would be sent and changes nothing until `--yes`;
22
+ `models consents revoke` turns it off and deletes what was written. Every answer carries `target` (the provider,
23
+ model and endpoint the estimate is about: the setting in force, the one `set` proposes, or the default offer while
24
+ off) with `key: {present, source, env_var}` (never the key), `per_sync`, `syncs_needed`, `offered` (provider and
25
+ model pairs with their prices), `measured` and `off_command`, so a window can write the consent in its own words. One setting for every WireCat CLI, the
26
+ `enrichment` section of the shared settings file. `embedNotes` and `embedMail` enrich up to 600 records a run before
27
+ they embed, each record once per text; a failed batch leaves its records for the next sync. The text goes into the
28
+ stems and a chunk of its own, never into `--exact`, the trigrams or the record's own chunks. An agent cannot turn it
29
+ on. The key: the tool's `embeddings:<provider>` entry, the environment, then its entry named after the provider
30
+ (`embeddingKeys(app).readPlain`). `enrichRecords`, `enrichmentState`, `readEnrichmentSetting` and `writeEnrichmentSetting` from
31
+ `@wirecat/cli-core/services`; `store.enrichment`.
32
+ - Store version 58: `enrichments`, one row per enriched record, deleted with the record. Additive; `minCompatible`
33
+ stays 56.
34
+ - The model gateway's answer carries `usage` (input and output tokens) for OpenAI and Anthropic.
9
35
 
10
36
  ## 0.611.0 — 08.11.2026
11
37
 
38
+ ### Added
39
+
40
+ - **Deep links into WireCat Desktop.** `linkFor(ref, { form: "web" | "app" })` builds
41
+ `https://wirecat.dev/o#/v1/<kind>/<parts>` or `wirecat://open/v1/<kind>/<parts>`; `parseLink` reads either form or
42
+ the bare `/v1/…` path, and `formatLink` writes the path. Kinds: `msg/<provider>/<account>/<chat>/<message>`,
43
+ `chat/<provider>/<account>/<chat>` (an email thread too), `task/<id>`, `tasks/overdue|today|tomorrow`,
44
+ `tasks/new/<ISO time>`, `proposal/<review id>`, `digest/<date>`, `sync/<tool>[/<account>]`. Each part is
45
+ percent-encoded as one segment; another version, an unknown kind, a part too many or empty, more than 6 segments or a
46
+ path over 512 characters is not a link, and a query is ignored. A ref is a store reference (`msg:`, `chat:`,
47
+ `task:`) or, for the kinds that are no reference, the path with a colon after the kind (`proposal:fact%3A512`,
48
+ `tasks:overdue`, `sync:telegram/1001`). The shared config's `links` section sets `base` and `enabled`;
49
+ `WIRECAT_LINKS=off` turns links off for one run, and `linkFor` then answers `null`. A link only opens a screen.
50
+ `test/fixtures/links-v1.json` holds the cases Desktop and the bounce page check their own parsers against.
51
+ - **A report links its items, its task groups and its sync problems.** The renderer fills each item's `links` from its
52
+ `refs` ("открыть"), and a health entry's from its `sync:` ref ("исправить"): the web form for Telegram and mail, the
53
+ app form in `latest.txt`. Links an agent wrote are still dropped, and with links off the words stay without a link.
54
+ - **`wirecat.report/1` takes `scope`, `tasks` and named accounts in `health`.** `scope` (`from`, `to`, `sources[]` of
55
+ `kind` and `accounts`, `counts` of `chats`, `mail`, `tasks`, `meetings`) becomes the last line of all three
56
+ templates: "Просмотрено за 24 ч: Telegram, MAX, WhatsApp, почта (4 ящика) · 31 чат, 12 писем, 17 задач", zero
57
+ counts left out. `tasks` (`overdue`, `today`, `tomorrow`, `new`, `new_since`) becomes one line of `tasks/<filter>`
58
+ links after the section that holds the task items: "Все просроченные (5) · на сегодня (3) · на завтра (2) · новые
59
+ (4)", zero groups left out. A `health[]` entry takes `account`, `reason` (`sync-failed`, `no-schedule`, `quiet`) and
60
+ `since`: "🛠 Telegram (@owner): синхронизация падает с 6 ноября · исправить". An entry with a reason is shown
61
+ whatever its `stale_hours`; a document without the new fields reads as before.
62
+ - **A `task` item needs only its `topic`.** A task created since the last digest may have no due date; it shows no
63
+ deadline phrase, and its person goes on the first line: "📌 Договор с подрядчиком — Пётр Белов".
64
+ - **Each report run keeps its checked document** as `runs/<time>.report.json` beside the run's `.md`, with refs and
65
+ without `links` or `internal`, for Desktop to render.
66
+
67
+ ### Changed — may break callers
68
+
69
+ - `PreparedReport` has `terminal` (plain text with app links, written to `latest.txt`) beside `text` (plain text with
70
+ web links, the email's body) and `document`. A quiet day with a sync problem says "Новых дел нет, но синхронизация
71
+ требует внимания." and lists the health lines below.
72
+
12
73
  ### Fixed
13
74
 
14
75
  - **In `search all`, a hit only words found keeps its place next to the hits around it.** It takes the cosine of the
@@ -1,3 +1,4 @@
1
+ import { type LinkConfig } from "../../domain/links.js";
1
2
  import { type ReportView } from "./view.js";
2
3
  export declare const REPORT_CHANNELS: readonly ["telegram", "email", "text"];
3
4
  export type ReportChannel = (typeof REPORT_CHANNELS)[number];
@@ -42,7 +43,12 @@ export interface ReportRun {
42
43
  }
43
44
  export interface PreparedReport {
44
45
  telegram: string;
46
+ /** Plain text with web links: the email's plain part. */
45
47
  text: string;
48
+ /** Plain text with app links (`wirecat://`), which a desktop terminal opens: `latest.txt`. */
49
+ terminal: string;
50
+ /** The checked `wirecat.report/1` document as JSON, for `<run>.report.json`; absent for an invalid one. */
51
+ document?: string;
46
52
  subject: string;
47
53
  /** The desktop notice: the title line and the summary. */
48
54
  notice: string;
@@ -53,9 +59,12 @@ export interface PreparedReport {
53
59
  * A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
54
60
  * line in the owner's language and is never shown raw.
55
61
  */
56
- export declare const prepareReport: (answer: string, { language, now, timeZone, templates, }: {
62
+ export declare const prepareReport: (answer: string, { language, now, timeZone, templates, links, env, }: {
57
63
  language: string;
58
64
  now: number;
59
65
  timeZone?: string;
60
66
  templates?: Partial<Record<ReportChannel, string>>;
67
+ links?: LinkConfig;
68
+ /** Read for `WIRECAT_LINKS=off`. */
69
+ env?: NodeJS.ProcessEnv;
61
70
  }) => Promise<PreparedReport | undefined>;
@@ -1,8 +1,9 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import { DEFAULT_LINK_CONFIG, linkFor } from "../../domain/links.js";
3
4
  import { safeLiquid } from "../../render/liquid.js";
4
5
  import { TELEGRAM_TEXT_CHARS } from "../deliver.js";
5
- import { parseReport } from "./schema.js";
6
+ import { parseReport, reportDocument } from "./schema.js";
6
7
  import { reportView } from "./view.js";
7
8
  export const REPORT_CHANNELS = ["telegram", "email", "text"];
8
9
  const DEFAULT_LANGUAGE = "en";
@@ -42,6 +43,7 @@ const ALLOWED = {
42
43
  const linkUrls = (view) => new Set([
43
44
  ...view.links,
44
45
  ...view.sections.flatMap((section) => section.items.flatMap((item) => item.links)),
46
+ ...view.sections.flatMap((section) => section.groups.flatMap((group) => (group.link ? [group.link] : []))),
45
47
  ...view.health.items.flatMap((item) => item.links),
46
48
  ].map((link) => link.url));
47
49
  /**
@@ -169,7 +171,7 @@ const INVALID_LINES = {
169
171
  * A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
170
172
  * line in the owner's language and is never shown raw.
171
173
  */
172
- export const prepareReport = async (answer, { language, now, timeZone, templates = {}, }) => {
174
+ export const prepareReport = async (answer, { language, now, timeZone, templates = {}, links = DEFAULT_LINK_CONFIG, env = process.env, }) => {
173
175
  const parsed = parseReport(answer);
174
176
  if (!parsed)
175
177
  return undefined;
@@ -178,6 +180,7 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
178
180
  return {
179
181
  telegram: escapeHtml(line),
180
182
  text: line,
183
+ terminal: line,
181
184
  subject: line,
182
185
  notice: line,
183
186
  invalid: true,
@@ -185,17 +188,27 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
185
188
  };
186
189
  }
187
190
  const shipped = existsSync(templateFile(parsed.report.kind, "telegram", language)) ? language : DEFAULT_LANGUAGE;
188
- const view = reportView(parsed.report, { language: shipped, now, ...(timeZone ? { timeZone } : {}) });
189
- const telegram = await renderReport(view, "telegram", templateOf(templates, "telegram"));
190
- const text = await renderReport(view, "text", templateOf(templates, "text"));
191
+ const viewFor = (form) => reportView(parsed.report, {
192
+ language: shipped,
193
+ now,
194
+ ...(timeZone ? { timeZone } : {}),
195
+ linkOf: (ref) => linkFor(ref, { form, config: links, env }),
196
+ });
197
+ const web = viewFor("web");
198
+ const telegram = await renderReport(web, "telegram", templateOf(templates, "telegram"));
199
+ const text = await renderReport(web, "text", templateOf(templates, "text"));
200
+ const terminal = await renderReport(viewFor("app"), "text", templateOf(templates, "text"));
201
+ const renderings = [telegram, text, terminal];
191
202
  const reasons = [
192
- ...(telegram.templateFailed || text.templateFailed ? [REPORT_REASONS.templateFailed] : []),
193
- ...(telegram.templateTags + text.templateTags > 0 ? [REPORT_REASONS.templateTags] : []),
203
+ ...(renderings.some((one) => one.templateFailed) ? [REPORT_REASONS.templateFailed] : []),
204
+ ...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
194
205
  ];
195
206
  const title = text.text.split("\n")[0] ?? "";
196
207
  return {
197
208
  telegram: telegram.text,
198
209
  text: text.text,
210
+ terminal: terminal.text,
211
+ document: `${JSON.stringify(reportDocument(parsed.report), null, 2)}\n`,
199
212
  subject: title,
200
213
  notice: [title, parsed.report.summary].filter(Boolean).join("\n"),
201
214
  invalid: false,
@@ -34,11 +34,41 @@ export interface ReportSection {
34
34
  items: ReportItem[];
35
35
  more: number;
36
36
  }
37
+ export declare const HEALTH_REASONS: readonly ["sync-failed", "no-schedule", "quiet"];
38
+ export type HealthReason = (typeof HEALTH_REASONS)[number];
39
+ /** One account's sync problem. A document written before accounts were named has only `source` and `staleHours`. */
37
40
  export interface HealthEntry {
38
41
  source: string;
42
+ /** The account's name, username or address, never a raw id. */
43
+ account: string | null;
44
+ reason: HealthReason | null;
45
+ since: string | null;
39
46
  staleHours: number;
40
47
  refs: string[];
41
48
  }
49
+ /** What the digest was built from: memo fills it from the agenda, not the agent. */
50
+ export interface ReportScope {
51
+ from: string;
52
+ to: string;
53
+ sources: {
54
+ kind: ChannelKind;
55
+ accounts: number;
56
+ }[];
57
+ counts: {
58
+ chats: number;
59
+ mail: number;
60
+ tasks: number;
61
+ meetings: number;
62
+ };
63
+ }
64
+ /** The open task groups, each opened by a `tasks/<filter>` link; `new` counts what was created since `newSince`. */
65
+ export interface TaskCounts {
66
+ overdue: number;
67
+ today: number;
68
+ tomorrow: number;
69
+ new: number;
70
+ newSince: string | null;
71
+ }
42
72
  /** A `wirecat.report/1` document as the renderers read it: checked, cut to its limits, with no `links` or `internal`. */
43
73
  export interface Report {
44
74
  kind: ReportKind;
@@ -46,12 +76,19 @@ export interface Report {
46
76
  summary: string | null;
47
77
  sections: ReportSection[];
48
78
  health: HealthEntry[];
79
+ scope: ReportScope | null;
80
+ tasks: TaskCounts | null;
49
81
  }
50
82
  /** What a leak pattern removed from agent text: a store reference, backticks, a `--flag` or a snake_case word. */
51
83
  export declare const withoutLeaks: (text: string) => {
52
84
  text: string;
53
85
  leaks: number;
54
86
  };
87
+ /**
88
+ * The checked document in the `wirecat.report/1` shape it came in, for `<run>.report.json`: what the renderers kept,
89
+ * with refs (Desktop builds its own links from them) and without `links` or `internal`.
90
+ */
91
+ export declare const reportDocument: (report: Report) => Record<string, unknown>;
55
92
  export type ParsedReport = {
56
93
  report: Report;
57
94
  leaks: number;
@@ -4,11 +4,21 @@ export const REPORT_KINDS = ["morning-digest"];
4
4
  export const SECTION_KINDS = ["today", "decisions", "money", "meetings", "projects", "mail"];
5
5
  export const ITEM_TYPES = ["reply", "question", "task", "fact", "risk", "money", "decision", "meeting"];
6
6
  export const CHANNEL_KINDS = ["telegram", "max", "whatsapp", "mail", "meeting", "task"];
7
- const TEXT_LIMITS = { summary: 120, who: 80, topic: 60, action: 120, detail: 160, quote: 100, source: 40 };
7
+ export const HEALTH_REASONS = ["sync-failed", "no-schedule", "quiet"];
8
+ const TEXT_LIMITS = {
9
+ summary: 120,
10
+ who: 80,
11
+ topic: 60,
12
+ action: 120,
13
+ detail: 160,
14
+ quote: 100,
15
+ source: 40,
16
+ account: 60,
17
+ };
8
18
  const REQUIRED = {
9
19
  reply: ["who", "topic", "action", "since"],
10
20
  question: ["who", "topic", "action"],
11
- task: ["topic", "due"],
21
+ task: ["topic"],
12
22
  fact: ["topic", "detail"],
13
23
  risk: ["topic", "detail", "action"],
14
24
  money: ["who", "topic", "amount"],
@@ -76,6 +86,54 @@ const amountOf = (value, at) => {
76
86
  direction: oneOf(["in", "out"], value.direction, `${at}.direction`),
77
87
  };
78
88
  };
89
+ const wholeOr0 = (value, at) => (value === undefined || value === null ? 0 : whole(value, at));
90
+ const scopeOf = (value) => {
91
+ if (value === undefined || value === null)
92
+ return null;
93
+ if (!isObject(value))
94
+ throw new Invalid("scope");
95
+ const from = momentOf(value.from, "scope.from");
96
+ const to = momentOf(value.to, "scope.to");
97
+ if (from === null || to === null || Date.parse(to) < Date.parse(from))
98
+ throw new Invalid("scope.to");
99
+ const sources = value.sources === undefined || value.sources === null ? [] : value.sources;
100
+ if (!Array.isArray(sources))
101
+ throw new Invalid("scope.sources");
102
+ const counts = value.counts === undefined || value.counts === null ? {} : value.counts;
103
+ if (!isObject(counts))
104
+ throw new Invalid("scope.counts");
105
+ return {
106
+ from,
107
+ to,
108
+ sources: sources.map((source, s) => {
109
+ if (!isObject(source))
110
+ throw new Invalid(`scope.sources[${s}]`);
111
+ return {
112
+ kind: oneOf(CHANNEL_KINDS, source.kind, `scope.sources[${s}].kind`),
113
+ accounts: source.accounts === undefined ? 1 : whole(source.accounts, `scope.sources[${s}].accounts`),
114
+ };
115
+ }),
116
+ counts: {
117
+ chats: wholeOr0(counts.chats, "scope.counts.chats"),
118
+ mail: wholeOr0(counts.mail, "scope.counts.mail"),
119
+ tasks: wholeOr0(counts.tasks, "scope.counts.tasks"),
120
+ meetings: wholeOr0(counts.meetings, "scope.counts.meetings"),
121
+ },
122
+ };
123
+ };
124
+ const tasksOf = (value) => {
125
+ if (value === undefined || value === null)
126
+ return null;
127
+ if (!isObject(value))
128
+ throw new Invalid("tasks");
129
+ return {
130
+ overdue: wholeOr0(value.overdue, "tasks.overdue"),
131
+ today: wholeOr0(value.today, "tasks.today"),
132
+ tomorrow: wholeOr0(value.tomorrow, "tasks.tomorrow"),
133
+ new: wholeOr0(value.new, "tasks.new"),
134
+ newSince: momentOf(value.new_since, "tasks.new_since"),
135
+ };
136
+ };
79
137
  const cut = (text, limit) => (text.length <= limit ? text : `${text.slice(0, limit - 1).trimEnd()}…`);
80
138
  /**
81
139
  * Checks a parsed document and keeps what the renderers may show. Any agent string loses what `withoutLeaks` finds
@@ -151,17 +209,53 @@ const checked = (document) => {
151
209
  sections,
152
210
  health: health.map((entry, h) => {
153
211
  const at = `health[${h}]`;
154
- if (!isObject(entry) || typeof entry.stale_hours !== "number" || !(entry.stale_hours >= 0))
212
+ if (!isObject(entry))
155
213
  throw new Invalid(at);
214
+ const reason = entry.reason === undefined || entry.reason === null
215
+ ? null
216
+ : oneOf(HEALTH_REASONS, entry.reason, `${at}.reason`);
217
+ // A named reason is the problem itself; the hours are only how stale an account without one is.
218
+ const hours = entry.stale_hours ?? (reason === null ? undefined : 0);
219
+ if (typeof hours !== "number" || !(hours >= 0))
220
+ throw new Invalid(`${at}.stale_hours`);
156
221
  const source = text(entry.source, "source", `${at}.source`);
157
222
  if (source === null)
158
223
  throw new Invalid(`${at}.source`);
159
- return { source, staleHours: entry.stale_hours, refs: refsOf(entry.refs, `${at}.refs`) };
224
+ return {
225
+ source,
226
+ account: text(entry.account, "account", `${at}.account`),
227
+ reason,
228
+ since: momentOf(entry.since, `${at}.since`),
229
+ staleHours: hours,
230
+ refs: refsOf(entry.refs, `${at}.refs`),
231
+ };
160
232
  }),
233
+ scope: scopeOf(document.scope),
234
+ tasks: tasksOf(document.tasks),
161
235
  },
162
236
  leaks,
163
237
  };
164
238
  };
239
+ /**
240
+ * The checked document in the `wirecat.report/1` shape it came in, for `<run>.report.json`: what the renderers kept,
241
+ * with refs (Desktop builds its own links from them) and without `links` or `internal`.
242
+ */
243
+ export const reportDocument = (report) => ({
244
+ format: REPORT_FORMAT,
245
+ kind: report.kind,
246
+ date: report.date,
247
+ summary: report.summary,
248
+ sections: report.sections,
249
+ health: report.health.map(({ staleHours, ...entry }) => ({ ...entry, stale_hours: staleHours })),
250
+ scope: report.scope,
251
+ tasks: report.tasks && {
252
+ overdue: report.tasks.overdue,
253
+ today: report.tasks.today,
254
+ tomorrow: report.tasks.tomorrow,
255
+ new: report.tasks.new,
256
+ new_since: report.tasks.newSince,
257
+ },
258
+ });
165
259
  /**
166
260
  * 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
167
261
  * report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
@@ -12,7 +12,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
12
12
  {%- if summary %}{{ nl }}<p style="margin:0 0 12px">{{ summary }}</p>{% endif -%}
13
13
  {%- if quiet -%}
14
14
  {{ nl }}<p style="margin:0 0 12px">
15
- {%- if health.items.size > 0 %}Nothing new, but {{ health.items[0].source }} has not synced for {{ health.items[0].span }}.
15
+ {%- if health.items.size > 0 %}Nothing new, but sync needs attention.
16
16
  {%- else %}A quiet morning: nothing urgent.{% endif %}</p>
17
17
  {%- endif -%}
18
18
  {%- for section in sections -%}
@@ -37,7 +37,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
37
37
  {%- case item.type -%}
38
38
  {%- when "reply" %}<b>{{ item.who }} · {{ item.topic }}</b> — {{ item.action }}
39
39
  {%- when "question" %}<b>{{ item.who }}</b> asks: {{ item.action }}
40
- {%- when "task" %}<b>{{ item.topic }}</b> — {{ due }}
40
+ {%- when "task" %}<b>{{ item.topic }}</b>{% if due != "" %} — {{ due }}{% elsif item.who %} — {{ item.who }}{% endif %}
41
41
  {%- when "fact" %}<b>{{ item.topic }}</b>: {{ item.detail }}
42
42
  {%- when "risk" %}<b>{{ item.topic }}</b>: {{ item.detail }} → {{ item.action }}
43
43
  {%- when "money" %}<b>{{ item.amount.text }} · {{ item.who }} · {{ item.topic }}</b>{% if item.action %} — {{ item.action }}{% endif %}
@@ -55,7 +55,8 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
55
55
  {%- if due != "" and "risk,money,decision" contains item.type %}{{ sep }}{{ due }}{% assign sep = " · " %}{% endif -%}
56
56
  {%- if item.action and "task,meeting" contains item.type %}{{ sep }}{{ item.action }}{% assign sep = " · " %}{% endif -%}
57
57
  {%- if item.detail and "task,money,meeting,decision" contains item.type %}{{ sep }}{{ item.detail }}{% assign sep = " · " %}{% endif -%}
58
- {%- if item.who and "task,fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
58
+ {%- if item.who and "fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
59
+ {%- if item.who and item.type == "task" and due != "" %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
59
60
  {%- if item.channel %}{{ sep }}
60
61
  {%- case item.channel -%}
61
62
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
@@ -69,11 +70,51 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
69
70
  {%- if second != "" %}<br><span style="{{ muted }}">{{ second }}</span>{% endif %}</p>
70
71
  {%- endfor -%}
71
72
  {%- if section.more > 0 %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">{{ section.more }} more</p>{% endif -%}
73
+ {%- if section.groups.size > 0 %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">
74
+ {%- for group in section.groups -%}
75
+ {%- unless forloop.first %} · {% endunless -%}
76
+ {%- capture words -%}
77
+ {%- case group.filter -%}
78
+ {%- when "overdue" %}All overdue
79
+ {%- when "today" %}{% if forloop.first %}Due today{% else %}due today{% endif %}
80
+ {%- when "tomorrow" %}{% if forloop.first %}Due tomorrow{% else %}due tomorrow{% endif %}
81
+ {%- when "new" %}{% if forloop.first %}New{% else %}new{% endif %}
82
+ {%- endcase %} ({{ group.count }})
83
+ {%- endcapture -%}
84
+ {%- if group.link %}<a href="{{ group.link.url }}" style="color:#3b82c4">{{ words }}</a>{% else %}{{ words }}{% endif -%}
85
+ {%- endfor -%}
86
+ </p>{%- endif -%}
72
87
  {%- endfor -%}
73
- {%- unless quiet -%}
74
- {%- for source in health.items -%}
75
- {{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }} has not synced for {{ source.span }}
76
- {%- for link in source.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor %}</p>
88
+ {%- for source in health.items -%}
89
+ {{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }}
90
+ {%- if source.account %} ({{ source.account }}){% endif -%}
91
+ {%- case source.reason -%}
92
+ {%- when "sync-failed" %}: sync failing{% if source.since %} since {{ source.since.date }}{% endif %}
93
+ {%- when "no-schedule" %}: no sync schedule
94
+ {%- when "quiet" %}: nothing new {% if source.since %}since {{ source.since.date }}{% else %}for {{ source.span }}{% endif %}
95
+ {%- else %} has not synced for {{ source.span }}
96
+ {%- endcase -%}
97
+ {%- for link in source.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor -%}</p>
98
+ {%- endfor -%}
99
+ {%- if scope -%}
100
+ {{ nl }}<p style="margin:20px 0 0;{{ muted }}">Viewed over {{ scope.window }}
101
+ {%- for source in scope.sources -%}
102
+ {%- if forloop.first %}: {% else %}, {% endif -%}
103
+ {%- case source.kind -%}
104
+ {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
105
+ {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks
106
+ {%- endcase -%}
107
+ {%- 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 -%}
77
108
  {%- endfor -%}
78
- {%- endunless -%}
109
+ {%- for count in scope.counts -%}
110
+ {%- if forloop.first %} · {% else %}, {% endif -%}
111
+ {{ count.count }} {% case count.kind -%}
112
+ {%- when "chats" %}{% if count.plural == "one" %}chat{% else %}chats{% endif %}
113
+ {%- when "mail" %}{% if count.plural == "one" %}email{% else %}emails{% endif %}
114
+ {%- when "tasks" %}{% if count.plural == "one" %}task{% else %}tasks{% endif %}
115
+ {%- when "meetings" %}{% if count.plural == "one" %}meeting{% else %}meetings{% endif %}
116
+ {%- endcase -%}
117
+ {%- endfor -%}
118
+ </p>
119
+ {%- endif -%}
79
120
  {{ nl }}</div>
@@ -12,7 +12,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
12
12
  {%- if summary %}{{ nl }}<p style="margin:0 0 12px">{{ summary }}</p>{% endif -%}
13
13
  {%- if quiet -%}
14
14
  {{ nl }}<p style="margin:0 0 12px">
15
- {%- if health.items.size > 0 %}Новых дел нет, но {{ health.items[0].source }} не обновлялся {{ health.items[0].span }}.
15
+ {%- if health.items.size > 0 %}Новых дел нет, но синхронизация требует внимания.
16
16
  {%- else %}Тихое утро: ничего срочного.{% endif %}</p>
17
17
  {%- endif -%}
18
18
  {%- for section in sections -%}
@@ -37,7 +37,7 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
37
37
  {%- case item.type -%}
38
38
  {%- when "reply" %}<b>{{ item.who }} · {{ item.topic }}</b> — {{ item.action }}
39
39
  {%- when "question" %}<b>{{ item.who }}</b> спрашивает: {{ item.action }}
40
- {%- when "task" %}<b>{{ item.topic }}</b> — {{ due }}
40
+ {%- when "task" %}<b>{{ item.topic }}</b>{% if due != "" %} — {{ due }}{% elsif item.who %} — {{ item.who }}{% endif %}
41
41
  {%- when "fact" %}<b>{{ item.topic }}</b>: {{ item.detail }}
42
42
  {%- when "risk" %}<b>{{ item.topic }}</b>: {{ item.detail }} → {{ item.action }}
43
43
  {%- when "money" %}<b>{{ item.amount.text }} · {{ item.who }} · {{ item.topic }}</b>{% if item.action %} — {{ item.action }}{% endif %}
@@ -55,7 +55,8 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
55
55
  {%- if due != "" and "risk,money,decision" contains item.type %}{{ sep }}{{ due }}{% assign sep = " · " %}{% endif -%}
56
56
  {%- if item.action and "task,meeting" contains item.type %}{{ sep }}{{ item.action }}{% assign sep = " · " %}{% endif -%}
57
57
  {%- if item.detail and "task,money,meeting,decision" contains item.type %}{{ sep }}{{ item.detail }}{% assign sep = " · " %}{% endif -%}
58
- {%- if item.who and "task,fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
58
+ {%- if item.who and "fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
59
+ {%- if item.who and item.type == "task" and due != "" %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
59
60
  {%- if item.channel %}{{ sep }}
60
61
  {%- case item.channel -%}
61
62
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
@@ -69,11 +70,51 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
69
70
  {%- if second != "" %}<br><span style="{{ muted }}">{{ second }}</span>{% endif %}</p>
70
71
  {%- endfor -%}
71
72
  {%- if section.more > 0 %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">ещё {{ section.more }}</p>{% endif -%}
73
+ {%- if section.groups.size > 0 %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">
74
+ {%- for group in section.groups -%}
75
+ {%- unless forloop.first %} · {% endunless -%}
76
+ {%- capture words -%}
77
+ {%- case group.filter -%}
78
+ {%- when "overdue" %}Все просроченные
79
+ {%- when "today" %}{% if forloop.first %}На сегодня{% else %}на сегодня{% endif %}
80
+ {%- when "tomorrow" %}{% if forloop.first %}На завтра{% else %}на завтра{% endif %}
81
+ {%- when "new" %}{% if forloop.first %}Новые{% else %}новые{% endif %}
82
+ {%- endcase %} ({{ group.count }})
83
+ {%- endcapture -%}
84
+ {%- if group.link %}<a href="{{ group.link.url }}" style="color:#3b82c4">{{ words }}</a>{% else %}{{ words }}{% endif -%}
85
+ {%- endfor -%}
86
+ </p>{%- endif -%}
72
87
  {%- endfor -%}
73
- {%- unless quiet -%}
74
- {%- for source in health.items -%}
75
- {{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }} не обновлялся {{ source.span }}
76
- {%- for link in source.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor %}</p>
88
+ {%- for source in health.items -%}
89
+ {{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }}
90
+ {%- if source.account %} ({{ source.account }}){% endif -%}
91
+ {%- case source.reason -%}
92
+ {%- when "sync-failed" %}: синхронизация падает{% if source.since %} с {{ source.since.date }}{% endif %}
93
+ {%- when "no-schedule" %}: нет расписания синхронизации
94
+ {%- when "quiet" %}: ничего нового {% if source.since %}с {{ source.since.date }}{% else %}{{ source.span }}{% endif %}
95
+ {%- else %} не обновлялся {{ source.span }}
96
+ {%- endcase -%}
97
+ {%- for link in source.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor -%}</p>
98
+ {%- endfor -%}
99
+ {%- if scope -%}
100
+ {{ nl }}<p style="margin:20px 0 0;{{ muted }}">Просмотрено за {{ scope.window }}
101
+ {%- for source in scope.sources -%}
102
+ {%- if forloop.first %}: {% else %}, {% endif -%}
103
+ {%- case source.kind -%}
104
+ {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
105
+ {%- when "mail" %}почта{% when "meeting" %}встречи{% when "task" %}задачи
106
+ {%- endcase -%}
107
+ {%- 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 -%}
77
108
  {%- endfor -%}
78
- {%- endunless -%}
109
+ {%- for count in scope.counts -%}
110
+ {%- if forloop.first %} · {% else %}, {% endif -%}
111
+ {{ count.count }} {% case count.kind -%}
112
+ {%- when "chats" %}{% case count.plural %}{% when "one" %}чат{% when "few" %}чата{% else %}чатов{% endcase %}
113
+ {%- when "mail" %}{% case count.plural %}{% when "one" %}письмо{% when "few" %}письма{% else %}писем{% endcase %}
114
+ {%- when "tasks" %}{% case count.plural %}{% when "one" %}задача{% when "few" %}задачи{% else %}задач{% endcase %}
115
+ {%- when "meetings" %}{% case count.plural %}{% when "one" %}встреча{% when "few" %}встречи{% else %}встреч{% endcase %}
116
+ {%- endcase -%}
117
+ {%- endfor -%}
118
+ </p>
119
+ {%- endif -%}
79
120
  {{ nl }}</div>
@@ -10,7 +10,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
10
10
  {%- if summary %}{{ nl }}{{ summary }}{% endif -%}
11
11
  {%- if quiet -%}
12
12
  {{ nl }}{{ nl }}
13
- {%- if health.items.size > 0 %}Nothing new, but {{ health.items[0].source }} has not synced for {{ health.items[0].span }}.
13
+ {%- if health.items.size > 0 %}Nothing new, but sync needs attention.
14
14
  {%- else %}A quiet morning: nothing urgent.{% endif -%}
15
15
  {%- endif -%}
16
16
  {%- for section in sections -%}
@@ -35,7 +35,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
35
35
  {%- case item.type -%}
36
36
  {%- when "reply" %}<b>{{ item.who }} · {{ item.topic }}</b> — {{ item.action }}
37
37
  {%- when "question" %}<b>{{ item.who }}</b> asks: {{ item.action }}
38
- {%- when "task" %}<b>{{ item.topic }}</b> — {{ due }}
38
+ {%- when "task" %}<b>{{ item.topic }}</b>{% if due != "" %} — {{ due }}{% elsif item.who %} — {{ item.who }}{% endif %}
39
39
  {%- when "fact" %}<b>{{ item.topic }}</b>: {{ item.detail }}
40
40
  {%- when "risk" %}<b>{{ item.topic }}</b>: {{ item.detail }} → {{ item.action }}
41
41
  {%- when "money" %}<b>{{ item.amount.text }} · {{ item.who }} · {{ item.topic }}</b>{% if item.action %} — {{ item.action }}{% endif %}
@@ -53,7 +53,8 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
53
53
  {%- if due != "" and "risk,money,decision" contains item.type %}{{ sep }}{{ due }}{% assign sep = " · " %}{% endif -%}
54
54
  {%- if item.action and "task,meeting" contains item.type %}{{ sep }}{{ item.action }}{% assign sep = " · " %}{% endif -%}
55
55
  {%- if item.detail and "task,money,meeting,decision" contains item.type %}{{ sep }}{{ item.detail }}{% assign sep = " · " %}{% endif -%}
56
- {%- if item.who and "task,fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
56
+ {%- if item.who and "fact,risk,decision" contains item.type %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
57
+ {%- if item.who and item.type == "task" and due != "" %}{{ sep }}{{ item.who }}{% assign sep = " · " %}{% endif -%}
57
58
  {%- if item.channel %}{{ sep }}
58
59
  {%- case item.channel -%}
59
60
  {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
@@ -67,11 +68,50 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
67
68
  {%- if second != "" %}{{ nl }}{{ second }}{% endif -%}
68
69
  {%- endfor -%}
69
70
  {%- if section.more > 0 %}{{ nl }}{{ section.more }} more{% endif -%}
71
+ {%- if section.groups.size > 0 %}{{ nl }}
72
+ {%- for group in section.groups -%}
73
+ {%- unless forloop.first %} · {% endunless -%}
74
+ {%- capture words -%}
75
+ {%- case group.filter -%}
76
+ {%- when "overdue" %}All overdue
77
+ {%- when "today" %}{% if forloop.first %}Due today{% else %}due today{% endif %}
78
+ {%- when "tomorrow" %}{% if forloop.first %}Due tomorrow{% else %}due tomorrow{% endif %}
79
+ {%- when "new" %}{% if forloop.first %}New{% else %}new{% endif %}
80
+ {%- endcase %} ({{ group.count }})
81
+ {%- endcapture -%}
82
+ {%- if group.link %}<a href="{{ group.link.url }}">{{ words }}</a>{% else %}{{ words }}{% endif -%}
83
+ {%- endfor -%}
84
+ {%- endif -%}
70
85
  {%- endfor -%}
71
- {%- unless quiet -%}
72
- {%- if health.items.size > 0 %}{{ nl }}{% endif -%}
73
- {%- for source in health.items -%}
74
- {{ nl }}{{ health.emoji }} {{ source.source }} has not synced for {{ source.span }}
75
- {%- for link in source.links %} · <a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
86
+ {%- if health.items.size > 0 %}{{ nl }}{% endif -%}
87
+ {%- for source in health.items -%}
88
+ {{ nl }}{{ health.emoji }} {{ source.source }}
89
+ {%- if source.account %} ({{ source.account }}){% endif -%}
90
+ {%- case source.reason -%}
91
+ {%- when "sync-failed" %}: sync failing{% if source.since %} since {{ source.since.date }}{% endif %}
92
+ {%- when "no-schedule" %}: no sync schedule
93
+ {%- when "quiet" %}: nothing new {% if source.since %}since {{ source.since.date }}{% else %}for {{ source.span }}{% endif %}
94
+ {%- else %} has not synced for {{ source.span }}
95
+ {%- endcase -%}
96
+ {%- for link in source.links %} · <a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
97
+ {%- endfor -%}
98
+ {%- if scope -%}
99
+ {{ nl }}{{ nl }}Viewed over {{ scope.window }}
100
+ {%- for source in scope.sources -%}
101
+ {%- if forloop.first %}: {% else %}, {% endif -%}
102
+ {%- case source.kind -%}
103
+ {%- when "telegram" %}Telegram{% when "max" %}MAX{% when "whatsapp" %}WhatsApp
104
+ {%- when "mail" %}mail{% when "meeting" %}meetings{% when "task" %}tasks
105
+ {%- endcase -%}
106
+ {%- 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 -%}
76
107
  {%- endfor -%}
77
- {%- endunless -%}
108
+ {%- for count in scope.counts -%}
109
+ {%- if forloop.first %} · {% else %}, {% endif -%}
110
+ {{ count.count }} {% case count.kind -%}
111
+ {%- when "chats" %}{% if count.plural == "one" %}chat{% else %}chats{% endif %}
112
+ {%- when "mail" %}{% if count.plural == "one" %}email{% else %}emails{% endif %}
113
+ {%- when "tasks" %}{% if count.plural == "one" %}task{% else %}tasks{% endif %}
114
+ {%- when "meetings" %}{% if count.plural == "one" %}meeting{% else %}meetings{% endif %}
115
+ {%- endcase -%}
116
+ {%- endfor -%}
117
+ {%- endif -%}