@wirecat/cli-core 0.623.0 → 0.625.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 +85 -0
- package/dist/background/backfill.d.ts +1 -1
- package/dist/background/backfill.js +1 -1
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/report/stored-templates.d.ts +21 -3
- package/dist/background/report/stored-templates.js +34 -6
- package/dist/background/schedules.d.ts +10 -20
- package/dist/background/schedules.js +8 -162
- package/dist/background/timers.d.ts +19 -0
- package/dist/background/timers.js +175 -0
- package/dist/background/when.d.ts +28 -7
- package/dist/background/when.js +55 -11
- package/dist/calendar/prepare.d.ts +14 -0
- package/dist/cli/app-doctor-command.js +2 -1
- package/dist/cli/envelope.d.ts +28 -0
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.js +3 -2
- package/dist/cli/schedule/schedule-command.d.ts +100 -3
- package/dist/cli/schedule/schedule-command.js +276 -118
- package/dist/cli/templates-command.js +45 -20
- package/dist/domain/display-names.d.ts +5 -2
- package/dist/domain/display-names.js +13 -4
- package/dist/domain/person-kinds.d.ts +9 -0
- package/dist/domain/person-kinds.js +67 -0
- package/dist/domain/records-table.d.ts +61 -0
- package/dist/domain/records-table.js +382 -0
- package/dist/entities/index.d.ts +2 -1
- package/dist/entities/list-results.d.ts +2 -0
- package/dist/entities/list-results.js +2 -0
- package/dist/entities/template.d.ts +1 -1
- package/dist/entities/template.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/surface.js +23 -2
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/search-harder.d.ts +6 -1
- package/dist/services/search-harder.js +9 -2
- package/dist/store/index.d.ts +2 -1
- package/dist/store/index.js +2 -0
- package/dist/store/people.d.ts +4 -3
- package/dist/store/sqlite/people-list.d.ts +23 -8
- package/dist/store/sqlite/people-list.js +189 -65
- package/package.json +2 -2
- package/parity.json +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,91 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.625.0 — 09.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A records file can be a spreadsheet.** `recordColumns(type)` lists a type's columns: `external_id`, its flat
|
|
13
|
+
fields, one per role and one per key of its lists (`lines.amount`), each with whether it is required, its shape and
|
|
14
|
+
its values. `recordTemplate(type, "csv" | "json")` writes a file to fill: the CSV header with a byte-order mark, in
|
|
15
|
+
the separator asked for, or an envelope of one example record. `envelopeOfCsv(text, { type, source })` reads a sheet
|
|
16
|
+
of one type as an envelope: `;`, `,` or a tab, a byte-order mark, `10 000,50` and `09.11.2026` as Excel writes them
|
|
17
|
+
in Russian or Spanish, a role as the target's external id (`<type>:<external id>` where it takes several types), and
|
|
18
|
+
a row that repeats an external id as one more item of a list. `placeOf(pointer)` names the line and column a
|
|
19
|
+
receipt's pointer came from; a sheet it cannot read throws a `TableError` that names them too. SMS and calls have no
|
|
20
|
+
table: they come from a phone's own export.
|
|
21
|
+
|
|
22
|
+
### Changed — may break callers
|
|
23
|
+
|
|
24
|
+
- **`people.list` has a `stranger` kind**: a named person with no tie to the owner, such as an author seen only in a
|
|
25
|
+
big group. `unsorted` now holds only people with nothing to show as a name. `kind: "stranger"` lists them, `all`
|
|
26
|
+
includes them, and `counts` counts them.
|
|
27
|
+
|
|
28
|
+
## 0.624.0 — 09.11.2026
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- `schedule agent|command --at` repeats: `--at 08:30 --at 18:00` runs twice a day, `--at 'mon,fri 09:00'` (or one
|
|
33
|
+
`--at` per weekday) on several days, all on one timer: one `OnCalendar=` per time under systemd, an array of
|
|
34
|
+
`StartCalendarInterval` under launchd, one trigger per time in Task Scheduler. `schedule list` says
|
|
35
|
+
`daily at 08:30, 18:00` or `weekly on Mon, Fri at 09:00`. One `--at` is saved and listed as before.
|
|
36
|
+
- `schedule pause <name>` takes a schedule off its timer and keeps it; `schedule run` still runs it, `schedule resume`
|
|
37
|
+
puts it back. `schedule list` marks it `paused: true`.
|
|
38
|
+
- `schedule run <name> --no-notify` keeps the result here: no route and no desktop notice. `--deliver-to <route>`
|
|
39
|
+
(repeatable) sends it along only those, which must be the schedule's own, whatever its `--notify-on` says.
|
|
40
|
+
- `templates show|edit|preview|reset report/<schedule>`: an agent schedule's own digest templates. A run of that
|
|
41
|
+
schedule renders with them, else with the owner's `report/morning-digest`, else with the shipped ones; `templates
|
|
42
|
+
show` and `list` call that middle case `source: "inherited"`. A schedule named after another message's key
|
|
43
|
+
(`weekly-gaps`) has no key of its own, and a removed schedule's templates can still be shown and reset.
|
|
44
|
+
- For a tool that keeps its own digests (memo): `agentSchedule`, `writeSchedule`, `pauseSchedule`, `removeSchedule`
|
|
45
|
+
and `runScheduleNow` build, save, pause, remove and run an agent schedule as the `schedule` commands do (the routes
|
|
46
|
+
and the day's cost cap checked the same way); `slotsOfAt` reads one `--at`; `parseRoute` and `routeText` read a
|
|
47
|
+
route; `slotsOf`, `calendarOf`, `runsBetween`, `previousRun` and `nextRun` read a calendar schedule's times.
|
|
48
|
+
- **`harderRanking(result)` gives the `--harder` outcome as cli-base 0.94.0's `meta.ranking`.** A CLI that offers
|
|
49
|
+
`search all --harder` puts it into its answer's `meta`, so a program such as WireCat Desktop reads whether the
|
|
50
|
+
model's order was used, why not (`reason_id`), which provider, model and endpoint, how many hits were sent, the cost
|
|
51
|
+
and, new in the result, the tokens (`usage`) instead of an English note. cli-base goes to 0.94.0.
|
|
52
|
+
|
|
53
|
+
### Changed — may break callers
|
|
54
|
+
|
|
55
|
+
- `template.source` gains `inherited`. A schedule's `When` gains `{ calendar: Slot[] }` for more than one time; code that switches over every `When` needs
|
|
56
|
+
the new case, or `slotsOf` for any calendar shape. A host's `reportTemplates` now gets the schedule's name as its
|
|
57
|
+
second argument.
|
|
58
|
+
- **The MCP `<app>_read` and `<app>_write` tools list a short answer schema: 3,323 characters for the three tools in
|
|
59
|
+
place of 17,278.** It names only what an agent acts on: `items` or `item`, `page.has_more`, `next`, `missing`, and
|
|
60
|
+
`meta` as an open object that points at `<app>_tools_search`, whose match still gives each command's full answer.
|
|
61
|
+
`_write` lists only `item`, `next` and `meta`, all a write answers with. The server still checks every answer
|
|
62
|
+
against the full cli-base envelope, so nothing an answer carries changes. Every client paid the full schema twice
|
|
63
|
+
on each connect, and cli-base 0.94.0's `meta.ranking` added 2,800 characters more. Watch for: a
|
|
64
|
+
client that built types from the listed `outputSchema` now gets open objects; it reads the full answer from
|
|
65
|
+
`<app>_tools_search`. An agent eval found no loss: 39 of 42 tasks with either listing, on half the input tokens
|
|
66
|
+
([cli-testing](https://github.com/WireCatLabs/cli-testing/tree/main/performance/agents/mcp-short-listing)).
|
|
67
|
+
- **`store.people.list` lists one kind of person at a time**, `person` by default, instead of hiding everyone with no
|
|
68
|
+
tie. `kind` is `person`, `organization`, `automated`, `unsorted` or `all`; the `all` option and `hidden` are gone,
|
|
69
|
+
and `counts` gives how many each kind holds. The first rule that holds decides the kind, and `kindSignals` names
|
|
70
|
+
it: the owner, people added by hand and task assignees are a `person`; a bot, a no-reply address, a sender most of
|
|
71
|
+
whose mail is in the bulk box, a sender memo scored `bulk_never_replied`, or a name such as «Notifications» or
|
|
72
|
+
«Рассылка» is `automated`; an identity an organization owns, a shared role address (`info@`) or a legal form or
|
|
73
|
+
company word in the name (ООО, LLC, Airlines, Hotel, Team…) is an `organization`; a named person with a tie is a
|
|
74
|
+
`person`; everyone else, with no tie or nothing to show as a name, is `unsorted`.
|
|
75
|
+
- `sort` takes `interactions` (the default: most messages and mail from them first), `recent`, `name` or `tasks`.
|
|
76
|
+
- Each listed person has `kind`, `kindSignals`, `contact` (the phone, else the email, else `@username`),
|
|
77
|
+
`messagesFrom` and `lastContact`. On a synthetic store of 51,000 people and 1.5 million messages a list takes about
|
|
78
|
+
0.5–0.6 s on a loaded machine and 1.9 s sorted by `recent`; a name search reads only the people it found
|
|
79
|
+
([cli-testing `performance/people/kinds`](https://github.com/WireCatLabs/cli-testing/tree/main/performance/people/kinds)).
|
|
80
|
+
- An unknown `kind` or `sort` is refused. A sender counts as bulk mail from 3 letters on; a role address makes an
|
|
81
|
+
`organization` only when every address of the person is one.
|
|
82
|
+
- `displayName` reads a messenger's placeholder for a missing name (`null`, «Без имени», `Deleted Account`) as no
|
|
83
|
+
name, so the username, phone or email shows instead; `nameKey` gives such a name no key, so two deleted
|
|
84
|
+
accounts are never proposed as one person.
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
|
|
88
|
+
- **`doctor --online` asks npm through `hostFetch`**, which reaches only `registry.npmjs.org`. cli-base 0.94.0's
|
|
89
|
+
`raw-network` lint reported the global `fetch` it fell back to. The model gateway and OpenAI transcription keep the
|
|
90
|
+
global `fetch` in the lint baseline: they call an endpoint the owner configures (OpenRouter, a local server), so no
|
|
91
|
+
host list can be declared in advance.
|
|
92
|
+
|
|
8
93
|
## 0.623.0 — 09.11.2026
|
|
9
94
|
|
|
10
95
|
### Added
|
|
@@ -17,5 +17,5 @@ export declare const backfillSchedule: (app: AppIdentity, system: ServerSystem,
|
|
|
17
17
|
killAfterMs?: number;
|
|
18
18
|
agentRuns?: readonly AgentCli[];
|
|
19
19
|
ownerLanguage?: (env: NodeJS.ProcessEnv) => Promise<string>;
|
|
20
|
-
reportTemplates?: (env: NodeJS.ProcessEnv) => StoredTemplates;
|
|
20
|
+
reportTemplates?: (env: NodeJS.ProcessEnv, schedule: string) => StoredTemplates;
|
|
21
21
|
}) => Promise<LastRun>;
|
|
@@ -31,7 +31,7 @@ export const backfillSchedule = async (app, system, env, file, { at, input, now
|
|
|
31
31
|
now: at.getTime(),
|
|
32
32
|
links: sharedLinks(runEnv),
|
|
33
33
|
env: runEnv,
|
|
34
|
-
...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
|
|
34
|
+
...(reportTemplates ? { templates: reportTemplates(runEnv, schedule.name) } : {}),
|
|
35
35
|
});
|
|
36
36
|
if (!prepared)
|
|
37
37
|
return last;
|
|
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
|
|
26
26
|
export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
27
|
-
action?: undefined;
|
|
28
27
|
name: string;
|
|
29
28
|
installed: boolean;
|
|
30
29
|
active: boolean;
|
|
31
30
|
servicePath: string;
|
|
32
31
|
timerPath: string;
|
|
32
|
+
action?: undefined;
|
|
33
33
|
} | {
|
|
34
34
|
active?: undefined;
|
|
35
35
|
name: string;
|
|
@@ -28,6 +28,23 @@ export declare const templateKeyOf: (key: string) => {
|
|
|
28
28
|
readonly kind: "schedule-failed";
|
|
29
29
|
readonly about: "the message sent when a scheduled run fails";
|
|
30
30
|
} | undefined;
|
|
31
|
+
/** The key of one schedule's own digest templates. */
|
|
32
|
+
export declare const scheduleReportKey: (schedule: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* A key of `TEMPLATE_KEYS`, or `report/<schedule>` for a schedule the tool has: that schedule's own digest templates,
|
|
35
|
+
* which `schedule` names.
|
|
36
|
+
*/
|
|
37
|
+
export declare const reportKeyOf: (key: string, schedules: readonly string[]) => {
|
|
38
|
+
key: string;
|
|
39
|
+
kind: MessageKind;
|
|
40
|
+
about: string;
|
|
41
|
+
schedule?: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Where a digest's template comes from, first stored one wins: the schedule's own, then the owner's morning-digest
|
|
45
|
+
* template (a digest schedule made before names existed may be called anything), then the shipped one.
|
|
46
|
+
*/
|
|
47
|
+
export declare const reportKeysOf: (kind: MessageKind, schedule?: string) => string[];
|
|
31
48
|
export declare const keyOfKind: (kind: MessageKind) => TemplateKey;
|
|
32
49
|
/** The languages cli-core ships a template in for `kind`: a stored template in another one would never be used. */
|
|
33
50
|
export declare const shippedLanguages: (kind: MessageKind) => string[];
|
|
@@ -37,7 +54,7 @@ export declare const shippedLanguages: (kind: MessageKind) => string[];
|
|
|
37
54
|
*/
|
|
38
55
|
export declare const sampleView: (kind: MessageKind, language: string, now: number) => MessageView;
|
|
39
56
|
/** 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) => {
|
|
57
|
+
export declare const lastReport: (state: string, kind: MessageKind, schedule?: string) => {
|
|
41
58
|
path: string;
|
|
42
59
|
document: string;
|
|
43
60
|
} | undefined;
|
|
@@ -51,16 +68,17 @@ export interface TemplateCheck {
|
|
|
51
68
|
* Whether `body` may be saved for one channel: it is rendered against the synthetic sample and against the last real
|
|
52
69
|
* report, when the tool has one, with the platform rules that run at send time. Any problem refuses the save.
|
|
53
70
|
*/
|
|
54
|
-
export declare const checkTemplateSave: ({ kind, channel, language, body, state, now, }: {
|
|
71
|
+
export declare const checkTemplateSave: ({ kind, channel, language, body, state, now, schedule, }: {
|
|
55
72
|
kind: MessageKind;
|
|
56
73
|
channel: ReportChannel;
|
|
57
74
|
language: string;
|
|
58
75
|
body: string;
|
|
59
76
|
state: string;
|
|
60
77
|
now: number;
|
|
78
|
+
schedule?: string;
|
|
61
79
|
}) => Promise<TemplateCheck[]>;
|
|
62
80
|
/** 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) => {
|
|
81
|
+
export declare const previewView: (state: string, kind: MessageKind, language: string, now: number, schedule?: string) => {
|
|
64
82
|
against: string;
|
|
65
83
|
view: MessageView;
|
|
66
84
|
};
|
|
@@ -14,6 +14,33 @@ export const TEMPLATE_KEYS = [
|
|
|
14
14
|
{ key: "notice/schedule-failed", kind: "schedule-failed", about: "the message sent when a scheduled run fails" },
|
|
15
15
|
];
|
|
16
16
|
export const templateKeyOf = (key) => TEMPLATE_KEYS.find((one) => one.key === key);
|
|
17
|
+
const DIGEST_KEY = "report/morning-digest";
|
|
18
|
+
/** The key of one schedule's own digest templates. */
|
|
19
|
+
export const scheduleReportKey = (schedule) => `report/${schedule}`;
|
|
20
|
+
/**
|
|
21
|
+
* A key of `TEMPLATE_KEYS`, or `report/<schedule>` for a schedule the tool has: that schedule's own digest templates,
|
|
22
|
+
* which `schedule` names.
|
|
23
|
+
*/
|
|
24
|
+
export const reportKeyOf = (key, schedules) => {
|
|
25
|
+
const known = templateKeyOf(key);
|
|
26
|
+
if (known)
|
|
27
|
+
return known;
|
|
28
|
+
const schedule = key.startsWith("report/") ? key.slice("report/".length) : "";
|
|
29
|
+
return schedule && schedules.includes(schedule)
|
|
30
|
+
? { key, kind: "morning-digest", about: `the ${schedule} digest`, schedule }
|
|
31
|
+
: undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Where a digest's template comes from, first stored one wins: the schedule's own, then the owner's morning-digest
|
|
35
|
+
* template (a digest schedule made before names existed may be called anything), then the shipped one.
|
|
36
|
+
*/
|
|
37
|
+
export const reportKeysOf = (kind, schedule) => {
|
|
38
|
+
const key = keyOfKind(kind);
|
|
39
|
+
// A schedule named after another message's key (weekly-gaps) has no key of its own.
|
|
40
|
+
return kind === "morning-digest" && schedule && !templateKeyOf(scheduleReportKey(schedule))
|
|
41
|
+
? [scheduleReportKey(schedule), DIGEST_KEY]
|
|
42
|
+
: [key];
|
|
43
|
+
};
|
|
17
44
|
export const keyOfKind = (kind) => TEMPLATE_KEYS.find((one) => one.kind === kind).key;
|
|
18
45
|
const TEMPLATES = fileURLToPath(new URL("./templates/", import.meta.url));
|
|
19
46
|
/** The languages cli-core ships a template in for `kind`: a stored template in another one would never be used. */
|
|
@@ -45,11 +72,12 @@ export const sampleView = (kind, language, now) => {
|
|
|
45
72
|
return view;
|
|
46
73
|
};
|
|
47
74
|
/** 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) => {
|
|
75
|
+
export const lastReport = (state, kind, schedule) => {
|
|
49
76
|
const folder = schedulesDir(state);
|
|
50
77
|
if (kind !== "morning-digest" || !existsSync(folder))
|
|
51
78
|
return undefined;
|
|
52
|
-
const
|
|
79
|
+
const names = schedule === undefined ? readdirSync(folder) : [schedule];
|
|
80
|
+
const files = names.flatMap((name) => {
|
|
53
81
|
const runs = join(folder, name, "runs");
|
|
54
82
|
return existsSync(runs)
|
|
55
83
|
? readdirSync(runs)
|
|
@@ -69,8 +97,8 @@ export const lastReport = (state, kind) => {
|
|
|
69
97
|
* Whether `body` may be saved for one channel: it is rendered against the synthetic sample and against the last real
|
|
70
98
|
* report, when the tool has one, with the platform rules that run at send time. Any problem refuses the save.
|
|
71
99
|
*/
|
|
72
|
-
export const checkTemplateSave = async ({ kind, channel, language, body, state, now, }) => {
|
|
73
|
-
const last = lastReport(state, kind);
|
|
100
|
+
export const checkTemplateSave = async ({ kind, channel, language, body, state, now, schedule, }) => {
|
|
101
|
+
const last = lastReport(state, kind, schedule);
|
|
74
102
|
const views = [
|
|
75
103
|
["sample", sampleView(kind, language, now)],
|
|
76
104
|
...(last ? [[last.path, viewOf(last.document, language, now)]] : []),
|
|
@@ -78,8 +106,8 @@ export const checkTemplateSave = async ({ kind, channel, language, body, state,
|
|
|
78
106
|
return Promise.all(views.flatMap(([against, view]) => view ? [checkTemplate(view, channel, body).then((check) => ({ against, ...check }))] : []));
|
|
79
107
|
};
|
|
80
108
|
/** 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);
|
|
109
|
+
export const previewView = (state, kind, language, now, schedule) => {
|
|
110
|
+
const last = lastReport(state, kind, schedule);
|
|
83
111
|
const view = last && viewOf(last.document, language, now);
|
|
84
112
|
return view ? { against: last.path, view } : { against: "sample", view: sampleView(kind, language, now) };
|
|
85
113
|
};
|
|
@@ -2,8 +2,10 @@ import { type AppIdentity } from "../ports/app.js";
|
|
|
2
2
|
import { type Delivery } from "./deliver.js";
|
|
3
3
|
import { type ReportRun, type StoredTemplates } from "./report/render.js";
|
|
4
4
|
import type { ServerSystem } from "./system.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { Timer } from "./timers.js";
|
|
6
|
+
import type { When } from "./when.js";
|
|
7
|
+
export { launchdTimer, systemdTimer, type Timer, timerFor, windowsTimer } from "./timers.js";
|
|
8
|
+
export { type CalendarWhen, calendarOf, describeWhen, isCalendar, nextRun, previousRun, runsBetween, type Slot, slotsOf, WEEKDAYS, type Weekday, type When, } from "./when.js";
|
|
7
9
|
export interface Schedule {
|
|
8
10
|
name: string;
|
|
9
11
|
kind: "command" | "agent";
|
|
@@ -24,6 +26,8 @@ export interface Schedule {
|
|
|
24
26
|
notify?: Notify;
|
|
25
27
|
/** `--deliver-to`'s routes (`telegram-bot:<profile>/<chat>`, `email:<profile>/<address>`), answered as `deliver_to`. */
|
|
26
28
|
to?: string[];
|
|
29
|
+
/** Kept with no timer: `schedule run` still runs it, and `schedule resume` puts the timer back. */
|
|
30
|
+
paused?: true;
|
|
27
31
|
}
|
|
28
32
|
export declare const NOTIFY_WHEN: readonly ["always", "failures", "never"];
|
|
29
33
|
export type Notify = (typeof NOTIFY_WHEN)[number];
|
|
@@ -138,22 +142,6 @@ export declare const scheduledRuns: (state: string) => {
|
|
|
138
142
|
last: LastRun | undefined;
|
|
139
143
|
}[];
|
|
140
144
|
export declare const listSchedules: (state: string, filter?: Partial<Pick<Schedule, "name" | "kind">>) => Schedule[];
|
|
141
|
-
/** How one operating system starts `argv` at the schedule's times. Every timer runs the same thing: `<cli> schedule exec <file>`. */
|
|
142
|
-
export interface Timer {
|
|
143
|
-
install: (schedule: Schedule, argv: string[]) => Promise<void>;
|
|
144
|
-
remove: (name: string) => Promise<void>;
|
|
145
|
-
/** Where the timer lives, for the owner to look at. */
|
|
146
|
-
where: (name: string) => string;
|
|
147
|
-
}
|
|
148
|
-
export declare const systemdTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, home: string) => Timer;
|
|
149
|
-
export declare const launchdTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, home: string) => Timer;
|
|
150
|
-
/**
|
|
151
|
-
* Task Scheduler through PowerShell's ScheduledTasks module. The values travel in variables, never in
|
|
152
|
-
* the script, so nothing needs quoting for PowerShell; Windows has no per-task environment, which is why
|
|
153
|
-
* the runner reads its variables from the schedule file.
|
|
154
|
-
*/
|
|
155
|
-
export declare const windowsTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|
|
156
|
-
export declare const timerFor: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|
|
157
145
|
/** The shared `links` settings; a config file that cannot be read keeps the default rather than stop a digest. */
|
|
158
146
|
export declare const sharedLinks: (env: NodeJS.ProcessEnv) => import("../domain/links.js").LinkConfig;
|
|
159
147
|
/** A desktop notification; a machine without one loses only the notice, never the run. */
|
|
@@ -176,7 +164,7 @@ export declare const CREDENTIALS_UNREACHABLE = "credentials.unreachable";
|
|
|
176
164
|
* keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
|
|
177
165
|
* 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
|
|
178
166
|
*/
|
|
179
|
-
export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, file: string, { now, timer, signal, killAfterMs, untilUnlocked, wait, agentRuns, agentInput, ownerLanguage, reportTemplates, skipRepeatedInput, }?: {
|
|
167
|
+
export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, file: string, { now, timer, signal, killAfterMs, untilUnlocked, wait, agentRuns, agentInput, ownerLanguage, reportTemplates, skipRepeatedInput, routes: chosen, }?: {
|
|
180
168
|
now?: () => Date;
|
|
181
169
|
timer?: Timer;
|
|
182
170
|
signal?: AbortSignal;
|
|
@@ -189,12 +177,14 @@ export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env:
|
|
|
189
177
|
/** The owner's first language, read only when the answer is a report; Russian when the host cannot say. */
|
|
190
178
|
ownerLanguage?: (env: NodeJS.ProcessEnv) => Promise<string>;
|
|
191
179
|
/** The owner's stored report templates; the shipped ones when the host gives none. */
|
|
192
|
-
reportTemplates?: (env: NodeJS.ProcessEnv) => StoredTemplates;
|
|
180
|
+
reportTemplates?: (env: NodeJS.ProcessEnv, schedule: string) => StoredTemplates;
|
|
193
181
|
/**
|
|
194
182
|
* Leave out a mail-gated agent whose input is the one its last run ended well on. The mark did not move, so the
|
|
195
183
|
* run would only meet the same input again and pay for it; new mail changes the input.
|
|
196
184
|
*/
|
|
197
185
|
skipRepeatedInput?: boolean;
|
|
186
|
+
/** Where this run goes instead of the schedule's own routes; `[]` keeps it here. */
|
|
187
|
+
routes?: readonly string[];
|
|
198
188
|
}) => Promise<LastRun>;
|
|
199
189
|
/** One run of the schedule's command or agent: its output in `runs/`, its result in `last.json`. */
|
|
200
190
|
export declare const attemptSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, schedule: Schedule, folder: string, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput, at, }: {
|
|
@@ -12,8 +12,8 @@ import { readSharedSection, sharedConfigPath } from "../store/shared-config.js";
|
|
|
12
12
|
import { deliver } from "./deliver.js";
|
|
13
13
|
import { causeOf, gapsView, noticeView, weeklyGapsOf } from "./report/messages.js";
|
|
14
14
|
import { prepareMessage, prepareReport, } from "./report/render.js";
|
|
15
|
-
|
|
16
|
-
export { describeWhen, WEEKDAYS } from "./when.js";
|
|
15
|
+
export { launchdTimer, systemdTimer, timerFor, windowsTimer } from "./timers.js";
|
|
16
|
+
export { calendarOf, describeWhen, isCalendar, nextRun, previousRun, runsBetween, slotsOf, WEEKDAYS, } from "./when.js";
|
|
17
17
|
export const NOTIFY_WHEN = ["always", "failures", "never"];
|
|
18
18
|
/** A repeating agent would otherwise notify on every tick; any other schedule runs rarely enough to say each result. */
|
|
19
19
|
export const notifyOf = (schedule) => schedule.notify ?? (schedule.kind === "agent" && "every" in schedule.when ? "failures" : "always");
|
|
@@ -188,161 +188,6 @@ export const listSchedules = (state, filter = {}) => existsSync(schedulesDir(sta
|
|
|
188
188
|
(filter.kind === undefined || schedule.kind === filter.kind))
|
|
189
189
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
190
190
|
: [];
|
|
191
|
-
const systemdQuote = (value) => `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%").replaceAll("$", "$$$$")}"`;
|
|
192
|
-
const xml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
193
|
-
const checked = async (system, env, argv, allowFailure = false) => {
|
|
194
|
-
const ran = await system.run(argv, env);
|
|
195
|
-
if (ran.code !== 0 && !allowFailure) {
|
|
196
|
-
throw new CliError("configuration_error", `${argv[0]} failed: ${(ran.stderr || ran.stdout).trim()}`);
|
|
197
|
-
}
|
|
198
|
-
return ran;
|
|
199
|
-
};
|
|
200
|
-
export const systemdTimer = (app, system, env, home) => {
|
|
201
|
-
const folder = join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "systemd", "user");
|
|
202
|
-
const unit = (name) => `${app.command}-schedule-${name}`;
|
|
203
|
-
return {
|
|
204
|
-
where: (name) => join(folder, `${unit(name)}.timer`),
|
|
205
|
-
install: async (schedule, argv) => {
|
|
206
|
-
const { when } = schedule;
|
|
207
|
-
writeSecurely(join(folder, `${unit(schedule.name)}.service`), [
|
|
208
|
-
"[Unit]",
|
|
209
|
-
`Description=${app.command} schedule ${schedule.name}`,
|
|
210
|
-
"",
|
|
211
|
-
"[Service]",
|
|
212
|
-
"Type=oneshot",
|
|
213
|
-
`ExecStart=${argv.map(systemdQuote).join(" ")}`,
|
|
214
|
-
"",
|
|
215
|
-
].join("\n"), 0o644);
|
|
216
|
-
writeSecurely(join(folder, `${unit(schedule.name)}.timer`), [
|
|
217
|
-
"[Unit]",
|
|
218
|
-
`Description=${app.command} schedule ${schedule.name} — ${describeWhen(when)}`,
|
|
219
|
-
"",
|
|
220
|
-
"[Timer]",
|
|
221
|
-
...("every" in when
|
|
222
|
-
? // From when a run ends: counted from its start, a run longer than the interval left no next run.
|
|
223
|
-
[`OnActiveSec=${when.every}min`, `OnUnitInactiveSec=${when.every}min`]
|
|
224
|
-
: // Persistent: a run missed while the machine slept happens when it wakes.
|
|
225
|
-
[`OnCalendar=${onCalendar(when)}`, "Persistent=true"]),
|
|
226
|
-
"",
|
|
227
|
-
"[Install]",
|
|
228
|
-
"WantedBy=timers.target",
|
|
229
|
-
"",
|
|
230
|
-
].join("\n"), 0o644);
|
|
231
|
-
await checked(system, env, ["systemctl", "--user", "daemon-reload"]);
|
|
232
|
-
await checked(system, env, ["systemctl", "--user", "enable", "--now", `${unit(schedule.name)}.timer`]);
|
|
233
|
-
},
|
|
234
|
-
remove: async (name) => {
|
|
235
|
-
await checked(system, env, ["systemctl", "--user", "disable", "--now", `${unit(name)}.timer`], true);
|
|
236
|
-
rmSync(join(folder, `${unit(name)}.timer`), { force: true });
|
|
237
|
-
rmSync(join(folder, `${unit(name)}.service`), { force: true });
|
|
238
|
-
await checked(system, env, ["systemctl", "--user", "daemon-reload"]);
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
export const launchdTimer = (app, system, env, home) => {
|
|
243
|
-
const folder = join(home, "Library", "LaunchAgents");
|
|
244
|
-
const label = (name) => `${app.appName}.schedule.${name}`;
|
|
245
|
-
const plist = (name) => join(folder, `${label(name)}.plist`);
|
|
246
|
-
const domain = `gui/${system.uid}`;
|
|
247
|
-
const calendar = (when) => {
|
|
248
|
-
if ("every" in when)
|
|
249
|
-
return [` <key>StartInterval</key><integer>${when.every * 60}</integer>`];
|
|
250
|
-
const [hour, minute] = ("once" in when ? localStamp(when.once).slice(11, 16) : clockOf(when)).split(":").map(Number);
|
|
251
|
-
const once = "once" in when ? new Date(when.once) : undefined;
|
|
252
|
-
return [
|
|
253
|
-
" <key>StartCalendarInterval</key>",
|
|
254
|
-
" <dict>",
|
|
255
|
-
// launchd has no year: a one-off is a yearly date, and the run removes it.
|
|
256
|
-
...(once
|
|
257
|
-
? [
|
|
258
|
-
` <key>Month</key><integer>${once.getMonth() + 1}</integer>`,
|
|
259
|
-
` <key>Day</key><integer>${once.getDate()}</integer>`,
|
|
260
|
-
]
|
|
261
|
-
: []),
|
|
262
|
-
// launchd counts Sunday as 0.
|
|
263
|
-
...("weekly" in when ? [` <key>Weekday</key><integer>${(WEEKDAYS.indexOf(when.on) + 1) % 7}</integer>`] : []),
|
|
264
|
-
` <key>Hour</key><integer>${hour}</integer>`,
|
|
265
|
-
` <key>Minute</key><integer>${minute}</integer>`,
|
|
266
|
-
" </dict>",
|
|
267
|
-
];
|
|
268
|
-
};
|
|
269
|
-
return {
|
|
270
|
-
where: plist,
|
|
271
|
-
install: async (schedule, argv) => {
|
|
272
|
-
await checked(system, env, ["launchctl", "bootout", `${domain}/${label(schedule.name)}`], true);
|
|
273
|
-
writeSecurely(plist(schedule.name), [
|
|
274
|
-
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
275
|
-
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
276
|
-
'<plist version="1.0">',
|
|
277
|
-
"<dict>",
|
|
278
|
-
` <key>Label</key><string>${xml(label(schedule.name))}</string>`,
|
|
279
|
-
" <key>ProgramArguments</key>",
|
|
280
|
-
" <array>",
|
|
281
|
-
...argv.map((word) => ` <string>${xml(word)}</string>`),
|
|
282
|
-
" </array>",
|
|
283
|
-
...calendar(schedule.when),
|
|
284
|
-
"</dict>",
|
|
285
|
-
"</plist>",
|
|
286
|
-
"",
|
|
287
|
-
].join("\n"), 0o644);
|
|
288
|
-
await checked(system, env, ["launchctl", "bootstrap", domain, plist(schedule.name)]);
|
|
289
|
-
},
|
|
290
|
-
remove: async (name) => {
|
|
291
|
-
await checked(system, env, ["launchctl", "bootout", `${domain}/${label(name)}`], true);
|
|
292
|
-
rmSync(plist(name), { force: true });
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
/**
|
|
297
|
-
* Task Scheduler through PowerShell's ScheduledTasks module. The values travel in variables, never in
|
|
298
|
-
* the script, so nothing needs quoting for PowerShell; Windows has no per-task environment, which is why
|
|
299
|
-
* the runner reads its variables from the schedule file.
|
|
300
|
-
*/
|
|
301
|
-
export const windowsTimer = (app, system, env) => {
|
|
302
|
-
const path = `\\${app.appName}\\`;
|
|
303
|
-
const powershell = (script, values, allowFailure = false) => checked(system, { ...env, ...values }, ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], allowFailure);
|
|
304
|
-
return {
|
|
305
|
-
where: (name) => `Task Scheduler ${path}${name}`,
|
|
306
|
-
install: async (schedule, [exe = "", ...args]) => {
|
|
307
|
-
const { when } = schedule;
|
|
308
|
-
await powershell([
|
|
309
|
-
"$ErrorActionPreference = 'Stop'",
|
|
310
|
-
"$action = New-ScheduledTaskAction -Execute $env:WIRECAT_EXE -Argument $env:WIRECAT_ARGS",
|
|
311
|
-
"$trigger = switch ($env:WIRECAT_KIND) {",
|
|
312
|
-
" 'every' { New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes ([int]$env:WIRECAT_MINUTES)) }",
|
|
313
|
-
" 'daily' { New-ScheduledTaskTrigger -Daily -At $env:WIRECAT_AT }",
|
|
314
|
-
" 'weekly' { New-ScheduledTaskTrigger -Weekly -DaysOfWeek $env:WIRECAT_DAY -At $env:WIRECAT_AT }",
|
|
315
|
-
" 'once' { New-ScheduledTaskTrigger -Once -At ([datetime]::ParseExact($env:WIRECAT_AT, 'yyyy-MM-dd HH:mm:ss', $null)) }",
|
|
316
|
-
"}",
|
|
317
|
-
"$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew",
|
|
318
|
-
"Register-ScheduledTask -TaskName $env:WIRECAT_NAME -TaskPath $env:WIRECAT_PATH -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null",
|
|
319
|
-
].join("\n"), {
|
|
320
|
-
WIRECAT_EXE: exe,
|
|
321
|
-
WIRECAT_ARGS: args.map((word) => `"${word.replaceAll('"', '\\"')}"`).join(" "),
|
|
322
|
-
WIRECAT_KIND: "every" in when ? "every" : "daily" in when ? "daily" : "weekly" in when ? "weekly" : "once",
|
|
323
|
-
WIRECAT_MINUTES: "every" in when ? String(when.every) : "",
|
|
324
|
-
WIRECAT_AT: "every" in when ? "" : "once" in when ? localStamp(when.once) : clockOf(when),
|
|
325
|
-
WIRECAT_DAY: "weekly" in when ? WINDOWS_DAYS[when.on] : "",
|
|
326
|
-
WIRECAT_NAME: schedule.name,
|
|
327
|
-
WIRECAT_PATH: path,
|
|
328
|
-
});
|
|
329
|
-
},
|
|
330
|
-
remove: async (name) => {
|
|
331
|
-
await powershell("Unregister-ScheduledTask -TaskName $env:WIRECAT_NAME -TaskPath $env:WIRECAT_PATH -Confirm:$false", { WIRECAT_NAME: name, WIRECAT_PATH: path }, true);
|
|
332
|
-
},
|
|
333
|
-
};
|
|
334
|
-
};
|
|
335
|
-
export const timerFor = (app, system, env) => {
|
|
336
|
-
if (system.platform === "win32")
|
|
337
|
-
return windowsTimer(app, system, env);
|
|
338
|
-
if (!env.HOME)
|
|
339
|
-
throw new CliError("configuration_error", "HOME is not set, so there is nowhere to put the timer");
|
|
340
|
-
if (system.platform === "linux")
|
|
341
|
-
return systemdTimer(app, system, env, env.HOME);
|
|
342
|
-
if (system.platform === "darwin")
|
|
343
|
-
return launchdTimer(app, system, env, env.HOME);
|
|
344
|
-
throw new CliError("validation_error", `${app.command} schedule knows Linux, macOS and Windows, not ${system.platform}`);
|
|
345
|
-
};
|
|
346
191
|
/** The shared `links` settings; a config file that cannot be read keeps the default rather than stop a digest. */
|
|
347
192
|
export const sharedLinks = (env) => {
|
|
348
193
|
try {
|
|
@@ -458,7 +303,7 @@ const pause = (ms, signal) => new Promise((resolve) => {
|
|
|
458
303
|
* keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
|
|
459
304
|
* 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
|
|
460
305
|
*/
|
|
461
|
-
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, } = {}) => {
|
|
306
|
+
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, routes: chosen, } = {}) => {
|
|
462
307
|
const schedule = readSchedule(file);
|
|
463
308
|
const folder = join(file, "..");
|
|
464
309
|
const runs = join(folder, "runs");
|
|
@@ -505,7 +350,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
505
350
|
now: now().getTime(),
|
|
506
351
|
links: sharedLinks(runEnv),
|
|
507
352
|
env: runEnv,
|
|
508
|
-
...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
|
|
353
|
+
...(reportTemplates ? { templates: reportTemplates(runEnv, schedule.name) } : {}),
|
|
509
354
|
})
|
|
510
355
|
: undefined;
|
|
511
356
|
const latestText = join(folder, "latest.txt");
|
|
@@ -525,7 +370,8 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
525
370
|
if (!kept.has(stampOf(file)))
|
|
526
371
|
rmSync(join(runs, file), { force: true });
|
|
527
372
|
const title = `${app.command} ${schedule.name}`;
|
|
528
|
-
|
|
373
|
+
// Routes the owner named for this run go whatever the schedule's notify says; none named, nobody is told.
|
|
374
|
+
const mode = chosen === undefined ? notifyOf(schedule) : chosen.length ? "always" : "never";
|
|
529
375
|
if (agent && exitCode === 0) {
|
|
530
376
|
if (mode === "always" && !announcedByDesktop(join(folder, ".."), schedule.name)) {
|
|
531
377
|
const first = readFileSync(output, "utf8")
|
|
@@ -539,7 +385,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
539
385
|
else if (exitCode !== 0 && mode !== "never") {
|
|
540
386
|
await notify(system, env, title, `failed (exit ${exitCode}) — ${errors}`);
|
|
541
387
|
}
|
|
542
|
-
const routes = schedule.to ?? [];
|
|
388
|
+
const routes = chosen ?? schedule.to ?? [];
|
|
543
389
|
const locked = readOnlyLockOf(app, runEnv);
|
|
544
390
|
const sendAlong = async (parcel) => {
|
|
545
391
|
const deliveries = await deliver(system, runEnv, routes, parcel, {
|
|
@@ -556,7 +402,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
556
402
|
const messageOptions = async () => ({
|
|
557
403
|
language: await ownerLanguage(runEnv).catch(() => "ru"),
|
|
558
404
|
linkOf: (ref) => linkFor(ref, { form: "web", config: sharedLinks(runEnv), env: runEnv }),
|
|
559
|
-
...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
|
|
405
|
+
...(reportTemplates ? { templates: reportTemplates(runEnv, schedule.name) } : {}),
|
|
560
406
|
});
|
|
561
407
|
if (routes.length > 0 && (exitCode === 0 ? mode === "always" : mode !== "never")) {
|
|
562
408
|
const at = shortTime(last.at);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
2
|
+
import type { Schedule } from "./schedules.js";
|
|
3
|
+
import type { ServerSystem } from "./system.js";
|
|
4
|
+
/** How one operating system starts `argv` at the schedule's times. Every timer runs the same thing: `<cli> schedule exec <file>`. */
|
|
5
|
+
export interface Timer {
|
|
6
|
+
install: (schedule: Schedule, argv: string[]) => Promise<void>;
|
|
7
|
+
remove: (name: string) => Promise<void>;
|
|
8
|
+
/** Where the timer lives, for the owner to look at. */
|
|
9
|
+
where: (name: string) => string;
|
|
10
|
+
}
|
|
11
|
+
export declare const systemdTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, home: string) => Timer;
|
|
12
|
+
export declare const launchdTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, home: string) => Timer;
|
|
13
|
+
/**
|
|
14
|
+
* Task Scheduler through PowerShell's ScheduledTasks module. The values travel in variables, never in
|
|
15
|
+
* the script, so nothing needs quoting for PowerShell; Windows has no per-task environment, which is why
|
|
16
|
+
* the runner reads its variables from the schedule file.
|
|
17
|
+
*/
|
|
18
|
+
export declare const windowsTimer: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|
|
19
|
+
export declare const timerFor: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv) => Timer;
|