@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/background/backfill.d.ts +1 -1
  3. package/dist/background/backfill.js +1 -1
  4. package/dist/background/daily-archive-timer.d.ts +1 -1
  5. package/dist/background/report/stored-templates.d.ts +21 -3
  6. package/dist/background/report/stored-templates.js +34 -6
  7. package/dist/background/schedules.d.ts +10 -20
  8. package/dist/background/schedules.js +8 -162
  9. package/dist/background/timers.d.ts +19 -0
  10. package/dist/background/timers.js +175 -0
  11. package/dist/background/when.d.ts +28 -7
  12. package/dist/background/when.js +55 -11
  13. package/dist/calendar/prepare.d.ts +14 -0
  14. package/dist/cli/app-doctor-command.js +2 -1
  15. package/dist/cli/envelope.d.ts +28 -0
  16. package/dist/cli/index.d.ts +3 -2
  17. package/dist/cli/index.js +3 -2
  18. package/dist/cli/schedule/schedule-command.d.ts +100 -3
  19. package/dist/cli/schedule/schedule-command.js +276 -118
  20. package/dist/cli/templates-command.js +45 -20
  21. package/dist/domain/display-names.d.ts +5 -2
  22. package/dist/domain/display-names.js +13 -4
  23. package/dist/domain/person-kinds.d.ts +9 -0
  24. package/dist/domain/person-kinds.js +67 -0
  25. package/dist/domain/records-table.d.ts +61 -0
  26. package/dist/domain/records-table.js +382 -0
  27. package/dist/entities/index.d.ts +2 -1
  28. package/dist/entities/list-results.d.ts +2 -0
  29. package/dist/entities/list-results.js +2 -0
  30. package/dist/entities/template.d.ts +1 -1
  31. package/dist/entities/template.js +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/mcp/surface.js +23 -2
  35. package/dist/meetings/mcp/index.d.ts +15 -15
  36. package/dist/services/index.d.ts +1 -1
  37. package/dist/services/index.js +1 -1
  38. package/dist/services/metadata.d.ts +1 -1
  39. package/dist/services/search-harder.d.ts +6 -1
  40. package/dist/services/search-harder.js +9 -2
  41. package/dist/store/index.d.ts +2 -1
  42. package/dist/store/index.js +2 -0
  43. package/dist/store/people.d.ts +4 -3
  44. package/dist/store/sqlite/people-list.d.ts +23 -8
  45. package/dist/store/sqlite/people-list.js +189 -65
  46. package/package.json +2 -2
  47. package/parity.json +29 -0
