@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
|
@@ -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 }}без срока: {{ section.undated.count }}
|
|
85
|
+
{%- if section.undated.link %} · открыть {{ 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 -%}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Email HTML with inline CSS: only div, p, b, i, a, br and span survive, with a style attribute and an href to a link
|
|
3
|
+
of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (#3b82c4) read on white and on dark.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
<div style="max-width:600px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif;font-size:15px">
|
|
8
|
+
{{- nl }}<p style="margin:0 0 8px;font-size:19px"><b>⚠️ {% if schedule == "morning-digest" %}The morning digest could not be built{% else %}The schedule “{{ tool }} {{ schedule }}” is failing{% endif %}</b></p>
|
|
9
|
+
{{- nl }}<p style="margin:0 0 4px">{% if failures > 1 %}Failing since {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} runs in a row{% else %}Failed {% if at.day == "today" %}today{% elsif at.day == "yesterday" %}yesterday{% else %}on {{ at.date }}{% endif %}{% if at.time %} at {{ at.time }}{% endif %}{% endif %}</p>
|
|
10
|
+
{{- nl }}<p style="margin:0 0 12px">Why: {% case cause %}{% when "locked" %}the keyring was locked; unlock the computer{% when "sign-in" %}the account needs a new sign-in{% when "network" %}the service could not be reached{% when "provider" %}the service answered with an error{% when "setup" %}something is wrong in the settings{% when "stopped" %}the run was stopped{% else %}the program ended with an error{% endcase %}</p>
|
|
11
|
+
{%- for link in links %}{{ nl }}<p style="margin:0"><a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a></p>{% endfor -%}
|
|
12
|
+
{{ nl }}</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Email HTML with inline CSS: only div, p, b, i, a, br and span survive, with a style attribute and an href to a link
|
|
3
|
+
of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (#3b82c4) read on white and on dark.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
<div style="max-width:600px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif;font-size:15px">
|
|
8
|
+
{{- nl }}<p style="margin:0 0 8px;font-size:19px"><b>⚠️ {% if schedule == "morning-digest" %}Утренняя сводка не собралась{% else %}Расписание «{{ tool }} {{ schedule }}» не работает{% endif %}</b></p>
|
|
9
|
+
{{- nl }}<p style="margin:0 0 4px">{% if failures > 1 %}Не работает с {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} {% case plural %}{% when "one" %}запуск{% when "few" %}запуска{% else %}запусков{% endcase %} подряд{% else %}Сбой {% if at.day == "today" %}сегодня{% elsif at.day == "yesterday" %}вчера{% else %}{{ at.date }}{% endif %}{% if at.time %} в {{ at.time }}{% endif %}{% endif %}</p>
|
|
10
|
+
{{- nl }}<p style="margin:0 0 12px">Причина: {% case cause %}{% when "locked" %}хранилище паролей было заблокировано, разблокируйте компьютер{% when "sign-in" %}нужно заново войти в аккаунт{% when "network" %}нет связи с сервисом{% when "provider" %}сервис ответил ошибкой{% when "setup" %}ошибка в настройках{% when "stopped" %}запуск остановили{% else %}программа завершилась с ошибкой{% endcase %}</p>
|
|
11
|
+
{%- for link in links %}{{ nl }}<p style="margin:0"><a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a></p>{% endfor -%}
|
|
12
|
+
{{ nl }}</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Telegram HTML: only <b>, <i> and <a href> survive, and an href only to a link of the view model.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
⚠️ <b>{% if schedule == "morning-digest" %}The morning digest could not be built{% else %}The schedule “{{ tool }} {{ schedule }}” is failing{% endif %}</b>
|
|
7
|
+
{{- nl }}{% if failures > 1 %}Failing since {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} runs in a row{% else %}Failed {% if at.day == "today" %}today{% elsif at.day == "yesterday" %}yesterday{% else %}on {{ at.date }}{% endif %}{% if at.time %} at {{ at.time }}{% endif %}{% endif %}
|
|
8
|
+
{{- nl }}Why: {% case cause %}{% when "locked" %}the keyring was locked; unlock the computer{% when "sign-in" %}the account needs a new sign-in{% when "network" %}the service could not be reached{% when "provider" %}the service answered with an error{% when "setup" %}something is wrong in the settings{% when "stopped" %}the run was stopped{% else %}the program ended with an error{% endcase %}
|
|
9
|
+
{%- for link in links %}{{ nl }}<a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Telegram HTML: only <b>, <i> and <a href> survive, and an href only to a link of the view model.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
⚠️ <b>{% if schedule == "morning-digest" %}Утренняя сводка не собралась{% else %}Расписание «{{ tool }} {{ schedule }}» не работает{% endif %}</b>
|
|
7
|
+
{{- nl }}{% if failures > 1 %}Не работает с {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} {% case plural %}{% when "one" %}запуск{% when "few" %}запуска{% else %}запусков{% endcase %} подряд{% else %}Сбой {% if at.day == "today" %}сегодня{% elsif at.day == "yesterday" %}вчера{% else %}{{ at.date }}{% endif %}{% if at.time %} в {{ at.time }}{% endif %}{% endif %}
|
|
8
|
+
{{- nl }}Причина: {% case cause %}{% when "locked" %}хранилище паролей было заблокировано, разблокируйте компьютер{% when "sign-in" %}нужно заново войти в аккаунт{% when "network" %}нет связи с сервисом{% when "provider" %}сервис ответил ошибкой{% when "setup" %}ошибка в настройках{% when "stopped" %}запуск остановили{% else %}программа завершилась с ошибкой{% endcase %}
|
|
9
|
+
{%- for link in links %}{{ nl }}<a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Plain text: the email's plain part and the terminal.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
⚠️ {% if schedule == "morning-digest" %}The morning digest could not be built{% else %}The schedule “{{ tool }} {{ schedule }}” is failing{% endif %}
|
|
7
|
+
{{- nl }}{% if failures > 1 %}Failing since {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} runs in a row{% else %}Failed {% if at.day == "today" %}today{% elsif at.day == "yesterday" %}yesterday{% else %}on {{ at.date }}{% endif %}{% if at.time %} at {{ at.time }}{% endif %}{% endif %}
|
|
8
|
+
{{- nl }}Why: {% case cause %}{% when "locked" %}the keyring was locked; unlock the computer{% when "sign-in" %}the account needs a new sign-in{% when "network" %}the service could not be reached{% when "provider" %}the service answered with an error{% when "setup" %}something is wrong in the settings{% when "stopped" %}the run was stopped{% else %}the program ended with an error{% endcase %}
|
|
9
|
+
{%- for link in links %}{{ nl }}{{ link.label }}: {{ link.url }}{% endfor -%}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Plain text: the email's plain part and the terminal.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
⚠️ {% if schedule == "morning-digest" %}Утренняя сводка не собралась{% else %}Расписание «{{ tool }} {{ schedule }}» не работает{% endif %}
|
|
7
|
+
{{- nl }}{% if failures > 1 %}Не работает с {{ since.date }}{% if since.time %}, {{ since.time }}{% endif %} · {{ failures }} {% case plural %}{% when "one" %}запуск{% when "few" %}запуска{% else %}запусков{% endcase %} подряд{% else %}Сбой {% if at.day == "today" %}сегодня{% elsif at.day == "yesterday" %}вчера{% else %}{{ at.date }}{% endif %}{% if at.time %} в {{ at.time }}{% endif %}{% endif %}
|
|
8
|
+
{{- nl }}Причина: {% case cause %}{% when "locked" %}хранилище паролей было заблокировано, разблокируйте компьютер{% when "sign-in" %}нужно заново войти в аккаунт{% when "network" %}нет связи с сервисом{% when "provider" %}сервис ответил ошибкой{% when "setup" %}ошибка в настройках{% when "stopped" %}запуск остановили{% else %}программа завершилась с ошибкой{% endcase %}
|
|
9
|
+
{%- for link in links %}{{ nl }}{{ link.label }}: {{ link.url }}{% endfor -%}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Email HTML with inline CSS: only div, p, b, i, a, br and span survive, with a style attribute and an href to a link
|
|
3
|
+
of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (#3b82c4) read on white and on dark.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
{%- assign muted = "color:#8a8a8a;font-size:13px" -%}
|
|
8
|
+
<div style="max-width:600px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif;font-size:15px">
|
|
9
|
+
{{- nl }}<p style="margin:0 0 4px;font-size:19px"><b>🔍 What the digest found on its own this week</b></p>
|
|
10
|
+
{{- nl }}<p style="margin:0 0 12px;{{ muted }}">Not in the day's selection · {{ runs }} {% if plural == "one" %}digest{% else %}digests{% endif %}, {{ from.date }} to {{ to.date }}</p>
|
|
11
|
+
{%- if items.size == 0 %}{{ nl }}<p style="margin:0 0 12px">Nothing was missed.</p>{% endif -%}
|
|
12
|
+
{%- for item in items -%}
|
|
13
|
+
{{ nl }}<p style="margin:0 0 10px">• {{ item.what }}<br><span style="{{ muted }}">
|
|
14
|
+
{%- if item.seen > 1 %}in {{ item.seen }} digests, last on {% endif %}{{ item.last.date }}
|
|
15
|
+
{%- for link in item.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor -%}
|
|
16
|
+
</span></p>
|
|
17
|
+
{%- endfor -%}
|
|
18
|
+
{%- if more > 0 %}{{ nl }}<p style="margin:0;{{ muted }}">{{ more }} more</p>{% endif -%}
|
|
19
|
+
{{ nl }}</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Email HTML with inline CSS: only div, p, b, i, a, br and span survive, with a style attribute and an href to a link
|
|
3
|
+
of the view model. No colour on the body: the grey (#8a8a8a) and the link blue (#3b82c4) read on white and on dark.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
{%- assign muted = "color:#8a8a8a;font-size:13px" -%}
|
|
8
|
+
<div style="max-width:600px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif;font-size:15px">
|
|
9
|
+
{{- nl }}<p style="margin:0 0 4px;font-size:19px"><b>🔍 Что сводка нашла сама за неделю</b></p>
|
|
10
|
+
{{- nl }}<p style="margin:0 0 12px;{{ muted }}">Этого не было в подборке дня · {{ runs }} {% case plural %}{% when "one" %}сводка{% when "few" %}сводки{% else %}сводок{% endcase %} с {{ from.date }} по {{ to.date }}</p>
|
|
11
|
+
{%- if items.size == 0 %}{{ nl }}<p style="margin:0 0 12px">Пропусков не было.</p>{% endif -%}
|
|
12
|
+
{%- for item in items -%}
|
|
13
|
+
{{ nl }}<p style="margin:0 0 10px">• {{ item.what }}<br><span style="{{ muted }}">
|
|
14
|
+
{%- if item.seen > 1 %}в {{ item.seen }} {% if item.plural == "one" %}сводке{% else %}сводках{% endif %}, последний раз {% endif %}{{ item.last.date }}
|
|
15
|
+
{%- for link in item.links %} · <a href="{{ link.url }}" style="color:#3b82c4">{{ link.label }}</a>{% endfor -%}
|
|
16
|
+
</span></p>
|
|
17
|
+
{%- endfor -%}
|
|
18
|
+
{%- if more > 0 %}{{ nl }}<p style="margin:0;{{ muted }}">ещё {{ more }}</p>{% endif -%}
|
|
19
|
+
{{ nl }}</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "wirecat.report/1",
|
|
3
|
+
"kind": "weekly-gaps",
|
|
4
|
+
"from": "2026-10-30T08:30:00+03:00",
|
|
5
|
+
"to": "2026-11-06T08:30:00+03:00",
|
|
6
|
+
"runs": 6,
|
|
7
|
+
"gaps": [
|
|
8
|
+
{
|
|
9
|
+
"what": "Анна Котова ждёт ответа в WhatsApp, а в подборке дня его не было",
|
|
10
|
+
"section": "owed",
|
|
11
|
+
"refs": ["chat:whatsapp/1001/4004"],
|
|
12
|
+
"seen": 4,
|
|
13
|
+
"first": "2026-11-01T08:31:00+03:00",
|
|
14
|
+
"last": "2026-11-06T08:31:00+03:00"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"what": "Счёт ООО «Вектор» нашёлся только поиском по почте",
|
|
18
|
+
"section": "mail",
|
|
19
|
+
"refs": ["msg:email/7"],
|
|
20
|
+
"seen": 2,
|
|
21
|
+
"first": "2026-11-03T08:31:00+03:00",
|
|
22
|
+
"last": "2026-11-05T08:31:00+03:00"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"what": "Встреча с подрядчиком в среду есть в календаре, но не в списке встреч",
|
|
26
|
+
"section": null,
|
|
27
|
+
"refs": [],
|
|
28
|
+
"seen": 1,
|
|
29
|
+
"first": "2026-11-04T08:31:00+03:00",
|
|
30
|
+
"last": "2026-11-04T08:31:00+03:00"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Telegram HTML: only <b>, <i> and <a href> survive, and an href only to a link of the view model.
|
|
3
|
+
Every string is already escaped. Lines are written with {{ nl }}; tags trim the source's own.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
🔍 <b>What the digest found on its own this week</b>
|
|
8
|
+
{{- nl }}<i>Not in the day's selection · {{ runs }} {% if plural == "one" %}digest{% else %}digests{% endif %}, {{ from.date }} to {{ to.date }}</i>
|
|
9
|
+
{%- if items.size == 0 %}{{ nl }}{{ nl }}Nothing was missed.{% endif -%}
|
|
10
|
+
{%- for item in items -%}
|
|
11
|
+
{{ nl }}{{ nl }}• {{ item.what }}
|
|
12
|
+
{{- nl }}<i>{% if item.seen > 1 %}in {{ item.seen }} digests, last on {% endif %}{{ item.last.date }}</i>
|
|
13
|
+
{%- for link in item.links %} · <a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
|
|
14
|
+
{%- endfor -%}
|
|
15
|
+
{%- if more > 0 %}{{ nl }}{{ nl }}{{ more }} more{% endif -%}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Telegram HTML: only <b>, <i> and <a href> survive, and an href only to a link of the view model.
|
|
3
|
+
Every string is already escaped. Lines are written with {{ nl }}; tags trim the source's own.
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- capture nl %}
|
|
6
|
+
{% endcapture -%}
|
|
7
|
+
🔍 <b>Что сводка нашла сама за неделю</b>
|
|
8
|
+
{{- nl }}<i>Этого не было в подборке дня · {{ runs }} {% case plural %}{% when "one" %}сводка{% when "few" %}сводки{% else %}сводок{% endcase %} с {{ from.date }} по {{ to.date }}</i>
|
|
9
|
+
{%- if items.size == 0 %}{{ nl }}{{ nl }}Пропусков не было.{% endif -%}
|
|
10
|
+
{%- for item in items -%}
|
|
11
|
+
{{ nl }}{{ nl }}• {{ item.what }}
|
|
12
|
+
{{- nl }}<i>{% if item.seen > 1 %}в {{ item.seen }} {% if item.plural == "one" %}сводке{% else %}сводках{% endif %}, последний раз {% endif %}{{ item.last.date }}</i>
|
|
13
|
+
{%- for link in item.links %} · <a href="{{ link.url }}">{{ link.label }}</a>{% endfor -%}
|
|
14
|
+
{%- endfor -%}
|
|
15
|
+
{%- if more > 0 %}{{ nl }}{{ nl }}ещё {{ more }}{% endif -%}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Plain text: the email's plain part and the terminal. Line 2 of an item is indented by two spaces.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
🔍 What the digest found on its own this week
|
|
7
|
+
{{- nl }}Not in the day's selection · {{ runs }} {% if plural == "one" %}digest{% else %}digests{% endif %}, {{ from.date }} to {{ to.date }}
|
|
8
|
+
{%- if items.size == 0 %}{{ nl }}{{ nl }}Nothing was missed.{% endif -%}
|
|
9
|
+
{%- for item in items -%}
|
|
10
|
+
{{ nl }}{{ nl }}• {{ item.what }}
|
|
11
|
+
{{- nl }} {% if item.seen > 1 %}in {{ item.seen }} digests, last on {% endif %}{{ item.last.date }}
|
|
12
|
+
{%- for link in item.links %} · {{ link.url }}{% endfor -%}
|
|
13
|
+
{%- endfor -%}
|
|
14
|
+
{%- if more > 0 %}{{ nl }}{{ nl }}{{ more }} more{% endif -%}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Plain text: the email's plain part and the terminal. Line 2 of an item is indented by two spaces.
|
|
3
|
+
{%- endcomment -%}
|
|
4
|
+
{%- capture nl %}
|
|
5
|
+
{% endcapture -%}
|
|
6
|
+
🔍 Что сводка нашла сама за неделю
|
|
7
|
+
{{- nl }}Этого не было в подборке дня · {{ runs }} {% case plural %}{% when "one" %}сводка{% when "few" %}сводки{% else %}сводок{% endcase %} с {{ from.date }} по {{ to.date }}
|
|
8
|
+
{%- if items.size == 0 %}{{ nl }}{{ nl }}Пропусков не было.{% endif -%}
|
|
9
|
+
{%- for item in items -%}
|
|
10
|
+
{{ nl }}{{ nl }}• {{ item.what }}
|
|
11
|
+
{{- nl }} {% if item.seen > 1 %}в {{ item.seen }} {% if item.plural == "one" %}сводке{% else %}сводках{% endif %}, последний раз {% endif %}{{ item.last.date }}
|
|
12
|
+
{%- for link in item.links %} · {{ link.url }}{% endfor -%}
|
|
13
|
+
{%- endfor -%}
|
|
14
|
+
{%- if more > 0 %}{{ nl }}{{ nl }}ещё {{ more }}{% endif -%}
|
|
@@ -54,6 +54,11 @@ export interface ViewSection {
|
|
|
54
54
|
more: number;
|
|
55
55
|
/** The task group links, on the section that holds the task items only; zero groups left out. */
|
|
56
56
|
groups: ViewTaskGroup[];
|
|
57
|
+
/** The open tasks with no due date, a line after the groups on the same section; null when there are none. */
|
|
58
|
+
undated: {
|
|
59
|
+
count: number;
|
|
60
|
+
link: ViewLink | null;
|
|
61
|
+
} | null;
|
|
57
62
|
}
|
|
58
63
|
export interface ViewHealth {
|
|
59
64
|
source: string;
|
|
@@ -166,10 +166,18 @@ export const reportView = (report, { language, now, timeZone, linkOf = () => nul
|
|
|
166
166
|
items: items.slice(0, cap).map(itemOf),
|
|
167
167
|
more: more + Math.max(items.length - cap, 0),
|
|
168
168
|
groups: [],
|
|
169
|
+
undated: null,
|
|
169
170
|
},
|
|
170
171
|
];
|
|
171
172
|
});
|
|
172
173
|
const groups = taskGroups(report.tasks, linkOf, words.open);
|
|
174
|
+
const undatedLink = linkOf("tasks:undated");
|
|
175
|
+
const undated = report.tasks?.undated
|
|
176
|
+
? {
|
|
177
|
+
count: report.tasks.undated,
|
|
178
|
+
link: undatedLink === null ? null : { kind: "open", url: undatedLink, label: words.open },
|
|
179
|
+
}
|
|
180
|
+
: null;
|
|
173
181
|
const holder = sections.find((section) => section.items.some((item) => item.type === "task")) ??
|
|
174
182
|
sections.find((section) => section.kind === "today") ??
|
|
175
183
|
sections.at(-1);
|
|
@@ -184,7 +192,7 @@ export const reportView = (report, { language, now, timeZone, linkOf = () => nul
|
|
|
184
192
|
emoji: "☀️",
|
|
185
193
|
date: momentFor(report.date, now, language, timeZone),
|
|
186
194
|
summary: report.summary,
|
|
187
|
-
sections: sections.map((section) => (section === holder ? { ...section, groups } : section)),
|
|
195
|
+
sections: sections.map((section) => (section === holder ? { ...section, groups, undated } : section)),
|
|
188
196
|
health: {
|
|
189
197
|
emoji: "🛠",
|
|
190
198
|
items: stale.slice(0, SECTION_CAPS.health).map((entry) => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AppIdentity } from "../ports/app.js";
|
|
2
2
|
import { type Delivery } from "./deliver.js";
|
|
3
|
-
import { type ReportRun } from "./report/render.js";
|
|
3
|
+
import { type ReportRun, type StoredTemplates } from "./report/render.js";
|
|
4
4
|
import type { ServerSystem } from "./system.js";
|
|
5
5
|
/** Minutes between runs, a daily local time, or one local moment. */
|
|
6
6
|
export type When = {
|
|
@@ -77,6 +77,8 @@ export interface LastRun {
|
|
|
77
77
|
failures?: number;
|
|
78
78
|
/** What the run cost, as the harness reported it; absent when it reports none. */
|
|
79
79
|
costUsd?: number;
|
|
80
|
+
/** The SHA-256 of a mail-gated agent's input, so a timer can tell the next input is the same one. */
|
|
81
|
+
inputHash?: string;
|
|
80
82
|
/** The last time the timer did not start it, and why; a run after it clears this. */
|
|
81
83
|
skipped?: {
|
|
82
84
|
at: string;
|
|
@@ -93,6 +95,7 @@ export declare const SKIP_REASONS: {
|
|
|
93
95
|
readonly costDayCap: "cost.day-cap";
|
|
94
96
|
readonly mailNone: "mail.none-new";
|
|
95
97
|
readonly mailBelowThreshold: "mail.below-threshold";
|
|
98
|
+
readonly mailSameInput: "mail.same-input";
|
|
96
99
|
};
|
|
97
100
|
export type SkipReason = (typeof SKIP_REASONS)[keyof typeof SKIP_REASONS];
|
|
98
101
|
/**
|
|
@@ -118,6 +121,7 @@ export declare const recordRun: (path: string, run: {
|
|
|
118
121
|
reason?: string;
|
|
119
122
|
errorCode?: string;
|
|
120
123
|
costUsd?: number;
|
|
124
|
+
inputHash?: string;
|
|
121
125
|
}) => LastRun;
|
|
122
126
|
/** Notes on the last run that the timer left this one out, keeping that run's result. */
|
|
123
127
|
export declare const recordSkip: (file: string, why: string, reason: SkipReason, at?: Date) => void;
|
|
@@ -175,7 +179,7 @@ export declare const CREDENTIALS_UNREACHABLE = "credentials.unreachable";
|
|
|
175
179
|
* keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
|
|
176
180
|
* 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
|
|
177
181
|
*/
|
|
178
|
-
export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, file: string, { now, timer, signal, killAfterMs, untilUnlocked, wait, agentRuns, agentInput, ownerLanguage, }?: {
|
|
182
|
+
export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, file: string, { now, timer, signal, killAfterMs, untilUnlocked, wait, agentRuns, agentInput, ownerLanguage, reportTemplates, skipRepeatedInput, }?: {
|
|
179
183
|
now?: () => Date;
|
|
180
184
|
timer?: Timer;
|
|
181
185
|
signal?: AbortSignal;
|
|
@@ -187,4 +191,11 @@ export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env:
|
|
|
187
191
|
agentInput?: AgentInput;
|
|
188
192
|
/** The owner's first language, read only when the answer is a report; Russian when the host cannot say. */
|
|
189
193
|
ownerLanguage?: (env: NodeJS.ProcessEnv) => Promise<string>;
|
|
194
|
+
/** The owner's stored report templates; the shipped ones when the host gives none. */
|
|
195
|
+
reportTemplates?: (env: NodeJS.ProcessEnv) => StoredTemplates;
|
|
196
|
+
/**
|
|
197
|
+
* Leave out a mail-gated agent whose input is the one its last run ended well on. The mark did not move, so the
|
|
198
|
+
* run would only meet the same input again and pay for it; new mail changes the input.
|
|
199
|
+
*/
|
|
200
|
+
skipRepeatedInput?: boolean;
|
|
190
201
|
}) => Promise<LastRun>;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { basename, join } from "node:path";
|
|
4
5
|
import { CliError, errorCodes, writeSecurely } from "@wirecat/cli-base";
|
|
5
|
-
import { linkConfigOf } from "../domain/links.js";
|
|
6
|
+
import { linkConfigOf, linkFor } from "../domain/links.js";
|
|
6
7
|
import { mailHolderVariable, readOnlyLockOf } from "../ports/app.js";
|
|
7
8
|
import { recordLogFor } from "../runs/record-log.js";
|
|
8
9
|
import { childTrace } from "../runs/scope.js";
|
|
9
10
|
import { storePath } from "../store/path.js";
|
|
10
11
|
import { readSharedSection, sharedConfigPath } from "../store/shared-config.js";
|
|
11
12
|
import { deliver } from "./deliver.js";
|
|
12
|
-
import {
|
|
13
|
+
import { causeOf, gapsView, noticeView, weeklyGapsOf } from "./report/messages.js";
|
|
14
|
+
import { prepareMessage, prepareReport, } from "./report/render.js";
|
|
13
15
|
export const NOTIFY_WHEN = ["always", "failures", "never"];
|
|
14
16
|
/** A repeating agent would otherwise notify on every tick; any other schedule runs rarely enough to say each result. */
|
|
15
17
|
export const notifyOf = (schedule) => schedule.notify ?? (schedule.kind === "agent" && "every" in schedule.when ? "failures" : "always");
|
|
@@ -67,6 +69,7 @@ export const SKIP_REASONS = {
|
|
|
67
69
|
costDayCap: "cost.day-cap",
|
|
68
70
|
mailNone: "mail.none-new",
|
|
69
71
|
mailBelowThreshold: "mail.below-threshold",
|
|
72
|
+
mailSameInput: "mail.same-input",
|
|
70
73
|
};
|
|
71
74
|
const REASON_ID = /^[a-z0-9][a-z0-9.-]{0,79}$/;
|
|
72
75
|
/**
|
|
@@ -354,6 +357,23 @@ const sharedLinks = (env) => {
|
|
|
354
357
|
return linkConfigOf(undefined);
|
|
355
358
|
}
|
|
356
359
|
};
|
|
360
|
+
/**
|
|
361
|
+
* WireCat Desktop, while it runs, writes `<state>/schedules/desktop.json` with its pid and the schedules whose new
|
|
362
|
+
* runs it announces itself; a marker whose pid is gone (a crash) announces nothing.
|
|
363
|
+
*/
|
|
364
|
+
const announcedByDesktop = (schedulesFolder, name) => {
|
|
365
|
+
try {
|
|
366
|
+
const { pid, announces } = JSON.parse(readFileSync(join(schedulesFolder, "desktop.json"), "utf8"));
|
|
367
|
+
if (!Number.isInteger(pid) || !Array.isArray(announces) || !announces.includes(name))
|
|
368
|
+
return false;
|
|
369
|
+
process.kill(pid, 0);
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
// EPERM: the process is there, under another user.
|
|
374
|
+
return error.code === "EPERM";
|
|
375
|
+
}
|
|
376
|
+
};
|
|
357
377
|
/** A desktop notification; a machine without one loses only the notice, never the run. */
|
|
358
378
|
export const notify = async (system, env, title, body) => {
|
|
359
379
|
const argv = system.platform === "linux"
|
|
@@ -443,7 +463,7 @@ const pause = (ms, signal) => new Promise((resolve) => {
|
|
|
443
463
|
* keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
|
|
444
464
|
* 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
|
|
445
465
|
*/
|
|
446
|
-
export const runSchedule = async (app, system, env, file, { now = () => new Date(), timer, signal, killAfterMs = KILL_AFTER_MS, untilUnlocked = false, wait = pause, agentRuns = [], agentInput, ownerLanguage = async () => "ru", } = {}) => {
|
|
466
|
+
export const runSchedule = async (app, system, env, file, { now = () => new Date(), timer, signal, killAfterMs = KILL_AFTER_MS, untilUnlocked = false, wait = pause, agentRuns = [], agentInput, ownerLanguage = async () => "ru", reportTemplates, skipRepeatedInput = false, } = {}) => {
|
|
447
467
|
const schedule = readSchedule(file);
|
|
448
468
|
const folder = join(file, "..");
|
|
449
469
|
const runs = join(folder, "runs");
|
|
@@ -451,24 +471,33 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
451
471
|
const agent = schedule.kind === "agent";
|
|
452
472
|
const retries = untilUnlocked && !("every" in schedule.when);
|
|
453
473
|
const firstAt = now().getTime();
|
|
454
|
-
|
|
474
|
+
const first = await attemptSchedule(app, system, env, schedule, folder, {
|
|
455
475
|
now,
|
|
456
476
|
signal,
|
|
457
477
|
killAfterMs,
|
|
458
478
|
agentRuns,
|
|
459
479
|
agentInput,
|
|
480
|
+
skipRepeatedInput,
|
|
460
481
|
});
|
|
482
|
+
if ("repeated" in first) {
|
|
483
|
+
recordSkip(file, "the input is the same as the last run's, which moved no mark; it runs again once new mail comes", SKIP_REASONS.mailSameInput, now());
|
|
484
|
+
return lastRun(file) ?? first.repeated;
|
|
485
|
+
}
|
|
486
|
+
let last = first;
|
|
461
487
|
for (let delay = LOCKED_FIRST_WAIT_MS; retries && lockedOut(last) && !signal?.aborted && now().getTime() - firstAt + delay <= LOCKED_GIVE_UP_MS; delay = Math.min(delay * 2, LOCKED_LONGEST_WAIT_MS)) {
|
|
462
488
|
await wait(delay, signal);
|
|
463
489
|
if (signal?.aborted)
|
|
464
490
|
break;
|
|
465
|
-
|
|
491
|
+
const again = await attemptSchedule(app, system, env, schedule, folder, {
|
|
466
492
|
now,
|
|
467
493
|
signal,
|
|
468
494
|
killAfterMs,
|
|
469
495
|
agentRuns,
|
|
470
496
|
agentInput,
|
|
471
497
|
});
|
|
498
|
+
if ("repeated" in again)
|
|
499
|
+
break;
|
|
500
|
+
last = again;
|
|
472
501
|
}
|
|
473
502
|
const { exitCode, output } = last;
|
|
474
503
|
const errors = agent ? output.replace(/\.md$/, ".log") : output;
|
|
@@ -481,6 +510,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
481
510
|
now: now().getTime(),
|
|
482
511
|
links: sharedLinks(runEnv),
|
|
483
512
|
env: runEnv,
|
|
513
|
+
...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
|
|
484
514
|
})
|
|
485
515
|
: undefined;
|
|
486
516
|
const latestText = join(folder, "latest.txt");
|
|
@@ -499,43 +529,65 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
499
529
|
rmSync(join(runs, file), { force: true });
|
|
500
530
|
const title = `${app.command} ${schedule.name}`;
|
|
501
531
|
const mode = notifyOf(schedule);
|
|
502
|
-
if (
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
532
|
+
if (agent && exitCode === 0) {
|
|
533
|
+
if (mode === "always" && !announcedByDesktop(join(folder, ".."), schedule.name)) {
|
|
534
|
+
const first = readFileSync(output, "utf8")
|
|
535
|
+
.split("\n")
|
|
536
|
+
.find((line) => line.trim()) ?? "report ready";
|
|
537
|
+
await notify(system, env, title, prepared
|
|
538
|
+
? `${prepared.notice.slice(0, 180)}\n${latestText}`
|
|
539
|
+
: `${first.trim().slice(0, 180)}\n${join(folder, "latest.md")}`);
|
|
540
|
+
}
|
|
510
541
|
}
|
|
511
542
|
else if (exitCode !== 0 && mode !== "never") {
|
|
512
543
|
await notify(system, env, title, `failed (exit ${exitCode}) — ${errors}`);
|
|
513
544
|
}
|
|
514
545
|
const routes = schedule.to ?? [];
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
const deliveries = await deliver(system, runEnv, routes, exitCode === 0
|
|
519
|
-
? {
|
|
520
|
-
title: `${title} · ${at}`,
|
|
521
|
-
file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${agent ? "md" : "txt"}` },
|
|
522
|
-
...(prepared ? { rendered: prepared } : {}),
|
|
523
|
-
}
|
|
524
|
-
: {
|
|
525
|
-
title: `${title} failed · ${at}`,
|
|
526
|
-
line: `${title} failed at ${at} (exit ${exitCode}` +
|
|
527
|
-
`${last.failures && last.failures > 1 ? `, ${last.failures} runs in a row` : ""})` +
|
|
528
|
-
`${last.reason ? `: ${last.reason}` : ""} — ${errors}`,
|
|
529
|
-
}, {
|
|
546
|
+
const locked = readOnlyLockOf(app, runEnv);
|
|
547
|
+
const sendAlong = async (parcel) => {
|
|
548
|
+
const deliveries = await deliver(system, runEnv, routes, parcel, {
|
|
530
549
|
find: (name, on) => findProgram(name, on, system.platform),
|
|
531
550
|
errorOf: reasonOf,
|
|
532
551
|
...(locked ? { locked } : {}),
|
|
533
552
|
});
|
|
534
|
-
last = rewriteRun(join(folder, "last.json"), { ...last, deliveries });
|
|
535
553
|
const lost = deliveries.filter((one) => !one.ok);
|
|
536
554
|
if (lost.length > 0 && mode !== "never") {
|
|
537
555
|
await notify(system, env, title, lost.map((one) => `not delivered to ${one.to}: ${one.reason}`).join("\n"));
|
|
538
556
|
}
|
|
557
|
+
return deliveries;
|
|
558
|
+
};
|
|
559
|
+
const messageOptions = async () => ({
|
|
560
|
+
language: await ownerLanguage(runEnv).catch(() => "ru"),
|
|
561
|
+
linkOf: (ref) => linkFor(ref, { form: "web", config: sharedLinks(runEnv), env: runEnv }),
|
|
562
|
+
...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
|
|
563
|
+
});
|
|
564
|
+
if (routes.length > 0 && (exitCode === 0 ? mode === "always" : mode !== "never")) {
|
|
565
|
+
const at = shortTime(last.at);
|
|
566
|
+
const notice = exitCode === 0 ? undefined : await failureNotice(app, schedule, last, now(), await messageOptions());
|
|
567
|
+
const deliveries = await sendAlong(exitCode === 0
|
|
568
|
+
? {
|
|
569
|
+
title: `${title} · ${at}`,
|
|
570
|
+
file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${agent ? "md" : "txt"}` },
|
|
571
|
+
...(prepared ? { rendered: prepared } : {}),
|
|
572
|
+
}
|
|
573
|
+
: notice
|
|
574
|
+
? { title: notice.subject, rendered: notice }
|
|
575
|
+
: {
|
|
576
|
+
title: `${title} failed · ${at}`,
|
|
577
|
+
line: `${title} failed at ${at} (exit ${exitCode}` +
|
|
578
|
+
`${last.failures && last.failures > 1 ? `, ${last.failures} runs in a row` : ""})` +
|
|
579
|
+
`${last.reason ? `: ${last.reason}` : ""} — ${errors}`,
|
|
580
|
+
});
|
|
581
|
+
last = rewriteRun(join(folder, "last.json"), { ...last, deliveries });
|
|
582
|
+
}
|
|
583
|
+
if (routes.length > 0 && mode === "always" && prepared && !prepared.invalid && gapsDue(folder, now())) {
|
|
584
|
+
const gaps = weeklyGapsOf(runs, now().getTime());
|
|
585
|
+
const options = await messageOptions();
|
|
586
|
+
const message = gaps.gaps.length === 0
|
|
587
|
+
? undefined
|
|
588
|
+
: await prepareMessage("weekly-gaps", (language) => gapsView(gaps, { language, now: now().getTime(), linkOf: options.linkOf }), options).catch(() => undefined);
|
|
589
|
+
const deliveries = message ? await sendAlong({ title: message.subject, rendered: message }) : [];
|
|
590
|
+
writeSecurely(join(folder, WEEKLY_GAPS_FILE), `${JSON.stringify({ at: now().toISOString(), gaps: gaps.gaps.length, runs: gaps.runs, deliveries }, null, 2)}\n`, 0o600);
|
|
539
591
|
}
|
|
540
592
|
if ("once" in schedule.when) {
|
|
541
593
|
await timer?.remove(schedule.name);
|
|
@@ -543,6 +595,44 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
543
595
|
}
|
|
544
596
|
return last;
|
|
545
597
|
};
|
|
598
|
+
/**
|
|
599
|
+
* The rendered notice of a failed run: which schedule, since when, the cause, and one link to the tool's sync
|
|
600
|
+
* screen; undefined when even the shipped template fails, and the run's one line goes instead.
|
|
601
|
+
*/
|
|
602
|
+
const failureNotice = async (app, schedule, last, at, options) => {
|
|
603
|
+
const failure = {
|
|
604
|
+
kind: "schedule-failed",
|
|
605
|
+
tool: app.command,
|
|
606
|
+
schedule: schedule.name,
|
|
607
|
+
at: last.at,
|
|
608
|
+
since: last.failingSince ?? last.at,
|
|
609
|
+
failures: last.failures ?? 1,
|
|
610
|
+
cause: lockedOut(last) ? "locked" : causeOf(last.errorCode, last.exitCode),
|
|
611
|
+
refs: [`sync:${app.command}`],
|
|
612
|
+
};
|
|
613
|
+
return prepareMessage("schedule-failed", (language) => noticeView(failure, { language, now: at.getTime(), linkOf: options.linkOf }), options).catch(() => undefined);
|
|
614
|
+
};
|
|
615
|
+
/** When the weekly gaps went last, how many, and along which routes. */
|
|
616
|
+
const WEEKLY_GAPS_FILE = "weekly-gaps.json";
|
|
617
|
+
/** Monday 00:00, local time, of the week `at` falls in. */
|
|
618
|
+
const weekStart = (at) => {
|
|
619
|
+
const day = new Date(at);
|
|
620
|
+
day.setHours(0, 0, 0, 0);
|
|
621
|
+
day.setDate(day.getDate() - ((day.getDay() + 6) % 7));
|
|
622
|
+
return day.getTime();
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* Whether this digest run also sends the week's gaps: on a Monday, or on the first run of a week whose Monday run
|
|
626
|
+
* did not send them. A schedule that never sent any waits for its first Monday, so it never sends one day's gaps.
|
|
627
|
+
*/
|
|
628
|
+
const gapsDue = (folder, now) => {
|
|
629
|
+
let sent;
|
|
630
|
+
try {
|
|
631
|
+
sent = Date.parse(JSON.parse(readFileSync(join(folder, WEEKLY_GAPS_FILE), "utf8")).at);
|
|
632
|
+
}
|
|
633
|
+
catch { }
|
|
634
|
+
return sent === undefined || Number.isNaN(sent) ? now.getDay() === 1 : sent < weekStart(now);
|
|
635
|
+
};
|
|
546
636
|
/** The agent's input, or none: a host read that fails leaves the agent to fetch what it needs itself. */
|
|
547
637
|
const inputOf = async (agentInput, system, env, schedule, log) => {
|
|
548
638
|
try {
|
|
@@ -560,7 +650,7 @@ const inputOf = async (agentInput, system, env, schedule, log) => {
|
|
|
560
650
|
}
|
|
561
651
|
};
|
|
562
652
|
/** One run of the schedule's command or agent: its output in `runs/`, its result in `last.json`. */
|
|
563
|
-
const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, }) => {
|
|
653
|
+
const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput = false, }) => {
|
|
564
654
|
const runs = join(folder, "runs");
|
|
565
655
|
const stamp = now()
|
|
566
656
|
.toISOString()
|
|
@@ -593,6 +683,13 @@ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal
|
|
|
593
683
|
const began = now().getTime();
|
|
594
684
|
log.info({ event: "schedule.start", ...facts });
|
|
595
685
|
const input = agent && agentInput ? await inputOf(agentInput, system, childEnv, schedule, log) : undefined;
|
|
686
|
+
const inputHash = input === undefined || !schedule.onNewMail ? undefined : createHash("sha256").update(input).digest("hex");
|
|
687
|
+
const before = skipRepeatedInput && inputHash !== undefined ? readRun(join(folder, "last.json")) : undefined;
|
|
688
|
+
if (before?.exitCode === 0 && before.inputHash === inputHash) {
|
|
689
|
+
// A skip every few minutes would otherwise push the kept runs' files out of runs/.
|
|
690
|
+
rmSync(join(runs, `${stamp}.jsonl`), { force: true });
|
|
691
|
+
return { repeated: before };
|
|
692
|
+
}
|
|
596
693
|
let costUsd;
|
|
597
694
|
const exitCode = await new Promise((resolve) => {
|
|
598
695
|
const child = spawn(program, args, { env: childEnv, cwd: folder, stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -645,6 +742,7 @@ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal
|
|
|
645
742
|
output,
|
|
646
743
|
traceId: trace.traceId,
|
|
647
744
|
...(costUsd === undefined ? {} : { costUsd }),
|
|
745
|
+
...(inputHash === undefined ? {} : { inputHash }),
|
|
648
746
|
...(exitCode === 0 ? {} : failureOf(readFileSync(errors, "utf8"), exitCode)),
|
|
649
747
|
});
|
|
650
748
|
};
|