@wirecat/cli-core 0.614.0 → 0.616.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/dist/background/report/messages.d.ts +108 -0
- package/dist/background/report/messages.js +230 -0
- package/dist/background/report/render.d.ts +41 -5
- package/dist/background/report/render.js +115 -25
- package/dist/background/report/schema.d.ts +7 -1
- package/dist/background/report/schema.js +9 -3
- package/dist/background/report/stored-templates.d.ts +66 -0
- package/dist/background/report/stored-templates.js +85 -0
- package/dist/background/report/templates/morning-digest.email.en.liquid +3 -0
- package/dist/background/report/templates/morning-digest.email.ru.liquid +3 -0
- package/dist/background/report/templates/morning-digest.sample.json +157 -0
- package/dist/background/report/templates/morning-digest.telegram.en.liquid +3 -0
- package/dist/background/report/templates/morning-digest.telegram.ru.liquid +3 -0
- package/dist/background/report/templates/morning-digest.text.en.liquid +3 -0
- package/dist/background/report/templates/morning-digest.text.ru.liquid +3 -0
- package/dist/background/report/templates/schedule-failed.email.en.liquid +12 -0
- package/dist/background/report/templates/schedule-failed.email.ru.liquid +12 -0
- package/dist/background/report/templates/schedule-failed.sample.json +10 -0
- package/dist/background/report/templates/schedule-failed.telegram.en.liquid +9 -0
- package/dist/background/report/templates/schedule-failed.telegram.ru.liquid +9 -0
- package/dist/background/report/templates/schedule-failed.text.en.liquid +9 -0
- package/dist/background/report/templates/schedule-failed.text.ru.liquid +9 -0
- package/dist/background/report/templates/weekly-gaps.email.en.liquid +19 -0
- package/dist/background/report/templates/weekly-gaps.email.ru.liquid +19 -0
- package/dist/background/report/templates/weekly-gaps.sample.json +33 -0
- package/dist/background/report/templates/weekly-gaps.telegram.en.liquid +15 -0
- package/dist/background/report/templates/weekly-gaps.telegram.ru.liquid +15 -0
- package/dist/background/report/templates/weekly-gaps.text.en.liquid +14 -0
- package/dist/background/report/templates/weekly-gaps.text.ru.liquid +14 -0
- package/dist/background/report/view.d.ts +5 -0
- package/dist/background/report/view.js +9 -1
- package/dist/background/schedules.d.ts +13 -2
- package/dist/background/schedules.js +128 -30
- package/dist/cli/help/sections.js +1 -0
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/schedule/schedule-command.d.ts +2 -0
- package/dist/cli/schedule/schedule-command.js +21 -2
- package/dist/cli/shared-command-exports.d.ts +1 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/templates-command.d.ts +16 -0
- package/dist/cli/templates-command.js +266 -0
- package/dist/domain/links.d.ts +1 -1
- package/dist/domain/links.js +1 -1
- package/dist/entities/fact.d.ts +4 -0
- package/dist/entities/fact.js +2 -1
- package/dist/entities/fields.d.ts +5 -0
- package/dist/entities/fields.js +3 -0
- package/dist/entities/index.d.ts +21 -1
- package/dist/entities/index.js +3 -1
- package/dist/entities/list-results.d.ts +4 -2
- package/dist/entities/list-results.js +4 -2
- package/dist/entities/memory.d.ts +4 -0
- package/dist/entities/memory.js +2 -1
- package/dist/entities/template.d.ts +11 -0
- package/dist/entities/template.js +12 -0
- package/dist/errors/reasons.js +13 -0
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/exports.d.ts +2 -0
- package/dist/store/exports.js +2 -0
- package/dist/store/index.d.ts +4 -2
- package/dist/store/index.js +1 -0
- package/dist/store/people.d.ts +7 -0
- package/dist/store/people.js +4 -0
- package/dist/store/source-review.d.ts +21 -0
- package/dist/store/sqlite/accounts.d.ts +3 -1
- package/dist/store/sqlite/accounts.js +10 -3
- package/dist/store/sqlite/added-sources.d.ts +16 -0
- package/dist/store/sqlite/added-sources.js +22 -0
- package/dist/store/sqlite/facts.js +3 -2
- package/dist/store/sqlite/imported-documents.js +3 -2
- package/dist/store/sqlite/knowledge.js +6 -4
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/memories.js +5 -4
- package/dist/store/sqlite/mention-drain.js +9 -1
- package/dist/store/sqlite/merged-persons.d.ts +24 -0
- package/dist/store/sqlite/merged-persons.js +59 -0
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/notes.js +5 -4
- package/dist/store/sqlite/person-links.d.ts +10 -1
- package/dist/store/sqlite/person-links.js +14 -6
- package/dist/store/sqlite/person-merges.d.ts +39 -0
- package/dist/store/sqlite/person-merges.js +136 -0
- package/dist/store/sqlite/person-preparation.js +11 -8
- package/dist/store/sqlite/person-resolution.js +2 -1
- package/dist/store/sqlite/person-scope.js +2 -1
- package/dist/store/sqlite/relation-list.js +3 -2
- package/dist/store/sqlite/reported-relations.js +6 -3
- package/dist/store/sqlite/schema/templates.d.ts +242 -0
- package/dist/store/sqlite/schema/templates.js +23 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +1 -0
- package/dist/store/sqlite/source-review.d.ts +20 -1
- package/dist/store/sqlite/source-review.js +74 -3
- package/dist/store/sqlite/task-board.d.ts +6 -1
- package/dist/store/sqlite/task-board.js +22 -4
- package/dist/store/sqlite/templates.d.ts +38 -0
- package/dist/store/sqlite/templates.js +69 -0
- package/dist/store/sqlite/work-tasks.js +8 -9
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/types.d.ts +2 -0
- package/package.json +4 -4
- package/parity.json +19 -0
|
@@ -40,28 +40,39 @@ const ALLOWED = {
|
|
|
40
40
|
span: ["style"],
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
/** Every link URL anywhere in the view: the only places a template's `href` may point. */
|
|
44
|
+
const linkUrls = (view) => {
|
|
45
|
+
const urls = new Set();
|
|
46
|
+
const walk = (value) => {
|
|
47
|
+
if (Array.isArray(value))
|
|
48
|
+
value.forEach(walk);
|
|
49
|
+
else if (value && typeof value === "object") {
|
|
50
|
+
const { kind, url, label } = value;
|
|
51
|
+
if ((kind === "open" || kind === "web") && typeof url === "string" && typeof label === "string")
|
|
52
|
+
urls.add(url);
|
|
53
|
+
else
|
|
54
|
+
Object.values(value).forEach(walk);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
walk(view);
|
|
58
|
+
return urls;
|
|
59
|
+
};
|
|
49
60
|
/**
|
|
50
61
|
* What a template's HTML may keep, enforced after it rendered: the channel's tags and attributes only, a `style`
|
|
51
|
-
* with no `url(`, and an `href` only to a URL of the view model. Anything else goes, its text kept; `
|
|
52
|
-
* what went.
|
|
62
|
+
* with no `url(`, and an `href` only to a URL of the view model. Anything else goes, its text kept; `removed` names
|
|
63
|
+
* what went, once per occurrence, and `changed` counts it.
|
|
53
64
|
*/
|
|
54
65
|
export const sanitizeHtml = (channel, html, urls) => {
|
|
55
66
|
const allowed = ALLOWED[channel];
|
|
56
|
-
|
|
67
|
+
const removed = [];
|
|
57
68
|
const dropped = [];
|
|
58
|
-
const withoutBlocks = html.replace(/<(script|style|iframe|object)\b[\s\S]*?(<\/\1\s*>|$)/gi, () => {
|
|
59
|
-
|
|
69
|
+
const withoutBlocks = html.replace(/<(script|style|iframe|object)\b[\s\S]*?(<\/\1\s*>|$)/gi, (_, name) => {
|
|
70
|
+
removed.push(`<${String(name).toLowerCase()}> and its content`);
|
|
60
71
|
return "";
|
|
61
72
|
});
|
|
62
73
|
const out = withoutBlocks.replace(/<(\/?)([a-zA-Z][a-zA-Z0-9]*)\b([^<>]*)>|[<>]/g, (tag, close, name, rest) => {
|
|
63
74
|
if (name === undefined) {
|
|
64
|
-
|
|
75
|
+
removed.push(`a bare ${tag}`);
|
|
65
76
|
return escapeHtml(tag);
|
|
66
77
|
}
|
|
67
78
|
const lower = String(name).toLowerCase();
|
|
@@ -70,26 +81,26 @@ export const sanitizeHtml = (channel, html, urls) => {
|
|
|
70
81
|
if (lower === "a" && dropped.pop())
|
|
71
82
|
return "";
|
|
72
83
|
if (!attributes)
|
|
73
|
-
|
|
84
|
+
removed.push(`</${lower}>`);
|
|
74
85
|
return attributes ? `</${lower}>` : "";
|
|
75
86
|
}
|
|
76
87
|
if (!attributes) {
|
|
77
|
-
|
|
88
|
+
removed.push(`<${lower}>`);
|
|
78
89
|
return "";
|
|
79
90
|
}
|
|
80
91
|
const kept = [];
|
|
81
92
|
const all = [...String(rest).matchAll(/([a-zA-Z-]+)\s*=\s*"([^"]*)"/g)];
|
|
82
93
|
if (all.length !== (String(rest).match(/=/g)?.length ?? 0))
|
|
83
|
-
|
|
94
|
+
removed.push(`an unquoted attribute on <${lower}>`);
|
|
84
95
|
for (const [, key = "", value = ""] of all) {
|
|
85
96
|
const attribute = key.toLowerCase();
|
|
86
97
|
const unescaped = value.replace(/&/g, "&");
|
|
87
98
|
if (!attributes.includes(attribute))
|
|
88
|
-
|
|
99
|
+
removed.push(`${attribute} on <${lower}>`);
|
|
89
100
|
else if (attribute === "href" && !urls.has(unescaped))
|
|
90
|
-
|
|
101
|
+
removed.push(`an href that is not a link of the report`);
|
|
91
102
|
else if (attribute === "style" && /url\(|expression\(|javascript:/i.test(value))
|
|
92
|
-
|
|
103
|
+
removed.push(`a style with url(), expression() or javascript:`);
|
|
93
104
|
else
|
|
94
105
|
kept.push(`${attribute}="${value}"`);
|
|
95
106
|
}
|
|
@@ -101,7 +112,7 @@ export const sanitizeHtml = (channel, html, urls) => {
|
|
|
101
112
|
}
|
|
102
113
|
return `<${lower}${kept.map((one) => ` ${one}`).join("")}>`;
|
|
103
114
|
});
|
|
104
|
-
return { html: out, changed };
|
|
115
|
+
return { html: out, changed: removed.length, removed };
|
|
105
116
|
};
|
|
106
117
|
const renderOnce = async (view, channel, source) => {
|
|
107
118
|
const engine = safeLiquid(LIMITS);
|
|
@@ -114,9 +125,9 @@ const renderOnce = async (view, channel, source) => {
|
|
|
114
125
|
if (!rendered)
|
|
115
126
|
throw new Error("empty");
|
|
116
127
|
if (channel === "text")
|
|
117
|
-
return { text: rendered, templateTags: 0 };
|
|
118
|
-
const { html, changed } = sanitizeHtml(channel, rendered, linkUrls(view));
|
|
119
|
-
return { text: html, templateTags: changed };
|
|
128
|
+
return { text: rendered, templateTags: 0, removed: [] };
|
|
129
|
+
const { html, changed, removed } = sanitizeHtml(channel, rendered, linkUrls(view));
|
|
130
|
+
return { text: html, templateTags: changed, removed };
|
|
120
131
|
};
|
|
121
132
|
const renderWithFallback = async (view, channel, template) => {
|
|
122
133
|
const shipped = () => renderOnce(view, channel, defaultTemplate(view.kind, channel, view.language));
|
|
@@ -129,8 +140,15 @@ const renderWithFallback = async (view, channel, template) => {
|
|
|
129
140
|
return { ...(await shipped()), templateFailed: true };
|
|
130
141
|
}
|
|
131
142
|
};
|
|
132
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The view with one item fewer: the digest's last item of its largest section, the last gap; counted in `more`.
|
|
145
|
+
* A notice has nothing to drop.
|
|
146
|
+
*/
|
|
133
147
|
const dropOne = (view) => {
|
|
148
|
+
if (view.kind === "schedule-failed")
|
|
149
|
+
return undefined;
|
|
150
|
+
if (view.kind === "weekly-gaps")
|
|
151
|
+
return view.items.length === 0 ? undefined : { ...view, items: view.items.slice(0, -1), more: view.more + 1 };
|
|
134
152
|
const lists = [...view.sections.map((section) => section.items.length), view.health.items.length];
|
|
135
153
|
const largest = lists.reduce((most, one) => Math.max(most, one), 0);
|
|
136
154
|
if (largest === 0)
|
|
@@ -163,6 +181,40 @@ export const renderReport = async (view, channel, { template } = {}) => {
|
|
|
163
181
|
current = smaller;
|
|
164
182
|
}
|
|
165
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Why `source` may not be saved for this view, empty when it may, and what it renders: it must render, the platform
|
|
186
|
+
* rules may take nothing out, and a Telegram text must fit once the size fit dropped what it could. Unlike
|
|
187
|
+
* `renderReport` it never falls back to the shipped template.
|
|
188
|
+
*/
|
|
189
|
+
export const checkTemplate = async (view, channel, source) => {
|
|
190
|
+
let current = view;
|
|
191
|
+
for (;;) {
|
|
192
|
+
let rendering;
|
|
193
|
+
try {
|
|
194
|
+
rendering = await renderOnce(current, channel, source);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
198
|
+
return { problems: [message === "empty" ? "it renders nothing" : `it does not render: ${message}`], text: "" };
|
|
199
|
+
}
|
|
200
|
+
if (rendering.removed.length > 0)
|
|
201
|
+
return {
|
|
202
|
+
problems: [...new Set(rendering.removed)].map((what) => `the ${channel} rules would remove ${what}`),
|
|
203
|
+
text: rendering.text,
|
|
204
|
+
};
|
|
205
|
+
if (channel !== "telegram" || rendering.text.length <= TELEGRAM_TEXT_CHARS)
|
|
206
|
+
return { problems: [], text: rendering.text };
|
|
207
|
+
const smaller = dropOne(current);
|
|
208
|
+
if (!smaller)
|
|
209
|
+
return {
|
|
210
|
+
problems: [
|
|
211
|
+
`it is ${rendering.text.length} characters with every item left out; Telegram takes ${TELEGRAM_TEXT_CHARS}`,
|
|
212
|
+
],
|
|
213
|
+
text: rendering.text,
|
|
214
|
+
};
|
|
215
|
+
current = smaller;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
166
218
|
const INVALID_LINES = {
|
|
167
219
|
ru: "Сводка не собралась: ошибка формата. Подробности в WireCat.",
|
|
168
220
|
en: "The report could not be built: format error. Details in WireCat.",
|
|
@@ -171,7 +223,7 @@ const INVALID_LINES = {
|
|
|
171
223
|
* A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
|
|
172
224
|
* line in the owner's language and is never shown raw.
|
|
173
225
|
*/
|
|
174
|
-
export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
226
|
+
export const prepareReport = async (answer, { language, now, timeZone, templates: storedTemplates, links = DEFAULT_LINK_CONFIG, env = process.env, }) => {
|
|
175
227
|
const parsed = parseReport(answer);
|
|
176
228
|
if (!parsed)
|
|
177
229
|
return undefined;
|
|
@@ -194,13 +246,20 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
194
246
|
...(timeZone ? { timeZone } : {}),
|
|
195
247
|
linkOf: (ref) => linkFor(ref, { form, config: links, env }),
|
|
196
248
|
});
|
|
249
|
+
let lookupFailed = false;
|
|
250
|
+
const templates = storedTemplates
|
|
251
|
+
? await storedTemplates(parsed.report.kind, shipped).catch(() => {
|
|
252
|
+
lookupFailed = true;
|
|
253
|
+
return {};
|
|
254
|
+
})
|
|
255
|
+
: {};
|
|
197
256
|
const web = viewFor("web");
|
|
198
257
|
const telegram = await renderReport(web, "telegram", templateOf(templates, "telegram"));
|
|
199
258
|
const text = await renderReport(web, "text", templateOf(templates, "text"));
|
|
200
259
|
const terminal = await renderReport(viewFor("app"), "text", templateOf(templates, "text"));
|
|
201
260
|
const renderings = [telegram, text, terminal];
|
|
202
261
|
const reasons = [
|
|
203
|
-
...(renderings.some((one) => one.templateFailed) ? [REPORT_REASONS.templateFailed] : []),
|
|
262
|
+
...(lookupFailed || renderings.some((one) => one.templateFailed) ? [REPORT_REASONS.templateFailed] : []),
|
|
204
263
|
...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
|
|
205
264
|
];
|
|
206
265
|
const title = text.text.split("\n")[0] ?? "";
|
|
@@ -219,3 +278,34 @@ const templateOf = (templates, channel) => {
|
|
|
219
278
|
const template = templates[channel];
|
|
220
279
|
return template === undefined ? {} : { template };
|
|
221
280
|
};
|
|
281
|
+
/**
|
|
282
|
+
* Renders `kind` in the owner's language, or in English when cli-core ships no template in it, over the owner's
|
|
283
|
+
* stored templates; a lookup or a template that fails falls back to the shipped one, as a report's does.
|
|
284
|
+
*/
|
|
285
|
+
export const prepareMessage = async (kind, viewOf, { language, templates: storedTemplates }) => {
|
|
286
|
+
const shipped = existsSync(templateFile(kind, "telegram", language)) ? language : DEFAULT_LANGUAGE;
|
|
287
|
+
let lookupFailed = false;
|
|
288
|
+
const templates = storedTemplates
|
|
289
|
+
? await storedTemplates(kind, shipped).catch(() => {
|
|
290
|
+
lookupFailed = true;
|
|
291
|
+
return {};
|
|
292
|
+
})
|
|
293
|
+
: {};
|
|
294
|
+
const view = viewOf(shipped);
|
|
295
|
+
const telegram = await renderReport(view, "telegram", templateOf(templates, "telegram"));
|
|
296
|
+
const email = await renderReport(view, "email", templateOf(templates, "email"));
|
|
297
|
+
const text = await renderReport(view, "text", templateOf(templates, "text"));
|
|
298
|
+
const renderings = [telegram, email, text];
|
|
299
|
+
return {
|
|
300
|
+
telegram: telegram.text,
|
|
301
|
+
email: email.text,
|
|
302
|
+
text: text.text,
|
|
303
|
+
subject: text.text.split("\n")[0] ?? "",
|
|
304
|
+
invalid: false,
|
|
305
|
+
language: shipped,
|
|
306
|
+
reasons: [
|
|
307
|
+
...(lookupFailed || renderings.some((one) => one.templateFailed) ? [REPORT_REASONS.templateFailed] : []),
|
|
308
|
+
...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
};
|
|
@@ -61,13 +61,17 @@ export interface ReportScope {
|
|
|
61
61
|
meetings: number;
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* The open task groups, each opened by a `tasks/<filter>` link; `new` counts what was created since `newSince`,
|
|
66
|
+
* `undated` the open tasks with no due date (0 when the report leaves it out).
|
|
67
|
+
*/
|
|
65
68
|
export interface TaskCounts {
|
|
66
69
|
overdue: number;
|
|
67
70
|
today: number;
|
|
68
71
|
tomorrow: number;
|
|
69
72
|
new: number;
|
|
70
73
|
newSince: string | null;
|
|
74
|
+
undated: number;
|
|
71
75
|
}
|
|
72
76
|
/** A `wirecat.report/1` document as the renderers read it: checked, cut to its limits, with no `links` or `internal`. */
|
|
73
77
|
export interface Report {
|
|
@@ -89,6 +93,8 @@ export declare const withoutLeaks: (text: string) => {
|
|
|
89
93
|
* with refs (Desktop builds its own links from them) and without `links` or `internal`.
|
|
90
94
|
*/
|
|
91
95
|
export declare const reportDocument: (report: Report) => Record<string, unknown>;
|
|
96
|
+
/** The JSON text of a run's answer: the bare object, or the only fenced `json` block; undefined for anything else. */
|
|
97
|
+
export declare const jsonOfAnswer: (answer: string) => string | undefined;
|
|
92
98
|
export type ParsedReport = {
|
|
93
99
|
report: Report;
|
|
94
100
|
leaks: number;
|
|
@@ -132,6 +132,7 @@ const tasksOf = (value) => {
|
|
|
132
132
|
tomorrow: wholeOr0(value.tomorrow, "tasks.tomorrow"),
|
|
133
133
|
new: wholeOr0(value.new, "tasks.new"),
|
|
134
134
|
newSince: momentOf(value.new_since, "tasks.new_since"),
|
|
135
|
+
undated: wholeOr0(value.undated, "tasks.undated"),
|
|
135
136
|
};
|
|
136
137
|
};
|
|
137
138
|
const cut = (text, limit) => (text.length <= limit ? text : `${text.slice(0, limit - 1).trimEnd()}…`);
|
|
@@ -254,17 +255,22 @@ export const reportDocument = (report) => ({
|
|
|
254
255
|
tomorrow: report.tasks.tomorrow,
|
|
255
256
|
new: report.tasks.new,
|
|
256
257
|
new_since: report.tasks.newSince,
|
|
258
|
+
undated: report.tasks.undated,
|
|
257
259
|
},
|
|
258
260
|
});
|
|
261
|
+
/** The JSON text of a run's answer: the bare object, or the only fenced `json` block; undefined for anything else. */
|
|
262
|
+
export const jsonOfAnswer = (answer) => {
|
|
263
|
+
const text = answer.trim();
|
|
264
|
+
const fenced = /^```json[ \t]*\n([\s\S]*?)\n```$/.exec(text)?.[1];
|
|
265
|
+
return fenced ?? (text.startsWith("{") ? text : undefined);
|
|
266
|
+
};
|
|
259
267
|
/**
|
|
260
268
|
* 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
|
|
261
269
|
* report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
|
|
262
270
|
* of the first field that failed, and is never shown.
|
|
263
271
|
*/
|
|
264
272
|
export const parseReport = (answer) => {
|
|
265
|
-
const
|
|
266
|
-
const fenced = /^```json[ \t]*\n([\s\S]*?)\n```$/.exec(text)?.[1];
|
|
267
|
-
const json = fenced ?? (text.startsWith("{") ? text : undefined);
|
|
273
|
+
const json = jsonOfAnswer(answer);
|
|
268
274
|
if (json === undefined)
|
|
269
275
|
return undefined;
|
|
270
276
|
let document;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type MessageKind } from "./messages.js";
|
|
2
|
+
import { type MessageView, type ReportChannel } from "./render.js";
|
|
3
|
+
/** What an owner's template renders: each key is one message kind. */
|
|
4
|
+
export declare const TEMPLATE_KEYS: readonly [{
|
|
5
|
+
readonly key: "report/morning-digest";
|
|
6
|
+
readonly kind: "morning-digest";
|
|
7
|
+
readonly about: "the morning digest";
|
|
8
|
+
}, {
|
|
9
|
+
readonly key: "report/weekly-gaps";
|
|
10
|
+
readonly kind: "weekly-gaps";
|
|
11
|
+
readonly about: "the weekly list of what the digest found on its own";
|
|
12
|
+
}, {
|
|
13
|
+
readonly key: "notice/schedule-failed";
|
|
14
|
+
readonly kind: "schedule-failed";
|
|
15
|
+
readonly about: "the message sent when a scheduled run fails";
|
|
16
|
+
}];
|
|
17
|
+
export type TemplateKey = (typeof TEMPLATE_KEYS)[number]["key"];
|
|
18
|
+
export declare const templateKeyOf: (key: string) => {
|
|
19
|
+
readonly key: "report/morning-digest";
|
|
20
|
+
readonly kind: "morning-digest";
|
|
21
|
+
readonly about: "the morning digest";
|
|
22
|
+
} | {
|
|
23
|
+
readonly key: "report/weekly-gaps";
|
|
24
|
+
readonly kind: "weekly-gaps";
|
|
25
|
+
readonly about: "the weekly list of what the digest found on its own";
|
|
26
|
+
} | {
|
|
27
|
+
readonly key: "notice/schedule-failed";
|
|
28
|
+
readonly kind: "schedule-failed";
|
|
29
|
+
readonly about: "the message sent when a scheduled run fails";
|
|
30
|
+
} | undefined;
|
|
31
|
+
export declare const keyOfKind: (kind: MessageKind) => TemplateKey;
|
|
32
|
+
/** The languages cli-core ships a template in for `kind`: a stored template in another one would never be used. */
|
|
33
|
+
export declare const shippedLanguages: (kind: MessageKind) => string[];
|
|
34
|
+
/**
|
|
35
|
+
* The synthetic document shipped beside the templates (`<kind>.sample.json`): for the digest every section, item
|
|
36
|
+
* type and health reason once; for the others a week of gaps and one failed schedule.
|
|
37
|
+
*/
|
|
38
|
+
export declare const sampleView: (kind: MessageKind, language: string, now: number) => MessageView;
|
|
39
|
+
/** The newest `<run>.report.json` of `kind` the tool's schedules wrote, or undefined; only the digest keeps one. */
|
|
40
|
+
export declare const lastReport: (state: string, kind: MessageKind) => {
|
|
41
|
+
path: string;
|
|
42
|
+
document: string;
|
|
43
|
+
} | undefined;
|
|
44
|
+
export interface TemplateCheck {
|
|
45
|
+
/** `sample`, or the path of the last real report. */
|
|
46
|
+
against: string;
|
|
47
|
+
problems: string[];
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether `body` may be saved for one channel: it is rendered against the synthetic sample and against the last real
|
|
52
|
+
* report, when the tool has one, with the platform rules that run at send time. Any problem refuses the save.
|
|
53
|
+
*/
|
|
54
|
+
export declare const checkTemplateSave: ({ kind, channel, language, body, state, now, }: {
|
|
55
|
+
kind: MessageKind;
|
|
56
|
+
channel: ReportChannel;
|
|
57
|
+
language: string;
|
|
58
|
+
body: string;
|
|
59
|
+
state: string;
|
|
60
|
+
now: number;
|
|
61
|
+
}) => Promise<TemplateCheck[]>;
|
|
62
|
+
/** The view a preview renders: the last real report when there is one, else the sample. */
|
|
63
|
+
export declare const previewView: (state: string, kind: MessageKind, language: string, now: number) => {
|
|
64
|
+
against: string;
|
|
65
|
+
view: MessageView;
|
|
66
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { linkFor } from "../../domain/links.js";
|
|
5
|
+
import { schedulesDir } from "../schedules.js";
|
|
6
|
+
import { gapsView, noticeView, parseScheduleFailure, parseWeeklyGaps } from "./messages.js";
|
|
7
|
+
import { checkTemplate, REPORT_CHANNELS } from "./render.js";
|
|
8
|
+
import { parseReport } from "./schema.js";
|
|
9
|
+
import { reportView } from "./view.js";
|
|
10
|
+
/** What an owner's template renders: each key is one message kind. */
|
|
11
|
+
export const TEMPLATE_KEYS = [
|
|
12
|
+
{ key: "report/morning-digest", kind: "morning-digest", about: "the morning digest" },
|
|
13
|
+
{ key: "report/weekly-gaps", kind: "weekly-gaps", about: "the weekly list of what the digest found on its own" },
|
|
14
|
+
{ key: "notice/schedule-failed", kind: "schedule-failed", about: "the message sent when a scheduled run fails" },
|
|
15
|
+
];
|
|
16
|
+
export const templateKeyOf = (key) => TEMPLATE_KEYS.find((one) => one.key === key);
|
|
17
|
+
export const keyOfKind = (kind) => TEMPLATE_KEYS.find((one) => one.kind === kind).key;
|
|
18
|
+
const TEMPLATES = fileURLToPath(new URL("./templates/", import.meta.url));
|
|
19
|
+
/** The languages cli-core ships a template in for `kind`: a stored template in another one would never be used. */
|
|
20
|
+
export const shippedLanguages = (kind) => [
|
|
21
|
+
...new Set(readdirSync(TEMPLATES)
|
|
22
|
+
.map((file) => file.match(new RegExp(`^${kind}\\.(?:${REPORT_CHANNELS.join("|")})\\.([a-z]{2})\\.liquid$`))?.[1])
|
|
23
|
+
.filter((one) => one !== undefined)),
|
|
24
|
+
].sort();
|
|
25
|
+
const webLink = (ref) => linkFor(ref, { form: "web", env: {} });
|
|
26
|
+
const viewOf = (document, language, now) => {
|
|
27
|
+
const parsed = parseReport(document);
|
|
28
|
+
if (!parsed || "invalid" in parsed)
|
|
29
|
+
return undefined;
|
|
30
|
+
return reportView(parsed.report, { language, now, linkOf: webLink });
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The synthetic document shipped beside the templates (`<kind>.sample.json`): for the digest every section, item
|
|
34
|
+
* type and health reason once; for the others a week of gaps and one failed schedule.
|
|
35
|
+
*/
|
|
36
|
+
export const sampleView = (kind, language, now) => {
|
|
37
|
+
const json = readFileSync(join(TEMPLATES, `${kind}.sample.json`), "utf8");
|
|
38
|
+
if (kind === "weekly-gaps")
|
|
39
|
+
return gapsView(parseWeeklyGaps(json), { language, now, linkOf: webLink });
|
|
40
|
+
if (kind === "schedule-failed")
|
|
41
|
+
return noticeView(parseScheduleFailure(json), { language, now, linkOf: webLink });
|
|
42
|
+
const view = viewOf(json, language, now);
|
|
43
|
+
if (!view)
|
|
44
|
+
throw new Error(`the shipped ${kind} sample is not a report`);
|
|
45
|
+
return view;
|
|
46
|
+
};
|
|
47
|
+
/** The newest `<run>.report.json` of `kind` the tool's schedules wrote, or undefined; only the digest keeps one. */
|
|
48
|
+
export const lastReport = (state, kind) => {
|
|
49
|
+
const folder = schedulesDir(state);
|
|
50
|
+
if (kind !== "morning-digest" || !existsSync(folder))
|
|
51
|
+
return undefined;
|
|
52
|
+
const files = readdirSync(folder).flatMap((name) => {
|
|
53
|
+
const runs = join(folder, name, "runs");
|
|
54
|
+
return existsSync(runs)
|
|
55
|
+
? readdirSync(runs)
|
|
56
|
+
.filter((file) => file.endsWith(".report.json"))
|
|
57
|
+
.map((file) => join(runs, file))
|
|
58
|
+
: [];
|
|
59
|
+
});
|
|
60
|
+
for (const path of files.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs)) {
|
|
61
|
+
const document = readFileSync(path, "utf8");
|
|
62
|
+
const parsed = parseReport(document);
|
|
63
|
+
if (parsed && !("invalid" in parsed) && parsed.report.kind === kind)
|
|
64
|
+
return { path, document };
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Whether `body` may be saved for one channel: it is rendered against the synthetic sample and against the last real
|
|
70
|
+
* report, when the tool has one, with the platform rules that run at send time. Any problem refuses the save.
|
|
71
|
+
*/
|
|
72
|
+
export const checkTemplateSave = async ({ kind, channel, language, body, state, now, }) => {
|
|
73
|
+
const last = lastReport(state, kind);
|
|
74
|
+
const views = [
|
|
75
|
+
["sample", sampleView(kind, language, now)],
|
|
76
|
+
...(last ? [[last.path, viewOf(last.document, language, now)]] : []),
|
|
77
|
+
];
|
|
78
|
+
return Promise.all(views.flatMap(([against, view]) => view ? [checkTemplate(view, channel, body).then((check) => ({ against, ...check }))] : []));
|
|
79
|
+
};
|
|
80
|
+
/** The view a preview renders: the last real report when there is one, else the sample. */
|
|
81
|
+
export const previewView = (state, kind, language, now) => {
|
|
82
|
+
const last = lastReport(state, kind);
|
|
83
|
+
const view = last && viewOf(last.document, language, now);
|
|
84
|
+
return view ? { against: last.path, view } : { against: "sample", view: sampleView(kind, language, now) };
|
|
85
|
+
};
|
|
@@ -84,6 +84,9 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
|
|
|
84
84
|
{%- if group.link %}<a href="{{ group.link.url }}" style="color:#3b82c4">{{ words }}</a>{% else %}{{ words }}{% endif -%}
|
|
85
85
|
{%- endfor -%}
|
|
86
86
|
</p>{%- endif -%}
|
|
87
|
+
{%- if section.undated %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">no due date: {{ section.undated.count }}
|
|
88
|
+
{%- if section.undated.link %} · <a href="{{ section.undated.link.url }}" style="color:#3b82c4">open</a>{% endif -%}
|
|
89
|
+
</p>{%- endif -%}
|
|
87
90
|
{%- endfor -%}
|
|
88
91
|
{%- for source in health.items -%}
|
|
89
92
|
{{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }}
|
|
@@ -84,6 +84,9 @@ of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (
|
|
|
84
84
|
{%- if group.link %}<a href="{{ group.link.url }}" style="color:#3b82c4">{{ words }}</a>{% else %}{{ words }}{% endif -%}
|
|
85
85
|
{%- endfor -%}
|
|
86
86
|
</p>{%- endif -%}
|
|
87
|
+
{%- if section.undated %}{{ nl }}<p style="margin:0 0 12px;{{ muted }}">без срока: {{ section.undated.count }}
|
|
88
|
+
{%- if section.undated.link %} · <a href="{{ section.undated.link.url }}" style="color:#3b82c4">открыть</a>{% endif -%}
|
|
89
|
+
</p>{%- endif -%}
|
|
87
90
|
{%- endfor -%}
|
|
88
91
|
{%- for source in health.items -%}
|
|
89
92
|
{{ nl }}<p style="margin:20px 0 0;{{ muted }}">{{ health.emoji }} {{ source.source }}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "wirecat.report/1",
|
|
3
|
+
"kind": "morning-digest",
|
|
4
|
+
"date": "2026-11-06",
|
|
5
|
+
"summary": "Two replies are waiting, one payment is overdue.",
|
|
6
|
+
"sections": [
|
|
7
|
+
{
|
|
8
|
+
"kind": "today",
|
|
9
|
+
"items": [
|
|
10
|
+
{
|
|
11
|
+
"type": "reply",
|
|
12
|
+
"who": "Alice Example",
|
|
13
|
+
"topic": "warehouse lease",
|
|
14
|
+
"action": "Say whether signing on Friday works",
|
|
15
|
+
"quote": "Can we sign on Friday?",
|
|
16
|
+
"since": "2026-11-04T14:20:00+03:00",
|
|
17
|
+
"channel": "mail",
|
|
18
|
+
"refs": ["msg:email/alice%40example.com/5005/6006"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "question",
|
|
22
|
+
"who": "Bob Sample",
|
|
23
|
+
"topic": "tile delivery",
|
|
24
|
+
"action": "can the delivery move to the 20th?",
|
|
25
|
+
"since": "2026-11-05T19:00:00+03:00",
|
|
26
|
+
"channel": "telegram",
|
|
27
|
+
"refs": ["chat:telegram/1001/4004"]
|
|
28
|
+
},
|
|
29
|
+
{ "type": "task", "topic": "Reconciliation for Demo Ltd", "due": "2026-11-04", "refs": ["task:80"] },
|
|
30
|
+
{ "type": "task", "topic": "Office repair estimate", "due": "2026-11-06T18:00:00+03:00", "who": "Carol Test" },
|
|
31
|
+
{
|
|
32
|
+
"type": "task",
|
|
33
|
+
"topic": "Contractor agreement",
|
|
34
|
+
"who": "Dan Fixture",
|
|
35
|
+
"priority": "high",
|
|
36
|
+
"refs": ["task:81"]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"more": 1
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"kind": "decisions",
|
|
43
|
+
"items": [
|
|
44
|
+
{
|
|
45
|
+
"type": "decision",
|
|
46
|
+
"topic": "Findings from mail",
|
|
47
|
+
"action": "waiting for review",
|
|
48
|
+
"count": 12,
|
|
49
|
+
"refs": ["proposal:fact%3A512"]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"kind": "money",
|
|
55
|
+
"items": [
|
|
56
|
+
{
|
|
57
|
+
"type": "money",
|
|
58
|
+
"who": "Demo Ltd",
|
|
59
|
+
"topic": "November rent",
|
|
60
|
+
"action": "pay",
|
|
61
|
+
"amount": { "value": 48000, "currency": "RUB", "direction": "out" },
|
|
62
|
+
"due": "2026-11-03",
|
|
63
|
+
"channel": "mail",
|
|
64
|
+
"refs": ["msg:email/7"]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"type": "money",
|
|
68
|
+
"who": "Sample LLC",
|
|
69
|
+
"topic": "prepayment, contract 14",
|
|
70
|
+
"amount": { "value": 1200, "currency": "EUR", "direction": "in" }
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"kind": "meetings",
|
|
76
|
+
"items": [
|
|
77
|
+
{
|
|
78
|
+
"type": "meeting",
|
|
79
|
+
"topic": "Warehouse stand-up",
|
|
80
|
+
"time": "2026-11-06T11:00:00+03:00",
|
|
81
|
+
"who": "Alice Example, Dan Fixture",
|
|
82
|
+
"action": "bring the lease figures",
|
|
83
|
+
"channel": "meeting"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"kind": "projects",
|
|
89
|
+
"items": [
|
|
90
|
+
{
|
|
91
|
+
"type": "fact",
|
|
92
|
+
"topic": "Warehouse",
|
|
93
|
+
"detail": "the landlord agreed to 5% off from January",
|
|
94
|
+
"who": "Alice Example"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "risk",
|
|
98
|
+
"topic": "Cable delivery",
|
|
99
|
+
"detail": "the supplier has not answered for 4 days",
|
|
100
|
+
"action": "call Dan Fixture before noon",
|
|
101
|
+
"priority": "high"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"more": 2
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"kind": "mail",
|
|
108
|
+
"items": [
|
|
109
|
+
{
|
|
110
|
+
"type": "reply",
|
|
111
|
+
"who": "Erin Placeholder",
|
|
112
|
+
"topic": "invoice copy",
|
|
113
|
+
"action": "send the signed copy",
|
|
114
|
+
"since": "2026-11-05T09:00:00+03:00",
|
|
115
|
+
"channel": "mail",
|
|
116
|
+
"refs": ["msg:email/9"]
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
"health": [
|
|
122
|
+
{
|
|
123
|
+
"source": "Telegram",
|
|
124
|
+
"account": "@demo",
|
|
125
|
+
"reason": "sync-failed",
|
|
126
|
+
"since": "2026-11-04T23:10:00+03:00",
|
|
127
|
+
"stale_hours": 33,
|
|
128
|
+
"refs": ["sync:telegram/1001"]
|
|
129
|
+
},
|
|
130
|
+
{ "source": "MAX", "account": "test account", "reason": "no-schedule", "stale_hours": 0 },
|
|
131
|
+
{
|
|
132
|
+
"source": "Mail",
|
|
133
|
+
"account": "owner@example.com",
|
|
134
|
+
"reason": "quiet",
|
|
135
|
+
"stale_hours": 50,
|
|
136
|
+
"refs": ["account:max/1"]
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"scope": {
|
|
140
|
+
"from": "2026-11-05T08:30:00+03:00",
|
|
141
|
+
"to": "2026-11-06T08:30:00+03:00",
|
|
142
|
+
"sources": [
|
|
143
|
+
{ "kind": "telegram", "accounts": 1 },
|
|
144
|
+
{ "kind": "max", "accounts": 1 },
|
|
145
|
+
{ "kind": "mail", "accounts": 2 }
|
|
146
|
+
],
|
|
147
|
+
"counts": { "chats": 31, "mail": 12, "tasks": 17, "meetings": 1 }
|
|
148
|
+
},
|
|
149
|
+
"tasks": {
|
|
150
|
+
"overdue": 5,
|
|
151
|
+
"today": 3,
|
|
152
|
+
"tomorrow": 2,
|
|
153
|
+
"new": 4,
|
|
154
|
+
"new_since": "2026-11-05T08:30:00+03:00",
|
|
155
|
+
"undated": 91
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -82,6 +82,9 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
82
82
|
{%- if group.link %}<a href="{{ group.link.url }}">{{ words }}</a>{% else %}{{ words }}{% endif -%}
|
|
83
83
|
{%- endfor -%}
|
|
84
84
|
{%- endif -%}
|
|
85
|
+
{%- if section.undated %}{{ nl }}no due date: {{ section.undated.count }}
|
|
86
|
+
{%- if section.undated.link %} · <a href="{{ section.undated.link.url }}">open</a>{% endif -%}
|
|
87
|
+
{%- endif -%}
|
|
85
88
|
{%- endfor -%}
|
|
86
89
|
{%- if health.items.size > 0 %}{{ nl }}{% endif -%}
|
|
87
90
|
{%- for source in health.items -%}
|
|
@@ -82,6 +82,9 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
82
82
|
{%- if group.link %}<a href="{{ group.link.url }}">{{ words }}</a>{% else %}{{ words }}{% endif -%}
|
|
83
83
|
{%- endfor -%}
|
|
84
84
|
{%- endif -%}
|
|
85
|
+
{%- if section.undated %}{{ nl }}без срока: {{ section.undated.count }}
|
|
86
|
+
{%- if section.undated.link %} · <a href="{{ section.undated.link.url }}">открыть</a>{% endif -%}
|
|
87
|
+
{%- endif -%}
|
|
85
88
|
{%- endfor -%}
|
|
86
89
|
{%- if health.items.size > 0 %}{{ nl }}{% endif -%}
|
|
87
90
|
{%- for source in health.items -%}
|
|
@@ -81,6 +81,9 @@ Plain text: the terminal, latest.txt, the desktop notice, the email's plain part
|
|
|
81
81
|
{%- if group.link %}{{ words }} {{ group.link.url }}{% else %}{{ words }}{% endif -%}
|
|
82
82
|
{%- endfor -%}
|
|
83
83
|
{%- endif -%}
|
|
84
|
+
{%- if section.undated %}{{ nl }}no due date: {{ section.undated.count }}
|
|
85
|
+
{%- if section.undated.link %} · open {{ section.undated.link.url }}{% endif -%}
|
|
86
|
+
{%- endif -%}
|
|
84
87
|
{%- endfor -%}
|
|
85
88
|
{%- if health.items.size > 0 %}{{ nl }}{% endif -%}
|
|
86
89
|
{%- for source in health.items -%}
|