@@ -0,0 +1,175 @@
1
+ import { rmSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { CliError, writeSecurely } from "@wirecat/cli-base";
4
+ import { describeWhen, localStamp, onCalendar, slotsOf, WEEKDAYS, WINDOWS_DAYS } from "./when.js";
5
+ const systemdQuote = (value) => `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%").replaceAll("$", "$$$$")}"`;
6
+ const xml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
7
+ const checked = async (system, env, argv, allowFailure = false) => {
8
+ const ran = await system.run(argv, env);
9
+ if (ran.code !== 0 && !allowFailure) {
10
+ throw new CliError("configuration_error", `${argv[0]} failed: ${(ran.stderr || ran.stdout).trim()}`);
11
+ }
12
+ return ran;
13
+ };
14
+ export const systemdTimer = (app, system, env, home) => {
15
+ const folder = join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "systemd", "user");
16
+ const unit = (name) => `${app.command}-schedule-${name}`;
17
+ return {
18
+ where: (name) => join(folder, `${unit(name)}.timer`),
19
+ install: async (schedule, argv) => {
20
+ const { when } = schedule;
21
+ writeSecurely(join(folder, `${unit(schedule.name)}.service`), [
22
+ "[Unit]",
23
+ `Description=${app.command} schedule ${schedule.name}`,
24
+ "",
25
+ "[Service]",
26
+ "Type=oneshot",
27
+ `ExecStart=${argv.map(systemdQuote).join(" ")}`,
28
+ "",
29
+ ].join("\n"), 0o644);
30
+ writeSecurely(join(folder, `${unit(schedule.name)}.timer`), [
31
+ "[Unit]",
32
+ `Description=${app.command} schedule ${schedule.name} — ${describeWhen(when)}`,
33
+ "",
34
+ "[Timer]",
35
+ ...("every" in when
36
+ ? // From when a run ends: counted from its start, a run longer than the interval left no next run.
37
+ [`OnActiveSec=${when.every}min`, `OnUnitInactiveSec=${when.every}min`]
38
+ : // Persistent: a run missed while the machine slept happens when it wakes.
39
+ [...onCalendar(when).map((value) => `OnCalendar=${value}`), "Persistent=true"]),
40
+ "",
41
+ "[Install]",
42
+ "WantedBy=timers.target",
43
+ "",
44
+ ].join("\n"), 0o644);
45
+ await checked(system, env, ["systemctl", "--user", "daemon-reload"]);
46
+ await checked(system, env, ["systemctl", "--user", "enable", "--now", `${unit(schedule.name)}.timer`]);
47
+ },
48
+ remove: async (name) => {
49
+ await checked(system, env, ["systemctl", "--user", "disable", "--now", `${unit(name)}.timer`], true);
50
+ rmSync(join(folder, `${unit(name)}.timer`), { force: true });
51
+ rmSync(join(folder, `${unit(name)}.service`), { force: true });
52
+ await checked(system, env, ["systemctl", "--user", "daemon-reload"]);
53
+ },
54
+ };
55
+ };
56
+ export const launchdTimer = (app, system, env, home) => {
57
+ const folder = join(home, "Library", "LaunchAgents");
58
+ const label = (name) => `${app.appName}.schedule.${name}`;
59
+ const plist = (name) => join(folder, `${label(name)}.plist`);
60
+ const domain = `gui/${system.uid}`;
61
+ const entry = ({ at, on }, once) => {
62
+ const [hour, minute] = at.split(":").map(Number);
63
+ return [
64
+ " <dict>",
65
+ // launchd has no year: a one-off is a yearly date, and the run removes it.
66
+ ...(once
67
+ ? [
68
+ ` <key>Month</key><integer>${once.getMonth() + 1}</integer>`,
69
+ ` <key>Day</key><integer>${once.getDate()}</integer>`,
70
+ ]
71
+ : []),
72
+ // launchd counts Sunday as 0.
73
+ ...(on ? [` <key>Weekday</key><integer>${(WEEKDAYS.indexOf(on) + 1) % 7}</integer>`] : []),
74
+ ` <key>Hour</key><integer>${hour}</integer>`,
75
+ ` <key>Minute</key><integer>${minute}</integer>`,
76
+ " </dict>",
77
+ ];
78
+ };
79
+ const calendar = (when) => {
80
+ if ("every" in when)
81
+ return [` <key>StartInterval</key><integer>${when.every * 60}</integer>`];
82
+ const entries = "once" in when
83
+ ? entry({ at: localStamp(when.once).slice(11, 16) }, new Date(when.once))
84
+ : slotsOf(when).flatMap((slot) => entry(slot));
85
+ return [" <key>StartCalendarInterval</key>", " <array>", ...entries, " </array>"];
86
+ };
87
+ return {
88
+ where: plist,
89
+ install: async (schedule, argv) => {
90
+ await checked(system, env, ["launchctl", "bootout", `${domain}/${label(schedule.name)}`], true);
91
+ writeSecurely(plist(schedule.name), [
92
+ '<?xml version="1.0" encoding="UTF-8"?>',
93
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
94
+ '<plist version="1.0">',
95
+ "<dict>",
96
+ ` <key>Label</key><string>${xml(label(schedule.name))}</string>`,
97
+ " <key>ProgramArguments</key>",
98
+ " <array>",
99
+ ...argv.map((word) => ` <string>${xml(word)}</string>`),
100
+ " </array>",
101
+ ...calendar(schedule.when),
102
+ "</dict>",
103
+ "</plist>",
104
+ "",
105
+ ].join("\n"), 0o644);
106
+ await checked(system, env, ["launchctl", "bootstrap", domain, plist(schedule.name)]);
107
+ },
108
+ remove: async (name) => {
109
+ await checked(system, env, ["launchctl", "bootout", `${domain}/${label(name)}`], true);
110
+ rmSync(plist(name), { force: true });
111
+ },
112
+ };
113
+ };
114
+ /**
115
+ * Task Scheduler through PowerShell's ScheduledTasks module. The values travel in variables, never in
116
+ * the script, so nothing needs quoting for PowerShell; Windows has no per-task environment, which is why
117
+ * the runner reads its variables from the schedule file.
118
+ */
119
+ export const windowsTimer = (app, system, env) => {
120
+ const path = `\\${app.appName}\\`;
121
+ const powershell = (script, values, allowFailure = false) => checked(system, { ...env, ...values }, ["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], allowFailure);
122
+ return {
123
+ where: (name) => `Task Scheduler ${path}${name}`,
124
+ install: async (schedule, [exe = "", ...args]) => {
125
+ const { when } = schedule;
126
+ await powershell([
127
+ "$ErrorActionPreference = 'Stop'",
128
+ "$action = New-ScheduledTaskAction -Execute $env:WIRECAT_EXE -Argument $env:WIRECAT_ARGS",
129
+ "$trigger = switch ($env:WIRECAT_KIND) {",
130
+ " 'every' { New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes ([int]$env:WIRECAT_MINUTES)) }",
131
+ " 'daily' { New-ScheduledTaskTrigger -Daily -At $env:WIRECAT_AT }",
132
+ " 'weekly' { New-ScheduledTaskTrigger -Weekly -DaysOfWeek $env:WIRECAT_DAY -At $env:WIRECAT_AT }",
133
+ " 'calendar' { @(foreach ($slot in $env:WIRECAT_SLOTS.Split(';')) { $day, $at = $slot.Split('|'); if ($day) { New-ScheduledTaskTrigger -Weekly -DaysOfWeek $day -At $at } else { New-ScheduledTaskTrigger -Daily -At $at } }) }",
134
+ " 'once' { New-ScheduledTaskTrigger -Once -At ([datetime]::ParseExact($env:WIRECAT_AT, 'yyyy-MM-dd HH:mm:ss', $null)) }",
135
+ "}",
136
+ "$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew",
137
+ "Register-ScheduledTask -TaskName $env:WIRECAT_NAME -TaskPath $env:WIRECAT_PATH -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null",
138
+ ].join("\n"), {
139
+ WIRECAT_EXE: exe,
140
+ WIRECAT_ARGS: args.map((word) => `"${word.replaceAll('"', '\\"')}"`).join(" "),
141
+ WIRECAT_KIND: "every" in when
142
+ ? "every"
143
+ : "once" in when
144
+ ? "once"
145
+ : "calendar" in when
146
+ ? "calendar"
147
+ : "daily" in when
148
+ ? "daily"
149
+ : "weekly",
150
+ WIRECAT_MINUTES: "every" in when ? String(when.every) : "",
151
+ WIRECAT_AT: "once" in when ? localStamp(when.once) : "daily" in when ? when.daily : "weekly" in when ? when.weekly : "",
152
+ WIRECAT_DAY: "weekly" in when ? WINDOWS_DAYS[when.on] : "",
153
+ WIRECAT_SLOTS: "calendar" in when
154
+ ? when.calendar.map((slot) => `${slot.on ? WINDOWS_DAYS[slot.on] : ""}|${slot.at}`).join(";")
155
+ : "",
156
+ WIRECAT_NAME: schedule.name,
157
+ WIRECAT_PATH: path,
158
+ });
159
+ },
160
+ remove: async (name) => {
161
+ await powershell("Unregister-ScheduledTask -TaskName $env:WIRECAT_NAME -TaskPath $env:WIRECAT_PATH -Confirm:$false", { WIRECAT_NAME: name, WIRECAT_PATH: path }, true);
162
+ },
163
+ };
164
+ };
165
+ export const timerFor = (app, system, env) => {
166
+ if (system.platform === "win32")
167
+ return windowsTimer(app, system, env);
168
+ if (!env.HOME)
169
+ throw new CliError("configuration_error", "HOME is not set, so there is nowhere to put the timer");
170
+ if (system.platform === "linux")
171
+ return systemdTimer(app, system, env, env.HOME);
172
+ if (system.platform === "darwin")
173
+ return launchdTimer(app, system, env, env.HOME);
174
+ throw new CliError("validation_error", `${app.command} schedule knows Linux, macOS and Windows, not ${system.platform}`);
175
+ };
@@ -1,7 +1,15 @@
1
1
  /** The days `--on` takes, Monday first. */
2
2
  export declare const WEEKDAYS: readonly ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
3
3
  export type Weekday = (typeof WEEKDAYS)[number];
4
- /** Minutes between runs, a daily local time, a weekday's local time, or one local moment. */
4
+ /** One calendar time: `HH:MM` local, every day or on one weekday. */
5
+ export interface Slot {
6
+ at: string;
7
+ on?: Weekday;
8
+ }
9
+ /**
10
+ * Minutes between runs, a daily local time, a weekday's local time, several of either, or one local moment. One
11
+ * `--at` keeps the `daily` or `weekly` shape that schedules were saved in before `calendar` existed.
12
+ */
5
13
  export type When = {
6
14
  every: number;
7
15
  } | {
@@ -9,20 +17,33 @@ export type When = {
9
17
  } | {
10
18
  weekly: string;
11
19
  on: Weekday;
20
+ } | {
21
+ calendar: Slot[];
12
22
  } | {
13
23
  once: string;
14
24
  };
15
- export declare const WINDOWS_DAYS: Record<Weekday, string>;
16
- /** The local time of a calendar schedule, `HH:MM`. */
17
- export declare const clockOf: (when: {
25
+ export type CalendarWhen = Extract<When, {
18
26
  daily: string;
19
27
  } | {
20
28
  weekly: string;
21
- on: Weekday;
22
- }) => string;
29
+ } | {
30
+ calendar: Slot[];
31
+ }>;
32
+ export declare const WINDOWS_DAYS: Record<Weekday, string>;
33
+ export declare const isCalendar: (when: When) => when is CalendarWhen;
34
+ /** A calendar schedule's times, whichever shape it was saved in. */
35
+ export declare const slotsOf: (when: CalendarWhen) => Slot[];
36
+ /** The shape a schedule is saved in: one slot as `daily` or `weekly`, so files and their wording stay as they were. */
37
+ export declare const calendarOf: (slots: readonly Slot[]) => CalendarWhen;
23
38
  export declare const describeWhen: (when: When) => string;
39
+ /** systemd's `OnCalendar=` values: one per slot, as a timer may carry several. */
24
40
  export declare const onCalendar: (when: Exclude<When, {
25
41
  every: number;
26
- }>) => string;
42
+ }>) => string[];
43
+ /** The local moments of a calendar schedule's runs from `from` (inclusive) to `to` (exclusive), oldest first. */
44
+ export declare const runsBetween: (when: CalendarWhen, from: number, to: number) => number[];
45
+ /** The run a calendar schedule has next after `now`, or the one before or at it; eight days hold every slot. */
46
+ export declare const nextRun: (when: CalendarWhen, now: number) => number | undefined;
47
+ export declare const previousRun: (when: CalendarWhen, now: number) => number | undefined;
27
48
  /** A local wall-clock time, as both systemd's `OnCalendar=` and PowerShell's parser take it. */
28
49
  export declare const localStamp: (iso: string) => string;
@@ -18,20 +18,64 @@ export const WINDOWS_DAYS = {
18
18
  sat: "Saturday",
19
19
  sun: "Sunday",
20
20
  };
21
- /** The local time of a calendar schedule, `HH:MM`. */
22
- export const clockOf = (when) => "daily" in when ? when.daily : when.weekly;
21
+ export const isCalendar = (when) => "daily" in when || "weekly" in when || "calendar" in when;
22
+ /** A calendar schedule's times, whichever shape it was saved in. */
23
+ export const slotsOf = (when) => "daily" in when ? [{ at: when.daily }] : "weekly" in when ? [{ at: when.weekly, on: when.on }] : when.calendar;
24
+ /** The shape a schedule is saved in: one slot as `daily` or `weekly`, so files and their wording stay as they were. */
25
+ export const calendarOf = (slots) => {
26
+ const seen = new Map(slots.map((slot) => [`${slot.on ?? ""} ${slot.at}`, slot]));
27
+ const unique = [...seen.values()].sort((a, b) => (a.on ? WEEKDAYS.indexOf(a.on) : -1) - (b.on ? WEEKDAYS.indexOf(b.on) : -1) || a.at.localeCompare(b.at));
28
+ const [one] = unique;
29
+ if (unique.length === 1 && one)
30
+ return one.on ? { weekly: one.at, on: one.on } : { daily: one.at };
31
+ return { calendar: unique };
32
+ };
33
+ const describeSlots = (slots) => {
34
+ const times = [...new Set(slots.map((slot) => slot.at))].sort();
35
+ const days = [...new Set(slots.flatMap((slot) => (slot.on ? [slot.on] : [])))];
36
+ if (days.length === 0)
37
+ return `daily at ${times.join(", ")}`;
38
+ if (slots.every((slot) => slot.on) && slots.length === times.length * days.length)
39
+ return `weekly on ${days.map((day) => SYSTEMD_DAYS[day]).join(", ")} at ${times.join(", ")}`;
40
+ return `at ${slots.map((slot) => (slot.on ? `${SYSTEMD_DAYS[slot.on]} ${slot.at}` : `daily ${slot.at}`)).join(", ")}`;
41
+ };
23
42
  export const describeWhen = (when) => "every" in when
24
43
  ? `every ${when.every % 1440 === 0 ? `${when.every / 1440}d` : when.every % 60 === 0 ? `${when.every / 60}h` : `${when.every}m`}`
25
- : "daily" in when
26
- ? `daily at ${when.daily}`
27
- : "weekly" in when
28
- ? `weekly on ${SYSTEMD_DAYS[when.on]} at ${when.weekly}`
29
- : `once at ${when.once}`;
44
+ : "once" in when
45
+ ? `once at ${when.once}`
46
+ : describeSlots(slotsOf(when));
47
+ /** systemd's `OnCalendar=` values: one per slot, as a timer may carry several. */
30
48
  export const onCalendar = (when) => "once" in when
31
- ? localStamp(when.once)
32
- : "weekly" in when
33
- ? `${SYSTEMD_DAYS[when.on]} *-*-* ${when.weekly}:00`
34
- : `*-*-* ${when.daily}:00`;
49
+ ? [localStamp(when.once)]
50
+ : slotsOf(when).map((slot) => (slot.on ? `${SYSTEMD_DAYS[slot.on]} *-*-* ${slot.at}:00` : `*-*-* ${slot.at}:00`));
51
+ /** The local moments of a calendar schedule's runs from `from` (inclusive) to `to` (exclusive), oldest first. */
52
+ export const runsBetween = (when, from, to) => {
53
+ const slots = slotsOf(when);
54
+ const moments = [];
55
+ const day = new Date(from);
56
+ day.setHours(0, 0, 0, 0);
57
+ for (; day.getTime() < to; day.setDate(day.getDate() + 1)) {
58
+ const weekday = WEEKDAYS[(day.getDay() + 6) % 7];
59
+ for (const slot of slots) {
60
+ if (slot.on && slot.on !== weekday)
61
+ continue;
62
+ const [hour, minute] = slot.at.split(":").map(Number);
63
+ const at = new Date(day.getFullYear(), day.getMonth(), day.getDate(), hour, minute).getTime();
64
+ if (at >= from && at < to)
65
+ moments.push(at);
66
+ }
67
+ }
68
+ return moments.sort((a, b) => a - b);
69
+ };
70
+ /** `days` calendar days from `at`, at the same wall-clock time: a week across a clock change is not 168 hours. */
71
+ const daysFrom = (at, days) => {
72
+ const moved = new Date(at);
73
+ moved.setDate(moved.getDate() + days);
74
+ return moved.getTime();
75
+ };
76
+ /** The run a calendar schedule has next after `now`, or the one before or at it; eight days hold every slot. */
77
+ export const nextRun = (when, now) => runsBetween(when, now + 1, daysFrom(now, 8))[0];
78
+ export const previousRun = (when, now) => runsBetween(when, daysFrom(now, -8), now + 1).at(-1);
35
79
  /** A local wall-clock time, as both systemd's `OnCalendar=` and PowerShell's parser take it. */
36
80
  export const localStamp = (iso) => {
37
81
  const at = new Date(iso);
@@ -139,5 +139,19 @@ export declare const eventPreparation: (details: EventDetails, options: Preparat
139
139
  since?: string | undefined;
140
140
  until?: string | undefined;
141
141
  } | undefined;
142
+ ranking?: {
143
+ applied: boolean;
144
+ reason_id?: string | undefined;
145
+ provider: string;
146
+ model: string;
147
+ endpoint: string;
148
+ sent: number;
149
+ cost_usd: number | null;
150
+ usage?: {
151
+ input: number;
152
+ output: number;
153
+ } | undefined;
154
+ ms: number;
155
+ } | undefined;
142
156
  }, "accounts" | "complete" | "issues" | "truncated">;
143
157
  }>;
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
3
  import { CliError, configFilePath, resolvePaths } from "@wirecat/cli-base";
4
4
  import { annotate } from "@wirecat/cli-base/commands";
5
+ import { hostFetch } from "@wirecat/cli-base/http";
5
6
  import { timezoneOf } from "@wirecat/cli-base/query";
6
7
  import { clockMeta } from "@wirecat/cli-base/standards";
7
8
  import { isNewer, latestVersion } from "@wirecat/cli-base/update";
@@ -149,7 +150,7 @@ export const appDoctorCommand = (app, configuration, options = {}) => profileFre
149
150
  const local = localCheck(env, options);
150
151
  const answer = async () => {
151
152
  const online = this.opts().online
152
- ? await onlineCheck(app, env, environment.fetch ?? fetch, options)
153
+ ? await onlineCheck(app, env, environment.fetch ?? hostFetch({ hosts: ["registry.npmjs.org"] }), options)
153
154
  : undefined;
154
155
  const output = outputFor(this);
155
156
  renderAnswer(this, output, itemOf({ ...report, ...local.fields, ...(online ? { online } : {}) }, { meta: clockMeta(Date.now(), timezoneOf()) }));
@@ -101,6 +101,20 @@ export declare const answerSchema: (item?: v.GenericSchema) => v.UnionSchema<[v.
101
101
  readonly since: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
102
102
  readonly until: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
103
103
  }, undefined>, undefined>;
104
+ readonly ranking: v.OptionalSchema<v.StrictObjectSchema<{
105
+ readonly applied: v.BooleanSchema<undefined>;
106
+ readonly reason_id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "dotted lower-case words, such as `page.next`">]>, undefined>;
107
+ readonly provider: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
108
+ readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
109
+ readonly endpoint: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
110
+ readonly sent: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
111
+ readonly cost_usd: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
112
+ readonly usage: v.OptionalSchema<v.StrictObjectSchema<{
113
+ readonly input: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
114
+ readonly output: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
115
+ }, undefined>, undefined>;
116
+ readonly ms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
117
+ }, undefined>, undefined>;
104
118
  }, undefined>;
105
119
  }, undefined>, v.StrictObjectSchema<{
106
120
  readonly item: v.GenericSchema;
@@ -156,6 +170,20 @@ export declare const answerSchema: (item?: v.GenericSchema) => v.UnionSchema<[v.
156
170
  readonly since: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
157
171
  readonly until: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
158
172
  }, undefined>, undefined>;
173
+ readonly ranking: v.OptionalSchema<v.StrictObjectSchema<{
174
+ readonly applied: v.BooleanSchema<undefined>;
175
+ readonly reason_id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "dotted lower-case words, such as `page.next`">]>, undefined>;
176
+ readonly provider: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
177
+ readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
178
+ readonly endpoint: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must not be empty">]>;
179
+ readonly sent: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
180
+ readonly cost_usd: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
181
+ readonly usage: v.OptionalSchema<v.StrictObjectSchema<{
182
+ readonly input: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
183
+ readonly output: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
184
+ }, undefined>, undefined>;
185
+ readonly ms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
186
+ }, undefined>, undefined>;
159
187
  }, undefined>;
160
188
  }, undefined>], undefined>;
161
189
  /**
@@ -1,5 +1,6 @@
1
1
  export { AI_ENTRIES, AI_SETTING_KEYS, type AISettings, resolveAISettings } from "../analysis/settings.js";
2
- export { AGENT_INPUT_MAX_CHARS, type AgentCli, type AgentInput, readSchedule, SCHEDULE_DEFAULTS, scheduleFile, spentToday, } from "../background/schedules.js";
2
+ export { parseRoute, ROUTE_HELP, routeText } from "../background/deliver.js";
3
+ export { AGENT_INPUT_MAX_CHARS, type AgentCli, type AgentInput, type CalendarWhen, calendarOf, describeWhen, isCalendar, lastRun, nextRun, previousRun, readSchedule, runsBetween, SCHEDULE_DEFAULTS, type Schedule, type Slot, scheduleFile, scheduleName, slotsOf, spentToday, WEEKDAYS, type Weekday, type When, } from "../background/schedules.js";
3
4
  export { parseDuration } from "../domain/duration.js";
4
5
  export { openOf, PROFILE_PLACEHOLDER, type ProfilesFor, profilesOn, type RefOpen, type RefSummary, refLabel, storedProfilesFor, type WritesWith, writesWithOf, } from "../domain/ref-summaries.js";
5
6
  /** The shared entities `person_context`, `organization_context`, `deal_context` and `deal_context.brief`. */
@@ -133,7 +134,7 @@ export { type ProjectTextHints, projectAnswerParts, projectCutoffTime, projectEv
133
134
  export { type ProjectStatusHints, type ProjectStatusItem, projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
134
135
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
135
136
  export { fieldsOf, projectFields } from "./result-fields.js";
136
- export { backfillScheduleRun, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, scheduleLimitsOf, } from "./schedule/schedule-command.js";
137
+ export { type AgentScheduleSpec, agentSchedule, backfillScheduleRun, type Harness, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, type ScheduleSite, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
137
138
  export { deniedKinds, deniedKindsOf, type LeftOut, type SearchedKind } from "./search-left-out.js";
138
139
  export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults } from "./setting-defaults.js";
139
140
  export { type Config, type Configuration, count, first, flag, fromFile, type GlobalFlags, NONE_NAMED, namedProfile, type ProfileKind, plain, type ResolveOptions, type Settings, type SettingsExtension, type SettingsExtensionContext, type Source, settingsFor, } from "./settings.js";
package/dist/cli/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { AI_ENTRIES, AI_SETTING_KEYS, resolveAISettings } from "../analysis/settings.js";
2
- export { AGENT_INPUT_MAX_CHARS, readSchedule, SCHEDULE_DEFAULTS, scheduleFile, spentToday, } from "../background/schedules.js";
2
+ export { parseRoute, ROUTE_HELP, routeText } from "../background/deliver.js";
3
+ export { AGENT_INPUT_MAX_CHARS, calendarOf, describeWhen, isCalendar, lastRun, nextRun, previousRun, readSchedule, runsBetween, SCHEDULE_DEFAULTS, scheduleFile, scheduleName, slotsOf, spentToday, WEEKDAYS, } from "../background/schedules.js";
3
4
  export { parseDuration } from "../domain/duration.js";
4
5
  export { openOf, PROFILE_PLACEHOLDER, profilesOn, refLabel, storedProfilesFor, writesWithOf, } from "../domain/ref-summaries.js";
5
6
  /** The shared entities `person_context`, `organization_context`, `deal_context` and `deal_context.brief`. */
@@ -123,7 +124,7 @@ export { projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWind
123
124
  export { projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
124
125
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
125
126
  export { fieldsOf, projectFields } from "./result-fields.js";
126
- export { backfillScheduleRun, SCHEDULE_SETTINGS, scheduleLimitsOf, } from "./schedule/schedule-command.js";
127
+ export { agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
127
128
  export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
128
129
  export { settingRows, withSettingDefaults } from "./setting-defaults.js";
129
130
  export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
@@ -1,11 +1,14 @@
1
1
  import { Command } from "commander";
2
- import { type AgentCli, type AgentInput, type Schedule } from "../../background/schedules.js";
2
+ import { type AgentCli, type AgentInput, type LastRun, type Notify, type Schedule, type SkipReason, type Slot, type When } from "../../background/schedules.js";
3
+ import { type ServerSystem } from "../../background/system.js";
3
4
  import { type MailWaiting } from "../../mail/marks.js";
4
5
  import { type AppIdentity } from "../../ports/app.js";
5
6
  import { type AnswerOutput } from "../envelope.js";
6
7
  import type { DeclaredSetting } from "../setting-defaults.js";
7
8
  declare const HARNESSES: readonly ["claude", "codex"];
8
- type Harness = (typeof HARNESSES)[number];
9
+ export type Harness = (typeof HARNESSES)[number];
10
+ /** One `--at`: `HH:MM` every day, or weekdays and a time, `mon 09:00` or `mon,fri 09:00`. */
11
+ export declare const slotsOfAt: (at: string) => Slot[];
9
12
  export interface ScheduleHost {
10
13
  app: AppIdentity;
11
14
  context(command: Command, resolving?: {
@@ -54,7 +57,101 @@ export declare const backfillScheduleRun: (command: Command, app: AppIdentity, e
54
57
  at: Date;
55
58
  input?: string;
56
59
  agentRuns?: readonly AgentCli[];
57
- }) => Promise<import("../../background/schedules.js").LastRun>;
60
+ }) => Promise<LastRun>;
61
+ /** Where a schedule is written and for whom: the CLI, the machine, the run's variables and its profile. */
62
+ export interface ScheduleSite {
63
+ app: AppIdentity;
64
+ system: ServerSystem;
65
+ env: NodeJS.ProcessEnv;
66
+ profile: string;
67
+ /** Other CLIs an agent may run besides this one, each under its own read-only lock. */
68
+ agentRuns?: readonly AgentCli[];
69
+ /** The config file's agent-schedule settings. */
70
+ limits?: ScheduleLimits;
71
+ }
72
+ /** The tool's state folder, which holds its schedules. */
73
+ export declare const scheduleState: ({ app, env }: Pick<ScheduleSite, "app" | "env">) => string;
74
+ /** An agent schedule as `schedule agent` makes it; the caller has checked the flags it was given. */
75
+ export interface AgentScheduleSpec {
76
+ name: string;
77
+ harness: Harness;
78
+ prompt: string;
79
+ when: When;
80
+ /** An alias or a model id; "" for the harness's own default; absent for the config file's, else ours. */
81
+ model?: string;
82
+ /** Claude only: a run that costs more is stopped, in US dollars. */
83
+ maxCost?: number;
84
+ maxCostPerDay?: number;
85
+ onNewMail?: string;
86
+ mailWaitMinutes?: number;
87
+ mailBatch?: number;
88
+ notify?: Notify;
89
+ to?: string[];
90
+ paused?: boolean;
91
+ }
92
+ /** The schedule `spec` describes, with the harness's argv built here, never by the caller: its limits live in it. */
93
+ export declare const agentSchedule: (site: ScheduleSite, spec: AgentScheduleSpec) => Schedule;
94
+ /**
95
+ * Writes the schedule's file and puts it on its timer, or takes it off when it is paused. A name another profile's
96
+ * schedule holds is refused.
97
+ */
98
+ export declare const writeSchedule: (site: ScheduleSite, schedule: Schedule) => Promise<{
99
+ file: string;
100
+ timer: string;
101
+ replaced: boolean;
102
+ }>;
103
+ /**
104
+ * Takes a schedule off its timer and keeps its file, or puts it back. It keeps the profile it was made for, as pausing
105
+ * names no new one.
106
+ */
107
+ export declare const pauseSchedule: (site: ScheduleSite, name: string, paused: boolean) => Promise<{
108
+ file: string;
109
+ timer: string;
110
+ replaced: boolean;
111
+ schedule: {
112
+ name: string;
113
+ kind: "command" | "agent";
114
+ argv: string[];
115
+ when: When;
116
+ environment: Record<string, string>;
117
+ createdAt: string;
118
+ onNewMail?: string;
119
+ mailWaitMinutes?: number;
120
+ mailBatch?: number;
121
+ maxCostPerDay?: number;
122
+ notify?: Notify;
123
+ to?: string[];
124
+ } | {
125
+ name: string;
126
+ kind: "command" | "agent";
127
+ argv: string[];
128
+ when: When;
129
+ environment: Record<string, string>;
130
+ createdAt: string;
131
+ onNewMail?: string;
132
+ mailWaitMinutes?: number;
133
+ mailBatch?: number;
134
+ maxCostPerDay?: number;
135
+ notify?: Notify;
136
+ to?: string[];
137
+ paused: true;
138
+ };
139
+ }>;
140
+ /** Takes the schedule off its timer and removes its file; its past runs stay. */
141
+ export declare const removeSchedule: (site: ScheduleSite, name: string) => Promise<void>;
142
+ /**
143
+ * Runs the schedule in `file` now, as `schedule run` does: its report rendered with the owner's language and templates
144
+ * and sent along `routes` (its own when absent, none when empty). A stop of the command stops the agent.
145
+ */
146
+ export declare const runScheduleNow: (command: Command, site: ScheduleSite, file: string, { routes, agentInput }?: {
147
+ routes?: readonly string[];
148
+ agentInput?: AgentInput;
149
+ }) => Promise<LastRun | {
150
+ skipped: {
151
+ why: string;
152
+ reason: SkipReason;
153
+ };
154
+ }>;
58
155
  /**
59
156
  * Runs the CLI's own commands, or an agent, later or on a timer — through systemd (Linux), launchd
60
157
  * (macOS) or Task Scheduler (Windows). Every timer runs `schedule exec <file>`; the schedule file holds